@reqvire-org/ads 0.3.45 → 0.3.47

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 (160) hide show
  1. package/README.md +23 -11
  2. package/dist/a11y.mjs +102 -0
  3. package/dist/assets.mjs +37 -8
  4. package/dist/atomic-composition.mjs +3 -2
  5. package/dist/brand-assets.mjs +48 -11
  6. package/dist/brands.mjs +82 -0
  7. package/dist/browser-audit/worker.mjs +45 -0
  8. package/dist/browser-audit.mjs +117 -0
  9. package/dist/capture/worker.mjs +2 -1
  10. package/dist/capture-store.mjs +4 -1
  11. package/dist/capture.mjs +10 -4
  12. package/dist/check.mjs +40 -9
  13. package/dist/cli.mjs +55 -8
  14. package/dist/color-values.mjs +325 -0
  15. package/dist/config.mjs +19 -2
  16. package/dist/contracts/tokens.json +1 -1
  17. package/dist/control-padding.mjs +93 -0
  18. package/dist/design-values.mjs +11 -4
  19. package/dist/finding-rules.mjs +61 -0
  20. package/dist/foundation.mjs +17 -1
  21. package/dist/icons.mjs +107 -0
  22. package/dist/init.mjs +3 -0
  23. package/dist/mcp/apps.mjs +9 -6
  24. package/dist/mcp/drafts.mjs +3 -0
  25. package/dist/mcp/mutations.mjs +17 -1
  26. package/dist/mcp/preview-widget.bundle.js +45 -39
  27. package/dist/mcp/project-widget.bundle.js +26 -26
  28. package/dist/mcp/server.mjs +23 -9
  29. package/dist/mcp/widget.bundle.js +17 -17
  30. package/dist/palette-generated.mjs +180 -0
  31. package/dist/preview-resources.mjs +12 -3
  32. package/dist/render-color-probe.mjs +148 -0
  33. package/dist/runtime-contracts.mjs +14 -4
  34. package/dist/scenarios.mjs +1 -1
  35. package/dist/showcase/client.bundle.js +28 -28
  36. package/dist/showcase/icons.js +146 -0
  37. package/dist/showcase/index.html +2 -1
  38. package/dist/showcase/style.css +19 -2
  39. package/dist/skills/README.md +2 -1
  40. package/dist/skills/ads-break-ui/SKILL.md +6 -5
  41. package/dist/skills/ads-break-ui/references/atomic-styles.md +12 -12
  42. package/dist/skills/ads-break-ui/references/captures.md +3 -2
  43. package/dist/skills/ads-break-ui/references/contracts.md +13 -10
  44. package/dist/skills/ads-break-ui/references/design-data.md +199 -2
  45. package/dist/skills/ads-break-ui/references/validation.md +8 -4
  46. package/dist/skills/ads-designer/SKILL.md +32 -15
  47. package/dist/skills/ads-designer/references/accessibility.md +77 -0
  48. package/dist/skills/ads-designer/references/atomic-styles.md +12 -12
  49. package/dist/skills/ads-designer/references/branding.md +61 -6
  50. package/dist/skills/ads-designer/references/captures.md +3 -2
  51. package/dist/skills/ads-designer/references/cli.md +8 -2
  52. package/dist/skills/ads-designer/references/contracts.md +13 -10
  53. package/dist/skills/ads-designer/references/design-data.md +199 -2
  54. package/dist/skills/ads-designer/references/validation.md +8 -4
  55. package/dist/skills/ads-import/SKILL.md +9 -8
  56. package/dist/skills/ads-import/references/atomic-styles.md +12 -12
  57. package/dist/skills/ads-import/references/captures.md +3 -2
  58. package/dist/skills/ads-import/references/cli.md +8 -2
  59. package/dist/skills/ads-import/references/contracts.md +13 -10
  60. package/dist/skills/ads-import/references/design-data.md +199 -2
  61. package/dist/skills/ads-import/references/tokens.md +7 -3
  62. package/dist/skills/ads-import/references/validation.md +8 -4
  63. package/dist/skills/ads-motion/SKILL.md +6 -5
  64. package/dist/skills/ads-motion/references/atomic-styles.md +12 -12
  65. package/dist/skills/ads-motion/references/build.md +33 -0
  66. package/dist/skills/ads-motion/references/captures.md +3 -2
  67. package/dist/skills/ads-motion/references/contracts.md +13 -10
  68. package/dist/skills/ads-motion/references/design-data.md +199 -2
  69. package/dist/skills/ads-motion/references/motion-review.md +2 -2
  70. package/dist/skills/ads-motion/references/validation.md +8 -4
  71. package/dist/skills/ads-port/SKILL.md +6 -5
  72. package/dist/skills/ads-port/references/atomic-styles.md +12 -12
  73. package/dist/skills/ads-port/references/captures.md +3 -2
  74. package/dist/skills/ads-port/references/cli.md +8 -2
  75. package/dist/skills/ads-port/references/contracts.md +13 -10
  76. package/dist/skills/ads-port/references/design-data.md +199 -2
  77. package/dist/skills/ads-port/references/validation.md +8 -4
  78. package/dist/starters/preact/design-system/components/Layout/Grid/Grid.tsx +76 -0
  79. package/dist/starters/preact/design-system/review/token-preview/TokenPreview.tsx +19 -1
  80. package/dist/starters/preact/ds.config.json +13 -1
  81. package/dist/starters/react/ADS.md +43 -10
  82. package/dist/starters/react/README.md +61 -9
  83. package/dist/starters/react/design-system/assets/brand/README.md +8 -3
  84. package/dist/starters/react/design-system/assets/glyphs/README.md +15 -0
  85. package/dist/starters/react/design-system/assets/glyphs/aliases.json +1 -0
  86. package/dist/starters/react/design-system/assets/glyphs/check.svg +1 -0
  87. package/dist/starters/react/design-system/assets/glyphs/chevron-down.svg +1 -0
  88. package/dist/starters/react/design-system/assets/glyphs/chevron-right.svg +1 -0
  89. package/dist/starters/react/design-system/assets/glyphs/close.svg +1 -0
  90. package/dist/starters/react/design-system/assets/glyphs/external-link.svg +1 -0
  91. package/dist/starters/react/design-system/assets/glyphs/info.svg +1 -0
  92. package/dist/starters/react/design-system/assets/glyphs/menu.svg +1 -0
  93. package/dist/starters/react/design-system/assets/glyphs/plus.svg +1 -0
  94. package/dist/starters/react/design-system/assets/glyphs/search.svg +1 -0
  95. package/dist/starters/react/design-system/assets/glyphs/warning.svg +1 -0
  96. package/dist/starters/react/design-system/components/Actions/Button/Button.tsx +11 -4
  97. package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.ads.fixture.ts +9 -0
  98. package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.ads.scenario.tsx +16 -0
  99. package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.tsx +44 -0
  100. package/dist/starters/react/design-system/components/Actions/IconButton/README.md +14 -0
  101. package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.fixture.ts +6 -0
  102. package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.scenario.tsx +16 -0
  103. package/dist/starters/react/design-system/components/Content/Icon/Icon.tsx +42 -0
  104. package/dist/starters/react/design-system/components/Content/Icon/README.md +17 -0
  105. package/dist/starters/react/design-system/components/Content/Icon/glyphs.ts +17 -0
  106. package/dist/starters/react/design-system/components/Content/Logo/Logo.tsx +3 -9
  107. package/dist/starters/react/design-system/components/Content/Logo/README.md +4 -2
  108. package/dist/starters/react/design-system/components/Forms/TextField/TextField.tsx +9 -5
  109. package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.fixture.ts +12 -0
  110. package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.scenario.tsx +17 -0
  111. package/dist/starters/react/design-system/components/Layout/Grid/Grid.tsx +75 -0
  112. package/dist/starters/react/design-system/components/Layout/Grid/README.md +21 -0
  113. package/dist/starters/react/design-system/controllers/Palette/Palette.ts +164 -0
  114. package/dist/starters/react/design-system/index.ts +6 -0
  115. package/dist/starters/react/design-system/review/brand-preview/BrandPreview.tsx +2 -5
  116. package/dist/starters/react/design-system/review/grid-cell/GridCell.tsx +18 -0
  117. package/dist/starters/react/design-system/review/index.ts +1 -0
  118. package/dist/starters/react/design-system/review/token-preview/TokenPreview.tsx +19 -1
  119. package/dist/starters/react/design-system/styles.css +1 -0
  120. package/dist/starters/react/design-system/tokens/Color.ads.fixture.ts +114 -8
  121. package/dist/starters/react/design-system/tokens/Layout.ads.fixture.ts +23 -0
  122. package/dist/starters/react/design-system/tokens/{SpaceTypeMotion.ads.scenario.tsx → Layout.ads.scenario.tsx} +1 -1
  123. package/dist/starters/react/design-system/tokens/Motion.ads.fixture.ts +18 -0
  124. package/dist/starters/react/design-system/tokens/Motion.ads.scenario.tsx +4 -0
  125. package/dist/starters/react/design-system/tokens/Shape.ads.fixture.ts +30 -0
  126. package/dist/starters/react/design-system/tokens/Shape.ads.scenario.tsx +4 -0
  127. package/dist/starters/react/design-system/tokens/Space.ads.fixture.ts +37 -0
  128. package/dist/starters/react/design-system/tokens/Space.ads.scenario.tsx +4 -0
  129. package/dist/starters/react/design-system/tokens/Type.ads.fixture.ts +29 -0
  130. package/dist/starters/react/design-system/tokens/Type.ads.scenario.tsx +4 -0
  131. package/dist/starters/react/design-system/tokens/base.css +9 -3
  132. package/dist/starters/react/design-system/tokens/colors.css +210 -24
  133. package/dist/starters/react/design-system/tokens/elevation.css +44 -6
  134. package/dist/starters/react/design-system/tokens/spacing.css +67 -3
  135. package/dist/starters/react/design-system/tokens/themes.generated.css +142 -0
  136. package/dist/starters/react/design-system/tokens/themes.generated.ts +402 -0
  137. package/dist/starters/react/design-system/tokens/typography.css +25 -7
  138. package/dist/starters/react/ds.config.json +13 -1
  139. package/dist/style-boundaries.mjs +2 -1
  140. package/dist/themes-generated.mjs +150 -0
  141. package/dist/themes-watch.mjs +42 -0
  142. package/dist/themes.mjs +257 -0
  143. package/dist/token-export.mjs +69 -0
  144. package/dist/token-policy.mjs +2 -1
  145. package/dist/token-quality.mjs +112 -0
  146. package/dist/tokens.mjs +32 -30
  147. package/dist/validation.mjs +18 -1
  148. package/dist/verification/browser.mjs +14 -3
  149. package/docs/ADS.md +56 -13
  150. package/docs/ARCHITECTURE.md +82 -10
  151. package/docs/CACHING.md +2 -3
  152. package/docs/CHANGELOG.md +149 -13
  153. package/docs/CONTRACTS.md +13 -10
  154. package/docs/GUIDE.md +104 -8
  155. package/docs/MCP.md +46 -27
  156. package/docs/benchmarks/bun-previews.md +5 -5
  157. package/docs/benchmarks/{gidi-preview-memory.md → preview-memory.md} +14 -12
  158. package/docs/benchmarks/turbo-poc.md +24 -6
  159. package/package.json +2 -1
  160. package/dist/starters/react/design-system/tokens/SpaceTypeMotion.ads.fixture.ts +0 -36
@@ -0,0 +1,325 @@
1
+ import valueParser from "postcss-value-parser";
2
+
3
+ // Static CSS Color 4/5 resolution for the generated renderer palette: every absolute color
4
+ // syntax (hex, named, rgb/hsl/hwb, lab/lch, oklab/oklch, color()), color-mix() and
5
+ // light-dark() parse to { space, coords, alpha }; conversions go through linear sRGB or
6
+ // XYZ-D65 with the CSS Color 4 matrices; srgb8 clips each channel to the sRGB gamut, as
7
+ // Chrome's 2D canvas does when it draws a wider color into an sRGB canvas. Contextual values
8
+ // (currentColor, system colors, relative color syntax, calc()) cannot be resolved without an
9
+ // element and return { unresolved: reason }; anything else that is not a color returns null.
10
+
11
+ const named = Object.fromEntries("aliceblue:f0f8ff antiquewhite:faebd7 aqua:00ffff aquamarine:7fffd4 azure:f0ffff beige:f5f5dc bisque:ffe4c4 black:000000 blanchedalmond:ffebcd blue:0000ff blueviolet:8a2be2 brown:a52a2a burlywood:deb887 cadetblue:5f9ea0 chartreuse:7fff00 chocolate:d2691e coral:ff7f50 cornflowerblue:6495ed cornsilk:fff8dc crimson:dc143c cyan:00ffff darkblue:00008b darkcyan:008b8b darkgoldenrod:b8860b darkgray:a9a9a9 darkgreen:006400 darkgrey:a9a9a9 darkkhaki:bdb76b darkmagenta:8b008b darkolivegreen:556b2f darkorange:ff8c00 darkorchid:9932cc darkred:8b0000 darksalmon:e9967a darkseagreen:8fbc8f darkslateblue:483d8b darkslategray:2f4f4f darkslategrey:2f4f4f darkturquoise:00ced1 darkviolet:9400d3 deeppink:ff1493 deepskyblue:00bfff dimgray:696969 dimgrey:696969 dodgerblue:1e90ff firebrick:b22222 floralwhite:fffaf0 forestgreen:228b22 fuchsia:ff00ff gainsboro:dcdcdc ghostwhite:f8f8ff gold:ffd700 goldenrod:daa520 gray:808080 green:008000 greenyellow:adff2f grey:808080 honeydew:f0fff0 hotpink:ff69b4 indianred:cd5c5c indigo:4b0082 ivory:fffff0 khaki:f0e68c lavender:e6e6fa lavenderblush:fff0f5 lawngreen:7cfc00 lemonchiffon:fffacd lightblue:add8e6 lightcoral:f08080 lightcyan:e0ffff lightgoldenrodyellow:fafad2 lightgray:d3d3d3 lightgreen:90ee90 lightgrey:d3d3d3 lightpink:ffb6c1 lightsalmon:ffa07a lightseagreen:20b2aa lightskyblue:87cefa lightslategray:778899 lightslategrey:778899 lightsteelblue:b0c4de lightyellow:ffffe0 lime:00ff00 limegreen:32cd32 linen:faf0e6 magenta:ff00ff maroon:800000 mediumaquamarine:66cdaa mediumblue:0000cd mediumorchid:ba55d3 mediumpurple:9370db mediumseagreen:3cb371 mediumslateblue:7b68ee mediumspringgreen:00fa9a mediumturquoise:48d1cc mediumvioletred:c71585 midnightblue:191970 mintcream:f5fffa mistyrose:ffe4e1 moccasin:ffe4b5 navajowhite:ffdead navy:000080 oldlace:fdf5e6 olive:808000 olivedrab:6b8e23 orange:ffa500 orangered:ff4500 orchid:da70d6 palegoldenrod:eee8aa palegreen:98fb98 paleturquoise:afeeee palevioletred:db7093 papayawhip:ffefd5 peachpuff:ffdab9 peru:cd853f pink:ffc0cb plum:dda0dd powderblue:b0e0e6 purple:800080 rebeccapurple:663399 red:ff0000 rosybrown:bc8f8f royalblue:4169e1 saddlebrown:8b4513 salmon:fa8072 sandybrown:f4a460 seagreen:2e8b57 seashell:fff5ee sienna:a0522d silver:c0c0c0 skyblue:87ceeb slateblue:6a5acd slategray:708090 slategrey:708090 snow:fffafa springgreen:00ff7f steelblue:4682b4 tan:d2b48c teal:008080 thistle:d8bfd8 tomato:ff6347 turquoise:40e0d0 violet:ee82ee wheat:f5deb3 white:ffffff whitesmoke:f5f5f5 yellow:ffff00 yellowgreen:9acd32".split(" ").map(pair => pair.split(":")));
12
+ const systemColors = new Set(["accentcolor", "accentcolortext", "activetext", "buttonborder", "buttonface", "buttontext", "canvas", "canvastext", "field", "fieldtext", "graytext", "highlight", "highlighttext", "linktext", "mark", "marktext", "selecteditem", "selecteditemtext", "visitedtext"]);
13
+ const colorFunctions = new Set(["rgb", "rgba", "hsl", "hsla", "hwb", "lab", "lch", "oklab", "oklch", "color", "color-mix", "light-dark", "contrast-color", "device-cmyk"]);
14
+
15
+ const multiply = (matrix, [a, b, c]) => matrix.map(row => row[0] * a + row[1] * b + row[2] * c);
16
+ const fromSrgbGamma = value => { const abs = Math.abs(value); return abs <= 0.04045 ? value / 12.92 : Math.sign(value) * ((abs + 0.055) / 1.055) ** 2.4; };
17
+ const toSrgbGamma = value => { const abs = Math.abs(value); return abs > 0.0031308 ? Math.sign(value) * (1.055 * abs ** (1 / 2.4) - 0.055) : 12.92 * value; };
18
+
19
+ const linearSrgbToXyz = [[506752 / 1228815, 87881 / 245763, 12673 / 70218], [87098 / 409605, 175762 / 245763, 12673 / 175545], [7918 / 409605, 87881 / 737289, 1001167 / 1053270]];
20
+ const xyzToLinearSrgb = [[12831 / 3959, -329 / 214, -1974 / 3959], [-851781 / 878810, 1648619 / 878810, 36519 / 878810], [705 / 12673, -2585 / 12673, 705 / 667]];
21
+ const d65ToD50 = [[1.0479297925449969, 0.022946870601609652, -0.05019226628920524], [0.02962780877005599, 0.9904344267538799, -0.017073799063418826], [-0.009243040646204504, 0.015055191490298152, 0.7518742814281371]];
22
+ const d50ToD65 = [[0.955473421488075, -0.02309845494876471, 0.06325924320057072], [-0.0283697093338637, 1.0099953980813041, 0.021041441191917323], [0.012314014864481998, -0.020507649298898964, 1.330365926242124]];
23
+ const xyzToLms = [[0.819022437996703, 0.3619062600528904, -0.1288737815209879], [0.0329836539323885, 0.9292868615863434, 0.0361446663506424], [0.0481771893596242, 0.2642395317527308, 0.6335478284694309]];
24
+ const lmsToXyz = [[1.2268798758459243, -0.5578149944602171, 0.2813910456659647], [-0.0405757452148008, 1.112286803280317, -0.0716766580655164], [-0.0763729366746601, -0.4214933324022432, 1.5869240198367816]];
25
+ const lmsToOklab = [[0.210454268309314, 0.7936177747023054, -0.0040720430116193], [1.9779985324311684, -2.42859224204858, 0.450593709617411], [0.0259040424655478, 0.7827717124575296, -0.8086757549230774]];
26
+ const oklabToLms = [[1, 0.3963377773761749, 0.2158037573099136], [1, -0.1055613458156586, -0.0638541728258133], [1, -0.0894841775298119, -1.2914855480194092]];
27
+ const d50White = [0.3457 / 0.3585, 1, (1 - 0.3457 - 0.3585) / 0.3585];
28
+ const kappa = 24389 / 27, epsilon = 216 / 24389;
29
+
30
+ // RGB spaces: transfer function to linear light and the linear-to-XYZ matrix (D65 unless noted).
31
+ const invert = matrix => {
32
+ const [[a, b, c], [d, e, f], [g, h, i]] = matrix, det = a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g);
33
+ return [[e * i - f * h, c * h - b * i, b * f - c * e], [f * g - d * i, a * i - c * g, c * d - a * f], [d * h - e * g, b * g - a * h, a * e - b * d]].map(row => row.map(value => value / det));
34
+ };
35
+ const rgbSpace = (toLinear, fromLinear, toXyz, d50 = false) => ({ toLinear, fromLinear, toXyz, fromXyz: invert(toXyz), d50 });
36
+ const identity = value => value;
37
+ const a98 = 563 / 256;
38
+ const rec2020 = { alpha: 1.09929682680944, beta: 0.018053968510807 };
39
+ const rgbSpaces = {
40
+ srgb: { toLinear: fromSrgbGamma, fromLinear: toSrgbGamma, toXyz: linearSrgbToXyz, fromXyz: xyzToLinearSrgb, d50: false },
41
+ "srgb-linear": { toLinear: identity, fromLinear: identity, toXyz: linearSrgbToXyz, fromXyz: xyzToLinearSrgb, d50: false },
42
+ "display-p3": rgbSpace(fromSrgbGamma, toSrgbGamma, [[608311 / 1250200, 189793 / 714400, 198249 / 1000160], [35783 / 156275, 247089 / 357200, 198249 / 2500400], [0, 32229 / 714400, 5220557 / 5000800]]),
43
+ "a98-rgb": rgbSpace(value => Math.sign(value) * Math.abs(value) ** a98, value => Math.sign(value) * Math.abs(value) ** (1 / a98),
44
+ [[573536 / 994567, 263643 / 1420810, 187206 / 994567], [591459 / 1989134, 6239551 / 9945670, 374412 / 4972835], [53769 / 1989134, 351524 / 4972835, 4929758 / 4972835]]),
45
+ "prophoto-rgb": rgbSpace(value => Math.abs(value) <= 16 / 512 ? value / 16 : Math.sign(value) * Math.abs(value) ** 1.8, value => Math.abs(value) >= 1 / 512 ? Math.sign(value) * Math.abs(value) ** (1 / 1.8) : 16 * value,
46
+ [[0.7977666449006423, 0.13518129740053308, 0.0313477341283922], [0.2880748288194013, 0.711835234241873, 0.00008993693872564], [0, 0, 0.8251046025104602]], true),
47
+ rec2020: rgbSpace(value => Math.abs(value) < rec2020.beta * 4.5 ? value / 4.5 : Math.sign(value) * ((Math.abs(value) + rec2020.alpha - 1) / rec2020.alpha) ** (1 / 0.45),
48
+ value => Math.abs(value) > rec2020.beta ? Math.sign(value) * (rec2020.alpha * Math.abs(value) ** 0.45 - (rec2020.alpha - 1)) : 4.5 * value,
49
+ [[63426534 / 99577255, 20160776 / 139408157, 47086771 / 278816314], [26158966 / 99577255, 472592308 / 697040785, 8267143 / 139408157], [0, 19567812 / 697040785, 295819943 / 278816314]]),
50
+ };
51
+ const xyzSpaces = { xyz: false, "xyz-d65": false, "xyz-d50": true };
52
+ const polar = new Set(["hsl", "hwb", "lch", "oklch"]);
53
+ /** The hue index of a polar space's coordinates. */
54
+ const hueIndex = space => space === "hsl" || space === "hwb" ? 0 : 2;
55
+
56
+ const zero = value => Number.isNaN(value) ? 0 : value;
57
+ const radians = degrees => degrees * Math.PI / 180;
58
+
59
+ function hslToSrgb([h, s, l]) {
60
+ const k = n => (n + h / 30) % 12, a = s * Math.min(l, 1 - l);
61
+ return [0, 8, 4].map(n => l - a * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1)));
62
+ }
63
+ function srgbToHsl([r, g, b]) {
64
+ const max = Math.max(r, g, b), min = Math.min(r, g, b), l = (max + min) / 2, d = max - min;
65
+ let h = Number.NaN, s = 0;
66
+ if (d !== 0) {
67
+ s = l === 0 || l === 1 ? 0 : (max - l) / Math.min(l, 1 - l);
68
+ h = max === r ? (g - b) / d + (g < b ? 6 : 0) : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
69
+ h *= 60;
70
+ }
71
+ if (s < 0) { h += 180; s = Math.abs(s); }
72
+ if (h >= 360) h -= 360;
73
+ return [Math.abs(s) < 1e-5 ? Number.NaN : h, s, l];
74
+ }
75
+ function hwbToSrgb([h, w, b]) {
76
+ if (w + b >= 1) { const gray = w / (w + b); return [gray, gray, gray]; }
77
+ return hslToSrgb([h, 1, 0.5]).map(value => value * (1 - w - b) + w);
78
+ }
79
+ function srgbToHwb(rgb) {
80
+ const [h] = srgbToHsl(rgb), w = Math.min(...rgb), b = 1 - Math.max(...rgb);
81
+ return [w + b >= 1 - 1e-5 ? Number.NaN : h, w, b];
82
+ }
83
+ const labToXyzD50 = ([l, a, b]) => {
84
+ const f1 = (l + 16) / 116, f0 = a / 500 + f1, f2 = f1 - b / 200;
85
+ return [f0 ** 3 > epsilon ? f0 ** 3 : (116 * f0 - 16) / kappa, l > kappa * epsilon ? f1 ** 3 : l / kappa, f2 ** 3 > epsilon ? f2 ** 3 : (116 * f2 - 16) / kappa].map((value, index) => value * d50White[index]);
86
+ };
87
+ const xyzD50ToLab = xyz => {
88
+ const [f0, f1, f2] = xyz.map((value, index) => value / d50White[index]).map(value => value > epsilon ? Math.cbrt(value) : (kappa * value + 16) / 116);
89
+ return [116 * f1 - 16, 500 * (f0 - f1), 200 * (f1 - f2)];
90
+ };
91
+ const toPolar = ([l, a, b], threshold) => { const c = Math.hypot(a, b); let h = Math.atan2(b, a) * 180 / Math.PI; if (h < 0) h += 360; return [l, c, c < threshold ? Number.NaN : h]; };
92
+ const fromPolar = ([l, c, h]) => [l, zero(c) * Math.cos(radians(zero(h))), zero(c) * Math.sin(radians(zero(h)))];
93
+
94
+ /** XYZ-D65 coordinates of a parsed color. */
95
+ function toXyz({ space, coords }) {
96
+ const values = coords.map(zero);
97
+ if (rgbSpaces[space]) { const rgb = rgbSpaces[space], xyz = multiply(rgb.toXyz, values.map(rgb.toLinear)); return rgb.d50 ? multiply(d50ToD65, xyz) : xyz; }
98
+ if (space in xyzSpaces) return xyzSpaces[space] ? multiply(d50ToD65, values) : values;
99
+ if (space === "hsl") return toXyz({ space: "srgb", coords: hslToSrgb(values) });
100
+ if (space === "hwb") return toXyz({ space: "srgb", coords: hwbToSrgb(values) });
101
+ if (space === "lab") return multiply(d50ToD65, labToXyzD50(values));
102
+ if (space === "lch") return multiply(d50ToD65, labToXyzD50(fromPolar(coords)));
103
+ if (space === "oklab" || space === "oklch") return multiply(lmsToXyz, multiply(oklabToLms, space === "oklch" ? fromPolar(coords) : values).map(value => value ** 3));
104
+ throw new Error(`Unknown color space ${space}.`);
105
+ }
106
+
107
+ /** A parsed color's coordinates in another space (polar spaces mark a powerless hue as NaN). */
108
+ export function convert(color, space) {
109
+ if (color.space === space) return color.coords;
110
+ const xyz = toXyz(color);
111
+ if (rgbSpaces[space]) { const rgb = rgbSpaces[space]; return multiply(rgb.fromXyz, rgb.d50 ? multiply(d65ToD50, xyz) : xyz).map(rgb.fromLinear); }
112
+ if (space in xyzSpaces) return xyzSpaces[space] ? multiply(d65ToD50, xyz) : xyz;
113
+ if (space === "hsl") return srgbToHsl(convert({ space: "xyz", coords: xyz }, "srgb"));
114
+ if (space === "hwb") return srgbToHwb(convert({ space: "xyz", coords: xyz }, "srgb"));
115
+ if (space === "lab") return xyzD50ToLab(multiply(d65ToD50, xyz));
116
+ if (space === "lch") return toPolar(xyzD50ToLab(multiply(d65ToD50, xyz)), 0.01);
117
+ const lab = multiply(lmsToOklab, multiply(xyzToLms, xyz).map(Math.cbrt));
118
+ if (space === "oklab") return lab;
119
+ if (space === "oklch") return toPolar(lab, 0.0004);
120
+ throw new Error(`Unknown color space ${space}.`);
121
+ }
122
+
123
+ /** sRGB 0–255 integer channels and alpha 0–1 (four decimals), each channel clipped to the gamut. */
124
+ export function srgb8(color) {
125
+ // A hair above half rounds up, so exact halves (hwb(200 10% 20%) → 25.5) land where Chrome puts them.
126
+ const rgb = convert(color, "srgb").map(value => Math.round(Math.min(1, Math.max(0, zero(value))) * 255 + 1e-9));
127
+ return [...rgb, Math.round(Math.min(1, Math.max(0, zero(color.alpha))) * 10000) / 10000];
128
+ }
129
+
130
+ /** The canonical CSS string of sRGB channels: #rrggbb when opaque, rgba(r, g, b, a) otherwise. */
131
+ export function canonicalCss([r, g, b, a]) {
132
+ return a >= 1 ? `#${[r, g, b].map(value => value.toString(16).padStart(2, "0")).join("")}` : `rgba(${r}, ${g}, ${b}, ${a})`;
133
+ }
134
+
135
+ class Unresolved extends Error {}
136
+ const unresolved = reason => { throw new Unresolved(reason); };
137
+ const meaningful = nodes => nodes.filter(node => node.type !== "space" && node.type !== "comment");
138
+
139
+ const angle = text => {
140
+ const match = text.match(/^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(deg|rad|grad|turn)?$/i);
141
+ if (!match) return null;
142
+ const value = Number(match[1]), unit = match[2]?.toLowerCase();
143
+ return unit === "rad" ? value * 180 / Math.PI : unit === "grad" ? value * 0.9 : unit === "turn" ? value * 360 : value;
144
+ };
145
+ const numeric = text => {
146
+ const match = text.match(/^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(%)?$/i);
147
+ return match ? { value: Number(match[1]), percent: !!match[2] } : null;
148
+ };
149
+ const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
150
+
151
+ /** One channel: a number, a percentage scaled to `percent` (100% = percent) or none (NaN). */
152
+ function channel(node, percent, { hue = false, allowNumber = true, allowPercent = true } = {}) {
153
+ if (node.type === "function") unresolved(node.value.toLowerCase() === "calc" || /^(?:min|max|clamp|round|mod|rem|abs|sign|sin|cos|tan|exp|pow|sqrt|log|hypot)$/i.test(node.value) ? "a math function in a color channel" : `${node.value}() in a color channel`);
154
+ if (node.type !== "word") throw new SyntaxError("channel");
155
+ if (node.value.toLowerCase() === "none") return Number.NaN;
156
+ if (hue) { const degrees = angle(node.value); if (degrees === null) throw new SyntaxError("hue"); return degrees; }
157
+ const parsed = numeric(node.value);
158
+ if (!parsed || (parsed.percent ? !allowPercent : !allowNumber)) throw new SyntaxError("channel");
159
+ return parsed.percent ? parsed.value / 100 * percent : parsed.value;
160
+ }
161
+ const alphaChannel = node => node ? channel(node, 1) : 1;
162
+
163
+ /** Splits a color function's arguments into channels and alpha, in the modern (space and /)
164
+ * or legacy (comma) syntax. */
165
+ function channels(node, count, legacy) {
166
+ const parts = meaningful(node.nodes);
167
+ if (parts[0]?.type === "word" && parts[0].value.toLowerCase() === "from") unresolved("relative color syntax");
168
+ if (legacy && parts.some(part => part.type === "div" && part.value === ",")) {
169
+ const items = [];
170
+ for (let index = 0; index < parts.length; index += 2) {
171
+ items.push(parts[index]);
172
+ if (index + 1 < parts.length && !(parts[index + 1].type === "div" && parts[index + 1].value === ",")) throw new SyntaxError("legacy");
173
+ }
174
+ if (items.length !== count && items.length !== count + 1) throw new SyntaxError("legacy");
175
+ return { values: items.slice(0, count), alpha: items[count], legacy: true };
176
+ }
177
+ const slash = parts.findIndex(part => part.type === "div" && part.value === "/");
178
+ const values = slash < 0 ? parts : parts.slice(0, slash), alpha = slash < 0 ? undefined : parts.slice(slash + 1);
179
+ if (values.length !== count || values.some(part => part.type === "div") || alpha && alpha.length !== 1) throw new SyntaxError("modern");
180
+ return { values, alpha: alpha?.[0] };
181
+ }
182
+
183
+ function parseHex(text) {
184
+ let hex = text.slice(1);
185
+ if (![3, 4, 6, 8].includes(hex.length) || !/^[\da-f]+$/i.test(hex)) return null;
186
+ if (hex.length < 6) hex = [...hex].map(digit => digit + digit).join("");
187
+ const values = [0, 2, 4, 6].map(index => parseInt(hex.slice(index, index + 2) || "ff", 16) / 255);
188
+ return { space: "srgb", coords: values.slice(0, 3), alpha: values[3] };
189
+ }
190
+
191
+ function parseFunction(node, options) {
192
+ const name = node.value.toLowerCase();
193
+ if (name === "color-mix") return parseMix(node, options);
194
+ if (name === "light-dark") {
195
+ const parts = meaningful(node.nodes), comma = parts.findIndex(part => part.type === "div" && part.value === ",");
196
+ if (comma !== 1 || parts.length !== 3) throw new SyntaxError("light-dark");
197
+ if (!options.scheme) unresolved("light-dark() needs the color scheme");
198
+ return parseNode(parts[options.scheme === "dark" ? 2 : 0], options);
199
+ }
200
+ if (name === "rgb" || name === "rgba") {
201
+ const { values, alpha, legacy } = channels(node, 3, true);
202
+ const parsed = values.map(part => channel(part, 255));
203
+ if (legacy && values.some(part => numeric(part.value)?.percent) !== values.every(part => numeric(part.value)?.percent)) throw new SyntaxError("rgb");
204
+ return { space: "srgb", coords: parsed.map(value => Number.isNaN(value) ? value : clamp(value, 0, 255) / 255), alpha: clamp(alphaChannel(alpha), 0, 1) };
205
+ }
206
+ if (name === "hsl" || name === "hsla" || name === "hwb") {
207
+ const { values, alpha, legacy } = channels(node, 3, name !== "hwb");
208
+ const h = channel(values[0], 0, { hue: true }), [a, b] = values.slice(1).map(part => channel(part, 100, { allowNumber: !legacy }) / 100);
209
+ const hue = Number.isNaN(h) ? h : ((h % 360) + 360) % 360;
210
+ return { space: name === "hwb" ? "hwb" : "hsl", coords: [hue, Number.isNaN(a) ? a : name === "hwb" ? a : clamp(a, 0, 1), Number.isNaN(b) ? b : name === "hwb" ? b : clamp(b, 0, 1)], alpha: clamp(alphaChannel(alpha), 0, 1) };
211
+ }
212
+ if (name === "lab" || name === "oklab") {
213
+ const { values, alpha } = channels(node, 3, false), ok = name === "oklab";
214
+ const l = channel(values[0], ok ? 1 : 100), [a, b] = values.slice(1).map(part => channel(part, ok ? 0.4 : 125));
215
+ return { space: name, coords: [Number.isNaN(l) ? l : clamp(l, 0, ok ? 1 : 100), a, b], alpha: clamp(alphaChannel(alpha), 0, 1) };
216
+ }
217
+ if (name === "lch" || name === "oklch") {
218
+ const { values, alpha } = channels(node, 3, false), ok = name === "oklch";
219
+ const l = channel(values[0], ok ? 1 : 100), c = channel(values[1], ok ? 0.4 : 150), h = channel(values[2], 0, { hue: true });
220
+ return { space: name, coords: [Number.isNaN(l) ? l : clamp(l, 0, ok ? 1 : 100), Number.isNaN(c) ? c : Math.max(0, c), Number.isNaN(h) ? h : ((h % 360) + 360) % 360], alpha: clamp(alphaChannel(alpha), 0, 1) };
221
+ }
222
+ if (name === "color") {
223
+ const parts = meaningful(node.nodes);
224
+ if (parts[0]?.type === "word" && parts[0].value.toLowerCase() === "from") unresolved("relative color syntax");
225
+ const space = parts[0]?.type === "word" ? parts[0].value.toLowerCase() : "";
226
+ if (!rgbSpaces[space] && !(space in xyzSpaces)) { if (space.startsWith("--")) unresolved(`custom color space ${space}`); throw new SyntaxError("color"); }
227
+ const { values, alpha } = channels({ nodes: parts.slice(1) }, 3, false);
228
+ return { space, coords: values.map(part => channel(part, 1)), alpha: clamp(alphaChannel(alpha), 0, 1) };
229
+ }
230
+ unresolved(`${node.value}() is not resolved statically`);
231
+ }
232
+
233
+ const mixSpaces = new Set([...Object.keys(rgbSpaces), ...Object.keys(xyzSpaces), "lab", "oklab", "hsl", "hwb", "lch", "oklch"]);
234
+
235
+ /** color-mix(in <space> [<method> hue], <color> [<p>], <color> [<p>]) per CSS Color 5:
236
+ * premultiplied interpolation, percentages normalized, and an alpha multiplier when they sum
237
+ * under 100%. Missing (none or powerless) components take the other color's value. */
238
+ function parseMix(node, options) {
239
+ const groups = [[]];
240
+ for (const part of meaningful(node.nodes)) if (part.type === "div" && part.value === ",") groups.push([]); else groups.at(-1).push(part);
241
+ let space = "oklab", method = "shorter";
242
+ if (groups[0][0]?.type === "word" && groups[0][0].value.toLowerCase() === "in") {
243
+ const words = groups.shift().map(part => part.type === "word" ? part.value.toLowerCase() : "");
244
+ space = words[1];
245
+ if (!mixSpaces.has(space)) { if (space?.startsWith("--")) unresolved(`custom color space ${space}`); throw new SyntaxError("color-mix space"); }
246
+ if (words.length === 4 && words[3] === "hue" && polar.has(space) && ["shorter", "longer", "increasing", "decreasing"].includes(words[2])) method = words[2];
247
+ else if (words.length !== 2) throw new SyntaxError("color-mix method");
248
+ }
249
+ if (space === "xyz") space = "xyz-d65";
250
+ if (groups.length !== 2) { if (groups.length > 2) unresolved("color-mix() with more than two colors"); throw new SyntaxError("color-mix colors"); }
251
+ const items = groups.map(group => {
252
+ const percentNode = group.find(part => part.type === "word" && part.value.endsWith("%")), rest = group.filter(part => part !== percentNode);
253
+ if (rest.length !== 1 || group.length > 2) throw new SyntaxError("color-mix item");
254
+ const percent = percentNode ? numeric(percentNode.value) : null;
255
+ if (percentNode && (!percent?.percent || percent.value < 0 || percent.value > 100)) throw new SyntaxError("color-mix percentage");
256
+ return { color: parseNode(rest[0], options), percent: percent?.value ?? null };
257
+ });
258
+ let [p1, p2] = items.map(item => item.percent);
259
+ if (p1 === null && p2 === null) [p1, p2] = [50, 50];
260
+ else if (p1 === null) p1 = 100 - p2;
261
+ else if (p2 === null) p2 = 100 - p1;
262
+ const sum = p1 + p2;
263
+ if (sum === 0) throw new SyntaxError("color-mix percentages sum to zero");
264
+ const multiplier = Math.min(1, sum / 100), t = p2 / sum;
265
+ const [a, b] = items.map(({ color }) => ({ coords: [...convert(color, space)], alpha: color.alpha }));
266
+ // A component missing in one color takes the other's.
267
+ for (let index = 0; index < 3; index++) {
268
+ if (Number.isNaN(a.coords[index])) a.coords[index] = b.coords[index];
269
+ else if (Number.isNaN(b.coords[index])) b.coords[index] = a.coords[index];
270
+ }
271
+ if (Number.isNaN(a.alpha)) a.alpha = b.alpha; else if (Number.isNaN(b.alpha)) b.alpha = a.alpha;
272
+ const alpha1 = zero(a.alpha), alpha2 = zero(b.alpha), alpha = alpha1 * (1 - t) + alpha2 * t;
273
+ const hue = polar.has(space) ? hueIndex(space) : -1;
274
+ const coords = [0, 1, 2].map(index => {
275
+ let [c1, c2] = [a.coords[index], b.coords[index]];
276
+ if (Number.isNaN(c1)) return Number.NaN;
277
+ if (index === hue) {
278
+ const delta = c2 - c1;
279
+ if (method === "shorter") { if (delta > 180) c1 += 360; else if (delta < -180) c2 += 360; }
280
+ else if (method === "longer") { if (delta > 0 && delta < 180) c1 += 360; else if (delta > -180 && delta <= 0) c2 += 360; }
281
+ else if (method === "increasing") { if (delta < 0) c2 += 360; }
282
+ else if (delta > 0) c1 += 360;
283
+ return ((c1 * (1 - t) + c2 * t) % 360 + 360) % 360;
284
+ }
285
+ const mixed = c1 * alpha1 * (1 - t) + c2 * alpha2 * t;
286
+ return alpha === 0 ? mixed : mixed / alpha;
287
+ });
288
+ return { space, coords, alpha: alpha * multiplier };
289
+ }
290
+
291
+ function parseNode(node, options) {
292
+ if (node.type === "word") {
293
+ const text = node.value.toLowerCase();
294
+ if (text.startsWith("#")) { const color = parseHex(text); if (!color) throw new SyntaxError("hex"); return color; }
295
+ if (text === "transparent") return { space: "srgb", coords: [0, 0, 0], alpha: 0 };
296
+ if (named[text]) return parseHex(`#${named[text]}`);
297
+ if (text === "currentcolor") unresolved("currentColor depends on the element");
298
+ if (systemColors.has(text)) unresolved(`system color ${node.value}`);
299
+ throw new SyntaxError("word");
300
+ }
301
+ if (node.type === "function" && colorFunctions.has(node.value.toLowerCase())) return parseFunction(node, options);
302
+ if (node.type === "function") unresolved(`${node.value}() is not resolved statically`);
303
+ throw new SyntaxError("node");
304
+ }
305
+
306
+ /** A CSS value as a color: { color: { space, coords, alpha } }, { unresolved: reason } for a color
307
+ * that depends on its element or uses syntax ADS does not evaluate, or null when the value is
308
+ * not a single color. `scheme` ("light" | "dark") selects light-dark() branches. */
309
+ export function parseCssColor(value, { scheme } = {}) {
310
+ const nodes = meaningful(valueParser(String(value).trim()).nodes);
311
+ if (nodes.length !== 1) return null;
312
+ const [node] = nodes;
313
+ const colorish = node.type === "function" ? colorFunctions.has(node.value.toLowerCase()) : node.type === "word" && (node.value.startsWith("#") || node.value.toLowerCase() in named || ["transparent", "currentcolor"].includes(node.value.toLowerCase()) || systemColors.has(node.value.toLowerCase()));
314
+ if (!colorish) return null;
315
+ try { return { color: parseNode(node, { scheme }) }; }
316
+ catch (error) {
317
+ if (error instanceof Unresolved) return { unresolved: error.message };
318
+ if (error instanceof SyntaxError) return { unresolved: "invalid color syntax" };
319
+ throw error;
320
+ }
321
+ }
322
+
323
+ /** Whether a value names something ADS treats as a color even when it cannot resolve it: a single
324
+ * function call (an unknown or contextual function). */
325
+ export const singleFunction = value => { const nodes = meaningful(valueParser(String(value).trim()).nodes); return nodes.length === 1 && nodes[0].type === "function" ? nodes[0].value : null; };
package/dist/config.mjs CHANGED
@@ -3,6 +3,8 @@ import path from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { isDraftFile, draftImportViolation } from "./draft-boundary.mjs";
5
5
  import { isSharedToken } from "./token-policy.mjs";
6
+ import { defaultThemes, validateThemes } from "./themes.mjs";
7
+ import { validateBrands } from "./brands.mjs";
6
8
 
7
9
  export const supportedFrameworks = ["react", "preact"];
8
10
 
@@ -18,12 +20,17 @@ export const defaultConfig = {
18
20
  reviewEntry: "review/index.ts",
19
21
  stylesEntry: "styles.css",
20
22
  tokenDir: "tokens",
23
+ themes: defaultThemes,
24
+ // Optional brand axis beside the themes; empty means one brand.
25
+ brands: [],
26
+ // With no data-theme on the root, the OS color scheme picks the first theme of that scheme.
27
+ followSystemTheme: false,
21
28
  inlineStyleFiles: [],
22
29
  boundaries: { styleWrites: [], componentVariables: [] },
23
30
  assets: { publicDirs: ["public/assets"], generatedPaths: ["dist", "dist-showcase", ".vite", ".ds"], generatedFiles: [], iconSource: null, targets: [], glyphs: null },
24
31
  oxlint: { plugins: [], rules: {}, overrides: [] },
25
- acceptance: { checks: [], behaviorChecks: false },
26
- validation: { checks: [], behaviorChecks: true, inputs: [] },
32
+ acceptance: { checks: [], behaviorChecks: false, browserAudit: false },
33
+ validation: { checks: [], behaviorChecks: true, browserAudit: false, inputs: [] },
27
34
  resources: { memoryLimitMb: null },
28
35
  mcp: { showcaseUrl: null, showcaseTitle: null, apps: [], previewWatch: null, previewManifest: null, mutationCheckTimeoutMs: 60000, behaviorProfiles: {}, capture: {}, resultRetention: {maxRuns:50,maxAgeDays:7,maxBytesMb:256} },
29
36
  };
@@ -100,6 +107,7 @@ export function loadConfig(directory = process.cwd()) {
100
107
  const configFile = path.join(root, "ds.config.json");
101
108
  const user = existsSync(configFile) ? JSON.parse(readFileSync(configFile, "utf8")) : {};
102
109
  if (!user || typeof user !== "object" || Array.isArray(user)) throw new Error("ds.config.json must be an object.");
110
+ if (Object.hasOwn(user, "enforce")) throw new Error("enforce was removed in 0.3.47: ADS findings are errors, review items or info. Remove enforce from ds.config.json.");
103
111
  for (const field of Object.keys(user)) {
104
112
  if (!(field in defaultConfig)) throw new Error(`Unknown ADS configuration field: ${field}`);
105
113
  }
@@ -110,6 +118,14 @@ export function loadConfig(directory = process.cwd()) {
110
118
  for (const key of Object.keys(user[field] ?? {})) if (!(key in defaultConfig[field])) throw new Error(`Unknown ${field} configuration field: ${key}`);
111
119
  }
112
120
  const config = { ...defaultConfig, ...user, boundaries: { ...defaultConfig.boundaries, ...user.boundaries }, assets: { ...defaultConfig.assets, ...user.assets }, oxlint: { ...defaultConfig.oxlint, ...user.oxlint }, acceptance: { ...defaultConfig.acceptance, ...user.acceptance }, validation: { ...defaultConfig.validation, ...user.validation }, mcp: { ...defaultConfig.mcp, ...user.mcp }, usage: { ...defaultConfig.usage, ...user.usage }, resources: { ...defaultConfig.resources, ...user.resources } };
121
+ validateThemes(config.themes);
122
+ validateBrands(config.brands);
123
+ if (typeof config.followSystemTheme !== "boolean") throw new Error("followSystemTheme must be true or false.");
124
+ if (config.followSystemTheme) {
125
+ const other = config.themes[0].scheme === "dark" ? "light" : "dark";
126
+ if (!config.themes.some(theme => theme.scheme === other)) throw new Error(`followSystemTheme needs a declared theme with scheme ${other}.`);
127
+ }
128
+ for (const brand of config.brands) if (config.themes.some(theme => theme.name === `brand-${brand.name}`)) throw new Error(`Theme "brand-${brand.name}" and brand "${brand.name}" would share the display switch --display-brand-${brand.name}; rename one.`);
113
129
  if(config.resources.memoryLimitMb!==null&&(!Number.isInteger(config.resources.memoryLimitMb)||config.resources.memoryLimitMb<64||config.resources.memoryLimitMb>1048576))throw new Error("resources.memoryLimitMb must be null (automatic) or an integer from 64 to 1048576 MiB.");
114
130
  if (!Array.isArray(config.usage.notifications) || config.usage.notifications.length > 100) throw new Error("usage.notifications must be an array of notification API registrations.");
115
131
  const notificationNames = new Set();
@@ -128,6 +144,7 @@ export function loadConfig(directory = process.cwd()) {
128
144
  const policy=config[name];
129
145
  if (!Array.isArray(policy.checks) || policy.checks.length>20 || new Set(policy.checks).size!==policy.checks.length || policy.checks.some(script=>typeof script!=="string" || !/^[a-zA-Z0-9][\w:.-]*$/.test(script))) throw new Error(`${name}.checks must contain up to 20 unique package script names.`);
130
146
  if(typeof policy.behaviorChecks!=="boolean")throw new Error(`${name}.behaviorChecks must be a boolean.`);
147
+ if(typeof policy.browserAudit!=="boolean")throw new Error(`${name}.browserAudit must be a boolean.`);
131
148
  }
132
149
  if (!Array.isArray(config.validation.inputs) || config.validation.inputs.length > 200 || new Set(config.validation.inputs).size !== config.validation.inputs.length) throw new Error("validation.inputs must contain at most 200 unique project-relative files or directories.");
133
150
  for (const file of config.validation.inputs) {
@@ -2,7 +2,7 @@
2
2
  "version": 1,
3
3
  "description": "Shared CSS token names, semantics, and value categories. Values belong to the project.",
4
4
  "naming": {
5
- "prefixes": ["--color-", "--slate-", "--warm-", "--rose-", "--bg-", "--text-", "--border-", "--font-", "--weight-", "--leading-", "--tracking-", "--type-", "--space-", "--radius-", "--control-", "--icon-", "--shadow-", "--ring-", "--filter-", "--ease-", "--dur-", "--z-", "--accent-", "--focus-", "--scroll-", "--success-", "--warning-", "--danger-", "--info-", "--side-pane-", "--toast-"],
5
+ "prefixes": ["--color-", "--slate-", "--warm-", "--rose-", "--bg-", "--text-", "--border-", "--font-", "--weight-", "--leading-", "--tracking-", "--type-", "--space-", "--radius-", "--control-", "--icon-", "--shadow-", "--ring-", "--filter-", "--ease-", "--dur-", "--z-", "--accent-", "--focus-", "--scroll-", "--success-", "--warning-", "--danger-", "--info-", "--side-pane-", "--container-", "--grid-", "--toast-"],
6
6
  "names": ["--accent", "--success", "--warning", "--danger", "--info", "--inset-hairline", "--navigation-rail-width", "--app-header-height", "--content-max", "--row-height-compact", "--compact-column-min", "--stack-gap-compact"]
7
7
  },
8
8
  "tokens": {
@@ -0,0 +1,93 @@
1
+ import valueParser from "postcss-value-parser";
2
+ import { findingSeverity } from "./finding-rules.mjs";
3
+
4
+ /** Controls that share a height share their side padding. A block sized from
5
+ * --control-height-<size> pads its inline sides with --control-padding-<size>
6
+ * (or --control-inset for a gap inside a track), not raw --space-* steps.
7
+ * An error: ADS keeps one side padding per control height. */
8
+ const sizeProperty = /^(?:min-)?(?:height|block-size|width|inline-size)$/;
9
+ const paddingProperty = /^padding(?:-inline(?:-start|-end)?|-left|-right)?$/;
10
+ const controlHeight = /^--control-height-([\w-]+)$/;
11
+ const controlPadding = /^--control-padding-[\w-]+$|^--control-inset$/;
12
+
13
+ function variables(node, names = []) {
14
+ if (node.type === "function" && node.value.toLowerCase() === "var") {
15
+ const name = node.nodes.find(child => child.type === "word")?.value;
16
+ if (name?.startsWith("--")) names.push(name);
17
+ }
18
+ for (const child of node.nodes ?? []) variables(child, names);
19
+ return names;
20
+ }
21
+
22
+ /** Top-level components of a value, each with the variables it reads. Local
23
+ * custom properties set in the same block resolve one level. */
24
+ function components(value, locals) {
25
+ return valueParser(value).nodes.filter(node => !["space", "comment", "div"].includes(node.type)).map(node => {
26
+ const names = variables(node);
27
+ return names.flatMap(name => locals.has(name) ? [name, ...locals.get(name)] : [name]);
28
+ });
29
+ }
30
+
31
+ /** The control height a size declaration sets: only a bare var(--control-height-*),
32
+ * directly or through a local property. A calc() that adds to a control height
33
+ * sizes a toolbar or header around controls, not a control. */
34
+ function controlSize(value, locals, depth = 0) {
35
+ for (const node of valueParser(value).nodes) {
36
+ if (node.type !== "function" || node.value.toLowerCase() !== "var") continue;
37
+ const name = node.nodes.find(child => child.type === "word")?.value ?? "";
38
+ const match = controlHeight.exec(name);
39
+ if (match) return match;
40
+ if (depth === 0 && locals.has(name)) {
41
+ const local = controlSize(locals.get(name), locals, 1);
42
+ if (local) return local;
43
+ }
44
+ }
45
+ return null;
46
+ }
47
+
48
+ /** The components of a padding declaration that set an inline side. */
49
+ function inlineSides(property, parts) {
50
+ if (property !== "padding") return parts;
51
+ if (parts.length === 4) return [parts[1], parts[3]];
52
+ return parts.length >= 2 ? [parts[1]] : parts;
53
+ }
54
+
55
+ /** Findings for one parsed style sheet or Linaria template. `tokens` is the set of
56
+ * declared shared token names; nothing fires without --control-padding-* tokens. */
57
+ export function controlPaddingAdvisories(css, { tokens, file, offset = { line: 1 } }) {
58
+ const paddings = [...tokens].filter(name => /^--control-padding-[\w-]+$/.test(name)).sort();
59
+ if (!paddings.length) return [];
60
+ const blocks = new Map();
61
+ css.walkDecls(decl => {
62
+ for (let parent = decl.parent; parent && parent.type !== "root"; parent = parent.parent) {
63
+ if (parent.type === "atrule" && /^(?:(?:-\w+-)?keyframes|property|font-face)$/i.test(parent.name)) return;
64
+ }
65
+ if (!blocks.has(decl.parent)) blocks.set(decl.parent, []);
66
+ blocks.get(decl.parent).push(decl);
67
+ });
68
+ const findings = [];
69
+ for (const declarations of blocks.values()) {
70
+ const customs = declarations.filter(decl => decl.prop.startsWith("--"));
71
+ const locals = new Map(customs.map(decl => [decl.prop, components(decl.value, new Map()).flat()]));
72
+ const size = declarations.filter(decl => sizeProperty.test(decl.prop.toLowerCase()))
73
+ .map(decl => controlSize(decl.value, new Map(customs.map(custom => [custom.prop, custom.value])))).find(Boolean);
74
+ if (!size) continue;
75
+ const sides = declarations.filter(decl => paddingProperty.test(decl.prop.toLowerCase()))
76
+ .map(decl => ({ decl, sides: inlineSides(decl.prop.toLowerCase(), components(decl.value, locals)) }));
77
+ // One side on a control padding and the other on a space step is deliberate
78
+ // room for a trailing affordance, such as a select's chevron.
79
+ if (sides.some(entry => entry.sides.some(names => names.some(name => controlPadding.test(name))))) continue;
80
+ for (const { decl, sides: parts } of sides) {
81
+ const space = parts.flatMap(names => names.filter(name => name.startsWith("--space-")))[0];
82
+ if (!space) continue;
83
+ const matching = `--control-padding-${size[1]}`;
84
+ const advice = tokens.has(matching) ? `use ${matching}` : `use a control padding token (${paddings.join(", ")})`;
85
+ const inset = tokens.has("--control-inset") ? " (or --control-inset for a gap inside a track)" : "";
86
+ findings.push({ rule: "control-padding", severity: findingSeverity("control-padding"), file, line: offset.line + decl.source.start.line - 1, column: decl.source.start.column,
87
+ tokens: [size[0], space], guidanceUri: "ads://guides/tokens",
88
+ message: `This control is sized ${size[1]} (${size[0]}) but pads with ${space}; ${advice}${inset}, so controls of the same height keep the same padding.` });
89
+ break; // One finding per block; its other sides follow the same fix.
90
+ }
91
+ }
92
+ return findings;
93
+ }
@@ -2,7 +2,9 @@ import path from "node:path";
2
2
  import { lexer, parse, generate } from "css-tree";
3
3
  import valueParser from "postcss-value-parser";
4
4
  import { isInside } from "./config.mjs";
5
+ import { tokenContract } from "./token-policy.mjs";
5
6
  import { createSourceValues, reference } from "./source-values.mjs";
7
+ import { findingSeverity } from "./finding-rules.mjs";
6
8
 
7
9
  const colorCache = new Map();
8
10
  export function isColorKeyword(value) {
@@ -63,19 +65,24 @@ export function inspectDesignAliases(styles, options, report) {
63
65
  }
64
66
 
65
67
  const canonical=value=>{try{return generate(parse(value,{context:"value"}));}catch{return value.trim();}};
66
- /** Equal definitions invite review, not an automatic merge of different semantic roles. */
68
+ // A token's family: its shared prefix (--space-, --radius-) or, for a fixed name, the name itself.
69
+ const prefixes=[...tokenContract.naming.prefixes].sort((a,b)=>b.length-a.length);
70
+ const family=name=>prefixes.find(prefix=>name.startsWith(prefix)&&name.length>prefix.length)??name;
71
+ /** Equal definitions within one family invite review, not an automatic merge of different
72
+ * semantic roles. Equal values in different families (a radius and a spacing step) are scales
73
+ * meeting by design. */
67
74
  export function tokenOverlapAdvisories(tokens) {
68
75
  const groups=new Map();
69
76
  for(const token of tokens) {
70
77
  if(token.owner!=="tokens"||!token.definitions.length)continue;
71
- const definitions=token.definitions.map(({scope,value})=>[scope,canonical(value)]).sort(([a],[b])=>a.localeCompare(b));
78
+ const definitions=token.definitions.map(({scope,theme,value})=>[theme?`${scope} ${theme}`:scope,canonical(value)]).sort(([a],[b])=>a.localeCompare(b));
72
79
  if(definitions.every(([,value])=>/^var\(--[\w-]+\)$/.test(value))||definitions.every(([,value])=>/^(?:0|1|none|auto|inherit|initial|unset|transparent)$/.test(value)))continue;
73
- const signature=JSON.stringify(definitions);
80
+ const signature=JSON.stringify([family(token.name),definitions]);
74
81
  if(!groups.has(signature))groups.set(signature,[]);
75
82
  groups.get(signature).push(token);
76
83
  }
77
84
  return [...groups.values()].filter(group=>group.length>1).map(group=>{
78
85
  const [first]=group, {file,line,column}=first.definitions[0],names=group.map(token=>token.name);
79
- return {rule:"token-overlap-review",severity:"warning",file,line,column,tokens:names,guidanceUri:"ads://guides/tokens",message:`Shared Data tokens have identical definitions across their declared theme/condition scopes: ${names.slice(0,6).join(", ")}${names.length>6?` and ${names.length-6} more`:""}. Review semantic roles and consumers before consolidating. Equal values do not prove equivalent purpose; preserve distinct roles or use an explicit shared alias when appropriate.`};
86
+ return {rule:"token-overlap-review",severity:findingSeverity("token-overlap-review"),file,line,column,tokens:names,guidanceUri:"ads://guides/tokens",message:`Shared Data tokens have identical definitions across their declared theme/condition scopes: ${names.slice(0,6).join(", ")}${names.length>6?` and ${names.length-6} more`:""}. Review semantic roles and consumers before consolidating. Equal values do not prove equivalent purpose; preserve distinct roles or use an explicit shared alias when appropriate.`};
80
87
  });
81
88
  }
@@ -0,0 +1,61 @@
1
+ /** The class of every ADS finding that is not a structural diagnostic. ADS is opinionated:
2
+ * an "error" blocks ads check, validation and acceptance; a "review" item is shown but never
3
+ * blocks, because deciding it needs human judgement; "info" notes an analysis limit.
4
+ * Structural diagnostics (pushed straight into diagnostics, with no severity) are errors.
5
+ * Every emitter takes its severity from here; add a new finding's id here. */
6
+ export const findingRules = Object.freeze({
7
+ // Accessibility: deterministic source and token rules, and axe-core where the audit runs.
8
+ "a11y-axe": "error", "a11y-focus": "error", "a11y-icon-label": "error", "a11y-image-alt": "error", "a11y-reduced-motion": "error",
9
+ "a11y-target-size": "error", "a11y-text-resize": "error", "a11y-text-spacing": "error",
10
+ // A click handler on a non-control may be reachable through a delegated or wrapping control.
11
+ "a11y-keyboard": "review",
12
+ // Atomic styles: the composition analysis is heuristic; its limits are informational.
13
+ "atomic-composition-review": "review", "atomic-composition-limit": "info",
14
+ // Brand artwork and brand token values.
15
+ "brand-coverage": "error", "brand-empty": "error", "brand-license": "error", "brand-new-token": "error", "brand-preview": "error", "brand-readme": "error",
16
+ // Artwork may be used by code ADS cannot trace (a CMS, a server template).
17
+ "brand-unused": "review",
18
+ "control-padding": "error",
19
+ "glyph-aliases": "error", "glyph-color": "error", "glyph-viewbox": "error",
20
+ // Local source cannot prove pointer-capture cleanup or dynamic scenario execution.
21
+ "pointer-capture-review": "review", "scenario-exercise-review": "review",
22
+ // A computed-style color read in a per-item render path; the helper may be cached or cold.
23
+ "render-color-probe": "review",
24
+ "theme-empty": "error", "theme-new-token": "error",
25
+ // A [data-theme]/[data-brand] ancestor selector matches the outermost section, not the nearest.
26
+ "theme-selector": "error",
27
+ // light-dark() picks by color scheme, so it cannot tell two themes of one scheme apart.
28
+ "theme-light-dark": "error",
29
+ "token-contrast": "error", "token-rhythm": "error",
30
+ // Equal values do not prove equal purpose.
31
+ "token-overlap-review": "review",
32
+ });
33
+
34
+ const severities = new Set(["error", "review", "info"]);
35
+
36
+ /** A classified finding's severity; throws for an id missing from the registry. */
37
+ export function findingSeverity(rule) {
38
+ const severity = findingRules[rule];
39
+ if (!severities.has(severity)) throw new Error(`ADS finding rule ${rule} is not classified as error, review or info in src/finding-rules.mjs.`);
40
+ return severity;
41
+ }
42
+
43
+ /** A finding carrying its rule's registered severity. */
44
+ export const classified = finding => ({ ...finding, severity: findingSeverity(finding.rule) });
45
+
46
+ /** Route findings by class: errors join the blocking diagnostics; review and info items stay
47
+ * nonblocking, review before info. Findings without a severity take their rule's. */
48
+ export function routeFindings(diagnostics, advisories) {
49
+ const blocking = [...diagnostics], kept = [];
50
+ for (const finding of advisories) {
51
+ const severity = finding.severity ?? findingSeverity(finding.rule);
52
+ (severity === "error" ? blocking : kept).push(finding.severity === severity ? finding : { ...finding, severity });
53
+ }
54
+ kept.sort((first, second) => Number(first.severity === "info") - Number(second.severity === "info"));
55
+ return { diagnostics: blocking, advisories: kept };
56
+ }
57
+
58
+ /** "N errors, M review items" for summaries. */
59
+ export function findingCounts(errors, reviews) {
60
+ return `${errors} error${errors === 1 ? "" : "s"}, ${reviews} review item${reviews === 1 ? "" : "s"}`;
61
+ }