@thi.ng/color 4.1.7 → 5.0.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/README.md +3 -3
  3. package/analog.d.ts +15 -15
  4. package/analog.js +16 -15
  5. package/api/constants.d.ts +1 -1
  6. package/api/constants.js +1 -1
  7. package/api/system.d.ts +1 -1
  8. package/api/system.js +1 -1
  9. package/api.d.ts +13 -6
  10. package/color-range.d.ts +6 -6
  11. package/color-range.js +6 -6
  12. package/convert.d.ts +1 -1
  13. package/convert.js +1 -1
  14. package/cosine-gradients.d.ts +5 -5
  15. package/cosine-gradients.js +5 -5
  16. package/css/parse-css.d.ts +1 -1
  17. package/css/parse-css.js +1 -1
  18. package/defcolor.js +5 -1
  19. package/distance.d.ts +17 -17
  20. package/distance.js +17 -17
  21. package/gradients.d.ts +2 -2
  22. package/gradients.js +2 -2
  23. package/hcy/hcy.js +5 -1
  24. package/hsi/hsi.js +5 -1
  25. package/hsl/hsl.js +10 -1
  26. package/hsv/hsv.js +10 -1
  27. package/index.d.ts +8 -0
  28. package/index.js +8 -0
  29. package/int/int-int.d.ts +1 -1
  30. package/int/int-int.js +1 -1
  31. package/internal/dispatch.d.ts +4 -0
  32. package/internal/dispatch.js +2 -0
  33. package/invert.d.ts +8 -1
  34. package/invert.js +34 -1
  35. package/is-black.d.ts +1 -1
  36. package/is-black.js +10 -7
  37. package/is-gamut.d.ts +9 -0
  38. package/is-gamut.js +16 -0
  39. package/is-gray.d.ts +1 -1
  40. package/is-gray.js +10 -8
  41. package/is-white.d.ts +1 -1
  42. package/is-white.js +9 -6
  43. package/lab/lab-css.d.ts +1 -1
  44. package/lab/lab-css.js +1 -1
  45. package/lab/lab-rgb.d.ts +4 -4
  46. package/lab/lab-rgb.js +4 -4
  47. package/lab/lab-xyz.d.ts +5 -5
  48. package/lab/lab-xyz.js +5 -5
  49. package/lch/lch-css.d.ts +1 -1
  50. package/lch/lch-css.js +1 -1
  51. package/lch/lch.js +1 -0
  52. package/lighten.d.ts +11 -0
  53. package/lighten.js +21 -0
  54. package/luminance-rgb.d.ts +2 -2
  55. package/luminance-rgb.js +2 -2
  56. package/luminance.d.ts +2 -2
  57. package/luminance.js +3 -2
  58. package/max-chroma.d.ts +8 -0
  59. package/max-chroma.js +240 -0
  60. package/mix.d.ts +8 -8
  61. package/mix.js +9 -8
  62. package/oklab/oklab-rgb.d.ts +2 -2
  63. package/oklab/oklab-rgb.js +2 -2
  64. package/package.json +131 -109
  65. package/rgb/rgb-lab.d.ts +4 -4
  66. package/rgb/rgb-lab.js +4 -4
  67. package/rgb/rgb-oklab.d.ts +2 -2
  68. package/rgb/rgb-oklab.js +2 -2
  69. package/rgb/rgb-xyz.d.ts +2 -2
  70. package/rgb/rgb-xyz.js +2 -2
  71. package/rgb/rgb-ycc.d.ts +3 -3
  72. package/rgb/rgb-ycc.js +3 -3
  73. package/rotate.d.ts +4 -0
  74. package/rotate.js +10 -0
  75. package/sort.d.ts +7 -7
  76. package/sort.js +7 -7
  77. package/strategies.d.ts +90 -0
  78. package/strategies.js +122 -0
  79. package/tint.d.ts +6 -0
  80. package/tint.js +11 -0
  81. package/transform.d.ts +11 -11
  82. package/transform.js +11 -11
  83. package/variations.d.ts +29 -0
  84. package/variations.js +14 -0
  85. package/xyy/xyy-xyz.d.ts +2 -2
  86. package/xyy/xyy-xyz.js +2 -2
  87. package/xyz/wavelength-xyz.d.ts +3 -3
  88. package/xyz/wavelength-xyz.js +3 -3
  89. package/xyz/xyz-lab.d.ts +5 -5
  90. package/xyz/xyz-lab.js +5 -5
  91. package/xyz/xyz-rgb.d.ts +2 -2
  92. package/xyz/xyz-rgb.js +2 -2
  93. package/xyz/xyz-xyy.d.ts +2 -2
  94. package/xyz/xyz-xyy.js +2 -2
  95. package/ycc/ycc-rgb.d.ts +3 -3
  96. 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/api").MultiFn4<import("@thi.ng/vectors").Vec | null, TypedColor<any>, TypedColor<any>, number, import("@thi.ng/vectors").Vec>;
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((_, a) => a.mode, {}, {
85
+ export const mix = defmulti(__dispatch1, {}, {
85
86
  hcy: mixHNNN,
86
87
  hsi: mixHNNN,
87
88
  hsl: mixHNNN,
@@ -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
@@ -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,