@reqvire-org/ads 0.3.52 → 0.3.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -202,7 +202,7 @@ async function main(args) {
202
202
  }
203
203
  else if (command === "lint-config") console.log(`Generated ${result.file}\nUse this optional configuration only in the project linter you choose to run.`);
204
204
  else if (command === "behaviors") console.log(JSON.stringify(result, null, 2));
205
- else if (command === "audit") { const { findingCounts } = await import("./finding-rules.mjs"); console.log(`ADS accessibility audit (${result.engine}): ${findingCounts(result.diagnostics.length, result.findings.filter(finding => finding.severity === "review").length)}, ${result.incomplete ?? 0} that axe could not decide across ${result.scenarios} scenarios × ${result.themes.length} themes (${result.themes.join(", ")})${result.brands ? ` × ${result.brands.length} brands (${result.brands.join(", ")})` : ""}.`); if (result.retries) console.log(`Retried ${result.retries.length} render${result.retries.length === 1 ? "" : "s"} that then passed: ${result.retries.map(retry => `${retry.scenario} [${[retry.theme, retry.brand].filter(Boolean).join(", ")}] in ${retry.attempts} attempts`).join("; ")}.`); for (const finding of result.findings) console.error(`${finding.file}:${finding.line}:${finding.column} [${finding.severity}:${finding.rule}] ${finding.message}`); }
205
+ else if (command === "audit") { const { findingCounts } = await import("./finding-rules.mjs"); console.log(`ADS accessibility audit (${result.engine}): ${findingCounts(result.diagnostics.length, result.findings.filter(finding => finding.severity === "review").length)}, ${result.incomplete ?? 0} that axe could not decide across ${result.scenarios} scenarios × ${result.themes.length} themes (${result.themes.join(", ")})${result.brands ? ` × ${result.brands.length} brands (${result.brands.join(", ")})` : ""}.`); if (result.coverage) { const skipped = Object.entries(result.coverage.skipped); console.log(`Covered: ${result.coverage.renders} renders, ${result.coverage.overlaysOpened} overlays opened, ${result.coverage.controlsMeasured} controls hovered and focused; ${skipped.length ? `skipped ${skipped.map(([reason, entry]) => `${reason} ${entry.count}`).join(", ")}` : "nothing skipped"}.`); } if (result.retries) console.log(`Retried ${result.retries.length} render${result.retries.length === 1 ? "" : "s"} that then passed: ${result.retries.map(retry => `${retry.scenario} [${[retry.theme, retry.brand].filter(Boolean).join(", ")}] in ${retry.attempts} attempts`).join("; ")}.`); for (const finding of result.findings) console.error(`${finding.file}:${finding.line}:${finding.column} [${finding.severity}:${finding.rule}] ${finding.message}`); }
206
206
  else if (command === "verify") { for (const item of result.results) console.log(`${item.unit}#${item.check}: ${item.status} (${item.profile})`); }
207
207
  else if (command === "validate") {console.log(`ADS ${result.policy} ${result.ok?"passed":"failed"}: ${result.scope}${result.fallback?` (${result.fallback})`:""}`);for(const check of result.checks)console.log(`${check.name}: ${check.skipped?"skipped":check.passed?"passed":"failed"}${check.reason?` (${check.reason})`:""}`);}
208
208
  else if (command === "tokens") {
package/dist/config.mjs CHANGED
@@ -28,7 +28,7 @@ export const defaultConfig = {
28
28
  followSystemTheme: false,
29
29
  inlineStyleFiles: [],
30
30
  boundaries: { styleWrites: [], componentVariables: [] },
31
- assets: { publicDirs: ["public/assets"], generatedPaths: ["dist", "dist-showcase", ".vite", ".ds"], generatedFiles: [], iconSource: null, targets: [], glyphs: null, imageBudgetKb: null },
31
+ assets: { publicDirs: ["public/assets"], generatedPaths: ["dist", "dist-showcase", ".vite", ".ds"], generatedFiles: [], iconSource: null, targets: [], glyphs: null, imageBudgetKb: null, fontBudgetKb: null, preloadFonts: null },
32
32
  oxlint: { plugins: [], rules: {}, overrides: [] },
33
33
  acceptance: { checks: [], behaviorChecks: false, browserAudit: true },
34
34
  validation: { checks: [], behaviorChecks: true, browserAudit: true, inputs: [] },
@@ -131,6 +131,8 @@ export function loadConfig(directory = process.cwd()) {
131
131
  for (const brand of config.brands) if (config.themes.some(theme => theme.name === `brand-${brand.name}`)) throw new Error(`Theme "brand-${brand.name}" and brand "${brand.name}" would share the display switch --display-brand-${brand.name}; rename one.`);
132
132
  if(config.resources.memoryLimitMb!==null&&(!Number.isInteger(config.resources.memoryLimitMb)||config.resources.memoryLimitMb<64||config.resources.memoryLimitMb>1048576))throw new Error("resources.memoryLimitMb must be null (automatic) or an integer from 64 to 1048576 MiB.");
133
133
  if (config.assets.imageBudgetKb !== null && (!Number.isInteger(config.assets.imageBudgetKb) || config.assets.imageBudgetKb < 1 || config.assets.imageBudgetKb > 1048576)) throw new Error("assets.imageBudgetKb must be null (a limit per format) or a positive whole number of KB for every format.");
134
+ if (config.assets.preloadFonts !== null && (!Array.isArray(config.assets.preloadFonts) || config.assets.preloadFonts.some(item => !item || typeof item !== "object" || Array.isArray(item) || Object.keys(item).some(key => !["family", "weight"].includes(key)) || typeof item.family !== "string" || !item.family || !Number.isInteger(item.weight) || item.weight < 1 || item.weight > 1000))) throw new Error('assets.preloadFonts must be null or an array of { "family": "Name", "weight": 400 }.');
135
+ if (config.assets.fontBudgetKb !== null && (!Number.isInteger(config.assets.fontBudgetKb) || config.assets.fontBudgetKb < 1 || config.assets.fontBudgetKb > 1048576)) throw new Error("assets.fontBudgetKb must be null (the default limit) or a positive whole number of KB.");
134
136
  if (!Array.isArray(config.layout.widthTokens) || config.layout.widthTokens.length > 200 || new Set(config.layout.widthTokens).size !== config.layout.widthTokens.length || config.layout.widthTokens.some(name => typeof name !== "string" || !/^--[\w-][\w*-]*$/.test(name))) throw new Error("layout.widthTokens must contain distinct token names or globs such as --panel-*, and cannot name every token.");
135
137
  if (!Array.isArray(config.layout.fixedWidthUnits) || config.layout.fixedWidthUnits.length > 200 || new Set(config.layout.fixedWidthUnits).size !== config.layout.fixedWidthUnits.length || config.layout.fixedWidthUnits.some(glob => typeof glob !== "string" || !glob || glob.includes("\\") || glob.startsWith("/") || glob.split("/").includes("..") || !/[^*/]/.test(glob))) throw new Error("layout.fixedWidthUnits must contain distinct unit ids or project-relative globs such as components/Overlay/*, and cannot name every unit.");
136
138
  if (!Array.isArray(config.usage.notifications) || config.usage.notifications.length > 100) throw new Error("usage.notifications must be an array of notification API registrations.");
@@ -27,9 +27,16 @@ export const findingRules = Object.freeze({
27
27
  // Whether a declared width must stay fixed, a fluid wrapper does anything, or a part ever sits in
28
28
  // a narrow pane takes judgement.
29
29
  "layout-declared-width": "review", "layout-width-noop": "review", "layout-overflow-narrow": "review",
30
+ // Rendered at a shape other than the one declared: cropped or stretched.
31
+ "img-shape": "error",
32
+ // What the audit could not measure, by reason; a render whose targets could none be measured is for review.
33
+ "browser-audit-skipped": "info", "browser-audit-nothing-measured": "review",
30
34
  // Images reserve their space and choose how they load; a spread or foreign class cannot be read.
31
35
  "img-attributes": "error", "img-attributes-unresolved": "info",
32
- "asset-image-budget": "error",
36
+ "asset-image-budget": "error", "asset-font-budget": "error",
37
+ // A weight no declared face covers is faked or replaced. An unused file, a font-display and a format
38
+ // are choices someone can have a reason for.
39
+ "font-weight-missing": "error", "font-preload-config": "error", "font-file-unused": "review", "font-display": "review", "font-format": "review",
33
40
  "layout-shift": "error",
34
41
  "glyph-aliases": "error", "glyph-color": "error", "glyph-viewbox": "error",
35
42
  // Local source cannot prove pointer-capture cleanup or dynamic scenario execution.
@@ -0,0 +1,103 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import postcss from "postcss";
4
+ import valueParser from "postcss-value-parser";
5
+ import { contextValues } from "./themes.mjs";
6
+ import { findingSeverity } from "./finding-rules.mjs";
7
+ import { fontFaces, preloadFace } from "./fonts-generated.mjs";
8
+
9
+ /** Fonts a project declares in tokens/fonts.css, against the weights its CSS uses. Without a declared
10
+ * face it finds nothing: a system font stack has no files and no faces to fake.
11
+ * A face with a weight range, or with no font-weight (auto, as a variable font), covers what it spans.
12
+ * A weight read in a rule with no font-family belongs to the body's family, since it inherits. */
13
+ const unquote = value => value.trim().replace(/^["']|["']$/g, "");
14
+ const keyword = { normal: 400, bold: 700 };
15
+ const weightOf = value => { const number = Number(value); return Number.isFinite(number) && number >= 1 && number <= 1000 ? number : keyword[value?.toLowerCase()]; };
16
+
17
+ function declaredFaces(file) {
18
+ const faces = [];
19
+ postcss.parse(readFileSync(file, "utf8")).walkAtRules(/^font-face$/i, rule => {
20
+ const read = name => rule.nodes.find(node => node.type === "decl" && node.prop.toLowerCase() === name)?.value;
21
+ const url = /url\(\s*["']?([^"')]+)["']?\s*\)/i.exec(read("src") ?? "")?.[1], weight = read("font-weight")?.trim().toLowerCase();
22
+ const parts = weight && weight !== "auto" ? weight.split(/\s+/).map(weightOf) : null;
23
+ faces.push({ family: unquote(read("font-family") ?? ""), url, low: parts?.[0], high: parts?.[1] ?? parts?.[0], auto: !parts, display: read("font-display")?.trim().toLowerCase(), italic: /italic|oblique/i.test(read("font-style") ?? ""), ranged: !!read("unicode-range"), line: rule.source.start.line });
24
+ });
25
+ return faces;
26
+ }
27
+
28
+ export function createFontRules({ root, dsRoot, config }, tokens) {
29
+ const file = path.join(dsRoot, config.tokenDir, "fonts.css");
30
+ let faces = [];
31
+ try { if (existsSync(file)) faces = declaredFaces(file); } catch { /* The core CSS syntax diagnostic owns a malformed sheet. */ }
32
+ const relative = target => path.relative(root, target).replaceAll("\\", "/");
33
+ // A named preload that fonts.css cannot satisfy is an error, so a typo cannot silently lose it.
34
+ const preloadFindings = () => (config.assets.preloadFonts ?? []).flatMap(entry => {
35
+ let sheet = [];
36
+ try { if (existsSync(file)) sheet = fontFaces(readFileSync(file, "utf8")); } catch { /* The core CSS syntax diagnostic owns a malformed sheet. */ }
37
+ if (preloadFace(sheet, entry)) return [];
38
+ const known = sheet.some(face => face.family === entry.family);
39
+ return [{ rule: "font-preload-config", severity: findingSeverity("font-preload-config"), file: "ds.config.json", line: 1, column: 1, guidanceUri: "ads://guides/performance",
40
+ message: `assets.preloadFonts names ${entry.family} at weight ${entry.weight}, and tokens/fonts.css ${known ? `has no upright face of ${entry.family} covering Latin at that weight` : `declares no font-family ${entry.family}`}. Correct the entry or add the face.` }];
41
+ });
42
+ if (!faces.length) return { collect() {}, findings: preloadFindings };
43
+ const values = contextValues(tokens, { theme: config.themes[0].name, themes: config.themes });
44
+ const families = new Set(faces.map(face => face.family));
45
+ /** A value with its var() read through, as far as tokens define it. */
46
+ const read = (value, seen = new Set()) => valueParser(value).nodes.map(node => {
47
+ if (node.type !== "function" || node.value !== "var") return valueParser.stringify(node);
48
+ const [name, ...fallback] = valueParser.stringify(node.nodes).split(",");
49
+ const token = name.trim();
50
+ if (seen.has(token)) return "";
51
+ const found = values.get(token)?.value ?? fallback.join(",");
52
+ return read(found, new Set([...seen, token]));
53
+ }).join("");
54
+ const familiesIn = value => read(value).split(",").map(unquote).filter(item => families.has(item));
55
+ // A family set with no weight in its rule takes whatever weight it inherits, so any of its weights may be in use.
56
+ const used = new Map(), named = new Set(), inherited = new Set();
57
+ let bodyFamily, pending = [];
58
+ const note = (family, weight, source) => { const uses = used.get(family) ?? new Map(); used.set(family, uses); if (!uses.has(weight)) uses.set(weight, source); };
59
+ return {
60
+ /** Reads one style sheet or Linaria template. */
61
+ collect(css, target, offset = { line: 1 }) {
62
+ const source = decl => ({ file: relative(target), line: offset.line + (decl.source?.start.line ?? 1) - 1 });
63
+ // A Linaria template's own declarations sit at the root of what it parses to.
64
+ const owners = new Set();
65
+ css.walkDecls(/^font(?:-family|-weight)?$/i, decl => { if (decl.parent.type !== "atrule" || !/^font-face$/i.test(decl.parent.name)) owners.add(decl.parent); });
66
+ for (const rule of owners) {
67
+ const own = name => rule.nodes.filter(node => node.type === "decl" && node.prop.toLowerCase() === name).at(-1);
68
+ const shorthand = own("font"), parts = shorthand ? read(shorthand.value).split(/\s+/) : [];
69
+ const familyDecl = own("font-family");
70
+ const stack = familyDecl ? familiesIn(familyDecl.value) : shorthand ? familiesIn(read(shorthand.value).replace(/^.*?\d[^ ]*(?:\/[^ ]+)?\s+/, "")) : [], family = stack[0];
71
+ for (const item of stack) named.add(item);
72
+ if (family && /^(?:(?::where\()?(?:html|body|:root)\)?)$/.test(rule.selector?.trim() ?? "")) bodyFamily ??= family;
73
+ const weightDecl = own("font-weight"), weight = weightDecl ? weightOf(read(weightDecl.value).trim()) : parts.map(weightOf).find(Boolean);
74
+ if (!weight) { for (const item of stack) inherited.add(item); continue; }
75
+ const where = source(weightDecl ?? shorthand);
76
+ if (family) note(family, weight, where);
77
+ else if (!familyDecl && !shorthand) pending.push({ weight, where });
78
+ }
79
+ },
80
+ findings() {
81
+ const findings = preloadFindings(), covering = (family, weight) => faces.some(face => face.family === family && !face.italic && (face.auto || face.low <= weight && weight <= face.high));
82
+ if (bodyFamily) { named.add(bodyFamily); inherited.delete(bodyFamily); for (const { weight, where } of pending) note(bodyFamily, weight, where); }
83
+ pending = [];
84
+ for (const [family, uses] of used) for (const [weight, where] of uses) if (!covering(family, weight)) {
85
+ findings.push({ rule: "font-weight-missing", severity: findingSeverity("font-weight-missing"), file: where.file, line: where.line, column: 1, guidanceUri: "ads://guides/performance",
86
+ message: `${where.file}:${where.line} uses ${family} at weight ${weight}, and tokens/fonts.css has no face that covers it, so the browser fakes it or picks another weight. Add the file, use a variable font with a font-weight range, or use a declared weight.` });
87
+ }
88
+ const seen = new Set();
89
+ // A face of local() files only downloads nothing: a fallback sized to match, say.
90
+ for (const face of faces.filter(item => item.url)) {
91
+ const at = { file: relative(file), line: face.line, column: 1, guidanceUri: "ads://guides/performance" };
92
+ const name = face.url ? path.basename(face.url) : face.family;
93
+ const single = !face.auto && face.low === face.high && !face.italic;
94
+ const unused = !named.has(face.family) || single && !face.ranged && !inherited.has(face.family) && ![400, 700].includes(face.low) && !used.get(face.family)?.has(face.low);
95
+ if (unused && !seen.has(name)) { seen.add(name); findings.push({ rule: "font-file-unused", severity: findingSeverity("font-file-unused"), ...at, message: `${name}${named.has(face.family) ? ` (${face.family} at weight ${face.low})` : ` (${face.family})`} is declared and no CSS uses it. Remove the face and the file, so nothing downloads it.` }); }
96
+ if (!face.display) findings.push({ rule: "font-display", severity: findingSeverity("font-display"), ...at, message: `${name} has no font-display, so text can stay invisible while it loads. Set font-display: swap.` });
97
+ else if (face.display === "optional") findings.push({ rule: "font-display", severity: findingSeverity("font-display"), ...at, message: `${name} has font-display: optional. The browser decides per file, so one page can draw some weights in the font and others in the fallback. Use font-display: swap.` });
98
+ if (face.url && !/^data:/i.test(face.url) && !/\.woff2(?:[?#].*)?$/i.test(face.url)) findings.push({ rule: "font-format", severity: findingSeverity("font-format"), ...at, message: `${name} is not WOFF2, the smallest format every current browser reads. Convert it.` });
99
+ }
100
+ return findings;
101
+ },
102
+ };
103
+ }
@@ -3,23 +3,25 @@ import path from "node:path";
3
3
  import postcss from "postcss";
4
4
  import { resolveValue } from "./themes.mjs";
5
5
 
6
- /** fonts.preload.generated.ts names the font files the first text uses, read from the sheets: the
7
- * first family in base.css's body font-family and heading font-family that fonts.css declares, at
8
- * the body and heading font-weight. Preloading more than that delays what matters. It imports each
6
+ /** fonts.preload.generated.ts names the font files the first text uses: assets.preloadFonts when the
7
+ * project lists them, otherwise read from the sheets: the first family in base.css's body font-family
8
+ * and heading font-family that fonts.css declares, at the body and heading font-weight. Preloading more than that delays what matters. It imports each
9
9
  * file through the bundler, the way the stylesheet's url() does, so both ask for one URL: a page
10
- * that preloads another URL downloads the font twice. Without such a font nothing is generated. */
10
+ * that preloads another URL downloads the font twice. A plain import is what Vite, Bun and the
11
+ * preview compiler all read as a file's URL. Without such a font nothing is generated. */
11
12
  export const generatedFontsFile = "fonts.preload.generated.ts";
12
13
  const unquote = value => value.trim().replace(/^["']|["']$/g, "");
13
14
  const formats = { woff2: "font/woff2", woff: "font/woff", ttf: "font/ttf", otf: "font/otf" };
14
15
 
15
- function fontFaces(text) {
16
+ export function fontFaces(text) {
16
17
  const faces = [];
17
18
  postcss.parse(text).walkAtRules(/^font-face$/i, rule => {
18
19
  const value = name => rule.nodes.find(node => node.type === "decl" && node.prop.toLowerCase() === name)?.value;
19
20
  const url = /url\(\s*["']?([^"')]+)["']?\s*\)/i.exec(value("src") ?? "")?.[1];
20
21
  if (!url || /^data:/i.test(url)) return;
21
- const [low, high = low] = (value("font-weight") ?? "400").replace(/\bnormal\b/, "400").replace(/\bbold\b/, "700").trim().split(/\s+/).map(Number);
22
- faces.push({ family: unquote(value("font-family") ?? ""), url, low, high, slant: (value("font-style") ?? "normal").trim().toLowerCase(), range: value("unicode-range") });
22
+ const auto = !value("font-weight") || /^auto$/i.test(value("font-weight").trim());
23
+ const [low, high = low] = (auto ? "400" : value("font-weight")).replace(/\bnormal\b/, "400").replace(/\bbold\b/, "700").trim().split(/\s+/).map(Number);
24
+ faces.push({ family: unquote(value("font-family") ?? ""), url, auto, low, high, slant: (value("font-style") ?? "normal").trim().toLowerCase(), range: value("unicode-range") });
23
25
  });
24
26
  return faces;
25
27
  }
@@ -27,6 +29,9 @@ function fontFaces(text) {
27
29
  /** Whether a unicode-range covers Latin capital A, the subset first text needs. */
28
30
  const coversLatin = range => !range || range.split(",").some(part => { const [first, last = first] = part.trim().replace(/^U\+/i, "").split("-").map(item => parseInt(item.replaceAll("?", "0"), 16)); return first <= 0x41 && 0x41 <= (part.includes("?") ? first + 0xff : last); });
29
31
 
32
+ /** The face a named family and weight loads for first text: upright, covering Latin and that weight. */
33
+ export const preloadFace = (faces, { family, weight }) => faces.find(face => face.family === family && face.slant === "normal" && coversLatin(face.range) && (face.auto || face.low <= weight && weight <= face.high));
34
+
30
35
  /** The font and weight of the body and of headings, as base.css sets them. */
31
36
  function firstTextFonts(text, values) {
32
37
  const read = pattern => {
@@ -47,11 +52,14 @@ function firstTextFonts(text, values) {
47
52
  /** The generated module for a project's tokens, or null when no first-text font is a project file. */
48
53
  export function fontPreloadText({ dsRoot, config }, values) {
49
54
  const directory = path.join(dsRoot, config.tokenDir), fontsFile = path.join(directory, "fonts.css"), baseFile = path.join(directory, "base.css");
50
- if (!existsSync(fontsFile) || !existsSync(baseFile)) return null;
55
+ const named = config.assets.preloadFonts;
56
+ if (!existsSync(fontsFile) || !named && !existsSync(baseFile)) return null;
51
57
  let faces, uses;
52
- try { faces = fontFaces(readFileSync(fontsFile, "utf8")); uses = firstTextFonts(readFileSync(baseFile, "utf8"), values); }
58
+ try { faces = fontFaces(readFileSync(fontsFile, "utf8")); uses = named ? [] : firstTextFonts(readFileSync(baseFile, "utf8"), values); }
53
59
  catch { return null; /* The core CSS syntax diagnostic owns malformed sheets. */ }
54
60
  const urls = new Set();
61
+ // Named in the config: exactly these, and font-preload-config reports one fonts.css does not have.
62
+ for (const entry of named ?? []) { const face = preloadFace(faces, entry); if (face) urls.add(face.url); }
55
63
  for (const { family, weight } of uses) {
56
64
  const name = (family ?? "").split(",").map(unquote).find(item => faces.some(face => face.family === item));
57
65
  if (!name) continue;
@@ -63,15 +71,25 @@ export function fontPreloadText({ dsRoot, config }, values) {
63
71
  const list = [...urls], local = url => !/^(?:[a-z]+:)?\/\//i.test(url) && !url.startsWith("/");
64
72
  const type = url => formats[/\.(\w+)(?:[?#].*)?$/.exec(url)?.[1]?.toLowerCase()] ?? "font/woff2";
65
73
  return [
66
- "/* Generated by ADS from fonts.css and base.css: the fonts the first text uses. `ads assets` and the",
74
+ "/* Generated by ADS from fonts.css and base.css or assets.preloadFonts: the fonts the first text uses. `ads assets` and the",
67
75
  " showcase and MCP server rewrite it; do not edit it. Call preloadFonts() in the app entry before",
68
- " the first render. */",
69
- ...list.flatMap((url, index) => local(url) ? [`import font${index} from ${JSON.stringify(`${url.startsWith(".") ? url : `./${url}`}?url`)};`] : []),
76
+ " the first render, or put fontPreloadTags() or fontPreloadHeader() in the page from a build step. */",
77
+ ...list.flatMap((url, index) => local(url) ? [`import font${index} from ${JSON.stringify(url.startsWith(".") ? url : `./${url}`)};`] : []),
70
78
  "",
71
79
  "export const fontPreloads: readonly { readonly href: string; readonly type: string }[] = [",
72
80
  ...list.map((url, index) => ` { href: ${local(url) ? `font${index}` : JSON.stringify(url)}, type: ${JSON.stringify(type(url))} },`),
73
81
  "];",
74
82
  "",
83
+ "/** The same list for a build step or prerender: <link> tags for the page's HTML. */",
84
+ "export function fontPreloadTags(): string {",
85
+ ' return fontPreloads.map(({ href, type }) => `<link rel="preload" href="${href}" as="font" type="${type}" crossorigin="anonymous">`).join("\\n");',
86
+ "}",
87
+ "",
88
+ "/** The same list as a Link header value. */",
89
+ "export function fontPreloadHeader(): string {",
90
+ ' return fontPreloads.map(({ href, type }) => `<${href}>; rel=preload; as=font; type="${type}"; crossorigin=anonymous`).join(", ");',
91
+ "}",
92
+ "",
75
93
  "/** Adds one preload link per font. The crossorigin attribute matches how browsers fetch fonts. */",
76
94
  "export function preloadFonts(): void {",
77
95
  " for (const { href, type } of fontPreloads) {",