@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
@@ -5,12 +5,19 @@ import { readFileSync } from "node:fs";
5
5
  const policy = JSON.parse(readFileSync(new URL("./contracts/foundation.json", import.meta.url), "utf8"));
6
6
  const cssWide = /^(?:inherit|initial|unset|revert|revert-layer)$/i;
7
7
 
8
+ // A theme or brand scope ([data-theme], [data-brand="name"]) anchors like the root: either
9
+ // can apply to the whole document or to one section of it (base.css paints a themed section).
8
10
  function rootAnchor(nodes) {
9
11
  return nodes.some(node => node.type === "tag" && !node.namespace && node.value.toLowerCase() === "html"
12
+ || node.type === "attribute" && ["data-theme", "data-brand"].includes(node.attribute) && (!node.operator || node.operator === "=")
10
13
  || node.type === "pseudo" && node.value.toLowerCase() === ":root"
11
14
  || node.type === "pseudo" && /^:(?:is|where)$/i.test(node.value) && node.nodes.length && node.nodes.every(selector => !selector.nodes.some(node => node.type === "combinator") && rootAnchor(selector.nodes)));
12
15
  }
13
16
 
17
+ // Token definitions sit on the root or one brand anchor, never on a descendant: theme values
18
+ // are per-theme halves, resolved by the generated themes.generated.css.
19
+ const anchoredDefinition = nodes => !nodes.some(node => node.type === "combinator") && rootAnchor(nodes);
20
+
14
21
  function rootCompound(node) {
15
22
  for (let current = node; current.parent; current = current.parent) {
16
23
  const parent = current.parent;
@@ -28,11 +35,18 @@ function rootCompound(node) {
28
35
  }
29
36
 
30
37
  /** Global defaults may address native elements and explicit document themes, not UI owners. */
38
+ // The one relational document rule: a modal dialog locks the page scroll behind it, keeping the
39
+ // scrollbar's space (html { scrollbar-gutter: stable }) so nothing shifts.
40
+ const modalLock = selector => selector.replace(/\s+/g, "").toLowerCase() === "html:has(:modal)";
41
+ const modalLockDeclaration = (selector, property, value) => modalLock(selector) ? property === "overflow" && value === "hidden"
42
+ : selector.trim().toLowerCase() === "html" && property === "scrollbar-gutter" && value === "stable";
43
+
31
44
  export function foundationSelector(selector, { definitions = false } = {}) {
45
+ if (modalLock(selector) && !definitions) return null;
32
46
  try {
33
47
  let violation = false;
34
48
  selectorParser(root => {
35
- if (definitions && root.nodes.some(selector => selector.nodes.some(node => node.type === "combinator") || !rootAnchor(selector.nodes))) violation = true;
49
+ if (definitions && root.nodes.some(selector => !anchoredDefinition(selector.nodes))) violation = true;
36
50
  root.walk(node => {
37
51
  if (["class", "id"].includes(node.type) && !rootCompound(node)) violation = true;
38
52
  if (node.type === "tag" && node.value.includes("-")) violation = true;
@@ -99,6 +113,8 @@ function roleAllows(rule, nodes, property, value) {
99
113
 
100
114
  /** Closed foundation roles apply even when a native selector uses valid tokens. */
101
115
  export function foundationDeclaration(rule, declaration) {
116
+ if (modalLockDeclaration(rule.selector, declaration.prop.toLowerCase(), declaration.value.trim())) return null;
117
+ if (modalLock(rule.selector)) return "html:has(:modal) only locks the page scroll behind a modal dialog: overflow: hidden.";
102
118
  try {
103
119
  const selectors = selectorParser().astSync(rule.selector);
104
120
  const property = declaration.prop.toLowerCase(), value = declaration.value.trim();
package/dist/icons.mjs ADDED
@@ -0,0 +1,107 @@
1
+ import { existsSync, lstatSync, readFileSync, readdirSync, statSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { glyphViewBox, inspectGlyphs } from "./assets.mjs";
4
+ import { glyphAliases, glyphMarkup } from "./brand-assets.mjs";
5
+ import { isTestFile } from "./config.mjs";
6
+ import { inspectTokens } from "./tokens.mjs";
7
+
8
+ export const ICONS_URI = "ads://project/icons";
9
+ const logoTypes = { ".svg": "image/svg+xml", ".png": "image/png", ".webp": "image/webp", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif" };
10
+ const logoBytes = 1024 * 1024;
11
+ const relative = (root, file) => path.relative(root, file).replaceAll("\\", "/");
12
+
13
+ function files(directory) {
14
+ const stat = lstatSync(directory, { throwIfNoEntry: false });
15
+ if (!stat || stat.isSymbolicLink() || !stat.isDirectory()) return [];
16
+ return readdirSync(directory, { withFileTypes: true }).filter(entry => entry.isFile()).map(entry => entry.name).sort();
17
+ }
18
+
19
+ /** The folders the Icons view reads; their files' changes refresh it. */
20
+ export function iconInputs({ dsRoot, config }) {
21
+ const glyphs = config.assets.glyphs;
22
+ if (!glyphs) return [];
23
+ const directories = [path.join(dsRoot, glyphs.source), path.join(dsRoot, "assets/logos")];
24
+ return [...directories, ...directories.flatMap(directory => files(directory).map(name => path.join(directory, name)))];
25
+ }
26
+
27
+ /** Each --icon-* token resolved to pixels through var() chains; unresolvable sizes are left out. */
28
+ function iconSizes(options) {
29
+ let tokens;
30
+ try { tokens = inspectTokens(options.root, options).tokens; } catch { return []; }
31
+ const values = new Map();
32
+ for (const token of tokens) {
33
+ const definitions = token.definitions ?? [];
34
+ const plain = definitions.find(item => !item.theme && !item.brand && !item.conditional && item.scope === ":root") ?? definitions.find(item => !item.theme && !item.brand) ?? definitions[0];
35
+ if (plain) values.set(token.name, plain.value);
36
+ }
37
+ const resolve = (value, depth = 0) => {
38
+ if (depth > 12) return null;
39
+ const match = String(value).trim().match(/^var\(\s*(--[\w-]+)\s*(?:,\s*(.+))?\)$/);
40
+ if (match) return values.has(match[1]) ? resolve(values.get(match[1]), depth + 1) : match[2] ? resolve(match[2], depth + 1) : null;
41
+ const length = String(value).trim().match(/^(-?\d*\.?\d+)(px|rem)$/i);
42
+ if (!length) return null;
43
+ const px = Number(length[1]) * (length[2].toLowerCase() === "rem" ? 16 : 1);
44
+ return px > 0 ? Math.round(px * 100) / 100 : null;
45
+ };
46
+ return [...values.keys()].filter(name => /^--icon-[\w-]+$/.test(name))
47
+ .map(token => ({ token, px: resolve(values.get(token)) })).filter(size => size.px !== null)
48
+ .sort((a, b) => a.px - b.px || a.token.localeCompare(b.token));
49
+ }
50
+
51
+ /** The size the project's Icon draws beside text: the first --icon-* its own sources (beside the glyph module) use, else the smallest of 16 px or more. */
52
+ function textSize({ dsRoot, config }, sizes) {
53
+ const output = path.join(dsRoot, config.assets.glyphs.output), folder = path.dirname(output);
54
+ for (const name of files(folder)) {
55
+ const file = path.join(folder, name);
56
+ if (file === output || !/\.[cm]?[jt]sx?$/.test(name) || isTestFile(name) || /\.(?:scenario|fixture)\.[jt]sx?$/.test(name)) continue;
57
+ for (const match of readFileSync(file, "utf8").matchAll(/var\(\s*(--icon-[\w-]+)/g)) {
58
+ const size = sizes.find(item => item.token === match[1]);
59
+ if (size) return size;
60
+ }
61
+ }
62
+ return sizes.find(size => size.px >= 16) ?? sizes.at(-1) ?? null;
63
+ }
64
+
65
+ function parseBox(box) {
66
+ const numbers = box?.split(/[\s,]+/).map(Number);
67
+ return numbers?.length === 4 && numbers.every(Number.isFinite) && numbers[2] > 0 && numbers[3] > 0 ? { x: numbers[0], y: numbers[1], width: numbers[2], height: numbers[3] } : null;
68
+ }
69
+
70
+ /** The glyph set, its aliases, icon sizes, per-glyph findings and other products' logos for the showcase's Icons view. */
71
+ export function iconSet(options) {
72
+ const { root, dsRoot, config } = options;
73
+ const glyphs = config.assets.glyphs;
74
+ if (!glyphs) return { configured: false };
75
+ const directory = path.join(dsRoot, glyphs.source);
76
+ const findings = [];
77
+ const names = files(directory).filter(name => name.toLowerCase().endsWith(".svg")).map(name => name.slice(0, -4));
78
+ const { aliases } = glyphAliases(directory, names);
79
+ const attributes = glyphs.attributes ?? {};
80
+ const set = files(directory).filter(name => name.toLowerCase().endsWith(".svg")).map(name => {
81
+ const file = path.join(directory, name), text = readFileSync(file, "utf8"), viewBox = glyphViewBox(text);
82
+ return { name: name.slice(0, -4), file: relative(root, file), viewBox, grid: parseBox(viewBox), svg: glyphMarkup(text, attributes), aliases: [], findings: [] };
83
+ }).filter(glyph => !Object.hasOwn(aliases, glyph.name));
84
+ const byName = new Map(set.map(glyph => [glyph.name, glyph]));
85
+ // Alias problems come with the glyph check's findings below.
86
+ for (const [alias, target] of Object.entries(aliases).sort(([a], [b]) => a.localeCompare(b))) byName.get(target)?.aliases.push(alias);
87
+ const byFile = new Map(set.map(glyph => [glyph.file, glyph]));
88
+ for (const { rule, severity, file, message } of inspectGlyphs(options)) {
89
+ const finding = { rule, severity: severity ?? "error", file, message };
90
+ (byFile.get(file)?.findings ?? findings).push(finding);
91
+ }
92
+ const boxes = [...new Set(set.map(glyph => glyph.viewBox).filter(Boolean))];
93
+ const sizes = iconSizes(options);
94
+ const logoDirectory = path.join(dsRoot, "assets/logos");
95
+ const logos = files(logoDirectory).filter(name => Object.hasOwn(logoTypes, path.extname(name).toLowerCase())).flatMap(name => {
96
+ const file = path.join(logoDirectory, name);
97
+ if (statSync(file).size > logoBytes) return [{ name: path.basename(name, path.extname(name)), file: relative(root, file), tooLarge: true }];
98
+ return [{ name: path.basename(name, path.extname(name)), file: relative(root, file), src: `data:${logoTypes[path.extname(name).toLowerCase()]};base64,${readFileSync(file).toString("base64")}` }];
99
+ });
100
+ return {
101
+ configured: true, source: relative(root, directory),
102
+ grid: boxes.length === 1 ? parseBox(boxes[0]) : null, mixed: boxes.length > 1,
103
+ aliasCount: Object.keys(aliases).length, sizes, textSize: textSize(options, sizes),
104
+ glyphs: set, findings,
105
+ logos: existsSync(logoDirectory) ? { source: relative(root, logoDirectory), files: logos } : null,
106
+ };
107
+ }
package/dist/init.mjs CHANGED
@@ -4,6 +4,7 @@ import { fileURLToPath } from "node:url";
4
4
  import ts from "typescript";
5
5
  import { isInside, loadConfig, sourceFiles, supportedFrameworks } from "./config.mjs";
6
6
  import { foundationFiles } from "./token-policy.mjs";
7
+ import { generatedPaletteFile } from "./palette-generated.mjs";
7
8
  import { assertFrameworkCompiler } from "./ui-framework.mjs";
8
9
 
9
10
  const tool = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
@@ -156,6 +157,8 @@ export function initProject(directory = process.cwd(), { toolPackage, packageMan
156
157
  return file;
157
158
  });
158
159
  if (!existingTokens.length) {
160
+ // The renderer palette generated from the starter's token sheets, beside its theme sheet.
161
+ addMissing(path.join(tokenRoot, generatedPaletteFile), readFileSync(path.join(starter, "design-system/tokens", generatedPaletteFile)));
159
162
  // The starter's token groups, each a scenario with its fixture.
160
163
  for (const name of readdirSync(path.join(starter, "design-system/tokens")).filter(name => /\.ads\.(?:scenario\.tsx|fixture\.ts)$/.test(name)).sort()) {
161
164
  const content = readFileSync(path.join(starter, "design-system/tokens", name), "utf8").replaceAll('"@ds/review"', JSON.stringify(`${config.publicAlias}/review`)).replaceAll('"@ds"', JSON.stringify(config.publicAlias));
package/dist/mcp/apps.mjs CHANGED
@@ -1,6 +1,8 @@
1
1
  import { readFileSync, realpathSync, statSync } from "node:fs";
2
2
  import { isInside, projectPath } from "../config.mjs";
3
3
  import { PREVIEW_APP_URI } from "../preview-resources.mjs";
4
+ import { themesCss } from "../themes-generated.mjs";
5
+ import { defaultThemes } from "../themes.mjs";
4
6
  export { PREVIEW_APP_URI };
5
7
 
6
8
  export const APP_MIME = "text/html;profile=mcp-app";
@@ -18,19 +20,20 @@ export function previewApp(selection) {
18
20
  export function tokenWidgetData(inventory) {
19
21
  const scopes = new Map();
20
22
  for (const token of inventory.tokens) for (const definition of token.definitions) {
21
- // Conditional definitions are displayed verbatim; simple theme selectors
22
- // also drive the in-frame browser samples, including alias resolution.
23
- if (definition.scope.includes("@") || definition.scope.includes(" > ")) continue;
23
+ // Conditional definitions are displayed verbatim; the root and brand definitions, with the
24
+ // generated theme resolvers, drive the in-frame browser samples, including alias resolution.
25
+ if (definition.conditional) continue;
24
26
  if (!scopes.has(definition.scope)) scopes.set(definition.scope, []);
25
- scopes.get(definition.scope).push(`${token.name}:${definition.value};`);
27
+ scopes.get(definition.scope).push(`${definition.property ?? token.name}:${definition.authored ?? definition.value};`);
26
28
  }
27
- return { ...inventory, css: [...scopes].map(([selector, declarations]) => `${selector}{${declarations.join("")}}`).join("\n") };
29
+ const css = [...scopes].map(([selector, declarations]) => `${selector}{${declarations.join("")}}`).join("\n");
30
+ return { ...inventory, css: `${css}\n${themesCss(inventory.tokens, { themes: inventory.themes ?? defaultThemes, brands: inventory.brands ?? [] })}` };
28
31
  }
29
32
 
30
33
  export function tokensApp(data) {
31
34
  return `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>ADS tokens</title><style>
32
35
  html{color-scheme:light dark;background:Canvas;color:CanvasText;font:13px/1.55 system-ui}html,body{height:100%}body{margin:0}#ads-token-root{padding:32px}#ads-scenario-root{height:100%}header{display:flex;gap:8px;flex-wrap:wrap;align-items:center}h1{font-size:18px;margin:0 auto 0 0}button,input,select{font:inherit;color:CanvasText;background:Canvas;border:1px solid GrayText;border-radius:4px;padding:6px 8px}ul{padding:0;list-style:none}li{margin:12px 0}summary{cursor:pointer;display:flex;gap:16px;align-items:baseline;flex-wrap:wrap}code{font:12px monospace;overflow-wrap:anywhere}dl{border:1px solid GrayText;padding:12px;overflow-wrap:anywhere}dt{font-weight:600}dd{margin:2px 0 12px}footer{display:flex;gap:8px;align-items:center}iframe{display:block;width:100%;height:100%;border:0}[hidden]{display:none!important}:root[data-theme="light"]{color-scheme:light}:root[data-theme="dark"]{color-scheme:dark}
33
- </style></head><body><p id="ads-scenario-status" role="status" hidden></p><main id="ads-scenario-root" hidden></main><main id="ads-token-root"><header><h1>Token definitions</h1><input id="ads-token-search" type="search" aria-label="Find token" placeholder="Find a token"><select id="ads-token-theme" aria-label="Preview theme"><option value="light">Light</option><option value="dark">Dark</option></select><button id="ads-token-refresh" type="button" disabled>Refresh</button></header><p id="ads-widget-status" role="status">Connecting to the Apps host…</p><ul id="ads-token-list"></ul><footer><button id="ads-token-prev" type="button">Previous</button><span id="ads-token-count"></span><button id="ads-token-next" type="button">Next</button></footer></main><script type="application/json" id="ads-token-seed">${safeJson(data)}</script><script type="module">${bridge()}</script></body></html>`;
36
+ </style></head><body><p id="ads-scenario-status" role="status" hidden></p><main id="ads-scenario-root" hidden></main><main id="ads-token-root"><header><h1>Token definitions</h1><input id="ads-token-search" type="search" aria-label="Find token" placeholder="Find a token"><select id="ads-token-theme" aria-label="Preview theme"></select><select id="ads-token-brand" aria-label="Preview brand" hidden></select><button id="ads-token-refresh" type="button" disabled>Refresh</button></header><p id="ads-widget-status" role="status">Connecting to the Apps host…</p><ul id="ads-token-list"></ul><footer><button id="ads-token-prev" type="button">Previous</button><span id="ads-token-count"></span><button id="ads-token-next" type="button">Next</button></footer></main><script type="application/json" id="ads-token-seed">${safeJson(data)}</script><script type="module">${bridge()}</script></body></html>`;
34
37
  }
35
38
 
36
39
  export function scenarioApp() {
@@ -1,4 +1,5 @@
1
1
  import { spawnSync } from "node:child_process";
2
+ import { writeThemesCss } from "../themes-generated.mjs";
2
3
  import { mkdtempSync } from "node:fs";
3
4
  import { tmpdir } from "node:os";
4
5
  import { createHash, randomUUID } from "node:crypto";
@@ -327,6 +328,8 @@ export function createDraftController(directory, { edits, startPreview, prewarm
327
328
  for (const target of session.inputs.keys()) if (!desired.has(target)) rmSync(safe(session.workspace, target), { force: true });
328
329
  for (const [target, content] of desired) if (session.inputs.get(target) !== hash(content) || !existsSync(safe(session.workspace,target))) atomic(safe(session.workspace, target), content);
329
330
  session.inputs = new Map([...desired].map(([target, content]) => [target, hash(content)]));
331
+ // A draft's token edits preview with their own generated theme sheet.
332
+ try { const draftOptions = loadConfig(session.workspace); writeThemesCss(draftOptions, inspectTokens(session.workspace, draftOptions)); } catch { /* Acceptance checks report broken token sheets. */ }
330
333
  const modules = path.join(session.workspace, "node_modules");
331
334
  if (!existsSync(modules) && existsSync(path.join(root, "node_modules"))) symlinkSync(realpathSync(path.join(root, "node_modules")), modules, process.platform === "win32" ? "junction" : "dir");
332
335
  if (!existsSync(path.join(session.workspace, "dist")) && existsSync(path.join(root, "dist/cli.mjs"))) {
@@ -16,6 +16,8 @@ import { checkCandidate, checkCommand, projectChecks as checks } from "../valida
16
16
  import { preparePreviewCache } from "../scenarios-compiler.mjs";
17
17
  import { validationInputFiles } from "../validation-inputs.mjs";
18
18
  import { mutationLimits } from "./mutation-limits.mjs";
19
+ import { writeThemesCss } from "../themes-generated.mjs";
20
+ import { inspectTokens } from "../tokens.mjs";
19
21
 
20
22
  export { mutationLimits } from "./mutation-limits.mjs";
21
23
  const digest = bytes => `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
@@ -178,7 +180,7 @@ export function createMutationController(directory, { captures = createCaptureCo
178
180
  const verified = [];
179
181
  try {
180
182
  const options = loadConfig(root);
181
- if (screenshot && !dryRun || selections !== undefined && !screenshot) throw fail("mutation-capture", "Use screenshot:true only with dryRun:true and an explicit captures:[{scenario,target?,theme?,viewport?}] selection. Ordinary patches create no screenshots.");
183
+ if (screenshot && !dryRun || selections !== undefined && !screenshot) throw fail("mutation-capture", "Use screenshot:true only with dryRun:true and an explicit captures:[{scenario,target?,theme?,brand?,viewport?}] selection. Ordinary patches create no screenshots.");
182
184
  if (screenshot) selections = captureSelections(selections);
183
185
  if (patches !== undefined && (unit !== undefined || patch !== undefined || patchFile !== undefined || !Array.isArray(patches) || patches.length < 2 || patches.length > mutationLimits.units)) throw fail("mutation-batch", `A transaction requires 2–${mutationLimits.units} distinct owner patches, without a top-level unit/patch.`);
184
186
  const groups = patches ?? [{unit,patch,patchFile}];
@@ -259,6 +261,20 @@ export function createMutationController(directory, { captures = createCaptureCo
259
261
  }
260
262
  checkUnitCandidate(loadConfig(candidate),plan.unit,selected,inventory);
261
263
  }
264
+ // Token sheet and theme/brand config patches carry the regenerated theme sheet with them.
265
+ {
266
+ const generatedOptions = loadConfig(candidate);
267
+ for (const generated of writeThemesCss(generatedOptions, inspectTokens(candidate, generatedOptions)).files) {
268
+ const relative = path.relative(candidate, generated.file).replaceAll("\\", "/"), current = generated.text !== undefined && read(options, relative);
269
+ if (current && current.content !== generated.text) {
270
+ if (!byPath.has(relative)) {
271
+ originals.push({...current,mode:current.exists ? lstatSync(address(options,relative)).mode : undefined});
272
+ byPath.set(relative,changes.length);
273
+ changes.push({path:relative,originalContent:current.content,content:generated.text,expectedDigest:current.digest});
274
+ } else changes[byPath.get(relative)].content = generated.text;
275
+ }
276
+ }
277
+ }
262
278
  const candidateOptions = loadConfig(candidate);
263
279
  // A proposed configuration may add roots or explicit inputs. Preserve
264
280
  // already patched files while bringing those additional live inputs in.