Repository navigation
SVG: read oklch() and oklab() colors - #2199
Merged
Merged
Conversation
They failed with ValueError: unsupported color specification, as in the social preview images of react-window and the favicon of styled-components. They are converted to sRGB and clipped to it.
andersonhc
requested changes
Nov 13, 2026
andersonhc
left a comment
Collaborator
There was a problem hiding this comment.
I noticed a few CSS Color 4 edge cases worth addressing before merging:
- oklch(50% 0.1 30 / none) raises ValueError. Missing alpha should render as zero.
- Negative chroma should clamp to zero before conversion. Currently, oklch(50% -0.2 30) produces cyan rather than gray.
- Lightness needs clamping and black/white endpoint handling. For example, oklab(100% 0.2 0.1) currently renders pink instead of white.
andersonhc
approved these changes
Nov 14, 2026
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.
oklch()colors fail withValueError: unsupported color specification, for example in the social preview images of react-window, react-virtualized and react-resizable-panels, and in the favicon of styled-components (oklch(0.6979 0.2752 25.7477 / 0.6))._oklab_color()readsoklab(L a b)andoklch(L C H)of CSS Color 4 (https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch), with percentages, hue units,noneand an optional/ A. It converts them to sRGB with Björn Ottosson's matrices and clips colors outside sRGB. The hue parsing ofhsl()moves to_hue_degrees()so both share it.lab()is still unsupported, so theunsupported-color.svgtest is unchanged.test_svgcolor_oklab_and_oklchchecks red, blue and lime, white and black with alpha,none, and a clipped color, and fails without the change.