@srobroek/pi-design 0.0.0 → 0.11.1
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/CHANGELOG.md +174 -0
- package/LICENSE +202 -0
- package/README.md +438 -2
- package/_kit/prereqs.json +41 -0
- package/_kit/prereqs.ts +374 -0
- package/agents/a11y-auditor.md +107 -0
- package/agents/council-user.md +25 -0
- package/agents/council-ux.md +25 -0
- package/agents/design-critic.md +80 -0
- package/agents/ui-implementer.md +75 -0
- package/agents/ui-ux-specialist.md +133 -0
- package/commands/council-product.md +26 -0
- package/commands/design-review.md +17 -0
- package/extensions/design.js +438 -0
- package/formulas/design-surface.formula.toml +344 -0
- package/formulas/design-system.formula.toml +509 -0
- package/formulas/design-touch.formula.toml +188 -0
- package/formulas/mol-design-a11y.formula.toml +128 -0
- package/formulas/mol-design-component.formula.toml +122 -0
- package/formulas/mol-design-iterate.formula.toml +187 -0
- package/formulas/mol-design-motion.formula.toml +138 -0
- package/formulas/mol-design-responsive.formula.toml +135 -0
- package/formulas/mol-design-tokens.formula.toml +165 -0
- package/mcp-servers.ts +49 -0
- package/package.json +61 -4
- package/skills/accessibility-audit/SKILL.md +92 -0
- package/skills/accessibility-audit/references/upstream.md +78 -0
- package/skills/design-component-truth/SKILL.md +41 -0
- package/skills/design-evidence/SKILL.md +21 -0
- package/skills/design-guide/SKILL.md +26 -0
- package/skills/design-md/LICENSE +21 -0
- package/skills/design-md/NOTICE +31 -0
- package/skills/design-md/SKILL.md +79 -0
- package/skills/design-md/references/create-design-md.md +254 -0
- package/skills/design-md/references/upstream.md +60 -0
- package/skills/design-no-slop/SKILL.md +32 -0
- package/skills/design-prototype/SKILL.md +84 -0
- package/skills/design-prototype/references/in-app-variants.md +47 -0
- package/skills/design-prototype/references/upstream.md +43 -0
- package/skills/design-system-audit/SKILL.md +62 -0
- package/skills/design-system-audit/references/token-carriers.md +106 -0
- package/skills/design-system-audit/references/token-pipeline.md +115 -0
- package/skills/design-system-audit/references/upstream.md +52 -0
- package/skills/design-token-discipline/SKILL.md +24 -0
- package/skills/design-upstream-preflight/SKILL.md +60 -0
- package/skills/motion-design/SKILL.md +60 -0
- package/skills/ui-microcopy/LICENSE +212 -0
- package/skills/ui-microcopy/NOTICE +28 -0
- package/skills/ui-microcopy/SKILL.md +50 -0
- package/skills/ui-microcopy/references/copy-guidance.md +86 -0
- package/skills/ui-microcopy/references/upstream.md +11 -0
- package/skills/ui-review/SKILL.md +92 -0
- package/skills/ui-review/references/probes.md +446 -0
- package/skills/ui-review/references/storybook.md +217 -0
- package/skills/ui-review/references/tools.md +269 -0
- package/skills/ui-review/references/viewport-checks.md +184 -0
- package/skills/wireloom/LICENSE +21 -0
- package/skills/wireloom/NOTICE +30 -0
- package/skills/wireloom/SKILL.md +95 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
# Computed-Style Probes
|
|
2
|
+
|
|
3
|
+
Page-side snippets for the VERIFY step: pass each to the browser's evaluate step (the
|
|
4
|
+
browser routes table in `tools.md`). Every one returns a number or a
|
|
5
|
+
resolved color string, so a finding can be written as `measured vs expected`
|
|
6
|
+
instead of "looks off".
|
|
7
|
+
|
|
8
|
+
## Scope every probe, then decide what is even a target
|
|
9
|
+
|
|
10
|
+
Three tests, in this order, before any probe below reports a number. They do different
|
|
11
|
+
work and must never be collapsed into one.
|
|
12
|
+
|
|
13
|
+
### 1. Resolve the root once
|
|
14
|
+
|
|
15
|
+
A Storybook story frame holds TWO DOMs: the story, and Storybook's hidden
|
|
16
|
+
fallback chrome. Bare `document.querySelectorAll` reads both and invents findings
|
|
17
|
+
that are not on the surface. Resolve the root ONCE, then query through it.
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
const root = document.querySelector('#storybook-root') ?? document.body;
|
|
21
|
+
const all = (sel) => [...root.querySelectorAll(sel)];
|
|
22
|
+
const one = (sel) => root.querySelector(sel);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
In a story frame the story root is `#storybook-root`. On a plain page no such
|
|
26
|
+
element exists, the fallback is `document.body`, and the root is the whole page.
|
|
27
|
+
Every probe below queries through `all` or `one`, never `document`.
|
|
28
|
+
|
|
29
|
+
Measured on one real story at 1440:
|
|
30
|
+
|
|
31
|
+
| Probe | Unscoped | Scoped to `#storybook-root` |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| `button, input, select, a[href]` | 28 | 21 |
|
|
34
|
+
| controls under 24x24 | 7 | 0 |
|
|
35
|
+
| `table` | 2 | 1 |
|
|
36
|
+
|
|
37
|
+
All seven of those sub-24px findings measured 0x0, and scoping removed them
|
|
38
|
+
because they came from the chrome ("Set string" x3, "Decorators documen",
|
|
39
|
+
"Webpack", "Vite", "Environment Variab"). Scoping closes that instance; test 2
|
|
40
|
+
is what makes the probe correct in general.
|
|
41
|
+
|
|
42
|
+
The interaction consequence fails differently from the measurement one, so it
|
|
43
|
+
needs its own check. An unscoped selector can resolve a 0x0 chrome element FIRST:
|
|
44
|
+
`document.querySelector('table tbody tr button')` returned the chrome's
|
|
45
|
+
placeholder prop table, and a click on that selector timed out after 8000ms
|
|
46
|
+
while reporting a plausible "matches 15 element(s)". A timeout whose match count
|
|
47
|
+
looks right is this trap, not a broken control. Prefix any selector handed to
|
|
48
|
+
a click, fill, or wait-for-selector step with `#storybook-root `, or
|
|
49
|
+
resolve the handle from `root` and call the method on the handle.
|
|
50
|
+
|
|
51
|
+
Recognise the chrome in any result by its class markers: `sb-preparing-story`,
|
|
52
|
+
`sb-preparing-docs`, `sb-nopreview`, `sb-errordisplay`.
|
|
53
|
+
|
|
54
|
+
`document.documentElement`, `document.activeElement`, and
|
|
55
|
+
`document.elementFromPoint` stay document-level on purpose: custom properties
|
|
56
|
+
resolve at `:root`, focus is a document property, and hit testing is
|
|
57
|
+
document-wide. A hit that lands outside `root` is itself the finding.
|
|
58
|
+
|
|
59
|
+
### 2. Drop what generates no boxes. Never judge on area alone
|
|
60
|
+
|
|
61
|
+
A node that generates no boxes is not a target, but a node with a zero-size border box
|
|
62
|
+
may still be hit-testable through a pseudo-element, so area alone never decides. Two
|
|
63
|
+
tests, and only the first one discards.
|
|
64
|
+
|
|
65
|
+
**Not rendered: discard outright.** `getClientRects().length === 0`, or a failed
|
|
66
|
+
`checkVisibility`. A `display: none` panel, a `content-visibility` subtree, a closed
|
|
67
|
+
dropdown's items, a toast queue that keeps its nodes. These generate no boxes at all and
|
|
68
|
+
are targets under no reading. They sit INSIDE the app root, so scoping cannot reach them,
|
|
69
|
+
which is why this test and not scoping is what generalises. It is also the test that
|
|
70
|
+
removed the seven chrome findings, because those nodes were not rendered either.
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
const rendered = (el) =>
|
|
74
|
+
el.checkVisibility?.({ checkVisibilityCSS: true }) !== false
|
|
75
|
+
&& el.getClientRects().length > 0;
|
|
76
|
+
const hits = (sel) => all(sel).filter(rendered);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`getClientRects().length > 0` is the portable form and decides the case on its own.
|
|
80
|
+
`checkVisibility` covers the same ground more directly and the `browser` tool drives
|
|
81
|
+
Chromium, so it is available; `?.` with `!== false` keeps the rect test as the decider
|
|
82
|
+
instead of skipping it when the method is absent.
|
|
83
|
+
|
|
84
|
+
NOT `checkOpacity: true`. An `opacity: 0` element still generates boxes, still receives
|
|
85
|
+
pointer events, and is still reachable by keyboard, so it is a real target. Discarding it
|
|
86
|
+
would hide the finding rather than measure it. An interactive element whose computed
|
|
87
|
+
`opacity` is 0 while it remains focusable is its own defect: report it as an invisible
|
|
88
|
+
focusable control, separately from target size.
|
|
89
|
+
|
|
90
|
+
NOT `contentVisibilityAuto: true` either, for a different reason. It returns false for an
|
|
91
|
+
off-screen `content-visibility: auto` subtree whose rendering is merely SKIPPED, not
|
|
92
|
+
suppressed. Those controls render as soon as they scroll into view, so filtering them here
|
|
93
|
+
means they never reach a target-size or style check at all. Scroll a candidate into view,
|
|
94
|
+
then measure it.
|
|
95
|
+
|
|
96
|
+
`visibility: hidden` is the case that stays filtered: it removes hit-testing outright, which
|
|
97
|
+
is why `checkVisibilityCSS` remains on.
|
|
98
|
+
|
|
99
|
+
**Rendered but zero area: ambiguous, never discarded on area.** The element has a rect
|
|
100
|
+
and it measures 0x0. Its border box is not its target: the hit area can come from a
|
|
101
|
+
pseudo-element or a positioned overlay, which is exactly what the target-size probe below
|
|
102
|
+
measures. An icon button with `::after { position: absolute; inset: -12px }` has a real
|
|
103
|
+
24x24 target and a 0x0 box. Discarding it on area turns a genuine pass into a silent false
|
|
104
|
+
NEGATIVE, which is worse than the false positive scoping fixes. Resolve it by hit-testing,
|
|
105
|
+
not by measuring: take points across the intended hit area and check that
|
|
106
|
+
`document.elementFromPoint(x, y)` resolves to the control or one of its descendants. Only
|
|
107
|
+
when nothing in that area resolves to it is it a finding.
|
|
108
|
+
|
|
109
|
+
### 3. Judge geometry on the effective hit area
|
|
110
|
+
|
|
111
|
+
So the order is: scope to the root, drop the not-rendered, then apply the 24x24 rule to
|
|
112
|
+
the EFFECTIVE hit area rather than the border box, using the pseudo-element probe below.
|
|
113
|
+
Every probe that measures geometry or counts interactive controls queries through `hits`,
|
|
114
|
+
never `all`: target size, the style sweep, the overflow scan, and the overlap check. Do
|
|
115
|
+
not delete these filters as noise.
|
|
116
|
+
|
|
117
|
+
## Color parsing: use the canvas, not a regex
|
|
118
|
+
|
|
119
|
+
Chromium returns `rgb()`, `rgba()`, `color(srgb ...)`, `oklch()`, or
|
|
120
|
+
`color-mix()` from `getComputedStyle` depending on how the author wrote the
|
|
121
|
+
value. A regex over `rgb(...)` silently misses the modern syntaxes. Round-trip
|
|
122
|
+
through a 1x1 canvas instead, which parses everything Chromium can parse.
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
const toRGB = (css) => {
|
|
126
|
+
const c = Object.assign(document.createElement('canvas'), { width: 1, height: 1 });
|
|
127
|
+
const ctx = c.getContext('2d', { willReadFrequently: true });
|
|
128
|
+
ctx.clearRect(0, 0, 1, 1);
|
|
129
|
+
ctx.fillStyle = '#000';
|
|
130
|
+
ctx.fillStyle = css; // an unparseable value leaves #000 behind
|
|
131
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
132
|
+
const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data;
|
|
133
|
+
return { r, g, b, a: a / 255 };
|
|
134
|
+
};
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Effective background behind an element
|
|
138
|
+
|
|
139
|
+
`background-color` is usually `rgba(0,0,0,0)`, so the visible backdrop lives on
|
|
140
|
+
an ancestor. Walk up, compositing any translucent layer onto the next.
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
const over = (top, under) => ({
|
|
144
|
+
r: top.r * top.a + under.r * (1 - top.a),
|
|
145
|
+
g: top.g * top.a + under.g * (1 - top.a),
|
|
146
|
+
b: top.b * top.a + under.b * (1 - top.a),
|
|
147
|
+
a: 1,
|
|
148
|
+
});
|
|
149
|
+
const backdrop = (el) => {
|
|
150
|
+
const stack = [];
|
|
151
|
+
for (let n = el; n; n = n.parentElement) {
|
|
152
|
+
const s = getComputedStyle(n);
|
|
153
|
+
if (s.backgroundImage !== 'none') return { undecidable: s.backgroundImage };
|
|
154
|
+
const c = toRGB(s.backgroundColor);
|
|
155
|
+
if (c.a > 0) { stack.push(c); if (c.a === 1) break; }
|
|
156
|
+
}
|
|
157
|
+
stack.push({ r: 255, g: 255, b: 255, a: 1 }); // canvas default
|
|
158
|
+
return stack.reduceRight((under, top) => over(top, under));
|
|
159
|
+
};
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
An `undecidable` result means a gradient or image sits behind the text. Report it
|
|
163
|
+
as NEEDS_HUMAN with an element screenshot path; never guess a ratio.
|
|
164
|
+
|
|
165
|
+
## Contrast ratio
|
|
166
|
+
|
|
167
|
+
```js
|
|
168
|
+
const lum = ({ r, g, b }) => {
|
|
169
|
+
const f = (v) => { v /= 255; return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4; };
|
|
170
|
+
return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b);
|
|
171
|
+
};
|
|
172
|
+
const ratio = (fg, bg) => {
|
|
173
|
+
const [a, b] = [lum(fg), lum(bg)].sort((x, y) => y - x);
|
|
174
|
+
return Math.round(((a + 0.05) / (b + 0.05)) * 100) / 100;
|
|
175
|
+
};
|
|
176
|
+
const contrast = (el) => {
|
|
177
|
+
const bg = backdrop(el);
|
|
178
|
+
if (bg.undecidable) return bg;
|
|
179
|
+
return ratio(over(toRGB(getComputedStyle(el).color), bg), bg);
|
|
180
|
+
};
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Composite the foreground before measuring it. `color` can carry its own alpha, and the
|
|
184
|
+
luminance formula assumes opaque colours, so passing the raw value scores the text as if
|
|
185
|
+
it were painted solid. Measured in Chromium: `rgba(0,0,0,0.1)` text on white read 21:1
|
|
186
|
+
uncomposited and 1.26:1 composited.
|
|
187
|
+
|
|
188
|
+
The arithmetic models only colour alpha. An ancestor with `opacity` below 1, a
|
|
189
|
+
`mix-blend-mode` other than `normal`, or a `filter` changes the painted colours in ways it
|
|
190
|
+
does not model: report those as NEEDS_HUMAN with a screenshot path, never as a measured
|
|
191
|
+
ratio.
|
|
192
|
+
|
|
193
|
+
Report both colors and the ratio. Thresholds: 4.5:1 for body text, 3:1 for large
|
|
194
|
+
text and for the boundary of a UI component.
|
|
195
|
+
|
|
196
|
+
## Type, spacing, radius, and elevation in one pass
|
|
197
|
+
|
|
198
|
+
```js
|
|
199
|
+
const read = (sel, props) => hits(sel).map((el) => {
|
|
200
|
+
const s = getComputedStyle(el);
|
|
201
|
+
return { sel, text: el.textContent.trim().slice(0, 40),
|
|
202
|
+
...Object.fromEntries(props.map((p) => [p, s.getPropertyValue(p)])) };
|
|
203
|
+
});
|
|
204
|
+
read('button, [role="button"]', [
|
|
205
|
+
'font-family', 'font-size', 'font-weight', 'line-height', 'letter-spacing',
|
|
206
|
+
'padding', 'gap', 'border-radius', 'border-width', 'box-shadow',
|
|
207
|
+
]);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Compare each value against the DESIGN.md token registry. A value that matches no
|
|
211
|
+
token is either a new token to record or drift to fix.
|
|
212
|
+
|
|
213
|
+
## Resolved custom properties
|
|
214
|
+
|
|
215
|
+
Source hex in a stylesheet is not what shipped. Read the resolved variable off
|
|
216
|
+
the element that consumes it.
|
|
217
|
+
|
|
218
|
+
```js
|
|
219
|
+
const tokens = (el, names) => Object.fromEntries(
|
|
220
|
+
names.map((n) => [n, getComputedStyle(el).getPropertyValue(n).trim()]));
|
|
221
|
+
tokens(document.documentElement, ['--color-fg', '--color-bg', '--space-2', '--radius-md']);
|
|
222
|
+
tokens(root, ['--color-fg', '--color-bg']); // a story decorator can override :root
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Focus ring
|
|
226
|
+
|
|
227
|
+
Focus first, then measure. A ring drawn with `box-shadow` reports
|
|
228
|
+
`outline-style: none`, so read both.
|
|
229
|
+
|
|
230
|
+
```js
|
|
231
|
+
// press Tab, or call el.focus(), first
|
|
232
|
+
const el = document.activeElement;
|
|
233
|
+
const s = getComputedStyle(el);
|
|
234
|
+
({ tag: el.tagName, name: el.ariaLabel ?? el.textContent.trim().slice(0, 40),
|
|
235
|
+
outline: `${s.outlineStyle} ${s.outlineWidth} ${s.outlineColor}`,
|
|
236
|
+
offset: s.outlineOffset, shadow: s.boxShadow, ring: s.getPropertyValue('--ring') });
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Settle the transition, or the second read lies
|
|
240
|
+
|
|
241
|
+
A read taken at t=0 returns the IDLE value, not the focused one. Measured on a
|
|
242
|
+
button with a transitioned ring: the read issued immediately after
|
|
243
|
+
a `Tab` key press returned the unfocused `box-shadow`, and the focused value
|
|
244
|
+
appeared only about 300ms later. Diffing that t=0 read against the unfocused read
|
|
245
|
+
finds them identical and reports "no focus indicator" on a component that has one.
|
|
246
|
+
A t=0 read is therefore a false negative, not evidence. The same applies to hover,
|
|
247
|
+
active, and selected, which are transitioned just as often.
|
|
248
|
+
|
|
249
|
+
Settle before the second read. Either await the transition on the property you are
|
|
250
|
+
about to measure:
|
|
251
|
+
|
|
252
|
+
```js
|
|
253
|
+
const settled = (el, prop, cap = 1000) => new Promise((res) => {
|
|
254
|
+
const done = (e) => {
|
|
255
|
+
if (e.propertyName !== prop) return;
|
|
256
|
+
el.removeEventListener('transitionend', done); res('transitionend');
|
|
257
|
+
};
|
|
258
|
+
el.addEventListener('transitionend', done);
|
|
259
|
+
setTimeout(() => { el.removeEventListener('transitionend', done); res('cap'); }, cap);
|
|
260
|
+
});
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Or poll the computed value until it stops changing, which needs no knowledge of
|
|
264
|
+
which property is transitioned and still returns when no `transitionend` ever
|
|
265
|
+
fires:
|
|
266
|
+
|
|
267
|
+
```js
|
|
268
|
+
const stable = (el, prop, ms = 50, runs = 3, timeout = 2000) =>
|
|
269
|
+
new Promise((res) => {
|
|
270
|
+
const deadline = Date.now() + timeout;
|
|
271
|
+
let prev = null, same = 0;
|
|
272
|
+
const tick = () => {
|
|
273
|
+
const v = getComputedStyle(el).getPropertyValue(prop);
|
|
274
|
+
same = v === prev ? same + 1 : 0;
|
|
275
|
+
prev = v;
|
|
276
|
+
if (same >= runs) return res({ value: v, settled: true });
|
|
277
|
+
if (Date.now() > deadline) return res({ value: v, settled: false });
|
|
278
|
+
setTimeout(tick, ms);
|
|
279
|
+
};
|
|
280
|
+
tick();
|
|
281
|
+
});
|
|
282
|
+
// const { value, settled } = await stable(document.activeElement, 'box-shadow')
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
The deadline is load-bearing: without it a continuously animated property never reaches
|
|
286
|
+
`same >= runs` and the pass hangs. A `settled: false` result is itself reportable, because a
|
|
287
|
+
property still moving after two seconds is an animation that never rests rather than a
|
|
288
|
+
transition to wait on. Read `transitionDuration` and `transitionProperty` beside the ring
|
|
289
|
+
values, so the report states the settle time it waited for instead of an unexplained sleep.
|
|
290
|
+
|
|
291
|
+
A focus indicator exists only when `outlineStyle !== 'none'` with a non-zero
|
|
292
|
+
width, or `boxShadow` differs between the unfocused read and the SETTLED focused
|
|
293
|
+
read. Two identical reads are a finding only when the second one settled.
|
|
294
|
+
|
|
295
|
+
## Overflow, clipping, and overlap
|
|
296
|
+
|
|
297
|
+
```js
|
|
298
|
+
const overflow = () => ({
|
|
299
|
+
docScrollX: document.documentElement.scrollWidth - document.documentElement.clientWidth,
|
|
300
|
+
scrollers: hits('*')
|
|
301
|
+
.filter((el) => el.scrollWidth > el.clientWidth + 1)
|
|
302
|
+
.map((el) => ({ tag: el.tagName, cls: el.className, over: el.scrollWidth - el.clientWidth })),
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
const overlaps = (containerSel) => {
|
|
306
|
+
const box = (el) => el.getBoundingClientRect();
|
|
307
|
+
const kids = [...one(containerSel).children]
|
|
308
|
+
.filter((el) => rendered(el) && box(el).width > 0 && box(el).height > 0)
|
|
309
|
+
.map((el) => [el, box(el)]);
|
|
310
|
+
const pairs = [];
|
|
311
|
+
for (let i = 0; i < kids.length; i++) for (let j = i + 1; j < kids.length; j++) {
|
|
312
|
+
const [a, b] = [kids[i][1], kids[j][1]];
|
|
313
|
+
if (a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom) {
|
|
314
|
+
pairs.push({ a: kids[i][0].tagName, b: kids[j][0].tagName });
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return pairs;
|
|
318
|
+
};
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
`docScrollX` greater than 0 at 375 CSS px is a horizontal-scroll finding, and it is
|
|
322
|
+
the deciding number for whole-page overflow; the ladder under it is in
|
|
323
|
+
`viewport-checks.md`. Both scans go through `hits`, so a
|
|
324
|
+
node that generates no boxes cannot reach either. The overlap check adds its own area
|
|
325
|
+
guard on top, because a zero-area child reports an intersection with every sibling whose
|
|
326
|
+
box spans its position while overlapping nothing anyone can see. Measured in Chromium on a
|
|
327
|
+
100x40 block with a `position: absolute` 0x0 sibling inside its box: 1 pair without the
|
|
328
|
+
guard, 0 with it. That guard belongs to the overlap test alone: never carry it over to
|
|
329
|
+
target size, where a zero-area box can still be a real target.
|
|
330
|
+
|
|
331
|
+
## Target size, including a pseudo-element hit area
|
|
332
|
+
|
|
333
|
+
`getBoundingClientRect` measures the control, not a `::before` overlay that
|
|
334
|
+
enlarges the hit area. A pseudo-element is hit-testable and `elementFromPoint`
|
|
335
|
+
returns the element that generated it, so walk outward from the centre until the
|
|
336
|
+
point stops resolving to the control or one of its descendants.
|
|
337
|
+
|
|
338
|
+
```js
|
|
339
|
+
const target = (sel) => hits(sel).map((el) => {
|
|
340
|
+
const r = el.getBoundingClientRect();
|
|
341
|
+
const cx = r.left + r.width / 2, cy = r.top + r.height / 2;
|
|
342
|
+
const reach = (dx, dy) => {
|
|
343
|
+
let n = 0;
|
|
344
|
+
while (n < 32) {
|
|
345
|
+
const hit = document.elementFromPoint(cx + dx * (n + 1), cy + dy * (n + 1));
|
|
346
|
+
if (!hit || !(hit === el || el.contains(hit))) break;
|
|
347
|
+
n++;
|
|
348
|
+
}
|
|
349
|
+
return n;
|
|
350
|
+
};
|
|
351
|
+
return { tag: el.tagName, w: Math.round(r.width), h: Math.round(r.height),
|
|
352
|
+
hitW: Math.max(Math.round(r.width), reach(-1, 0) + reach(1, 0) + 1),
|
|
353
|
+
hitH: Math.max(Math.round(r.height), reach(0, -1) + reach(0, 1) + 1) };
|
|
354
|
+
});
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
Minimum is 24x24 CSS px. Report the larger of the box and the probed hit area. A target
|
|
358
|
+
under that size can still pass through the spacing exception below.
|
|
359
|
+
|
|
360
|
+
`hits(sel)`, never `all(sel)`, and judge against `hitW`/`hitH`, never against `w`/`h`.
|
|
361
|
+
Unscoped and unfiltered, this exact probe reported 7 controls under 24x24 on a story that
|
|
362
|
+
has none, and all seven measured 0x0. Scoping dropped them because they were chrome, and
|
|
363
|
+
the not-rendered test drops them too because they generated no boxes. A RENDERED 0x0 box
|
|
364
|
+
is the opposite case and stays in: `reach` hit-tests outward from its collapsed centre.
|
|
365
|
+
Measured in Chromium on a `width:0;height:0` button with `::after { position: absolute;
|
|
366
|
+
inset: -12px }`: `w` 0, `h` 0, `hitW` 24, `hitH` 24. That is a pass, and discarding it on
|
|
367
|
+
area would have hidden it. The same button placed 10 CSS px from the viewport edge measured
|
|
368
|
+
`hitW` 22, because the leftward walk hit `x < 0` and truncated; that is the off-viewport
|
|
369
|
+
trap below, not a target-size finding.
|
|
370
|
+
|
|
371
|
+
Three traps this arithmetic already handles, and one it does not:
|
|
372
|
+
|
|
373
|
+
- Never test `hit.contains(el)`. `body` contains the control, so the walk escapes
|
|
374
|
+
the element and keeps counting until it strikes an unrelated neighbour. A lone
|
|
375
|
+
20x20 button then measures 26 tall.
|
|
376
|
+
- Extents are summed as `left + right + 1`, not doubled. The centre is not
|
|
377
|
+
equidistant from both edges on an even-width box.
|
|
378
|
+
- `scrollIntoView` first. Off-viewport points return `null`, which truncates the
|
|
379
|
+
walk and under-reports the target.
|
|
380
|
+
- The walk is integer-pixel, so a fractional box can read 1px high. A result of
|
|
381
|
+
24 or 25 needs the `w`/`h` box values checked before you call it a pass.
|
|
382
|
+
|
|
383
|
+
### Undersized targets: the SC 2.5.8 spacing exception
|
|
384
|
+
|
|
385
|
+
SC 2.5.8 passes a target under 24x24 when a 24 CSS px diameter circle centred on its
|
|
386
|
+
bounding box intersects no other target and no other undersized target's circle. The
|
|
387
|
+
criterion sets no fixed gap. The passing gap depends on the targets' own size: an 8 px
|
|
388
|
+
gap leaves two 16x16 targets' centres 24 px apart, which passes, but two 10x10 targets
|
|
389
|
+
only 18 px apart, which fails.
|
|
390
|
+
|
|
391
|
+
```js
|
|
392
|
+
const spacing = (sel) => {
|
|
393
|
+
const els = hits(sel), size = target(sel);
|
|
394
|
+
const box = els.map((el) => el.getBoundingClientRect());
|
|
395
|
+
const mid = (b) => [b.left + b.width / 2, b.top + b.height / 2];
|
|
396
|
+
const toBox = ([x, y], b) =>
|
|
397
|
+
Math.hypot(Math.max(b.left - x, 0, x - b.right), Math.max(b.top - y, 0, y - b.bottom));
|
|
398
|
+
const small = size.map((s) => s.hitW < 24 || s.hitH < 24);
|
|
399
|
+
const fails = [];
|
|
400
|
+
els.forEach((el, i) => {
|
|
401
|
+
if (!small[i]) return;
|
|
402
|
+
const c = mid(box[i]);
|
|
403
|
+
els.forEach((other, j) => {
|
|
404
|
+
if (i === j) return;
|
|
405
|
+
// another undersized target: the two circles meet; a full-size one: the circle reaches its box
|
|
406
|
+
const d = small[j] ? Math.hypot(c[0] - mid(box[j])[0], c[1] - mid(box[j])[1]) : toBox(c, box[j]);
|
|
407
|
+
if (d < (small[j] ? 24 : 12)) fails.push({ el: el.id || el.tagName, other: other.id || other.tagName, d: Math.round(d) });
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
return fails;
|
|
411
|
+
};
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
Measured in Chromium: two 16x16 buttons with a 4 px gap failed at 20 px between centres,
|
|
415
|
+
and a 16x16 button 8 px from a 24x24 button passed at 16 px from its centre to the other
|
|
416
|
+
box. Run `spacing` over every interactive selector at once, because the exception is
|
|
417
|
+
about neighbours. The equivalent, inline, user-agent, and essential exceptions are judged
|
|
418
|
+
by reading the surface, not by this probe.
|
|
419
|
+
|
|
420
|
+
## Console and network
|
|
421
|
+
|
|
422
|
+
These run in the driver, not inside the page. Start collecting before the first
|
|
423
|
+
navigation and scope the count to one surface: a tab that was already open carries
|
|
424
|
+
diagnostics from earlier pages. With the OpenCode desktop browser read `browser.console`
|
|
425
|
+
and `browser.network.list` for the tab. With Playwright, listen before `goto`:
|
|
426
|
+
|
|
427
|
+
```js
|
|
428
|
+
const errors = [];
|
|
429
|
+
const failed = [];
|
|
430
|
+
page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()); });
|
|
431
|
+
page.on('pageerror', (e) => errors.push(e.message));
|
|
432
|
+
page.on('response', (r) => { if (!r.ok()) failed.push(`${r.status()} ${r.url()}`); });
|
|
433
|
+
page.on('requestfailed', (r) => failed.push(`${r.failure()?.errorText} ${r.url()}`));
|
|
434
|
+
await page.goto(url);
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
An HTTP error comes back with a status and a not-ok response. A DNS failure, a blocked
|
|
438
|
+
request, a CORS rejection, or a refused connection gets no status: it arrives only as a
|
|
439
|
+
failed request, with the driver's failure text (`net::ERR_...` in Chromium). Count request
|
|
440
|
+
failures from the request log once. Chromium also logs a `Failed to load resource`
|
|
441
|
+
console error for each failed subresource, so drop those lines from `errors` or every
|
|
442
|
+
failure counts twice; keep uncaught page errors separate from console errors.
|
|
443
|
+
|
|
444
|
+
A WebKit-based view may report only fetch/XHR and navigation responses, so a broken image
|
|
445
|
+
or stylesheet never shows up there. Drive Chromium when the failed-request count must
|
|
446
|
+
cover subresources.
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# Storybook without the MCP server
|
|
2
|
+
|
|
3
|
+
Storybook supports many frameworks. Its own feature-support matrix names four core
|
|
4
|
+
frameworks with dedicated maintainers, React, Vue 3, Angular, and Web Components, plus six
|
|
5
|
+
community frameworks, Ember, HTML, Svelte, Preact, Qwik, and SolidJS. `ArgTypes` and
|
|
6
|
+
`CSF Stories` are supported in all ten, and the test runner in all but Ember.
|
|
7
|
+
|
|
8
|
+
## Which routes work on which framework
|
|
9
|
+
|
|
10
|
+
Measured on Storybook 10.5.10 with `@storybook/addon-mcp` 0.7.0 installed in BOTH projects,
|
|
11
|
+
so the difference is the framework and not a missing addon.
|
|
12
|
+
|
|
13
|
+
| Route | React | Vue 3 |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| `/index.json`, the CSF index | 200 | 200 |
|
|
16
|
+
| `/iframe.html?id=<storyId>` | 200 | 200 |
|
|
17
|
+
| `/manifests/docs.json` | 200 | 200 |
|
|
18
|
+
| `/manifests/components.html`, the debugger | 200 | 200, reporting zero components |
|
|
19
|
+
| `/manifests/components.json`, the prop table | 200 | 404, `Manifest "components" not found` |
|
|
20
|
+
|
|
21
|
+
Three packages share the work, which is why the table splits the way it does.
|
|
22
|
+
`@storybook/addon-mcp` only turns the feature on, setting `features.componentsManifest`.
|
|
23
|
+
`@storybook/react` generates the components payload into `experimental_manifests`.
|
|
24
|
+
`@storybook/addon-docs` generates the docs manifest. Verified in each package's own
|
|
25
|
+
`dist/preset.js`.
|
|
26
|
+
|
|
27
|
+
So a Vue project with `@storybook/addon-mcp` installed still has no components manifest: the
|
|
28
|
+
flag is on, and no framework package produces that payload. Its docs manifest works, because
|
|
29
|
+
`@storybook/addon-docs` is framework-agnostic.
|
|
30
|
+
|
|
31
|
+
The React initializer installs `@storybook/addon-mcp` automatically; the Vue initializer does
|
|
32
|
+
not, so add it before expecting any manifest route at all.
|
|
33
|
+
|
|
34
|
+
## Why the MCP server usually is not available
|
|
35
|
+
|
|
36
|
+
An agent cannot connect or reconnect an MCP server: only the user can, through the
|
|
37
|
+
harness (in OpenCode, `/mcps`). The design plugin's README configures the `storybook`
|
|
38
|
+
server disabled, so it is absent unless the user enabled it, and even then it connects to
|
|
39
|
+
`http://localhost:6006/mcp` only if Storybook was running when the server started.
|
|
40
|
+
|
|
41
|
+
When this skill starts Storybook itself, assume the MCP tools stay unavailable for the
|
|
42
|
+
rest of the session. Say so in the report and use the HTTP routes above. You MAY tell the
|
|
43
|
+
user that reconnecting the `storybook` server would enable the tools, but never plan it as
|
|
44
|
+
your own action.
|
|
45
|
+
|
|
46
|
+
## Start the dev server, and keep it
|
|
47
|
+
|
|
48
|
+
DEFAULT the dev server, started once and reused for every later check in the run: one
|
|
49
|
+
background shell process running the `storybook dev` command from the Storybook lifecycle
|
|
50
|
+
table in
|
|
51
|
+
`tools.md`. That table also covers the static build,
|
|
52
|
+
`doctor`, and the `*.log` a crash leaves in the caller's cwd.
|
|
53
|
+
|
|
54
|
+
Gate readiness on the PORT, never on a log pattern. Storybook 10.5.10 prints
|
|
55
|
+
`storybook v10.5.10` and then a manifest line, and never the word "started", so a
|
|
56
|
+
`log` condition waits out the whole timeout while the server is already serving. When both
|
|
57
|
+
`log` and `port` are supplied, BOTH must pass, so one stale pattern hides a working server.
|
|
58
|
+
Allow 240 seconds: a cold Vite dependency scan takes minutes.
|
|
59
|
+
|
|
60
|
+
MUST report the URL in your output so the user can follow along.
|
|
61
|
+
|
|
62
|
+
Enumerate stories from `http://localhost:6006/index.json`, which carries `id`, `title`,
|
|
63
|
+
and `tags` per entry.
|
|
64
|
+
|
|
65
|
+
A static build answers only what the dev server serves for that framework, so a Vue
|
|
66
|
+
project still yields no components manifest. Measured on React, `--test` keeps
|
|
67
|
+
`index.json` and `manifests/components.json` but drops `manifests/docs.json` and
|
|
68
|
+
`manifests/components.html`: use it for running stories as tests, and a plain build for
|
|
69
|
+
reading documentation.
|
|
70
|
+
|
|
71
|
+
## What persists
|
|
72
|
+
|
|
73
|
+
Two layers, and only one of them is durable.
|
|
74
|
+
|
|
75
|
+
**The source is the durable design record.** Components, stories, and tokens are ordinary
|
|
76
|
+
committed files. The `stories` glob in `.storybook/main.ts`, for example
|
|
77
|
+
`["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"]`, IS the registry: any
|
|
78
|
+
matching file is discovered on every start. Nothing is ever re-added.
|
|
79
|
+
|
|
80
|
+
**The local view is disposable.** `storybook dev` serves from memory and fills two caches,
|
|
81
|
+
`node_modules/.cache/storybook/` and `node_modules/.vite/`. One command regenerates all of
|
|
82
|
+
it.
|
|
83
|
+
|
|
84
|
+
## The manifests are the primary agent surface
|
|
85
|
+
|
|
86
|
+
`http://localhost:6006/manifests/components.json` is the ground truth that
|
|
87
|
+
the `design-component-truth` skill requires before a prop is used. Its shape, verified against
|
|
88
|
+
Storybook 10.5.10:
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
{ "v": 0,
|
|
92
|
+
"components": { <- an OBJECT keyed by component id, not an array
|
|
93
|
+
"example-button": {
|
|
94
|
+
"id", "name", "path", "import", "description", "jsDocTags",
|
|
95
|
+
"reactDocgen": { <- engine-specific payload; see the dispatch below
|
|
96
|
+
"props": { "backgroundColor": { "required": false,
|
|
97
|
+
"tsType": { "name": "string" },
|
|
98
|
+
"description": "What background color to use" } },
|
|
99
|
+
"actualName", "definedInFile", "displayName", "exportName", "methods" },
|
|
100
|
+
"stories": [ { "id", "name", "snippet" } ] } },
|
|
101
|
+
"meta": { "docgen": "react-docgen", "durationMs": 64 } }
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Index `components` by component id, then read the ENGINE-SPECIFIC payload. Do not hardcode
|
|
105
|
+
one key: read `meta.docgen` and pick accordingly. The key is not the engine string itself,
|
|
106
|
+
for example engine `react-docgen` puts its payload under `reactDocgen`.
|
|
107
|
+
|
|
108
|
+
`@storybook/react/dist/preset.js` chooses the engine:
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
features.experimentalDocgenServer -> components: {}, meta.docgen "react-component-meta"
|
|
112
|
+
features.experimentalReactComponentMeta -> "react-component-meta"
|
|
113
|
+
typescript.reactDocgen set -> that value verbatim, e.g. "react-docgen-typescript"
|
|
114
|
+
otherwise -> "react-docgen"
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
On the `react-docgen` path, `reactDocgen.props` is keyed by prop name, each entry carrying
|
|
118
|
+
`required`, a `tsType`, and a `description`.
|
|
119
|
+
|
|
120
|
+
An empty `components` map is NOT proof that a project has no components: under
|
|
121
|
+
`experimentalDocgenServer` the generator returns an empty map by design. Treat empty as
|
|
122
|
+
inconclusive and read the source instead.
|
|
123
|
+
|
|
124
|
+
Take the `import` statement verbatim, and take a `snippet` from `stories` as a worked example.
|
|
125
|
+
|
|
126
|
+
`http://localhost:6006/manifests/docs.json` gives MDX pages as
|
|
127
|
+
`{ "v", "docs": { <id>: { "id", "name", "title", "path", "summary", "content" } } }`,
|
|
128
|
+
including design-token and typography documentation.
|
|
129
|
+
|
|
130
|
+
`http://localhost:6006/manifests/components.html` is the human-readable debugger and shows
|
|
131
|
+
generation errors and warnings.
|
|
132
|
+
|
|
133
|
+
The docs manifest is static analysis only. A `Colors.mdx` that maps over a token object at
|
|
134
|
+
runtime contributes nothing, so token values must appear literally. That is one more reason
|
|
135
|
+
DESIGN.md stays the literal authored record.
|
|
136
|
+
|
|
137
|
+
## Inspect and test
|
|
138
|
+
|
|
139
|
+
Render one story in isolation at `http://localhost:6006/iframe.html?id=<storyId>` and apply
|
|
140
|
+
the ARIA, computed-style, and viewport probes from `probes.md`
|
|
141
|
+
to it. This is Component Driven verification: a component-level failure is smaller to
|
|
142
|
+
locate than the same failure found on an assembled page.
|
|
143
|
+
|
|
144
|
+
MUST Scope every probe to `#storybook-root`. The frame also holds Storybook's hidden
|
|
145
|
+
fallback chrome, and the root helper plus the measured cost of skipping it are in the
|
|
146
|
+
"Resolve the root once" section of `probes.md`.
|
|
147
|
+
|
|
148
|
+
To execute every story, take the `test-storybook` row of
|
|
149
|
+
`tools.md`: it carries the required `--package` and the
|
|
150
|
+
preference for `vitest` on Vite-powered frameworks. The runner picks up accessibility
|
|
151
|
+
checks when `@storybook/addon-a11y` is installed.
|
|
152
|
+
|
|
153
|
+
## Composition, for Component Driven stages two and three
|
|
154
|
+
|
|
155
|
+
`refs` in `.storybook/main.ts` composes any Storybook reachable by URL, local or published,
|
|
156
|
+
across frameworks, so a design-system Storybook can be referenced while larger components
|
|
157
|
+
are assembled:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
refs: { 'design-system': { title: '...', url: 'https://...', expanded: false, sourceUrl: '...' } }
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Local multi-framework composition uses separate ports, and `refs` may be a function of
|
|
164
|
+
`(config, { configType })` to vary by environment.
|
|
165
|
+
|
|
166
|
+
Two caveats that matter in practice: addons in composed Storybooks do not work as they
|
|
167
|
+
normally do, and `storybook extract` is not available in 8.0 or higher.
|
|
168
|
+
|
|
169
|
+
## MCP tools, when they are connected
|
|
170
|
+
|
|
171
|
+
Seven tools in three toolsets, all enabled by default, configured through
|
|
172
|
+
`@storybook/addon-mcp` `options.toolsets`:
|
|
173
|
+
|
|
174
|
+
| Toolset | Tools |
|
|
175
|
+
|---|---|
|
|
176
|
+
| `docs` | `list-all-documentation`, `get-documentation`, `get-documentation-for-story` |
|
|
177
|
+
| `dev` | `get-storybook-story-instructions`, `get-changed-stories`, `preview-stories` |
|
|
178
|
+
| `test` | `run-story-tests` |
|
|
179
|
+
|
|
180
|
+
These are React-only and in preview, and the manifest schema is explicitly not a public
|
|
181
|
+
API. Where they are absent, the HTTP routes above are equivalent for reading, and reading
|
|
182
|
+
the component source and its type declaration is the fallback authority.
|
|
183
|
+
|
|
184
|
+
## Setting Storybook up where none exists
|
|
185
|
+
|
|
186
|
+
Never install it unprompted. When the user wants it, run `npx --yes storybook ai setup`,
|
|
187
|
+
which derives project-specific setup and story instructions from the actual codebase. Follow
|
|
188
|
+
its output rather than a remembered procedure: the value is that it reads this repo.
|
|
189
|
+
|
|
190
|
+
## Authoring rules that make stories useful to an agent
|
|
191
|
+
|
|
192
|
+
- One concept per story. A story demonstrating five sizes and variants at once is the named
|
|
193
|
+
anti-pattern.
|
|
194
|
+
- Describe why, not what.
|
|
195
|
+
- Put a JSDoc description and `@summary` above the component export and above each story,
|
|
196
|
+
because the agent receives the summary or a truncated description.
|
|
197
|
+
- Document every prop with JSDoc.
|
|
198
|
+
- Prefer `reactDocgen: 'react-docgen-typescript'` for accuracy; fall back to `react-docgen`
|
|
199
|
+
for speed.
|
|
200
|
+
- Curate with the implicit `manifest` tag. Exclude a story or a whole file with
|
|
201
|
+
`tags: ['!manifest']`.
|
|
202
|
+
- Wrap a CONTROLLED component in a state holder, never args alone. A component taking a
|
|
203
|
+
value plus an `onChange` renders every field from args and then rejects every keystroke,
|
|
204
|
+
because nothing writes the value back. That reads as a broken control rather than as a
|
|
205
|
+
story defect, and it is the failure a page-level state story hits first. Give the story a
|
|
206
|
+
decorator or wrapper holding real state, and verify by typing into a field and reading the
|
|
207
|
+
value back.
|
|
208
|
+
|
|
209
|
+
## Documentation retrieval
|
|
210
|
+
|
|
211
|
+
`https://storybook.js.org/llms.txt` is the index and states the access contract;
|
|
212
|
+
`llms-full.txt` is the whole corpus. Append `.md` to any docs URL for clean markdown, with
|
|
213
|
+
`?renderer=react|vue|angular|svelte|web-components|solid|preact|html|ember|qwik`,
|
|
214
|
+
`?language=ts|js`, and `?codeOnly=true`. Always pass the project's real renderer, because
|
|
215
|
+
the default is React. Version with `/docs/9/...md` or `llms-full.txt?version=9`.
|
|
216
|
+
|
|
217
|
+
Prefer these over the `context7` MCP: they are primary and add no dependency.
|