@reqvire-org/ads 0.4.2 → 0.4.4
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/README.md +11 -2
- package/dist/a11y.mjs +71 -65
- package/dist/analysis/helpers.mjs +5 -3
- package/dist/analysis/inputs.mjs +13 -6
- package/dist/analysis/module-resolvers.mjs +46 -0
- package/dist/analysis/service.mjs +7 -0
- package/dist/analysis/syntax.mjs +20 -5
- package/dist/assets.mjs +1 -1
- package/dist/boundaries.mjs +6 -4
- package/dist/bun-compiler.mjs +6 -5
- package/dist/check-service.mjs +8 -5
- package/dist/check.mjs +11 -46
- package/dist/component-contrast.mjs +126 -8
- package/dist/contrast-composition.mjs +80 -0
- package/dist/contrast-styles.mjs +88 -0
- package/dist/finding-rules.mjs +2 -0
- package/dist/font-rules.mjs +20 -15
- package/dist/fonts-generated.mjs +21 -14
- package/dist/foundation-views.mjs +6 -2
- package/dist/image-attributes.mjs +96 -92
- package/dist/mcp/build-status.mjs +8 -3
- package/dist/mcp/drafts.mjs +12 -5
- package/dist/mcp/mutations.mjs +11 -8
- package/dist/mcp/preview-widget.bundle.js +45 -45
- package/dist/mcp/resource-loader.js +1 -201
- package/dist/mcp/server.mjs +19 -5
- package/dist/pictogram-model.mjs +59 -0
- package/dist/pictograms.mjs +52 -0
- package/dist/preview-bun.mjs +76 -60
- package/dist/preview-incremental.mjs +358 -0
- package/dist/preview-manifest-update.mjs +70 -0
- package/dist/preview-resources.mjs +33 -1
- package/dist/render-audit/image-shape.mjs +13 -3
- package/dist/render-audit/pictograms.mjs +88 -0
- package/dist/render-audit/worker.mjs +12 -0
- package/dist/render-audit.mjs +11 -1
- package/dist/render-composition.mjs +186 -0
- package/dist/scenario-registry.mjs +2 -2
- package/dist/scenarios-compiler.mjs +1 -1
- package/dist/showcase/client.bundle.js +23 -23
- package/dist/showcase/draft-navigation.js +5 -5
- package/dist/showcase/foundation-view.css +3 -0
- package/dist/showcase/foundation-view.mjs +3 -0
- package/dist/showcase/pictogram-view.mjs +53 -0
- package/dist/showcase/ui/ui.js +2 -0
- package/dist/skills/README.md +1 -1
- package/dist/skills/ads-designer/SKILL.md +18 -2
- package/dist/skills/ads-designer/references/accessibility.md +70 -2
- package/dist/skills/ads-designer/references/branding.md +5 -16
- package/dist/skills/ads-designer/references/performance.md +3 -2
- package/dist/skills/ads-designer/references/pictograms.md +131 -0
- package/dist/skills/ads-designer/references/runtimes.md +15 -0
- package/dist/skills/ads-import/references/runtimes.md +15 -0
- package/dist/skills/ads-migrate/SKILL.md +2 -1
- package/dist/skills/ads-migrate/references/0.4.1-to-0.4.2.md +2 -3
- package/dist/skills/ads-migrate/references/0.4.3-to-0.4.4.md +80 -0
- package/dist/skills/ads-port/SKILL.md +4 -1
- package/dist/skills/ads-port/references/runtimes.md +15 -0
- package/dist/source-values.mjs +4 -1
- package/dist/starters/react/design-system/assets/pictograms/catalog.ads.json +13 -0
- package/dist/starters/react/design-system/assets/pictograms/journey.dark.svg +7 -0
- package/dist/starters/react/design-system/assets/pictograms/journey.svg +7 -0
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.fixture.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.scenario.tsx +7 -0
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.tsx +26 -0
- package/dist/style-token-rules.mjs +51 -0
- package/dist/task-cache.mjs +2 -2
- package/dist/units.mjs +4 -4
- package/dist/validation-inputs.mjs +7 -3
- package/docs/ADS.md +6 -1
- package/docs/ARCHITECTURE.md +144 -16
- package/docs/CACHING.md +65 -1
- package/docs/CHANGELOG.md +86 -50
- package/docs/GUIDE.md +52 -7
- package/docs/MCP.md +47 -16
- package/docs/benchmarks/README.md +1 -1
- package/package.json +7 -4
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Serialized into the preview frame. Identify artwork by bytes, including unmarked
|
|
2
|
+
* imports; a data-ads-pictogram id disambiguates reuse and catches wrong sources.
|
|
3
|
+
* The audit owns/reuses sourceDigests across its viewport samples. */
|
|
4
|
+
export async function pictogramAudit({ pictograms, theme, nodeLimit, sourceDigests = {} }) {
|
|
5
|
+
const root = document.querySelector("#root"), issues = [], counts = {};
|
|
6
|
+
if (!root) return { issues, counts, sourceDigests };
|
|
7
|
+
const byId = new Map(pictograms.map(item => [item.id, item]));
|
|
8
|
+
const byDigest = new Map();
|
|
9
|
+
for (const item of pictograms) for (const asset of Object.values(item.assets)) {
|
|
10
|
+
const entries = byDigest.get(asset.digest) ?? [];
|
|
11
|
+
if (!entries.some(entry => entry.item.id === item.id)) entries.push({ item, asset });
|
|
12
|
+
byDigest.set(asset.digest, entries);
|
|
13
|
+
}
|
|
14
|
+
const selector = element => {
|
|
15
|
+
const parts = [];
|
|
16
|
+
for (let node = element; node && node !== root; node = node.parentElement) {
|
|
17
|
+
const siblings = [...node.parentElement.children].filter(child => child.localName === node.localName);
|
|
18
|
+
parts.unshift(`${node.localName}:nth-of-type(${siblings.indexOf(node) + 1})`);
|
|
19
|
+
}
|
|
20
|
+
return ["#root", ...parts].join(" > ");
|
|
21
|
+
};
|
|
22
|
+
const report = (image, id, reason, message, rule = "pictogram-render") => {
|
|
23
|
+
counts[reason] = (counts[reason] ?? 0) + 1;
|
|
24
|
+
if (counts[reason] <= nodeLimit) issues.push({ rule, selector: image ? selector(image) : "#root", id, reason, message });
|
|
25
|
+
};
|
|
26
|
+
const images = [...root.querySelectorAll(pictograms.length ? "img" : "img[data-ads-pictogram]")];
|
|
27
|
+
if (images.length > 1000) report(null, null, "limit", "Pictogram audit exceeds 1000 images; split the scenario to obtain complete evidence.");
|
|
28
|
+
for (const image of images.slice(0, 1000)) {
|
|
29
|
+
if (!image.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true })) continue;
|
|
30
|
+
const declared = image.getAttribute("data-ads-pictogram"), src = image.currentSrc || image.src;
|
|
31
|
+
if (declared !== null && !byId.has(declared)) { report(image, declared, "unknown", `Unknown pictogram ${declared}. Use an id from assets/pictograms/catalog.ads.json.`); continue; }
|
|
32
|
+
// Ordinary imports are blob URLs. Do not issue extra network requests for
|
|
33
|
+
// unrelated remote images; explicit declarations opt into source checking.
|
|
34
|
+
if (declared === null && !/^(?:blob:|data:image\/svg\+xml[;,])/i.test(src)) continue;
|
|
35
|
+
if (!Object.hasOwn(sourceDigests, src)) {
|
|
36
|
+
try {
|
|
37
|
+
const response = await fetch(src);
|
|
38
|
+
if (!response.ok) throw new Error("Image could not be read");
|
|
39
|
+
if (!/image\/svg\+xml/i.test(response.headers.get("content-type") ?? "") || Number(response.headers.get("content-length")) > 1024 * 1024)
|
|
40
|
+
throw new Error("Not a supported SVG image");
|
|
41
|
+
const bytes = await response.arrayBuffer();
|
|
42
|
+
if (bytes.byteLength > 1024 * 1024) throw new Error("Image exceeds pictogram budget");
|
|
43
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
44
|
+
sourceDigests[src] = [...new Uint8Array(digest)].map(byte => byte.toString(16).padStart(2, "0")).join("");
|
|
45
|
+
} catch { sourceDigests[src] = null; }
|
|
46
|
+
}
|
|
47
|
+
const digest = sourceDigests[src], matches = byDigest.get(digest) ?? [];
|
|
48
|
+
if (declared !== null && !digest) {
|
|
49
|
+
report(image, declared, "source", `${declared}: the SVG source could not be identified. Use a readable SVG import from the catalogue.`);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (declared === null && !matches.length) continue;
|
|
53
|
+
if (declared === null && matches.length > 1) {
|
|
54
|
+
report(image, null, "ambiguous", "Artwork is shared by multiple pictogram ids. Add data-ads-pictogram to select its usage contract.", "pictogram-unresolved");
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const activeTheme = image.closest("[data-theme]")?.getAttribute("data-theme") ?? theme;
|
|
58
|
+
const item = declared === null ? matches[0].item : byId.get(declared), expected = item.assets[item.variants[activeTheme]];
|
|
59
|
+
if (!expected || digest !== expected.digest) {
|
|
60
|
+
report(image, item.id, "theme", `${item.id}: use the declared artwork for theme ${activeTheme}; the displayed source does not match it.`);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (!image.hasAttribute("alt")) report(image, item.id, "alt", `${item.id}: supply meaningful alt text, or alt="" when decorative.`);
|
|
64
|
+
if (!image.complete || !image.naturalWidth) { report(image, item.id, "load", `${item.id}: the artwork did not load.`); continue; }
|
|
65
|
+
const style = getComputedStyle(image), width = image.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight), height = image.clientHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom);
|
|
66
|
+
const ratio = expected.geometry.width / expected.geometry.height;
|
|
67
|
+
const mismatch = Math.abs(width / height / ratio - 1) > 0.03 && Math.abs(width / ratio - height) > 2;
|
|
68
|
+
if (mismatch && ["fill", "cover"].includes(style.objectFit) || style.objectFit === "none" && (width < image.naturalWidth || height < image.naturalHeight))
|
|
69
|
+
report(image, item.id, "shape", `${item.id}: ${Math.round(width)}×${Math.round(height)}px crops or stretches the artwork. Preserve its proportions with height: auto or object-fit: contain.`);
|
|
70
|
+
const drawnHeight = ["contain", "scale-down"].includes(style.objectFit) ? Math.min(height, width / ratio, ...(style.objectFit === "scale-down" ? [image.naturalHeight] : [])) : height;
|
|
71
|
+
if (drawnHeight + 1 < item.minHeight)
|
|
72
|
+
report(image, item.id, "size", `${item.id}: artwork is ${Math.round(drawnHeight)}px high; its catalogue declares a minimum of ${item.minHeight}px.`);
|
|
73
|
+
}
|
|
74
|
+
return { issues, counts, sourceDigests };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function pictogramFindings(runs, scenarios) {
|
|
78
|
+
const files = new Map(scenarios.map(scenario => [scenario.id, scenario.file])), groups = new Map();
|
|
79
|
+
for (const run of runs) for (const issue of run.pictograms ?? []) {
|
|
80
|
+
const key = JSON.stringify([run.scenario, issue.selector, issue.reason, issue.id]);
|
|
81
|
+
let item = groups.get(key);
|
|
82
|
+
if (!item) groups.set(key, item = { rule: issue.rule, severity: issue.rule === "pictogram-unresolved" ? "review" : "error", file: files.get(run.scenario) ?? run.scenario, line: 1, column: 1, source: "ads", scenario: run.scenario, themes: [], brands: [], nodes: [], guidanceUri: "ads://guides/pictograms", message: issue.message });
|
|
83
|
+
if (!item.themes.includes(run.theme)) item.themes.push(run.theme);
|
|
84
|
+
if (run.brand && !item.brands.includes(run.brand)) item.brands.push(run.brand);
|
|
85
|
+
item.nodes.push(issue);
|
|
86
|
+
}
|
|
87
|
+
return [...groups.values()];
|
|
88
|
+
}
|
|
@@ -8,6 +8,7 @@ import { nonTextContrast } from "./non-text-contrast.mjs";
|
|
|
8
8
|
import { layoutOverflow } from "./layout-overflow.mjs";
|
|
9
9
|
import { layoutShift } from "./layout-shift.mjs";
|
|
10
10
|
import { imageShape } from "./image-shape.mjs";
|
|
11
|
+
import { pictogramAudit } from "./pictograms.mjs";
|
|
11
12
|
import { auditRenderStates, listTargets } from "./render-states.mjs";
|
|
12
13
|
|
|
13
14
|
// Runs only as an owned child, using the receiving project's browser dependency.
|
|
@@ -69,6 +70,9 @@ try {
|
|
|
69
70
|
}));
|
|
70
71
|
});
|
|
71
72
|
try {
|
|
73
|
+
// Set before any App mounts, including nested/replaced frames. Only this
|
|
74
|
+
// worker disables decorative subject staging; captures keep showcase chrome.
|
|
75
|
+
await context.addInitScript(() => { globalThis.__ADS_RENDER_AUDIT__ = true; });
|
|
72
76
|
// A bounded number of pages render at once; results keep request order.
|
|
73
77
|
const results = [];
|
|
74
78
|
let next = 0;
|
|
@@ -140,17 +144,25 @@ try {
|
|
|
140
144
|
// The same page is resized: one evaluate per width, no new render.
|
|
141
145
|
result.layout = [];
|
|
142
146
|
result.imageShape = new Map();
|
|
147
|
+
result.pictograms = new Map();
|
|
148
|
+
let sourceDigests = {};
|
|
143
149
|
for (const width of request.overflowWidths) {
|
|
144
150
|
await page.setViewportSize({ width, height: request.viewport.height });
|
|
145
151
|
result.layout.push({ width, ...(await frame.evaluate(layoutOverflow, { nodeLimit: request.nodeLimit, width })) });
|
|
146
152
|
for (const issue of (await frame.evaluate(imageShape, { nodeLimit: request.nodeLimit })).issues)
|
|
147
153
|
result.imageShape.set(issue.selector, { ...issue, width });
|
|
154
|
+
{
|
|
155
|
+
const audit = await frame.evaluate(pictogramAudit, { pictograms: request.pictograms, theme: app.theme, nodeLimit: request.nodeLimit, sourceDigests });
|
|
156
|
+
sourceDigests = audit.sourceDigests;
|
|
157
|
+
for (const issue of audit.issues) result.pictograms.set(`${issue.selector}:${issue.reason}`, { ...issue, width });
|
|
158
|
+
}
|
|
148
159
|
}
|
|
149
160
|
const assigned = await turns[index];
|
|
150
161
|
await auditRenderStates({ page, frame, result, request, phoneWidth: request.overflowWidths[0], assigned });
|
|
151
162
|
if (!contentSettled) result.coverage.skipped.push({ reason: "content-still-changing", name: "the page" });
|
|
152
163
|
result.coverage.claimed = [...assigned.triggers, ...assigned.controls].map((item) => item.claim);
|
|
153
164
|
result.imageShape = [...result.imageShape.values()];
|
|
165
|
+
result.pictograms = [...result.pictograms.values()];
|
|
154
166
|
// Last: it narrows #root for good, at the widest viewport, as a pane in a window would be.
|
|
155
167
|
// A scenario with the main landmark is a whole page, which no pane hosts.
|
|
156
168
|
if (app.container && !(await frame.evaluate(() => !!document.querySelector('main, [role="main"]')))) {
|
package/dist/render-audit.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import { inspectScenarios } from "./scenarios.mjs";
|
|
|
12
12
|
import { inspectUnits } from "./units.mjs";
|
|
13
13
|
import { globMatcher } from "./layout-widths.mjs";
|
|
14
14
|
import { affectedScenarios } from "./verification.mjs";
|
|
15
|
+
import { pictogramFindings } from "./render-audit/pictograms.mjs";
|
|
15
16
|
|
|
16
17
|
// Render audit: axe-core (Deque, MPL-2.0, an unmodified ADS dependency
|
|
17
18
|
// injected at run time, never bundled) runs inside each rendered scenario document, once per
|
|
@@ -555,7 +556,7 @@ async function warmScenariosApart(host, ids, signal) {
|
|
|
555
556
|
|
|
556
557
|
/** One browser process over the given renders. Its report grows as they finish, so a worker that
|
|
557
558
|
* dies keeps what it finished. A browser that is not installed stops the audit. */
|
|
558
|
-
async function runAuditWorker({ root, temporary, playwright, settings, apps, signal, claimed, pages }) {
|
|
559
|
+
async function runAuditWorker({ root, temporary, playwright, settings, apps, signal, claimed, pages, pictograms }) {
|
|
559
560
|
const request = path.join(temporary, "request.json"),
|
|
560
561
|
report = path.join(temporary, "report.json"),
|
|
561
562
|
runId = randomUUID();
|
|
@@ -580,6 +581,7 @@ async function runAuditWorker({ root, temporary, playwright, settings, apps, sig
|
|
|
580
581
|
nodeLimit: limits.nodes,
|
|
581
582
|
concurrency: pages,
|
|
582
583
|
apps,
|
|
584
|
+
pictograms,
|
|
583
585
|
output: temporary,
|
|
584
586
|
}),
|
|
585
587
|
);
|
|
@@ -664,6 +666,12 @@ export async function runRenderAudit(
|
|
|
664
666
|
{ code: "ADS_AUDIT_UNAVAILABLE" },
|
|
665
667
|
);
|
|
666
668
|
const registry = await analyze(root, "registry", [], signal);
|
|
669
|
+
// Registry discovery already checked the captured SVGs. Send only their
|
|
670
|
+
// identity/geometry, not another copy of the artwork or a live filesystem read.
|
|
671
|
+
const pictograms = registry.scenarios.filter(item => item.foundation?.pictogram).map(({ foundation: { pictogram } }) => ({
|
|
672
|
+
id: pictogram.id, minHeight: pictogram.minHeight, variants: pictogram.variants,
|
|
673
|
+
assets: Object.fromEntries(Object.entries(pictogram.assets).map(([name, asset]) => [name, { digest: asset.digest, geometry: asset.geometry }])),
|
|
674
|
+
}));
|
|
667
675
|
if (registry.diagnostics.length) throw new Error(`Scenario registration failed: ${registry.diagnostics[0].message}`);
|
|
668
676
|
const unknown = (selected ?? []).filter((id) => !registry.scenarios.some((scenario) => scenario.id === id));
|
|
669
677
|
if (unknown.length) throw new Error(`Unknown scenario ${unknown[0]}. Discover exact IDs with ads_scenarios.`);
|
|
@@ -755,6 +763,7 @@ export async function runRenderAudit(
|
|
|
755
763
|
apps,
|
|
756
764
|
signal,
|
|
757
765
|
pages: options.config.mcp.auditPages,
|
|
766
|
+
pictograms,
|
|
758
767
|
claimed: [...renders.values()].flatMap((render) => render.result?.coverage?.claimed ?? []),
|
|
759
768
|
})
|
|
760
769
|
: { runs: [], capped: [] };
|
|
@@ -794,6 +803,7 @@ export async function runRenderAudit(
|
|
|
794
803
|
...layoutOverflowFindings(runs, scenarios),
|
|
795
804
|
...layoutShiftFindings(runs, scenarios),
|
|
796
805
|
...imageShapeFindings(runs, scenarios),
|
|
806
|
+
...pictogramFindings(runs, scenarios),
|
|
797
807
|
...unauditedFindings(
|
|
798
808
|
all.filter((render) => !render.result),
|
|
799
809
|
scenarios,
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import ts from "./analysis/syntax.mjs";
|
|
2
|
+
import { memoProgram, walk, symbolAt, valueSymbolAt } from "./analysis/helpers.mjs";
|
|
3
|
+
import { isInside, isDevelopmentFile, isTestFile } from "./config.mjs";
|
|
4
|
+
import { createSourceValues, reference, isFunction } from "./source-values.mjs";
|
|
5
|
+
|
|
6
|
+
/** Source-only DOM relationships. Owned by the immutable program, not live paths.
|
|
7
|
+
* Rules consume these facts without constructing another compiler or executing UI.
|
|
8
|
+
* Uncertain branches stay uncertain: a sampled render is never proof of a cascade. */
|
|
9
|
+
export function renderComposition(program, options) {
|
|
10
|
+
return memoProgram(program, `render-composition:${options.dsRoot}`, () => build(program, options));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function build(program, options) {
|
|
14
|
+
const checker = program.getTypeChecker(), bindings = new Map();
|
|
15
|
+
async function linaria(node, seen = new Set()) {
|
|
16
|
+
if (!node || seen.has(node)) return null;
|
|
17
|
+
if (bindings.has(node)) return bindings.get(node);
|
|
18
|
+
seen.add(node);
|
|
19
|
+
const base = ts.isPropertyAccessExpression(node) ? node.expression : node;
|
|
20
|
+
// Preserve import declarations here; unaliasing would lose the package name.
|
|
21
|
+
const symbol = await symbolAt(checker, base);
|
|
22
|
+
for (const decl of symbol?.declarations ?? []) {
|
|
23
|
+
if (ts.isImportSpecifier(decl) && ["@linaria/atomic", "@linaria/core"].includes(decl.parent.parent.parent.moduleSpecifier.text)) {
|
|
24
|
+
const result = (decl.propertyName ?? decl.name).text;
|
|
25
|
+
bindings.set(node, result);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
if (ts.isNamespaceImport(decl) && ts.isPropertyAccessExpression(node) && ["@linaria/atomic", "@linaria/core"].includes(decl.parent.parent.moduleSpecifier.text)) {
|
|
29
|
+
bindings.set(node, node.name.text);
|
|
30
|
+
return node.name.text;
|
|
31
|
+
}
|
|
32
|
+
if (ts.isVariableDeclaration(decl) && decl.initializer && decl.parent.flags & ts.NodeFlags.Const) return linaria(decl.initializer, seen);
|
|
33
|
+
}
|
|
34
|
+
bindings.set(node, null);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const isCx = async node => await linaria(node) === "cx";
|
|
38
|
+
const values = createSourceValues(program, options, { preserveCall: isCx, strict: true });
|
|
39
|
+
const roots = [], nodes = [], limits = new Map();
|
|
40
|
+
const limit = (node, reason) => { if (!limits.has(reason)) limits.set(reason, { node, reason }); };
|
|
41
|
+
|
|
42
|
+
async function classes(input, context) {
|
|
43
|
+
const value = await values.resolve(input, values.next(context));
|
|
44
|
+
context = value.context ?? input.context ?? context;
|
|
45
|
+
if (value.kind === "literal") return !value.value || typeof value.value === "string"
|
|
46
|
+
? { templates: [], names: typeof value.value === "string" ? value.value.split(/\s+/).filter(Boolean) : [] }
|
|
47
|
+
: { templates: [], names: [], reason: "A class value is not a string." };
|
|
48
|
+
if (value.kind === "union") {
|
|
49
|
+
const alternatives = [];
|
|
50
|
+
if (value.values.length > 64) return { templates: [], names: [], reason: "Class composition exceeds 64 alternatives." };
|
|
51
|
+
for (const item of value.values) alternatives.push(await classes(item, values.next(context)));
|
|
52
|
+
const first = alternatives[0];
|
|
53
|
+
if (first && alternatives.every(item => !item.reason && !item.choices?.length && item.templates.length === first.templates.length && item.templates.every((template, i) => template === first.templates[i]) && item.names.join(" ") === first.names.join(" "))) return first;
|
|
54
|
+
return { templates: [], names: [], choices: [alternatives] };
|
|
55
|
+
}
|
|
56
|
+
if (value.kind === "node") {
|
|
57
|
+
if (ts.isTaggedTemplateExpression(value.node) && await linaria(value.node.tag) === "css") return { templates: [value.node], names: [] };
|
|
58
|
+
if (ts.isCallExpression(value.node) && await isCx(value.node.expression)) {
|
|
59
|
+
const result = { templates: [], names: [], choices: [] };
|
|
60
|
+
for (const argument of value.node.arguments) {
|
|
61
|
+
const items = ts.isSpreadElement(argument)
|
|
62
|
+
? await values.arrays(reference(argument.expression, value.env, value.via), values.next(context))
|
|
63
|
+
: [reference(argument, value.env, value.via)];
|
|
64
|
+
if (!items) { result.reason = "A class argument spread cannot be resolved."; continue; }
|
|
65
|
+
for (const item of items) {
|
|
66
|
+
const part = await classes(item, values.next(context));
|
|
67
|
+
result.templates.push(...part.templates); result.names.push(...part.names);
|
|
68
|
+
result.choices.push(...(part.choices ?? []));
|
|
69
|
+
result.reason ??= part.reason;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return { templates: [], names: [], reason: value.reason ?? "A class or later prop spread cannot be resolved." };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const textTypes = new Map();
|
|
79
|
+
async function textSlot(input) {
|
|
80
|
+
const node = input?.node;
|
|
81
|
+
if (!node || !ts.isIdentifier(node) && !ts.isPropertyAccessExpression(node) && !ts.isElementAccessExpression(node)) return false;
|
|
82
|
+
if (!textTypes.has(node)) textTypes.set(node, (async () => {
|
|
83
|
+
const type = await checker.getTypeAtLocation(node), parts = type?.isUnion() ? type.types : [type];
|
|
84
|
+
const text = ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike;
|
|
85
|
+
const absent = ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.BooleanLike;
|
|
86
|
+
return parts.some(part => part?.flags & text) && parts.every(part => part?.flags & (text | absent));
|
|
87
|
+
})());
|
|
88
|
+
return textTypes.get(node);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function render(input, parent, context, sites = new Set(), uncertain = false) {
|
|
92
|
+
if (nodes.length >= 20000 || context.depth > 48 || context.budget.steps > 16000) {
|
|
93
|
+
limit(input.node ?? parent?.node, "Render composition reached its depth or work limit.");
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const value = await values.resolve(input, values.next(context));
|
|
97
|
+
context = value.context ?? input.context ?? context;
|
|
98
|
+
if (value.kind === "union") {
|
|
99
|
+
if (value.values.length > 64) { limit(input.node ?? parent?.node, "Render composition exceeds 64 alternatives."); return; }
|
|
100
|
+
for (const branch of value.values) await render(branch, parent, values.next(context), sites, true);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (value.kind === "array") {
|
|
104
|
+
for (const child of value.values) await render(child, parent, values.next(context), sites, uncertain);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (value.kind === "literal") {
|
|
108
|
+
if (parent && (typeof value.value === "number" || typeof value.value === "string" && value.value.trim())) parent.text = true;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (value.kind !== "node") {
|
|
112
|
+
// A typed text slot needs readable paint for its supplied text. Arbitrary
|
|
113
|
+
// children, failed resolution and bounded-analysis limits remain unknown.
|
|
114
|
+
if (parent && value.kind === "unknown" && !value.reason && await textSlot(input)) { parent.text = true; return; }
|
|
115
|
+
if (parent) parent.unknownText = value.reason ?? "Dynamic children cannot be established as text.";
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const { node, env, via } = value;
|
|
119
|
+
if (ts.isJsxText(node)) { if (parent && node.text.trim()) parent.text = true; return; }
|
|
120
|
+
if (ts.isJsxExpression(node)) return render(reference(node.expression, env, via), parent, values.next(context), sites, uncertain);
|
|
121
|
+
if (ts.isJsxFragment(node) || ts.isArrayLiteralExpression(node)) {
|
|
122
|
+
for (const child of node.children ?? node.elements) {
|
|
123
|
+
if (ts.isSpreadElement(child)) {
|
|
124
|
+
const items = await values.arrays(reference(child.expression, env, via), values.next(context));
|
|
125
|
+
if (!items) { if (parent) parent.unknownText = "Dynamic render array cannot be resolved."; continue; }
|
|
126
|
+
for (const item of items) await render(item, parent, values.next(context), sites, uncertain);
|
|
127
|
+
} else await render(reference(child, env, via), parent, values.next(context), sites, uncertain);
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (!ts.isJsxElement(node) && !ts.isJsxSelfClosingElement(node)) {
|
|
132
|
+
if (parent) parent.unknownText = "The rendered child is outside source-resolvable JSX.";
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const opening = ts.isJsxElement(node) ? node.openingElement : node;
|
|
136
|
+
const props = values.props(opening, env, via);
|
|
137
|
+
if (ts.isJsxElement(node) && node.children.length) props.layers.push(new Map([["children", { kind: "array", values: node.children.map(child => reference(child, env, via)) }]]));
|
|
138
|
+
const property = async name => values.resolve(await values.get(props, name, values.next(context)), values.next(context));
|
|
139
|
+
const tag = opening.tagName.getText();
|
|
140
|
+
if (/^[a-z][\w-]*$/.test(tag)) {
|
|
141
|
+
// SVG paint, metadata and raw HTML have different text/render semantics.
|
|
142
|
+
// Their accessibility remains with the existing asset and browser guards.
|
|
143
|
+
if (["svg", "script", "style", "template", "title", "progress", "meter"].includes(tag)) return;
|
|
144
|
+
let classValue = await values.get(props, "className", values.next(context));
|
|
145
|
+
if (classValue.kind === "literal" && classValue.value === undefined) classValue = await values.get(props, "class", values.next(context));
|
|
146
|
+
const item = { node: opening, parent, tag, classes: await classes(classValue, context), children: [], text: false, uncertain, via, attributes: {} };
|
|
147
|
+
for (const name of ["style", "disabled", "aria-disabled", "hidden", "dangerouslySetInnerHTML"]) item.attributes[name] = await property(name);
|
|
148
|
+
nodes.push(item);
|
|
149
|
+
if (parent) parent.children.push(item); else roots.push(item);
|
|
150
|
+
await render(await values.get(props, "children", values.next(context)), item, values.next(context), sites, uncertain);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
// Fragments do not introduce a backdrop. Other external components (including
|
|
154
|
+
// portals) are boundaries, not transparent wrappers guessed from their names.
|
|
155
|
+
const symbol = await valueSymbolAt(checker, opening.tagName);
|
|
156
|
+
if (symbol?.name === "Fragment" && symbol.declarations?.every(decl => decl.getSourceFile().fileName.includes("/node_modules/")))
|
|
157
|
+
return render(await values.get(props, "children", values.next(context)), parent, values.next(context), sites, uncertain);
|
|
158
|
+
const target = await values.resolve(reference(opening.tagName, env, via), values.next(context));
|
|
159
|
+
if (target.kind !== "node" || !isFunction(target.node) || sites.has(node) || isDevelopmentFile(target.node.getSourceFile().fileName, options)) {
|
|
160
|
+
if (parent) parent.unknownText = `Component ${tag} cannot be traced to owned DOM here.`;
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const nested = new Set([...sites, node]);
|
|
164
|
+
const outputs = await values.returns(target, [props], values.next(context), "component");
|
|
165
|
+
for (const output of outputs) await render(output, parent, values.next(context), nested, uncertain || outputs.length > 1);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
for (const source of await program.getSourceFiles()) {
|
|
169
|
+
if (!isInside(options.dsRoot, source.fileName) || source.isDeclarationFile || isDevelopmentFile(source.fileName, options) || isTestFile(source.fileName)) continue;
|
|
170
|
+
const sites = [];
|
|
171
|
+
walk(source, node => {
|
|
172
|
+
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node)) { sites.push(node); return false; }
|
|
173
|
+
});
|
|
174
|
+
for (const node of sites) await render(reference(node), null, { ...values.state(), maxSteps: 16000 });
|
|
175
|
+
}
|
|
176
|
+
function freezeClasses(classes) {
|
|
177
|
+
Object.freeze(classes.templates); Object.freeze(classes.names);
|
|
178
|
+
for (const choice of classes.choices ?? []) { choice.forEach(freezeClasses); Object.freeze(choice); }
|
|
179
|
+
if (classes.choices) Object.freeze(classes.choices);
|
|
180
|
+
Object.freeze(classes);
|
|
181
|
+
}
|
|
182
|
+
for (const item of nodes) {
|
|
183
|
+
freezeClasses(item.classes); Object.freeze(item.children); Object.freeze(item.attributes); Object.freeze(item);
|
|
184
|
+
}
|
|
185
|
+
return Object.freeze({ roots: Object.freeze(roots), nodes: Object.freeze(nodes), limits: Object.freeze([...limits.values()]) });
|
|
186
|
+
}
|
|
@@ -51,10 +51,10 @@ function validRegistry(value, options) {
|
|
|
51
51
|
value.scenarios.every(
|
|
52
52
|
(item) =>
|
|
53
53
|
typeof item?.id === "string" &&
|
|
54
|
-
/^(?:brand|tokens|components|patterns|composition)\/[\w./-]+$/.test(item.id) &&
|
|
54
|
+
/^(?:brand|pictograms|tokens|components|patterns|composition)\/[\w./-]+$/.test(item.id) &&
|
|
55
55
|
path.posix.normalize(item.id) === item.id &&
|
|
56
56
|
typeof item.title === "string" &&
|
|
57
|
-
["brand", "tokens", "components", "patterns", "composition"].includes(item.kind) &&
|
|
57
|
+
["brand", "pictograms", "tokens", "components", "patterns", "composition"].includes(item.kind) &&
|
|
58
58
|
typeof item.file === "string" &&
|
|
59
59
|
isInside(options.dsRoot, path.resolve(options.root, item.file)) &&
|
|
60
60
|
item.artifact === `.ds/scenarios/${item.id}/index.html` &&
|
|
@@ -257,7 +257,7 @@ export function createPreviewCache(options, compilerFiles = []) {
|
|
|
257
257
|
const valid = value.registry.every(
|
|
258
258
|
(entry) =>
|
|
259
259
|
typeof entry?.id === "string" &&
|
|
260
|
-
/^(?:brand|tokens|components|patterns|composition)\/[\w./-]+$/.test(entry.id) &&
|
|
260
|
+
/^(?:brand|pictograms|tokens|components|patterns|composition)\/[\w./-]+$/.test(entry.id) &&
|
|
261
261
|
path.posix.normalize(entry.id) === entry.id &&
|
|
262
262
|
typeof entry.file === "string" &&
|
|
263
263
|
isInside(options.dsRoot, path.resolve(root, entry.file)) &&
|