@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
@@ -11,241 +11,189 @@ import { tween } from "@thi.ng/transducers/tween";
11
11
  import { zip } from "@thi.ng/transducers/zip";
12
12
  import { setS4 } from "@thi.ng/vectors/sets";
13
13
  import { clamp } from "./clamp.js";
14
- /**
15
- * Preset cosine gradient definitions. See previews at:
16
- * https://github.com/thi-ng/umbrella/tree/develop/packages/color#cosine-gradients
17
- *
18
- * @remarks
19
- * See http://dev.thi.ng/gradients/ for a gradient designer. Note: unlike the
20
- * linked original Clojure version, these presets here are for RGBA (though the
21
- * alpha channel is configured to always be 1.0)
22
- */
23
- export const COSINE_GRADIENTS = {
24
- "blue-cyan": [
25
- [0, 0.5, 0.5, 1],
26
- [0, 0.5, 0.5, 0],
27
- [0, 0.5, 0.3333, 0],
28
- [0, 0.5, 0.6666, 0],
29
- ],
30
- "blue-magenta-orange": [
31
- [0.938, 0.328, 0.718, 1],
32
- [0.659, 0.438, 0.328, 0],
33
- [0.388, 0.388, 0.296, 0],
34
- [2.538, 2.478, 0.168, 0],
35
- ],
36
- "blue-white-red": [
37
- [0.66, 0.56, 0.68, 1],
38
- [0.718, 0.438, 0.72, 0],
39
- [0.52, 0.8, 0.52, 0],
40
- [-0.43, -0.397, -0.083, 0],
41
- ],
42
- "cyan-magenta": [
43
- [0.61, 0.498, 0.65, 1],
44
- [0.388, 0.498, 0.35, 0],
45
- [0.53, 0.498, 0.62, 0],
46
- [3.438, 3.012, 4.025, 0],
47
- ],
48
- "green-blue-orange": [
49
- [0.892, 0.725, 0, 1],
50
- [0.878, 0.278, 0.725, 0],
51
- [0.332, 0.518, 0.545, 0],
52
- [2.44, 5.043, 0.732, 0],
53
- ],
54
- "green-cyan": [
55
- [0, 0.5, 0.5, 1],
56
- [0, 0.5, 0.5, 0],
57
- [0, 0.3333, 0.5, 0],
58
- [0, 0.6666, 0.5, 0],
59
- ],
60
- "green-magenta": [
61
- [0.6666, 0.5, 0.5, 1],
62
- [0.5, 0.6666, 0.5, 0],
63
- [0.6666, 0.666, 0.5, 0],
64
- [0.2, 0, 0.5, 0],
65
- ],
66
- "green-red": [
67
- [0.5, 0.5, 0, 1],
68
- [0.5, 0.5, 0, 0],
69
- [0.5, 0.5, 0, 0],
70
- [0.5, 0, 0, 0],
71
- ],
72
- heat1: [
73
- [0.5, 0.4, 0.25, 1],
74
- [0.5, 0.5, 0.666, 0],
75
- [0.5, 0.666, 0.8, 0],
76
- [0.5, 0.666, 0.8, 0],
77
- ],
78
- "magenta-green": [
79
- [0.59, 0.811, 0.12, 1],
80
- [0.41, 0.392, 0.59, 0],
81
- [0.94, 0.548, 0.278, 0],
82
- [-4.242, -6.611, -4.045, 0],
83
- ],
84
- "orange-blue": [
85
- [0.5, 0.5, 0.5, 1],
86
- [0.5, 0.5, 0.5, 0],
87
- [0.8, 0.8, 0.5, 0],
88
- [0, 0.2, 0.5, 0],
89
- ],
90
- "orange-magenta-blue": [
91
- [0.821, 0.328, 0.242, 1],
92
- [0.659, 0.481, 0.896, 0],
93
- [0.612, 0.34, 0.296, 0],
94
- [2.82, 3.026, -0.273, 0],
95
- ],
96
- "purple-orange-cyan": [
97
- [0.5, 0.5, 0.5, 1],
98
- [0.5, 0.5, 0.5, 0],
99
- [0.5, 0.5, 1, 0],
100
- [-0.25, 0.5, 1, 0],
101
- ],
102
- rainbow1: [
103
- [0.5, 0.5, 0.5, 1],
104
- [0.5, 0.5, 0.5, 0],
105
- [1.0, 1.0, 1.0, 0],
106
- [0, 0.3333, 0.6666, 0],
107
- ],
108
- rainbow2: [
109
- [0.5, 0.5, 0.5, 1],
110
- [0.666, 0.666, 0.666, 0],
111
- [1.0, 1.0, 1.0, 0],
112
- [0, 0.3333, 0.6666, 0],
113
- ],
114
- rainbow3: [
115
- [0.5, 0.5, 0.5, 1],
116
- [0.75, 0.75, 0.75, 0],
117
- [1.0, 1.0, 1.0, 0],
118
- [0, 0.3333, 0.6666, 0],
119
- ],
120
- rainbow4: [
121
- [0.5, 0.5, 0.5, 1],
122
- [1, 1, 1, 0],
123
- [1.0, 1.0, 1.0, 0],
124
- [0, 0.3333, 0.6666, 0],
125
- ],
126
- "red-blue": [
127
- [0.5, 0, 0.5, 1],
128
- [0.5, 0, 0.5, 0],
129
- [0.5, 0, 0.5, 0],
130
- [0, 0, 0.5, 0],
131
- ],
132
- "yellow-green-blue": [
133
- [0.65, 0.5, 0.31, 1],
134
- [-0.65, 0.5, 0.6, 0],
135
- [0.333, 0.278, 0.278, 0],
136
- [0.66, 0, 0.667, 0],
137
- ],
138
- "yellow-magenta-cyan": [
139
- [1, 0.5, 0.5, 1],
140
- [0.5, 0.5, 0.5, 0],
141
- [0.75, 1.0, 0.6666, 0],
142
- [0.8, 1.0, 0.3333, 0],
143
- ],
144
- "yellow-purple-magenta": [
145
- [0.731, 1.098, 0.192, 1],
146
- [0.358, 1.09, 0.657, 0],
147
- [1.077, 0.36, 0.328, 0],
148
- [0.965, 2.265, 0.837, 0],
149
- ],
150
- "yellow-red": [
151
- [0.5, 0.5, 0, 1],
152
- [0.5, 0.5, 0, 0],
153
- [0.1, 0.5, 0, 0],
154
- [0, 0, 0, 0],
155
- ],
14
+ const COSINE_GRADIENTS = {
15
+ "blue-cyan": [
16
+ [0, 0.5, 0.5, 1],
17
+ [0, 0.5, 0.5, 0],
18
+ [0, 0.5, 0.3333, 0],
19
+ [0, 0.5, 0.6666, 0]
20
+ ],
21
+ "blue-magenta-orange": [
22
+ [0.938, 0.328, 0.718, 1],
23
+ [0.659, 0.438, 0.328, 0],
24
+ [0.388, 0.388, 0.296, 0],
25
+ [2.538, 2.478, 0.168, 0]
26
+ ],
27
+ "blue-white-red": [
28
+ [0.66, 0.56, 0.68, 1],
29
+ [0.718, 0.438, 0.72, 0],
30
+ [0.52, 0.8, 0.52, 0],
31
+ [-0.43, -0.397, -0.083, 0]
32
+ ],
33
+ "cyan-magenta": [
34
+ [0.61, 0.498, 0.65, 1],
35
+ [0.388, 0.498, 0.35, 0],
36
+ [0.53, 0.498, 0.62, 0],
37
+ [3.438, 3.012, 4.025, 0]
38
+ ],
39
+ "green-blue-orange": [
40
+ [0.892, 0.725, 0, 1],
41
+ [0.878, 0.278, 0.725, 0],
42
+ [0.332, 0.518, 0.545, 0],
43
+ [2.44, 5.043, 0.732, 0]
44
+ ],
45
+ "green-cyan": [
46
+ [0, 0.5, 0.5, 1],
47
+ [0, 0.5, 0.5, 0],
48
+ [0, 0.3333, 0.5, 0],
49
+ [0, 0.6666, 0.5, 0]
50
+ ],
51
+ "green-magenta": [
52
+ [0.6666, 0.5, 0.5, 1],
53
+ [0.5, 0.6666, 0.5, 0],
54
+ [0.6666, 0.666, 0.5, 0],
55
+ [0.2, 0, 0.5, 0]
56
+ ],
57
+ "green-red": [
58
+ [0.5, 0.5, 0, 1],
59
+ [0.5, 0.5, 0, 0],
60
+ [0.5, 0.5, 0, 0],
61
+ [0.5, 0, 0, 0]
62
+ ],
63
+ heat1: [
64
+ [0.5, 0.4, 0.25, 1],
65
+ [0.5, 0.5, 0.666, 0],
66
+ [0.5, 0.666, 0.8, 0],
67
+ [0.5, 0.666, 0.8, 0]
68
+ ],
69
+ "magenta-green": [
70
+ [0.59, 0.811, 0.12, 1],
71
+ [0.41, 0.392, 0.59, 0],
72
+ [0.94, 0.548, 0.278, 0],
73
+ [-4.242, -6.611, -4.045, 0]
74
+ ],
75
+ "orange-blue": [
76
+ [0.5, 0.5, 0.5, 1],
77
+ [0.5, 0.5, 0.5, 0],
78
+ [0.8, 0.8, 0.5, 0],
79
+ [0, 0.2, 0.5, 0]
80
+ ],
81
+ "orange-magenta-blue": [
82
+ [0.821, 0.328, 0.242, 1],
83
+ [0.659, 0.481, 0.896, 0],
84
+ [0.612, 0.34, 0.296, 0],
85
+ [2.82, 3.026, -0.273, 0]
86
+ ],
87
+ "purple-orange-cyan": [
88
+ [0.5, 0.5, 0.5, 1],
89
+ [0.5, 0.5, 0.5, 0],
90
+ [0.5, 0.5, 1, 0],
91
+ [-0.25, 0.5, 1, 0]
92
+ ],
93
+ rainbow1: [
94
+ [0.5, 0.5, 0.5, 1],
95
+ [0.5, 0.5, 0.5, 0],
96
+ [1, 1, 1, 0],
97
+ [0, 0.3333, 0.6666, 0]
98
+ ],
99
+ rainbow2: [
100
+ [0.5, 0.5, 0.5, 1],
101
+ [0.666, 0.666, 0.666, 0],
102
+ [1, 1, 1, 0],
103
+ [0, 0.3333, 0.6666, 0]
104
+ ],
105
+ rainbow3: [
106
+ [0.5, 0.5, 0.5, 1],
107
+ [0.75, 0.75, 0.75, 0],
108
+ [1, 1, 1, 0],
109
+ [0, 0.3333, 0.6666, 0]
110
+ ],
111
+ rainbow4: [
112
+ [0.5, 0.5, 0.5, 1],
113
+ [1, 1, 1, 0],
114
+ [1, 1, 1, 0],
115
+ [0, 0.3333, 0.6666, 0]
116
+ ],
117
+ "red-blue": [
118
+ [0.5, 0, 0.5, 1],
119
+ [0.5, 0, 0.5, 0],
120
+ [0.5, 0, 0.5, 0],
121
+ [0, 0, 0.5, 0]
122
+ ],
123
+ "yellow-green-blue": [
124
+ [0.65, 0.5, 0.31, 1],
125
+ [-0.65, 0.5, 0.6, 0],
126
+ [0.333, 0.278, 0.278, 0],
127
+ [0.66, 0, 0.667, 0]
128
+ ],
129
+ "yellow-magenta-cyan": [
130
+ [1, 0.5, 0.5, 1],
131
+ [0.5, 0.5, 0.5, 0],
132
+ [0.75, 1, 0.6666, 0],
133
+ [0.8, 1, 0.3333, 0]
134
+ ],
135
+ "yellow-purple-magenta": [
136
+ [0.731, 1.098, 0.192, 1],
137
+ [0.358, 1.09, 0.657, 0],
138
+ [1.077, 0.36, 0.328, 0],
139
+ [0.965, 2.265, 0.837, 0]
140
+ ],
141
+ "yellow-red": [
142
+ [0.5, 0.5, 0, 1],
143
+ [0.5, 0.5, 0, 0],
144
+ [0.1, 0.5, 0, 0],
145
+ [0, 0, 0, 0]
146
+ ]
156
147
  };
157
- /**
158
- * Computes a single linear RGBA color for given gradient spec and normalized
159
- * position `t` (in [0..1] interval).
160
- *
161
- * @param spec -
162
- * @param t -
163
- */
164
- export const cosineColor = (spec, t) => transduce(map(([a, b, c, d]) => clamp01(a + b * Math.cos(TAU * (c * t + d)))), push(),
165
- // @ts-ignore
166
- zip(...spec));
167
- /**
168
- * Computes a full cosine gradient and returns an array of `n` sampled linear
169
- * RGBA colors. If the optional `tx` is given, each computed color will be
170
- * re-interpreted and/or transformed into another {@link Color} type.
171
- *
172
- * @remarks
173
- * For CSS/SVG use cases you could use {@link srgba} as transformation function
174
- * to not convert, but reinterpret & wrap raw color values as SRGBA.
175
- *
176
- * @param n -
177
- * @param spec -
178
- * @param tx -
179
- */
180
- export const cosineGradient = (n, spec, tx) => transduce(comp(map(partial(cosineColor, spec)), tx ? map(tx) : noop()), push(), normRange(n - 1));
181
- /**
182
- * Similar to {@link cosineGradient}, but writes results into `buffer` from
183
- * given `offset` and component/element strides. Returns buffer.
184
- *
185
- * @remarks
186
- * Intended use case for this function: 1D texturemap/tonemap generation, e.g.
187
- * for dataviz etc. Also @see {@link multiColorGradientBuffer}.
188
- *
189
- * @param n - number of colors
190
- * @param spec - gradient spec
191
- * @param buffer - target buffer/array
192
- * @param offset - start index (default: 0)
193
- * @param cstride - channel stride (default: 1)
194
- * @param estride - element stride (default: 4)
195
- */
196
- export const cosineGradientBuffer = (n, spec, buffer = [], offset = 0, cstride = 1, estride = 4) => {
197
- for (let t of normRange(n - 1)) {
198
- setS4(buffer, cosineColor(spec, t), offset, 0, cstride);
199
- offset += estride;
200
- }
201
- return buffer;
148
+ const cosineColor = (spec, t) => transduce(
149
+ map(
150
+ ([a, b, c, d]) => clamp01(a + b * Math.cos(TAU * (c * t + d)))
151
+ ),
152
+ push(),
153
+ // @ts-ignore
154
+ zip(...spec)
155
+ );
156
+ const cosineGradient = (n, spec, tx) => transduce(
157
+ comp(map(partial(cosineColor, spec)), tx ? map(tx) : noop()),
158
+ push(),
159
+ normRange(n - 1)
160
+ );
161
+ const cosineGradientBuffer = (n, spec, buffer = [], offset = 0, cstride = 1, estride = 4) => {
162
+ for (let t of normRange(n - 1)) {
163
+ setS4(buffer, cosineColor(spec, t), offset, 0, cstride);
164
+ offset += estride;
165
+ }
166
+ return buffer;
202
167
  };
203
- /**
204
- * Returns coefficients to produce a cosine gradient between the two
205
- * given RGBA colors.
206
- *
207
- * @param from - start color
208
- * @param to - end color
209
- */
210
- export const cosineCoeffs = (from, to) => {
211
- from = clamp([], from);
212
- to = clamp([], to);
213
- const amp = [...map(([a, b]) => 0.5 * (a - b), zip(from, to))];
214
- return [
215
- [...map(([s, a]) => s - a, zip(from, amp))],
216
- amp,
217
- [-0.5, -0.5, -0.5, -0.5],
218
- [0, 0, 0, 0],
219
- ];
168
+ const cosineCoeffs = (from, to) => {
169
+ from = clamp([], from);
170
+ to = clamp([], to);
171
+ const amp = [...map(([a, b]) => 0.5 * (a - b), zip(from, to))];
172
+ return [
173
+ [...map(([s, a]) => s - a, zip(from, amp))],
174
+ amp,
175
+ [-0.5, -0.5, -0.5, -0.5],
176
+ [0, 0, 0, 0]
177
+ ];
220
178
  };
221
- /**
222
- * Multi-color cosine gradient generator using linear RGBA color stops. Returns
223
- * an array of `n+1` linear RGBA color samples.
224
- *
225
- * @remarks
226
- * See
227
- * [`tween()`](https://docs.thi.ng/umbrella/transducers/functions/tween.html)
228
- *
229
- * @example
230
- * ```ts
231
- * multiCosineGradient({
232
- * num: 10,
233
- * // gradient stops (normalized positions)
234
- * stops: [[0.1, [1, 0, 0, 1]], [0.5, [0, 1, 0, 1]], [0.9, [0, 0, 1, 1]]],
235
- * // optional color transform/coercion
236
- * tx: srgba
237
- * })
238
- * ```
239
- *
240
- * @param num - number of color steps to produce
241
- * @param stops - gradient stops
242
- */
243
- export const multiCosineGradient = (opts) => transduce(opts.tx ? map(opts.tx) : noop(), push(), tween({
179
+ const multiCosineGradient = (opts) => transduce(
180
+ opts.tx ? map(opts.tx) : noop(),
181
+ push(),
182
+ tween({
244
183
  num: opts.num,
245
184
  stops: opts.stops,
246
185
  easing: opts.easing,
247
186
  min: 0,
248
187
  max: 1,
249
188
  init: cosineCoeffs,
250
- mix: cosineColor,
251
- }));
189
+ mix: cosineColor
190
+ })
191
+ );
192
+ export {
193
+ COSINE_GRADIENTS,
194
+ cosineCoeffs,
195
+ cosineColor,
196
+ cosineGradient,
197
+ cosineGradientBuffer,
198
+ multiCosineGradient
199
+ };
package/css/css.js CHANGED
@@ -15,59 +15,33 @@ import { oklchCss } from "../oklch/oklch-css.js";
15
15
  import { rgbCss } from "../rgb/rgb-css.js";
16
16
  import { rgbSrgb } from "../rgb/rgb-srgb.js";
17
17
  import { srgbCss } from "../srgb/srgb-css.js";
18
- export const CSS_LEVEL3 = {
19
- abgr32: (x) => intArgb32Css(intAbgr32Argb32(x[0])),
20
- argb32: (x) => intArgb32Css(x[0]),
21
- hsl: hslCss,
22
- hsv: hsvCss,
23
- lab50: (src) => srgbCss(rgbSrgb(null, labRgb([], src))),
24
- lab65: (src) => srgbCss(rgbSrgb(null, labRgbD65([], src))),
25
- lch: (src) => srgbCss(rgbSrgb(null, labRgb(null, lchLab([], src)))),
26
- rgb: rgbCss,
27
- srgb: srgbCss,
18
+ const CSS_LEVEL3 = {
19
+ abgr32: (x) => intArgb32Css(intAbgr32Argb32(x[0])),
20
+ argb32: (x) => intArgb32Css(x[0]),
21
+ hsl: hslCss,
22
+ hsv: hsvCss,
23
+ lab50: (src) => srgbCss(rgbSrgb(null, labRgb([], src))),
24
+ lab65: (src) => srgbCss(rgbSrgb(null, labRgbD65([], src))),
25
+ lch: (src) => srgbCss(rgbSrgb(null, labRgb(null, lchLab([], src)))),
26
+ rgb: rgbCss,
27
+ srgb: srgbCss
28
28
  };
29
- /**
30
- * Extended set of direct CSS conversions for use with CSS Color Module Level 4.
31
- * Based on {@link CSS_LEVEL3}.
32
- */
33
- export const CSS_LEVEL4 = {
34
- ...CSS_LEVEL3,
35
- lab50: labCss,
36
- lab65: (x) => labCss(labLabD65_50([], x)),
37
- lch: lchCss,
38
- oklab: oklabCss,
39
- oklch: oklchCss,
29
+ const CSS_LEVEL4 = {
30
+ ...CSS_LEVEL3,
31
+ lab50: labCss,
32
+ lab65: (x) => labCss(labLabD65_50([], x)),
33
+ lch: lchCss,
34
+ oklab: oklabCss,
35
+ oklch: oklchCss
40
36
  };
41
- /**
42
- * Takes a color in one of the following formats and tries to convert it to a
43
- * CSS string.
44
- *
45
- * @remarks
46
- * The following input formats are supported:
47
- *
48
- * - any {@link TypedColor} instance
49
- * - raw sRGB(A) vector
50
- * - number (packed 0xaarrggbb int, MUST provide alpha channel)
51
- * - string (passthrough)
52
- *
53
- * If CSS Color Module Level 4 support is desired, pass {@link CSS_LEVEL4} as
54
- * 2nd argument.
55
- *
56
- * If no direct conversion route for a given source color mode exists, the color
57
- * will be first converted to sRGB and serialized as such.
58
- *
59
- * @param col - source color
60
- * @param cssTarget - CSS conversions
61
- */
62
- export const css = (src, cssTarget = CSS_LEVEL3) => {
63
- let asCss;
64
- return isString(src)
65
- ? src
66
- : isNumber(src)
67
- ? intArgb32Css(src)
68
- : src.mode
69
- ? (asCss = cssTarget[src.mode])
70
- ? asCss(src)
71
- : cssTarget.rgb(convert([], src, "rgb", src.mode))
72
- : srgbCss(src);
37
+ const css = (src, cssTarget = CSS_LEVEL3) => {
38
+ let asCss;
39
+ return isString(src) ? src : isNumber(src) ? intArgb32Css(src) : src.mode ? (asCss = cssTarget[src.mode]) ? asCss(src) : cssTarget.rgb(
40
+ convert([], src, "rgb", src.mode)
41
+ ) : srgbCss(src);
42
+ };
43
+ export {
44
+ CSS_LEVEL3,
45
+ CSS_LEVEL4,
46
+ css
73
47
  };