@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
@@ -1,9 +1,9 @@
1
- import { readFileSync } from "node:fs";
2
1
  import path from "node:path";
3
2
  import ts from "./analysis/syntax.mjs";
4
3
  import postcss from "postcss";
5
- import { isDevelopmentFile, isInside, isTestFile, sourceFiles } from "./config.mjs";
4
+ import { isDevelopmentFile, isInside, isTestFile } from "./config.mjs";
6
5
  import { findingSeverity } from "./finding-rules.mjs";
6
+ import { sourceAst, sourceText, memoProgram } from "./analysis/helpers.mjs";
7
7
 
8
8
  /** A raw <img> in component, pattern and composition source reserves its space and chooses how it
9
9
  * loads. It needs width and height, or a size its own style shows (aspect-ratio, or both a width
@@ -83,101 +83,105 @@ function classSize(expression, { variables, classes }) {
83
83
  return found ? true : unknown ? null : false;
84
84
  }
85
85
 
86
- export async function imageAttributeFindings({ root, dsRoot }) {
86
+ export async function imageAttributeFindings({ root, dsRoot }, sources) {
87
87
  const options = { root, dsRoot },
88
88
  findings = [];
89
89
  const inScope = (file) =>
90
90
  (isInside(path.join(dsRoot, "composition"), file) && !isTestFile(file)) ||
91
91
  (["components", "patterns"].some((layer) => isInside(path.join(dsRoot, layer), file)) && !isDevelopmentFile(file, options));
92
- for (const file of sourceFiles(dsRoot).filter((file) => /\.[jt]sx$/.test(file) && inScope(file))) {
93
- const text = readFileSync(file, "utf8");
94
- if (!/<(?:img|Image)\b/.test(text)) continue;
95
- const source = await ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX),
96
- relative = path.relative(root, file).replaceAll("\\", "/");
97
- const styles = fileStyles(source);
98
- const visit = (node) => {
99
- if (ts.isJsxSelfClosingElement(node) || ts.isJsxOpeningElement(node)) {
100
- const tag = node.tagName.getText(source);
101
- if (tag === "img" || tag === "Image") inspectCandidates(node, tag);
102
- if (tag === "img") inspect(node);
103
- }
104
- ts.forEachChild(node, visit);
105
- };
106
- /** Width descriptors say nothing about display size, so sizes must. */
107
- const inspectCandidates = (node, tag) => {
108
- const attributes = node.attributes.properties;
109
- const attribute = (name) => attributes.find((item) => ts.isJsxAttribute(item) && item.name.getText(source) === name);
110
- const candidates = attribute("srcset") ?? attribute("srcSet");
111
- if (!candidates || attribute("sizes")) return;
112
- const { line, character } = source.getLineAndCharacterOfPosition(node.getStart(source));
113
- const add = (rule, message) =>
114
- findings.push({
115
- rule,
116
- severity: findingSeverity(rule),
117
- file: relative,
118
- line: line + 1,
119
- column: character + 1,
120
- guidanceUri: guidance,
121
- message: `${relative}:${line + 1} ${message}`,
122
- });
123
- let value = candidates.initializer;
124
- if (value && ts.isJsxExpression(value)) value = value.expression;
125
- const literal = value && ts.isStringLiteralLike(value) ? value.text : null;
126
- if (attributes.some(ts.isJsxSpreadAttribute) || literal === null)
127
- add(
128
- "img-attributes-unresolved",
129
- `<${tag}> has a srcset ADS cannot read or spread props that may hold sizes. With width descriptors it needs sizes, the width it displays at.`,
130
- );
131
- else if (/\d\s*w\s*(?:,|$)/.test(literal.trim()))
132
- add(
133
- "img-attributes",
134
- `<${tag}> has a srcset with width descriptors and no sizes, so the browser assumes the full viewport width and can pick a larger file than it shows. Add sizes, such as "(min-width: 1024px) 50vw, 100vw".`,
135
- );
136
- };
137
- const inspect = (node) => {
138
- const { line, character } = source.getLineAndCharacterOfPosition(node.getStart(source));
139
- const add = (rule, message) =>
140
- findings.push({
141
- rule,
142
- severity: findingSeverity(rule),
143
- file: relative,
144
- line: line + 1,
145
- column: character + 1,
146
- guidanceUri: guidance,
147
- message: `${relative}:${line + 1} ${message}`,
148
- });
149
- const attributes = node.attributes.properties,
150
- spread = attributes.some(ts.isJsxSpreadAttribute);
151
- const attribute = (name) => attributes.find((item) => ts.isJsxAttribute(item) && item.name.getText(source) === name);
152
- const styleText = attribute("style")?.initializer?.getText(source) ?? "";
153
- const className = attribute("className") ?? attribute("class");
154
- let size = !!(attribute("width") && attribute("height")) || /\baspectRatio\b|aspect-ratio/.test(styleText) || styles.imgRule;
155
- if (!size && className?.initializer) size = classSize(className.initializer, styles);
156
- const loading = !!attribute("loading");
157
- if (spread && (size !== true || !loading)) {
158
- add(
159
- "img-attributes-unresolved",
160
- `spreads props onto <img>, so ADS cannot see its dimensions or loading. Pass width, height and loading explicitly so the page reserves the space and the load order is a choice.`,
161
- );
162
- return;
163
- }
164
- if (size === null)
165
- add(
166
- "img-attributes-unresolved",
167
- `styles <img> with a class ADS cannot read here, so its size is not checked. Set width and height so the page reserves the space.`,
168
- );
169
- if (size === false)
170
- add(
171
- "img-attributes",
172
- `<img> has no width and height or a visible aspect-ratio, so the page shifts when it loads. Set the file's width and height, or a sized aspect-ratio in its style.`,
173
- );
174
- if (!loading)
175
- add(
176
- "img-attributes",
177
- `<img> has no loading attribute. Use loading="lazy" below the fold; the page's main visible image uses loading="eager" with fetchpriority="high", or the project's image component with priority.`,
178
- );
179
- };
180
- visit(source);
92
+ for (const file of sources.filter((file) => /\.[jt]sx$/.test(file) && inScope(file))) {
93
+ if (!/<(?:img|Image)\b/.test(sourceText(file))) continue;
94
+ const source = await sourceAst(file), relative = path.relative(root, file).replaceAll("\\", "/");
95
+ findings.push(...memoProgram(source, `image-attributes:${relative}`, () => sourceFindings(source, relative)));
181
96
  }
182
97
  return findings;
183
98
  }
99
+
100
+ /** Local sizing/loading evidence; imported styles remain explicitly unresolved. */
101
+ function sourceFindings(source, relative) {
102
+ const findings = [], styles = fileStyles(source);
103
+ const visit = (node) => {
104
+ if (ts.isJsxSelfClosingElement(node) || ts.isJsxOpeningElement(node)) {
105
+ const tag = node.tagName.getText(source);
106
+ if (tag === "img" || tag === "Image") inspectCandidates(node, tag);
107
+ if (tag === "img") inspect(node);
108
+ }
109
+ ts.forEachChild(node, visit);
110
+ };
111
+ /** Width descriptors say nothing about display size, so sizes must. */
112
+ const inspectCandidates = (node, tag) => {
113
+ const attributes = node.attributes.properties;
114
+ const attribute = (name) => attributes.find((item) => ts.isJsxAttribute(item) && item.name.getText(source) === name);
115
+ const candidates = attribute("srcset") ?? attribute("srcSet");
116
+ if (!candidates || attribute("sizes")) return;
117
+ const { line, character } = source.getLineAndCharacterOfPosition(node.getStart(source));
118
+ const add = (rule, message) =>
119
+ findings.push({
120
+ rule,
121
+ severity: findingSeverity(rule),
122
+ file: relative,
123
+ line: line + 1,
124
+ column: character + 1,
125
+ guidanceUri: guidance,
126
+ message: `${relative}:${line + 1} ${message}`,
127
+ });
128
+ let value = candidates.initializer;
129
+ if (value && ts.isJsxExpression(value)) value = value.expression;
130
+ const literal = value && ts.isStringLiteralLike(value) ? value.text : null;
131
+ if (attributes.some(ts.isJsxSpreadAttribute) || literal === null)
132
+ add(
133
+ "img-attributes-unresolved",
134
+ `<${tag}> has a srcset ADS cannot read or spread props that may hold sizes. With width descriptors it needs sizes, the width it displays at.`,
135
+ );
136
+ else if (/\d\s*w\s*(?:,|$)/.test(literal.trim()))
137
+ add(
138
+ "img-attributes",
139
+ `<${tag}> has a srcset with width descriptors and no sizes, so the browser assumes the full viewport width and can pick a larger file than it shows. Add sizes, such as "(min-width: 1024px) 50vw, 100vw".`,
140
+ );
141
+ };
142
+ const inspect = (node) => {
143
+ const { line, character } = source.getLineAndCharacterOfPosition(node.getStart(source));
144
+ const add = (rule, message) =>
145
+ findings.push({
146
+ rule,
147
+ severity: findingSeverity(rule),
148
+ file: relative,
149
+ line: line + 1,
150
+ column: character + 1,
151
+ guidanceUri: guidance,
152
+ message: `${relative}:${line + 1} ${message}`,
153
+ });
154
+ const attributes = node.attributes.properties,
155
+ spread = attributes.some(ts.isJsxSpreadAttribute);
156
+ const attribute = (name) => attributes.find((item) => ts.isJsxAttribute(item) && item.name.getText(source) === name);
157
+ const styleText = attribute("style")?.initializer?.getText(source) ?? "";
158
+ const className = attribute("className") ?? attribute("class");
159
+ let size = !!(attribute("width") && attribute("height")) || /\baspectRatio\b|aspect-ratio/.test(styleText) || styles.imgRule;
160
+ if (!size && className?.initializer) size = classSize(className.initializer, styles);
161
+ const loading = !!attribute("loading");
162
+ if (spread && (size !== true || !loading)) {
163
+ add(
164
+ "img-attributes-unresolved",
165
+ `spreads props onto <img>, so ADS cannot see its dimensions or loading. Pass width, height and loading explicitly so the page reserves the space and the load order is a choice.`,
166
+ );
167
+ return;
168
+ }
169
+ if (size === null)
170
+ add(
171
+ "img-attributes-unresolved",
172
+ `styles <img> with a class ADS cannot read here, so its size is not checked. Set width and height so the page reserves the space.`,
173
+ );
174
+ if (size === false)
175
+ add(
176
+ "img-attributes",
177
+ `<img> has no width and height or a visible aspect-ratio, so the page shifts when it loads. Set the file's width and height, or a sized aspect-ratio in its style.`,
178
+ );
179
+ if (!loading)
180
+ add(
181
+ "img-attributes",
182
+ `<img> has no loading attribute. Use loading="lazy" below the fold; the page's main visible image uses loading="eager" with fetchpriority="high", or the project's image component with priority.`,
183
+ );
184
+ };
185
+ visit(source);
186
+ return Object.freeze(findings.map(Object.freeze));
187
+ }
@@ -525,7 +525,11 @@ export function createDraftController(directory, { edits, startPreview, prewarm
525
525
  return summary(await inspect(id));
526
526
  }
527
527
  async function prepare(id) {
528
- const value = await inspect(id);
528
+ // One operation owns both the inspection revision and the workspace bytes.
529
+ // inspect still performs its targeted live conflict/path checks.
530
+ const captured = new Map();
531
+ const inputs = await validationInputFiles(loadConfig(root), [], { onFile: (file, content) => captured.set(file, content) });
532
+ const value = await inspect(id, [], { inputs, seen: new Set(), memo: new Map() });
529
533
  if (value.dependencyErrors.length) throw new Error(`Draft dependency error: ${value.dependencyErrors[0].message}`);
530
534
  if (value.conflicts.length) throw new Error(`Draft baseline conflict: ${value.conflicts.join(", ")}`);
531
535
  let session = previews.get(id);
@@ -543,9 +547,7 @@ export function createDraftController(directory, { edits, startPreview, prewarm
543
547
  if (session.revision && !existsSync(path.join(session.workspace, ".ds/draft-preview.json"))) session.recovering = true;
544
548
  mkdirSync(session.workspace, { recursive: true });
545
549
  if (realpathSync(session.workspace) !== session.workspace) throw new Error("Draft preview workspace cannot be a symlink.");
546
- const captured = new Map();
547
- const inputs = await validationInputFiles(loadConfig(root), [], { onFile: (file, content) => captured.set(file, content) }),
548
- desired = new Map();
550
+ const desired = new Map();
549
551
  const baseline = new Map([...captured].filter(([file]) => isAnalysisSource(file)).map(([file, content]) => [file, content.toString("utf8")]));
550
552
  let size = 0;
551
553
  for (const [target, digest] of Object.entries(inputs))
@@ -557,9 +557,12 @@ export function createMutationController(directory, { captures = createCaptureCo
557
557
  }
558
558
  await registerAnalysis();
559
559
  const inputPaths = [...new Set([...changes.map((change) => change.path), ...Object.keys(await validationInputFiles(candidateOptions))])];
560
+ // A source-only edit has the same input scope on both sides. Capture it
561
+ // once per fence; configuration changes still fence both distinct scopes.
562
+ const inputScopes = [...new Map([options, candidateOptions].map(original => [JSON.stringify(original.config), original])).values()];
560
563
  const scopedInputs = async () => {
561
564
  const files = {};
562
- for (const original of [options, candidateOptions]) {
565
+ for (const original of inputScopes) {
563
566
  const rebased = {
564
567
  root,
565
568
  config: original.config,
@@ -581,12 +584,12 @@ export function createMutationController(directory, { captures = createCaptureCo
581
584
  // A reviewed draft's workspace holds exactly this candidate's inputs at a stable path, so
582
585
  // its warm check (and a remembered report from a dry run) applies; otherwise check the copy.
583
586
  // Compared over the project's own inputs plus the changed files.
584
- const compared = [...new Set([...Object.keys(await validationInputFiles(options)), ...changes.map((change) => change.path)])];
585
- const pick = (digests) => JSON.stringify(compared.map((file) => [file, digests[file] ?? null]));
586
- const sameInputs =
587
- checkRoot &&
588
- existsSync(checkRoot) &&
589
- pick(await validationInputFiles(loadConfig(checkRoot), compared)) === pick(await validationInputFiles(candidateOptions, compared));
587
+ let sameInputs = false;
588
+ if (checkRoot && existsSync(checkRoot)) {
589
+ const compared = [...new Set([...Object.keys(await validationInputFiles(options)), ...changes.map((change) => change.path)])];
590
+ const pick = (digests) => JSON.stringify(compared.map((file) => [file, digests[file] ?? null]));
591
+ sameInputs = pick(await validationInputFiles(loadConfig(checkRoot), compared)) === pick(await validationInputFiles(candidateOptions, compared));
592
+ }
590
593
  // Browser checks of a reviewed draft render its workspace through the project's own host and
591
594
  // compiler; only a candidate without one gets a preview host of its own.
592
595
  const reviewRoot = sameInputs ? checkRoot : candidate,
@@ -630,7 +633,7 @@ export function createMutationController(directory, { captures = createCaptureCo
630
633
  const auditSelection =
631
634
  audit && (await analyze(candidate, "audit-selection", [changes.map((change) => change.path), { mode: "owners", owners: units }], signal));
632
635
  // Previews are built only when a browser behavior check renders them.
633
- if ((await analyze(candidate, "needs-browser", [behaviorUnits], signal)) && candidateOptions.config.framework) {
636
+ if (behaviorUnits.length && candidateOptions.config.framework && await analyze(candidate, "needs-browser", [behaviorUnits], signal)) {
634
637
  boundary = evidenceFailure("build", "preview-build", "ADS_PREVIEW_BUILD");
635
638
  progress = { stage: "preview-build", message: "Building all candidate previews" };
636
639
  notifyProgress?.(progress);