impeccable 2.1.8 → 2.1.9
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 +1 -1
- package/README.npm.md +1 -1
- package/README.repo.md +38 -16
- package/{bin → cli/bin}/cli.js +3 -3
- package/{bin → cli/bin}/commands/skills.mjs +5 -5
- package/{src → cli/engine}/detect-antipatterns-browser.js +713 -36
- package/{src → cli/engine}/detect-antipatterns.mjs +819 -43
- package/cli/lib/download-providers.js +25 -0
- package/package.json +15 -11
|
@@ -61,7 +61,13 @@ const BORDER_SAFE_TAGS = new Set(
|
|
|
61
61
|
);
|
|
62
62
|
|
|
63
63
|
const OVERUSED_FONTS = new Set([
|
|
64
|
+
// Older monoculture (still ubiquitous):
|
|
64
65
|
'inter', 'roboto', 'open sans', 'lato', 'montserrat', 'arial', 'helvetica',
|
|
66
|
+
// Newer monoculture (the Anthropic-skill / Vercel / GitHub default wave):
|
|
67
|
+
'fraunces', 'instrument sans',
|
|
68
|
+
'geist', 'geist sans', 'geist mono',
|
|
69
|
+
'mona sans',
|
|
70
|
+
'plus jakarta sans', 'space grotesk', 'recoleta',
|
|
65
71
|
]);
|
|
66
72
|
|
|
67
73
|
// Brand-associated fonts: don't flag these as "overused" on the brand's own domains.
|
|
@@ -70,10 +76,16 @@ const GOOGLE_DOMAINS = [
|
|
|
70
76
|
'google.com', 'youtube.com', 'android.com', 'chromium.org',
|
|
71
77
|
'chrome.com', 'web.dev', 'gstatic.com', 'firebase.google.com',
|
|
72
78
|
];
|
|
79
|
+
const VERCEL_DOMAINS = ['vercel.com', 'nextjs.org', 'v0.app'];
|
|
80
|
+
const GITHUB_DOMAINS = ['github.com', 'githubnext.com'];
|
|
73
81
|
const BRAND_FONT_DOMAINS = {
|
|
74
82
|
'roboto': GOOGLE_DOMAINS,
|
|
75
83
|
'google sans': GOOGLE_DOMAINS,
|
|
76
84
|
'product sans': GOOGLE_DOMAINS,
|
|
85
|
+
'geist': VERCEL_DOMAINS,
|
|
86
|
+
'geist sans': VERCEL_DOMAINS,
|
|
87
|
+
'geist mono': VERCEL_DOMAINS,
|
|
88
|
+
'mona sans': GITHUB_DOMAINS,
|
|
77
89
|
};
|
|
78
90
|
|
|
79
91
|
function isBrandFontOnOwnDomain(font) {
|
|
@@ -91,6 +103,23 @@ const GENERIC_FONTS = new Set([
|
|
|
91
103
|
'inherit', 'initial', 'unset', 'revert',
|
|
92
104
|
]);
|
|
93
105
|
|
|
106
|
+
// Serif faces that show up in italic-display heroes. The rule also fires when
|
|
107
|
+
// the primary face is unknown but the stack ends in the generic `serif` token,
|
|
108
|
+
// which catches custom/private faces with a serif fallback.
|
|
109
|
+
const KNOWN_SERIF_FONTS = new Set([
|
|
110
|
+
'fraunces', 'recoleta', 'newsreader', 'playfair display', 'playfair',
|
|
111
|
+
'cormorant', 'cormorant garamond', 'garamond', 'eb garamond',
|
|
112
|
+
'tiempos', 'tiempos headline', 'tiempos text',
|
|
113
|
+
'lora', 'vollkorn', 'spectral',
|
|
114
|
+
'source serif pro', 'source serif 4', 'source serif',
|
|
115
|
+
'ibm plex serif', 'merriweather',
|
|
116
|
+
'libre caslon', 'libre baskerville', 'baskerville',
|
|
117
|
+
'georgia', 'times new roman', 'times',
|
|
118
|
+
'dm serif display', 'dm serif text',
|
|
119
|
+
'instrument serif', 'gt sectra', 'ogg', 'canela',
|
|
120
|
+
'freight display', 'freight text',
|
|
121
|
+
]);
|
|
122
|
+
|
|
94
123
|
const ANTIPATTERNS = [
|
|
95
124
|
// ── AI slop: tells that something was AI-generated ──
|
|
96
125
|
{
|
|
@@ -116,7 +145,7 @@ const ANTIPATTERNS = [
|
|
|
116
145
|
category: 'slop',
|
|
117
146
|
name: 'Overused font',
|
|
118
147
|
description:
|
|
119
|
-
'Inter, Roboto,
|
|
148
|
+
'Inter, Roboto, Fraunces, Geist, Plus Jakarta Sans, and Space Grotesk are used on so many sites they no longer feel distinctive. Each new wave of AI-generated UIs converges on the same handful of faces. Choose a face that gives your interface personality.',
|
|
120
149
|
skillSection: 'Typography',
|
|
121
150
|
skillGuideline: 'overused fonts like Inter',
|
|
122
151
|
},
|
|
@@ -210,6 +239,34 @@ const ANTIPATTERNS = [
|
|
|
210
239
|
skillSection: 'Typography',
|
|
211
240
|
skillGuideline: 'large icons with rounded corners above every heading',
|
|
212
241
|
},
|
|
242
|
+
{
|
|
243
|
+
id: 'italic-serif-display',
|
|
244
|
+
category: 'slop',
|
|
245
|
+
name: 'Italic serif display headline',
|
|
246
|
+
description:
|
|
247
|
+
'Oversized italic serif (Fraunces, Recoleta, Playfair, Newsreader-italic) as the primary hero headline reads as taste in isolation but has become the universal AI-startup landing page hero. Set roman, or move to a non-serif display face. Editorial / magazine register may legitimately want this — judge by context.',
|
|
248
|
+
skillSection: 'Typography',
|
|
249
|
+
skillGuideline: 'oversized italic serif as the hero headline',
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
id: 'hero-eyebrow-chip',
|
|
253
|
+
category: 'slop',
|
|
254
|
+
name: 'Hero eyebrow / pill chip',
|
|
255
|
+
description:
|
|
256
|
+
'A tiny uppercase letter-spaced label sitting immediately above an oversized hero headline — or the same shape rendered as a pill chip — is now the default AI SaaS hero. Drop the eyebrow, integrate the kicker into the headline, or run it as a navigation breadcrumb instead.',
|
|
257
|
+
skillSection: 'Typography',
|
|
258
|
+
skillGuideline: 'tiny uppercase tracked label above the hero headline',
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
id: 'repeated-section-kickers',
|
|
262
|
+
category: 'slop',
|
|
263
|
+
severity: 'advisory',
|
|
264
|
+
name: 'Repeated section kicker labels',
|
|
265
|
+
description:
|
|
266
|
+
'Repeating tiny uppercase tracked labels above section headings turns a brand page into AI editorial scaffolding. Replace them with stronger structure, artifacts, imagery, or a deliberate brand system.',
|
|
267
|
+
skillSection: 'Typography',
|
|
268
|
+
skillGuideline: 'repeated eyebrow or kicker labels as section scaffolding',
|
|
269
|
+
},
|
|
213
270
|
|
|
214
271
|
// ── Quality: general design and accessibility issues ──
|
|
215
272
|
{
|
|
@@ -262,6 +319,13 @@ const ANTIPATTERNS = [
|
|
|
262
319
|
description:
|
|
263
320
|
'Text is too close to the edge of its container. Add at least 8px (ideally 12-16px) of padding inside bordered or colored containers.',
|
|
264
321
|
},
|
|
322
|
+
{
|
|
323
|
+
id: 'body-text-viewport-edge',
|
|
324
|
+
category: 'quality',
|
|
325
|
+
name: 'Body text touching viewport edge',
|
|
326
|
+
description:
|
|
327
|
+
'Body paragraphs render flush against the left or right viewport edge with no container providing horizontal padding. Wrap content in a container with at least 16px (ideally 24-32px) of horizontal padding, or apply max-width with mx-auto.',
|
|
328
|
+
},
|
|
265
329
|
{
|
|
266
330
|
id: 'tight-leading',
|
|
267
331
|
category: 'quality',
|
|
@@ -465,7 +529,18 @@ function isEmojiOnlyText(text) {
|
|
|
465
529
|
|
|
466
530
|
function checkColors(opts) {
|
|
467
531
|
const { tag, textColor, bgColor, effectiveBg, effectiveBgStops, fontSize, fontWeight, hasDirectText, isEmojiOnly, bgClip, bgImage, classList } = opts;
|
|
468
|
-
if (SAFE_TAGS.has(tag))
|
|
532
|
+
if (SAFE_TAGS.has(tag)) {
|
|
533
|
+
// Exception for <a> and <button> elements styled as buttons. SAFE_TAGS
|
|
534
|
+
// exists to suppress contrast noise on inline links and unstyled controls,
|
|
535
|
+
// where the element has no own background and the contrast against the
|
|
536
|
+
// ancestor surface is already the intended visual. When the element has
|
|
537
|
+
// its own opaque background and direct text, it is a styled button — and
|
|
538
|
+
// contrast on its own surface is a real, frequent bug worth flagging.
|
|
539
|
+
const isStyledButton = (tag === 'a' || tag === 'button')
|
|
540
|
+
&& hasDirectText
|
|
541
|
+
&& bgColor && bgColor.a > 0.5;
|
|
542
|
+
if (!isStyledButton) return [];
|
|
543
|
+
}
|
|
469
544
|
const findings = [];
|
|
470
545
|
|
|
471
546
|
// Pure black background (only solid or near-solid, not semi-transparent overlays)
|
|
@@ -495,7 +570,20 @@ function checkColors(opts) {
|
|
|
495
570
|
const isLargeText = fontSize >= 18 || (fontSize >= 14 && fontWeight >= 700) || isHeading;
|
|
496
571
|
const threshold = isLargeText ? 3.0 : 4.5;
|
|
497
572
|
if (ratio < threshold) {
|
|
498
|
-
|
|
573
|
+
// Skip the false-positive class where text has alpha < 1 AND we
|
|
574
|
+
// couldn't find an opaque ancestor (effectiveBg is null, we're
|
|
575
|
+
// comparing against gradient-stop fallback). In jsdom mode the
|
|
576
|
+
// detector can't resolve `var(--X)` color tokens, so a dark
|
|
577
|
+
// section sitting between the text and the body's decorative
|
|
578
|
+
// gradient is invisible to us — we end up measuring contrast
|
|
579
|
+
// against the body's paper-grain noise instead of the real
|
|
580
|
+
// local bg. Real low-contrast bugs use alpha=1 and have a
|
|
581
|
+
// resolvable opaque ancestor; semi-transparent Tailwind tokens
|
|
582
|
+
// like `text-paper/60` on `bg-ink` sections are the FP pattern.
|
|
583
|
+
const isAlphaFallbackFP = !IS_BROWSER && !effectiveBg && (textColor.a != null && textColor.a < 1);
|
|
584
|
+
if (!isAlphaFallbackFP) {
|
|
585
|
+
findings.push({ id: 'low-contrast', snippet: `${ratio.toFixed(1)}:1 (need ${threshold}:1) — text ${colorToHex(textColor)} on ${colorToHex(bgs[worstIdx])}` });
|
|
586
|
+
}
|
|
499
587
|
}
|
|
500
588
|
}
|
|
501
589
|
|
|
@@ -604,6 +692,150 @@ function checkIconTile(opts) {
|
|
|
604
692
|
}];
|
|
605
693
|
}
|
|
606
694
|
|
|
695
|
+
// Resolve the primary (non-generic) face from a font-family string and return
|
|
696
|
+
// whether the resolved primary is serif. Two paths:
|
|
697
|
+
// 1. Primary face is in KNOWN_SERIF_FONTS → serif.
|
|
698
|
+
// 2. Primary face is unknown but the stack ends in the generic `serif`
|
|
699
|
+
// token → treat as serif. Authors who declare `font-family: 'X', serif`
|
|
700
|
+
// almost always have a serif primary; a sans declared with a serif
|
|
701
|
+
// fallback is a code smell, not the common case.
|
|
702
|
+
// Returns { primary, isSerif } so the snippet can name the face.
|
|
703
|
+
function resolveSerif(fontFamily) {
|
|
704
|
+
if (!fontFamily) return { primary: null, isSerif: false };
|
|
705
|
+
const tokens = fontFamily.split(',').map(f => f.trim().replace(/^['"]|['"]$/g, '').toLowerCase());
|
|
706
|
+
const primary = tokens.find(f => f && !GENERIC_FONTS.has(f)) || null;
|
|
707
|
+
if (!primary) return { primary: null, isSerif: false };
|
|
708
|
+
if (KNOWN_SERIF_FONTS.has(primary)) return { primary, isSerif: true };
|
|
709
|
+
if (tokens.includes('serif')) return { primary, isSerif: true };
|
|
710
|
+
return { primary, isSerif: false };
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function checkItalicSerif(opts) {
|
|
714
|
+
const { tag, fontStyle, fontFamily, fontSize, headingText } = opts;
|
|
715
|
+
if (fontStyle !== 'italic') return [];
|
|
716
|
+
// Anchor the rule on hero-scale text. h1 is the canonical hero element;
|
|
717
|
+
// h2 ≥ 48px catches the cases where the design demotes the visual hero
|
|
718
|
+
// to an h2 but keeps the size.
|
|
719
|
+
if (tag !== 'h1' && !(tag === 'h2' && fontSize >= 48)) return [];
|
|
720
|
+
if (fontSize < 48) return [];
|
|
721
|
+
const { primary, isSerif } = resolveSerif(fontFamily);
|
|
722
|
+
if (!isSerif) return [];
|
|
723
|
+
|
|
724
|
+
const text = (headingText || '').trim().slice(0, 60);
|
|
725
|
+
return [{
|
|
726
|
+
id: 'italic-serif-display',
|
|
727
|
+
snippet: `italic serif ${tag} (${primary || 'serif'}) at ${Math.round(fontSize)}px "${text}"`,
|
|
728
|
+
}];
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// Color saturation check. Returns true when the color has visible
|
|
732
|
+
// chroma — i.e., it's an "accent color" rather than near-neutral.
|
|
733
|
+
// Handles rgb()/rgba(), #hex, oklch(), and hsl(). var() refs are
|
|
734
|
+
// expected to be pre-resolved by the caller.
|
|
735
|
+
function isAccentColor(cssColor) {
|
|
736
|
+
if (!cssColor) return false;
|
|
737
|
+
const s = String(cssColor).trim();
|
|
738
|
+
// rgb / rgba — direct channel-distance check.
|
|
739
|
+
const rgbM = /rgba?\(\s*(\d+)\s*,?\s+|\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/.exec(s.replace(/rgba?\(\s*/, 'rgb(').replace(/,/g, ', '));
|
|
740
|
+
const rgbStrict = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/.exec(s);
|
|
741
|
+
if (rgbStrict) {
|
|
742
|
+
const r = +rgbStrict[1], g = +rgbStrict[2], b = +rgbStrict[3];
|
|
743
|
+
return (Math.max(r, g, b) - Math.min(r, g, b)) >= 40;
|
|
744
|
+
}
|
|
745
|
+
// #hex — 3, 4, 6, or 8 digit.
|
|
746
|
+
const hexM = /^#([0-9a-f]{3,8})\b/i.exec(s);
|
|
747
|
+
if (hexM) {
|
|
748
|
+
let h = hexM[1];
|
|
749
|
+
if (h.length === 3 || h.length === 4) h = h.split('').map((c) => c + c).join('').slice(0, 6);
|
|
750
|
+
else h = h.slice(0, 6);
|
|
751
|
+
if (h.length === 6) {
|
|
752
|
+
const r = parseInt(h.slice(0, 2), 16);
|
|
753
|
+
const g = parseInt(h.slice(2, 4), 16);
|
|
754
|
+
const b = parseInt(h.slice(4, 6), 16);
|
|
755
|
+
return (Math.max(r, g, b) - Math.min(r, g, b)) >= 40;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
// oklch(L C H) — chroma C is what matters. Typical neutral grays
|
|
759
|
+
// have C < 0.02; visible accents are 0.05+. CSS minification can
|
|
760
|
+
// collapse spaces between L% and C ("oklch(43%.15 34)"), so we
|
|
761
|
+
// extract all numbers and take the second rather than matching a
|
|
762
|
+
// strict L-then-whitespace-then-C pattern.
|
|
763
|
+
if (/^oklch\(/i.test(s)) {
|
|
764
|
+
const nums = s.match(/\d*\.\d+|\d+/g);
|
|
765
|
+
if (nums && nums.length >= 2) {
|
|
766
|
+
const c = parseFloat(nums[1]);
|
|
767
|
+
return !Number.isNaN(c) && c >= 0.05;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
// hsl(H, S%, L%) — saturation > 20% reads as accent.
|
|
771
|
+
const hslM = /hsla?\(\s*[\d.]+\s*,\s*([\d.]+)%/i.exec(s);
|
|
772
|
+
if (hslM) {
|
|
773
|
+
const sat = parseFloat(hslM[1]);
|
|
774
|
+
return !Number.isNaN(sat) && sat >= 20;
|
|
775
|
+
}
|
|
776
|
+
return false;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// Sibling-relationship rule. Anchor on a hero-scale h1, look at the
|
|
780
|
+
// previousElementSibling, and gate on EITHER the classic tracked-
|
|
781
|
+
// uppercase eyebrow OR the modern accent-colored bold eyebrow.
|
|
782
|
+
function checkHeroEyebrow(opts) {
|
|
783
|
+
const {
|
|
784
|
+
headingTag, headingText, headingFontSize,
|
|
785
|
+
siblingTag, siblingText, siblingTextTransform,
|
|
786
|
+
siblingFontSize, siblingLetterSpacing,
|
|
787
|
+
siblingFontWeight, siblingColor,
|
|
788
|
+
} = opts;
|
|
789
|
+
if (headingTag !== 'h1') return [];
|
|
790
|
+
// We previously gated on headingFontSize >= 48 to anchor "hero scale".
|
|
791
|
+
// But modern hero h1s use clamp() / vw / var(--text-*), none of which
|
|
792
|
+
// jsdom can resolve — the computed value comes back as "2em" or
|
|
793
|
+
// "var(--text-9xl)" and parseFloat returns 2 or NaN. The gate fails
|
|
794
|
+
// on virtually every Tailwind v4 / framework build. The other gates
|
|
795
|
+
// (sibling text 2-60 chars, font-size ≤ 14px, accent-bold OR
|
|
796
|
+
// tracked-caps) are tight enough to avoid false positives on non-
|
|
797
|
+
// hero h1s — a tiny tan label directly above any h1 is the
|
|
798
|
+
// antipattern regardless of how big the h1 ends up.
|
|
799
|
+
if (!siblingTag) return [];
|
|
800
|
+
// An h2 above an h1 is a different anti-pattern (heading hierarchy / dual
|
|
801
|
+
// headings) — never an eyebrow.
|
|
802
|
+
if (HEADING_TAGS.has(siblingTag)) return [];
|
|
803
|
+
|
|
804
|
+
const text = (siblingText || '').trim();
|
|
805
|
+
if (text.length < 2 || text.length > 60) return [];
|
|
806
|
+
if (!(siblingFontSize > 0 && siblingFontSize <= 14)) return [];
|
|
807
|
+
|
|
808
|
+
// Branch A: classic tracked-uppercase eyebrow.
|
|
809
|
+
const isUppercased = siblingTextTransform === 'uppercase'
|
|
810
|
+
|| (/[A-Z]/.test(text) && !/[a-z]/.test(text));
|
|
811
|
+
const isClassicTracked = isUppercased && siblingLetterSpacing >= 1.6;
|
|
812
|
+
|
|
813
|
+
// Branch B: modern accent-bold eyebrow — sentence case, low
|
|
814
|
+
// tracking, but bold + accent-colored. The style choices changed;
|
|
815
|
+
// the pattern is the same kicker-above-headline anti-pattern.
|
|
816
|
+
const weight = Number(siblingFontWeight) || 400;
|
|
817
|
+
const isAccentBold = weight >= 700 && isAccentColor(siblingColor || '');
|
|
818
|
+
|
|
819
|
+
if (!isClassicTracked && !isAccentBold) return [];
|
|
820
|
+
|
|
821
|
+
const headingTextSnippet = (headingText || '').trim().slice(0, 60);
|
|
822
|
+
const eyebrowSnippet = text.slice(0, 40);
|
|
823
|
+
const style = isClassicTracked ? 'tracked-caps' : 'accent-bold';
|
|
824
|
+
return [{
|
|
825
|
+
id: 'hero-eyebrow-chip',
|
|
826
|
+
snippet: `eyebrow chip (${style}) "${eyebrowSnippet}" above ${headingTag} "${headingTextSnippet}"`,
|
|
827
|
+
}];
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
function checkRepeatedSectionKickers(opts) {
|
|
831
|
+
const { candidates, minCount = 3 } = opts;
|
|
832
|
+
if (!Array.isArray(candidates) || candidates.length < minCount) return [];
|
|
833
|
+
return candidates.map(candidate => ({
|
|
834
|
+
id: 'repeated-section-kickers',
|
|
835
|
+
snippet: `repeated section kicker "${candidate.kickerText}" before ${candidate.headingTag} "${candidate.headingText}" (${candidates.length} on page)`,
|
|
836
|
+
}));
|
|
837
|
+
}
|
|
838
|
+
|
|
607
839
|
const LAYOUT_TRANSITION_PROPS = new Set([
|
|
608
840
|
'width', 'height', 'padding', 'margin',
|
|
609
841
|
'max-height', 'max-width', 'min-height', 'min-width',
|
|
@@ -817,43 +1049,88 @@ function checkHtmlPatterns(html) {
|
|
|
817
1049
|
|
|
818
1050
|
// ─── Section 4: resolveBackground (unified) ─────────────────────────────────
|
|
819
1051
|
|
|
820
|
-
|
|
1052
|
+
// Read the element's own background color, computed-style first, with a
|
|
1053
|
+
// jsdom-friendly fallback that parses the inline `background:` shorthand
|
|
1054
|
+
// from the raw style attribute. jsdom (~v29) does not decompose the
|
|
1055
|
+
// shorthand into `backgroundColor`, so without this fallback the CLI silently
|
|
1056
|
+
// returns null for any element styled via `background: rgb(...)` or
|
|
1057
|
+
// `background: #abc`. Real browsers always decompose, so the fallback is
|
|
1058
|
+
// a no-op there.
|
|
1059
|
+
function readOwnBackgroundColor(el, computedStyle) {
|
|
1060
|
+
const bg = parseRgb(computedStyle.backgroundColor);
|
|
1061
|
+
if (IS_BROWSER || (bg && bg.a >= 0.1)) return bg;
|
|
1062
|
+
const rawStyle = el.getAttribute?.('style') || '';
|
|
1063
|
+
const bgMatch = rawStyle.match(/background(?:-color)?\s*:\s*([^;]+)/i);
|
|
1064
|
+
const inlineBg = bgMatch ? bgMatch[1].trim() : '';
|
|
1065
|
+
if (!inlineBg) return bg;
|
|
1066
|
+
if (/gradient/i.test(inlineBg) || /url\s*\(/i.test(inlineBg)) return bg;
|
|
1067
|
+
const fromRgb = parseRgb(inlineBg);
|
|
1068
|
+
if (fromRgb) return fromRgb;
|
|
1069
|
+
const hexMatch = inlineBg.match(/#([0-9a-f]{6}|[0-9a-f]{3})\b/i);
|
|
1070
|
+
if (hexMatch) {
|
|
1071
|
+
const h = hexMatch[1];
|
|
1072
|
+
if (h.length === 6) {
|
|
1073
|
+
return { r: parseInt(h.slice(0, 2), 16), g: parseInt(h.slice(2, 4), 16), b: parseInt(h.slice(4, 6), 16), a: 1 };
|
|
1074
|
+
}
|
|
1075
|
+
return { r: parseInt(h[0] + h[0], 16), g: parseInt(h[1] + h[1], 16), b: parseInt(h[2] + h[2], 16), a: 1 };
|
|
1076
|
+
}
|
|
1077
|
+
return bg;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
function resolveBackground(el, win, customPropMap) {
|
|
821
1081
|
let current = el;
|
|
822
1082
|
while (current && current.nodeType === 1) {
|
|
823
1083
|
const style = IS_BROWSER ? getComputedStyle(current) : win.getComputedStyle(current);
|
|
824
|
-
|
|
825
|
-
// If this element has a background-image (gradient or url), it's visually
|
|
826
|
-
// opaque but we can't determine the effective color — bail out so callers
|
|
827
|
-
// don't get a false solid-color answer.
|
|
828
1084
|
const bgImage = style.backgroundImage || '';
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
1085
|
+
const hasGradientOrUrl = bgImage && bgImage !== 'none' && (/gradient/i.test(bgImage) || /url\s*\(/i.test(bgImage));
|
|
1086
|
+
|
|
1087
|
+
// Try the solid bg-color FIRST. If the element has both a solid color
|
|
1088
|
+
// and a gradient/url overlay (a common pattern: `background: var(--paper)
|
|
1089
|
+
// radial-gradient(...)` for paper-grain texture), the solid color is the
|
|
1090
|
+
// dominant visible surface for contrast purposes; the overlay is
|
|
1091
|
+
// decorative. The old behavior bailed on any gradient ancestor, which
|
|
1092
|
+
// caused massive false-positive contrast findings on grain-textured
|
|
1093
|
+
// body backgrounds.
|
|
833
1094
|
let bg = parseRgb(style.backgroundColor);
|
|
834
1095
|
if (!IS_BROWSER && (!bg || bg.a < 0.1)) {
|
|
835
|
-
// jsdom
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
if (
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
const
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
} else {
|
|
849
|
-
bg = { r: parseInt(h[0]+h[0], 16), g: parseInt(h[1]+h[1], 16), b: parseInt(h[2]+h[2], 16), a: 1 };
|
|
850
|
-
}
|
|
1096
|
+
// jsdom returns literal "var(--X)" / "oklch(...)" strings. Resolve
|
|
1097
|
+
// through customPropMap so Tailwind v4 color tokens become RGB.
|
|
1098
|
+
if (customPropMap) {
|
|
1099
|
+
bg = parseColorResolved(style.backgroundColor, customPropMap);
|
|
1100
|
+
}
|
|
1101
|
+
if (!bg || bg.a < 0.1) {
|
|
1102
|
+
// Inline-style fallback. jsdom doesn't decompose background
|
|
1103
|
+
// shorthand, so colors set via inline style are otherwise invisible.
|
|
1104
|
+
const rawStyle = current.getAttribute?.('style') || '';
|
|
1105
|
+
const bgMatch = rawStyle.match(/background(?:-color)?\s*:\s*([^;]+)/i);
|
|
1106
|
+
const inlineBg = bgMatch ? bgMatch[1].trim() : '';
|
|
1107
|
+
if (inlineBg && !/gradient/i.test(inlineBg) && !/url\s*\(/i.test(inlineBg)) {
|
|
1108
|
+
bg = parseColorResolved(inlineBg, customPropMap) || parseAnyColor(inlineBg);
|
|
851
1109
|
}
|
|
852
1110
|
}
|
|
853
1111
|
}
|
|
1112
|
+
|
|
854
1113
|
if (bg && bg.a > 0.1) {
|
|
855
1114
|
if (IS_BROWSER || bg.a >= 0.5) return bg;
|
|
856
1115
|
}
|
|
1116
|
+
// No solid bg-color at this level. If THIS level has a gradient/url
|
|
1117
|
+
// with no underlying solid color we can read:
|
|
1118
|
+
// • on body/html: assume white. Body-level gradients are almost
|
|
1119
|
+
// always decorative texture (paper grain, noise) on top of a
|
|
1120
|
+
// solid bg-color the page set via `background: var(--paper)`
|
|
1121
|
+
// shorthand — which jsdom can't decompose into bg-color. The
|
|
1122
|
+
// downstream gradient-stops fallback path produces catastrophic
|
|
1123
|
+
// false positives in this case (gradient noise stops have
|
|
1124
|
+
// accidental browns/blacks that look like card backgrounds).
|
|
1125
|
+
// • on other elements: bail to null and let the caller fall back
|
|
1126
|
+
// to gradient stops (gradient buttons / hero sections are real
|
|
1127
|
+
// bgs worth checking against).
|
|
1128
|
+
if (hasGradientOrUrl) {
|
|
1129
|
+
if (current.tagName === 'BODY' || current.tagName === 'HTML') {
|
|
1130
|
+
return { r: 255, g: 255, b: 255, a: 1 };
|
|
1131
|
+
}
|
|
1132
|
+
return null;
|
|
1133
|
+
}
|
|
857
1134
|
current = current.parentElement;
|
|
858
1135
|
}
|
|
859
1136
|
return { r: 255, g: 255, b: 255 };
|
|
@@ -982,7 +1259,9 @@ function checkElementBordersDOM(el) {
|
|
|
982
1259
|
|
|
983
1260
|
function checkElementColorsDOM(el) {
|
|
984
1261
|
const tag = el.tagName.toLowerCase();
|
|
985
|
-
|
|
1262
|
+
// No early SAFE_TAGS bail here — checkColors() does its own gating that
|
|
1263
|
+
// includes the styled-button exception for <a> / <button> with their own
|
|
1264
|
+
// opaque background. Bailing here would prevent that exception from firing.
|
|
986
1265
|
const rect = el.getBoundingClientRect();
|
|
987
1266
|
if (rect.width < 10 || rect.height < 10) return [];
|
|
988
1267
|
const style = getComputedStyle(el);
|
|
@@ -992,7 +1271,7 @@ function checkElementColorsDOM(el) {
|
|
|
992
1271
|
return checkColors({
|
|
993
1272
|
tag,
|
|
994
1273
|
textColor: parseRgb(style.color),
|
|
995
|
-
bgColor:
|
|
1274
|
+
bgColor: readOwnBackgroundColor(el, style),
|
|
996
1275
|
effectiveBg,
|
|
997
1276
|
effectiveBgStops: effectiveBg ? null : resolveGradientStops(el),
|
|
998
1277
|
fontSize: parseFloat(style.fontSize) || 16,
|
|
@@ -1040,6 +1319,274 @@ function checkElementIconTileDOM(el) {
|
|
|
1040
1319
|
});
|
|
1041
1320
|
}
|
|
1042
1321
|
|
|
1322
|
+
function checkElementItalicSerifDOM(el) {
|
|
1323
|
+
const tag = el.tagName.toLowerCase();
|
|
1324
|
+
if (tag !== 'h1' && tag !== 'h2') return [];
|
|
1325
|
+
const style = getComputedStyle(el);
|
|
1326
|
+
return checkItalicSerif({
|
|
1327
|
+
tag,
|
|
1328
|
+
fontStyle: style.fontStyle || '',
|
|
1329
|
+
fontFamily: style.fontFamily || '',
|
|
1330
|
+
fontSize: parseFloat(style.fontSize) || 0,
|
|
1331
|
+
headingText: el.textContent || '',
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
function checkElementHeroEyebrowDOM(el) {
|
|
1336
|
+
const tag = el.tagName.toLowerCase();
|
|
1337
|
+
if (tag !== 'h1') return [];
|
|
1338
|
+
const sibling = el.previousElementSibling;
|
|
1339
|
+
if (!sibling) return [];
|
|
1340
|
+
const headStyle = getComputedStyle(el);
|
|
1341
|
+
const sibStyle = getComputedStyle(sibling);
|
|
1342
|
+
return checkHeroEyebrow({
|
|
1343
|
+
headingTag: tag,
|
|
1344
|
+
headingText: el.textContent || '',
|
|
1345
|
+
headingFontSize: parseFloat(headStyle.fontSize) || 0,
|
|
1346
|
+
siblingTag: sibling.tagName.toLowerCase(),
|
|
1347
|
+
siblingText: sibling.textContent || '',
|
|
1348
|
+
siblingTextTransform: sibStyle.textTransform || '',
|
|
1349
|
+
siblingFontSize: parseFloat(sibStyle.fontSize) || 0,
|
|
1350
|
+
siblingLetterSpacing: parseFloat(sibStyle.letterSpacing) || 0,
|
|
1351
|
+
siblingFontWeight: sibStyle.fontWeight || '',
|
|
1352
|
+
siblingColor: sibStyle.color || '',
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
// Build a map of CSS custom properties declared on :root / :host / html.
|
|
1357
|
+
// Used to resolve var(--X) refs that jsdom returns verbatim in
|
|
1358
|
+
// getComputedStyle. Tailwind v4 routes every utility class through
|
|
1359
|
+
// CSS vars (font-weight: var(--font-weight-bold), font-size:
|
|
1360
|
+
// var(--text-xs), letter-spacing: var(--tracking-widest)), so without
|
|
1361
|
+
// resolution every style-based check silently fails on Tailwind v4
|
|
1362
|
+
// builds — the values come back as literal "var(--font-weight-bold)"
|
|
1363
|
+
// strings and parseFloat returns NaN.
|
|
1364
|
+
function buildCustomPropMap(document) {
|
|
1365
|
+
const map = new Map();
|
|
1366
|
+
let sheets;
|
|
1367
|
+
try { sheets = Array.from(document.styleSheets || []); }
|
|
1368
|
+
catch { return map; }
|
|
1369
|
+
for (const sheet of sheets) {
|
|
1370
|
+
let rules;
|
|
1371
|
+
try { rules = Array.from(sheet.cssRules || []); }
|
|
1372
|
+
catch { continue; }
|
|
1373
|
+
for (const rule of rules) {
|
|
1374
|
+
// Style rules only (type 1). Walk @media / @supports if present.
|
|
1375
|
+
if (rule.type === 4 /* MEDIA_RULE */ || rule.type === 12 /* SUPPORTS_RULE */) {
|
|
1376
|
+
try { rules.push(...Array.from(rule.cssRules || [])); } catch { /* ignore */ }
|
|
1377
|
+
continue;
|
|
1378
|
+
}
|
|
1379
|
+
if (rule.type !== 1 /* STYLE_RULE */) continue;
|
|
1380
|
+
const sel = rule.selectorText || '';
|
|
1381
|
+
if (!/(^|,\s*)(:root|html|:host)\b/i.test(sel)) continue;
|
|
1382
|
+
const style = rule.style;
|
|
1383
|
+
if (!style) continue;
|
|
1384
|
+
for (let i = 0; i < style.length; i++) {
|
|
1385
|
+
const prop = style[i];
|
|
1386
|
+
if (!prop || !prop.startsWith('--')) continue;
|
|
1387
|
+
const val = style.getPropertyValue(prop).trim();
|
|
1388
|
+
if (val) map.set(prop, val);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
return map;
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
// Resolve var(--X[, fallback]) refs in a computed-style value string.
|
|
1396
|
+
// Recurses up to 8 levels for chained refs (--a: var(--b)). Returns
|
|
1397
|
+
// the original string when no refs are present or the chain doesn't
|
|
1398
|
+
// resolve. Safe to call on already-resolved values.
|
|
1399
|
+
function resolveVarRefs(raw, customPropMap, depth = 0) {
|
|
1400
|
+
if (typeof raw !== 'string' || !raw.includes('var(')) return raw;
|
|
1401
|
+
if (depth > 8) return raw;
|
|
1402
|
+
return raw.replace(/var\(\s*(--[a-zA-Z0-9_-]+)\s*(?:,\s*([^)]+))?\)/g, (_m, name, fallback) => {
|
|
1403
|
+
const v = customPropMap.get(name);
|
|
1404
|
+
if (v != null) return resolveVarRefs(v, customPropMap, depth + 1);
|
|
1405
|
+
return fallback ? resolveVarRefs(fallback.trim(), customPropMap, depth + 1) : _m;
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
// OKLCH → sRGB conversion (Björn Ottosson's matrices). L in 0..1 (or %),
|
|
1410
|
+
// C in 0..~0.4 typical, H in degrees. Returns clamped {r,g,b,a:1} in 0..255.
|
|
1411
|
+
// Needed because jsdom doesn't compute oklch() values — getComputedStyle
|
|
1412
|
+
// returns the literal "oklch(...)" string. Without this, the entire
|
|
1413
|
+
// Tailwind v4 color palette (which is OKLCH-based) is invisible to the
|
|
1414
|
+
// detector's contrast / color checks.
|
|
1415
|
+
function oklchToRgb(L, C, H) {
|
|
1416
|
+
const hRad = (H * Math.PI) / 180;
|
|
1417
|
+
const a = C * Math.cos(hRad);
|
|
1418
|
+
const b = C * Math.sin(hRad);
|
|
1419
|
+
const l_ = L + 0.3963377774 * a + 0.2158037573 * b;
|
|
1420
|
+
const m_ = L - 0.1055613458 * a - 0.0638541728 * b;
|
|
1421
|
+
const s_ = L - 0.0894841775 * a - 1.2914855480 * b;
|
|
1422
|
+
const lc = l_ * l_ * l_, mc = m_ * m_ * m_, sc = s_ * s_ * s_;
|
|
1423
|
+
const rLin = 4.0767416621 * lc - 3.3077115913 * mc + 0.2309699292 * sc;
|
|
1424
|
+
const gLin = -1.2684380046 * lc + 2.6097574011 * mc - 0.3413193965 * sc;
|
|
1425
|
+
const bLin = -0.0041960863 * lc - 0.7034186147 * mc + 1.7076147010 * sc;
|
|
1426
|
+
const enc = (x) => {
|
|
1427
|
+
const c = Math.max(0, Math.min(1, x));
|
|
1428
|
+
return c <= 0.0031308 ? 12.92 * c : 1.055 * Math.pow(c, 1 / 2.4) - 0.055;
|
|
1429
|
+
};
|
|
1430
|
+
return {
|
|
1431
|
+
r: Math.round(enc(rLin) * 255),
|
|
1432
|
+
g: Math.round(enc(gLin) * 255),
|
|
1433
|
+
b: Math.round(enc(bLin) * 255),
|
|
1434
|
+
a: 1,
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
// Extended color parser: rgb/rgba/hex/oklch. Returns null on no match.
|
|
1439
|
+
// Use this when the input might be any CSS color form; use plain parseRgb
|
|
1440
|
+
// when you only expect computed rgb() values from real browsers.
|
|
1441
|
+
function parseAnyColor(s) {
|
|
1442
|
+
if (!s || typeof s !== 'string') return null;
|
|
1443
|
+
const str = s.trim();
|
|
1444
|
+
if (str === 'transparent' || str === 'currentcolor' || str === 'inherit') return null;
|
|
1445
|
+
let m;
|
|
1446
|
+
m = str.match(/rgba?\(\s*(\d+(?:\.\d+)?)\s*,?\s*(\d+(?:\.\d+)?)\s*,?\s*(\d+(?:\.\d+)?)(?:\s*[,/]\s*([\d.]+))?\s*\)/);
|
|
1447
|
+
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 };
|
|
1448
|
+
m = str.match(/^#([0-9a-f]{3,8})$/i);
|
|
1449
|
+
if (m) {
|
|
1450
|
+
const h = m[1];
|
|
1451
|
+
if (h.length === 3 || h.length === 4) {
|
|
1452
|
+
return {
|
|
1453
|
+
r: parseInt(h[0] + h[0], 16),
|
|
1454
|
+
g: parseInt(h[1] + h[1], 16),
|
|
1455
|
+
b: parseInt(h[2] + h[2], 16),
|
|
1456
|
+
a: h.length === 4 ? parseInt(h[3] + h[3], 16) / 255 : 1,
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
if (h.length === 6 || h.length === 8) {
|
|
1460
|
+
return {
|
|
1461
|
+
r: parseInt(h.slice(0, 2), 16),
|
|
1462
|
+
g: parseInt(h.slice(2, 4), 16),
|
|
1463
|
+
b: parseInt(h.slice(4, 6), 16),
|
|
1464
|
+
a: h.length === 8 ? parseInt(h.slice(6, 8), 16) / 255 : 1,
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
// OKLCH parser. Tailwind v4's CSS minifier squishes the space after
|
|
1469
|
+
// `%` ("21.5%.02 50"), so the separator between L and C may be absent.
|
|
1470
|
+
// Match L (with optional %), then C and H separated permissively.
|
|
1471
|
+
m = str.match(/oklch\(\s*([\d.]+)(%?)\s*[\s,]*\s*([\d.]+)\s*[\s,]+\s*([-\d.]+)(?:deg)?\s*\)/i);
|
|
1472
|
+
if (m) {
|
|
1473
|
+
const Lnum = parseFloat(m[1]);
|
|
1474
|
+
const L = m[2] === '%' ? Lnum / 100 : Lnum;
|
|
1475
|
+
return oklchToRgb(L, parseFloat(m[3]), parseFloat(m[4]));
|
|
1476
|
+
}
|
|
1477
|
+
return null;
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
// Resolve var() refs in a color string (via customPropMap), then parse.
|
|
1481
|
+
// Returns null on any failure. Used in jsdom-mode paths where
|
|
1482
|
+
// getComputedStyle returns literal "var(--X)" or "oklch(...)" strings.
|
|
1483
|
+
function parseColorResolved(str, customPropMap) {
|
|
1484
|
+
if (!str) return null;
|
|
1485
|
+
const resolved = customPropMap ? resolveVarRefs(str, customPropMap) : str;
|
|
1486
|
+
return parseAnyColor(resolved);
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
const REPEATED_KICKER_SKIP_SELECTOR = [
|
|
1490
|
+
'nav',
|
|
1491
|
+
'form',
|
|
1492
|
+
'table',
|
|
1493
|
+
'thead',
|
|
1494
|
+
'tbody',
|
|
1495
|
+
'tfoot',
|
|
1496
|
+
'figure',
|
|
1497
|
+
'figcaption',
|
|
1498
|
+
'ol',
|
|
1499
|
+
'ul',
|
|
1500
|
+
'li',
|
|
1501
|
+
'[role="navigation"]',
|
|
1502
|
+
'[aria-label*="breadcrumb" i]',
|
|
1503
|
+
'[class*="breadcrumb" i]',
|
|
1504
|
+
'[data-impeccable-allow-kickers]',
|
|
1505
|
+
].join(',');
|
|
1506
|
+
|
|
1507
|
+
function cleanInlineText(el) {
|
|
1508
|
+
return [...el.childNodes]
|
|
1509
|
+
.filter(n => n.nodeType === 3)
|
|
1510
|
+
.map(n => n.textContent)
|
|
1511
|
+
.join(' ')
|
|
1512
|
+
.replace(/\s+/g, ' ')
|
|
1513
|
+
.trim();
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
function isRepeatedKickerCandidate(opts) {
|
|
1517
|
+
const {
|
|
1518
|
+
headingTag,
|
|
1519
|
+
headingText,
|
|
1520
|
+
headingFontSize,
|
|
1521
|
+
kickerTag,
|
|
1522
|
+
kickerText,
|
|
1523
|
+
kickerTextTransform,
|
|
1524
|
+
kickerFontSize,
|
|
1525
|
+
kickerLetterSpacing,
|
|
1526
|
+
} = opts;
|
|
1527
|
+
if (!['h2', 'h3', 'h4'].includes(headingTag)) return false;
|
|
1528
|
+
if (!headingText || headingText.length < 3) return false;
|
|
1529
|
+
if (!(headingFontSize >= 20)) return false;
|
|
1530
|
+
if (!kickerTag || HEADING_TAGS.has(kickerTag)) return false;
|
|
1531
|
+
if (!['p', 'span', 'div', 'small'].includes(kickerTag)) return false;
|
|
1532
|
+
if (!kickerText || kickerText.length < 2 || kickerText.length > 34) return false;
|
|
1533
|
+
if (/^step\s*\d+/i.test(kickerText) || /^\d{1,2}$/.test(kickerText)) return false;
|
|
1534
|
+
|
|
1535
|
+
const isUppercased = kickerTextTransform === 'uppercase'
|
|
1536
|
+
|| (/[A-Z]/.test(kickerText) && !/[a-z]/.test(kickerText));
|
|
1537
|
+
if (!isUppercased) return false;
|
|
1538
|
+
if (!(kickerFontSize > 0 && kickerFontSize <= 14)) return false;
|
|
1539
|
+
const minTrackedSpacing = Math.max(1, kickerFontSize * 0.08);
|
|
1540
|
+
if (!(kickerLetterSpacing >= minTrackedSpacing)) return false;
|
|
1541
|
+
return true;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
function collectRepeatedSectionKickerCandidates(doc, getStyle, resolveLetterSpacing) {
|
|
1545
|
+
const candidates = [];
|
|
1546
|
+
for (const heading of doc.querySelectorAll('h2, h3, h4')) {
|
|
1547
|
+
if (heading.closest?.(REPEATED_KICKER_SKIP_SELECTOR)) continue;
|
|
1548
|
+
const kicker = heading.previousElementSibling;
|
|
1549
|
+
if (!kicker || kicker.closest?.(REPEATED_KICKER_SKIP_SELECTOR)) continue;
|
|
1550
|
+
|
|
1551
|
+
const headingStyle = getStyle(heading);
|
|
1552
|
+
const kickerStyle = getStyle(kicker);
|
|
1553
|
+
const headingText = (heading.textContent || '').replace(/\s+/g, ' ').trim();
|
|
1554
|
+
const kickerText = cleanInlineText(kicker) || (kicker.textContent || '').replace(/\s+/g, ' ').trim();
|
|
1555
|
+
const headingFontSize = resolveLetterSpacing(headingStyle.fontSize || '', 16) || parseFloat(headingStyle.fontSize) || 0;
|
|
1556
|
+
const kickerFontSize = resolveLetterSpacing(kickerStyle.fontSize || '', 16) || parseFloat(kickerStyle.fontSize) || 0;
|
|
1557
|
+
const kickerLetterSpacing = resolveLetterSpacing(kickerStyle.letterSpacing || '', kickerFontSize);
|
|
1558
|
+
|
|
1559
|
+
if (!isRepeatedKickerCandidate({
|
|
1560
|
+
headingTag: heading.tagName.toLowerCase(),
|
|
1561
|
+
headingText,
|
|
1562
|
+
headingFontSize,
|
|
1563
|
+
kickerTag: kicker.tagName.toLowerCase(),
|
|
1564
|
+
kickerText,
|
|
1565
|
+
kickerTextTransform: kickerStyle.textTransform || '',
|
|
1566
|
+
kickerFontSize,
|
|
1567
|
+
kickerLetterSpacing,
|
|
1568
|
+
})) {
|
|
1569
|
+
continue;
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
candidates.push({
|
|
1573
|
+
headingTag: heading.tagName.toLowerCase(),
|
|
1574
|
+
headingText: headingText.replace(/^"|"$/g, '').slice(0, 60),
|
|
1575
|
+
kickerText: kickerText.slice(0, 40),
|
|
1576
|
+
});
|
|
1577
|
+
}
|
|
1578
|
+
return candidates;
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
function checkRepeatedSectionKickersDOM() {
|
|
1582
|
+
const candidates = collectRepeatedSectionKickerCandidates(
|
|
1583
|
+
document,
|
|
1584
|
+
(el) => getComputedStyle(el),
|
|
1585
|
+
(value, fontSize) => resolveLengthPx(value, fontSize) || 0,
|
|
1586
|
+
);
|
|
1587
|
+
return checkRepeatedSectionKickers({ candidates });
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1043
1590
|
function checkElementMotionDOM(el) {
|
|
1044
1591
|
const tag = el.tagName.toLowerCase();
|
|
1045
1592
|
if (SAFE_TAGS.has(tag)) return [];
|
|
@@ -1190,7 +1737,7 @@ function resolveLengthPx(value, fontSizePx) {
|
|
|
1190
1737
|
// Both adapters resolve font-size, line-height and letter-spacing to pixels
|
|
1191
1738
|
// before calling this so the pure function only deals with numbers.
|
|
1192
1739
|
function checkQuality(opts) {
|
|
1193
|
-
const { el, tag, style, hasDirectText, textLen, fontSize, lineHeightPx, letterSpacingPx, rect, lineMax = 80 } = opts;
|
|
1740
|
+
const { el, tag, style, hasDirectText, textLen, fontSize, lineHeightPx, letterSpacingPx, rect, lineMax = 80, viewportWidth = 0 } = opts;
|
|
1194
1741
|
const findings = [];
|
|
1195
1742
|
// Skip browser extension injected elements
|
|
1196
1743
|
const elId = el.id || '';
|
|
@@ -1241,6 +1788,40 @@ function checkQuality(opts) {
|
|
|
1241
1788
|
}
|
|
1242
1789
|
}
|
|
1243
1790
|
|
|
1791
|
+
// --- Body text touching viewport edge --- (browser-only: needs rect)
|
|
1792
|
+
// Catches the failure mode where the agent ships body paragraphs
|
|
1793
|
+
// with NO container providing horizontal padding — text bleeds
|
|
1794
|
+
// directly to the viewport edge. Different from cramped-padding,
|
|
1795
|
+
// which requires a colored/bordered container. Here the failure
|
|
1796
|
+
// is the absence of the container entirely.
|
|
1797
|
+
//
|
|
1798
|
+
// Gate aggressively to avoid false positives:
|
|
1799
|
+
// - <p> or <li> only (body content; not headings, not nav, not
|
|
1800
|
+
// wrappers)
|
|
1801
|
+
// - text > 40 chars (paragraph-like, not a label)
|
|
1802
|
+
// - rect.width > 50% of viewport (real body, not a pull-quote)
|
|
1803
|
+
// - rect.left < 16 OR rect.right > viewport - 16 (actually
|
|
1804
|
+
// touching the edge)
|
|
1805
|
+
// - not inside <nav> or <header> (those legitimately bleed)
|
|
1806
|
+
// - element itself has no background-color (intentional full-bleed
|
|
1807
|
+
// sections set a bg-color and provide their own internal padding)
|
|
1808
|
+
if (rect && hasDirectText && textLen > 40 && ['P', 'LI'].includes(tag.toUpperCase()) && viewportWidth > 0) {
|
|
1809
|
+
const inNavHeader = el.closest && (el.closest('nav') || el.closest('header'));
|
|
1810
|
+
const hasOwnBg = style.backgroundColor && style.backgroundColor !== 'rgba(0, 0, 0, 0)' && style.backgroundColor !== 'transparent';
|
|
1811
|
+
const isPositioned = ['fixed', 'absolute'].includes(style.position || '');
|
|
1812
|
+
const widthRatio = rect.width / viewportWidth;
|
|
1813
|
+
const leftClose = rect.left < 16;
|
|
1814
|
+
const rightClose = rect.right > viewportWidth - 16;
|
|
1815
|
+
if (!inNavHeader && !hasOwnBg && !isPositioned && widthRatio > 0.5 && (leftClose || rightClose)) {
|
|
1816
|
+
const which = leftClose && rightClose
|
|
1817
|
+
? `left ${Math.round(rect.left)}px / right ${Math.round(viewportWidth - rect.right)}px`
|
|
1818
|
+
: leftClose
|
|
1819
|
+
? `left ${Math.round(rect.left)}px`
|
|
1820
|
+
: `right ${Math.round(viewportWidth - rect.right)}px`;
|
|
1821
|
+
findings.push({ id: 'body-text-viewport-edge', snippet: `<${tag.toLowerCase()}> with ${textLen}-char body bleeds to viewport edge (${which})` });
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1244
1825
|
// --- Tight line height ---
|
|
1245
1826
|
if (hasDirectText && textLen > 50 && !['h1','h2','h3','h4','h5','h6'].includes(tag)) {
|
|
1246
1827
|
if (lineHeightPx != null && fontSize > 0) {
|
|
@@ -1302,7 +1883,8 @@ function checkElementQualityDOM(el) {
|
|
|
1302
1883
|
const letterSpacingPx = resolveLengthPx(style.letterSpacing, fontSize);
|
|
1303
1884
|
const rect = el.getBoundingClientRect();
|
|
1304
1885
|
const lineMax = (typeof window !== 'undefined' && window.__IMPECCABLE_CONFIG__?.lineLengthMax) || 80;
|
|
1305
|
-
|
|
1886
|
+
const viewportWidth = (typeof window !== 'undefined' ? window.innerWidth : 0) || 0;
|
|
1887
|
+
return checkQuality({ el, tag, style, hasDirectText, textLen, fontSize, lineHeightPx, letterSpacingPx, rect, lineMax, viewportWidth });
|
|
1306
1888
|
}
|
|
1307
1889
|
|
|
1308
1890
|
// Pure page-level skipped-heading walk. Takes a Document so it works in both
|
|
@@ -1377,15 +1959,48 @@ function checkElementBorders(tag, style, overrides, resolvedRadius) {
|
|
|
1377
1959
|
return checkBorders(tag, widths, colors, radius);
|
|
1378
1960
|
}
|
|
1379
1961
|
|
|
1380
|
-
function checkElementColors(el, style, tag, window) {
|
|
1962
|
+
function checkElementColors(el, style, tag, window, customPropMap, hasAnchorInheritRule) {
|
|
1381
1963
|
const directText = [...el.childNodes].filter(n => n.nodeType === 3).map(n => n.textContent).join('');
|
|
1382
1964
|
const hasDirectText = directText.trim().length > 0;
|
|
1383
1965
|
|
|
1384
|
-
const effectiveBg = resolveBackground(el, window);
|
|
1966
|
+
const effectiveBg = resolveBackground(el, window, customPropMap);
|
|
1967
|
+
// jsdom returns literal "var(--X)" / "oklch(...)" for color, so plain
|
|
1968
|
+
// parseRgb misses Tailwind-tokenized text colors. Resolve through the
|
|
1969
|
+
// customPropMap first; fall back to parseRgb for vanilla rgb() pages.
|
|
1970
|
+
let textColor = customPropMap ? parseColorResolved(style.color, customPropMap) : null;
|
|
1971
|
+
if (!textColor) textColor = parseRgb(style.color);
|
|
1972
|
+
|
|
1973
|
+
// Anchor-inherit FP workaround: jsdom's UA stylesheet has `:link { color:
|
|
1974
|
+
// blue }` at high specificity. The page's `a { color: inherit }` rule
|
|
1975
|
+
// (Tailwind v4 preflight) loses to jsdom even though it WINS in real
|
|
1976
|
+
// browsers (Chrome's UA wraps :link in :where() — zero specificity).
|
|
1977
|
+
// When the page declares the inherit rule AND we see jsdom's default
|
|
1978
|
+
// link blue on an anchor, walk to the nearest non-anchor ancestor and
|
|
1979
|
+
// use its color instead.
|
|
1980
|
+
if (
|
|
1981
|
+
hasAnchorInheritRule &&
|
|
1982
|
+
textColor &&
|
|
1983
|
+
textColor.r === 0 && textColor.g === 0 && textColor.b === 238 &&
|
|
1984
|
+
(tag === 'a' || el.closest?.('a'))
|
|
1985
|
+
) {
|
|
1986
|
+
let cur = el.parentElement;
|
|
1987
|
+
while (cur && cur.tagName !== 'HTML') {
|
|
1988
|
+
if (cur.tagName !== 'A') {
|
|
1989
|
+
const ps = window.getComputedStyle(cur);
|
|
1990
|
+
const inh = (customPropMap ? parseColorResolved(ps.color, customPropMap) : null) || parseRgb(ps.color);
|
|
1991
|
+
if (inh && !(inh.r === 0 && inh.g === 0 && inh.b === 238)) {
|
|
1992
|
+
textColor = inh;
|
|
1993
|
+
break;
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
cur = cur.parentElement;
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
|
|
1385
2000
|
return checkColors({
|
|
1386
2001
|
tag,
|
|
1387
|
-
textColor
|
|
1388
|
-
bgColor:
|
|
2002
|
+
textColor,
|
|
2003
|
+
bgColor: readOwnBackgroundColor(el, style),
|
|
1389
2004
|
effectiveBg,
|
|
1390
2005
|
effectiveBgStops: effectiveBg ? null : resolveGradientStops(el, window),
|
|
1391
2006
|
fontSize: parseFloat(style.fontSize) || 16,
|
|
@@ -1435,6 +2050,57 @@ function checkElementIconTile(el, tag, window) {
|
|
|
1435
2050
|
});
|
|
1436
2051
|
}
|
|
1437
2052
|
|
|
2053
|
+
function checkElementItalicSerif(el, style, tag) {
|
|
2054
|
+
if (tag !== 'h1' && tag !== 'h2') return [];
|
|
2055
|
+
return checkItalicSerif({
|
|
2056
|
+
tag,
|
|
2057
|
+
fontStyle: style.fontStyle || '',
|
|
2058
|
+
fontFamily: style.fontFamily || '',
|
|
2059
|
+
fontSize: parseFloat(style.fontSize) || 0,
|
|
2060
|
+
headingText: el.textContent || '',
|
|
2061
|
+
});
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
function checkElementHeroEyebrow(el, style, tag, window, customPropMap) {
|
|
2065
|
+
if (tag !== 'h1') return [];
|
|
2066
|
+
const sibling = el.previousElementSibling;
|
|
2067
|
+
if (!sibling) return [];
|
|
2068
|
+
const sibStyle = window.getComputedStyle(sibling);
|
|
2069
|
+
// Resolve Tailwind v4 CSS-variable wrappers (font-weight:var(--font-weight-bold)
|
|
2070
|
+
// etc.) before parsing. jsdom returns these verbatim from getComputedStyle;
|
|
2071
|
+
// without resolution every style-based gate fails silently on Tailwind v4 builds.
|
|
2072
|
+
const fontSizeRaw = customPropMap ? resolveVarRefs(sibStyle.fontSize, customPropMap) : sibStyle.fontSize;
|
|
2073
|
+
const fontWeightRaw = customPropMap ? resolveVarRefs(sibStyle.fontWeight, customPropMap) : sibStyle.fontWeight;
|
|
2074
|
+
const letterSpacingRaw = customPropMap ? resolveVarRefs(sibStyle.letterSpacing, customPropMap) : sibStyle.letterSpacing;
|
|
2075
|
+
const colorRaw = customPropMap ? resolveVarRefs(sibStyle.color, customPropMap) : sibStyle.color;
|
|
2076
|
+
const headingFontSizeRaw = customPropMap ? resolveVarRefs(style.fontSize, customPropMap) : style.fontSize;
|
|
2077
|
+
const siblingFontSize = parseFloat(fontSizeRaw) || 0;
|
|
2078
|
+
// resolveLengthPx returns null for 'normal' / 'auto'; coerce to 0 so the
|
|
2079
|
+
// gate falls through cleanly. jsdom returns letter-spacing verbatim
|
|
2080
|
+
// (e.g. '0.15em'), unlike real browsers, so this conversion is required.
|
|
2081
|
+
return checkHeroEyebrow({
|
|
2082
|
+
headingTag: tag,
|
|
2083
|
+
headingText: el.textContent || '',
|
|
2084
|
+
headingFontSize: parseFloat(headingFontSizeRaw) || 0,
|
|
2085
|
+
siblingTag: sibling.tagName.toLowerCase(),
|
|
2086
|
+
siblingText: sibling.textContent || '',
|
|
2087
|
+
siblingTextTransform: sibStyle.textTransform || '',
|
|
2088
|
+
siblingFontSize,
|
|
2089
|
+
siblingLetterSpacing: resolveLengthPx(letterSpacingRaw, siblingFontSize) || 0,
|
|
2090
|
+
siblingFontWeight: fontWeightRaw || '',
|
|
2091
|
+
siblingColor: colorRaw || '',
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
function checkRepeatedSectionKickersFromDoc(doc, win) {
|
|
2096
|
+
const candidates = collectRepeatedSectionKickerCandidates(
|
|
2097
|
+
doc,
|
|
2098
|
+
(el) => win.getComputedStyle(el),
|
|
2099
|
+
(value, fontSize) => resolveLengthPx(value, fontSize) || 0,
|
|
2100
|
+
);
|
|
2101
|
+
return checkRepeatedSectionKickers({ candidates });
|
|
2102
|
+
}
|
|
2103
|
+
|
|
1438
2104
|
function checkElementMotion(tag, style) {
|
|
1439
2105
|
return checkMotion({
|
|
1440
2106
|
tag,
|
|
@@ -2288,6 +2954,7 @@ if (IS_BROWSER) {
|
|
|
2288
2954
|
return {
|
|
2289
2955
|
type: f.type || f.id,
|
|
2290
2956
|
category: ap ? ap.category : 'quality',
|
|
2957
|
+
severity: ap?.severity || 'warning',
|
|
2291
2958
|
detail: f.detail || f.snippet,
|
|
2292
2959
|
name: ap ? ap.name : (f.type || f.id),
|
|
2293
2960
|
description: ap ? ap.description : '',
|
|
@@ -2343,6 +3010,8 @@ if (IS_BROWSER) {
|
|
|
2343
3010
|
...checkElementGlowDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
2344
3011
|
...checkElementAIPaletteDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
2345
3012
|
...checkElementIconTileDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
3013
|
+
...checkElementItalicSerifDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
3014
|
+
...checkElementHeroEyebrowDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
2346
3015
|
...checkElementQualityDOM(el).map(f => ({ type: f.id, detail: f.snippet })),
|
|
2347
3016
|
].filter(f => _ruleOk(f.type));
|
|
2348
3017
|
|
|
@@ -2360,6 +3029,14 @@ if (IS_BROWSER) {
|
|
|
2360
3029
|
allFindings.push({ el: document.body, findings: typoFindings });
|
|
2361
3030
|
}
|
|
2362
3031
|
|
|
3032
|
+
const sectionKickerFindings = checkRepeatedSectionKickersDOM()
|
|
3033
|
+
.map(f => ({ type: f.id, detail: f.snippet }))
|
|
3034
|
+
.filter(f => _ruleOk(f.type));
|
|
3035
|
+
if (sectionKickerFindings.length > 0) {
|
|
3036
|
+
pageLevelFindings.push(...sectionKickerFindings);
|
|
3037
|
+
allFindings.push({ el: document.body, findings: sectionKickerFindings });
|
|
3038
|
+
}
|
|
3039
|
+
|
|
2363
3040
|
const layoutFindings = checkLayout().filter(f => _ruleOk(f.type));
|
|
2364
3041
|
for (const f of layoutFindings) {
|
|
2365
3042
|
const el = f.el || document.body;
|