@reqvire-org/ads 0.4.2 → 0.4.3

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.
Files changed (62) hide show
  1. package/README.md +10 -1
  2. package/dist/a11y.mjs +71 -65
  3. package/dist/analysis/helpers.mjs +5 -3
  4. package/dist/analysis/inputs.mjs +13 -6
  5. package/dist/analysis/module-resolvers.mjs +46 -0
  6. package/dist/analysis/service.mjs +7 -0
  7. package/dist/analysis/syntax.mjs +20 -5
  8. package/dist/assets.mjs +1 -1
  9. package/dist/boundaries.mjs +6 -4
  10. package/dist/check-service.mjs +8 -5
  11. package/dist/check.mjs +8 -3
  12. package/dist/component-contrast.mjs +126 -8
  13. package/dist/contrast-composition.mjs +134 -0
  14. package/dist/finding-rules.mjs +2 -0
  15. package/dist/font-rules.mjs +20 -15
  16. package/dist/fonts-generated.mjs +21 -14
  17. package/dist/foundation-views.mjs +6 -2
  18. package/dist/image-attributes.mjs +96 -92
  19. package/dist/mcp/drafts.mjs +6 -4
  20. package/dist/mcp/mutations.mjs +11 -8
  21. package/dist/mcp/preview-widget.bundle.js +43 -43
  22. package/dist/mcp/server.mjs +9 -2
  23. package/dist/pictogram-model.mjs +59 -0
  24. package/dist/pictograms.mjs +52 -0
  25. package/dist/preview-bun.mjs +1 -0
  26. package/dist/render-audit/image-shape.mjs +13 -3
  27. package/dist/render-audit/pictograms.mjs +88 -0
  28. package/dist/render-audit/worker.mjs +12 -0
  29. package/dist/render-audit.mjs +11 -1
  30. package/dist/render-composition.mjs +164 -0
  31. package/dist/scenario-registry.mjs +2 -2
  32. package/dist/scenarios-compiler.mjs +1 -1
  33. package/dist/showcase/client.bundle.js +23 -23
  34. package/dist/showcase/draft-navigation.js +5 -5
  35. package/dist/showcase/foundation-view.css +3 -0
  36. package/dist/showcase/foundation-view.mjs +3 -0
  37. package/dist/showcase/pictogram-view.mjs +53 -0
  38. package/dist/showcase/ui/ui.js +2 -0
  39. package/dist/skills/ads-designer/SKILL.md +13 -1
  40. package/dist/skills/ads-designer/references/accessibility.md +66 -2
  41. package/dist/skills/ads-designer/references/branding.md +5 -16
  42. package/dist/skills/ads-designer/references/performance.md +3 -2
  43. package/dist/skills/ads-designer/references/pictograms.md +131 -0
  44. package/dist/skills/ads-port/SKILL.md +4 -1
  45. package/dist/source-values.mjs +4 -1
  46. package/dist/starters/react/design-system/assets/pictograms/catalog.ads.json +13 -0
  47. package/dist/starters/react/design-system/assets/pictograms/journey.dark.svg +7 -0
  48. package/dist/starters/react/design-system/assets/pictograms/journey.svg +7 -0
  49. package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.exports.ts +1 -0
  50. package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.fixture.ts +1 -0
  51. package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.scenario.tsx +7 -0
  52. package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.tsx +26 -0
  53. package/dist/task-cache.mjs +2 -2
  54. package/dist/units.mjs +4 -4
  55. package/dist/validation-inputs.mjs +7 -3
  56. package/docs/ADS.md +6 -1
  57. package/docs/ARCHITECTURE.md +75 -2
  58. package/docs/CACHING.md +25 -0
  59. package/docs/CHANGELOG.md +75 -52
  60. package/docs/GUIDE.md +30 -5
  61. package/docs/MCP.md +6 -0
  62. package/package.json +2 -1
package/README.md CHANGED
@@ -82,6 +82,7 @@ There is no warning level.
82
82
  | **Themes and brands** | One mechanism: per-theme halves (`--x-light`, `--x-dark`) and brands on `[data-brand]`. `ads assets` generates `themes.generated.css` and `.ts`; missing or conflicting halves, empty themes, stale generated files, `light-dark()` and ancestor theme selectors are errors. |
83
83
  | **Tokens** | Ownership, naming, rhythm, missing references and the token catalogue (`catalog.ads.json`); equal values in different roles are flagged for review. |
84
84
  | **Architecture** | Data, UX and Skin ownership, project structure, unit and paint contracts, binding and variable ownership; Linaria atomic composition risks are flagged for review. |
85
+ | **Pictograms** | Catalogue, SVG geometry and theme coverage; rendered images preserve the declared variant, minimum size and proportions. Fixed colors and gradients are allowed. |
85
86
  | **Brand assets and glyphs** | Brand coverage, licenses and READMEs; glyph viewBox, color and alias rules. |
86
87
  | **Behavior** | Registered guarantees need current passing execution evidence; `ads verify` runs them against current source. |
87
88
  | **Two gates** | Draft acceptance runs `ads check`, `acceptance.scripts`, and the draft owners' own behavior tests and render audit. `ads validate` runs `ads check`, `acceptance.scripts` then `validation.scripts`, and every behavior test and render audit its change set reaches; `--changed` narrows that to what changed since the last full run. |
@@ -234,7 +235,7 @@ Clients without Apps can inspect text/resources and use the regular showcase.
234
235
  ## Showcase
235
236
 
236
237
  The showcase is **a minimal shell plus an MCP client and Apps host**. It ships
237
- with ADS tooling. Brand, Tokens, Components, Patterns and Composition share its header,
238
+ with ADS tooling. Brand, Icons, Pictograms, Tokens, Components, Patterns and Composition share its header,
238
239
  collapsible left menu, theme and brand switches and preview area; an Icons tab shows the
239
240
  glyph set. Lists come from MCP results;
240
241
  selecting an entry renders its real scenario inside one reusable MCP App. The
@@ -293,6 +294,14 @@ of production. Full-app harnesses belong in application tests. See the
293
294
  [architecture](docs/ARCHITECTURE.md#the-showcase-is-the-shared-design-workspace),
294
295
  [contract](docs/ADS.md#showcase-contract) and [setup guide](docs/GUIDE.md#showcase).
295
296
 
297
+ ## Pictograms
298
+
299
+ Illustrative SVG artwork has its own `assets/pictograms/` owner and showcase section,
300
+ separate from logos and UI icons. Its catalogue declares theme variants, intended
301
+ use and a project-selected minimum size. The shared starter includes an original
302
+ Journey example and renderer. See the [pictogram guide](skills/ads-designer/references/pictograms.md)
303
+ for the format, artistic freedom and check boundaries.
304
+
296
305
  ## Branding
297
306
 
298
307
  Change values in `design-system/tokens/`, keeping the
package/dist/a11y.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { existsSync, readFileSync } from "node:fs";
2
1
  import path from "node:path";
3
2
  import ts from "./analysis/syntax.mjs";
4
- import { isDevelopmentFile, isInside, sourceFiles } from "./config.mjs";
3
+ import { isDevelopmentFile, isInside } from "./config.mjs";
5
4
  import { parseColor } from "./token-quality.mjs";
6
5
  import { baseDefinition } from "./themes.mjs";
7
6
  import { findingSeverity } from "./finding-rules.mjs";
7
+ import { sourceAst, optionalSourceText, memoProgram } from "./analysis/helpers.mjs";
8
8
 
9
9
  // Accessibility guards ADS can check without a browser: token values (WCAG target size,
10
10
  // focus, text resize, reduced motion, text spacing) and runtime component source (text
@@ -83,7 +83,8 @@ export function a11yTokenAdvisories(tokens, { foundationFile, root } = {}) {
83
83
  advisories.push(advisory("a11y-text-spacing", root, `--content-max is ${match[1]}ch; keep text lines under 80 characters (WCAG 1.4.8).`, [token.name]));
84
84
  }
85
85
  }
86
- if (foundationFile && existsSync(foundationFile) && !/:focus-visible\b/.test(readFileSync(foundationFile, "utf8"))) {
86
+ const foundation = foundationFile ? optionalSourceText(foundationFile) : null;
87
+ if (foundation !== null && !/:focus-visible\b/.test(foundation)) {
87
88
  advisories.push(
88
89
  advisory(
89
90
  "a11y-focus",
@@ -99,10 +100,10 @@ const nonInteractive = new Set(["div", "span", "p", "li", "section", "article",
99
100
  // Children of composite widgets: the container owns focus (aria-activedescendant or roving).
100
101
  const managedRoles = new Set(["option", "menuitem", "menuitemcheckbox", "menuitemradio", "tab", "treeitem", "row", "gridcell"]);
101
102
  /** Source guards over runtime components and patterns (not previews, fixtures or tests). */
102
- export async function a11ySourceAdvisories({ root, dsRoot }) {
103
+ export async function a11ySourceAdvisories({ root, dsRoot }, sources) {
103
104
  const advisories = [];
104
105
  const options = { root, dsRoot };
105
- const files = sourceFiles(dsRoot).filter(
106
+ const files = sources.filter(
106
107
  (file) =>
107
108
  /\.[jt]sx$/.test(file) &&
108
109
  ["components", "patterns"].some((layer) => isInside(path.join(dsRoot, layer), file)) &&
@@ -110,72 +111,77 @@ export async function a11ySourceAdvisories({ root, dsRoot }) {
110
111
  !/\.test\.|\.spec\./.test(file),
111
112
  );
112
113
  for (const file of files) {
113
- const text = readFileSync(file, "utf8"),
114
- relative = path.relative(root, file).replaceAll("\\", "/");
115
- const source = await ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
116
- const at = (node) => {
117
- const { line, character } = source.getLineAndCharacterOfPosition(node.getStart(source));
118
- return { file: relative, line: line + 1, column: character + 1 };
119
- };
120
- const visit = (node) => {
121
- if (ts.isJsxSelfClosingElement(node) || ts.isJsxOpeningElement(node)) {
122
- const tag = node.tagName.getText(source);
123
- const attributes = node.attributes.properties;
124
- const spread = attributes.some(ts.isJsxSpreadAttribute);
125
- const names = new Set(attributes.filter(ts.isJsxAttribute).map((attribute) => attribute.name.getText(source)));
126
- if (tag === "img" && !spread && !names.has("alt"))
127
- advisories.push(advisory("a11y-image-alt", at(node), `<img> needs alt text, or alt="" when it is decorative (WCAG 1.1.1).`));
128
- // A button or link whose only content is an icon, SVG or image has no accessible name.
129
- if (
130
- ts.isJsxOpeningElement(node) &&
131
- ["button", "a"].includes(tag) &&
132
- !spread &&
133
- !["aria-label", "aria-labelledby", "title"].some((name) => names.has(name))
134
- ) {
135
- const children = node.parent.children.filter((child) => !(ts.isJsxText(child) && !child.text.trim()));
136
- const graphic = (child) =>
137
- ts.isJsxSelfClosingElement(child) &&
138
- (/Icon|Glyph|Svg/i.test(child.tagName.getText(source)) || ["svg", "img"].includes(child.tagName.getText(source)));
139
- if (children.length && children.every(graphic))
140
- advisories.push(
141
- advisory(
142
- "a11y-icon-label",
143
- at(node),
144
- `<${tag}> shows only an icon and has no accessible name; add aria-label (or use IconButton with a label) (WCAG 4.1.2).`,
145
- ),
146
- );
147
- }
148
- const attribute = (name) => attributes.find((item) => ts.isJsxAttribute(item) && item.name.getText(source) === name);
149
- const role = attribute("role")
150
- ?.initializer?.getText(source)
151
- .replace(/^["'{]+|["'}]+$/g, "");
152
- // A backdrop that closes on its own click repeats Escape; it is not the keyboard path.
153
- const backdrop = /currentTarget/.test(attribute("onClick")?.getText(source) ?? "");
154
- if (nonInteractive.has(tag) && !spread && names.has("onClick") && !backdrop && !managedRoles.has(role) && !(role && names.has("tabIndex"))) {
114
+ const source = await sourceAst(file), relative = path.relative(root, file).replaceAll("\\", "/");
115
+ advisories.push(...memoProgram(source, `a11y-source:${relative}`, () => sourceAdvisories(source, relative)));
116
+ }
117
+ return advisories;
118
+ }
119
+
120
+ /** These facts depend only on this immutable source tree, not tokens or callers. */
121
+ function sourceAdvisories(source, relative) {
122
+ const advisories = [], text = source.text;
123
+ const at = (node) => {
124
+ const { line, character } = source.getLineAndCharacterOfPosition(node.getStart(source));
125
+ return { file: relative, line: line + 1, column: character + 1 };
126
+ };
127
+ const visit = (node) => {
128
+ if (ts.isJsxSelfClosingElement(node) || ts.isJsxOpeningElement(node)) {
129
+ const tag = node.tagName.getText(source);
130
+ const attributes = node.attributes.properties;
131
+ const spread = attributes.some(ts.isJsxSpreadAttribute);
132
+ const names = new Set(attributes.filter(ts.isJsxAttribute).map((attribute) => attribute.name.getText(source)));
133
+ if (tag === "img" && !spread && !names.has("alt"))
134
+ advisories.push(advisory("a11y-image-alt", at(node), `<img> needs alt text, or alt="" when it is decorative (WCAG 1.1.1).`));
135
+ // A button or link whose only content is an icon, SVG or image has no accessible name.
136
+ if (
137
+ ts.isJsxOpeningElement(node) &&
138
+ ["button", "a"].includes(tag) &&
139
+ !spread &&
140
+ !["aria-label", "aria-labelledby", "title"].some((name) => names.has(name))
141
+ ) {
142
+ const children = node.parent.children.filter((child) => !(ts.isJsxText(child) && !child.text.trim()));
143
+ const graphic = (child) =>
144
+ ts.isJsxSelfClosingElement(child) &&
145
+ (/Icon|Glyph|Svg/i.test(child.tagName.getText(source)) || ["svg", "img"].includes(child.tagName.getText(source)));
146
+ if (children.length && children.every(graphic))
155
147
  advisories.push(
156
148
  advisory(
157
- "a11y-keyboard",
149
+ "a11y-icon-label",
158
150
  at(node),
159
- `<${tag} onClick> cannot be reached or used from the keyboard; use a <button>, or add role, tabIndex and a key handler (WCAG 2.1.1).`,
151
+ `<${tag}> shows only an icon and has no accessible name; add aria-label (or use IconButton with a label) (WCAG 4.1.2).`,
160
152
  ),
161
153
  );
162
- }
163
154
  }
164
- ts.forEachChild(node, visit);
165
- };
166
- visit(source);
167
- // Motion that never stops must yield to the reader's reduced-motion setting.
168
- if (/animation(?:-iteration-count)?\s*:[^;`]*\binfinite\b/.test(text) && !/prefers-reduced-motion/.test(text)) {
169
- const index = text.search(/\binfinite\b/),
170
- line = text.slice(0, index).split("\n").length;
171
- advisories.push(
172
- advisory(
173
- "a11y-reduced-motion",
174
- { file: relative, line },
175
- "An infinite animation runs without a prefers-reduced-motion guard; stop it under @media (prefers-reduced-motion: reduce), or let the user pause it (WCAG 2.2.2, 2.3.3).",
176
- ),
177
- );
155
+ const attribute = (name) => attributes.find((item) => ts.isJsxAttribute(item) && item.name.getText(source) === name);
156
+ const role = attribute("role")
157
+ ?.initializer?.getText(source)
158
+ .replace(/^["'{]+|["'}]+$/g, "");
159
+ // A backdrop that closes on its own click repeats Escape; it is not the keyboard path.
160
+ const backdrop = /currentTarget/.test(attribute("onClick")?.getText(source) ?? "");
161
+ if (nonInteractive.has(tag) && !spread && names.has("onClick") && !backdrop && !managedRoles.has(role) && !(role && names.has("tabIndex"))) {
162
+ advisories.push(
163
+ advisory(
164
+ "a11y-keyboard",
165
+ at(node),
166
+ `<${tag} onClick> cannot be reached or used from the keyboard; use a <button>, or add role, tabIndex and a key handler (WCAG 2.1.1).`,
167
+ ),
168
+ );
169
+ }
178
170
  }
171
+ ts.forEachChild(node, visit);
172
+ };
173
+ visit(source);
174
+ // Motion that never stops must yield to the reader's reduced-motion setting.
175
+ if (/animation(?:-iteration-count)?\s*:[^;`]*\binfinite\b/.test(text) && !/prefers-reduced-motion/.test(text)) {
176
+ const index = text.search(/\binfinite\b/),
177
+ line = text.slice(0, index).split("\n").length;
178
+ advisories.push(
179
+ advisory(
180
+ "a11y-reduced-motion",
181
+ { file: relative, line },
182
+ "An infinite animation runs without a prefers-reduced-motion guard; stop it under @media (prefers-reduced-motion: reduce), or let the user pause it (WCAG 2.2.2, 2.3.3).",
183
+ ),
184
+ );
179
185
  }
180
- return advisories;
186
+ return Object.freeze(advisories.map(Object.freeze));
181
187
  }
@@ -25,7 +25,8 @@ export function optionalSourceText(file) {
25
25
  const context = currentAnalysis();
26
26
  file = path.resolve(file);
27
27
  if (context?.readText && file.startsWith(context.root + path.sep) && !file.includes(`${path.sep}node_modules${path.sep}`)) {
28
- return context.readText(file) ?? null;
28
+ const read = () => context.readText(file) ?? null, key = `text:${file}`;
29
+ return memoFact(context, key, () => context.revision ? memoProgram(context.revision, key, read) : read());
29
30
  }
30
31
  try { return readFileSync(file, "utf8"); }
31
32
  catch (error) { if (["ENOENT", "ENOTDIR"].includes(error.code)) return null; throw error; }
@@ -44,12 +45,13 @@ export function sourceDirectoryFiles(directory) {
44
45
  } catch (error) { if (["ENOENT", "ENOTDIR"].includes(error.code)) return []; throw error; }
45
46
  }
46
47
 
47
- /** Shared read-only CSS tree. Call clone() before modifying it. */
48
+ /** Shared read-only CSS tree, weakly owned by the captured revision. Clone before modifying it. */
48
49
  export function sourceCss(file) {
49
50
  file = path.resolve(file);
50
51
  const parse = () => postcss.parse(sourceText(file), { from: file });
51
52
  const context = currentAnalysis();
52
- return context ? memoFact(context, `css:${file}`, parse) : parse();
53
+ const key = `css:${file}`;
54
+ return context ? memoFact(context, key, () => context.revision ? memoProgram(context.revision, key, parse) : parse()) : parse();
53
55
  }
54
56
 
55
57
  /** Reuse compiled source trees; isolated syntax clients parse at most once per request. */
@@ -1,15 +1,22 @@
1
1
  import { loadConfig } from "../config.mjs";
2
2
  import { validationInputFiles } from "../validation-inputs.mjs";
3
3
 
4
- export const isAnalysisSource = (file) => /\.(?:[cm]?[jt]sx?|jsonc?|css|html|lock|ya?ml|toml)$/.test(file);
4
+ export const isAnalysisSource = (file) => /\.(?:[cm]?[jt]sx?|jsonc?|css|html|lock|ya?ml|toml)$/.test(file) || /(?:^|[\\/])assets[\\/]pictograms[\\/].*\.svg$/.test(file);
5
5
 
6
- /** Collect source text during the existing input read, not in a second scan. */
7
- export async function readAnalysisInputs(root) {
6
+ /** Operation-local collector: digests and compiler bytes come from the same read. */
7
+ export function createAnalysisInputCapture() {
8
8
  const files = new Map();
9
- const digests = await validationInputFiles(loadConfig(root), [], {
9
+ return {
10
10
  onFile(file, content) {
11
11
  if (isAnalysisSource(file)) files.set(file, content.toString("utf8"));
12
12
  },
13
- });
14
- return { files, dependencyRevision: digests["installed-dependencies"] ?? "" };
13
+ complete(digests) { return { files, dependencyRevision: digests["installed-dependencies"] ?? "" }; },
14
+ };
15
+ }
16
+
17
+ /** Collect source text during the existing input read, not in a second scan. */
18
+ export async function readAnalysisInputs(root) {
19
+ const capture = createAnalysisInputCapture();
20
+ const digests = await validationInputFiles(loadConfig(root), [], capture);
21
+ return capture.complete(digests);
15
22
  }
@@ -0,0 +1,46 @@
1
+ /** Native resolver leases belong to one input capture, never live paths across captures. */
2
+ export function createModuleResolvers(createResolver) {
3
+ const resolvers = new Map(), leases = new Set(), requests = new Set();
4
+ let closed = false, closing;
5
+ function resolve(specifier, directory, options) {
6
+ if (closed) return Promise.reject(new Error("Module resolution capture is closed."));
7
+ const key = JSON.stringify(options);
8
+ if (!resolvers.has(key)) {
9
+ const lease = Promise.resolve().then(() => createResolver(options));
10
+ resolvers.set(key, lease);
11
+ leases.add(lease);
12
+ lease.catch(() => { if (resolvers.get(key) === lease) resolvers.delete(key); });
13
+ }
14
+ const lease = resolvers.get(key);
15
+ const request = lease.then(resolver => resolver.resolveModuleName(specifier, directory));
16
+ requests.add(request);
17
+ request.then(
18
+ () => requests.delete(request),
19
+ () => {
20
+ requests.delete(request);
21
+ // A failed query may leave its native resolver unusable. Retry with a
22
+ // fresh lease; dispose the old one after all of its queries settle.
23
+ if (resolvers.get(key) === lease) resolvers.delete(key);
24
+ },
25
+ );
26
+ return request;
27
+ }
28
+ function close() {
29
+ if (closing) return closing;
30
+ closed = true;
31
+ closing = (async () => {
32
+ await Promise.allSettled(requests);
33
+ const results = await Promise.allSettled([...leases].map(async lease => {
34
+ // Failed creation has no lease to dispose. Its error reached the query.
35
+ const resolver = await lease.catch(() => undefined);
36
+ await resolver?.dispose();
37
+ }));
38
+ resolvers.clear();
39
+ leases.clear();
40
+ const failed = results.find(result => result.status === "rejected");
41
+ if (failed) throw failed.reason;
42
+ })();
43
+ return closing;
44
+ }
45
+ return { resolve, close };
46
+ }
@@ -115,6 +115,13 @@ export async function registerAnalysisRevision(projectRoot, root, files, changes
115
115
  export async function analyze(root, kind = "registry", args = [], signal) {
116
116
  root = path.resolve(root);
117
117
  const inputs = registered.has(root) ? undefined : await readAnalysisInputs(root);
118
+ return analyzeCaptured(root, inputs, kind, args, signal);
119
+ }
120
+ /** Internal handoff of an operation's captured bytes; pinned drafts retain their branch. */
121
+ export function analyzeCaptured(root, inputs, kind = "registry", args = [], signal) {
122
+ root = path.resolve(root);
123
+ if (registered.has(root)) inputs = undefined;
124
+ else if (!inputs) throw new Error("Unregistered analysis requires captured inputs.");
118
125
  if (inputs) baselines.delete(root);
119
126
  return request(
120
127
  { action: "analyze", root, kind, args, ...(inputs ? { files: [...inputs.files], dependencyRevision: inputs.dependencyRevision } : {}) },
@@ -4,9 +4,13 @@ import * as ast from "typescript/ast";
4
4
  import { API, ModuleKind, ModuleResolutionKind, JsxEmit, SymbolFlags, TypeFlags, TypeFormatFlags } from "typescript/async";
5
5
  import { serverFS } from "typescript/fs";
6
6
  import { existsSync, readFileSync } from "node:fs";
7
+ import { AsyncLocalStorage } from "node:async_hooks";
7
8
  import path from "node:path";
8
9
  import { nativeCompilerOptions } from "./compiler-options.mjs";
9
10
  import { currentAnalysis } from "./context.mjs";
11
+ import { createModuleResolvers } from "./module-resolvers.mjs";
12
+
13
+ const resolutionScope = new AsyncLocalStorage();
10
14
 
11
15
  let api,
12
16
  sequence = 0,
@@ -102,16 +106,27 @@ export const transpileSource = (input, options) =>
102
106
  return { ...result, diagnostics: result.diagnostics?.map((diagnostic) => ({ ...diagnostic, messageText: diagnostic.text })) };
103
107
  });
104
108
  export const parseConfigFile = (file) => use((current) => current.parseConfigFile(path.resolve(file)));
105
- export async function resolveModule(specifier, file, options) {
109
+ /** Keep the syntax client and resolver leases alive for exactly one capture. */
110
+ export function withModuleResolutionScope(run) {
106
111
  return use(async (current) => {
107
- const resolver = await current.createModuleResolver(nativeCompilerOptions(options, path.dirname(file)));
112
+ const scope = createModuleResolvers(options => current.createModuleResolver(options));
113
+ let result;
108
114
  try {
109
- return (await resolver.resolveModuleName(specifier, path.dirname(file))).resolvedModule?.resolvedFileName;
110
- } finally {
111
- await resolver.dispose();
115
+ result = await resolutionScope.run(scope, run);
116
+ } catch (error) {
117
+ // Cleanup every lease, preserving the operation's original error.
118
+ await scope.close().catch(() => {});
119
+ throw error;
112
120
  }
121
+ await scope.close();
122
+ return result;
113
123
  });
114
124
  }
125
+ export async function resolveModule(specifier, file, options) {
126
+ const scope = resolutionScope.getStore();
127
+ if (!scope) return withModuleResolutionScope(() => resolveModule(specifier, file, options));
128
+ return (await scope.resolve(specifier, path.dirname(file), nativeCompilerOptions(options, path.dirname(file)))).resolvedModule?.resolvedFileName;
129
+ }
115
130
  function findConfigFile(directory, exists = existsSync, name = "tsconfig.json") {
116
131
  for (directory = path.resolve(directory); ; ) {
117
132
  const file = path.join(directory, name);
package/dist/assets.mjs CHANGED
@@ -60,7 +60,7 @@ export function inspectGlyphs({ root, dsRoot, config }) {
60
60
  else if (shared && box !== shared) findings.push(finding("glyph-viewbox", file, `${base} uses viewBox "${box}"; the set uses "${shared}", so it would draw at a different size.`));
61
61
  // Any fill or stroke other than none or currentColor fixes the icon's color.
62
62
  const colors = [...text.matchAll(/\b(fill|stroke)\s*[=:]\s*["']?\s*([^"';\s>]+)/g)].map(match => match[2]).filter(value => !/^(?:none|currentcolor|inherit)$/i.test(value) && !/^url\(/i.test(value));
63
- if (colors.length) findings.push(finding("glyph-color", file, `${base} sets ${[...new Set(colors)].join(", ")}; draw glyphs in currentColor so they follow the text color and theme. Another product's logo that keeps its own colors belongs in assets/logos/, shown as an image; the project's own colored artwork belongs in assets/brand/.`));
63
+ if (colors.length) findings.push(finding("glyph-color", file, `${base} sets ${[...new Set(colors)].join(", ")}; draw glyphs in currentColor so they follow the text color and theme. Another product's logo that keeps its own colors belongs in assets/logos/, shown as an image; logos belong in assets/brand/; illustrative pictograms belong in assets/pictograms/ with catalog.ads.json.`));
64
64
  }
65
65
  return findings;
66
66
  }
@@ -41,9 +41,6 @@ async function createImportResolver(options) {
41
41
  const compiler = await projectCompilerOptions(options);
42
42
  const cache = new Map();
43
43
  const resolve = async (specifier, filename) => {
44
- // Vite and other bundlers attach resource queries to the same source file.
45
- // They cannot turn a private file into a public import.
46
- specifier = specifier.replace(/[?#].*$/, "");
47
44
  const analysis = currentAnalysis();
48
45
  const resolved = analysis?.resolveModule ? await analysis.resolveModule(specifier, filename, compiler) : await resolveModule(specifier, filename, compiler);
49
46
  if (resolved) return [path.resolve(resolved)];
@@ -60,7 +57,12 @@ async function createImportResolver(options) {
60
57
  return [path.resolve(compiler.baseUrl ?? root, specifier)];
61
58
  };
62
59
  return async (specifier, filename) => {
63
- const key = `${filename}\0${specifier}`;
60
+ // The native API resolves from the importing directory, with this resolver's
61
+ // compiler options. Sibling files must share that query, including pending
62
+ // work. The cache still belongs to this captured request/inventory.
63
+ // Bundler resource queries do not change the source being resolved.
64
+ specifier = specifier.replace(/[?#].*$/, "");
65
+ const key = `${path.dirname(filename)}\0${specifier}`;
64
66
  if (!cache.has(key)) {
65
67
  const pending = resolve(specifier, filename);
66
68
  cache.set(key, pending);
@@ -1,7 +1,8 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import path from "node:path";
3
3
  import { architectureTaskInputs } from "./task-cache.mjs";
4
- import { analyze } from "./analysis/service.mjs";
4
+ import { analyzeCaptured } from "./analysis/service.mjs";
5
+ import { createAnalysisInputCapture } from "./analysis/inputs.mjs";
5
6
 
6
7
  const hash = (value) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
7
8
  const remembered = new Map(),
@@ -13,10 +14,10 @@ function cancelled() {
13
14
  diagnostic: { rule: "mutation-cancelled", message: "Mutation cancelled during validation." },
14
15
  });
15
16
  }
16
- async function run(root, trackingRoot, signal) {
17
+ async function run(root, trackingRoot, signal, inputs) {
17
18
  active = new AbortController();
18
19
  try {
19
- return await analyze(root, "check", [trackingRoot], signal ? AbortSignal.any([signal, active.signal]) : active.signal);
20
+ return await analyzeCaptured(root, inputs, "check", [trackingRoot], signal ? AbortSignal.any([signal, active.signal]) : active.signal);
20
21
  } finally {
21
22
  active = undefined;
22
23
  }
@@ -30,10 +31,12 @@ export function warmCheck(root, trackingRoot = root, signal, { fresh = false } =
30
31
  const job = queue.then(async () => {
31
32
  if (signal?.aborted) throw cancelled();
32
33
  const started = Date.now(),
33
- key = hash(await architectureTaskInputs(root, trackingRoot));
34
+ capture = createAnalysisInputCapture(),
35
+ inputs = await architectureTaskInputs(root, trackingRoot, capture),
36
+ key = hash(inputs);
34
37
  if (!fresh && remembered.has(key))
35
38
  return { ...remembered.get(key), cache: { backend: "warm", task: "architecture", key, status: "hit", elapsedMs: Date.now() - started } };
36
- const result = await run(root, trackingRoot, signal);
39
+ const result = await run(root, trackingRoot, signal, capture.complete(inputs.files));
37
40
  if (hash(await architectureTaskInputs(root, trackingRoot)) !== key)
38
41
  throw Object.assign(new Error("Source, dependencies or Git tracking changed during the ADS task; retry against the current inputs."), {
39
42
  code: "ADS_SOURCE_CHANGED",
package/dist/check.mjs CHANGED
@@ -55,6 +55,7 @@ import { inspectBehaviorLibraries } from "./behavior-libraries.mjs";
55
55
  import { inspectUsage } from "./usage.mjs";
56
56
  import { controlPaddingAdvisories } from "./control-padding.mjs";
57
57
  import { createComponentContrast } from "./component-contrast.mjs";
58
+ import { createContrastComposition } from "./contrast-composition.mjs";
58
59
  import { createFontRules } from "./font-rules.mjs";
59
60
  import { createLayoutWidths, globMatcher } from "./layout-widths.mjs";
60
61
  import { imageAttributeFindings } from "./image-attributes.mjs";
@@ -293,6 +294,7 @@ async function checkCapturedProject(directory, { trackingRoot }) {
293
294
  const registeredProperties = new Map(),
294
295
  controlPaddingSeen = new Set();
295
296
  const componentContrast = createComponentContrast(tokenInventory.tokens, config.themes, config.brands);
297
+ const contrastComposition = createContrastComposition(program, options, componentContrast);
296
298
  const layoutWidths = createLayoutWidths(tokenInventory.tokens, config, spatialFoundation),
297
299
  fixedWidthOwner = globMatcher(config.layout.fixedWidthUnits);
298
300
  for (const glob of config.layout.widthTokens)
@@ -387,8 +389,10 @@ async function checkCapturedProject(directory, { trackingRoot }) {
387
389
  layerStyles.push({ file, css, offset });
388
390
  if (foundation || !isDevelopmentFile(file, options)) fontRules.collect(css, file, offset);
389
391
  await checkRegistrations(file, css, offset);
390
- if (!foundation && !isDevelopmentFile(file, options) && ["components", "patterns"].some((layer) => isInside(path.join(dsRoot, layer), file)))
392
+ if (!foundation && !isDevelopmentFile(file, options) && ["components", "patterns"].some((layer) => isInside(path.join(dsRoot, layer), file))) {
391
393
  componentContrast.collect(path.relative(root, file).replaceAll("\\", "/"), css, offset);
394
+ contrastComposition.record(template, css, path.relative(root, file).replaceAll("\\", "/"), offset);
395
+ }
392
396
  if (
393
397
  !foundation &&
394
398
  (isInside(path.join(dsRoot, "composition"), file) ||
@@ -925,13 +929,14 @@ async function checkCapturedProject(directory, { trackingRoot }) {
925
929
  await visit(source);
926
930
  }
927
931
  diagnostics.push(...await spatialComposition.check());
932
+ await contrastComposition.check();
928
933
  inspectDesignAliases(layerStyles, options, report);
929
934
  for (const { file, css, offset } of layerStyles) await layers.inspectStyles(file, css, offset);
930
935
  advisories.push(
931
936
  ...(tokenInventory.advisories ?? []),
932
937
  ...assetAdvisories,
933
- ...(await a11ySourceAdvisories(options)),
934
- ...(await imageAttributeFindings(options)),
938
+ ...(await a11ySourceAdvisories(options, scriptFiles)),
939
+ ...(await imageAttributeFindings(options, scriptFiles)),
935
940
  ...componentContrast.findings(),
936
941
  ...layoutWidths.declaredWidths(ownerFixedWidths),
937
942
  ...fontRules.findings(),