trykeyline-browser 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +14 -2
- package/audit/probe.mjs +390 -0
- package/audit.mjs +209 -0
- package/bin/trykeyline-browser.mjs +79 -0
- package/browse/args.mjs +44 -0
- package/browse/capture.mjs +181 -0
- package/browse/compare.mjs +260 -0
- package/browse/findings.mjs +125 -0
- package/browse/playwright.mjs +78 -0
- package/browse/report.mjs +265 -0
- package/browse/routes.mjs +252 -0
- package/browse/serve.mjs +61 -0
- package/browse/walk.mjs +117 -0
- package/browse.mjs +175 -0
- package/package.json +53 -4
- package/probe.mjs +26 -0
- package/smoke/clicks.mjs +320 -0
- package/smoke/config.mjs +184 -0
- package/smoke/forms.mjs +329 -0
- package/smoke/keyboard.mjs +100 -0
- package/smoke/links.mjs +120 -0
- package/smoke/page.mjs +575 -0
- package/smoke/phone.mjs +126 -0
- package/smoke/shift.mjs +103 -0
- package/smoke/util.mjs +113 -0
- package/smoke.mjs +412 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mihir Modi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# trykeyline-browser
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The browser half of [Keyline](https://github.com/Mihirmodi27/keyline): the audit, the smoke test, and the walk and report under them. It lives in its own package so `trykeyline` and the skill it installs stay small and never pull in Playwright.
|
|
4
|
+
|
|
5
|
+
You don't install it by hand. `npx trykeyline audit|smoke|pages|capture|report|probe` runs this package at the same version, fetching it the first time:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npx trykeyline audit --base http://localhost:3000
|
|
9
|
+
npx trykeyline smoke --serve dist
|
|
10
|
+
npx trykeyline probe audit # the audit's page checks as one expression, for your own browser tool
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Playwright is an optional peer. It's used from your project when it's there; otherwise it's installed once into `~/.cache/keyline` (or `$KEYLINE_CACHE`), and drives your installed Chrome.
|
|
14
|
+
|
|
15
|
+
MIT licence.
|
package/audit/probe.mjs
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The audit's measurements inside a rendered page. `auditProbe` is passed to
|
|
3
|
+
* Playwright's `page.evaluate`, so it must be self-contained: no imports, no
|
|
4
|
+
* closures over this module. It relies on the helpers capture.mjs installs on
|
|
5
|
+
* every page (`__keylineSelector`, `__keylineBox`).
|
|
6
|
+
*
|
|
7
|
+
* It returns raw findings — rule, severity, title, detail, evidence, selector,
|
|
8
|
+
* box, law — and audit.mjs adds the page, viewport, theme and shot. Which
|
|
9
|
+
* checks run depends on the pass: contrast in every theme, target size and
|
|
10
|
+
* overflow at phone width, structure, type, copy and slop once per page.
|
|
11
|
+
*
|
|
12
|
+
* Everything here is a measurement a machine can make. Judgement (hierarchy,
|
|
13
|
+
* grouping, whether a box should exist, whether the copy sounds like the
|
|
14
|
+
* product) is the agent's, from the screenshots, written into the same report.
|
|
15
|
+
*/
|
|
16
|
+
export function auditProbe({ viewport, theme, firstPass, limit = 12 }) {
|
|
17
|
+
const out = [];
|
|
18
|
+
const sel = (el) => window.__keylineSelector?.(el) ?? el.tagName.toLowerCase();
|
|
19
|
+
const box = (el) => window.__keylineBox?.(el) ?? null;
|
|
20
|
+
const push = (f) => out.push(f);
|
|
21
|
+
// The layout width: a phone browser widens innerWidth to fit content that overflows, which would hide the overflow.
|
|
22
|
+
const vw = document.documentElement.clientWidth || window.innerWidth;
|
|
23
|
+
// What the theme actually changed: a page with no dark theme renders the same colours in both passes.
|
|
24
|
+
const bodyCs = getComputedStyle(document.body);
|
|
25
|
+
out.push({ meta: true, signature: `${getComputedStyle(document.documentElement).backgroundColor}|${bodyCs.backgroundColor}|${bodyCs.color}` });
|
|
26
|
+
|
|
27
|
+
const visible = (el) => {
|
|
28
|
+
if (!(el instanceof Element)) return false;
|
|
29
|
+
const r = el.getBoundingClientRect();
|
|
30
|
+
if (r.width <= 2 || r.height <= 2) return false;
|
|
31
|
+
const cs = getComputedStyle(el);
|
|
32
|
+
if (cs.visibility === "hidden" || cs.display === "none" || Number(cs.opacity) === 0) return false;
|
|
33
|
+
// Visually hidden for screen readers (.sr-only and friends): not on screen, so not measured.
|
|
34
|
+
if ((cs.clip && cs.clip !== "auto") || /inset\(50%\)/.test(cs.clipPath)) return false;
|
|
35
|
+
if (el.closest("[aria-hidden='true'], [hidden], [inert]")) return false;
|
|
36
|
+
return true;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/* ── Colour, through a canvas so every CSS colour syntax lands in sRGB ── */
|
|
40
|
+
const canvas = document.createElement("canvas");
|
|
41
|
+
canvas.width = canvas.height = 1;
|
|
42
|
+
const ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
43
|
+
const rgbaCache = new Map();
|
|
44
|
+
const rgba = (str) => {
|
|
45
|
+
if (rgbaCache.has(str)) return rgbaCache.get(str);
|
|
46
|
+
ctx.clearRect(0, 0, 1, 1);
|
|
47
|
+
ctx.fillStyle = "#000";
|
|
48
|
+
ctx.fillStyle = str;
|
|
49
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
50
|
+
const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data;
|
|
51
|
+
const v = str === "transparent" || /rgba?\([^)]*,\s*0\)$/.test(str) ? [0, 0, 0, 0] : [r, g, b, a / 255];
|
|
52
|
+
rgbaCache.set(str, v);
|
|
53
|
+
return v;
|
|
54
|
+
};
|
|
55
|
+
const over = (top, bottom) => {
|
|
56
|
+
const a = top[3] + bottom[3] * (1 - top[3]);
|
|
57
|
+
if (a === 0) return [0, 0, 0, 0];
|
|
58
|
+
return [0, 1, 2].map((i) => (top[i] * top[3] + bottom[i] * bottom[3] * (1 - top[3])) / a).concat(a);
|
|
59
|
+
};
|
|
60
|
+
const lum = ([r, g, b]) => {
|
|
61
|
+
const c = (v) => {
|
|
62
|
+
v /= 255;
|
|
63
|
+
return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
64
|
+
};
|
|
65
|
+
return 0.2126 * c(r) + 0.7152 * c(g) + 0.0722 * c(b);
|
|
66
|
+
};
|
|
67
|
+
const ratio = (a, b) => {
|
|
68
|
+
const [l1, l2] = [lum(a), lum(b)].sort((x, y) => y - x);
|
|
69
|
+
return (l1 + 0.05) / (l2 + 0.05);
|
|
70
|
+
};
|
|
71
|
+
const hex = ([r, g, b]) => "#" + [r, g, b].map((v) => Math.round(v).toString(16).padStart(2, "0")).join("");
|
|
72
|
+
|
|
73
|
+
/** The opaque colour behind an element, or null when an image or gradient is in the way. */
|
|
74
|
+
const background = (el) => {
|
|
75
|
+
let layers = [];
|
|
76
|
+
for (let n = el; n; n = n.parentElement) {
|
|
77
|
+
const cs = getComputedStyle(n);
|
|
78
|
+
if (cs.backgroundImage && cs.backgroundImage !== "none") return null;
|
|
79
|
+
const c = rgba(cs.backgroundColor);
|
|
80
|
+
if (c[3] > 0) layers.push(c);
|
|
81
|
+
if (c[3] >= 1) break;
|
|
82
|
+
}
|
|
83
|
+
let base = rgba(getComputedStyle(document.documentElement).backgroundColor);
|
|
84
|
+
if (base[3] < 1) base = over(base, theme === "dark" ? [0, 0, 0, 1] : [255, 255, 255, 1]);
|
|
85
|
+
for (const c of layers.reverse()) base = over(c, base);
|
|
86
|
+
return base;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/* ── Contrast: every rendered run of text, grouped so one bad style is one finding.
|
|
90
|
+
Measured at desktop width in each theme; the phone pass would only repeat it. ── */
|
|
91
|
+
const groups = new Map();
|
|
92
|
+
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, {
|
|
93
|
+
acceptNode: (t) => (t.textContent.trim().length > 1 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT),
|
|
94
|
+
});
|
|
95
|
+
const textEls = new Set();
|
|
96
|
+
for (let t = walker.nextNode(); t; t = walker.nextNode()) {
|
|
97
|
+
const el = t.parentElement;
|
|
98
|
+
// Text inside a picture (role="img", an SVG) is part of an illustration, not text to read: its alt is what's read.
|
|
99
|
+
if (el && !textEls.has(el) && !["SCRIPT", "STYLE", "NOSCRIPT", "TEMPLATE"].includes(el.tagName) && !el.closest('[role="img"], svg') && visible(el)) textEls.add(el);
|
|
100
|
+
}
|
|
101
|
+
for (const el of viewport === "desktop" ? textEls : []) {
|
|
102
|
+
const cs = getComputedStyle(el);
|
|
103
|
+
let fg = rgba(cs.color);
|
|
104
|
+
let opacity = 1;
|
|
105
|
+
let blended = false;
|
|
106
|
+
for (let n = el; n; n = n.parentElement) {
|
|
107
|
+
const ns = getComputedStyle(n);
|
|
108
|
+
opacity *= Number(ns.opacity);
|
|
109
|
+
if (ns.mixBlendMode !== "normal") blended = true;
|
|
110
|
+
}
|
|
111
|
+
// Blended text (mix-blend-mode: difference over a photo, say) shows a colour no stylesheet names; the agent judges it from the shot.
|
|
112
|
+
if (blended) continue;
|
|
113
|
+
fg = [fg[0], fg[1], fg[2], fg[3] * opacity];
|
|
114
|
+
// Transparent text is a layout or effect layer (a measuring copy, a crossfade's hidden face), not something read.
|
|
115
|
+
if (fg[3] < 0.15) continue;
|
|
116
|
+
const bg = background(el);
|
|
117
|
+
if (!bg) continue;
|
|
118
|
+
const solid = over(fg, bg);
|
|
119
|
+
const r = ratio(solid, bg);
|
|
120
|
+
const size = parseFloat(cs.fontSize);
|
|
121
|
+
const weight = Number(cs.fontWeight) || 400;
|
|
122
|
+
const large = size >= 24 || (size >= 18.66 && weight >= 700);
|
|
123
|
+
const floor = large ? 3 : 4.5;
|
|
124
|
+
if (r >= floor) continue;
|
|
125
|
+
const key = `${hex(solid)}|${hex(bg)}|${Math.round(size)}`;
|
|
126
|
+
const g = groups.get(key) ?? { el, r, floor, fg: hex(solid), bg: hex(bg), size, count: 0, sample: el.textContent.trim().slice(0, 40) };
|
|
127
|
+
g.count++;
|
|
128
|
+
// Point at an instance that's on the page, not one scrolled away inside a carousel.
|
|
129
|
+
const onPage = (n) => {
|
|
130
|
+
const b = n.getBoundingClientRect();
|
|
131
|
+
return b.left >= 0 && b.right <= vw;
|
|
132
|
+
};
|
|
133
|
+
if (!onPage(g.el) && onPage(el)) {
|
|
134
|
+
g.el = el;
|
|
135
|
+
g.sample = el.textContent.trim().slice(0, 40);
|
|
136
|
+
}
|
|
137
|
+
groups.set(key, g);
|
|
138
|
+
}
|
|
139
|
+
[...groups.values()]
|
|
140
|
+
.sort((a, b) => a.r - b.r)
|
|
141
|
+
.slice(0, limit)
|
|
142
|
+
.forEach((g) =>
|
|
143
|
+
push({
|
|
144
|
+
rule: "color/contrast",
|
|
145
|
+
law: "color law 2",
|
|
146
|
+
severity: g.r < 3 ? "error" : "warning",
|
|
147
|
+
title: g.r < 3 ? "Text too faint to read" : "Text below its contrast floor",
|
|
148
|
+
detail: `"${g.sample}" and ${g.count - 1 || "no"} other${g.count === 2 ? "" : "s"} like it: ${g.fg} on ${g.bg} at ${Math.round(g.size)}px.`,
|
|
149
|
+
evidence: `${g.r.toFixed(2)}:1, needs ${g.floor}:1`,
|
|
150
|
+
selector: sel(g.el),
|
|
151
|
+
box: box(g.el),
|
|
152
|
+
}),
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
/* ── Interactive elements: names, targets, labels ── */
|
|
156
|
+
const INTERACTIVE = "a[href], button, input:not([type=hidden]), select, textarea, summary, [role=button], [role=link], [role=tab], [role=menuitem], [role=checkbox], [role=switch], [tabindex]:not([tabindex='-1'])";
|
|
157
|
+
const interactive = [...document.querySelectorAll(INTERACTIVE)].filter((el) => visible(el) && !el.closest('[role="img"]'));
|
|
158
|
+
// Words that are never names, so a label capitalising them is Title Case, not a product name ("Claude Code").
|
|
159
|
+
const COMMON = new Set("a an and the to for of with in on up out now all more new your my our account changes details settings started free demo plan order cart started contact us here view get save add create delete edit remove cancel submit continue next back sign log try start book read learn download upload send open close show hide manage see join buy".split(" "));
|
|
160
|
+
|
|
161
|
+
const labelText = (el) => {
|
|
162
|
+
const ids = el.getAttribute("aria-labelledby");
|
|
163
|
+
if (ids) return ids.split(/\s+/).map((id) => document.getElementById(id)?.textContent ?? "").join(" ").trim();
|
|
164
|
+
if (el.getAttribute("aria-label")) return el.getAttribute("aria-label").trim();
|
|
165
|
+
if (el.matches("input, select, textarea")) {
|
|
166
|
+
const forLabel = el.id && document.querySelector(`label[for="${CSS.escape(el.id)}"]`);
|
|
167
|
+
const wrap = el.closest("label");
|
|
168
|
+
const t = (forLabel?.textContent || wrap?.textContent || "").trim();
|
|
169
|
+
if (t) return t;
|
|
170
|
+
if (["submit", "button", "reset"].includes(el.type)) return el.value?.trim() ?? "";
|
|
171
|
+
return el.getAttribute("title")?.trim() ?? "";
|
|
172
|
+
}
|
|
173
|
+
const text = (el.innerText ?? el.textContent ?? "").trim();
|
|
174
|
+
if (text) return text;
|
|
175
|
+
const img = el.querySelector("img[alt]");
|
|
176
|
+
if (img?.alt.trim()) return img.alt.trim();
|
|
177
|
+
const svgTitle = el.querySelector("svg title");
|
|
178
|
+
if (svgTitle?.textContent.trim()) return svgTitle.textContent.trim();
|
|
179
|
+
return el.getAttribute("title")?.trim() ?? "";
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
if (firstPass) {
|
|
183
|
+
let unnamed = 0;
|
|
184
|
+
let placeholderOnly = 0;
|
|
185
|
+
for (const el of interactive) {
|
|
186
|
+
const name = labelText(el);
|
|
187
|
+
if (!name) {
|
|
188
|
+
if (el.matches("input, textarea") && el.placeholder) {
|
|
189
|
+
if (placeholderOnly++ < limit)
|
|
190
|
+
push({ rule: "copy/placeholder-label", law: "patterns law 16", severity: "warning", title: "A field labelled only by its placeholder", detail: `"${el.placeholder}" vanishes as soon as someone types, and screen readers may not announce it. Give the field a visible label.`, selector: sel(el), box: box(el) });
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (unnamed++ < limit)
|
|
194
|
+
push({ rule: "a11y/name", law: "patterns law 1", severity: "error", title: "A control with no name", detail: "A screen reader announces it as just its role. Give it visible text, or an aria-label naming what it does.", evidence: `<${el.tagName.toLowerCase()}${el.getAttribute("role") ? ` role="${el.getAttribute("role")}"` : ""}>`, selector: sel(el), box: box(el) });
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const label = name.replace(/\s+/g, " ");
|
|
198
|
+
if (/^(click here|here|learn more|read more|more|submit|ok|go|link)$/i.test(label)) {
|
|
199
|
+
push({ rule: "copy/vague-label", law: "patterns law 1", severity: "warning", title: `"${label}" doesn't say what happens`, detail: "Name the action or the destination: Save changes, View pricing, Read the case study.", selector: sel(el), box: box(el) });
|
|
200
|
+
} else if (el.matches("button, [role=button], input[type=submit]") && /^([A-Z][a-z']+)( [A-Z][a-z']+){1,4}$/.test(label) && label.split(" ").slice(1).some((w) => COMMON.has(w.toLowerCase()))) {
|
|
201
|
+
push({ rule: "copy/title-case", law: "patterns law 1", severity: "info", title: `"${label}" is in Title Case`, detail: "Labels read faster in sentence case: only the first word and names capitalised.", selector: sel(el), box: box(el) });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (unnamed > limit) push({ rule: "a11y/name", law: "patterns law 1", severity: "error", title: `${unnamed - limit} more controls with no name`, evidence: `${unnamed} in all` });
|
|
205
|
+
|
|
206
|
+
const imgs = [...document.querySelectorAll("img")].filter((i) => visible(i) && !i.hasAttribute("alt"));
|
|
207
|
+
imgs.slice(0, limit).forEach((i) => push({ rule: "a11y/img-alt", law: "patterns law 14", severity: "error", title: "An image with no alt text", detail: "Say what it's for (\"Sign-ups doubled in March\"), or alt=\"\" if it's decoration.", evidence: (i.currentSrc || i.src).split("/").pop()?.slice(0, 60), selector: sel(i), box: box(i) }));
|
|
208
|
+
|
|
209
|
+
if (!document.documentElement.lang) push({ rule: "a11y/lang", severity: "warning", title: "The page doesn't declare its language", detail: "Add lang to <html> so screen readers pronounce it and browsers offer translation correctly." });
|
|
210
|
+
if (!document.querySelector("main, [role=main]")) push({ rule: "a11y/landmarks", law: "layout law 12", severity: "warning", title: "No main landmark", detail: "Wrap the page's content in <main>, so keyboard and screen-reader users can jump straight to it." });
|
|
211
|
+
const h1s = [...document.querySelectorAll("h1")].filter(visible);
|
|
212
|
+
if (!h1s.length) push({ rule: "a11y/headings", law: "type law 3", severity: "warning", title: "No top-level heading", detail: "The page has no visible h1; screen-reader users navigate by headings and start from it." });
|
|
213
|
+
if (h1s.length > 1) push({ rule: "a11y/headings", law: "type law 3", severity: "info", title: `${h1s.length} top-level headings`, detail: "One h1 names the page; the rest are h2 and below.", selector: sel(h1s[1]), box: box(h1s[1]) });
|
|
214
|
+
let prev = 0;
|
|
215
|
+
for (const h of [...document.querySelectorAll("h1, h2, h3, h4, h5, h6")].filter(visible)) {
|
|
216
|
+
const level = Number(h.tagName[1]);
|
|
217
|
+
if (prev && level > prev + 1) {
|
|
218
|
+
push({ rule: "a11y/headings", law: "type law 3", severity: "info", title: `Heading jumps from h${prev} to h${level}`, detail: `"${h.textContent.trim().slice(0, 50)}" skips a level, so the outline a screen reader builds has a hole.`, selector: sel(h), box: box(h) });
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
prev = level;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (viewport === "phone" && theme === "light") {
|
|
226
|
+
const rects = interactive.map((el) => el.getBoundingClientRect());
|
|
227
|
+
const centre = (r) => [r.left + r.width / 2, r.top + r.height / 2];
|
|
228
|
+
const small = new Map();
|
|
229
|
+
interactive.forEach((el, i) => {
|
|
230
|
+
const r = rects[i];
|
|
231
|
+
if (r.width >= 24 && r.height >= 24) return;
|
|
232
|
+
const cs = getComputedStyle(el);
|
|
233
|
+
// A link inside running text is exempt (WCAG 2.5.8): its size is the text's.
|
|
234
|
+
if (cs.display === "inline" && el.parentElement && el.parentElement.textContent.trim().length > el.textContent.trim().length + 20) return;
|
|
235
|
+
// So is a small target with room around it: no other target's centre within 24px of its own.
|
|
236
|
+
const [cx, cy] = centre(r);
|
|
237
|
+
const crowded = rects.some((o, j) => {
|
|
238
|
+
if (j === i) return false;
|
|
239
|
+
const [ox, oy] = centre(o);
|
|
240
|
+
return Math.abs(ox - cx) < 24 && Math.abs(oy - cy) < 24;
|
|
241
|
+
});
|
|
242
|
+
if (!crowded) return;
|
|
243
|
+
const key = `${Math.round(r.width)}x${Math.round(r.height)}|${el.parentElement?.tagName}.${el.parentElement?.className}`;
|
|
244
|
+
const g = small.get(key) ?? { el, r, n: 0 };
|
|
245
|
+
g.n++;
|
|
246
|
+
small.set(key, g);
|
|
247
|
+
});
|
|
248
|
+
[...small.values()].slice(0, limit).forEach((g) =>
|
|
249
|
+
push({ rule: "a11y/target-size", law: "layout law 13", severity: "warning", title: g.n > 1 ? `${g.n} tap targets too small and too close together` : "A tap target too small and too close to its neighbours", detail: "Under 24×24px on a phone, with another target within reach of a thumb. Pad the hit area (padding or a pseudo-element) without changing the look.", evidence: `${Math.round(g.r.width)}×${Math.round(g.r.height)}px`, selector: sel(g.el), box: box(g.el) }),
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
const meta = document.querySelector('meta[name="viewport"]')?.content ?? "";
|
|
253
|
+
if (!/width\s*=\s*device-width/.test(meta))
|
|
254
|
+
push({ rule: "layout/viewport-meta", law: "layout law 8", severity: "error", title: "The page isn't set up for phones", detail: "Without <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">, phones render it at desktop width and shrink it to fit, so every size on it is too small to read.", evidence: meta ? `content="${meta}"` : "no viewport meta tag" });
|
|
255
|
+
|
|
256
|
+
const doc = document.documentElement;
|
|
257
|
+
if (doc.scrollWidth > vw + 1) {
|
|
258
|
+
const wide = [...document.body.querySelectorAll("*")].filter((el) => {
|
|
259
|
+
const r = el.getBoundingClientRect();
|
|
260
|
+
if (r.right <= vw + 1 || !visible(el)) return false;
|
|
261
|
+
const p = el.parentElement?.getBoundingClientRect();
|
|
262
|
+
return !p || p.right <= vw + 1;
|
|
263
|
+
});
|
|
264
|
+
push({ rule: "layout/horizontal-overflow", law: "layout law 8", severity: "error", title: "The page scrolls sideways on a phone", detail: wide.length ? `It starts at ${sel(wide[0])}${wide.length > 1 ? ` and ${wide.length - 1} more` : ""}.` : "Something is wider than the screen.", evidence: `${doc.scrollWidth}px wide in a ${vw}px viewport`, selector: wide[0] ? sel(wide[0]) : undefined, box: wide[0] ? box(wide[0]) : undefined });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/* ── Text cut off without an ellipsis ── */
|
|
269
|
+
if (theme === "light") {
|
|
270
|
+
let clipped = 0;
|
|
271
|
+
for (const el of textEls) {
|
|
272
|
+
const cs = getComputedStyle(el);
|
|
273
|
+
if (!/hidden|clip/.test(cs.overflowX + cs.overflow) || cs.textOverflow === "ellipsis") continue;
|
|
274
|
+
if (el.scrollWidth <= el.clientWidth + 2 && el.scrollHeight <= el.clientHeight + 2) continue;
|
|
275
|
+
if (cs.webkitLineClamp && cs.webkitLineClamp !== "none") continue;
|
|
276
|
+
if (clipped++ < 4)
|
|
277
|
+
push({ rule: "layout/clipped-text", law: "layout law 8", severity: "warning", title: "Text is cut off", detail: `"${el.textContent.trim().slice(0, 50)}" overflows a box that hides it, with no ellipsis to say there's more.`, selector: sel(el), box: box(el) });
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (firstPass) {
|
|
282
|
+
/* ── Type: the ladder as rendered ── */
|
|
283
|
+
const sizes = new Map();
|
|
284
|
+
const weights = new Set();
|
|
285
|
+
let tiny = 0;
|
|
286
|
+
for (const el of textEls) {
|
|
287
|
+
const cs = getComputedStyle(el);
|
|
288
|
+
const s = Math.round(parseFloat(cs.fontSize) * 2) / 2;
|
|
289
|
+
sizes.set(s, (sizes.get(s) ?? 0) + 1);
|
|
290
|
+
weights.add(Number(cs.fontWeight) || 400);
|
|
291
|
+
if (s < 12 && !el.closest("sup, sub, svg") && tiny++ < 3)
|
|
292
|
+
push({ rule: "type/tiny-text", law: "type law 1", severity: "warning", title: "Text below the 12px floor", detail: `"${el.textContent.trim().slice(0, 40)}" is set at ${s}px.`, evidence: `${s}px`, selector: sel(el), box: box(el) });
|
|
293
|
+
}
|
|
294
|
+
// Display sizes (32px and up) are their own tier; the ladder is what sits under them.
|
|
295
|
+
const ladder = [...sizes.keys()].filter((s) => s < 32).sort((a, b) => a - b);
|
|
296
|
+
if (ladder.length > 8)
|
|
297
|
+
push({ rule: "type/many-sizes", law: "type law 1", severity: "warning", title: `${ladder.length} text sizes below the display tier`, detail: "A scale nobody chose. Assign each size to a role and fold the strays onto the ladder.", evidence: ladder.join(", ") + "px" });
|
|
298
|
+
if (weights.size > 3)
|
|
299
|
+
push({ rule: "type/many-weights", law: "type law 5", severity: "warning", title: `${weights.size} font weights on one page`, detail: "Two weights, each with one job, read as a system; four read as four templates.", evidence: [...weights].sort().join(", ") });
|
|
300
|
+
for (const p of [...document.querySelectorAll("p, li")].filter((el) => visible(el) && el.textContent.trim().length > 240)) {
|
|
301
|
+
const cs = getComputedStyle(p);
|
|
302
|
+
const perLine = p.getBoundingClientRect().width / (parseFloat(cs.fontSize) * 0.5);
|
|
303
|
+
if (perLine > 95) {
|
|
304
|
+
push({ rule: "type/long-measure", law: "layout law 1", severity: "warning", title: "Lines too long to read comfortably", detail: "Running text past ~80 characters a line makes the eye lose its place on the return sweep. Cap the column.", evidence: `≈ ${Math.round(perLine)} characters a line`, selector: sel(p), box: box(p) });
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/* ── Copy: words that read as unfinished, cute or vague ── */
|
|
310
|
+
// Copy is read from the page minus its illustrations.
|
|
311
|
+
const pictureText = [...document.querySelectorAll('[role="img"]')].map((n) => n.innerText).filter(Boolean);
|
|
312
|
+
const bodyText = pictureText.reduce((text, p) => text.replace(p, ""), document.body.innerText);
|
|
313
|
+
const say = (re, rule, severity, title, detail, law) => {
|
|
314
|
+
const m = bodyText.match(re);
|
|
315
|
+
if (m) push({ rule, law, severity, title, detail, evidence: `"${m[0].trim().slice(0, 80)}"` });
|
|
316
|
+
};
|
|
317
|
+
say(/lorem ipsum[^.]{0,40}|\bTODO\b|\bTBD\b|\[object Object\]|\bundefined\b|\bNaN\b/i, "copy/placeholder-text", "error", "Placeholder or broken text on the page", "Leftover filler, or a value that failed to render.", "patterns law 14");
|
|
318
|
+
say(/\b(oops|whoops|uh[- ]oh)\b[^.!\n]{0,60}/i, "copy/interjection", "warning", "An interjection where a plain message belongs", "Say what happened and what to do; \"Oops\" sounds insincere at the worst moment.", "patterns law 18");
|
|
319
|
+
say(/\bwe('re| are) (having trouble|sorry|unable)[^.!\n]{0,50}|\bwe (couldn't|can't|could not|were unable to|weren't able to)\b[^.!\n]{0,50}/i, "copy/we", "warning", "\"We\" in an error message", "The reader can't tell who \"we\" is. Name what happened to the thing: \"Couldn't load the report\".", "patterns law 18");
|
|
320
|
+
say(/\bsuccessfully\b[^.!\n]{0,40}/i, "copy/successfully", "info", "\"Successfully\" in a message", "The outcome is the message: \"Project created\", not \"Project successfully created\".", "patterns law 18");
|
|
321
|
+
if (viewport === "phone") say(/\bclick (here|on|the|to)\b[^.!\n]{0,40}/i, "copy/device-verb", "info", "\"Click\" on a touch layout", "Use \"tap\" on touch, or \"select\"/\"open\" where both apply.", "patterns law 18");
|
|
322
|
+
|
|
323
|
+
/* ── AI slop: the tells of a page nobody designed ── */
|
|
324
|
+
const slop = (rule, title, detail, evidence, el, severity = "warning", law) =>
|
|
325
|
+
push({ rule, law, severity, title, detail, evidence, selector: el ? sel(el) : undefined, box: el ? box(el) : undefined });
|
|
326
|
+
|
|
327
|
+
const generic = bodyText.match(/\b(unlock the (full )?power|supercharge|revolutioni[sz]e|next[- ]level|seamless(ly)?|elevate your|game[- ]chang(er|ing)|cutting[- ]edge|all[- ]in[- ]one (platform|solution)|in (just )?(a few )?(seconds|minutes)|built for the future|harness the power|effortless(ly)?|empower(s|ing)? (you|teams))\b/gi);
|
|
328
|
+
if (generic?.length) slop("slop/generic-copy", "Stock marketing phrases", "These lines could sit on any product's page. Say what this one does, for whom, in its own nouns.", [...new Set(generic.map((g) => g.toLowerCase()))].slice(0, 5).join(", "), null, "warning", "patterns law 18");
|
|
329
|
+
|
|
330
|
+
const brands = bodyText.match(/\b(Acme( Corp| Inc)?|Globex|Initech|Hooli|Umbrella Corp|Contoso|Lorem Co)\b/);
|
|
331
|
+
if (brands) slop("slop/placeholder-brands", "Placeholder company names", "Logos or testimonials from companies that don't exist read as fake social proof.", brands[0], null, "warning");
|
|
332
|
+
|
|
333
|
+
let gradientText = null;
|
|
334
|
+
let purple = null;
|
|
335
|
+
let glass = 0;
|
|
336
|
+
let emoji = 0;
|
|
337
|
+
let emojiEl = null;
|
|
338
|
+
let eyebrows = 0;
|
|
339
|
+
for (const el of document.body.querySelectorAll("*")) {
|
|
340
|
+
if (!visible(el)) continue;
|
|
341
|
+
const cs = getComputedStyle(el);
|
|
342
|
+
if (cs.backdropFilter && cs.backdropFilter !== "none") glass++;
|
|
343
|
+
const img = cs.backgroundImage;
|
|
344
|
+
if (img && img.includes("gradient")) {
|
|
345
|
+
if (!gradientText && (cs.backgroundClip === "text" || cs.webkitBackgroundClip === "text")) gradientText = el;
|
|
346
|
+
const r = el.getBoundingClientRect();
|
|
347
|
+
if (!purple && r.width > vw * 0.6 && r.height > 240) {
|
|
348
|
+
const hues = [...img.matchAll(/rgba?\((\d+),\s*(\d+),\s*(\d+)/g)].map(([, r, g, b]) => {
|
|
349
|
+
const [R, G, B] = [r, g, b].map((v) => v / 255);
|
|
350
|
+
const max = Math.max(R, G, B);
|
|
351
|
+
const min = Math.min(R, G, B);
|
|
352
|
+
if (max - min < 0.2) return null;
|
|
353
|
+
const h = max === R ? ((G - B) / (max - min)) % 6 : max === G ? (B - R) / (max - min) + 2 : (R - G) / (max - min) + 4;
|
|
354
|
+
return (h * 60 + 360) % 360;
|
|
355
|
+
});
|
|
356
|
+
if (hues.some((h) => h !== null && h >= 245 && h <= 300)) purple = el;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
if (/^(LI|H2|H3|H4|P|BUTTON|A|SPAN)$/.test(el.tagName) && el.children.length <= 2 && /^\s*\p{Extended_Pictographic}/u.test(el.textContent)) {
|
|
360
|
+
emoji++;
|
|
361
|
+
emojiEl ??= el;
|
|
362
|
+
}
|
|
363
|
+
if (cs.textTransform === "uppercase" && parseFloat(cs.letterSpacing) > parseFloat(cs.fontSize) * 0.05 && parseFloat(cs.fontSize) <= 14) {
|
|
364
|
+
const next = el.nextElementSibling;
|
|
365
|
+
if (next && /^H[1-4]$/.test(next.tagName)) eyebrows++;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (gradientText) slop("slop/gradient-text", "Gradient-filled headline text", "A signature of generated landing pages; it also drops contrast where the gradient goes light. Set the headline in ink and let the words carry it.", null, gradientText, "warning", "color law 7");
|
|
369
|
+
if (purple) slop("slop/purple-gradient", "A large purple gradient panel", "The default \"AI product\" hero. Use the brand's own colour, or none.", null, purple, "warning", "color law 7");
|
|
370
|
+
if (glass > 4) slop("slop/glass-everywhere", "Frosted glass on many surfaces", "Translucency is for chrome over moving content. On everything it's texture, and it costs every frame.", `${glass} elements with backdrop-filter`, null, "warning", "depth law 10");
|
|
371
|
+
if (emoji >= 3) slop("slop/emoji-bullets", "Emoji used as icons or bullets", "Emoji at the start of headings and list items read as generated. Use the product's icon set, or nothing.", `${emoji} elements`, emojiEl, "info");
|
|
372
|
+
if (eyebrows >= 3) slop("slop/eyebrows", "An uppercase eyebrow over every heading", "Spaced capitals above each section heading is a template habit; let the heading open the section.", `${eyebrows} headings`, null, "info", "type dials");
|
|
373
|
+
|
|
374
|
+
// Many same-styled bordered or shadowed siblings: the card grid that boxes everything.
|
|
375
|
+
for (const parent of document.body.querySelectorAll("*")) {
|
|
376
|
+
const kids = [...parent.children].filter(visible);
|
|
377
|
+
if (kids.length < 6) continue;
|
|
378
|
+
const cls = kids[0].className;
|
|
379
|
+
if (typeof cls !== "string" || !cls || !kids.every((k) => k.className === cls)) continue;
|
|
380
|
+
const cs = getComputedStyle(kids[0]);
|
|
381
|
+
const boxed = (parseFloat(cs.borderTopWidth) > 0 || cs.boxShadow !== "none") && parseFloat(cs.borderTopLeftRadius) > 0;
|
|
382
|
+
if (boxed && !parent.matches("ul[role=listbox], table, tbody, nav")) {
|
|
383
|
+
slop("slop/card-grid", "A grid of identical boxed cards", "Every item in its own bordered card reads as a template. Sit the items on the page, parted by space or hairlines; keep a card for one object taken in whole.", `${kids.length} cards`, parent, "info", "depth law 2");
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return out;
|
|
390
|
+
}
|
package/audit.mjs
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The audit's machine half: walk every page of a running product at desktop
|
|
3
|
+
* and phone, light and dark; measure contrast, names, targets, overflow, the
|
|
4
|
+
* type actually rendered, copy and the tells of AI slop inside each page; add
|
|
5
|
+
* the detector's findings from the source; draft a score per domain; write
|
|
6
|
+
* keyline-report/ (findings.json, index.html, shots/).
|
|
7
|
+
*
|
|
8
|
+
* The agent's half follows (commands/audit.md): look at the shots, add the
|
|
9
|
+
* findings only judgement can make, settle the scores, write the summary, and
|
|
10
|
+
* re-render with `keyline report`.
|
|
11
|
+
*
|
|
12
|
+
* keyline audit --base http://localhost:3000 [--root .]
|
|
13
|
+
* keyline audit --serve dist
|
|
14
|
+
* keyline audit --base … --quick [--routes /pricing] one page, the quick read
|
|
15
|
+
*
|
|
16
|
+
* Exit codes: 0 done, 1 errors found, 2 a usage error.
|
|
17
|
+
*/
|
|
18
|
+
import { existsSync, rmSync } from "node:fs";
|
|
19
|
+
import { resolve } from "node:path";
|
|
20
|
+
import { add, counts, writeRun } from "./browse/findings.mjs";
|
|
21
|
+
import { shotKey } from "./browse/capture.mjs";
|
|
22
|
+
import { renderDir } from "./browse/report.mjs";
|
|
23
|
+
import { walk } from "./browse/walk.mjs";
|
|
24
|
+
import { parseOrExplain } from "./browse/args.mjs";
|
|
25
|
+
import { target } from "./browse.mjs";
|
|
26
|
+
import { auditProbe } from "./audit/probe.mjs";
|
|
27
|
+
import { check } from "trykeyline/check";
|
|
28
|
+
import { DOMAINS } from "trykeyline/check/rules";
|
|
29
|
+
|
|
30
|
+
const USAGE = `keyline audit — every page, measured, in one report.
|
|
31
|
+
|
|
32
|
+
keyline audit (--base URL | --serve DIR) [options]
|
|
33
|
+
|
|
34
|
+
Options:
|
|
35
|
+
--base <url> the running product
|
|
36
|
+
--serve <dir> serve a static folder instead
|
|
37
|
+
--root <dir> the project's code: routes, and the detector (default: .)
|
|
38
|
+
--out <dir> where the report goes (default: keyline-report)
|
|
39
|
+
--routes <a,b> only these paths
|
|
40
|
+
--limit <n> at most this many pages (default 40)
|
|
41
|
+
--title <name> the product's name, in the report's heading
|
|
42
|
+
--quick one page (the first route, or /), desktop and phone, light only
|
|
43
|
+
--no-check skip the source detector
|
|
44
|
+
--motion leave motion on (default: reduced, so pages are shot settled)
|
|
45
|
+
--headed show the browser
|
|
46
|
+
-h, --help this`;
|
|
47
|
+
|
|
48
|
+
/** The six law domains the scores are kept for, and where the audit's own rules fall among them. */
|
|
49
|
+
export const SCORED = DOMAINS;
|
|
50
|
+
const SCORE_DOMAIN = {
|
|
51
|
+
a11y: "patterns",
|
|
52
|
+
copy: "patterns",
|
|
53
|
+
states: "patterns",
|
|
54
|
+
runtime: "patterns",
|
|
55
|
+
"a11y/target-size": "layout",
|
|
56
|
+
"a11y/headings": "type",
|
|
57
|
+
"color/contrast": "color",
|
|
58
|
+
"slop/gradient-text": "color",
|
|
59
|
+
"slop/purple-gradient": "color",
|
|
60
|
+
"slop/glass-everywhere": "depth",
|
|
61
|
+
"slop/card-grid": "depth",
|
|
62
|
+
"slop/eyebrows": "type",
|
|
63
|
+
"slop/emoji-bullets": "patterns",
|
|
64
|
+
"slop/generic-copy": "patterns",
|
|
65
|
+
"slop/placeholder-brands": "patterns",
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const FIX = {
|
|
69
|
+
type: "/keyline type",
|
|
70
|
+
color: "/keyline color",
|
|
71
|
+
layout: "/keyline layout",
|
|
72
|
+
depth: "/keyline depth",
|
|
73
|
+
motion: "/keyline motion",
|
|
74
|
+
patterns: "/keyline patterns",
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export function scoreDomain(f) {
|
|
78
|
+
const domain = f.domain ?? f.rule.split("/")[0];
|
|
79
|
+
return SCORE_DOMAIN[f.rule] ?? (SCORED.includes(domain) ? domain : SCORE_DOMAIN[domain] ?? "patterns");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A draft score per domain from the findings: 4 with nothing to report, down
|
|
84
|
+
* by each distinct rule broken (an error 1.5, a warning 0.75, a note 0.15),
|
|
85
|
+
* plus up to 1 more for how many places break it. The agent settles the
|
|
86
|
+
* real score; the draft keeps a mechanical floor under the judgement.
|
|
87
|
+
*/
|
|
88
|
+
export function draftScores(findings) {
|
|
89
|
+
const scores = {};
|
|
90
|
+
for (const d of SCORED) {
|
|
91
|
+
const rules = new Map();
|
|
92
|
+
for (const f of findings) {
|
|
93
|
+
if (f.status === "dismissed" || f.status === "fixed" || scoreDomain(f) !== d) continue;
|
|
94
|
+
const w = f.severity === "error" ? 1.5 : f.severity === "warning" ? 0.75 : 0.15;
|
|
95
|
+
const r = rules.get(f.rule) ?? { w: 0, n: 0 };
|
|
96
|
+
rules.set(f.rule, { w: Math.max(r.w, w), n: r.n + 1 });
|
|
97
|
+
}
|
|
98
|
+
// Each rule broken costs its weight once, plus a little for how widely it's broken.
|
|
99
|
+
const penalty = [...rules.values()].reduce((sum, r) => sum + r.w + Math.min(1, (r.n - 1) * 0.1), 0);
|
|
100
|
+
scores[d] = Math.max(0, Math.min(4, Math.round(4 - penalty)));
|
|
101
|
+
}
|
|
102
|
+
return scores;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The detector's findings, as report findings pointing at source lines. Its walk already skips reports, dependencies and build output. */
|
|
106
|
+
export function sourceFindings(run, root, ignores = []) {
|
|
107
|
+
const result = check({ root, paths: ["."], ignores });
|
|
108
|
+
for (const f of result.findings) {
|
|
109
|
+
const [title, ...rest] = f.message.split(/(?<=\.)\s+/);
|
|
110
|
+
add(run, {
|
|
111
|
+
kind: "check",
|
|
112
|
+
rule: f.rule,
|
|
113
|
+
domain: f.domain,
|
|
114
|
+
law: f.law,
|
|
115
|
+
severity: f.severity,
|
|
116
|
+
title: title.replace(/\.$/, ""),
|
|
117
|
+
detail: rest.join(" ") || undefined,
|
|
118
|
+
file: f.file,
|
|
119
|
+
line: f.line,
|
|
120
|
+
fix: FIX[f.domain],
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const AUDIT_OPTIONS = {
|
|
127
|
+
values: ["base", "serve", "root", "out", "routes", "limit", "title"],
|
|
128
|
+
switches: ["quick", "no-check", "motion", "headed"],
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export async function run(argv) {
|
|
132
|
+
const opts = parseOrExplain("audit", argv, AUDIT_OPTIONS);
|
|
133
|
+
if (!opts) return 2;
|
|
134
|
+
if (opts._.length) {
|
|
135
|
+
console.error(`keyline audit: no command '${opts._[0]}' (try --help)`);
|
|
136
|
+
return 2;
|
|
137
|
+
}
|
|
138
|
+
if (opts.help) {
|
|
139
|
+
console.log(USAGE);
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
const t = await target(opts);
|
|
143
|
+
if (!t) {
|
|
144
|
+
console.error("audit needs --base <url> or --serve <dir>\n");
|
|
145
|
+
console.error(USAGE);
|
|
146
|
+
return 2;
|
|
147
|
+
}
|
|
148
|
+
const out = resolve(opts.out ?? "keyline-report");
|
|
149
|
+
if (existsSync(`${out}/shots`)) rmSync(`${out}/shots`, { recursive: true });
|
|
150
|
+
const quick = Boolean(opts.quick);
|
|
151
|
+
const routes = opts.routes ? String(opts.routes).split(",").map((s) => s.trim()) : quick ? ["/"] : null;
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
const signatures = new Map();
|
|
155
|
+
const result = await walk({
|
|
156
|
+
kind: "audit",
|
|
157
|
+
title: opts.title ?? null,
|
|
158
|
+
base: t.base,
|
|
159
|
+
root: t.root,
|
|
160
|
+
out,
|
|
161
|
+
routes: quick ? routes.slice(0, 1) : routes,
|
|
162
|
+
limit: quick ? 1 : Number(opts.limit ?? 40),
|
|
163
|
+
viewports: ["desktop", "phone"],
|
|
164
|
+
themes: quick ? ["light"] : ["light", "dark"],
|
|
165
|
+
headless: !opts.headed,
|
|
166
|
+
// Shot and measured as a reader sees the page once it settles: opening sequences and
|
|
167
|
+
// scroll reveals done. --motion audits with motion on, as a first visit plays it.
|
|
168
|
+
reducedMotion: !opts.motion,
|
|
169
|
+
// Structure, type, copy and slop are measured once per page, on the first (desktop, light) pass.
|
|
170
|
+
probeFor: (viewport, theme) => [{ name: "audit", fn: auditProbe, arg: { viewport, theme, firstPass: viewport === "desktop" && theme === "light" } }],
|
|
171
|
+
judge: (run, v) => {
|
|
172
|
+
const raw = v.results.audit;
|
|
173
|
+
// A page without a dark theme renders the same colours in the dark pass; skip its repeats.
|
|
174
|
+
const meta = Array.isArray(raw) ? raw.find((f) => f.meta) : null;
|
|
175
|
+
if (meta) {
|
|
176
|
+
const key = `${v.route}|${v.viewport}`;
|
|
177
|
+
if (v.theme === "light") signatures.set(key, meta.signature);
|
|
178
|
+
else if (signatures.get(key) === meta.signature) return;
|
|
179
|
+
}
|
|
180
|
+
if (!Array.isArray(raw)) {
|
|
181
|
+
if (raw?.error) add(run, { rule: "runtime/probe-failed", severity: "info", title: "The audit's checks couldn't run on this page", evidence: raw.error, page: v.route, viewport: v.viewport, theme: v.theme });
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
for (const f of raw.filter((f) => !f.meta)) {
|
|
185
|
+
add(run, {
|
|
186
|
+
...f,
|
|
187
|
+
kind: "audit",
|
|
188
|
+
page: v.route,
|
|
189
|
+
viewport: v.viewport,
|
|
190
|
+
theme: v.theme,
|
|
191
|
+
shot: v.shot && f.box ? shotKey(v.viewport, v.theme) : undefined,
|
|
192
|
+
fix: f.fix ?? FIX[scoreDomain(f)],
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
if (!opts["no-check"] && t.root && existsSync(t.root)) sourceFindings(result, t.root);
|
|
199
|
+
result.scores = draftScores(result.findings);
|
|
200
|
+
result.scoresDraft = true;
|
|
201
|
+
writeRun(out, result);
|
|
202
|
+
const file = renderDir(out);
|
|
203
|
+
const c = counts(result.findings);
|
|
204
|
+
console.log(`\n${result.pages.length} ${result.pages.length === 1 ? "page" : "pages"} · ${c.error} errors · ${c.warning} warnings · ${c.info} notes\n${file}`);
|
|
205
|
+
return c.error ? 1 : 0;
|
|
206
|
+
} finally {
|
|
207
|
+
await t.stop();
|
|
208
|
+
}
|
|
209
|
+
}
|