@terrazzo/plugin-css 0.7.4 → 0.8.1
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 +20 -0
- package/README.md +2 -0
- package/dist/index.d.ts +75 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3150 -84
- package/dist/index.js.map +1 -1
- package/package.json +15 -12
- package/dist/build/index.d.ts +0 -11
- package/dist/build/index.d.ts.map +0 -1
- package/dist/build/index.js +0 -132
- package/dist/build/index.js.map +0 -1
- package/dist/build/utility-css.d.ts +0 -4
- package/dist/build/utility-css.d.ts.map +0 -1
- package/dist/build/utility-css.js +0 -215
- package/dist/build/utility-css.js.map +0 -1
- package/dist/lib.d.ts +0 -57
- package/dist/lib.d.ts.map +0 -1
- package/dist/lib.js +0 -66
- package/dist/lib.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,87 +1,3153 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/rgb/parseNumber.js
|
|
2
|
+
const parseNumber = (color, len) => {
|
|
3
|
+
if (typeof color !== "number") return;
|
|
4
|
+
if (len === 3) return {
|
|
5
|
+
mode: "rgb",
|
|
6
|
+
r: (color >> 8 & 15 | color >> 4 & 240) / 255,
|
|
7
|
+
g: (color >> 4 & 15 | color & 240) / 255,
|
|
8
|
+
b: (color & 15 | color << 4 & 240) / 255
|
|
9
|
+
};
|
|
10
|
+
if (len === 4) return {
|
|
11
|
+
mode: "rgb",
|
|
12
|
+
r: (color >> 12 & 15 | color >> 8 & 240) / 255,
|
|
13
|
+
g: (color >> 8 & 15 | color >> 4 & 240) / 255,
|
|
14
|
+
b: (color >> 4 & 15 | color & 240) / 255,
|
|
15
|
+
alpha: (color & 15 | color << 4 & 240) / 255
|
|
16
|
+
};
|
|
17
|
+
if (len === 6) return {
|
|
18
|
+
mode: "rgb",
|
|
19
|
+
r: (color >> 16 & 255) / 255,
|
|
20
|
+
g: (color >> 8 & 255) / 255,
|
|
21
|
+
b: (color & 255) / 255
|
|
22
|
+
};
|
|
23
|
+
if (len === 8) return {
|
|
24
|
+
mode: "rgb",
|
|
25
|
+
r: (color >> 24 & 255) / 255,
|
|
26
|
+
g: (color >> 16 & 255) / 255,
|
|
27
|
+
b: (color >> 8 & 255) / 255,
|
|
28
|
+
alpha: (color & 255) / 255
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
var parseNumber_default = parseNumber;
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/colors/named.js
|
|
35
|
+
const named = {
|
|
36
|
+
aliceblue: 15792383,
|
|
37
|
+
antiquewhite: 16444375,
|
|
38
|
+
aqua: 65535,
|
|
39
|
+
aquamarine: 8388564,
|
|
40
|
+
azure: 15794175,
|
|
41
|
+
beige: 16119260,
|
|
42
|
+
bisque: 16770244,
|
|
43
|
+
black: 0,
|
|
44
|
+
blanchedalmond: 16772045,
|
|
45
|
+
blue: 255,
|
|
46
|
+
blueviolet: 9055202,
|
|
47
|
+
brown: 10824234,
|
|
48
|
+
burlywood: 14596231,
|
|
49
|
+
cadetblue: 6266528,
|
|
50
|
+
chartreuse: 8388352,
|
|
51
|
+
chocolate: 13789470,
|
|
52
|
+
coral: 16744272,
|
|
53
|
+
cornflowerblue: 6591981,
|
|
54
|
+
cornsilk: 16775388,
|
|
55
|
+
crimson: 14423100,
|
|
56
|
+
cyan: 65535,
|
|
57
|
+
darkblue: 139,
|
|
58
|
+
darkcyan: 35723,
|
|
59
|
+
darkgoldenrod: 12092939,
|
|
60
|
+
darkgray: 11119017,
|
|
61
|
+
darkgreen: 25600,
|
|
62
|
+
darkgrey: 11119017,
|
|
63
|
+
darkkhaki: 12433259,
|
|
64
|
+
darkmagenta: 9109643,
|
|
65
|
+
darkolivegreen: 5597999,
|
|
66
|
+
darkorange: 16747520,
|
|
67
|
+
darkorchid: 10040012,
|
|
68
|
+
darkred: 9109504,
|
|
69
|
+
darksalmon: 15308410,
|
|
70
|
+
darkseagreen: 9419919,
|
|
71
|
+
darkslateblue: 4734347,
|
|
72
|
+
darkslategray: 3100495,
|
|
73
|
+
darkslategrey: 3100495,
|
|
74
|
+
darkturquoise: 52945,
|
|
75
|
+
darkviolet: 9699539,
|
|
76
|
+
deeppink: 16716947,
|
|
77
|
+
deepskyblue: 49151,
|
|
78
|
+
dimgray: 6908265,
|
|
79
|
+
dimgrey: 6908265,
|
|
80
|
+
dodgerblue: 2003199,
|
|
81
|
+
firebrick: 11674146,
|
|
82
|
+
floralwhite: 16775920,
|
|
83
|
+
forestgreen: 2263842,
|
|
84
|
+
fuchsia: 16711935,
|
|
85
|
+
gainsboro: 14474460,
|
|
86
|
+
ghostwhite: 16316671,
|
|
87
|
+
gold: 16766720,
|
|
88
|
+
goldenrod: 14329120,
|
|
89
|
+
gray: 8421504,
|
|
90
|
+
green: 32768,
|
|
91
|
+
greenyellow: 11403055,
|
|
92
|
+
grey: 8421504,
|
|
93
|
+
honeydew: 15794160,
|
|
94
|
+
hotpink: 16738740,
|
|
95
|
+
indianred: 13458524,
|
|
96
|
+
indigo: 4915330,
|
|
97
|
+
ivory: 16777200,
|
|
98
|
+
khaki: 15787660,
|
|
99
|
+
lavender: 15132410,
|
|
100
|
+
lavenderblush: 16773365,
|
|
101
|
+
lawngreen: 8190976,
|
|
102
|
+
lemonchiffon: 16775885,
|
|
103
|
+
lightblue: 11393254,
|
|
104
|
+
lightcoral: 15761536,
|
|
105
|
+
lightcyan: 14745599,
|
|
106
|
+
lightgoldenrodyellow: 16448210,
|
|
107
|
+
lightgray: 13882323,
|
|
108
|
+
lightgreen: 9498256,
|
|
109
|
+
lightgrey: 13882323,
|
|
110
|
+
lightpink: 16758465,
|
|
111
|
+
lightsalmon: 16752762,
|
|
112
|
+
lightseagreen: 2142890,
|
|
113
|
+
lightskyblue: 8900346,
|
|
114
|
+
lightslategray: 7833753,
|
|
115
|
+
lightslategrey: 7833753,
|
|
116
|
+
lightsteelblue: 11584734,
|
|
117
|
+
lightyellow: 16777184,
|
|
118
|
+
lime: 65280,
|
|
119
|
+
limegreen: 3329330,
|
|
120
|
+
linen: 16445670,
|
|
121
|
+
magenta: 16711935,
|
|
122
|
+
maroon: 8388608,
|
|
123
|
+
mediumaquamarine: 6737322,
|
|
124
|
+
mediumblue: 205,
|
|
125
|
+
mediumorchid: 12211667,
|
|
126
|
+
mediumpurple: 9662683,
|
|
127
|
+
mediumseagreen: 3978097,
|
|
128
|
+
mediumslateblue: 8087790,
|
|
129
|
+
mediumspringgreen: 64154,
|
|
130
|
+
mediumturquoise: 4772300,
|
|
131
|
+
mediumvioletred: 13047173,
|
|
132
|
+
midnightblue: 1644912,
|
|
133
|
+
mintcream: 16121850,
|
|
134
|
+
mistyrose: 16770273,
|
|
135
|
+
moccasin: 16770229,
|
|
136
|
+
navajowhite: 16768685,
|
|
137
|
+
navy: 128,
|
|
138
|
+
oldlace: 16643558,
|
|
139
|
+
olive: 8421376,
|
|
140
|
+
olivedrab: 7048739,
|
|
141
|
+
orange: 16753920,
|
|
142
|
+
orangered: 16729344,
|
|
143
|
+
orchid: 14315734,
|
|
144
|
+
palegoldenrod: 15657130,
|
|
145
|
+
palegreen: 10025880,
|
|
146
|
+
paleturquoise: 11529966,
|
|
147
|
+
palevioletred: 14381203,
|
|
148
|
+
papayawhip: 16773077,
|
|
149
|
+
peachpuff: 16767673,
|
|
150
|
+
peru: 13468991,
|
|
151
|
+
pink: 16761035,
|
|
152
|
+
plum: 14524637,
|
|
153
|
+
powderblue: 11591910,
|
|
154
|
+
purple: 8388736,
|
|
155
|
+
rebeccapurple: 6697881,
|
|
156
|
+
red: 16711680,
|
|
157
|
+
rosybrown: 12357519,
|
|
158
|
+
royalblue: 4286945,
|
|
159
|
+
saddlebrown: 9127187,
|
|
160
|
+
salmon: 16416882,
|
|
161
|
+
sandybrown: 16032864,
|
|
162
|
+
seagreen: 3050327,
|
|
163
|
+
seashell: 16774638,
|
|
164
|
+
sienna: 10506797,
|
|
165
|
+
silver: 12632256,
|
|
166
|
+
skyblue: 8900331,
|
|
167
|
+
slateblue: 6970061,
|
|
168
|
+
slategray: 7372944,
|
|
169
|
+
slategrey: 7372944,
|
|
170
|
+
snow: 16775930,
|
|
171
|
+
springgreen: 65407,
|
|
172
|
+
steelblue: 4620980,
|
|
173
|
+
tan: 13808780,
|
|
174
|
+
teal: 32896,
|
|
175
|
+
thistle: 14204888,
|
|
176
|
+
tomato: 16737095,
|
|
177
|
+
turquoise: 4251856,
|
|
178
|
+
violet: 15631086,
|
|
179
|
+
wheat: 16113331,
|
|
180
|
+
white: 16777215,
|
|
181
|
+
whitesmoke: 16119285,
|
|
182
|
+
yellow: 16776960,
|
|
183
|
+
yellowgreen: 10145074
|
|
184
|
+
};
|
|
185
|
+
var named_default = named;
|
|
186
|
+
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/rgb/parseNamed.js
|
|
189
|
+
const parseNamed = (color) => {
|
|
190
|
+
return parseNumber_default(named_default[color.toLowerCase()], 6);
|
|
191
|
+
};
|
|
192
|
+
var parseNamed_default = parseNamed;
|
|
193
|
+
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/rgb/parseHex.js
|
|
196
|
+
const hex = /^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i;
|
|
197
|
+
const parseHex = (color) => {
|
|
198
|
+
let match;
|
|
199
|
+
return (match = color.match(hex)) ? parseNumber_default(parseInt(match[1], 16), match[1].length) : void 0;
|
|
200
|
+
};
|
|
201
|
+
var parseHex_default = parseHex;
|
|
202
|
+
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/util/regex.js
|
|
205
|
+
const num$1 = "([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)";
|
|
206
|
+
const num_none = `(?:${num$1}|none)`;
|
|
207
|
+
const per = `${num$1}%`;
|
|
208
|
+
const per_none = `(?:${num$1}%|none)`;
|
|
209
|
+
const num_per = `(?:${num$1}%|${num$1})`;
|
|
210
|
+
const num_per_none = `(?:${num$1}%|${num$1}|none)`;
|
|
211
|
+
const hue$1 = `(?:${num$1}(deg|grad|rad|turn)|${num$1})`;
|
|
212
|
+
const hue_none = `(?:${num$1}(deg|grad|rad|turn)|${num$1}|none)`;
|
|
213
|
+
const c = `\\s*,\\s*`;
|
|
214
|
+
const rx_num_per_none = new RegExp("^" + num_per_none + "$");
|
|
215
|
+
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/rgb/parseRgbLegacy.js
|
|
218
|
+
const rgb_num_old = new RegExp(`^rgba?\\(\\s*${num$1}${c}${num$1}${c}${num$1}\\s*(?:,\\s*${num_per}\\s*)?\\)$`);
|
|
219
|
+
const rgb_per_old = new RegExp(`^rgba?\\(\\s*${per}${c}${per}${c}${per}\\s*(?:,\\s*${num_per}\\s*)?\\)$`);
|
|
220
|
+
const parseRgbLegacy = (color) => {
|
|
221
|
+
let res = { mode: "rgb" };
|
|
222
|
+
let match;
|
|
223
|
+
if (match = color.match(rgb_num_old)) {
|
|
224
|
+
if (match[1] !== void 0) res.r = match[1] / 255;
|
|
225
|
+
if (match[2] !== void 0) res.g = match[2] / 255;
|
|
226
|
+
if (match[3] !== void 0) res.b = match[3] / 255;
|
|
227
|
+
} else if (match = color.match(rgb_per_old)) {
|
|
228
|
+
if (match[1] !== void 0) res.r = match[1] / 100;
|
|
229
|
+
if (match[2] !== void 0) res.g = match[2] / 100;
|
|
230
|
+
if (match[3] !== void 0) res.b = match[3] / 100;
|
|
231
|
+
} else return void 0;
|
|
232
|
+
if (match[4] !== void 0) res.alpha = Math.max(0, Math.min(1, match[4] / 100));
|
|
233
|
+
else if (match[5] !== void 0) res.alpha = Math.max(0, Math.min(1, +match[5]));
|
|
234
|
+
return res;
|
|
235
|
+
};
|
|
236
|
+
var parseRgbLegacy_default = parseRgbLegacy;
|
|
237
|
+
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/_prepare.js
|
|
240
|
+
const prepare = (color, mode) => color === void 0 ? void 0 : typeof color !== "object" ? parse_default(color) : color.mode !== void 0 ? color : mode ? {
|
|
241
|
+
...color,
|
|
242
|
+
mode
|
|
243
|
+
} : void 0;
|
|
244
|
+
var _prepare_default = prepare;
|
|
245
|
+
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/converter.js
|
|
248
|
+
const converter = (target_mode = "rgb") => (color) => (color = _prepare_default(color, target_mode)) !== void 0 ? color.mode === target_mode ? color : converters$1[color.mode][target_mode] ? converters$1[color.mode][target_mode](color) : target_mode === "rgb" ? converters$1[color.mode].rgb(color) : converters$1.rgb[target_mode](converters$1[color.mode].rgb(color)) : void 0;
|
|
249
|
+
var converter_default = converter;
|
|
250
|
+
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/modes.js
|
|
253
|
+
const converters$1 = {};
|
|
254
|
+
const modes = {};
|
|
255
|
+
const parsers = [];
|
|
256
|
+
const colorProfiles = {};
|
|
257
|
+
const identity = (v) => v;
|
|
258
|
+
const useMode = (definition$15) => {
|
|
259
|
+
converters$1[definition$15.mode] = {
|
|
260
|
+
...converters$1[definition$15.mode],
|
|
261
|
+
...definition$15.toMode
|
|
262
|
+
};
|
|
263
|
+
Object.keys(definition$15.fromMode || {}).forEach((k$2) => {
|
|
264
|
+
if (!converters$1[k$2]) converters$1[k$2] = {};
|
|
265
|
+
converters$1[k$2][definition$15.mode] = definition$15.fromMode[k$2];
|
|
266
|
+
});
|
|
267
|
+
if (!definition$15.ranges) definition$15.ranges = {};
|
|
268
|
+
if (!definition$15.difference) definition$15.difference = {};
|
|
269
|
+
definition$15.channels.forEach((channel) => {
|
|
270
|
+
if (definition$15.ranges[channel] === void 0) definition$15.ranges[channel] = [0, 1];
|
|
271
|
+
if (!definition$15.interpolate[channel]) throw new Error(`Missing interpolator for: ${channel}`);
|
|
272
|
+
if (typeof definition$15.interpolate[channel] === "function") definition$15.interpolate[channel] = { use: definition$15.interpolate[channel] };
|
|
273
|
+
if (!definition$15.interpolate[channel].fixup) definition$15.interpolate[channel].fixup = identity;
|
|
274
|
+
});
|
|
275
|
+
modes[definition$15.mode] = definition$15;
|
|
276
|
+
(definition$15.parse || []).forEach((parser) => {
|
|
277
|
+
useParser(parser, definition$15.mode);
|
|
278
|
+
});
|
|
279
|
+
return converter_default(definition$15.mode);
|
|
280
|
+
};
|
|
281
|
+
const getMode = (mode) => modes[mode];
|
|
282
|
+
const useParser = (parser, mode) => {
|
|
283
|
+
if (typeof parser === "string") {
|
|
284
|
+
if (!mode) throw new Error(`'mode' required when 'parser' is a string`);
|
|
285
|
+
colorProfiles[parser] = mode;
|
|
286
|
+
} else if (typeof parser === "function") {
|
|
287
|
+
if (parsers.indexOf(parser) < 0) parsers.push(parser);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/parse.js
|
|
293
|
+
const IdentStartCodePoint = /[^\x00-\x7F]|[a-zA-Z_]/;
|
|
294
|
+
const IdentCodePoint = /[^\x00-\x7F]|[-\w]/;
|
|
295
|
+
const Tok = {
|
|
296
|
+
Function: "function",
|
|
297
|
+
Ident: "ident",
|
|
298
|
+
Number: "number",
|
|
299
|
+
Percentage: "percentage",
|
|
300
|
+
ParenClose: ")",
|
|
301
|
+
None: "none",
|
|
302
|
+
Hue: "hue",
|
|
303
|
+
Alpha: "alpha"
|
|
304
|
+
};
|
|
305
|
+
let _i = 0;
|
|
306
|
+
function is_num(chars) {
|
|
307
|
+
let ch = chars[_i];
|
|
308
|
+
let ch1 = chars[_i + 1];
|
|
309
|
+
if (ch === "-" || ch === "+") return /\d/.test(ch1) || ch1 === "." && /\d/.test(chars[_i + 2]);
|
|
310
|
+
if (ch === ".") return /\d/.test(ch1);
|
|
311
|
+
return /\d/.test(ch);
|
|
312
|
+
}
|
|
313
|
+
function is_ident(chars) {
|
|
314
|
+
if (_i >= chars.length) return false;
|
|
315
|
+
let ch = chars[_i];
|
|
316
|
+
if (IdentStartCodePoint.test(ch)) return true;
|
|
317
|
+
if (ch === "-") {
|
|
318
|
+
if (chars.length - _i < 2) return false;
|
|
319
|
+
let ch1 = chars[_i + 1];
|
|
320
|
+
if (ch1 === "-" || IdentStartCodePoint.test(ch1)) return true;
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
const huenits = {
|
|
326
|
+
deg: 1,
|
|
327
|
+
rad: 180 / Math.PI,
|
|
328
|
+
grad: 9 / 10,
|
|
329
|
+
turn: 360
|
|
330
|
+
};
|
|
331
|
+
function num(chars) {
|
|
332
|
+
let value = "";
|
|
333
|
+
if (chars[_i] === "-" || chars[_i] === "+") value += chars[_i++];
|
|
334
|
+
value += digits(chars);
|
|
335
|
+
if (chars[_i] === "." && /\d/.test(chars[_i + 1])) value += chars[_i++] + digits(chars);
|
|
336
|
+
if (chars[_i] === "e" || chars[_i] === "E") {
|
|
337
|
+
if ((chars[_i + 1] === "-" || chars[_i + 1] === "+") && /\d/.test(chars[_i + 2])) value += chars[_i++] + chars[_i++] + digits(chars);
|
|
338
|
+
else if (/\d/.test(chars[_i + 1])) value += chars[_i++] + digits(chars);
|
|
339
|
+
}
|
|
340
|
+
if (is_ident(chars)) {
|
|
341
|
+
let id = ident(chars);
|
|
342
|
+
if (id === "deg" || id === "rad" || id === "turn" || id === "grad") return {
|
|
343
|
+
type: Tok.Hue,
|
|
344
|
+
value: value * huenits[id]
|
|
345
|
+
};
|
|
346
|
+
return void 0;
|
|
347
|
+
}
|
|
348
|
+
if (chars[_i] === "%") {
|
|
349
|
+
_i++;
|
|
350
|
+
return {
|
|
351
|
+
type: Tok.Percentage,
|
|
352
|
+
value: +value
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
type: Tok.Number,
|
|
357
|
+
value: +value
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function digits(chars) {
|
|
361
|
+
let v = "";
|
|
362
|
+
while (/\d/.test(chars[_i])) v += chars[_i++];
|
|
363
|
+
return v;
|
|
364
|
+
}
|
|
365
|
+
function ident(chars) {
|
|
366
|
+
let v = "";
|
|
367
|
+
while (_i < chars.length && IdentCodePoint.test(chars[_i])) v += chars[_i++];
|
|
368
|
+
return v;
|
|
369
|
+
}
|
|
370
|
+
function identlike(chars) {
|
|
371
|
+
let v = ident(chars);
|
|
372
|
+
if (chars[_i] === "(") {
|
|
373
|
+
_i++;
|
|
374
|
+
return {
|
|
375
|
+
type: Tok.Function,
|
|
376
|
+
value: v
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
if (v === "none") return {
|
|
380
|
+
type: Tok.None,
|
|
381
|
+
value: void 0
|
|
382
|
+
};
|
|
383
|
+
return {
|
|
384
|
+
type: Tok.Ident,
|
|
385
|
+
value: v
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function tokenize(str = "") {
|
|
389
|
+
let chars = str.trim();
|
|
390
|
+
let tokens = [];
|
|
391
|
+
let ch;
|
|
392
|
+
_i = 0;
|
|
393
|
+
while (_i < chars.length) {
|
|
394
|
+
ch = chars[_i++];
|
|
395
|
+
if (ch === "\n" || ch === " " || ch === " ") {
|
|
396
|
+
while (_i < chars.length && (chars[_i] === "\n" || chars[_i] === " " || chars[_i] === " ")) _i++;
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
if (ch === ",") return void 0;
|
|
400
|
+
if (ch === ")") {
|
|
401
|
+
tokens.push({ type: Tok.ParenClose });
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
if (ch === "+") {
|
|
405
|
+
_i--;
|
|
406
|
+
if (is_num(chars)) {
|
|
407
|
+
tokens.push(num(chars));
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
return void 0;
|
|
411
|
+
}
|
|
412
|
+
if (ch === "-") {
|
|
413
|
+
_i--;
|
|
414
|
+
if (is_num(chars)) {
|
|
415
|
+
tokens.push(num(chars));
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
if (is_ident(chars)) {
|
|
419
|
+
tokens.push({
|
|
420
|
+
type: Tok.Ident,
|
|
421
|
+
value: ident(chars)
|
|
422
|
+
});
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
return void 0;
|
|
426
|
+
}
|
|
427
|
+
if (ch === ".") {
|
|
428
|
+
_i--;
|
|
429
|
+
if (is_num(chars)) {
|
|
430
|
+
tokens.push(num(chars));
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
return void 0;
|
|
434
|
+
}
|
|
435
|
+
if (ch === "/") {
|
|
436
|
+
while (_i < chars.length && (chars[_i] === "\n" || chars[_i] === " " || chars[_i] === " ")) _i++;
|
|
437
|
+
let alpha;
|
|
438
|
+
if (is_num(chars)) {
|
|
439
|
+
alpha = num(chars);
|
|
440
|
+
if (alpha.type !== Tok.Hue) {
|
|
441
|
+
tokens.push({
|
|
442
|
+
type: Tok.Alpha,
|
|
443
|
+
value: alpha
|
|
444
|
+
});
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if (is_ident(chars)) {
|
|
449
|
+
if (ident(chars) === "none") {
|
|
450
|
+
tokens.push({
|
|
451
|
+
type: Tok.Alpha,
|
|
452
|
+
value: {
|
|
453
|
+
type: Tok.None,
|
|
454
|
+
value: void 0
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return void 0;
|
|
461
|
+
}
|
|
462
|
+
if (/\d/.test(ch)) {
|
|
463
|
+
_i--;
|
|
464
|
+
tokens.push(num(chars));
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
if (IdentStartCodePoint.test(ch)) {
|
|
468
|
+
_i--;
|
|
469
|
+
tokens.push(identlike(chars));
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
return void 0;
|
|
473
|
+
}
|
|
474
|
+
return tokens;
|
|
475
|
+
}
|
|
476
|
+
function parseColorSyntax(tokens) {
|
|
477
|
+
tokens._i = 0;
|
|
478
|
+
let token = tokens[tokens._i++];
|
|
479
|
+
if (!token || token.type !== Tok.Function || token.value !== "color") return void 0;
|
|
480
|
+
token = tokens[tokens._i++];
|
|
481
|
+
if (token.type !== Tok.Ident) return void 0;
|
|
482
|
+
const mode = colorProfiles[token.value];
|
|
483
|
+
if (!mode) return void 0;
|
|
484
|
+
const res = { mode };
|
|
485
|
+
const coords = consumeCoords(tokens, false);
|
|
486
|
+
if (!coords) return void 0;
|
|
487
|
+
const channels = getMode(mode).channels;
|
|
488
|
+
for (let ii = 0, c$1, ch; ii < channels.length; ii++) {
|
|
489
|
+
c$1 = coords[ii];
|
|
490
|
+
ch = channels[ii];
|
|
491
|
+
if (c$1.type !== Tok.None) {
|
|
492
|
+
res[ch] = c$1.type === Tok.Number ? c$1.value : c$1.value / 100;
|
|
493
|
+
if (ch === "alpha") res[ch] = Math.max(0, Math.min(1, res[ch]));
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return res;
|
|
497
|
+
}
|
|
498
|
+
function consumeCoords(tokens, includeHue) {
|
|
499
|
+
const coords = [];
|
|
500
|
+
let token;
|
|
501
|
+
while (tokens._i < tokens.length) {
|
|
502
|
+
token = tokens[tokens._i++];
|
|
503
|
+
if (token.type === Tok.None || token.type === Tok.Number || token.type === Tok.Alpha || token.type === Tok.Percentage || includeHue && token.type === Tok.Hue) {
|
|
504
|
+
coords.push(token);
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
if (token.type === Tok.ParenClose) {
|
|
508
|
+
if (tokens._i < tokens.length) return void 0;
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
return void 0;
|
|
512
|
+
}
|
|
513
|
+
if (coords.length < 3 || coords.length > 4) return void 0;
|
|
514
|
+
if (coords.length === 4) {
|
|
515
|
+
if (coords[3].type !== Tok.Alpha) return void 0;
|
|
516
|
+
coords[3] = coords[3].value;
|
|
517
|
+
}
|
|
518
|
+
if (coords.length === 3) coords.push({
|
|
519
|
+
type: Tok.None,
|
|
520
|
+
value: void 0
|
|
521
|
+
});
|
|
522
|
+
return coords.every((c$1) => c$1.type !== Tok.Alpha) ? coords : void 0;
|
|
523
|
+
}
|
|
524
|
+
function parseModernSyntax(tokens, includeHue) {
|
|
525
|
+
tokens._i = 0;
|
|
526
|
+
let token = tokens[tokens._i++];
|
|
527
|
+
if (!token || token.type !== Tok.Function) return void 0;
|
|
528
|
+
let coords = consumeCoords(tokens, includeHue);
|
|
529
|
+
if (!coords) return void 0;
|
|
530
|
+
coords.unshift(token.value);
|
|
531
|
+
return coords;
|
|
532
|
+
}
|
|
533
|
+
const parse = (color) => {
|
|
534
|
+
if (typeof color !== "string") return void 0;
|
|
535
|
+
const tokens = tokenize(color);
|
|
536
|
+
const parsed = tokens ? parseModernSyntax(tokens, true) : void 0;
|
|
537
|
+
let result = void 0;
|
|
538
|
+
let i = 0;
|
|
539
|
+
let len = parsers.length;
|
|
540
|
+
while (i < len) if ((result = parsers[i++](color, parsed)) !== void 0) return result;
|
|
541
|
+
return tokens ? parseColorSyntax(tokens) : void 0;
|
|
542
|
+
};
|
|
543
|
+
var parse_default = parse;
|
|
544
|
+
|
|
545
|
+
//#endregion
|
|
546
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/rgb/parseRgb.js
|
|
547
|
+
function parseRgb(color, parsed) {
|
|
548
|
+
if (!parsed || parsed[0] !== "rgb" && parsed[0] !== "rgba") return void 0;
|
|
549
|
+
const res = { mode: "rgb" };
|
|
550
|
+
const [, r$1, g, b, alpha] = parsed;
|
|
551
|
+
if (r$1.type === Tok.Hue || g.type === Tok.Hue || b.type === Tok.Hue) return void 0;
|
|
552
|
+
if (r$1.type !== Tok.None) res.r = r$1.type === Tok.Number ? r$1.value / 255 : r$1.value / 100;
|
|
553
|
+
if (g.type !== Tok.None) res.g = g.type === Tok.Number ? g.value / 255 : g.value / 100;
|
|
554
|
+
if (b.type !== Tok.None) res.b = b.type === Tok.Number ? b.value / 255 : b.value / 100;
|
|
555
|
+
if (alpha.type !== Tok.None) res.alpha = Math.min(1, Math.max(0, alpha.type === Tok.Number ? alpha.value : alpha.value / 100));
|
|
556
|
+
return res;
|
|
557
|
+
}
|
|
558
|
+
var parseRgb_default = parseRgb;
|
|
559
|
+
|
|
560
|
+
//#endregion
|
|
561
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/rgb/parseTransparent.js
|
|
562
|
+
const parseTransparent = (c$1) => c$1 === "transparent" ? {
|
|
563
|
+
mode: "rgb",
|
|
564
|
+
r: 0,
|
|
565
|
+
g: 0,
|
|
566
|
+
b: 0,
|
|
567
|
+
alpha: 0
|
|
568
|
+
} : void 0;
|
|
569
|
+
var parseTransparent_default = parseTransparent;
|
|
570
|
+
|
|
571
|
+
//#endregion
|
|
572
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/interpolate/lerp.js
|
|
573
|
+
const lerp = (a, b, t) => a + t * (b - a);
|
|
574
|
+
|
|
575
|
+
//#endregion
|
|
576
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/interpolate/piecewise.js
|
|
577
|
+
const get_classes = (arr) => {
|
|
578
|
+
let classes = [];
|
|
579
|
+
for (let i = 0; i < arr.length - 1; i++) {
|
|
580
|
+
let a = arr[i];
|
|
581
|
+
let b = arr[i + 1];
|
|
582
|
+
if (a === void 0 && b === void 0) classes.push(void 0);
|
|
583
|
+
else if (a !== void 0 && b !== void 0) classes.push([a, b]);
|
|
584
|
+
else classes.push(a !== void 0 ? [a, a] : [b, b]);
|
|
585
|
+
}
|
|
586
|
+
return classes;
|
|
587
|
+
};
|
|
588
|
+
const interpolatorPiecewise = (interpolator) => (arr) => {
|
|
589
|
+
let classes = get_classes(arr);
|
|
590
|
+
return (t) => {
|
|
591
|
+
let cls = t * classes.length;
|
|
592
|
+
let idx = t >= 1 ? classes.length - 1 : Math.max(Math.floor(cls), 0);
|
|
593
|
+
let pair = classes[idx];
|
|
594
|
+
return pair === void 0 ? void 0 : interpolator(pair[0], pair[1], cls - idx);
|
|
595
|
+
};
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
//#endregion
|
|
599
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/interpolate/linear.js
|
|
600
|
+
const interpolatorLinear = interpolatorPiecewise(lerp);
|
|
601
|
+
|
|
602
|
+
//#endregion
|
|
603
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/fixup/alpha.js
|
|
604
|
+
const fixupAlpha = (arr) => {
|
|
605
|
+
let some_defined = false;
|
|
606
|
+
let res = arr.map((v) => {
|
|
607
|
+
if (v !== void 0) {
|
|
608
|
+
some_defined = true;
|
|
609
|
+
return v;
|
|
610
|
+
}
|
|
611
|
+
return 1;
|
|
612
|
+
});
|
|
613
|
+
return some_defined ? res : arr;
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
//#endregion
|
|
617
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/rgb/definition.js
|
|
618
|
+
const definition$14 = {
|
|
619
|
+
mode: "rgb",
|
|
620
|
+
channels: [
|
|
621
|
+
"r",
|
|
622
|
+
"g",
|
|
623
|
+
"b",
|
|
624
|
+
"alpha"
|
|
625
|
+
],
|
|
626
|
+
parse: [
|
|
627
|
+
parseRgb_default,
|
|
628
|
+
parseHex_default,
|
|
629
|
+
parseRgbLegacy_default,
|
|
630
|
+
parseNamed_default,
|
|
631
|
+
parseTransparent_default,
|
|
632
|
+
"srgb"
|
|
633
|
+
],
|
|
634
|
+
serialize: "srgb",
|
|
635
|
+
interpolate: {
|
|
636
|
+
r: interpolatorLinear,
|
|
637
|
+
g: interpolatorLinear,
|
|
638
|
+
b: interpolatorLinear,
|
|
639
|
+
alpha: {
|
|
640
|
+
use: interpolatorLinear,
|
|
641
|
+
fixup: fixupAlpha
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
gamut: true,
|
|
645
|
+
white: {
|
|
646
|
+
r: 1,
|
|
647
|
+
g: 1,
|
|
648
|
+
b: 1
|
|
649
|
+
},
|
|
650
|
+
black: {
|
|
651
|
+
r: 0,
|
|
652
|
+
g: 0,
|
|
653
|
+
b: 0
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
var definition_default$12 = definition$14;
|
|
657
|
+
|
|
658
|
+
//#endregion
|
|
659
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/a98/convertA98ToXyz65.js
|
|
660
|
+
const linearize$2 = (v = 0) => Math.pow(Math.abs(v), 563 / 256) * Math.sign(v);
|
|
661
|
+
const convertA98ToXyz65 = (a98) => {
|
|
662
|
+
let r$1 = linearize$2(a98.r);
|
|
663
|
+
let g = linearize$2(a98.g);
|
|
664
|
+
let b = linearize$2(a98.b);
|
|
665
|
+
let res = {
|
|
666
|
+
mode: "xyz65",
|
|
667
|
+
x: .5766690429101305 * r$1 + .1855582379065463 * g + .1882286462349947 * b,
|
|
668
|
+
y: .297344975250536 * r$1 + .6273635662554661 * g + .0752914584939979 * b,
|
|
669
|
+
z: .0270313613864123 * r$1 + .0706888525358272 * g + .9913375368376386 * b
|
|
670
|
+
};
|
|
671
|
+
if (a98.alpha !== void 0) res.alpha = a98.alpha;
|
|
672
|
+
return res;
|
|
673
|
+
};
|
|
674
|
+
var convertA98ToXyz65_default = convertA98ToXyz65;
|
|
675
|
+
|
|
676
|
+
//#endregion
|
|
677
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/a98/convertXyz65ToA98.js
|
|
678
|
+
const gamma$2 = (v) => Math.pow(Math.abs(v), 256 / 563) * Math.sign(v);
|
|
679
|
+
const convertXyz65ToA98 = ({ x, y, z, alpha }) => {
|
|
680
|
+
if (x === void 0) x = 0;
|
|
681
|
+
if (y === void 0) y = 0;
|
|
682
|
+
if (z === void 0) z = 0;
|
|
683
|
+
let res = {
|
|
684
|
+
mode: "a98",
|
|
685
|
+
r: gamma$2(x * 2.0415879038107465 - y * .5650069742788597 - .3447313507783297 * z),
|
|
686
|
+
g: gamma$2(x * -.9692436362808798 + y * 1.8759675015077206 + .0415550574071756 * z),
|
|
687
|
+
b: gamma$2(x * .0134442806320312 - y * .1183623922310184 + 1.0151749943912058 * z)
|
|
688
|
+
};
|
|
689
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
690
|
+
return res;
|
|
691
|
+
};
|
|
692
|
+
var convertXyz65ToA98_default = convertXyz65ToA98;
|
|
693
|
+
|
|
694
|
+
//#endregion
|
|
695
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/lrgb/convertRgbToLrgb.js
|
|
696
|
+
const fn$2 = (c$1 = 0) => {
|
|
697
|
+
const abs = Math.abs(c$1);
|
|
698
|
+
if (abs <= .04045) return c$1 / 12.92;
|
|
699
|
+
return (Math.sign(c$1) || 1) * Math.pow((abs + .055) / 1.055, 2.4);
|
|
700
|
+
};
|
|
701
|
+
const convertRgbToLrgb = ({ r: r$1, g, b, alpha }) => {
|
|
702
|
+
let res = {
|
|
703
|
+
mode: "lrgb",
|
|
704
|
+
r: fn$2(r$1),
|
|
705
|
+
g: fn$2(g),
|
|
706
|
+
b: fn$2(b)
|
|
707
|
+
};
|
|
708
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
709
|
+
return res;
|
|
710
|
+
};
|
|
711
|
+
var convertRgbToLrgb_default = convertRgbToLrgb;
|
|
712
|
+
|
|
713
|
+
//#endregion
|
|
714
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/xyz65/convertRgbToXyz65.js
|
|
715
|
+
const convertRgbToXyz65 = (rgb$2) => {
|
|
716
|
+
let { r: r$1, g, b, alpha } = convertRgbToLrgb_default(rgb$2);
|
|
717
|
+
let res = {
|
|
718
|
+
mode: "xyz65",
|
|
719
|
+
x: .4123907992659593 * r$1 + .357584339383878 * g + .1804807884018343 * b,
|
|
720
|
+
y: .2126390058715102 * r$1 + .715168678767756 * g + .0721923153607337 * b,
|
|
721
|
+
z: .0193308187155918 * r$1 + .119194779794626 * g + .9505321522496607 * b
|
|
722
|
+
};
|
|
723
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
724
|
+
return res;
|
|
725
|
+
};
|
|
726
|
+
var convertRgbToXyz65_default = convertRgbToXyz65;
|
|
727
|
+
|
|
728
|
+
//#endregion
|
|
729
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/lrgb/convertLrgbToRgb.js
|
|
730
|
+
const fn$1 = (c$1 = 0) => {
|
|
731
|
+
const abs = Math.abs(c$1);
|
|
732
|
+
if (abs > .0031308) return (Math.sign(c$1) || 1) * (1.055 * Math.pow(abs, 1 / 2.4) - .055);
|
|
733
|
+
return c$1 * 12.92;
|
|
734
|
+
};
|
|
735
|
+
const convertLrgbToRgb = ({ r: r$1, g, b, alpha }, mode = "rgb") => {
|
|
736
|
+
let res = {
|
|
737
|
+
mode,
|
|
738
|
+
r: fn$1(r$1),
|
|
739
|
+
g: fn$1(g),
|
|
740
|
+
b: fn$1(b)
|
|
741
|
+
};
|
|
742
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
743
|
+
return res;
|
|
744
|
+
};
|
|
745
|
+
var convertLrgbToRgb_default = convertLrgbToRgb;
|
|
746
|
+
|
|
747
|
+
//#endregion
|
|
748
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/xyz65/convertXyz65ToRgb.js
|
|
749
|
+
const convertXyz65ToRgb = ({ x, y, z, alpha }) => {
|
|
750
|
+
if (x === void 0) x = 0;
|
|
751
|
+
if (y === void 0) y = 0;
|
|
752
|
+
if (z === void 0) z = 0;
|
|
753
|
+
let res = convertLrgbToRgb_default({
|
|
754
|
+
r: x * 3.2409699419045226 - y * 1.537383177570094 - .4986107602930034 * z,
|
|
755
|
+
g: x * -.9692436362808796 + y * 1.8759675015077204 + .0415550574071756 * z,
|
|
756
|
+
b: x * .0556300796969936 - y * .2039769588889765 + 1.0569715142428784 * z
|
|
757
|
+
});
|
|
758
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
759
|
+
return res;
|
|
760
|
+
};
|
|
761
|
+
var convertXyz65ToRgb_default = convertXyz65ToRgb;
|
|
762
|
+
|
|
763
|
+
//#endregion
|
|
764
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/a98/definition.js
|
|
765
|
+
const definition$13 = {
|
|
766
|
+
...definition_default$12,
|
|
767
|
+
mode: "a98",
|
|
768
|
+
parse: ["a98-rgb"],
|
|
769
|
+
serialize: "a98-rgb",
|
|
770
|
+
fromMode: {
|
|
771
|
+
rgb: (color) => convertXyz65ToA98_default(convertRgbToXyz65_default(color)),
|
|
772
|
+
xyz65: convertXyz65ToA98_default
|
|
773
|
+
},
|
|
774
|
+
toMode: {
|
|
775
|
+
rgb: (color) => convertXyz65ToRgb_default(convertA98ToXyz65_default(color)),
|
|
776
|
+
xyz65: convertA98ToXyz65_default
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
var definition_default = definition$13;
|
|
780
|
+
|
|
781
|
+
//#endregion
|
|
782
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/util/normalizeHue.js
|
|
783
|
+
const normalizeHue = (hue$2) => (hue$2 = hue$2 % 360) < 0 ? hue$2 + 360 : hue$2;
|
|
784
|
+
var normalizeHue_default = normalizeHue;
|
|
785
|
+
|
|
786
|
+
//#endregion
|
|
787
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/hsl/convertHslToRgb.js
|
|
788
|
+
function convertHslToRgb({ h, s, l, alpha }) {
|
|
789
|
+
h = normalizeHue_default(h !== void 0 ? h : 0);
|
|
790
|
+
if (s === void 0) s = 0;
|
|
791
|
+
if (l === void 0) l = 0;
|
|
792
|
+
let m1 = l + s * (l < .5 ? l : 1 - l);
|
|
793
|
+
let m2 = m1 - (m1 - l) * 2 * Math.abs(h / 60 % 2 - 1);
|
|
794
|
+
let res;
|
|
795
|
+
switch (Math.floor(h / 60)) {
|
|
796
|
+
case 0:
|
|
797
|
+
res = {
|
|
798
|
+
r: m1,
|
|
799
|
+
g: m2,
|
|
800
|
+
b: 2 * l - m1
|
|
801
|
+
};
|
|
802
|
+
break;
|
|
803
|
+
case 1:
|
|
804
|
+
res = {
|
|
805
|
+
r: m2,
|
|
806
|
+
g: m1,
|
|
807
|
+
b: 2 * l - m1
|
|
808
|
+
};
|
|
809
|
+
break;
|
|
810
|
+
case 2:
|
|
811
|
+
res = {
|
|
812
|
+
r: 2 * l - m1,
|
|
813
|
+
g: m1,
|
|
814
|
+
b: m2
|
|
815
|
+
};
|
|
816
|
+
break;
|
|
817
|
+
case 3:
|
|
818
|
+
res = {
|
|
819
|
+
r: 2 * l - m1,
|
|
820
|
+
g: m2,
|
|
821
|
+
b: m1
|
|
822
|
+
};
|
|
823
|
+
break;
|
|
824
|
+
case 4:
|
|
825
|
+
res = {
|
|
826
|
+
r: m2,
|
|
827
|
+
g: 2 * l - m1,
|
|
828
|
+
b: m1
|
|
829
|
+
};
|
|
830
|
+
break;
|
|
831
|
+
case 5:
|
|
832
|
+
res = {
|
|
833
|
+
r: m1,
|
|
834
|
+
g: 2 * l - m1,
|
|
835
|
+
b: m2
|
|
836
|
+
};
|
|
837
|
+
break;
|
|
838
|
+
default: res = {
|
|
839
|
+
r: 2 * l - m1,
|
|
840
|
+
g: 2 * l - m1,
|
|
841
|
+
b: 2 * l - m1
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
res.mode = "rgb";
|
|
845
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
846
|
+
return res;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
//#endregion
|
|
850
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/hsl/convertRgbToHsl.js
|
|
851
|
+
function convertRgbToHsl({ r: r$1, g, b, alpha }) {
|
|
852
|
+
if (r$1 === void 0) r$1 = 0;
|
|
853
|
+
if (g === void 0) g = 0;
|
|
854
|
+
if (b === void 0) b = 0;
|
|
855
|
+
let M = Math.max(r$1, g, b), m = Math.min(r$1, g, b);
|
|
856
|
+
let res = {
|
|
857
|
+
mode: "hsl",
|
|
858
|
+
s: M === m ? 0 : (M - m) / (1 - Math.abs(M + m - 1)),
|
|
859
|
+
l: .5 * (M + m)
|
|
860
|
+
};
|
|
861
|
+
if (M - m !== 0) res.h = (M === r$1 ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r$1) / (M - m) + 2 : (r$1 - g) / (M - m) + 4) * 60;
|
|
862
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
863
|
+
return res;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
//#endregion
|
|
867
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/util/hue.js
|
|
868
|
+
const hueToDeg = (val, unit) => {
|
|
869
|
+
switch (unit) {
|
|
870
|
+
case "deg": return +val;
|
|
871
|
+
case "rad": return val / Math.PI * 180;
|
|
872
|
+
case "grad": return val / 10 * 9;
|
|
873
|
+
case "turn": return val * 360;
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
var hue_default = hueToDeg;
|
|
877
|
+
|
|
878
|
+
//#endregion
|
|
879
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/hsl/parseHslLegacy.js
|
|
880
|
+
const hsl_old = new RegExp(`^hsla?\\(\\s*${hue$1}${c}${per}${c}${per}\\s*(?:,\\s*${num_per}\\s*)?\\)$`);
|
|
881
|
+
const parseHslLegacy = (color) => {
|
|
882
|
+
let match = color.match(hsl_old);
|
|
883
|
+
if (!match) return;
|
|
884
|
+
let res = { mode: "hsl" };
|
|
885
|
+
if (match[3] !== void 0) res.h = +match[3];
|
|
886
|
+
else if (match[1] !== void 0 && match[2] !== void 0) res.h = hue_default(match[1], match[2]);
|
|
887
|
+
if (match[4] !== void 0) res.s = Math.min(Math.max(0, match[4] / 100), 1);
|
|
888
|
+
if (match[5] !== void 0) res.l = Math.min(Math.max(0, match[5] / 100), 1);
|
|
889
|
+
if (match[6] !== void 0) res.alpha = Math.max(0, Math.min(1, match[6] / 100));
|
|
890
|
+
else if (match[7] !== void 0) res.alpha = Math.max(0, Math.min(1, +match[7]));
|
|
891
|
+
return res;
|
|
892
|
+
};
|
|
893
|
+
var parseHslLegacy_default = parseHslLegacy;
|
|
894
|
+
|
|
895
|
+
//#endregion
|
|
896
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/hsl/parseHsl.js
|
|
897
|
+
function parseHsl(color, parsed) {
|
|
898
|
+
if (!parsed || parsed[0] !== "hsl" && parsed[0] !== "hsla") return void 0;
|
|
899
|
+
const res = { mode: "hsl" };
|
|
900
|
+
const [, h, s, l, alpha] = parsed;
|
|
901
|
+
if (h.type !== Tok.None) {
|
|
902
|
+
if (h.type === Tok.Percentage) return void 0;
|
|
903
|
+
res.h = h.value;
|
|
904
|
+
}
|
|
905
|
+
if (s.type !== Tok.None) {
|
|
906
|
+
if (s.type === Tok.Hue) return void 0;
|
|
907
|
+
res.s = s.value / 100;
|
|
908
|
+
}
|
|
909
|
+
if (l.type !== Tok.None) {
|
|
910
|
+
if (l.type === Tok.Hue) return void 0;
|
|
911
|
+
res.l = l.value / 100;
|
|
912
|
+
}
|
|
913
|
+
if (alpha.type !== Tok.None) res.alpha = Math.min(1, Math.max(0, alpha.type === Tok.Number ? alpha.value : alpha.value / 100));
|
|
914
|
+
return res;
|
|
915
|
+
}
|
|
916
|
+
var parseHsl_default = parseHsl;
|
|
917
|
+
|
|
918
|
+
//#endregion
|
|
919
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/fixup/hue.js
|
|
920
|
+
const hue = (hues, fn$3) => {
|
|
921
|
+
return hues.map((hue$2, idx, arr) => {
|
|
922
|
+
if (hue$2 === void 0) return hue$2;
|
|
923
|
+
let normalized = normalizeHue_default(hue$2);
|
|
924
|
+
if (idx === 0 || hues[idx - 1] === void 0) return normalized;
|
|
925
|
+
return fn$3(normalized - normalizeHue_default(arr[idx - 1]));
|
|
926
|
+
}).reduce((acc, curr) => {
|
|
927
|
+
if (!acc.length || curr === void 0 || acc[acc.length - 1] === void 0) {
|
|
928
|
+
acc.push(curr);
|
|
929
|
+
return acc;
|
|
930
|
+
}
|
|
931
|
+
acc.push(curr + acc[acc.length - 1]);
|
|
932
|
+
return acc;
|
|
933
|
+
}, []);
|
|
934
|
+
};
|
|
935
|
+
const fixupHueShorter = (arr) => hue(arr, (d) => Math.abs(d) <= 180 ? d : d - 360 * Math.sign(d));
|
|
936
|
+
|
|
937
|
+
//#endregion
|
|
938
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/difference.js
|
|
939
|
+
const differenceHueSaturation = (std, smp) => {
|
|
940
|
+
if (std.h === void 0 || smp.h === void 0 || !std.s || !smp.s) return 0;
|
|
941
|
+
let std_h = normalizeHue_default(std.h);
|
|
942
|
+
let smp_h = normalizeHue_default(smp.h);
|
|
943
|
+
let dH = Math.sin((smp_h - std_h + 360) / 2 * Math.PI / 180);
|
|
944
|
+
return 2 * Math.sqrt(std.s * smp.s) * dH;
|
|
945
|
+
};
|
|
946
|
+
const differenceHueNaive = (std, smp) => {
|
|
947
|
+
if (std.h === void 0 || smp.h === void 0) return 0;
|
|
948
|
+
let std_h = normalizeHue_default(std.h);
|
|
949
|
+
let smp_h = normalizeHue_default(smp.h);
|
|
950
|
+
if (Math.abs(smp_h - std_h) > 180) return std_h - (smp_h - 360 * Math.sign(smp_h - std_h));
|
|
951
|
+
return smp_h - std_h;
|
|
952
|
+
};
|
|
953
|
+
const differenceHueChroma = (std, smp) => {
|
|
954
|
+
if (std.h === void 0 || smp.h === void 0 || !std.c || !smp.c) return 0;
|
|
955
|
+
let std_h = normalizeHue_default(std.h);
|
|
956
|
+
let smp_h = normalizeHue_default(smp.h);
|
|
957
|
+
let dH = Math.sin((smp_h - std_h + 360) / 2 * Math.PI / 180);
|
|
958
|
+
return 2 * Math.sqrt(std.c * smp.c) * dH;
|
|
959
|
+
};
|
|
960
|
+
const differenceEuclidean = (mode = "rgb", weights = [
|
|
961
|
+
1,
|
|
962
|
+
1,
|
|
963
|
+
1,
|
|
964
|
+
0
|
|
965
|
+
]) => {
|
|
966
|
+
let def = getMode(mode);
|
|
967
|
+
let channels = def.channels;
|
|
968
|
+
let diffs = def.difference;
|
|
969
|
+
let conv = converter_default(mode);
|
|
970
|
+
return (std, smp) => {
|
|
971
|
+
let ConvStd = conv(std);
|
|
972
|
+
let ConvSmp = conv(smp);
|
|
973
|
+
return Math.sqrt(channels.reduce((sum, k$2, idx) => {
|
|
974
|
+
let delta = diffs[k$2] ? diffs[k$2](ConvStd, ConvSmp) : ConvStd[k$2] - ConvSmp[k$2];
|
|
975
|
+
return sum + (weights[idx] || 0) * Math.pow(isNaN(delta) ? 0 : delta, 2);
|
|
976
|
+
}, 0));
|
|
977
|
+
};
|
|
978
|
+
};
|
|
979
|
+
|
|
980
|
+
//#endregion
|
|
981
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/average.js
|
|
982
|
+
const averageAngle = (val) => {
|
|
983
|
+
let sum = val.reduce((sum$1, val$1) => {
|
|
984
|
+
if (val$1 !== void 0) {
|
|
985
|
+
let rad = val$1 * Math.PI / 180;
|
|
986
|
+
sum$1.sin += Math.sin(rad);
|
|
987
|
+
sum$1.cos += Math.cos(rad);
|
|
988
|
+
}
|
|
989
|
+
return sum$1;
|
|
990
|
+
}, {
|
|
991
|
+
sin: 0,
|
|
992
|
+
cos: 0
|
|
993
|
+
});
|
|
994
|
+
let angle = Math.atan2(sum.sin, sum.cos) * 180 / Math.PI;
|
|
995
|
+
return angle < 0 ? 360 + angle : angle;
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
//#endregion
|
|
999
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/hsl/definition.js
|
|
1000
|
+
const definition$12 = {
|
|
1001
|
+
mode: "hsl",
|
|
1002
|
+
toMode: { rgb: convertHslToRgb },
|
|
1003
|
+
fromMode: { rgb: convertRgbToHsl },
|
|
1004
|
+
channels: [
|
|
1005
|
+
"h",
|
|
1006
|
+
"s",
|
|
1007
|
+
"l",
|
|
1008
|
+
"alpha"
|
|
1009
|
+
],
|
|
1010
|
+
ranges: { h: [0, 360] },
|
|
1011
|
+
gamut: "rgb",
|
|
1012
|
+
parse: [parseHsl_default, parseHslLegacy_default],
|
|
1013
|
+
serialize: (c$1) => `hsl(${c$1.h !== void 0 ? c$1.h : "none"} ${c$1.s !== void 0 ? c$1.s * 100 + "%" : "none"} ${c$1.l !== void 0 ? c$1.l * 100 + "%" : "none"}${c$1.alpha < 1 ? ` / ${c$1.alpha}` : ""})`,
|
|
1014
|
+
interpolate: {
|
|
1015
|
+
h: {
|
|
1016
|
+
use: interpolatorLinear,
|
|
1017
|
+
fixup: fixupHueShorter
|
|
1018
|
+
},
|
|
1019
|
+
s: interpolatorLinear,
|
|
1020
|
+
l: interpolatorLinear,
|
|
1021
|
+
alpha: {
|
|
1022
|
+
use: interpolatorLinear,
|
|
1023
|
+
fixup: fixupAlpha
|
|
1024
|
+
}
|
|
1025
|
+
},
|
|
1026
|
+
difference: { h: differenceHueSaturation },
|
|
1027
|
+
average: { h: averageAngle }
|
|
1028
|
+
};
|
|
1029
|
+
var definition_default$1 = definition$12;
|
|
1030
|
+
|
|
1031
|
+
//#endregion
|
|
1032
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/hsv/convertHsvToRgb.js
|
|
1033
|
+
function convertHsvToRgb({ h, s, v, alpha }) {
|
|
1034
|
+
h = normalizeHue_default(h !== void 0 ? h : 0);
|
|
1035
|
+
if (s === void 0) s = 0;
|
|
1036
|
+
if (v === void 0) v = 0;
|
|
1037
|
+
let f$1 = Math.abs(h / 60 % 2 - 1);
|
|
1038
|
+
let res;
|
|
1039
|
+
switch (Math.floor(h / 60)) {
|
|
1040
|
+
case 0:
|
|
1041
|
+
res = {
|
|
1042
|
+
r: v,
|
|
1043
|
+
g: v * (1 - s * f$1),
|
|
1044
|
+
b: v * (1 - s)
|
|
1045
|
+
};
|
|
1046
|
+
break;
|
|
1047
|
+
case 1:
|
|
1048
|
+
res = {
|
|
1049
|
+
r: v * (1 - s * f$1),
|
|
1050
|
+
g: v,
|
|
1051
|
+
b: v * (1 - s)
|
|
1052
|
+
};
|
|
1053
|
+
break;
|
|
1054
|
+
case 2:
|
|
1055
|
+
res = {
|
|
1056
|
+
r: v * (1 - s),
|
|
1057
|
+
g: v,
|
|
1058
|
+
b: v * (1 - s * f$1)
|
|
1059
|
+
};
|
|
1060
|
+
break;
|
|
1061
|
+
case 3:
|
|
1062
|
+
res = {
|
|
1063
|
+
r: v * (1 - s),
|
|
1064
|
+
g: v * (1 - s * f$1),
|
|
1065
|
+
b: v
|
|
1066
|
+
};
|
|
1067
|
+
break;
|
|
1068
|
+
case 4:
|
|
1069
|
+
res = {
|
|
1070
|
+
r: v * (1 - s * f$1),
|
|
1071
|
+
g: v * (1 - s),
|
|
1072
|
+
b: v
|
|
1073
|
+
};
|
|
1074
|
+
break;
|
|
1075
|
+
case 5:
|
|
1076
|
+
res = {
|
|
1077
|
+
r: v,
|
|
1078
|
+
g: v * (1 - s),
|
|
1079
|
+
b: v * (1 - s * f$1)
|
|
1080
|
+
};
|
|
1081
|
+
break;
|
|
1082
|
+
default: res = {
|
|
1083
|
+
r: v * (1 - s),
|
|
1084
|
+
g: v * (1 - s),
|
|
1085
|
+
b: v * (1 - s)
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
res.mode = "rgb";
|
|
1089
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1090
|
+
return res;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
//#endregion
|
|
1094
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/hsv/convertRgbToHsv.js
|
|
1095
|
+
function convertRgbToHsv({ r: r$1, g, b, alpha }) {
|
|
1096
|
+
if (r$1 === void 0) r$1 = 0;
|
|
1097
|
+
if (g === void 0) g = 0;
|
|
1098
|
+
if (b === void 0) b = 0;
|
|
1099
|
+
let M = Math.max(r$1, g, b), m = Math.min(r$1, g, b);
|
|
1100
|
+
let res = {
|
|
1101
|
+
mode: "hsv",
|
|
1102
|
+
s: M === 0 ? 0 : 1 - m / M,
|
|
1103
|
+
v: M
|
|
1104
|
+
};
|
|
1105
|
+
if (M - m !== 0) res.h = (M === r$1 ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r$1) / (M - m) + 2 : (r$1 - g) / (M - m) + 4) * 60;
|
|
1106
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1107
|
+
return res;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
//#endregion
|
|
1111
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/hsv/definition.js
|
|
1112
|
+
const definition$11 = {
|
|
1113
|
+
mode: "hsv",
|
|
1114
|
+
toMode: { rgb: convertHsvToRgb },
|
|
1115
|
+
parse: ["--hsv"],
|
|
1116
|
+
serialize: "--hsv",
|
|
1117
|
+
fromMode: { rgb: convertRgbToHsv },
|
|
1118
|
+
channels: [
|
|
1119
|
+
"h",
|
|
1120
|
+
"s",
|
|
1121
|
+
"v",
|
|
1122
|
+
"alpha"
|
|
1123
|
+
],
|
|
1124
|
+
ranges: { h: [0, 360] },
|
|
1125
|
+
gamut: "rgb",
|
|
1126
|
+
interpolate: {
|
|
1127
|
+
h: {
|
|
1128
|
+
use: interpolatorLinear,
|
|
1129
|
+
fixup: fixupHueShorter
|
|
1130
|
+
},
|
|
1131
|
+
s: interpolatorLinear,
|
|
1132
|
+
v: interpolatorLinear,
|
|
1133
|
+
alpha: {
|
|
1134
|
+
use: interpolatorLinear,
|
|
1135
|
+
fixup: fixupAlpha
|
|
1136
|
+
}
|
|
1137
|
+
},
|
|
1138
|
+
difference: { h: differenceHueSaturation },
|
|
1139
|
+
average: { h: averageAngle }
|
|
1140
|
+
};
|
|
1141
|
+
var definition_default$2 = definition$11;
|
|
1142
|
+
|
|
1143
|
+
//#endregion
|
|
1144
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/hwb/convertHwbToRgb.js
|
|
1145
|
+
function convertHwbToRgb({ h, w, b, alpha }) {
|
|
1146
|
+
if (w === void 0) w = 0;
|
|
1147
|
+
if (b === void 0) b = 0;
|
|
1148
|
+
if (w + b > 1) {
|
|
1149
|
+
let s = w + b;
|
|
1150
|
+
w /= s;
|
|
1151
|
+
b /= s;
|
|
1152
|
+
}
|
|
1153
|
+
return convertHsvToRgb({
|
|
1154
|
+
h,
|
|
1155
|
+
s: b === 1 ? 1 : 1 - w / (1 - b),
|
|
1156
|
+
v: 1 - b,
|
|
1157
|
+
alpha
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
//#endregion
|
|
1162
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/hwb/convertRgbToHwb.js
|
|
1163
|
+
function convertRgbToHwb(rgba) {
|
|
1164
|
+
let hsv = convertRgbToHsv(rgba);
|
|
1165
|
+
if (hsv === void 0) return void 0;
|
|
1166
|
+
let s = hsv.s !== void 0 ? hsv.s : 0;
|
|
1167
|
+
let v = hsv.v !== void 0 ? hsv.v : 0;
|
|
1168
|
+
let res = {
|
|
1169
|
+
mode: "hwb",
|
|
1170
|
+
w: (1 - s) * v,
|
|
1171
|
+
b: 1 - v
|
|
1172
|
+
};
|
|
1173
|
+
if (hsv.h !== void 0) res.h = hsv.h;
|
|
1174
|
+
if (hsv.alpha !== void 0) res.alpha = hsv.alpha;
|
|
1175
|
+
return res;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
//#endregion
|
|
1179
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/hwb/parseHwb.js
|
|
1180
|
+
function ParseHwb(color, parsed) {
|
|
1181
|
+
if (!parsed || parsed[0] !== "hwb") return void 0;
|
|
1182
|
+
const res = { mode: "hwb" };
|
|
1183
|
+
const [, h, w, b, alpha] = parsed;
|
|
1184
|
+
if (h.type !== Tok.None) {
|
|
1185
|
+
if (h.type === Tok.Percentage) return void 0;
|
|
1186
|
+
res.h = h.value;
|
|
1187
|
+
}
|
|
1188
|
+
if (w.type !== Tok.None) {
|
|
1189
|
+
if (w.type === Tok.Hue) return void 0;
|
|
1190
|
+
res.w = w.value / 100;
|
|
1191
|
+
}
|
|
1192
|
+
if (b.type !== Tok.None) {
|
|
1193
|
+
if (b.type === Tok.Hue) return void 0;
|
|
1194
|
+
res.b = b.value / 100;
|
|
1195
|
+
}
|
|
1196
|
+
if (alpha.type !== Tok.None) res.alpha = Math.min(1, Math.max(0, alpha.type === Tok.Number ? alpha.value : alpha.value / 100));
|
|
1197
|
+
return res;
|
|
1198
|
+
}
|
|
1199
|
+
var parseHwb_default = ParseHwb;
|
|
1200
|
+
|
|
1201
|
+
//#endregion
|
|
1202
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/hwb/definition.js
|
|
1203
|
+
const definition$10 = {
|
|
1204
|
+
mode: "hwb",
|
|
1205
|
+
toMode: { rgb: convertHwbToRgb },
|
|
1206
|
+
fromMode: { rgb: convertRgbToHwb },
|
|
1207
|
+
channels: [
|
|
1208
|
+
"h",
|
|
1209
|
+
"w",
|
|
1210
|
+
"b",
|
|
1211
|
+
"alpha"
|
|
1212
|
+
],
|
|
1213
|
+
ranges: { h: [0, 360] },
|
|
1214
|
+
gamut: "rgb",
|
|
1215
|
+
parse: [parseHwb_default],
|
|
1216
|
+
serialize: (c$1) => `hwb(${c$1.h !== void 0 ? c$1.h : "none"} ${c$1.w !== void 0 ? c$1.w * 100 + "%" : "none"} ${c$1.b !== void 0 ? c$1.b * 100 + "%" : "none"}${c$1.alpha < 1 ? ` / ${c$1.alpha}` : ""})`,
|
|
1217
|
+
interpolate: {
|
|
1218
|
+
h: {
|
|
1219
|
+
use: interpolatorLinear,
|
|
1220
|
+
fixup: fixupHueShorter
|
|
1221
|
+
},
|
|
1222
|
+
w: interpolatorLinear,
|
|
1223
|
+
b: interpolatorLinear,
|
|
1224
|
+
alpha: {
|
|
1225
|
+
use: interpolatorLinear,
|
|
1226
|
+
fixup: fixupAlpha
|
|
1227
|
+
}
|
|
1228
|
+
},
|
|
1229
|
+
difference: { h: differenceHueNaive },
|
|
1230
|
+
average: { h: averageAngle }
|
|
1231
|
+
};
|
|
1232
|
+
var definition_default$3 = definition$10;
|
|
1233
|
+
|
|
1234
|
+
//#endregion
|
|
1235
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/xyz50/constants.js
|
|
1236
|
+
const k = Math.pow(29, 3) / Math.pow(3, 3);
|
|
1237
|
+
const e = Math.pow(6, 3) / Math.pow(29, 3);
|
|
1238
|
+
|
|
1239
|
+
//#endregion
|
|
1240
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/constants.js
|
|
1241
|
+
const D50 = {
|
|
1242
|
+
X: .3457 / .3585,
|
|
1243
|
+
Y: 1,
|
|
1244
|
+
Z: .2958 / .3585
|
|
1245
|
+
};
|
|
1246
|
+
const D65 = {
|
|
1247
|
+
X: .3127 / .329,
|
|
1248
|
+
Y: 1,
|
|
1249
|
+
Z: .3583 / .329
|
|
1250
|
+
};
|
|
1251
|
+
const k$1 = Math.pow(29, 3) / Math.pow(3, 3);
|
|
1252
|
+
const e$1 = Math.pow(6, 3) / Math.pow(29, 3);
|
|
1253
|
+
|
|
1254
|
+
//#endregion
|
|
1255
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/lab/convertLabToXyz50.js
|
|
1256
|
+
let fn = (v) => Math.pow(v, 3) > e ? Math.pow(v, 3) : (116 * v - 16) / k;
|
|
1257
|
+
const convertLabToXyz50 = ({ l, a, b, alpha }) => {
|
|
1258
|
+
if (l === void 0) l = 0;
|
|
1259
|
+
if (a === void 0) a = 0;
|
|
1260
|
+
if (b === void 0) b = 0;
|
|
1261
|
+
let fy = (l + 16) / 116;
|
|
1262
|
+
let fx = a / 500 + fy;
|
|
1263
|
+
let fz = fy - b / 200;
|
|
1264
|
+
let res = {
|
|
1265
|
+
mode: "xyz50",
|
|
1266
|
+
x: fn(fx) * D50.X,
|
|
1267
|
+
y: fn(fy) * D50.Y,
|
|
1268
|
+
z: fn(fz) * D50.Z
|
|
1269
|
+
};
|
|
1270
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1271
|
+
return res;
|
|
1272
|
+
};
|
|
1273
|
+
var convertLabToXyz50_default = convertLabToXyz50;
|
|
1274
|
+
|
|
1275
|
+
//#endregion
|
|
1276
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/xyz50/convertXyz50ToRgb.js
|
|
1277
|
+
const convertXyz50ToRgb = ({ x, y, z, alpha }) => {
|
|
1278
|
+
if (x === void 0) x = 0;
|
|
1279
|
+
if (y === void 0) y = 0;
|
|
1280
|
+
if (z === void 0) z = 0;
|
|
1281
|
+
let res = convertLrgbToRgb_default({
|
|
1282
|
+
r: x * 3.1341359569958707 - y * 1.6173863321612538 - .4906619460083532 * z,
|
|
1283
|
+
g: x * -.978795502912089 + y * 1.916254567259524 + .03344273116131949 * z,
|
|
1284
|
+
b: x * .07195537988411677 - y * .2289768264158322 + 1.405386058324125 * z
|
|
1285
|
+
});
|
|
1286
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1287
|
+
return res;
|
|
1288
|
+
};
|
|
1289
|
+
var convertXyz50ToRgb_default = convertXyz50ToRgb;
|
|
1290
|
+
|
|
1291
|
+
//#endregion
|
|
1292
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/lab/convertLabToRgb.js
|
|
1293
|
+
const convertLabToRgb = (lab) => convertXyz50ToRgb_default(convertLabToXyz50_default(lab));
|
|
1294
|
+
var convertLabToRgb_default = convertLabToRgb;
|
|
1295
|
+
|
|
1296
|
+
//#endregion
|
|
1297
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/xyz50/convertRgbToXyz50.js
|
|
1298
|
+
const convertRgbToXyz50 = (rgb$2) => {
|
|
1299
|
+
let { r: r$1, g, b, alpha } = convertRgbToLrgb_default(rgb$2);
|
|
1300
|
+
let res = {
|
|
1301
|
+
mode: "xyz50",
|
|
1302
|
+
x: .436065742824811 * r$1 + .3851514688337912 * g + .14307845442264197 * b,
|
|
1303
|
+
y: .22249319175623702 * r$1 + .7168870538238823 * g + .06061979053616537 * b,
|
|
1304
|
+
z: .013923904500943465 * r$1 + .09708128566574634 * g + .7140993584005155 * b
|
|
1305
|
+
};
|
|
1306
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1307
|
+
return res;
|
|
1308
|
+
};
|
|
1309
|
+
var convertRgbToXyz50_default = convertRgbToXyz50;
|
|
1310
|
+
|
|
1311
|
+
//#endregion
|
|
1312
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/lab/convertXyz50ToLab.js
|
|
1313
|
+
const f = (value) => value > e ? Math.cbrt(value) : (k * value + 16) / 116;
|
|
1314
|
+
const convertXyz50ToLab = ({ x, y, z, alpha }) => {
|
|
1315
|
+
if (x === void 0) x = 0;
|
|
1316
|
+
if (y === void 0) y = 0;
|
|
1317
|
+
if (z === void 0) z = 0;
|
|
1318
|
+
let f0 = f(x / D50.X);
|
|
1319
|
+
let f1 = f(y / D50.Y);
|
|
1320
|
+
let f2 = f(z / D50.Z);
|
|
1321
|
+
let res = {
|
|
1322
|
+
mode: "lab",
|
|
1323
|
+
l: 116 * f1 - 16,
|
|
1324
|
+
a: 500 * (f0 - f1),
|
|
1325
|
+
b: 200 * (f1 - f2)
|
|
1326
|
+
};
|
|
1327
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1328
|
+
return res;
|
|
1329
|
+
};
|
|
1330
|
+
var convertXyz50ToLab_default = convertXyz50ToLab;
|
|
1331
|
+
|
|
1332
|
+
//#endregion
|
|
1333
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/lab/convertRgbToLab.js
|
|
1334
|
+
const convertRgbToLab = (rgb$2) => {
|
|
1335
|
+
let res = convertXyz50ToLab_default(convertRgbToXyz50_default(rgb$2));
|
|
1336
|
+
if (rgb$2.r === rgb$2.b && rgb$2.b === rgb$2.g) res.a = res.b = 0;
|
|
1337
|
+
return res;
|
|
1338
|
+
};
|
|
1339
|
+
var convertRgbToLab_default = convertRgbToLab;
|
|
1340
|
+
|
|
1341
|
+
//#endregion
|
|
1342
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/lab/parseLab.js
|
|
1343
|
+
function parseLab(color, parsed) {
|
|
1344
|
+
if (!parsed || parsed[0] !== "lab") return void 0;
|
|
1345
|
+
const res = { mode: "lab" };
|
|
1346
|
+
const [, l, a, b, alpha] = parsed;
|
|
1347
|
+
if (l.type === Tok.Hue || a.type === Tok.Hue || b.type === Tok.Hue) return void 0;
|
|
1348
|
+
if (l.type !== Tok.None) res.l = Math.min(Math.max(0, l.value), 100);
|
|
1349
|
+
if (a.type !== Tok.None) res.a = a.type === Tok.Number ? a.value : a.value * 125 / 100;
|
|
1350
|
+
if (b.type !== Tok.None) res.b = b.type === Tok.Number ? b.value : b.value * 125 / 100;
|
|
1351
|
+
if (alpha.type !== Tok.None) res.alpha = Math.min(1, Math.max(0, alpha.type === Tok.Number ? alpha.value : alpha.value / 100));
|
|
1352
|
+
return res;
|
|
1353
|
+
}
|
|
1354
|
+
var parseLab_default = parseLab;
|
|
1355
|
+
|
|
1356
|
+
//#endregion
|
|
1357
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/lab/definition.js
|
|
1358
|
+
const definition$9 = {
|
|
1359
|
+
mode: "lab",
|
|
1360
|
+
toMode: {
|
|
1361
|
+
xyz50: convertLabToXyz50_default,
|
|
1362
|
+
rgb: convertLabToRgb_default
|
|
1363
|
+
},
|
|
1364
|
+
fromMode: {
|
|
1365
|
+
xyz50: convertXyz50ToLab_default,
|
|
1366
|
+
rgb: convertRgbToLab_default
|
|
1367
|
+
},
|
|
1368
|
+
channels: [
|
|
1369
|
+
"l",
|
|
1370
|
+
"a",
|
|
1371
|
+
"b",
|
|
1372
|
+
"alpha"
|
|
1373
|
+
],
|
|
1374
|
+
ranges: {
|
|
1375
|
+
l: [0, 100],
|
|
1376
|
+
a: [-100, 100],
|
|
1377
|
+
b: [-100, 100]
|
|
1378
|
+
},
|
|
1379
|
+
parse: [parseLab_default],
|
|
1380
|
+
serialize: (c$1) => `lab(${c$1.l !== void 0 ? c$1.l : "none"} ${c$1.a !== void 0 ? c$1.a : "none"} ${c$1.b !== void 0 ? c$1.b : "none"}${c$1.alpha < 1 ? ` / ${c$1.alpha}` : ""})`,
|
|
1381
|
+
interpolate: {
|
|
1382
|
+
l: interpolatorLinear,
|
|
1383
|
+
a: interpolatorLinear,
|
|
1384
|
+
b: interpolatorLinear,
|
|
1385
|
+
alpha: {
|
|
1386
|
+
use: interpolatorLinear,
|
|
1387
|
+
fixup: fixupAlpha
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
};
|
|
1391
|
+
var definition_default$4 = definition$9;
|
|
1392
|
+
|
|
1393
|
+
//#endregion
|
|
1394
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/lch/convertLabToLch.js
|
|
1395
|
+
const convertLabToLch = ({ l, a, b, alpha }, mode = "lch") => {
|
|
1396
|
+
if (a === void 0) a = 0;
|
|
1397
|
+
if (b === void 0) b = 0;
|
|
1398
|
+
let c$1 = Math.sqrt(a * a + b * b);
|
|
1399
|
+
let res = {
|
|
1400
|
+
mode,
|
|
1401
|
+
l,
|
|
1402
|
+
c: c$1
|
|
1403
|
+
};
|
|
1404
|
+
if (c$1) res.h = normalizeHue_default(Math.atan2(b, a) * 180 / Math.PI);
|
|
1405
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1406
|
+
return res;
|
|
1407
|
+
};
|
|
1408
|
+
var convertLabToLch_default = convertLabToLch;
|
|
1409
|
+
|
|
1410
|
+
//#endregion
|
|
1411
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/lch/convertLchToLab.js
|
|
1412
|
+
const convertLchToLab = ({ l, c: c$1, h, alpha }, mode = "lab") => {
|
|
1413
|
+
if (h === void 0) h = 0;
|
|
1414
|
+
let res = {
|
|
1415
|
+
mode,
|
|
1416
|
+
l,
|
|
1417
|
+
a: c$1 ? c$1 * Math.cos(h / 180 * Math.PI) : 0,
|
|
1418
|
+
b: c$1 ? c$1 * Math.sin(h / 180 * Math.PI) : 0
|
|
1419
|
+
};
|
|
1420
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1421
|
+
return res;
|
|
1422
|
+
};
|
|
1423
|
+
var convertLchToLab_default = convertLchToLab;
|
|
1424
|
+
|
|
1425
|
+
//#endregion
|
|
1426
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/lch/parseLch.js
|
|
1427
|
+
function parseLch(color, parsed) {
|
|
1428
|
+
if (!parsed || parsed[0] !== "lch") return void 0;
|
|
1429
|
+
const res = { mode: "lch" };
|
|
1430
|
+
const [, l, c$1, h, alpha] = parsed;
|
|
1431
|
+
if (l.type !== Tok.None) {
|
|
1432
|
+
if (l.type === Tok.Hue) return void 0;
|
|
1433
|
+
res.l = Math.min(Math.max(0, l.value), 100);
|
|
1434
|
+
}
|
|
1435
|
+
if (c$1.type !== Tok.None) res.c = Math.max(0, c$1.type === Tok.Number ? c$1.value : c$1.value * 150 / 100);
|
|
1436
|
+
if (h.type !== Tok.None) {
|
|
1437
|
+
if (h.type === Tok.Percentage) return void 0;
|
|
1438
|
+
res.h = h.value;
|
|
1439
|
+
}
|
|
1440
|
+
if (alpha.type !== Tok.None) res.alpha = Math.min(1, Math.max(0, alpha.type === Tok.Number ? alpha.value : alpha.value / 100));
|
|
1441
|
+
return res;
|
|
1442
|
+
}
|
|
1443
|
+
var parseLch_default = parseLch;
|
|
1444
|
+
|
|
1445
|
+
//#endregion
|
|
1446
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/lch/definition.js
|
|
1447
|
+
const definition$8 = {
|
|
1448
|
+
mode: "lch",
|
|
1449
|
+
toMode: {
|
|
1450
|
+
lab: convertLchToLab_default,
|
|
1451
|
+
rgb: (c$1) => convertLabToRgb_default(convertLchToLab_default(c$1))
|
|
1452
|
+
},
|
|
1453
|
+
fromMode: {
|
|
1454
|
+
rgb: (c$1) => convertLabToLch_default(convertRgbToLab_default(c$1)),
|
|
1455
|
+
lab: convertLabToLch_default
|
|
1456
|
+
},
|
|
1457
|
+
channels: [
|
|
1458
|
+
"l",
|
|
1459
|
+
"c",
|
|
1460
|
+
"h",
|
|
1461
|
+
"alpha"
|
|
1462
|
+
],
|
|
1463
|
+
ranges: {
|
|
1464
|
+
l: [0, 100],
|
|
1465
|
+
c: [0, 150],
|
|
1466
|
+
h: [0, 360]
|
|
1467
|
+
},
|
|
1468
|
+
parse: [parseLch_default],
|
|
1469
|
+
serialize: (c$1) => `lch(${c$1.l !== void 0 ? c$1.l : "none"} ${c$1.c !== void 0 ? c$1.c : "none"} ${c$1.h !== void 0 ? c$1.h : "none"}${c$1.alpha < 1 ? ` / ${c$1.alpha}` : ""})`,
|
|
1470
|
+
interpolate: {
|
|
1471
|
+
h: {
|
|
1472
|
+
use: interpolatorLinear,
|
|
1473
|
+
fixup: fixupHueShorter
|
|
1474
|
+
},
|
|
1475
|
+
c: interpolatorLinear,
|
|
1476
|
+
l: interpolatorLinear,
|
|
1477
|
+
alpha: {
|
|
1478
|
+
use: interpolatorLinear,
|
|
1479
|
+
fixup: fixupAlpha
|
|
1480
|
+
}
|
|
1481
|
+
},
|
|
1482
|
+
difference: { h: differenceHueChroma },
|
|
1483
|
+
average: { h: averageAngle }
|
|
1484
|
+
};
|
|
1485
|
+
var definition_default$5 = definition$8;
|
|
1486
|
+
|
|
1487
|
+
//#endregion
|
|
1488
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/lrgb/definition.js
|
|
1489
|
+
const definition$7 = {
|
|
1490
|
+
...definition_default$12,
|
|
1491
|
+
mode: "lrgb",
|
|
1492
|
+
toMode: { rgb: convertLrgbToRgb_default },
|
|
1493
|
+
fromMode: { rgb: convertRgbToLrgb_default },
|
|
1494
|
+
parse: ["srgb-linear"],
|
|
1495
|
+
serialize: "srgb-linear"
|
|
1496
|
+
};
|
|
1497
|
+
var definition_default$6 = definition$7;
|
|
1498
|
+
|
|
1499
|
+
//#endregion
|
|
1500
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/oklab/convertOklabToLrgb.js
|
|
1501
|
+
const convertOklabToLrgb = ({ l, a, b, alpha }) => {
|
|
1502
|
+
if (l === void 0) l = 0;
|
|
1503
|
+
if (a === void 0) a = 0;
|
|
1504
|
+
if (b === void 0) b = 0;
|
|
1505
|
+
let L = Math.pow(l * .9999999984505198 + .39633779217376786 * a + .2158037580607588 * b, 3);
|
|
1506
|
+
let M = Math.pow(l * 1.0000000088817609 - .10556134232365635 * a - .06385417477170591 * b, 3);
|
|
1507
|
+
let S = Math.pow(l * 1.0000000546724108 - .08948418209496575 * a - 1.2914855378640917 * b, 3);
|
|
1508
|
+
let res = {
|
|
1509
|
+
mode: "lrgb",
|
|
1510
|
+
r: 4.076741661347994 * L - 3.307711590408193 * M + .230969928729428 * S,
|
|
1511
|
+
g: -1.2684380040921763 * L + 2.6097574006633715 * M - .3413193963102197 * S,
|
|
1512
|
+
b: -.004196086541837188 * L - .7034186144594493 * M + 1.7076147009309444 * S
|
|
1513
|
+
};
|
|
1514
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1515
|
+
return res;
|
|
1516
|
+
};
|
|
1517
|
+
var convertOklabToLrgb_default = convertOklabToLrgb;
|
|
1518
|
+
|
|
1519
|
+
//#endregion
|
|
1520
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/oklab/convertLrgbToOklab.js
|
|
1521
|
+
const convertLrgbToOklab = ({ r: r$1, g, b, alpha }) => {
|
|
1522
|
+
if (r$1 === void 0) r$1 = 0;
|
|
1523
|
+
if (g === void 0) g = 0;
|
|
1524
|
+
if (b === void 0) b = 0;
|
|
1525
|
+
let L = Math.cbrt(.41222147079999993 * r$1 + .5363325363 * g + .0514459929 * b);
|
|
1526
|
+
let M = Math.cbrt(.2119034981999999 * r$1 + .6806995450999999 * g + .1073969566 * b);
|
|
1527
|
+
let S = Math.cbrt(.08830246189999998 * r$1 + .2817188376 * g + .6299787005000002 * b);
|
|
1528
|
+
let res = {
|
|
1529
|
+
mode: "oklab",
|
|
1530
|
+
l: .2104542553 * L + .793617785 * M - .0040720468 * S,
|
|
1531
|
+
a: 1.9779984951 * L - 2.428592205 * M + .4505937099 * S,
|
|
1532
|
+
b: .0259040371 * L + .7827717662 * M - .808675766 * S
|
|
1533
|
+
};
|
|
1534
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1535
|
+
return res;
|
|
1536
|
+
};
|
|
1537
|
+
var convertLrgbToOklab_default = convertLrgbToOklab;
|
|
1538
|
+
|
|
1539
|
+
//#endregion
|
|
1540
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/oklab/convertRgbToOklab.js
|
|
1541
|
+
const convertRgbToOklab = (rgb$2) => {
|
|
1542
|
+
let res = convertLrgbToOklab_default(convertRgbToLrgb_default(rgb$2));
|
|
1543
|
+
if (rgb$2.r === rgb$2.b && rgb$2.b === rgb$2.g) res.a = res.b = 0;
|
|
1544
|
+
return res;
|
|
1545
|
+
};
|
|
1546
|
+
var convertRgbToOklab_default = convertRgbToOklab;
|
|
1547
|
+
|
|
1548
|
+
//#endregion
|
|
1549
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/oklab/convertOklabToRgb.js
|
|
1550
|
+
const convertOklabToRgb = (c$1) => convertLrgbToRgb_default(convertOklabToLrgb_default(c$1));
|
|
1551
|
+
var convertOklabToRgb_default = convertOklabToRgb;
|
|
1552
|
+
|
|
1553
|
+
//#endregion
|
|
1554
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/oklab/parseOklab.js
|
|
1555
|
+
function parseOklab(color, parsed) {
|
|
1556
|
+
if (!parsed || parsed[0] !== "oklab") return void 0;
|
|
1557
|
+
const res = { mode: "oklab" };
|
|
1558
|
+
const [, l, a, b, alpha] = parsed;
|
|
1559
|
+
if (l.type === Tok.Hue || a.type === Tok.Hue || b.type === Tok.Hue) return void 0;
|
|
1560
|
+
if (l.type !== Tok.None) res.l = Math.min(Math.max(0, l.type === Tok.Number ? l.value : l.value / 100), 1);
|
|
1561
|
+
if (a.type !== Tok.None) res.a = a.type === Tok.Number ? a.value : a.value * .4 / 100;
|
|
1562
|
+
if (b.type !== Tok.None) res.b = b.type === Tok.Number ? b.value : b.value * .4 / 100;
|
|
1563
|
+
if (alpha.type !== Tok.None) res.alpha = Math.min(1, Math.max(0, alpha.type === Tok.Number ? alpha.value : alpha.value / 100));
|
|
1564
|
+
return res;
|
|
1565
|
+
}
|
|
1566
|
+
var parseOklab_default = parseOklab;
|
|
1567
|
+
|
|
1568
|
+
//#endregion
|
|
1569
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/oklab/definition.js
|
|
1570
|
+
const definition$6 = {
|
|
1571
|
+
...definition_default$4,
|
|
1572
|
+
mode: "oklab",
|
|
1573
|
+
toMode: {
|
|
1574
|
+
lrgb: convertOklabToLrgb_default,
|
|
1575
|
+
rgb: convertOklabToRgb_default
|
|
1576
|
+
},
|
|
1577
|
+
fromMode: {
|
|
1578
|
+
lrgb: convertLrgbToOklab_default,
|
|
1579
|
+
rgb: convertRgbToOklab_default
|
|
1580
|
+
},
|
|
1581
|
+
ranges: {
|
|
1582
|
+
l: [0, 1],
|
|
1583
|
+
a: [-.4, .4],
|
|
1584
|
+
b: [-.4, .4]
|
|
1585
|
+
},
|
|
1586
|
+
parse: [parseOklab_default],
|
|
1587
|
+
serialize: (c$1) => `oklab(${c$1.l !== void 0 ? c$1.l : "none"} ${c$1.a !== void 0 ? c$1.a : "none"} ${c$1.b !== void 0 ? c$1.b : "none"}${c$1.alpha < 1 ? ` / ${c$1.alpha}` : ""})`
|
|
1588
|
+
};
|
|
1589
|
+
var definition_default$7 = definition$6;
|
|
1590
|
+
|
|
1591
|
+
//#endregion
|
|
1592
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/oklch/parseOklch.js
|
|
1593
|
+
function parseOklch(color, parsed) {
|
|
1594
|
+
if (!parsed || parsed[0] !== "oklch") return void 0;
|
|
1595
|
+
const res = { mode: "oklch" };
|
|
1596
|
+
const [, l, c$1, h, alpha] = parsed;
|
|
1597
|
+
if (l.type !== Tok.None) {
|
|
1598
|
+
if (l.type === Tok.Hue) return void 0;
|
|
1599
|
+
res.l = Math.min(Math.max(0, l.type === Tok.Number ? l.value : l.value / 100), 1);
|
|
1600
|
+
}
|
|
1601
|
+
if (c$1.type !== Tok.None) res.c = Math.max(0, c$1.type === Tok.Number ? c$1.value : c$1.value * .4 / 100);
|
|
1602
|
+
if (h.type !== Tok.None) {
|
|
1603
|
+
if (h.type === Tok.Percentage) return void 0;
|
|
1604
|
+
res.h = h.value;
|
|
1605
|
+
}
|
|
1606
|
+
if (alpha.type !== Tok.None) res.alpha = Math.min(1, Math.max(0, alpha.type === Tok.Number ? alpha.value : alpha.value / 100));
|
|
1607
|
+
return res;
|
|
1608
|
+
}
|
|
1609
|
+
var parseOklch_default = parseOklch;
|
|
1610
|
+
|
|
1611
|
+
//#endregion
|
|
1612
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/oklch/definition.js
|
|
1613
|
+
const definition$5 = {
|
|
1614
|
+
...definition_default$5,
|
|
1615
|
+
mode: "oklch",
|
|
1616
|
+
toMode: {
|
|
1617
|
+
oklab: (c$1) => convertLchToLab_default(c$1, "oklab"),
|
|
1618
|
+
rgb: (c$1) => convertOklabToRgb_default(convertLchToLab_default(c$1, "oklab"))
|
|
1619
|
+
},
|
|
1620
|
+
fromMode: {
|
|
1621
|
+
rgb: (c$1) => convertLabToLch_default(convertRgbToOklab_default(c$1), "oklch"),
|
|
1622
|
+
oklab: (c$1) => convertLabToLch_default(c$1, "oklch")
|
|
1623
|
+
},
|
|
1624
|
+
parse: [parseOklch_default],
|
|
1625
|
+
serialize: (c$1) => `oklch(${c$1.l !== void 0 ? c$1.l : "none"} ${c$1.c !== void 0 ? c$1.c : "none"} ${c$1.h !== void 0 ? c$1.h : "none"}${c$1.alpha < 1 ? ` / ${c$1.alpha}` : ""})`,
|
|
1626
|
+
ranges: {
|
|
1627
|
+
l: [0, 1],
|
|
1628
|
+
c: [0, .4],
|
|
1629
|
+
h: [0, 360]
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
var definition_default$8 = definition$5;
|
|
1633
|
+
|
|
1634
|
+
//#endregion
|
|
1635
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/p3/convertP3ToXyz65.js
|
|
1636
|
+
const convertP3ToXyz65 = (rgb$2) => {
|
|
1637
|
+
let { r: r$1, g, b, alpha } = convertRgbToLrgb_default(rgb$2);
|
|
1638
|
+
let res = {
|
|
1639
|
+
mode: "xyz65",
|
|
1640
|
+
x: .486570948648216 * r$1 + .265667693169093 * g + .1982172852343625 * b,
|
|
1641
|
+
y: .2289745640697487 * r$1 + .6917385218365062 * g + .079286914093745 * b,
|
|
1642
|
+
z: 0 * r$1 + .0451133818589026 * g + 1.043944368900976 * b
|
|
1643
|
+
};
|
|
1644
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1645
|
+
return res;
|
|
1646
|
+
};
|
|
1647
|
+
var convertP3ToXyz65_default = convertP3ToXyz65;
|
|
1648
|
+
|
|
1649
|
+
//#endregion
|
|
1650
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/p3/convertXyz65ToP3.js
|
|
1651
|
+
const convertXyz65ToP3 = ({ x, y, z, alpha }) => {
|
|
1652
|
+
if (x === void 0) x = 0;
|
|
1653
|
+
if (y === void 0) y = 0;
|
|
1654
|
+
if (z === void 0) z = 0;
|
|
1655
|
+
let res = convertLrgbToRgb_default({
|
|
1656
|
+
r: x * 2.4934969119414263 - y * .9313836179191242 - .402710784450717 * z,
|
|
1657
|
+
g: x * -.8294889695615749 + y * 1.7626640603183465 + .0236246858419436 * z,
|
|
1658
|
+
b: x * .0358458302437845 - y * .0761723892680418 + .9568845240076871 * z
|
|
1659
|
+
}, "p3");
|
|
1660
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1661
|
+
return res;
|
|
1662
|
+
};
|
|
1663
|
+
var convertXyz65ToP3_default = convertXyz65ToP3;
|
|
1664
|
+
|
|
1665
|
+
//#endregion
|
|
1666
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/p3/definition.js
|
|
1667
|
+
const definition$4 = {
|
|
1668
|
+
...definition_default$12,
|
|
1669
|
+
mode: "p3",
|
|
1670
|
+
parse: ["display-p3"],
|
|
1671
|
+
serialize: "display-p3",
|
|
1672
|
+
fromMode: {
|
|
1673
|
+
rgb: (color) => convertXyz65ToP3_default(convertRgbToXyz65_default(color)),
|
|
1674
|
+
xyz65: convertXyz65ToP3_default
|
|
1675
|
+
},
|
|
1676
|
+
toMode: {
|
|
1677
|
+
rgb: (color) => convertXyz65ToRgb_default(convertP3ToXyz65_default(color)),
|
|
1678
|
+
xyz65: convertP3ToXyz65_default
|
|
1679
|
+
}
|
|
1680
|
+
};
|
|
1681
|
+
var definition_default$9 = definition$4;
|
|
1682
|
+
|
|
1683
|
+
//#endregion
|
|
1684
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/prophoto/convertXyz50ToProphoto.js
|
|
1685
|
+
const gamma$1 = (v) => {
|
|
1686
|
+
let abs = Math.abs(v);
|
|
1687
|
+
if (abs >= 1 / 512) return Math.sign(v) * Math.pow(abs, 1 / 1.8);
|
|
1688
|
+
return 16 * v;
|
|
1689
|
+
};
|
|
1690
|
+
const convertXyz50ToProphoto = ({ x, y, z, alpha }) => {
|
|
1691
|
+
if (x === void 0) x = 0;
|
|
1692
|
+
if (y === void 0) y = 0;
|
|
1693
|
+
if (z === void 0) z = 0;
|
|
1694
|
+
let res = {
|
|
1695
|
+
mode: "prophoto",
|
|
1696
|
+
r: gamma$1(x * 1.3457868816471585 - y * .2555720873797946 - .0511018649755453 * z),
|
|
1697
|
+
g: gamma$1(x * -.5446307051249019 + y * 1.5082477428451466 + .0205274474364214 * z),
|
|
1698
|
+
b: gamma$1(x * 0 + y * 0 + 1.2119675456389452 * z)
|
|
1699
|
+
};
|
|
1700
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1701
|
+
return res;
|
|
1702
|
+
};
|
|
1703
|
+
var convertXyz50ToProphoto_default = convertXyz50ToProphoto;
|
|
1704
|
+
|
|
1705
|
+
//#endregion
|
|
1706
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/prophoto/convertProphotoToXyz50.js
|
|
1707
|
+
const linearize$1 = (v = 0) => {
|
|
1708
|
+
let abs = Math.abs(v);
|
|
1709
|
+
if (abs >= 16 / 512) return Math.sign(v) * Math.pow(abs, 1.8);
|
|
1710
|
+
return v / 16;
|
|
1711
|
+
};
|
|
1712
|
+
const convertProphotoToXyz50 = (prophoto) => {
|
|
1713
|
+
let r$1 = linearize$1(prophoto.r);
|
|
1714
|
+
let g = linearize$1(prophoto.g);
|
|
1715
|
+
let b = linearize$1(prophoto.b);
|
|
1716
|
+
let res = {
|
|
1717
|
+
mode: "xyz50",
|
|
1718
|
+
x: .7977666449006423 * r$1 + .1351812974005331 * g + .0313477341283922 * b,
|
|
1719
|
+
y: .2880748288194013 * r$1 + .7118352342418731 * g + 899369387256e-16 * b,
|
|
1720
|
+
z: 0 * r$1 + 0 * g + .8251046025104602 * b
|
|
1721
|
+
};
|
|
1722
|
+
if (prophoto.alpha !== void 0) res.alpha = prophoto.alpha;
|
|
1723
|
+
return res;
|
|
1724
|
+
};
|
|
1725
|
+
var convertProphotoToXyz50_default = convertProphotoToXyz50;
|
|
1726
|
+
|
|
1727
|
+
//#endregion
|
|
1728
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/prophoto/definition.js
|
|
1729
|
+
const definition$3 = {
|
|
1730
|
+
...definition_default$12,
|
|
1731
|
+
mode: "prophoto",
|
|
1732
|
+
parse: ["prophoto-rgb"],
|
|
1733
|
+
serialize: "prophoto-rgb",
|
|
1734
|
+
fromMode: {
|
|
1735
|
+
xyz50: convertXyz50ToProphoto_default,
|
|
1736
|
+
rgb: (color) => convertXyz50ToProphoto_default(convertRgbToXyz50_default(color))
|
|
1737
|
+
},
|
|
1738
|
+
toMode: {
|
|
1739
|
+
xyz50: convertProphotoToXyz50_default,
|
|
1740
|
+
rgb: (color) => convertXyz50ToRgb_default(convertProphotoToXyz50_default(color))
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
var definition_default$10 = definition$3;
|
|
1744
|
+
|
|
1745
|
+
//#endregion
|
|
1746
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/rec2020/convertXyz65ToRec2020.js
|
|
1747
|
+
const α$1 = 1.09929682680944;
|
|
1748
|
+
const β$1 = .018053968510807;
|
|
1749
|
+
const gamma = (v) => {
|
|
1750
|
+
const abs = Math.abs(v);
|
|
1751
|
+
if (abs > β$1) return (Math.sign(v) || 1) * (α$1 * Math.pow(abs, .45) - (α$1 - 1));
|
|
1752
|
+
return 4.5 * v;
|
|
1753
|
+
};
|
|
1754
|
+
const convertXyz65ToRec2020 = ({ x, y, z, alpha }) => {
|
|
1755
|
+
if (x === void 0) x = 0;
|
|
1756
|
+
if (y === void 0) y = 0;
|
|
1757
|
+
if (z === void 0) z = 0;
|
|
1758
|
+
let res = {
|
|
1759
|
+
mode: "rec2020",
|
|
1760
|
+
r: gamma(x * 1.7166511879712683 - y * .3556707837763925 - .2533662813736599 * z),
|
|
1761
|
+
g: gamma(x * -.6666843518324893 + y * 1.6164812366349395 + .0157685458139111 * z),
|
|
1762
|
+
b: gamma(x * .0176398574453108 - y * .0427706132578085 + .9421031212354739 * z)
|
|
1763
|
+
};
|
|
1764
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1765
|
+
return res;
|
|
1766
|
+
};
|
|
1767
|
+
var convertXyz65ToRec2020_default = convertXyz65ToRec2020;
|
|
1768
|
+
|
|
1769
|
+
//#endregion
|
|
1770
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/rec2020/convertRec2020ToXyz65.js
|
|
1771
|
+
const α = 1.09929682680944;
|
|
1772
|
+
const β = .018053968510807;
|
|
1773
|
+
const linearize = (v = 0) => {
|
|
1774
|
+
let abs = Math.abs(v);
|
|
1775
|
+
if (abs < β * 4.5) return v / 4.5;
|
|
1776
|
+
return (Math.sign(v) || 1) * Math.pow((abs + α - 1) / α, 1 / .45);
|
|
1777
|
+
};
|
|
1778
|
+
const convertRec2020ToXyz65 = (rec2020) => {
|
|
1779
|
+
let r$1 = linearize(rec2020.r);
|
|
1780
|
+
let g = linearize(rec2020.g);
|
|
1781
|
+
let b = linearize(rec2020.b);
|
|
1782
|
+
let res = {
|
|
1783
|
+
mode: "xyz65",
|
|
1784
|
+
x: .6369580483012911 * r$1 + .1446169035862083 * g + .1688809751641721 * b,
|
|
1785
|
+
y: .262700212011267 * r$1 + .6779980715188708 * g + .059301716469862 * b,
|
|
1786
|
+
z: 0 * r$1 + .0280726930490874 * g + 1.0609850577107909 * b
|
|
1787
|
+
};
|
|
1788
|
+
if (rec2020.alpha !== void 0) res.alpha = rec2020.alpha;
|
|
1789
|
+
return res;
|
|
1790
|
+
};
|
|
1791
|
+
var convertRec2020ToXyz65_default = convertRec2020ToXyz65;
|
|
1792
|
+
|
|
1793
|
+
//#endregion
|
|
1794
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/rec2020/definition.js
|
|
1795
|
+
const definition$2 = {
|
|
1796
|
+
...definition_default$12,
|
|
1797
|
+
mode: "rec2020",
|
|
1798
|
+
fromMode: {
|
|
1799
|
+
xyz65: convertXyz65ToRec2020_default,
|
|
1800
|
+
rgb: (color) => convertXyz65ToRec2020_default(convertRgbToXyz65_default(color))
|
|
1801
|
+
},
|
|
1802
|
+
toMode: {
|
|
1803
|
+
xyz65: convertRec2020ToXyz65_default,
|
|
1804
|
+
rgb: (color) => convertXyz65ToRgb_default(convertRec2020ToXyz65_default(color))
|
|
1805
|
+
},
|
|
1806
|
+
parse: ["rec2020"],
|
|
1807
|
+
serialize: "rec2020"
|
|
1808
|
+
};
|
|
1809
|
+
var definition_default$11 = definition$2;
|
|
1810
|
+
|
|
1811
|
+
//#endregion
|
|
1812
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/xyz50/definition.js
|
|
1813
|
+
const definition$1 = {
|
|
1814
|
+
mode: "xyz50",
|
|
1815
|
+
parse: ["xyz-d50"],
|
|
1816
|
+
serialize: "xyz-d50",
|
|
1817
|
+
toMode: {
|
|
1818
|
+
rgb: convertXyz50ToRgb_default,
|
|
1819
|
+
lab: convertXyz50ToLab_default
|
|
1820
|
+
},
|
|
1821
|
+
fromMode: {
|
|
1822
|
+
rgb: convertRgbToXyz50_default,
|
|
1823
|
+
lab: convertLabToXyz50_default
|
|
1824
|
+
},
|
|
1825
|
+
channels: [
|
|
1826
|
+
"x",
|
|
1827
|
+
"y",
|
|
1828
|
+
"z",
|
|
1829
|
+
"alpha"
|
|
1830
|
+
],
|
|
1831
|
+
ranges: {
|
|
1832
|
+
x: [0, .964],
|
|
1833
|
+
y: [0, .999],
|
|
1834
|
+
z: [0, .825]
|
|
1835
|
+
},
|
|
1836
|
+
interpolate: {
|
|
1837
|
+
x: interpolatorLinear,
|
|
1838
|
+
y: interpolatorLinear,
|
|
1839
|
+
z: interpolatorLinear,
|
|
1840
|
+
alpha: {
|
|
1841
|
+
use: interpolatorLinear,
|
|
1842
|
+
fixup: fixupAlpha
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
};
|
|
1846
|
+
var definition_default$13 = definition$1;
|
|
1847
|
+
|
|
1848
|
+
//#endregion
|
|
1849
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/xyz65/convertXyz65ToXyz50.js
|
|
1850
|
+
const convertXyz65ToXyz50 = (xyz65) => {
|
|
1851
|
+
let { x, y, z, alpha } = xyz65;
|
|
1852
|
+
if (x === void 0) x = 0;
|
|
1853
|
+
if (y === void 0) y = 0;
|
|
1854
|
+
if (z === void 0) z = 0;
|
|
1855
|
+
let res = {
|
|
1856
|
+
mode: "xyz50",
|
|
1857
|
+
x: 1.0479298208405488 * x + .0229467933410191 * y - .0501922295431356 * z,
|
|
1858
|
+
y: .0296278156881593 * x + .990434484573249 * y - .0170738250293851 * z,
|
|
1859
|
+
z: -.0092430581525912 * x + .0150551448965779 * y + .7518742899580008 * z
|
|
1860
|
+
};
|
|
1861
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1862
|
+
return res;
|
|
1863
|
+
};
|
|
1864
|
+
var convertXyz65ToXyz50_default = convertXyz65ToXyz50;
|
|
1865
|
+
|
|
1866
|
+
//#endregion
|
|
1867
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/xyz65/convertXyz50ToXyz65.js
|
|
1868
|
+
const convertXyz50ToXyz65 = (xyz50) => {
|
|
1869
|
+
let { x, y, z, alpha } = xyz50;
|
|
1870
|
+
if (x === void 0) x = 0;
|
|
1871
|
+
if (y === void 0) y = 0;
|
|
1872
|
+
if (z === void 0) z = 0;
|
|
1873
|
+
let res = {
|
|
1874
|
+
mode: "xyz65",
|
|
1875
|
+
x: .9554734527042182 * x - .0230985368742614 * y + .0632593086610217 * z,
|
|
1876
|
+
y: -.0283697069632081 * x + 1.0099954580058226 * y + .021041398966943 * z,
|
|
1877
|
+
z: .0123140016883199 * x - .0205076964334779 * y + 1.3303659366080753 * z
|
|
1878
|
+
};
|
|
1879
|
+
if (alpha !== void 0) res.alpha = alpha;
|
|
1880
|
+
return res;
|
|
1881
|
+
};
|
|
1882
|
+
var convertXyz50ToXyz65_default = convertXyz50ToXyz65;
|
|
1883
|
+
|
|
1884
|
+
//#endregion
|
|
1885
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/xyz65/definition.js
|
|
1886
|
+
const definition = {
|
|
1887
|
+
mode: "xyz65",
|
|
1888
|
+
toMode: {
|
|
1889
|
+
rgb: convertXyz65ToRgb_default,
|
|
1890
|
+
xyz50: convertXyz65ToXyz50_default
|
|
1891
|
+
},
|
|
1892
|
+
fromMode: {
|
|
1893
|
+
rgb: convertRgbToXyz65_default,
|
|
1894
|
+
xyz50: convertXyz50ToXyz65_default
|
|
1895
|
+
},
|
|
1896
|
+
ranges: {
|
|
1897
|
+
x: [0, .95],
|
|
1898
|
+
y: [0, 1],
|
|
1899
|
+
z: [0, 1.088]
|
|
1900
|
+
},
|
|
1901
|
+
channels: [
|
|
1902
|
+
"x",
|
|
1903
|
+
"y",
|
|
1904
|
+
"z",
|
|
1905
|
+
"alpha"
|
|
1906
|
+
],
|
|
1907
|
+
parse: ["xyz", "xyz-d65"],
|
|
1908
|
+
serialize: "xyz-d65",
|
|
1909
|
+
interpolate: {
|
|
1910
|
+
x: interpolatorLinear,
|
|
1911
|
+
y: interpolatorLinear,
|
|
1912
|
+
z: interpolatorLinear,
|
|
1913
|
+
alpha: {
|
|
1914
|
+
use: interpolatorLinear,
|
|
1915
|
+
fixup: fixupAlpha
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
};
|
|
1919
|
+
var definition_default$14 = definition;
|
|
1920
|
+
|
|
1921
|
+
//#endregion
|
|
1922
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/round.js
|
|
1923
|
+
const r = (value, precision) => Math.round(value * (precision = Math.pow(10, precision))) / precision;
|
|
1924
|
+
const round = (precision = 4) => (value) => typeof value === "number" ? r(value, precision) : value;
|
|
1925
|
+
var round_default = round;
|
|
1926
|
+
|
|
1927
|
+
//#endregion
|
|
1928
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/formatter.js
|
|
1929
|
+
let twoDecimals = round_default(2);
|
|
1930
|
+
const clamp = (value) => Math.max(0, Math.min(1, value || 0));
|
|
1931
|
+
const fixup = (value) => Math.round(clamp(value) * 255);
|
|
1932
|
+
const rgb$1 = converter_default("rgb");
|
|
1933
|
+
const hsl = converter_default("hsl");
|
|
1934
|
+
const serializeHex = (color) => {
|
|
1935
|
+
if (color === void 0) return void 0;
|
|
1936
|
+
let r$1 = fixup(color.r);
|
|
1937
|
+
let g = fixup(color.g);
|
|
1938
|
+
let b = fixup(color.b);
|
|
1939
|
+
return "#" + (1 << 24 | r$1 << 16 | g << 8 | b).toString(16).slice(1);
|
|
1940
|
+
};
|
|
1941
|
+
const serializeHex8 = (color) => {
|
|
1942
|
+
if (color === void 0) return void 0;
|
|
1943
|
+
let a = fixup(color.alpha !== void 0 ? color.alpha : 1);
|
|
1944
|
+
return serializeHex(color) + (256 | a).toString(16).slice(1);
|
|
1945
|
+
};
|
|
1946
|
+
const formatCss = (c$1) => {
|
|
1947
|
+
const color = _prepare_default(c$1);
|
|
1948
|
+
if (!color) return void 0;
|
|
1949
|
+
const def = getMode(color.mode);
|
|
1950
|
+
if (!def.serialize || typeof def.serialize === "string") {
|
|
1951
|
+
let res = `color(${def.serialize || `--${color.mode}`} `;
|
|
1952
|
+
def.channels.forEach((ch, i) => {
|
|
1953
|
+
if (ch !== "alpha") res += (i ? " " : "") + (color[ch] !== void 0 ? color[ch] : "none");
|
|
1954
|
+
});
|
|
1955
|
+
if (color.alpha !== void 0 && color.alpha < 1) res += ` / ${color.alpha}`;
|
|
1956
|
+
return res + ")";
|
|
1957
|
+
}
|
|
1958
|
+
if (typeof def.serialize === "function") return def.serialize(color);
|
|
1959
|
+
return void 0;
|
|
1960
|
+
};
|
|
1961
|
+
const formatHex = (c$1) => serializeHex(rgb$1(c$1));
|
|
1962
|
+
const formatHex8 = (c$1) => serializeHex8(rgb$1(c$1));
|
|
1963
|
+
|
|
1964
|
+
//#endregion
|
|
1965
|
+
//#region ../../node_modules/.pnpm/culori@4.0.1/node_modules/culori/src/clamp.js
|
|
1966
|
+
const rgb = converter_default("rgb");
|
|
1967
|
+
const fixup_rgb = (c$1) => {
|
|
1968
|
+
const res = {
|
|
1969
|
+
mode: c$1.mode,
|
|
1970
|
+
r: Math.max(0, Math.min(c$1.r !== void 0 ? c$1.r : 0, 1)),
|
|
1971
|
+
g: Math.max(0, Math.min(c$1.g !== void 0 ? c$1.g : 0, 1)),
|
|
1972
|
+
b: Math.max(0, Math.min(c$1.b !== void 0 ? c$1.b : 0, 1))
|
|
1973
|
+
};
|
|
1974
|
+
if (c$1.alpha !== void 0) res.alpha = c$1.alpha;
|
|
1975
|
+
return res;
|
|
1976
|
+
};
|
|
1977
|
+
const inrange_rgb = (c$1) => {
|
|
1978
|
+
return c$1 !== void 0 && (c$1.r === void 0 || c$1.r >= 0 && c$1.r <= 1) && (c$1.g === void 0 || c$1.g >= 0 && c$1.g <= 1) && (c$1.b === void 0 || c$1.b >= 0 && c$1.b <= 1);
|
|
1979
|
+
};
|
|
1980
|
+
function displayable(color) {
|
|
1981
|
+
return inrange_rgb(rgb(color));
|
|
1982
|
+
}
|
|
1983
|
+
function inGamut(mode = "rgb") {
|
|
1984
|
+
const { gamut } = getMode(mode);
|
|
1985
|
+
if (!gamut) return (color) => true;
|
|
1986
|
+
const conv = converter_default(typeof gamut === "string" ? gamut : mode);
|
|
1987
|
+
return (color) => inrange_rgb(conv(color));
|
|
1988
|
+
}
|
|
1989
|
+
function clampGamut(mode = "rgb") {
|
|
1990
|
+
const { gamut } = getMode(mode);
|
|
1991
|
+
if (!gamut) return (color) => _prepare_default(color);
|
|
1992
|
+
const destMode = typeof gamut === "string" ? gamut : mode;
|
|
1993
|
+
const destConv = converter_default(destMode);
|
|
1994
|
+
const inDestGamut = inGamut(destMode);
|
|
1995
|
+
return (color) => {
|
|
1996
|
+
const original = _prepare_default(color);
|
|
1997
|
+
if (!original) return void 0;
|
|
1998
|
+
const converted = destConv(original);
|
|
1999
|
+
if (inDestGamut(converted)) return original;
|
|
2000
|
+
const clamped = fixup_rgb(converted);
|
|
2001
|
+
if (original.mode === clamped.mode) return clamped;
|
|
2002
|
+
return converter_default(original.mode)(clamped);
|
|
2003
|
+
};
|
|
2004
|
+
}
|
|
2005
|
+
function toGamut(dest = "rgb", mode = "oklch", delta = differenceEuclidean("oklch"), jnd = .02) {
|
|
2006
|
+
const destConv = converter_default(dest);
|
|
2007
|
+
const destMode = getMode(dest);
|
|
2008
|
+
if (!destMode.gamut) return (color) => destConv(color);
|
|
2009
|
+
const inDestinationGamut = inGamut(dest);
|
|
2010
|
+
const clipToGamut = clampGamut(dest);
|
|
2011
|
+
const ucs = converter_default(mode);
|
|
2012
|
+
const { ranges } = getMode(mode);
|
|
2013
|
+
return (color) => {
|
|
2014
|
+
color = _prepare_default(color);
|
|
2015
|
+
if (color === void 0) return void 0;
|
|
2016
|
+
const candidate = { ...ucs(color) };
|
|
2017
|
+
if (candidate.l === void 0) candidate.l = 0;
|
|
2018
|
+
if (candidate.c === void 0) candidate.c = 0;
|
|
2019
|
+
if (candidate.l >= ranges.l[1]) {
|
|
2020
|
+
const res = {
|
|
2021
|
+
...destMode.white,
|
|
2022
|
+
mode: dest
|
|
2023
|
+
};
|
|
2024
|
+
if (color.alpha !== void 0) res.alpha = color.alpha;
|
|
2025
|
+
return res;
|
|
2026
|
+
}
|
|
2027
|
+
if (candidate.l <= ranges.l[0]) {
|
|
2028
|
+
const res = {
|
|
2029
|
+
...destMode.black,
|
|
2030
|
+
mode: dest
|
|
2031
|
+
};
|
|
2032
|
+
if (color.alpha !== void 0) res.alpha = color.alpha;
|
|
2033
|
+
return res;
|
|
2034
|
+
}
|
|
2035
|
+
if (inDestinationGamut(candidate)) return destConv(candidate);
|
|
2036
|
+
let start = 0;
|
|
2037
|
+
let end = candidate.c;
|
|
2038
|
+
let epsilon = (ranges.c[1] - ranges.c[0]) / 4e3;
|
|
2039
|
+
let clipped = clipToGamut(candidate);
|
|
2040
|
+
while (end - start > epsilon) {
|
|
2041
|
+
candidate.c = (start + end) * .5;
|
|
2042
|
+
clipped = clipToGamut(candidate);
|
|
2043
|
+
if (inDestinationGamut(candidate) || delta && jnd > 0 && delta(candidate, clipped) <= jnd) start = candidate.c;
|
|
2044
|
+
else end = candidate.c;
|
|
2045
|
+
}
|
|
2046
|
+
return destConv(inDestinationGamut(candidate) ? candidate : clipped);
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
//#endregion
|
|
2051
|
+
//#region ../token-tools/dist/string-BZ5Le1WD.js
|
|
2052
|
+
const HEX_RE = /^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i;
|
|
2053
|
+
const CULORI_TO_CSS = {
|
|
2054
|
+
a98: "a98",
|
|
2055
|
+
hsl: "hsl",
|
|
2056
|
+
hsv: "hsv",
|
|
2057
|
+
hwb: "hwb",
|
|
2058
|
+
lab: "lab",
|
|
2059
|
+
lch: "lch",
|
|
2060
|
+
lrgb: "srgb-linear",
|
|
2061
|
+
oklab: "oklab",
|
|
2062
|
+
oklch: "oklch",
|
|
2063
|
+
p3: "display-p3",
|
|
2064
|
+
prophoto: "prophoto-rgb",
|
|
2065
|
+
rec2020: "rec2020",
|
|
2066
|
+
rgb: "srgb",
|
|
2067
|
+
xyz50: "xyz-d50",
|
|
2068
|
+
xyz65: "xyz-d65"
|
|
2069
|
+
};
|
|
2070
|
+
const CSS_TO_CULORI = {
|
|
2071
|
+
a98: "a98",
|
|
2072
|
+
"display-p3": "p3",
|
|
2073
|
+
hsl: "hsl",
|
|
2074
|
+
hsv: "hsv",
|
|
2075
|
+
hwb: "hwb",
|
|
2076
|
+
lab: "lab",
|
|
2077
|
+
lch: "lch",
|
|
2078
|
+
oklab: "oklab",
|
|
2079
|
+
oklch: "oklch",
|
|
2080
|
+
"prophoto-rgb": "prophoto",
|
|
2081
|
+
rec2020: "rec2020",
|
|
2082
|
+
srgb: "rgb",
|
|
2083
|
+
"srgb-linear": "lrgb",
|
|
2084
|
+
"xyz-d50": "xyz50",
|
|
2085
|
+
"xyz-d65": "xyz65"
|
|
2086
|
+
};
|
|
2087
|
+
/** Parse any color */
|
|
2088
|
+
function parseColor(color) {
|
|
2089
|
+
const result = parse_default(color);
|
|
2090
|
+
if (!result) throw new Error(`Unable to parse color "${color}"`);
|
|
2091
|
+
if (!(result.mode in CULORI_TO_CSS)) throw new Error(`Unsupported color space: ${result.mode}`);
|
|
2092
|
+
const colorSpace = CULORI_TO_CSS[result.mode];
|
|
2093
|
+
let components = [
|
|
2094
|
+
0,
|
|
2095
|
+
0,
|
|
2096
|
+
0
|
|
2097
|
+
];
|
|
2098
|
+
switch (result.mode) {
|
|
2099
|
+
case "a98":
|
|
2100
|
+
case "rec2020":
|
|
2101
|
+
case "p3":
|
|
2102
|
+
case "prophoto":
|
|
2103
|
+
case "lrgb":
|
|
2104
|
+
case "rgb": {
|
|
2105
|
+
components = [
|
|
2106
|
+
result.r,
|
|
2107
|
+
result.g,
|
|
2108
|
+
result.b
|
|
2109
|
+
];
|
|
2110
|
+
break;
|
|
2111
|
+
}
|
|
2112
|
+
case "hsl": {
|
|
2113
|
+
components = [
|
|
2114
|
+
result.h ?? 0,
|
|
2115
|
+
result.s,
|
|
2116
|
+
result.l
|
|
2117
|
+
];
|
|
2118
|
+
break;
|
|
2119
|
+
}
|
|
2120
|
+
case "hsv": {
|
|
2121
|
+
components = [
|
|
2122
|
+
result.h ?? 0,
|
|
2123
|
+
result.s,
|
|
2124
|
+
result.v
|
|
2125
|
+
];
|
|
2126
|
+
break;
|
|
2127
|
+
}
|
|
2128
|
+
case "hwb": {
|
|
2129
|
+
components = [
|
|
2130
|
+
result.h ?? 0,
|
|
2131
|
+
result.w,
|
|
2132
|
+
result.b
|
|
2133
|
+
];
|
|
2134
|
+
break;
|
|
2135
|
+
}
|
|
2136
|
+
case "lab":
|
|
2137
|
+
case "oklab": {
|
|
2138
|
+
components = [
|
|
2139
|
+
result.l,
|
|
2140
|
+
result.a,
|
|
2141
|
+
result.b
|
|
2142
|
+
];
|
|
2143
|
+
break;
|
|
2144
|
+
}
|
|
2145
|
+
case "lch":
|
|
2146
|
+
case "oklch": {
|
|
2147
|
+
components = [
|
|
2148
|
+
result.l,
|
|
2149
|
+
result.c,
|
|
2150
|
+
result.h ?? 0
|
|
2151
|
+
];
|
|
2152
|
+
break;
|
|
2153
|
+
}
|
|
2154
|
+
case "xyz50":
|
|
2155
|
+
case "xyz65": {
|
|
2156
|
+
components = [
|
|
2157
|
+
result.x,
|
|
2158
|
+
result.y,
|
|
2159
|
+
result.z
|
|
2160
|
+
];
|
|
2161
|
+
break;
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
const value = {
|
|
2165
|
+
colorSpace,
|
|
2166
|
+
components,
|
|
2167
|
+
alpha: result.alpha ?? 1
|
|
2168
|
+
};
|
|
2169
|
+
if (HEX_RE.test(color)) value.hex = formatHex(result);
|
|
2170
|
+
return value;
|
|
2171
|
+
}
|
|
2172
|
+
/** Convert a color token to a Culori color */
|
|
2173
|
+
function tokenToCulori(value) {
|
|
2174
|
+
switch (value.colorSpace) {
|
|
2175
|
+
case "a98":
|
|
2176
|
+
case "display-p3":
|
|
2177
|
+
case "prophoto-rgb":
|
|
2178
|
+
case "rec2020":
|
|
2179
|
+
case "srgb":
|
|
2180
|
+
case "srgb-linear": {
|
|
2181
|
+
const [r$1, g, b] = value.components;
|
|
2182
|
+
return {
|
|
2183
|
+
mode: CSS_TO_CULORI[value.colorSpace] || value.colorSpace,
|
|
2184
|
+
r: r$1,
|
|
2185
|
+
g,
|
|
2186
|
+
b,
|
|
2187
|
+
alpha: value.alpha
|
|
2188
|
+
};
|
|
2189
|
+
}
|
|
2190
|
+
case "hsl": {
|
|
2191
|
+
const [h, s, l] = value.components;
|
|
2192
|
+
return {
|
|
2193
|
+
mode: "hsl",
|
|
2194
|
+
h,
|
|
2195
|
+
s,
|
|
2196
|
+
l,
|
|
2197
|
+
alpha: value.alpha
|
|
2198
|
+
};
|
|
2199
|
+
}
|
|
2200
|
+
case "hsv": {
|
|
2201
|
+
const [h, s, v] = value.components;
|
|
2202
|
+
return {
|
|
2203
|
+
mode: "hsv",
|
|
2204
|
+
h,
|
|
2205
|
+
s,
|
|
2206
|
+
v,
|
|
2207
|
+
alpha: value.alpha
|
|
2208
|
+
};
|
|
2209
|
+
}
|
|
2210
|
+
case "hwb": {
|
|
2211
|
+
const [h, w, b] = value.components;
|
|
2212
|
+
return {
|
|
2213
|
+
mode: "hwb",
|
|
2214
|
+
h,
|
|
2215
|
+
w,
|
|
2216
|
+
b,
|
|
2217
|
+
alpha: value.alpha
|
|
2218
|
+
};
|
|
2219
|
+
}
|
|
2220
|
+
case "lab":
|
|
2221
|
+
case "oklab": {
|
|
2222
|
+
const [l, a, b] = value.components;
|
|
2223
|
+
return {
|
|
2224
|
+
mode: value.colorSpace,
|
|
2225
|
+
l,
|
|
2226
|
+
a,
|
|
2227
|
+
b,
|
|
2228
|
+
alpha: value.alpha
|
|
2229
|
+
};
|
|
2230
|
+
}
|
|
2231
|
+
case "lch":
|
|
2232
|
+
case "oklch": {
|
|
2233
|
+
const [l, c$1, h] = value.components;
|
|
2234
|
+
return {
|
|
2235
|
+
mode: value.colorSpace,
|
|
2236
|
+
l,
|
|
2237
|
+
c: c$1,
|
|
2238
|
+
h,
|
|
2239
|
+
alpha: value.alpha
|
|
2240
|
+
};
|
|
2241
|
+
}
|
|
2242
|
+
case "xyz-d50": {
|
|
2243
|
+
const [x, y, z] = value.components;
|
|
2244
|
+
return {
|
|
2245
|
+
mode: "xyz50",
|
|
2246
|
+
x,
|
|
2247
|
+
y,
|
|
2248
|
+
z,
|
|
2249
|
+
alpha: value.alpha
|
|
2250
|
+
};
|
|
2251
|
+
}
|
|
2252
|
+
case "xyz-d65": {
|
|
2253
|
+
const [x, y, z] = value.components;
|
|
2254
|
+
return {
|
|
2255
|
+
mode: "xyz65",
|
|
2256
|
+
x,
|
|
2257
|
+
y,
|
|
2258
|
+
z,
|
|
2259
|
+
alpha: value.alpha
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
/** Turn a string into kebab-case */
|
|
2265
|
+
function kebabCase(str) {
|
|
2266
|
+
let output = "";
|
|
2267
|
+
for (const c$1 of str.split("")) {
|
|
2268
|
+
if (c$1 === ".") {
|
|
2269
|
+
output += "-";
|
|
2270
|
+
continue;
|
|
2271
|
+
}
|
|
2272
|
+
let isFirstUppercase = true;
|
|
2273
|
+
if (isFirstUppercase && /\p{Uppercase_Letter}/u.test(c$1)) {
|
|
2274
|
+
output += `-${c$1.toLocaleLowerCase()}`;
|
|
2275
|
+
isFirstUppercase = false;
|
|
2276
|
+
continue;
|
|
2277
|
+
} else isFirstUppercase = true;
|
|
2278
|
+
output += c$1;
|
|
2279
|
+
}
|
|
2280
|
+
return output;
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2283
|
+
//#endregion
|
|
2284
|
+
//#region ../../node_modules/.pnpm/wildcard-match@5.1.4/node_modules/wildcard-match/build/index.es.mjs
|
|
2285
|
+
/**
|
|
2286
|
+
* Escapes a character if it has a special meaning in regular expressions
|
|
2287
|
+
* and returns the character as is if it doesn't
|
|
2288
|
+
*/
|
|
2289
|
+
function escapeRegExpChar(char) {
|
|
2290
|
+
if (char === "-" || char === "^" || char === "$" || char === "+" || char === "." || char === "(" || char === ")" || char === "|" || char === "[" || char === "]" || char === "{" || char === "}" || char === "*" || char === "?" || char === "\\") return "\\".concat(char);
|
|
2291
|
+
else return char;
|
|
2292
|
+
}
|
|
2293
|
+
/**
|
|
2294
|
+
* Escapes all characters in a given string that have a special meaning in regular expressions
|
|
2295
|
+
*/
|
|
2296
|
+
function escapeRegExpString(str) {
|
|
2297
|
+
var result = "";
|
|
2298
|
+
for (var i = 0; i < str.length; i++) result += escapeRegExpChar(str[i]);
|
|
2299
|
+
return result;
|
|
2300
|
+
}
|
|
2301
|
+
/**
|
|
2302
|
+
* Transforms one or more glob patterns into a RegExp pattern
|
|
2303
|
+
*/
|
|
2304
|
+
function transform(pattern, separator) {
|
|
2305
|
+
if (separator === void 0) separator = true;
|
|
2306
|
+
if (Array.isArray(pattern)) {
|
|
2307
|
+
var regExpPatterns = pattern.map(function(p) {
|
|
2308
|
+
return "^".concat(transform(p, separator), "$");
|
|
2309
|
+
});
|
|
2310
|
+
return "(?:".concat(regExpPatterns.join("|"), ")");
|
|
2311
|
+
}
|
|
2312
|
+
var separatorSplitter = "";
|
|
2313
|
+
var separatorMatcher = "";
|
|
2314
|
+
var wildcard = ".";
|
|
2315
|
+
if (separator === true) {
|
|
2316
|
+
separatorSplitter = "/";
|
|
2317
|
+
separatorMatcher = "[/\\\\]";
|
|
2318
|
+
wildcard = "[^/\\\\]";
|
|
2319
|
+
} else if (separator) {
|
|
2320
|
+
separatorSplitter = separator;
|
|
2321
|
+
separatorMatcher = escapeRegExpString(separatorSplitter);
|
|
2322
|
+
if (separatorMatcher.length > 1) {
|
|
2323
|
+
separatorMatcher = "(?:".concat(separatorMatcher, ")");
|
|
2324
|
+
wildcard = "((?!".concat(separatorMatcher, ").)");
|
|
2325
|
+
} else wildcard = "[^".concat(separatorMatcher, "]");
|
|
2326
|
+
}
|
|
2327
|
+
var requiredSeparator = separator ? "".concat(separatorMatcher, "+?") : "";
|
|
2328
|
+
var optionalSeparator = separator ? "".concat(separatorMatcher, "*?") : "";
|
|
2329
|
+
var segments = separator ? pattern.split(separatorSplitter) : [pattern];
|
|
2330
|
+
var result = "";
|
|
2331
|
+
for (var s = 0; s < segments.length; s++) {
|
|
2332
|
+
var segment = segments[s];
|
|
2333
|
+
var nextSegment = segments[s + 1];
|
|
2334
|
+
var currentSeparator = "";
|
|
2335
|
+
if (!segment && s > 0) continue;
|
|
2336
|
+
if (separator) if (s === segments.length - 1) currentSeparator = optionalSeparator;
|
|
2337
|
+
else if (nextSegment !== "**") currentSeparator = requiredSeparator;
|
|
2338
|
+
else currentSeparator = "";
|
|
2339
|
+
if (separator && segment === "**") {
|
|
2340
|
+
if (currentSeparator) {
|
|
2341
|
+
result += s === 0 ? "" : s === segments.length - 1 ? "(?:".concat(requiredSeparator, "|$)") : requiredSeparator;
|
|
2342
|
+
result += "(?:".concat(wildcard, "*?").concat(currentSeparator, ")*?");
|
|
2343
|
+
}
|
|
2344
|
+
continue;
|
|
2345
|
+
}
|
|
2346
|
+
for (var c$1 = 0; c$1 < segment.length; c$1++) {
|
|
2347
|
+
var char = segment[c$1];
|
|
2348
|
+
if (char === "\\") {
|
|
2349
|
+
if (c$1 < segment.length - 1) {
|
|
2350
|
+
result += escapeRegExpChar(segment[c$1 + 1]);
|
|
2351
|
+
c$1++;
|
|
2352
|
+
}
|
|
2353
|
+
} else if (char === "?") result += wildcard;
|
|
2354
|
+
else if (char === "*") result += "".concat(wildcard, "*?");
|
|
2355
|
+
else result += escapeRegExpChar(char);
|
|
2356
|
+
}
|
|
2357
|
+
result += currentSeparator;
|
|
2358
|
+
}
|
|
2359
|
+
return result;
|
|
2360
|
+
}
|
|
2361
|
+
function isMatch(regexp, sample) {
|
|
2362
|
+
if (typeof sample !== "string") throw new TypeError("Sample must be a string, but ".concat(typeof sample, " given"));
|
|
2363
|
+
return regexp.test(sample);
|
|
2364
|
+
}
|
|
2365
|
+
/**
|
|
2366
|
+
* Compiles one or more glob patterns into a RegExp and returns an isMatch function.
|
|
2367
|
+
* The isMatch function takes a sample string as its only argument and returns `true`
|
|
2368
|
+
* if the string matches the pattern(s).
|
|
2369
|
+
*
|
|
2370
|
+
* ```js
|
|
2371
|
+
* wildcardMatch('src/*.js')('src/index.js') //=> true
|
|
2372
|
+
* ```
|
|
2373
|
+
*
|
|
2374
|
+
* ```js
|
|
2375
|
+
* const isMatch = wildcardMatch('*.example.com', '.')
|
|
2376
|
+
* isMatch('foo.example.com') //=> true
|
|
2377
|
+
* isMatch('foo.bar.com') //=> false
|
|
2378
|
+
* ```
|
|
2379
|
+
*/
|
|
2380
|
+
function wildcardMatch(pattern, options) {
|
|
2381
|
+
if (typeof pattern !== "string" && !Array.isArray(pattern)) throw new TypeError("The first argument must be a single pattern string or an array of patterns, but ".concat(typeof pattern, " given"));
|
|
2382
|
+
if (typeof options === "string" || typeof options === "boolean") options = { separator: options };
|
|
2383
|
+
if (arguments.length === 2 && !(typeof options === "undefined" || typeof options === "object" && options !== null && !Array.isArray(options))) throw new TypeError("The second argument must be an options object or a string/boolean separator, but ".concat(typeof options, " given"));
|
|
2384
|
+
options = options || {};
|
|
2385
|
+
if (options.separator === "\\") throw new Error("\\ is not a valid separator because it is used for escaping. Try setting the separator to `true` instead");
|
|
2386
|
+
var regexpPattern = transform(pattern, options.separator);
|
|
2387
|
+
var regexp = new RegExp("^".concat(regexpPattern, "$"), options.flags);
|
|
2388
|
+
var fn$3 = isMatch.bind(null, regexp);
|
|
2389
|
+
fn$3.options = options;
|
|
2390
|
+
fn$3.pattern = pattern;
|
|
2391
|
+
fn$3.regexp = regexp;
|
|
2392
|
+
return fn$3;
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2395
|
+
//#endregion
|
|
2396
|
+
//#region ../token-tools/dist/index.js
|
|
2397
|
+
/** Match token against globs */
|
|
2398
|
+
function isTokenMatch(tokenID, globPatterns) {
|
|
2399
|
+
return wildcardMatch(globPatterns)(tokenID);
|
|
2400
|
+
}
|
|
2401
|
+
/** Give a user pertinent feedback if they override a transform incorrectly */
|
|
2402
|
+
function validateCustomTransform(value, { $type }) {
|
|
2403
|
+
if (value) {
|
|
2404
|
+
if (typeof value !== "string" && typeof value !== "object" || Array.isArray(value)) throw new Error(`transform(): expected string or Object of strings, received ${Array.isArray(value) ? "Array" : typeof value}`);
|
|
2405
|
+
switch ($type) {
|
|
2406
|
+
case "typography": {
|
|
2407
|
+
if (typeof value !== "object") throw new Error("transform(): typography tokens must be an object of keys");
|
|
2408
|
+
break;
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2414
|
+
//#endregion
|
|
2415
|
+
//#region ../token-tools/dist/css.js
|
|
2416
|
+
function defaultAliasTransform(token) {
|
|
2417
|
+
if (!token) throw new Error("Undefined token");
|
|
2418
|
+
return `var(${makeCSSVar(token.id)})`;
|
|
2419
|
+
}
|
|
2420
|
+
/** Generate shorthand CSS for select token types */
|
|
2421
|
+
function generateShorthand({ $type, localID }) {
|
|
2422
|
+
switch ($type) {
|
|
2423
|
+
case "transition": return [
|
|
2424
|
+
"duration",
|
|
2425
|
+
"delay",
|
|
2426
|
+
"timing-function"
|
|
2427
|
+
].map((p) => makeCSSVar(`${localID}-${p}`, { wrapVar: true })).join(" ");
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
const CSS_VAR_RE = /(?:(\p{Uppercase_Letter}?[\p{Lowercase_Letter}\p{Number}]+|[\p{Uppercase_Letter}\p{Number}]+|[\u{80}-\u{10FFFF}\p{Number}]+)|.)/u;
|
|
2431
|
+
/**
|
|
2432
|
+
* Generate a valid CSS variable from any string
|
|
2433
|
+
* Code by @dfrankland
|
|
2434
|
+
*/
|
|
2435
|
+
function makeCSSVar(name, { prefix, wrapVar = false } = {}) {
|
|
2436
|
+
if (typeof name !== "string") throw new Error(`makeCSSVar() Expected string, received ${name}`);
|
|
2437
|
+
let property = name.split(CSS_VAR_RE).filter(Boolean).join("-");
|
|
2438
|
+
if (prefix && !property.startsWith(`${prefix}-`)) property = `${prefix}-${property}`;
|
|
2439
|
+
const finalProperty = `--${property}`.toLocaleLowerCase();
|
|
2440
|
+
return wrapVar ? `var(${finalProperty})` : finalProperty;
|
|
2441
|
+
}
|
|
2442
|
+
/** Convert boolean value to CSS string */
|
|
2443
|
+
function transformBoolean(token, { tokensSet, transformAlias = defaultAliasTransform }) {
|
|
2444
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2445
|
+
return token.$value === true ? "1" : "0";
|
|
2446
|
+
}
|
|
2447
|
+
/** Convert color value to CSS string */
|
|
2448
|
+
function transformColor(token, options) {
|
|
2449
|
+
const { transformAlias = defaultAliasTransform, tokensSet } = options;
|
|
2450
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2451
|
+
const { colorSpace, components, alpha = 1 } = typeof token.$value === "string" ? parseColor(token.$value) : token.$value;
|
|
2452
|
+
const color = tokenToCulori({
|
|
2453
|
+
colorSpace,
|
|
2454
|
+
components,
|
|
2455
|
+
alpha
|
|
2456
|
+
});
|
|
2457
|
+
if (!color) throw new Error(`Can’t convert color ${JSON.stringify(token.$value)} to Culori color`);
|
|
2458
|
+
let formatColor = formatCss;
|
|
2459
|
+
if (options.color?.legacyHex) formatColor = color.alpha !== 1 ? formatHex8 : formatHex;
|
|
2460
|
+
return displayable(color) ? formatColor(color) : downsample({
|
|
2461
|
+
colorSpace,
|
|
2462
|
+
components,
|
|
2463
|
+
alpha
|
|
2464
|
+
}, color);
|
|
2465
|
+
}
|
|
2466
|
+
const converters = {
|
|
2467
|
+
a98: useMode(definition_default),
|
|
2468
|
+
hsl: useMode(definition_default$1),
|
|
2469
|
+
hsv: useMode(definition_default$2),
|
|
2470
|
+
hwb: useMode(definition_default$3),
|
|
2471
|
+
lab: useMode(definition_default$4),
|
|
2472
|
+
lch: useMode(definition_default$5),
|
|
2473
|
+
lrgb: useMode(definition_default$6),
|
|
2474
|
+
oklab: useMode(definition_default$7),
|
|
2475
|
+
oklch: useMode(definition_default$8),
|
|
2476
|
+
p3: useMode(definition_default$9),
|
|
2477
|
+
prophoto: useMode(definition_default$10),
|
|
2478
|
+
rec2020: useMode(definition_default$11),
|
|
2479
|
+
rgb: useMode(definition_default$12),
|
|
2480
|
+
xyz50: useMode(definition_default$13),
|
|
2481
|
+
xyz65: useMode(definition_default$14)
|
|
2482
|
+
};
|
|
1
2483
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
2484
|
+
* Downsample color to sRGB/Display P3/Rec2020 colorspaces.
|
|
2485
|
+
* Note: because Culori tends to convert to RGB color spaces to ensure the operation,
|
|
2486
|
+
* we have to do an additional step of converting back. So we’re not really converting;
|
|
2487
|
+
* we’re just preserving the original colorspace.
|
|
2488
|
+
*/
|
|
2489
|
+
function downsample($value, culoriColor) {
|
|
2490
|
+
const conversionSpace = CSS_TO_CULORI[$value.colorSpace] || "oklab";
|
|
2491
|
+
const converter$1 = converters[conversionSpace];
|
|
2492
|
+
return {
|
|
2493
|
+
".": formatCss(culoriColor),
|
|
2494
|
+
srgb: formatCss(converter$1(toGamut("rgb", conversionSpace)(culoriColor))),
|
|
2495
|
+
p3: formatCss(converter$1(toGamut("p3", conversionSpace)(culoriColor))),
|
|
2496
|
+
rec2020: formatCss(converter$1(toGamut("rec2020", conversionSpace)(culoriColor)))
|
|
2497
|
+
};
|
|
2498
|
+
}
|
|
2499
|
+
/** Convert dimension value to CSS */
|
|
2500
|
+
function transformDimension(token, options) {
|
|
2501
|
+
const { tokensSet, transformAlias = defaultAliasTransform } = options;
|
|
2502
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2503
|
+
return token.$value.value === 0 ? "0" : `${token.$value.value}${token.$value.unit}`;
|
|
2504
|
+
}
|
|
2505
|
+
/** Convert strokeStyle value to CSS */
|
|
2506
|
+
function transformStrokeStyle(token, options) {
|
|
2507
|
+
const { tokensSet, transformAlias = defaultAliasTransform } = options;
|
|
2508
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2509
|
+
return typeof token.$value === "string" ? token.$value : "dashed";
|
|
2510
|
+
}
|
|
2511
|
+
/** Convert border value to multiple CSS values */
|
|
2512
|
+
function transformBorder(token, options) {
|
|
2513
|
+
const { tokensSet, transformAlias = defaultAliasTransform } = options;
|
|
2514
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2515
|
+
const width = token.partialAliasOf?.width ? transformAlias(tokensSet[token.partialAliasOf.width]) : transformDimension({ $value: token.$value.width }, options);
|
|
2516
|
+
const color = token.partialAliasOf?.color ? transformAlias(tokensSet[token.partialAliasOf.color]) : transformColor({ $value: token.$value.color }, options);
|
|
2517
|
+
const style = token.partialAliasOf?.style ? transformAlias(tokensSet[token.partialAliasOf.style]) : transformStrokeStyle({ $value: token.$value.style }, options);
|
|
2518
|
+
const formatBorder = (colorKey) => [
|
|
2519
|
+
width,
|
|
2520
|
+
style,
|
|
2521
|
+
typeof color === "string" ? color : color[colorKey]
|
|
2522
|
+
].join(" ");
|
|
2523
|
+
return typeof color === "string" || displayable(color.p3) ? formatBorder(".") : {
|
|
2524
|
+
".": formatBorder("."),
|
|
2525
|
+
srgb: formatBorder("srgb"),
|
|
2526
|
+
p3: formatBorder("p3"),
|
|
2527
|
+
rec2020: formatBorder("rec2020")
|
|
2528
|
+
};
|
|
2529
|
+
}
|
|
2530
|
+
/** Convert cubicBezier value to CSS */
|
|
2531
|
+
function transformCubicBezier(token, options) {
|
|
2532
|
+
const { tokensSet, transformAlias = defaultAliasTransform } = options;
|
|
2533
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2534
|
+
return `cubic-bezier(${token.$value.map((v, i) => token.partialAliasOf?.[i] ? transformAlias(tokensSet[token.partialAliasOf[i]]) : v).join(", ")})`;
|
|
2535
|
+
}
|
|
2536
|
+
/** Convert duration value to CSS */
|
|
2537
|
+
function transformDuration(token, options) {
|
|
2538
|
+
const { tokensSet, transformAlias = defaultAliasTransform } = options;
|
|
2539
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2540
|
+
return `${token.$value.value}${token.$value.unit}`;
|
|
2541
|
+
}
|
|
2542
|
+
const FONT_NAME_KEYWORD = /^[a-z-]+$/;
|
|
2543
|
+
function transformFontFamily(token, options) {
|
|
2544
|
+
const { tokensSet, transformAlias = defaultAliasTransform } = options;
|
|
2545
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2546
|
+
return token.$value.map((fontName) => FONT_NAME_KEYWORD.test(fontName) ? fontName : `"${fontName}"`).join(", ");
|
|
2547
|
+
}
|
|
2548
|
+
/** Convert fontWeight value to CSS */
|
|
2549
|
+
function transformFontWeight(token, options) {
|
|
2550
|
+
const { tokensSet, transformAlias = defaultAliasTransform } = options;
|
|
2551
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2552
|
+
return String(token.$value);
|
|
2553
|
+
}
|
|
2554
|
+
/** Convert gradient value to CSS */
|
|
2555
|
+
function transformGradient(token, options) {
|
|
2556
|
+
const { tokensSet, transformAlias = defaultAliasTransform } = options;
|
|
2557
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2558
|
+
let isHDR = false;
|
|
2559
|
+
const colors = [];
|
|
2560
|
+
const positions = [];
|
|
2561
|
+
for (let i = 0; i < token.$value.length; i++) {
|
|
2562
|
+
const { color, position } = token.$value[i];
|
|
2563
|
+
const colorValue = token.partialAliasOf?.[i]?.color ? transformAlias(tokensSet[token.partialAliasOf[i].color]) : transformColor({ $value: color }, options);
|
|
2564
|
+
if (typeof colorValue !== "string") isHDR = true;
|
|
2565
|
+
colors.push(colorValue);
|
|
2566
|
+
positions.push(token.partialAliasOf?.[i]?.position ? transformAlias(tokensSet[token.partialAliasOf[i].position]) : `${100 * position}%`);
|
|
2567
|
+
}
|
|
2568
|
+
function formatStop(i, colorKey = ".") {
|
|
2569
|
+
return `${typeof colors[i] === "string" ? colors[i] : colors[i][colorKey]} ${positions[i]}`;
|
|
2570
|
+
}
|
|
2571
|
+
return !isHDR ? token.$value.map((_, i) => formatStop(i, positions[i])).join(", ") : {
|
|
2572
|
+
".": token.$value.map((_, i) => formatStop(i, ".")).join(", "),
|
|
2573
|
+
srgb: token.$value.map((_, i) => formatStop(i, "srgb")).join(", "),
|
|
2574
|
+
p3: token.$value.map((_, i) => formatStop(i, "p3")).join(", "),
|
|
2575
|
+
rec2020: token.$value.map((_, i) => formatStop(i, "rec2020")).join(", ")
|
|
2576
|
+
};
|
|
2577
|
+
}
|
|
2578
|
+
/** Convert link value to CSS */
|
|
2579
|
+
function transformLink(token, options) {
|
|
2580
|
+
const { tokensSet, transformAlias = defaultAliasTransform } = options;
|
|
2581
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2582
|
+
return `url("${token.$value}")`;
|
|
2583
|
+
}
|
|
2584
|
+
/** Convert number value to CSS */
|
|
2585
|
+
function transformNumber(token, options) {
|
|
2586
|
+
const { tokensSet, transformAlias = defaultAliasTransform } = options;
|
|
2587
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2588
|
+
return String(token.$value);
|
|
2589
|
+
}
|
|
2590
|
+
/** Convert shadow subvalue to CSS */
|
|
2591
|
+
function transformShadowLayer(value, options) {
|
|
2592
|
+
const { tokensSet, colorValue, partialAliasOf, transformAlias = defaultAliasTransform } = options;
|
|
2593
|
+
const offsetX = partialAliasOf?.offsetX ? transformAlias(tokensSet[partialAliasOf.offsetX]) : transformDimension({ $value: value.offsetX }, options);
|
|
2594
|
+
const offsetY = partialAliasOf?.offsetY ? transformAlias(tokensSet[partialAliasOf.offsetY]) : transformDimension({ $value: value.offsetY }, options);
|
|
2595
|
+
const blur = partialAliasOf?.blur ? transformAlias(tokensSet[partialAliasOf.blur]) : transformDimension({ $value: value.blur }, options);
|
|
2596
|
+
const spread = partialAliasOf?.spread ? transformAlias(tokensSet[partialAliasOf.spread]) : transformDimension({ $value: value.spread }, options);
|
|
2597
|
+
const inset = value?.inset === true ? "inset" : void 0;
|
|
2598
|
+
return [
|
|
2599
|
+
inset,
|
|
2600
|
+
offsetX,
|
|
2601
|
+
offsetY,
|
|
2602
|
+
blur,
|
|
2603
|
+
spread,
|
|
2604
|
+
colorValue
|
|
2605
|
+
].filter(Boolean).join(" ");
|
|
2606
|
+
}
|
|
2607
|
+
/** Convert shadow value to CSS */
|
|
2608
|
+
function transformShadow(token, options) {
|
|
2609
|
+
const { tokensSet, transformAlias = defaultAliasTransform } = options;
|
|
2610
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2611
|
+
const colors = token.$value.map((v, i) => token.partialAliasOf?.[i]?.color ? transformAlias(tokensSet[token.partialAliasOf[i].color]) : transformColor({ $value: v.color }, options));
|
|
2612
|
+
const isHDR = colors.some((c$1) => typeof c$1 === "object");
|
|
2613
|
+
const formatShadow = (colorKey) => token.$value.map((v, i) => transformShadowLayer(v, {
|
|
2614
|
+
tokensSet,
|
|
2615
|
+
colorValue: typeof colors[i] === "string" ? colors[i] : colors[i][colorKey],
|
|
2616
|
+
partialAliasOf: token.partialAliasOf?.[i],
|
|
2617
|
+
transformAlias
|
|
2618
|
+
})).join(", ");
|
|
2619
|
+
return !isHDR ? formatShadow(".") : {
|
|
2620
|
+
".": formatShadow("."),
|
|
2621
|
+
srgb: formatShadow("srgb"),
|
|
2622
|
+
p3: formatShadow("p3"),
|
|
2623
|
+
rec2020: formatShadow("rec2020")
|
|
2624
|
+
};
|
|
2625
|
+
}
|
|
2626
|
+
/** Convert string value to CSS */
|
|
2627
|
+
function transformString(token, options) {
|
|
2628
|
+
const { tokensSet, transformAlias = defaultAliasTransform } = options;
|
|
2629
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2630
|
+
return String(token.$value);
|
|
2631
|
+
}
|
|
2632
|
+
/** Convert transition value to shorthand */
|
|
2633
|
+
function transformTransition(token, options) {
|
|
2634
|
+
const { tokensSet, transformAlias = defaultAliasTransform } = options;
|
|
2635
|
+
if (token.aliasChain?.[0]) return transformAlias(tokensSet[token.aliasChain[0]]);
|
|
2636
|
+
const duration = token.partialAliasOf?.duration ? transformAlias(tokensSet[token.partialAliasOf.duration]) : transformDuration({ $value: token.$value.duration }, options);
|
|
2637
|
+
const delay = token.partialAliasOf?.delay ? transformAlias(tokensSet[token.partialAliasOf.delay]) : transformDuration({ $value: token.$value.delay }, options);
|
|
2638
|
+
const timingFunction = token.partialAliasOf?.timingFunction ? transformAlias(tokensSet[token.partialAliasOf.timingFunction]) : transformCubicBezier({ $value: token.$value.timingFunction }, options);
|
|
2639
|
+
return `${duration} ${delay} ${timingFunction}`;
|
|
2640
|
+
}
|
|
2641
|
+
/** Convert typography value to multiple CSS values */
|
|
2642
|
+
function transformTypography(token, options) {
|
|
2643
|
+
const { tokensSet, transformAlias = defaultAliasTransform } = options;
|
|
2644
|
+
const output = {};
|
|
2645
|
+
for (const [property, subvalue] of Object.entries(token.$value)) {
|
|
2646
|
+
let transformedValue;
|
|
2647
|
+
const aliasedID = token.aliasChain?.[0] ?? token.partialAliasOf?.[property];
|
|
2648
|
+
if (aliasedID) {
|
|
2649
|
+
const resolvedToken = tokensSet[aliasedID];
|
|
2650
|
+
transformedValue = transformAlias(resolvedToken.$type === "typography" ? { id: `${aliasedID}-${property}` } : resolvedToken);
|
|
2651
|
+
} else switch (property) {
|
|
2652
|
+
case "fontFamily": {
|
|
2653
|
+
transformedValue = transformFontFamily({ $value: subvalue }, options);
|
|
2654
|
+
break;
|
|
2655
|
+
}
|
|
2656
|
+
case "fontSize":
|
|
2657
|
+
case "letterSpacing": {
|
|
2658
|
+
transformedValue = transformDimension({ $value: subvalue }, options);
|
|
2659
|
+
break;
|
|
2660
|
+
}
|
|
2661
|
+
case "fontWeight": {
|
|
2662
|
+
transformedValue = transformFontWeight({ $value: subvalue }, options);
|
|
2663
|
+
break;
|
|
2664
|
+
}
|
|
2665
|
+
case "lineHeight": {
|
|
2666
|
+
if (typeof subvalue === "number") transformedValue = transformNumber({ $value: subvalue }, options);
|
|
2667
|
+
else transformedValue = transformDimension({ $value: subvalue }, options);
|
|
2668
|
+
break;
|
|
2669
|
+
}
|
|
2670
|
+
default: {
|
|
2671
|
+
transformedValue = transformString({ $value: subvalue }, options);
|
|
2672
|
+
break;
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
output[kebabCase(property)] = transformedValue;
|
|
2676
|
+
}
|
|
2677
|
+
return output;
|
|
2678
|
+
}
|
|
2679
|
+
/** Main CSS Transform */
|
|
2680
|
+
function transformCSSValue(token, { mode,...options }) {
|
|
2681
|
+
const selectedMode = token.mode[mode];
|
|
2682
|
+
if (!selectedMode) return;
|
|
2683
|
+
const tokenWithModeValue = {
|
|
2684
|
+
id: token.id,
|
|
2685
|
+
$type: token.$type,
|
|
2686
|
+
...selectedMode
|
|
2687
|
+
};
|
|
2688
|
+
switch (tokenWithModeValue.$type) {
|
|
2689
|
+
case "boolean": return transformBoolean(tokenWithModeValue, options);
|
|
2690
|
+
case "border": return transformBorder(tokenWithModeValue, options);
|
|
2691
|
+
case "color": return transformColor(tokenWithModeValue, options);
|
|
2692
|
+
case "cubicBezier": return transformCubicBezier(tokenWithModeValue, options);
|
|
2693
|
+
case "dimension": return transformDimension(tokenWithModeValue, options);
|
|
2694
|
+
case "duration": return transformDuration(tokenWithModeValue, options);
|
|
2695
|
+
case "fontFamily": return transformFontFamily(tokenWithModeValue, options);
|
|
2696
|
+
case "fontWeight": return transformFontWeight(tokenWithModeValue, options);
|
|
2697
|
+
case "gradient": return transformGradient(tokenWithModeValue, options);
|
|
2698
|
+
case "link": return transformLink(tokenWithModeValue, options);
|
|
2699
|
+
case "number": return transformNumber(tokenWithModeValue, options);
|
|
2700
|
+
case "shadow": return transformShadow(tokenWithModeValue, options);
|
|
2701
|
+
case "string": return transformString(tokenWithModeValue, options);
|
|
2702
|
+
case "strokeStyle": return transformStrokeStyle(tokenWithModeValue, options);
|
|
2703
|
+
case "transition": return transformTransition(tokenWithModeValue, options);
|
|
2704
|
+
case "typography": return transformTypography(tokenWithModeValue, options);
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
//#endregion
|
|
2709
|
+
//#region src/lib.ts
|
|
2710
|
+
const FORMAT_ID = "css";
|
|
2711
|
+
const FILE_PREFIX = `/* -------------------------------------------
|
|
2712
|
+
* Autogenerated by ⛋ Terrazzo. DO NOT EDIT!
|
|
2713
|
+
* ------------------------------------------- */`;
|
|
2714
|
+
/** Convert CSSRules into a formatted, indented CSS string */
|
|
2715
|
+
function printRules(rules) {
|
|
2716
|
+
const output = [];
|
|
2717
|
+
for (const rule of rules) {
|
|
2718
|
+
if (!rule.selectors.length || !Object.keys(rule.declarations).length) continue;
|
|
2719
|
+
const mqSelectors = [];
|
|
2720
|
+
const joinableSelectors = [];
|
|
2721
|
+
for (const s of rule.selectors) (s.startsWith("@") ? mqSelectors : joinableSelectors).push(s);
|
|
2722
|
+
for (const s of mqSelectors) output.push(_printRule({
|
|
2723
|
+
...rule,
|
|
2724
|
+
selectors: [s]
|
|
2725
|
+
}));
|
|
2726
|
+
if (joinableSelectors.length) output.push(_printRule({
|
|
2727
|
+
...rule,
|
|
2728
|
+
selectors: joinableSelectors
|
|
2729
|
+
}));
|
|
2730
|
+
}
|
|
2731
|
+
return output.join("\n\n");
|
|
2732
|
+
}
|
|
2733
|
+
function _printRule(rule) {
|
|
2734
|
+
const output = [];
|
|
2735
|
+
const isMediaQuery = rule.selectors.some((s) => s.startsWith("@"));
|
|
2736
|
+
let indent = "";
|
|
2737
|
+
if (rule.nestedQuery && isMediaQuery) {
|
|
2738
|
+
output.push(`${indent}${rule.selectors.join(`,\n${indent}`)} {`);
|
|
2739
|
+
indent += " ";
|
|
2740
|
+
output.push(`${indent}${rule.nestedQuery} {`);
|
|
2741
|
+
} else if (rule.nestedQuery && !isMediaQuery) {
|
|
2742
|
+
output.push(`${indent}${rule.nestedQuery} {`);
|
|
2743
|
+
indent += " ";
|
|
2744
|
+
output.push(`${indent}${rule.selectors.join(`,\n${indent}`)} {`);
|
|
2745
|
+
} else output.push(`${indent}${rule.selectors.join(`,\n${indent}`)} {`);
|
|
2746
|
+
indent += " ";
|
|
2747
|
+
if (isMediaQuery) {
|
|
2748
|
+
output.push(`${indent}:root {`);
|
|
2749
|
+
indent += " ";
|
|
2750
|
+
}
|
|
2751
|
+
const declarations = Object.entries(rule.declarations);
|
|
2752
|
+
declarations.sort((a, b) => a[0].localeCompare(b[0], "en-us", { numeric: true }));
|
|
2753
|
+
for (const [k$2, v] of declarations) output.push(`${indent}${k$2}: ${v};`);
|
|
2754
|
+
while (indent !== "") {
|
|
2755
|
+
indent = indent.substring(0, indent.length - 2);
|
|
2756
|
+
output.push(`${indent}}`);
|
|
2757
|
+
}
|
|
2758
|
+
return output.join("\n");
|
|
2759
|
+
}
|
|
2760
|
+
|
|
2761
|
+
//#endregion
|
|
2762
|
+
//#region src/build/utility-css.ts
|
|
2763
|
+
const GROUP_REGEX = {
|
|
2764
|
+
bg: /(^bg-|-bg-)/,
|
|
2765
|
+
border: /(^border-|-border-)/,
|
|
2766
|
+
font: /(^font-|-font-)/,
|
|
2767
|
+
gap: /(^gap-|-gap-)/,
|
|
2768
|
+
m: /(^margin-|-margin-|)/,
|
|
2769
|
+
p: /(^padding-|-padding-|)/,
|
|
2770
|
+
shadow: /(^shadow-|-shadow-)/,
|
|
2771
|
+
text: /(^text-|-text-)/
|
|
2772
|
+
};
|
|
2773
|
+
/** Make CSS class name from transformed token */
|
|
2774
|
+
function makeSelector(token, prefix, subgroup) {
|
|
2775
|
+
return `.${prefix}${subgroup || ""}-${kebabCase(token.token.id).replace(GROUP_REGEX[prefix], "")}`;
|
|
2776
|
+
}
|
|
2777
|
+
function makeVarValue(token) {
|
|
2778
|
+
return makeCSSVar(token.localID ?? token.token.id, { wrapVar: true });
|
|
2779
|
+
}
|
|
2780
|
+
function generateUtilityCSS(groups, tokens) {
|
|
2781
|
+
const output = [];
|
|
2782
|
+
const groupEntries = Object.entries(groups);
|
|
2783
|
+
groupEntries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
2784
|
+
for (const [group, selectors] of groupEntries) {
|
|
2785
|
+
const matchingTokens = tokens.filter((token) => isTokenMatch(token.token.id, selectors));
|
|
2786
|
+
if (!matchingTokens.length) {
|
|
2787
|
+
console.warn(`[@terrazzo/plugin-css] utility group "${group}" matched 0 tokens: ${JSON.stringify(selectors)}`);
|
|
2788
|
+
break;
|
|
2789
|
+
}
|
|
2790
|
+
switch (group) {
|
|
2791
|
+
case "bg": {
|
|
2792
|
+
for (const token of matchingTokens) {
|
|
2793
|
+
const selector = makeSelector(token, "bg");
|
|
2794
|
+
switch (token.token.$type) {
|
|
2795
|
+
case "color": {
|
|
2796
|
+
output.push({
|
|
2797
|
+
selectors: [selector],
|
|
2798
|
+
declarations: { "background-color": makeVarValue(token) }
|
|
2799
|
+
});
|
|
2800
|
+
break;
|
|
2801
|
+
}
|
|
2802
|
+
case "gradient": output.push({
|
|
2803
|
+
selectors: [selector],
|
|
2804
|
+
declarations: { "background-image": `linear-gradient(${makeCSSVar(token.localID ?? token.token.id, { wrapVar: true })})` }
|
|
2805
|
+
});
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
break;
|
|
2809
|
+
}
|
|
2810
|
+
case "border": {
|
|
2811
|
+
for (const token of matchingTokens) {
|
|
2812
|
+
const property = {
|
|
2813
|
+
border: "border",
|
|
2814
|
+
color: "border-color",
|
|
2815
|
+
dimension: "border-width",
|
|
2816
|
+
strokeStyle: "border-style"
|
|
2817
|
+
}[token.token.$type];
|
|
2818
|
+
if (property) output.push({
|
|
2819
|
+
selectors: [makeSelector(token, "border")],
|
|
2820
|
+
declarations: { [property]: makeVarValue(token) }
|
|
2821
|
+
});
|
|
2822
|
+
}
|
|
2823
|
+
for (const token of matchingTokens) for (const side of [
|
|
2824
|
+
"top",
|
|
2825
|
+
"right",
|
|
2826
|
+
"bottom",
|
|
2827
|
+
"left"
|
|
2828
|
+
]) {
|
|
2829
|
+
const property = {
|
|
2830
|
+
border: `border-${side}`,
|
|
2831
|
+
color: `border-${side}-color`,
|
|
2832
|
+
dimension: `border-${side}-width`,
|
|
2833
|
+
strokeStyle: `border-${side}-style`
|
|
2834
|
+
}[token.token.$type];
|
|
2835
|
+
if (property) output.push({
|
|
2836
|
+
selectors: [makeSelector(token, "border", `-${side}`)],
|
|
2837
|
+
declarations: { [property]: makeVarValue(token) }
|
|
2838
|
+
});
|
|
2839
|
+
}
|
|
2840
|
+
break;
|
|
2841
|
+
}
|
|
2842
|
+
case "font": {
|
|
2843
|
+
for (const token of matchingTokens) {
|
|
2844
|
+
const selector = makeSelector(token, "font");
|
|
2845
|
+
if (token.token.$type === "typography" && token.type === "MULTI_VALUE") {
|
|
2846
|
+
const declarations = {};
|
|
2847
|
+
for (const k$2 of Object.keys(token.value)) declarations[k$2] = makeCSSVar(`${token.localID ?? token.token.id}-${k$2}`, { wrapVar: true });
|
|
2848
|
+
output.push({
|
|
2849
|
+
selectors: [selector],
|
|
2850
|
+
declarations
|
|
2851
|
+
});
|
|
2852
|
+
} else {
|
|
2853
|
+
const property = {
|
|
2854
|
+
dimension: "font-size",
|
|
2855
|
+
fontFamily: "font-family",
|
|
2856
|
+
fontWeight: "font-weight"
|
|
2857
|
+
}[token.token.$type];
|
|
2858
|
+
if (property) output.push({
|
|
2859
|
+
selectors: [selector],
|
|
2860
|
+
declarations: { [property]: makeVarValue(token) }
|
|
2861
|
+
});
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2864
|
+
break;
|
|
2865
|
+
}
|
|
2866
|
+
case "layout": {
|
|
2867
|
+
const filteredTokens = matchingTokens.filter((t) => t.token.$type === "dimension");
|
|
2868
|
+
for (const token of filteredTokens) output.push({
|
|
2869
|
+
selectors: [makeSelector(token, "gap")],
|
|
2870
|
+
declarations: { gap: makeVarValue(token) }
|
|
2871
|
+
});
|
|
2872
|
+
for (const token of filteredTokens) output.push({
|
|
2873
|
+
selectors: [makeSelector(token, "gap", "-col")],
|
|
2874
|
+
declarations: { "column-gap": makeVarValue(token) }
|
|
2875
|
+
});
|
|
2876
|
+
for (const token of filteredTokens) output.push({
|
|
2877
|
+
selectors: [makeSelector(token, "gap", "-row")],
|
|
2878
|
+
declarations: { "row-gap": makeVarValue(token) }
|
|
2879
|
+
});
|
|
2880
|
+
for (const prefix of ["m", "p"]) {
|
|
2881
|
+
const property = prefix === "m" ? "margin" : "padding";
|
|
2882
|
+
for (const token of filteredTokens) output.push({
|
|
2883
|
+
selectors: [makeSelector(token, prefix, "a")],
|
|
2884
|
+
declarations: { [property]: makeVarValue(token) }
|
|
2885
|
+
});
|
|
2886
|
+
for (const token of filteredTokens) {
|
|
2887
|
+
const value = makeVarValue(token);
|
|
2888
|
+
output.push({
|
|
2889
|
+
selectors: [makeSelector(token, prefix, "x")],
|
|
2890
|
+
declarations: {
|
|
2891
|
+
[`${property}-left`]: value,
|
|
2892
|
+
[`${property}-right`]: value
|
|
2893
|
+
}
|
|
2894
|
+
}, {
|
|
2895
|
+
selectors: [makeSelector(token, prefix, "y")],
|
|
2896
|
+
declarations: {
|
|
2897
|
+
[`${property}-bottom`]: value,
|
|
2898
|
+
[`${property}-top`]: value
|
|
2899
|
+
}
|
|
2900
|
+
});
|
|
2901
|
+
}
|
|
2902
|
+
for (const side of [
|
|
2903
|
+
"top",
|
|
2904
|
+
"right",
|
|
2905
|
+
"bottom",
|
|
2906
|
+
"left"
|
|
2907
|
+
]) for (const token of filteredTokens) output.push({
|
|
2908
|
+
selectors: [makeSelector(token, prefix, side[0])],
|
|
2909
|
+
declarations: { [`${property}-${side}`]: makeVarValue(token) }
|
|
2910
|
+
});
|
|
2911
|
+
for (const token of filteredTokens) {
|
|
2912
|
+
const value = makeVarValue(token);
|
|
2913
|
+
output.push({
|
|
2914
|
+
selectors: [makeSelector(token, prefix, "s")],
|
|
2915
|
+
declarations: { [`${property}-inline-start`]: value }
|
|
2916
|
+
}, {
|
|
2917
|
+
selectors: [makeSelector(token, prefix, "e")],
|
|
2918
|
+
declarations: { [`${property}-inline-end`]: value }
|
|
2919
|
+
});
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
break;
|
|
2923
|
+
}
|
|
2924
|
+
case "shadow": {
|
|
2925
|
+
for (const token of matchingTokens) if (token.token.$type === "shadow") output.push({
|
|
2926
|
+
selectors: [makeSelector(token, "shadow")],
|
|
2927
|
+
declarations: { "box-shadow": makeVarValue(token) }
|
|
2928
|
+
});
|
|
2929
|
+
break;
|
|
2930
|
+
}
|
|
2931
|
+
case "text": {
|
|
2932
|
+
for (const token of matchingTokens) {
|
|
2933
|
+
const selector = makeSelector(token, "text");
|
|
2934
|
+
const value = makeVarValue(token);
|
|
2935
|
+
switch (token.token.$type) {
|
|
2936
|
+
case "color": {
|
|
2937
|
+
output.push({
|
|
2938
|
+
selectors: [selector],
|
|
2939
|
+
declarations: { color: value }
|
|
2940
|
+
});
|
|
2941
|
+
break;
|
|
2942
|
+
}
|
|
2943
|
+
case "gradient": {
|
|
2944
|
+
output.push({
|
|
2945
|
+
selectors: [selector],
|
|
2946
|
+
declarations: {
|
|
2947
|
+
background: `-webkit-linear-gradient(${value})`,
|
|
2948
|
+
"-webkit-background-clip": "text",
|
|
2949
|
+
"-webkit-text-fill-color": "transparent"
|
|
2950
|
+
}
|
|
2951
|
+
});
|
|
2952
|
+
break;
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2955
|
+
}
|
|
2956
|
+
break;
|
|
2957
|
+
}
|
|
2958
|
+
default: {
|
|
2959
|
+
console.warn(`[@terrazzo/plugin-css] unknown utility CSS group "${group}", ignoring`);
|
|
2960
|
+
break;
|
|
2961
|
+
}
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
return output;
|
|
2965
|
+
}
|
|
2966
|
+
|
|
2967
|
+
//#endregion
|
|
2968
|
+
//#region src/build/index.ts
|
|
2969
|
+
const P3_MQ = "@media (color-gamut: p3)";
|
|
2970
|
+
const REC2020_MQ = "@media (color-gamut: rec2020)";
|
|
2971
|
+
function buildFormat({ getTransforms, exclude, utility, modeSelectors, baseSelector }) {
|
|
2972
|
+
const rules = [];
|
|
2973
|
+
const rootTokens = getTransforms({
|
|
2974
|
+
format: FORMAT_ID,
|
|
2975
|
+
mode: "."
|
|
2976
|
+
});
|
|
2977
|
+
if (rootTokens.length) {
|
|
2978
|
+
const rootRule = {
|
|
2979
|
+
selectors: [baseSelector],
|
|
2980
|
+
declarations: {}
|
|
2981
|
+
};
|
|
2982
|
+
const p3Rule = {
|
|
2983
|
+
selectors: [baseSelector],
|
|
2984
|
+
nestedQuery: P3_MQ,
|
|
2985
|
+
declarations: {}
|
|
2986
|
+
};
|
|
2987
|
+
const rec2020Rule = {
|
|
2988
|
+
selectors: [baseSelector],
|
|
2989
|
+
nestedQuery: REC2020_MQ,
|
|
2990
|
+
declarations: {}
|
|
2991
|
+
};
|
|
2992
|
+
rules.push(rootRule, p3Rule, rec2020Rule);
|
|
2993
|
+
for (const token of rootTokens) {
|
|
2994
|
+
if (isTokenMatch(token.token.id, exclude ?? [])) continue;
|
|
2995
|
+
const localID = token.localID ?? token.token.id;
|
|
2996
|
+
const aliasTokens = token.token.aliasedBy?.length ? getTransforms({
|
|
2997
|
+
format: FORMAT_ID,
|
|
2998
|
+
id: token.token.aliasedBy
|
|
2999
|
+
}) : [];
|
|
3000
|
+
if (token.type === "SINGLE_VALUE") rootRule.declarations[localID] = token.value;
|
|
3001
|
+
else if (token.value.srgb && token.value.p3 && token.value.rec2020) {
|
|
3002
|
+
rootRule.declarations[localID] = token.value.srgb;
|
|
3003
|
+
if (token.value.p3 !== token.value.srgb) {
|
|
3004
|
+
p3Rule.declarations[localID] = token.value.p3;
|
|
3005
|
+
rec2020Rule.declarations[localID] = token.value.rec2020;
|
|
3006
|
+
for (const alias of aliasTokens) if (alias.localID && typeof alias.value === "string") {
|
|
3007
|
+
p3Rule.declarations[alias.localID] ??= alias.value;
|
|
3008
|
+
rec2020Rule.declarations[alias.localID] ??= alias.value;
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
} else if (token.type === "MULTI_VALUE") {
|
|
3012
|
+
const shorthand = generateShorthand({
|
|
3013
|
+
$type: token.token.$type,
|
|
3014
|
+
localID
|
|
3015
|
+
});
|
|
3016
|
+
if (shorthand) rootRule.declarations[token.localID ?? token.token.id] = shorthand;
|
|
3017
|
+
for (const [name, value] of Object.entries(token.value)) rootRule.declarations[name === "." ? localID : [localID, name].join("-")] = value;
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
for (const { selectors, tokens, mode } of modeSelectors ?? []) {
|
|
3022
|
+
if (!selectors.length) continue;
|
|
3023
|
+
const selectorTokens = getTransforms({
|
|
3024
|
+
format: FORMAT_ID,
|
|
3025
|
+
id: tokens,
|
|
3026
|
+
mode
|
|
3027
|
+
});
|
|
3028
|
+
if (!selectorTokens.length) continue;
|
|
3029
|
+
const selectorRule = {
|
|
3030
|
+
selectors,
|
|
3031
|
+
declarations: {}
|
|
3032
|
+
};
|
|
3033
|
+
const selectorP3Rule = {
|
|
3034
|
+
selectors,
|
|
3035
|
+
nestedQuery: P3_MQ,
|
|
3036
|
+
declarations: {}
|
|
3037
|
+
};
|
|
3038
|
+
const selectorRec2020Rule = {
|
|
3039
|
+
selectors,
|
|
3040
|
+
nestedQuery: REC2020_MQ,
|
|
3041
|
+
declarations: {}
|
|
3042
|
+
};
|
|
3043
|
+
const selectorAliasDeclarations = {};
|
|
3044
|
+
rules.push(selectorRule, selectorP3Rule, selectorRec2020Rule);
|
|
3045
|
+
for (const token of selectorTokens) {
|
|
3046
|
+
const localID = token.localID ?? token.token.id;
|
|
3047
|
+
const aliasTokens = token.token.aliasedBy?.length ? getTransforms({
|
|
3048
|
+
format: FORMAT_ID,
|
|
3049
|
+
id: token.token.aliasedBy
|
|
3050
|
+
}) : [];
|
|
3051
|
+
if (token.type === "SINGLE_VALUE") selectorRule.declarations[localID] = token.value;
|
|
3052
|
+
else if (token.value.srgb && token.value.p3 && token.value.rec2020) {
|
|
3053
|
+
selectorRule.declarations[localID] = token.value.srgb;
|
|
3054
|
+
if (token.value.p3 !== token.value.srgb) {
|
|
3055
|
+
selectorP3Rule.declarations[localID] = token.value.p3;
|
|
3056
|
+
selectorRec2020Rule.declarations[localID] = token.value.rec2020;
|
|
3057
|
+
for (const alias of aliasTokens) if (alias.localID && typeof alias.value === "string") {
|
|
3058
|
+
selectorP3Rule.declarations[alias.localID] ??= alias.value;
|
|
3059
|
+
selectorRec2020Rule.declarations[alias.localID] ??= alias.value;
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
} else {
|
|
3063
|
+
const shorthand = generateShorthand({
|
|
3064
|
+
$type: token.token.$type,
|
|
3065
|
+
localID
|
|
3066
|
+
});
|
|
3067
|
+
if (shorthand) selectorRule.declarations[localID] = shorthand;
|
|
3068
|
+
for (const [name, subvalue] of Object.entries(token.value)) selectorRule.declarations[`${localID}-${name}`] = subvalue;
|
|
3069
|
+
}
|
|
3070
|
+
for (const alias of aliasTokens) if (alias.localID && typeof alias.value === "string") selectorAliasDeclarations[alias.localID] = alias.value;
|
|
3071
|
+
}
|
|
3072
|
+
for (const [name, value] of Object.entries(selectorAliasDeclarations)) selectorRule.declarations[name] ??= value;
|
|
3073
|
+
}
|
|
3074
|
+
if (utility && Object.keys(utility).length) rules.push(...generateUtilityCSS(utility, getTransforms({
|
|
3075
|
+
format: FORMAT_ID,
|
|
3076
|
+
mode: "."
|
|
3077
|
+
})));
|
|
3078
|
+
return printRules(rules);
|
|
3079
|
+
}
|
|
3080
|
+
|
|
3081
|
+
//#endregion
|
|
3082
|
+
//#region src/index.ts
|
|
3083
|
+
function cssPlugin(options) {
|
|
3084
|
+
const { exclude, variableName, modeSelectors, transform: customTransform, utility, legacyHex, skipBuild } = options ?? {};
|
|
3085
|
+
const filename = options?.filename ?? options?.fileName ?? "index.css";
|
|
3086
|
+
const baseSelector = options?.baseSelector ?? ":root";
|
|
3087
|
+
function transformName(token) {
|
|
3088
|
+
const customName = variableName?.(token);
|
|
3089
|
+
if (customName !== void 0) {
|
|
3090
|
+
if (typeof customName !== "string") throw new Error(`variableName() must return a string; received ${customName}`);
|
|
3091
|
+
return customName;
|
|
3092
|
+
}
|
|
3093
|
+
return makeCSSVar(token.id);
|
|
3094
|
+
}
|
|
3095
|
+
const transformAlias = (token) => `var(${transformName(token)})`;
|
|
3096
|
+
return {
|
|
3097
|
+
name: "@terrazzo/plugin-css",
|
|
3098
|
+
async transform({ tokens, getTransforms, setTransform }) {
|
|
3099
|
+
const cssTokens = getTransforms({
|
|
3100
|
+
format: FORMAT_ID,
|
|
3101
|
+
id: "*",
|
|
3102
|
+
mode: "*"
|
|
3103
|
+
});
|
|
3104
|
+
if (cssTokens.length) return;
|
|
3105
|
+
for (const [id, token] of Object.entries(tokens)) {
|
|
3106
|
+
const localID = transformName(token);
|
|
3107
|
+
for (const mode of Object.keys(token.mode)) {
|
|
3108
|
+
if (customTransform) {
|
|
3109
|
+
const value = customTransform(token, mode);
|
|
3110
|
+
if (value !== void 0 && value !== null) {
|
|
3111
|
+
validateCustomTransform(value, { $type: token.$type });
|
|
3112
|
+
setTransform(id, {
|
|
3113
|
+
format: FORMAT_ID,
|
|
3114
|
+
localID,
|
|
3115
|
+
value,
|
|
3116
|
+
mode
|
|
3117
|
+
});
|
|
3118
|
+
continue;
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
const transformedValue = transformCSSValue(token, {
|
|
3122
|
+
mode,
|
|
3123
|
+
tokensSet: tokens,
|
|
3124
|
+
transformAlias,
|
|
3125
|
+
color: { legacyHex }
|
|
3126
|
+
});
|
|
3127
|
+
if (transformedValue !== void 0) setTransform(id, {
|
|
3128
|
+
format: FORMAT_ID,
|
|
3129
|
+
localID,
|
|
3130
|
+
value: transformedValue,
|
|
3131
|
+
mode
|
|
3132
|
+
});
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
},
|
|
3136
|
+
async build({ getTransforms, outputFile }) {
|
|
3137
|
+
if (skipBuild === true) return;
|
|
3138
|
+
const output = [FILE_PREFIX, ""];
|
|
3139
|
+
output.push(buildFormat({
|
|
3140
|
+
exclude,
|
|
3141
|
+
getTransforms,
|
|
3142
|
+
modeSelectors,
|
|
3143
|
+
utility,
|
|
3144
|
+
baseSelector
|
|
3145
|
+
}), "\n");
|
|
3146
|
+
outputFile(filename, output.join("\n"));
|
|
3147
|
+
}
|
|
3148
|
+
};
|
|
86
3149
|
}
|
|
3150
|
+
|
|
3151
|
+
//#endregion
|
|
3152
|
+
export { FILE_PREFIX, FORMAT_ID, cssPlugin as default, printRules };
|
|
87
3153
|
//# sourceMappingURL=index.js.map
|