@tempots/std 0.26.1 → 0.28.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.
Files changed (51) hide show
  1. package/color-D7FAmkht.cjs +1 -0
  2. package/color-SZxckS9U.js +522 -0
  3. package/color-adjust.cjs +1 -0
  4. package/color-adjust.d.ts +148 -0
  5. package/color-adjust.js +47 -0
  6. package/color-contrast.cjs +1 -0
  7. package/color-contrast.d.ts +96 -0
  8. package/color-contrast.js +22 -0
  9. package/color-distance.cjs +1 -0
  10. package/color-distance.d.ts +41 -0
  11. package/color-distance.js +25 -0
  12. package/color-harmony.cjs +1 -0
  13. package/color-harmony.d.ts +81 -0
  14. package/color-harmony.js +35 -0
  15. package/color-hsl.cjs +1 -0
  16. package/color-hsl.d.ts +81 -0
  17. package/color-hsl.js +10 -0
  18. package/color-hsv.cjs +1 -0
  19. package/color-hsv.d.ts +116 -0
  20. package/color-hsv.js +12 -0
  21. package/color-hwb.cjs +1 -0
  22. package/color-hwb.d.ts +88 -0
  23. package/color-hwb.js +10 -0
  24. package/color-lab.cjs +1 -0
  25. package/color-lab.d.ts +161 -0
  26. package/color-lab.js +15 -0
  27. package/color-mix.cjs +1 -0
  28. package/color-mix.d.ts +50 -0
  29. package/color-mix.js +101 -0
  30. package/color-named.cjs +1 -0
  31. package/color-named.d.ts +8 -0
  32. package/color-named.js +153 -0
  33. package/color-oklab.cjs +1 -0
  34. package/color-oklab.d.ts +141 -0
  35. package/color-oklab.js +15 -0
  36. package/color-rgb.cjs +1 -0
  37. package/color-rgb.d.ts +119 -0
  38. package/color-rgb.js +14 -0
  39. package/color-utils.cjs +1 -0
  40. package/color-utils.d.ts +57 -0
  41. package/color-utils.js +54 -0
  42. package/color.cjs +1 -0
  43. package/color.d.ts +466 -0
  44. package/color.js +33 -0
  45. package/index.cjs +1 -1
  46. package/index.d.ts +14 -0
  47. package/index.js +370 -265
  48. package/number.cjs +1 -1
  49. package/number.d.ts +15 -0
  50. package/number.js +32 -31
  51. package/package.json +99 -1
package/color-hsv.d.ts ADDED
@@ -0,0 +1,116 @@
1
+ import { RGB8A, HSVA, HSLA } from './color';
2
+ /**
3
+ * Returns `true` if the string can be parsed as an `hsv()` or `hsva()` color.
4
+ *
5
+ * This is a non-standard format commonly used in design tools such as Figma
6
+ * and Sketch. Supports both legacy comma-separated and modern
7
+ * space-separated syntax.
8
+ *
9
+ * @param s - The string to test.
10
+ * @returns `true` if the string is a valid HSV functional notation.
11
+ * @public
12
+ * @example
13
+ * ```ts
14
+ * canParseHsv('hsv(0, 100%, 100%)') // true
15
+ * canParseHsv('hsv(120 50% 80% / 0.5)') // true
16
+ * canParseHsv('hsl(0, 100%, 50%)') // false
17
+ * ```
18
+ */
19
+ export declare const canParseHsv: (s: string) => boolean;
20
+ /**
21
+ * Parses an `hsv()` or `hsva()` color string into an HSVA color.
22
+ *
23
+ * Supports both legacy comma-separated and modern space-separated syntax.
24
+ *
25
+ * @param s - The string to parse.
26
+ * @returns An HSVA color.
27
+ * @throws ParsingError if the string is not a valid HSV color.
28
+ * @public
29
+ * @example
30
+ * ```ts
31
+ * parseHsv('hsv(0, 100%, 100%)') // hsva(0, 100, 100)
32
+ * parseHsv('hsva(120, 50%, 80%, 0.5)') // hsva(120, 50, 80, 0.5)
33
+ * parseHsv('hsv(240 25% 90% / 50%)') // hsva(240, 25, 90, 0.5)
34
+ * ```
35
+ */
36
+ export declare const parseHsv: (s: string) => HSVA;
37
+ /**
38
+ * Converts an RGB8A color to an HSVA color.
39
+ *
40
+ * Uses the standard RGB-to-HSV algorithm where Value is the maximum channel
41
+ * and Saturation is the ratio of chroma to Value.
42
+ *
43
+ * @param c - The RGB8A color to convert.
44
+ * @returns An HSVA color.
45
+ * @public
46
+ * @example
47
+ * ```ts
48
+ * rgb8aToHsva(rgb8a(255, 0, 0)) // hsva(0, 100, 100)
49
+ * rgb8aToHsva(rgb8a(0, 0, 0)) // hsva(0, 0, 0)
50
+ * rgb8aToHsva(rgb8a(128, 128, 128)) // hsva(0, 0, ~50.2)
51
+ * ```
52
+ */
53
+ export declare const rgb8aToHsva: (c: RGB8A) => HSVA;
54
+ /**
55
+ * Converts an HSVA color to an RGB8A color.
56
+ *
57
+ * Uses the standard HSV-to-RGB algorithm with chroma, hue sectors, and an
58
+ * offset to produce final channel values.
59
+ *
60
+ * @param c - The HSVA color to convert.
61
+ * @returns An RGB8A color.
62
+ * @public
63
+ * @example
64
+ * ```ts
65
+ * hsvaToRgb8a(hsva(0, 100, 100)) // rgb8a(255, 0, 0)
66
+ * hsvaToRgb8a(hsva(120, 100, 100)) // rgb8a(0, 255, 0)
67
+ * hsvaToRgb8a(hsva(0, 0, 0)) // rgb8a(0, 0, 0)
68
+ * ```
69
+ */
70
+ export declare const hsvaToRgb8a: (c: HSVA) => RGB8A;
71
+ /**
72
+ * Converts an HSLA color to an HSVA color using a direct formula that
73
+ * avoids an intermediate RGB conversion.
74
+ *
75
+ * @param c - The HSLA color to convert.
76
+ * @returns An HSVA color.
77
+ * @public
78
+ * @example
79
+ * ```ts
80
+ * hslaToHsva(hsla(0, 100, 50)) // hsva(0, 100, 100)
81
+ * hslaToHsva(hsla(0, 0, 0)) // hsva(0, 0, 0)
82
+ * hslaToHsva(hsla(120, 50, 75)) // hsva(120, ~33.3, ~87.5)
83
+ * ```
84
+ */
85
+ export declare const hslaToHsva: (c: HSLA) => HSVA;
86
+ /**
87
+ * Converts an HSVA color to an HSLA color using a direct formula that
88
+ * avoids an intermediate RGB conversion.
89
+ *
90
+ * @param c - The HSVA color to convert.
91
+ * @returns An HSLA color.
92
+ * @public
93
+ * @example
94
+ * ```ts
95
+ * hsvaToHsla(hsva(0, 100, 100)) // hsla(0, 100, 50)
96
+ * hsvaToHsla(hsva(0, 0, 0)) // hsla(0, 0, 0)
97
+ * hsvaToHsla(hsva(120, 50, 80)) // hsla(120, ~47.1, 60)
98
+ * ```
99
+ */
100
+ export declare const hsvaToHsla: (c: HSVA) => HSLA;
101
+ /**
102
+ * Serializes an HSVA color to an `hsv()` or `hsva()` string.
103
+ *
104
+ * Produces `hsv(h, s%, v%)` when alpha is 1, or `hsva(h, s%, v%, a)`
105
+ * otherwise.
106
+ *
107
+ * @param c - The HSVA color to serialize.
108
+ * @returns An HSV color string.
109
+ * @public
110
+ * @example
111
+ * ```ts
112
+ * hsvaToHsvString(hsva(0, 100, 100)) // 'hsv(0, 100%, 100%)'
113
+ * hsvaToHsvString(hsva(120, 50, 80, 0.5)) // 'hsva(120, 50%, 80%, 0.5)'
114
+ * ```
115
+ */
116
+ export declare const hsvaToHsvString: (c: HSVA) => string;
package/color-hsv.js ADDED
@@ -0,0 +1,12 @@
1
+ import "./error.js";
2
+ import "./number.js";
3
+ import { d as r, q as H, t, u as T, v as h, Y as p, a7 as e } from "./color-SZxckS9U.js";
4
+ export {
5
+ r as canParseHsv,
6
+ H as hslaToHsva,
7
+ t as hsvaToHsla,
8
+ T as hsvaToHsvString,
9
+ h as hsvaToRgb8a,
10
+ p as parseHsv,
11
+ e as rgb8aToHsva
12
+ };
package/color-hwb.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./error.cjs");require("./number.cjs");const b=require("./color-D7FAmkht.cjs");exports.canParseHwb=b.canParseHwb;exports.hwbaToHwbString=b.hwbaToHwbString;exports.hwbaToRgb8a=b.hwbaToRgb8a;exports.parseHwb=b.parseHwb;exports.rgb8aToHwba=b.rgb8aToHwba;
package/color-hwb.d.ts ADDED
@@ -0,0 +1,88 @@
1
+ import { RGB8A, HWBA } from './color';
2
+ /**
3
+ * Returns `true` if the string can be parsed as an `hwb()` CSS Level 4 color.
4
+ *
5
+ * Only the modern space-separated syntax is supported:
6
+ * `hwb(h w% b%)` or `hwb(h w% b% / alpha)`.
7
+ *
8
+ * @param s - The string to test.
9
+ * @returns `true` if the string is a valid HWB functional notation.
10
+ * @public
11
+ * @example
12
+ * ```ts
13
+ * canParseHwb('hwb(0 0% 0%)') // true
14
+ * canParseHwb('hwb(180 20% 30% / 0.5)') // true
15
+ * canParseHwb('rgb(255, 0, 0)') // false
16
+ * ```
17
+ */
18
+ export declare const canParseHwb: (s: string) => boolean;
19
+ /**
20
+ * Parses an `hwb()` CSS Level 4 color string into an HWBA color.
21
+ *
22
+ * Only the modern space-separated syntax is supported:
23
+ * `hwb(h w% b%)` or `hwb(h w% b% / alpha)`.
24
+ *
25
+ * @param s - The string to parse.
26
+ * @returns An HWBA color.
27
+ * @throws ParsingError if the string is not a valid HWB color.
28
+ * @public
29
+ * @example
30
+ * ```ts
31
+ * parseHwb('hwb(0 0% 0%)') // hwba(0, 0, 0)
32
+ * parseHwb('hwb(180 20% 30%)') // hwba(180, 20, 30)
33
+ * parseHwb('hwb(90 10% 20% / 0.5)') // hwba(90, 10, 20, 0.5)
34
+ * ```
35
+ */
36
+ export declare const parseHwb: (s: string) => HWBA;
37
+ /**
38
+ * Converts an RGB8A color to an HWBA color.
39
+ *
40
+ * The conversion derives hue, whiteness, and blackness from the RGB channels.
41
+ * Whiteness is the minimum channel value and blackness is one minus the maximum
42
+ * channel value.
43
+ *
44
+ * @param c - The RGB8A color to convert.
45
+ * @returns An HWBA color.
46
+ * @public
47
+ * @example
48
+ * ```ts
49
+ * rgb8aToHwba(rgb8a(255, 0, 0)) // hwba(0, 0, 0)
50
+ * rgb8aToHwba(rgb8a(0, 0, 0)) // hwba(0, 0, 100)
51
+ * rgb8aToHwba(rgb8a(255, 255, 255)) // hwba(0, 100, 0)
52
+ * ```
53
+ */
54
+ export declare const rgb8aToHwba: (c: RGB8A) => HWBA;
55
+ /**
56
+ * Converts an HWBA color to an RGB8A color.
57
+ *
58
+ * When whiteness plus blackness exceed 100%, they are proportionally scaled
59
+ * so that their sum equals 100%. The pure hue color is then blended between
60
+ * white and black according to the whiteness and blackness values.
61
+ *
62
+ * @param c - The HWBA color to convert.
63
+ * @returns An RGB8A color.
64
+ * @public
65
+ * @example
66
+ * ```ts
67
+ * hwbaToRgb8a(hwba(0, 0, 0)) // rgb8a(255, 0, 0)
68
+ * hwbaToRgb8a(hwba(0, 100, 0)) // rgb8a(255, 255, 255)
69
+ * hwbaToRgb8a(hwba(0, 0, 100)) // rgb8a(0, 0, 0)
70
+ * ```
71
+ */
72
+ export declare const hwbaToRgb8a: (c: HWBA) => RGB8A;
73
+ /**
74
+ * Serializes an HWBA color to a CSS `hwb()` string.
75
+ *
76
+ * Produces `hwb(h w% b%)` when alpha is 1, or `hwb(h w% b% / alpha)`
77
+ * otherwise.
78
+ *
79
+ * @param c - The HWBA color to serialize.
80
+ * @returns A CSS `hwb()` color string.
81
+ * @public
82
+ * @example
83
+ * ```ts
84
+ * hwbaToHwbString(hwba(0, 0, 0)) // 'hwb(0 0% 0%)'
85
+ * hwbaToHwbString(hwba(180, 20, 30, 0.5)) // 'hwb(180 20% 30% / 0.5)'
86
+ * ```
87
+ */
88
+ export declare const hwbaToHwbString: (c: HWBA) => string;
package/color-hwb.js ADDED
@@ -0,0 +1,10 @@
1
+ import "./error.js";
2
+ import "./number.js";
3
+ import { e as s, x as w, y as e, Z as p, a8 as t } from "./color-SZxckS9U.js";
4
+ export {
5
+ s as canParseHwb,
6
+ w as hwbaToHwbString,
7
+ e as hwbaToRgb8a,
8
+ p as parseHwb,
9
+ t as rgb8aToHwba
10
+ };
package/color-lab.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./error.cjs");require("./number.cjs");const a=require("./color-D7FAmkht.cjs");exports.canParseLab=a.canParseLab;exports.canParseLch=a.canParseLch;exports.labaToLabString=a.labaToLabString;exports.labaToRgb8a=a.labaToRgb8a;exports.lchaToLchString=a.lchaToLchString;exports.lchaToRgb8a=a.lchaToRgb8a;exports.parseLab=a.parseLab;exports.parseLch=a.parseLch;exports.rgb8aToLaba=a.rgb8aToLaba;exports.rgb8aToLcha=a.rgb8aToLcha;
package/color-lab.d.ts ADDED
@@ -0,0 +1,161 @@
1
+ import { RGB8A, LABA, LCHA } from './color';
2
+ /**
3
+ * Returns `true` if the string can be parsed as a `lab()` color.
4
+ *
5
+ * @param s - The string to test.
6
+ * @returns `true` if the string is a valid LAB functional notation.
7
+ * @public
8
+ * @example
9
+ * ```ts
10
+ * canParseLab('lab(50 -20 30)') // true
11
+ * canParseLab('lab(50% -20 30 / 0.5)') // true
12
+ * canParseLab('#ff0000') // false
13
+ * ```
14
+ */
15
+ export declare const canParseLab: (s: string) => boolean;
16
+ /**
17
+ * Parses a `lab()` color string into a LABA color.
18
+ *
19
+ * Supports `lab(L a b)` and `lab(L a b / alpha)` syntax. The lightness
20
+ * value can be a percentage (0–100%) or a plain number (0–100). The `a`
21
+ * and `b` axes accept any number, including negatives.
22
+ *
23
+ * @param s - The string to parse.
24
+ * @returns A LABA color.
25
+ * @throws ParsingError if the string is not a valid LAB color.
26
+ * @public
27
+ * @example
28
+ * ```ts
29
+ * parseLab('lab(50 -20 30)') // laba(50, -20, 30)
30
+ * parseLab('lab(50% -20 30 / 0.5)') // laba(50, -20, 30, 0.5)
31
+ * ```
32
+ */
33
+ export declare const parseLab: (s: string) => LABA;
34
+ /**
35
+ * Returns `true` if the string can be parsed as an `lch()` color.
36
+ *
37
+ * @param s - The string to test.
38
+ * @returns `true` if the string is a valid LCH functional notation.
39
+ * @public
40
+ * @example
41
+ * ```ts
42
+ * canParseLch('lch(50 36 326)') // true
43
+ * canParseLch('lch(50% 36 326 / 0.8)') // true
44
+ * canParseLch('rgb(0,0,0)') // false
45
+ * ```
46
+ */
47
+ export declare const canParseLch: (s: string) => boolean;
48
+ /**
49
+ * Parses an `lch()` color string into a LCHA color.
50
+ *
51
+ * Supports `lch(L C H)` and `lch(L C H / alpha)` syntax. The lightness
52
+ * value can be a percentage (0–100%) or a plain number (0–100). Chroma
53
+ * must be non-negative, and hue is an angle in degrees.
54
+ *
55
+ * @param s - The string to parse.
56
+ * @returns A LCHA color.
57
+ * @throws ParsingError if the string is not a valid LCH color.
58
+ * @public
59
+ * @example
60
+ * ```ts
61
+ * parseLch('lch(50 36 326)') // lcha(50, 36, 326)
62
+ * parseLch('lch(75% 40 120 / 50%)') // lcha(75, 40, 120, 0.5)
63
+ * ```
64
+ */
65
+ export declare const parseLch: (s: string) => LCHA;
66
+ /**
67
+ * Converts an RGB8A color to a LABA color through the CIE XYZ intermediate
68
+ * color space.
69
+ *
70
+ * @param c - The RGB8A color to convert.
71
+ * @returns The equivalent LABA color.
72
+ * @public
73
+ * @example
74
+ * ```ts
75
+ * rgb8aToLaba(rgb8a(255, 0, 0)) // laba(~53.23, ~80.11, ~67.22)
76
+ * rgb8aToLaba(rgb8a(0, 0, 0)) // laba(0, 0, 0)
77
+ * ```
78
+ */
79
+ export declare const rgb8aToLaba: (c: RGB8A) => LABA;
80
+ /**
81
+ * Converts a LABA color to an RGB8A color through the CIE XYZ intermediate
82
+ * color space.
83
+ *
84
+ * Channel values are clamped to the sRGB gamut before rounding.
85
+ *
86
+ * @param c - The LABA color to convert.
87
+ * @returns The equivalent RGB8A color.
88
+ * @public
89
+ * @example
90
+ * ```ts
91
+ * labaToRgb8a(laba(53.23, 80.11, 67.22)) // rgb8a(~255, ~0, ~0)
92
+ * labaToRgb8a(laba(0, 0, 0)) // rgb8a(0, 0, 0)
93
+ * ```
94
+ */
95
+ export declare const labaToRgb8a: (c: LABA) => RGB8A;
96
+ /**
97
+ * Converts an RGB8A color to a LCHA color by converting to LABA first and
98
+ * then applying the polar (cylindrical) transformation.
99
+ *
100
+ * @param c - The RGB8A color to convert.
101
+ * @returns The equivalent LCHA color.
102
+ * @public
103
+ * @example
104
+ * ```ts
105
+ * rgb8aToLcha(rgb8a(255, 0, 0)) // lcha(~53.23, ~104.55, ~40.0)
106
+ * rgb8aToLcha(rgb8a(0, 0, 0)) // lcha(0, 0, 0)
107
+ * ```
108
+ */
109
+ export declare const rgb8aToLcha: (c: RGB8A) => LCHA;
110
+ /**
111
+ * Converts a LCHA color to an RGB8A color by converting from polar
112
+ * coordinates to rectangular LAB and then to RGB8A.
113
+ *
114
+ * @param c - The LCHA color to convert.
115
+ * @returns The equivalent RGB8A color.
116
+ * @public
117
+ * @example
118
+ * ```ts
119
+ * lchaToRgb8a(lcha(53.23, 104.55, 40.0)) // rgb8a(~255, ~0, ~0)
120
+ * lchaToRgb8a(lcha(0, 0, 0)) // rgb8a(0, 0, 0)
121
+ * ```
122
+ */
123
+ export declare const lchaToRgb8a: (c: LCHA) => RGB8A;
124
+ /**
125
+ * Serializes a LABA color to a `lab()` CSS string.
126
+ *
127
+ * Produces `lab(L a b)` when alpha is 1, or `lab(L a b / alpha)` otherwise.
128
+ * Lightness is rounded to 2 decimal places; `a` and `b` axes are rounded
129
+ * to 4 decimal places.
130
+ *
131
+ * @param c - The LABA color to serialize.
132
+ * @returns A CSS `lab()` color string.
133
+ * @public
134
+ * @example
135
+ * ```ts
136
+ * labaToLabString(laba(50, -20, 30))
137
+ * // 'lab(50 -20 30)'
138
+ * labaToLabString(laba(50, -20, 30, 0.5))
139
+ * // 'lab(50 -20 30 / 0.5)'
140
+ * ```
141
+ */
142
+ export declare const labaToLabString: (c: LABA) => string;
143
+ /**
144
+ * Serializes a LCHA color to an `lch()` CSS string.
145
+ *
146
+ * Produces `lch(L C H)` when alpha is 1, or `lch(L C H / alpha)` otherwise.
147
+ * Lightness is rounded to 2 decimal places; chroma and hue are rounded to
148
+ * 4 decimal places.
149
+ *
150
+ * @param c - The LCHA color to serialize.
151
+ * @returns A CSS `lch()` color string.
152
+ * @public
153
+ * @example
154
+ * ```ts
155
+ * lchaToLchString(lcha(50, 36, 326))
156
+ * // 'lch(50 36 326)'
157
+ * lchaToLchString(lcha(50, 36, 326, 0.8))
158
+ * // 'lch(50 36 326 / 0.8)'
159
+ * ```
160
+ */
161
+ export declare const lchaToLchString: (c: LCHA) => string;
package/color-lab.js ADDED
@@ -0,0 +1,15 @@
1
+ import "./error.js";
2
+ import "./number.js";
3
+ import { f as o, g as c, J as L, K as g, M as h, N as T, _ as e, $ as p, a9 as t, aa as i } from "./color-SZxckS9U.js";
4
+ export {
5
+ o as canParseLab,
6
+ c as canParseLch,
7
+ L as labaToLabString,
8
+ g as labaToRgb8a,
9
+ h as lchaToLchString,
10
+ T as lchaToRgb8a,
11
+ e as parseLab,
12
+ p as parseLch,
13
+ t as rgb8aToLaba,
14
+ i as rgb8aToLcha
15
+ };
package/color-mix.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./color-D7FAmkht.cjs"),p=require("./number.cjs"),r=p.interpolate,b=p.interpolateAngle,i=(e,t,l,h)=>{const n=s.convertColor(e,h),c=s.convertColor(t,h);switch(h){case"rgb":{const a=n,o=c;return s.rgba(r(a.r,o.r,l),r(a.g,o.g,l),r(a.b,o.b,l),r(a.alpha,o.alpha,l))}case"rgb8":{const a=n,o=c;return s.rgb8a(Math.round(r(a.r,o.r,l)),Math.round(r(a.g,o.g,l)),Math.round(r(a.b,o.b,l)),r(a.alpha,o.alpha,l))}case"hsl":{const a=n,o=c;return s.hsla(b(a.h,o.h,l),r(a.s,o.s,l),r(a.l,o.l,l),r(a.alpha,o.alpha,l))}case"hsv":{const a=n,o=c;return s.hsva(b(a.h,o.h,l),r(a.s,o.s,l),r(a.v,o.v,l),r(a.alpha,o.alpha,l))}case"hwb":{const a=n,o=c;return s.hwba(b(a.h,o.h,l),r(a.w,o.w,l),r(a.b,o.b,l),r(a.alpha,o.alpha,l))}case"lab":{const a=n,o=c;return s.laba(r(a.l,o.l,l),r(a.a,o.a,l),r(a.b,o.b,l),r(a.alpha,o.alpha,l))}case"lch":{const a=n,o=c;return s.lcha(r(a.l,o.l,l),r(a.c,o.c,l),b(a.h,o.h,l),r(a.alpha,o.alpha,l))}case"oklab":{const a=n,o=c;return s.oklaba(r(a.l,o.l,l),r(a.a,o.a,l),r(a.b,o.b,l),r(a.alpha,o.alpha,l))}case"oklch":{const a=n,o=c;return s.oklcha(r(a.l,o.l,l),r(a.c,o.c,l),b(a.h,o.h,l),r(a.alpha,o.alpha,l))}}},u=(e,t,l=.5,h="oklch")=>i(e,t,l,h),g=(e,t,l,h="oklch")=>{if(l<2)return[u(e,t,.5,h)];const n=[];for(let c=0;c<l;c++){const a=c/(l-1);n.push(u(e,t,a,h))}return n};exports.interpolateColors=g;exports.mixColors=u;
package/color-mix.d.ts ADDED
@@ -0,0 +1,50 @@
1
+ import { Color, ColorSpace } from './color';
2
+ /**
3
+ * Blends two colors together in the specified color space.
4
+ *
5
+ * Converts both colors to the target space, linearly
6
+ * interpolates each channel (using shortest-path hue
7
+ * interpolation for polar spaces), and returns the result
8
+ * in the target space.
9
+ *
10
+ * @param a - The first color.
11
+ * @param b - The second color.
12
+ * @param t - The blend factor (0 = fully `a`, 1 = fully `b`).
13
+ * Defaults to 0.5.
14
+ * @param space - The color space to blend in.
15
+ * Defaults to `'oklch'`.
16
+ * @returns The blended color in the specified space.
17
+ * @public
18
+ * @example
19
+ * ```ts
20
+ * import { rgb8a } from './color'
21
+ * mixColors(rgb8a(255, 0, 0), rgb8a(0, 0, 255))
22
+ * // blended in oklch at t=0.5
23
+ * mixColors(rgb8a(255, 0, 0), rgb8a(0, 0, 255), 0.25, 'lab')
24
+ * // 25% blend in LAB space
25
+ * ```
26
+ */
27
+ export declare const mixColors: (a: Color, b: Color, t?: number, space?: ColorSpace) => Color;
28
+ /**
29
+ * Generates an array of evenly spaced colors between two
30
+ * endpoints (inclusive).
31
+ *
32
+ * If `steps` is less than 2, returns a single-element array
33
+ * containing the midpoint blend of `a` and `b`.
34
+ *
35
+ * @param a - The start color.
36
+ * @param b - The end color.
37
+ * @param steps - The number of colors to generate (inclusive
38
+ * of both endpoints).
39
+ * @param space - The color space to interpolate in.
40
+ * Defaults to `'oklch'`.
41
+ * @returns An array of interpolated colors.
42
+ * @public
43
+ * @example
44
+ * ```ts
45
+ * import { rgb8a } from './color'
46
+ * interpolateColors(rgb8a(255, 0, 0), rgb8a(0, 0, 255), 5)
47
+ * // [red, ..., blue] — 5 evenly spaced colors in oklch
48
+ * ```
49
+ */
50
+ export declare const interpolateColors: (a: Color, b: Color, steps: number, space?: ColorSpace) => Color[];
package/color-mix.js ADDED
@@ -0,0 +1,101 @@
1
+ import { m as b, R as u, O as x, L as i, I as g, w as y, s as m, o as k, a4 as w, af as f } from "./color-SZxckS9U.js";
2
+ import { interpolate as v, interpolateAngle as d } from "./number.js";
3
+ const l = v, p = d, C = (h, e, s, n) => {
4
+ const c = b(h, n), r = b(e, n);
5
+ switch (n) {
6
+ case "rgb": {
7
+ const a = c, o = r;
8
+ return f(
9
+ l(a.r, o.r, s),
10
+ l(a.g, o.g, s),
11
+ l(a.b, o.b, s),
12
+ l(a.alpha, o.alpha, s)
13
+ );
14
+ }
15
+ case "rgb8": {
16
+ const a = c, o = r;
17
+ return w(
18
+ Math.round(l(a.r, o.r, s)),
19
+ Math.round(l(a.g, o.g, s)),
20
+ Math.round(l(a.b, o.b, s)),
21
+ l(a.alpha, o.alpha, s)
22
+ );
23
+ }
24
+ case "hsl": {
25
+ const a = c, o = r;
26
+ return k(
27
+ p(a.h, o.h, s),
28
+ l(a.s, o.s, s),
29
+ l(a.l, o.l, s),
30
+ l(a.alpha, o.alpha, s)
31
+ );
32
+ }
33
+ case "hsv": {
34
+ const a = c, o = r;
35
+ return m(
36
+ p(a.h, o.h, s),
37
+ l(a.s, o.s, s),
38
+ l(a.v, o.v, s),
39
+ l(a.alpha, o.alpha, s)
40
+ );
41
+ }
42
+ case "hwb": {
43
+ const a = c, o = r;
44
+ return y(
45
+ p(a.h, o.h, s),
46
+ l(a.w, o.w, s),
47
+ l(a.b, o.b, s),
48
+ l(a.alpha, o.alpha, s)
49
+ );
50
+ }
51
+ case "lab": {
52
+ const a = c, o = r;
53
+ return g(
54
+ l(a.l, o.l, s),
55
+ l(a.a, o.a, s),
56
+ l(a.b, o.b, s),
57
+ l(a.alpha, o.alpha, s)
58
+ );
59
+ }
60
+ case "lch": {
61
+ const a = c, o = r;
62
+ return i(
63
+ l(a.l, o.l, s),
64
+ l(a.c, o.c, s),
65
+ p(a.h, o.h, s),
66
+ l(a.alpha, o.alpha, s)
67
+ );
68
+ }
69
+ case "oklab": {
70
+ const a = c, o = r;
71
+ return x(
72
+ l(a.l, o.l, s),
73
+ l(a.a, o.a, s),
74
+ l(a.b, o.b, s),
75
+ l(a.alpha, o.alpha, s)
76
+ );
77
+ }
78
+ case "oklch": {
79
+ const a = c, o = r;
80
+ return u(
81
+ l(a.l, o.l, s),
82
+ l(a.c, o.c, s),
83
+ p(a.h, o.h, s),
84
+ l(a.alpha, o.alpha, s)
85
+ );
86
+ }
87
+ }
88
+ }, t = (h, e, s = 0.5, n = "oklch") => C(h, e, s, n), A = (h, e, s, n = "oklch") => {
89
+ if (s < 2)
90
+ return [t(h, e, 0.5, n)];
91
+ const c = [];
92
+ for (let r = 0; r < s; r++) {
93
+ const a = r / (s - 1);
94
+ c.push(t(h, e, a, n));
95
+ }
96
+ return c;
97
+ };
98
+ export {
99
+ A as interpolateColors,
100
+ t as mixColors
101
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]};exports.NAMED_COLORS=e;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * CSS named colors map.
3
+ *
4
+ * Contains all 148 CSS named colors as lowercase keys mapped to `[r, g, b]` tuples.
5
+ *
6
+ * @public
7
+ */
8
+ export declare const NAMED_COLORS: Record<string, readonly [number, number, number]>;