{"name":"@colordx/core","version":"7.0.0","keywords":["color","colour","oklch","oklab","display-p3","wide-gamut","hsl","rgb","hex","hsv","hwb","lab","lch","xyz","cmyk","color-space","color-manipulation","color-conversion","performance","tinycolor","tinycolor2"],"author":{"name":"Dmitrii Kriaklin"},"license":"MIT","_id":"@colordx/core@7.0.0","maintainers":[{"name":"dmkryak","email":"dmkryak@gmail.com"}],"homepage":"https://colordx.dev","bugs":{"url":"https://github.com/dkryaklin/colordx/issues"},"dist":{"shasum":"9e2fc87a30eeeda139dcbf5dcb5247a1f11bce9d","tarball":"http://registry-npm.ywwl.com/@colordx/core/download/@colordx/core-7.0.0.tgz","fileCount":133,"integrity":"sha512-Pzhfq1q7exN0kf7MJOO5KjcYJDMmj4uxxAmunw5tFF8rcVGq6vFvHZUu5A86k0PcCnaPlYxReOChfWriJnfHNQ==","signatures":[{"sig":"MEQCIEvlZFAIm673mdZDDoKuSeMkILAMhVoO6Y8VxFLWpkyvAiAipkOVr1idjIHP2a8scISTeqrUwWOR+CXKNDAHinubnA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEQCIFzcRjpIp6W4khCmUn1KjZ/DwIvggeqQNCGjAk14hYZAAiAB2GXHaPOKq/PkEHx4gItvjnoHV0jxsaDEZOMO8sSkug==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@colordx%2fcore@7.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":378001,"size":109588,"noattachment":false,"key":"/@colordx/core/-/@colordx/core-7.0.0.tgz"},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"./fn":{"import":{"types":"./dist/fn.d.ts","default":"./dist/fn.mjs"},"require":{"types":"./dist/fn.d.cts","default":"./dist/fn.cjs"}},"./plugins/*":{"import":{"types":"./dist/plugins/*.d.ts","default":"./dist/plugins/*.mjs"},"require":{"types":"./dist/plugins/*.d.cts","default":"./dist/plugins/*.cjs"}},"./tinycolor":{"import":{"types":"./dist/tinycolor.d.ts","default":"./dist/tinycolor.mjs"},"require":{"types":"./dist/tinycolor.d.cts","default":"./dist/tinycolor.cjs"}}},"gitHead":"282b4c2a9e857e588fb5654e2b603b0e2ee568a9","scripts":{"dev":"tsup --watch","knip":"knip","lint":"eslint src","size":"tsx scripts/size.ts","test":"vitest run","bench":"node --expose-gc --import tsx/esm bench/index.ts","build":"tsup","check":"tsc --noEmit && pnpm test:types && echo 'tsc ok' && pnpm lint && pnpm format","format":"prettier --write \"src/**/*.ts\"","prepare":"node --eval \"if (process.env.CI) process.exit(0)\" && husky || true","release":"pnpm build && publint && changeset publish","version":"changeset version","changeset":"changeset","typecheck":"tsc --noEmit","test:types":"tsc --noEmit -p tsconfig.tests.json","test:watch":"vitest","test:mutate":"stryker run","changeset:ai":"tsx scripts/changeset.ts","format:check":"prettier --check \"src/**/*.ts\"","test:coverage":"vitest run --coverage"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f554ef5f-d63e-43e2-864c-f33dd3fe073d"}},"repository":{"url":"git+https://github.com/dkryaklin/colordx.git","type":"git"},"_npmVersion":"12.1.0","description":"A high-performance color library with extended support for modern color spaces including OKLCH, OKLAB, Display-P3, and more","directories":{},"lint-staged":{"src/**/*.ts":["prettier --write","eslint --fix"]},"sideEffects":false,"_nodeVersion":"24.21.0","typesVersions":{"*":{"fn":["./dist/fn.d.ts"],"plugins/*":["./dist/plugins/*.d.ts"],"tinycolor":["./dist/tinycolor.d.ts"]}},"_hasShrinkwrap":false,"packageManager":"pnpm@12.3.4","devDependencies":{"tsx":"^4.21.0","knip":"^6.7.0","tsup":"^8.5.1","color":"^5.0.3","husky":"^9.1.7","colord":"^2.10.0","culori":"^4.0.2","eslint":"^9.39.0","mitata":"^1.0.34","vitest":"^4.1.0","apca-w3":"^0.1.9","esbuild":"^0.28.0","publint":"^0.3.18","prettier":"^3.8.1","chroma-js":"^3.2.0","fast-check":"^4.6.0","tinycolor2":"^1.6.0","typescript":"^5.9.3","lint-staged":"^16.4.0","@texel/color":"^1.1.11","@types/culori":"^4.0.1","@types/apca-w3":"^0","@changesets/cli":"^2.30.0","@types/chroma-js":"^3","@anthropic-ai/sdk":"^0.80.0","@types/tinycolor2":"^1","typescript-eslint":"^8.57.1","@vitest/coverage-v8":"^4.1.0","@stryker-mutator/core":"^9.6.1","eslint-config-prettier":"^10.1.8","@stryker-mutator/vitest-runner":"^9.6.1","@trivago/prettier-plugin-sort-imports":"^6.0.2"},"_npmOperationalInternal":{"tmp":"tmp/core_7.0.0_1790184606265_0.6874270998090384","host":"s3://npm-registry-packages-npm-production"},"readme":"<p align=\"center\">\n  <img src=\"assets/logo.svg\" width=\"128\" height=\"128\" alt=\"colordx\" />\n</p>\n\n# @colordx/core\n\n[![npm version](https://img.shields.io/npm/v/@colordx/core?labelColor=764be5&color=ffc200)](https://www.npmjs.com/package/@colordx/core)\n[![used by cssnano](https://img.shields.io/badge/used_by-cssnano-ffc200?labelColor=764be5)](https://github.com/cssnano/cssnano)\n[![used by oklch-picker](https://img.shields.io/badge/used_by-oklch--picker-ffc200?labelColor=764be5)](https://github.com/evilmartians/oklch-picker)\n[![bundle size](https://img.shields.io/bundlejs/size/@colordx/core?labelColor=764be5&color=ffc200)](https://bundlejs.com/?q=@colordx/core)\n[![npm downloads](https://img.shields.io/npm/dw/@colordx/core?labelColor=764be5&color=ffc200)](https://www.npmjs.com/package/@colordx/core)\n[![zero dependencies](https://img.shields.io/badge/dependencies-0-ffc200?labelColor=764be5)](https://github.com/dkryaklin/colordx/blob/main/package.json)\n[![CI](https://img.shields.io/github/actions/workflow/status/dkryaklin/colordx/ci.yml?branch=main&label=ci&labelColor=764be5&color=ffc200)](https://github.com/dkryaklin/colordx/actions/workflows/ci.yml)\n\n**[Try it on colordx.dev](https://colordx.dev)**\n\nA modern color manipulation library built for the CSS Color 4 era, with first-class support for **OKLCH** and **OKLab**. **8.8 KB gzipped (6.7 KB for `colordx()` alone). 0 Dependencies.**\n\n## Contents\n\n- [Install](#install) · [Quick start](#quick-start)\n- [API](#api): [Parsing](#parsing) · [Conversion](#conversion) · [Precision](#precision) · [Manipulation](#manipulation) · [Getters](#getters) · [Utilities](#utilities)\n- [Gamut](#gamut)\n- [Plugins](#plugins)\n- [Channel functions](#channel-functions) · [Functional API](#functional-api)\n- [Migrating from tinycolor2](#migrating-from-tinycolor2)\n- [Performance](#performance)\n- [Roadmap](#roadmap) · [Ecosystem](#ecosystem)\n\n## Install\n\n```bash\nnpm install @colordx/core\n```\n\n## Quick start\n\n```ts\nimport { colordx } from '@colordx/core';\n\n// Parse any CSS color string or color object, then chain conversions:\ncolordx('#ff0000').toRgbString();     // 'rgb(255 0 0)'\ncolordx('#ff0000').toHex();           // '#ff0000'\ncolordx('#ff0000').toOklch();         // { l: 0.62796, c: 0.25768, h: 29.23388, alpha: 1 }\ncolordx('#ff0000').toOklchString();   // 'oklch(0.62796 0.25768 29.23388)'\n\n// Works from any input format — hex, rgb(), hsl(), oklch(), oklab(), plain objects:\ncolordx('oklch(0.5 0.2 240)').toHex();                     // '#0069c7'\ncolordx({ r: 255, g: 0, b: 0 }).toHslString();             // 'hsl(0 100% 50%)'\n\n// Chain manipulations — each call returns a new immutable Colordx:\ncolordx('#ff0000').lighten(0.1).saturate(0.2).toHex();\ncolordx('#3d7a9f').rotate(30).darken(0.1).toRgbString();\n```\n\n`.toHex()` and `.toRgbString()` clip an out-of-gamut `oklch()` / `oklab()` the way browsers render it. For gamut mapping instead, see [Gamut](#gamut).\n\n## API\n\nAll methods are immutable — they return a new `Colordx` instance.\n\nA method that needs two colors (`contrast()`, `mix()`, `delta()`, `over()`, `nearest()`, …) throws a `RangeError` on an invalid one, naming the method and the input. Single-color methods on an invalid instance read it as black, as colord does, so check `isValid()` on untrusted input.\n\n### Parsing\n\nAccepts any CSS color string or color object:\n\n```ts\ncolordx('#ff0000');\ncolordx('#f00');\ncolordx('rgb(255 0 0)');\ncolordx('color(srgb 1 0 0)'); // CSS Color 4 color() form of sRGB\ncolordx('rgba(255, 0, 0, 0.5)');\ncolordx('hsl(0 100% 50%)');\ncolordx('oklab(0.6279 0.2249 0.1257)');\ncolordx('oklch(0.6279 0.2577 29.23)');\ncolordx('oklch(6e-1 1e-7 30)');           // CSS number tokens may carry an exponent\ncolordx({ r: 255, g: 0, b: 0 });           // alpha defaults to 1\ncolordx({ r: 255, g: 0, b: 0, alpha: 0.5 });\ncolordx({ r: 255, g: 0, b: 0, a: 0.5 });   // `a` is an alias for `alpha`\ncolordx({ h: 0, s: 100, l: 50 });\ncolordx({ l: 0.6279, a: 0.2249, b: 0.1257 }); // OKLab\ncolordx({ l: 0.6279, c: 0.2577, h: 29.23 }); // OKLch\n// With p3 plugin loaded:\ncolordx('color(display-p3 0.9175 0.2003 0.1386)'); // Display-P3 string\n// With rec2020 plugin loaded:\ncolordx('color(rec2020 0.82346 0.32843 0.18034)'); // Rec.2020 string\n// With a98rgb plugin loaded:\ncolordx('color(a98-rgb 0.8586 0 0)'); // A98 (Adobe RGB 1998) string\n// With prophoto plugin loaded:\ncolordx('color(prophoto-rgb 0.70225 0.27572 0.10355)'); // ProPhoto string\n// With srgb-linear plugin loaded:\ncolordx('color(srgb-linear 1 0 0)'); // linear-light sRGB string\n// With hwb plugin loaded:\ncolordx('hwb(0 0% 0%)');\ncolordx({ h: 0, w: 0, b: 0 });\n// With hsv plugin loaded:\ncolordx({ h: 0, s: 100, v: 100 }); // HSV\n```\n\nChannels are clamped the way CSS Color 4 clamps them at parsed-value time: `rgb()` / `hsl()` channels to their ranges, `lab()` / `lch()` / `oklab()` / `oklch()` lightness to `[0, 100]` / `[0, 1]`, chroma to `≥ 0`. Lab/LCH `a`, `b`, `c` and OKLab/OKLCh `a`, `b`, `c` are unbounded, which is what makes out-of-gamut colors representable (see [Gamut](#gamut)). Alpha is clamped to `[0, 1]`.\n\n<details>\n<summary>Edge cases: lightness round-trips, rejected objects, NaN</summary>\n\n- An imaginary `lab()` / `lch()` / `color(xyz …)` input can have an OKLab lightness outside `[0, 1]`; `.toOklchString()` reports it faithfully, but feeding that string back clamps L, so only colors with L in range round-trip through OKLCh. The same holds the other way for CIE Lab: a far-out-of-gamut `oklch()` / `oklab()` / `color()` input can have a Lab lightness below 0 (`oklch(0.31924 0.4 279.2)` → `lab(-7.33 212.95 -169.91)`), which `.toLabString()` / `.toLchString()` print as is and a browser clamps to 0.\n- An OKLab/OKLCh object with `l > 1` is rejected as invalid — it is almost certainly a CIE Lab/LCH value missing its `colorSpace: 'lab' | 'lch'` brand, and clamping it to white would hide the mistake.\n- An object whose `colorSpace` names a different space than its keys (`{ r, g, b, colorSpace: 'lab' }`, `{ h, s, l, colorSpace: 'okhsv' }`) is rejected rather than read as the unbranded model.\n- `NaN` in any channel reads as `0` (an infinite hue reads as `0°`).\n\n</details>\n\nObject input accepts `a` as an alias for `alpha` (the `{ r, g, b, a }` shape colord and tinycolor2 use) in every color model except Lab and OKLab, where `a` is a channel. When both are present, `alpha` wins.\n\nTypeScript: input color objects use `*ColorInput` types (`alpha` optional, defaults to 1).\nOutput methods like `.toRgb()` / `.toOklch()` return `*Color` types (`alpha` always present).\n\n```ts\nimport type { RgbColor, RgbColorInput } from '@colordx/core';\n\nconst input: RgbColorInput = { r: 255, g: 0, b: 0 };       // alpha optional\nconst output: RgbColor = colordx(input).toRgb();           // alpha guaranteed\n```\n\n### Conversion\n\n```ts\n.toRgb()           // { r: 255, g: 0, b: 0, alpha: 1 }\n.toRgb(2)          // unrounded channels, kept to 2 decimals: colordx('hsl(210 40% 47%)').toRgb(2) → { r: 71.91, g: 119.85, b: 167.79, alpha: 1 }\n.toRgbString()                    // 'rgb(255 0 0)'                — CSS Color 4 (default)\n.toRgbString({ legacy: true })    // 'rgb(255, 0, 0)'              — CSS Color 3 comma syntax\n// Legacy form also switches to `rgba()` when alpha < 1:\ncolordx({ r: 255, g: 0, b: 0, alpha: 0.5 }).toRgbString({ legacy: true }); // 'rgba(255, 0, 0, 0.5)'\n.toHex()           // '#ff0000'\n.toNumber()        // 16711680  (0xff0000 — PixiJS / Discord integer format)\n.toNumber32()      // 4278190335 (0xff0000ff — 32-bit RGBA, alpha as the low byte)\n.toHsl()           // { h: 0, s: 100, l: 50, alpha: 1 }\n.toHslString()     // 'hsl(0 100% 50%)'\n// toHsl accepts an optional precision argument (decimal places):\ncolordx('#3d7a9f').toHsl()         // { h: 202.65, s: 44.55, l: 43.14, alpha: 1 }      — default (2)\ncolordx('#3d7a9f').toHsl(4)        // { h: 202.6531, s: 44.5455, l: 43.1373, alpha: 1 }\ncolordx('#3d7a9f').toHsl(0)        // { h: 203, s: 45, l: 43, alpha: 1 }               — integers\ncolordx('#3d7a9f').toHslString()   // 'hsl(202.65 44.55% 43.14%)'\ncolordx('#3d7a9f').toHslString(4)  // 'hsl(202.6531 44.5455% 43.1373%)'\n// With hwb plugin loaded:\n.toHwb()           // { h: 0, w: 0, b: 0, alpha: 1 }\n.toHwbString()     // 'hwb(0 0% 0%)'\n.toOklab()         // { l: 0.62796, a: 0.22486, b: 0.12585, alpha: 1 }\n.toOklabString()   // 'oklab(0.62796 0.22486 0.12585)'\n.toOklch()         // { l: 0.62796, c: 0.25768, h: 29.23388, alpha: 1 }\n.toOklchString()   // 'oklch(0.62796 0.25768 29.23388)'\n// With p3 plugin loaded:\n.toP3()            // { r: 0.9175, g: 0.2003, b: 0.1386, alpha: 1, colorSpace: 'display-p3' }\n.toP3String()      // 'color(display-p3 0.9175 0.2003 0.1386)'\n// With srgb-linear plugin loaded:\n.toSrgbLinear()    // { r: 1, g: 0, b: 0, alpha: 1, colorSpace: 'srgb-linear' }\n.toSrgbLinearString() // 'color(srgb-linear 1 0 0)'\n```\n\n### Precision\n\nEvery `toX()` / `toXString()` method accepts an optional `precision` (decimal places), applied uniformly to every channel of that format. Alpha is fixed at 3 dp globally. Hues are wrapped after rounding, so a hue never prints as `360` at any precision. Format-specific defaults (scale-appropriate):\n\n| format | default |\n|---|---|\n| `toHsl`, `toHsv`, `toHwb`, `toCmyk`, `toLab`, `toLch`, `toXyz`, `toXyzD65` | `2` |\n| `toP3`, `toA98` | `4` |\n| `toOklab`, `toOklch`, `toOkhsl`, `toOkhsv`, `toSrgbLinear`, `toRec2020`, `toProphoto`, `toXyzString`, `toXyzD65String` | `5` |\n\nEach string default is the fewest decimals at which every 8-bit sRGB color parses back to the same bytes. A precision above 20 reads as 20 (past double precision anyway), and NaN or a negative as 0.\n\n```ts\ncolordx('#3d7a9f').toHsl();      // { h: 202.65, s: 44.55, l: 43.14, alpha: 1 }\ncolordx('#3d7a9f').toHsl(4);     // { h: 202.6531, s: 44.5455, l: 43.1373, alpha: 1 }\ncolordx('#3d7a9f').toHsl(0);     // { h: 203, s: 45, l: 43, alpha: 1 }\n\ncolordx('#ff0000').toOklchString();   // 'oklch(0.62796 0.25768 29.23388)'\ncolordx('#ff0000').toOklchString(2);  // 'oklch(0.63 0.26 29.23)'\n```\n\n### Manipulation\n\n```ts\n.lighten(0.1)                        // increase lightness by 10 percentage points\n.lighten(0.1, { relative: true })    // increase lightness by 10% of current value\n.darken(0.1)                         // decrease lightness by 10 percentage points\n.darken(0.1, { relative: true })     // decrease lightness by 10% of current value\n.saturate(0.1)                       // increase saturation by 10 percentage points\n.saturate(0.1, { relative: true })   // increase saturation by 10% of current value\n.desaturate(0.1)                     // decrease saturation by 10 percentage points\n.desaturate(0.1, { relative: true }) // decrease saturation by 10% of current value\n.grayscale()       // fully desaturate\n.invert()          // invert RGB channels\n.rotate(30)        // rotate hue by 30°\n.alpha(0.5)        // set alpha\n.hue(120)          // set hue (HSL)\n.lightness(0.5)    // set lightness (OKLCH, 0–1)\n.chroma(0.1)       // set chroma (OKLCH, 0–0.4)\n```\n\nThe HSL-based methods and `invert` work on the sRGB-clipped color, the one `.toHex()` prints. `lightness()` and `chroma()` work in OKLCH and clip the result. A whole-turn `rotate` (`0`, `±360`, …) returns the color untouched.\n\nBy default, `.lighten(0.1)` shifts lightness by an **absolute** 10 percentage points. Pass `{ relative: true }` to shift by a fraction of the **current** value instead — useful when migrating from Qix's `color` library or when you want proportional adjustments:\n\n```ts\ncolordx('hsl(0 100% 10%)').lighten(0.1); // l = 10 + 10 = 20%  (absolute)\ncolordx('hsl(0 100% 10%)').lighten(0.1, { relative: true }); // l = 10 * 1.1 = 11% (relative)\n\ncolordx('hsl(0 40% 50%)').saturate(0.1); // s = 40 + 10 = 50%  (absolute)\ncolordx('hsl(0 40% 50%)').saturate(0.1, { relative: true }); // s = 40 * 1.1 = 44% (relative)\n```\n\nThe same flag works on `.darken()` and `.desaturate()`.\n\n### Getters\n\n```ts\n.isValid()         // true if input was parseable\n.alpha()           // get alpha (0–1)\n.hue()             // get HSL hue, [0, 360)\n.lightness()       // get OKLCH lightness (0–1)\n.chroma()          // get OKLCH chroma (0–0.4)\n.brightness()      // perceived brightness (0–1), of the sRGB-clipped color\n.isDark()          // brightness < 0.5\n.isLight()         // brightness >= 0.5\n.isEqual('#f00')   // same RGBA bytes after rounding; false if either is invalid\n.over('#fff')      // source-over composite of a translucent color onto a bg\n// With a11y plugin loaded:\n.luminance()       // relative luminance (0–1, WCAG), optional precision\n.contrast('#fff')  // WCAG 2.x contrast ratio (1–21), optional precision\n// With mix plugin loaded:\n.mix('#0000ff', 0.5)       // mix in sRGB space (CSS spec)\n.mixOklab('#0000ff', 0.5)  // mix in Oklab space (perceptually uniform)\n```\n\n### Utilities\n\n```ts\nimport { getFormat, nearest, random } from '@colordx/core';\n\ngetFormat('#ff0000'); // 'hex'\ngetFormat('rgb(255 0 0)'); // 'rgb'\ngetFormat('hsl(0 100% 50%)'); // 'hsl'\ngetFormat('oklch(0.5 0.2 240)'); // 'oklch'\ngetFormat('oklab(0.6279 0.2249 0.1257)'); // 'oklab'\ngetFormat({ r: 255, g: 0, b: 0 }); // 'rgb'\ngetFormat({ h: 0, s: 100, l: 50 }); // 'hsl'\ngetFormat('notacolor'); // undefined\n// Plugin-added parsers register their own format:\n// p3 → 'p3', hsv → 'hsv', hwb → 'hwb', okhsl → 'okhsl', okhsv → 'okhsv', cmyk → 'cmyk', lch → 'lch', lab → 'lab' | 'xyz' | 'xyz-d65', names → 'name', rec2020 → 'rec2020', a98rgb → 'a98-rgb', prophoto → 'prophoto-rgb', srgb-linear → 'srgb-linear'\n\nnearest('#800', ['#f00', '#ff0', '#00f']); // '#f00' — perceptual distance via OKLab\nnearest('#ffe', ['#f00', '#ff0', '#00f']); // '#ff0'\n\nrandom(); // random Colordx instance\n```\n\n## Gamut\n\nAn out-of-gamut `oklch()` / `oklab()` input is stored unclamped, so `.toOklchString()` round-trips what you wrote. `.toHex()` and `.toRgbString()` clip it at output the way browsers do, which is what you want for everyday conversion. When you need a `Colordx` that is itself inside sRGB, choose how it gets there:\n\n```ts\nconst input = 'oklch(0.5 0.4 180)';  // out of sRGB gamut\n\n// 1. Preserve — keep the authored oklch as-is, clip only at sRGB output time\ncolordx(input).toOklchString();          // 'oklch(0.5 0.4 180)'\ncolordx(input).toRgbString();            // 'rgb(0 152 108)' — naive clip, matches browser\n\n// 2. Map — CSS Color 4 gamut mapping (reduces chroma; lightness + hue kept within JND)\ncolordx(input).mapSrgb().toOklchString();   // 'oklch(0.50903 0.09378 177.85846)'\ncolordx(input).mapSrgb().toRgbString();     // 'rgb(0 119 102)'\n\n// 3. Clamp — naive-clip into sRGB as a Colordx (matches browser, but hue drifts)\ncolordx(input).clampSrgb().toOklchString(); // 'oklch(0.60125 0.1276 164.29893)'\ncolordx(input).clampSrgb().toRgbString();   // 'rgb(0 152 108)' — same bytes as (1)\n```\n\n- **`.mapSrgb()`** — CSS Color 4 gamut mapping: reduces chroma and keeps lightness and hue within a just-noticeable difference. Use for CSS output, OKLCH pickers and harmonies.\n- **`.clampSrgb()`** — naive clip in linear sRGB. Hue and lightness may drift. Use when you want a `Colordx` whose `.toOklchString()` describes what browsers actually render.\n\n<details>\n<summary>How far <code>mapSrgb()</code> can drift, and which methods clip</summary>\n\nPer the spec, the search stops at the first clipped color within a just-noticeable difference (deltaEOK 0.02) of its chroma-reduced candidate, so L and h can drift slightly — most visibly on colors far outside sRGB (the example above lands at hue 177.9°, not 180°; a pale or dark saturated red can move several degrees of hue, or land on pure `#xx0000`). When a palette needs exact L and h per step, bisect chroma with `inGamutSrgb()` instead.\n\nWhich color a method sees follows from its model. Wide-gamut models (`toOklab`, `toOklch`, `toLab`, `toLch`, `toXyz*`, `toP3`, `toRec2020`, `toA98`, `toProphoto`, `toSrgbLinear`, `mix`, `mixOklab`, `mixLab`, `delta`) read the unclamped color, and the three mixers keep their result unclamped too, like `color-mix()`. sRGB-bounded models (`toRgb`, `toHex`, `toHsl`, `toHsv`, `toHwb`, `toCmyk`, `toName`, `brightness`) and the HSL-based manipulators read the naive-clipped color, so `.toHslString()` always names the same color as `.toHex()`. The a11y and cvd plugins gamut-map (not clip) first.\n\n</details>\n\n`Colordx.toGamutSrgb(input)` is the static form of `colordx(input).mapSrgb()`. It and the plugin mappers (`toGamutP3()`, `toGamutRec2020()`, `toGamutA98()`, `toGamutProphoto()`) return a color already in the target gamut unchanged.\n\ncolordx also includes standalone utilities for checking and mapping into wider gamuts (Display-P3 / Rec.2020, via plugins):\n\n```ts\nimport { Colordx, inGamutSrgb } from '@colordx/core';\nimport { inGamutP3 } from '@colordx/core/plugins/p3';\nimport { inGamutRec2020 } from '@colordx/core/plugins/rec2020';\nimport p3 from '@colordx/core/plugins/p3';\nimport rec2020 from '@colordx/core/plugins/rec2020';\nextend([p3, rec2020]);\n\n// Check: is this color displayable in sRGB?\ninGamutSrgb('#ff0000'); // true  — hex is always sRGB\ninGamutSrgb('oklch(0.5 0.1 30)'); // true  — clearly in sRGB\ninGamutSrgb('oklch(0.5 0.4 180)'); // false — too much cyan chroma\ninGamutSrgb('not-a-color'); // false — not a color, so in no gamut\n\n// Map: reduce chroma until in-gamut (lightness and hue kept within JND)\nColordx.toGamutSrgb('oklch(0.5 0.4 180)'); // → Colordx at the sRGB boundary\nColordx.toGamutSrgb('#ff0000'); // → unchanged, already in sRGB\n\n// Display-P3 gamut (wider than sRGB) — available after extend([p3])\ninGamutP3('oklch(0.64 0.27 29)'); // true  — inside P3 but outside sRGB\ninGamutP3('oklch(0.5 0.4 180)'); // false — outside P3\nColordx.toGamutP3('oklch(0.5 0.4 180)'); // → Colordx at the P3 boundary\n\n// Rec.2020 gamut (wider than P3) — available after extend([rec2020])\ninGamutRec2020('oklch(0.5 0.4 180)'); // false — outside Rec.2020\nColordx.toGamutRec2020('oklch(0.5 0.4 180)'); // → Colordx at the Rec.2020 boundary\n```\n\n`inGamut*` always returns `true` for sRGB-bounded inputs (hex, rgb, hsl, hsv, hwb). Mapping follows the [CSS Color 4 gamut mapping algorithm](https://www.w3.org/TR/css-color-4/#css-gamut-mapping).\n\n<details>\n<summary>How the gamuts nest</summary>\n\nGamut containment is largely hierarchical: sRGB ⊂ Display-P3 ⊂ Rec.2020 ⊂ ProPhoto. A98 (Adobe RGB 1998) sits between sRGB and Rec.2020 — wider than sRGB, mostly in the greens — but is not a strict superset of Display-P3.\n\n</details>\n\nChecks and mapping accept every wide-gamut input `colordx()` does — `lab()` / `lch()` strings, `color(display-p3 …)` and friends, branded `{ colorSpace: 'lab' | 'lch' }` objects — once that format's plugin is loaded. A plugin's own helpers (`inGamutP3`, `inGamutRec2020`, …) read their own format without `extend()`:\n\n```ts\nextend([lab, lch]);\n\n// CIE LCH object — recognized as wide-gamut, not clamped at parse time\nconst lch = { l: 50, c: 100, h: 180, alpha: 1, colorSpace: 'lch' as const };\ninGamutSrgb(lch);  // false — outside sRGB\ninGamutP3(lch);    // false — outside P3\ncolordx(lch).toHex();           // '#009774' — naive clip\ncolordx(lch).mapSrgb().toHex(); // '#008471' — chroma-reduced (CSS Color 4)\n\n// CIE Lab string works too\ninGamutSrgb('lab(50 100 0)'); // false\nColordx.toGamutSrgb('lab(50 100 0)'); // → Colordx at the sRGB boundary\n```\n\n## Plugins\n\nOpt-in plugins for less common color spaces and utilities. Each is imported from `@colordx/core/plugins/<name>` and registered once with `extend()`:\n\n| Plugin | Adds |\n|---|---|\n| **Color spaces** | |\n| [`lab`](#lab-plugin) | CIE Lab and XYZ (D50, D65), `mixLab()`, `delta()` (CIEDE2000) |\n| [`lch`](#lch-plugin) | CIE LCH |\n| [`hsv`](#hsv-plugin) | HSV, plus HSV channel functions |\n| [`hwb`](#hwb-plugin) | HWB |\n| [`cmyk`](#cmyk-plugin) | CMYK, `device-cmyk()` |\n| [`okhsl`, `okhsv`](#okhsl-and-okhsv-plugins) | Okhsl and Okhsv picker spaces |\n| [`p3`](#p3-plugin) | Display-P3, `inGamutP3()`, `Colordx.toGamutP3()` |\n| [`rec2020`](#rec2020-plugin) | Rec.2020, `inGamutRec2020()`, `Colordx.toGamutRec2020()` |\n| [`a98rgb`](#a98rgb-plugin) | A98 (Adobe RGB 1998), `inGamutA98()`, `Colordx.toGamutA98()` |\n| [`prophoto`](#prophoto-plugin) | ProPhoto, `inGamutProphoto()`, `Colordx.toGamutProphoto()` |\n| [`srgb-linear`](#srgb-linear-plugin) | `color(srgb-linear …)` |\n| **Tools** | |\n| [`a11y`](#a11y-plugin) | WCAG and APCA contrast, readability gates, `fixContrast()` |\n| [`cvd`](#cvd-plugin) | Colour vision deficiency simulation |\n| [`mix`](#mix-plugin) | `mix()`, `mixOklab()`, tints, shades, tones, palettes |\n| [`harmonies`](#harmonies-plugin) | Color harmonies |\n| [`names`](#names-plugin) | CSS color names |\n| [`minify`](#minify-plugin) | Shortest CSS string |\n\nAll of them at once:\n\n```ts\nimport { extend } from '@colordx/core';\nimport a11y from '@colordx/core/plugins/a11y';\nimport cmyk from '@colordx/core/plugins/cmyk';\nimport cvd from '@colordx/core/plugins/cvd';\nimport harmonies from '@colordx/core/plugins/harmonies';\nimport hwb from '@colordx/core/plugins/hwb';\nimport hsv from '@colordx/core/plugins/hsv';\nimport okhsl from '@colordx/core/plugins/okhsl';\nimport okhsv from '@colordx/core/plugins/okhsv';\nimport lab from '@colordx/core/plugins/lab';\nimport lch from '@colordx/core/plugins/lch';\nimport minify from '@colordx/core/plugins/minify';\nimport mix from '@colordx/core/plugins/mix';\nimport names from '@colordx/core/plugins/names';\nimport p3 from '@colordx/core/plugins/p3';\nimport rec2020 from '@colordx/core/plugins/rec2020';\nimport a98rgb from '@colordx/core/plugins/a98rgb';\nimport prophoto from '@colordx/core/plugins/prophoto';\nimport srgbLinear from '@colordx/core/plugins/srgb-linear';\n\nextend([lab, lch, cmyk, names, a11y, harmonies, hwb, hsv, okhsl, okhsv, mix, minify, p3, rec2020, a98rgb, prophoto, srgbLinear]);\n```\n\n### lab plugin\n\nCIE Lab (D50), CIE XYZ (D50), and CIE XYZ (D65) color models. Lab and XYZ objects are also accepted as color input (Lab requires a `colorSpace: 'lab'` discriminant; XYZ D65 requires `colorSpace: 'xyz-d65'`; plain `{ x, y, z }` parses as D50). Also adds `.mixLab()` for perceptual mixing in CIE Lab, `.delta()` for CIEDE2000 color difference, and string conversion methods.\n\n```ts\nimport lab from '@colordx/core/plugins/lab';\n\nextend([lab]);\n\ncolordx('#ff0000').toLab(); // { l: 54.29, a: 80.8, b: 69.89, alpha: 1, colorSpace: 'lab' }\ncolordx('#ff0000').toLabString(); // 'lab(54.29 80.8 69.89)'\ncolordx('lab(54.29 80.8 69.89)').toHex(); // '#ff0000'  — lab strings are parseable\n\n// XYZ D50 (chromatic-adapted; matches Lab's white point)\ncolordx('#ff0000').toXyz(); // { x: 43.61, y: 22.25, z: 1.39, alpha: 1 }\ncolordx('#ff0000').toXyzString(); // 'color(xyz-d50 0.43607 0.22249 0.01392)' — CSS scale (1 = reference white)\n\n// XYZ D65 (screen-native; no Bradford adaptation — same illuminant as sRGB/OKLab)\ncolordx('#ff0000').toXyzD65(); // { x: 41.24, y: 21.26, z: 1.93, alpha: 1, colorSpace: 'xyz-d65' }\ncolordx('#ff0000').toXyzD65String(); // 'color(xyz-d65 0.41239 0.21264 0.01933)'\n\n// Lab and XYZ objects parse as color input (with lab plugin loaded)\n// Lab objects require colorSpace: 'lab' to distinguish from OKLab (which has the same l/a/b shape)\ncolordx({ l: 54.29, a: 80.8, b: 69.89, colorSpace: 'lab' as const }).toHex(); // '#ff0000'\ncolordx({ x: 43.61, y: 22.25, z: 1.39 }).toHex(); // '#ff0000' (D50)\ncolordx({ x: 41.24, y: 21.26, z: 1.93, colorSpace: 'xyz-d65' as const }).toHex(); // '#ff0000'\n\n// color() strings parse for both white points. Per CSS Color 4 the string channels are 0–1\n// (1 = reference-white Y, 100% = 1), unlike the 0–100 object convention above.\ncolordx('color(xyz-d50 0.43607 0.22249 0.01392)').toHex(); // '#ff0000'\ncolordx('color(xyz-d65 0.41239 0.21264 0.01933)').toHex(); // '#ff0000'\ncolordx('color(xyz 0.4124 0.2126 0.0193)').toHex(); // '#ff0000' — bare xyz is the spec alias for xyz-d65\ncolordx('color(xyz-d65 41.24% 21.26% 1.93%)').toHex(); // '#ff0000'\n\n// Mix in CIE Lab space\ncolordx('#000000').mixLab('#ffffff').toHex(); // '#777777'\n\n// CIEDE2000 perceptual color difference (0 = identical, ~1 = maximum)\ncolordx('#ff0000').delta('#ff0000'); // 0\ncolordx('#000000').delta('#ffffff'); // ~1\ncolordx('#ff0000').delta(); // compared against white (default)\ncolordx('#ef4444').delta('#10b981', 5); // 0.71465 — optional precision (default 3)\n```\n\n### lch plugin\n\nCIE LCH (D50) — the polar form of CIE Lab. Parses `lch()` CSS strings and LCH objects.\n\n```ts\nimport lch from '@colordx/core/plugins/lch';\n\nextend([lch]);\n\ncolordx('#ff0000').toLch(); // { l: 54.29, c: 106.84, h: 40.86, alpha: 1, colorSpace: 'lch' }\ncolordx('#ff0000').toLchString(); // 'lch(54.29 106.84 40.86)'\ncolordx('lch(54.29 106.84 40.86)').toHex(); // '#ff0000'\n// LCH objects require colorSpace: 'lch' to distinguish from OKLCH (which has the same l/c/h shape)\ncolordx({ l: 50, c: 50, h: 180, colorSpace: 'lch' as const }).toHex(); // parses as LCH object\n```\n\n### hsv plugin\n\nHSV/HSVa color model. Parses `hsv()` / `hsva()` strings and HSV objects.\n\n```ts\nimport hsv from '@colordx/core/plugins/hsv';\n\nextend([hsv]);\n\ncolordx('#ff0000').toHsv(); // { h: 0, s: 100, v: 100, alpha: 1 }\ncolordx('#ff0000').toHsvString(); // 'hsv(0 100% 100%)'\ncolordx('hsv(0 100% 100%)').toHex(); // '#ff0000'\ncolordx({ h: 0, s: 100, v: 100, alpha: 1 }).toHex(); // '#ff0000'\n```\n\nThe plugin entry also exports the HSV channel functions — `rgbToHsvChannels`, `hsvToRgbChannels` and their `*Into` siblings — for per-pixel work such as a saturation/value plane:\n\n```ts\nimport { hsvToRgbChannelsInto } from '@colordx/core/plugins/hsv';\n\n// 256×256 S/V plane for a fixed hue → RGBA bytes. One buffer, no allocation per pixel.\nconst buf = new Float64Array(3);\nconst plane = new Uint8ClampedArray(256 * 256 * 4);\nlet i = 0;\nfor (let y = 0; y < 256; y++) {\n  for (let x = 0; x < 256; x++) {\n    hsvToRgbChannelsInto(buf, 210, (x / 255) * 100, (1 - y / 255) * 100);\n    plane[i++] = buf[0] * 255;\n    plane[i++] = buf[1] * 255;\n    plane[i++] = buf[2] * 255;\n    plane[i++] = 255;\n  }\n}\n```\n\n### hwb plugin\n\nCSS Color Level 4 HWB (Hue, Whiteness, Blackness) color model.\n\n```ts\nimport hwb from '@colordx/core/plugins/hwb';\n\nextend([hwb]);\n\ncolordx('#ff0000').toHwb();         // { h: 0, w: 0, b: 0, alpha: 1 }\ncolordx('#ff0000').toHwbString();   // 'hwb(0 0% 0%)'\ncolordx('hwb(0 0% 0%)').toHex();   // '#ff0000'\ncolordx({ h: 0, w: 0, b: 0, alpha: 1 }).toHex(); // '#ff0000'\n\n// toHwb accepts an optional precision argument (decimal places):\ncolordx('#3d7a9f').toHwb();    // { h: 202.65, w: 23.92, b: 37.65, alpha: 1 }   — default (2)\ncolordx('#3d7a9f').toHwb(2);   // { h: 202.65, w: 23.92, b: 37.65, alpha: 1 }\ncolordx('#3d7a9f').toHwbString();  // 'hwb(202.65 23.92% 37.65%)'\ncolordx('#3d7a9f').toHwbString(2); // 'hwb(202.65 23.92% 37.65%)'\n```\n\n### cmyk plugin\n\nCMYK color model. Parses `device-cmyk()` CSS strings and CMYK objects.\n\n```ts\nimport cmyk from '@colordx/core/plugins/cmyk';\n\nextend([cmyk]);\n\ncolordx('#ff0000').toCmyk(); // { c: 0, m: 100, y: 100, k: 0, alpha: 1 }\ncolordx('#ff0000').toCmykString(); // 'device-cmyk(0% 100% 100% 0%)'\ncolordx('device-cmyk(0% 100% 100% 0%)').toHex(); // '#ff0000'\ncolordx({ c: 0, m: 100, y: 100, k: 0 }).toHex(); // '#ff0000'\n```\n\n### okhsl and okhsv plugins\n\n[Okhsl and Okhsv](https://bottosson.github.io/posts/colorpicker/) are Björn Ottosson's color-picker spaces: the shape of HSL / HSV, where every `h`/`s`/`l` combination is a real sRGB color, with the perceptual behaviour of OKLCH. Same scale as `toHsl()` / `toHsv()`: h in degrees, s / l / v in 0–100. The `okhsl()` / `okhsv()` strings are this library's own (CSS has no such syntax), and objects carry a `colorSpace` brand because `{ h, s, l }` alone is HSL.\n\n```ts\nimport okhsl from '@colordx/core/plugins/okhsl';\nimport okhsv from '@colordx/core/plugins/okhsv';\n\nextend([okhsl, okhsv]);\n\ncolordx('#3d7a9f').toOkhsl();       // { h: 237.65615, s: 57.92201, l: 48.38305, alpha: 1, colorSpace: 'okhsl' }\ncolordx('#3d7a9f').toOkhsv();       // { h: 237.65615, s: 65.38077, v: 64.31605, alpha: 1, colorSpace: 'okhsv' }\ncolordx('#3d7a9f').toOkhslString(); // 'okhsl(237.65615 57.92201% 48.38305%)'\ncolordx('#3d7a9f').toOkhsvString(); // 'okhsv(237.65615 65.38077% 64.31605%)'\ncolordx('okhsl(237.65615 57.92201% 48.38305%)').toHex(); // '#3d7a9f'\ncolordx({ colorSpace: 'okhsv', h: 237.65615, s: 65.38077, v: 64.31605 }).toHex(); // '#3d7a9f'\ncolordx('#3d7a9f').toOkhsl(2);      // { h: 237.66, s: 57.92, l: 48.38, alpha: 1, colorSpace: 'okhsl' }\ncolordx('#3d7a9f').toOkhsl().h === colordx('#3d7a9f').toOklch().h; // true\n```\n\n<details>\n<summary>Channels, precision and edge cases</summary>\n\n`h` is exactly the OKLCH hue, so a hue ramp stays the same hue instead of drifting purple in the blues; Okhsl's `l` is a lightness estimate that tracks CIELab L (`toe(OKLab L)`); `s` remaps chroma onto 0–100 with the interior kept smooth across hues.\n\nBoth spaces are defined for sRGB only; a wide-gamut input reads as its sRGB clip, like `toHsl()`. The default precision is 5 dp rather than the 2 of `toHsl()`: the OKLCH hue is sensitive around the edges of the sRGB cube, and at 2 dp `rgb(0, 42, 204)` comes back as `rgb(7, 53, 190)`. Two edge behaviours are inherent to the spaces and shared with every implementation of the reference code: pure blues (`r = g = 0`) do not round-trip at any printed precision (`#0000ff` → `okhsl(264.05202 100% 36.65653%)` → `#0134e2` — at that hue and lightness the most chromatic sRGB color really is that one; the hue would need ~8 dp), and the reference approximates the gamut cusp with a polynomial, so ~0.7% of 8-bit colors report a raw `s` a little above 100 (at most ~101.2). `toOkhsl()` / `toOkhsv()` clamp it, the channel functions do not, and about 1 in 16 of the clamped colors comes back up to 5 bytes off.\n\n</details>\n\nThe plugin entries also export channel functions — `rgbToOkhslChannels`, `okhslToRgbChannels`, `rgbToOkhsvChannels`, `okhsvToRgbChannels` and their `*Into` siblings — for per-pixel work. Same shape as the HSV ones (RGB in 0–1), so a picker plane is a drop-in:\n\n```ts\nimport { okhslToRgbChannelsInto } from '@colordx/core/plugins/okhsl';\n\n// 256×256 saturation / lightness plane for a fixed hue → RGBA bytes. Every cell is in gamut.\nconst buf = new Float64Array(3);\nconst plane = new Uint8ClampedArray(256 * 256 * 4);\nlet i = 0;\nfor (let y = 0; y < 256; y++) {\n  for (let x = 0; x < 256; x++) {\n    okhslToRgbChannelsInto(buf, 210, (x / 255) * 100, (1 - y / 255) * 100);\n    plane[i++] = buf[0] * 255;\n    plane[i++] = buf[1] * 255;\n    plane[i++] = buf[2] * 255;\n    plane[i++] = 255;\n  }\n}\n```\n\n### p3 plugin\n\nAdds Display-P3 color space support. P3 has a wider gamut than sRGB and is natively supported by all modern browsers and most Mac/iOS displays.\n\n```ts\nimport p3 from '@colordx/core/plugins/p3';\n\nextend([p3]);\n\ncolordx('#ff0000').toP3(); // { r: 0.9175, g: 0.2003, b: 0.1386, alpha: 1, colorSpace: 'display-p3' }\ncolordx('#ff0000').toP3String(); // 'color(display-p3 0.9175 0.2003 0.1386)'\n\n// Parse Display-P3 strings (alpha optional)\ncolordx('color(display-p3 0.9175 0.2003 0.1386)').toHex(); // '#ff0000'\ncolordx('color(display-p3 0.9175 0.2003 0.1386 / 0.5)').toHex(); // '#ff000080'\n```\n\nThe plugin also exports standalone gamut utilities and low-level channel functions. `inGamutP3` and the channel helpers need no `extend()`. Gamut mapping is available as `Colordx.toGamutP3` after `extend([p3])`:\n\n```ts\nimport { Colordx, extend } from '@colordx/core';\nimport p3, { inGamutP3, linearToP3Channels, oklchToP3Channels } from '@colordx/core/plugins/p3';\n\nextend([p3]);\n\ninGamutP3('oklch(0.64 0.27 29)');        // true — inside P3 but outside sRGB\nColordx.toGamutP3('oklch(0.5 0.4 180)'); // → Colordx at the P3 boundary\n\noklchToP3Channels(0.5, 0.2, 240); // [r, g, b] gamma-encoded P3, unclamped\n```\n\nObject parsing is also supported using the `colorSpace` discriminant:\n\n```ts\ncolordx({ r: 0.9505, g: 0.2856, b: 0.0459, alpha: 1, colorSpace: 'display-p3' }).toHex();\n```\n\n### rec2020 plugin\n\nAdds Rec.2020 (BT.2020) color space support. Rec.2020 is wider than Display-P3 and covers most of the visible spectrum. It uses the pure 2.4 gamma CSS Color 4 now defines for `rec2020` ([csswg-drafts#12574](https://github.com/w3c/csswg-drafts/issues/12574)), so `color(rec2020 …)` values differ from those of libraries still on the older BT.2020 curve (culori 4, for one).\n\n```ts\nimport rec2020 from '@colordx/core/plugins/rec2020';\n\nextend([rec2020]);\n\ncolordx('#ff0000').toRec2020(); // { r: 0.82346, g: 0.32843, b: 0.18034, alpha: 1, colorSpace: 'rec2020' }\ncolordx('#ff0000').toRec2020String(); // 'color(rec2020 0.82346 0.32843 0.18034)'\n\n// Parse Rec.2020 strings (alpha optional)\ncolordx('color(rec2020 0.82346 0.32843 0.18034)').toHex(); // '#ff0000'\ncolordx('color(rec2020 0.82346 0.32843 0.18034 / 0.5)').toHex(); // '#ff000080'\n```\n\nThe plugin also exports standalone gamut utilities and low-level channel functions. `inGamutRec2020` and the channel helpers need no `extend()`. Gamut mapping is available as `Colordx.toGamutRec2020` after `extend([rec2020])`:\n\n```ts\nimport { Colordx, extend } from '@colordx/core';\nimport rec2020, { inGamutRec2020, linearToRec2020Channels, oklchToRec2020Channels } from '@colordx/core/plugins/rec2020';\n\nextend([rec2020]);\n\ninGamutRec2020('oklch(0.5 0.4 180)');        // false — outside Rec.2020\nColordx.toGamutRec2020('oklch(0.5 0.4 180)'); // → Colordx at the Rec.2020 boundary\n\noklchToRec2020Channels(0.5, 0.2, 240); // [r, g, b] gamma-encoded Rec.2020, unclamped\n```\n\nObject parsing is also supported using the `colorSpace` discriminant:\n\n```ts\ncolordx({ r: 0.82346, g: 0.32843, b: 0.18034, alpha: 1, colorSpace: 'rec2020' }).toHex();\n```\n\n### a98rgb plugin\n\nAdds A98 (Adobe RGB 1998) color space support. A98 shares sRGB's red and blue primaries but a wider green primary, so it extends mainly into the greens/cyans. It is a CSS Color 4 predefined space and a long-standing photography/print working space.\n\n```ts\nimport a98rgb from '@colordx/core/plugins/a98rgb';\n\nextend([a98rgb]);\n\ncolordx('#ff0000').toA98(); // { r: 0.8586, g: 0, b: 0, alpha: 1, colorSpace: 'a98-rgb' }\ncolordx('#ff0000').toA98String(); // 'color(a98-rgb 0.8586 0 0)'\n\n// Parse A98 strings (alpha optional)\ncolordx('color(a98-rgb 0.8586 0 0)').toHex(); // '#ff0000'\ncolordx('color(a98-rgb 0.8586 0 0 / 0.5)').toHex(); // '#ff000080'\n```\n\nThe plugin also exports standalone gamut utilities and low-level channel functions. `inGamutA98` and the channel helpers need no `extend()`. Gamut mapping is available as `Colordx.toGamutA98` after `extend([a98rgb])`:\n\n```ts\nimport { Colordx, extend } from '@colordx/core';\nimport a98rgb, { inGamutA98, linearToA98Channels, oklchToA98Channels } from '@colordx/core/plugins/a98rgb';\n\nextend([a98rgb]);\n\ninGamutA98('oklch(0.7 0.25 150)');        // true — inside A98 but outside sRGB\nColordx.toGamutA98('oklch(0.5 0.4 180)'); // → Colordx at the A98 boundary\n\noklchToA98Channels(0.5, 0.2, 240); // [r, g, b] gamma-encoded A98, unclamped\n```\n\nObject parsing is also supported using the `colorSpace` discriminant:\n\n```ts\ncolordx({ r: 0.8586, g: 0, b: 0, alpha: 1, colorSpace: 'a98-rgb' }).toHex();\n```\n\n### prophoto plugin\n\nAdds ProPhoto (ROMM RGB) color space support. ProPhoto has an extremely wide gamut — wider than Rec.2020, covering most of the visible spectrum — and uses a D50 white point with a gamma-1.8 transfer curve. It is the standard working space for high-end RAW photo and print pipelines.\n\n```ts\nimport prophoto from '@colordx/core/plugins/prophoto';\n\nextend([prophoto]);\n\ncolordx('#ff0000').toProphoto(); // { r: 0.70225, g: 0.27572, b: 0.10355, alpha: 1, colorSpace: 'prophoto-rgb' }\ncolordx('#ff0000').toProphotoString(); // 'color(prophoto-rgb 0.70225 0.27572 0.10355)'\n\n// Parse ProPhoto strings (alpha optional)\ncolordx('color(prophoto-rgb 0.70225 0.27572 0.10355)').toHex(); // '#ff0000'\ncolordx('color(prophoto-rgb 0.70225 0.27572 0.10355 / 0.5)').toHex(); // '#ff000080'\n```\n\nThe plugin also exports standalone gamut utilities and low-level channel functions. `inGamutProphoto` and the channel helpers need no `extend()`. Gamut mapping is available as `Colordx.toGamutProphoto` after `extend([prophoto])`:\n\n```ts\nimport { Colordx, extend } from '@colordx/core';\nimport prophoto, { inGamutProphoto, linearToProphotoChannels, oklchToProphotoChannels } from '@colordx/core/plugins/prophoto';\n\nextend([prophoto]);\n\ninGamutProphoto('oklch(0.5 0.4 180)');       // false — outside even ProPhoto\nColordx.toGamutProphoto('oklch(0.5 0.4 180)'); // → Colordx at the ProPhoto boundary\n\noklchToProphotoChannels(0.5, 0.2, 240); // [r, g, b] gamma-encoded ProPhoto, unclamped\n```\n\nObject parsing is also supported using the `colorSpace` discriminant:\n\n```ts\ncolordx({ r: 0.70225, g: 0.27572, b: 0.10355, alpha: 1, colorSpace: 'prophoto-rgb' }).toHex();\n```\n\n### srgb-linear plugin\n\nAdds the CSS Color 4 `srgb-linear` space: sRGB with the transfer curve removed. Same primaries and gamut as sRGB, so `inGamutSrgb()` and `Colordx.toGamutSrgb()` already apply. Values outside `[0, 1]` are kept as-is and only clip on sRGB output.\n\n```ts\nimport srgbLinear from '@colordx/core/plugins/srgb-linear';\n\nextend([srgbLinear]);\n\ncolordx('#3b82f6').toSrgbLinear(); // { r: 0.04374, g: 0.22323, b: 0.92158, alpha: 1, colorSpace: 'srgb-linear' }\ncolordx('#3b82f6').toSrgbLinearString(); // 'color(srgb-linear 0.04374 0.22323 0.92158)'\ncolordx('#3b82f6').toSrgbLinearString(4); // 'color(srgb-linear 0.0437 0.2232 0.9216)'\n\n// Parse srgb-linear strings (alpha optional)\ncolordx('color(srgb-linear 1 0 0)').toHex(); // '#ff0000'\ncolordx('color(srgb-linear 100% none 0 / 0.5)').toHex(); // '#ff000080'\n\n// Out-of-gamut values survive until sRGB output\ncolordx('oklch(0.7 0.3 150)').toSrgbLinearString(); // 'color(srgb-linear -0.1728 0.59844 -0.00771)'\ninGamutSrgb('color(srgb-linear 1.2 0 0)'); // false\n```\n\nObject parsing is also supported using the `colorSpace` discriminant:\n\n```ts\ncolordx({ r: 0.5, g: 0, b: 0, colorSpace: 'srgb-linear' }).toHex(); // '#bc0000'\n```\n\nFor per-pixel work use the core channel helpers instead: `rgbToLinear()` and `oklchToLinear()` return the same linear channels without a `Colordx` instance.\n\n### a11y plugin\n\nWCAG 2.x contrast:\n\n```ts\nimport a11y from '@colordx/core/plugins/a11y';\n\nextend([a11y]);\n\ncolordx('#000').isReadable('#fff'); // true  — AA normal (ratio >= 4.5)\ncolordx('#000').isReadable('#fff', { level: 'AAA' }); // true  — AAA normal (ratio >= 7)\ncolordx('#000').isReadable('#fff', { size: 'large' }); // true  — AA large (ratio >= 3)\ncolordx('#000').readableScore('#fff'); // 'AAA'\ncolordx('#e60000').readableScore('#ffff47'); // 'AA'\ncolordx('#949494').readableScore('#fff'); // 'AA large'\ncolordx('#aaa').readableScore('#fff'); // 'fail'\ncolordx('#777').minReadable('#fff'); // fixContrast at 4.5, or the input if nothing passes\n```\n\n`fixContrast` finds the nearest color that passes a gate. It keeps hue, moves OKLCH lightness, lets the gamut map reduce chroma only when it must, and returns `null` when no color with that hue passes. A darker fg stays darker (APCA sign is kept) unless nothing on that side passes.\n\n```ts\ncolordx('#3b82f6').fixContrast('#fff'); // #2c72e5 — WCAG 4.5 by default\ncolordx('#3b82f6').fixContrast('#fff', { apca: 75 }); // APCA only, |Lc| >= 75\ncolordx('#3b82f6').fixContrast('#fff', { wcag: 4.5, apca: 75 }); // #2168da — both\ncolordx('#999').fixContrast('#777', { wcag: 7 }); // null — no grey reaches 7:1 on #777\ncolordx('oklch(0.9 0.3 145)').fixContrast('#fff', { space: 'p3' }); // fix stays inside Display-P3\n```\n\nNumbers are rounded for display only (`contrast` to 2 decimals, `apcaContrast` to 1). Every `isReadable*` / `readableScore` gate uses the unrounded value, so a true 4.496:1 fails AA even though `contrast()` shows 4.5. Pass a precision to see more digits:\n\n```ts\ncolordx('#d200d2').contrast('#fff'); // 4.5\ncolordx('#d200d2').contrast('#fff', 4); // 4.4959\ncolordx('#d200d2').isReadable('#fff'); // false\n```\n\nA translucent fg is composited over the bg first. To check a stack (fg over a translucent surface over the page), flatten it bottom up with `over()`:\n\n```ts\nconst surface = colordx('rgba(255, 255, 255, 0.2)').over('#000');\ncolordx('rgba(255, 255, 255, 0.6)').over(surface).contrast('#000');\n```\n\nColors outside sRGB are gamut-mapped (not clipped) before the check. WCAG always runs on the sRGB-mapped color; APCA can run on the Display-P3-mapped color with its own coefficients via `{ space: 'p3' }`.\n\nAPCA (Accessible Perceptual Contrast Algorithm) — the projected replacement for WCAG 2.x in WCAG 3.0:\n\n```ts\n// Returns a signed Lc value: positive = dark text on light bg, negative = light text on dark bg\ncolordx('#000').apcaContrast('#fff'); //  106.0\ncolordx('#fff').apcaContrast('#000'); // -107.9\ncolordx('#202122').apcaContrast('#cf674a'); //  37.2  ← dark text on orange\ncolordx('#ffffff').apcaContrast('#cf674a'); // -69.5  ← white text on orange\n\n// Checks readability using |Lc| thresholds: >= 75 for normal text, >= 60 for large text/headings\ncolordx('#000').isReadableApca('#fff'); // true\ncolordx('#777').isReadableApca('#fff'); // false\ncolordx('#777').isReadableApca('#fff', { size: 'large' }); // true\n\n// Options: precision (default 1) and space ('srgb' | 'p3', default 'srgb')\ncolordx('#9900ff').apcaContrast('#fff', { precision: 3 }); // 74.956\ncolordx('oklch(0.8 0.3 145)').apcaContrast('#000', { space: 'p3' }); // -73.3 (P3-mapped), vs -74.8 in sRGB\ncolordx('#777').isReadableApca('#fff', { space: 'p3' }); // false\n```\n\nAPCA is better suited than WCAG 2.x for dark color pairs and more accurately reflects human perception. See [Introduction to APCA](https://git.apcacontrast.com/documentation/APCAeasyIntro) for background.\n\n### cvd plugin\n\nSimulates colour vision deficiency. Machado 2009 (severity 1.0) for protanopia and deuteranopia, the same matrices Chrome and Firefox DevTools use; Brettel 1997 for tritanopia, where Machado is weak. Runs on linear sRGB; wide-gamut input is gamut-mapped first. Reference values are checked against DaltonLens in the test suite.\n\n```ts\nimport cvd from '@colordx/core/plugins/cvd';\n\nextend([cvd]);\n\ncolordx('#ff0000').simulate('protanopia'); // #6d5f00\ncolordx('#ff0000').simulate('deuteranopia'); // #a39000\ncolordx('#0000ff').simulate('tritanopia'); // #006087\n\n// Do two status colours collapse? Compare ΔE2000 before and after (lab plugin).\nconst [a, b] = [colordx('#ef4444'), colordx('#10b981')];\na.delta(b, 5); // 0.71465 — clearly distinct\na.simulate('deuteranopia').delta(b.simulate('deuteranopia'), 5); // ~0.14 — nearly the same colour\n```\n\n### mix plugin\n\nColor mixing helpers built on top of `.mix()`.\n\n```ts\nimport mix from '@colordx/core/plugins/mix';\n\nextend([mix]);\n\ncolordx('#ff0000').tints(5); // [#ff0000, #ff4040, #ff8080, #ffbfbf, #ffffff]\ncolordx('#ff0000').shades(3); // [#ff0000, #800000, #000000]\ncolordx('#ff0000').tones(3);  // [#ff0000, #c04040, #808080]\n\n// palette: N evenly-spaced stops toward any target (default: white)\ncolordx('#ff0000').palette(3, '#0000ff'); // [#ff0000, #800080, #0000ff]\n// A fractional count is floored; 0, a negative count or NaN give []; Infinity throws a RangeError.\n```\n\n`mix()` interpolates in **sRGB**, matching CSS `color-mix(in srgb, ...)` and how browsers composite layers. Like `color-mix()`, it keeps the exact result rather than rounding it to bytes, and a wide-gamut input stays wide-gamut. Use `mixOklab()` for perceptually uniform blending, or `mixLab()` (lab plugin) for CIE Lab. All three premultiply by alpha as `color-mix()` does, so a transparent color contributes no hue: `colordx('rgba(255,0,0,0)').mix('#0000ff').toRgbString()` is `'rgb(0 0 255 / 0.5)'`.\n\n```ts\ncolordx('#000000').mix('#ffffff').toHex();       // '#808080' — sRGB (CSS spec)\ncolordx('#000000').mixOklab('#ffffff').toHex();  // '#636363' — Oklab (perceptually uniform)\n\nimport lab from '@colordx/core/plugins/lab';\nextend([lab]);\ncolordx('#000000').mixLab('#ffffff').toHex();    // '#777777' — CIE Lab\n```\n\n`tints()`, `shades()`, `tones()` and `palette()` are built on `mix()`, so they blend in sRGB too.\n\n### harmonies plugin\n\nColor harmony generation using hue rotation. Every harmony includes a 0° entry, which is the input color itself — returned unchanged, so a wide-gamut input survives in its own harmony set.\n\n```ts\nimport harmonies from '@colordx/core/plugins/harmonies';\n\nextend([harmonies]);\n\ncolordx('#ff0000').harmonies();                              // complementary (default) — 2 colors\ncolordx('#ff0000').harmonies('complementary');               // [0°, 180°] — 2 colors\ncolordx('#ff0000').harmonies('analogous');                   // [−30°, 0°, 30°] — 3 colors\ncolordx('#ff0000').harmonies('split-complementary');         // [0°, 150°, 210°] — 3 colors\ncolordx('#ff0000').harmonies('triadic');                     // [0°, 120°, 240°] — 3 colors\ncolordx('#ff0000').harmonies('tetradic');                    // [0°, 90°, 180°, 270°] — 4 colors (square)\ncolordx('#ff0000').harmonies('rectangle');                   // [0°, 60°, 180°, 240°] — 4 colors\ncolordx('#ff0000').harmonies('double-split-complementary');  // [−30°, 0°, 30°, 150°, 210°] — 5 colors\n```\n\nAn unknown type throws a `RangeError` naming it.\n\n### names plugin\n\nCSS named color support (all 148 names from the CSS spec). `toName()` returns `undefined` for colors with no CSS name.\n\n```ts\nimport names from '@colordx/core/plugins/names';\n\nextend([names]);\n\ncolordx('red').toHex(); // '#ff0000'\ncolordx('rebeccapurple').toHex(); // '#663399'\ncolordx('#ff0000').toName(); // 'red'\ncolordx('#c06060').toName(); // undefined — no CSS name for this color\ncolordx('#c06060').toName({ closest: true }); // nearest named color by RGB distance\n```\n\n### minify plugin\n\nReturns the shortest valid CSS representation of a color. By default tries hex, RGB, and HSL and picks the shortest.\n\nA color outside sRGB (a wide-gamut `oklch()`, `oklab()`, `lab()`, `lch()` or `color()` input) has no hex, RGB, HSL or name form — each would clip it, while a wide-gamut display renders the original — so it minifies to its `oklch()` string instead, with leading zeros dropped: `oklch(0.5 0.2 240)` → `'oklch(.5 .2 240)'`.\n\n```ts\nimport minify from '@colordx/core/plugins/minify';\n\nextend([minify]);\n\ncolordx('#ff0000').minify(); // '#f00'\ncolordx('#ffffff').minify(); // '#fff'\ncolordx('#ff0000').minify({ name: true }); // 'red'  — requires names plugin\ncolordx({ r: 0, g: 0, b: 0, alpha: 0 }).minify({ transparent: true }); // 'transparent'\ncolordx({ r: 255, g: 0, b: 0, alpha: 0.5 }).minify({ alphaHex: true }); // '#ff000080'\n\n// Disable specific formats to exclude them from candidates:\ncolordx('#ff0000').minify({ hsl: false }); // skips HSL, picks from hex/RGB (a preference: see the half-byte note below)\n```\n\n<details>\n<summary>Rounding and wide-gamut edge cases</summary>\n\nThe `minify()` plugin preserves full HSL precision when building candidates, so minification is lossless — it only picks HSL when the string is genuinely shorter than hex/rgb. One exception: a color with a channel on an *inexact* half byte (`hsl(220, 80%, 50%)` has a green of 93.50000000000013) stays `hsl()` as written, even with `hsl: false`, because engines round such a channel either way — Chrome paints that color as `rgb(26 93 230)`, exact rounding gives `rgb(26 94 230)` — and hex, `rgb()` or a name would commit to one side. When no `hsl()` reproduces the channels exactly (most `hwb()` sources), they are printed as fractional legacy `rgb()` instead, the tie left for the engine. An exact tie (`rgb(50% 50% 50%)`, `hsl(270 100% 50%)`) comes from exact arithmetic, rounds up in every engine per WPT, and minifies to bytes as usual. Colors outside sRGB are never clipped to hex; they stay `oklch()`, or `color(srgb …)` when brighter than white or darker than black, since `oklch()` clamps its lightness at parse time. With every format option turned off, a visible alpha that hex would round to `00` falls back to `rgba()`.\n\n</details>\n\n## Channel functions\n\nPlain-number converters for per-pixel work (canvas renderers, pickers, gradients): no parsing, no `Colordx` object, no rounding.\n\n```ts\nimport { oklchToLinear, oklchToRgbChannels } from '@colordx/core';\n\noklchToRgbChannels(0.5, 0.2, 240); // [-0.29354, 0.41025, 0.78055] — gamma-encoded sRGB, unclamped\n// Out-of-gamut channels leave [0, 1] (this one is outside sRGB) — callers clamp before byte encoding\n\nconst linear = oklchToLinear(0.5, 0.2, 240); // unclamped linear sRGB — also a free sRGB gamut check\n\n// Non-OKLCH inputs → linear sRGB (same output scale and gamut-check behavior as oklchToLinear).\n// Use these when you already have RGB/Lab/LCH values and want linear pixels without round-tripping through OKLCH.\nimport {\n  labToLinearAndSrgb,\n  labToLinearSrgb,\n  labToRgbChannels,\n  lchToLinearAndSrgb,\n  lchToLinearSrgb,\n  lchToRgbChannels,\n  rgbToLinear,\n} from '@colordx/core';\n\nrgbToLinear(1, 0, 0);          // [1, 0, 0]           — 0–1 gamma sRGB in\nlabToLinearSrgb(54.29, 80.8, 69.89); // Lab D50 → linear sRGB (via XYZ D50)\nlchToLinearSrgb(54.29, 106.84, 40.86); // LCH D50 → Lab → linear sRGB\n\n// Gamma-encoded sRGB in one call:\nlabToRgbChannels(54.29, 80.8, 69.89); // → [r, g, b] gamma sRGB in [0, 1]\nlchToRgbChannels(54.29, 106.84, 40.86);\n\n// Both linear (for gamut check) and gamma (for display) in a single pass:\nconst [lin, srgb] = labToLinearAndSrgb(54.29, 80.8, 69.89); // or lchToLinearAndSrgb\n\n// Hex/RGB input? Parse once, then divide by 255:\nconst { r, g, b } = colordx('#ff0000').toRgb();\nrgbToLinear(r / 255, g / 255, b / 255); // [1, 0, 0]\n\n// P3/Rec.2020 channel functions live in their plugins:\nimport { labToP3Channels, lchToP3Channels, linearToP3Channels, oklchToP3Channels } from '@colordx/core/plugins/p3';\nimport {\n  labToRec2020Channels,\n  lchToRec2020Channels,\n  linearToRec2020Channels,\n  oklchToRec2020Channels,\n} from '@colordx/core/plugins/rec2020';\n\noklchToP3Channels(0.5, 0.2, 240);      // [r, g, b] gamma-encoded Display-P3, unclamped\noklchToRec2020Channels(0.5, 0.2, 240); // [r, g, b] gamma-encoded Rec.2020, unclamped (2.4 gamma)\n\n// CIE Lab/LCH → P3 / Rec.2020 (hot path for LCH renderers without OKLCH detour):\nlabToP3Channels(54.29, 80.8, 69.89);      // [r, g, b] gamma P3\nlchToP3Channels(54.29, 106.84, 40.86);\nlabToRec2020Channels(54.29, 80.8, 69.89); // [r, g, b] gamma Rec.2020\nlchToRec2020Channels(54.29, 106.84, 40.86);\n\n// Split-step API: compute the shared expensive OKLCH→linear sRGB step once,\n// then apply cheap per-space steps to avoid repeating 3× Math.cbrt + OKLab matrix.\nlinearToP3Channels(...linear);      // linear sRGB → gamma-encoded P3\nlinearToRec2020Channels(...linear); // linear sRGB → gamma-encoded Rec.2020 (2.4 gamma)\n\n// sRGB ↔ HSL / HSV on the same scale toHsl() / toHsv() report: h in degrees, s and l/v in 0–100.\n// RGB is 0–1 gamma sRGB, like rgbToLinear. This is the per-pixel path for pickers, hue wheels\n// and vectorscopes — no parsing, no object, no rounding.\nimport { hslToRgbChannels, rgbToHslChannels } from '@colordx/core';\nimport { hsvToRgbChannels, rgbToHsvChannels } from '@colordx/core/plugins/hsv';\n\nrgbToHslChannels(1, 0, 0);       // [0, 100, 50]\nrgbToHsvChannels(0, 0, 1);       // [240, 100, 100]\nhslToRgbChannels(120, 100, 50);  // [0, 1, 0]\nhsvToRgbChannels(-30, 50, 50);   // hue wraps: same as hsvToRgbChannels(330, 50, 50)\n// Greys report h = 0, s = 0 (same ACHROMATIC_EPS threshold as toHsl()). Nothing is clipped:\n// HSL/HSV live on the sRGB cube, so clip a wide-gamut color first — for bytes, pass r/255, g/255, b/255.\n```\n\n### Zero-allocation variants\n\nEvery channel function has an `*Into` sibling that writes into a caller-provided `Float64Array | number[]` instead of allocating a new tuple, for loops that run once per pixel. Output is bit-for-bit identical to the allocating version.\n\n```ts\nimport {\n  oklchToLinearInto,\n  oklchToRgbChannelsInto,\n  oklchToLinearAndSrgbInto,\n} from '@colordx/core';\nimport { linearToP3ChannelsInto, oklchToP3ChannelsInto } from '@colordx/core/plugins/p3';\nimport { linearToRec2020ChannelsInto, oklchToRec2020ChannelsInto } from '@colordx/core/plugins/rec2020';\n\n// Pixel-renderer pattern: allocate one buffer, reuse for every pixel.\nconst buf = new Float64Array(3);\nfor (let y = 0; y < height; y++) {\n  for (let x = 0; x < width; x++) {\n    const [l, c, h] = getOklch(x, y);\n    oklchToP3ChannelsInto(buf, l, c, h);\n    imageData[i++] = Math.floor(buf[0] * 255);\n    imageData[i++] = Math.floor(buf[1] * 255);\n    imageData[i++] = Math.floor(buf[2] * 255);\n    imageData[i++] = 255;\n  }\n}\n```\n\n<details>\n<summary>Full <code>*Into</code> list (all tree-shakable)</summary>\n\n```ts\n// from '@colordx/core' — OKLCH → linear / sRGB\noklchToLinearInto(out, l, c, h);           // → [lr, lg, lb] linear sRGB\noklchToRgbChannelsInto(out, l, c, h);      // → [r, g, b] gamma-encoded sRGB\noklchToLinearAndSrgbInto(linOut, srgbOut, l, c, h); // both at once (distinct buffers)\n\n// from '@colordx/core' — non-OKLCH inputs → linear / gamma sRGB (complements oklchToLinear)\nrgbToLinearInto(out, r, g, b);             // 0–1 gamma sRGB → linear sRGB\nlabToLinearSrgbInto(out, l, a, b);         // CIE Lab (D50) → linear sRGB (via XYZ D50)\nlabToRgbChannelsInto(out, l, a, b);        // CIE Lab (D50) → gamma sRGB\nlabToLinearAndSrgbInto(linOut, srgbOut, l, a, b); // both (distinct buffers)\nlchToLinearSrgbInto(out, l, c, h);         // CIE LCH (D50) → linear sRGB\nlchToRgbChannelsInto(out, l, c, h);        // CIE LCH (D50) → gamma sRGB\nlchToLinearAndSrgbInto(linOut, srgbOut, l, c, h);\n\n// from '@colordx/core' — sRGB ↔ HSL (h degrees, s/l 0–100; RGB 0–1)\nrgbToHslChannelsInto(out, r, g, b);        // → [h, s, l]\nhslToRgbChannelsInto(out, h, s, l);        // → [r, g, b] gamma sRGB\n\n// from '@colordx/core/plugins/hsv' — sRGB ↔ HSV (h degrees, s/v 0–100; RGB 0–1)\nrgbToHsvChannelsInto(out, r, g, b);        // → [h, s, v]\nhsvToRgbChannelsInto(out, h, s, v);        // → [r, g, b] gamma sRGB\n\n// from '@colordx/core/plugins/p3'\nlinearToP3ChannelsInto(out, lr, lg, lb);\noklchToP3ChannelsInto(out, l, c, h);\nlabToP3ChannelsInto(out, l, a, b);\nlchToP3ChannelsInto(out, l, c, h);\n\n// from '@colordx/core/plugins/rec2020'\nlinearToRec2020ChannelsInto(out, lr, lg, lb);\noklchToRec2020ChannelsInto(out, l, c, h);\nlabToRec2020ChannelsInto(out, l, a, b);\nlchToRec2020ChannelsInto(out, l, c, h);\n```\n\n</details>\n\nGuidance:\n- Use `Float64Array(3)` for the buffer when you can — it's the convention and keeps the V8 call site monomorphic. `number[]` also works.\n- One buffer per loop is plenty; don't allocate per iteration.\n- `linOut` and `srgbOut` in `oklchToLinearAndSrgbInto` **must be distinct buffers** (the function writes to both).\n- If you're outside a hot loop, the regular allocating versions are more ergonomic — reach for `*Into` only when you've profiled and GC is the bottleneck.\n\n## Functional API\n\n`@colordx/core/fn` exports the parsers and converters behind `colordx()` as plain functions. Nothing is shared with the `Colordx` class, so a bundle only carries what it imports — parsing a hex string and printing it back is about 0.7 KB gzipped.\n\n```ts\nimport { parse, parseHex, rgbToHex, rgbToOklch } from '@colordx/core/fn';\n\nparse('oklch(0.6279 0.2577 29.23)'); // { r, g, b, alpha } or null — every format colordx() accepts, plugins included\nparseHex('#ff0000');                 // { r: 255, g: 0, b: 0, alpha: 1 }\nrgbToHex({ r: 255, g: 0, b: 0, alpha: 0.5 }); // '#ff000080'\nrgbToOklch(parseHex('#ff0000')!);    // { l: 0.6279…, c: 0.2576…, h: 29.23…, alpha: 1 } — unrounded\n```\n\n`RgbColor` here is the library's storage form: `r`, `g`, `b` on the 0–255 scale, unrounded and unclamped, so a wide-gamut color keeps its out-of-range channels.\n\nTo accept only some formats, compose the single-format parsers instead of calling `parse()`. Order them by how often each format shows up, and keep `parseNameString` last: every other parser rejects a foreign input on its first character or key, while the name lookup lowercases the string first.\n\n```ts\nimport { parseHex, parseHsvObject, parseNameString, parseRgbObject } from '@colordx/core/fn';\n\nconst parsers = [parseHex, parseRgbObject, parseHsvObject, parseNameString];\nconst parseColor = (input: unknown) => {\n  for (const p of parsers) {\n    const rgb = p(input);\n    if (rgb) return rgb;\n  }\n  return null;\n};\n```\n\nAvailable: `parse`, `parseHex`, `parseRgbString`, `parseRgbObject`, `parseSrgbColorString`, `parseHslString`, `parseHslObject`, `parseHsvString`, `parseHsvObject`, `parseHwbString`, `parseHwbObject`, `parseOklabString`, `parseOklabObject`, `parseOklchString`, `parseOklchObject`, `parseNameString`, `NAMES`, `rgbToHex`, `rgbToHex8`, `rgbToHsl` / `hslToRgb`, `rgbToHsv` / `hsvToRgb`, `rgbToHwb` / `hwbToRgb`, `rgbToOklab` / `oklabToRgb`, `rgbToOklch` / `oklchToRgb`, `rgbToOkhsl` / `okhslToRgb`, `rgbToOkhsv` / `okhsvToRgb`, `parseOkhslString`, `parseOkhslObject`, `parseOkhsvString`, `parseOkhsvObject`.\n\n## Migrating from tinycolor2\n\n`@colordx/core/tinycolor` is a drop-in replacement for [tinycolor2](https://github.com/bgrins/TinyColor). Swap the import (or the `require`) and keep the code:\n\n```ts\nimport tinycolor from '@colordx/core/tinycolor'; // was: from 'tinycolor2'\n\ntinycolor('#f00').lighten(20).toHexString();     // '#ff6666'\ntinycolor('rgb 255 0 0').toHslString();          // 'hsl(0, 100%, 50%)'\ntinycolor.mix('#f00', '#00f', 50).toHexString(); // '#800080'\ntinycolor.isReadable('#777', '#fff');            // false\ntinycolor('#f00').toColordx().toOklchString();   // 'oklch(0.62796 0.25768 29.23388)'\n```\n\nSame API, same input quirks (`f00`, `rgb 255 0 0`, `{ h: 0, s: 1, l: 0.5 }` read as fractions), same output strings, mutable instances (`lighten()` changes the instance and returns it). Types come along: `tinycolor.Instance`, `tinycolor.ColorInput`.\n\nWhat is different:\n\n- **Precision.** tinycolor2 truncates percentages to two decimals when it re-parses HSL between operations. colordx keeps full precision, so `lighten()`, `darken()`, `saturate()`, `desaturate()`, `spin()` and the harmony helpers can differ from tinycolor2 by 1/255 on a channel. The test suite checks every operation against tinycolor2 within that bound.\n- **`toName()`** returns `'rebeccapurple'` for `#663399`; tinycolor2 returns `false` there (a lookup bug).\n- **`tinycolor.names`** holds full hex (`ff0000`); tinycolor2 holds shortened hex (`f00`).\n- **CSS angle units** on a hue (`hsl(0.5turn 100% 50%)`, `200grad`, `3.14rad`) convert to degrees. tinycolor2 rejects them as invalid.\n- **`analogous()` / `monochromatic()`** always terminate. tinycolor2 loops forever on a negative or fractional count ([#280](https://github.com/bgrins/TinyColor/issues/280)); here it is floored, with anything below 1 treated as 1.\n- **`.toColordx()`** is new: the immutable `Colordx` underneath, for oklch, gamut mapping and plugins. `tinycolor()` reads a `Colordx` back, as its sRGB clip.\n\n## Performance\n\nApple M5 Pro, Node 24, using [mitata](https://github.com/evanwashere/mitata). Operations per\nsecond — higher is better. Versions: colord 2.10.0, culori 4.0.2, chroma-js 3.2.0, color 5.0.3,\ntinycolor2 1.6.0, @texel/color 1.1.11.\n\n| Benchmark | **colordx** | @texel/color | colord | culori | chroma-js | color | tinycolor2 |\n|---|---|---|---|---|---|---|---|\n| Parse HEX → toHex | **38M** | 8.0M | 7.5M | 7.1M | 3.7M | 1.6M | 2.9M |\n| Parse HEX → toHsl | **35M** | — | 29M | 7.7M | 3.8M | 3.4M | 2.8M |\n| Parse RGB object → toHex | **50M** | — | 35M | 49M | 5.2M | 1.6M | 5.8M |\n| Parse rgb() string → toHex | **12M** | — | 7.4M | 3.1M | 227K | 1.5M | 3.0M |\n| Parse hsl() string → toHex | **11M** | — | 4.9M | 3.1M | 219K | 1.4M | 2.0M |\n| Parse named color → toHex | **14M** | — | 4.5M | 3.9M | 4.5M | 1.3M | 2.6M |\n| Parse HEX → lighten → toHex | **18M** | — | 13M | 5.2M | 1.9M | 1.2M | 1.1M |\n| Mix two colors | **19M** | 6.0M | 2.5M | 1.3M | 1.3M | 678K | 1.3M |\n| WCAG contrast ratio | **21M** | — | 3.6M | 3.3M | 2.0M | — | 1.5M |\n| Parse HEX → toOklch | **14M** | 6.6M | — | 4.7M | 1.3M | 2.6M | — |\n| inGamutP3 | **8.9M** | 3.9M | — | 1.5M | — | — | — |\n| inGamutRec2020 | **8.7M** | 3.9M | — | 1.5M | — | — | — |\n| CIEDE2000 delta | **6.0M** | — | — | 2.0M | 1.3M | — | — |\n| OKLCH string → HEX | **6.3M** | 2.8M | — | 1.7M | 191K | — | — |\n| Gamut map → sRGB | **1.7M** | — | — | 509K | — | — | — |\n\nIn the RGB object row culori gets its own `{ mode, r, g, b }` format, so it skips parsing.\n\nMean of two runs. Run `pnpm bench` to check.\n\n## Roadmap\n\n### CSS Color 4/5 completeness\n\n- **`color-mix()`** — parse and evaluate `color-mix(in oklch, red 30%, blue)` strings, with support for all interpolation spaces and polar hue methods (`shorter`, `longer`, `increasing`, `decreasing`)\n- **Relative color syntax** — `oklch(from red l c h)` and channel arithmetic like `oklch(from red l calc(c + 0.1) h)`\n\n## Ecosystem\n\n- [**@colordx/cli**](https://github.com/dkryaklin/colordx-a11y) — color accessibility on the command line, and a skill for coding agents: check a pair, audit a token file, build a scale, solve a theme. WCAG 2.2 and APCA gates, one JSON record per pair, a fix on every fail.\n- [**@colordx/gpu**](https://github.com/dkryaklin/colordx-gpu) — colordx's color math on the GPU: conversions and gamut tests as generated GLSL, parity-tested against this library. For per-pixel workloads — picker charts, gamut visualizations, gradients — where you convert millions of colors per frame instead of one at a time.\n\n## Sponsors\n\nSupported by [Ruslo.app](https://ruslo.app).\n\n## License\n\nMIT\n","publish_time":1790184606375,"_cnpm_publish_time":1790184606375,"dist-tags":{"latest":"7.3.0"}}