From 8dec6020b9d46e711a090d767bfa89e12d5af3a2 Mon Sep 17 00:00:00 2001 From: Rostislav Rotaru Date: Sat, 28 Nov 2026 18:19:30 -0800 Subject: [PATCH 1/9] Add the symbols entry, which serves a site only the glyphs it draws @noldova/ui.components.angular/symbols is a Node.js tool, ported from the websites' scripts/material-symbols.ts. A site refreshes and checks its subset of Material Symbols from the kit's glyphs.json and its own code, and checks its built pages for a glyph the subset lacks or another copy of the font. styles/kit-without-symbol-font.css is everything kit.css loads but the whole font, with the symbol class's rules in styles/symbols.css. Agent: DEV7 (developer) Agent-Model: Anthropic Opus 5.5, Medium --- README.md | 6 +- documents/ARCHITECTURE.md | 3 + documents/KIT.md | 15 +- src/noldova.ui.components.angular/README.md | 2 +- .../angular.json | 4 + .../package.json | 4 + .../scripts/angular-package-builder.ts | 2 +- .../scripts/test.ts | 22 +- .../scripts/tsconfig.json | 1 + .../src/api/symbols.d.ts | 150 ++++++ .../src/api/symbols.ts | 10 + .../src/styles/kit-without-symbol-font.css | 23 + .../src/styles/kit.css | 13 +- .../src/styles/symbols.css | 24 + .../interfaces/i-material-symbols-site.ts | 19 + .../src/symbols/material-symbols.ts | 298 ++++++++++++ .../tests/fixtures/node-load/load.mts | 1 + .../tests/node/kit-stylesheets.test.ts | 45 ++ .../tests/node/material-symbols.test.ts | 444 ++++++++++++++++++ .../tsconfig.json | 3 + .../tsconfig.spec.json | 3 + .../tsconfig.symbols.json | 11 + 22 files changed, 1082 insertions(+), 21 deletions(-) create mode 100644 src/noldova.ui.components.angular/src/api/symbols.d.ts create mode 100644 src/noldova.ui.components.angular/src/api/symbols.ts create mode 100644 src/noldova.ui.components.angular/src/styles/kit-without-symbol-font.css create mode 100644 src/noldova.ui.components.angular/src/styles/symbols.css create mode 100644 src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts create mode 100644 src/noldova.ui.components.angular/src/symbols/material-symbols.ts create mode 100644 src/noldova.ui.components.angular/tests/node/kit-stylesheets.test.ts create mode 100644 src/noldova.ui.components.angular/tests/node/material-symbols.test.ts create mode 100644 src/noldova.ui.components.angular/tsconfig.symbols.json diff --git a/README.md b/README.md index 184eb12b..5b2109fa 100644 --- a/README.md +++ b/README.md @@ -75,12 +75,12 @@ A new release of a package the kit's peers pull in can turn these steps red with It then compares the installed kit's declarations and API documentation with its source, and checks the types of each package's `scripts/`. Those comparisons, and the kit's own build, which carries the documentation onto the declarations the Angular compiler writes, read the kit's source through TypeScript's compiler API in the same process, from `src/noldova.ui.components.angular/scripts/api/`. -`npm test` runs every test past the others' failures: the nativeElement assertions check, the OnPush strategies check, the poll and test limits check, the part glyphs check, on Linux x64 only the Kit bundles, the Kit copies, the Kit manifest and Angular's newest, and the kit's Angular specs, which must each report a result, with no test identity, the spec file and the titles of its suites and test, repeated, then, on Linux only, builds the docs site and tests it, as `npm run docs:build` and `npm run docs:test` do, as the static site it serves is the same on every platform. +`npm test` runs every test past the others' failures: the nativeElement assertions check, the OnPush strategies check, the poll and test limits check, the part glyphs check, on Linux x64 only the Kit bundles, the Kit copies, the Kit manifest and Angular's newest, the kit's Node.js tests, `src/noldova.ui.components.angular/tests/node/*.test.ts`, with `node --test`, of the symbols entry and the stylesheets that load the symbol font, which no browser loads, and the kit's Angular specs, which must each report a result, with no test identity, the spec file and the titles of its suites and test, repeated, then, on Linux only, builds the docs site and tests it, as `npm run docs:build` and `npm run docs:test` do, as the static site it serves is the same on every platform. With `NOLDOVA_SEPARATE_TEST=docs`, as the CI targets' tests set it, `npm test` leaves the docs site out, and the CI run's "Separate test" job checks it once, with `npm run build` and `npm run test:docs`. The kit's Angular specs run in two runs of Angular's test builder, each in a browser of its own: first every test but those in a `describe(LayoutTraceFixture.suite, ...)`, then, from the spec files that hold one, only those. A layout trace records every tab of its browser, so in the first browser, under the whole suite, one could take over 10 seconds to end and keep another spec's trace from starting ([#198](https://github.com/noldova-com/ui-components/issues/198)); in the second only the tracing tests run. Both runs use the Angular `part` configuration, and the script adds up their coverage as `npm run test:merge` does below, gating it on a whole run. The suite's title is in `src/noldova.ui.components.angular/tests/fixtures/layout-trace-suite.ts`, which the fixture and the script both read. After both runs, the script fails unless each test in either run's report passed or failed in exactly one of them, and the second run ran at least one test, so a traced test that both filters skip, or that both run, fails the run. -`npm test -- --shard=/`, with 2 to 8 parts, runs only every ``-th spec file of the kit's sorted list, from the ``-th, with the Angular `part` configuration, which keeps the coverage report in `_build/angular-coverage` without gating it, and runs the checks before the specs only in part 1. +`npm test -- --shard=/`, with 2 to 8 parts, runs only every ``-th spec file of the kit's sorted list, from the ``-th, with the Angular `part` configuration, which keeps the coverage report in `_build/angular-coverage` without gating it, and runs the checks and the Node.js tests before the specs only in part 1. `npm run test:merge -- `, with Node.js alone, first checks itself on small reports in a temporary folder, then adds up the coverage of the parts, each in a subfolder of ``, by where each function, statement and branch sits in its file, from only the parts that loaded the file, since a part that never loaded it maps it from its source and can map it otherwise, and fails as `npm test` does below the requirement in [Coverage](#coverage), naming what no part reached; it also fails when fewer subfolders than `` came, or when one holds no report or one that isn't JSON. -`npm test -- ...` runs only the spec files whose path from the repository root holds a filter, without the coverage gates, the nativeElement assertions check, the OnPush strategies check, the poll and test limits check, the part glyphs check, the Kit bundles, the Kit copies, the Kit manifest, Angular's newest and the docs site, and fails when nothing matches. +`npm test -- ...` runs only the spec files and Node.js tests whose path from the repository root holds a filter, without the coverage gates, the nativeElement assertions check, the OnPush strategies check, the poll and test limits check, the part glyphs check, the Kit bundles, the Kit copies, the Kit manifest, Angular's newest and the docs site, and fails when nothing matches. `npm run test:timing`, after `npm test`, is the timing check that [Time per file](#time-per-file) describes; CI doesn't run it, since its pass condition is a time, and it belongs on a test machine. The root's `npm run build:components` and `npm test` run each workspace's own `build` and `test`, and `npm run build:docs` each workspace's own `docs:build`, passing on what follows `--`; each package's scripts run from its own folder, with paths relative to it, and write to the root's `_build/` and `_packages/`. The kit's entry points are `src/noldova.ui.components.angular/scripts/build.ts` and `src/noldova.ui.components.angular/scripts/test.ts`, and the docs site's are in `src/noldova.ui.components.angular.docs/scripts/`. diff --git a/documents/ARCHITECTURE.md b/documents/ARCHITECTURE.md index 915f35e7..d8ba90b1 100644 --- a/documents/ARCHITECTURE.md +++ b/documents/ARCHITECTURE.md @@ -20,6 +20,7 @@ | Lazy pages | The entries an app's start imports instead of the main one, `@noldova/ui.components.angular/button`, `@noldova/ui.components.angular/typography` and, for a website, `@noldova/ui.components.angular/site` or, for a start that shows only the site's header and footer, their own entries, `@noldova/ui.components.angular/site/header` and `/site/footer`, with the stage service's, `/site/stage`, and the code block's and the other site parts', `@noldova/ui.components.angular/code-block` and `/site/hero`, `/site/section`, `/site/card` and `/site/closing`, which a lazy page imports; each exports the same classes as the main entry, so the parts only a lazy page uses come in its own chunk, but for the site's header, footer and search slot, which only the site entry and theirs export: their tooltips import the tooltip's engine lazily, and a lazy import anywhere in the main entry's graph would split the engine out of every app's start. The Kit bundles check keeps the code block out of the start of such an app, the Angular CDK out of a website's, and the site's hero, sections, cards and closing out of the start of a website that shows only its header and footer there and takes the stage service from its entry. | | Code highlighting | The highlighter and its grammars, which an app turns on with `provideCodeHighlighting()` from `@noldova/ui.components.angular/code-highlighting` and which then load lazily, or ahead while the page is idle for the languages it names in `preload`; with `provideCodeHighlightingWorker`, they load and tokenize in the app's worker, whose file calls `serveCodeHighlighting` from `@noldova/ui.components.angular/code-highlighting/worker` and holds every grammar, with no lazy import. The package declares no side effects, and the Kit bundles check keeps an app without the provider free of them. | | Markdown | The parser of a message's text, `markdown-it`, which an app turns on with `provideMarkdown()` from `@noldova/ui.components.angular/markdown` and which then loads lazily; without it a message shows its text plain. The same entry point exports the markdown view, `MarkdownViewComponent`, for an app that lays out its own message. The Kit bundles check keeps an app without the provider free of it. | +| Symbol subsets | A Node.js tool, `MaterialSymbols` in `src/symbols`, which a site imports from `@noldova/ui.components.angular/symbols` to serve only the symbol glyphs it draws, with `styles/kit-without-symbol-font.css` in place of `styles/kit.css`, as [KIT.md](KIT.md#icons-a-site-subsets) says; no browser loads it. | | Testing helpers | The fixtures and providers of the kit's own tests, in `src/testing`, which products' tests import from `@noldova/ui.components.angular/testing`. The build keeps every other entry from reaching them or Vitest. | ## Dependencies @@ -59,6 +60,8 @@ The code rules only this repository has; [Noldova's standards](https://github.co Only the package's testing entry, `src/api/testing.ts`, imports it, so an app's bundle never takes the helpers. The build refuses any other entry that reaches it or imports `vitest`. It compiles that entry on its own, with `tsconfig.testing.json`, which adds the Node.js types Vitest's declarations use, so the other entries' code never sees them. +- **Node.js code:** the symbols entry, `src/api/symbols.ts`, and its source in `src/symbols/` run only in Node.js. + The build compiles that entry on its own, with `tsconfig.symbols.json`, which adds the Node.js types; the specs' compile and the Angular specs' coverage leave it out, and its tests are `node --test` files in `tests/node/`. - **Foundation value checks:** the kit's production code uses context.core's additions to the global `Object` and `String` constructors. The value checks are `Object.isUndefined`, `Object.isNull`, `Object.isNullOrUndefined`, `Object.isString`, `Object.isNumber`, `Object.isBigInt`, `Object.isBoolean`, `Object.isObject`, `Object.isFunction`, `String.isNullOrEmpty` and `String.isNullOrWhitespace`, and the empty string is `String.empty`. They replace comparisons with `undefined` and `null`, comparisons of a `typeof` result, and `""`. diff --git a/documents/KIT.md b/documents/KIT.md index 18c18c98..14e834c1 100644 --- a/documents/KIT.md +++ b/documents/KIT.md @@ -281,11 +281,20 @@ A compact row, as tall as an icon button, takes `--nol-icon-button`, 1.375rem, f ## Icons a site subsets -A site that serves a subset of the symbol font, rather than the whole font, takes the glyphs the kit's parts draw from the package's `glyphs.json`, exported as `@noldova/ui.components.angular/glyphs.json`. -The kit's build writes it from the kit's source, as the README's [Part glyphs](../README.md#part-glyphs) check reads it; nobody keeps it by hand. +`kit.css` loads the whole Material Symbols font, about 5.4 MB, so a site that draws a few dozen glyphs, such as a website or a documentation site, serves a subset of it instead, holding only the glyphs its pages and parts draw. + +The kit's build writes the glyphs its parts draw, from the kit's source, to the package's `glyphs.json`, exported as `@noldova/ui.components.angular/glyphs.json`, as the README's [Part glyphs](../README.md#part-glyphs) check reads them; nobody keeps it by hand. It is `{ "parts": { "": ["", …], … } }`: for each part the package's entries export, by its class name, such as `SiteHeaderComponent`, the sorted names of the glyphs it can draw, those of the kit's parts it shows included. A glyph the site passes to a part, such as an icon button's `icon` or a `SiteAction`'s, is in no list. -A site subsets the font to the union of the lists of the parts it imports, with every icon it names itself. +The icon chooser's and the gallery's lists hold every name of the set, since they can draw any of them. + +A site gets its subset from the entry `@noldova/ui.components.angular/symbols`, a Node.js tool that loads in no browser: +- Its `MaterialSymbols` reads the union of the `glyphs.json` lists of the kit's parts the site's code imports, the icons its templates draw between the symbol class's span tags or give a part as `icon="…"`, the glyphs its code keeps in a field whose name ends in glyph, and the names the site gives it for icons its code builds; a refresh, which the site runs as `npm run symbols`, downloads that subset from Google Fonts with its license, keeps it in the site's fonts folder named by its SHA-256, points the site's `@font-face` at it and records its SHA-256 and source in the site's license notice. +- Its check, `npm run symbols -- --check` in the site's checks, fails when the committed font, its record, its stylesheet or the glyphs the site draws disagree. +- Its `drawnGlyphs` expression and `findPageProblemsAsync` let the site's check of its built pages fail on a page that draws a glyph the subset lacks, or that loads another copy of the font, such as the whole font `kit.css` brings. + +Such a site loads `styles/kit-without-symbol-font.css` in place of `styles/kit.css`: everything `kit.css` loads but the whole font, with the symbol class's text rules, `styles/symbols.css`, first, and declares the subset's `@font-face` for the family `Material Symbols Rounded` itself. +A page that must draw any glyph, such as the icon chooser's, loads the whole font under a family of its own, so the browser fetches it only on that page. ## Controls diff --git a/src/noldova.ui.components.angular/README.md b/src/noldova.ui.components.angular/README.md index 58dde9b3..f322ac5f 100644 --- a/src/noldova.ui.components.angular/README.md +++ b/src/noldova.ui.components.angular/README.md @@ -1,7 +1,7 @@ # @noldova/ui.components.angular Noldova's interface kit: the design tokens, the fonts and the Angular components that Noldova's products build their interfaces from. -Its public API is everything the package exports through its entries: `@noldova/ui.components.angular`, `@noldova/ui.components.angular/button`, `@noldova/ui.components.angular/code-block`, `@noldova/ui.components.angular/code-highlighting`, `@noldova/ui.components.angular/code-highlighting/worker`, `@noldova/ui.components.angular/gallery`, `@noldova/ui.components.angular/markdown`, `@noldova/ui.components.angular/site`, its part entries `@noldova/ui.components.angular/site/card`, `@noldova/ui.components.angular/site/closing`, `@noldova/ui.components.angular/site/footer`, `@noldova/ui.components.angular/site/header`, `@noldova/ui.components.angular/site/hero` and `@noldova/ui.components.angular/site/section`, its stage entry `@noldova/ui.components.angular/site/stage`, `@noldova/ui.components.angular/testing` and `@noldova/ui.components.angular/typography`. +Its public API is everything the package exports through its entries: `@noldova/ui.components.angular`, `@noldova/ui.components.angular/button`, `@noldova/ui.components.angular/code-block`, `@noldova/ui.components.angular/code-highlighting`, `@noldova/ui.components.angular/code-highlighting/worker`, `@noldova/ui.components.angular/gallery`, `@noldova/ui.components.angular/markdown`, `@noldova/ui.components.angular/site`, its part entries `@noldova/ui.components.angular/site/card`, `@noldova/ui.components.angular/site/closing`, `@noldova/ui.components.angular/site/footer`, `@noldova/ui.components.angular/site/header`, `@noldova/ui.components.angular/site/hero` and `@noldova/ui.components.angular/site/section`, its stage entry `@noldova/ui.components.angular/site/stage`, `@noldova/ui.components.angular/symbols`, a Node.js tool that serves a site only the symbol glyphs it draws, as [KIT.md](../../documents/KIT.md#icons-a-site-subsets) says, `@noldova/ui.components.angular/testing` and `@noldova/ui.components.angular/typography`. Its type declarations carry the documentation of every export and public member, which editors show on hover and in completions. ## What an app needs diff --git a/src/noldova.ui.components.angular/angular.json b/src/noldova.ui.components.angular/angular.json index 255880a0..1f232b00 100644 --- a/src/noldova.ui.components.angular/angular.json +++ b/src/noldova.ui.components.angular/angular.json @@ -40,6 +40,10 @@ "coverageInclude": [ "src/**/*.ts" ], + "coverageExclude": [ + "src/api/symbols.ts", + "src/symbols/**" + ], "coverageReporters": [ "text", "json-summary", diff --git a/src/noldova.ui.components.angular/package.json b/src/noldova.ui.components.angular/package.json index 5bad06a5..448896e0 100644 --- a/src/noldova.ui.components.angular/package.json +++ b/src/noldova.ui.components.angular/package.json @@ -78,6 +78,10 @@ "types": "./api/site-stage.d.ts", "default": "./api/site-stage.js" }, + "./symbols": { + "types": "./api/symbols.d.ts", + "default": "./api/symbols.js" + }, "./testing": { "types": "./api/testing.d.ts", "default": "./api/testing.js" diff --git a/src/noldova.ui.components.angular/scripts/angular-package-builder.ts b/src/noldova.ui.components.angular/scripts/angular-package-builder.ts index d92c1688..8bcdfeee 100644 --- a/src/noldova.ui.components.angular/scripts/angular-package-builder.ts +++ b/src/noldova.ui.components.angular/scripts/angular-package-builder.ts @@ -23,7 +23,7 @@ export class AngularPackageBuilder { private static readonly CARRY_TIMEOUT: number = 300_000; private static readonly CARRY_SCRIPT: readonly string[] = ["scripts", "carry-docs.ts"]; private static readonly PROJECT_FILE: string = "tsconfig.json"; - private static readonly ENTRY_PROJECTS: ReadonlyMap = new Map([["testing.ts", "tsconfig.testing.json"]]); + private static readonly ENTRY_PROJECTS: ReadonlyMap = new Map([["symbols.ts", "tsconfig.symbols.json"], ["testing.ts", "tsconfig.testing.json"]]); private static readonly SOURCE_FOLDER: string = "src"; private static readonly ENTRY_FOLDER: string = "api"; private static readonly STYLES_FOLDER: string = "styles"; diff --git a/src/noldova.ui.components.angular/scripts/test.ts b/src/noldova.ui.components.angular/scripts/test.ts index 2df37722..b9e2c354 100644 --- a/src/noldova.ui.components.angular/scripts/test.ts +++ b/src/noldova.ui.components.angular/scripts/test.ts @@ -37,6 +37,10 @@ export class Test extends Script { private static readonly BLANK_LINE: string = ""; private static readonly FILTERED_COVERAGE_SKIPPED: string = "Coverage gates, the nativeElement assertions check, the OnPush strategies check, the poll and test limits check, the Failure screenshots check, the Kit bundles, the Kit copies, the Kit manifest and Angular's newest skipped for a filtered run."; private static readonly NO_TEST_MATCHED: string = "No test matched the filters."; + private static readonly NODE_TESTS_TITLE: string = "The Node.js tests"; + private static readonly NODE_TESTS_FOLDER: string = "tests/node"; + private static readonly NODE_TEST_FILE: string = ".test.ts"; + private static readonly NODE_TEST_OPTION: string = "--test"; private static readonly KIT_CHECK_PLATFORM: NodeJS.Platform = "linux"; private static readonly KIT_CHECK_ARCHITECTURE: NodeJS.Architecture = "x64"; private static readonly KIT_CHECKS_SKIPPED: string = "The Kit bundles, the Kit copies, the Kit manifest and Angular's newest run only on Linux x64; skipped."; @@ -107,13 +111,14 @@ export class Test extends Script { await this.writeLogAsync(Test.KIT_CHECKS_SKIPPED); } } + const nodeTests = await this.runNodeTestsAsync(filters, shard); const selected = await this.runAngularTestsAsync(filters, shard); if (!Object.isNull(shard)) await this.writeLogAsync(Test.partRun(shard.part, shard.parts, selected)); if (isFiltered) { await this.writeLogAsync(Test.FILTERED_COVERAGE_SKIPPED); - if (selected === 0) { + if (selected + nodeTests === 0) { await this.writeLogAsync(Test.NO_TEST_MATCHED); this.failed = true; } @@ -130,6 +135,21 @@ export class Test extends Script { this.failed = true; } + // The Node.js tests, of code that loads in no browser: every one in a whole run and in a shard's first part, and those the filters + // match in a filtered run. + private async runNodeTestsAsync(filters: readonly string[], shard: TestShard | null): Promise { + const files = (await fs.readdir(Test.NODE_TESTS_FOLDER)).filter(t => t.endsWith(Test.NODE_TEST_FILE)).sort().map(t => `${Test.NODE_TESTS_FOLDER}/${t}`); + const selected = filters.length === 0 + ? Object.isNull(shard) || shard.part === 1 ? files : [] + : files.filter(t => filters.some(u => `${Test.KIT_FOLDER}/${t}`.includes(u))); + if (selected.length === 0) + return 0; + await this.writeLogAsync(Test.BLANK_LINE); + await this.writeLogAsync(Test.NODE_TESTS_TITLE); + await this.runCommandAsync(process.execPath, [Test.NODE_TEST_OPTION, ...selected], Test.WORKSPACE_FOLDER); + return selected.length; + } + private async runAngularTestsAsync(filters: readonly string[], shard: TestShard | null): Promise { const specs = await this.report.listSpecFilesAsync(); const matched = filters.length === 0 ? specs : specs.filter(t => filters.some(u => `${Test.KIT_FOLDER}/${t}`.includes(u))); diff --git a/src/noldova.ui.components.angular/scripts/tsconfig.json b/src/noldova.ui.components.angular/scripts/tsconfig.json index 8b4cea03..1df16453 100644 --- a/src/noldova.ui.components.angular/scripts/tsconfig.json +++ b/src/noldova.ui.components.angular/scripts/tsconfig.json @@ -14,6 +14,7 @@ "../tests/coverage/**/*.ts", "../tests/fixtures/layout-trace-suite.ts", "../tests/network/**/*.ts", + "../tests/node/**/*.ts", "../tests/screenshots/**/*.ts" ] } diff --git a/src/noldova.ui.components.angular/src/api/symbols.d.ts b/src/noldova.ui.components.angular/src/api/symbols.d.ts new file mode 100644 index 00000000..f4b0d445 --- /dev/null +++ b/src/noldova.ui.components.angular/src/api/symbols.d.ts @@ -0,0 +1,150 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * Where a site keeps what its subset of the symbol font needs. Every path is + * relative to `root`, written with forward slashes. + */ +export interface IMaterialSymbolsSite { + /** + * The site's own folder, such as its Angular project's, from which every + * other path is read. + */ + readonly root: string; + + /** + * The folder of the site's code, read for the kit's parts it imports, the + * icons its templates draw or give a part's `icon`, and the glyphs its code + * keeps by name; `src` when left out. + */ + readonly code?: string; + + /** + * The stylesheet whose `@font-face` loads the subset, which a refresh + * points at the new font; `src/styles.css` when left out. + */ + readonly styles?: string; + + /** + * The folder that holds the subset and nothing else of the font; + * `public/assets/fonts` when left out. + */ + readonly fonts?: string; + + /** + * The folder of the site's license notice, `README.txt`, and of the + * font's license, `MATERIAL-SYMBOLS-LICENSE.txt`; `public/assets/licenses` + * when left out. + */ + readonly licenses?: string; + + /** + * The address the site serves the fonts folder at, which the stylesheet's + * `@font-face` names; `/assets/fonts/` when left out. + */ + readonly fontsAddress?: string; + + /** + * The kit's `glyphs.json`, the glyphs each part can draw; the installed + * kit's, `node_modules/@noldova/ui.components.angular/glyphs.json`, when + * left out. + */ + readonly kitGlyphs?: string; + + /** + * The icons the site draws that its code doesn't name where the subset's + * reading finds them, such as an icon its code builds or reads from data. + */ + readonly names?: readonly string[]; +} + +/** + * Serves a site only the Material Symbols glyphs it draws, rather than the + * whole font, about 5.4 MB, that `styles/kit.css` loads: a Node.js tool, + * which loads in no browser. + * + * The subset holds the union of the `glyphs.json` lists of the kit's parts the + * site's code imports, with the icons its templates draw or give a part's + * `icon`, the glyphs its code keeps in a field whose name ends in glyph, and + * the site's own `names`. A refresh asks Google Fonts for that subset, keeps + * it in the fonts folder named by its SHA-256, points the stylesheet at it + * and records its SHA-256 and source address in the license notice; the check + * reads it all again and fails where any of it disagrees, and the site's + * check of its built pages fails on a page that draws a glyph the subset lacks + * or loads another copy of the font. + * + * @example + * ```ts + * import { MaterialSymbols } from "@noldova/ui.components.angular/symbols"; + * + * // npm run symbols refreshes the subset; npm run symbols -- --check checks it. + * await new MaterialSymbols({ root: process.cwd() }).runAsync(process.argv.slice(2)); + * ``` + */ +export declare class MaterialSymbols { + /** + * The font's family, `Material Symbols Rounded`, which the site's + * `@font-face` gives the subset. + */ + public static readonly family: string; + + /** + * An expression to evaluate in a built page, such as with Playwright's + * `page.evaluate`, that gives as JSON the sorted names of the glyphs the + * page shows in {@link MaterialSymbols.family}: the text of each element + * whose first font family it is. + */ + public static readonly drawnGlyphs: string; + + /** + * @param site Where the site keeps its subset. + */ + public constructor(site: IMaterialSymbolsSite); + + /** + * Checks the subset when the arguments hold `--check`, and refreshes it + * otherwise. + * + * @param args The command line's arguments. + * @returns Resolves once the check or the refresh is done, and rejects with + * the check's problems or the refresh's failure. + */ + public runAsync(args: readonly string[]): Promise; + + /** + * Downloads the subset of the icons the site draws from Google Fonts, with + * the font's license, and writes the font, the stylesheet's address of it + * and the notice's record of it, keeping the notice's other lines. + * + * @returns Resolves once the subset is written, and rejects, leaving the + * notice as it was, when a download fails or answers something else. + */ + public refreshAsync(): Promise; + + /** + * Fails, naming each problem, unless the fonts folder holds only the + * recorded subset, named by its SHA-256 and matching it, the stylesheet + * loads it, it holds exactly the icons the site draws, and the license is + * there. + * + * @returns Resolves when the subset agrees with all of it. + */ + public checkAsync(): Promise; + + /** + * What is wrong with one built page: each glyph it draws that the recorded + * subset lacks, and each font it loads whose name holds `material-symbols` + * other than the subset, such as the whole font. + * + * @param page The page's address, which each problem names. + * @param drawn The glyphs {@link MaterialSymbols.drawnGlyphs} gave. + * @param fonts The full addresses of the fonts the page loaded. + * @returns The problems, none when the page is right. + */ + public findPageProblemsAsync(page: string, drawn: readonly string[], fonts: readonly string[]): Promise; +} diff --git a/src/noldova.ui.components.angular/src/api/symbols.ts b/src/noldova.ui.components.angular/src/api/symbols.ts new file mode 100644 index 00000000..384f3a55 --- /dev/null +++ b/src/noldova.ui.components.angular/src/api/symbols.ts @@ -0,0 +1,10 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +export type { IMaterialSymbolsSite } from "../symbols/interfaces/i-material-symbols-site.js"; +export { MaterialSymbols } from "../symbols/material-symbols.js"; diff --git a/src/noldova.ui.components.angular/src/styles/kit-without-symbol-font.css b/src/noldova.ui.components.angular/src/styles/kit-without-symbol-font.css new file mode 100644 index 00000000..69e8f424 --- /dev/null +++ b/src/noldova.ui.components.angular/src/styles/kit-without-symbol-font.css @@ -0,0 +1,23 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +/* Everything kit.css loads but the whole Material Symbols font, for a site that serves its own subset of it, as the symbols + * entry makes; the site declares the subset's @font-face. */ +@import "./symbols.css"; +@import "katex/dist/katex.css"; +@import "./fonts.css"; +@import "./base.css"; +@import "./drop-line.css"; +@import "./mention-field.css"; +@import "./overlays.css"; +@import "./popover.css"; +@import "./scroll.css"; +@import "./site.css"; +@import "./terminal.css"; +@import "./status.css"; +@import "@angular/cdk/a11y-prebuilt.css"; diff --git a/src/noldova.ui.components.angular/src/styles/kit.css b/src/noldova.ui.components.angular/src/styles/kit.css index 979adf87..3d0b6228 100644 --- a/src/noldova.ui.components.angular/src/styles/kit.css +++ b/src/noldova.ui.components.angular/src/styles/kit.css @@ -7,15 +7,4 @@ */ @import "material-symbols/rounded.css"; -@import "katex/dist/katex.css"; -@import "./fonts.css"; -@import "./base.css"; -@import "./drop-line.css"; -@import "./mention-field.css"; -@import "./overlays.css"; -@import "./popover.css"; -@import "./scroll.css"; -@import "./site.css"; -@import "./terminal.css"; -@import "./status.css"; -@import "@angular/cdk/a11y-prebuilt.css"; +@import "./kit-without-symbol-font.css"; diff --git a/src/noldova.ui.components.angular/src/styles/symbols.css b/src/noldova.ui.components.angular/src/styles/symbols.css new file mode 100644 index 00000000..aca04dcf --- /dev/null +++ b/src/noldova.ui.components.angular/src/styles/symbols.css @@ -0,0 +1,24 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +/* The Material Symbols class's text rules with no font, for a site that serves its own subset of the font and declares the + * subset's @font-face itself. */ +.material-symbols-rounded { + font-family: "Material Symbols Rounded"; + font-weight: 400; + font-style: normal; + letter-spacing: normal; + text-transform: none; + display: inline-block; + white-space: nowrap; + word-wrap: normal; + direction: ltr; + font-feature-settings: "liga"; + -webkit-font-smoothing: antialiased; + flex-shrink: 0; +} diff --git a/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts b/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts new file mode 100644 index 00000000..b2973396 --- /dev/null +++ b/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts @@ -0,0 +1,19 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +// Where a site keeps what its subset of the symbol font needs, each path relative to its root. +export interface IMaterialSymbolsSite { + readonly root: string; + readonly code?: string; + readonly styles?: string; + readonly fonts?: string; + readonly licenses?: string; + readonly fontsAddress?: string; + readonly kitGlyphs?: string; + readonly names?: readonly string[]; +} diff --git a/src/noldova.ui.components.angular/src/symbols/material-symbols.ts b/src/noldova.ui.components.angular/src/symbols/material-symbols.ts new file mode 100644 index 00000000..a43815c6 --- /dev/null +++ b/src/noldova.ui.components.angular/src/symbols/material-symbols.ts @@ -0,0 +1,298 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +import "@noldova/context.core"; +import { createHash } from "node:crypto"; +import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises"; +import path from "node:path"; + +import type { IMaterialSymbolsSite } from "./interfaces/i-material-symbols-site.js"; + +// Self-hosts the subset of Material Symbols a site draws, and records its SHA-256 beside its license notice; its check fails when +// the committed font, its record, its notice or the icons the site draws disagree, and its page check when a built page draws a +// glyph the subset lacks or loads another copy of the font. Every path is under the site's root folder. +export class MaterialSymbols { + public static readonly family: string = "Material Symbols Rounded"; + // A page expression that gives, as JSON, the sorted names each element drawn in the symbol font's own family shows as its text. + public static readonly drawnGlyphs: string = + `JSON.stringify([...new Set([...document.querySelectorAll('body *')].filter(t => getComputedStyle(t).fontFamily.split(',')[0].replaceAll('"', '').replaceAll("'", '').trim() === '${MaterialSymbols.family}' && [...t.childNodes].some(u => u.nodeType === Node.TEXT_NODE && (u.textContent ?? '').trim() !== '')).map(t => (t.textContent ?? '').trim()))].sort())`; + private static readonly KIT_NAME: string = "@noldova/ui.components.angular"; + private static readonly DEFAULT_CODE: string = "src"; + private static readonly DEFAULT_STYLES: string = "src/styles.css"; + private static readonly DEFAULT_FONTS: string = "public/assets/fonts"; + private static readonly DEFAULT_LICENSES: string = "public/assets/licenses"; + private static readonly DEFAULT_FONTS_ADDRESS: string = "/assets/fonts/"; + private static readonly DEFAULT_KIT_GLYPHS: string = `node_modules/${MaterialSymbols.KIT_NAME}/glyphs.json`; + private static readonly NOTICE: string = "README.txt"; + private static readonly LICENSE: string = "MATERIAL-SYMBOLS-LICENSE.txt"; + private static readonly CHECK_OPTION: string = "--check"; + private static readonly TIMEOUT: number = 30_000; + private static readonly BROWSER: string = + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"; + private static readonly LICENSE_ADDRESS: string = "https://raw.githubusercontent.com/google/material-design-icons/master/LICENSE"; + private static readonly SOURCE_ADDRESS: string = "https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@24,400,0,0&icon_names="; + private static readonly SOURCE_END: string = "&display=swap"; + private static readonly FONT_ADDRESS: RegExp = /url\((https:\/\/fonts\.gstatic\.com\/[^)]+)\)/u; + // An icon a template draws by its name, written between the symbol font's span tags. + private static readonly DRAWN_ICON: RegExp = /]*material-symbols-rounded[^>]*>\s*([a-z0-9_]+)\s*<\/span\s*>/gu; + // An icon a template hands a part by its name, as its icon attribute. + private static readonly GIVEN_ICON: RegExp = /\sicon="([a-z0-9_]+)"/gu; + // A glyph the site's code keeps by its name, in a field or constant whose name ends in glyph or Glyph. + private static readonly KEPT_GLYPH: RegExp = /[gG]lyph(?:: IconName =|:) "([a-z0-9_]+)"/gu; + // The names the site's code imports from any of the kit's entry points. + private static readonly KIT_IMPORT: RegExp = /import (?:type )?\{([^}]+)\} from "@noldova\/ui\.components\.angular(?:\/[a-z-]+)*";/gu; + private static readonly FONT_NAME: RegExp = /^material-symbols-([a-f0-9]{8})\.woff2$/u; + private static readonly ANY_FONT_NAME: RegExp = /^material-symbols(?:-[a-f0-9]{8})?\.woff2$/u; + private static readonly STYLES_FONT: RegExp = /material-symbols(?:-[a-f0-9]{8})?\.woff2/gu; + private static readonly RECORD: RegExp = /^SHA-256: ([a-f0-9]{64}) {2}(\S+)$/mu; + private static readonly SOURCE: RegExp = /^Source: (\S+)$/mu; + private static readonly LINES: RegExp = /\r?\n/u; + // A line of the subset's own record in the notice, which a refresh writes again. + private static readonly RECORD_LINE: RegExp = + /^(?:Material Symbols is from |The site serves a subset of it, |SHA-256: [a-f0-9]{64} {2}material-symbols-[a-f0-9]{8}\.woff2$|Source: https:\/\/fonts\.googleapis\.com\/)/u; + private static readonly ENCODING: BufferEncoding = "utf8"; + private static readonly MISSING_FILE: string = "ENOENT"; + + private readonly root: string; + private readonly code: string; + private readonly styles: string; + private readonly fonts: string; + private readonly notice: string; + private readonly license: string; + private readonly fontsAddress: string; + private readonly kitGlyphs: string; + private readonly names: readonly string[]; + + public constructor(site: IMaterialSymbolsSite) { + this.root = site.root; + this.code = site.code ?? MaterialSymbols.DEFAULT_CODE; + this.styles = site.styles ?? MaterialSymbols.DEFAULT_STYLES; + this.fonts = site.fonts ?? MaterialSymbols.DEFAULT_FONTS; + const licenses = site.licenses ?? MaterialSymbols.DEFAULT_LICENSES; + this.notice = path.posix.join(licenses, MaterialSymbols.NOTICE); + this.license = path.posix.join(licenses, MaterialSymbols.LICENSE); + this.fontsAddress = site.fontsAddress ?? MaterialSymbols.DEFAULT_FONTS_ADDRESS; + this.kitGlyphs = site.kitGlyphs ?? MaterialSymbols.DEFAULT_KIT_GLYPHS; + this.names = site.names ?? []; + } + + // What the command line asks for: with --check, the check, and otherwise the refresh. + public async runAsync(args: readonly string[]): Promise { + await (args.includes(MaterialSymbols.CHECK_OPTION) ? this.checkAsync() : this.refreshAsync()); + } + + public async refreshAsync(): Promise { + const names = await this.iconNamesAsync(); + const address = MaterialSymbols.sourceAddress(names); + const response = await fetch(address, { headers: { "User-Agent": MaterialSymbols.BROWSER }, signal: AbortSignal.timeout(MaterialSymbols.TIMEOUT) }); + if (!response.ok) + throw new Error(`Font stylesheet download failed: ${response.status}`); + const match = MaterialSymbols.FONT_ADDRESS.exec(await response.text()); + if (Object.isUndefined(match?.[1])) + throw new Error("Expected an official Google Fonts font URL."); + const font = await fetch(match[1], { signal: AbortSignal.timeout(MaterialSymbols.TIMEOUT) }); + if (!font.ok) + throw new Error(`Font download failed: ${font.status}`); + const bytes = Buffer.from(await font.arrayBuffer()); + if (bytes.subarray(0, 4).toString() !== "wOF2") + throw new Error("Expected a WOFF2 font."); + await mkdir(this.at(this.fonts), { recursive: true }); + const digest = MaterialSymbols.sha256(bytes); + const filename = `material-symbols-${digest.slice(0, 8)}.woff2`; + await writeFile(path.join(this.at(this.fonts), filename), bytes); + for (const entry of await readdir(this.at(this.fonts))) + if (MaterialSymbols.ANY_FONT_NAME.test(entry) && entry !== filename) + await rm(path.join(this.at(this.fonts), entry)); + const styles = await readFile(this.at(this.styles), MaterialSymbols.ENCODING); + await writeFile(this.at(this.styles), styles.replace(MaterialSymbols.STYLES_FONT, filename)); + const license = await fetch(MaterialSymbols.LICENSE_ADDRESS, { signal: AbortSignal.timeout(MaterialSymbols.TIMEOUT) }); + if (!license.ok) + throw new Error("Material Symbols license download failed."); + await mkdir(path.dirname(this.at(this.license)), { recursive: true }); + await writeFile(this.at(this.license), `${(await license.text()).trimEnd()}\n`); + const notice = await this.noticeTextAsync(); + await writeFile(this.at(this.notice), this.noticeOf(notice, filename, digest, address)); + console.log(`Self-hosted ${names.size} Material Symbols in ${bytes.length} bytes, SHA-256 ${digest}.`); + } + + public async checkAsync(): Promise { + const problems: string[] = []; + const notice = await readFile(this.at(this.notice), MaterialSymbols.ENCODING); + const record = MaterialSymbols.RECORD.exec(notice); + const source = MaterialSymbols.SOURCE.exec(notice); + const fonts = (await readdir(this.at(this.fonts))).filter(t => t.startsWith("material-symbols")).sort(); + if (Object.isUndefined(record?.[1]) || Object.isUndefined(record[2]) || Object.isUndefined(source?.[1])) + problems.push(`${this.notice} records no SHA-256 or source.`); + else { + const digest = record[1]; + const filename = record[2]; + if (fonts.length !== 1 || fonts[0] !== filename) + problems.push(`${this.fonts} holds ${fonts.join(", ") || "no font"}, not only the recorded ${filename}.`); + else if (MaterialSymbols.sha256(await readFile(path.join(this.at(this.fonts), filename))) !== digest) + problems.push(`${filename} does not match its recorded SHA-256.`); + if (MaterialSymbols.FONT_NAME.exec(filename)?.[1] !== digest.slice(0, 8)) + problems.push(`${filename} is not named by its SHA-256.`); + if (!(await readFile(this.at(this.styles), MaterialSymbols.ENCODING)).includes(`${this.fontsAddress}${filename}`)) + problems.push(`${this.styles} does not load ${filename}.`); + if (source[1] !== MaterialSymbols.sourceAddress(await this.iconNamesAsync())) + problems.push("The icons the site draws differ from the recorded subset; run npm run symbols."); + } + if (!(await readFile(this.at(this.license), MaterialSymbols.ENCODING).catch(() => "")).includes("Apache License")) + problems.push(`${this.license} does not hold the Apache 2.0 license.`); + if (problems.length > 0) + throw new Error(problems.join("\n")); + console.log("The Material Symbols subset matches its recorded SHA-256, its notice and the icons the site draws."); + } + + // What is wrong with one built page: each glyph it draws that the recorded subset lacks, and each copy of the symbol font it loads + // other than the recorded subset, given the glyphs drawnGlyphs read and the addresses of the fonts the page loaded. + public async findPageProblemsAsync(page: string, drawn: readonly string[], fonts: readonly string[]): Promise { + const notice = await readFile(this.at(this.notice), MaterialSymbols.ENCODING); + const record = MaterialSymbols.RECORD.exec(notice)?.[2]; + const source = MaterialSymbols.SOURCE.exec(notice)?.[1]; + if (Object.isUndefined(record) || Object.isUndefined(source)) + return [`${this.notice} records no subset, so ${page} can't be checked.`]; + const subset = new Set(new URL(source).searchParams.get("icon_names")?.split(",") ?? []); + const missing = drawn.filter(t => !subset.has(t)); + const others = fonts.filter(t => { + const name = path.posix.basename(new URL(t).pathname); + return name.includes("material-symbols") && name !== record; + }); + return [ + ...missing.length === 0 ? [] : [`${page} draws ${missing.join(", ")}, which the subset ${record} lacks; run npm run symbols.`], + ...others.map(t => `${page} loads ${t}, a copy of the symbol font other than the subset ${record}.`) + ]; + } + + private async iconNamesAsync(): Promise> { + const names = await this.kitIconNamesAsync(); + for (const name of this.names) + names.add(name); + await this.collectAsync(this.at(this.code), names); + return names; + } + + // The icons the site's templates draw or hand its parts, and the glyphs its code keeps by name. + private async collectAsync(directory: string, names: Set): Promise { + for (const entry of await readdir(directory, { withFileTypes: true })) { + const filename = path.join(directory, entry.name); + if (entry.isDirectory()) + await this.collectAsync(filename, names); + else if (filename.endsWith(".html")) { + const text = await readFile(filename, MaterialSymbols.ENCODING); + for (const name of [...MaterialSymbols.groupsOf(text, MaterialSymbols.DRAWN_ICON), ...MaterialSymbols.groupsOf(text, MaterialSymbols.GIVEN_ICON)]) + names.add(name); + } + else if (filename.endsWith(".ts")) + for (const name of MaterialSymbols.groupsOf(await readFile(filename, MaterialSymbols.ENCODING), MaterialSymbols.KEPT_GLYPH)) + names.add(name); + } + } + + // The glyphs the kit's parts the site's code imports can draw: the union of their lists in the kit's glyphs.json. A name the + // site imports that is no part, such as a model or a type, has no list there. + private async kitIconNamesAsync(): Promise> { + const parts = MaterialSymbols.field(await this.kitGlyphListAsync(), "parts"); + if (!Object.isObject(parts)) + throw new Error(`${this.kitGlyphs} lists no parts.`); + const lists = new Map(Object.entries(parts)); + const imported = new Set(); + await this.collectKitImportsAsync(this.at(this.code), imported); + const names = new Set(); + for (const part of imported) { + if (!lists.has(part)) + continue; + const list = lists.get(part); + if (!Array.isArray(list)) + throw new Error(`${this.kitGlyphs} lists ${part}'s glyphs as something other than a list.`); + const glyphs: readonly unknown[] = list; + for (const glyph of glyphs) { + if (!Object.isString(glyph)) + throw new Error(`${this.kitGlyphs} lists ${part}'s glyphs as something other than names.`); + names.add(glyph); + } + } + return names; + } + + // The kit's glyphs.json, which kits from 0.0.37 on publish. + private async kitGlyphListAsync(): Promise { + let text: string; + try { + text = await readFile(this.at(this.kitGlyphs), MaterialSymbols.ENCODING); + } + catch (error) { + throw new Error(`${this.kitGlyphs} can't be read; the site needs ${MaterialSymbols.KIT_NAME} 0.0.37 or later.`, { cause: error }); + } + try { + return JSON.parse(text); + } + catch (error) { + throw new Error(`${this.kitGlyphs} isn't JSON.`, { cause: error }); + } + } + + private async collectKitImportsAsync(directory: string, imported: Set): Promise { + for (const entry of await readdir(directory, { withFileTypes: true })) { + const filename = path.join(directory, entry.name); + if (entry.isDirectory()) + await this.collectKitImportsAsync(filename, imported); + else if (filename.endsWith(".ts")) + for (const list of MaterialSymbols.groupsOf(await readFile(filename, MaterialSymbols.ENCODING), MaterialSymbols.KIT_IMPORT)) + for (const name of list.split(",")) + imported.add(name.trim()); + } + } + + private at(relative: string): string { + return path.join(this.root, relative); + } + + // The notice as it stands, or none when there is no file yet; any other failure to read it stops the refresh, so a notice it + // couldn't read is never written over. + private async noticeTextAsync(): Promise { + try { + return await readFile(this.at(this.notice), MaterialSymbols.ENCODING); + } + catch (error) { + if (error instanceof Error && "code" in error && error.code === MaterialSymbols.MISSING_FILE) + return ""; + throw error; + } + } + + // The notice with the subset's record at its top, in place of the old one, and every other line in it kept, in its order. + private noticeOf(notice: string, filename: string, digest: string, address: string): string { + const record = [ + `Material Symbols is from Google material-design-icons, under the Apache 2.0 license in ${MaterialSymbols.LICENSE}.`, + `The site serves a subset of it, ${path.posix.join(this.fonts, filename)}, holding only the icons it draws; refresh it with npm run symbols after adding an icon.`, + `SHA-256: ${digest} ${filename}`, + `Source: ${address}` + ]; + const others = notice.split(MaterialSymbols.LINES).filter(t => t !== "" && !MaterialSymbols.RECORD_LINE.test(t)); + return [...record, ...others, ""].join("\n"); + } + + // The first group of each match of a pattern in a text. + private static groupsOf(text: string, pattern: RegExp): readonly string[] { + return [...text.matchAll(pattern)].flatMap(t => t[1] ?? []); + } + + // A JSON object's field, or undefined when the value isn't an object or has no such field. + private static field(value: unknown, key: string): unknown { + return Object.isObject(value) ? new Map(Object.entries(value)).get(key) : undefined; + } + + private static sourceAddress(names: ReadonlySet): string { + return `${MaterialSymbols.SOURCE_ADDRESS}${[...names].sort().join(",")}${MaterialSymbols.SOURCE_END}`; + } + + private static sha256(bytes: Buffer): string { + return createHash("sha256").update(bytes).digest("hex"); + } +} diff --git a/src/noldova.ui.components.angular/tests/fixtures/node-load/load.mts b/src/noldova.ui.components.angular/tests/fixtures/node-load/load.mts index f76f41bc..08bb284f 100644 --- a/src/noldova.ui.components.angular/tests/fixtures/node-load/load.mts +++ b/src/noldova.ui.components.angular/tests/fixtures/node-load/load.mts @@ -25,6 +25,7 @@ await import("@noldova/ui.components.angular/site/header"); await import("@noldova/ui.components.angular/site/hero"); await import("@noldova/ui.components.angular/site/section"); await import("@noldova/ui.components.angular/site/stage"); +await import("@noldova/ui.components.angular/symbols"); await import("@noldova/ui.components.angular/typography"); export type * from "@noldova/ui.components.angular/testing"; diff --git a/src/noldova.ui.components.angular/tests/node/kit-stylesheets.test.ts b/src/noldova.ui.components.angular/tests/node/kit-stylesheets.test.ts new file mode 100644 index 00000000..a6fdef0d --- /dev/null +++ b/src/noldova.ui.components.angular/tests/node/kit-stylesheets.test.ts @@ -0,0 +1,45 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +import "@noldova/context.core"; +import assert from "node:assert/strict"; +import { readFile } from "node:fs/promises"; +import path from "node:path"; +import { describe, it } from "node:test"; + +const styles = path.join(import.meta.dirname, "../../src/styles"); +const importPattern = /^@import "([^"]+)";$/gmu; + +// The stylesheets a stylesheet of the kit imports, in order, with those of the kit's own it imports in turn. +async function importsOfAsync(name: string): Promise { + const text = await readFile(path.join(styles, name), "utf8"); + const imports: string[] = []; + for (const target of [...text.matchAll(importPattern)].flatMap(t => t[1] ?? [])) { + imports.push(target); + if (target.startsWith("./")) + imports.push(...await importsOfAsync(target.slice(2))); + } + return imports; +} + +describe("The kit's stylesheets", () => { + it("load everything kit.css loads but the whole symbol font from kit-without-symbol-font.css, the symbol class's rules first", async () => { + const whole = await importsOfAsync("kit.css"); + const without = await importsOfAsync("kit-without-symbol-font.css"); + + assert.deepEqual(whole, ["material-symbols/rounded.css", "./kit-without-symbol-font.css", ...without]); + assert.equal(without[0], "./symbols.css"); + assert.ok(!without.some(t => t.startsWith("material-symbols")), without.join(", ")); + }); + + it("declare no font for the symbol class in kit-without-symbol-font.css, so a site's own subset is the only one", async () => { + const own = (await importsOfAsync("kit-without-symbol-font.css")).filter(t => t.startsWith("./")); + for (const name of ["kit-without-symbol-font.css", ...own.map(t => t.slice(2))]) + assert.doesNotMatch(await readFile(path.join(styles, name), "utf8"), /@font-face\s*\{[^}]*Material Symbols/u, name); + }); +}); diff --git a/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts b/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts new file mode 100644 index 00000000..678df6f0 --- /dev/null +++ b/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts @@ -0,0 +1,444 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +import "@noldova/context.core"; +import assert from "node:assert/strict"; +import { createHash } from "node:crypto"; +import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { afterEach, beforeEach, describe, it, mock } from "node:test"; + +import type { IMaterialSymbolsSite } from "../../src/symbols/interfaces/i-material-symbols-site.ts"; +import { MaterialSymbols } from "../../src/symbols/material-symbols.ts"; + +const font = Buffer.from("wOF2 a subset of two icons"); +const digest = createHash("sha256").update(font).digest("hex"); +const filename = `material-symbols-${digest.slice(0, 8)}.woff2`; +const source = + "https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@24,400,0,0&icon_names=arrow_forward,close,dark_mode,desktop_windows,download,light_mode,menu,search&display=swap"; +const changed = "The icons the site draws differ from the recorded subset; run npm run symbols."; +const kitGlyphs = "node_modules/@noldova/ui.components.angular/glyphs.json"; + +// A site whose subset agrees with its record, its notice and its code; each test breaks one of them. +class Site { + public readonly root: string; + + public constructor(root: string) { + this.root = root; + } + + public static async createAsync(): Promise { + const site = new Site(await mkdtemp(path.join(tmpdir(), "material-symbols-"))); + await site.writeAsync(`public/assets/fonts/${filename}`, font); + await site.writeAsync("public/assets/licenses/README.txt", Site.notice(digest, filename, source)); + await site.writeAsync("public/assets/licenses/MATERIAL-SYMBOLS-LICENSE.txt", "Apache License\nVersion 2.0\n"); + await site.writeAsync("src/styles.css", `@font-face { src: url('/assets/fonts/${filename}'); }\n`); + await site.writeAsync("src/app/page.html", "arrow_forward\n"); + await site.writeAsync("src/resources.ts", "export class Resources {}\n"); + await site.writeAsync("src/app/frame.ts", "import { SiteHeaderComponent, SiteLink } from \"@noldova/ui.components.angular/site\";\n"); + await site.writeAsync("src/app/page.ts", + "import type { IconName } from \"@noldova/ui.components.angular\";\nimport { ButtonComponent } from \"@noldova/ui.components.angular\";\nimport { SiteLink } from \"@noldova/ui.components.angular/site\";\n"); + await site.writeKitGlyphsAsync({ + ButtonComponent: [], + SiteCanvasComponent: ["zoom_in"], + SiteHeaderComponent: ["close", "dark_mode", "desktop_windows", "download", "light_mode", "menu", "search"] + }); + return site; + } + + public async writeKitAsync(relative: string, content: string): Promise { + await this.writeAsync(`node_modules/@noldova/ui.components.angular/${relative}`, content); + } + + public async writeKitGlyphsAsync(parts: Readonly>): Promise { + await this.writeKitAsync("glyphs.json", JSON.stringify({ parts })); + } + + public static notice(sha: string, name: string, address: string): string { + return `Material Symbols\nSHA-256: ${sha} ${name}\nSource: ${address}\n`; + } + + public async writeAsync(relative: string, content: string | Buffer): Promise { + const file = path.join(this.root, relative); + await mkdir(path.dirname(file), { recursive: true }); + await writeFile(file, content); + } + + public async removeAsync(relative: string): Promise { + await rm(path.join(this.root, relative)); + } + + public symbols(site: Omit = {}): MaterialSymbols { + return new MaterialSymbols({ root: this.root, ...site }); + } + + public async refusalAsync(site: Omit = {}): Promise { + try { + await this.symbols(site).checkAsync(); + } + catch (error) { + if (error instanceof Error) + return error.message; + throw error; + } + return ""; + } +} + +describe("MaterialSymbols.checkAsync", () => { + let site: Site | null = null; + + beforeEach(async () => { + site = await Site.createAsync(); + mock.method(console, "log", () => undefined); + }); + + afterEach(async () => { + mock.restoreAll(); + if (!Object.isNull(site)) + await rm(site.root, { recursive: true, force: true }); + }); + + const current = (): Site => { + assert.ok(!Object.isNull(site)); + return site; + }; + + it("passes a subset that agrees with its record, its notice and its code", async () => { + assert.equal(await current().refusalAsync(), ""); + }); + + it("checks, and changes nothing, when the command line asks with --check", async () => { + await current().writeAsync("public/assets/licenses/README.txt", "Material Symbols\n"); + + await assert.rejects(current().symbols().runAsync(["--check"]), { message: "public/assets/licenses/README.txt records no SHA-256 or source." }); + assert.equal(await readFile(path.join(current().root, "public/assets/licenses/README.txt"), "utf8"), "Material Symbols\n"); + }); + + it("refuses a fonts folder with no font", async () => { + await current().removeAsync(`public/assets/fonts/${filename}`); + assert.equal(await current().refusalAsync(), `public/assets/fonts holds no font, not only the recorded ${filename}.`); + }); + + it("reads the icons of templates in folders under the code too", async () => { + await current().writeAsync("src/app/home/home.html", "star\n"); + assert.equal(await current().refusalAsync(), changed); + }); + + it("reads an icon a template gives a part by its icon attribute", async () => { + await current().writeAsync("src/app/home/home.html", "\n"); + assert.equal(await current().refusalAsync(), changed); + }); + + it("refuses a notice with no record", async () => { + await current().writeAsync("public/assets/licenses/README.txt", "Material Symbols\n"); + assert.equal(await current().refusalAsync(), "public/assets/licenses/README.txt records no SHA-256 or source."); + }); + + it("refuses a font that is not the recorded one", async () => { + await current().removeAsync(`public/assets/fonts/${filename}`); + await current().writeAsync("public/assets/fonts/material-symbols-00000000.woff2", font); + assert.equal(await current().refusalAsync(), `public/assets/fonts holds material-symbols-00000000.woff2, not only the recorded ${filename}.`); + }); + + it("refuses a second font beside the recorded one", async () => { + await current().writeAsync("public/assets/fonts/material-symbols-00000000.woff2", font); + assert.equal(await current().refusalAsync(), + `public/assets/fonts holds ${[filename, "material-symbols-00000000.woff2"].sort().join(", ")}, not only the recorded ${filename}.`); + }); + + it("refuses a font whose bytes changed", async () => { + await current().writeAsync(`public/assets/fonts/${filename}`, Buffer.from("wOF2 another subset")); + assert.equal(await current().refusalAsync(), `${filename} does not match its recorded SHA-256.`); + }); + + it("refuses a font not named by its SHA-256", async () => { + const other = "material-symbols-00000000.woff2"; + await current().removeAsync(`public/assets/fonts/${filename}`); + await current().writeAsync(`public/assets/fonts/${other}`, font); + await current().writeAsync("public/assets/licenses/README.txt", Site.notice(digest, other, source)); + await current().writeAsync("src/styles.css", `@font-face { src: url('/assets/fonts/${other}'); }\n`); + assert.equal(await current().refusalAsync(), `${other} is not named by its SHA-256.`); + }); + + it("refuses styles that do not load the recorded font", async () => { + await current().writeAsync("src/styles.css", "@font-face { src: url('/assets/fonts/material-symbols.woff2'); }\n"); + assert.equal(await current().refusalAsync(), `src/styles.css does not load ${filename}.`); + }); + + it("reads the glyphs the site's data names, which the kit's parts draw", async () => { + await current().writeAsync("src/resources.ts", "const card = { glyph: \"undo\" };\n"); + assert.equal(await current().refusalAsync(), changed); + }); + + it("reads a glyph the site's data keeps by name", async () => { + await current().writeAsync("src/resources.ts", "public static readonly saveGlyph: IconName = \"save\";\n"); + assert.equal(await current().refusalAsync(), changed); + }); + + it("passes the data's glyphs once the subset holds them", async () => { + await current().writeAsync("src/resources.ts", "const card = { glyph: \"menu\" };\n"); + assert.equal(await current().refusalAsync(), ""); + }); + + it("refuses templates that draw an icon the subset lacks", async () => { + await current().writeAsync("src/app/other.html", "settings\n"); + assert.equal(await current().refusalAsync(), changed); + }); + + it("refuses a subset that holds an icon the site no longer draws", async () => { + await current().writeAsync("src/app/page.html", "

No icons.

\n"); + assert.equal(await current().refusalAsync(), changed); + }); + + it("reads the icons the site names itself", async () => { + await current().writeAsync("src/app/page.html", "

No icons.

\n"); + assert.equal(await current().refusalAsync({ names: ["arrow_forward"] }), ""); + assert.equal(await current().refusalAsync({ names: ["arrow_forward", "star"] }), changed); + }); + + it("reads the union of the glyphs.json lists of the kit's parts the site imports, the header's search included, and none of the parts it doesn't", async () => { + assert.equal(await current().refusalAsync(), ""); + }); + + it("refuses a subset that lacks a glyph a kit part's list gained", async () => { + await current().writeKitGlyphsAsync({ SiteHeaderComponent: ["arrow_back", "close", "dark_mode", "desktop_windows", "download", "light_mode", "menu", "search"] }); + assert.equal(await current().refusalAsync(), changed); + }); + + it("refuses a subset that lacks the glyphs of a kit part the site begins to import", async () => { + await current().writeAsync("src/app/canvas.ts", "import { SiteCanvasComponent } from \"@noldova/ui.components.angular/site\";\n"); + assert.equal(await current().refusalAsync(), changed); + }); + + it("reads the site's own folders, stylesheet, font address and glyphs.json", async () => { + await current().writeAsync(`web/fonts/${filename}`, font); + await current().writeAsync("web/notices/README.txt", Site.notice(digest, filename, source)); + await current().writeAsync("web/notices/MATERIAL-SYMBOLS-LICENSE.txt", "Apache License\n"); + await current().writeAsync("site/theme.css", `@font-face { src: url('/static/${filename}'); }\n`); + await current().writeAsync("site/app/page.html", "arrow_forward\n"); + await current().writeAsync("site/app/frame.ts", "import { SiteHeaderComponent } from \"@noldova/ui.components.angular/site\";\n"); + await current().writeAsync("kit/glyphs.json", JSON.stringify({ parts: { SiteHeaderComponent: ["close", "dark_mode", "desktop_windows", "download", "light_mode", "menu", "search"] } })); + await rm(path.join(current().root, "src"), { recursive: true }); + await rm(path.join(current().root, "public"), { recursive: true }); + await rm(path.join(current().root, "node_modules"), { recursive: true }); + + assert.equal(await current().refusalAsync({ code: "site", styles: "site/theme.css", fonts: "web/fonts", licenses: "web/notices", fontsAddress: "/static/", kitGlyphs: "kit/glyphs.json" }), ""); + }); + + it("stops when the installed kit publishes no glyphs.json", async () => { + await current().removeAsync(kitGlyphs); + await assert.rejects(current().symbols().checkAsync(), { message: `${kitGlyphs} can't be read; the site needs @noldova/ui.components.angular 0.0.37 or later.` }); + }); + + it("stops when the kit's glyphs.json lists no parts", async () => { + await current().writeKitAsync("glyphs.json", "{}"); + await assert.rejects(current().symbols().checkAsync(), { message: `${kitGlyphs} lists no parts.` }); + }); + + it("stops when the kit's glyphs.json is no object", async () => { + await current().writeKitAsync("glyphs.json", "7"); + await assert.rejects(current().symbols().checkAsync(), { message: `${kitGlyphs} lists no parts.` }); + }); + + it("stops when the kit's glyphs.json lists a part's glyphs as anything but names", async () => { + await current().writeKitGlyphsAsync({ SiteHeaderComponent: ["close", 7] }); + await assert.rejects(current().symbols().checkAsync(), { message: `${kitGlyphs} lists SiteHeaderComponent's glyphs as something other than names.` }); + }); + + it("stops when the kit's glyphs.json lists a part's glyphs as anything but a list", async () => { + await current().writeKitAsync("glyphs.json", JSON.stringify({ parts: { ButtonComponent: [], SiteHeaderComponent: "close" } })); + await assert.rejects(current().symbols().checkAsync(), { message: `${kitGlyphs} lists SiteHeaderComponent's glyphs as something other than a list.` }); + }); + + it("stops when the kit's glyphs.json isn't JSON", async () => { + await current().writeKitAsync("glyphs.json", "{ \"parts\": "); + await assert.rejects(current().symbols().checkAsync(), { message: `${kitGlyphs} isn't JSON.` }); + }); + + it("refuses a missing license", async () => { + await current().removeAsync("public/assets/licenses/MATERIAL-SYMBOLS-LICENSE.txt"); + assert.equal(await current().refusalAsync(), "public/assets/licenses/MATERIAL-SYMBOLS-LICENSE.txt does not hold the Apache 2.0 license."); + }); +}); + +describe("MaterialSymbols.findPageProblemsAsync", () => { + let site: Site | null = null; + + beforeEach(async () => { + site = await Site.createAsync(); + }); + + afterEach(async () => { + if (!Object.isNull(site)) + await rm(site.root, { recursive: true, force: true }); + }); + + const current = (): Site => { + assert.ok(!Object.isNull(site)); + return site; + }; + + it("finds nothing wrong with a page that draws only the subset's glyphs and loads only the subset", async () => { + assert.deepEqual(await current().symbols().findPageProblemsAsync("/", ["close", "menu"], [`https://docs.test/assets/fonts/${filename}`, "https://docs.test/media/noldova-sans.woff2"]), []); + }); + + it("names each glyph a page draws that the subset lacks", async () => { + assert.deepEqual(await current().symbols().findPageProblemsAsync("/a", ["close", "star", "zoom_in"], []), + [`/a draws star, zoom_in, which the subset ${filename} lacks; run npm run symbols.`]); + }); + + it("names each other copy of the symbol font a page loads, such as the whole font the kit's stylesheet brings", async () => { + const whole = "https://docs.test/media/material-symbols-rounded-2PAJMT5W.woff2"; + assert.deepEqual(await current().symbols().findPageProblemsAsync("/b", [], [whole, `https://docs.test/assets/fonts/${filename}`]), + [`/b loads ${whole}, a copy of the symbol font other than the subset ${filename}.`]); + }); + + it("says a page can't be checked when the notice records no subset", async () => { + await current().writeAsync("public/assets/licenses/README.txt", "Material Symbols\n"); + assert.deepEqual(await current().symbols().findPageProblemsAsync("/c", ["close"], []), + ["public/assets/licenses/README.txt records no subset, so /c can't be checked."]); + }); +}); + +// A refresh whose download from one service fails: what goes wrong, the addresses it changes, the answer they get and the +// error the refresh stops with. +class RefreshFailure { + public readonly problem: string; + public readonly message: string; + private readonly prefix: string; + private readonly changed: () => Response; + + public constructor(problem: string, prefix: string, changed: () => Response, message: string) { + this.problem = problem; + this.prefix = prefix; + this.changed = changed; + this.message = message; + } + + public answer(address: string): Response | null { + return address.startsWith(this.prefix) ? this.changed() : null; + } +} + +describe("MaterialSymbols.refreshAsync", () => { + const refreshed = Buffer.from("wOF2 a refreshed subset"); + const refreshedDigest = createHash("sha256").update(refreshed).digest("hex"); + const refreshedName = `material-symbols-${refreshedDigest.slice(0, 8)}.woff2`; + const others = [ + "Noldova Sans and Noldova Mono come with the @noldova/ui.components.angular package; the build copies their SIL Open Font Licenses into this folder.", + "SHA-256: 58d7237ab77e9ed8d5f8b297577bf673b21c1fe6a1610d6f1bc8598e886d18c6 cursor-light.svg" + ]; + let site: Site | null = null; + + // The answers of Google Fonts and GitHub to the refresh, each as the service gives it unless failure changes it. + const answer = (address: string, failure: RefreshFailure | null = null): Response => { + const changedAnswer = failure?.answer(address) ?? null; + if (!Object.isNull(changedAnswer)) + return changedAnswer; + if (address.startsWith("https://fonts.googleapis.com/")) + return new Response("@font-face { src: url(https://fonts.gstatic.com/s/subset.woff2) format('woff2'); }"); + if (address.startsWith("https://fonts.gstatic.com/")) + return new Response(refreshed); + return new Response("Apache License\nVersion 2.0\n"); + }; + const addressOf = (input: string | URL | Request): string => input instanceof Request ? input.url : String(input); + + beforeEach(async () => { + site = await Site.createAsync(); + mock.method(console, "log", () => undefined); + mock.method(globalThis, "fetch", (input: string | URL | Request) => Promise.resolve(answer(addressOf(input)))); + }); + + afterEach(async () => { + mock.restoreAll(); + if (!Object.isNull(site)) + await rm(site.root, { recursive: true, force: true }); + }); + + const current = (): Site => { + assert.ok(!Object.isNull(site)); + return site; + }; + + const failures: readonly RefreshFailure[] = [ + new RefreshFailure("the font stylesheet answers 503", "https://fonts.googleapis.com/", () => new Response("", { status: 503 }), "Font stylesheet download failed: 503"), + new RefreshFailure("the stylesheet names no Google Fonts font", "https://fonts.googleapis.com/", () => new Response("@font-face { src: url(https://example.com/a.woff2); }"), + "Expected an official Google Fonts font URL."), + new RefreshFailure("the font answers 404", "https://fonts.gstatic.com/", () => new Response("", { status: 404 }), "Font download failed: 404"), + new RefreshFailure("the font is no WOFF2", "https://fonts.gstatic.com/", () => new Response("GIF89a"), "Expected a WOFF2 font."), + new RefreshFailure("the license answers 500", "https://raw.githubusercontent.com/", () => new Response("", { status: 500 }), "Material Symbols license download failed.") + ]; + for (const failure of failures) + it(`stops, with nothing recorded, when ${failure.problem}`, async () => { + mock.restoreAll(); + mock.method(globalThis, "fetch", (input: string | URL | Request) => Promise.resolve(answer(addressOf(input), failure))); + const before = await readFile(path.join(current().root, notice), "utf8"); + + await assert.rejects(current().symbols().refreshAsync(), { message: failure.message }); + assert.equal(await readFile(path.join(current().root, notice), "utf8"), before); + }); + + // The subset's record exactly as the refresh writes it, for a font and the address it came from. + const record = (fontName: string, sha: string, address: string): string[] => [ + "Material Symbols is from Google material-design-icons, under the Apache 2.0 license in MATERIAL-SYMBOLS-LICENSE.txt.", + `The site serves a subset of it, public/assets/fonts/${fontName}, holding only the icons it draws; refresh it with npm run symbols after adding an icon.`, + `SHA-256: ${sha} ${fontName}`, + `Source: ${address}` + ]; + const notice = "public/assets/licenses/README.txt"; + const expected = [...record(refreshedName, refreshedDigest, source), ...others, ""].join("\n"); + + const refreshNoticeAsync = async (before: string): Promise => { + await current().writeAsync(notice, before); + await current().symbols().refreshAsync(); + return readFile(path.join(current().root, notice), "utf8"); + }; + + it("refreshes the subset when the command line asks for no check, and points the stylesheet at it alone", async () => { + await current().writeAsync(notice, [...record(filename, digest, source), ""].join("\n")); + + await current().symbols().runAsync([]); + + assert.equal(await readFile(path.join(current().root, notice), "utf8"), [...record(refreshedName, refreshedDigest, source), ""].join("\n")); + assert.equal(await readFile(path.join(current().root, "src/styles.css"), "utf8"), `@font-face { src: url('/assets/fonts/${refreshedName}'); }\n`); + await assert.rejects(stat(path.join(current().root, `public/assets/fonts/${filename}`)), { code: "ENOENT" }); + }); + + it("keeps the other notices, in their order, under the new record, when the old record comes first", async () => { + assert.equal(await refreshNoticeAsync([...record(filename, digest, source), ...others, ""].join("\n")), expected); + assert.equal(await current().refusalAsync(), ""); + }); + + it("keeps the other notices, in their order, under the new record, when the old record comes last", async () => { + assert.equal(await refreshNoticeAsync([...others, ...record(filename, digest, source), ""].join("\n")), expected); + }); + + it("writes the new record alone in place of an old record alone", async () => { + assert.equal(await refreshNoticeAsync([...record(filename, digest, source), ""].join("\n")), [...record(refreshedName, refreshedDigest, source), ""].join("\n")); + }); + + it("reads a notice with CRLF endings and writes it with LF, the old record gone", async () => { + assert.equal(await refreshNoticeAsync([...record(filename, digest, source), ...others, ""].join("\r\n")), expected); + }); + + it("writes the record alone, and the license beside it, when there is no notice or licenses folder yet", async () => { + await rm(path.join(current().root, "public/assets/licenses"), { recursive: true }); + await current().symbols().refreshAsync(); + assert.equal(await readFile(path.join(current().root, notice), "utf8"), [...record(refreshedName, refreshedDigest, source), ""].join("\n")); + assert.equal(await current().refusalAsync(), ""); + }); + + it("stops on a notice it can't read, and writes nothing in its place", async () => { + await current().removeAsync(notice); + await mkdir(path.join(current().root, notice)); + await assert.rejects(current().symbols().refreshAsync(), { code: "EISDIR", syscall: "read" }); + assert.ok((await stat(path.join(current().root, notice))).isDirectory(), "the notice is untouched"); + }); +}); diff --git a/src/noldova.ui.components.angular/tsconfig.json b/src/noldova.ui.components.angular/tsconfig.json index 9d096267..5875002b 100644 --- a/src/noldova.ui.components.angular/tsconfig.json +++ b/src/noldova.ui.components.angular/tsconfig.json @@ -61,6 +61,9 @@ "@noldova/ui.components.angular/site/stage": [ "./src/api/site-stage.ts" ], + "@noldova/ui.components.angular/symbols": [ + "./src/api/symbols.ts" + ], "@noldova/ui.components.angular/testing": [ "./src/api/testing.ts" ], diff --git a/src/noldova.ui.components.angular/tsconfig.spec.json b/src/noldova.ui.components.angular/tsconfig.spec.json index 4e765368..48e46259 100644 --- a/src/noldova.ui.components.angular/tsconfig.spec.json +++ b/src/noldova.ui.components.angular/tsconfig.spec.json @@ -11,6 +11,9 @@ "tests/**/*.ts" ], "exclude": [ + "src/api/symbols.ts", + "src/symbols/**", + "tests/node/**", "tests/coverage/**", "tests/network/**", "tests/screenshots/**", diff --git a/src/noldova.ui.components.angular/tsconfig.symbols.json b/src/noldova.ui.components.angular/tsconfig.symbols.json new file mode 100644 index 00000000..c91bf293 --- /dev/null +++ b/src/noldova.ui.components.angular/tsconfig.symbols.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "typeRoots": [ + "../../node_modules/@types" + ], + "types": [ + "node" + ] + } +} From e3c9372c2ed33ef8a0fd00e0386f4c8a02f96ac8 Mon Sep 17 00:00:00 2001 From: Rostislav Rotaru Date: Sat, 28 Nov 2026 18:20:31 -0800 Subject: [PATCH 2/9] Read glyphs kept as strings, and give sites the fonts a page loaded Agent: DEV7 (developer) Agent-Model: Anthropic Opus 5.5, Medium --- documents/KIT.md | 4 ++-- src/noldova.ui.components.angular/src/api/symbols.d.ts | 9 ++++++++- .../src/symbols/material-symbols.ts | 7 +++++-- .../tests/node/material-symbols.test.ts | 5 +++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/documents/KIT.md b/documents/KIT.md index 14e834c1..6668220a 100644 --- a/documents/KIT.md +++ b/documents/KIT.md @@ -289,9 +289,9 @@ A glyph the site passes to a part, such as an icon button's `icon` or a `SiteAct The icon chooser's and the gallery's lists hold every name of the set, since they can draw any of them. A site gets its subset from the entry `@noldova/ui.components.angular/symbols`, a Node.js tool that loads in no browser: -- Its `MaterialSymbols` reads the union of the `glyphs.json` lists of the kit's parts the site's code imports, the icons its templates draw between the symbol class's span tags or give a part as `icon="…"`, the glyphs its code keeps in a field whose name ends in glyph, and the names the site gives it for icons its code builds; a refresh, which the site runs as `npm run symbols`, downloads that subset from Google Fonts with its license, keeps it in the site's fonts folder named by its SHA-256, points the site's `@font-face` at it and records its SHA-256 and source in the site's license notice. +- Its `MaterialSymbols` reads the union of the `glyphs.json` lists of the kit's parts the site's code imports, the icons its templates draw between the symbol class's span tags or give a part as `icon="…"`, the glyphs its code keeps in a field whose name ends in glyph, as an `IconName` or a string, and the names the site gives it for icons its code builds; a refresh, which the site runs as `npm run symbols`, downloads that subset from Google Fonts with its license, keeps it in the site's fonts folder named by its SHA-256, points the site's `@font-face` at it and records its SHA-256 and source in the site's license notice. - Its check, `npm run symbols -- --check` in the site's checks, fails when the committed font, its record, its stylesheet or the glyphs the site draws disagree. -- Its `drawnGlyphs` expression and `findPageProblemsAsync` let the site's check of its built pages fail on a page that draws a glyph the subset lacks, or that loads another copy of the font, such as the whole font `kit.css` brings. +- Its `drawnGlyphs` and `loadedFonts` page expressions and `findPageProblemsAsync` let the site's check of its built pages fail on a page that draws a glyph the subset lacks, or that loads another copy of the font, such as the whole font `kit.css` brings. Such a site loads `styles/kit-without-symbol-font.css` in place of `styles/kit.css`: everything `kit.css` loads but the whole font, with the symbol class's text rules, `styles/symbols.css`, first, and declares the subset's `@font-face` for the family `Material Symbols Rounded` itself. A page that must draw any glyph, such as the icon chooser's, loads the whole font under a family of its own, so the browser fetches it only on that page. diff --git a/src/noldova.ui.components.angular/src/api/symbols.d.ts b/src/noldova.ui.components.angular/src/api/symbols.d.ts index f4b0d445..ebad25a4 100644 --- a/src/noldova.ui.components.angular/src/api/symbols.d.ts +++ b/src/noldova.ui.components.angular/src/api/symbols.d.ts @@ -101,6 +101,13 @@ export declare class MaterialSymbols { */ public static readonly drawnGlyphs: string; + /** + * An expression to evaluate in a built page, as {@link MaterialSymbols.drawnGlyphs} + * is, that waits for the page's fonts to be ready and gives as JSON the + * full addresses of the WOFF2 fonts it loaded. + */ + public static readonly loadedFonts: string; + /** * @param site Where the site keeps its subset. */ @@ -143,7 +150,7 @@ export declare class MaterialSymbols { * * @param page The page's address, which each problem names. * @param drawn The glyphs {@link MaterialSymbols.drawnGlyphs} gave. - * @param fonts The full addresses of the fonts the page loaded. + * @param fonts The fonts {@link MaterialSymbols.loadedFonts} gave. * @returns The problems, none when the page is right. */ public findPageProblemsAsync(page: string, drawn: readonly string[], fonts: readonly string[]): Promise; diff --git a/src/noldova.ui.components.angular/src/symbols/material-symbols.ts b/src/noldova.ui.components.angular/src/symbols/material-symbols.ts index a43815c6..2a1400cd 100644 --- a/src/noldova.ui.components.angular/src/symbols/material-symbols.ts +++ b/src/noldova.ui.components.angular/src/symbols/material-symbols.ts @@ -21,6 +21,9 @@ export class MaterialSymbols { // A page expression that gives, as JSON, the sorted names each element drawn in the symbol font's own family shows as its text. public static readonly drawnGlyphs: string = `JSON.stringify([...new Set([...document.querySelectorAll('body *')].filter(t => getComputedStyle(t).fontFamily.split(',')[0].replaceAll('"', '').replaceAll("'", '').trim() === '${MaterialSymbols.family}' && [...t.childNodes].some(u => u.nodeType === Node.TEXT_NODE && (u.textContent ?? '').trim() !== '')).map(t => (t.textContent ?? '').trim()))].sort())`; + // A page expression that gives, as JSON, the addresses of the fonts the page loaded, once its fonts are ready. + public static readonly loadedFonts: string = + "document.fonts.ready.then(() => JSON.stringify(performance.getEntriesByType('resource').map(t => t.name).filter(t => new URL(t).pathname.endsWith('.woff2'))))"; private static readonly KIT_NAME: string = "@noldova/ui.components.angular"; private static readonly DEFAULT_CODE: string = "src"; private static readonly DEFAULT_STYLES: string = "src/styles.css"; @@ -43,7 +46,7 @@ export class MaterialSymbols { // An icon a template hands a part by its name, as its icon attribute. private static readonly GIVEN_ICON: RegExp = /\sicon="([a-z0-9_]+)"/gu; // A glyph the site's code keeps by its name, in a field or constant whose name ends in glyph or Glyph. - private static readonly KEPT_GLYPH: RegExp = /[gG]lyph(?:: IconName =|:) "([a-z0-9_]+)"/gu; + private static readonly KEPT_GLYPH: RegExp = /[gG]lyph(?:: (?:IconName|string) =|:) "([a-z0-9_]+)"/gu; // The names the site's code imports from any of the kit's entry points. private static readonly KIT_IMPORT: RegExp = /import (?:type )?\{([^}]+)\} from "@noldova\/ui\.components\.angular(?:\/[a-z-]+)*";/gu; private static readonly FONT_NAME: RegExp = /^material-symbols-([a-f0-9]{8})\.woff2$/u; @@ -150,7 +153,7 @@ export class MaterialSymbols { } // What is wrong with one built page: each glyph it draws that the recorded subset lacks, and each copy of the symbol font it loads - // other than the recorded subset, given the glyphs drawnGlyphs read and the addresses of the fonts the page loaded. + // other than the recorded subset, given the glyphs drawnGlyphs read and the fonts loadedFonts read. public async findPageProblemsAsync(page: string, drawn: readonly string[], fonts: readonly string[]): Promise { const notice = await readFile(this.at(this.notice), MaterialSymbols.ENCODING); const record = MaterialSymbols.RECORD.exec(notice)?.[2]; diff --git a/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts b/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts index 678df6f0..9baec16a 100644 --- a/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts +++ b/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts @@ -182,6 +182,11 @@ describe("MaterialSymbols.checkAsync", () => { assert.equal(await current().refusalAsync(), changed); }); + it("reads a glyph the site's code keeps as a string by name", async () => { + await current().writeAsync("src/resources.ts", "public static readonly menuGlyph: string = \"toc\";\n"); + assert.equal(await current().refusalAsync(), changed); + }); + it("passes the data's glyphs once the subset holds them", async () => { await current().writeAsync("src/resources.ts", "const card = { glyph: \"menu\" };\n"); assert.equal(await current().refusalAsync(), ""); From 017f48f2912fbbd1abd5930e81d8a85cdd12715f Mon Sep 17 00:00:00 2001 From: Rostislav Rotaru Date: Sat, 28 Nov 2026 18:47:08 -0800 Subject: [PATCH 3/9] Leave the symbols tool out of the specs' coverage in the one exclude list angular.json held two coverageExclude keys, and the later one, the enums', replaced the symbols tool's, so the kit's coverage named the Node.js tool, which no spec loads, as never reached. Agent: DEV7 (developer) Agent-Model: Anthropic Opus 5.5, Medium --- src/noldova.ui.components.angular/angular.json | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/noldova.ui.components.angular/angular.json b/src/noldova.ui.components.angular/angular.json index 1f232b00..c70f9f0e 100644 --- a/src/noldova.ui.components.angular/angular.json +++ b/src/noldova.ui.components.angular/angular.json @@ -40,10 +40,6 @@ "coverageInclude": [ "src/**/*.ts" ], - "coverageExclude": [ - "src/api/symbols.ts", - "src/symbols/**" - ], "coverageReporters": [ "text", "json-summary", @@ -56,7 +52,9 @@ "lines": 100 }, "coverageExclude": [ - "src/app/enums/**" + "src/app/enums/**", + "src/api/symbols.ts", + "src/symbols/**" ] }, "configurations": { From 46f217d0034fa2f0d76d312e5fe7ded7a4415875 Mon Sep 17 00:00:00 2001 From: Rostislav Rotaru Date: Sat, 28 Nov 2026 19:11:31 -0800 Subject: [PATCH 4/9] WIP: subset the kit docs site, the chooser in the whole font Agent: DEV7 (developer) Agent-Model: Anthropic Opus 5.5, Medium --- .../angular.json | 2 +- .../package.json | 4 ++- .../scripts/docs-site-check.ts | 21 ++++++++++-- .../scripts/docs/docs-symbols.ts | 32 +++++++++++++++++++ .../scripts/prepare-symbols.ts | 23 +++++++++++++ .../scripts/test-docs.ts | 20 +++++++++++- .../src/styles.css | 24 ++++++++++++++ .../src/api/symbols.d.ts | 8 +++++ .../interfaces/i-material-symbols-site.ts | 1 + .../src/symbols/material-symbols.ts | 7 ++-- .../tests/node/material-symbols.test.ts | 6 ++++ 11 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 src/noldova.ui.components.angular.docs/scripts/docs/docs-symbols.ts create mode 100644 src/noldova.ui.components.angular.docs/scripts/prepare-symbols.ts diff --git a/src/noldova.ui.components.angular.docs/angular.json b/src/noldova.ui.components.angular.docs/angular.json index 26ce35dd..f706493e 100644 --- a/src/noldova.ui.components.angular.docs/angular.json +++ b/src/noldova.ui.components.angular.docs/angular.json @@ -31,7 +31,7 @@ ], "styles": [ "../noldova.ui.components.angular/src/styles/theme.css", - "../noldova.ui.components.angular/src/styles/kit.css", + "../noldova.ui.components.angular/src/styles/kit-without-symbol-font.css", "src/styles.css" ] }, diff --git a/src/noldova.ui.components.angular.docs/package.json b/src/noldova.ui.components.angular.docs/package.json index 9dbe2302..7b0125ab 100644 --- a/src/noldova.ui.components.angular.docs/package.json +++ b/src/noldova.ui.components.angular.docs/package.json @@ -8,7 +8,9 @@ "docs:build": "node scripts/build-docs.ts", "docs:test": "node scripts/test-docs.ts", "test": "node scripts/test-docs.ts --suite", - "test:timing": "node scripts/test-docs-timing.ts" + "test:timing": "node scripts/test-docs-timing.ts", + "symbols": "node scripts/prepare-symbols.ts", + "symbols:check": "node scripts/prepare-symbols.ts --check" }, "dependencies": { "@angular/common": "22.3.0", diff --git a/src/noldova.ui.components.angular.docs/scripts/docs-site-check.ts b/src/noldova.ui.components.angular.docs/scripts/docs-site-check.ts index 77e32a40..6ebc7dc5 100644 --- a/src/noldova.ui.components.angular.docs/scripts/docs-site-check.ts +++ b/src/noldova.ui.components.angular.docs/scripts/docs-site-check.ts @@ -11,9 +11,13 @@ import path from "node:path"; import type { Writable } from "node:stream"; import { pathToFileURL } from "node:url"; +import "@noldova/context.core"; + import type { ICheck } from "../../noldova.ui.components.angular/scripts/checks/interfaces/i-check.ts"; import { JsonFields } from "../../noldova.ui.components.angular/scripts/angular/json-fields.ts"; +import { MaterialSymbols } from "../../noldova.ui.components.angular/src/symbols/material-symbols.ts"; import { DocsSiteServer } from "./docs/docs-site-server.ts"; +import { DocsSymbols } from "./docs/docs-symbols.ts"; import type { IPlaywrightModule } from "./docs/interfaces/i-playwright-module.ts"; import type { ISiteBrowser } from "./docs/interfaces/i-site-browser.ts"; import type { ISitePage } from "./docs/interfaces/i-site-page.ts"; @@ -62,9 +66,10 @@ export class DocsSiteCheck implements ICheck { const browser = await (await this.loadPlaywrightAsync()).default.chromium.launch(); try { const findings: string[] = []; + const symbols = await DocsSymbols.createAsync(this.root); const links = await this.readMenuAsync(browser, address, findings); for (const link of links) - await this.checkPageAsync(browser, address, link.link, link.title, findings); + await this.checkPageAsync(browser, address, link.link, link.title, symbols, findings); for (const finding of findings) output.write(`${finding}\n`); output.write(`Opened ${links.length} pages of ${DocsSiteCheck.SITE_FOLDER} that the site's menu links.\n`); @@ -102,7 +107,7 @@ export class DocsSiteCheck implements ICheck { } } - private async checkPageAsync(browser: ISiteBrowser, address: string, link: string, title: string, findings: string[]): Promise { + private async checkPageAsync(browser: ISiteBrowser, address: string, link: string, title: string, symbols: MaterialSymbols, findings: string[]): Promise { const page = await browser.newPage(); const errors: string[] = []; DocsSiteCheck.collectErrors(page, errors); @@ -131,6 +136,9 @@ export class DocsSiteCheck implements ICheck { const shown = JsonFields.parse(String(await page.evaluate(DocsSiteCheck.SHOWN)), link); if (!isHighlighted) findings.push(DocsSiteCheck.unhighlighted(link, shown.count("plainCode"))); + const drawn = DocsSiteCheck.namesOf(await page.evaluate(MaterialSymbols.drawnGlyphs), link); + const fonts = DocsSiteCheck.namesOf(await page.evaluate(MaterialSymbols.loadedFonts), link); + findings.push(...await symbols.findPageProblemsAsync(link, drawn, link === DocsSymbols.wholeFontPage ? fonts.filter(t => !DocsSymbols.wholeFontFile.test(new URL(t).pathname)) : fonts)); for (const width of DocsSiteCheck.WIDTHS) await DocsSiteCheck.checkWrapsAsync(page, link, width, findings); const titles = shown.texts("titles"); @@ -163,6 +171,15 @@ export class DocsSiteCheck implements ICheck { return html.split(DocsSiteCheck.CODE_BLOCK_START).slice(1).filter(t => !t.slice(0, t.indexOf(DocsSiteCheck.CODE_BLOCK_END)).includes(DocsSiteCheck.CODE_LINE)).length; } + // The names a page expression gave as a JSON list. + private static namesOf(value: unknown, link: string): readonly string[] { + const parsed: unknown = JSON.parse(String(value)); + if (!Array.isArray(parsed)) + throw new Error(`${link} gave ${String(value)}, not a list of names.`); + const items: readonly unknown[] = parsed; + return items.filter(t => Object.isString(t)); + } + private static isTimeout(error: unknown): boolean { return error instanceof Error && error.name === DocsSiteCheck.TIMEOUT_ERROR; } diff --git a/src/noldova.ui.components.angular.docs/scripts/docs/docs-symbols.ts b/src/noldova.ui.components.angular.docs/scripts/docs/docs-symbols.ts new file mode 100644 index 00000000..cf449573 --- /dev/null +++ b/src/noldova.ui.components.angular.docs/scripts/docs/docs-symbols.ts @@ -0,0 +1,32 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { mkdir, writeFile } from "node:fs/promises"; +import path from "node:path"; + +import { KitGlyphs } from "../../../noldova.ui.components.angular/scripts/glyphs/kit-glyphs.ts"; +import { PartGlyphs } from "../../../noldova.ui.components.angular/scripts/glyphs/part-glyphs.ts"; +import { MaterialSymbols } from "../../../noldova.ui.components.angular/src/symbols/material-symbols.ts"; + +// The docs site's subset of the symbol font, from the glyphs of the kit's source as its build writes them to glyphs.json. The icon +// chooser can draw any glyph, so its page loads the whole font under a family of its own and the subset leaves its list out. +export class DocsSymbols { + public static readonly wholeFontPage: string = "/components/icon-chooser"; + public static readonly wholeFontFile: RegExp = /\/material-symbols-rounded[^/]*\.woff2$/u; + private static readonly SITE_FOLDER: string = "src/noldova.ui.components.angular.docs"; + private static readonly GLYPHS_FILE: string = "_build/docs-symbols/glyphs.json"; + private static readonly WHOLE_FONT_PARTS: readonly string[] = ["IconChooserComponent"]; + + public static async createAsync(root: string): Promise { + const glyphs = path.join(root, DocsSymbols.GLYPHS_FILE); + await mkdir(path.dirname(glyphs), { recursive: true }); + await writeFile(glyphs, PartGlyphs.render((await KitGlyphs.readAsync(root)).parts)); + const site = path.join(root, DocsSymbols.SITE_FOLDER); + return new MaterialSymbols({ root: site, kitGlyphs: path.relative(site, glyphs).split(path.sep).join(path.posix.sep), wholeFontParts: DocsSymbols.WHOLE_FONT_PARTS }); + } +} diff --git a/src/noldova.ui.components.angular.docs/scripts/prepare-symbols.ts b/src/noldova.ui.components.angular.docs/scripts/prepare-symbols.ts new file mode 100644 index 00000000..e7233842 --- /dev/null +++ b/src/noldova.ui.components.angular.docs/scripts/prepare-symbols.ts @@ -0,0 +1,23 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +import path from "node:path"; + +import Config from "../../noldova.ui.components.angular/scripts/config.ts"; +import Script from "../../noldova.ui.components.angular/scripts/script.ts"; +import { DocsSymbols } from "./docs/docs-symbols.ts"; + +// npm run symbols refreshes the docs site's subset of the symbol font; npm run symbols:check checks it. +export class PrepareSymbols extends Script { + public override async runAsync(): Promise { + await (await DocsSymbols.createAsync(path.resolve(Config.ROOT))).runAsync(process.argv.slice(2)); + } +} + +const preparer = new PrepareSymbols(); +await preparer.runAsEntryPointAsync(); diff --git a/src/noldova.ui.components.angular.docs/scripts/test-docs.ts b/src/noldova.ui.components.angular.docs/scripts/test-docs.ts index 0773df3b..17ac36f9 100644 --- a/src/noldova.ui.components.angular.docs/scripts/test-docs.ts +++ b/src/noldova.ui.components.angular.docs/scripts/test-docs.ts @@ -16,6 +16,7 @@ import { AngularCoverageReport } from "../../noldova.ui.components.angular/scrip import { AngularTestReport } from "../../noldova.ui.components.angular/scripts/angular/angular-test-report.ts"; import { DocsSiteCheck } from "./docs-site-check.ts"; import { DocsPreparation } from "./docs/docs-preparation.ts"; +import { DocsSymbols } from "./docs/docs-symbols.ts"; export class TestDocs extends Script { private static readonly ANGULAR_PROJECT: string = "docs"; @@ -27,6 +28,7 @@ export class TestDocs extends Script { private static readonly COVERAGE_FILE: string = "../../_build/angular-coverage/coverage-final.json"; private static readonly COVERAGE_OWNER: string = "The docs site's"; private static readonly BLANK_LINE: string = ""; + private static readonly SYMBOLS_TITLE: string = "The docs site's subset of the symbol font"; private static readonly WORKSPACE_FOLDER: string = "."; private static readonly PLATFORM: NodeJS.Platform = "linux"; private static readonly SUITE_OPTION: string = "--suite"; @@ -75,13 +77,29 @@ export class TestDocs extends Script { const findings = [...await report.checkAsync(file, specs), ...await coverage.listUnhitAsync()]; for (const finding of findings) await this.writeLogAsync(finding); + await this.writeLogAsync(TestDocs.BLANK_LINE); + await this.writeLogAsync(TestDocs.SYMBOLS_TITLE); + const isSubsetSound = await this.checkSubsetAsync(); const site = new DocsSiteCheck(TestDocs.ROOT); await this.writeLogAsync(TestDocs.BLANK_LINE); await this.writeLogAsync(site.title); const isSiteSound = await site.runAsync(process.stdout); - if (failed || findings.length > 0 || !isSiteSound) + if (failed || findings.length > 0 || !isSubsetSound || !isSiteSound) process.exitCode = 1; } + + private async checkSubsetAsync(): Promise { + try { + await (await DocsSymbols.createAsync(TestDocs.ROOT)).checkAsync(); + return true; + } + catch (error) { + if (!(error instanceof Error)) + throw error; + await this.writeLogAsync(error.message); + return false; + } + } } const test = new TestDocs(); diff --git a/src/noldova.ui.components.angular.docs/src/styles.css b/src/noldova.ui.components.angular.docs/src/styles.css index b8bd0b78..07312bd6 100644 --- a/src/noldova.ui.components.angular.docs/src/styles.css +++ b/src/noldova.ui.components.angular.docs/src/styles.css @@ -6,6 +6,30 @@ * LICENSE file in the root directory of this source tree. */ +/* The pages and the kit's parts draw their glyphs in Material Symbols, which the site serves as a subset holding only the glyphs + * they draw; npm run symbols builds it again and names this file. */ +@font-face { + font-family: "Material Symbols Rounded"; + src: url("/assets/fonts/material-symbols.woff2") format("woff2"); + font-style: normal; + font-weight: 400; + font-display: block; +} + +/* The icon chooser can draw any glyph, so it draws them in the whole font under a family of its own, which the browser fetches only + * on the page that shows it. */ +@font-face { + font-family: "Material Symbols Rounded Whole"; + src: url("../../../node_modules/material-symbols/material-symbols-rounded.woff2") format("woff2"); + font-style: normal; + font-weight: 400; + font-display: block; +} + +nol-icon-chooser .material-symbols-rounded { + font-family: "Material Symbols Rounded Whole"; +} + :root { scroll-padding-block-start: var(--nol-docs-header-height, 0px); } diff --git a/src/noldova.ui.components.angular/src/api/symbols.d.ts b/src/noldova.ui.components.angular/src/api/symbols.d.ts index ebad25a4..8fc1028c 100644 --- a/src/noldova.ui.components.angular/src/api/symbols.d.ts +++ b/src/noldova.ui.components.angular/src/api/symbols.d.ts @@ -61,6 +61,14 @@ export interface IMaterialSymbolsSite { * reading finds them, such as an icon its code builds or reads from data. */ readonly names?: readonly string[]; + + /** + * The kit's parts, by class name, that the site shows only on pages that + * load the whole font under a family of their own, such as + * `IconChooserComponent`, whose list holds every glyph of the set: the + * subset leaves their `glyphs.json` lists out. + */ + readonly wholeFontParts?: readonly string[]; } /** diff --git a/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts b/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts index b2973396..088d2948 100644 --- a/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts +++ b/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts @@ -16,4 +16,5 @@ export interface IMaterialSymbolsSite { readonly fontsAddress?: string; readonly kitGlyphs?: string; readonly names?: readonly string[]; + readonly wholeFontParts?: readonly string[]; } diff --git a/src/noldova.ui.components.angular/src/symbols/material-symbols.ts b/src/noldova.ui.components.angular/src/symbols/material-symbols.ts index 2a1400cd..af17a8c9 100644 --- a/src/noldova.ui.components.angular/src/symbols/material-symbols.ts +++ b/src/noldova.ui.components.angular/src/symbols/material-symbols.ts @@ -70,6 +70,7 @@ export class MaterialSymbols { private readonly fontsAddress: string; private readonly kitGlyphs: string; private readonly names: readonly string[]; + private readonly wholeFontParts: ReadonlySet; public constructor(site: IMaterialSymbolsSite) { this.root = site.root; @@ -82,6 +83,7 @@ export class MaterialSymbols { this.fontsAddress = site.fontsAddress ?? MaterialSymbols.DEFAULT_FONTS_ADDRESS; this.kitGlyphs = site.kitGlyphs ?? MaterialSymbols.DEFAULT_KIT_GLYPHS; this.names = site.names ?? []; + this.wholeFontParts = new Set(site.wholeFontParts); } // What the command line asks for: with --check, the check, and otherwise the refresh. @@ -198,7 +200,8 @@ export class MaterialSymbols { } // The glyphs the kit's parts the site's code imports can draw: the union of their lists in the kit's glyphs.json. A name the - // site imports that is no part, such as a model or a type, has no list there. + // site imports that is no part, such as a model or a type, has no list there, and a part the site shows only in the whole font + // adds nothing. private async kitIconNamesAsync(): Promise> { const parts = MaterialSymbols.field(await this.kitGlyphListAsync(), "parts"); if (!Object.isObject(parts)) @@ -208,7 +211,7 @@ export class MaterialSymbols { await this.collectKitImportsAsync(this.at(this.code), imported); const names = new Set(); for (const part of imported) { - if (!lists.has(part)) + if (!lists.has(part) || this.wholeFontParts.has(part)) continue; const list = lists.get(part); if (!Array.isArray(list)) diff --git a/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts b/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts index 9baec16a..9dd52a39 100644 --- a/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts +++ b/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts @@ -222,6 +222,12 @@ describe("MaterialSymbols.checkAsync", () => { assert.equal(await current().refusalAsync(), changed); }); + it("leaves out the lists of the kit parts the site shows only in the whole font, and only theirs", async () => { + await current().writeAsync("src/app/canvas.ts", "import { SiteCanvasComponent } from \"@noldova/ui.components.angular/site\";\n"); + assert.equal(await current().refusalAsync({ wholeFontParts: ["SiteCanvasComponent"] }), ""); + assert.equal(await current().refusalAsync({ wholeFontParts: ["SiteCanvasComponent", "SiteHeaderComponent"] }), changed); + }); + it("reads the site's own folders, stylesheet, font address and glyphs.json", async () => { await current().writeAsync(`web/fonts/${filename}`, font); await current().writeAsync("web/notices/README.txt", Site.notice(digest, filename, source)); From 356c30e70a21832362baa5ba870d549598dcb31d Mon Sep 17 00:00:00 2001 From: Rostislav Rotaru Date: Sat, 28 Nov 2026 19:33:44 -0800 Subject: [PATCH 5/9] Fix the symbols review: the package rule, coverage, digits and the kit's code rules - symbols.css holds material-symbols' own rule, every declaration but the font, so kit.css gives the symbol class what it gave before; the stylesheet test compares declarations with the installed package's rule. - The Node.js tests measure their coverage of the symbols entry's code and fail below 100%; the Angular specs leave it out, as README says. - Tests for digits in drawn, given and kept glyph names. - MaterialSymbolsException, a UiComponentsException; the strings in MaterialSymbolsResources and MaterialSymbolsSiteResources; sites are MaterialSymbolsSite instances. - KIT.md says a site with the icon chooser keeps kit.css; the notice names the font by its served address. Agent: DEV7 (developer) Agent-Model: Anthropic Opus 5.5, Medium --- README.md | 2 +- documents/KIT.md | 7 +- .../angular.json | 1 + .../scripts/test.ts | 15 +- .../src/api/symbols.d.ts | 150 ++++++++++++--- .../src/api/symbols.ts | 2 + .../exceptions/material-symbols.exception.ts | 19 ++ .../src/styles/symbols.css | 13 +- .../interfaces/i-material-symbols-site.ts | 14 +- .../material-symbols-site.resources.ts | 16 ++ .../src/symbols/material-symbols-site.ts | 26 +++ .../src/symbols/material-symbols.resources.ts | 101 ++++++++++ .../src/symbols/material-symbols.ts | 173 ++++++++---------- .../tests/node/kit-stylesheets.test.ts | 90 +++++++-- .../tests/node/material-symbols.test.ts | 85 +++++++-- .../tests/node/source-imports.ts | 27 +++ 16 files changed, 560 insertions(+), 181 deletions(-) create mode 100644 src/noldova.ui.components.angular/src/app/exceptions/material-symbols.exception.ts create mode 100644 src/noldova.ui.components.angular/src/symbols/material-symbols-site.resources.ts create mode 100644 src/noldova.ui.components.angular/src/symbols/material-symbols-site.ts create mode 100644 src/noldova.ui.components.angular/src/symbols/material-symbols.resources.ts create mode 100644 src/noldova.ui.components.angular/tests/node/source-imports.ts diff --git a/README.md b/README.md index 5b2109fa..9b427417 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ The repository's automation, in each package's `scripts/`, has no coverage requi | Scope | Requirement | |---|---| -| `src/noldova.ui.components.angular` | 100% of executable production code, measured by the component and service specs through the Angular unit-test builder, without the enum files and class-metadata calls that the Angular standard leaves out; the coverage plugin under `src/noldova.ui.components.angular/tests/coverage` marks those calls and reports how many it skipped. | +| `src/noldova.ui.components.angular` | 100% of executable production code, measured by the component and service specs through the Angular unit-test builder, without the enum files and class-metadata calls that the Angular standard leaves out; the coverage plugin under `src/noldova.ui.components.angular/tests/coverage` marks those calls and reports how many it skipped. The Node.js entry's code, `src/symbols/`, `src/api/symbols.ts` and `src/app/exceptions/material-symbols.exception.ts`, loads in no browser, so the Angular specs leave it out and the Node.js tests measure it instead: `node --test --experimental-test-coverage` fails below 100% of its lines, branches and functions, in a whole run and in a shard's first part. | | `src/noldova.ui.components.angular.docs` | 100% of executable production code, measured by the docs site's specs the same way, without its enum files and class-metadata calls and its entry points and server settings, `main.ts`, `main.server.ts`, `app.config.server.ts` and `app.routes.server.ts`, which run only in the browser's start and the prerender; the built-site check in `npm run docs:test` opens every page they produce. | ### OnPush strategies diff --git a/documents/KIT.md b/documents/KIT.md index 6668220a..0008f9d0 100644 --- a/documents/KIT.md +++ b/documents/KIT.md @@ -289,12 +289,13 @@ A glyph the site passes to a part, such as an icon button's `icon` or a `SiteAct The icon chooser's and the gallery's lists hold every name of the set, since they can draw any of them. A site gets its subset from the entry `@noldova/ui.components.angular/symbols`, a Node.js tool that loads in no browser: -- Its `MaterialSymbols` reads the union of the `glyphs.json` lists of the kit's parts the site's code imports, the icons its templates draw between the symbol class's span tags or give a part as `icon="…"`, the glyphs its code keeps in a field whose name ends in glyph, as an `IconName` or a string, and the names the site gives it for icons its code builds; a refresh, which the site runs as `npm run symbols`, downloads that subset from Google Fonts with its license, keeps it in the site's fonts folder named by its SHA-256, points the site's `@font-face` at it and records its SHA-256 and source in the site's license notice. +- Its `MaterialSymbols` takes where the site keeps its subset as a `MaterialSymbolsSite`, whose defaults a site overrides in a class of its own, and fails with a `MaterialSymbolsException`, a `UiComponentsException`. + It reads the union of the `glyphs.json` lists of the kit's parts the site's code imports, the icons its templates draw between the symbol class's span tags or give a part as `icon="…"`, the glyphs its code keeps in a field whose name ends in glyph, as an `IconName` or a string, and the names the site gives it for icons its code builds; a refresh, which the site runs as `npm run symbols`, downloads that subset from Google Fonts with its license, keeps it in the site's fonts folder named by its SHA-256, points the site's `@font-face` at it and records the address the site serves it at, its SHA-256 and its source in the site's license notice. - Its check, `npm run symbols -- --check` in the site's checks, fails when the committed font, its record, its stylesheet or the glyphs the site draws disagree. - Its `drawnGlyphs` and `loadedFonts` page expressions and `findPageProblemsAsync` let the site's check of its built pages fail on a page that draws a glyph the subset lacks, or that loads another copy of the font, such as the whole font `kit.css` brings. -Such a site loads `styles/kit-without-symbol-font.css` in place of `styles/kit.css`: everything `kit.css` loads but the whole font, with the symbol class's text rules, `styles/symbols.css`, first, and declares the subset's `@font-face` for the family `Material Symbols Rounded` itself. -A page that must draw any glyph, such as the icon chooser's, loads the whole font under a family of its own, so the browser fetches it only on that page. +Such a site loads `styles/kit-without-symbol-font.css` in place of `styles/kit.css`: everything `kit.css` loads but the whole font, with the symbol class's rule from material-symbols' own `rounded.css`, every declaration but the font, in `styles/symbols.css`, first, so the class gets the same declarations from either; it declares the subset's `@font-face` for the family `Material Symbols Rounded` itself. +The icon chooser draws any glyph of the set in that class, so a site that shows it keeps `styles/kit.css` and the whole font. ## Controls diff --git a/src/noldova.ui.components.angular/angular.json b/src/noldova.ui.components.angular/angular.json index c70f9f0e..d3aed801 100644 --- a/src/noldova.ui.components.angular/angular.json +++ b/src/noldova.ui.components.angular/angular.json @@ -54,6 +54,7 @@ "coverageExclude": [ "src/app/enums/**", "src/api/symbols.ts", + "src/app/exceptions/material-symbols.exception.ts", "src/symbols/**" ] }, diff --git a/src/noldova.ui.components.angular/scripts/test.ts b/src/noldova.ui.components.angular/scripts/test.ts index b9e2c354..d5dff1f4 100644 --- a/src/noldova.ui.components.angular/scripts/test.ts +++ b/src/noldova.ui.components.angular/scripts/test.ts @@ -40,7 +40,18 @@ export class Test extends Script { private static readonly NODE_TESTS_TITLE: string = "The Node.js tests"; private static readonly NODE_TESTS_FOLDER: string = "tests/node"; private static readonly NODE_TEST_FILE: string = ".test.ts"; - private static readonly NODE_TEST_OPTION: string = "--test"; + private static readonly NODE_TEST_OPTIONS: readonly string[] = ["--import", "./tests/node/source-imports.ts", "--test"]; + // The Node.js code's own coverage gate, which a whole run and a shard's first part keep: every line, branch and function of the + // Node.js entry's code, which no Angular spec loads. + private static readonly NODE_COVERAGE_OPTIONS: readonly string[] = [ + "--experimental-test-coverage", + "--test-coverage-include=src/symbols/**/*.ts", + "--test-coverage-include=src/api/symbols.ts", + "--test-coverage-include=src/app/exceptions/material-symbols.exception.ts", + "--test-coverage-lines=100", + "--test-coverage-branches=100", + "--test-coverage-functions=100" + ]; private static readonly KIT_CHECK_PLATFORM: NodeJS.Platform = "linux"; private static readonly KIT_CHECK_ARCHITECTURE: NodeJS.Architecture = "x64"; private static readonly KIT_CHECKS_SKIPPED: string = "The Kit bundles, the Kit copies, the Kit manifest and Angular's newest run only on Linux x64; skipped."; @@ -146,7 +157,7 @@ export class Test extends Script { return 0; await this.writeLogAsync(Test.BLANK_LINE); await this.writeLogAsync(Test.NODE_TESTS_TITLE); - await this.runCommandAsync(process.execPath, [Test.NODE_TEST_OPTION, ...selected], Test.WORKSPACE_FOLDER); + await this.runCommandAsync(process.execPath, [...Test.NODE_TEST_OPTIONS, ...filters.length === 0 ? Test.NODE_COVERAGE_OPTIONS : [], ...selected], Test.WORKSPACE_FOLDER); return selected.length; } diff --git a/src/noldova.ui.components.angular/src/api/symbols.d.ts b/src/noldova.ui.components.angular/src/api/symbols.d.ts index ebad25a4..627e724e 100644 --- a/src/noldova.ui.components.angular/src/api/symbols.d.ts +++ b/src/noldova.ui.components.angular/src/api/symbols.d.ts @@ -6,9 +6,13 @@ * LICENSE file in the root directory of this source tree. */ +import type { ExceptionOptions } from "@noldova/context.exceptions"; +import { UiComponentsException } from "@noldova/ui.components.angular"; + /** * Where a site keeps what its subset of the symbol font needs. Every path is - * relative to `root`, written with forward slashes. + * relative to `root`, written with forward slashes. {@link MaterialSymbolsSite} + * gives each the kit's default. */ export interface IMaterialSymbolsSite { /** @@ -20,47 +24,134 @@ export interface IMaterialSymbolsSite { /** * The folder of the site's code, read for the kit's parts it imports, the * icons its templates draw or give a part's `icon`, and the glyphs its code - * keeps by name; `src` when left out. + * keeps by name. */ - readonly code?: string; + readonly code: string; /** * The stylesheet whose `@font-face` loads the subset, which a refresh - * points at the new font; `src/styles.css` when left out. + * points at the new font. */ - readonly styles?: string; + readonly styles: string; /** - * The folder that holds the subset and nothing else of the font; - * `public/assets/fonts` when left out. + * The folder that holds the subset and nothing else of the font. */ - readonly fonts?: string; + readonly fonts: string; /** * The folder of the site's license notice, `README.txt`, and of the - * font's license, `MATERIAL-SYMBOLS-LICENSE.txt`; `public/assets/licenses` - * when left out. + * font's license, `MATERIAL-SYMBOLS-LICENSE.txt`. */ - readonly licenses?: string; + readonly licenses: string; /** * The address the site serves the fonts folder at, which the stylesheet's - * `@font-face` names; `/assets/fonts/` when left out. + * `@font-face` and the notice name. */ - readonly fontsAddress?: string; + readonly fontsAddress: string; /** - * The kit's `glyphs.json`, the glyphs each part can draw; the installed - * kit's, `node_modules/@noldova/ui.components.angular/glyphs.json`, when - * left out. + * The kit's `glyphs.json`, the glyphs each part can draw. */ - readonly kitGlyphs?: string; + readonly kitGlyphs: string; /** * The icons the site draws that its code doesn't name where the subset's * reading finds them, such as an icon its code builds or reads from data. */ - readonly names?: readonly string[]; + readonly names: readonly string[]; +} + +/** + * A site that keeps its subset where the kit's defaults put it. A site that + * keeps it elsewhere, or names icons of its own, extends it and overrides the + * fields that differ. + * + * @example + * ```ts + * import { MaterialSymbolsSite } from "@noldova/ui.components.angular/symbols"; + * + * export class DocsSymbolsSite extends MaterialSymbolsSite { + * public override readonly kitGlyphs: string = "../../node_modules/@noldova/ui.components.angular/glyphs.json"; + * } + * ``` + */ +export declare class MaterialSymbolsSite implements IMaterialSymbolsSite { + /** + * The site's own folder, from which every other path is read. + */ + public readonly root: string; + + /** + * The folder of the site's code, `src`. + */ + public readonly code: string; + + /** + * The stylesheet whose `@font-face` loads the subset, `src/styles.css`. + */ + public readonly styles: string; + + /** + * The folder that holds the subset, `public/assets/fonts`. + */ + public readonly fonts: string; + + /** + * The folder of the notice and the font's license, + * `public/assets/licenses`. + */ + public readonly licenses: string; + + /** + * The address the site serves the fonts folder at, `/assets/fonts/`. + */ + public readonly fontsAddress: string; + + /** + * The installed kit's `glyphs.json`, + * `node_modules/@noldova/ui.components.angular/glyphs.json`. + */ + public readonly kitGlyphs: string; + + /** + * No icons beyond those the site's code names. + */ + public readonly names: readonly string[]; + + /** + * @param root The site's own folder. + */ + public constructor(root: string); +} + +/** + * The exception {@link MaterialSymbols} throws when a refresh's download + * fails, the kit's `glyphs.json` can't be read, or the check finds the + * subset, its record, its stylesheet or its license wrong. + */ +export declare class MaterialSymbolsException extends UiComponentsException { + /** + * The exception's name, `"MaterialSymbolsException"`, which the class sets + * itself so that a minified build keeps it. + */ + public override readonly name: string; + + /** + * Creates the exception. + * + * @param message A sentence naming what failed. + * @param options The failure that caused it, as its `cause`, such as the + * error reading the kit's `glyphs.json` met. + * @example + * ```ts + * import { MaterialSymbolsException } from "@noldova/ui.components.angular/symbols"; + * + * export const failed: MaterialSymbolsException = new MaterialSymbolsException("Font download failed: 503"); + * ``` + */ + public constructor(message: string, options?: ExceptionOptions); } /** @@ -73,17 +164,17 @@ export interface IMaterialSymbolsSite { * `icon`, the glyphs its code keeps in a field whose name ends in glyph, and * the site's own `names`. A refresh asks Google Fonts for that subset, keeps * it in the fonts folder named by its SHA-256, points the stylesheet at it - * and records its SHA-256 and source address in the license notice; the check - * reads it all again and fails where any of it disagrees, and the site's - * check of its built pages fails on a page that draws a glyph the subset lacks - * or loads another copy of the font. + * and records its served address, SHA-256 and source address in the license + * notice; the check reads it all again and fails where any of it disagrees, + * and the site's check of its built pages fails on a page that draws a glyph + * the subset lacks or loads another copy of the font. * * @example * ```ts - * import { MaterialSymbols } from "@noldova/ui.components.angular/symbols"; + * import { MaterialSymbols, MaterialSymbolsSite } from "@noldova/ui.components.angular/symbols"; * * // npm run symbols refreshes the subset; npm run symbols -- --check checks it. - * await new MaterialSymbols({ root: process.cwd() }).runAsync(process.argv.slice(2)); + * await new MaterialSymbols(new MaterialSymbolsSite(process.cwd())).runAsync(process.argv.slice(2)); * ``` */ export declare class MaterialSymbols { @@ -109,7 +200,8 @@ export declare class MaterialSymbols { public static readonly loadedFonts: string; /** - * @param site Where the site keeps its subset. + * @param site Where the site keeps its subset, such as a + * {@link MaterialSymbolsSite}. */ public constructor(site: IMaterialSymbolsSite); @@ -128,8 +220,9 @@ export declare class MaterialSymbols { * the font's license, and writes the font, the stylesheet's address of it * and the notice's record of it, keeping the notice's other lines. * - * @returns Resolves once the subset is written, and rejects, leaving the - * notice as it was, when a download fails or answers something else. + * @returns Resolves once the subset is written, and rejects with a + * {@link MaterialSymbolsException}, leaving the notice as it was, when a + * download fails or answers something else. */ public refreshAsync(): Promise; @@ -139,7 +232,8 @@ export declare class MaterialSymbols { * loads it, it holds exactly the icons the site draws, and the license is * there. * - * @returns Resolves when the subset agrees with all of it. + * @returns Resolves when the subset agrees with all of it, and rejects with + * a {@link MaterialSymbolsException} naming each problem otherwise. */ public checkAsync(): Promise; diff --git a/src/noldova.ui.components.angular/src/api/symbols.ts b/src/noldova.ui.components.angular/src/api/symbols.ts index 384f3a55..77f8fabf 100644 --- a/src/noldova.ui.components.angular/src/api/symbols.ts +++ b/src/noldova.ui.components.angular/src/api/symbols.ts @@ -8,3 +8,5 @@ export type { IMaterialSymbolsSite } from "../symbols/interfaces/i-material-symbols-site.js"; export { MaterialSymbols } from "../symbols/material-symbols.js"; +export { MaterialSymbolsException } from "../app/exceptions/material-symbols.exception.js"; +export { MaterialSymbolsSite } from "../symbols/material-symbols-site.js"; diff --git a/src/noldova.ui.components.angular/src/app/exceptions/material-symbols.exception.ts b/src/noldova.ui.components.angular/src/app/exceptions/material-symbols.exception.ts new file mode 100644 index 00000000..b8072dcb --- /dev/null +++ b/src/noldova.ui.components.angular/src/app/exceptions/material-symbols.exception.ts @@ -0,0 +1,19 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +import type { ExceptionOptions } from "@noldova/context.exceptions"; + +import { UiComponentsException } from "./ui-components.exception.js"; + +export class MaterialSymbolsException extends UiComponentsException { + public override readonly name: string = "MaterialSymbolsException"; + + public constructor(message: string, options?: ExceptionOptions) { + super(message, options); + } +} diff --git a/src/noldova.ui.components.angular/src/styles/symbols.css b/src/noldova.ui.components.angular/src/styles/symbols.css index aca04dcf..cccea364 100644 --- a/src/noldova.ui.components.angular/src/styles/symbols.css +++ b/src/noldova.ui.components.angular/src/styles/symbols.css @@ -6,19 +6,22 @@ * LICENSE file in the root directory of this source tree. */ -/* The Material Symbols class's text rules with no font, for a site that serves its own subset of the font and declares the - * subset's @font-face itself. */ +/* The Material Symbols class's rule from material-symbols' rounded.css, with every declaration but no font, for a site that serves + * its own subset of the font and declares the subset's @font-face itself; loaded after the package's rule, it changes nothing. */ .material-symbols-rounded { font-family: "Material Symbols Rounded"; - font-weight: 400; + font-weight: normal; font-style: normal; + font-size: 24px; + line-height: 1; letter-spacing: normal; text-transform: none; display: inline-block; white-space: nowrap; word-wrap: normal; direction: ltr; - font-feature-settings: "liga"; -webkit-font-smoothing: antialiased; - flex-shrink: 0; + -moz-osx-font-smoothing: grayscale; + text-rendering: optimizeLegibility; + font-feature-settings: "liga"; } diff --git a/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts b/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts index b2973396..497c559e 100644 --- a/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts +++ b/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts @@ -9,11 +9,11 @@ // Where a site keeps what its subset of the symbol font needs, each path relative to its root. export interface IMaterialSymbolsSite { readonly root: string; - readonly code?: string; - readonly styles?: string; - readonly fonts?: string; - readonly licenses?: string; - readonly fontsAddress?: string; - readonly kitGlyphs?: string; - readonly names?: readonly string[]; + readonly code: string; + readonly styles: string; + readonly fonts: string; + readonly licenses: string; + readonly fontsAddress: string; + readonly kitGlyphs: string; + readonly names: readonly string[]; } diff --git a/src/noldova.ui.components.angular/src/symbols/material-symbols-site.resources.ts b/src/noldova.ui.components.angular/src/symbols/material-symbols-site.resources.ts new file mode 100644 index 00000000..832744e9 --- /dev/null +++ b/src/noldova.ui.components.angular/src/symbols/material-symbols-site.resources.ts @@ -0,0 +1,16 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +export class MaterialSymbolsSiteResources { + public static readonly code: string = "src"; + public static readonly styles: string = "src/styles.css"; + public static readonly fonts: string = "public/assets/fonts"; + public static readonly licenses: string = "public/assets/licenses"; + public static readonly fontsAddress: string = "/assets/fonts/"; + public static readonly kitGlyphs: string = "node_modules/@noldova/ui.components.angular/glyphs.json"; +} diff --git a/src/noldova.ui.components.angular/src/symbols/material-symbols-site.ts b/src/noldova.ui.components.angular/src/symbols/material-symbols-site.ts new file mode 100644 index 00000000..43edf252 --- /dev/null +++ b/src/noldova.ui.components.angular/src/symbols/material-symbols-site.ts @@ -0,0 +1,26 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +import type { IMaterialSymbolsSite } from "./interfaces/i-material-symbols-site.js"; +import { MaterialSymbolsSiteResources } from "./material-symbols-site.resources.js"; + +// A site that keeps its subset where the kit's defaults put it; a site that keeps it elsewhere overrides the fields that differ. +export class MaterialSymbolsSite implements IMaterialSymbolsSite { + public readonly root: string; + public readonly code: string = MaterialSymbolsSiteResources.code; + public readonly styles: string = MaterialSymbolsSiteResources.styles; + public readonly fonts: string = MaterialSymbolsSiteResources.fonts; + public readonly licenses: string = MaterialSymbolsSiteResources.licenses; + public readonly fontsAddress: string = MaterialSymbolsSiteResources.fontsAddress; + public readonly kitGlyphs: string = MaterialSymbolsSiteResources.kitGlyphs; + public readonly names: readonly string[] = []; + + public constructor(root: string) { + this.root = root; + } +} diff --git a/src/noldova.ui.components.angular/src/symbols/material-symbols.resources.ts b/src/noldova.ui.components.angular/src/symbols/material-symbols.resources.ts new file mode 100644 index 00000000..5e538a01 --- /dev/null +++ b/src/noldova.ui.components.angular/src/symbols/material-symbols.resources.ts @@ -0,0 +1,101 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +export class MaterialSymbolsResources { + public static readonly family: string = "Material Symbols Rounded"; + public static readonly kitName: string = "@noldova/ui.components.angular"; + public static readonly noticeFile: string = "README.txt"; + public static readonly licenseFile: string = "MATERIAL-SYMBOLS-LICENSE.txt"; + public static readonly fontFilePrefix: string = "material-symbols"; + public static readonly checkOption: string = "--check"; + public static readonly encoding: BufferEncoding = "utf8"; + public static readonly missingFile: string = "ENOENT"; + public static readonly woff2Signature: string = "wOF2"; + public static readonly licenseTitle: string = "Apache License"; + public static readonly partsField: string = "parts"; + public static readonly iconNamesParameter: string = "icon_names"; + public static readonly htmlExtension: string = ".html"; + public static readonly codeExtension: string = ".ts"; + public static readonly browser: string = + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"; + public static readonly licenseAddress: string = "https://raw.githubusercontent.com/google/material-design-icons/master/LICENSE"; + public static readonly sourceAddress: string = "https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@24,400,0,0&icon_names="; + public static readonly sourceEnd: string = "&display=swap"; + public static readonly noFont: string = "no font"; + public static readonly fontAddressMissing: string = "Expected an official Google Fonts font URL."; + public static readonly notWoff2: string = "Expected a WOFF2 font."; + public static readonly licenseDownloadFailed: string = "Material Symbols license download failed."; + public static readonly subsetChanged: string = "The icons the site draws differ from the recorded subset; run npm run symbols."; + public static readonly subsetSound: string = "The Material Symbols subset matches its recorded SHA-256, its notice and the icons the site draws."; + public static formatFontName(digest: string): string { + return `${MaterialSymbolsResources.fontFilePrefix}-${digest.slice(0, 8)}.woff2`; + } + public static formatStylesheetDownloadFailed(status: number): string { + return `Font stylesheet download failed: ${status}`; + } + public static formatFontDownloadFailed(status: number): string { + return `Font download failed: ${status}`; + } + public static formatSelfHosted(count: number, bytes: number, digest: string): string { + return `Self-hosted ${count} Material Symbols in ${bytes} bytes, SHA-256 ${digest}.`; + } + public static formatNoRecord(notice: string): string { + return `${notice} records no SHA-256 or source.`; + } + public static formatOtherFonts(fonts: string, held: readonly string[], filename: string): string { + return `${fonts} holds ${held.join(", ") || MaterialSymbolsResources.noFont}, not only the recorded ${filename}.`; + } + public static formatFontChanged(filename: string): string { + return `${filename} does not match its recorded SHA-256.`; + } + public static formatFontMisnamed(filename: string): string { + return `${filename} is not named by its SHA-256.`; + } + public static formatStylesWithoutFont(styles: string, filename: string): string { + return `${styles} does not load ${filename}.`; + } + public static formatLicenseMissing(license: string): string { + return `${license} does not hold the Apache 2.0 license.`; + } + public static formatPageUnchecked(notice: string, page: string): string { + return `${notice} records no subset, so ${page} can't be checked.`; + } + public static formatPageDrawsMissing(page: string, missing: readonly string[], record: string): string { + return `${page} draws ${missing.join(", ")}, which the subset ${record} lacks; run npm run symbols.`; + } + public static formatPageLoadsOther(page: string, font: string, record: string): string { + return `${page} loads ${font}, a copy of the symbol font other than the subset ${record}.`; + } + public static formatNoParts(kitGlyphs: string): string { + return `${kitGlyphs} lists no parts.`; + } + public static formatListNotList(kitGlyphs: string, part: string): string { + return `${kitGlyphs} lists ${part}'s glyphs as something other than a list.`; + } + public static formatListNotNames(kitGlyphs: string, part: string): string { + return `${kitGlyphs} lists ${part}'s glyphs as something other than names.`; + } + public static formatKitGlyphsUnread(kitGlyphs: string): string { + return `${kitGlyphs} can't be read; the site needs ${MaterialSymbolsResources.kitName} 0.0.37 or later.`; + } + public static formatKitGlyphsNotJson(kitGlyphs: string): string { + return `${kitGlyphs} isn't JSON.`; + } + public static formatNoticeFrom(): string { + return `Material Symbols is from Google material-design-icons, under the Apache 2.0 license in ${MaterialSymbolsResources.licenseFile}.`; + } + public static formatNoticeServes(address: string): string { + return `The site serves a subset of it, ${address}, holding only the icons it draws; refresh it with npm run symbols after adding an icon.`; + } + public static formatNoticeDigest(digest: string, filename: string): string { + return `SHA-256: ${digest} ${filename}`; + } + public static formatNoticeSource(address: string): string { + return `Source: ${address}`; + } +} diff --git a/src/noldova.ui.components.angular/src/symbols/material-symbols.ts b/src/noldova.ui.components.angular/src/symbols/material-symbols.ts index 2a1400cd..7ff69319 100644 --- a/src/noldova.ui.components.angular/src/symbols/material-symbols.ts +++ b/src/noldova.ui.components.angular/src/symbols/material-symbols.ts @@ -11,35 +11,24 @@ import { createHash } from "node:crypto"; import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises"; import path from "node:path"; +import { ExceptionOptions } from "@noldova/context.exceptions"; + +import { MaterialSymbolsException } from "../app/exceptions/material-symbols.exception.js"; import type { IMaterialSymbolsSite } from "./interfaces/i-material-symbols-site.js"; +import { MaterialSymbolsResources } from "./material-symbols.resources.js"; // Self-hosts the subset of Material Symbols a site draws, and records its SHA-256 beside its license notice; its check fails when // the committed font, its record, its notice or the icons the site draws disagree, and its page check when a built page draws a // glyph the subset lacks or loads another copy of the font. Every path is under the site's root folder. export class MaterialSymbols { - public static readonly family: string = "Material Symbols Rounded"; + public static readonly family: string = MaterialSymbolsResources.family; // A page expression that gives, as JSON, the sorted names each element drawn in the symbol font's own family shows as its text. public static readonly drawnGlyphs: string = `JSON.stringify([...new Set([...document.querySelectorAll('body *')].filter(t => getComputedStyle(t).fontFamily.split(',')[0].replaceAll('"', '').replaceAll("'", '').trim() === '${MaterialSymbols.family}' && [...t.childNodes].some(u => u.nodeType === Node.TEXT_NODE && (u.textContent ?? '').trim() !== '')).map(t => (t.textContent ?? '').trim()))].sort())`; // A page expression that gives, as JSON, the addresses of the fonts the page loaded, once its fonts are ready. public static readonly loadedFonts: string = "document.fonts.ready.then(() => JSON.stringify(performance.getEntriesByType('resource').map(t => t.name).filter(t => new URL(t).pathname.endsWith('.woff2'))))"; - private static readonly KIT_NAME: string = "@noldova/ui.components.angular"; - private static readonly DEFAULT_CODE: string = "src"; - private static readonly DEFAULT_STYLES: string = "src/styles.css"; - private static readonly DEFAULT_FONTS: string = "public/assets/fonts"; - private static readonly DEFAULT_LICENSES: string = "public/assets/licenses"; - private static readonly DEFAULT_FONTS_ADDRESS: string = "/assets/fonts/"; - private static readonly DEFAULT_KIT_GLYPHS: string = `node_modules/${MaterialSymbols.KIT_NAME}/glyphs.json`; - private static readonly NOTICE: string = "README.txt"; - private static readonly LICENSE: string = "MATERIAL-SYMBOLS-LICENSE.txt"; - private static readonly CHECK_OPTION: string = "--check"; private static readonly TIMEOUT: number = 30_000; - private static readonly BROWSER: string = - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"; - private static readonly LICENSE_ADDRESS: string = "https://raw.githubusercontent.com/google/material-design-icons/master/LICENSE"; - private static readonly SOURCE_ADDRESS: string = "https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@24,400,0,0&icon_names="; - private static readonly SOURCE_END: string = "&display=swap"; private static readonly FONT_ADDRESS: RegExp = /url\((https:\/\/fonts\.gstatic\.com\/[^)]+)\)/u; // An icon a template draws by its name, written between the symbol font's span tags. private static readonly DRAWN_ICON: RegExp = /]*material-symbols-rounded[^>]*>\s*([a-z0-9_]+)\s*<\/span\s*>/gu; @@ -58,125 +47,111 @@ export class MaterialSymbols { // A line of the subset's own record in the notice, which a refresh writes again. private static readonly RECORD_LINE: RegExp = /^(?:Material Symbols is from |The site serves a subset of it, |SHA-256: [a-f0-9]{64} {2}material-symbols-[a-f0-9]{8}\.woff2$|Source: https:\/\/fonts\.googleapis\.com\/)/u; - private static readonly ENCODING: BufferEncoding = "utf8"; - private static readonly MISSING_FILE: string = "ENOENT"; - private readonly root: string; - private readonly code: string; - private readonly styles: string; - private readonly fonts: string; + private readonly site: IMaterialSymbolsSite; private readonly notice: string; private readonly license: string; - private readonly fontsAddress: string; - private readonly kitGlyphs: string; - private readonly names: readonly string[]; public constructor(site: IMaterialSymbolsSite) { - this.root = site.root; - this.code = site.code ?? MaterialSymbols.DEFAULT_CODE; - this.styles = site.styles ?? MaterialSymbols.DEFAULT_STYLES; - this.fonts = site.fonts ?? MaterialSymbols.DEFAULT_FONTS; - const licenses = site.licenses ?? MaterialSymbols.DEFAULT_LICENSES; - this.notice = path.posix.join(licenses, MaterialSymbols.NOTICE); - this.license = path.posix.join(licenses, MaterialSymbols.LICENSE); - this.fontsAddress = site.fontsAddress ?? MaterialSymbols.DEFAULT_FONTS_ADDRESS; - this.kitGlyphs = site.kitGlyphs ?? MaterialSymbols.DEFAULT_KIT_GLYPHS; - this.names = site.names ?? []; + this.site = site; + this.notice = path.posix.join(site.licenses, MaterialSymbolsResources.noticeFile); + this.license = path.posix.join(site.licenses, MaterialSymbolsResources.licenseFile); } // What the command line asks for: with --check, the check, and otherwise the refresh. public async runAsync(args: readonly string[]): Promise { - await (args.includes(MaterialSymbols.CHECK_OPTION) ? this.checkAsync() : this.refreshAsync()); + await (args.includes(MaterialSymbolsResources.checkOption) ? this.checkAsync() : this.refreshAsync()); } public async refreshAsync(): Promise { const names = await this.iconNamesAsync(); const address = MaterialSymbols.sourceAddress(names); - const response = await fetch(address, { headers: { "User-Agent": MaterialSymbols.BROWSER }, signal: AbortSignal.timeout(MaterialSymbols.TIMEOUT) }); + const response = await fetch(address, { headers: { "User-Agent": MaterialSymbolsResources.browser }, signal: AbortSignal.timeout(MaterialSymbols.TIMEOUT) }); if (!response.ok) - throw new Error(`Font stylesheet download failed: ${response.status}`); + throw new MaterialSymbolsException(MaterialSymbolsResources.formatStylesheetDownloadFailed(response.status)); const match = MaterialSymbols.FONT_ADDRESS.exec(await response.text()); if (Object.isUndefined(match?.[1])) - throw new Error("Expected an official Google Fonts font URL."); + throw new MaterialSymbolsException(MaterialSymbolsResources.fontAddressMissing); const font = await fetch(match[1], { signal: AbortSignal.timeout(MaterialSymbols.TIMEOUT) }); if (!font.ok) - throw new Error(`Font download failed: ${font.status}`); + throw new MaterialSymbolsException(MaterialSymbolsResources.formatFontDownloadFailed(font.status)); const bytes = Buffer.from(await font.arrayBuffer()); - if (bytes.subarray(0, 4).toString() !== "wOF2") - throw new Error("Expected a WOFF2 font."); - await mkdir(this.at(this.fonts), { recursive: true }); + if (bytes.subarray(0, 4).toString() !== MaterialSymbolsResources.woff2Signature) + throw new MaterialSymbolsException(MaterialSymbolsResources.notWoff2); + const fonts = this.at(this.site.fonts); + await mkdir(fonts, { recursive: true }); const digest = MaterialSymbols.sha256(bytes); - const filename = `material-symbols-${digest.slice(0, 8)}.woff2`; - await writeFile(path.join(this.at(this.fonts), filename), bytes); - for (const entry of await readdir(this.at(this.fonts))) + const filename = MaterialSymbolsResources.formatFontName(digest); + await writeFile(path.join(fonts, filename), bytes); + for (const entry of await readdir(fonts)) if (MaterialSymbols.ANY_FONT_NAME.test(entry) && entry !== filename) - await rm(path.join(this.at(this.fonts), entry)); - const styles = await readFile(this.at(this.styles), MaterialSymbols.ENCODING); - await writeFile(this.at(this.styles), styles.replace(MaterialSymbols.STYLES_FONT, filename)); - const license = await fetch(MaterialSymbols.LICENSE_ADDRESS, { signal: AbortSignal.timeout(MaterialSymbols.TIMEOUT) }); + await rm(path.join(fonts, entry)); + const styles = await readFile(this.at(this.site.styles), MaterialSymbolsResources.encoding); + await writeFile(this.at(this.site.styles), styles.replace(MaterialSymbols.STYLES_FONT, filename)); + const license = await fetch(MaterialSymbolsResources.licenseAddress, { signal: AbortSignal.timeout(MaterialSymbols.TIMEOUT) }); if (!license.ok) - throw new Error("Material Symbols license download failed."); + throw new MaterialSymbolsException(MaterialSymbolsResources.licenseDownloadFailed); await mkdir(path.dirname(this.at(this.license)), { recursive: true }); await writeFile(this.at(this.license), `${(await license.text()).trimEnd()}\n`); const notice = await this.noticeTextAsync(); await writeFile(this.at(this.notice), this.noticeOf(notice, filename, digest, address)); - console.log(`Self-hosted ${names.size} Material Symbols in ${bytes.length} bytes, SHA-256 ${digest}.`); + console.log(MaterialSymbolsResources.formatSelfHosted(names.size, bytes.length, digest)); } public async checkAsync(): Promise { const problems: string[] = []; - const notice = await readFile(this.at(this.notice), MaterialSymbols.ENCODING); + const notice = await readFile(this.at(this.notice), MaterialSymbolsResources.encoding); const record = MaterialSymbols.RECORD.exec(notice); const source = MaterialSymbols.SOURCE.exec(notice); - const fonts = (await readdir(this.at(this.fonts))).filter(t => t.startsWith("material-symbols")).sort(); + const fonts = (await readdir(this.at(this.site.fonts))).filter(t => t.startsWith(MaterialSymbolsResources.fontFilePrefix)).sort(); if (Object.isUndefined(record?.[1]) || Object.isUndefined(record[2]) || Object.isUndefined(source?.[1])) - problems.push(`${this.notice} records no SHA-256 or source.`); + problems.push(MaterialSymbolsResources.formatNoRecord(this.notice)); else { const digest = record[1]; const filename = record[2]; if (fonts.length !== 1 || fonts[0] !== filename) - problems.push(`${this.fonts} holds ${fonts.join(", ") || "no font"}, not only the recorded ${filename}.`); - else if (MaterialSymbols.sha256(await readFile(path.join(this.at(this.fonts), filename))) !== digest) - problems.push(`${filename} does not match its recorded SHA-256.`); + problems.push(MaterialSymbolsResources.formatOtherFonts(this.site.fonts, fonts, filename)); + else if (MaterialSymbols.sha256(await readFile(path.join(this.at(this.site.fonts), filename))) !== digest) + problems.push(MaterialSymbolsResources.formatFontChanged(filename)); if (MaterialSymbols.FONT_NAME.exec(filename)?.[1] !== digest.slice(0, 8)) - problems.push(`${filename} is not named by its SHA-256.`); - if (!(await readFile(this.at(this.styles), MaterialSymbols.ENCODING)).includes(`${this.fontsAddress}${filename}`)) - problems.push(`${this.styles} does not load ${filename}.`); + problems.push(MaterialSymbolsResources.formatFontMisnamed(filename)); + if (!(await readFile(this.at(this.site.styles), MaterialSymbolsResources.encoding)).includes(`${this.site.fontsAddress}${filename}`)) + problems.push(MaterialSymbolsResources.formatStylesWithoutFont(this.site.styles, filename)); if (source[1] !== MaterialSymbols.sourceAddress(await this.iconNamesAsync())) - problems.push("The icons the site draws differ from the recorded subset; run npm run symbols."); + problems.push(MaterialSymbolsResources.subsetChanged); } - if (!(await readFile(this.at(this.license), MaterialSymbols.ENCODING).catch(() => "")).includes("Apache License")) - problems.push(`${this.license} does not hold the Apache 2.0 license.`); + if (!(await readFile(this.at(this.license), MaterialSymbolsResources.encoding).catch(() => "")).includes(MaterialSymbolsResources.licenseTitle)) + problems.push(MaterialSymbolsResources.formatLicenseMissing(this.license)); if (problems.length > 0) - throw new Error(problems.join("\n")); - console.log("The Material Symbols subset matches its recorded SHA-256, its notice and the icons the site draws."); + throw new MaterialSymbolsException(problems.join("\n")); + console.log(MaterialSymbolsResources.subsetSound); } // What is wrong with one built page: each glyph it draws that the recorded subset lacks, and each copy of the symbol font it loads // other than the recorded subset, given the glyphs drawnGlyphs read and the fonts loadedFonts read. public async findPageProblemsAsync(page: string, drawn: readonly string[], fonts: readonly string[]): Promise { - const notice = await readFile(this.at(this.notice), MaterialSymbols.ENCODING); + const notice = await readFile(this.at(this.notice), MaterialSymbolsResources.encoding); const record = MaterialSymbols.RECORD.exec(notice)?.[2]; const source = MaterialSymbols.SOURCE.exec(notice)?.[1]; if (Object.isUndefined(record) || Object.isUndefined(source)) - return [`${this.notice} records no subset, so ${page} can't be checked.`]; - const subset = new Set(new URL(source).searchParams.get("icon_names")?.split(",") ?? []); + return [MaterialSymbolsResources.formatPageUnchecked(this.notice, page)]; + const subset = new Set(new URL(source).searchParams.get(MaterialSymbolsResources.iconNamesParameter)?.split(",") ?? []); const missing = drawn.filter(t => !subset.has(t)); const others = fonts.filter(t => { const name = path.posix.basename(new URL(t).pathname); - return name.includes("material-symbols") && name !== record; + return name.includes(MaterialSymbolsResources.fontFilePrefix) && name !== record; }); return [ - ...missing.length === 0 ? [] : [`${page} draws ${missing.join(", ")}, which the subset ${record} lacks; run npm run symbols.`], - ...others.map(t => `${page} loads ${t}, a copy of the symbol font other than the subset ${record}.`) + ...missing.length === 0 ? [] : [MaterialSymbolsResources.formatPageDrawsMissing(page, missing, record)], + ...others.map(t => MaterialSymbolsResources.formatPageLoadsOther(page, t, record)) ]; } private async iconNamesAsync(): Promise> { const names = await this.kitIconNamesAsync(); - for (const name of this.names) + for (const name of this.site.names) names.add(name); - await this.collectAsync(this.at(this.code), names); + await this.collectAsync(this.at(this.site.code), names); return names; } @@ -186,13 +161,13 @@ export class MaterialSymbols { const filename = path.join(directory, entry.name); if (entry.isDirectory()) await this.collectAsync(filename, names); - else if (filename.endsWith(".html")) { - const text = await readFile(filename, MaterialSymbols.ENCODING); + else if (filename.endsWith(MaterialSymbolsResources.htmlExtension)) { + const text = await readFile(filename, MaterialSymbolsResources.encoding); for (const name of [...MaterialSymbols.groupsOf(text, MaterialSymbols.DRAWN_ICON), ...MaterialSymbols.groupsOf(text, MaterialSymbols.GIVEN_ICON)]) names.add(name); } - else if (filename.endsWith(".ts")) - for (const name of MaterialSymbols.groupsOf(await readFile(filename, MaterialSymbols.ENCODING), MaterialSymbols.KEPT_GLYPH)) + else if (filename.endsWith(MaterialSymbolsResources.codeExtension)) + for (const name of MaterialSymbols.groupsOf(await readFile(filename, MaterialSymbolsResources.encoding), MaterialSymbols.KEPT_GLYPH)) names.add(name); } } @@ -200,23 +175,24 @@ export class MaterialSymbols { // The glyphs the kit's parts the site's code imports can draw: the union of their lists in the kit's glyphs.json. A name the // site imports that is no part, such as a model or a type, has no list there. private async kitIconNamesAsync(): Promise> { - const parts = MaterialSymbols.field(await this.kitGlyphListAsync(), "parts"); + const kitGlyphs = this.site.kitGlyphs; + const parts = MaterialSymbols.field(await this.kitGlyphListAsync(), MaterialSymbolsResources.partsField); if (!Object.isObject(parts)) - throw new Error(`${this.kitGlyphs} lists no parts.`); + throw new MaterialSymbolsException(MaterialSymbolsResources.formatNoParts(kitGlyphs)); const lists = new Map(Object.entries(parts)); const imported = new Set(); - await this.collectKitImportsAsync(this.at(this.code), imported); + await this.collectKitImportsAsync(this.at(this.site.code), imported); const names = new Set(); for (const part of imported) { if (!lists.has(part)) continue; const list = lists.get(part); if (!Array.isArray(list)) - throw new Error(`${this.kitGlyphs} lists ${part}'s glyphs as something other than a list.`); + throw new MaterialSymbolsException(MaterialSymbolsResources.formatListNotList(kitGlyphs, part)); const glyphs: readonly unknown[] = list; for (const glyph of glyphs) { if (!Object.isString(glyph)) - throw new Error(`${this.kitGlyphs} lists ${part}'s glyphs as something other than names.`); + throw new MaterialSymbolsException(MaterialSymbolsResources.formatListNotNames(kitGlyphs, part)); names.add(glyph); } } @@ -227,16 +203,16 @@ export class MaterialSymbols { private async kitGlyphListAsync(): Promise { let text: string; try { - text = await readFile(this.at(this.kitGlyphs), MaterialSymbols.ENCODING); + text = await readFile(this.at(this.site.kitGlyphs), MaterialSymbolsResources.encoding); } catch (error) { - throw new Error(`${this.kitGlyphs} can't be read; the site needs ${MaterialSymbols.KIT_NAME} 0.0.37 or later.`, { cause: error }); + throw new MaterialSymbolsException(MaterialSymbolsResources.formatKitGlyphsUnread(this.site.kitGlyphs), new ExceptionOptions(error)); } try { return JSON.parse(text); } catch (error) { - throw new Error(`${this.kitGlyphs} isn't JSON.`, { cause: error }); + throw new MaterialSymbolsException(MaterialSymbolsResources.formatKitGlyphsNotJson(this.site.kitGlyphs), new ExceptionOptions(error)); } } @@ -245,37 +221,38 @@ export class MaterialSymbols { const filename = path.join(directory, entry.name); if (entry.isDirectory()) await this.collectKitImportsAsync(filename, imported); - else if (filename.endsWith(".ts")) - for (const list of MaterialSymbols.groupsOf(await readFile(filename, MaterialSymbols.ENCODING), MaterialSymbols.KIT_IMPORT)) + else if (filename.endsWith(MaterialSymbolsResources.codeExtension)) + for (const list of MaterialSymbols.groupsOf(await readFile(filename, MaterialSymbolsResources.encoding), MaterialSymbols.KIT_IMPORT)) for (const name of list.split(",")) imported.add(name.trim()); } } private at(relative: string): string { - return path.join(this.root, relative); + return path.join(this.site.root, relative); } // The notice as it stands, or none when there is no file yet; any other failure to read it stops the refresh, so a notice it // couldn't read is never written over. private async noticeTextAsync(): Promise { try { - return await readFile(this.at(this.notice), MaterialSymbols.ENCODING); + return await readFile(this.at(this.notice), MaterialSymbolsResources.encoding); } catch (error) { - if (error instanceof Error && "code" in error && error.code === MaterialSymbols.MISSING_FILE) + if (error instanceof Error && "code" in error && error.code === MaterialSymbolsResources.missingFile) return ""; throw error; } } - // The notice with the subset's record at its top, in place of the old one, and every other line in it kept, in its order. + // The notice with the subset's record at its top, in place of the old one, and every other line in it kept, in its order; it + // names the font by the address the site serves it at. private noticeOf(notice: string, filename: string, digest: string, address: string): string { const record = [ - `Material Symbols is from Google material-design-icons, under the Apache 2.0 license in ${MaterialSymbols.LICENSE}.`, - `The site serves a subset of it, ${path.posix.join(this.fonts, filename)}, holding only the icons it draws; refresh it with npm run symbols after adding an icon.`, - `SHA-256: ${digest} ${filename}`, - `Source: ${address}` + MaterialSymbolsResources.formatNoticeFrom(), + MaterialSymbolsResources.formatNoticeServes(`${this.site.fontsAddress}${filename}`), + MaterialSymbolsResources.formatNoticeDigest(digest, filename), + MaterialSymbolsResources.formatNoticeSource(address) ]; const others = notice.split(MaterialSymbols.LINES).filter(t => t !== "" && !MaterialSymbols.RECORD_LINE.test(t)); return [...record, ...others, ""].join("\n"); @@ -283,7 +260,7 @@ export class MaterialSymbols { // The first group of each match of a pattern in a text. private static groupsOf(text: string, pattern: RegExp): readonly string[] { - return [...text.matchAll(pattern)].flatMap(t => t[1] ?? []); + return [...text.matchAll(pattern)].map(t => t[1]).filter(t => Object.isString(t)); } // A JSON object's field, or undefined when the value isn't an object or has no such field. @@ -292,7 +269,7 @@ export class MaterialSymbols { } private static sourceAddress(names: ReadonlySet): string { - return `${MaterialSymbols.SOURCE_ADDRESS}${[...names].sort().join(",")}${MaterialSymbols.SOURCE_END}`; + return `${MaterialSymbolsResources.sourceAddress}${[...names].sort().join(",")}${MaterialSymbolsResources.sourceEnd}`; } private static sha256(bytes: Buffer): string { diff --git a/src/noldova.ui.components.angular/tests/node/kit-stylesheets.test.ts b/src/noldova.ui.components.angular/tests/node/kit-stylesheets.test.ts index a6fdef0d..7e72be32 100644 --- a/src/noldova.ui.components.angular/tests/node/kit-stylesheets.test.ts +++ b/src/noldova.ui.components.angular/tests/node/kit-stylesheets.test.ts @@ -8,38 +8,90 @@ import "@noldova/context.core"; import assert from "node:assert/strict"; +import { existsSync } from "node:fs"; import { readFile } from "node:fs/promises"; import path from "node:path"; import { describe, it } from "node:test"; const styles = path.join(import.meta.dirname, "../../src/styles"); +const symbolClass = ".material-symbols-rounded"; +const family = "\"Material Symbols Rounded\""; const importPattern = /^@import "([^"]+)";$/gmu; +const commentPattern = /\/\*[\s\S]*?\*\//gu; -// The stylesheets a stylesheet of the kit imports, in order, with those of the kit's own it imports in turn. -async function importsOfAsync(name: string): Promise { - const text = await readFile(path.join(styles, name), "utf8"); - const imports: string[] = []; - for (const target of [...text.matchAll(importPattern)].flatMap(t => t[1] ?? [])) { - imports.push(target); - if (target.startsWith("./")) - imports.push(...await importsOfAsync(target.slice(2))); +// A rule's prelude, such as a selector list or @font-face, and its declarations, at the top of a stylesheet. +class CssRule { + public readonly prelude: string; + public readonly declarations: ReadonlyMap; + + public constructor(prelude: string, body: string) { + this.prelude = prelude; + this.declarations = new Map(body.split(";").map(t => t.trim()).filter(t => t !== "").map(t => { + const colon = t.indexOf(":"); + return [t.slice(0, colon).trim(), t.slice(colon + 1).trim()]; + })); + } + + public static parse(text: string): readonly CssRule[] { + const rules: CssRule[] = []; + let start = 0; + for (let index = text.indexOf("{"); index !== -1; index = text.indexOf("{", start)) { + let depth = 1; + let end = index + 1; + for (; depth > 0 && end < text.length; end++) + depth += text[end] === "{" ? 1 : text[end] === "}" ? -1 : 0; + rules.push(new CssRule(text.slice(start, index).split(";").at(-1)?.trim() ?? "", text.slice(index + 1, end - 1))); + start = end; + } + return rules; } - return imports; +} + +// A stylesheet a stylesheet imports: one of the kit's own beside it, or a package's, from the nearest node_modules that holds it. +function resolveImport(from: string, target: string): string { + if (target.startsWith("./")) + return path.join(path.dirname(from), target); + for (let folder = path.dirname(from); ; folder = path.dirname(folder)) { + const file = path.join(folder, "node_modules", target); + if (existsSync(file)) + return file; + assert.notEqual(path.dirname(folder), folder, `${target} isn't installed.`); + } +} + +// Every top-level rule a stylesheet holds, after those of each stylesheet it imports, in the order a browser applies them. +async function rulesOfAsync(file: string): Promise { + const text = (await readFile(file, "utf8")).replaceAll(commentPattern, ""); + const imported: CssRule[] = []; + for (const target of [...text.matchAll(importPattern)].flatMap(t => t[1] ?? [])) + imported.push(...await rulesOfAsync(resolveImport(file, target))); + return [...imported, ...CssRule.parse(text)]; +} + +// The declarations the symbol class gets from a stylesheet's rules for that class alone, each from the last rule that sets it. +function symbolDeclarations(rules: readonly CssRule[]): ReadonlyMap { + return new Map(rules.filter(t => t.prelude === symbolClass).flatMap(t => [...t.declarations])); +} + +function symbolFaces(rules: readonly CssRule[]): readonly CssRule[] { + return rules.filter(t => t.prelude === "@font-face" && t.declarations.get("font-family") === family); } describe("The kit's stylesheets", () => { - it("load everything kit.css loads but the whole symbol font from kit-without-symbol-font.css, the symbol class's rules first", async () => { - const whole = await importsOfAsync("kit.css"); - const without = await importsOfAsync("kit-without-symbol-font.css"); + it("give the symbol class material-symbols' own declarations in symbols.css, in the same order, so it changes nothing after the package's rule", async () => { + const own = symbolDeclarations(await rulesOfAsync(resolveImport(path.join(styles, "kit.css"), "material-symbols/rounded.css"))); + assert.ok(own.size > 0); + + assert.deepEqual([...symbolDeclarations(await rulesOfAsync(path.join(styles, "symbols.css")))], [...own]); + }); - assert.deepEqual(whole, ["material-symbols/rounded.css", "./kit-without-symbol-font.css", ...without]); - assert.equal(without[0], "./symbols.css"); - assert.ok(!without.some(t => t.startsWith("material-symbols")), without.join(", ")); + it("give the symbol class the same declarations from kit.css and from kit-without-symbol-font.css", async () => { + assert.deepEqual([...symbolDeclarations(await rulesOfAsync(path.join(styles, "kit-without-symbol-font.css")))], + [...symbolDeclarations(await rulesOfAsync(path.join(styles, "kit.css")))]); }); - it("declare no font for the symbol class in kit-without-symbol-font.css, so a site's own subset is the only one", async () => { - const own = (await importsOfAsync("kit-without-symbol-font.css")).filter(t => t.startsWith("./")); - for (const name of ["kit-without-symbol-font.css", ...own.map(t => t.slice(2))]) - assert.doesNotMatch(await readFile(path.join(styles, name), "utf8"), /@font-face\s*\{[^}]*Material Symbols/u, name); + it("load the whole symbol font from kit.css only, so a site's own subset is the only font kit-without-symbol-font.css leaves", async () => { + assert.equal(symbolFaces(await rulesOfAsync(path.join(styles, "kit.css"))).length, 1); + assert.deepEqual(symbolFaces(await rulesOfAsync(path.join(styles, "kit-without-symbol-font.css"))), []); }); }); diff --git a/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts b/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts index 9baec16a..10a91802 100644 --- a/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts +++ b/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts @@ -14,8 +14,8 @@ import { tmpdir } from "node:os"; import path from "node:path"; import { afterEach, beforeEach, describe, it, mock } from "node:test"; -import type { IMaterialSymbolsSite } from "../../src/symbols/interfaces/i-material-symbols-site.ts"; -import { MaterialSymbols } from "../../src/symbols/material-symbols.ts"; +import { UiComponentsException } from "../../src/app/exceptions/ui-components.exception.ts"; +import { MaterialSymbols, MaterialSymbolsException, MaterialSymbolsSite } from "../../src/api/symbols.ts"; const font = Buffer.from("wOF2 a subset of two icons"); const digest = createHash("sha256").update(font).digest("hex"); @@ -25,6 +25,26 @@ const source = const changed = "The icons the site draws differ from the recorded subset; run npm run symbols."; const kitGlyphs = "node_modules/@noldova/ui.components.angular/glyphs.json"; +// A site that names icons its code builds, which no template or field shows. +class NamingSite extends MaterialSymbolsSite { + public override readonly names: readonly string[]; + + public constructor(root: string, names: readonly string[]) { + super(root); + this.names = names; + } +} + +// A site that keeps its code, stylesheet, font, notice and the kit's glyphs.json in folders of its own. +class OwnFoldersSite extends MaterialSymbolsSite { + public override readonly code: string = "site"; + public override readonly styles: string = "site/theme.css"; + public override readonly fonts: string = "web/fonts"; + public override readonly licenses: string = "web/notices"; + public override readonly fontsAddress: string = "/static/"; + public override readonly kitGlyphs: string = "kit/glyphs.json"; +} + // A site whose subset agrees with its record, its notice and its code; each test breaks one of them. class Site { public readonly root: string; @@ -74,16 +94,16 @@ class Site { await rm(path.join(this.root, relative)); } - public symbols(site: Omit = {}): MaterialSymbols { - return new MaterialSymbols({ root: this.root, ...site }); + public symbols(site: MaterialSymbolsSite = new MaterialSymbolsSite(this.root)): MaterialSymbols { + return new MaterialSymbols(site); } - public async refusalAsync(site: Omit = {}): Promise { + public async refusalAsync(site: MaterialSymbolsSite = new MaterialSymbolsSite(this.root)): Promise { try { await this.symbols(site).checkAsync(); } catch (error) { - if (error instanceof Error) + if (error instanceof MaterialSymbolsException) return error.message; throw error; } @@ -117,7 +137,7 @@ describe("MaterialSymbols.checkAsync", () => { it("checks, and changes nothing, when the command line asks with --check", async () => { await current().writeAsync("public/assets/licenses/README.txt", "Material Symbols\n"); - await assert.rejects(current().symbols().runAsync(["--check"]), { message: "public/assets/licenses/README.txt records no SHA-256 or source." }); + await assert.rejects(current().symbols().runAsync(["--check"]), { name: "MaterialSymbolsException", message: "public/assets/licenses/README.txt records no SHA-256 or source." }); assert.equal(await readFile(path.join(current().root, "public/assets/licenses/README.txt"), "utf8"), "Material Symbols\n"); }); @@ -136,6 +156,29 @@ describe("MaterialSymbols.checkAsync", () => { assert.equal(await current().refusalAsync(), changed); }); + it("reads a drawn icon whose name holds a digit", async () => { + await current().writeAsync("src/app/home/home.html", "looks_3\n"); + assert.equal(await current().refusalAsync(), changed); + }); + + it("reads a given icon whose name holds a digit", async () => { + await current().writeAsync("src/app/home/home.html", "\n"); + assert.equal(await current().refusalAsync(), changed); + }); + + it("reads a kept glyph whose name holds a digit", async () => { + await current().writeAsync("src/resources.ts", "public static readonly stepGlyph: IconName = \"counter_2\";\n"); + assert.equal(await current().refusalAsync(), changed); + }); + + it("fails as a MaterialSymbolsException, which is a UiComponentsException", async () => { + await current().writeAsync("public/assets/licenses/README.txt", "Material Symbols\n"); + const failure = await current().symbols().checkAsync().then(() => null, (error: unknown) => error); + assert.ok(failure instanceof MaterialSymbolsException); + assert.ok(failure instanceof UiComponentsException); + assert.equal(failure.name, "MaterialSymbolsException"); + }); + it("refuses a notice with no record", async () => { await current().writeAsync("public/assets/licenses/README.txt", "Material Symbols\n"); assert.equal(await current().refusalAsync(), "public/assets/licenses/README.txt records no SHA-256 or source."); @@ -204,8 +247,8 @@ describe("MaterialSymbols.checkAsync", () => { it("reads the icons the site names itself", async () => { await current().writeAsync("src/app/page.html", "

No icons.

\n"); - assert.equal(await current().refusalAsync({ names: ["arrow_forward"] }), ""); - assert.equal(await current().refusalAsync({ names: ["arrow_forward", "star"] }), changed); + assert.equal(await current().refusalAsync(new NamingSite(current().root, ["arrow_forward"])), ""); + assert.equal(await current().refusalAsync(new NamingSite(current().root, ["arrow_forward", "star"])), changed); }); it("reads the union of the glyphs.json lists of the kit's parts the site imports, the header's search included, and none of the parts it doesn't", async () => { @@ -234,37 +277,37 @@ describe("MaterialSymbols.checkAsync", () => { await rm(path.join(current().root, "public"), { recursive: true }); await rm(path.join(current().root, "node_modules"), { recursive: true }); - assert.equal(await current().refusalAsync({ code: "site", styles: "site/theme.css", fonts: "web/fonts", licenses: "web/notices", fontsAddress: "/static/", kitGlyphs: "kit/glyphs.json" }), ""); + assert.equal(await current().refusalAsync(new OwnFoldersSite(current().root)), ""); }); it("stops when the installed kit publishes no glyphs.json", async () => { await current().removeAsync(kitGlyphs); - await assert.rejects(current().symbols().checkAsync(), { message: `${kitGlyphs} can't be read; the site needs @noldova/ui.components.angular 0.0.37 or later.` }); + await assert.rejects(current().symbols().checkAsync(), { name: "MaterialSymbolsException", message: `${kitGlyphs} can't be read; the site needs @noldova/ui.components.angular 0.0.37 or later.` }); }); it("stops when the kit's glyphs.json lists no parts", async () => { await current().writeKitAsync("glyphs.json", "{}"); - await assert.rejects(current().symbols().checkAsync(), { message: `${kitGlyphs} lists no parts.` }); + await assert.rejects(current().symbols().checkAsync(), { name: "MaterialSymbolsException", message: `${kitGlyphs} lists no parts.` }); }); it("stops when the kit's glyphs.json is no object", async () => { await current().writeKitAsync("glyphs.json", "7"); - await assert.rejects(current().symbols().checkAsync(), { message: `${kitGlyphs} lists no parts.` }); + await assert.rejects(current().symbols().checkAsync(), { name: "MaterialSymbolsException", message: `${kitGlyphs} lists no parts.` }); }); it("stops when the kit's glyphs.json lists a part's glyphs as anything but names", async () => { await current().writeKitGlyphsAsync({ SiteHeaderComponent: ["close", 7] }); - await assert.rejects(current().symbols().checkAsync(), { message: `${kitGlyphs} lists SiteHeaderComponent's glyphs as something other than names.` }); + await assert.rejects(current().symbols().checkAsync(), { name: "MaterialSymbolsException", message: `${kitGlyphs} lists SiteHeaderComponent's glyphs as something other than names.` }); }); it("stops when the kit's glyphs.json lists a part's glyphs as anything but a list", async () => { await current().writeKitAsync("glyphs.json", JSON.stringify({ parts: { ButtonComponent: [], SiteHeaderComponent: "close" } })); - await assert.rejects(current().symbols().checkAsync(), { message: `${kitGlyphs} lists SiteHeaderComponent's glyphs as something other than a list.` }); + await assert.rejects(current().symbols().checkAsync(), { name: "MaterialSymbolsException", message: `${kitGlyphs} lists SiteHeaderComponent's glyphs as something other than a list.` }); }); it("stops when the kit's glyphs.json isn't JSON", async () => { await current().writeKitAsync("glyphs.json", "{ \"parts\": "); - await assert.rejects(current().symbols().checkAsync(), { message: `${kitGlyphs} isn't JSON.` }); + await assert.rejects(current().symbols().checkAsync(), { name: "MaterialSymbolsException", message: `${kitGlyphs} isn't JSON.` }); }); it("refuses a missing license", async () => { @@ -310,6 +353,12 @@ describe("MaterialSymbols.findPageProblemsAsync", () => { assert.deepEqual(await current().symbols().findPageProblemsAsync("/c", ["close"], []), ["public/assets/licenses/README.txt records no subset, so /c can't be checked."]); }); + + it("names every glyph a page draws when the recorded source names no icons", async () => { + await current().writeAsync("public/assets/licenses/README.txt", Site.notice(digest, filename, "https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded")); + assert.deepEqual(await current().symbols().findPageProblemsAsync("/d", ["close"], []), + [`/d draws close, which the subset ${filename} lacks; run npm run symbols.`]); + }); }); // A refresh whose download from one service fails: what goes wrong, the addresses it changes, the answer they get and the @@ -386,14 +435,14 @@ describe("MaterialSymbols.refreshAsync", () => { mock.method(globalThis, "fetch", (input: string | URL | Request) => Promise.resolve(answer(addressOf(input), failure))); const before = await readFile(path.join(current().root, notice), "utf8"); - await assert.rejects(current().symbols().refreshAsync(), { message: failure.message }); + await assert.rejects(current().symbols().refreshAsync(), { name: "MaterialSymbolsException", message: failure.message }); assert.equal(await readFile(path.join(current().root, notice), "utf8"), before); }); // The subset's record exactly as the refresh writes it, for a font and the address it came from. const record = (fontName: string, sha: string, address: string): string[] => [ "Material Symbols is from Google material-design-icons, under the Apache 2.0 license in MATERIAL-SYMBOLS-LICENSE.txt.", - `The site serves a subset of it, public/assets/fonts/${fontName}, holding only the icons it draws; refresh it with npm run symbols after adding an icon.`, + `The site serves a subset of it, /assets/fonts/${fontName}, holding only the icons it draws; refresh it with npm run symbols after adding an icon.`, `SHA-256: ${sha} ${fontName}`, `Source: ${address}` ]; diff --git a/src/noldova.ui.components.angular/tests/node/source-imports.ts b/src/noldova.ui.components.angular/tests/node/source-imports.ts new file mode 100644 index 00000000..eb1a65ad --- /dev/null +++ b/src/noldova.ui.components.angular/tests/node/source-imports.ts @@ -0,0 +1,27 @@ +/** + * @license + * Copyright (c) Noldova. + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + */ + +import "@noldova/context.core"; +import { existsSync } from "node:fs"; +import { registerHooks } from "node:module"; +import { fileURLToPath } from "node:url"; + +// The Node.js tests run the kit's source, whose relative imports name the .js file its build writes; this resolves each to the +// .ts source beside the importing file, where that exists, as the build's own module resolution does. +const builtExtension = /\.js$/u; + +registerHooks({ + resolve(specifier, context, nextResolve) { + if (specifier.startsWith(".") && builtExtension.test(specifier) && !Object.isUndefined(context.parentURL)) { + const source = new URL(specifier.replace(builtExtension, ".ts"), context.parentURL); + if (existsSync(fileURLToPath(source))) + return nextResolve(source.href, context); + } + return nextResolve(specifier, context); + } +}); From ad4226c51db7edf315ac79ffa95c27079a9124ab Mon Sep 17 00:00:00 2001 From: Rostislav Rotaru Date: Sat, 28 Nov 2026 19:56:07 -0800 Subject: [PATCH 6/9] WIP: docs site serves its own symbol subset Agent: DEV7 (developer) Agent-Model: Anthropic Opus 5.5, Medium --- documents/DOCS-SITE.md | 12 +++++-- documents/KIT.md | 4 +-- .../package.json | 8 ++--- .../scripts/docs/docs-symbols.ts | 20 +++++++++--- .../{tests/node => scripts}/source-imports.ts | 2 +- .../scripts/test.ts | 2 +- .../src/api/symbols.d.ts | 30 +++++++++++++++-- .../interfaces/i-material-symbols-site.ts | 2 ++ .../src/symbols/material-symbols-site.ts | 2 ++ .../src/symbols/material-symbols.ts | 12 ++++--- .../tests/node/material-symbols.test.ts | 32 +++++++++++++++++-- 11 files changed, 103 insertions(+), 23 deletions(-) rename src/noldova.ui.components.angular/{tests/node => scripts}/source-imports.ts (85%) diff --git a/documents/DOCS-SITE.md b/documents/DOCS-SITE.md index 75e871e7..e1bf77c6 100644 --- a/documents/DOCS-SITE.md +++ b/documents/DOCS-SITE.md @@ -1,6 +1,6 @@ # The docs site -**Scope:** The docs site's commands, its generated sources, the rules its pages keep, its theme and what it leaves to hosting. +**Scope:** The docs site's commands, its symbol font, its generated sources, the rules its pages keep, its theme and what it leaves to hosting. The docs site shows each component of `@noldova/ui.components.angular` with its description, live examples and their code, its states and its API. It is an Angular app in `src/noldova.ui.components.angular.docs`, built against the kit's source, never published as a package, and drawn only with the kit's own components, tokens, fonts and icons, apart from the GitHub and X marks its header shows. @@ -11,13 +11,21 @@ It is an Angular app in `src/noldova.ui.components.angular.docs`, built against |---|---| | `npm run docs:api -w src/noldova.ui.components.angular.docs` | Writes the API reference alone. | | `npm run docs:build -w src/noldova.ui.components.angular.docs` | Writes the generated sources, then prerenders every page into `_build/docs`. | -| `npm run docs:test -w src/noldova.ui.components.angular.docs` | Writes the generated sources, then runs the site's tests in Chromium, held to 100% coverage of `src/` without the files the README's coverage table names, and fails when a spec file reports no result or a function, statement or branch goes unreached. It then serves the site `npm run docs:build` wrote to `_build/docs/browser`, which must run first, opens each page the menu links in Chromium, and fails when a page or a favicon the page links isn't served, a favicon's type isn't an image, its one h1 isn't its menu title, a component page shows no example or an empty one, an example's code shows no highlighted token, a table, the docs' own or a Markdown one, breaks a word across lines or wraps a name, a key name or a type but before a `|`, at 1280 or 375px wide, or the browser logs an error, as a failed hydration does. | +| `npm run symbols -w src/noldova.ui.components.angular.docs` | Refreshes the site's subset of the symbol font, as the [kit's symbols tool](KIT.md) does for any site, then needs `npm run docs:build` again. | +| `npm run symbols:check -w src/noldova.ui.components.angular.docs` | Fails when the committed subset, its record, `src/styles.css` or the glyphs the site draws disagree. | +| `npm run docs:test -w src/noldova.ui.components.angular.docs` | Writes the generated sources, then runs the site's tests in Chromium, held to 100% coverage of `src/` without the files the README's coverage table names, and fails when a spec file reports no result or a function, statement or branch goes unreached. It then serves the site `npm run docs:build` wrote to `_build/docs/browser`, which must run first, opens each page the menu links in Chromium, and fails when a page or a favicon the page links isn't served, a favicon's type isn't an image, its one h1 isn't its menu title, a component page shows no example or an empty one, an example's code shows no highlighted token, a page draws a glyph the subset lacks or loads another copy of the symbol font, the icon chooser's page aside, a table, the docs' own or a Markdown one, breaks a word across lines or wraps a name, a key name or a type but before a `|`, at 1280 or 375px wide, or the browser logs an error, as a failed hydration does. | The site compiles the kit's source, through the docs package's `tsconfig.json` paths and the kit's stylesheets in its `angular.json`, not the kit that `npm run build:components` installs; still, each command needs `npm run build:components` first, which installs the root's packages and the browser the site's tests use, and checks only that the kit is installed at the root as the sign that it ran; the root's `npm run build:docs` runs only this package's `docs:build`, which fails with a line saying to run `npm run build:components` first when the kit isn't built, and the root's `npm run build` runs `npm run build:components` then `npm run build:docs`; the API reference is read from the kit's declarations, `src/noldova.ui.components.angular/src/api/*.d.ts`, and its source. The docs package's own `test`, which an unfiltered `npm test` runs after the kit's, builds and tests the site on Linux; on other platforms, in a filtered run, and with `NOLDOVA_SEPARATE_TEST=docs`, which the CI targets set, it leaves them out, and the CI run's "Separate test" job checks the site once, on Linux x64, with `npm run build` and `npm run test:docs`, as the [README](../README.md#checks) says. Its spec run prints each test as it ends, with its file and name, through Vitest's `verbose` reporter, so a long spec file, such as the component page's, shows its progress, and a run that stops making progress shows the last test that ended. The commands' scripts are in the package's `scripts/`, and its Angular workspace is its own `angular.json`. +## Symbol font + +The site loads the kit's `styles/kit-without-symbol-font.css` and its own subset of Material Symbols Rounded, `public/assets/fonts/material-symbols-.woff2`, with its notice and license in `public/assets/licenses`, rather than the whole font, as [KIT.md](KIT.md) says. +`scripts/docs/docs-symbols.ts` reads the site's `src/`, the kit's gallery source the site renders and the `glyphs.json` the kit's source gives, written to `_build/docs-symbols`, and leaves the icon chooser's list out: only its page shows it, and `src/styles.css` gives its glyphs the whole font from `node_modules/material-symbols` under a family of their own, which the build copies to `media/`. +The docs package's scripts load the kit's `scripts/source-imports.ts`, which resolves the kit source's `.js` imports to its `.ts` files. + ## Generated sources The folder `_build/docs-generated` is written by every docs command, emptied first so that a warm build writes what a clean one does, and is never edited by hand; nothing is written under the docs app's `src/`. diff --git a/documents/KIT.md b/documents/KIT.md index 0008f9d0..1bf4cc65 100644 --- a/documents/KIT.md +++ b/documents/KIT.md @@ -290,12 +290,12 @@ The icon chooser's and the gallery's lists hold every name of the set, since the A site gets its subset from the entry `@noldova/ui.components.angular/symbols`, a Node.js tool that loads in no browser: - Its `MaterialSymbols` takes where the site keeps its subset as a `MaterialSymbolsSite`, whose defaults a site overrides in a class of its own, and fails with a `MaterialSymbolsException`, a `UiComponentsException`. - It reads the union of the `glyphs.json` lists of the kit's parts the site's code imports, the icons its templates draw between the symbol class's span tags or give a part as `icon="…"`, the glyphs its code keeps in a field whose name ends in glyph, as an `IconName` or a string, and the names the site gives it for icons its code builds; a refresh, which the site runs as `npm run symbols`, downloads that subset from Google Fonts with its license, keeps it in the site's fonts folder named by its SHA-256, points the site's `@font-face` at it and records the address the site serves it at, its SHA-256 and its source in the site's license notice. + It reads the union of the `glyphs.json` lists of the kit's parts the site's code imports, the icons its templates draw between the symbol class's span tags or give a part as `icon="…"`, the glyphs its code keeps in a field whose name ends or starts in glyph, as an `IconName` or a string, the same icons and glyphs of the other folders of code its pages show, its `moreCode`, and the names the site gives it for icons its code builds; a refresh, which the site runs as `npm run symbols`, downloads that subset from Google Fonts with its license, keeps it in the site's fonts folder named by its SHA-256, points the site's `@font-face` at it and records the address the site serves it at, its SHA-256 and its source in the site's license notice. - Its check, `npm run symbols -- --check` in the site's checks, fails when the committed font, its record, its stylesheet or the glyphs the site draws disagree. - Its `drawnGlyphs` and `loadedFonts` page expressions and `findPageProblemsAsync` let the site's check of its built pages fail on a page that draws a glyph the subset lacks, or that loads another copy of the font, such as the whole font `kit.css` brings. Such a site loads `styles/kit-without-symbol-font.css` in place of `styles/kit.css`: everything `kit.css` loads but the whole font, with the symbol class's rule from material-symbols' own `rounded.css`, every declaration but the font, in `styles/symbols.css`, first, so the class gets the same declarations from either; it declares the subset's `@font-face` for the family `Material Symbols Rounded` itself. -The icon chooser draws any glyph of the set in that class, so a site that shows it keeps `styles/kit.css` and the whole font. +The icon chooser draws any glyph of the set in that class, so a site that shows it keeps `styles/kit.css` and the whole font, or shows it only on a page that loads the whole font under a family of its own for the chooser's glyphs and names the chooser in its `wholeFontParts`, which the subset then leaves out, as the kit's docs site does. ## Controls diff --git a/src/noldova.ui.components.angular.docs/package.json b/src/noldova.ui.components.angular.docs/package.json index 7b0125ab..17b41b62 100644 --- a/src/noldova.ui.components.angular.docs/package.json +++ b/src/noldova.ui.components.angular.docs/package.json @@ -6,11 +6,11 @@ "scripts": { "docs:api": "node scripts/generate-api.ts", "docs:build": "node scripts/build-docs.ts", - "docs:test": "node scripts/test-docs.ts", - "test": "node scripts/test-docs.ts --suite", + "docs:test": "node --import ../noldova.ui.components.angular/scripts/source-imports.ts scripts/test-docs.ts", + "test": "node --import ../noldova.ui.components.angular/scripts/source-imports.ts scripts/test-docs.ts --suite", "test:timing": "node scripts/test-docs-timing.ts", - "symbols": "node scripts/prepare-symbols.ts", - "symbols:check": "node scripts/prepare-symbols.ts --check" + "symbols": "node --import ../noldova.ui.components.angular/scripts/source-imports.ts scripts/prepare-symbols.ts", + "symbols:check": "node --import ../noldova.ui.components.angular/scripts/source-imports.ts scripts/prepare-symbols.ts --check" }, "dependencies": { "@angular/common": "22.3.0", diff --git a/src/noldova.ui.components.angular.docs/scripts/docs/docs-symbols.ts b/src/noldova.ui.components.angular.docs/scripts/docs/docs-symbols.ts index cf449573..c60f9a7b 100644 --- a/src/noldova.ui.components.angular.docs/scripts/docs/docs-symbols.ts +++ b/src/noldova.ui.components.angular.docs/scripts/docs/docs-symbols.ts @@ -11,22 +11,34 @@ import path from "node:path"; import { KitGlyphs } from "../../../noldova.ui.components.angular/scripts/glyphs/kit-glyphs.ts"; import { PartGlyphs } from "../../../noldova.ui.components.angular/scripts/glyphs/part-glyphs.ts"; +import { MaterialSymbolsSite } from "../../../noldova.ui.components.angular/src/symbols/material-symbols-site.ts"; import { MaterialSymbols } from "../../../noldova.ui.components.angular/src/symbols/material-symbols.ts"; -// The docs site's subset of the symbol font, from the glyphs of the kit's source as its build writes them to glyphs.json. The icon -// chooser can draw any glyph, so its page loads the whole font under a family of its own and the subset leaves its list out. +// The docs site, which reads the kit's glyphs from its source rather than an installed kit, shows the kit's gallery parts from the +// kit's source too, and shows the icon chooser only on its own page, which loads the whole font under a family of its own. +class DocsSymbolsSite extends MaterialSymbolsSite { + public override readonly moreCode: readonly string[] = ["../noldova.ui.components.angular/src/app/components/gallery"]; + public override readonly kitGlyphs: string; + public override readonly wholeFontParts: readonly string[] = ["IconChooserComponent"]; + + public constructor(root: string, kitGlyphs: string) { + super(root); + this.kitGlyphs = kitGlyphs; + } +} + +// The docs site's subset of the symbol font, from the glyphs of the kit's source as its build writes them to glyphs.json. export class DocsSymbols { public static readonly wholeFontPage: string = "/components/icon-chooser"; public static readonly wholeFontFile: RegExp = /\/material-symbols-rounded[^/]*\.woff2$/u; private static readonly SITE_FOLDER: string = "src/noldova.ui.components.angular.docs"; private static readonly GLYPHS_FILE: string = "_build/docs-symbols/glyphs.json"; - private static readonly WHOLE_FONT_PARTS: readonly string[] = ["IconChooserComponent"]; public static async createAsync(root: string): Promise { const glyphs = path.join(root, DocsSymbols.GLYPHS_FILE); await mkdir(path.dirname(glyphs), { recursive: true }); await writeFile(glyphs, PartGlyphs.render((await KitGlyphs.readAsync(root)).parts)); const site = path.join(root, DocsSymbols.SITE_FOLDER); - return new MaterialSymbols({ root: site, kitGlyphs: path.relative(site, glyphs).split(path.sep).join(path.posix.sep), wholeFontParts: DocsSymbols.WHOLE_FONT_PARTS }); + return new MaterialSymbols(new DocsSymbolsSite(site, path.relative(site, glyphs).split(path.sep).join(path.posix.sep))); } } diff --git a/src/noldova.ui.components.angular/tests/node/source-imports.ts b/src/noldova.ui.components.angular/scripts/source-imports.ts similarity index 85% rename from src/noldova.ui.components.angular/tests/node/source-imports.ts rename to src/noldova.ui.components.angular/scripts/source-imports.ts index eb1a65ad..7ca6ddbc 100644 --- a/src/noldova.ui.components.angular/tests/node/source-imports.ts +++ b/src/noldova.ui.components.angular/scripts/source-imports.ts @@ -11,7 +11,7 @@ import { existsSync } from "node:fs"; import { registerHooks } from "node:module"; import { fileURLToPath } from "node:url"; -// The Node.js tests run the kit's source, whose relative imports name the .js file its build writes; this resolves each to the +// The Node.js tests and the docs site's scripts run the kit's source, whose relative imports name the .js file its build writes; this resolves each to the // .ts source beside the importing file, where that exists, as the build's own module resolution does. const builtExtension = /\.js$/u; diff --git a/src/noldova.ui.components.angular/scripts/test.ts b/src/noldova.ui.components.angular/scripts/test.ts index d5dff1f4..4c47252f 100644 --- a/src/noldova.ui.components.angular/scripts/test.ts +++ b/src/noldova.ui.components.angular/scripts/test.ts @@ -40,7 +40,7 @@ export class Test extends Script { private static readonly NODE_TESTS_TITLE: string = "The Node.js tests"; private static readonly NODE_TESTS_FOLDER: string = "tests/node"; private static readonly NODE_TEST_FILE: string = ".test.ts"; - private static readonly NODE_TEST_OPTIONS: readonly string[] = ["--import", "./tests/node/source-imports.ts", "--test"]; + private static readonly NODE_TEST_OPTIONS: readonly string[] = ["--import", "./scripts/source-imports.ts", "--test"]; // The Node.js code's own coverage gate, which a whole run and a shard's first part keep: every line, branch and function of the // Node.js entry's code, which no Angular spec loads. private static readonly NODE_COVERAGE_OPTIONS: readonly string[] = [ diff --git a/src/noldova.ui.components.angular/src/api/symbols.d.ts b/src/noldova.ui.components.angular/src/api/symbols.d.ts index 627e724e..37ef6e00 100644 --- a/src/noldova.ui.components.angular/src/api/symbols.d.ts +++ b/src/noldova.ui.components.angular/src/api/symbols.d.ts @@ -28,6 +28,14 @@ export interface IMaterialSymbolsSite { */ readonly code: string; + /** + * Other folders of code the site's pages show, such as the kit's own + * source a documentation site renders, read as `code` is for the icons + * their templates draw or give and the glyphs their code keeps, but not for + * the kit's parts they import. + */ + readonly moreCode: readonly string[]; + /** * The stylesheet whose `@font-face` loads the subset, which a refresh * points at the new font. @@ -61,6 +69,14 @@ export interface IMaterialSymbolsSite { * reading finds them, such as an icon its code builds or reads from data. */ readonly names: readonly string[]; + + /** + * The kit's parts, by class name, that the site shows only on pages that + * load the whole font under a family of their own, such as + * `IconChooserComponent`, whose list holds every glyph of the set: the + * subset leaves their `glyphs.json` lists out. + */ + readonly wholeFontParts: readonly string[]; } /** @@ -88,6 +104,11 @@ export declare class MaterialSymbolsSite implements IMaterialSymbolsSite { */ public readonly code: string; + /** + * No other folders of code. + */ + public readonly moreCode: readonly string[]; + /** * The stylesheet whose `@font-face` loads the subset, `src/styles.css`. */ @@ -120,6 +141,11 @@ export declare class MaterialSymbolsSite implements IMaterialSymbolsSite { */ public readonly names: readonly string[]; + /** + * No parts left to the whole font. + */ + public readonly wholeFontParts: readonly string[]; + /** * @param root The site's own folder. */ @@ -161,8 +187,8 @@ export declare class MaterialSymbolsException extends UiComponentsException { * * The subset holds the union of the `glyphs.json` lists of the kit's parts the * site's code imports, with the icons its templates draw or give a part's - * `icon`, the glyphs its code keeps in a field whose name ends in glyph, and - * the site's own `names`. A refresh asks Google Fonts for that subset, keeps + * `icon`, the glyphs its code keeps in a field whose name ends or starts in + * glyph, and the site's own `names`. A refresh asks Google Fonts for that subset, keeps * it in the fonts folder named by its SHA-256, points the stylesheet at it * and records its served address, SHA-256 and source address in the license * notice; the check reads it all again and fails where any of it disagrees, diff --git a/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts b/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts index 497c559e..685bc026 100644 --- a/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts +++ b/src/noldova.ui.components.angular/src/symbols/interfaces/i-material-symbols-site.ts @@ -10,10 +10,12 @@ export interface IMaterialSymbolsSite { readonly root: string; readonly code: string; + readonly moreCode: readonly string[]; readonly styles: string; readonly fonts: string; readonly licenses: string; readonly fontsAddress: string; readonly kitGlyphs: string; readonly names: readonly string[]; + readonly wholeFontParts: readonly string[]; } diff --git a/src/noldova.ui.components.angular/src/symbols/material-symbols-site.ts b/src/noldova.ui.components.angular/src/symbols/material-symbols-site.ts index 43edf252..c59ebc0c 100644 --- a/src/noldova.ui.components.angular/src/symbols/material-symbols-site.ts +++ b/src/noldova.ui.components.angular/src/symbols/material-symbols-site.ts @@ -13,12 +13,14 @@ import { MaterialSymbolsSiteResources } from "./material-symbols-site.resources. export class MaterialSymbolsSite implements IMaterialSymbolsSite { public readonly root: string; public readonly code: string = MaterialSymbolsSiteResources.code; + public readonly moreCode: readonly string[] = []; public readonly styles: string = MaterialSymbolsSiteResources.styles; public readonly fonts: string = MaterialSymbolsSiteResources.fonts; public readonly licenses: string = MaterialSymbolsSiteResources.licenses; public readonly fontsAddress: string = MaterialSymbolsSiteResources.fontsAddress; public readonly kitGlyphs: string = MaterialSymbolsSiteResources.kitGlyphs; public readonly names: readonly string[] = []; + public readonly wholeFontParts: readonly string[] = []; public constructor(root: string) { this.root = root; diff --git a/src/noldova.ui.components.angular/src/symbols/material-symbols.ts b/src/noldova.ui.components.angular/src/symbols/material-symbols.ts index 7ff69319..a9e8bf03 100644 --- a/src/noldova.ui.components.angular/src/symbols/material-symbols.ts +++ b/src/noldova.ui.components.angular/src/symbols/material-symbols.ts @@ -34,8 +34,8 @@ export class MaterialSymbols { private static readonly DRAWN_ICON: RegExp = /]*material-symbols-rounded[^>]*>\s*([a-z0-9_]+)\s*<\/span\s*>/gu; // An icon a template hands a part by its name, as its icon attribute. private static readonly GIVEN_ICON: RegExp = /\sicon="([a-z0-9_]+)"/gu; - // A glyph the site's code keeps by its name, in a field or constant whose name ends in glyph or Glyph. - private static readonly KEPT_GLYPH: RegExp = /[gG]lyph(?:: (?:IconName|string) =|:) "([a-z0-9_]+)"/gu; + // A glyph the site's code keeps by its name, in a field or constant whose name ends in glyph or Glyph, or starts with glyph. + private static readonly KEPT_GLYPH: RegExp = /(?:[gG]lyph|\bglyph[A-Z]\w*)(?:: (?:IconName|string) =|:) "([a-z0-9_]+)"/gu; // The names the site's code imports from any of the kit's entry points. private static readonly KIT_IMPORT: RegExp = /import (?:type )?\{([^}]+)\} from "@noldova\/ui\.components\.angular(?:\/[a-z-]+)*";/gu; private static readonly FONT_NAME: RegExp = /^material-symbols-([a-f0-9]{8})\.woff2$/u; @@ -151,7 +151,8 @@ export class MaterialSymbols { const names = await this.kitIconNamesAsync(); for (const name of this.site.names) names.add(name); - await this.collectAsync(this.at(this.site.code), names); + for (const folder of [this.site.code, ...this.site.moreCode]) + await this.collectAsync(this.at(folder), names); return names; } @@ -173,7 +174,8 @@ export class MaterialSymbols { } // The glyphs the kit's parts the site's code imports can draw: the union of their lists in the kit's glyphs.json. A name the - // site imports that is no part, such as a model or a type, has no list there. + // site imports that is no part, such as a model or a type, has no list there, and a part the site shows only in the whole font + // adds nothing. private async kitIconNamesAsync(): Promise> { const kitGlyphs = this.site.kitGlyphs; const parts = MaterialSymbols.field(await this.kitGlyphListAsync(), MaterialSymbolsResources.partsField); @@ -184,7 +186,7 @@ export class MaterialSymbols { await this.collectKitImportsAsync(this.at(this.site.code), imported); const names = new Set(); for (const part of imported) { - if (!lists.has(part)) + if (!lists.has(part) || this.site.wholeFontParts.includes(part)) continue; const list = lists.get(part); if (!Array.isArray(list)) diff --git a/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts b/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts index 98683f22..9610e8e6 100644 --- a/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts +++ b/src/noldova.ui.components.angular/tests/node/material-symbols.test.ts @@ -35,6 +35,21 @@ class NamingSite extends MaterialSymbolsSite { } } +// A site that shows some of the kit's parts only on pages that load the whole font. +class WholeFontSite extends MaterialSymbolsSite { + public override readonly wholeFontParts: readonly string[]; + + public constructor(root: string, wholeFontParts: readonly string[]) { + super(root); + this.wholeFontParts = wholeFontParts; + } +} + +// A site whose pages also show code from a folder outside its own. +class MoreCodeSite extends MaterialSymbolsSite { + public override readonly moreCode: readonly string[] = ["shared"]; +} + // A site that keeps its code, stylesheet, font, notice and the kit's glyphs.json in folders of its own. class OwnFoldersSite extends MaterialSymbolsSite { public override readonly code: string = "site"; @@ -225,6 +240,19 @@ describe("MaterialSymbols.checkAsync", () => { assert.equal(await current().refusalAsync(), changed); }); + it("reads a glyph the site's code keeps in a field whose name starts with glyph", async () => { + await current().writeAsync("src/resources.ts", "export const parts = { glyphShield: \"shield\" };\n"); + assert.equal(await current().refusalAsync(), changed); + }); + + it("reads the icons and glyphs of the other folders of code the site shows, and none of their kit imports", async () => { + await current().writeAsync("shared/canvas.ts", "import { SiteCanvasComponent } from \"@noldova/ui.components.angular/site\";\n"); + assert.equal(await current().refusalAsync(new MoreCodeSite(current().root)), ""); + await current().writeAsync("shared/card.html", "\n"); + assert.equal(await current().refusalAsync(new MoreCodeSite(current().root)), changed); + assert.equal(await current().refusalAsync(), ""); + }); + it("reads a glyph the site's code keeps as a string by name", async () => { await current().writeAsync("src/resources.ts", "public static readonly menuGlyph: string = \"toc\";\n"); assert.equal(await current().refusalAsync(), changed); @@ -267,8 +295,8 @@ describe("MaterialSymbols.checkAsync", () => { it("leaves out the lists of the kit parts the site shows only in the whole font, and only theirs", async () => { await current().writeAsync("src/app/canvas.ts", "import { SiteCanvasComponent } from \"@noldova/ui.components.angular/site\";\n"); - assert.equal(await current().refusalAsync({ wholeFontParts: ["SiteCanvasComponent"] }), ""); - assert.equal(await current().refusalAsync({ wholeFontParts: ["SiteCanvasComponent", "SiteHeaderComponent"] }), changed); + assert.equal(await current().refusalAsync(new WholeFontSite(current().root, ["SiteCanvasComponent"])), ""); + assert.equal(await current().refusalAsync(new WholeFontSite(current().root, ["SiteCanvasComponent", "SiteHeaderComponent"])), changed); }); it("reads the site's own folders, stylesheet, font address and glyphs.json", async () => { From d59d605beacb65344abb224a01ecb3f23e495837 Mon Sep 17 00:00:00 2001 From: Rostislav Rotaru Date: Sat, 28 Nov 2026 19:56:33 -0800 Subject: [PATCH 7/9] Keep the source-imports hook only in scripts after the merge Agent: DEV7 (developer) Agent-Model: Anthropic Opus 5.5, Medium --- .../tests/node/source-imports.ts | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100644 src/noldova.ui.components.angular/tests/node/source-imports.ts diff --git a/src/noldova.ui.components.angular/tests/node/source-imports.ts b/src/noldova.ui.components.angular/tests/node/source-imports.ts deleted file mode 100644 index eb1a65ad..00000000 --- a/src/noldova.ui.components.angular/tests/node/source-imports.ts +++ /dev/null @@ -1,27 +0,0 @@ -/** - * @license - * Copyright (c) Noldova. - * - * This source code is licensed under the license found in the - * LICENSE file in the root directory of this source tree. - */ - -import "@noldova/context.core"; -import { existsSync } from "node:fs"; -import { registerHooks } from "node:module"; -import { fileURLToPath } from "node:url"; - -// The Node.js tests run the kit's source, whose relative imports name the .js file its build writes; this resolves each to the -// .ts source beside the importing file, where that exists, as the build's own module resolution does. -const builtExtension = /\.js$/u; - -registerHooks({ - resolve(specifier, context, nextResolve) { - if (specifier.startsWith(".") && builtExtension.test(specifier) && !Object.isUndefined(context.parentURL)) { - const source = new URL(specifier.replace(builtExtension, ".ts"), context.parentURL); - if (existsSync(fileURLToPath(source))) - return nextResolve(source.href, context); - } - return nextResolve(specifier, context); - } -}); From 0fea474bc761272caf8dff13359236a39f990b39 Mon Sep 17 00:00:00 2001 From: Rostislav Rotaru Date: Sun, 29 Nov 2026 13:08:40 -0800 Subject: [PATCH 8/9] Serve the docs site its own subset of the symbol font The docs site loads kit-without-symbol-font.css and a subset of the glyphs its pages draw, with the icon chooser's page alone loading the whole font under a family of its own. The kit's tool reads more code folders, leaves out parts shown only in the whole font, and reads glyphX fields; the docs site's check fails on a page that draws a glyph the subset lacks. Agent: DEV7 (developer) Agent-Model: Anthropic Opus 5.5, Medium --- .../fonts/material-symbols-a10fbdab.woff2 | Bin 0 -> 8844 bytes .../licenses/MATERIAL-SYMBOLS-LICENSE.txt | 202 ++++++++++++++++++ .../public/assets/licenses/README.txt | 4 + .../scripts/docs/docs-symbols.ts | 5 +- .../src/styles.css | 2 +- 5 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 src/noldova.ui.components.angular.docs/public/assets/fonts/material-symbols-a10fbdab.woff2 create mode 100644 src/noldova.ui.components.angular.docs/public/assets/licenses/MATERIAL-SYMBOLS-LICENSE.txt create mode 100644 src/noldova.ui.components.angular.docs/public/assets/licenses/README.txt diff --git a/src/noldova.ui.components.angular.docs/public/assets/fonts/material-symbols-a10fbdab.woff2 b/src/noldova.ui.components.angular.docs/public/assets/fonts/material-symbols-a10fbdab.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..3e11311aeac3b375650b357e7f2a61dd25e9c576 GIT binary patch literal 8844 zcmV;7B6Hn$Pew8T0RR9103wV44gdfE08G3903t8|0RR9100000000000000000000 z0000SmmCIQKT}jeRB!-?8W9Kz?hxDw3xP}k0X7081A$BgAO(bS2Otaw8}&g|Bqyys z6j4p;Ayd^VA?^-)Rs8znuYdmgBV?Ex9{%U-yDw0nLFy1tsO2O-O^33;AW{Fb3e~bi z_0I~0LZJpSC=Z*O8>l$@B@l@>#}faS)2hB@Cr+tkD~Z5?CUOtsjYz6W$IVK|!;4h) z_Ey@x3G8-;?T(=llVOnTrPJVX>D}jl(9Qn~0xAJXx}clTMfVaM`)i^!;+h241naTI z4vHJQR_IvJu~E})d+^nNv^@v)ZT^~sKi^oxzjOA+1(RG6+tziMRJ0E)8sg$bggAdNlbM1^AzlR%n2rszbCovRR{NNF7C5JTrW#oaEXdYf*~ z7Dc<&7HzpNG4*75cAw|dWL2SrU`80#x$lph_I(=M?QX4cHCF795E0e;!|Oo+F$S1J zIyf?lr0%?U@NQBl?1-k2bN`*U-9qG+9XC@514``G$XCigq@I1nAc9c7ph5Xqd0zfm zepN2Z-O^vuchU{%9Vrk$i=V`kqRcnkNs$R8nh7Bj#=)UXKpq=~2o4T|=TOCmoobpW z9vUve;fHH+fse`_Gj!8Pf*E8S40cecVq?)n1PhNc;F%gFjzc6z)zIUaRb0}YQ5{h# zP3-3z<9Y7ok|HN;vA`H61e5}T%IARerar!#r6Q6RQx+L8uR@OKW2&Iyd1Dog6-H<$ z!6DkgJt{cZB>Sr9Lw+8Eb;2kdJ{sr*oorDddZQA%#3-S0NyqSlayZw3>iMGL#e@mS zvcUv>v{K6|vNm!;noX;$4VzfBliaz2M%G;;nxsHUXP`oq#x62_G!mf$wE{MTs*oF$lt&*` z6srmbYsi={(@i}QF}YA~1XYt^k6EG#H^5e=v5LV8L$s2hzD#Lkd<08y-N~{YRBdci z!a>7igQ(i!qEHl8fC6}MgS#cu9M2z40khgf0 zG%_3X5#g9b(-A&jZu0&+WXO;v*_MR1z;+YFoevI49}H=2pQ=`ZdwHJx7NYgJha{UK z0HJO)pv}zjxlHqxab`eFZt1YNOl1&U=;~MgeyddOulTbi3bt=`v zSz5PhC9a;dxbVz%i*%7lk=q8~x#l5WHN8fECHmmRlIAE0=2)iu?CPiVuj2m&KZ>=Vxy44$rejYmQV2Q3!cK6he?I z;*aekF+_-CYTR4kn9FiZt-A}{x@iYB$%?Yb!0>cFA}$k%+M&Hjoz#H4M7qbW1 z!|fyXY1?w@J6)Z8r;rBG5K8DkI)aX+^XOu_oUW%E>1Miv9-t@bS$ct9qTlEb>bP)= zxMkhO?i5#bQ-6j3di#6D|0zkulBy)NO`4pvENNBJ#-z6?mC`3>T_`LBpr9vut57Sc z)zpS67wvIZ)2_ZJ|NoSJ8`PmUu-Fci&4Tnp}EjmXe5jl$_XU^f$$Ca zBD})=;0A9M-CWDB8=JwJ>{E6>+l`&g#xZ}G2TUWT0prP3V9Enz4?y;lS!6ZYKo*ku zWI5SMhLH}W8Cgb#k~RSGCJC``W3R>DkF6csE;cfzU-ZK8ML@Vu*yXSnVN=64hwTj; z6B-rx%C8MPV8-G{zS3?aZ#_z0yS>mCa8kUji>$%A@;4Q0Gs>TpEoVULh_v}~{NWD{ zELixV3L+q*EEtF=f?6noDkzNvBq9(c@k5)Dj#i`92+;U7z6a$4f**cBMG)F|+48{| za4SMaaFM+X&);9X9Lk}L_th{`mPjjez@Ag~l#~Ko>KewGt_f z77C+<0wKgI7=_g}&uO%z`-oe zJWMq@z1kWXx#k+%&WCl^Wpi?q+1#}CILBH!HkQwq8inr6{51rtBi&V?vIg0Efr_H* z`W3`}sEo^bvzX5pi)L}8{7sFJX?;@PS|}8Uv--%$W{e5mNXTS9J7ht9utp)P=CfDj zO>E`!1ZUOZ;?Um8?31~f8EqCS#FI;q1KAZlRfUVK{SJaB;%y9Bei7$LRtV7g@BdW~ z6w#G!l;Iu!-kyi72A@Jz_QgQ;Q^b?aZpe*5TC|-|e<1o;COmx_W5kAb^bldh+p-I8 z9q-xn^Wu~py5hS(;u6a6iQzgh8EAK;5fkus2|u z->_&T4d>Jw)H`wz#K2ESkQL}_^}k*Qu_P}derZ+(+N_4Q7h~Sn%YVBJ^;5lde++q9V7U~L$@7aZMNX&WW&b^FLBo|tu8hY)Yg26Qk8l9YCI zfl&gE=I;!_B<3Yfo|WC_fL<9|(Uw=WjjlaF^A;^BJ$iVlu@8j(w^ zkSM){nphlR&s5}6PaA6YH~EcQFS+XQLKCeTrl zMw~(XZ(%d0*JB_kKHBJo6fEf@w%}~OG@RUAWfIj+YVSC}oK#Fy&U032PYx=r1s@T1 z$i1@Sh3R$###_Rg5uBWi1={#|WApVdizU2!4i*sGm+EpXYukK^p>n8Fex;xstnG6I zb8*zoxjn2SUh5=`5=}k0100o=%ML5U?NI4xumxlb*3HZN8Qzy}c;0fVRjQ)7NH_My zo^Mv?yk<4E7?LbS>CR!KBZ&zS&SaXw*VaSpb0WVSs`@8D9LE?`{|Jcl82_m55O&_1 zH^S*RgkGH2L-gs)L0Axa2_~{1tk1$&BA*z+)_d(bbn115dzjTp$CZ7MydR8(k`pws zJnXsIUoCSxmtXp;kvbuE@-LA35$$t%kP{7?^}8`Hi(6qGWn1M<$%ra6<1)pWV~Vo} zGVl~+fT`8T=9~ieH|%Olwm0K}CWVxP zj}E^h{k}7P4B{||FI83I?)Bu{Hd{B^N9V(-4>#GFY`!sTp1hrX5HC(85;{M~|H~?N z(ib1KJlRXf;i8rNZpL2A+y8=rr|yVeq#N^gX33o1cLx>KKV{w?E*OEFjb60xGfvY*s9KnwT>M8Th0^+R({Sm!lk zcMxFNWdMlLij<;@H^1-?e1IHTiT2y<$Y9H(Gm3#DgUemRiO+}*bx>Y0IS(96%8x0( zCpfvs{}RL(Sbm21=k72|zf@YTy`bh>o?M!w(E;n8<_D8>|EpUcjvBd{{ZRLnDc1OK z!@cpM%^EKsz=RvN%=;JLpK$9hZGIr+h;!q?&dVjI_TI+(f~MirmcO4KTl{dV%V^vH zvEO3U>3*=0VyF4uX6m>>4e`3^xUBR32DaoTRxi<;__g50XP4j8dCqPSZ*Kaq9yRy2 zUY87zoB090`S%1h^nIVyX|*`hcQDa0t~JVUnY9IkRD0i>TYImWbW112liOGY`-Mq9 zLFw1Pa~k~cSk_>7Fx17e9(HiQ0@d&#vsiamSy zg5S)JHd~@Mj^vo*i21&aKx8XuaUfxNvex3x_bakao|E%jo+UGjwOR(2rc)=bAqdj- za@jUu@ru89j{<&mh{8nIgoAR(?Q8UDE08jAxlyl|QHXHD&TN8rmws`Pl%u63yw4Ja zqvs$czBoDAWYYW4KW1ubA>#FVy;$POnVOFXF$e?MF>Y1iS7GbKxwelao`fgmzeI#D z3ql0qpfEndlL{p~3?u?6lw}?d0gJ}+_IN=E-=aSW!f!xoL1xgGB0@xvUk;MH9@&_W z;l(c!ugef;Z4l#pM2IvYDj^~eH;Zw8q3~mE%v4_NOs5x$k`~II8+c*~KS;{nj^wwQ z$A7;Osy|7#ut-;!j7_fbuWVD6J~Jx|spi7G_Q}b~rB4aLGEa(yiJF+$EUHAMS%#=2 zi>250WfYbpr4*v45hIm{c*b^9v}&qOp8Wje$*QW?WmnBj zZu9w^Dkpk0pKmI8?n)xbXgs;GlD@N`o2yRYT-9)~Eqj!XqnV4yj4rmFU&LFFq1yrz zIL20%#&ZUb5BKAC+>bj9mmwS^(qT=62X-U(f1`+sqVhuIO-z4F!~9!Q=gLF!sHi9f z;bX|sUdGO+fBb5PV+XN1`5&j7=nt=`2=CYF!uu;K`opi=pFWM)QmnGSd>N`L-eMgb zY;V1qR=4!<4`s*()y7V{%i?2mE z0{7#VG?JEdG|TTH|0mgTLV9B63F(PM$^Sgi_93CiQ4b26H ze$&}C@3JN>BgjR>P73;0>iWi z6nj4b@6c|s0}OeRl2{o#6kutZRkAeg1lFl?exvIL=zsCpi;SbAPMda|(=o)LuaF@0 z(0DWJ7Z*qf42n-ioU=O!BKq@45w+Z%BUrvhdo7M@xjQF_5Nyo2mc!LOH}i8$Dn%FJ zkpRDGKrYucHePRR)Q$I!c>_7D4UVE^oLYYi2$bf8_YNGFovjkgt!W}Rl}IZZDp^gs znu=Cs=m{o*Vb(L*OWSQDVUxucGC^f$H*cF&Jme&ZZ_7x)u3xUExr;=2MWc9IIQCFYbyPn? zPj@C1y`4gow>;^0tV)t3cn_(*<6J`8o2iZ+05$n>+#h*5HJuKS-Bs1JwqUP)eLG7B zZQU{}WY(6gbWrCeW&__c6o_ncljPjE^^T*e#Qd&{VTSRsJ09A)^cvgxz082zA+_>H zi`FHS+HYa_5Qhxchc_udlrwJCf{)QJl#)X)2EOr~JLgnUDyQ2`C8Nod+YP6|l+mkI zoIB_L7QNuM4iB>d)+J+ugDEfSrGkTyi2T^1xJve4bvH}RYM zebD-uUBAo2{dl}yU$Hgm^+w4=0mCU|IbW##9$O0BQF!qxI1eY7hy^P;t~N&z1BdQg z&oessH%)rF=9ns=$mC>Y)vG%z>-)1VV5x%nwjH+lfBj;Vmh4+|pfVmMhm*88ErV_I#kN zFfEN$nsBzdhE=jI7YnE#-0tF@>&RsYd^d)NQ@zl`!{09Cdq$s6s3)R|h}$^16FNtC zWwys|uc$Gu(;|p=V`*hB{&A*a{@i@fGwd)LBbPqk6}Id7Qj2?>wjm~F10T>Y_*stK zt6UP#T0yvSdoch+=H^Bof41`Lm-c-TKL?T1_0xT_p>6XF5neLvwoD`r z#vM~NHd>JN(%-)w3{QO>_Bz$2=sWZu?DQ-zv(?LOH7)zxwA%fNX|>n1%q;^iXb|uM zcs$#!R-4tj%!V1TLiCyQ+i!+OQS=KJJ#Es+h1LAEPM~yv!%Qs{7`a3*WQxE&@z$a%lR8>R`tOy`+6C+N$qhl*OEW}_&4xc z9(pSzY+~t({uQy2xxY$n8F1{ky&SY29vT9l>C}f0r#c_K??PYi$jAuZ8yc$2YHQ0{ z_2kque}C46J6$m3(R|bQL*P2= zLWfw@(5)fm_rEt%xD(RzHWtUeLD1Erq9uweKid_;d4$6Lv*OAuNr6il3C&4 zRk@zv3)UEy0jl81-73-G>R+HwZVm$IJ!+m#T1i5hCqWq1)qy*c6o`SL>bXg9Krjam zST{L7li6WjXLgu_IkUqIW2UiIs(sPJ-R%-G@f8SRH-#v(5Z(PqL2VEuUb<6+=5+A01}TK};s!>~)em>VN0 zZ7suTq~PM?&@y>vO4FfnLlSCS^PqR>=OZa?H4jSk4R^03?@S~qyf_;GTHf|9;oW(WGUPy<`!=ciFjLep4o6hX+fk=Y;Tc!wssp zE+sw(W~-R62UGQTOoB88LFy1Bg|0#BG)U42*v()1G$W%|e+gY*iKMVAPdX;?cpa0T zTnQr)XZSBtO?*alUfGLc{z*xgKia#}*<sjox zm;i;${Ppvf-tce&FKW-@Df340OrwwHb}H>*{p`iJX&FG$;%8dWpjtf-#NbS5mLAP# zhE7Ux_-Jkk*a%28RjsCj$?IS8UB}eXm%I}DIgO0WteA%xH>D`&+N#Olgr9#66~l$c zL!W`c-omLm$Zx~{DUNR`*tDgzp`x)Oaa*K3B1#T0{QtD&lJaD>;Oc~Sk(yt=+?0t+ z#t|()DOt-##$`(pRSG3RMMai^Uv9c(5zQuPADSlZZ8k28(9ydHHDsO9Re)X+C#R9J zT|zmnQ*(ukBEj@K{r#jummH#$&O~hmdb5Q*KmZutv+&!7^)BnbtzQ@>32)opHs~_6 zy`?Q2V0eK1_``Bp`H%BbfZ;LnTkl(>Eiqt%n_*>Wn_k|ZWfu0T%;AHdOiMck0{USy1dBfZ>_(T!{6L0ndtIL6iT2 zXKov;Yxcl#=%yA;kM)gPb8MAZlI`B zV+%aVxU(J?bduL~$MbM7!);D@wO-I|f=z<%YW6|*DWHDgQH|FO=FP%GPycMrqE z$9vj4j(3g1qsKeHmm8l47@q+Qhcjm66qSx;XYcjN-pkUld-V+F-mL8BQ?ooiQNb&> zUBC6UcBmbD1AWt)aT+DKh}=(X`#0}y6QMj@E@x|YWZwU=zQSOaX2+eAuxa)5=p=t- zSlOf+PvN=AXG}%uk5RBIyHB1g@5u%W+=fERRNO|S1#Risfz?*;s_bepwIH0vGSy%R z*a7X>T1fxHEQi?TDSvYIYz2>@(_1sfZ0169XWQg0uvq{N4%wui-kLt&@gQ_@o+EJC zV{wwl_phpQ%1U04oou(VYFHL;x7Px8fK8jagJUK^F(EO{n>GOu#XC6B!%k{+?2*M? zGVUd*b*ZptYc?AGaUQz*yIpAz_O7W|G2-!P`>A0xvSaQ4+y6P~QaV}QCKL(yYLhY2 z@&C8~Z_*|BcjJY0%qf!$sF5eKHXUFRH_8ft16sfyUNn$23R6vr36U)Xn`~*xQ*1op z_-d9p-i5wnwR}#hK?rNAYvYR?# zq?m%M${5&PpiPicV6^%a&@Z98)+Pp;c84bEaO5}dgC8n-$UvrxcB*Nkkb0VFq=_Cf z15`7$o)If@pJ<4B66vCvI_gP)DD1tBbgJo5T{K5qHkU!#sXS?5xHYEyFki_WL|JX7eSmA>Q!35!tv6Piw%1S>hD<2jWO5&=!D=(4Iat1h7Y1xce zP$~waa^j+ Date: Sun, 29 Nov 2026 13:32:19 -0800 Subject: [PATCH 9/9] Require the whole font on the icon chooser's page, and word the glyph field rule plainly Agent: DEV7 (developer) Agent-Model: Anthropic Opus 5.5, Medium --- documents/DOCS-SITE.md | 2 +- documents/KIT.md | 2 +- .../scripts/docs-site-check.ts | 10 +++++++++- src/noldova.ui.components.angular/src/api/symbols.d.ts | 5 +++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/documents/DOCS-SITE.md b/documents/DOCS-SITE.md index e1bf77c6..b8ba1d46 100644 --- a/documents/DOCS-SITE.md +++ b/documents/DOCS-SITE.md @@ -13,7 +13,7 @@ It is an Angular app in `src/noldova.ui.components.angular.docs`, built against | `npm run docs:build -w src/noldova.ui.components.angular.docs` | Writes the generated sources, then prerenders every page into `_build/docs`. | | `npm run symbols -w src/noldova.ui.components.angular.docs` | Refreshes the site's subset of the symbol font, as the [kit's symbols tool](KIT.md) does for any site, then needs `npm run docs:build` again. | | `npm run symbols:check -w src/noldova.ui.components.angular.docs` | Fails when the committed subset, its record, `src/styles.css` or the glyphs the site draws disagree. | -| `npm run docs:test -w src/noldova.ui.components.angular.docs` | Writes the generated sources, then runs the site's tests in Chromium, held to 100% coverage of `src/` without the files the README's coverage table names, and fails when a spec file reports no result or a function, statement or branch goes unreached. It then serves the site `npm run docs:build` wrote to `_build/docs/browser`, which must run first, opens each page the menu links in Chromium, and fails when a page or a favicon the page links isn't served, a favicon's type isn't an image, its one h1 isn't its menu title, a component page shows no example or an empty one, an example's code shows no highlighted token, a page draws a glyph the subset lacks or loads another copy of the symbol font, the icon chooser's page aside, a table, the docs' own or a Markdown one, breaks a word across lines or wraps a name, a key name or a type but before a `|`, at 1280 or 375px wide, or the browser logs an error, as a failed hydration does. | +| `npm run docs:test -w src/noldova.ui.components.angular.docs` | Writes the generated sources, then runs the site's tests in Chromium, held to 100% coverage of `src/` without the files the README's coverage table names, and fails when a spec file reports no result or a function, statement or branch goes unreached. It then serves the site `npm run docs:build` wrote to `_build/docs/browser`, which must run first, opens each page the menu links in Chromium, and fails when a page or a favicon the page links isn't served, a favicon's type isn't an image, its one h1 isn't its menu title, a component page shows no example or an empty one, an example's code shows no highlighted token, a page draws a glyph the subset lacks or loads another copy of the symbol font, the icon chooser's page aside, which must load the whole font, a table, the docs' own or a Markdown one, breaks a word across lines or wraps a name, a key name or a type but before a `|`, at 1280 or 375px wide, or the browser logs an error, as a failed hydration does. | The site compiles the kit's source, through the docs package's `tsconfig.json` paths and the kit's stylesheets in its `angular.json`, not the kit that `npm run build:components` installs; still, each command needs `npm run build:components` first, which installs the root's packages and the browser the site's tests use, and checks only that the kit is installed at the root as the sign that it ran; the root's `npm run build:docs` runs only this package's `docs:build`, which fails with a line saying to run `npm run build:components` first when the kit isn't built, and the root's `npm run build` runs `npm run build:components` then `npm run build:docs`; the API reference is read from the kit's declarations, `src/noldova.ui.components.angular/src/api/*.d.ts`, and its source. The docs package's own `test`, which an unfiltered `npm test` runs after the kit's, builds and tests the site on Linux; on other platforms, in a filtered run, and with `NOLDOVA_SEPARATE_TEST=docs`, which the CI targets set, it leaves them out, and the CI run's "Separate test" job checks the site once, on Linux x64, with `npm run build` and `npm run test:docs`, as the [README](../README.md#checks) says. diff --git a/documents/KIT.md b/documents/KIT.md index 1bf4cc65..14318d74 100644 --- a/documents/KIT.md +++ b/documents/KIT.md @@ -290,7 +290,7 @@ The icon chooser's and the gallery's lists hold every name of the set, since the A site gets its subset from the entry `@noldova/ui.components.angular/symbols`, a Node.js tool that loads in no browser: - Its `MaterialSymbols` takes where the site keeps its subset as a `MaterialSymbolsSite`, whose defaults a site overrides in a class of its own, and fails with a `MaterialSymbolsException`, a `UiComponentsException`. - It reads the union of the `glyphs.json` lists of the kit's parts the site's code imports, the icons its templates draw between the symbol class's span tags or give a part as `icon="…"`, the glyphs its code keeps in a field whose name ends or starts in glyph, as an `IconName` or a string, the same icons and glyphs of the other folders of code its pages show, its `moreCode`, and the names the site gives it for icons its code builds; a refresh, which the site runs as `npm run symbols`, downloads that subset from Google Fonts with its license, keeps it in the site's fonts folder named by its SHA-256, points the site's `@font-face` at it and records the address the site serves it at, its SHA-256 and its source in the site's license notice. + It reads the union of the `glyphs.json` lists of the kit's parts the site's code imports, the icons its templates draw between the symbol class's span tags or give a part as `icon="…"`, the glyphs its code keeps in a field whose name ends in glyph or starts with glyph and a capital, such as `glyphShield`, as an `IconName` or a string, the same icons and glyphs of the other folders of code its pages show, its `moreCode`, and the names the site gives it for icons its code builds; a refresh, which the site runs as `npm run symbols`, downloads that subset from Google Fonts with its license, keeps it in the site's fonts folder named by its SHA-256, points the site's `@font-face` at it and records the address the site serves it at, its SHA-256 and its source in the site's license notice. - Its check, `npm run symbols -- --check` in the site's checks, fails when the committed font, its record, its stylesheet or the glyphs the site draws disagree. - Its `drawnGlyphs` and `loadedFonts` page expressions and `findPageProblemsAsync` let the site's check of its built pages fail on a page that draws a glyph the subset lacks, or that loads another copy of the font, such as the whole font `kit.css` brings. diff --git a/src/noldova.ui.components.angular.docs/scripts/docs-site-check.ts b/src/noldova.ui.components.angular.docs/scripts/docs-site-check.ts index 6ebc7dc5..613080df 100644 --- a/src/noldova.ui.components.angular.docs/scripts/docs-site-check.ts +++ b/src/noldova.ui.components.angular.docs/scripts/docs-site-check.ts @@ -138,7 +138,11 @@ export class DocsSiteCheck implements ICheck { findings.push(DocsSiteCheck.unhighlighted(link, shown.count("plainCode"))); const drawn = DocsSiteCheck.namesOf(await page.evaluate(MaterialSymbols.drawnGlyphs), link); const fonts = DocsSiteCheck.namesOf(await page.evaluate(MaterialSymbols.loadedFonts), link); - findings.push(...await symbols.findPageProblemsAsync(link, drawn, link === DocsSymbols.wholeFontPage ? fonts.filter(t => !DocsSymbols.wholeFontFile.test(new URL(t).pathname)) : fonts)); + const isWholeFontPage = link === DocsSymbols.wholeFontPage; + const wholeFonts = fonts.filter(t => DocsSymbols.wholeFontFile.test(new URL(t).pathname)); + if (isWholeFontPage && wholeFonts.length === 0) + findings.push(DocsSiteCheck.noWholeFont(link)); + findings.push(...await symbols.findPageProblemsAsync(link, drawn, isWholeFontPage ? fonts.filter(t => !wholeFonts.includes(t)) : fonts)); for (const width of DocsSiteCheck.WIDTHS) await DocsSiteCheck.checkWrapsAsync(page, link, width, findings); const titles = shown.texts("titles"); @@ -216,6 +220,10 @@ export class DocsSiteCheck implements ICheck { return `${link} should have one h1, "${title}", as its menu link names it, and has ${titles.length === 0 ? "none" : titles.map(t => `"${t}"`).join(", ")}.`; } + private static noWholeFont(link: string): string { + return `${link} loads no copy of the whole symbol font, which the icon chooser draws its glyphs in.`; + } + private static noExamples(link: string): string { return `${link} shows no example.`; } diff --git a/src/noldova.ui.components.angular/src/api/symbols.d.ts b/src/noldova.ui.components.angular/src/api/symbols.d.ts index 37ef6e00..889f37c9 100644 --- a/src/noldova.ui.components.angular/src/api/symbols.d.ts +++ b/src/noldova.ui.components.angular/src/api/symbols.d.ts @@ -187,8 +187,9 @@ export declare class MaterialSymbolsException extends UiComponentsException { * * The subset holds the union of the `glyphs.json` lists of the kit's parts the * site's code imports, with the icons its templates draw or give a part's - * `icon`, the glyphs its code keeps in a field whose name ends or starts in - * glyph, and the site's own `names`. A refresh asks Google Fonts for that subset, keeps + * `icon`, the glyphs its code keeps in a field whose name ends in glyph or + * starts with glyph and a capital, such as `glyphShield`, and the site's own + * `names`. A refresh asks Google Fonts for that subset, keeps * it in the fonts folder named by its SHA-256, points the stylesheet at it * and records its served address, SHA-256 and source address in the license * notice; the check reads it all again and fails where any of it disagrees,