app/lib/inter-width.ts
18 lines and 1 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| interWidthEm | 9 to 19 | 4 | 100% | OkCRAP 4 | No data: no mutants in this code |
Imports
It imports app/lib/inter-advances.generated.ts. Imported by app/components/filter-link.tsx.
Source
import { INTER_ADVANCES } from "./inter-advances.generated.ts";
/*
* A filter link's box is sized from Inter's own advances, so the row wraps the same way in whichever
* face is drawing it. Wrapping by measured glyph width re-flowed the /writing tag row when Inter replaced
* its fallback: the metric-matched Arial held the row still only between size-adjust 108% and 110%, and
* a machine with a different Arial fell outside that window (nightly CLS 0.094).
*/
export function interWidthEm(text: string, weight: 400 | 600): number {
const advances = INTER_ADVANCES[weight];
// Wider than any Latin glyph, so a character outside the table can only widen the box.
const unknown = Math.max(...advances);
let width = 0;
for (const char of text) {
const code = char.codePointAt(0) ?? 0;
width += advances[code - 32] ?? unknown;
}
return Math.ceil(width * 100) / 100;
}