Skip to content

Read the alpha of modern CSS color syntax in colorAlpha - #3

Merged
Dszae merged 1 commit into
mainfrom
fix/color-alpha-modern-color-syntax
Nov 23, 2026
Merged

Dszae merged 1 commit into
mainfrom
fix/color-alpha-modern-color-syntax

Conversation

@Dszae

@Dszae Dszae commented Nov 23, 2026

Copy link
Copy Markdown
Owner

colorAlpha() only understood rgb()/rgba() and treated every other color as fully opaque. Computed colors aren't always rgb(): browsers keep the space a color was written or mixed in, so oklab(), oklch(), lab(), hsl() and color(srgb …) all occur. Tailwind v4 compiles bg-black/50 to color-mix(in oklab, …), which Chrome reports as oklab(0 0 0 / 0.5).

Effect: the backdrop finder in detection/engine.ts skips a full-screen layer whose background alpha is >= 0.99. A half-transparent dimming backdrop written in any of those forms was read as solid, so it was never recognized as a backdrop.

Fix: colorAlpha() parses any color function. It reads the value after / in the modern syntax, or the fourth argument of the legacy comma syntax, as a number or percentage. The result is clamped to 0..1, and none is read as 0. transparent and opaque colors behave as before.

Tests: new tests/unit/layout.test.ts with 13 cases. The 6 translucent modern forms (oklab, oklch, color(srgb), lab, hsl with a slash, hsla) fail on main, where each reads as 1. The rgb/rgba/transparent and opaque modern cases pass on both. Typecheck, lint and Prettier are clean. npm test: 212 passed.

Co-authored-by: Claude noreply@anthropic.com

colorAlpha() only understood rgb()/rgba() and treated any other color as
fully opaque. Computed colors are not always rgb(): browsers keep the
space a color was written or mixed in, so oklab(), oklch(), lab(), hsl()
and color(srgb ...) all occur. Tailwind v4 compiles bg-black/50 to
color-mix(in oklab, ...), which Chrome reports as oklab(0 0 0 / 0.5).

The backdrop finder skips a full-screen layer whose background alpha is
>= 0.99, so a half-transparent dimming backdrop written in any of those
forms was read as solid and never recognized as a backdrop.

colorAlpha() now parses any color function: the value after "/" in the
modern syntax, or the fourth argument of the legacy comma syntax, as a
number or percentage, clamped to 0..1, with "none" read as 0.

Co-authored-by: Claude <noreply@anthropic.com>
@Dszae
Dszae merged commit 8d46938 into main Nov 23, 2026
2 checks passed
@Dszae
Dszae deleted the fix/color-alpha-modern-color-syntax branch November 23, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant