Skip to content

Using color js for logic#44

Merged
chipcullen merged 5 commits into
mainfrom
using-color-js-for-logic
Apr 6, 2026
Merged

Using color js for logic#44
chipcullen merged 5 commits into
mainfrom
using-color-js-for-logic

Conversation

@chipcullen

@chipcullen chipcullen commented Apr 6, 2026

Copy link
Copy Markdown
Owner

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/utils/translatedColor.ts
Comment thread src/components/Swatch.tsx Outdated
Comment thread src/utils/isValidColor.ts
Comment thread src/utils/translatedColor.ts
@chipcullen chipcullen merged commit 19dbc0b into main Apr 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants