@tbela99/css-parser 2.3.1 → 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 +38 -0
  2. package/README.md +56 -26
  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 +1084 -293
  38. package/dist/index.d.ts +597 -686
  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 +3 -1
  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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { getAngle, convertColor } from '../syntax/color/color.js';
@@ -1734,7 +1734,8 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1734
1734
  key === "0 0" ||
1735
1735
  key === "top left" ||
1736
1736
  key === "left top") {
1737
- positions.splice(0, positions.length, arena.createToken(EnumToken.PercentageTokenType, 0));
1737
+ // a single value is centered vertically: both values are kept
1738
+ positions.splice(0, positions.length, arena.createToken(EnumToken.PercentageTokenType, 0), arena.createToken(EnumToken.WhitespaceTokenType), arena.createToken(EnumToken.PercentageTokenType, 0));
1738
1739
  }
1739
1740
  else if (key === "50% 0%" ||
1740
1741
  key === "50% 0" ||
@@ -1758,7 +1759,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1758
1759
  key === "0% 100%" ||
1759
1760
  key === "left bottom" ||
1760
1761
  key === "bottom left") {
1761
- positions.splice(0, positions.length, arena.createToken(EnumToken.IdenTokenType, "bottom"));
1762
+ positions.splice(0, positions.length, arena.createToken(EnumToken.PercentageTokenType, 0), arena.createToken(EnumToken.WhitespaceTokenType), arena.createToken(EnumToken.PercentageTokenType, 100));
1762
1763
  }
1763
1764
  else if (key === "50% 100%" ||
1764
1765
  key === "center bottom" ||
@@ -1768,10 +1769,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1768
1769
  else if (key === "100% 100%" ||
1769
1770
  key === "right bottom" ||
1770
1771
  key === "bottom right") {
1771
- positions.splice(0, positions.length, arena.createToken(EnumToken.PercentageTokenType, 100));
1772
- }
1773
- else if (position1 === position2) {
1774
- positions.splice(0, positions.length, positions[k]);
1772
+ positions.splice(0, positions.length, arena.createToken(EnumToken.PercentageTokenType, 100), arena.createToken(EnumToken.WhitespaceTokenType), arena.createToken(EnumToken.PercentageTokenType, 100));
1775
1773
  }
1776
1774
  }
1777
1775
  }
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  /**
@@ -70,6 +70,7 @@ class RenderResult {
70
70
  */
71
71
  #codeLength;
72
72
  /**
73
+ * create a render result
73
74
  * @param write rendered css, encoded as UTF-8
74
75
  * @param errors
75
76
  * @param stats
@@ -134,6 +135,7 @@ class TransformResult extends RenderResult {
134
135
  */
135
136
  arena;
136
137
  /**
138
+ * create a transform result from the parse result and the render result
137
139
  * @param parseResult
138
140
  * @param renderResult
139
141
  * @param stats
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { toBase64 } from '../parser/utils/base64.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  /**
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { xyz2srgb } from './srgb.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { ColorType, EnumToken } from '../../ast/types.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken, ColorType } from '../../ast/types.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken, ColorType, EnumAstNodeStatus } from '../../ast/types.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { ColorType, EnumToken } from '../../ast/types.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken, ColorType } from '../../ast/types.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { color2srgbvalues, getNumber } from './color.js';
@@ -93,6 +93,14 @@ function hslToken(arena, values) {
93
93
  }
94
94
  return arena.createColor("hsl", ColorType.HSL, chi);
95
95
  }
96
+ /**
97
+ * value of a red, green or blue component of an `rgb()` color, from 0 to 255: `100%` is 255
98
+ * @param arena
99
+ * @param token
100
+ */
101
+ function rgbChannel(arena, token) {
102
+ return (arena.dataTypes[token] === EnumToken.PercentageTokenType ? 255 : 1) * getNumber(arena, token);
103
+ }
96
104
  function rgb2hslvalues(arena, token) {
97
105
  const chi = getColorComponents(arena, token);
98
106
  if (chi == null || chi.length < 3) {
@@ -101,15 +109,15 @@ function rgb2hslvalues(arena, token) {
101
109
  // @ts-ignore
102
110
  let t = chi[0];
103
111
  // @ts-ignore
104
- let r = getNumber(arena, t);
112
+ let r = rgbChannel(arena, t);
105
113
  // @ts-ignore
106
114
  t = chi[1];
107
115
  // @ts-ignore
108
- let g = getNumber(arena, t);
116
+ let g = rgbChannel(arena, t);
109
117
  // @ts-ignore
110
118
  t = chi[2];
111
119
  // @ts-ignore
112
- let b = getNumber(arena, t);
120
+ let b = rgbChannel(arena, t);
113
121
  // @ts-ignore
114
122
  let a = null;
115
123
  if (chi.length === 4) {
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { getColorComponents } from './utils/components.js';
@@ -78,11 +78,17 @@ function hwbToken(arena, values) {
78
78
  return arena.createColor("hwb", ColorType.HWB, chi);
79
79
  }
80
80
  function rgb2hwbvalues(arena, token) {
81
- const values = getColorComponents(arena, token).map((t, index) => {
81
+ const components = getColorComponents(arena, token);
82
+ // the components cannot be computed: var(), ...
83
+ if (components == null) {
84
+ return null;
85
+ }
86
+ const values = components.map((t, index) => {
82
87
  if (index === 3) {
83
88
  return getNumber(arena, t);
84
89
  }
85
- return getNumber(arena, t) / 255;
90
+ // the components are from 0 to 255: 100% is 255
91
+ return ((arena.dataTypes[t] === EnumToken.PercentageTokenType ? 255 : 1) * getNumber(arena, t)) / 255;
86
92
  });
87
93
  // @ts-ignore
88
94
  return srgb2hwb(values[0], values[1], values[2], values[3]);
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { e, k, D50 } from '../constants.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { getColorComponents } from './utils/components.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { getColorComponents } from './utils/components.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { getColorComponents } from './utils/components.js';
@@ -100,7 +100,7 @@ function hsl2oklchvalues(arena, token) {
100
100
  }
101
101
  function hwb2oklchvalues(arena, token) {
102
102
  const values = hwb2oklabvalues(arena, token);
103
- return labvalues2lchvalues(values[0], values[1], values[2], values[3]);
103
+ return values == null ? null : labvalues2lchvalues(values[0], values[1], values[2], values[3]);
104
104
  }
105
105
  function cmyk2oklchvalues(arena, token) {
106
106
  const values = cmyk2srgbvalues(arena, token);
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { lsrgb2srgbvalues, xyz2srgb, srgb2lsrgbvalues } from './srgb.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { XYZ_D65_to_D50, xyzd502srgb } from './xyzd50.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { xyz2srgb } from './srgb.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { convertColor, getNumber } from './color.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { color2srgbvalues, minmax } from './color.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { getColorComponents } from './utils/components.js';
@@ -94,8 +94,9 @@ function xyz2srgb(x, y, z, alpha = null) {
94
94
  }
95
95
  function hwb2srgbvalues(arena, token) {
96
96
  const { h, w, b, a } = hwbvalues(arena, token) ?? {};
97
+ // the components cannot be computed: var(), ...
97
98
  if (h == null || w == null || b == null) {
98
- return [];
99
+ return null;
99
100
  }
100
101
  const rgb = hwb2srgb(h, w, b);
101
102
  if (a != null && a !== 1) {
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { ColorType } from '../../../ast/types.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { equalsIgnoreCase } from '../../../parser/utils/text.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { ColorType, EnumToken } from '../../../ast/types.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { convertColor } from '../color.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken, ColorType } from '../../../ast/types.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  // from https://www.w3.org/TR/css-color-4/multiply-matrices.js
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { multiplyMatrices } from './utils/matrix.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { lsrgb2srgbvalues } from './srgb.js';
@@ -2,14 +2,14 @@
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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from '../ast/types.js';
9
9
  import config from '../data/validation.json.js';
10
10
 
11
11
  /**
12
- * Used by the validation parser
12
+ * key of the position of a validation token in the syntax, see {@link ValidationToken}
13
13
  */
14
14
  const LOC = Symbol.for("loc");
15
15
  /**
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { TokenField } from '../ast/arena.js';
package/dist/types.js CHANGED
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  /**
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from '../ast/types.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  /**
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from '../../ast/types.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { interpreted, seq, kws, alt, leaf, kw, rep, list, unordered, fn, comma, occ, opt, rng, ref, slash, fndef, num, optGroup, closeParens, str, colon, openParens, optList, empty } from './runtime.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import config from '../data/validation.json.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from '../ast/types.js';
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { TokenField } from '../ast/arena.js';
@@ -116,6 +116,71 @@ function trimArray(arena, tokens) {
116
116
  }
117
117
  return tokens;
118
118
  }
119
+ /**
120
+ * true if the token is a simple selector without arguments: a type (`a`), an id (`#a`), a class (`.a`), a
121
+ * pseudo-class (`:hover`) or a pseudo-element (`::before`)
122
+ * @param type
123
+ */
124
+ function isSimpleSelectorToken(type) {
125
+ return (type === EnumToken.ClassSelectorTokenType ||
126
+ type === EnumToken.IdenTokenType ||
127
+ type === EnumToken.PseudoElementTokenType ||
128
+ type === EnumToken.PseudoClassTokenType ||
129
+ type === EnumToken.HashTokenType);
130
+ }
131
+ /**
132
+ * match a selector made of simple selectors (see {@link isSimpleSelectorToken}), separated by whitespace (the
133
+ * descendant combinator) and by commas: `.a:hover`, `.a .b`, `.a, #b`. such a selector is valid: the whitespace
134
+ * around the commas is removed, the tokens are the tokens produced by {@link matchSelectorSyntax}. the tokens of
135
+ * another selector are not changed
136
+ * @param arena
137
+ * @param tokens
138
+ * @returns true if the selector is made of simple selectors
139
+ */
140
+ function matchSimpleSelector(arena, tokens) {
141
+ const length = tokens.length;
142
+ // a simple selector is expected: at the start of the selector and after a comma
143
+ let expected = true;
144
+ let commaWhitespace = false;
145
+ for (let i = 0; i < length; i++) {
146
+ const type = arena.dataTypes[tokens[i]];
147
+ if (isSimpleSelectorToken(type)) {
148
+ expected = false;
149
+ continue;
150
+ }
151
+ if (type === EnumToken.WhitespaceTokenType) {
152
+ // leading whitespace
153
+ if (i === 0) {
154
+ return false;
155
+ }
156
+ // whitespace after a comma or before a comma
157
+ if (expected || arena.dataTypes[tokens[i + 1]] === EnumToken.CommaTokenType) {
158
+ commaWhitespace = true;
159
+ }
160
+ continue;
161
+ }
162
+ if (type !== EnumToken.CommaTokenType || expected) {
163
+ return false;
164
+ }
165
+ expected = true;
166
+ }
167
+ if (expected) {
168
+ return false;
169
+ }
170
+ if (commaWhitespace) {
171
+ let write = 0;
172
+ for (let i = 0; i < length; i++) {
173
+ if (arena.dataTypes[tokens[i]] === EnumToken.WhitespaceTokenType &&
174
+ (arena.dataTypes[tokens[i - 1]] === EnumToken.CommaTokenType ||
175
+ arena.dataTypes[tokens[i + 1]] === EnumToken.CommaTokenType)) {
176
+ continue;
177
+ }
178
+ tokens[write++] = tokens[i];
179
+ }
180
+ tokens.length = write;
181
+ }
182
+ return true;
183
+ }
119
184
  /**
120
185
  *
121
186
  * @param featureName
@@ -1517,8 +1582,12 @@ function isInRange(arena, token, syntax) {
1517
1582
  * @param token
1518
1583
  */
1519
1584
  function functionSyntax(arena, token) {
1585
+ const previousSyntaxArena = syntaxArena;
1520
1586
  syntaxArena = arena;
1521
- return arena.stringDerived(arena.stringValue[token], 0 /* StringDerived.FunctionSyntax */, computeFunctionSyntax);
1587
+ const syntax = arena.stringDerived(arena.stringValue[token], 0 /* StringDerived.FunctionSyntax */, computeFunctionSyntax);
1588
+ // the arena is not kept after the parse: the previous arena is restored (a nested call)
1589
+ syntaxArena = previousSyntaxArena;
1590
+ return syntax;
1522
1591
  }
1523
1592
  /**
1524
1593
  * the arena of the function names read by {@link computeFunctionSyntax} and {@link computeSelectorFunctionSyntax}:
@@ -1545,8 +1614,12 @@ function computeSelectorFunctionSyntax(id) {
1545
1614
  * @param token
1546
1615
  */
1547
1616
  function selectorFunctionSyntax(arena, token) {
1617
+ const previousSyntaxArena = syntaxArena;
1548
1618
  syntaxArena = arena;
1549
- return arena.stringDerived(arena.stringValue[token], 1 /* StringDerived.SelectorFunctionSyntax */, computeSelectorFunctionSyntax);
1619
+ const syntax = arena.stringDerived(arena.stringValue[token], 1 /* StringDerived.SelectorFunctionSyntax */, computeSelectorFunctionSyntax);
1620
+ // the arena is not kept after the parse: the previous arena is restored (a nested call)
1621
+ syntaxArena = previousSyntaxArena;
1622
+ return syntax;
1550
1623
  }
1551
1624
  /**
1552
1625
  * the wildcard functions being matched with a syntax, see {@link matchWildCardFunction}
@@ -3176,4 +3249,4 @@ function matchRepeatableSyntax(arena, syntax, context, options) {
3176
3249
  };
3177
3250
  }
3178
3251
 
3179
- export { ValidationTokenContext, createValidationContext, funcTypes, getMFInfo, isCssWideKeyword, isMFValue, isValidDeclarationValue, matchAllSyntaxes, matchDeclarationSyntax, matchOccurenceSyntax, matchProperty, matchSelectorSyntax, selectorFunctionSyntax, trimArray };
3252
+ export { ValidationTokenContext, createValidationContext, funcTypes, getMFInfo, isCssWideKeyword, isMFValue, isValidDeclarationValue, matchAllSyntaxes, matchDeclarationSyntax, matchOccurenceSyntax, matchProperty, matchSelectorSyntax, matchSimpleSelector, selectorFunctionSyntax, trimArray };
@@ -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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from '../../ast/types.js';
@@ -2,9 +2,12 @@
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.1
5
+ Version: 2.3.2
6
6
  License: MIT
7
7
  */
8
+ /**
9
+ * type of a validation token: a node of the parsed value definition syntax, see {@link parseSyntax}
10
+ */
8
11
  var ValidationTokenEnum;
9
12
  (function (ValidationTokenEnum) {
10
13
  ValidationTokenEnum[ValidationTokenEnum["Root"] = 0] = "Root";