@tbela99/css-parser 1.4.3 → 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 (166) hide show
  1. package/CHANGELOG.md +192 -2
  2. package/README.md +69 -1120
  3. package/dist/config.json.js +43 -2
  4. package/dist/index-umd-web.js +17226 -15037
  5. package/dist/index.cjs +16889 -14705
  6. package/dist/index.d.ts +1804 -1684
  7. package/dist/lib/ast/clone.js +4 -3
  8. package/dist/lib/ast/expand.js +2 -2
  9. package/dist/lib/ast/features/calc.js +59 -54
  10. package/dist/lib/ast/features/if.js +22 -16
  11. package/dist/lib/ast/features/inlinecssvariables.js +2 -2
  12. package/dist/lib/ast/features/prefix.js +343 -6
  13. package/dist/lib/ast/features/transform.js +7 -4
  14. package/dist/lib/ast/find.js +5 -5
  15. package/dist/lib/ast/math/expression.js +12 -8
  16. package/dist/lib/ast/minify.js +28 -33
  17. package/dist/lib/ast/transform/minify.js +135 -131
  18. package/dist/lib/ast/transform/utils.js +3 -2
  19. package/dist/lib/ast/types.js +69 -8
  20. package/dist/lib/ast/walk.js +4 -5
  21. package/dist/lib/fs/resolve.js +71 -57
  22. package/dist/lib/parser/declaration/list.js +92 -3
  23. package/dist/lib/parser/declaration/map.js +5 -5
  24. package/dist/lib/parser/parse.js +528 -466
  25. package/dist/lib/parser/tokenize.js +110 -4
  26. package/dist/lib/parser/utils/angle.js +29 -0
  27. package/dist/lib/parser/utils/at-rule-container.js +2 -2
  28. package/dist/lib/parser/utils/at-rule-font-feature-values.js +2 -2
  29. package/dist/lib/parser/utils/at-rule-generic.js +1 -1
  30. package/dist/lib/parser/utils/at-rule-media.js +2 -2
  31. package/dist/lib/parser/utils/at-rule-support.js +73 -8
  32. package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
  33. package/dist/lib/parser/utils/at-rule.js +2 -8
  34. package/dist/lib/parser/utils/declaration.js +179 -76
  35. package/dist/lib/parser/utils/selector.js +53 -11
  36. package/dist/lib/parser/utils/token.js +13 -11
  37. package/dist/lib/renderer/render.js +501 -59
  38. package/dist/lib/syntax/color/alpha.js +64 -0
  39. package/dist/lib/syntax/color/cmyk.js +2 -2
  40. package/dist/lib/syntax/color/color-mix.js +283 -220
  41. package/dist/lib/syntax/color/color.js +37 -28
  42. package/dist/lib/syntax/color/hex.js +2 -2
  43. package/dist/lib/syntax/color/hsl.js +3 -3
  44. package/dist/lib/syntax/color/hwb.js +7 -7
  45. package/dist/lib/syntax/color/lab.js +5 -5
  46. package/dist/lib/syntax/color/lch.js +4 -4
  47. package/dist/lib/syntax/color/oklab.js +3 -3
  48. package/dist/lib/syntax/color/oklch.js +3 -3
  49. package/dist/lib/syntax/color/relativecolor.js +97 -12
  50. package/dist/lib/syntax/color/srgb.js +5 -5
  51. package/dist/lib/syntax/color/utils/color-type.js +18 -0
  52. package/dist/lib/syntax/color/utils/colorspace.js +46 -0
  53. package/dist/lib/syntax/color/utils/components.js +7 -3
  54. package/dist/lib/syntax/color/utils/distance.js +21 -4
  55. package/dist/lib/syntax/color/utils/make-color.js +56 -0
  56. package/dist/lib/syntax/color/xyz.js +2 -2
  57. package/dist/lib/syntax/constants.js +29 -1
  58. package/dist/lib/syntax/syntax.js +307 -39
  59. package/dist/lib/validation/config.js +2 -2
  60. package/dist/lib/validation/config.json.js +32 -17
  61. package/dist/lib/validation/match.js +239 -104
  62. package/dist/lib/validation/parser/parse.js +0 -1
  63. package/dist/lib/validation/parser/typedef.js +6 -0
  64. package/dist/node.js +64 -22
  65. package/dist/web.js +65 -18
  66. package/package.json +26 -15
  67. package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
  68. package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
  69. package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
  70. package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
  71. package/.repl_history +0 -4
  72. package/badges/coverage.svg +0 -20
  73. package/deno.lock +0 -2861
  74. package/dist/lib/ast/clone.d.ts +0 -10
  75. package/dist/lib/ast/expand.d.ts +0 -14
  76. package/dist/lib/ast/features/calc.d.ts +0 -10
  77. package/dist/lib/ast/features/if.d.ts +0 -10
  78. package/dist/lib/ast/features/index.d.ts +0 -6
  79. package/dist/lib/ast/features/inlinecssvariables.d.ts +0 -15
  80. package/dist/lib/ast/features/prefix.d.ts +0 -8
  81. package/dist/lib/ast/features/shorthand.d.ts +0 -12
  82. package/dist/lib/ast/features/transform.d.ts +0 -10
  83. package/dist/lib/ast/features/type.d.ts +0 -15
  84. package/dist/lib/ast/find.d.ts +0 -165
  85. package/dist/lib/ast/math/expression.d.ts +0 -18
  86. package/dist/lib/ast/math/math.d.ts +0 -6
  87. package/dist/lib/ast/minify.d.ts +0 -19
  88. package/dist/lib/ast/transform/compute.d.ts +0 -8
  89. package/dist/lib/ast/transform/matrix.d.ts +0 -22
  90. package/dist/lib/ast/transform/minify.d.ts +0 -5
  91. package/dist/lib/ast/transform/perspective.d.ts +0 -3
  92. package/dist/lib/ast/transform/rotate.d.ts +0 -12
  93. package/dist/lib/ast/transform/scale.d.ts +0 -6
  94. package/dist/lib/ast/transform/skew.d.ts +0 -4
  95. package/dist/lib/ast/transform/translate.d.ts +0 -6
  96. package/dist/lib/ast/transform/utils.d.ts +0 -9
  97. package/dist/lib/ast/types.d.ts +0 -903
  98. package/dist/lib/ast/walk.d.ts +0 -162
  99. package/dist/lib/fs/resolve.d.ts +0 -20
  100. package/dist/lib/parser/declaration/list.d.ts +0 -16
  101. package/dist/lib/parser/declaration/map.d.ts +0 -15
  102. package/dist/lib/parser/declaration/set.d.ts +0 -9
  103. package/dist/lib/parser/node.d.ts +0 -7
  104. package/dist/lib/parser/parse.d.ts +0 -107
  105. package/dist/lib/parser/tokenize.d.ts +0 -57
  106. package/dist/lib/parser/utils/at-rule-container.d.ts +0 -5
  107. package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +0 -5
  108. package/dist/lib/parser/utils/at-rule-generic.d.ts +0 -5
  109. package/dist/lib/parser/utils/at-rule-import.d.ts +0 -5
  110. package/dist/lib/parser/utils/at-rule-media.d.ts +0 -5
  111. package/dist/lib/parser/utils/at-rule-page.d.ts +0 -5
  112. package/dist/lib/parser/utils/at-rule-page.js +0 -28
  113. package/dist/lib/parser/utils/at-rule-support.d.ts +0 -5
  114. package/dist/lib/parser/utils/at-rule-token.d.ts +0 -1
  115. package/dist/lib/parser/utils/at-rule-when-else.d.ts +0 -5
  116. package/dist/lib/parser/utils/at-rule.d.ts +0 -13
  117. package/dist/lib/parser/utils/cache.d.ts +0 -6
  118. package/dist/lib/parser/utils/config.d.ts +0 -2
  119. package/dist/lib/parser/utils/declaration-list.d.ts +0 -5
  120. package/dist/lib/parser/utils/declaration.d.ts +0 -18
  121. package/dist/lib/parser/utils/eq.d.ts +0 -1
  122. package/dist/lib/parser/utils/hash.d.ts +0 -21
  123. package/dist/lib/parser/utils/selector.d.ts +0 -5
  124. package/dist/lib/parser/utils/text.d.ts +0 -3
  125. package/dist/lib/parser/utils/token.d.ts +0 -14
  126. package/dist/lib/parser/utils/type.d.ts +0 -2
  127. package/dist/lib/renderer/render.d.ts +0 -28
  128. package/dist/lib/renderer/sourcemap/lib/encode.d.ts +0 -1
  129. package/dist/lib/renderer/sourcemap/sourcemap.d.ts +0 -26
  130. package/dist/lib/syntax/color/a98rgb.d.ts +0 -2
  131. package/dist/lib/syntax/color/cmyk.d.ts +0 -10
  132. package/dist/lib/syntax/color/color-mix.d.ts +0 -2
  133. package/dist/lib/syntax/color/color.d.ts +0 -42
  134. package/dist/lib/syntax/color/hex.d.ts +0 -16
  135. package/dist/lib/syntax/color/hsl.d.ts +0 -20
  136. package/dist/lib/syntax/color/hsv.d.ts +0 -2
  137. package/dist/lib/syntax/color/hwb.d.ts +0 -21
  138. package/dist/lib/syntax/color/lab.d.ts +0 -25
  139. package/dist/lib/syntax/color/lch.d.ts +0 -23
  140. package/dist/lib/syntax/color/oklab.d.ts +0 -22
  141. package/dist/lib/syntax/color/oklch.d.ts +0 -20
  142. package/dist/lib/syntax/color/p3.d.ts +0 -6
  143. package/dist/lib/syntax/color/prophotorgb.d.ts +0 -2
  144. package/dist/lib/syntax/color/rec2020.d.ts +0 -2
  145. package/dist/lib/syntax/color/relativecolor.d.ts +0 -13
  146. package/dist/lib/syntax/color/rgb.d.ts +0 -20
  147. package/dist/lib/syntax/color/srgb.d.ts +0 -23
  148. package/dist/lib/syntax/color/utils/components.d.ts +0 -2
  149. package/dist/lib/syntax/color/utils/distance.d.ts +0 -18
  150. package/dist/lib/syntax/color/utils/matrix.d.ts +0 -6
  151. package/dist/lib/syntax/color/xyz.d.ts +0 -5
  152. package/dist/lib/syntax/color/xyzd50.d.ts +0 -4
  153. package/dist/lib/syntax/constants.d.ts +0 -67
  154. package/dist/lib/syntax/syntax.d.ts +0 -38
  155. package/dist/lib/validation/config.d.ts +0 -14
  156. package/dist/lib/validation/json.d.ts +0 -2
  157. package/dist/lib/validation/match.d.ts +0 -38
  158. package/dist/lib/validation/parser/parse.d.ts +0 -8
  159. package/dist/lib/validation/parser/typedef.d.ts +0 -95
  160. package/dist/lib/validation/utils/list.d.ts +0 -4
  161. package/dist/lib/validation/utils/whitespace.d.ts +0 -2
  162. package/dist/node.d.ts +0 -207
  163. package/dist/web.d.ts +0 -169
  164. package/playground/index.html +0 -1328
  165. package/playground/sw.js +0 -55
  166. package/playground/tree.js +0 -176
@@ -1,6 +1,7 @@
1
1
  import { EnumToken, ColorType } from '../ast/types.js';
2
2
  import { definedPropertySettings, wildCardFuncs, whenElseFunc, transformFunctions, mathFuncs, colorsFunc, timingFunc, supportFunc, generalEnclosedFunc, timelineFunc, imageFunc, gridTemplateFunc, urlFunc, containerFunc } from '../syntax/constants.js';
3
- import { isDigit, isPseudo, isIdent, isNumber, isWhiteSpace, isNewLine, isHexColor, isHash, isPercentage, parseDimension } from '../syntax/syntax.js';
3
+ import { isDigit, isPseudo, isIdent, isWhiteSpace, isNumber, isNewLine, isHexColor, isHash, isPercentage, parseDimension } from '../syntax/syntax.js';
4
+ import { equalsIgnoreCase } from './utils/text.js';
4
5
 
5
6
  const SymbolsMapTokens = {
6
7
  "+": EnumToken.Plus,
@@ -140,6 +141,10 @@ function consumeString(quoteStr, buffer, parseInfo) {
140
141
  buffer += quoteStr;
141
142
  while ((value = parseInfo.stream.charAt(parseInfo.currentPosition.ind - parseInfo.offset + 1))) {
142
143
  if (value == "\\") {
144
+ if ("\\" == parseInfo.stream.charAt(parseInfo.currentPosition.ind - parseInfo.offset + 2)) {
145
+ buffer += next(parseInfo, 2);
146
+ continue;
147
+ }
143
148
  const sequence = peek(parseInfo, 6);
144
149
  let escapeSequence = "";
145
150
  let codepoint;
@@ -205,6 +210,51 @@ function getTokenType(val, hint) {
205
210
  let token = null;
206
211
  let dimension;
207
212
  if (hint != null) {
213
+ let searchArray = null;
214
+ switch (hint) {
215
+ case EnumToken.TransformFunctionTokenDefType:
216
+ searchArray = transformFunctions;
217
+ break;
218
+ case EnumToken.ColorFunctionTokenDefType:
219
+ searchArray = colorsFunc;
220
+ break;
221
+ case EnumToken.ContainerFunctionTokenDefType:
222
+ searchArray = containerFunc;
223
+ break;
224
+ case EnumToken.UrlFunctionTokenDefType:
225
+ searchArray = urlFunc;
226
+ break;
227
+ case EnumToken.GridTemplateFuncTokenDefType:
228
+ searchArray = gridTemplateFunc;
229
+ break;
230
+ case EnumToken.ImageFunctionTokenDefType:
231
+ searchArray = imageFunc;
232
+ break;
233
+ case EnumToken.TimelineFunctionTokenDefType:
234
+ searchArray = timelineFunc;
235
+ break;
236
+ case EnumToken.GeneralEnclosedFunctionTokenDefType:
237
+ searchArray = generalEnclosedFunc;
238
+ break;
239
+ case EnumToken.SupportsFunctionTokenDefType:
240
+ searchArray = supportFunc;
241
+ break;
242
+ case EnumToken.TimingFunctionTokenDefType:
243
+ searchArray = timingFunc;
244
+ break;
245
+ case EnumToken.MathFunctionTokenDefType:
246
+ searchArray = mathFuncs;
247
+ break;
248
+ case EnumToken.WhenElseFunctionTokenDefType:
249
+ searchArray = whenElseFunc;
250
+ break;
251
+ case EnumToken.WildCardFunctionTokenDefType:
252
+ searchArray = wildCardFuncs;
253
+ break;
254
+ }
255
+ if (searchArray != null) {
256
+ val = searchArray.find((v) => equalsIgnoreCase(v, val));
257
+ }
208
258
  token = hintsEnum.has(hint) ? { typ: hint } : { typ: hint, val };
209
259
  }
210
260
  else {
@@ -334,7 +384,7 @@ function next(parseInfo, count = 1) {
334
384
  return char;
335
385
  }
336
386
  /**
337
- * tokenize css string
387
+ * Tokenize css string
338
388
  * @param parseInfo
339
389
  * @param yieldEOFToken
340
390
  */
@@ -408,10 +458,66 @@ function tokenize(parseInfo, yieldEOFToken = true) {
408
458
  break;
409
459
  }
410
460
  else if (isIdent(buffer)) {
411
- result.push(yieldResult(buffer, parseInfo, buffer.startsWith("--")
461
+ const hint = buffer.startsWith("--")
412
462
  ? EnumToken.CustomFunctionTokenDefType
413
- : (SymbolsMapTokens[buffer.toLowerCase() + "("] ?? EnumToken.FunctionTokenDefType)));
463
+ : (SymbolsMapTokens[buffer.toLowerCase() + "("] ?? EnumToken.FunctionTokenDefType);
464
+ result.push(yieldResult(buffer, parseInfo, hint));
414
465
  buffer = "";
466
+ if (hint === EnumToken.UrlFunctionTokenDefType) {
467
+ value = peek(parseInfo);
468
+ // consume an <url>
469
+ while (isWhiteSpace((charCode = value.charCodeAt(0)))) {
470
+ buffer += next(parseInfo);
471
+ value = peek(parseInfo);
472
+ charCode = value.charCodeAt(0);
473
+ if (value === "/" && match(parseInfo, "/*")) {
474
+ if (buffer.length > 0) {
475
+ result.push(yieldResult(buffer, parseInfo));
476
+ buffer = "";
477
+ }
478
+ buffer += next(parseInfo, 2);
479
+ while ((value = next(parseInfo))) {
480
+ if (value == "*") {
481
+ buffer += value;
482
+ if (match(parseInfo, "/")) {
483
+ result.push(yieldResult(buffer + next(parseInfo), parseInfo, EnumToken.CommentTokenType));
484
+ buffer = "";
485
+ break;
486
+ }
487
+ }
488
+ else {
489
+ buffer += value;
490
+ }
491
+ }
492
+ if (buffer.length > 0) {
493
+ result.push(yieldResult(buffer, parseInfo, EnumToken.BadCommentTokenType));
494
+ buffer = "";
495
+ }
496
+ value = peek(parseInfo);
497
+ charCode = value.charCodeAt(0);
498
+ }
499
+ }
500
+ if (buffer.length > 0) {
501
+ result.push(yieldResult(buffer, parseInfo, EnumToken.WhitespaceTokenType));
502
+ buffer = "";
503
+ }
504
+ if (value === ")" || value === '"' || value === "'") {
505
+ break;
506
+ }
507
+ do {
508
+ buffer += next(parseInfo);
509
+ value = peek(parseInfo);
510
+ charCode = value.charCodeAt(0);
511
+ } while (value !== ")" &&
512
+ !isWhiteSpace(charCode) &&
513
+ !(value === "/" && match(parseInfo, "/*")));
514
+ if (buffer.length > 0) {
515
+ result.push(yieldResult(buffer, parseInfo, peek(parseInfo) === ""
516
+ ? EnumToken.BadUrlTokenType
517
+ : EnumToken.UrlTokenTokenType));
518
+ buffer = "";
519
+ }
520
+ }
415
521
  break;
416
522
  }
417
523
  }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * convert angle to degrees
3
+ * @param angle
4
+ * @returns
5
+ */
6
+ function toDegrees(angle) {
7
+ switch (angle.unit) {
8
+ // case "deg":
9
+ // return angle;
10
+ case "rad":
11
+ // @ts-expect-error
12
+ angle.val *= 180 / Math.PI;
13
+ angle.unit = "deg";
14
+ return angle;
15
+ case "grad":
16
+ // @ts-expect-error
17
+ angle.val *= 0.9;
18
+ angle.unit = "deg";
19
+ return angle;
20
+ case "turn":
21
+ // @ts-expect-error
22
+ angle.val *= 360;
23
+ angle.unit = "deg";
24
+ return angle;
25
+ }
26
+ return angle;
27
+ }
28
+
29
+ export { toDegrees };
@@ -1,6 +1,6 @@
1
1
  import { EnumToken } from '../../ast/types.js';
2
2
  import { tokensfuncDefMap, mFLT, mFGT, definedPropertySettings } from '../../syntax/constants.js';
3
- import { matchAllSyntax, createValidationContext, trimArray, isStyleRangeValue } from '../../validation/match.js';
3
+ import { matchAllSyntaxes, createValidationContext, trimArray, isStyleRangeValue } from '../../validation/match.js';
4
4
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
5
5
  import { getSyntaxRule } from '../../validation/config.js';
6
6
  import { parseColor } from '../../syntax/syntax.js';
@@ -27,7 +27,7 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
27
27
  }
28
28
  return acc;
29
29
  }, [[]]);
30
- const result = matchAllSyntax(syntax, createValidationContext(stream), options);
30
+ const result = matchAllSyntaxes(syntax, createValidationContext(stream), options);
31
31
  if (!result.success) {
32
32
  errors.push(...result.errors);
33
33
  return {
@@ -1,12 +1,12 @@
1
1
  import { getSyntaxRule } from '../../validation/config.js';
2
- import { trimArray, matchAllSyntax, createValidationContext } from '../../validation/match.js';
2
+ import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
3
3
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
4
4
 
5
5
  function parseAtRuleFontFeatureValues(stream, context, options = {}) {
6
6
  const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + context.nam);
7
7
  const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
8
8
  trimArray(stream);
9
- const { success, errors} = matchAllSyntax(syntax, createValidationContext(stream), options);
9
+ const { success, errors} = matchAllSyntaxes(syntax, createValidationContext(stream), options);
10
10
  return { success, errors };
11
11
  }
12
12
 
@@ -2,7 +2,7 @@ import { EnumToken } from '../../ast/types.js';
2
2
  import { tokensfuncDefMap } from '../../syntax/constants.js';
3
3
  import { equalsIgnoreCase } from './text.js';
4
4
 
5
- function matchGenericSyntax(atRule, stream, options) {
5
+ function matchGenericSyntax(stream) {
6
6
  const stack = [];
7
7
  let i = 0;
8
8
  let success = true;
@@ -2,7 +2,7 @@ import { EnumToken } from '../../ast/types.js';
2
2
  import { evaluate } from '../../ast/math/expression.js';
3
3
  import { gcd } from '../../ast/math/math.js';
4
4
  import { tokensfuncDefMap, mediaTypes, definedPropertySettings, mFLT, mFGT } from '../../syntax/constants.js';
5
- import { trimArray, matchAllSyntax, createValidationContext, getMFInfo, isMFValue, isMFName } from '../../validation/match.js';
5
+ import { trimArray, matchAllSyntaxes, createValidationContext, getMFInfo, isMFValue, isMFName } from '../../validation/match.js';
6
6
  import { ValidationSyntaxGroupEnum, MediaFeatureType } from '../../validation/parser/typedef.js';
7
7
  import { getParsedSyntax } from '../../validation/config.js';
8
8
 
@@ -222,7 +222,7 @@ function parseMediaqueryList(stream, options) {
222
222
  value: { ...tokens[index].loc, end: stream[i].loc.end },
223
223
  });
224
224
  tokens.length = index + 1;
225
- const result = matchAllSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
225
+ const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
226
226
  stack.pop();
227
227
  scopes.pop();
228
228
  currentScope = scopes.at(-1);
@@ -1,11 +1,12 @@
1
1
  import { EnumToken, ValidationLevel } from '../../ast/types.js';
2
- import { renderToken } from '../../renderer/render.js';
2
+ import { renderValue } from '../../renderer/render.js';
3
3
  import { tokensfuncDefMap, trimTokenSpace, tokensfuncSet, definedPropertySettings } from '../../syntax/constants.js';
4
- import { getParsedSyntax } from '../../validation/config.js';
5
- import { matchAllSyntax, createValidationContext, trimArray } from '../../validation/match.js';
4
+ import { getSyntaxConfig, getParsedSyntax } from '../../validation/config.js';
5
+ import { matchAllSyntaxes, createValidationContext, trimArray } from '../../validation/match.js';
6
6
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
7
7
  import { parseDeclaration } from './declaration.js';
8
8
  import { equalsIgnoreCase } from './text.js';
9
+ import { pseudoElements } from '../../syntax/syntax.js';
9
10
 
10
11
  function parseAtRuleSupportSyntax(stream, context, options = {}) {
11
12
  const tokens = [];
@@ -14,6 +15,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
14
15
  let success = true;
15
16
  let expectAndOr = false;
16
17
  let scope = new Set();
18
+ let val;
17
19
  const errors = [];
18
20
  const scopes = [scope];
19
21
  const trimWhiteSpace = new Set([
@@ -33,7 +35,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
33
35
  stream[i]?.typ !== EnumToken.StartParensTokenType &&
34
36
  !(stream[i]?.typ === EnumToken.IdenTokenType && "not" === stream[i]?.val.toLowerCase())) {
35
37
  return {
36
- success,
38
+ success: false,
37
39
  errors: [
38
40
  {
39
41
  action: "drop",
@@ -45,6 +47,55 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
45
47
  }
46
48
  for (; i < stream.length; i++) {
47
49
  tokens.push(stream[i]);
50
+ if (stream[i].typ == EnumToken.ColonTokenType) {
51
+ if (stream[i + 1]?.typ == EnumToken.IdenTokenType) {
52
+ Object.assign(stream[i], {
53
+ typ: EnumToken.PseudoElementTokenType,
54
+ val: ":" + stream[i + 1].val,
55
+ });
56
+ stream[i].loc.end = stream[i + 1].loc.end;
57
+ stream.splice(i + 1, 1);
58
+ continue;
59
+ }
60
+ if (stream[i + 1]?.typ == EnumToken.FunctionTokenDefType) {
61
+ val = ":" + stream[i + 1].val;
62
+ Object.assign(stream[i], {
63
+ typ: val + "()" in getSyntaxConfig().selectors
64
+ ? EnumToken.PseudoClassFunctionTokenDefType
65
+ : stream[i + 1].typ,
66
+ val,
67
+ });
68
+ stack.push(stream[i]);
69
+ stream[i].loc.end = stream[i + 1].loc.end;
70
+ stream.splice(i + 1, 1);
71
+ continue;
72
+ }
73
+ }
74
+ if (stream[i].typ == EnumToken.DoubleColonTokenType) {
75
+ val = ":" + stream[i + 1].val;
76
+ if (stream[i + 1]?.typ == EnumToken.IdenTokenType) {
77
+ Object.assign(stream[i], {
78
+ typ: EnumToken.PseudoClassTokenType,
79
+ val: (pseudoElements.includes(val) ? "" : ":") + val,
80
+ });
81
+ stream[i].loc.end = stream[i + 1].loc.end;
82
+ stream.splice(i + 1, 1);
83
+ continue;
84
+ }
85
+ if (stream[i + 1]?.typ == EnumToken.FunctionTokenDefType) {
86
+ val = "::" + stream[i + 1].val;
87
+ Object.assign(stream[i], {
88
+ typ: val + "()" in getSyntaxConfig().selectors
89
+ ? EnumToken.PseudoClassFunctionTokenDefType
90
+ : EnumToken.FunctionTokenDefType,
91
+ val,
92
+ });
93
+ stack.push(stream[i]);
94
+ stream[i].loc.end = stream[i + 1].loc.end;
95
+ stream.splice(i + 1, 1);
96
+ continue;
97
+ }
98
+ }
48
99
  if (trimWhiteSpace.has(stream[i].typ)) {
49
100
  if (tokens.at(-2)?.typ === EnumToken.WhitespaceTokenType) {
50
101
  tokens.splice(tokens.length - 2, 1);
@@ -114,7 +165,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
114
165
  tokens.splice(index + 1, 1);
115
166
  stack.pop();
116
167
  const index2 = tokens.indexOf(stack[stack.length - 1]);
117
- const result = matchAllSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index2].val + "()")[0]?.chi, createValidationContext(tokens.slice(index2 + 1, -1)), options);
168
+ const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index2].val + "()")[0]?.chi, createValidationContext(tokens.slice(index2 + 1, -1)), options);
118
169
  if (!result.success) {
119
170
  return {
120
171
  success: false,
@@ -209,13 +260,27 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
209
260
  ...definedPropertySettings,
210
261
  value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
211
262
  });
263
+ if (tokens[index].typ === EnumToken.PseudoClassFuncTokenType) {
264
+ // not a declaration
265
+ const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
266
+ if (!result.success) {
267
+ return {
268
+ success: false,
269
+ errors: result.errors,
270
+ };
271
+ }
272
+ stack.pop();
273
+ tokens.pop();
274
+ break;
275
+ }
212
276
  //
213
277
  let k = stack.length - 1;
214
278
  while (tokensfuncDefMap.has(stack[k]?.typ)) {
215
279
  k--;
216
280
  }
217
281
  if (stack[k]?.typ !== EnumToken.ColonTokenType) {
218
- if (tokens[index].typ !== EnumToken.SupportsFunctionTokenType && !equalsIgnoreCase('env', tokens[index].val)) {
282
+ if (tokens[index].typ !== EnumToken.SupportsFunctionTokenType &&
283
+ !equalsIgnoreCase("env", tokens[index].val)) {
219
284
  errors.push({
220
285
  action: "ignore",
221
286
  node: tokens[index],
@@ -224,7 +289,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
224
289
  }
225
290
  else {
226
291
  // not a declaration
227
- const result = matchAllSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
292
+ const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
228
293
  if (!result.valid) {
229
294
  errors.push(...result.errors, {
230
295
  action: "ignore",
@@ -353,7 +418,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
353
418
  {
354
419
  action: "drop",
355
420
  node: stack.at(-1),
356
- message: `unmatched token '${renderToken(stack.at(-1))}' at ${stack.at(-1).loc.src}:${stack.at(-1).loc.sta.lin}:${stack.at(-1).loc.sta.col}`,
421
+ message: `unmatched token '${renderValue(stack.at(-1))}' at ${stack.at(-1).loc.src}:${stack.at(-1).loc.sta.lin}:${stack.at(-1).loc.sta.col}`,
357
422
  },
358
423
  ],
359
424
  };
@@ -1,5 +1,5 @@
1
1
  import { EnumToken } from '../../ast/types.js';
2
- import { renderToken } from '../../renderer/render.js';
2
+ import { renderValue } from '../../renderer/render.js';
3
3
  import { trimArray } from '../../validation/match.js';
4
4
  import { tokensfuncDefMap, definedPropertySettings, tokensfuncSet } from '../../syntax/constants.js';
5
5
  import { parseMediaqueryList } from './at-rule-media.js';
@@ -350,7 +350,7 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
350
350
  {
351
351
  action: "drop",
352
352
  node: stack.at(-1),
353
- message: `unmatched token '${renderToken(stack.at(-1))}' at ${stack.at(-1).loc.src}:${stack.at(-1).loc.sta.lin}:${stack.at(-1).loc.sta.col}`,
353
+ message: `unmatched token '${renderValue(stack.at(-1))}' at ${stack.at(-1).loc.src}:${stack.at(-1).loc.sta.lin}:${stack.at(-1).loc.sta.col}`,
354
354
  },
355
355
  ],
356
356
  };
@@ -1,14 +1,8 @@
1
1
  import { EnumToken } from '../../ast/types.js';
2
2
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
3
3
  import { getSyntaxRule } from '../../validation/config.js';
4
- import { trimArray, matchAllSyntax, createValidationContext } from '../../validation/match.js';
4
+ import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
5
5
 
6
- // export const mediaQueryConditionEnum: Set<EnumToken> = new Set([
7
- // EnumToken.ParensTokenType,
8
- // EnumToken.IdenTokenType,
9
- // EnumToken.MediaQueryConditionTokenType,
10
- // EnumToken.MediaQueryUnaryFeatureTokenType,
11
- // ]);
12
6
  function matchAtRuleSyntax(atRule, stream, options) {
13
7
  const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + atRule.nam);
14
8
  const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
@@ -30,7 +24,7 @@ function matchAtRuleSyntax(atRule, stream, options) {
30
24
  }
31
25
  return { success: true, errors: [] };
32
26
  }
33
- const { success, errors} = matchAllSyntax(syntax, createValidationContext(stream), options);
27
+ const { success, errors} = matchAllSyntaxes(syntax, createValidationContext(stream), options);
34
28
  return { success, errors };
35
29
  }
36
30