@texel/color
Advanced tools
+1
-1
| { | ||
| "name": "@texel/color", | ||
| "version": "1.1.2", | ||
| "version": "1.1.3", | ||
| "description": "a minimal and modern color library", | ||
@@ -5,0 +5,0 @@ "type": "module", |
+1
-1
@@ -88,3 +88,3 @@ # @texel/color | ||
| Performs fast gamut mapping in OKLCH as [described by Björn Ottoson](https://bottosson.github.io/posts/gamutclipping/) (2021). This takes an input `[l,c,h]` coords in OKLCH space, and ensures the final result will lie within the specified color `gamut` (default `sRGBGamut`). You can further specify a different target space (which default's to the gamut's space), for example to get a linear-light sRGB and avoid the transfer function, or to keep the result in OKLCH: | ||
| Performs fast gamut mapping in OKLCH as [described by Björn Ottosson](https://bottosson.github.io/posts/gamutclipping/) (2021). This takes an input `[l,c,h]` coords in OKLCH space, and ensures the final result will lie within the specified color `gamut` (default `sRGBGamut`). You can further specify a different target space (which default's to the gamut's space), for example to get a linear-light sRGB and avoid the transfer function, or to keep the result in OKLCH: | ||
@@ -91,0 +91,0 @@ ```js |
+4
-2
@@ -185,4 +185,5 @@ import { | ||
| if ((l1 - l0) * cusp[1] - (cusp[0] - l0) * c1 <= 0.0) { | ||
| const denom = (c1 * cusp[0] + cusp[1] * (l0 - l1)); | ||
| // Lower half | ||
| t = (cusp[1] * l0) / (c1 * cusp[0] + cusp[1] * (l0 - l1)); | ||
| t = denom === 0 ? 0 : (cusp[1] * l0) / denom; | ||
| } else { | ||
@@ -192,3 +193,4 @@ // Upper half | ||
| // First intersect with triangle | ||
| t = (cusp[1] * (l0 - 1.0)) / (c1 * (cusp[0] - 1.0) + cusp[1] * (l0 - l1)); | ||
| const denom = (c1 * (cusp[0] - 1.0) + cusp[1] * (l0 - l1)); | ||
| t = denom === 0 ? 0 : (cusp[1] * (l0 - 1.0)) / denom; | ||
@@ -195,0 +197,0 @@ // Then one step Halley's method |
+31
-1
@@ -47,2 +47,3 @@ import test from "tape"; | ||
| parse, | ||
| MapToL, | ||
| } from "../src/index.js"; | ||
@@ -286,3 +287,2 @@ | ||
| test("should deserialize color string information", async (t) => { | ||
| t.deepEqual(deserialize("rgb(0, 128, 255)"), { | ||
@@ -312,2 +312,6 @@ coords: [0, 128 / 0xff, 255 / 0xff], | ||
| }); | ||
| t.deepEqual(deserialize("rgb(0 128 255 / 1e-2)"), { | ||
| coords: [0, 128 / 0xff, 255 / 0xff, 1e-2], | ||
| id: "srgb", | ||
| }); | ||
| t.deepEqual(deserialize("rgb(0 128 255 / 50%)"), { | ||
@@ -349,2 +353,6 @@ coords: [0, 128 / 0xff, 255 / 0xff, 0.5], | ||
| }); | ||
| t.deepEqual(deserialize("color(srgb-linear 0 1e-2 1)"), { | ||
| id: "srgb-linear", | ||
| coords: [0, 1e-2, 1], | ||
| }); | ||
| t.deepEqual(deserialize("color(srgb-linear 0 0.5 1/0.25)"), { | ||
@@ -450,2 +458,24 @@ id: "srgb-linear", | ||
| ); | ||
| t.deepEqual( | ||
| convert([1, 0, 0], OKLCH, OKLab, undefined), | ||
| [1, 0, 0], | ||
| "handles [1,0,0] OKLCH to OKLab gamut map" | ||
| ); | ||
| t.deepEqual( | ||
| arrayAlmostEqual(convert([1, 0, 0], OKLCH, sRGBLinear), [1, 1, 1]), | ||
| true, | ||
| "handles [1,1,1] OKLCH to sRGBLinear" | ||
| ); | ||
| t.deepEqual( | ||
| gamutMapOKLCH([1, 0, 0], sRGBGamut, OKLCH, undefined, MapToL), | ||
| [1, 0, 0], | ||
| "handles [1,0,0] OKLCH to sRGB gamut map" | ||
| ); | ||
| t.deepEqual( | ||
| gamutMapOKLCH([0, 0, 0], sRGBGamut, OKLCH, undefined, MapToL), | ||
| [0, 0, 0], | ||
| "handles [0,0,0] OKLCH to sRGB gamut map" | ||
| ); | ||
| }); | ||
@@ -452,0 +482,0 @@ |
177960
0.51%3826
0.82%