@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,150 +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 { validateAtRuleMediaQueryList } from './media.js';
10
- import { consumeWhitespace } from '../utils/whitespace.js';
11
- import { validateLayerName } from '../syntaxes/layer-name.js';
12
- import '../syntaxes/complex-selector.js';
13
- import '../syntax.js';
14
- import '../config.js';
15
- import { validateAtRuleSupportsConditions } from './supports.js';
16
-
17
- function validateAtRuleImport(atRule, options, root) {
18
- if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
19
- // @ts-ignore
20
- return {
21
- valid: SyntaxValidationResult.Drop,
22
- context: [],
23
- node: null,
24
- syntax: '@' + atRule.nam,
25
- error: 'expected @import media query list'
26
- };
27
- }
28
- if ('chi' in atRule) {
29
- // @ts-ignore
30
- return {
31
- valid: SyntaxValidationResult.Drop,
32
- context: [],
33
- node: null,
34
- syntax: '@' + atRule.nam,
35
- error: 'unexpected at-rule body'
36
- };
37
- }
38
- const tokens = atRule.tokens.filter((t) => ![EnumToken.CommentTokenType].includes(t.typ));
39
- if (tokens.length == 0) {
40
- // @ts-ignore
41
- return {
42
- valid: SyntaxValidationResult.Drop,
43
- context: [],
44
- node: null,
45
- syntax: '@' + atRule.nam,
46
- error: 'expected @import media query list'
47
- };
48
- }
49
- if (tokens[0].typ == EnumToken.StringTokenType) {
50
- tokens.shift();
51
- // @ts-ignore
52
- consumeWhitespace(tokens);
53
- }
54
- else if (tokens[0].typ == EnumToken.UrlFunctionTokenType) {
55
- const slice = tokens[0].chi.filter((t) => t.typ != EnumToken.CommentTokenType && t.typ != EnumToken.WhitespaceTokenType);
56
- if (slice.length != 1 || ![EnumToken.StringTokenType, EnumToken.UrlTokenTokenType].includes(slice[0].typ)) {
57
- // @ts-ignore
58
- return {
59
- valid: SyntaxValidationResult.Drop,
60
- context: [],
61
- node: tokens[0],
62
- syntax: '@' + atRule.nam,
63
- error: 'invalid url()'
64
- };
65
- }
66
- else {
67
- tokens.shift();
68
- // @ts-ignore
69
- if (!consumeWhitespace(tokens)) {
70
- // @ts-ignore
71
- return {
72
- valid: SyntaxValidationResult.Drop,
73
- context: [],
74
- node: tokens[0],
75
- syntax: '@' + atRule.nam,
76
- error: 'expecting whitespace'
77
- };
78
- }
79
- }
80
- tokens.shift();
81
- // @ts-ignore
82
- consumeWhitespace(tokens);
83
- }
84
- else {
85
- // @ts-ignore
86
- return {
87
- valid: SyntaxValidationResult.Drop,
88
- context: [],
89
- node: tokens[0],
90
- syntax: '@' + atRule.nam,
91
- error: 'expecting url() or string'
92
- };
93
- }
94
- if (tokens.length > 0) {
95
- // @ts-ignore
96
- if (tokens[0].typ == EnumToken.IdenTokenType) {
97
- if ('layer' === tokens[0].val.toLowerCase()) {
98
- tokens.shift();
99
- // @ts-ignore
100
- if (!consumeWhitespace(tokens)) {
101
- // @ts-ignore
102
- return {
103
- valid: SyntaxValidationResult.Drop,
104
- context: [],
105
- node: tokens[0],
106
- syntax: '@' + atRule.nam,
107
- error: 'expecting whitespace'
108
- };
109
- }
110
- }
111
- }
112
- // @ts-ignore
113
- else if (tokens[0].typ == EnumToken.FunctionTokenType) {
114
- // @ts-ignore
115
- if ('layer' === tokens[0].val.toLowerCase()) {
116
- const result = validateLayerName(tokens[0].chi);
117
- if (result.valid == SyntaxValidationResult.Drop) {
118
- return result;
119
- }
120
- tokens.shift();
121
- // @ts-ignore
122
- consumeWhitespace(tokens);
123
- }
124
- // tokens[0]?.val
125
- // @ts-ignore
126
- if ('supports' === tokens[0]?.val?.toLowerCase?.()) {
127
- const result = validateAtRuleSupportsConditions(atRule, tokens[0].chi);
128
- if (result.valid == SyntaxValidationResult.Drop) {
129
- return result;
130
- }
131
- tokens.shift();
132
- // @ts-ignore
133
- consumeWhitespace(tokens);
134
- }
135
- }
136
- }
137
- if (tokens.length > 0) {
138
- return validateAtRuleMediaQueryList(tokens, atRule);
139
- }
140
- // @ts-ignore
141
- return {
142
- valid: SyntaxValidationResult.Valid,
143
- context: [],
144
- node: null,
145
- syntax: '@' + atRule.nam,
146
- error: ''
147
- };
148
- }
149
-
150
- export { validateAtRuleImport };
@@ -1,67 +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
-
11
- function validateAtRuleKeyframes(atRule, options, root) {
12
- if (!Array.isArray(atRule.chi)) {
13
- // @ts-ignore
14
- return {
15
- valid: SyntaxValidationResult.Drop,
16
- matches: [],
17
- node: atRule,
18
- syntax: '@' + atRule.nam,
19
- error: 'expected supports body',
20
- tokens: []
21
- };
22
- }
23
- if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
24
- // @ts-ignore
25
- return {
26
- valid: SyntaxValidationResult.Drop,
27
- context: [],
28
- node: atRule,
29
- syntax: '@keyframes',
30
- error: 'expecting at-rule prelude'
31
- };
32
- }
33
- const tokens = atRule.tokens.filter((t) => t.typ != EnumToken.CommentTokenType).slice();
34
- consumeWhitespace(tokens);
35
- if (tokens.length == 0 || ![EnumToken.StringTokenType, EnumToken.IdenTokenType].includes(tokens[0].typ)) {
36
- // @ts-ignore
37
- return {
38
- valid: SyntaxValidationResult.Drop,
39
- context: [],
40
- node: atRule,
41
- syntax: '@keyframes',
42
- error: 'expecting ident or string token'
43
- };
44
- }
45
- tokens.shift();
46
- consumeWhitespace(tokens);
47
- if (tokens.length > 0) {
48
- // @ts-ignore
49
- return {
50
- valid: SyntaxValidationResult.Drop,
51
- context: [],
52
- node: tokens[0],
53
- syntax: '@keyframes',
54
- error: 'unexpected token'
55
- };
56
- }
57
- // @ts-ignore
58
- return {
59
- valid: SyntaxValidationResult.Valid,
60
- context: [],
61
- node: atRule,
62
- syntax: '@keyframes',
63
- error: ''
64
- };
65
- }
66
-
67
- export { validateAtRuleKeyframes };
@@ -1,41 +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 { validateLayerName } from '../syntaxes/layer-name.js';
10
- import '../syntaxes/complex-selector.js';
11
- import '../syntax.js';
12
- import '../config.js';
13
-
14
- function validateAtRuleLayer(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
- // media-query-list
27
- if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
28
- // @ts-ignore
29
- return {
30
- valid: SyntaxValidationResult.Valid,
31
- matches: [],
32
- node: atRule,
33
- syntax: '@layer',
34
- error: '',
35
- tokens: []
36
- };
37
- }
38
- return validateLayerName(atRule.tokens);
39
- }
40
-
41
- export { validateAtRuleLayer };
@@ -1,255 +0,0 @@
1
- import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
2
- import '../../ast/minify.js';
3
- import '../../ast/walk.js';
4
- import '../../parser/parse.js';
5
- import '../../parser/tokenize.js';
6
- import '../../parser/utils/config.js';
7
- import { generalEnclosedFunc } from '../../syntax/color/utils/constants.js';
8
- import '../../renderer/sourcemap/lib/encode.js';
9
- import { consumeWhitespace } from '../utils/whitespace.js';
10
- import { splitTokenList } from '../utils/list.js';
11
-
12
- function validateAtRuleMedia(atRule, options, root) {
13
- if (!Array.isArray(atRule.chi)) {
14
- // @ts-ignore
15
- return {
16
- valid: SyntaxValidationResult.Drop,
17
- matches: [],
18
- node: atRule,
19
- syntax: '@' + atRule.nam,
20
- error: 'expected supports body',
21
- tokens: []
22
- };
23
- }
24
- // media-query-list
25
- if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
26
- // @ts-ignore
27
- return {
28
- valid: SyntaxValidationResult.Valid,
29
- context: [],
30
- node: null,
31
- syntax: null,
32
- error: '',
33
- tokens: []
34
- };
35
- }
36
- let result = null;
37
- const slice = atRule.tokens.slice();
38
- consumeWhitespace(slice);
39
- if (slice.length == 0) {
40
- return {
41
- valid: SyntaxValidationResult.Valid,
42
- context: [],
43
- node: atRule,
44
- syntax: '@media',
45
- error: ''
46
- };
47
- }
48
- result = validateAtRuleMediaQueryList(atRule.tokens, atRule);
49
- if (result.valid == SyntaxValidationResult.Drop) {
50
- return result;
51
- }
52
- if (!('chi' in atRule)) {
53
- // @ts-ignore
54
- return {
55
- valid: SyntaxValidationResult.Drop,
56
- context: [],
57
- node: atRule,
58
- syntax: '@media',
59
- error: 'expected at-rule body'
60
- };
61
- }
62
- // @ts-ignore
63
- return {
64
- valid: SyntaxValidationResult.Valid,
65
- context: [],
66
- node: atRule,
67
- syntax: '@media',
68
- error: ''
69
- };
70
- }
71
- function validateAtRuleMediaQueryList(tokenList, atRule) {
72
- const split = splitTokenList(tokenList);
73
- const matched = [];
74
- let result = null;
75
- let previousToken;
76
- let mediaFeatureType;
77
- for (let i = 0; i < split.length; i++) {
78
- const tokens = split[i].slice();
79
- const match = [];
80
- result = null;
81
- mediaFeatureType = null;
82
- previousToken = null;
83
- if (tokens.length == 0) {
84
- // @ts-ignore
85
- result = {
86
- valid: SyntaxValidationResult.Drop,
87
- context: [],
88
- node: tokens[0] ?? atRule,
89
- syntax: '@media',
90
- error: 'unexpected token'
91
- };
92
- continue;
93
- }
94
- while (tokens.length > 0) {
95
- previousToken = tokens[0];
96
- // media-condition | media-type | custom-media
97
- if (!(validateMediaCondition(tokens[0], atRule) || validateMediaFeature(tokens[0]) || validateCustomMediaCondition(tokens[0], atRule))) {
98
- if (tokens[0].typ == EnumToken.ParensTokenType) {
99
- result = validateAtRuleMediaQueryList(tokens[0].chi, atRule);
100
- }
101
- else {
102
- result = {
103
- valid: SyntaxValidationResult.Drop,
104
- context: [],
105
- node: tokens[0] ?? atRule,
106
- syntax: '@media',
107
- error: 'expecting media feature or media condition'
108
- };
109
- }
110
- if (result.valid == SyntaxValidationResult.Drop) {
111
- break;
112
- }
113
- result = null;
114
- }
115
- match.push(tokens.shift());
116
- if (tokens.length == 0) {
117
- break;
118
- }
119
- if (!consumeWhitespace(tokens)) {
120
- if (previousToken?.typ != EnumToken.ParensTokenType) {
121
- // @ts-ignore
122
- result = {
123
- valid: SyntaxValidationResult.Drop,
124
- context: [],
125
- node: tokens[0] ?? atRule,
126
- syntax: '@media',
127
- error: 'expected media query list'
128
- };
129
- break;
130
- }
131
- }
132
- else if (![EnumToken.MediaFeatureOrTokenType, EnumToken.MediaFeatureAndTokenType].includes(tokens[0].typ)) {
133
- // @ts-ignore
134
- result = {
135
- valid: SyntaxValidationResult.Drop,
136
- context: [],
137
- node: tokens[0] ?? atRule,
138
- syntax: '@media',
139
- error: 'expected and/or'
140
- };
141
- break;
142
- }
143
- if (mediaFeatureType == null) {
144
- mediaFeatureType = tokens[0];
145
- }
146
- if (mediaFeatureType.typ != tokens[0].typ) {
147
- // @ts-ignore
148
- result = {
149
- valid: SyntaxValidationResult.Drop,
150
- context: [],
151
- node: tokens[0] ?? atRule,
152
- syntax: '@media',
153
- error: 'mixing and/or not allowed at the same level'
154
- };
155
- break;
156
- }
157
- match.push({ typ: EnumToken.WhitespaceTokenType }, tokens.shift());
158
- consumeWhitespace(tokens);
159
- if (tokens.length == 0) {
160
- // @ts-ignore
161
- result = {
162
- valid: SyntaxValidationResult.Drop,
163
- context: [],
164
- node: tokens[0] ?? atRule,
165
- syntax: '@media',
166
- error: 'expected media-condition'
167
- };
168
- break;
169
- }
170
- match.push({ typ: EnumToken.WhitespaceTokenType });
171
- }
172
- if (result == null && match.length > 0) {
173
- matched.push(match);
174
- }
175
- }
176
- if (result != null) {
177
- return result;
178
- }
179
- if (matched.length == 0) {
180
- return {
181
- valid: SyntaxValidationResult.Drop,
182
- context: [],
183
- node: atRule,
184
- syntax: '@media',
185
- error: 'expected media query list'
186
- };
187
- }
188
- tokenList.length = 0;
189
- let hasAll = false;
190
- for (let i = 0; i < matched.length; i++) {
191
- if (tokenList.length > 0) {
192
- tokenList.push({ typ: EnumToken.CommaTokenType });
193
- }
194
- if (matched[i].length == 1 && matched.length > 1 && matched[i][0].typ == EnumToken.MediaFeatureTokenType && matched[i][0].val == 'all') {
195
- hasAll = true;
196
- continue;
197
- }
198
- tokenList.push(...matched[i]);
199
- }
200
- if (hasAll && tokenList.length == 0) {
201
- tokenList.push({ typ: EnumToken.MediaFeatureTokenType, val: 'all' });
202
- }
203
- // @ts-ignore
204
- return {
205
- valid: SyntaxValidationResult.Valid,
206
- context: [],
207
- node: atRule,
208
- syntax: '@media',
209
- error: ''
210
- };
211
- }
212
- function validateCustomMediaCondition(token, atRule) {
213
- if (token.typ == EnumToken.MediaFeatureNotTokenType) {
214
- return validateMediaCondition(token.val, atRule);
215
- }
216
- if (token.typ != EnumToken.ParensTokenType) {
217
- return false;
218
- }
219
- const chi = token.chi.filter((t) => t.typ != EnumToken.CommentTokenType && t.typ != EnumToken.WhitespaceTokenType);
220
- if (chi.length != 1) {
221
- return false;
222
- }
223
- return chi[0].typ == EnumToken.DashedIdenTokenType;
224
- }
225
- function validateMediaCondition(token, atRule) {
226
- if (token.typ == EnumToken.MediaFeatureNotTokenType) {
227
- return validateMediaCondition(token.val, atRule);
228
- }
229
- if (token.typ != EnumToken.ParensTokenType && !(['when', 'else', 'import'].includes(atRule.nam) && token.typ == EnumToken.FunctionTokenType && generalEnclosedFunc.includes(token.val))) {
230
- return false;
231
- }
232
- const chi = token.chi.filter((t) => t.typ != EnumToken.CommentTokenType && t.typ != EnumToken.WhitespaceTokenType);
233
- if (chi.length != 1) {
234
- return false;
235
- }
236
- if (chi[0].typ == EnumToken.IdenTokenType) {
237
- return true;
238
- }
239
- if (chi[0].typ == EnumToken.MediaFeatureNotTokenType) {
240
- return validateMediaCondition(chi[0].val, atRule);
241
- }
242
- if (chi[0].typ == EnumToken.MediaQueryConditionTokenType) {
243
- return chi[0].l.typ == EnumToken.IdenTokenType;
244
- }
245
- return false;
246
- }
247
- function validateMediaFeature(token) {
248
- let val = token;
249
- if (token.typ == EnumToken.MediaFeatureOnlyTokenType || token.typ == EnumToken.MediaFeatureNotTokenType) {
250
- val = token.val;
251
- }
252
- return val.typ == EnumToken.MediaFeatureTokenType;
253
- }
254
-
255
- export { validateAtRuleMedia, validateAtRuleMediaQueryList, validateMediaCondition, validateMediaFeature };
@@ -1,81 +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 { validateURL } from '../syntaxes/url.js';
11
-
12
- function validateAtRuleNamespace(atRule, options, root) {
13
- if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
14
- // @ts-ignore
15
- return {
16
- valid: SyntaxValidationResult.Drop,
17
- context: [],
18
- node: atRule,
19
- syntax: '@namespace',
20
- error: 'expected at-rule prelude'
21
- };
22
- }
23
- if ('chi' in atRule) {
24
- // @ts-ignore
25
- return {
26
- valid: SyntaxValidationResult.Drop,
27
- context: [],
28
- node: atRule,
29
- syntax: '@namespace',
30
- error: 'unexpected at-rule body'
31
- };
32
- }
33
- const tokens = atRule.tokens.slice();
34
- consumeWhitespace(tokens);
35
- if (tokens[0].typ == EnumToken.IdenTokenType) {
36
- tokens.shift();
37
- consumeWhitespace(tokens);
38
- }
39
- if (tokens.length == 0) {
40
- // @ts-ignore
41
- return {
42
- valid: SyntaxValidationResult.Drop,
43
- context: [],
44
- node: atRule,
45
- syntax: '@namespace',
46
- error: 'expected string or url()'
47
- };
48
- }
49
- if (tokens[0].typ != EnumToken.StringTokenType) {
50
- const result = validateURL(tokens[0]);
51
- if (result.valid != SyntaxValidationResult.Valid) {
52
- return result;
53
- }
54
- tokens.shift();
55
- consumeWhitespace(tokens);
56
- }
57
- else {
58
- tokens.shift();
59
- consumeWhitespace(tokens);
60
- }
61
- if (tokens.length > 0) {
62
- // @ts-ignore
63
- return {
64
- valid: SyntaxValidationResult.Drop,
65
- context: [],
66
- node: tokens[0],
67
- syntax: '@namespace',
68
- error: 'unexpected token'
69
- };
70
- }
71
- // @ts-ignore
72
- return {
73
- valid: SyntaxValidationResult.Valid,
74
- context: [],
75
- node: atRule,
76
- syntax: '@namespace',
77
- error: ''
78
- };
79
- }
80
-
81
- export { validateAtRuleNamespace };
@@ -1,64 +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 validateAtRulePageMarginBox(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
- if (Array.isArray(atRule.tokens) && atRule.tokens.length > 0) {
23
- // @ts-ignore
24
- return {
25
- valid: SyntaxValidationResult.Valid,
26
- context: [],
27
- node: null,
28
- syntax: '@' + atRule.nam,
29
- error: ''
30
- };
31
- }
32
- if (!('chi' in atRule)) {
33
- // @ts-ignore
34
- return {
35
- valid: SyntaxValidationResult.Drop,
36
- context: [],
37
- node: atRule,
38
- syntax: '@' + atRule.nam,
39
- error: 'expected margin-box body'
40
- };
41
- }
42
- for (const token of atRule.chi) {
43
- if (![EnumToken.DeclarationNodeType, EnumToken.CommentNodeType, EnumToken.WhitespaceTokenType].includes(token.typ)) {
44
- // @ts-ignore
45
- return {
46
- valid: SyntaxValidationResult.Drop,
47
- context: [],
48
- node: token,
49
- syntax: 'declaration-list',
50
- error: 'expected margin-box body'
51
- };
52
- }
53
- }
54
- // @ts-ignore
55
- return {
56
- valid: SyntaxValidationResult.Valid,
57
- context: [],
58
- node: null,
59
- syntax: '@' + atRule.nam,
60
- error: ''
61
- };
62
- }
63
-
64
- export { validateAtRulePageMarginBox };