@tbela99/css-parser 0.9.1 → 1.1.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 (99) hide show
  1. package/CHANGELOG.md +265 -0
  2. package/LICENSE.md +1 -1
  3. package/README.md +29 -17
  4. package/dist/index-umd-web.js +7461 -4360
  5. package/dist/index.cjs +8608 -5507
  6. package/dist/index.d.ts +203 -61
  7. package/dist/lib/ast/expand.js +2 -1
  8. package/dist/lib/ast/features/calc.js +19 -11
  9. package/dist/lib/ast/features/index.js +1 -0
  10. package/dist/lib/ast/features/inlinecssvariables.js +47 -29
  11. package/dist/lib/ast/features/prefix.js +117 -91
  12. package/dist/lib/ast/features/shorthand.js +34 -14
  13. package/dist/lib/ast/features/transform.js +67 -0
  14. package/dist/lib/ast/features/type.js +7 -0
  15. package/dist/lib/ast/math/expression.js +20 -10
  16. package/dist/lib/ast/math/math.js +20 -2
  17. package/dist/lib/ast/minify.js +209 -80
  18. package/dist/lib/ast/transform/compute.js +337 -0
  19. package/dist/lib/ast/transform/convert.js +33 -0
  20. package/dist/lib/ast/transform/matrix.js +112 -0
  21. package/dist/lib/ast/transform/minify.js +296 -0
  22. package/dist/lib/ast/transform/perspective.js +10 -0
  23. package/dist/lib/ast/transform/rotate.js +40 -0
  24. package/dist/lib/ast/transform/scale.js +32 -0
  25. package/dist/lib/ast/transform/skew.js +23 -0
  26. package/dist/lib/ast/transform/translate.js +32 -0
  27. package/dist/lib/ast/transform/utils.js +198 -0
  28. package/dist/lib/ast/types.js +18 -15
  29. package/dist/lib/ast/walk.js +54 -22
  30. package/dist/lib/fs/resolve.js +10 -0
  31. package/dist/lib/parser/declaration/list.js +48 -45
  32. package/dist/lib/parser/declaration/map.js +1 -0
  33. package/dist/lib/parser/declaration/set.js +2 -1
  34. package/dist/lib/parser/parse.js +449 -340
  35. package/dist/lib/parser/tokenize.js +147 -72
  36. package/dist/lib/parser/utils/declaration.js +5 -4
  37. package/dist/lib/parser/utils/type.js +2 -1
  38. package/dist/lib/renderer/color/a98rgb.js +2 -1
  39. package/dist/lib/renderer/color/{colormix.js → color-mix.js} +16 -7
  40. package/dist/lib/renderer/color/color.js +264 -170
  41. package/dist/lib/renderer/color/hex.js +19 -8
  42. package/dist/lib/renderer/color/hsl.js +9 -3
  43. package/dist/lib/renderer/color/hwb.js +2 -1
  44. package/dist/lib/renderer/color/lab.js +10 -1
  45. package/dist/lib/renderer/color/lch.js +10 -1
  46. package/dist/lib/renderer/color/oklab.js +10 -1
  47. package/dist/lib/renderer/color/oklch.js +10 -1
  48. package/dist/lib/renderer/color/p3.js +2 -1
  49. package/dist/lib/renderer/color/rec2020.js +2 -1
  50. package/dist/lib/renderer/color/relativecolor.js +27 -32
  51. package/dist/lib/renderer/color/rgb.js +14 -10
  52. package/dist/lib/renderer/color/srgb.js +48 -23
  53. package/dist/lib/renderer/color/utils/components.js +18 -6
  54. package/dist/lib/renderer/color/utils/constants.js +47 -3
  55. package/dist/lib/renderer/color/xyz.js +2 -1
  56. package/dist/lib/renderer/color/xyzd50.js +2 -1
  57. package/dist/lib/renderer/render.js +108 -43
  58. package/dist/lib/syntax/syntax.js +267 -136
  59. package/dist/lib/validation/at-rules/container.js +81 -103
  60. package/dist/lib/validation/at-rules/counter-style.js +9 -8
  61. package/dist/lib/validation/at-rules/custom-media.js +13 -15
  62. package/dist/lib/validation/at-rules/document.js +22 -27
  63. package/dist/lib/validation/at-rules/font-feature-values.js +8 -8
  64. package/dist/lib/validation/at-rules/import.js +30 -81
  65. package/dist/lib/validation/at-rules/keyframes.js +19 -23
  66. package/dist/lib/validation/at-rules/layer.js +5 -5
  67. package/dist/lib/validation/at-rules/media.js +42 -53
  68. package/dist/lib/validation/at-rules/namespace.js +19 -23
  69. package/dist/lib/validation/at-rules/page-margin-box.js +15 -18
  70. package/dist/lib/validation/at-rules/page.js +8 -7
  71. package/dist/lib/validation/at-rules/supports.js +73 -82
  72. package/dist/lib/validation/at-rules/when.js +32 -36
  73. package/dist/lib/validation/atrule.js +15 -18
  74. package/dist/lib/validation/config.js +24 -1
  75. package/dist/lib/validation/config.json.js +563 -63
  76. package/dist/lib/validation/parser/parse.js +196 -185
  77. package/dist/lib/validation/parser/types.js +1 -1
  78. package/dist/lib/validation/selector.js +8 -5
  79. package/dist/lib/validation/syntax.js +724 -1405
  80. package/dist/lib/validation/syntaxes/complex-selector-list.js +10 -11
  81. package/dist/lib/validation/syntaxes/complex-selector.js +10 -11
  82. package/dist/lib/validation/syntaxes/compound-selector.js +40 -50
  83. package/dist/lib/validation/syntaxes/family-name.js +9 -8
  84. package/dist/lib/validation/syntaxes/keyframe-block-list.js +6 -5
  85. package/dist/lib/validation/syntaxes/keyframe-selector.js +23 -105
  86. package/dist/lib/validation/syntaxes/layer-name.js +6 -5
  87. package/dist/lib/validation/syntaxes/relative-selector-list.js +7 -6
  88. package/dist/lib/validation/syntaxes/relative-selector.js +17 -15
  89. package/dist/lib/validation/syntaxes/url.js +18 -22
  90. package/dist/lib/validation/utils/list.js +20 -2
  91. package/dist/lib/validation/utils/whitespace.js +2 -1
  92. package/dist/node/index.js +4 -2
  93. package/dist/node/load.js +6 -1
  94. package/dist/web/index.js +4 -2
  95. package/dist/web/load.js +5 -0
  96. package/package.json +16 -15
  97. package/dist/lib/renderer/color/prophotoRgb.js +0 -56
  98. package/dist/lib/validation/declaration.js +0 -94
  99. package/dist/lib/validation/syntaxes/image.js +0 -29
@@ -1,10 +1,11 @@
1
- import { ValidationLevel } from '../../ast/types.js';
1
+ import { SyntaxValidationResult } from '../../ast/types.js';
2
2
  import '../../ast/minify.js';
3
3
  import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
+ import '../../parser/tokenize.js';
6
+ import '../../parser/utils/config.js';
5
7
  import '../../renderer/color/utils/constants.js';
6
8
  import '../../renderer/sourcemap/lib/encode.js';
7
- import '../../parser/utils/config.js';
8
9
  import { validateSelector } from './selector.js';
9
10
  import { consumeWhitespace } from '../utils/whitespace.js';
10
11
  import { splitTokenList } from '../utils/list.js';
@@ -14,31 +15,29 @@ function validateComplexSelectorList(tokens, root, options) {
14
15
  consumeWhitespace(tokens);
15
16
  if (tokens.length == 0) {
16
17
  return {
17
- valid: ValidationLevel.Drop,
18
- matches: [],
18
+ valid: SyntaxValidationResult.Drop,
19
+ context: [],
19
20
  // @ts-ignore
20
21
  node: root,
21
22
  syntax: null,
22
- error: 'expecting complex selector list',
23
- tokens
23
+ error: 'expecting complex selector list'
24
24
  };
25
25
  }
26
26
  let result = null;
27
27
  for (const t of splitTokenList(tokens)) {
28
28
  result = validateSelector(t, root, options);
29
- if (result.valid == ValidationLevel.Drop) {
29
+ if (result.valid == SyntaxValidationResult.Drop) {
30
30
  return result;
31
31
  }
32
32
  }
33
33
  // @ts-ignore
34
34
  return result ?? {
35
- valid: ValidationLevel.Drop,
36
- matches: [],
35
+ valid: SyntaxValidationResult.Drop,
36
+ context: [],
37
37
  // @ts-ignore
38
38
  node: root,
39
39
  syntax: null,
40
- error: 'expecting complex selector list',
41
- tokens
40
+ error: 'expecting complex selector list'
42
41
  };
43
42
  }
44
43
 
@@ -1,12 +1,13 @@
1
1
  import { consumeWhitespace } from '../utils/whitespace.js';
2
2
  import { splitTokenList } from '../utils/list.js';
3
- import { EnumToken, ValidationLevel } from '../../ast/types.js';
3
+ import { EnumToken, SyntaxValidationResult } from '../../ast/types.js';
4
4
  import '../../ast/minify.js';
5
5
  import '../../ast/walk.js';
6
6
  import '../../parser/parse.js';
7
+ import '../../parser/tokenize.js';
8
+ import '../../parser/utils/config.js';
7
9
  import '../../renderer/color/utils/constants.js';
8
10
  import '../../renderer/sourcemap/lib/encode.js';
9
- import '../../parser/utils/config.js';
10
11
  import { validateCompoundSelector } from './compound-selector.js';
11
12
 
12
13
  const combinatorsTokens = [EnumToken.ChildCombinatorTokenType, EnumToken.ColumnCombinatorTokenType,
@@ -19,13 +20,12 @@ function validateComplexSelector(tokens, root, options) {
19
20
  consumeWhitespace(tokens);
20
21
  if (tokens.length == 0) {
21
22
  return {
22
- valid: ValidationLevel.Drop,
23
- matches: [],
23
+ valid: SyntaxValidationResult.Drop,
24
+ context: [],
24
25
  // @ts-ignore
25
26
  node: root,
26
27
  syntax: null,
27
- error: 'expected selector',
28
- tokens
28
+ error: 'expected selector'
29
29
  };
30
30
  }
31
31
  // const config = getSyntaxConfig();
@@ -35,18 +35,17 @@ function validateComplexSelector(tokens, root, options) {
35
35
  // const combinators: EnumToken[] = combinatorsTokens.filter((t: EnumToken) => t != EnumToken.DescendantCombinatorTokenType);
36
36
  for (const t of splitTokenList(tokens, combinatorsTokens)) {
37
37
  result = validateCompoundSelector(t, root, options);
38
- if (result.valid == ValidationLevel.Drop) {
38
+ if (result.valid == SyntaxValidationResult.Drop) {
39
39
  return result;
40
40
  }
41
41
  }
42
42
  // @ts-ignore
43
43
  return result ?? {
44
- valid: ValidationLevel.Drop,
45
- matches: [],
44
+ valid: SyntaxValidationResult.Drop,
45
+ context: [],
46
46
  node: root,
47
47
  syntax: null,
48
- error: 'expecting compound-selector',
49
- tokens
48
+ error: 'expecting compound-selector'
50
49
  };
51
50
  }
52
51
 
@@ -1,9 +1,10 @@
1
- import { ValidationLevel, EnumToken } from '../../ast/types.js';
1
+ import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
2
2
  import '../../ast/minify.js';
3
3
  import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
- import { mozExtensions, webkitExtensions } from '../../syntax/syntax.js';
5
+ import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
+ import { mozExtensions, webkitExtensions } from '../../syntax/syntax.js';
7
8
  import '../../renderer/color/utils/constants.js';
8
9
  import '../../renderer/sourcemap/lib/encode.js';
9
10
  import { consumeWhitespace } from '../utils/whitespace.js';
@@ -13,8 +14,8 @@ function validateCompoundSelector(tokens, root, options) {
13
14
  if (tokens.length == 0) {
14
15
  // @ts-ignore
15
16
  return {
16
- valid: ValidationLevel.Drop,
17
- matches: [],
17
+ valid: SyntaxValidationResult.Drop,
18
+ context: [],
18
19
  // @ts-ignore
19
20
  node: root,
20
21
  // @ts-ignore
@@ -33,13 +34,12 @@ function validateCompoundSelector(tokens, root, options) {
33
34
  if (!options?.nestedSelector) {
34
35
  // @ts-ignore
35
36
  return {
36
- valid: ValidationLevel.Drop,
37
- matches: [],
37
+ valid: SyntaxValidationResult.Drop,
38
+ context: [],
38
39
  // @ts-ignore
39
40
  node: tokens[0],
40
41
  syntax: null,
41
- error: 'nested selector not allowed',
42
- tokens
42
+ error: 'nested selector not allowed'
43
43
  };
44
44
  }
45
45
  match++;
@@ -66,13 +66,12 @@ function validateCompoundSelector(tokens, root, options) {
66
66
  if (!options?.lenient || /^(:?)-webkit-/.test(tokens[0].val)) {
67
67
  // @ts-ignore
68
68
  return {
69
- valid: ValidationLevel.Drop,
70
- matches: [],
69
+ valid: SyntaxValidationResult.Drop,
70
+ context: [],
71
71
  // @ts-ignore
72
72
  node: tokens[0],
73
73
  syntax: null,
74
- error: 'unknown pseudo-class: ' + tokens[0].val + '()',
75
- tokens
74
+ error: 'unknown pseudo-class: ' + tokens[0].val + '()'
76
75
  };
77
76
  }
78
77
  }
@@ -93,13 +92,12 @@ function validateCompoundSelector(tokens, root, options) {
93
92
  if (!options?.lenient || /^(:?)-webkit-/.test(tokens[0].val)) {
94
93
  // @ts-ignore
95
94
  return {
96
- valid: ValidationLevel.Drop,
97
- matches: [],
95
+ valid: SyntaxValidationResult.Drop,
96
+ context: [],
98
97
  // @ts-ignore
99
98
  node: tokens[0],
100
99
  syntax: null,
101
- error: 'unknown pseudo-class: ' + tokens[0].val,
102
- tokens
100
+ error: 'unknown pseudo-class: ' + tokens[0].val
103
101
  };
104
102
  }
105
103
  }
@@ -113,12 +111,11 @@ function validateCompoundSelector(tokens, root, options) {
113
111
  if (children.length == 0) {
114
112
  // @ts-ignore
115
113
  return {
116
- valid: ValidationLevel.Drop,
117
- matches: [],
114
+ valid: SyntaxValidationResult.Drop,
115
+ context: [],
118
116
  node: tokens[0],
119
117
  syntax: null,
120
- error: 'invalid attribute selector',
121
- tokens
118
+ error: 'invalid attribute selector'
122
119
  };
123
120
  }
124
121
  if (![
@@ -128,23 +125,21 @@ function validateCompoundSelector(tokens, root, options) {
128
125
  ].includes(children[0].typ)) {
129
126
  // @ts-ignore
130
127
  return {
131
- valid: ValidationLevel.Drop,
132
- matches: [],
128
+ valid: SyntaxValidationResult.Drop,
129
+ context: [],
133
130
  node: tokens[0],
134
131
  syntax: null,
135
- error: 'invalid attribute selector',
136
- tokens
132
+ error: 'invalid attribute selector'
137
133
  };
138
134
  }
139
135
  if (children[0].typ == EnumToken.MatchExpressionTokenType) {
140
136
  if (children.length != 1) {
141
137
  return {
142
- valid: ValidationLevel.Drop,
143
- matches: [],
138
+ valid: SyntaxValidationResult.Drop,
139
+ context: [],
144
140
  node: tokens[0],
145
141
  syntax: null,
146
- error: 'invalid <attribute-selector>',
147
- tokens
142
+ error: 'invalid <attribute-selector>'
148
143
  };
149
144
  }
150
145
  if (![
@@ -156,29 +151,27 @@ function validateCompoundSelector(tokens, root, options) {
156
151
  EnumToken.StartMatchTokenType, EnumToken.ContainMatchTokenType,
157
152
  EnumToken.EndMatchTokenType, EnumToken.IncludeMatchTokenType
158
153
  ].includes(children[0].op.typ) ||
159
- ![
154
+ !([
160
155
  EnumToken.StringTokenType,
161
156
  EnumToken.IdenTokenType
162
- ].includes(children[0].r.typ)) {
157
+ ].includes(children[0].r.typ))) {
163
158
  // @ts-ignore
164
159
  return {
165
- valid: ValidationLevel.Drop,
166
- matches: [],
160
+ valid: SyntaxValidationResult.Drop,
161
+ context: [],
167
162
  node: tokens[0],
168
163
  syntax: null,
169
- error: 'invalid attribute selector',
170
- tokens
164
+ error: 'invalid attribute selector'
171
165
  };
172
166
  }
173
167
  if (children[0].attr != null && !['i', 's'].includes(children[0].attr)) {
174
168
  // @ts-ignore
175
169
  return {
176
- valid: ValidationLevel.Drop,
177
- matches: [],
170
+ valid: SyntaxValidationResult.Drop,
171
+ context: [],
178
172
  node: tokens[0],
179
173
  syntax: null,
180
- error: 'invalid attribute selector',
181
- tokens
174
+ error: 'invalid attribute selector'
182
175
  };
183
176
  }
184
177
  }
@@ -188,38 +181,35 @@ function validateCompoundSelector(tokens, root, options) {
188
181
  }
189
182
  if (length == tokens.length) {
190
183
  return {
191
- valid: ValidationLevel.Drop,
192
- matches: [],
184
+ valid: SyntaxValidationResult.Drop,
185
+ context: [],
193
186
  // @ts-ignore
194
187
  node: tokens[0],
195
188
  // @ts-ignore
196
189
  syntax: null,
197
- error: 'expected compound selector',
198
- tokens
190
+ error: 'expected compound selector'
199
191
  };
200
192
  }
201
193
  length = tokens.length;
202
194
  }
203
195
  return match == 0 ? {
204
- valid: ValidationLevel.Drop,
205
- matches: [],
196
+ valid: SyntaxValidationResult.Drop,
197
+ context: [],
206
198
  // @ts-ignore
207
199
  node: root,
208
200
  // @ts-ignore
209
201
  syntax: null,
210
- error: 'expected compound selector',
211
- tokens
202
+ error: 'expected compound selector'
212
203
  } :
213
204
  // @ts-ignore
214
205
  {
215
- valid: ValidationLevel.Valid,
216
- matches: [],
206
+ valid: SyntaxValidationResult.Valid,
207
+ context: [],
217
208
  // @ts-ignore
218
209
  node: root,
219
210
  // @ts-ignore
220
211
  syntax: null,
221
- error: null,
222
- tokens
212
+ error: null
223
213
  };
224
214
  }
225
215
 
@@ -1,10 +1,11 @@
1
- import { ValidationLevel, EnumToken } from '../../ast/types.js';
1
+ import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
2
2
  import '../../ast/minify.js';
3
3
  import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
+ import '../../parser/tokenize.js';
6
+ import '../../parser/utils/config.js';
5
7
  import '../../renderer/color/utils/constants.js';
6
8
  import '../../renderer/sourcemap/lib/encode.js';
7
- import '../../parser/utils/config.js';
8
9
  import { consumeWhitespace } from '../utils/whitespace.js';
9
10
 
10
11
  function validateFamilyName(tokens, atRule) {
@@ -14,7 +15,7 @@ function validateFamilyName(tokens, atRule) {
14
15
  if (tokens.length == 0) {
15
16
  // @ts-ignore
16
17
  return {
17
- valid: ValidationLevel.Drop,
18
+ valid: SyntaxValidationResult.Drop,
18
19
  matches: [],
19
20
  node: atRule,
20
21
  syntax: null,
@@ -25,7 +26,7 @@ function validateFamilyName(tokens, atRule) {
25
26
  if (tokens[0].typ == EnumToken.CommaTokenType) {
26
27
  // @ts-ignore
27
28
  return {
28
- valid: ValidationLevel.Drop,
29
+ valid: SyntaxValidationResult.Drop,
29
30
  matches: [],
30
31
  node: tokens[0],
31
32
  syntax: null,
@@ -41,7 +42,7 @@ function validateFamilyName(tokens, atRule) {
41
42
  if (tokens.length == 0) {
42
43
  // @ts-ignore
43
44
  return {
44
- valid: ValidationLevel.Drop,
45
+ valid: SyntaxValidationResult.Drop,
45
46
  matches: [],
46
47
  node,
47
48
  syntax: null,
@@ -54,7 +55,7 @@ function validateFamilyName(tokens, atRule) {
54
55
  if (![EnumToken.IdenTokenType, EnumToken.StringTokenType].includes(node.typ)) {
55
56
  // @ts-ignore
56
57
  return {
57
- valid: ValidationLevel.Drop,
58
+ valid: SyntaxValidationResult.Drop,
58
59
  matches: [],
59
60
  node,
60
61
  syntax: null,
@@ -68,7 +69,7 @@ function validateFamilyName(tokens, atRule) {
68
69
  if (tokens.length > 0 && node.typ == EnumToken.BadStringTokenType && tokens[0].typ != EnumToken.CommaTokenType) {
69
70
  // @ts-ignore
70
71
  return {
71
- valid: ValidationLevel.Drop,
72
+ valid: SyntaxValidationResult.Drop,
72
73
  matches: [],
73
74
  node: tokens[0],
74
75
  syntax: null,
@@ -79,7 +80,7 @@ function validateFamilyName(tokens, atRule) {
79
80
  }
80
81
  // @ts-ignore
81
82
  return {
82
- valid: ValidationLevel.Valid,
83
+ valid: SyntaxValidationResult.Valid,
83
84
  matches: [],
84
85
  node: null,
85
86
  syntax: null,
@@ -1,10 +1,11 @@
1
- import { EnumToken, ValidationLevel } from '../../ast/types.js';
1
+ import { EnumToken, SyntaxValidationResult } from '../../ast/types.js';
2
2
  import '../../ast/minify.js';
3
3
  import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
+ import '../../parser/tokenize.js';
6
+ import '../../parser/utils/config.js';
5
7
  import '../../renderer/color/utils/constants.js';
6
8
  import '../../renderer/sourcemap/lib/encode.js';
7
- import '../../parser/utils/config.js';
8
9
  import { validateKeyframeSelector } from './keyframe-selector.js';
9
10
 
10
11
  function validateKeyframeBlockList(tokens, atRule, options) {
@@ -13,15 +14,15 @@ function validateKeyframeBlockList(tokens, atRule, options) {
13
14
  let result = null;
14
15
  while (i + 1 < tokens.length) {
15
16
  if (tokens[++i].typ == EnumToken.CommaTokenType) {
16
- result = validateKeyframeSelector(tokens.slice(j, i), atRule);
17
- if (result.valid == ValidationLevel.Drop) {
17
+ result = validateKeyframeSelector(tokens.slice(j, i));
18
+ if (result.valid == SyntaxValidationResult.Drop) {
18
19
  return result;
19
20
  }
20
21
  j = i + 1;
21
22
  i = j;
22
23
  }
23
24
  }
24
- return validateKeyframeSelector(i == j ? tokens.slice(i) : tokens.slice(j, i + 1), atRule);
25
+ return validateKeyframeSelector(i == j ? tokens.slice(i) : tokens.slice(j, i + 1));
25
26
  }
26
27
 
27
28
  export { validateKeyframeBlockList };
@@ -1,136 +1,54 @@
1
1
  import { consumeWhitespace } from '../utils/whitespace.js';
2
- import { ValidationLevel, EnumToken } from '../../ast/types.js';
2
+ import { splitTokenList } from '../utils/list.js';
3
+ import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
3
4
  import '../../ast/minify.js';
4
5
  import '../../ast/walk.js';
5
6
  import '../../parser/parse.js';
7
+ import '../../parser/tokenize.js';
8
+ import '../../parser/utils/config.js';
6
9
  import '../../renderer/color/utils/constants.js';
7
10
  import '../../renderer/sourcemap/lib/encode.js';
8
- import '../../parser/utils/config.js';
9
11
 
10
- function validateKeyframeSelector(tokens, atRule, options) {
12
+ function validateKeyframeSelector(tokens, options) {
11
13
  consumeWhitespace(tokens);
12
14
  if (tokens.length == 0) {
13
15
  // @ts-ignore
14
16
  return {
15
- valid: ValidationLevel.Drop,
16
- matches: [],
17
- node: atRule,
17
+ valid: SyntaxValidationResult.Drop,
18
+ context: [],
19
+ node: null,
18
20
  syntax: null,
19
- error: 'expected keyframe selector',
20
- tokens
21
+ error: 'expected keyframe selector'
21
22
  };
22
23
  }
23
- if (tokens[0].typ == EnumToken.PercentageTokenType) {
24
- tokens.shift();
25
- consumeWhitespace(tokens);
26
- if (tokens.length == 0) {
27
- // @ts-ignore
24
+ for (const t of splitTokenList(tokens)) {
25
+ if (t.length != 1) {
28
26
  return {
29
- valid: ValidationLevel.Valid,
30
- matches: [],
31
- node: atRule,
27
+ valid: SyntaxValidationResult.Drop,
28
+ context: [],
29
+ node: t[0] ?? null,
32
30
  syntax: null,
33
- error: '',
34
- tokens
31
+ error: 'unexpected token'
35
32
  };
36
33
  }
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
34
+ if (t[0].typ != EnumToken.PercentageTokenType && !(t[0].typ == EnumToken.IdenTokenType && ['from', 'to', 'cover', 'contain', 'entry', 'exit', 'entry-crossing', 'exit-crossing'].includes(t[0].val))) {
64
35
  return {
65
- valid: ValidationLevel.Drop,
66
- matches: [],
67
- node: tokens[0],
36
+ valid: SyntaxValidationResult.Drop,
37
+ context: [],
38
+ node: t[0],
68
39
  syntax: null,
69
- error: 'unexpected token',
70
- tokens
40
+ error: 'expected keyframe selector'
71
41
  };
72
42
  }
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
43
  }
125
44
  // @ts-ignore
126
45
  return {
127
- valid: ValidationLevel.Valid,
128
- matches: [],
46
+ valid: SyntaxValidationResult.Valid,
47
+ context: [],
129
48
  node: null,
130
49
  // @ts-ignore
131
50
  syntax: null,
132
- error: '',
133
- tokens
51
+ error: ''
134
52
  };
135
53
  }
136
54
 
@@ -1,10 +1,11 @@
1
- import { EnumToken, ValidationLevel } from '../../ast/types.js';
1
+ import { EnumToken, SyntaxValidationResult } from '../../ast/types.js';
2
2
  import '../../ast/minify.js';
3
3
  import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
+ import '../../parser/tokenize.js';
6
+ import '../../parser/utils/config.js';
5
7
  import '../../renderer/color/utils/constants.js';
6
8
  import '../../renderer/sourcemap/lib/encode.js';
7
- import '../../parser/utils/config.js';
8
9
 
9
10
  function validateLayerName(tokens) {
10
11
  const slice = tokens.reduce((acc, curr) => {
@@ -20,7 +21,7 @@ function validateLayerName(tokens) {
20
21
  if (slice[i].length == 0) {
21
22
  // @ts-ignore
22
23
  return {
23
- valid: ValidationLevel.Drop,
24
+ valid: SyntaxValidationResult.Drop,
24
25
  matches: tokens,
25
26
  node: null,
26
27
  syntax: null,
@@ -32,7 +33,7 @@ function validateLayerName(tokens) {
32
33
  if (slice[i][j].typ != EnumToken.IdenTokenType && slice[i][j].typ != EnumToken.ClassSelectorTokenType) {
33
34
  // @ts-ignore
34
35
  return {
35
- valid: ValidationLevel.Drop,
36
+ valid: SyntaxValidationResult.Drop,
36
37
  matches: tokens,
37
38
  node: slice[i][j],
38
39
  syntax: '<layer-name>',
@@ -44,7 +45,7 @@ function validateLayerName(tokens) {
44
45
  }
45
46
  // @ts-ignore
46
47
  return {
47
- valid: ValidationLevel.Valid,
48
+ valid: SyntaxValidationResult.Valid,
48
49
  matches: tokens,
49
50
  node: null,
50
51
  syntax: null,
@@ -1,10 +1,11 @@
1
- import { ValidationLevel } from '../../ast/types.js';
1
+ import { SyntaxValidationResult } from '../../ast/types.js';
2
2
  import '../../ast/minify.js';
3
3
  import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
+ import '../../parser/tokenize.js';
6
+ import '../../parser/utils/config.js';
5
7
  import '../../renderer/color/utils/constants.js';
6
8
  import '../../renderer/sourcemap/lib/encode.js';
7
- import '../../parser/utils/config.js';
8
9
  import { validateRelativeSelector } from './relative-selector.js';
9
10
  import { consumeWhitespace } from '../utils/whitespace.js';
10
11
  import { splitTokenList } from '../utils/list.js';
@@ -14,7 +15,7 @@ function validateRelativeSelectorList(tokens, root, options) {
14
15
  consumeWhitespace(tokens);
15
16
  if (tokens.length == 0) {
16
17
  return {
17
- valid: ValidationLevel.Drop,
18
+ valid: SyntaxValidationResult.Drop,
18
19
  matches: [],
19
20
  // @ts-ignore
20
21
  node: root,
@@ -27,7 +28,7 @@ function validateRelativeSelectorList(tokens, root, options) {
27
28
  for (const t of splitTokenList(tokens)) {
28
29
  if (t.length == 0) {
29
30
  return {
30
- valid: ValidationLevel.Drop,
31
+ valid: SyntaxValidationResult.Drop,
31
32
  matches: [],
32
33
  // @ts-ignore
33
34
  node: root,
@@ -38,12 +39,12 @@ function validateRelativeSelectorList(tokens, root, options) {
38
39
  };
39
40
  }
40
41
  const result = validateRelativeSelector(t, root, options);
41
- if (result.valid == ValidationLevel.Drop) {
42
+ if (result.valid == SyntaxValidationResult.Drop) {
42
43
  return result;
43
44
  }
44
45
  }
45
46
  return {
46
- valid: ValidationLevel.Valid,
47
+ valid: SyntaxValidationResult.Valid,
47
48
  matches: [],
48
49
  // @ts-ignore
49
50
  node: root,