@tbela99/css-parser 2.3.0 → 2.3.2

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 (115) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +66 -21
  3. package/architecture.png +0 -0
  4. package/dist/ast/arena-node.js +32 -3
  5. package/dist/ast/arena.js +88 -10
  6. package/dist/ast/cache.js +1 -1
  7. package/dist/ast/features/calc.js +1 -1
  8. package/dist/ast/features/if.js +1 -1
  9. package/dist/ast/features/index.js +1 -1
  10. package/dist/ast/features/inlinecssvariables.js +1 -1
  11. package/dist/ast/features/mixin.js +1 -1
  12. package/dist/ast/features/prefix.js +1 -1
  13. package/dist/ast/features/shorthand.js +1 -1
  14. package/dist/ast/features/transform.js +1 -1
  15. package/dist/ast/features/type.js +1 -1
  16. package/dist/ast/math/expression.js +1 -1
  17. package/dist/ast/math/math.js +1 -1
  18. package/dist/ast/minify.js +131 -36
  19. package/dist/ast/mixins/custom-function.js +1 -1
  20. package/dist/ast/mixins/utils.js +1 -1
  21. package/dist/ast/mixins/variables.js +1 -1
  22. package/dist/ast/strings.js +26 -1
  23. package/dist/ast/transform/compute.js +6 -2
  24. package/dist/ast/transform/matrix.js +1 -1
  25. package/dist/ast/transform/minify.js +1 -1
  26. package/dist/ast/transform/perspective.js +1 -1
  27. package/dist/ast/transform/rotate.js +1 -1
  28. package/dist/ast/transform/scale.js +1 -1
  29. package/dist/ast/transform/skew.js +1 -1
  30. package/dist/ast/transform/translate.js +1 -1
  31. package/dist/ast/transform/utils.js +1 -1
  32. package/dist/ast/types.js +22 -2
  33. package/dist/ast/walk.js +1 -1
  34. package/dist/data/properties.json.js +1 -1
  35. package/dist/data/validation.json.js +1 -1
  36. package/dist/fs/resolve.js +1 -1
  37. package/dist/index-umd-web.js +1099 -295
  38. package/dist/index.d.ts +612 -688
  39. package/dist/node.js +14 -8
  40. package/dist/parser/declaration/list.js +8 -5
  41. package/dist/parser/declaration/map.js +1 -1
  42. package/dist/parser/declaration/set.js +1 -1
  43. package/dist/parser/input.js +62 -4
  44. package/dist/parser/linesmap.js +1 -1
  45. package/dist/parser/parse.js +121 -13
  46. package/dist/parser/source.js +1 -1
  47. package/dist/parser/tokenize.js +161 -19
  48. package/dist/parser/utils/angle.js +1 -1
  49. package/dist/parser/utils/at-rule-container.js +1 -1
  50. package/dist/parser/utils/at-rule-font-feature-values.js +1 -1
  51. package/dist/parser/utils/at-rule-generic.js +1 -1
  52. package/dist/parser/utils/at-rule-import.js +1 -1
  53. package/dist/parser/utils/at-rule-media.js +42 -2
  54. package/dist/parser/utils/at-rule-support.js +1 -1
  55. package/dist/parser/utils/at-rule-when-else.js +1 -1
  56. package/dist/parser/utils/at-rule.js +1 -1
  57. package/dist/parser/utils/base64.js +1 -1
  58. package/dist/parser/utils/cache.js +1 -1
  59. package/dist/parser/utils/canonical.js +1 -1
  60. package/dist/parser/utils/codes.js +1 -1
  61. package/dist/parser/utils/config.js +1 -1
  62. package/dist/parser/utils/declaration.js +1 -1
  63. package/dist/parser/utils/eq.js +1 -1
  64. package/dist/parser/utils/hash.js +1 -1
  65. package/dist/parser/utils/selector.js +98 -6
  66. package/dist/parser/utils/text.js +1 -1
  67. package/dist/parser/utils/token.js +1 -1
  68. package/dist/parser/utils/type.js +1 -1
  69. package/dist/printer/lib/codec.js +1 -1
  70. package/dist/printer/render.js +5 -7
  71. package/dist/printer/result.js +18 -3
  72. package/dist/printer/sourcemap.js +1 -1
  73. package/dist/printer/writer.js +1 -1
  74. package/dist/syntax/color/a98rgb.js +1 -1
  75. package/dist/syntax/color/alpha.js +1 -1
  76. package/dist/syntax/color/cmyk.js +1 -1
  77. package/dist/syntax/color/color-mix.js +1 -1
  78. package/dist/syntax/color/color.js +1 -1
  79. package/dist/syntax/color/hex.js +1 -1
  80. package/dist/syntax/color/hsl.js +12 -4
  81. package/dist/syntax/color/hwb.js +9 -3
  82. package/dist/syntax/color/lab.js +1 -1
  83. package/dist/syntax/color/lch.js +1 -1
  84. package/dist/syntax/color/oklab.js +1 -1
  85. package/dist/syntax/color/oklch.js +2 -2
  86. package/dist/syntax/color/p3.js +1 -1
  87. package/dist/syntax/color/prophotorgb.js +1 -1
  88. package/dist/syntax/color/rec2020.js +1 -1
  89. package/dist/syntax/color/relative-color.js +1 -1
  90. package/dist/syntax/color/rgb.js +1 -1
  91. package/dist/syntax/color/srgb.js +3 -2
  92. package/dist/syntax/color/utils/color-type.js +1 -1
  93. package/dist/syntax/color/utils/colorspace.js +1 -1
  94. package/dist/syntax/color/utils/components.js +1 -1
  95. package/dist/syntax/color/utils/distance.js +1 -1
  96. package/dist/syntax/color/utils/make-color.js +1 -1
  97. package/dist/syntax/color/utils/matrix.js +1 -1
  98. package/dist/syntax/color/xyz.js +1 -1
  99. package/dist/syntax/color/xyzd50.js +1 -1
  100. package/dist/syntax/constants.js +2 -2
  101. package/dist/syntax/syntax.js +1 -1
  102. package/dist/types.js +1 -1
  103. package/dist/utils/sync.js +1 -1
  104. package/dist/validation/compiled/builtins.js +1 -1
  105. package/dist/validation/compiled/runtime.js +1 -1
  106. package/dist/validation/compiled/syntaxes.js +1 -1
  107. package/dist/validation/config.js +1 -1
  108. package/dist/validation/first.js +1 -1
  109. package/dist/validation/match.js +77 -4
  110. package/dist/validation/parser/parse.js +1 -1
  111. package/dist/validation/parser/typedef.js +4 -1
  112. package/dist/validation/utils/list.js +1 -1
  113. package/dist/version.js +2 -2
  114. package/dist/web.js +13 -6
  115. package/package.json +15 -6
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.3.0
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  (function (global, factory) {
@@ -1014,6 +1014,26 @@
1014
1014
  */
1015
1015
  WalkerEvent[WalkerEvent["Leave"] = 2] = "Leave";
1016
1016
  })(exports.WalkerEvent || (exports.WalkerEvent = {}));
1017
+ /**
1018
+ * Merge of the adjacent rules, see {@link ParserOptions.mergeRules}. `true` is a shortcut for
1019
+ * {@link MergeRulesEnum.All}, `false` for {@link MergeRulesEnum.None}
1020
+ */
1021
+ exports.MergeRulesEnum = void 0;
1022
+ (function (MergeRulesEnum) {
1023
+ /**
1024
+ * the rules are not merged
1025
+ */
1026
+ MergeRulesEnum[MergeRulesEnum["None"] = 0] = "None";
1027
+ /**
1028
+ * only the rules that have the same declarations are merged, the size of the output is not computed:
1029
+ * `.a{color:red}.b{color:red}` is merged into `.a,.b{color:red}`
1030
+ */
1031
+ MergeRulesEnum[MergeRulesEnum["Identical"] = 1] = "Identical";
1032
+ /**
1033
+ * the rules that share declarations are merged when the output is smaller
1034
+ */
1035
+ MergeRulesEnum[MergeRulesEnum["All"] = 2] = "All";
1036
+ })(exports.MergeRulesEnum || (exports.MergeRulesEnum = {}));
1017
1037
 
1018
1038
  /**
1019
1039
  * push the direct value tokens of a token onto a stack, from the linked lists: the token list, then the fields (the
@@ -1419,8 +1439,9 @@
1419
1439
  */
1420
1440
  [ARENAID];
1421
1441
  /**
1422
- * @param arena
1423
- * @param id
1442
+ * create a view of a node of the arena. the view reads and writes the arena: it holds no data
1443
+ * @param arena the arena that holds the node
1444
+ * @param id the node or token id
1424
1445
  */
1425
1446
  constructor(arena, id) {
1426
1447
  this[ARENA] = arena;
@@ -1432,6 +1453,9 @@
1432
1453
  get typ() {
1433
1454
  return this[ARENA].dataTypes[this[ARENAID]];
1434
1455
  }
1456
+ /**
1457
+ * Set the node or token type
1458
+ */
1435
1459
  set typ(typ) {
1436
1460
  this[ARENA].dataTypes[this[ARENAID]] = typ;
1437
1461
  }
@@ -1450,6 +1474,7 @@
1450
1474
  return arena.name[id] === 0 ? undefined : arena.resolveString(arena.name[id]);
1451
1475
  }
1452
1476
  /**
1477
+ * Set the at-rule / declaration name, token name. undefined for the other nodes
1453
1478
  *
1454
1479
  * @param nam
1455
1480
  */
@@ -1468,6 +1493,7 @@
1468
1493
  : undefined;
1469
1494
  }
1470
1495
  /**
1496
+ * Set the rule selector. undefined for the other nodes
1471
1497
  *
1472
1498
  * @param sel
1473
1499
  */
@@ -1516,6 +1542,7 @@
1516
1542
  : undefined;
1517
1543
  }
1518
1544
  /**
1545
+ * Set the value, see the getter: a string, a number, a token or a list of tokens depending on the type of the node
1519
1546
  *
1520
1547
  * @param val
1521
1548
  */
@@ -1570,6 +1597,8 @@
1570
1597
  return listViews(arena, arena.firstToken[id]);
1571
1598
  }
1572
1599
  /**
1600
+ * Set the children: the child nodes of a stylesheet, a rule or an at-rule with a block, the tokens of a function
1601
+ * token (arguments), a parentheses token, ... undefined when the node has no children
1573
1602
  *
1574
1603
  * @param chi
1575
1604
  */
@@ -1607,6 +1636,7 @@
1607
1636
  : listViews(arena, arena.firstToken[id]);
1608
1637
  }
1609
1638
  /**
1639
+ * Set the prelude tokens of an at-rule, selector tokens of a rule. null when the node has no prelude tokens
1610
1640
  *
1611
1641
  * @param tokens
1612
1642
  */
@@ -1625,6 +1655,7 @@
1625
1655
  : arena.resolveString(arena.unit[id]);
1626
1656
  }
1627
1657
  /**
1658
+ * Set the unit of a dimension, calendar (`cal`) of a color, attribute (`attr`) of a match expression
1628
1659
  *
1629
1660
  * @param unit
1630
1661
  */
@@ -1641,6 +1672,9 @@
1641
1672
  ? undefined
1642
1673
  : arena.resolveString(arena.unit[id]);
1643
1674
  }
1675
+ /**
1676
+ * Set the color space of a color
1677
+ */
1644
1678
  set cal(cal) {
1645
1679
  this[ARENA].setUnitString(this[ARENAID], cal ?? null);
1646
1680
  }
@@ -1654,6 +1688,9 @@
1654
1688
  ? undefined
1655
1689
  : arena.resolveString(arena.unit[id]);
1656
1690
  }
1691
+ /**
1692
+ * Set the attribute of a match expression
1693
+ */
1657
1694
  set attr(attr) {
1658
1695
  this[ARENA].setUnitString(this[ARENAID], attr ?? null);
1659
1696
  }
@@ -1667,6 +1704,9 @@
1667
1704
  ? undefined
1668
1705
  : arena.colorType[id];
1669
1706
  }
1707
+ /**
1708
+ * Set the color type of a color token
1709
+ */
1670
1710
  set kin(kin) {
1671
1711
  this[ARENA].colorType[this[ARENAID]] = kin ?? exports.ColorType.NONE;
1672
1712
  }
@@ -1679,6 +1719,7 @@
1679
1719
  return arena.dataTypes[id] === exports.EnumToken.UnaryExpressionTokenType ? arena.numericValue[id] : undefined;
1680
1720
  }
1681
1721
  /**
1722
+ * Set the sign of a unary expression
1682
1723
  *
1683
1724
  * @param sign
1684
1725
  */
@@ -1696,6 +1737,7 @@
1696
1737
  : this.getField("op");
1697
1738
  }
1698
1739
  /**
1740
+ * Set the operator: the operator of a binary expression, the operator tokens of a structured token
1699
1741
  *
1700
1742
  * @param op
1701
1743
  */
@@ -1716,6 +1758,7 @@
1716
1758
  return this.getField("op1");
1717
1759
  }
1718
1760
  /**
1761
+ * Set the first operator of a media range query
1719
1762
  *
1720
1763
  * @param op
1721
1764
  */
@@ -1729,6 +1772,7 @@
1729
1772
  return this.getField("op2");
1730
1773
  }
1731
1774
  /**
1775
+ * Set the second operator of a media range query
1732
1776
  *
1733
1777
  * @param op
1734
1778
  */
@@ -1747,6 +1791,7 @@
1747
1791
  return this.getField("l");
1748
1792
  }
1749
1793
  /**
1794
+ * Set the left hand side of a structured token, numerator of a fraction
1750
1795
  *
1751
1796
  * @param l
1752
1797
  */
@@ -1776,6 +1821,7 @@
1776
1821
  return this.getField("r");
1777
1822
  }
1778
1823
  /**
1824
+ * Set the right hand side of a structured token, denominator of a fraction
1779
1825
  *
1780
1826
  * @param r
1781
1827
  */
@@ -1802,6 +1848,7 @@
1802
1848
  return loc == null ? null : Object.freeze(loc);
1803
1849
  }
1804
1850
  /**
1851
+ * Set the source location. null when the node has no location
1805
1852
  *
1806
1853
  * @param loc
1807
1854
  */
@@ -1815,6 +1862,7 @@
1815
1862
  return this[ARENA].flags[this[ARENAID]] & exports.EnumAstNodeStatus.StateMask;
1816
1863
  }
1817
1864
  /**
1865
+ * Set the validation state
1818
1866
  *
1819
1867
  * @param state
1820
1868
  */
@@ -1830,6 +1878,7 @@
1830
1878
  return errors == null ? null : Object.freeze(errors.slice());
1831
1879
  }
1832
1880
  /**
1881
+ * Set the validation errors. null when the node has no errors
1833
1882
  *
1834
1883
  * @param errors
1835
1884
  */
@@ -8472,7 +8521,7 @@
8472
8521
  };
8473
8522
 
8474
8523
  /**
8475
- * Used by the validation parser
8524
+ * key of the position of a validation token in the syntax, see {@link ValidationToken}
8476
8525
  */
8477
8526
  const LOC = Symbol.for("loc");
8478
8527
  /**
@@ -9458,7 +9507,7 @@
9458
9507
  }
9459
9508
  function hwb2oklchvalues(arena, token) {
9460
9509
  const values = hwb2oklabvalues(arena, token);
9461
- return labvalues2lchvalues(values[0], values[1], values[2], values[3]);
9510
+ return values == null ? null : labvalues2lchvalues(values[0], values[1], values[2], values[3]);
9462
9511
  }
9463
9512
  function cmyk2oklchvalues(arena, token) {
9464
9513
  const values = cmyk2srgbvalues(arena, token);
@@ -10037,11 +10086,17 @@
10037
10086
  return arena.createColor("hwb", exports.ColorType.HWB, chi);
10038
10087
  }
10039
10088
  function rgb2hwbvalues(arena, token) {
10040
- const values = getColorComponents(arena, token).map((t, index) => {
10089
+ const components = getColorComponents(arena, token);
10090
+ // the components cannot be computed: var(), ...
10091
+ if (components == null) {
10092
+ return null;
10093
+ }
10094
+ const values = components.map((t, index) => {
10041
10095
  if (index === 3) {
10042
10096
  return getNumber(arena, t);
10043
10097
  }
10044
- return getNumber(arena, t) / 255;
10098
+ // the components are from 0 to 255: 100% is 255
10099
+ return ((arena.dataTypes[t] === exports.EnumToken.PercentageTokenType ? 255 : 1) * getNumber(arena, t)) / 255;
10045
10100
  });
10046
10101
  // @ts-ignore
10047
10102
  return srgb2hwb(values[0], values[1], values[2], values[3]);
@@ -10252,8 +10307,9 @@
10252
10307
  }
10253
10308
  function hwb2srgbvalues(arena, token) {
10254
10309
  const { h, w, b, a } = hwbvalues(arena, token) ?? {};
10310
+ // the components cannot be computed: var(), ...
10255
10311
  if (h == null || w == null || b == null) {
10256
- return [];
10312
+ return null;
10257
10313
  }
10258
10314
  const rgb = hwb2srgb(h, w, b);
10259
10315
  if (a != null && a !== 1) {
@@ -10861,6 +10917,14 @@
10861
10917
  }
10862
10918
  return arena.createColor("hsl", exports.ColorType.HSL, chi);
10863
10919
  }
10920
+ /**
10921
+ * value of a red, green or blue component of an `rgb()` color, from 0 to 255: `100%` is 255
10922
+ * @param arena
10923
+ * @param token
10924
+ */
10925
+ function rgbChannel(arena, token) {
10926
+ return (arena.dataTypes[token] === exports.EnumToken.PercentageTokenType ? 255 : 1) * getNumber(arena, token);
10927
+ }
10864
10928
  function rgb2hslvalues(arena, token) {
10865
10929
  const chi = getColorComponents(arena, token);
10866
10930
  if (chi == null || chi.length < 3) {
@@ -10869,15 +10933,15 @@
10869
10933
  // @ts-ignore
10870
10934
  let t = chi[0];
10871
10935
  // @ts-ignore
10872
- let r = getNumber(arena, t);
10936
+ let r = rgbChannel(arena, t);
10873
10937
  // @ts-ignore
10874
10938
  t = chi[1];
10875
10939
  // @ts-ignore
10876
- let g = getNumber(arena, t);
10940
+ let g = rgbChannel(arena, t);
10877
10941
  // @ts-ignore
10878
10942
  t = chi[2];
10879
10943
  // @ts-ignore
10880
- let b = getNumber(arena, t);
10944
+ let b = rgbChannel(arena, t);
10881
10945
  // @ts-ignore
10882
10946
  let a = null;
10883
10947
  if (chi.length === 4) {
@@ -12851,7 +12915,10 @@
12851
12915
  return arena.createColor("device-cmyk", exports.ColorType.DEVICE_CMYK, chi);
12852
12916
  }
12853
12917
 
12854
- var ValidationTokenEnum;
12918
+ /**
12919
+ * type of a validation token: a node of the parsed value definition syntax, see {@link parseSyntax}
12920
+ */
12921
+ exports.ValidationTokenEnum = void 0;
12855
12922
  (function (ValidationTokenEnum) {
12856
12923
  ValidationTokenEnum[ValidationTokenEnum["Root"] = 0] = "Root";
12857
12924
  ValidationTokenEnum[ValidationTokenEnum["Keyword"] = 1] = "Keyword";
@@ -12926,7 +12993,7 @@
12926
12993
  ValidationTokenEnum[ValidationTokenEnum["Dimension"] = 45] = "Dimension";
12927
12994
  ValidationTokenEnum[ValidationTokenEnum["DisallowWhitespace"] = 46] = "DisallowWhitespace";
12928
12995
  ValidationTokenEnum[ValidationTokenEnum["Colon"] = 47] = "Colon";
12929
- })(ValidationTokenEnum || (ValidationTokenEnum = {}));
12996
+ })(exports.ValidationTokenEnum || (exports.ValidationTokenEnum = {}));
12930
12997
  /**
12931
12998
  * Keys of the validation config object
12932
12999
  */
@@ -12961,37 +13028,37 @@
12961
13028
  })(MediaFeatureType || (MediaFeatureType = {}));
12962
13029
 
12963
13030
  const SymbolsMapTokens = {
12964
- "&&": ValidationTokenEnum.Ampersand,
12965
- "|": ValidationTokenEnum.Pipe,
12966
- "† ": ValidationTokenEnum.DisallowWhitespace,
12967
- "||": ValidationTokenEnum.Column,
12968
- "*": ValidationTokenEnum.Star,
12969
- ",": ValidationTokenEnum.Comma,
12970
- "/": ValidationTokenEnum.Separator,
12971
- "+": ValidationTokenEnum.Plus,
12972
- ";": ValidationTokenEnum.SemiColon,
12973
- "(": ValidationTokenEnum.OpenParenthesis,
12974
- ")": ValidationTokenEnum.CloseParenthesis,
12975
- "[": ValidationTokenEnum.OpenBracket,
12976
- "]": ValidationTokenEnum.CloseBracket,
12977
- "{": ValidationTokenEnum.OpenCurlyBrace,
12978
- "}": ValidationTokenEnum.CloseCurlyBrace,
12979
- "?": ValidationTokenEnum.QuestionMark,
12980
- "!": ValidationTokenEnum.Exclamation,
12981
- "#": ValidationTokenEnum.HashMark,
12982
- "<": ValidationTokenEnum.LessThan,
12983
- ">": ValidationTokenEnum.GreaterThan,
12984
- " ": ValidationTokenEnum.Whitespace,
12985
- "\t": ValidationTokenEnum.Whitespace,
12986
- "\r": ValidationTokenEnum.Whitespace,
12987
- "\n": ValidationTokenEnum.Whitespace,
12988
- "\f": ValidationTokenEnum.Whitespace,
13031
+ "&&": exports.ValidationTokenEnum.Ampersand,
13032
+ "|": exports.ValidationTokenEnum.Pipe,
13033
+ "† ": exports.ValidationTokenEnum.DisallowWhitespace,
13034
+ "||": exports.ValidationTokenEnum.Column,
13035
+ "*": exports.ValidationTokenEnum.Star,
13036
+ ",": exports.ValidationTokenEnum.Comma,
13037
+ "/": exports.ValidationTokenEnum.Separator,
13038
+ "+": exports.ValidationTokenEnum.Plus,
13039
+ ";": exports.ValidationTokenEnum.SemiColon,
13040
+ "(": exports.ValidationTokenEnum.OpenParenthesis,
13041
+ ")": exports.ValidationTokenEnum.CloseParenthesis,
13042
+ "[": exports.ValidationTokenEnum.OpenBracket,
13043
+ "]": exports.ValidationTokenEnum.CloseBracket,
13044
+ "{": exports.ValidationTokenEnum.OpenCurlyBrace,
13045
+ "}": exports.ValidationTokenEnum.CloseCurlyBrace,
13046
+ "?": exports.ValidationTokenEnum.QuestionMark,
13047
+ "!": exports.ValidationTokenEnum.Exclamation,
13048
+ "#": exports.ValidationTokenEnum.HashMark,
13049
+ "<": exports.ValidationTokenEnum.LessThan,
13050
+ ">": exports.ValidationTokenEnum.GreaterThan,
13051
+ " ": exports.ValidationTokenEnum.Whitespace,
13052
+ "\t": exports.ValidationTokenEnum.Whitespace,
13053
+ "\r": exports.ValidationTokenEnum.Whitespace,
13054
+ "\n": exports.ValidationTokenEnum.Whitespace,
13055
+ "\f": exports.ValidationTokenEnum.Whitespace,
12989
13056
  // '∞'
12990
- "\u221e": ValidationTokenEnum.InfinityToken,
13057
+ "\u221e": exports.ValidationTokenEnum.InfinityToken,
12991
13058
  };
12992
13059
  const makeBinaryOp = new Map([
12993
- [ValidationTokenEnum.Column, ValidationTokenEnum.ColumnToken],
12994
- [ValidationTokenEnum.Ampersand, ValidationTokenEnum.AmpersandToken],
13060
+ [exports.ValidationTokenEnum.Column, exports.ValidationTokenEnum.ColumnToken],
13061
+ [exports.ValidationTokenEnum.Ampersand, exports.ValidationTokenEnum.AmpersandToken],
12995
13062
  ]);
12996
13063
  /**
12997
13064
  * single character symbols, by character code
@@ -13078,7 +13145,7 @@
13078
13145
  function getTokenType(token, loc) {
13079
13146
  if (token === "<an+b>") {
13080
13147
  return {
13081
- typ: ValidationTokenEnum.PropertyType,
13148
+ typ: exports.ValidationTokenEnum.PropertyType,
13082
13149
  val: token.slice(1, -1),
13083
13150
  [LOC]: loc,
13084
13151
  };
@@ -13087,7 +13154,7 @@
13087
13154
  // " or '
13088
13155
  if (first === 34 || first === 39) {
13089
13156
  return {
13090
- typ: ValidationTokenEnum.StringToken,
13157
+ typ: exports.ValidationTokenEnum.StringToken,
13091
13158
  val: token,
13092
13159
  [LOC]: loc,
13093
13160
  };
@@ -13095,7 +13162,7 @@
13095
13162
  // integer, optionally negative: range bounds such as `<integer [-∞,-1]>`
13096
13163
  if (isDigits(token) || (first === 45 && isDigits(token.slice(1)))) {
13097
13164
  return {
13098
- typ: ValidationTokenEnum.Number,
13165
+ typ: exports.ValidationTokenEnum.Number,
13099
13166
  val: Number(token),
13100
13167
  [LOC]: loc,
13101
13168
  };
@@ -13104,7 +13171,7 @@
13104
13171
  if (dimension) {
13105
13172
  // @ts-expect-error
13106
13173
  return {
13107
- typ: ValidationTokenEnum.Dimension,
13174
+ typ: exports.ValidationTokenEnum.Dimension,
13108
13175
  unit: exports.EnumToken[dimension.typ],
13109
13176
  val: dimension.val,
13110
13177
  unitText: dimension.unit,
@@ -13113,7 +13180,7 @@
13113
13180
  }
13114
13181
  if (isPseudo(token)) {
13115
13182
  return {
13116
- typ: ValidationTokenEnum.PseudoClassToken,
13183
+ typ: exports.ValidationTokenEnum.PseudoClassToken,
13117
13184
  val: token,
13118
13185
  [LOC]: loc,
13119
13186
  };
@@ -13121,31 +13188,31 @@
13121
13188
  // @
13122
13189
  if (first === 64 && isIdent(token.slice(1))) {
13123
13190
  return {
13124
- typ: ValidationTokenEnum.AtRule,
13191
+ typ: exports.ValidationTokenEnum.AtRule,
13125
13192
  val: token.slice(1),
13126
13193
  [LOC]: loc,
13127
13194
  };
13128
13195
  }
13129
13196
  return {
13130
- typ: ValidationTokenEnum.Keyword,
13197
+ typ: exports.ValidationTokenEnum.Keyword,
13131
13198
  val: token,
13132
13199
  [LOC]: loc,
13133
13200
  };
13134
13201
  }
13135
13202
  function trimSyntaxArray(tokens) {
13136
- while (tokens[0]?.typ === ValidationTokenEnum.Whitespace) {
13203
+ while (tokens[0]?.typ === exports.ValidationTokenEnum.Whitespace) {
13137
13204
  tokens.shift();
13138
13205
  }
13139
- while (tokens[tokens.length - 1]?.typ === ValidationTokenEnum.Whitespace) {
13206
+ while (tokens[tokens.length - 1]?.typ === exports.ValidationTokenEnum.Whitespace) {
13140
13207
  tokens.pop();
13141
13208
  }
13142
13209
  let i = 0;
13143
13210
  for (; i < tokens.length; i++) {
13144
- if (tokens[i].typ === ValidationTokenEnum.Comma) {
13145
- if (i + 1 < tokens.length && tokens[i + 1].typ === ValidationTokenEnum.Whitespace) {
13211
+ if (tokens[i].typ === exports.ValidationTokenEnum.Comma) {
13212
+ if (i + 1 < tokens.length && tokens[i + 1].typ === exports.ValidationTokenEnum.Whitespace) {
13146
13213
  tokens.splice(i + 1, 1);
13147
13214
  }
13148
- if (i > 0 && tokens[i - 1].typ === ValidationTokenEnum.Whitespace) {
13215
+ if (i > 0 && tokens[i - 1].typ === exports.ValidationTokenEnum.Whitespace) {
13149
13216
  tokens.splice(--i, 1);
13150
13217
  }
13151
13218
  }
@@ -13256,9 +13323,9 @@
13256
13323
  }
13257
13324
  type = symbolTypes.get(code) ?? null;
13258
13325
  if (type != null) {
13259
- if (type === ValidationTokenEnum.Whitespace) {
13326
+ if (type === exports.ValidationTokenEnum.Whitespace) {
13260
13327
  let k = i;
13261
- while (k + 1 < length && symbolTypes.get(syntax.charCodeAt(k + 1)) === ValidationTokenEnum.Whitespace) {
13328
+ while (k + 1 < length && symbolTypes.get(syntax.charCodeAt(k + 1)) === exports.ValidationTokenEnum.Whitespace) {
13262
13329
  k++;
13263
13330
  }
13264
13331
  if (k !== i) {
@@ -13288,7 +13355,7 @@
13288
13355
  clear();
13289
13356
  }
13290
13357
  tokens.push({
13291
- typ: ValidationTokenEnum.Colon,
13358
+ typ: exports.ValidationTokenEnum.Colon,
13292
13359
  [LOC]: loc,
13293
13360
  });
13294
13361
  break;
@@ -13321,7 +13388,7 @@
13321
13388
  tokens.push(getTokenType(buffer(), startToken()));
13322
13389
  }
13323
13390
  tokens.push({
13324
- typ: ValidationTokenEnum.EOF,
13391
+ typ: exports.ValidationTokenEnum.EOF,
13325
13392
  [LOC]: { ind: posInd, lin: posLin, col: posCol },
13326
13393
  });
13327
13394
  position.ind = posInd;
@@ -13347,30 +13414,30 @@
13347
13414
  for (const token of iterator) {
13348
13415
  tokens.push(token);
13349
13416
  switch (token.typ) {
13350
- case ValidationTokenEnum.EOF:
13351
- if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
13417
+ case exports.ValidationTokenEnum.EOF:
13418
+ if (stack.at(-1)?.typ === exports.ValidationTokenEnum.PipeToken) {
13352
13419
  let index = tokens.lastIndexOf(stack.at(-1));
13353
13420
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
13354
13421
  stack.pop();
13355
13422
  }
13356
- else if (stack.at(-1)?.typ === ValidationTokenEnum.AmpersandToken) {
13423
+ else if (stack.at(-1)?.typ === exports.ValidationTokenEnum.AmpersandToken) {
13357
13424
  let index = tokens.lastIndexOf(stack.at(-1));
13358
13425
  stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
13359
13426
  stack.pop();
13360
13427
  }
13361
- else if (stack.at(-1)?.typ === ValidationTokenEnum.ColumnToken) {
13428
+ else if (stack.at(-1)?.typ === exports.ValidationTokenEnum.ColumnToken) {
13362
13429
  let index = tokens.lastIndexOf(stack.at(-1));
13363
13430
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
13364
13431
  stack.pop();
13365
13432
  }
13366
13433
  tokens.pop();
13367
13434
  break;
13368
- case ValidationTokenEnum.Pipe:
13435
+ case exports.ValidationTokenEnum.Pipe:
13369
13436
  {
13370
- while (stack.at(-1)?.typ === ValidationTokenEnum.AmpersandToken ||
13371
- stack.at(-1)?.typ === ValidationTokenEnum.ColumnToken) {
13437
+ while (stack.at(-1)?.typ === exports.ValidationTokenEnum.AmpersandToken ||
13438
+ stack.at(-1)?.typ === exports.ValidationTokenEnum.ColumnToken) {
13372
13439
  let index = tokens.lastIndexOf(stack.at(-1));
13373
- if (stack.at(-1)?.typ === ValidationTokenEnum.AmpersandToken) {
13440
+ if (stack.at(-1)?.typ === exports.ValidationTokenEnum.AmpersandToken) {
13374
13441
  stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
13375
13442
  }
13376
13443
  else {
@@ -13379,9 +13446,9 @@
13379
13446
  stack.pop();
13380
13447
  }
13381
13448
  let index = stack.length === 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
13382
- if (stack.at(-1)?.typ !== ValidationTokenEnum.PipeToken) {
13449
+ if (stack.at(-1)?.typ !== exports.ValidationTokenEnum.PipeToken) {
13383
13450
  stack.push(Object.assign(token, {
13384
- typ: ValidationTokenEnum.PipeToken,
13451
+ typ: exports.ValidationTokenEnum.PipeToken,
13385
13452
  chi: [trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2))],
13386
13453
  }));
13387
13454
  break;
@@ -13390,11 +13457,11 @@
13390
13457
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 1)));
13391
13458
  }
13392
13459
  break;
13393
- case ValidationTokenEnum.Ampersand:
13460
+ case exports.ValidationTokenEnum.Ampersand:
13394
13461
  {
13395
13462
  let index = stack.length === 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
13396
13463
  if (stack.at(-1)?.typ === makeBinaryOp.get(token.typ)) {
13397
- if (token.typ === ValidationTokenEnum.Ampersand) {
13464
+ if (token.typ === exports.ValidationTokenEnum.Ampersand) {
13398
13465
  stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
13399
13466
  stack.pop();
13400
13467
  stack.push(Object.assign(token, {
@@ -13426,7 +13493,7 @@
13426
13493
  }
13427
13494
  }
13428
13495
  break;
13429
- case ValidationTokenEnum.Column:
13496
+ case exports.ValidationTokenEnum.Column:
13430
13497
  {
13431
13498
  let index = stack.length === 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
13432
13499
  if (stack.at(-1)?.typ === makeBinaryOp.get(token.typ)) {
@@ -13449,18 +13516,18 @@
13449
13516
  }
13450
13517
  }
13451
13518
  break;
13452
- case ValidationTokenEnum.OpenParenthesis:
13453
- if (tokens.at(-2)?.typ === ValidationTokenEnum.Keyword) {
13519
+ case exports.ValidationTokenEnum.OpenParenthesis:
13520
+ if (tokens.at(-2)?.typ === exports.ValidationTokenEnum.Keyword) {
13454
13521
  stack.push(Object.assign(tokens.at(-2), {
13455
- typ: ValidationTokenEnum.Function,
13522
+ typ: exports.ValidationTokenEnum.Function,
13456
13523
  chi: [],
13457
13524
  }));
13458
13525
  tokens.pop();
13459
13526
  break;
13460
13527
  }
13461
- if (tokens.at(-2)?.typ === ValidationTokenEnum.PseudoClassToken) {
13528
+ if (tokens.at(-2)?.typ === exports.ValidationTokenEnum.PseudoClassToken) {
13462
13529
  stack.push(Object.assign(tokens.at(-2), {
13463
- typ: ValidationTokenEnum.PseudoClassFunctionToken,
13530
+ typ: exports.ValidationTokenEnum.PseudoClassFunctionToken,
13464
13531
  chi: [],
13465
13532
  }));
13466
13533
  tokens.pop();
@@ -13468,14 +13535,14 @@
13468
13535
  }
13469
13536
  stack.push(token);
13470
13537
  break;
13471
- case ValidationTokenEnum.CloseParenthesis:
13472
- if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
13538
+ case exports.ValidationTokenEnum.CloseParenthesis:
13539
+ if (stack.at(-1)?.typ === exports.ValidationTokenEnum.PipeToken) {
13473
13540
  let index = tokens.lastIndexOf(stack.at(-1));
13474
13541
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
13475
13542
  stack.pop();
13476
13543
  }
13477
- if (stack.at(-1)?.typ === ValidationTokenEnum.OpenParenthesis ||
13478
- (stack.at(-1)?.typ === ValidationTokenEnum.PropertyType &&
13544
+ if (stack.at(-1)?.typ === exports.ValidationTokenEnum.OpenParenthesis ||
13545
+ (stack.at(-1)?.typ === exports.ValidationTokenEnum.PropertyType &&
13479
13546
  stack.at(-1).val === "function-token")) {
13480
13547
  stack.pop();
13481
13548
  }
@@ -13486,13 +13553,13 @@
13486
13553
  // );
13487
13554
  // stack.pop();
13488
13555
  // }
13489
- else if (stack.at(-1)?.typ === ValidationTokenEnum.AmpersandToken) {
13556
+ else if (stack.at(-1)?.typ === exports.ValidationTokenEnum.AmpersandToken) {
13490
13557
  let index = tokens.lastIndexOf(stack.at(-1));
13491
13558
  stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
13492
13559
  stack.pop();
13493
13560
  }
13494
- if (stack.at(-1)?.typ === ValidationTokenEnum.Function ||
13495
- stack.at(-1)?.typ === ValidationTokenEnum.PseudoClassFunctionToken) {
13561
+ if (stack.at(-1)?.typ === exports.ValidationTokenEnum.Function ||
13562
+ stack.at(-1)?.typ === exports.ValidationTokenEnum.PseudoClassFunctionToken) {
13496
13563
  let index = tokens.lastIndexOf(stack.at(-1));
13497
13564
  tokens.pop();
13498
13565
  stack.at(-1).chi =
@@ -13500,11 +13567,11 @@
13500
13567
  stack.pop();
13501
13568
  }
13502
13569
  break;
13503
- case ValidationTokenEnum.GreaterThan:
13504
- if (tokens[tokens.length - 3]?.typ === ValidationTokenEnum.LessThan) {
13505
- if (tokens[tokens.length - 2]?.typ === ValidationTokenEnum.Keyword) {
13570
+ case exports.ValidationTokenEnum.GreaterThan:
13571
+ if (tokens[tokens.length - 3]?.typ === exports.ValidationTokenEnum.LessThan) {
13572
+ if (tokens[tokens.length - 2]?.typ === exports.ValidationTokenEnum.Keyword) {
13506
13573
  Object.assign(tokens[tokens.length - 3], {
13507
- typ: ValidationTokenEnum.PropertyType,
13574
+ typ: exports.ValidationTokenEnum.PropertyType,
13508
13575
  val: tokens[tokens.length - 2].val,
13509
13576
  });
13510
13577
  if ("range" in tokens[tokens.length - 2]) {
@@ -13516,40 +13583,40 @@
13516
13583
  stack.push(tokens.at(-1));
13517
13584
  }
13518
13585
  }
13519
- else if (tokens[tokens.length - 2]?.typ === ValidationTokenEnum.StringToken) {
13586
+ else if (tokens[tokens.length - 2]?.typ === exports.ValidationTokenEnum.StringToken) {
13520
13587
  Object.assign(tokens[tokens.length - 3], {
13521
- typ: ValidationTokenEnum.DeclarationType,
13588
+ typ: exports.ValidationTokenEnum.DeclarationType,
13522
13589
  val: tokens[tokens.length - 2].val.slice(1, -1),
13523
13590
  });
13524
13591
  tokens.splice(tokens.length - 2, 2);
13525
13592
  }
13526
- else if (tokens[tokens.length - 2]?.typ === ValidationTokenEnum.Function) {
13593
+ else if (tokens[tokens.length - 2]?.typ === exports.ValidationTokenEnum.Function) {
13527
13594
  Object.assign(tokens[tokens.length - 3], {
13528
- typ: ValidationTokenEnum.FunctionDefinition,
13595
+ typ: exports.ValidationTokenEnum.FunctionDefinition,
13529
13596
  val: tokens[tokens.length - 2].val,
13530
13597
  });
13531
13598
  tokens.splice(tokens.length - 2, 2);
13532
13599
  }
13533
13600
  }
13534
13601
  break;
13535
- case ValidationTokenEnum.OpenBracket:
13602
+ case exports.ValidationTokenEnum.OpenBracket:
13536
13603
  stack.push(token);
13537
13604
  break;
13538
- case ValidationTokenEnum.CloseBracket:
13605
+ case exports.ValidationTokenEnum.CloseBracket:
13539
13606
  while (true) {
13540
- if (stack.at(-1).typ === ValidationTokenEnum.AmpersandToken) {
13607
+ if (stack.at(-1).typ === exports.ValidationTokenEnum.AmpersandToken) {
13541
13608
  let index = tokens.lastIndexOf(stack.at(-1));
13542
13609
  stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
13543
13610
  stack.pop();
13544
13611
  continue;
13545
13612
  }
13546
- else if (stack.at(-1).typ === ValidationTokenEnum.ColumnToken) {
13613
+ else if (stack.at(-1).typ === exports.ValidationTokenEnum.ColumnToken) {
13547
13614
  let index = tokens.lastIndexOf(stack.at(-1));
13548
13615
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
13549
13616
  stack.pop();
13550
13617
  continue;
13551
13618
  }
13552
- if (stack.at(-1).typ === ValidationTokenEnum.PipeToken) {
13619
+ if (stack.at(-1).typ === exports.ValidationTokenEnum.PipeToken) {
13553
13620
  let index = tokens.lastIndexOf(stack.at(-1));
13554
13621
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
13555
13622
  stack.pop();
@@ -13565,24 +13632,24 @@
13565
13632
  {
13566
13633
  let index = tokens.lastIndexOf(stack.at(-1));
13567
13634
  // the lower bound of a range may be '-∞': <integer [-∞,-1]>
13568
- const isNegativeInfinity = tokens[index + 1]?.typ === ValidationTokenEnum.Keyword &&
13635
+ const isNegativeInfinity = tokens[index + 1]?.typ === exports.ValidationTokenEnum.Keyword &&
13569
13636
  tokens[index + 1].val === "-" &&
13570
- tokens[index + 2]?.typ === ValidationTokenEnum.InfinityToken;
13637
+ tokens[index + 2]?.typ === exports.ValidationTokenEnum.InfinityToken;
13571
13638
  if (isNegativeInfinity &&
13572
- (tokens[index - 2]?.typ === ValidationTokenEnum.Keyword ||
13573
- tokens[index - 2]?.typ === ValidationTokenEnum.StringToken) &&
13574
- tokens[index - 1]?.typ === ValidationTokenEnum.Whitespace &&
13575
- tokens[index + 3]?.typ === ValidationTokenEnum.Comma &&
13576
- (tokens[index + 4]?.typ === ValidationTokenEnum.Number ||
13577
- tokens[index + 4]?.typ === ValidationTokenEnum.Dimension ||
13578
- tokens[index + 4]?.typ === ValidationTokenEnum.InfinityToken) &&
13579
- tokens[index + 5]?.typ === ValidationTokenEnum.CloseBracket) {
13639
+ (tokens[index - 2]?.typ === exports.ValidationTokenEnum.Keyword ||
13640
+ tokens[index - 2]?.typ === exports.ValidationTokenEnum.StringToken) &&
13641
+ tokens[index - 1]?.typ === exports.ValidationTokenEnum.Whitespace &&
13642
+ tokens[index + 3]?.typ === exports.ValidationTokenEnum.Comma &&
13643
+ (tokens[index + 4]?.typ === exports.ValidationTokenEnum.Number ||
13644
+ tokens[index + 4]?.typ === exports.ValidationTokenEnum.Dimension ||
13645
+ tokens[index + 4]?.typ === exports.ValidationTokenEnum.InfinityToken) &&
13646
+ tokens[index + 5]?.typ === exports.ValidationTokenEnum.CloseBracket) {
13580
13647
  stack.pop();
13581
13648
  // a null bound is unbounded
13582
13649
  Object.assign(tokens[index - 2], {
13583
13650
  range: {
13584
13651
  min: null,
13585
- max: tokens[index + 4]?.typ === ValidationTokenEnum.InfinityToken
13652
+ max: tokens[index + 4]?.typ === exports.ValidationTokenEnum.InfinityToken
13586
13653
  ? null
13587
13654
  : tokens[index + 4],
13588
13655
  },
@@ -13590,11 +13657,11 @@
13590
13657
  tokens.splice(index - 1, 8);
13591
13658
  break;
13592
13659
  }
13593
- if ((tokens[index - 2]?.typ === ValidationTokenEnum.Keyword ||
13594
- tokens[index - 2]?.typ === ValidationTokenEnum.StringToken) &&
13595
- tokens[index - 1]?.typ === ValidationTokenEnum.Whitespace &&
13596
- (tokens[index + 1]?.typ === ValidationTokenEnum.Number ||
13597
- tokens[index + 1]?.typ === ValidationTokenEnum.Dimension)) {
13660
+ if ((tokens[index - 2]?.typ === exports.ValidationTokenEnum.Keyword ||
13661
+ tokens[index - 2]?.typ === exports.ValidationTokenEnum.StringToken) &&
13662
+ tokens[index - 1]?.typ === exports.ValidationTokenEnum.Whitespace &&
13663
+ (tokens[index + 1]?.typ === exports.ValidationTokenEnum.Number ||
13664
+ tokens[index + 1]?.typ === exports.ValidationTokenEnum.Dimension)) {
13598
13665
  // if (tokens[index + 2]?.typ === ValidationTokenEnum.CloseBracket) {
13599
13666
  // stack.pop();
13600
13667
  // Object.assign(tokens[index - 2], {
@@ -13606,10 +13673,10 @@
13606
13673
  // tokens.splice(index - 1, 5);
13607
13674
  // break;
13608
13675
  // }
13609
- if (tokens[index + 2]?.typ === ValidationTokenEnum.Comma &&
13676
+ if (tokens[index + 2]?.typ === exports.ValidationTokenEnum.Comma &&
13610
13677
  (tokens[index + 3]?.typ === tokens[index + 1]?.typ ||
13611
- tokens[index + 3]?.typ === ValidationTokenEnum.InfinityToken) &&
13612
- tokens[index + 4]?.typ === ValidationTokenEnum.CloseBracket) {
13678
+ tokens[index + 3]?.typ === exports.ValidationTokenEnum.InfinityToken) &&
13679
+ tokens[index + 4]?.typ === exports.ValidationTokenEnum.CloseBracket) {
13613
13680
  stack.pop();
13614
13681
  Object.assign(tokens[index - 2], {
13615
13682
  range: {
@@ -13628,17 +13695,17 @@
13628
13695
  startIndex = tokens.lastIndexOf(currentToken);
13629
13696
  endIndex = tokens.indexOf(token);
13630
13697
  Object.assign(currentToken, {
13631
- typ: ValidationTokenEnum.Bracket,
13698
+ typ: exports.ValidationTokenEnum.Bracket,
13632
13699
  chi: trimSyntaxArray(tokens.slice(startIndex + 1, endIndex)),
13633
13700
  });
13634
13701
  tokens.splice(startIndex + 1, tokens.length);
13635
13702
  break;
13636
13703
  // {
13637
- case ValidationTokenEnum.OpenCurlyBrace:
13704
+ case exports.ValidationTokenEnum.OpenCurlyBrace:
13638
13705
  stack.push(token);
13639
13706
  break;
13640
13707
  // }
13641
- case ValidationTokenEnum.CloseCurlyBrace:
13708
+ case exports.ValidationTokenEnum.CloseCurlyBrace:
13642
13709
  while (true) {
13643
13710
  // if ((stack.at(-1) as ValidationToken).typ == ValidationTokenEnum.AmpersandToken) {
13644
13711
  // let index: number = tokens.lastIndexOf(stack.at(-1) as ValidationToken);
@@ -13648,13 +13715,13 @@
13648
13715
  // stack.pop();
13649
13716
  // continue;
13650
13717
  // } else
13651
- if (stack.at(-1).typ === ValidationTokenEnum.ColumnToken) {
13718
+ if (stack.at(-1).typ === exports.ValidationTokenEnum.ColumnToken) {
13652
13719
  let index = tokens.lastIndexOf(stack.at(-1));
13653
13720
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
13654
13721
  stack.pop();
13655
13722
  continue;
13656
13723
  }
13657
- if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
13724
+ if (stack.at(-1)?.typ === exports.ValidationTokenEnum.PipeToken) {
13658
13725
  let index = tokens.lastIndexOf(stack.at(-1));
13659
13726
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
13660
13727
  stack.pop();
@@ -13669,7 +13736,7 @@
13669
13736
  let index = tokens.lastIndexOf(stack.at(-1));
13670
13737
  const slice = tokens.slice(index + 1, -1);
13671
13738
  if (slice.length === 1 || slice.length === 3) {
13672
- if (slice[0].typ === ValidationTokenEnum.Number) {
13739
+ if (slice[0].typ === exports.ValidationTokenEnum.Number) {
13673
13740
  Object.assign(tokens[index - 1], {
13674
13741
  match: {
13675
13742
  min: slice[0],
@@ -13691,7 +13758,7 @@
13691
13758
  Object.assign(tokens[index - 1], {
13692
13759
  match: {
13693
13760
  min: slice[0],
13694
- max: slice[2].typ === ValidationTokenEnum.InfinityToken
13761
+ max: slice[2].typ === exports.ValidationTokenEnum.InfinityToken
13695
13762
  ? Number.POSITIVE_INFINITY
13696
13763
  : slice[2],
13697
13764
  },
@@ -13705,11 +13772,11 @@
13705
13772
  }
13706
13773
  stack.pop();
13707
13774
  break;
13708
- case ValidationTokenEnum.Star:
13775
+ case exports.ValidationTokenEnum.Star:
13709
13776
  tokens.pop();
13710
13777
  tokens.at(-1).isRepeatable = true;
13711
13778
  break;
13712
- case ValidationTokenEnum.QuestionMark:
13779
+ case exports.ValidationTokenEnum.QuestionMark:
13713
13780
  tokens.pop();
13714
13781
  // if the previous token is a comma, we wrap them in a virtual group and mark the group as optional
13715
13782
  {
@@ -13719,14 +13786,14 @@
13719
13786
  // sliceIndex = tokens.length - 2;
13720
13787
  // } else
13721
13788
  // {
13722
- isGroup = tokens.at(-3)?.typ === ValidationTokenEnum.Comma;
13789
+ isGroup = tokens.at(-3)?.typ === exports.ValidationTokenEnum.Comma;
13723
13790
  if (isGroup) {
13724
13791
  sliceIndex = tokens.length - 3;
13725
13792
  }
13726
13793
  // }
13727
13794
  if (isGroup) {
13728
13795
  tokens.splice(sliceIndex, tokens.length - sliceIndex, {
13729
- typ: ValidationTokenEnum.OptionalGroupToken,
13796
+ typ: exports.ValidationTokenEnum.OptionalGroupToken,
13730
13797
  chi: trimSyntaxArray(tokens.slice(sliceIndex)),
13731
13798
  isOptional: true,
13732
13799
  });
@@ -13736,15 +13803,15 @@
13736
13803
  }
13737
13804
  }
13738
13805
  break;
13739
- case ValidationTokenEnum.Comma:
13806
+ case exports.ValidationTokenEnum.Comma:
13740
13807
  {
13741
13808
  let sliceIndex = -1;
13742
13809
  // if (tokens.at(-2)?.isOptional && tokens.at(-2)!.typ !== ValidationTokenEnum.OptionalGroupToken) {
13743
13810
  // sliceIndex = tokens.length - 2;
13744
13811
  // } else
13745
- if (tokens.at(-2).typ === ValidationTokenEnum.Whitespace &&
13812
+ if (tokens.at(-2).typ === exports.ValidationTokenEnum.Whitespace &&
13746
13813
  tokens.at(-3)?.isOptional &&
13747
- tokens.at(-3).typ !== ValidationTokenEnum.OptionalGroupToken) {
13814
+ tokens.at(-3).typ !== exports.ValidationTokenEnum.OptionalGroupToken) {
13748
13815
  sliceIndex = tokens.length - 3;
13749
13816
  }
13750
13817
  if (sliceIndex !== -1) {
@@ -13752,7 +13819,7 @@
13752
13819
  tokens.pop();
13753
13820
  }
13754
13821
  tokens.splice(sliceIndex, tokens.length - sliceIndex, {
13755
- typ: ValidationTokenEnum.OptionalGroupToken,
13822
+ typ: exports.ValidationTokenEnum.OptionalGroupToken,
13756
13823
  chi: trimSyntaxArray(tokens.slice(sliceIndex).map((t) => {
13757
13824
  delete t.isOptional;
13758
13825
  return t;
@@ -13762,22 +13829,22 @@
13762
13829
  }
13763
13830
  }
13764
13831
  break;
13765
- case ValidationTokenEnum.HashMark:
13832
+ case exports.ValidationTokenEnum.HashMark:
13766
13833
  tokens.pop();
13767
13834
  tokens.at(-1).isList = true;
13768
13835
  break;
13769
- case ValidationTokenEnum.Exclamation:
13836
+ case exports.ValidationTokenEnum.Exclamation:
13770
13837
  tokens.pop();
13771
13838
  tokens.at(-1).isMandatatoryGroup = true;
13772
13839
  break;
13773
- case ValidationTokenEnum.Plus:
13840
+ case exports.ValidationTokenEnum.Plus:
13774
13841
  tokens.pop();
13775
13842
  tokens.at(-1).isRepeatableAtLeastOnce = true;
13776
13843
  break;
13777
13844
  }
13778
13845
  }
13779
13846
  if (stack.length > 0) {
13780
- if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
13847
+ if (stack.at(-1)?.typ === exports.ValidationTokenEnum.PipeToken) {
13781
13848
  let index = tokens.lastIndexOf(stack.at(-1));
13782
13849
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 1)));
13783
13850
  stack.pop();
@@ -13977,8 +14044,8 @@
13977
14044
  let blockEnd = -1;
13978
14045
  let i;
13979
14046
  for (i = 0; i < syntaxRules.length; i++) {
13980
- if (syntaxRules[i].typ === ValidationTokenEnum.OpenCurlyBrace ||
13981
- syntaxRules[i].typ === ValidationTokenEnum.SemiColon) {
14047
+ if (syntaxRules[i].typ === exports.ValidationTokenEnum.OpenCurlyBrace ||
14048
+ syntaxRules[i].typ === exports.ValidationTokenEnum.SemiColon) {
13982
14049
  blockStart = i;
13983
14050
  break;
13984
14051
  }
@@ -13986,7 +14053,7 @@
13986
14053
  if (blockStart !== -1) {
13987
14054
  i = syntaxRules.length;
13988
14055
  while (i--) {
13989
- if (syntaxRules[i].typ === ValidationTokenEnum.CloseCurlyBrace) {
14056
+ if (syntaxRules[i].typ === exports.ValidationTokenEnum.CloseCurlyBrace) {
13990
14057
  blockEnd = i;
13991
14058
  break;
13992
14059
  }
@@ -14007,14 +14074,14 @@
14007
14074
  let optionalBody = false;
14008
14075
  if (block == null || block.length === 0) {
14009
14076
  let k = prelude.length - 1;
14010
- if (ValidationTokenEnum.SemiColon === prelude[k].typ) {
14077
+ if (exports.ValidationTokenEnum.SemiColon === prelude[k].typ) {
14011
14078
  k--;
14012
14079
  }
14013
- if (k >= 0 && ValidationTokenEnum.Bracket === prelude[k].typ) {
14080
+ if (k >= 0 && exports.ValidationTokenEnum.Bracket === prelude[k].typ) {
14014
14081
  if (prelude[k].chi[0].typ ===
14015
- ValidationTokenEnum.OpenCurlyBrace &&
14082
+ exports.ValidationTokenEnum.OpenCurlyBrace &&
14016
14083
  prelude[k].chi.at(-1).typ ===
14017
- ValidationTokenEnum.CloseCurlyBrace) {
14084
+ exports.ValidationTokenEnum.CloseCurlyBrace) {
14018
14085
  block = prelude[k].chi.slice(1, -1);
14019
14086
  optionalBody = prelude[k].isOptional ?? false;
14020
14087
  }
@@ -14041,7 +14108,7 @@
14041
14108
  * @param syntax
14042
14109
  */
14043
14110
  function isNullable(syntax) {
14044
- if (syntax.typ === ValidationTokenEnum.Whitespace) {
14111
+ if (syntax.typ === exports.ValidationTokenEnum.Whitespace) {
14045
14112
  return true;
14046
14113
  }
14047
14114
  // `[ <a>? <b>? ]!`: at least one token
@@ -14054,13 +14121,13 @@
14054
14121
  let nullable = nullableSyntaxes.get(syntax);
14055
14122
  if (nullable == null) {
14056
14123
  switch (syntax.typ) {
14057
- case ValidationTokenEnum.Bracket:
14124
+ case exports.ValidationTokenEnum.Bracket:
14058
14125
  nullable = syntax.chi.every(isNullable);
14059
14126
  break;
14060
- case ValidationTokenEnum.PipeToken:
14127
+ case exports.ValidationTokenEnum.PipeToken:
14061
14128
  nullable = syntax.chi.some((syntaxes) => syntaxes.every(isNullable));
14062
14129
  break;
14063
- case ValidationTokenEnum.AmpersandToken:
14130
+ case exports.ValidationTokenEnum.AmpersandToken:
14064
14131
  nullable =
14065
14132
  syntax.l.every(isNullable) &&
14066
14133
  syntax.r.every(isNullable);
@@ -14299,71 +14366,71 @@
14299
14366
  let nullable = false;
14300
14367
  let first;
14301
14368
  switch (syntax.typ) {
14302
- case ValidationTokenEnum.Whitespace:
14369
+ case exports.ValidationTokenEnum.Whitespace:
14303
14370
  nullable = true;
14304
14371
  break;
14305
- case ValidationTokenEnum.Keyword:
14372
+ case exports.ValidationTokenEnum.Keyword:
14306
14373
  set.keywords.add(lowercase(syntax.val));
14307
14374
  break;
14308
- case ValidationTokenEnum.Comma:
14375
+ case exports.ValidationTokenEnum.Comma:
14309
14376
  set.types.add(exports.EnumToken.CommaTokenType);
14310
14377
  break;
14311
- case ValidationTokenEnum.Colon:
14378
+ case exports.ValidationTokenEnum.Colon:
14312
14379
  set.types.add(exports.EnumToken.ColonTokenType);
14313
14380
  break;
14314
- case ValidationTokenEnum.Separator:
14381
+ case exports.ValidationTokenEnum.Separator:
14315
14382
  set.types.add(exports.EnumToken.LiteralTokenType);
14316
14383
  break;
14317
- case ValidationTokenEnum.OpenParenthesis:
14384
+ case exports.ValidationTokenEnum.OpenParenthesis:
14318
14385
  set.types.add(exports.EnumToken.StartParensTokenType);
14319
14386
  break;
14320
- case ValidationTokenEnum.CloseParenthesis:
14387
+ case exports.ValidationTokenEnum.CloseParenthesis:
14321
14388
  set.types.add(exports.EnumToken.EndParensTokenType);
14322
14389
  break;
14323
- case ValidationTokenEnum.OpenCurlyBrace:
14390
+ case exports.ValidationTokenEnum.OpenCurlyBrace:
14324
14391
  set.types.add(exports.EnumToken.BlockStartTokenType);
14325
14392
  break;
14326
- case ValidationTokenEnum.Number:
14393
+ case exports.ValidationTokenEnum.Number:
14327
14394
  set.types.add(exports.EnumToken.NumberTokenType);
14328
14395
  break;
14329
- case ValidationTokenEnum.Dimension:
14396
+ case exports.ValidationTokenEnum.Dimension:
14330
14397
  set.types.add(exports.EnumToken[syntax.unit]);
14331
14398
  break;
14332
- case ValidationTokenEnum.StringToken:
14399
+ case exports.ValidationTokenEnum.StringToken:
14333
14400
  // `'+'`, `'-'`, `'/'`
14334
14401
  set.types.add(exports.EnumToken.Add);
14335
14402
  set.types.add(exports.EnumToken.Sub);
14336
14403
  set.types.add(exports.EnumToken.LiteralTokenType);
14337
14404
  set.types.add(exports.EnumToken.Plus);
14338
14405
  break;
14339
- case ValidationTokenEnum.Function:
14340
- case ValidationTokenEnum.FunctionDefinition:
14406
+ case exports.ValidationTokenEnum.Function:
14407
+ case exports.ValidationTokenEnum.FunctionDefinition:
14341
14408
  set.functions.add(lowercase(syntax.val));
14342
14409
  break;
14343
- case ValidationTokenEnum.Bracket:
14410
+ case exports.ValidationTokenEnum.Bracket:
14344
14411
  first = firstOfSequence(syntax.chi);
14345
14412
  merge(set, first);
14346
14413
  nullable = first.nullable;
14347
14414
  break;
14348
- case ValidationTokenEnum.OptionalGroupToken:
14415
+ case exports.ValidationTokenEnum.OptionalGroupToken:
14349
14416
  // the group is skipped when it does not match
14350
14417
  merge(set, firstOfSequence(syntax.chi));
14351
14418
  nullable = true;
14352
14419
  break;
14353
- case ValidationTokenEnum.PipeToken:
14420
+ case exports.ValidationTokenEnum.PipeToken:
14354
14421
  for (const syntaxes of syntax.chi) {
14355
14422
  first = firstOfSequence(syntaxes);
14356
14423
  merge(set, first);
14357
14424
  nullable ||= first.nullable;
14358
14425
  }
14359
14426
  break;
14360
- case ValidationTokenEnum.ColumnToken:
14427
+ case exports.ValidationTokenEnum.ColumnToken:
14361
14428
  // one or more operands, in any order: at least one token
14362
14429
  for (const syntaxes of syntax.chi) {
14363
14430
  merge(set, firstOfSequence(syntaxes));
14364
14431
  }
14365
14432
  break;
14366
- case ValidationTokenEnum.AmpersandToken:
14433
+ case exports.ValidationTokenEnum.AmpersandToken:
14367
14434
  // all the operands, in any order
14368
14435
  nullable = true;
14369
14436
  for (const syntaxes of [syntax.l, syntax.r]) {
@@ -14372,12 +14439,12 @@
14372
14439
  nullable &&= first.nullable;
14373
14440
  }
14374
14441
  break;
14375
- case ValidationTokenEnum.DeclarationType:
14442
+ case exports.ValidationTokenEnum.DeclarationType:
14376
14443
  first = firstOfSequence(getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, syntax.val));
14377
14444
  merge(set, first);
14378
14445
  nullable = first.nullable;
14379
14446
  break;
14380
- case ValidationTokenEnum.PropertyType: {
14447
+ case exports.ValidationTokenEnum.PropertyType: {
14381
14448
  const name = syntax.val;
14382
14449
  if (builtinTypes.has(name)) {
14383
14450
  const types = builtinTypes.get(name);
@@ -16528,7 +16595,7 @@
16528
16595
  return interpreted;
16529
16596
  }
16530
16597
  const property = {
16531
- typ: ValidationTokenEnum.PropertyType,
16598
+ typ: exports.ValidationTokenEnum.PropertyType,
16532
16599
  val: name,
16533
16600
  };
16534
16601
  const fast = numericTypes[name] ?? null;
@@ -17015,6 +17082,71 @@
17015
17082
  }
17016
17083
  return tokens;
17017
17084
  }
17085
+ /**
17086
+ * true if the token is a simple selector without arguments: a type (`a`), an id (`#a`), a class (`.a`), a
17087
+ * pseudo-class (`:hover`) or a pseudo-element (`::before`)
17088
+ * @param type
17089
+ */
17090
+ function isSimpleSelectorToken(type) {
17091
+ return (type === exports.EnumToken.ClassSelectorTokenType ||
17092
+ type === exports.EnumToken.IdenTokenType ||
17093
+ type === exports.EnumToken.PseudoElementTokenType ||
17094
+ type === exports.EnumToken.PseudoClassTokenType ||
17095
+ type === exports.EnumToken.HashTokenType);
17096
+ }
17097
+ /**
17098
+ * match a selector made of simple selectors (see {@link isSimpleSelectorToken}), separated by whitespace (the
17099
+ * descendant combinator) and by commas: `.a:hover`, `.a .b`, `.a, #b`. such a selector is valid: the whitespace
17100
+ * around the commas is removed, the tokens are the tokens produced by {@link matchSelectorSyntax}. the tokens of
17101
+ * another selector are not changed
17102
+ * @param arena
17103
+ * @param tokens
17104
+ * @returns true if the selector is made of simple selectors
17105
+ */
17106
+ function matchSimpleSelector(arena, tokens) {
17107
+ const length = tokens.length;
17108
+ // a simple selector is expected: at the start of the selector and after a comma
17109
+ let expected = true;
17110
+ let commaWhitespace = false;
17111
+ for (let i = 0; i < length; i++) {
17112
+ const type = arena.dataTypes[tokens[i]];
17113
+ if (isSimpleSelectorToken(type)) {
17114
+ expected = false;
17115
+ continue;
17116
+ }
17117
+ if (type === exports.EnumToken.WhitespaceTokenType) {
17118
+ // leading whitespace
17119
+ if (i === 0) {
17120
+ return false;
17121
+ }
17122
+ // whitespace after a comma or before a comma
17123
+ if (expected || arena.dataTypes[tokens[i + 1]] === exports.EnumToken.CommaTokenType) {
17124
+ commaWhitespace = true;
17125
+ }
17126
+ continue;
17127
+ }
17128
+ if (type !== exports.EnumToken.CommaTokenType || expected) {
17129
+ return false;
17130
+ }
17131
+ expected = true;
17132
+ }
17133
+ if (expected) {
17134
+ return false;
17135
+ }
17136
+ if (commaWhitespace) {
17137
+ let write = 0;
17138
+ for (let i = 0; i < length; i++) {
17139
+ if (arena.dataTypes[tokens[i]] === exports.EnumToken.WhitespaceTokenType &&
17140
+ (arena.dataTypes[tokens[i - 1]] === exports.EnumToken.CommaTokenType ||
17141
+ arena.dataTypes[tokens[i + 1]] === exports.EnumToken.CommaTokenType)) {
17142
+ continue;
17143
+ }
17144
+ tokens[write++] = tokens[i];
17145
+ }
17146
+ tokens.length = write;
17147
+ }
17148
+ return true;
17149
+ }
17018
17150
  /**
17019
17151
  *
17020
17152
  * @param featureName
@@ -18210,9 +18342,9 @@
18210
18342
  */
18211
18343
  function countItemCommas(syntax) {
18212
18344
  let count = 0;
18213
- if (syntax.typ === ValidationTokenEnum.Bracket) {
18345
+ if (syntax.typ === exports.ValidationTokenEnum.Bracket) {
18214
18346
  for (const token of syntax.chi) {
18215
- if (token.typ === ValidationTokenEnum.Comma) {
18347
+ if (token.typ === exports.ValidationTokenEnum.Comma) {
18216
18348
  count++;
18217
18349
  }
18218
18350
  }
@@ -18374,7 +18506,7 @@
18374
18506
  if (arena.hasFraction(token) || arena.numericValue[token] !== syntax.val) {
18375
18507
  return false;
18376
18508
  }
18377
- if (syntax.typ === ValidationTokenEnum.Number) {
18509
+ if (syntax.typ === exports.ValidationTokenEnum.Number) {
18378
18510
  return arena.dataTypes[token] === exports.EnumToken.NumberTokenType;
18379
18511
  }
18380
18512
  const type = exports.EnumToken[syntax.unit];
@@ -18398,7 +18530,7 @@
18398
18530
  const range = syntax.range;
18399
18531
  // a null lower bound is -∞
18400
18532
  let success = !arena.hasFraction(token) && (range.min == null || arena.numericValue[token] >= range.min.val);
18401
- if (range.min?.typ === ValidationTokenEnum.Dimension) {
18533
+ if (range.min?.typ === exports.ValidationTokenEnum.Dimension) {
18402
18534
  success =
18403
18535
  arena.dataTypes[token] ===
18404
18536
  exports.EnumToken[
@@ -18416,8 +18548,12 @@
18416
18548
  * @param token
18417
18549
  */
18418
18550
  function functionSyntax(arena, token) {
18551
+ const previousSyntaxArena = syntaxArena;
18419
18552
  syntaxArena = arena;
18420
- return arena.stringDerived(arena.stringValue[token], 0 /* StringDerived.FunctionSyntax */, computeFunctionSyntax);
18553
+ const syntax = arena.stringDerived(arena.stringValue[token], 0 /* StringDerived.FunctionSyntax */, computeFunctionSyntax);
18554
+ // the arena is not kept after the parse: the previous arena is restored (a nested call)
18555
+ syntaxArena = previousSyntaxArena;
18556
+ return syntax;
18421
18557
  }
18422
18558
  /**
18423
18559
  * the arena of the function names read by {@link computeFunctionSyntax} and {@link computeSelectorFunctionSyntax}:
@@ -18444,8 +18580,12 @@
18444
18580
  * @param token
18445
18581
  */
18446
18582
  function selectorFunctionSyntax(arena, token) {
18583
+ const previousSyntaxArena = syntaxArena;
18447
18584
  syntaxArena = arena;
18448
- return arena.stringDerived(arena.stringValue[token], 1 /* StringDerived.SelectorFunctionSyntax */, computeSelectorFunctionSyntax);
18585
+ const syntax = arena.stringDerived(arena.stringValue[token], 1 /* StringDerived.SelectorFunctionSyntax */, computeSelectorFunctionSyntax);
18586
+ // the arena is not kept after the parse: the previous arena is restored (a nested call)
18587
+ syntaxArena = previousSyntaxArena;
18588
+ return syntax;
18449
18589
  }
18450
18590
  /**
18451
18591
  * the wildcard functions being matched with a syntax, see {@link matchWildCardFunction}
@@ -18472,12 +18612,12 @@
18472
18612
  let errors = noErrors;
18473
18613
  const candidates = [];
18474
18614
  // the function is a part of the syntax. a keyword, a comma, ... is matched by the function
18475
- if (syntaxes[index].typ !== ValidationTokenEnum.Keyword &&
18476
- syntaxes[index].typ !== ValidationTokenEnum.Comma &&
18477
- syntaxes[index].typ !== ValidationTokenEnum.Separator &&
18478
- syntaxes[index].typ !== ValidationTokenEnum.StringToken &&
18479
- syntaxes[index].typ !== ValidationTokenEnum.OpenParenthesis &&
18480
- syntaxes[index].typ !== ValidationTokenEnum.CloseParenthesis) {
18615
+ if (syntaxes[index].typ !== exports.ValidationTokenEnum.Keyword &&
18616
+ syntaxes[index].typ !== exports.ValidationTokenEnum.Comma &&
18617
+ syntaxes[index].typ !== exports.ValidationTokenEnum.Separator &&
18618
+ syntaxes[index].typ !== exports.ValidationTokenEnum.StringToken &&
18619
+ syntaxes[index].typ !== exports.ValidationTokenEnum.OpenParenthesis &&
18620
+ syntaxes[index].typ !== exports.ValidationTokenEnum.CloseParenthesis) {
18481
18621
  const previous = wildCardProbes.get(token);
18482
18622
  let probe;
18483
18623
  wildCardProbes.set(token, syntaxes[index]);
@@ -18576,7 +18716,7 @@
18576
18716
  return setMatch(out, true, true, context.peek(), context, null, noErrors);
18577
18717
  }
18578
18718
  while (++i < syntaxes.length) {
18579
- if (syntaxes[i].typ === ValidationTokenEnum.Whitespace) {
18719
+ if (syntaxes[i].typ === exports.ValidationTokenEnum.Whitespace) {
18580
18720
  continue;
18581
18721
  }
18582
18722
  isOptional =
@@ -18695,7 +18835,7 @@
18695
18835
  success = false;
18696
18836
  try {
18697
18837
  switch (syntaxes[i].typ) {
18698
- case ValidationTokenEnum.Colon:
18838
+ case exports.ValidationTokenEnum.Colon:
18699
18839
  // `<ident-token> : <declaration-value>?`
18700
18840
  if (arena.dataTypes[token] === exports.EnumToken.ColonTokenType) {
18701
18841
  success = true;
@@ -18706,7 +18846,7 @@
18706
18846
  break;
18707
18847
  }
18708
18848
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
18709
- case ValidationTokenEnum.Comma:
18849
+ case exports.ValidationTokenEnum.Comma:
18710
18850
  if (arena.dataTypes[token] === exports.EnumToken.CommaTokenType) {
18711
18851
  success = true;
18712
18852
  visitedSyntaxes[visit] = null;
@@ -18714,7 +18854,7 @@
18714
18854
  break;
18715
18855
  }
18716
18856
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
18717
- case ValidationTokenEnum.Keyword:
18857
+ case exports.ValidationTokenEnum.Keyword:
18718
18858
  if (arena.dataTypes[token] === exports.EnumToken.IdenTokenType &&
18719
18859
  lowercase(arena.resolveString(arena.stringValue[token])) ===
18720
18860
  lowercase(syntaxes[i].val)) {
@@ -18727,7 +18867,7 @@
18727
18867
  break;
18728
18868
  }
18729
18869
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
18730
- case ValidationTokenEnum.DeclarationType:
18870
+ case exports.ValidationTokenEnum.DeclarationType:
18731
18871
  result = matchSyntax(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, syntaxes[i].val), context, options, out);
18732
18872
  if (result.success) {
18733
18873
  success = true;
@@ -18746,7 +18886,7 @@
18746
18886
  break;
18747
18887
  }
18748
18888
  return setMatch(out, false, true, token, context, syntaxes[i], result.errors);
18749
- case ValidationTokenEnum.OptionalGroupToken: {
18889
+ case exports.ValidationTokenEnum.OptionalGroupToken: {
18750
18890
  const chi = syntaxes[i].chi;
18751
18891
  // `<bg-layer>#? , <final-bg-layer>` (the group of the optional list, the comma is the list separator) is
18752
18892
  // matched as `[ <bg-layer> , ]* <final-bg-layer>`: the last item is left to the next syntax
@@ -18754,7 +18894,7 @@
18754
18894
  const { isList, isOptional, match, ...item } = chi[0];
18755
18895
  const group = [
18756
18896
  item,
18757
- { typ: ValidationTokenEnum.Comma },
18897
+ { typ: exports.ValidationTokenEnum.Comma },
18758
18898
  ];
18759
18899
  while (context.peek() != null) {
18760
18900
  const tmp = matchSyntax(arena, group, context.slice(), options);
@@ -18781,7 +18921,7 @@
18781
18921
  }
18782
18922
  break;
18783
18923
  }
18784
- case ValidationTokenEnum.StringToken:
18924
+ case exports.ValidationTokenEnum.StringToken:
18785
18925
  if (arena.dataTypes[token] === exports.EnumToken.Add) {
18786
18926
  success = syntaxes[i].val.slice(1, -1) === "+";
18787
18927
  }
@@ -18804,7 +18944,7 @@
18804
18944
  break;
18805
18945
  }
18806
18946
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
18807
- case ValidationTokenEnum.PropertyType:
18947
+ case exports.ValidationTokenEnum.PropertyType:
18808
18948
  result = matchProperty(arena, syntaxes[i], context, options);
18809
18949
  if (!result.success) {
18810
18950
  if (isOptional) {
@@ -18825,7 +18965,7 @@
18825
18965
  context.update(result.context.current());
18826
18966
  }
18827
18967
  break;
18828
- case ValidationTokenEnum.PipeToken:
18968
+ case exports.ValidationTokenEnum.PipeToken:
18829
18969
  {
18830
18970
  // each alternative is matched in the same scratch result, the best match is copied
18831
18971
  const scratch = createMatch();
@@ -18871,7 +19011,7 @@
18871
19011
  syntax: syntaxes[i],
18872
19012
  },
18873
19013
  ]);
18874
- case ValidationTokenEnum.Bracket:
19014
+ case exports.ValidationTokenEnum.Bracket:
18875
19015
  result = matchSyntax(arena, syntaxes[i].chi, context.slice(), options, out);
18876
19016
  if (result.success) {
18877
19017
  success = true;
@@ -18889,7 +19029,7 @@
18889
19029
  break;
18890
19030
  }
18891
19031
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
18892
- case ValidationTokenEnum.ColumnToken:
19032
+ case exports.ValidationTokenEnum.ColumnToken:
18893
19033
  result = matchColumnSyntax(arena, syntaxes[i], context.slice(), options);
18894
19034
  if (result.success) {
18895
19035
  success = true;
@@ -18904,7 +19044,7 @@
18904
19044
  break;
18905
19045
  }
18906
19046
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
18907
- case ValidationTokenEnum.AmpersandToken:
19047
+ case exports.ValidationTokenEnum.AmpersandToken:
18908
19048
  result = matchAmpersandSyntax(arena, syntaxes[i], context.slice(), options);
18909
19049
  if (result.success) {
18910
19050
  success = true;
@@ -18919,7 +19059,7 @@
18919
19059
  break;
18920
19060
  }
18921
19061
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
18922
- case ValidationTokenEnum.Function:
19062
+ case exports.ValidationTokenEnum.Function:
18923
19063
  if ((!isFunctionDefType(arena.dataTypes[token]) &&
18924
19064
  !funcLike.includes(arena.dataTypes[token]) &&
18925
19065
  !funcTypes.includes(arena.dataTypes[token])) ||
@@ -18951,8 +19091,8 @@
18951
19091
  }
18952
19092
  }
18953
19093
  return setMatch(out, false, true, token, context, syntaxes[i], result.errors);
18954
- case ValidationTokenEnum.Number:
18955
- case ValidationTokenEnum.Dimension:
19094
+ case exports.ValidationTokenEnum.Number:
19095
+ case exports.ValidationTokenEnum.Dimension:
18956
19096
  // a literal number or dimension: `-moz-force-broken-image-icon: 0 | 1`,
18957
19097
  // `glyph-orientation-vertical: auto | 0deg | 90deg | 0 | 90`
18958
19098
  if (isLiteralNumber(arena, token, syntaxes[i])) {
@@ -18965,7 +19105,7 @@
18965
19105
  break;
18966
19106
  }
18967
19107
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
18968
- case ValidationTokenEnum.Separator:
19108
+ case exports.ValidationTokenEnum.Separator:
18969
19109
  if (arena.dataTypes[token] === exports.EnumToken.LiteralTokenType &&
18970
19110
  arena.resolveString(arena.stringValue[token]) === "/") {
18971
19111
  visitedSyntaxes[visit] = null;
@@ -18973,7 +19113,7 @@
18973
19113
  break;
18974
19114
  }
18975
19115
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
18976
- case ValidationTokenEnum.FunctionDefinition:
19116
+ case exports.ValidationTokenEnum.FunctionDefinition:
18977
19117
  if (arena.resolveString(arena.stringValue[token]) &&
18978
19118
  equalsIgnoreCase(arena.resolveString(arena.stringValue[token]), syntaxes[i].val)) {
18979
19119
  if (isFunctionDefType(arena.dataTypes[token])) {
@@ -18997,21 +19137,21 @@
18997
19137
  }
18998
19138
  }
18999
19139
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
19000
- case ValidationTokenEnum.OpenParenthesis:
19140
+ case exports.ValidationTokenEnum.OpenParenthesis:
19001
19141
  if (arena.dataTypes[token] === exports.EnumToken.StartParensTokenType) {
19002
19142
  visitedSyntaxes[visit] = null;
19003
19143
  context.next();
19004
19144
  break;
19005
19145
  }
19006
19146
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
19007
- case ValidationTokenEnum.OpenCurlyBrace:
19147
+ case exports.ValidationTokenEnum.OpenCurlyBrace:
19008
19148
  if (arena.dataTypes[token] === exports.EnumToken.BlockStartTokenType) {
19009
19149
  visitedSyntaxes[visit] = null;
19010
19150
  context.next();
19011
19151
  break;
19012
19152
  }
19013
19153
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
19014
- case ValidationTokenEnum.CloseParenthesis:
19154
+ case exports.ValidationTokenEnum.CloseParenthesis:
19015
19155
  if (arena.dataTypes[token] === exports.EnumToken.EndParensTokenType) {
19016
19156
  visitedSyntaxes[visit] = null;
19017
19157
  context.next();
@@ -19019,7 +19159,7 @@
19019
19159
  }
19020
19160
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
19021
19161
  default:
19022
- throw new Error(`Unexpected syntax ${ValidationTokenEnum[syntaxes[i].typ]}`);
19162
+ throw new Error(`Unexpected syntax ${exports.ValidationTokenEnum[syntaxes[i].typ]}`);
19023
19163
  }
19024
19164
  }
19025
19165
  finally {
@@ -19157,9 +19297,9 @@
19157
19297
  */
19158
19298
  function ampersandOperands(syntax, operands = []) {
19159
19299
  for (const side of [syntax.l, syntax.r]) {
19160
- const tokens = side.filter((token) => token.typ !== ValidationTokenEnum.Whitespace);
19300
+ const tokens = side.filter((token) => token.typ !== exports.ValidationTokenEnum.Whitespace);
19161
19301
  if (tokens.length === 1 &&
19162
- tokens[0].typ === ValidationTokenEnum.AmpersandToken &&
19302
+ tokens[0].typ === exports.ValidationTokenEnum.AmpersandToken &&
19163
19303
  !tokens[0].isOptional &&
19164
19304
  !tokens[0].isRepeatable &&
19165
19305
  !tokens[0].isRepeatableAtLeastOnce &&
@@ -22111,7 +22251,16 @@
22111
22251
  */
22112
22252
  static shape = new RenderResult(new Uint8Array(0), [], { total: "0ms" });
22113
22253
  /**
22114
- * Rendered CSS, encoded as UTF-8
22254
+ * Rendered CSS, encoded as UTF-8: the output of the render, no conversion. Use it to write the css to a file or to
22255
+ * the network, or to send it to another thread without a copy:
22256
+ *
22257
+ * ```ts
22258
+ * self.postMessage(result.write, [result.write.buffer]);
22259
+ * ```
22260
+ *
22261
+ * It is a view of the first bytes of a larger buffer (`write.buffer`): without a transfer, `postMessage()` copies
22262
+ * the whole buffer, send `write.slice()` to copy only the css. See
22263
+ * [Zero copy between threads](../../files/usage.md#zero-copy-between-threads).
22115
22264
  */
22116
22265
  write;
22117
22266
  /**
@@ -22135,6 +22284,7 @@
22135
22284
  */
22136
22285
  #codeLength;
22137
22286
  /**
22287
+ * create a render result
22138
22288
  * @param write rendered css, encoded as UTF-8
22139
22289
  * @param errors
22140
22290
  * @param stats
@@ -22158,7 +22308,11 @@
22158
22308
  return result.#codeLength >= 0 ? result.#codeLength : result.code.length;
22159
22309
  }
22160
22310
  /**
22161
- * Rendered CSS. The bytes of {@link RenderResult.write} are decoded the first time the property is read
22311
+ * Rendered CSS. The bytes of {@link RenderResult.write} are decoded the first time the property is read, the
22312
+ * string is kept for the next reads: no string is created when it is not read.
22313
+ *
22314
+ * It is a getter, not a property of the object: `postMessage()` and `structuredClone()` do not send it, and it is
22315
+ * an empty string when it is read for the first time after {@link RenderResult.write} was transferred.
22162
22316
  */
22163
22317
  get code() {
22164
22318
  if (this.#code === null) {
@@ -22195,6 +22349,7 @@
22195
22349
  */
22196
22350
  arena;
22197
22351
  /**
22352
+ * create a transform result from the parse result and the render result
22198
22353
  * @param parseResult
22199
22354
  * @param renderResult
22200
22355
  * @param stats
@@ -23932,7 +24087,8 @@
23932
24087
  key === "0 0" ||
23933
24088
  key === "top left" ||
23934
24089
  key === "left top") {
23935
- positions.splice(0, positions.length, arena.createToken(exports.EnumToken.PercentageTokenType, 0));
24090
+ // a single value is centered vertically: both values are kept
24091
+ positions.splice(0, positions.length, arena.createToken(exports.EnumToken.PercentageTokenType, 0), arena.createToken(exports.EnumToken.WhitespaceTokenType), arena.createToken(exports.EnumToken.PercentageTokenType, 0));
23936
24092
  }
23937
24093
  else if (key === "50% 0%" ||
23938
24094
  key === "50% 0" ||
@@ -23956,7 +24112,7 @@
23956
24112
  key === "0% 100%" ||
23957
24113
  key === "left bottom" ||
23958
24114
  key === "bottom left") {
23959
- positions.splice(0, positions.length, arena.createToken(exports.EnumToken.IdenTokenType, "bottom"));
24115
+ positions.splice(0, positions.length, arena.createToken(exports.EnumToken.PercentageTokenType, 0), arena.createToken(exports.EnumToken.WhitespaceTokenType), arena.createToken(exports.EnumToken.PercentageTokenType, 100));
23960
24116
  }
23961
24117
  else if (key === "50% 100%" ||
23962
24118
  key === "center bottom" ||
@@ -23966,10 +24122,7 @@
23966
24122
  else if (key === "100% 100%" ||
23967
24123
  key === "right bottom" ||
23968
24124
  key === "bottom right") {
23969
- positions.splice(0, positions.length, arena.createToken(exports.EnumToken.PercentageTokenType, 100));
23970
- }
23971
- else if (position1 === position2) {
23972
- positions.splice(0, positions.length, positions[k]);
24125
+ positions.splice(0, positions.length, arena.createToken(exports.EnumToken.PercentageTokenType, 100), arena.createToken(exports.EnumToken.WhitespaceTokenType), arena.createToken(exports.EnumToken.PercentageTokenType, 100));
23973
24126
  }
23974
24127
  }
23975
24128
  }
@@ -30402,7 +30555,8 @@
30402
30555
  */
30403
30556
  options = { removeDuplicateDeclarations: true, computeShorthand: true };
30404
30557
  /**
30405
- * declarations
30558
+ * declarations, by property name
30559
+ * @ignore
30406
30560
  */
30407
30561
  declarations;
30408
30562
  /**
@@ -30419,8 +30573,8 @@
30419
30573
  */
30420
30574
  descriptors;
30421
30575
  /**
30422
- *
30423
- * @param arena
30576
+ * create an empty declaration list
30577
+ * @param arena the arena the declarations are stored in
30424
30578
  * @param options
30425
30579
  * @param memo keys shared by the lists that use the same arena
30426
30580
  * @param descriptors syntaxes of the descriptors of the at-rule that contains the declarations
@@ -30599,6 +30753,8 @@
30599
30753
  return this;
30600
30754
  }
30601
30755
  /**
30756
+ * Normalize the values of a declaration with the mapping of its property: the values are reordered by the patterns
30757
+ * of the mapping, the keywords are replaced by their mapped value
30602
30758
  *
30603
30759
  * @param declaration
30604
30760
  * @param mapping
@@ -30663,7 +30819,7 @@
30663
30819
  }
30664
30820
  }
30665
30821
  /**
30666
- *
30822
+ * iterate over the declarations, the shorthands are expanded into their declarations
30667
30823
  * @returns
30668
30824
  */
30669
30825
  [Symbol.iterator]() {
@@ -31973,8 +32129,12 @@
31973
32129
  * @param id interned string id
31974
32130
  */
31975
32131
  function transformKind(arena, id) {
32132
+ const previousKindArena = kindArena;
31976
32133
  kindArena = arena;
31977
- return arena.stringDerived(id, 2 /* StringDerived.TransformKind */, computeTransformKind);
32134
+ const kind = arena.stringDerived(id, 2 /* StringDerived.TransformKind */, computeTransformKind);
32135
+ // the arena is not kept after the transformation: the previous arena is restored (a nested call)
32136
+ kindArena = previousKindArena;
32137
+ return kind;
31978
32138
  }
31979
32139
  /**
31980
32140
  * numeric arguments of a transform function (the first 16 arguments), reused
@@ -33046,6 +33206,10 @@
33046
33206
  */
33047
33207
  StringDerived[StringDerived["AtRuleAcceptsRules"] = 3] = "AtRuleAcceptsRules";
33048
33208
  })(StringDerived || (StringDerived = {}));
33209
+ /**
33210
+ * code units of a short string, see {@link fromCodes}
33211
+ */
33212
+ const shortCodes = [];
33049
33213
  /**
33050
33214
  * string of a range of code units
33051
33215
  * @param codes
@@ -33053,6 +33217,15 @@
33053
33217
  * @param end
33054
33218
  */
33055
33219
  function fromCodes(codes, start, end) {
33220
+ const length = end - start;
33221
+ // a short string: the code units are copied to an array, a subarray is slower to create
33222
+ if (length <= 256) {
33223
+ shortCodes.length = length;
33224
+ for (let i = 0; i < length; i++) {
33225
+ shortCodes[i] = codes[start + i];
33226
+ }
33227
+ return String.fromCharCode.apply(null, shortCodes);
33228
+ }
33056
33229
  let result = "";
33057
33230
  // String.fromCharCode() with a limited number of arguments
33058
33231
  while (start < end) {
@@ -33224,6 +33397,18 @@
33224
33397
  this.texts[source] = text;
33225
33398
  this.codes[source] = codes ?? undefined;
33226
33399
  }
33400
+ /**
33401
+ * code unit of the text of a source, NaN after its end
33402
+ * @param source source index
33403
+ * @param offset
33404
+ */
33405
+ sourceCodeAt(source, offset) {
33406
+ const text = this.texts[source];
33407
+ if (text !== undefined && offset < text.length) {
33408
+ return text.charCodeAt(offset);
33409
+ }
33410
+ return this.codes[source]?.[offset] ?? NaN;
33411
+ }
33227
33412
  /**
33228
33413
  * drop the code units of a source: the source is no longer tokenized, see {@link setText}
33229
33414
  * @param source
@@ -34132,6 +34317,22 @@
34132
34317
  *
34133
34318
  * @private
34134
34319
  */
34320
+ /**
34321
+ * Merge the adjacent rules without minifying the ast: `minify: false` with {@link ParserOptions.mergeRules}. The style
34322
+ * rules that have the same selector, the keyframes rules that have the same selector, the at-rules that have the same
34323
+ * name and prelude (not `@font-face`) and, depending on `mergeRules`, the rules that share declarations are merged. Of
34324
+ * the `@keyframes` that have the same name, the last one is kept. The other minifications are not applied
34325
+ * @param arena
34326
+ * @param ast
34327
+ * @param options
34328
+ *
34329
+ * @private
34330
+ */
34331
+ function mergeRules(arena, ast, options) {
34332
+ return doMinify(arena, ast, { ...options, nestingRules: false, optimizeSelectors: false }, true, undefined, false, {
34333
+ mergeOnly: true,
34334
+ });
34335
+ }
34135
34336
  function doMinify(arena, ast, options = {}, recursive = false, errors, nestingContent, context = {}) {
34136
34337
  if (!("nodes" in context)) {
34137
34338
  context.nodes = new Set();
@@ -34182,7 +34383,7 @@
34182
34383
  }
34183
34384
  // there is no early return: the result that precedes the conditional rules is moved after them.
34184
34385
  // the conditional rules are never removed
34185
- if (equalsIgnoreCase(nam, "function")) {
34386
+ if (!context.mergeOnly && equalsIgnoreCase(nam, "function")) {
34186
34387
  moveResult(arena, node);
34187
34388
  }
34188
34389
  }
@@ -34209,7 +34410,8 @@
34209
34410
  cursor = arena.nextSibling[previous];
34210
34411
  continue;
34211
34412
  }
34212
- let k = arena.firstChild[node];
34413
+ // merge only (see mergeRules()): the declarations are not removed
34414
+ let k = context.mergeOnly ? 0 : arena.firstChild[node];
34213
34415
  while (k !== 0) {
34214
34416
  const next = arena.nextSibling[k];
34215
34417
  if (arena.dataTypes[k] === exports.EnumToken.DeclarationNodeType) {
@@ -34242,7 +34444,8 @@
34242
34444
  (index + 3 < arr.length || arena.dataTypes[arr[index + 2]] === exports.EnumToken.WhitespaceTokenType))
34243
34445
  ? ""
34244
34446
  : renderValue(arena, curr));
34245
- if (nam === "apply") {
34447
+ if (context.mergeOnly) ;
34448
+ else if (nam === "apply") {
34246
34449
  // `@apply --mixin()` is equivalent to `@apply --mixin`
34247
34450
  minifyApplyPrelude(arena, node);
34248
34451
  }
@@ -34284,9 +34487,11 @@
34284
34487
  arena.stringValue[node] = arena.internString(trimArray(arena, tokens).reduce(renderPrelude, ""));
34285
34488
  }
34286
34489
  }
34287
- else if (arena.dataTypes[ast] === nodeType &&
34490
+ if (arena.dataTypes[ast] === nodeType &&
34288
34491
  arena.name[ast] === arena.name[node] &&
34289
- arena.stringValue[ast] === arena.stringValue[node]) {
34492
+ arena.stringValue[ast] === arena.stringValue[node] &&
34493
+ // the at-rules handled above are not replaced when the ast is minified
34494
+ (context.mergeOnly || (nam !== "apply" && nam !== "media" && !(nam === "import" && tokens != null)))) {
34290
34495
  // the node is replaced by its children
34291
34496
  cursor = arena.firstChild[node] || arena.nextSibling[node];
34292
34497
  arena.moveChildren(node, ast, node);
@@ -34318,8 +34523,9 @@
34318
34523
  }
34319
34524
  else if (nodeType === exports.EnumToken.RuleNodeType) {
34320
34525
  // a single selector that does not end with a combinator is not reduced (see isSimpleSelector()): the
34321
- // selector is not read
34322
- if (!isSimpleSelector(arena, arena.name[node])) {
34526
+ // selector is not read. the nesting reads the reduced selectors: optimizeSelectors only applies without it
34527
+ if ((options.optimizeSelectors !== false || options.nestingRules) &&
34528
+ !isSimpleSelector(arena, arena.name[node])) {
34323
34529
  reduceRuleSelector(arena, node);
34324
34530
  }
34325
34531
  let wrapper = null;
@@ -34485,7 +34691,9 @@
34485
34691
  cursor = arena.nextSibling[node];
34486
34692
  continue;
34487
34693
  }
34488
- else if (nodeType === previousType &&
34694
+ else if (options.mergeRules !== false &&
34695
+ options.mergeRules !== exports.MergeRulesEnum.None &&
34696
+ nodeType === previousType &&
34489
34697
  [exports.EnumToken.KeyframesRuleNodeType, exports.EnumToken.RuleNodeType].includes(nodeType)) {
34490
34698
  const intersect = diff(arena, previous, node, options, context);
34491
34699
  if (intersect != null) {
@@ -34528,6 +34736,7 @@
34528
34736
  }
34529
34737
  }
34530
34738
  if (!nestingContent &&
34739
+ !context.mergeOnly &&
34531
34740
  previous != null &&
34532
34741
  arena.dataTypes[previous] === exports.EnumToken.RuleNodeType &&
34533
34742
  arena.stringIndexOf(arena.name[previous], 0x26) !== -1) {
@@ -34545,6 +34754,7 @@
34545
34754
  }
34546
34755
  }
34547
34756
  if (!nestingContent &&
34757
+ !context.mergeOnly &&
34548
34758
  node != null &&
34549
34759
  arena.dataTypes[node] === exports.EnumToken.RuleNodeType &&
34550
34760
  arena.stringIndexOf(arena.name[node], 0x26) !== -1) {
@@ -35138,24 +35348,38 @@
35138
35348
  *
35139
35349
  * @private
35140
35350
  */
35141
- function diff(arena, n1, n2, options, context) {
35142
- // the declarations of a rule that applies a mixin are not moved: `@apply` inserts declarations at its position,
35143
- // the declarations that follow it override them
35144
- if (hasAtRuleStatement(arena, n1) || hasAtRuleStatement(arena, n2)) {
35145
- return null;
35146
- }
35147
- if (!("cache" in options)) {
35148
- options.cache = new Map();
35351
+ /**
35352
+ * the number of declarations of a rule: its children that are not comments
35353
+ * @param arena
35354
+ * @param node
35355
+ */
35356
+ function declarationCount(arena, node) {
35357
+ let count = 0;
35358
+ for (let child = arena.firstChild[node]; child !== 0; child = arena.nextSibling[child]) {
35359
+ if (arena.dataTypes[child] !== exports.EnumToken.CommentNodeType) {
35360
+ count++;
35361
+ }
35149
35362
  }
35150
- let node1 = n1;
35151
- let node2 = n2;
35152
- let exchanged = false;
35153
- if (arena.childCount(node1) > arena.childCount(node2)) {
35154
- const t = node1;
35155
- node1 = node2;
35156
- node2 = t;
35157
- exchanged = true;
35363
+ return count;
35364
+ }
35365
+ /**
35366
+ * clear the matched flag of the children of a rule
35367
+ * @param arena
35368
+ * @param node
35369
+ */
35370
+ function clearMatched(arena, node) {
35371
+ for (let child = arena.firstChild[node]; child !== 0; child = arena.nextSibling[child]) {
35372
+ arena.flags[child] &= ~exports.EnumAstNodeStatus.Matched;
35158
35373
  }
35374
+ }
35375
+ /**
35376
+ * the selectors of both rules have the same vendor prefixes: the rules that do not are not merged (a browser drops a
35377
+ * selector list that contains a pseudo class with an unknown prefix)
35378
+ * @param arena
35379
+ * @param node1
35380
+ * @param node2
35381
+ */
35382
+ function samePrefixes(arena, node1, node2) {
35159
35383
  const raw1 = arena.raw.get(node1);
35160
35384
  const raw2 = arena.raw.get(node2);
35161
35385
  if (raw1 == null || raw2 == null) {
@@ -35164,11 +35388,11 @@
35164
35388
  const prefixes1 = raw1 == null ? selectorPrefixes(arena, arena.name[node1]) : rawSelectorPrefixes(raw1);
35165
35389
  const prefixes2 = raw2 == null ? selectorPrefixes(arena, arena.name[node2]) : rawSelectorPrefixes(raw2);
35166
35390
  if (prefixes1.size !== prefixes2.size) {
35167
- return null;
35391
+ return false;
35168
35392
  }
35169
35393
  for (const prefix of prefixes1) {
35170
35394
  if (!prefixes2.has(prefix)) {
35171
- return null;
35395
+ return false;
35172
35396
  }
35173
35397
  }
35174
35398
  }
@@ -35210,14 +35434,39 @@
35210
35434
  }
35211
35435
  }
35212
35436
  if (prefixes1.size !== prefixes2.size) {
35213
- return null;
35437
+ return false;
35214
35438
  }
35215
35439
  for (const prefix of prefixes1) {
35216
35440
  if (!prefixes2.has(prefix)) {
35217
- return null;
35441
+ return false;
35218
35442
  }
35219
35443
  }
35220
35444
  }
35445
+ return true;
35446
+ }
35447
+ function diff(arena, n1, n2, options, context) {
35448
+ // the declarations of a rule that applies a mixin are not moved: `@apply` inserts declarations at its position,
35449
+ // the declarations that follow it override them
35450
+ if (hasAtRuleStatement(arena, n1) || hasAtRuleStatement(arena, n2)) {
35451
+ return null;
35452
+ }
35453
+ // only the rules that have the same declarations are merged: the rules that have a different number of
35454
+ // declarations are not compared
35455
+ if (options.mergeRules === exports.MergeRulesEnum.Identical && declarationCount(arena, n1) !== declarationCount(arena, n2)) {
35456
+ return null;
35457
+ }
35458
+ if (!("cache" in options)) {
35459
+ options.cache = new Map();
35460
+ }
35461
+ let node1 = n1;
35462
+ let node2 = n2;
35463
+ let exchanged = false;
35464
+ if (arena.childCount(node1) > arena.childCount(node2)) {
35465
+ const t = node1;
35466
+ node1 = node2;
35467
+ node2 = t;
35468
+ exchanged = true;
35469
+ }
35221
35470
  // match the declarations of both rules, from the last to the first
35222
35471
  let matches = 0;
35223
35472
  for (let child1 = arena.lastChild[node1]; child1 !== 0; child1 = arena.previousSibling[child1]) {
@@ -35236,10 +35485,31 @@
35236
35485
  break;
35237
35486
  }
35238
35487
  }
35488
+ // a declaration without a match: the rules are not identical
35489
+ if (options.mergeRules === exports.MergeRulesEnum.Identical && !(arena.flags[child1] & exports.EnumAstNodeStatus.Matched)) {
35490
+ clearMatched(arena, node1);
35491
+ clearMatched(arena, node2);
35492
+ return null;
35493
+ }
35239
35494
  }
35240
35495
  if (matches === 0 && (arena.firstChild[node1] !== 0 || arena.firstChild[node2] !== 0)) {
35241
35496
  return null;
35242
35497
  }
35498
+ // every declaration of both rules is matched: the merged rule replaces both rules, it is always smaller, the sizes
35499
+ // are not computed
35500
+ const identical = matches === declarationCount(arena, node1) && matches === declarationCount(arena, node2);
35501
+ if (!identical && options.mergeRules === exports.MergeRulesEnum.Identical) {
35502
+ // the rules are not merged: the matched declarations are released
35503
+ clearMatched(arena, node1);
35504
+ clearMatched(arena, node2);
35505
+ return null;
35506
+ }
35507
+ // the vendor prefixes are compared once the rules share declarations
35508
+ if (!samePrefixes(arena, node1, node2)) {
35509
+ clearMatched(arena, node1);
35510
+ clearMatched(arena, node2);
35511
+ return null;
35512
+ }
35243
35513
  // the rules are rendered with the same options during the minification: the options are resolved once and
35244
35514
  // identical values are rendered once
35245
35515
  const renderer = (context.renderer ??= new NodeRenderer(options));
@@ -35254,7 +35524,7 @@
35254
35524
  return arena.firstChild[node] === 0 ? 0 : size;
35255
35525
  };
35256
35526
  // size of the original nodes
35257
- const size = renderedSize(n1, true) + renderedSize(n2, true);
35527
+ const size = identical ? 0 : renderedSize(n1, true) + renderedSize(n2, true);
35258
35528
  // the shared declarations are moved into the result node
35259
35529
  const result = arena.cloneNode(node1);
35260
35530
  // the distinct selectors of both rules: built from the code units of the selectors when they are normalized
@@ -35296,7 +35566,9 @@
35296
35566
  // the merge is kept when the output is smaller, or when it has the same size and removes a rule (an emptied rule is
35297
35567
  // removed, its size is 0). the other rule keeps its selector, which is repeated in the merged selector: the merge of
35298
35568
  // `html{margin:0}` and `body,div,...{margin:0;font:inherit}` is larger than the rules
35299
- const mergedSize = renderedSize(node1, false) + renderedSize(node2, false) + renderedSize(result, false);
35569
+ const mergedSize = identical
35570
+ ? 0
35571
+ : renderedSize(node1, false) + renderedSize(node2, false) + renderedSize(result, false);
35300
35572
  if (size < mergedSize ||
35301
35573
  (size === mergedSize && arena.firstChild[node1] !== 0 && arena.firstChild[node2] !== 0)) {
35302
35574
  // restore the nodes: undo the moves in reverse order
@@ -35320,7 +35592,7 @@
35320
35592
  if (arena.optimized.get(result) != null) {
35321
35593
  arena.optimized.set(result, null);
35322
35594
  }
35323
- const optimized = optimizeSelector(splitRule(arena.resolveString(arena.name[result])));
35595
+ const optimized = options.optimizeSelectors === false ? null : optimizeSelector(splitRule(arena.resolveString(arena.name[result])));
35324
35596
  if (optimized?.match) {
35325
35597
  const sel = factorSelector(optimized);
35326
35598
  if (sel != null && sel.length < arena.resolveString(arena.name[result]).length) {
@@ -35671,8 +35943,12 @@
35671
35943
  * @param id selector string id
35672
35944
  */
35673
35945
  function isSimpleSelector(arena, id) {
35946
+ const previousSelectorArena = selectorArena;
35674
35947
  selectorArena = arena;
35675
- return arena.stringFlagId(id, 1 /* StringFlag.SimpleSelector */, computeSimpleSelector);
35948
+ const simple = arena.stringFlagId(id, 1 /* StringFlag.SimpleSelector */, computeSimpleSelector);
35949
+ // the arena is not kept after the minification: the previous arena is restored (a nested call)
35950
+ selectorArena = previousSelectorArena;
35951
+ return simple;
35676
35952
  }
35677
35953
  /**
35678
35954
  * the arena of the selector read by {@link computeSimpleSelector} and {@link hasVendorPrefix}: the functions passed to
@@ -35767,8 +36043,12 @@
35767
36043
  */
35768
36044
  function selectorPrefixes(arena, id) {
35769
36045
  // the selectors without `:-` are skipped: computed once per string id
36046
+ const previousSelectorArena = selectorArena;
35770
36047
  selectorArena = arena;
35771
- if (!arena.stringFlagId(id, 2 /* StringFlag.VendorPrefix */, hasVendorPrefix)) {
36048
+ const prefixed = arena.stringFlagId(id, 2 /* StringFlag.VendorPrefix */, hasVendorPrefix);
36049
+ // the arena is not kept after the minification: the previous arena is restored (a nested call)
36050
+ selectorArena = previousSelectorArena;
36051
+ if (!prefixed) {
35772
36052
  return emptyPrefixes;
35773
36053
  }
35774
36054
  const prefixes = new Set();
@@ -36199,6 +36479,10 @@
36199
36479
  * the high word holds the 24 high bits of the start position and the source
36200
36480
  */
36201
36481
  spans32;
36482
+ /**
36483
+ * create an empty arena
36484
+ * @param size initial number of nodes the columns can hold. the columns grow when they are full
36485
+ */
36202
36486
  constructor(size = 4096) {
36203
36487
  this.dataTypes = new Uint8Array(size);
36204
36488
  this.capacity = size;
@@ -36263,6 +36547,9 @@
36263
36547
  arena.importProperties(properties, transferables);
36264
36548
  return arena;
36265
36549
  }
36550
+ /**
36551
+ * Allocate a node or a token: a released id is reused, the columns grow when the arena is full. Returns the new id
36552
+ */
36266
36553
  allocate() {
36267
36554
  let id = this.freeList;
36268
36555
  if (id !== 0) {
@@ -36290,7 +36577,9 @@
36290
36577
  this.unit[id] = 0;
36291
36578
  this.flags[id] = 0;
36292
36579
  this.colorType[id] = 0;
36293
- this.spans[id] = 0n;
36580
+ // the 32 bits view: no bigint
36581
+ this.spans32[id << 1] = 0;
36582
+ this.spans32[(id << 1) + 1] = 0;
36294
36583
  if (this.errors.size > 0) {
36295
36584
  this.errors.delete(id);
36296
36585
  }
@@ -36333,6 +36622,14 @@
36333
36622
  setSourceText(source, text, codes = null) {
36334
36623
  this.stringTable.setText(source, text, codes);
36335
36624
  }
36625
+ /**
36626
+ * code unit of the text of a source, NaN after its end. no string is created
36627
+ * @param source source index (see {@link getSourceId})
36628
+ * @param offset
36629
+ */
36630
+ sourceCodeAt(source, offset) {
36631
+ return this.stringTable.sourceCodeAt(source, offset);
36632
+ }
36336
36633
  /**
36337
36634
  * drop the code units of a source set by {@link setSourceText}: the source is no longer tokenized
36338
36635
  * @param source source index
@@ -36419,6 +36716,7 @@
36419
36716
  * @param id
36420
36717
  * @param flag
36421
36718
  * @param compute computes the property from the string
36719
+ * @ignore
36422
36720
  */
36423
36721
  stringFlag(id, flag, compute) {
36424
36722
  return this.stringTable.flag(id, flag, compute);
@@ -36428,6 +36726,7 @@
36428
36726
  * @param id
36429
36727
  * @param flag
36430
36728
  * @param compute computes the property from the string id
36729
+ * @ignore
36431
36730
  */
36432
36731
  stringFlagId(id, flag, compute) {
36433
36732
  return this.stringTable.flagId(id, flag, compute);
@@ -36437,6 +36736,7 @@
36437
36736
  * @param id
36438
36737
  * @param slot
36439
36738
  * @param compute computes the value from the string id
36739
+ * @ignore
36440
36740
  */
36441
36741
  stringDerived(id, slot, compute) {
36442
36742
  return this.stringTable.derived(id, slot, compute);
@@ -36474,6 +36774,7 @@
36474
36774
  return this.stringTable.epoch;
36475
36775
  }
36476
36776
  /**
36777
+ * Type of a node or a token, see {@link EnumToken}
36477
36778
  *
36478
36779
  * @param id
36479
36780
  */
@@ -36488,6 +36789,7 @@
36488
36789
  return id == null ? null : this.dataTypes[id];
36489
36790
  }
36490
36791
  /**
36792
+ * Set the type of a node or a token, see {@link EnumToken}
36491
36793
  *
36492
36794
  * @param id
36493
36795
  * @param type
@@ -36496,6 +36798,7 @@
36496
36798
  this.dataTypes[id] = type;
36497
36799
  }
36498
36800
  /**
36801
+ * Set the name of a node or a token: `nameId` is a string table id, see {@link AstArena.internString}
36499
36802
  *
36500
36803
  * @param id
36501
36804
  * @param nameId
@@ -36504,6 +36807,7 @@
36504
36807
  this.name[id] = nameId;
36505
36808
  }
36506
36809
  /**
36810
+ * Name of a node or a token: the name of an at-rule, a declaration, a function, ...
36507
36811
  *
36508
36812
  * @param id
36509
36813
  */
@@ -36511,6 +36815,7 @@
36511
36815
  return this.resolveString(this.name[id]) ?? null;
36512
36816
  }
36513
36817
  /**
36818
+ * Set the value of a node or a token: `valueId` is a string table id, see {@link AstArena.internString}
36514
36819
  *
36515
36820
  * @param id
36516
36821
  * @param valueId
@@ -36519,6 +36824,7 @@
36519
36824
  this.stringValue[id] = valueId;
36520
36825
  }
36521
36826
  /**
36827
+ * Value of a node or a token: the value of an identifier, a string, a hash, ...
36522
36828
  *
36523
36829
  * @param id
36524
36830
  */
@@ -36526,6 +36832,7 @@
36526
36832
  return this.resolveString(this.stringValue[id]) ?? null;
36527
36833
  }
36528
36834
  /**
36835
+ * Set the numeric value of a token
36529
36836
  *
36530
36837
  * @param id
36531
36838
  * @param numericValue
@@ -36534,6 +36841,7 @@
36534
36841
  this.numericValue[id] = numericValue;
36535
36842
  }
36536
36843
  /**
36844
+ * Set the unit of a dimension token: `unit` is a string table id
36537
36845
  *
36538
36846
  * @param id
36539
36847
  * @param unit
@@ -36542,6 +36850,7 @@
36542
36850
  this.unit[id] = unit;
36543
36851
  }
36544
36852
  /**
36853
+ * Unit of a dimension token
36545
36854
  *
36546
36855
  * @param id
36547
36856
  */
@@ -36549,6 +36858,7 @@
36549
36858
  return this.resolveString(this.unit[id]) ?? null;
36550
36859
  }
36551
36860
  /**
36861
+ * Numeric value of a token: number, dimension, percentage, ...
36552
36862
  *
36553
36863
  * @param id
36554
36864
  */
@@ -36556,6 +36866,8 @@
36556
36866
  return this.numericValue[id];
36557
36867
  }
36558
36868
  /**
36869
+ * Set the parent id of a node. The node is not moved: use {@link AstArena.appendChild} or {@link
36870
+ * AstArena.insertBefore} to move it
36559
36871
  *
36560
36872
  * @param id
36561
36873
  * @param parentId
@@ -36638,6 +36950,7 @@
36638
36950
  }
36639
36951
  }
36640
36952
  /**
36953
+ * Last child of a node. 0 when the node has no children
36641
36954
  *
36642
36955
  * @param id
36643
36956
  */
@@ -36720,6 +37033,7 @@
36720
37033
  }
36721
37034
  }
36722
37035
  /**
37036
+ * Set the color type of a color token, see {@link ColorType}
36723
37037
  *
36724
37038
  * @param id
36725
37039
  * @param colorType
@@ -36728,6 +37042,7 @@
36728
37042
  this.colorType[id] = colorType;
36729
37043
  }
36730
37044
  /**
37045
+ * Color type of a color token, see {@link ColorType}
36731
37046
  *
36732
37047
  * @param id
36733
37048
  */
@@ -36735,6 +37050,7 @@
36735
37050
  return this.colorType[id];
36736
37051
  }
36737
37052
  /**
37053
+ * Replace the flags of a node, see {@link EnumAstNodeStatus}
36738
37054
  *
36739
37055
  * @param id
36740
37056
  * @param flags
@@ -36743,6 +37059,7 @@
36743
37059
  this.flags[id] = flags;
36744
37060
  }
36745
37061
  /**
37062
+ * Flags of a node, see {@link EnumAstNodeStatus}
36746
37063
  *
36747
37064
  * @param id
36748
37065
  */
@@ -36750,6 +37067,7 @@
36750
37067
  return this.flags[id];
36751
37068
  }
36752
37069
  /**
37070
+ * `true` when a node has all the given flags, see {@link EnumAstNodeStatus}
36753
37071
  *
36754
37072
  * @param id
36755
37073
  * @param flag
@@ -36758,6 +37076,7 @@
36758
37076
  return (this.flags[id] & flag) === flag;
36759
37077
  }
36760
37078
  /**
37079
+ * The child of a node at a position (0 based). null when the position is out of range
36761
37080
  *
36762
37081
  * @param id
36763
37082
  * @param index
@@ -36879,6 +37198,7 @@
36879
37198
  this.appendTokenList(this.fieldList(id, field), tokens);
36880
37199
  }
36881
37200
  /**
37201
+ * Replace the tokens of the left hand side of a structured token
36882
37202
  *
36883
37203
  * @param id
36884
37204
  * @param children
@@ -36888,6 +37208,7 @@
36888
37208
  this.setTokenList(this.fieldList(id, exports.TokenField.L), children);
36889
37209
  }
36890
37210
  /**
37211
+ * Tokens of the left hand side of a structured token (numerator of a fraction, ...). null when it is not set
36891
37212
  *
36892
37213
  * @param id
36893
37214
  */
@@ -36895,15 +37216,17 @@
36895
37216
  return this.getChildAt(id, exports.TokenField.L) == null ? null : this.fieldTokens(id, exports.TokenField.L);
36896
37217
  }
36897
37218
  /**
37219
+ * Replace the tokens of the right hand side of a structured token. null removes them
36898
37220
  *
36899
- * @param id
36900
- * @param rightId
37221
+ * @param id the structured token
37222
+ * @param rightId the tokens, or null
36901
37223
  */
36902
37224
  setRight(id, ...rightId) {
36903
37225
  // inlined: this.setField(id, TokenField.R, ...(rightId == null || rightId[0] == null ? [] : (rightId as number[])))
36904
37226
  this.setTokenList(this.fieldList(id, exports.TokenField.R), rightId == null || rightId[0] == null ? [] : rightId);
36905
37227
  }
36906
37228
  /**
37229
+ * Tokens of the right hand side of a structured token (denominator of a fraction, ...). null when it is not set
36907
37230
  *
36908
37231
  * @param id
36909
37232
  */
@@ -36911,6 +37234,7 @@
36911
37234
  return this.getChildAt(id, exports.TokenField.R) == null ? null : this.fieldTokens(id, exports.TokenField.R);
36912
37235
  }
36913
37236
  /**
37237
+ * Set the operator token of a structured token
36914
37238
  *
36915
37239
  * @param id
36916
37240
  * @param opId
@@ -36920,6 +37244,7 @@
36920
37244
  this.setTokenList(this.fieldList(id, exports.TokenField.Op), [opId]);
36921
37245
  }
36922
37246
  /**
37247
+ * Operator token of a structured token: the operator of a binary expression, ...
36923
37248
  *
36924
37249
  * @param id
36925
37250
  */
@@ -36927,6 +37252,7 @@
36927
37252
  return this.field(id, exports.TokenField.Op);
36928
37253
  }
36929
37254
  /**
37255
+ * Set the second operator token of a structured token: the second operator of a media range query
36930
37256
  *
36931
37257
  * @param id
36932
37258
  * @param op2Id
@@ -36936,6 +37262,7 @@
36936
37262
  this.setTokenList(this.fieldList(id, exports.TokenField.Op2), [op2Id]);
36937
37263
  }
36938
37264
  /**
37265
+ * Second operator token of a structured token: the second operator of a media range query
36939
37266
  *
36940
37267
  * @param id
36941
37268
  */
@@ -36943,6 +37270,7 @@
36943
37270
  return this.field(id, exports.TokenField.Op2);
36944
37271
  }
36945
37272
  /**
37273
+ * Set the location of a node or a token: the id of its source file and its start and end offsets
36946
37274
  *
36947
37275
  * @param id
36948
37276
  * @param sourceId
@@ -36971,6 +37299,7 @@
36971
37299
  this.spans32[t + 1] = this.spans32[s + 1];
36972
37300
  }
36973
37301
  /**
37302
+ * Id of the source file of a node or a token, see {@link getSpanStart} and {@link getSpanEnd}
36974
37303
  *
36975
37304
  * @param id
36976
37305
  */
@@ -36981,6 +37310,7 @@
36981
37310
  return Number((this.spans[id] >> 56n) & 0xffn);
36982
37311
  }
36983
37312
  /**
37313
+ * Start offset of a node or a token in its source file
36984
37314
  *
36985
37315
  * @param id
36986
37316
  */
@@ -36993,6 +37323,7 @@
36993
37323
  }
36994
37324
  // ---- spans ---------------------------------------------------------------------
36995
37325
  /**
37326
+ * Set the start offset of a node or a token in its source file
36996
37327
  *
36997
37328
  * @param id
36998
37329
  * @param start
@@ -37001,6 +37332,7 @@
37001
37332
  this.setSpan(id, this.getSourceId(id), start, this.getSpanEnd(id));
37002
37333
  }
37003
37334
  /**
37335
+ * End offset of a node or a token in its source file
37004
37336
  *
37005
37337
  * @param id
37006
37338
  */
@@ -37011,6 +37343,7 @@
37011
37343
  return Number(this.spans[id] & 0xfffffffn);
37012
37344
  }
37013
37345
  /**
37346
+ * Set the end offset of a node or a token in its source file
37014
37347
  *
37015
37348
  * @param id
37016
37349
  * @param end
@@ -37019,6 +37352,7 @@
37019
37352
  this.setSpan(id, this.getSourceId(id), this.getSpanStart(id), end);
37020
37353
  }
37021
37354
  /**
37355
+ * Parent of a node. 0 when the node has no parent
37022
37356
  *
37023
37357
  * @param id
37024
37358
  */
@@ -37026,6 +37360,7 @@
37026
37360
  return this.parents[id];
37027
37361
  }
37028
37362
  /**
37363
+ * The string of a string table id. The string is created the first time it is read
37029
37364
  *
37030
37365
  * @param id
37031
37366
  */
@@ -37368,6 +37703,7 @@
37368
37703
  return result;
37369
37704
  }
37370
37705
  /**
37706
+ * The first child of a node for which the predicate returns `true`. null when there is none
37371
37707
  *
37372
37708
  * @param id
37373
37709
  * @param predicate
@@ -37463,6 +37799,7 @@
37463
37799
  return count;
37464
37800
  }
37465
37801
  /**
37802
+ * Replace the children of a node
37466
37803
  *
37467
37804
  * @param id
37468
37805
  * @param children
@@ -37489,6 +37826,7 @@
37489
37826
  this.appendChildList(id, children);
37490
37827
  }
37491
37828
  /**
37829
+ * Replace the tokens of a node or a token
37492
37830
  *
37493
37831
  * @param id
37494
37832
  * @param children
@@ -37538,6 +37876,7 @@
37538
37876
  }
37539
37877
  }
37540
37878
  /**
37879
+ * Append children to a node
37541
37880
  *
37542
37881
  * @param id
37543
37882
  * @param children
@@ -37576,6 +37915,7 @@
37576
37915
  }
37577
37916
  }
37578
37917
  /**
37918
+ * Append tokens to a node or a token
37579
37919
  *
37580
37920
  * @param id
37581
37921
  * @param children
@@ -37680,6 +38020,8 @@
37680
38020
  }
37681
38021
  }
37682
38022
  /**
38023
+ * Compare the name (`"nam"`) or the value (`"val"`) of a node with a string, ignoring the case. The string of the
38024
+ * node is not created
37683
38025
  *
37684
38026
  * @param node
37685
38027
  * @param key
@@ -37690,6 +38032,8 @@
37690
38032
  return this.stringTable.equalsIgnoreCase(key === "nam" ? this.name[node] : this.stringValue[node], string);
37691
38033
  }
37692
38034
  /**
38035
+ * `true` when the name (`"nam"`) or the value (`"val"`) of a node starts with a string. The string of the node is
38036
+ * not created
37693
38037
  *
37694
38038
  * @param node
37695
38039
  * @param key
@@ -37700,6 +38044,7 @@
37700
38044
  return this.stringTable.startsWith(key === "nam" ? this.name[node] : this.stringValue[node], string);
37701
38045
  }
37702
38046
  /**
38047
+ * Grow the columns of the arena so they hold `newSize` ids. The columns are never shrunk
37703
38048
  *
37704
38049
  * @param newSize
37705
38050
  */
@@ -37967,6 +38312,7 @@
37967
38312
  return this.compact(errors);
37968
38313
  }
37969
38314
  /**
38315
+ * Set the validation errors of a node. null or an empty list removes them
37970
38316
  *
37971
38317
  * @param id
37972
38318
  * @param errors
@@ -37981,6 +38327,7 @@
37981
38327
  }
37982
38328
  }
37983
38329
  /**
38330
+ * Validation errors of a node. null when the node has no errors
37984
38331
  *
37985
38332
  * @param id
37986
38333
  */
@@ -38091,8 +38438,8 @@
38091
38438
  */
38092
38439
  inputLengths = [];
38093
38440
  /**
38094
- *
38095
- * @param size
38441
+ * create an arena that holds an empty stylesheet
38442
+ * @param size initial number of nodes the columns can hold. the columns grow when they are full
38096
38443
  */
38097
38444
  constructor(size = 4096) {
38098
38445
  super(size);
@@ -38101,7 +38448,10 @@
38101
38448
  this.flags[this.root] = exports.EnumAstNodeStatus.HasChildren;
38102
38449
  }
38103
38450
  /**
38104
- * @inheritDoc
38451
+ * release nodes: detach them and drop their data (interned strings, errors) and their minification caches. node
38452
+ * ids are never reused: the memory is reclaimed by {@link trim}
38453
+ * @param id the node to release. every marked node (and its descendants) is released when omitted
38454
+ * @param deep release the children and the tokens too
38105
38455
  */
38106
38456
  release(id, deep = false) {
38107
38457
  super.release(id, deep);
@@ -38119,7 +38469,11 @@
38119
38469
  }
38120
38470
  }
38121
38471
  /**
38122
- * @inheritDoc
38472
+ * drop the nodes that are not reachable from the root and renumber the remaining nodes in document order.
38473
+ * the node ids change: ids obtained before the call (from visitors for instance) are no longer valid.
38474
+ * the unused strings and the minification caches are dropped too
38475
+ * @param errors error descriptions whose `node` is remapped
38476
+ * @returns mapping of the old ids to the new ids (0 when the node was dropped)
38123
38477
  */
38124
38478
  compact(errors) {
38125
38479
  const mapping = super.compact(errors);
@@ -39057,7 +39411,7 @@
39057
39411
  return tokens.reduce((acc, curr) => acc + renderValue(this, curr), "");
39058
39412
  }
39059
39413
  /**
39060
- * @inheritDoc
39414
+ * structured-cloneable properties of the arena, the sources and the minification caches included
39061
39415
  */
39062
39416
  exportProperties() {
39063
39417
  return {
@@ -39070,7 +39424,10 @@
39070
39424
  };
39071
39425
  }
39072
39426
  /**
39073
- * @inheritDoc
39427
+ * initialize the arena from exported properties and column buffers, the sources and the minification caches
39428
+ * included
39429
+ * @param properties
39430
+ * @param transferables
39074
39431
  */
39075
39432
  importProperties(properties, transferables) {
39076
39433
  super.importProperties(properties, transferables);
@@ -39478,6 +39835,7 @@
39478
39835
  }
39479
39836
  }
39480
39837
  /**
39838
+ * Replace the nesting selectors (`&`) of a compound selector with a selector
39481
39839
  *
39482
39840
  * @param selector
39483
39841
  * @param replace
@@ -41068,7 +41426,30 @@
41068
41426
  */
41069
41427
  const littleEndian = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
41070
41428
  const decoder = new TextDecoder();
41071
- const nonAscii = /[^\x00-\x7f]/;
41429
+ /**
41430
+ * true if the bytes are ascii. the bytes are read 4 at a time when they are aligned: 5 times faster than a regular
41431
+ * expression on the decoded text
41432
+ * @param bytes
41433
+ */
41434
+ function isAscii(bytes) {
41435
+ const length = bytes.length;
41436
+ let bits = 0;
41437
+ let i = 0;
41438
+ if ((bytes.byteOffset & 3) === 0) {
41439
+ const words = new Uint32Array(bytes.buffer, bytes.byteOffset, length >>> 2);
41440
+ for (let k = 0; k < words.length; k++) {
41441
+ bits |= words[k];
41442
+ }
41443
+ if ((bits & 0x80808080) !== 0) {
41444
+ return false;
41445
+ }
41446
+ i = words.length << 2;
41447
+ }
41448
+ for (; i < length; i++) {
41449
+ bits |= bytes[i];
41450
+ }
41451
+ return (bits & 0x80) === 0;
41452
+ }
41072
41453
  const empty = new Uint8Array(0);
41073
41454
  /**
41074
41455
  * true if the input is an ArrayBuffer or a view of an ArrayBuffer
@@ -41131,11 +41512,46 @@
41131
41512
  const bytes = bytesOf(input);
41132
41513
  const text = decoder.decode(bytes);
41133
41514
  // the text of an ascii input has a character for each byte. the byte order mark is removed by the decoder
41134
- if (text.length === bytes.length && !nonAscii.test(text)) {
41515
+ if (text.length === bytes.length && isAscii(bytes)) {
41135
41516
  return { codes: bytes, text };
41136
41517
  }
41137
41518
  return { codes: codeUnitsOf(text), text };
41138
41519
  }
41520
+ /**
41521
+ * the size of the css of the streams, in bytes, when it is known (a file, a response with a content length)
41522
+ */
41523
+ const streamSizes = new WeakMap();
41524
+ /**
41525
+ * record the size of the css of a stream, in bytes: the parser allocates the code units and the arena once, like for
41526
+ * an ArrayBuffer, instead of growing them as the stream is read. 0: the size is not known
41527
+ * @param stream
41528
+ * @param size
41529
+ */
41530
+ function setStreamSize(stream, size) {
41531
+ if (size > 0) {
41532
+ streamSizes.set(stream, size);
41533
+ }
41534
+ return stream;
41535
+ }
41536
+ /**
41537
+ * the size of the css of a stream, in bytes, see {@link setStreamSize}. 0: the size is not known
41538
+ * @param stream
41539
+ */
41540
+ function getStreamSize(stream) {
41541
+ return stream == null ? 0 : (streamSizes.get(stream) ?? 0);
41542
+ }
41543
+ /**
41544
+ * the size of the body of a response: its content length, 0 when it is not known or when the body is compressed (the
41545
+ * content length is the size of the compressed body)
41546
+ * @param response
41547
+ */
41548
+ function responseSize(response) {
41549
+ if (response.headers.get("content-encoding") != null) {
41550
+ return 0;
41551
+ }
41552
+ const length = Number(response.headers.get("content-length"));
41553
+ return Number.isFinite(length) && length > 0 ? length : 0;
41554
+ }
41139
41555
 
41140
41556
  /**
41141
41557
  * decoded code units of the last value decoded by {@link decodeEscapes}
@@ -41791,17 +42207,52 @@
41791
42207
  hint = null;
41792
42208
  state = null;
41793
42209
  parseInfo;
42210
+ /**
42211
+ * true when the whole css is in {@link ParseInfo.codes}: the input is not a stream, or the stream is read to its end
42212
+ */
42213
+ streamDone = true;
42214
+ /**
42215
+ * the last call of {@link next} reached the end of the code units read from the stream: the token may continue in
42216
+ * the next chunk. no token is returned, the stream must be read ({@link read}) before {@link next} is called again
42217
+ */
42218
+ waiting = false;
42219
+ /**
42220
+ * reader of the stream
42221
+ */
42222
+ reader = null;
42223
+ /**
42224
+ * decoder of the chunks of the stream: a character can be split between two chunks
42225
+ */
42226
+ decoder = null;
42227
+ /**
42228
+ * the code units read from the stream: {@link ParseInfo.codes} is a view of its first {@link ParseInfo.length}
42229
+ * code units. the buffer doubles when it is full, the code units are copied once per doubling
42230
+ */
42231
+ buffer = new Uint8Array(0);
42232
+ /**
42233
+ * the size of the css of the stream, in bytes, when it is known (see {@link setStreamSize}). 0: not known
42234
+ */
42235
+ expectedLength = 0;
41794
42236
  /**
41795
42237
  * @param parseInfo the parse info, or the css: a string, an ArrayBuffer or a view of an ArrayBuffer
41796
42238
  * @param input a stream of css
41797
42239
  */
41798
42240
  constructor(parseInfo, input = null) {
41799
42241
  this.input = input;
42242
+ if (input != null) {
42243
+ this.streamDone = false;
42244
+ this.expectedLength = getStreamSize(input);
42245
+ // the size of the stream is known: the code units are allocated once. the size in bytes is not less than
42246
+ // the number of utf-16 code units
42247
+ if (this.expectedLength > 0) {
42248
+ this.buffer = new Uint8Array(this.expectedLength);
42249
+ }
42250
+ }
41800
42251
  if (isCssInput(parseInfo)) {
41801
42252
  this.parseInfo = createParseInfo(parseInfo, new SourceFile("", [], ""));
41802
42253
  }
41803
42254
  else {
41804
- // the parse info of a stream is loaded by tokenizeStream()
42255
+ // the code units of a stream are appended chunk by chunk, see read()
41805
42256
  if (parseInfo.codes == null && input == null) {
41806
42257
  Tokenizer.load(parseInfo, parseInfo.source.content);
41807
42258
  }
@@ -42699,9 +43150,37 @@
42699
43150
  return this.typ === exports.EnumToken.EOF;
42700
43151
  }
42701
43152
  /**
42702
- * Tokenize CSS string
43153
+ * read the next token. when the input is a stream that is not read to its end, a token that ends near the end of
43154
+ * the code units read so far may continue in the next chunk (an identifier, a number, a string, a comment, ...): the
43155
+ * token is not returned, {@link waiting} is true and the stream must be read ({@link read}) before the next call
42703
43156
  */
42704
- next( /* parseInfo: ParseInfo | string, yieldEOFToken: boolean = true */) {
43157
+ next() {
43158
+ if (this.streamDone) {
43159
+ return this.nextToken();
43160
+ }
43161
+ const parseInfo = this.parseInfo;
43162
+ const position = parseInfo.position;
43163
+ const currentPosition = parseInfo.currentPosition;
43164
+ const state = this.state;
43165
+ const lineStarts = parseInfo.source.lineStarts.lineStarts;
43166
+ const lineCount = lineStarts.length;
43167
+ this.nextToken();
43168
+ // the tokenizer reads at most a few code units after the end of a token: the token is complete when the
43169
+ // stream has more code units after it
43170
+ if (parseInfo.currentPosition + STREAM_LOOKAHEAD > parseInfo.length) {
43171
+ parseInfo.position = position;
43172
+ parseInfo.currentPosition = currentPosition;
43173
+ this.state = state;
43174
+ lineStarts.length = lineCount;
43175
+ this.typ = null;
43176
+ this.waiting = true;
43177
+ }
43178
+ return this;
43179
+ }
43180
+ /**
43181
+ * read the next token from the code units of the input
43182
+ */
43183
+ nextToken() {
42705
43184
  const parseInfo = this.parseInfo;
42706
43185
  this.source = parseInfo.source;
42707
43186
  let charCode;
@@ -43128,27 +43607,106 @@
43128
43607
  return this.makeToken(parseInfo, exports.EnumToken.EOFTokenType);
43129
43608
  }
43130
43609
  /**
43131
- * tokenize readable stream
43610
+ * start reading the stream: the first chunk is read. the next chunks are read when the tokenizer reaches the end
43611
+ * of the code units read so far, see {@link next} and {@link read}
43132
43612
  */
43133
43613
  async tokenizeStream() {
43134
- const decoder = new TextDecoder("utf-8");
43135
- const reader = this.input.getReader();
43136
- let parseInfo = this.parseInfo;
43137
- while (true) {
43138
- const { done, value } = await reader.read();
43139
- const stream = ArrayBuffer.isView(value) ? decoder.decode(value, { stream: true }) : value;
43140
- if (!done) {
43141
- // inlined: parseInfo.source.append(stream as string)
43142
- parseInfo.source.content += stream;
43143
- }
43144
- else {
43614
+ if (!this.streamDone && this.reader == null) {
43615
+ await this.read();
43616
+ }
43617
+ return this;
43618
+ }
43619
+ /**
43620
+ * read the next chunk of the stream and append it to the css: the text of the source file and the code units.
43621
+ * the code units stay a view of the bytes while the css is ascii, they are utf-16 code units otherwise
43622
+ */
43623
+ async read() {
43624
+ if (this.streamDone) {
43625
+ this.waiting = false;
43626
+ return;
43627
+ }
43628
+ if (this.reader == null) {
43629
+ this.reader = this.input.getReader();
43630
+ this.decoder = new TextDecoder("utf-8");
43631
+ }
43632
+ // the chunks are appended together: at least 64 KB, or half of the css read so far. the text of the css is copied
43633
+ // when it is read after a chunk is appended (a string is not appended in place): the batches grow with the css,
43634
+ // the text is copied a few times instead of once per chunk
43635
+ const batch = Math.max(STREAM_BATCH, this.parseInfo.length >> 1);
43636
+ const texts = [];
43637
+ let length = 0;
43638
+ while (length < batch) {
43639
+ const { done, value } = await this.reader.read();
43640
+ if (done) {
43641
+ // the end of a character split between the last chunks
43642
+ texts.push(this.decoder.decode());
43643
+ this.streamDone = true;
43644
+ this.reader.releaseLock();
43145
43645
  break;
43146
43646
  }
43647
+ const text = typeof value === "string" ? value : this.decoder.decode(value, { stream: true });
43648
+ texts.push(text);
43649
+ length += text.length;
43650
+ }
43651
+ const text = texts.length === 1 ? texts[0] : texts.join("");
43652
+ if (text.length > 0) {
43653
+ this.append(text);
43654
+ }
43655
+ this.waiting = false;
43656
+ }
43657
+ /**
43658
+ * append the text of a chunk to the css
43659
+ * @param text
43660
+ */
43661
+ append(text) {
43662
+ const parseInfo = this.parseInfo;
43663
+ const length = parseInfo.length;
43664
+ const required = length + text.length;
43665
+ parseInfo.source.content += text;
43666
+ if (required > this.buffer.length) {
43667
+ let capacity = this.buffer.length > 0 ? this.buffer.length * 2 : 1 << 16;
43668
+ while (capacity < required) {
43669
+ capacity *= 2;
43670
+ }
43671
+ const buffer = this.buffer instanceof Uint8Array ? new Uint8Array(capacity) : new Uint16Array(capacity);
43672
+ buffer.set(this.buffer.subarray(0, length));
43673
+ this.buffer = buffer;
43674
+ }
43675
+ let ascii = false;
43676
+ if (this.buffer instanceof Uint8Array) {
43677
+ // an ascii text has a byte for each character
43678
+ const { read, written } = streamEncoder.encodeInto(text, this.buffer.subarray(length, required));
43679
+ ascii = read === text.length && written === text.length;
43680
+ if (!ascii) {
43681
+ // the css is not ascii: the code units are utf-16 code units from now on
43682
+ const buffer = new Uint16Array(this.buffer.length);
43683
+ buffer.set(this.buffer.subarray(0, length));
43684
+ this.buffer = buffer;
43685
+ }
43147
43686
  }
43148
- Tokenizer.load(parseInfo, parseInfo.source.content);
43149
- return this; // .next();
43687
+ if (!ascii) {
43688
+ const buffer = this.buffer;
43689
+ for (let i = 0; i < text.length; i++) {
43690
+ buffer[length + i] = text.charCodeAt(i);
43691
+ }
43692
+ }
43693
+ parseInfo.length = required;
43694
+ parseInfo.codes = this.buffer.subarray(0, required);
43150
43695
  }
43151
43696
  }
43697
+ /**
43698
+ * number of code units the tokenizer may read after the end of a token (escape sequences, unicode ranges, `<!--`,
43699
+ * ...): a token read from a stream is complete when the stream has more code units after it, see {@link Tokenizer.next}
43700
+ */
43701
+ const STREAM_LOOKAHEAD = 32;
43702
+ /**
43703
+ * minimum number of code units appended to the css when a stream is read, see {@link Tokenizer.read}
43704
+ */
43705
+ const STREAM_BATCH = 1 << 16;
43706
+ /**
43707
+ * encoder of the chunks of a stream, see {@link Tokenizer.append}
43708
+ */
43709
+ const streamEncoder = new TextEncoder();
43152
43710
 
43153
43711
  /**
43154
43712
  * response type
@@ -43450,6 +44008,58 @@
43450
44008
  }
43451
44009
  }
43452
44010
  }
44011
+ /**
44012
+ * true if the token is a keyframe selector: `from`, `to` or a percentage between 0 and 100
44013
+ * @param arena
44014
+ * @param token
44015
+ */
44016
+ function isKeyframeSelectorToken(arena, token) {
44017
+ if (token === undefined) {
44018
+ return false;
44019
+ }
44020
+ if (arena.dataTypes[token] === exports.EnumToken.PercentageTokenType) {
44021
+ return arena.numericValue[token] >= 0 && arena.numericValue[token] <= 100;
44022
+ }
44023
+ if (arena.dataTypes[token] !== exports.EnumToken.IdenTokenType) {
44024
+ return false;
44025
+ }
44026
+ const id = arena.stringValue[token];
44027
+ const length = arena.stringLength(id);
44028
+ // `from` and `to`, case-insensitive
44029
+ return length === 4
44030
+ ? (arena.stringCodeAt(id, 0) | 0x20) === 0x66 &&
44031
+ (arena.stringCodeAt(id, 1) | 0x20) === 0x72 &&
44032
+ (arena.stringCodeAt(id, 2) | 0x20) === 0x6f &&
44033
+ (arena.stringCodeAt(id, 3) | 0x20) === 0x6d
44034
+ : length === 2 && (arena.stringCodeAt(id, 0) | 0x20) === 0x74 && (arena.stringCodeAt(id, 1) | 0x20) === 0x6f;
44035
+ }
44036
+ /**
44037
+ * true if the selector of a keyframe is a list of `from`, `to` and percentages between 0 and 100, separated by commas
44038
+ * and whitespace: it matches the `keyframe-selectors` syntax
44039
+ * @param arena
44040
+ * @param tokens
44041
+ */
44042
+ function isSimpleKeyframeSelector(arena, tokens) {
44043
+ // a keyframe selector is expected
44044
+ let selector = true;
44045
+ let i = 0;
44046
+ for (; i < tokens.length; i++) {
44047
+ const type = arena.dataTypes[tokens[i]];
44048
+ if (type === exports.EnumToken.WhitespaceTokenType) {
44049
+ continue;
44050
+ }
44051
+ if (selector) {
44052
+ if (!isKeyframeSelectorToken(arena, tokens[i])) {
44053
+ return false;
44054
+ }
44055
+ }
44056
+ else if (type !== exports.EnumToken.CommaTokenType) {
44057
+ return false;
44058
+ }
44059
+ selector = !selector;
44060
+ }
44061
+ return !selector;
44062
+ }
43453
44063
  /**
43454
44064
  * parse selector
43455
44065
  * @param arena
@@ -43462,7 +44072,10 @@
43462
44072
  const contextType = context == null ? null : arena.dataTypes[context];
43463
44073
  splitUnicodeRanges(arena, tokens);
43464
44074
  if (contextType === exports.EnumToken.KeyframesAtRuleNodeType) {
43465
- const result = matchAllSyntaxes(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "keyframe-selectors"), createValidationContext(arena, tokens), options);
44075
+ // `from`, `to` and the percentages are valid: the syntax is not matched
44076
+ const result = isSimpleKeyframeSelector(arena, tokens)
44077
+ ? { success: true, errors: [] }
44078
+ : matchAllSyntaxes(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "keyframe-selectors"), createValidationContext(arena, tokens), options);
43466
44079
  const parts = splitTokenList(arena, tokens);
43467
44080
  for (const part of parts) {
43468
44081
  trimArray(arena, part);
@@ -43510,8 +44123,11 @@
43510
44123
  allowed = false;
43511
44124
  if (contextType === exports.EnumToken.AtRuleNodeType) {
43512
44125
  // computed once per at-rule name: the name is not concatenated for each selector
44126
+ const previousAtRuleArena = atRuleArena;
43513
44127
  atRuleArena = arena;
43514
44128
  allowed = arena.stringDerived(arena.name[context], 3 /* StringDerived.AtRuleAcceptsRules */, atRuleAcceptsRules);
44129
+ // the arena is not kept after the parse: the previous arena is restored (a nested call)
44130
+ atRuleArena = previousAtRuleArena;
43515
44131
  }
43516
44132
  }
43517
44133
  while (parent != null && parent > 0) {
@@ -43612,9 +44228,11 @@
43612
44228
  }
43613
44229
  tokens.length = write;
43614
44230
  }
43615
- const result = matchSelectorSyntax(arena, tokens, errors, options, nested);
44231
+ // a selector made of simple selectors is valid, it has no attribute selector and no function
44232
+ const simple = matchSimpleSelector(arena, tokens);
44233
+ const result = simple ? simpleSelectorMatch : matchSelectorSyntax(arena, tokens, errors, options, nested);
43616
44234
  trimArray(arena, tokens);
43617
- if (result.success) {
44235
+ if (result.success && !simple) {
43618
44236
  for (let i = 0; i < tokens.length; i++) {
43619
44237
  const token = tokens[i];
43620
44238
  switch (arena.dataTypes[token]) {
@@ -43667,7 +44285,7 @@
43667
44285
  }
43668
44286
  }
43669
44287
  }
43670
- const node = arena.createRule(exports.EnumToken.RuleNodeType, renderSelector(arena, tokens), tokens, result.success && allowed
44288
+ const node = arena.createRule(exports.EnumToken.RuleNodeType, simple ? renderSimpleSelector(arena, tokens) : renderSelector(arena, tokens), tokens, result.success && allowed
43671
44289
  ? exports.EnumAstNodeStatus.Validated
43672
44290
  : allowed
43673
44291
  ? exports.EnumAstNodeStatus.Invalid
@@ -43676,6 +44294,13 @@
43676
44294
  arena.setLocation(node, arena.sources[arena.getSourceId(tokens[0])] ?? 0, arena.getSpanStart(tokens[0]), arena.getSpanEnd(tokens[tokens.length - 1]));
43677
44295
  return node;
43678
44296
  }
44297
+ /**
44298
+ * result of the validation of a simple selector, see {@link matchSimpleSelector}
44299
+ */
44300
+ const simpleSelectorMatch = Object.freeze({
44301
+ success: true,
44302
+ errors: Object.freeze([]),
44303
+ });
43679
44304
  // options of the rendering of the selector tokens
43680
44305
  const selectorRenderOptions = { minify: false };
43681
44306
  /**
@@ -43699,7 +44324,7 @@
43699
44324
  const rules = syntaxRule?.getBlockRules?.();
43700
44325
  if (rules != null) {
43701
44326
  for (const rule of rules) {
43702
- if (ValidationTokenEnum.PropertyType === rule.typ &&
44327
+ if (exports.ValidationTokenEnum.PropertyType === rule.typ &&
43703
44328
  ("block-contents" === rule.val ||
43704
44329
  "rule-list" === rule.val)) {
43705
44330
  return true;
@@ -43940,6 +44565,31 @@
43940
44565
  selectorOffsets[selectors * 2 + 1] = end;
43941
44566
  return selectors + 1;
43942
44567
  }
44568
+ /**
44569
+ * selector of a rule made of simple selectors (see {@link matchSimpleSelector}), without the leading and the trailing
44570
+ * whitespace: the string of a single token is used as is, a compound or a complex selector is built without
44571
+ * {@link renderSelector}. a selector list is rendered with {@link renderSelector}: the duplicate selectors are removed
44572
+ * @param arena
44573
+ * @param tokens
44574
+ * @returns the interned string id of the selector
44575
+ */
44576
+ function renderSimpleSelector(arena, tokens) {
44577
+ if (tokens.length === 1) {
44578
+ const type = arena.dataTypes[tokens[0]];
44579
+ // rendered as their string by appendSelectorToken()
44580
+ if (type !== exports.EnumToken.PseudoElementTokenType) {
44581
+ return arena.stringValue[tokens[0]];
44582
+ }
44583
+ }
44584
+ selectorBuilder.reset();
44585
+ for (let index = 0; index < tokens.length; index++) {
44586
+ if (arena.dataTypes[tokens[index]] === exports.EnumToken.CommaTokenType) {
44587
+ return renderSelector(arena, tokens);
44588
+ }
44589
+ appendSelectorToken(arena, tokens[index], selectorBuilder);
44590
+ }
44591
+ return arena.internBuilder(selectorBuilder);
44592
+ }
43943
44593
  /**
43944
44594
  * selector of a rule: the distinct comma separated selectors, the whitespace around the combinators is removed.
43945
44595
  * a universal selector is removed before a compound selector. the selector is built from the code units of the
@@ -44150,7 +44800,7 @@
44150
44800
  // else
44151
44801
  if (syntaxRules == null ||
44152
44802
  (syntaxRules.length === 1 &&
44153
- syntaxRules[0].typ === ValidationTokenEnum.PropertyType &&
44803
+ syntaxRules[0].typ === exports.ValidationTokenEnum.PropertyType &&
44154
44804
  (syntaxRules[0].val === "declaration-list" ||
44155
44805
  syntaxRules[0].val === "declaration-rule-list" ||
44156
44806
  syntaxRules[0].val === "block-contents"))) {
@@ -44519,7 +45169,47 @@
44519
45169
  i++;
44520
45170
  }
44521
45171
  // [not | only] <media-type> [ and <media-condition-without-or> ]?
44522
- if (i < stream.length) {
45172
+ let modifier = null;
45173
+ if (i < stream.length && arena.dataTypes[stream[i]] === exports.EnumToken.IdenTokenType) {
45174
+ const val = arena.resolveString(arena.stringValue[stream[i]]).toLowerCase();
45175
+ if (val === "not" || val === "only") {
45176
+ modifier = val;
45177
+ tokens.push(stream[i]);
45178
+ i++;
45179
+ while (i < stream.length &&
45180
+ (arena.dataTypes[stream[i]] === exports.EnumToken.WhitespaceTokenType ||
45181
+ arena.dataTypes[stream[i]] === exports.EnumToken.CommentTokenType)) {
45182
+ tokens.push(stream[i]);
45183
+ i++;
45184
+ }
45185
+ }
45186
+ }
45187
+ if (modifier != null && i === stream.length) {
45188
+ success = false;
45189
+ errors.push({
45190
+ action: "drop",
45191
+ message: `expecting '<media-type>'`,
45192
+ node: stream[i - 1],
45193
+ location: [
45194
+ options.source.file,
45195
+ ...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[i - 1])),
45196
+ ],
45197
+ });
45198
+ }
45199
+ else if (modifier === "only" && arena.dataTypes[stream[i]] !== exports.EnumToken.IdenTokenType) {
45200
+ // only is followed by a media type
45201
+ success = false;
45202
+ errors.push({
45203
+ action: "drop",
45204
+ message: `expecting '<media-type>'`,
45205
+ node: stream[i],
45206
+ location: [
45207
+ options.source.file,
45208
+ ...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[i])),
45209
+ ],
45210
+ });
45211
+ }
45212
+ else if (i < stream.length) {
44523
45213
  if (arena.dataTypes[stream[i]] === exports.EnumToken.IdenTokenType) {
44524
45214
  const val = arena.resolveString(arena.stringValue[stream[i]]).toLowerCase();
44525
45215
  if (mediaTypes.includes(val)) {
@@ -46132,7 +46822,8 @@
46132
46822
  * @param tokenizer
46133
46823
  */
46134
46824
  function arenaCapacity(tokenizer) {
46135
- const length = tokenizer.streamLength;
46825
+ // a stream: the size of the css when it is known, the arena is allocated as for an ArrayBuffer
46826
+ const length = Math.max(tokenizer.streamLength, tokenizer.expectedLength);
46136
46827
  // small inputs (css modules, inline styles, ...) do not allocate a large arena, the arena grows when needed
46137
46828
  return length === 0 ? 4096 : Math.min(1 << 25, Math.ceil(length / 4) + 1024);
46138
46829
  }
@@ -46174,6 +46865,29 @@
46174
46865
  }
46175
46866
  return item;
46176
46867
  }
46868
+ /**
46869
+ * allocate a whitespace token
46870
+ * @param arena
46871
+ * @param sourceIndex index of the source in the arena sources table
46872
+ * @param start
46873
+ * @param end
46874
+ */
46875
+ function allocateWhitespace(arena, sourceIndex, start, end) {
46876
+ const item = arena.allocate();
46877
+ arena.dataTypes[item] = exports.EnumToken.WhitespaceTokenType;
46878
+ arena.setTokenLocation(item, sourceIndex, start, end);
46879
+ return item;
46880
+ }
46881
+ /**
46882
+ * true if the token ends a statement or a block: the whitespace that precedes it is not significant
46883
+ * @param type
46884
+ */
46885
+ function isStatementEnd(type) {
46886
+ return (type === exports.EnumToken.SemiColonTokenType ||
46887
+ type === exports.EnumToken.BlockStartTokenType ||
46888
+ type === exports.EnumToken.BlockEndTokenType ||
46889
+ type === exports.EnumToken.EOFTokenType);
46890
+ }
46177
46891
  /**
46178
46892
  * recycle the tokens of a statement that were not attached to the tree: their ids are reused by the next allocations.
46179
46893
  * the tokens referenced by the errors or the invalid nodes of the statement are kept
@@ -46185,6 +46899,8 @@
46185
46899
  * @param invalidStart index of the first invalid node of the statement
46186
46900
  */
46187
46901
  function recycleStatementTokens(arena, tokens, errors, errorStart, invalidNodes, invalidStart) {
46902
+ // the statement has errors or invalid nodes: the tokens they reference are kept
46903
+ const references = errors.length > errorStart || invalidNodes.length > invalidStart;
46188
46904
  for (let i = 0; i < tokens.length; i++) {
46189
46905
  const token = tokens[i];
46190
46906
  // already recycled (a token can be recorded twice), attached or holding other tokens
@@ -46194,6 +46910,10 @@
46194
46910
  arena.firstToken[token] !== 0) {
46195
46911
  continue;
46196
46912
  }
46913
+ if (!references) {
46914
+ arena.recycle(token);
46915
+ continue;
46916
+ }
46197
46917
  let referenced = invalidNodes.indexOf(token, invalidStart) !== -1;
46198
46918
  for (let j = errorStart; !referenced && j < errors.length; j++) {
46199
46919
  referenced = errors[j].node === token;
@@ -46637,6 +47357,14 @@
46637
47357
  }
46638
47358
  return result;
46639
47359
  }
47360
+ /**
47361
+ * the settings of the fast mode (see {@link ParserOptions.fastMode}): the default values of these options when
47362
+ * `fastMode` is `true`
47363
+ */
47364
+ const fastModeOptions = Object.freeze({
47365
+ minify: false,
47366
+ mergeRules: exports.MergeRulesEnum.None,
47367
+ });
46640
47368
  /**
46641
47369
  * Parse css string
46642
47370
  * @param tokenizer
@@ -46647,6 +47375,8 @@
46647
47375
  */
46648
47376
  function doParseSync(tokenizer, options = {}) {
46649
47377
  if (options.signal != null) {
47378
+ // an aborted signal does not dispatch the abort event
47379
+ options.signal.throwIfAborted();
46650
47380
  options.signal.addEventListener("abort", reject);
46651
47381
  }
46652
47382
  options = {
@@ -46671,6 +47401,7 @@
46671
47401
  removePrefix: false,
46672
47402
  validation: false,
46673
47403
  lenient: true,
47404
+ ...(options.fastMode ? fastModeOptions : null),
46674
47405
  ...options,
46675
47406
  };
46676
47407
  options.validation = !!options.validation;
@@ -46722,13 +47453,34 @@
46722
47453
  // the strings of the tokens are ranges of the content of the source
46723
47454
  arena.setSourceText(sourceIndex, tokenizer.content, tokenizer.codes);
46724
47455
  let itemType;
47456
+ // whitespace outside of parentheses, at the start of a statement or before ';', '{' and '}' is not significant: it
47457
+ // is not allocated. the whitespace that follows a token is allocated when the next token is read
47458
+ let whitespaceStart = -1;
47459
+ let whitespaceEnd = 0;
46725
47460
  // inlined: tokenizer.done()
46726
47461
  while (!(tokenizer.typ === exports.EnumToken.EOF)) {
46727
47462
  tokenizer.next();
46728
- item = allocateToken(arena, tokenizer, sourceIndex);
46729
47463
  itemType = tokenizer.typ;
46730
47464
  stats.bytesIn = tokenizer.bytesIn;
46731
47465
  stats.tokensCount++;
47466
+ if (parensMatch === 0) {
47467
+ if (itemType === exports.EnumToken.WhitespaceTokenType) {
47468
+ if (tokens.length > 0) {
47469
+ whitespaceStart = tokenizer.sta;
47470
+ whitespaceEnd = tokenizer.end;
47471
+ }
47472
+ continue;
47473
+ }
47474
+ if (whitespaceStart !== -1) {
47475
+ if (!isStatementEnd(itemType)) {
47476
+ item = allocateWhitespace(arena, sourceIndex, whitespaceStart, whitespaceEnd);
47477
+ tokens.push(item);
47478
+ statement.push(item);
47479
+ }
47480
+ whitespaceStart = -1;
47481
+ }
47482
+ }
47483
+ item = allocateToken(arena, tokenizer, sourceIndex);
46732
47484
  if (isBadToken(itemType)) {
46733
47485
  tokens.push(item);
46734
47486
  statement.push(item);
@@ -47022,6 +47774,13 @@
47022
47774
  }
47023
47775
  }
47024
47776
  }
47777
+ else if (options.mergeRules != null &&
47778
+ options.mergeRules !== false &&
47779
+ options.mergeRules !== exports.MergeRulesEnum.None &&
47780
+ arena.firstChild[ast] !== 0) {
47781
+ // the ast is not minified: the adjacent rules are merged
47782
+ mergeRules(arena, ast, minifyOptions);
47783
+ }
47025
47784
  stats.bytesIn += stats.importedBytesIn;
47026
47785
  // the source is no longer tokenized: the code units are not kept
47027
47786
  arena.releaseSourceCodes(sourceIndex);
@@ -47577,6 +48336,8 @@
47577
48336
  */
47578
48337
  async function doParse(iter, options = {}) {
47579
48338
  if (options.signal != null) {
48339
+ // an aborted signal does not dispatch the abort event
48340
+ options.signal.throwIfAborted();
47580
48341
  options.signal.addEventListener("abort", reject);
47581
48342
  }
47582
48343
  options = {
@@ -47602,6 +48363,7 @@
47602
48363
  removePrefix: false,
47603
48364
  validation: false,
47604
48365
  lenient: true,
48366
+ ...(options.fastMode ? fastModeOptions : null),
47605
48367
  ...options,
47606
48368
  };
47607
48369
  options.minifyAST ??= options.minify;
@@ -47658,13 +48420,41 @@
47658
48420
  // the strings of the tokens are ranges of the content of the source
47659
48421
  arena.setSourceText(sourceIndex, tokenizer.content, tokenizer.codes);
47660
48422
  let itemType;
48423
+ // whitespace outside of parentheses, at the start of a statement or before ';', '{' and '}' is not significant: it
48424
+ // is not allocated. the whitespace that follows a token is allocated when the next token is read
48425
+ let whitespaceStart = -1;
48426
+ let whitespaceEnd = 0;
47661
48427
  // inlined: tokenizer.done()
47662
48428
  while (!(tokenizer.typ === exports.EnumToken.EOF)) {
47663
48429
  tokenizer.next();
47664
- item = allocateToken(arena, tokenizer, sourceIndex);
48430
+ // a stream: the token may continue in the next chunk, the chunk is read and the token is read again
48431
+ if (tokenizer.waiting) {
48432
+ await tokenizer.read();
48433
+ // the strings of the tokens are ranges of the content read so far
48434
+ arena.setSourceText(sourceIndex, tokenizer.content, tokenizer.codes);
48435
+ continue;
48436
+ }
47665
48437
  itemType = tokenizer.typ;
47666
48438
  stats.bytesIn = tokenizer.bytesIn;
47667
48439
  stats.tokensCount++;
48440
+ if (parensMatch === 0) {
48441
+ if (itemType === exports.EnumToken.WhitespaceTokenType) {
48442
+ if (tokens.length > 0) {
48443
+ whitespaceStart = tokenizer.sta;
48444
+ whitespaceEnd = tokenizer.end;
48445
+ }
48446
+ continue;
48447
+ }
48448
+ if (whitespaceStart !== -1) {
48449
+ if (!isStatementEnd(itemType)) {
48450
+ item = allocateWhitespace(arena, sourceIndex, whitespaceStart, whitespaceEnd);
48451
+ tokens.push(item);
48452
+ statement.push(item);
48453
+ }
48454
+ whitespaceStart = -1;
48455
+ }
48456
+ }
48457
+ item = allocateToken(arena, tokenizer, sourceIndex);
47668
48458
  if (isBadToken(itemType)) {
47669
48459
  tokens.push(item);
47670
48460
  statement.push(item);
@@ -47726,6 +48516,11 @@
47726
48516
  tokens.push(item);
47727
48517
  do {
47728
48518
  tokenizer.next();
48519
+ if (tokenizer.waiting) {
48520
+ await tokenizer.read();
48521
+ arena.setSourceText(sourceIndex, tokenizer.content, tokenizer.codes);
48522
+ continue;
48523
+ }
47729
48524
  item = allocateToken(arena, tokenizer, sourceIndex);
47730
48525
  itemType = tokenizer.typ;
47731
48526
  tokens.push(item);
@@ -48018,6 +48813,13 @@
48018
48813
  }
48019
48814
  }
48020
48815
  }
48816
+ else if (options.mergeRules != null &&
48817
+ options.mergeRules !== false &&
48818
+ options.mergeRules !== exports.MergeRulesEnum.None &&
48819
+ arena.firstChild[ast] !== 0) {
48820
+ // the ast is not minified: the adjacent rules are merged
48821
+ mergeRules(arena, ast, minifyOptions);
48822
+ }
48021
48823
  stats.bytesIn += stats.importedBytesIn;
48022
48824
  // the source is no longer tokenized: the code units are not kept
48023
48825
  arena.releaseSourceCodes(sourceIndex);
@@ -48981,10 +49783,7 @@
48981
49783
  if (stream.length === 0 ||
48982
49784
  arena.dataTypes[stream[0]] !== exports.EnumToken.WhitespaceTokenType ||
48983
49785
  arena.getSpanEnd(stream[0]) - arena.getSpanStart(stream[0]) !== 1 ||
48984
- // inlined: arena.getSource(stream[0]), options.sourcesMap?.get(...)?.getContent()
48985
- options.sourcesMap
48986
- ?.get(arena.sources[arena.getSourceId(stream[0])] ?? 0)
48987
- ?.content.charCodeAt(arena.getSpanStart(stream[0])) !== 0x20) {
49786
+ arena.sourceCodeAt(arena.getSourceId(stream[0]), arena.getSpanStart(stream[0])) !== 0x20) {
48988
49787
  success = false;
48989
49788
  errors.push({
48990
49789
  action: "drop",
@@ -49392,8 +50191,7 @@
49392
50191
  }
49393
50192
  else {
49394
50193
  context = createValidationContext(arena, stream, index);
49395
- // @ts-ignore
49396
- range = context.peekRange((t) => arena.dataTypes[t] === exports.EnumToken.EndParensTokenType);
50194
+ range = context.peekRange(exports.EnumToken.EndParensTokenType);
49397
50195
  // inlined: arena.typeOf(range.at(-1))
49398
50196
  if (arena.dataTypes[range.at(-1)] !== exports.EnumToken.EndParensTokenType) {
49399
50197
  errors.push({
@@ -50108,7 +50906,7 @@
50108
50906
  /**
50109
50907
  * Version number
50110
50908
  */
50111
- const version = "2.3.0";
50909
+ const version = "2.3.2";
50112
50910
 
50113
50911
  /**
50114
50912
  * Load file or url
@@ -50150,7 +50948,10 @@
50150
50948
  if (responseType === exports.ResponseType.JSON) {
50151
50949
  return response.json();
50152
50950
  }
50153
- return responseType === exports.ResponseType.ReadableStream ? response.body : response.text();
50951
+ // the size of the body: the parser allocates its buffers once
50952
+ return responseType === exports.ResponseType.ReadableStream
50953
+ ? setStreamSize(response.body, responseSize(response))
50954
+ : response.text();
50154
50955
  });
50155
50956
  }
50156
50957
  /**
@@ -50287,7 +51088,8 @@
50287
51088
  validateSyncArguments(options);
50288
51089
  }
50289
51090
  // the options of the caller are not modified: they may be reused
50290
- options = { minify: true, removeEmpty: true, removeCharset: true, ...options };
51091
+ // the fast mode sets the default value of minify (see fastModeOptions)
51092
+ options = { ...(options?.fastMode ? null : { minify: true }), removeEmpty: true, removeCharset: true, ...options };
50291
51093
  const startTime = performance.now();
50292
51094
  const parseResult = parseSyncInput(stream, options);
50293
51095
  let mapping = null;
@@ -50434,7 +51236,8 @@
50434
51236
  stream = input;
50435
51237
  }
50436
51238
  }
50437
- options = { minify: true, removeEmpty: true, removeCharset: true, ...options };
51239
+ // the fast mode sets the default value of minify (see fastModeOptions)
51240
+ options = { ...(options?.fastMode ? null : { minify: true }), removeEmpty: true, removeCharset: true, ...options };
50438
51241
  const startTime = performance.now();
50439
51242
  return parseInput(stream, options).then((parseResult) => {
50440
51243
  let mapping = null;
@@ -50465,6 +51268,7 @@
50465
51268
  exports.Arena = Arena;
50466
51269
  exports.AstArena = AstArena;
50467
51270
  exports.AstArenaNode = AstArenaNode;
51271
+ exports.LOC = LOC;
50468
51272
  exports.PropertyList = PropertyList;
50469
51273
  exports.RenderResult = RenderResult;
50470
51274
  exports.SourceMap = SourceMap;