@tbela99/css-parser 1.4.1 → 1.4.3

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 (216) hide show
  1. package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
  2. package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
  3. package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
  4. package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
  5. package/.repl_history +4 -0
  6. package/CHANGELOG.md +168 -4
  7. package/README.md +82 -0
  8. package/badges/coverage.svg +20 -0
  9. package/deno.lock +2861 -0
  10. package/dist/config.json.js +33 -1
  11. package/dist/index-umd-web.js +24393 -18479
  12. package/dist/index.cjs +27430 -21519
  13. package/dist/index.d.ts +1403 -933
  14. package/dist/lib/ast/clone.d.ts +10 -0
  15. package/dist/lib/ast/clone.js +45 -0
  16. package/dist/lib/ast/expand.d.ts +14 -0
  17. package/dist/lib/ast/expand.js +89 -64
  18. package/dist/lib/ast/features/calc.d.ts +10 -0
  19. package/dist/lib/ast/features/calc.js +62 -24
  20. package/dist/lib/ast/features/if.d.ts +10 -0
  21. package/dist/lib/ast/features/if.js +215 -0
  22. package/dist/lib/ast/features/index.d.ts +6 -0
  23. package/dist/lib/ast/features/index.js +1 -0
  24. package/dist/lib/ast/features/inlinecssvariables.d.ts +15 -0
  25. package/dist/lib/ast/features/inlinecssvariables.js +32 -27
  26. package/dist/lib/ast/features/prefix.d.ts +8 -0
  27. package/dist/lib/ast/features/prefix.js +68 -43
  28. package/dist/lib/ast/features/shorthand.d.ts +12 -0
  29. package/dist/lib/ast/features/shorthand.js +6 -9
  30. package/dist/lib/ast/features/transform.d.ts +10 -0
  31. package/dist/lib/ast/features/transform.js +9 -13
  32. package/dist/lib/ast/features/type.d.ts +15 -0
  33. package/dist/lib/ast/find.d.ts +165 -0
  34. package/dist/lib/ast/find.js +175 -0
  35. package/dist/lib/ast/math/expression.d.ts +18 -0
  36. package/dist/lib/ast/math/expression.js +140 -98
  37. package/dist/lib/ast/math/math.d.ts +6 -0
  38. package/dist/lib/ast/math/math.js +30 -41
  39. package/dist/lib/ast/minify.d.ts +19 -0
  40. package/dist/lib/ast/minify.js +543 -215
  41. package/dist/lib/ast/transform/compute.d.ts +8 -0
  42. package/dist/lib/ast/transform/compute.js +82 -69
  43. package/dist/lib/ast/transform/matrix.d.ts +22 -0
  44. package/dist/lib/ast/transform/matrix.js +12 -26
  45. package/dist/lib/ast/transform/minify.d.ts +5 -0
  46. package/dist/lib/ast/transform/minify.js +20 -20
  47. package/dist/lib/ast/transform/perspective.d.ts +3 -0
  48. package/dist/lib/ast/transform/perspective.js +1 -1
  49. package/dist/lib/ast/transform/rotate.d.ts +12 -0
  50. package/dist/lib/ast/transform/rotate.js +1 -1
  51. package/dist/lib/ast/transform/scale.d.ts +6 -0
  52. package/dist/lib/ast/transform/scale.js +1 -1
  53. package/dist/lib/ast/transform/skew.d.ts +4 -0
  54. package/dist/lib/ast/transform/skew.js +1 -1
  55. package/dist/lib/ast/transform/translate.d.ts +6 -0
  56. package/dist/lib/ast/transform/translate.js +1 -1
  57. package/dist/lib/ast/transform/utils.d.ts +9 -0
  58. package/dist/lib/ast/types.d.ts +903 -0
  59. package/dist/lib/ast/types.js +277 -23
  60. package/dist/lib/ast/walk.d.ts +162 -0
  61. package/dist/lib/ast/walk.js +116 -60
  62. package/dist/lib/fs/resolve.d.ts +20 -0
  63. package/dist/lib/fs/resolve.js +37 -45
  64. package/dist/lib/parser/declaration/list.d.ts +16 -0
  65. package/dist/lib/parser/declaration/list.js +26 -24
  66. package/dist/lib/parser/declaration/map.d.ts +15 -0
  67. package/dist/lib/parser/declaration/map.js +140 -95
  68. package/dist/lib/parser/declaration/set.d.ts +9 -0
  69. package/dist/lib/parser/declaration/set.js +30 -25
  70. package/dist/lib/parser/node.d.ts +7 -0
  71. package/dist/lib/parser/parse.d.ts +107 -0
  72. package/dist/lib/parser/parse.js +1454 -1445
  73. package/dist/lib/parser/tokenize.d.ts +57 -0
  74. package/dist/lib/parser/tokenize.js +557 -404
  75. package/dist/lib/parser/utils/at-rule-container.d.ts +5 -0
  76. package/dist/lib/parser/utils/at-rule-container.js +486 -0
  77. package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +5 -0
  78. package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
  79. package/dist/lib/parser/utils/at-rule-generic.d.ts +5 -0
  80. package/dist/lib/parser/utils/at-rule-generic.js +118 -0
  81. package/dist/lib/parser/utils/at-rule-import.d.ts +5 -0
  82. package/dist/lib/parser/utils/at-rule-import.js +393 -0
  83. package/dist/lib/parser/utils/at-rule-media.d.ts +5 -0
  84. package/dist/lib/parser/utils/at-rule-media.js +603 -0
  85. package/dist/lib/parser/utils/at-rule-page.d.ts +5 -0
  86. package/dist/lib/parser/utils/at-rule-page.js +28 -0
  87. package/dist/lib/parser/utils/at-rule-support.d.ts +5 -0
  88. package/dist/lib/parser/utils/at-rule-support.js +366 -0
  89. package/dist/lib/parser/utils/at-rule-token.d.ts +1 -0
  90. package/dist/lib/parser/utils/at-rule-when-else.d.ts +5 -0
  91. package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
  92. package/dist/lib/parser/utils/at-rule.d.ts +13 -0
  93. package/dist/lib/parser/utils/at-rule.js +37 -0
  94. package/dist/lib/parser/utils/cache.d.ts +6 -0
  95. package/dist/lib/parser/utils/cache.js +19 -0
  96. package/dist/lib/parser/utils/config.d.ts +2 -0
  97. package/dist/lib/parser/utils/config.js +1 -0
  98. package/dist/lib/parser/utils/declaration-list.d.ts +5 -0
  99. package/dist/lib/parser/utils/declaration.d.ts +18 -0
  100. package/dist/lib/parser/utils/declaration.js +569 -91
  101. package/dist/lib/parser/utils/eq.d.ts +1 -0
  102. package/dist/lib/parser/utils/hash.d.ts +21 -0
  103. package/dist/lib/parser/utils/hash.js +1 -1
  104. package/dist/lib/parser/utils/selector.d.ts +5 -0
  105. package/dist/lib/parser/utils/selector.js +476 -0
  106. package/dist/lib/parser/utils/text.d.ts +3 -0
  107. package/dist/lib/parser/utils/text.js +17 -1
  108. package/dist/lib/parser/utils/token.d.ts +14 -0
  109. package/dist/lib/parser/utils/token.js +102 -0
  110. package/dist/lib/parser/utils/type.d.ts +2 -0
  111. package/dist/lib/parser/utils/type.js +29 -18
  112. package/dist/lib/renderer/render.d.ts +28 -0
  113. package/dist/lib/renderer/render.js +421 -262
  114. package/dist/lib/renderer/sourcemap/lib/encode.d.ts +1 -0
  115. package/dist/lib/renderer/sourcemap/sourcemap.d.ts +26 -0
  116. package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
  117. package/dist/lib/syntax/color/a98rgb.d.ts +2 -0
  118. package/dist/lib/syntax/color/a98rgb.js +8 -12
  119. package/dist/lib/syntax/color/cmyk.d.ts +10 -0
  120. package/dist/lib/syntax/color/cmyk.js +23 -21
  121. package/dist/lib/syntax/color/color-mix.d.ts +2 -0
  122. package/dist/lib/syntax/color/color-mix.js +88 -77
  123. package/dist/lib/syntax/color/color.d.ts +42 -0
  124. package/dist/lib/syntax/color/color.js +65 -68
  125. package/dist/lib/syntax/color/hex.d.ts +16 -0
  126. package/dist/lib/syntax/color/hex.js +27 -31
  127. package/dist/lib/syntax/color/hsl.d.ts +20 -0
  128. package/dist/lib/syntax/color/hsl.js +5 -12
  129. package/dist/lib/syntax/color/hsv.d.ts +2 -0
  130. package/dist/lib/syntax/color/hwb.d.ts +21 -0
  131. package/dist/lib/syntax/color/hwb.js +8 -21
  132. package/dist/lib/syntax/color/lab.d.ts +25 -0
  133. package/dist/lib/syntax/color/lab.js +20 -21
  134. package/dist/lib/syntax/color/lch.d.ts +23 -0
  135. package/dist/lib/syntax/color/lch.js +13 -15
  136. package/dist/lib/syntax/color/oklab.d.ts +22 -0
  137. package/dist/lib/syntax/color/oklab.js +20 -39
  138. package/dist/lib/syntax/color/oklch.d.ts +20 -0
  139. package/dist/lib/syntax/color/oklch.js +14 -16
  140. package/dist/lib/syntax/color/p3.d.ts +6 -0
  141. package/dist/lib/syntax/color/p3.js +0 -8
  142. package/dist/lib/syntax/color/prophotorgb.d.ts +2 -0
  143. package/dist/lib/syntax/color/rec2020.d.ts +2 -0
  144. package/dist/lib/syntax/color/rec2020.js +9 -13
  145. package/dist/lib/syntax/color/relativecolor.d.ts +13 -0
  146. package/dist/lib/syntax/color/relativecolor.js +68 -41
  147. package/dist/lib/syntax/color/rgb.d.ts +20 -0
  148. package/dist/lib/syntax/color/rgb.js +14 -18
  149. package/dist/lib/syntax/color/srgb.d.ts +23 -0
  150. package/dist/lib/syntax/color/srgb.js +27 -26
  151. package/dist/lib/syntax/color/utils/components.d.ts +2 -0
  152. package/dist/lib/syntax/color/utils/components.js +30 -14
  153. package/dist/lib/syntax/color/utils/distance.d.ts +18 -0
  154. package/dist/lib/syntax/color/utils/distance.js +1 -8
  155. package/dist/lib/syntax/color/utils/matrix.d.ts +6 -0
  156. package/dist/lib/syntax/color/xyz.d.ts +5 -0
  157. package/dist/lib/syntax/color/xyz.js +8 -20
  158. package/dist/lib/syntax/color/xyzd50.d.ts +4 -0
  159. package/dist/lib/syntax/color/xyzd50.js +6 -20
  160. package/dist/lib/syntax/constants.d.ts +67 -0
  161. package/dist/lib/syntax/constants.js +436 -0
  162. package/dist/lib/syntax/syntax.d.ts +38 -0
  163. package/dist/lib/syntax/syntax.js +533 -568
  164. package/dist/lib/validation/config.d.ts +14 -0
  165. package/dist/lib/validation/config.js +72 -33
  166. package/dist/lib/validation/config.json.js +1159 -74
  167. package/dist/lib/validation/json.d.ts +2 -0
  168. package/dist/lib/validation/match.d.ts +38 -0
  169. package/dist/lib/validation/match.js +2985 -0
  170. package/dist/lib/validation/parser/parse.d.ts +8 -0
  171. package/dist/lib/validation/parser/parse.js +684 -935
  172. package/dist/lib/validation/parser/typedef.d.ts +95 -0
  173. package/dist/lib/validation/parser/typedef.js +100 -0
  174. package/dist/lib/validation/utils/list.d.ts +4 -0
  175. package/dist/lib/validation/utils/list.js +4 -11
  176. package/dist/lib/validation/utils/whitespace.d.ts +2 -0
  177. package/dist/lib/validation/utils/whitespace.js +2 -8
  178. package/dist/node.d.ts +207 -0
  179. package/dist/node.js +53 -47
  180. package/dist/web.d.ts +169 -0
  181. package/dist/web.js +50 -41
  182. package/package.json +18 -13
  183. package/playground/index.html +1328 -0
  184. package/playground/sw.js +55 -0
  185. package/playground/tree.js +176 -0
  186. package/dist/lib/syntax/color/utils/constants.js +0 -214
  187. package/dist/lib/syntax/utils.js +0 -70
  188. package/dist/lib/validation/at-rules/container.js +0 -342
  189. package/dist/lib/validation/at-rules/counter-style.js +0 -90
  190. package/dist/lib/validation/at-rules/custom-media.js +0 -50
  191. package/dist/lib/validation/at-rules/document.js +0 -89
  192. package/dist/lib/validation/at-rules/else.js +0 -5
  193. package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
  194. package/dist/lib/validation/at-rules/import.js +0 -150
  195. package/dist/lib/validation/at-rules/keyframes.js +0 -67
  196. package/dist/lib/validation/at-rules/layer.js +0 -41
  197. package/dist/lib/validation/at-rules/media.js +0 -255
  198. package/dist/lib/validation/at-rules/namespace.js +0 -81
  199. package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
  200. package/dist/lib/validation/at-rules/page.js +0 -100
  201. package/dist/lib/validation/at-rules/supports.js +0 -295
  202. package/dist/lib/validation/at-rules/when.js +0 -185
  203. package/dist/lib/validation/atrule.js +0 -184
  204. package/dist/lib/validation/selector.js +0 -36
  205. package/dist/lib/validation/syntax.js +0 -1073
  206. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
  207. package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
  208. package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
  209. package/dist/lib/validation/syntaxes/family-name.js +0 -57
  210. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
  211. package/dist/lib/validation/syntaxes/layer-name.js +0 -57
  212. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
  213. package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
  214. package/dist/lib/validation/syntaxes/selector-list.js +0 -5
  215. package/dist/lib/validation/syntaxes/selector.js +0 -5
  216. package/dist/lib/validation/syntaxes/url.js +0 -40
@@ -0,0 +1,5 @@
1
+ import type { AstAtRule, AtRuleToken, ErrorDescription, ParserOptions, Token } from "../../../@types/index.d.ts";
2
+ export declare function parseAtRuleContainerQueryList(stream: Token[], context: AstAtRule | AtRuleToken, options?: ParserOptions): {
3
+ success: boolean;
4
+ errors: ErrorDescription[];
5
+ };
@@ -0,0 +1,486 @@
1
+ import { EnumToken } from '../../ast/types.js';
2
+ import { tokensfuncDefMap, mFLT, mFGT, definedPropertySettings } from '../../syntax/constants.js';
3
+ import { matchAllSyntax, createValidationContext, trimArray, isStyleRangeValue } from '../../validation/match.js';
4
+ import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
5
+ import { getSyntaxRule } from '../../validation/config.js';
6
+ import { parseColor } from '../../syntax/syntax.js';
7
+
8
+ function parseAtRuleContainerQueryList(stream, context, options = {}) {
9
+ let matchCount = 0;
10
+ const errors = [];
11
+ const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + context.nam);
12
+ const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
13
+ const parts = stream.reduce((acc, t) => {
14
+ if (t.typ === EnumToken.CommaTokenType && matchCount === 0) {
15
+ acc.push([]);
16
+ }
17
+ else {
18
+ acc[acc.length - 1].push(t);
19
+ if (t.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(t.typ)) {
20
+ matchCount++;
21
+ }
22
+ else if (t.typ === EnumToken.EndParensTokenType) {
23
+ if (matchCount > 0) {
24
+ matchCount--;
25
+ }
26
+ }
27
+ }
28
+ return acc;
29
+ }, [[]]);
30
+ const result = matchAllSyntax(syntax, createValidationContext(stream), options);
31
+ if (!result.success) {
32
+ errors.push(...result.errors);
33
+ return {
34
+ success: false,
35
+ errors,
36
+ };
37
+ }
38
+ {
39
+ for (const stream of parts.slice()) {
40
+ let success = true;
41
+ let i;
42
+ let currentScope = new Set();
43
+ const scopes = [currentScope];
44
+ const stack = [];
45
+ const tokens = [];
46
+ let expectAndOr = false;
47
+ i = 0;
48
+ while (i < stream.length &&
49
+ (stream[i]?.typ === EnumToken.WhitespaceTokenType || stream[i]?.typ === EnumToken.CommentTokenType)) {
50
+ tokens.push(stream[i++]);
51
+ }
52
+ if (i >= stream.length) {
53
+ return {
54
+ success: false,
55
+ errors: [
56
+ {
57
+ action: "drop",
58
+ node: context,
59
+ location: context.loc,
60
+ message: `expecting <container-condition> at ${context.loc?.src}:${context?.loc?.sta.lin}:${context.loc?.sta.col}`,
61
+ },
62
+ ],
63
+ };
64
+ }
65
+ if (stream[i].typ === EnumToken.IdenTokenType) {
66
+ tokens.push(stream[i++]);
67
+ }
68
+ while (stream[i]?.typ === EnumToken.WhitespaceTokenType || stream[i]?.typ === EnumToken.CommentTokenType) {
69
+ tokens.push(stream[i++]);
70
+ }
71
+ if (i < stream.length &&
72
+ stream[i]?.typ !== EnumToken.StartParensTokenType &&
73
+ stream[i]?.typ !== EnumToken.ContainerFunctionTokenDefType) {
74
+ return {
75
+ success: false,
76
+ errors: [
77
+ {
78
+ action: "drop",
79
+ node: stream[i],
80
+ location: stream[i]?.loc ?? context.loc,
81
+ message: `expecting <container-condition> at ${(stream[i] ?? context)?.loc?.src}:${(stream[i] ?? context)?.loc?.sta.lin}:${(stream[i] ?? context)?.loc?.sta.col}`,
82
+ },
83
+ ],
84
+ };
85
+ }
86
+ if (stream[i]?.typ === EnumToken.IdenTokenType) {
87
+ const val = stream[i].val.toLowerCase();
88
+ if ("not" === val) {
89
+ tokens.push(stream[i]);
90
+ stack.push(Object.assign(stream[i], { typ: EnumToken.NotTokenType }));
91
+ i++;
92
+ }
93
+ else if ("and" === val || "or" === val) {
94
+ return {
95
+ success: false,
96
+ errors: [
97
+ {
98
+ action: "drop",
99
+ node: stream[i],
100
+ location: stream[i]?.loc,
101
+ message: `unexpected token at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
102
+ },
103
+ ],
104
+ };
105
+ }
106
+ else {
107
+ tokens.push(stream[i++]);
108
+ }
109
+ }
110
+ for (; i < stream.length; i++) {
111
+ tokens.push(stream[i]);
112
+ if (stream[i].typ === EnumToken.WhitespaceTokenType || stream[i].typ === EnumToken.CommentTokenType) {
113
+ continue;
114
+ }
115
+ if (expectAndOr) {
116
+ let valid = true;
117
+ if (stream[i].typ === EnumToken.IdenTokenType) {
118
+ const val = stream[i].val.toLowerCase();
119
+ valid = val === "and" || val === "or";
120
+ }
121
+ else {
122
+ valid = stream[i].typ !== EnumToken.CommaTokenType;
123
+ }
124
+ if (!valid) {
125
+ success = false;
126
+ errors.push({
127
+ action: "drop",
128
+ node: stream[i],
129
+ message: `expecting <and>, <or> or comma at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
130
+ });
131
+ break;
132
+ }
133
+ expectAndOr = false;
134
+ }
135
+ if (stream[i].typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[i].typ)) {
136
+ scopes.push((currentScope = new Set()));
137
+ stack.push(stream[i]);
138
+ continue;
139
+ }
140
+ switch (stream[i].typ) {
141
+ case EnumToken.LiteralTokenType:
142
+ if (stream[i].val === "<") {
143
+ stack.push(Object.assign(stream[i], { typ: EnumToken.LtTokenType }));
144
+ }
145
+ if (stream[i].val === ">") {
146
+ stack.push(Object.assign(stream[i], { typ: EnumToken.GtTokenType }));
147
+ }
148
+ break;
149
+ case EnumToken.ColonTokenType:
150
+ case EnumToken.LtTokenType:
151
+ case EnumToken.LteTokenType:
152
+ case EnumToken.GtTokenType:
153
+ case EnumToken.GteTokenType:
154
+ case EnumToken.DelimTokenType:
155
+ stack.push(stream[i]);
156
+ break;
157
+ case EnumToken.IdenTokenType:
158
+ {
159
+ const val = stream[i].val.toLowerCase();
160
+ if (val === "not") {
161
+ Object.assign(stream[i], {
162
+ typ: EnumToken.NotTokenType,
163
+ });
164
+ stack.push(stream[i]);
165
+ }
166
+ else if (val === "and" || val === "or") {
167
+ Object.assign(stream[i], {
168
+ typ: val === "and" ? EnumToken.AndTokenType : EnumToken.OrTokenType,
169
+ });
170
+ if (val === "or" && scopes.length <= 1) {
171
+ success = false;
172
+ errors.push({
173
+ action: "drop",
174
+ node: stream[i],
175
+ message: `<or> is not allowed outside of parentheses ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
176
+ });
177
+ break;
178
+ }
179
+ if (currentScope.has(val === "or" ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
180
+ success = false;
181
+ errors.push({
182
+ action: "drop",
183
+ node: stream[i],
184
+ message: `cannot mix <and> and <or> at the same level at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
185
+ });
186
+ break;
187
+ }
188
+ currentScope.add(stream[i].typ);
189
+ stack.push(stream[i]);
190
+ }
191
+ else if (scopes.length === 0) {
192
+ success = false;
193
+ errors.push({
194
+ action: "drop",
195
+ node: stream[i],
196
+ location: stream[i]?.loc,
197
+ message: `unexpected <ident> at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
198
+ });
199
+ return {
200
+ success,
201
+ errors,
202
+ };
203
+ }
204
+ }
205
+ break;
206
+ case EnumToken.EndParensTokenType:
207
+ // feature
208
+ if (mFLT.has(stack.at(-1)?.typ) || mFGT.has(stack.at(-1)?.typ)) {
209
+ // <mf-lt> | <mf-gt>
210
+ const index = tokens.indexOf(stack.at(-1));
211
+ const prevToken = stack[stack.length - 2];
212
+ if (mFLT.has(prevToken?.typ) || mFGT.has(prevToken?.typ)) {
213
+ if (stack[stack.length - 3]?.typ !== EnumToken.StartParensTokenType) {
214
+ success = false;
215
+ errors.push({
216
+ action: "drop",
217
+ node: stream[i],
218
+ message: `unmatched '(' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
219
+ });
220
+ break;
221
+ }
222
+ if (!mFLT.has(stack.at(-1)?.typ) && mFLT.has(prevToken?.typ)) {
223
+ success = false;
224
+ errors.push({
225
+ action: "drop",
226
+ node: stack.at(-1),
227
+ message: `expected <mf-lt> at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
228
+ });
229
+ break;
230
+ }
231
+ else if (!mFGT.has(stack.at(-1)?.typ) && mFGT.has(prevToken?.typ)) {
232
+ success = false;
233
+ errors.push({
234
+ action: "drop",
235
+ node: stream[i],
236
+ message: `expected <mf-gt> at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
237
+ });
238
+ break;
239
+ }
240
+ // <style-range>
241
+ // const index: number = tokens.indexOf(stack.at(-1)!);
242
+ // <mf-lt> | <mf-gt>
243
+ const index2 = tokens.indexOf(prevToken);
244
+ // '('
245
+ const index3 = tokens.indexOf(stack.at(-3));
246
+ const left = trimArray(tokens.slice(index3 + 1, index2));
247
+ const right = trimArray(tokens.slice(index + 1, tokens.length - 1));
248
+ const names = trimArray(tokens.slice(index2 + 1, index));
249
+ if (!isStyleRangeValue(left)) {
250
+ success = false;
251
+ errors.push({
252
+ action: "drop",
253
+ node: left[0],
254
+ message: `expected <style-feature-value> at ${left[0]?.loc?.src}:${left[0]?.loc?.sta.lin}:${left[0]?.loc?.sta.col}`,
255
+ });
256
+ break;
257
+ }
258
+ if (!isStyleRangeValue(right)) {
259
+ success = false;
260
+ errors.push({
261
+ action: "drop",
262
+ node: right[0],
263
+ message: `expected <style-feature-value> at ${right[0]?.loc?.src}:${right[0]?.loc?.sta.lin}:${right[0]?.loc?.sta.col}`,
264
+ });
265
+ break;
266
+ }
267
+ if (!isStyleRangeValue(names)) {
268
+ success = false;
269
+ errors.push({
270
+ action: "drop",
271
+ node: names[0],
272
+ message: `expected <style-feature-value> at ${names[0]?.loc?.src}:${names[0]?.loc?.sta.lin}:${names[0]?.loc?.sta.col}`,
273
+ });
274
+ break;
275
+ }
276
+ tokens.splice(index3 + 1, tokens.length - index3 - 2, Object.defineProperty({
277
+ typ: EnumToken.ContainerStyleRangeTokenType,
278
+ l: left,
279
+ op: names,
280
+ r: right,
281
+ }, "loc", {
282
+ ...definedPropertySettings,
283
+ value: { ...left[0].loc, end: right.at(-1).loc.end },
284
+ }));
285
+ // check <style()> or <scroll-state()>
286
+ stack.pop();
287
+ stack.pop();
288
+ }
289
+ else if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
290
+ success = false;
291
+ errors.push({
292
+ action: "drop",
293
+ node: stream[i],
294
+ location: stream[i]?.loc,
295
+ message: `expected '(' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
296
+ });
297
+ break;
298
+ }
299
+ }
300
+ if (mFGT.has(stack.at(-1)?.typ) ||
301
+ mFLT.has(stack.at(-1)?.typ) ||
302
+ stack.at(-1)?.typ === EnumToken.DelimTokenType ||
303
+ stack.at(-1)?.typ === EnumToken.ColonTokenType) {
304
+ const funcName = stack[stack.length - 2].val?.toLowerCase?.();
305
+ if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType &&
306
+ !(stack[stack.length - 2]?.typ === EnumToken.ContainerFunctionTokenDefType &&
307
+ ("style" === funcName || "scroll-state" === funcName))) {
308
+ success = false;
309
+ errors.push({
310
+ action: "drop",
311
+ node: stream[i],
312
+ location: stream[i]?.loc,
313
+ message: `unmatched2 ')' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
314
+ });
315
+ break;
316
+ }
317
+ const index2 = tokens.indexOf(stack.at(-1));
318
+ const index3 = tokens.indexOf(stack.at(-2));
319
+ let names = trimArray(tokens.slice(index3 + 1, index2));
320
+ let values = trimArray(tokens.slice(index2 + 1, tokens.length - 1));
321
+ if (stack.at(-1)?.typ !== EnumToken.ColonTokenType &&
322
+ stack.at(-1)?.typ !== EnumToken.DelimTokenType) {
323
+ names.filter((n) => n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType);
324
+ }
325
+ tokens.splice(index3 + 1, tokens.length - index3 - 2, Object.defineProperty({
326
+ typ: EnumToken.MediaQueryConditionTokenType,
327
+ l: names,
328
+ op: stack.pop(),
329
+ r: values,
330
+ }, "loc", {
331
+ ...definedPropertySettings,
332
+ value: { ...names[0].loc, end: values.at(-1).loc.end },
333
+ }));
334
+ // check <style()> or <scroll-state()>
335
+ }
336
+ if (tokensfuncDefMap.has(stack.at(-1)?.typ)) {
337
+ const index = tokens.indexOf(stack.at(-1));
338
+ Object.defineProperty(Object.assign(tokens[index], {
339
+ typ: tokensfuncDefMap.get(stack.at(-1)?.typ),
340
+ chi: trimArray(tokens.slice(index + 1, tokens.length - 1)),
341
+ }), "loc", {
342
+ ...definedPropertySettings,
343
+ value: { ...tokens[index].loc, end: stream[i].loc.end },
344
+ });
345
+ if (tokens[index].chi.every((t) => t.typ === EnumToken.WhitespaceTokenType || t.typ === EnumToken.CommentTokenType)) {
346
+ success = false;
347
+ errors.push({
348
+ action: "drop",
349
+ node: stream[i],
350
+ location: stream[i]?.loc,
351
+ message: `expecting '<${tokens[index].val}-query>' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
352
+ });
353
+ break;
354
+ }
355
+ tokens.length = index + 1;
356
+ if (EnumToken.ColorTokenType === tokens[index].typ) {
357
+ parseColor(tokens[index]);
358
+ }
359
+ stack.pop();
360
+ scopes.pop();
361
+ currentScope = scopes.at(-1);
362
+ }
363
+ else {
364
+ const index = tokens.indexOf(stack.at(-1));
365
+ tokens[index] = Object.defineProperty({
366
+ typ: EnumToken.ParensTokenType,
367
+ chi: tokens.slice(index + 1, tokens.length - 1),
368
+ }, "loc", {
369
+ ...definedPropertySettings,
370
+ value: { ...tokens[index].loc, end: stream[i].loc.end },
371
+ });
372
+ if (tokens[index].chi.every((t) => t.typ === EnumToken.WhitespaceTokenType || t.typ === EnumToken.CommentTokenType)) {
373
+ success = false;
374
+ errors.push({
375
+ action: "drop",
376
+ node: stream[i],
377
+ location: stream[i]?.loc,
378
+ message: `expecting '<query-in-parens>' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
379
+ });
380
+ break;
381
+ }
382
+ tokens.length = index + 1;
383
+ scopes.pop();
384
+ currentScope = scopes.at(-1);
385
+ stack.pop();
386
+ }
387
+ if (stack.at(-1)?.typ === EnumToken.NotTokenType) {
388
+ let j = tokens.indexOf(stack.at(-1));
389
+ let k = j;
390
+ while (j-- &&
391
+ (tokens[j]?.typ === EnumToken.WhitespaceTokenType ||
392
+ tokens[j]?.typ === EnumToken.CommentTokenType)) { }
393
+ if (j >= 0) {
394
+ if (tokens[j]?.typ !== EnumToken.StartParensTokenType) {
395
+ success = false;
396
+ errors.push({
397
+ action: "drop",
398
+ node: tokens[k],
399
+ location: tokens[k]?.loc,
400
+ message: `unexpected token 'not' at ${tokens[k]?.loc?.src}:${tokens[k]?.loc?.sta.lin}:${tokens[k]?.loc?.sta.col}`,
401
+ });
402
+ break;
403
+ }
404
+ }
405
+ const index = tokens.indexOf(stack.at(-1));
406
+ const slice = trimArray(tokens.slice(index + 1));
407
+ tokens[index] = Object.defineProperty({
408
+ typ: EnumToken.MediaQueryUnaryFeatureTokenType,
409
+ l: stack.pop(),
410
+ r: slice,
411
+ }, "loc", {
412
+ ...definedPropertySettings,
413
+ value: { ...tokens[index].loc, end: slice.at(-1).loc.end },
414
+ });
415
+ tokens.length = index + 1;
416
+ }
417
+ if (stack.at(-1)?.typ === EnumToken.AndTokenType ||
418
+ stack.at(-1)?.typ === EnumToken.OrTokenType) {
419
+ const index = tokens.indexOf(stack.at(-1));
420
+ let l = index - 1;
421
+ while (l > 0 &&
422
+ (tokens[l].typ === EnumToken.WhitespaceTokenType ||
423
+ tokens[l].typ === EnumToken.CommentTokenType)) {
424
+ l--;
425
+ }
426
+ const left = trimArray(tokens.slice(l, index));
427
+ const right = trimArray(tokens.slice(index + 1));
428
+ tokens[l] = Object.defineProperty({
429
+ typ: EnumToken.MediaQueryConditionTokenType,
430
+ op: stack.pop(),
431
+ l: left,
432
+ r: right,
433
+ }, "loc", {
434
+ ...definedPropertySettings,
435
+ value: { ...left[0].loc, end: right.at(-1).loc.end },
436
+ });
437
+ tokens.length = l + 1;
438
+ expectAndOr = true;
439
+ }
440
+ break;
441
+ default:
442
+ if (tokensfuncDefMap.has(stream[i]?.typ)) {
443
+ stack.push(stream[i]);
444
+ scopes.push((currentScope = new Set()));
445
+ }
446
+ break;
447
+ }
448
+ if (!success) {
449
+ break;
450
+ }
451
+ }
452
+ if (success && stack.length > 0) {
453
+ success = false;
454
+ errors.push({
455
+ action: "drop",
456
+ node: stack.at(-1),
457
+ message: `unmatched token '${EnumToken[stack.at(-1)?.typ]}' at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
458
+ });
459
+ }
460
+ if (!success) {
461
+ return {
462
+ success,
463
+ errors,
464
+ };
465
+ }
466
+ stream.length = 0;
467
+ stream.push(...trimArray(tokens));
468
+ }
469
+ }
470
+ stream.length = 0;
471
+ stream.push(...parts
472
+ .filter((p) => p.length > 0 && p[0].typ !== EnumToken.InvalidMediaQueryTokenType)
473
+ .reduce((acc, b) => {
474
+ if (acc.length > 0) {
475
+ acc.push({ typ: EnumToken.CommaTokenType });
476
+ }
477
+ acc.push(...b);
478
+ return acc;
479
+ }, []));
480
+ return {
481
+ success: true,
482
+ errors,
483
+ };
484
+ }
485
+
486
+ export { parseAtRuleContainerQueryList };
@@ -0,0 +1,5 @@
1
+ import type { ParserOptions, Token, AstAtRule, AtRuleToken } from "../../../@types/index.d.ts";
2
+ export declare function parseAtRuleFontFeatureValues(stream: Token[], context: AstAtRule | AtRuleToken, options?: ParserOptions): {
3
+ success: boolean;
4
+ errors: import("../../../@types/index.d.ts").ErrorDescription[];
5
+ };
@@ -0,0 +1,13 @@
1
+ import { getSyntaxRule } from '../../validation/config.js';
2
+ import { trimArray, matchAllSyntax, createValidationContext } from '../../validation/match.js';
3
+ import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
4
+
5
+ function parseAtRuleFontFeatureValues(stream, context, options = {}) {
6
+ const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + context.nam);
7
+ const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
8
+ trimArray(stream);
9
+ const { success, errors} = matchAllSyntax(syntax, createValidationContext(stream), options);
10
+ return { success, errors };
11
+ }
12
+
13
+ export { parseAtRuleFontFeatureValues };
@@ -0,0 +1,5 @@
1
+ import type { AtRuleToken, ErrorDescription, ParserOptions, Token, ValidationOptions } from "../../../@types/index.d.ts";
2
+ export declare function matchGenericSyntax(atRule: AtRuleToken, stream: Token[], options: ParserOptions | ValidationOptions): {
3
+ success: boolean;
4
+ errors: ErrorDescription[];
5
+ };
@@ -0,0 +1,118 @@
1
+ import { EnumToken } from '../../ast/types.js';
2
+ import { tokensfuncDefMap } from '../../syntax/constants.js';
3
+ import { equalsIgnoreCase } from './text.js';
4
+
5
+ function matchGenericSyntax(atRule, stream, options) {
6
+ const stack = [];
7
+ let i = 0;
8
+ let success = true;
9
+ let expectAndOr = false;
10
+ let expectComma = false;
11
+ const errors = [];
12
+ const scopes = [new Set()];
13
+ for (; i < stream.length; i++) {
14
+ const token = stream[i];
15
+ if (token.typ === EnumToken.WhitespaceTokenType || token.typ === EnumToken.CommentTokenType) {
16
+ continue;
17
+ }
18
+ if (token.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(token.typ)) {
19
+ stack.push(token);
20
+ scopes.push(new Set());
21
+ expectAndOr = false;
22
+ continue;
23
+ }
24
+ if (token.typ === EnumToken.EndParensTokenType) {
25
+ if (stack.length === 0 ||
26
+ (stack.at(-1)?.typ !== EnumToken.ParensTokenType && !tokensfuncDefMap.has(stack.at(-1)?.typ))) {
27
+ errors.push({
28
+ action: "drop",
29
+ message: `unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
30
+ node: token,
31
+ location: token.loc,
32
+ });
33
+ success = false;
34
+ break;
35
+ }
36
+ stack.pop();
37
+ scopes.pop();
38
+ if (scopes.length === 0) {
39
+ return {
40
+ success: false,
41
+ errors: [
42
+ {
43
+ action: "drop",
44
+ node: token,
45
+ message: `Unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
46
+ location: token.loc,
47
+ },
48
+ ],
49
+ };
50
+ }
51
+ continue;
52
+ }
53
+ if (token.typ === EnumToken.IdenTokenType && equalsIgnoreCase("and", token.val)) {
54
+ if (!expectAndOr || scopes.at(-1)?.has(EnumToken.OrTokenType)) {
55
+ errors.push({
56
+ action: "drop",
57
+ message: `unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
58
+ node: token,
59
+ location: token.loc,
60
+ });
61
+ success = false;
62
+ break;
63
+ }
64
+ Object.assign(token, { typ: EnumToken.AndTokenType });
65
+ scopes.at(-1).add(EnumToken.AndTokenType);
66
+ expectComma = false;
67
+ continue;
68
+ }
69
+ if (token.typ === EnumToken.IdenTokenType && equalsIgnoreCase("or", token.val)) {
70
+ if (!expectAndOr || scopes.at(-1)?.has(EnumToken.AndTokenType)) {
71
+ errors.push({
72
+ action: "drop",
73
+ message: `unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
74
+ node: token,
75
+ location: token.loc,
76
+ });
77
+ success = false;
78
+ break;
79
+ }
80
+ expectComma = false;
81
+ Object.assign(token, { typ: EnumToken.OrTokenType });
82
+ scopes.at(-1).add(EnumToken.OrTokenType);
83
+ continue;
84
+ }
85
+ if (token.typ === EnumToken.CommaTokenType) {
86
+ if (!expectComma) {
87
+ errors.push({
88
+ action: "drop",
89
+ message: `unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
90
+ node: token,
91
+ location: token.loc,
92
+ });
93
+ success = false;
94
+ break;
95
+ }
96
+ stack.push(token);
97
+ expectComma = false;
98
+ continue;
99
+ }
100
+ expectAndOr = true;
101
+ expectComma = true;
102
+ if (stack.length > 0 && stack.at(-1)?.typ === EnumToken.CommaTokenType) {
103
+ stack.pop();
104
+ }
105
+ }
106
+ if (stack.length > 0) {
107
+ errors.push({
108
+ action: "drop",
109
+ message: `unexpected token ${EnumToken[stack.at(-1)?.typ]} at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
110
+ node: stack.at(-1),
111
+ location: stack.at(-1)?.loc,
112
+ });
113
+ success = false;
114
+ }
115
+ return { success, errors };
116
+ }
117
+
118
+ export { matchGenericSyntax };
@@ -0,0 +1,5 @@
1
+ import type { AstAtRule, AstRule, AstStyleSheet, AtRuleToken, ErrorDescription, ParserOptions, Token } from "../../../@types/index.d.ts";
2
+ export declare function matchAtRuleImportSyntax(atRule: AtRuleToken, stream: Token[], context: AstRule | AstAtRule | AstStyleSheet, options: ParserOptions): {
3
+ success: boolean;
4
+ errors: ErrorDescription[];
5
+ };