@tbela99/css-parser 1.1.1 → 1.3.0

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 (107) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +53 -6
  3. package/dist/index-umd-web.js +5503 -5037
  4. package/dist/index.cjs +5510 -5044
  5. package/dist/index.d.ts +148 -41
  6. package/dist/lib/ast/expand.js +81 -65
  7. package/dist/lib/ast/features/calc.js +14 -36
  8. package/dist/lib/ast/features/inlinecssvariables.js +6 -17
  9. package/dist/lib/ast/features/prefix.js +22 -19
  10. package/dist/lib/ast/features/shorthand.js +1 -1
  11. package/dist/lib/ast/features/transform.js +17 -2
  12. package/dist/lib/ast/math/expression.js +74 -172
  13. package/dist/lib/ast/math/math.js +24 -22
  14. package/dist/lib/ast/minify.js +249 -199
  15. package/dist/lib/ast/transform/compute.js +18 -41
  16. package/dist/lib/ast/transform/matrix.js +36 -36
  17. package/dist/lib/ast/transform/minify.js +37 -59
  18. package/dist/lib/ast/transform/perspective.js +1 -1
  19. package/dist/lib/ast/transform/rotate.js +13 -13
  20. package/dist/lib/ast/transform/scale.js +8 -8
  21. package/dist/lib/ast/transform/skew.js +4 -4
  22. package/dist/lib/ast/transform/translate.js +8 -8
  23. package/dist/lib/ast/transform/utils.js +80 -28
  24. package/dist/lib/ast/types.js +122 -2
  25. package/dist/lib/fs/resolve.js +1 -14
  26. package/dist/lib/parser/declaration/list.js +1 -1
  27. package/dist/lib/parser/declaration/map.js +1 -1
  28. package/dist/lib/parser/declaration/set.js +3 -3
  29. package/dist/lib/parser/parse.js +53 -107
  30. package/dist/lib/parser/tokenize.js +29 -53
  31. package/dist/lib/parser/utils/declaration.js +1 -1
  32. package/dist/lib/parser/utils/type.js +2 -2
  33. package/dist/lib/renderer/render.js +79 -194
  34. package/dist/lib/{renderer → syntax}/color/a98rgb.js +2 -2
  35. package/dist/lib/syntax/color/cmyk.js +104 -0
  36. package/dist/lib/{renderer → syntax}/color/color-mix.js +31 -33
  37. package/dist/lib/syntax/color/color.js +581 -0
  38. package/dist/lib/syntax/color/hex.js +179 -0
  39. package/dist/lib/syntax/color/hsl.js +201 -0
  40. package/dist/lib/syntax/color/hwb.js +204 -0
  41. package/dist/lib/syntax/color/lab.js +262 -0
  42. package/dist/lib/syntax/color/lch.js +194 -0
  43. package/dist/lib/syntax/color/oklab.js +237 -0
  44. package/dist/lib/syntax/color/oklch.js +166 -0
  45. package/dist/lib/{renderer → syntax}/color/p3.js +3 -3
  46. package/dist/lib/{renderer → syntax}/color/rec2020.js +11 -11
  47. package/dist/lib/{renderer → syntax}/color/relativecolor.js +54 -41
  48. package/dist/lib/syntax/color/rgb.js +140 -0
  49. package/dist/lib/{renderer → syntax}/color/srgb.js +58 -46
  50. package/dist/lib/syntax/color/utils/components.js +46 -0
  51. package/dist/lib/{renderer → syntax}/color/utils/constants.js +6 -33
  52. package/dist/lib/syntax/color/utils/distance.js +40 -0
  53. package/dist/lib/{renderer → syntax}/color/xyz.js +27 -14
  54. package/dist/lib/{renderer → syntax}/color/xyzd50.js +8 -8
  55. package/dist/lib/syntax/syntax.js +78 -77
  56. package/dist/lib/syntax/utils.js +70 -0
  57. package/dist/lib/validation/at-rules/container.js +1 -1
  58. package/dist/lib/validation/at-rules/counter-style.js +1 -1
  59. package/dist/lib/validation/at-rules/custom-media.js +1 -1
  60. package/dist/lib/validation/at-rules/document.js +2 -2
  61. package/dist/lib/validation/at-rules/font-feature-values.js +2 -2
  62. package/dist/lib/validation/at-rules/import.js +5 -5
  63. package/dist/lib/validation/at-rules/keyframes.js +3 -13
  64. package/dist/lib/validation/at-rules/layer.js +1 -1
  65. package/dist/lib/validation/at-rules/media.js +1 -1
  66. package/dist/lib/validation/at-rules/namespace.js +1 -1
  67. package/dist/lib/validation/at-rules/page-margin-box.js +1 -1
  68. package/dist/lib/validation/at-rules/page.js +1 -1
  69. package/dist/lib/validation/at-rules/supports.js +7 -7
  70. package/dist/lib/validation/at-rules/when.js +1 -1
  71. package/dist/lib/validation/atrule.js +2 -2
  72. package/dist/lib/validation/config.js +0 -3
  73. package/dist/lib/validation/config.json.js +1 -1
  74. package/dist/lib/validation/parser/parse.js +8 -11
  75. package/dist/lib/validation/selector.js +1 -9
  76. package/dist/lib/validation/syntax.js +67 -137
  77. package/dist/lib/validation/syntaxes/complex-selector-list.js +2 -19
  78. package/dist/lib/validation/syntaxes/complex-selector.js +1 -1
  79. package/dist/lib/validation/syntaxes/compound-selector.js +5 -24
  80. package/dist/lib/validation/syntaxes/family-name.js +5 -40
  81. package/dist/lib/validation/syntaxes/keyframe-selector.js +3 -22
  82. package/dist/lib/validation/syntaxes/layer-name.js +1 -1
  83. package/dist/lib/validation/syntaxes/relative-selector-list.js +1 -25
  84. package/dist/lib/validation/syntaxes/relative-selector.js +1 -1
  85. package/dist/lib/validation/syntaxes/url.js +3 -34
  86. package/dist/lib/validation/utils/list.js +2 -9
  87. package/dist/lib/validation/utils/whitespace.js +1 -1
  88. package/dist/node/index.js +4 -2
  89. package/dist/web/index.js +4 -2
  90. package/package.json +4 -4
  91. package/.editorconfig +0 -484
  92. package/dist/lib/ast/transform/convert.js +0 -33
  93. package/dist/lib/ast/utils/utils.js +0 -104
  94. package/dist/lib/renderer/color/color.js +0 -654
  95. package/dist/lib/renderer/color/hex.js +0 -105
  96. package/dist/lib/renderer/color/hsl.js +0 -125
  97. package/dist/lib/renderer/color/hwb.js +0 -103
  98. package/dist/lib/renderer/color/lab.js +0 -148
  99. package/dist/lib/renderer/color/lch.js +0 -90
  100. package/dist/lib/renderer/color/oklab.js +0 -131
  101. package/dist/lib/renderer/color/oklch.js +0 -75
  102. package/dist/lib/renderer/color/rgb.js +0 -50
  103. package/dist/lib/renderer/color/utils/components.js +0 -34
  104. package/dist/lib/validation/syntaxes/keyframe-block-list.js +0 -28
  105. package/dist/lib/{renderer → syntax}/color/hsv.js +0 -0
  106. package/dist/lib/{renderer → syntax}/color/prophotorgb.js +1 -1
  107. /package/dist/lib/{renderer → syntax}/color/utils/matrix.js +0 -0
@@ -1,10 +1,10 @@
1
- import { EnumToken } from '../ast/types.js';
1
+ import { EnumToken, ColorType } from '../ast/types.js';
2
2
  import '../ast/minify.js';
3
3
  import { walkValues, WalkerOptionEnum } from '../ast/walk.js';
4
4
  import '../parser/parse.js';
5
5
  import '../parser/tokenize.js';
6
6
  import '../parser/utils/config.js';
7
- import { COLORS_NAMES, colorsFunc, funcLike, ColorKind } from '../renderer/color/utils/constants.js';
7
+ import { COLORS_NAMES, colorsFunc, funcLike } from './color/utils/constants.js';
8
8
  import { buildExpression } from '../ast/math/expression.js';
9
9
  import '../renderer/sourcemap/lib/encode.js';
10
10
 
@@ -498,15 +498,24 @@ function isPolarColorspace(token) {
498
498
  return ['hsl', 'hwb', 'lch', 'oklch'].includes(token.val);
499
499
  }
500
500
  function isHueInterpolationMethod(token) {
501
- if (token.typ != EnumToken.IdenTokenType) {
501
+ if (!Array.isArray(token)) {
502
+ return token.typ == EnumToken.IdenTokenType && 'hue' === token.val?.toLowerCase?.();
503
+ }
504
+ if (token.length != 2 || token[0].typ != EnumToken.IdenTokenType || token[1].typ != EnumToken.IdenTokenType) {
502
505
  return false;
503
506
  }
504
- return ['shorter', 'longer', 'increasing', 'decreasing'].includes(token.val);
507
+ return ['shorter', 'longer', 'increasing', 'decreasing'].includes(token[0].val?.toLowerCase?.()) && 'hue' === token[1].val?.toLowerCase?.();
505
508
  }
506
509
  function isIdentColor(token) {
507
- return token.typ == EnumToken.ColorTokenType && [ColorKind.SYS, ColorKind.DPSYS, ColorKind.LIT].includes(token.kin) && isIdent(token.val);
510
+ return token.typ == EnumToken.ColorTokenType && [ColorType.SYS, ColorType.DPSYS, ColorType.LIT].includes(token.kin) && isIdent(token.val);
511
+ }
512
+ function isPercentageToken(token) {
513
+ return token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == 0);
508
514
  }
509
515
  function isColor(token) {
516
+ if (token.typ == EnumToken.ColorTokenType) {
517
+ return true;
518
+ }
510
519
  if (token.typ == EnumToken.IdenTokenType) {
511
520
  // named color
512
521
  return token.val.toLowerCase() in COLORS_NAMES;
@@ -595,79 +604,80 @@ function isColor(token) {
595
604
  }
596
605
  return true;
597
606
  }
598
- else { // @ts-ignore
599
- if (token.val == 'color-mix') {
600
- // @ts-ignore
601
- const children = token.chi.reduce((acc, t) => {
602
- if (t.typ == EnumToken.CommaTokenType) {
603
- acc.push([]);
604
- }
605
- else {
606
- if (![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ)) {
607
- acc[acc.length - 1].push(t);
608
- }
607
+ // @ts-ignore
608
+ else if (token.val == 'color-mix') {
609
+ // @ts-ignore
610
+ const children = token.chi.reduce((acc, t) => {
611
+ if (t.typ == EnumToken.CommaTokenType) {
612
+ acc.push([]);
613
+ }
614
+ else {
615
+ if (![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ)) {
616
+ acc[acc.length - 1].push(t);
609
617
  }
610
- return acc;
611
- }, [[]]);
612
- if (children.length == 3) {
613
- if (children[0].length > 3 ||
614
- children[0][0].typ != EnumToken.IdenTokenType ||
615
- children[0][0].val != 'in' ||
616
- !isColorspace(children[0][1]) ||
617
- (children[0].length == 3 && !isHueInterpolationMethod(children[0][2])) ||
618
- children[1].length > 2 ||
619
- children[1][0].typ != EnumToken.ColorTokenType ||
620
- children[2].length > 2 ||
621
- children[2][0].typ != EnumToken.ColorTokenType) {
618
+ }
619
+ return acc;
620
+ }, [[]]);
621
+ if (children.length == 3) {
622
+ if (children[0].length > 4 ||
623
+ children[0][0].typ != EnumToken.IdenTokenType ||
624
+ 'in' !== children[0][0].val?.toLowerCase?.() ||
625
+ !isColorspace(children[0][1]) ||
626
+ (children[0].length >= 3 && !isHueInterpolationMethod(children[0].slice(2))) ||
627
+ children[1].length > 2 ||
628
+ !isColor(children[1][0]) ||
629
+ (children[1].length == 2 && !isPercentageToken(children[1][1])) ||
630
+ children[2].length > 2 ||
631
+ (children[2].length == 2 && !isPercentageToken(children[2][1])) ||
632
+ !isColor(children[2][0])) {
633
+ return false;
634
+ }
635
+ if (children[1].length == 2) {
636
+ if (!(children[1][1].typ == EnumToken.PercentageTokenType || (children[1][1].typ == EnumToken.NumberTokenType && children[1][1].val == 0))) {
622
637
  return false;
623
638
  }
624
- if (children[1].length == 2) {
625
- if (!(children[1][1].typ == EnumToken.PercentageTokenType || (children[1][1].typ == EnumToken.NumberTokenType && children[1][1].val == '0'))) {
626
- return false;
627
- }
628
- }
629
- if (children[2].length == 2) {
630
- if (!(children[2][1].typ == EnumToken.PercentageTokenType || (children[2][1].typ == EnumToken.NumberTokenType && children[2][1].val == '0'))) {
631
- return false;
632
- }
639
+ }
640
+ if (children[2].length == 2) {
641
+ if (!(children[2][1].typ == EnumToken.PercentageTokenType || (children[2][1].typ == EnumToken.NumberTokenType && children[2][1].val == 0))) {
642
+ return false;
633
643
  }
634
- return true;
635
644
  }
636
- return false;
645
+ return true;
637
646
  }
638
- else {
639
- const keywords = ['from', 'none'];
647
+ return false;
648
+ }
649
+ else {
650
+ const keywords = ['from', 'none'];
651
+ // @ts-ignore
652
+ if (['rgb', 'hsl', 'hwb', 'lab', 'lch', 'oklab', 'oklch'].includes(token.val)) {
640
653
  // @ts-ignore
641
- if (['rgb', 'hsl', 'hwb', 'lab', 'lch', 'oklab', 'oklch'].includes(token.val)) {
642
- // @ts-ignore
643
- keywords.push('alpha', ...token.val.slice(-3).split(''));
654
+ keywords.push('alpha', ...token.val.slice(-3).split(''));
655
+ }
656
+ // @ts-ignore
657
+ for (const v of token.chi) {
658
+ if (v.typ == EnumToken.CommaTokenType) {
659
+ isLegacySyntax = true;
644
660
  }
645
- // @ts-ignore
646
- for (const v of token.chi) {
647
- if (v.typ == EnumToken.CommaTokenType) {
648
- isLegacySyntax = true;
661
+ if (v.typ == EnumToken.IdenTokenType) {
662
+ if (!(keywords.includes(v.val) || v.val.toLowerCase() in COLORS_NAMES)) {
663
+ return false;
649
664
  }
650
- if (v.typ == EnumToken.IdenTokenType) {
651
- if (!(keywords.includes(v.val) || v.val.toLowerCase() in COLORS_NAMES)) {
665
+ if (keywords.includes(v.val)) {
666
+ if (isLegacySyntax) {
652
667
  return false;
653
668
  }
654
- if (keywords.includes(v.val)) {
655
- if (isLegacySyntax) {
656
- return false;
657
- }
658
- // @ts-ignore
659
- if (v.val == 'from' && ['rgba', 'hsla'].includes(token.val)) {
660
- return false;
661
- }
669
+ // @ts-ignore
670
+ if (v.val == 'from' && ['rgba', 'hsla'].includes(token.val)) {
671
+ return false;
662
672
  }
663
- continue;
664
- }
665
- if (v.typ == EnumToken.FunctionTokenType && (mathFuncs.includes(v.val) || v.val == 'var' || colorsFunc.includes(v.val))) {
666
- continue;
667
- }
668
- if (![EnumToken.ColorTokenType, EnumToken.IdenTokenType, EnumToken.NumberTokenType, EnumToken.AngleTokenType, EnumToken.PercentageTokenType, EnumToken.CommaTokenType, EnumToken.WhitespaceTokenType, EnumToken.LiteralTokenType].includes(v.typ)) {
669
- return false;
670
673
  }
674
+ continue;
675
+ }
676
+ if (v.typ == EnumToken.FunctionTokenType && (mathFuncs.includes(v.val) || v.val == 'var' || colorsFunc.includes(v.val))) {
677
+ continue;
678
+ }
679
+ if (![EnumToken.ColorTokenType, EnumToken.IdenTokenType, EnumToken.NumberTokenType, EnumToken.AngleTokenType, EnumToken.PercentageTokenType, EnumToken.CommaTokenType, EnumToken.WhitespaceTokenType, EnumToken.LiteralTokenType].includes(v.typ)) {
680
+ return false;
671
681
  }
672
682
  }
673
683
  }
@@ -680,7 +690,7 @@ function parseColor(token) {
680
690
  // @ts-ignore
681
691
  token.typ = EnumToken.ColorTokenType;
682
692
  // @ts-ignore
683
- token.kin = ColorKind[token.val.replaceAll('-', '_').toUpperCase()];
693
+ token.kin = ColorType[token.val.replaceAll('-', '_').toUpperCase()];
684
694
  // @ts-ignore
685
695
  if (token.chi[0].typ == EnumToken.IdenTokenType) {
686
696
  // @ts-ignore
@@ -772,15 +782,6 @@ function isIdent(name) {
772
782
  }
773
783
  return true;
774
784
  }
775
- function isNonPrintable(codepoint) {
776
- // null -> backspace
777
- return (codepoint >= 0 && codepoint <= 0x8) ||
778
- // tab
779
- codepoint == 0xb ||
780
- // delete
781
- codepoint == 0x7f ||
782
- (codepoint >= 0xe && codepoint <= 0x1f);
783
- }
784
785
  function isPseudo(name) {
785
786
  return name.charAt(0) == ':' &&
786
787
  ((name.endsWith('(') && isIdent(name.charAt(1) == ':' ? name.slice(2, -1) : name.slice(1, -1))) ||
@@ -887,7 +888,7 @@ function parseDimension(name) {
887
888
  }
888
889
  const dimension = {
889
890
  typ: EnumToken.DimensionTokenType,
890
- val: name.slice(0, index),
891
+ val: +name.slice(0, index),
891
892
  unit: name.slice(index)
892
893
  };
893
894
  if (isAngle(dimension)) {
@@ -947,4 +948,4 @@ function isWhiteSpace(codepoint) {
947
948
  codepoint == 0xa || codepoint == 0xc || codepoint == 0xd;
948
949
  }
949
950
 
950
- export { colorFontTech, fontFeaturesTech, fontFormat, isAngle, isAtKeyword, isColor, isColorspace, isDigit, isDimension, isFlex, isFrequency, isFunction, isHash, isHexColor, isHueInterpolationMethod, isIdent, isIdentCodepoint, isIdentColor, isIdentStart, isLength, isNewLine, isNonPrintable, isNumber, isPercentage, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolution, isTime, isWhiteSpace, mathFuncs, mediaTypes, mozExtensions, parseColor, parseDimension, pseudoAliasMap, pseudoElements, transformFunctions, webkitExtensions, wildCardFuncs };
951
+ export { colorFontTech, fontFeaturesTech, fontFormat, isAngle, isAtKeyword, isColor, isColorspace, isDigit, isDimension, isFlex, isFrequency, isFunction, isHash, isHexColor, isHueInterpolationMethod, isIdent, isIdentCodepoint, isIdentColor, isIdentStart, isLength, isNewLine, isNumber, isPercentage, isPercentageToken, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolution, isTime, isWhiteSpace, mathFuncs, mediaTypes, mozExtensions, parseColor, parseDimension, pseudoAliasMap, pseudoElements, transformFunctions, webkitExtensions, wildCardFuncs };
@@ -0,0 +1,70 @@
1
+ import { EnumToken } from '../ast/types.js';
2
+ import '../ast/minify.js';
3
+ import '../ast/walk.js';
4
+ import '../parser/parse.js';
5
+ import '../parser/tokenize.js';
6
+ import '../parser/utils/config.js';
7
+ import './color/utils/constants.js';
8
+ import '../renderer/sourcemap/lib/encode.js';
9
+
10
+ function length2Px(value) {
11
+ let result = null;
12
+ if (value.typ == EnumToken.NumberTokenType) {
13
+ result = +value.val;
14
+ }
15
+ else {
16
+ switch (value.unit) {
17
+ case 'cm':
18
+ // @ts-ignore
19
+ result = value.val * 37.8;
20
+ break;
21
+ case 'mm':
22
+ // @ts-ignore
23
+ result = value.val * 3.78;
24
+ break;
25
+ case 'Q':
26
+ // @ts-ignore
27
+ result = value.val * 37.8 / 40;
28
+ break;
29
+ case 'in':
30
+ // @ts-ignore
31
+ result = value.val / 96;
32
+ break;
33
+ case 'pc':
34
+ // @ts-ignore
35
+ result = value.val / 16;
36
+ break;
37
+ case 'pt':
38
+ // @ts-ignore
39
+ result = value.val * 4 / 3;
40
+ break;
41
+ case 'px':
42
+ result = +value.val;
43
+ break;
44
+ }
45
+ }
46
+ return isNaN(result) ? null : result;
47
+ }
48
+ /**
49
+ * minify number
50
+ * @param val
51
+ */
52
+ function minifyNumber(val) {
53
+ val = String(val);
54
+ if (val === '0') {
55
+ return '0';
56
+ }
57
+ const chr = val.charAt(0);
58
+ if (chr == '-') {
59
+ const slice = val.slice(0, 2);
60
+ if (slice == '-0') {
61
+ return val.length == 2 ? '0' : '-' + val.slice(2);
62
+ }
63
+ }
64
+ if (chr == '0') {
65
+ return val.slice(1);
66
+ }
67
+ return val;
68
+ }
69
+
70
+ export { length2Px, minifyNumber };
@@ -4,7 +4,7 @@ import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
- import '../../renderer/color/utils/constants.js';
7
+ import '../../syntax/color/utils/constants.js';
8
8
  import '../../renderer/sourcemap/lib/encode.js';
9
9
  import { consumeWhitespace } from '../utils/whitespace.js';
10
10
  import { splitTokenList } from '../utils/list.js';
@@ -4,7 +4,7 @@ import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
- import '../../renderer/color/utils/constants.js';
7
+ import '../../syntax/color/utils/constants.js';
8
8
  import '../../renderer/sourcemap/lib/encode.js';
9
9
 
10
10
  function validateAtRuleCounterStyle(atRule, options, root) {
@@ -4,7 +4,7 @@ import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
- import '../../renderer/color/utils/constants.js';
7
+ import '../../syntax/color/utils/constants.js';
8
8
  import '../../renderer/sourcemap/lib/encode.js';
9
9
  import { consumeWhitespace } from '../utils/whitespace.js';
10
10
  import { validateAtRuleMediaQueryList } from './media.js';
@@ -4,7 +4,7 @@ import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
- import '../../renderer/color/utils/constants.js';
7
+ import '../../syntax/color/utils/constants.js';
8
8
  import '../../renderer/sourcemap/lib/encode.js';
9
9
  import { consumeWhitespace } from '../utils/whitespace.js';
10
10
  import { splitTokenList } from '../utils/list.js';
@@ -45,7 +45,7 @@ function validateAtRuleDocument(atRule, options, root) {
45
45
  };
46
46
  }
47
47
  // @ts-ignore
48
- if ((t[0].typ != EnumToken.FunctionTokenType && t[0].typ != EnumToken.UrlFunctionTokenType) || !['url', 'url-prefix', 'domain', 'media-document', 'regexp'].some((f) => f.localeCompare(t[0].val, undefined, { sensitivity: 'base' }) == 0)) {
48
+ if ((t[0].typ != EnumToken.FunctionTokenType && t[0].typ != EnumToken.UrlFunctionTokenType) || !['url', 'url-prefix', 'domain', 'media-document', 'regexp'].includes(t[0].val?.toLowerCase?.())) {
49
49
  return {
50
50
  valid: SyntaxValidationResult.Drop,
51
51
  context: [],
@@ -4,7 +4,7 @@ import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
- import '../../renderer/color/utils/constants.js';
7
+ import '../../syntax/color/utils/constants.js';
8
8
  import '../../renderer/sourcemap/lib/encode.js';
9
9
  import { validateFamilyName } from '../syntaxes/family-name.js';
10
10
  import '../syntaxes/complex-selector.js';
@@ -23,7 +23,7 @@ function validateAtRuleFontFeatureValues(atRule, options, root) {
23
23
  tokens: []
24
24
  };
25
25
  }
26
- const result = validateFamilyName(atRule.tokens, atRule);
26
+ const result = validateFamilyName(atRule.tokens);
27
27
  if (result.valid == SyntaxValidationResult.Drop) {
28
28
  return result;
29
29
  }
@@ -4,7 +4,7 @@ import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
- import '../../renderer/color/utils/constants.js';
7
+ import '../../syntax/color/utils/constants.js';
8
8
  import '../../renderer/sourcemap/lib/encode.js';
9
9
  import { validateAtRuleMediaQueryList } from './media.js';
10
10
  import { consumeWhitespace } from '../utils/whitespace.js';
@@ -94,8 +94,7 @@ function validateAtRuleImport(atRule, options, root) {
94
94
  if (tokens.length > 0) {
95
95
  // @ts-ignore
96
96
  if (tokens[0].typ == EnumToken.IdenTokenType) {
97
- // @ts-ignore
98
- if ('layer'.localeCompare(tokens[0].val, undefined, { sensitivity: 'base' }) == 0) {
97
+ if ('layer' === tokens[0].val.toLowerCase()) {
99
98
  tokens.shift();
100
99
  // @ts-ignore
101
100
  if (!consumeWhitespace(tokens)) {
@@ -113,7 +112,7 @@ function validateAtRuleImport(atRule, options, root) {
113
112
  // @ts-ignore
114
113
  else if (tokens[0].typ == EnumToken.FunctionTokenType) {
115
114
  // @ts-ignore
116
- if ('layer'.localeCompare(tokens[0].val, undefined, { sensitivity: 'base' }) == 0) {
115
+ if ('layer' === tokens[0].val.toLowerCase()) {
117
116
  const result = validateLayerName(tokens[0].chi);
118
117
  if (result.valid == SyntaxValidationResult.Drop) {
119
118
  return result;
@@ -122,8 +121,9 @@ function validateAtRuleImport(atRule, options, root) {
122
121
  // @ts-ignore
123
122
  consumeWhitespace(tokens);
124
123
  }
124
+ // tokens[0]?.val
125
125
  // @ts-ignore
126
- if ('supports'.localeCompare(tokens[0]?.val, undefined, { sensitivity: 'base' }) == 0) {
126
+ if ('supports' === tokens[0]?.val?.toLowerCase?.()) {
127
127
  const result = validateAtRuleSupportsConditions(atRule, tokens[0].chi);
128
128
  if (result.valid == SyntaxValidationResult.Drop) {
129
129
  return result;
@@ -4,7 +4,7 @@ import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
- import '../../renderer/color/utils/constants.js';
7
+ import '../../syntax/color/utils/constants.js';
8
8
  import '../../renderer/sourcemap/lib/encode.js';
9
9
  import { consumeWhitespace } from '../utils/whitespace.js';
10
10
 
@@ -19,19 +19,9 @@ function validateAtRuleKeyframes(atRule, options, root) {
19
19
  error: 'expecting at-rule prelude'
20
20
  };
21
21
  }
22
- const tokens = atRule.tokens.slice();
22
+ const tokens = atRule.tokens.filter((t) => t.typ != EnumToken.CommentTokenType).slice();
23
23
  consumeWhitespace(tokens);
24
- if (tokens.length == 0) {
25
- // @ts-ignore
26
- return {
27
- valid: SyntaxValidationResult.Drop,
28
- context: [],
29
- node: atRule,
30
- syntax: '@keyframes',
31
- error: 'expecting at-rule prelude'
32
- };
33
- }
34
- if (![EnumToken.StringTokenType, EnumToken.IdenTokenType].includes(tokens[0].typ)) {
24
+ if (tokens.length == 0 || ![EnumToken.StringTokenType, EnumToken.IdenTokenType].includes(tokens[0].typ)) {
35
25
  // @ts-ignore
36
26
  return {
37
27
  valid: SyntaxValidationResult.Drop,
@@ -4,7 +4,7 @@ import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
- import '../../renderer/color/utils/constants.js';
7
+ import '../../syntax/color/utils/constants.js';
8
8
  import '../../renderer/sourcemap/lib/encode.js';
9
9
  import { validateLayerName } from '../syntaxes/layer-name.js';
10
10
  import '../syntaxes/complex-selector.js';
@@ -4,7 +4,7 @@ import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
- import { generalEnclosedFunc } from '../../renderer/color/utils/constants.js';
7
+ import { generalEnclosedFunc } from '../../syntax/color/utils/constants.js';
8
8
  import '../../renderer/sourcemap/lib/encode.js';
9
9
  import { consumeWhitespace } from '../utils/whitespace.js';
10
10
  import { splitTokenList } from '../utils/list.js';
@@ -4,7 +4,7 @@ import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
- import '../../renderer/color/utils/constants.js';
7
+ import '../../syntax/color/utils/constants.js';
8
8
  import '../../renderer/sourcemap/lib/encode.js';
9
9
  import { consumeWhitespace } from '../utils/whitespace.js';
10
10
  import { validateURL } from '../syntaxes/url.js';
@@ -4,7 +4,7 @@ import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
- import '../../renderer/color/utils/constants.js';
7
+ import '../../syntax/color/utils/constants.js';
8
8
  import '../../renderer/sourcemap/lib/encode.js';
9
9
 
10
10
  function validateAtRulePageMarginBox(atRule, options, root) {
@@ -4,7 +4,7 @@ import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
- import '../../renderer/color/utils/constants.js';
7
+ import '../../syntax/color/utils/constants.js';
8
8
  import '../../renderer/sourcemap/lib/encode.js';
9
9
  import { splitTokenList } from '../utils/list.js';
10
10
 
@@ -5,7 +5,7 @@ import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
7
  import { colorFontTech, fontFeaturesTech, fontFormat } from '../../syntax/syntax.js';
8
- import '../../renderer/color/utils/constants.js';
8
+ import '../../syntax/color/utils/constants.js';
9
9
  import '../../renderer/sourcemap/lib/encode.js';
10
10
  import { consumeWhitespace } from '../utils/whitespace.js';
11
11
  import { splitTokenList } from '../utils/list.js';
@@ -166,7 +166,7 @@ function validateSupportCondition(atRule, token) {
166
166
  if (token.typ == EnumToken.MediaFeatureNotTokenType) {
167
167
  return validateSupportCondition(atRule, token.val);
168
168
  }
169
- if (token.typ == EnumToken.FunctionTokenType && token.val.localeCompare('selector', undefined, { sensitivity: 'base' }) == 0) {
169
+ if (token.typ == EnumToken.FunctionTokenType && 'selector' === token.val.toLowerCase()) {
170
170
  return {
171
171
  valid: SyntaxValidationResult.Valid,
172
172
  context: [],
@@ -223,7 +223,7 @@ function validateSupportFeature(token) {
223
223
  return validateSupportFeature(token.val);
224
224
  }
225
225
  if (token.typ == EnumToken.FunctionTokenType) {
226
- if (token.val.localeCompare('selector', undefined, { sensitivity: 'base' }) == 0) {
226
+ if ('selector' === token.val.toLowerCase()) {
227
227
  return {
228
228
  valid: SyntaxValidationResult.Valid,
229
229
  context: [],
@@ -232,10 +232,10 @@ function validateSupportFeature(token) {
232
232
  error: ''
233
233
  };
234
234
  }
235
- if (token.val.localeCompare('font-tech', undefined, { sensitivity: 'base' }) == 0) {
235
+ if ('font-tech' === token.val.toLowerCase()) {
236
236
  const chi = token.chi.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ));
237
237
  // @ts-ignore
238
- return chi.length == 1 && chi[0].typ == EnumToken.IdenTokenType && colorFontTech.concat(fontFeaturesTech).some((t) => t.localeCompare(chi[0].val, undefined, { sensitivity: 'base' }) == 0) ?
238
+ return chi.length == 1 && chi[0].typ == EnumToken.IdenTokenType && colorFontTech.concat(fontFeaturesTech).includes(chi[0].val.toLowerCase()) ?
239
239
  {
240
240
  valid: SyntaxValidationResult.Valid,
241
241
  context: [],
@@ -251,10 +251,10 @@ function validateSupportFeature(token) {
251
251
  error: 'expected font-tech'
252
252
  };
253
253
  }
254
- if (token.val.localeCompare('font-format', undefined, { sensitivity: 'base' }) == 0) {
254
+ if ('font-format' === token.val.toLowerCase()) {
255
255
  const chi = token.chi.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ));
256
256
  // @ts-ignore
257
- return chi.length == 1 && chi[0].typ == EnumToken.IdenTokenType && fontFormat.some((t) => t.localeCompare(chi[0].val, undefined, { sensitivity: 'base' }) == 0) ?
257
+ return chi.length == 1 && chi[0].typ == EnumToken.IdenTokenType && fontFormat.includes(chi[0].val, toLowerCase()) ?
258
258
  {
259
259
  valid: SyntaxValidationResult.Valid,
260
260
  context: [],
@@ -4,7 +4,7 @@ import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
- import { generalEnclosedFunc } from '../../renderer/color/utils/constants.js';
7
+ import { generalEnclosedFunc } from '../../syntax/color/utils/constants.js';
8
8
  import '../../renderer/sourcemap/lib/encode.js';
9
9
  import { consumeWhitespace } from '../utils/whitespace.js';
10
10
  import { splitTokenList } from '../utils/list.js';
@@ -4,7 +4,7 @@ import '../ast/walk.js';
4
4
  import '../parser/parse.js';
5
5
  import '../parser/tokenize.js';
6
6
  import '../parser/utils/config.js';
7
- import '../renderer/color/utils/constants.js';
7
+ import '../syntax/color/utils/constants.js';
8
8
  import '../renderer/sourcemap/lib/encode.js';
9
9
  import { getSyntaxConfig, getParsedSyntax } from './config.js';
10
10
  import { validateAtRuleMedia } from './at-rules/media.js';
@@ -77,7 +77,7 @@ function validateAtRule(atRule, options, root) {
77
77
  return validateAtRuleCustomMedia(atRule);
78
78
  }
79
79
  if (['position-try', 'property', 'font-palette-values'].includes(atRule.nam)) {
80
- if (!('tokens' in atRule)) {
80
+ if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
81
81
  return {
82
82
  valid: SyntaxValidationResult.Drop,
83
83
  node: atRule,
@@ -21,9 +21,6 @@ function getSyntax(group, key) {
21
21
  key = matches[1] + matches[3];
22
22
  }
23
23
  }
24
- if (!(key in obj)) {
25
- return null;
26
- }
27
24
  }
28
25
  // @ts-ignore
29
26
  obj = obj[key];
@@ -3340,7 +3340,7 @@ var syntaxes = {
3340
3340
  syntax: "cover | contain | entry | exit | entry-crossing | exit-crossing"
3341
3341
  },
3342
3342
  "track-breadth": {
3343
- syntax: "<length-percentage> | <flex> | min-content | max-content | auto"
3343
+ syntax: "<length-percentage> | <flex> | min-content | max-content | auto | <-non-standard-size>"
3344
3344
  },
3345
3345
  "track-list": {
3346
3346
  syntax: "[ <line-names>? [ <track-size> | <track-repeat> ] ]+ <line-names>?"