Performance and bundling
Import what you use. A named function from colore-js/fn fits an isolated conversion or edit. A Color object is useful when several operations work on the same input.
Choose an import
import { lighten } from 'colore-js/fn';
console.log(lighten('#2563eb', 8)); // '#306ff8'
Named imports let your bundler drop unused exports. One function still includes the parser it needs for named colors, supported CSS functions and tagged objects.
What an import costs
These are approximate gzip sizes for the local Colore v2 build, measured with Rollup 4.59, Terser 5.31 and gzip level 9. Measure your own production bundle to see what the rest of your app shares.
Parse once for several changes
import { colore } from 'colore-js';
const input = colore('#7c3aed');
console.log(input.lighten(8).saturate(6).css()); // 'color(display-p3 0.49629 0.27042 0.97260)'
The chain keeps the working color in memory until you call css(). Passing a CSS string from one standalone transform to the next formats and parses an intermediate value. For a palette you use on every render, compute it when its input changes.
Run the benchmarks
With the repo dependencies installed, build the package at the repo root and run its quick benchmark.
yarn build
yarn bench:quick
The runner measures parse-plus-hex, parse-plus-RGB and WCAG contrast on 256 opaque sRGB hex inputs or pairs. Each reported operation is a full pass over its dataset. For an app decision, also measure the color formats and operations your users run.
Related
- Entry points and exports for the names available from each import
- Immutability and chaining
- Benchmark source