Using color js for logic#44
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR migrates ColoRosetta’s color parsing/conversion from custom utility functions to colorjs.io, simplifying conversion logic while expanding supported color formats (notably OKLCH and display-p3) and updating gamut checking and UI text accordingly.
Changes:
- Added colorjs.io dependency and replaced most custom conversion code with library-based conversions.
- Added support for oklch() and color(display-p3 …) across type detection, validation, translation, and UI inputs.
- Replaced legacy LCH gamut logic with a generalized sRGB gamut check helper and updated warnings/copy.
Reviewed changes
Copilot reviewed 34 out of 35 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Adds lock entry for colorjs.io. |
| package.json | Adds colorjs.io dependency. |
| src/utils/w3conversions.ts | Removes legacy matrix/color conversion implementation. |
| src/utils/toRgb.ts | Removes legacy RGB conversion helpers. |
| src/utils/toRgb.test.ts | Removes tests for deleted toRgb helpers. |
| src/utils/toRgba.ts | Removes legacy RGBA conversion helpers. |
| src/utils/toRgba.test.ts | Removes tests for deleted toRgba helpers. |
| src/utils/toHex.ts | Removes legacy hex conversion helpers. |
| src/utils/toHex8.ts | Removes legacy hex8 conversion helpers. |
| src/utils/toHex8.test.ts | Removes tests for deleted toHex8 helpers. |
| src/utils/toHsl.ts | Removes legacy HSL conversion helpers. |
| src/utils/toHsl.test.ts | Removes tests for deleted toHsl helpers. |
| src/utils/toHsla.ts | Removes legacy HSLA conversion helpers. |
| src/utils/toHsla.test.ts | Removes tests for deleted toHsla helpers. |
| src/utils/toLch.ts | Removes legacy LCH conversion helpers. |
| src/utils/toLch.test.ts | Removes tests for deleted toLch helpers. |
| src/utils/formatColor.ts | Removes legacy formatting utilities previously used by conversions. |
| src/utils/formatColor.test.ts | Removes tests for deleted formatting utilities. |
| src/utils/colorStringToArray.ts | Removes legacy color-string parsing helper. |
| src/utils/colorStringToArray.test.ts | Removes tests for deleted parsing helper. |
| src/utils/isLchOutOfRgbGamut.ts | Removes old LCH→sRGB gamut check implementation. |
| src/utils/isLchOutOfRgbGamut.test.ts | Removes tests for deleted gamut helper. |
| src/utils/isOutOfSrgbGamut.ts | Adds new generic sRGB gamut check using colorjs.io. |
| src/utils/isOutOfSrgbGamut.test.ts | Adds tests for the new sRGB gamut helper. |
| src/utils/colorTypes.ts | Adds new enum members for oklch and p3. |
| src/utils/typeOfColor.ts | Detects oklch() and color(display-p3 …) inputs. |
| src/utils/isValidColor.ts | Switches parsing/validation for functional syntaxes to colorjs.io; adds OKLCH/P3 validation. |
| src/utils/isValidColor.test.ts | Updates tests to match new validation approach and expectations. |
| src/utils/translatedColor.ts | Rewrites translation logic to use colorjs.io, adds OKLCH/P3 outputs, and handles alpha flattening via overlay. |
| src/components/Input.tsx | Uses the new sRGB gamut helper; updates warning text and applies gamut checks to OKLCH too. |
| src/components/Swatch.tsx | Updates LCH fallback rendering to use colorjs.io for an sRGB approximation. |
| src/components/Footer.tsx | Updates attribution to reference color.js as the conversion engine. |
| src/App.tsx | Adds new input fields for P3 and OKLCH and adjusts layout ordering. |
| src/App.test.tsx | Removes the skipped app-level test file. |
| src/App.css | Renames layout section class and applies formatting/selector tweaks to match updated layout. |
💡 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 PR makes a major shift in the color conversion logic. Rather than using my cobbled together conversion functions, we're now using color.js: https://colorjs.io/
This PR removes the functions that have been superseded by the library, and updated the footer accordingly.