@reqvire-org/ads 0.3.46 → 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.
- package/README.md +21 -11
- package/dist/a11y.mjs +4 -2
- package/dist/assets.mjs +20 -15
- package/dist/atomic-composition.mjs +3 -2
- package/dist/brand-assets.mjs +48 -11
- package/dist/brands.mjs +82 -0
- package/dist/browser-audit/worker.mjs +45 -0
- package/dist/browser-audit.mjs +117 -0
- package/dist/capture/worker.mjs +1 -0
- package/dist/capture-store.mjs +2 -0
- package/dist/capture.mjs +7 -4
- package/dist/check.mjs +38 -8
- package/dist/cli.mjs +45 -10
- package/dist/color-values.mjs +325 -0
- package/dist/config.mjs +16 -2
- package/dist/control-padding.mjs +93 -0
- package/dist/design-values.mjs +3 -2
- package/dist/finding-rules.mjs +61 -0
- package/dist/foundation.mjs +17 -4
- package/dist/icons.mjs +107 -0
- package/dist/init.mjs +3 -0
- package/dist/mcp/apps.mjs +9 -6
- package/dist/mcp/drafts.mjs +3 -0
- package/dist/mcp/mutations.mjs +17 -1
- package/dist/mcp/preview-widget.bundle.js +36 -36
- package/dist/mcp/project-widget.bundle.js +12 -12
- package/dist/mcp/server.mjs +21 -9
- package/dist/mcp/widget.bundle.js +17 -17
- package/dist/palette-generated.mjs +180 -0
- package/dist/preview-resources.mjs +12 -3
- package/dist/render-color-probe.mjs +148 -0
- package/dist/runtime-contracts.mjs +14 -4
- package/dist/scenarios.mjs +1 -1
- package/dist/showcase/client.bundle.js +28 -28
- package/dist/showcase/icons.js +146 -0
- package/dist/showcase/index.html +2 -1
- package/dist/showcase/style.css +19 -2
- package/dist/skills/README.md +2 -1
- package/dist/skills/ads-break-ui/SKILL.md +6 -5
- package/dist/skills/ads-break-ui/references/atomic-styles.md +12 -12
- package/dist/skills/ads-break-ui/references/contracts.md +13 -10
- package/dist/skills/ads-break-ui/references/design-data.md +137 -29
- package/dist/skills/ads-break-ui/references/validation.md +8 -4
- package/dist/skills/ads-designer/SKILL.md +23 -16
- package/dist/skills/ads-designer/references/accessibility.md +39 -5
- package/dist/skills/ads-designer/references/atomic-styles.md +12 -12
- package/dist/skills/ads-designer/references/branding.md +37 -10
- package/dist/skills/ads-designer/references/cli.md +8 -2
- package/dist/skills/ads-designer/references/contracts.md +13 -10
- package/dist/skills/ads-designer/references/design-data.md +137 -29
- package/dist/skills/ads-designer/references/validation.md +8 -4
- package/dist/skills/ads-import/SKILL.md +9 -8
- package/dist/skills/ads-import/references/atomic-styles.md +12 -12
- package/dist/skills/ads-import/references/cli.md +8 -2
- package/dist/skills/ads-import/references/contracts.md +13 -10
- package/dist/skills/ads-import/references/design-data.md +137 -29
- package/dist/skills/ads-import/references/tokens.md +7 -3
- package/dist/skills/ads-import/references/validation.md +8 -4
- package/dist/skills/ads-motion/SKILL.md +6 -5
- package/dist/skills/ads-motion/references/atomic-styles.md +12 -12
- package/dist/skills/ads-motion/references/contracts.md +13 -10
- package/dist/skills/ads-motion/references/design-data.md +137 -29
- package/dist/skills/ads-motion/references/validation.md +8 -4
- package/dist/skills/ads-port/SKILL.md +6 -5
- package/dist/skills/ads-port/references/atomic-styles.md +12 -12
- package/dist/skills/ads-port/references/cli.md +8 -2
- package/dist/skills/ads-port/references/contracts.md +13 -10
- package/dist/skills/ads-port/references/design-data.md +137 -29
- package/dist/skills/ads-port/references/validation.md +8 -4
- package/dist/starters/preact/design-system/review/token-preview/TokenPreview.tsx +11 -2
- package/dist/starters/react/ADS.md +43 -10
- package/dist/starters/react/README.md +14 -9
- package/dist/starters/react/design-system/assets/brand/README.md +8 -3
- package/dist/starters/react/design-system/assets/glyphs/README.md +4 -1
- package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.fixture.ts +6 -1
- package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.scenario.tsx +3 -2
- package/dist/starters/react/design-system/components/Content/Icon/README.md +2 -1
- package/dist/starters/react/design-system/components/Content/Logo/Logo.tsx +3 -9
- package/dist/starters/react/design-system/components/Content/Logo/README.md +4 -2
- package/dist/starters/react/design-system/controllers/Palette/Palette.ts +164 -0
- package/dist/starters/react/design-system/index.ts +3 -0
- package/dist/starters/react/design-system/review/brand-preview/BrandPreview.tsx +2 -5
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.tsx +11 -2
- package/dist/starters/react/design-system/styles.css +1 -0
- package/dist/starters/react/design-system/tokens/base.css +8 -5
- package/dist/starters/react/design-system/tokens/colors.css +167 -175
- package/dist/starters/react/design-system/tokens/elevation.css +14 -21
- package/dist/starters/react/design-system/tokens/themes.generated.css +142 -0
- package/dist/starters/react/design-system/tokens/themes.generated.ts +402 -0
- package/dist/style-boundaries.mjs +2 -1
- package/dist/themes-generated.mjs +150 -0
- package/dist/themes-watch.mjs +42 -0
- package/dist/themes.mjs +214 -63
- package/dist/token-export.mjs +22 -11
- package/dist/token-policy.mjs +2 -1
- package/dist/token-quality.mjs +28 -25
- package/dist/tokens.mjs +27 -32
- package/dist/validation.mjs +18 -1
- package/dist/verification/browser.mjs +14 -3
- package/docs/ADS.md +41 -27
- package/docs/ARCHITECTURE.md +49 -22
- package/docs/CACHING.md +2 -3
- package/docs/CHANGELOG.md +97 -13
- package/docs/CONTRACTS.md +13 -10
- package/docs/GUIDE.md +89 -21
- package/docs/MCP.md +35 -25
- package/docs/benchmarks/bun-previews.md +5 -5
- package/docs/benchmarks/{gidi-preview-memory.md → preview-memory.md} +14 -12
- package/docs/benchmarks/turbo-poc.md +24 -6
- package/package.json +2 -1
package/dist/config.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { fileURLToPath } from "node:url";
|
|
|
4
4
|
import { isDraftFile, draftImportViolation } from "./draft-boundary.mjs";
|
|
5
5
|
import { isSharedToken } from "./token-policy.mjs";
|
|
6
6
|
import { defaultThemes, validateThemes } from "./themes.mjs";
|
|
7
|
+
import { validateBrands } from "./brands.mjs";
|
|
7
8
|
|
|
8
9
|
export const supportedFrameworks = ["react", "preact"];
|
|
9
10
|
|
|
@@ -20,12 +21,16 @@ export const defaultConfig = {
|
|
|
20
21
|
stylesEntry: "styles.css",
|
|
21
22
|
tokenDir: "tokens",
|
|
22
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,
|
|
23
28
|
inlineStyleFiles: [],
|
|
24
29
|
boundaries: { styleWrites: [], componentVariables: [] },
|
|
25
30
|
assets: { publicDirs: ["public/assets"], generatedPaths: ["dist", "dist-showcase", ".vite", ".ds"], generatedFiles: [], iconSource: null, targets: [], glyphs: null },
|
|
26
31
|
oxlint: { plugins: [], rules: {}, overrides: [] },
|
|
27
|
-
acceptance: { checks: [], behaviorChecks: false },
|
|
28
|
-
validation: { checks: [], behaviorChecks: true, inputs: [] },
|
|
32
|
+
acceptance: { checks: [], behaviorChecks: false, browserAudit: false },
|
|
33
|
+
validation: { checks: [], behaviorChecks: true, browserAudit: false, inputs: [] },
|
|
29
34
|
resources: { memoryLimitMb: null },
|
|
30
35
|
mcp: { showcaseUrl: null, showcaseTitle: null, apps: [], previewWatch: null, previewManifest: null, mutationCheckTimeoutMs: 60000, behaviorProfiles: {}, capture: {}, resultRetention: {maxRuns:50,maxAgeDays:7,maxBytesMb:256} },
|
|
31
36
|
};
|
|
@@ -102,6 +107,7 @@ export function loadConfig(directory = process.cwd()) {
|
|
|
102
107
|
const configFile = path.join(root, "ds.config.json");
|
|
103
108
|
const user = existsSync(configFile) ? JSON.parse(readFileSync(configFile, "utf8")) : {};
|
|
104
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.");
|
|
105
111
|
for (const field of Object.keys(user)) {
|
|
106
112
|
if (!(field in defaultConfig)) throw new Error(`Unknown ADS configuration field: ${field}`);
|
|
107
113
|
}
|
|
@@ -113,6 +119,13 @@ export function loadConfig(directory = process.cwd()) {
|
|
|
113
119
|
}
|
|
114
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 } };
|
|
115
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.`);
|
|
116
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.");
|
|
117
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.");
|
|
118
131
|
const notificationNames = new Set();
|
|
@@ -131,6 +144,7 @@ export function loadConfig(directory = process.cwd()) {
|
|
|
131
144
|
const policy=config[name];
|
|
132
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.`);
|
|
133
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.`);
|
|
134
148
|
}
|
|
135
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.");
|
|
136
150
|
for (const file of config.validation.inputs) {
|
|
@@ -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
|
+
}
|
package/dist/design-values.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import valueParser from "postcss-value-parser";
|
|
|
4
4
|
import { isInside } from "./config.mjs";
|
|
5
5
|
import { tokenContract } from "./token-policy.mjs";
|
|
6
6
|
import { createSourceValues, reference } from "./source-values.mjs";
|
|
7
|
+
import { findingSeverity } from "./finding-rules.mjs";
|
|
7
8
|
|
|
8
9
|
const colorCache = new Map();
|
|
9
10
|
export function isColorKeyword(value) {
|
|
@@ -74,7 +75,7 @@ export function tokenOverlapAdvisories(tokens) {
|
|
|
74
75
|
const groups=new Map();
|
|
75
76
|
for(const token of tokens) {
|
|
76
77
|
if(token.owner!=="tokens"||!token.definitions.length)continue;
|
|
77
|
-
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));
|
|
78
79
|
if(definitions.every(([,value])=>/^var\(--[\w-]+\)$/.test(value))||definitions.every(([,value])=>/^(?:0|1|none|auto|inherit|initial|unset|transparent)$/.test(value)))continue;
|
|
79
80
|
const signature=JSON.stringify([family(token.name),definitions]);
|
|
80
81
|
if(!groups.has(signature))groups.set(signature,[]);
|
|
@@ -82,6 +83,6 @@ export function tokenOverlapAdvisories(tokens) {
|
|
|
82
83
|
}
|
|
83
84
|
return [...groups.values()].filter(group=>group.length>1).map(group=>{
|
|
84
85
|
const [first]=group, {file,line,column}=first.definitions[0],names=group.map(token=>token.name);
|
|
85
|
-
return {rule:"token-overlap-review",severity:"
|
|
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.`};
|
|
86
87
|
});
|
|
87
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
|
+
}
|
package/dist/foundation.mjs
CHANGED
|
@@ -5,15 +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 scope ([data-theme]
|
|
9
|
-
// apply to the whole document or to one section of it.
|
|
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).
|
|
10
10
|
function rootAnchor(nodes) {
|
|
11
11
|
return nodes.some(node => node.type === "tag" && !node.namespace && node.value.toLowerCase() === "html"
|
|
12
|
-
|| node.type === "attribute" &&
|
|
12
|
+
|| node.type === "attribute" && ["data-theme", "data-brand"].includes(node.attribute) && (!node.operator || node.operator === "=")
|
|
13
13
|
|| node.type === "pseudo" && node.value.toLowerCase() === ":root"
|
|
14
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)));
|
|
15
15
|
}
|
|
16
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
|
+
|
|
17
21
|
function rootCompound(node) {
|
|
18
22
|
for (let current = node; current.parent; current = current.parent) {
|
|
19
23
|
const parent = current.parent;
|
|
@@ -31,11 +35,18 @@ function rootCompound(node) {
|
|
|
31
35
|
}
|
|
32
36
|
|
|
33
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
|
+
|
|
34
44
|
export function foundationSelector(selector, { definitions = false } = {}) {
|
|
45
|
+
if (modalLock(selector) && !definitions) return null;
|
|
35
46
|
try {
|
|
36
47
|
let violation = false;
|
|
37
48
|
selectorParser(root => {
|
|
38
|
-
if (definitions && root.nodes.some(selector =>
|
|
49
|
+
if (definitions && root.nodes.some(selector => !anchoredDefinition(selector.nodes))) violation = true;
|
|
39
50
|
root.walk(node => {
|
|
40
51
|
if (["class", "id"].includes(node.type) && !rootCompound(node)) violation = true;
|
|
41
52
|
if (node.type === "tag" && node.value.includes("-")) violation = true;
|
|
@@ -102,6 +113,8 @@ function roleAllows(rule, nodes, property, value) {
|
|
|
102
113
|
|
|
103
114
|
/** Closed foundation roles apply even when a native selector uses valid tokens. */
|
|
104
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.";
|
|
105
118
|
try {
|
|
106
119
|
const selectors = selectorParser().astSync(rule.selector);
|
|
107
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;
|
|
22
|
-
//
|
|
23
|
-
if (definition.
|
|
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
|
-
|
|
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"></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() {
|
package/dist/mcp/drafts.mjs
CHANGED
|
@@ -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"))) {
|
package/dist/mcp/mutations.mjs
CHANGED
|
@@ -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.
|