mirror of
https://github.com/bitbaum/heidi.git
synced 2026-12-04 12:37:06 +01:00
THE DEFECT, FOUND BY MEASURING RATHER THAN READING. `SectionNav` carries a
full mobile treatment — `sticky top-0 z-20`, a translucent background, a
backdrop blur, a bottom border — for a state that could never occur. Scrolled
to 2500px on `/de/method` at 375px wide, the rail sat at `top: -1489`: it had
scrolled away like any static block.
A sticky element can only travel inside its containing block, and
`SectionNavLayout` wrapped the rail in a grid-item div exactly as tall as the
rail itself. Zero room to travel, so `position: sticky` did nothing and every
style written for the stuck state was decoration. `display: contents` below
`lg` takes the wrapper out of layout, the nav becomes the grid item, and it
inherits the grid's full height.
And it had pinned to `top: 0`, which is where the 69px site header already is
with a higher z-index — so had it ever stuck, it would have stuck underneath
the header.
WHILE FIXING IT, THE ROW GOT HONEST ABOUT SIZE. Seven sections wrapped to four
rows: 153px, a fifth of an 800px phone screen, held permanently to show a table
of contents nobody asked to keep looking at. It is now one row that scrolls
sideways — 57px — which is what documentation sites converged on for the same
reason. Measured after: pinned at exactly 69px, links clickable, and the
document still 375px wide in a 375px viewport.
ONE HEADER HEIGHT, REPLACING FOUR GUESSES. The header had no height; 69px
emerged from `min-h-11` plus `py-3` plus a border. Headings meanwhile carried
`scroll-mt-20`, `scroll-mt-24` AND `scroll-mt-28` — 2, 15 and 7 of them — three
answers to "how far below the top does an anchor land", each clearing 69px by
luck. `--header-height` in globals.css is now the single value: the header is
given it, the rail pins below it, and one `scroll-mt-anchor` utility (which
also accounts for the rail on phones) replaced all 24 occurrences.
TWO MORE DUPLICATIONS, EACH WITH A COPY THAT HAD DRIFTED:
- `lib/text/words.ts` replaces FIVE whole-word matchers. `saysWord`,
`says` and `demonstrates` were byte-identical under three names; `check.ts`
and `text.ts` each kept a private `escape`. `display.ts` says in its own
comment that it is copying the variety gate — the author knew they were
writing the second one, because there was nowhere to put it. `text.ts` opens
by arguing these operations belong "in one place" while holding a fifth copy.
Eight tests pin the cases the five copies each half-knew.
- `lib/i18n/dates.ts` replaces THREE date formatters whose comments all said
"the reader's own date format, never a hardcoded one" and which then
disagreed about the month and the fallback. The tag was resolved at three
different layers: not at all, at the caller, and at the use site — so
`SavedWords` declared `locale: string` and was handed a pre-resolved
`de-CH`. Now the formatter owns it and the prop is `Locale`. A test asserts
the chat workspace's date is byte-identical in all seven locales, because a
refactor that changes a glyph is not one. Also ends `essays/[slug]`
importing a helper out of another page module.
THE AUDIT LEARNED TWO THINGS, BOTH PROVEN BY MUTATION:
- Its two checks disagreed about scrollers. `clipped` exempts a deliberate
`overflow-x: auto` ("a real scroller is a deliberate choice"); the horizontal
`over` check did not, and reported four findings against a correct page whose
document did not overflow. They now agree. Mutation-tested: widened the rail
to 900px and `OVER` still fires, on the nav itself.
- It now fails if the header's CONTENT outgrows the token height. The first
version compared the header to the token and could never fail — the header
IS the token — which is worse than no check. Mutation-tested at `2rem`:
"the header contains 68px of content in a 32px bar".
Note that lint and type-check both passed while globals.css was unparseable
(`@utility` cannot nest inside `@media`); neither compiles CSS. The dev server
was what said so.
Verified: verify exit 0 — 852 tests, 72 suites; audit:language 20 pages / 0
English; audit:responsive 116 renders across de/fr/ru, 320–375px, light and
dark — 0 overflow, 0 header drift; `/de/method` screenshotted at 390px
scrolled to 2200, rail pinned under the header.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
67 lines
3.0 KiB
TypeScript
67 lines
3.0 KiB
TypeScript
/**
|
|
* Whole-word matching, once, for a language written with umlauts.
|
|
*
|
|
* FIVE COPIES, THREE OF THEM BYTE-IDENTICAL. `saysWord` in
|
|
* `lib/situations/display.ts`, `says` in `lib/domain/practice/kinds/pick.ts`
|
|
* and `demonstrates` in `lib/domain/saved/example.ts` were the same two lines
|
|
* under three names; `wordPattern` in `lib/variety/check.ts` and `blank` in
|
|
* `lib/domain/practice/kinds/text.ts` were the same idea with their own
|
|
* private `escape`.
|
|
*
|
|
* The copies were not accidental, which is the interesting part.
|
|
* `display.ts` says so in its own comment — "Same pattern the variety gate
|
|
* uses, and for the same reason" — so the author knew they were writing the
|
|
* second one and wrote it anyway, because there was nowhere to put it. That
|
|
* is what a missing module looks like from the inside. `text.ts` opens by
|
|
* arguing that these operations belong "in one place" and then keeps a fifth
|
|
* private escape.
|
|
*
|
|
* WHY `\p{L}` AND NOT `\w`. `\w` is `[A-Za-z0-9_]`. Half the words in this
|
|
* language carry an umlaut, so a `\w` boundary treats «grüezi» as ending at
|
|
* the «r» and matches the fragment inside a longer word. `si` matching inside
|
|
* «isch» is the concrete failure every one of the five copies was written to
|
|
* avoid.
|
|
*
|
|
* WHY CASE-INSENSITIVE. A word at the start of a sentence is the same word.
|
|
* `text.ts` records the bug that proved it: `pick` located «Mir» in
|
|
* «Mir händ …» case-insensitively, asked `blank` to remove it case-sensitively,
|
|
* and shipped an item that claimed to have a gap while printing the answer.
|
|
*
|
|
* Pure, no DOM, no product types — so every layer can import it and a test can
|
|
* call it directly.
|
|
*/
|
|
|
|
/**
|
|
* A literal string, safe to paste into a pattern.
|
|
*
|
|
* Packs and vocabulary carry literal forms, not patterns. Without this a stray
|
|
* `.` in a stored form matches any character, and a form containing `(` throws
|
|
* at construction — on data a contributor typed, not on anything we control.
|
|
*/
|
|
export function escapeLiteral(value: string): string {
|
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
}
|
|
|
|
/**
|
|
* A pattern matching `word` only where it stands as a whole word.
|
|
*
|
|
* `flags` is the caller's, because the callers genuinely differ: a test wants
|
|
* one match and a replacement wants `g`. `i` and `u` are forced on — they are
|
|
* the two decisions this module exists to make, and a caller that could turn
|
|
* them off would be a caller that could reintroduce the «Mir» bug.
|
|
*/
|
|
export function wordPattern(word: string, flags = ""): RegExp {
|
|
const forced = `iu${flags.replace(/[iu]/g, "")}`;
|
|
return new RegExp(`(?<!\\p{L})${escapeLiteral(word)}(?!\\p{L})`, forced);
|
|
}
|
|
|
|
/** Whether `sentence` actually says `word` — not merely contains its letters. */
|
|
export function saysWord(sentence: string, word: string): boolean {
|
|
return wordPattern(word).test(sentence);
|
|
}
|
|
|
|
/** Replace every whole-word occurrence of `word`, for gapped exercises. */
|
|
export function replaceWord(sentence: string, word: string, with_: string): string {
|
|
return sentence.replace(wordPattern(word, "g"), with_);
|
|
}
|