@tbela99/css-parser 1.8.2 → 2.0.0
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 +62 -0
- package/README.md +129 -31
- package/dist/index-umd-web.js +27383 -24083
- package/dist/index.d.ts +2737 -2200
- package/dist/package.json.js +2 -2
- package/dist/src/data/properties.json.js +1 -1
- package/dist/src/data/validation.json.js +1 -1
- package/dist/src/lib/ast/arena-node.js +548 -0
- package/dist/src/lib/ast/arena.js +3198 -0
- package/dist/src/lib/ast/features/calc.js +85 -76
- package/dist/src/lib/ast/features/if.js +155 -115
- package/dist/src/lib/ast/features/index.js +1 -1
- package/dist/src/lib/ast/features/inlinecssvariables.js +77 -84
- package/dist/src/lib/ast/features/prefix.js +184 -183
- package/dist/src/lib/ast/features/shorthand.js +40 -46
- package/dist/src/lib/ast/features/transform.js +24 -24
- package/dist/src/lib/ast/features/type.js +1 -1
- package/dist/src/lib/ast/fingerprint.js +333 -0
- package/dist/src/lib/ast/math/expression.js +458 -543
- package/dist/src/lib/ast/math/math.js +19 -41
- package/dist/src/lib/ast/minify.js +590 -647
- package/dist/src/lib/ast/transform/compute.js +82 -85
- package/dist/src/lib/ast/transform/matrix.js +21 -38
- package/dist/src/lib/ast/transform/minify.js +82 -193
- package/dist/src/lib/ast/transform/perspective.js +2 -3
- package/dist/src/lib/ast/transform/rotate.js +1 -1
- package/dist/src/lib/ast/transform/scale.js +1 -1
- package/dist/src/lib/ast/transform/skew.js +1 -1
- package/dist/src/lib/ast/transform/translate.js +1 -1
- package/dist/src/lib/ast/transform/utils.js +2 -2
- package/dist/src/lib/ast/types.js +263 -258
- package/dist/src/lib/ast/walk.js +246 -610
- package/dist/src/lib/fs/resolve.js +1 -1
- package/dist/src/lib/parser/declaration/list.js +223 -139
- package/dist/src/lib/parser/declaration/map.js +251 -238
- package/dist/src/lib/parser/declaration/set.js +74 -66
- package/dist/src/lib/parser/linesmap.js +1 -1
- package/dist/src/lib/parser/parse.js +1379 -1658
- package/dist/src/lib/parser/source.js +7 -4
- package/dist/src/lib/parser/tokenize.js +406 -199
- package/dist/src/lib/parser/utils/angle.js +11 -13
- package/dist/src/lib/parser/utils/at-rule-container.js +183 -168
- package/dist/src/lib/parser/utils/at-rule-font-feature-values.js +5 -5
- package/dist/src/lib/parser/utils/at-rule-generic.js +31 -24
- package/dist/src/lib/parser/utils/at-rule-import.js +44 -44
- package/dist/src/lib/parser/utils/at-rule-media.js +216 -205
- package/dist/src/lib/parser/utils/at-rule-support.js +83 -88
- package/dist/src/lib/parser/utils/at-rule-when-else.js +47 -47
- package/dist/src/lib/parser/utils/at-rule.js +5 -5
- package/dist/src/lib/parser/utils/base64.js +2 -2
- package/dist/src/lib/parser/utils/cache.js +1 -1
- package/dist/src/lib/parser/utils/config.js +1 -1
- package/dist/src/lib/parser/utils/declaration.js +233 -234
- package/dist/src/lib/parser/utils/eq.js +50 -3
- package/dist/src/lib/parser/utils/hash.js +2 -35
- package/dist/src/lib/parser/utils/selector.js +309 -387
- package/dist/src/lib/parser/utils/text.js +18 -4
- package/dist/src/lib/parser/utils/token.js +16 -69
- package/dist/src/lib/parser/utils/type.js +37 -24
- package/dist/src/lib/printer/render.js +965 -511
- package/dist/src/lib/printer/sourcemap/lib/codec.js +1 -1
- package/dist/src/lib/printer/sourcemap/sourcemap.js +1 -1
- package/dist/src/lib/syntax/color/a98rgb.js +1 -1
- package/dist/src/lib/syntax/color/alpha.js +36 -37
- package/dist/src/lib/syntax/color/cmyk.js +35 -52
- package/dist/src/lib/syntax/color/color-mix.js +96 -132
- package/dist/src/lib/syntax/color/color.js +222 -231
- package/dist/src/lib/syntax/color/hex.js +45 -55
- package/dist/src/lib/syntax/color/hsl.js +54 -62
- package/dist/src/lib/syntax/color/hwb.js +60 -68
- package/dist/src/lib/syntax/color/lab.js +59 -67
- package/dist/src/lib/syntax/color/lch.js +59 -67
- package/dist/src/lib/syntax/color/oklab.js +60 -68
- package/dist/src/lib/syntax/color/oklch.js +60 -67
- package/dist/src/lib/syntax/color/p3.js +1 -1
- package/dist/src/lib/syntax/color/prophotorgb.js +1 -1
- package/dist/src/lib/syntax/color/rec2020.js +1 -1
- package/dist/src/lib/syntax/color/relative-color.js +94 -144
- package/dist/src/lib/syntax/color/rgb.js +54 -57
- package/dist/src/lib/syntax/color/srgb.js +55 -53
- package/dist/src/lib/syntax/color/utils/color-type.js +13 -10
- package/dist/src/lib/syntax/color/utils/colorspace.js +11 -11
- package/dist/src/lib/syntax/color/utils/components.js +19 -20
- package/dist/src/lib/syntax/color/utils/distance.js +15 -13
- package/dist/src/lib/syntax/color/utils/make-color.js +15 -19
- package/dist/src/lib/syntax/color/utils/matrix.js +2 -2
- package/dist/src/lib/syntax/color/xyz.js +1 -1
- package/dist/src/lib/syntax/color/xyzd50.js +1 -1
- package/dist/src/lib/syntax/constants.js +2 -16
- package/dist/src/lib/syntax/syntax.js +301 -407
- package/dist/src/lib/validation/config.js +1 -1
- package/dist/src/lib/validation/match.js +959 -723
- package/dist/src/lib/validation/parser/parse.js +230 -112
- package/dist/src/lib/validation/parser/typedef.js +1 -1
- package/dist/src/lib/validation/utils/list.js +27 -12
- package/dist/src/node.js +12 -72
- package/dist/src/types.js +1 -1
- package/dist/src/utils/sync.js +9 -6
- package/dist/src/web.js +11 -73
- package/package.json +9 -10
- package/dist/index.cjs +0 -35870
- package/dist/src/lib/ast/clone.js +0 -51
- package/dist/src/lib/ast/expand.js +0 -311
- package/dist/src/lib/ast/find.js +0 -192
- package/dist/src/lib/ast/node.js +0 -59
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version:
|
|
5
|
+
Version: 2.0.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken, ColorType, EnumAstNodeStatus } from '../../ast/types.js';
|
|
@@ -23,7 +23,7 @@ import { srgb2rec2020values } from './rec2020.js';
|
|
|
23
23
|
import { isRectangularOrthogonalColorspace, isPolarColorspace } from '../syntax.js';
|
|
24
24
|
import { equalsIgnoreCase } from '../../parser/utils/text.js';
|
|
25
25
|
import { srgb2a98values } from './a98rgb.js';
|
|
26
|
-
import {
|
|
26
|
+
import { colorRange } from '../constants.js';
|
|
27
27
|
|
|
28
28
|
function interpolateHue(interpolationMethod, h1, h2) {
|
|
29
29
|
switch (interpolationMethod) {
|
|
@@ -63,9 +63,9 @@ function interpolateHue(interpolationMethod, h1, h2) {
|
|
|
63
63
|
* @param args
|
|
64
64
|
* @returns
|
|
65
65
|
*/
|
|
66
|
-
function colorMix(...args) {
|
|
66
|
+
function colorMix(arena, ...args) {
|
|
67
67
|
// invalid color or custom color profile
|
|
68
|
-
if (args.length == 0 || args[0]
|
|
68
|
+
if (args.length == 0 || arena.dataTypes[args[0]] === EnumToken.DashedIdenTokenType) {
|
|
69
69
|
return null;
|
|
70
70
|
}
|
|
71
71
|
let i = 0;
|
|
@@ -75,31 +75,31 @@ function colorMix(...args) {
|
|
|
75
75
|
let colorSpace = "oklab";
|
|
76
76
|
let hueInterpolationMethod = "shorter";
|
|
77
77
|
let values = null;
|
|
78
|
-
// const colors:
|
|
78
|
+
// const colors: Token[] = [];
|
|
79
79
|
const percentages = [];
|
|
80
80
|
const srgbComponentValues = [];
|
|
81
81
|
const colorComponents = [];
|
|
82
82
|
const colors = [];
|
|
83
|
-
if (args[i]
|
|
84
|
-
if (!equalsIgnoreCase(args[i++]
|
|
83
|
+
if (arena.dataTypes[args[i]] === EnumToken.IdenTokenType) {
|
|
84
|
+
if (!equalsIgnoreCase(arena.strings[arena.stringValue[args[i++]]], "in")) {
|
|
85
85
|
return null;
|
|
86
86
|
}
|
|
87
|
-
if (args[i]
|
|
87
|
+
if (arena.dataTypes[args[i]] !== EnumToken.IdenTokenType) {
|
|
88
88
|
return null;
|
|
89
89
|
}
|
|
90
|
-
if (isRectangularOrthogonalColorspace(args[i])) {
|
|
91
|
-
colorSpace = args[i++]
|
|
90
|
+
if (isRectangularOrthogonalColorspace(arena, args[i])) {
|
|
91
|
+
colorSpace = arena.strings[arena.stringValue[args[i++]]];
|
|
92
92
|
}
|
|
93
|
-
else if (isPolarColorspace(args[i])) {
|
|
94
|
-
colorSpace = args[i++]
|
|
95
|
-
if (args[i]
|
|
93
|
+
else if (isPolarColorspace(arena, args[i])) {
|
|
94
|
+
colorSpace = arena.strings[arena.stringValue[args[i++]]];
|
|
95
|
+
if (arena.dataTypes[args[i]] !== EnumToken.IdenTokenType && arena.dataTypes[args[i]] !== EnumToken.ColorTokenType) {
|
|
96
96
|
return null;
|
|
97
97
|
}
|
|
98
|
-
if (args[i]
|
|
99
|
-
if (args[i]
|
|
98
|
+
if (arena.dataTypes[args[i]] === EnumToken.IdenTokenType && !equalsIgnoreCase(arena.strings[arena.stringValue[args[i]]], "hue")) {
|
|
99
|
+
if (arena.dataTypes[args[i]] !== EnumToken.IdenTokenType) {
|
|
100
100
|
return null;
|
|
101
101
|
}
|
|
102
|
-
hueInterpolationMethod = args[i++]
|
|
102
|
+
hueInterpolationMethod = arena.strings[arena.stringValue[args[i++]]];
|
|
103
103
|
switch (hueInterpolationMethod) {
|
|
104
104
|
case "increasing":
|
|
105
105
|
case "decreasing":
|
|
@@ -109,30 +109,30 @@ function colorMix(...args) {
|
|
|
109
109
|
default:
|
|
110
110
|
return null;
|
|
111
111
|
}
|
|
112
|
-
if (!equalsIgnoreCase(args[i++]
|
|
112
|
+
if (!equalsIgnoreCase(arena.strings[arena.stringValue[args[i++]]], "hue")) {
|
|
113
113
|
return null;
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
while (i < args.length) {
|
|
119
|
-
if (args[i]
|
|
120
|
-
ColorType.SYS == args[i]
|
|
121
|
-
ColorType.DPSYS == args[i]
|
|
122
|
-
ColorType.NON_STD == args[i]
|
|
123
|
-
ColorType.CUSTOM_COLOR == args[i]
|
|
124
|
-
equalsIgnoreCase(args[i]
|
|
119
|
+
if (arena.dataTypes[args[i]] !== EnumToken.ColorTokenType ||
|
|
120
|
+
ColorType.SYS == arena.colorType[args[i]] ||
|
|
121
|
+
ColorType.DPSYS == arena.colorType[args[i]] ||
|
|
122
|
+
ColorType.NON_STD == arena.colorType[args[i]] ||
|
|
123
|
+
ColorType.CUSTOM_COLOR == arena.colorType[args[i]] ||
|
|
124
|
+
equalsIgnoreCase(arena.strings[arena.stringValue[args[i]]], "currentcolor")) {
|
|
125
125
|
return null;
|
|
126
126
|
}
|
|
127
|
-
colorComponents.push(getColorComponents(args[i]));
|
|
128
|
-
values = srgbvalues(args[i]);
|
|
127
|
+
colorComponents.push(getColorComponents(arena, args[i]));
|
|
128
|
+
values = srgbvalues(arena, args[i]);
|
|
129
129
|
if (values == null) {
|
|
130
130
|
return null;
|
|
131
131
|
}
|
|
132
132
|
// if (colorSpace == "hwb") {
|
|
133
133
|
// colorSpace = "srgb";
|
|
134
134
|
// }
|
|
135
|
-
colors.push(processPowerlessComponents(args[i]));
|
|
135
|
+
colors.push(processPowerlessComponents(arena, args[i]));
|
|
136
136
|
switch (colorSpace) {
|
|
137
137
|
case "srgb":
|
|
138
138
|
break;
|
|
@@ -184,24 +184,24 @@ function colorMix(...args) {
|
|
|
184
184
|
return null;
|
|
185
185
|
}
|
|
186
186
|
srgbComponentValues.push(values);
|
|
187
|
-
// colors.push(args[i++]
|
|
187
|
+
// colors.push(args[i++]);
|
|
188
188
|
i++;
|
|
189
189
|
if (i >= args.length) {
|
|
190
190
|
missingPercentageCount++;
|
|
191
191
|
percentages.push(null);
|
|
192
192
|
break;
|
|
193
193
|
}
|
|
194
|
-
if (args[i]
|
|
194
|
+
if (arena.dataTypes[args[i]] === EnumToken.ColorTokenType) {
|
|
195
195
|
percentages.push(null);
|
|
196
196
|
missingPercentageCount++;
|
|
197
197
|
continue;
|
|
198
198
|
}
|
|
199
|
-
if (args[i]
|
|
200
|
-
(args[i]
|
|
201
|
-
if (args[i]
|
|
199
|
+
if (arena.dataTypes[args[i]] === EnumToken.PercentageTokenType ||
|
|
200
|
+
(arena.dataTypes[args[i]] === EnumToken.NumberTokenType && 0 == arena.numericValue[args[i]])) {
|
|
201
|
+
if (arena.numericValue[args[i]] < 0) {
|
|
202
202
|
return null;
|
|
203
203
|
}
|
|
204
|
-
percentages.push(minmax(getNumber(args[i++]), 0, 1));
|
|
204
|
+
percentages.push(minmax(getNumber(arena, args[i++]), 0, 1));
|
|
205
205
|
totalPercentage += percentages.at(-1);
|
|
206
206
|
}
|
|
207
207
|
}
|
|
@@ -248,10 +248,10 @@ function colorMix(...args) {
|
|
|
248
248
|
let premult1;
|
|
249
249
|
let premult2;
|
|
250
250
|
let mixedPremult;
|
|
251
|
-
let offset1 = colors[0]
|
|
251
|
+
let offset1 = arena.colorType[colors[0]] == ColorType.COLOR ? 1 : 0;
|
|
252
252
|
if (colorComponents[0][offset1 + 3] != null &&
|
|
253
|
-
colorComponents[0][offset1 + 3]
|
|
254
|
-
colorComponents[0][offset1 + 3]
|
|
253
|
+
arena.dataTypes[colorComponents[0][offset1 + 3]] == EnumToken.IdenTokenType &&
|
|
254
|
+
arena.strings[arena.stringValue[colorComponents[0][offset1 + 3]]] == "none" &&
|
|
255
255
|
colorComponents[1].length == offset1 + 4) {
|
|
256
256
|
// fix powerless alpha for last color if previous color has alpha
|
|
257
257
|
stack[stack.length - 1].color[3] = stack[stack.length - 2].color[3];
|
|
@@ -261,59 +261,59 @@ function colorMix(...args) {
|
|
|
261
261
|
// powerless hue for lch spaces
|
|
262
262
|
// if (lchSpaces.includes(colorSpace)) {
|
|
263
263
|
// console.error(JSON.stringify({colorSpace1, colorSpace, stack, colorComponents}, null, 1));
|
|
264
|
-
if ((stack[stack.length - 1].color[0] == 0 && colorComponents[0][offset1]
|
|
265
|
-
colorComponents[0][offset1]
|
|
266
|
-
colorComponents[0][0]
|
|
264
|
+
if ((stack[stack.length - 1].color[0] == 0 && arena.dataTypes[colorComponents[0][offset1]] == EnumToken.IdenTokenType &&
|
|
265
|
+
arena.strings[arena.stringValue[colorComponents[0][offset1]]] == "none") ||
|
|
266
|
+
arena.flags[colorComponents[0][0]] & EnumAstNodeStatus.PowerlessColorComponent) {
|
|
267
267
|
stack[stack.length - 1].color[0] = stack[stack.length - 2].color[0];
|
|
268
268
|
}
|
|
269
|
-
if ((stack[stack.length - 1].color[1] == 0 && colorComponents[0][offset1 + 1]
|
|
270
|
-
colorComponents[0][offset1 + 1]
|
|
271
|
-
colorComponents[0][1]
|
|
269
|
+
if ((stack[stack.length - 1].color[1] == 0 && arena.dataTypes[colorComponents[0][offset1 + 1]] == EnumToken.IdenTokenType &&
|
|
270
|
+
arena.strings[arena.stringValue[colorComponents[0][offset1 + 1]]] == "none") ||
|
|
271
|
+
arena.flags[colorComponents[0][1]] & EnumAstNodeStatus.PowerlessColorComponent) {
|
|
272
272
|
stack[stack.length - 1].color[1] = stack[stack.length - 2].color[1];
|
|
273
273
|
}
|
|
274
|
-
if ((stack[stack.length - 1].color[2] == 0 && colorComponents[0][offset1 + 2]
|
|
275
|
-
colorComponents[0][offset1 + 2]
|
|
276
|
-
colorComponents[0][2]
|
|
274
|
+
if ((stack[stack.length - 1].color[2] == 0 && arena.dataTypes[colorComponents[0][offset1 + 2]] == EnumToken.IdenTokenType &&
|
|
275
|
+
arena.strings[arena.stringValue[colorComponents[0][offset1 + 2]]] == "none") ||
|
|
276
|
+
arena.flags[colorComponents[0][2]] & EnumAstNodeStatus.PowerlessColorComponent ||
|
|
277
277
|
(isLCHOrOKLCH &&
|
|
278
278
|
(stack[stack.length - 1].color[1] == 0 ||
|
|
279
279
|
stack[stack.length - 1].color[0] == 0 ||
|
|
280
280
|
stack[stack.length - 1].color[0] ==
|
|
281
|
-
colorRange[colors[0]
|
|
281
|
+
colorRange[arena.colorType[colors[0]] == ColorType.LCH ? "lch" : "oklch"].l[1]))) {
|
|
282
282
|
stack[stack.length - 1].color[2] = stack[stack.length - 2].color[2];
|
|
283
283
|
}
|
|
284
284
|
// }
|
|
285
285
|
}
|
|
286
|
-
// console.error([colorComponents[0][offset1]
|
|
286
|
+
// console.error([arena.dataTypes[colorComponents[0][offset1]] == EnumToken.IdenTokenType, arena.strings[arena.stringValue[colorComponents[0][offset1]]] == "none"]);
|
|
287
287
|
// console.error(isLCHOrOKLCH, colorComponents, stack);
|
|
288
288
|
while (stack.length > 1) {
|
|
289
289
|
r1 = stack.pop();
|
|
290
290
|
r2 = stack.pop();
|
|
291
|
-
offset1 = colors[++currentIndex]
|
|
291
|
+
offset1 = arena.colorType[colors[++currentIndex]] == ColorType.COLOR ? 1 : 0;
|
|
292
292
|
// r2 powerless alpha
|
|
293
293
|
if (colorComponents[currentIndex][offset1 + 3] != null &&
|
|
294
|
-
colorComponents[currentIndex][offset1 + 3]
|
|
295
|
-
colorComponents[currentIndex][offset1 + 3]
|
|
294
|
+
arena.dataTypes[colorComponents[currentIndex][offset1 + 3]] == EnumToken.IdenTokenType &&
|
|
295
|
+
arena.strings[arena.stringValue[colorComponents[currentIndex][offset1 + 3]]] == "none") {
|
|
296
296
|
// fix powerless alpha for last color if previous color has alpha
|
|
297
297
|
r2.color[3] = r1.color[3];
|
|
298
298
|
}
|
|
299
299
|
// powerless hue for lch spaces
|
|
300
|
-
if ((r2.color[0] == 0 && colorComponents[currentIndex][offset1]
|
|
301
|
-
colorComponents[currentIndex][offset1]
|
|
302
|
-
colorComponents[currentIndex][offset1]
|
|
300
|
+
if ((r2.color[0] == 0 && arena.dataTypes[colorComponents[currentIndex][offset1]] == EnumToken.IdenTokenType &&
|
|
301
|
+
arena.strings[arena.stringValue[colorComponents[currentIndex][offset1]]] == "none") ||
|
|
302
|
+
arena.flags[colorComponents[currentIndex][offset1]] & EnumAstNodeStatus.PowerlessColorComponent) {
|
|
303
303
|
r2.color[0] = r1.color[0];
|
|
304
304
|
}
|
|
305
|
-
if ((r2.color[1] == 0 && colorComponents[currentIndex][offset1 + 1]
|
|
306
|
-
colorComponents[currentIndex][offset1 + 1]
|
|
307
|
-
colorComponents[currentIndex][offset1 + 1]
|
|
305
|
+
if ((r2.color[1] == 0 && arena.dataTypes[colorComponents[currentIndex][offset1 + 1]] == EnumToken.IdenTokenType &&
|
|
306
|
+
arena.strings[arena.stringValue[colorComponents[currentIndex][offset1 + 1]]] == "none") ||
|
|
307
|
+
arena.flags[colorComponents[currentIndex][offset1 + 1]] & EnumAstNodeStatus.PowerlessColorComponent) {
|
|
308
308
|
r2.color[1] = r1.color[1];
|
|
309
309
|
}
|
|
310
|
-
if ((r2.color[2] == 0 && colorComponents[currentIndex][offset1 + 2]
|
|
311
|
-
colorComponents[currentIndex][offset1 + 2]
|
|
312
|
-
colorComponents[currentIndex][offset1 + 2]
|
|
310
|
+
if ((r2.color[2] == 0 && arena.dataTypes[colorComponents[currentIndex][offset1 + 2]] == EnumToken.IdenTokenType &&
|
|
311
|
+
arena.strings[arena.stringValue[colorComponents[currentIndex][offset1 + 2]]] == "none") ||
|
|
312
|
+
arena.flags[colorComponents[currentIndex][offset1 + 2]] & EnumAstNodeStatus.PowerlessColorComponent ||
|
|
313
313
|
(isLCHOrOKLCH &&
|
|
314
314
|
(r2.color[1] == 0 ||
|
|
315
315
|
r2.color[0] == 0 ||
|
|
316
|
-
r2.color[0] == colorRange[colors[currentIndex]
|
|
316
|
+
r2.color[0] == colorRange[arena.colorType[colors[currentIndex]] == ColorType.LCH ? "lch" : "oklch"].l[1]))) {
|
|
317
317
|
r2.color[2] = r1.color[2];
|
|
318
318
|
}
|
|
319
319
|
if (hueInterpolationMethod != null) {
|
|
@@ -362,17 +362,7 @@ function colorMix(...args) {
|
|
|
362
362
|
else {
|
|
363
363
|
values = xyz2lchvalues(values[0], values[1], values[2], values[3]);
|
|
364
364
|
}
|
|
365
|
-
return
|
|
366
|
-
typ: EnumToken.ColorTokenType,
|
|
367
|
-
val: "lch",
|
|
368
|
-
chi: values.map((val) => {
|
|
369
|
-
return {
|
|
370
|
-
typ: EnumToken.NumberTokenType,
|
|
371
|
-
val,
|
|
372
|
-
};
|
|
373
|
-
}),
|
|
374
|
-
kin: ColorType.LCH,
|
|
375
|
-
};
|
|
365
|
+
return arena.createColor("lch", ColorType.LCH, values.map((val) => arena.createToken(EnumToken.NumberTokenType, val)));
|
|
376
366
|
case "srgb":
|
|
377
367
|
case "srgb-linear":
|
|
378
368
|
case "a98-rgb":
|
|
@@ -380,21 +370,12 @@ function colorMix(...args) {
|
|
|
380
370
|
case "display-p3":
|
|
381
371
|
case "display-p3-linear":
|
|
382
372
|
case "prophoto-rgb":
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
values.map((v) => {
|
|
390
|
-
return {
|
|
391
|
-
typ: EnumToken.NumberTokenType,
|
|
392
|
-
val: v,
|
|
393
|
-
};
|
|
394
|
-
})),
|
|
395
|
-
kin: ColorType.COLOR,
|
|
396
|
-
cal: "col",
|
|
397
|
-
};
|
|
373
|
+
{
|
|
374
|
+
const color = arena.createColor("color", ColorType.COLOR, [arena.createToken(EnumToken.IdenTokenType, colorSpace)].concat(values.map((v) => arena.createToken(EnumToken.NumberTokenType, v))));
|
|
375
|
+
// inlined: arena.setUnitString(color, "col")
|
|
376
|
+
arena.unit[color] = arena.internString("col");
|
|
377
|
+
return color;
|
|
378
|
+
}
|
|
398
379
|
// case "rgb":
|
|
399
380
|
case "hsl":
|
|
400
381
|
case "hwb":
|
|
@@ -420,85 +401,68 @@ function colorMix(...args) {
|
|
|
420
401
|
values[2] %= 360;
|
|
421
402
|
}
|
|
422
403
|
}
|
|
423
|
-
|
|
424
|
-
const result = {
|
|
425
|
-
typ: EnumToken.ColorTokenType,
|
|
426
|
-
val: colorSpace,
|
|
427
|
-
chi: values.map((v) => {
|
|
428
|
-
return {
|
|
429
|
-
typ: EnumToken.NumberTokenType,
|
|
430
|
-
val: v,
|
|
431
|
-
};
|
|
432
|
-
}),
|
|
433
|
-
kin: ColorType[colorSpace.toUpperCase().replaceAll("-", "_")],
|
|
434
|
-
};
|
|
404
|
+
const components = values.map((v) => arena.createToken(EnumToken.NumberTokenType, v));
|
|
435
405
|
if (colorSpace == "hsl") {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
result.chi[2] = { typ: EnumToken.PercentageTokenType, val: result.chi[2].val };
|
|
406
|
+
arena.dataTypes[components[0]] = EnumToken.AngleTokenType;
|
|
407
|
+
// inlined: arena.setUnitString(components[0], "deg")
|
|
408
|
+
arena.unit[components[0]] = arena.internString("deg");
|
|
409
|
+
arena.dataTypes[components[1]] = EnumToken.PercentageTokenType;
|
|
410
|
+
arena.dataTypes[components[2]] = EnumToken.PercentageTokenType;
|
|
442
411
|
}
|
|
443
|
-
return
|
|
412
|
+
return arena.createColor(colorSpace, ColorType[colorSpace.toUpperCase().replaceAll("-", "_")], components);
|
|
444
413
|
}
|
|
445
414
|
return null;
|
|
446
415
|
}
|
|
447
|
-
function processPowerlessComponents(color) {
|
|
416
|
+
function processPowerlessComponents(arena, color) {
|
|
448
417
|
let components;
|
|
449
418
|
let values;
|
|
450
|
-
switch (color
|
|
419
|
+
switch (arena.colorType[color]) {
|
|
451
420
|
case ColorType.LCH:
|
|
452
421
|
case ColorType.OKLCH:
|
|
453
|
-
values = color
|
|
454
|
-
components = getColorComponents(color);
|
|
422
|
+
values = arena.colorType[color] == ColorType.LCH ? getLCHComponents(arena, color) : getOKLCHComponents(arena, color);
|
|
423
|
+
components = getColorComponents(arena, color);
|
|
455
424
|
if (values == null || values.length < 3 || components == null) {
|
|
456
425
|
break;
|
|
457
426
|
}
|
|
458
|
-
const max = color
|
|
427
|
+
const max = arena.colorType[color] == ColorType.LCH ? colorRange.lch.l[1] : colorRange.oklch.l[1];
|
|
459
428
|
// https://www.w3.org/TR/css-color-4/#specifying-lab-lch
|
|
460
429
|
// https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch
|
|
461
|
-
const epsilon = color
|
|
430
|
+
const epsilon = arena.colorType[color] == ColorType.LCH ? 0.0015 : 0.000004;
|
|
462
431
|
if (values[0] < epsilon || Math.abs(values[0] - max) < epsilon) {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
setColorFlag(components[1], EnumAstNodeStatus.PowerlessColorComponent);
|
|
467
|
-
setColorFlag(components[2], EnumAstNodeStatus.PowerlessColorComponent);
|
|
432
|
+
arena.resetToken(components[0], EnumToken.NumberTokenType, values[0] < epsilon ? 0 : max);
|
|
433
|
+
arena.resetToken(components[1], EnumToken.IdenTokenType, "none");
|
|
434
|
+
arena.resetToken(components[2], EnumToken.IdenTokenType, "none");
|
|
435
|
+
setColorFlag(arena, components[1], EnumAstNodeStatus.PowerlessColorComponent);
|
|
436
|
+
setColorFlag(arena, components[2], EnumAstNodeStatus.PowerlessColorComponent);
|
|
468
437
|
}
|
|
469
438
|
else if (values[1] < epsilon) {
|
|
470
439
|
values[1] = 0;
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
setColorFlag(components[2], EnumAstNodeStatus.PowerlessColorComponent);
|
|
440
|
+
arena.resetToken(components[1], EnumToken.NumberTokenType, 0);
|
|
441
|
+
arena.resetToken(components[2], EnumToken.IdenTokenType, "none");
|
|
442
|
+
setColorFlag(arena, components[2], EnumAstNodeStatus.PowerlessColorComponent);
|
|
474
443
|
}
|
|
475
444
|
break;
|
|
476
445
|
case ColorType.HSL:
|
|
477
446
|
case ColorType.HWB:
|
|
478
|
-
values = Object.values((color
|
|
479
|
-
components = getColorComponents(color);
|
|
447
|
+
values = Object.values((arena.colorType[color] == ColorType.HSL ? hslvalues(arena, color) : hwbvalues(arena, color)) ?? {});
|
|
448
|
+
components = getColorComponents(arena, color);
|
|
480
449
|
if (values == null || values.length < 3 || components == null) {
|
|
481
450
|
break;
|
|
482
451
|
}
|
|
483
452
|
// https://www.w3.org/TR/css-color-4/#the-hsl-notation
|
|
484
453
|
// https://www.w3.org/TR/css-color-4/#the-hwb-notation
|
|
485
|
-
if ((color
|
|
486
|
-
(color
|
|
487
|
-
|
|
488
|
-
setColorFlag(components[0], EnumAstNodeStatus.PowerlessColorComponent);
|
|
454
|
+
if ((arena.colorType[color] == ColorType.HSL && values[1] <= 0.001) ||
|
|
455
|
+
(arena.colorType[color] == ColorType.HWB && values[1] + values[2] >= 99.999)) {
|
|
456
|
+
arena.resetToken(components[0], EnumToken.IdenTokenType, "none");
|
|
457
|
+
setColorFlag(arena, components[0], EnumAstNodeStatus.PowerlessColorComponent);
|
|
489
458
|
}
|
|
490
459
|
break;
|
|
491
460
|
}
|
|
492
|
-
// console.error({ color: color
|
|
461
|
+
// console.error({ color: arena.tokens(color) ?? color, values });
|
|
493
462
|
return color;
|
|
494
463
|
}
|
|
495
|
-
function setColorFlag(token, flag) {
|
|
496
|
-
|
|
497
|
-
token[STATE] = flag;
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
token[STATE] |= flag;
|
|
501
|
-
}
|
|
464
|
+
function setColorFlag(arena, token, flag) {
|
|
465
|
+
arena.flags[token] |= flag;
|
|
502
466
|
}
|
|
503
467
|
|
|
504
468
|
export { colorMix };
|