@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.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/alpha.js +6 -10
- package/analog.js +35 -67
- package/api/constants.js +128 -156
- package/api/gradients.js +0 -1
- package/api/names.js +154 -151
- package/api/ranges.js +0 -1
- package/api/system.js +21 -26
- package/api.js +27 -32
- package/clamp.js +18 -29
- package/closest-hue.js +6 -12
- package/color-range.js +159 -228
- package/color.js +29 -28
- package/contrast.js +7 -17
- package/convert.js +19 -40
- package/cosine-gradients.js +177 -229
- package/css/css.js +27 -53
- package/css/parse-css.js +94 -160
- package/defcolor.js +97 -108
- package/distance.js +96 -187
- package/gradients.js +29 -37
- package/hcy/hcy-rgb.js +20 -13
- package/hcy/hcy.js +9 -11
- package/hsi/hsi-rgb.js +32 -30
- package/hsi/hsi.js +9 -11
- package/hsl/hsl-css.js +9 -10
- package/hsl/hsl-hsv.js +12 -9
- package/hsl/hsl-rgb.js +14 -6
- package/hsl/hsl.js +14 -16
- package/hsv/hsv-css.js +4 -1
- package/hsv/hsv-hsl.js +11 -8
- package/hsv/hsv-rgb.js +14 -6
- package/hsv/hsv.js +14 -16
- package/hue.js +12 -12
- package/int/int-css.js +10 -6
- package/int/int-int.js +6 -10
- package/int/int-rgb.js +16 -5
- package/int/int-srgb.js +22 -4
- package/int/int.js +136 -142
- package/internal/css.js +16 -12
- package/internal/dispatch.js +6 -2
- package/internal/ensure.js +18 -16
- package/internal/matrix-ops.js +39 -41
- package/internal/scale.js +4 -2
- package/invert.js +46 -39
- package/is-black.js +12 -5
- package/is-gamut.js +8 -13
- package/is-gray.js +12 -5
- package/is-white.js +14 -7
- package/lab/lab-css.js +4 -9
- package/lab/lab-lab.js +6 -2
- package/lab/lab-lch.js +18 -10
- package/lab/lab-rgb.js +6 -14
- package/lab/lab-xyz.js +16 -20
- package/lab/lab50.js +18 -15
- package/lab/lab65.js +18 -15
- package/lch/lch-css.js +4 -9
- package/lch/lch.js +18 -23
- package/lighten.js +13 -17
- package/linear.js +6 -16
- package/luminance-rgb.js +14 -22
- package/luminance.js +16 -14
- package/max-chroma.js +1340 -227
- package/mix.js +34 -82
- package/oklab/oklab-css.js +4 -9
- package/oklab/oklab-rgb.js +17 -23
- package/oklab/oklab-xyz.js +22 -9
- package/oklab/oklab.js +19 -22
- package/oklch/oklab-oklch.js +10 -11
- package/oklch/oklch-css.js +4 -9
- package/oklch/oklch-oklab.js +9 -9
- package/oklch/oklch.js +14 -20
- package/package.json +19 -17
- package/rgb/hue-rgb.js +14 -11
- package/rgb/kelvin-rgba.js +23 -22
- package/rgb/rgb-css.js +4 -1
- package/rgb/rgb-hcv.js +14 -15
- package/rgb/rgb-hcy.js +10 -14
- package/rgb/rgb-hsi.js +13 -8
- package/rgb/rgb-hsl.js +8 -5
- package/rgb/rgb-hsv.js +7 -4
- package/rgb/rgb-lab.js +6 -18
- package/rgb/rgb-oklab.js +13 -19
- package/rgb/rgb-srgb.js +18 -8
- package/rgb/rgb-xyz.js +6 -19
- package/rgb/rgb-ycc.js +12 -17
- package/rgb/rgb.js +25 -22
- package/rotate.js +25 -38
- package/sort.js +24 -72
- package/srgb/srgb-css.js +9 -9
- package/srgb/srgb-int.js +6 -10
- package/srgb/srgb-rgb.js +18 -8
- package/srgb/srgb.js +16 -13
- package/strategies.js +42 -112
- package/swatches.js +28 -5
- package/tint.js +27 -53
- package/transform.js +274 -149
- package/variations.js +10 -9
- package/xyy/xyy-xyz.js +12 -11
- package/xyy/xyy.js +16 -13
- package/xyz/wavelength-xyz.js +14 -28
- package/xyz/xyz-lab.js +17 -26
- package/xyz/xyz-oklab.js +4 -1
- package/xyz/xyz-rgb.js +6 -18
- package/xyz/xyz-xyy.js +13 -12
- package/xyz/xyz-xyz.js +6 -2
- package/xyz/xyz50.js +20 -17
- package/xyz/xyz65.js +20 -17
- package/ycc/ycc-rgb.js +14 -19
- package/ycc/ycc.js +12 -9
package/cosine-gradients.js
CHANGED
|
@@ -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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
],
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
],
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
],
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
],
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
],
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
],
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
],
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
],
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
],
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
],
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
],
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
],
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
],
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
],
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
],
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
],
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
],
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
],
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
],
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
],
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
159
|
-
*
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
*
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
223
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
};
|