@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,100 +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 { splitTokenList } from '../utils/list.js';
|
|
10
|
-
|
|
11
|
-
function validateAtRulePage(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
|
-
// media-query-list
|
|
24
|
-
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
return {
|
|
27
|
-
valid: SyntaxValidationResult.Valid,
|
|
28
|
-
matches: [],
|
|
29
|
-
node: null,
|
|
30
|
-
syntax: '@page',
|
|
31
|
-
error: '',
|
|
32
|
-
tokens: []
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
// page-selector-list
|
|
36
|
-
for (const tokens of splitTokenList(atRule.tokens)) {
|
|
37
|
-
if (tokens.length == 0) {
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
return {
|
|
40
|
-
valid: SyntaxValidationResult.Drop,
|
|
41
|
-
matches: [],
|
|
42
|
-
node: tokens[0] ?? atRule,
|
|
43
|
-
syntax: '@page',
|
|
44
|
-
error: 'unexpected token',
|
|
45
|
-
tokens: []
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
// <pseudo-page>+ | <ident> <pseudo-page>*
|
|
49
|
-
// ident pseudo-page* | pseudo-page+
|
|
50
|
-
if (tokens[0].typ == EnumToken.IdenTokenType) {
|
|
51
|
-
tokens.shift();
|
|
52
|
-
if (tokens.length == 0) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
if (tokens[0].typ != EnumToken.WhitespaceTokenType) {
|
|
57
|
-
// @ts-ignore
|
|
58
|
-
return {
|
|
59
|
-
valid: SyntaxValidationResult.Drop,
|
|
60
|
-
matches: [],
|
|
61
|
-
node: tokens[0] ?? atRule,
|
|
62
|
-
syntax: '@page',
|
|
63
|
-
error: 'unexpected token',
|
|
64
|
-
tokens: []
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
while (tokens.length > 0) {
|
|
69
|
-
if (tokens[0].typ == EnumToken.PseudoPageTokenType) {
|
|
70
|
-
tokens.shift();
|
|
71
|
-
if (tokens.length == 0) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
// @ts-ignore
|
|
75
|
-
if (tokens[0].typ != EnumToken.WhitespaceTokenType) {
|
|
76
|
-
// @ts-ignore
|
|
77
|
-
return {
|
|
78
|
-
valid: SyntaxValidationResult.Drop,
|
|
79
|
-
matches: [],
|
|
80
|
-
node: tokens[0] ?? atRule,
|
|
81
|
-
syntax: '@page',
|
|
82
|
-
error: 'unexpected token',
|
|
83
|
-
tokens: []
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
return {
|
|
91
|
-
valid: SyntaxValidationResult.Valid,
|
|
92
|
-
matches: [],
|
|
93
|
-
node: atRule,
|
|
94
|
-
syntax: '@page',
|
|
95
|
-
error: '',
|
|
96
|
-
tokens: []
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export { validateAtRulePage };
|
|
@@ -1,295 +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 { colorFontTech, fontFeaturesTech, fontFormat } from '../../syntax/syntax.js';
|
|
8
|
-
import '../../syntax/color/utils/constants.js';
|
|
9
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
10
|
-
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
11
|
-
import { splitTokenList } from '../utils/list.js';
|
|
12
|
-
|
|
13
|
-
function validateAtRuleSupports(atRule, options, root) {
|
|
14
|
-
// media-query-list
|
|
15
|
-
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
return {
|
|
18
|
-
valid: SyntaxValidationResult.Drop,
|
|
19
|
-
matches: [],
|
|
20
|
-
node: atRule,
|
|
21
|
-
syntax: '@' + atRule.nam,
|
|
22
|
-
error: 'expected supports query list',
|
|
23
|
-
tokens: []
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
if (!Array.isArray(atRule.chi)) {
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
return {
|
|
29
|
-
valid: SyntaxValidationResult.Drop,
|
|
30
|
-
matches: [],
|
|
31
|
-
node: atRule,
|
|
32
|
-
syntax: '@' + atRule.nam,
|
|
33
|
-
error: 'expected supports body',
|
|
34
|
-
tokens: []
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
const result = validateAtRuleSupportsConditions(atRule, atRule.tokens);
|
|
38
|
-
if (result) {
|
|
39
|
-
if (result.node == null) {
|
|
40
|
-
result.node = atRule;
|
|
41
|
-
}
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
if (!('chi' in atRule)) {
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
return {
|
|
47
|
-
valid: SyntaxValidationResult.Drop,
|
|
48
|
-
context: [],
|
|
49
|
-
node: atRule,
|
|
50
|
-
syntax: '@' + atRule.nam,
|
|
51
|
-
error: 'expected at-rule body'
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
// @ts-ignore
|
|
55
|
-
return {
|
|
56
|
-
valid: SyntaxValidationResult.Valid,
|
|
57
|
-
context: [],
|
|
58
|
-
node: atRule,
|
|
59
|
-
syntax: '@' + atRule.nam,
|
|
60
|
-
error: ''
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function validateAtRuleSupportsConditions(atRule, tokenList) {
|
|
64
|
-
let result = null;
|
|
65
|
-
for (const tokens of splitTokenList(tokenList)) {
|
|
66
|
-
if (tokens.length == 0) {
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
return {
|
|
69
|
-
valid: SyntaxValidationResult.Drop,
|
|
70
|
-
context: [],
|
|
71
|
-
node: tokens[0] ?? atRule,
|
|
72
|
-
syntax: '@' + atRule.nam,
|
|
73
|
-
error: 'unexpected token',
|
|
74
|
-
tokens: []
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
let previousToken = null;
|
|
78
|
-
while (tokens.length > 0) {
|
|
79
|
-
result = validateSupportCondition(atRule, tokens[0]);
|
|
80
|
-
// supports-condition
|
|
81
|
-
if (result.valid == SyntaxValidationResult.Valid) {
|
|
82
|
-
previousToken = tokens[0];
|
|
83
|
-
tokens.shift();
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
result = validateSupportFeature(tokens[0]);
|
|
87
|
-
if ( /*result == null || */result.valid == SyntaxValidationResult.Valid) {
|
|
88
|
-
previousToken = tokens[0];
|
|
89
|
-
tokens.shift();
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
if (tokens[0].typ == EnumToken.ParensTokenType) {
|
|
93
|
-
result = validateAtRuleSupportsConditions(atRule, tokens[0].chi);
|
|
94
|
-
if ( /* result == null || */result.valid == SyntaxValidationResult.Valid) {
|
|
95
|
-
previousToken = tokens[0];
|
|
96
|
-
tokens.shift();
|
|
97
|
-
// continue;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
return result;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
return result;
|
|
105
|
-
}
|
|
106
|
-
// if (result!= null && result.valid == ValidationLevel.Drop) {
|
|
107
|
-
//
|
|
108
|
-
// return {
|
|
109
|
-
// valid: ValidationLevel.Drop,
|
|
110
|
-
// context: [],
|
|
111
|
-
// node: tokens[0] ?? atRule,
|
|
112
|
-
// syntax: '@' + atRule.nam,
|
|
113
|
-
// // @ts-ignore
|
|
114
|
-
// error: result.error as string ?? 'unexpected token',
|
|
115
|
-
// tokens: []
|
|
116
|
-
// };
|
|
117
|
-
// }
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (tokens.length == 0) {
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
if (!consumeWhitespace(tokens)) {
|
|
124
|
-
if (previousToken?.typ != EnumToken.ParensTokenType) {
|
|
125
|
-
// @ts-ignore
|
|
126
|
-
return {
|
|
127
|
-
valid: SyntaxValidationResult.Drop,
|
|
128
|
-
context: [],
|
|
129
|
-
node: tokens[0] ?? previousToken ?? atRule,
|
|
130
|
-
syntax: '@' + atRule.nam,
|
|
131
|
-
error: 'expected whitespace'
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (![EnumToken.MediaFeatureOrTokenType, EnumToken.MediaFeatureAndTokenType].includes(tokens[0].typ)) {
|
|
136
|
-
// @ts-ignore
|
|
137
|
-
return {
|
|
138
|
-
valid: SyntaxValidationResult.Drop,
|
|
139
|
-
context: [],
|
|
140
|
-
node: tokens[0] ?? atRule,
|
|
141
|
-
syntax: '@' + atRule.nam,
|
|
142
|
-
error: 'expected and/or'
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
if (tokens.length == 1) {
|
|
146
|
-
// @ts-ignore
|
|
147
|
-
return {
|
|
148
|
-
valid: SyntaxValidationResult.Drop,
|
|
149
|
-
context: [],
|
|
150
|
-
node: tokens[0] ?? atRule,
|
|
151
|
-
syntax: '@' + atRule.nam,
|
|
152
|
-
error: 'expected supports-condition'
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
tokens.shift();
|
|
156
|
-
if (!consumeWhitespace(tokens)) {
|
|
157
|
-
// @ts-ignore
|
|
158
|
-
return {
|
|
159
|
-
valid: SyntaxValidationResult.Drop,
|
|
160
|
-
context: [],
|
|
161
|
-
node: tokens[0] ?? atRule,
|
|
162
|
-
syntax: '@' + atRule.nam,
|
|
163
|
-
error: 'expected whitespace'
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return {
|
|
169
|
-
valid: SyntaxValidationResult.Valid,
|
|
170
|
-
context: [],
|
|
171
|
-
node: atRule,
|
|
172
|
-
syntax: '@' + atRule.nam,
|
|
173
|
-
error: ''
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
function validateSupportCondition(atRule, token) {
|
|
177
|
-
if (token.typ == EnumToken.MediaFeatureNotTokenType) {
|
|
178
|
-
return validateSupportCondition(atRule, token.val);
|
|
179
|
-
}
|
|
180
|
-
if (token.typ == EnumToken.FunctionTokenType && 'selector' === token.val.toLowerCase()) {
|
|
181
|
-
return {
|
|
182
|
-
valid: SyntaxValidationResult.Valid,
|
|
183
|
-
context: [],
|
|
184
|
-
node: token,
|
|
185
|
-
syntax: '@' + atRule.nam,
|
|
186
|
-
error: ''
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
const chi = token.chi.filter((t) => t.typ != EnumToken.CommentTokenType && t.typ != EnumToken.WhitespaceTokenType);
|
|
190
|
-
if (chi.length != 1) {
|
|
191
|
-
return validateAtRuleSupportsConditions(atRule, token.chi);
|
|
192
|
-
}
|
|
193
|
-
if (chi[0].typ == EnumToken.IdenTokenType) {
|
|
194
|
-
// @ts-ignore
|
|
195
|
-
return {
|
|
196
|
-
valid: SyntaxValidationResult.Valid,
|
|
197
|
-
context: [],
|
|
198
|
-
node: null,
|
|
199
|
-
syntax: '@' + atRule.nam,
|
|
200
|
-
error: ''
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
if (chi[0].typ == EnumToken.MediaFeatureNotTokenType) {
|
|
204
|
-
return validateSupportCondition(atRule, chi[0].val);
|
|
205
|
-
}
|
|
206
|
-
if (chi[0].typ == EnumToken.MediaQueryConditionTokenType) {
|
|
207
|
-
// @ts-ignore
|
|
208
|
-
return chi[0].l.typ == EnumToken.IdenTokenType && chi[0].op.typ == EnumToken.ColonTokenType ?
|
|
209
|
-
{
|
|
210
|
-
valid: SyntaxValidationResult.Valid,
|
|
211
|
-
context: [],
|
|
212
|
-
node: null,
|
|
213
|
-
syntax: 'supports-condition',
|
|
214
|
-
error: ''
|
|
215
|
-
} : {
|
|
216
|
-
valid: SyntaxValidationResult.Drop,
|
|
217
|
-
context: [],
|
|
218
|
-
node: token,
|
|
219
|
-
syntax: 'supports-condition',
|
|
220
|
-
error: 'expected supports condition-in-parens'
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
// @ts-ignore
|
|
224
|
-
return {
|
|
225
|
-
valid: SyntaxValidationResult.Drop,
|
|
226
|
-
context: [],
|
|
227
|
-
node: token,
|
|
228
|
-
syntax: 'supports-condition',
|
|
229
|
-
error: 'expected supports condition-in-parens'
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
function validateSupportFeature(token) {
|
|
233
|
-
if (token.typ == EnumToken.MediaFeatureNotTokenType) {
|
|
234
|
-
return validateSupportFeature(token.val);
|
|
235
|
-
}
|
|
236
|
-
if (token.typ == EnumToken.FunctionTokenType) {
|
|
237
|
-
if ('selector' === token.val.toLowerCase()) {
|
|
238
|
-
return {
|
|
239
|
-
valid: SyntaxValidationResult.Valid,
|
|
240
|
-
context: [],
|
|
241
|
-
node: token,
|
|
242
|
-
syntax: 'selector',
|
|
243
|
-
error: ''
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
if ('font-tech' === token.val.toLowerCase()) {
|
|
247
|
-
const chi = token.chi.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ));
|
|
248
|
-
// @ts-ignore
|
|
249
|
-
return chi.length == 1 && chi[0].typ == EnumToken.IdenTokenType && colorFontTech.concat(fontFeaturesTech).includes(chi[0].val.toLowerCase()) ?
|
|
250
|
-
{
|
|
251
|
-
valid: SyntaxValidationResult.Valid,
|
|
252
|
-
context: [],
|
|
253
|
-
node: token,
|
|
254
|
-
syntax: 'font-tech',
|
|
255
|
-
error: ''
|
|
256
|
-
} :
|
|
257
|
-
{
|
|
258
|
-
valid: SyntaxValidationResult.Drop,
|
|
259
|
-
context: [],
|
|
260
|
-
node: token,
|
|
261
|
-
syntax: 'font-tech',
|
|
262
|
-
error: 'expected font-tech'
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
if ('font-format' === token.val.toLowerCase()) {
|
|
266
|
-
const chi = token.chi.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ));
|
|
267
|
-
// @ts-ignore
|
|
268
|
-
return chi.length == 1 && chi[0].typ == EnumToken.IdenTokenType && fontFormat.includes(chi[0].val, toLowerCase()) ?
|
|
269
|
-
{
|
|
270
|
-
valid: SyntaxValidationResult.Valid,
|
|
271
|
-
context: [],
|
|
272
|
-
node: token,
|
|
273
|
-
syntax: 'font-format',
|
|
274
|
-
error: ''
|
|
275
|
-
} :
|
|
276
|
-
{
|
|
277
|
-
valid: SyntaxValidationResult.Drop,
|
|
278
|
-
context: [],
|
|
279
|
-
node: token,
|
|
280
|
-
syntax: 'font-format',
|
|
281
|
-
error: 'expected font-format'
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
// @ts-ignore
|
|
286
|
-
return {
|
|
287
|
-
valid: SyntaxValidationResult.Drop,
|
|
288
|
-
context: [],
|
|
289
|
-
node: token,
|
|
290
|
-
syntax: '@supports',
|
|
291
|
-
error: 'expected feature'
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
export { validateAtRuleSupports, validateAtRuleSupportsConditions, validateSupportCondition };
|
|
@@ -1,185 +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
|
-
import { validateMediaFeature, validateMediaCondition } from './media.js';
|
|
12
|
-
import { validateSupportCondition } from './supports.js';
|
|
13
|
-
|
|
14
|
-
function validateAtRuleWhen(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
|
-
const slice = Array.isArray(atRule.tokens) ? atRule.tokens.slice() : [];
|
|
27
|
-
consumeWhitespace(slice);
|
|
28
|
-
if (slice.length == 0) {
|
|
29
|
-
// @ts-ignore
|
|
30
|
-
return {
|
|
31
|
-
valid: SyntaxValidationResult.Valid,
|
|
32
|
-
context: [],
|
|
33
|
-
node: atRule,
|
|
34
|
-
syntax: '@when',
|
|
35
|
-
error: '',
|
|
36
|
-
tokens: []
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
const result = validateAtRuleWhenQueryList(atRule.tokens, atRule);
|
|
40
|
-
if (result.valid == SyntaxValidationResult.Drop) {
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
if (!('chi' in atRule)) {
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
return {
|
|
46
|
-
valid: SyntaxValidationResult.Drop,
|
|
47
|
-
context: [],
|
|
48
|
-
node: atRule,
|
|
49
|
-
syntax: '@when',
|
|
50
|
-
error: 'expected at-rule body',
|
|
51
|
-
tokens: []
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
valid: SyntaxValidationResult.Valid,
|
|
56
|
-
context: [],
|
|
57
|
-
node: atRule,
|
|
58
|
-
syntax: '@when',
|
|
59
|
-
error: ''
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
// media() = media( [ <mf-plain> | <mf-boolean> | <mf-range> ] )
|
|
63
|
-
// supports() = supports( <declaration> )
|
|
64
|
-
function validateAtRuleWhenQueryList(tokenList, atRule) {
|
|
65
|
-
const matched = [];
|
|
66
|
-
let result = null;
|
|
67
|
-
for (const split of splitTokenList(tokenList)) {
|
|
68
|
-
const match = [];
|
|
69
|
-
result = null;
|
|
70
|
-
consumeWhitespace(split);
|
|
71
|
-
if (split.length == 0) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
while (split.length > 0) {
|
|
75
|
-
if (split[0].typ != EnumToken.FunctionTokenType || !generalEnclosedFunc.includes(split[0].val)) {
|
|
76
|
-
result = {
|
|
77
|
-
valid: SyntaxValidationResult.Drop,
|
|
78
|
-
context: [],
|
|
79
|
-
node: split[0] ?? atRule,
|
|
80
|
-
syntax: '@when',
|
|
81
|
-
error: 'unexpected token',
|
|
82
|
-
tokens: []
|
|
83
|
-
};
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
const chi = split[0].chi.slice();
|
|
87
|
-
consumeWhitespace(chi);
|
|
88
|
-
if (split[0].val == 'media') {
|
|
89
|
-
// result = valida
|
|
90
|
-
if (chi.length != 1 || !(validateMediaFeature(chi[0]) || validateMediaCondition(split[0], atRule))) {
|
|
91
|
-
result = {
|
|
92
|
-
valid: SyntaxValidationResult.Drop,
|
|
93
|
-
context: [],
|
|
94
|
-
node: split[0] ?? atRule,
|
|
95
|
-
syntax: 'media( [ <mf-plain> | <mf-boolean> | <mf-range> ] )',
|
|
96
|
-
error: 'unexpected token'
|
|
97
|
-
};
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
else if (generalEnclosedFunc.includes(split[0].val)) {
|
|
102
|
-
// result = valida
|
|
103
|
-
if (!validateSupportCondition(atRule, split[0])) {
|
|
104
|
-
result = {
|
|
105
|
-
valid: SyntaxValidationResult.Drop,
|
|
106
|
-
context: [],
|
|
107
|
-
node: split[0] ?? atRule,
|
|
108
|
-
syntax: 'media( [ <mf-plain> | <mf-boolean> | <mf-range> ] )',
|
|
109
|
-
error: 'unexpected token'
|
|
110
|
-
};
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (match.length > 0) {
|
|
115
|
-
match.push({ typ: EnumToken.WhitespaceTokenType });
|
|
116
|
-
}
|
|
117
|
-
match.push(split.shift());
|
|
118
|
-
consumeWhitespace(split);
|
|
119
|
-
if (split.length == 0) {
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
if (![EnumToken.MediaFeatureAndTokenType, EnumToken.MediaFeatureOrTokenType].includes(split[0].typ)) {
|
|
123
|
-
result = {
|
|
124
|
-
valid: SyntaxValidationResult.Drop,
|
|
125
|
-
context: [],
|
|
126
|
-
node: split[0] ?? atRule,
|
|
127
|
-
syntax: '@when',
|
|
128
|
-
error: 'expecting and/or media-condition',
|
|
129
|
-
tokens: []
|
|
130
|
-
};
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
if (match.length > 0) {
|
|
134
|
-
match.push({ typ: EnumToken.WhitespaceTokenType });
|
|
135
|
-
}
|
|
136
|
-
match.push(split.shift());
|
|
137
|
-
consumeWhitespace(split);
|
|
138
|
-
if (split.length == 0) {
|
|
139
|
-
result = {
|
|
140
|
-
valid: SyntaxValidationResult.Drop,
|
|
141
|
-
context: [],
|
|
142
|
-
node: split[0] ?? atRule,
|
|
143
|
-
syntax: '@when',
|
|
144
|
-
error: 'expecting media-condition',
|
|
145
|
-
tokens: []
|
|
146
|
-
};
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (result == null && match.length > 0) {
|
|
151
|
-
matched.push(match);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (result != null) {
|
|
155
|
-
return result;
|
|
156
|
-
}
|
|
157
|
-
if (matched.length == 0) {
|
|
158
|
-
return {
|
|
159
|
-
valid: SyntaxValidationResult.Drop,
|
|
160
|
-
context: [],
|
|
161
|
-
// @ts-ignore
|
|
162
|
-
node: result?.node ?? atRule,
|
|
163
|
-
syntax: '@when',
|
|
164
|
-
error: 'invalid at-rule body'
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
tokenList.length = 0;
|
|
168
|
-
for (const match of matched) {
|
|
169
|
-
if (tokenList.length > 0) {
|
|
170
|
-
tokenList.push({
|
|
171
|
-
typ: EnumToken.CommaTokenType
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
tokenList.push(...match);
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
valid: SyntaxValidationResult.Valid,
|
|
178
|
-
context: [],
|
|
179
|
-
node: atRule,
|
|
180
|
-
syntax: '@when',
|
|
181
|
-
error: ''
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export { validateAtRuleWhen, validateAtRuleWhenQueryList };
|