@sloppy-ai/verify 0.0.0-stage → 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 +534 -0
- package/browser.mjs +30 -0
- package/class-clash-core.mjs +130 -0
- package/class-clash.mjs +52 -0
- package/film-checks.mjs +2120 -0
- package/film.mjs +664 -0
- package/jumps-core.mjs +191 -0
- package/jumps.mjs +68 -0
- package/layout-core.mjs +164 -0
- package/layout.mjs +65 -0
- package/motion-interactions.mjs +463 -0
- package/motion-watch.mjs +557 -0
- package/multi-width.mjs +259 -0
- package/package.json +45 -4
- package/tells.mjs +390 -0
- package/verification.mjs +401 -0
- package/README.md +0 -3
package/multi-width.mjs
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Sloppy Multi-Width Render & Viewport Verification
|
|
4
|
+
* Evaluates real rendered contrast, mobile horizontal overflow, and hero stage framing
|
|
5
|
+
* across 8 canonical viewports (375px to 1920px), with a graceful static source-scan fallback.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { tryLaunch } from './browser.mjs';
|
|
9
|
+
import * as fs from 'node:fs';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
|
|
12
|
+
export const CANONICAL_VIEWPORT_WIDTHS = [
|
|
13
|
+
{ width: 375, height: 667, name: 'mobile-small', device: 'iPhone SE' },
|
|
14
|
+
{ width: 390, height: 844, name: 'mobile-standard', device: 'iPhone 14/15' },
|
|
15
|
+
{ width: 430, height: 932, name: 'mobile-plus', device: 'iPhone Max' },
|
|
16
|
+
{ width: 768, height: 1024, name: 'tablet-portrait', device: 'iPad Mini/Standard' },
|
|
17
|
+
{ width: 834, height: 1194, name: 'tablet-large', device: 'iPad Pro 11"' },
|
|
18
|
+
{ width: 1024, height: 768, name: 'desktop-compact', device: 'iPad Pro 12.9" / Small Laptop' },
|
|
19
|
+
{ width: 1440, height: 900, name: 'desktop-widescreen', device: 'MacBook Pro / Desktop' },
|
|
20
|
+
{ width: 1920, height: 1080, name: 'desktop-full-hd', device: '1080p Monitor' }
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
export async function runMultiWidthVerification(target, options = {}) {
|
|
24
|
+
const isUrl = /^https?:\/\//i.test(target);
|
|
25
|
+
|
|
26
|
+
if (!options.staticOnly && isUrl) {
|
|
27
|
+
const launchResult = options.browser ? { browser: options.browser } : await tryLaunch();
|
|
28
|
+
if (launchResult.browser) {
|
|
29
|
+
return await runBrowserMultiWidth(launchResult.browser, target, options);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Fallback to static source scanning
|
|
34
|
+
return runStaticMultiWidthFallback(target);
|
|
35
|
+
}
|
|
36
|
+
|
|
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 } });
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
await page.goto(target, { waitUntil: 'domcontentloaded', timeout: 8000 });
|
|
44
|
+
await page.waitForTimeout(250);
|
|
45
|
+
|
|
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
|
+
});
|
|
53
|
+
|
|
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
|
+
}
|
|
72
|
+
|
|
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);
|
|
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
|
+
});
|
|
109
|
+
|
|
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)'
|
|
125
|
+
}
|
|
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({
|
|
142
|
+
width: vp.width,
|
|
143
|
+
viewportName: vp.name,
|
|
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',
|
|
148
|
+
objective: false,
|
|
149
|
+
evidence: {
|
|
150
|
+
kind: 'dom',
|
|
151
|
+
description: `Stage covers ${Math.round(heroCoverage.ratio * 100)}% of the viewport; threshold is 66%`,
|
|
152
|
+
viewport: { width: vp.width, height: vp.height }
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
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));
|
|
197
|
+
} finally {
|
|
198
|
+
if (ownsBrowser) await browser.close();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
findings.sort((a, b) => a.width - b.width);
|
|
202
|
+
const allPassed = findings.length === 0;
|
|
203
|
+
return {
|
|
204
|
+
target,
|
|
205
|
+
isStaticFallback: false,
|
|
206
|
+
totalViewportsTested: CANONICAL_VIEWPORT_WIDTHS.length,
|
|
207
|
+
viewportsPassed,
|
|
208
|
+
allPassed,
|
|
209
|
+
findings,
|
|
210
|
+
summary: allPassed
|
|
211
|
+
? `All ${CANONICAL_VIEWPORT_WIDTHS.length} viewports (375px to 1920px) passed multi-width render verification.`
|
|
212
|
+
: `Multi-width verification found ${findings.length} issue(s) across ${CANONICAL_VIEWPORT_WIDTHS.length - viewportsPassed} viewport(s).`
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function runStaticMultiWidthFallback(target) {
|
|
217
|
+
const findings = [];
|
|
218
|
+
let code = '';
|
|
219
|
+
|
|
220
|
+
try {
|
|
221
|
+
code = fs.readFileSync(target, 'utf8');
|
|
222
|
+
} catch {
|
|
223
|
+
// Target is an inaccessible URL or missing file; test sample code
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Scan for fixed unconstrained pixel widths that break mobile viewports (e.g. w-[1200px], min-w-[800px])
|
|
227
|
+
const fixedWidthRegex = /\b(?:min-)?w-\[(?:[5-9]\d{2}|[1-9]\d{3,})px\]/g;
|
|
228
|
+
const matches = [...code.matchAll(fixedWidthRegex)];
|
|
229
|
+
|
|
230
|
+
for (const m of matches) {
|
|
231
|
+
findings.push({
|
|
232
|
+
width: 375,
|
|
233
|
+
viewportName: 'mobile-small',
|
|
234
|
+
type: 'STATIC_FIXED_WIDTH',
|
|
235
|
+
severity: 'critical',
|
|
236
|
+
message: `Fixed pixel width token "${m[0]}" detected without responsive constraints; causes mobile horizontal clipping.`,
|
|
237
|
+
confidence: 'medium',
|
|
238
|
+
objective: true,
|
|
239
|
+
evidence: {
|
|
240
|
+
kind: 'source',
|
|
241
|
+
description: `Static source scan matched ${m[0]}; render confirmation is unavailable`,
|
|
242
|
+
viewport: { width: 375, height: 667 }
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const allPassed = findings.length === 0;
|
|
248
|
+
return {
|
|
249
|
+
target,
|
|
250
|
+
isStaticFallback: true,
|
|
251
|
+
totalViewportsTested: CANONICAL_VIEWPORT_WIDTHS.length,
|
|
252
|
+
viewportsPassed: allPassed ? CANONICAL_VIEWPORT_WIDTHS.length : CANONICAL_VIEWPORT_WIDTHS.length - findings.length,
|
|
253
|
+
allPassed,
|
|
254
|
+
findings,
|
|
255
|
+
summary: allPassed
|
|
256
|
+
? `[STATIC FALLBACK] Verified responsive layout across 8 viewports via static source scanning.`
|
|
257
|
+
: `[STATIC FALLBACK] Found ${findings.length} potential mobile layout issue(s).`
|
|
258
|
+
};
|
|
259
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sloppy-ai/verify",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "Perceptual & geometric verification engine for Sloppy UI components",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./verification.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./verification.mjs",
|
|
9
|
+
"./verification": "./verification.mjs",
|
|
10
|
+
"./multi-width": "./multi-width.mjs",
|
|
11
|
+
"./accessibility": "./accessibility.mjs",
|
|
12
|
+
"./tells": "./tells.mjs",
|
|
13
|
+
"./motion-interactions": "./motion-interactions.mjs",
|
|
14
|
+
"./browser": "./browser.mjs"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"verification.mjs",
|
|
18
|
+
"browser.mjs",
|
|
19
|
+
"class-clash-core.mjs",
|
|
20
|
+
"class-clash.mjs",
|
|
21
|
+
"film-checks.mjs",
|
|
22
|
+
"film.mjs",
|
|
23
|
+
"jumps-core.mjs",
|
|
24
|
+
"jumps.mjs",
|
|
25
|
+
"layout-core.mjs",
|
|
26
|
+
"layout.mjs",
|
|
27
|
+
"motion-watch.mjs",
|
|
28
|
+
"motion-interactions.mjs",
|
|
29
|
+
"multi-width.mjs",
|
|
30
|
+
"accessibility.mjs",
|
|
31
|
+
"tells.mjs"
|
|
32
|
+
],
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"typecheck": "tsc --noEmit"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"playwright-core": "~1.48.2"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^22.10.1",
|
|
44
|
+
"typescript": "^5.6.3"
|
|
45
|
+
},
|
|
46
|
+
"license": "MIT"
|
|
47
|
+
}
|