@tbela99/css-parser 1.5.0 → 1.6.1

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 (78) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +10 -10
  3. package/dist/index-umd-web.js +5998 -4972
  4. package/dist/index.cjs +6001 -4977
  5. package/dist/index.d.ts +52 -38
  6. package/dist/lib/ast/expand.js +21 -7
  7. package/dist/lib/ast/features/calc.js +17 -55
  8. package/dist/lib/ast/features/if.js +7 -3
  9. package/dist/lib/ast/features/inlinecssvariables.js +6 -5
  10. package/dist/lib/ast/features/prefix.js +41 -44
  11. package/dist/lib/ast/features/shorthand.js +10 -5
  12. package/dist/lib/ast/features/transform.js +2 -2
  13. package/dist/lib/ast/math/expression.js +207 -34
  14. package/dist/lib/ast/minify.js +121 -24
  15. package/dist/lib/ast/node.js +5 -3
  16. package/dist/lib/ast/transform/compute.js +37 -5
  17. package/dist/lib/ast/transform/minify.js +7 -7
  18. package/dist/lib/ast/transform/perspective.js +1 -1
  19. package/dist/lib/ast/transform/rotate.js +1 -1
  20. package/dist/lib/ast/transform/scale.js +1 -1
  21. package/dist/lib/ast/transform/skew.js +1 -1
  22. package/dist/lib/ast/transform/translate.js +1 -1
  23. package/dist/lib/ast/transform/utils.js +46 -18
  24. package/dist/lib/ast/walk.js +28 -4
  25. package/dist/{config.json.js → lib/data/properties.json.js} +106 -0
  26. package/dist/lib/{validation/config.json.js → data/validation.json.js} +14 -8
  27. package/dist/lib/fs/resolve.js +11 -2
  28. package/dist/lib/parser/declaration/list.js +22 -7
  29. package/dist/lib/parser/declaration/map.js +26 -8
  30. package/dist/lib/parser/declaration/set.js +3 -1
  31. package/dist/lib/parser/linesmap.js +2 -4
  32. package/dist/lib/parser/parse.js +393 -231
  33. package/dist/lib/parser/tokenize.js +1478 -819
  34. package/dist/lib/parser/utils/at-rule-container.js +28 -196
  35. package/dist/lib/parser/utils/at-rule-generic.js +6 -7
  36. package/dist/lib/parser/utils/at-rule-import.js +17 -13
  37. package/dist/lib/parser/utils/at-rule-media.js +36 -19
  38. package/dist/lib/parser/utils/at-rule-support.js +19 -9
  39. package/dist/lib/parser/utils/at-rule-when-else.js +11 -38
  40. package/dist/lib/parser/utils/at-rule.js +0 -18
  41. package/dist/lib/parser/utils/config.js +1 -1
  42. package/dist/lib/parser/utils/declaration.js +40 -97
  43. package/dist/lib/parser/utils/hash.js +4 -4
  44. package/dist/lib/parser/utils/selector.js +179 -224
  45. package/dist/lib/parser/utils/text.js +4 -2
  46. package/dist/lib/renderer/render.js +104 -74
  47. package/dist/lib/renderer/sourcemap/lib/codec.js +3 -3
  48. package/dist/lib/renderer/sourcemap/sourcemap.js +2 -5
  49. package/dist/lib/syntax/color/a98rgb.js +14 -4
  50. package/dist/lib/syntax/color/cmyk.js +14 -21
  51. package/dist/lib/syntax/color/color-mix.js +21 -34
  52. package/dist/lib/syntax/color/color.js +32 -49
  53. package/dist/lib/syntax/color/hsl.js +15 -15
  54. package/dist/lib/syntax/color/hwb.js +18 -17
  55. package/dist/lib/syntax/color/lab.js +17 -17
  56. package/dist/lib/syntax/color/lch.js +13 -13
  57. package/dist/lib/syntax/color/oklab.js +10 -11
  58. package/dist/lib/syntax/color/oklch.js +15 -18
  59. package/dist/lib/syntax/color/p3.js +18 -12
  60. package/dist/lib/syntax/color/prophotorgb.js +26 -28
  61. package/dist/lib/syntax/color/rec2020.js +8 -4
  62. package/dist/lib/syntax/color/relative-color.js +26 -10
  63. package/dist/lib/syntax/color/srgb.js +9 -7
  64. package/dist/lib/syntax/color/utils/distance.js +1 -1
  65. package/dist/lib/syntax/color/xyz.js +2 -2
  66. package/dist/lib/syntax/color/xyzd50.js +2 -2
  67. package/dist/lib/syntax/constants.js +13 -3
  68. package/dist/lib/syntax/syntax.js +32 -108
  69. package/dist/lib/validation/config.js +1 -1
  70. package/dist/lib/validation/match.js +29 -26
  71. package/dist/lib/validation/parser/parse.js +7 -3
  72. package/dist/node.js +16 -9
  73. package/dist/types.d.ts +5 -1
  74. package/dist/types.js +4 -0
  75. package/dist/utils/sync.js +22 -1
  76. package/dist/web.js +13 -4
  77. package/package.json +4 -4
  78. package/llms.txt +0 -80
@@ -3,20 +3,32 @@ import { multiplyMatrices } from './utils/matrix.js';
3
3
  import { srgb2xyz } from './xyz.js';
4
4
 
5
5
  function p32srgbvalues(r, g, b, alpha) {
6
+ let values = p32lp3(r, g, b);
7
+ values = lp32xyz(values[0], values[1], values[2]);
6
8
  // @ts-ignore
7
- return xyz2srgb(...lp32xyz(...p32lp3(r, g, b, alpha)));
9
+ return xyz2srgb(values[0], values[1], values[2], alpha);
8
10
  }
9
11
  function srgb2p3values(r, g, b, alpha) {
10
- // @ts-ignore
11
- return lp32p3(...xyz2lp3(...srgb2xyz(r, g, b, alpha)));
12
+ let values = srgb2xyz(r, g, b);
13
+ values = xyz2lp3(values[0], values[1], values[2]);
14
+ values = lp32p3(values[0], values[1], values[2]);
15
+ if (alpha != null && alpha < 1) {
16
+ values.push(alpha);
17
+ }
18
+ return values;
12
19
  }
13
20
  function srgb2lp3values(r, g, b, alpha) {
14
- // @ts-ignore
15
- return xyz2lp3(...srgb2xyz(r, g, b, alpha));
21
+ let values = srgb2xyz(r, g, b);
22
+ values = xyz2lp3(values[0], values[1], values[2]);
23
+ if (alpha != null && alpha < 1) {
24
+ values.push(alpha);
25
+ }
26
+ return values;
16
27
  }
17
28
  function lp32srgbvalues(r, g, b, alpha) {
29
+ let values = lp32xyz(r, g, b);
18
30
  // @ts-ignore
19
- return xyz2srgb(...lp32xyz(r, g, b, alpha));
31
+ return xyz2srgb(values[0], values[1], values[2], alpha);
20
32
  }
21
33
  function p32lp3(r, g, b, alpha) {
22
34
  // convert an array of display-p3 RGB values in the range 0.0 - 1.0
@@ -38,9 +50,6 @@ function lp32xyz(r, g, b, alpha) {
38
50
  [0, 32229 / 714400, 5220557 / 5000800],
39
51
  ];
40
52
  const result = multiplyMatrices(M, [r, g, b]);
41
- if (alpha != null && alpha != 1) {
42
- result.push(alpha);
43
- }
44
53
  return result;
45
54
  }
46
55
  function xyz2lp3(x, y, z, alpha) {
@@ -51,9 +60,6 @@ function xyz2lp3(x, y, z, alpha) {
51
60
  [11844 / 330415, -50337 / 660830, 316169 / 330415],
52
61
  ];
53
62
  const result = multiplyMatrices(M, [x, y, z]);
54
- if (alpha != null && alpha != 1) {
55
- result.push(alpha);
56
- }
57
63
  return result;
58
64
  }
59
65
 
@@ -2,55 +2,53 @@ import { XYZ_D65_to_D50, xyzd502srgb } from './xyzd50.js';
2
2
  import { srgb2xyz } from './xyz.js';
3
3
 
4
4
  function prophotorgb2srgbvalues(r, g, b, a = null) {
5
+ let values = prophotorgb2xyz50(r, g, b);
5
6
  // @ts-ignore
6
- return xyzd502srgb(...prophotorgb2xyz50(r, g, b, a));
7
+ return xyzd502srgb(values[0], values[1], values[2], a);
7
8
  }
8
9
  function srgb2prophotorgbvalues(r, g, b, a) {
9
- // @ts-ignore
10
- return xyz50_to_prophotorgb(...XYZ_D65_to_D50(...srgb2xyz(r, g, b, a)));
10
+ let values = srgb2xyz(r, g, b);
11
+ values = XYZ_D65_to_D50(values[0], values[1], values[2]);
12
+ values = xyz50_to_prophotorgb(values[0], values[1], values[2]);
13
+ if (a != null && a < 1) {
14
+ values.push(a);
15
+ }
16
+ return values;
11
17
  }
12
18
  function prophotorgb2lin_ProPhoto(r, g, b, a = null) {
13
- return [r, g, b].map(v => {
19
+ return [r, g, b]
20
+ .map((v) => {
14
21
  let abs = Math.abs(v);
15
22
  if (abs >= 16 / 512) {
16
23
  return Math.sign(v) * Math.pow(abs, 1.8);
17
24
  }
18
25
  return v / 16;
19
- }).concat(a == null || a == 1 ? [] : [a]);
26
+ })
27
+ .concat(a == null || a == 1 ? [] : [a]);
20
28
  }
21
29
  function prophotorgb2xyz50(r, g, b, a = null) {
22
30
  [r, g, b, a] = prophotorgb2lin_ProPhoto(r, g, b, a);
23
31
  const xyz = [
24
- 0.7977666449006423 * r +
25
- 0.1351812974005331 * g +
26
- 0.0313477341283922 * b,
27
- 0.2880748288194013 * r +
28
- 0.7118352342418731 * g +
29
- 0.0000899369387256 * b,
30
- 0.8251046025104602 * b
32
+ 0.7977666449006423 * r + 0.1351812974005331 * g + 0.0313477341283922 * b,
33
+ 0.2880748288194013 * r + 0.7118352342418731 * g + 0.0000899369387256 * b,
34
+ 0.8251046025104602 * b,
31
35
  ];
32
36
  return xyz.concat(a == null || a == 1 ? [] : [a]);
33
37
  }
34
38
  function xyz50_to_prophotorgb(x, y, z, a) {
35
39
  // @ts-ignore
36
- return gam_prophotorgb(...[
37
- x * 1.3457868816471585 -
38
- y * 0.2555720873797946 -
39
- 0.0511018649755453 * z,
40
- x * -0.5446307051249019 +
41
- y * 1.5082477428451466 +
42
- 0.0205274474364214 * z,
43
- 1.2119675456389452 * z
44
- ].concat(a == null || a == 1 ? [] : [a]));
40
+ return gam_prophotorgb(x * 1.3457868816471585 - y * 0.2555720873797946 - 0.0511018649755453 * z, x * -0.5446307051249019 + y * 1.5082477428451466 + 0.0205274474364214 * z, 1.2119675456389452 * z);
41
+ }
42
+ function gam_prophotorgbvalue(v) {
43
+ let abs = Math.abs(v);
44
+ if (abs >= 1 / 512) {
45
+ return Math.sign(v) * Math.pow(abs, 1 / 1.8);
46
+ }
47
+ return 16 * v;
45
48
  }
46
49
  function gam_prophotorgb(r, g, b, a) {
47
- return [r, g, b].map(v => {
48
- let abs = Math.abs(v);
49
- if (abs >= 1 / 512) {
50
- return Math.sign(v) * Math.pow(abs, 1 / 1.8);
51
- }
52
- return 16 * v;
53
- }).concat(a == null || a == 1 ? [] : [a]);
50
+ const values = [gam_prophotorgbvalue(r), gam_prophotorgbvalue(g), gam_prophotorgbvalue(b)];
51
+ return values;
54
52
  }
55
53
 
56
54
  export { prophotorgb2srgbvalues, srgb2prophotorgbvalues };
@@ -3,12 +3,16 @@ import { multiplyMatrices } from './utils/matrix.js';
3
3
  import { srgb2xyz } from './xyz.js';
4
4
 
5
5
  function rec20202srgb(r, g, b, a) {
6
+ let values = rec20202lrec2020(r, g, b);
7
+ values = lrec20202xyz(values[0], values[1], values[2]);
6
8
  // @ts-ignore
7
- return xyz2srgb(...lrec20202xyz(...rec20202lrec2020(r, g, b)), a);
9
+ return xyz2srgb(values[0], values[1], values[2], a);
8
10
  }
9
11
  function srgb2rec2020values(r, g, b, a) {
12
+ let values = srgb2xyz(r, g, b);
13
+ values = xyz2lrec2020(values[0], values[1], values[2]);
10
14
  // @ts-ignore
11
- return lrec20202rec2020(...xyz2lrec2020(...srgb2xyz(r, g, b)), a);
15
+ return lrec20202rec2020(values[0], values[1], values[2], a);
12
16
  }
13
17
  function rec20202lrec2020(r, g, b, a) {
14
18
  // convert an array of rec2020 RGB values in the range 0.0 - 1.0
@@ -54,7 +58,7 @@ function lrec20202xyz(r, g, b, a) {
54
58
  [0, 19567812 / 697040785, 295819943 / 278816314],
55
59
  ];
56
60
  // 0 is actually calculated as 4.994106574466076e-17
57
- return multiplyMatrices(M, [r, g, b]).concat(a == null || a == 1 ? [] : [a]);
61
+ return multiplyMatrices(M, [r, g, b]).concat([] );
58
62
  }
59
63
  function xyz2lrec2020(x, y, z, a) {
60
64
  // convert XYZ to linear-light rec2020
@@ -63,7 +67,7 @@ function xyz2lrec2020(x, y, z, a) {
63
67
  [-19765991 / 29648200, 47925759 / 29648200, 467509 / 29648200],
64
68
  [792561 / 44930125, -1921689 / 44930125, 42328811 / 44930125],
65
69
  ];
66
- return multiplyMatrices(M, [x, y, z]).concat(a == null || a == 1 ? [] : [a]);
70
+ return multiplyMatrices(M, [x, y, z]).concat([] );
67
71
  }
68
72
 
69
73
  export { rec20202srgb, srgb2rec2020values };
@@ -2,7 +2,7 @@ import { convertColor, getNumber } from './color.js';
2
2
  import { EnumToken, ColorType } from '../../ast/types.js';
3
3
  import { walkValues } from '../../ast/walk.js';
4
4
  import { evaluateFunc, evaluate } from '../../ast/math/expression.js';
5
- import { colorsFunc, colorFuncColorSpace, LOC, colorRange, mathFuncs } from '../constants.js';
5
+ import { colorsFunc, colorFuncColorSpace, LOCEND, LOCSTA, LOCSRCID, colorRange, mathFuncs } from '../constants.js';
6
6
  import { equalsIgnoreCase } from '../../parser/utils/text.js';
7
7
  import { getColorComponents } from './utils/components.js';
8
8
 
@@ -34,7 +34,9 @@ function parseRelativeColorComponents(relativeKeys, original, rExp, gExp, bExp,
34
34
  const validKeys = names.split("");
35
35
  let val = "";
36
36
  if (components != null) {
37
- allComponents.push(...components);
37
+ for (const component of components) {
38
+ allComponents.push(component);
39
+ }
38
40
  }
39
41
  // ensure all components are valid for the color space
40
42
  for (const component of allComponents) {
@@ -103,19 +105,25 @@ function parseRelativeColorComponents(relativeKeys, original, rExp, gExp, bExp,
103
105
  ? {
104
106
  typ: EnumToken.NumberTokenType,
105
107
  val: 1,
106
- [LOC]: b[LOC],
108
+ [LOCSRCID]: b[LOCSRCID],
109
+ [LOCSTA]: b[LOCSTA],
110
+ [LOCEND]: b[LOCEND],
107
111
  }
108
112
  : alpha.typ == EnumToken.IdenTokenType && alpha.val == "none"
109
113
  ? {
110
114
  typ: EnumToken.NumberTokenType,
111
115
  val: 0,
112
- [LOC]: alpha[LOC],
116
+ [LOCSRCID]: alpha[LOCSRCID],
117
+ [LOCSTA]: alpha[LOCSTA],
118
+ [LOCEND]: alpha[LOCEND],
113
119
  }
114
120
  : alpha.typ == EnumToken.PercentageTokenType
115
121
  ? {
116
122
  typ: EnumToken.NumberTokenType,
117
123
  val: getNumber(alpha),
118
- [LOC]: alpha[LOC],
124
+ [LOCSRCID]: alpha[LOCSRCID],
125
+ [LOCSTA]: alpha[LOCSTA],
126
+ [LOCEND]: alpha[LOCEND],
119
127
  }
120
128
  : alpha,
121
129
  };
@@ -128,13 +136,17 @@ function parseRelativeColorComponents(relativeKeys, original, rExp, gExp, bExp,
128
136
  ? {
129
137
  typ: EnumToken.NumberTokenType,
130
138
  val: 1,
131
- [LOC]: bExp[LOC],
139
+ [LOCSRCID]: bExp[LOCSRCID],
140
+ [LOCSTA]: bExp[LOCSTA],
141
+ [LOCEND]: bExp[LOCEND],
132
142
  }
133
143
  : aExp.typ == EnumToken.IdenTokenType && aExp.val == "none"
134
144
  ? {
135
145
  typ: EnumToken.NumberTokenType,
136
146
  val: 0,
137
- [LOC]: aExp[LOC],
147
+ [LOCSRCID]: aExp[LOCSRCID],
148
+ [LOCSTA]: aExp[LOCSTA],
149
+ [LOCEND]: aExp[LOCEND],
138
150
  }
139
151
  : aExp),
140
152
  };
@@ -165,7 +177,9 @@ function getValue(t, converted, component) {
165
177
  return {
166
178
  typ: EnumToken.NumberTokenType,
167
179
  val: value,
168
- [LOC]: t[LOC],
180
+ [LOCSRCID]: t[LOCSRCID],
181
+ [LOCSTA]: t[LOCSTA],
182
+ [LOCEND]: t[LOCEND],
169
183
  };
170
184
  }
171
185
  return t;
@@ -208,8 +222,10 @@ function computeComponentValue(expr, values) {
208
222
  {
209
223
  typ: EnumToken.NumberTokenType,
210
224
  // @ts-ignore
211
- val: "" + Math[value.val.toUpperCase()],
212
- [LOC]: value[LOC],
225
+ val: Math[value.val.toUpperCase()],
226
+ [LOCSRCID]: value[LOCSRCID],
227
+ [LOCSTA]: value[LOCSTA],
228
+ [LOCEND]: value[LOCEND],
213
229
  // @ts-ignore
214
230
  });
215
231
  }
@@ -69,8 +69,9 @@ function hex2srgbvalues(token) {
69
69
  }
70
70
  // xyz d65 input
71
71
  function xyz2srgb(x, y, z, alpha = null) {
72
+ let values = XYZ_to_lin_sRGB(x, y, z);
72
73
  // @ts-ignore
73
- return lsrgb2srgbvalues(...XYZ_to_lin_sRGB(x, y, z, alpha));
74
+ return lsrgb2srgbvalues(values[0], values[1], values[2], alpha);
74
75
  }
75
76
  function hwb2srgbvalues(token) {
76
77
  const { h: hue, s: white, l: black, a: alpha } = hslvalues(token) ?? {};
@@ -115,10 +116,11 @@ function cmyk2srgbvalues(token) {
115
116
  t = components[3];
116
117
  // @ts-ignore
117
118
  const k = getNumber(t);
119
+ const mul = 1 - k;
118
120
  const rgb = [
119
- 1 - Math.min(1, c * (1 - k) + k),
120
- 1 - Math.min(1, m * (1 - k) + k),
121
- 1 - Math.min(1, y * (1 - k) + k),
121
+ 1 - Math.min(1, c * mul + k),
122
+ 1 - Math.min(1, m * mul + k),
123
+ 1 - Math.min(1, y * mul + k),
122
124
  ];
123
125
  if (components.length == 5) {
124
126
  rgb.push(getNumber(components[4]));
@@ -141,8 +143,8 @@ function oklch2srgbvalues(token) {
141
143
  if (l == null || c == null || h == null) {
142
144
  return null;
143
145
  }
144
- // @ts-ignore
145
- const rgb = OKLab_to_sRGB(...lchvalues2labvalues(l, c, h));
146
+ const values = lchvalues2labvalues(l, c, h);
147
+ const rgb = OKLab_to_sRGB(values[0], values[1], values[2]);
146
148
  if (alpha != 1) {
147
149
  rgb.push(alpha);
148
150
  }
@@ -243,7 +245,7 @@ function lch2srgbvalues(token) {
243
245
  return null;
244
246
  }
245
247
  // @ts-ignore
246
- const [l, a, b, alpha] = lchvalues2labvalues(...components);
248
+ const [l, a, b, alpha] = lchvalues2labvalues(components[0], components[1], components[2], components[3]);
247
249
  if (l == null || a == null || b == null) {
248
250
  return null;
249
251
  }
@@ -28,7 +28,7 @@ function okLabDistance(color1, color2) {
28
28
  if (okLab1[3] != null || okLab2[3] != null) {
29
29
  diff.push((okLab1[3] ?? 1) - (okLab2[3] ?? 1));
30
30
  }
31
- return toPrecisionValue(Math.hypot(...diff));
31
+ return toPrecisionValue(Math.hypot(diff[0], diff[1], diff[2], diff[3] ?? 0));
32
32
  }
33
33
  /**
34
34
  * Check if two colors are close in okLab space.
@@ -41,8 +41,8 @@ function srgb2xyz(r, g, b, alpha) {
41
41
  // xyz d50
42
42
  function srgb2xyz_d65(r, g, b, alpha) {
43
43
  // xyx d65
44
- // @ts-ignore
45
- let rgb = XYZ_D65_to_D50(...srgb2xyz(r, g, b));
44
+ let values = srgb2xyz(r, g, b);
45
+ let rgb = XYZ_D65_to_D50(values[0], values[1], values[2]);
46
46
  if (alpha != null && alpha != 1) {
47
47
  rgb.push(alpha);
48
48
  }
@@ -7,8 +7,8 @@ import { labvalues2lchvalues } from './lch.js';
7
7
  /*
8
8
  */
9
9
  function xyzd502lch(x, y, z, alpha) {
10
- // @ts-ignore
11
- const [l, a, b] = xyz2lab(...XYZ_D50_to_D65(x, y, z));
10
+ const values = XYZ_D50_to_D65(x, y, z);
11
+ const [l, a, b] = xyz2lab(values[0], values[1], values[2]);
12
12
  // L in range [0,100]. For use in CSS, add a percent
13
13
  return labvalues2lchvalues(l, a, b, alpha);
14
14
  }
@@ -1,6 +1,15 @@
1
1
  import { EnumToken } from '../ast/types.js';
2
- import config from '../validation/config.json.js';
2
+ import config from '../data/validation.json.js';
3
3
 
4
+ /**
5
+ * Location source id
6
+ */
7
+ const LOCSRCID = Symbol.for("locSrcId");
8
+ const LOCSTA = Symbol.for("locSta");
9
+ const LOCEND = Symbol.for("locEnd");
10
+ /**
11
+ * Used by the validation parser
12
+ */
4
13
  const LOC = Symbol.for("loc");
5
14
  const RAW = Symbol.for("raw");
6
15
  const STATE = Symbol.for("state");
@@ -53,7 +62,7 @@ const colorPrecision = 6;
53
62
  /**
54
63
  * Angle precision
55
64
  */
56
- const anglePrecision = 0.001;
65
+ const anglePrecision = 3;
57
66
  /**
58
67
  * Color range definitions
59
68
  */
@@ -109,6 +118,7 @@ const mathFuncs = [
109
118
  "acos",
110
119
  "atan",
111
120
  "atan2",
121
+ "tan",
112
122
  "pow",
113
123
  "sqrt",
114
124
  "hypot",
@@ -484,4 +494,4 @@ const trimTokenSpace = new Set([
484
494
  ]);
485
495
  const combinators = ["+", ">", "~", "||", "|"];
486
496
 
487
- export { COLORS_NAMES, D50, ERRORS, LOC, 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 };
497
+ 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 };
@@ -8,14 +8,19 @@ import { trimArray } from '../validation/match.js';
8
8
  import { splitTokenList } from '../validation/utils/list.js';
9
9
  import { getColorSpace } from './color/utils/colorspace.js';
10
10
  import { getColorComponents } from './color/utils/components.js';
11
- import { nonStandardColors, systemColors, deprecatedSystemColors, COLORS_NAMES, colorsFunc, colorFuncColorSpace, colorPrecision, epsilon, anglePrecision } from './constants.js';
11
+ import { anglePrecision, nonStandardColors, systemColors, deprecatedSystemColors, COLORS_NAMES, colorsFunc, colorFuncColorSpace, colorPrecision, epsilon } from './constants.js';
12
12
  import { getSyntaxConfig } from '../validation/config.js';
13
13
 
14
14
  // https://www.w3.org/TR/CSS21/syndata.html#syntax
15
15
  // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token
16
16
  // '\\'
17
17
  const REVERSE_SOLIDUS = 0x5c;
18
- const dimensionUnits = new Set([
18
+ const flexUnits = ["fr"];
19
+ const frequencyUnits = ["hz", "khz"];
20
+ const timeUnits = ["ms", "s"];
21
+ const angleUnits = ["rad", "turn", "deg", "grad"];
22
+ const resolutionUnits = ["dpi", "dpcm", "dppx", "x"];
23
+ const dimensionUnits = [
19
24
  "q",
20
25
  "cap",
21
26
  "ch",
@@ -59,7 +64,7 @@ const dimensionUnits = new Set([
59
64
  "vmax",
60
65
  "vmin",
61
66
  "vw",
62
- ]);
67
+ ];
63
68
  // https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions
64
69
  // https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions
65
70
  const pseudoAliasMap = {
@@ -196,19 +201,19 @@ const pseudoAliasMap = {
196
201
  // renamed standard properties
197
202
  const renamedStandardProperties = new Map([["color-adjust", "print-color-adjust"]]);
198
203
  function isLength(dimension) {
199
- return "unit" in dimension && dimensionUnits.has(dimension.unit.toLowerCase());
204
+ return "unit" in dimension && dimensionUnits.includes(dimension.unit.toLowerCase());
200
205
  }
201
206
  function isResolution(dimension) {
202
- return "unit" in dimension && ["dpi", "dpcm", "dppx", "x"].includes(dimension.unit.toLowerCase());
207
+ return "unit" in dimension && resolutionUnits.includes(dimension.unit.toLowerCase());
203
208
  }
204
209
  function isAngle(dimension) {
205
- return "unit" in dimension && ["rad", "turn", "deg", "grad"].includes(dimension.unit.toLowerCase());
210
+ return "unit" in dimension && angleUnits.includes(dimension.unit.toLowerCase());
206
211
  }
207
212
  function isTime(dimension) {
208
- return "unit" in dimension && ["ms", "s"].includes(dimension.unit.toLowerCase());
213
+ return "unit" in dimension && timeUnits.includes(dimension.unit.toLowerCase());
209
214
  }
210
215
  function isFrequency(dimension) {
211
- return "unit" in dimension && ["hz", "khz"].includes(dimension.unit.toLowerCase());
216
+ return "unit" in dimension && frequencyUnits.includes(dimension.unit.toLowerCase());
212
217
  }
213
218
  /**
214
219
  * Reduce color stops
@@ -231,7 +236,9 @@ function reduceColorStops(stops) {
231
236
  if (parts[i - 1].length == 1) {
232
237
  parts[i - 1].push({ typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.PercentageTokenType, val: ((k - 1) * 100) / n });
233
238
  }
234
- parts[i - 1].push(...parts[i].slice(1));
239
+ for (let m = 1; m < parts[i].length; m++) {
240
+ parts[i - 1].push(parts[i][m]);
241
+ }
235
242
  parts.splice(i--, 1);
236
243
  updated = true;
237
244
  continue;
@@ -255,7 +262,9 @@ function reduceColorStops(stops) {
255
262
  if (stops.length > 0) {
256
263
  stops.push({ typ: EnumToken.CommaTokenType });
257
264
  }
258
- stops.push(...parts[j]);
265
+ for (let m = 0; m < parts[j].length; m++) {
266
+ stops.push(parts[j][m]);
267
+ }
259
268
  }
260
269
  }
261
270
  return stops;
@@ -353,7 +362,9 @@ function reduceConicColorStops(stops) {
353
362
  if (parts[i - 1].length == 1) {
354
363
  parts[i - 1].push({ typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.AngleTokenType, val: ((k - 1) * 100) / n, unit: "deg" });
355
364
  }
356
- parts[i - 1].push(...parts[i].slice(1));
365
+ for (let m = 1; m < parts[i].length; m++) {
366
+ parts[i - 1].push(parts[i][m]);
367
+ }
357
368
  parts.splice(i--, 1);
358
369
  updated = true;
359
370
  continue;
@@ -376,7 +387,9 @@ function reduceConicColorStops(stops) {
376
387
  if (stops.length > 0) {
377
388
  stops.push({ typ: EnumToken.CommaTokenType });
378
389
  }
379
- stops.push(...parts[j]);
390
+ for (const token of parts[j]) {
391
+ stops.push(token);
392
+ }
380
393
  }
381
394
  }
382
395
  return stops;
@@ -672,11 +685,10 @@ function isColor(token, errors) {
672
685
  return true;
673
686
  }
674
687
  else {
675
- const keywords = ["from", "none"];
676
688
  // @ts-ignore
677
689
  if (["rgb", "hsl", "hwb", "lab", "lch", "oklab", "oklch"].some((t) => equalsIgnoreCase(t, token.val))) {
678
- // @ts-ignore
679
- keywords.push("alpha", ...token.val.slice(-3).split(""));
690
+ for (const keyword of token.val.slice(-3).split("")) {
691
+ }
680
692
  }
681
693
  // @ts-ignore
682
694
  for (const v of token.chi) {
@@ -841,75 +853,6 @@ function isPseudo(name) {
841
853
  function isHash(name) {
842
854
  return name.charAt(0) == "#" && isIdentStart(name.charCodeAt(1));
843
855
  }
844
- const isNumber = memoize(function (name) {
845
- let codepoint = name.charCodeAt(0);
846
- let i = 0;
847
- const j = name.length;
848
- if (j == 1 && !isDigit(codepoint)) {
849
- return false;
850
- }
851
- // '+' '-'
852
- if ([0x2b, 0x2d].includes(codepoint)) {
853
- i++;
854
- }
855
- // consume digits
856
- while (i < j) {
857
- codepoint = name.charCodeAt(i);
858
- if (isDigit(codepoint)) {
859
- i++;
860
- continue;
861
- }
862
- // '.' 'E' 'e'
863
- if (codepoint == 0x2e || codepoint == 0x45 || codepoint == 0x65) {
864
- break;
865
- }
866
- return false;
867
- }
868
- // '.'
869
- if (codepoint == 0x2e) {
870
- if (!isDigit(name.charCodeAt(++i))) {
871
- return false;
872
- }
873
- }
874
- while (i < j) {
875
- codepoint = name.charCodeAt(i);
876
- if (isDigit(codepoint)) {
877
- i++;
878
- continue;
879
- }
880
- // 'E' 'e'
881
- if (codepoint == 0x45 || codepoint == 0x65) {
882
- i++;
883
- break;
884
- }
885
- return false;
886
- }
887
- // 'E' 'e'
888
- if (codepoint == 0x45 || codepoint == 0x65) {
889
- // if (i == j) {
890
- // return false;
891
- // }
892
- codepoint = name.charCodeAt(i + 1);
893
- // '+' '-'
894
- // if ([0x2b, 0x2d].includes(codepoint)) {
895
- // i++;
896
- // }
897
- codepoint = name.charCodeAt(i + 1);
898
- if (!isDigit(codepoint)) {
899
- return false;
900
- }
901
- }
902
- // while (++i < j) {
903
- // codepoint = name.charCodeAt(i) as number;
904
- // if (!isDigit(codepoint)) {
905
- // return false;
906
- // }
907
- // }
908
- return true;
909
- });
910
- function isPercentage(name) {
911
- return name.endsWith("%") && isNumber(name.slice(0, -1));
912
- }
913
856
  function isFlex(dimension) {
914
857
  return "unit" in dimension && "fr" == dimension.unit.toLowerCase();
915
858
  }
@@ -950,9 +893,9 @@ function parseDimension(name) {
950
893
  else if (isResolution(dimension)) {
951
894
  // @ts-ignore
952
895
  dimension.typ = EnumToken.ResolutionTokenType;
953
- if (dimension.unit == "dppx") {
954
- dimension.unit = "x";
955
- }
896
+ // if (dimension.unit == "dppx") {
897
+ // dimension.unit = "x";
898
+ // }
956
899
  }
957
900
  else if (isFrequency(dimension)) {
958
901
  // @ts-ignore
@@ -964,22 +907,6 @@ function parseDimension(name) {
964
907
  }
965
908
  return dimension;
966
909
  }
967
- function isHexColor(name) {
968
- if (name.charAt(0) != "#" || ![4, 5, 7, 9].includes(name.length)) {
969
- return false;
970
- }
971
- for (let chr of name.slice(1)) {
972
- let codepoint = chr.charCodeAt(0);
973
- if (!isDigit(codepoint) &&
974
- // A-F
975
- !(codepoint >= 0x41 && codepoint <= 0x46) &&
976
- // a-f
977
- !(codepoint >= 0x61 && codepoint <= 0x66)) {
978
- return false;
979
- }
980
- }
981
- return true;
982
- }
983
910
  function isFunction(name) {
984
911
  return name.endsWith("(") && isIdent(name.slice(0, -1));
985
912
  }
@@ -1074,18 +1001,15 @@ function toPrecisionValue(value, precision = colorPrecision) {
1074
1001
  value = Math.round(value * div) / div;
1075
1002
  return Math.abs(value) < epsilon ? 0 : value;
1076
1003
  }
1077
- function toPrecisionAngle(angle, precision = colorPrecision, correctValue = true) {
1004
+ function toPrecisionAngle(angle, precision = anglePrecision, correctValue = true) {
1078
1005
  angle = toPrecisionValue(angle, precision);
1079
1006
  if (correctValue && Math.abs(angle) >= 360) {
1080
1007
  angle %= 360;
1081
1008
  }
1082
- if (Math.abs(angle) < anglePrecision) {
1083
- angle = 0;
1084
- }
1085
1009
  if (correctValue && angle < 0) {
1086
1010
  angle += 360;
1087
1011
  }
1088
1012
  return angle;
1089
1013
  }
1090
1014
 
1091
- export { dimensionUnits, isAngle, isColor, isDigit, isFlex, isFrequency, isFunction, isHash, isHexColor, isIdent, isIdentCodepoint, isIdentColor, isIdentStart, isLength, isLetter, isNewLine, isNonPrintable, isNumber, isPercentage, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolution, isTime, isWhiteSpace, length2Px, minifyNumber, parseColor, parseDimension, pseudoAliasMap, reduceColorStops, reduceConicColorStops, reducegradientBackgroundPosition, renamedStandardProperties, toPrecisionAngle, toPrecisionValue };
1015
+ export { angleUnits, dimensionUnits, flexUnits, frequencyUnits, isAngle, isColor, isDigit, isFlex, isFrequency, isFunction, isHash, isIdent, isIdentCodepoint, isIdentColor, isIdentStart, isLength, isLetter, isNewLine, isNonPrintable, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolution, isTime, isWhiteSpace, length2Px, minifyNumber, parseColor, parseDimension, pseudoAliasMap, reduceColorStops, reduceConicColorStops, reducegradientBackgroundPosition, renamedStandardProperties, resolutionUnits, timeUnits, toPrecisionAngle, toPrecisionValue };
@@ -1,4 +1,4 @@
1
- import config from './config.json.js';
1
+ import config from '../data/validation.json.js';
2
2
  import { trimSyntaxArray, parseSyntax } from './parser/parse.js';
3
3
  import { ValidationTokenEnum } from './parser/typedef.js';
4
4
  import { memoize } from '../parser/utils/cache.js';