@behavioral-agentic-design-system/core 0.39.0 → 0.40.0
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/package.json +8 -3
- package/scripts/a11y-lint.cjs +93 -39
- package/scripts/a11y-ratchet.mjs +10 -23
- package/scripts/bads-components.mjs +118 -0
- package/scripts/build-tokens.cjs +175 -17
- package/scripts/check-stories.mjs +1 -1
- package/scripts/health-report.mjs +52 -10
- package/scripts/lib/scan-roots.cjs +143 -0
- package/scripts/lint-component-source.mjs +100 -0
- package/scripts/lint-microanimation.mjs +267 -0
- package/scripts/lint-slop.mjs +21 -28
- package/scripts/lint-token-intent.mjs +10 -16
- package/scripts/size-audit.cjs +94 -27
- package/scripts/source-of-truth.cjs +58 -0
- package/scripts/ux-smoke.mjs +438 -0
- package/scripts/wcag-audit.cjs +49 -1
- package/src/api/layers/file.ts +2 -0
- package/src/app/preview/components/page.tsx +972 -0
- package/src/app/preview/health/page.tsx +8 -5
- package/src/app/preview/history/page.tsx +11 -0
- package/src/app/shell.tsx +261 -87
- package/src/components/customize/brand-mark-section.tsx +4 -2
- package/src/components/customize/design-controls.tsx +1 -1
- package/src/components/customize/discipline-section.tsx +91 -0
- package/src/components/customize/font-pickers.tsx +1 -1
- package/src/components/customize/letter-spacing.tsx +1 -1
- package/src/components/customize/save-bar.tsx +2 -2
- package/src/components/customize/theme-io.tsx +7 -7
- package/src/components/customize/type-scale.tsx +1 -1
- package/src/components/customize-tab.tsx +9 -4
- package/src/components/home-tab.tsx +3 -0
- package/src/components/ui/accordion.tsx +7 -0
- package/src/components/ui/alert.tsx +1 -0
- package/src/components/ui/announcement-bar.tsx +256 -0
- package/src/components/ui/badge.tsx +1 -0
- package/src/components/ui/callout.tsx +218 -0
- package/src/components/ui/chart.tsx +2 -14
- package/src/components/ui/color-picker.tsx +1 -1
- package/src/components/ui/format-relative-time.tsx +139 -0
- package/src/components/ui/grid.tsx +255 -0
- package/src/components/ui/icon.tsx +108 -0
- package/src/components/ui/index.ts +8 -0
- package/src/components/ui/page-header.tsx +63 -0
- package/src/components/ui/portal.tsx +111 -0
- package/src/components/ui/presence.tsx +172 -0
- package/src/components/ui/progress-stack.tsx +258 -0
- package/src/components/ui/select.tsx +89 -4
- package/src/components/ui/separator.tsx +1 -0
- package/src/components/ui/slider.tsx +83 -3
- package/src/components/ui/sparkline.tsx +15 -15
- package/src/components/ui/textarea.tsx +28 -1
- package/src/data/docs-index.ts +5 -0
- package/src/data/history.json +269 -0
- package/src/hooks/use-reduced-motion.ts +6 -0
- package/src/stories/Accordion.stories.tsx +59 -0
- package/src/stories/Alert.stories.tsx +3 -1
- package/src/stories/AnnouncementBar.stories.tsx +261 -0
- package/src/stories/Badge.stories.tsx +3 -0
- package/src/stories/Calendar.stories.tsx +1 -1
- package/src/stories/Callout.stories.tsx +219 -0
- package/src/stories/Chart.stories.tsx +4 -0
- package/src/stories/ColorPicker.stories.tsx +23 -0
- package/src/stories/FormatRelativeTime.stories.tsx +116 -0
- package/src/stories/Grid.stories.tsx +197 -0
- package/src/stories/Icon.stories.tsx +175 -0
- package/src/stories/MultiSelect.stories.tsx +1 -1
- package/src/stories/PageHeader.stories.tsx +102 -0
- package/src/stories/Portal.stories.tsx +189 -0
- package/src/stories/Presence.stories.tsx +228 -0
- package/src/stories/ProgressStack.stories.tsx +287 -0
- package/src/stories/Select.stories.tsx +25 -0
- package/src/stories/Separator.stories.tsx +3 -0
- package/src/stories/Sheet.stories.tsx +9 -3
- package/src/stories/Slider.stories.tsx +54 -5
- package/src/stories/Sparkline.stories.tsx +39 -0
- package/src/stories/Textarea.stories.tsx +18 -0
- package/src/stories/story-groups.json +14 -5
- package/src/styles.css +133 -12
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* ux-smoke — deterministic, browser-driven UX smoke gate for the Night Shift
|
|
4
|
+
* persona UX-test pass (scripts/prompts/night-shift.md → step 3d).
|
|
5
|
+
*
|
|
6
|
+
* Drives headless Chromium over one or more showcase anchors on a RUNNING
|
|
7
|
+
* preview server, IN BOTH LIGHT AND DARK THEMES, and runs the checks that a
|
|
8
|
+
* screenshot and the per-story CI axe run both miss:
|
|
9
|
+
*
|
|
10
|
+
* 1. axe (scoped to the anchor) — critical/serious => BLOCKER
|
|
11
|
+
* 2. rendered contrast (fg vs real bg) — < 4.5:1 => BLOCKER, < 7:1 (AAA) => HIGH
|
|
12
|
+
* 3. sub-14px rendered text (the floor) — computed font-size < 14px => HIGH
|
|
13
|
+
* 4. reduced-motion halt — any animation not collapsed => BLOCKER
|
|
14
|
+
* 5. anchor horizontal overflow — content wider than its box => BLOCKER
|
|
15
|
+
* 6. keyboard focus indicator — focusable el with no ring => WARN
|
|
16
|
+
*
|
|
17
|
+
* Running every check in BOTH themes is the point: it catches the "fixed in
|
|
18
|
+
* light, still broken in dark" asymmetry and the dark-on-dark / light-on-white
|
|
19
|
+
* text the token-pair audit can't see (that audit checks token pairs; this
|
|
20
|
+
* checks what actually paints on the assembled page). Each anchor is also
|
|
21
|
+
* screenshotted in both themes so the report can show the flow.
|
|
22
|
+
*
|
|
23
|
+
* Usage:
|
|
24
|
+
* pnpm ux:smoke <anchor> [anchor...]
|
|
25
|
+
* BASE_URL=http://localhost:3000 ROUTE=/preview/components \
|
|
26
|
+
* UX_SCREENS_DIR=/tmp/ux-screens pnpm ux:smoke buttons separator
|
|
27
|
+
*
|
|
28
|
+
* Exit 1 if any BLOCKER is produced (0 otherwise). Every finding + screenshot
|
|
29
|
+
* path is printed as one JSON line for the calling agent to log + attach.
|
|
30
|
+
*/
|
|
31
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
32
|
+
|
|
33
|
+
const BASE_URL = process.env.BASE_URL || "http://localhost:3000";
|
|
34
|
+
// ROUTE takes a comma-separated LIST. The default is still the components page,
|
|
35
|
+
// so nothing that calls this today changes behaviour.
|
|
36
|
+
const ROUTES = (process.env.ROUTE || "/preview/components")
|
|
37
|
+
.split(",")
|
|
38
|
+
.map((r) => r.trim())
|
|
39
|
+
.filter(Boolean);
|
|
40
|
+
// Mutable: reassigned per route by the sweep loop, and read by openPage().
|
|
41
|
+
let ROUTE = ROUTES[0];
|
|
42
|
+
let URL = BASE_URL.replace(/\/$/, "") + ROUTE;
|
|
43
|
+
const SCREENS_DIR = process.env.UX_SCREENS_DIR || "/tmp/ux-screens";
|
|
44
|
+
const argv = process.argv.slice(2).filter(Boolean);
|
|
45
|
+
// `--page` scopes every check to the WHOLE route instead of a named anchor.
|
|
46
|
+
//
|
|
47
|
+
// Without it this gate can only ever check what somebody remembered to name, and
|
|
48
|
+
// a gate aimed at a fraction of a page reports green on a broken page. That is
|
|
49
|
+
// not hypothetical: in the Furnished Finder fork it was being invoked with two
|
|
50
|
+
// anchors against a route carrying 61k characters of component demos, and it
|
|
51
|
+
// passed six consecutive nightly runs while that page had unreadable banner
|
|
52
|
+
// text, a collapsed slider, a tab pill overlapping body copy and clipped select
|
|
53
|
+
// values. Whole-page mode is one pseudo-anchor whose selector is `body`, so every
|
|
54
|
+
// existing check runs unchanged over the entire route.
|
|
55
|
+
const WHOLE_PAGE = argv.includes("--page");
|
|
56
|
+
const anchors = argv.filter((a) => !a.startsWith("--"));
|
|
57
|
+
|
|
58
|
+
/** Filesystem-safe slug for a route, so per-route screenshots cannot collide. */
|
|
59
|
+
const routeSlug = (route) => route.replace(/^\//, "").replace(/[^a-z0-9]+/gi, "-") || "root";
|
|
60
|
+
|
|
61
|
+
// A 404 that is the POINT of a demo rather than a defect. Each entry states why,
|
|
62
|
+
// because an unexplained allowlist is how a real defect gets waved through later.
|
|
63
|
+
// Empty here: BADS itself has no such demo. Forks add entries with a reason.
|
|
64
|
+
const MISSING_ASSET_ALLOWLIST = [];
|
|
65
|
+
const THEMES = ["light", "dark"];
|
|
66
|
+
// AAA is BADS's bar; BLOCKER only on a true AA failure (unreadable), HIGH on
|
|
67
|
+
// an AAA (7:1) miss so the brief can surface it without flooding.
|
|
68
|
+
const AAA = 7,
|
|
69
|
+
AA = 4.5,
|
|
70
|
+
AA_LARGE = 3;
|
|
71
|
+
|
|
72
|
+
if (anchors.length === 0 && !WHOLE_PAGE) {
|
|
73
|
+
console.error("ux-smoke: pass at least one showcase anchor, e.g. `pnpm ux:smoke buttons separator`");
|
|
74
|
+
console.error(" or `pnpm ux:smoke --page` to check the whole route.");
|
|
75
|
+
process.exit(2);
|
|
76
|
+
}
|
|
77
|
+
mkdirSync(SCREENS_DIR, { recursive: true });
|
|
78
|
+
|
|
79
|
+
function chromiumExecutable() {
|
|
80
|
+
if (process.env.PW_CHROMIUM && existsSync(process.env.PW_CHROMIUM)) return process.env.PW_CHROMIUM;
|
|
81
|
+
for (const c of [
|
|
82
|
+
"/opt/pw-browsers/chromium-1194/chrome-linux/chrome",
|
|
83
|
+
"/opt/pw-browsers/chromium/chrome-linux/chrome",
|
|
84
|
+
]) if (existsSync(c)) return c;
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let chromium, injectAxe, getViolations;
|
|
89
|
+
try {
|
|
90
|
+
({ chromium } = await import("playwright"));
|
|
91
|
+
({ injectAxe, getViolations } = await import("axe-playwright"));
|
|
92
|
+
} catch (e) {
|
|
93
|
+
console.error("ux-smoke: playwright / axe-playwright not installed — run `pnpm install`.", e.message);
|
|
94
|
+
process.exit(2);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const findings = [];
|
|
98
|
+
const screenshots = [];
|
|
99
|
+
const add = (f) => { findings.push(f); console.log(JSON.stringify({ type: "finding", ...f })); };
|
|
100
|
+
|
|
101
|
+
const exe = chromiumExecutable();
|
|
102
|
+
const browser = await chromium.launch(exe ? { executablePath: exe } : {});
|
|
103
|
+
|
|
104
|
+
async function openPage(theme, opts = {}) {
|
|
105
|
+
const ctx = await browser.newContext({ viewport: { width: 1280, height: 1400 }, deviceScaleFactor: 2, ...opts });
|
|
106
|
+
const page = await ctx.newPage();
|
|
107
|
+
// Track subresources that never arrived. A missing image does not throw; it
|
|
108
|
+
// degrades into whatever is painted underneath, and no contrast gate can
|
|
109
|
+
// attribute the resulting reading to the asset that is missing.
|
|
110
|
+
page.__failedRequests = [];
|
|
111
|
+
page.on("response", (r) => {
|
|
112
|
+
const st = r.status();
|
|
113
|
+
if (st >= 400) page.__failedRequests.push(`${st} ${r.url()}`);
|
|
114
|
+
});
|
|
115
|
+
page.on("requestfailed", (r) => {
|
|
116
|
+
page.__failedRequests.push(`FAILED ${r.url()} (${r.failure()?.errorText || "unknown"})`);
|
|
117
|
+
});
|
|
118
|
+
// The preview app toggles dark via the `?dark=1` query param (dark-mode-client.tsx),
|
|
119
|
+
// NOT localStorage — use the app's real mechanism so the theme is deterministic.
|
|
120
|
+
const dark = theme === "dark";
|
|
121
|
+
const url = dark ? URL + (URL.includes("?") ? "&" : "?") + "dark=1" : URL;
|
|
122
|
+
const res = await page.goto(url, { waitUntil: "networkidle", timeout: 60000 }).catch(() => null);
|
|
123
|
+
if (!res || !res.ok()) { await ctx.close(); throw new Error(`could not load ${url} (is the preview server running?)`); }
|
|
124
|
+
// Verify the theme actually took (the toggle runs in a useEffect). Retry a few
|
|
125
|
+
// times, force the class as a fallback, and confirm the painted body bg matches
|
|
126
|
+
// the expected theme before any probe reads colors — a flaky theme = a flaky gate.
|
|
127
|
+
for (let i = 0; i < 6; i++) {
|
|
128
|
+
const ok = await page.evaluate((wantDark) => {
|
|
129
|
+
const r = document.documentElement;
|
|
130
|
+
const has = r.classList.contains("dark");
|
|
131
|
+
if (has !== wantDark) { r.classList.toggle("dark", wantDark); r.style.colorScheme = wantDark ? "dark" : "light"; return false; }
|
|
132
|
+
// confirm it actually painted: body bg luminance should match the theme
|
|
133
|
+
const cv = document.createElement("canvas").getContext("2d", { willReadFrequently: true });
|
|
134
|
+
cv.fillStyle = getComputedStyle(document.body).backgroundColor; cv.fillRect(0, 0, 1, 1);
|
|
135
|
+
const d = cv.getImageData(0, 0, 1, 1).data;
|
|
136
|
+
const L = (0.2126 * d[0] + 0.7152 * d[1] + 0.0722 * d[2]) / 255;
|
|
137
|
+
return wantDark ? L < 0.4 : L > 0.6;
|
|
138
|
+
}, dark);
|
|
139
|
+
if (ok) break;
|
|
140
|
+
await page.waitForTimeout(200);
|
|
141
|
+
}
|
|
142
|
+
await page.waitForTimeout(200);
|
|
143
|
+
return { ctx, page };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// In-page contrast helpers, injected as a string so they run in the browser.
|
|
147
|
+
const CONTRAST_PROBE = `(sel, AAA, AA, AA_LARGE) => {
|
|
148
|
+
const root = document.querySelector(sel);
|
|
149
|
+
if (!root) return [];
|
|
150
|
+
// Normalize ANY computed color (oklch/oklab/hsl/named/hex/rgb) to sRGB by
|
|
151
|
+
// rasterizing one pixel — getComputedStyle preserves oklch (which every BADS
|
|
152
|
+
// token uses), so string-parsing rgb() alone silently misreads everything.
|
|
153
|
+
const _cv = document.createElement('canvas'); _cv.width = 1; _cv.height = 1;
|
|
154
|
+
const _ctx = _cv.getContext('2d', { willReadFrequently: true });
|
|
155
|
+
const parse = (c) => {
|
|
156
|
+
if (!c) return null;
|
|
157
|
+
try {
|
|
158
|
+
_ctx.clearRect(0, 0, 1, 1);
|
|
159
|
+
_ctx.fillStyle = '#000000';
|
|
160
|
+
_ctx.fillStyle = c;
|
|
161
|
+
_ctx.fillRect(0, 0, 1, 1);
|
|
162
|
+
const d = _ctx.getImageData(0, 0, 1, 1).data;
|
|
163
|
+
return { r: d[0], g: d[1], b: d[2], a: d[3] / 255 };
|
|
164
|
+
} catch { return null; }
|
|
165
|
+
};
|
|
166
|
+
const lin = (v) => { v /= 255; return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4); };
|
|
167
|
+
const lum = (c) => 0.2126 * lin(c.r) + 0.7152 * lin(c.g) + 0.0722 * lin(c.b);
|
|
168
|
+
const ratio = (f, b) => { const L1 = lum(f), L2 = lum(b); const hi = Math.max(L1, L2), lo = Math.min(L1, L2); return (hi + 0.05) / (lo + 0.05); };
|
|
169
|
+
const over = (fg, bg) => ({ // source-over composite fg (with alpha) onto opaque bg
|
|
170
|
+
r: fg.r * fg.a + bg.r * (1 - fg.a),
|
|
171
|
+
g: fg.g * fg.a + bg.g * (1 - fg.a),
|
|
172
|
+
b: fg.b * fg.a + bg.b * (1 - fg.a),
|
|
173
|
+
a: 1,
|
|
174
|
+
});
|
|
175
|
+
// True painted background: composite every semi-transparent bg layer from the
|
|
176
|
+
// element up to the root, in paint order. A naive "first opaque ancestor"
|
|
177
|
+
// walk misreads bg-*/10 tints (bg-destructive/10 over a dark card) — the exact
|
|
178
|
+
// case that produces false red-on-red readings.
|
|
179
|
+
//
|
|
180
|
+
// Second rule, added after a measured false positive: a layer only counts if it
|
|
181
|
+
// actually SITS BEHIND THE TEXT. An ancestor paints its own box, not its
|
|
182
|
+
// descendants boxes, and an absolutely-positioned child can sit entirely
|
|
183
|
+
// outside its parent rect.
|
|
184
|
+
//
|
|
185
|
+
// The case, from the Furnished Finder fork: a Slider step label is positioned
|
|
186
|
+
// below its own 4x4px brand-blue dot, so the walk composited the dot and
|
|
187
|
+
// reported the label as blue-on-blue at 1:1. Zero rect overlap; a pixel sample
|
|
188
|
+
// of the glyph area was 913 of 1092 pure white, and the real ratio was 8.88:1.
|
|
189
|
+
//
|
|
190
|
+
// A false BLOCKER is not a cheap mistake: it sends someone to fix a component
|
|
191
|
+
// that is already correct, and a gate that cries wolf gets bypassed rather than
|
|
192
|
+
// obeyed. So intersect first, composite second.
|
|
193
|
+
const intersects = (a, b) => a.right > b.left && a.left < b.right && a.bottom > b.top && a.top < b.bottom;
|
|
194
|
+
const effectiveBg = (el) => {
|
|
195
|
+
const layers = [];
|
|
196
|
+
const target = el.getBoundingClientRect();
|
|
197
|
+
let n = el, untrusted = false;
|
|
198
|
+
while (n && n !== document.documentElement) {
|
|
199
|
+
const cs = getComputedStyle(n);
|
|
200
|
+
// Skip a layer whose painted box does not cover the text at all.
|
|
201
|
+
if (n !== el && !intersects(target, n.getBoundingClientRect())) { n = n.parentElement; continue; }
|
|
202
|
+
if (cs.backgroundImage && cs.backgroundImage !== "none") untrusted = true; // gradient/image — can't know the pixel
|
|
203
|
+
if (cs.backdropFilter && cs.backdropFilter !== "none") untrusted = true;
|
|
204
|
+
const bg = parse(cs.backgroundColor);
|
|
205
|
+
if (bg && bg.a > 0.001) layers.push(bg);
|
|
206
|
+
n = n.parentElement;
|
|
207
|
+
}
|
|
208
|
+
let base = parse(getComputedStyle(document.body).backgroundColor);
|
|
209
|
+
if (!base || base.a < 0.99) base = parse(getComputedStyle(document.documentElement).backgroundColor);
|
|
210
|
+
if (!base || base.a < 0.99) base = { r: 255, g: 255, b: 255, a: 1 };
|
|
211
|
+
// composite from the root layer (last collected) down to the element (first)
|
|
212
|
+
let acc = { r: base.r, g: base.g, b: base.b, a: 1 };
|
|
213
|
+
for (let i = layers.length - 1; i >= 0; i--) acc = over(layers[i], acc);
|
|
214
|
+
acc.untrusted = untrusted;
|
|
215
|
+
return acc;
|
|
216
|
+
};
|
|
217
|
+
const isDisabled = (el) => !!el.closest('[disabled],[aria-disabled="true"],[data-disabled]') ||
|
|
218
|
+
/opacity-[0-5]0\\b/.test(el.className || "");
|
|
219
|
+
const out = [];
|
|
220
|
+
const seen = new Set();
|
|
221
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
222
|
+
let node;
|
|
223
|
+
while ((node = walker.nextNode())) {
|
|
224
|
+
const text = node.textContent.trim();
|
|
225
|
+
if (!text || text.length < 2) continue;
|
|
226
|
+
const el = node.parentElement;
|
|
227
|
+
if (!el) continue;
|
|
228
|
+
const s = getComputedStyle(el);
|
|
229
|
+
if (s.visibility === "hidden" || s.display === "none" || parseFloat(s.opacity) < 0.7) continue;
|
|
230
|
+
const rect = el.getBoundingClientRect();
|
|
231
|
+
if (rect.width < 2 || rect.height < 2) continue;
|
|
232
|
+
if (isDisabled(el)) continue;
|
|
233
|
+
let fg = parse(s.color);
|
|
234
|
+
if (!fg || fg.a < 0.3) continue;
|
|
235
|
+
const bg = effectiveBg(el);
|
|
236
|
+
if (fg.a < 1) fg = over(fg, bg); // composite translucent text onto its real bg
|
|
237
|
+
const r = ratio(fg, bg);
|
|
238
|
+
const fs = parseFloat(s.fontSize);
|
|
239
|
+
const large = fs >= 24 || (fs >= 18.66 && parseInt(s.fontWeight) >= 700);
|
|
240
|
+
const blockAt = large ? AA_LARGE : AA;
|
|
241
|
+
const aaaAt = large ? AA : AAA;
|
|
242
|
+
const key = Math.round(fg.r) + "," + Math.round(fg.g) + "," + Math.round(fg.b) + "|" + Math.round(bg.r) + "," + Math.round(bg.g) + "," + Math.round(bg.b);
|
|
243
|
+
if (seen.has(key)) continue;
|
|
244
|
+
seen.add(key);
|
|
245
|
+
if (r < aaaAt) {
|
|
246
|
+
// BLOCKER only for a confident AA failure on a fully-determinable bg.
|
|
247
|
+
// Over a gradient/image/backdrop-filter (untrusted) we can't know the
|
|
248
|
+
// painted pixel, so cap at HIGH for the agent to eyeball in the shot.
|
|
249
|
+
const sev = r < blockAt ? (bg.untrusted ? "HIGH" : "BLOCKER") : "HIGH";
|
|
250
|
+
out.push({
|
|
251
|
+
ratio: Math.round(r * 100) / 100,
|
|
252
|
+
severity: sev,
|
|
253
|
+
untrusted: !!bg.untrusted,
|
|
254
|
+
fontSizePx: fs, large,
|
|
255
|
+
fg: 'rgb(' + Math.round(fg.r) + ',' + Math.round(fg.g) + ',' + Math.round(fg.b) + ')',
|
|
256
|
+
bg: 'rgb(' + Math.round(bg.r) + ',' + Math.round(bg.g) + ',' + Math.round(bg.b) + ')',
|
|
257
|
+
sample: text.slice(0, 40),
|
|
258
|
+
tag: el.tagName.toLowerCase(),
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return out.sort((a, b) => a.ratio - b.ratio).slice(0, 12);
|
|
263
|
+
}`;
|
|
264
|
+
|
|
265
|
+
const SUBFLOOR_PROBE = `(sel) => {
|
|
266
|
+
const root = document.querySelector(sel);
|
|
267
|
+
if (!root) return [];
|
|
268
|
+
const out = [];
|
|
269
|
+
const seen = new Set();
|
|
270
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
271
|
+
let node;
|
|
272
|
+
while ((node = walker.nextNode())) {
|
|
273
|
+
const text = node.textContent.trim();
|
|
274
|
+
if (!text) continue;
|
|
275
|
+
const el = node.parentElement;
|
|
276
|
+
const s = getComputedStyle(el);
|
|
277
|
+
if (s.visibility === "hidden" || s.display === "none") continue;
|
|
278
|
+
const fs = parseFloat(s.fontSize);
|
|
279
|
+
if (fs && fs < 14) {
|
|
280
|
+
const key = fs + "|" + el.tagName + "|" + text.slice(0, 20);
|
|
281
|
+
if (seen.has(key)) continue;
|
|
282
|
+
seen.add(key);
|
|
283
|
+
out.push({ fontSizePx: fs, sample: text.slice(0, 40), tag: el.tagName.toLowerCase() });
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return out.slice(0, 8);
|
|
287
|
+
}`;
|
|
288
|
+
|
|
289
|
+
// Whole-page mode checks one pseudo-anchor whose selector is `body`.
|
|
290
|
+
if (WHOLE_PAGE) anchors.push("__page__");
|
|
291
|
+
|
|
292
|
+
for (const __route of ROUTES) {
|
|
293
|
+
ROUTE = __route;
|
|
294
|
+
URL = BASE_URL.replace(/\/$/, "") + ROUTE;
|
|
295
|
+
if (ROUTES.length > 1) console.log(JSON.stringify({ type: "route", route: ROUTE }));
|
|
296
|
+
|
|
297
|
+
for (const anchor of anchors) {
|
|
298
|
+
const sel = anchor === "__page__" ? "body" : `#${anchor}`;
|
|
299
|
+
|
|
300
|
+
for (const theme of THEMES) {
|
|
301
|
+
// Reduced motion on the MEASURING pass, deliberately.
|
|
302
|
+
//
|
|
303
|
+
// Without it axe samples elements mid-animation: a skeleton using animate-pulse
|
|
304
|
+
// interpolates opacity 1 to 0.5, so the reading is whatever phase the frame
|
|
305
|
+
// landed on, which is not a design value and differs run to run. Measured in a
|
|
306
|
+
// fork carrying the same code: eight consecutive loads of an UNCHANGED page gave
|
|
307
|
+
// 3, 3, 1, 0, 3, 3, 1, 0 findings, with the same heading reading #919191, #888888
|
|
308
|
+
// and #868686 on different runs. Under reduced motion the same page is clean on
|
|
309
|
+
// four consecutive runs.
|
|
310
|
+
//
|
|
311
|
+
// A gate that reports a different number each night teaches people to re-run it
|
|
312
|
+
// until it is green, which is worse than not having it. check-rendered-contrast
|
|
313
|
+
// already measures this way for the same reason. The dedicated reduced-motion
|
|
314
|
+
// check below opens its own context and is unaffected.
|
|
315
|
+
const { ctx, page } = await openPage(theme, { reducedMotion: "reduce" });
|
|
316
|
+
const el = await page.$(sel);
|
|
317
|
+
if (!el) {
|
|
318
|
+
if (theme === "light") add({ anchor, theme, check: "anchor", severity: "BLOCKER", detail: `anchor ${sel} not found on ${ROUTE}` });
|
|
319
|
+
await ctx.close();
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
await el.scrollIntoViewIfNeeded();
|
|
323
|
+
await page.waitForTimeout(200);
|
|
324
|
+
|
|
325
|
+
// screenshot this theme
|
|
326
|
+
const shot = `${SCREENS_DIR}/${ROUTES.length > 1 ? routeSlug(ROUTE) + "-" : ""}${anchor}-${theme}.png`;
|
|
327
|
+
await el.screenshot({ path: shot }).catch(() => {});
|
|
328
|
+
if (existsSync(shot)) { screenshots.push(shot); console.log(JSON.stringify({ type: "screenshot", anchor, theme, path: shot })); }
|
|
329
|
+
|
|
330
|
+
// 0. subresources that never arrived.
|
|
331
|
+
//
|
|
332
|
+
// Whole-page only: a per-anchor run cannot attribute a page-level request to
|
|
333
|
+
// the anchor it was scoped to, so reporting it there would blame the wrong
|
|
334
|
+
// section. A missing image does not throw — it degrades into whatever is
|
|
335
|
+
// painted underneath, and every contrast reading taken over it is a reading
|
|
336
|
+
// of the wrong thing.
|
|
337
|
+
if (anchor === "__page__") {
|
|
338
|
+
// Deduplicate: Next re-requests the same missing asset per render pass.
|
|
339
|
+
const uniq = [...new Set(page.__failedRequests || [])].filter(
|
|
340
|
+
(u) => !/\/_next\/(static|image)\/|hot-update|__nextjs/.test(u),
|
|
341
|
+
);
|
|
342
|
+
for (const u of uniq) {
|
|
343
|
+
const allowed = MISSING_ASSET_ALLOWLIST.find((a) => u.includes(a.match));
|
|
344
|
+
if (allowed) {
|
|
345
|
+
console.log(JSON.stringify({ type: "allowed", check: "missing-asset", url: u, reason: allowed.reason }));
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
add({
|
|
349
|
+
anchor, theme, check: "missing-asset", severity: "BLOCKER",
|
|
350
|
+
detail: `a subresource the page asks for never arrived: ${u} — a missing image does not throw, it degrades into whatever is painted underneath, which no contrast gate can attribute`,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// 1. axe (scoped)
|
|
356
|
+
await injectAxe(page);
|
|
357
|
+
const violations = await getViolations(page, sel, { runOnly: ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"] })
|
|
358
|
+
.catch((e) => { add({ anchor, theme, check: "axe", severity: "WARN", detail: `axe run failed: ${e.message}` }); return []; });
|
|
359
|
+
for (const v of violations) {
|
|
360
|
+
const blocker = v.impact === "critical" || v.impact === "serious";
|
|
361
|
+
add({ anchor, theme, check: "axe", severity: blocker ? "BLOCKER" : "WARN", rule: v.id, impact: v.impact, nodes: v.nodes.length, detail: v.help });
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// 2. rendered contrast (the dark-on-dark / light-on-white catcher)
|
|
365
|
+
const contrast = await page.evaluate(`(${CONTRAST_PROBE})('${sel}', ${AAA}, ${AA}, ${AA_LARGE})`);
|
|
366
|
+
for (const c of contrast) {
|
|
367
|
+
add({ anchor, theme, check: "contrast", severity: c.severity, ratio: c.ratio, detail: `"${c.sample}" ${c.fg} on ${c.bg} = ${c.ratio}:1 (${c.large ? "large" : "normal"} text, needs ${c.large ? "4.5" : "7"}:1 AAA${c.severity === "BLOCKER" ? "; fails even AA — reads as unreadable" : ""}${c.untrusted ? "; over a gradient/image so bg is estimated — eyeball the screenshot" : ""})` });
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// 5. anchor horizontal overflow
|
|
371
|
+
const overflow = await el.evaluate((n) => ({ overflows: n.scrollWidth > n.clientWidth + 1, by: n.scrollWidth - n.clientWidth }));
|
|
372
|
+
if (overflow.overflows) add({ anchor, theme, check: "overflow-x", severity: "BLOCKER", detail: `anchor overflows its box by ${overflow.by}px (layout break / long-string risk)` });
|
|
373
|
+
|
|
374
|
+
// 6. keyboard focus indicator (WARN)
|
|
375
|
+
const focusables = await page.$$(`${sel} a[href], ${sel} button:not([disabled]), ${sel} [tabindex]:not([tabindex="-1"]), ${sel} input:not([disabled]), ${sel} select:not([disabled])`);
|
|
376
|
+
let noRing = 0;
|
|
377
|
+
for (const f of focusables.slice(0, 12)) {
|
|
378
|
+
const ring = await f.evaluate((n) => {
|
|
379
|
+
n.focus();
|
|
380
|
+
const s = getComputedStyle(n);
|
|
381
|
+
const outline = s.outlineStyle !== "none" && parseFloat(s.outlineWidth) > 0;
|
|
382
|
+
const shadow = s.boxShadow && s.boxShadow !== "none" && /rgb|hsl|oklch/.test(s.boxShadow);
|
|
383
|
+
const ringClass = /focus-visible:ring|focus-visible:outline|focus:ring/.test(n.className || "");
|
|
384
|
+
return outline || shadow || ringClass;
|
|
385
|
+
}).catch(() => true);
|
|
386
|
+
if (!ring) noRing++;
|
|
387
|
+
}
|
|
388
|
+
if (noRing > 0) add({ anchor, theme, check: "focus-ring", severity: "WARN", detail: `${noRing} focusable element(s) with no detectable focus indicator` });
|
|
389
|
+
|
|
390
|
+
await ctx.close();
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// 3. sub-14px rendered text (theme-independent — run once)
|
|
394
|
+
{
|
|
395
|
+
const { ctx, page } = await openPage("light");
|
|
396
|
+
const el = await page.$(sel);
|
|
397
|
+
if (el) {
|
|
398
|
+
await el.scrollIntoViewIfNeeded();
|
|
399
|
+
const tiny = await page.evaluate(`(${SUBFLOOR_PROBE})('${sel}')`);
|
|
400
|
+
for (const t of tiny) add({ anchor, theme: "both", check: "font-size", severity: "HIGH", detail: `"${t.sample}" renders at ${t.fontSizePx}px (below the 14px floor)` });
|
|
401
|
+
}
|
|
402
|
+
await ctx.close();
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// 4. reduced-motion (dark theme happens to exercise the same rule; run once)
|
|
406
|
+
{
|
|
407
|
+
const { ctx, page } = await openPage("light", { reducedMotion: "reduce" });
|
|
408
|
+
const el = await page.$(sel);
|
|
409
|
+
if (el) {
|
|
410
|
+
await el.scrollIntoViewIfNeeded();
|
|
411
|
+
const running = await el.evaluate((root) => {
|
|
412
|
+
const bad = [];
|
|
413
|
+
for (const n of root.querySelectorAll("*")) {
|
|
414
|
+
const s = getComputedStyle(n);
|
|
415
|
+
if (s.animationName !== "none" && parseFloat(s.animationDuration) > 0.05) bad.push({ tag: n.tagName.toLowerCase(), dur: s.animationDuration });
|
|
416
|
+
}
|
|
417
|
+
return bad.slice(0, 5);
|
|
418
|
+
});
|
|
419
|
+
if (running.length) add({ anchor, theme: "both", check: "reduced-motion", severity: "BLOCKER", detail: `${running.length} animation(s) not halted under prefers-reduced-motion`, samples: running });
|
|
420
|
+
}
|
|
421
|
+
await ctx.close();
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
await browser.close();
|
|
427
|
+
|
|
428
|
+
const blockers = findings.filter((f) => f.severity === "BLOCKER");
|
|
429
|
+
const highs = findings.filter((f) => f.severity === "HIGH");
|
|
430
|
+
const warns = findings.filter((f) => f.severity === "WARN");
|
|
431
|
+
console.log(JSON.stringify({
|
|
432
|
+
type: "summary", routes: ROUTES, anchors, themes: THEMES,
|
|
433
|
+
blockers: blockers.length, highs: highs.length, warns: warns.length,
|
|
434
|
+
screenshots, screensDir: SCREENS_DIR,
|
|
435
|
+
verdict: blockers.length ? "FAIL" : "PASS",
|
|
436
|
+
}));
|
|
437
|
+
|
|
438
|
+
process.exit(blockers.length ? 1 : 0);
|
package/scripts/wcag-audit.cjs
CHANGED
|
@@ -118,6 +118,24 @@ const json = process.argv.includes('--json');
|
|
|
118
118
|
const NORMAL_FLOOR = aa ? 4.5 : 7.0;
|
|
119
119
|
const LARGE_FLOOR = aa ? 3.0 : 4.5;
|
|
120
120
|
|
|
121
|
+
// Client-owned mode (.client-identity.json → sourceOfTruth.components ===
|
|
122
|
+
// "client") downgrades AAA (7:1) token-pair failures to warnings — still
|
|
123
|
+
// printed, never failing the build — because a client's own component
|
|
124
|
+
// library is generally built to AA, not AAA, and a red pipeline over a
|
|
125
|
+
// palette BADS didn't choose is a bad way to open that conversation. See
|
|
126
|
+
// docs/superpowers/specs/2026-09-10-client-owned-components-design.md →
|
|
127
|
+
// "Accessibility floor: flag, do not enforce" and CLAUDE.md → Accessibility
|
|
128
|
+
// Floor. readSourceOfTruth() never throws and defaults to "bads" with no
|
|
129
|
+
// identity file, so upstream BADS and "bads"-owned forks are unaffected.
|
|
130
|
+
//
|
|
131
|
+
// Only the AAA invocation downgrades. `--aa` is an explicit request for the
|
|
132
|
+
// real WCAG AA standard (not a BADS house opinion), so it keeps blocking even
|
|
133
|
+
// on a client-owned fork.
|
|
134
|
+
const { readSourceOfTruth } = require('./source-of-truth.cjs');
|
|
135
|
+
const CLIENT_OWNED = readSourceOfTruth(process.cwd()).components === 'client';
|
|
136
|
+
const DOWNGRADE_AAA = CLIENT_OWNED && !aa;
|
|
137
|
+
const CLIENT_OWNED_NOTE = 'warned, not failed: components are client-owned';
|
|
138
|
+
|
|
121
139
|
// ---- color math (oklch → linear sRGB → relative luminance) -------------
|
|
122
140
|
|
|
123
141
|
function clamp(n, min, max) { return Math.min(max, Math.max(min, n)); }
|
|
@@ -480,9 +498,31 @@ for (const r of all) {
|
|
|
480
498
|
// it never matched a real row at all. Reported, never build-failing: see findStaleExceptions.
|
|
481
499
|
const staleExceptions = findStaleExceptions(exceptions, all);
|
|
482
500
|
|
|
501
|
+
// Client-owned degrade: recategorize AAA fails as warns before either output
|
|
502
|
+
// path (json or human-readable) reads `all`, so both report the same
|
|
503
|
+
// downgraded status and the same non-blocking exit code.
|
|
504
|
+
//
|
|
505
|
+
// TEXT pairs only. Non-text pairs are NOT downgraded, because they are not an
|
|
506
|
+
// AAA requirement: NORMAL_FLOOR and LARGE_FLOOR move with `--aa` (7.0/4.5 vs
|
|
507
|
+
// 4.5/3.0) but NON_TEXT_FLOOR is a flat 3.0 in both modes, since SC 1.4.11 is
|
|
508
|
+
// Level AA. Downgrading them would drop a client-owned fork below the real
|
|
509
|
+
// standard while claiming only to relax a BADS house preference — the same
|
|
510
|
+
// reason `--aa` itself is exempt from this block.
|
|
511
|
+
let clientDowngraded = 0;
|
|
512
|
+
if (DOWNGRADE_AAA) {
|
|
513
|
+
for (const r of all) {
|
|
514
|
+
if (r.status === 'fail' && r.kind !== 'non-text') {
|
|
515
|
+
r.status = 'warn';
|
|
516
|
+
r.clientOwned = true;
|
|
517
|
+
clientDowngraded++;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
483
522
|
if (json) {
|
|
484
523
|
console.log(JSON.stringify({
|
|
485
524
|
floor: { normal: NORMAL_FLOOR, large: LARGE_FLOOR },
|
|
525
|
+
clientOwned: CLIENT_OWNED,
|
|
486
526
|
results: all,
|
|
487
527
|
runtimeMutated: brandResults,
|
|
488
528
|
staleExceptions,
|
|
@@ -504,9 +544,10 @@ if (json) {
|
|
|
504
544
|
r.status === 'warn' ? '!' : '·';
|
|
505
545
|
const kind = r.kind === 'non-text' ? ' [non-text]' : '';
|
|
506
546
|
const brandNote = r.brand && r.status !== 'pass' ? ' (brand)' : '';
|
|
547
|
+
const clientNote = r.clientOwned ? ` (${CLIENT_OWNED_NOTE})` : '';
|
|
507
548
|
console.log(
|
|
508
549
|
` ${mark} ${r.label.padEnd(34)} ${String(r.ratio).padStart(5)}:1 ` +
|
|
509
|
-
`${r.fgKey} ${r.fgHex} on ${r.bgKey} ${r.bgHex}${kind}${brandNote}`
|
|
550
|
+
`${r.fgKey} ${r.fgHex} on ${r.bgKey} ${r.bgHex}${kind}${brandNote}${clientNote}`
|
|
510
551
|
);
|
|
511
552
|
}
|
|
512
553
|
console.log('');
|
|
@@ -547,5 +588,12 @@ if (json) {
|
|
|
547
588
|
` the same warning in-product (see CLAUDE.md → Accessibility Floor). Not blocking.`,
|
|
548
589
|
);
|
|
549
590
|
}
|
|
591
|
+
if (clientDowngraded) {
|
|
592
|
+
console.log(
|
|
593
|
+
`\n${clientDowngraded} pair${clientDowngraded === 1 ? '' : 's'} below the AAA floor ${clientDowngraded === 1 ? 'is' : 'are'} ` +
|
|
594
|
+
`${CLIENT_OWNED_NOTE} (sourceOfTruth.components === "client"). Your palette is being held to AA, ` +
|
|
595
|
+
`not AAA — see CLAUDE.md → Accessibility Floor. Not blocking.`,
|
|
596
|
+
);
|
|
597
|
+
}
|
|
550
598
|
if (failed.length) process.exit(1);
|
|
551
599
|
}
|
package/src/api/layers/file.ts
CHANGED
|
@@ -34,6 +34,7 @@ const ALLOWED_ROOT_MD = new Set([
|
|
|
34
34
|
"DESIGN_SYSTEM_STACK.md",
|
|
35
35
|
"ENGINEERING.md",
|
|
36
36
|
"MIGRATION_UNRENAME.md",
|
|
37
|
+
"PRODUCT.md",
|
|
37
38
|
"SECURITY.md",
|
|
38
39
|
"STORYBOOK_RULE.md",
|
|
39
40
|
"V0_SYSTEM.md",
|
|
@@ -47,6 +48,7 @@ function isAllowed(rel: string) {
|
|
|
47
48
|
if (norm === "packages/core/src/tokens.json") return true;
|
|
48
49
|
if (/^layer-[\w-]+\//.test(norm) && /\.(md|json)$/.test(norm)) return true;
|
|
49
50
|
if (/^docs\/[\w.-]+\.md$/.test(norm)) return true;
|
|
51
|
+
if (/^disciplines\/[\w./-]+\.(md|json)$/.test(norm)) return true;
|
|
50
52
|
if (/^prompts\/[\w.-]+\.md$/.test(norm)) return true;
|
|
51
53
|
if (/^\.claude\/skills\/[\w.-]+\/SKILL\.md$/.test(norm)) return true;
|
|
52
54
|
if (/^(ledgers|aggregator|automation|roi)\/README\.md$/.test(norm)) return true;
|