@tbela99/css-parser 0.7.1 → 0.8.0

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 (82) hide show
  1. package/README.md +136 -82
  2. package/dist/index-umd-web.js +6956 -51524
  3. package/dist/index.cjs +6955 -51528
  4. package/dist/index.d.ts +180 -65
  5. package/dist/lib/ast/expand.js +34 -9
  6. package/dist/lib/ast/features/calc.js +76 -12
  7. package/dist/lib/ast/features/inlinecssvariables.js +6 -1
  8. package/dist/lib/ast/features/prefix.js +17 -9
  9. package/dist/lib/ast/features/shorthand.js +1 -0
  10. package/dist/lib/ast/math/expression.js +299 -11
  11. package/dist/lib/ast/math/math.js +7 -1
  12. package/dist/lib/ast/minify.js +1 -1
  13. package/dist/lib/ast/types.js +58 -49
  14. package/dist/lib/ast/walk.js +80 -18
  15. package/dist/lib/parser/declaration/list.js +1 -0
  16. package/dist/lib/parser/declaration/map.js +1 -0
  17. package/dist/lib/parser/declaration/set.js +1 -0
  18. package/dist/lib/parser/parse.js +285 -72
  19. package/dist/lib/parser/tokenize.js +16 -3
  20. package/dist/lib/parser/utils/declaration.js +2 -2
  21. package/dist/lib/parser/utils/type.js +6 -6
  22. package/dist/lib/renderer/color/a98rgb.js +1 -0
  23. package/dist/lib/renderer/color/color.js +1 -0
  24. package/dist/lib/renderer/color/colormix.js +1 -0
  25. package/dist/lib/renderer/color/hex.js +1 -0
  26. package/dist/lib/renderer/color/hsl.js +1 -0
  27. package/dist/lib/renderer/color/hwb.js +1 -0
  28. package/dist/lib/renderer/color/lab.js +1 -0
  29. package/dist/lib/renderer/color/lch.js +1 -0
  30. package/dist/lib/renderer/color/oklab.js +1 -0
  31. package/dist/lib/renderer/color/oklch.js +1 -0
  32. package/dist/lib/renderer/color/p3.js +1 -0
  33. package/dist/lib/renderer/color/prophotoRgb.js +56 -0
  34. package/dist/lib/renderer/color/rec2020.js +1 -0
  35. package/dist/lib/renderer/color/relativecolor.js +52 -28
  36. package/dist/lib/renderer/color/rgb.js +1 -0
  37. package/dist/lib/renderer/color/srgb.js +1 -0
  38. package/dist/lib/renderer/color/utils/components.js +1 -0
  39. package/dist/lib/renderer/color/utils/constants.js +1 -0
  40. package/dist/lib/renderer/color/xyz.js +1 -0
  41. package/dist/lib/renderer/color/xyzd50.js +1 -0
  42. package/dist/lib/renderer/render.js +28 -6
  43. package/dist/lib/syntax/syntax.js +27 -4
  44. package/dist/lib/validation/at-rules/counter-style.js +78 -0
  45. package/dist/lib/validation/at-rules/document.js +114 -0
  46. package/dist/lib/validation/at-rules/font-feature-values.js +49 -0
  47. package/dist/lib/validation/at-rules/import.js +196 -0
  48. package/dist/lib/validation/at-rules/keyframes.js +70 -0
  49. package/dist/lib/validation/at-rules/layer.js +27 -0
  50. package/dist/lib/validation/at-rules/media.js +166 -0
  51. package/dist/lib/validation/at-rules/namespace.js +85 -0
  52. package/dist/lib/validation/at-rules/page-margin-box.js +56 -0
  53. package/dist/lib/validation/at-rules/page.js +88 -0
  54. package/dist/lib/validation/at-rules/supports.js +262 -0
  55. package/dist/lib/validation/atrule.js +172 -0
  56. package/dist/lib/validation/config.js +30 -2
  57. package/dist/lib/validation/config.json.js +1560 -50902
  58. package/dist/lib/validation/declaration.js +72 -0
  59. package/dist/lib/validation/parser/parse.js +1059 -7
  60. package/dist/lib/validation/parser/types.js +27 -12
  61. package/dist/lib/validation/selector.js +23 -444
  62. package/dist/lib/validation/syntax.js +1429 -0
  63. package/dist/lib/validation/syntaxes/complex-selector-list.js +41 -0
  64. package/dist/lib/validation/syntaxes/complex-selector.js +283 -0
  65. package/dist/lib/validation/syntaxes/family-name.js +91 -0
  66. package/dist/lib/validation/syntaxes/keyframe-block-list.js +27 -0
  67. package/dist/lib/validation/syntaxes/keyframe-selector.js +137 -0
  68. package/dist/lib/validation/syntaxes/layer-name.js +67 -0
  69. package/dist/lib/validation/syntaxes/relative-selector-list.js +27 -0
  70. package/dist/lib/validation/syntaxes/relative-selector.js +36 -0
  71. package/dist/lib/validation/syntaxes/selector-list.js +5 -0
  72. package/dist/lib/validation/syntaxes/selector.js +5 -0
  73. package/dist/lib/validation/syntaxes/url.js +75 -0
  74. package/dist/lib/validation/utils/list.js +24 -0
  75. package/dist/lib/validation/utils/whitespace.js +22 -0
  76. package/dist/node/index.js +4 -4
  77. package/dist/web/index.js +4 -0
  78. package/dist/web/load.js +1 -0
  79. package/package.json +15 -13
  80. package/dist/lib/ast/utils/minifyfeature.js +0 -9
  81. package/dist/lib/iterable/weakset.js +0 -58
  82. package/dist/lib/parser/utils/syntax.js +0 -450
@@ -0,0 +1,41 @@
1
+ import { ValidationLevel, EnumToken } from '../../ast/types.js';
2
+ import '../../ast/minify.js';
3
+ import '../../ast/walk.js';
4
+ import '../../parser/parse.js';
5
+ import '../../renderer/color/utils/constants.js';
6
+ import '../../renderer/sourcemap/lib/encode.js';
7
+ import '../../parser/utils/config.js';
8
+ import { validateSelector } from './selector.js';
9
+ import { consumeWhitespace } from '../utils/whitespace.js';
10
+
11
+ function validateComplexSelectorList(tokens, root, options) {
12
+ tokens = tokens.slice();
13
+ consumeWhitespace(tokens);
14
+ if (tokens.length == 0) {
15
+ return {
16
+ valid: ValidationLevel.Drop,
17
+ matches: [],
18
+ // @ts-ignore
19
+ node: root,
20
+ syntax: null,
21
+ error: 'expecting complex selector list',
22
+ tokens
23
+ };
24
+ }
25
+ let i = -1;
26
+ let j = 0;
27
+ let result = null;
28
+ while (i + 1 < tokens.length) {
29
+ if (tokens[++i].typ == EnumToken.CommaTokenType) {
30
+ result = validateSelector(tokens.slice(j, i), root, options);
31
+ if (result.valid == ValidationLevel.Drop) {
32
+ return result;
33
+ }
34
+ j = i + 1;
35
+ i = j;
36
+ }
37
+ }
38
+ return validateSelector(i == j ? tokens.slice(i) : tokens.slice(j, i + 1), root, options);
39
+ }
40
+
41
+ export { validateComplexSelectorList };
@@ -0,0 +1,283 @@
1
+ import { consumeWhitespace } from '../utils/whitespace.js';
2
+ import { EnumToken, ValidationLevel } from '../../ast/types.js';
3
+ import '../../ast/minify.js';
4
+ import '../../ast/walk.js';
5
+ import '../../parser/parse.js';
6
+ import '../../renderer/color/utils/constants.js';
7
+ import '../../renderer/sourcemap/lib/encode.js';
8
+ import '../../parser/utils/config.js';
9
+
10
+ const combinatorsTokens = [EnumToken.ChildCombinatorTokenType, EnumToken.ColumnCombinatorTokenType,
11
+ EnumToken.DescendantCombinatorTokenType, EnumToken.NextSiblingCombinatorTokenType, EnumToken.SubsequentSiblingCombinatorTokenType];
12
+ // <compound-selector> [ <combinator>? <compound-selector> ]*
13
+ function validateComplexSelector(tokens, root, options) {
14
+ // [ <type-selector>? <subclass-selector>* [ <pseudo-element-selector> <pseudo-class-selector>* ]* ]!
15
+ tokens = tokens.slice();
16
+ consumeWhitespace(tokens);
17
+ if (tokens.length == 0) {
18
+ return {
19
+ valid: ValidationLevel.Drop,
20
+ matches: [],
21
+ // @ts-ignore
22
+ node: root,
23
+ syntax: null,
24
+ error: 'expected selector',
25
+ tokens
26
+ };
27
+ }
28
+ while (tokens.length > 0) {
29
+ if (combinatorsTokens.includes(tokens[0].typ)) {
30
+ // @ts-ignore
31
+ return {
32
+ valid: ValidationLevel.Drop,
33
+ matches: [],
34
+ // @ts-ignore
35
+ node: tokens[0],
36
+ syntax: null,
37
+ error: 'unexpected combinator',
38
+ tokens
39
+ };
40
+ }
41
+ if (tokens[0].typ == EnumToken.NestingSelectorTokenType) {
42
+ if (!options?.nestedSelector) {
43
+ // @ts-ignore
44
+ return {
45
+ valid: ValidationLevel.Drop,
46
+ matches: [],
47
+ // @ts-ignore
48
+ node: tokens[0],
49
+ syntax: null,
50
+ error: 'nested selector not allowed',
51
+ tokens
52
+ };
53
+ }
54
+ while (tokens.length > 0 && tokens[0].typ == EnumToken.NestingSelectorTokenType) {
55
+ tokens.shift();
56
+ consumeWhitespace(tokens);
57
+ }
58
+ if (tokens.length == 0) {
59
+ break;
60
+ }
61
+ }
62
+ if (EnumToken.IdenTokenType == tokens[0].typ) {
63
+ tokens.shift();
64
+ consumeWhitespace(tokens);
65
+ if (tokens.length == 0) {
66
+ break;
67
+ }
68
+ }
69
+ if (EnumToken.UniversalSelectorTokenType == tokens[0].typ) {
70
+ tokens.shift();
71
+ consumeWhitespace(tokens);
72
+ }
73
+ while (tokens.length > 0) {
74
+ if (tokens[0].typ == EnumToken.PseudoClassFuncTokenType) {
75
+ if (tokens[0].val.startsWith(':-webkit-')) {
76
+ // @ts-ignore
77
+ return {
78
+ valid: ValidationLevel.Drop,
79
+ matches: [],
80
+ // @ts-ignore
81
+ node: tokens[0],
82
+ syntax: null,
83
+ error: 'invalid pseudo-class',
84
+ tokens
85
+ };
86
+ }
87
+ }
88
+ if ([
89
+ EnumToken.ClassSelectorTokenType,
90
+ EnumToken.HashTokenType,
91
+ EnumToken.PseudoClassTokenType,
92
+ EnumToken.PseudoClassFuncTokenType
93
+ ].includes(tokens[0].typ)) {
94
+ tokens.shift();
95
+ consumeWhitespace(tokens);
96
+ continue;
97
+ }
98
+ if (tokens[0].typ == EnumToken.NestingSelectorTokenType) {
99
+ if (!options?.nestedSelector) {
100
+ // @ts-ignore
101
+ return {
102
+ valid: ValidationLevel.Drop,
103
+ matches: [],
104
+ // @ts-ignore
105
+ node: tokens[0],
106
+ syntax: null,
107
+ error: 'nested selector not allowed',
108
+ tokens
109
+ };
110
+ }
111
+ tokens.shift();
112
+ consumeWhitespace(tokens);
113
+ continue;
114
+ }
115
+ // validate namespace
116
+ if (tokens[0].typ == EnumToken.NameSpaceAttributeTokenType) {
117
+ if (!((tokens[0].l == null || tokens[0].l.typ == EnumToken.IdenTokenType || (tokens[0].l.typ == EnumToken.LiteralTokenType && tokens[0].l.val == '*')) &&
118
+ tokens[0].r.typ == EnumToken.IdenTokenType)) {
119
+ // @ts-ignore
120
+ return {
121
+ valid: ValidationLevel.Drop,
122
+ matches: [],
123
+ node: tokens[0],
124
+ syntax: null,
125
+ error: 'expecting wq-name',
126
+ tokens
127
+ };
128
+ }
129
+ tokens.shift();
130
+ consumeWhitespace(tokens);
131
+ continue;
132
+ }
133
+ // validate attribute
134
+ else if (tokens[0].typ == EnumToken.AttrTokenType) {
135
+ const children = tokens[0].chi.slice();
136
+ consumeWhitespace(children);
137
+ if (children.length == 0) {
138
+ // @ts-ignore
139
+ return {
140
+ valid: ValidationLevel.Drop,
141
+ matches: [],
142
+ node: tokens[0],
143
+ syntax: null,
144
+ error: 'invalid attribute selector',
145
+ tokens
146
+ };
147
+ }
148
+ if (![
149
+ EnumToken.IdenTokenType,
150
+ EnumToken.NameSpaceAttributeTokenType,
151
+ EnumToken.MatchExpressionTokenType
152
+ ].includes(children[0].typ)) {
153
+ // @ts-ignore
154
+ return {
155
+ valid: ValidationLevel.Drop,
156
+ matches: [],
157
+ node: tokens[0],
158
+ syntax: null,
159
+ error: 'invalid attribute selector',
160
+ tokens
161
+ };
162
+ }
163
+ if (children[0].typ == EnumToken.MatchExpressionTokenType) {
164
+ if (![EnumToken.IdenTokenType,
165
+ EnumToken.NameSpaceAttributeTokenType].includes(children[0].l.typ) ||
166
+ ![
167
+ EnumToken.EqualMatchTokenType, EnumToken.DashMatchTokenType,
168
+ EnumToken.StartMatchTokenType, EnumToken.ContainMatchTokenType,
169
+ EnumToken.EndMatchTokenType, EnumToken.IncludeMatchTokenType
170
+ ].includes(children[0].op.typ) ||
171
+ ![EnumToken.StringTokenType,
172
+ EnumToken.IdenTokenType].includes(children[0].r.typ)) {
173
+ // @ts-ignore
174
+ return {
175
+ valid: ValidationLevel.Drop,
176
+ matches: [],
177
+ node: tokens[0],
178
+ syntax: null,
179
+ error: 'invalid attribute selector',
180
+ tokens
181
+ };
182
+ }
183
+ if (children[0].attr != null && !['i', 's'].includes(children[0].attr)) {
184
+ // @ts-ignore
185
+ return {
186
+ valid: ValidationLevel.Drop,
187
+ matches: [],
188
+ node: tokens[0],
189
+ syntax: null,
190
+ error: 'invalid attribute selector',
191
+ tokens
192
+ };
193
+ }
194
+ }
195
+ children.shift();
196
+ consumeWhitespace(children);
197
+ if (children.length > 0) {
198
+ // @ts-ignore
199
+ return {
200
+ valid: ValidationLevel.Drop,
201
+ matches: [],
202
+ node: children[0],
203
+ syntax: null,
204
+ error: 'unexpected token',
205
+ tokens
206
+ };
207
+ }
208
+ tokens.shift();
209
+ consumeWhitespace(tokens);
210
+ continue;
211
+ }
212
+ break;
213
+ }
214
+ if (tokens.length == 0) {
215
+ break;
216
+ }
217
+ // combinator
218
+ if (!combinatorsTokens.includes(tokens[0].typ)) {
219
+ if (tokens[0].typ == EnumToken.NestingSelectorTokenType) {
220
+ if (!options?.nestedSelector) {
221
+ // @ts-ignore
222
+ return {
223
+ valid: ValidationLevel.Drop,
224
+ matches: [],
225
+ // @ts-ignore
226
+ node: tokens[0],
227
+ syntax: null,
228
+ error: 'nested selector not allowed',
229
+ tokens
230
+ };
231
+ }
232
+ tokens.shift();
233
+ consumeWhitespace(tokens);
234
+ continue;
235
+ }
236
+ if (tokens.length > 0 &&
237
+ [
238
+ EnumToken.IdenTokenType,
239
+ EnumToken.AttrTokenType,
240
+ EnumToken.NameSpaceAttributeTokenType,
241
+ EnumToken.ClassSelectorTokenType,
242
+ EnumToken.HashTokenType,
243
+ EnumToken.PseudoClassTokenType,
244
+ EnumToken.PseudoClassFuncTokenType
245
+ ].includes(tokens[0].typ)) {
246
+ continue;
247
+ }
248
+ // @ts-ignore
249
+ return {
250
+ valid: ValidationLevel.Drop,
251
+ matches: [],
252
+ node: tokens[0],
253
+ syntax: null,
254
+ error: 'expecting combinator or subclass-selector',
255
+ tokens
256
+ };
257
+ }
258
+ const token = tokens.shift();
259
+ consumeWhitespace(tokens);
260
+ if (tokens.length == 0) {
261
+ // @ts-ignore
262
+ return {
263
+ valid: ValidationLevel.Drop,
264
+ matches: [],
265
+ node: token,
266
+ syntax: null,
267
+ error: 'expected compound-selector',
268
+ tokens
269
+ };
270
+ }
271
+ }
272
+ // @ts-ignore
273
+ return {
274
+ valid: ValidationLevel.Valid,
275
+ matches: [],
276
+ node: null,
277
+ syntax: null,
278
+ error: '',
279
+ tokens
280
+ };
281
+ }
282
+
283
+ export { combinatorsTokens, validateComplexSelector };
@@ -0,0 +1,91 @@
1
+ import { ValidationLevel, EnumToken } from '../../ast/types.js';
2
+ import '../../ast/minify.js';
3
+ import '../../ast/walk.js';
4
+ import '../../parser/parse.js';
5
+ import '../../renderer/color/utils/constants.js';
6
+ import '../../renderer/sourcemap/lib/encode.js';
7
+ import '../../parser/utils/config.js';
8
+ import { consumeWhitespace } from '../utils/whitespace.js';
9
+
10
+ function validateFamilyName(tokens, atRule) {
11
+ let node;
12
+ tokens = tokens.slice();
13
+ consumeWhitespace(tokens);
14
+ if (tokens.length == 0) {
15
+ // @ts-ignore
16
+ return {
17
+ valid: ValidationLevel.Drop,
18
+ matches: [],
19
+ node: atRule,
20
+ syntax: null,
21
+ error: 'expected at-rule prelude',
22
+ tokens
23
+ };
24
+ }
25
+ if (tokens[0].typ == EnumToken.CommaTokenType) {
26
+ // @ts-ignore
27
+ return {
28
+ valid: ValidationLevel.Drop,
29
+ matches: [],
30
+ node: tokens[0],
31
+ syntax: null,
32
+ error: 'unexpected token',
33
+ tokens
34
+ };
35
+ }
36
+ while (tokens.length > 0) {
37
+ // @ts-ignore
38
+ if (tokens[0].typ == EnumToken.CommaTokenType) {
39
+ node = tokens.shift();
40
+ consumeWhitespace(tokens);
41
+ if (tokens.length == 0) {
42
+ // @ts-ignore
43
+ return {
44
+ valid: ValidationLevel.Drop,
45
+ matches: [],
46
+ node,
47
+ syntax: null,
48
+ error: 'unexpected token',
49
+ tokens
50
+ };
51
+ }
52
+ }
53
+ node = tokens[0];
54
+ if (![EnumToken.IdenTokenType, EnumToken.StringTokenType].includes(node.typ)) {
55
+ // @ts-ignore
56
+ return {
57
+ valid: ValidationLevel.Drop,
58
+ matches: [],
59
+ node,
60
+ syntax: null,
61
+ error: 'unexpected token',
62
+ tokens
63
+ };
64
+ }
65
+ tokens.shift();
66
+ consumeWhitespace(tokens);
67
+ // @ts-ignore
68
+ if (tokens.length > 0 && node.typ == EnumToken.BadStringTokenType && tokens[0].typ != EnumToken.CommaTokenType) {
69
+ // @ts-ignore
70
+ return {
71
+ valid: ValidationLevel.Drop,
72
+ matches: [],
73
+ node: tokens[0],
74
+ syntax: null,
75
+ error: 'expected comma token',
76
+ tokens
77
+ };
78
+ }
79
+ }
80
+ // @ts-ignore
81
+ return {
82
+ valid: ValidationLevel.Valid,
83
+ matches: [],
84
+ node: null,
85
+ syntax: null,
86
+ error: '',
87
+ tokens
88
+ };
89
+ }
90
+
91
+ export { validateFamilyName };
@@ -0,0 +1,27 @@
1
+ import { EnumToken, ValidationLevel } from '../../ast/types.js';
2
+ import '../../ast/minify.js';
3
+ import '../../ast/walk.js';
4
+ import '../../parser/parse.js';
5
+ import '../../renderer/color/utils/constants.js';
6
+ import '../../renderer/sourcemap/lib/encode.js';
7
+ import '../../parser/utils/config.js';
8
+ import { validateKeyframeSelector } from './keyframe-selector.js';
9
+
10
+ function validateKeyframeBlockList(tokens, atRule) {
11
+ let i = 0;
12
+ let j = 0;
13
+ let result = null;
14
+ while (i + 1 < tokens.length) {
15
+ if (tokens[++i].typ == EnumToken.CommaTokenType) {
16
+ result = validateKeyframeSelector(tokens.slice(j, i), atRule);
17
+ if (result.valid == ValidationLevel.Drop) {
18
+ return result;
19
+ }
20
+ j = i + 1;
21
+ i = j;
22
+ }
23
+ }
24
+ return validateKeyframeSelector(i == j ? tokens.slice(i) : tokens.slice(j, i + 1), atRule);
25
+ }
26
+
27
+ export { validateKeyframeBlockList };
@@ -0,0 +1,137 @@
1
+ import { consumeWhitespace } from '../utils/whitespace.js';
2
+ import { ValidationLevel, EnumToken } from '../../ast/types.js';
3
+ import '../../ast/minify.js';
4
+ import '../../ast/walk.js';
5
+ import '../../parser/parse.js';
6
+ import '../../renderer/color/utils/constants.js';
7
+ import '../../renderer/sourcemap/lib/encode.js';
8
+ import '../../parser/utils/config.js';
9
+
10
+ function validateKeyframeSelector(tokens, atRule) {
11
+ consumeWhitespace(tokens);
12
+ if (tokens.length == 0) {
13
+ // @ts-ignore
14
+ return {
15
+ valid: ValidationLevel.Drop,
16
+ matches: [],
17
+ node: atRule,
18
+ syntax: null,
19
+ error: 'expected keyframe selector',
20
+ tokens
21
+ };
22
+ }
23
+ if (tokens[0].typ == EnumToken.PercentageTokenType) {
24
+ tokens.shift();
25
+ consumeWhitespace(tokens);
26
+ if (tokens.length == 0) {
27
+ // @ts-ignore
28
+ return {
29
+ valid: ValidationLevel.Valid,
30
+ matches: [],
31
+ node: atRule,
32
+ syntax: null,
33
+ error: '',
34
+ tokens
35
+ };
36
+ }
37
+ // @ts-ignore
38
+ return {
39
+ valid: ValidationLevel.Drop,
40
+ matches: [],
41
+ node: tokens[0],
42
+ syntax: null,
43
+ error: 'unexpected token',
44
+ tokens
45
+ };
46
+ }
47
+ if (tokens[0].typ != EnumToken.IdenTokenType) {
48
+ // @ts-ignore
49
+ return {
50
+ valid: ValidationLevel.Drop,
51
+ matches: [],
52
+ node: tokens[0],
53
+ // @ts-ignore
54
+ syntax: null,
55
+ error: 'expected keyframe selector',
56
+ tokens
57
+ };
58
+ }
59
+ if (['from', 'to'].includes(tokens[0].val)) {
60
+ tokens.shift();
61
+ consumeWhitespace(tokens);
62
+ if (tokens.length > 0) {
63
+ // @ts-ignore
64
+ return {
65
+ valid: ValidationLevel.Drop,
66
+ matches: [],
67
+ node: tokens[0],
68
+ syntax: null,
69
+ error: 'unexpected token',
70
+ tokens
71
+ };
72
+ }
73
+ // @ts-ignore
74
+ return {
75
+ valid: ValidationLevel.Valid,
76
+ matches: [],
77
+ node: null,
78
+ // @ts-ignore
79
+ syntax: null,
80
+ error: '',
81
+ tokens
82
+ };
83
+ }
84
+ if (!['cover', 'contain', 'entry', 'exit', 'entry-crossing', 'exit-crossing'].includes(tokens[0].val)) {
85
+ // @ts-ignore
86
+ return {
87
+ valid: ValidationLevel.Drop,
88
+ matches: [],
89
+ node: tokens[0],
90
+ // @ts-ignore
91
+ syntax: null,
92
+ error: 'unexpected token',
93
+ tokens
94
+ };
95
+ }
96
+ tokens.shift();
97
+ consumeWhitespace(tokens);
98
+ // @ts-ignore
99
+ if (tokens.length == 0 || tokens[0].typ != EnumToken.PercentageTokenType) {
100
+ // @ts-ignore
101
+ return {
102
+ valid: ValidationLevel.Drop,
103
+ matches: [],
104
+ node: tokens[0],
105
+ // @ts-ignore
106
+ syntax: null,
107
+ error: 'expecting percentage token',
108
+ tokens
109
+ };
110
+ }
111
+ tokens.shift();
112
+ consumeWhitespace(tokens);
113
+ if (tokens.length > 0) {
114
+ // @ts-ignore
115
+ return {
116
+ valid: ValidationLevel.Drop,
117
+ matches: [],
118
+ node: tokens[0],
119
+ // @ts-ignore
120
+ syntax: null,
121
+ error: 'unexpected token',
122
+ tokens
123
+ };
124
+ }
125
+ // @ts-ignore
126
+ return {
127
+ valid: ValidationLevel.Valid,
128
+ matches: [],
129
+ node: null,
130
+ // @ts-ignore
131
+ syntax: null,
132
+ error: '',
133
+ tokens
134
+ };
135
+ }
136
+
137
+ export { validateKeyframeSelector };
@@ -0,0 +1,67 @@
1
+ import { EnumToken, ValidationLevel } from '../../ast/types.js';
2
+ import '../../ast/minify.js';
3
+ import '../../ast/walk.js';
4
+ import '../../parser/parse.js';
5
+ import '../../renderer/color/utils/constants.js';
6
+ import '../../renderer/sourcemap/lib/encode.js';
7
+ import '../../parser/utils/config.js';
8
+
9
+ function validateLayerName(tokens) {
10
+ const slice = tokens.reduce((acc, curr) => {
11
+ if (curr.typ == EnumToken.CommaTokenType) {
12
+ acc.push([]);
13
+ }
14
+ else if (curr.typ != EnumToken.CommentTokenType) {
15
+ acc[acc.length - 1].push(curr);
16
+ }
17
+ return acc;
18
+ }, [[]]).slice(1);
19
+ for (let i = 0; i < slice.length; i++) {
20
+ if (slice[i].length == 0) {
21
+ // @ts-ignore
22
+ return {
23
+ valid: ValidationLevel.Drop,
24
+ matches: tokens,
25
+ node: null,
26
+ syntax: null,
27
+ error: 'Invalid ident',
28
+ tokens
29
+ };
30
+ }
31
+ if (slice[i][0].typ != EnumToken.IdenTokenType) {
32
+ // @ts-ignore
33
+ return {
34
+ valid: ValidationLevel.Drop,
35
+ matches: tokens,
36
+ node: slice[i][0],
37
+ syntax: 'ident',
38
+ error: 'expecting ident',
39
+ tokens
40
+ };
41
+ }
42
+ for (let j = 1; j < slice[i].length; j++) {
43
+ if (slice[i][j].typ != EnumToken.ClassSelectorTokenType) {
44
+ // @ts-ignore
45
+ return {
46
+ valid: ValidationLevel.Drop,
47
+ matches: tokens,
48
+ node: slice[i][j],
49
+ syntax: 'layer-name',
50
+ error: 'expecting class selector',
51
+ tokens
52
+ };
53
+ }
54
+ }
55
+ }
56
+ // @ts-ignore
57
+ return {
58
+ valid: ValidationLevel.Valid,
59
+ matches: tokens,
60
+ node: null,
61
+ syntax: null,
62
+ error: '',
63
+ tokens
64
+ };
65
+ }
66
+
67
+ export { validateLayerName };
@@ -0,0 +1,27 @@
1
+ import { EnumToken, ValidationLevel } from '../../ast/types.js';
2
+ import '../../ast/minify.js';
3
+ import '../../ast/walk.js';
4
+ import '../../parser/parse.js';
5
+ import '../../renderer/color/utils/constants.js';
6
+ import '../../renderer/sourcemap/lib/encode.js';
7
+ import '../../parser/utils/config.js';
8
+ import { validateRelativeSelector } from './relative-selector.js';
9
+
10
+ function validateRelativeSelectorList(tokens, root, options) {
11
+ let i = 0;
12
+ let j = 0;
13
+ let result = null;
14
+ while (i + 1 < tokens.length) {
15
+ if (tokens[++i].typ == EnumToken.CommaTokenType) {
16
+ result = validateRelativeSelector(tokens.slice(j, i), root, options);
17
+ if (result.valid == ValidationLevel.Drop) {
18
+ return result;
19
+ }
20
+ j = i + 1;
21
+ i = j;
22
+ }
23
+ }
24
+ return validateRelativeSelector(i == j ? tokens.slice(i) : tokens.slice(j, i + 1), root, options);
25
+ }
26
+
27
+ export { validateRelativeSelectorList };