@reqvire-org/ads 0.5.4 → 0.5.5

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 (95) hide show
  1. package/dist/ads-errors.mjs +105 -8
  2. package/dist/analysis/client-directive.mjs +26 -0
  3. package/dist/analysis/externals.mjs +47 -0
  4. package/dist/analysis/module-graph.mjs +6 -0
  5. package/dist/analysis/owner-analysis-key.mjs +1 -1
  6. package/dist/analysis/owner-choices.mjs +12 -2
  7. package/dist/analysis/owner-composition.mjs +19 -4
  8. package/dist/analysis/owner-source.mjs +112 -15
  9. package/dist/border-paint.mjs +34 -0
  10. package/dist/check.mjs +2 -0
  11. package/dist/composed-contrast.mjs +10 -7
  12. package/dist/construction-output.mjs +52 -27
  13. package/dist/construction-spec.d.mts +40 -10
  14. package/dist/construction-spec.mjs +41 -17
  15. package/dist/corner-overpaint.mjs +3 -1
  16. package/dist/design-foundation.mjs +14 -0
  17. package/dist/emit/owner-emission-cache.mjs +1 -1
  18. package/dist/end-alignment.mjs +69 -0
  19. package/dist/external-macro.d.mts +20 -0
  20. package/dist/external-macro.mjs +12 -0
  21. package/dist/finding-rules.mjs +3 -0
  22. package/dist/forced-colors.mjs +81 -0
  23. package/dist/frame-regions.mjs +2 -2
  24. package/dist/guard/externals.mjs +64 -0
  25. package/dist/guard/run.mjs +9 -5
  26. package/dist/inventories.mjs +1 -1
  27. package/dist/lowering-layer.mjs +38 -4
  28. package/dist/lowering-overlaps.mjs +7 -0
  29. package/dist/lowering-properties.mjs +1 -0
  30. package/dist/lowering-region-layout.mjs +22 -3
  31. package/dist/lowering-session.mjs +1 -1
  32. package/dist/mcp/preview-http.bundle.js +2 -2
  33. package/dist/mcp/preview-widget.bundle.js +12 -12
  34. package/dist/measured-geometry.mjs +8 -2
  35. package/dist/owner-analysis-check.mjs +190 -11
  36. package/dist/owner-errors.mjs +3 -0
  37. package/dist/owner-lowering.mjs +3 -2
  38. package/dist/ownership-model.mjs +6 -3
  39. package/dist/platform-features.mjs +1 -0
  40. package/dist/preview-bun.mjs +15 -2
  41. package/dist/profile-macro.d.mts +18 -0
  42. package/dist/recipe-macro.d.mts +49 -6
  43. package/dist/recipe-model.mjs +13 -5
  44. package/dist/region-lowering.mjs +115 -22
  45. package/dist/render-audit/axe-run.page.mjs +40 -1
  46. package/dist/render-audit/forced-states.page.mjs +37 -0
  47. package/dist/render-audit/layout-overflow.page.mjs +52 -2
  48. package/dist/render-audit/non-text-contrast.page.mjs +14 -10
  49. package/dist/render-audit/worker.mjs +38 -0
  50. package/dist/render-audit.mjs +42 -5
  51. package/dist/role-vocabulary.d.mts +2 -2
  52. package/dist/role-vocabulary.mjs +3 -3
  53. package/dist/scenario-kit.d.mts +2 -2
  54. package/dist/showcase/assets-view.mjs +12 -47
  55. package/dist/showcase/client.bundle.js +54 -54
  56. package/dist/showcase/http-client.bundle.js +18 -18
  57. package/dist/showcase/token-sample.mjs +2 -2
  58. package/dist/showcase/ui/ui.css +1 -1
  59. package/dist/showcase/ui/ui.js +13 -13
  60. package/dist/skills/ads-designer/references/accessibility.md +21 -1
  61. package/dist/skills/ads-designer/references/branding.md +4 -0
  62. package/dist/skills/ads-designer/references/design-data.md +6 -0
  63. package/dist/skills/ads-designer/references/layers.md +5 -0
  64. package/dist/skills/ads-designer/references/layout.md +8 -1
  65. package/dist/skills/ads-designer/references/recipes.md +36 -0
  66. package/dist/skills/ads-designer/references/runtimes.md +4 -0
  67. package/dist/skills/ads-designer/references/scenarios.md +2 -0
  68. package/dist/skills/ads-import/references/design-data.md +6 -0
  69. package/dist/skills/ads-import/references/layers.md +5 -0
  70. package/dist/skills/ads-import/references/layout.md +8 -1
  71. package/dist/skills/ads-import/references/recipes.md +36 -0
  72. package/dist/skills/ads-import/references/runtimes.md +4 -0
  73. package/dist/skills/ads-import/references/scenarios.md +2 -0
  74. package/dist/skills/ads-migrate/SKILL.md +1 -0
  75. package/dist/skills/ads-migrate/references/0.5.4-to-0.5.5.md +61 -0
  76. package/dist/skills/ads-port/references/design-data.md +6 -0
  77. package/dist/skills/ads-port/references/layers.md +5 -0
  78. package/dist/skills/ads-port/references/layout.md +8 -1
  79. package/dist/skills/ads-port/references/recipes.md +36 -0
  80. package/dist/skills/ads-port/references/runtimes.md +4 -0
  81. package/dist/skills/ads-port/references/scenarios.md +2 -0
  82. package/dist/spatial-model.mjs +37 -10
  83. package/dist/system-colors.d.mts +9 -0
  84. package/dist/system-colors.mjs +1 -0
  85. package/dist/target-size.mjs +14 -1
  86. package/dist/tsconfig.declarations.json +1 -0
  87. package/docs/ADS.md +23 -1
  88. package/docs/ASSETS.md +21 -0
  89. package/docs/CACHING.md +1 -1
  90. package/docs/CHANGELOG.md +167 -21
  91. package/docs/GUIDE.md +31 -20
  92. package/docs/LANGUAGE.md +118 -6
  93. package/docs/PROFILE-KINDS.md +50 -4
  94. package/docs/RULES.md +21 -8
  95. package/package.json +5 -1
@@ -9,7 +9,7 @@ export const ACCESSIBILITY_BOUNDARIES = ["visible-label", "boundary-on-interacti
9
9
  translateInline: { channel: "translate", field: "distance" },
10
10
  translateBlock: { channel: "translate", field: "distance" },
11
11
  rotate: { channel: "rotate", field: "angle" }
12
- }, scaleValue = (effect, value) => effect === "scale" ? value : effect === "scaleInline" || effect === "scale-inline" ? `${value} 1` : `1 ${value}`, STICKY_EDGES = ["block-start", "block-end"], ENTER_MOVEMENTS = { translate: "distance", translateInline: "distance", scale: "scale", rotate: "angle" }, PSEUDO_ELEMENTS = ["placeholder", "progressValue", "marker", "before"], REPLACED_ELEMENTS = ["img", "input", "select", "textarea", "video", "iframe", "br", "hr", "svg"], PSEUDO_HOSTS = { placeholder: ["input", "textarea"], progressValue: ["progress"], marker: ["li", "summary"], before: "non-replaced" }, pseudoHosted = (pseudo, element) => {
12
+ }, scaleValue = (effect, value) => effect === "scale" ? value : effect === "scaleInline" || effect === "scale-inline" ? `${value} 1` : `1 ${value}`, STICKY_EDGES = ["block-start", "block-end"], ENTER_MOVEMENTS = { translate: "distance", translateInline: "distance", scale: "scale", rotate: "angle" }, PSEUDO_ELEMENTS = ["placeholder", "progressValue", "marker", "before", "sliderTrack", "sliderThumb"], REPLACED_ELEMENTS = ["img", "input", "select", "textarea", "video", "iframe", "br", "hr", "svg"], PSEUDO_HOSTS = { placeholder: ["input", "textarea"], progressValue: ["progress"], marker: ["li", "summary"], before: "non-replaced", sliderTrack: ["input"], sliderThumb: ["input"] }, pseudoHosted = (pseudo, element) => {
13
13
  const hosts = PSEUDO_HOSTS[pseudo];
14
14
  return hosts === "non-replaced" ? !REPLACED_ELEMENTS.includes(element) : hosts.includes(element);
15
15
  }, MARKER_STYLES = ["disc", "circle", "square", "none", "decimal", "decimal-leading-zero", "lower-alpha", "upper-alpha", "lower-roman", "upper-roman"], COUNTER_STYLES = ["decimal", "decimal-leading-zero", "lower-alpha", "upper-alpha", "lower-roman", "upper-roman"], SNAP_TYPES = ["inline mandatory", "inline proximity", "block mandatory", "block proximity", "both mandatory", "both proximity"], SNAP_ALIGNS = ["start", "center", "end"], GEOMETRY_CHANNELS = ["size", "inset", "gap", "radius", "border-width", "overlap"], FRAME_SIDES = ["block-start", "block-end", "inline-start", "inline-end"], FRAME_CORNERS = ["start-start", "start-end", "end-start", "end-end"], CORNER_RADIUS_FIELDS = {
@@ -17,7 +17,7 @@ export const ACCESSIBILITY_BOUNDARIES = ["visible-label", "boundary-on-interacti
17
17
  "start-end": "start-end-radius",
18
18
  "end-start": "end-start-radius",
19
19
  "end-end": "end-end-radius"
20
- }, cornerRadius = (field, corner) => field(CORNER_RADIUS_FIELDS[corner]) ?? field("radius"), OVERFLOW_VALUES = ["clip", "scroll-block", "scroll-inline", "scroll-both"], ELEMENT_NAMES = ["iframe", "select", "search-input", "text-input", "table", "header-cell", "cell", "list", "summary"], TEXT_WRAPS = ["anywhere", "never", "truncate", "balance", "pretty"], TEXT_ALIGNS = ["start", "center", "end"], MEASURED_TYPES = ["length", "transform", "size-track", "position", "intrinsic-size"], GRID_FIELDS = ["columns", "weights", "gutter", "margin", "bound", "rows", "context", "align"];
20
+ }, cornerRadius = (field, corner) => field(CORNER_RADIUS_FIELDS[corner]) ?? field("radius"), OVERFLOW_VALUES = ["clip", "scroll-block", "scroll-inline", "scroll-both"], ELEMENT_NAMES = ["iframe", "select", "search-input", "text-input", "table", "header-cell", "cell", "list", "summary", "document"], TEXT_WRAPS = ["anywhere", "never", "truncate", "balance", "pretty", "preserve"], TEXT_ALIGNS = ["start", "center", "end"], MEASURED_TYPES = ["length", "transform", "scale", "size-track", "position", "intrinsic-size"], GRID_FIELDS = ["columns", "weights", "gutter", "margin", "bound", "rows", "context", "align", "contentFrom"];
21
21
  export function elementTags(element) {
22
22
  switch (element.kind) {
23
23
  case "iframe":
@@ -30,6 +30,8 @@ export function elementTags(element) {
30
30
  return [element.header ? "th" : "td"];
31
31
  case "list":
32
32
  return ["ul", "ol"];
33
+ case "document":
34
+ return ["html"];
33
35
  }
34
36
  }
35
37
  export const CONTROL_TEXT_TAGS = ["button", "label", "legend", "summary", "select", "option", "input", "textarea"], VECTOR_SHAPES = ["line", "path", "circle", "rect", "polyline"];
@@ -376,26 +378,29 @@ function artwork(spec, read) {
376
378
  }
377
379
  const REGION_LAYOUTS = ["inline", "stack", "flow", "layered"], ROOT_LAYOUTS = REGION_LAYOUTS;
378
380
  export const ROOT_EXTENTS = ["content", "container"];
379
- function rootExtent(value, layout, layer, read) {
381
+ function rootExtent(value, layout, layer, read, table = !1) {
380
382
  if (value === void 0)
381
383
  return "content";
382
- if (layout !== "inline" || layer !== null)
384
+ if (layout !== "inline" && !table || layer !== null)
383
385
  return read.reject({ kind: "field-unsupported", construction: "region", path: "recipe.extent" });
384
386
  return read.literal(value, "recipe.extent", ROOT_EXTENTS);
385
387
  }
386
388
  function arrangement(spec, read, path, layout) {
387
- const gap = spec.gap ?? spec.rowGap;
389
+ const gap = spec.gap ?? spec.rowGap, rowGap = spec.gap !== void 0 && spec.rowGap !== void 0 ? spec.rowGap : void 0;
388
390
  if (layout === "layered") {
389
391
  for (const field of ["gap", "rowGap", "wrap"])
390
392
  if (spec[field] !== void 0)
391
393
  read.reject({ kind: "field-unsupported", construction: "region", path: `${path}.${field}` });
392
394
  }
395
+ if (layout === "layered" && typeof spec.justify === "string" && spec.justify.startsWith("space-"))
396
+ read.reject({ kind: "field-unsupported", construction: "region", path: `${path}.justify` });
393
397
  return {
394
398
  layout,
395
399
  align: read.optionalString(spec.align, `${path}.align`),
396
400
  justify: read.optionalString(spec.justify, `${path}.justify`),
397
401
  wrap: read.boolean(spec.wrap, `${path}.wrap`),
398
402
  gap: gap === void 0 ? null : read.slot(gap, `${path}.gap`, "spacing"),
403
+ ...rowGap === void 0 ? {} : { rowGap: read.slot(rowGap, `${path}.rowGap`, "spacing") },
399
404
  overlap: overlapSpec(spec, read, path, layout),
400
405
  snap: snap(spec.snap, `${path}.snap`, read)
401
406
  };
@@ -661,14 +666,15 @@ function pseudoTreatments(value, path, read) {
661
666
  if (value === void 0)
662
667
  return [];
663
668
  return Object.entries(read.object(value, path)).map(([name, treatment]) => {
664
- const at = `${path}.${name}`, pseudo = read.literal(name, at, PSEUDO_ELEMENTS), fields = read.object(treatment, at), generated = pseudo === "marker" || pseudo === "before";
665
- read.only(fields, at, generated ? ["surface", "text", "content", "when"] : ["surface", "when"]);
669
+ const at = `${path}.${name}`, pseudo = read.literal(name, at, PSEUDO_ELEMENTS), fields = read.object(treatment, at), generated = pseudo === "marker" || pseudo === "before", slider = pseudo === "sliderTrack" || pseudo === "sliderThumb";
670
+ read.only(fields, at, generated ? ["surface", "text", "content", "when"] : slider ? ["surface", "frame", "when"] : ["surface", "when"]);
666
671
  const surface = generated ? read.optionalString(fields.surface, `${at}.surface`) : read.string(fields.surface, `${at}.surface`), text = read.optionalString(fields.text, `${at}.text`), content = generatedContent(fields.content, `${at}.content`, read);
667
672
  if (pseudo === "before" && content === null)
668
673
  read.invalid(`${at}.content`, "the generated content `before` shows (a counter)");
669
674
  if (pseudo === "marker" && surface === null && text === null && content === null)
670
675
  read.invalid(at, "a `surface`, a `text`, a `content` or several");
671
- return { pseudo, surface, text, content, when: treatments(fields.when, `${at}.when`, read) };
676
+ const frame = slider ? read.string(fields.frame, `${at}.frame`) : null;
677
+ return { pseudo, surface, text, content, ...slider ? { frame } : {}, when: treatments(fields.when, `${at}.when`, read) };
672
678
  });
673
679
  }
674
680
  function frameBorder(value, path, read) {
@@ -847,7 +853,9 @@ function overflow(value, path, read) {
847
853
  return { kind: "scroll", axis: "both" };
848
854
  }
849
855
  }
850
- function elementKind(value, marker, path, read) {
856
+ function elementKind(value, marker, path, read, align) {
857
+ if (align !== void 0 && value !== "cell" && value !== "header-cell")
858
+ read.reject({ kind: "field-unsupported", construction: "region", path: `${path}.align` });
851
859
  if (value === void 0) {
852
860
  if (marker !== void 0)
853
861
  read.reject({ kind: "field-unsupported", construction: "region", path: `${path}.marker` });
@@ -862,14 +870,17 @@ function elementKind(value, marker, path, read) {
862
870
  case "table":
863
871
  case "list":
864
872
  return { kind: name };
873
+ case "document":
874
+ if (path !== "recipe")
875
+ read.reject({ kind: "field-unsupported", construction: "region", path: `${path}.element` });
876
+ return { kind: name };
865
877
  case "search-input":
866
878
  return { kind: "input", type: "search" };
867
879
  case "text-input":
868
880
  return { kind: "input", type: "text" };
869
881
  case "header-cell":
870
- return { kind: "cell", header: !0 };
871
882
  case "cell":
872
- return { kind: "cell", header: !1 };
883
+ return { kind: "cell", header: name === "header-cell", align: align === void 0 ? "center" : read.literal(align, `${path}.align`, ["start", "center", "end"]) };
873
884
  case "summary":
874
885
  return { kind: "summary", marker: marker === void 0 ? "native" : read.literal(marker, `${path}.marker`, ["native", "none"]) };
875
886
  }
@@ -966,6 +977,15 @@ function measuredValues(value, path, read) {
966
977
  read.only(offset, `${at}.fallback`, ["x", "y"]);
967
978
  return { type, name, property, fallback: { x: pixels(offset.x, `${at}.fallback.x`, read), y: pixels(offset.y, `${at}.fallback.y`, read) }, motion };
968
979
  }
980
+ case "scale": {
981
+ read.only(fields, at, ["type", "property", "fallback", "motion"]);
982
+ if (fallback === void 0)
983
+ return { type, name, property, fallback: null, motion };
984
+ const factors = read.object(fallback, `${at}.fallback`);
985
+ read.only(factors, `${at}.fallback`, ["x", "y"]);
986
+ const factor = (value, path) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : read.invalid(path, "a positive scale factor");
987
+ return { type, name, property, fallback: { x: factor(factors.x, `${at}.fallback.x`), y: factor(factors.y, `${at}.fallback.y`) }, motion };
988
+ }
969
989
  case "size-track": {
970
990
  read.only(fields, at, ["type", "property", "track", "fallback", "motion"]);
971
991
  const track = fields.track;
@@ -1056,6 +1076,7 @@ function regionPart(name, value, read, path, nested) {
1056
1076
  "at",
1057
1077
  "element",
1058
1078
  "marker",
1079
+ "align",
1059
1080
  "media",
1060
1081
  "stroke",
1061
1082
  "accessibility",
@@ -1104,7 +1125,7 @@ function regionPart(name, value, read, path, nested) {
1104
1125
  overflow: overflow(part.overflow, `${path}.overflow`, read),
1105
1126
  extent: extent(part.extent, `${path}.extent`, read),
1106
1127
  at: partConditions(part.at, `${path}.at`, read),
1107
- element: elementKind(part.element, part.marker, path, read),
1128
+ element: elementKind(part.element, part.marker, path, read, part.align),
1108
1129
  text: textBinding(part.text, `${path}.text`, read),
1109
1130
  surface: read.optionalString(part.surface, `${path}.surface`),
1110
1131
  frame: boxed === null ? controlFrame(part.frame, `${path}.frame`, read) : null,
@@ -1243,6 +1264,7 @@ function region(authored, read) {
1243
1264
  "counter",
1244
1265
  "markers",
1245
1266
  "between",
1267
+ "carry",
1246
1268
  "parts",
1247
1269
  "exposeRows",
1248
1270
  "layer",
@@ -1274,16 +1296,17 @@ function region(authored, read) {
1274
1296
  counter: counterSpec(spec.counter, "recipe.counter", read),
1275
1297
  markers: markerStyles(spec.markers, "recipe.markers", read),
1276
1298
  between: betweenRule(spec.between, "recipe.between", read),
1299
+ carry: read.boolean(spec.carry, "recipe.carry"),
1277
1300
  profile: read.optionalString(spec.profile, "recipe.profile"),
1278
1301
  select: Object.fromEntries(spec.select === void 0 ? [] : read.stringRecord(spec.select, "recipe.select")),
1279
1302
  arrangement: arrangement(spec, read, "recipe", layout),
1280
- extent: rootExtent(spec.extent, layout, layer, read),
1303
+ extent: rootExtent(spec.extent, layout, layer, read, spec.element === "table"),
1281
1304
  frame: regionFrame(spec.frame, read),
1282
1305
  surface: read.optionalString(spec.surface, "recipe.surface"),
1283
1306
  text: textBinding(spec.text, "recipe.text", read),
1284
1307
  textAlign: spec.textAlign === void 0 ? null : read.literal(spec.textAlign, "recipe.textAlign", TEXT_ALIGNS),
1285
1308
  overflow: overflow(spec.overflow, "recipe.overflow", read),
1286
- element: elementKind(spec.element, spec.marker, "recipe", read),
1309
+ element: elementKind(spec.element, spec.marker, "recipe", read, spec.element === "cell" || spec.element === "header-cell" ? spec.align : void 0),
1287
1310
  normalize: normalized.values,
1288
1311
  normalizeWhen: normalized.when,
1289
1312
  when: rootStates.when,
@@ -1304,7 +1327,7 @@ function region(authored, read) {
1304
1327
  paints
1305
1328
  };
1306
1329
  }
1307
- const EDGES = ["start", "end"];
1330
+ const EDGES = ["start", "end"], DIALOG_EDGES = ["start", "end", "center", "block-start"];
1308
1331
  function layerSpec(value, read) {
1309
1332
  if (value === void 0)
1310
1333
  return null;
@@ -1314,15 +1337,16 @@ function layerSpec(value, read) {
1314
1337
  read.only(layer, path, ["element", "edge", "backdrop", "motion", "modalBelow"]);
1315
1338
  const backdrop = read.object(layer.backdrop, `${path}.backdrop`);
1316
1339
  read.only(backdrop, `${path}.backdrop`, ["surface", "dismiss"]);
1340
+ const edge = read.literal(layer.edge, `${path}.edge`, DIALOG_EDGES), card = edge === "center" || edge === "block-start";
1317
1341
  return {
1318
1342
  kind: "modal-sheet",
1319
1343
  element,
1320
- edge: read.literal(layer.edge, `${path}.edge`, EDGES),
1344
+ edge,
1321
1345
  backdrop: {
1322
1346
  surface: read.string(backdrop.surface, `${path}.backdrop.surface`),
1323
1347
  dismiss: backdrop.dismiss === void 0 ? "none" : read.literal(backdrop.dismiss, `${path}.backdrop.dismiss`, ["press", "none"])
1324
1348
  },
1325
- motion: layer.motion === void 0 ? null : read.literal(layer.motion, `${path}.motion`, ["slide"]),
1349
+ motion: layer.motion === void 0 ? null : card ? read.literal(layer.motion, `${path}.motion`, ["fade"]) : read.literal(layer.motion, `${path}.motion`, ["slide"]),
1326
1350
  modalBelow: read.optionalString(layer.modalBelow, `${path}.modalBelow`)
1327
1351
  };
1328
1352
  }
@@ -47,9 +47,11 @@ function overpaintUnder(foundation, spec, under) {
47
47
  const corners = reached(index);
48
48
  if (corners.length === 0)
49
49
  continue;
50
- const box = fieldsOf(foundation, framedUnder(part.box, part.geometryWhen, under), "frame");
50
+ const own = part.box ?? (part.frame !== null ? slots.get("frame-profile") ?? null : null), box = fieldsOf(foundation, framedUnder(own, part.geometryWhen, under), "frame");
51
51
  if (box !== null && corners.every((corner) => cornerRadius((field) => box.get(field), corner) !== void 0))
52
52
  continue;
53
+ if (box?.get("border-width") !== void 0 && box.get("border-style") !== "forced-only")
54
+ return { kind: "corner-overpaint", part: part.name, surface: part.surface ?? "", state: null, corners, under, paint: "border" };
53
55
  for (const [state, name] of [[null, part.surface], ...part.when]) {
54
56
  const background = fieldsOf(foundation, name, "surface")?.get("background");
55
57
  if (name === null || background === void 0)
@@ -1,3 +1,4 @@
1
+ import { FORCED_PREFIX, SYSTEM_COLORS } from "./forced-colors.mjs";
1
2
  import path from "node:path";
2
3
  import postcss, { CssSyntaxError } from "postcss";
3
4
  import { readTokenRegistrations } from "./token-registrations.mjs";
@@ -128,6 +129,11 @@ export function readFoundation(captured, contexts) {
128
129
  }
129
130
  continue;
130
131
  }
132
+ if (field.startsWith(FORCED_PREFIX)) {
133
+ if (!SYSTEM_COLORS.includes(value))
134
+ return reject({ kind: "forced-color-invalid", profile: name, field, value });
135
+ continue;
136
+ }
131
137
  const expected = roles?.[field];
132
138
  if (expected === void 0)
133
139
  continue;
@@ -210,6 +216,7 @@ function slotArguments(spec, file, declaration) {
210
216
  return Object.entries(objectAt(value.select)).map(([choice, option]) => ({ file, declaration, path: [...path, field, "select", choice], profile, reference, choice, option: String(option) }));
211
217
  }));
212
218
  }
219
+ const DOCUMENT_TEXT_FIELDS = ["font-family", "font-size", "line-height"];
213
220
  export function documentProfiles(foundation, references) {
214
221
  const fields = (field) => {
215
222
  const reference = references[field], profile = selectedProfile(foundation, reference);
@@ -221,6 +228,9 @@ export function documentProfiles(foundation, references) {
221
228
  }, text = fields("text");
222
229
  if (text.kind === "err")
223
230
  return text;
231
+ const missing = DOCUMENT_TEXT_FIELDS.filter((field) => !text.value.has(field));
232
+ if (missing.length > 0)
233
+ return err({ kind: "document-text-incomplete", reference: references.text, missing });
224
234
  const surface = fields("surface");
225
235
  if (surface.kind === "err")
226
236
  return surface;
@@ -530,6 +540,10 @@ export function describeFoundationFailure(failure) {
530
540
  return `Wrong role ${failure.profile}.${failure.field}: ${failure.token}`;
531
541
  case "provided-role-self":
532
542
  return `Profile ${failure.profile} provides ${failure.token} and reads it in ${failure.field}`;
543
+ case "forced-color-invalid":
544
+ return `Profile ${failure.profile} ${failure.field}: ${failure.value} is not a CSS system colour`;
545
+ case "document-text-incomplete":
546
+ return `foundation.ads.ts text: ${failure.reference} states no ${failure.missing.join(", ")}`;
533
547
  case "document-profile-kind":
534
548
  return `foundation.ads.ts ${failure.field}: ${failure.reference} is a ${failure.actual} profile, not a ${failure.field} profile`;
535
549
  }
@@ -49,4 +49,4 @@ export function outcomeDigest(owner, root) {
49
49
  outcomeDigests.set(owner, computed);
50
50
  return computed;
51
51
  }
52
- export const ownerEmissionKey = (inputs) => digest(["ads-owner-emission/1", inputs.analysisKey, outcomeDigest(inputs.outcome, inputs.root), inputs.classes]);
52
+ export const ownerEmissionKey = (inputs) => digest(["ads-owner-emission/2", inputs.analysisKey, outcomeDigest(inputs.outcome, inputs.root), inputs.classes]);
@@ -0,0 +1,69 @@
1
+ import { selectedProfile } from "./design-foundation.mjs";
2
+ import { frameInlineInsets } from "./lowering-region-layout.mjs";
3
+ const tokenOf = (value) => value === void 0 ? void 0 : value.startsWith("--") ? `var(${value})` : value;
4
+ export function endInsetOf(foundation, spec) {
5
+ switch (spec.kind) {
6
+ case "region": {
7
+ if (spec.frame === null || spec.profile === null)
8
+ return [];
9
+ const selected = selectedProfile(foundation, spec.profile, spec.select);
10
+ if (selected.kind === "err")
11
+ return null;
12
+ const frameName = selected.value.kind === "frame" ? spec.profile : selected.value.kind === "composite" ? selected.value.fields.get("frame-profile") : void 0;
13
+ if (frameName === void 0)
14
+ return [];
15
+ const frame = frameName === spec.profile ? selected : selectedProfile(foundation, frameName);
16
+ if (frame.kind === "err" || frame.value.kind !== "frame")
17
+ return null;
18
+ const surfaceName = spec.surface ?? (selected.value.kind === "composite" ? selected.value.fields.get("surface-profile") : void 0), surface = surfaceName === void 0 ? null : selectedProfile(foundation, surfaceName);
19
+ if (surface !== null && surface.kind === "ok" && surface.value.kind === "surface" && surface.value.fields.has("background") || frame.value.fields.has("border-width"))
20
+ return [];
21
+ const end = frameInlineInsets(Object.fromEntries(frame.value.fields)).end;
22
+ return end === void 0 ? [] : [end];
23
+ }
24
+ case "grid": {
25
+ if (spec.mode !== "fluid" && spec.mode !== "hybrid")
26
+ return null;
27
+ const mode = spec.layout.find(([key]) => key === "gutter")?.[1] ?? "wide";
28
+ if (mode === "none")
29
+ return [];
30
+ const named = selectedProfile(foundation, spec.profile);
31
+ if (named.kind === "err")
32
+ return null;
33
+ const reference = named.value.kind === "spatial" ? spec.profile : named.value.fields.get("spatial-profile");
34
+ if (reference === void 0)
35
+ return null;
36
+ const spatial = reference === spec.profile ? named : selectedProfile(foundation, reference);
37
+ if (spatial.kind === "err" || spatial.value.kind !== "spatial")
38
+ return null;
39
+ const gutter = spatial.value.clauses.get(`ads-gutter ${String(mode)}`);
40
+ if (gutter === void 0)
41
+ return null;
42
+ if (gutter.get("gap") !== void 0)
43
+ return [];
44
+ const end = tokenOf(gutter.get("end"));
45
+ return end === void 0 ? null : [end];
46
+ }
47
+ case "control":
48
+ case "artwork":
49
+ return null;
50
+ }
51
+ }
52
+ export function stackPartsOf(foundation, spec) {
53
+ if (spec.kind !== "region" || spec.arrangement.layout !== "stack")
54
+ return [];
55
+ return spec.parts.flatMap((part) => {
56
+ if (part.content.kind === "component")
57
+ return [{ part: part.name, kind: "component", inset: [] }];
58
+ if (part.box === null)
59
+ return [];
60
+ const frame = selectedProfile(foundation, part.box);
61
+ if (frame.kind === "err" || frame.value.kind !== "frame")
62
+ return [];
63
+ const surface = part.surface === null ? null : selectedProfile(foundation, part.surface);
64
+ if (surface !== null && surface.kind === "ok" && surface.value.kind === "surface" && surface.value.fields.has("background") || frame.value.fields.has("border-width"))
65
+ return [{ part: part.name, kind: "box", inset: [] }];
66
+ const end = frameInlineInsets(Object.fromEntries(frame.value.fields)).end;
67
+ return [{ part: part.name, kind: "box", inset: end === void 0 ? [] : [end] }];
68
+ });
69
+ }
@@ -0,0 +1,20 @@
1
+ /** What an external renders and where it comes from. */
2
+ export interface ExternalSpec {
3
+ /** The module that exports it: `"next/link"`. */
4
+ readonly from: string;
5
+ /** Its export: `"default"` (the default) or a named export (`"Html"` of `next/document`). */
6
+ readonly name?: string;
7
+ /** The one element it renders (`"a"`): ADS checks owners as if they wrote that element. */
8
+ readonly renders: string;
9
+ /** The library component needs the client (state, effects): owners that render it are "use client". */
10
+ readonly client?: boolean;
11
+ }
12
+ /** The props every external takes beside its declared ones: the owner's class and what it holds. */
13
+ export interface ExternalBaseProps {
14
+ readonly className?: string;
15
+ readonly children?: unknown;
16
+ }
17
+ /** A declared external, typed as a component of its props. Never called by ADS: owners render the real one. */
18
+ export type External<Props> = (props: Props & ExternalBaseProps) => never;
19
+ /** Declares an external component. */
20
+ export declare function external<Props>(spec: ExternalSpec): External<Props>;
@@ -0,0 +1,12 @@
1
+ const MODULE = /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*(?:\/[\w.-]+)*$/, ELEMENT = /^[a-z][a-z0-9-]*$/;
2
+ export function external(spec) {
3
+ if (!MODULE.test(spec.from))
4
+ throw Error(`external: "${spec.from}" is not a package module (a bare specifier such as "next/link").`);
5
+ if (!ELEMENT.test(spec.renders))
6
+ throw Error(`external: renders "${spec.renders}" is not an element name.`);
7
+ if (spec.name !== void 0 && !/^[A-Za-z_$][\w$]*$/.test(spec.name))
8
+ throw Error(`external: name "${spec.name}" is not an export name.`);
9
+ return () => {
10
+ throw Error(`external ${spec.from}: an ADS declaration is not rendered; the emitted design system re-exports the real component.`);
11
+ };
12
+ }
@@ -5,6 +5,7 @@ export const findingRules = Object.freeze({
5
5
  "a11y-text-scale": "error",
6
6
  "a11y-text-spacing-override": "error",
7
7
  "a11y-reflow": "error",
8
+ "a11y-forced-colors-render": "error",
8
9
  "render-audit": "error",
9
10
  "a11y-focus": "error",
10
11
  "a11y-icon-label": "error",
@@ -13,6 +14,8 @@ export const findingRules = Object.freeze({
13
14
  "a11y-text-resize": "error",
14
15
  "a11y-focus-unresolved": "review",
15
16
  "a11y-target-size-unresolved": "review",
17
+ "a11y-forced-colors": "error",
18
+ "a11y-forced-colors-review": "review",
16
19
  "a11y-keyboard": "review",
17
20
  "a11y-motion-endless": "info",
18
21
  "a11y-incomplete": "info",
@@ -0,0 +1,81 @@
1
+ import { selectedProfile } from "./design-foundation.mjs";
2
+ export { SYSTEM_COLORS } from "./system-colors.mjs";
3
+ export const FORCED_FIELDS = {
4
+ "forced-colors-background": "background",
5
+ "forced-colors-color": "color",
6
+ "forced-colors-border": "border-color"
7
+ }, FORCED_PREFIX = "forced-colors-";
8
+ export { FORCED_KEYS } from "./system-colors.mjs";
9
+ export const FORCED_ONLY = "forced-only", declaresForced = (fields) => [...fields instanceof Map ? fields.keys() : Object.keys(fields)].some((field) => field.startsWith(FORCED_PREFIX));
10
+ const fieldsOf = (foundation, name, kind, select = {}) => {
11
+ if (name === null || name === void 0)
12
+ return null;
13
+ const selected = selectedProfile(foundation, name, select);
14
+ return selected.kind === "ok" && selected.value.kind === kind ? selected.value.fields : null;
15
+ };
16
+ function slotsOf(foundation, profile, select) {
17
+ if (profile === null)
18
+ return new Map;
19
+ const selected = selectedProfile(foundation, profile, select);
20
+ if (selected.kind === "err")
21
+ return new Map;
22
+ return selected.value.kind === "composite" ? selected.value.fields : new Map([[`${selected.value.kind}-profile`, profile]]);
23
+ }
24
+ const borderless = (frame) => frame?.get("border-width") === void 0 ? "every context" : null;
25
+ export function forcedBoundaryMissing(foundation, spec) {
26
+ switch (spec.kind) {
27
+ case "control": {
28
+ const name = slotsOf(foundation, spec.profile, spec.select).get("frame-profile") ?? null, context = borderless(fieldsOf(foundation, name, "frame"));
29
+ return context === null ? null : { kind: "forced-boundary-missing", element: "&", frame: name, context };
30
+ }
31
+ case "region": {
32
+ const name = slotsOf(foundation, spec.profile, spec.select).get("frame-profile") ?? null;
33
+ for (const part of spec.parts) {
34
+ if (part.frame === null)
35
+ continue;
36
+ const context = borderless(fieldsOf(foundation, name, "frame"));
37
+ if (context !== null)
38
+ return { kind: "forced-boundary-missing", element: part.name, frame: name, context };
39
+ }
40
+ return null;
41
+ }
42
+ case "artwork":
43
+ case "grid":
44
+ return null;
45
+ }
46
+ }
47
+ const FILL_FIELDS = new Set(["background", "background-color", "background-image", "box-shadow", "group-shadow", "shape-shadow"]), MEANT = /aria-(selected|pressed|checked|current)|:checked\b/;
48
+ function fillOnly(base, state) {
49
+ const own = (fields) => new Map([...fields ?? new Map].filter(([field]) => !field.startsWith(FORCED_PREFIX) && field !== "state")), before = own(base), after = own(state), changed = new Set([...before.keys(), ...after.keys()].filter((field) => before.get(field) !== after.get(field)));
50
+ return changed.size > 0 && [...changed].every((field) => FILL_FIELDS.has(field));
51
+ }
52
+ export function forcedStateFillOnly(foundation, spec) {
53
+ const found = [], visit = (element, base, when) => {
54
+ const baseFields = fieldsOf(foundation, base, "surface");
55
+ for (const [condition, surface] of when) {
56
+ if (surface === null || !MEANT.test(condition))
57
+ continue;
58
+ const fields = fieldsOf(foundation, surface, "surface");
59
+ if (fields === null || declaresForced(fields))
60
+ continue;
61
+ if (fillOnly(baseFields, fields))
62
+ found.push({ kind: "forced-state-fill-only", element, condition, surface });
63
+ }
64
+ };
65
+ switch (spec.kind) {
66
+ case "control":
67
+ visit("&", spec.surface, spec.when);
68
+ break;
69
+ case "region": {
70
+ const slots = slotsOf(foundation, spec.profile, spec.select);
71
+ visit("&", spec.surface ?? slots.get("surface-profile") ?? null, spec.when);
72
+ for (const part of spec.parts)
73
+ visit(part.name, part.surface, part.when);
74
+ break;
75
+ }
76
+ case "artwork":
77
+ case "grid":
78
+ break;
79
+ }
80
+ return found;
81
+ }
@@ -185,7 +185,7 @@ function frameRegionOf(foundation, place, spec, regions, moved, under) {
185
185
  context: context.label
186
186
  }), placed = (bounds) => bounds[cell] ?? [], lowest = moved.has(cell) && conditions.length > 0 ? Math.min(...conditions.map((item) => item.boundPx)) : -1 / 0;
187
187
  for (const bound of placed(cells)) {
188
- if (bound.kind === "hidden")
188
+ if (bound.kind === "hidden" || bound.kind === "content")
189
189
  continue;
190
190
  if (bound.kind === "unbounded") {
191
191
  review(`its ${px(need.px)} ${need.field} sits in inherited tracks at ${bound.tier}, which the grid algebra does not bound here`, context.label);
@@ -204,7 +204,7 @@ function frameRegionOf(foundation, place, spec, regions, moved, under) {
204
204
  for (const bound of placed(condition.cells)) {
205
205
  if (bound.kind === "hidden" || bound.fromPx >= condition.boundPx)
206
206
  continue;
207
- if (bound.kind === "unbounded")
207
+ if (bound.kind === "unbounded" || bound.kind === "content")
208
208
  continue;
209
209
  if (need.px > space(bound) + 0.01)
210
210
  return exceeds(bound, condition.condition);
@@ -0,0 +1,64 @@
1
+ import { readdirSync, readFileSync, statSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import path from "node:path";
4
+ import { pathToFileURL } from "node:url";
5
+ const MARK = /export \{ ([\w$]+)(?: as ([\w$]+))? \} from "([^"]+)";\n\/\* ads-external (\{[^*]*\}) \*\//g, PROBE = "ads-external-probe";
6
+ function declared(folder) {
7
+ const found = [], visit = (directory, depth) => {
8
+ if (depth > 6)
9
+ return;
10
+ for (const entry of readdirSync(directory)) {
11
+ if (entry === "node_modules" || entry.startsWith("."))
12
+ continue;
13
+ const file = path.join(directory, entry);
14
+ if (statSync(file).isDirectory())
15
+ visit(file, depth + 1);
16
+ else if (/\.ads\.[cm]?[jt]s$/.test(entry))
17
+ for (const match of readFileSync(file, "utf8").matchAll(MARK)) {
18
+ const mark = JSON.parse(match[4] ?? "{}");
19
+ if (mark.name !== void 0 && mark.renders !== void 0)
20
+ found.push({ name: mark.name, exportName: match[1] ?? "default", from: match[3] ?? "", renders: mark.renders });
21
+ }
22
+ }
23
+ };
24
+ visit(folder, 0);
25
+ return found;
26
+ }
27
+ export async function verifyExternals(root, entry) {
28
+ const externals = declared(path.dirname(entry));
29
+ if (externals.length === 0)
30
+ return [];
31
+ const require = createRequire(path.join(root, "package.json"));
32
+ let react, server;
33
+ try {
34
+ react = require("react");
35
+ server = require("react-dom/server");
36
+ } catch {
37
+ return externals.map((external) => ({ ...external, problem: "the application has no react and react-dom/server to render it with: verify it by hand" }));
38
+ }
39
+ const checks = [];
40
+ for (const external of externals) {
41
+ let problem = null;
42
+ try {
43
+ const module = await import(pathToFileURL(require.resolve(external.from)).href), exported = external.exportName === "default" ? module.default?.default ?? module.default : module[external.exportName];
44
+ if (exported === void 0)
45
+ problem = `${external.from} exports no ${external.exportName}`;
46
+ else {
47
+ const markup = server.renderToStaticMarkup(react.createElement(exported, { className: PROBE, href: "/", children: "probe" })).replace(/^(?:<link[^>]*\brel="(?:preload|modulepreload|preconnect|dns-prefetch)"[^>]*\/?>)+/, ""), root = /^<([a-z][\w-]*)([^>]*)>/.exec(markup), closes = root === null ? !1 : markup.endsWith(`</${root[1]}>`) || markup.endsWith("/>");
48
+ if (root === null || !closes)
49
+ problem = `it renders ${markup.slice(0, 80)}, not one element`;
50
+ else if (root[1] !== external.renders)
51
+ problem = `it renders <${root[1]}>, not the declared <${external.renders}>`;
52
+ else if (!new RegExp(`class="[^"]*\\b${PROBE}\\b`).test(root[2] ?? ""))
53
+ problem = "it does not put the class it is given on its element";
54
+ else if (/\sstyle="/.test(root[2] ?? ""))
55
+ problem = "it brings a style of its own: it carries design (use its data function instead)";
56
+ }
57
+ } catch (error) {
58
+ problem = `it could not be rendered: ${error instanceof Error ? error.message.split(`
59
+ `)[0] : String(error)}`;
60
+ }
61
+ checks.push({ name: external.name, from: external.from, renders: external.renders, problem });
62
+ }
63
+ return checks;
64
+ }
@@ -5,6 +5,7 @@ import { checkDesignUsage, designSystemEntry } from "../design-usage.mjs";
5
5
  import { err, ok } from "../result.mjs";
6
6
  import { readGuardConfig } from "./config.mjs";
7
7
  import { guardScope } from "./files.mjs";
8
+ import { verifyExternals } from "./externals.mjs";
8
9
  const ENTRY_NAMES = ["index.ts", "index.tsx", "index.mts", "index.js", "index.mjs"];
9
10
  function entryFile(root, config) {
10
11
  if (config.entry !== void 0) {
@@ -29,15 +30,16 @@ export async function runGuard(root) {
29
30
  const located = entryFile(absolute, config.value);
30
31
  if (located.kind === "err")
31
32
  return err([located.error]);
32
- const entry = await designSystemEntry(config.value.designSystem, located.value), folder = path.dirname(located.value), scope = guardScope(absolute, config.value.include, config.value.exclude, folder.startsWith(absolute + path.sep) ? folder : null), sources = scope.files.map((file) => ({ file, text: readFileSync(path.join(absolute, file), "utf8") })), findings = await checkDesignUsage(sources, entry, { components: config.value.allow, metadata: !0 }), inside = located.value.startsWith(absolute + path.sep);
33
+ const entry = await designSystemEntry(config.value.designSystem, located.value), folder = path.dirname(located.value), scope = guardScope(absolute, config.value.include, config.value.exclude, folder.startsWith(absolute + path.sep) ? folder : null), sources = scope.files.map((file) => ({ file, text: readFileSync(path.join(absolute, file), "utf8") })), findings = await checkDesignUsage(sources, entry, { components: config.value.allow, metadata: !0 }), inside = located.value.startsWith(absolute + path.sep), externals = await verifyExternals(absolute, located.value);
33
34
  return ok({
34
- ok: findings.length === 0,
35
+ ok: findings.length === 0 && externals.every((item) => item.problem === null),
35
36
  designSystem: config.value.designSystem,
36
37
  entry: inside ? path.relative(absolute, located.value).split(path.sep).join("/") : located.value,
37
38
  patterns: entry.patterns.size,
38
39
  checked: scope.files.length,
39
40
  scope: { excluded: scope.excluded, tests: scope.tests, designSystem: scope.designSystem },
40
- findings
41
+ findings,
42
+ externals
41
43
  });
42
44
  }
43
45
  export function guardText(report) {
@@ -50,7 +52,9 @@ export function guardText(report) {
50
52
  left.push(`${report.scope.tests} test file${report.scope.tests === 1 ? "" : "s"}`);
51
53
  if (report.scope.designSystem > 0)
52
54
  left.push(`${report.scope.designSystem} file${report.scope.designSystem === 1 ? "" : "s"} of the design system`);
53
- const summary = `Checked ${report.checked} file${report.checked === 1 ? "" : "s"} against ${report.designSystem} (${report.patterns} pattern${report.patterns === 1 ? "" : "s"})${left.length ? `; not checked: ${left.join("; ")}` : ""}.`, verdict = report.ok ? "The source uses the design system only." : `${report.findings.length} finding${report.findings.length === 1 ? "" : "s"}.`;
54
- return [...lines, summary, verdict].join(`
55
+ const summary = `Checked ${report.checked} file${report.checked === 1 ? "" : "s"} against ${report.designSystem} (${report.patterns} pattern${report.patterns === 1 ? "" : "s"})${left.length ? `; not checked: ${left.join("; ")}` : ""}.`, externals = report.externals.map((item) => item.problem === null ? `external ${item.name} (${item.from}) renders <${item.renders}> as declared` : `external ${item.name} (${item.from}) external-mismatch
56
+ ${item.problem}
57
+ Declare what it renders, or use a component that renders one element with the given class and no style of its own.`), failing = report.findings.length + report.externals.filter((item) => item.problem !== null).length, verdict = report.ok ? "The source uses the design system only." : `${failing} finding${failing === 1 ? "" : "s"}.`;
58
+ return [...lines, ...externals, summary, verdict].join(`
55
59
  `);
56
60
  }
@@ -58,7 +58,7 @@ export function revisionTokenInventory(options) {
58
58
  }
59
59
  const used = new Set;
60
60
  for (const construction of outcome.owner.styles.values())
61
- for (const token of construction.used)
61
+ for (const token of [...construction.used, ...construction.scriptTokens ?? []])
62
62
  used.add(token);
63
63
  tokens.push({ owner: path.posix.join(designSystem, name), tokens: used });
64
64
  }