@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.
Files changed (122) hide show
  1. package/CHANGELOG.md +354 -4
  2. package/README.md +69 -1077
  3. package/dist/config.json.js +76 -3
  4. package/dist/index-umd-web.js +26838 -18743
  5. package/dist/index.cjs +26819 -18731
  6. package/dist/index.d.ts +2471 -1884
  7. package/dist/lib/ast/clone.js +46 -0
  8. package/dist/lib/ast/expand.js +90 -65
  9. package/dist/lib/ast/features/calc.js +86 -43
  10. package/dist/lib/ast/features/if.js +221 -0
  11. package/dist/lib/ast/features/index.js +1 -0
  12. package/dist/lib/ast/features/inlinecssvariables.js +33 -28
  13. package/dist/lib/ast/features/prefix.js +406 -44
  14. package/dist/lib/ast/features/shorthand.js +6 -9
  15. package/dist/lib/ast/features/transform.js +14 -15
  16. package/dist/lib/ast/find.js +175 -0
  17. package/dist/lib/ast/math/expression.js +145 -99
  18. package/dist/lib/ast/math/math.js +30 -41
  19. package/dist/lib/ast/minify.js +551 -232
  20. package/dist/lib/ast/transform/compute.js +82 -69
  21. package/dist/lib/ast/transform/matrix.js +12 -26
  22. package/dist/lib/ast/transform/minify.js +154 -150
  23. package/dist/lib/ast/transform/perspective.js +1 -1
  24. package/dist/lib/ast/transform/rotate.js +1 -1
  25. package/dist/lib/ast/transform/scale.js +1 -1
  26. package/dist/lib/ast/transform/skew.js +1 -1
  27. package/dist/lib/ast/transform/translate.js +1 -1
  28. package/dist/lib/ast/transform/utils.js +3 -2
  29. package/dist/lib/ast/types.js +345 -30
  30. package/dist/lib/ast/walk.js +119 -64
  31. package/dist/lib/fs/resolve.js +94 -88
  32. package/dist/lib/parser/declaration/list.js +117 -26
  33. package/dist/lib/parser/declaration/map.js +141 -96
  34. package/dist/lib/parser/declaration/set.js +30 -25
  35. package/dist/lib/parser/parse.js +1810 -1739
  36. package/dist/lib/parser/tokenize.js +662 -403
  37. package/dist/lib/parser/utils/angle.js +29 -0
  38. package/dist/lib/parser/utils/at-rule-container.js +486 -0
  39. package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
  40. package/dist/lib/parser/utils/at-rule-generic.js +118 -0
  41. package/dist/lib/parser/utils/at-rule-import.js +393 -0
  42. package/dist/lib/parser/utils/at-rule-media.js +603 -0
  43. package/dist/lib/parser/utils/at-rule-support.js +431 -0
  44. package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
  45. package/dist/lib/parser/utils/at-rule.js +31 -0
  46. package/dist/lib/parser/utils/cache.js +19 -0
  47. package/dist/lib/parser/utils/config.js +1 -0
  48. package/dist/lib/parser/utils/declaration.js +672 -91
  49. package/dist/lib/parser/utils/hash.js +1 -1
  50. package/dist/lib/parser/utils/selector.js +518 -0
  51. package/dist/lib/parser/utils/text.js +17 -1
  52. package/dist/lib/parser/utils/token.js +104 -0
  53. package/dist/lib/parser/utils/type.js +29 -18
  54. package/dist/lib/renderer/render.js +870 -269
  55. package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
  56. package/dist/lib/syntax/color/a98rgb.js +8 -12
  57. package/dist/lib/syntax/color/alpha.js +64 -0
  58. package/dist/lib/syntax/color/cmyk.js +23 -21
  59. package/dist/lib/syntax/color/color-mix.js +311 -237
  60. package/dist/lib/syntax/color/color.js +98 -92
  61. package/dist/lib/syntax/color/hex.js +29 -33
  62. package/dist/lib/syntax/color/hsl.js +7 -14
  63. package/dist/lib/syntax/color/hwb.js +14 -27
  64. package/dist/lib/syntax/color/lab.js +23 -24
  65. package/dist/lib/syntax/color/lch.js +16 -18
  66. package/dist/lib/syntax/color/oklab.js +21 -40
  67. package/dist/lib/syntax/color/oklch.js +16 -18
  68. package/dist/lib/syntax/color/p3.js +0 -8
  69. package/dist/lib/syntax/color/rec2020.js +9 -13
  70. package/dist/lib/syntax/color/relativecolor.js +160 -48
  71. package/dist/lib/syntax/color/rgb.js +14 -18
  72. package/dist/lib/syntax/color/srgb.js +30 -29
  73. package/dist/lib/syntax/color/utils/color-type.js +18 -0
  74. package/dist/lib/syntax/color/utils/colorspace.js +46 -0
  75. package/dist/lib/syntax/color/utils/components.js +36 -16
  76. package/dist/lib/syntax/color/utils/distance.js +21 -11
  77. package/dist/lib/syntax/color/utils/make-color.js +56 -0
  78. package/dist/lib/syntax/color/xyz.js +10 -22
  79. package/dist/lib/syntax/color/xyzd50.js +6 -20
  80. package/dist/lib/syntax/constants.js +464 -0
  81. package/dist/lib/syntax/syntax.js +825 -592
  82. package/dist/lib/validation/config.js +72 -33
  83. package/dist/lib/validation/config.json.js +1185 -85
  84. package/dist/lib/validation/match.js +3120 -0
  85. package/dist/lib/validation/parser/parse.js +683 -935
  86. package/dist/lib/validation/parser/typedef.js +106 -0
  87. package/dist/lib/validation/utils/list.js +4 -11
  88. package/dist/lib/validation/utils/whitespace.js +2 -8
  89. package/dist/node.js +102 -57
  90. package/dist/web.js +100 -48
  91. package/package.json +31 -17
  92. package/dist/lib/syntax/color/utils/constants.js +0 -214
  93. package/dist/lib/syntax/utils.js +0 -70
  94. package/dist/lib/validation/at-rules/container.js +0 -342
  95. package/dist/lib/validation/at-rules/counter-style.js +0 -90
  96. package/dist/lib/validation/at-rules/custom-media.js +0 -50
  97. package/dist/lib/validation/at-rules/document.js +0 -89
  98. package/dist/lib/validation/at-rules/else.js +0 -5
  99. package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
  100. package/dist/lib/validation/at-rules/import.js +0 -150
  101. package/dist/lib/validation/at-rules/keyframes.js +0 -67
  102. package/dist/lib/validation/at-rules/layer.js +0 -41
  103. package/dist/lib/validation/at-rules/media.js +0 -255
  104. package/dist/lib/validation/at-rules/namespace.js +0 -81
  105. package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
  106. package/dist/lib/validation/at-rules/page.js +0 -100
  107. package/dist/lib/validation/at-rules/supports.js +0 -295
  108. package/dist/lib/validation/at-rules/when.js +0 -185
  109. package/dist/lib/validation/atrule.js +0 -184
  110. package/dist/lib/validation/selector.js +0 -36
  111. package/dist/lib/validation/syntax.js +0 -1073
  112. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
  113. package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
  114. package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
  115. package/dist/lib/validation/syntaxes/family-name.js +0 -57
  116. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
  117. package/dist/lib/validation/syntaxes/layer-name.js +0 -57
  118. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
  119. package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
  120. package/dist/lib/validation/syntaxes/selector-list.js +0 -5
  121. package/dist/lib/validation/syntaxes/selector.js +0 -5
  122. 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 };