@marktiderman/genesis-cli 1.28.0 → 1.29.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/dist/verify.js ADDED
@@ -0,0 +1,549 @@
1
+ // src/verify/dom.ts
2
+ async function domChecks(opts) {
3
+ const findings = [];
4
+ const vw = document.documentElement.clientWidth;
5
+ const vh = window.innerHeight;
6
+ const nameOf = (el) => {
7
+ const label = el.getAttribute("aria-label") ?? el.innerText ?? el.textContent ?? "";
8
+ const text = label.replace(/\s+/g, " ").replace(/"/g, "'").trim();
9
+ return text.length > 48 ? `${text.slice(0, 28)}\u2026${text.slice(-19)}` : text;
10
+ };
11
+ const describe = (el) => {
12
+ const parts = [];
13
+ let node = el;
14
+ while (node && node !== document.body && parts.length < 4) {
15
+ let part = node.tagName.toLowerCase();
16
+ const slot = node.getAttribute("data-slot");
17
+ const testId = node.getAttribute("data-testid");
18
+ if (node.id && !/^radix-|^_r_|:/.test(node.id)) part += `#${node.id}`;
19
+ else if (testId) part += `[data-testid="${testId}"]`;
20
+ else if (slot) part += `[data-slot="${slot}"]`;
21
+ else if (node.parentElement) {
22
+ const same = Array.from(node.parentElement.children).filter((c) => c.tagName === node.tagName);
23
+ if (same.length > 1) part += `:nth-of-type(${same.indexOf(node) + 1})`;
24
+ }
25
+ parts.unshift(part);
26
+ if (node.id && !/^radix-|^_r_|:/.test(node.id) || testId) break;
27
+ node = node.parentElement;
28
+ }
29
+ const name = nameOf(el);
30
+ return name ? `${parts.join(" > ")} "${name}"` : parts.join(" > ");
31
+ };
32
+ const hidden = (el, allowTiny = false) => {
33
+ if (el.closest("[inert], [aria-hidden='true']")) return true;
34
+ const style = getComputedStyle(el);
35
+ const visible = el.checkVisibility?.({ opacityProperty: true, visibilityProperty: true });
36
+ if (visible === false) return true;
37
+ if (style.visibility === "hidden" || style.display === "none" || Number(style.opacity) === 0) return true;
38
+ const rect = el.getBoundingClientRect();
39
+ if (rect.width === 0 || rect.height === 0) return true;
40
+ if (allowTiny) return false;
41
+ if (rect.width <= 1 && rect.height <= 1) return true;
42
+ return /rect\(0(px)?,? ?0(px)?,? ?0(px)?,? ?0(px)?\)/.test(style.clip) || /inset\(50%\)/.test(style.clipPath);
43
+ };
44
+ const overflowX = (el) => getComputedStyle(el).overflowX;
45
+ const scrolls = (el) => ["auto", "scroll"].includes(overflowX(el));
46
+ const clips = (el) => ["hidden", "clip"].includes(overflowX(el));
47
+ const isFixed = (el) => ["fixed", "sticky"].includes(getComputedStyle(el).position);
48
+ const offscreen = (r) => r.right <= 0 || r.left >= vw || r.bottom <= 0 || r.top >= vh;
49
+ const paints = (el) => {
50
+ const s = getComputedStyle(el);
51
+ return !/rgba\(.*,\s*0\)|transparent/.test(s.backgroundColor) || s.backdropFilter !== "none" || s.backgroundImage !== "none";
52
+ };
53
+ const WIDE_CONTENT = "table, pre, code, [role='grid'], [role='table'], [role='treegrid'], [role='tablist'], [role='toolbar'], canvas, svg, iframe, video, img, [data-scroll-frame]";
54
+ const saved = /* @__PURE__ */ new Map();
55
+ for (const el of Array.from(document.querySelectorAll("*"))) if (el.scrollTop || el.scrollLeft) saved.set(el, [el.scrollTop, el.scrollLeft]);
56
+ const winScroll = [window.scrollX, window.scrollY];
57
+ const parkedOffCanvas = (el) => {
58
+ for (let a = el; a && a !== document.body; a = a.parentElement) {
59
+ if (getComputedStyle(a).position !== "fixed") continue;
60
+ const ar = a.getBoundingClientRect();
61
+ return ar.left >= vw || ar.right <= 0;
62
+ }
63
+ return false;
64
+ };
65
+ const intoView = (el) => {
66
+ const r = el.getBoundingClientRect();
67
+ if (r.bottom > 0 && r.top < vh && r.right > 0 && r.left < vw) return r;
68
+ el.scrollIntoView({ block: "center", inline: "nearest", behavior: "instant" });
69
+ return el.getBoundingClientRect();
70
+ };
71
+ const meta = document.querySelector("meta[name='viewport']")?.content ?? "";
72
+ for (const [part, rule] of [
73
+ [/width\s*=\s*device-width/, "width=device-width"],
74
+ [/viewport-fit\s*=\s*cover/, "viewport-fit=cover (rule 7)"],
75
+ [/interactive-widget\s*=\s*resizes-content/, "interactive-widget=resizes-content (rule 6)"]
76
+ ])
77
+ if (!part.test(meta)) findings.push({ check: "viewport-meta", target: 'meta[name="viewport"]', message: `viewport meta lacks ${rule} ("${meta}")` });
78
+ let coarse = opts.coarse;
79
+ if (opts.coarse && !(matchMedia("(pointer: coarse)").matches && matchMedia("(hover: none)").matches)) {
80
+ findings.push({
81
+ check: "touch-media",
82
+ level: "info",
83
+ message: `touch is on but (pointer: coarse) is ${matchMedia("(pointer: coarse)").matches} and (hover: none) is ${matchMedia("(hover: none)").matches} in this engine; coarse-pointer checks skipped`
84
+ });
85
+ coarse = false;
86
+ }
87
+ const root = document.scrollingElement ?? document.documentElement;
88
+ if (root.scrollWidth > root.clientWidth + 1)
89
+ findings.push({ check: "reflow", target: "html", message: `the page scrolls sideways: ${root.scrollWidth}px wide in a ${root.clientWidth}px viewport` });
90
+ for (const scroller of Array.from(document.querySelectorAll("[data-slot='shell-main'], [data-slot='shell-frame'], main"))) {
91
+ if (scroller.scrollWidth > scroller.clientWidth + 1 && !hidden(scroller))
92
+ findings.push({ check: "reflow", target: describe(scroller).replace(/ ".*"$/, ""), message: `the page scroller is ${scroller.scrollWidth}px wide in ${scroller.clientWidth}px` });
93
+ }
94
+ const offenders = [];
95
+ for (const el of Array.from(document.body.querySelectorAll("*"))) {
96
+ const rect = el.getBoundingClientRect();
97
+ if (rect.right <= vw + 1 && rect.left >= -1) continue;
98
+ if (hidden(el)) continue;
99
+ if (parkedOffCanvas(el)) continue;
100
+ let frame = null;
101
+ for (let a = el.parentElement; a && a !== document.documentElement; a = a.parentElement) {
102
+ if (a !== document.body && (scrolls(a) || clips(a))) {
103
+ frame = a;
104
+ break;
105
+ }
106
+ }
107
+ if (frame && scrolls(frame)) {
108
+ const wide = el.closest(WIDE_CONTENT);
109
+ if (wide && frame.contains(wide) || frame.matches("[data-scroll-frame]")) continue;
110
+ }
111
+ if (frame && clips(frame) && frame.matches("td, th, [role='cell'], [role='gridcell'], [role='columnheader'], [role='rowheader']")) {
112
+ const table = frame.closest("table, [role='grid'], [role='table'], [role='treegrid']");
113
+ let scroller = table?.parentElement ?? null;
114
+ while (scroller && scroller !== document.body && !scrolls(scroller)) scroller = scroller.parentElement;
115
+ if (table && scroller && scroller !== document.body) continue;
116
+ }
117
+ if (offenders.some((o) => o.el.contains(el))) continue;
118
+ for (let i = offenders.length - 1; i >= 0; i--) if (el.contains(offenders[i].el)) offenders.splice(i, 1);
119
+ offenders.push({ el, how: frame && clips(frame) ? `cut off by ${describe(frame)}` : "outside a frame that scrolls it" });
120
+ }
121
+ for (const { el, how } of offenders) {
122
+ const rect = el.getBoundingClientRect();
123
+ findings.push({ check: "reflow", target: describe(el), message: `runs past the ${vw}px viewport (${Math.round(rect.left)}..${Math.round(rect.right)}px), ${how}` });
124
+ }
125
+ if (coarse) {
126
+ const controls = Array.from(
127
+ document.querySelectorAll(
128
+ "button, [role='button'], [role='switch'], [role='checkbox'], [role='radio'], [role='tab'], [role='menuitem'], input[type='checkbox'], input[type='radio'], a[href]"
129
+ )
130
+ );
131
+ for (const el of controls) {
132
+ if (el.tagName === "INPUT" && (el.closest("label") || el.id && document.querySelector(`label[for="${CSS.escape(el.id)}"]`))) {
133
+ const label = el.closest("label") ?? document.querySelector(`label[for="${CSS.escape(el.id)}"]`);
134
+ if (!hidden(label)) {
135
+ const size2 = label.getBoundingClientRect();
136
+ if (size2.width >= 44 && size2.height >= 44) {
137
+ const r2 = intoView(label);
138
+ const left = Math.max(r2.left, 0);
139
+ const right = Math.min(r2.right, vw);
140
+ const top = Math.max(r2.top, 0);
141
+ const bottom = Math.min(r2.bottom, vh);
142
+ const cx2 = (left + right) / 2;
143
+ const cy2 = (top + bottom) / 2;
144
+ const room = right - left >= 44 && bottom - top >= 44;
145
+ const points = [[cx2, cy2], [cx2 - 21, cy2], [cx2 + 21, cy2], [cx2, cy2 - 21], [cx2, cy2 + 21]].filter(([x, y]) => x >= 0 && y >= 0 && x < vw && y < vh);
146
+ const reaches = room && points.length === 5 && points.every(([x, y]) => {
147
+ const hit = document.elementFromPoint(x, y);
148
+ return !!hit && (label.contains(hit) || el.contains(hit) || hit === el);
149
+ });
150
+ if (reaches) continue;
151
+ }
152
+ }
153
+ }
154
+ if (hidden(el)) continue;
155
+ if (el.tagName === "A") {
156
+ const block = el.parentElement;
157
+ const own = (el.textContent ?? "").trim();
158
+ const around = (block?.textContent ?? "").replace(own, "").trim();
159
+ if (getComputedStyle(el).display === "inline" && around.length > 0) continue;
160
+ }
161
+ const size = el.getBoundingClientRect();
162
+ if (parkedOffCanvas(el)) continue;
163
+ let w = size.width;
164
+ let h = size.height;
165
+ for (const pseudo of ["::before", "::after"]) {
166
+ const s = getComputedStyle(el, pseudo);
167
+ if (s.content === "none" || s.position !== "absolute") continue;
168
+ w = Math.max(w, parseFloat(s.width) || 0);
169
+ h = Math.max(h, parseFloat(s.height) || 0);
170
+ }
171
+ if (w < 44 || h < 44) {
172
+ findings.push({ check: "hit-area", target: describe(el), message: `hit area ${Math.round(w)}\xD7${Math.round(h)}px, under 44\xD744 on a coarse pointer` });
173
+ continue;
174
+ }
175
+ const r = intoView(el);
176
+ if (r.right <= 0 || r.left >= vw || r.bottom <= 0 || r.top >= vh) continue;
177
+ const cx = r.left + r.width / 2;
178
+ const cy = r.top + r.height / 2;
179
+ const stolen = [
180
+ [cx - 21, cy],
181
+ [cx + 21, cy],
182
+ [cx, cy - 21],
183
+ [cx, cy + 21]
184
+ ].filter(([x, y]) => x >= 0 && y >= 0 && x < vw && y < vh).find(([x, y]) => {
185
+ const hit = document.elementFromPoint(x, y);
186
+ return !hit || !(el.contains(hit) || hit === el);
187
+ });
188
+ if (stolen) {
189
+ const hit = document.elementFromPoint(stolen[0], stolen[1]);
190
+ findings.push({
191
+ check: "hit-area",
192
+ target: describe(el),
193
+ message: `44px hit area is cut back: a tap ${Math.round(stolen[0] - cx)},${Math.round(stolen[1] - cy)}px from its centre lands on ${hit ? describe(hit) : "nothing"}`
194
+ });
195
+ }
196
+ }
197
+ }
198
+ if (opts.textZoom) {
199
+ for (const el of Array.from(document.body.querySelectorAll("*"))) {
200
+ if (!clips(el) && !["hidden", "clip"].includes(getComputedStyle(el).overflowY)) continue;
201
+ if (hidden(el)) continue;
202
+ const s = getComputedStyle(el);
203
+ const clamp = s.getPropertyValue("-webkit-line-clamp");
204
+ if (s.textOverflow === "ellipsis" || clamp && clamp !== "none") continue;
205
+ if (el.closest("[data-scroll-frame], pre, code")) continue;
206
+ const hasText = Array.from(el.childNodes).some((n) => n.nodeType === 3 && n.textContent.trim()) || !!el.querySelector("p, span, label, h1, h2, h3, h4, li, td, button, a");
207
+ if (!hasText) continue;
208
+ const clipsY = ["hidden", "clip"].includes(s.overflowY);
209
+ if (clipsY && el.scrollHeight > el.clientHeight + 2 || clips(el) && el.scrollWidth > el.clientWidth + 2)
210
+ findings.push({ check: "text-clipped", target: describe(el), message: `at 200% text, ${el.scrollWidth}\xD7${el.scrollHeight}px of content is cut to ${el.clientWidth}\xD7${el.clientHeight}px` });
211
+ }
212
+ }
213
+ if (opts.phone) {
214
+ const floating = /* @__PURE__ */ new Set();
215
+ for (const el of Array.from(document.querySelectorAll("button, a[href], [role='button']"))) {
216
+ if (hidden(el)) continue;
217
+ let box = el;
218
+ while (box && getComputedStyle(box).position !== "fixed") box = box.parentElement;
219
+ if (!box) continue;
220
+ if (box.closest("[role='dialog'], [role='alertdialog'], [role='menu'], [role='listbox']")) continue;
221
+ const r = box.getBoundingClientRect();
222
+ if (offscreen(r) || r.width >= vw * 0.6) continue;
223
+ floating.add(box);
224
+ }
225
+ if (floating.size > 1)
226
+ findings.push({
227
+ check: "floating-controls",
228
+ target: Array.from(floating).map(describe).join(", "),
229
+ message: `${floating.size} floating controls on a phone; at most one (rule 9)`
230
+ });
231
+ }
232
+ const before = document.activeElement;
233
+ const selector = "a[href], button:not([disabled]), input:not([disabled]):not([type='hidden']), select:not([disabled]), textarea:not([disabled]), summary, iframe, [contenteditable]:not([contenteditable='false']), [tabindex]:not([tabindex='-1'])";
234
+ const all = Array.from(document.querySelectorAll(selector)).filter((el) => !hidden(el, true));
235
+ const main = document.querySelector("main");
236
+ const ordered = main ? [...all.filter((el) => main.contains(el)), ...all.filter((el) => !main.contains(el))] : all;
237
+ const bars = Array.from(document.querySelectorAll("*")).filter((el) => isFixed(el) && !hidden(el) && paints(el));
238
+ for (const el of ordered.slice(0, opts.maxFocus)) {
239
+ el.focus({ preventScroll: true });
240
+ if (document.activeElement !== el) continue;
241
+ el.scrollIntoView({ block: "nearest", inline: "nearest", behavior: "instant" });
242
+ const r = el.getBoundingClientRect();
243
+ if (r.width <= 1 || r.height <= 1 || offscreen(r)) continue;
244
+ const ownPointer = [el.style.getPropertyValue("pointer-events"), el.style.getPropertyPriority("pointer-events")];
245
+ el.style.setProperty("pointer-events", "auto", "important");
246
+ const points = [
247
+ [r.left + r.width / 2, r.top + r.height / 2],
248
+ [r.left + 1, r.top + 1],
249
+ [r.right - 1, r.top + 1],
250
+ [r.left + 1, r.bottom - 1],
251
+ [r.right - 1, r.bottom - 1]
252
+ ].filter(([x, y]) => x >= 0 && y >= 0 && x < vw && y < vh);
253
+ let coveredBy = null;
254
+ const covered = points.length > 0 && points.every(([x, y]) => {
255
+ const hit = document.elementFromPoint(x, y);
256
+ let bar = hit;
257
+ while (bar && !isFixed(bar)) bar = bar.parentElement;
258
+ if (hit && (el.contains(hit) || hit.contains(el))) bar = null;
259
+ if (!bar || bar.contains(el)) {
260
+ bar = bars.find((b) => {
261
+ if (b.contains(el) || el.contains(b) || getComputedStyle(b).pointerEvents !== "none") return false;
262
+ const br = b.getBoundingClientRect();
263
+ if (x < br.left || x > br.right || y < br.top || y > br.bottom) return false;
264
+ const before2 = b.style.getPropertyValue("pointer-events");
265
+ const priority = b.style.getPropertyPriority("pointer-events");
266
+ b.style.setProperty("pointer-events", "auto", "important");
267
+ const top = document.elementFromPoint(x, y);
268
+ if (before2) b.style.setProperty("pointer-events", before2, priority);
269
+ else b.style.removeProperty("pointer-events");
270
+ return !!top && b.contains(top);
271
+ }) ?? null;
272
+ }
273
+ if (bar) coveredBy = bar;
274
+ return !!bar;
275
+ });
276
+ if (ownPointer[0]) el.style.setProperty("pointer-events", ownPointer[0], ownPointer[1]);
277
+ else el.style.removeProperty("pointer-events");
278
+ if (covered && coveredBy) findings.push({ check: "focus-obscured", target: describe(el), message: `focused, it is hidden under ${describe(coveredBy)}` });
279
+ el.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", code: "Escape", bubbles: true }));
280
+ }
281
+ document.activeElement?.blur?.();
282
+ if (before && before !== document.body) before.focus({ preventScroll: true });
283
+ for (const el of Array.from(document.querySelectorAll("*"))) {
284
+ const [top, left] = saved.get(el) ?? [0, 0];
285
+ if (el.scrollTop !== top || el.scrollLeft !== left) el.scrollTo({ top, left, behavior: "instant" });
286
+ }
287
+ window.scrollTo({ left: winScroll[0], top: winScroll[1], behavior: "instant" });
288
+ await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
289
+ return findings;
290
+ }
291
+
292
+ // src/verify/page.ts
293
+ var AXE_TAGS = ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"];
294
+ var AT_REST = "*, *::before, *::after { animation: none !important; transition: none !important; caret-color: transparent !important; }";
295
+ async function zoomText(page) {
296
+ const cdp = await page.context().newCDPSession(page);
297
+ await cdp.send("Page.enable");
298
+ await cdp.send("Page.setFontSizes", { fontSizes: { standard: 32, fixed: 26 } });
299
+ }
300
+ async function checkPage(page, opts) {
301
+ await page.addStyleTag({ content: AT_REST });
302
+ await page.waitForFunction(() => document.getAnimations().every((a) => a.playState !== "running"), void 0, { timeout: 2e3 }).catch(() => {
303
+ });
304
+ const findings = [];
305
+ const { default: AxeBuilder } = await import('@axe-core/playwright');
306
+ let axe = new AxeBuilder({ page }).withTags(AXE_TAGS);
307
+ if (opts.disableAxeRules?.length) axe = axe.disableRules(opts.disableAxeRules);
308
+ for (const sel of opts.axeExclude ?? []) axe = axe.exclude(sel);
309
+ const { violations } = await axe.analyze();
310
+ for (const v of violations) {
311
+ for (const node of v.nodes) {
312
+ const selector = node.target.map(String).join(" ");
313
+ const bare = /^[a-z][a-z0-9-]*$/.test(selector.trim());
314
+ const target = /#(?:radix-|_r_|_R_)/.test(selector) || bare ? await stableTarget(page, selector) : selector;
315
+ if (v.id === "target-size" && opts.viewport.touch && await hasTouchTarget(page, selector)) continue;
316
+ findings.push({ check: "axe", rule: v.id, target, message: `${v.help} (${v.impact ?? "n/a"})` });
317
+ }
318
+ }
319
+ const dom = await page.evaluate(domChecks, {
320
+ phone: opts.viewport.phone,
321
+ coarse: opts.viewport.touch,
322
+ maxFocus: opts.maxFocus ?? 60,
323
+ textZoom: opts.viewport.textZoom
324
+ });
325
+ for (const f of dom) if (!(opts.skipMeta && f.check === "viewport-meta")) findings.push(f);
326
+ return findings;
327
+ }
328
+ async function stableTarget(page, selector) {
329
+ return page.evaluate((sel) => {
330
+ const el = document.querySelector(sel);
331
+ if (!el) return sel;
332
+ const part = (n) => {
333
+ const slot = n.getAttribute("data-slot");
334
+ const testId = n.getAttribute("data-testid");
335
+ const role = n.getAttribute("role");
336
+ const tag = n.tagName.toLowerCase();
337
+ return testId ? `${tag}[data-testid="${testId}"]` : slot ? `${tag}[data-slot="${slot}"]` : role ? `${tag}[role="${role}"]` : tag;
338
+ };
339
+ const parent = el.parentElement && el.parentElement !== document.body ? `${part(el.parentElement)} > ` : "";
340
+ const label = (el.getAttribute("aria-label") ?? el.innerText ?? "").replace(/\s+/g, " ").replace(/"/g, "'").trim();
341
+ const name = label.length > 48 ? `${label.slice(0, 28)}\u2026${label.slice(-19)}` : label;
342
+ return `${parent}${part(el)}${name ? ` "${name}"` : ""}`;
343
+ }, selector).catch(() => selector);
344
+ }
345
+ async function hasTouchTarget(page, selector) {
346
+ return page.evaluate((sel) => {
347
+ const el = document.querySelector(sel);
348
+ if (!el || !matchMedia("(pointer: coarse)").matches) return false;
349
+ const big = ["::before", "::after"].some((p) => {
350
+ const s = getComputedStyle(el, p);
351
+ return s.content !== "none" && s.position === "absolute" && parseFloat(s.width) >= 44 && parseFloat(s.height) >= 44;
352
+ });
353
+ if (!big) return false;
354
+ const scrolled = [];
355
+ for (let a = el.parentElement; a; a = a.parentElement) scrolled.push([a, a.scrollTop, a.scrollLeft]);
356
+ const win = [window.scrollX, window.scrollY];
357
+ el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" });
358
+ const r = el.getBoundingClientRect();
359
+ const cx = r.left + r.width / 2;
360
+ const cy = r.top + r.height / 2;
361
+ const reaches = [[cx - 21, cy], [cx + 21, cy], [cx, cy - 21], [cx, cy + 21]].every(([x, y]) => {
362
+ const hit = document.elementFromPoint(x, y);
363
+ return !!hit && (hit === el || el.contains(hit));
364
+ });
365
+ for (const [a, top, left] of scrolled) if (a.scrollTop !== top || a.scrollLeft !== left) a.scrollTo({ top, left, behavior: "instant" });
366
+ window.scrollTo({ left: win[0], top: win[1], behavior: "instant" });
367
+ return reaches;
368
+ }, selector).catch(() => false);
369
+ }
370
+
371
+ // src/verify/matrix.ts
372
+ var ENGINES = ["chromium", "webkit", "firefox"];
373
+ var WIDTHS = [320, 375, 768, 1024, 1280, 1440];
374
+ var HEIGHTS = { 320: 640, 375: 812, 768: 1024, 1024: 768, 1280: 800, 1440: 900 };
375
+ function widthViewport(width) {
376
+ return { name: String(width), width, height: HEIGHTS[width] ?? 900, touch: width <= 768, phone: width < 640 };
377
+ }
378
+ var ZOOM_VIEWPORTS = [
379
+ { name: "zoom-200", width: 640, height: 512, touch: false, phone: false },
380
+ { name: "zoom-400", width: 320, height: 256, touch: false, phone: true }
381
+ ];
382
+ var TEXT_ZOOM_VIEWPORT = { name: "text-200", width: 1280, height: 800, touch: false, phone: false, textZoom: true };
383
+ function allViewports(widths = WIDTHS) {
384
+ return [...widths.map(widthViewport), ...ZOOM_VIEWPORTS, TEXT_ZOOM_VIEWPORT];
385
+ }
386
+ function runsIn(viewport, engine) {
387
+ return !viewport.textZoom || engine === "chromium";
388
+ }
389
+ function contextOptions(viewport, engine) {
390
+ return {
391
+ viewport: { width: viewport.width, height: viewport.height },
392
+ hasTouch: viewport.touch,
393
+ // Playwright doesn't support isMobile in Firefox; hasTouch alone there, and the touch-media
394
+ // finding reports when (pointer: coarse) doesn't follow.
395
+ isMobile: viewport.touch && engine !== "firefox",
396
+ reducedMotion: "reduce"
397
+ };
398
+ }
399
+
400
+ // src/verify/routes.ts
401
+ var clean = (path) => `/${path.split("/").filter(Boolean).join("/")}`;
402
+ var join = (base, path) => path.startsWith("/") ? clean(path) : clean(`${base}/${path}`);
403
+ function flattenReactRouterRoutes(routes, base = "") {
404
+ const out = [];
405
+ for (const r of routes) {
406
+ const full = r.path !== void 0 ? join(base, r.path) : base || "/";
407
+ if (r.children?.length) {
408
+ if (r.path !== void 0 && !r.children.some((c) => c.index)) out.push({ pattern: full || "/", id: r.id });
409
+ out.push(...flattenReactRouterRoutes(r.children, full));
410
+ } else out.push({ pattern: full || "/", id: r.id });
411
+ }
412
+ return out;
413
+ }
414
+ function segmentRegex(seg) {
415
+ const parts = seg.split(/([:$][A-Za-z_][\w-]*)/);
416
+ const body = parts.map((part) => /^[:$][A-Za-z_]/.test(part) ? "[^/]+" : part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("");
417
+ return new RegExp(`^${body}$`);
418
+ }
419
+ function matchesPattern(pattern, path) {
420
+ const segs = pattern.split("/").filter(Boolean);
421
+ const parts = path.split("/").filter(Boolean);
422
+ const walk = (i, j) => {
423
+ if (i === segs.length) return j === parts.length;
424
+ const seg = segs[i];
425
+ if (seg === "*" || seg === "$") return true;
426
+ const optional = seg.endsWith("?");
427
+ const name = optional ? seg.slice(0, -1) : seg;
428
+ if (j < parts.length && segmentRegex(name).test(parts[j]) && walk(i + 1, j + 1)) return true;
429
+ return optional && walk(i + 1, j);
430
+ };
431
+ return walk(0, 0);
432
+ }
433
+ function rank(pattern) {
434
+ const segs = pattern.split("/");
435
+ let score = segs.length;
436
+ if (segs.includes("*") || segs.includes("$")) score -= 2;
437
+ for (const raw of segs) {
438
+ if (raw === "*" || raw === "$") continue;
439
+ const seg = raw.endsWith("?") ? raw.slice(0, -1) : raw;
440
+ if (seg === "") score += 1;
441
+ else if (/^[:$][A-Za-z_][\w-]*$/.test(seg)) score += 3;
442
+ else if (/[:$][A-Za-z_]/.test(seg)) score += 3.5;
443
+ else score += 10;
444
+ }
445
+ return score;
446
+ }
447
+ function patternFor(path, patterns) {
448
+ return patterns.filter((p) => matchesPattern(p.pattern, path)).sort((a, b) => rank(b.pattern) - rank(a.pattern))[0];
449
+ }
450
+ function onePathPerPattern(paths, patterns) {
451
+ const seen = /* @__PURE__ */ new Set();
452
+ return paths.filter((path) => {
453
+ const key = patternFor(path, patterns)?.pattern ?? path;
454
+ if (seen.has(key)) return false;
455
+ seen.add(key);
456
+ return true;
457
+ });
458
+ }
459
+
460
+ // src/verify/allow.ts
461
+ function matchesPage(pattern, page) {
462
+ if (pattern.startsWith("story:") || page.startsWith("story:")) return pattern.endsWith("*") ? page.startsWith(pattern.slice(0, -1)) : pattern === page;
463
+ return pattern === page || matchesPattern(pattern, page);
464
+ }
465
+ var UNSTABLE = /:nth-(?:of-type|child)\(\d+\)|#(?:radix-|_r_|_R_)[^\s.[:#>]*|\[(?!(?:data-slot|data-testid|role|type|name)[=\]])[\w-]+(?:[~|^$*]?=(?:"[^"]*"|'[^']*'|[^\]]*))?\]/g;
466
+ function targetParts(target) {
467
+ const named = /\s("[^"]*")$/.exec(target);
468
+ const path = named ? target.slice(0, named.index) : target;
469
+ const parts = path.split(">").map((p) => p.replace(UNSTABLE, "").trim()).filter(Boolean);
470
+ return { parts, name: named?.[1] };
471
+ }
472
+ var ARIA_LABEL = /\[aria-label(?:[~|^$*]?=(?:"[^"]*"|'[^']*'|[^\]]*))?\]/g;
473
+ function rawParts(target) {
474
+ const named = /\s("[^"]*")$/.exec(target);
475
+ return (named ? target.slice(0, named.index) : target).split(">").map((p) => p.trim()).filter(Boolean);
476
+ }
477
+ function matchesTarget(entryTarget, findingTarget) {
478
+ if (!findingTarget) return false;
479
+ const found = targetParts(findingTarget);
480
+ if (/^"[^"]*"$/.test(entryTarget)) return found.name === entryTarget;
481
+ const want = targetParts(entryTarget);
482
+ if (want.name && want.name !== found.name) return false;
483
+ if (!want.parts.length || want.parts.length > found.parts.length) return false;
484
+ const tail = found.parts.slice(-want.parts.length);
485
+ if (!want.parts.every((p, i) => p === tail[i])) return false;
486
+ const wantRaw = rawParts(entryTarget);
487
+ const foundRaw = rawParts(findingTarget).slice(-wantRaw.length);
488
+ return wantRaw.every((p, i) => (p.match(ARIA_LABEL) ?? []).every((label) => (foundRaw[i] ?? "").includes(label)));
489
+ }
490
+ function covers(e, finding, where) {
491
+ return e.check === finding.check && (e.rule === void 0 || e.rule === finding.rule) && matchesPage(e.page, where.page) && (!e.viewports || e.viewports.includes(where.viewport)) && (!e.engines || e.engines.includes(where.engine)) && (e.target === void 0 || matchesTarget(e.target, finding.target));
492
+ }
493
+ function allowFor(entries, finding, where) {
494
+ return entries.find((e) => e.target !== void 0 && covers(e, finding, where)) ?? entries.find((e) => e.target === void 0 && covers(e, finding, where));
495
+ }
496
+ function patternCovers(base, pattern) {
497
+ const b = base.split("/").filter(Boolean);
498
+ const p = pattern.split("/").filter(Boolean);
499
+ const isParam = (s) => /^[:$][A-Za-z_]/.test(s);
500
+ const walk = (i, j) => {
501
+ if (i < b.length && (b[i] === "*" || b[i] === "$")) return true;
502
+ if (j === p.length) return b.slice(i).every((s) => s.endsWith("?"));
503
+ if (i === b.length) return false;
504
+ const bs = b[i];
505
+ const ps = p[j];
506
+ if (ps === "*" || ps === "$") return false;
507
+ const bOpt = bs.endsWith("?");
508
+ const pOpt = ps.endsWith("?");
509
+ const bName = bOpt ? bs.slice(0, -1) : bs;
510
+ const pName = pOpt ? ps.slice(0, -1) : ps;
511
+ const plainParam = /^[:$][A-Za-z_][\w-]*$/.test(bName);
512
+ const segment = plainParam ? true : /[:$]/.test(pName) ? bName === pName : isParam(bName) ? matchesPattern(`/${bName}`, `/${pName}`) : bName === pName;
513
+ if (segment && (bOpt || !pOpt) && walk(i + 1, j + 1)) return true;
514
+ return bOpt && walk(i + 1, j);
515
+ };
516
+ return walk(0, 0);
517
+ }
518
+ function entryCovers(base, e) {
519
+ const within = (wide, narrow) => !wide || !!narrow && narrow.every((x) => wide.includes(x));
520
+ const story = base.page.startsWith("story:") || e.page.startsWith("story:");
521
+ const pageIn = story ? base.page === e.page || base.page.endsWith("*") && e.page.startsWith(base.page.slice(0, -1)) && !(e.page.endsWith("*") && e.page.length < base.page.length) : patternCovers(base.page, e.page);
522
+ const targetIn = base.target === void 0 || e.target !== void 0 && (base.target === e.target || matchesTarget(base.target, e.target));
523
+ return base.check === e.check && (base.rule === void 0 || base.rule === e.rule) && pageIn && within(base.viewports, e.viewports) && within(base.engines, e.engines) && targetIn;
524
+ }
525
+ function applyAllow(entries, findings, where) {
526
+ const allowed = [];
527
+ const notes = [];
528
+ const failing = [];
529
+ for (const finding of findings) {
530
+ if (finding.level === "info") {
531
+ notes.push(finding);
532
+ continue;
533
+ }
534
+ const entry = allowFor(entries, finding, where);
535
+ if (entry) allowed.push({ finding, entry });
536
+ else failing.push(finding);
537
+ }
538
+ return { allowed, notes, failing };
539
+ }
540
+ function validateAllow(entries) {
541
+ return entries.flatMap((e, i) => e.reason?.trim() ? [] : [`allow entry ${i} (${e.check} on ${e.page}) has no reason`]);
542
+ }
543
+ function formatFinding(f) {
544
+ return `${f.check}${f.rule ? `/${f.rule}` : ""}${f.target ? ` at ${f.target}` : ""}: ${f.message}`;
545
+ }
546
+
547
+ export { AXE_TAGS, ENGINES, TEXT_ZOOM_VIEWPORT, WIDTHS, ZOOM_VIEWPORTS, allViewports, allowFor, applyAllow, checkPage, contextOptions, domChecks, entryCovers, flattenReactRouterRoutes, formatFinding, matchesPage, matchesPattern, matchesTarget, onePathPerPattern, patternCovers, patternFor, runsIn, targetParts, validateAllow, widthViewport, zoomText };
548
+ //# sourceMappingURL=verify.js.map
549
+ //# sourceMappingURL=verify.js.map