@tbela99/css-parser 1.4.2 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +354 -4
- package/README.md +69 -1077
- package/dist/config.json.js +76 -3
- package/dist/index-umd-web.js +26838 -18743
- package/dist/index.cjs +26819 -18731
- package/dist/index.d.ts +2471 -1884
- package/dist/lib/ast/clone.js +46 -0
- package/dist/lib/ast/expand.js +90 -65
- package/dist/lib/ast/features/calc.js +86 -43
- package/dist/lib/ast/features/if.js +221 -0
- package/dist/lib/ast/features/index.js +1 -0
- package/dist/lib/ast/features/inlinecssvariables.js +33 -28
- package/dist/lib/ast/features/prefix.js +406 -44
- package/dist/lib/ast/features/shorthand.js +6 -9
- package/dist/lib/ast/features/transform.js +14 -15
- package/dist/lib/ast/find.js +175 -0
- package/dist/lib/ast/math/expression.js +145 -99
- package/dist/lib/ast/math/math.js +30 -41
- package/dist/lib/ast/minify.js +551 -232
- package/dist/lib/ast/transform/compute.js +82 -69
- package/dist/lib/ast/transform/matrix.js +12 -26
- package/dist/lib/ast/transform/minify.js +154 -150
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.js +1 -1
- package/dist/lib/ast/transform/scale.js +1 -1
- package/dist/lib/ast/transform/skew.js +1 -1
- package/dist/lib/ast/transform/translate.js +1 -1
- package/dist/lib/ast/transform/utils.js +3 -2
- package/dist/lib/ast/types.js +345 -30
- package/dist/lib/ast/walk.js +119 -64
- package/dist/lib/fs/resolve.js +94 -88
- package/dist/lib/parser/declaration/list.js +117 -26
- package/dist/lib/parser/declaration/map.js +141 -96
- package/dist/lib/parser/declaration/set.js +30 -25
- package/dist/lib/parser/parse.js +1810 -1739
- package/dist/lib/parser/tokenize.js +662 -403
- package/dist/lib/parser/utils/angle.js +29 -0
- package/dist/lib/parser/utils/at-rule-container.js +486 -0
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
- package/dist/lib/parser/utils/at-rule-generic.js +118 -0
- package/dist/lib/parser/utils/at-rule-import.js +393 -0
- package/dist/lib/parser/utils/at-rule-media.js +603 -0
- package/dist/lib/parser/utils/at-rule-support.js +431 -0
- package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
- package/dist/lib/parser/utils/at-rule.js +31 -0
- package/dist/lib/parser/utils/cache.js +19 -0
- package/dist/lib/parser/utils/config.js +1 -0
- package/dist/lib/parser/utils/declaration.js +672 -91
- package/dist/lib/parser/utils/hash.js +1 -1
- package/dist/lib/parser/utils/selector.js +518 -0
- package/dist/lib/parser/utils/text.js +17 -1
- package/dist/lib/parser/utils/token.js +104 -0
- package/dist/lib/parser/utils/type.js +29 -18
- package/dist/lib/renderer/render.js +870 -269
- package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
- package/dist/lib/syntax/color/a98rgb.js +8 -12
- package/dist/lib/syntax/color/alpha.js +64 -0
- package/dist/lib/syntax/color/cmyk.js +23 -21
- package/dist/lib/syntax/color/color-mix.js +311 -237
- package/dist/lib/syntax/color/color.js +98 -92
- package/dist/lib/syntax/color/hex.js +29 -33
- package/dist/lib/syntax/color/hsl.js +7 -14
- package/dist/lib/syntax/color/hwb.js +14 -27
- package/dist/lib/syntax/color/lab.js +23 -24
- package/dist/lib/syntax/color/lch.js +16 -18
- package/dist/lib/syntax/color/oklab.js +21 -40
- package/dist/lib/syntax/color/oklch.js +16 -18
- package/dist/lib/syntax/color/p3.js +0 -8
- package/dist/lib/syntax/color/rec2020.js +9 -13
- package/dist/lib/syntax/color/relativecolor.js +160 -48
- package/dist/lib/syntax/color/rgb.js +14 -18
- package/dist/lib/syntax/color/srgb.js +30 -29
- package/dist/lib/syntax/color/utils/color-type.js +18 -0
- package/dist/lib/syntax/color/utils/colorspace.js +46 -0
- package/dist/lib/syntax/color/utils/components.js +36 -16
- package/dist/lib/syntax/color/utils/distance.js +21 -11
- package/dist/lib/syntax/color/utils/make-color.js +56 -0
- package/dist/lib/syntax/color/xyz.js +10 -22
- package/dist/lib/syntax/color/xyzd50.js +6 -20
- package/dist/lib/syntax/constants.js +464 -0
- package/dist/lib/syntax/syntax.js +825 -592
- package/dist/lib/validation/config.js +72 -33
- package/dist/lib/validation/config.json.js +1185 -85
- package/dist/lib/validation/match.js +3120 -0
- package/dist/lib/validation/parser/parse.js +683 -935
- package/dist/lib/validation/parser/typedef.js +106 -0
- package/dist/lib/validation/utils/list.js +4 -11
- package/dist/lib/validation/utils/whitespace.js +2 -8
- package/dist/node.js +102 -57
- package/dist/web.js +100 -48
- package/package.json +31 -17
- package/dist/lib/syntax/color/utils/constants.js +0 -214
- package/dist/lib/syntax/utils.js +0 -70
- package/dist/lib/validation/at-rules/container.js +0 -342
- package/dist/lib/validation/at-rules/counter-style.js +0 -90
- package/dist/lib/validation/at-rules/custom-media.js +0 -50
- package/dist/lib/validation/at-rules/document.js +0 -89
- package/dist/lib/validation/at-rules/else.js +0 -5
- package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
- package/dist/lib/validation/at-rules/import.js +0 -150
- package/dist/lib/validation/at-rules/keyframes.js +0 -67
- package/dist/lib/validation/at-rules/layer.js +0 -41
- package/dist/lib/validation/at-rules/media.js +0 -255
- package/dist/lib/validation/at-rules/namespace.js +0 -81
- package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
- package/dist/lib/validation/at-rules/page.js +0 -100
- package/dist/lib/validation/at-rules/supports.js +0 -295
- package/dist/lib/validation/at-rules/when.js +0 -185
- package/dist/lib/validation/atrule.js +0 -184
- package/dist/lib/validation/selector.js +0 -36
- package/dist/lib/validation/syntax.js +0 -1073
- package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
- package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
- package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
- package/dist/lib/validation/syntaxes/family-name.js +0 -57
- package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
- package/dist/lib/validation/syntaxes/layer-name.js +0 -57
- package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
- package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
- package/dist/lib/validation/syntaxes/selector-list.js +0 -5
- package/dist/lib/validation/syntaxes/selector.js +0 -5
- package/dist/lib/validation/syntaxes/url.js +0 -40
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { convertColor } from '../color.js';
|
|
2
2
|
import { getOKLABComponents } from '../oklab.js';
|
|
3
3
|
import { ColorType } from '../../../ast/types.js';
|
|
4
|
-
import '
|
|
5
|
-
import '../../../ast/walk.js';
|
|
6
|
-
import '../../../parser/parse.js';
|
|
7
|
-
import '../../../parser/tokenize.js';
|
|
8
|
-
import '../../../parser/utils/config.js';
|
|
9
|
-
import './constants.js';
|
|
10
|
-
import '../../../renderer/sourcemap/lib/encode.js';
|
|
4
|
+
import { colorDistancePrecision } from '../../constants.js';
|
|
11
5
|
|
|
12
6
|
/**
|
|
13
7
|
* Calculate the distance between two okLab colors.
|
|
@@ -15,9 +9,20 @@ import '../../../renderer/sourcemap/lib/encode.js';
|
|
|
15
9
|
* @param okLab2
|
|
16
10
|
*
|
|
17
11
|
* @private
|
|
12
|
+
* {@link https://drafts.csswg.org/css-color-4/#comparing-color-values}
|
|
18
13
|
*/
|
|
19
|
-
function okLabDistance(
|
|
20
|
-
|
|
14
|
+
function okLabDistance(color1, color2) {
|
|
15
|
+
color1 = convertColor(color1, ColorType.OKLAB);
|
|
16
|
+
color2 = convertColor(color2, ColorType.OKLAB);
|
|
17
|
+
if (color1 == null || color2 == null) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const okLab1 = getOKLABComponents(color1);
|
|
21
|
+
const okLab2 = getOKLABComponents(color2);
|
|
22
|
+
if (okLab1 == null || okLab2 == null) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return Math.hypot(okLab1[0] - okLab2[0], okLab1[1] - okLab2[1], okLab1[2] - okLab2[2]);
|
|
21
26
|
}
|
|
22
27
|
/**
|
|
23
28
|
* Check if two colors are close in okLab space.
|
|
@@ -27,7 +32,7 @@ function okLabDistance(okLab1, okLab2) {
|
|
|
27
32
|
*
|
|
28
33
|
* @private
|
|
29
34
|
*/
|
|
30
|
-
function isOkLabClose(color1, color2, threshold =
|
|
35
|
+
function isOkLabClose(color1, color2, threshold = colorDistancePrecision) {
|
|
31
36
|
color1 = convertColor(color1, ColorType.OKLAB);
|
|
32
37
|
color2 = convertColor(color2, ColorType.OKLAB);
|
|
33
38
|
if (color1 == null || color2 == null) {
|
|
@@ -38,7 +43,12 @@ function isOkLabClose(color1, color2, threshold = .01) {
|
|
|
38
43
|
if (okLab1 == null || okLab2 == null) {
|
|
39
44
|
return false;
|
|
40
45
|
}
|
|
41
|
-
|
|
46
|
+
for (let i = 0; i < 3; i++) {
|
|
47
|
+
if (Math.abs(okLab1[i] - okLab2[i]) > threshold) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
export { isOkLabClose, okLabDistance };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { EnumToken, ColorType } from '../../../ast/types.js';
|
|
2
|
+
import { equalsIgnoreCase } from '../../../parser/utils/text.js';
|
|
3
|
+
import { minmax, getNumber } from '../color.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create a color token
|
|
7
|
+
* @param kind
|
|
8
|
+
* @param components
|
|
9
|
+
* @param alpha
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
function makeColor(kind, components, alpha) {
|
|
13
|
+
if (components.length < 3) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const alphaValue = alpha == null
|
|
17
|
+
? 1
|
|
18
|
+
: alpha.typ === EnumToken.IdenTokenType && equalsIgnoreCase(alpha.val, "none")
|
|
19
|
+
? 0
|
|
20
|
+
: minmax(getNumber(alpha), 0, 1);
|
|
21
|
+
components.length = 3;
|
|
22
|
+
if (alphaValue !== 1) {
|
|
23
|
+
components.push({ typ: EnumToken.NumberTokenType, val: alphaValue });
|
|
24
|
+
}
|
|
25
|
+
if (kind === ColorType.LIT || kind === ColorType.HEX) {
|
|
26
|
+
const val = "#" +
|
|
27
|
+
components.reduce((acc, token, index) => {
|
|
28
|
+
let value = getNumber(token);
|
|
29
|
+
if (index === 3) {
|
|
30
|
+
value *= 255;
|
|
31
|
+
}
|
|
32
|
+
return acc + Math.round(value).toString(16).padStart(2, "0");
|
|
33
|
+
}, "");
|
|
34
|
+
return {
|
|
35
|
+
typ: EnumToken.ColorTokenType,
|
|
36
|
+
val,
|
|
37
|
+
kin: ColorType.HEX,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const hasAlpha = components.length === 4;
|
|
41
|
+
let i = components.length;
|
|
42
|
+
while (--i > 0) {
|
|
43
|
+
components.splice(i, 0, { typ: EnumToken.WhitespaceTokenType });
|
|
44
|
+
}
|
|
45
|
+
if (hasAlpha) {
|
|
46
|
+
components[components.length - 2] = { typ: EnumToken.LiteralTokenType, val: "/" };
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
typ: EnumToken.ColorTokenType,
|
|
50
|
+
val: ColorType[kind].toLowerCase(),
|
|
51
|
+
chi: components,
|
|
52
|
+
kin: kind,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { makeColor };
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { multiplyMatrices } from './utils/matrix.js';
|
|
2
|
-
import './utils/constants.js';
|
|
3
|
-
import '../../ast/types.js';
|
|
4
|
-
import '../../ast/minify.js';
|
|
5
|
-
import '../../ast/walk.js';
|
|
6
|
-
import '../../parser/parse.js';
|
|
7
|
-
import '../../parser/tokenize.js';
|
|
8
|
-
import '../../parser/utils/config.js';
|
|
9
2
|
import { srgb2lsrgbvalues } from './srgb.js';
|
|
10
3
|
import { XYZ_D65_to_D50 } from './xyzd50.js';
|
|
11
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
12
4
|
|
|
13
5
|
function XYZ_to_lin_sRGB(x, y, z, alpha = null) {
|
|
14
6
|
// convert XYZ to linear-light sRGB
|
|
@@ -18,32 +10,28 @@ function XYZ_to_lin_sRGB(x, y, z, alpha = null) {
|
|
|
18
10
|
[705 / 12673, -2585 / 12673, 705 / 667],
|
|
19
11
|
];
|
|
20
12
|
const XYZ = [x, y, z]; // convert to XYZ
|
|
21
|
-
return multiplyMatrices(M, XYZ)
|
|
13
|
+
return multiplyMatrices(M, XYZ)
|
|
14
|
+
.map((v) => v)
|
|
15
|
+
.concat(alpha == null || alpha == 1 ? [] : [alpha]);
|
|
22
16
|
}
|
|
23
17
|
function XYZ_D50_to_D65(x, y, z) {
|
|
24
18
|
// Bradford chromatic adaptation from D50 to D65
|
|
25
19
|
const M = [
|
|
26
20
|
[0.9554734527042182, -0.023098536874261423, 0.0632593086610217],
|
|
27
21
|
[-0.028369706963208136, 1.0099954580058226, 0.021041398966943008],
|
|
28
|
-
[0.012314001688319899, -0.020507696433477912, 1.3303659366080753]
|
|
22
|
+
[0.012314001688319899, -0.020507696433477912, 1.3303659366080753],
|
|
29
23
|
];
|
|
30
24
|
const XYZ = [x, y, z];
|
|
31
|
-
return multiplyMatrices(M, XYZ);
|
|
25
|
+
return multiplyMatrices(M, XYZ);
|
|
32
26
|
}
|
|
33
27
|
// xyz d65
|
|
34
28
|
function srgb2xyz(r, g, b, alpha) {
|
|
35
29
|
[r, g, b] = srgb2lsrgbvalues(r, g, b);
|
|
36
30
|
// xyx d65
|
|
37
31
|
let rgb = [
|
|
38
|
-
0.4123907992659595 * r +
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
0.21263900587151036 * r +
|
|
42
|
-
0.7151686787677559 * g +
|
|
43
|
-
0.07219231536073371 * b,
|
|
44
|
-
0.01933081871559185 * r +
|
|
45
|
-
0.11919477979462599 * g +
|
|
46
|
-
0.9505321522496606 * b
|
|
32
|
+
0.4123907992659595 * r + 0.35758433938387796 * g + 0.1804807884018343 * b,
|
|
33
|
+
0.21263900587151036 * r + 0.7151686787677559 * g + 0.07219231536073371 * b,
|
|
34
|
+
0.01933081871559185 * r + 0.11919477979462599 * g + 0.9505321522496606 * b,
|
|
47
35
|
];
|
|
48
36
|
if (alpha != null && alpha != 1) {
|
|
49
37
|
rgb.push(alpha);
|
|
@@ -51,7 +39,7 @@ function srgb2xyz(r, g, b, alpha) {
|
|
|
51
39
|
return rgb;
|
|
52
40
|
}
|
|
53
41
|
// xyz d50
|
|
54
|
-
function
|
|
42
|
+
function srgb2xyz_d65(r, g, b, alpha) {
|
|
55
43
|
// xyx d65
|
|
56
44
|
// @ts-ignore
|
|
57
45
|
let rgb = XYZ_D65_to_D50(...srgb2xyz(r, g, b));
|
|
@@ -61,4 +49,4 @@ function srgb2xyz_d50(r, g, b, alpha) {
|
|
|
61
49
|
return rgb;
|
|
62
50
|
}
|
|
63
51
|
|
|
64
|
-
export { XYZ_D50_to_D65, XYZ_to_lin_sRGB, srgb2xyz,
|
|
52
|
+
export { XYZ_D50_to_D65, XYZ_to_lin_sRGB, srgb2xyz, srgb2xyz_d65 };
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import { lsrgb2srgbvalues } from './srgb.js';
|
|
2
2
|
import { multiplyMatrices } from './utils/matrix.js';
|
|
3
|
-
import './utils/constants.js';
|
|
4
|
-
import '../../ast/types.js';
|
|
5
|
-
import '../../ast/minify.js';
|
|
6
|
-
import '../../ast/walk.js';
|
|
7
|
-
import '../../parser/parse.js';
|
|
8
|
-
import '../../parser/tokenize.js';
|
|
9
|
-
import '../../parser/utils/config.js';
|
|
10
3
|
import { xyz2lab } from './lab.js';
|
|
11
|
-
import { labvalues2lchvalues } from './lch.js';
|
|
12
4
|
import { XYZ_D50_to_D65 } from './xyz.js';
|
|
13
|
-
import '
|
|
5
|
+
import { labvalues2lchvalues } from './lch.js';
|
|
14
6
|
|
|
15
7
|
/*
|
|
16
|
-
*/
|
|
8
|
+
*/
|
|
17
9
|
function xyzd502lch(x, y, z, alpha) {
|
|
18
10
|
// @ts-ignore
|
|
19
11
|
const [l, a, b] = xyz2lab(...XYZ_D50_to_D65(x, y, z));
|
|
@@ -30,7 +22,7 @@ function XYZ_D65_to_D50(x, y, z, alpha = null) {
|
|
|
30
22
|
let M = [
|
|
31
23
|
[1.0479297925449969, 0.022946870601609652, -0.05019226628920524],
|
|
32
24
|
[0.02962780877005599, 0.9904344267538799, -0.017073799063418826],
|
|
33
|
-
[-0.009243040646204504, 0.015055191490298152, 0.7518742814281371]
|
|
25
|
+
[-0.009243040646204504, 0.015055191490298152, 0.7518742814281371],
|
|
34
26
|
];
|
|
35
27
|
return multiplyMatrices(M, [x, y, z]).concat(alpha == null || alpha == 1 ? [] : [alpha]);
|
|
36
28
|
}
|
|
@@ -38,17 +30,11 @@ function xyzd502srgb(x, y, z, alpha = null) {
|
|
|
38
30
|
// @ts-ignore
|
|
39
31
|
return lsrgb2srgbvalues(
|
|
40
32
|
/* r: */
|
|
41
|
-
x * 3.1341359569958707 -
|
|
42
|
-
y * 1.6173863321612538 -
|
|
43
|
-
0.4906619460083532 * z,
|
|
33
|
+
x * 3.1341359569958707 - y * 1.6173863321612538 - 0.4906619460083532 * z,
|
|
44
34
|
/* g: */
|
|
45
|
-
x * -0.978795502912089 +
|
|
46
|
-
y * 1.916254567259524 +
|
|
47
|
-
0.03344273116131949 * z,
|
|
35
|
+
x * -0.978795502912089 + y * 1.916254567259524 + 0.03344273116131949 * z,
|
|
48
36
|
/* b: */
|
|
49
|
-
x * 0.07195537988411677 -
|
|
50
|
-
y * 0.2289768264158322 +
|
|
51
|
-
1.405386058324125 * z, alpha);
|
|
37
|
+
x * 0.07195537988411677 - y * 0.2289768264158322 + 1.405386058324125 * z, alpha);
|
|
52
38
|
}
|
|
53
39
|
|
|
54
40
|
export { XYZ_D65_to_D50, xyzd502lch, xyzd502srgb };
|
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { EnumToken } from '../ast/types.js';
|
|
2
|
+
import config from '../validation/config.json.js';
|
|
3
|
+
|
|
4
|
+
const regMatchLinearGradient = /^-((webkit)|o|moz)(-repeating)?-linear-gradient$/i;
|
|
5
|
+
const regMatchRadialGradient = /^-((webkit)|o|moz)(-repeating)?-radial-gradient$/i;
|
|
6
|
+
const mFLT = new Set([EnumToken.LtTokenType, EnumToken.LteTokenType]);
|
|
7
|
+
const mFGT = new Set([EnumToken.GtTokenType, EnumToken.GteTokenType]);
|
|
8
|
+
const tokensMap = new Map([
|
|
9
|
+
[EnumToken.Star, EnumToken.Mul],
|
|
10
|
+
[EnumToken.Plus, EnumToken.Add],
|
|
11
|
+
]);
|
|
12
|
+
const urlTokenMatcher = /^(["']?)[a-zA-Z0-9_/.-][a-zA-Z0-9_/:.#?-]+(\1)$/;
|
|
13
|
+
const tokensfuncDefMap = new Map([
|
|
14
|
+
[EnumToken.FunctionTokenDefType, EnumToken.FunctionTokenType],
|
|
15
|
+
[EnumToken.ColorFunctionTokenDefType, EnumToken.ColorTokenType],
|
|
16
|
+
[EnumToken.UrlFunctionTokenDefType, EnumToken.UrlFunctionTokenType],
|
|
17
|
+
[EnumToken.MathFunctionTokenDefType, EnumToken.MathFunctionTokenType],
|
|
18
|
+
[EnumToken.ImageFunctionTokenDefType, EnumToken.ImageFunctionTokenType],
|
|
19
|
+
[EnumToken.TimingFunctionTokenDefType, EnumToken.TimingFunctionTokenType],
|
|
20
|
+
[EnumToken.CustomFunctionTokenDefType, EnumToken.CustomFunctionTokenType],
|
|
21
|
+
[EnumToken.WildCardFunctionTokenDefType, EnumToken.WildCardFunctionTokenType],
|
|
22
|
+
[EnumToken.TimelineFunctionTokenDefType, EnumToken.TimelineFunctionTokenType],
|
|
23
|
+
[EnumToken.GridTemplateFuncTokenDefType, EnumToken.GridTemplateFuncTokenType],
|
|
24
|
+
[EnumToken.SupportsFunctionTokenDefType, EnumToken.SupportsFunctionTokenType],
|
|
25
|
+
[EnumToken.WhenElseFunctionTokenDefType, EnumToken.WhenElseFunctionTokenType],
|
|
26
|
+
[EnumToken.ContainerFunctionTokenDefType, EnumToken.ContainerFunctionTokenType],
|
|
27
|
+
[EnumToken.PseudoClassFunctionTokenDefType, EnumToken.PseudoClassFuncTokenType],
|
|
28
|
+
[EnumToken.TransformFunctionTokenDefType, EnumToken.TransformFunctionTokenType],
|
|
29
|
+
[EnumToken.GeneralEnclosedFunctionTokenDefType, EnumToken.GeneralEnclosedFunctionTokenType],
|
|
30
|
+
]);
|
|
31
|
+
const tokensfuncSet = new Set(tokensfuncDefMap.values());
|
|
32
|
+
/**
|
|
33
|
+
* Epsilon
|
|
34
|
+
*/
|
|
35
|
+
const epsilon = 1e-5;
|
|
36
|
+
/**
|
|
37
|
+
* Color distance precision
|
|
38
|
+
*/
|
|
39
|
+
const colorDistancePrecision = epsilon;
|
|
40
|
+
/**
|
|
41
|
+
* Color precision
|
|
42
|
+
*/
|
|
43
|
+
const colorPrecision = 6;
|
|
44
|
+
/**
|
|
45
|
+
* Angle precision
|
|
46
|
+
*/
|
|
47
|
+
const anglePrecision = 0.001;
|
|
48
|
+
/**
|
|
49
|
+
* Color range definitions
|
|
50
|
+
*/
|
|
51
|
+
const colorRange = {
|
|
52
|
+
lab: {
|
|
53
|
+
l: [0, 100],
|
|
54
|
+
a: [-125, 125],
|
|
55
|
+
b: [-125, 125],
|
|
56
|
+
},
|
|
57
|
+
lch: {
|
|
58
|
+
l: [0, 100],
|
|
59
|
+
c: [0, 150],
|
|
60
|
+
h: [0, 360],
|
|
61
|
+
},
|
|
62
|
+
oklab: {
|
|
63
|
+
l: [0, 1],
|
|
64
|
+
a: [-0.4, 0.4],
|
|
65
|
+
b: [-0.4, 0.4],
|
|
66
|
+
},
|
|
67
|
+
oklch: {
|
|
68
|
+
l: [0, 1],
|
|
69
|
+
a: [0, 0.4],
|
|
70
|
+
b: [0, 0.4],
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
const wildCardFuncs = ["var", "env", "if"];
|
|
74
|
+
const mathFuncs = [
|
|
75
|
+
"minmax",
|
|
76
|
+
"repeat",
|
|
77
|
+
"fit-content",
|
|
78
|
+
"calc",
|
|
79
|
+
"clamp",
|
|
80
|
+
"min",
|
|
81
|
+
"max",
|
|
82
|
+
"round",
|
|
83
|
+
"mod",
|
|
84
|
+
"rem",
|
|
85
|
+
"sin",
|
|
86
|
+
"cos",
|
|
87
|
+
"tan",
|
|
88
|
+
"asin",
|
|
89
|
+
"acos",
|
|
90
|
+
"atan",
|
|
91
|
+
"atan2",
|
|
92
|
+
"pow",
|
|
93
|
+
"sqrt",
|
|
94
|
+
"hypot",
|
|
95
|
+
"log",
|
|
96
|
+
"exp",
|
|
97
|
+
"abs",
|
|
98
|
+
"sign",
|
|
99
|
+
"anchor",
|
|
100
|
+
];
|
|
101
|
+
// export const fontFormat: string[] = ['collection', 'embedded-opentype', 'opentype', 'svg', 'truetype', 'woff', 'woff2'];
|
|
102
|
+
// export const colorFontTech: string[] = ['color-colrv0', 'color-colrv1', 'color-svg', 'color-sbix', 'color-cbdt'];
|
|
103
|
+
// export const fontFeaturesTech: string[] = ['features-opentype', 'features-aat', 'features-graphite', 'incremental-patch', 'incremental-range', 'incremental-auto', 'variations', 'palettes'];
|
|
104
|
+
// https://drafts.csswg.org/mediaqueries/#media-types
|
|
105
|
+
const mediaTypes = [
|
|
106
|
+
"all",
|
|
107
|
+
"print",
|
|
108
|
+
"screen",
|
|
109
|
+
/* deprecated */
|
|
110
|
+
"aural",
|
|
111
|
+
"braille",
|
|
112
|
+
"embossed",
|
|
113
|
+
"handheld",
|
|
114
|
+
"projection",
|
|
115
|
+
"tty",
|
|
116
|
+
"tv",
|
|
117
|
+
"speech",
|
|
118
|
+
];
|
|
119
|
+
const pageMarginBoxType = new Set([
|
|
120
|
+
"top-left-corner",
|
|
121
|
+
"top-left",
|
|
122
|
+
"top-center",
|
|
123
|
+
"top-right",
|
|
124
|
+
"top-right-corner",
|
|
125
|
+
"bottom-left-corner",
|
|
126
|
+
"bottom-left",
|
|
127
|
+
"bottom-center",
|
|
128
|
+
"bottom-right",
|
|
129
|
+
"bottom-right-corner",
|
|
130
|
+
"left-top",
|
|
131
|
+
"left-middle",
|
|
132
|
+
"left-bottom",
|
|
133
|
+
"right-top",
|
|
134
|
+
"right-middle",
|
|
135
|
+
"right-bottom",
|
|
136
|
+
]);
|
|
137
|
+
const urlFunc = ["url"];
|
|
138
|
+
const timelineFunc = ["view", "scroll"];
|
|
139
|
+
const gridTemplateFunc = ["minmax", "fit-content", "repeat"];
|
|
140
|
+
const generalEnclosedFunc = [];
|
|
141
|
+
const supportFunc = ["selector", "font-tech", "font-format", "at-rule", "named-feature"];
|
|
142
|
+
const whenElseFunc = ["media", "supports"];
|
|
143
|
+
const containerFunc = ["style", "scroll-state"];
|
|
144
|
+
const timingFunc = [
|
|
145
|
+
"ease",
|
|
146
|
+
"ease-in",
|
|
147
|
+
"ease-out",
|
|
148
|
+
"ease-in-out",
|
|
149
|
+
"linear",
|
|
150
|
+
"step-start",
|
|
151
|
+
"step-end",
|
|
152
|
+
"steps",
|
|
153
|
+
"cubic-bezier",
|
|
154
|
+
];
|
|
155
|
+
const colorsFunc = [
|
|
156
|
+
"rgb",
|
|
157
|
+
"rgba",
|
|
158
|
+
"hsl",
|
|
159
|
+
"hsla",
|
|
160
|
+
"hwb",
|
|
161
|
+
"device-cmyk",
|
|
162
|
+
"color-mix",
|
|
163
|
+
"color",
|
|
164
|
+
"oklab",
|
|
165
|
+
"lab",
|
|
166
|
+
"oklch",
|
|
167
|
+
"lch",
|
|
168
|
+
"light-dark",
|
|
169
|
+
"contrast-color",
|
|
170
|
+
"alpha",
|
|
171
|
+
];
|
|
172
|
+
const imageFunc = [
|
|
173
|
+
"linear-gradient",
|
|
174
|
+
"radial-gradient",
|
|
175
|
+
"repeating-linear-gradient",
|
|
176
|
+
"repeating-radial-gradient",
|
|
177
|
+
"repeating-conic-gradient",
|
|
178
|
+
"conic-gradient",
|
|
179
|
+
"image",
|
|
180
|
+
"image-set",
|
|
181
|
+
"element",
|
|
182
|
+
"cross-fade",
|
|
183
|
+
"paint",
|
|
184
|
+
"-o-linear-gradient",
|
|
185
|
+
"-moz-linear-gradient",
|
|
186
|
+
"-webkit-linear-gradient",
|
|
187
|
+
"-webkit-repeating-linear-gradient",
|
|
188
|
+
"-webkit-gradient",
|
|
189
|
+
"-webkit-radial-gradient",
|
|
190
|
+
"-webkit-repeating-radial-gradient",
|
|
191
|
+
];
|
|
192
|
+
const transformFunctions = [
|
|
193
|
+
"translate",
|
|
194
|
+
"scale",
|
|
195
|
+
"rotate",
|
|
196
|
+
"skew",
|
|
197
|
+
"perspective",
|
|
198
|
+
"translateX",
|
|
199
|
+
"translateY",
|
|
200
|
+
"translateZ",
|
|
201
|
+
"scaleX",
|
|
202
|
+
"scaleY",
|
|
203
|
+
"scaleZ",
|
|
204
|
+
"rotateX",
|
|
205
|
+
"rotateY",
|
|
206
|
+
"rotateZ",
|
|
207
|
+
"skewX",
|
|
208
|
+
"skewY",
|
|
209
|
+
"rotate3d",
|
|
210
|
+
"translate3d",
|
|
211
|
+
"scale3d",
|
|
212
|
+
"matrix",
|
|
213
|
+
"matrix3d",
|
|
214
|
+
];
|
|
215
|
+
const funcLike = [
|
|
216
|
+
EnumToken.ParensTokenType,
|
|
217
|
+
EnumToken.FunctionTokenType,
|
|
218
|
+
EnumToken.UrlFunctionTokenType,
|
|
219
|
+
EnumToken.StartParensTokenType,
|
|
220
|
+
EnumToken.ImageFunctionTokenType,
|
|
221
|
+
EnumToken.TimingFunctionTokenType,
|
|
222
|
+
EnumToken.TimingFunctionTokenType,
|
|
223
|
+
EnumToken.PseudoClassFuncTokenType,
|
|
224
|
+
EnumToken.GridTemplateFuncTokenType,
|
|
225
|
+
];
|
|
226
|
+
const colorFuncColorSpace = [
|
|
227
|
+
"srgb",
|
|
228
|
+
"srgb-linear",
|
|
229
|
+
"display-p3",
|
|
230
|
+
"prophoto-rgb",
|
|
231
|
+
"a98-rgb",
|
|
232
|
+
"rec2020",
|
|
233
|
+
"xyz",
|
|
234
|
+
"xyz-d65",
|
|
235
|
+
"xyz-d50",
|
|
236
|
+
];
|
|
237
|
+
const D50 = [0.3457 / 0.3585, 1.0, (1.0 - 0.3457 - 0.3585) / 0.3585];
|
|
238
|
+
const k = Math.pow(29, 3) / Math.pow(3, 3);
|
|
239
|
+
const e = Math.pow(6, 3) / Math.pow(29, 3);
|
|
240
|
+
const nonStandardColors = new Set(config.syntaxes["-non-standard-color"].syntax.split(/[\s|]+/g).map((m) => m.toLowerCase()));
|
|
241
|
+
// color module v4
|
|
242
|
+
const systemColors = new Set([
|
|
243
|
+
"ActiveText",
|
|
244
|
+
"ButtonBorder",
|
|
245
|
+
"ButtonFace",
|
|
246
|
+
"ButtonText",
|
|
247
|
+
"Canvas",
|
|
248
|
+
"CanvasText",
|
|
249
|
+
"Field",
|
|
250
|
+
"FieldText",
|
|
251
|
+
"GrayText",
|
|
252
|
+
"Highlight",
|
|
253
|
+
"HighlightText",
|
|
254
|
+
"LinkText",
|
|
255
|
+
"Mark",
|
|
256
|
+
"MarkText",
|
|
257
|
+
"VisitedText",
|
|
258
|
+
"-webkit-focus-ring-color",
|
|
259
|
+
].map((m) => m.toLowerCase()));
|
|
260
|
+
// deprecated
|
|
261
|
+
const deprecatedSystemColors = new Set([
|
|
262
|
+
"ActiveBorder",
|
|
263
|
+
"ActiveCaption",
|
|
264
|
+
"AppWorkspace",
|
|
265
|
+
"Background",
|
|
266
|
+
"ButtonFace",
|
|
267
|
+
"ButtonHighlight",
|
|
268
|
+
"ButtonShadow",
|
|
269
|
+
"ButtonText",
|
|
270
|
+
"CaptionText",
|
|
271
|
+
"GrayText",
|
|
272
|
+
"Highlight",
|
|
273
|
+
"HighlightText",
|
|
274
|
+
"InactiveBorder",
|
|
275
|
+
"InactiveCaption",
|
|
276
|
+
"InactiveCaptionText",
|
|
277
|
+
"InfoBackground",
|
|
278
|
+
"InfoText",
|
|
279
|
+
"Menu",
|
|
280
|
+
"MenuText",
|
|
281
|
+
"Scrollbar",
|
|
282
|
+
"ThreeDDarkShadow",
|
|
283
|
+
"ThreeDFace",
|
|
284
|
+
"ThreeDHighlight",
|
|
285
|
+
"ThreeDLightShadow",
|
|
286
|
+
"ThreeDShadow",
|
|
287
|
+
"Window",
|
|
288
|
+
"WindowFrame",
|
|
289
|
+
"WindowText",
|
|
290
|
+
].map((t) => t.toLowerCase()));
|
|
291
|
+
// name to color
|
|
292
|
+
const COLORS_NAMES = Object.seal({
|
|
293
|
+
aliceblue: "#f0f8ff",
|
|
294
|
+
antiquewhite: "#faebd7",
|
|
295
|
+
aqua: "#00ffff",
|
|
296
|
+
aquamarine: "#7fffd4",
|
|
297
|
+
azure: "#f0ffff",
|
|
298
|
+
beige: "#f5f5dc",
|
|
299
|
+
bisque: "#ffe4c4",
|
|
300
|
+
black: "#000000",
|
|
301
|
+
blanchedalmond: "#ffebcd",
|
|
302
|
+
blue: "#0000ff",
|
|
303
|
+
blueviolet: "#8a2be2",
|
|
304
|
+
brown: "#a52a2a",
|
|
305
|
+
burlywood: "#deb887",
|
|
306
|
+
cadetblue: "#5f9ea0",
|
|
307
|
+
chartreuse: "#7fff00",
|
|
308
|
+
chocolate: "#d2691e",
|
|
309
|
+
coral: "#ff7f50",
|
|
310
|
+
cornflowerblue: "#6495ed",
|
|
311
|
+
cornsilk: "#fff8dc",
|
|
312
|
+
crimson: "#dc143c",
|
|
313
|
+
cyan: "#00ffff",
|
|
314
|
+
darkblue: "#00008b",
|
|
315
|
+
darkcyan: "#008b8b",
|
|
316
|
+
darkgoldenrod: "#b8860b",
|
|
317
|
+
darkgray: "#a9a9a9",
|
|
318
|
+
darkgrey: "#a9a9a9",
|
|
319
|
+
darkgreen: "#006400",
|
|
320
|
+
darkkhaki: "#bdb76b",
|
|
321
|
+
darkmagenta: "#8b008b",
|
|
322
|
+
darkolivegreen: "#556b2f",
|
|
323
|
+
darkorange: "#ff8c00",
|
|
324
|
+
darkorchid: "#9932cc",
|
|
325
|
+
darkred: "#8b0000",
|
|
326
|
+
darksalmon: "#e9967a",
|
|
327
|
+
darkseagreen: "#8fbc8f",
|
|
328
|
+
darkslateblue: "#483d8b",
|
|
329
|
+
darkslategray: "#2f4f4f",
|
|
330
|
+
darkslategrey: "#2f4f4f",
|
|
331
|
+
darkturquoise: "#00ced1",
|
|
332
|
+
darkviolet: "#9400d3",
|
|
333
|
+
deeppink: "#ff1493",
|
|
334
|
+
deepskyblue: "#00bfff",
|
|
335
|
+
dimgray: "#696969",
|
|
336
|
+
dimgrey: "#696969",
|
|
337
|
+
dodgerblue: "#1e90ff",
|
|
338
|
+
firebrick: "#b22222",
|
|
339
|
+
floralwhite: "#fffaf0",
|
|
340
|
+
forestgreen: "#228b22",
|
|
341
|
+
fuchsia: "#ff00ff",
|
|
342
|
+
gainsboro: "#dcdcdc",
|
|
343
|
+
ghostwhite: "#f8f8ff",
|
|
344
|
+
gold: "#ffd700",
|
|
345
|
+
goldenrod: "#daa520",
|
|
346
|
+
gray: "#808080",
|
|
347
|
+
grey: "#808080",
|
|
348
|
+
green: "#008000",
|
|
349
|
+
greenyellow: "#adff2f",
|
|
350
|
+
honeydew: "#f0fff0",
|
|
351
|
+
hotpink: "#ff69b4",
|
|
352
|
+
indianred: "#cd5c5c",
|
|
353
|
+
indigo: "#4b0082",
|
|
354
|
+
ivory: "#fffff0",
|
|
355
|
+
khaki: "#f0e68c",
|
|
356
|
+
lavender: "#e6e6fa",
|
|
357
|
+
lavenderblush: "#fff0f5",
|
|
358
|
+
lawngreen: "#7cfc00",
|
|
359
|
+
lemonchiffon: "#fffacd",
|
|
360
|
+
lightblue: "#add8e6",
|
|
361
|
+
lightcoral: "#f08080",
|
|
362
|
+
lightcyan: "#e0ffff",
|
|
363
|
+
lightgoldenrodyellow: "#fafad2",
|
|
364
|
+
lightgray: "#d3d3d3",
|
|
365
|
+
lightgrey: "#d3d3d3",
|
|
366
|
+
lightgreen: "#90ee90",
|
|
367
|
+
lightpink: "#ffb6c1",
|
|
368
|
+
lightsalmon: "#ffa07a",
|
|
369
|
+
lightseagreen: "#20b2aa",
|
|
370
|
+
lightskyblue: "#87cefa",
|
|
371
|
+
lightslategray: "#778899",
|
|
372
|
+
lightslategrey: "#778899",
|
|
373
|
+
lightsteelblue: "#b0c4de",
|
|
374
|
+
lightyellow: "#ffffe0",
|
|
375
|
+
lime: "#00ff00",
|
|
376
|
+
limegreen: "#32cd32",
|
|
377
|
+
linen: "#faf0e6",
|
|
378
|
+
magenta: "#ff00ff",
|
|
379
|
+
maroon: "#800000",
|
|
380
|
+
mediumaquamarine: "#66cdaa",
|
|
381
|
+
mediumblue: "#0000cd",
|
|
382
|
+
mediumorchid: "#ba55d3",
|
|
383
|
+
mediumpurple: "#9370d8",
|
|
384
|
+
mediumseagreen: "#3cb371",
|
|
385
|
+
mediumslateblue: "#7b68ee",
|
|
386
|
+
mediumspringgreen: "#00fa9a",
|
|
387
|
+
mediumturquoise: "#48d1cc",
|
|
388
|
+
mediumvioletred: "#c71585",
|
|
389
|
+
midnightblue: "#191970",
|
|
390
|
+
mintcream: "#f5fffa",
|
|
391
|
+
mistyrose: "#ffe4e1",
|
|
392
|
+
moccasin: "#ffe4b5",
|
|
393
|
+
navajowhite: "#ffdead",
|
|
394
|
+
navy: "#000080",
|
|
395
|
+
oldlace: "#fdf5e6",
|
|
396
|
+
olive: "#808000",
|
|
397
|
+
olivedrab: "#6b8e23",
|
|
398
|
+
orange: "#ffa500",
|
|
399
|
+
orangered: "#ff4500",
|
|
400
|
+
orchid: "#da70d6",
|
|
401
|
+
palegoldenrod: "#eee8aa",
|
|
402
|
+
palegreen: "#98fb98",
|
|
403
|
+
paleturquoise: "#afeeee",
|
|
404
|
+
palevioletred: "#d87093",
|
|
405
|
+
papayawhip: "#ffefd5",
|
|
406
|
+
peachpuff: "#ffdab9",
|
|
407
|
+
peru: "#cd853f",
|
|
408
|
+
pink: "#ffc0cb",
|
|
409
|
+
plum: "#dda0dd",
|
|
410
|
+
powderblue: "#b0e0e6",
|
|
411
|
+
purple: "#800080",
|
|
412
|
+
red: "#ff0000",
|
|
413
|
+
rosybrown: "#bc8f8f",
|
|
414
|
+
royalblue: "#4169e1",
|
|
415
|
+
saddlebrown: "#8b4513",
|
|
416
|
+
salmon: "#fa8072",
|
|
417
|
+
sandybrown: "#f4a460",
|
|
418
|
+
seagreen: "#2e8b57",
|
|
419
|
+
seashell: "#fff5ee",
|
|
420
|
+
sienna: "#a0522d",
|
|
421
|
+
silver: "#c0c0c0",
|
|
422
|
+
skyblue: "#87ceeb",
|
|
423
|
+
slateblue: "#6a5acd",
|
|
424
|
+
slategray: "#708090",
|
|
425
|
+
slategrey: "#708090",
|
|
426
|
+
snow: "#fffafa",
|
|
427
|
+
springgreen: "#00ff7f",
|
|
428
|
+
steelblue: "#4682b4",
|
|
429
|
+
tan: "#d2b48c",
|
|
430
|
+
teal: "#008080",
|
|
431
|
+
thistle: "#d8bfd8",
|
|
432
|
+
tomato: "#ff6347",
|
|
433
|
+
turquoise: "#40e0d0",
|
|
434
|
+
violet: "#ee82ee",
|
|
435
|
+
wheat: "#f5deb3",
|
|
436
|
+
white: "#ffffff",
|
|
437
|
+
whitesmoke: "#f5f5f5",
|
|
438
|
+
yellow: "#ffff00",
|
|
439
|
+
yellowgreen: "#9acd32",
|
|
440
|
+
rebeccapurple: "#663399",
|
|
441
|
+
transparent: "#00000000",
|
|
442
|
+
});
|
|
443
|
+
// color to name
|
|
444
|
+
const NAMES_COLORS = Object.seal(Object.entries(COLORS_NAMES).reduce((acc, [key, value]) => {
|
|
445
|
+
acc[value] = key;
|
|
446
|
+
return acc;
|
|
447
|
+
}, Object.create(null)));
|
|
448
|
+
const trimTokenSpace = new Set([
|
|
449
|
+
EnumToken.Add,
|
|
450
|
+
EnumToken.Mul,
|
|
451
|
+
EnumToken.Div,
|
|
452
|
+
EnumToken.Sub,
|
|
453
|
+
EnumToken.ColonTokenType,
|
|
454
|
+
EnumToken.CommaTokenType,
|
|
455
|
+
EnumToken.SemiColonTokenType,
|
|
456
|
+
EnumToken.DashedIdenTokenType,
|
|
457
|
+
EnumToken.DeclarationNodeType,
|
|
458
|
+
EnumToken.SupportsQueryConditionTokenType,
|
|
459
|
+
EnumToken.SupportsQueryUnaryConditionTokenType,
|
|
460
|
+
]);
|
|
461
|
+
const definedPropertySettings = { configurable: true, enumerable: false, writable: true };
|
|
462
|
+
const combinators = ["+", ">", "~", "||", "|"];
|
|
463
|
+
|
|
464
|
+
export { COLORS_NAMES, D50, NAMES_COLORS, anglePrecision, colorDistancePrecision, colorFuncColorSpace, colorPrecision, colorRange, colorsFunc, combinators, containerFunc, definedPropertySettings, deprecatedSystemColors, e, epsilon, funcLike, generalEnclosedFunc, gridTemplateFunc, imageFunc, k, mFGT, mFLT, mathFuncs, mediaTypes, nonStandardColors, pageMarginBoxType, regMatchLinearGradient, regMatchRadialGradient, supportFunc, systemColors, timelineFunc, timingFunc, tokensMap, tokensfuncDefMap, tokensfuncSet, transformFunctions, trimTokenSpace, urlFunc, urlTokenMatcher, whenElseFunc, wildCardFuncs };
|