@thi.ng/color 4.1.5 → 5.0.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/CHANGELOG.md +31 -1
- package/README.md +3 -3
- package/analog.d.ts +15 -15
- package/analog.js +16 -15
- package/api/constants.d.ts +1 -1
- package/api/constants.js +1 -1
- package/api/system.d.ts +1 -1
- package/api/system.js +1 -1
- package/api.d.ts +13 -6
- package/color-range.d.ts +6 -6
- package/color-range.js +6 -6
- package/convert.d.ts +1 -1
- package/convert.js +1 -1
- package/cosine-gradients.d.ts +5 -5
- package/cosine-gradients.js +5 -5
- package/css/parse-css.d.ts +1 -1
- package/css/parse-css.js +1 -1
- package/defcolor.js +5 -1
- package/distance.d.ts +17 -17
- package/distance.js +17 -17
- package/gradients.d.ts +2 -2
- package/gradients.js +2 -2
- package/hcy/hcy.js +5 -1
- package/hsi/hsi.js +5 -1
- package/hsl/hsl.js +10 -1
- package/hsv/hsv.js +10 -1
- package/index.d.ts +8 -0
- package/index.js +8 -0
- package/int/int-int.d.ts +1 -1
- package/int/int-int.js +1 -1
- package/internal/dispatch.d.ts +4 -0
- package/internal/dispatch.js +2 -0
- package/invert.d.ts +8 -1
- package/invert.js +34 -1
- package/is-black.d.ts +1 -1
- package/is-black.js +10 -7
- package/is-gamut.d.ts +9 -0
- package/is-gamut.js +16 -0
- package/is-gray.d.ts +1 -1
- package/is-gray.js +10 -8
- package/is-white.d.ts +1 -1
- package/is-white.js +9 -6
- package/lab/lab-css.d.ts +1 -1
- package/lab/lab-css.js +1 -1
- package/lab/lab-rgb.d.ts +4 -4
- package/lab/lab-rgb.js +4 -4
- package/lab/lab-xyz.d.ts +5 -5
- package/lab/lab-xyz.js +5 -5
- package/lch/lch-css.d.ts +1 -1
- package/lch/lch-css.js +1 -1
- package/lch/lch.js +1 -0
- package/lighten.d.ts +11 -0
- package/lighten.js +21 -0
- package/luminance-rgb.d.ts +2 -2
- package/luminance-rgb.js +2 -2
- package/luminance.d.ts +2 -2
- package/luminance.js +3 -2
- package/max-chroma.d.ts +8 -0
- package/max-chroma.js +240 -0
- package/mix.d.ts +8 -8
- package/mix.js +9 -8
- package/oklab/oklab-rgb.d.ts +2 -2
- package/oklab/oklab-rgb.js +2 -2
- package/package.json +41 -19
- package/rgb/rgb-lab.d.ts +4 -4
- package/rgb/rgb-lab.js +4 -4
- package/rgb/rgb-oklab.d.ts +2 -2
- package/rgb/rgb-oklab.js +2 -2
- package/rgb/rgb-xyz.d.ts +2 -2
- package/rgb/rgb-xyz.js +2 -2
- package/rgb/rgb-ycc.d.ts +3 -3
- package/rgb/rgb-ycc.js +3 -3
- package/rotate.d.ts +4 -0
- package/rotate.js +10 -0
- package/sort.d.ts +7 -7
- package/sort.js +7 -7
- package/strategies.d.ts +90 -0
- package/strategies.js +122 -0
- package/tint.d.ts +6 -0
- package/tint.js +11 -0
- package/transform.d.ts +11 -11
- package/transform.js +11 -11
- package/variations.d.ts +29 -0
- package/variations.js +14 -0
- package/xyy/xyy-xyz.d.ts +2 -2
- package/xyy/xyy-xyz.js +2 -2
- package/xyz/wavelength-xyz.d.ts +3 -3
- package/xyz/wavelength-xyz.js +3 -3
- package/xyz/xyz-lab.d.ts +5 -5
- package/xyz/xyz-lab.js +5 -5
- package/xyz/xyz-rgb.d.ts +2 -2
- package/xyz/xyz-rgb.js +2 -2
- package/xyz/xyz-xyy.d.ts +2 -2
- package/xyz/xyz-xyy.js +2 -2
- package/ycc/ycc-rgb.d.ts +3 -3
- package/ycc/ycc-rgb.js +3 -3
package/max-chroma.js
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { clamp01 } from "@thi.ng/math/interval";
|
|
2
|
+
import { mix, mixBilinear } from "@thi.ng/math/mix";
|
|
3
|
+
import { fract } from "@thi.ng/math/prec";
|
|
4
|
+
import { lch } from "./lch/lch.js";
|
|
5
|
+
// LUT generated via tools/max-chroma.ts
|
|
6
|
+
/** @internal */
|
|
7
|
+
const MAX_CHROMA = [
|
|
8
|
+
[
|
|
9
|
+
4, 22, 30, 34, 38, 43, 47, 52, 56, 61, 66, 70, 75, 80, 84, 74, 65, 56,
|
|
10
|
+
47, 39, 32, 25, 18, 11, 5,
|
|
11
|
+
],
|
|
12
|
+
[
|
|
13
|
+
4, 22, 30, 34, 39, 43, 48, 52, 57, 61, 66, 71, 75, 80, 82, 72, 63, 54,
|
|
14
|
+
46, 38, 31, 24, 17, 10, 5,
|
|
15
|
+
],
|
|
16
|
+
[
|
|
17
|
+
4, 22, 31, 35, 39, 44, 49, 53, 58, 63, 67, 72, 77, 82, 83, 73, 63, 54,
|
|
18
|
+
46, 38, 31, 24, 17, 10, 5,
|
|
19
|
+
],
|
|
20
|
+
[
|
|
21
|
+
3, 20, 32, 37, 41, 46, 51, 55, 60, 65, 70, 75, 80, 85, 85, 74, 65, 55,
|
|
22
|
+
47, 39, 31, 24, 17, 10, 5,
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
2, 15, 27, 39, 44, 49, 54, 59, 64, 69, 75, 80, 85, 90, 89, 78, 67, 57,
|
|
26
|
+
48, 40, 32, 25, 18, 10, 5,
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
2, 11, 22, 32, 43, 53, 59, 64, 70, 76, 81, 87, 93, 99, 96, 84, 72, 61,
|
|
30
|
+
51, 42, 34, 26, 19, 11, 5,
|
|
31
|
+
],
|
|
32
|
+
[
|
|
33
|
+
1, 10, 19, 27, 36, 44, 52, 59, 66, 72, 77, 83, 88, 93, 98, 92, 79, 67,
|
|
34
|
+
56, 45, 36, 28, 20, 12, 6,
|
|
35
|
+
],
|
|
36
|
+
[
|
|
37
|
+
1, 9, 17, 24, 31, 38, 45, 51, 57, 61, 66, 70, 75, 79, 84, 88, 90, 75,
|
|
38
|
+
62, 51, 40, 30, 22, 13, 6,
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
1, 8, 15, 22, 28, 35, 40, 46, 50, 54, 58, 62, 66, 70, 74, 78, 82, 86,
|
|
42
|
+
73, 59, 46, 35, 24, 15, 7,
|
|
43
|
+
],
|
|
44
|
+
[
|
|
45
|
+
1, 7, 13, 20, 26, 32, 37, 42, 46, 50, 53, 57, 61, 64, 68, 72, 75, 79,
|
|
46
|
+
83, 72, 55, 41, 29, 18, 8,
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
1, 7, 12, 19, 25, 30, 35, 40, 43, 47, 50, 54, 57, 60, 64, 67, 71, 74,
|
|
50
|
+
78, 81, 73, 53, 36, 22, 10,
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
1, 7, 12, 19, 24, 29, 34, 38, 42, 45, 48, 51, 55, 58, 61, 65, 68, 71,
|
|
54
|
+
75, 78, 82, 79, 50, 29, 12,
|
|
55
|
+
],
|
|
56
|
+
[
|
|
57
|
+
1, 7, 12, 19, 24, 29, 33, 37, 41, 44, 47, 50, 54, 57, 60, 63, 67, 70,
|
|
58
|
+
73, 77, 80, 83, 86, 48, 19,
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
1, 7, 12, 19, 24, 29, 33, 37, 41, 44, 47, 50, 53, 57, 60, 63, 66, 70,
|
|
62
|
+
73, 76, 80, 83, 86, 90, 45,
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
1, 7, 12, 19, 25, 30, 34, 38, 41, 44, 48, 51, 54, 58, 61, 64, 67, 71,
|
|
66
|
+
74, 78, 81, 84, 88, 91, 94,
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
1, 7, 13, 20, 26, 31, 35, 39, 43, 46, 49, 53, 56, 60, 63, 66, 70, 73,
|
|
70
|
+
77, 80, 84, 87, 91, 94, 60,
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
1, 8, 15, 21, 27, 33, 37, 42, 45, 49, 52, 56, 59, 63, 66, 70, 74, 77,
|
|
74
|
+
81, 85, 88, 92, 96, 96, 44,
|
|
75
|
+
],
|
|
76
|
+
[
|
|
77
|
+
1, 9, 16, 23, 29, 35, 40, 45, 49, 52, 56, 60, 64, 68, 72, 76, 80, 84,
|
|
78
|
+
87, 91, 95, 99, 103, 77, 35,
|
|
79
|
+
],
|
|
80
|
+
[
|
|
81
|
+
1, 10, 18, 26, 33, 39, 44, 48, 52, 56, 60, 65, 69, 73, 77, 82, 86, 90,
|
|
82
|
+
94, 99, 103, 107, 110, 65, 30,
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
2, 10, 21, 28, 30, 34, 37, 40, 44, 47, 51, 55, 58, 62, 65, 69, 73, 76,
|
|
86
|
+
80, 83, 87, 91, 94, 58, 26,
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
1, 10, 18, 24, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 60, 63, 66,
|
|
90
|
+
69, 72, 75, 78, 81, 52, 24,
|
|
91
|
+
],
|
|
92
|
+
[
|
|
93
|
+
1, 8, 15, 21, 23, 26, 28, 31, 33, 36, 39, 42, 44, 47, 50, 53, 55, 58,
|
|
94
|
+
61, 64, 66, 69, 72, 48, 22,
|
|
95
|
+
],
|
|
96
|
+
[
|
|
97
|
+
1, 7, 13, 19, 21, 23, 25, 28, 30, 33, 35, 37, 40, 42, 45, 47, 50, 52,
|
|
98
|
+
55, 57, 60, 62, 65, 46, 21,
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
1, 7, 12, 17, 19, 21, 23, 25, 28, 30, 32, 34, 37, 39, 41, 44, 46, 48,
|
|
102
|
+
50, 53, 55, 57, 60, 44, 20,
|
|
103
|
+
],
|
|
104
|
+
[
|
|
105
|
+
1, 6, 11, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 39, 41, 43, 45,
|
|
106
|
+
47, 49, 51, 54, 56, 43, 19,
|
|
107
|
+
],
|
|
108
|
+
[
|
|
109
|
+
1, 6, 11, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43,
|
|
110
|
+
45, 47, 49, 51, 53, 43, 19,
|
|
111
|
+
],
|
|
112
|
+
[
|
|
113
|
+
1, 6, 10, 15, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 35, 37, 39, 41,
|
|
114
|
+
43, 45, 47, 49, 51, 43, 20,
|
|
115
|
+
],
|
|
116
|
+
[
|
|
117
|
+
1, 6, 10, 13, 16, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41,
|
|
118
|
+
43, 45, 46, 48, 49, 33, 16,
|
|
119
|
+
],
|
|
120
|
+
[
|
|
121
|
+
1, 6, 10, 13, 16, 18, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41,
|
|
122
|
+
42, 44, 46, 48, 37, 25, 11,
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
1, 7, 11, 13, 16, 18, 20, 22, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41,
|
|
126
|
+
43, 45, 47, 40, 30, 20, 10,
|
|
127
|
+
],
|
|
128
|
+
[
|
|
129
|
+
1, 7, 11, 15, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42,
|
|
130
|
+
44, 46, 43, 34, 26, 17, 8,
|
|
131
|
+
],
|
|
132
|
+
[
|
|
133
|
+
1, 7, 12, 15, 17, 19, 21, 23, 25, 27, 29, 31, 34, 36, 38, 40, 42, 44,
|
|
134
|
+
46, 46, 38, 31, 23, 15, 7,
|
|
135
|
+
],
|
|
136
|
+
[
|
|
137
|
+
1, 8, 13, 16, 18, 20, 22, 25, 27, 29, 31, 33, 36, 38, 40, 42, 45, 47,
|
|
138
|
+
49, 42, 35, 28, 21, 13, 7,
|
|
139
|
+
],
|
|
140
|
+
[
|
|
141
|
+
1, 10, 15, 18, 20, 22, 24, 27, 29, 31, 34, 36, 39, 41, 43, 46, 48, 51,
|
|
142
|
+
46, 40, 33, 26, 19, 12, 6,
|
|
143
|
+
],
|
|
144
|
+
[
|
|
145
|
+
2, 10, 17, 19, 22, 24, 27, 29, 32, 35, 37, 40, 43, 45, 48, 51, 53, 51,
|
|
146
|
+
44, 38, 31, 25, 18, 11, 6,
|
|
147
|
+
],
|
|
148
|
+
[
|
|
149
|
+
2, 13, 19, 22, 25, 28, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 56, 49,
|
|
150
|
+
43, 37, 30, 24, 18, 11, 6,
|
|
151
|
+
],
|
|
152
|
+
[
|
|
153
|
+
3, 17, 22, 26, 29, 32, 36, 39, 42, 46, 49, 53, 56, 60, 63, 62, 55, 49,
|
|
154
|
+
43, 36, 30, 24, 18, 11, 6,
|
|
155
|
+
],
|
|
156
|
+
[
|
|
157
|
+
6, 23, 27, 31, 35, 39, 43, 47, 51, 56, 60, 64, 68, 73, 69, 62, 56, 49,
|
|
158
|
+
43, 36, 30, 24, 18, 11, 6,
|
|
159
|
+
],
|
|
160
|
+
[
|
|
161
|
+
18, 30, 34, 39, 44, 49, 54, 60, 65, 70, 76, 81, 84, 77, 70, 64, 57, 50,
|
|
162
|
+
44, 37, 31, 25, 18, 11, 6,
|
|
163
|
+
],
|
|
164
|
+
[
|
|
165
|
+
12, 41, 45, 52, 59, 66, 73, 80, 87, 94, 102, 95, 88, 81, 74, 66, 60, 53,
|
|
166
|
+
46, 39, 32, 26, 19, 11, 6,
|
|
167
|
+
],
|
|
168
|
+
[
|
|
169
|
+
9, 58, 65, 75, 85, 96, 106, 117, 124, 116, 109, 101, 93, 86, 78, 71, 63,
|
|
170
|
+
56, 49, 42, 34, 27, 20, 12, 6,
|
|
171
|
+
],
|
|
172
|
+
[
|
|
173
|
+
7, 42, 58, 66, 74, 82, 91, 99, 108, 117, 119, 110, 102, 94, 85, 77, 69,
|
|
174
|
+
61, 53, 45, 37, 30, 22, 13, 7,
|
|
175
|
+
],
|
|
176
|
+
[
|
|
177
|
+
6, 34, 47, 53, 60, 67, 74, 81, 88, 95, 102, 109, 114, 105, 95, 86, 77,
|
|
178
|
+
68, 59, 51, 42, 33, 25, 16, 8,
|
|
179
|
+
],
|
|
180
|
+
[
|
|
181
|
+
5, 29, 40, 46, 52, 57, 63, 70, 76, 82, 88, 94, 100, 107, 110, 100, 89,
|
|
182
|
+
79, 69, 58, 48, 38, 29, 19, 9,
|
|
183
|
+
],
|
|
184
|
+
[
|
|
185
|
+
4, 26, 36, 41, 46, 52, 57, 62, 68, 73, 79, 85, 90, 96, 101, 104, 91, 79,
|
|
186
|
+
67, 56, 45, 35, 26, 17, 8,
|
|
187
|
+
],
|
|
188
|
+
[
|
|
189
|
+
4, 24, 34, 38, 43, 48, 53, 58, 63, 68, 73, 78, 83, 88, 94, 91, 79, 69,
|
|
190
|
+
59, 49, 40, 31, 23, 15, 7,
|
|
191
|
+
],
|
|
192
|
+
[
|
|
193
|
+
4, 23, 32, 36, 40, 45, 50, 55, 59, 64, 69, 74, 79, 84, 89, 82, 72, 62,
|
|
194
|
+
53, 44, 36, 28, 20, 12, 6,
|
|
195
|
+
],
|
|
196
|
+
[
|
|
197
|
+
4, 22, 31, 35, 39, 44, 48, 53, 57, 62, 67, 71, 76, 81, 86, 77, 67, 58,
|
|
198
|
+
50, 41, 33, 26, 19, 11, 6,
|
|
199
|
+
],
|
|
200
|
+
];
|
|
201
|
+
const RES_H = MAX_CHROMA.length;
|
|
202
|
+
const RES_L = MAX_CHROMA[0].length;
|
|
203
|
+
export const maxChroma = (l, h) => {
|
|
204
|
+
h = fract(h);
|
|
205
|
+
l = clamp01(l);
|
|
206
|
+
if (l < 1) {
|
|
207
|
+
const h1 = (h * RES_H) | 0;
|
|
208
|
+
const l1 = (l * RES_L) | 0;
|
|
209
|
+
const lutH1 = MAX_CHROMA[h1];
|
|
210
|
+
const lutH2 = MAX_CHROMA[(h1 + 1) % RES_H];
|
|
211
|
+
return (mixBilinear(lutH1[l1], lutH2[l1], l1 < RES_L - 1 ? lutH1[l1 + 1] : 0, l1 < RES_L - 1 ? lutH2[l1 + 1] : 0, h * RES_H - h1, l * RES_L - l1) * 0.01);
|
|
212
|
+
}
|
|
213
|
+
return 0;
|
|
214
|
+
};
|
|
215
|
+
export const lchMaxChroma = (l, h, a = 1) => lch(l, maxChroma(l, h), h, a);
|
|
216
|
+
export const maxLumaChroma = (h) => {
|
|
217
|
+
const h1 = (fract(h) * RES_H) | 0;
|
|
218
|
+
const t = h * RES_H - h1;
|
|
219
|
+
const [l1, c1] = __maxLC(MAX_CHROMA[h1]);
|
|
220
|
+
const [l2, c2] = __maxLC(MAX_CHROMA[(h1 + 1) % RES_H]);
|
|
221
|
+
return { l: mix(l1, l2, t) / RES_L, c: mix(c1, c2, t) * 0.01 };
|
|
222
|
+
};
|
|
223
|
+
export const lchMaxLumaChroma = (h, a = 1) => {
|
|
224
|
+
const max = maxLumaChroma(h);
|
|
225
|
+
return lch(max.l, max.c, h, a);
|
|
226
|
+
};
|
|
227
|
+
/** @internal */
|
|
228
|
+
const __maxLC = (chroma) => {
|
|
229
|
+
let maxL = 0;
|
|
230
|
+
let maxC = 0;
|
|
231
|
+
for (let i = RES_L; i-- > 0;) {
|
|
232
|
+
if (chroma[i] >= maxC) {
|
|
233
|
+
maxC = chroma[i];
|
|
234
|
+
maxL = i;
|
|
235
|
+
}
|
|
236
|
+
else
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
return [maxL, maxC];
|
|
240
|
+
};
|
package/mix.d.ts
CHANGED
|
@@ -4,10 +4,10 @@ import type { ColorMixFn, TypedColor } from "./api.js";
|
|
|
4
4
|
* HOF color mix function. Takes 4 scalar mix fns (one per color channel) and
|
|
5
5
|
* returns new {@link ColorMixFn}.
|
|
6
6
|
*
|
|
7
|
-
* @param x
|
|
8
|
-
* @param y
|
|
9
|
-
* @param z
|
|
10
|
-
* @param alpha
|
|
7
|
+
* @param x -
|
|
8
|
+
* @param y -
|
|
9
|
+
* @param z -
|
|
10
|
+
* @param alpha -
|
|
11
11
|
*/
|
|
12
12
|
export declare const defMix: FnU4<FnN3, ColorMixFn>;
|
|
13
13
|
/**
|
|
@@ -22,9 +22,9 @@ export declare const mixH: FnN3;
|
|
|
22
22
|
/**
|
|
23
23
|
* Single channel linear interpolation function.
|
|
24
24
|
*
|
|
25
|
-
* @param a
|
|
26
|
-
* @param b
|
|
27
|
-
* @param t
|
|
25
|
+
* @param a -
|
|
26
|
+
* @param b -
|
|
27
|
+
* @param t -
|
|
28
28
|
*/
|
|
29
29
|
export declare const mixN: FnN3;
|
|
30
30
|
export declare const mixHNNN: ColorMixFn<import("@thi.ng/vectors").ReadonlyVec>;
|
|
@@ -67,5 +67,5 @@ export declare const mixNNNN: ColorMixFn;
|
|
|
67
67
|
* @param b -
|
|
68
68
|
* @param t -
|
|
69
69
|
*/
|
|
70
|
-
export declare const mix: import("@thi.ng/defmulti
|
|
70
|
+
export declare const mix: import("@thi.ng/defmulti").MultiFn4<import("@thi.ng/vectors").Vec | null, TypedColor<any>, TypedColor<any>, number, import("@thi.ng/vectors").Vec>;
|
|
71
71
|
//# sourceMappingURL=mix.d.ts.map
|
package/mix.js
CHANGED
|
@@ -3,14 +3,15 @@ import { mix as $mix } from "@thi.ng/math/mix";
|
|
|
3
3
|
import { fract } from "@thi.ng/math/prec";
|
|
4
4
|
import { mixN4 } from "@thi.ng/vectors/mixn";
|
|
5
5
|
import { setC4 } from "@thi.ng/vectors/setc";
|
|
6
|
+
import { __dispatch1 } from "./internal/dispatch.js";
|
|
6
7
|
/**
|
|
7
8
|
* HOF color mix function. Takes 4 scalar mix fns (one per color channel) and
|
|
8
9
|
* returns new {@link ColorMixFn}.
|
|
9
10
|
*
|
|
10
|
-
* @param x
|
|
11
|
-
* @param y
|
|
12
|
-
* @param z
|
|
13
|
-
* @param alpha
|
|
11
|
+
* @param x -
|
|
12
|
+
* @param y -
|
|
13
|
+
* @param z -
|
|
14
|
+
* @param alpha -
|
|
14
15
|
*/
|
|
15
16
|
export const defMix = (x, y, z, alpha) => (out, a, b, t) => setC4(out || a, x(a[0], b[0], t), y(a[1], b[1], t), z(a[2], b[2], t), alpha(a[3], b[3], t));
|
|
16
17
|
/**
|
|
@@ -36,9 +37,9 @@ export const mixH = (a, b, t) => {
|
|
|
36
37
|
/**
|
|
37
38
|
* Single channel linear interpolation function.
|
|
38
39
|
*
|
|
39
|
-
* @param a
|
|
40
|
-
* @param b
|
|
41
|
-
* @param t
|
|
40
|
+
* @param a -
|
|
41
|
+
* @param b -
|
|
42
|
+
* @param t -
|
|
42
43
|
*/
|
|
43
44
|
export const mixN = $mix;
|
|
44
45
|
export const mixHNNN = defMix(mixH, mixN, mixN, mixN);
|
|
@@ -81,7 +82,7 @@ export const mixNNNN = mixN4;
|
|
|
81
82
|
* @param b -
|
|
82
83
|
* @param t -
|
|
83
84
|
*/
|
|
84
|
-
export const mix = defmulti(
|
|
85
|
+
export const mix = defmulti(__dispatch1, {}, {
|
|
85
86
|
hcy: mixHNNN,
|
|
86
87
|
hsi: mixHNNN,
|
|
87
88
|
hsl: mixHNNN,
|
package/oklab/oklab-rgb.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import type { ColorOp } from "../api.js";
|
|
|
3
3
|
* @remarks
|
|
4
4
|
* Reference: https://bottosson.github.io/posts/oklab/
|
|
5
5
|
*
|
|
6
|
-
* @param out
|
|
7
|
-
* @param src
|
|
6
|
+
* @param out -
|
|
7
|
+
* @param src -
|
|
8
8
|
*/
|
|
9
9
|
export declare const oklabRgb: ColorOp;
|
|
10
10
|
//# sourceMappingURL=oklab-rgb.d.ts.map
|
package/oklab/oklab-rgb.js
CHANGED
|
@@ -7,8 +7,8 @@ const LMS_CONE = [
|
|
|
7
7
|
* @remarks
|
|
8
8
|
* Reference: https://bottosson.github.io/posts/oklab/
|
|
9
9
|
*
|
|
10
|
-
* @param out
|
|
11
|
-
* @param src
|
|
10
|
+
* @param out -
|
|
11
|
+
* @param src -
|
|
12
12
|
*/
|
|
13
13
|
export const oklabRgb = (out, { 0: l, 1: a, 2: b, 3: alpha }) => __mulV33(out, LMS_CONE, [
|
|
14
14
|
(l + 0.3963377774 * a + 0.2158037573 * b) ** 3,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/color",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Array-based color types, CSS parsing, conversions, transformations, declarative theme generation, gradients, presets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -32,30 +32,31 @@
|
|
|
32
32
|
"doc:stats": "tools:module-stats",
|
|
33
33
|
"pub": "yarn npm publish --access public",
|
|
34
34
|
"test": "testament test",
|
|
35
|
+
"tool:maxchroma": "tools:node-esm tools/max-chroma.ts",
|
|
35
36
|
"tool:swatches": "tools:node-esm tools/index.ts"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@thi.ng/api": "^8.3.
|
|
39
|
-
"@thi.ng/arrays": "^2.
|
|
40
|
-
"@thi.ng/binary": "^3.
|
|
41
|
-
"@thi.ng/checks": "^3.1.
|
|
42
|
-
"@thi.ng/compare": "^2.1.
|
|
43
|
-
"@thi.ng/compose": "^2.1.
|
|
44
|
-
"@thi.ng/defmulti": "^2.1.
|
|
45
|
-
"@thi.ng/errors": "^2.1.
|
|
46
|
-
"@thi.ng/math": "^5.
|
|
47
|
-
"@thi.ng/random": "^3.2.
|
|
48
|
-
"@thi.ng/strings": "^3.3.
|
|
49
|
-
"@thi.ng/transducers": "^8.
|
|
50
|
-
"@thi.ng/vectors": "^7.
|
|
39
|
+
"@thi.ng/api": "^8.3.4",
|
|
40
|
+
"@thi.ng/arrays": "^2.2.0",
|
|
41
|
+
"@thi.ng/binary": "^3.2.0",
|
|
42
|
+
"@thi.ng/checks": "^3.1.4",
|
|
43
|
+
"@thi.ng/compare": "^2.1.4",
|
|
44
|
+
"@thi.ng/compose": "^2.1.4",
|
|
45
|
+
"@thi.ng/defmulti": "^2.1.4",
|
|
46
|
+
"@thi.ng/errors": "^2.1.4",
|
|
47
|
+
"@thi.ng/math": "^5.3.0",
|
|
48
|
+
"@thi.ng/random": "^3.2.4",
|
|
49
|
+
"@thi.ng/strings": "^3.3.2",
|
|
50
|
+
"@thi.ng/transducers": "^8.3.0",
|
|
51
|
+
"@thi.ng/vectors": "^7.5.0"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
|
-
"@microsoft/api-extractor": "^7.
|
|
54
|
-
"@thi.ng/testament": "^0.2.
|
|
54
|
+
"@microsoft/api-extractor": "^7.19.4",
|
|
55
|
+
"@thi.ng/testament": "^0.2.4",
|
|
55
56
|
"rimraf": "^3.0.2",
|
|
56
57
|
"tools": "^0.0.1",
|
|
57
|
-
"typedoc": "^0.22.
|
|
58
|
-
"typescript": "^4.
|
|
58
|
+
"typedoc": "^0.22.13",
|
|
59
|
+
"typescript": "^4.6.2"
|
|
59
60
|
},
|
|
60
61
|
"keywords": [
|
|
61
62
|
"color",
|
|
@@ -239,6 +240,9 @@
|
|
|
239
240
|
"./is-black": {
|
|
240
241
|
"import": "./is-black.js"
|
|
241
242
|
},
|
|
243
|
+
"./is-gamut": {
|
|
244
|
+
"import": "./is-gamut.js"
|
|
245
|
+
},
|
|
242
246
|
"./is-gray": {
|
|
243
247
|
"import": "./is-gray.js"
|
|
244
248
|
},
|
|
@@ -272,6 +276,9 @@
|
|
|
272
276
|
"./lch/lch": {
|
|
273
277
|
"import": "./lch/lch.js"
|
|
274
278
|
},
|
|
279
|
+
"./lighten": {
|
|
280
|
+
"import": "./lighten.js"
|
|
281
|
+
},
|
|
275
282
|
"./linear": {
|
|
276
283
|
"import": "./linear.js"
|
|
277
284
|
},
|
|
@@ -281,6 +288,9 @@
|
|
|
281
288
|
"./luminance": {
|
|
282
289
|
"import": "./luminance.js"
|
|
283
290
|
},
|
|
291
|
+
"./max-chroma": {
|
|
292
|
+
"import": "./max-chroma.js"
|
|
293
|
+
},
|
|
284
294
|
"./mix": {
|
|
285
295
|
"import": "./mix.js"
|
|
286
296
|
},
|
|
@@ -335,6 +345,9 @@
|
|
|
335
345
|
"./rgb/rgb": {
|
|
336
346
|
"import": "./rgb/rgb.js"
|
|
337
347
|
},
|
|
348
|
+
"./rotate": {
|
|
349
|
+
"import": "./rotate.js"
|
|
350
|
+
},
|
|
338
351
|
"./sort": {
|
|
339
352
|
"import": "./sort.js"
|
|
340
353
|
},
|
|
@@ -350,12 +363,21 @@
|
|
|
350
363
|
"./srgb/srgb": {
|
|
351
364
|
"import": "./srgb/srgb.js"
|
|
352
365
|
},
|
|
366
|
+
"./strategies": {
|
|
367
|
+
"import": "./strategies.js"
|
|
368
|
+
},
|
|
353
369
|
"./swatches": {
|
|
354
370
|
"import": "./swatches.js"
|
|
355
371
|
},
|
|
372
|
+
"./tint": {
|
|
373
|
+
"import": "./tint.js"
|
|
374
|
+
},
|
|
356
375
|
"./transform": {
|
|
357
376
|
"import": "./transform.js"
|
|
358
377
|
},
|
|
378
|
+
"./variations": {
|
|
379
|
+
"import": "./variations.js"
|
|
380
|
+
},
|
|
359
381
|
"./xyy/xyy-xyz": {
|
|
360
382
|
"import": "./xyy/xyy-xyz.js"
|
|
361
383
|
},
|
|
@@ -399,5 +421,5 @@
|
|
|
399
421
|
"vectors"
|
|
400
422
|
]
|
|
401
423
|
},
|
|
402
|
-
"gitHead": "
|
|
424
|
+
"gitHead": "0fc692a3225c068aacafdc4cb6140cf603c67ad8\n"
|
|
403
425
|
}
|
package/rgb/rgb-lab.d.ts
CHANGED
|
@@ -6,15 +6,15 @@ import type { ColorOp } from "../api.js";
|
|
|
6
6
|
* Important: We're using a normalized Lab space w/ all three coordinates
|
|
7
7
|
* divided by 100 (normalized to 100% luminance).
|
|
8
8
|
*
|
|
9
|
-
* @param out
|
|
10
|
-
* @param src
|
|
9
|
+
* @param out -
|
|
10
|
+
* @param src -
|
|
11
11
|
*/
|
|
12
12
|
export declare const rgbLab: ColorOp;
|
|
13
13
|
/**
|
|
14
14
|
* Same as {@link rgbLab}, but using {@link D65} white point.
|
|
15
15
|
*
|
|
16
|
-
* @param out
|
|
17
|
-
* @param src
|
|
16
|
+
* @param out -
|
|
17
|
+
* @param src -
|
|
18
18
|
*/
|
|
19
19
|
export declare const rgbLabD65: ColorOp;
|
|
20
20
|
//# sourceMappingURL=rgb-lab.d.ts.map
|
package/rgb/rgb-lab.js
CHANGED
|
@@ -7,14 +7,14 @@ import { xyzLab, xyzLabD65 } from "../xyz/xyz-lab.js";
|
|
|
7
7
|
* Important: We're using a normalized Lab space w/ all three coordinates
|
|
8
8
|
* divided by 100 (normalized to 100% luminance).
|
|
9
9
|
*
|
|
10
|
-
* @param out
|
|
11
|
-
* @param src
|
|
10
|
+
* @param out -
|
|
11
|
+
* @param src -
|
|
12
12
|
*/
|
|
13
13
|
export const rgbLab = (out, src) => xyzLab(null, rgbXyz(out, src));
|
|
14
14
|
/**
|
|
15
15
|
* Same as {@link rgbLab}, but using {@link D65} white point.
|
|
16
16
|
*
|
|
17
|
-
* @param out
|
|
18
|
-
* @param src
|
|
17
|
+
* @param out -
|
|
18
|
+
* @param src -
|
|
19
19
|
*/
|
|
20
20
|
export const rgbLabD65 = (out, src) => xyzLabD65(null, rgbXyzD65(out, src));
|
package/rgb/rgb-oklab.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import type { ColorOp } from "../api.js";
|
|
|
3
3
|
* @remarks
|
|
4
4
|
* Reference: https://bottosson.github.io/posts/oklab/
|
|
5
5
|
*
|
|
6
|
-
* @param out
|
|
7
|
-
* @param src
|
|
6
|
+
* @param out -
|
|
7
|
+
* @param src -
|
|
8
8
|
*/
|
|
9
9
|
export declare const rgbOklab: ColorOp;
|
|
10
10
|
//# sourceMappingURL=rgb-oklab.d.ts.map
|
package/rgb/rgb-oklab.js
CHANGED
|
@@ -9,7 +9,7 @@ const CONE_LMS = [
|
|
|
9
9
|
* @remarks
|
|
10
10
|
* Reference: https://bottosson.github.io/posts/oklab/
|
|
11
11
|
*
|
|
12
|
-
* @param out
|
|
13
|
-
* @param src
|
|
12
|
+
* @param out -
|
|
13
|
+
* @param src -
|
|
14
14
|
*/
|
|
15
15
|
export const rgbOklab = (out, src) => __mulV33(null, OKLAB_M2, powN3(null, __mulV33(out, CONE_LMS, src), 1 / 3));
|
package/rgb/rgb-xyz.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ export declare const rgbXyz: (out: Color | null, src: ReadonlyColor, mat?: numbe
|
|
|
14
14
|
* Same as {@link rgbXyz}, but hard coded to use {@link D65} white point (via
|
|
15
15
|
* {@link RGB_XYZ_D65} matrix).
|
|
16
16
|
*
|
|
17
|
-
* @param out
|
|
18
|
-
* @param src
|
|
17
|
+
* @param out -
|
|
18
|
+
* @param src -
|
|
19
19
|
*/
|
|
20
20
|
export declare const rgbXyzD65: ColorOp;
|
|
21
21
|
//# sourceMappingURL=rgb-xyz.d.ts.map
|
package/rgb/rgb-xyz.js
CHANGED
|
@@ -16,7 +16,7 @@ export const rgbXyz = (out, src, mat = RGB_XYZ_D50) => __mulV33(null, mat, clamp
|
|
|
16
16
|
* Same as {@link rgbXyz}, but hard coded to use {@link D65} white point (via
|
|
17
17
|
* {@link RGB_XYZ_D65} matrix).
|
|
18
18
|
*
|
|
19
|
-
* @param out
|
|
20
|
-
* @param src
|
|
19
|
+
* @param out -
|
|
20
|
+
* @param src -
|
|
21
21
|
*/
|
|
22
22
|
export const rgbXyzD65 = (out, src) => rgbXyz(out, src, RGB_XYZ_D65);
|
package/rgb/rgb-ycc.d.ts
CHANGED
|
@@ -9,9 +9,9 @@ import type { Color, ReadonlyColor } from "../api.js";
|
|
|
9
9
|
* - https://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.709_conversion
|
|
10
10
|
* - https://en.wikipedia.org/wiki/Rec._709
|
|
11
11
|
*
|
|
12
|
-
* @param out
|
|
13
|
-
* @param src
|
|
14
|
-
* @param luma
|
|
12
|
+
* @param out -
|
|
13
|
+
* @param src -
|
|
14
|
+
* @param luma -
|
|
15
15
|
*/
|
|
16
16
|
export declare const rgbYcc: (out: Color | null, src: ReadonlyColor, luma?: number[]) => import("@thi.ng/vectors").Vec;
|
|
17
17
|
//# sourceMappingURL=rgb-ycc.d.ts.map
|
package/rgb/rgb-ycc.js
CHANGED
|
@@ -12,9 +12,9 @@ import { __ensureAlpha } from "../internal/ensure.js";
|
|
|
12
12
|
* - https://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.709_conversion
|
|
13
13
|
* - https://en.wikipedia.org/wiki/Rec._709
|
|
14
14
|
*
|
|
15
|
-
* @param out
|
|
16
|
-
* @param src
|
|
17
|
-
* @param luma
|
|
15
|
+
* @param out -
|
|
16
|
+
* @param src -
|
|
17
|
+
* @param luma -
|
|
18
18
|
*/
|
|
19
19
|
export const rgbYcc = (out, src, luma = RGB_LUMINANCE_REC709) => {
|
|
20
20
|
const y = dot3(src, luma);
|
package/rotate.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Color, TypedColor } from "./api.js";
|
|
2
|
+
export declare const rotate: import("@thi.ng/defmulti").MultiFn3<import("@thi.ng/vectors").Vec | null, TypedColor<any>, number, import("@thi.ng/vectors").Vec>;
|
|
3
|
+
export declare const complementary: (out: Color | null, src: TypedColor<any>) => import("@thi.ng/vectors").Vec;
|
|
4
|
+
//# sourceMappingURL=rotate.d.ts.map
|
package/rotate.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
|
+
import { fract } from "@thi.ng/math/prec";
|
|
3
|
+
import { setC4 } from "@thi.ng/vectors/setc";
|
|
4
|
+
import { __dispatch1 } from "./internal/dispatch.js";
|
|
5
|
+
import { __ensureAlpha } from "./internal/ensure.js";
|
|
6
|
+
export const rotate = defmulti(__dispatch1, { hsv: "hsl", hsi: "hsl", hcy: "hsl" }, {
|
|
7
|
+
hsl: (out, src, theta) => setC4(out || src, fract(src[0] + theta), src[1], src[2], __ensureAlpha(src[3])),
|
|
8
|
+
lch: (out, src, theta) => setC4(out || src, src[0], src[1], fract(src[2] + theta), __ensureAlpha(src[3])),
|
|
9
|
+
});
|
|
10
|
+
export const complementary = (out, src) => rotate(out, src, 0.5);
|
package/sort.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export declare const selectChannel: (id: number) => (col: ReadonlyColor) => numb
|
|
|
7
7
|
* function for {@link sort} to compute the distance metric of a color to the
|
|
8
8
|
* given `target`.
|
|
9
9
|
*
|
|
10
|
-
* @param target
|
|
11
|
-
* @param dist
|
|
10
|
+
* @param target -
|
|
11
|
+
* @param dist -
|
|
12
12
|
*/
|
|
13
13
|
export declare const proximity: (target: ReadonlyColor, dist?: ColorDistance) => (col: ReadonlyColor) => number;
|
|
14
14
|
/**
|
|
@@ -17,8 +17,8 @@ export declare const proximity: (target: ReadonlyColor, dist?: ColorDistance) =>
|
|
|
17
17
|
* function (default: {@link distEucledian3}) and will be in sRGB space. Hence
|
|
18
18
|
* given `target` color should be provided in the same space too.
|
|
19
19
|
*
|
|
20
|
-
* @param target
|
|
21
|
-
* @param dist
|
|
20
|
+
* @param target -
|
|
21
|
+
* @param dist -
|
|
22
22
|
*/
|
|
23
23
|
export declare const proximityABGR32: (target: ReadonlyColor, dist?: ColorDistance) => (col: ReadonlyColor) => number;
|
|
24
24
|
export declare const sort: (colors: ReadonlyColor[], key: Fn<ReadonlyColor, number>, isReverse?: boolean) => import("@thi.ng/vectors").ReadonlyVec[];
|
|
@@ -56,9 +56,9 @@ export declare const sort: (colors: ReadonlyColor[], key: Fn<ReadonlyColor, numb
|
|
|
56
56
|
* // ]
|
|
57
57
|
* ```
|
|
58
58
|
*
|
|
59
|
-
* @param colors
|
|
60
|
-
* @param key
|
|
61
|
-
* @param isReverse
|
|
59
|
+
* @param colors -
|
|
60
|
+
* @param key -
|
|
61
|
+
* @param isReverse -
|
|
62
62
|
*/
|
|
63
63
|
export declare const sortMapped: <T extends TypedColor<any>>(colors: T[], key: Fn<ReadonlyColor, number>, isReverse?: boolean) => T[];
|
|
64
64
|
//# sourceMappingURL=sort.d.ts.map
|
package/sort.js
CHANGED
|
@@ -12,8 +12,8 @@ export const selectChannel = (id) => (col) => col[id];
|
|
|
12
12
|
* function for {@link sort} to compute the distance metric of a color to the
|
|
13
13
|
* given `target`.
|
|
14
14
|
*
|
|
15
|
-
* @param target
|
|
16
|
-
* @param dist
|
|
15
|
+
* @param target -
|
|
16
|
+
* @param dist -
|
|
17
17
|
*/
|
|
18
18
|
export const proximity = (target, dist = distEucledian3) => (col) => dist(target, col);
|
|
19
19
|
/**
|
|
@@ -22,8 +22,8 @@ export const proximity = (target, dist = distEucledian3) => (col) => dist(target
|
|
|
22
22
|
* function (default: {@link distEucledian3}) and will be in sRGB space. Hence
|
|
23
23
|
* given `target` color should be provided in the same space too.
|
|
24
24
|
*
|
|
25
|
-
* @param target
|
|
26
|
-
* @param dist
|
|
25
|
+
* @param target -
|
|
26
|
+
* @param dist -
|
|
27
27
|
*/
|
|
28
28
|
export const proximityABGR32 = (target, dist = distEucledian3) => (col) => dist(target, intAbgr32Srgb([], col[0]));
|
|
29
29
|
export const sort = (colors, key, isReverse = false) => sortByCachedKey(colors, key, isReverse ? compareNumDesc : compareNumAsc);
|
|
@@ -61,9 +61,9 @@ export const sort = (colors, key, isReverse = false) => sortByCachedKey(colors,
|
|
|
61
61
|
* // ]
|
|
62
62
|
* ```
|
|
63
63
|
*
|
|
64
|
-
* @param colors
|
|
65
|
-
* @param key
|
|
66
|
-
* @param isReverse
|
|
64
|
+
* @param colors -
|
|
65
|
+
* @param key -
|
|
66
|
+
* @param isReverse -
|
|
67
67
|
*/
|
|
68
68
|
export const sortMapped = (colors, key, isReverse = false) => {
|
|
69
69
|
if (!colors.length)
|