@tbela99/css-parser 1.4.2 → 1.4.3
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/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
- package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
- package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
- package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
- package/.repl_history +4 -0
- package/CHANGELOG.md +164 -4
- package/README.md +43 -0
- package/badges/coverage.svg +20 -0
- package/deno.lock +2861 -0
- package/dist/config.json.js +33 -1
- package/dist/index-umd-web.js +24382 -18476
- package/dist/index.cjs +24522 -18618
- package/dist/index.d.ts +1396 -929
- package/dist/lib/ast/clone.d.ts +10 -0
- package/dist/lib/ast/clone.js +45 -0
- package/dist/lib/ast/expand.d.ts +14 -0
- package/dist/lib/ast/expand.js +89 -64
- package/dist/lib/ast/features/calc.d.ts +10 -0
- package/dist/lib/ast/features/calc.js +62 -24
- package/dist/lib/ast/features/if.d.ts +10 -0
- package/dist/lib/ast/features/if.js +215 -0
- package/dist/lib/ast/features/index.d.ts +6 -0
- package/dist/lib/ast/features/index.js +1 -0
- package/dist/lib/ast/features/inlinecssvariables.d.ts +15 -0
- package/dist/lib/ast/features/inlinecssvariables.js +32 -27
- package/dist/lib/ast/features/prefix.d.ts +8 -0
- package/dist/lib/ast/features/prefix.js +68 -43
- package/dist/lib/ast/features/shorthand.d.ts +12 -0
- package/dist/lib/ast/features/shorthand.js +6 -9
- package/dist/lib/ast/features/transform.d.ts +10 -0
- package/dist/lib/ast/features/transform.js +9 -13
- package/dist/lib/ast/features/type.d.ts +15 -0
- package/dist/lib/ast/find.d.ts +165 -0
- package/dist/lib/ast/find.js +175 -0
- package/dist/lib/ast/math/expression.d.ts +18 -0
- package/dist/lib/ast/math/expression.js +140 -98
- package/dist/lib/ast/math/math.d.ts +6 -0
- package/dist/lib/ast/math/math.js +30 -41
- package/dist/lib/ast/minify.d.ts +19 -0
- package/dist/lib/ast/minify.js +541 -217
- package/dist/lib/ast/transform/compute.d.ts +8 -0
- package/dist/lib/ast/transform/compute.js +82 -69
- package/dist/lib/ast/transform/matrix.d.ts +22 -0
- package/dist/lib/ast/transform/matrix.js +12 -26
- package/dist/lib/ast/transform/minify.d.ts +5 -0
- package/dist/lib/ast/transform/minify.js +20 -20
- package/dist/lib/ast/transform/perspective.d.ts +3 -0
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.d.ts +12 -0
- package/dist/lib/ast/transform/rotate.js +1 -1
- package/dist/lib/ast/transform/scale.d.ts +6 -0
- package/dist/lib/ast/transform/scale.js +1 -1
- package/dist/lib/ast/transform/skew.d.ts +4 -0
- package/dist/lib/ast/transform/skew.js +1 -1
- package/dist/lib/ast/transform/translate.d.ts +6 -0
- package/dist/lib/ast/transform/translate.js +1 -1
- package/dist/lib/ast/transform/utils.d.ts +9 -0
- package/dist/lib/ast/types.d.ts +903 -0
- package/dist/lib/ast/types.js +277 -23
- package/dist/lib/ast/walk.d.ts +162 -0
- package/dist/lib/ast/walk.js +116 -60
- package/dist/lib/fs/resolve.d.ts +20 -0
- package/dist/lib/fs/resolve.js +37 -45
- package/dist/lib/parser/declaration/list.d.ts +16 -0
- package/dist/lib/parser/declaration/list.js +26 -24
- package/dist/lib/parser/declaration/map.d.ts +15 -0
- package/dist/lib/parser/declaration/map.js +140 -95
- package/dist/lib/parser/declaration/set.d.ts +9 -0
- package/dist/lib/parser/declaration/set.js +30 -25
- package/dist/lib/parser/node.d.ts +7 -0
- package/dist/lib/parser/parse.d.ts +107 -0
- package/dist/lib/parser/parse.js +1454 -1445
- package/dist/lib/parser/tokenize.d.ts +57 -0
- package/dist/lib/parser/tokenize.js +557 -404
- package/dist/lib/parser/utils/at-rule-container.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-container.js +486 -0
- package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
- package/dist/lib/parser/utils/at-rule-generic.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-generic.js +118 -0
- package/dist/lib/parser/utils/at-rule-import.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-import.js +393 -0
- package/dist/lib/parser/utils/at-rule-media.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-media.js +603 -0
- package/dist/lib/parser/utils/at-rule-page.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-page.js +28 -0
- package/dist/lib/parser/utils/at-rule-support.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-support.js +366 -0
- package/dist/lib/parser/utils/at-rule-token.d.ts +1 -0
- package/dist/lib/parser/utils/at-rule-when-else.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
- package/dist/lib/parser/utils/at-rule.d.ts +13 -0
- package/dist/lib/parser/utils/at-rule.js +37 -0
- package/dist/lib/parser/utils/cache.d.ts +6 -0
- package/dist/lib/parser/utils/cache.js +19 -0
- package/dist/lib/parser/utils/config.d.ts +2 -0
- package/dist/lib/parser/utils/config.js +1 -0
- package/dist/lib/parser/utils/declaration-list.d.ts +5 -0
- package/dist/lib/parser/utils/declaration.d.ts +18 -0
- package/dist/lib/parser/utils/declaration.js +569 -91
- package/dist/lib/parser/utils/eq.d.ts +1 -0
- package/dist/lib/parser/utils/hash.d.ts +21 -0
- package/dist/lib/parser/utils/hash.js +1 -1
- package/dist/lib/parser/utils/selector.d.ts +5 -0
- package/dist/lib/parser/utils/selector.js +476 -0
- package/dist/lib/parser/utils/text.d.ts +3 -0
- package/dist/lib/parser/utils/text.js +17 -1
- package/dist/lib/parser/utils/token.d.ts +14 -0
- package/dist/lib/parser/utils/token.js +102 -0
- package/dist/lib/parser/utils/type.d.ts +2 -0
- package/dist/lib/parser/utils/type.js +29 -18
- package/dist/lib/renderer/render.d.ts +28 -0
- package/dist/lib/renderer/render.js +421 -262
- package/dist/lib/renderer/sourcemap/lib/encode.d.ts +1 -0
- package/dist/lib/renderer/sourcemap/sourcemap.d.ts +26 -0
- package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
- package/dist/lib/syntax/color/a98rgb.d.ts +2 -0
- package/dist/lib/syntax/color/a98rgb.js +8 -12
- package/dist/lib/syntax/color/cmyk.d.ts +10 -0
- package/dist/lib/syntax/color/cmyk.js +23 -21
- package/dist/lib/syntax/color/color-mix.d.ts +2 -0
- package/dist/lib/syntax/color/color-mix.js +88 -77
- package/dist/lib/syntax/color/color.d.ts +42 -0
- package/dist/lib/syntax/color/color.js +65 -68
- package/dist/lib/syntax/color/hex.d.ts +16 -0
- package/dist/lib/syntax/color/hex.js +27 -31
- package/dist/lib/syntax/color/hsl.d.ts +20 -0
- package/dist/lib/syntax/color/hsl.js +5 -12
- package/dist/lib/syntax/color/hsv.d.ts +2 -0
- package/dist/lib/syntax/color/hwb.d.ts +21 -0
- package/dist/lib/syntax/color/hwb.js +8 -21
- package/dist/lib/syntax/color/lab.d.ts +25 -0
- package/dist/lib/syntax/color/lab.js +20 -21
- package/dist/lib/syntax/color/lch.d.ts +23 -0
- package/dist/lib/syntax/color/lch.js +13 -15
- package/dist/lib/syntax/color/oklab.d.ts +22 -0
- package/dist/lib/syntax/color/oklab.js +20 -39
- package/dist/lib/syntax/color/oklch.d.ts +20 -0
- package/dist/lib/syntax/color/oklch.js +14 -16
- package/dist/lib/syntax/color/p3.d.ts +6 -0
- package/dist/lib/syntax/color/p3.js +0 -8
- package/dist/lib/syntax/color/prophotorgb.d.ts +2 -0
- package/dist/lib/syntax/color/rec2020.d.ts +2 -0
- package/dist/lib/syntax/color/rec2020.js +9 -13
- package/dist/lib/syntax/color/relativecolor.d.ts +13 -0
- package/dist/lib/syntax/color/relativecolor.js +68 -41
- package/dist/lib/syntax/color/rgb.d.ts +20 -0
- package/dist/lib/syntax/color/rgb.js +14 -18
- package/dist/lib/syntax/color/srgb.d.ts +23 -0
- package/dist/lib/syntax/color/srgb.js +27 -26
- package/dist/lib/syntax/color/utils/components.d.ts +2 -0
- package/dist/lib/syntax/color/utils/components.js +30 -14
- package/dist/lib/syntax/color/utils/distance.d.ts +18 -0
- package/dist/lib/syntax/color/utils/distance.js +1 -8
- package/dist/lib/syntax/color/utils/matrix.d.ts +6 -0
- package/dist/lib/syntax/color/xyz.d.ts +5 -0
- package/dist/lib/syntax/color/xyz.js +8 -20
- package/dist/lib/syntax/color/xyzd50.d.ts +4 -0
- package/dist/lib/syntax/color/xyzd50.js +6 -20
- package/dist/lib/syntax/constants.d.ts +67 -0
- package/dist/lib/syntax/constants.js +436 -0
- package/dist/lib/syntax/syntax.d.ts +38 -0
- package/dist/lib/syntax/syntax.js +533 -568
- package/dist/lib/validation/config.d.ts +14 -0
- package/dist/lib/validation/config.js +72 -33
- package/dist/lib/validation/config.json.js +1159 -74
- package/dist/lib/validation/json.d.ts +2 -0
- package/dist/lib/validation/match.d.ts +38 -0
- package/dist/lib/validation/match.js +2985 -0
- package/dist/lib/validation/parser/parse.d.ts +8 -0
- package/dist/lib/validation/parser/parse.js +684 -935
- package/dist/lib/validation/parser/typedef.d.ts +95 -0
- package/dist/lib/validation/parser/typedef.js +100 -0
- package/dist/lib/validation/utils/list.d.ts +4 -0
- package/dist/lib/validation/utils/list.js +4 -11
- package/dist/lib/validation/utils/whitespace.d.ts +2 -0
- package/dist/lib/validation/utils/whitespace.js +2 -8
- package/dist/node.d.ts +207 -0
- package/dist/node.js +42 -39
- package/dist/web.d.ts +169 -0
- package/dist/web.js +38 -33
- package/package.json +15 -12
- package/playground/index.html +1328 -0
- package/playground/sw.js +55 -0
- package/playground/tree.js +176 -0
- 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,150 +0,0 @@
|
|
|
1
|
-
import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
|
-
import '../../syntax/color/utils/constants.js';
|
|
8
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
|
-
import { validateAtRuleMediaQueryList } from './media.js';
|
|
10
|
-
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
11
|
-
import { validateLayerName } from '../syntaxes/layer-name.js';
|
|
12
|
-
import '../syntaxes/complex-selector.js';
|
|
13
|
-
import '../syntax.js';
|
|
14
|
-
import '../config.js';
|
|
15
|
-
import { validateAtRuleSupportsConditions } from './supports.js';
|
|
16
|
-
|
|
17
|
-
function validateAtRuleImport(atRule, options, root) {
|
|
18
|
-
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
return {
|
|
21
|
-
valid: SyntaxValidationResult.Drop,
|
|
22
|
-
context: [],
|
|
23
|
-
node: null,
|
|
24
|
-
syntax: '@' + atRule.nam,
|
|
25
|
-
error: 'expected @import media query list'
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
if ('chi' in atRule) {
|
|
29
|
-
// @ts-ignore
|
|
30
|
-
return {
|
|
31
|
-
valid: SyntaxValidationResult.Drop,
|
|
32
|
-
context: [],
|
|
33
|
-
node: null,
|
|
34
|
-
syntax: '@' + atRule.nam,
|
|
35
|
-
error: 'unexpected at-rule body'
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
const tokens = atRule.tokens.filter((t) => ![EnumToken.CommentTokenType].includes(t.typ));
|
|
39
|
-
if (tokens.length == 0) {
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
return {
|
|
42
|
-
valid: SyntaxValidationResult.Drop,
|
|
43
|
-
context: [],
|
|
44
|
-
node: null,
|
|
45
|
-
syntax: '@' + atRule.nam,
|
|
46
|
-
error: 'expected @import media query list'
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
if (tokens[0].typ == EnumToken.StringTokenType) {
|
|
50
|
-
tokens.shift();
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
consumeWhitespace(tokens);
|
|
53
|
-
}
|
|
54
|
-
else if (tokens[0].typ == EnumToken.UrlFunctionTokenType) {
|
|
55
|
-
const slice = tokens[0].chi.filter((t) => t.typ != EnumToken.CommentTokenType && t.typ != EnumToken.WhitespaceTokenType);
|
|
56
|
-
if (slice.length != 1 || ![EnumToken.StringTokenType, EnumToken.UrlTokenTokenType].includes(slice[0].typ)) {
|
|
57
|
-
// @ts-ignore
|
|
58
|
-
return {
|
|
59
|
-
valid: SyntaxValidationResult.Drop,
|
|
60
|
-
context: [],
|
|
61
|
-
node: tokens[0],
|
|
62
|
-
syntax: '@' + atRule.nam,
|
|
63
|
-
error: 'invalid url()'
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
tokens.shift();
|
|
68
|
-
// @ts-ignore
|
|
69
|
-
if (!consumeWhitespace(tokens)) {
|
|
70
|
-
// @ts-ignore
|
|
71
|
-
return {
|
|
72
|
-
valid: SyntaxValidationResult.Drop,
|
|
73
|
-
context: [],
|
|
74
|
-
node: tokens[0],
|
|
75
|
-
syntax: '@' + atRule.nam,
|
|
76
|
-
error: 'expecting whitespace'
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
tokens.shift();
|
|
81
|
-
// @ts-ignore
|
|
82
|
-
consumeWhitespace(tokens);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
// @ts-ignore
|
|
86
|
-
return {
|
|
87
|
-
valid: SyntaxValidationResult.Drop,
|
|
88
|
-
context: [],
|
|
89
|
-
node: tokens[0],
|
|
90
|
-
syntax: '@' + atRule.nam,
|
|
91
|
-
error: 'expecting url() or string'
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
if (tokens.length > 0) {
|
|
95
|
-
// @ts-ignore
|
|
96
|
-
if (tokens[0].typ == EnumToken.IdenTokenType) {
|
|
97
|
-
if ('layer' === tokens[0].val.toLowerCase()) {
|
|
98
|
-
tokens.shift();
|
|
99
|
-
// @ts-ignore
|
|
100
|
-
if (!consumeWhitespace(tokens)) {
|
|
101
|
-
// @ts-ignore
|
|
102
|
-
return {
|
|
103
|
-
valid: SyntaxValidationResult.Drop,
|
|
104
|
-
context: [],
|
|
105
|
-
node: tokens[0],
|
|
106
|
-
syntax: '@' + atRule.nam,
|
|
107
|
-
error: 'expecting whitespace'
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
else if (tokens[0].typ == EnumToken.FunctionTokenType) {
|
|
114
|
-
// @ts-ignore
|
|
115
|
-
if ('layer' === tokens[0].val.toLowerCase()) {
|
|
116
|
-
const result = validateLayerName(tokens[0].chi);
|
|
117
|
-
if (result.valid == SyntaxValidationResult.Drop) {
|
|
118
|
-
return result;
|
|
119
|
-
}
|
|
120
|
-
tokens.shift();
|
|
121
|
-
// @ts-ignore
|
|
122
|
-
consumeWhitespace(tokens);
|
|
123
|
-
}
|
|
124
|
-
// tokens[0]?.val
|
|
125
|
-
// @ts-ignore
|
|
126
|
-
if ('supports' === tokens[0]?.val?.toLowerCase?.()) {
|
|
127
|
-
const result = validateAtRuleSupportsConditions(atRule, tokens[0].chi);
|
|
128
|
-
if (result.valid == SyntaxValidationResult.Drop) {
|
|
129
|
-
return result;
|
|
130
|
-
}
|
|
131
|
-
tokens.shift();
|
|
132
|
-
// @ts-ignore
|
|
133
|
-
consumeWhitespace(tokens);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (tokens.length > 0) {
|
|
138
|
-
return validateAtRuleMediaQueryList(tokens, atRule);
|
|
139
|
-
}
|
|
140
|
-
// @ts-ignore
|
|
141
|
-
return {
|
|
142
|
-
valid: SyntaxValidationResult.Valid,
|
|
143
|
-
context: [],
|
|
144
|
-
node: null,
|
|
145
|
-
syntax: '@' + atRule.nam,
|
|
146
|
-
error: ''
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export { validateAtRuleImport };
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
|
-
import '../../syntax/color/utils/constants.js';
|
|
8
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
|
-
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
10
|
-
|
|
11
|
-
function validateAtRuleKeyframes(atRule, options, root) {
|
|
12
|
-
if (!Array.isArray(atRule.chi)) {
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
return {
|
|
15
|
-
valid: SyntaxValidationResult.Drop,
|
|
16
|
-
matches: [],
|
|
17
|
-
node: atRule,
|
|
18
|
-
syntax: '@' + atRule.nam,
|
|
19
|
-
error: 'expected supports body',
|
|
20
|
-
tokens: []
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
return {
|
|
26
|
-
valid: SyntaxValidationResult.Drop,
|
|
27
|
-
context: [],
|
|
28
|
-
node: atRule,
|
|
29
|
-
syntax: '@keyframes',
|
|
30
|
-
error: 'expecting at-rule prelude'
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
const tokens = atRule.tokens.filter((t) => t.typ != EnumToken.CommentTokenType).slice();
|
|
34
|
-
consumeWhitespace(tokens);
|
|
35
|
-
if (tokens.length == 0 || ![EnumToken.StringTokenType, EnumToken.IdenTokenType].includes(tokens[0].typ)) {
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
return {
|
|
38
|
-
valid: SyntaxValidationResult.Drop,
|
|
39
|
-
context: [],
|
|
40
|
-
node: atRule,
|
|
41
|
-
syntax: '@keyframes',
|
|
42
|
-
error: 'expecting ident or string token'
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
tokens.shift();
|
|
46
|
-
consumeWhitespace(tokens);
|
|
47
|
-
if (tokens.length > 0) {
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
return {
|
|
50
|
-
valid: SyntaxValidationResult.Drop,
|
|
51
|
-
context: [],
|
|
52
|
-
node: tokens[0],
|
|
53
|
-
syntax: '@keyframes',
|
|
54
|
-
error: 'unexpected token'
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
// @ts-ignore
|
|
58
|
-
return {
|
|
59
|
-
valid: SyntaxValidationResult.Valid,
|
|
60
|
-
context: [],
|
|
61
|
-
node: atRule,
|
|
62
|
-
syntax: '@keyframes',
|
|
63
|
-
error: ''
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export { validateAtRuleKeyframes };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { SyntaxValidationResult } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
|
-
import '../../syntax/color/utils/constants.js';
|
|
8
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
|
-
import { validateLayerName } from '../syntaxes/layer-name.js';
|
|
10
|
-
import '../syntaxes/complex-selector.js';
|
|
11
|
-
import '../syntax.js';
|
|
12
|
-
import '../config.js';
|
|
13
|
-
|
|
14
|
-
function validateAtRuleLayer(atRule, options, root) {
|
|
15
|
-
if (!Array.isArray(atRule.chi)) {
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
return {
|
|
18
|
-
valid: SyntaxValidationResult.Drop,
|
|
19
|
-
matches: [],
|
|
20
|
-
node: atRule,
|
|
21
|
-
syntax: '@' + atRule.nam,
|
|
22
|
-
error: 'expected supports body',
|
|
23
|
-
tokens: []
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
// media-query-list
|
|
27
|
-
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
return {
|
|
30
|
-
valid: SyntaxValidationResult.Valid,
|
|
31
|
-
matches: [],
|
|
32
|
-
node: atRule,
|
|
33
|
-
syntax: '@layer',
|
|
34
|
-
error: '',
|
|
35
|
-
tokens: []
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
return validateLayerName(atRule.tokens);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { validateAtRuleLayer };
|
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
|
-
import { generalEnclosedFunc } from '../../syntax/color/utils/constants.js';
|
|
8
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
|
-
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
10
|
-
import { splitTokenList } from '../utils/list.js';
|
|
11
|
-
|
|
12
|
-
function validateAtRuleMedia(atRule, options, root) {
|
|
13
|
-
if (!Array.isArray(atRule.chi)) {
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
return {
|
|
16
|
-
valid: SyntaxValidationResult.Drop,
|
|
17
|
-
matches: [],
|
|
18
|
-
node: atRule,
|
|
19
|
-
syntax: '@' + atRule.nam,
|
|
20
|
-
error: 'expected supports body',
|
|
21
|
-
tokens: []
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
// media-query-list
|
|
25
|
-
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
26
|
-
// @ts-ignore
|
|
27
|
-
return {
|
|
28
|
-
valid: SyntaxValidationResult.Valid,
|
|
29
|
-
context: [],
|
|
30
|
-
node: null,
|
|
31
|
-
syntax: null,
|
|
32
|
-
error: '',
|
|
33
|
-
tokens: []
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
let result = null;
|
|
37
|
-
const slice = atRule.tokens.slice();
|
|
38
|
-
consumeWhitespace(slice);
|
|
39
|
-
if (slice.length == 0) {
|
|
40
|
-
return {
|
|
41
|
-
valid: SyntaxValidationResult.Valid,
|
|
42
|
-
context: [],
|
|
43
|
-
node: atRule,
|
|
44
|
-
syntax: '@media',
|
|
45
|
-
error: ''
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
result = validateAtRuleMediaQueryList(atRule.tokens, atRule);
|
|
49
|
-
if (result.valid == SyntaxValidationResult.Drop) {
|
|
50
|
-
return result;
|
|
51
|
-
}
|
|
52
|
-
if (!('chi' in atRule)) {
|
|
53
|
-
// @ts-ignore
|
|
54
|
-
return {
|
|
55
|
-
valid: SyntaxValidationResult.Drop,
|
|
56
|
-
context: [],
|
|
57
|
-
node: atRule,
|
|
58
|
-
syntax: '@media',
|
|
59
|
-
error: 'expected at-rule body'
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
// @ts-ignore
|
|
63
|
-
return {
|
|
64
|
-
valid: SyntaxValidationResult.Valid,
|
|
65
|
-
context: [],
|
|
66
|
-
node: atRule,
|
|
67
|
-
syntax: '@media',
|
|
68
|
-
error: ''
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function validateAtRuleMediaQueryList(tokenList, atRule) {
|
|
72
|
-
const split = splitTokenList(tokenList);
|
|
73
|
-
const matched = [];
|
|
74
|
-
let result = null;
|
|
75
|
-
let previousToken;
|
|
76
|
-
let mediaFeatureType;
|
|
77
|
-
for (let i = 0; i < split.length; i++) {
|
|
78
|
-
const tokens = split[i].slice();
|
|
79
|
-
const match = [];
|
|
80
|
-
result = null;
|
|
81
|
-
mediaFeatureType = null;
|
|
82
|
-
previousToken = null;
|
|
83
|
-
if (tokens.length == 0) {
|
|
84
|
-
// @ts-ignore
|
|
85
|
-
result = {
|
|
86
|
-
valid: SyntaxValidationResult.Drop,
|
|
87
|
-
context: [],
|
|
88
|
-
node: tokens[0] ?? atRule,
|
|
89
|
-
syntax: '@media',
|
|
90
|
-
error: 'unexpected token'
|
|
91
|
-
};
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
while (tokens.length > 0) {
|
|
95
|
-
previousToken = tokens[0];
|
|
96
|
-
// media-condition | media-type | custom-media
|
|
97
|
-
if (!(validateMediaCondition(tokens[0], atRule) || validateMediaFeature(tokens[0]) || validateCustomMediaCondition(tokens[0], atRule))) {
|
|
98
|
-
if (tokens[0].typ == EnumToken.ParensTokenType) {
|
|
99
|
-
result = validateAtRuleMediaQueryList(tokens[0].chi, atRule);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
result = {
|
|
103
|
-
valid: SyntaxValidationResult.Drop,
|
|
104
|
-
context: [],
|
|
105
|
-
node: tokens[0] ?? atRule,
|
|
106
|
-
syntax: '@media',
|
|
107
|
-
error: 'expecting media feature or media condition'
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
if (result.valid == SyntaxValidationResult.Drop) {
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
result = null;
|
|
114
|
-
}
|
|
115
|
-
match.push(tokens.shift());
|
|
116
|
-
if (tokens.length == 0) {
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
if (!consumeWhitespace(tokens)) {
|
|
120
|
-
if (previousToken?.typ != EnumToken.ParensTokenType) {
|
|
121
|
-
// @ts-ignore
|
|
122
|
-
result = {
|
|
123
|
-
valid: SyntaxValidationResult.Drop,
|
|
124
|
-
context: [],
|
|
125
|
-
node: tokens[0] ?? atRule,
|
|
126
|
-
syntax: '@media',
|
|
127
|
-
error: 'expected media query list'
|
|
128
|
-
};
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
else if (![EnumToken.MediaFeatureOrTokenType, EnumToken.MediaFeatureAndTokenType].includes(tokens[0].typ)) {
|
|
133
|
-
// @ts-ignore
|
|
134
|
-
result = {
|
|
135
|
-
valid: SyntaxValidationResult.Drop,
|
|
136
|
-
context: [],
|
|
137
|
-
node: tokens[0] ?? atRule,
|
|
138
|
-
syntax: '@media',
|
|
139
|
-
error: 'expected and/or'
|
|
140
|
-
};
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
if (mediaFeatureType == null) {
|
|
144
|
-
mediaFeatureType = tokens[0];
|
|
145
|
-
}
|
|
146
|
-
if (mediaFeatureType.typ != tokens[0].typ) {
|
|
147
|
-
// @ts-ignore
|
|
148
|
-
result = {
|
|
149
|
-
valid: SyntaxValidationResult.Drop,
|
|
150
|
-
context: [],
|
|
151
|
-
node: tokens[0] ?? atRule,
|
|
152
|
-
syntax: '@media',
|
|
153
|
-
error: 'mixing and/or not allowed at the same level'
|
|
154
|
-
};
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
match.push({ typ: EnumToken.WhitespaceTokenType }, tokens.shift());
|
|
158
|
-
consumeWhitespace(tokens);
|
|
159
|
-
if (tokens.length == 0) {
|
|
160
|
-
// @ts-ignore
|
|
161
|
-
result = {
|
|
162
|
-
valid: SyntaxValidationResult.Drop,
|
|
163
|
-
context: [],
|
|
164
|
-
node: tokens[0] ?? atRule,
|
|
165
|
-
syntax: '@media',
|
|
166
|
-
error: 'expected media-condition'
|
|
167
|
-
};
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
match.push({ typ: EnumToken.WhitespaceTokenType });
|
|
171
|
-
}
|
|
172
|
-
if (result == null && match.length > 0) {
|
|
173
|
-
matched.push(match);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
if (result != null) {
|
|
177
|
-
return result;
|
|
178
|
-
}
|
|
179
|
-
if (matched.length == 0) {
|
|
180
|
-
return {
|
|
181
|
-
valid: SyntaxValidationResult.Drop,
|
|
182
|
-
context: [],
|
|
183
|
-
node: atRule,
|
|
184
|
-
syntax: '@media',
|
|
185
|
-
error: 'expected media query list'
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
tokenList.length = 0;
|
|
189
|
-
let hasAll = false;
|
|
190
|
-
for (let i = 0; i < matched.length; i++) {
|
|
191
|
-
if (tokenList.length > 0) {
|
|
192
|
-
tokenList.push({ typ: EnumToken.CommaTokenType });
|
|
193
|
-
}
|
|
194
|
-
if (matched[i].length == 1 && matched.length > 1 && matched[i][0].typ == EnumToken.MediaFeatureTokenType && matched[i][0].val == 'all') {
|
|
195
|
-
hasAll = true;
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
tokenList.push(...matched[i]);
|
|
199
|
-
}
|
|
200
|
-
if (hasAll && tokenList.length == 0) {
|
|
201
|
-
tokenList.push({ typ: EnumToken.MediaFeatureTokenType, val: 'all' });
|
|
202
|
-
}
|
|
203
|
-
// @ts-ignore
|
|
204
|
-
return {
|
|
205
|
-
valid: SyntaxValidationResult.Valid,
|
|
206
|
-
context: [],
|
|
207
|
-
node: atRule,
|
|
208
|
-
syntax: '@media',
|
|
209
|
-
error: ''
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
function validateCustomMediaCondition(token, atRule) {
|
|
213
|
-
if (token.typ == EnumToken.MediaFeatureNotTokenType) {
|
|
214
|
-
return validateMediaCondition(token.val, atRule);
|
|
215
|
-
}
|
|
216
|
-
if (token.typ != EnumToken.ParensTokenType) {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
const chi = token.chi.filter((t) => t.typ != EnumToken.CommentTokenType && t.typ != EnumToken.WhitespaceTokenType);
|
|
220
|
-
if (chi.length != 1) {
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
return chi[0].typ == EnumToken.DashedIdenTokenType;
|
|
224
|
-
}
|
|
225
|
-
function validateMediaCondition(token, atRule) {
|
|
226
|
-
if (token.typ == EnumToken.MediaFeatureNotTokenType) {
|
|
227
|
-
return validateMediaCondition(token.val, atRule);
|
|
228
|
-
}
|
|
229
|
-
if (token.typ != EnumToken.ParensTokenType && !(['when', 'else', 'import'].includes(atRule.nam) && token.typ == EnumToken.FunctionTokenType && generalEnclosedFunc.includes(token.val))) {
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
const chi = token.chi.filter((t) => t.typ != EnumToken.CommentTokenType && t.typ != EnumToken.WhitespaceTokenType);
|
|
233
|
-
if (chi.length != 1) {
|
|
234
|
-
return false;
|
|
235
|
-
}
|
|
236
|
-
if (chi[0].typ == EnumToken.IdenTokenType) {
|
|
237
|
-
return true;
|
|
238
|
-
}
|
|
239
|
-
if (chi[0].typ == EnumToken.MediaFeatureNotTokenType) {
|
|
240
|
-
return validateMediaCondition(chi[0].val, atRule);
|
|
241
|
-
}
|
|
242
|
-
if (chi[0].typ == EnumToken.MediaQueryConditionTokenType) {
|
|
243
|
-
return chi[0].l.typ == EnumToken.IdenTokenType;
|
|
244
|
-
}
|
|
245
|
-
return false;
|
|
246
|
-
}
|
|
247
|
-
function validateMediaFeature(token) {
|
|
248
|
-
let val = token;
|
|
249
|
-
if (token.typ == EnumToken.MediaFeatureOnlyTokenType || token.typ == EnumToken.MediaFeatureNotTokenType) {
|
|
250
|
-
val = token.val;
|
|
251
|
-
}
|
|
252
|
-
return val.typ == EnumToken.MediaFeatureTokenType;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
export { validateAtRuleMedia, validateAtRuleMediaQueryList, validateMediaCondition, validateMediaFeature };
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
|
-
import '../../syntax/color/utils/constants.js';
|
|
8
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
|
-
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
10
|
-
import { validateURL } from '../syntaxes/url.js';
|
|
11
|
-
|
|
12
|
-
function validateAtRuleNamespace(atRule, options, root) {
|
|
13
|
-
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
return {
|
|
16
|
-
valid: SyntaxValidationResult.Drop,
|
|
17
|
-
context: [],
|
|
18
|
-
node: atRule,
|
|
19
|
-
syntax: '@namespace',
|
|
20
|
-
error: 'expected at-rule prelude'
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
if ('chi' in atRule) {
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
return {
|
|
26
|
-
valid: SyntaxValidationResult.Drop,
|
|
27
|
-
context: [],
|
|
28
|
-
node: atRule,
|
|
29
|
-
syntax: '@namespace',
|
|
30
|
-
error: 'unexpected at-rule body'
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
const tokens = atRule.tokens.slice();
|
|
34
|
-
consumeWhitespace(tokens);
|
|
35
|
-
if (tokens[0].typ == EnumToken.IdenTokenType) {
|
|
36
|
-
tokens.shift();
|
|
37
|
-
consumeWhitespace(tokens);
|
|
38
|
-
}
|
|
39
|
-
if (tokens.length == 0) {
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
return {
|
|
42
|
-
valid: SyntaxValidationResult.Drop,
|
|
43
|
-
context: [],
|
|
44
|
-
node: atRule,
|
|
45
|
-
syntax: '@namespace',
|
|
46
|
-
error: 'expected string or url()'
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
if (tokens[0].typ != EnumToken.StringTokenType) {
|
|
50
|
-
const result = validateURL(tokens[0]);
|
|
51
|
-
if (result.valid != SyntaxValidationResult.Valid) {
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
tokens.shift();
|
|
55
|
-
consumeWhitespace(tokens);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
tokens.shift();
|
|
59
|
-
consumeWhitespace(tokens);
|
|
60
|
-
}
|
|
61
|
-
if (tokens.length > 0) {
|
|
62
|
-
// @ts-ignore
|
|
63
|
-
return {
|
|
64
|
-
valid: SyntaxValidationResult.Drop,
|
|
65
|
-
context: [],
|
|
66
|
-
node: tokens[0],
|
|
67
|
-
syntax: '@namespace',
|
|
68
|
-
error: 'unexpected token'
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
// @ts-ignore
|
|
72
|
-
return {
|
|
73
|
-
valid: SyntaxValidationResult.Valid,
|
|
74
|
-
context: [],
|
|
75
|
-
node: atRule,
|
|
76
|
-
syntax: '@namespace',
|
|
77
|
-
error: ''
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export { validateAtRuleNamespace };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
|
-
import '../../syntax/color/utils/constants.js';
|
|
8
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
|
-
|
|
10
|
-
function validateAtRulePageMarginBox(atRule, options, root) {
|
|
11
|
-
if (!Array.isArray(atRule.chi)) {
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
return {
|
|
14
|
-
valid: SyntaxValidationResult.Drop,
|
|
15
|
-
matches: [],
|
|
16
|
-
node: atRule,
|
|
17
|
-
syntax: '@' + atRule.nam,
|
|
18
|
-
error: 'expected supports body',
|
|
19
|
-
tokens: []
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
if (Array.isArray(atRule.tokens) && atRule.tokens.length > 0) {
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
return {
|
|
25
|
-
valid: SyntaxValidationResult.Valid,
|
|
26
|
-
context: [],
|
|
27
|
-
node: null,
|
|
28
|
-
syntax: '@' + atRule.nam,
|
|
29
|
-
error: ''
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
if (!('chi' in atRule)) {
|
|
33
|
-
// @ts-ignore
|
|
34
|
-
return {
|
|
35
|
-
valid: SyntaxValidationResult.Drop,
|
|
36
|
-
context: [],
|
|
37
|
-
node: atRule,
|
|
38
|
-
syntax: '@' + atRule.nam,
|
|
39
|
-
error: 'expected margin-box body'
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
for (const token of atRule.chi) {
|
|
43
|
-
if (![EnumToken.DeclarationNodeType, EnumToken.CommentNodeType, EnumToken.WhitespaceTokenType].includes(token.typ)) {
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
return {
|
|
46
|
-
valid: SyntaxValidationResult.Drop,
|
|
47
|
-
context: [],
|
|
48
|
-
node: token,
|
|
49
|
-
syntax: 'declaration-list',
|
|
50
|
-
error: 'expected margin-box body'
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// @ts-ignore
|
|
55
|
-
return {
|
|
56
|
-
valid: SyntaxValidationResult.Valid,
|
|
57
|
-
context: [],
|
|
58
|
-
node: null,
|
|
59
|
-
syntax: '@' + atRule.nam,
|
|
60
|
-
error: ''
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export { validateAtRulePageMarginBox };
|