@tbela99/css-parser 1.4.3 → 1.4.5

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 +196 -2
  2. package/README.md +68 -1120
  3. package/dist/config.json.js +43 -2
  4. package/dist/index-umd-web.js +18118 -15886
  5. package/dist/index.cjs +16838 -14611
  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 +64 -17
  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 +530 -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
@@ -6,6 +6,8 @@ import { pseudoElements, isValue, isColor } from '../syntax/syntax.js';
6
6
  import { isDeclarationValue } from '../parser/utils/declaration.js';
7
7
  import { renderSyntax } from './parser/parse.js';
8
8
  import { equalsIgnoreCase } from '../parser/utils/text.js';
9
+ import { cloneNode } from '../ast/clone.js';
10
+ import { parseTokens } from '../parser/parse.js';
9
11
 
10
12
  const config = getSyntaxConfig();
11
13
  // @ts-expect-error
@@ -321,7 +323,7 @@ function createValidationContext(tokens) {
321
323
  };
322
324
  return token;
323
325
  }
324
- function matchSelectorSyntax(stream, errors, options, nested) {
326
+ function matchSelectorSyntax(stream, errors, options, nested = true) {
325
327
  const stack = [];
326
328
  const tokens = [];
327
329
  const nodes = [
@@ -340,20 +342,20 @@ function matchSelectorSyntax(stream, errors, options, nested) {
340
342
  let token;
341
343
  let i = 0;
342
344
  let success = true;
343
- if (!nested) {
344
- while (i < stream.length &&
345
- (stream[i].typ === EnumToken.WhitespaceTokenType || stream[i].typ === EnumToken.CommentTokenType)) {
346
- i++;
347
- }
348
- if (i < stream.length) {
349
- switch (stream[i].typ) {
350
- case EnumToken.Plus:
351
- case EnumToken.Tilda:
352
- case EnumToken.GtTokenType:
353
- case EnumToken.ColumnCombinatorTokenType:
354
- case EnumToken.ChildCombinatorTokenType:
355
- case EnumToken.NextSiblingCombinatorTokenType:
356
- case EnumToken.SubsequentSiblingCombinatorTokenType:
345
+ while (i < stream.length &&
346
+ (stream[i].typ === EnumToken.WhitespaceTokenType || stream[i].typ === EnumToken.CommentTokenType)) {
347
+ i++;
348
+ }
349
+ if (i < stream.length) {
350
+ switch (stream[i].typ) {
351
+ case EnumToken.Plus:
352
+ case EnumToken.Tilda:
353
+ case EnumToken.GtTokenType:
354
+ case EnumToken.ColumnCombinatorTokenType:
355
+ case EnumToken.ChildCombinatorTokenType:
356
+ case EnumToken.NextSiblingCombinatorTokenType:
357
+ case EnumToken.SubsequentSiblingCombinatorTokenType:
358
+ if (!nested) {
357
359
  return {
358
360
  success: false,
359
361
  errors: [
@@ -365,7 +367,7 @@ function matchSelectorSyntax(stream, errors, options, nested) {
365
367
  },
366
368
  ],
367
369
  };
368
- }
370
+ }
369
371
  }
370
372
  }
371
373
  for (; i < stream.length; i++) {
@@ -373,9 +375,12 @@ function matchSelectorSyntax(stream, errors, options, nested) {
373
375
  if (token.typ === EnumToken.EOF) {
374
376
  break;
375
377
  }
378
+ if (token.typ === EnumToken.Star) {
379
+ token.typ = EnumToken.UniversalSelectorTokenType;
380
+ }
376
381
  tokens.push(token);
377
382
  if (tokensfuncDefMap.has(token.typ)) {
378
- if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
383
+ if (stack.length > 0 && nodes.includes(stack.at(-1).typ)) {
379
384
  stack.pop();
380
385
  }
381
386
  stack.push(token);
@@ -398,6 +403,15 @@ function matchSelectorSyntax(stream, errors, options, nested) {
398
403
  case EnumToken.BadCommentTokenType:
399
404
  case EnumToken.BadStringTokenType:
400
405
  break;
406
+ case EnumToken.PseudoClassFuncTokenType: {
407
+ const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, token.val + "()")?.[0]?.chi ?? [], createValidationContext(token.chi), options);
408
+ if (!result.success) {
409
+ success = false;
410
+ if (result.errors.length > 0) {
411
+ errors.push(...result.errors);
412
+ }
413
+ }
414
+ }
401
415
  case EnumToken.WhitespaceTokenType:
402
416
  case EnumToken.CommentTokenType:
403
417
  case EnumToken.CDOCOMMTokenType:
@@ -449,6 +463,9 @@ function matchSelectorSyntax(stream, errors, options, nested) {
449
463
  if (stream[i + 1]?.typ === EnumToken.WhitespaceTokenType) {
450
464
  i++;
451
465
  }
466
+ if (stack.length > 0 && stack.at(-1)?.typ === EnumToken.UniversalSelectorTokenType) {
467
+ stack.pop();
468
+ }
452
469
  if (stack.length > 0 && nodes.includes(stack.at(-1)?.typ)) {
453
470
  return {
454
471
  success: false,
@@ -465,6 +482,9 @@ function matchSelectorSyntax(stream, errors, options, nested) {
465
482
  stack.push(token);
466
483
  break;
467
484
  case EnumToken.CommaTokenType:
485
+ if (stack.length > 0 && stack.at(-1).typ === EnumToken.UniversalSelectorTokenType) {
486
+ stack.pop();
487
+ }
468
488
  if (tokens.length === 0 || stack.at(-1)?.typ == EnumToken.CommaTokenType) {
469
489
  return {
470
490
  success: false,
@@ -519,7 +539,9 @@ function matchSelectorSyntax(stream, errors, options, nested) {
519
539
  case EnumToken.StartMatchTokenType:
520
540
  case EnumToken.EndMatchTokenType:
521
541
  case EnumToken.DashMatchTokenType:
522
- if (stack.at(-1)?.typ !== EnumToken.AttrStartTokenType) {
542
+ if (stack.at(-1)?.typ !== EnumToken.AttrStartTokenType &&
543
+ !(stack.at(-1)?.typ === EnumToken.UniversalSelectorTokenType &&
544
+ stack.at(-2)?.typ === EnumToken.AttrStartTokenType)) {
523
545
  return {
524
546
  success: false,
525
547
  errors: [
@@ -533,9 +555,9 @@ function matchSelectorSyntax(stream, errors, options, nested) {
533
555
  };
534
556
  }
535
557
  break;
536
- case EnumToken.Star:
537
- Object.assign(token, { typ: EnumToken.UniversalSelectorTokenType });
538
- break;
558
+ // case EnumToken.Star:
559
+ // Object.assign(token, { typ: EnumToken.UniversalSelectorTokenType });
560
+ // break;
539
561
  case EnumToken.IdenTokenType:
540
562
  case EnumToken.HashTokenType:
541
563
  case EnumToken.PseudoElementTokenType:
@@ -552,6 +574,9 @@ function matchSelectorSyntax(stream, errors, options, nested) {
552
574
  stack.push(token);
553
575
  break;
554
576
  case EnumToken.AttrEndTokenType:
577
+ if (stack.length > 0 && stack.at(-1).typ === EnumToken.UniversalSelectorTokenType) {
578
+ stack.pop();
579
+ }
555
580
  if (stack.at(-1)?.typ !== EnumToken.AttrStartTokenType) {
556
581
  return {
557
582
  success: false,
@@ -815,7 +840,7 @@ function matchSelectorSyntax(stream, errors, options, nested) {
815
840
  typ: EnumToken.PseudoClassFunctionTokenDefType,
816
841
  chi: [],
817
842
  }));
818
- tokens.pop();
843
+ // tokens.pop();
819
844
  break;
820
845
  }
821
846
  return {
@@ -830,6 +855,9 @@ function matchSelectorSyntax(stream, errors, options, nested) {
830
855
  ],
831
856
  };
832
857
  case EnumToken.EndParensTokenType:
858
+ if (stack.length > 0 && stack.at(-1)?.typ === EnumToken.UniversalSelectorTokenType) {
859
+ stack.pop();
860
+ }
833
861
  if (stack.at(-1)?.typ === EnumToken.PseudoClassFunctionTokenDefType ||
834
862
  stack.at(-1)?.typ === EnumToken.PseudoElementTokenType) {
835
863
  const token = stack.at(-1);
@@ -847,7 +875,7 @@ function matchSelectorSyntax(stream, errors, options, nested) {
847
875
  };
848
876
  }
849
877
  const index = tokens.indexOf(token);
850
- const result = matchAllSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, token.val + "()")?.[0]?.chi ?? [], createValidationContext(tokens.slice(index + 1, tokens.length - 1)), options);
878
+ const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, token.val + "()")?.[0]?.chi ?? [], createValidationContext(tokens.slice(index + 1, tokens.length - 1)), options);
851
879
  if (!result.success) {
852
880
  success = false;
853
881
  if (result.errors.length > 0) {
@@ -899,6 +927,9 @@ function matchSelectorSyntax(stream, errors, options, nested) {
899
927
  tokens.splice(tokens.length - 2, 1);
900
928
  }
901
929
  }
930
+ if (stack.length > 0 && stack.at(-1).typ === EnumToken.UniversalSelectorTokenType) {
931
+ stack.pop();
932
+ }
902
933
  if (stack.length > 0) {
903
934
  return {
904
935
  success: false,
@@ -924,7 +955,7 @@ function matchSelectorSyntax(stream, errors, options, nested) {
924
955
  }
925
956
  return { success, errors };
926
957
  }
927
- function matchAllSyntax(syntaxes, context, options) {
958
+ function matchAllSyntaxes(syntaxes, context, options) {
928
959
  const result = matchSyntax(syntaxes, context, {
929
960
  ...options,
930
961
  visited: new Map(),
@@ -999,12 +1030,15 @@ function matchListSyntax(syntax, context, options) {
999
1030
  count++;
1000
1031
  success = true;
1001
1032
  result = tmpResult;
1002
- context.update(range.at(-1));
1003
- if (context.done()) {
1004
- // context.end();
1033
+ if (Number.isFinite(match?.max?.val) && count === match.max.val) {
1034
+ context.update(range.at(-1)?.typ === EnumToken.CommaTokenType ? range.at(-2) : range.at(-1));
1005
1035
  break;
1006
1036
  }
1007
- if (Number.isFinite(match?.max?.val) && count === match.max.val) {
1037
+ else {
1038
+ context.update(range.at(-1));
1039
+ }
1040
+ if (context.done()) {
1041
+ // context.end();
1008
1042
  break;
1009
1043
  }
1010
1044
  }
@@ -1025,12 +1059,21 @@ function matchListSyntax(syntax, context, options) {
1025
1059
  };
1026
1060
  }
1027
1061
  }
1028
- return {
1029
- ...(result ?? tmpResult),
1030
- success,
1031
- context,
1032
- token: context.peek(),
1033
- };
1062
+ return result == null
1063
+ ? {
1064
+ success: false,
1065
+ valid: true,
1066
+ context,
1067
+ token: context.peek(),
1068
+ syntaxToken: syntax,
1069
+ errors: [],
1070
+ }
1071
+ : {
1072
+ ...result,
1073
+ success,
1074
+ context,
1075
+ token: context.peek(),
1076
+ };
1034
1077
  }
1035
1078
  function matchOccurenceSyntax(syntax, context, options) {
1036
1079
  const { match, ...rest } = syntax;
@@ -1099,7 +1142,7 @@ function matchSyntax(syntaxes, context, options) {
1099
1142
  }
1100
1143
  syntaxes = syntaxes.slice();
1101
1144
  let i = -1;
1102
- let success;
1145
+ let success = false;
1103
1146
  let token = null;
1104
1147
  let result = null;
1105
1148
  let isOptional;
@@ -1148,7 +1191,7 @@ function matchSyntax(syntaxes, context, options) {
1148
1191
  }
1149
1192
  if (token.typ === EnumToken.WildCardFunctionTokenType && token.val === "var") {
1150
1193
  result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, token.val + "()")?.[0]?.chi, createValidationContext(token.chi), options);
1151
- if (result.success || isOptional) {
1194
+ if ((result.success && result.context.done()) || isOptional) {
1152
1195
  context.next();
1153
1196
  continue;
1154
1197
  }
@@ -1331,11 +1374,49 @@ function matchSyntax(syntaxes, context, options) {
1331
1374
  options.visited.get(token).add(syntaxes[i]);
1332
1375
  success = false;
1333
1376
  switch (syntaxes[i].typ) {
1377
+ case ValidationTokenEnum.Comma:
1378
+ if (token.typ == EnumToken.CommaTokenType) {
1379
+ success = true;
1380
+ options.visited.get(token).delete(syntaxes[i]);
1381
+ context.next();
1382
+ if (context.done()) {
1383
+ return {
1384
+ success: true,
1385
+ valid: true,
1386
+ token: null,
1387
+ context,
1388
+ syntaxToken: syntaxes[i + 1],
1389
+ errors: [],
1390
+ };
1391
+ }
1392
+ break;
1393
+ }
1394
+ if (isOptional) {
1395
+ break;
1396
+ }
1397
+ return {
1398
+ success: false,
1399
+ valid: true,
1400
+ token,
1401
+ context,
1402
+ syntaxToken: syntaxes[i],
1403
+ errors: [],
1404
+ };
1334
1405
  case ValidationTokenEnum.Colon:
1335
1406
  if (token.typ == EnumToken.ColonTokenType) {
1336
1407
  success = true;
1337
1408
  options.visited.get(token).delete(syntaxes[i]);
1338
1409
  context.next();
1410
+ if (context.done()) {
1411
+ return {
1412
+ success: true,
1413
+ valid: true,
1414
+ token: null,
1415
+ context,
1416
+ syntaxToken: syntaxes[i + 1],
1417
+ errors: [],
1418
+ };
1419
+ }
1339
1420
  break;
1340
1421
  }
1341
1422
  if (isOptional) {
@@ -1547,6 +1628,14 @@ function matchSyntax(syntaxes, context, options) {
1547
1628
  options.visited.get(token).delete(syntaxes[i]);
1548
1629
  if (result.context.done()) {
1549
1630
  context.end();
1631
+ return {
1632
+ success: true,
1633
+ valid: true,
1634
+ token: null,
1635
+ context,
1636
+ syntaxToken: syntaxes[i + 1],
1637
+ errors: [],
1638
+ };
1550
1639
  }
1551
1640
  else {
1552
1641
  context.update(result.context.current());
@@ -1742,41 +1831,22 @@ function matchSyntax(syntaxes, context, options) {
1742
1831
  };
1743
1832
  }
1744
1833
  result = matchSyntax(syntaxes[i].chi, createValidationContext(range.slice(1, -1)), options);
1745
- if (result.success) {
1834
+ if (result.success && result.context.done()) {
1746
1835
  context.update(range.at(-1));
1747
1836
  options.visited.get(token).delete(syntaxes[i]);
1837
+ break;
1748
1838
  }
1749
- break;
1750
1839
  }
1751
1840
  else {
1752
1841
  result = matchSyntax(syntaxes[i].chi, createValidationContext(token.chi), options);
1753
- }
1754
- if (result.success) {
1755
- success = true;
1756
- options.visited.get(token).delete(syntaxes[i]);
1757
- context.next();
1758
- break;
1759
- }
1760
- return {
1761
- success: false,
1762
- valid: true,
1763
- token,
1764
- context,
1765
- syntaxToken: syntaxes[i],
1766
- errors: result.errors,
1767
- };
1768
- case ValidationTokenEnum.Comma:
1769
- if (token.typ !== EnumToken.CommaTokenType && isOptional) {
1770
- let k = i;
1771
- while (syntaxes[--k]?.typ === ValidationTokenEnum.Whitespace) { }
1772
- // ignore the comma if the previous token is a list
1773
- if (syntaxes[k]?.isList) {
1774
- continue;
1842
+ if (result.success && result.context.done()) {
1843
+ success = true;
1844
+ options.visited.get(token).delete(syntaxes[i]);
1845
+ context.next();
1846
+ break;
1775
1847
  }
1776
1848
  }
1777
- if (token.typ === EnumToken.CommaTokenType) {
1778
- options.visited.get(token).delete(syntaxes[i]);
1779
- context.next();
1849
+ if (isOptional) {
1780
1850
  break;
1781
1851
  }
1782
1852
  return {
@@ -1785,7 +1855,7 @@ function matchSyntax(syntaxes, context, options) {
1785
1855
  token,
1786
1856
  context,
1787
1857
  syntaxToken: syntaxes[i],
1788
- errors: [],
1858
+ errors: result.errors,
1789
1859
  };
1790
1860
  case ValidationTokenEnum.LessThan:
1791
1861
  if (token.typ === EnumToken.LtTokenType) {
@@ -1816,25 +1886,25 @@ function matchSyntax(syntaxes, context, options) {
1816
1886
  errors: [],
1817
1887
  };
1818
1888
  case ValidationTokenEnum.FunctionDefinition:
1819
- if (tokensfuncDefMap.has(token.typ) &&
1820
- equalsIgnoreCase(token.val, syntaxes[i].val)) {
1821
- const children = trimArray(context.peekRange());
1822
- result = matchSyntax((getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()")?.[0]).chi ?? [], createValidationContext(children.slice(1, -1)), options);
1823
- if (result.success) {
1824
- success = true;
1825
- options.visited.get(token).delete(syntaxes[i]);
1826
- context.update(children.at(-1));
1827
- break;
1889
+ if (equalsIgnoreCase(token.val, syntaxes[i].val)) {
1890
+ if (tokensfuncDefMap.has(token.typ)) {
1891
+ const children = trimArray(context.peekRange());
1892
+ result = matchSyntax((getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()")?.[0]).chi ?? [], createValidationContext(children.slice(1, -1)), options);
1893
+ if (result.success && result.context.done()) {
1894
+ success = true;
1895
+ options.visited.get(token).delete(syntaxes[i]);
1896
+ context.update(children.at(-1));
1897
+ break;
1898
+ }
1828
1899
  }
1829
- }
1830
- else if (tokensfuncSet.has(token.typ) &&
1831
- equalsIgnoreCase(token.val, syntaxes[i].val)) {
1832
- result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()") ?? [], createValidationContext([token]), options);
1833
- if (result.success) {
1834
- success = true;
1835
- options.visited.get(token).delete(syntaxes[i]);
1836
- context.next();
1837
- break;
1900
+ else if (tokensfuncSet.has(token.typ)) {
1901
+ result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()") ?? [], createValidationContext([token]), options);
1902
+ if (result.success && result.context.done()) {
1903
+ success = true;
1904
+ options.visited.get(token).delete(syntaxes[i]);
1905
+ context.next();
1906
+ break;
1907
+ }
1838
1908
  }
1839
1909
  }
1840
1910
  return {
@@ -2036,7 +2106,8 @@ function matchAmpersandSyntax(syntax, context, options) {
2036
2106
  }
2037
2107
  function matchProperty(property, context, options) {
2038
2108
  let success = false;
2039
- let checkCalc = context.peek()?.typ == EnumToken.MathFunctionTokenDefType &&
2109
+ let t = context.peek()?.typ;
2110
+ let checkCalc = (t == EnumToken.MathFunctionTokenDefType || t == EnumToken.MathFunctionTokenType) &&
2040
2111
  [
2041
2112
  "number",
2042
2113
  "zero",
@@ -2053,18 +2124,36 @@ function matchProperty(property, context, options) {
2053
2124
  checkCalc = context.peek().val === "calc";
2054
2125
  }
2055
2126
  if (checkCalc) {
2056
- const range = context.peekRange();
2057
- const result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, context.peek().val + "()")?.[0]?.chi, createValidationContext(range.slice(1, -1)), options);
2058
- if (result.success) {
2059
- context.update(range.at(-1));
2060
- return {
2061
- success: true,
2062
- valid: true,
2063
- token: range.at(-1),
2064
- context,
2065
- syntaxToken: null,
2066
- errors: [],
2067
- };
2127
+ let result;
2128
+ const syntax = getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, context.peek().val + "()")?.[0]?.chi;
2129
+ if (t === EnumToken.MathFunctionTokenType) {
2130
+ result = matchSyntax(syntax, createValidationContext(context.peek().chi), options);
2131
+ if (result.success && result.context.done()) {
2132
+ context.next();
2133
+ return {
2134
+ success: true,
2135
+ valid: true,
2136
+ token: context.peek(),
2137
+ context,
2138
+ syntaxToken: null,
2139
+ errors: [],
2140
+ };
2141
+ }
2142
+ }
2143
+ else {
2144
+ const range = context.peekRange();
2145
+ result = matchSyntax(syntax, createValidationContext(range.slice(1, -1)), options);
2146
+ if (result.success) {
2147
+ context.update(range.at(-1));
2148
+ return {
2149
+ success: true,
2150
+ valid: true,
2151
+ token: range.at(-1),
2152
+ context,
2153
+ syntaxToken: null,
2154
+ errors: [],
2155
+ };
2156
+ }
2068
2157
  }
2069
2158
  return {
2070
2159
  success: false,
@@ -2111,6 +2200,9 @@ function matchProperty(property, context, options) {
2111
2200
  expectToken = true;
2112
2201
  }
2113
2202
  while ((token = context.peek()) != null) {
2203
+ if (token.typ == EnumToken.StartParensTokenType || tokensfuncDefMap.has(token?.typ)) {
2204
+ stack.push(token);
2205
+ }
2114
2206
  if (token.typ == EnumToken.WhitespaceTokenType || token.typ == EnumToken.CommentTokenType) {
2115
2207
  context.next();
2116
2208
  }
@@ -2196,7 +2288,7 @@ function matchProperty(property, context, options) {
2196
2288
  const token = context.peek();
2197
2289
  if (token?.typ === EnumToken.ParensTokenType) {
2198
2290
  const result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc()")[0].chi, createValidationContext(token.chi), options);
2199
- success = result.success;
2291
+ success = result.success && result.context.done();
2200
2292
  break;
2201
2293
  }
2202
2294
  if (token?.typ === EnumToken.BinaryExpressionTokenType) {
@@ -2639,8 +2731,17 @@ function matchProperty(property, context, options) {
2639
2731
  const errors = [];
2640
2732
  if (tokensfuncDefMap.has(token?.typ)) {
2641
2733
  const range = context.peekRange();
2642
- const result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, token.val + "()"), createValidationContext(range), options);
2643
- if (result.success) {
2734
+ // if (
2735
+ // range.some(
2736
+ // (token) =>
2737
+ // token.typ == EnumToken.IdenTokenType &&
2738
+ // "hslrgbchwmyk".split("").some((t) => equalsIgnoreCase(t, (token as IdentToken).val)),
2739
+ // )
2740
+ // ) {
2741
+ const newRange = range.map((t) => cloneNode(t, true));
2742
+ parseTokens(newRange, { parseColor: true }, errors);
2743
+ success = newRange.length == 1 && isColor(newRange[0], errors);
2744
+ if (success) {
2644
2745
  context.update(range.at(-1));
2645
2746
  return {
2646
2747
  success: true,
@@ -2648,10 +2749,38 @@ function matchProperty(property, context, options) {
2648
2749
  token: context.peek(),
2649
2750
  context,
2650
2751
  syntaxToken: null,
2651
- errors: [],
2752
+ errors,
2652
2753
  };
2653
2754
  }
2654
- return result;
2755
+ return {
2756
+ success: false,
2757
+ valid: true,
2758
+ token: context.peek(),
2759
+ context,
2760
+ syntaxToken: null,
2761
+ errors,
2762
+ };
2763
+ // }
2764
+ // const result = matchSyntax(
2765
+ // getParsedSyntax(
2766
+ // ValidationSyntaxGroupEnum.Syntaxes,
2767
+ // (token as FunctionToken).val + "()",
2768
+ // ) as ValidationFunctionToken[],
2769
+ // createValidationContext(range),
2770
+ // options,
2771
+ // );
2772
+ // if (result.success) {
2773
+ // context.update(range.at(-1) as Token);
2774
+ // return {
2775
+ // success: true,
2776
+ // valid: true,
2777
+ // token: context.peek(),
2778
+ // context,
2779
+ // syntaxToken: null,
2780
+ // errors: [],
2781
+ // };
2782
+ // }
2783
+ // return result;
2655
2784
  }
2656
2785
  // @ts-expect-error
2657
2786
  else if ("chi" in token) {
@@ -2681,14 +2810,15 @@ function matchProperty(property, context, options) {
2681
2810
  case "attribute-selector":
2682
2811
  case "complex-selector-unit":
2683
2812
  case "pseudo-compound-selector":
2813
+ case "forgiving-relative-selector-list":
2684
2814
  case "complex-selector-list": {
2685
2815
  const tokens = context.getRemainingTokens();
2686
- const result = matchSelectorSyntax(tokens, [], options);
2687
- if (result.success) {
2816
+ const result = matchSelectorSyntax(tokens, [], options, property.val.startsWith("forgiving-relative-selector-list"));
2817
+ if (result.success || property.val == "forgiving-relative-selector-list") {
2688
2818
  context.update(tokens.at(-1));
2689
2819
  }
2690
2820
  return {
2691
- success: result.success,
2821
+ success: result.success || property.val == "forgiving-relative-selector-list",
2692
2822
  valid: true,
2693
2823
  token: context.peek(),
2694
2824
  context,
@@ -2955,6 +3085,7 @@ function matchRepeatableSyntax(syntax, context, options) {
2955
3085
  let result = null;
2956
3086
  let tmpResult;
2957
3087
  let success = !!isRepeatable;
3088
+ let index = context.index;
2958
3089
  do {
2959
3090
  tmpResult = matchSyntax([rest], context.slice(), options);
2960
3091
  if (tmpResult.success) {
@@ -2970,6 +3101,10 @@ function matchRepeatableSyntax(syntax, context, options) {
2970
3101
  else {
2971
3102
  context.update(result.context.current());
2972
3103
  }
3104
+ if (index === context.index) {
3105
+ break;
3106
+ }
3107
+ index = context.index;
2973
3108
  }
2974
3109
  } while (tmpResult.success && !context.done());
2975
3110
  return {
@@ -2982,4 +3117,4 @@ function matchRepeatableSyntax(syntax, context, options) {
2982
3117
  };
2983
3118
  }
2984
3119
 
2985
- export { createValidationContext, funcTypes, getMFInfo, isMFName, isMFValue, isStyleRangeValue, matchAllSyntax, matchOccurenceSyntax, matchSelectorSyntax, trimArray };
3120
+ export { createValidationContext, funcTypes, getMFInfo, isMFName, isMFValue, isStyleRangeValue, matchAllSyntaxes, matchOccurenceSyntax, matchSelectorSyntax, trimArray };
@@ -473,7 +473,6 @@ function parseSyntax(syntax) {
473
473
  }
474
474
  {
475
475
  let index = tokens.lastIndexOf(stack.at(-1));
476
- // "fit-content( <length-percentage [0,∞]> )"
477
476
  if ((tokens[index - 2]?.typ === ValidationTokenEnum.Keyword ||
478
477
  tokens[index - 2]?.typ === ValidationTokenEnum.StringToken) &&
479
478
  tokens[index - 1]?.typ === ValidationTokenEnum.Whitespace &&
@@ -74,6 +74,9 @@ var ValidationTokenEnum;
74
74
  ValidationTokenEnum[ValidationTokenEnum["DisallowWhitespace"] = 46] = "DisallowWhitespace";
75
75
  ValidationTokenEnum[ValidationTokenEnum["Colon"] = 47] = "Colon";
76
76
  })(ValidationTokenEnum || (ValidationTokenEnum = {}));
77
+ /**
78
+ * Keys of the validation config object
79
+ */
77
80
  var ValidationSyntaxGroupEnum;
78
81
  (function (ValidationSyntaxGroupEnum) {
79
82
  ValidationSyntaxGroupEnum["Declarations"] = "declarations";
@@ -85,6 +88,9 @@ var ValidationSyntaxGroupEnum;
85
88
  ValidationSyntaxGroupEnum["Languages"] = "languages";
86
89
  ValidationSyntaxGroupEnum["mediaFeatures"] = "mediaFeatures";
87
90
  })(ValidationSyntaxGroupEnum || (ValidationSyntaxGroupEnum = {}));
91
+ /**
92
+ * Types of media features
93
+ */
88
94
  var MediaFeatureType;
89
95
  (function (MediaFeatureType) {
90
96
  MediaFeatureType["BooleanType"] = "boolean";