Files
feuerwerk/src/ui/fonts.ts
T
adminandClaude Opus 5.5 f2282a81fb Stop loading the bold face the editor never draws in (#273)
The editor waits for every face in FACES before it starts. Source Sans 3
in 700 was one of them, but nothing in src/ sets a weight above 600, so
it cost a download and a wait for nothing.

- fonts.ts loads Source Sans 3 in 400, 500 and 600 plus Source Code Pro
  400. The 700 file (15 596 bytes) is gone from src/ui/fonts.
- A search for bold, font-weight and HTML headings in src/, web/*.html
  and the player found nothing that would fall back to 700.
- fonts.test.ts now checks both ways. A loaded Sans face must be set
  somewhere in src/, and every .woff2 in the font folder must be in
  FACES, so a stray file the glyph test would still read shows up too.
- The weight scan moved into usedWeights(), since two tests need it.

Tests:
- Gate on melektaus-atx: 197 files, 2856 tests (2855 + 1), exit 0.
- e2e 1-14: all passed, 492 checks, loaded faces ["400","500","600"].
- e2e 14 alone fails its two tab width checks, as known: it needs the
  documents 7-13 open. The font check was green there as well.
- dist/assets holds no 700 file after the build.
- Counter check: loading 700 again with its file fails the new
  "loads no face the editor never sets".
- Counter check: the file back without a FACES entry fails
  "... and no other" and names the file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 21:27:46 +02:00

28 lines
1.1 KiB
TypeScript

import codePro400 from './fonts/source-code-pro-latin-400-normal.woff2?url';
import sans400 from './fonts/source-sans-3-latin-400-normal.woff2?url';
import sans500 from './fonts/source-sans-3-latin-500-normal.woff2?url';
import sans600 from './fonts/source-sans-3-latin-600-normal.woff2?url';
export const FACES: readonly [family: string, url: string, weight: string][] = [
['Source Sans 3', sans400, '400'],
['Source Sans 3', sans500, '500'],
['Source Sans 3', sans600, '600'],
['Source Code Pro', codePro400, '400'],
];
/**
* Pixi measures a text the moment it is laid out, so the faces have to be usable before the
* first widget exists. A face that fails to load is reported and the fallback in `Theme` takes over.
*/
export async function loadEditorFonts(): Promise<void> {
await Promise.all(
FACES.map(async ([family, url, weight]) => {
try {
document.fonts.add(await new FontFace(family, `url("${url}")`, { weight }).load());
} catch (error) {
console.warn(`[fonts] ${family} ${weight} did not load`, error);
}
}),
);
}