@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,342 +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 { splitTokenList } from '../utils/list.js';
11
-
12
- const validateContainerScrollStateFeature = validateContainerSizeFeature;
13
- function validateAtRuleContainer(atRule, options, root) {
14
- if (!Array.isArray(atRule.chi)) {
15
- // @ts-ignore
16
- return {
17
- valid: SyntaxValidationResult.Drop,
18
- matches: [],
19
- node: atRule,
20
- syntax: '@' + atRule.nam,
21
- error: 'expected supports body',
22
- tokens: []
23
- };
24
- }
25
- // media-query-list
26
- if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
27
- // @ts-ignore
28
- return {
29
- valid: SyntaxValidationResult.Drop,
30
- context: [],
31
- node: atRule,
32
- syntax: '@' + atRule.nam,
33
- error: 'expected supports query list'
34
- };
35
- }
36
- const result = validateAtRuleContainerQueryList(atRule.tokens, atRule);
37
- if (result.valid == SyntaxValidationResult.Drop) {
38
- return result;
39
- }
40
- if (!('chi' in atRule)) {
41
- // @ts-ignore
42
- return {
43
- valid: SyntaxValidationResult.Drop,
44
- context: [],
45
- node: atRule,
46
- syntax: '@' + atRule.nam,
47
- error: 'expected at-rule body'
48
- };
49
- }
50
- return {
51
- valid: SyntaxValidationResult.Valid,
52
- context: [],
53
- node: atRule,
54
- syntax: '@' + atRule.nam,
55
- error: '',
56
- };
57
- }
58
- function validateAtRuleContainerQueryList(tokens, atRule) {
59
- if (tokens.length == 0) {
60
- // @ts-ignore
61
- return {
62
- valid: SyntaxValidationResult.Drop,
63
- context: [],
64
- node: atRule,
65
- syntax: '@' + atRule.nam,
66
- error: 'expected container query list'
67
- };
68
- }
69
- let result = null;
70
- let tokenType = null;
71
- for (const queries of splitTokenList(tokens)) {
72
- consumeWhitespace(queries);
73
- if (queries.length == 0) {
74
- return {
75
- valid: SyntaxValidationResult.Drop,
76
- context: [],
77
- node: atRule,
78
- syntax: '@' + atRule.nam,
79
- error: 'expected container query list'
80
- };
81
- }
82
- result = null;
83
- const match = [];
84
- let token = null;
85
- tokenType = null;
86
- while (queries.length > 0) {
87
- if (queries.length == 0) {
88
- return {
89
- valid: SyntaxValidationResult.Drop,
90
- context: [],
91
- node: atRule,
92
- syntax: '@' + atRule.nam,
93
- error: 'expected container query list'
94
- };
95
- }
96
- if (queries[0].typ == EnumToken.IdenTokenType) {
97
- match.push(queries.shift());
98
- consumeWhitespace(queries);
99
- }
100
- if (queries.length == 0) {
101
- break;
102
- }
103
- token = queries[0];
104
- if (token?.typ == EnumToken.MediaFeatureNotTokenType) {
105
- token = token.val;
106
- }
107
- if (token?.typ != EnumToken.ParensTokenType && (token?.typ != EnumToken.FunctionTokenType || !['scroll-state', 'style'].includes(token.val))) {
108
- return {
109
- valid: SyntaxValidationResult.Drop,
110
- context: [],
111
- node: queries[0],
112
- syntax: '@' + atRule.nam,
113
- error: 'expected container query-in-parens'
114
- };
115
- }
116
- if (token?.typ == EnumToken.ParensTokenType) {
117
- result = validateContainerSizeFeature(token.chi, atRule);
118
- }
119
- else if (token.val == 'scroll-state') {
120
- result = validateContainerScrollStateFeature(token.chi, atRule);
121
- }
122
- else {
123
- result = validateContainerStyleFeature(token.chi, atRule);
124
- }
125
- if (result.valid == SyntaxValidationResult.Drop) {
126
- return result;
127
- }
128
- queries.shift();
129
- consumeWhitespace(queries);
130
- if (queries.length == 0) {
131
- break;
132
- }
133
- token = queries[0];
134
- if (token?.typ != EnumToken.MediaFeatureAndTokenType && token?.typ != EnumToken.MediaFeatureOrTokenType) {
135
- return {
136
- valid: SyntaxValidationResult.Drop,
137
- context: [],
138
- node: queries[0],
139
- syntax: '@' + atRule.nam,
140
- error: 'expecting and/or container query token'
141
- };
142
- }
143
- if (tokenType == null) {
144
- tokenType = token?.typ;
145
- }
146
- if (tokenType == null || tokenType != token?.typ) {
147
- return {
148
- valid: SyntaxValidationResult.Drop,
149
- context: [],
150
- node: queries[0],
151
- syntax: '@' + atRule.nam,
152
- error: 'mixing and/or not allowed at the same level'
153
- };
154
- }
155
- queries.shift();
156
- consumeWhitespace(queries);
157
- if (queries.length == 0) {
158
- return {
159
- valid: SyntaxValidationResult.Drop,
160
- context: [],
161
- node: queries[0],
162
- syntax: '@' + atRule.nam,
163
- error: 'expected container query-in-parens'
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 validateContainerStyleFeature(tokens, atRule) {
177
- tokens = tokens.slice();
178
- consumeWhitespace(tokens);
179
- if (tokens.length == 1) {
180
- if (tokens[0].typ == EnumToken.ParensTokenType) {
181
- return validateContainerStyleFeature(tokens[0].chi, atRule);
182
- }
183
- if ([EnumToken.DashedIdenTokenType, EnumToken.IdenTokenType].includes(tokens[0].typ) ||
184
- (tokens[0].typ == EnumToken.MediaQueryConditionTokenType && tokens[0].op.typ == EnumToken.ColonTokenType)) {
185
- return {
186
- valid: SyntaxValidationResult.Valid,
187
- context: [],
188
- node: atRule,
189
- syntax: '@' + atRule.nam,
190
- error: ''
191
- };
192
- }
193
- }
194
- return {
195
- valid: SyntaxValidationResult.Drop,
196
- context: [],
197
- node: atRule,
198
- syntax: '@' + atRule.nam,
199
- error: 'expected container query features'
200
- };
201
- }
202
- function validateContainerSizeFeature(tokens, atRule) {
203
- tokens = tokens.slice();
204
- consumeWhitespace(tokens);
205
- if (tokens.length == 0) {
206
- return {
207
- valid: SyntaxValidationResult.Drop,
208
- context: [],
209
- node: atRule,
210
- syntax: '@' + atRule.nam,
211
- error: 'expected container query features'
212
- };
213
- }
214
- if (tokens.length == 1) {
215
- const token = tokens[0];
216
- if (token.typ == EnumToken.MediaFeatureNotTokenType) {
217
- return validateContainerSizeFeature([token.val], atRule);
218
- }
219
- if (token.typ == EnumToken.ParensTokenType) {
220
- return validateAtRuleContainerQueryStyleInParams(token.chi, atRule);
221
- }
222
- if (![EnumToken.DashedIdenTokenType, EnumToken.MediaQueryConditionTokenType].includes(tokens[0].typ)) {
223
- return {
224
- valid: SyntaxValidationResult.Drop,
225
- context: [],
226
- node: atRule,
227
- syntax: '@' + atRule.nam,
228
- error: 'expected container query features'
229
- };
230
- }
231
- return {
232
- valid: SyntaxValidationResult.Valid,
233
- context: [],
234
- node: atRule,
235
- syntax: '@' + atRule.nam,
236
- error: ''
237
- };
238
- }
239
- return validateAtRuleContainerQueryStyleInParams(tokens, atRule);
240
- }
241
- function validateAtRuleContainerQueryStyleInParams(tokens, atRule) {
242
- tokens = tokens.slice();
243
- consumeWhitespace(tokens);
244
- if (tokens.length == 0) {
245
- return {
246
- valid: SyntaxValidationResult.Drop,
247
- context: [],
248
- node: atRule,
249
- syntax: '@' + atRule.nam,
250
- error: 'expected container query features'
251
- };
252
- }
253
- let token = tokens[0];
254
- let tokenType = null;
255
- let result = null;
256
- while (tokens.length > 0) {
257
- token = tokens[0];
258
- if (token.typ == EnumToken.MediaFeatureNotTokenType) {
259
- token = token.val;
260
- }
261
- if (tokens[0].typ != EnumToken.ParensTokenType) {
262
- return {
263
- valid: SyntaxValidationResult.Drop,
264
- context: [],
265
- node: atRule,
266
- syntax: '@' + atRule.nam,
267
- error: 'expected container query-in-parens'
268
- };
269
- }
270
- const slices = tokens[0].chi.slice();
271
- consumeWhitespace(slices);
272
- if (slices.length == 1) {
273
- if ([EnumToken.MediaFeatureNotTokenType, EnumToken.ParensTokenType].includes(slices[0].typ)) {
274
- result = validateAtRuleContainerQueryStyleInParams(slices, atRule);
275
- if (result.valid == SyntaxValidationResult.Drop) {
276
- return result;
277
- }
278
- }
279
- else if (![EnumToken.DashedIdenTokenType, EnumToken.MediaQueryConditionTokenType].includes(slices[0].typ)) {
280
- result = {
281
- valid: SyntaxValidationResult.Drop,
282
- context: [],
283
- node: atRule,
284
- syntax: '@' + atRule.nam,
285
- error: 'expected container query features'
286
- };
287
- }
288
- }
289
- else {
290
- result = validateAtRuleContainerQueryStyleInParams(slices, atRule);
291
- if (result.valid == SyntaxValidationResult.Drop) {
292
- return result;
293
- }
294
- }
295
- tokens.shift();
296
- consumeWhitespace(tokens);
297
- if (tokens.length == 0) {
298
- break;
299
- }
300
- if (![EnumToken.MediaFeatureAndTokenType, EnumToken.MediaFeatureOrTokenType].includes(tokens[0].typ)) {
301
- return {
302
- valid: SyntaxValidationResult.Drop,
303
- context: [],
304
- node: tokens[0],
305
- syntax: '@' + atRule.nam,
306
- error: 'expecting and/or container query token'
307
- };
308
- }
309
- if (tokenType == null) {
310
- tokenType = tokens[0].typ;
311
- }
312
- if (tokenType != tokens[0].typ) {
313
- return {
314
- valid: SyntaxValidationResult.Drop,
315
- context: [],
316
- node: tokens[0],
317
- syntax: '@' + atRule.nam,
318
- error: 'mixing and/or not allowed at the same level'
319
- };
320
- }
321
- tokens.shift();
322
- consumeWhitespace(tokens);
323
- if (tokens.length == 0) {
324
- return {
325
- valid: SyntaxValidationResult.Drop,
326
- context: [],
327
- node: tokens[0],
328
- syntax: '@' + atRule.nam,
329
- error: 'expected container query-in-parens'
330
- };
331
- }
332
- }
333
- return {
334
- valid: SyntaxValidationResult.Valid,
335
- context: [],
336
- node: atRule,
337
- syntax: '@' + atRule.nam,
338
- error: ''
339
- };
340
- }
341
-
342
- export { validateAtRuleContainer };
@@ -1,90 +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 validateAtRuleCounterStyle(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
- // media-query-list
23
- if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
24
- // @ts-ignore
25
- return {
26
- valid: SyntaxValidationResult.Drop,
27
- matches: [],
28
- node: atRule,
29
- syntax: '@counter-style',
30
- error: 'expected counter style name',
31
- tokens: []
32
- };
33
- }
34
- const tokens = atRule.tokens.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ));
35
- if (tokens.length == 0) {
36
- // @ts-ignore
37
- return {
38
- valid: SyntaxValidationResult.Drop,
39
- matches: [],
40
- node: atRule,
41
- syntax: '@counter-style',
42
- error: 'expected counter style name',
43
- tokens
44
- };
45
- }
46
- if (tokens.length > 1) {
47
- // @ts-ignore
48
- return {
49
- valid: SyntaxValidationResult.Drop,
50
- matches: [],
51
- node: tokens[1] ?? atRule,
52
- syntax: '@counter-style',
53
- error: 'unexpected token',
54
- tokens
55
- };
56
- }
57
- if (![EnumToken.IdenTokenType, EnumToken.DashedIdenTokenType].includes(tokens[0].typ)) {
58
- // @ts-ignore
59
- return {
60
- valid: SyntaxValidationResult.Drop,
61
- matches: [],
62
- node: tokens[0],
63
- syntax: '@counter-style',
64
- error: 'expected counter style name',
65
- tokens
66
- };
67
- }
68
- if (!('chi' in atRule)) {
69
- // @ts-ignore
70
- return {
71
- valid: SyntaxValidationResult.Drop,
72
- matches: [],
73
- node: atRule,
74
- syntax: '@counter-style',
75
- error: 'expected counter style body',
76
- tokens
77
- };
78
- }
79
- // @ts-ignore
80
- return {
81
- valid: SyntaxValidationResult.Valid,
82
- matches: [],
83
- node: atRule,
84
- syntax: '@counter-style',
85
- error: '',
86
- tokens
87
- };
88
- }
89
-
90
- export { validateAtRuleCounterStyle };
@@ -1,50 +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 { validateAtRuleMediaQueryList } from './media.js';
11
-
12
- function validateAtRuleCustomMedia(atRule, options, root) {
13
- // media-query-list
14
- if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
15
- // @ts-ignore
16
- return {
17
- valid: SyntaxValidationResult.Valid,
18
- context: [],
19
- node: null,
20
- syntax: null,
21
- error: ''
22
- };
23
- }
24
- const queries = atRule.tokens.slice();
25
- consumeWhitespace(queries);
26
- if (queries.length == 0 || queries[0].typ != EnumToken.DashedIdenTokenType) {
27
- return {
28
- valid: SyntaxValidationResult.Drop,
29
- context: [],
30
- node: atRule,
31
- syntax: '@custom-media',
32
- error: 'expecting dashed identifier'
33
- };
34
- }
35
- queries.shift();
36
- const result = validateAtRuleMediaQueryList(queries, atRule);
37
- if (result.valid == SyntaxValidationResult.Drop) {
38
- atRule.tokens = [];
39
- return {
40
- valid: SyntaxValidationResult.Valid,
41
- context: [],
42
- node: atRule,
43
- syntax: '@custom-media',
44
- error: ''
45
- };
46
- }
47
- return result;
48
- }
49
-
50
- export { validateAtRuleCustomMedia };
@@ -1,89 +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 { splitTokenList } from '../utils/list.js';
11
- import { validateURL } from '../syntaxes/url.js';
12
-
13
- function validateAtRuleDocument(atRule, options, root) {
14
- if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
15
- // @ts-ignore
16
- return {
17
- valid: SyntaxValidationResult.Drop,
18
- context: [],
19
- node: atRule,
20
- syntax: '@document',
21
- error: 'expecting at-rule prelude'
22
- };
23
- }
24
- const tokens = atRule.tokens.slice();
25
- let result = null;
26
- consumeWhitespace(tokens);
27
- if (tokens.length == 0) {
28
- // @ts-ignore
29
- return {
30
- valid: SyntaxValidationResult.Drop,
31
- context: [],
32
- node: atRule,
33
- syntax: '@document',
34
- error: 'expecting at-rule prelude'
35
- };
36
- }
37
- for (const t of splitTokenList(tokens)) {
38
- if (t.length != 1) {
39
- return {
40
- valid: SyntaxValidationResult.Drop,
41
- context: [],
42
- node: t[0] ?? atRule,
43
- syntax: '@document',
44
- error: 'unexpected token'
45
- };
46
- }
47
- // @ts-ignore
48
- if ((t[0].typ != EnumToken.FunctionTokenType && t[0].typ != EnumToken.UrlFunctionTokenType) || !['url', 'url-prefix', 'domain', 'media-document', 'regexp'].includes(t[0].val?.toLowerCase?.())) {
49
- return {
50
- valid: SyntaxValidationResult.Drop,
51
- context: [],
52
- node: t[0] ?? atRule,
53
- syntax: '@document',
54
- error: 'expecting any of url-prefix(), domain(), media-document(), regexp() but found ' + t[0].val
55
- };
56
- }
57
- if (t[0].typ == EnumToken.UrlFunctionTokenType) {
58
- result = validateURL(t[0]);
59
- if (result?.valid == SyntaxValidationResult.Drop) {
60
- return result;
61
- }
62
- continue;
63
- }
64
- const children = t[0].chi.slice();
65
- consumeWhitespace(children);
66
- if (children.length != 1 || (children[0].typ != EnumToken.StringTokenType && children[0].typ != EnumToken.UrlTokenTokenType)) {
67
- // @ts-ignore
68
- return {
69
- valid: SyntaxValidationResult.Drop,
70
- context: [],
71
- node: tokens[0],
72
- syntax: '@document',
73
- error: 'expecting string argument'
74
- };
75
- }
76
- tokens.shift();
77
- consumeWhitespace(tokens);
78
- }
79
- // @ts-ignore
80
- return {
81
- valid: SyntaxValidationResult.Valid,
82
- context: [],
83
- node: atRule,
84
- syntax: '@document',
85
- error: ''
86
- };
87
- }
88
-
89
- export { validateAtRuleDocument };
@@ -1,5 +0,0 @@
1
- import { validateAtRuleWhen } from './when.js';
2
-
3
- const validateAtRuleElse = validateAtRuleWhen;
4
-
5
- export { validateAtRuleElse };
@@ -1,63 +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 { validateFamilyName } from '../syntaxes/family-name.js';
10
- import '../syntaxes/complex-selector.js';
11
- import '../syntax.js';
12
- import '../config.js';
13
-
14
- function validateAtRuleFontFeatureValues(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
- if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
27
- // @ts-ignore
28
- return {
29
- valid: SyntaxValidationResult.Drop,
30
- matches: [],
31
- node: null,
32
- syntax: '@' + atRule.nam,
33
- error: 'expected at-rule prelude',
34
- tokens: []
35
- };
36
- }
37
- const result = validateFamilyName(atRule.tokens);
38
- if (result.valid == SyntaxValidationResult.Drop) {
39
- return result;
40
- }
41
- if (!('chi' in atRule)) {
42
- // @ts-ignore
43
- return {
44
- valid: SyntaxValidationResult.Drop,
45
- matches: [],
46
- node: atRule,
47
- syntax: '@' + atRule.nam,
48
- error: 'expected at-rule body',
49
- tokens: []
50
- };
51
- }
52
- // @ts-ignore
53
- return {
54
- valid: SyntaxValidationResult.Valid,
55
- matches: [],
56
- node: atRule,
57
- syntax: '@' + atRule.nam,
58
- error: '',
59
- tokens: []
60
- };
61
- }
62
-
63
- export { validateAtRuleFontFeatureValues };