impeccable 3.2.1 → 3.3.1
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/README.md +2 -2
- package/README.npm.md +2 -2
- package/README.repo.md +30 -9
- package/cli/bin/commands/ignores.mjs +27 -6
- package/cli/bin/commands/skills.mjs +168 -22
- package/cli/engine/browser/injected/index.mjs +84 -6
- package/cli/engine/cli/main.mjs +143 -26
- package/cli/engine/design-system.mjs +181 -12
- package/cli/engine/detect-antipatterns-browser.js +2877 -138
- package/cli/engine/engines/browser/detect-url.mjs +67 -4
- package/cli/engine/engines/regex/detect-text.mjs +266 -70
- package/cli/engine/engines/static-html/css-cascade.mjs +161 -5
- package/cli/engine/engines/static-html/detect-html.mjs +18 -5
- package/cli/engine/findings.mjs +7 -1
- package/cli/engine/registry/antipatterns.mjs +142 -37
- package/cli/engine/rules/checks.mjs +2706 -127
- package/cli/engine/shared/constants.mjs +11 -0
- package/cli/lib/download-providers.js +2 -0
- package/cli/lib/impeccable-config.mjs +20 -5
- package/package.json +7 -19
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BORDER_SAFE_TAGS,
|
|
3
|
+
EM_DASH_CHARS_PER_DASH,
|
|
4
|
+
EM_DASH_FLOOR,
|
|
3
5
|
GENERIC_FONTS,
|
|
4
6
|
KNOWN_SERIF_FONTS,
|
|
5
7
|
OVERUSED_FONTS,
|
|
@@ -24,8 +26,15 @@ const DETECTOR_IS_BROWSER = typeof window !== 'undefined';
|
|
|
24
26
|
|
|
25
27
|
// ─── Section 3: Pure Detection ──────────────────────────────────────────────
|
|
26
28
|
|
|
27
|
-
function checkBorders(tag, widths, colors, radius) {
|
|
28
|
-
|
|
29
|
+
function checkBorders(tag, widths, colors, radius, opts = {}) {
|
|
30
|
+
// Badge-shaped <span>s (own visible background) are a real stripe target
|
|
31
|
+
// for the top/bottom variant — the inline-tag exemption exists to quiet
|
|
32
|
+
// text-level borders, not chips. They skip the left/right arms below.
|
|
33
|
+
const spanBadge = tag === 'span' && !!opts.badgeLike;
|
|
34
|
+
if (BORDER_SAFE_TAGS.has(tag) && !spanBadge) return [];
|
|
35
|
+
// A live status/alert region wears a colored single-edge border as a
|
|
36
|
+
// severity accent (toast, snackbar, callout), not as the side-tab tell.
|
|
37
|
+
if (opts.statusContext) return [];
|
|
29
38
|
const findings = [];
|
|
30
39
|
const sides = ['Top', 'Right', 'Bottom', 'Left'];
|
|
31
40
|
|
|
@@ -41,10 +50,20 @@ function checkBorders(tag, widths, colors, radius) {
|
|
|
41
50
|
const isSide = side === 'Left' || side === 'Right';
|
|
42
51
|
|
|
43
52
|
if (isSide) {
|
|
53
|
+
if (spanBadge) continue;
|
|
44
54
|
if (radius > 0) findings.push({ id: 'side-tab', snippet: `border-${sn}: ${w}px + border-radius: ${radius}px` });
|
|
45
55
|
else if (w >= 3) findings.push({ id: 'side-tab', snippet: `border-${sn}: ${w}px` });
|
|
46
56
|
} else {
|
|
47
57
|
if (radius > 0 && w >= 2) findings.push({ id: 'border-accent-on-rounded', snippet: `border-${sn}: ${w}px + border-radius: ${radius}px` });
|
|
58
|
+
// Horizontal variant of the side-tab stripe: a thick chromatic accent
|
|
59
|
+
// riding the top or bottom edge of a card/badge/container. Same
|
|
60
|
+
// dominant-edge + chroma gates as left/right, 3-12px band. Selected-
|
|
61
|
+
// tab underlines are exempt via opts.tabContext (adapters look for
|
|
62
|
+
// tablist/nav/tab ancestors and aria-selected); links, buttons,
|
|
63
|
+
// table cells, and <hr> never reach here (BORDER_SAFE_TAGS).
|
|
64
|
+
else if (!opts.tabContext && w >= 3 && w <= 12) {
|
|
65
|
+
findings.push({ id: 'side-tab', snippet: `border-${sn}: ${w}px` });
|
|
66
|
+
}
|
|
48
67
|
}
|
|
49
68
|
}
|
|
50
69
|
|
|
@@ -66,16 +85,26 @@ function isEmojiOnlyText(text) {
|
|
|
66
85
|
function checkColors(opts) {
|
|
67
86
|
const { tag, textColor, bgColor, effectiveBg, effectiveBgStops, fontSize, fontWeight, hasDirectText, isEmojiOnly, bgClip, bgImage, classList } = opts;
|
|
68
87
|
if (SAFE_TAGS.has(tag)) {
|
|
69
|
-
// Exception for
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
// contrast on its own surface is a real,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
// Exception for elements styled as controls or chips. SAFE_TAGS exists to
|
|
89
|
+
// suppress contrast noise on inline links and unstyled spans, where the
|
|
90
|
+
// element has no own background and the contrast against the ancestor
|
|
91
|
+
// surface is already the intended visual. When the element paints its own
|
|
92
|
+
// opaque background under direct text, it is a styled button, chip, or
|
|
93
|
+
// badge regardless of tag, and contrast on its own surface is a real,
|
|
94
|
+
// frequent bug worth flagging. (The shipped miss: a <span> severity chip
|
|
95
|
+
// whose white text lost a specificity fight and rendered muted-on-red at
|
|
96
|
+
// 1.2:1; the old a/button-only exception never looked at it.) The 9px
|
|
97
|
+
// font floor keeps sub-text decorations out.
|
|
98
|
+
const isStyledControl = hasDirectText
|
|
99
|
+
&& ((bgColor && bgColor.a > 0.5)
|
|
100
|
+
// A gradient painted on the element itself is an own surface the
|
|
101
|
+
// same way a solid background is. Without this branch a nav CTA
|
|
102
|
+
// built as `<a>` with `background: linear-gradient(…)` and a text
|
|
103
|
+
// color that fails against every stop sails through on the
|
|
104
|
+
// SAFE_TAGS suppression (the shipped escape).
|
|
105
|
+
|| (bgImage && /gradient/i.test(bgImage)))
|
|
106
|
+
&& fontSize >= 9;
|
|
107
|
+
if (!isStyledControl) return [];
|
|
79
108
|
}
|
|
80
109
|
const findings = [];
|
|
81
110
|
|
|
@@ -112,7 +141,11 @@ function checkColors(opts) {
|
|
|
112
141
|
// like `text-paper/60` on `bg-ink` sections are the FP pattern.
|
|
113
142
|
const isAlphaFallbackFP = !DETECTOR_IS_BROWSER && !effectiveBg && (textColor.a != null && textColor.a < 1);
|
|
114
143
|
if (!isAlphaFallbackFP) {
|
|
115
|
-
|
|
144
|
+
// Near-threshold ratios (e.g. 4.497) would round to the threshold
|
|
145
|
+
// itself at one decimal and read as "4.5 needs 4.5" — show two
|
|
146
|
+
// decimals there so the finding stays legible.
|
|
147
|
+
const ratioLabel = ratio.toFixed(1) === threshold.toFixed(1) ? ratio.toFixed(2) : ratio.toFixed(1);
|
|
148
|
+
findings.push({ id: 'low-contrast', snippet: `${ratioLabel}:1 (need ${threshold}:1) — text ${colorToHex(textColor)} on ${colorToHex(bgs[worstIdx])}` });
|
|
116
149
|
}
|
|
117
150
|
}
|
|
118
151
|
}
|
|
@@ -158,6 +191,27 @@ function checkColors(opts) {
|
|
|
158
191
|
return findings;
|
|
159
192
|
}
|
|
160
193
|
|
|
194
|
+
// WCAG contrast for the :hover state of an element whose hover rules change
|
|
195
|
+
// its text color and/or background. The classic miss: a nav CTA whose
|
|
196
|
+
// author-intended hover pair passes AA, but a broader selector (e.g.
|
|
197
|
+
// `.nav-links a:hover`) wins the specificity fight and swaps in a color
|
|
198
|
+
// that fails. Only fires on elements that present as styled controls —
|
|
199
|
+
// direct text plus an opaque-ish own background in either state — so plain
|
|
200
|
+
// inline links keep the same suppression they get in checkColors.
|
|
201
|
+
function checkHoverContrast(opts) {
|
|
202
|
+
const { tag, textColor, bg, ownBgAlpha, fontSize, fontWeight, hasDirectText, isEmojiOnly } = opts;
|
|
203
|
+
if (!hasDirectText || isEmojiOnly || !textColor || !bg) return [];
|
|
204
|
+
if (SAFE_TAGS.has(tag) && !(ownBgAlpha != null && ownBgAlpha > 0.5)) return [];
|
|
205
|
+
const ratio = contrastRatio(textColor, bg);
|
|
206
|
+
const isLargeText = fontSize >= WCAG_LARGE_TEXT_PX || (fontSize >= WCAG_LARGE_BOLD_TEXT_PX && fontWeight >= 700);
|
|
207
|
+
const threshold = isLargeText ? 3.0 : 4.5;
|
|
208
|
+
if (ratio >= threshold) return [];
|
|
209
|
+
return [{
|
|
210
|
+
id: 'low-contrast',
|
|
211
|
+
snippet: `:hover state ${ratio.toFixed(1)}:1 (need ${threshold}:1) — text ${colorToHex(textColor)} on ${colorToHex(bg)}`,
|
|
212
|
+
}];
|
|
213
|
+
}
|
|
214
|
+
|
|
161
215
|
function isCardLikeFromProps(hasShadow, hasBorder, hasRadius, hasBg) {
|
|
162
216
|
if (!hasShadow && !hasBorder) return false;
|
|
163
217
|
return hasRadius || hasBg;
|
|
@@ -303,26 +357,57 @@ function isAccentColor(cssColor) {
|
|
|
303
357
|
return false;
|
|
304
358
|
}
|
|
305
359
|
|
|
360
|
+
function resolveHeroHeadingSizePx(value) {
|
|
361
|
+
const input = String(value || '').trim().toLowerCase();
|
|
362
|
+
if (!input) return 0;
|
|
363
|
+
|
|
364
|
+
const simpleLengthPx = (token) => {
|
|
365
|
+
const match = /^(-?\d*\.?\d+)\s*(px|rem|em|%)?$/.exec(String(token || '').trim());
|
|
366
|
+
if (!match) return null;
|
|
367
|
+
const amount = Number(match[1]);
|
|
368
|
+
if (!Number.isFinite(amount)) return null;
|
|
369
|
+
if (match[2] === 'rem' || match[2] === 'em') return amount * 16;
|
|
370
|
+
if (match[2] === '%') return amount * 0.16;
|
|
371
|
+
return amount;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
const direct = simpleLengthPx(input);
|
|
375
|
+
if (direct !== null) return direct;
|
|
376
|
+
|
|
377
|
+
// Static CSS engines cannot resolve viewport units, but clamp's min/max
|
|
378
|
+
// bounds still tell us whether the heading can ever reach hero scale.
|
|
379
|
+
const clamp = /^clamp\((.*)\)$/.exec(input);
|
|
380
|
+
if (clamp) {
|
|
381
|
+
const parts = clamp[1].split(',');
|
|
382
|
+
if (parts.length === 3) {
|
|
383
|
+
const bounds = [simpleLengthPx(parts[0]), simpleLengthPx(parts[2])]
|
|
384
|
+
.filter((candidate) => candidate !== null);
|
|
385
|
+
if (bounds.length > 0) return Math.max(...bounds);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return 0;
|
|
390
|
+
}
|
|
391
|
+
|
|
306
392
|
// Sibling-relationship rule. Anchor on a hero-scale h1, look at the
|
|
307
393
|
// previousElementSibling, and gate on EITHER the classic tracked-
|
|
308
394
|
// uppercase eyebrow OR the modern accent-colored bold eyebrow.
|
|
309
395
|
function checkHeroEyebrow(opts) {
|
|
310
396
|
const {
|
|
311
397
|
headingTag, headingText, headingFontSize,
|
|
398
|
+
headingInApplicationContext,
|
|
312
399
|
siblingTag, siblingText, siblingTextTransform,
|
|
313
400
|
siblingFontSize, siblingLetterSpacing,
|
|
314
401
|
siblingFontWeight, siblingColor,
|
|
402
|
+
siblingHasAccentDashPseudo,
|
|
315
403
|
} = opts;
|
|
316
404
|
if (headingTag !== 'h1') return [];
|
|
317
|
-
//
|
|
318
|
-
//
|
|
319
|
-
//
|
|
320
|
-
//
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
// tracked-caps) are tight enough to avoid false positives on non-
|
|
324
|
-
// hero h1s — a tiny tan label directly above any h1 is the
|
|
325
|
-
// antipattern regardless of how big the h1 ends up.
|
|
405
|
+
// This is specifically a marketing-hero cliché, not a ban on compact
|
|
406
|
+
// context labels in product UI (for example, a station name inside a tab
|
|
407
|
+
// panel). Browser-computed sizes are reliable; the static adapter also
|
|
408
|
+
// resolves ordinary px/rem/em and clamp() bounds before reaching here.
|
|
409
|
+
if (headingInApplicationContext) return [];
|
|
410
|
+
if (!(headingFontSize >= 48)) return [];
|
|
326
411
|
if (!siblingTag) return [];
|
|
327
412
|
// An h2 above an h1 is a different anti-pattern (heading hierarchy / dual
|
|
328
413
|
// headings) — never an eyebrow.
|
|
@@ -343,11 +428,16 @@ function checkHeroEyebrow(opts) {
|
|
|
343
428
|
const weight = Number(siblingFontWeight) || 400;
|
|
344
429
|
const isAccentBold = weight >= 700 && isAccentColor(siblingColor || '');
|
|
345
430
|
|
|
346
|
-
|
|
431
|
+
// Branch C: dash-prefix eyebrow — sentence case, low tracking, regular
|
|
432
|
+
// weight, but announced by a short chromatic ::before/::after bar
|
|
433
|
+
// (the kicker dash). Same label-above-headline pattern, third styling.
|
|
434
|
+
const isDashPrefixed = !!siblingHasAccentDashPseudo;
|
|
435
|
+
|
|
436
|
+
if (!isClassicTracked && !isAccentBold && !isDashPrefixed) return [];
|
|
347
437
|
|
|
348
438
|
const headingTextSnippet = (headingText || '').trim().slice(0, 60);
|
|
349
439
|
const eyebrowSnippet = text.slice(0, 40);
|
|
350
|
-
const style = isClassicTracked ? 'tracked-caps' : 'accent-bold';
|
|
440
|
+
const style = isClassicTracked ? 'tracked-caps' : isAccentBold ? 'accent-bold' : 'dash-prefix';
|
|
351
441
|
return [{
|
|
352
442
|
id: 'hero-eyebrow-chip',
|
|
353
443
|
snippet: `eyebrow chip (${style}) "${eyebrowSnippet}" above ${headingTag} "${headingTextSnippet}"`,
|
|
@@ -408,38 +498,872 @@ function checkMotion(opts) {
|
|
|
408
498
|
return findings;
|
|
409
499
|
}
|
|
410
500
|
|
|
501
|
+
// Locate the color token in a single shadow layer. Returns
|
|
502
|
+
// { color, start, end } where color is the parsed {r,g,b,a} (null when the
|
|
503
|
+
// token exists but can't be parsed — e.g. an unresolved var() or an exotic
|
|
504
|
+
// color space), or null when no color token is present at all. Handles both
|
|
505
|
+
// serialization orders: computed style puts the color first
|
|
506
|
+
// ("rgb(…) 0px 0px 20px"), authored CSS usually puts it last
|
|
507
|
+
// ("0 0 20px #3b82f6").
|
|
508
|
+
function findShadowColor(layer) {
|
|
509
|
+
const fn = layer.match(/(?:rgba?|hsla?|hwb|oklch|oklab|lch|lab|color)\([^)]*\)/i);
|
|
510
|
+
if (fn) return { color: parseAnyColor(fn[0]), start: fn.index, end: fn.index + fn[0].length };
|
|
511
|
+
const hex = layer.match(/#[0-9a-fA-F]{3,8}\b/);
|
|
512
|
+
if (hex) return { color: parseAnyColor(hex[0]), start: hex.index, end: hex.index + hex[0].length };
|
|
513
|
+
const wordRe = /[a-zA-Z][a-zA-Z]*/g;
|
|
514
|
+
let m;
|
|
515
|
+
while ((m = wordRe.exec(layer)) !== null) {
|
|
516
|
+
const named = CSS_NAMED_COLORS[m[0].toLowerCase()];
|
|
517
|
+
if (named) return { color: { ...named, a: 1 }, start: m.index, end: m.index + m[0].length };
|
|
518
|
+
}
|
|
519
|
+
return null;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// Extract the length values of a shadow layer in declaration order, with the
|
|
523
|
+
// color token removed so its components aren't misread as lengths. Handles
|
|
524
|
+
// computed-style px values AND authored unitless zeros ("0 0 20px"); rem/em
|
|
525
|
+
// approximate at 16px. Result order is offset-x, offset-y, blur, [spread].
|
|
526
|
+
function extractShadowLengths(layer, colorStart, colorEnd) {
|
|
527
|
+
const stripped = colorStart != null
|
|
528
|
+
? layer.slice(0, colorStart) + ' ' + layer.slice(colorEnd)
|
|
529
|
+
: layer;
|
|
530
|
+
const vals = [];
|
|
531
|
+
const re = /(-?\d*\.?\d+)(px|rem|em)?/g;
|
|
532
|
+
let m;
|
|
533
|
+
while ((m = re.exec(stripped)) !== null) {
|
|
534
|
+
let v = parseFloat(m[1]);
|
|
535
|
+
if (m[2] === 'rem' || m[2] === 'em') v *= 16;
|
|
536
|
+
vals.push(v);
|
|
537
|
+
}
|
|
538
|
+
return vals;
|
|
539
|
+
}
|
|
540
|
+
|
|
411
541
|
function checkGlow(opts) {
|
|
412
|
-
const { boxShadow, effectiveBg } = opts;
|
|
413
|
-
|
|
414
|
-
|
|
542
|
+
const { boxShadow, textShadow, effectiveBg } = opts;
|
|
543
|
+
const onDarkBg = effectiveBg ? relativeLuminance(effectiveBg) < 0.1 : false;
|
|
544
|
+
|
|
545
|
+
// Scan one shadow list. Two glow tells, in any color format:
|
|
546
|
+
// 1. Zero-offset chromatic halo (0 0 Npx <color>) — slop on ANY
|
|
547
|
+
// background; the light radiates evenly outward, which is never how
|
|
548
|
+
// real elevation shadows behave. Achromatic zero-offset shadows stay
|
|
549
|
+
// legal (soft ambient elevation), as do focus rings (blur 0).
|
|
550
|
+
// 2. Any chromatic shadow with real blur on a dark background — the
|
|
551
|
+
// classic dark-mode glow accent.
|
|
552
|
+
const scan = (value, prop) => {
|
|
553
|
+
if (!value || value === 'none') return null;
|
|
554
|
+
// Split multiple shadows (commas not inside parentheses)
|
|
555
|
+
for (const layer of value.split(/,(?![^(]*\))/)) {
|
|
556
|
+
const colorInfo = findShadowColor(layer);
|
|
557
|
+
// No color token, or one we can't resolve (unresolved var(), exotic
|
|
558
|
+
// color space): don't guess — skip rather than false-positive.
|
|
559
|
+
if (!colorInfo || !colorInfo.color) continue;
|
|
560
|
+
const color = colorInfo.color;
|
|
561
|
+
if (!hasChroma(color, 30)) continue;
|
|
562
|
+
const vals = extractShadowLengths(layer, colorInfo.start, colorInfo.end);
|
|
563
|
+
// Third value is blur (offset-x, offset-y, blur, [spread])
|
|
564
|
+
if (vals.length < 3 || vals[2] <= 4) continue;
|
|
565
|
+
if (vals[0] === 0 && vals[1] === 0) {
|
|
566
|
+
return { id: 'dark-glow', snippet: `Zero-offset ${prop} glow (${colorToHex(color)})` };
|
|
567
|
+
}
|
|
568
|
+
if (onDarkBg) {
|
|
569
|
+
return { id: 'dark-glow', snippet: `Colored ${prop} glow (${colorToHex(color)}) on dark background` };
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return null;
|
|
573
|
+
};
|
|
415
574
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
575
|
+
const found = scan(boxShadow, 'box-shadow') || scan(textShadow, 'text-shadow');
|
|
576
|
+
return found ? [found] : [];
|
|
577
|
+
}
|
|
419
578
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
579
|
+
// Collect CSS custom property declarations from raw stylesheet/HTML text.
|
|
580
|
+
// First declaration wins (:root declarations usually come first); good
|
|
581
|
+
// enough for the single-level var() resolution the text engines need.
|
|
582
|
+
function collectCssCustomProps(content) {
|
|
583
|
+
const map = new Map();
|
|
584
|
+
const re = /(--[\w-]+)\s*:\s*([^;{}]+)/g;
|
|
585
|
+
let m;
|
|
586
|
+
while ((m = re.exec(content)) !== null) {
|
|
587
|
+
if (!map.has(m[1])) map.set(m[1], m[2].trim());
|
|
588
|
+
}
|
|
589
|
+
return map;
|
|
590
|
+
}
|
|
427
591
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
592
|
+
// Text-level glow scan shared by the regex engine and the page-level HTML
|
|
593
|
+
// pattern pass. Resolves single-level var() refs against custom properties
|
|
594
|
+
// collected from the same text, then applies the same two glow tells as
|
|
595
|
+
// checkGlow: zero-offset chromatic halo (any background) and chromatic
|
|
596
|
+
// blurred shadow when the page has a dark background. Returns
|
|
597
|
+
// [{ index, snippet }] — index is the offset of the shadow declaration.
|
|
598
|
+
// Dark-page heuristic for raw CSS/HTML text: dark hex/rgb literals, Tailwind
|
|
599
|
+
// dark bg utilities, or a ROOT-scoped (body/html/:root or <body style>)
|
|
600
|
+
// background that resolves — via var() — to a dark color. The var/modern-
|
|
601
|
+
// color extension is deliberately root-scoped: a light page with one dark
|
|
602
|
+
// accent chip must not turn every tinted drop shadow into a "dark page"
|
|
603
|
+
// signal. Shared by the glow and radial-halo text scanners.
|
|
604
|
+
function cssTextHasDarkRootBg(content, customProps) {
|
|
605
|
+
const darkBgRe = /background(?:-color)?\s*:\s*(?:#(?:0[0-9a-f]|1[0-9a-f]|2[0-3])[0-9a-f]{4}\b|#(?:0|1)[0-9a-f]{2}\b|rgb\(\s*(\d{1,2})\s*,\s*(\d{1,2})\s*,\s*(\d{1,2})\s*\))/i;
|
|
606
|
+
const twDarkBg = /\bbg-(?:gray|slate|zinc|neutral|stone)-(?:9\d{2}|800)\b/;
|
|
607
|
+
if (darkBgRe.test(content) || twDarkBg.test(content)) return true;
|
|
608
|
+
const rootScopes = [];
|
|
609
|
+
const blockRe = /(?:^|[}\s,;>])(?:body|html|:root)\s*(?:,[^{]*)?\{([^}]*)\}/gi;
|
|
610
|
+
let sm;
|
|
611
|
+
while ((sm = blockRe.exec(content)) !== null) rootScopes.push(sm[1]);
|
|
612
|
+
const inlineBody = content.match(/<body[^>]*\bstyle\s*=\s*"([^"]*)"/i);
|
|
613
|
+
if (inlineBody) rootScopes.push(inlineBody[1]);
|
|
614
|
+
for (const scope of rootScopes) {
|
|
615
|
+
const bgRe = /background(?:-color)?\s*:\s*([^;{}]+)/gi;
|
|
616
|
+
let bm;
|
|
617
|
+
while ((bm = bgRe.exec(scope)) !== null) {
|
|
618
|
+
const c = parseAnyColor(resolveVarRefs(bm[1].trim(), customProps));
|
|
619
|
+
if (c && (c.a ?? 1) > 0.5 && relativeLuminance(c) < 0.1) return true;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return false;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
function scanCssTextForGlow(content) {
|
|
626
|
+
const customProps = collectCssCustomProps(content);
|
|
627
|
+
const hasDarkBg = cssTextHasDarkRootBg(content, customProps);
|
|
433
628
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
629
|
+
const results = [];
|
|
630
|
+
const shadowRe = /\b(box-shadow|text-shadow)\s*:\s*([^;{}]+)/gi;
|
|
631
|
+
let m;
|
|
632
|
+
while ((m = shadowRe.exec(content)) !== null) {
|
|
633
|
+
const prop = m[1].toLowerCase();
|
|
634
|
+
const value = resolveVarRefs(m[2].trim(), customProps);
|
|
635
|
+
for (const layer of value.split(/,(?![^(]*\))/)) {
|
|
636
|
+
const colorInfo = findShadowColor(layer);
|
|
637
|
+
if (!colorInfo || !colorInfo.color || !hasChroma(colorInfo.color, 30)) continue;
|
|
638
|
+
const vals = extractShadowLengths(layer, colorInfo.start, colorInfo.end);
|
|
639
|
+
if (vals.length < 3 || vals[2] <= 4) continue;
|
|
640
|
+
const zeroOffset = vals[0] === 0 && vals[1] === 0;
|
|
641
|
+
if (!zeroOffset && !hasDarkBg) continue;
|
|
642
|
+
results.push({
|
|
643
|
+
index: m.index,
|
|
644
|
+
snippet: zeroOffset
|
|
645
|
+
? `Zero-offset ${prop} glow (${colorToHex(colorInfo.color)})`
|
|
646
|
+
: `Colored ${prop} glow (${colorToHex(colorInfo.color)}) on dark page`,
|
|
647
|
+
});
|
|
648
|
+
break; // one finding per declaration
|
|
437
649
|
}
|
|
438
650
|
}
|
|
651
|
+
return results;
|
|
652
|
+
}
|
|
439
653
|
|
|
654
|
+
// Decorative grid or line-field backgrounds drawn with hairline
|
|
655
|
+
// linear-gradient layers tiled by a fixed pixel cell. Shared by the HTML
|
|
656
|
+
// pattern pass and the regex source engine so standalone CSS, component
|
|
657
|
+
// styles, and inline styles receive the same coverage. Both signals must
|
|
658
|
+
// co-occur in one declaration block; unrelated rules must not add up across
|
|
659
|
+
// the file. Returns [{ index, snippet }], capped at one finding per source to
|
|
660
|
+
// match the page-level HTML check's existing behavior.
|
|
661
|
+
function scanCssTextForGridBackground(content) {
|
|
662
|
+
const hairlineRe = /\b\d{1,3}px\s*,\s*transparent\s+\d{1,3}px/gi;
|
|
663
|
+
const invertedHairlineRe = /transparent\s+calc\(100%\s*-\s*\d{1,3}px\)/gi;
|
|
664
|
+
const sizeDeclPxRe = /background-size\s*:[^;{}"']*\b\d{1,3}px\b/i;
|
|
665
|
+
const sizeDeclPxPairRe = /background-size\s*:[^;{}"']*\b\d{1,3}px\s+\d{1,3}px/i;
|
|
666
|
+
const shorthandPxAnyRe = /\/\s*\d{1,3}px\b/;
|
|
667
|
+
const shorthandPxPairRe = /\/\s*\d{1,3}px\s+\d{1,3}px/;
|
|
668
|
+
const bgDeclRe = /\bbackground(?:-image)?\s*:\s*([^;{}"']*)/gi;
|
|
669
|
+
const blockRe = /\{([^{}]*)\}|style\s*=\s*"([^"]*)"|style\s*=\s*'([^']*)'/gi;
|
|
670
|
+
let blk;
|
|
671
|
+
while ((blk = blockRe.exec(content)) !== null) {
|
|
672
|
+
const block = blk[1] || blk[2] || blk[3] || '';
|
|
673
|
+
let hairlineCount = 0;
|
|
674
|
+
let bgJoined = '';
|
|
675
|
+
let bm;
|
|
676
|
+
bgDeclRe.lastIndex = 0;
|
|
677
|
+
while ((bm = bgDeclRe.exec(block)) !== null) {
|
|
678
|
+
hairlineCount += (bm[1].match(hairlineRe) || []).length;
|
|
679
|
+
hairlineCount += (bm[1].match(invertedHairlineRe) || []).length;
|
|
680
|
+
bgJoined += `${bm[1]};`;
|
|
681
|
+
}
|
|
682
|
+
if (hairlineCount === 0) continue;
|
|
683
|
+
const hasPxCell = sizeDeclPxRe.test(block) || shorthandPxAnyRe.test(bgJoined);
|
|
684
|
+
const hasPxPairCell = sizeDeclPxPairRe.test(block) || shorthandPxPairRe.test(bgJoined);
|
|
685
|
+
if ((hairlineCount >= 2 && hasPxCell) || hasPxPairCell) {
|
|
686
|
+
return [{
|
|
687
|
+
index: blk.index,
|
|
688
|
+
snippet: hairlineCount >= 2
|
|
689
|
+
? 'two-axis grid-line gradient background'
|
|
690
|
+
: 'px-tiled hairline line-field background',
|
|
691
|
+
}];
|
|
692
|
+
}
|
|
693
|
+
}
|
|
440
694
|
return [];
|
|
441
695
|
}
|
|
442
696
|
|
|
697
|
+
// Decorative chromatic halo drawn as a radial-gradient background on a dark
|
|
698
|
+
// page: a saturated center stop dissolving to transparent. The gradient
|
|
699
|
+
// sibling of the dark-glow shadow tell. Mechanical gates, in order:
|
|
700
|
+
// * page has a dark root background (shared heuristic with the glow scan)
|
|
701
|
+
// * declaration has no url() layer (photographic imagery is exempt)
|
|
702
|
+
// * the gradient's first color stop is chromatic (RGB spread >= 24) and
|
|
703
|
+
// visible (alpha >= 0.7 — deliberately translucent light-scene washes
|
|
704
|
+
// composite with content instead of painting a flat halo, and stay legal)
|
|
705
|
+
// * the gradient's last stop is transparent / near-zero alpha
|
|
706
|
+
// * no small pixel-sized stop positions (<= 24px = dot/texture patterns)
|
|
707
|
+
// * not a repeating-* gradient
|
|
708
|
+
// Achromatic vignettes fail the chroma gate; panel sheens that fade to an
|
|
709
|
+
// opaque surface color fail the transparent-end gate.
|
|
710
|
+
function scanCssTextForRadialHalo(content) {
|
|
711
|
+
const customProps = collectCssCustomProps(content);
|
|
712
|
+
if (!cssTextHasDarkRootBg(content, customProps)) return [];
|
|
713
|
+
|
|
714
|
+
const findings = [];
|
|
715
|
+
const seen = new Set();
|
|
716
|
+
const declRe = /background(?:-image)?\s*:\s*([^;{}]+)/gi;
|
|
717
|
+
let m;
|
|
718
|
+
while ((m = declRe.exec(content)) !== null) {
|
|
719
|
+
const value = resolveVarRefs(m[1].trim(), customProps);
|
|
720
|
+
if (/url\s*\(/i.test(value)) continue;
|
|
721
|
+
|
|
722
|
+
const gradRe = /(repeating-)?radial-gradient\(/gi;
|
|
723
|
+
let g;
|
|
724
|
+
while ((g = gradRe.exec(value)) !== null) {
|
|
725
|
+
if (g[1]) continue; // repeating-* = pattern, not halo
|
|
726
|
+
// Balanced-paren capture of the gradient arguments.
|
|
727
|
+
let depth = 0, end = -1;
|
|
728
|
+
const open = value.indexOf('(', g.index);
|
|
729
|
+
for (let i = open; i < value.length; i++) {
|
|
730
|
+
if (value[i] === '(') depth++;
|
|
731
|
+
else if (value[i] === ')') { depth--; if (depth === 0) { end = i; break; } }
|
|
732
|
+
}
|
|
733
|
+
if (end < 0) break;
|
|
734
|
+
const args = splitTopLevelCommas(value.slice(open + 1, end));
|
|
735
|
+
if (args.length < 2) continue;
|
|
736
|
+
|
|
737
|
+
// Optional prelude (shape / size / `at <pos>`) carries no color.
|
|
738
|
+
const colorTokenRe = /(?:rgba?|hsla?|oklch|oklab|lab|lch|hwb|color-mix)\([^)]*(?:\([^)]*\))?[^)]*\)|#[0-9a-f]{3,8}\b|\btransparent\b/i;
|
|
739
|
+
const stops = args.filter(a => colorTokenRe.test(a));
|
|
740
|
+
if (stops.length < 2) continue;
|
|
741
|
+
|
|
742
|
+
// Dot/texture exemption: px-sized stop positions mean a repeating
|
|
743
|
+
// background-size pattern, not a page-scale halo.
|
|
744
|
+
const pxStop = stops.some(s => {
|
|
745
|
+
const pm = s.match(/(-?[\d.]+)px\b/);
|
|
746
|
+
return pm && Math.abs(parseFloat(pm[1])) <= 24;
|
|
747
|
+
});
|
|
748
|
+
if (pxStop) continue;
|
|
749
|
+
|
|
750
|
+
const first = stops[0].match(colorTokenRe);
|
|
751
|
+
const last = stops[stops.length - 1].match(colorTokenRe);
|
|
752
|
+
if (!first || !last) continue;
|
|
753
|
+
|
|
754
|
+
const lastColor = /^transparent$/i.test(last[0]) ? { r: 0, g: 0, b: 0, a: 0 } : parseAnyColor(last[0]);
|
|
755
|
+
if (!lastColor || (lastColor.a ?? 1) > 0.05) continue;
|
|
756
|
+
|
|
757
|
+
const firstColor = /^transparent$/i.test(first[0]) ? null : parseAnyColor(first[0]);
|
|
758
|
+
if (!firstColor) continue;
|
|
759
|
+
if ((firstColor.a ?? 1) < 0.7) continue;
|
|
760
|
+
const spread = Math.max(firstColor.r, firstColor.g, firstColor.b) - Math.min(firstColor.r, firstColor.g, firstColor.b);
|
|
761
|
+
if (spread < 24) continue;
|
|
762
|
+
|
|
763
|
+
const snippet = `radial-gradient halo (${colorToHex(firstColor)} → transparent) on dark page`;
|
|
764
|
+
if (seen.has(snippet)) continue;
|
|
765
|
+
seen.add(snippet);
|
|
766
|
+
findings.push({ index: m.index, snippet });
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
return findings;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// ---------------------------------------------------------------------------
|
|
773
|
+
// Text-level CSS rule-block scanners (pseudo-element stripes, pulsing dots)
|
|
774
|
+
// ---------------------------------------------------------------------------
|
|
775
|
+
|
|
776
|
+
// Iterate `selector { declarations }` pairs in raw CSS/HTML text. The block
|
|
777
|
+
// body excludes braces, so nested structures (@media, @keyframes) naturally
|
|
778
|
+
// yield their innermost rules with the innermost selector text. Callers
|
|
779
|
+
// create the regex locally — a shared /g instance is not re-entrant.
|
|
780
|
+
const CSS_RULE_BLOCK_SOURCE = String.raw`([^{};]+)\{([^{}]*)\}`;
|
|
781
|
+
|
|
782
|
+
// Parse a declaration block into a prop → value map (last declaration wins,
|
|
783
|
+
// approximating the cascade inside one block). Values keep their raw text
|
|
784
|
+
// with any !important suffix stripped.
|
|
785
|
+
function parseCssDeclBlock(block) {
|
|
786
|
+
const decls = new Map();
|
|
787
|
+
for (const part of String(block || '').split(';')) {
|
|
788
|
+
const idx = part.indexOf(':');
|
|
789
|
+
if (idx <= 0) continue;
|
|
790
|
+
const prop = part.slice(0, idx).trim().toLowerCase();
|
|
791
|
+
const value = part.slice(idx + 1).replace(/\s*!important\s*$/i, '').trim();
|
|
792
|
+
if (prop && value) decls.set(prop, value);
|
|
793
|
+
}
|
|
794
|
+
return decls;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
function cssLengthToPx(value) {
|
|
798
|
+
const m = String(value || '').trim().match(/^(-?[\d.]+)(px|rem|em)$/i);
|
|
799
|
+
if (!m) return null;
|
|
800
|
+
const n = parseFloat(m[1]);
|
|
801
|
+
return m[2].toLowerCase() === 'px' ? n : n * 16;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
function isZeroOffset(value) {
|
|
805
|
+
return value != null && /^-?0(?:px|%|rem|em)?$/.test(String(value).trim());
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// Side-tab variant: the accent stripe drawn as an absolutely-positioned
|
|
809
|
+
// ::before/::after pseudo-element (narrow colored box hugging a vertical
|
|
810
|
+
// edge) instead of a border-left/right. The element-level border checks
|
|
811
|
+
// never see it — pseudo-elements aren't part of the DOM the cascade walks —
|
|
812
|
+
// so this scans stylesheet text directly, mirroring the border rule's
|
|
813
|
+
// gates: >= 3px thick, chromatic fill, full height against a side edge.
|
|
814
|
+
function scanCssTextForPseudoStripe(content) {
|
|
815
|
+
const customProps = collectCssCustomProps(content);
|
|
816
|
+
const findings = [];
|
|
817
|
+
const seen = new Set();
|
|
818
|
+
const ruleRe = new RegExp(CSS_RULE_BLOCK_SOURCE, 'g');
|
|
819
|
+
let m;
|
|
820
|
+
while ((m = ruleRe.exec(content)) !== null) {
|
|
821
|
+
const selector = m[1].trim();
|
|
822
|
+
if (!/::?(?:before|after)\b/i.test(selector)) continue;
|
|
823
|
+
// Keep the border rule's prose exemptions (blockquote bars etc.).
|
|
824
|
+
if (/\b(?:blockquote|pre|code|nav|hr)\b/i.test(selector)) continue;
|
|
825
|
+
const decls = parseCssDeclBlock(m[2]);
|
|
826
|
+
const position = decls.get('position');
|
|
827
|
+
if (position !== 'absolute' && position !== 'fixed') continue;
|
|
828
|
+
|
|
829
|
+
const widthPx = cssLengthToPx(resolveVarRefs(
|
|
830
|
+
decls.get('width') || decls.get('inline-size') || '', customProps));
|
|
831
|
+
const heightPx = cssLengthToPx(resolveVarRefs(
|
|
832
|
+
decls.get('height') || decls.get('block-size') || '', customProps));
|
|
833
|
+
const verticalCandidate = widthPx != null && widthPx >= 3 && widthPx <= 12;
|
|
834
|
+
// Horizontal variant (top/bottom stripe) carries extra exemptions:
|
|
835
|
+
// link/button underline affordances, selected-state indicators
|
|
836
|
+
// (aria-selected="true", aria-current, active/current/selected class
|
|
837
|
+
// hints), and state-conditional (:hover/:focus/...) affordances are
|
|
838
|
+
// not stripes. Tab-strip membership alone ([role=tab], .tabs, bare
|
|
839
|
+
// [aria-selected]) is NOT exempt — a stripe on every tab in the
|
|
840
|
+
// group is decoration; only the selected item's underline stays.
|
|
841
|
+
const horizontalCandidate = heightPx != null && heightPx >= 3 && heightPx <= 12
|
|
842
|
+
&& !/(?:^|[\s>+~,(])(?:a|button|summary|tr|td|th|table|li)(?![\w-])/i.test(selector)
|
|
843
|
+
&& !/\[aria-selected\s*[*^$|~]?=\s*["']?true/i.test(selector)
|
|
844
|
+
&& !/\[aria-current(?!\s*[*^$|~]?=\s*["']?false)/i.test(selector)
|
|
845
|
+
&& !/(?:^|[\s._[-])(?:active|current|selected|btn[\w-]*|button[\w-]*|link[\w-]*)(?![\w])/i.test(selector)
|
|
846
|
+
&& !/:(?:hover|focus|focus-visible|focus-within|active|checked)\b/i.test(selector);
|
|
847
|
+
if (!verticalCandidate && !horizontalCandidate) continue;
|
|
848
|
+
|
|
849
|
+
// Resolve edge offsets, letting an `inset` shorthand fill the gaps.
|
|
850
|
+
const offsets = {
|
|
851
|
+
top: decls.get('top'), right: decls.get('right'),
|
|
852
|
+
bottom: decls.get('bottom'), left: decls.get('left'),
|
|
853
|
+
};
|
|
854
|
+
const inset = decls.get('inset');
|
|
855
|
+
if (inset) {
|
|
856
|
+
const p = inset.split(/\s+/);
|
|
857
|
+
const [t, r, b, l] =
|
|
858
|
+
p.length === 1 ? [p[0], p[0], p[0], p[0]]
|
|
859
|
+
: p.length === 2 ? [p[0], p[1], p[0], p[1]]
|
|
860
|
+
: p.length === 3 ? [p[0], p[1], p[2], p[1]]
|
|
861
|
+
: p;
|
|
862
|
+
if (offsets.top == null) offsets.top = t;
|
|
863
|
+
if (offsets.right == null) offsets.right = r;
|
|
864
|
+
if (offsets.bottom == null) offsets.bottom = b;
|
|
865
|
+
if (offsets.left == null) offsets.left = l;
|
|
866
|
+
}
|
|
867
|
+
if (offsets.left == null) offsets.left = decls.get('inset-inline-start');
|
|
868
|
+
if (offsets.right == null) offsets.right = decls.get('inset-inline-end');
|
|
869
|
+
|
|
870
|
+
const heightValue = String(resolveVarRefs(
|
|
871
|
+
decls.get('height') || decls.get('block-size') || '', customProps)).trim();
|
|
872
|
+
const widthValue = String(resolveVarRefs(
|
|
873
|
+
decls.get('width') || decls.get('inline-size') || '', customProps)).trim();
|
|
874
|
+
|
|
875
|
+
let edge = null;
|
|
876
|
+
let thicknessPx = null;
|
|
877
|
+
if (verticalCandidate) {
|
|
878
|
+
// Full-height stripes hug both corners; the "floating" variant backs
|
|
879
|
+
// off each end by a small inset (top/bottom a few px) so the bar
|
|
880
|
+
// clears the card's corners. Both read as the same side-tab accent —
|
|
881
|
+
// corner treatment is styling, not a different pattern.
|
|
882
|
+
const topPx = cssLengthToPx(resolveVarRefs(String(offsets.top ?? ''), customProps));
|
|
883
|
+
const bottomPx = cssLengthToPx(resolveVarRefs(String(offsets.bottom ?? ''), customProps));
|
|
884
|
+
const fullHeight = (isZeroOffset(offsets.top) && isZeroOffset(offsets.bottom))
|
|
885
|
+
|| /^100(?:\.0*)?%$/.test(heightValue)
|
|
886
|
+
|| (topPx != null && bottomPx != null
|
|
887
|
+
&& topPx >= 0 && topPx <= 20 && bottomPx >= 0 && bottomPx <= 20);
|
|
888
|
+
if (fullHeight) {
|
|
889
|
+
edge = isZeroOffset(offsets.left) ? 'left'
|
|
890
|
+
: isZeroOffset(offsets.right) ? 'right' : null;
|
|
891
|
+
thicknessPx = widthPx;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
if (!edge && horizontalCandidate) {
|
|
895
|
+
const fullWidth = (isZeroOffset(offsets.left) && isZeroOffset(offsets.right))
|
|
896
|
+
|| /^100(?:\.0*)?%$/.test(widthValue);
|
|
897
|
+
if (fullWidth) {
|
|
898
|
+
edge = isZeroOffset(offsets.top) ? 'top'
|
|
899
|
+
: isZeroOffset(offsets.bottom) ? 'bottom' : null;
|
|
900
|
+
thicknessPx = heightPx;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
if (!edge) continue;
|
|
904
|
+
|
|
905
|
+
// Chromatic fill only — a neutral hairline divider is not an accent
|
|
906
|
+
// stripe. Unresolvable colors err toward detection, matching the
|
|
907
|
+
// border rule's unknown-format default.
|
|
908
|
+
const bg = String(resolveVarRefs(
|
|
909
|
+
decls.get('background-color') || decls.get('background') || '', customProps)).trim();
|
|
910
|
+
if (!bg || /^(?:none|transparent|inherit|initial|unset|currentcolor)$/i.test(bg)) continue;
|
|
911
|
+
const colorToken = bg.match(/(?:rgba?|hsla?|oklch|oklab|lab|lch|hwb)\([^)]*\)|#[0-9a-f]{3,8}\b/i);
|
|
912
|
+
const parsed = parseAnyColor(colorToken ? colorToken[0] : bg);
|
|
913
|
+
if (parsed) {
|
|
914
|
+
if ((parsed.a ?? 1) < 0.1) continue;
|
|
915
|
+
const spread = Math.max(parsed.r, parsed.g, parsed.b) - Math.min(parsed.r, parsed.g, parsed.b);
|
|
916
|
+
if (spread < 30) continue;
|
|
917
|
+
} else if (/^(?:white|black|gray|grey|silver)$/i.test(bg)) {
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
if (seen.has(selector)) continue;
|
|
922
|
+
seen.add(selector);
|
|
923
|
+
findings.push({
|
|
924
|
+
id: 'side-tab',
|
|
925
|
+
snippet: `${selector} — absolute ${thicknessPx}px pseudo-element stripe (${edge}: 0)`,
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
return findings;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// Side-tab stripe drawn as a single-edge inset box-shadow
|
|
932
|
+
// (x or y offset 3-12px, other axis 0, no blur/spread, chromatic color):
|
|
933
|
+
// paints a bar along one edge with no border property involved, so the
|
|
934
|
+
// element-level border checks never see it. Selection-state indicators
|
|
935
|
+
// are exempt — an inset stripe on [aria-current] / .active / [role=tab]
|
|
936
|
+
// marks the selected item; the same stripe unconditionally on every item
|
|
937
|
+
// is decoration and flags.
|
|
938
|
+
function scanCssTextForInsetStripe(content) {
|
|
939
|
+
const customProps = collectCssCustomProps(content);
|
|
940
|
+
const findings = [];
|
|
941
|
+
const seen = new Set();
|
|
942
|
+
const ruleRe = new RegExp(CSS_RULE_BLOCK_SOURCE, 'g');
|
|
943
|
+
let m;
|
|
944
|
+
while ((m = ruleRe.exec(content)) !== null) {
|
|
945
|
+
const selector = m[1].trim();
|
|
946
|
+
// Selection-state contexts: current-item markers and interaction
|
|
947
|
+
// states. Tab-strip membership alone ([role=tab], .tabs, bare
|
|
948
|
+
// [aria-selected]) is NOT exempt — a stripe on every tab in the
|
|
949
|
+
// group is decoration; only the selected item's indicator stays.
|
|
950
|
+
if (/:(?:hover|focus|focus-visible|focus-within|active|checked|target)\b/i.test(selector)) continue;
|
|
951
|
+
if (/\[aria-selected\s*[*^$|~]?=\s*["']?true/i.test(selector)) continue;
|
|
952
|
+
if (/\[aria-current(?!\s*[*^$|~]?=\s*["']?false)/i.test(selector)) continue;
|
|
953
|
+
if (/(?:^|[\s._[-])(?:active|current|selected)(?![\w])/i.test(selector)) continue;
|
|
954
|
+
// Structural tags where a single-edge inset shadow is depth/quoting,
|
|
955
|
+
// not an accent stripe.
|
|
956
|
+
if (/(?:^|[\s>+~,(])(?:button|hr|tr|td|th|table|blockquote|pre|code)(?![\w-])/i.test(selector)) continue;
|
|
957
|
+
|
|
958
|
+
const decls = parseCssDeclBlock(m[2]);
|
|
959
|
+
const shadow = decls.get('box-shadow');
|
|
960
|
+
if (!shadow || !/\binset\b/i.test(shadow)) continue;
|
|
961
|
+
// Narrow fixed-width elements (logo marks, icon glyphs) use inset
|
|
962
|
+
// fills as artwork, not edge stripes. Stripe targets — cards, badges,
|
|
963
|
+
// menu items — are wider or leave width to layout.
|
|
964
|
+
const declaredWidth = cssLengthToPx(resolveVarRefs(decls.get('width') || decls.get('inline-size') || '', customProps));
|
|
965
|
+
if (declaredWidth != null && declaredWidth <= 40) continue;
|
|
966
|
+
const value = resolveVarRefs(shadow, customProps);
|
|
967
|
+
for (const layer of value.split(/,(?![^(]*\))/)) {
|
|
968
|
+
if (!/\binset\b/i.test(layer)) continue;
|
|
969
|
+
const colorInfo = findShadowColor(layer);
|
|
970
|
+
// Unresolvable colors (currentColor, external vars): don't guess.
|
|
971
|
+
if (!colorInfo || !colorInfo.color) continue;
|
|
972
|
+
const c = colorInfo.color;
|
|
973
|
+
if ((c.a ?? 1) < 0.1) continue;
|
|
974
|
+
const chroma = Math.max(c.r, c.g, c.b) - Math.min(c.r, c.g, c.b);
|
|
975
|
+
if (chroma < 30) continue;
|
|
976
|
+
const vals = extractShadowLengths(layer, colorInfo.start, colorInfo.end);
|
|
977
|
+
const x = vals[0] || 0, y = vals[1] || 0, blur = vals[2] || 0, sp = vals[3] || 0;
|
|
978
|
+
if (blur !== 0 || sp !== 0) continue;
|
|
979
|
+
const ax = Math.abs(x), ay = Math.abs(y);
|
|
980
|
+
const isStripe = (ax >= 3 && ax <= 12 && ay === 0) || (ay >= 3 && ay <= 12 && ax === 0);
|
|
981
|
+
if (!isStripe) continue;
|
|
982
|
+
if (seen.has(selector)) break;
|
|
983
|
+
seen.add(selector);
|
|
984
|
+
const edge = ay === 0 ? (x > 0 ? 'left' : 'right') : (y > 0 ? 'top' : 'bottom');
|
|
985
|
+
findings.push({
|
|
986
|
+
id: 'side-tab',
|
|
987
|
+
snippet: `${selector} — inset box-shadow ${ay === 0 ? ax : ay}px stripe (${edge})`,
|
|
988
|
+
});
|
|
989
|
+
break;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
return findings;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
// Collect @keyframes names whose body travels horizontally — the marquee
|
|
996
|
+
// loop. X travel is measured across every translateX/translate/translate3d
|
|
997
|
+
// X component in the body: a centered element animating something else
|
|
998
|
+
// keeps a constant -50% X (zero travel) and never qualifies, while a
|
|
999
|
+
// ticker moves from its resting position to a large offset. Keyframes
|
|
1000
|
+
// with a single X sample that also vary scale/opacity read as pulses or
|
|
1001
|
+
// breathes, not marquees.
|
|
1002
|
+
function collectMarqueeKeyframes(content) {
|
|
1003
|
+
const names = new Set();
|
|
1004
|
+
const re = /@(?:-webkit-)?keyframes\s+([\w-]+)\s*\{/g;
|
|
1005
|
+
let m;
|
|
1006
|
+
while ((m = re.exec(content)) !== null) {
|
|
1007
|
+
let depth = 1;
|
|
1008
|
+
let i = re.lastIndex;
|
|
1009
|
+
while (i < content.length && depth > 0) {
|
|
1010
|
+
const ch = content.charCodeAt(i);
|
|
1011
|
+
if (ch === 0x7b /* { */) depth++;
|
|
1012
|
+
else if (ch === 0x7d /* } */) depth--;
|
|
1013
|
+
i++;
|
|
1014
|
+
}
|
|
1015
|
+
const body = content.slice(re.lastIndex, Math.max(re.lastIndex, i - 1));
|
|
1016
|
+
re.lastIndex = i;
|
|
1017
|
+
|
|
1018
|
+
// Only percentage travel qualifies: a content marquee translates by a
|
|
1019
|
+
// fraction of its own (unknown) track width, so generated tickers use
|
|
1020
|
+
// -50% / -100%. Pixel-travel loops are bespoke product animations —
|
|
1021
|
+
// sweeping playheads, progress indicators — not marquees.
|
|
1022
|
+
const pct = [];
|
|
1023
|
+
const xRe = /\btranslate(?:X|3d)?\(\s*(-?[\d.]+)%/gi;
|
|
1024
|
+
let xm;
|
|
1025
|
+
while ((xm = xRe.exec(body)) !== null) pct.push(parseFloat(xm[1]));
|
|
1026
|
+
if (pct.length === 0) continue;
|
|
1027
|
+
if (pct.length === 1 && /\bscale\(|\bopacity\s*:/i.test(body)) continue;
|
|
1028
|
+
// Implicit start: a lone declared X animates from the element's
|
|
1029
|
+
// resting position, so its magnitude is the travel.
|
|
1030
|
+
const travelPct = pct.length > 1 ? Math.max(...pct) - Math.min(...pct) : Math.abs(pct[0]);
|
|
1031
|
+
if (travelPct >= 20) names.add(m[1]);
|
|
1032
|
+
}
|
|
1033
|
+
return names;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
// Auto-scrolling marquee: a <marquee> element, or an infinite animation
|
|
1037
|
+
// bound to a keyframe loop that travels a large horizontal distance.
|
|
1038
|
+
// Rotation/opacity animations never qualify (no X travel); JS-driven
|
|
1039
|
+
// carousels with user controls have no infinite CSS X-loop to match.
|
|
1040
|
+
function scanCssTextForMarquee(content) {
|
|
1041
|
+
const findings = [];
|
|
1042
|
+
if (/<marquee\b/i.test(content)) {
|
|
1043
|
+
findings.push({ id: 'marquee', snippet: '<marquee> element' });
|
|
1044
|
+
}
|
|
1045
|
+
const marqueeKeyframes = collectMarqueeKeyframes(content);
|
|
1046
|
+
if (marqueeKeyframes.size === 0) return findings;
|
|
1047
|
+
const seen = new Set();
|
|
1048
|
+
const ruleRe = new RegExp(CSS_RULE_BLOCK_SOURCE, 'g');
|
|
1049
|
+
let m;
|
|
1050
|
+
while ((m = ruleRe.exec(content)) !== null) {
|
|
1051
|
+
const selector = m[1].trim();
|
|
1052
|
+
const decls = parseCssDeclBlock(m[2]);
|
|
1053
|
+
for (const name of infiniteAnimationNames(decls)) {
|
|
1054
|
+
if (!marqueeKeyframes.has(name)) continue;
|
|
1055
|
+
const key = `${selector} ${name}`;
|
|
1056
|
+
if (seen.has(key)) continue;
|
|
1057
|
+
seen.add(key);
|
|
1058
|
+
findings.push({ id: 'marquee', snippet: `${selector} — infinite horizontal loop animation "${name}"` });
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
return findings;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
// Collect @keyframes names and whether each one reads as a "pulse" —
|
|
1065
|
+
// i.e. it varies opacity, scale, or box-shadow. Rotation-only keyframes
|
|
1066
|
+
// (spinners) are explicitly not pulses.
|
|
1067
|
+
function collectPulseKeyframes(content) {
|
|
1068
|
+
const map = new Map();
|
|
1069
|
+
const re = /@(?:-webkit-)?keyframes\s+([\w-]+)\s*\{/g;
|
|
1070
|
+
let m;
|
|
1071
|
+
while ((m = re.exec(content)) !== null) {
|
|
1072
|
+
let depth = 1;
|
|
1073
|
+
let i = re.lastIndex;
|
|
1074
|
+
while (i < content.length && depth > 0) {
|
|
1075
|
+
const ch = content.charCodeAt(i);
|
|
1076
|
+
if (ch === 0x7b /* { */) depth++;
|
|
1077
|
+
else if (ch === 0x7d /* } */) depth--;
|
|
1078
|
+
i++;
|
|
1079
|
+
}
|
|
1080
|
+
const body = content.slice(re.lastIndex, Math.max(re.lastIndex, i - 1));
|
|
1081
|
+
const pulses = /\bopacity\s*:/i.test(body)
|
|
1082
|
+
|| /\bbox-shadow\s*:/i.test(body)
|
|
1083
|
+
|| /\btransform\s*:[^;{}]*\bscale/i.test(body);
|
|
1084
|
+
if (!map.has(m[1]) || pulses) map.set(m[1], pulses);
|
|
1085
|
+
re.lastIndex = i;
|
|
1086
|
+
}
|
|
1087
|
+
return map;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
const ANIMATION_VALUE_KEYWORDS = new Set([
|
|
1091
|
+
'ease', 'ease-in', 'ease-out', 'ease-in-out', 'linear',
|
|
1092
|
+
'infinite', 'alternate', 'alternate-reverse', 'normal', 'reverse',
|
|
1093
|
+
'none', 'forwards', 'backwards', 'both', 'running', 'paused',
|
|
1094
|
+
'step-start', 'step-end', 'inherit', 'initial', 'unset',
|
|
1095
|
+
]);
|
|
1096
|
+
|
|
1097
|
+
// Extract animation names that run with iteration-count: infinite from a
|
|
1098
|
+
// declaration block (shorthand layers or animation-name + iteration-count).
|
|
1099
|
+
function infiniteAnimationNames(decls) {
|
|
1100
|
+
const out = [];
|
|
1101
|
+
const shorthand = decls.get('animation');
|
|
1102
|
+
if (shorthand) {
|
|
1103
|
+
for (const layer of shorthand.split(/,(?![^(]*\))/)) {
|
|
1104
|
+
if (!/\binfinite\b/i.test(layer)) continue;
|
|
1105
|
+
const name = layer.split(/\s+/).find(t =>
|
|
1106
|
+
/^[a-zA-Z_-][\w-]*$/.test(t) && !ANIMATION_VALUE_KEYWORDS.has(t.toLowerCase()));
|
|
1107
|
+
if (name) out.push(name);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
const nameDecl = decls.get('animation-name');
|
|
1111
|
+
if (nameDecl && /\binfinite\b/i.test(decls.get('animation-iteration-count') || '')) {
|
|
1112
|
+
for (const raw of nameDecl.split(',')) {
|
|
1113
|
+
const t = raw.trim();
|
|
1114
|
+
if (t && t.toLowerCase() !== 'none') out.push(t);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
return out;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
function isRoundDotRadius(radiusValue, w, h) {
|
|
1121
|
+
if (!radiusValue) return false;
|
|
1122
|
+
const first = String(radiusValue).trim().split(/\s+/)[0];
|
|
1123
|
+
const pct = first.match(/^([\d.]+)%$/);
|
|
1124
|
+
if (pct) return parseFloat(pct[1]) >= 40;
|
|
1125
|
+
const px = cssLengthToPx(first);
|
|
1126
|
+
if (px == null) return false;
|
|
1127
|
+
return px >= 999 || px >= 0.4 * Math.min(w, h);
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
// Remove @media blocks whose condition is prefers-reduced-motion: reduce.
|
|
1131
|
+
// Those blocks describe the accessibility fallback, not the default
|
|
1132
|
+
// experience that ships — an `animation: none` reset inside one must not
|
|
1133
|
+
// mask the resting-state animation the page plays for everyone else.
|
|
1134
|
+
function stripReducedMotionBlocks(content) {
|
|
1135
|
+
const re = /@media[^{]*prefers-reduced-motion\s*:\s*reduce[^{]*\{/gi;
|
|
1136
|
+
let out = '';
|
|
1137
|
+
let last = 0;
|
|
1138
|
+
let m;
|
|
1139
|
+
while ((m = re.exec(content)) !== null) {
|
|
1140
|
+
let depth = 1;
|
|
1141
|
+
let i = re.lastIndex;
|
|
1142
|
+
while (i < content.length && depth > 0) {
|
|
1143
|
+
const ch = content.charCodeAt(i);
|
|
1144
|
+
if (ch === 0x7b /* { */) depth++;
|
|
1145
|
+
else if (ch === 0x7d /* } */) depth--;
|
|
1146
|
+
i++;
|
|
1147
|
+
}
|
|
1148
|
+
out += content.slice(last, m.index);
|
|
1149
|
+
last = i;
|
|
1150
|
+
re.lastIndex = i;
|
|
1151
|
+
}
|
|
1152
|
+
return out + content.slice(last);
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
// Source-index ranges of <header> and <nav> landmark elements in an HTML
|
|
1156
|
+
// string. Lets string-level scans decide whether a matched element sits in
|
|
1157
|
+
// the page chrome (the hero/nav region) without needing a DOM.
|
|
1158
|
+
function landmarkSourceRanges(content) {
|
|
1159
|
+
const ranges = [];
|
|
1160
|
+
for (const tag of ['header', 'nav']) {
|
|
1161
|
+
const re = new RegExp(`<${tag}\\b|</${tag}\\s*>`, 'gi');
|
|
1162
|
+
const stack = [];
|
|
1163
|
+
let m;
|
|
1164
|
+
while ((m = re.exec(content)) !== null) {
|
|
1165
|
+
if (m[0].charAt(1) === '/') {
|
|
1166
|
+
const start = stack.pop();
|
|
1167
|
+
if (start != null) ranges.push([start, m.index]);
|
|
1168
|
+
} else {
|
|
1169
|
+
stack.push(m.index);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
return ranges;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
function indexInSourceRanges(index, ranges) {
|
|
1177
|
+
return ranges.some(([start, end]) => index >= start && index < end);
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// Does any element targeted by the final compound of `selector` appear
|
|
1181
|
+
// inside a header/nav landmark range of the HTML source? Resolves the last
|
|
1182
|
+
// .class or #id token of the selector against class/id attributes; a
|
|
1183
|
+
// tag-only compound is never resolvable this way and returns false
|
|
1184
|
+
// (conservative: no promotion without placement evidence).
|
|
1185
|
+
function selectorHitsLandmark(content, selector, ranges) {
|
|
1186
|
+
if (!ranges || ranges.length === 0) return false;
|
|
1187
|
+
const last = selector.split(/[\s>+~]+/).filter(Boolean).pop() || '';
|
|
1188
|
+
const idMatch = last.match(/#([A-Za-z_][\w-]*)/);
|
|
1189
|
+
const classMatch = last.match(/\.([A-Za-z_][\w-]*)/);
|
|
1190
|
+
let attrRe = null;
|
|
1191
|
+
if (idMatch) {
|
|
1192
|
+
const id = idMatch[1].replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1193
|
+
attrRe = new RegExp(`<[a-zA-Z][^>]*\\bid\\s*=\\s*["']${id}["']`, 'gi');
|
|
1194
|
+
} else if (classMatch) {
|
|
1195
|
+
const cls = classMatch[1].replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1196
|
+
attrRe = new RegExp(`<[a-zA-Z][^>]*\\bclass\\s*=\\s*["'][^"']*(?<![\\w-])${cls}(?![\\w-])[^"']*["']`, 'gi');
|
|
1197
|
+
}
|
|
1198
|
+
if (!attrRe) return false;
|
|
1199
|
+
let m;
|
|
1200
|
+
while ((m = attrRe.exec(content)) !== null) {
|
|
1201
|
+
if (indexInSourceRanges(m.index, ranges)) return true;
|
|
1202
|
+
}
|
|
1203
|
+
return false;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
// Small circular indicator bound to an infinite pulse animation — the
|
|
1207
|
+
// decorative "live" dot. Gates: tiny (<= 16px square-ish), round
|
|
1208
|
+
// (border-radius >= 40% or pill values), and an infinite animation whose
|
|
1209
|
+
// keyframes vary opacity/scale/box-shadow (or a pulse/blink/ping name when
|
|
1210
|
+
// the keyframes aren't in the scanned text). Rotation-only animations
|
|
1211
|
+
// (spinners) never flag.
|
|
1212
|
+
//
|
|
1213
|
+
// Declarations for one selector are merged across rule blocks before the
|
|
1214
|
+
// predicate runs: size in the base rule plus the animation added in a
|
|
1215
|
+
// second block (or inside a matching @media block) is the construction
|
|
1216
|
+
// that ships. prefers-reduced-motion: reduce overrides are stripped first
|
|
1217
|
+
// so their animation resets don't mask the default experience. A dot whose
|
|
1218
|
+
// element sits inside a header/nav landmark is the hero liveness cliché
|
|
1219
|
+
// and is promoted to error severity; occurrences elsewhere keep the
|
|
1220
|
+
// registry default severity.
|
|
1221
|
+
function scanCssTextForPulsingDot(content) {
|
|
1222
|
+
const customProps = collectCssCustomProps(content);
|
|
1223
|
+
const keyframes = collectPulseKeyframes(content);
|
|
1224
|
+
const heroRanges = landmarkSourceRanges(content);
|
|
1225
|
+
const findings = [];
|
|
1226
|
+
const seen = new Set();
|
|
1227
|
+
|
|
1228
|
+
// Merge declarations per selector across rule blocks, approximating the
|
|
1229
|
+
// cascade: later declarations for the same property win. Comma lists are
|
|
1230
|
+
// split so `.a, .b { … }` contributes to both selectors. Comments are
|
|
1231
|
+
// stripped first so they neither pollute selector keys nor smuggle a
|
|
1232
|
+
// comma into the selector-list split.
|
|
1233
|
+
const scanText = stripReducedMotionBlocks(content).replace(/\/\*[\s\S]*?\*\//g, ' ');
|
|
1234
|
+
const merged = new Map();
|
|
1235
|
+
const ruleRe = new RegExp(CSS_RULE_BLOCK_SOURCE, 'g');
|
|
1236
|
+
let m;
|
|
1237
|
+
while ((m = ruleRe.exec(scanText)) !== null) {
|
|
1238
|
+
const decls = parseCssDeclBlock(m[2]);
|
|
1239
|
+
if (decls.size === 0) continue;
|
|
1240
|
+
for (const rawSelector of m[1].split(',')) {
|
|
1241
|
+
const selector = rawSelector.trim();
|
|
1242
|
+
if (!selector || selector.startsWith('@')) continue;
|
|
1243
|
+
let acc = merged.get(selector);
|
|
1244
|
+
if (!acc) {
|
|
1245
|
+
acc = new Map();
|
|
1246
|
+
merged.set(selector, acc);
|
|
1247
|
+
}
|
|
1248
|
+
for (const [prop, value] of decls) acc.set(prop, value);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
for (const [selector, decls] of merged) {
|
|
1253
|
+
const names = infiniteAnimationNames(decls);
|
|
1254
|
+
if (names.length === 0) continue;
|
|
1255
|
+
const pulseName = names.find(n => {
|
|
1256
|
+
const known = keyframes.get(n);
|
|
1257
|
+
if (known != null) return known;
|
|
1258
|
+
return /pulse|blink|ping/i.test(n);
|
|
1259
|
+
});
|
|
1260
|
+
if (!pulseName) continue;
|
|
1261
|
+
|
|
1262
|
+
const w = cssLengthToPx(resolveVarRefs(
|
|
1263
|
+
decls.get('width') || decls.get('inline-size') || '', customProps));
|
|
1264
|
+
const h = cssLengthToPx(resolveVarRefs(
|
|
1265
|
+
decls.get('height') || decls.get('block-size') || '', customProps));
|
|
1266
|
+
if (w == null || h == null || w < 2 || h < 2 || w > 16 || h > 16) continue;
|
|
1267
|
+
|
|
1268
|
+
const radius = resolveVarRefs(decls.get('border-radius') || '', customProps);
|
|
1269
|
+
if (!isRoundDotRadius(radius, w, h)) continue;
|
|
1270
|
+
|
|
1271
|
+
if (seen.has(selector)) continue;
|
|
1272
|
+
seen.add(selector);
|
|
1273
|
+
const inLandmark = selectorHitsLandmark(content, selector, heroRanges);
|
|
1274
|
+
findings.push({
|
|
1275
|
+
id: 'pulsing-dot',
|
|
1276
|
+
snippet: `${selector} — ${w}x${h}px dot with infinite "${pulseName}" animation${inLandmark ? ' in header/nav' : ''}`,
|
|
1277
|
+
selector,
|
|
1278
|
+
...(inLandmark ? { severity: 'error' } : {}),
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
// Tailwind utilities: animate-ping / animate-pulse on a tiny rounded-full
|
|
1283
|
+
// element declared entirely in the class attribute.
|
|
1284
|
+
const classRe = /class\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;
|
|
1285
|
+
let cm;
|
|
1286
|
+
while ((cm = classRe.exec(content)) !== null) {
|
|
1287
|
+
const cls = cm[1] || cm[2] || '';
|
|
1288
|
+
const anim = cls.match(/\banimate-(ping|pulse)\b/);
|
|
1289
|
+
if (!anim) continue;
|
|
1290
|
+
if (!/\brounded-full\b/.test(cls)) continue;
|
|
1291
|
+
if (!/\b(?:w|h|size)-(?:1|1\.5|2|2\.5|3|3\.5|4)\b/.test(cls)) continue;
|
|
1292
|
+
const key = `tw:${cls}`;
|
|
1293
|
+
if (seen.has(key)) continue;
|
|
1294
|
+
seen.add(key);
|
|
1295
|
+
const inLandmark = indexInSourceRanges(cm.index, heroRanges);
|
|
1296
|
+
findings.push({
|
|
1297
|
+
id: 'pulsing-dot',
|
|
1298
|
+
snippet: `animate-${anim[1]} on tiny rounded-full element${inLandmark ? ' in header/nav' : ''}`,
|
|
1299
|
+
...(inLandmark ? { severity: 'error' } : {}),
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
return findings;
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
// Shape-assembled illustration: a large inline SVG composing a pictorial
|
|
1307
|
+
// scene from many primitive shapes (rect / circle / ellipse / polygon) in
|
|
1308
|
+
// several fill colors — the clip-art hero mascot. Gates keep the legitimate
|
|
1309
|
+
// SVG population out:
|
|
1310
|
+
// • icons and logos: intrinsic size gate (>= 200px on both axes, from
|
|
1311
|
+
// width/height attributes or the viewBox when no explicit size is set)
|
|
1312
|
+
// • charts / labeled diagrams: more than two <text>/<tspan> nodes exempts
|
|
1313
|
+
// the graphic (axis labels, callouts)
|
|
1314
|
+
// • line drawings / technical diagrams: primitive count < 8 or fewer
|
|
1315
|
+
// than 3 distinct fills never qualifies (stroke-only art has no fills)
|
|
1316
|
+
// • tiling background textures: any <pattern> definition exempts
|
|
1317
|
+
function scanHtmlForShapeAssembledIllustration(html) {
|
|
1318
|
+
const findings = [];
|
|
1319
|
+
const svgRe = /<svg\b[^>]*>[\s\S]*?<\/svg>/gi;
|
|
1320
|
+
let m;
|
|
1321
|
+
while ((m = svgRe.exec(html)) !== null) {
|
|
1322
|
+
const block = m[0];
|
|
1323
|
+
const openTag = (block.match(/^<svg\b[^>]*>/i) || [''])[0];
|
|
1324
|
+
|
|
1325
|
+
// Data-bearing or annotated graphics: axis labels and callout text
|
|
1326
|
+
// mark a chart or diagram, not a mascot.
|
|
1327
|
+
const textCount = (block.match(/<(?:text|tspan)\b/gi) || []).length;
|
|
1328
|
+
if (textCount > 2) continue;
|
|
1329
|
+
// Tiling texture definitions are decorative backgrounds, not scenes.
|
|
1330
|
+
if (/<pattern\b/i.test(block)) continue;
|
|
1331
|
+
|
|
1332
|
+
const primitives = (block.match(/<(?:rect|circle|ellipse|polygon)\b/gi) || []).length;
|
|
1333
|
+
if (primitives < 8) continue;
|
|
1334
|
+
|
|
1335
|
+
// Intrinsic size: explicit width/height attributes win; fall back to
|
|
1336
|
+
// the viewBox box. Percentage or missing sizes stay unresolvable on
|
|
1337
|
+
// that axis and the viewBox speaks for them.
|
|
1338
|
+
const attrDim = (name) => {
|
|
1339
|
+
// (?<![-\w]) keeps compound attributes like stroke-width from
|
|
1340
|
+
// masquerading as the svg's own width.
|
|
1341
|
+
const am = openTag.match(new RegExp(`(?<![-\\w])${name}\\s*=\\s*["']\\s*([\\d.]+)(?:px)?\\s*["']`, 'i'));
|
|
1342
|
+
return am ? parseFloat(am[1]) : null;
|
|
1343
|
+
};
|
|
1344
|
+
const vb = openTag.match(/\bviewBox\s*=\s*["']\s*[-\d.]+[\s,]+[-\d.]+[\s,]+([\d.]+)[\s,]+([\d.]+)\s*["']/i);
|
|
1345
|
+
const w = attrDim('width') ?? (vb ? parseFloat(vb[1]) : null);
|
|
1346
|
+
const h = attrDim('height') ?? (vb ? parseFloat(vb[2]) : null);
|
|
1347
|
+
if (w == null || h == null || w < 200 || h < 200) continue;
|
|
1348
|
+
|
|
1349
|
+
// Distinct fill paints (attributes and inline styles), excluding
|
|
1350
|
+
// non-paints. Multiple fills are what turn a shape pile into a scene.
|
|
1351
|
+
const fills = new Set();
|
|
1352
|
+
for (const fm of block.matchAll(/\bfill\s*[:=]\s*["']?\s*([^"';>}\s]+)/gi)) {
|
|
1353
|
+
const paint = fm[1].trim().toLowerCase();
|
|
1354
|
+
if (!paint || ['none', 'transparent', 'currentcolor', 'inherit'].includes(paint)) continue;
|
|
1355
|
+
fills.add(paint);
|
|
1356
|
+
}
|
|
1357
|
+
if (fills.size < 3) continue;
|
|
1358
|
+
|
|
1359
|
+
findings.push({
|
|
1360
|
+
id: 'shape-assembled-illustration',
|
|
1361
|
+
snippet: `inline <svg> scene: ${primitives} primitive shapes, ~${Math.round(w)}x${Math.round(h)}px, ${fills.size} fill colors`,
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
1364
|
+
return findings;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
443
1367
|
/**
|
|
444
1368
|
* Regex-on-HTML checks shared between browser and Node page-level detection.
|
|
445
1369
|
* These don't need DOM access, just the raw HTML string.
|
|
@@ -473,6 +1397,16 @@ function checkHtmlPatterns(html) {
|
|
|
473
1397
|
findings.push({ id: 'gradient-text', snippet: 'bg-clip-text + bg-gradient (Tailwind)' });
|
|
474
1398
|
}
|
|
475
1399
|
|
|
1400
|
+
// --- Borders ---
|
|
1401
|
+
|
|
1402
|
+
// Side-tab accent stripe drawn as an absolutely-positioned pseudo-element
|
|
1403
|
+
// (no border property involved, so the element-level border checks and
|
|
1404
|
+
// the border-left regexes never see it).
|
|
1405
|
+
findings.push(...scanCssTextForPseudoStripe(html));
|
|
1406
|
+
|
|
1407
|
+
// Side-tab accent stripe drawn as a single-edge inset box-shadow.
|
|
1408
|
+
findings.push(...scanCssTextForInsetStripe(html));
|
|
1409
|
+
|
|
476
1410
|
// --- Layout ---
|
|
477
1411
|
|
|
478
1412
|
// Monotonous spacing
|
|
@@ -548,33 +1482,34 @@ function checkHtmlPatterns(html) {
|
|
|
548
1482
|
}
|
|
549
1483
|
}
|
|
550
1484
|
|
|
551
|
-
//
|
|
1485
|
+
// Pulsing status dots (tiny circular elements on infinite pulse animations)
|
|
1486
|
+
findings.push(...scanCssTextForPulsingDot(html));
|
|
552
1487
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
}
|
|
1488
|
+
// Shape-assembled illustrations (large pictorial SVGs built from primitives)
|
|
1489
|
+
findings.push(...scanHtmlForShapeAssembledIllustration(html));
|
|
1490
|
+
|
|
1491
|
+
// Auto-scrolling marquees (<marquee> or infinite horizontal loop animations)
|
|
1492
|
+
findings.push(...scanCssTextForMarquee(html));
|
|
1493
|
+
|
|
1494
|
+
// --- Dark glow / chromatic halo shadows ---
|
|
1495
|
+
|
|
1496
|
+
const glowHits = scanCssTextForGlow(html);
|
|
1497
|
+
if (glowHits.length > 0) {
|
|
1498
|
+
findings.push({ id: 'dark-glow', snippet: glowHits[0].snippet });
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
// Radial-gradient background halo (gradient-drawn sibling of dark-glow)
|
|
1502
|
+
const haloHits = scanCssTextForRadialHalo(html);
|
|
1503
|
+
if (haloHits.length > 0) {
|
|
1504
|
+
findings.push({ id: 'radial-halo', snippet: haloHits[0].snippet });
|
|
570
1505
|
}
|
|
571
1506
|
|
|
572
|
-
// ---
|
|
1507
|
+
// --- Generated-UI tells: repeating-gradient stripes ---
|
|
573
1508
|
if (/repeating-(?:linear|radial|conic)-gradient\s*\(/i.test(html)) {
|
|
574
1509
|
findings.push({ id: 'repeating-stripes-gradient', snippet: 'repeating-gradient decorative stripes' });
|
|
575
1510
|
}
|
|
576
1511
|
|
|
577
|
-
// ---
|
|
1512
|
+
// --- Generated-UI tells: two-axis grid-line background ---
|
|
578
1513
|
// The Codex grid tell is two hairline `linear-gradient(... <color> 1px,
|
|
579
1514
|
// transparent 1px)` layers (one per axis) tiled by a repeating
|
|
580
1515
|
// `background-size` cell. Both signals must co-occur in the SAME style block
|
|
@@ -587,30 +1522,12 @@ function checkHtmlPatterns(html) {
|
|
|
587
1522
|
// in for the second axis. Colors like `oklch(96% 0.012 82 / 0.055)` carry
|
|
588
1523
|
// nested parens, so match the hairline stop directly rather than parsing
|
|
589
1524
|
// whole gradient layers.
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
const bgDeclRe = /\bbackground(?:-image)?\s*:\s*([^;{}"']*)/gi;
|
|
594
|
-
const blockRe = /\{([^{}]*)\}|style\s*=\s*"([^"]*)"|style\s*=\s*'([^']*)'/gi;
|
|
595
|
-
let blk;
|
|
596
|
-
while ((blk = blockRe.exec(html)) !== null) {
|
|
597
|
-
const block = blk[1] || blk[2] || blk[3] || '';
|
|
598
|
-
if (!gridSizeRe.test(block)) continue;
|
|
599
|
-
let hairlineCount = 0;
|
|
600
|
-
let bm;
|
|
601
|
-
bgDeclRe.lastIndex = 0;
|
|
602
|
-
while ((bm = bgDeclRe.exec(block)) !== null) {
|
|
603
|
-
const stops = bm[1].match(hairlineRe);
|
|
604
|
-
if (stops) hairlineCount += stops.length;
|
|
605
|
-
}
|
|
606
|
-
if (hairlineCount >= 2) {
|
|
607
|
-
findings.push({ id: 'codex-grid-background', snippet: 'two-axis grid-line gradient background' });
|
|
608
|
-
break;
|
|
609
|
-
}
|
|
610
|
-
}
|
|
1525
|
+
const gridHits = scanCssTextForGridBackground(html);
|
|
1526
|
+
if (gridHits.length > 0) {
|
|
1527
|
+
findings.push({ id: 'codex-grid-background', snippet: gridHits[0].snippet });
|
|
611
1528
|
}
|
|
612
1529
|
|
|
613
|
-
// ---
|
|
1530
|
+
// --- Generated-copy tells: "X theater" framing copy ---
|
|
614
1531
|
// Lives here (regex-on-HTML) rather than in the text-content analyzers so it
|
|
615
1532
|
// runs in the bundled browser path too, not just the CLI/static path.
|
|
616
1533
|
{
|
|
@@ -622,7 +1539,7 @@ function checkHtmlPatterns(html) {
|
|
|
622
1539
|
if (tm) findings.push({ id: 'theater-slop-phrase', snippet: `"${tm[0].trim()}"` });
|
|
623
1540
|
}
|
|
624
1541
|
|
|
625
|
-
// ---
|
|
1542
|
+
// --- Generated-UI tells: image hover transform ---
|
|
626
1543
|
// A CSS `img...:hover { transform: ... }` rule, or a Tailwind hover:scale /
|
|
627
1544
|
// hover:rotate / hover:translate utility on an <img>. Each distinct
|
|
628
1545
|
// mechanism is its own finding.
|
|
@@ -651,7 +1568,11 @@ function checkHtmlPatterns(html) {
|
|
|
651
1568
|
// `background: #abc`. Real browsers always decompose, so the fallback is
|
|
652
1569
|
// a no-op there.
|
|
653
1570
|
function readOwnBackgroundColor(el, computedStyle) {
|
|
654
|
-
|
|
1571
|
+
// Real browsers keep wide-gamut/computed color functions (oklch(), oklab(),
|
|
1572
|
+
// color-mix() results) in getComputedStyle output, which plain parseRgb
|
|
1573
|
+
// misses — a flat oklch button background would silently skip every
|
|
1574
|
+
// contrast check without the parseAnyColor fallback.
|
|
1575
|
+
const bg = parseRgb(computedStyle.backgroundColor) || parseAnyColor(computedStyle.backgroundColor);
|
|
655
1576
|
if (DETECTOR_IS_BROWSER || (bg && bg.a >= 0.1)) return bg;
|
|
656
1577
|
const rawStyle = el.getAttribute?.('style') || '';
|
|
657
1578
|
const bgMatch = rawStyle.match(/background(?:-color)?\s*:\s*([^;]+)/i);
|
|
@@ -673,6 +1594,18 @@ function readOwnBackgroundColor(el, computedStyle) {
|
|
|
673
1594
|
|
|
674
1595
|
function resolveBackground(el, win, customPropMap) {
|
|
675
1596
|
let current = el;
|
|
1597
|
+
// Translucent layers (0.1 < a < 1) found on the way down to an opaque
|
|
1598
|
+
// base. A browser composites these over the base; the old behavior
|
|
1599
|
+
// either returned them as-if-opaque (browser mode) or skipped them
|
|
1600
|
+
// entirely (static mode), both of which misstate the effective surface
|
|
1601
|
+
// for contrast checks (e.g. `background: color-mix(in oklab, var(--hot)
|
|
1602
|
+
// 16%, transparent)` chips on dark pages).
|
|
1603
|
+
const overlays = [];
|
|
1604
|
+
const flatten = (base) => {
|
|
1605
|
+
let acc = base;
|
|
1606
|
+
for (let i = overlays.length - 1; i >= 0; i--) acc = compositeColorOver(overlays[i], acc);
|
|
1607
|
+
return acc;
|
|
1608
|
+
};
|
|
676
1609
|
while (current && current.nodeType === 1) {
|
|
677
1610
|
const style = DETECTOR_IS_BROWSER ? getComputedStyle(current) : win.getComputedStyle(current);
|
|
678
1611
|
const bgImage = style.backgroundImage || '';
|
|
@@ -685,7 +1618,9 @@ function resolveBackground(el, win, customPropMap) {
|
|
|
685
1618
|
// decorative. The old behavior bailed on any gradient ancestor, which
|
|
686
1619
|
// caused massive false-positive contrast findings on grain-textured
|
|
687
1620
|
// body backgrounds.
|
|
688
|
-
|
|
1621
|
+
// Real browsers serialize wide-gamut computed values as oklab()/oklch()
|
|
1622
|
+
// (e.g. any color-mix() result), which plain parseRgb misses.
|
|
1623
|
+
let bg = parseRgb(style.backgroundColor) || parseAnyColor(style.backgroundColor);
|
|
689
1624
|
if (!DETECTOR_IS_BROWSER && (!bg || bg.a < 0.1)) {
|
|
690
1625
|
// jsdom returns literal "var(--X)" / "oklch(...)" strings. Resolve
|
|
691
1626
|
// through customPropMap so Tailwind v4 color tokens become RGB.
|
|
@@ -705,7 +1640,8 @@ function resolveBackground(el, win, customPropMap) {
|
|
|
705
1640
|
}
|
|
706
1641
|
|
|
707
1642
|
if (bg && bg.a > 0.1) {
|
|
708
|
-
if (
|
|
1643
|
+
if (bg.a >= 0.99) return flatten(bg);
|
|
1644
|
+
overlays.push(bg);
|
|
709
1645
|
}
|
|
710
1646
|
// No solid bg-color at this level. If THIS level has a gradient/url
|
|
711
1647
|
// with no underlying solid color we can read:
|
|
@@ -721,13 +1657,13 @@ function resolveBackground(el, win, customPropMap) {
|
|
|
721
1657
|
// bgs worth checking against).
|
|
722
1658
|
if (hasGradientOrUrl) {
|
|
723
1659
|
if (current.tagName === 'BODY' || current.tagName === 'HTML') {
|
|
724
|
-
return { r: 255, g: 255, b: 255, a: 1 };
|
|
1660
|
+
return flatten({ r: 255, g: 255, b: 255, a: 1 });
|
|
725
1661
|
}
|
|
726
1662
|
return null;
|
|
727
1663
|
}
|
|
728
1664
|
current = current.parentElement;
|
|
729
1665
|
}
|
|
730
|
-
return { r: 255, g: 255, b: 255 };
|
|
1666
|
+
return flatten({ r: 255, g: 255, b: 255, a: 1 });
|
|
731
1667
|
}
|
|
732
1668
|
|
|
733
1669
|
// Walk parents looking for a gradient background and return its color stops.
|
|
@@ -789,6 +1725,43 @@ function resolveBorderRadiusPx(el, style, widthPx, win) {
|
|
|
789
1725
|
|
|
790
1726
|
// Browser adapters — call getComputedStyle/getBoundingClientRect on live DOM
|
|
791
1727
|
|
|
1728
|
+
// Selected-state context for accent stripes. Only an actual selection
|
|
1729
|
+
// marker exempts the stripe as the standard active-item indicator:
|
|
1730
|
+
// aria-selected="true", aria-current (any non-false value), or an
|
|
1731
|
+
// active/current/selected class hint. Tab-strip MEMBERSHIP alone
|
|
1732
|
+
// ([role=tablist]/[role=tab]/.tabs ancestry, aria-selected="false")
|
|
1733
|
+
// deliberately does not — a chromatic stripe repeated on every tab in
|
|
1734
|
+
// the group, or on every menu item, is decoration, not state; the
|
|
1735
|
+
// selected item's own underline stays legal.
|
|
1736
|
+
function isTabContextElement(el) {
|
|
1737
|
+
if (!el) return false;
|
|
1738
|
+
try {
|
|
1739
|
+
if (el.closest?.('[aria-selected="true"], [aria-current]:not([aria-current="false"])')) return true;
|
|
1740
|
+
} catch { /* selector engine differences — fall through to class scan */ }
|
|
1741
|
+
let cur = el, depth = 0;
|
|
1742
|
+
while (cur && cur.nodeType === 1 && depth < 6) {
|
|
1743
|
+
const cls = String(cur.getAttribute?.('class') || cur.className || '');
|
|
1744
|
+
if (/(?:^|[\s_-])(?:active|current|selected)(?:$|[\s_-])/i.test(cls)) return true;
|
|
1745
|
+
cur = cur.parentElement;
|
|
1746
|
+
depth++;
|
|
1747
|
+
}
|
|
1748
|
+
return false;
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
// Status-surface context for accent borders. On a live status/alert region
|
|
1752
|
+
// (role=status|alert|alertdialog|log, or aria-live=polite|assertive) a colored
|
|
1753
|
+
// single-edge border is the established severity-accent convention — a toast,
|
|
1754
|
+
// snackbar, or callout bar — not the decorative side-tab tell. The element
|
|
1755
|
+
// itself or a wrapping live region qualifies. This never fires from the
|
|
1756
|
+
// CSS-only / regex scanners, which have no role information.
|
|
1757
|
+
function isStatusContextElement(el) {
|
|
1758
|
+
if (!el) return false;
|
|
1759
|
+
try {
|
|
1760
|
+
if (el.closest?.('[role="status"], [role="alert"], [role="alertdialog"], [role="log"], [aria-live="polite"], [aria-live="assertive"]')) return true;
|
|
1761
|
+
} catch { /* selector engine differences — fall through */ }
|
|
1762
|
+
return false;
|
|
1763
|
+
}
|
|
1764
|
+
|
|
792
1765
|
function checkElementBordersDOM(el) {
|
|
793
1766
|
const tag = el.tagName.toLowerCase();
|
|
794
1767
|
if (BORDER_SAFE_TAGS.has(tag)) return [];
|
|
@@ -801,7 +1774,105 @@ function checkElementBordersDOM(el) {
|
|
|
801
1774
|
widths[s] = parseFloat(style[`border${s}Width`]) || 0;
|
|
802
1775
|
colors[s] = style[`border${s}Color`] || '';
|
|
803
1776
|
}
|
|
804
|
-
|
|
1777
|
+
const ownBg = parseRgb(style.backgroundColor) || parseAnyColor(style.backgroundColor);
|
|
1778
|
+
return checkBorders(tag, widths, colors, parseFloat(style.borderRadius) || 0, {
|
|
1779
|
+
tabContext: isTabContextElement(el),
|
|
1780
|
+
statusContext: isStatusContextElement(el),
|
|
1781
|
+
badgeLike: !!(ownBg && (ownBg.a ?? 1) > 0.1),
|
|
1782
|
+
});
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
// Browser-side twin of scanCssTextForPseudoStripe. The text scanner reads
|
|
1786
|
+
// stylesheet source, so a stripe whose color only exists at runtime (an
|
|
1787
|
+
// inline per-card custom property, a JS-assigned var) or whose geometry
|
|
1788
|
+
// resolves in layout never matches it. In a real browser the pseudo-element's
|
|
1789
|
+
// computed style carries the actual used color and px geometry — check those
|
|
1790
|
+
// directly. Gates mirror the text scanner: 3-12px thick, chromatic fill,
|
|
1791
|
+
// spanning (nearly) the full edge; corner rounding on the host card is
|
|
1792
|
+
// irrelevant. Exemptions stay narrow: structural/prose tags, real selection
|
|
1793
|
+
// markers (isTabContextElement), and button/link affordances for the
|
|
1794
|
+
// horizontal variant.
|
|
1795
|
+
function checkElementPseudoStripeDOM(el) {
|
|
1796
|
+
const tag = el.tagName.toLowerCase();
|
|
1797
|
+
if (BORDER_SAFE_TAGS.has(tag) || tag === 'summary') return [];
|
|
1798
|
+
if (el.closest?.('nav, blockquote, pre')) return [];
|
|
1799
|
+
if (!isRenderedForBrowserRule(el)) return [];
|
|
1800
|
+
const rect = el.getBoundingClientRect();
|
|
1801
|
+
if (rect.width < 40 || rect.height < 20) return [];
|
|
1802
|
+
if (isTabContextElement(el)) return [];
|
|
1803
|
+
|
|
1804
|
+
const findings = [];
|
|
1805
|
+
for (const which of ['::before', '::after']) {
|
|
1806
|
+
let ps;
|
|
1807
|
+
try { ps = getComputedStyle(el, which); } catch { continue; }
|
|
1808
|
+
if (!ps || ps.content === 'none' || ps.content === '') continue;
|
|
1809
|
+
if (ps.position !== 'absolute' && ps.position !== 'fixed') continue;
|
|
1810
|
+
if ((parseFloat(ps.opacity) || 0) <= 0.01 || ps.display === 'none') continue;
|
|
1811
|
+
const w = parseFloat(ps.width) || 0;
|
|
1812
|
+
const h = parseFloat(ps.height) || 0;
|
|
1813
|
+
if (!(w > 0 && h > 0)) continue;
|
|
1814
|
+
|
|
1815
|
+
// Used values: for absolutely-positioned boxes the browser resolves
|
|
1816
|
+
// both edge offsets after layout, so left/right (and top/bottom) are
|
|
1817
|
+
// real distances, never "auto".
|
|
1818
|
+
const left = parseFloat(ps.left);
|
|
1819
|
+
const right = parseFloat(ps.right);
|
|
1820
|
+
const top = parseFloat(ps.top);
|
|
1821
|
+
const bottom = parseFloat(ps.bottom);
|
|
1822
|
+
const hugs = (v) => Number.isFinite(v) && v >= -2 && v <= 2;
|
|
1823
|
+
|
|
1824
|
+
let edge = null;
|
|
1825
|
+
let thickness = null;
|
|
1826
|
+
// Vertical stripe: narrow box spanning (nearly) the full height of the
|
|
1827
|
+
// host, hugging its left or right edge. "Nearly" tolerates the floating
|
|
1828
|
+
// variant that backs off each end by a small inset.
|
|
1829
|
+
if (w >= 3 && w <= 12 && h >= rect.height - 44 && h >= rect.height * 0.5) {
|
|
1830
|
+
edge = hugs(left) ? 'left' : hugs(right) ? 'right' : null;
|
|
1831
|
+
thickness = w;
|
|
1832
|
+
}
|
|
1833
|
+
// Horizontal stripe riding the top or bottom edge. Button/link-styled
|
|
1834
|
+
// hosts keep their underline affordances.
|
|
1835
|
+
if (!edge && h >= 3 && h <= 12 && w >= rect.width - 44 && w >= rect.width * 0.5) {
|
|
1836
|
+
const cls = String(el.getAttribute?.('class') || el.className || '');
|
|
1837
|
+
if (!/(?:^|[\s_-])(?:btn|button|link)(?:$|[\s\w_-])/i.test(cls)) {
|
|
1838
|
+
edge = hugs(top) ? 'top' : hugs(bottom) ? 'bottom' : null;
|
|
1839
|
+
thickness = h;
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
if (!edge) continue;
|
|
1843
|
+
|
|
1844
|
+
const bg = parseRgb(ps.backgroundColor) || parseAnyColor(ps.backgroundColor);
|
|
1845
|
+
if (!bg || (bg.a ?? 1) < 0.1) continue;
|
|
1846
|
+
if (Math.max(bg.r, bg.g, bg.b) - Math.min(bg.r, bg.g, bg.b) < 30) continue;
|
|
1847
|
+
|
|
1848
|
+
findings.push({
|
|
1849
|
+
id: 'side-tab',
|
|
1850
|
+
snippet: `${classSelector(el)}${which} — absolute ${thickness}px pseudo-element stripe (${edge})`,
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
return findings;
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
// Full-cover surface pseudo (browser): a ::before/::after positioned
|
|
1857
|
+
// absolute/fixed whose box covers (nearly) the whole host and carries an
|
|
1858
|
+
// opaque background. That pseudo is the element's visible surface even
|
|
1859
|
+
// though the element's own background-color reads transparent — the nav-CTA
|
|
1860
|
+
// construction that otherwise escapes every own-background contrast gate.
|
|
1861
|
+
function readPseudoSurfaceDOM(el, rect) {
|
|
1862
|
+
for (const which of ['::before', '::after']) {
|
|
1863
|
+
let ps;
|
|
1864
|
+
try { ps = getComputedStyle(el, which); } catch { continue; }
|
|
1865
|
+
if (!ps || ps.content === 'none' || ps.content === '') continue;
|
|
1866
|
+
if (ps.position !== 'absolute' && ps.position !== 'fixed') continue;
|
|
1867
|
+
if (ps.display === 'none' || (parseFloat(ps.opacity) || 1) < 0.9) continue;
|
|
1868
|
+
const w = parseFloat(ps.width) || 0;
|
|
1869
|
+
const h = parseFloat(ps.height) || 0;
|
|
1870
|
+
if (w < rect.width - 4 || h < rect.height - 4) continue;
|
|
1871
|
+
const bg = parseRgb(ps.backgroundColor) || parseAnyColor(ps.backgroundColor);
|
|
1872
|
+
if (!bg || (bg.a ?? 1) < 0.9) continue;
|
|
1873
|
+
return bg;
|
|
1874
|
+
}
|
|
1875
|
+
return null;
|
|
805
1876
|
}
|
|
806
1877
|
|
|
807
1878
|
function checkElementColorsDOM(el) {
|
|
@@ -814,11 +1885,24 @@ function checkElementColorsDOM(el) {
|
|
|
814
1885
|
const style = getComputedStyle(el);
|
|
815
1886
|
const directText = [...el.childNodes].filter(n => n.nodeType === 3).map(n => n.textContent).join('');
|
|
816
1887
|
const hasDirectText = directText.trim().length > 0;
|
|
817
|
-
|
|
1888
|
+
let effectiveBg = resolveBackground(el);
|
|
1889
|
+
let ownBg = readOwnBackgroundColor(el, style);
|
|
1890
|
+
if (!ownBg || (ownBg.a ?? 1) <= 0.5) {
|
|
1891
|
+
const pseudoSurface = readPseudoSurfaceDOM(el, rect);
|
|
1892
|
+
if (pseudoSurface) {
|
|
1893
|
+
ownBg = pseudoSurface;
|
|
1894
|
+
effectiveBg = pseudoSurface;
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
818
1897
|
return checkColors({
|
|
819
1898
|
tag,
|
|
820
|
-
|
|
821
|
-
|
|
1899
|
+
// Chrome serializes computed colors specified in modern spaces as
|
|
1900
|
+
// oklch()/oklab() strings; without the parseAnyColor fallback the text
|
|
1901
|
+
// color comes back null and the low-contrast / gray-on-color checks
|
|
1902
|
+
// silently never run (the shipped miss: a nav CTA whose text color was
|
|
1903
|
+
// an oklch token near its own oklch background).
|
|
1904
|
+
textColor: parseRgb(style.color) || parseAnyColor(style.color),
|
|
1905
|
+
bgColor: ownBg,
|
|
822
1906
|
effectiveBg,
|
|
823
1907
|
effectiveBgStops: effectiveBg ? null : resolveGradientStops(el),
|
|
824
1908
|
fontSize: parseFloat(style.fontSize) || 16,
|
|
@@ -879,6 +1963,21 @@ function checkElementItalicSerifDOM(el) {
|
|
|
879
1963
|
});
|
|
880
1964
|
}
|
|
881
1965
|
|
|
1966
|
+
function domAccentDashPseudo(el) {
|
|
1967
|
+
for (const which of ['::before', '::after']) {
|
|
1968
|
+
let ps;
|
|
1969
|
+
try { ps = getComputedStyle(el, which); } catch { continue; }
|
|
1970
|
+
if (!ps || ps.content === 'none' || ps.content === '') continue;
|
|
1971
|
+
const w = parseFloat(ps.width) || 0;
|
|
1972
|
+
const h = parseFloat(ps.height) || 0;
|
|
1973
|
+
if (!(w >= 8 && w <= 80 && h >= 1 && h <= 6)) continue;
|
|
1974
|
+
const bg = parseRgb(ps.backgroundColor) || parseAnyColor(ps.backgroundColor);
|
|
1975
|
+
if (!bg || (bg.a ?? 1) < 0.1) continue;
|
|
1976
|
+
if (Math.max(bg.r, bg.g, bg.b) - Math.min(bg.r, bg.g, bg.b) >= 30) return true;
|
|
1977
|
+
}
|
|
1978
|
+
return false;
|
|
1979
|
+
}
|
|
1980
|
+
|
|
882
1981
|
function checkElementHeroEyebrowDOM(el) {
|
|
883
1982
|
const tag = el.tagName.toLowerCase();
|
|
884
1983
|
if (tag !== 'h1') return [];
|
|
@@ -890,6 +1989,7 @@ function checkElementHeroEyebrowDOM(el) {
|
|
|
890
1989
|
headingTag: tag,
|
|
891
1990
|
headingText: el.textContent || '',
|
|
892
1991
|
headingFontSize: parseFloat(headStyle.fontSize) || 0,
|
|
1992
|
+
headingInApplicationContext: !!el.closest('[role="tabpanel"], [role="dialog"], [role="application"], dialog'),
|
|
893
1993
|
siblingTag: sibling.tagName.toLowerCase(),
|
|
894
1994
|
siblingText: sibling.textContent || '',
|
|
895
1995
|
siblingTextTransform: sibStyle.textTransform || '',
|
|
@@ -897,6 +1997,7 @@ function checkElementHeroEyebrowDOM(el) {
|
|
|
897
1997
|
siblingLetterSpacing: parseFloat(sibStyle.letterSpacing) || 0,
|
|
898
1998
|
siblingFontWeight: sibStyle.fontWeight || '',
|
|
899
1999
|
siblingColor: sibStyle.color || '',
|
|
2000
|
+
siblingHasAccentDashPseudo: domAccentDashPseudo(sibling),
|
|
900
2001
|
});
|
|
901
2002
|
}
|
|
902
2003
|
|
|
@@ -961,8 +2062,10 @@ function resolveVarRefs(raw, customPropMap, depth = 0) {
|
|
|
961
2062
|
// detector's contrast / color checks.
|
|
962
2063
|
function oklchToRgb(L, C, H) {
|
|
963
2064
|
const hRad = (H * Math.PI) / 180;
|
|
964
|
-
|
|
965
|
-
|
|
2065
|
+
return oklabToRgb(L, C * Math.cos(hRad), C * Math.sin(hRad));
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
function oklabToRgb(L, a, b) {
|
|
966
2069
|
const l_ = L + 0.3963377774 * a + 0.2158037573 * b;
|
|
967
2070
|
const m_ = L - 0.1055613458 * a - 0.0638541728 * b;
|
|
968
2071
|
const s_ = L - 0.0894841775 * a - 1.2914855480 * b;
|
|
@@ -982,13 +2085,178 @@ function oklchToRgb(L, C, H) {
|
|
|
982
2085
|
};
|
|
983
2086
|
}
|
|
984
2087
|
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
2088
|
+
function hslToRgb(h, s, l) {
|
|
2089
|
+
h = ((h % 360) + 360) % 360;
|
|
2090
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
2091
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
2092
|
+
const m0 = l - c / 2;
|
|
2093
|
+
const [r, g, b] =
|
|
2094
|
+
h < 60 ? [c, x, 0] :
|
|
2095
|
+
h < 120 ? [x, c, 0] :
|
|
2096
|
+
h < 180 ? [0, c, x] :
|
|
2097
|
+
h < 240 ? [0, x, c] :
|
|
2098
|
+
h < 300 ? [x, 0, c] : [c, 0, x];
|
|
2099
|
+
return {
|
|
2100
|
+
r: Math.round((r + m0) * 255),
|
|
2101
|
+
g: Math.round((g + m0) * 255),
|
|
2102
|
+
b: Math.round((b + m0) * 255),
|
|
2103
|
+
a: 1,
|
|
2104
|
+
};
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
function hwbToRgb(h, w, bl) {
|
|
2108
|
+
if (w + bl >= 1) {
|
|
2109
|
+
const g = Math.round((w / (w + bl)) * 255);
|
|
2110
|
+
return { r: g, g, b: g, a: 1 };
|
|
2111
|
+
}
|
|
2112
|
+
const base = hslToRgb(h, 1, 0.5);
|
|
2113
|
+
const mix = (c) => Math.round(((c / 255) * (1 - w - bl) + w) * 255);
|
|
2114
|
+
return { r: mix(base.r), g: mix(base.g), b: mix(base.b), a: 1 };
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
// Common CSS named colors — the handful that actually show up in generated
|
|
2118
|
+
// UIs, not the full 148-name spec list. Includes the achromatic names so a
|
|
2119
|
+
// named gray parses (and correctly reads as no-chroma) instead of being
|
|
2120
|
+
// treated as an unknown color.
|
|
2121
|
+
const CSS_NAMED_COLORS = {
|
|
2122
|
+
black: { r: 0, g: 0, b: 0 },
|
|
2123
|
+
white: { r: 255, g: 255, b: 255 },
|
|
2124
|
+
gray: { r: 128, g: 128, b: 128 },
|
|
2125
|
+
grey: { r: 128, g: 128, b: 128 },
|
|
2126
|
+
silver: { r: 192, g: 192, b: 192 },
|
|
2127
|
+
dimgray: { r: 105, g: 105, b: 105 },
|
|
2128
|
+
darkgray: { r: 169, g: 169, b: 169 },
|
|
2129
|
+
lightgray: { r: 211, g: 211, b: 211 },
|
|
2130
|
+
gainsboro: { r: 220, g: 220, b: 220 },
|
|
2131
|
+
whitesmoke: { r: 245, g: 245, b: 245 },
|
|
2132
|
+
red: { r: 255, g: 0, b: 0 },
|
|
2133
|
+
crimson: { r: 220, g: 20, b: 60 },
|
|
2134
|
+
tomato: { r: 255, g: 99, b: 71 },
|
|
2135
|
+
coral: { r: 255, g: 127, b: 80 },
|
|
2136
|
+
salmon: { r: 250, g: 128, b: 114 },
|
|
2137
|
+
orange: { r: 255, g: 165, b: 0 },
|
|
2138
|
+
gold: { r: 255, g: 215, b: 0 },
|
|
2139
|
+
yellow: { r: 255, g: 255, b: 0 },
|
|
2140
|
+
olive: { r: 128, g: 128, b: 0 },
|
|
2141
|
+
lime: { r: 0, g: 255, b: 0 },
|
|
2142
|
+
green: { r: 0, g: 128, b: 0 },
|
|
2143
|
+
teal: { r: 0, g: 128, b: 128 },
|
|
2144
|
+
turquoise: { r: 64, g: 224, b: 208 },
|
|
2145
|
+
cyan: { r: 0, g: 255, b: 255 },
|
|
2146
|
+
aqua: { r: 0, g: 255, b: 255 },
|
|
2147
|
+
skyblue: { r: 135, g: 206, b: 235 },
|
|
2148
|
+
dodgerblue: { r: 30, g: 144, b: 255 },
|
|
2149
|
+
blue: { r: 0, g: 0, b: 255 },
|
|
2150
|
+
navy: { r: 0, g: 0, b: 128 },
|
|
2151
|
+
indigo: { r: 75, g: 0, b: 130 },
|
|
2152
|
+
rebeccapurple: { r: 102, g: 51, b: 153 },
|
|
2153
|
+
purple: { r: 128, g: 0, b: 128 },
|
|
2154
|
+
violet: { r: 238, g: 130, b: 238 },
|
|
2155
|
+
orchid: { r: 218, g: 112, b: 214 },
|
|
2156
|
+
magenta: { r: 255, g: 0, b: 255 },
|
|
2157
|
+
fuchsia: { r: 255, g: 0, b: 255 },
|
|
2158
|
+
hotpink: { r: 255, g: 105, b: 180 },
|
|
2159
|
+
pink: { r: 255, g: 192, b: 203 },
|
|
2160
|
+
maroon: { r: 128, g: 0, b: 0 },
|
|
2161
|
+
};
|
|
2162
|
+
|
|
2163
|
+
// Split a string on top-level commas (ignoring commas nested in parens).
|
|
2164
|
+
function splitTopLevelCommas(str) {
|
|
2165
|
+
const parts = [];
|
|
2166
|
+
let depth = 0, start = 0;
|
|
2167
|
+
for (let i = 0; i < str.length; i++) {
|
|
2168
|
+
const ch = str[i];
|
|
2169
|
+
if (ch === '(') depth++;
|
|
2170
|
+
else if (ch === ')') depth = Math.max(0, depth - 1);
|
|
2171
|
+
else if (ch === ',' && depth === 0) {
|
|
2172
|
+
parts.push(str.slice(start, i).trim());
|
|
2173
|
+
start = i + 1;
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
const tail = str.slice(start).trim();
|
|
2177
|
+
if (tail) parts.push(tail);
|
|
2178
|
+
return parts;
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2181
|
+
// Evaluate a CSS color-mix() expression to {r,g,b,a}. Returns null when
|
|
2182
|
+
// the expression can't be resolved (unresolved var(), unknown colors).
|
|
2183
|
+
//
|
|
2184
|
+
// Mixing is done with premultiplied alpha in sRGB regardless of the
|
|
2185
|
+
// declared interpolation space. That is exact for the dominant generated-UI
|
|
2186
|
+
// pattern — `color-mix(in oklab, <color> N%, transparent)` — where the
|
|
2187
|
+
// result is simply <color> at alpha N% in ANY rectangular space, and a
|
|
2188
|
+
// close-enough approximation for opaque-opaque mixes (the detector only
|
|
2189
|
+
// consumes these values for contrast/chroma thresholds, not for display).
|
|
2190
|
+
function parseColorMix(str) {
|
|
2191
|
+
const m = String(str).trim().match(/^color-mix\(/i);
|
|
2192
|
+
if (!m) return null;
|
|
2193
|
+
// Balanced-paren capture of the arguments.
|
|
2194
|
+
let depth = 0, end = -1;
|
|
2195
|
+
const open = str.indexOf('(');
|
|
2196
|
+
for (let i = open; i < str.length; i++) {
|
|
2197
|
+
if (str[i] === '(') depth++;
|
|
2198
|
+
else if (str[i] === ')') { depth--; if (depth === 0) { end = i; break; } }
|
|
2199
|
+
}
|
|
2200
|
+
if (end < 0) return null;
|
|
2201
|
+
const args = splitTopLevelCommas(str.slice(open + 1, end));
|
|
2202
|
+
if (args.length !== 3 || !/^in\s/i.test(args[0])) return null;
|
|
2203
|
+
|
|
2204
|
+
const parseComponent = (component) => {
|
|
2205
|
+
// Percentage may lead or trail the color per spec.
|
|
2206
|
+
let pct = null;
|
|
2207
|
+
let colorStr = component;
|
|
2208
|
+
const trail = component.match(/\s+([\d.]+)%$/);
|
|
2209
|
+
const lead = component.match(/^([\d.]+)%\s+/);
|
|
2210
|
+
if (trail) { pct = parseFloat(trail[1]); colorStr = component.slice(0, trail.index).trim(); }
|
|
2211
|
+
else if (lead) { pct = parseFloat(lead[1]); colorStr = component.slice(lead[0].length).trim(); }
|
|
2212
|
+
let color;
|
|
2213
|
+
if (/^transparent$/i.test(colorStr)) color = { r: 0, g: 0, b: 0, a: 0 };
|
|
2214
|
+
else color = parseAnyColor(colorStr);
|
|
2215
|
+
if (!color) return null;
|
|
2216
|
+
return { color, pct };
|
|
2217
|
+
};
|
|
2218
|
+
|
|
2219
|
+
const c1 = parseComponent(args[1]);
|
|
2220
|
+
const c2 = parseComponent(args[2]);
|
|
2221
|
+
if (!c1 || !c2) return null;
|
|
2222
|
+
let p1 = c1.pct, p2 = c2.pct;
|
|
2223
|
+
if (p1 == null && p2 == null) { p1 = 50; p2 = 50; }
|
|
2224
|
+
else if (p1 == null) p1 = 100 - p2;
|
|
2225
|
+
else if (p2 == null) p2 = 100 - p1;
|
|
2226
|
+
const sum = p1 + p2;
|
|
2227
|
+
if (sum <= 0) return null;
|
|
2228
|
+
// Per spec: weights normalize to sum; when sum < 100 the result alpha is
|
|
2229
|
+
// additionally scaled by sum/100.
|
|
2230
|
+
const w1 = p1 / sum, w2 = p2 / sum;
|
|
2231
|
+
const alphaScale = sum < 100 ? sum / 100 : 1;
|
|
2232
|
+
const a1 = c1.color.a ?? 1, a2 = c2.color.a ?? 1;
|
|
2233
|
+
const a = (a1 * w1 + a2 * w2) * alphaScale;
|
|
2234
|
+
if (a <= 0) return { r: 0, g: 0, b: 0, a: 0 };
|
|
2235
|
+
const mix = (ch) => Math.round((c1.color[ch] * a1 * w1 + c2.color[ch] * a2 * w2) / (a1 * w1 + a2 * w2));
|
|
2236
|
+
return { r: mix('r'), g: mix('g'), b: mix('b'), a: Math.min(1, a) };
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
// Composite a translucent color over an opaque(ish) base (simple
|
|
2240
|
+
// source-over in sRGB). Returns an opaque {r,g,b,a:1}.
|
|
2241
|
+
function compositeColorOver(top, base) {
|
|
2242
|
+
const a = top.a ?? 1;
|
|
2243
|
+
return {
|
|
2244
|
+
r: Math.round(top.r * a + base.r * (1 - a)),
|
|
2245
|
+
g: Math.round(top.g * a + base.g * (1 - a)),
|
|
2246
|
+
b: Math.round(top.b * a + base.b * (1 - a)),
|
|
2247
|
+
a: 1,
|
|
2248
|
+
};
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
// Extended color parser: rgb/rgba/hex/oklch/oklab/hsl/hwb/color-mix/common
|
|
2252
|
+
// named colors. Returns null on no match. Use this when the input might be
|
|
2253
|
+
// any CSS color form; use plain parseRgb when you only expect computed rgb()
|
|
2254
|
+
// values from real browsers.
|
|
988
2255
|
function parseAnyColor(s) {
|
|
989
2256
|
if (!s || typeof s !== 'string') return null;
|
|
990
2257
|
const str = s.trim();
|
|
991
2258
|
if (str === 'transparent' || str === 'currentcolor' || str === 'inherit') return null;
|
|
2259
|
+
if (/^color-mix\(/i.test(str)) return parseColorMix(str);
|
|
992
2260
|
let m;
|
|
993
2261
|
m = str.match(/rgba?\(\s*(\d+(?:\.\d+)?)\s*,?\s*(\d+(?:\.\d+)?)\s*,?\s*(\d+(?:\.\d+)?)(?:\s*[,/]\s*([\d.]+))?\s*\)/);
|
|
994
2262
|
if (m) return { r: Math.round(+m[1]), g: Math.round(+m[2]), b: Math.round(+m[3]), a: m[4] !== undefined ? +m[4] : 1 };
|
|
@@ -1026,6 +2294,41 @@ function parseAnyColor(s) {
|
|
|
1026
2294
|
}
|
|
1027
2295
|
return rgb;
|
|
1028
2296
|
}
|
|
2297
|
+
// OKLAB — a/b are signed axes; percentages map 100% → 0.4.
|
|
2298
|
+
m = str.match(/oklab\(\s*([\d.]+)(%?)\s+(-?[\d.]+)(%?)\s+(-?[\d.]+)(%?)(?:\s*\/\s*([\d.]+)(%)?)?\s*\)/i);
|
|
2299
|
+
if (m) {
|
|
2300
|
+
const L = m[2] === '%' ? parseFloat(m[1]) / 100 : parseFloat(m[1]);
|
|
2301
|
+
const a = m[4] === '%' ? parseFloat(m[3]) * 0.004 : parseFloat(m[3]);
|
|
2302
|
+
const b = m[6] === '%' ? parseFloat(m[5]) * 0.004 : parseFloat(m[5]);
|
|
2303
|
+
const rgb = oklabToRgb(L, a, b);
|
|
2304
|
+
if (m[7] !== undefined) {
|
|
2305
|
+
const alpha = parseFloat(m[7]);
|
|
2306
|
+
rgb.a = m[8] === '%' ? alpha / 100 : alpha;
|
|
2307
|
+
}
|
|
2308
|
+
return rgb;
|
|
2309
|
+
}
|
|
2310
|
+
// HSL/HSLA — comma or space syntax, optional deg on hue.
|
|
2311
|
+
m = str.match(/hsla?\(\s*(-?[\d.]+)(?:deg)?\s*[,\s]\s*([\d.]+)%\s*[,\s]\s*([\d.]+)%(?:\s*[,/]\s*([\d.]+)(%)?)?\s*\)/i);
|
|
2312
|
+
if (m) {
|
|
2313
|
+
const rgb = hslToRgb(parseFloat(m[1]), parseFloat(m[2]) / 100, parseFloat(m[3]) / 100);
|
|
2314
|
+
if (m[4] !== undefined) {
|
|
2315
|
+
const alpha = parseFloat(m[4]);
|
|
2316
|
+
rgb.a = m[5] === '%' ? alpha / 100 : alpha;
|
|
2317
|
+
}
|
|
2318
|
+
return rgb;
|
|
2319
|
+
}
|
|
2320
|
+
// HWB — hue whiteness% blackness%.
|
|
2321
|
+
m = str.match(/hwb\(\s*(-?[\d.]+)(?:deg)?\s+([\d.]+)%\s+([\d.]+)%(?:\s*\/\s*([\d.]+)(%)?)?\s*\)/i);
|
|
2322
|
+
if (m) {
|
|
2323
|
+
const rgb = hwbToRgb(parseFloat(m[1]), parseFloat(m[2]) / 100, parseFloat(m[3]) / 100);
|
|
2324
|
+
if (m[4] !== undefined) {
|
|
2325
|
+
const alpha = parseFloat(m[4]);
|
|
2326
|
+
rgb.a = m[5] === '%' ? alpha / 100 : alpha;
|
|
2327
|
+
}
|
|
2328
|
+
return rgb;
|
|
2329
|
+
}
|
|
2330
|
+
const named = CSS_NAMED_COLORS[str.toLowerCase()];
|
|
2331
|
+
if (named) return { ...named, a: 1 };
|
|
1029
2332
|
return null;
|
|
1030
2333
|
}
|
|
1031
2334
|
|
|
@@ -1118,42 +2421,206 @@ function collectRepeatedSectionKickerCandidates(doc, getStyle, resolveLetterSpac
|
|
|
1118
2421
|
if (isRepeatedKickerCardContext(heading, kicker)) continue;
|
|
1119
2422
|
|
|
1120
2423
|
const headingStyle = getStyle(heading);
|
|
1121
|
-
const kickerStyle = getStyle(kicker);
|
|
2424
|
+
const kickerStyle = getStyle(kicker);
|
|
2425
|
+
const headingText = (heading.textContent || '').replace(/\s+/g, ' ').trim();
|
|
2426
|
+
const kickerText = cleanInlineText(kicker) || (kicker.textContent || '').replace(/\s+/g, ' ').trim();
|
|
2427
|
+
const headingFontSize = resolveLetterSpacing(headingStyle.fontSize || '', 16) || parseFloat(headingStyle.fontSize) || 0;
|
|
2428
|
+
const kickerFontSize = resolveLetterSpacing(kickerStyle.fontSize || '', 16) || parseFloat(kickerStyle.fontSize) || 0;
|
|
2429
|
+
const kickerLetterSpacing = resolveLetterSpacing(kickerStyle.letterSpacing || '', kickerFontSize);
|
|
2430
|
+
|
|
2431
|
+
if (!isRepeatedKickerCandidate({
|
|
2432
|
+
headingTag: heading.tagName.toLowerCase(),
|
|
2433
|
+
headingText,
|
|
2434
|
+
headingFontSize,
|
|
2435
|
+
kickerTag: kicker.tagName.toLowerCase(),
|
|
2436
|
+
kickerText,
|
|
2437
|
+
kickerTextTransform: kickerStyle.textTransform || '',
|
|
2438
|
+
kickerFontSize,
|
|
2439
|
+
kickerLetterSpacing,
|
|
2440
|
+
})) {
|
|
2441
|
+
continue;
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
candidates.push({
|
|
2445
|
+
headingTag: heading.tagName.toLowerCase(),
|
|
2446
|
+
headingText: headingText.replace(/^"|"$/g, '').slice(0, 60),
|
|
2447
|
+
kickerText: kickerText.slice(0, 40),
|
|
2448
|
+
});
|
|
2449
|
+
}
|
|
2450
|
+
return candidates;
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
function checkRepeatedSectionKickersDOM() {
|
|
2454
|
+
const candidates = collectRepeatedSectionKickerCandidates(
|
|
2455
|
+
document,
|
|
2456
|
+
(el) => getComputedStyle(el),
|
|
2457
|
+
(value, fontSize) => resolveLengthPx(value, fontSize) || 0,
|
|
2458
|
+
);
|
|
2459
|
+
return checkRepeatedSectionKickers({ candidates });
|
|
2460
|
+
}
|
|
2461
|
+
|
|
2462
|
+
// ── Numbered section labels ─────────────────────────────────────────────────
|
|
2463
|
+
// Sibling of the repeated-kicker rule: instead of a tracked uppercase word,
|
|
2464
|
+
// the section scaffold is a tiny numeric index riding beside each section
|
|
2465
|
+
// heading — bare and zero-padded, or an index joined to a short micro-label
|
|
2466
|
+
// by a separator glyph. The kicker rule deliberately excludes bare 1-2 digit
|
|
2467
|
+
// labels; this rule owns that shape.
|
|
2468
|
+
|
|
2469
|
+
const NUMBERED_LABEL_TAGS = new Set(['span', 'p', 'div', 'small', 'em', 'strong', 'b']);
|
|
2470
|
+
|
|
2471
|
+
// Returns { index, text } when the trimmed text reads as a section index
|
|
2472
|
+
// label, else null. Two accepted shapes: a zero-padded/two-digit bare index,
|
|
2473
|
+
// or a 1-2 digit index followed by a non-word separator and a short label.
|
|
2474
|
+
function parseNumberedLabelText(rawText) {
|
|
2475
|
+
const text = (rawText || '').replace(/\s+/g, ' ').trim();
|
|
2476
|
+
if (!text || text.length > 40) return null;
|
|
2477
|
+
let m = /^(\d{2})$/.exec(text);
|
|
2478
|
+
if (!m) m = /^(\d{1,2})\s*[^\w\s]\s*\S/.exec(text);
|
|
2479
|
+
if (!m) return null;
|
|
2480
|
+
const index = parseInt(m[1], 10);
|
|
2481
|
+
if (!Number.isFinite(index) || index > 40) return null;
|
|
2482
|
+
return { index, text };
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2485
|
+
function isNumberedSectionLabelCandidate(opts) {
|
|
2486
|
+
const {
|
|
2487
|
+
headingTag, headingText, headingFontSize,
|
|
2488
|
+
labelTag, labelIndex, labelText,
|
|
2489
|
+
labelFontSize, labelLetterSpacing, labelFontWeight,
|
|
2490
|
+
labelFontFamily, labelTextTransform, labelColor,
|
|
2491
|
+
} = opts;
|
|
2492
|
+
if (!['h2', 'h3', 'h4'].includes(headingTag)) return false;
|
|
2493
|
+
if (!headingText || headingText.length < 3) return false;
|
|
2494
|
+
if (!labelTag || !NUMBERED_LABEL_TAGS.has(labelTag)) return false;
|
|
2495
|
+
if (labelIndex == null || !labelText) return false;
|
|
2496
|
+
// Tiny rendered size is the tell — a display-scale section number is a
|
|
2497
|
+
// different (deliberate) device and stays legal.
|
|
2498
|
+
if (!(labelFontSize > 0 && labelFontSize <= 13)) return false;
|
|
2499
|
+
// The heading must be visibly larger where we can resolve its size.
|
|
2500
|
+
// clamp()/var() sizes come back unparseable (0) in the static engine —
|
|
2501
|
+
// the remaining gates carry the check there.
|
|
2502
|
+
if (headingFontSize > 0 && headingFontSize < labelFontSize * 1.3) return false;
|
|
2503
|
+
// Deliberate micro-label styling separates the scaffold from incidental
|
|
2504
|
+
// small text: mono face, bold weight, tracking, uppercase, or accent color.
|
|
2505
|
+
const weight = Number(labelFontWeight) || 400;
|
|
2506
|
+
return /mono/i.test(labelFontFamily || '')
|
|
2507
|
+
|| weight >= 600
|
|
2508
|
+
|| (labelLetterSpacing || 0) >= 0.5
|
|
2509
|
+
|| (labelTextTransform || '') === 'uppercase'
|
|
2510
|
+
|| isAccentColor(labelColor || '');
|
|
2511
|
+
}
|
|
2512
|
+
|
|
2513
|
+
function collectNumberedSectionLabelCandidates(doc, getStyle, resolveLetterSpacing) {
|
|
2514
|
+
const candidates = [];
|
|
2515
|
+
const seenLabels = new Set();
|
|
2516
|
+
for (const heading of doc.querySelectorAll('h2, h3, h4')) {
|
|
2517
|
+
if (heading.closest?.(REPEATED_KICKER_SKIP_SELECTOR)) continue;
|
|
2518
|
+
// The index sits either directly before the heading, or before the
|
|
2519
|
+
// wrapper the heading leads (label | <div><h2>…</h2>…</div>).
|
|
2520
|
+
let label = heading.previousElementSibling;
|
|
2521
|
+
if (!label) {
|
|
2522
|
+
const parent = heading.parentElement;
|
|
2523
|
+
const firstChild = parent?.children?.[0];
|
|
2524
|
+
if (firstChild === heading) label = parent.previousElementSibling;
|
|
2525
|
+
}
|
|
2526
|
+
if (!label || seenLabels.has(label)) continue;
|
|
2527
|
+
if (label.closest?.(REPEATED_KICKER_SKIP_SELECTOR)) continue;
|
|
2528
|
+
if (HEADING_TAGS.has(label.tagName.toLowerCase())) continue;
|
|
2529
|
+
if (isRepeatedKickerCardContext(heading, label)) continue;
|
|
2530
|
+
|
|
2531
|
+
const labelText = cleanInlineText(label) || (label.textContent || '').replace(/\s+/g, ' ').trim();
|
|
2532
|
+
const parsed = parseNumberedLabelText(labelText);
|
|
2533
|
+
if (!parsed) continue;
|
|
2534
|
+
|
|
2535
|
+
const headingStyle = getStyle(heading);
|
|
2536
|
+
const labelStyle = getStyle(label);
|
|
1122
2537
|
const headingText = (heading.textContent || '').replace(/\s+/g, ' ').trim();
|
|
1123
|
-
const kickerText = cleanInlineText(kicker) || (kicker.textContent || '').replace(/\s+/g, ' ').trim();
|
|
1124
2538
|
const headingFontSize = resolveLetterSpacing(headingStyle.fontSize || '', 16) || parseFloat(headingStyle.fontSize) || 0;
|
|
1125
|
-
const
|
|
1126
|
-
const kickerLetterSpacing = resolveLetterSpacing(kickerStyle.letterSpacing || '', kickerFontSize);
|
|
2539
|
+
const labelFontSize = resolveLetterSpacing(labelStyle.fontSize || '', 16) || parseFloat(labelStyle.fontSize) || 0;
|
|
1127
2540
|
|
|
1128
|
-
if (!
|
|
2541
|
+
if (!isNumberedSectionLabelCandidate({
|
|
1129
2542
|
headingTag: heading.tagName.toLowerCase(),
|
|
1130
2543
|
headingText,
|
|
1131
2544
|
headingFontSize,
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
2545
|
+
labelTag: label.tagName.toLowerCase(),
|
|
2546
|
+
labelIndex: parsed.index,
|
|
2547
|
+
labelText: parsed.text,
|
|
2548
|
+
labelFontSize,
|
|
2549
|
+
labelLetterSpacing: resolveLetterSpacing(labelStyle.letterSpacing || '', labelFontSize),
|
|
2550
|
+
labelFontWeight: labelStyle.fontWeight || '',
|
|
2551
|
+
labelFontFamily: labelStyle.fontFamily || '',
|
|
2552
|
+
labelTextTransform: labelStyle.textTransform || '',
|
|
2553
|
+
labelColor: labelStyle.color || '',
|
|
1137
2554
|
})) {
|
|
1138
2555
|
continue;
|
|
1139
2556
|
}
|
|
1140
2557
|
|
|
2558
|
+
seenLabels.add(label);
|
|
1141
2559
|
candidates.push({
|
|
2560
|
+
index: parsed.index,
|
|
2561
|
+
labelText: parsed.text.slice(0, 24),
|
|
1142
2562
|
headingTag: heading.tagName.toLowerCase(),
|
|
1143
2563
|
headingText: headingText.replace(/^"|"$/g, '').slice(0, 60),
|
|
1144
|
-
kickerText: kickerText.slice(0, 40),
|
|
1145
2564
|
});
|
|
1146
2565
|
}
|
|
1147
2566
|
return candidates;
|
|
1148
2567
|
}
|
|
1149
2568
|
|
|
1150
|
-
function
|
|
1151
|
-
const candidates =
|
|
2569
|
+
function checkNumberedSectionLabels(opts) {
|
|
2570
|
+
const { candidates, minCount = 2 } = opts;
|
|
2571
|
+
if (!Array.isArray(candidates) || candidates.length < minCount) return [];
|
|
2572
|
+
// A repeated identical number is some other device; the scaffold counts up.
|
|
2573
|
+
const distinctIndices = new Set(candidates.map(c => c.index));
|
|
2574
|
+
if (distinctIndices.size < 2) return [];
|
|
2575
|
+
return candidates.map(candidate => ({
|
|
2576
|
+
id: 'numbered-section-labels',
|
|
2577
|
+
snippet: `tiny numbered label "${candidate.labelText}" beside ${candidate.headingTag} "${candidate.headingText}" (${candidates.length} on page)`,
|
|
2578
|
+
}));
|
|
2579
|
+
}
|
|
2580
|
+
|
|
2581
|
+
function checkNumberedSectionLabelsFromDoc(doc, win) {
|
|
2582
|
+
const candidates = collectNumberedSectionLabelCandidates(
|
|
2583
|
+
doc,
|
|
2584
|
+
(el) => win.getComputedStyle(el),
|
|
2585
|
+
(value, fontSize) => resolveLengthPx(value, fontSize) || 0,
|
|
2586
|
+
);
|
|
2587
|
+
return checkNumberedSectionLabels({ candidates });
|
|
2588
|
+
}
|
|
2589
|
+
|
|
2590
|
+
function checkNumberedSectionLabelsDOM() {
|
|
2591
|
+
const candidates = collectNumberedSectionLabelCandidates(
|
|
1152
2592
|
document,
|
|
1153
2593
|
(el) => getComputedStyle(el),
|
|
1154
2594
|
(value, fontSize) => resolveLengthPx(value, fontSize) || 0,
|
|
1155
2595
|
);
|
|
1156
|
-
return
|
|
2596
|
+
return checkNumberedSectionLabels({ candidates });
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
// Em-dash overuse (ADVISORY) — pure logic shared by the browser DOM check.
|
|
2600
|
+
// Mirrors the regex/static-HTML analyzer in engines/regex/detect-text.mjs:
|
|
2601
|
+
// two gates (absolute floor + density) so a long article using a few dashes is
|
|
2602
|
+
// left alone while a short, dash-per-clause page is flagged. Operates on
|
|
2603
|
+
// already-rendered text, so no HTML-entity decoding is needed (the browser has
|
|
2604
|
+
// resolved `—` to the literal glyph). Exported for jsdom unit tests.
|
|
2605
|
+
function checkEmDashOveruse(text) {
|
|
2606
|
+
const body = typeof text === 'string' ? text.replace(/\s+/g, ' ') : '';
|
|
2607
|
+
let count = 0;
|
|
2608
|
+
const re = /[—]|--(?=\S)/g;
|
|
2609
|
+
while (re.exec(body) !== null) count++;
|
|
2610
|
+
if (count < EM_DASH_FLOOR) return [];
|
|
2611
|
+
if (body.length > count * EM_DASH_CHARS_PER_DASH) return [];
|
|
2612
|
+
return [{ id: 'em-dash-overuse', snippet: `${count} em-dashes in body text` }];
|
|
2613
|
+
}
|
|
2614
|
+
|
|
2615
|
+
function checkEmDashOveruseDOM() {
|
|
2616
|
+
const body = document.body;
|
|
2617
|
+
if (!body) return [];
|
|
2618
|
+
// innerText reflects rendered, visible text; fall back to textContent for
|
|
2619
|
+
// engines (jsdom) that don't compute innerText.
|
|
2620
|
+
const text = typeof body.innerText === 'string' && body.innerText
|
|
2621
|
+
? body.innerText
|
|
2622
|
+
: (body.textContent || '');
|
|
2623
|
+
return checkEmDashOveruse(text);
|
|
1157
2624
|
}
|
|
1158
2625
|
|
|
1159
2626
|
function checkElementMotionDOM(el) {
|
|
@@ -1172,7 +2639,14 @@ function checkElementMotionDOM(el) {
|
|
|
1172
2639
|
function checkElementGlowDOM(el) {
|
|
1173
2640
|
const tag = el.tagName.toLowerCase();
|
|
1174
2641
|
const style = getComputedStyle(el);
|
|
1175
|
-
|
|
2642
|
+
const boxShadow = style.boxShadow && style.boxShadow !== 'none' ? style.boxShadow : '';
|
|
2643
|
+
// text-shadow inherits: only check the element that introduces it, so one
|
|
2644
|
+
// declaration doesn't produce a finding on every descendant.
|
|
2645
|
+
let textShadow = style.textShadow && style.textShadow !== 'none' ? style.textShadow : '';
|
|
2646
|
+
if (textShadow && el.parentElement && getComputedStyle(el.parentElement).textShadow === textShadow) {
|
|
2647
|
+
textShadow = '';
|
|
2648
|
+
}
|
|
2649
|
+
if (!boxShadow && !textShadow) return [];
|
|
1176
2650
|
// Use parent's background — glow radiates outward, so the surrounding context matters
|
|
1177
2651
|
// If resolveBackground returns null (gradient), try to infer from the gradient colors
|
|
1178
2652
|
let parentBg = el.parentElement ? resolveBackground(el.parentElement) : resolveBackground(el);
|
|
@@ -1195,7 +2669,7 @@ function checkElementGlowDOM(el) {
|
|
|
1195
2669
|
cur = cur.parentElement;
|
|
1196
2670
|
}
|
|
1197
2671
|
}
|
|
1198
|
-
return checkGlow({ tag, boxShadow
|
|
2672
|
+
return checkGlow({ tag, boxShadow, textShadow, effectiveBg: parentBg });
|
|
1199
2673
|
}
|
|
1200
2674
|
|
|
1201
2675
|
function checkElementAIPaletteDOM(el) {
|
|
@@ -1376,6 +2850,27 @@ function textDescendantsFlushSides(el, rect) {
|
|
|
1376
2850
|
return flush;
|
|
1377
2851
|
}
|
|
1378
2852
|
|
|
2853
|
+
// Screen-reader-only ("visually hidden") text is exempt from the tiny-text
|
|
2854
|
+
// floors: it is never rendered, so its size is irrelevant. Detect the two
|
|
2855
|
+
// standard idioms — a known sr-only class on the element or an ancestor, and
|
|
2856
|
+
// the clip / 1px-box pattern. Works in both jsdom (declared styles) and the
|
|
2857
|
+
// browser (computed styles).
|
|
2858
|
+
const SR_ONLY_SELECTOR = '.sr-only, .visually-hidden, .visuallyhidden, .screen-reader, .screen-reader-only, .screenreader, .a11y-hidden, .hidden-visually, [class*="sr-only" i], [class*="visually-hidden" i], [class*="visuallyhidden" i], [class*="screen-reader" i], [class*="screenreader" i]';
|
|
2859
|
+
function isVisuallyHidden(el, style) {
|
|
2860
|
+
if ((el.matches && el.matches(SR_ONLY_SELECTOR)) || (el.closest && el.closest(SR_ONLY_SELECTOR))) return true;
|
|
2861
|
+
const pos = style.position || '';
|
|
2862
|
+
if (pos === 'absolute' || pos === 'fixed') {
|
|
2863
|
+
const clip = style.clip || '';
|
|
2864
|
+
const clipPath = style.clipPath || style.webkitClipPath || style['clip-path'] || '';
|
|
2865
|
+
if (/rect\(\s*0/.test(clip) || /inset\(\s*(?:50%|99|100%)/.test(clipPath)) return true;
|
|
2866
|
+
const w = parseFloat(style.width);
|
|
2867
|
+
const h = parseFloat(style.height);
|
|
2868
|
+
const overflow = style.overflow || '';
|
|
2869
|
+
if ((w === 1 || h === 1) && (overflow === 'hidden' || overflow === 'clip')) return true;
|
|
2870
|
+
}
|
|
2871
|
+
return false;
|
|
2872
|
+
}
|
|
2873
|
+
|
|
1379
2874
|
// Pure quality checks. Most run on computed CSS and DOM-only inputs (work in
|
|
1380
2875
|
// jsdom and the browser). Two checks (line-length, cramped-padding) gate on
|
|
1381
2876
|
// element rect dimensions, which jsdom can't compute — pass `rect: null` from
|
|
@@ -1660,6 +3155,60 @@ function checkQuality(opts) {
|
|
|
1660
3155
|
}
|
|
1661
3156
|
}
|
|
1662
3157
|
|
|
3158
|
+
// --- Undersized functional / UI text ---
|
|
3159
|
+
// Complements `tiny-text` above, which owns long body copy and deliberately
|
|
3160
|
+
// EXEMPTS the UI furniture layer (nav, footer, links, buttons, labels,
|
|
3161
|
+
// uppercase micro-labels). This rule targets exactly that blind spot: the
|
|
3162
|
+
// interactive and short content-bearing text — nav items, buttons, labels,
|
|
3163
|
+
// table cells, meta rows, timecodes — shipped below an 11px floor.
|
|
3164
|
+
//
|
|
3165
|
+
// The live failure it closes: a build shipped its entire furniture layer at
|
|
3166
|
+
// 8px, and the design hook waved it through because 8px had been added to
|
|
3167
|
+
// the DESIGN.md size ramp. Being on the ramp is a token argument, not a
|
|
3168
|
+
// legibility one, so this rule ignores the design system entirely — a value
|
|
3169
|
+
// on the ramp is still flagged.
|
|
3170
|
+
//
|
|
3171
|
+
// Floors: 11px for anything functional. The floor holds inside a footer;
|
|
3172
|
+
// only NON-interactive legal smallprint gets the softer 10px floor. Exempts
|
|
3173
|
+
// sup/sub, visually-hidden (sr-only) text, and code/terminal contexts.
|
|
3174
|
+
// Uppercase letterspaced micro-labels are still functional — not exempt.
|
|
3175
|
+
{
|
|
3176
|
+
const directText = [...el.childNodes]
|
|
3177
|
+
.filter(n => n.nodeType === 3)
|
|
3178
|
+
.map(n => n.textContent || '')
|
|
3179
|
+
.join('')
|
|
3180
|
+
.replace(/\s+/g, ' ')
|
|
3181
|
+
.trim();
|
|
3182
|
+
const dtLen = directText.length;
|
|
3183
|
+
const UI_SKIP_TAGS = new Set(['sub', 'sup', 'script', 'style', 'title', 'option']);
|
|
3184
|
+
const notRendered = style.display === 'none' || style.visibility === 'hidden' || style.visibility === 'collapse';
|
|
3185
|
+
// jsdom resolves the parent chain in resolveFontSizePx, so em/rem/%-sized
|
|
3186
|
+
// text that computes at or above the floor never reaches here. The browser
|
|
3187
|
+
// adapter additionally catches values only resolvable with real layout
|
|
3188
|
+
// (e.g. viewport-relative units, cascade winners set in linked sheets).
|
|
3189
|
+
if (fontSize > 0 && fontSize < 11 && dtLen >= 2 && !UI_SKIP_TAGS.has(tag) && !notRendered) {
|
|
3190
|
+
const EXEMPT_CONTEXT = 'pre, code, kbd, samp, var, svg, [aria-hidden="true"], [class*="terminal" i], [class*="console" i], [class*="code" i], [class*="mock" i], [class*="editor" i], [class*="syntax" i], [class*="diff" i]';
|
|
3191
|
+
const isExemptContext = (el.matches && el.matches(EXEMPT_CONTEXT)) || (el.closest && el.closest(EXEMPT_CONTEXT));
|
|
3192
|
+
if (!isExemptContext && !isVisuallyHidden(el, style)) {
|
|
3193
|
+
const INTERACTIVE = 'a[href], button, summary, label, select, textarea, [role="button"], [role="link"], [role="tab"], [role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"], [role="option"], [role="checkbox"], [role="radio"], [role="switch"], [role="treeitem"], [tabindex]';
|
|
3194
|
+
const FURNITURE = 'nav, [role="navigation"], td, th, [role="gridcell"], [role="cell"], caption, figcaption, dt, dd, footer, [class*="meta" i], [class*="label" i], [class*="badge" i], [class*="chip" i], [class*="pill" i], [class*="tag" i], [class*="kicker" i], [class*="eyebrow" i], [class*="breadcrumb" i], [class*="timestamp" i], [class*="category" i], [class*="caption" i], [class*="nav" i]';
|
|
3195
|
+
const SMALLPRINT = 'small, footer, [class*="legal" i], [class*="copyright" i], [class*="fineprint" i], [class*="fine-print" i], [class*="smallprint" i], [class*="small-print" i], [class*="disclaimer" i], [class*="disclosure" i], [class*="footnote" i]';
|
|
3196
|
+
const isInteractive = (el.matches && el.matches(INTERACTIVE)) || (el.closest && el.closest(INTERACTIVE));
|
|
3197
|
+
const isFurniture = (el.matches && el.matches(FURNITURE)) || (el.closest && el.closest(FURNITURE));
|
|
3198
|
+
const isSmallprint = (el.matches && el.matches(SMALLPRINT)) || (el.closest && el.closest(SMALLPRINT));
|
|
3199
|
+
const floor = (!isInteractive && isSmallprint) ? 10 : 11;
|
|
3200
|
+
// Fire on functional text only: interactive, structural furniture, or
|
|
3201
|
+
// any short (<=20-char) run — the label / meta / timecode shape. Long
|
|
3202
|
+
// non-furniture body copy stays with `tiny-text`, so the two rules
|
|
3203
|
+
// never double-flag the same element.
|
|
3204
|
+
if (fontSize < floor && (isInteractive || isFurniture || dtLen <= 20)) {
|
|
3205
|
+
const excerpt = directText.slice(0, 40);
|
|
3206
|
+
findings.push({ id: 'undersized-ui-text', snippet: `${fontSize}px functional text "${excerpt}" (below ${floor}px floor)` });
|
|
3207
|
+
}
|
|
3208
|
+
}
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
|
|
1663
3212
|
// --- All-caps body text ---
|
|
1664
3213
|
if (hasDirectText && textLen > 30 && style.textTransform === 'uppercase') {
|
|
1665
3214
|
if (!['h1','h2','h3','h4','h5','h6'].includes(tag)) {
|
|
@@ -1752,7 +3301,7 @@ function checkElementQuality(el, style, tag, window) {
|
|
|
1752
3301
|
return checkQuality({ el, tag, style, hasDirectText, textLen, fontSize, lineHeightPx, letterSpacingPx, rect: null, win: window });
|
|
1753
3302
|
}
|
|
1754
3303
|
|
|
1755
|
-
function checkElementBorders(tag, style, overrides, resolvedRadius) {
|
|
3304
|
+
function checkElementBorders(tag, style, overrides, resolvedRadius, el = null) {
|
|
1756
3305
|
const sides = ['Top', 'Right', 'Bottom', 'Left'];
|
|
1757
3306
|
const widths = {}, colors = {};
|
|
1758
3307
|
for (const s of sides) {
|
|
@@ -1779,7 +3328,12 @@ function checkElementBorders(tag, style, overrides, resolvedRadius) {
|
|
|
1779
3328
|
const radius = resolvedRadius != null
|
|
1780
3329
|
? resolvedRadius
|
|
1781
3330
|
: (parseFloat(style.borderRadius) || 0);
|
|
1782
|
-
|
|
3331
|
+
const ownBg = parseAnyColor(style.backgroundColor);
|
|
3332
|
+
return checkBorders(tag, widths, colors, radius, {
|
|
3333
|
+
tabContext: isTabContextElement(el),
|
|
3334
|
+
statusContext: isStatusContextElement(el),
|
|
3335
|
+
badgeLike: !!(ownBg && (ownBg.a ?? 1) > 0.1),
|
|
3336
|
+
});
|
|
1783
3337
|
}
|
|
1784
3338
|
|
|
1785
3339
|
function checkElementColors(el, style, tag, window, customPropMap, hasAnchorInheritRule) {
|
|
@@ -1820,12 +3374,32 @@ function checkElementColors(el, style, tag, window, customPropMap, hasAnchorInhe
|
|
|
1820
3374
|
}
|
|
1821
3375
|
}
|
|
1822
3376
|
|
|
3377
|
+
// Own background: resolve var()/oklch() tokens through the custom-property
|
|
3378
|
+
// map first (mirrors the textColor path above). Without this a chip whose
|
|
3379
|
+
// background is `var(--sev)` reads as no-own-bg in the static engine and
|
|
3380
|
+
// the styled-control contrast exception never engages.
|
|
3381
|
+
let ownBg = (customPropMap ? parseColorResolved(style.backgroundColor, customPropMap) : null)
|
|
3382
|
+
|| readOwnBackgroundColor(el, style);
|
|
3383
|
+
|
|
3384
|
+
// Full-cover surface pseudo (static): the cascade pass marks elements
|
|
3385
|
+
// whose ::before/::after paints an opaque covering surface. When the
|
|
3386
|
+
// element itself has no usable own background, that pseudo is the real
|
|
3387
|
+
// surface for contrast purposes.
|
|
3388
|
+
let finalEffectiveBg = effectiveBg;
|
|
3389
|
+
if ((!ownBg || (ownBg.a ?? 1) <= 0.5) && typeof window.getPseudoSurface === 'function') {
|
|
3390
|
+
const pseudoSurface = window.getPseudoSurface(el);
|
|
3391
|
+
if (pseudoSurface) {
|
|
3392
|
+
ownBg = pseudoSurface;
|
|
3393
|
+
finalEffectiveBg = pseudoSurface;
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
|
|
1823
3397
|
return checkColors({
|
|
1824
3398
|
tag,
|
|
1825
3399
|
textColor,
|
|
1826
|
-
bgColor:
|
|
1827
|
-
effectiveBg,
|
|
1828
|
-
effectiveBgStops:
|
|
3400
|
+
bgColor: ownBg,
|
|
3401
|
+
effectiveBg: finalEffectiveBg,
|
|
3402
|
+
effectiveBgStops: finalEffectiveBg ? null : resolveGradientStops(el, window),
|
|
1829
3403
|
fontSize: parseFloat(style.fontSize) || 16,
|
|
1830
3404
|
fontWeight: parseInt(style.fontWeight) || 400,
|
|
1831
3405
|
hasDirectText,
|
|
@@ -1836,6 +3410,50 @@ function checkElementColors(el, style, tag, window, customPropMap, hasAnchorInhe
|
|
|
1836
3410
|
});
|
|
1837
3411
|
}
|
|
1838
3412
|
|
|
3413
|
+
// Static-engine adapter for hover-state contrast. Relies on the static
|
|
3414
|
+
// cascade's hover pass (css-cascade.mjs) exposing a per-element hover style
|
|
3415
|
+
// via window.getHoverStyle — present only when a :hover rule changed the
|
|
3416
|
+
// element's color or background-color relative to its resting state.
|
|
3417
|
+
function checkElementHoverContrast(el, style, tag, window) {
|
|
3418
|
+
if (typeof window.getHoverStyle !== 'function') return [];
|
|
3419
|
+
const hover = window.getHoverStyle(el);
|
|
3420
|
+
if (!hover) return [];
|
|
3421
|
+
|
|
3422
|
+
const directText = [...el.childNodes].filter(n => n.nodeType === 3).map(n => n.textContent).join('');
|
|
3423
|
+
if (directText.trim().length === 0) return [];
|
|
3424
|
+
|
|
3425
|
+
const textColor = parseAnyColor(hover.color);
|
|
3426
|
+
if (!textColor || (textColor.a != null && textColor.a < 1)) return [];
|
|
3427
|
+
|
|
3428
|
+
const restingOwnBg = parseAnyColor(style.backgroundColor);
|
|
3429
|
+
const hoverOwnBg = parseAnyColor(hover.backgroundColor);
|
|
3430
|
+
const ownBg = hoverOwnBg || restingOwnBg;
|
|
3431
|
+
|
|
3432
|
+
// Effective hover background: the element's own hover bg composited over
|
|
3433
|
+
// whatever sits underneath. Bail when the surface can't be resolved to a
|
|
3434
|
+
// solid color — gradient ancestors are handled (as at rest) by the
|
|
3435
|
+
// resting-state check, not duplicated here.
|
|
3436
|
+
let bg = null;
|
|
3437
|
+
if (ownBg && ownBg.a >= 0.99) {
|
|
3438
|
+
bg = ownBg;
|
|
3439
|
+
} else {
|
|
3440
|
+
const under = resolveBackground(el.parentElement || el, window, null);
|
|
3441
|
+
if (!under) return [];
|
|
3442
|
+
bg = ownBg && ownBg.a > 0.1 ? compositeColorOver(ownBg, under) : under;
|
|
3443
|
+
}
|
|
3444
|
+
|
|
3445
|
+
return checkHoverContrast({
|
|
3446
|
+
tag,
|
|
3447
|
+
textColor,
|
|
3448
|
+
bg,
|
|
3449
|
+
ownBgAlpha: ownBg ? ownBg.a ?? 1 : null,
|
|
3450
|
+
fontSize: parseFloat(style.fontSize) || 16,
|
|
3451
|
+
fontWeight: parseInt(style.fontWeight) || 400,
|
|
3452
|
+
hasDirectText: true,
|
|
3453
|
+
isEmojiOnly: isEmojiOnlyText(directText),
|
|
3454
|
+
});
|
|
3455
|
+
}
|
|
3456
|
+
|
|
1839
3457
|
function checkElementIconTile(el, tag, window) {
|
|
1840
3458
|
if (!HEADING_TAGS.has(tag)) return [];
|
|
1841
3459
|
const sibling = el.previousElementSibling;
|
|
@@ -1904,7 +3522,8 @@ function checkElementHeroEyebrow(el, style, tag, window, customPropMap) {
|
|
|
1904
3522
|
return checkHeroEyebrow({
|
|
1905
3523
|
headingTag: tag,
|
|
1906
3524
|
headingText: el.textContent || '',
|
|
1907
|
-
headingFontSize:
|
|
3525
|
+
headingFontSize: resolveHeroHeadingSizePx(headingFontSizeRaw),
|
|
3526
|
+
headingInApplicationContext: !!el.closest?.('[role="tabpanel"], [role="dialog"], [role="application"], dialog'),
|
|
1908
3527
|
siblingTag: sibling.tagName.toLowerCase(),
|
|
1909
3528
|
siblingText: sibling.textContent || '',
|
|
1910
3529
|
siblingTextTransform: sibStyle.textTransform || '',
|
|
@@ -1912,6 +3531,11 @@ function checkElementHeroEyebrow(el, style, tag, window, customPropMap) {
|
|
|
1912
3531
|
siblingLetterSpacing: resolveLengthPx(letterSpacingRaw, siblingFontSize) || 0,
|
|
1913
3532
|
siblingFontWeight: fontWeightRaw || '',
|
|
1914
3533
|
siblingColor: colorRaw || '',
|
|
3534
|
+
// Static cascade marks elements matched by a ::before/::after rule
|
|
3535
|
+
// whose geometry is a short chromatic dash (css-cascade.mjs).
|
|
3536
|
+
siblingHasAccentDashPseudo: typeof window.hasAccentDashPseudo === 'function'
|
|
3537
|
+
? window.hasAccentDashPseudo(sibling)
|
|
3538
|
+
: false,
|
|
1915
3539
|
});
|
|
1916
3540
|
}
|
|
1917
3541
|
|
|
@@ -1935,8 +3559,10 @@ function checkElementMotion(tag, style) {
|
|
|
1935
3559
|
}
|
|
1936
3560
|
|
|
1937
3561
|
function checkElementGlow(tag, style, effectiveBg) {
|
|
1938
|
-
|
|
1939
|
-
|
|
3562
|
+
const boxShadow = style.boxShadow && style.boxShadow !== 'none' ? style.boxShadow : '';
|
|
3563
|
+
const textShadow = style.textShadow && style.textShadow !== 'none' ? style.textShadow : '';
|
|
3564
|
+
if (!boxShadow && !textShadow) return [];
|
|
3565
|
+
return checkGlow({ tag, boxShadow, textShadow, effectiveBg });
|
|
1940
3566
|
}
|
|
1941
3567
|
|
|
1942
3568
|
// ─── Section 6: Page-Level Checks ───────────────────────────────────────────
|
|
@@ -2046,6 +3672,157 @@ function checkLayout() {
|
|
|
2046
3672
|
return findings;
|
|
2047
3673
|
}
|
|
2048
3674
|
|
|
3675
|
+
// Heading rhythm (browser-only): a heading binds to the content it
|
|
3676
|
+
// introduces, so its rendered space above must exceed its space below.
|
|
3677
|
+
// Margins alone can't be trusted (collapsing, flex rows, section padding),
|
|
3678
|
+
// so this measures actual getBoundingClientRect gaps between the heading
|
|
3679
|
+
// and the nearest content genuinely above / below it. Fires only when two
|
|
3680
|
+
// or more headings violate the principle — a single occurrence is noise.
|
|
3681
|
+
function checkHeadingRhythmDOM() {
|
|
3682
|
+
const MIN_VIOLATIONS = 2;
|
|
3683
|
+
const CARD_EXEMPT_HEIGHT = 200;
|
|
3684
|
+
const MAX_BELOW_PX = 160; // beyond this the heading isn't binding to nearby content at all
|
|
3685
|
+
const MIN_DEFICIT_PX = 12;
|
|
3686
|
+
|
|
3687
|
+
function isVisibleFlow(el) {
|
|
3688
|
+
const style = getComputedStyle(el);
|
|
3689
|
+
if (style.display === 'none' || style.visibility === 'hidden') return false;
|
|
3690
|
+
if (parseFloat(style.opacity || '1') <= 0.05) return false;
|
|
3691
|
+
if (style.position === 'absolute' || style.position === 'fixed' || style.position === 'sticky') return false;
|
|
3692
|
+
const rect = el.getBoundingClientRect();
|
|
3693
|
+
return rect.width >= 1 && rect.height >= 1;
|
|
3694
|
+
}
|
|
3695
|
+
|
|
3696
|
+
// Edges only count when they share the heading's column — grid layouts
|
|
3697
|
+
// put content beside a heading, and a far-away element in another column
|
|
3698
|
+
// says nothing about the heading's vertical rhythm.
|
|
3699
|
+
function overlapsX(sr, rect) {
|
|
3700
|
+
return Math.min(sr.right, rect.right) - Math.max(sr.left, rect.left) >= 8;
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
// Does this container draw its own top boundary (background, top border,
|
|
3704
|
+
// shadow)? Crossing out of such a container means the container edge is
|
|
3705
|
+
// the separator above the heading, not raw whitespace — exempt.
|
|
3706
|
+
function hasOwnTopBoundary(el) {
|
|
3707
|
+
const style = getComputedStyle(el);
|
|
3708
|
+
const bg = parseAnyColor(style.backgroundColor || '');
|
|
3709
|
+
if (bg && (bg.a ?? 1) > 0.05) return true;
|
|
3710
|
+
if ((parseFloat(style.borderTopWidth) || 0) > 0) return true;
|
|
3711
|
+
if (style.boxShadow && style.boxShadow !== 'none') return true;
|
|
3712
|
+
return false;
|
|
3713
|
+
}
|
|
3714
|
+
|
|
3715
|
+
// Eyebrows, kickers, and index labels sitting directly on top of a
|
|
3716
|
+
// heading belong to the heading's own cluster — space above is measured
|
|
3717
|
+
// from the top of the cluster, not from the label to the heading.
|
|
3718
|
+
function clusterTop(h, rect) {
|
|
3719
|
+
const headingFontSize = parseFloat(getComputedStyle(h).fontSize) || 16;
|
|
3720
|
+
let topEl = h;
|
|
3721
|
+
let top = rect.top;
|
|
3722
|
+
for (let i = 0; i < 3; i++) {
|
|
3723
|
+
const sib = topEl.previousElementSibling;
|
|
3724
|
+
if (!sib || !isVisibleFlow(sib)) break;
|
|
3725
|
+
const sr = sib.getBoundingClientRect();
|
|
3726
|
+
if (!overlapsX(sr, rect)) break;
|
|
3727
|
+
const gap = top - sr.bottom;
|
|
3728
|
+
if (gap < 0 || gap >= 28 || sr.height > 60) break;
|
|
3729
|
+
const text = (sib.textContent || '').trim();
|
|
3730
|
+
const sibFontSize = parseFloat(getComputedStyle(sib).fontSize) || 16;
|
|
3731
|
+
const labelLike = sibFontSize < headingFontSize * 0.75 || text.length <= 40;
|
|
3732
|
+
if (!labelLike || text.length > 80) break;
|
|
3733
|
+
topEl = sib;
|
|
3734
|
+
top = sr.top;
|
|
3735
|
+
}
|
|
3736
|
+
return { topEl, top };
|
|
3737
|
+
}
|
|
3738
|
+
|
|
3739
|
+
// Nearest content edge strictly above the heading cluster. Walks
|
|
3740
|
+
// previous siblings, then out through ancestors. Skips elements that
|
|
3741
|
+
// vertically overlap (flex-row companions, sticky rails) or sit in
|
|
3742
|
+
// another column. Returns null when nothing qualifies — first content
|
|
3743
|
+
// on the page, or the top of a visually bounded container.
|
|
3744
|
+
function edgeAbove(startEl, top, rect) {
|
|
3745
|
+
let node = startEl;
|
|
3746
|
+
while (node && node !== document.body) {
|
|
3747
|
+
let sib = node.previousElementSibling;
|
|
3748
|
+
while (sib) {
|
|
3749
|
+
if (isVisibleFlow(sib)) {
|
|
3750
|
+
const sr = sib.getBoundingClientRect();
|
|
3751
|
+
if (sr.bottom <= top + 2 && overlapsX(sr, rect)) return sr.bottom;
|
|
3752
|
+
}
|
|
3753
|
+
sib = sib.previousElementSibling;
|
|
3754
|
+
}
|
|
3755
|
+
const parent = node.parentElement;
|
|
3756
|
+
if (!parent || parent === document.body) return null;
|
|
3757
|
+
// Leaving a container upward: if it draws its own top edge, that
|
|
3758
|
+
// edge separates the heading from whatever sits above.
|
|
3759
|
+
if (hasOwnTopBoundary(parent)) return null;
|
|
3760
|
+
node = parent;
|
|
3761
|
+
}
|
|
3762
|
+
return null;
|
|
3763
|
+
}
|
|
3764
|
+
|
|
3765
|
+
// Nearest content edge strictly below the heading — the block the
|
|
3766
|
+
// heading introduces. Crosses wrappers freely (headings often share a
|
|
3767
|
+
// row wrapper with an eyebrow or index label).
|
|
3768
|
+
function edgeBelow(h, rect) {
|
|
3769
|
+
let node = h;
|
|
3770
|
+
while (node && node !== document.body) {
|
|
3771
|
+
let sib = node.nextElementSibling;
|
|
3772
|
+
while (sib) {
|
|
3773
|
+
if (isVisibleFlow(sib)) {
|
|
3774
|
+
const sr = sib.getBoundingClientRect();
|
|
3775
|
+
if (sr.top >= rect.bottom - 2 && overlapsX(sr, rect)) return sr.top;
|
|
3776
|
+
}
|
|
3777
|
+
sib = sib.nextElementSibling;
|
|
3778
|
+
}
|
|
3779
|
+
node = node.parentElement;
|
|
3780
|
+
}
|
|
3781
|
+
return null;
|
|
3782
|
+
}
|
|
3783
|
+
|
|
3784
|
+
function insideSmallCard(h) {
|
|
3785
|
+
let cur = h.parentElement;
|
|
3786
|
+
while (cur && cur !== document.body) {
|
|
3787
|
+
if (isCardLikeDOM(cur)) {
|
|
3788
|
+
const cr = cur.getBoundingClientRect();
|
|
3789
|
+
if (cr.height < CARD_EXEMPT_HEIGHT) return true;
|
|
3790
|
+
}
|
|
3791
|
+
cur = cur.parentElement;
|
|
3792
|
+
}
|
|
3793
|
+
return false;
|
|
3794
|
+
}
|
|
3795
|
+
|
|
3796
|
+
const candidates = [];
|
|
3797
|
+
for (const h of document.querySelectorAll('h2, h3, h4')) {
|
|
3798
|
+
if (!isVisibleFlow(h)) continue;
|
|
3799
|
+
const text = (h.textContent || '').trim().replace(/\s+/g, ' ');
|
|
3800
|
+
if (text.length < 3) continue;
|
|
3801
|
+
const rect = h.getBoundingClientRect();
|
|
3802
|
+
const belowTop = edgeBelow(h, rect);
|
|
3803
|
+
if (belowTop == null) continue; // heading introduces nothing measurable
|
|
3804
|
+
const { topEl, top } = clusterTop(h, rect);
|
|
3805
|
+
const aboveBottom = edgeAbove(topEl, top, rect);
|
|
3806
|
+
if (aboveBottom == null) continue; // first content, or bounded container
|
|
3807
|
+
if (insideSmallCard(h)) continue;
|
|
3808
|
+
const above = Math.max(0, top - aboveBottom);
|
|
3809
|
+
const below = Math.max(0, belowTop - rect.bottom);
|
|
3810
|
+
if (below < 6 || below > MAX_BELOW_PX) continue;
|
|
3811
|
+
// Violation: the space above clearly fails to exceed the space below.
|
|
3812
|
+
// Near-equal gaps are ambiguous rather than inverted, so they pass.
|
|
3813
|
+
if (above < below * 0.75 && below - above >= MIN_DEFICIT_PX) {
|
|
3814
|
+
candidates.push({ el: h, tag: h.tagName.toLowerCase(), text: text.slice(0, 60), above, below });
|
|
3815
|
+
}
|
|
3816
|
+
}
|
|
3817
|
+
|
|
3818
|
+
if (candidates.length < MIN_VIOLATIONS) return [];
|
|
3819
|
+
return candidates.map(c => ({
|
|
3820
|
+
type: 'heading-rhythm',
|
|
3821
|
+
detail: `${c.tag} "${c.text}" has ${Math.round(c.above)}px above vs ${Math.round(c.below)}px below — it reads as bound to the block above (${candidates.length} headings on page)`,
|
|
3822
|
+
el: c.el,
|
|
3823
|
+
}));
|
|
3824
|
+
}
|
|
3825
|
+
|
|
2049
3826
|
// Node page-level checks — take document/window as parameters
|
|
2050
3827
|
|
|
2051
3828
|
function checkPageTypography(doc, win) {
|
|
@@ -2188,6 +3965,135 @@ function checkPageLayout(doc, win) {
|
|
|
2188
3965
|
return findings;
|
|
2189
3966
|
}
|
|
2190
3967
|
|
|
3968
|
+
// ── Repeated text inside one container ──────────────────────────────────────
|
|
3969
|
+
// The same literal string rendered 3+ times in structurally different spots
|
|
3970
|
+
// inside one bordered/elevated container — typically a status word wired
|
|
3971
|
+
// into every slot of a card template. Legitimate repetition is structural:
|
|
3972
|
+
// table columns, calendar grids, nav/menu lists, and templated sibling rows
|
|
3973
|
+
// all repeat text in *parallel* positions, so occurrences whose element
|
|
3974
|
+
// paths inside the container are identical (or live in dedicated repetition
|
|
3975
|
+
// structures) never count. Only 3+ occurrences at 3+ distinct structural
|
|
3976
|
+
// positions flag.
|
|
3977
|
+
|
|
3978
|
+
const REPEATED_TEXT_SKIP_SELECTOR = [
|
|
3979
|
+
'table',
|
|
3980
|
+
'select',
|
|
3981
|
+
'datalist',
|
|
3982
|
+
'nav',
|
|
3983
|
+
'menu',
|
|
3984
|
+
'[role="navigation"]',
|
|
3985
|
+
'[role="menu"]',
|
|
3986
|
+
'[role="menubar"]',
|
|
3987
|
+
'[role="listbox"]',
|
|
3988
|
+
'[role="grid"]',
|
|
3989
|
+
'[role="tablist"]',
|
|
3990
|
+
'[role="radiogroup"]',
|
|
3991
|
+
'[aria-hidden="true"]',
|
|
3992
|
+
].join(',');
|
|
3993
|
+
|
|
3994
|
+
const REPEATED_TEXT_CONTAINER_TAGS = new Set([
|
|
3995
|
+
'div', 'section', 'article', 'aside', 'main', 'figure', 'form', 'fieldset', 'details', 'li',
|
|
3996
|
+
]);
|
|
3997
|
+
|
|
3998
|
+
// A container worth attributing text to: visibly bounded (border on most
|
|
3999
|
+
// sides or an elevation shadow) and surface-like (radius or own background).
|
|
4000
|
+
function isRepeatedTextContainer(style) {
|
|
4001
|
+
if (!style) return false;
|
|
4002
|
+
const hasShadow = !!(style.boxShadow && style.boxShadow !== 'none' && style.boxShadow !== '');
|
|
4003
|
+
const borderSides = ['Top', 'Right', 'Bottom', 'Left']
|
|
4004
|
+
.filter(side => (parseFloat(style[`border${side}Width`]) || 0) >= 1).length;
|
|
4005
|
+
const hasBorder = borderSides >= 3;
|
|
4006
|
+
const hasRadius = (parseFloat(style.borderRadius) || 0) > 0;
|
|
4007
|
+
const bg = parseRgb(style.backgroundColor) || parseAnyColor(style.backgroundColor);
|
|
4008
|
+
const hasBg = !!(bg && (bg.a ?? 1) > 0.1);
|
|
4009
|
+
return isCardLikeFromProps(hasShadow, hasBorder, hasRadius, hasBg);
|
|
4010
|
+
}
|
|
4011
|
+
|
|
4012
|
+
function collectRepeatedContainerTextFindings(doc, getStyle, opts = {}) {
|
|
4013
|
+
const isVisible = opts.isVisible || (() => true);
|
|
4014
|
+
const findings = [];
|
|
4015
|
+
|
|
4016
|
+
const containers = [];
|
|
4017
|
+
const containerSet = new Set();
|
|
4018
|
+
for (const el of doc.querySelectorAll('*')) {
|
|
4019
|
+
if (!REPEATED_TEXT_CONTAINER_TAGS.has(el.tagName.toLowerCase())) continue;
|
|
4020
|
+
if (el.closest?.(REPEATED_TEXT_SKIP_SELECTOR)) continue;
|
|
4021
|
+
if (!isRepeatedTextContainer(getStyle(el))) continue;
|
|
4022
|
+
containers.push(el);
|
|
4023
|
+
containerSet.add(el);
|
|
4024
|
+
}
|
|
4025
|
+
|
|
4026
|
+
for (const container of containers) {
|
|
4027
|
+
if (!isVisible(container)) continue;
|
|
4028
|
+
const descendants = container.querySelectorAll('*');
|
|
4029
|
+
// Page-scale wrappers that merely happen to carry a background are not
|
|
4030
|
+
// the "one card" this rule reasons about.
|
|
4031
|
+
if (descendants.length > 250) continue;
|
|
4032
|
+
|
|
4033
|
+
const groups = new Map();
|
|
4034
|
+
for (const d of descendants) {
|
|
4035
|
+
// Attribute text to the innermost container only.
|
|
4036
|
+
let anc = d.parentElement;
|
|
4037
|
+
let ownedByInner = false;
|
|
4038
|
+
while (anc && anc !== container) {
|
|
4039
|
+
if (containerSet.has(anc)) { ownedByInner = true; break; }
|
|
4040
|
+
anc = anc.parentElement;
|
|
4041
|
+
}
|
|
4042
|
+
if (ownedByInner) continue;
|
|
4043
|
+
if (d.closest?.(REPEATED_TEXT_SKIP_SELECTOR)) continue;
|
|
4044
|
+
// Icon-font glyph names read as text but render as symbols.
|
|
4045
|
+
if (/icon|material-symbols|(?:^|\s)fa[srlbd]?(?:\s|-|$)/i.test(String(d.getAttribute?.('class') || ''))) continue;
|
|
4046
|
+
if (!isVisible(d)) continue;
|
|
4047
|
+
|
|
4048
|
+
const direct = [...d.childNodes]
|
|
4049
|
+
.filter(n => n.nodeType === 3)
|
|
4050
|
+
.map(n => n.textContent)
|
|
4051
|
+
.join(' ')
|
|
4052
|
+
.replace(/\s+/g, ' ')
|
|
4053
|
+
.trim();
|
|
4054
|
+
if (direct.length < 4 || direct.length > 48) continue;
|
|
4055
|
+
if (!/[a-zA-Z]/.test(direct)) continue;
|
|
4056
|
+
|
|
4057
|
+
// Structural signature: the element path from the occurrence up to
|
|
4058
|
+
// the container. Parallel/templated repetition shares one signature.
|
|
4059
|
+
const sig = [];
|
|
4060
|
+
for (let cur = d; cur && cur !== container; cur = cur.parentElement) {
|
|
4061
|
+
const cls = String(cur.getAttribute?.('class') || '')
|
|
4062
|
+
.trim().split(/\s+/).filter(Boolean).sort().join('.');
|
|
4063
|
+
sig.push(cur.tagName.toLowerCase() + (cls ? `.${cls}` : ''));
|
|
4064
|
+
}
|
|
4065
|
+
if (!groups.has(direct)) groups.set(direct, []);
|
|
4066
|
+
groups.get(direct).push(sig.join('>'));
|
|
4067
|
+
}
|
|
4068
|
+
|
|
4069
|
+
for (const [text, sigs] of groups) {
|
|
4070
|
+
if (sigs.length < 3) continue;
|
|
4071
|
+
if (new Set(sigs).size < 3) continue;
|
|
4072
|
+
findings.push({
|
|
4073
|
+
id: 'repeated-container-text',
|
|
4074
|
+
snippet: `"${text.slice(0, 40)}" rendered ${sigs.length}× in distinct spots inside ${classSelector(container)}`,
|
|
4075
|
+
});
|
|
4076
|
+
}
|
|
4077
|
+
}
|
|
4078
|
+
return findings;
|
|
4079
|
+
}
|
|
4080
|
+
|
|
4081
|
+
function checkRepeatedContainerTextFromDoc(doc, win) {
|
|
4082
|
+
return collectRepeatedContainerTextFindings(
|
|
4083
|
+
doc,
|
|
4084
|
+
(el) => win.getComputedStyle(el),
|
|
4085
|
+
{ isVisible: (el) => String(win.getComputedStyle(el).display || '') !== 'none' },
|
|
4086
|
+
);
|
|
4087
|
+
}
|
|
4088
|
+
|
|
4089
|
+
function checkRepeatedContainerTextDOM() {
|
|
4090
|
+
return collectRepeatedContainerTextFindings(
|
|
4091
|
+
document,
|
|
4092
|
+
(el) => getComputedStyle(el),
|
|
4093
|
+
{ isVisible: isRenderedForBrowserRule },
|
|
4094
|
+
);
|
|
4095
|
+
}
|
|
4096
|
+
|
|
2191
4097
|
// ─── Cream / beige palette (the default "tasteful" AI surface) ────────────────
|
|
2192
4098
|
// A warm, lightly-tinted off-white page background — light, with R≥G≥B and a
|
|
2193
4099
|
// small warm tint (not white, not a strong color). The current reflex surface.
|
|
@@ -2301,7 +4207,7 @@ function checkElementOversizedH1DOM(el) {
|
|
|
2301
4207
|
return checkOversizedH1({ tag, fontSize, headingText, rect, viewportWidth, viewportHeight });
|
|
2302
4208
|
}
|
|
2303
4209
|
|
|
2304
|
-
// ───
|
|
4210
|
+
// ─── Generated-UI tell: hairline border + wide diffuse shadow ────────────────
|
|
2305
4211
|
const CSS_COLOR_TOKEN_RE = /(?:rgba?|hsla?|oklch|oklab|lab|lch|color)\([^)]*\)|#[0-9a-fA-F]{3,8}\b|\b(?:black|white|transparent|currentcolor)\b/gi;
|
|
2306
4212
|
|
|
2307
4213
|
function shadowLayerAlpha(layer) {
|
|
@@ -2626,13 +4532,653 @@ function checkElementTextOverflowDOM(el) {
|
|
|
2626
4532
|
if (el.clientWidth > 0 && delta >= 16) {
|
|
2627
4533
|
return [{ id: 'text-overflow', snippet: `${classSelector(el)} overflows its box by ${Math.round(delta)}px` }];
|
|
2628
4534
|
}
|
|
4535
|
+
|
|
4536
|
+
// Inline text owners have no client geometry (clientWidth/scrollWidth are
|
|
4537
|
+
// both 0), so the scrollWidth path above never sees them. Their overflow
|
|
4538
|
+
// registers only on a block ancestor, and that ancestor has no direct text
|
|
4539
|
+
// so the ownership gate skips it. (The shipped miss: a nowrap inline
|
|
4540
|
+
// <span> spilling 45px past its fixed-width grid cell.) Measure the inline
|
|
4541
|
+
// box against the padding box of its nearest block container instead.
|
|
4542
|
+
if (el.clientWidth === 0 && rect && rect.width > 0) {
|
|
4543
|
+
let container = el.parentElement;
|
|
4544
|
+
while (container && container.clientWidth === 0) container = container.parentElement;
|
|
4545
|
+
if (!container) return [];
|
|
4546
|
+
// Transforms make rect comparisons lie; skip anything on that path.
|
|
4547
|
+
for (let p = el; p && p !== container.parentElement; p = p.parentElement) {
|
|
4548
|
+
const t = getComputedStyle(p).transform;
|
|
4549
|
+
if (t && t !== 'none') return [];
|
|
4550
|
+
}
|
|
4551
|
+
const cRect = container.getBoundingClientRect();
|
|
4552
|
+
const contentRight = cRect.left + container.clientLeft + container.clientWidth;
|
|
4553
|
+
const spill = rect.right - contentRight;
|
|
4554
|
+
if (spill >= 16) {
|
|
4555
|
+
return [{ id: 'text-overflow', snippet: `${classSelector(el)} overflows its container by ${Math.round(spill)}px` }];
|
|
4556
|
+
}
|
|
4557
|
+
}
|
|
2629
4558
|
return [];
|
|
2630
4559
|
}
|
|
2631
4560
|
|
|
4561
|
+
// ---------------------------------------------------------------------------
|
|
4562
|
+
// Blinking cursor (browser-only)
|
|
4563
|
+
// ---------------------------------------------------------------------------
|
|
4564
|
+
|
|
4565
|
+
// Block / underscore glyphs commonly used as a fake text cursor.
|
|
4566
|
+
const CURSOR_GLYPH_RE = /^[_|▀-▟■▮❙❚|]$/;
|
|
4567
|
+
|
|
4568
|
+
// How far down the page still counts as the first-viewport / hero region.
|
|
4569
|
+
// Hero compositions regularly run past a literal viewport height, so the
|
|
4570
|
+
// gate is a landing-region budget, not an exact fold line.
|
|
4571
|
+
const CURSOR_FIRST_VIEWPORT_PX = 1200;
|
|
4572
|
+
|
|
4573
|
+
// Do the named @keyframes only toggle visibility (opacity dropping to ~0 or
|
|
4574
|
+
// visibility:hidden), i.e. a blink rather than a fade/move/spin? Walks the
|
|
4575
|
+
// live CSSOM; cross-origin sheets are skipped.
|
|
4576
|
+
function keyframesToggleVisibilityDOM(name) {
|
|
4577
|
+
if (!name) return false;
|
|
4578
|
+
for (const sheet of document.styleSheets) {
|
|
4579
|
+
let rules;
|
|
4580
|
+
try { rules = sheet.cssRules || sheet.rules; } catch { continue; }
|
|
4581
|
+
if (!rules) continue;
|
|
4582
|
+
const stack = [...rules];
|
|
4583
|
+
while (stack.length) {
|
|
4584
|
+
const rule = stack.shift();
|
|
4585
|
+
if (rule.cssRules && rule.type !== 7) { stack.push(...rule.cssRules); continue; }
|
|
4586
|
+
if (rule.type !== 7 || rule.name !== name) continue; // 7 = KEYFRAMES_RULE
|
|
4587
|
+
let togglesOut = false;
|
|
4588
|
+
for (const frame of rule.cssRules || []) {
|
|
4589
|
+
const fs = frame.style;
|
|
4590
|
+
if (!fs) continue;
|
|
4591
|
+
for (let i = 0; i < fs.length; i++) {
|
|
4592
|
+
const prop = fs[i];
|
|
4593
|
+
if (prop === 'opacity') {
|
|
4594
|
+
if ((parseFloat(fs.getPropertyValue('opacity')) || 0) <= 0.15) togglesOut = true;
|
|
4595
|
+
} else if (prop === 'visibility') {
|
|
4596
|
+
if (/hidden/i.test(fs.getPropertyValue('visibility'))) togglesOut = true;
|
|
4597
|
+
} else if (prop !== 'animation-timing-function') {
|
|
4598
|
+
return false; // keyframes animate something else — not a blink
|
|
4599
|
+
}
|
|
4600
|
+
}
|
|
4601
|
+
}
|
|
4602
|
+
return togglesOut;
|
|
4603
|
+
}
|
|
4604
|
+
}
|
|
4605
|
+
return false;
|
|
4606
|
+
}
|
|
4607
|
+
|
|
4608
|
+
// Decorative blinking cursor: a small block / underscore element bound to an
|
|
4609
|
+
// infinite blink animation, sitting in the first-viewport region of a page.
|
|
4610
|
+
// Real editable surfaces (inputs, textareas, contenteditable, role=textbox)
|
|
4611
|
+
// draw their own caret and are exempt. Round pulsing dots stay with the
|
|
4612
|
+
// pulsing-dot rule.
|
|
4613
|
+
function checkElementBlinkingCursorDOM(el) {
|
|
4614
|
+
const tag = el.tagName.toLowerCase();
|
|
4615
|
+
if (['input', 'textarea', 'select', 'img', 'svg', 'script', 'style'].includes(tag)) return [];
|
|
4616
|
+
const style = getComputedStyle(el);
|
|
4617
|
+
|
|
4618
|
+
const iterations = (style.animationIterationCount || '').split(',').map(s => s.trim());
|
|
4619
|
+
if (!iterations.includes('infinite')) return [];
|
|
4620
|
+
const names = (style.animationName || '').split(',').map(s => s.trim()).filter(n => n && n !== 'none');
|
|
4621
|
+
if (names.length === 0) return [];
|
|
4622
|
+
const blinkName = names.find(n => /blink|caret|cursor/i.test(n))
|
|
4623
|
+
|| names.find(n => keyframesToggleVisibilityDOM(n));
|
|
4624
|
+
if (!blinkName) return [];
|
|
4625
|
+
|
|
4626
|
+
// Real caret contexts are exempt.
|
|
4627
|
+
if (el.isContentEditable || el.closest('[contenteditable=""], [contenteditable="true"], [role="textbox"]')) return [];
|
|
4628
|
+
|
|
4629
|
+
const rect = el.getBoundingClientRect();
|
|
4630
|
+
if (rect.width <= 0 || rect.height <= 0) return [];
|
|
4631
|
+
|
|
4632
|
+
// First-viewport gate: the hero cliché, not a footer terminal.
|
|
4633
|
+
const pageTop = rect.top + (window.scrollY || 0);
|
|
4634
|
+
if (pageTop > CURSOR_FIRST_VIEWPORT_PX) return [];
|
|
4635
|
+
|
|
4636
|
+
// Cursor shape: a lone block/underscore glyph, or an empty solid
|
|
4637
|
+
// rectangle sized like a text caret (block or underscore form).
|
|
4638
|
+
const text = (el.textContent || '').trim();
|
|
4639
|
+
const glyphCursor = text.length === 1 && CURSOR_GLYPH_RE.test(text);
|
|
4640
|
+
let blockCursor = false;
|
|
4641
|
+
if (!glyphCursor) {
|
|
4642
|
+
if (text.length > 0 || el.childElementCount > 0) return [];
|
|
4643
|
+
const bg = parseAnyColor(style.backgroundColor || '');
|
|
4644
|
+
const filled = bg && (bg.a ?? 1) > 0.2;
|
|
4645
|
+
const hasBorderFill = ['Left', 'Right', 'Bottom'].some(
|
|
4646
|
+
side => (parseFloat(style[`border${side}Width`]) || 0) >= 1,
|
|
4647
|
+
);
|
|
4648
|
+
if (!filled && !hasBorderFill) return [];
|
|
4649
|
+
const vertical = rect.width >= 1 && rect.width <= 24 && rect.height >= 6 && rect.height <= 48 && rect.height >= rect.width;
|
|
4650
|
+
const underscore = rect.height >= 1 && rect.height <= 6 && rect.width >= 4 && rect.width <= 24;
|
|
4651
|
+
if (!vertical && !underscore) return [];
|
|
4652
|
+
// Round dots are the pulsing-dot rule's territory.
|
|
4653
|
+
const radiusPx = parseFloat(style.borderRadius) || 0;
|
|
4654
|
+
if (radiusPx >= 0.4 * Math.min(rect.width, rect.height)) return [];
|
|
4655
|
+
blockCursor = true;
|
|
4656
|
+
}
|
|
4657
|
+
if (!glyphCursor && !blockCursor) return [];
|
|
4658
|
+
|
|
4659
|
+
// Hero-region promotion: a fake caret blinking in the first ~900px or
|
|
4660
|
+
// inside the page chrome is the shipped hero cliché, not an incidental
|
|
4661
|
+
// flourish. Promote those from the registry's advisory to warning;
|
|
4662
|
+
// lower first-viewport occurrences keep the default severity.
|
|
4663
|
+
const inHeroRegion = pageTop <= 900
|
|
4664
|
+
|| !!(el.closest && el.closest('header, nav, [role="banner"], [role="navigation"]'));
|
|
4665
|
+
return [{
|
|
4666
|
+
id: 'blinking-cursor',
|
|
4667
|
+
snippet: `${classSelector(el)} — ${Math.round(rect.width)}x${Math.round(rect.height)}px blinking cursor (animation "${blinkName}") in the first viewport`,
|
|
4668
|
+
...(inHeroRegion ? { severity: 'warning' } : {}),
|
|
4669
|
+
}];
|
|
4670
|
+
}
|
|
4671
|
+
|
|
4672
|
+
// ---------------------------------------------------------------------------
|
|
4673
|
+
// Content invisible at rest (browser-only, driven by the URL engine)
|
|
4674
|
+
// ---------------------------------------------------------------------------
|
|
4675
|
+
|
|
4676
|
+
// Tags whose text never renders, or whose hidden state is legitimate UI
|
|
4677
|
+
// (templates, dialogs, native select options). Text inside them stays out of
|
|
4678
|
+
// both the numerator and the denominator.
|
|
4679
|
+
const HIDDEN_TEXT_EXCLUDE_TAGS = new Set([
|
|
4680
|
+
'script', 'style', 'noscript', 'template', 'title', 'head', 'meta', 'link',
|
|
4681
|
+
'option', 'optgroup', 'select', 'datalist', 'dialog',
|
|
4682
|
+
]);
|
|
4683
|
+
|
|
4684
|
+
// Measure how many text characters currently render invisible (computed
|
|
4685
|
+
// opacity ~0 or visibility hidden anywhere on the ancestor chain) versus
|
|
4686
|
+
// visible. display:none / [hidden] / aria-hidden subtrees are legitimately
|
|
4687
|
+
// hidden UI (menus, tab panels, templates): they are excluded from the
|
|
4688
|
+
// denominator entirely rather than counted as invisible.
|
|
4689
|
+
function measureHiddenTextDOM() {
|
|
4690
|
+
const cache = new Map();
|
|
4691
|
+
function stateOf(el) {
|
|
4692
|
+
if (!el || el.nodeType !== 1 || el === document.documentElement) return 'visible';
|
|
4693
|
+
const cached = cache.get(el);
|
|
4694
|
+
if (cached) return cached;
|
|
4695
|
+
let state;
|
|
4696
|
+
const tag = el.tagName.toLowerCase();
|
|
4697
|
+
if (HIDDEN_TEXT_EXCLUDE_TAGS.has(tag)) {
|
|
4698
|
+
state = 'excluded';
|
|
4699
|
+
} else {
|
|
4700
|
+
const parentState = stateOf(el.parentElement);
|
|
4701
|
+
if (parentState === 'excluded') {
|
|
4702
|
+
state = 'excluded';
|
|
4703
|
+
} else {
|
|
4704
|
+
const style = getComputedStyle(el);
|
|
4705
|
+
if (style.display === 'none' || el.hidden || el.getAttribute('aria-hidden') === 'true'
|
|
4706
|
+
|| String(style.contentVisibility || '').toLowerCase() === 'hidden') {
|
|
4707
|
+
state = 'excluded';
|
|
4708
|
+
} else if (parentState === 'invisible'
|
|
4709
|
+
|| (parseFloat(style.opacity) || 0) <= 0.02
|
|
4710
|
+
|| /^(hidden|collapse)$/.test(style.visibility)) {
|
|
4711
|
+
state = 'invisible';
|
|
4712
|
+
} else {
|
|
4713
|
+
state = 'visible';
|
|
4714
|
+
}
|
|
4715
|
+
}
|
|
4716
|
+
}
|
|
4717
|
+
cache.set(el, state);
|
|
4718
|
+
return state;
|
|
4719
|
+
}
|
|
4720
|
+
|
|
4721
|
+
let totalChars = 0;
|
|
4722
|
+
let hiddenChars = 0;
|
|
4723
|
+
const hiddenSamples = [];
|
|
4724
|
+
for (const el of document.querySelectorAll('body *')) {
|
|
4725
|
+
let len = 0;
|
|
4726
|
+
for (const node of el.childNodes) {
|
|
4727
|
+
if (node.nodeType === 3) len += node.textContent.replace(/\s+/g, ' ').trim().length;
|
|
4728
|
+
}
|
|
4729
|
+
if (!len) continue;
|
|
4730
|
+
const state = stateOf(el);
|
|
4731
|
+
if (state === 'excluded') continue;
|
|
4732
|
+
totalChars += len;
|
|
4733
|
+
if (state === 'invisible') {
|
|
4734
|
+
hiddenChars += len;
|
|
4735
|
+
if (hiddenSamples.length < 3) {
|
|
4736
|
+
const text = String(el.textContent || '').replace(/\s+/g, ' ').trim().slice(0, 40);
|
|
4737
|
+
if (text) hiddenSamples.push(text);
|
|
4738
|
+
}
|
|
4739
|
+
}
|
|
4740
|
+
}
|
|
4741
|
+
return { totalChars, hiddenChars, hiddenSamples };
|
|
4742
|
+
}
|
|
4743
|
+
|
|
4744
|
+
// Pure threshold check over a measureHiddenTextDOM() result. The URL engine
|
|
4745
|
+
// calls it AFTER a reveal sweep (scroll through the document so every
|
|
4746
|
+
// IntersectionObserver / scroll reveal had its chance to fire, then back to
|
|
4747
|
+
// the top): a healthy reveal-on-scroll page drops to ~0 invisible text after
|
|
4748
|
+
// the sweep, while a page whose reveal script died keeps most of its text at
|
|
4749
|
+
// opacity 0 forever. Fires only when the invisible share stays above 30%
|
|
4750
|
+
// with a real amount of text behind it.
|
|
4751
|
+
function checkContentHiddenAtRest({ totalChars = 0, hiddenChars = 0, hiddenSamples = [] } = {}) {
|
|
4752
|
+
if (totalChars < 200 || hiddenChars < 150) return [];
|
|
4753
|
+
const share = hiddenChars / totalChars;
|
|
4754
|
+
if (share <= 0.3) return [];
|
|
4755
|
+
const sample = hiddenSamples.length ? ` (e.g. "${hiddenSamples[0]}")` : '';
|
|
4756
|
+
return [{
|
|
4757
|
+
id: 'content-hidden-at-rest',
|
|
4758
|
+
snippet: `${Math.round(share * 100)}% of page text (${hiddenChars} of ${totalChars} chars) stays at opacity 0 / visibility hidden after reveal handlers ran${sample}`,
|
|
4759
|
+
}];
|
|
4760
|
+
}
|
|
4761
|
+
|
|
4762
|
+
// ---------------------------------------------------------------------------
|
|
4763
|
+
// Edge-flush cards in horizontal scrollers (browser-only)
|
|
4764
|
+
// ---------------------------------------------------------------------------
|
|
4765
|
+
|
|
4766
|
+
// A visually-defined card (own opaque background, or borders on 2+ sides)
|
|
4767
|
+
// inside a horizontal scroller, sitting flush against one edge of the
|
|
4768
|
+
// scroller's clip box at rest while keeping a clear gutter on the other
|
|
4769
|
+
// side. The canonical bug: the first snap panel is sized wider than the
|
|
4770
|
+
// scroller, so its cards end exactly at the clip edge with their rounded
|
|
4771
|
+
// corners cut, while every sibling panel keeps its inset. Cards that extend
|
|
4772
|
+
// far past the edge are deliberate peeks and stay exempt.
|
|
4773
|
+
function checkEdgeFlushCardsDOM() {
|
|
4774
|
+
const findings = [];
|
|
4775
|
+
const vh = window.innerHeight || 800;
|
|
4776
|
+
const isScroller = (s) => /(auto|scroll)/.test(s.overflowX || '') || /(auto|scroll)/.test(s.overflow || '');
|
|
4777
|
+
|
|
4778
|
+
for (const scroller of document.querySelectorAll('*')) {
|
|
4779
|
+
const style = getComputedStyle(scroller);
|
|
4780
|
+
if (!isScroller(style)) continue;
|
|
4781
|
+
if (scroller.scrollWidth <= scroller.clientWidth + 8) continue;
|
|
4782
|
+
// At rest only: a user-scrolled or snapped-forward scroller legitimately
|
|
4783
|
+
// shows cut cards at both edges.
|
|
4784
|
+
if (scroller.scrollLeft > 4) continue;
|
|
4785
|
+
const scRect = scroller.getBoundingClientRect();
|
|
4786
|
+
if (scRect.width < 120 || scRect.height < 60) continue;
|
|
4787
|
+
// Landing-region gate: the defect matters where the page opens.
|
|
4788
|
+
if (scRect.top + (window.scrollY || 0) > 2 * vh) continue;
|
|
4789
|
+
const contentLeft = scRect.left + scroller.clientLeft;
|
|
4790
|
+
const contentRight = contentLeft + scroller.clientWidth;
|
|
4791
|
+
|
|
4792
|
+
const flush = [];
|
|
4793
|
+
for (const card of scroller.querySelectorAll('*')) {
|
|
4794
|
+
if (!isRenderedForBrowserRule(card)) continue;
|
|
4795
|
+
// Attribute cards to their nearest scroller only (nested scrollers).
|
|
4796
|
+
let owner = card.parentElement;
|
|
4797
|
+
while (owner && owner !== scroller && !isScroller(getComputedStyle(owner))) owner = owner.parentElement;
|
|
4798
|
+
if (owner !== scroller) continue;
|
|
4799
|
+
const cs = getComputedStyle(card);
|
|
4800
|
+
const rect = card.getBoundingClientRect();
|
|
4801
|
+
if (rect.width < 80 || rect.height < 40) continue;
|
|
4802
|
+
const bg = parseAnyColor(cs.backgroundColor || '');
|
|
4803
|
+
const hasBg = !!(bg && (bg.a ?? 1) > 0.5);
|
|
4804
|
+
const borderSides = ['Top', 'Right', 'Bottom', 'Left']
|
|
4805
|
+
.filter(side => (parseFloat(cs[`border${side}Width`]) || 0) > 0).length;
|
|
4806
|
+
if (!hasBg && borderSides < 2) continue;
|
|
4807
|
+
const leftGutter = rect.left - contentLeft;
|
|
4808
|
+
const rightGap = contentRight - rect.right;
|
|
4809
|
+
// Flush right with a left gutter, or the mirror. The -24 floor keeps
|
|
4810
|
+
// deliberately peeking next-cards (cut mid-card) exempt.
|
|
4811
|
+
const flushRight = leftGutter >= 6 && rightGap < 8 && rightGap > -24;
|
|
4812
|
+
const flushLeft = rightGap >= 6 && leftGutter < 8 && leftGutter > -24;
|
|
4813
|
+
if (!flushRight && !flushLeft) continue;
|
|
4814
|
+
flush.push({ card, edge: flushRight ? 'right' : 'left', gap: Math.round(flushRight ? rightGap : leftGutter) });
|
|
4815
|
+
}
|
|
4816
|
+
if (flush.length === 0) continue;
|
|
4817
|
+
const worst = flush.reduce((a, b) => (b.gap < a.gap ? b : a));
|
|
4818
|
+
findings.push({
|
|
4819
|
+
el: scroller,
|
|
4820
|
+
type: 'edge-flush-cards',
|
|
4821
|
+
detail: `${flush.length} card${flush.length === 1 ? '' : 's'} flush against the ${worst.edge} edge of ${classSelector(scroller)} at rest (${worst.gap}px gap, e.g. ${classSelector(worst.card)})`,
|
|
4822
|
+
});
|
|
4823
|
+
}
|
|
4824
|
+
return findings;
|
|
4825
|
+
}
|
|
4826
|
+
|
|
4827
|
+
// ---------------------------------------------------------------------------
|
|
4828
|
+
// Text occlusion / element overlap (browser-only)
|
|
4829
|
+
// ---------------------------------------------------------------------------
|
|
4830
|
+
|
|
4831
|
+
// An opaque decorated box: a near-solid background fill or two-plus visible
|
|
4832
|
+
// borders make it hide whatever sits behind it. Gradient / image fills are
|
|
4833
|
+
// deliberately excluded — a scrim gradient over hero imagery is a contrast
|
|
4834
|
+
// layer, not an occluder, and belongs to the pixel low-contrast rule.
|
|
4835
|
+
function isOpaqueDecoratedBox(cs) {
|
|
4836
|
+
if (!cs) return false;
|
|
4837
|
+
const bg = parseAnyColor(cs.backgroundColor || '');
|
|
4838
|
+
if (bg && (bg.a ?? 1) > 0.6) return true;
|
|
4839
|
+
const borderSides = ['Top', 'Right', 'Bottom', 'Left'].filter((side) => {
|
|
4840
|
+
if ((parseFloat(cs[`border${side}Width`]) || 0) <= 0) return false;
|
|
4841
|
+
const bc = parseAnyColor(cs[`border${side}Color`] || '');
|
|
4842
|
+
return bc && (bc.a ?? 1) > 0.3;
|
|
4843
|
+
}).length;
|
|
4844
|
+
return borderSides >= 2;
|
|
4845
|
+
}
|
|
4846
|
+
|
|
4847
|
+
// Is this element lifted out of normal flow into a layer that can cover
|
|
4848
|
+
// siblings? Two normal-flow blocks stacked vertically cannot truly hide each
|
|
4849
|
+
// other's ink — an overlap between their rects is line-box bleed from tight
|
|
4850
|
+
// leading (a display headline reaching up over the line before it), not
|
|
4851
|
+
// occlusion. Only out-of-flow positioning (absolute / fixed / sticky) moves an
|
|
4852
|
+
// element off its own row onto the pixels of another; an in-place transform or
|
|
4853
|
+
// relative nudge on a display headline does not.
|
|
4854
|
+
function isLayeredElement(el) {
|
|
4855
|
+
for (let cur = el; cur && cur.nodeType === 1 && cur !== document.body; cur = cur.parentElement) {
|
|
4856
|
+
const pos = String(getComputedStyle(cur).position || 'static');
|
|
4857
|
+
if (pos === 'absolute' || pos === 'fixed' || pos === 'sticky') return true;
|
|
4858
|
+
}
|
|
4859
|
+
return false;
|
|
4860
|
+
}
|
|
4861
|
+
|
|
4862
|
+
function elementDirectText(el) {
|
|
4863
|
+
let t = '';
|
|
4864
|
+
for (const node of el.childNodes || []) {
|
|
4865
|
+
if (node.nodeType === 3) t += node.textContent;
|
|
4866
|
+
}
|
|
4867
|
+
return t.trim();
|
|
4868
|
+
}
|
|
4869
|
+
|
|
4870
|
+
// Rendered gate that, unlike isRenderedForBrowserRule, does NOT exempt
|
|
4871
|
+
// aria-hidden subtrees: a decorative aria-hidden box still paints on screen
|
|
4872
|
+
// and can still visually cover real text.
|
|
4873
|
+
function isPaintedForOcclusion(el) {
|
|
4874
|
+
for (let cur = el; cur && cur.nodeType === 1; cur = cur.parentElement) {
|
|
4875
|
+
const style = getComputedStyle(cur);
|
|
4876
|
+
const visibility = String(style.visibility || '').toLowerCase();
|
|
4877
|
+
if (style.display === 'none' || visibility === 'hidden' || visibility === 'collapse') return false;
|
|
4878
|
+
if ((parseFloat(style.opacity) || 0) <= 0.05) return false;
|
|
4879
|
+
if (String(style.contentVisibility || '').toLowerCase() === 'hidden') return false;
|
|
4880
|
+
}
|
|
4881
|
+
return true;
|
|
4882
|
+
}
|
|
4883
|
+
|
|
4884
|
+
// Detects text that is actually painted UNDER an opaque box or another text
|
|
4885
|
+
// run (the reader can't read it), plus two structural overlap tells the
|
|
4886
|
+
// elementFromPoint probe can't reach: a large headline whose edge tucks behind
|
|
4887
|
+
// an opaque card, and an inline element whose leaked padding-box (a common
|
|
4888
|
+
// class-name-collision bug) covers a sibling.
|
|
4889
|
+
//
|
|
4890
|
+
// The occlusion probe is viewport-bound: elementFromPoint only answers for the
|
|
4891
|
+
// scan's current viewport (scroll 0), so the ground-truth paths cover the
|
|
4892
|
+
// first-viewport composition where collisions matter most. The inline-leak
|
|
4893
|
+
// path is pure geometry and runs anywhere on the page.
|
|
4894
|
+
const OCCLUSION_TEXT_SKIP_TAGS = new Set(['script', 'style', 'noscript', 'template', 'title']);
|
|
4895
|
+
|
|
4896
|
+
function checkTextOcclusionDOM() {
|
|
4897
|
+
const findings = [];
|
|
4898
|
+
const seenVictims = new Set();
|
|
4899
|
+
const vw = window.innerWidth || 1280;
|
|
4900
|
+
const vh = window.innerHeight || 800;
|
|
4901
|
+
|
|
4902
|
+
const isFloated = (cs) => {
|
|
4903
|
+
const f = String(cs.cssFloat || cs.float || 'none').toLowerCase();
|
|
4904
|
+
return f === 'left' || f === 'right';
|
|
4905
|
+
};
|
|
4906
|
+
const isMarqueeish = (el, cs) => {
|
|
4907
|
+
if (el.tagName === 'MARQUEE') return true;
|
|
4908
|
+
const ident = `${el.getAttribute?.('class') || ''} ${el.getAttribute?.('id') || ''}`;
|
|
4909
|
+
if (/\b(marquee|ticker|scroller|carousel|conveyor)\b/i.test(ident)) return true;
|
|
4910
|
+
const anim = String(cs.animationName || '').toLowerCase();
|
|
4911
|
+
return /marquee|ticker|scroll/.test(anim);
|
|
4912
|
+
};
|
|
4913
|
+
// A fixed or sticky overlay (status bar, toolbar, sticky header) floats above
|
|
4914
|
+
// scrolling content by design — whatever sits under it at rest scrolls clear,
|
|
4915
|
+
// so it is not occluding the page.
|
|
4916
|
+
const isPinnedOverlay = (el) => {
|
|
4917
|
+
for (let cur = el; cur && cur.nodeType === 1 && cur !== document.body; cur = cur.parentElement) {
|
|
4918
|
+
const pos = String(getComputedStyle(cur).position || 'static');
|
|
4919
|
+
if (pos === 'fixed' || pos === 'sticky') return true;
|
|
4920
|
+
}
|
|
4921
|
+
return false;
|
|
4922
|
+
};
|
|
4923
|
+
|
|
4924
|
+
// Collect renderable text owners in / near the first viewport for the
|
|
4925
|
+
// elementFromPoint probe. SVG <text> counts too.
|
|
4926
|
+
const textEls = [];
|
|
4927
|
+
for (const el of document.querySelectorAll('body *')) {
|
|
4928
|
+
const tag = el.tagName.toLowerCase();
|
|
4929
|
+
if (OCCLUSION_TEXT_SKIP_TAGS.has(tag)) continue;
|
|
4930
|
+
const inSvg = !!el.closest('svg');
|
|
4931
|
+
if (inSvg && tag !== 'text') continue;
|
|
4932
|
+
const text = inSvg ? (el.textContent || '').trim() : elementDirectText(el);
|
|
4933
|
+
if (text.length < 2) continue;
|
|
4934
|
+
if (!isPaintedForOcclusion(el)) continue;
|
|
4935
|
+
let rect; try { rect = el.getBoundingClientRect(); } catch { continue; }
|
|
4936
|
+
if (rect.width < 6 || rect.height < 6) continue;
|
|
4937
|
+
// Viewport-bound probe: keep text whose box overlaps the live viewport.
|
|
4938
|
+
if (rect.bottom <= 0 || rect.top >= vh) continue;
|
|
4939
|
+
textEls.push({ el, rect, text, inSvg });
|
|
4940
|
+
}
|
|
4941
|
+
|
|
4942
|
+
for (const victim of textEls) {
|
|
4943
|
+
const { el, rect, text } = victim;
|
|
4944
|
+
if (seenVictims.has(el)) continue;
|
|
4945
|
+
const style = getComputedStyle(el);
|
|
4946
|
+
if (isScreenReaderOnlyTextStyle(style, { width: rect.width, height: rect.height, clientWidth: el.clientWidth, clientHeight: el.clientHeight })) continue;
|
|
4947
|
+
|
|
4948
|
+
const cols = Math.max(6, Math.min(30, Math.round(rect.width / 12)));
|
|
4949
|
+
const rows = Math.max(1, Math.min(4, Math.round(rect.height / 14)));
|
|
4950
|
+
let total = 0;
|
|
4951
|
+
let occluded = 0;
|
|
4952
|
+
let occluderEl = null;
|
|
4953
|
+
let occluderKind = '';
|
|
4954
|
+
for (let i = 0; i < cols; i++) {
|
|
4955
|
+
const x = rect.left + rect.width * ((i + 0.5) / cols);
|
|
4956
|
+
if (x < 1 || x > vw - 1) continue;
|
|
4957
|
+
for (let j = 0; j < rows; j++) {
|
|
4958
|
+
const y = rect.top + rect.height * ((j + 0.5) / rows);
|
|
4959
|
+
if (y < 1 || y > vh - 1) continue;
|
|
4960
|
+
total++;
|
|
4961
|
+
const top = document.elementFromPoint(x, y);
|
|
4962
|
+
if (!top) continue;
|
|
4963
|
+
// Text visible here: the probe returns the text itself, a descendant,
|
|
4964
|
+
// or one of its ancestors (the text's own container / background).
|
|
4965
|
+
if (top === el || el.contains(top) || top.contains(el)) continue;
|
|
4966
|
+
const topCs = getComputedStyle(top);
|
|
4967
|
+
if (isFloated(topCs) || isMarqueeish(top, topCs) || isPinnedOverlay(top)) continue;
|
|
4968
|
+
const topTag = top.tagName.toLowerCase();
|
|
4969
|
+
// Text sitting under a raw image/video is contrast territory (deduped
|
|
4970
|
+
// against the pixel low-contrast rule); leave those alone here.
|
|
4971
|
+
if (['img', 'video', 'canvas', 'picture'].includes(topTag)) continue;
|
|
4972
|
+
const topHasText = elementDirectText(top).length > 0 || !!top.closest('svg');
|
|
4973
|
+
if (isOpaqueDecoratedBox(topCs)) {
|
|
4974
|
+
occluded++;
|
|
4975
|
+
if (!occluderEl) { occluderEl = top; occluderKind = 'box'; }
|
|
4976
|
+
} else if (topHasText) {
|
|
4977
|
+
occluded++;
|
|
4978
|
+
if (!occluderEl) { occluderEl = top; occluderKind = 'text'; }
|
|
4979
|
+
}
|
|
4980
|
+
}
|
|
4981
|
+
}
|
|
4982
|
+
if (total === 0 || !occluderEl) continue;
|
|
4983
|
+
const occFrac = occluded / total;
|
|
4984
|
+
// A solid box's paint fills its rect, so box coverage is real at a lower
|
|
4985
|
+
// bar. Text coverage rides on elementFromPoint returning the occluder's box
|
|
4986
|
+
// (line box / container), which can exceed its actual glyph ink, so the
|
|
4987
|
+
// text bar is higher — partial overlaps below it are crowding, not burial.
|
|
4988
|
+
if (occFrac < (occluderKind === 'text' ? 0.45 : 0.3)) continue;
|
|
4989
|
+
|
|
4990
|
+
// (i) Substantial occlusion: a real slab of the text is behind something.
|
|
4991
|
+
if (occluderKind === 'text') {
|
|
4992
|
+
// Two SVG texts inside the same emblem (concentric arcs, monogram) are one
|
|
4993
|
+
// decorative unit, not a collision.
|
|
4994
|
+
const victimSvg = el.closest('svg');
|
|
4995
|
+
const occSvg = occluderEl.closest('svg');
|
|
4996
|
+
if (victimSvg && occSvg && victimSvg === occSvg) continue;
|
|
4997
|
+
// Both sides in plain flow: the overlap is line-box bleed from tight
|
|
4998
|
+
// leading (a big headline reaching up over its own eyebrow), not one text
|
|
4999
|
+
// run painted over another.
|
|
5000
|
+
if (!isLayeredElement(el) && !isLayeredElement(occluderEl)) continue;
|
|
5001
|
+
}
|
|
5002
|
+
seenVictims.add(el);
|
|
5003
|
+
findings.push({
|
|
5004
|
+
el,
|
|
5005
|
+
type: 'text-occlusion',
|
|
5006
|
+
detail: `${classSelector(el)} "${text.slice(0, 24)}" is ${Math.round(occFrac * 100)}% covered by ${occluderKind === 'text' ? 'overlapping text' : 'an opaque element'} (${classSelector(occluderEl)})`,
|
|
5007
|
+
});
|
|
5008
|
+
}
|
|
5009
|
+
|
|
5010
|
+
// (ii) Headline overhanging an opaque card: a display-scale line whose bulk
|
|
5011
|
+
// sits outside a bounded content card but whose edge clips into it. The text
|
|
5012
|
+
// may still paint on top and stay readable, but the two layers were dropped
|
|
5013
|
+
// on the same pixels — a placement collision, not a composition.
|
|
5014
|
+
const cards = [];
|
|
5015
|
+
for (const el of document.querySelectorAll('body *')) {
|
|
5016
|
+
if (el.closest('svg')) continue;
|
|
5017
|
+
if (!isPaintedForOcclusion(el)) continue;
|
|
5018
|
+
const cs = getComputedStyle(el);
|
|
5019
|
+
const bg = parseAnyColor(cs.backgroundColor || '');
|
|
5020
|
+
const bgImg = cs.backgroundImage || '';
|
|
5021
|
+
if (!bg || (bg.a ?? 1) <= 0.7) continue;
|
|
5022
|
+
if (bgImg && bgImg !== 'none' && /(gradient|url)\(/i.test(bgImg)) continue;
|
|
5023
|
+
const hasBorder = ['Top', 'Right', 'Bottom', 'Left'].some((s) => (parseFloat(cs[`border${s}Width`]) || 0) > 0);
|
|
5024
|
+
const hasShadow = cs.boxShadow && cs.boxShadow !== 'none';
|
|
5025
|
+
if (!hasBorder && !hasShadow) continue;
|
|
5026
|
+
if (isPinnedOverlay(el)) continue;
|
|
5027
|
+
let cr; try { cr = el.getBoundingClientRect(); } catch { continue; }
|
|
5028
|
+
if (cr.width < 100 || cr.width > 0.8 * vw || cr.height < 60) continue;
|
|
5029
|
+
cards.push({ el, rect: cr });
|
|
5030
|
+
}
|
|
5031
|
+
for (const victim of textEls) {
|
|
5032
|
+
const { el, rect, text } = victim;
|
|
5033
|
+
if (seenVictims.has(el)) continue;
|
|
5034
|
+
const style = getComputedStyle(el);
|
|
5035
|
+
if ((parseFloat(style.fontSize) || 16) < 40) continue;
|
|
5036
|
+
let lineHeight = parseFloat(style.lineHeight);
|
|
5037
|
+
if (!Number.isFinite(lineHeight)) lineHeight = (parseFloat(style.fontSize) || 16) * 1.2;
|
|
5038
|
+
const centerX = rect.left + rect.width / 2;
|
|
5039
|
+
for (const card of cards) {
|
|
5040
|
+
if (card.el === el || el.contains(card.el) || card.el.contains(el)) continue;
|
|
5041
|
+
const ix = Math.max(0, Math.min(rect.right, card.rect.right) - Math.max(rect.left, card.rect.left));
|
|
5042
|
+
const iy = Math.max(0, Math.min(rect.bottom, card.rect.bottom) - Math.max(rect.top, card.rect.top));
|
|
5043
|
+
if (ix < 8 || iy < 0.5 * lineHeight) continue;
|
|
5044
|
+
// The headline's bulk must sit outside the card — only its edge clips in.
|
|
5045
|
+
if (centerX >= card.rect.left && centerX <= card.rect.right) continue;
|
|
5046
|
+
if (ix > 0.5 * rect.width) continue;
|
|
5047
|
+
seenVictims.add(el);
|
|
5048
|
+
findings.push({
|
|
5049
|
+
el,
|
|
5050
|
+
type: 'text-occlusion',
|
|
5051
|
+
detail: `${classSelector(el)} "${text.slice(0, 24)}" overhangs ${classSelector(card.el)} by ${Math.round(ix)}px — the headline and the card collide`,
|
|
5052
|
+
});
|
|
5053
|
+
break;
|
|
5054
|
+
}
|
|
5055
|
+
}
|
|
5056
|
+
|
|
5057
|
+
// (iii) Inline padding leak: an inline element with an opaque background and
|
|
5058
|
+
// large vertical padding paints a filled block whose padding-box overflows
|
|
5059
|
+
// its line (inline padding reserves no vertical space), so the fill lands on
|
|
5060
|
+
// the content above and below instead of enclosing its own text. The
|
|
5061
|
+
// canonical bug is a class-name collision that hands a decorative marker a
|
|
5062
|
+
// payoff card's padding. The tell is a rendered height several times the line
|
|
5063
|
+
// height, which distinguishes the leak from a padded inline highlight.
|
|
5064
|
+
for (const el of document.querySelectorAll('body *')) {
|
|
5065
|
+
if (el.closest('svg')) continue;
|
|
5066
|
+
if (!isPaintedForOcclusion(el)) continue;
|
|
5067
|
+
const cs = getComputedStyle(el);
|
|
5068
|
+
if (cs.display !== 'inline') continue;
|
|
5069
|
+
const bg = parseAnyColor(cs.backgroundColor || '');
|
|
5070
|
+
if (!bg || (bg.a ?? 1) <= 0.6) continue;
|
|
5071
|
+
const padTop = parseFloat(cs.paddingTop) || 0;
|
|
5072
|
+
const padBottom = parseFloat(cs.paddingBottom) || 0;
|
|
5073
|
+
if (padTop + padBottom < 24) continue;
|
|
5074
|
+
let rect; try { rect = el.getBoundingClientRect(); } catch { continue; }
|
|
5075
|
+
if (rect.width < 12 || rect.height < 24) continue;
|
|
5076
|
+
const fontSize = parseFloat(cs.fontSize) || 16;
|
|
5077
|
+
let lineHeight = parseFloat(cs.lineHeight);
|
|
5078
|
+
if (!Number.isFinite(lineHeight)) lineHeight = fontSize * 1.4;
|
|
5079
|
+
// The padding box has to overflow the line by a clear margin — a padded
|
|
5080
|
+
// inline highlight sits at roughly one line height, the leak at several.
|
|
5081
|
+
if (rect.height < 2.2 * lineHeight) continue;
|
|
5082
|
+
if (seenVictims.has(el)) continue;
|
|
5083
|
+
// Name a neighbour the fill lands on, if one is nearby (paint state aside,
|
|
5084
|
+
// reveal-on-scroll siblings still occupy the space it covers).
|
|
5085
|
+
let overlaps = null;
|
|
5086
|
+
for (const other of el.parentElement ? el.parentElement.children : []) {
|
|
5087
|
+
if (other === el || el.contains(other) || other.contains(el)) continue;
|
|
5088
|
+
if (getComputedStyle(other).display === 'none') continue;
|
|
5089
|
+
const oRect = other.getBoundingClientRect();
|
|
5090
|
+
const ix = Math.max(0, Math.min(rect.right, oRect.right) - Math.max(rect.left, oRect.left));
|
|
5091
|
+
const iy = Math.max(0, Math.min(rect.bottom, oRect.bottom) - Math.max(rect.top, oRect.top));
|
|
5092
|
+
if (ix > 4 && iy > 4 && (other.textContent || '').trim().length > 0) { overlaps = other; break; }
|
|
5093
|
+
}
|
|
5094
|
+
seenVictims.add(el);
|
|
5095
|
+
findings.push({
|
|
5096
|
+
el,
|
|
5097
|
+
type: 'text-occlusion',
|
|
5098
|
+
detail: `${classSelector(el)} is an inline element whose opaque fill leaks ${Math.round(rect.height)}px past its line${overlaps ? ` onto ${classSelector(overlaps)}` : ''}`,
|
|
5099
|
+
});
|
|
5100
|
+
}
|
|
5101
|
+
|
|
5102
|
+
return findings;
|
|
5103
|
+
}
|
|
5104
|
+
|
|
5105
|
+
// ---------------------------------------------------------------------------
|
|
5106
|
+
// First-viewport column overflow — the stretched-hero signature (browser-only)
|
|
5107
|
+
// ---------------------------------------------------------------------------
|
|
5108
|
+
|
|
5109
|
+
// A multi-column composition that opens the page (grid/flex with two or more
|
|
5110
|
+
// side-by-side columns, each a real share of the width) where one column's
|
|
5111
|
+
// content runs far past the fold while its sibling fits inside a single
|
|
5112
|
+
// viewport. The row stretches to the tall column, so the short one floats in a
|
|
5113
|
+
// screen-and-a-half of dead space and the fold falls deep inside a single
|
|
5114
|
+
// section. Single-column pages and full-page heroes (no sibling column) are
|
|
5115
|
+
// exempt because there is no fitting sibling to contrast against.
|
|
5116
|
+
function checkFirstViewportColumnOverflowDOM() {
|
|
5117
|
+
const findings = [];
|
|
5118
|
+
const vw = window.innerWidth || 1280;
|
|
5119
|
+
const vh = window.innerHeight || 800;
|
|
5120
|
+
const isMultiCol = (s) => /(^|inline-)(grid|flex)$/.test(String(s.display || ''));
|
|
5121
|
+
|
|
5122
|
+
for (const el of document.querySelectorAll('body *')) {
|
|
5123
|
+
const style = getComputedStyle(el);
|
|
5124
|
+
if (!isMultiCol(style)) continue;
|
|
5125
|
+
let rect; try { rect = el.getBoundingClientRect(); } catch { continue; }
|
|
5126
|
+
if (rect.width < 0.5 * vw) continue;
|
|
5127
|
+
const pageTop = rect.top + (window.scrollY || 0);
|
|
5128
|
+
const pageBottom = pageTop + rect.height;
|
|
5129
|
+
// The fold must fall inside this container: it opens within the first
|
|
5130
|
+
// viewport and runs past it.
|
|
5131
|
+
if (pageTop >= vh * 0.9 || pageBottom <= vh) continue;
|
|
5132
|
+
|
|
5133
|
+
// Direct children that read as side-by-side columns: a real width share,
|
|
5134
|
+
// not full-bleed (stacked single column), sharing the container's top row.
|
|
5135
|
+
const cols = [];
|
|
5136
|
+
for (const child of el.children) {
|
|
5137
|
+
const cs = getComputedStyle(child);
|
|
5138
|
+
if (cs.display === 'none') continue;
|
|
5139
|
+
if (String(cs.position || '') === 'absolute' || String(cs.position || '') === 'fixed') continue;
|
|
5140
|
+
let cr; try { cr = child.getBoundingClientRect(); } catch { continue; }
|
|
5141
|
+
const wShare = cr.width / rect.width;
|
|
5142
|
+
if (wShare < 0.25 || wShare > 0.9) continue;
|
|
5143
|
+
if (cr.height < 40) continue;
|
|
5144
|
+
// Content extent: how far the child's own content actually reaches,
|
|
5145
|
+
// independent of a stretched row height.
|
|
5146
|
+
let contentBottom = cr.top;
|
|
5147
|
+
for (const d of child.querySelectorAll('*')) {
|
|
5148
|
+
const ds = getComputedStyle(d);
|
|
5149
|
+
if (ds.position === 'absolute' || ds.position === 'fixed') continue;
|
|
5150
|
+
if (ds.display === 'none' || ds.visibility === 'hidden') continue;
|
|
5151
|
+
let dr; try { dr = d.getBoundingClientRect(); } catch { continue; }
|
|
5152
|
+
if (dr.width > 0 && dr.height > 0) contentBottom = Math.max(contentBottom, dr.bottom);
|
|
5153
|
+
}
|
|
5154
|
+
cols.push({ child, top: cr.top, contentH: contentBottom - cr.top });
|
|
5155
|
+
}
|
|
5156
|
+
if (cols.length < 2) continue;
|
|
5157
|
+
// Side-by-side: the two candidate columns must share the top row.
|
|
5158
|
+
cols.sort((a, b) => b.contentH - a.contentH);
|
|
5159
|
+
const tall = cols[0];
|
|
5160
|
+
const shortest = cols[cols.length - 1];
|
|
5161
|
+
if (Math.abs(tall.top - shortest.top) > 0.25 * vh) continue;
|
|
5162
|
+
if (tall.contentH <= vh * 1.4) continue;
|
|
5163
|
+
if (shortest.contentH > vh) continue;
|
|
5164
|
+
|
|
5165
|
+
findings.push({
|
|
5166
|
+
el,
|
|
5167
|
+
type: 'first-viewport-column-overflow',
|
|
5168
|
+
detail: `${classSelector(el)} opens the page with one column running ${Math.round(tall.contentH / vh * 100)}% of the viewport tall while a sibling fits in ${Math.round(shortest.contentH / vh * 100)}% — the fold falls deep inside the section`,
|
|
5169
|
+
});
|
|
5170
|
+
}
|
|
5171
|
+
return findings;
|
|
5172
|
+
}
|
|
5173
|
+
|
|
2632
5174
|
export {
|
|
2633
5175
|
checkBorders,
|
|
2634
5176
|
isEmojiOnlyText,
|
|
2635
5177
|
checkColors,
|
|
5178
|
+
checkHoverContrast,
|
|
5179
|
+
checkElementHoverContrast,
|
|
5180
|
+
parseColorMix,
|
|
5181
|
+
compositeColorOver,
|
|
2636
5182
|
isCardLikeFromProps,
|
|
2637
5183
|
checkIconTile,
|
|
2638
5184
|
resolveSerif,
|
|
@@ -2642,6 +5188,17 @@ export {
|
|
|
2642
5188
|
checkRepeatedSectionKickers,
|
|
2643
5189
|
checkMotion,
|
|
2644
5190
|
checkGlow,
|
|
5191
|
+
scanCssTextForGlow,
|
|
5192
|
+
scanCssTextForGridBackground,
|
|
5193
|
+
scanCssTextForRadialHalo,
|
|
5194
|
+
scanCssTextForPseudoStripe,
|
|
5195
|
+
scanCssTextForInsetStripe,
|
|
5196
|
+
scanCssTextForMarquee,
|
|
5197
|
+
collectMarqueeKeyframes,
|
|
5198
|
+
collectCssCustomProps,
|
|
5199
|
+
cssLengthToPx,
|
|
5200
|
+
scanCssTextForPulsingDot,
|
|
5201
|
+
scanHtmlForShapeAssembledIllustration,
|
|
2645
5202
|
checkHtmlPatterns,
|
|
2646
5203
|
readOwnBackgroundColor,
|
|
2647
5204
|
resolveBackground,
|
|
@@ -2662,6 +5219,19 @@ export {
|
|
|
2662
5219
|
isRepeatedKickerCandidate,
|
|
2663
5220
|
collectRepeatedSectionKickerCandidates,
|
|
2664
5221
|
checkRepeatedSectionKickersDOM,
|
|
5222
|
+
parseNumberedLabelText,
|
|
5223
|
+
isNumberedSectionLabelCandidate,
|
|
5224
|
+
collectNumberedSectionLabelCandidates,
|
|
5225
|
+
checkNumberedSectionLabels,
|
|
5226
|
+
checkNumberedSectionLabelsFromDoc,
|
|
5227
|
+
checkNumberedSectionLabelsDOM,
|
|
5228
|
+
checkEmDashOveruse,
|
|
5229
|
+
checkEmDashOveruseDOM,
|
|
5230
|
+
isRepeatedTextContainer,
|
|
5231
|
+
collectRepeatedContainerTextFindings,
|
|
5232
|
+
checkRepeatedContainerTextFromDoc,
|
|
5233
|
+
checkRepeatedContainerTextDOM,
|
|
5234
|
+
checkElementPseudoStripeDOM,
|
|
2665
5235
|
checkElementMotionDOM,
|
|
2666
5236
|
checkElementGlowDOM,
|
|
2667
5237
|
checkElementAIPaletteDOM,
|
|
@@ -2700,4 +5270,13 @@ export {
|
|
|
2700
5270
|
checkElementClippedOverflowDOM,
|
|
2701
5271
|
isScreenReaderOnlyTextStyle,
|
|
2702
5272
|
checkElementTextOverflowDOM,
|
|
5273
|
+
checkHeadingRhythmDOM,
|
|
5274
|
+
checkElementBlinkingCursorDOM,
|
|
5275
|
+
measureHiddenTextDOM,
|
|
5276
|
+
checkContentHiddenAtRest,
|
|
5277
|
+
checkEdgeFlushCardsDOM,
|
|
5278
|
+
isOpaqueDecoratedBox,
|
|
5279
|
+
isLayeredElement,
|
|
5280
|
+
checkTextOcclusionDOM,
|
|
5281
|
+
checkFirstViewportColumnOverflowDOM,
|
|
2703
5282
|
};
|