Repository navigation
Read the alpha of modern CSS color syntax in colorAlpha - #3
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
colorAlpha()only understoodrgb()/rgba()and treated every other color as fully opaque. Computed colors aren't alwaysrgb(): browsers keep the space a color was written or mixed in, sooklab(),oklch(),lab(),hsl()andcolor(srgb …)all occur. Tailwind v4 compilesbg-black/50tocolor-mix(in oklab, …), which Chrome reports asoklab(0 0 0 / 0.5).Effect: the backdrop finder in
detection/engine.tsskips 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, andnoneis read as 0.transparentand opaque colors behave as before.Tests: new
tests/unit/layout.test.tswith 13 cases. The 6 translucent modern forms (oklab,oklch,color(srgb),lab,hslwith a slash,hsla) fail onmain, where each reads as 1. Thergb/rgba/transparentand opaque modern cases pass on both. Typecheck, lint and Prettier are clean.npm test: 212 passed.Co-authored-by: Claude noreply@anthropic.com