@tbela99/css-parser 1.8.1 → 2.0.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 (105) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +129 -31
  3. package/dist/index-umd-web.js +27382 -24086
  4. package/dist/index.d.ts +2737 -2200
  5. package/dist/package.json.js +2 -2
  6. package/dist/src/data/properties.json.js +1 -1
  7. package/dist/src/data/validation.json.js +1 -1
  8. package/dist/src/lib/ast/arena-node.js +548 -0
  9. package/dist/src/lib/ast/arena.js +3198 -0
  10. package/dist/src/lib/ast/features/calc.js +85 -76
  11. package/dist/src/lib/ast/features/if.js +155 -115
  12. package/dist/src/lib/ast/features/index.js +1 -1
  13. package/dist/src/lib/ast/features/inlinecssvariables.js +77 -84
  14. package/dist/src/lib/ast/features/prefix.js +184 -183
  15. package/dist/src/lib/ast/features/shorthand.js +40 -46
  16. package/dist/src/lib/ast/features/transform.js +24 -24
  17. package/dist/src/lib/ast/features/type.js +1 -1
  18. package/dist/src/lib/ast/fingerprint.js +333 -0
  19. package/dist/src/lib/ast/math/expression.js +458 -543
  20. package/dist/src/lib/ast/math/math.js +19 -41
  21. package/dist/src/lib/ast/minify.js +590 -647
  22. package/dist/src/lib/ast/transform/compute.js +82 -85
  23. package/dist/src/lib/ast/transform/matrix.js +21 -38
  24. package/dist/src/lib/ast/transform/minify.js +82 -193
  25. package/dist/src/lib/ast/transform/perspective.js +2 -3
  26. package/dist/src/lib/ast/transform/rotate.js +1 -1
  27. package/dist/src/lib/ast/transform/scale.js +1 -1
  28. package/dist/src/lib/ast/transform/skew.js +1 -1
  29. package/dist/src/lib/ast/transform/translate.js +1 -1
  30. package/dist/src/lib/ast/transform/utils.js +2 -2
  31. package/dist/src/lib/ast/types.js +263 -258
  32. package/dist/src/lib/ast/walk.js +246 -610
  33. package/dist/src/lib/fs/resolve.js +1 -1
  34. package/dist/src/lib/parser/declaration/list.js +223 -139
  35. package/dist/src/lib/parser/declaration/map.js +251 -238
  36. package/dist/src/lib/parser/declaration/set.js +74 -66
  37. package/dist/src/lib/parser/linesmap.js +1 -1
  38. package/dist/src/lib/parser/parse.js +1379 -1662
  39. package/dist/src/lib/parser/source.js +7 -4
  40. package/dist/src/lib/parser/tokenize.js +406 -199
  41. package/dist/src/lib/parser/utils/angle.js +11 -13
  42. package/dist/src/lib/parser/utils/at-rule-container.js +183 -168
  43. package/dist/src/lib/parser/utils/at-rule-font-feature-values.js +5 -5
  44. package/dist/src/lib/parser/utils/at-rule-generic.js +31 -24
  45. package/dist/src/lib/parser/utils/at-rule-import.js +44 -44
  46. package/dist/src/lib/parser/utils/at-rule-media.js +216 -205
  47. package/dist/src/lib/parser/utils/at-rule-support.js +83 -88
  48. package/dist/src/lib/parser/utils/at-rule-when-else.js +47 -47
  49. package/dist/src/lib/parser/utils/at-rule.js +5 -5
  50. package/dist/src/lib/parser/utils/base64.js +2 -2
  51. package/dist/src/lib/parser/utils/cache.js +1 -1
  52. package/dist/src/lib/parser/utils/config.js +1 -1
  53. package/dist/src/lib/parser/utils/declaration.js +233 -234
  54. package/dist/src/lib/parser/utils/eq.js +50 -3
  55. package/dist/src/lib/parser/utils/hash.js +2 -35
  56. package/dist/src/lib/parser/utils/selector.js +309 -387
  57. package/dist/src/lib/parser/utils/text.js +18 -4
  58. package/dist/src/lib/parser/utils/token.js +16 -69
  59. package/dist/src/lib/parser/utils/type.js +37 -24
  60. package/dist/src/lib/printer/render.js +965 -511
  61. package/dist/src/lib/printer/sourcemap/lib/codec.js +1 -1
  62. package/dist/src/lib/printer/sourcemap/sourcemap.js +1 -1
  63. package/dist/src/lib/syntax/color/a98rgb.js +1 -1
  64. package/dist/src/lib/syntax/color/alpha.js +36 -37
  65. package/dist/src/lib/syntax/color/cmyk.js +35 -52
  66. package/dist/src/lib/syntax/color/color-mix.js +96 -132
  67. package/dist/src/lib/syntax/color/color.js +222 -231
  68. package/dist/src/lib/syntax/color/hex.js +45 -55
  69. package/dist/src/lib/syntax/color/hsl.js +54 -62
  70. package/dist/src/lib/syntax/color/hwb.js +60 -68
  71. package/dist/src/lib/syntax/color/lab.js +59 -67
  72. package/dist/src/lib/syntax/color/lch.js +59 -67
  73. package/dist/src/lib/syntax/color/oklab.js +60 -68
  74. package/dist/src/lib/syntax/color/oklch.js +60 -67
  75. package/dist/src/lib/syntax/color/p3.js +1 -1
  76. package/dist/src/lib/syntax/color/prophotorgb.js +1 -1
  77. package/dist/src/lib/syntax/color/rec2020.js +1 -1
  78. package/dist/src/lib/syntax/color/relative-color.js +94 -144
  79. package/dist/src/lib/syntax/color/rgb.js +54 -57
  80. package/dist/src/lib/syntax/color/srgb.js +55 -53
  81. package/dist/src/lib/syntax/color/utils/color-type.js +13 -10
  82. package/dist/src/lib/syntax/color/utils/colorspace.js +11 -11
  83. package/dist/src/lib/syntax/color/utils/components.js +19 -20
  84. package/dist/src/lib/syntax/color/utils/distance.js +15 -13
  85. package/dist/src/lib/syntax/color/utils/make-color.js +15 -19
  86. package/dist/src/lib/syntax/color/utils/matrix.js +2 -2
  87. package/dist/src/lib/syntax/color/xyz.js +1 -1
  88. package/dist/src/lib/syntax/color/xyzd50.js +1 -1
  89. package/dist/src/lib/syntax/constants.js +2 -16
  90. package/dist/src/lib/syntax/syntax.js +301 -407
  91. package/dist/src/lib/validation/config.js +1 -1
  92. package/dist/src/lib/validation/match.js +959 -723
  93. package/dist/src/lib/validation/parser/parse.js +230 -112
  94. package/dist/src/lib/validation/parser/typedef.js +1 -1
  95. package/dist/src/lib/validation/utils/list.js +27 -12
  96. package/dist/src/node.js +12 -72
  97. package/dist/src/types.js +1 -1
  98. package/dist/src/utils/sync.js +9 -6
  99. package/dist/src/web.js +11 -73
  100. package/package.json +9 -10
  101. package/dist/index.cjs +0 -35874
  102. package/dist/src/lib/ast/clone.js +0 -51
  103. package/dist/src/lib/ast/expand.js +0 -311
  104. package/dist/src/lib/ast/find.js +0 -192
  105. package/dist/src/lib/ast/node.js +0 -59
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.8.1
5
+ Version: 2.0.0
6
6
  License: MIT
7
7
  */
8
8
  import { getColorComponents } from './utils/components.js';
@@ -21,48 +21,48 @@ import { hwbvalues } from './hwb.js';
21
21
  // from https://www.w3.org/TR/css-color-4/#color-conversion-code
22
22
  // srgb-linear -> srgb
23
23
  // 0 <= r, g, b <= 1
24
- function srgbvalues(token) {
25
- if (token.typ === EnumToken.IdenTokenType) {
26
- token = parseColor(token);
24
+ function srgbvalues(arena, token) {
25
+ if (arena.dataTypes[token] === EnumToken.IdenTokenType) {
26
+ token = parseColor(arena, token);
27
27
  }
28
- switch (token.kin) {
28
+ switch (arena.colorType[token]) {
29
29
  case ColorType.LIT:
30
30
  case ColorType.HEX:
31
- return hex2srgbvalues(token);
31
+ return hex2srgbvalues(arena, token);
32
32
  case ColorType.RGB:
33
33
  case ColorType.RGBA:
34
- return rgb2srgb(token);
34
+ return rgb2srgb(arena, token);
35
35
  case ColorType.HSL:
36
36
  case ColorType.HSLA:
37
- return hsl2srgb(token);
37
+ return hsl2srgb(arena, token);
38
38
  case ColorType.HWB:
39
- return hwb2srgbvalues(token);
39
+ return hwb2srgbvalues(arena, token);
40
40
  case ColorType.LAB:
41
- return lab2srgbvalues(token);
41
+ return lab2srgbvalues(arena, token);
42
42
  case ColorType.LCH:
43
- return lch2srgbvalues(token);
43
+ return lch2srgbvalues(arena, token);
44
44
  case ColorType.OKLAB:
45
- return oklab2srgbvalues(token);
45
+ return oklab2srgbvalues(arena, token);
46
46
  case ColorType.OKLCH:
47
- return oklch2srgbvalues(token);
47
+ return oklch2srgbvalues(arena, token);
48
48
  case ColorType.COLOR:
49
- return color2srgbvalues(token);
49
+ return color2srgbvalues(arena, token);
50
50
  }
51
51
  return null;
52
52
  }
53
- function rgb2srgb(token) {
54
- return (getColorComponents(token)?.map?.((t, index) => index == 3
55
- ? t.typ == EnumToken.IdenTokenType && t.val == "none"
53
+ function rgb2srgb(arena, token) {
54
+ return (getColorComponents(arena, token)?.map?.((t, index) => index == 3
55
+ ? arena.dataTypes[t] == EnumToken.IdenTokenType && arena.strings[arena.stringValue[t]] == "none"
56
56
  ? 1
57
- : getNumber(t)
58
- : ((t.typ == EnumToken.PercentageTokenType ? 255 : 1) *
59
- getNumber(t)) /
57
+ : getNumber(arena, t)
58
+ : ((arena.dataTypes[t] == EnumToken.PercentageTokenType ? 255 : 1) *
59
+ getNumber(arena, t)) /
60
60
  255) ?? null);
61
61
  }
62
- function rgb2srgbvalues(token) {
63
- return (getColorComponents(token)?.map?.((t, index) => index == 3
64
- ? getNumber(t)
65
- : getNumber(t) / 255) ?? null);
62
+ function rgb2srgbvalues(arena, token) {
63
+ return (getColorComponents(arena, token)?.map?.((t, index) => index == 3
64
+ ? getNumber(arena, t)
65
+ : getNumber(arena, t) / 255) ?? null);
66
66
  }
67
67
  // export function rgbvalues2srgbvalues(r: number, g: number, b: number, a: number | null = null): number[] | null {
68
68
  // const result = [r / 255, g / 255, b / 255];
@@ -73,8 +73,10 @@ function rgb2srgbvalues(token) {
73
73
  //
74
74
  // return result;
75
75
  // }
76
- function hex2srgbvalues(token) {
77
- const value = expandHexValue(token.kin == ColorType.LIT ? COLORS_NAMES[token.val.toLowerCase()] : token.val);
76
+ function hex2srgbvalues(arena, token) {
77
+ const value = expandHexValue(arena.colorType[token] == ColorType.LIT
78
+ ? COLORS_NAMES[arena.strings[arena.stringValue[token]].toLowerCase()]
79
+ : arena.strings[arena.stringValue[token]]);
78
80
  const rgb = [];
79
81
  for (let i = 1; i < value.length; i += 2) {
80
82
  rgb.push(parseInt(value.slice(i, i + 2), 16) / 255);
@@ -90,8 +92,8 @@ function xyz2srgb(x, y, z, alpha = null) {
90
92
  // @ts-ignore
91
93
  return lsrgb2srgbvalues(values[0], values[1], values[2], alpha);
92
94
  }
93
- function hwb2srgbvalues(token) {
94
- const { h, w, b, a } = hwbvalues(token) ?? {};
95
+ function hwb2srgbvalues(arena, token) {
96
+ const { h, w, b, a } = hwbvalues(arena, token) ?? {};
95
97
  if (h == null || w == null || b == null) {
96
98
  return [];
97
99
  }
@@ -138,44 +140,44 @@ function hwb2srgb(h, w, b, alpha) {
138
140
  const srgb = [rChroma * factor + wNorm, gChroma * factor + wNorm, bChroma * factor + wNorm];
139
141
  return srgb;
140
142
  }
141
- function hsl2srgb(token) {
142
- let { h, s, l, a } = hslvalues(token) ?? {};
143
+ function hsl2srgb(arena, token) {
144
+ let { h, s, l, a } = hslvalues(arena, token) ?? {};
143
145
  if (h == null || s == null || l == null) {
144
146
  return null;
145
147
  }
146
148
  // hue in degrees
147
149
  return hslvalues2srgbvalues(h, s, l, a);
148
150
  }
149
- function cmyk2srgbvalues(token) {
150
- const components = getColorComponents(token);
151
+ function cmyk2srgbvalues(arena, token) {
152
+ const components = getColorComponents(arena, token);
151
153
  if (components == null) {
152
154
  return null;
153
155
  }
154
156
  // @ts-ignore
155
157
  let t = components[0];
156
158
  // @ts-ignore
157
- const c = getNumber(t);
159
+ const c = getNumber(arena, t);
158
160
  // @ts-ignore
159
161
  t = components[1];
160
162
  // @ts-ignore
161
- const m = getNumber(t);
163
+ const m = getNumber(arena, t);
162
164
  // @ts-ignore
163
165
  t = components[2];
164
166
  // @ts-ignore
165
- const y = getNumber(t);
167
+ const y = getNumber(arena, t);
166
168
  // @ts-ignore
167
169
  t = components[3];
168
170
  // @ts-ignore
169
- const k = getNumber(t);
171
+ const k = getNumber(arena, t);
170
172
  const mul = 1 - k;
171
173
  const rgb = [1 - Math.min(1, c * mul + k), 1 - Math.min(1, m * mul + k), 1 - Math.min(1, y * mul + k)];
172
174
  if (components.length == 5) {
173
- rgb.push(getNumber(components[4]));
175
+ rgb.push(getNumber(arena, components[4]));
174
176
  }
175
177
  return rgb;
176
178
  }
177
- function oklab2srgbvalues(token) {
178
- const [l, a, b, alpha] = getOKLABComponents(token) ?? [];
179
+ function oklab2srgbvalues(arena, token) {
180
+ const [l, a, b, alpha] = getOKLABComponents(arena, token) ?? [];
179
181
  if (l == null || a == null || b == null) {
180
182
  return null;
181
183
  }
@@ -185,8 +187,8 @@ function oklab2srgbvalues(token) {
185
187
  }
186
188
  return rgb;
187
189
  }
188
- function oklch2srgbvalues(token) {
189
- const [l, c, h, alpha] = getOKLCHComponents(token) ?? [];
190
+ function oklch2srgbvalues(arena, token) {
191
+ const [l, c, h, alpha] = getOKLCHComponents(arena, token) ?? [];
190
192
  if (l == null || c == null || h == null) {
191
193
  return null;
192
194
  }
@@ -197,26 +199,26 @@ function oklch2srgbvalues(token) {
197
199
  }
198
200
  return rgb;
199
201
  }
200
- function hslvalues(token) {
201
- const components = getColorComponents(token);
202
+ function hslvalues(arena, token) {
203
+ const components = getColorComponents(arena, token);
202
204
  if (components == null) {
203
205
  return null;
204
206
  }
205
207
  let t;
206
208
  // @ts-ignore
207
- let h = getAngle(components[0]) * 360;
209
+ let h = getAngle(arena, components[0]) * 360;
208
210
  // @ts-ignore
209
211
  t = components[1];
210
212
  // @ts-ignore
211
- let s = getNumber(t);
213
+ let s = getNumber(arena, t);
212
214
  // @ts-ignore
213
215
  t = components[2];
214
216
  // @ts-ignore
215
- let l = getNumber(t);
216
- if (components[1].typ == EnumToken.PercentageTokenType) {
217
+ let l = getNumber(arena, t);
218
+ if (arena.dataTypes[components[1]] == EnumToken.PercentageTokenType) {
217
219
  s *= 100;
218
220
  }
219
- if (components[2].typ == EnumToken.PercentageTokenType) {
221
+ if (arena.dataTypes[components[2]] == EnumToken.PercentageTokenType) {
220
222
  l *= 100;
221
223
  }
222
224
  let a = null;
@@ -224,7 +226,7 @@ function hslvalues(token) {
224
226
  // @ts-ignore
225
227
  t = components[3];
226
228
  // @ts-ignore
227
- a = getNumber(t);
229
+ a = getNumber(arena, t);
228
230
  }
229
231
  return a == null ? { h, s, l } : { h, s, l, a };
230
232
  }
@@ -263,8 +265,8 @@ function hslvalues2srgbvalues(h, s, l, a = null) {
263
265
  // Return exact float decimals instead of multiplying by 255
264
266
  return values;
265
267
  }
266
- function lab2srgbvalues(token) {
267
- const [l, a, b, alpha] = getLABComponents(token) ?? [];
268
+ function lab2srgbvalues(arena, token) {
269
+ const [l, a, b, alpha] = getLABComponents(arena, token) ?? [];
268
270
  if (l == null || a == null || b == null) {
269
271
  return null;
270
272
  }
@@ -274,8 +276,8 @@ function lab2srgbvalues(token) {
274
276
  }
275
277
  return rgb;
276
278
  }
277
- function lch2srgbvalues(token) {
278
- const components = getLCHComponents(token);
279
+ function lch2srgbvalues(arena, token) {
280
+ const components = getLCHComponents(arena, token);
279
281
  if (components == null) {
280
282
  return null;
281
283
  }
@@ -2,24 +2,27 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.8.1
5
+ Version: 2.0.0
6
6
  License: MIT
7
7
  */
8
8
  import { ColorType } from '../../../ast/types.js';
9
9
 
10
10
  /**
11
11
  * Return the color type of the color components
12
+ * @param arena
13
+ * @param color
12
14
  */
13
- function getColorType(color) {
14
- if (color.kin === ColorType.COLOR_MIX || color.cal === "rel") {
15
- return color.kin === ColorType.COLOR_MIX
16
- ? // @ts-expect-error
17
- ColorType[
18
- // @ts-expect-error
19
- color.chi[2]?.val?.toUpperCase?.()?.replace?.("-", "_")]
20
- : getColorType(color.chi[2]);
15
+ function getColorType(arena, color) {
16
+ if (arena.colorType[color] === ColorType.COLOR_MIX || arena.strings[arena.unit[color]] === "rel") {
17
+ const token = arena.getTokenAt(color, 2);
18
+ if (token == null) {
19
+ return null;
20
+ }
21
+ return arena.colorType[color] === ColorType.COLOR_MIX
22
+ ? ColorType[arena.strings[arena.stringValue[token]]?.toUpperCase?.()?.replace?.("-", "_")]
23
+ : getColorType(arena, token);
21
24
  }
22
- return color.kin;
25
+ return arena.colorType[color];
23
26
  }
24
27
 
25
28
  export { getColorType };
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.8.1
5
+ Version: 2.0.0
6
6
  License: MIT
7
7
  */
8
8
  import { equalsIgnoreCase } from '../../../parser/utils/text.js';
@@ -13,33 +13,33 @@ import { getColorComponents } from './components.js';
13
13
  * @param color
14
14
  * @returns
15
15
  */
16
- function getColorSpace(color) {
16
+ function getColorSpace(arena, color) {
17
17
  // if (!("chi" in color)) {
18
18
  // return "rgb";
19
19
  // }
20
20
  let name;
21
- const components = getColorComponents(color);
21
+ const components = getColorComponents(arena, color);
22
22
  if (components == null || components.length < 3) {
23
23
  return null;
24
24
  }
25
- if (equalsIgnoreCase("color", color.val)) {
26
- if (equalsIgnoreCase("from", components[0].val)) {
27
- name = components[2].val;
25
+ if (equalsIgnoreCase("color", arena.strings[arena.stringValue[color]])) {
26
+ if (equalsIgnoreCase("from", arena.strings[arena.stringValue[components[0]]])) {
27
+ name = arena.strings[arena.stringValue[components[2]]];
28
28
  }
29
29
  else {
30
- name = components[0].val;
30
+ name = arena.strings[arena.stringValue[components[0]]];
31
31
  }
32
32
  }
33
- else if (equalsIgnoreCase("color-mix", color.val)) {
34
- if (equalsIgnoreCase("in", components[0].val)) {
35
- name = components[1].val;
33
+ else if (equalsIgnoreCase("color-mix", arena.strings[arena.stringValue[color]])) {
34
+ if (equalsIgnoreCase("in", arena.strings[arena.stringValue[components[0]]])) {
35
+ name = arena.strings[arena.stringValue[components[1]]];
36
36
  }
37
37
  else {
38
38
  return "oklab";
39
39
  }
40
40
  }
41
41
  else {
42
- name = color.val;
42
+ name = arena.strings[arena.stringValue[color]];
43
43
  }
44
44
  return name == "device-cmyk"
45
45
  ? "cmyk"
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.8.1
5
+ Version: 2.0.0
6
6
  License: MIT
7
7
  */
8
8
  import { ColorType, EnumToken } from '../../../ast/types.js';
@@ -10,38 +10,37 @@ import { COLORS_NAMES } from '../../constants.js';
10
10
  import { expandHexValue } from '../hex.js';
11
11
  import { equalsIgnoreCase } from '../../../parser/utils/text.js';
12
12
 
13
- function getColorComponents(token) {
14
- if (token.kin == ColorType.HEX || token.kin == ColorType.LIT) {
15
- if (equalsIgnoreCase("currentcolor", token.val)) {
13
+ function getColorComponents(arena, token) {
14
+ if (arena.colorType[token] == ColorType.HEX || arena.colorType[token] == ColorType.LIT) {
15
+ const val = arena.strings[arena.stringValue[token]];
16
+ if (equalsIgnoreCase("currentcolor", val)) {
16
17
  return null;
17
18
  }
18
- const value = expandHexValue(token.kin == ColorType.LIT ? COLORS_NAMES[token.val.toLowerCase()] : token.val);
19
+ const value = expandHexValue(arena.colorType[token] == ColorType.LIT ? COLORS_NAMES[val.toLowerCase()] : val);
19
20
  // @ts-ignore
20
21
  return value
21
22
  .slice(1)
22
23
  .match(/([a-fA-F0-9]{2})/g)
23
- .map((t, index) => {
24
- return { typ: EnumToken.Number, val: index < 3 ? parseInt(t, 16) : parseInt(t, 16) / 255 };
25
- });
24
+ .map((t, index) => arena.createToken(EnumToken.Number, index < 3 ? parseInt(t, 16) : parseInt(t, 16) / 255));
26
25
  }
27
26
  const result = [];
28
- for (const child of token.chi) {
29
- if ([
30
- EnumToken.LiteralTokenType,
31
- EnumToken.CommentTokenType,
32
- EnumToken.CommaTokenType,
33
- EnumToken.WhitespaceTokenType,
34
- ].includes(child.typ)) {
27
+ for (let child = arena.firstToken[token]; child != 0; child = arena.nextSibling[child]) {
28
+ const typ = arena.dataTypes[child];
29
+ if (typ == EnumToken.LiteralTokenType ||
30
+ typ == EnumToken.CommentTokenType ||
31
+ typ == EnumToken.CommaTokenType ||
32
+ typ == EnumToken.WhitespaceTokenType) {
35
33
  continue;
36
34
  }
37
- if (child.typ === EnumToken.FunctionTokenType ||
38
- child.typ === EnumToken.WildCardFunctionTokenType ||
39
- child.typ === EnumToken.MathFunctionTokenType) {
40
- if ("var" == child.val.toLowerCase()) {
35
+ if (typ === EnumToken.FunctionTokenType ||
36
+ typ === EnumToken.WildCardFunctionTokenType ||
37
+ typ === EnumToken.MathFunctionTokenType) {
38
+ if ("var" == arena.strings[arena.stringValue[child]].toLowerCase()) {
41
39
  return null;
42
40
  }
43
41
  }
44
- if (child.typ == EnumToken.ColorTokenType && equalsIgnoreCase("currentcolor", child.val)) {
42
+ if (typ == EnumToken.ColorTokenType &&
43
+ equalsIgnoreCase("currentcolor", arena.strings[arena.stringValue[child]])) {
45
44
  return null;
46
45
  }
47
46
  result.push(child);
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.8.1
5
+ Version: 2.0.0
6
6
  License: MIT
7
7
  */
8
8
  import { convertColor } from '../color.js';
@@ -16,17 +16,18 @@ import { toPrecisionValue } from '../../syntax.js';
16
16
  *
17
17
  * @private
18
18
  * {@link https://drafts.csswg.org/css-color-4/#comparing-color-values}
19
+ * @param arena
19
20
  * @param color1
20
21
  * @param color2
21
22
  */
22
- function okLabDistance(color1, color2) {
23
- color1 = convertColor(color1, ColorType.OKLAB);
24
- color2 = convertColor(color2, ColorType.OKLAB);
25
- if (color1 == null || color2 == null) {
23
+ function okLabDistance(arena, color1, color2) {
24
+ const c1 = convertColor(arena, color1, ColorType.OKLAB);
25
+ const c2 = convertColor(arena, color2, ColorType.OKLAB);
26
+ if (c1 == null || c2 == null) {
26
27
  return null;
27
28
  }
28
- const okLab1 = getOKLABComponents(color1);
29
- const okLab2 = getOKLABComponents(color2);
29
+ const okLab1 = getOKLABComponents(arena, c1);
30
+ const okLab2 = getOKLABComponents(arena, c2);
30
31
  if (okLab1 == null || okLab2 == null) {
31
32
  return null;
32
33
  }
@@ -39,20 +40,21 @@ function okLabDistance(color1, color2) {
39
40
  }
40
41
  /**
41
42
  * Check if two colors are close in okLab space.
43
+ * @param arena
42
44
  * @param color1
43
45
  * @param color2
44
46
  * @param threshold
45
47
  *
46
48
  * @private
47
49
  */
48
- function isOkLabClose(color1, color2, threshold = colorDistancePrecision) {
49
- color1 = convertColor(color1, ColorType.OKLAB);
50
- color2 = convertColor(color2, ColorType.OKLAB);
51
- if (color1 == null || color2 == null) {
50
+ function isOkLabClose(arena, color1, color2, threshold = colorDistancePrecision) {
51
+ const c1 = convertColor(arena, color1, ColorType.OKLAB);
52
+ const c2 = convertColor(arena, color2, ColorType.OKLAB);
53
+ if (c1 == null || c2 == null) {
52
54
  return false;
53
55
  }
54
- const okLab1 = getOKLABComponents(color1);
55
- const okLab2 = getOKLABComponents(color2);
56
+ const okLab1 = getOKLABComponents(arena, c1);
57
+ const okLab2 = getOKLABComponents(arena, c2);
56
58
  if (okLab1 == null || okLab2 == null) {
57
59
  return false;
58
60
  }
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.8.1
5
+ Version: 2.0.0
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken, ColorType } from '../../../ast/types.js';
@@ -16,48 +16,44 @@ import { minmax, getNumber } from '../color.js';
16
16
  * @param alpha
17
17
  * @returns
18
18
  */
19
- function makeColor(kind, components, alpha) {
19
+ function makeColor(arena, kind, components, alpha) {
20
20
  if (components.length < 3) {
21
21
  return null;
22
22
  }
23
23
  const alphaValue = alpha == null
24
24
  ? 1
25
- : alpha.typ === EnumToken.IdenTokenType && equalsIgnoreCase(alpha.val, "none")
25
+ : arena.dataTypes[alpha] === EnumToken.IdenTokenType && equalsIgnoreCase(arena.strings[arena.stringValue[alpha]], "none")
26
26
  ? 0
27
- : minmax(getNumber(alpha), 0, 1);
27
+ : minmax(getNumber(arena, alpha), 0, 1);
28
28
  components.length = 3;
29
+ // the components may belong to another color token: a token belongs to one token list
30
+ for (let i = 0; i < components.length; i++) {
31
+ // inlined: arena.take(components[i])
32
+ components[i] = arena.parents[components[i]] == 0 ? components[i] : arena.clone(components[i], true);
33
+ }
29
34
  if (alphaValue !== 1) {
30
- components.push({ typ: EnumToken.NumberTokenType, val: alphaValue });
35
+ components.push(arena.createToken(EnumToken.NumberTokenType, alphaValue));
31
36
  }
32
37
  if (kind === ColorType.LIT || kind === ColorType.HEX) {
33
38
  const val = "#" +
34
39
  components.reduce((acc, token, index) => {
35
- let value = getNumber(token);
40
+ let value = getNumber(arena, token);
36
41
  if (index === 3) {
37
42
  value *= 255;
38
43
  }
39
44
  return acc + Math.round(value).toString(16).padStart(2, "0");
40
45
  }, "");
41
- return {
42
- typ: EnumToken.ColorTokenType,
43
- val,
44
- kin: ColorType.HEX,
45
- };
46
+ return arena.createColor(val, ColorType.HEX);
46
47
  }
47
48
  const hasAlpha = components.length === 4;
48
49
  let i = components.length;
49
50
  while (--i > 0) {
50
- components.splice(i, 0, { typ: EnumToken.WhitespaceTokenType });
51
+ components.splice(i, 0, arena.createToken(EnumToken.WhitespaceTokenType));
51
52
  }
52
53
  if (hasAlpha) {
53
- components[components.length - 2] = { typ: EnumToken.LiteralTokenType, val: "/" };
54
+ components[components.length - 2] = arena.createToken(EnumToken.LiteralTokenType, "/");
54
55
  }
55
- return {
56
- typ: EnumToken.ColorTokenType,
57
- val: ColorType[kind].toLowerCase(),
58
- chi: components,
59
- kin: kind,
60
- };
56
+ return arena.createColor(ColorType[kind].toLowerCase(), kind, components);
61
57
  }
62
58
 
63
59
  export { makeColor };
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.8.1
5
+ Version: 2.0.0
6
6
  License: MIT
7
7
  */
8
8
  // from https://www.w3.org/TR/css-color-4/multiply-matrices.js
@@ -32,7 +32,7 @@ function multiplyMatrices(A, B) {
32
32
  return row.reduce((a, c, i) => a + c * (col[i] || 0), 0);
33
33
  }));
34
34
  // if (m === 1) {
35
- // product = <number[]>product[0]; // Avoid [[a, b, c, ...]]
35
+ // product = <Token[]>product[0]; // Avoid [[a, b, c, ...]]
36
36
  // }
37
37
  if (p === 1) {
38
38
  // @ts-expect-error
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.8.1
5
+ Version: 2.0.0
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 and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.8.1
5
+ Version: 2.0.0
6
6
  License: MIT
7
7
  */
8
8
  import { lsrgb2srgbvalues } from './srgb.js';
@@ -2,30 +2,16 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.8.1
5
+ Version: 2.0.0
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
- /**
12
- * Location source id
13
- */
14
- const LOCSRCID = Symbol.for("locSrcId");
15
- const LOCSTA = Symbol.for("locSta");
16
- const LOCEND = Symbol.for("locEnd");
17
11
  /**
18
12
  * Used by the validation parser
19
13
  */
20
14
  const LOC = Symbol.for("loc");
21
- const RAW = Symbol.for("raw");
22
- const STATE = Symbol.for("state");
23
- const ROOT = Symbol.for("root");
24
- const ERRORS = Symbol.for("errors");
25
- const TOKENS = Symbol.for("tokens");
26
- const PARENT = Symbol.for("parent");
27
- const OPTIMIZED = Symbol.for("optimized");
28
- const PROPERTYNAME = Symbol.for("propertyName");
29
15
  const regMatchLinearGradient = /^-((webkit)|o|moz)(-repeating)?-linear-gradient$/i;
30
16
  const regMatchRadialGradient = /^-((webkit)|o|moz)(-repeating)?-radial-gradient$/i;
31
17
  const mFLT = new Set([EnumToken.LtTokenType, EnumToken.LteTokenType]);
@@ -506,4 +492,4 @@ const trimTokenSpace = new Set([
506
492
  ]);
507
493
  const combinators = ["+", ">", "~", "||", "|"];
508
494
 
509
- export { COLORS_NAMES, D50, ERRORS, LOC, LOCEND, LOCSRCID, LOCSTA, NAMES_COLORS, OPTIMIZED, PARENT, PROPERTYNAME, RAW, ROOT, STATE, TOKENS, anglePrecision, colorDistancePrecision, colorFuncColorSpace, colorPrecision, colorRange, colorsFunc, combinators, containerFunc, deprecatedSystemColors, e, epsilon, funcLike, gridTemplateFunc, imageFunc, k, mFGT, mFLT, mathFuncs, mediaTypes, nonStandardColors, pageMarginBoxType, pseudoElements, regMatchLinearGradient, regMatchRadialGradient, supportFunc, systemColors, timelineFunc, timingFunc, tokensMap, tokensfuncDefMap, tokensfuncSet, transformFunctions, trimTokenSpace, urlFunc, urlTokenMatcher, whenElseFunc, wildCardFuncs };
495
+ export { COLORS_NAMES, D50, LOC, NAMES_COLORS, anglePrecision, colorDistancePrecision, colorFuncColorSpace, colorPrecision, colorRange, colorsFunc, combinators, containerFunc, deprecatedSystemColors, e, epsilon, funcLike, gridTemplateFunc, imageFunc, k, mFGT, mFLT, mathFuncs, mediaTypes, nonStandardColors, pageMarginBoxType, pseudoElements, regMatchLinearGradient, regMatchRadialGradient, supportFunc, systemColors, timelineFunc, timingFunc, tokensMap, tokensfuncDefMap, tokensfuncSet, transformFunctions, trimTokenSpace, urlFunc, urlTokenMatcher, whenElseFunc, wildCardFuncs };