@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,40 +1,22 @@
|
|
|
1
1
|
import config from './config.json.js';
|
|
2
|
-
import { parseSyntax } from './parser/parse.js';
|
|
2
|
+
import { trimSyntaxArray, parseSyntax } from './parser/parse.js';
|
|
3
|
+
import { ValidationTokenEnum } from './parser/typedef.js';
|
|
4
|
+
import { memoize } from '../parser/utils/cache.js';
|
|
3
5
|
|
|
4
6
|
const parsedSyntaxes = new Map();
|
|
5
7
|
Object.freeze(config);
|
|
6
8
|
function getSyntaxConfig() {
|
|
7
|
-
// @ts-
|
|
9
|
+
// @ts-expect-error
|
|
8
10
|
return config;
|
|
9
11
|
}
|
|
10
|
-
function
|
|
11
|
-
// @ts-
|
|
12
|
+
function findNode(group, key) {
|
|
13
|
+
// @ts-expect-error
|
|
12
14
|
let obj = config[group];
|
|
13
15
|
const keys = Array.isArray(key) ? key : [key];
|
|
14
16
|
for (let i = 0; i < keys.length; i++) {
|
|
15
17
|
key = keys[i];
|
|
16
18
|
if (!(key in obj)) {
|
|
17
|
-
if ((i == 0 && key.charAt(0) ==
|
|
18
|
-
const matches = key.match(/^(@?)(-[a-zA-Z]+)-(.*?)$/);
|
|
19
|
-
if (matches != null) {
|
|
20
|
-
key = matches[1] + matches[3];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
obj = obj[key];
|
|
26
|
-
}
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
return obj?.syntax ?? null;
|
|
29
|
-
}
|
|
30
|
-
function getParsedSyntax(group, key) {
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
let obj = config[group];
|
|
33
|
-
const keys = Array.isArray(key) ? key : [key];
|
|
34
|
-
for (let i = 0; i < keys.length; i++) {
|
|
35
|
-
key = keys[i];
|
|
36
|
-
if (!(key in obj)) {
|
|
37
|
-
if ((i == 0 && key.charAt(0) == '@') || key.charAt(0) == '-') {
|
|
19
|
+
if ((i == 0 && key.charAt(0) == "@") || key.charAt(0) == "-") {
|
|
38
20
|
const matches = key.match(/^(@?)(-[a-zA-Z]+)-(.*?)$/);
|
|
39
21
|
if (matches != null) {
|
|
40
22
|
key = matches[1] + matches[3];
|
|
@@ -44,17 +26,74 @@ function getParsedSyntax(group, key) {
|
|
|
44
26
|
return null;
|
|
45
27
|
}
|
|
46
28
|
}
|
|
47
|
-
// @ts-
|
|
29
|
+
// @ts-expect-error
|
|
48
30
|
obj = obj[key];
|
|
49
31
|
}
|
|
50
|
-
|
|
51
|
-
|
|
32
|
+
return obj;
|
|
33
|
+
}
|
|
34
|
+
const getParsedSyntax = memoize((group, key) => {
|
|
35
|
+
// @ts-expect-error
|
|
36
|
+
const obj = findNode(group, key);
|
|
37
|
+
if (obj == null) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const keys = Array.isArray(key) ? key : [key];
|
|
41
|
+
const index = group + "." + keys.join(".");
|
|
52
42
|
if (!parsedSyntaxes.has(index)) {
|
|
53
|
-
const syntax = parseSyntax(obj.syntax);
|
|
54
|
-
|
|
55
|
-
parsedSyntaxes.set(index, syntax.chi);
|
|
43
|
+
const syntax = Object.freeze(trimSyntaxArray(parseSyntax(obj.syntax)));
|
|
44
|
+
parsedSyntaxes.set(index, syntax);
|
|
56
45
|
}
|
|
57
46
|
return parsedSyntaxes.get(index);
|
|
58
|
-
}
|
|
47
|
+
});
|
|
48
|
+
const getSyntaxRule = memoize((group, key) => {
|
|
49
|
+
const node = findNode(group, key);
|
|
50
|
+
if (node == null) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
let syntaxRules = getParsedSyntax(group, key);
|
|
54
|
+
if (syntaxRules == null) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
let blockStart = -1;
|
|
58
|
+
let blockEnd = -1;
|
|
59
|
+
let i;
|
|
60
|
+
for (i = 0; i < syntaxRules.length; i++) {
|
|
61
|
+
if (syntaxRules[i].typ === ValidationTokenEnum.OpenCurlyBrace ||
|
|
62
|
+
syntaxRules[i].typ === ValidationTokenEnum.SemiColon) {
|
|
63
|
+
blockStart = i;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (blockStart != -1) {
|
|
68
|
+
i = syntaxRules.length;
|
|
69
|
+
while (i--) {
|
|
70
|
+
if (syntaxRules[i].typ === ValidationTokenEnum.CloseCurlyBrace) {
|
|
71
|
+
blockEnd = i;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const block = blockStart == -1 ? null : trimSyntaxArray(syntaxRules.slice(blockStart + 1, blockEnd));
|
|
77
|
+
const prelude = trimSyntaxArray(blockStart == -1 ? syntaxRules.slice() : syntaxRules.slice(0, blockStart));
|
|
78
|
+
let propertyDescriptors = null;
|
|
79
|
+
// @ts-expect-error
|
|
80
|
+
if (node.descriptors != null) {
|
|
81
|
+
propertyDescriptors = {};
|
|
82
|
+
// @ts-expect-error
|
|
83
|
+
for (const [key, value] of Object.entries(node.descriptors)) {
|
|
84
|
+
// @ts-expect-error
|
|
85
|
+
propertyDescriptors[key] = parseSyntax(typeof value === "string" ? value : value.syntax);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
acceptAnyDeclaration: node.syntax.includes("<declaration-list>"),
|
|
90
|
+
acceptAnyRule: node.syntax.includes("<group-rule-body>") ||
|
|
91
|
+
node.syntax.includes("<stylesheet>"),
|
|
92
|
+
getPreludeRules: () => prelude,
|
|
93
|
+
getBlockRules: () => (block == null || block.length === 0 ? null : block),
|
|
94
|
+
getRules: () => syntaxRules,
|
|
95
|
+
getPropertyDescriptors: () => propertyDescriptors,
|
|
96
|
+
};
|
|
97
|
+
});
|
|
59
98
|
|
|
60
|
-
export { getParsedSyntax,
|
|
99
|
+
export { getParsedSyntax, getSyntaxConfig, getSyntaxRule };
|