impeccable 2.0.6 → 2.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.
- package/LICENSE +191 -77
- package/README.md +10 -10
- package/README.npm.md +76 -0
- package/README.repo.md +246 -0
- package/bin/commands/skills.mjs +27 -0
- package/package.json +47 -27
- package/src/detect-antipatterns-browser.js +1029 -213
- package/src/detect-antipatterns.mjs +1221 -215
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Anti-Pattern Browser Detector for Impeccable
|
|
3
3
|
* Copyright (c) 2026 Paul Bakaus
|
|
4
|
-
* SPDX-License-Identifier:
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*
|
|
6
6
|
* GENERATED -- do not edit. Source: detect-antipatterns.mjs
|
|
7
7
|
* Rebuild: node scripts/build-browser-detector.js
|
|
@@ -15,7 +15,7 @@ if (typeof window === 'undefined') return;
|
|
|
15
15
|
/**
|
|
16
16
|
* Anti-Pattern Detector for Impeccable
|
|
17
17
|
* Copyright (c) 2026 Paul Bakaus
|
|
18
|
-
* SPDX-License-Identifier:
|
|
18
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
19
19
|
*
|
|
20
20
|
* Universal file — auto-detects environment (browser vs Node) and adapts.
|
|
21
21
|
*
|
|
@@ -48,10 +48,42 @@ const SAFE_TAGS = new Set([
|
|
|
48
48
|
'rect', 'line', 'polyline', 'polygon', 'g', 'defs', 'use',
|
|
49
49
|
]);
|
|
50
50
|
|
|
51
|
+
// Per-check safe-tags override for the border (side-tab / border-accent)
|
|
52
|
+
// rule. We intentionally re-allow <label> here because card-shaped clickable
|
|
53
|
+
// labels (e.g. .checklist-item wrapping a checkbox + content) are one of the
|
|
54
|
+
// canonical side-tab anti-pattern shapes and must be detected. The rule's
|
|
55
|
+
// other preconditions (non-neutral color, width >= 2px on a single side,
|
|
56
|
+
// radius > 0 or width >= 3, element size >= 20x20 in the browser path)
|
|
57
|
+
// already filter out plain inline form labels so this does not introduce
|
|
58
|
+
// false positives. See modern-color-borders.html for the test matrix.
|
|
59
|
+
const BORDER_SAFE_TAGS = new Set(
|
|
60
|
+
[...SAFE_TAGS].filter(t => t !== 'label')
|
|
61
|
+
);
|
|
62
|
+
|
|
51
63
|
const OVERUSED_FONTS = new Set([
|
|
52
64
|
'inter', 'roboto', 'open sans', 'lato', 'montserrat', 'arial', 'helvetica',
|
|
53
65
|
]);
|
|
54
66
|
|
|
67
|
+
// Brand-associated fonts: don't flag these as "overused" on the brand's own domains.
|
|
68
|
+
// Keys are font names, values are arrays of hostname suffixes where the font is allowed.
|
|
69
|
+
const GOOGLE_DOMAINS = [
|
|
70
|
+
'google.com', 'youtube.com', 'android.com', 'chromium.org',
|
|
71
|
+
'chrome.com', 'web.dev', 'gstatic.com', 'firebase.google.com',
|
|
72
|
+
];
|
|
73
|
+
const BRAND_FONT_DOMAINS = {
|
|
74
|
+
'roboto': GOOGLE_DOMAINS,
|
|
75
|
+
'google sans': GOOGLE_DOMAINS,
|
|
76
|
+
'product sans': GOOGLE_DOMAINS,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function isBrandFontOnOwnDomain(font) {
|
|
80
|
+
if (typeof location === 'undefined') return false;
|
|
81
|
+
const allowed = BRAND_FONT_DOMAINS[font];
|
|
82
|
+
if (!allowed) return false;
|
|
83
|
+
const host = location.hostname.toLowerCase();
|
|
84
|
+
return allowed.some(suffix => host === suffix || host.endsWith('.' + suffix));
|
|
85
|
+
}
|
|
86
|
+
|
|
55
87
|
const GENERIC_FONTS = new Set([
|
|
56
88
|
'serif', 'sans-serif', 'monospace', 'cursive', 'fantasy',
|
|
57
89
|
'system-ui', 'ui-serif', 'ui-sans-serif', 'ui-monospace', 'ui-rounded',
|
|
@@ -60,146 +92,216 @@ const GENERIC_FONTS = new Set([
|
|
|
60
92
|
]);
|
|
61
93
|
|
|
62
94
|
const ANTIPATTERNS = [
|
|
95
|
+
// ── AI slop: tells that something was AI-generated ──
|
|
63
96
|
{
|
|
64
97
|
id: 'side-tab',
|
|
98
|
+
category: 'slop',
|
|
65
99
|
name: 'Side-tab accent border',
|
|
66
100
|
description:
|
|
67
101
|
'Thick colored border on one side of a card — the most recognizable tell of AI-generated UIs. Use a subtler accent or remove it entirely.',
|
|
102
|
+
skillSection: 'Visual Details',
|
|
103
|
+
skillGuideline: 'colored accent stripe',
|
|
68
104
|
},
|
|
69
105
|
{
|
|
70
106
|
id: 'border-accent-on-rounded',
|
|
107
|
+
category: 'slop',
|
|
71
108
|
name: 'Border accent on rounded element',
|
|
72
109
|
description:
|
|
73
110
|
'Thick accent border on a rounded card — the border clashes with the rounded corners. Remove the border or the border-radius.',
|
|
111
|
+
skillSection: 'Visual Details',
|
|
112
|
+
skillGuideline: 'colored accent stripe',
|
|
74
113
|
},
|
|
75
114
|
{
|
|
76
115
|
id: 'overused-font',
|
|
116
|
+
category: 'slop',
|
|
77
117
|
name: 'Overused font',
|
|
78
118
|
description:
|
|
79
119
|
'Inter, Roboto, Open Sans, Lato, Montserrat, and Arial are used on millions of sites. Choose a distinctive font that gives your interface personality.',
|
|
120
|
+
skillSection: 'Typography',
|
|
121
|
+
skillGuideline: 'overused fonts like Inter',
|
|
80
122
|
},
|
|
81
123
|
{
|
|
82
124
|
id: 'single-font',
|
|
125
|
+
category: 'slop',
|
|
83
126
|
name: 'Single font for everything',
|
|
84
127
|
description:
|
|
85
128
|
'Only one font family is used for the entire page. Pair a distinctive display font with a refined body font to create typographic hierarchy.',
|
|
129
|
+
skillSection: 'Typography',
|
|
130
|
+
skillGuideline: 'only one font family for the entire page',
|
|
86
131
|
},
|
|
87
132
|
{
|
|
88
133
|
id: 'flat-type-hierarchy',
|
|
134
|
+
category: 'slop',
|
|
89
135
|
name: 'Flat type hierarchy',
|
|
90
136
|
description:
|
|
91
137
|
'Font sizes are too close together — no clear visual hierarchy. Use fewer sizes with more contrast (aim for at least a 1.25 ratio between steps).',
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
id: 'pure-black-white',
|
|
95
|
-
name: 'Pure black background',
|
|
96
|
-
description:
|
|
97
|
-
'Pure #000000 as a background color looks harsh and unnatural. Tint it slightly toward your brand hue (e.g., oklch(12% 0.01 250)) for a more refined feel.',
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
id: 'gray-on-color',
|
|
101
|
-
name: 'Gray text on colored background',
|
|
102
|
-
description:
|
|
103
|
-
'Gray text looks washed out on colored backgrounds. Use a darker shade of the background color instead, or white/near-white for contrast.',
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
id: 'low-contrast',
|
|
107
|
-
name: 'Low contrast text',
|
|
108
|
-
description:
|
|
109
|
-
'Text does not meet WCAG AA contrast requirements (4.5:1 for body, 3:1 for large text). Increase the contrast between text and background.',
|
|
138
|
+
skillSection: 'Typography',
|
|
139
|
+
skillGuideline: 'flat type hierarchy',
|
|
110
140
|
},
|
|
111
141
|
{
|
|
112
142
|
id: 'gradient-text',
|
|
143
|
+
category: 'slop',
|
|
113
144
|
name: 'Gradient text',
|
|
114
145
|
description:
|
|
115
146
|
'Gradient text is decorative rather than meaningful — a common AI tell, especially on headings and metrics. Use solid colors for text.',
|
|
147
|
+
skillSection: 'Color & Contrast',
|
|
148
|
+
skillGuideline: 'gradient text for',
|
|
116
149
|
},
|
|
117
150
|
{
|
|
118
151
|
id: 'ai-color-palette',
|
|
152
|
+
category: 'slop',
|
|
119
153
|
name: 'AI color palette',
|
|
120
154
|
description:
|
|
121
155
|
'Purple/violet gradients and cyan-on-dark are the most recognizable tells of AI-generated UIs. Choose a distinctive, intentional palette.',
|
|
156
|
+
skillSection: 'Color & Contrast',
|
|
157
|
+
skillGuideline: 'AI color palette',
|
|
122
158
|
},
|
|
123
159
|
{
|
|
124
160
|
id: 'nested-cards',
|
|
161
|
+
category: 'slop',
|
|
125
162
|
name: 'Nested cards',
|
|
126
163
|
description:
|
|
127
164
|
'Cards inside cards create visual noise and excessive depth. Flatten the hierarchy — use spacing, typography, and dividers instead of nesting containers.',
|
|
165
|
+
skillSection: 'Layout & Space',
|
|
166
|
+
skillGuideline: 'Nest cards inside cards',
|
|
128
167
|
},
|
|
129
168
|
{
|
|
130
169
|
id: 'monotonous-spacing',
|
|
170
|
+
category: 'slop',
|
|
131
171
|
name: 'Monotonous spacing',
|
|
132
172
|
description:
|
|
133
173
|
'The same spacing value used everywhere — no rhythm, no variation. Use tight groupings for related items and generous separations between sections.',
|
|
174
|
+
skillSection: 'Layout & Space',
|
|
175
|
+
skillGuideline: 'same spacing everywhere',
|
|
134
176
|
},
|
|
135
177
|
{
|
|
136
178
|
id: 'everything-centered',
|
|
179
|
+
category: 'slop',
|
|
137
180
|
name: 'Everything centered',
|
|
138
181
|
description:
|
|
139
182
|
'Every text element is center-aligned. Left-aligned text with asymmetric layouts feels more designed. Center only hero sections and CTAs.',
|
|
183
|
+
skillSection: 'Layout & Space',
|
|
184
|
+
skillGuideline: 'Center everything',
|
|
140
185
|
},
|
|
141
186
|
{
|
|
142
187
|
id: 'bounce-easing',
|
|
188
|
+
category: 'slop',
|
|
143
189
|
name: 'Bounce or elastic easing',
|
|
144
190
|
description:
|
|
145
191
|
'Bounce and elastic easing feel dated and tacky. Real objects decelerate smoothly — use exponential easing (ease-out-quart/quint/expo) instead.',
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
id: 'layout-transition',
|
|
149
|
-
name: 'Layout property animation',
|
|
150
|
-
description:
|
|
151
|
-
'Animating width, height, padding, or margin causes layout thrash and janky performance. Use transform and opacity instead, or grid-template-rows for height animations.',
|
|
192
|
+
skillSection: 'Motion',
|
|
193
|
+
skillGuideline: 'bounce or elastic easing',
|
|
152
194
|
},
|
|
153
195
|
{
|
|
154
196
|
id: 'dark-glow',
|
|
197
|
+
category: 'slop',
|
|
155
198
|
name: 'Dark mode with glowing accents',
|
|
156
199
|
description:
|
|
157
200
|
'Dark backgrounds with colored box-shadow glows are the default "cool" look of AI-generated UIs. Use subtle, purposeful lighting instead — or skip the dark theme entirely.',
|
|
201
|
+
skillSection: 'Color & Contrast',
|
|
202
|
+
skillGuideline: 'dark mode with glowing accents',
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
id: 'icon-tile-stack',
|
|
206
|
+
category: 'slop',
|
|
207
|
+
name: 'Icon tile stacked above heading',
|
|
208
|
+
description:
|
|
209
|
+
'A small rounded-square icon container above a heading is the universal AI feature-card template — every generator outputs this exact shape. Try a side-by-side icon and heading, or let the icon sit in flow without its own container.',
|
|
210
|
+
skillSection: 'Typography',
|
|
211
|
+
skillGuideline: 'large icons with rounded corners above every heading',
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
// ── Quality: general design and accessibility issues ──
|
|
215
|
+
{
|
|
216
|
+
id: 'pure-black-white',
|
|
217
|
+
category: 'quality',
|
|
218
|
+
name: 'Pure black background',
|
|
219
|
+
description:
|
|
220
|
+
'Pure #000000 as a background color looks harsh and unnatural. Tint it slightly toward your brand hue (e.g., oklch(12% 0.01 250)) for a more refined feel.',
|
|
221
|
+
skillSection: 'Color & Contrast',
|
|
222
|
+
skillGuideline: 'pure black (#000)',
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
id: 'gray-on-color',
|
|
226
|
+
category: 'quality',
|
|
227
|
+
name: 'Gray text on colored background',
|
|
228
|
+
description:
|
|
229
|
+
'Gray text looks washed out on colored backgrounds. Use a darker shade of the background color instead, or white/near-white for contrast.',
|
|
230
|
+
skillSection: 'Color & Contrast',
|
|
231
|
+
skillGuideline: 'gray text on colored backgrounds',
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
id: 'low-contrast',
|
|
235
|
+
category: 'quality',
|
|
236
|
+
name: 'Low contrast text',
|
|
237
|
+
description:
|
|
238
|
+
'Text does not meet WCAG AA contrast requirements (4.5:1 for body, 3:1 for large text). Increase the contrast between text and background.',
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
id: 'layout-transition',
|
|
242
|
+
category: 'quality',
|
|
243
|
+
name: 'Layout property animation',
|
|
244
|
+
description:
|
|
245
|
+
'Animating width, height, padding, or margin causes layout thrash and janky performance. Use transform and opacity instead, or grid-template-rows for height animations.',
|
|
246
|
+
skillSection: 'Motion',
|
|
247
|
+
skillGuideline: 'Animate layout properties',
|
|
158
248
|
},
|
|
159
249
|
{
|
|
160
250
|
id: 'line-length',
|
|
251
|
+
category: 'quality',
|
|
161
252
|
name: 'Line length too long',
|
|
162
253
|
description:
|
|
163
254
|
'Text lines wider than ~80 characters are hard to read. The eye loses its place tracking back to the start of the next line. Add a max-width (65ch to 75ch) to text containers.',
|
|
255
|
+
skillSection: 'Layout & Space',
|
|
256
|
+
skillGuideline: 'wrap beyond ~80 characters',
|
|
164
257
|
},
|
|
165
258
|
{
|
|
166
259
|
id: 'cramped-padding',
|
|
260
|
+
category: 'quality',
|
|
167
261
|
name: 'Cramped padding',
|
|
168
262
|
description:
|
|
169
263
|
'Text is too close to the edge of its container. Add at least 8px (ideally 12-16px) of padding inside bordered or colored containers.',
|
|
170
264
|
},
|
|
171
265
|
{
|
|
172
266
|
id: 'tight-leading',
|
|
267
|
+
category: 'quality',
|
|
173
268
|
name: 'Tight line height',
|
|
174
269
|
description:
|
|
175
270
|
'Line height below 1.3x the font size makes multi-line text hard to read. Use 1.5 to 1.7 for body text so lines have room to breathe.',
|
|
176
271
|
},
|
|
177
272
|
{
|
|
178
273
|
id: 'skipped-heading',
|
|
274
|
+
category: 'quality',
|
|
179
275
|
name: 'Skipped heading level',
|
|
180
276
|
description:
|
|
181
277
|
'Heading levels should not skip (e.g. h1 then h3 with no h2). Screen readers use heading hierarchy for navigation. Skipping levels breaks the document outline.',
|
|
182
278
|
},
|
|
183
279
|
{
|
|
184
280
|
id: 'justified-text',
|
|
281
|
+
category: 'quality',
|
|
185
282
|
name: 'Justified text',
|
|
186
283
|
description:
|
|
187
284
|
'Justified text without hyphenation creates uneven word spacing ("rivers of white"). Use text-align: left for body text, or enable hyphens: auto if you must justify.',
|
|
188
285
|
},
|
|
189
286
|
{
|
|
190
287
|
id: 'tiny-text',
|
|
288
|
+
category: 'quality',
|
|
191
289
|
name: 'Tiny body text',
|
|
192
290
|
description:
|
|
193
291
|
'Body text below 12px is hard to read, especially on high-DPI screens. Use at least 14px for body content, 16px is ideal.',
|
|
194
292
|
},
|
|
195
293
|
{
|
|
196
294
|
id: 'all-caps-body',
|
|
295
|
+
category: 'quality',
|
|
197
296
|
name: 'All-caps body text',
|
|
198
297
|
description:
|
|
199
298
|
'Long passages in uppercase are hard to read. We recognize words by shape (ascenders and descenders), which all-caps removes. Reserve uppercase for short labels and headings.',
|
|
299
|
+
skillSection: 'Typography',
|
|
300
|
+
skillGuideline: 'long body passages in uppercase',
|
|
200
301
|
},
|
|
201
302
|
{
|
|
202
303
|
id: 'wide-tracking',
|
|
304
|
+
category: 'quality',
|
|
203
305
|
name: 'Wide letter spacing on body text',
|
|
204
306
|
description:
|
|
205
307
|
'Letter spacing above 0.05em on body text disrupts natural character groupings and slows reading. Reserve wide tracking for short uppercase labels only.',
|
|
@@ -210,9 +312,53 @@ const ANTIPATTERNS = [
|
|
|
210
312
|
|
|
211
313
|
function isNeutralColor(color) {
|
|
212
314
|
if (!color || color === 'transparent') return true;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
315
|
+
|
|
316
|
+
// rgb/rgba — use channel spread. Threshold 30 ≈ 11.7% of the 0–255 range.
|
|
317
|
+
const rgb = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
|
318
|
+
if (rgb) {
|
|
319
|
+
return (Math.max(+rgb[1], +rgb[2], +rgb[3]) - Math.min(+rgb[1], +rgb[2], +rgb[3])) < 30;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// oklch()/lch() — chroma is the second numeric component.
|
|
323
|
+
// oklch chroma is ~0–0.4 in sRGB gamut; >= 0.02 reads as tinted, not gray.
|
|
324
|
+
// lch chroma is ~0–150; >= 3 reads as tinted. jsdom emits both formats
|
|
325
|
+
// literally (it does NOT convert them to rgb).
|
|
326
|
+
const oklch = color.match(/oklch\(\s*[\d.%-]+\s+([\d.-]+)/i);
|
|
327
|
+
if (oklch) return parseFloat(oklch[1]) < 0.02;
|
|
328
|
+
const lch = color.match(/lch\(\s*[\d.%-]+\s+([\d.-]+)/i);
|
|
329
|
+
if (lch) return parseFloat(lch[1]) < 3;
|
|
330
|
+
|
|
331
|
+
// oklab()/lab() — a and b are signed axes; chroma = sqrt(a² + b²).
|
|
332
|
+
// oklab a/b are ~-0.4..0.4, threshold 0.02. lab a/b are ~-128..127, threshold 3.
|
|
333
|
+
const oklab = color.match(/oklab\(\s*[\d.%-]+\s+([\d.-]+)\s+([\d.-]+)/i);
|
|
334
|
+
if (oklab) {
|
|
335
|
+
const a = parseFloat(oklab[1]), b = parseFloat(oklab[2]);
|
|
336
|
+
return Math.hypot(a, b) < 0.02;
|
|
337
|
+
}
|
|
338
|
+
const lab = color.match(/lab\(\s*[\d.%-]+\s+([\d.-]+)\s+([\d.-]+)/i);
|
|
339
|
+
if (lab) {
|
|
340
|
+
const a = parseFloat(lab[1]), b = parseFloat(lab[2]);
|
|
341
|
+
return Math.hypot(a, b) < 3;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// hsl/hsla — saturation is the second numeric component (percent).
|
|
345
|
+
// Modern jsdom usually converts hsl() to rgb, but handle it directly for
|
|
346
|
+
// safety across versions and for any engine that preserves the format.
|
|
347
|
+
const hsl = color.match(/hsla?\(\s*[\d.-]+\s*,?\s*([\d.]+)%/i);
|
|
348
|
+
if (hsl) return parseFloat(hsl[1]) < 10;
|
|
349
|
+
|
|
350
|
+
// hwb(hue whiteness% blackness%) — a pixel is fully gray when
|
|
351
|
+
// whiteness + blackness >= 100; chroma-like saturation = 1 - (w+b)/100.
|
|
352
|
+
const hwb = color.match(/hwb\(\s*[\d.-]+\s+([\d.]+)%\s+([\d.]+)%/i);
|
|
353
|
+
if (hwb) {
|
|
354
|
+
const w = parseFloat(hwb[1]), b = parseFloat(hwb[2]);
|
|
355
|
+
return (1 - Math.min(100, w + b) / 100) < 0.1;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Unknown / unrecognized format — err on the side of DETECTING rather
|
|
359
|
+
// than silently skipping. This is the opposite of the previous default,
|
|
360
|
+
// which was the root cause of the oklch bug.
|
|
361
|
+
return false;
|
|
216
362
|
}
|
|
217
363
|
|
|
218
364
|
function parseRgb(color) {
|
|
@@ -237,9 +383,20 @@ function contrastRatio(c1, c2) {
|
|
|
237
383
|
|
|
238
384
|
function parseGradientColors(bgImage) {
|
|
239
385
|
if (!bgImage || !bgImage.includes('gradient')) return [];
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
386
|
+
const colors = [];
|
|
387
|
+
for (const m of bgImage.matchAll(/rgba?\([^)]+\)/g)) {
|
|
388
|
+
const c = parseRgb(m[0]);
|
|
389
|
+
if (c) colors.push(c);
|
|
390
|
+
}
|
|
391
|
+
for (const m of bgImage.matchAll(/#([0-9a-f]{6}|[0-9a-f]{3})\b/gi)) {
|
|
392
|
+
const h = m[1];
|
|
393
|
+
if (h.length === 6) {
|
|
394
|
+
colors.push({ r: parseInt(h.slice(0,2),16), g: parseInt(h.slice(2,4),16), b: parseInt(h.slice(4,6),16), a: 1 });
|
|
395
|
+
} else {
|
|
396
|
+
colors.push({ r: parseInt(h[0]+h[0],16), g: parseInt(h[1]+h[1],16), b: parseInt(h[2]+h[2],16), a: 1 });
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return colors;
|
|
243
400
|
}
|
|
244
401
|
|
|
245
402
|
function hasChroma(c, threshold = 30) {
|
|
@@ -268,7 +425,7 @@ function colorToHex(c) {
|
|
|
268
425
|
// ─── Section 3: Pure Detection ──────────────────────────────────────────────
|
|
269
426
|
|
|
270
427
|
function checkBorders(tag, widths, colors, radius) {
|
|
271
|
-
if (
|
|
428
|
+
if (BORDER_SAFE_TAGS.has(tag)) return [];
|
|
272
429
|
const findings = [];
|
|
273
430
|
const sides = ['Top', 'Right', 'Bottom', 'Left'];
|
|
274
431
|
|
|
@@ -294,8 +451,20 @@ function checkBorders(tag, widths, colors, radius) {
|
|
|
294
451
|
return findings;
|
|
295
452
|
}
|
|
296
453
|
|
|
454
|
+
// Returns true if the given text is composed entirely of emoji characters
|
|
455
|
+
// (plus whitespace / variation selectors). Emojis render as multicolor glyphs
|
|
456
|
+
// regardless of CSS `color`, so contrast checks against the element's text
|
|
457
|
+
// color are meaningless for these nodes.
|
|
458
|
+
const EMOJI_CHAR_RE = /[\u{1F1E6}-\u{1F1FF}\u{1F300}-\u{1F9FF}\u{1FA00}-\u{1FAFF}\u{2600}-\u{27BF}\u{2300}-\u{23FF}\u{FE0F}\u{200D}\u{1F3FB}-\u{1F3FF}]/u;
|
|
459
|
+
const EMOJI_CHARS_GLOBAL = /[\u{1F1E6}-\u{1F1FF}\u{1F300}-\u{1F9FF}\u{1FA00}-\u{1FAFF}\u{2600}-\u{27BF}\u{2300}-\u{23FF}\u{FE0F}\u{200D}\u{1F3FB}-\u{1F3FF}]/gu;
|
|
460
|
+
function isEmojiOnlyText(text) {
|
|
461
|
+
if (!text) return false;
|
|
462
|
+
if (!EMOJI_CHAR_RE.test(text)) return false;
|
|
463
|
+
return text.replace(EMOJI_CHARS_GLOBAL, '').trim() === '';
|
|
464
|
+
}
|
|
465
|
+
|
|
297
466
|
function checkColors(opts) {
|
|
298
|
-
const { tag, textColor, bgColor, effectiveBg, fontSize, fontWeight, hasDirectText, bgClip, bgImage, classList } = opts;
|
|
467
|
+
const { tag, textColor, bgColor, effectiveBg, effectiveBgStops, fontSize, fontWeight, hasDirectText, isEmojiOnly, bgClip, bgImage, classList } = opts;
|
|
299
468
|
if (SAFE_TAGS.has(tag)) return [];
|
|
300
469
|
const findings = [];
|
|
301
470
|
|
|
@@ -304,23 +473,29 @@ function checkColors(opts) {
|
|
|
304
473
|
findings.push({ id: 'pure-black-white', snippet: '#000000 background' });
|
|
305
474
|
}
|
|
306
475
|
|
|
307
|
-
if (hasDirectText && textColor) {
|
|
308
|
-
//
|
|
309
|
-
|
|
310
|
-
|
|
476
|
+
if (hasDirectText && textColor && !isEmojiOnly) {
|
|
477
|
+
// Run background-dependent checks against either a solid bg or, if the
|
|
478
|
+
// ancestor is a gradient, against every gradient stop (use the worst case).
|
|
479
|
+
const bgs = effectiveBg ? [effectiveBg] : (effectiveBgStops && effectiveBgStops.length ? effectiveBgStops : null);
|
|
480
|
+
if (bgs) {
|
|
481
|
+
// Gray on colored background — flag if every stop is chromatic
|
|
311
482
|
const textLum = relativeLuminance(textColor);
|
|
312
483
|
const isGray = !hasChroma(textColor, 20) && textLum > 0.05 && textLum < 0.85;
|
|
313
|
-
if (isGray && hasChroma(
|
|
314
|
-
|
|
484
|
+
if (isGray && bgs.every(b => hasChroma(b, 40))) {
|
|
485
|
+
const bgLabel = effectiveBg ? colorToHex(effectiveBg) : `gradient(${bgs.map(colorToHex).join(', ')})`;
|
|
486
|
+
findings.push({ id: 'gray-on-color', snippet: `text ${colorToHex(textColor)} on bg ${bgLabel}` });
|
|
315
487
|
}
|
|
316
488
|
|
|
317
|
-
// Low contrast (WCAG AA)
|
|
318
|
-
const
|
|
489
|
+
// Low contrast (WCAG AA) — worst case across all bg stops
|
|
490
|
+
const ratios = bgs.map(b => contrastRatio(textColor, b));
|
|
491
|
+
let worstIdx = 0;
|
|
492
|
+
for (let i = 1; i < ratios.length; i++) if (ratios[i] < ratios[worstIdx]) worstIdx = i;
|
|
493
|
+
const ratio = ratios[worstIdx];
|
|
319
494
|
const isHeading = ['h1', 'h2', 'h3'].includes(tag);
|
|
320
495
|
const isLargeText = fontSize >= 18 || (fontSize >= 14 && fontWeight >= 700) || isHeading;
|
|
321
496
|
const threshold = isLargeText ? 3.0 : 4.5;
|
|
322
497
|
if (ratio < threshold) {
|
|
323
|
-
findings.push({ id: 'low-contrast', snippet: `${ratio.toFixed(1)}:1 (need ${threshold}:1) — text ${colorToHex(textColor)} on ${colorToHex(
|
|
498
|
+
findings.push({ id: 'low-contrast', snippet: `${ratio.toFixed(1)}:1 (need ${threshold}:1) — text ${colorToHex(textColor)} on ${colorToHex(bgs[worstIdx])}` });
|
|
324
499
|
}
|
|
325
500
|
}
|
|
326
501
|
|
|
@@ -373,6 +548,62 @@ function isCardLikeFromProps(hasShadow, hasBorder, hasRadius, hasBg) {
|
|
|
373
548
|
return hasRadius || hasBg;
|
|
374
549
|
}
|
|
375
550
|
|
|
551
|
+
const HEADING_TAGS = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']);
|
|
552
|
+
|
|
553
|
+
// Pure check: given a heading and metrics about its previousElementSibling,
|
|
554
|
+
// decide if the sibling is the canonical "icon-tile-stacked-above-heading" shape.
|
|
555
|
+
//
|
|
556
|
+
// Triggers when ALL of the following hold for the sibling:
|
|
557
|
+
// • size 32–128px on both axes (not too small, not a hero image)
|
|
558
|
+
// • aspect ratio 0.7–1.4 (squarish — excludes wide thumbnails / pill badges)
|
|
559
|
+
// • has a non-transparent background-color, background-image, OR a visible border
|
|
560
|
+
// (covers solid colors, white-with-border, gradients — anything that visually
|
|
561
|
+
// defines a tile)
|
|
562
|
+
// • border-radius < width/2 (excludes round avatars; rounded squares pass)
|
|
563
|
+
// • contains an <svg> or icon-class <i> element that's smaller than the tile
|
|
564
|
+
// • the tile sits above the heading (its bottom is above the heading's top)
|
|
565
|
+
function checkIconTile(opts) {
|
|
566
|
+
const { headingTag, headingText, headingTop,
|
|
567
|
+
siblingTag, siblingWidth, siblingHeight, siblingBottom,
|
|
568
|
+
siblingBgColor, siblingBgImage, siblingBorderWidth, siblingBorderRadius,
|
|
569
|
+
hasIconChild, iconChildWidth } = opts;
|
|
570
|
+
if (!HEADING_TAGS.has(headingTag)) return [];
|
|
571
|
+
if (!siblingTag) return [];
|
|
572
|
+
// Don't recurse into nested headings (e.g. h2 above h3 in a section header)
|
|
573
|
+
if (HEADING_TAGS.has(siblingTag)) return [];
|
|
574
|
+
|
|
575
|
+
// Size window: 32–128px on each axis
|
|
576
|
+
if (!(siblingWidth >= 32 && siblingWidth <= 128)) return [];
|
|
577
|
+
if (!(siblingHeight >= 32 && siblingHeight <= 128)) return [];
|
|
578
|
+
|
|
579
|
+
// Squarish aspect ratio
|
|
580
|
+
const ratio = siblingWidth / siblingHeight;
|
|
581
|
+
if (ratio < 0.7 || ratio > 1.4) return [];
|
|
582
|
+
|
|
583
|
+
// Must have something that visually defines the tile
|
|
584
|
+
const bgVisible = (siblingBgColor && siblingBgColor.a > 0.1)
|
|
585
|
+
|| (siblingBgImage && siblingBgImage !== 'none' && siblingBgImage !== '');
|
|
586
|
+
const borderVisible = siblingBorderWidth > 0;
|
|
587
|
+
if (!bgVisible && !borderVisible) return [];
|
|
588
|
+
|
|
589
|
+
// Exclude circles (avatars). Rounded squares pass.
|
|
590
|
+
if (siblingBorderRadius >= siblingWidth / 2) return [];
|
|
591
|
+
|
|
592
|
+
// Must contain an icon element smaller than the tile
|
|
593
|
+
if (!hasIconChild) return [];
|
|
594
|
+
if (iconChildWidth && iconChildWidth >= siblingWidth * 0.95) return [];
|
|
595
|
+
|
|
596
|
+
// Vertical stacking: tile must end above where the heading starts.
|
|
597
|
+
// (Allow the check to skip when both top/bottom are 0 — jsdom layout case.)
|
|
598
|
+
if (headingTop && siblingBottom && siblingBottom > headingTop + 4) return [];
|
|
599
|
+
|
|
600
|
+
const text = (headingText || '').trim().slice(0, 60);
|
|
601
|
+
return [{
|
|
602
|
+
id: 'icon-tile-stack',
|
|
603
|
+
snippet: `${Math.round(siblingWidth)}x${Math.round(siblingHeight)}px icon tile above ${headingTag} "${text}"`,
|
|
604
|
+
}];
|
|
605
|
+
}
|
|
606
|
+
|
|
376
607
|
const LAYOUT_TRANSITION_PROPS = new Set([
|
|
377
608
|
'width', 'height', 'padding', 'margin',
|
|
378
609
|
'max-height', 'max-width', 'min-height', 'min-width',
|
|
@@ -626,13 +857,39 @@ function resolveBackground(el, win) {
|
|
|
626
857
|
return { r: 255, g: 255, b: 255 };
|
|
627
858
|
}
|
|
628
859
|
|
|
860
|
+
// Walk parents looking for a gradient background and return its color stops.
|
|
861
|
+
// Used as a fallback when resolveBackground() returns null because the
|
|
862
|
+
// effective background is a gradient (no single solid color to compare against).
|
|
863
|
+
function resolveGradientStops(el, win) {
|
|
864
|
+
let current = el;
|
|
865
|
+
while (current && current.nodeType === 1) {
|
|
866
|
+
const style = IS_BROWSER ? getComputedStyle(current) : win.getComputedStyle(current);
|
|
867
|
+
const bgImage = style.backgroundImage || '';
|
|
868
|
+
if (bgImage && bgImage !== 'none' && /gradient/i.test(bgImage)) {
|
|
869
|
+
const stops = parseGradientColors(bgImage);
|
|
870
|
+
if (stops.length > 0) return stops;
|
|
871
|
+
}
|
|
872
|
+
if (!IS_BROWSER) {
|
|
873
|
+
// jsdom doesn't decompose `background:` shorthand — peek at the raw inline style
|
|
874
|
+
const rawStyle = current.getAttribute?.('style') || '';
|
|
875
|
+
const bgMatch = rawStyle.match(/background(?:-image)?\s*:\s*([^;]+)/i);
|
|
876
|
+
if (bgMatch && /gradient/i.test(bgMatch[1])) {
|
|
877
|
+
const stops = parseGradientColors(bgMatch[1]);
|
|
878
|
+
if (stops.length > 0) return stops;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
current = current.parentElement;
|
|
882
|
+
}
|
|
883
|
+
return null;
|
|
884
|
+
}
|
|
885
|
+
|
|
629
886
|
// ─── Section 5: Element Adapters ────────────────────────────────────────────
|
|
630
887
|
|
|
631
888
|
// Browser adapters — call getComputedStyle/getBoundingClientRect on live DOM
|
|
632
889
|
|
|
633
890
|
function checkElementBordersDOM(el) {
|
|
634
891
|
const tag = el.tagName.toLowerCase();
|
|
635
|
-
if (
|
|
892
|
+
if (BORDER_SAFE_TAGS.has(tag)) return [];
|
|
636
893
|
const rect = el.getBoundingClientRect();
|
|
637
894
|
if (rect.width < 20 || rect.height < 20) return [];
|
|
638
895
|
const style = getComputedStyle(el);
|
|
@@ -651,21 +908,60 @@ function checkElementColorsDOM(el) {
|
|
|
651
908
|
const rect = el.getBoundingClientRect();
|
|
652
909
|
if (rect.width < 10 || rect.height < 10) return [];
|
|
653
910
|
const style = getComputedStyle(el);
|
|
654
|
-
const
|
|
911
|
+
const directText = [...el.childNodes].filter(n => n.nodeType === 3).map(n => n.textContent).join('');
|
|
912
|
+
const hasDirectText = directText.trim().length > 0;
|
|
913
|
+
const effectiveBg = resolveBackground(el);
|
|
655
914
|
return checkColors({
|
|
656
915
|
tag,
|
|
657
916
|
textColor: parseRgb(style.color),
|
|
658
917
|
bgColor: parseRgb(style.backgroundColor),
|
|
659
|
-
effectiveBg
|
|
918
|
+
effectiveBg,
|
|
919
|
+
effectiveBgStops: effectiveBg ? null : resolveGradientStops(el),
|
|
660
920
|
fontSize: parseFloat(style.fontSize) || 16,
|
|
661
921
|
fontWeight: parseInt(style.fontWeight) || 400,
|
|
662
922
|
hasDirectText,
|
|
923
|
+
isEmojiOnly: isEmojiOnlyText(directText),
|
|
663
924
|
bgClip: style.webkitBackgroundClip || style.backgroundClip || '',
|
|
664
925
|
bgImage: style.backgroundImage || '',
|
|
665
926
|
classList: el.getAttribute('class') || '',
|
|
666
927
|
});
|
|
667
928
|
}
|
|
668
929
|
|
|
930
|
+
function checkElementIconTileDOM(el) {
|
|
931
|
+
const tag = el.tagName.toLowerCase();
|
|
932
|
+
if (!HEADING_TAGS.has(tag)) return [];
|
|
933
|
+
const sibling = el.previousElementSibling;
|
|
934
|
+
if (!sibling) return [];
|
|
935
|
+
|
|
936
|
+
const sibRect = sibling.getBoundingClientRect();
|
|
937
|
+
const headRect = el.getBoundingClientRect();
|
|
938
|
+
const sibStyle = getComputedStyle(sibling);
|
|
939
|
+
|
|
940
|
+
// The tile may either contain an <svg>/<i> icon child, OR the tile itself
|
|
941
|
+
// may contain an emoji/symbol character directly as its only text content
|
|
942
|
+
// (the "card-icon" pattern from many AI-generated demos).
|
|
943
|
+
const iconChild = sibling.querySelector('svg, i[data-lucide], i[class*="fa-"], i[class*="icon"]');
|
|
944
|
+
const iconRect = iconChild?.getBoundingClientRect();
|
|
945
|
+
const sibDirectText = [...sibling.childNodes].filter(n => n.nodeType === 3).map(n => n.textContent).join('');
|
|
946
|
+
const hasInlineEmojiIcon = sibling.children.length === 0 && isEmojiOnlyText(sibDirectText);
|
|
947
|
+
|
|
948
|
+
return checkIconTile({
|
|
949
|
+
headingTag: tag,
|
|
950
|
+
headingText: el.textContent || '',
|
|
951
|
+
headingTop: headRect.top,
|
|
952
|
+
siblingTag: sibling.tagName.toLowerCase(),
|
|
953
|
+
siblingWidth: sibRect.width,
|
|
954
|
+
siblingHeight: sibRect.height,
|
|
955
|
+
siblingBottom: sibRect.bottom,
|
|
956
|
+
siblingBgColor: parseRgb(sibStyle.backgroundColor),
|
|
957
|
+
siblingBgImage: sibStyle.backgroundImage || '',
|
|
958
|
+
siblingBorderWidth: parseFloat(sibStyle.borderTopWidth) || 0,
|
|
959
|
+
siblingBorderRadius: parseFloat(sibStyle.borderRadius) || 0,
|
|
960
|
+
hasIconChild: !!iconChild || hasInlineEmojiIcon,
|
|
961
|
+
iconChildWidth: iconRect?.width || 0,
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
|
|
669
965
|
function checkElementMotionDOM(el) {
|
|
670
966
|
const tag = el.tagName.toLowerCase();
|
|
671
967
|
if (SAFE_TAGS.has(tag)) return [];
|
|
@@ -767,67 +1063,116 @@ function checkElementAIPaletteDOM(el) {
|
|
|
767
1063
|
|
|
768
1064
|
const QUALITY_TEXT_TAGS = new Set(['p', 'li', 'td', 'th', 'dd', 'blockquote', 'figcaption']);
|
|
769
1065
|
|
|
770
|
-
|
|
771
|
-
|
|
1066
|
+
// Resolve a CSS font-size value to pixels by walking up the parent chain.
|
|
1067
|
+
// Browsers resolve em/rem/% to px in getComputedStyle, but jsdom returns the
|
|
1068
|
+
// specified value verbatim — so for the Node path we walk parents ourselves.
|
|
1069
|
+
function resolveFontSizePx(el, win) {
|
|
1070
|
+
const chain = []; // raw font-size strings, leaf → root
|
|
1071
|
+
let cur = el;
|
|
1072
|
+
while (cur && cur.nodeType === 1) {
|
|
1073
|
+
const fs = (win ? win.getComputedStyle(cur) : getComputedStyle(cur)).fontSize;
|
|
1074
|
+
chain.push(fs || '');
|
|
1075
|
+
cur = cur.parentElement;
|
|
1076
|
+
}
|
|
1077
|
+
// Walk root → leaf, resolving each value relative to its parent context.
|
|
1078
|
+
let px = 16; // root default
|
|
1079
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
1080
|
+
const v = chain[i];
|
|
1081
|
+
if (!v || v === 'inherit') continue;
|
|
1082
|
+
const num = parseFloat(v);
|
|
1083
|
+
if (isNaN(num)) continue;
|
|
1084
|
+
if (v.endsWith('px')) px = num;
|
|
1085
|
+
else if (v.endsWith('rem')) px = num * 16;
|
|
1086
|
+
else if (v.endsWith('em')) px = num * px;
|
|
1087
|
+
else if (v.endsWith('%')) px = (num / 100) * px;
|
|
1088
|
+
else px = num; // unitless — already resolved
|
|
1089
|
+
}
|
|
1090
|
+
return px;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// Resolve a CSS length value (line-height, letter-spacing, etc.) given a
|
|
1094
|
+
// known font-size context. Returns null for "normal" / unparseable values.
|
|
1095
|
+
function resolveLengthPx(value, fontSizePx) {
|
|
1096
|
+
if (!value || value === 'normal' || value === 'auto' || value === 'inherit') return null;
|
|
1097
|
+
const num = parseFloat(value);
|
|
1098
|
+
if (isNaN(num)) return null;
|
|
1099
|
+
if (value.endsWith('px')) return num;
|
|
1100
|
+
if (value.endsWith('rem')) return num * 16;
|
|
1101
|
+
if (value.endsWith('em')) return num * fontSizePx;
|
|
1102
|
+
if (value.endsWith('%')) return (num / 100) * fontSizePx;
|
|
1103
|
+
// Unitless line-height = multiplier, return px equivalent
|
|
1104
|
+
return num * fontSizePx;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
// Pure quality checks. Most run on computed CSS and DOM-only inputs (work in
|
|
1108
|
+
// jsdom and the browser). Two checks (line-length, cramped-padding) gate on
|
|
1109
|
+
// element rect dimensions, which jsdom can't compute — pass `rect: null` from
|
|
1110
|
+
// the Node adapter to skip those.
|
|
1111
|
+
//
|
|
1112
|
+
// Both adapters resolve font-size, line-height and letter-spacing to pixels
|
|
1113
|
+
// before calling this so the pure function only deals with numbers.
|
|
1114
|
+
function checkQuality(opts) {
|
|
1115
|
+
const { el, tag, style, hasDirectText, textLen, fontSize, lineHeightPx, letterSpacingPx, rect, lineMax = 80 } = opts;
|
|
1116
|
+
const findings = [];
|
|
772
1117
|
// Skip browser extension injected elements
|
|
773
1118
|
const elId = el.id || '';
|
|
774
|
-
if (elId.startsWith('claude-') || elId.startsWith('cic-')) return
|
|
775
|
-
const style = getComputedStyle(el);
|
|
776
|
-
const findings = [];
|
|
1119
|
+
if (elId.startsWith('claude-') || elId.startsWith('cic-')) return findings;
|
|
777
1120
|
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
const fontSize = parseFloat(style.fontSize) || 16;
|
|
781
|
-
const rect = el.getBoundingClientRect();
|
|
782
|
-
|
|
783
|
-
// --- Line length too long ---
|
|
784
|
-
// Only flag if text is long enough to actually fill the line (>80 chars)
|
|
785
|
-
if (hasDirectText && QUALITY_TEXT_TAGS.has(tag) && rect.width > 0 && textLen > 80) {
|
|
1121
|
+
// --- Line length too long --- (browser-only: needs rect.width)
|
|
1122
|
+
if (rect && hasDirectText && QUALITY_TEXT_TAGS.has(tag) && rect.width > 0 && textLen > lineMax) {
|
|
786
1123
|
const charsPerLine = rect.width / (fontSize * 0.5);
|
|
787
|
-
if (charsPerLine >
|
|
788
|
-
findings.push({ id: 'line-length', snippet: `~${Math.round(charsPerLine)} chars/line (aim for
|
|
1124
|
+
if (charsPerLine > lineMax + 5) {
|
|
1125
|
+
findings.push({ id: 'line-length', snippet: `~${Math.round(charsPerLine)} chars/line (aim for <${lineMax})` });
|
|
789
1126
|
}
|
|
790
1127
|
}
|
|
791
1128
|
|
|
792
|
-
// --- Cramped padding (skip small
|
|
793
|
-
|
|
1129
|
+
// --- Cramped padding --- (browser-only: needs rect to skip small badges/labels)
|
|
1130
|
+
// Vertical and horizontal thresholds are independent because line-height
|
|
1131
|
+
// already provides built-in vertical breathing room (the line box is taller
|
|
1132
|
+
// than the cap height), but horizontal has no equivalent. Both scale with
|
|
1133
|
+
// font-size — bigger text demands proportionally more padding.
|
|
1134
|
+
// vertical: max(4px, fontSize × 0.3)
|
|
1135
|
+
// horizontal: max(8px, fontSize × 0.5)
|
|
1136
|
+
if (rect && hasDirectText && textLen > 20 && rect.width > 100 && rect.height > 30) {
|
|
794
1137
|
const borders = {
|
|
795
1138
|
top: parseFloat(style.borderTopWidth) || 0,
|
|
796
1139
|
right: parseFloat(style.borderRightWidth) || 0,
|
|
797
1140
|
bottom: parseFloat(style.borderBottomWidth) || 0,
|
|
798
1141
|
left: parseFloat(style.borderLeftWidth) || 0,
|
|
799
1142
|
};
|
|
800
|
-
// Need at least 2 borders (a container), or a non-transparent background
|
|
801
1143
|
const borderCount = Object.values(borders).filter(w => w > 0).length;
|
|
802
1144
|
const hasBg = style.backgroundColor && style.backgroundColor !== 'rgba(0, 0, 0, 0)';
|
|
803
1145
|
if (borderCount >= 2 || hasBg) {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
if (hasBg || borders.
|
|
807
|
-
if (hasBg || borders.
|
|
808
|
-
if (hasBg || borders.
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
1146
|
+
const vPads = [], hPads = [];
|
|
1147
|
+
if (hasBg || borders.top > 0) vPads.push(parseFloat(style.paddingTop) || 0);
|
|
1148
|
+
if (hasBg || borders.bottom > 0) vPads.push(parseFloat(style.paddingBottom) || 0);
|
|
1149
|
+
if (hasBg || borders.left > 0) hPads.push(parseFloat(style.paddingLeft) || 0);
|
|
1150
|
+
if (hasBg || borders.right > 0) hPads.push(parseFloat(style.paddingRight) || 0);
|
|
1151
|
+
|
|
1152
|
+
const vMin = vPads.length ? Math.min(...vPads) : Infinity;
|
|
1153
|
+
const hMin = hPads.length ? Math.min(...hPads) : Infinity;
|
|
1154
|
+
const vThresh = Math.max(4, fontSize * 0.3);
|
|
1155
|
+
const hThresh = Math.max(8, fontSize * 0.5);
|
|
1156
|
+
|
|
1157
|
+
// Emit at most one finding per element — pick whichever axis is worse.
|
|
1158
|
+
if (vMin < vThresh) {
|
|
1159
|
+
findings.push({ id: 'cramped-padding', snippet: `${vMin}px vertical padding (need ≥${vThresh.toFixed(1)}px for ${fontSize}px text)` });
|
|
1160
|
+
} else if (hMin < hThresh) {
|
|
1161
|
+
findings.push({ id: 'cramped-padding', snippet: `${hMin}px horizontal padding (need ≥${hThresh.toFixed(1)}px for ${fontSize}px text)` });
|
|
815
1162
|
}
|
|
816
1163
|
}
|
|
817
1164
|
}
|
|
818
1165
|
|
|
819
1166
|
// --- Tight line height ---
|
|
820
1167
|
if (hasDirectText && textLen > 50 && !['h1','h2','h3','h4','h5','h6'].includes(tag)) {
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
if (ratio < 1.3 && ratio > 0) {
|
|
1168
|
+
if (lineHeightPx != null && fontSize > 0) {
|
|
1169
|
+
const ratio = lineHeightPx / fontSize;
|
|
1170
|
+
if (ratio > 0 && ratio < 1.3) {
|
|
825
1171
|
findings.push({ id: 'tight-leading', snippet: `line-height ${ratio.toFixed(2)}x (need >=1.3)` });
|
|
826
1172
|
}
|
|
827
1173
|
}
|
|
828
1174
|
}
|
|
829
1175
|
|
|
830
|
-
|
|
831
1176
|
// --- Justified text (without hyphens) ---
|
|
832
1177
|
if (hasDirectText && style.textAlign === 'justify') {
|
|
833
1178
|
const hyphens = style.hyphens || style.webkitHyphens || '';
|
|
@@ -837,8 +1182,12 @@ function checkElementQualityDOM(el) {
|
|
|
837
1182
|
}
|
|
838
1183
|
|
|
839
1184
|
// --- Tiny body text ---
|
|
1185
|
+
// Only flag actual body content, not UI labels (buttons, tabs, badges, captions, footer text, etc.)
|
|
840
1186
|
if (hasDirectText && textLen > 20 && fontSize < 12) {
|
|
841
|
-
|
|
1187
|
+
const skipTags = ['sub', 'sup', 'code', 'kbd', 'samp', 'var', 'caption', 'figcaption'];
|
|
1188
|
+
const inUIContext = el.closest && el.closest('button, a, label, summary, [role="button"], [role="link"], [role="tab"], [role="menuitem"], [role="option"], nav, footer, [class*="badge" i], [class*="chip" i], [class*="pill" i], [class*="tag" i], [class*="label" i], [class*="caption" i]');
|
|
1189
|
+
const isUppercase = style.textTransform === 'uppercase';
|
|
1190
|
+
if (!skipTags.includes(tag) && !inUIContext && !isUppercase) {
|
|
842
1191
|
findings.push({ id: 'tiny-text', snippet: `${fontSize}px body text` });
|
|
843
1192
|
}
|
|
844
1193
|
}
|
|
@@ -851,10 +1200,9 @@ function checkElementQualityDOM(el) {
|
|
|
851
1200
|
}
|
|
852
1201
|
|
|
853
1202
|
// --- Wide letter spacing on body text ---
|
|
854
|
-
if (hasDirectText && textLen > 20) {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
const trackingEm = tracking / fontSize;
|
|
1203
|
+
if (hasDirectText && textLen > 20 && style.textTransform !== 'uppercase') {
|
|
1204
|
+
if (letterSpacingPx != null && letterSpacingPx > 0 && fontSize > 0) {
|
|
1205
|
+
const trackingEm = letterSpacingPx / fontSize;
|
|
858
1206
|
if (trackingEm > 0.05) {
|
|
859
1207
|
findings.push({ id: 'wide-tracking', snippet: `letter-spacing: ${trackingEm.toFixed(2)}em on body text` });
|
|
860
1208
|
}
|
|
@@ -864,53 +1212,144 @@ function checkElementQualityDOM(el) {
|
|
|
864
1212
|
return findings;
|
|
865
1213
|
}
|
|
866
1214
|
|
|
867
|
-
function
|
|
868
|
-
const
|
|
1215
|
+
function checkElementQualityDOM(el) {
|
|
1216
|
+
const tag = el.tagName.toLowerCase();
|
|
1217
|
+
const style = getComputedStyle(el);
|
|
1218
|
+
const hasDirectText = [...el.childNodes].some(n => n.nodeType === 3 && n.textContent.trim().length > 10);
|
|
1219
|
+
const textLen = el.textContent?.trim().length || 0;
|
|
1220
|
+
// Browser getComputedStyle resolves everything to px — direct parseFloat
|
|
1221
|
+
// works.
|
|
1222
|
+
const fontSize = parseFloat(style.fontSize) || 16;
|
|
1223
|
+
const lineHeightPx = resolveLengthPx(style.lineHeight, fontSize);
|
|
1224
|
+
const letterSpacingPx = resolveLengthPx(style.letterSpacing, fontSize);
|
|
1225
|
+
const rect = el.getBoundingClientRect();
|
|
1226
|
+
const lineMax = (typeof window !== 'undefined' && window.__IMPECCABLE_CONFIG__?.lineLengthMax) || 80;
|
|
1227
|
+
return checkQuality({ el, tag, style, hasDirectText, textLen, fontSize, lineHeightPx, letterSpacingPx, rect, lineMax });
|
|
1228
|
+
}
|
|
869
1229
|
|
|
870
|
-
|
|
871
|
-
|
|
1230
|
+
// Pure page-level skipped-heading walk. Takes a Document so it works in both
|
|
1231
|
+
// the browser and jsdom.
|
|
1232
|
+
function checkPageQualityFromDoc(doc) {
|
|
1233
|
+
const findings = [];
|
|
1234
|
+
const headings = doc.querySelectorAll('h1, h2, h3, h4, h5, h6');
|
|
872
1235
|
let prevLevel = 0;
|
|
1236
|
+
let prevText = '';
|
|
873
1237
|
for (const h of headings) {
|
|
874
1238
|
const level = parseInt(h.tagName[1]);
|
|
1239
|
+
const text = (h.textContent || '').trim().replace(/\s+/g, ' ').slice(0, 60);
|
|
875
1240
|
if (prevLevel > 0 && level > prevLevel + 1) {
|
|
876
|
-
findings.push({
|
|
1241
|
+
findings.push({
|
|
1242
|
+
id: 'skipped-heading',
|
|
1243
|
+
snippet: `<h${prevLevel}> "${prevText}" followed by <h${level}> "${text}" (missing h${prevLevel + 1})`,
|
|
1244
|
+
});
|
|
877
1245
|
}
|
|
878
1246
|
prevLevel = level;
|
|
1247
|
+
prevText = text;
|
|
879
1248
|
}
|
|
880
|
-
|
|
881
1249
|
return findings;
|
|
882
1250
|
}
|
|
883
1251
|
|
|
1252
|
+
// Browser adapter (returns the legacy { type, detail } shape used by the overlay loop)
|
|
1253
|
+
function checkPageQualityDOM() {
|
|
1254
|
+
return checkPageQualityFromDoc(document).map(f => ({ type: f.id, detail: f.snippet }));
|
|
1255
|
+
}
|
|
1256
|
+
|
|
884
1257
|
// Node adapters — take pre-extracted jsdom computed style
|
|
885
1258
|
|
|
886
|
-
|
|
1259
|
+
// jsdom doesn't lay out OR resolve em/rem/% to px — so we pre-resolve every
|
|
1260
|
+
// CSS length the rule needs ourselves (walking the parent chain for
|
|
1261
|
+
// font-size inheritance), and pass `rect: null` to skip the two rules that
|
|
1262
|
+
// genuinely need element rects (line-length, cramped-padding).
|
|
1263
|
+
function checkElementQuality(el, style, tag, window) {
|
|
1264
|
+
const hasDirectText = [...el.childNodes].some(n => n.nodeType === 3 && n.textContent.trim().length > 10);
|
|
1265
|
+
const textLen = el.textContent?.trim().length || 0;
|
|
1266
|
+
const fontSize = resolveFontSizePx(el, window);
|
|
1267
|
+
const lineHeightPx = resolveLengthPx(style.lineHeight, fontSize);
|
|
1268
|
+
const letterSpacingPx = resolveLengthPx(style.letterSpacing, fontSize);
|
|
1269
|
+
return checkQuality({ el, tag, style, hasDirectText, textLen, fontSize, lineHeightPx, letterSpacingPx, rect: null });
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
function checkElementBorders(tag, style, overrides) {
|
|
887
1273
|
const sides = ['Top', 'Right', 'Bottom', 'Left'];
|
|
888
1274
|
const widths = {}, colors = {};
|
|
889
1275
|
for (const s of sides) {
|
|
890
1276
|
widths[s] = parseFloat(style[`border${s}Width`]) || 0;
|
|
891
1277
|
colors[s] = style[`border${s}Color`] || '';
|
|
1278
|
+
// jsdom silently drops any border shorthand containing var(), leaving
|
|
1279
|
+
// both width and color empty on the computed style. When the detectHtml
|
|
1280
|
+
// pre-pass pulled a resolved value off the rule, use it to fill in the
|
|
1281
|
+
// missing side so the side-tab check can run. Real browsers resolve
|
|
1282
|
+
// var() natively, so this fallback is a no-op in the browser path.
|
|
1283
|
+
if (widths[s] === 0 && overrides && overrides[s]) {
|
|
1284
|
+
widths[s] = overrides[s].width;
|
|
1285
|
+
colors[s] = overrides[s].color;
|
|
1286
|
+
} else if (colors[s] && colors[s].startsWith('var(') && overrides && overrides[s]) {
|
|
1287
|
+
// Longhand case: jsdom kept the width but left the color as the
|
|
1288
|
+
// literal `var(...)` string. Substitute the resolved color.
|
|
1289
|
+
colors[s] = overrides[s].color;
|
|
1290
|
+
}
|
|
892
1291
|
}
|
|
893
1292
|
return checkBorders(tag, widths, colors, parseFloat(style.borderRadius) || 0);
|
|
894
1293
|
}
|
|
895
1294
|
|
|
896
1295
|
function checkElementColors(el, style, tag, window) {
|
|
897
|
-
const
|
|
898
|
-
const hasDirectText =
|
|
1296
|
+
const directText = [...el.childNodes].filter(n => n.nodeType === 3).map(n => n.textContent).join('');
|
|
1297
|
+
const hasDirectText = directText.trim().length > 0;
|
|
899
1298
|
|
|
1299
|
+
const effectiveBg = resolveBackground(el, window);
|
|
900
1300
|
return checkColors({
|
|
901
1301
|
tag,
|
|
902
1302
|
textColor: parseRgb(style.color),
|
|
903
1303
|
bgColor: parseRgb(style.backgroundColor),
|
|
904
|
-
effectiveBg
|
|
1304
|
+
effectiveBg,
|
|
1305
|
+
effectiveBgStops: effectiveBg ? null : resolveGradientStops(el, window),
|
|
905
1306
|
fontSize: parseFloat(style.fontSize) || 16,
|
|
906
1307
|
fontWeight: parseInt(style.fontWeight) || 400,
|
|
907
1308
|
hasDirectText,
|
|
1309
|
+
isEmojiOnly: isEmojiOnlyText(directText),
|
|
908
1310
|
bgClip: style.webkitBackgroundClip || style.backgroundClip || '',
|
|
909
1311
|
bgImage: style.backgroundImage || '',
|
|
910
1312
|
classList: el.getAttribute?.('class') || el.className || '',
|
|
911
1313
|
});
|
|
912
1314
|
}
|
|
913
1315
|
|
|
1316
|
+
function checkElementIconTile(el, tag, window) {
|
|
1317
|
+
if (!HEADING_TAGS.has(tag)) return [];
|
|
1318
|
+
const sibling = el.previousElementSibling;
|
|
1319
|
+
if (!sibling) return [];
|
|
1320
|
+
|
|
1321
|
+
const sibStyle = window.getComputedStyle(sibling);
|
|
1322
|
+
// jsdom doesn't lay out — read explicit pixel dimensions from CSS instead.
|
|
1323
|
+
const sibWidth = parseFloat(sibStyle.width) || 0;
|
|
1324
|
+
const sibHeight = parseFloat(sibStyle.height) || 0;
|
|
1325
|
+
|
|
1326
|
+
const iconChild = sibling.querySelector('svg, i[data-lucide], i[class*="fa-"], i[class*="icon"]');
|
|
1327
|
+
let iconWidth = 0;
|
|
1328
|
+
if (iconChild) {
|
|
1329
|
+
const iconStyle = window.getComputedStyle(iconChild);
|
|
1330
|
+
iconWidth = parseFloat(iconStyle.width) || parseFloat(iconChild.getAttribute('width')) || 0;
|
|
1331
|
+
}
|
|
1332
|
+
// Or: tile contains an emoji/symbol character directly as its only content
|
|
1333
|
+
const sibDirectText = [...sibling.childNodes].filter(n => n.nodeType === 3).map(n => n.textContent).join('');
|
|
1334
|
+
const hasInlineEmojiIcon = sibling.children.length === 0 && isEmojiOnlyText(sibDirectText);
|
|
1335
|
+
|
|
1336
|
+
return checkIconTile({
|
|
1337
|
+
headingTag: tag,
|
|
1338
|
+
headingText: el.textContent || '',
|
|
1339
|
+
headingTop: 0, // jsdom: no layout, skip vertical-stacking gate
|
|
1340
|
+
siblingTag: sibling.tagName.toLowerCase(),
|
|
1341
|
+
siblingWidth: sibWidth,
|
|
1342
|
+
siblingHeight: sibHeight,
|
|
1343
|
+
siblingBottom: 0,
|
|
1344
|
+
siblingBgColor: parseRgb(sibStyle.backgroundColor),
|
|
1345
|
+
siblingBgImage: sibStyle.backgroundImage || '',
|
|
1346
|
+
siblingBorderWidth: parseFloat(sibStyle.borderTopWidth) || 0,
|
|
1347
|
+
siblingBorderRadius: parseFloat(sibStyle.borderRadius) || 0,
|
|
1348
|
+
hasIconChild: !!iconChild || hasInlineEmojiIcon,
|
|
1349
|
+
iconChildWidth: iconWidth,
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
|
|
914
1353
|
function checkElementMotion(tag, style) {
|
|
915
1354
|
return checkMotion({
|
|
916
1355
|
tag,
|
|
@@ -932,41 +1371,45 @@ function checkElementGlow(tag, style, effectiveBg) {
|
|
|
932
1371
|
|
|
933
1372
|
function checkTypography() {
|
|
934
1373
|
const findings = [];
|
|
935
|
-
const fonts = new Set();
|
|
936
|
-
const overusedFound = new Set();
|
|
937
1374
|
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
1375
|
+
// Walk actual text-bearing elements and tally font usage by *computed style*.
|
|
1376
|
+
// This is much more accurate than scanning CSS rules — it ignores rules that
|
|
1377
|
+
// exist in the stylesheet but apply to nothing (e.g. demo classes showing
|
|
1378
|
+
// anti-patterns), and counts what the user actually sees.
|
|
1379
|
+
const fontUsage = new Map(); // primary font name → count of elements
|
|
1380
|
+
let totalTextElements = 0;
|
|
1381
|
+
for (const el of document.querySelectorAll('p, h1, h2, h3, h4, h5, h6, li, td, th, dd, blockquote, figcaption, a, button, label, span')) {
|
|
1382
|
+
// Skip impeccable's own elements
|
|
1383
|
+
if (el.closest && el.closest('.impeccable-overlay, .impeccable-label, .impeccable-banner, .impeccable-tooltip')) continue;
|
|
1384
|
+
// Only count elements that actually have visible direct text
|
|
1385
|
+
const hasText = [...el.childNodes].some(n => n.nodeType === 3 && n.textContent.trim().length > 0);
|
|
1386
|
+
if (!hasText) continue;
|
|
1387
|
+
const style = getComputedStyle(el);
|
|
1388
|
+
const ff = style.fontFamily;
|
|
1389
|
+
if (!ff) continue;
|
|
1390
|
+
const stack = ff.split(',').map(f => f.trim().replace(/^['"]|['"]$/g, '').toLowerCase());
|
|
1391
|
+
const primary = stack.find(f => f && !GENERIC_FONTS.has(f));
|
|
1392
|
+
if (!primary) continue;
|
|
1393
|
+
fontUsage.set(primary, (fontUsage.get(primary) || 0) + 1);
|
|
1394
|
+
totalTextElements++;
|
|
953
1395
|
}
|
|
954
1396
|
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
if (OVERUSED_FONTS.has(
|
|
1397
|
+
if (totalTextElements >= 20) {
|
|
1398
|
+
// A font is "primary" if it's used by at least 15% of text elements
|
|
1399
|
+
const PRIMARY_THRESHOLD = 0.15;
|
|
1400
|
+
for (const [font, count] of fontUsage) {
|
|
1401
|
+
const share = count / totalTextElements;
|
|
1402
|
+
if (share < PRIMARY_THRESHOLD) continue;
|
|
1403
|
+
if (!OVERUSED_FONTS.has(font)) continue;
|
|
1404
|
+
if (isBrandFontOnOwnDomain(font)) continue;
|
|
1405
|
+
findings.push({ type: 'overused-font', detail: `Primary font: ${font} (${Math.round(share * 100)}% of text)` });
|
|
962
1406
|
}
|
|
963
|
-
}
|
|
964
1407
|
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1408
|
+
// Single-font check: only one distinct primary font across all text
|
|
1409
|
+
if (fontUsage.size === 1) {
|
|
1410
|
+
const only = [...fontUsage.keys()][0];
|
|
1411
|
+
findings.push({ type: 'single-font', detail: `only font used is ${only}` });
|
|
1412
|
+
}
|
|
970
1413
|
}
|
|
971
1414
|
|
|
972
1415
|
const sizes = new Set();
|
|
@@ -1209,52 +1652,143 @@ function checkPageLayout(doc, win) {
|
|
|
1209
1652
|
// ─── Section 7: Browser UI (IS_BROWSER only) ────────────────────────────────
|
|
1210
1653
|
|
|
1211
1654
|
if (IS_BROWSER) {
|
|
1212
|
-
|
|
1213
|
-
|
|
1655
|
+
// Detect extension mode via the script tag's data attribute or the document element fallback.
|
|
1656
|
+
// currentScript is reliable for synchronously-executing scripts (which our IIFE is).
|
|
1657
|
+
const _myScript = document.currentScript;
|
|
1658
|
+
const EXTENSION_MODE = (_myScript && _myScript.dataset.impeccableExtension === 'true')
|
|
1659
|
+
|| document.documentElement.dataset.impeccableExtension === 'true';
|
|
1660
|
+
|
|
1661
|
+
const BRAND_COLOR = 'oklch(55% 0.25 350)';
|
|
1662
|
+
const BRAND_COLOR_HOVER = 'oklch(45% 0.25 350)';
|
|
1663
|
+
const LABEL_BG = BRAND_COLOR;
|
|
1664
|
+
const OUTLINE_COLOR = BRAND_COLOR;
|
|
1214
1665
|
|
|
1215
1666
|
// Inject hover styles via CSS (more reliable than JS event listeners)
|
|
1216
1667
|
const styleEl = document.createElement('style');
|
|
1217
1668
|
styleEl.textContent = `
|
|
1218
1669
|
@keyframes impeccable-reveal {
|
|
1219
|
-
from { opacity: 0;
|
|
1220
|
-
to { opacity: 1;
|
|
1670
|
+
from { opacity: 0; }
|
|
1671
|
+
to { opacity: 1; }
|
|
1221
1672
|
}
|
|
1222
1673
|
.impeccable-overlay:not(.impeccable-banner) {
|
|
1223
1674
|
pointer-events: none;
|
|
1224
1675
|
outline: 2px solid ${OUTLINE_COLOR};
|
|
1225
1676
|
border-radius: 4px;
|
|
1226
|
-
transition: outline-color 0.
|
|
1677
|
+
transition: outline-color 0.15s ease;
|
|
1227
1678
|
animation: impeccable-reveal 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
1228
1679
|
animation-play-state: paused;
|
|
1680
|
+
border-top-left-radius: 0;
|
|
1229
1681
|
}
|
|
1230
1682
|
.impeccable-overlay.impeccable-visible {
|
|
1231
1683
|
animation-play-state: running;
|
|
1232
1684
|
}
|
|
1233
1685
|
.impeccable-overlay.impeccable-hover {
|
|
1234
|
-
outline-color:
|
|
1686
|
+
outline-color: ${BRAND_COLOR_HOVER};
|
|
1235
1687
|
z-index: 100001 !important;
|
|
1236
1688
|
}
|
|
1237
|
-
.impeccable-label
|
|
1238
|
-
|
|
1239
|
-
|
|
1689
|
+
.impeccable-overlay.impeccable-hover .impeccable-label {
|
|
1690
|
+
background: ${BRAND_COLOR_HOVER};
|
|
1691
|
+
}
|
|
1692
|
+
.impeccable-overlay.impeccable-spotlight {
|
|
1693
|
+
z-index: 100002 !important;
|
|
1694
|
+
}
|
|
1695
|
+
.impeccable-overlay.impeccable-spotlight-dimmed {
|
|
1696
|
+
opacity: 0.15 !important;
|
|
1697
|
+
animation: none !important;
|
|
1698
|
+
filter: blur(3px);
|
|
1699
|
+
}
|
|
1700
|
+
.impeccable-spotlight-backdrop {
|
|
1701
|
+
position: fixed;
|
|
1702
|
+
top: 0; left: 0; right: 0; bottom: 0;
|
|
1703
|
+
backdrop-filter: blur(3px) brightness(0.6);
|
|
1704
|
+
-webkit-backdrop-filter: blur(3px) brightness(0.6);
|
|
1705
|
+
pointer-events: none;
|
|
1706
|
+
z-index: 99998;
|
|
1707
|
+
opacity: 0;
|
|
1708
|
+
outline: none !important;
|
|
1709
|
+
animation: none !important;
|
|
1240
1710
|
}
|
|
1241
|
-
.impeccable-
|
|
1242
|
-
|
|
1711
|
+
.impeccable-spotlight-backdrop.impeccable-visible {
|
|
1712
|
+
opacity: 1;
|
|
1243
1713
|
}
|
|
1244
|
-
.impeccable-
|
|
1245
|
-
|
|
1246
|
-
transform: translateY(-100%);
|
|
1714
|
+
.impeccable-hidden .impeccable-overlay${EXTENSION_MODE ? '' : ':not(.impeccable-banner)'} {
|
|
1715
|
+
display: none !important;
|
|
1247
1716
|
}
|
|
1248
|
-
.impeccable-hidden .impeccable-overlay:not(.impeccable-banner) {
|
|
1717
|
+
.impeccable-hidden .impeccable-overlay${EXTENSION_MODE ? '' : ':not(.impeccable-banner)'} {
|
|
1249
1718
|
display: none !important;
|
|
1250
1719
|
}
|
|
1251
1720
|
`;
|
|
1252
1721
|
(document.head || document.documentElement).appendChild(styleEl);
|
|
1253
1722
|
|
|
1723
|
+
// Spotlight backdrop element (created lazily on first use)
|
|
1724
|
+
let spotlightBackdrop = null;
|
|
1725
|
+
let spotlightTarget = null;
|
|
1726
|
+
let spotlightTimer = null;
|
|
1727
|
+
|
|
1728
|
+
function getSpotlightBackdrop() {
|
|
1729
|
+
if (!spotlightBackdrop) {
|
|
1730
|
+
spotlightBackdrop = document.createElement('div');
|
|
1731
|
+
spotlightBackdrop.className = 'impeccable-spotlight-backdrop';
|
|
1732
|
+
document.body.appendChild(spotlightBackdrop);
|
|
1733
|
+
}
|
|
1734
|
+
return spotlightBackdrop;
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
function updateSpotlightClipPath() {
|
|
1738
|
+
if (!spotlightBackdrop || !spotlightTarget) return;
|
|
1739
|
+
const r = spotlightTarget.getBoundingClientRect();
|
|
1740
|
+
// Match the overlay's outer edge: element rect + 4px (2px overlay offset + 2px outline width)
|
|
1741
|
+
const inset = 4;
|
|
1742
|
+
const radius = 6; // outline border-radius (4) + outline width (2)
|
|
1743
|
+
const x1 = r.left - inset;
|
|
1744
|
+
const y1 = r.top - inset;
|
|
1745
|
+
const x2 = r.right + inset;
|
|
1746
|
+
const y2 = r.bottom + inset;
|
|
1747
|
+
const vw = window.innerWidth;
|
|
1748
|
+
const vh = window.innerHeight;
|
|
1749
|
+
// Outer rect + rounded inner rect (evenodd creates a hole)
|
|
1750
|
+
const path = `M0 0H${vw}V${vh}H0Z M${x1 + radius} ${y1}H${x2 - radius}A${radius} ${radius} 0 0 1 ${x2} ${y1 + radius}V${y2 - radius}A${radius} ${radius} 0 0 1 ${x2 - radius} ${y2}H${x1 + radius}A${radius} ${radius} 0 0 1 ${x1} ${y2 - radius}V${y1 + radius}A${radius} ${radius} 0 0 1 ${x1 + radius} ${y1}Z`;
|
|
1751
|
+
spotlightBackdrop.style.clipPath = `path(evenodd, "${path}")`;
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
function showSpotlight(target) {
|
|
1755
|
+
if (!target || !target.getBoundingClientRect) return;
|
|
1756
|
+
// Respect the spotlightBlur setting: if disabled, don't show the backdrop
|
|
1757
|
+
if (window.__IMPECCABLE_CONFIG__?.spotlightBlur === false) {
|
|
1758
|
+
spotlightTarget = target;
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1761
|
+
spotlightTarget = target;
|
|
1762
|
+
const bd = getSpotlightBackdrop();
|
|
1763
|
+
updateSpotlightClipPath();
|
|
1764
|
+
bd.classList.add('impeccable-visible');
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
function hideSpotlight() {
|
|
1768
|
+
spotlightTarget = null;
|
|
1769
|
+
if (spotlightTimer) { clearTimeout(spotlightTimer); spotlightTimer = null; }
|
|
1770
|
+
if (spotlightBackdrop) spotlightBackdrop.classList.remove('impeccable-visible');
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
function isInViewport(el) {
|
|
1774
|
+
const r = el.getBoundingClientRect();
|
|
1775
|
+
return r.top >= 0 && r.left >= 0 && r.bottom <= window.innerHeight && r.right <= window.innerWidth;
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
// Reposition spotlight on scroll/resize
|
|
1779
|
+
window.addEventListener('scroll', () => {
|
|
1780
|
+
if (spotlightTarget) updateSpotlightClipPath();
|
|
1781
|
+
}, { passive: true });
|
|
1782
|
+
window.addEventListener('resize', () => {
|
|
1783
|
+
if (spotlightTarget) updateSpotlightClipPath();
|
|
1784
|
+
});
|
|
1785
|
+
|
|
1254
1786
|
const overlays = [];
|
|
1255
1787
|
const TYPE_LABELS = {};
|
|
1788
|
+
const RULE_CATEGORY = {};
|
|
1256
1789
|
for (const ap of ANTIPATTERNS) {
|
|
1257
|
-
TYPE_LABELS[ap.id] = ap.name.toLowerCase()
|
|
1790
|
+
TYPE_LABELS[ap.id] = ap.name.toLowerCase();
|
|
1791
|
+
RULE_CATEGORY[ap.id] = ap.category || 'quality';
|
|
1258
1792
|
}
|
|
1259
1793
|
|
|
1260
1794
|
function isInFixedContext(el) {
|
|
@@ -1286,6 +1820,8 @@ if (IS_BROWSER) {
|
|
|
1286
1820
|
function repositionOverlays() {
|
|
1287
1821
|
for (const o of overlays) {
|
|
1288
1822
|
if (!o._targetEl || o.classList.contains('impeccable-banner')) continue;
|
|
1823
|
+
// Skip overlays whose target is currently hidden (display: none on the overlay)
|
|
1824
|
+
if (o.style.display === 'none') continue;
|
|
1289
1825
|
positionOverlay(o);
|
|
1290
1826
|
}
|
|
1291
1827
|
}
|
|
@@ -1296,6 +1832,13 @@ if (IS_BROWSER) {
|
|
|
1296
1832
|
resizeRAF = requestAnimationFrame(repositionOverlays);
|
|
1297
1833
|
};
|
|
1298
1834
|
window.addEventListener('resize', onResize);
|
|
1835
|
+
// Reposition on scroll too -- catches sticky/parallax shifts
|
|
1836
|
+
window.addEventListener('scroll', onResize, { passive: true });
|
|
1837
|
+
// Reposition when body resizes (lazy-loaded images, dynamic content, fonts loading)
|
|
1838
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
1839
|
+
const bodyResizeObserver = new ResizeObserver(onResize);
|
|
1840
|
+
bodyResizeObserver.observe(document.body);
|
|
1841
|
+
}
|
|
1299
1842
|
|
|
1300
1843
|
// Track target element visibility via IntersectionObserver.
|
|
1301
1844
|
// Uses a huge rootMargin so all *rendered* elements count as intersecting,
|
|
@@ -1311,8 +1854,17 @@ if (IS_BROWSER) {
|
|
|
1311
1854
|
positionOverlay(overlay);
|
|
1312
1855
|
if (!overlay._revealed) {
|
|
1313
1856
|
overlay._revealed = true;
|
|
1314
|
-
|
|
1315
|
-
|
|
1857
|
+
if (firstScanDone) {
|
|
1858
|
+
// Subsequent reveals (re-scans, scroll-into-view): instant, no animation
|
|
1859
|
+
overlay.style.animation = 'none';
|
|
1860
|
+
} else {
|
|
1861
|
+
// Initial scan: staggered cascade reveal
|
|
1862
|
+
overlay.style.animationDelay = `${Math.min((overlay._staggerIndex || 0) * 60, 600)}ms`;
|
|
1863
|
+
}
|
|
1864
|
+
requestAnimationFrame(() => {
|
|
1865
|
+
overlay.classList.add('impeccable-visible');
|
|
1866
|
+
if (overlay._checkLabel) overlay._checkLabel();
|
|
1867
|
+
});
|
|
1316
1868
|
}
|
|
1317
1869
|
} else {
|
|
1318
1870
|
overlay.style.display = 'none';
|
|
@@ -1334,6 +1886,8 @@ if (IS_BROWSER) {
|
|
|
1334
1886
|
});
|
|
1335
1887
|
|
|
1336
1888
|
const highlight = function(el, findings) {
|
|
1889
|
+
const hasSlop = findings.some(f => RULE_CATEGORY[f.type || f.id] === 'slop');
|
|
1890
|
+
|
|
1337
1891
|
const fixed = isInFixedContext(el);
|
|
1338
1892
|
const rect = el.getBoundingClientRect();
|
|
1339
1893
|
const outline = document.createElement('div');
|
|
@@ -1348,33 +1902,85 @@ if (IS_BROWSER) {
|
|
|
1348
1902
|
zIndex: '99999', boxSizing: 'border-box',
|
|
1349
1903
|
});
|
|
1350
1904
|
|
|
1351
|
-
|
|
1352
|
-
const
|
|
1905
|
+
// Build per-finding label entries: ✦ prefix for slop
|
|
1906
|
+
const entries = findings.map(f => {
|
|
1907
|
+
const name = TYPE_LABELS[f.type || f.id] || f.type || f.id;
|
|
1908
|
+
const prefix = RULE_CATEGORY[f.type || f.id] === 'slop' ? '\u2726 ' : '';
|
|
1909
|
+
return { name: prefix + name, detail: f.detail || f.snippet };
|
|
1910
|
+
});
|
|
1911
|
+
const allText = entries.map(e => e.name).join(', ');
|
|
1353
1912
|
|
|
1354
1913
|
const label = document.createElement('div');
|
|
1355
1914
|
label.className = 'impeccable-label';
|
|
1356
1915
|
Object.assign(label.style, {
|
|
1357
|
-
position: 'absolute',
|
|
1358
|
-
|
|
1916
|
+
position: 'absolute', bottom: '100%', left: '-2px',
|
|
1917
|
+
display: 'flex', alignItems: 'center',
|
|
1918
|
+
whiteSpace: 'nowrap',
|
|
1919
|
+
fontSize: '11px', fontWeight: '600', letterSpacing: '0.02em',
|
|
1920
|
+
color: 'white', lineHeight: '14px',
|
|
1921
|
+
background: LABEL_BG,
|
|
1922
|
+
fontFamily: 'system-ui, sans-serif',
|
|
1923
|
+
borderRadius: '4px 4px 0 0',
|
|
1359
1924
|
});
|
|
1360
1925
|
|
|
1361
|
-
const
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1926
|
+
const textSpan = document.createElement('span');
|
|
1927
|
+
textSpan.style.padding = '3px 8px';
|
|
1928
|
+
textSpan.textContent = allText;
|
|
1929
|
+
label.appendChild(textSpan);
|
|
1930
|
+
|
|
1931
|
+
// State for cycling mode
|
|
1932
|
+
let cycleMode = false;
|
|
1933
|
+
let cycleIndex = 0;
|
|
1934
|
+
let isHovered = false;
|
|
1935
|
+
let prevBtn, nextBtn;
|
|
1936
|
+
|
|
1937
|
+
function updateCycleText() {
|
|
1938
|
+
const e = entries[cycleIndex];
|
|
1939
|
+
textSpan.textContent = isHovered ? e.detail : e.name;
|
|
1940
|
+
}
|
|
1366
1941
|
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
Object.assign(nameRow.style, { ...rowBase, background: LABEL_BG, fontFamily: 'system-ui, sans-serif' });
|
|
1371
|
-
label.appendChild(nameRow);
|
|
1942
|
+
function enableCycleMode() {
|
|
1943
|
+
if (cycleMode || entries.length < 2) return;
|
|
1944
|
+
cycleMode = true;
|
|
1372
1945
|
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1946
|
+
const btnStyle = {
|
|
1947
|
+
background: 'none', border: 'none', color: 'rgba(255,255,255,0.7)',
|
|
1948
|
+
fontSize: '11px', cursor: 'pointer', padding: '3px 4px',
|
|
1949
|
+
fontFamily: 'system-ui, sans-serif', lineHeight: '14px',
|
|
1950
|
+
pointerEvents: 'auto',
|
|
1951
|
+
};
|
|
1952
|
+
|
|
1953
|
+
const navGroup = document.createElement('span');
|
|
1954
|
+
Object.assign(navGroup.style, {
|
|
1955
|
+
display: 'inline-flex', alignItems: 'center', flexShrink: '0',
|
|
1956
|
+
});
|
|
1957
|
+
|
|
1958
|
+
prevBtn = document.createElement('button');
|
|
1959
|
+
prevBtn.textContent = '\u2039';
|
|
1960
|
+
Object.assign(prevBtn.style, btnStyle);
|
|
1961
|
+
prevBtn.style.paddingLeft = '6px';
|
|
1962
|
+
prevBtn.addEventListener('click', (e) => {
|
|
1963
|
+
e.stopPropagation();
|
|
1964
|
+
cycleIndex = (cycleIndex - 1 + entries.length) % entries.length;
|
|
1965
|
+
updateCycleText();
|
|
1966
|
+
});
|
|
1967
|
+
|
|
1968
|
+
nextBtn = document.createElement('button');
|
|
1969
|
+
nextBtn.textContent = '\u203A';
|
|
1970
|
+
Object.assign(nextBtn.style, btnStyle);
|
|
1971
|
+
nextBtn.style.paddingRight = '2px';
|
|
1972
|
+
nextBtn.addEventListener('click', (e) => {
|
|
1973
|
+
e.stopPropagation();
|
|
1974
|
+
cycleIndex = (cycleIndex + 1) % entries.length;
|
|
1975
|
+
updateCycleText();
|
|
1976
|
+
});
|
|
1977
|
+
|
|
1978
|
+
navGroup.appendChild(prevBtn);
|
|
1979
|
+
navGroup.appendChild(nextBtn);
|
|
1980
|
+
label.insertBefore(navGroup, textSpan);
|
|
1981
|
+
textSpan.style.padding = '3px 8px 3px 4px';
|
|
1982
|
+
updateCycleText();
|
|
1983
|
+
}
|
|
1378
1984
|
|
|
1379
1985
|
outline.appendChild(label);
|
|
1380
1986
|
|
|
@@ -1384,9 +1990,36 @@ if (IS_BROWSER) {
|
|
|
1384
1990
|
el._impeccableOverlay = outline;
|
|
1385
1991
|
visibilityObserver.observe(el);
|
|
1386
1992
|
|
|
1387
|
-
//
|
|
1388
|
-
|
|
1389
|
-
|
|
1993
|
+
// After first paint, check label width vs outline
|
|
1994
|
+
outline._checkLabel = () => {
|
|
1995
|
+
if (entries.length > 1 && label.offsetWidth > outline.offsetWidth) {
|
|
1996
|
+
enableCycleMode();
|
|
1997
|
+
}
|
|
1998
|
+
};
|
|
1999
|
+
|
|
2000
|
+
// Hover: show detail text, darken
|
|
2001
|
+
el.addEventListener('mouseenter', () => {
|
|
2002
|
+
isHovered = true;
|
|
2003
|
+
outline.classList.add('impeccable-hover');
|
|
2004
|
+
outline.style.outlineColor = BRAND_COLOR_HOVER;
|
|
2005
|
+
label.style.background = BRAND_COLOR_HOVER;
|
|
2006
|
+
if (cycleMode) {
|
|
2007
|
+
updateCycleText();
|
|
2008
|
+
} else {
|
|
2009
|
+
textSpan.textContent = entries.map(e => e.detail).join(' | ');
|
|
2010
|
+
}
|
|
2011
|
+
});
|
|
2012
|
+
el.addEventListener('mouseleave', () => {
|
|
2013
|
+
isHovered = false;
|
|
2014
|
+
outline.classList.remove('impeccable-hover');
|
|
2015
|
+
outline.style.outlineColor = '';
|
|
2016
|
+
label.style.background = LABEL_BG;
|
|
2017
|
+
if (cycleMode) {
|
|
2018
|
+
updateCycleText();
|
|
2019
|
+
} else {
|
|
2020
|
+
textSpan.textContent = allText;
|
|
2021
|
+
}
|
|
2022
|
+
});
|
|
1390
2023
|
|
|
1391
2024
|
document.body.appendChild(outline);
|
|
1392
2025
|
overlays.push(outline);
|
|
@@ -1418,8 +2051,9 @@ if (IS_BROWSER) {
|
|
|
1418
2051
|
scrollbarWidth: 'none',
|
|
1419
2052
|
});
|
|
1420
2053
|
for (const f of findings) {
|
|
2054
|
+
const prefix = RULE_CATEGORY[f.type] === 'slop' ? '\u2726 ' : '';
|
|
1421
2055
|
const tag = document.createElement('span');
|
|
1422
|
-
tag.textContent = `${TYPE_LABELS[f.type] || f.type}: ${f.detail}`;
|
|
2056
|
+
tag.textContent = `${prefix}${TYPE_LABELS[f.type] || f.type}: ${f.detail}`;
|
|
1423
2057
|
Object.assign(tag.style, {
|
|
1424
2058
|
background: 'rgba(255,255,255,0.15)', padding: '2px 8px',
|
|
1425
2059
|
borderRadius: '3px', fontSize: '12px', fontFamily: 'ui-monospace, monospace',
|
|
@@ -1429,47 +2063,153 @@ if (IS_BROWSER) {
|
|
|
1429
2063
|
}
|
|
1430
2064
|
banner.appendChild(scrollArea);
|
|
1431
2065
|
|
|
1432
|
-
// Controls area (
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
2066
|
+
// Controls area (only in standalone mode, not extension)
|
|
2067
|
+
if (!EXTENSION_MODE) {
|
|
2068
|
+
const controls = document.createElement('div');
|
|
2069
|
+
Object.assign(controls.style, {
|
|
2070
|
+
display: 'flex', alignItems: 'center', gap: '2px',
|
|
2071
|
+
padding: '0 8px', flexShrink: '0',
|
|
2072
|
+
});
|
|
1438
2073
|
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
2074
|
+
// Toggle visibility button
|
|
2075
|
+
const toggle = document.createElement('button');
|
|
2076
|
+
toggle.textContent = '\u25C9'; // circle with dot (visible state)
|
|
2077
|
+
toggle.title = 'Toggle overlay visibility';
|
|
2078
|
+
Object.assign(toggle.style, {
|
|
2079
|
+
background: 'none', border: 'none',
|
|
2080
|
+
color: 'white', fontSize: '16px', cursor: 'pointer', padding: '0 4px',
|
|
2081
|
+
opacity: '0.85', transition: 'opacity 0.15s',
|
|
2082
|
+
});
|
|
2083
|
+
let overlaysVisible = true;
|
|
2084
|
+
toggle.addEventListener('click', () => {
|
|
2085
|
+
overlaysVisible = !overlaysVisible;
|
|
2086
|
+
document.body.classList.toggle('impeccable-hidden', !overlaysVisible);
|
|
2087
|
+
toggle.textContent = overlaysVisible ? '\u25C9' : '\u25CB'; // filled vs empty circle
|
|
2088
|
+
toggle.style.opacity = overlaysVisible ? '0.85' : '0.5';
|
|
2089
|
+
});
|
|
2090
|
+
controls.appendChild(toggle);
|
|
2091
|
+
|
|
2092
|
+
// Close button
|
|
2093
|
+
const close = document.createElement('button');
|
|
2094
|
+
close.textContent = '\u00d7';
|
|
2095
|
+
close.title = 'Dismiss banner';
|
|
2096
|
+
Object.assign(close.style, {
|
|
2097
|
+
background: 'none', border: 'none',
|
|
2098
|
+
color: 'white', fontSize: '18px', cursor: 'pointer', padding: '0 4px',
|
|
2099
|
+
});
|
|
2100
|
+
close.addEventListener('click', () => banner.remove());
|
|
2101
|
+
controls.appendChild(close);
|
|
1467
2102
|
|
|
1468
|
-
|
|
2103
|
+
banner.appendChild(controls);
|
|
2104
|
+
}
|
|
1469
2105
|
document.body.appendChild(banner);
|
|
1470
2106
|
overlays.push(banner);
|
|
1471
2107
|
};
|
|
1472
2108
|
|
|
2109
|
+
// Heuristic for skipping CSS-in-JS hashed class names like "css-1a2b3c" or "_2x4hG_".
|
|
2110
|
+
// These change between builds and produce brittle, ugly selectors.
|
|
2111
|
+
function isLikelyHashedClass(c) {
|
|
2112
|
+
if (!c) return true;
|
|
2113
|
+
if (/^(css|sc|emotion|jsx|module)-[\w-]{4,}$/i.test(c)) return true;
|
|
2114
|
+
if (/^_[\w-]{5,}$/.test(c)) return true;
|
|
2115
|
+
if (/^[a-z0-9]{6,}$/i.test(c) && /\d/.test(c)) return true;
|
|
2116
|
+
return false;
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
function buildSelectorSegment(el) {
|
|
2120
|
+
const tag = el.tagName.toLowerCase();
|
|
2121
|
+
let sel = tag;
|
|
2122
|
+
|
|
2123
|
+
if (el.classList && el.classList.length > 0) {
|
|
2124
|
+
const classes = [...el.classList]
|
|
2125
|
+
.filter(c => !c.startsWith('impeccable-') && !isLikelyHashedClass(c))
|
|
2126
|
+
.slice(0, 2);
|
|
2127
|
+
if (classes.length > 0) {
|
|
2128
|
+
sel += '.' + classes.map(c => CSS.escape(c)).join('.');
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
// Disambiguate among siblings only if the parent has multiple matches
|
|
2133
|
+
const parent = el.parentElement;
|
|
2134
|
+
if (parent) {
|
|
2135
|
+
try {
|
|
2136
|
+
const matching = parent.querySelectorAll(':scope > ' + sel);
|
|
2137
|
+
if (matching.length > 1) {
|
|
2138
|
+
const sameType = [...parent.children].filter(c => c.tagName === el.tagName);
|
|
2139
|
+
const idx = sameType.indexOf(el) + 1;
|
|
2140
|
+
sel += `:nth-of-type(${idx})`;
|
|
2141
|
+
}
|
|
2142
|
+
} catch {
|
|
2143
|
+
const idx = [...parent.children].indexOf(el) + 1;
|
|
2144
|
+
sel = `${tag}:nth-child(${idx})`;
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
return sel;
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
function generateSelector(el) {
|
|
2151
|
+
if (el === document.body) return 'body';
|
|
2152
|
+
if (el === document.documentElement) return 'html';
|
|
2153
|
+
if (el.id) return '#' + CSS.escape(el.id);
|
|
2154
|
+
|
|
2155
|
+
const parts = [];
|
|
2156
|
+
let current = el;
|
|
2157
|
+
let depth = 0;
|
|
2158
|
+
const MAX_DEPTH = 10;
|
|
2159
|
+
|
|
2160
|
+
while (current && current !== document.body && current !== document.documentElement && depth < MAX_DEPTH) {
|
|
2161
|
+
parts.unshift(buildSelectorSegment(current));
|
|
2162
|
+
|
|
2163
|
+
// Anchor on an ancestor's ID and stop walking up
|
|
2164
|
+
if (current.id) {
|
|
2165
|
+
parts[0] = '#' + CSS.escape(current.id);
|
|
2166
|
+
break;
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
// Stop as soon as the partial selector uniquely identifies the target
|
|
2170
|
+
const trySelector = parts.join(' > ');
|
|
2171
|
+
try {
|
|
2172
|
+
const matches = document.querySelectorAll(trySelector);
|
|
2173
|
+
if (matches.length === 1 && matches[0] === el) {
|
|
2174
|
+
return trySelector;
|
|
2175
|
+
}
|
|
2176
|
+
} catch { /* invalid selector — keep walking */ }
|
|
2177
|
+
|
|
2178
|
+
current = current.parentElement;
|
|
2179
|
+
depth++;
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
return parts.join(' > ');
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
function isElementHidden(el) {
|
|
2186
|
+
if (!el || el === document.body || el === document.documentElement) return false;
|
|
2187
|
+
if (typeof el.checkVisibility === 'function') return !el.checkVisibility({ checkOpacity: false, checkVisibilityCSS: true });
|
|
2188
|
+
// Fallback: zero size or no offsetParent (covers display:none and detached subtrees)
|
|
2189
|
+
return el.offsetWidth === 0 && el.offsetHeight === 0;
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
function serializeFindings(allFindings) {
|
|
2193
|
+
return allFindings.map(({ el, findings }) => ({
|
|
2194
|
+
selector: generateSelector(el),
|
|
2195
|
+
tagName: el.tagName?.toLowerCase() || 'unknown',
|
|
2196
|
+
rect: (el !== document.body && el !== document.documentElement && el.getBoundingClientRect)
|
|
2197
|
+
? el.getBoundingClientRect().toJSON() : null,
|
|
2198
|
+
isPageLevel: el === document.body || el === document.documentElement,
|
|
2199
|
+
isHidden: isElementHidden(el),
|
|
2200
|
+
findings: findings.map(f => {
|
|
2201
|
+
const ap = ANTIPATTERNS.find(a => a.id === (f.type || f.id));
|
|
2202
|
+
return {
|
|
2203
|
+
type: f.type || f.id,
|
|
2204
|
+
category: ap ? ap.category : 'quality',
|
|
2205
|
+
detail: f.detail || f.snippet,
|
|
2206
|
+
name: ap ? ap.name : (f.type || f.id),
|
|
2207
|
+
description: ap ? ap.description : '',
|
|
2208
|
+
};
|
|
2209
|
+
}),
|
|
2210
|
+
}));
|
|
2211
|
+
}
|
|
2212
|
+
|
|
1473
2213
|
const printSummary = function(allFindings) {
|
|
1474
2214
|
if (allFindings.length === 0) {
|
|
1475
2215
|
console.log('%c[impeccable] No anti-patterns found.', 'color: #22c55e; font-weight: bold');
|
|
@@ -1488,16 +2228,19 @@ if (IS_BROWSER) {
|
|
|
1488
2228
|
console.groupEnd();
|
|
1489
2229
|
};
|
|
1490
2230
|
|
|
2231
|
+
let firstScanDone = false;
|
|
1491
2232
|
const scan = function() {
|
|
1492
2233
|
for (const o of overlays) o.remove();
|
|
1493
2234
|
overlays.length = 0;
|
|
1494
2235
|
visibilityObserver.disconnect();
|
|
2236
|
+
overlayIndex = 0;
|
|
1495
2237
|
const allFindings = [];
|
|
2238
|
+
const _disabled = EXTENSION_MODE ? (window.__IMPECCABLE_CONFIG__?.disabledRules || []) : [];
|
|
2239
|
+
const _ruleOk = (id) => !_disabled.length || !_disabled.includes(id);
|
|
1496
2240
|
|
|
1497
2241
|
for (const el of document.querySelectorAll('*')) {
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
el.classList.contains('impeccable-tooltip')) continue;
|
|
2242
|
+
// Skip impeccable's own elements and any descendants (overlays, labels, banner, nav buttons)
|
|
2243
|
+
if (el.closest('.impeccable-overlay, .impeccable-label, .impeccable-banner, .impeccable-tooltip')) continue;
|
|
1501
2244
|
// Skip browser extension elements (Claude, etc.)
|
|
1502
2245
|
const elId = el.id || '';
|
|
1503
2246
|
if (elId.startsWith('claude-') || elId.startsWith('cic-')) continue;
|
|
@@ -1510,8 +2253,9 @@ if (IS_BROWSER) {
|
|
|
1510
2253
|
...checkElementMotionDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
1511
2254
|
...checkElementGlowDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
1512
2255
|
...checkElementAIPaletteDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
2256
|
+
...checkElementIconTileDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
1513
2257
|
...checkElementQualityDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
1514
|
-
];
|
|
2258
|
+
].filter(f => _ruleOk(f.type));
|
|
1515
2259
|
|
|
1516
2260
|
if (findings.length > 0) {
|
|
1517
2261
|
highlight(el, findings);
|
|
@@ -1521,13 +2265,13 @@ if (IS_BROWSER) {
|
|
|
1521
2265
|
|
|
1522
2266
|
const pageLevelFindings = [];
|
|
1523
2267
|
|
|
1524
|
-
const typoFindings = checkTypography();
|
|
2268
|
+
const typoFindings = checkTypography().filter(f => _ruleOk(f.type));
|
|
1525
2269
|
if (typoFindings.length > 0) {
|
|
1526
2270
|
pageLevelFindings.push(...typoFindings);
|
|
1527
2271
|
allFindings.push({ el: document.body, findings: typoFindings });
|
|
1528
2272
|
}
|
|
1529
2273
|
|
|
1530
|
-
const layoutFindings = checkLayout();
|
|
2274
|
+
const layoutFindings = checkLayout().filter(f => _ruleOk(f.type));
|
|
1531
2275
|
for (const f of layoutFindings) {
|
|
1532
2276
|
const el = f.el || document.body;
|
|
1533
2277
|
delete f.el;
|
|
@@ -1546,7 +2290,7 @@ if (IS_BROWSER) {
|
|
|
1546
2290
|
}
|
|
1547
2291
|
|
|
1548
2292
|
// Page-level quality checks (headings, etc.)
|
|
1549
|
-
const qualityFindings = checkPageQualityDOM();
|
|
2293
|
+
const qualityFindings = checkPageQualityDOM().filter(f => _ruleOk(f.type));
|
|
1550
2294
|
if (qualityFindings.length > 0) {
|
|
1551
2295
|
pageLevelFindings.push(...qualityFindings);
|
|
1552
2296
|
allFindings.push({ el: document.body, findings: qualityFindings });
|
|
@@ -1555,7 +2299,7 @@ if (IS_BROWSER) {
|
|
|
1555
2299
|
// Regex-on-HTML checks (shared with Node)
|
|
1556
2300
|
const htmlPatternFindings = checkHtmlPatterns(document.documentElement.outerHTML);
|
|
1557
2301
|
if (htmlPatternFindings.length > 0) {
|
|
1558
|
-
const mapped = htmlPatternFindings.map(f => ({ type: f.id, detail: f.snippet }));
|
|
2302
|
+
const mapped = htmlPatternFindings.map(f => ({ type: f.id, detail: f.snippet })).filter(f => _ruleOk(f.type));
|
|
1559
2303
|
pageLevelFindings.push(...mapped);
|
|
1560
2304
|
allFindings.push({ el: document.body, findings: mapped });
|
|
1561
2305
|
}
|
|
@@ -1564,14 +2308,86 @@ if (IS_BROWSER) {
|
|
|
1564
2308
|
showPageBanner(pageLevelFindings);
|
|
1565
2309
|
}
|
|
1566
2310
|
|
|
1567
|
-
printSummary(allFindings);
|
|
2311
|
+
if (!EXTENSION_MODE) printSummary(allFindings);
|
|
2312
|
+
|
|
2313
|
+
// In extension mode, post serialized results for the DevTools panel
|
|
2314
|
+
if (EXTENSION_MODE) {
|
|
2315
|
+
window.postMessage({
|
|
2316
|
+
source: 'impeccable-results',
|
|
2317
|
+
findings: serializeFindings(allFindings),
|
|
2318
|
+
count: allFindings.length,
|
|
2319
|
+
}, '*');
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2322
|
+
// After this scan completes, all subsequent reveals are instant (no stagger, no animation)
|
|
2323
|
+
setTimeout(() => { firstScanDone = true; }, 1000);
|
|
2324
|
+
|
|
1568
2325
|
return allFindings;
|
|
1569
2326
|
};
|
|
1570
2327
|
|
|
1571
|
-
if (
|
|
1572
|
-
|
|
2328
|
+
if (EXTENSION_MODE) {
|
|
2329
|
+
// Extension mode: listen for commands, don't auto-scan
|
|
2330
|
+
window.addEventListener('message', (e) => {
|
|
2331
|
+
if (e.source !== window || !e.data || e.data.source !== 'impeccable-command') return;
|
|
2332
|
+
if (e.data.action === 'scan') {
|
|
2333
|
+
if (e.data.config) window.__IMPECCABLE_CONFIG__ = e.data.config;
|
|
2334
|
+
scan();
|
|
2335
|
+
}
|
|
2336
|
+
if (e.data.action === 'toggle-overlays') {
|
|
2337
|
+
const visible = !document.body.classList.contains('impeccable-hidden');
|
|
2338
|
+
document.body.classList.toggle('impeccable-hidden', visible);
|
|
2339
|
+
window.postMessage({ source: 'impeccable-overlays-toggled', visible: !visible }, '*');
|
|
2340
|
+
}
|
|
2341
|
+
if (e.data.action === 'remove') {
|
|
2342
|
+
for (const o of overlays) o.remove();
|
|
2343
|
+
overlays.length = 0;
|
|
2344
|
+
visibilityObserver.disconnect();
|
|
2345
|
+
styleEl.remove();
|
|
2346
|
+
if (spotlightBackdrop) { spotlightBackdrop.remove(); spotlightBackdrop = null; }
|
|
2347
|
+
document.body.classList.remove('impeccable-hidden');
|
|
2348
|
+
}
|
|
2349
|
+
if (e.data.action === 'highlight') {
|
|
2350
|
+
if (spotlightTimer) { clearTimeout(spotlightTimer); spotlightTimer = null; }
|
|
2351
|
+
try {
|
|
2352
|
+
const target = e.data.selector ? document.querySelector(e.data.selector) : null;
|
|
2353
|
+
if (target) {
|
|
2354
|
+
// Scroll first so positionOverlay reads the post-scroll rect
|
|
2355
|
+
if (!isInViewport(target) && target.scrollIntoView) {
|
|
2356
|
+
target.scrollIntoView({ behavior: 'instant', block: 'center' });
|
|
2357
|
+
}
|
|
2358
|
+
for (const o of overlays) {
|
|
2359
|
+
if (o.classList.contains('impeccable-banner')) continue;
|
|
2360
|
+
const isMatch = o._targetEl === target;
|
|
2361
|
+
o.classList.toggle('impeccable-spotlight', isMatch);
|
|
2362
|
+
o.classList.toggle('impeccable-spotlight-dimmed', !isMatch);
|
|
2363
|
+
if (isMatch) {
|
|
2364
|
+
// Force the matching overlay visible immediately, don't wait for IntersectionObserver
|
|
2365
|
+
o.style.display = '';
|
|
2366
|
+
o.style.animation = 'none';
|
|
2367
|
+
o.classList.add('impeccable-visible');
|
|
2368
|
+
o._revealed = true;
|
|
2369
|
+
positionOverlay(o);
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
showSpotlight(target);
|
|
2373
|
+
}
|
|
2374
|
+
} catch { /* invalid selector */ }
|
|
2375
|
+
}
|
|
2376
|
+
if (e.data.action === 'unhighlight') {
|
|
2377
|
+
hideSpotlight();
|
|
2378
|
+
for (const o of overlays) {
|
|
2379
|
+
o.classList.remove('impeccable-spotlight');
|
|
2380
|
+
o.classList.remove('impeccable-spotlight-dimmed');
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
});
|
|
2384
|
+
window.postMessage({ source: 'impeccable-ready' }, '*');
|
|
1573
2385
|
} else {
|
|
1574
|
-
|
|
2386
|
+
if (document.readyState === 'loading') {
|
|
2387
|
+
document.addEventListener('DOMContentLoaded', () => setTimeout(scan, 100));
|
|
2388
|
+
} else {
|
|
2389
|
+
setTimeout(scan, 100);
|
|
2390
|
+
}
|
|
1575
2391
|
}
|
|
1576
2392
|
|
|
1577
2393
|
window.impeccableScan = scan;
|