Updates - #6
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR tightens OKLCH handling by introducing a Display‑P3 chroma clamp and wiring it into key color-picker entry points and OKLCH interactions, backed by expanded tests. The goal is to prevent out-of-gamut OKLCH chroma values from entering or persisting in picker state and emitted values.
Changes:
- Added
clampOklchToP3utility (based ongetP3MaxChroma) and applied it when OKLCH values enter or are mutated in the hook. - Updated OKLCH slider logic to clamp relative chroma so lightness/hue changes can’t preserve an out-of-gamut chroma ratio.
- Expanded tests to validate clamping across initialization, controlled prop updates, input handling, and interactions; updated dependency versions.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/modules/colorSpace.ts |
Adds clampOklchToP3 to enforce P3-gamut chroma constraints. |
src/hooks/useColorPicker.ts |
Integrates clamping into OKLCH state initialization, prop updates, and OKLCH interactions. |
src/ChannelSliders/OKLCHSliders.tsx |
Clamps relative chroma on lightness/hue changes to prevent exceeding new gamut maxima. |
tests/modules/colorSpace.test.ts |
Adds unit tests for the new clamp utility. |
tests/hooks/useColorPicker.test.tsx |
Adds hook-level coverage ensuring clamping across multiple interaction paths. |
tests/ColorPicker.test.tsx |
Adds integration coverage ensuring emitted values remain within gamut when inputs would otherwise strand chroma. |
tests/ChannelSliders/OKLCHSliders.test.tsx |
Adds regression coverage ensuring slider interactions don’t emit invalid chroma. |
package.json |
Bumps runtime/dev dependencies (incl. colorizr, Storybook, Vite/Vitest, Playwright, pnpm). |
pnpm-lock.yaml |
Lockfile updates corresponding to dependency bumps. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
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.



This pull request introduces comprehensive improvements to OKLCH color handling, ensuring chroma values are always clamped to the Display-P3 gamut maximum across all entry points and interactions. This prevents out-of-gamut chroma from causing errors or inconsistencies, especially when colors are set via input, props, or user interaction. The changes include a new utility function, its integration throughout the codebase, and an expanded test suite to cover these scenarios.
OKLCH Chroma Clamping and Consistency
clampOklchToP3tocolorSpace.tsthat clamps the chroma (c) of an OKLCH color to the Display-P3 maximum for its lightness and hue, ensuring all colors remain within the supported gamut.clampOklchToP3throughout the color picker logic, including initialization, controlled prop updates, color input handling, and all OKLCH-related user interactions inuseColorPickerandOKLCHSliders. This guarantees that chroma never exceeds the P3 maximum, regardless of how a color enters the system. [1] [2] [3] [4] [5] [6] [7] [8] [9]Testing and Validation
ColorPicker.test.tsx,OKLCHSliders.test.tsx,useColorPicker.test.tsx, andcolorSpace.test.tsto validate that chroma is always clamped to the P3 maximum in all scenarios, including prop changes, input, panel, and slider interactions. These tests assert both the internal state and emitted values. [1] [2] [3] [4]Dependency Updates
package.jsonto their latest patch/minor versions for improved stability and compatibility, includingcolorizr, Storybook, Vite, Vitest, andpnpm. [1] [2]Internal Refactoring
colorSpace.tsfor clarity and to support the new chroma clamping logic. [1] [2]These changes collectively ensure that the color picker never emits or operates on out-of-gamut OKLCH colors, improving reliability and user experience.