@monoes/monodesign 1.2.17 → 1.2.20

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.
@@ -1,498 +1,11 @@
1
- const ANTIPATTERNS = [
2
- // ── AI slop: tells that something was AI-generated ──
3
- {
4
- id: 'side-tab',
5
- category: 'slop',
6
- name: 'Side-tab accent border',
7
- description:
8
- 'Thick colored border on one side of a card — the most recognizable tell of AI-generated UIs. Use a subtler accent or remove it entirely.',
9
- skillSection: 'Visual Details',
10
- skillGuideline: 'colored accent stripe',
11
- },
12
- {
13
- id: 'border-accent-on-rounded',
14
- category: 'slop',
15
- name: 'Border accent on rounded element',
16
- description:
17
- 'Thick accent border on a rounded card — the border clashes with the rounded corners. Remove the border or the border-radius.',
18
- skillSection: 'Visual Details',
19
- skillGuideline: 'colored accent stripe',
20
- },
21
- {
22
- id: 'overused-font',
23
- category: 'slop',
24
- scopes: ['type'],
25
- name: 'Overused font',
26
- description:
27
- '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.',
28
- skillSection: 'Typography',
29
- skillGuideline: 'overused fonts like Inter',
30
- },
31
- {
32
- id: 'single-font',
33
- category: 'slop',
34
- scopes: ['type'],
35
- name: 'Single font for everything',
36
- description:
37
- 'Only one font family is used for the entire page. Pair a distinctive display font with a refined body font to create typographic hierarchy.',
38
- skillSection: 'Typography',
39
- skillGuideline: 'only one font family for the entire page',
40
- },
41
- {
42
- id: 'flat-type-hierarchy',
43
- category: 'slop',
44
- scopes: ['type'],
45
- name: 'Flat type hierarchy',
46
- description:
47
- 'Font sizes are too close together — no clear visual hierarchy. Use fewer sizes with more contrast (aim for at least a 1.25 ratio between steps).',
48
- skillSection: 'Typography',
49
- skillGuideline: 'flat type hierarchy',
50
- },
51
- {
52
- id: 'gradient-text',
53
- category: 'slop',
54
- name: 'Gradient text',
55
- description:
56
- 'Gradient text is decorative rather than meaningful — a common AI tell, especially on headings and metrics. Use solid colors for text.',
57
- skillSection: 'Color & Contrast',
58
- skillGuideline: 'gradient text for',
59
- },
60
- {
61
- id: 'ai-color-palette',
62
- category: 'slop',
63
- name: 'AI color palette',
64
- description:
65
- 'Purple/violet gradients and cyan-on-dark are the most recognizable tells of AI-generated UIs. Choose a distinctive, intentional palette.',
66
- skillSection: 'Color & Contrast',
67
- skillGuideline: 'AI color palette',
68
- },
69
- {
70
- id: 'cream-palette',
71
- category: 'slop',
72
- name: 'Cream / beige palette',
73
- description:
74
- 'A warm cream or beige page background has become the default "tasteful" AI surface, reached for by reflex. Choose a background that comes from a deliberate palette, not the safe warm off-white.',
75
- skillSection: 'Color & Contrast',
76
- skillGuideline: 'cream and beige as the default surface',
77
- },
78
- {
79
- id: 'nested-cards',
80
- category: 'slop',
81
- scopes: ['layout'],
82
- name: 'Nested cards',
83
- description:
84
- 'Cards inside cards create visual noise and excessive depth. Flatten the hierarchy — use spacing, typography, and dividers instead of nesting containers.',
85
- skillSection: 'Layout & Space',
86
- skillGuideline: 'Nest cards inside cards',
87
- },
88
- {
89
- id: 'monotonous-spacing',
90
- category: 'slop',
91
- scopes: ['layout'],
92
- name: 'Monotonous spacing',
93
- description:
94
- 'The same spacing value used everywhere — no rhythm, no variation. Use tight groupings for related items and generous separations between sections.',
95
- skillSection: 'Layout & Space',
96
- skillGuideline: 'same spacing everywhere',
97
- },
98
- {
99
- id: 'bounce-easing',
100
- category: 'slop',
101
- name: 'Bounce or elastic easing',
102
- description:
103
- 'Bounce and elastic easing feel dated and tacky. Real objects decelerate smoothly — use exponential easing (ease-out-quart/quint/expo) instead.',
104
- skillSection: 'Motion',
105
- skillGuideline: 'bounce or elastic easing',
106
- },
107
- {
108
- id: 'dark-glow',
109
- category: 'slop',
110
- name: 'Dark mode with glowing accents',
111
- description:
112
- 'Dark backgrounds with colored box-shadow glows are the default "cool" look of AI-generated UIs. Use subtle, purposeful lighting instead — or skip the dark theme entirely.',
113
- skillSection: 'Color & Contrast',
114
- skillGuideline: 'dark mode with glowing accents',
115
- },
116
- {
117
- id: 'icon-tile-stack',
118
- category: 'slop',
119
- scopes: ['layout'],
120
- name: 'Icon tile stacked above heading',
121
- description:
122
- 'A small rounded-square icon container above a heading is the universal AI feature-card template — every generator outputs this exact shape. Try a side-by-side icon and heading, or let the icon sit in flow without its own container.',
123
- skillSection: 'Typography',
124
- skillGuideline: 'large icons with rounded corners above every heading',
125
- },
126
- {
127
- id: 'italic-serif-display',
128
- category: 'slop',
129
- scopes: ['type'],
130
- name: 'Italic serif display headline',
131
- description:
132
- '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.',
133
- skillSection: 'Typography',
134
- skillGuideline: 'oversized italic serif as the hero headline',
135
- },
136
- {
137
- id: 'hero-eyebrow-chip',
138
- category: 'slop',
139
- scopes: ['type'],
140
- name: 'Hero eyebrow / pill chip',
141
- description:
142
- '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.',
143
- skillSection: 'Typography',
144
- skillGuideline: 'tiny uppercase tracked label above the hero headline',
145
- },
146
- {
147
- id: 'repeated-section-kickers',
148
- category: 'slop',
149
- scopes: ['type'],
150
- severity: 'advisory',
151
- name: 'Repeated section kicker labels',
152
- description:
153
- '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.',
154
- skillSection: 'Typography',
155
- skillGuideline: 'repeated eyebrow or kicker labels as section scaffolding',
156
- },
157
- {
158
- id: 'numbered-section-markers',
159
- category: 'slop',
160
- scopes: ['layout'],
161
- severity: 'advisory',
162
- name: 'Numbered section markers (01 / 02 / 03)',
163
- description:
164
- 'Numbered display markers as section labels (01, 02, 03) are the AI editorial scaffold one tier deeper than tracked eyebrow chips. If you find yourself reaching for them, choose a different section cadence.',
165
- skillSection: 'Layout & Space',
166
- skillGuideline: 'numbered section markers',
167
- },
168
- {
169
- id: 'em-dash-overuse',
170
- category: 'slop',
171
- name: 'Em-dash overuse',
172
- description:
173
- 'More than two em-dashes (— or --) in body copy is an AI cadence tell. Use commas, colons, periods, or parentheses instead.',
174
- skillSection: 'Copy',
175
- skillGuideline: 'no em dashes',
176
- },
177
- {
178
- id: 'marketing-buzzword',
179
- category: 'slop',
180
- name: 'Marketing buzzword',
181
- description:
182
- 'Generic SaaS phrases (streamline / empower / supercharge / world-class / enterprise-grade / next-generation / cutting-edge / etc) are instant AI tells. Pick a specific verb and noun that says what the product literally does.',
183
- skillSection: 'Copy',
184
- skillGuideline: 'marketing buzzwords',
185
- },
186
- {
187
- id: 'aphoristic-cadence',
188
- category: 'slop',
189
- name: 'Aphoristic-cadence copy',
190
- description:
191
- 'Three or more sections landing on a short rebuttal sentence ("X. No Y." / "X. Just Y.") or a manufactured-contrast aphorism ("Not a feature. A platform.") reads as AI cadence, not voice. Once is fine; the pattern is the tell.',
192
- skillSection: 'Copy',
193
- skillGuideline: 'aphoristic cadence',
194
- },
195
- {
196
- id: 'oversized-h1',
197
- category: 'slop',
198
- scopes: ['type'],
199
- name: 'Oversized hero headline',
200
- description:
201
- 'A full-sentence headline set at display size ends up dominating the viewport, leaving no room for anything else above the fold. A punchy one- or two-word headline at that size is fine — the problem is a long headline blown up too large. Set long headlines smaller, or tighten the copy.',
202
- skillSection: 'Typography',
203
- skillGuideline: 'long headline set at display size',
204
- },
205
- {
206
- id: 'extreme-negative-tracking',
207
- category: 'slop',
208
- scopes: ['type'],
209
- name: 'Crushed letter spacing',
210
- description:
211
- 'Letter-spacing pulled tighter than the point where characters keep their own shapes costs legibility. Tighten display type optically, not destructively.',
212
- skillSection: 'Typography',
213
- skillGuideline: 'letter spacing crushed past legibility',
214
- },
215
- {
216
- id: 'broken-image',
217
- category: 'quality',
218
- name: 'Broken or placeholder image',
219
- description:
220
- '<img> tags with empty src, missing src, or placeholder values ship as broken-image boxes. Use real images, generated assets, or remove the tag.',
221
- skillSection: 'Imagery',
222
- skillGuideline: 'broken image references',
223
- },
224
-
225
- // ── Quality: general design and accessibility issues ──
226
- {
227
- id: 'gray-on-color',
228
- category: 'quality',
229
- name: 'Gray text on colored background',
230
- description:
231
- 'Gray text looks washed out on colored backgrounds. Use a darker shade of the background color instead, or white/near-white for contrast.',
232
- skillSection: 'Color & Contrast',
233
- skillGuideline: 'gray text on colored backgrounds',
234
- },
235
- {
236
- id: 'low-contrast',
237
- category: 'quality',
238
- name: 'Low contrast text',
239
- description:
240
- 'Text does not meet WCAG AA contrast requirements (4.5:1 for body, 3:1 for large text). Increase the contrast between text and background.',
241
- },
242
- {
243
- id: 'layout-transition',
244
- category: 'quality',
245
- name: 'Layout property animation',
246
- description:
247
- 'Animating width, height, padding, or margin causes layout thrash and janky performance. Use transform and opacity instead, or grid-template-rows for height animations.',
248
- skillSection: 'Motion',
249
- skillGuideline: 'Animate layout properties',
250
- },
251
- {
252
- id: 'line-length',
253
- category: 'quality',
254
- scopes: ['type', 'layout'],
255
- name: 'Line length too long',
256
- description:
257
- 'Text lines wider than ~80 characters are hard to read. The eye loses its place tracking back to the start of the next line. Add a max-width (65ch to 75ch) to text containers.',
258
- skillSection: 'Layout & Space',
259
- skillGuideline: 'wrap beyond ~80 characters',
260
- },
261
- {
262
- id: 'cramped-padding',
263
- category: 'quality',
264
- scopes: ['layout'],
265
- name: 'Cramped padding',
266
- description:
267
- 'Text is too close to the edge of its container. Two shapes: (1) an element with its own text where the padding is too low for the font size, and (2) a wrapper with text-bearing children and near-zero padding against a visible boundary (border, outline, or non-transparent background) — children land flush against the boundary line. Add at least 8px (ideally 12–16px) of padding inside bordered, outlined, or colored containers.',
268
- skillSection: 'Layout & Space',
269
- skillGuideline: 'inside bordered or colored containers',
270
- },
271
- {
272
- id: 'body-text-viewport-edge',
273
- category: 'quality',
274
- scopes: ['layout'],
275
- name: 'Body text touching viewport edge',
276
- description:
277
- '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.',
278
- },
279
- {
280
- id: 'tight-leading',
281
- category: 'quality',
282
- scopes: ['type'],
283
- name: 'Tight line height',
284
- description:
285
- 'Line height below 1.3x the font size makes multi-line text hard to read. Use 1.5 to 1.7 for body text so lines have room to breathe.',
286
- },
287
- {
288
- id: 'skipped-heading',
289
- category: 'quality',
290
- scopes: ['type'],
291
- name: 'Skipped heading level',
292
- description:
293
- 'Heading levels should not skip (e.g. h1 then h3 with no h2). Screen readers use heading hierarchy for navigation. Skipping levels breaks the document outline.',
294
- },
295
- {
296
- id: 'justified-text',
297
- category: 'quality',
298
- scopes: ['type'],
299
- name: 'Justified text',
300
- description:
301
- 'Justified text without hyphenation creates uneven word spacing ("rivers of white"). Use text-align: left for body text, or enable hyphens: auto if you must justify.',
302
- },
303
- {
304
- id: 'tiny-text',
305
- category: 'quality',
306
- scopes: ['type'],
307
- name: 'Tiny body text',
308
- description:
309
- 'Body text below 12px is hard to read, especially on high-DPI screens. Use at least 14px for body content, 16px is ideal.',
310
- },
311
- {
312
- id: 'all-caps-body',
313
- category: 'quality',
314
- scopes: ['type'],
315
- name: 'All-caps body text',
316
- description:
317
- 'Long passages in uppercase are hard to read. We recognize words by shape (ascenders and descenders), which all-caps removes. Reserve uppercase for short labels and headings.',
318
- skillSection: 'Typography',
319
- skillGuideline: 'long body passages in uppercase',
320
- },
321
- {
322
- id: 'wide-tracking',
323
- category: 'quality',
324
- scopes: ['type'],
325
- name: 'Wide letter spacing on body text',
326
- description:
327
- 'Letter spacing above 0.05em on body text disrupts natural character groupings and slows reading. Reserve wide tracking for short uppercase labels only.',
328
- },
329
- {
330
- id: 'text-overflow',
331
- category: 'quality',
332
- scopes: ['layout'],
333
- name: 'Content overflowing its container',
334
- description:
335
- 'Content renders wider than its container, spilling out or forcing a horizontal scrollbar. Let text wrap, constrain widths, or give the region a deliberate scroll affordance.',
336
- skillSection: 'Layout & Space',
337
- skillGuideline: 'content wider than its container',
338
- },
339
- {
340
- id: 'clipped-overflow-container',
341
- category: 'quality',
342
- scopes: ['layout'],
343
- name: 'Positioned child clipped by overflow container',
344
- description:
345
- 'A clipping container (overflow hidden or clip) wrapping an absolutely-positioned child cuts off tooltips, menus, and popovers that need to escape. Let the overflow be visible, or move the positioned layer out of the clip.',
346
- skillSection: 'Layout & Space',
347
- skillGuideline: 'overflow container clipping positioned children',
348
- },
349
- {
350
- id: 'design-system-font',
351
- category: 'quality',
352
- scopes: ['type'],
353
- name: 'Font outside DESIGN.md',
354
- description:
355
- 'A font is used that is not declared in DESIGN.md typography. Use the documented type system or update DESIGN.md if this is an intentional brand addition.',
356
- skillSection: 'Typography',
357
- skillGuideline: 'font family outside the project design system',
358
- },
359
- {
360
- id: 'design-system-color',
361
- category: 'quality',
362
- severity: 'advisory',
363
- name: 'Color outside DESIGN.md',
364
- description:
365
- 'A literal color is outside the DESIGN.md palette and sidecar tonal ramps. This may be legitimate, but it should be an intentional design-system addition rather than drift.',
366
- skillSection: 'Color & Contrast',
367
- skillGuideline: 'literal color outside the project design system',
368
- },
369
- {
370
- id: 'design-system-radius',
371
- category: 'quality',
372
- severity: 'advisory',
373
- name: 'Radius outside DESIGN.md',
374
- description:
375
- 'A border-radius value is outside the DESIGN.md rounded scale. Use a documented radius token or update the design system if the new shape is intentional.',
376
- skillSection: 'Visual Details',
377
- skillGuideline: 'border radius outside the project design system',
378
- },
379
- {
380
- id: 'design-system-font-size',
381
- category: 'quality',
382
- severity: 'advisory',
383
- scopes: ['type'],
384
- name: 'Font size outside DESIGN.md',
385
- description:
386
- 'A literal font-size is off the type ramp documented in DESIGN.md typography. Use a documented size step or update the design system if the new step is intentional.',
387
- skillSection: 'Typography',
388
- skillGuideline: 'font size outside the project design system',
389
- },
1
+ import { AI_SLOP_ANTIPATTERNS } from './antipatterns-slop.mjs';
2
+ import { QUALITY_ANTIPATTERNS } from './antipatterns-quality.mjs';
3
+ import { PROVIDER_TELL_ANTIPATTERNS } from './antipatterns-provider.mjs';
390
4
 
391
- {
392
- id: 'missing-focus-visible',
393
- category: 'quality',
394
- name: 'Suppressed focus outline with no replacement',
395
- description:
396
- 'An interactive element (link, button, input) removes its focus outline (outline: none / 0) but the stylesheet never provides a :focus-visible or :focus replacement. Keyboard users lose all sense of where they are. Remove the suppression, or pair it with a visible :focus-visible ring (outline, box-shadow, or border).',
397
- skillSection: 'Interaction',
398
- skillGuideline: 'outline removed without a focus-visible replacement',
399
- },
400
- {
401
- id: 'small-touch-target',
402
- category: 'quality',
403
- scopes: ['layout'],
404
- name: 'Touch target below 44px',
405
- description:
406
- 'A clickable control (button, link, input, [role=button]) renders smaller than 44×44px on one or both axes. Fingers miss small targets and mis-tap neighbors. Give standalone controls at least 44×44px of hit area via padding or min-width/height. Inline text links inside prose are exempt.',
407
- skillSection: 'Layout & Space',
408
- skillGuideline: 'touch target smaller than 44px',
409
- },
410
- {
411
- id: 'hover-only-affordance',
412
- category: 'quality',
413
- name: 'Functionality gated behind hover only',
414
- description:
415
- 'An element is hidden by default and revealed only on :hover, with no :focus, :focus-within, or :active equivalent. Keyboard and touch users can never reach it. Mirror every hover reveal with a focus-within (or active) rule so the affordance is reachable without a pointer.',
416
- skillSection: 'Interaction',
417
- skillGuideline: 'affordance revealed on hover with no focus equivalent',
418
- },
419
- {
420
- id: 'image-missing-dimensions',
421
- category: 'quality',
422
- scopes: ['layout'],
423
- name: 'Image without reserved dimensions',
424
- description:
425
- 'An <img> ships without width and height attributes and without a CSS aspect-ratio or explicit height. The browser cannot reserve space before the image loads, so surrounding content jumps (cumulative layout shift). Set width and height attributes, or give the image a CSS aspect-ratio.',
426
- skillSection: 'Imagery',
427
- skillGuideline: 'image with no reserved dimensions',
428
- },
429
- {
430
- id: 'dark-scheme-contrast-blindspot',
431
- category: 'quality',
432
- severity: 'advisory',
433
- name: 'Dark-scheme contrast blindspot',
434
- description:
435
- 'The page ships dark styling (a prefers-color-scheme: dark block or a .dark / [data-theme=dark] scope), but for some selector the dark override changes the background without changing the paired text color (or the reverse). The half-updated pair often collapses to unreadable contrast in dark mode. Override text and background together, or verify the inherited half still contrasts.',
436
- skillSection: 'Color & Contrast',
437
- skillGuideline: 'dark scheme overrides one of a color pair but not the other',
438
- },
439
-
440
- // ── Provider tells: opt-in via --gpt / --gemini (gated off by default) ──
441
- {
442
- id: 'gpt-thin-border-wide-shadow',
443
- category: 'slop',
444
- severity: 'advisory',
445
- gated: 'gpt',
446
- name: 'Hairline border with wide shadow',
447
- description:
448
- 'A hairline border paired with a wide, diffuse shadow is a recurring generated-UI signature. Commit to one — a defined edge or a soft elevation — rather than both at once.',
449
- skillSection: 'Visual Details',
450
- skillGuideline: 'hairline border plus wide diffuse shadow',
451
- },
452
- {
453
- id: 'repeating-stripes-gradient',
454
- category: 'slop',
455
- severity: 'advisory',
456
- gated: 'gpt',
457
- name: 'Repeating-gradient stripes',
458
- description:
459
- 'Repeating-gradient stripes used as surface decoration are a recurring generated-UI signature. Reach for a deliberate texture or leave the surface plain.',
460
- skillSection: 'Visual Details',
461
- skillGuideline: 'repeating-gradient decorative stripes',
462
- },
463
- {
464
- id: 'codex-grid-background',
465
- category: 'slop',
466
- severity: 'advisory',
467
- gated: 'gpt',
468
- name: 'Decorative grid-line background',
469
- description:
470
- 'A two-axis grid drawn with hairline linear-gradient layers ("1px, transparent 1px" on both axes) is a recurring generated-UI signature. Reserve grid overlays for actual canvas, map, blueprint, or measurement surfaces; elsewhere use product structure or a plain surface.',
471
- skillSection: 'Visual Details',
472
- skillGuideline: 'two-axis grid-line gradient background',
473
- },
474
- {
475
- id: 'theater-slop-phrase',
476
- category: 'slop',
477
- severity: 'advisory',
478
- gated: 'gpt',
479
- name: 'Theater framing copy',
480
- description:
481
- 'Dismissing something as "theater" is a recurring generated-copy tic. Say plainly what the thing does or does not do.',
482
- skillSection: 'Copy',
483
- skillGuideline: 'theater framing copy',
484
- },
485
- {
486
- id: 'image-hover-transform',
487
- category: 'slop',
488
- severity: 'advisory',
489
- gated: 'gemini',
490
- name: 'Image hover transform',
491
- description:
492
- 'Scaling or rotating an image on hover is a recurring generated-UI signature. Let imagery sit still, or use a subtler, purposeful interaction.',
493
- skillSection: 'Motion',
494
- skillGuideline: 'image scale or rotate on hover',
495
- },
5
+ const ANTIPATTERNS = [
6
+ ...AI_SLOP_ANTIPATTERNS,
7
+ ...QUALITY_ANTIPATTERNS,
8
+ ...PROVIDER_TELL_ANTIPATTERNS,
496
9
  ];
497
10
 
498
11
  const RULE_ENGINE_SUPPORT = {
@@ -0,0 +1,155 @@
1
+ import { parseGradientColors, parseRgb } from '../shared/color.mjs';
2
+ import { DETECTOR_IS_BROWSER } from './checks-pure.mjs';
3
+ import { parseAnyColor, parseColorResolved } from './checks-css-values.mjs';
4
+
5
+ // ─── Section 4: resolveBackground (unified) ─────────────────────────────────
6
+
7
+ // Read the element's own background color, computed-style first, with a
8
+ // jsdom-friendly fallback that parses the inline `background:` shorthand
9
+ // from the raw style attribute. jsdom (~v29) does not decompose the
10
+ // shorthand into `backgroundColor`, so without this fallback the CLI silently
11
+ // returns null for any element styled via `background: rgb(...)` or
12
+ // `background: #abc`. Real browsers always decompose, so the fallback is
13
+ // a no-op there.
14
+ function readOwnBackgroundColor(el, computedStyle) {
15
+ const bg = parseRgb(computedStyle.backgroundColor);
16
+ if (DETECTOR_IS_BROWSER || (bg && bg.a >= 0.1)) return bg;
17
+ const rawStyle = el.getAttribute?.('style') || '';
18
+ const bgMatch = rawStyle.match(/background(?:-color)?\s*:\s*([^;]+)/i);
19
+ const inlineBg = bgMatch ? bgMatch[1].trim() : '';
20
+ if (!inlineBg) return bg;
21
+ if (/gradient/i.test(inlineBg) || /url\s*\(/i.test(inlineBg)) return bg;
22
+ const fromRgb = parseRgb(inlineBg);
23
+ if (fromRgb) return fromRgb;
24
+ const hexMatch = inlineBg.match(/#([0-9a-f]{6}|[0-9a-f]{3})\b/i);
25
+ if (hexMatch) {
26
+ const h = hexMatch[1];
27
+ if (h.length === 6) {
28
+ return { r: parseInt(h.slice(0, 2), 16), g: parseInt(h.slice(2, 4), 16), b: parseInt(h.slice(4, 6), 16), a: 1 };
29
+ }
30
+ return { r: parseInt(h[0] + h[0], 16), g: parseInt(h[1] + h[1], 16), b: parseInt(h[2] + h[2], 16), a: 1 };
31
+ }
32
+ return bg;
33
+ }
34
+
35
+ function resolveBackground(el, win, customPropMap) {
36
+ let current = el;
37
+ while (current && current.nodeType === 1) {
38
+ const style = DETECTOR_IS_BROWSER ? getComputedStyle(current) : win.getComputedStyle(current);
39
+ const bgImage = style.backgroundImage || '';
40
+ const hasGradientOrUrl = bgImage && bgImage !== 'none' && (/gradient/i.test(bgImage) || /url\s*\(/i.test(bgImage));
41
+
42
+ // Try the solid bg-color FIRST. If the element has both a solid color
43
+ // and a gradient/url overlay (a common pattern: `background: var(--paper)
44
+ // radial-gradient(...)` for paper-grain texture), the solid color is the
45
+ // dominant visible surface for contrast purposes; the overlay is
46
+ // decorative. The old behavior bailed on any gradient ancestor, which
47
+ // caused massive false-positive contrast findings on grain-textured
48
+ // body backgrounds.
49
+ let bg = parseRgb(style.backgroundColor);
50
+ if (!DETECTOR_IS_BROWSER && (!bg || bg.a < 0.1)) {
51
+ // jsdom returns literal "var(--X)" / "oklch(...)" strings. Resolve
52
+ // through customPropMap so Tailwind v4 color tokens become RGB.
53
+ if (customPropMap) {
54
+ bg = parseColorResolved(style.backgroundColor, customPropMap);
55
+ }
56
+ if (!bg || bg.a < 0.1) {
57
+ // Inline-style fallback. jsdom doesn't decompose background
58
+ // shorthand, so colors set via inline style are otherwise invisible.
59
+ const rawStyle = current.getAttribute?.('style') || '';
60
+ const bgMatch = rawStyle.match(/background(?:-color)?\s*:\s*([^;]+)/i);
61
+ const inlineBg = bgMatch ? bgMatch[1].trim() : '';
62
+ if (inlineBg && !/gradient/i.test(inlineBg) && !/url\s*\(/i.test(inlineBg)) {
63
+ bg = parseColorResolved(inlineBg, customPropMap) || parseAnyColor(inlineBg);
64
+ }
65
+ }
66
+ }
67
+
68
+ if (bg && bg.a > 0.1) {
69
+ if (DETECTOR_IS_BROWSER || bg.a >= 0.5) return bg;
70
+ }
71
+ // No solid bg-color at this level. If THIS level has a gradient/url
72
+ // with no underlying solid color we can read:
73
+ // • on body/html: assume white. Body-level gradients are almost
74
+ // always decorative texture (paper grain, noise) on top of a
75
+ // solid bg-color the page set via `background: var(--paper)`
76
+ // shorthand — which jsdom can't decompose into bg-color. The
77
+ // downstream gradient-stops fallback path produces catastrophic
78
+ // false positives in this case (gradient noise stops have
79
+ // accidental browns/blacks that look like card backgrounds).
80
+ // • on other elements: bail to null and let the caller fall back
81
+ // to gradient stops (gradient buttons / hero sections are real
82
+ // bgs worth checking against).
83
+ if (hasGradientOrUrl) {
84
+ if (current.tagName === 'BODY' || current.tagName === 'HTML') {
85
+ return { r: 255, g: 255, b: 255, a: 1 };
86
+ }
87
+ return null;
88
+ }
89
+ current = current.parentElement;
90
+ }
91
+ return { r: 255, g: 255, b: 255 };
92
+ }
93
+
94
+ // Walk parents looking for a gradient background and return its color stops.
95
+ // Used as a fallback when resolveBackground() returns null because the
96
+ // effective background is a gradient (no single solid color to compare against).
97
+ function resolveGradientStops(el, win) {
98
+ let current = el;
99
+ while (current && current.nodeType === 1) {
100
+ const style = DETECTOR_IS_BROWSER ? getComputedStyle(current) : win.getComputedStyle(current);
101
+ const bgImage = style.backgroundImage || '';
102
+ if (bgImage && bgImage !== 'none' && /gradient/i.test(bgImage)) {
103
+ const stops = parseGradientColors(bgImage);
104
+ if (stops.length > 0) return stops;
105
+ }
106
+ if (!DETECTOR_IS_BROWSER) {
107
+ // jsdom doesn't decompose `background:` shorthand — peek at the raw inline style
108
+ const rawStyle = current.getAttribute?.('style') || '';
109
+ const bgMatch = rawStyle.match(/background(?:-image)?\s*:\s*([^;]+)/i);
110
+ if (bgMatch && /gradient/i.test(bgMatch[1])) {
111
+ const stops = parseGradientColors(bgMatch[1]);
112
+ if (stops.length > 0) return stops;
113
+ }
114
+ }
115
+ current = current.parentElement;
116
+ }
117
+ return null;
118
+ }
119
+
120
+ // Parse a single CSS length token to pixels. Accepts "12px", "50%", a
121
+ // shorthand like "12px 4px" (uses the first value), or empty / null.
122
+ // Returns the pixel value, or null when the input is unparseable.
123
+ // Percentages convert against `widthPx` when one is supplied. Without a
124
+ // usable width (jsdom returns "auto" for many real-world elements,
125
+ // which parseFloat collapses to 0), fall back to the raw percentage
126
+ // number so callers gating on `> 0` (border-accent-on-rounded,
127
+ // isCardLike's hasRadius) still see a positive value, matching the
128
+ // original parseFloat("50%") === 50 behavior.
129
+ function parseRadiusToPx(value, widthPx) {
130
+ if (!value || typeof value !== 'string') return null;
131
+ const trimmed = value.trim();
132
+ if (!trimmed) return null;
133
+ const first = trimmed.split(/\s+/)[0];
134
+ const num = parseFloat(first);
135
+ if (Number.isNaN(num)) return null;
136
+ if (/%$/.test(first)) {
137
+ if (widthPx && widthPx > 0) return (num / 100) * widthPx;
138
+ return num;
139
+ }
140
+ return num;
141
+ }
142
+
143
+ function resolveBorderRadiusPx(_el, style, widthPx, _win) {
144
+ const fromComputed = parseRadiusToPx(style.borderRadius, widthPx);
145
+ if (fromComputed !== null) return fromComputed;
146
+ return 0;
147
+ }
148
+
149
+ export {
150
+ readOwnBackgroundColor,
151
+ resolveBackground,
152
+ resolveGradientStops,
153
+ parseRadiusToPx,
154
+ resolveBorderRadiusPx,
155
+ };