@sloppy-ai/verify 0.0.0-stage → 1.1.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.
@@ -0,0 +1,244 @@
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 = await tryLaunch();
28
+ if (launchResult.browser) {
29
+ return await runBrowserMultiWidth(launchResult.browser, target);
30
+ }
31
+ }
32
+
33
+ // Fallback to static source scanning
34
+ return runStaticMultiWidthFallback(target);
35
+ }
36
+
37
+ async function runBrowserMultiWidth(browser, url) {
38
+ const findings = [];
39
+ let viewportsPassed = 0;
40
+
41
+ try {
42
+ for (const vp of CANONICAL_VIEWPORT_WIDTHS) {
43
+ const page = await browser.newPage({ viewport: { width: vp.width, height: vp.height } });
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
+ });
57
+
58
+ if (overflow.hasOverflow) {
59
+ vpPassed = false;
60
+ findings.push({
61
+ width: vp.width,
62
+ viewportName: vp.name,
63
+ type: 'HORIZONTAL_OVERFLOW',
64
+ severity: 'critical',
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
+ }
76
+
77
+ // 2. Measure rendered text contrast against the nearest painted ancestor.
78
+ const contrastDefects = await page.evaluate(() => {
79
+ const parse = (value) => {
80
+ const match = String(value || '').match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*([\d.]+))?\s*\)/);
81
+ return match ? [Number(match[1]), Number(match[2]), Number(match[3]), match[4] === undefined ? 1 : Number(match[4])] : null;
82
+ };
83
+ const luminance = ([r, g, b]) => {
84
+ const channel = (v) => { const x = v / 255; return x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4; };
85
+ return channel(r) * 0.2126 + channel(g) * 0.7152 + channel(b) * 0.0722;
86
+ };
87
+ const ratio = (a, b) => { const x = luminance(a), y = luminance(b); return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05); };
88
+ const defects = [];
89
+ for (const el of document.querySelectorAll('body *')) {
90
+ if (el.closest('script, style, svg')) continue;
91
+ const text = [...el.childNodes].filter((n) => n.nodeType === 3).map((n) => n.textContent || '').join(' ').trim();
92
+ if (text.length < 2) continue;
93
+ const style = getComputedStyle(el);
94
+ if (style.display === 'none' || style.visibility === 'hidden' || Number(style.opacity) === 0) continue;
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
+ });
113
+
114
+ for (const defect of contrastDefects) {
115
+ vpPassed = false;
116
+ findings.push({
117
+ width: vp.width,
118
+ viewportName: vp.name,
119
+ type: 'RENDERED_CONTRAST_DEFECT',
120
+ severity: 'high',
121
+ message: `Text "${defect.text}" has ${defect.ratio}:1 contrast (minimum ${defect.minRatio}:1 at ${defect.fontSize}px).`,
122
+ confidence: 'high',
123
+ objective: true,
124
+ evidence: {
125
+ kind: 'computed-style',
126
+ description: `Computed foreground/background contrast ${defect.ratio}:1 at ${defect.fontSize}px`,
127
+ viewport: { width: vp.width, height: vp.height },
128
+ criterion: 'WCAG 1.4.3 Contrast (Minimum)'
129
+ }
130
+ });
131
+ }
132
+
133
+ // 3. Check Above-the-fold Hero Framing on desktop viewports
134
+ if (vp.width >= 1024) {
135
+ const heroCoverage = await page.evaluate(() => {
136
+ const stage = document.querySelector('.ss-stage, [data-sloppy-stage], main, header');
137
+ if (!stage) return { found: false, ratio: 0 };
138
+ const rect = stage.getBoundingClientRect();
139
+ const ratio = (rect.width * Math.min(rect.height, 800)) / (window.innerWidth * 800);
140
+ return { found: true, ratio };
141
+ });
142
+
143
+ if (heroCoverage.found && heroCoverage.ratio < 0.5) {
144
+ vpPassed = false;
145
+ findings.push({
146
+ width: vp.width,
147
+ viewportName: vp.name,
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
+ }
160
+ }
161
+ } catch (err) {
162
+ findings.push({
163
+ width: vp.width,
164
+ viewportName: vp.name,
165
+ type: 'RENDER_EVALUATION_ERROR',
166
+ severity: 'medium',
167
+ message: `Evaluation error at ${vp.width}px: ${err?.message || err}`,
168
+ confidence: 'low',
169
+ objective: false,
170
+ evidence: {
171
+ kind: 'runtime',
172
+ description: `Browser evaluation failed at ${vp.width}px`,
173
+ viewport: { width: vp.width, height: vp.height }
174
+ }
175
+ });
176
+ vpPassed = false;
177
+ } finally {
178
+ await page.close();
179
+ }
180
+
181
+ if (vpPassed) viewportsPassed++;
182
+ }
183
+ } finally {
184
+ await browser.close();
185
+ }
186
+
187
+ const allPassed = findings.length === 0;
188
+ return {
189
+ target,
190
+ isStaticFallback: false,
191
+ totalViewportsTested: CANONICAL_VIEWPORT_WIDTHS.length,
192
+ viewportsPassed,
193
+ allPassed,
194
+ findings,
195
+ summary: allPassed
196
+ ? `All ${CANONICAL_VIEWPORT_WIDTHS.length} viewports (375px to 1920px) passed multi-width render verification.`
197
+ : `Multi-width verification found ${findings.length} issue(s) across ${CANONICAL_VIEWPORT_WIDTHS.length - viewportsPassed} viewport(s).`
198
+ };
199
+ }
200
+
201
+ function runStaticMultiWidthFallback(target) {
202
+ const findings = [];
203
+ let code = '';
204
+
205
+ try {
206
+ code = fs.readFileSync(target, 'utf8');
207
+ } catch {
208
+ // Target is an inaccessible URL or missing file; test sample code
209
+ }
210
+
211
+ // Scan for fixed unconstrained pixel widths that break mobile viewports (e.g. w-[1200px], min-w-[800px])
212
+ const fixedWidthRegex = /\b(?:min-)?w-\[(?:[5-9]\d{2}|[1-9]\d{3,})px\]/g;
213
+ const matches = [...code.matchAll(fixedWidthRegex)];
214
+
215
+ for (const m of matches) {
216
+ findings.push({
217
+ width: 375,
218
+ viewportName: 'mobile-small',
219
+ type: 'STATIC_FIXED_WIDTH',
220
+ severity: 'critical',
221
+ message: `Fixed pixel width token "${m[0]}" detected without responsive constraints; causes mobile horizontal clipping.`,
222
+ confidence: 'medium',
223
+ objective: true,
224
+ evidence: {
225
+ kind: 'source',
226
+ description: `Static source scan matched ${m[0]}; render confirmation is unavailable`,
227
+ viewport: { width: 375, height: 667 }
228
+ }
229
+ });
230
+ }
231
+
232
+ const allPassed = findings.length === 0;
233
+ return {
234
+ target,
235
+ isStaticFallback: true,
236
+ totalViewportsTested: CANONICAL_VIEWPORT_WIDTHS.length,
237
+ viewportsPassed: allPassed ? CANONICAL_VIEWPORT_WIDTHS.length : CANONICAL_VIEWPORT_WIDTHS.length - findings.length,
238
+ allPassed,
239
+ findings,
240
+ summary: allPassed
241
+ ? `[STATIC FALLBACK] Verified responsive layout across 8 viewports via static source scanning.`
242
+ : `[STATIC FALLBACK] Found ${findings.length} potential mobile layout issue(s).`
243
+ };
244
+ }
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@sloppy-ai/verify",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.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
+ },
13
+ "files": [
14
+ "verification.mjs",
15
+ "browser.mjs",
16
+ "class-clash-core.mjs",
17
+ "class-clash.mjs",
18
+ "film-checks.mjs",
19
+ "film.mjs",
20
+ "jumps-core.mjs",
21
+ "jumps.mjs",
22
+ "layout-core.mjs",
23
+ "layout.mjs",
24
+ "motion-watch.mjs",
25
+ "multi-width.mjs",
26
+ "accessibility.mjs"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "scripts": {
32
+ "typecheck": "tsc --noEmit"
33
+ },
34
+ "dependencies": {
35
+ "playwright-core": "~1.48.2"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^22.10.1",
39
+ "typescript": "^5.6.3"
40
+ },
41
+ "license": "MIT"
42
+ }