@reqvire-org/ads 0.5.2 → 0.5.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 (68) hide show
  1. package/dist/ads-errors.mjs +33 -26
  2. package/dist/analysis/design-usage.mjs +4 -20
  3. package/dist/analysis/mock-check.mjs +4 -5
  4. package/dist/analysis/owner-accessibility.mjs +4 -4
  5. package/dist/analysis/owner-analysis-key.mjs +1 -1
  6. package/dist/analysis/owner-choices.mjs +33 -3
  7. package/dist/analysis/owner-composition.mjs +61 -12
  8. package/dist/analysis/owner-source.mjs +52 -35
  9. package/dist/composed-contrast.mjs +143 -62
  10. package/dist/construction-output.mjs +6 -1
  11. package/dist/construction-spec.d.mts +53 -44
  12. package/dist/construction-spec.mjs +64 -76
  13. package/dist/corner-overpaint.mjs +5 -4
  14. package/dist/design-foundation.mjs +16 -0
  15. package/dist/design-usage.mjs +2 -8
  16. package/dist/emit/emission.mjs +0 -5
  17. package/dist/grid-lowering.mjs +3 -1
  18. package/dist/lowering-enter.mjs +6 -6
  19. package/dist/lowering-session.mjs +10 -0
  20. package/dist/mcp/server-observation.mjs +6 -4
  21. package/dist/mcp/server-project.mjs +4 -1
  22. package/dist/owner-analysis-check.mjs +4 -1
  23. package/dist/owner-errors.mjs +2 -1
  24. package/dist/owner-lowering.mjs +10 -4
  25. package/dist/owner-scenarios.mjs +2 -22
  26. package/dist/ownership-model.mjs +7 -5
  27. package/dist/paint-contrast.mjs +6 -0
  28. package/dist/profile-macro.d.mts +7 -0
  29. package/dist/recipe-macro.d.mts +46 -42
  30. package/dist/recipe-model.mjs +12 -11
  31. package/dist/region-lowering.mjs +54 -109
  32. package/dist/role-vocabulary.d.mts +4 -0
  33. package/dist/role-vocabulary.mjs +4 -0
  34. package/dist/runtime-paint-contrast.mjs +5 -2
  35. package/dist/showcase/client.bundle.js +48 -48
  36. package/dist/showcase/http-client.bundle.js +13 -13
  37. package/dist/showcase/ui/ui.css +1 -1
  38. package/dist/showcase/ui/ui.js +5 -5
  39. package/dist/skills/ads-designer/references/accessibility.md +3 -4
  40. package/dist/skills/ads-designer/references/design-data.md +12 -6
  41. package/dist/skills/ads-designer/references/layout.md +7 -3
  42. package/dist/skills/ads-designer/references/motion.md +2 -1
  43. package/dist/skills/ads-designer/references/recipes.md +28 -18
  44. package/dist/skills/ads-import/references/design-data.md +12 -6
  45. package/dist/skills/ads-import/references/layout.md +7 -3
  46. package/dist/skills/ads-import/references/recipes.md +28 -18
  47. package/dist/skills/ads-migrate/SKILL.md +1 -0
  48. package/dist/skills/ads-migrate/references/0.5.2-to-0.5.3.md +71 -0
  49. package/dist/skills/ads-port/references/design-data.md +12 -6
  50. package/dist/skills/ads-port/references/layout.md +7 -3
  51. package/dist/skills/ads-port/references/recipes.md +28 -18
  52. package/dist/spatial-model.mjs +2 -2
  53. package/dist/surface-contrast.mjs +6 -2
  54. package/dist/target-size.mjs +21 -3
  55. package/docs/ADS.md +9 -3
  56. package/docs/ARCHITECTURE.md +33 -23
  57. package/docs/CACHING.md +1 -1
  58. package/docs/CHANGELOG.md +128 -21
  59. package/docs/GUIDE.md +64 -19
  60. package/docs/LANGUAGE.md +141 -134
  61. package/docs/MCP.md +5 -1
  62. package/docs/MOTION.md +5 -2
  63. package/docs/PROFILE-KINDS.md +46 -4
  64. package/docs/RULES.md +16 -15
  65. package/package.json +1 -1
  66. package/dist/analysis/prose-owners.mjs +0 -57
  67. package/dist/prose-model.d.mts +0 -81
  68. package/dist/prose-model.mjs +0 -101
@@ -172,7 +172,7 @@ function insideMap(node, ancestor) {
172
172
  return !0;
173
173
  return !1;
174
174
  }
175
- const isLoop = (node) => isForStatement(node) || isForOfStatement(node) || isForInStatement(node) || isWhileStatement(node) || isDoStatement(node), lowercaseTag = (opening) => /^[a-z]/.test(opening.tagName.getText()), NO_CLASSES = { fragments: [], calls: [], markers: [], placement: [], bindings: [] };
175
+ const isLoop = (node) => isForStatement(node) || isForOfStatement(node) || isForInStatement(node) || isWhileStatement(node) || isDoStatement(node), NO_CLASSES = { fragments: [], calls: [], markers: [], placement: [], bindings: [] };
176
176
  function validateReferences(foundation, spec) {
177
177
  if (typeof spec !== "object" || spec === null)
178
178
  return null;
@@ -266,14 +266,14 @@ export async function checkOwners(root, names, options, reuse) {
266
266
  const { program, graph } = walked.value, emitted = new Set(graph.modules.keys());
267
267
  options.stats.analyses++;
268
268
  const outcomes = new Map, facts = new Map, pass = await timing.timeStage("owner-keys", () => reuse.begin(program, graph));
269
- let plain = { modules: new Map, failures: [], placements: [] }, unemitted = [];
269
+ let plain = { modules: new Map, failures: [], placements: [], composition: new Map }, unemitted = [];
270
270
  await timing.timeStage("owner-facts", async () => {
271
271
  for (const name of names) {
272
272
  throwIfCancelled();
273
273
  const analyze = (foundation, assets) => checkedOwner(root, emitted, name, program, { ...options, foundation, assets }, outcomes, (analyzed) => facts.set(name, analyzed));
274
274
  outcomes.set(name, await pass.owner({ name, settled: outcomes, analyze }));
275
275
  }
276
- plain = await checkedPlainModules(root, graph, program, options.publicAlias, emitted, options.assets);
276
+ plain = await checkedPlainModules(root, graph, program, options.publicAlias, emitted, options.assets, options.foundation);
277
277
  unemitted = [
278
278
  ...(await unemittedStyling(root, emitted)).map(stylingFailure),
279
279
  ...await frameworkMismatches(root, options.framework ?? null),
@@ -299,7 +299,8 @@ export async function checkOwners(root, names, options, reuse) {
299
299
  checkProgram: program,
300
300
  facts,
301
301
  plain: plain.modules,
302
- plainPlacements: plain.placements
302
+ plainPlacements: plain.placements,
303
+ plainComposition: plain.composition
303
304
  });
304
305
  }
305
306
  async function checkedOwner(root, emitted, name, program, options, settled, retain) {
@@ -341,8 +342,8 @@ async function plainModules(root, graph, program, publicAlias, emitted, catalog,
341
342
  }
342
343
  return plain;
343
344
  }
344
- async function checkedPlainModules(root, graph, program, publicAlias, emitted, catalog) {
345
- const modules = new Map, failures = [], placements = [], checker = program.getTypeChecker();
345
+ async function checkedPlainModules(root, graph, program, publicAlias, emitted, catalog, foundation) {
346
+ const modules = new Map, failures = [], placements = [], composition = new Map, checker = program.getTypeChecker();
346
347
  for (const module of graph.modules.values()) {
347
348
  if (module.role === "owner")
348
349
  continue;
@@ -352,14 +353,24 @@ async function checkedPlainModules(root, graph, program, publicAlias, emitted, c
352
353
  switch (checked.kind) {
353
354
  case "ok":
354
355
  modules.set(file, checked.value);
355
- placements.push(...await timing.timeStage("plain-placements", () => plainPlacements(root, checked.value.source, (node) => valueSymbolAt(checker, node))));
356
+ const placed = await timing.timeStage("plain-placements", () => plainPlacements(root, checked.value.source, (node) => valueSymbolAt(checker, node)));
357
+ if (placed.length === 0)
358
+ break;
359
+ const facts = await attemptAsync(async (reject) => {
360
+ const source = checked.value.source, values = await choiceValues({ program, source, root, validateSpec: (spec) => validateReferences(foundation, spec), fail: failAt(reject) });
361
+ return timing.timeStage("plain-composition", () => compositionFacts({ root, source, values, checker, foundation }));
362
+ });
363
+ if (facts.kind === "ok")
364
+ composition.set(file, facts.value);
365
+ else
366
+ placements.push(...placed);
356
367
  break;
357
368
  case "err":
358
369
  failures.push(checked.error);
359
370
  break;
360
371
  }
361
372
  }
362
- return { modules, failures, placements };
373
+ return { modules, failures, placements, composition };
363
374
  }
364
375
  async function plainStyling(root, file, program) {
365
376
  return plainModuleStyling(await programSource(program, path.join(root, file)), program, program.getTypeChecker());
@@ -426,7 +437,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
426
437
  const [stylesheet] = ownerStylesheetImports(source);
427
438
  if (stylesheet !== void 0)
428
439
  return fail(stylesheet.node, stylesheet.problem);
429
- const values = await choiceValues({ program, source, root, validateSpec: (spec) => validateReferences(foundation, spec), fail }), checker = program.getTypeChecker(), [styleWrite] = await ownerStyleWrites(source, program, checker);
440
+ const values = await choiceValues({ program, source, root, validateSpec: (spec) => validateReferences(foundation, spec), fail }), lowercaseTag = (opening) => /^[a-z]/.test(values.tag(opening)), checker = program.getTypeChecker(), [styleWrite] = await ownerStyleWrites(source, program, checker);
430
441
  if (styleWrite !== void 0)
431
442
  return fail(styleWrite.node, styleWrite.problem);
432
443
  const [animation] = await scriptAnimations(source, program, checker);
@@ -530,7 +541,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
530
541
  }
531
542
  async function intrinsicSource(opening, context, resolve) {
532
543
  const images = await children(opening, context, resolve), [image] = images;
533
- if (images.length !== 1 || image === void 0 || image.tagName.getText() !== "img")
544
+ if (images.length !== 1 || image === void 0 || values.tag(image) !== "img")
534
545
  return fail(opening, { kind: "intrinsic-image-count" });
535
546
  const src = expression(attr(image, "src"));
536
547
  if (src === void 0)
@@ -581,9 +592,9 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
581
592
  const descendants = (opening) => {
582
593
  const element = elementOf(opening);
583
594
  return openings.filter((other) => other !== opening && other.getStart() >= element.getStart() && other.end <= element.end);
584
- }, FOCUSABLE_TAGS = ["a", "button", "input", "select", "textarea", "summary", "iframe"], focusable = (other) => FOCUSABLE_TAGS.includes(other.tagName.getText()) || attr(other, "tabIndex") !== void 0 || attr(other, "href") !== void 0;
595
+ }, FOCUSABLE_TAGS = ["a", "button", "input", "select", "textarea", "summary", "iframe"], focusable = (other) => FOCUSABLE_TAGS.includes(values.tag(other)) || attr(other, "tabIndex") !== void 0 || attr(other, "href") !== void 0;
585
596
  async function textEntryElement(opening, partName, context, resolve) {
586
- const expected = ['<input type="text|email|tel|url|password|search|number">', "<textarea>", "<select>"], tag = opening.tagName.getText();
597
+ const expected = ['<input type="text|email|tel|url|password|search|number">', "<textarea>", "<select>"], tag = values.tag(opening);
587
598
  if (tag === "textarea" || tag === "select")
588
599
  return;
589
600
  if (tag !== "input")
@@ -595,7 +606,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
595
606
  async function nativeElement(opening, element, partName, parent, context, resolve) {
596
607
  if (element === null)
597
608
  return;
598
- const tag = opening.tagName.getText(), tags = elementTags(element);
609
+ const tag = values.tag(opening), tags = elementTags(element);
599
610
  if (!tags.includes(tag))
600
611
  return fail(opening, { kind: "part-element-mismatch", part: partName, expected: tags.map((expected) => `<${expected}>`), actual: `<${tag}>` });
601
612
  switch (element.kind) {
@@ -609,9 +620,9 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
609
620
  let host = parent === null ? elementOf(opening).parent : elementOf(parent);
610
621
  while (host !== void 0 && !isJsxElement(host) && !isJsxSelfClosingElement(host) && (isJsxExpression(host) || isParenthesizedExpression(host) || isJsxFragment(host)))
611
622
  host = host.parent;
612
- if ((host === void 0 ? null : openingOf(host)?.tagName.getText() ?? null) !== "details")
623
+ if ((host === void 0 ? null : openingOf(host) === void 0 ? null : values.tag(openingOf(host))) !== "details")
613
624
  return fail(opening, { kind: "summary-outside-details", part: partName });
614
- if (element.marker === "none" && !descendants(opening).some((other) => !lowercaseTag(other) || other.tagName.getText() === "svg" || attr(other, "aria-hidden") !== void 0))
625
+ if (element.marker === "none" && !descendants(opening).some((other) => !lowercaseTag(other) || values.tag(other) === "svg" || attr(other, "aria-hidden") !== void 0))
615
626
  review(opening, { kind: "marker-none-unlabelled", part: partName });
616
627
  return;
617
628
  }
@@ -688,7 +699,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
688
699
  const touchDisabled = [], handovers = [];
689
700
  let containerGrids = !1;
690
701
  async function layerRoot(opening, layer, context, resolve) {
691
- const tag = opening.tagName.getText(), named = attr(opening, "aria-label") !== void 0 || attr(opening, "aria-labelledby") !== void 0;
702
+ const tag = values.tag(opening), named = attr(opening, "aria-label") !== void 0 || attr(opening, "aria-labelledby") !== void 0;
692
703
  switch (layer.kind) {
693
704
  case "modal-sheet": {
694
705
  if (tag !== "dialog")
@@ -893,7 +904,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
893
904
  const parent = matched.get(part.within.join(" "));
894
905
  if (parent === void 0)
895
906
  continue;
896
- const candidates = (await factsOf(parent)).filter((fact) => !fact.component);
907
+ const candidates = (await factsOf(parent)).filter((fact) => fact.component === (part.kind === "component"));
897
908
  for (const fact of candidates) {
898
909
  const shared = fact.classes.markers.filter((marker) => declaredMarkers.has(marker));
899
910
  if (shared.length > 1)
@@ -904,21 +915,23 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
904
915
  if (part.required && match === void 0)
905
916
  return fail(node, { kind: "part-missing-or-repeated", part: part.name });
906
917
  for (const shape of matches) {
907
- const tag = shape.opening.tagName.getText(), host = parent.tagName.getText();
918
+ const tag = values.tag(shape.opening), host = values.tag(parent);
908
919
  if (!VECTOR_SHAPES.includes(tag) || host !== "svg")
909
920
  return fail(shape.opening, { kind: "part-element-mismatch", part: part.name, expected: VECTOR_SHAPES.map((shapeTag) => `<svg> > <${shapeTag}>`), actual: `<${host}> > <${tag}>` });
910
921
  }
911
922
  continue;
912
923
  }
913
- if (matches.length > 1 || match?.repeated === !0 || part.required && match === void 0)
924
+ if (!part.repeat && (matches.length > 1 || match?.repeated === !0) || part.required && match === void 0)
914
925
  return fail(node, { kind: "part-missing-or-repeated", part: part.name });
915
926
  if (match === void 0)
916
927
  continue;
928
+ if (part.kind === "component")
929
+ continue;
917
930
  matched.set([...part.within, part.selector].join(" "), match.opening);
918
931
  const ariaHidden = attr(match.opening, "aria-hidden");
919
932
  if (tinted.has(part.name) && ariaHidden !== void 0 && (ariaHidden.initializer === void 0 || [!0, "true"].includes(await resolve(expression(ariaHidden), context))))
920
933
  decorative.add(part.name);
921
- const element = match.opening.tagName.getText(), hostless = part.pseudo.find((pseudo) => !PSEUDO_HOSTS[pseudo].includes(element));
934
+ const element = values.tag(match.opening), hostless = part.pseudo.find((pseudo) => !PSEUDO_HOSTS[pseudo].includes(element));
922
935
  if (hostless !== void 0)
923
936
  return fail(match.opening, { kind: "pseudo-host-unsupported", part: part.name, pseudo: hostless, element });
924
937
  await nativeElement(match.opening, part.element, part.name, parent, context, resolve);
@@ -939,9 +952,9 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
939
952
  if ((foundation.profiles.get(sequence)?.fields.repeat ?? "loop") !== "once")
940
953
  review(authoredAt(classes.calls, `${part.path}.play`) ?? node, { kind: "motion-endless", part: part.name, sequence });
941
954
  if (part.clamped) {
942
- const enclosing = part.within.map((_, index) => matched.get(part.within.slice(0, index + 1).join(" "))), control = [match.opening, ...enclosing.reverse(), opening].find((element) => element !== void 0 && CONTROL_TEXT_TAGS.includes(element.tagName.getText()));
955
+ const enclosing = part.within.map((_, index) => matched.get(part.within.slice(0, index + 1).join(" "))), control = [match.opening, ...enclosing.reverse(), opening].find((element) => element !== void 0 && CONTROL_TEXT_TAGS.includes(values.tag(element)));
943
956
  if (control !== void 0)
944
- return fail(match.opening, { kind: "clamp-on-control", part: part.name, element: `<${control.tagName.getText()}>` });
957
+ return fail(match.opening, { kind: "clamp-on-control", part: part.name, element: `<${values.tag(control)}>` });
945
958
  }
946
959
  guardChild(match, part.selector, part.within);
947
960
  if (part.kind === "text")
@@ -984,7 +997,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
984
997
  visuals.set(part.name, { fact: { kind: "inspected-svg" }, drawings: void 0 });
985
998
  continue;
986
999
  }
987
- if (match.classes.bindings.length === 0 && parsed.value.kind === "region" && match.opening.tagName.getText() === "img") {
1000
+ if (match.classes.bindings.length === 0 && parsed.value.kind === "region" && values.tag(match.opening) === "img") {
988
1001
  visual ??= { kind: "content-media" };
989
1002
  visuals.set(part.name, { fact: { kind: "content-media" }, drawings: void 0 });
990
1003
  continue;
@@ -1052,7 +1065,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1052
1065
  return fail(fact.opening, { kind: "markers-shared", markers: shared });
1053
1066
  }
1054
1067
  if (parsed.value.kind === "control" && !hasText && (visual !== void 0 || parsed.value.decor.length > 0) && !await namedByAttribute(opening, async (condition) => values.truthy(await resolve(condition, context), condition, context)))
1055
- return fail(opening, { kind: "control-name-missing", element: opening.tagName.getText() });
1068
+ return fail(opening, { kind: "control-name-missing", element: values.tag(opening) });
1056
1069
  const theme = visual?.kind === "asset" ? visual.theme : void 0, rootTheme = attr(opening, "data-theme"), boundThemes = [...new Set([...theme === void 0 ? [] : [theme.name], ...[...visuals.values()].flatMap(({ fact }) => fact.kind === "asset" ? [fact.theme.name] : [])])];
1057
1070
  if (rootTheme !== void 0 && boundThemes.length > 0) {
1058
1071
  const named = await resolve(expression(rootTheme), context), other = boundThemes.find((name) => name !== named);
@@ -1063,9 +1076,13 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1063
1076
  artworkThemed.add(opening);
1064
1077
  const inherited = new Map, aligned = new Map;
1065
1078
  for (const selector of declaredCells(parsed.value)) {
1066
- const cells = allFacts.filter((fact) => fact.classes.markers.includes(selector.slice(1))), [cell] = cells, single = cells.length === 1 && cell?.repeated === !1;
1067
- if (!/^\.[\w-]+$/.test(selector) || cell === void 0 || !single && !autoPlaced(parsed.value, selector))
1079
+ const cells = allFacts.filter((fact) => fact.classes.markers.includes(selector.slice(1))), [cell] = cells, declared = parsed.value.kind === "grid" ? parsed.value.cells.find((item) => item.selector === selector) : void 0, single = cells.length === 1 && cell?.repeated === !1, many = declared?.repeat === !0 || autoPlaced(parsed.value, selector);
1080
+ if (!/^\.[\w-]+$/.test(selector) || cell === void 0 && declared?.required !== !1 || cell !== void 0 && !single && !many)
1068
1081
  return fail(node, { kind: "cell-missing-or-repeated", cell: selector });
1082
+ if (declared !== void 0 && !declared.required && [declared.values, ...declared.at.map(([, values]) => values)].some((values) => values.some(([field]) => field === "row")))
1083
+ review(authoredAt(classes.calls, `recipe.cells.${selector}.row`) ?? node, { kind: "optional-cell-row", cell: selector });
1084
+ if (cell === void 0)
1085
+ continue;
1069
1086
  for (const each of cells)
1070
1087
  guardChild(each, selector);
1071
1088
  if (cell.classes.fragments.length === 0)
@@ -1173,7 +1190,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1173
1190
  fail(expression(attr(host, "className")) ?? host, missed);
1174
1191
  }, check = (place, spec, component) => tiles ? tileFrameFinding(foundation, place, spec, component, regions) : component !== null ? componentCellFinding(foundation, place.cell, component, regions) : spec === null ? null : frameRegionFinding(foundation, place, spec, regions, moved), inside = async (cell, host, path) => {
1175
1192
  for (const child of await children(host, context, resolve)) {
1176
- const step = lowercaseTag(child) ? { kind: "element", tag: child.tagName.getText(), spec: await constructionOf(child) } : { kind: "component", name: child.tagName.getText() };
1193
+ const step = lowercaseTag(child) ? { kind: "element", tag: values.tag(child), spec: await constructionOf(child) } : { kind: "component", name: values.tag(child) };
1177
1194
  if (step.kind === "element") {
1178
1195
  if (step.spec?.kind === "grid")
1179
1196
  continue;
@@ -1185,14 +1202,14 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1185
1202
  }
1186
1203
  }, visit = async (cell, opening) => {
1187
1204
  if (!lowercaseTag(opening)) {
1188
- report(check({ cell, element: null, path: [] }, null, opening.tagName.getText()), opening);
1205
+ report(check({ cell, element: null, path: [] }, null, values.tag(opening)), opening);
1189
1206
  return;
1190
1207
  }
1191
1208
  const own = await constructionOf(opening);
1192
1209
  report(check({ cell, element: null, path: [] }, own, null), opening);
1193
1210
  aligned({ cell, element: null, path: [] }, own, opening);
1194
1211
  if (own?.kind !== "grid")
1195
- return inside(cell, opening, [{ kind: "element", tag: opening.tagName.getText(), spec: own }]);
1212
+ return inside(cell, opening, [{ kind: "element", tag: values.tag(opening), spec: own }]);
1196
1213
  if (own.mode !== "inherited")
1197
1214
  return;
1198
1215
  for (const child of await children(opening, context, resolve)) {
@@ -1204,7 +1221,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1204
1221
  };
1205
1222
  if (tiles)
1206
1223
  for (const fact of allFacts)
1207
- await visit(`a tile <${fact.opening.tagName.getText()}>`, fact.opening);
1224
+ await visit(`a tile <${values.tag(fact.opening)}>`, fact.opening);
1208
1225
  else
1209
1226
  for (const selector of declaredCells(parsed.value))
1210
1227
  for (const fact of allFacts.filter((item) => item.classes.markers.includes(selector.slice(1))))
@@ -1398,10 +1415,10 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1398
1415
  for (const opening of openings) {
1399
1416
  if (!lowercaseTag(opening))
1400
1417
  continue;
1401
- const tag = opening.tagName.getText();
1418
+ const tag = values.tag(opening);
1402
1419
  if (tag === "img" && attr(opening, "alt") === void 0)
1403
1420
  return fail(opening, { kind: "image-alt-missing" });
1404
- if (clickWithoutKeyboard(opening))
1421
+ if (clickWithoutKeyboard(opening, tag))
1405
1422
  review(opening, { kind: "click-without-keyboard", element: tag });
1406
1423
  if (!sections && !artworkThemed.has(opening))
1407
1424
  for (const attribute of ["data-theme", "data-brand"]) {
@@ -1411,10 +1428,10 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1411
1428
  }
1412
1429
  }
1413
1430
  for (const opening of openings) {
1414
- const component = !lowercaseTag(opening), suggestion = missingAutocomplete(opening, component);
1431
+ const component = !lowercaseTag(opening), suggestion = missingAutocomplete(opening, component, values.tag(opening));
1415
1432
  if (suggestion === null || component && !await takesAutocomplete(opening))
1416
1433
  continue;
1417
- review(opening, { kind: "autocomplete-missing", element: opening.tagName.getText(), suggestion });
1434
+ review(opening, { kind: "autocomplete-missing", element: values.tag(opening), suggestion });
1418
1435
  }
1419
1436
  if (!openings.some((opening) => opening.attributes.properties.some((attribute) => isJsxAttribute(attribute) && /^on(?:Pointer|Touch)[A-Z]/.test(nameText(attribute.name) ?? ""))))
1420
1437
  for (const { at, element } of touchDisabled)
@@ -1726,7 +1743,7 @@ function presenceTest(identifier) {
1726
1743
  return !1;
1727
1744
  const operator = parent.operatorToken.kind;
1728
1745
  if (operator === SyntaxKind.AmpersandAmpersandToken)
1729
- return parent.left === node;
1746
+ return parent.left === node || presenceTest(parent);
1730
1747
  const equality = [SyntaxKind.EqualsEqualsEqualsToken, SyntaxKind.ExclamationEqualsEqualsToken, SyntaxKind.EqualsEqualsToken, SyntaxKind.ExclamationEqualsToken].includes(operator), other = parent.left === node ? parent.right : parent.left;
1731
1748
  return equality && (isIdentifier(other) && other.text === "undefined" || other.kind === SyntaxKind.NullKeyword);
1732
1749
  }
@@ -1,5 +1,5 @@
1
1
  import { selectedProfile, tokenDefinitionContexts } from "./design-foundation.mjs";
2
- import { inactiveCondition, layeredBackdrop, layeredContrast, opaque, readColor } from "./paint-contrast.mjs";
2
+ import { inactiveCondition, layeredBackdrop, layeredContrast, opaque, readColor, unshown } from "./paint-contrast.mjs";
3
3
  import { describeUnresolved, textMinimum } from "./surface-contrast.mjs";
4
4
  import { sectionsDeclared } from "./token-sections.mjs";
5
5
  export const NO_COMPOSITION = { positions: [] }, compositionLimits = Object.freeze({ chains: 512, hops: 24, backdrops: 256 });
@@ -44,6 +44,13 @@ export function composedContrastFindings(inputs) {
44
44
  const selected = selectedProfile(foundation, surface), fields = selected.kind === "ok" && selected.value.kind === "surface" ? selected.value.fields : null, paint = fields === null ? null : { color: fields.get("color") ?? null, background: fields.get("background") ?? null, backgroundImage: fields.get("background-image") ?? null, opacity: fields.get("opacity") ?? null };
45
45
  paints.set(surface, paint);
46
46
  return paint;
47
+ }, provided = new Map, providesOf = (surface) => {
48
+ const known = provided.get(surface);
49
+ if (known !== void 0)
50
+ return known;
51
+ const selected = selectedProfile(foundation, surface), roles = new Map(selected.kind === "ok" && selected.value.kind === "surface" ? [...selected.value.fields].filter(([field]) => field.startsWith("--")) : []);
52
+ provided.set(surface, roles);
53
+ return roles;
47
54
  }, documentElement = {
48
55
  owner: null,
49
56
  component: "the document",
@@ -72,10 +79,20 @@ export function composedContrastFindings(inputs) {
72
79
  return "the base context";
73
80
  const named = reported(context);
74
81
  return `${[named.theme ?? "the base context", ...named.brand === void 0 ? [] : [named.brand]].join(", ")}${named.condition === void 0 ? "" : ` under ${named.condition}`}`;
75
- }, FIRST = { index: 0, label: nameOf(contexts[0]) }, chainRelated = new Map, chains = [], emit = (walk, certain, top) => {
82
+ }, FIRST = { index: 0, label: nameOf(contexts[0]) }, evaluationKey = (elements) => {
83
+ let sized = !1;
84
+ return elements.flatMap((placed) => {
85
+ const { fact } = placed, text = sized ? null : fact.text;
86
+ if (fact.text !== null)
87
+ sized = !0;
88
+ if (placed.boundary === void 0 && fact.surfaces !== null && fact.surfaces.length === 0 && text === null && fact.flow === "in" && fact.context === null && fact.exempt === null && !UA_COLOR.has(fact.tag) && !UA_FILL.has(fact.tag))
89
+ return [];
90
+ return [[placed.owner, fact.scope ?? `${fact.at.file}:${fact.at.line}:${fact.at.column}`, fact.tag, fact.surfaces?.map((state) => [state.condition, state.surface]) ?? null, text, fact.flow, fact.context, fact.exempt, placed.boundary?.reason ?? null]];
91
+ });
92
+ }, chainRelated = new Map, chains = [], emit = (walk, certain, top) => {
76
93
  if (walk.elements.some((placed) => placed.fact.exempt !== null))
77
94
  return null;
78
- const elements = [...walk.elements, top], key = JSON.stringify([certain, elements.map((placed) => [placed.owner, placed.component, placed.fact, placed.boundary ?? null])]);
95
+ const elements = [...walk.elements, top], key = JSON.stringify([certain, evaluationKey(elements)]);
79
96
  let related = chainRelated.get(key);
80
97
  if (related === void 0) {
81
98
  chainRelated.set(key, related = new Map);
@@ -103,10 +120,13 @@ export function composedContrastFindings(inputs) {
103
120
  return !1;
104
121
  continue;
105
122
  }
106
- if (arg === void 0 || arg.value.kind !== "literal")
123
+ const value = arg === void 0 ? void 0 : arg.value.kind === "literal" ? arg.value.value : null;
124
+ if (arg === void 0 || typeof value === "object" && value !== null) {
125
+ if (prop.omitted === !1)
126
+ return !1;
107
127
  continue;
108
- const value = arg.value.value;
109
- if (typeof value === "object" && value !== null)
128
+ }
129
+ if (arg.value.kind !== "literal")
110
130
  continue;
111
131
  switch (prop.test) {
112
132
  case "text": {
@@ -206,7 +226,7 @@ export function composedContrastFindings(inputs) {
206
226
  note(source(placement.at), `it is rendered through <${content.tag}>${of}, a component ADS does not analyze: whether that wrapper paints a backdrop or passes the text on is unknown`, FIRST, walk.related);
207
227
  return;
208
228
  }
209
- if (helper(owner, content.target)) {
229
+ if (helper(owner, content.target) && placement.component !== content.target.name) {
210
230
  note(source(placement.at), sameFileReason(content.tag), FIRST, walk.related);
211
231
  return;
212
232
  }
@@ -250,8 +270,10 @@ export function composedContrastFindings(inputs) {
250
270
  for (const { owner, position } of placementsOf.get(key) ?? []) {
251
271
  if (!consistent(argsOf(position), frame.props))
252
272
  continue;
253
- const tag = position.content.kind === "placement" ? position.content.tag : frame.component;
254
- if (helper(owner, { file: frame.owner, name: frame.component })) {
273
+ const tag = position.content.kind === "placement" ? position.content.tag : frame.component, recursive = owner === frame.owner && position.component === frame.component, recursion = pointKey(position.at);
274
+ if (recursive && (walk.recursed ?? []).includes(recursion))
275
+ continue;
276
+ if (!recursive && helper(owner, { file: frame.owner, name: frame.component })) {
255
277
  steps.emit({ ...walk, related: [...walk.related, relatedOf(position.at, `rendered as <${tag}>`)] }, boundaryAt(position.at, position.component, sameFileReason(tag)));
256
278
  continue;
257
279
  }
@@ -264,7 +286,7 @@ export function composedContrastFindings(inputs) {
264
286
  continue;
265
287
  }
266
288
  for (const leaf of position.leaves.leaves)
267
- walkFrame({ owner, component: position.component, segments: leaf.segments, index: 0, props: leaf.props }, { ...walk, hops: walk.hops + 1, related: [...walk.related, relatedOf(position.at, `rendered as <${tag}>`)] }, mode, steps);
289
+ walkFrame({ owner, component: position.component, segments: leaf.segments, index: 0, props: leaf.props }, { ...walk, hops: walk.hops + 1, related: [...walk.related, relatedOf(position.at, `rendered as <${tag}>`)], ...recursive ? { recursed: [...walk.recursed ?? [], recursion] } : {} }, mode, steps);
268
290
  }
269
291
  for (const placement of plainOf.get(key) ?? [])
270
292
  steps.emit({ ...walk, related: [...walk.related, relatedOf(placement.at, `rendered as <${placement.tag}> in ${placement.module}`)] }, boundaryAt(placement.at, frame.component, `${frame.component} is placed as <${placement.tag}> in ${placement.module}, a plain module whose composition ADS does not follow, so the backdrop ${frame.component} is rendered on there is unknown`));
@@ -379,66 +401,125 @@ export function composedContrastFindings(inputs) {
379
401
  note(b.site, b.reason, contextLabel(index), related);
380
402
  continue;
381
403
  }
382
- const terminal = b.layers.at(-1);
383
- if (terminal === void 0)
384
- continue;
385
- if (b.layers.length === 1 && terminal.element === f.element)
386
- continue;
387
- const above = opacityAbove(terminal.element);
388
- if (above !== void 0) {
389
- note(siteOf(above.placed, above.state.at), `${describeUnresolved({ kind: "opacity", value: paintOf(above.state.surface)?.opacity ?? "" })}: it fades the text and its backdrop together`, contextLabel(index), related);
390
- continue;
391
- }
392
- const backdrop = layeredBackdrop(context, b.layers);
393
- if (backdrop.kind === "unresolved") {
394
- const layer = b.layers[backdrop.layer] ?? terminal, placed = elements[layer.element];
395
- if (placed !== void 0)
396
- note(siteOf(placed, layer.state.at), describeUnresolved(backdrop.unresolved), contextLabel(index), related);
397
- continue;
398
- }
399
- const minimum = textMinimum(text, context), outcome = layeredContrast(context, f.value, backdrop.colors, minimum), foreElement = elements[f.element];
400
- if (foreElement === void 0)
401
- continue;
402
- switch (outcome.kind) {
403
- case "sufficient":
404
- break;
405
- case "unresolved":
406
- note(siteOf(foreElement, f.state.at), describeUnresolved(outcome.unresolved), contextLabel(index), related);
407
- break;
408
- case "insufficient": {
409
- const worst = b.layers[outcome.worst.layer] ?? terminal, backElement = elements[worst.element];
410
- if (backElement === void 0)
404
+ for (const variant of providedVariants(elements, f, b)) {
405
+ if (variant.requires.some((condition) => variant.excludes.includes(condition)))
406
+ continue;
407
+ const { value, layers } = variant, terminal = layers.at(-1);
408
+ if (terminal === void 0)
409
+ continue;
410
+ if (layers.length === 1 && terminal.element === f.element && !variant.changed)
411
+ continue;
412
+ const above = opacityAbove(terminal.element);
413
+ if (above !== void 0) {
414
+ note(siteOf(above.placed, above.state.at), `${describeUnresolved({ kind: "opacity", value: paintOf(above.state.surface)?.opacity ?? "" })}: it fades the text and its backdrop together`, contextLabel(index), related);
415
+ continue;
416
+ }
417
+ if (unshown(value, context))
418
+ continue;
419
+ const backdrop = layeredBackdrop(context, layers);
420
+ if (backdrop.kind === "unresolved") {
421
+ const layer = layers[backdrop.layer] ?? terminal, placed = elements[layer.element];
422
+ if (placed !== void 0)
423
+ note(siteOf(placed, layer.state.at), describeUnresolved(backdrop.unresolved), contextLabel(index), related);
424
+ continue;
425
+ }
426
+ const minimum = textMinimum(text, context), outcome = layeredContrast(context, value, backdrop.colors, minimum), foreElement = elements[f.element];
427
+ if (foreElement === void 0)
428
+ continue;
429
+ switch (outcome.kind) {
430
+ case "sufficient":
431
+ break;
432
+ case "unresolved":
433
+ note(siteOf(foreElement, f.state.at), describeUnresolved(outcome.unresolved), contextLabel(index), related);
411
434
  break;
412
- const backPaint = paintOf(worst.state.surface), backToken = (outcome.worst.image ? backPaint?.backgroundImage : backPaint?.background) ?? worst.state.surface, foregroundSite = siteOf(foreElement, f.state.at), backdropSite = siteOf(backElement, worst.state.at);
413
- if (!chain.certain) {
414
- note(foregroundSite.kind === "source" ? foregroundSite : backdropSite, `the expression it renders may be text: ${tokenOf(f.value)} on ${tokenOf(backToken)} is ${outcome.ratio}:1, below ${minimum}:1, if it is`, contextLabel(index), related);
435
+ case "insufficient": {
436
+ const worst = layers[outcome.worst.layer] ?? terminal, backElement = elements[worst.element];
437
+ if (backElement === void 0)
438
+ break;
439
+ const backPaint = paintOf(worst.state.surface), backToken = (outcome.worst.image ? backPaint?.backgroundImage : backPaint?.background) ?? worst.state.surface, foregroundSite = siteOf(foreElement, f.state.at), backdropSite = siteOf(backElement, worst.state.at);
440
+ if (!chain.certain) {
441
+ note(foregroundSite.kind === "source" ? foregroundSite : backdropSite, `the expression it renders may be text: ${tokenOf(value)} on ${tokenOf(backToken)} is ${outcome.ratio}:1, below ${minimum}:1, if it is`, contextLabel(index), related);
442
+ break;
443
+ }
444
+ const terminalElement = elements[terminal.element], over = worst === terminal || terminalElement === void 0 ? null : {
445
+ side: { component: terminalElement.component, surface: terminal.state.surface, token: tokenOf(paintOf(terminal.state.surface)?.background ?? terminal.state.surface) },
446
+ site: siteOf(terminalElement, terminal.state.at)
447
+ }, groupKey = JSON.stringify([siteKey(foregroundSite), siteKey(backdropSite), value, backToken, over === null ? null : siteKey(over.site)]), group = failures.get(groupKey) ?? {
448
+ over,
449
+ site: foregroundSite.kind === "source" ? foregroundSite : backdropSite,
450
+ foreground: { component: foreElement.component, surface: f.state.surface, token: tokenOf(value) },
451
+ background: { component: backElement.component, surface: worst.state.surface, token: tokenOf(backToken) },
452
+ foregroundSite,
453
+ backdropSite,
454
+ contexts: new Map,
455
+ related: new Map
456
+ };
457
+ failures.set(groupKey, group);
458
+ const failure = { ratio: outcome.ratio, minimum, foreground: outcome.foreground, background: outcome.background, states: [stateOf(f.requires), stateOf(b.requires.at(-1) ?? null)] }, known = group.contexts.get(index);
459
+ if (known === void 0 || failure.ratio < known.ratio)
460
+ group.contexts.set(index, failure);
461
+ for (const item of related)
462
+ group.related.set(siteKey(item.site), item);
415
463
  break;
416
464
  }
417
- const terminalElement = elements[terminal.element], over = worst === terminal || terminalElement === void 0 ? null : {
418
- side: { component: terminalElement.component, surface: terminal.state.surface, token: tokenOf(paintOf(terminal.state.surface)?.background ?? terminal.state.surface) },
419
- site: siteOf(terminalElement, terminal.state.at)
420
- }, groupKey = JSON.stringify([siteKey(foregroundSite), siteKey(backdropSite), f.value, backToken, over === null ? null : siteKey(over.site)]), group = failures.get(groupKey) ?? {
421
- over,
422
- site: foregroundSite.kind === "source" ? foregroundSite : backdropSite,
423
- foreground: { component: foreElement.component, surface: f.state.surface, token: tokenOf(f.value) },
424
- background: { component: backElement.component, surface: worst.state.surface, token: tokenOf(backToken) },
425
- foregroundSite,
426
- backdropSite,
427
- contexts: new Map,
428
- related: new Map
429
- };
430
- failures.set(groupKey, group);
431
- const failure = { ratio: outcome.ratio, minimum, foreground: outcome.foreground, background: outcome.background, states: [stateOf(f.requires), stateOf(b.requires.at(-1) ?? null)] }, known = group.contexts.get(index);
432
- if (known === void 0 || failure.ratio < known.ratio)
433
- group.contexts.set(index, failure);
434
- for (const item of related)
435
- group.related.set(siteKey(item.site), item);
436
- break;
437
465
  }
438
466
  }
439
467
  }
440
468
  });
441
469
  }
470
+ function providedVariants(elements, f, b) {
471
+ const base = { value: f.value, layers: b.layers, requires: [...f.requires === null ? [] : [f.requires], ...b.requires], excludes: [...f.excludes, ...b.excludes], changed: !1 };
472
+ if (!elements.some((placed) => (placed.fact.surfaces ?? []).some((state) => providesOf(state.surface).size > 0)))
473
+ return [base];
474
+ const resolve = (value, from, depth) => {
475
+ const tokens = [...new Set([...value.matchAll(/var\(\s*(--[\w-]+)/g)].map((match) => match[1] ?? ""))];
476
+ let results = [{ value, requires: [], excludes: [], changed: !1 }];
477
+ for (const token of tokens) {
478
+ const options = depth > 4 ? [] : bindings(token, from, depth);
479
+ if (options.length === 0)
480
+ continue;
481
+ results = results.flatMap((result) => options.map((option) => ({
482
+ value: option.value === null ? result.value : result.value.replaceAll(new RegExp(`var\\(\\s*${token}\\s*\\)`, "g"), option.value),
483
+ requires: [...result.requires, ...option.requires],
484
+ excludes: [...result.excludes, ...option.excludes],
485
+ changed: result.changed || option.value !== null
486
+ })));
487
+ if (results.length > compositionLimits.backdrops)
488
+ return results.slice(0, compositionLimits.backdrops);
489
+ }
490
+ return results;
491
+ }, bindings = (token, from, depth) => {
492
+ const out = [];
493
+ let passed = [];
494
+ for (let index = from;index < elements.length; index++) {
495
+ const placed = elements[index];
496
+ if (placed === void 0)
497
+ break;
498
+ const states = (placed.fact.surfaces ?? []).filter((state) => providesOf(state.surface).has(token));
499
+ if (states.length === 0)
500
+ continue;
501
+ const conditions = states.flatMap((state) => state.condition === null ? [] : [conditionKey(placed, state.condition)]);
502
+ for (const state of states) {
503
+ const raw = providesOf(state.surface).get(token) ?? "", requires = state.condition === null ? [] : [conditionKey(placed, state.condition)], excludes = state.condition === null ? [...passed, ...conditions] : passed;
504
+ for (const inner of resolve(raw, index, depth + 1))
505
+ out.push({ value: inner.value, requires: [...requires, ...inner.requires], excludes: [...excludes, ...inner.excludes] });
506
+ }
507
+ if (states.some((state) => state.condition === null))
508
+ return out;
509
+ passed = [...passed, ...conditions];
510
+ }
511
+ out.push({ value: null, requires: [], excludes: passed });
512
+ return out;
513
+ };
514
+ let variants = resolve(f.value, f.element, 0).map((fore) => ({ value: fore.value, layers: [], requires: [...base.requires, ...fore.requires], excludes: [...base.excludes, ...fore.excludes], changed: fore.changed }));
515
+ for (const layer of b.layers) {
516
+ const options = layer.background === null ? [null] : resolve(layer.background, layer.element, 0);
517
+ variants = variants.flatMap((variant) => options.map((option) => option === null ? { ...variant, layers: [...variant.layers, layer] } : { value: variant.value, layers: [...variant.layers, { ...layer, background: option.value }], requires: [...variant.requires, ...option.requires], excludes: [...variant.excludes, ...option.excludes], changed: variant.changed || option.changed }));
518
+ if (variants.length > compositionLimits.backdrops)
519
+ variants = variants.slice(0, compositionLimits.backdrops);
520
+ }
521
+ return variants;
522
+ }
442
523
  function foregroundOptions(elements) {
443
524
  const options = [];
444
525
  let excludes = [];
@@ -48,7 +48,12 @@ export function output(root, operation, reject, profile) {
48
48
  use(own);
49
49
  declarations.push([name, own]);
50
50
  }
51
- checked(session.write({ selector, conditions: condition === void 0 ? [] : [{ name: condition[0], params: condition[1] }], values: declarations, important: !1 }));
51
+ const conditions = condition === void 0 ? [] : [{ name: condition[0], params: condition[1] }], roles = declarations.filter(([property]) => property.startsWith("--"));
52
+ if (roles.length > 0)
53
+ checked(session.writeProvidedRoles({ selector, conditions, values: roles, important: !1 }));
54
+ const rest = declarations.filter(([property]) => !property.startsWith("--"));
55
+ if (rest.length > 0 || roles.length === 0)
56
+ checked(session.write({ selector, conditions, values: rest, important: !1 }));
52
57
  },
53
58
  tree: (node) => checked(session.writeTree(node, root)),
54
59
  document: (rule) => session.writeDocument(rule),