Add CSS Color 4/5 color functions (oklch/oklab/lab/lch, color-mix)#222
Open
jhaygood86 wants to merge 1 commit into
Open
Add CSS Color 4/5 color functions (oklch/oklab/lab/lch, color-mix)#222jhaygood86 wants to merge 1 commit into
jhaygood86 wants to merge 1 commit into
Conversation
Add object-model parsing and sRGB resolution for the CSS Color 4/5 color functions oklch(), oklab(), lab(), lch(), and color-mix(), plus the lenient CSS Color 4 space-separated and slash-alpha forms of rgb()/rgba()/hsl()/hsla()/hwb(). - FunctionNames: add Lab, Oklab, Lch, Oklch, ColorMix. - ColorSpaceMath (new): sRGB <-> lab/oklab/lch/oklch/xyz/display-p3/hsl/hwb conversion math plus premultiplied and polar-hue interpolation. Portable Cbrt/Clamp01 helpers so it compiles on net48/netstandard2.0. - Color: FromLab/FromOklab/FromLch/FromOklch factories and a Mix(color-mix) factory. - ColorFunctionExtensions (new): token-stream -> Color resolver (ToResolvedColor / ParseColorFunction), including the percentage-before-color color-mix operand form. - ColorInterpolationMethodGrammar (new): shared in <color-space> <hue>? prelude grammar. - Converters: lenient Any-based Lab/Oklab/Lch/Oklch/ColorMix and space/slash rgb/hsl/hwb converters, appended after the existing strict comma-form converters in ColorConverter so legacy serialization is unchanged. - Tests: ModernColorTests covering parse + resolved sRGB values. Spec: https://www.w3.org/TR/css-color-4/ and css-color-5 (color-mix).
jhaygood86
marked this pull request as ready for review
July 24, 2026 20:09
jhaygood86
marked this pull request as draft
July 24, 2026 20:34
jhaygood86
marked this pull request as ready for review
July 24, 2026 20:37
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
Adds CSS Color 4/5 color functions, resolved to sRGB (CSS Color 4, CSS Color 5):
oklch(),oklab(),lab(),lch()— modern perceptual color spaces.color-mix(in <space>, …)— including the percentage-before-color operand form.rgb()/rgba()/hsl()/hsla()/hwb()— space-separated and slash-alpha (rgb(r g b / a)). This also fixes a latent stack-overflow wherehsl()/hwb()used as solid colors recursed forever.Design
oklch(0.63 0.26 29)round-trips), mirroring ExCSS's existingAspectRatioValueConverteraccept-and-preserve precedent. The strict comma-form converters stay first so legacy serialization (hsla(50deg, …)) is unchanged; lenientAny-based converters are appended.ColorFunctionExtensions.ToResolvedColorover the token stream, backed by a newColorSpaceMath(sRGB↔lab/oklab/lch/oklch/xyz, premultiplied-alpha + polar-hue interpolation).ColorgainsFromLab/FromOklab/FromLch/FromOklchand a color-mixMixoverload.Portability
Builds clean across all 8 target frameworks.
Math.Clamp/Math.Cbrt(absent on net48/netstandard2.0) are replaced with portable helpers; no C# 10+ syntax (LangVersion 9).Tests
ModernColorTests— 43 parse + resolve cases (oklch/oklab/lab/lch, color-mix in a space, space-separated & slash-alpha rgb/hsl/hwb, and the hsl()/hwb()-as-solid-color regression). Full suite green (1559 passing, no regressions).Ported from PeachPDF, which vendors ExCSS.