Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ npm test
`npm run build:docs` builds no kit, and needs `npm run build:components` first, as [the docs site](documents/DOCS-SITE.md#commands) says.
The kit's build builds it each time: it compiles it, packs it into `_packages/` as `noldova-ui.components.angular-<version>.tgz`, at the version `version.json` holds, and installs the archive at the root without saving it.
It installs the npm packages first when `node_modules` is missing, and the browser for the Angular tests.
It writes into the package `glyphs.json`, the glyphs each exported part can draw, which it reads from the kit's source as the [Part glyphs](#part-glyphs) check does, and which [KIT.md](documents/KIT.md#icons-a-site-subsets) describes; it compares the packed kit's `glyphs.json` with the file it wrote, byte for byte.
It writes into the package `glyphs.json`, the glyphs each exported part can draw and each exported model holds, which it reads from the kit's source as the [Part glyphs](#part-glyphs) check does, and which [KIT.md](documents/KIT.md#icons-a-site-subsets) describes; it compares the packed kit's `glyphs.json` with the file it wrote, byte for byte.
Each archive's `package.json` records the commit it was built from as `gitHead` when the clone has no changed tracked files and no untracked files that Git doesn't ignore, and leaves it out otherwise.
The kit's build also refuses an entry other than the testing entry that reaches `src/testing/` or Vitest.
`npm run docs:build -w src/noldova.ui.components.angular.docs` builds the docs site into `_build/docs` from the kit's source, `npm run docs:test -w src/noldova.ui.components.angular.docs` runs its tests, and `npm run docs:api -w src/noldova.ui.components.angular.docs` writes only its API reference; all three need `npm run build:components` first, as [the docs site](documents/DOCS-SITE.md) says.
Expand Down Expand Up @@ -141,8 +141,9 @@ It reads one line at a time: it refuses an assertion that a line break splits fr
The part glyphs check, `src/noldova.ui.components.angular/scripts/checks/part-glyphs-check.ts`, reads the glyphs each part the kit's entries export can draw, as the build writes them to the package's `glyphs.json`, with TypeScript's type checker over every source file under `src/noldova.ui.components.angular/src` but the specs.
A glyph is a string literal typed `IconName`, or, in a constant written `as const`, an icon name under a property whose name holds glyph or icon; an icon written between the symbol font's span tags in a template is one too, and so is an icon name a template gives an input, or model, that a part's selector places and types `IconName` or a list of them: the attribute's value, such as `icon="forum"`, or each quoted literal of a bound expression and each one between backticks with no interpolation, such as `[icon]="open() ? 'close' : 'menu'"` or ``[icon]="`forum`"``.
A part's list holds the glyphs its own file gives, those of the files it imports, not only for types, that its code uses or its template names, the icons its template draws as written, and the same of every part it imports, which it shows.
The check fails on each glyph of the source that no part's list holds, naming its file and line, since a part could draw it and a site's subset of the font would leave it out.
It first reads a small source of its own, with a part that shows another, a resources class with a used and an unused glyph, a template's glyph, icons handed to an input as written, and a constant's, and fails when that reading differs from the one it expects.
Each other class the entries export, a model such as `LinkReferenceAction`, gets a list of the glyphs of its files its code uses, such as the glyph it defaults to, when it has any, under `models`, since a part draws what a model holds.
The check fails on each glyph of the source that no part's or model's list holds, naming its file and line, since a part could draw it and a site's subset of the font would leave it out.
It first reads a small source of its own, with a part that shows another, a resources class with a used and an unused glyph, a template's glyph, icons handed to an input as written, a constant's, a model that defaults to a glyph and one that holds none, and fails when that reading differs from the one it expects.
A glyph a part takes as an input or a model field, such as `IconButtonComponent.icon`, is the site's own and in no list.

### Kit bundles
Expand Down
4 changes: 2 additions & 2 deletions documents/KIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,13 @@ A compact row, as tall as an icon button, takes `--nol-icon-button`, 1.375rem, f
`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": { "<class name>": ["<glyph>", …], … } }`: 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.
It is `{ "parts": { "<class name>": ["<glyph>", …], … }, "models": { … } }`: 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, and the same for each other class they export that holds glyphs, a model such as `LinkReferenceAction`, whose list holds the glyph it defaults to, `open_in_new`.
A glyph the site passes to a part, such as an icon button's `icon` or a `SiteAction`'s, is in no list.
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` 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 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.
It reads the union of the `glyphs.json` lists of the kit's parts and models 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`, with the lists of the kit's models they import by any path, 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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ 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"];
// The glyphs no reading finds: those the examples give a part's model by position, such as a tree node's or a quick input item's icon, the
// gallery's option icons, and a link reference action's default, which belongs to a model and so to no part's list.
public override readonly names: readonly string[] = ["book", "bookmark", "groups", "open_in_new", "person"];
// The glyphs no reading finds: those the examples give a part's model by position, such as a tree node's or a quick input item's icon, and
// the gallery's option icons.
public override readonly names: readonly string[] = ["book", "bookmark", "groups", "person"];

public constructor(root: string, kitGlyphs: string) {
super(root);
Expand All @@ -40,7 +40,7 @@ export class DocsSymbols {
public static async createAsync(root: string): Promise<MaterialSymbols> {
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));
await writeFile(glyphs, PartGlyphs.render(await KitGlyphs.readAsync(root)));
const site = path.join(root, DocsSymbols.SITE_FOLDER);
return new MaterialSymbols(new DocsSymbolsSite(site, path.relative(site, glyphs).split(path.sep).join(path.posix.sep)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/noldova.ui.components.angular/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class Build extends Script {
const { KitGlyphs } = await import("./glyphs/kit-glyphs.ts");
const { PartGlyphs } = await import("./glyphs/part-glyphs.ts");
const file = path.join(output, KitGlyphs.FILE_NAME);
await this.writeFileAsync(file, PartGlyphs.render((await KitGlyphs.readAsync(Build.ROOT)).parts));
await this.writeFileAsync(file, PartGlyphs.render(await KitGlyphs.readAsync(Build.ROOT)));
return new PackageFile(file, KitGlyphs.FILE_NAME);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import { KitGlyphs } from "../glyphs/kit-glyphs.ts";
import { PartGlyphs } from "../glyphs/part-glyphs.ts";
import type { PartGlyphsReading } from "../glyphs/part-glyphs-reading.ts";

// Reads the glyphs each exported part can draw, as the build writes them to the package's glyphs.json, first from a small source of its own, then
// from the kit's, and fails when a glyph of the kit's source is in no part's list: a part would draw it and a site's subset of the font leave it out.
// Reads the glyphs each exported part can draw, and each exported model holds, as the build writes them to the package's glyphs.json, first from a
// small source of its own, then from the kit's, and fails when a glyph of the kit's source is in no list: a part would draw it and a site's subset
// of the font leave it out.
export class PartGlyphsCheck implements ICheck {
private static readonly OWN_FOLDER: string = "_build/part-glyphs-check";
private static readonly OWN_NAMES: readonly string[] = ["add", "close", "delete", "edit", "forum", "home", "menu", "refresh", "search", "share", "star", "sync",
Expand Down Expand Up @@ -94,8 +95,26 @@ export class PartGlyphsCheck implements ICheck {
"}",
""
].join("\n")],
["action.ts", [
"import { HeaderResources } from \"./header.resources.js\";",
"import type { IconName } from \"./icon-name.js\";",
"export class Action {",
" public readonly glyph: IconName;",
" public constructor(glyph: IconName = HeaderResources.searchGlyph) {",
" this.glyph = glyph;",
" }",
"}",
""
].join("\n")],
["plain.ts", "export class Plain {\n public readonly label: string = \"add\";\n}\n"],
["unused.ts", "import type { IconName } from \"./icon-name.js\";\nexport const zoomGlyph: IconName = \"zoom_in\";\n"],
[PartGlyphsCheck.OWN_ENTRY, "export { HeaderComponent } from \"./header.component.js\";\nexport { PanelComponent } from \"./panel.component.js\";\n"]
[PartGlyphsCheck.OWN_ENTRY, [
"export { Action } from \"./action.js\";",
"export { HeaderComponent } from \"./header.component.js\";",
"export { PanelComponent } from \"./panel.component.js\";",
"export { Plain } from \"./plain.js\";",
""
].join("\n")]
]);
private static readonly OWN_LIST: string = [
"{",
Expand All @@ -114,11 +133,16 @@ export class PartGlyphsCheck implements ICheck {
" \"add\",",
" \"star\"",
" ]",
" },",
" \"models\": {",
" \"Action\": [",
" \"search\"",
" ]",
" }",
"}",
""
].join("\n");
private static readonly OWN_ORPHANS: string = "header.resources.ts:4: search,unused.ts:2: zoom_in";
private static readonly OWN_ORPHANS: string = "unused.ts:2: zoom_in";

private readonly root: string;

Expand All @@ -130,18 +154,19 @@ export class PartGlyphsCheck implements ICheck {

public async runAsync(output: Writable): Promise<boolean> {
const own = this.readOwn();
const isOwnRight = PartGlyphs.render(own.parts) === PartGlyphsCheck.OWN_LIST && own.orphans.join(",") === PartGlyphsCheck.OWN_ORPHANS;
const isOwnRight = PartGlyphs.render(own) === PartGlyphsCheck.OWN_LIST && own.orphans.join(",") === PartGlyphsCheck.OWN_ORPHANS;
if (!isOwnRight)
output.write(`The check's own test read ${JSON.stringify(PartGlyphs.render(own.parts))} with the glyphs in no list ${JSON.stringify(own.orphans)} ` +
output.write(`The check's own test read ${JSON.stringify(PartGlyphs.render(own))} with the glyphs in no list ${JSON.stringify(own.orphans)} ` +
`from a small source, not ${JSON.stringify(PartGlyphsCheck.OWN_LIST)} with ${PartGlyphsCheck.OWN_ORPHANS}.\n`);
const kit = await KitGlyphs.readAsync(this.root);
for (const orphan of kit.orphans)
output.write(`${orphan} is a glyph no exported part's list in ${KitGlyphs.FILE_NAME} holds; ` +
output.write(`${orphan} is a glyph no exported part's or model's list in ${KitGlyphs.FILE_NAME} holds; ` +
"name it in a resources class's field that the part that draws it uses, or in its template.\n");
if (kit.parts.size === 0)
output.write(`The kit's entries export no part, so ${KitGlyphs.FILE_NAME} would list none.\n`);
else
output.write(`${KitGlyphs.FILE_NAME} lists the glyphs of ${kit.parts.size} parts, ${new Set([...kit.parts.values()].flat()).size} glyphs in all.\n`);
output.write(`${KitGlyphs.FILE_NAME} lists the glyphs of ${kit.parts.size} parts and ${kit.models.size} models, ` +
`${new Set([...kit.parts.values(), ...kit.models.values()].flat()).size} glyphs in all.\n`);
return isOwnRight && kit.orphans.length === 0 && kit.parts.size > 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

import type ts from "typescript";

// A part an entry of the kit exports: its exported name and the file that declares it.
export class ExportedPart {
// A class an entry of the kit exports: its exported name, the file that declares it, and whether it is a part, a component, or a model.
export class ExportedClass {
public readonly name: string;
public readonly source: ts.SourceFile;
public readonly isPart: boolean;
Comment thread
rostislavrotaru marked this conversation as resolved.
Resolved

public constructor(name: string, source: ts.SourceFile) {
public constructor(name: string, source: ts.SourceFile, isPart: boolean) {
this.name = name;
this.source = source;
this.isPart = isPart;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
* LICENSE file in the root directory of this source tree.
*/

// The package's glyphs.json: for each part the kit exports, by its class name, the sorted glyphs it can draw.
// The package's glyphs.json: for each part the kit exports, by its class name, the sorted glyphs it can draw, and the same for each model it
// exports that holds glyphs.
export class PartGlyphsFile {
public readonly parts: Readonly<Record<string, readonly string[]>>;
public readonly models: Readonly<Record<string, readonly string[]>>;

public constructor(parts: Readonly<Record<string, readonly string[]>>) {
public constructor(parts: Readonly<Record<string, readonly string[]>>, models: Readonly<Record<string, readonly string[]>>) {
this.parts = parts;
this.models = models;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
* LICENSE file in the root directory of this source tree.
*/

// What PartGlyphs read: each exported part's glyphs, and each glyph of the source that no part's list holds, by its place.
// What PartGlyphs read: each exported part's glyphs, each exported model's that has any, and each glyph of the source that no list holds, by its
// place.
export class PartGlyphsReading {
public readonly parts: ReadonlyMap<string, readonly string[]>;
public readonly models: ReadonlyMap<string, readonly string[]>;
public readonly orphans: readonly string[];

public constructor(parts: ReadonlyMap<string, readonly string[]>, orphans: readonly string[]) {
public constructor(parts: ReadonlyMap<string, readonly string[]>, models: ReadonlyMap<string, readonly string[]>, orphans: readonly string[]) {
this.parts = parts;
this.models = models;
this.orphans = orphans;
}
}
Loading
Loading