@tbela99/css-parser 1.4.7 → 1.4.9
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 +33 -2
- package/dist/index-umd-web.js +12953 -13248
- package/dist/index.cjs +10358 -10655
- package/dist/index.d.ts +820 -89
- package/dist/lib/ast/features/calc.js +3 -1
- package/dist/lib/ast/features/if.js +2 -96
- package/dist/lib/ast/features/prefix.js +7 -2
- package/dist/lib/ast/features/shorthand.js +1 -1
- package/dist/lib/ast/features/transform.js +1 -1
- package/dist/lib/ast/find.js +6 -6
- package/dist/lib/ast/math/expression.js +30 -12
- package/dist/lib/ast/minify.js +34 -5
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/utils.js +29 -21
- package/dist/lib/ast/types.js +12 -0
- package/dist/lib/fs/resolve.js +2 -17
- package/dist/lib/parser/declaration/list.js +6 -1
- package/dist/lib/parser/linesmap.js +78 -0
- package/dist/lib/parser/parse.js +1264 -151
- package/dist/lib/parser/source.js +103 -0
- package/dist/lib/parser/tokenize.js +112 -133
- package/dist/lib/parser/utils/at-rule-container.js +12 -44
- package/dist/lib/parser/utils/at-rule-generic.js +12 -24
- package/dist/lib/parser/utils/at-rule-import.js +4 -172
- package/dist/lib/parser/utils/at-rule-media.js +27 -263
- package/dist/lib/parser/utils/at-rule-support.js +8 -258
- package/dist/lib/parser/utils/at-rule-when-else.js +4 -214
- package/dist/lib/parser/utils/declaration.js +5 -95
- package/dist/lib/parser/utils/hash.js +54 -1
- package/dist/lib/parser/utils/selector.js +1 -1
- package/dist/lib/parser/utils/token.js +1 -0
- package/dist/lib/renderer/render.js +79 -45
- package/dist/lib/renderer/sourcemap/sourcemap.js +47 -43
- package/dist/lib/syntax/color/cmyk.js +3 -3
- package/dist/lib/syntax/color/color-mix.js +15 -8
- package/dist/lib/syntax/color/color.js +19 -11
- package/dist/lib/syntax/color/hex.js +1 -1
- package/dist/lib/syntax/color/hsl.js +6 -6
- package/dist/lib/syntax/color/hwb.js +6 -6
- package/dist/lib/syntax/color/lab.js +5 -5
- package/dist/lib/syntax/color/lch.js +6 -6
- package/dist/lib/syntax/color/oklab.js +5 -5
- package/dist/lib/syntax/color/oklch.js +5 -5
- package/dist/lib/syntax/color/p3.js +9 -1
- package/dist/lib/syntax/color/{relativecolor.js → relative-color.js} +8 -1
- package/dist/lib/syntax/color/utils/distance.js +7 -2
- package/dist/lib/syntax/constants.js +5 -1
- package/dist/lib/syntax/syntax.js +12 -21
- package/dist/lib/validation/config.json.js +27 -6
- package/dist/lib/validation/match.js +42 -845
- package/dist/node.js +136 -11
- package/dist/web.js +135 -8
- package/llms.txt +73 -0
- package/package.json +14 -17
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { EnumToken, ColorType } from '../../ast/types.js';
|
|
2
|
-
import { minmax, getNumber
|
|
2
|
+
import { minmax, getNumber } from './color.js';
|
|
3
3
|
import { srgbvalues, srgb2lsrgbvalues } from './srgb.js';
|
|
4
4
|
import { srgb2lch, xyz2lchvalues } from './lch.js';
|
|
5
5
|
import { srgb2rgb } from './rgb.js';
|
|
6
6
|
import { srgb2hslvalues } from './hsl.js';
|
|
7
7
|
import { srgb2hwb } from './hwb.js';
|
|
8
8
|
import { srgb2labvalues } from './lab.js';
|
|
9
|
-
import { srgb2p3values } from './p3.js';
|
|
9
|
+
import { srgb2lp3values, srgb2p3values } from './p3.js';
|
|
10
10
|
import { getColorComponents } from './utils/components.js';
|
|
11
11
|
import { srgb2oklch } from './oklch.js';
|
|
12
12
|
import { srgb2oklab } from './oklab.js';
|
|
@@ -127,6 +127,10 @@ function colorMix(...args) {
|
|
|
127
127
|
// @ts-ignore
|
|
128
128
|
values = srgb2p3values(...values);
|
|
129
129
|
break;
|
|
130
|
+
case "display-p3-linear":
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
values = srgb2lp3values(...values);
|
|
133
|
+
break;
|
|
130
134
|
case "a98-rgb":
|
|
131
135
|
// @ts-ignore
|
|
132
136
|
values = srgb2a98values(...values);
|
|
@@ -341,7 +345,7 @@ function colorMix(...args) {
|
|
|
341
345
|
chi: values.map((v) => {
|
|
342
346
|
return {
|
|
343
347
|
typ: EnumToken.NumberTokenType,
|
|
344
|
-
val:
|
|
348
|
+
val: v,
|
|
345
349
|
};
|
|
346
350
|
}),
|
|
347
351
|
kin: ColorType.LCH,
|
|
@@ -350,6 +354,9 @@ function colorMix(...args) {
|
|
|
350
354
|
case "srgb-linear":
|
|
351
355
|
case "a98-rgb":
|
|
352
356
|
case "rec2020":
|
|
357
|
+
case "display-p3":
|
|
358
|
+
case "display-p3-linear":
|
|
359
|
+
case "prophoto-rgb":
|
|
353
360
|
// @ts-ignore
|
|
354
361
|
return {
|
|
355
362
|
typ: EnumToken.ColorTokenType,
|
|
@@ -359,7 +366,7 @@ function colorMix(...args) {
|
|
|
359
366
|
values.map((v) => {
|
|
360
367
|
return {
|
|
361
368
|
typ: EnumToken.NumberTokenType,
|
|
362
|
-
val:
|
|
369
|
+
val: v,
|
|
363
370
|
};
|
|
364
371
|
})),
|
|
365
372
|
kin: ColorType.COLOR,
|
|
@@ -397,18 +404,18 @@ function colorMix(...args) {
|
|
|
397
404
|
chi: values.map((v) => {
|
|
398
405
|
return {
|
|
399
406
|
typ: EnumToken.NumberTokenType,
|
|
400
|
-
val:
|
|
407
|
+
val: v,
|
|
401
408
|
};
|
|
402
409
|
}),
|
|
403
410
|
kin: ColorType[colorSpace.toUpperCase().replaceAll("-", "_")],
|
|
404
411
|
};
|
|
405
412
|
if (colorSpace == "hsl" || colorSpace == "hwb") {
|
|
406
413
|
// @ts-ignore
|
|
407
|
-
result.chi[0] = { typ: EnumToken.AngleTokenType, val:
|
|
414
|
+
result.chi[0] = { typ: EnumToken.AngleTokenType, val: result.chi[0].val * 360 };
|
|
408
415
|
// @ts-ignore
|
|
409
|
-
result.chi[1] = { typ: EnumToken.PercentageTokenType, val:
|
|
416
|
+
result.chi[1] = { typ: EnumToken.PercentageTokenType, val: result.chi[1].val * 100 };
|
|
410
417
|
// @ts-ignore
|
|
411
|
-
result.chi[2] = { typ: EnumToken.PercentageTokenType, val:
|
|
418
|
+
result.chi[2] = { typ: EnumToken.PercentageTokenType, val: result.chi[2].val * 100 };
|
|
412
419
|
}
|
|
413
420
|
return result;
|
|
414
421
|
}
|
|
@@ -11,15 +11,15 @@ import { oklch2srgbvalues, lch2srgbvalues, oklab2srgbvalues, lab2srgbvalues, cmy
|
|
|
11
11
|
import { prophotorgb2srgbvalues, srgb2prophotorgbvalues } from './prophotorgb.js';
|
|
12
12
|
import { rec20202srgb, srgb2rec2020values } from './rec2020.js';
|
|
13
13
|
import { srgb2xyz_d65, srgb2xyz } from './xyz.js';
|
|
14
|
-
import { p32srgbvalues, srgb2p3values } from './p3.js';
|
|
14
|
+
import { lp32srgbvalues, p32srgbvalues, srgb2p3values } from './p3.js';
|
|
15
15
|
import { xyzd502srgb } from './xyzd50.js';
|
|
16
16
|
import { colorMix } from './color-mix.js';
|
|
17
17
|
import { reduceHexValue, rgb2HexToken, color2HexToken, lch2HexToken, lab2HexToken, oklch2HexToken, oklab2HexToken, cmyk2HexToken, hwb2HexToken, hsl2HexToken } from './hex.js';
|
|
18
|
-
import { parseRelativeColorComponents } from './
|
|
18
|
+
import { parseRelativeColorComponents } from './relative-color.js';
|
|
19
19
|
import { isIdentColor } from '../syntax.js';
|
|
20
20
|
import { color2cmykToken, lch2cmykToken, lab2cmykToken, oklch2cmykToken, oklab2cmyk, hwb2cmykToken, hsl2cmykToken, rgb2cmykToken } from './cmyk.js';
|
|
21
21
|
import { a98rgb2srgbvalues, srgb2a98values } from './a98rgb.js';
|
|
22
|
-
import { LOC,
|
|
22
|
+
import { LOC, colorFuncColorSpace, colorPrecision, epsilon, anglePrecision } from '../constants.js';
|
|
23
23
|
import { trimArray } from '../../validation/match.js';
|
|
24
24
|
import { alpha } from './alpha.js';
|
|
25
25
|
import { equalsIgnoreCase } from '../../parser/utils/text.js';
|
|
@@ -39,7 +39,7 @@ import { equalsIgnoreCase } from '../../parser/utils/text.js';
|
|
|
39
39
|
function convertColor(token, to) {
|
|
40
40
|
if (token.kin == ColorType.SYS ||
|
|
41
41
|
token.kin == ColorType.DPSYS ||
|
|
42
|
-
(isIdentColor(token) && "currentcolor" == token.val
|
|
42
|
+
(isIdentColor(token) && "currentcolor" == token.val)) {
|
|
43
43
|
return token;
|
|
44
44
|
}
|
|
45
45
|
if (token.kin == ColorType.ALPHA) {
|
|
@@ -102,7 +102,7 @@ function convertColor(token, to) {
|
|
|
102
102
|
if (colorSpace.val == ColorType[to].toLowerCase().replaceAll("_", "-")) {
|
|
103
103
|
for (const chi of token.chi) {
|
|
104
104
|
if (chi.typ == EnumToken.NumberTokenType && typeof chi.val == "number") {
|
|
105
|
-
chi.val =
|
|
105
|
+
chi.val = getNumber(chi);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
return token;
|
|
@@ -450,6 +450,10 @@ function srgb2srgbcolorspace(val, to) {
|
|
|
450
450
|
// @ts-ignore
|
|
451
451
|
values.push(...srgb2p3values(...val));
|
|
452
452
|
break;
|
|
453
|
+
case ColorType.DISPLAY_P3_LINEAR:
|
|
454
|
+
// @ts-ignore
|
|
455
|
+
values.push(...srgb2lp3values(...val));
|
|
456
|
+
break;
|
|
453
457
|
case ColorType.PROPHOTO_RGB:
|
|
454
458
|
// @ts-ignore
|
|
455
459
|
values.push(...srgb2prophotorgbvalues(...val));
|
|
@@ -484,11 +488,15 @@ function color2srgbvalues(token) {
|
|
|
484
488
|
}
|
|
485
489
|
const colorSpace = components.shift();
|
|
486
490
|
let values = components.map((val) => getNumber(val));
|
|
487
|
-
switch (colorSpace.val
|
|
491
|
+
switch (colorSpace.val) {
|
|
488
492
|
case "display-p3":
|
|
489
493
|
// @ts-ignore
|
|
490
494
|
values = p32srgbvalues(...values);
|
|
491
495
|
break;
|
|
496
|
+
case "display-p3-linear":
|
|
497
|
+
// @ts-ignore
|
|
498
|
+
values = lp32srgbvalues(...values);
|
|
499
|
+
break;
|
|
492
500
|
case "srgb-linear":
|
|
493
501
|
// @ts-ignore
|
|
494
502
|
values = lsrgb2srgbvalues(...values);
|
|
@@ -516,21 +524,21 @@ function color2srgbvalues(token) {
|
|
|
516
524
|
break;
|
|
517
525
|
}
|
|
518
526
|
if (values.length == 4) {
|
|
519
|
-
values[3] =
|
|
527
|
+
values[3] = values[3];
|
|
520
528
|
}
|
|
521
529
|
return values;
|
|
522
530
|
}
|
|
523
531
|
function values2colortoken(values, to) {
|
|
524
532
|
values = srgb2srgbcolorspace(values, to);
|
|
525
533
|
const chi = [
|
|
526
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
527
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
528
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
534
|
+
{ typ: EnumToken.NumberTokenType, val: values[0] },
|
|
535
|
+
{ typ: EnumToken.NumberTokenType, val: values[1] },
|
|
536
|
+
{ typ: EnumToken.NumberTokenType, val: values[2] },
|
|
529
537
|
];
|
|
530
538
|
if (values.length == 4) {
|
|
531
539
|
chi.push({ typ: EnumToken.LiteralTokenType, val: "/" }, {
|
|
532
540
|
typ: EnumToken.PercentageTokenType,
|
|
533
|
-
val:
|
|
541
|
+
val: values[3] * 100,
|
|
534
542
|
});
|
|
535
543
|
}
|
|
536
544
|
const colorSpace = ColorType[to].toLowerCase().replaceAll("_", "-");
|
|
@@ -70,7 +70,7 @@ function color2HexToken(token) {
|
|
|
70
70
|
if (value == null) {
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
|
-
return hexToken(value.reduce((acc, curr) => acc + srgb2rgb(curr).toString(16).padStart(2, "0"), "#"));
|
|
73
|
+
return hexToken(value.reduce((acc, curr) => acc + srgb2rgb(curr + Number.EPSILON).toString(16).padStart(2, "0"), "#"));
|
|
74
74
|
}
|
|
75
75
|
function oklab2HexToken(token) {
|
|
76
76
|
let value = oklab2srgbvalues(token);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hwb2hsv } from './hsv.js';
|
|
2
|
-
import { color2srgbvalues,
|
|
2
|
+
import { color2srgbvalues, getNumber } from './color.js';
|
|
3
3
|
import { lch2rgbvalues, lab2rgbvalues, cmyk2rgbvalues } from './rgb.js';
|
|
4
4
|
import { getColorComponents } from './utils/components.js';
|
|
5
5
|
import { hex2srgbvalues, oklch2srgbvalues, oklab2srgbvalues, hslvalues } from './srgb.js';
|
|
@@ -67,16 +67,16 @@ function color2HslToken(token) {
|
|
|
67
67
|
return hslToken(srgb2hslvalues(...values));
|
|
68
68
|
}
|
|
69
69
|
function hslToken(values) {
|
|
70
|
-
values[0] =
|
|
70
|
+
values[0] = values[0] * 360;
|
|
71
71
|
const chi = [
|
|
72
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
73
|
-
{ typ: EnumToken.PercentageTokenType, val:
|
|
74
|
-
{ typ: EnumToken.PercentageTokenType, val:
|
|
72
|
+
{ typ: EnumToken.NumberTokenType, val: values[0] },
|
|
73
|
+
{ typ: EnumToken.PercentageTokenType, val: values[1] * 100 },
|
|
74
|
+
{ typ: EnumToken.PercentageTokenType, val: values[2] * 100 },
|
|
75
75
|
];
|
|
76
76
|
if (values.length == 4 && values[3] != 1) {
|
|
77
77
|
chi.push({ typ: EnumToken.LiteralTokenType, val: "/" }, {
|
|
78
78
|
typ: EnumToken.PercentageTokenType,
|
|
79
|
-
val:
|
|
79
|
+
val: values[3] * 100,
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { hsl2hsv } from './hsv.js';
|
|
2
2
|
import { getColorComponents } from './utils/components.js';
|
|
3
|
-
import { color2srgbvalues,
|
|
3
|
+
import { color2srgbvalues, getAngle, getNumber } from './color.js';
|
|
4
4
|
import { EnumToken, ColorType } from '../../ast/types.js';
|
|
5
5
|
import { cmyk2srgbvalues, lch2srgbvalues, lab2srgbvalues, oklch2srgbvalues, oklab2srgbvalues } from './srgb.js';
|
|
6
6
|
|
|
@@ -61,16 +61,16 @@ function color2hwbToken(token) {
|
|
|
61
61
|
return hwbToken(values);
|
|
62
62
|
}
|
|
63
63
|
function hwbToken(values) {
|
|
64
|
-
values[0] =
|
|
64
|
+
values[0] = values[0] * 360;
|
|
65
65
|
const chi = [
|
|
66
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
67
|
-
{ typ: EnumToken.PercentageTokenType, val:
|
|
68
|
-
{ typ: EnumToken.PercentageTokenType, val:
|
|
66
|
+
{ typ: EnumToken.NumberTokenType, val: values[0] },
|
|
67
|
+
{ typ: EnumToken.PercentageTokenType, val: values[1] * 100 },
|
|
68
|
+
{ typ: EnumToken.PercentageTokenType, val: values[2] * 100 },
|
|
69
69
|
];
|
|
70
70
|
if (values.length == 4) {
|
|
71
71
|
chi.push({ typ: EnumToken.LiteralTokenType, val: "/" }, {
|
|
72
72
|
typ: EnumToken.PercentageTokenType,
|
|
73
|
-
val:
|
|
73
|
+
val: values[3] * 100
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
return {
|
|
@@ -4,7 +4,7 @@ import { srgb2xyz_d65, XYZ_D50_to_D65 } from './xyz.js';
|
|
|
4
4
|
import { oklch2srgbvalues, cmyk2srgbvalues, hwb2srgbvalues, hsl2srgb, rgb2srgb, hex2srgbvalues, xyz2srgb } from './srgb.js';
|
|
5
5
|
import { getLCHComponents } from './lch.js';
|
|
6
6
|
import { getOKLABComponents, OKLab_to_XYZ } from './oklab.js';
|
|
7
|
-
import { color2srgbvalues,
|
|
7
|
+
import { color2srgbvalues, getNumber } from './color.js';
|
|
8
8
|
import { EnumToken, ColorType } from '../../ast/types.js';
|
|
9
9
|
import { XYZ_D65_to_D50 } from './xyzd50.js';
|
|
10
10
|
|
|
@@ -70,14 +70,14 @@ function color2labToken(token) {
|
|
|
70
70
|
}
|
|
71
71
|
function labToken(values) {
|
|
72
72
|
const chi = [
|
|
73
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
74
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
75
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
73
|
+
{ typ: EnumToken.NumberTokenType, val: values[0] },
|
|
74
|
+
{ typ: EnumToken.NumberTokenType, val: values[1] },
|
|
75
|
+
{ typ: EnumToken.NumberTokenType, val: values[2] },
|
|
76
76
|
];
|
|
77
77
|
if (values.length == 4) {
|
|
78
78
|
chi.push({ typ: EnumToken.LiteralTokenType, val: "/" }, {
|
|
79
79
|
typ: EnumToken.PercentageTokenType,
|
|
80
|
-
val:
|
|
80
|
+
val: values[3] * 100,
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getColorComponents } from './utils/components.js';
|
|
2
|
-
import { color2srgbvalues,
|
|
2
|
+
import { color2srgbvalues, getNumber, getAngle } from './color.js';
|
|
3
3
|
import { EnumToken, ColorType } from '../../ast/types.js';
|
|
4
4
|
import { srgb2labvalues, xyz2lab, oklch2labvalues, oklab2labvalues, getLABComponents, hwb2labvalues, hsl2labvalues, rgb2labvalues, hex2labvalues } from './lab.js';
|
|
5
5
|
import { cmyk2srgbvalues } from './srgb.js';
|
|
@@ -68,16 +68,16 @@ function color2lchToken(token) {
|
|
|
68
68
|
return lchToken(values);
|
|
69
69
|
}
|
|
70
70
|
function lchToken(values) {
|
|
71
|
-
values[2] =
|
|
71
|
+
values[2] = values[2];
|
|
72
72
|
const chi = [
|
|
73
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
74
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
75
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
73
|
+
{ typ: EnumToken.NumberTokenType, val: values[0] },
|
|
74
|
+
{ typ: EnumToken.NumberTokenType, val: values[1] },
|
|
75
|
+
{ typ: EnumToken.NumberTokenType, val: values[2] },
|
|
76
76
|
];
|
|
77
77
|
if (values.length == 4) {
|
|
78
78
|
chi.push({ typ: EnumToken.LiteralTokenType, val: "/" }, {
|
|
79
79
|
typ: EnumToken.PercentageTokenType,
|
|
80
|
-
val:
|
|
80
|
+
val: values[3] * 100,
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
return {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getColorComponents } from './utils/components.js';
|
|
2
2
|
import { multiplyMatrices } from './utils/matrix.js';
|
|
3
3
|
import { srgb2lsrgbvalues, lch2srgbvalues, lab2srgbvalues, cmyk2srgbvalues, hwb2srgbvalues, hsl2srgb, rgb2srgb, hex2srgbvalues, lsrgb2srgbvalues } from './srgb.js';
|
|
4
|
-
import {
|
|
4
|
+
import { getNumber, color2srgbvalues } from './color.js';
|
|
5
5
|
import { EnumToken, ColorType } from '../../ast/types.js';
|
|
6
6
|
import { getOKLCHComponents } from './oklch.js';
|
|
7
7
|
import { lchvalues2labvalues } from './lab.js';
|
|
@@ -71,14 +71,14 @@ function color2oklabToken(token) {
|
|
|
71
71
|
}
|
|
72
72
|
function oklabToken(values) {
|
|
73
73
|
const chi = [
|
|
74
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
75
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
76
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
74
|
+
{ typ: EnumToken.NumberTokenType, val: values[0] },
|
|
75
|
+
{ typ: EnumToken.NumberTokenType, val: values[1] },
|
|
76
|
+
{ typ: EnumToken.NumberTokenType, val: values[2] },
|
|
77
77
|
];
|
|
78
78
|
if (values.length == 4) {
|
|
79
79
|
chi.push({ typ: EnumToken.LiteralTokenType, val: "/" }, {
|
|
80
80
|
typ: EnumToken.PercentageTokenType,
|
|
81
|
-
val:
|
|
81
|
+
val: values[3] * 100,
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getColorComponents } from './utils/components.js';
|
|
2
|
-
import { color2srgbvalues,
|
|
2
|
+
import { color2srgbvalues, getNumber, getAngle } from './color.js';
|
|
3
3
|
import { EnumToken, ColorType } from '../../ast/types.js';
|
|
4
4
|
import { labvalues2lchvalues } from './lch.js';
|
|
5
5
|
import { srgb2oklab, lch2oklabvalues, getOKLABComponents, lab2oklabvalues, hwb2oklabvalues, hsl2oklabvalues, rgb2oklabvalues, hex2oklabvalues } from './oklab.js';
|
|
@@ -67,16 +67,16 @@ function color2oklchToken(token) {
|
|
|
67
67
|
return oklchToken(srgb2oklch(...values));
|
|
68
68
|
}
|
|
69
69
|
function oklchToken(values) {
|
|
70
|
-
values[2] =
|
|
70
|
+
values[2] = values[2];
|
|
71
71
|
const chi = [
|
|
72
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
73
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
72
|
+
{ typ: EnumToken.NumberTokenType, val: values[0] },
|
|
73
|
+
{ typ: EnumToken.NumberTokenType, val: values[1] },
|
|
74
74
|
{ typ: EnumToken.NumberTokenType, val: values[2] },
|
|
75
75
|
];
|
|
76
76
|
if (values.length == 4) {
|
|
77
77
|
chi.push({ typ: EnumToken.LiteralTokenType, val: "/" }, {
|
|
78
78
|
typ: EnumToken.PercentageTokenType,
|
|
79
|
-
val:
|
|
79
|
+
val: values[3] * 100,
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
return {
|
|
@@ -10,6 +10,14 @@ function srgb2p3values(r, g, b, alpha) {
|
|
|
10
10
|
// @ts-ignore
|
|
11
11
|
return lp32p3(...xyz2lp3(...srgb2xyz(r, g, b, alpha)));
|
|
12
12
|
}
|
|
13
|
+
function srgb2lp3values(r, g, b, alpha) {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
return xyz2lp3(...srgb2xyz(r, g, b, alpha));
|
|
16
|
+
}
|
|
17
|
+
function lp32srgbvalues(r, g, b, alpha) {
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
return xyz2srgb(...lp32xyz(r, g, b, alpha));
|
|
20
|
+
}
|
|
13
21
|
function p32lp3(r, g, b, alpha) {
|
|
14
22
|
// convert an array of display-p3 RGB values in the range 0.0 - 1.0
|
|
15
23
|
// to linear light (un-companded) form.
|
|
@@ -49,4 +57,4 @@ function xyz2lp3(x, y, z, alpha) {
|
|
|
49
57
|
return result;
|
|
50
58
|
}
|
|
51
59
|
|
|
52
|
-
export { lp32p3, lp32xyz, p32lp3, p32srgbvalues, srgb2p3values, xyz2lp3 };
|
|
60
|
+
export { lp32p3, lp32srgbvalues, lp32xyz, p32lp3, p32srgbvalues, srgb2lp3values, srgb2p3values, xyz2lp3 };
|
|
@@ -2,7 +2,7 @@ import { convertColor, getNumber } from './color.js';
|
|
|
2
2
|
import { EnumToken, ColorType } from '../../ast/types.js';
|
|
3
3
|
import { walkValues } from '../../ast/walk.js';
|
|
4
4
|
import { evaluateFunc, evaluate } from '../../ast/math/expression.js';
|
|
5
|
-
import { colorsFunc, colorFuncColorSpace, colorRange, mathFuncs } from '../constants.js';
|
|
5
|
+
import { colorsFunc, colorFuncColorSpace, LOC, colorRange, mathFuncs } from '../constants.js';
|
|
6
6
|
import { equalsIgnoreCase } from '../../parser/utils/text.js';
|
|
7
7
|
import { getColorComponents } from './utils/components.js';
|
|
8
8
|
|
|
@@ -103,16 +103,19 @@ function parseRelativeColorComponents(relativeKeys, original, rExp, gExp, bExp,
|
|
|
103
103
|
? {
|
|
104
104
|
typ: EnumToken.NumberTokenType,
|
|
105
105
|
val: 1,
|
|
106
|
+
[LOC]: b[LOC],
|
|
106
107
|
}
|
|
107
108
|
: alpha.typ == EnumToken.IdenTokenType && alpha.val == "none"
|
|
108
109
|
? {
|
|
109
110
|
typ: EnumToken.NumberTokenType,
|
|
110
111
|
val: 0,
|
|
112
|
+
[LOC]: alpha[LOC],
|
|
111
113
|
}
|
|
112
114
|
: alpha.typ == EnumToken.PercentageTokenType
|
|
113
115
|
? {
|
|
114
116
|
typ: EnumToken.NumberTokenType,
|
|
115
117
|
val: getNumber(alpha),
|
|
118
|
+
[LOC]: alpha[LOC],
|
|
116
119
|
}
|
|
117
120
|
: alpha,
|
|
118
121
|
};
|
|
@@ -125,11 +128,13 @@ function parseRelativeColorComponents(relativeKeys, original, rExp, gExp, bExp,
|
|
|
125
128
|
? {
|
|
126
129
|
typ: EnumToken.NumberTokenType,
|
|
127
130
|
val: 1,
|
|
131
|
+
[LOC]: bExp[LOC],
|
|
128
132
|
}
|
|
129
133
|
: aExp.typ == EnumToken.IdenTokenType && aExp.val == "none"
|
|
130
134
|
? {
|
|
131
135
|
typ: EnumToken.NumberTokenType,
|
|
132
136
|
val: 0,
|
|
137
|
+
[LOC]: aExp[LOC],
|
|
133
138
|
}
|
|
134
139
|
: aExp),
|
|
135
140
|
};
|
|
@@ -160,6 +165,7 @@ function getValue(t, converted, component) {
|
|
|
160
165
|
return {
|
|
161
166
|
typ: EnumToken.NumberTokenType,
|
|
162
167
|
val: value,
|
|
168
|
+
[LOC]: t[LOC],
|
|
163
169
|
};
|
|
164
170
|
}
|
|
165
171
|
return t;
|
|
@@ -203,6 +209,7 @@ function computeComponentValue(expr, values) {
|
|
|
203
209
|
typ: EnumToken.NumberTokenType,
|
|
204
210
|
// @ts-ignore
|
|
205
211
|
val: "" + Math[value.val.toUpperCase()],
|
|
212
|
+
[LOC]: value[LOC],
|
|
206
213
|
// @ts-ignore
|
|
207
214
|
});
|
|
208
215
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { convertColor } from '../color.js';
|
|
1
|
+
import { convertColor, toPrecisionValue } from '../color.js';
|
|
2
2
|
import { getOKLABComponents } from '../oklab.js';
|
|
3
3
|
import { ColorType } from '../../../ast/types.js';
|
|
4
4
|
import { colorDistancePrecision } from '../../constants.js';
|
|
@@ -22,7 +22,12 @@ function okLabDistance(color1, color2) {
|
|
|
22
22
|
if (okLab1 == null || okLab2 == null) {
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
const diff = [okLab1[0] - okLab2[0], okLab1[1] - okLab2[1], okLab1[2] - okLab2[2]];
|
|
26
|
+
// include alpha
|
|
27
|
+
if (okLab1[3] != null || okLab2[3] != null) {
|
|
28
|
+
diff.push((okLab1[3] ?? 1) - (okLab2[3] ?? 1));
|
|
29
|
+
}
|
|
30
|
+
return toPrecisionValue(Math.hypot(...diff));
|
|
26
31
|
}
|
|
27
32
|
/**
|
|
28
33
|
* Check if two colors are close in okLab space.
|
|
@@ -185,9 +185,10 @@ const colorsFunc = [
|
|
|
185
185
|
"lab",
|
|
186
186
|
"oklch",
|
|
187
187
|
"lch",
|
|
188
|
+
"alpha",
|
|
188
189
|
"light-dark",
|
|
190
|
+
"color-layers",
|
|
189
191
|
"contrast-color",
|
|
190
|
-
"alpha",
|
|
191
192
|
];
|
|
192
193
|
const imageFunc = [
|
|
193
194
|
"linear-gradient",
|
|
@@ -247,9 +248,12 @@ const colorFuncColorSpace = [
|
|
|
247
248
|
"srgb",
|
|
248
249
|
"srgb-linear",
|
|
249
250
|
"display-p3",
|
|
251
|
+
"display-p3-linear",
|
|
250
252
|
"prophoto-rgb",
|
|
251
253
|
"a98-rgb",
|
|
252
254
|
"rec2020",
|
|
255
|
+
"lab",
|
|
256
|
+
"oklab",
|
|
253
257
|
"xyz",
|
|
254
258
|
"xyz-d65",
|
|
255
259
|
"xyz-d50",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isOkLabClose } from './color/utils/distance.js';
|
|
1
2
|
import { EnumToken, ColorType } from '../ast/types.js';
|
|
2
3
|
import { walkValues, WalkerOptionEnum } from '../ast/walk.js';
|
|
3
4
|
import { toDegrees } from '../parser/utils/angle.js';
|
|
@@ -7,8 +8,8 @@ import { trimArray } from '../validation/match.js';
|
|
|
7
8
|
import { splitTokenList } from '../validation/utils/list.js';
|
|
8
9
|
import { getColorSpace } from './color/utils/colorspace.js';
|
|
9
10
|
import { getColorComponents } from './color/utils/components.js';
|
|
10
|
-
import { nonStandardColors, systemColors, deprecatedSystemColors, COLORS_NAMES, colorsFunc, colorFuncColorSpace
|
|
11
|
-
import {
|
|
11
|
+
import { nonStandardColors, systemColors, deprecatedSystemColors, COLORS_NAMES, colorsFunc, colorFuncColorSpace } from './constants.js';
|
|
12
|
+
import { getSyntaxConfig } from '../validation/config.js';
|
|
12
13
|
|
|
13
14
|
// https://www.w3.org/TR/CSS21/syndata.html#syntax
|
|
14
15
|
// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token
|
|
@@ -387,19 +388,7 @@ function reduceConicColorStops(stops) {
|
|
|
387
388
|
*/
|
|
388
389
|
function isRectangularOrthogonalColorspace(token) {
|
|
389
390
|
return (token.typ === EnumToken.IdenTokenType &&
|
|
390
|
-
|
|
391
|
-
"srgb",
|
|
392
|
-
"srgb-linear",
|
|
393
|
-
"display-p3",
|
|
394
|
-
"a98-rgb",
|
|
395
|
-
"prophoto-rgb",
|
|
396
|
-
"rec2020",
|
|
397
|
-
"lab",
|
|
398
|
-
"oklab",
|
|
399
|
-
"xyz",
|
|
400
|
-
"xyz-d50",
|
|
401
|
-
"xyz-d65",
|
|
402
|
-
].some((t) => equalsIgnoreCase(t, token.val)));
|
|
391
|
+
colorFuncColorSpace.some((t) => equalsIgnoreCase(t, token.val)));
|
|
403
392
|
}
|
|
404
393
|
/**
|
|
405
394
|
* Is polar colorspace
|
|
@@ -494,7 +483,7 @@ function isColor(token, errors) {
|
|
|
494
483
|
action: "drop",
|
|
495
484
|
message: `Unexpected constant '${val}'`,
|
|
496
485
|
node: value,
|
|
497
|
-
location: value[LOC],
|
|
486
|
+
// location: options.source!.getSourLocation(value[LOC]!.sta),
|
|
498
487
|
});
|
|
499
488
|
return false;
|
|
500
489
|
}
|
|
@@ -524,7 +513,7 @@ function isColor(token, errors) {
|
|
|
524
513
|
action: "drop",
|
|
525
514
|
message: `Unexpected constant '${val}'`,
|
|
526
515
|
node: v.value,
|
|
527
|
-
location: v.value[LOC],
|
|
516
|
+
// location: options.source!.getSourLocation(v.value[LOC]!.sta),
|
|
528
517
|
});
|
|
529
518
|
return false;
|
|
530
519
|
}
|
|
@@ -572,7 +561,7 @@ function isColor(token, errors) {
|
|
|
572
561
|
action: "drop",
|
|
573
562
|
message: "adding percentage and number is not allowed",
|
|
574
563
|
node: token,
|
|
575
|
-
location: token[LOC],
|
|
564
|
+
// location: options.source!.getSourLocation(token[LOC]!.sta),
|
|
576
565
|
});
|
|
577
566
|
return false;
|
|
578
567
|
}
|
|
@@ -600,9 +589,9 @@ function isColor(token, errors) {
|
|
|
600
589
|
if (children.length <= offset + 1) {
|
|
601
590
|
errors?.push({
|
|
602
591
|
action: "drop",
|
|
603
|
-
message: `Invalid color
|
|
592
|
+
message: `Invalid color`,
|
|
604
593
|
node: token,
|
|
605
|
-
location: token[LOC],
|
|
594
|
+
// location: options.source!.getSourLocation(token[LOC]!.sta),
|
|
606
595
|
});
|
|
607
596
|
return false;
|
|
608
597
|
}
|
|
@@ -1073,10 +1062,12 @@ function parseDimension(name) {
|
|
|
1073
1062
|
if (index < 0) {
|
|
1074
1063
|
return null;
|
|
1075
1064
|
}
|
|
1065
|
+
const unit = name.slice(index);
|
|
1076
1066
|
const dimension = {
|
|
1077
1067
|
typ: EnumToken.DimensionTokenType,
|
|
1078
1068
|
val: +name.slice(0, index),
|
|
1079
|
-
|
|
1069
|
+
// @ts-ignore
|
|
1070
|
+
unit: getSyntaxConfig().units.find((u) => equalsIgnoreCase(u, unit)) || unit.toLowerCase(),
|
|
1080
1071
|
};
|
|
1081
1072
|
if (Number.isNaN(dimension.val)) {
|
|
1082
1073
|
return null;
|