fix(framework): parse space-separated hsl() color values - #307
Open
shuvamk wants to merge 1 commit into
Open
Conversation
CSS Color-4 space syntax (`hsl(0 0% 80%)`, `hsl(0 0% 80% / 50%)`) is what modern CSS and importers such as Tailwind emit, but HSLA_RE only accepted the legacy comma form with a number-only alpha. Space-syntax hsl() tokens fell through parseColor to the verbatim base fallback, so every derived transparent/shade/tint variant was silently dropped. Widen HSLA_RE to the same comma-or-space, number-or-percentage-alpha shape its sibling RGBA_RE already uses, and share the alpha coercion between both branches via parseAlpha. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
shuvamk
marked this pull request as ready for review
July 29, 2026 13:44
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.
Summary
Color tokens authored with CSS Color-4 space syntax —
hsl(0 0% 80%)andhsl(0 0% 80% / 50%)— silently lose every derived variant (transparent steps, shades, tints). Only the bare--<slug>base is emitted, verbatim.HSLA_REinsrc/core/framework/colors.tsonly matched the legacy comma form with a number-only alpha:Space-separated
hsl()therefore failedparseColor, fell through to the verbatim base fallback, and produced no channels to derive from. Its siblingRGBA_RE— one line below — already documents and supports "both comma and space syntax, alpha as number or percentage", so the two were asymmetric.This matters in practice: modern CSS and common import sources (Tailwind) emit space-separated
hsl(), andsrc/core/siteImport/colorTokens.tseven useshsl(0 0% 80%)as a canonical example of an imported palette entry that becomes a framework color token.Before → after
lightValuehsl(0 0% 80%)--cverbatim, no variants)hsla(0, 0%, 80%, 1)+ 10 transparent + 2 shades + 2 tintshsl(0 0% 80% / 50%)hsla(0, 0%, 80%, 0.5)+ variantshsl(0, 0%, 80%)(comma)Fix
HSLA_REto the same comma-or-space separator and number-or-percentage / slash-delimited alpha shapeRGBA_REalready uses.parseAlphaand share it between the hsl and rgb branches instead of duplicating the number/percentage coercion.No new behavior for values that already parsed; comma-syntax
hsl()/hsla()output is byte-identical.Verification
bun run buildbun test(6332 pass, 0 fail; the new test fails onmainand passes with the fix)bun run lintChecklist
hsl(0 0% 80%)+hsl(... / 50%)case alongside the existingrgb(5 5 5 / 78%)space-syntax test.