tailwind-a11y 0.13.1 → 0.13.5
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.
|
@@ -131,6 +131,24 @@ export function suggestContrastFix(textClass, bgClass, required, palette = defau
|
|
|
131
131
|
}
|
|
132
132
|
return null;
|
|
133
133
|
}
|
|
134
|
+
// resolveColorValue() bails out on any bg-side opacity modifier before ever
|
|
135
|
+
// checking whether the underlying color is real (background-side opacity
|
|
136
|
+
// compositing is out of scope -- see CLAUDE.md -- since it depends on
|
|
137
|
+
// knowing what's rendered behind an already-semi-transparent background).
|
|
138
|
+
// Caught in independent adversarial testing: this made checkContrastValueSkips
|
|
139
|
+
// report `bg-gray-800/50 is not a recognized color`, even though gray-800
|
|
140
|
+
// is a perfectly recognized default-palette color -- a developer reading
|
|
141
|
+
// that message would reasonably (and pointlessly) try adding a theme entry
|
|
142
|
+
// for it. Distinguishes the two cases by re-resolving the color with the
|
|
143
|
+
// opacity suffix stripped off: if that succeeds, the real reason is the
|
|
144
|
+
// out-of-scope opacity, not an unrecognized color.
|
|
145
|
+
function bgSkipReason(bgColorClass, palette) {
|
|
146
|
+
const { base, alpha } = splitOpacityModifier(bgColorClass);
|
|
147
|
+
if (alpha < 1 && resolveColorValue(base, palette) !== null) {
|
|
148
|
+
return `${bgColorClass} is a recognized color, but background-side opacity isn't resolved (compositing it correctly requires knowing what's rendered behind it) — skipped`;
|
|
149
|
+
}
|
|
150
|
+
return `${bgColorClass} is not a recognized color (custom theme color or unsupported arbitrary value) — skipped`;
|
|
151
|
+
}
|
|
134
152
|
// A candidate that extractChecks *did* find a background for, but whose
|
|
135
153
|
// text or bg utility didn't resolve to a known value (custom theme color,
|
|
136
154
|
// non-hex arbitrary value, background-side opacity shorthand) — surfaced
|
|
@@ -150,11 +168,7 @@ export function checkContrastValueSkips(checks, palette = defaultPalette) {
|
|
|
150
168
|
const bgHex = resolveColorValue(check.bgColorClass, palette);
|
|
151
169
|
const bgRgb = bgHex ? hexToRgb(bgHex) : null;
|
|
152
170
|
if (!bgRgb) {
|
|
153
|
-
skips.push({
|
|
154
|
-
file: check.file,
|
|
155
|
-
line: check.line,
|
|
156
|
-
reason: `${check.bgColorClass} is not a recognized color (custom theme color or unsupported arbitrary value) — skipped`,
|
|
157
|
-
});
|
|
171
|
+
skips.push({ file: check.file, line: check.line, reason: bgSkipReason(check.bgColorClass, palette) });
|
|
158
172
|
continue;
|
|
159
173
|
}
|
|
160
174
|
const { alpha } = splitOpacityModifier(check.textColorClass);
|
|
@@ -11,9 +11,15 @@ const REMOVAL_BASE = "outline-none";
|
|
|
11
11
|
// resets every element to `border: 0 solid`, so border-width stays 0
|
|
12
12
|
// regardless of style and no border is ever drawn, same failure mode as
|
|
13
13
|
// border-0.
|
|
14
|
+
// inset-shadow-none/inset-ring-0 (Tailwind v4's inset-* box-shadow family,
|
|
15
|
+
// missed by the original one-time audit -- these utilities didn't exist,
|
|
16
|
+
// or weren't considered, at the time) are the exact same failure mode as
|
|
17
|
+
// shadow-none/ring-0: verified against a real build that inset-shadow-none
|
|
18
|
+
// computes to a fully transparent shadow and inset-ring-0 computes to a
|
|
19
|
+
// 0px-wide inset ring, both real but invisible.
|
|
14
20
|
const DEGENERATE_BASES = new Set([
|
|
15
21
|
"outline-none", "ring-0", "border-0", "shadow-none", "bg-transparent",
|
|
16
|
-
"border-none", "border-hidden",
|
|
22
|
+
"border-none", "border-hidden", "inset-shadow-none", "inset-ring-0",
|
|
17
23
|
]);
|
|
18
24
|
// Modifier-only utilities (opacity/offset/inset) don't set a concrete value
|
|
19
25
|
// on their own — e.g. bg-opacity-50 with no bg-* color, or ring-offset-4
|
|
@@ -58,16 +64,35 @@ const NON_VISUAL_PATTERN = /^bg-blend-|^border-spacing(-[xy])?-/;
|
|
|
58
64
|
// offset cases above, but shaped like a color token rather than a fixed
|
|
59
65
|
// suffix, so it reuses COLOR_TOKEN (the exact same "is this a color value"
|
|
60
66
|
// test extractClasses.ts uses) instead of a third, drifting definition of
|
|
61
|
-
// what a color looks like.
|
|
67
|
+
// what a color looks like. inset-shadow-{color}/inset-ring-{color} are the
|
|
68
|
+
// same mechanism one prefix-family over (verified against a real build:
|
|
69
|
+
// inset-shadow-blue-500 alone only sets --tw-inset-shadow-color,
|
|
70
|
+
// inset-ring-blue-500 alone only sets --tw-inset-ring-color -- neither
|
|
71
|
+
// produces a box-shadow without a companion size utility).
|
|
62
72
|
function isColorOnlyShadowOrRing(base) {
|
|
63
|
-
const shadowMatch = /^shadow-(.+)$/.exec(base);
|
|
73
|
+
const shadowMatch = /^(?:inset-)?shadow-(.+)$/.exec(base);
|
|
64
74
|
if (shadowMatch && COLOR_TOKEN.test(shadowMatch[1]))
|
|
65
75
|
return true;
|
|
66
|
-
const ringMatch = /^ring-(.+)$/.exec(base);
|
|
76
|
+
const ringMatch = /^(?:inset-)?ring-(.+)$/.exec(base);
|
|
67
77
|
if (ringMatch && COLOR_TOKEN.test(ringMatch[1]))
|
|
68
78
|
return true;
|
|
69
79
|
return false;
|
|
70
80
|
}
|
|
81
|
+
// ring-offset-{color} (e.g. ring-offset-blue-500) sets only the
|
|
82
|
+
// --tw-ring-offset-color CSS variable -- the offset ring itself is only
|
|
83
|
+
// ever drawn when a real ring width is *also* present (ring-2, etc.),
|
|
84
|
+
// verified against a real Tailwind v4 build. MODIFIER_ONLY above already
|
|
85
|
+
// excludes the numeric width form (ring-offset-4), but its regex requires
|
|
86
|
+
// digits after "offset-", so it never matched this color-shaped form --
|
|
87
|
+
// caught in independent adversarial testing (a real false negative: this
|
|
88
|
+
// fell through to the generic ring-* prefix match at the bottom of
|
|
89
|
+
// isReplacement and was silently accepted as a real replacement). One
|
|
90
|
+
// level deeper than isColorOnlyShadowOrRing above, so a separate check
|
|
91
|
+
// rather than folding into it.
|
|
92
|
+
function isColorOnlyRingOffset(base) {
|
|
93
|
+
const match = /^ring-offset-(.+)$/.exec(base);
|
|
94
|
+
return !!match && COLOR_TOKEN.test(match[1]);
|
|
95
|
+
}
|
|
71
96
|
function baseUtility(raw) {
|
|
72
97
|
return raw.slice(raw.lastIndexOf(":") + 1);
|
|
73
98
|
}
|
|
@@ -79,7 +104,16 @@ function isReplacement(raw) {
|
|
|
79
104
|
return false;
|
|
80
105
|
if (isColorOnlyShadowOrRing(base))
|
|
81
106
|
return false;
|
|
82
|
-
|
|
107
|
+
if (isColorOnlyRingOffset(base))
|
|
108
|
+
return false;
|
|
109
|
+
// inset-shadow-*/inset-ring-* (Tailwind v4) are their own prefix
|
|
110
|
+
// families, not `ring`/`shadow` with a suffix -- a string starting with
|
|
111
|
+
// "inset-" doesn't match the "shadow"/"ring" alternatives below at all,
|
|
112
|
+
// so a real inset-shadow-sm/inset-ring-2 replacement was previously
|
|
113
|
+
// rejected outright (a false positive on the overall check: it reported
|
|
114
|
+
// the outline as removed with nothing put back, when something real
|
|
115
|
+
// was). Caught in independent adversarial testing.
|
|
116
|
+
return /^(ring|border|shadow|bg|outline|inset-shadow|inset-ring)(-|$)/.test(base);
|
|
83
117
|
}
|
|
84
118
|
export function checkFocusIndicators(checks) {
|
|
85
119
|
const violations = [];
|
|
@@ -60,22 +60,60 @@ export function checkReducedMotion(checks, strict = false) {
|
|
|
60
60
|
return [];
|
|
61
61
|
const violations = [];
|
|
62
62
|
for (const check of checks) {
|
|
63
|
-
let
|
|
63
|
+
let realTransition = null;
|
|
64
64
|
let hasMotionReduceGuard = false;
|
|
65
65
|
for (const raw of check.classes) {
|
|
66
66
|
const base = baseUtility(raw);
|
|
67
67
|
const segments = variantSegments(raw);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
// A transition counts as "real" (needs checking) unless its variant
|
|
69
|
+
// stack makes it not actually apply at the moment the interaction
|
|
70
|
+
// begins:
|
|
71
|
+
// - an interaction pseudo-class (hover:/focus:/focus-within:/
|
|
72
|
+
// active:) anywhere in the stack means the transition-property
|
|
73
|
+
// only exists *during* that momentary state, not before it -- CSS
|
|
74
|
+
// has nothing to transition *from* right as the interaction
|
|
75
|
+
// starts, so `hover:transition-transform hover:scale-110` still
|
|
76
|
+
// snaps instantly, same as before this fix (this is the one case
|
|
77
|
+
// the original `segments.length === 0` check happened to get
|
|
78
|
+
// right, so it's preserved here under its real reason instead).
|
|
79
|
+
// - motion-safe: anywhere in the stack means the transition simply
|
|
80
|
+
// doesn't exist unless motion is already safe -- a complete,
|
|
81
|
+
// persistent exemption, unrelated to interaction timing.
|
|
82
|
+
// Any *other* scoping (dark:, sm:, lg:, ...) is a persistent
|
|
83
|
+
// precondition, not a momentary one -- the transition genuinely is
|
|
84
|
+
// present in the resting state whenever that condition holds, with
|
|
85
|
+
// zero relationship to prefers-reduced-motion. Caught in independent
|
|
86
|
+
// adversarial testing: the previous version required
|
|
87
|
+
// `segments.length === 0` (no variant at all), so
|
|
88
|
+
// `dark:transition hover:scale-110` was silently treated as
|
|
89
|
+
// compliant even though it animates on hover in dark mode
|
|
90
|
+
// regardless of the user's motion preference.
|
|
91
|
+
const isInteractionGated = segments.some((v) => INTERACTION_VARIANTS.has(v));
|
|
92
|
+
const isMotionSafeGated = segments.includes("motion-safe");
|
|
93
|
+
if (TRANSITION_BASES.has(base) && !isInteractionGated && !isMotionSafeGated)
|
|
94
|
+
realTransition = raw;
|
|
95
|
+
// Only a *bare* motion-reduce:transition-none/transform-none (no
|
|
96
|
+
// other variant stacked with it) is trusted as a full guard --
|
|
97
|
+
// caught in independent adversarial testing: `sm:motion-reduce:
|
|
98
|
+
// transition-none` was being accepted as fully protective even
|
|
99
|
+
// though it only suppresses the transition at/above the `sm`
|
|
100
|
+
// breakpoint, leaving it completely unguarded below that width.
|
|
101
|
+
// Correctly modeling arbitrary variant-subset relationships (does
|
|
102
|
+
// this guard's other conditions always hold whenever the real
|
|
103
|
+
// trigger's conditions hold?) is out of scope -- requiring the
|
|
104
|
+
// guard to be unconditional is the same "skip/flag rather than
|
|
105
|
+
// guess" posture used everywhere else in this project, erring
|
|
106
|
+
// toward a false positive over the worse failure mode, a false
|
|
107
|
+
// negative.
|
|
108
|
+
if (segments.length === 1 && segments[0] === "motion-reduce" && (base === "transition-none" || base === "transform-none")) {
|
|
71
109
|
hasMotionReduceGuard = true;
|
|
72
110
|
}
|
|
73
111
|
}
|
|
74
|
-
//
|
|
75
|
-
//
|
|
112
|
+
// No real (non-motion-safe-guarded) transition at all means it simply
|
|
113
|
+
// doesn't exist unless motion is already safe -- a complete
|
|
76
114
|
// alternative way of satisfying 2.3.3, not a partial one -- so this
|
|
77
115
|
// correctly falls through as a pass, not a skip-because-unresolvable.
|
|
78
|
-
if (!
|
|
116
|
+
if (!realTransition)
|
|
79
117
|
continue;
|
|
80
118
|
if (hasMotionReduceGuard)
|
|
81
119
|
continue;
|
|
@@ -100,7 +138,7 @@ export function checkReducedMotion(checks, strict = false) {
|
|
|
100
138
|
file: check.file,
|
|
101
139
|
line: check.line,
|
|
102
140
|
tagName: check.tagName,
|
|
103
|
-
transitionClass:
|
|
141
|
+
transitionClass: realTransition,
|
|
104
142
|
motionClass,
|
|
105
143
|
level: "AAA",
|
|
106
144
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwind-a11y",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.5",
|
|
4
4
|
"description": "Static analysis CLI that catches WCAG accessibility violations — color contrast, touch target size, and focus indicator removal/contrast — in Tailwind CSS class combinations before they ship.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|