@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,27 +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 { validateSelector } from './selector.js';
10
- import { consumeWhitespace } from '../utils/whitespace.js';
11
- import { splitTokenList } from '../utils/list.js';
12
-
13
- function validateComplexSelectorList(tokens, root, options) {
14
- tokens = tokens.slice();
15
- consumeWhitespace(tokens);
16
- let result = null;
17
- for (const t of splitTokenList(tokens)) {
18
- result = validateSelector(t, root, options);
19
- if (result.valid == SyntaxValidationResult.Drop) {
20
- return result;
21
- }
22
- }
23
- // @ts-ignore
24
- return result;
25
- }
26
-
27
- export { validateComplexSelectorList };
@@ -1,52 +0,0 @@
1
- import { consumeWhitespace } from '../utils/whitespace.js';
2
- import { splitTokenList } from '../utils/list.js';
3
- import { EnumToken, SyntaxValidationResult } from '../../ast/types.js';
4
- import '../../ast/minify.js';
5
- import '../../ast/walk.js';
6
- import '../../parser/parse.js';
7
- import '../../parser/tokenize.js';
8
- import '../../parser/utils/config.js';
9
- import '../../syntax/color/utils/constants.js';
10
- import '../../renderer/sourcemap/lib/encode.js';
11
- import { validateCompoundSelector } from './compound-selector.js';
12
-
13
- const combinatorsTokens = [EnumToken.ChildCombinatorTokenType, EnumToken.ColumnCombinatorTokenType,
14
- // EnumToken.DescendantCombinatorTokenType,
15
- EnumToken.NextSiblingCombinatorTokenType, EnumToken.SubsequentSiblingCombinatorTokenType];
16
- // <compound-selector> [ <combinator>? <compound-selector> ]*
17
- function validateComplexSelector(tokens, root, options) {
18
- // [ <type-selector>? <subclass-selector>* [ <pseudo-element-selector> <pseudo-class-selector>* ]* ]!
19
- tokens = tokens.slice();
20
- consumeWhitespace(tokens);
21
- if (tokens.length == 0) {
22
- return {
23
- valid: SyntaxValidationResult.Drop,
24
- context: [],
25
- // @ts-ignore
26
- node: root,
27
- syntax: null,
28
- error: 'expected selector'
29
- };
30
- }
31
- // const config = getSyntaxConfig();
32
- //
33
- // let match: number = 0;
34
- let result = null;
35
- // const combinators: EnumToken[] = combinatorsTokens.filter((t: EnumToken) => t != EnumToken.DescendantCombinatorTokenType);
36
- for (const t of splitTokenList(tokens, combinatorsTokens)) {
37
- result = validateCompoundSelector(t, root, options);
38
- if (result.valid == SyntaxValidationResult.Drop) {
39
- return result;
40
- }
41
- }
42
- // @ts-ignore
43
- return result ?? {
44
- valid: SyntaxValidationResult.Drop,
45
- context: [],
46
- node: root,
47
- syntax: null,
48
- error: 'expecting compound-selector'
49
- };
50
- }
51
-
52
- export { combinatorsTokens, validateComplexSelector };
@@ -1,196 +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 { mozExtensions, webkitExtensions } 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 { getSyntaxConfig } from '../config.js';
12
-
13
- function validateCompoundSelector(tokens, root, options) {
14
- if (tokens.length == 0) {
15
- // @ts-ignore
16
- return {
17
- valid: SyntaxValidationResult.Drop,
18
- context: [],
19
- // @ts-ignore
20
- node: root,
21
- // @ts-ignore
22
- syntax: null,
23
- error: 'expected selector'
24
- };
25
- }
26
- tokens = tokens.slice();
27
- consumeWhitespace(tokens);
28
- const config = getSyntaxConfig();
29
- let match = 0;
30
- let length = tokens.length;
31
- while (tokens.length > 0) {
32
- while (tokens.length > 0 && tokens[0].typ == EnumToken.NestingSelectorTokenType) {
33
- if (!options?.nestedSelector) {
34
- // @ts-ignore
35
- return {
36
- valid: SyntaxValidationResult.Drop,
37
- context: [],
38
- // @ts-ignore
39
- node: tokens[0],
40
- syntax: null,
41
- error: 'nested selector not allowed'
42
- };
43
- }
44
- match++;
45
- tokens.shift();
46
- consumeWhitespace(tokens);
47
- }
48
- // <type-selector>
49
- while (tokens.length > 0 &&
50
- [
51
- EnumToken.IdenTokenType,
52
- EnumToken.NameSpaceAttributeTokenType,
53
- EnumToken.ClassSelectorTokenType,
54
- EnumToken.HashTokenType,
55
- EnumToken.UniversalSelectorTokenType
56
- ].includes(tokens[0].typ)) {
57
- match++;
58
- tokens.shift();
59
- consumeWhitespace(tokens);
60
- }
61
- while (tokens.length > 0 && tokens[0].typ == EnumToken.PseudoClassFuncTokenType) {
62
- if (!mozExtensions.has(tokens[0].val + '()') &&
63
- !webkitExtensions.has(tokens[0].val + '()') &&
64
- !((tokens[0].val + '()') in config.selectors)) {
65
- if (!options?.lenient || /^(:?)-webkit-/.test(tokens[0].val)) {
66
- // @ts-ignore
67
- return {
68
- valid: SyntaxValidationResult.Drop,
69
- context: [],
70
- // @ts-ignore
71
- node: tokens[0],
72
- syntax: null,
73
- error: 'unknown pseudo-class: ' + tokens[0].val + '()'
74
- };
75
- }
76
- }
77
- match++;
78
- tokens.shift();
79
- consumeWhitespace(tokens);
80
- }
81
- while (tokens.length > 0 && (tokens[0].typ == EnumToken.PseudoElementTokenType || tokens[0].typ == EnumToken.PseudoClassTokenType)) {
82
- const isPseudoElement = tokens[0].typ == EnumToken.PseudoElementTokenType;
83
- if (
84
- // https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions#pseudo-elements
85
- !(isPseudoElement && tokens[0].val.startsWith('::-webkit-')) &&
86
- !mozExtensions.has(tokens[0].val) &&
87
- !webkitExtensions.has(tokens[0].val) &&
88
- !(tokens[0].val in config.selectors) &&
89
- !(!isPseudoElement &&
90
- (':' + tokens[0].val) in config.selectors)) {
91
- if (!options?.lenient || /^(:?)-webkit-/.test(tokens[0].val)) {
92
- // @ts-ignore
93
- return {
94
- valid: SyntaxValidationResult.Drop,
95
- context: [],
96
- // @ts-ignore
97
- node: tokens[0],
98
- syntax: null,
99
- error: 'unknown pseudo-class: ' + tokens[0].val
100
- };
101
- }
102
- }
103
- match++;
104
- tokens.shift();
105
- consumeWhitespace(tokens);
106
- }
107
- while (tokens.length > 0 && tokens[0].typ == EnumToken.AttrTokenType) {
108
- const children = tokens[0].chi.slice();
109
- consumeWhitespace(children);
110
- if (children.length == 0 || ![
111
- EnumToken.IdenTokenType,
112
- EnumToken.NameSpaceAttributeTokenType,
113
- EnumToken.MatchExpressionTokenType
114
- ].includes(children[0].typ)) {
115
- // @ts-ignore
116
- return {
117
- valid: SyntaxValidationResult.Drop,
118
- context: [],
119
- node: tokens[0],
120
- syntax: null,
121
- error: 'invalid attribute selector'
122
- };
123
- }
124
- if (children[0].typ == EnumToken.MatchExpressionTokenType) {
125
- if (children.length != 1) {
126
- return {
127
- valid: SyntaxValidationResult.Drop,
128
- context: [],
129
- node: tokens[0],
130
- syntax: null,
131
- error: 'invalid <attribute-selector>'
132
- };
133
- }
134
- if (![
135
- EnumToken.IdenTokenType,
136
- EnumToken.NameSpaceAttributeTokenType
137
- ].includes(children[0].l.typ) ||
138
- ![
139
- EnumToken.EqualMatchTokenType, EnumToken.DashMatchTokenType,
140
- EnumToken.StartMatchTokenType, EnumToken.ContainMatchTokenType,
141
- EnumToken.EndMatchTokenType, EnumToken.IncludeMatchTokenType
142
- ].includes(children[0].op.typ) ||
143
- ![
144
- EnumToken.StringTokenType,
145
- EnumToken.IdenTokenType
146
- ].includes(children[0].r.typ) ||
147
- (children[0].attr != null && !['i', 's'].includes(children[0].attr))) {
148
- // @ts-ignore
149
- return {
150
- valid: SyntaxValidationResult.Drop,
151
- context: [],
152
- node: tokens[0],
153
- syntax: null,
154
- error: 'invalid attribute selector'
155
- };
156
- }
157
- }
158
- match++;
159
- tokens.shift();
160
- consumeWhitespace(tokens);
161
- }
162
- if (length == tokens.length) {
163
- return {
164
- valid: SyntaxValidationResult.Drop,
165
- context: [],
166
- // @ts-ignore
167
- node: tokens[0],
168
- // @ts-ignore
169
- syntax: null,
170
- error: 'expected compound selector'
171
- };
172
- }
173
- length = tokens.length;
174
- }
175
- return match == 0 ? {
176
- valid: SyntaxValidationResult.Drop,
177
- context: [],
178
- // @ts-ignore
179
- node: root,
180
- // @ts-ignore
181
- syntax: null,
182
- error: 'expected compound selector'
183
- } :
184
- // @ts-ignore
185
- {
186
- valid: SyntaxValidationResult.Valid,
187
- context: [],
188
- // @ts-ignore
189
- node: root,
190
- // @ts-ignore
191
- syntax: null,
192
- error: null
193
- };
194
- }
195
-
196
- export { validateCompoundSelector };
@@ -1,57 +0,0 @@
1
- import { EnumToken, 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 { consumeWhitespace } from '../utils/whitespace.js';
10
-
11
- function validateFamilyName(tokens, atRule) {
12
- let node;
13
- tokens = tokens.slice();
14
- consumeWhitespace(tokens);
15
- if (tokens.length == 0 || tokens[0].typ == EnumToken.CommaTokenType) {
16
- // @ts-ignore
17
- return {
18
- valid: SyntaxValidationResult.Drop,
19
- matches: [],
20
- node: tokens[0],
21
- syntax: null,
22
- error: 'unexpected token',
23
- tokens
24
- };
25
- }
26
- while (tokens.length > 0) {
27
- node = tokens[0];
28
- if (![EnumToken.IdenTokenType, EnumToken.StringTokenType].includes(node.typ)) {
29
- // @ts-ignore
30
- return {
31
- valid: SyntaxValidationResult.Drop,
32
- matches: [],
33
- node,
34
- syntax: null,
35
- error: 'unexpected token',
36
- tokens
37
- };
38
- }
39
- tokens.shift();
40
- consumeWhitespace(tokens);
41
- // @ts-ignore
42
- if (tokens.length > 0 && tokens[0].typ == EnumToken.CommaTokenType) {
43
- tokens.shift();
44
- }
45
- }
46
- // @ts-ignore
47
- return {
48
- valid: SyntaxValidationResult.Valid,
49
- matches: [],
50
- node: null,
51
- syntax: null,
52
- error: '',
53
- tokens
54
- };
55
- }
56
-
57
- export { validateFamilyName };
@@ -1,36 +0,0 @@
1
- import { consumeWhitespace } from '../utils/whitespace.js';
2
- import { splitTokenList } from '../utils/list.js';
3
- import { EnumToken, SyntaxValidationResult } from '../../ast/types.js';
4
- import '../../ast/minify.js';
5
- import '../../ast/walk.js';
6
- import '../../parser/parse.js';
7
- import '../../parser/tokenize.js';
8
- import '../../parser/utils/config.js';
9
- import '../../syntax/color/utils/constants.js';
10
- import '../../renderer/sourcemap/lib/encode.js';
11
-
12
- function validateKeyframeSelector(tokens, options) {
13
- consumeWhitespace(tokens);
14
- for (const t of splitTokenList(tokens)) {
15
- if (t.length != 1 || (t[0].typ != EnumToken.PercentageTokenType && !(t[0].typ == EnumToken.IdenTokenType && ['from', 'to', 'cover', 'contain', 'entry', 'exit', 'entry-crossing', 'exit-crossing'].includes(t[0].val)))) {
16
- return {
17
- valid: SyntaxValidationResult.Drop,
18
- context: [],
19
- node: t[0],
20
- syntax: null,
21
- error: 'expected keyframe selector'
22
- };
23
- }
24
- }
25
- // @ts-ignore
26
- return {
27
- valid: SyntaxValidationResult.Valid,
28
- context: [],
29
- node: null,
30
- // @ts-ignore
31
- syntax: null,
32
- error: ''
33
- };
34
- }
35
-
36
- export { validateKeyframeSelector };
@@ -1,57 +0,0 @@
1
- import { EnumToken, 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
-
10
- function validateLayerName(tokens) {
11
- const slice = tokens.reduce((acc, curr) => {
12
- if (curr.typ == EnumToken.CommaTokenType) {
13
- acc.push([]);
14
- }
15
- else if (curr.typ != EnumToken.CommentTokenType) {
16
- acc[acc.length - 1].push(curr);
17
- }
18
- return acc;
19
- }, [[]]);
20
- for (let i = 0; i < slice.length; i++) {
21
- if (slice[i].length == 0) {
22
- // @ts-ignore
23
- return {
24
- valid: SyntaxValidationResult.Drop,
25
- matches: tokens,
26
- node: null,
27
- syntax: null,
28
- error: 'Invalid ident',
29
- tokens
30
- };
31
- }
32
- for (let j = 0; j < slice[i].length; j++) {
33
- if (slice[i][j].typ != EnumToken.IdenTokenType && slice[i][j].typ != EnumToken.ClassSelectorTokenType) {
34
- // @ts-ignore
35
- return {
36
- valid: SyntaxValidationResult.Drop,
37
- matches: tokens,
38
- node: slice[i][j],
39
- syntax: '<layer-name>',
40
- error: 'expecting ident or class selector',
41
- tokens
42
- };
43
- }
44
- }
45
- }
46
- // @ts-ignore
47
- return {
48
- valid: SyntaxValidationResult.Valid,
49
- matches: tokens,
50
- node: null,
51
- syntax: null,
52
- error: '',
53
- tokens
54
- };
55
- }
56
-
57
- export { validateLayerName };
@@ -1,31 +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 { validateRelativeSelector } from './relative-selector.js';
10
- import { consumeWhitespace } from '../utils/whitespace.js';
11
- import { splitTokenList } from '../utils/list.js';
12
-
13
- function validateRelativeSelectorList(tokens, root, options) {
14
- tokens = tokens.slice();
15
- consumeWhitespace(tokens);
16
- for (const t of splitTokenList(tokens)) {
17
- const result = validateRelativeSelector(t, root, options);
18
- if (result.valid == SyntaxValidationResult.Drop) {
19
- return result;
20
- }
21
- }
22
- // @ts-ignore
23
- return {
24
- valid: SyntaxValidationResult.Valid,
25
- node: root,
26
- syntax: null,
27
- error: ''
28
- };
29
- }
30
-
31
- export { validateRelativeSelectorList };
@@ -1,38 +0,0 @@
1
- import { consumeWhitespace } from '../utils/whitespace.js';
2
- import '../../ast/types.js';
3
- import '../../ast/minify.js';
4
- import '../../ast/walk.js';
5
- import '../../parser/parse.js';
6
- import '../../parser/tokenize.js';
7
- import '../../parser/utils/config.js';
8
- import '../../syntax/color/utils/constants.js';
9
- import '../../renderer/sourcemap/lib/encode.js';
10
- import { validateSelector } from './selector.js';
11
- import { combinatorsTokens } from './complex-selector.js';
12
-
13
- function validateRelativeSelector(tokens, root, options) {
14
- tokens = tokens.slice();
15
- consumeWhitespace(tokens);
16
- // if (tokens.length == 0) {
17
- //
18
- // // @ts-ignore
19
- // return {
20
- // valid: ValidationLevel.Drop,
21
- // matches: [],
22
- // // @ts-ignore
23
- // node: root,
24
- // // @ts-ignore
25
- // syntax: null,
26
- // error: 'expected selector',
27
- // tokens
28
- // }
29
- // }
30
- // , EnumToken.DescendantCombinatorTokenType
31
- if (combinatorsTokens.includes(tokens[0].typ)) {
32
- tokens.shift();
33
- consumeWhitespace(tokens);
34
- }
35
- return validateSelector(tokens, root, options);
36
- }
37
-
38
- export { validateRelativeSelector };
@@ -1,5 +0,0 @@
1
- import { validateComplexSelectorList } from './complex-selector-list.js';
2
-
3
- const validateSelectorList = validateComplexSelectorList;
4
-
5
- export { validateSelectorList };
@@ -1,5 +0,0 @@
1
- import { validateComplexSelector } from './complex-selector.js';
2
-
3
- const validateSelector = validateComplexSelector;
4
-
5
- export { validateSelector };
@@ -1,40 +0,0 @@
1
- import { EnumToken, 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 { consumeWhitespace } from '../utils/whitespace.js';
10
-
11
- function validateURL(token) {
12
- const children = token.chi.slice();
13
- consumeWhitespace(children);
14
- if (children.length > 0 && [EnumToken.UrlTokenTokenType, EnumToken.StringTokenType, EnumToken.HashTokenType].includes(children[0].typ)) {
15
- children.shift();
16
- }
17
- consumeWhitespace(children);
18
- if (children.length > 0) {
19
- // @ts-ignore
20
- return {
21
- valid: SyntaxValidationResult.Drop,
22
- context: [],
23
- node: children[0] ?? token,
24
- // @ts-ignore
25
- syntax: 'url()',
26
- error: 'unexpected token'
27
- };
28
- }
29
- // @ts-ignore
30
- return {
31
- valid: SyntaxValidationResult.Valid,
32
- context: [],
33
- node: token,
34
- // @ts-ignore
35
- syntax: 'url()',
36
- error: ''
37
- };
38
- }
39
-
40
- export { validateURL };