feat(core): support oklch() colors in the color parser - #3
Open
SiTaggart wants to merge 1 commit into
Open
Conversation
parseToRgba assumed browsers serialize computed colors as legacy "rgb(r, g, b)". CSS Color 4 colors keep their functional form, so oklch() strings were mangled into NaN and every blend, alpha, luminance and interpolation path silently failed. Parse oklch() literals directly (oklch -> oklab -> linear sRGB), route browser-resolved oklch through the same conversion, and warn on other unsupported modern forms instead of producing garbage. Co-Authored-By: Claude Fable 5.1 <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.
Summary
Theme colors,
themeOverrides, and cell colors can now be written asoklch()strings. Before, any oklch color that passed through a blend, alpha, luminance, or hover-interpolation path came out asrgba(NaN, …), which the canvas silently ignores — cells kept stale fills, selection tints and row stripes vanished, and text-contrast checks broke. Colors handed straight toctx.fillStylealready worked; only the parsed paths were broken.Root cause:
parseToRgbaasks the browser to compute the color, then comma-splits the result assuming legacyrgb(r, g, b)serialization. CSS Color 4 colors keep their functional form (oklch(0.7 0.15 150), space-separated), so the split produced[0.7, 1].What changed
parseToRgbais now a short pipeline: literaloklch()is parsed directly (oklch → oklab → linear sRGB, the Ottosson / CSS Color 4 matrices); anything else goes through the browser, dispatching on the computed serialization. Browser-resolved oklch (e.g. from a CSS variable) uses the same conversion. Other unsupported modern forms (lab(),color()) return the standard invalid-color black with a dev warning instead of garbage.parseLegacyRgb.blend,withAlpha,interpolateColors,getLuminance, theme merging, and the cells package all work with oklch inputs.Design notes
getComputedStyle, and it skips DOM work for the common case.vitest-canvas-mockreturns zeroed pixels, and premultiplied-alpha readback changes existing low-alpha blends such asborderColor.Verification
degforms, invalid input, a hex DOM-path regression, and each drawing helper with oklch inputs.Tests/TestCases → OklchColorsrenders two grids from the same data, one entirely oklch and one in the sRGB equivalents. Canvas byte-diff between them: max channel delta 1 (0.4% of bytes) with this change; 37% of bytes differing, deltas up to 241, with the old parser.main: the same 4 tests fail there (data-editor-inputadditive blending ×2,data-editorrow-marker drag,use-column-sizerlast row), and the Build workflow is already red onmainat thenpm run test -- --coveragestep. Nothing color-related.No
dist/in this PR; build onmainat release as usual.🤖 Generated with Claude Code