@rafters/color-utils 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/gamut.ts +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rafters/color-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "OKLCH color manipulation utilities for Rafters design system",
|
|
5
5
|
"homepage": "https://rafters.studio",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"apca-w3": "^0.1.9",
|
|
26
26
|
"colorjs.io": "^0.5.2",
|
|
27
27
|
"zod": "^4.1.12",
|
|
28
|
-
"@rafters/shared": "0.
|
|
28
|
+
"@rafters/shared": "0.4.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "24.10.0",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"test": "vitest run",
|
|
39
|
+
"test:unit": "vitest run",
|
|
39
40
|
"test:watch": "vitest",
|
|
40
41
|
"test:coverage": "vitest run --coverage",
|
|
41
42
|
"typecheck": "tsc --noEmit",
|
package/src/gamut.ts
CHANGED
|
@@ -80,6 +80,19 @@ export function clampColor(color: OKLCH): OKLCH {
|
|
|
80
80
|
const DEFAULT_STEPS = 101;
|
|
81
81
|
const TOLERANCE = 0.001;
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Largest chroma at this lightness and hue that colorjs.io still calls in
|
|
85
|
+
* gamut, by bisection over `inGamut`.
|
|
86
|
+
*
|
|
87
|
+
* The bisection stays rather than deferring to `toGamut`, whose 0.5.2 options
|
|
88
|
+
* do include a coordinate-reduction method (`{ method: 'oklch.c' }`) that
|
|
89
|
+
* looks like it would answer this directly. It does not: `toGamut` returns a
|
|
90
|
+
* color CLIPPED into the target space, and clipping moves lightness too, so
|
|
91
|
+
* reading chroma back off the result overshoots the boundary AT THIS
|
|
92
|
+
* LIGHTNESS -- 0.0284 against the true 0.0094 at h=160, l=0.04, and 0.0337
|
|
93
|
+
* against 0.0227 at h=145, l=0.05. `inGamut` is the predicate this function
|
|
94
|
+
* actually needs, and bisecting it is the only way to ask where it flips.
|
|
95
|
+
*/
|
|
83
96
|
function findMaxChroma(l: number, h: number, gamutSpace: string): number {
|
|
84
97
|
let lo = 0;
|
|
85
98
|
let hi = MAX_CHROMA;
|