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>
This commit is contained in:
1 parent
cbda6d64a7
commit
f2282a81fb
3 files changed
+25
-9
No files matched your search
@@ -2,13 +2,11 @@ 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';
|
||||
import sans700 from './fonts/source-sans-3-latin-700-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 Sans 3', sans700, '700'],
|
||||
['Source Code Pro', codePro400, '400'],
|
||||
];
|
||||
|
||||
|
||||
Binary file not shown.
+25
-7
@@ -97,27 +97,45 @@ function codePoints(file: string): Set<number> {
|
||||
return found;
|
||||
}
|
||||
|
||||
describe('editor fonts', () => {
|
||||
it('loads a face for every weight the editor sets (#214)', () => {
|
||||
const loaded = new Set(
|
||||
FACES.filter(([family]) => family === 'Source Sans 3').map(([, , weight]) => weight),
|
||||
);
|
||||
/** The weights `src/` sets as `fontWeight`, plus the 400 a style without one draws in. */
|
||||
function usedWeights(): Set<string> {
|
||||
const used = new Set(['400']);
|
||||
for (const file of sources('src'))
|
||||
for (const [, setting] of readFileSync(file, 'utf8').matchAll(/fontWeight:([^,\n}]*)/g))
|
||||
for (const [, weight] of setting!.matchAll(/'(\d{3}|bold|normal)'/g))
|
||||
used.add(weight === 'bold' ? '700' : weight === 'normal' ? '400' : weight!);
|
||||
return used;
|
||||
}
|
||||
|
||||
describe('editor fonts', () => {
|
||||
const loaded = new Set(
|
||||
FACES.filter(([family]) => family === 'Source Sans 3').map(([, , weight]) => weight),
|
||||
);
|
||||
|
||||
it('loads a face for every weight the editor sets (#214)', () => {
|
||||
const used = usedWeights();
|
||||
expect(used.has('500')).toBe(true);
|
||||
for (const weight of used) expect(loaded, `weight ${weight}`).toContain(weight);
|
||||
});
|
||||
|
||||
it('ships a file for every face it loads', () => {
|
||||
const files = readdirSync(FONT_DIR);
|
||||
// Every face is waited for before the editor starts (#273).
|
||||
it('loads no face the editor never sets', () => {
|
||||
const used = usedWeights();
|
||||
for (const weight of loaded) expect(used, `weight ${weight}`).toContain(weight);
|
||||
});
|
||||
|
||||
it('ships a file for every face it loads, and no other', () => {
|
||||
const files = readdirSync(FONT_DIR).filter((f) => f.endsWith('.woff2'));
|
||||
for (const [, url, weight] of FACES)
|
||||
expect(
|
||||
files.some((f) => url.endsWith(f)),
|
||||
`${url} (${weight})`,
|
||||
).toBe(true);
|
||||
for (const file of files)
|
||||
expect(
|
||||
FACES.some(([, url]) => url.endsWith(file)),
|
||||
file,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('reads the Latin subset from the files themselves', () => {
|
||||
|
||||
Reference in new issue
Block a user