@tbela99/css-parser 2.0.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/CHANGELOG.md +86 -1
  2. package/README.md +15 -7
  3. package/architecture.png +0 -0
  4. package/dist/{src/data → data}/properties.json.js +86 -2
  5. package/dist/{src/data → data}/validation.json.js +4848 -3750
  6. package/dist/index-umd-web.js +18234 -9498
  7. package/dist/index.d.ts +1251 -373
  8. package/dist/{src/lib → lib}/ast/arena-node.js +119 -57
  9. package/dist/{src/lib → lib}/ast/arena.js +1034 -655
  10. package/dist/{src/lib → lib}/ast/cache.js +36 -31
  11. package/dist/{src/lib → lib}/ast/features/calc.js +37 -27
  12. package/dist/{src/lib → lib}/ast/features/if.js +24 -19
  13. package/dist/{src/lib → lib}/ast/features/index.js +3 -2
  14. package/dist/{src/lib → lib}/ast/features/inlinecssvariables.js +42 -23
  15. package/dist/lib/ast/features/mixin.js +953 -0
  16. package/dist/{src/lib → lib}/ast/features/prefix.js +82 -69
  17. package/dist/lib/ast/features/shorthand.js +129 -0
  18. package/dist/lib/ast/features/transform.js +188 -0
  19. package/dist/{src/lib → lib}/ast/features/type.js +2 -2
  20. package/dist/{src/lib → lib}/ast/math/expression.js +150 -150
  21. package/dist/{src/lib → lib}/ast/math/math.js +8 -8
  22. package/dist/{src/lib → lib}/ast/minify.js +932 -354
  23. package/dist/lib/ast/mixins/custom-function.js +393 -0
  24. package/dist/lib/ast/mixins/utils.js +53 -0
  25. package/dist/lib/ast/mixins/variables.js +678 -0
  26. package/dist/lib/ast/strings.js +906 -0
  27. package/dist/lib/ast/transform/compute.js +560 -0
  28. package/dist/lib/ast/transform/matrix.js +67 -0
  29. package/dist/lib/ast/transform/minify.js +325 -0
  30. package/dist/lib/ast/transform/perspective.js +24 -0
  31. package/dist/{src/lib → lib}/ast/transform/rotate.js +16 -7
  32. package/dist/lib/ast/transform/scale.js +43 -0
  33. package/dist/lib/ast/transform/skew.js +38 -0
  34. package/dist/lib/ast/transform/translate.js +56 -0
  35. package/dist/lib/ast/transform/utils.js +390 -0
  36. package/dist/{src/lib → lib}/ast/types.js +7 -15
  37. package/dist/{src/lib → lib}/ast/walk.js +19 -19
  38. package/dist/{src/lib → lib}/fs/resolve.js +15 -15
  39. package/dist/{src/lib → lib}/parser/declaration/list.js +55 -26
  40. package/dist/{src/lib → lib}/parser/declaration/map.js +85 -72
  41. package/dist/{src/lib → lib}/parser/declaration/set.js +32 -27
  42. package/dist/lib/parser/input.js +85 -0
  43. package/dist/{src/lib → lib}/parser/linesmap.js +3 -16
  44. package/dist/{src/lib → lib}/parser/parse.js +852 -619
  45. package/dist/lib/parser/source.js +71 -0
  46. package/dist/{src/lib → lib}/parser/tokenize.js +886 -722
  47. package/dist/{src/lib → lib}/parser/utils/angle.js +3 -3
  48. package/dist/{src/lib → lib}/parser/utils/at-rule-container.js +68 -35
  49. package/dist/{src/lib → lib}/parser/utils/at-rule-font-feature-values.js +3 -3
  50. package/dist/{src/lib → lib}/parser/utils/at-rule-generic.js +31 -13
  51. package/dist/{src/lib → lib}/parser/utils/at-rule-import.js +29 -16
  52. package/dist/{src/lib → lib}/parser/utils/at-rule-media.js +77 -58
  53. package/dist/{src/lib → lib}/parser/utils/at-rule-support.js +18 -20
  54. package/dist/{src/lib → lib}/parser/utils/at-rule-when-else.js +9 -8
  55. package/dist/{src/lib → lib}/parser/utils/at-rule.js +3 -3
  56. package/dist/{src/lib → lib}/parser/utils/base64.js +2 -2
  57. package/dist/lib/parser/utils/cache.js +53 -0
  58. package/dist/lib/parser/utils/canonical.js +78 -0
  59. package/dist/lib/parser/utils/codes.js +93 -0
  60. package/dist/{src/lib → lib}/parser/utils/config.js +2 -2
  61. package/dist/{src/lib → lib}/parser/utils/declaration.js +67 -49
  62. package/dist/{src/lib → lib}/parser/utils/eq.js +14 -14
  63. package/dist/{src/lib → lib}/parser/utils/hash.js +4 -4
  64. package/dist/lib/parser/utils/selector.js +720 -0
  65. package/dist/{src/lib → lib}/parser/utils/text.js +2 -2
  66. package/dist/{src/lib → lib}/parser/utils/token.js +2 -2
  67. package/dist/{src/lib → lib}/parser/utils/type.js +11 -9
  68. package/dist/{src/lib → lib}/printer/render.js +536 -243
  69. package/dist/lib/printer/result.js +148 -0
  70. package/dist/{src/lib → lib}/printer/sourcemap/lib/codec.js +5 -8
  71. package/dist/{src/lib → lib}/printer/sourcemap/sourcemap.js +13 -13
  72. package/dist/lib/printer/writer.js +252 -0
  73. package/dist/{src/lib → lib}/syntax/color/a98rgb.js +6 -6
  74. package/dist/{src/lib → lib}/syntax/color/alpha.js +12 -11
  75. package/dist/{src/lib → lib}/syntax/color/cmyk.js +11 -6
  76. package/dist/{src/lib → lib}/syntax/color/color-mix.js +78 -67
  77. package/dist/{src/lib → lib}/syntax/color/color.js +52 -47
  78. package/dist/{src/lib → lib}/syntax/color/hex.js +17 -17
  79. package/dist/{src/lib → lib}/syntax/color/hsl.js +8 -8
  80. package/dist/{src/lib → lib}/syntax/color/hwb.js +6 -7
  81. package/dist/{src/lib → lib}/syntax/color/lab.js +8 -8
  82. package/dist/{src/lib → lib}/syntax/color/lch.js +12 -11
  83. package/dist/{src/lib → lib}/syntax/color/oklab.js +9 -9
  84. package/dist/{src/lib → lib}/syntax/color/oklch.js +5 -5
  85. package/dist/{src/lib → lib}/syntax/color/p3.js +2 -2
  86. package/dist/{src/lib → lib}/syntax/color/prophotorgb.js +4 -4
  87. package/dist/{src/lib → lib}/syntax/color/rec2020.js +3 -3
  88. package/dist/{src/lib → lib}/syntax/color/relative-color.js +41 -34
  89. package/dist/{src/lib → lib}/syntax/color/rgb.js +17 -17
  90. package/dist/{src/lib → lib}/syntax/color/srgb.js +20 -20
  91. package/dist/{src/lib → lib}/syntax/color/utils/color-type.js +6 -4
  92. package/dist/{src/lib → lib}/syntax/color/utils/colorspace.js +12 -14
  93. package/dist/{src/lib → lib}/syntax/color/utils/components.js +13 -13
  94. package/dist/{src/lib → lib}/syntax/color/utils/distance.js +2 -2
  95. package/dist/{src/lib → lib}/syntax/color/utils/make-color.js +6 -4
  96. package/dist/{src/lib → lib}/syntax/color/utils/matrix.js +2 -2
  97. package/dist/{src/lib → lib}/syntax/color/xyz.js +5 -10
  98. package/dist/{src/lib → lib}/syntax/color/xyzd50.js +3 -3
  99. package/dist/{src/lib → lib}/syntax/constants.js +30 -3
  100. package/dist/{src/lib → lib}/syntax/syntax.js +151 -116
  101. package/dist/lib/validation/config.js +173 -0
  102. package/dist/lib/validation/first.js +571 -0
  103. package/dist/{src/lib → lib}/validation/match.js +1256 -579
  104. package/dist/{src/lib → lib}/validation/parser/parse.js +85 -59
  105. package/dist/{src/lib → lib}/validation/parser/typedef.js +6 -2
  106. package/dist/{src/lib → lib}/validation/utils/list.js +3 -19
  107. package/dist/{src/node.js → node.js} +92 -80
  108. package/dist/{src/types.js → types.js} +2 -2
  109. package/dist/{src/utils → utils}/sync.js +13 -8
  110. package/dist/version.d.ts +4 -0
  111. package/dist/version.js +13 -0
  112. package/dist/{src/web.js → web.js} +80 -75
  113. package/package.json +13 -13
  114. package/dist/package.json.js +0 -10
  115. package/dist/src/lib/ast/features/shorthand.js +0 -87
  116. package/dist/src/lib/ast/features/transform.js +0 -85
  117. package/dist/src/lib/ast/transform/compute.js +0 -358
  118. package/dist/src/lib/ast/transform/matrix.js +0 -88
  119. package/dist/src/lib/ast/transform/minify.js +0 -267
  120. package/dist/src/lib/ast/transform/perspective.js +0 -16
  121. package/dist/src/lib/ast/transform/scale.js +0 -39
  122. package/dist/src/lib/ast/transform/skew.js +0 -30
  123. package/dist/src/lib/ast/transform/translate.js +0 -39
  124. package/dist/src/lib/ast/transform/utils.js +0 -287
  125. package/dist/src/lib/parser/source.js +0 -127
  126. package/dist/src/lib/parser/utils/cache.js +0 -54
  127. package/dist/src/lib/parser/utils/selector.js +0 -440
  128. package/dist/src/lib/validation/config.js +0 -120
@@ -1,8 +1,8 @@
1
1
  /*
2
- CSS parser, minifier and validator for node and the browser
2
+ CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.0.1
5
+ Version: 2.2.0
6
6
  License: MIT
7
7
  */
8
8
  import { TokenField } from '../ast/arena.js';
@@ -29,7 +29,6 @@ const timeUnits = ["ms", "s"];
29
29
  const angleUnits = ["rad", "turn", "deg", "grad"];
30
30
  const resolutionUnits = ["dpi", "dpcm", "dppx", "x"];
31
31
  const dimensionUnits = [
32
- "Q",
33
32
  "cap",
34
33
  "ch",
35
34
  "cm",
@@ -54,16 +53,23 @@ const dimensionUnits = [
54
53
  "lvh",
55
54
  "lvi",
56
55
  "lvmax",
56
+ "lvmin",
57
57
  "lvw",
58
58
  "mm",
59
59
  "pc",
60
60
  "pt",
61
61
  "px",
62
+ "Q",
63
+ "rcap",
64
+ "rch",
62
65
  "rem",
66
+ "rex",
67
+ "ric",
63
68
  "rlh",
64
69
  "svb",
65
70
  "svh",
66
71
  "svi",
72
+ "svmax",
67
73
  "svmin",
68
74
  "svw",
69
75
  "vb",
@@ -500,52 +506,69 @@ const pseudoAliasMap = {
500
506
  // "-moz-windows-glass",
501
507
  // "-moz-alt-content",
502
508
  // ]);
503
- // renamed standard properties
504
- const renamedStandardProperties = new Map([["color-adjust", "print-color-adjust"]]);
509
+ // renamed standard properties: the legacy name aliases of webref that are not vendor prefixed (see scripts/webref.ts),
510
+ // updated manually. the vendor prefixed aliases are not renamed: they use the syntax of the standard property (alias)
511
+ const renamedStandardProperties = new Map([
512
+ ["color-adjust", "print-color-adjust"],
513
+ ["font-stretch", "font-width"],
514
+ ["grid-column-gap", "column-gap"],
515
+ ["grid-gap", "gap"],
516
+ ["grid-row-gap", "row-gap"],
517
+ ["word-wrap", "overflow-wrap"],
518
+ ]);
519
+ /**
520
+ * the units of each dimension, lower case: the units are case-insensitive (`Q`, `Hz`, `kHz`)
521
+ */
522
+ const lengthUnitSet = new Set(dimensionUnits.map((unit) => unit.toLowerCase()));
523
+ const resolutionUnitSet = new Set(resolutionUnits.map((unit) => unit.toLowerCase()));
524
+ const angleUnitSet = new Set(angleUnits.map((unit) => unit.toLowerCase()));
525
+ const timeUnitSet = new Set(timeUnits.map((unit) => unit.toLowerCase()));
526
+ const frequencyUnitSet = new Set(frequencyUnits.map((unit) => unit.toLowerCase()));
527
+ const flexUnitSet = new Set(flexUnits.map((unit) => unit.toLowerCase()));
505
528
  /**
506
529
  * true if the unit is a length unit
507
530
  * @param unit
508
531
  */
509
532
  function isLengthUnit(unit) {
510
- return dimensionUnits.includes(unit.toLowerCase());
533
+ return lengthUnitSet.has(unit.toLowerCase());
511
534
  }
512
535
  /**
513
536
  * true if the unit is a resolution unit
514
537
  * @param unit
515
538
  */
516
539
  function isResolutionUnit(unit) {
517
- return resolutionUnits.includes(unit.toLowerCase());
540
+ return resolutionUnitSet.has(unit.toLowerCase());
518
541
  }
519
542
  /**
520
543
  * true if the unit is an angle unit
521
544
  * @param unit
522
545
  */
523
546
  function isAngleUnit(unit) {
524
- return angleUnits.includes(unit.toLowerCase());
547
+ return angleUnitSet.has(unit.toLowerCase());
525
548
  }
526
549
  /**
527
550
  * true if the unit is a time unit
528
551
  * @param unit
529
552
  */
530
553
  function isTimeUnit(unit) {
531
- return timeUnits.includes(unit.toLowerCase());
554
+ return timeUnitSet.has(unit.toLowerCase());
532
555
  }
533
556
  /**
534
557
  * true if the unit is a frequency unit
535
558
  * @param unit
536
559
  */
537
560
  function isFrequencyUnit(unit) {
538
- return frequencyUnits.includes(unit.toLowerCase());
561
+ return frequencyUnitSet.has(unit.toLowerCase());
539
562
  }
540
563
  /**
541
564
  * true if the unit is a flex unit
542
565
  * @param unit
543
566
  */
544
567
  function isFlexUnit(unit) {
545
- return "fr" == unit.toLowerCase();
568
+ return flexUnitSet.has(unit.toLowerCase());
546
569
  }
547
570
  function isLength(arena, dimension) {
548
- return arena.unit[dimension] != 0 && isLengthUnit(arena.strings[arena.unit[dimension]]);
571
+ return arena.unit[dimension] !== 0 && isLengthUnit(arena.resolveString(arena.unit[dimension]));
549
572
  }
550
573
  /**
551
574
  * Reduce color stops
@@ -555,18 +578,18 @@ function isLength(arena, dimension) {
555
578
  */
556
579
  function reduceColorStops(arena, stops) {
557
580
  const parts = splitTokenList(arena, stops);
558
- const n = parts.length == 1 ? 1 : parts.length - 1;
581
+ const n = parts.length === 1 ? 1 : parts.length - 1;
559
582
  let j;
560
583
  let i;
561
584
  let k = -1;
562
585
  let updated = false;
563
586
  for (i = 0; i < parts.length; i++) {
564
587
  k++;
565
- if (parts[i].length != 3) {
588
+ if (parts[i].length !== 3) {
566
589
  continue;
567
590
  }
568
591
  if (i > 0 && isOkLabClose(arena, parts[i - 1][0], parts[i][0])) {
569
- if (parts[i - 1].length == 1) {
592
+ if (parts[i - 1].length === 1) {
570
593
  parts[i - 1].push(arena.createToken(EnumToken.WhitespaceTokenType), arena.createToken(EnumToken.PercentageTokenType, ((k - 1) * 100) / n));
571
594
  }
572
595
  for (let m = 1; m < parts[i].length; m++) {
@@ -578,9 +601,9 @@ function reduceColorStops(arena, stops) {
578
601
  }
579
602
  for (j = 0; j < parts[i].length; j++) {
580
603
  const typ = arena.dataTypes[parts[i][j]];
581
- if ((typ == EnumToken.LengthTokenType && 0 == arena.numericValue[parts[i][j]]) ||
582
- typ == EnumToken.NumberTokenType ||
583
- typ == EnumToken.PercentageTokenType) {
604
+ if ((typ === EnumToken.LengthTokenType && 0 === arena.numericValue[parts[i][j]]) ||
605
+ typ === EnumToken.NumberTokenType ||
606
+ typ === EnumToken.PercentageTokenType) {
584
607
  if (arena.numericValue[parts[i][j]] === (k * 100) / n) {
585
608
  parts[i].length = j;
586
609
  trimArray(arena, parts[i]);
@@ -676,18 +699,18 @@ function reducegradientBackgroundPosition(arena, positions, position) {
676
699
  */
677
700
  function reduceConicColorStops(arena, stops) {
678
701
  const parts = splitTokenList(arena, stops);
679
- const n = parts.length == 1 ? 1 : parts.length - 1;
702
+ const n = parts.length === 1 ? 1 : parts.length - 1;
680
703
  let j;
681
704
  let i;
682
705
  let k = -1;
683
706
  let updated = false;
684
707
  for (i = 0; i < parts.length; i++) {
685
708
  k++;
686
- if (parts[i].length != 3) {
709
+ if (parts[i].length !== 3) {
687
710
  continue;
688
711
  }
689
712
  if (i > 0 && isOkLabClose(arena, parts[i - 1][0], parts[i][0])) {
690
- if (parts[i - 1].length == 1) {
713
+ if (parts[i - 1].length === 1) {
691
714
  parts[i - 1].push(arena.createToken(EnumToken.WhitespaceTokenType), arena.createToken(EnumToken.AngleTokenType, ((k - 1) * 100) / n, "deg"));
692
715
  }
693
716
  for (let m = 1; m < parts[i].length; m++) {
@@ -699,8 +722,8 @@ function reduceConicColorStops(arena, stops) {
699
722
  }
700
723
  for (j = 0; j < parts[i].length; j++) {
701
724
  const typ = arena.dataTypes[parts[i][j]];
702
- if ((typ == EnumToken.NumberTokenType && 0 == arena.numericValue[parts[i][j]]) ||
703
- typ == EnumToken.AngleTokenType) {
725
+ if ((typ === EnumToken.NumberTokenType && 0 === arena.numericValue[parts[i][j]]) ||
726
+ typ === EnumToken.AngleTokenType) {
704
727
  if (arena.numericValue[toDegrees(arena, parts[i][j])] === (k * 360) / n) {
705
728
  parts[i].length = j;
706
729
  trimArray(arena, parts[i]);
@@ -731,7 +754,7 @@ function reduceConicColorStops(arena, stops) {
731
754
  */
732
755
  function isRectangularOrthogonalColorspace(arena, token) {
733
756
  return (arena.dataTypes[token] === EnumToken.IdenTokenType &&
734
- colorFuncColorSpace.some((t) => equalsIgnoreCase(t, arena.strings[arena.stringValue[token]])));
757
+ colorFuncColorSpace.some((t) => equalsIgnoreCase(t, arena.resolveString(arena.stringValue[token]))));
735
758
  }
736
759
  /**
737
760
  * Is polar colorspace
@@ -741,7 +764,7 @@ function isRectangularOrthogonalColorspace(arena, token) {
741
764
  */
742
765
  function isPolarColorspace(arena, token) {
743
766
  return (arena.dataTypes[token] === EnumToken.IdenTokenType &&
744
- ["hsl", "hwb", "lch", "oklch"].some((t) => equalsIgnoreCase(t, arena.strings[arena.stringValue[token]])));
767
+ ["hsl", "hwb", "lch", "oklch"].some((t) => equalsIgnoreCase(t, arena.resolveString(arena.stringValue[token]))));
745
768
  }
746
769
  /**
747
770
  * Is ident color
@@ -750,10 +773,22 @@ function isPolarColorspace(arena, token) {
750
773
  * @returns
751
774
  */
752
775
  function isIdentColor(arena, token) {
753
- return (arena.dataTypes[token] == EnumToken.ColorTokenType &&
754
- arena.colorType[token] != ColorType.NONE &&
776
+ return (arena.dataTypes[token] === EnumToken.ColorTokenType &&
777
+ arena.colorType[token] !== ColorType.NONE &&
755
778
  [ColorType.SYS, ColorType.DPSYS, ColorType.LIT].includes(arena.colorType[token]) &&
756
- isIdent(arena.strings[arena.stringValue[token]]));
779
+ isIdent(arena.resolveString(arena.stringValue[token])));
780
+ }
781
+ /**
782
+ * true if the identifier is a color: a system color, a named color, `currentcolor` or `transparent`, ignoring the case
783
+ * @param str
784
+ */
785
+ function isColorName(str) {
786
+ const val = lowercase(str);
787
+ if (systemColors.has(val) || deprecatedSystemColors.has(val) || nonStandardColors.has(val)) {
788
+ return true;
789
+ }
790
+ // named color
791
+ return val in COLORS_NAMES || "currentcolor" === val || "transparent" === val;
757
792
  }
758
793
  /**
759
794
  * color function arguments without whitespace and comments
@@ -763,7 +798,7 @@ function isIdentColor(arena, token) {
763
798
  */
764
799
  function filterChildren(arena, token, types) {
765
800
  const children = [];
766
- for (let t = arena.firstToken[token]; t != 0; t = arena.nextSibling[t]) {
801
+ for (let t = arena.firstToken[token]; t !== 0; t = arena.nextSibling[t]) {
767
802
  if (types.includes(arena.dataTypes[t])) {
768
803
  children.push(t);
769
804
  }
@@ -783,25 +818,21 @@ const colorKeywords = [
783
818
  ];
784
819
  function isColor(arena, token, errors) {
785
820
  const typ = arena.dataTypes[token];
786
- if (typ == EnumToken.WildCardFunctionTokenType) {
821
+ if (typ === EnumToken.WildCardFunctionTokenType) {
787
822
  return true;
788
823
  }
789
- if (typ == EnumToken.ColorTokenType) {
790
- if (arena.colorType[token] != ColorType.NONE && arena.firstToken[token] == 0) {
824
+ if (typ === EnumToken.ColorTokenType) {
825
+ if (arena.colorType[token] !== ColorType.NONE && arena.firstToken[token] === 0) {
791
826
  return true;
792
827
  }
793
828
  }
794
- if (typ == EnumToken.IdenTokenType) {
795
- const val = lowercase(arena.strings[arena.stringValue[token]]);
796
- if (systemColors.has(val) || deprecatedSystemColors.has(val) || nonStandardColors.has(val)) {
797
- return true;
798
- }
799
- // named color
800
- return val in COLORS_NAMES || "currentcolor" === val || "transparent" === val;
829
+ if (typ === EnumToken.IdenTokenType) {
830
+ // computed once per string id
831
+ return arena.stringFlag(arena.stringValue[token], 0 /* StringFlag.Color */, isColorName);
801
832
  }
802
833
  if (typ === EnumToken.FunctionTokenType || typ === EnumToken.ColorTokenType) {
803
- if (arena.firstToken[token] != 0) {
804
- const name = arena.strings[arena.stringValue[token]];
834
+ if (arena.firstToken[token] !== 0) {
835
+ const name = arena.resolveString(arena.stringValue[token]);
805
836
  if (name === "light-dark") {
806
837
  const children = filterChildren(arena, token, [
807
838
  EnumToken.IdenTokenType,
@@ -812,7 +843,7 @@ function isColor(arena, token, errors) {
812
843
  EnumToken.PercentageTokenType,
813
844
  EnumToken.WildCardFunctionTokenType,
814
845
  ]);
815
- if (children.length != 2) {
846
+ if (children.length !== 2) {
816
847
  errors?.push({
817
848
  message: "light-dark function must have 2 arguments",
818
849
  node: token,
@@ -832,7 +863,7 @@ function isColor(arena, token, errors) {
832
863
  if (colorSpace != null) {
833
864
  for (const value of components) {
834
865
  if (arena.dataTypes[value] === EnumToken.IdenTokenType) {
835
- const val = arena.strings[arena.stringValue[value]].toLowerCase();
866
+ const val = arena.resolveString(arena.stringValue[value]).toLowerCase();
836
867
  if (
837
868
  // @ts-expect-error
838
869
  typeof Math[val.toUpperCase()] !== "number" &&
@@ -849,12 +880,12 @@ function isColor(arena, token, errors) {
849
880
  }
850
881
  }
851
882
  else if (arena.dataTypes[value] === EnumToken.MathFunctionTokenType &&
852
- equalsIgnoreCase("calc", arena.strings[arena.stringValue[value]])) {
883
+ equalsIgnoreCase("calc", arena.resolveString(arena.stringValue[value]))) {
853
884
  let val;
854
885
  // inlined: arena.walkValues(arena.tokens(value))
855
886
  for (const v of new ValueWalker(arena, arena.tokens(value))) {
856
887
  if (arena.dataTypes[v] === EnumToken.IdenTokenType) {
857
- val = arena.strings[arena.stringValue[v]].toLowerCase();
888
+ val = arena.resolveString(arena.stringValue[v]).toLowerCase();
858
889
  if (
859
890
  // @ts-expect-error
860
891
  typeof Math[val.toUpperCase()] !== "number" &&
@@ -890,9 +921,9 @@ function isColor(arena, token, errors) {
890
921
  tl = arena.field(value, TokenField.R);
891
922
  }
892
923
  else if (parent != null &&
893
- parent != token &&
924
+ parent !== token &&
894
925
  arena.dataTypes[parent] === EnumToken.MathFunctionTokenType &&
895
- arena.strings[arena.stringValue[parent]] === "calc") {
926
+ arena.resolveString(arena.stringValue[parent]) === "calc") {
896
927
  const children = arena.tokens(parent);
897
928
  l = k + 1;
898
929
  while (l + 1 < children.length) {
@@ -911,7 +942,7 @@ function isColor(arena, token, errors) {
911
942
  tk = children[k];
912
943
  tl = children[l];
913
944
  }
914
- if (tk != 0 && tl != 0 && tk != null && tl != null) {
945
+ if (tk !== 0 && tl !== 0 && tk != null && tl != null) {
915
946
  if ((arena.dataTypes[tk] === EnumToken.PercentageTokenType ||
916
947
  arena.dataTypes[tl] === EnumToken.PercentageTokenType) &&
917
948
  arena.dataTypes[tk] !== arena.dataTypes[tl]) {
@@ -924,7 +955,7 @@ function isColor(arena, token, errors) {
924
955
  }
925
956
  }
926
957
  }
927
- if (name == "color") {
958
+ if (name === "color") {
928
959
  const children = filterChildren(arena, token, [
929
960
  EnumToken.DashedIdenTokenType,
930
961
  EnumToken.IdenTokenType,
@@ -935,13 +966,13 @@ function isColor(arena, token, errors) {
935
966
  EnumToken.MathFunctionTokenType,
936
967
  EnumToken.PercentageTokenType,
937
968
  ]);
938
- const isRelative = arena.dataTypes[children[0]] == EnumToken.IdenTokenType &&
939
- arena.strings[arena.stringValue[children[0]]] == "from";
969
+ const isRelative = arena.dataTypes[children[0]] === EnumToken.IdenTokenType &&
970
+ arena.resolveString(arena.stringValue[children[0]]) === "from";
940
971
  let offset = 0;
941
972
  if (isRelative) {
942
973
  offset = 2;
943
974
  }
944
- if (offset < children.length && arena.dataTypes[children[offset]] == EnumToken.DashedIdenTokenType) {
975
+ if (offset < children.length && arena.dataTypes[children[offset]] === EnumToken.DashedIdenTokenType) {
945
976
  if (children.length <= offset + 1) {
946
977
  errors?.push({
947
978
  action: "drop",
@@ -952,30 +983,30 @@ function isColor(arena, token, errors) {
952
983
  }
953
984
  for (let i = offset + 1; i < children.length; i++) {
954
985
  const childType = arena.dataTypes[children[i]];
955
- if (childType == EnumToken.NumberTokenType ||
956
- childType == EnumToken.LiteralTokenType ||
957
- childType == EnumToken.ColorTokenType ||
958
- childType == EnumToken.FunctionTokenType ||
959
- childType == EnumToken.MathFunctionTokenType ||
960
- childType == EnumToken.PercentageTokenType ||
986
+ if (childType === EnumToken.NumberTokenType ||
987
+ childType === EnumToken.LiteralTokenType ||
988
+ childType === EnumToken.ColorTokenType ||
989
+ childType === EnumToken.FunctionTokenType ||
990
+ childType === EnumToken.MathFunctionTokenType ||
991
+ childType === EnumToken.PercentageTokenType ||
961
992
  isColor(arena, children[i]) ||
962
- (childType == EnumToken.IdenTokenType &&
963
- equalsIgnoreCase("none", arena.strings[arena.stringValue[children[i]]]))) {
993
+ (childType === EnumToken.IdenTokenType &&
994
+ equalsIgnoreCase("none", arena.resolveString(arena.stringValue[children[i]])))) {
964
995
  continue;
965
996
  }
966
997
  return false;
967
998
  }
968
999
  return true;
969
1000
  }
970
- if (children.length == 4 || (isRelative && children.length == 6)) {
1001
+ if (children.length === 4 || (isRelative && children.length === 6)) {
971
1002
  return true;
972
1003
  }
973
1004
  return true;
974
1005
  }
975
- else if (name == "color-mix") {
1006
+ else if (name === "color-mix") {
976
1007
  const children = [[]];
977
- for (let t = arena.firstToken[token]; t != 0; t = arena.nextSibling[t]) {
978
- if (arena.dataTypes[t] == EnumToken.CommaTokenType) {
1008
+ for (let t = arena.firstToken[token]; t !== 0; t = arena.nextSibling[t]) {
1009
+ if (arena.dataTypes[t] === EnumToken.CommaTokenType) {
979
1010
  children.push([]);
980
1011
  }
981
1012
  else if (![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(arena.dataTypes[t])) {
@@ -986,20 +1017,20 @@ function isColor(arena, token, errors) {
986
1017
  let k = 0;
987
1018
  if (children[j].length > 0 &&
988
1019
  arena.dataTypes[children[j][0]] === EnumToken.IdenTokenType &&
989
- equalsIgnoreCase("in", arena.strings[arena.stringValue[children[j][k]]])) {
1020
+ equalsIgnoreCase("in", arena.resolveString(arena.stringValue[children[j][k]]))) {
990
1021
  k++;
991
1022
  if (k < children[j].length && arena.dataTypes[children[j][k]] === EnumToken.IdenTokenType) {
992
1023
  if (!isRectangularOrthogonalColorspace(arena, children[j][k])) {
993
1024
  if (isPolarColorspace(arena, children[j][k++])) {
994
- if (k == children[j].length) ;
1025
+ if (k === children[j].length) ;
995
1026
  else if (arena.dataTypes[children[j][k]] !== EnumToken.IdenTokenType) {
996
1027
  return false;
997
1028
  }
998
- else if (equalsIgnoreCase("hue", arena.strings[arena.stringValue[children[j][k]]])) {
1029
+ else if (equalsIgnoreCase("hue", arena.resolveString(arena.stringValue[children[j][k]]))) {
999
1030
  k++;
1000
1031
  }
1001
1032
  else {
1002
- switch (arena.strings[arena.stringValue[children[j][k]]]) {
1033
+ switch (arena.resolveString(arena.stringValue[children[j][k]])) {
1003
1034
  case "increasing":
1004
1035
  case "decreasing":
1005
1036
  case "longer":
@@ -1011,7 +1042,7 @@ function isColor(arena, token, errors) {
1011
1042
  }
1012
1043
  if (k >= children[j].length ||
1013
1044
  arena.dataTypes[children[j][k]] !== EnumToken.IdenTokenType ||
1014
- !equalsIgnoreCase("hue", arena.strings[arena.stringValue[children[j][k]]])) {
1045
+ !equalsIgnoreCase("hue", arena.resolveString(arena.stringValue[children[j][k]]))) {
1015
1046
  return false;
1016
1047
  }
1017
1048
  k++;
@@ -1039,7 +1070,7 @@ function isColor(arena, token, errors) {
1039
1070
  function parseColor(arena, token) {
1040
1071
  const typ = arena.dataTypes[token];
1041
1072
  if (typ === EnumToken.IdenTokenType) {
1042
- const val = arena.strings[arena.stringValue[token]].toLowerCase();
1073
+ const val = arena.resolveString(arena.stringValue[token]).toLowerCase();
1043
1074
  if (nonStandardColors.has(val)) {
1044
1075
  arena.dataTypes[token] = EnumToken.ColorTokenType;
1045
1076
  // inlined: arena.setColorType(token, ColorType.NON_STD)
@@ -1068,27 +1099,27 @@ function parseColor(arena, token) {
1068
1099
  }
1069
1100
  }
1070
1101
  if (typ === EnumToken.ColorTokenType) {
1071
- const val = arena.strings[arena.stringValue[token]];
1072
- if (arena.colorType[token] == ColorType.NONE && arena.stringValue[token] != 0) {
1102
+ const val = arena.resolveString(arena.stringValue[token]);
1103
+ if (arena.colorType[token] === ColorType.NONE && arena.stringValue[token] !== 0) {
1073
1104
  // inlined: arena.setColorType(token, ColorType[val.replaceAll("-", "_").toUpperCase()] ?? 0)
1074
1105
  // @ts-expect-error
1075
1106
  arena.colorType[token] = (ColorType[val.replaceAll("-", "_").toUpperCase()] ?? 0);
1076
1107
  }
1077
- if (arena.firstToken[token] != 0) {
1108
+ if (arena.firstToken[token] !== 0) {
1078
1109
  const tk = arena.findToken(token, (arena, t) => arena.dataTypes[t] !== EnumToken.WhitespaceTokenType &&
1079
1110
  arena.dataTypes[t] !== EnumToken.CommentTokenType);
1080
1111
  if (tk != null &&
1081
1112
  arena.dataTypes[tk] === EnumToken.IdenTokenType &&
1082
- arena.strings[arena.stringValue[tk]] === "from") {
1113
+ arena.resolveString(arena.stringValue[tk]) === "from") {
1083
1114
  // inlined: arena.setUnitString(token, "rel")
1084
1115
  arena.unit[token] = arena.internString("rel");
1085
1116
  }
1086
- else if (val == "color-mix" && tk != null && arena.strings[arena.stringValue[tk]] == "in") {
1117
+ else if (val === "color-mix" && tk != null && arena.resolveString(arena.stringValue[tk]) === "in") {
1087
1118
  // inlined: arena.setUnitString(token, "mix")
1088
1119
  arena.unit[token] = arena.internString("mix");
1089
1120
  }
1090
- if (val == "color") {
1091
- if (tk != null && EnumToken.DashedIdenTokenType == arena.dataTypes[tk]) {
1121
+ if (val === "color") {
1122
+ if (tk != null && EnumToken.DashedIdenTokenType === arena.dataTypes[tk]) {
1092
1123
  // inlined: arena.setColorType(token, ColorType.CUSTOM_COLOR)
1093
1124
  arena.colorType[token] = ColorType.CUSTOM_COLOR;
1094
1125
  }
@@ -1108,21 +1139,21 @@ function isNonAscii(codepoint) {
1108
1139
  }
1109
1140
  function isIdentStart(codepoint) {
1110
1141
  // _
1111
- return codepoint == 0x5f || isLetter(codepoint) || isNonAscii(codepoint) || codepoint == REVERSE_SOLIDUS;
1142
+ return codepoint === 0x5f || isLetter(codepoint) || isNonAscii(codepoint) || codepoint === REVERSE_SOLIDUS;
1112
1143
  }
1113
1144
  function isDigit(codepoint) {
1114
1145
  return codepoint >= 0x30 && codepoint <= 0x39;
1115
1146
  }
1116
1147
  function isIdentCodepoint(codepoint) {
1117
1148
  // -
1118
- return codepoint == 0x2d || isDigit(codepoint) || isIdentStart(codepoint);
1149
+ return codepoint === 0x2d || isDigit(codepoint) || isIdentStart(codepoint);
1119
1150
  }
1120
1151
  const isIdent = memoize(function (name) {
1121
1152
  const j = name.length - 1;
1122
1153
  let i = 0;
1123
1154
  let codepoint = name.charCodeAt(0);
1124
1155
  // -
1125
- if (codepoint == 0x2d) {
1156
+ if (codepoint === 0x2d) {
1126
1157
  const nextCodepoint = name.charCodeAt(1);
1127
1158
  if (Number.isNaN(nextCodepoint)) {
1128
1159
  return false;
@@ -1139,7 +1170,7 @@ const isIdent = memoize(function (name) {
1139
1170
  if (codepoint !== 0x2d && !isIdentStart(codepoint)) {
1140
1171
  return false;
1141
1172
  }
1142
- if (codepoint == REVERSE_SOLIDUS) {
1173
+ if (codepoint === REVERSE_SOLIDUS) {
1143
1174
  if (i + 1 > j) {
1144
1175
  return false;
1145
1176
  }
@@ -1158,7 +1189,7 @@ const isIdent = memoize(function (name) {
1158
1189
  while (i < j) {
1159
1190
  i += codepoint < 0x80 ? 1 : String.fromCodePoint(codepoint).length;
1160
1191
  codepoint = name.charCodeAt(i);
1161
- if (codepoint == REVERSE_SOLIDUS) {
1192
+ if (codepoint === REVERSE_SOLIDUS) {
1162
1193
  i += codepoint < 0x80 ? 1 : String.fromCodePoint(codepoint).length;
1163
1194
  codepoint = name.charCodeAt(i);
1164
1195
  i += codepoint < 0x80 ? 1 : String.fromCodePoint(codepoint).length;
@@ -1174,9 +1205,9 @@ function isNonPrintable(codepoint) {
1174
1205
  // null -> backspace
1175
1206
  return ((codepoint >= 0 && codepoint <= 0x8) ||
1176
1207
  // tab
1177
- codepoint == 0xb ||
1208
+ codepoint === 0xb ||
1178
1209
  // delete
1179
- codepoint == 0x7f ||
1210
+ codepoint === 0x7f ||
1180
1211
  (codepoint >= 0xe && codepoint <= 0x1f));
1181
1212
  }
1182
1213
  // export function isURLToken(str: string): boolean {
@@ -1218,12 +1249,12 @@ function isNonPrintable(codepoint) {
1218
1249
  // return i == str.length;
1219
1250
  // }
1220
1251
  function isPseudo(name) {
1221
- return (name.charAt(0) == ":" &&
1222
- ((name.endsWith("(") && isIdent(name.charAt(1) == ":" ? name.slice(2, -1) : name.slice(1, -1))) ||
1223
- isIdent(name.charAt(1) == ":" ? name.slice(2) : name.slice(1))));
1252
+ return (name.charAt(0) === ":" &&
1253
+ ((name.endsWith("(") && isIdent(name.charAt(1) === ":" ? name.slice(2, -1) : name.slice(1, -1))) ||
1254
+ isIdent(name.charAt(1) === ":" ? name.slice(2) : name.slice(1))));
1224
1255
  }
1225
1256
  function isHash(name) {
1226
- return name.charAt(0) == "#" && isIdentStart(name.charCodeAt(1));
1257
+ return name.charAt(0) === "#" && isIdentStart(name.charCodeAt(1));
1227
1258
  }
1228
1259
  function parseDimension(name) {
1229
1260
  let index = name.length;
@@ -1296,23 +1327,23 @@ function isFunction(name) {
1296
1327
  // }
1297
1328
  function isNewLine(codepoint) {
1298
1329
  // \n \r \f \v
1299
- return (codepoint == 0xa ||
1300
- codepoint == 0xb ||
1301
- codepoint == 0xc ||
1302
- codepoint == 0xd ||
1303
- codepoint == 0x2028 ||
1304
- codepoint == 0x2029);
1330
+ return (codepoint === 0xa ||
1331
+ codepoint === 0xb ||
1332
+ codepoint === 0xc ||
1333
+ codepoint === 0xd ||
1334
+ codepoint === 0x2028 ||
1335
+ codepoint === 0x2029);
1305
1336
  }
1306
1337
  function isWhiteSpace(codepoint) {
1307
- return (codepoint == 0x9 ||
1308
- codepoint == 0x20 ||
1338
+ return (codepoint === 0x9 ||
1339
+ codepoint === 0x20 ||
1309
1340
  // isNewLine
1310
- codepoint == 0xa ||
1311
- codepoint == 0xb ||
1312
- codepoint == 0xc ||
1313
- codepoint == 0xd ||
1314
- codepoint == 0x2028 ||
1315
- codepoint == 0x2029);
1341
+ codepoint === 0xa ||
1342
+ codepoint === 0xb ||
1343
+ codepoint === 0xc ||
1344
+ codepoint === 0xd ||
1345
+ codepoint === 0x2028 ||
1346
+ codepoint === 0x2029);
1316
1347
  }
1317
1348
  // export function isValue(token: Token) {
1318
1349
  // if (token == null) {
@@ -1349,27 +1380,31 @@ function isWhiteSpace(codepoint) {
1349
1380
  function length2Px(arena, value) {
1350
1381
  let result = null;
1351
1382
  const val = arena.numericValue[value];
1352
- if (arena.dataTypes[value] == EnumToken.NumberTokenType) {
1383
+ if (arena.dataTypes[value] === EnumToken.NumberTokenType) {
1353
1384
  result = val;
1354
1385
  }
1355
1386
  else {
1356
- switch (arena.strings[arena.unit[value]]) {
1387
+ // the absolute length units: 1in = 2.54cm = 96px. the units are case-insensitive
1388
+ switch (arena.resolveString(arena.unit[value])?.toLowerCase()) {
1357
1389
  case "cm":
1358
- result = val * 37.8;
1390
+ result = (val * 96) / 2.54;
1359
1391
  break;
1360
1392
  case "mm":
1361
- result = val * 3.78;
1393
+ result = (val * 96) / 25.4;
1362
1394
  break;
1363
- case "Q":
1364
- result = (val * 37.8) / 40;
1395
+ case "q":
1396
+ // 1Q = 1/40cm
1397
+ result = (val * 96) / 101.6;
1365
1398
  break;
1366
1399
  case "in":
1367
- result = val / 96;
1400
+ result = val * 96;
1368
1401
  break;
1369
1402
  case "pc":
1370
- result = val / 16;
1403
+ // 1pc = 1/6in
1404
+ result = val * 16;
1371
1405
  break;
1372
1406
  case "pt":
1407
+ // 1pt = 1/72in
1373
1408
  result = (val * 4) / 3;
1374
1409
  break;
1375
1410
  case "px":
@@ -1384,7 +1419,7 @@ function length2Px(arena, value) {
1384
1419
  * @param val
1385
1420
  */
1386
1421
  function minifyNumber(val) {
1387
- if (typeof val != "number") {
1422
+ if (typeof val !== "number") {
1388
1423
  return minifyNumberValue(val);
1389
1424
  }
1390
1425
  // the same numbers are rendered many times (0, 1, .5, 100, ...): the result only depends on the number
@@ -1421,13 +1456,13 @@ function minifyNumberValue(val) {
1421
1456
  return "0";
1422
1457
  }
1423
1458
  const chr = val.charAt(0);
1424
- if (chr == "-") {
1459
+ if (chr === "-") {
1425
1460
  const slice = val.slice(0, 2);
1426
- if (slice == "-0") {
1427
- return val.length == 2 ? "0" : "-" + val.slice(2);
1461
+ if (slice === "-0") {
1462
+ return val.length === 2 ? "0" : "-" + val.slice(2);
1428
1463
  }
1429
1464
  }
1430
- if (chr == "0") {
1465
+ if (chr === "0") {
1431
1466
  return val.slice(1);
1432
1467
  }
1433
1468
  return val;
@@ -1449,4 +1484,4 @@ function toPrecisionAngle(angle, precision = anglePrecision, correctValue = true
1449
1484
  return angle;
1450
1485
  }
1451
1486
 
1452
- export { angleUnits, dimensionUnits, flexUnits, frequencyUnits, isAngleUnit, isColor, isDigit, isFlexUnit, isFrequencyUnit, isFunction, isHash, isIdent, isIdentCodepoint, isIdentColor, isIdentStart, isLength, isLengthUnit, isLetter, isNewLine, isNonPrintable, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolutionUnit, isTimeUnit, isWhiteSpace, length2Px, minifyNumber, parseColor, parseDimension, pseudoAliasMap, reduceColorStops, reduceConicColorStops, reducegradientBackgroundPosition, renamedStandardProperties, resolutionUnits, timeUnits, toPrecisionAngle, toPrecisionValue };
1487
+ export { angleUnits, dimensionUnits, flexUnits, frequencyUnits, isAngleUnit, isColor, isColorName, isDigit, isFlexUnit, isFrequencyUnit, isFunction, isHash, isIdent, isIdentCodepoint, isIdentColor, isIdentStart, isLength, isLengthUnit, isLetter, isNewLine, isNonPrintable, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolutionUnit, isTimeUnit, isWhiteSpace, length2Px, minifyNumber, parseColor, parseDimension, pseudoAliasMap, reduceColorStops, reduceConicColorStops, reducegradientBackgroundPosition, renamedStandardProperties, resolutionUnits, timeUnits, toPrecisionAngle, toPrecisionValue };