@thi.ng/color 5.6.2 → 5.6.4

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 (111) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +1 -1
  3. package/alpha.js +6 -10
  4. package/analog.js +35 -67
  5. package/api/constants.js +128 -156
  6. package/api/gradients.js +0 -1
  7. package/api/names.js +154 -151
  8. package/api/ranges.js +0 -1
  9. package/api/system.js +21 -26
  10. package/api.js +27 -32
  11. package/clamp.js +18 -29
  12. package/closest-hue.js +6 -12
  13. package/color-range.js +159 -228
  14. package/color.js +29 -28
  15. package/contrast.js +7 -17
  16. package/convert.js +19 -40
  17. package/cosine-gradients.js +177 -229
  18. package/css/css.js +27 -53
  19. package/css/parse-css.js +94 -160
  20. package/defcolor.js +97 -108
  21. package/distance.js +96 -187
  22. package/gradients.js +29 -37
  23. package/hcy/hcy-rgb.js +20 -13
  24. package/hcy/hcy.js +9 -11
  25. package/hsi/hsi-rgb.js +32 -30
  26. package/hsi/hsi.js +9 -11
  27. package/hsl/hsl-css.js +9 -10
  28. package/hsl/hsl-hsv.js +12 -9
  29. package/hsl/hsl-rgb.js +14 -6
  30. package/hsl/hsl.js +14 -16
  31. package/hsv/hsv-css.js +4 -1
  32. package/hsv/hsv-hsl.js +11 -8
  33. package/hsv/hsv-rgb.js +14 -6
  34. package/hsv/hsv.js +14 -16
  35. package/hue.js +12 -12
  36. package/int/int-css.js +10 -6
  37. package/int/int-int.js +6 -10
  38. package/int/int-rgb.js +16 -5
  39. package/int/int-srgb.js +22 -4
  40. package/int/int.js +136 -142
  41. package/internal/css.js +16 -12
  42. package/internal/dispatch.js +6 -2
  43. package/internal/ensure.js +18 -16
  44. package/internal/matrix-ops.js +39 -41
  45. package/internal/scale.js +4 -2
  46. package/invert.js +46 -39
  47. package/is-black.js +12 -5
  48. package/is-gamut.js +8 -13
  49. package/is-gray.js +12 -5
  50. package/is-white.js +14 -7
  51. package/lab/lab-css.js +4 -9
  52. package/lab/lab-lab.js +6 -2
  53. package/lab/lab-lch.js +18 -10
  54. package/lab/lab-rgb.js +6 -14
  55. package/lab/lab-xyz.js +16 -20
  56. package/lab/lab50.js +18 -15
  57. package/lab/lab65.js +18 -15
  58. package/lch/lch-css.js +4 -9
  59. package/lch/lch.js +18 -23
  60. package/lighten.js +13 -17
  61. package/linear.js +6 -16
  62. package/luminance-rgb.js +14 -22
  63. package/luminance.js +16 -14
  64. package/max-chroma.js +1340 -227
  65. package/mix.js +34 -82
  66. package/oklab/oklab-css.js +4 -9
  67. package/oklab/oklab-rgb.js +17 -23
  68. package/oklab/oklab-xyz.js +22 -9
  69. package/oklab/oklab.js +19 -22
  70. package/oklch/oklab-oklch.js +10 -11
  71. package/oklch/oklch-css.js +4 -9
  72. package/oklch/oklch-oklab.js +9 -9
  73. package/oklch/oklch.js +14 -20
  74. package/package.json +19 -17
  75. package/rgb/hue-rgb.js +14 -11
  76. package/rgb/kelvin-rgba.js +23 -22
  77. package/rgb/rgb-css.js +4 -1
  78. package/rgb/rgb-hcv.js +14 -15
  79. package/rgb/rgb-hcy.js +10 -14
  80. package/rgb/rgb-hsi.js +13 -8
  81. package/rgb/rgb-hsl.js +8 -5
  82. package/rgb/rgb-hsv.js +7 -4
  83. package/rgb/rgb-lab.js +6 -18
  84. package/rgb/rgb-oklab.js +13 -19
  85. package/rgb/rgb-srgb.js +18 -8
  86. package/rgb/rgb-xyz.js +6 -19
  87. package/rgb/rgb-ycc.js +12 -17
  88. package/rgb/rgb.js +25 -22
  89. package/rotate.js +25 -38
  90. package/sort.js +24 -72
  91. package/srgb/srgb-css.js +9 -9
  92. package/srgb/srgb-int.js +6 -10
  93. package/srgb/srgb-rgb.js +18 -8
  94. package/srgb/srgb.js +16 -13
  95. package/strategies.js +42 -112
  96. package/swatches.js +28 -5
  97. package/tint.js +27 -53
  98. package/transform.js +274 -149
  99. package/variations.js +10 -9
  100. package/xyy/xyy-xyz.js +12 -11
  101. package/xyy/xyy.js +16 -13
  102. package/xyz/wavelength-xyz.js +14 -28
  103. package/xyz/xyz-lab.js +17 -26
  104. package/xyz/xyz-oklab.js +4 -1
  105. package/xyz/xyz-rgb.js +6 -18
  106. package/xyz/xyz-xyy.js +13 -12
  107. package/xyz/xyz-xyz.js +6 -2
  108. package/xyz/xyz50.js +20 -17
  109. package/xyz/xyz65.js +20 -17
  110. package/ycc/ycc-rgb.js +14 -19
  111. package/ycc/ycc.js +12 -9
package/color-range.js CHANGED
@@ -14,247 +14,178 @@ import { isBlack } from "./is-black.js";
14
14
  import { isGray } from "./is-gray.js";
15
15
  import { isWhite } from "./is-white.js";
16
16
  import { lch } from "./lch/lch.js";
17
- /**
18
- * Preset {@link ColorRange}s for use with {@link colorsFromRange},
19
- * {@link colorsFromTheme} etc.
20
- */
21
- export const COLOR_RANGES = {
22
- light: {
23
- c: [[0.3, 0.7]],
24
- l: [[0.9, 1]],
25
- b: [[0.35, 0.5]],
26
- w: [[0.6, 1]],
27
- },
28
- dark: {
29
- c: [[0.7, 1]],
30
- l: [[0.15, 0.4]],
31
- b: [[0, 0.4]],
32
- w: [[0.4, 0.6]],
33
- },
34
- bright: {
35
- c: [[0.75, 0.95]],
36
- l: [[0.8, 1]],
37
- },
38
- weak: {
39
- c: [[0.15, 0.3]],
40
- l: [[0.7, 1]],
41
- b: [[0.4, 0.6]],
42
- w: [[0.8, 1]],
43
- },
44
- neutral: {
45
- c: [[0.25, 0.35]],
46
- l: [[0.3, 0.7]],
47
- b: [[0.25, 0.4]],
48
- w: [[0.9, 1]],
49
- },
50
- fresh: {
51
- c: [[0.4, 0.8]],
52
- l: [[0.8, 1]],
53
- b: [[0.05, 0.3]],
54
- w: [[0.8, 1]],
55
- },
56
- soft: {
57
- c: [[0.2, 0.3]],
58
- l: [[0.6, 0.9]],
59
- b: [[0.05, 0.15]],
60
- w: [[0.6, 0.9]],
61
- },
62
- hard: {
63
- c: [[0.85, 0.95]],
64
- l: [[0.4, 1]],
65
- },
66
- warm: {
67
- c: [[0.6, 0.9]],
68
- l: [[0.4, 0.9]],
69
- b: [[0.2, 0.3]],
70
- w: [[0.8, 1]],
71
- },
72
- cool: {
73
- c: [[0.05, 0.2]],
74
- l: [[0.9, 1]],
75
- b: [[0, 0.95]],
76
- w: [[0.95, 1]],
77
- },
78
- intense: {
79
- c: [[0.9, 1]],
80
- l: [
81
- [0.2, 0.35],
82
- [0.8, 1],
83
- ],
84
- },
17
+ const COLOR_RANGES = {
18
+ light: {
19
+ c: [[0.3, 0.7]],
20
+ l: [[0.9, 1]],
21
+ b: [[0.35, 0.5]],
22
+ w: [[0.6, 1]]
23
+ },
24
+ dark: {
25
+ c: [[0.7, 1]],
26
+ l: [[0.15, 0.4]],
27
+ b: [[0, 0.4]],
28
+ w: [[0.4, 0.6]]
29
+ },
30
+ bright: {
31
+ c: [[0.75, 0.95]],
32
+ l: [[0.8, 1]]
33
+ },
34
+ weak: {
35
+ c: [[0.15, 0.3]],
36
+ l: [[0.7, 1]],
37
+ b: [[0.4, 0.6]],
38
+ w: [[0.8, 1]]
39
+ },
40
+ neutral: {
41
+ c: [[0.25, 0.35]],
42
+ l: [[0.3, 0.7]],
43
+ b: [[0.25, 0.4]],
44
+ w: [[0.9, 1]]
45
+ },
46
+ fresh: {
47
+ c: [[0.4, 0.8]],
48
+ l: [[0.8, 1]],
49
+ b: [[0.05, 0.3]],
50
+ w: [[0.8, 1]]
51
+ },
52
+ soft: {
53
+ c: [[0.2, 0.3]],
54
+ l: [[0.6, 0.9]],
55
+ b: [[0.05, 0.15]],
56
+ w: [[0.6, 0.9]]
57
+ },
58
+ hard: {
59
+ c: [[0.85, 0.95]],
60
+ l: [[0.4, 1]]
61
+ },
62
+ warm: {
63
+ c: [[0.6, 0.9]],
64
+ l: [[0.4, 0.9]],
65
+ b: [[0.2, 0.3]],
66
+ w: [[0.8, 1]]
67
+ },
68
+ cool: {
69
+ c: [[0.05, 0.2]],
70
+ l: [[0.9, 1]],
71
+ b: [[0, 0.95]],
72
+ w: [[0.95, 1]]
73
+ },
74
+ intense: {
75
+ c: [[0.9, 1]],
76
+ l: [
77
+ [0.2, 0.35],
78
+ [0.8, 1]
79
+ ]
80
+ }
85
81
  };
86
82
  const FULL = [[0, 1]];
87
83
  const DEFAULT_RANGE = {
88
- h: FULL,
89
- c: FULL,
90
- l: FULL,
91
- b: FULL,
92
- w: FULL,
93
- a: [[1, 1]],
84
+ h: FULL,
85
+ c: FULL,
86
+ l: FULL,
87
+ b: FULL,
88
+ w: FULL,
89
+ a: [[1, 1]]
94
90
  };
95
91
  const DEFAULT_OPTS = {
96
- num: Infinity,
97
- variance: 0.025,
98
- eps: 1e-3,
99
- rnd: SYSTEM,
92
+ num: Infinity,
93
+ variance: 0.025,
94
+ eps: 1e-3,
95
+ rnd: SYSTEM
100
96
  };
101
97
  const $rnd = (ranges, rnd) => rnd.minmax(...ranges[rnd.int() % ranges.length]);
102
- /**
103
- * Takes a {@link ColorRange} and options to produce a single new result color.
104
- * This color is randomized within the channel limits of the given `range`
105
- * descriptor. If a `base` color is provided (via {@link ColorRangeOpts}), its
106
- * hue is used as bias and the `variance` option defines the max. -/+ normalized
107
- * hue shift of the result color.
108
- *
109
- * @remarks
110
- * If the base color is a shade of gray (incl. black & white), the result will
111
- * be another gray and is based on the range's black and white point sub-ranges.
112
- *
113
- * The alpha channel of the result color will only be randomized (based on
114
- * `range.a` settings) iff no `base` color was provided. If `base` is given, the
115
- * result will used the same alpha.
116
- *
117
- * A custom PRNG can be defined via the `rnd` option (default: `Math.random`).
118
- *
119
- * @param range -
120
- * @param opts -
121
- */
122
- export const colorFromRange = (range, opts) => {
123
- range = {
124
- ...DEFAULT_RANGE,
125
- ...(isString(range) ? COLOR_RANGES[range] : range),
126
- };
127
- const { base, variance, rnd, eps } = { ...DEFAULT_OPTS, ...opts };
128
- let h;
129
- let c;
130
- let l;
131
- let a;
132
- if (base) {
133
- const col = lch(base);
134
- h = col[2];
135
- a = __ensureAlpha(col[3]);
136
- if (isBlack(col, eps)) {
137
- c = 0;
138
- l = $rnd(range.b, rnd);
139
- }
140
- else if (isWhite(col, eps)) {
141
- c = 0;
142
- l = $rnd(range.w, rnd);
143
- }
144
- else if (isGray(col, eps)) {
145
- c = 0;
146
- l = $rnd(coin(rnd) ? range.b : range.w, rnd);
147
- }
148
- else {
149
- h = fract(h + rnd.norm(variance));
150
- }
98
+ const colorFromRange = (range, opts) => {
99
+ range = {
100
+ ...DEFAULT_RANGE,
101
+ ...isString(range) ? COLOR_RANGES[range] : range
102
+ };
103
+ const { base, variance, rnd, eps } = { ...DEFAULT_OPTS, ...opts };
104
+ let h;
105
+ let c;
106
+ let l;
107
+ let a;
108
+ if (base) {
109
+ const col = lch(base);
110
+ h = col[2];
111
+ a = __ensureAlpha(col[3]);
112
+ if (isBlack(col, eps)) {
113
+ c = 0;
114
+ l = $rnd(range.b, rnd);
115
+ } else if (isWhite(col, eps)) {
116
+ c = 0;
117
+ l = $rnd(range.w, rnd);
118
+ } else if (isGray(col, eps)) {
119
+ c = 0;
120
+ l = $rnd(coin(rnd) ? range.b : range.w, rnd);
121
+ } else {
122
+ h = fract(h + rnd.norm(variance));
151
123
  }
152
- else {
153
- h = $rnd(range.h, rnd);
154
- a = $rnd(range.a, rnd);
155
- }
156
- return lch([
157
- l != undefined ? l : $rnd(range.l, rnd),
158
- c !== undefined ? c : $rnd(range.c, rnd),
159
- h,
160
- a,
161
- ]);
124
+ } else {
125
+ h = $rnd(range.h, rnd);
126
+ a = $rnd(range.a, rnd);
127
+ }
128
+ return lch([
129
+ l != void 0 ? l : $rnd(range.l, rnd),
130
+ c !== void 0 ? c : $rnd(range.c, rnd),
131
+ h,
132
+ a
133
+ ]);
162
134
  };
163
- /**
164
- * Generator version of {@link colorFromRange}, by default yielding an infinite
165
- * sequence of random colors based on given range, base color (optional) and
166
- * other opts. Use `num` option to limit number of results.
167
- *
168
- * @param range -
169
- * @param opts -
170
- */
171
- export function* colorsFromRange(range, opts = {}) {
172
- let num = opts.num != undefined ? opts.num : Infinity;
173
- while (num-- > 0)
174
- yield colorFromRange(range, opts);
135
+ function* colorsFromRange(range, opts = {}) {
136
+ let num = opts.num != void 0 ? opts.num : Infinity;
137
+ while (num-- > 0)
138
+ yield colorFromRange(range, opts);
175
139
  }
176
- /** @internal */
177
140
  const compileThemePart = (part, opts) => {
178
- let spec;
179
- if (isArray(part)) {
180
- spec = themePartFromTuple(part);
181
- }
182
- else if (isString(part)) {
183
- spec = themePartFromString(part);
184
- }
185
- else {
186
- spec = { ...part };
187
- spec.weight == null && (spec.weight = 1);
188
- }
189
- isString(spec.range) && (spec.range = COLOR_RANGES[spec.range]);
190
- isString(spec.base) && (spec.base = lch(parseCss(spec.base)));
191
- if (spec.base !== undefined) {
192
- opts = { ...opts, base: spec.base };
193
- }
194
- return { spec, opts };
141
+ let spec;
142
+ if (isArray(part)) {
143
+ spec = themePartFromTuple(part);
144
+ } else if (isString(part)) {
145
+ spec = themePartFromString(part);
146
+ } else {
147
+ spec = { ...part };
148
+ spec.weight == null && (spec.weight = 1);
149
+ }
150
+ isString(spec.range) && (spec.range = COLOR_RANGES[spec.range]);
151
+ isString(spec.base) && (spec.base = lch(parseCss(spec.base)));
152
+ if (spec.base !== void 0) {
153
+ opts = { ...opts, base: spec.base };
154
+ }
155
+ return { spec, opts };
195
156
  };
196
- /** @internal */
197
157
  const themePartFromTuple = (part) => {
198
- let weight;
199
- const [range, ...xs] = part;
200
- if (isNumber(peek(xs))) {
201
- weight = peek(xs);
202
- xs.pop();
203
- }
204
- else {
205
- weight = 1;
206
- }
207
- return ((xs.length === 1
208
- ? { range, base: xs[0], weight }
209
- : xs.length === 0
210
- ? COLOR_RANGES[range]
211
- ? { range, weight }
212
- : { base: range, weight }
213
- : illegalArgs(`invalid theme part: "${part}"`)));
158
+ let weight;
159
+ const [range, ...xs] = part;
160
+ if (isNumber(peek(xs))) {
161
+ weight = peek(xs);
162
+ xs.pop();
163
+ } else {
164
+ weight = 1;
165
+ }
166
+ return xs.length === 1 ? { range, base: xs[0], weight } : xs.length === 0 ? COLOR_RANGES[range] ? { range, weight } : { base: range, weight } : illegalArgs(`invalid theme part: "${part}"`);
214
167
  };
215
- /** @internal */
216
- const themePartFromString = (part) => ((COLOR_RANGES[part]
217
- ? { range: part, weight: 1 }
218
- : { base: part, weight: 1 }));
219
- /**
220
- * Probabilistic color theme generator. Yield randomized colors based on given
221
- * weighted set of theme part specs.
222
- *
223
- * @remarks
224
- * Each theme part is a tuple of either:
225
- *
226
- * - `[range, color, weight?]`
227
- * - `[range, weight?]`
228
- * - `[color, weight?]`
229
- *
230
- * `range` can be either a {@link ColorRange} or the name of a
231
- * {@link COLOR_RANGES} preset. Likewise, `color` can be a color instance or CSS
232
- * color name. The `weight` of each part defines the relative
233
- * importance/probability of this theme part, compared to others. Default weight
234
- * is 1.0.
235
- *
236
- * @example
237
- * ```ts
238
- * [...colorsFromTheme(
239
- * [["cool", "aliceblue"], ["bright", "orange", 0.25], ["hotpink", 0.1]],
240
- * { num: 10 }
241
- * )]
242
- * ```
243
- *
244
- * @param parts -
245
- * @param opts -
246
- */
247
- export function* colorsFromTheme(parts, opts = {}) {
248
- let { num, variance, rnd } = { ...DEFAULT_OPTS, ...opts };
249
- const theme = parts.map((p) => compileThemePart(p, opts));
250
- const choice = weightedRandom(theme, theme.map((x) => x.spec.weight), rnd);
251
- while (--num >= 0) {
252
- const { spec, opts } = choice();
253
- if (spec.range) {
254
- yield colorFromRange(spec.range, opts);
255
- }
256
- else if (spec.base) {
257
- yield analog(lch(), lch(spec.base), variance, rnd);
258
- }
168
+ const themePartFromString = (part) => COLOR_RANGES[part] ? { range: part, weight: 1 } : { base: part, weight: 1 };
169
+ function* colorsFromTheme(parts, opts = {}) {
170
+ let { num, variance, rnd } = { ...DEFAULT_OPTS, ...opts };
171
+ const theme = parts.map((p) => compileThemePart(p, opts));
172
+ const choice = weightedRandom(
173
+ theme,
174
+ theme.map((x) => x.spec.weight),
175
+ rnd
176
+ );
177
+ while (--num >= 0) {
178
+ const { spec, opts: opts2 } = choice();
179
+ if (spec.range) {
180
+ yield colorFromRange(spec.range, opts2);
181
+ } else if (spec.base) {
182
+ yield analog(lch(), lch(spec.base), variance, rnd);
259
183
  }
184
+ }
260
185
  }
186
+ export {
187
+ COLOR_RANGES,
188
+ colorFromRange,
189
+ colorsFromRange,
190
+ colorsFromTheme
191
+ };
package/color.js CHANGED
@@ -17,33 +17,34 @@ import { xyzD50 } from "./xyz/xyz50.js";
17
17
  import { xyzD65 } from "./xyz/xyz65.js";
18
18
  import { ycc } from "./ycc/ycc.js";
19
19
  const FACTORIES = {
20
- argb32,
21
- abgr32,
22
- hcy,
23
- hsi,
24
- hsl,
25
- hsv,
26
- lab50: labD50,
27
- lab65: labD65,
28
- lch,
29
- oklab,
30
- oklch,
31
- rgb,
32
- srgb,
33
- xyy,
34
- xyz50: xyzD50,
35
- xyz65: xyzD65,
36
- ycc,
20
+ argb32,
21
+ abgr32,
22
+ hcy,
23
+ hsi,
24
+ hsl,
25
+ hsv,
26
+ lab50: labD50,
27
+ lab65: labD65,
28
+ lch,
29
+ oklab,
30
+ oklch,
31
+ rgb,
32
+ srgb,
33
+ xyy,
34
+ xyz50: xyzD50,
35
+ xyz65: xyzD65,
36
+ ycc
37
37
  };
38
- export function color(src, buf, idx, stride) {
39
- if (isString(src))
40
- return buf
41
- ? FACTORIES[src](buf, idx, stride)
42
- : color(parseCss(src));
43
- if (buf) {
44
- const res = FACTORIES[src.mode](buf, idx, stride);
45
- res.set(src.deref());
46
- return res;
47
- }
48
- return FACTORIES[src.mode](src.deref());
38
+ function color(src, buf, idx, stride) {
39
+ if (isString(src))
40
+ return buf ? FACTORIES[src](buf, idx, stride) : color(parseCss(src));
41
+ if (buf) {
42
+ const res = FACTORIES[src.mode](buf, idx, stride);
43
+ res.set(src.deref());
44
+ return res;
45
+ }
46
+ return FACTORIES[src.mode](src.deref());
49
47
  }
48
+ export {
49
+ color
50
+ };
package/contrast.js CHANGED
@@ -1,20 +1,10 @@
1
1
  import { luminanceRgb } from "./luminance-rgb.js";
2
2
  import { rgb } from "./rgb/rgb.js";
3
- /**
4
- * Computes the WCAG 2.0 contrast ratio of the two given colors (order is
5
- * irrelevant). Contrast ratios can range from 1 to 21.
6
- *
7
- * @remarks
8
- * For accessibility guideline conformance, the visual presentation of text must
9
- * have a minimum contrast ratio of at least 4.5 (with some exceptions).
10
- *
11
- * Reference: https://www.w3.org/TR/WCAG20/#contrast-ratiodef
12
- *
13
- * @param a
14
- * @param b
15
- */
16
- export const contrast = (a, b) => {
17
- const lumA = luminanceRgb(rgb(a)) + 0.05;
18
- const lumB = luminanceRgb(rgb(b)) + 0.05;
19
- return lumA > lumB ? lumA / lumB : lumB / lumA;
3
+ const contrast = (a, b) => {
4
+ const lumA = luminanceRgb(rgb(a)) + 0.05;
5
+ const lumB = luminanceRgb(rgb(b)) + 0.05;
6
+ return lumA > lumB ? lumA / lumB : lumB / lumA;
7
+ };
8
+ export {
9
+ contrast
20
10
  };
package/convert.js CHANGED
@@ -1,46 +1,25 @@
1
1
  import { isArray } from "@thi.ng/checks/is-array";
2
2
  import { assert } from "@thi.ng/errors/assert";
3
3
  import { unsupported } from "@thi.ng/errors/unsupported";
4
- export const CONVERSIONS = {};
5
- /**
6
- * Registers conversions for given {@link ColorSpec}. Called by
7
- * {@link defColor}.
8
- *
9
- * @param spec -
10
- *
11
- * @internal
12
- */
13
- export const defConversions = (mode, spec) => {
14
- for (let id in spec) {
15
- const val = spec[id];
16
- if (isArray(val)) {
17
- const [a, b, c, d] = val;
18
- spec[id] =
19
- val.length === 2
20
- ? (out, src) => b(out, a(out, src))
21
- : val.length === 3
22
- ? (out, src) => c(out, b(out, a(out, src)))
23
- : (out, src) => d(out, c(out, b(out, a(out, src))));
24
- }
4
+ const CONVERSIONS = {};
5
+ const defConversions = (mode, spec) => {
6
+ for (let id in spec) {
7
+ const val = spec[id];
8
+ if (isArray(val)) {
9
+ const [a, b, c, d] = val;
10
+ spec[id] = val.length === 2 ? (out, src) => b(out, a(out, src)) : val.length === 3 ? (out, src) => c(out, b(out, a(out, src))) : (out, src) => d(out, c(out, b(out, a(out, src))));
25
11
  }
26
- CONVERSIONS[mode] = { ...CONVERSIONS[mode], ...spec };
12
+ }
13
+ CONVERSIONS[mode] = { ...CONVERSIONS[mode], ...spec };
27
14
  };
28
- /**
29
- * Converts a (raw, untyped) color from one mode to another and writes result
30
- * into `out` (or if null, back into `src`).
31
- *
32
- * @param res
33
- * @param src
34
- * @param destMode
35
- * @param srcMode
36
- */
37
- export const convert = (res, src, destMode, srcMode) => {
38
- const spec = CONVERSIONS[destMode];
39
- assert(!!spec, `no conversions available for ${destMode}`);
40
- let $convert = spec[srcMode];
41
- return $convert
42
- ? $convert(res, src)
43
- : CONVERSIONS.rgb[srcMode]
44
- ? spec.rgb(res, CONVERSIONS.rgb[srcMode]([], src))
45
- : unsupported(`can't convert: ${srcMode} -> ${destMode}`);
15
+ const convert = (res, src, destMode, srcMode) => {
16
+ const spec = CONVERSIONS[destMode];
17
+ assert(!!spec, `no conversions available for ${destMode}`);
18
+ let $convert = spec[srcMode];
19
+ return $convert ? $convert(res, src) : CONVERSIONS.rgb[srcMode] ? spec.rgb(res, CONVERSIONS.rgb[srcMode]([], src)) : unsupported(`can't convert: ${srcMode} -> ${destMode}`);
20
+ };
21
+ export {
22
+ CONVERSIONS,
23
+ convert,
24
+ defConversions
46
25
  };