@tbela99/css-parser 1.4.8 → 1.4.10
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 +32 -3
- package/README.md +1 -1
- package/dist/index-umd-web.js +12950 -13310
- package/dist/index.cjs +16447 -16809
- package/dist/index.d.ts +2481 -1754
- 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/math/math.js +2 -1
- package/dist/lib/ast/minify.js +34 -5
- package/dist/lib/ast/transform/compute.js +2 -1
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/utils.js +29 -21
- package/dist/lib/ast/types.js +9 -66
- package/dist/lib/fs/resolve.js +1 -16
- package/dist/lib/parser/declaration/list.js +6 -1
- package/dist/lib/parser/{linemap.js → linesmap.js} +25 -9
- package/dist/lib/parser/parse.js +1264 -151
- package/dist/lib/parser/source.js +48 -17
- 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 +14 -251
- 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 -87
- 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 +7 -7
- package/dist/lib/syntax/color/color.js +9 -27
- 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/relative-color.js +8 -1
- package/dist/lib/syntax/color/utils/distance.js +2 -1
- package/dist/lib/syntax/constants.js +2 -1
- package/dist/lib/syntax/syntax.js +96 -9
- package/dist/lib/validation/config.json.js +27 -6
- package/dist/lib/validation/match.js +42 -845
- package/dist/node.js +134 -9
- package/dist/web.js +133 -6
- package/llms.txt +73 -0
- package/package.json +13 -16
- package/dist/lib/parser/arena.js +0 -206
|
@@ -1,5 +1,5 @@
|
|
|
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';
|
|
@@ -345,7 +345,7 @@ function colorMix(...args) {
|
|
|
345
345
|
chi: values.map((v) => {
|
|
346
346
|
return {
|
|
347
347
|
typ: EnumToken.NumberTokenType,
|
|
348
|
-
val:
|
|
348
|
+
val: v,
|
|
349
349
|
};
|
|
350
350
|
}),
|
|
351
351
|
kin: ColorType.LCH,
|
|
@@ -366,7 +366,7 @@ function colorMix(...args) {
|
|
|
366
366
|
values.map((v) => {
|
|
367
367
|
return {
|
|
368
368
|
typ: EnumToken.NumberTokenType,
|
|
369
|
-
val:
|
|
369
|
+
val: v,
|
|
370
370
|
};
|
|
371
371
|
})),
|
|
372
372
|
kin: ColorType.COLOR,
|
|
@@ -404,18 +404,18 @@ function colorMix(...args) {
|
|
|
404
404
|
chi: values.map((v) => {
|
|
405
405
|
return {
|
|
406
406
|
typ: EnumToken.NumberTokenType,
|
|
407
|
-
val:
|
|
407
|
+
val: v,
|
|
408
408
|
};
|
|
409
409
|
}),
|
|
410
410
|
kin: ColorType[colorSpace.toUpperCase().replaceAll("-", "_")],
|
|
411
411
|
};
|
|
412
412
|
if (colorSpace == "hsl" || colorSpace == "hwb") {
|
|
413
413
|
// @ts-ignore
|
|
414
|
-
result.chi[0] = { typ: EnumToken.AngleTokenType, val:
|
|
414
|
+
result.chi[0] = { typ: EnumToken.AngleTokenType, val: result.chi[0].val * 360 };
|
|
415
415
|
// @ts-ignore
|
|
416
|
-
result.chi[1] = { typ: EnumToken.PercentageTokenType, val:
|
|
416
|
+
result.chi[1] = { typ: EnumToken.PercentageTokenType, val: result.chi[1].val * 100 };
|
|
417
417
|
// @ts-ignore
|
|
418
|
-
result.chi[2] = { typ: EnumToken.PercentageTokenType, val:
|
|
418
|
+
result.chi[2] = { typ: EnumToken.PercentageTokenType, val: result.chi[2].val * 100 };
|
|
419
419
|
}
|
|
420
420
|
return result;
|
|
421
421
|
}
|
|
@@ -11,7 +11,7 @@ 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 { lp32srgbvalues, p32srgbvalues, srgb2p3values } from './p3.js';
|
|
14
|
+
import { lp32srgbvalues, p32srgbvalues, srgb2lp3values, 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';
|
|
@@ -19,7 +19,7 @@ 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 } 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';
|
|
@@ -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;
|
|
@@ -524,21 +524,21 @@ function color2srgbvalues(token) {
|
|
|
524
524
|
break;
|
|
525
525
|
}
|
|
526
526
|
if (values.length == 4) {
|
|
527
|
-
values[3] =
|
|
527
|
+
values[3] = values[3];
|
|
528
528
|
}
|
|
529
529
|
return values;
|
|
530
530
|
}
|
|
531
531
|
function values2colortoken(values, to) {
|
|
532
532
|
values = srgb2srgbcolorspace(values, to);
|
|
533
533
|
const chi = [
|
|
534
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
535
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
536
|
-
{ 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] },
|
|
537
537
|
];
|
|
538
538
|
if (values.length == 4) {
|
|
539
539
|
chi.push({ typ: EnumToken.LiteralTokenType, val: "/" }, {
|
|
540
540
|
typ: EnumToken.PercentageTokenType,
|
|
541
|
-
val:
|
|
541
|
+
val: values[3] * 100,
|
|
542
542
|
});
|
|
543
543
|
}
|
|
544
544
|
const colorSpace = ColorType[to].toLowerCase().replaceAll("_", "-");
|
|
@@ -602,23 +602,5 @@ function getAngle(token) {
|
|
|
602
602
|
// @ts-ignore
|
|
603
603
|
return token.val / 360;
|
|
604
604
|
}
|
|
605
|
-
function toPrecisionValue(value, precision = colorPrecision) {
|
|
606
|
-
const div = Math.pow(10, precision);
|
|
607
|
-
value = Math.round(value * div) / div;
|
|
608
|
-
return Math.abs(value) < epsilon ? 0 : value;
|
|
609
|
-
}
|
|
610
|
-
function toPrecisionAngle(angle, precision = colorPrecision, correctValue = true) {
|
|
611
|
-
angle = toPrecisionValue(angle, precision);
|
|
612
|
-
if (correctValue && Math.abs(angle) >= 360) {
|
|
613
|
-
angle %= 360;
|
|
614
|
-
}
|
|
615
|
-
if (Math.abs(angle) < anglePrecision) {
|
|
616
|
-
angle = 0;
|
|
617
|
-
}
|
|
618
|
-
if (correctValue && angle < 0) {
|
|
619
|
-
angle += 360;
|
|
620
|
-
}
|
|
621
|
-
return angle;
|
|
622
|
-
}
|
|
623
605
|
|
|
624
|
-
export { cmyk2colorToken, color2colorToken, color2srgbvalues, convertColor, getAngle, getNumber, hex2colorToken, hsl2colorToken, hwb2colorToken, lab2colorToken, lch2colorToken, minmax, oklab2colorToken, oklch2colorToken, rgb2colorToken
|
|
606
|
+
export { cmyk2colorToken, color2colorToken, color2srgbvalues, convertColor, getAngle, getNumber, hex2colorToken, hsl2colorToken, hwb2colorToken, lab2colorToken, lch2colorToken, minmax, oklab2colorToken, oklch2colorToken, rgb2colorToken };
|
|
@@ -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 {
|
|
@@ -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
|
}
|
|
@@ -2,6 +2,7 @@ import { convertColor } 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';
|
|
5
|
+
import { toPrecisionValue } from '../../syntax.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Calculate the distance between two okLab colors.
|
|
@@ -27,7 +28,7 @@ function okLabDistance(color1, color2) {
|
|
|
27
28
|
if (okLab1[3] != null || okLab2[3] != null) {
|
|
28
29
|
diff.push((okLab1[3] ?? 1) - (okLab2[3] ?? 1));
|
|
29
30
|
}
|
|
30
|
-
return Math.hypot(...diff);
|
|
31
|
+
return toPrecisionValue(Math.hypot(...diff));
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* Check if two colors are close in okLab space.
|
|
@@ -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, colorPrecision, epsilon, anglePrecision } 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
|
|
@@ -482,7 +483,7 @@ function isColor(token, errors) {
|
|
|
482
483
|
action: "drop",
|
|
483
484
|
message: `Unexpected constant '${val}'`,
|
|
484
485
|
node: value,
|
|
485
|
-
location: value[LOC],
|
|
486
|
+
// location: options.source!.getSourLocation(value[LOC]!.sta),
|
|
486
487
|
});
|
|
487
488
|
return false;
|
|
488
489
|
}
|
|
@@ -512,7 +513,7 @@ function isColor(token, errors) {
|
|
|
512
513
|
action: "drop",
|
|
513
514
|
message: `Unexpected constant '${val}'`,
|
|
514
515
|
node: v.value,
|
|
515
|
-
location: v.value[LOC],
|
|
516
|
+
// location: options.source!.getSourLocation(v.value[LOC]!.sta),
|
|
516
517
|
});
|
|
517
518
|
return false;
|
|
518
519
|
}
|
|
@@ -560,7 +561,7 @@ function isColor(token, errors) {
|
|
|
560
561
|
action: "drop",
|
|
561
562
|
message: "adding percentage and number is not allowed",
|
|
562
563
|
node: token,
|
|
563
|
-
location: token[LOC],
|
|
564
|
+
// location: options.source!.getSourLocation(token[LOC]!.sta),
|
|
564
565
|
});
|
|
565
566
|
return false;
|
|
566
567
|
}
|
|
@@ -588,9 +589,9 @@ function isColor(token, errors) {
|
|
|
588
589
|
if (children.length <= offset + 1) {
|
|
589
590
|
errors?.push({
|
|
590
591
|
action: "drop",
|
|
591
|
-
message: `Invalid color
|
|
592
|
+
message: `Invalid color`,
|
|
592
593
|
node: token,
|
|
593
|
-
location: token[LOC],
|
|
594
|
+
// location: options.source!.getSourLocation(token[LOC]!.sta),
|
|
594
595
|
});
|
|
595
596
|
return false;
|
|
596
597
|
}
|
|
@@ -1061,10 +1062,12 @@ function parseDimension(name) {
|
|
|
1061
1062
|
if (index < 0) {
|
|
1062
1063
|
return null;
|
|
1063
1064
|
}
|
|
1065
|
+
const unit = name.slice(index);
|
|
1064
1066
|
const dimension = {
|
|
1065
1067
|
typ: EnumToken.DimensionTokenType,
|
|
1066
1068
|
val: +name.slice(0, index),
|
|
1067
|
-
|
|
1069
|
+
// @ts-ignore
|
|
1070
|
+
unit: getSyntaxConfig().units.find((u) => equalsIgnoreCase(u, unit)) || unit.toLowerCase(),
|
|
1068
1071
|
};
|
|
1069
1072
|
if (Number.isNaN(dimension.val)) {
|
|
1070
1073
|
return null;
|
|
@@ -1137,5 +1140,89 @@ function isWhiteSpace(codepoint) {
|
|
|
1137
1140
|
codepoint == 0x2028 ||
|
|
1138
1141
|
codepoint == 0x2029);
|
|
1139
1142
|
}
|
|
1143
|
+
// https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Values_and_units#absolute_length_units
|
|
1144
|
+
/**
|
|
1145
|
+
* Convert length to px
|
|
1146
|
+
* @param value
|
|
1147
|
+
* @returns
|
|
1148
|
+
*/
|
|
1149
|
+
function length2Px(value) {
|
|
1150
|
+
let result = null;
|
|
1151
|
+
if (value.typ == EnumToken.NumberTokenType) {
|
|
1152
|
+
result = +value.val;
|
|
1153
|
+
}
|
|
1154
|
+
else {
|
|
1155
|
+
switch (value.unit) {
|
|
1156
|
+
case "cm":
|
|
1157
|
+
// @ts-ignore
|
|
1158
|
+
result = value.val * 37.8;
|
|
1159
|
+
break;
|
|
1160
|
+
case "mm":
|
|
1161
|
+
// @ts-ignore
|
|
1162
|
+
result = value.val * 3.78;
|
|
1163
|
+
break;
|
|
1164
|
+
case "Q":
|
|
1165
|
+
// @ts-ignore
|
|
1166
|
+
result = (value.val * 37.8) / 40;
|
|
1167
|
+
break;
|
|
1168
|
+
case "in":
|
|
1169
|
+
// @ts-ignore
|
|
1170
|
+
result = value.val / 96;
|
|
1171
|
+
break;
|
|
1172
|
+
case "pc":
|
|
1173
|
+
// @ts-ignore
|
|
1174
|
+
result = value.val / 16;
|
|
1175
|
+
break;
|
|
1176
|
+
case "pt":
|
|
1177
|
+
// @ts-ignore
|
|
1178
|
+
result = (value.val * 4) / 3;
|
|
1179
|
+
break;
|
|
1180
|
+
case "px":
|
|
1181
|
+
result = +value.val;
|
|
1182
|
+
break;
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
return isNaN(result) ? null : result;
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* minify number
|
|
1189
|
+
* @param val
|
|
1190
|
+
*/
|
|
1191
|
+
function minifyNumber(val) {
|
|
1192
|
+
val = String(toPrecisionValue(val));
|
|
1193
|
+
if (val === "0") {
|
|
1194
|
+
return "0";
|
|
1195
|
+
}
|
|
1196
|
+
const chr = val.charAt(0);
|
|
1197
|
+
if (chr == "-") {
|
|
1198
|
+
const slice = val.slice(0, 2);
|
|
1199
|
+
if (slice == "-0") {
|
|
1200
|
+
return val.length == 2 ? "0" : "-" + val.slice(2);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
if (chr == "0") {
|
|
1204
|
+
return val.slice(1);
|
|
1205
|
+
}
|
|
1206
|
+
return val;
|
|
1207
|
+
}
|
|
1208
|
+
function toPrecisionValue(value, precision = colorPrecision) {
|
|
1209
|
+
const div = Math.pow(10, precision);
|
|
1210
|
+
// @ts-ignore
|
|
1211
|
+
value = Math.round(value * div) / div;
|
|
1212
|
+
return Math.abs(value) < epsilon ? 0 : value;
|
|
1213
|
+
}
|
|
1214
|
+
function toPrecisionAngle(angle, precision = colorPrecision, correctValue = true) {
|
|
1215
|
+
angle = toPrecisionValue(angle, precision);
|
|
1216
|
+
if (correctValue && Math.abs(angle) >= 360) {
|
|
1217
|
+
angle %= 360;
|
|
1218
|
+
}
|
|
1219
|
+
if (Math.abs(angle) < anglePrecision) {
|
|
1220
|
+
angle = 0;
|
|
1221
|
+
}
|
|
1222
|
+
if (correctValue && angle < 0) {
|
|
1223
|
+
angle += 360;
|
|
1224
|
+
}
|
|
1225
|
+
return angle;
|
|
1226
|
+
}
|
|
1140
1227
|
|
|
1141
|
-
export { dimensionUnits, isAngle, isColor, isDigit, isFlex, isFrequency, isFunction, isHash, isHexColor, isIdent, isIdentCodepoint, isIdentColor, isIdentStart, isLength, isLetter, isNewLine, isNumber, isPercentage, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolution, isTime, isWhiteSpace, parseColor, parseDimension, pseudoAliasMap, reduceColorStops, reduceConicColorStops, reducegradientBackgroundPosition, renamedStandardProperties };
|
|
1228
|
+
export { dimensionUnits, isAngle, isColor, isDigit, isFlex, isFrequency, isFunction, isHash, isHexColor, isIdent, isIdentCodepoint, isIdentColor, isIdentStart, isLength, isLetter, isNewLine, isNumber, isPercentage, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolution, isTime, isWhiteSpace, length2Px, minifyNumber, parseColor, parseDimension, pseudoAliasMap, reduceColorStops, reduceConicColorStops, reducegradientBackgroundPosition, renamedStandardProperties, toPrecisionAngle, toPrecisionValue };
|
|
@@ -914,11 +914,14 @@ var declarations = {
|
|
|
914
914
|
"flex-grow": {
|
|
915
915
|
syntax: "<number>"
|
|
916
916
|
},
|
|
917
|
+
"flex-line-count": {
|
|
918
|
+
syntax: "<integer [1,∞]>"
|
|
919
|
+
},
|
|
917
920
|
"flex-shrink": {
|
|
918
921
|
syntax: "<number>"
|
|
919
922
|
},
|
|
920
923
|
"flex-wrap": {
|
|
921
|
-
syntax: "nowrap | wrap | wrap-reverse"
|
|
924
|
+
syntax: "nowrap | [ wrap | wrap-reverse ] || balance"
|
|
922
925
|
},
|
|
923
926
|
float: {
|
|
924
927
|
syntax: "left | right | none | inline-start | inline-end"
|
|
@@ -1184,6 +1187,9 @@ var declarations = {
|
|
|
1184
1187
|
"line-height-step": {
|
|
1185
1188
|
syntax: "<length>"
|
|
1186
1189
|
},
|
|
1190
|
+
"link-parameters": {
|
|
1191
|
+
syntax: "none | <param()>#"
|
|
1192
|
+
},
|
|
1187
1193
|
"list-style": {
|
|
1188
1194
|
syntax: "<'list-style-type'> || <'list-style-position'> || <'list-style-image'>"
|
|
1189
1195
|
},
|
|
@@ -1481,6 +1487,9 @@ var declarations = {
|
|
|
1481
1487
|
"paint-order": {
|
|
1482
1488
|
syntax: "normal | [ fill || stroke || markers ]"
|
|
1483
1489
|
},
|
|
1490
|
+
"path-length": {
|
|
1491
|
+
syntax: "none | <length> [0,∞]"
|
|
1492
|
+
},
|
|
1484
1493
|
perspective: {
|
|
1485
1494
|
syntax: "none | <length>"
|
|
1486
1495
|
},
|
|
@@ -1776,7 +1785,7 @@ var declarations = {
|
|
|
1776
1785
|
syntax: "<color>"
|
|
1777
1786
|
},
|
|
1778
1787
|
"text-decoration-inset": {
|
|
1779
|
-
syntax: "<length>{1,2} | auto"
|
|
1788
|
+
syntax: "<length-percentage>{1,2} | auto"
|
|
1780
1789
|
},
|
|
1781
1790
|
"text-decoration-line": {
|
|
1782
1791
|
syntax: "none | [ underline || overline || line-through || blink ] | spelling-error | grammar-error"
|
|
@@ -2338,6 +2347,9 @@ var functions = {
|
|
|
2338
2347
|
"palette-mix": {
|
|
2339
2348
|
syntax: "palette-mix(<color-interpolation-method> , [ [normal | light | dark | <palette-identifier> | <palette-mix()> ] && <percentage [0,100]>? ]#{2})"
|
|
2340
2349
|
},
|
|
2350
|
+
param: {
|
|
2351
|
+
syntax: "mod( <dashed-ident>, <declaration-value>? )"
|
|
2352
|
+
},
|
|
2341
2353
|
path: {
|
|
2342
2354
|
syntax: "path( <'fill-rule'>? , <string> )"
|
|
2343
2355
|
},
|
|
@@ -2929,7 +2941,7 @@ var syntaxes = {
|
|
|
2929
2941
|
syntax: "[ historical-ligatures | no-historical-ligatures ]"
|
|
2930
2942
|
},
|
|
2931
2943
|
"hsl()": {
|
|
2932
|
-
syntax: "hsl( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsl( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? ) | hsl(from <color> [ <hue> | none | h | s | l ] <relative-hsl-component>{2} [ / [ <alpha-value> | none]
|
|
2944
|
+
syntax: "hsl( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsl( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? ) | hsl(from <color> [ <hue> | none | h | s | l ] <relative-hsl-component>{2} [ / [ <alpha-value> | none] ]? )"
|
|
2933
2945
|
},
|
|
2934
2946
|
"hsla()": {
|
|
2935
2947
|
syntax: "hsla( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsla( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? ) | hsla(from <color> < [ <hue> | none | h | s | l ] <relative-hsl-component>{2} [ / [ <alpha-value> | none ] ]? )"
|
|
@@ -2944,7 +2956,7 @@ var syntaxes = {
|
|
|
2944
2956
|
syntax: "hue-rotate( [ <angle> | <zero> ]? )"
|
|
2945
2957
|
},
|
|
2946
2958
|
"hwb()": {
|
|
2947
|
-
syntax: "hwb( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? ) | hwb(from <color> [ <hue> | none | h | w | b ] <relative-hwb-component>{2} [ / [ <alpha-value> | none]
|
|
2959
|
+
syntax: "hwb( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? ) | hwb(from <color> [ <hue> | none | h | w | b ] <relative-hwb-component>{2} [ / [ <alpha-value> | none] ]? )"
|
|
2948
2960
|
},
|
|
2949
2961
|
"hypot()": {
|
|
2950
2962
|
syntax: "hypot( <calc-sum># )"
|
|
@@ -3319,7 +3331,7 @@ var syntaxes = {
|
|
|
3319
3331
|
syntax: "reversed( <counter-name> )"
|
|
3320
3332
|
},
|
|
3321
3333
|
"rgb()": {
|
|
3322
|
-
syntax: "rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? ) | rgb( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? ) | rgb(from <color> <relative-rgb-component>{3} [ / [ <alpha-value> | none]
|
|
3334
|
+
syntax: "rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? ) | rgb( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? ) | rgb(from <color> <relative-rgb-component>{3} [ / [ <alpha-value> | none] ]? )"
|
|
3323
3335
|
},
|
|
3324
3336
|
"rgba()": {
|
|
3325
3337
|
syntax: "rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? ) | rgba( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? ) | rgba(from <color> <relative-rgb-component>{3} [ / [ <alpha-value> | none ] ]? )"
|
|
@@ -3888,8 +3900,17 @@ var syntaxes = {
|
|
|
3888
3900
|
"composes-selector": {
|
|
3889
3901
|
syntax: "<ident>+ [from [global&&<string>]]?"
|
|
3890
3902
|
},
|
|
3903
|
+
wcag2: {
|
|
3904
|
+
syntax: "wcag2 | wcag2([<number> | [ aa | aaa ] && large? ])"
|
|
3905
|
+
},
|
|
3906
|
+
"target-contrast": {
|
|
3907
|
+
syntax: "<wcag2>"
|
|
3908
|
+
},
|
|
3891
3909
|
"contrast-color()": {
|
|
3892
|
-
syntax: "contrast-color(<color> )"
|
|
3910
|
+
syntax: "contrast-color( [ [ <color> && [ tbd-fg | tbd-bg ] && <target-contrast>? ] | [ <color> && [ tbd-fg | tbd-bg ] && <target-contrast>, <color># ] ] )"
|
|
3911
|
+
},
|
|
3912
|
+
"color-layers()": {
|
|
3913
|
+
syntax: "color-layers([ <blend-mode>, ]? <color># )"
|
|
3893
3914
|
},
|
|
3894
3915
|
"font-feature-custom-ident": {
|
|
3895
3916
|
syntax: "<integer>"
|