perf: replace colorjs.io with @colordx/core - #154
Merged
Merged
Conversation
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.
Contributor
🎉 Package Size Decrease
|
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.
Summary
colorjs.iodependency for@colordx/core, a smaller, tree-shakeable color library.convert()on top ofcolordx()/.toHsl()instead oftryColor()+to(HSL).lab,lch,hwb,hsv,p3,rec2020,a98rgb,prophoto,names) to keep parsing support for the same color spaces the oldColorSpace.register(...)calls covered.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 ...)andcolor(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.OKLrab,Lab-D65, absoluteXYZ_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 thecolor()function fordisplay-p3,a98-rgb,prophoto-rgb,rec2020,xyz-d50, andxyz-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: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_modulesfootprint of the color dependency itself (npm'sunpackedSize, confirmed with a realnpm install):colorjs.io ships its full source, docs, and multiple build outputs in the published tarball even though only
colorjs.io/fnis imported here;@colordx/corepublishes just itsdist/output, so the install footprint drops from ~15 MB to well under 1 MB.Test plan
pnpm vitest run— 25/25 tests passpnpm run check(tsc --noEmit)pnpm run lint(oxlint + oxfmt)pnpm run build(tsdown + publint)