impeccable 2.3.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -5
- package/README.npm.md +17 -5
- package/README.repo.md +79 -25
- package/cli/bin/cli.js +48 -29
- package/cli/bin/commands/skills.mjs +1227 -260
- package/cli/engine/browser/injected/index.mjs +17 -7
- package/cli/engine/detect-antipatterns-browser.js +410 -50
- package/cli/engine/engines/regex/detect-text.mjs +16 -4
- package/cli/engine/engines/static-html/css-cascade.mjs +27 -0
- package/cli/engine/node/file-system.mjs +1 -1
- package/cli/engine/rules/checks.mjs +394 -43
- package/cli/lib/impeccable-config.mjs +119 -0
- package/package.json +30 -18
|
@@ -974,11 +974,16 @@ function parseAnyColor(s) {
|
|
|
974
974
|
// OKLCH parser. Tailwind v4's CSS minifier squishes the space after
|
|
975
975
|
// `%` ("21.5%.02 50"), so the separator between L and C may be absent.
|
|
976
976
|
// Match L (with optional %), then C and H separated permissively.
|
|
977
|
-
m = str.match(/oklch\(\s*([\d.]+)(%?)\s*[\s,]*\s*([\d.]+)\s*[\s,]+\s*([-\d.]+)(?:deg)?\s*\)/i);
|
|
977
|
+
m = str.match(/oklch\(\s*([\d.]+)(%?)\s*[\s,]*\s*([\d.]+)\s*[\s,]+\s*([-\d.]+)(?:deg)?(?:\s*\/\s*([\d.]+)(%)?)?\s*\)/i);
|
|
978
978
|
if (m) {
|
|
979
979
|
const Lnum = parseFloat(m[1]);
|
|
980
980
|
const L = m[2] === '%' ? Lnum / 100 : Lnum;
|
|
981
|
-
|
|
981
|
+
const rgb = oklchToRgb(L, parseFloat(m[3]), parseFloat(m[4]));
|
|
982
|
+
if (m[5] !== undefined) {
|
|
983
|
+
const alpha = parseFloat(m[5]);
|
|
984
|
+
rgb.a = m[6] === '%' ? alpha / 100 : alpha;
|
|
985
|
+
}
|
|
986
|
+
return rgb;
|
|
982
987
|
}
|
|
983
988
|
return null;
|
|
984
989
|
}
|
|
@@ -1007,9 +1012,19 @@ const REPEATED_KICKER_SKIP_SELECTOR = [
|
|
|
1007
1012
|
'[role="navigation"]',
|
|
1008
1013
|
'[aria-label*="breadcrumb" i]',
|
|
1009
1014
|
'[class*="breadcrumb" i]',
|
|
1015
|
+
'[aria-hidden="true"]',
|
|
1010
1016
|
'[data-impeccable-allow-kickers]',
|
|
1011
1017
|
].join(',');
|
|
1012
1018
|
|
|
1019
|
+
const REPEATED_KICKER_CARD_CONTEXT_SELECTOR = [
|
|
1020
|
+
'article',
|
|
1021
|
+
'button',
|
|
1022
|
+
'a',
|
|
1023
|
+
'li',
|
|
1024
|
+
'[role="listitem"]',
|
|
1025
|
+
'[role="option"]',
|
|
1026
|
+
].join(',');
|
|
1027
|
+
|
|
1013
1028
|
function cleanInlineText(el) {
|
|
1014
1029
|
return [...el.childNodes]
|
|
1015
1030
|
.filter(n => n.nodeType === 3)
|
|
@@ -1019,6 +1034,11 @@ function cleanInlineText(el) {
|
|
|
1019
1034
|
.trim();
|
|
1020
1035
|
}
|
|
1021
1036
|
|
|
1037
|
+
function isRepeatedKickerCardContext(heading, kicker) {
|
|
1038
|
+
const item = heading.closest?.(REPEATED_KICKER_CARD_CONTEXT_SELECTOR);
|
|
1039
|
+
return Boolean(item && (!item.contains || item.contains(kicker)));
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1022
1042
|
function isRepeatedKickerCandidate(opts) {
|
|
1023
1043
|
const {
|
|
1024
1044
|
headingTag,
|
|
@@ -1032,6 +1052,7 @@ function isRepeatedKickerCandidate(opts) {
|
|
|
1032
1052
|
} = opts;
|
|
1033
1053
|
if (!['h2', 'h3', 'h4'].includes(headingTag)) return false;
|
|
1034
1054
|
if (!headingText || headingText.length < 3) return false;
|
|
1055
|
+
if (/^\/[\w-]+/i.test(headingText.replace(/^"|"$/g, '').trim())) return false;
|
|
1035
1056
|
if (!(headingFontSize >= 20)) return false;
|
|
1036
1057
|
if (!kickerTag || HEADING_TAGS.has(kickerTag)) return false;
|
|
1037
1058
|
if (!['p', 'span', 'div', 'small'].includes(kickerTag)) return false;
|
|
@@ -1053,6 +1074,7 @@ function collectRepeatedSectionKickerCandidates(doc, getStyle, resolveLetterSpac
|
|
|
1053
1074
|
if (heading.closest?.(REPEATED_KICKER_SKIP_SELECTOR)) continue;
|
|
1054
1075
|
const kicker = heading.previousElementSibling;
|
|
1055
1076
|
if (!kicker || kicker.closest?.(REPEATED_KICKER_SKIP_SELECTOR)) continue;
|
|
1077
|
+
if (isRepeatedKickerCardContext(heading, kicker)) continue;
|
|
1056
1078
|
|
|
1057
1079
|
const headingStyle = getStyle(heading);
|
|
1058
1080
|
const kickerStyle = getStyle(kicker);
|
|
@@ -1235,6 +1257,84 @@ function resolveLengthPx(value, fontSizePx) {
|
|
|
1235
1257
|
return num * fontSizePx;
|
|
1236
1258
|
}
|
|
1237
1259
|
|
|
1260
|
+
function cssColorIsTransparent(value) {
|
|
1261
|
+
if (!value) return true;
|
|
1262
|
+
const str = String(value).trim().toLowerCase();
|
|
1263
|
+
if (!str || str === 'transparent' || str === 'rgba(0, 0, 0, 0)') return true;
|
|
1264
|
+
const parsed = parseAnyColor(str);
|
|
1265
|
+
if (parsed) return (parsed.a ?? 1) <= 0.05;
|
|
1266
|
+
return /^rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*0(?:\.0+)?\s*\)$/.test(str);
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
function colorsNearlyMatch(a, b) {
|
|
1270
|
+
const ca = parseAnyColor(a);
|
|
1271
|
+
const cb = parseAnyColor(b);
|
|
1272
|
+
if (!ca || !cb) return false;
|
|
1273
|
+
const alphaDelta = Math.abs((ca.a ?? 1) - (cb.a ?? 1));
|
|
1274
|
+
const channelDelta = Math.max(
|
|
1275
|
+
Math.abs(ca.r - cb.r),
|
|
1276
|
+
Math.abs(ca.g - cb.g),
|
|
1277
|
+
Math.abs(ca.b - cb.b),
|
|
1278
|
+
);
|
|
1279
|
+
return alphaDelta <= 0.03 && channelDelta <= 3;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
function getComputedStyleFor(win, el) {
|
|
1283
|
+
if (win && typeof win.getComputedStyle === 'function') {
|
|
1284
|
+
try { return win.getComputedStyle(el); } catch {}
|
|
1285
|
+
}
|
|
1286
|
+
if (typeof getComputedStyle === 'function') {
|
|
1287
|
+
try { return getComputedStyle(el); } catch {}
|
|
1288
|
+
}
|
|
1289
|
+
return null;
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
function hasVisibleBackgroundBoundary(style, el, win) {
|
|
1293
|
+
const bg = style?.backgroundColor || '';
|
|
1294
|
+
if (cssColorIsTransparent(bg)) return false;
|
|
1295
|
+
|
|
1296
|
+
let parent = el?.parentElement || null;
|
|
1297
|
+
while (parent) {
|
|
1298
|
+
const parentStyle = getComputedStyleFor(win, parent);
|
|
1299
|
+
const parentBg = parentStyle?.backgroundColor || '';
|
|
1300
|
+
if (!cssColorIsTransparent(parentBg)) {
|
|
1301
|
+
return !colorsNearlyMatch(bg, parentBg);
|
|
1302
|
+
}
|
|
1303
|
+
parent = parent.parentElement;
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
return true;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
const TEXT_EDGE_TAGS = new Set(['A', 'BUTTON', 'CODE', 'DD', 'DT', 'FIGCAPTION', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'LI', 'P', 'PRE', 'SPAN', 'TD', 'TH']);
|
|
1310
|
+
|
|
1311
|
+
function hasMeaningfulDirectText(node) {
|
|
1312
|
+
if (!node?.childNodes) return false;
|
|
1313
|
+
for (const child of node.childNodes) {
|
|
1314
|
+
if (child.nodeType === 3 && child.textContent.trim().length > 4) return true;
|
|
1315
|
+
}
|
|
1316
|
+
return false;
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
function textDescendantsFlushSides(el, rect) {
|
|
1320
|
+
const flush = { top: false, right: false, bottom: false, left: false };
|
|
1321
|
+
if (!rect || !el?.querySelectorAll) return flush;
|
|
1322
|
+
const TEXT_EDGE_THRESHOLD = 4;
|
|
1323
|
+
const candidates = el.querySelectorAll('a, button, code, dd, dt, figcaption, h1, h2, h3, h4, h5, h6, li, p, pre, span, td, th');
|
|
1324
|
+
for (const node of candidates) {
|
|
1325
|
+
if (!TEXT_EDGE_TAGS.has(node.tagName) || !hasMeaningfulDirectText(node)) continue;
|
|
1326
|
+
let nodeRect = null;
|
|
1327
|
+
try { nodeRect = node.getBoundingClientRect(); } catch {}
|
|
1328
|
+
if (!nodeRect || nodeRect.width <= 0 || nodeRect.height <= 0) continue;
|
|
1329
|
+
if (nodeRect.bottom < rect.top || nodeRect.top > rect.bottom || nodeRect.right < rect.left || nodeRect.left > rect.right) continue;
|
|
1330
|
+
if (nodeRect.top - rect.top <= TEXT_EDGE_THRESHOLD) flush.top = true;
|
|
1331
|
+
if (rect.right - nodeRect.right <= TEXT_EDGE_THRESHOLD) flush.right = true;
|
|
1332
|
+
if (rect.bottom - nodeRect.bottom <= TEXT_EDGE_THRESHOLD) flush.bottom = true;
|
|
1333
|
+
if (nodeRect.left - rect.left <= TEXT_EDGE_THRESHOLD) flush.left = true;
|
|
1334
|
+
}
|
|
1335
|
+
return flush;
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1238
1338
|
// Pure quality checks. Most run on computed CSS and DOM-only inputs (work in
|
|
1239
1339
|
// jsdom and the browser). Two checks (line-length, cramped-padding) gate on
|
|
1240
1340
|
// element rect dimensions, which jsdom can't compute — pass `rect: null` from
|
|
@@ -1264,7 +1364,8 @@ function checkQuality(opts) {
|
|
|
1264
1364
|
// font-size — bigger text demands proportionally more padding.
|
|
1265
1365
|
// vertical: max(4px, fontSize × 0.3)
|
|
1266
1366
|
// horizontal: max(8px, fontSize × 0.5)
|
|
1267
|
-
|
|
1367
|
+
const isInlineCode = tag === 'code' && !(el.closest && el.closest('pre'));
|
|
1368
|
+
if (!isInlineCode && rect && hasDirectText && textLen > 20 && rect.width > 100 && rect.height > 30) {
|
|
1268
1369
|
const borders = {
|
|
1269
1370
|
top: parseFloat(style.borderTopWidth) || 0,
|
|
1270
1371
|
right: parseFloat(style.borderRightWidth) || 0,
|
|
@@ -1272,7 +1373,7 @@ function checkQuality(opts) {
|
|
|
1272
1373
|
left: parseFloat(style.borderLeftWidth) || 0,
|
|
1273
1374
|
};
|
|
1274
1375
|
const borderCount = Object.values(borders).filter(w => w > 0).length;
|
|
1275
|
-
const hasBg = style
|
|
1376
|
+
const hasBg = hasVisibleBackgroundBoundary(style, el, win);
|
|
1276
1377
|
if (borderCount >= 2 || hasBg) {
|
|
1277
1378
|
const vPads = [], hPads = [];
|
|
1278
1379
|
if (hasBg || borders.top > 0) vPads.push(parseFloat(style.paddingTop) || 0);
|
|
@@ -1320,10 +1421,6 @@ function checkQuality(opts) {
|
|
|
1320
1421
|
!['fixed', 'absolute'].includes(elPosition) &&
|
|
1321
1422
|
el.children && el.children.length > 0
|
|
1322
1423
|
) {
|
|
1323
|
-
const isTransparent = (c) =>
|
|
1324
|
-
!c || c === 'transparent' || c === 'rgba(0, 0, 0, 0)' ||
|
|
1325
|
-
/^rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*0(?:\.0+)?\s*\)$/.test(c);
|
|
1326
|
-
|
|
1327
1424
|
const borderW = {
|
|
1328
1425
|
top: parseFloat(style.borderTopWidth) || 0,
|
|
1329
1426
|
right: parseFloat(style.borderRightWidth) || 0,
|
|
@@ -1331,10 +1428,10 @@ function checkQuality(opts) {
|
|
|
1331
1428
|
left: parseFloat(style.borderLeftWidth) || 0,
|
|
1332
1429
|
};
|
|
1333
1430
|
const borderVisible = {
|
|
1334
|
-
top: borderW.top > 0 && !
|
|
1335
|
-
right: borderW.right > 0 && !
|
|
1336
|
-
bottom: borderW.bottom > 0 && !
|
|
1337
|
-
left: borderW.left > 0 && !
|
|
1431
|
+
top: borderW.top > 0 && !cssColorIsTransparent(style.borderTopColor),
|
|
1432
|
+
right: borderW.right > 0 && !cssColorIsTransparent(style.borderRightColor),
|
|
1433
|
+
bottom: borderW.bottom > 0 && !cssColorIsTransparent(style.borderBottomColor),
|
|
1434
|
+
left: borderW.left > 0 && !cssColorIsTransparent(style.borderLeftColor),
|
|
1338
1435
|
};
|
|
1339
1436
|
// Outline detection. jsdom decomposes `border` shorthand into
|
|
1340
1437
|
// border{Top,…}Width/Color but does NOT decompose `outline` —
|
|
@@ -1354,8 +1451,8 @@ function checkQuality(opts) {
|
|
|
1354
1451
|
if (cMatch) outlineColorVal = cMatch[1];
|
|
1355
1452
|
}
|
|
1356
1453
|
}
|
|
1357
|
-
const outlineVisible = outlineW > 0 && !
|
|
1358
|
-
const bgVisible =
|
|
1454
|
+
const outlineVisible = outlineW > 0 && !cssColorIsTransparent(outlineColorVal) && outlineStyleVal && outlineStyleVal !== 'none';
|
|
1455
|
+
const bgVisible = hasVisibleBackgroundBoundary(style, el, win);
|
|
1359
1456
|
|
|
1360
1457
|
const anyVisible = borderVisible.top || borderVisible.right || borderVisible.bottom || borderVisible.left || outlineVisible || bgVisible;
|
|
1361
1458
|
if (anyVisible) {
|
|
@@ -1383,13 +1480,7 @@ function checkQuality(opts) {
|
|
|
1383
1480
|
const CHILD_INSULATE_THRESHOLD = 4;
|
|
1384
1481
|
const childrenInsulate = { top: false, right: false, bottom: false, left: false };
|
|
1385
1482
|
for (const child of el.children) {
|
|
1386
|
-
let childStyle =
|
|
1387
|
-
if (win && typeof win.getComputedStyle === 'function') {
|
|
1388
|
-
try { childStyle = win.getComputedStyle(child); } catch {}
|
|
1389
|
-
}
|
|
1390
|
-
if (!childStyle && typeof getComputedStyle === 'function') {
|
|
1391
|
-
try { childStyle = getComputedStyle(child); } catch {}
|
|
1392
|
-
}
|
|
1483
|
+
let childStyle = getComputedStyleFor(win, child);
|
|
1393
1484
|
if (!childStyle) continue;
|
|
1394
1485
|
const childPad = {
|
|
1395
1486
|
top: resolveLengthPx(childStyle.paddingTop, fontSize) ?? 0,
|
|
@@ -1397,15 +1488,37 @@ function checkQuality(opts) {
|
|
|
1397
1488
|
bottom: resolveLengthPx(childStyle.paddingBottom, fontSize) ?? 0,
|
|
1398
1489
|
left: resolveLengthPx(childStyle.paddingLeft, fontSize) ?? 0,
|
|
1399
1490
|
};
|
|
1491
|
+
const childMargin = {
|
|
1492
|
+
top: resolveLengthPx(childStyle.marginTop, fontSize) ?? 0,
|
|
1493
|
+
right: resolveLengthPx(childStyle.marginRight, fontSize) ?? 0,
|
|
1494
|
+
bottom: resolveLengthPx(childStyle.marginBottom, fontSize) ?? 0,
|
|
1495
|
+
left: resolveLengthPx(childStyle.marginLeft, fontSize) ?? 0,
|
|
1496
|
+
};
|
|
1497
|
+
if (rect && typeof child.getBoundingClientRect === 'function') {
|
|
1498
|
+
try {
|
|
1499
|
+
const childRect = child.getBoundingClientRect();
|
|
1500
|
+
if (childRect && childRect.width > 0 && childRect.height > 0) {
|
|
1501
|
+
if (childRect.top - rect.top >= CHILD_INSULATE_THRESHOLD) childrenInsulate.top = true;
|
|
1502
|
+
if (rect.right - childRect.right >= CHILD_INSULATE_THRESHOLD) childrenInsulate.right = true;
|
|
1503
|
+
if (rect.bottom - childRect.bottom >= CHILD_INSULATE_THRESHOLD) childrenInsulate.bottom = true;
|
|
1504
|
+
if (childRect.left - rect.left >= CHILD_INSULATE_THRESHOLD) childrenInsulate.left = true;
|
|
1505
|
+
}
|
|
1506
|
+
} catch {}
|
|
1507
|
+
}
|
|
1400
1508
|
for (const s of ['top', 'right', 'bottom', 'left']) {
|
|
1401
|
-
if (childPad[s] >= CHILD_INSULATE_THRESHOLD
|
|
1509
|
+
if (childPad[s] >= CHILD_INSULATE_THRESHOLD || childMargin[s] >= CHILD_INSULATE_THRESHOLD) {
|
|
1510
|
+
childrenInsulate[s] = true;
|
|
1511
|
+
}
|
|
1402
1512
|
}
|
|
1403
1513
|
}
|
|
1404
1514
|
|
|
1515
|
+
const textFlush = rect ? textDescendantsFlushSides(el, rect) : null;
|
|
1516
|
+
const fullBleedBgBand = rect && viewportWidth > 0 && rect.width >= viewportWidth * 0.94 && bgVisible && !outlineVisible;
|
|
1405
1517
|
const flushSides = [];
|
|
1406
1518
|
for (const side of ['top', 'right', 'bottom', 'left']) {
|
|
1407
|
-
const
|
|
1408
|
-
|
|
1519
|
+
const bgBoundsSide = bgVisible && !(fullBleedBgBand && (side === 'left' || side === 'right'));
|
|
1520
|
+
const sideBounded = borderVisible[side] || outlineVisible || bgBoundsSide;
|
|
1521
|
+
if (sideBounded && pad[side] <= PAD_THRESHOLD && !childrenInsulate[side] && (!textFlush || textFlush[side])) {
|
|
1409
1522
|
flushSides.push(side);
|
|
1410
1523
|
}
|
|
1411
1524
|
}
|
|
@@ -1499,7 +1612,7 @@ function checkQuality(opts) {
|
|
|
1499
1612
|
// Only flag actual body content, not UI labels (buttons, tabs, badges, captions, footer text, etc.)
|
|
1500
1613
|
if (hasDirectText && textLen > 20 && fontSize < 12) {
|
|
1501
1614
|
const skipTags = ['sub', 'sup', 'code', 'kbd', 'samp', 'var', 'caption', 'figcaption'];
|
|
1502
|
-
const inUIContext = el.closest && el.closest('button, a, label, summary, [role="button"], [role="link"], [role="tab"], [role="menuitem"], [role="option"], nav, footer, [class*="badge" i], [class*="chip" i], [class*="pill" i], [class*="tag" i], [class*="
|
|
1615
|
+
const inUIContext = el.closest && el.closest('button, a, label, summary, pre, [role="button"], [role="link"], [role="tab"], [role="menuitem"], [role="option"], nav, footer, [aria-hidden="true"], [class*="badge" i], [class*="caption" i], [class*="chip" i], [class*="code" i], [class*="console" i], [class*="diff" i], [class*="label" i], [class*="meta" i], [class*="mock" i], [class*="pill" i], [class*="preview" i], [class*="tag" i], [class*="terminal" i], [class*="writes" i]');
|
|
1503
1616
|
const isUppercase = style.textTransform === 'uppercase';
|
|
1504
1617
|
if (!skipTags.includes(tag) && !inUIContext && !isUppercase) {
|
|
1505
1618
|
findings.push({ id: 'tiny-text', snippet: `${fontSize}px body text` });
|
|
@@ -2107,17 +2220,28 @@ function checkCreamPalette(doc, win) {
|
|
|
2107
2220
|
}
|
|
2108
2221
|
|
|
2109
2222
|
// ─── Oversized hero headline ────────────────────────────────────────────────
|
|
2110
|
-
// Fires when a *long* headline is set at display size
|
|
2111
|
-
//
|
|
2112
|
-
//
|
|
2113
|
-
//
|
|
2223
|
+
// Fires when a *long* headline is set at display size and actually dominates
|
|
2224
|
+
// the viewport. A punchy one- or two-word headline at the same size is a
|
|
2225
|
+
// legitimate stylistic choice, and a large-but-contained two-line hero should
|
|
2226
|
+
// pass too — length and viewport share together are the tell.
|
|
2114
2227
|
const OVERSIZED_H1_FONT_PX = 72;
|
|
2115
2228
|
const OVERSIZED_H1_MIN_CHARS = 40;
|
|
2116
|
-
|
|
2229
|
+
const OVERSIZED_H1_MIN_VIEWPORT_HEIGHT_RATIO = 0.28;
|
|
2230
|
+
const OVERSIZED_H1_MIN_VIEWPORT_AREA_RATIO = 0.25;
|
|
2231
|
+
function checkOversizedH1({ tag, fontSize, headingText, rect = null, viewportWidth = 0, viewportHeight = 0 }) {
|
|
2117
2232
|
if (tag !== 'h1') return [];
|
|
2118
2233
|
const textLen = headingText.length;
|
|
2119
2234
|
if (fontSize >= OVERSIZED_H1_FONT_PX && textLen >= OVERSIZED_H1_MIN_CHARS) {
|
|
2120
|
-
|
|
2235
|
+
let viewportDetail = '';
|
|
2236
|
+
if (rect && viewportWidth > 0 && viewportHeight > 0) {
|
|
2237
|
+
const heightRatio = rect.height / viewportHeight;
|
|
2238
|
+
const areaRatio = (rect.width * rect.height) / (viewportWidth * viewportHeight);
|
|
2239
|
+
const dominatesViewport = heightRatio >= OVERSIZED_H1_MIN_VIEWPORT_HEIGHT_RATIO
|
|
2240
|
+
|| areaRatio >= OVERSIZED_H1_MIN_VIEWPORT_AREA_RATIO;
|
|
2241
|
+
if (!dominatesViewport) return [];
|
|
2242
|
+
viewportDetail = `, ${Math.round(heightRatio * 100)}vh`;
|
|
2243
|
+
}
|
|
2244
|
+
return [{ id: 'oversized-h1', snippet: `${Math.round(fontSize)}px h1, ${textLen} chars${viewportDetail} "${headingText.slice(0, 60)}"` }];
|
|
2121
2245
|
}
|
|
2122
2246
|
return [];
|
|
2123
2247
|
}
|
|
@@ -2135,31 +2259,54 @@ function checkElementOversizedH1DOM(el) {
|
|
|
2135
2259
|
const style = getComputedStyle(el);
|
|
2136
2260
|
const fontSize = parseFloat(style.fontSize) || 0;
|
|
2137
2261
|
const headingText = (el.textContent || '').trim().replace(/\s+/g, ' ');
|
|
2138
|
-
|
|
2262
|
+
const rect = el.getBoundingClientRect();
|
|
2263
|
+
const viewportWidth = (typeof window !== 'undefined' ? window.innerWidth : 0) || 0;
|
|
2264
|
+
const viewportHeight = (typeof window !== 'undefined' ? window.innerHeight : 0) || 0;
|
|
2265
|
+
return checkOversizedH1({ tag, fontSize, headingText, rect, viewportWidth, viewportHeight });
|
|
2139
2266
|
}
|
|
2140
2267
|
|
|
2141
2268
|
// ─── GPT tell: hairline border + wide diffuse shadow (gated --gpt) ────────────
|
|
2142
|
-
|
|
2269
|
+
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;
|
|
2270
|
+
|
|
2271
|
+
function shadowLayerAlpha(layer) {
|
|
2272
|
+
CSS_COLOR_TOKEN_RE.lastIndex = 0;
|
|
2273
|
+
const match = CSS_COLOR_TOKEN_RE.exec(layer);
|
|
2274
|
+
if (!match) return 1;
|
|
2275
|
+
if (match[0].toLowerCase() === 'transparent') return 0;
|
|
2276
|
+
const parsed = parseAnyColor(match[0]);
|
|
2277
|
+
return parsed ? (parsed.a ?? 1) : 1;
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2280
|
+
function shadowMaxBlurPx(boxShadow, { minAlpha = 0 } = {}) {
|
|
2143
2281
|
if (!boxShadow || boxShadow === 'none') return 0;
|
|
2144
2282
|
let maxBlur = 0;
|
|
2145
2283
|
// Split into layers on commas not inside parentheses (rgba(...) etc.).
|
|
2146
2284
|
for (const layer of boxShadow.split(/,(?![^()]*\))/)) {
|
|
2285
|
+
if (shadowLayerAlpha(layer) < minAlpha) continue;
|
|
2147
2286
|
// Strip colors and keywords (rgba()/hsl()/hex/named/inset/px), leaving the
|
|
2148
2287
|
// ordered length tokens: offsetX offsetY blur [spread]. Static jsdom keeps
|
|
2149
2288
|
// unitless zeros ("0 0 24px"); browsers normalize to px ("0px 0px 24px") —
|
|
2150
2289
|
// both reduce to the same numbers here.
|
|
2151
|
-
const cleaned = layer.replace(
|
|
2290
|
+
const cleaned = layer.replace(CSS_COLOR_TOKEN_RE, ' ').replace(/\b[a-z]+\b/gi, ' ');
|
|
2152
2291
|
const nums = [...cleaned.matchAll(/-?\d*\.?\d+/g)].map(m => parseFloat(m[0]));
|
|
2153
2292
|
if (nums.length >= 3) maxBlur = Math.max(maxBlur, nums[2]);
|
|
2154
2293
|
}
|
|
2155
2294
|
return maxBlur;
|
|
2156
2295
|
}
|
|
2157
2296
|
|
|
2158
|
-
function
|
|
2159
|
-
|
|
2160
|
-
const
|
|
2161
|
-
|
|
2162
|
-
|
|
2297
|
+
function cssColorAlpha(value) {
|
|
2298
|
+
if (cssColorIsTransparent(value)) return 0;
|
|
2299
|
+
const parsed = parseAnyColor(value);
|
|
2300
|
+
return parsed ? (parsed.a ?? 1) : 1;
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
function checkGptThinBorderWideShadow({ borderWidths, borderColors, boxShadow }) {
|
|
2304
|
+
const visibleThinBorders = borderWidths
|
|
2305
|
+
.map((width, index) => ({ width, alpha: cssColorAlpha(borderColors?.[index] || '') }))
|
|
2306
|
+
.filter(({ width, alpha }) => width > 0 && width <= 1.5 && alpha >= 0.28);
|
|
2307
|
+
const maxBorder = Math.max(0, ...visibleThinBorders.map(({ width }) => width));
|
|
2308
|
+
const blur = shadowMaxBlurPx(boxShadow, { minAlpha: 0.12 });
|
|
2309
|
+
if (visibleThinBorders.length >= 2 && blur >= 16) {
|
|
2163
2310
|
return [{ id: 'gpt-thin-border-wide-shadow', snippet: `${maxBorder}px border + ${Math.round(blur)}px shadow blur` }];
|
|
2164
2311
|
}
|
|
2165
2312
|
return [];
|
|
@@ -2174,13 +2321,22 @@ function borderWidthsFromStyle(style) {
|
|
|
2174
2321
|
];
|
|
2175
2322
|
}
|
|
2176
2323
|
|
|
2324
|
+
function borderColorsFromStyle(style) {
|
|
2325
|
+
return [
|
|
2326
|
+
style.borderTopColor || '',
|
|
2327
|
+
style.borderRightColor || '',
|
|
2328
|
+
style.borderBottomColor || '',
|
|
2329
|
+
style.borderLeftColor || '',
|
|
2330
|
+
];
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2177
2333
|
function checkElementGptBorderShadow(el, style) {
|
|
2178
|
-
return checkGptThinBorderWideShadow({ borderWidths: borderWidthsFromStyle(style), boxShadow: style.boxShadow || '' });
|
|
2334
|
+
return checkGptThinBorderWideShadow({ borderWidths: borderWidthsFromStyle(style), borderColors: borderColorsFromStyle(style), boxShadow: style.boxShadow || '' });
|
|
2179
2335
|
}
|
|
2180
2336
|
|
|
2181
2337
|
function checkElementGptBorderShadowDOM(el) {
|
|
2182
2338
|
const style = getComputedStyle(el);
|
|
2183
|
-
return checkGptThinBorderWideShadow({ borderWidths: borderWidthsFromStyle(style), boxShadow: style.boxShadow || '' });
|
|
2339
|
+
return checkGptThinBorderWideShadow({ borderWidths: borderWidthsFromStyle(style), borderColors: borderColorsFromStyle(style), boxShadow: style.boxShadow || '' });
|
|
2184
2340
|
}
|
|
2185
2341
|
|
|
2186
2342
|
// ─── Clipped overflow container ───────────────────────────────────────────────
|
|
@@ -2193,17 +2349,131 @@ function classSelector(el) {
|
|
|
2193
2349
|
return tokens.length ? `${tag}.${tokens.join('.')}` : tag;
|
|
2194
2350
|
}
|
|
2195
2351
|
|
|
2352
|
+
function positionedChildIsDecorative(child) {
|
|
2353
|
+
if (!child || typeof child.getAttribute !== 'function') return false;
|
|
2354
|
+
if (child.closest?.('[aria-hidden="true"]')) return true;
|
|
2355
|
+
const role = (child.getAttribute('role') || '').toLowerCase();
|
|
2356
|
+
if (role === 'none' || role === 'presentation') return true;
|
|
2357
|
+
const tag = child.tagName ? child.tagName.toLowerCase() : '';
|
|
2358
|
+
if (['img', 'svg', 'canvas', 'video'].includes(tag)) return true;
|
|
2359
|
+
const ident = `${child.getAttribute('class') || ''} ${child.getAttribute('id') || ''}`;
|
|
2360
|
+
if (
|
|
2361
|
+
/\b(art|bg|background|badge|blob|crop|decor|dot|glow|grain|image|mask|ornament|overlay|photo|scrim|shadow|shine|texture)\b/i.test(ident) &&
|
|
2362
|
+
!positionedChildHasSubstantiveContent(child)
|
|
2363
|
+
) {
|
|
2364
|
+
return true;
|
|
2365
|
+
}
|
|
2366
|
+
return false;
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2369
|
+
const POSITIONED_CHILD_INTERACTIVE_SELECTOR = [
|
|
2370
|
+
'a[href]',
|
|
2371
|
+
'button',
|
|
2372
|
+
'input',
|
|
2373
|
+
'select',
|
|
2374
|
+
'summary',
|
|
2375
|
+
'textarea',
|
|
2376
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
2377
|
+
'[role="button"]',
|
|
2378
|
+
'[role="dialog"]',
|
|
2379
|
+
'[role="link"]',
|
|
2380
|
+
'[role="listbox"]',
|
|
2381
|
+
'[role="menu"]',
|
|
2382
|
+
'[role="menuitem"]',
|
|
2383
|
+
'[role="option"]',
|
|
2384
|
+
'[role="tooltip"]',
|
|
2385
|
+
].join(',');
|
|
2386
|
+
|
|
2387
|
+
function positionedChildHasSubstantiveContent(child) {
|
|
2388
|
+
const text = (child.textContent || '').replace(/\s+/g, ' ').trim();
|
|
2389
|
+
if (text.length > 0) return true;
|
|
2390
|
+
if (typeof child.matches === 'function') {
|
|
2391
|
+
try {
|
|
2392
|
+
if (child.matches(POSITIONED_CHILD_INTERACTIVE_SELECTOR)) return true;
|
|
2393
|
+
} catch {}
|
|
2394
|
+
}
|
|
2395
|
+
if (typeof child.querySelector === 'function') {
|
|
2396
|
+
try {
|
|
2397
|
+
if (child.querySelector(POSITIONED_CHILD_INTERACTIVE_SELECTOR)) return true;
|
|
2398
|
+
} catch {}
|
|
2399
|
+
}
|
|
2400
|
+
return false;
|
|
2401
|
+
}
|
|
2402
|
+
|
|
2403
|
+
function clippingContainerIsIntentionalViewport(el) {
|
|
2404
|
+
if (!el || typeof el.getAttribute !== 'function') return false;
|
|
2405
|
+
const roleDescription = (el.getAttribute('aria-roledescription') || '').toLowerCase();
|
|
2406
|
+
if (/\b(carousel|slider)\b/.test(roleDescription)) return true;
|
|
2407
|
+
const ident = `${el.getAttribute('class') || ''} ${el.getAttribute('id') || ''}`.toLowerCase();
|
|
2408
|
+
return /\b(carousel|comparison|compare|fisheye|marquee|preview|scroller|slider|slideshow|split|viewport)\b/.test(ident) ||
|
|
2409
|
+
/\b(demo-area|demo-stage|demo-viewport)\b/.test(ident);
|
|
2410
|
+
}
|
|
2411
|
+
|
|
2412
|
+
function elementRect(el) {
|
|
2413
|
+
if (!el || typeof el.getBoundingClientRect !== 'function') return null;
|
|
2414
|
+
try {
|
|
2415
|
+
const rect = el.getBoundingClientRect();
|
|
2416
|
+
if (!rect) return null;
|
|
2417
|
+
const values = [rect.top, rect.right, rect.bottom, rect.left, rect.width, rect.height];
|
|
2418
|
+
if (!values.every(Number.isFinite)) return null;
|
|
2419
|
+
if (rect.width <= 0 && rect.height <= 0) return null;
|
|
2420
|
+
return rect;
|
|
2421
|
+
} catch {
|
|
2422
|
+
return null;
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
function positionedStyleImpliesEscape(style) {
|
|
2427
|
+
const values = [
|
|
2428
|
+
style.top,
|
|
2429
|
+
style.right,
|
|
2430
|
+
style.bottom,
|
|
2431
|
+
style.left,
|
|
2432
|
+
style.inset,
|
|
2433
|
+
style.insetBlock,
|
|
2434
|
+
style.insetInline,
|
|
2435
|
+
style.insetBlockStart,
|
|
2436
|
+
style.insetBlockEnd,
|
|
2437
|
+
style.insetInlineStart,
|
|
2438
|
+
style.insetInlineEnd,
|
|
2439
|
+
].filter(Boolean).map(value => String(value).trim().toLowerCase());
|
|
2440
|
+
for (const value of values) {
|
|
2441
|
+
if (/(^|[\s(])-+(?:\d|\.)/.test(value)) return true;
|
|
2442
|
+
if (/(^|[\s(])100(?:\.0+)?%/.test(value)) return true;
|
|
2443
|
+
}
|
|
2444
|
+
return false;
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
function positionedChildEscapesClip(el, child, clipX, clipY) {
|
|
2448
|
+
const parentRect = elementRect(el);
|
|
2449
|
+
const childRect = elementRect(child);
|
|
2450
|
+
if (!parentRect || !childRect) return null;
|
|
2451
|
+
const threshold = 2;
|
|
2452
|
+
return Boolean(
|
|
2453
|
+
(clipX && (childRect.left < parentRect.left - threshold || childRect.right > parentRect.right + threshold)) ||
|
|
2454
|
+
(clipY && (childRect.top < parentRect.top - threshold || childRect.bottom > parentRect.bottom + threshold))
|
|
2455
|
+
);
|
|
2456
|
+
}
|
|
2457
|
+
|
|
2196
2458
|
function checkClippedOverflow(el, style, getStyle) {
|
|
2197
2459
|
const clips = (v) => v === 'hidden' || v === 'clip';
|
|
2198
2460
|
const scrolls = (v) => v === 'auto' || v === 'scroll';
|
|
2199
2461
|
const ox = style.overflowX || '', oy = style.overflowY || '', ov = style.overflow || '';
|
|
2200
|
-
const
|
|
2462
|
+
const clipX = clips(ox) || clips(ov);
|
|
2463
|
+
const clipY = clips(oy) || clips(ov);
|
|
2464
|
+
const anyClip = clipX || clipY;
|
|
2201
2465
|
const anyScroll = scrolls(ox) || scrolls(oy) || scrolls(ov);
|
|
2202
2466
|
if (!anyClip || anyScroll) return [];
|
|
2467
|
+
if (clippingContainerIsIntentionalViewport(el)) return [];
|
|
2203
2468
|
if (!el.querySelectorAll) return [];
|
|
2204
2469
|
for (const child of el.querySelectorAll('*')) {
|
|
2205
|
-
const
|
|
2470
|
+
const childStyle = getStyle(child);
|
|
2471
|
+
const pos = childStyle.position || '';
|
|
2206
2472
|
if (pos === 'absolute' || pos === 'fixed') {
|
|
2473
|
+
if (positionedChildIsDecorative(child)) continue;
|
|
2474
|
+
const escapes = positionedChildEscapesClip(el, child, clipX, clipY);
|
|
2475
|
+
if (escapes === false) continue;
|
|
2476
|
+
if (escapes === null && !positionedStyleImpliesEscape(childStyle)) continue;
|
|
2207
2477
|
return [{ id: 'clipped-overflow-container', snippet: `${classSelector(el)} clips a positioned child` }];
|
|
2208
2478
|
}
|
|
2209
2479
|
}
|
|
@@ -2222,14 +2492,94 @@ function checkElementClippedOverflowDOM(el) {
|
|
|
2222
2492
|
// ─── Text overflow (browser-only: needs scrollWidth/clientWidth) ──────────────
|
|
2223
2493
|
const TEXT_OVERFLOW_SKIP_TAGS = new Set(['pre', 'code', 'textarea', 'svg', 'canvas', 'select', 'option', 'marquee']);
|
|
2224
2494
|
|
|
2495
|
+
function metricLengthPx(value, fontSizePx = 16) {
|
|
2496
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value;
|
|
2497
|
+
if (typeof value !== 'string') return null;
|
|
2498
|
+
return resolveLengthPx(value, fontSizePx);
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
function firstMetricLengthPx(fontSizePx, ...values) {
|
|
2502
|
+
for (const value of values) {
|
|
2503
|
+
const parsed = metricLengthPx(value, fontSizePx);
|
|
2504
|
+
if (parsed !== null) return parsed;
|
|
2505
|
+
}
|
|
2506
|
+
return null;
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
function expandBoxShorthand(parts) {
|
|
2510
|
+
if (parts.length === 1) return [parts[0], parts[0], parts[0], parts[0]];
|
|
2511
|
+
if (parts.length === 2) return [parts[0], parts[1], parts[0], parts[1]];
|
|
2512
|
+
if (parts.length === 3) return [parts[0], parts[1], parts[2], parts[1]];
|
|
2513
|
+
return [parts[0], parts[1], parts[2], parts[3]];
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
function clippedByInset(clipPath) {
|
|
2517
|
+
const match = String(clipPath || '').trim().toLowerCase().match(/^inset\s*\(([^)]*)\)$/);
|
|
2518
|
+
if (!match) return false;
|
|
2519
|
+
const beforeRound = match[1].split(/\s+round\s+/)[0].trim();
|
|
2520
|
+
if (!beforeRound) return false;
|
|
2521
|
+
const values = expandBoxShorthand(beforeRound.split(/\s+/).slice(0, 4));
|
|
2522
|
+
const percents = values.map(value => String(value).trim().match(/^(-?\d+(?:\.\d+)?)%$/));
|
|
2523
|
+
if (percents.some(match => !match)) return false;
|
|
2524
|
+
const [top, right, bottom, left] = percents.map(match => parseFloat(match[1]));
|
|
2525
|
+
return top + bottom >= 100 || left + right >= 100;
|
|
2526
|
+
}
|
|
2527
|
+
|
|
2528
|
+
function clippedByRect(clip) {
|
|
2529
|
+
const match = String(clip || '').trim().toLowerCase().match(/^rect\s*\(([^)]*)\)$/);
|
|
2530
|
+
if (!match) return false;
|
|
2531
|
+
const values = match[1].split(/[,\s]+/).map(value => value.trim()).filter(Boolean);
|
|
2532
|
+
if (values.length !== 4) return false;
|
|
2533
|
+
const [top, right, bottom, left] = values.map(value => metricLengthPx(value, 16));
|
|
2534
|
+
if ([top, right, bottom, left].some(value => value === null)) return false;
|
|
2535
|
+
return bottom <= top || right <= left;
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
function isScreenReaderOnlyTextStyle(style, metrics = {}) {
|
|
2539
|
+
if (!style) return false;
|
|
2540
|
+
const overflowValues = [style.overflow, style.overflowX, style.overflowY]
|
|
2541
|
+
.map(value => String(value || '').toLowerCase());
|
|
2542
|
+
const clipsOverflow = overflowValues.some(value => value === 'hidden' || value === 'clip');
|
|
2543
|
+
|
|
2544
|
+
const fontSize = metricLengthPx(style.fontSize, 16) || 16;
|
|
2545
|
+
const width = firstMetricLengthPx(fontSize, metrics.width, metrics.clientWidth, style.width, style.inlineSize);
|
|
2546
|
+
const height = firstMetricLengthPx(fontSize, metrics.height, metrics.clientHeight, style.height, style.blockSize);
|
|
2547
|
+
const isTiny = width !== null && height !== null && width <= 2 && height <= 2;
|
|
2548
|
+
const isAbsolutelyHidden = String(style.position || '').toLowerCase() === 'absolute' && isTiny && clipsOverflow;
|
|
2549
|
+
|
|
2550
|
+
const clipPath = String(style.clipPath || style.webkitClipPath || '').trim();
|
|
2551
|
+
const clip = String(style.clip || '').trim();
|
|
2552
|
+
return isAbsolutelyHidden || clippedByInset(clipPath) || clippedByRect(clip);
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2555
|
+
function isRenderedForBrowserRule(el) {
|
|
2556
|
+
for (let cur = el; cur && cur.nodeType === 1; cur = cur.parentElement) {
|
|
2557
|
+
if (cur.getAttribute?.('aria-hidden') === 'true') return false;
|
|
2558
|
+
const style = getComputedStyle(cur);
|
|
2559
|
+
const visibility = String(style.visibility || '').toLowerCase();
|
|
2560
|
+
if (style.display === 'none' || visibility === 'hidden' || visibility === 'collapse') return false;
|
|
2561
|
+
if ((parseFloat(style.opacity) || 0) <= 0.01) return false;
|
|
2562
|
+
if (String(style.contentVisibility || '').toLowerCase() === 'hidden') return false;
|
|
2563
|
+
}
|
|
2564
|
+
return true;
|
|
2565
|
+
}
|
|
2566
|
+
|
|
2225
2567
|
function checkElementTextOverflowDOM(el) {
|
|
2226
2568
|
const tag = el.tagName.toLowerCase();
|
|
2227
2569
|
if (TEXT_OVERFLOW_SKIP_TAGS.has(tag)) return [];
|
|
2570
|
+
if (!isRenderedForBrowserRule(el)) return [];
|
|
2228
2571
|
// Only the element that actually owns overflowing text — not its ancestors,
|
|
2229
2572
|
// which inherit a wider scrollWidth from the spilling descendant.
|
|
2230
2573
|
const hasDirectText = [...el.childNodes].some(n => n.nodeType === 3 && n.textContent.trim().length > 0);
|
|
2231
2574
|
if (!hasDirectText) return [];
|
|
2232
2575
|
const style = getComputedStyle(el);
|
|
2576
|
+
const rect = el.getBoundingClientRect ? el.getBoundingClientRect() : null;
|
|
2577
|
+
if (isScreenReaderOnlyTextStyle(style, {
|
|
2578
|
+
width: rect?.width,
|
|
2579
|
+
height: rect?.height,
|
|
2580
|
+
clientWidth: el.clientWidth,
|
|
2581
|
+
clientHeight: el.clientHeight,
|
|
2582
|
+
})) return [];
|
|
2233
2583
|
const isScrollRegion = (s) => /(auto|scroll)/.test(s.overflowX || '') || /(auto|scroll)/.test(s.overflow || '');
|
|
2234
2584
|
if (isScrollRegion(style)) return [];
|
|
2235
2585
|
// A scrollable ancestor means this overflow is intentional and scrollable.
|
|
@@ -2312,5 +2662,6 @@ export {
|
|
|
2312
2662
|
checkClippedOverflow,
|
|
2313
2663
|
checkElementClippedOverflow,
|
|
2314
2664
|
checkElementClippedOverflowDOM,
|
|
2665
|
+
isScreenReaderOnlyTextStyle,
|
|
2315
2666
|
checkElementTextOverflowDOM,
|
|
2316
2667
|
};
|