Add oklch color format support for animations#3637
Conversation
Greptile SummaryThis PR adds However, there is one critical gap that needs to be addressed before merging:
Additional concerns:
Confidence Score: 2/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Input color string] --> B{Is it a complex value?}
B -- No --> C{getColorType}
B -- Yes --> D[analyseComplexValue\nuses complexRegex]
D --> E{complexRegex matches oklch?}
E -- No - BUG --> F["oklch numbers extracted\nas individual number tokens\n❌ Wrong animation output"]
E -- Yes - after fix --> G[color.parse called\nconverts oklch → RGBA\n✅]
C --> H{type === hex / rgba / hsla / oklch}
H -- oklch --> I[oklch.parse\nlightness, chroma, hue, alpha]
I --> J[oklchToRgba\nOKLCH → OKLAB → LMS → sRGB]
J --> K[RGBA object]
H -- hex/rgba/hsla --> L[Existing parsers]
L --> K
K --> M[mixLinearColor blends\nred, green, blue, alpha]
M --> N[rgba.transform\noutput: rgba string ✅]
|
| test("mixColor oklch to hex", () => { | ||
| const mix = mixColor("oklch(0.65 0.18 260)", "#ffffff") | ||
| expect(mix(0.5)).toMatch(/^rgba\(/) | ||
| }) | ||
|
|
||
| test("mixColor hex to oklch", () => { | ||
| const mix = mixColor("#ffffff", "oklch(0.65 0.18 260)") | ||
| expect(mix(0.5)).toMatch(/^rgba\(/) | ||
| }) | ||
|
|
||
| test("mixColor oklch with alpha", () => { | ||
| const mix = mixColor("oklch(0.65 0.18 260 / 0.5)", "#ffffff") | ||
| expect(mix(0)).toMatch(/^rgba\(/) | ||
| expect(mix(0)).toContain("0.5)") | ||
| }) |
There was a problem hiding this comment.
Tests verify format only, not correctness of color math
All three new oklch tests only assert that the output starts with rgba(, which would pass even if the conversion matrix had a typo. Consider adding at least one test that checks a known, expected output value to guard against regression in the math. For example, oklch(1 0 0) (lightness = 1, chroma = 0, any hue) should equal pure white rgba(255, 255, 255, 1), and oklch(0 0 0) should equal pure black rgba(0, 0, 0, 1):
test("mixColor oklch achromatic white", () => {
// Pure white in OKLCH: L=1, C=0 → rgb(255,255,255)
expect(mixColor("oklch(1 0 0)", "#ffffff")(0)).toBe("rgba(255, 255, 255, 1)")
})d54b331 to
e33ea64
Compare
When animating color properties with modern CSS color formats like oklch() that the JS animation path can't parse, force WAAPI which handles native browser color interpolation. Falls back to JS animation if WAAPI throws. Fixes #3058 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
e33ea64 to
5500225
Compare
Summary
oklch()colors were not recognized as animatable, causing animations betweenoklchand other formats (hex, rgb, hsl) to snap instantly with a console warning:'oklch(...)' is not an animatable color#hex,rgb(a), andhsl(a)formats.oklch()strings failed thesingleColorRegextest, soasRGBA()returnedfalseandmixColor()fell back tomixImmediateoklch(), added an oklch parser and oklch-to-RGBA conversion (OKLCH → OKLAB → LMS → linear sRGB → sRGB), and wired it into the color mixing pipelineFixes #3058
Test plan
mixColorwith oklch colors (oklch-to-hex, hex-to-oklch, oklch with alpha)yarn buildpasses (all 8 packages)yarn testpasses (769 tests across all packages)🤖 Generated with Claude Code