@sloppy-ai/verify 1.1.0 → 1.4.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/accessibility.mjs +118 -4
- package/motion-interactions.mjs +463 -0
- package/multi-width.mjs +147 -132
- package/package.json +8 -3
- package/tells.mjs +390 -0
package/multi-width.mjs
CHANGED
|
@@ -24,9 +24,9 @@ export async function runMultiWidthVerification(target, options = {}) {
|
|
|
24
24
|
const isUrl = /^https?:\/\//i.test(target);
|
|
25
25
|
|
|
26
26
|
if (!options.staticOnly && isUrl) {
|
|
27
|
-
const launchResult = await tryLaunch();
|
|
27
|
+
const launchResult = options.browser ? { browser: options.browser } : await tryLaunch();
|
|
28
28
|
if (launchResult.browser) {
|
|
29
|
-
return await runBrowserMultiWidth(launchResult.browser, target);
|
|
29
|
+
return await runBrowserMultiWidth(launchResult.browser, target, options);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -34,156 +34,171 @@ export async function runMultiWidthVerification(target, options = {}) {
|
|
|
34
34
|
return runStaticMultiWidthFallback(target);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
async function
|
|
38
|
-
const
|
|
39
|
-
let
|
|
37
|
+
async function checkViewport(browser, target, vp) {
|
|
38
|
+
const found = [];
|
|
39
|
+
let passed = true;
|
|
40
|
+
const page = await browser.newPage({ viewport: { width: vp.width, height: vp.height } });
|
|
40
41
|
|
|
41
42
|
try {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
let vpPassed = true;
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 8000 });
|
|
48
|
-
await page.waitForTimeout(250);
|
|
49
|
-
|
|
50
|
-
// 1. Check Mobile Horizontal Overflow
|
|
51
|
-
const overflow = await page.evaluate(() => {
|
|
52
|
-
const docWidth = document.documentElement.scrollWidth;
|
|
53
|
-
const winWidth = window.innerWidth;
|
|
54
|
-
const hasOverflow = docWidth > winWidth + 1;
|
|
55
|
-
return { hasOverflow, docWidth, winWidth };
|
|
56
|
-
});
|
|
43
|
+
await page.goto(target, { waitUntil: 'domcontentloaded', timeout: 8000 });
|
|
44
|
+
await page.waitForTimeout(250);
|
|
57
45
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
message: `Document width (${overflow.docWidth}px) exceeds viewport (${overflow.winWidth}px) causing horizontal scroll.`,
|
|
66
|
-
confidence: 'high',
|
|
67
|
-
objective: true,
|
|
68
|
-
evidence: {
|
|
69
|
-
kind: 'dom',
|
|
70
|
-
description: `documentElement.scrollWidth ${overflow.docWidth}px > innerWidth ${overflow.winWidth}px`,
|
|
71
|
-
viewport: { width: vp.width, height: vp.height },
|
|
72
|
-
criterion: 'WCAG 1.4.10 Reflow'
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
46
|
+
// 1. Check Mobile Horizontal Overflow
|
|
47
|
+
const overflow = await page.evaluate(() => {
|
|
48
|
+
const docWidth = document.documentElement.scrollWidth;
|
|
49
|
+
const winWidth = window.innerWidth;
|
|
50
|
+
const hasOverflow = docWidth > winWidth + 1;
|
|
51
|
+
return { hasOverflow, docWidth, winWidth };
|
|
52
|
+
});
|
|
76
53
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const rect = el.getBoundingClientRect();
|
|
96
|
-
if (!rect.width || !rect.height) continue;
|
|
97
|
-
const fg = parse(style.color);
|
|
98
|
-
let bg = parse(style.backgroundColor);
|
|
99
|
-
let parent = el;
|
|
100
|
-
while ((!bg || bg[3] === 0) && parent && parent !== document.documentElement) {
|
|
101
|
-
parent = parent.parentElement;
|
|
102
|
-
if (parent) bg = parse(getComputedStyle(parent).backgroundColor);
|
|
103
|
-
}
|
|
104
|
-
if (!fg || !bg) continue;
|
|
105
|
-
const fontSize = Number.parseFloat(style.fontSize) || 16;
|
|
106
|
-
const bold = Number(style.fontWeight) >= 700;
|
|
107
|
-
const minRatio = fontSize >= 24 || (bold && fontSize >= 18.66) ? 3 : 4.5;
|
|
108
|
-
const measured = ratio(fg, bg);
|
|
109
|
-
if (measured < minRatio) defects.push({ ratio: Number(measured.toFixed(2)), minRatio, fontSize, text: text.slice(0, 60) });
|
|
110
|
-
}
|
|
111
|
-
return defects.sort((a, b) => a.ratio - b.ratio).slice(0, 3);
|
|
112
|
-
});
|
|
54
|
+
if (overflow.hasOverflow) {
|
|
55
|
+
passed = false;
|
|
56
|
+
found.push({
|
|
57
|
+
width: vp.width,
|
|
58
|
+
viewportName: vp.name,
|
|
59
|
+
type: 'HORIZONTAL_OVERFLOW',
|
|
60
|
+
severity: 'critical',
|
|
61
|
+
message: `Document width (${overflow.docWidth}px) exceeds viewport (${overflow.winWidth}px) causing horizontal scroll.`,
|
|
62
|
+
confidence: 'high',
|
|
63
|
+
objective: true,
|
|
64
|
+
evidence: {
|
|
65
|
+
kind: 'dom',
|
|
66
|
+
description: `documentElement.scrollWidth ${overflow.docWidth}px > innerWidth ${overflow.winWidth}px`,
|
|
67
|
+
viewport: { width: vp.width, height: vp.height },
|
|
68
|
+
criterion: 'WCAG 1.4.10 Reflow'
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
113
72
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
73
|
+
// 2. Measure rendered text contrast against the nearest painted ancestor.
|
|
74
|
+
const contrastDefects = await page.evaluate(() => {
|
|
75
|
+
const parse = (value) => {
|
|
76
|
+
const match = String(value || '').match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*([\d.]+))?\s*\)/);
|
|
77
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3]), match[4] === undefined ? 1 : Number(match[4])] : null;
|
|
78
|
+
};
|
|
79
|
+
const luminance = ([r, g, b]) => {
|
|
80
|
+
const channel = (v) => { const x = v / 255; return x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4; };
|
|
81
|
+
return channel(r) * 0.2126 + channel(g) * 0.7152 + channel(b) * 0.0722;
|
|
82
|
+
};
|
|
83
|
+
const ratio = (a, b) => { const x = luminance(a), y = luminance(b); return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05); };
|
|
84
|
+
const defects = [];
|
|
85
|
+
for (const el of document.querySelectorAll('body *')) {
|
|
86
|
+
if (el.closest('script, style, svg')) continue;
|
|
87
|
+
const text = [...el.childNodes].filter((n) => n.nodeType === 3).map((n) => n.textContent || '').join(' ').trim();
|
|
88
|
+
if (text.length < 2) continue;
|
|
89
|
+
const style = getComputedStyle(el);
|
|
90
|
+
if (style.display === 'none' || style.visibility === 'hidden' || Number(style.opacity) === 0) continue;
|
|
91
|
+
const rect = el.getBoundingClientRect();
|
|
92
|
+
if (!rect.width || !rect.height) continue;
|
|
93
|
+
const fg = parse(style.color);
|
|
94
|
+
let bg = parse(style.backgroundColor);
|
|
95
|
+
let parent = el;
|
|
96
|
+
while ((!bg || bg[3] === 0) && parent && parent !== document.documentElement) {
|
|
97
|
+
parent = parent.parentElement;
|
|
98
|
+
if (parent) bg = parse(getComputedStyle(parent).backgroundColor);
|
|
131
99
|
}
|
|
100
|
+
if (!fg || !bg) continue;
|
|
101
|
+
const fontSize = Number.parseFloat(style.fontSize) || 16;
|
|
102
|
+
const bold = Number(style.fontWeight) >= 700;
|
|
103
|
+
const minRatio = fontSize >= 24 || (bold && fontSize >= 18.66) ? 3 : 4.5;
|
|
104
|
+
const measured = ratio(fg, bg);
|
|
105
|
+
if (measured < minRatio) defects.push({ ratio: Number(measured.toFixed(2)), minRatio, fontSize, text: text.slice(0, 60) });
|
|
106
|
+
}
|
|
107
|
+
return defects.sort((a, b) => a.ratio - b.ratio).slice(0, 3);
|
|
108
|
+
});
|
|
132
109
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
type: 'HERO_FRAMING_DEFECT',
|
|
149
|
-
severity: 'high',
|
|
150
|
-
message: `Hero/Stage coverage (${Math.round(heroCoverage.ratio * 100)}%) is under the 66% threshold for desktop viewports.`,
|
|
151
|
-
confidence: 'medium',
|
|
152
|
-
objective: false,
|
|
153
|
-
evidence: {
|
|
154
|
-
kind: 'dom',
|
|
155
|
-
description: `Stage covers ${Math.round(heroCoverage.ratio * 100)}% of the viewport; threshold is 66%`,
|
|
156
|
-
viewport: { width: vp.width, height: vp.height }
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
110
|
+
for (const defect of contrastDefects) {
|
|
111
|
+
passed = false;
|
|
112
|
+
found.push({
|
|
113
|
+
width: vp.width,
|
|
114
|
+
viewportName: vp.name,
|
|
115
|
+
type: 'RENDERED_CONTRAST_DEFECT',
|
|
116
|
+
severity: 'high',
|
|
117
|
+
message: `Text "${defect.text}" has ${defect.ratio}:1 contrast (minimum ${defect.minRatio}:1 at ${defect.fontSize}px).`,
|
|
118
|
+
confidence: 'high',
|
|
119
|
+
objective: true,
|
|
120
|
+
evidence: {
|
|
121
|
+
kind: 'computed-style',
|
|
122
|
+
description: `Computed foreground/background contrast ${defect.ratio}:1 at ${defect.fontSize}px`,
|
|
123
|
+
viewport: { width: vp.width, height: vp.height },
|
|
124
|
+
criterion: 'WCAG 1.4.3 Contrast (Minimum)'
|
|
160
125
|
}
|
|
161
|
-
}
|
|
162
|
-
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 3. Check Above-the-fold Hero Framing on desktop viewports
|
|
130
|
+
if (vp.width >= 1024) {
|
|
131
|
+
const heroCoverage = await page.evaluate(() => {
|
|
132
|
+
const stage = document.querySelector('.ss-stage, [data-sloppy-stage], main, header');
|
|
133
|
+
if (!stage) return { found: false, ratio: 0 };
|
|
134
|
+
const rect = stage.getBoundingClientRect();
|
|
135
|
+
const ratio = (rect.width * Math.min(rect.height, 800)) / (window.innerWidth * 800);
|
|
136
|
+
return { found: true, ratio };
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
if (heroCoverage.found && heroCoverage.ratio < 0.5) {
|
|
140
|
+
passed = false;
|
|
141
|
+
found.push({
|
|
163
142
|
width: vp.width,
|
|
164
143
|
viewportName: vp.name,
|
|
165
|
-
type: '
|
|
166
|
-
severity: '
|
|
167
|
-
message: `
|
|
168
|
-
confidence: '
|
|
144
|
+
type: 'HERO_FRAMING_DEFECT',
|
|
145
|
+
severity: 'high',
|
|
146
|
+
message: `Hero/Stage coverage (${Math.round(heroCoverage.ratio * 100)}%) is under the 66% threshold for desktop viewports.`,
|
|
147
|
+
confidence: 'medium',
|
|
169
148
|
objective: false,
|
|
170
149
|
evidence: {
|
|
171
|
-
kind: '
|
|
172
|
-
description: `
|
|
150
|
+
kind: 'dom',
|
|
151
|
+
description: `Stage covers ${Math.round(heroCoverage.ratio * 100)}% of the viewport; threshold is 66%`,
|
|
173
152
|
viewport: { width: vp.width, height: vp.height }
|
|
174
153
|
}
|
|
175
154
|
});
|
|
176
|
-
vpPassed = false;
|
|
177
|
-
} finally {
|
|
178
|
-
await page.close();
|
|
179
155
|
}
|
|
180
|
-
|
|
181
|
-
if (vpPassed) viewportsPassed++;
|
|
182
156
|
}
|
|
157
|
+
} catch (err) {
|
|
158
|
+
found.push({
|
|
159
|
+
width: vp.width,
|
|
160
|
+
viewportName: vp.name,
|
|
161
|
+
type: 'RENDER_EVALUATION_ERROR',
|
|
162
|
+
severity: 'medium',
|
|
163
|
+
message: `Evaluation error at ${vp.width}px: ${err?.message || err}`,
|
|
164
|
+
confidence: 'low',
|
|
165
|
+
objective: false,
|
|
166
|
+
evidence: {
|
|
167
|
+
kind: 'runtime',
|
|
168
|
+
description: `Browser evaluation failed at ${vp.width}px`,
|
|
169
|
+
viewport: { width: vp.width, height: vp.height }
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
passed = false;
|
|
173
|
+
} finally {
|
|
174
|
+
await page.close();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return { passed, findings: found };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function runBrowserMultiWidth(browser, target, options = {}) {
|
|
181
|
+
const findings = [];
|
|
182
|
+
let viewportsPassed = 0;
|
|
183
|
+
const ownsBrowser = !options.browser;
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
// Four isolated pages keep eight viewports inside one browser without serializing them.
|
|
187
|
+
let next = 0;
|
|
188
|
+
const run = async () => {
|
|
189
|
+
while (next < CANONICAL_VIEWPORT_WIDTHS.length) {
|
|
190
|
+
const vp = CANONICAL_VIEWPORT_WIDTHS[next++];
|
|
191
|
+
const result = await checkViewport(browser, target, vp);
|
|
192
|
+
findings.push(...result.findings);
|
|
193
|
+
if (result.passed) viewportsPassed++;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
await Promise.all(Array.from({ length: Math.min(4, CANONICAL_VIEWPORT_WIDTHS.length) }, run));
|
|
183
197
|
} finally {
|
|
184
|
-
await browser.close();
|
|
198
|
+
if (ownsBrowser) await browser.close();
|
|
185
199
|
}
|
|
186
200
|
|
|
201
|
+
findings.sort((a, b) => a.width - b.width);
|
|
187
202
|
const allPassed = findings.length === 0;
|
|
188
203
|
return {
|
|
189
204
|
target,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sloppy-ai/verify",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Perceptual & geometric verification engine for Sloppy UI components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./verification.mjs",
|
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
".": "./verification.mjs",
|
|
9
9
|
"./verification": "./verification.mjs",
|
|
10
10
|
"./multi-width": "./multi-width.mjs",
|
|
11
|
-
"./accessibility": "./accessibility.mjs"
|
|
11
|
+
"./accessibility": "./accessibility.mjs",
|
|
12
|
+
"./tells": "./tells.mjs",
|
|
13
|
+
"./motion-interactions": "./motion-interactions.mjs",
|
|
14
|
+
"./browser": "./browser.mjs"
|
|
12
15
|
},
|
|
13
16
|
"files": [
|
|
14
17
|
"verification.mjs",
|
|
@@ -22,8 +25,10 @@
|
|
|
22
25
|
"layout-core.mjs",
|
|
23
26
|
"layout.mjs",
|
|
24
27
|
"motion-watch.mjs",
|
|
28
|
+
"motion-interactions.mjs",
|
|
25
29
|
"multi-width.mjs",
|
|
26
|
-
"accessibility.mjs"
|
|
30
|
+
"accessibility.mjs",
|
|
31
|
+
"tells.mjs"
|
|
27
32
|
],
|
|
28
33
|
"publishConfig": {
|
|
29
34
|
"access": "public"
|