@solid-primitives/utils 7.0.0-next.1 → 7.0.0-next.2

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.
@@ -1,278 +1,251 @@
1
- /*
2
- * Portions of this file incorporate color science from the following sources:
3
- *
4
- * OKLab/OKLCH color space by Björn Ottosson.
5
- * MIT License, Copyright Björn Ottosson.
6
- * https://bottosson.github.io/posts/oklab/
7
- *
8
- * WCAG 2.1 relative luminance and contrast ratio formulas.
9
- * W3C Web Content Accessibility Guidelines 2.1, Copyright W3C.
10
- * https://www.w3.org/TR/WCAG21/#contrast-minimum
11
- */
1
+ /* @ts-self-types="./manipulation.d.ts" */
12
2
  import { clamp } from "../index.js";
13
3
  import { colorToOKLCH, normalizeHue, parseColor } from "./helpers.js";
14
- // ─── Safe parsing ─────────────────────────────────────────────────────────────
4
+ //#region src/colors/manipulation.ts
15
5
  /**
16
- * Like {@link parseColor} but returns `undefined` instead of throwing for invalid input.
17
- *
18
- * @example
19
- * ```ts
20
- * tryParseColor("#3264C8") // Color
21
- * tryParseColor("nope") // undefined
22
- * ```
23
- */
24
- export function tryParseColor(value) {
25
- try {
26
- return parseColor(value);
27
- }
28
- catch {
29
- return undefined;
30
- }
6
+ * Like {@link parseColor} but returns `undefined` instead of throwing for invalid input.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * tryParseColor("#3264C8") // Color
11
+ * tryParseColor("nope") // undefined
12
+ * ```
13
+ */
14
+ function tryParseColor(value) {
15
+ try {
16
+ return parseColor(value);
17
+ } catch {
18
+ return;
19
+ }
31
20
  }
32
21
  /**
33
- * Returns `true` if `value` is a parseable color string.
34
- *
35
- * @example
36
- * ```ts
37
- * isValidColor("#3264C8") // true
38
- * isValidColor("nope") // false
39
- * ```
40
- */
41
- export function isValidColor(value) {
42
- return tryParseColor(value) !== undefined;
22
+ * Returns `true` if `value` is a parseable color string.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * isValidColor("#3264C8") // true
27
+ * isValidColor("nope") // false
28
+ * ```
29
+ */
30
+ function isValidColor(value) {
31
+ return tryParseColor(value) !== void 0;
43
32
  }
44
33
  /**
45
- * Detects the format of a color string without parsing it.
46
- * Returns `undefined` for strings that do not match any known format.
47
- *
48
- * The returned format reflects the **syntax** of the string (e.g. `"rgb"` for
49
- * `rgb(...)` even if an alpha channel is present via slash notation).
50
- *
51
- * @example
52
- * ```ts
53
- * detectColorFormat("#3264C8") // "hex"
54
- * detectColorFormat("#3264C8FF") // "hexa"
55
- * detectColorFormat("rgb(50, 100, 200)") // "rgb"
56
- * detectColorFormat("hsla(220, 60%, 49%, 0.5)") // "hsla"
57
- * detectColorFormat("nope") // undefined
58
- * ```
59
- */
60
- export function detectColorFormat(value) {
61
- const s = value.trim();
62
- if (/^#[\da-f]+$/i.test(s)) {
63
- if (s.length === 4 || s.length === 7)
64
- return "hex";
65
- if (s.length === 5 || s.length === 9)
66
- return "hexa";
67
- }
68
- if (/^rgba?\(/i.test(s))
69
- return /^rgba\(/i.test(s) ? "rgba" : "rgb";
70
- if (/^hsla?\(/i.test(s))
71
- return /^hsla\(/i.test(s) ? "hsla" : "hsl";
72
- if (/^hsba?\(/i.test(s))
73
- return /^hsba\(/i.test(s) ? "hsba" : "hsb";
74
- return undefined;
34
+ * Detects the format of a color string without parsing it.
35
+ * Returns `undefined` for strings that do not match any known format.
36
+ *
37
+ * The returned format reflects the **syntax** of the string (e.g. `"rgb"` for
38
+ * `rgb(...)` even if an alpha channel is present via slash notation).
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * detectColorFormat("#3264C8") // "hex"
43
+ * detectColorFormat("#3264C8FF") // "hexa"
44
+ * detectColorFormat("rgb(50, 100, 200)") // "rgb"
45
+ * detectColorFormat("hsla(220, 60%, 49%, 0.5)") // "hsla"
46
+ * detectColorFormat("nope") // undefined
47
+ * ```
48
+ */
49
+ function detectColorFormat(value) {
50
+ const s = value.trim();
51
+ if (/^#[\da-f]+$/i.test(s)) {
52
+ if (s.length === 4 || s.length === 7) return "hex";
53
+ if (s.length === 5 || s.length === 9) return "hexa";
54
+ }
55
+ if (/^rgba?\(/i.test(s)) return /^rgba\(/i.test(s) ? "rgba" : "rgb";
56
+ if (/^hsla?\(/i.test(s)) return /^hsla\(/i.test(s) ? "hsla" : "hsl";
57
+ if (/^hsba?\(/i.test(s)) return /^hsba\(/i.test(s) ? "hsba" : "hsb";
75
58
  }
76
- // ─── Manipulation ─────────────────────────────────────────────────────────────
77
59
  /**
78
- * Returns a new color with lightness increased by `amount` (0–1 ratio = percentage points).
79
- * Operates in HSL space; the returned color is in HSL.
80
- *
81
- * @example
82
- * ```ts
83
- * lighten(parseColor("hsl(220, 60%, 50%)"), 0.1).getChannelValue("lightness") // 60
84
- * ```
85
- */
86
- export function lighten(color, amount) {
87
- const hsl = color.toFormat("hsl");
88
- return hsl.withChannelValue("lightness", clamp(hsl.getChannelValue("lightness") + amount * 100, 0, 100));
60
+ * Returns a new color with lightness increased by `amount` (0–1 ratio = percentage points).
61
+ * Operates in HSL space; the returned color is in HSL.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * lighten(parseColor("hsl(220, 60%, 50%)"), 0.1).getChannelValue("lightness") // 60
66
+ * ```
67
+ */
68
+ function lighten(color, amount) {
69
+ const hsl = color.toFormat("hsl");
70
+ return hsl.withChannelValue("lightness", clamp(hsl.getChannelValue("lightness") + amount * 100, 0, 100));
89
71
  }
90
72
  /**
91
- * Returns a new color with lightness decreased by `amount` (0–1 ratio = percentage points).
92
- * Operates in HSL space; the returned color is in HSL.
93
- */
94
- export function darken(color, amount) {
95
- return lighten(color, -amount);
73
+ * Returns a new color with lightness decreased by `amount` (0–1 ratio = percentage points).
74
+ * Operates in HSL space; the returned color is in HSL.
75
+ */
76
+ function darken(color, amount) {
77
+ return lighten(color, -amount);
96
78
  }
97
79
  /**
98
- * Returns a new color with saturation increased by `amount` (0–1 ratio = percentage points).
99
- * Operates in HSL space; the returned color is in HSL.
100
- */
101
- export function saturate(color, amount) {
102
- const hsl = color.toFormat("hsl");
103
- return hsl.withChannelValue("saturation", clamp(hsl.getChannelValue("saturation") + amount * 100, 0, 100));
80
+ * Returns a new color with saturation increased by `amount` (0–1 ratio = percentage points).
81
+ * Operates in HSL space; the returned color is in HSL.
82
+ */
83
+ function saturate(color, amount) {
84
+ const hsl = color.toFormat("hsl");
85
+ return hsl.withChannelValue("saturation", clamp(hsl.getChannelValue("saturation") + amount * 100, 0, 100));
104
86
  }
105
87
  /**
106
- * Returns a new color with saturation decreased by `amount` (0–1 ratio = percentage points).
107
- * Operates in HSL space; the returned color is in HSL.
108
- */
109
- export function desaturate(color, amount) {
110
- return saturate(color, -amount);
88
+ * Returns a new color with saturation decreased by `amount` (0–1 ratio = percentage points).
89
+ * Operates in HSL space; the returned color is in HSL.
90
+ */
91
+ function desaturate(color, amount) {
92
+ return saturate(color, -amount);
111
93
  }
112
94
  /**
113
- * Returns the complementary color (hue rotated 180°), preserving saturation, lightness, and alpha.
114
- * The returned color is in HSL.
115
- *
116
- * @example
117
- * ```ts
118
- * complement(parseColor("hsl(60, 50%, 50%)")).getChannelValue("hue") // 240
119
- * ```
120
- */
121
- export function complement(color) {
122
- const hsl = color.toFormat("hsl");
123
- return hsl.withChannelValue("hue", normalizeHue(hsl.getChannelValue("hue") + 180));
95
+ * Returns the complementary color (hue rotated 180°), preserving saturation, lightness, and alpha.
96
+ * The returned color is in HSL.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * complement(parseColor("hsl(60, 50%, 50%)")).getChannelValue("hue") // 240
101
+ * ```
102
+ */
103
+ function complement(color) {
104
+ const hsl = color.toFormat("hsl");
105
+ return hsl.withChannelValue("hue", normalizeHue(hsl.getChannelValue("hue") + 180));
124
106
  }
125
107
  /**
126
- * Mixes two colors in RGB space at the given `ratio` (0 = fully `a`, 1 = fully `b`).
127
- * Alpha is also interpolated. The returned color is in RGB.
128
- *
129
- * @example
130
- * ```ts
131
- * mix(parseColor("#000000"), parseColor("#ffffff")).toString("hex") // "#808080"
132
- * mix(parseColor("#000000"), parseColor("#ffffff"), 0.25).toString("hex") // "#404040"
133
- * ```
134
- */
135
- export function mix(a, b, ratio = 0.5) {
136
- const r = Number.isFinite(ratio) ? clamp(ratio, 0, 1) : 0.5;
137
- const ra = a.toFormat("rgb");
138
- const rb = b.toFormat("rgb");
139
- const lerp = (x, y) => x + (y - x) * r;
140
- return ra
141
- .withChannelValue("red", Math.round(lerp(ra.getChannelValue("red"), rb.getChannelValue("red"))))
142
- .withChannelValue("green", Math.round(lerp(ra.getChannelValue("green"), rb.getChannelValue("green"))))
143
- .withChannelValue("blue", Math.round(lerp(ra.getChannelValue("blue"), rb.getChannelValue("blue"))))
144
- .withChannelValue("alpha", lerp(ra.getChannelValue("alpha"), rb.getChannelValue("alpha")));
108
+ * Mixes two colors in RGB space at the given `ratio` (0 = fully `a`, 1 = fully `b`).
109
+ * Alpha is also interpolated. The returned color is in RGB.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * mix(parseColor("#000000"), parseColor("#ffffff")).toString("hex") // "#808080"
114
+ * mix(parseColor("#000000"), parseColor("#ffffff"), 0.25).toString("hex") // "#404040"
115
+ * ```
116
+ */
117
+ function mix(a, b, ratio = .5) {
118
+ const r = Number.isFinite(ratio) ? clamp(ratio, 0, 1) : .5;
119
+ const ra = a.toFormat("rgb");
120
+ const rb = b.toFormat("rgb");
121
+ const lerp = (x, y) => x + (y - x) * r;
122
+ return ra.withChannelValue("red", Math.round(lerp(ra.getChannelValue("red"), rb.getChannelValue("red")))).withChannelValue("green", Math.round(lerp(ra.getChannelValue("green"), rb.getChannelValue("green")))).withChannelValue("blue", Math.round(lerp(ra.getChannelValue("blue"), rb.getChannelValue("blue")))).withChannelValue("alpha", lerp(ra.getChannelValue("alpha"), rb.getChannelValue("alpha")));
145
123
  }
146
- // ─── Accessibility ────────────────────────────────────────────────────────────
147
124
  /** WCAG 2.1 relative luminance. Alpha is ignored (assumes opaque rendering). */
148
125
  function relativeLuminance(color) {
149
- const rgb = color.toFormat("rgb");
150
- const linearize = (v) => {
151
- const c = v / 255;
152
- return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
153
- };
154
- return (0.2126 * linearize(rgb.getChannelValue("red")) +
155
- 0.7152 * linearize(rgb.getChannelValue("green")) +
156
- 0.0722 * linearize(rgb.getChannelValue("blue")));
126
+ const rgb = color.toFormat("rgb");
127
+ const linearize = (v) => {
128
+ const c = v / 255;
129
+ return c <= .04045 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4;
130
+ };
131
+ return .2126 * linearize(rgb.getChannelValue("red")) + .7152 * linearize(rgb.getChannelValue("green")) + .0722 * linearize(rgb.getChannelValue("blue"));
157
132
  }
158
133
  /**
159
- * Returns the WCAG 2.1 contrast ratio between two colors (1–21).
160
- * The order of arguments does not matter.
161
- *
162
- * - Black on white: `21`
163
- * - Same color: `1`
164
- *
165
- * @example
166
- * ```ts
167
- * contrastRatio(parseColor("#000"), parseColor("#fff")) // 21
168
- * ```
169
- */
170
- export function contrastRatio(a, b) {
171
- const l1 = relativeLuminance(a);
172
- const l2 = relativeLuminance(b);
173
- return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);
134
+ * Returns the WCAG 2.1 contrast ratio between two colors (1–21).
135
+ * The order of arguments does not matter.
136
+ *
137
+ * - Black on white: `21`
138
+ * - Same color: `1`
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * contrastRatio(parseColor("#000"), parseColor("#fff")) // 21
143
+ * ```
144
+ */
145
+ function contrastRatio(a, b) {
146
+ const l1 = relativeLuminance(a);
147
+ const l2 = relativeLuminance(b);
148
+ return (Math.max(l1, l2) + .05) / (Math.min(l1, l2) + .05);
174
149
  }
175
150
  /**
176
- * Returns whether the contrast between `foreground` and `background` meets the
177
- * specified WCAG 2.1 conformance level and text size.
178
- *
179
- * | Level | Normal text | Large text (≥18pt / ≥14pt bold) |
180
- * |-------|-------------|----------------------------------|
181
- * | AA | 4.5 : 1 | 3 : 1 |
182
- * | AAA | 7 : 1 | 4.5 : 1 |
183
- *
184
- * @example
185
- * ```ts
186
- * isReadable(parseColor("#fff"), parseColor("#000")) // true (AA, normal)
187
- * isReadable(parseColor("#fff"), parseColor("#000"), "AAA") // true
188
- * isReadable(parseColor("#777"), parseColor("#fff"), "AAA") // false
189
- * ```
190
- */
191
- export function isReadable(foreground, background, level = "AA", size = "normal") {
192
- const ratio = contrastRatio(foreground, background);
193
- if (level === "AAA")
194
- return ratio >= (size === "large" ? 4.5 : 7);
195
- return ratio >= (size === "large" ? 3 : 4.5);
151
+ * Returns whether the contrast between `foreground` and `background` meets the
152
+ * specified WCAG 2.1 conformance level and text size.
153
+ *
154
+ * | Level | Normal text | Large text (≥18pt / ≥14pt bold) |
155
+ * |-------|-------------|----------------------------------|
156
+ * | AA | 4.5 : 1 | 3 : 1 |
157
+ * | AAA | 7 : 1 | 4.5 : 1 |
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * isReadable(parseColor("#fff"), parseColor("#000")) // true (AA, normal)
162
+ * isReadable(parseColor("#fff"), parseColor("#000"), "AAA") // true
163
+ * isReadable(parseColor("#777"), parseColor("#fff"), "AAA") // false
164
+ * ```
165
+ */
166
+ function isReadable(foreground, background, level = "AA", size = "normal") {
167
+ const ratio = contrastRatio(foreground, background);
168
+ if (level === "AAA") return ratio >= (size === "large" ? 4.5 : 7);
169
+ return ratio >= (size === "large" ? 3 : 4.5);
196
170
  }
197
- // ─── Color scales ─────────────────────────────────────────────────────────────
198
171
  /**
199
- * Returns an array of `steps` colors linearly interpolated in RGB space between
200
- * `from` and `to`. The first element is `from`, the last is `to`.
201
- *
202
- * @throws if `steps` is not a finite integer >= 2.
203
- *
204
- * @example
205
- * ```ts
206
- * colorScale(parseColor("#000"), parseColor("#fff"), 3)
207
- * // [#000000, #808080, #FFFFFF]
208
- * ```
209
- */
210
- export function colorScale(from, to, steps) {
211
- if (!Number.isFinite(steps) || !Number.isInteger(steps) || steps < 2)
212
- throw new Error("colorScale: steps must be a finite integer >= 2");
213
- return Array.from({ length: steps }, (_, i) => mix(from, to, i / (steps - 1)));
172
+ * Returns an array of `steps` colors linearly interpolated in RGB space between
173
+ * `from` and `to`. The first element is `from`, the last is `to`.
174
+ *
175
+ * @throws if `steps` is not a finite integer >= 2.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * colorScale(parseColor("#000"), parseColor("#fff"), 3)
180
+ * // [#000000, #808080, #FFFFFF]
181
+ * ```
182
+ */
183
+ function colorScale(from, to, steps) {
184
+ if (!Number.isFinite(steps) || !Number.isInteger(steps) || steps < 2) throw new Error("colorScale: steps must be a finite integer >= 2");
185
+ return Array.from({ length: steps }, (_, i) => mix(from, to, i / (steps - 1)));
214
186
  }
215
187
  /** Interpolate between two OKLCH triplets, taking the shortest hue path. */
216
188
  function lerpOKLCH([l1, c1, h1], [l2, c2, h2], t) {
217
- let dh = h2 - h1;
218
- if (dh > 180)
219
- dh -= 360;
220
- if (dh < -180)
221
- dh += 360;
222
- return [l1 + (l2 - l1) * t, c1 + (c2 - c1) * t, normalizeHue(h1 + dh * t)];
189
+ let dh = h2 - h1;
190
+ if (dh > 180) dh -= 360;
191
+ if (dh < -180) dh += 360;
192
+ return [
193
+ l1 + (l2 - l1) * t,
194
+ c1 + (c2 - c1) * t,
195
+ normalizeHue(h1 + dh * t)
196
+ ];
223
197
  }
224
198
  /**
225
- * Convert OKLCH back to an RGB `Color` via the OKLab → LMS → linear sRGB → sRGB pipeline.
226
- * Out-of-gamut values are clamped to [0, 1] before gamma encoding.
227
- * Coefficients from https://bottosson.github.io/posts/oklab/
228
- */
199
+ * Convert OKLCH back to an RGB `Color` via the OKLab → LMS → linear sRGB → sRGB pipeline.
200
+ * Out-of-gamut values are clamped to [0, 1] before gamma encoding.
201
+ * Coefficients from https://bottosson.github.io/posts/oklab/
202
+ */
229
203
  function oklchToColor(l, c, h, alpha) {
230
- const hRad = (h * Math.PI) / 180;
231
- const a = c * Math.cos(hRad);
232
- const b = c * Math.sin(hRad);
233
- // OKLab → cube-root LMS
234
- const l_ = l + 0.3963377774 * a + 0.2158037573 * b;
235
- const m_ = l - 0.1055613458 * a - 0.0638541728 * b;
236
- const s_ = l - 0.0894841775 * a - 1.291485548 * b;
237
- // Cube to LMS, then combined (M1_inv × XYZ→sRGB) matrix to linear sRGB
238
- const ll = l_ ** 3;
239
- const mm = m_ ** 3;
240
- const ss = s_ ** 3;
241
- const r_lin = +4.0767416621 * ll - 3.3077115913 * mm + 0.2309699292 * ss;
242
- const g_lin = -1.2684380046 * ll + 2.6097574011 * mm - 0.3413193965 * ss;
243
- const b_lin = -0.0041960863 * ll - 0.7034186147 * mm + 1.7076147010 * ss;
244
- const toSRGB = (v) => {
245
- const clamped = clamp(v, 0, 1);
246
- return Math.round((clamped <= 0.0031308 ? 12.92 * clamped : 1.055 * clamped ** (1 / 2.4) - 0.055) * 255);
247
- };
248
- return parseColor(`rgba(${toSRGB(r_lin)}, ${toSRGB(g_lin)}, ${toSRGB(b_lin)}, ${alpha})`);
204
+ const hRad = h * Math.PI / 180;
205
+ const a = c * Math.cos(hRad);
206
+ const b = c * Math.sin(hRad);
207
+ const l_ = l + .3963377774 * a + .2158037573 * b;
208
+ const m_ = l - .1055613458 * a - .0638541728 * b;
209
+ const s_ = l - .0894841775 * a - 1.291485548 * b;
210
+ const ll = l_ ** 3;
211
+ const mm = m_ ** 3;
212
+ const ss = s_ ** 3;
213
+ const r_lin = 4.0767416621 * ll - 3.3077115913 * mm + .2309699292 * ss;
214
+ const g_lin = -1.2684380046 * ll + 2.6097574011 * mm - .3413193965 * ss;
215
+ const b_lin = -.0041960863 * ll - .7034186147 * mm + 1.707614701 * ss;
216
+ const toSRGB = (v) => {
217
+ const clamped = clamp(v, 0, 1);
218
+ return Math.round((clamped <= .0031308 ? 12.92 * clamped : 1.055 * clamped ** (1 / 2.4) - .055) * 255);
219
+ };
220
+ return parseColor(`rgba(${toSRGB(r_lin)}, ${toSRGB(g_lin)}, ${toSRGB(b_lin)}, ${alpha})`);
249
221
  }
250
222
  /**
251
- * Returns an array of `steps` colors interpolated in OKLCH space between `from` and `to`.
252
- * OKLCH is a perceptually uniform color space, so the steps appear more evenly distributed
253
- * to the human eye than a plain RGB scale.
254
- *
255
- * Hue interpolation takes the shortest arc around the color wheel.
256
- * Alpha is linearly interpolated. The returned colors are in RGB.
257
- *
258
- * @throws if `steps` is not a finite integer >= 2.
259
- *
260
- * @example
261
- * ```ts
262
- * // A scale from red to blue that passes through purple rather than through green
263
- * perceptualColorScale(parseColor("hsl(0, 80%, 50%)"), parseColor("hsl(240, 80%, 50%)"), 5)
264
- * ```
265
- */
266
- export function perceptualColorScale(from, to, steps) {
267
- if (!Number.isFinite(steps) || !Number.isInteger(steps) || steps < 2)
268
- throw new Error("perceptualColorScale: steps must be a finite integer >= 2");
269
- const fromOKLCH = colorToOKLCH(from);
270
- const toOKLCH = colorToOKLCH(to);
271
- const alphaFrom = from.getChannelValue("alpha");
272
- const alphaTo = to.getChannelValue("alpha");
273
- return Array.from({ length: steps }, (_, i) => {
274
- const t = i / (steps - 1);
275
- const [l, c, h] = lerpOKLCH(fromOKLCH, toOKLCH, t);
276
- return oklchToColor(l, c, h, alphaFrom + (alphaTo - alphaFrom) * t);
277
- });
278
- }
223
+ * Returns an array of `steps` colors interpolated in OKLCH space between `from` and `to`.
224
+ * OKLCH is a perceptually uniform color space, so the steps appear more evenly distributed
225
+ * to the human eye than a plain RGB scale.
226
+ *
227
+ * Hue interpolation takes the shortest arc around the color wheel.
228
+ * Alpha is linearly interpolated. The returned colors are in RGB.
229
+ *
230
+ * @throws if `steps` is not a finite integer >= 2.
231
+ *
232
+ * @example
233
+ * ```ts
234
+ * // A scale from red to blue that passes through purple rather than through green
235
+ * perceptualColorScale(parseColor("hsl(0, 80%, 50%)"), parseColor("hsl(240, 80%, 50%)"), 5)
236
+ * ```
237
+ */
238
+ function perceptualColorScale(from, to, steps) {
239
+ if (!Number.isFinite(steps) || !Number.isInteger(steps) || steps < 2) throw new Error("perceptualColorScale: steps must be a finite integer >= 2");
240
+ const fromOKLCH = colorToOKLCH(from);
241
+ const toOKLCH = colorToOKLCH(to);
242
+ const alphaFrom = from.getChannelValue("alpha");
243
+ const alphaTo = to.getChannelValue("alpha");
244
+ return Array.from({ length: steps }, (_, i) => {
245
+ const t = i / (steps - 1);
246
+ const [l, c, h] = lerpOKLCH(fromOKLCH, toOKLCH, t);
247
+ return oklchToColor(l, c, h, alphaFrom + (alphaTo - alphaFrom) * t);
248
+ });
249
+ }
250
+ //#endregion
251
+ export { colorScale, complement, contrastRatio, darken, desaturate, detectColorFormat, isReadable, isValidColor, lighten, mix, perceptualColorScale, saturate, tryParseColor };