Skip to content

perf: replace colorjs.io with @colordx/core - #154

Merged
bartveneman merged 3 commits into
mainfrom
claude/colorjs-to-colordx-if6ooh
Aug 5, 2026
Merged

bartveneman merged 3 commits into
mainfrom
claude/colorjs-to-colordx-if6ooh

Conversation

@bartveneman

@bartveneman bartveneman commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Swap the colorjs.io dependency for @colordx/core, a smaller, tree-shakeable color library.
  • Re-implement convert() on top of colordx() / .toHsl() instead of tryColor() + to(HSL).
  • Register colordx's plugins (lab, lch, hwb, hsv, p3, rec2020, a98rgb, prophoto, names) to keep parsing support for the same color spaces the old ColorSpace.register(...) calls covered.
  • Add test coverage for the wide-gamut / CIE formats (lab(), lch(), hwb(), color(display-p3 ...), color(a98-rgb ...), color(prophoto-rgb ...), color(rec2020 ...)) to lock in parsing parity going forward.

Color space parity

Every color space the old setup registered is still parseable, except:

  • color(srgb ...) and color(srgb-linear ...) function syntax — not yet supported by @colordx/core (on their roadmap). These are rarely authored directly in the wild (rgb() / hex cover the same gamut), so the trade-off seemed worth it. rgb(), rgba(), and hex are of course unaffected.
  • A few colorjs.io-only, non-standard extensions that were registered but aren't real CSS syntax anyway (OKLrab, Lab-D65, absolute XYZ_ABS_D65) — these were never reachable through an actual CSS color string.

Everything else — hex, rgb(), hsl(), hwb(), hsv(), named colors, lab(), lch(), oklab(), oklch(), and the color() function for display-p3, a98-rgb, prophoto-rgb, rec2020, xyz-d50, and xyz-d65 — parses the same as before. All 24 existing tests pass unchanged, plus 1 new test covering the wide-gamut formats above.

Bundle size

Measured by bundling the full public API (convert, sort_fn, compare, color_group) together with its color dependency, minified and tree-shaken with esbuild — i.e. what a consuming app actually ships to the browser:

Before (colorjs.io) After (@colordx/core) Change
Minified 54.6 KB 40.7 KB -25.5%
Minified + gzip 22.8 KB 12.4 KB -45.7%
Minified + brotli 19.8 KB 10.6 KB -46.5%

The package's own dist/index.js (excluding the dependency, which is external in the published package) also shrinks slightly: 4.17 KB → 3.73 KB raw, 1.57 KB → 1.48 KB gzip.

Install size

node_modules footprint of the color dependency itself (npm's unpackedSize, confirmed with a real npm install):

Before (colorjs.io@0.7.1) After (@colordx/core@5.5.0) Change
Unpacked size 15.05 MB (15,781,049 B) 890 KB (911,447 B) -94.2%

colorjs.io ships its full source, docs, and multiple build outputs in the published tarball even though only colorjs.io/fn is imported here; @colordx/core publishes just its dist/ output, so the install footprint drops from ~15 MB to well under 1 MB.

Test plan

  • pnpm vitest run — 25/25 tests pass
  • pnpm run check (tsc --noEmit)
  • pnpm run lint (oxlint + oxfmt)
  • pnpm run build (tsdown + publint)

colordx's tree-shakeable plugin architecture (lab, lch, hwb, hsv, p3,
rec2020, a98rgb, prophoto, names) covers the same color spaces the
previous colorjs.io setup registered, minus `color(srgb ...)` /
`color(srgb-linear ...)` function-syntax parsing, which @colordx/core
doesn't support yet.

Cuts the real-world (bundled + minified + gzipped) footprint of this
package from ~23.4 KB to ~12.7 KB.
@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🎉 Package Size Decrease

📦 Package 📏 Base Size 📏 Source Size 📈 Size Change
color-sorter 4.1 kB 4 kB -82 B

@bartveneman bartveneman changed the title Replace colorjs.io with @colordx/core perf: replace colorjs.io with @colordx/core Aug 5, 2026
@bartveneman
bartveneman merged commit 69a8705 into main Aug 5, 2026
8 checks passed
@bartveneman
bartveneman deleted the claude/colorjs-to-colordx-if6ooh branch August 5, 2026 08:21
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