@reqvire-org/ads 0.3.50 → 0.3.52
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 +1 -1
- package/dist/browser-audit/axe-run.mjs +17 -0
- package/dist/browser-audit/first-render.mjs +18 -0
- package/dist/browser-audit/layout-overflow.mjs +88 -41
- package/dist/browser-audit/non-text-contrast.mjs +12 -7
- package/dist/browser-audit/render-states.mjs +182 -0
- package/dist/browser-audit/worker.mjs +23 -12
- package/dist/browser-audit.mjs +56 -13
- package/dist/bun-compiler.mjs +9 -1
- package/dist/capture/worker.mjs +2 -5
- package/dist/check.mjs +5 -3
- package/dist/cli.mjs +11 -5
- package/dist/config.mjs +2 -2
- package/dist/finding-rules.mjs +11 -0
- package/dist/layout-widths.mjs +132 -79
- package/dist/mcp/preview-watch.mjs +2 -2
- package/dist/mcp/server.mjs +2 -2
- package/dist/preview-resources.mjs +4 -1
- package/dist/scenarios-compiler.mjs +2 -2
- package/dist/skills/ads-break-ui/SKILL.md +2 -1
- package/dist/skills/ads-break-ui/references/design-data.md +34 -14
- package/dist/skills/ads-break-ui/references/validation.md +1 -1
- package/dist/skills/ads-designer/SKILL.md +6 -4
- package/dist/skills/ads-designer/references/design-data.md +34 -14
- package/dist/skills/ads-designer/references/validation.md +1 -1
- package/dist/skills/ads-import/references/design-data.md +34 -14
- package/dist/skills/ads-import/references/validation.md +1 -1
- package/dist/skills/ads-motion/references/design-data.md +34 -14
- package/dist/skills/ads-motion/references/validation.md +1 -1
- package/dist/skills/ads-port/references/design-data.md +34 -14
- package/dist/skills/ads-port/references/validation.md +1 -1
- package/dist/starters/preact/ds.config.json +0 -1
- package/dist/starters/react/README.md +6 -4
- package/dist/starters/react/design-system/components/Content/Image/Image.tsx +7 -4
- package/dist/starters/react/design-system/components/Content/Image/README.md +2 -2
- package/dist/starters/react/design-system/tokens/spacing.css +1 -1
- package/dist/starters/react/ds.config.json +0 -1
- package/docs/ADS.md +2 -2
- package/docs/ARCHITECTURE.md +9 -6
- package/docs/CHANGELOG.md +81 -12
- package/docs/GUIDE.md +77 -23
- package/package.json +1 -1
package/dist/layout-widths.mjs
CHANGED
|
@@ -2,30 +2,31 @@ import valueParser from "postcss-value-parser";
|
|
|
2
2
|
import { contextValues } from "./themes.mjs";
|
|
3
3
|
import { findingSeverity } from "./finding-rules.mjs";
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* A
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* layout.widthTokens pass
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* knows a unit's layer, not whether it floats. */
|
|
5
|
+
/** In component, pattern and composition styles, a width (width, min-width, the logical inline
|
|
6
|
+
* sizes, flex-basis or the flex shorthand's basis, and grid-template-columns tracks) is a
|
|
7
|
+
* layout-fixed-width error when it cannot shrink below smallPartLimitPx: raw, through tokens, in
|
|
8
|
+
* any length unit, or by arithmetic. Every value is read as what it resolves to in the smallest
|
|
9
|
+
* and the largest container, so max(100%, 280px) is fixed at 280px, and min(100%, 280px) is not.
|
|
10
|
+
* A maximum cannot force overflow, so max-width and max-inline-size are not read at all, except
|
|
11
|
+
* that a fluid one in the same rule lets a width shrink.
|
|
12
|
+
* What the source cannot settle (a variable with no definition) passes; the audit renders it.
|
|
13
|
+
* Tokens named by layout.widthTokens pass when used plainly, and fixed ones are listed for review,
|
|
14
|
+
* as are the fixed widths of owners matched by layout.fixedWidthUnits, which is where overlays
|
|
15
|
+
* such as dialogs, menus, popovers and tooltips are declared: ADS knows a unit's layer, not
|
|
16
|
+
* whether it floats. */
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
18
|
+
/** The largest plain size a part may have: see the Layout section of the guide for the evidence. */
|
|
19
|
+
export const smallPartLimitPx = 96;
|
|
20
|
+
const widthProperties = new Set(["width", "min-width", "inline-size", "min-inline-size", "flex-basis", "flex", "grid-template-columns"]);
|
|
21
|
+
const fluidUnits = /^(?:%|fr|[sld]?v(?:w|h|i|b|min|max)|cq(?:w|h|i|b|min|max))$/i;
|
|
22
|
+
/** Lengths in px. A font-relative one is estimated at the rule's font-size, or 16 px. It is still fixed. */
|
|
23
|
+
const absoluteUnits = { px: 1, pt: 4 / 3, pc: 16, in: 96, cm: 96 / 2.54, mm: 96 / 25.4, q: 96 / 101.6, rem: 16, rlh: 24 };
|
|
24
|
+
/** Per px of the element's font size, as estimates. */
|
|
25
|
+
const fontUnits = { em: 1, ic: 1, ch: 0.5, ex: 0.5, cap: 0.7, lh: 1.5 };
|
|
27
26
|
const keywords = /^(?:auto|none|min-content|max-content|fit-content|stretch|inherit|initial|unset|revert|revert-layer|content|subgrid)$/i;
|
|
28
|
-
const fluid = {
|
|
27
|
+
const fluid = { low: 0, high: Infinity }, neutral = { neutral: true }, unknown = { unknown: true };
|
|
28
|
+
const isLength = part => part.low !== undefined;
|
|
29
|
+
const fixedAt = px => ({ low: px, high: px });
|
|
29
30
|
|
|
30
31
|
/** A regular expression for a token or path glob: * within a path segment, ** across them. */
|
|
31
32
|
export function globPattern(glob) {
|
|
@@ -44,54 +45,76 @@ function splitArguments(nodes) {
|
|
|
44
45
|
export function createLayoutWidths(tokens, { themes, layout }) {
|
|
45
46
|
const values = contextValues(tokens, { theme: themes[0].name, themes });
|
|
46
47
|
const widthToken = globMatcher(layout.widthTokens);
|
|
47
|
-
const
|
|
48
|
-
/** A named width token is allowed; only a fixed --container-* cap is limited to max sizes. */
|
|
49
|
-
const cap = name => capToken.test(name) && values.has(name) && !isFluid(name, values.get(name).value);
|
|
48
|
+
const declaredUses = new Map();
|
|
50
49
|
|
|
51
50
|
function variable(node, scope) {
|
|
52
51
|
const [name, fallback = []] = splitArguments(node.nodes).map(meaningful);
|
|
53
52
|
const token = name?.find(child => child.type === "word")?.value;
|
|
54
53
|
if (!token?.startsWith("--")) return unknown;
|
|
55
|
-
if (widthToken(token)) return cap(token) ? { cap: token } : neutral;
|
|
56
|
-
if (sizeFamilies.test(token)) return neutral;
|
|
57
54
|
if (scope.seen.has(token)) return unknown;
|
|
58
55
|
const seen = new Set([...scope.seen, token]);
|
|
59
56
|
// Component variables declared in the same template are read through, so a width cannot hide in one.
|
|
60
57
|
const local = scope.locals.get(token);
|
|
61
|
-
if (local)
|
|
58
|
+
if (local) {
|
|
59
|
+
const results = local.map(value => sequence(valueParser(value).nodes, { ...scope, seen })).filter(isLength);
|
|
60
|
+
return results.length ? results.reduce((worst, result) => result.low > worst.low ? result : worst) : unknown;
|
|
61
|
+
}
|
|
62
62
|
const value = values.get(token)?.value;
|
|
63
63
|
if (value === undefined) return fallback.length ? sequence(fallback, { ...scope, seen }) : unknown;
|
|
64
64
|
const result = sequence(valueParser(value).nodes, { ...scope, seen });
|
|
65
|
-
|
|
65
|
+
if (!widthToken(token)) return result;
|
|
66
|
+
scope.declared?.add(token);
|
|
67
|
+
return { ...(isLength(result) ? result : neutral), declared: token };
|
|
66
68
|
}
|
|
67
|
-
/** One value part: {
|
|
69
|
+
/** One value part: { neutral } | { unknown } | { number } | { low, high, declared? }, the length
|
|
70
|
+
* it resolves to in the smallest and the largest container. */
|
|
68
71
|
function measure(node, scope) {
|
|
69
72
|
if (node.type === "word") {
|
|
70
73
|
const parsed = valueParser.unit(node.value);
|
|
71
74
|
if (!parsed) return keywords.test(node.value) ? neutral : unknown;
|
|
72
75
|
const number = Number(parsed.number), unit = parsed.unit.toLowerCase();
|
|
73
|
-
if (!unit) return { number };
|
|
74
|
-
if (number === 0
|
|
75
|
-
|
|
76
|
+
if (!unit) return number === 0 ? fixedAt(0) : { number };
|
|
77
|
+
if (number === 0) return fixedAt(0);
|
|
78
|
+
if (fluidUnits.test(unit)) return fluid;
|
|
79
|
+
const size = absoluteUnits[unit] ?? (fontUnits[unit] ? fontUnits[unit] * (scope.fontPx ?? 16) : undefined);
|
|
80
|
+
return size ? fixedAt(number * size) : unknown;
|
|
76
81
|
}
|
|
77
82
|
if (node.type !== "function") return unknown;
|
|
78
83
|
const name = node.value.toLowerCase();
|
|
79
84
|
if (name === "var") return variable(node, scope);
|
|
80
85
|
if (name === "calc" || name === "") return calculation(node.nodes, scope);
|
|
81
86
|
if (name === "fit-content") return neutral;
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
if (name === "min") return smallest(splitArguments(node.nodes).map(part => sequence(part, scope)));
|
|
88
|
+
if (name === "max") return largest(splitArguments(node.nodes).map(part => sequence(part, scope)));
|
|
89
|
+
if (name !== "clamp") return unknown;
|
|
90
|
+
const [floor, preferred, ceiling] = splitArguments(node.nodes).map(part => sequence(part, scope));
|
|
91
|
+
const value = floor?.neutral ? (ceiling?.neutral || !ceiling ? preferred ?? unknown : smallest([preferred, ceiling]))
|
|
92
|
+
// A preferred value that cannot be read still leaves the floor: it cannot shrink below that.
|
|
93
|
+
: isLength(floor) && !isLength(preferred ?? unknown) ? { low: floor.low, high: Infinity }
|
|
94
|
+
: largest([floor, !ceiling || ceiling.neutral ? preferred : smallest([preferred, ceiling])]);
|
|
95
|
+
// A resizable part: every value is a declared width, each listed for review.
|
|
96
|
+
return floor?.declared && preferred?.declared && ceiling?.declared ? { ...(isLength(value) ? value : neutral), declared: "clamp" } : value;
|
|
97
|
+
}
|
|
98
|
+
/** min(): a part that reaches zero lets the whole shrink, whatever the others are. */
|
|
99
|
+
function smallest(parts) {
|
|
100
|
+
const lengths = parts.filter(isLength), open = lengths.length !== parts.length;
|
|
101
|
+
if (!lengths.length || open && !lengths.some(part => part.low === 0)) return unknown;
|
|
102
|
+
return { low: Math.min(...lengths.map(part => part.low)), high: open ? Infinity : Math.min(...lengths.map(part => part.high)) };
|
|
103
|
+
}
|
|
104
|
+
/** max(): it cannot shrink below any part, so a part that cannot be read leaves it unread. */
|
|
105
|
+
function largest(parts) {
|
|
106
|
+
if (!parts.every(isLength)) return unknown;
|
|
107
|
+
return { low: Math.max(...parts.map(part => part.low)), high: Math.max(...parts.map(part => part.high)) };
|
|
89
108
|
}
|
|
90
109
|
function sequence(nodes, scope) {
|
|
91
110
|
const items = meaningful(nodes);
|
|
92
111
|
return items.length === 1 ? measure(items[0], scope) : unknown;
|
|
93
112
|
}
|
|
94
|
-
|
|
113
|
+
const scaled = (length, factor) => {
|
|
114
|
+
const [low, high] = [length.low, length.high].map(size => factor === 0 ? 0 : size * factor);
|
|
115
|
+
return factor < 0 ? { low: high, high: low } : { low, high };
|
|
116
|
+
};
|
|
117
|
+
/** calc(): evaluated at both ends, so 100% - 200px reaches zero and 100% + 200px does not. */
|
|
95
118
|
function calculation(nodes, scope) {
|
|
96
119
|
const operands = [], operators = [];
|
|
97
120
|
for (const item of meaningful(nodes)) {
|
|
@@ -101,83 +124,113 @@ export function createLayoutWidths(tokens, { themes, layout }) {
|
|
|
101
124
|
// valueParser keeps * and calc()'s / in a word, spaced or not.
|
|
102
125
|
for (const part of item.value.split(/([*/])/).filter(Boolean)) { if (part === "*" || part === "/") operators.push(part); else operands.push(measure({ type: "word", value: part }, scope)); }
|
|
103
126
|
}
|
|
104
|
-
if (operands.some(operand => operand.
|
|
105
|
-
if (operands.length !== operators.length + 1 || operands.some(operand => operand.px === undefined && operand.number === undefined)) return unknown;
|
|
127
|
+
if (operands.length !== operators.length + 1 || operands.some(operand => !isLength(operand) && operand.number === undefined)) return unknown;
|
|
106
128
|
// Multiplication and division bind first.
|
|
107
129
|
const terms = [operands[0]], signs = [];
|
|
108
130
|
operators.forEach((operator, index) => {
|
|
109
131
|
const next = operands[index + 1];
|
|
110
132
|
if (operator !== "*" && operator !== "/") { terms.push(next); signs.push(operator); return; }
|
|
111
|
-
const last = terms.pop(), length = last
|
|
112
|
-
if (length
|
|
113
|
-
else
|
|
133
|
+
const last = terms.pop(), length = isLength(last) ? last : next, factor = isLength(last) ? next.number : last.number;
|
|
134
|
+
if (!isLength(length)) terms.push({ number: operator === "*" ? last.number * next.number : last.number / next.number });
|
|
135
|
+
else if (factor === undefined) terms.push(unknown);
|
|
136
|
+
else terms.push(scaled(length, operator === "*" ? factor : 1 / factor));
|
|
137
|
+
});
|
|
138
|
+
if (!terms.every(isLength)) return unknown;
|
|
139
|
+
let { low, high } = terms[0];
|
|
140
|
+
terms.slice(1).forEach((term, index) => {
|
|
141
|
+
if (signs[index] === "+") { low += term.low; high += term.high; } else { low -= term.high; high -= term.low; }
|
|
114
142
|
});
|
|
115
|
-
|
|
116
|
-
const px = terms.slice(1).reduce((sum, term, index) => signs[index] === "+" ? sum + term.px : sum - term.px, terms[0].px);
|
|
117
|
-
return { px, space: operands.some(operand => operand.space), math: operators.length > 0 };
|
|
143
|
+
return { low: Math.max(low, 0), high: Math.max(high, 0) };
|
|
118
144
|
}
|
|
119
|
-
/** The sizes of a grid-template-columns value
|
|
145
|
+
/** The sizes of a grid-template-columns value. minmax() can shrink to its minimum, and a track
|
|
146
|
+
* repeated with auto-fill or auto-fit wraps instead of forcing overflow. */
|
|
120
147
|
function tracks(nodes, scope) {
|
|
121
148
|
const sizes = [];
|
|
122
149
|
for (const node of meaningful(nodes)) {
|
|
123
150
|
const name = node.type === "function" ? node.value.toLowerCase() : "";
|
|
124
151
|
if (node.type === "word" && node.value.startsWith("[")) continue;
|
|
125
|
-
if (name === "repeat")
|
|
126
|
-
|
|
127
|
-
|
|
152
|
+
if (name === "repeat") {
|
|
153
|
+
const [count, ...rest] = splitArguments(node.nodes);
|
|
154
|
+
if (!/^auto-(?:fill|fit)$/i.test(meaningful(count)[0]?.value ?? "")) sizes.push(...tracks(rest.flat(), scope));
|
|
155
|
+
} else if (name === "minmax") {
|
|
156
|
+
const floor = sequence(splitArguments(node.nodes)[0] ?? [], scope);
|
|
157
|
+
sizes.push(isLength(floor) ? { ...floor, high: Infinity } : neutral);
|
|
158
|
+
} else sizes.push(measure(node, scope));
|
|
128
159
|
}
|
|
129
160
|
return sizes;
|
|
130
161
|
}
|
|
131
|
-
/**
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
162
|
+
/** What a width that can give way looks like, in the terms of the property it is set on. */
|
|
163
|
+
const fix = (property, value, px) => property === "grid-template-columns" ? `a track of minmax(0, ${px}px)` : property === "flex" || property === "flex-basis" ? `flex: 1 1 ${px}px` : `${property}: min(100%, ${value})`;
|
|
164
|
+
/** What is wrong with a resolved width: { error } | { review } | null when it is fluid or allowed. */
|
|
165
|
+
function verdict(result, property, value) {
|
|
166
|
+
if (!isLength(result) || result.declared) return null;
|
|
167
|
+
if (result.low > smallPartLimitPx) {
|
|
168
|
+
const px = Math.round(result.low);
|
|
169
|
+
return { error: result.low === result.high ? `fixed at about ${px}px` : `unable to shrink below about ${px}px`, fix: fix(property, value, px) };
|
|
170
|
+
}
|
|
171
|
+
return result.low !== result.high && result.high <= smallPartLimitPx ? { review: Math.round(result.high) } : null;
|
|
172
|
+
}
|
|
173
|
+
function judge(property, value, scope) {
|
|
139
174
|
const nodes = valueParser(value).nodes;
|
|
140
175
|
if (property === "grid-template-columns") {
|
|
141
|
-
for (const track of tracks(nodes, scope)) { const
|
|
176
|
+
for (const track of tracks(nodes, scope)) { const found = verdict(track, property, value); if (found?.error) return { ...found, error: `a track ${found.error}` }; }
|
|
142
177
|
return null;
|
|
143
178
|
}
|
|
144
179
|
if (property === "flex") {
|
|
145
180
|
const parts = meaningful(nodes);
|
|
146
181
|
if (parts.length < 2) return null;
|
|
147
182
|
const basis = parts.at(-1), shrink = parts.length === 3 ? Number(parts[1].value) : 1;
|
|
148
|
-
return Number(parts[0].value) > 0 && shrink > 0 ? null : verdict(measure(basis, scope));
|
|
183
|
+
return Number(parts[0].value) > 0 && shrink > 0 ? null : verdict(measure(basis, scope), property, value);
|
|
149
184
|
}
|
|
150
|
-
return verdict(sequence(nodes, scope));
|
|
185
|
+
return verdict(sequence(nodes, scope), property, value);
|
|
151
186
|
}
|
|
152
187
|
|
|
153
188
|
return {
|
|
154
|
-
/** layout-fixed-width findings for one parsed style sheet or Linaria template. */
|
|
189
|
+
/** layout-fixed-width and layout-width-noop findings for one parsed style sheet or Linaria template. */
|
|
155
190
|
inspect(css, file, offset = { line: 1, column: 1 }) {
|
|
156
191
|
const findings = [], locals = new Map();
|
|
157
192
|
css.walkDecls(/^--/, decl => { locals.set(decl.prop, [...(locals.get(decl.prop) ?? []), decl.value]); });
|
|
158
193
|
css.walkDecls(decl => {
|
|
159
194
|
const property = decl.prop.toLowerCase();
|
|
160
195
|
if (!widthProperties.has(property) || decl.value.includes("__ds_expression__")) return;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
196
|
+
// ch and em follow a font size set in the same rule, read through its token; an em font size is taken against 16 px.
|
|
197
|
+
const fontSize = decl.parent.nodes.findLast(sibling => sibling.type === "decl" && sibling.prop.toLowerCase() === "font-size");
|
|
198
|
+
const font = fontSize && sequence(valueParser(fontSize.value).nodes, { seen: new Set(), locals });
|
|
199
|
+
const fontPx = font?.low !== undefined && font.low === font.high && font.low > 0 ? font.low : undefined;
|
|
200
|
+
const declared = new Set(), scope = { seen: new Set(), locals, declared, fontPx }, found = judge(property, decl.value, scope);
|
|
201
|
+
for (const token of declared) declaredUses.set(token, (declaredUses.get(token) ?? 0) + 1);
|
|
202
|
+
if (!found) return;
|
|
203
|
+
// width: 280px with max-width: 100% in the same rule is min(100%, 280px).
|
|
204
|
+
if (found.error && /^(?:width|inline-size)$/.test(property) && decl.parent.nodes.some(sibling => sibling.type === "decl" && /^max-(?:width|inline-size)$/i.test(sibling.prop) && sequence(valueParser(sibling.value).nodes, scope).low === 0)) return;
|
|
205
|
+
const line = offset.line + decl.source.start.line - 1, column = decl.source.start.column + (decl.source.start.line === 1 ? offset.column - 1 : 0);
|
|
206
|
+
if (found.review !== undefined) {
|
|
207
|
+
findings.push({ rule: "layout-width-noop", severity: findingSeverity("layout-width-noop"), file, line, column, property, value: decl.value, guidanceUri: "ads://guides/tokens",
|
|
208
|
+
message: `${file}:${line} sets ${property}: ${decl.value}. It never exceeds ${found.review}px, within the ${smallPartLimitPx}px a small part may use plainly, so it does not protect against overflow, and a plain size is clearer. In a flex or grid parent the percentage can still affect wrapping, so compare the scenario after changing it.` });
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
findings.push({ rule: "layout-fixed-width", severity: findingSeverity("layout-fixed-width"), file, line, column, property, value: decl.value, guidanceUri: "ads://guides/tokens",
|
|
212
|
+
message: `${file}:${line} sets ${property}: ${decl.value}, ${found.error}, above the ${smallPartLimitPx}px a small part may use. The fix depends on what this is. A small part: size it at ${smallPartLimitPx}px or less, plainly, and leave it. A panel, column or anything else that can give way: ${found.fix}. A part that truly stays this wide: give it a token, list the token in layout.widthTokens in ds.config.json, and use the token plainly; ads check lists it for review. These do not fix it: another unit (ch, em and rem are fixed too), max() or a min() that stays under ${smallPartLimitPx}px, or a token name such as --control-*, since no name is exempt.` });
|
|
166
213
|
});
|
|
167
214
|
return findings;
|
|
168
215
|
},
|
|
169
|
-
/** Every
|
|
170
|
-
|
|
216
|
+
/** Every fixed width the project declared, for review, so that it stays visible: tokens named by
|
|
217
|
+
* layout.widthTokens with how many widths use them, and what fixedWidthUnits owners set. Call
|
|
218
|
+
* it after inspect has seen every style. */
|
|
219
|
+
declaredWidths(ownerFindings = []) {
|
|
171
220
|
const findings = [];
|
|
172
221
|
for (const token of tokens) {
|
|
173
|
-
if (!widthToken(token.name)
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
222
|
+
if (!widthToken(token.name)) continue;
|
|
223
|
+
const value = values.get(token.name)?.value;
|
|
224
|
+
const result = value === undefined ? unknown : sequence(valueParser(value).nodes, { seen: new Set([token.name]), locals: new Map() });
|
|
225
|
+
if (!isLength(result) || result.low <= smallPartLimitPx) continue;
|
|
226
|
+
const definition = token.definitions[0], uses = declaredUses.get(token.name) ?? 0;
|
|
227
|
+
findings.push({ rule: "layout-declared-width", severity: findingSeverity("layout-declared-width"), file: definition.file, line: definition.line, column: definition.column, tokens: [token.name], guidanceUri: "ads://guides/tokens",
|
|
228
|
+
message: `${token.name} is ${value}, declared in layout.widthTokens: it cannot shrink below about ${Math.round(result.low)}px. ${uses ? `${uses} width declaration${uses === 1 ? " uses" : "s use"} it. Confirm it must stay fixed.` : "No width uses it, and a maximum needs no declaration: remove it from layout.widthTokens."}` });
|
|
180
229
|
}
|
|
230
|
+
const owners = new Map();
|
|
231
|
+
for (const finding of ownerFindings) owners.set(finding.file, [...(owners.get(finding.file) ?? []), finding]);
|
|
232
|
+
for (const [file, list] of owners) findings.push({ rule: "layout-declared-width", severity: findingSeverity("layout-declared-width"), file, line: list[0].line, column: list[0].column, guidanceUri: "ads://guides/tokens",
|
|
233
|
+
message: `${file} is in layout.fixedWidthUnits, so its widths are not checked: ${list.map(finding => `${finding.property}: ${finding.value} (line ${finding.line})`).join(", ")}. Confirm it floats above the layout.` });
|
|
181
234
|
return findings;
|
|
182
235
|
},
|
|
183
236
|
};
|
|
@@ -16,7 +16,7 @@ function stamp(file) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/** One project-owned compiler process, shared by all protocol instances. */
|
|
19
|
-
export function createPreviewWatch(root, config, { log = process.stderr, buildTimeout = 30000, prewarm = false } = {}) {
|
|
19
|
+
export function createPreviewWatch(root, config, { log = process.stderr, buildTimeout = 30000, prewarm = false, despitePolicy = false } = {}) {
|
|
20
20
|
config = { ...config, apps: [...config.apps] };
|
|
21
21
|
const command = config.previewWatch;
|
|
22
22
|
let session = randomUUID();
|
|
@@ -77,7 +77,7 @@ export function createPreviewWatch(root, config, { log = process.stderr, buildTi
|
|
|
77
77
|
// No shell: configured arguments remain literal. Child stdin cannot consume
|
|
78
78
|
// the MCP channel, and both output streams go exclusively to diagnostics.
|
|
79
79
|
const executable = developmentExecutable(command.command);
|
|
80
|
-
const env = { ...process.env, ADS_MCP_BUILD_SESSION: session, ADS_MCP_BUILD_STATUS: reportFile, ADS_MCP_REQUEST_FILE: requestFile, ADS_MCP_PREWARM_VIEWS: prewarm ? "1" : "0", PATH: [path.join(root, "node_modules/.bin"), path.dirname(process.execPath), process.env.PATH ?? ""].join(path.delimiter) };
|
|
80
|
+
const env = { ...process.env, ADS_MCP_BUILD_SESSION: session, ADS_MCP_BUILD_STATUS: reportFile, ADS_MCP_REQUEST_FILE: requestFile, ADS_MCP_PREWARM_VIEWS: prewarm ? "1" : "0", ADS_PREVIEW_DESPITE_POLICY: despitePolicy ? "1" : "0", PATH: [path.join(root, "node_modules/.bin"), path.dirname(process.execPath), process.env.PATH ?? ""].join(path.delimiter) };
|
|
81
81
|
try {
|
|
82
82
|
child = spawn(executable, command.args, { cwd: root, env, shell: false, detached: process.platform !== "win32", stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
83
83
|
} catch (failure) {
|
package/dist/mcp/server.mjs
CHANGED
|
@@ -786,14 +786,14 @@ export function createAdsMcp(directory, { era = "legacy", skillDirectory, pollIn
|
|
|
786
786
|
return { server, refresh, warmScenarios, buildAll(signal, options) { previewWatch.setApps(allApps()); return previewWatch.buildAll(signal, options); }, readResource:read, async callTool(name,args,signal){const tool=tools().find(tool=>tool.name===name);if(!tool)throw new Error("Unknown preview tool.");return tool.call(tool.schema.parse(args),signal);}, async close() { executionObservers.delete(executionChanged);stopObservation(); if (!inspection) { await coordinator.close(); await cache.registryInspector?.close(); await drafts.close(); await validation.close(); await verification.close(); await captures.close(); } await server.close(); } };
|
|
787
787
|
}
|
|
788
788
|
|
|
789
|
-
export async function startAdsMcp(directory = process.cwd(), { stdio = true, showcase = true, port = 0, mutations = false, previewWork = createPreviewWork(), previewBuildTimeoutMs = 30000, prewarm = stdio } = {}) {
|
|
789
|
+
export async function startAdsMcp(directory = process.cwd(), { stdio = true, despitePolicy = false, showcase = true, port = 0, mutations = false, previewWork = createPreviewWork(), previewBuildTimeoutMs = 30000, prewarm = stdio } = {}) {
|
|
790
790
|
if (process.versions.bun) assertBunRuntime();
|
|
791
791
|
// Fail before opening the transport for configuration/distribution errors.
|
|
792
792
|
const { root, config } = loadConfig(directory);
|
|
793
793
|
// The generated theme sheet follows the token sheets and ds.config.json from startup on.
|
|
794
794
|
const themesWatch = watchThemesCss(root, { log: message => process.stderr.write(`${message}\n`) });
|
|
795
795
|
const inspection = { skills: createSkillStore(), previewWork };
|
|
796
|
-
const previewWatch = createReconfigurablePreviewWatch(root, config.mcp, {buildTimeout:previewBuildTimeoutMs,prewarm});
|
|
796
|
+
const previewWatch = createReconfigurablePreviewWatch(root, config.mcp, {buildTimeout:previewBuildTimeoutMs,prewarm,despitePolicy});
|
|
797
797
|
let host, api;
|
|
798
798
|
let buildWatcher, buildChangeTimer;
|
|
799
799
|
const buildListeners = new Set();
|
|
@@ -76,7 +76,10 @@ function resourceUris(prepared) {
|
|
|
76
76
|
node.dependencies.map(file => { const child = nodes.get(file); return [file, child.group === group ? null : fingerprint(child.group)]; }),
|
|
77
77
|
])));
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
// A file with nothing rewritten in it is named by its bytes, so a font a stylesheet and a preload
|
|
80
|
+
// both reach, through different build paths, is one resource and one download.
|
|
81
|
+
const leaf = (file, node) => !node.dependencies.length && !/\.(?:[cm]?js|css|map)$/.test(file);
|
|
82
|
+
return new Map([...nodes].map(([file, node]) => [file, `ads://assets/${hash("ads-preview-v3\n" + (leaf(file, node) ? `asset\n${node.digest}` : `${file}\n${fingerprint(node.group)}`))}.${file.split(".").pop()}`]));
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
/** Convert compiler output to registered MCP resources without evaluating project code. */
|
|
@@ -282,9 +282,9 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
282
282
|
function gate(stamp) {
|
|
283
283
|
if (isDraftPreviewWorkspace(root)) return Promise.resolve();
|
|
284
284
|
if (cache.validated(stamp)) return Promise.resolve();
|
|
285
|
-
return validation ??= Promise.resolve().then(validate).then(
|
|
285
|
+
return validation ??= Promise.resolve().then(validate).then(valid => {
|
|
286
286
|
if (stamp !== cache.inputs()) throw new Error("Sources changed during preview validation. Waiting for the current build.");
|
|
287
|
-
cache.validate(stamp);
|
|
287
|
+
if (valid !== false) cache.validate(stamp);
|
|
288
288
|
}).catch(error=>{throw scopedPreviewFailure(error,"project","validation");});
|
|
289
289
|
}
|
|
290
290
|
async function checkedBuild(stamp, build) {
|
|
@@ -41,7 +41,8 @@ request already identifies the target.
|
|
|
41
41
|
|
|
42
42
|
Run `ads audit` on the stressed scenario. `layout-overflow` fails it when the page overflows
|
|
43
43
|
horizontally, an element reaches past the viewport or content is clipped at 390, 768 or 1280
|
|
44
|
-
px. `overflow-x: auto` scrollers and
|
|
44
|
+
px, or a set width above 96 px overflows a 240 px container. `overflow-x: auto` scrollers and
|
|
45
|
+
`text-overflow: ellipsis` are exempt. Fix a failure with
|
|
45
46
|
fluid widths (`%`, `fr`, a `--grid-span-N` token in a container query), `min-width: 0` on flex
|
|
46
47
|
and grid children, and wrapping, not with `overflow: hidden`.
|
|
47
48
|
|
|
@@ -134,7 +134,7 @@ container width (768 and 1024 px) with container queries, since CSS variables ca
|
|
|
134
134
|
breakpoints. The showcase's grid overlay draws these tokens over every preview at the same
|
|
135
135
|
widths; a project without them shows no overlay. Align text to a cell's edge, not its gutter.
|
|
136
136
|
|
|
137
|
-
### Widths are fluid on the grid
|
|
137
|
+
### Widths are fluid on the grid
|
|
138
138
|
|
|
139
139
|
`--grid-span-1` to `--grid-span-16` are widths of N of 16 columns, fluid in their container.
|
|
140
140
|
Set one inside a container query, under a `Grid` or another `container-type: inline-size`
|
|
@@ -155,23 +155,43 @@ Atomic CSS does not keep rule order, so two queries on one property need exclusi
|
|
|
155
155
|
Use `%` or `fr` for a share of the parent and a `ch` measure for running text
|
|
156
156
|
(`max-inline-size: 65ch`).
|
|
157
157
|
|
|
158
|
-
`layout-fixed-width` is an error for `width`, `min-width`,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
`layout-fixed-width` is an error for `width`, `min-width`, the logical inline sizes, `flex-basis`,
|
|
159
|
+
`flex`'s basis and `grid-template-columns` tracks that cannot shrink below 96 px, in any unit, raw,
|
|
160
|
+
through a token or by arithmetic. `max-width` and `max-inline-size` are not read: a maximum cannot
|
|
161
|
+
force overflow, so cap with them freely.
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
A
|
|
169
|
-
|
|
170
|
-
|
|
163
|
+
When it fires, pick the fix by what the element is:
|
|
164
|
+
|
|
165
|
+
| The element | Do |
|
|
166
|
+
|---|---|
|
|
167
|
+
| A small part: an icon, control, handle or thumbnail | Size it at 96 px or less, plainly: `width: 64px`, `width: var(--control-height-lg)` |
|
|
168
|
+
| A panel, column or anything that can give way | `width: min(100%, 280px)`, `flex: 1 1 280px` or a `minmax(0, 280px)` track |
|
|
169
|
+
| A part that truly stays that wide | A token listed in `layout.widthTokens` in `ds.config.json`, used plainly: `width: var(--side-pane-width)` |
|
|
170
|
+
| A resizable part | A `clamp()` of three such tokens; a runtime variable needs a declared fallback: `clamp(var(--pane-min), var(--ux-pane, var(--pane)), var(--pane-max))` |
|
|
171
|
+
| An overlay: dialog, menu, popover, tooltip | Its owner in `layout.fixedWidthUnits`, by unit id or file glob |
|
|
172
|
+
|
|
173
|
+
These do not fix it:
|
|
174
|
+
|
|
175
|
+
- Another unit. `32.5ch`, `20em` and `20rem` are as fixed as `280px`, and depend on the font too.
|
|
176
|
+
`ch` and `em` are measured at the rule's `font-size`, or 16 px.
|
|
177
|
+
- `max(100%, 280px)`, `clamp(200px, 50%, 400px)`, `calc(100% + 200px)`: they cannot shrink below
|
|
178
|
+
their fixed part.
|
|
179
|
+
- `min(100%, 64px)` around a small part. `layout-width-noop` asks for the plain size; in a flex or
|
|
180
|
+
grid parent the percentage can affect wrapping, so compare the scenario after changing it.
|
|
181
|
+
- A token name. `--control-*`, `--side-pane-*` and every other name are read for their value.
|
|
182
|
+
|
|
183
|
+
`ads check` lists every declared fixed width for review (`layout-declared-width`). There is no
|
|
184
|
+
per-declaration exception.
|
|
185
|
+
|
|
186
|
+
`ads audit` opens each control with `aria-haspopup` and measures what opens, hovers and focuses
|
|
187
|
+
controls for contrast, and checks a control with `aria-busy="true"`. So give overlay triggers
|
|
188
|
+
`aria-haspopup`, or render the overlay open in its scenario, and render a busy example.
|
|
171
189
|
|
|
172
190
|
`layout-overflow` (`ads audit`) renders every UI scenario at 390, 768 and 1280 px and fails on
|
|
173
191
|
horizontal page overflow, elements past the viewport and clipped content. `overflow-x: auto`
|
|
174
|
-
scrollers and `text-overflow: ellipsis` are exempt.
|
|
192
|
+
scrollers and `text-overflow: ellipsis` are exempt. It also renders components and patterns in a
|
|
193
|
+
240 px container, and fails when a set width above 96 px overflows it. Make that width fluid, or
|
|
194
|
+
scroll it. Only an overlay's owner, listed in `layout.fixedWidthUnits`, stays out of this render.
|
|
175
195
|
|
|
176
196
|
## Color roles and states
|
|
177
197
|
|
|
@@ -43,7 +43,7 @@ implicitly requiring them at acceptance.
|
|
|
43
43
|
owners while project scripts and core gates retain full scope.
|
|
44
44
|
- Both policies run the axe-core audit of every rendered UI scenario in every brand
|
|
45
45
|
and theme (`browser-accessibility-audit`); `browserAudit: false` turns it off for
|
|
46
|
-
that policy. Its `a11y-axe`, `a11y-non-text-contrast` and `layout-overflow` findings are errors that fail the policy, and an audit
|
|
46
|
+
that policy. An `a11y-incomplete` info item means axe could not decide that rule on those elements: check it by hand, using the reason it names (`bgGradient` is text over a gradient). Its `a11y-axe`, `a11y-non-text-contrast` and `layout-overflow` findings are errors that fail the policy, and an audit
|
|
47
47
|
that cannot run (no project Playwright or browser) fails it with a `browser-audit`
|
|
48
48
|
error naming what to install. Under the acceptance policy, draft
|
|
49
49
|
acceptance and guarded patches/transactions audit the candidate's affected UI
|
|
@@ -327,12 +327,14 @@ brand artwork, icon outputs or glyphs.
|
|
|
327
327
|
|
|
328
328
|
## Layout widths
|
|
329
329
|
|
|
330
|
-
Widths are fluid on the grid
|
|
331
|
-
|
|
332
|
-
|
|
330
|
+
Widths are fluid on the grid. Span columns with a `--grid-span-N` token in a container query, or
|
|
331
|
+
use `%` or `fr`. `layout-fixed-width` fails a width that cannot shrink below 96 px, in any unit.
|
|
332
|
+
Small parts use plain sizes up to 96 px. A panel takes `width: min(100%, 280px)`. A part that truly
|
|
333
|
+
stays wider takes a token listed in `layout.widthTokens`, and an overlay's owner goes in
|
|
334
|
+
`layout.fixedWidthUnits`. `max-width` is not read. Atomic CSS
|
|
333
335
|
does not keep rule order: give queries on one property exclusive ranges, such as
|
|
334
336
|
`(min-width: 768px) and (max-width: 1023.98px)`. `ads audit` fails horizontal overflow at 390,
|
|
335
|
-
768 and 1280 px (`layout-overflow`). See the Grid section of
|
|
337
|
+
768 and 1280 px, and reports a set width above 96 px that overflows a 240 px container as a review item (`layout-overflow-narrow`). See the Grid section of
|
|
336
338
|
[design-data.md](references/design-data.md) (`ads://guides/tokens`).
|
|
337
339
|
|
|
338
340
|
## Web performance
|
|
@@ -134,7 +134,7 @@ container width (768 and 1024 px) with container queries, since CSS variables ca
|
|
|
134
134
|
breakpoints. The showcase's grid overlay draws these tokens over every preview at the same
|
|
135
135
|
widths; a project without them shows no overlay. Align text to a cell's edge, not its gutter.
|
|
136
136
|
|
|
137
|
-
### Widths are fluid on the grid
|
|
137
|
+
### Widths are fluid on the grid
|
|
138
138
|
|
|
139
139
|
`--grid-span-1` to `--grid-span-16` are widths of N of 16 columns, fluid in their container.
|
|
140
140
|
Set one inside a container query, under a `Grid` or another `container-type: inline-size`
|
|
@@ -155,23 +155,43 @@ Atomic CSS does not keep rule order, so two queries on one property need exclusi
|
|
|
155
155
|
Use `%` or `fr` for a share of the parent and a `ch` measure for running text
|
|
156
156
|
(`max-inline-size: 65ch`).
|
|
157
157
|
|
|
158
|
-
`layout-fixed-width` is an error for `width`, `min-width`,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
`layout-fixed-width` is an error for `width`, `min-width`, the logical inline sizes, `flex-basis`,
|
|
159
|
+
`flex`'s basis and `grid-template-columns` tracks that cannot shrink below 96 px, in any unit, raw,
|
|
160
|
+
through a token or by arithmetic. `max-width` and `max-inline-size` are not read: a maximum cannot
|
|
161
|
+
force overflow, so cap with them freely.
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
A
|
|
169
|
-
|
|
170
|
-
|
|
163
|
+
When it fires, pick the fix by what the element is:
|
|
164
|
+
|
|
165
|
+
| The element | Do |
|
|
166
|
+
|---|---|
|
|
167
|
+
| A small part: an icon, control, handle or thumbnail | Size it at 96 px or less, plainly: `width: 64px`, `width: var(--control-height-lg)` |
|
|
168
|
+
| A panel, column or anything that can give way | `width: min(100%, 280px)`, `flex: 1 1 280px` or a `minmax(0, 280px)` track |
|
|
169
|
+
| A part that truly stays that wide | A token listed in `layout.widthTokens` in `ds.config.json`, used plainly: `width: var(--side-pane-width)` |
|
|
170
|
+
| A resizable part | A `clamp()` of three such tokens; a runtime variable needs a declared fallback: `clamp(var(--pane-min), var(--ux-pane, var(--pane)), var(--pane-max))` |
|
|
171
|
+
| An overlay: dialog, menu, popover, tooltip | Its owner in `layout.fixedWidthUnits`, by unit id or file glob |
|
|
172
|
+
|
|
173
|
+
These do not fix it:
|
|
174
|
+
|
|
175
|
+
- Another unit. `32.5ch`, `20em` and `20rem` are as fixed as `280px`, and depend on the font too.
|
|
176
|
+
`ch` and `em` are measured at the rule's `font-size`, or 16 px.
|
|
177
|
+
- `max(100%, 280px)`, `clamp(200px, 50%, 400px)`, `calc(100% + 200px)`: they cannot shrink below
|
|
178
|
+
their fixed part.
|
|
179
|
+
- `min(100%, 64px)` around a small part. `layout-width-noop` asks for the plain size; in a flex or
|
|
180
|
+
grid parent the percentage can affect wrapping, so compare the scenario after changing it.
|
|
181
|
+
- A token name. `--control-*`, `--side-pane-*` and every other name are read for their value.
|
|
182
|
+
|
|
183
|
+
`ads check` lists every declared fixed width for review (`layout-declared-width`). There is no
|
|
184
|
+
per-declaration exception.
|
|
185
|
+
|
|
186
|
+
`ads audit` opens each control with `aria-haspopup` and measures what opens, hovers and focuses
|
|
187
|
+
controls for contrast, and checks a control with `aria-busy="true"`. So give overlay triggers
|
|
188
|
+
`aria-haspopup`, or render the overlay open in its scenario, and render a busy example.
|
|
171
189
|
|
|
172
190
|
`layout-overflow` (`ads audit`) renders every UI scenario at 390, 768 and 1280 px and fails on
|
|
173
191
|
horizontal page overflow, elements past the viewport and clipped content. `overflow-x: auto`
|
|
174
|
-
scrollers and `text-overflow: ellipsis` are exempt.
|
|
192
|
+
scrollers and `text-overflow: ellipsis` are exempt. It also renders components and patterns in a
|
|
193
|
+
240 px container, and fails when a set width above 96 px overflows it. Make that width fluid, or
|
|
194
|
+
scroll it. Only an overlay's owner, listed in `layout.fixedWidthUnits`, stays out of this render.
|
|
175
195
|
|
|
176
196
|
## Color roles and states
|
|
177
197
|
|
|
@@ -43,7 +43,7 @@ implicitly requiring them at acceptance.
|
|
|
43
43
|
owners while project scripts and core gates retain full scope.
|
|
44
44
|
- Both policies run the axe-core audit of every rendered UI scenario in every brand
|
|
45
45
|
and theme (`browser-accessibility-audit`); `browserAudit: false` turns it off for
|
|
46
|
-
that policy. Its `a11y-axe`, `a11y-non-text-contrast` and `layout-overflow` findings are errors that fail the policy, and an audit
|
|
46
|
+
that policy. An `a11y-incomplete` info item means axe could not decide that rule on those elements: check it by hand, using the reason it names (`bgGradient` is text over a gradient). Its `a11y-axe`, `a11y-non-text-contrast` and `layout-overflow` findings are errors that fail the policy, and an audit
|
|
47
47
|
that cannot run (no project Playwright or browser) fails it with a `browser-audit`
|
|
48
48
|
error naming what to install. Under the acceptance policy, draft
|
|
49
49
|
acceptance and guarded patches/transactions audit the candidate's affected UI
|