diff --git a/documents/DOCS-SITE.md b/documents/DOCS-SITE.md index 75e871e7..b8ba1d46 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, 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. 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..14318d74 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 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. 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/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..17b41b62 100644 --- a/src/noldova.ui.components.angular.docs/package.json +++ b/src/noldova.ui.components.angular.docs/package.json @@ -6,9 +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", - "test:timing": "node scripts/test-docs-timing.ts" + "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 --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/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 00000000..3e11311a Binary files /dev/null and b/src/noldova.ui.components.angular.docs/public/assets/fonts/material-symbols-a10fbdab.woff2 differ diff --git a/src/noldova.ui.components.angular.docs/public/assets/licenses/MATERIAL-SYMBOLS-LICENSE.txt b/src/noldova.ui.components.angular.docs/public/assets/licenses/MATERIAL-SYMBOLS-LICENSE.txt new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/src/noldova.ui.components.angular.docs/public/assets/licenses/MATERIAL-SYMBOLS-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/src/noldova.ui.components.angular.docs/public/assets/licenses/README.txt b/src/noldova.ui.components.angular.docs/public/assets/licenses/README.txt new file mode 100644 index 00000000..2a674ba8 --- /dev/null +++ b/src/noldova.ui.components.angular.docs/public/assets/licenses/README.txt @@ -0,0 +1,4 @@ +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, /assets/fonts/material-symbols-a10fbdab.woff2, holding only the icons it draws; refresh it with npm run symbols after adding an icon. +SHA-256: a10fbdabb558ff196b4a8d647553a05e311f02394c5517e352f6c6a46aefd34d material-symbols-a10fbdab.woff2 +Source: https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@24,400,0,0&icon_names=account_tree,add,arrow_downward,arrow_upward,block,book,bookmark,chat,chat_bubble,check,checklist,chevron_right,close,content_copy,crop_square,dark_mode,data_object,delete,description,desktop_windows,download,draft,edit,edit_note,error,filter_list,filter_none,fit_screen,folder,folder_open,format_bold,format_quote,forum,groups,history,image,keep,keyboard_arrow_down,light_mode,link,lock,map,menu,more_horiz,more_vert,open_in_new,palette,pan_tool,person,play_arrow,public,query_stats,refresh,restart_alt,save,search,send,settings,share,shield,sort,stop,subdirectory_arrow_right,sync,terminal,thumb_up,toc,tune,vertical_split,wrap_text,zoom_in,zoom_out&display=swap 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..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 @@ -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,13 @@ 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); + 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"); @@ -163,6 +175,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; } @@ -199,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.docs/scripts/docs/docs-symbols.ts b/src/noldova.ui.components.angular.docs/scripts/docs/docs-symbols.ts new file mode 100644 index 00000000..26f19b38 --- /dev/null +++ b/src/noldova.ui.components.angular.docs/scripts/docs/docs-symbols.ts @@ -0,0 +1,47 @@ +/** + * @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 { 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, 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"]; + // 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"]; + + 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"; + + 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(new DocsSymbolsSite(site, path.relative(site, glyphs).split(path.sep).join(path.posix.sep))); + } +} 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..cc192000 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-a10fbdab.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/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..889f37c9 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,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 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, 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 10a91802..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); @@ -265,6 +293,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(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 () => { await current().writeAsync(`web/fonts/${filename}`, font); await current().writeAsync("web/notices/README.txt", Site.notice(digest, filename, source));