@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 { getColorComponents } from './utils/components.js';
@@ -78,7 +78,7 @@ function oklchToken(arena, values) {
78
78
  arena.createToken(EnumToken.NumberTokenType, values[1]),
79
79
  arena.createToken(EnumToken.NumberTokenType, values[2]),
80
80
  ];
81
- if (values.length == 4) {
81
+ if (values.length === 4) {
82
82
  chi.push(arena.createToken(EnumToken.LiteralTokenType, "/"), arena.createToken(EnumToken.PercentageTokenType, values[3] * 100));
83
83
  }
84
84
  return arena.createColor("oklch", ColorType.OKLCH, chi);
@@ -156,14 +156,14 @@ function getOKLCHComponents(arena, token) {
156
156
  // @ts-ignore
157
157
  t = components[1];
158
158
  // @ts-ignore
159
- const c = getNumber(arena, t) * (arena.dataTypes[t] == EnumToken.PercentageTokenType ? 0.4 : 1);
159
+ const c = getNumber(arena, t) * (arena.dataTypes[t] === EnumToken.PercentageTokenType ? 0.4 : 1);
160
160
  // @ts-ignore
161
161
  t = components[2];
162
162
  // @ts-ignore
163
163
  const h = getAngle(arena, t) * 360;
164
164
  // @ts-ignore
165
165
  t = components[3];
166
- const alpha = t == null || (arena.dataTypes[t] == EnumToken.IdenTokenType && arena.strings[arena.stringValue[t]] == "none")
166
+ const alpha = t == null || (arena.dataTypes[t] === EnumToken.IdenTokenType && arena.resolveString(arena.stringValue[t]) === "none")
167
167
  ? 1
168
168
  : getNumber(arena, t);
169
169
  return [l, c, h, alpha];
@@ -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 { lsrgb2srgbvalues, xyz2srgb, srgb2lsrgbvalues } from './srgb.js';
@@ -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 { XYZ_D65_to_D50, xyzd502srgb } from './xyzd50.js';
@@ -31,7 +31,7 @@ function prophotorgb2lin_ProPhoto(r, g, b, a = null) {
31
31
  }
32
32
  return v / 16;
33
33
  })
34
- .concat(a == null || a == 1 ? [] : [a]);
34
+ .concat(a == null || a === 1 ? [] : [a]);
35
35
  }
36
36
  function prophotorgb2xyz50(r, g, b, a = null) {
37
37
  [r, g, b, a] = prophotorgb2lin_ProPhoto(r, g, b, a);
@@ -40,7 +40,7 @@ function prophotorgb2xyz50(r, g, b, a = null) {
40
40
  0.2880748288194013 * r + 0.7118352342418731 * g + 0.0000899369387256 * b,
41
41
  0.8251046025104602 * b,
42
42
  ];
43
- return xyz.concat(a == null || a == 1 ? [] : [a]);
43
+ return xyz.concat(a == null || a === 1 ? [] : [a]);
44
44
  }
45
45
  function xyz50_to_prophotorgb(x, y, z, a) {
46
46
  // @ts-ignore
@@ -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 { xyz2srgb } from './srgb.js';
@@ -53,7 +53,7 @@ function lrec20202rec2020(r, g, b, a) {
53
53
  }
54
54
  return 4.5 * val;
55
55
  })
56
- .concat(a == null || a == 1 ? [] : [a]);
56
+ .concat(a == null || a === 1 ? [] : [a]);
57
57
  }
58
58
  function lrec20202xyz(r, g, b, a) {
59
59
  // convert an array of linear-light rec2020 values to CIE XYZ
@@ -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 { convertColor, getNumber } from './color.js';
@@ -15,6 +15,7 @@ import { ValueWalker } from '../../ast/walk.js';
15
15
 
16
16
  /**
17
17
  * Parse relative color components
18
+ * @param arena
18
19
  * @param relativeKeys
19
20
  * @param original
20
21
  * @param rExp
@@ -50,8 +51,8 @@ function parseRelativeColorComponents(arena, relativeKeys, original, rExp, gExp,
50
51
  if (component == null) {
51
52
  continue;
52
53
  }
53
- if (arena.dataTypes[component] == EnumToken.IdenTokenType) {
54
- val = arena.strings[arena.stringValue[component]];
54
+ if (arena.dataTypes[component] === EnumToken.IdenTokenType) {
55
+ val = arena.resolveString(arena.stringValue[component]);
55
56
  if (
56
57
  // @ts-expect-error
57
58
  typeof Math[val.toUpperCase()] !== "number" &&
@@ -72,23 +73,23 @@ function parseRelativeColorComponents(arena, relativeKeys, original, rExp, gExp,
72
73
  continue;
73
74
  }
74
75
  if (arena.dataTypes[component] === EnumToken.MathFunctionTokenType &&
75
- equalsIgnoreCase("calc", arena.strings[arena.stringValue[component]])) {
76
+ equalsIgnoreCase("calc", arena.resolveString(arena.stringValue[component]))) {
76
77
  // inlined: arena.walkValues(arena.tokens(component))
77
78
  for (const value of new ValueWalker(arena, arena.tokens(component))) {
78
- if (arena.dataTypes[value] == EnumToken.IdenTokenType) {
79
- val = arena.strings[arena.stringValue[value]].toLowerCase();
79
+ if (arena.dataTypes[value] === EnumToken.IdenTokenType) {
80
+ val = arena.resolveString(arena.stringValue[value]).toLowerCase();
80
81
  if (
81
82
  // @ts-expect-error
82
83
  typeof Math[val.toUpperCase()] !== "number" &&
83
- val != "in" &&
84
- val != "hue" &&
85
- val != "from" &&
86
- val != "alpha" &&
87
- val != "none" &&
88
- val != "shorter" &&
89
- val != "longer" &&
90
- val != "increasing" &&
91
- val != "decreasing" &&
84
+ val !== "in" &&
85
+ val !== "hue" &&
86
+ val !== "from" &&
87
+ val !== "alpha" &&
88
+ val !== "none" &&
89
+ val !== "shorter" &&
90
+ val !== "longer" &&
91
+ val !== "increasing" &&
92
+ val !== "decreasing" &&
92
93
  !colorsFunc.includes(val) &&
93
94
  !colorFuncColorSpace.includes(val) &&
94
95
  !validKeys.includes(val)) {
@@ -102,8 +103,10 @@ function parseRelativeColorComponents(arena, relativeKeys, original, rExp, gExp,
102
103
  if (converted == null) {
103
104
  return null;
104
105
  }
105
- const children = arena.tokens(converted).filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.LiteralTokenType, EnumToken.CommentTokenType].includes(arena.dataTypes[t]));
106
- [r, g, b, alpha] = arena.colorType[converted] == ColorType.COLOR ? children.slice(1) : children;
106
+ const children = arena
107
+ .tokens(converted)
108
+ .filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.LiteralTokenType, EnumToken.CommentTokenType].includes(arena.dataTypes[t]));
109
+ [r, g, b, alpha] = arena.colorType[converted] === ColorType.COLOR ? children.slice(1) : children;
107
110
  values = {
108
111
  [names[0]]: getValue(arena, r, converted, names[0]),
109
112
  [names[1]]: getValue(arena, g, converted, names[1]), // string,
@@ -111,9 +114,9 @@ function parseRelativeColorComponents(arena, relativeKeys, original, rExp, gExp,
111
114
  // @ts-ignore
112
115
  alpha: alpha == null
113
116
  ? numberToken(arena, 1, b)
114
- : arena.dataTypes[alpha] == EnumToken.IdenTokenType && arena.strings[arena.stringValue[alpha]] == "none"
117
+ : arena.dataTypes[alpha] === EnumToken.IdenTokenType && arena.resolveString(arena.stringValue[alpha]) === "none"
115
118
  ? numberToken(arena, 0, alpha)
116
- : arena.dataTypes[alpha] == EnumToken.PercentageTokenType
119
+ : arena.dataTypes[alpha] === EnumToken.PercentageTokenType
117
120
  ? numberToken(arena, getNumber(arena, alpha), alpha)
118
121
  : alpha,
119
122
  };
@@ -124,17 +127,17 @@ function parseRelativeColorComponents(arena, relativeKeys, original, rExp, gExp,
124
127
  // @ts-ignore
125
128
  alpha: getValue(arena, aExp == null
126
129
  ? numberToken(arena, 1, bExp)
127
- : arena.dataTypes[aExp] == EnumToken.IdenTokenType && arena.strings[arena.stringValue[aExp]] == "none"
130
+ : arena.dataTypes[aExp] === EnumToken.IdenTokenType && arena.resolveString(arena.stringValue[aExp]) === "none"
128
131
  ? numberToken(arena, 0, aExp)
129
132
  : aExp),
130
133
  };
131
134
  const result = computeComponentValue(arena, keys, values);
132
135
  if (result != null) {
133
- if ("hsl" == relativeKeys) {
136
+ if ("hsl" === relativeKeys) {
134
137
  toPercentage(arena, result.s);
135
138
  toPercentage(arena, result.l);
136
139
  }
137
- else if ("hwb" == relativeKeys) {
140
+ else if ("hwb" === relativeKeys) {
138
141
  toPercentage(arena, result.w);
139
142
  toPercentage(arena, result.b);
140
143
  }
@@ -149,13 +152,14 @@ function parseRelativeColorComponents(arena, relativeKeys, original, rExp, gExp,
149
152
  }
150
153
  /**
151
154
  * Get token numeric value
155
+ * @param arena
152
156
  * @param t
153
157
  * @param converted
154
158
  * @param component
155
159
  * @returns
156
160
  */
157
161
  function getValue(arena, t, converted, component) {
158
- if (arena.dataTypes[t] == EnumToken.PercentageTokenType) {
162
+ if (arena.dataTypes[t] === EnumToken.PercentageTokenType) {
159
163
  let value = getNumber(arena, t);
160
164
  if (converted != null) {
161
165
  let colorSpace = ColorType[arena.colorType[converted]].toLowerCase().replaceAll("-", "_");
@@ -170,6 +174,7 @@ function getValue(arena, t, converted, component) {
170
174
  }
171
175
  /**
172
176
  * Compute component value
177
+ * @param arena
173
178
  * @param expr
174
179
  * @param values
175
180
  * @returns
@@ -180,7 +185,7 @@ function computeComponentValue(arena, expr, values) {
180
185
  // normalize hue
181
186
  // inlined: arena.walkValues([object.h as Token])
182
187
  for (const k of new ValueWalker(arena, [object.h])) {
183
- if (arena.dataTypes[k] == EnumToken.AngleTokenType && arena.strings[arena.unit[k]] == "deg") {
188
+ if (arena.dataTypes[k] === EnumToken.AngleTokenType && arena.resolveString(arena.unit[k]) === "deg") {
184
189
  arena.dataTypes[k] = EnumToken.NumberTokenType;
185
190
  }
186
191
  }
@@ -193,15 +198,16 @@ function computeComponentValue(arena, expr, values) {
193
198
  EnumToken.AngleTokenType,
194
199
  EnumToken.LengthTokenType,
195
200
  ].includes(arena.dataTypes[exp])) ;
196
- else if (arena.dataTypes[exp] == EnumToken.IdenTokenType && arena.strings[arena.stringValue[exp]] in values) {
197
- expr[key] = values[arena.strings[arena.stringValue[exp]]];
201
+ else if (arena.dataTypes[exp] === EnumToken.IdenTokenType && arena.resolveString(arena.stringValue[exp]) in values) {
202
+ expr[key] = values[arena.resolveString(arena.stringValue[exp])];
198
203
  }
199
- else if (arena.dataTypes[exp] == EnumToken.MathFunctionTokenType ||
200
- (arena.dataTypes[exp] == EnumToken.FunctionTokenType && mathFuncs.includes(arena.strings[arena.stringValue[exp]]))) {
204
+ else if (arena.dataTypes[exp] === EnumToken.MathFunctionTokenType ||
205
+ (arena.dataTypes[exp] === EnumToken.FunctionTokenType &&
206
+ mathFuncs.includes(arena.resolveString(arena.stringValue[exp])))) {
201
207
  // inlined: arena.walkValues(arena.tokens(exp))
202
208
  for (const value of new ValueWalker(arena, arena.tokens(exp))) {
203
- if (arena.dataTypes[value] == EnumToken.IdenTokenType) {
204
- const name = arena.strings[arena.stringValue[value]];
209
+ if (arena.dataTypes[value] === EnumToken.IdenTokenType) {
210
+ const name = arena.resolveString(arena.stringValue[value]);
205
211
  const replacement = values[name];
206
212
  // replace the identifier by its value
207
213
  if (replacement != null) {
@@ -215,11 +221,12 @@ function computeComponentValue(arena, expr, values) {
215
221
  }
216
222
  }
217
223
  const result = (arena.dataTypes[exp] === EnumToken.MathFunctionTokenType ||
218
- (arena.dataTypes[exp] == EnumToken.FunctionTokenType && mathFuncs.includes(arena.strings[arena.stringValue[exp]]))) &&
219
- arena.strings[arena.stringValue[exp]] !== "calc"
224
+ (arena.dataTypes[exp] === EnumToken.FunctionTokenType &&
225
+ mathFuncs.includes(arena.resolveString(arena.stringValue[exp])))) &&
226
+ arena.resolveString(arena.stringValue[exp]) !== "calc"
220
227
  ? evaluateFunc(arena, exp)
221
228
  : evaluate(arena, arena.tokens(exp));
222
- if (result.length == 1 && arena.dataTypes[result[0]] != EnumToken.BinaryExpressionTokenType) {
229
+ if (result.length === 1 && arena.dataTypes[result[0]] !== EnumToken.BinaryExpressionTokenType) {
223
230
  expr[key] = result[0];
224
231
  }
225
232
  }
@@ -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 { color2srgbvalues, minmax } from './color.js';
@@ -71,7 +71,7 @@ function color2RgbToken(arena, token) {
71
71
  if (values == null) {
72
72
  return null;
73
73
  }
74
- return rgb2RgbToken(arena, values.map((t, index) => (index == 3 ? t : srgb2rgb(t))));
74
+ return rgb2RgbToken(arena, values.map((t, index) => (index === 3 ? t : srgb2rgb(t))));
75
75
  }
76
76
  function rgb2RgbToken(arena, values) {
77
77
  const chi = [
@@ -79,21 +79,21 @@ function rgb2RgbToken(arena, values) {
79
79
  arena.createToken(EnumToken.NumberTokenType, values[1]),
80
80
  arena.createToken(EnumToken.NumberTokenType, values[2]),
81
81
  ];
82
- if (values.length == 4) {
82
+ if (values.length === 4) {
83
83
  chi.push(arena.createToken(EnumToken.PercentageTokenType, values[3] * 100));
84
84
  }
85
85
  return arena.createColor("rgb", ColorType.RGB, chi);
86
86
  }
87
87
  function hex2rgbvalues(arena, token) {
88
- const value = expandHexValue(arena.colorType[token] == ColorType.LIT
89
- ? COLORS_NAMES[arena.strings[arena.stringValue[token]].toLowerCase()]
90
- : arena.strings[arena.stringValue[token]]);
88
+ const value = expandHexValue(arena.colorType[token] === ColorType.LIT
89
+ ? COLORS_NAMES[arena.resolveString(arena.stringValue[token]).toLowerCase()]
90
+ : arena.resolveString(arena.stringValue[token]));
91
91
  const rgb = [];
92
92
  for (let i = 1; i < value.length; i += 2) {
93
93
  rgb.push(parseInt(value.slice(i, i + 2), 16));
94
94
  }
95
- if (rgb.length == 4) {
96
- if (rgb[3] == 255) {
95
+ if (rgb.length === 4) {
96
+ if (rgb[3] === 255) {
97
97
  rgb.pop();
98
98
  }
99
99
  else {
@@ -103,7 +103,7 @@ function hex2rgbvalues(arena, token) {
103
103
  return rgb;
104
104
  }
105
105
  function hwb2rgbvalues(arena, token) {
106
- return hwb2srgbvalues(arena, token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
106
+ return hwb2srgbvalues(arena, token)?.map?.((t, index) => (index === 3 ? t : srgb2rgb(t))) ?? null;
107
107
  }
108
108
  function hsl2rgbvalues(arena, token) {
109
109
  let { h, s, l, a } = hslvalues(arena, token) ?? {};
@@ -112,29 +112,29 @@ function hsl2rgbvalues(arena, token) {
112
112
  }
113
113
  return hslvalues2srgbvalues(h, s, l)
114
114
  .map((t) => minmax(Math.round(t * 255), 0, 255))
115
- .concat(a == 1 || a == null ? [] : [a]);
115
+ .concat(a === 1 || a == null ? [] : [a]);
116
116
  }
117
117
  function hsl2srgbvalues(arena, token) {
118
118
  let { h, s, l, a } = hslvalues(arena, token) ?? {};
119
119
  if (h == null || s == null || l == null) {
120
120
  return null;
121
121
  }
122
- return hslvalues2srgbvalues(h, s, l).concat(a == 1 || a == null ? [] : [a]);
122
+ return hslvalues2srgbvalues(h, s, l).concat(a === 1 || a == null ? [] : [a]);
123
123
  }
124
124
  function cmyk2rgbvalues(arena, token) {
125
- return cmyk2srgbvalues(arena, token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
125
+ return cmyk2srgbvalues(arena, token)?.map?.((t, index) => (index === 3 ? t : srgb2rgb(t))) ?? null;
126
126
  }
127
127
  function oklab2rgbvalues(arena, token) {
128
- return oklab2srgbvalues(arena, token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
128
+ return oklab2srgbvalues(arena, token)?.map?.((t, index) => (index === 3 ? t : srgb2rgb(t))) ?? null;
129
129
  }
130
130
  function oklch2rgbvalues(arena, token) {
131
- return oklch2srgbvalues(arena, token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
131
+ return oklch2srgbvalues(arena, token)?.map?.((t, index) => (index === 3 ? t : srgb2rgb(t))) ?? null;
132
132
  }
133
133
  function lab2rgbvalues(arena, token) {
134
- return lab2srgbvalues(arena, token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
134
+ return lab2srgbvalues(arena, token)?.map?.((t, index) => (index === 3 ? t : srgb2rgb(t))) ?? null;
135
135
  }
136
136
  function lch2rgbvalues(arena, token) {
137
- return lch2srgbvalues(arena, token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
137
+ return lch2srgbvalues(arena, token)?.map?.((t, index) => (index === 3 ? t : srgb2rgb(t))) ?? null;
138
138
  }
139
139
 
140
140
  export { cmyk2RgbToken, cmyk2rgbvalues, color2RgbToken, hex2RgbToken, hex2rgbvalues, hsl2RgbToken, hsl2rgbvalues, hsl2srgbvalues, hwb2RgbToken, hwb2rgbvalues, lab2RgbToken, lab2rgbvalues, lch2RgbToken, lch2rgbvalues, oklab2RgbToken, oklab2rgbvalues, oklch2RgbToken, oklch2rgbvalues, srgb2rgb };
@@ -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 { getColorComponents } from './utils/components.js';
@@ -51,16 +51,16 @@ function srgbvalues(arena, token) {
51
51
  return null;
52
52
  }
53
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"
54
+ return (getColorComponents(arena, token)?.map?.((t, index) => index === 3
55
+ ? arena.dataTypes[t] === EnumToken.IdenTokenType && arena.resolveString(arena.stringValue[t]) === "none"
56
56
  ? 1
57
57
  : getNumber(arena, t)
58
- : ((arena.dataTypes[t] == EnumToken.PercentageTokenType ? 255 : 1) *
58
+ : ((arena.dataTypes[t] === EnumToken.PercentageTokenType ? 255 : 1) *
59
59
  getNumber(arena, t)) /
60
60
  255) ?? null);
61
61
  }
62
62
  function rgb2srgbvalues(arena, token) {
63
- return (getColorComponents(arena, token)?.map?.((t, index) => index == 3
63
+ return (getColorComponents(arena, token)?.map?.((t, index) => index === 3
64
64
  ? getNumber(arena, t)
65
65
  : getNumber(arena, t) / 255) ?? null);
66
66
  }
@@ -74,14 +74,14 @@ function rgb2srgbvalues(arena, token) {
74
74
  // return result;
75
75
  // }
76
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]]);
77
+ const value = expandHexValue(arena.colorType[token] === ColorType.LIT
78
+ ? COLORS_NAMES[arena.resolveString(arena.stringValue[token]).toLowerCase()]
79
+ : arena.resolveString(arena.stringValue[token]));
80
80
  const rgb = [];
81
81
  for (let i = 1; i < value.length; i += 2) {
82
82
  rgb.push(parseInt(value.slice(i, i + 2), 16) / 255);
83
83
  }
84
- if (rgb.length == 4) {
84
+ if (rgb.length === 4) {
85
85
  rgb[3] = +rgb[3].toFixed(2);
86
86
  }
87
87
  return rgb;
@@ -98,7 +98,7 @@ function hwb2srgbvalues(arena, token) {
98
98
  return [];
99
99
  }
100
100
  const rgb = hwb2srgb(h, w, b);
101
- if (a != null && a != 1) {
101
+ if (a != null && a !== 1) {
102
102
  rgb.push(a);
103
103
  }
104
104
  return rgb;
@@ -171,7 +171,7 @@ function cmyk2srgbvalues(arena, token) {
171
171
  const k = getNumber(arena, t);
172
172
  const mul = 1 - k;
173
173
  const rgb = [1 - Math.min(1, c * mul + k), 1 - Math.min(1, m * mul + k), 1 - Math.min(1, y * mul + k)];
174
- if (components.length == 5) {
174
+ if (components.length === 5) {
175
175
  rgb.push(getNumber(arena, components[4]));
176
176
  }
177
177
  return rgb;
@@ -182,7 +182,7 @@ function oklab2srgbvalues(arena, token) {
182
182
  return null;
183
183
  }
184
184
  const rgb = OKLab_to_sRGB(l, a, b);
185
- if (alpha != null && alpha != 1) {
185
+ if (alpha != null && alpha !== 1) {
186
186
  rgb.push(alpha);
187
187
  }
188
188
  return rgb;
@@ -194,7 +194,7 @@ function oklch2srgbvalues(arena, token) {
194
194
  }
195
195
  const values = lchvalues2labvalues(l, c, h);
196
196
  const rgb = OKLab_to_sRGB(values[0], values[1], values[2]);
197
- if (alpha != 1) {
197
+ if (alpha !== 1) {
198
198
  rgb.push(alpha);
199
199
  }
200
200
  return rgb;
@@ -215,14 +215,14 @@ function hslvalues(arena, token) {
215
215
  t = components[2];
216
216
  // @ts-ignore
217
217
  let l = getNumber(arena, t);
218
- if (arena.dataTypes[components[1]] == EnumToken.PercentageTokenType) {
218
+ if (arena.dataTypes[components[1]] === EnumToken.PercentageTokenType) {
219
219
  s *= 100;
220
220
  }
221
- if (arena.dataTypes[components[2]] == EnumToken.PercentageTokenType) {
221
+ if (arena.dataTypes[components[2]] === EnumToken.PercentageTokenType) {
222
222
  l *= 100;
223
223
  }
224
224
  let a = null;
225
- if (components.length == 4) {
225
+ if (components.length === 4) {
226
226
  // @ts-ignore
227
227
  t = components[3];
228
228
  // @ts-ignore
@@ -288,7 +288,7 @@ function lch2srgbvalues(arena, token) {
288
288
  }
289
289
  // https://www.w3.org/TR/css-color-4/#lab-to-lch
290
290
  const rgb = Lab_to_sRGB(l, a, b);
291
- if (alpha != 1) {
291
+ if (alpha !== 1) {
292
292
  rgb.push(alpha);
293
293
  }
294
294
  return rgb;
@@ -308,7 +308,7 @@ function srgb2lsrgbvalues(r, g, b, a = null) {
308
308
  }
309
309
  return (Math.sign(val) || 1) * Math.pow((abs + 0.055) / 1.055, 2.4);
310
310
  });
311
- if (a != 1 && a != null) {
311
+ if (a !== 1 && a != null) {
312
312
  rgb.push(a);
313
313
  }
314
314
  return rgb;
@@ -327,7 +327,7 @@ function lsrgb2srgbvalues(r, g, b, alpha = null) {
327
327
  }
328
328
  return 12.92 * val;
329
329
  });
330
- if (alpha != 1 && alpha != null) {
330
+ if (alpha !== 1 && alpha != null) {
331
331
  rgb.push(alpha);
332
332
  }
333
333
  return rgb;
@@ -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 { ColorType } from '../../../ast/types.js';
@@ -13,13 +13,15 @@ import { ColorType } from '../../../ast/types.js';
13
13
  * @param color
14
14
  */
15
15
  function getColorType(arena, color) {
16
- if (arena.colorType[color] === ColorType.COLOR_MIX || arena.strings[arena.unit[color]] === "rel") {
16
+ if (arena.colorType[color] === ColorType.COLOR_MIX || arena.resolveString(arena.unit[color]) === "rel") {
17
17
  const token = arena.getTokenAt(color, 2);
18
18
  if (token == null) {
19
19
  return null;
20
20
  }
21
21
  return arena.colorType[color] === ColorType.COLOR_MIX
22
- ? ColorType[arena.strings[arena.stringValue[token]]?.toUpperCase?.()?.replace?.("-", "_")]
22
+ ? ColorType[arena.resolveString(arena.stringValue[token])
23
+ ?.toUpperCase?.()
24
+ ?.replace?.("-", "_")]
23
25
  : getColorType(arena, token);
24
26
  }
25
27
  return arena.colorType[color];
@@ -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 { equalsIgnoreCase } from '../../../parser/utils/text.js';
@@ -10,38 +10,36 @@ import { getColorComponents } from './components.js';
10
10
 
11
11
  /**
12
12
  * Return the color space of the color
13
+ * @param arena
13
14
  * @param color
14
15
  * @returns
15
16
  */
16
17
  function getColorSpace(arena, color) {
17
- // if (!("chi" in color)) {
18
- // return "rgb";
19
- // }
20
18
  let name;
21
19
  const components = getColorComponents(arena, color);
22
20
  if (components == null || components.length < 3) {
23
21
  return null;
24
22
  }
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]]];
23
+ if (equalsIgnoreCase("color", arena.resolveString(arena.stringValue[color]))) {
24
+ if (equalsIgnoreCase("from", arena.resolveString(arena.stringValue[components[0]]))) {
25
+ name = arena.resolveString(arena.stringValue[components[2]]);
28
26
  }
29
27
  else {
30
- name = arena.strings[arena.stringValue[components[0]]];
28
+ name = arena.resolveString(arena.stringValue[components[0]]);
31
29
  }
32
30
  }
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]]];
31
+ else if (equalsIgnoreCase("color-mix", arena.resolveString(arena.stringValue[color]))) {
32
+ if (equalsIgnoreCase("in", arena.resolveString(arena.stringValue[components[0]]))) {
33
+ name = arena.resolveString(arena.stringValue[components[1]]);
36
34
  }
37
35
  else {
38
36
  return "oklab";
39
37
  }
40
38
  }
41
39
  else {
42
- name = arena.strings[arena.stringValue[color]];
40
+ name = arena.resolveString(arena.stringValue[color]);
43
41
  }
44
- return name == "device-cmyk"
42
+ return name === "device-cmyk"
45
43
  ? "cmyk"
46
44
  : name.startsWith("xyz")
47
45
  ? "xyz"
@@ -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 { ColorType, EnumToken } from '../../../ast/types.js';
@@ -11,12 +11,12 @@ import { expandHexValue } from '../hex.js';
11
11
  import { equalsIgnoreCase } from '../../../parser/utils/text.js';
12
12
 
13
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]];
14
+ if (arena.colorType[token] === ColorType.HEX || arena.colorType[token] === ColorType.LIT) {
15
+ const val = arena.resolveString(arena.stringValue[token]);
16
16
  if (equalsIgnoreCase("currentcolor", val)) {
17
17
  return null;
18
18
  }
19
- const value = expandHexValue(arena.colorType[token] == ColorType.LIT ? COLORS_NAMES[val.toLowerCase()] : val);
19
+ const value = expandHexValue(arena.colorType[token] === ColorType.LIT ? COLORS_NAMES[val.toLowerCase()] : val);
20
20
  // @ts-ignore
21
21
  return value
22
22
  .slice(1)
@@ -24,23 +24,23 @@ function getColorComponents(arena, token) {
24
24
  .map((t, index) => arena.createToken(EnumToken.Number, index < 3 ? parseInt(t, 16) : parseInt(t, 16) / 255));
25
25
  }
26
26
  const result = [];
27
- for (let child = arena.firstToken[token]; child != 0; child = arena.nextSibling[child]) {
27
+ for (let child = arena.firstToken[token]; child !== 0; child = arena.nextSibling[child]) {
28
28
  const typ = arena.dataTypes[child];
29
- if (typ == EnumToken.LiteralTokenType ||
30
- typ == EnumToken.CommentTokenType ||
31
- typ == EnumToken.CommaTokenType ||
32
- typ == EnumToken.WhitespaceTokenType) {
29
+ if (typ === EnumToken.LiteralTokenType ||
30
+ typ === EnumToken.CommentTokenType ||
31
+ typ === EnumToken.CommaTokenType ||
32
+ typ === EnumToken.WhitespaceTokenType) {
33
33
  continue;
34
34
  }
35
35
  if (typ === EnumToken.FunctionTokenType ||
36
36
  typ === EnumToken.WildCardFunctionTokenType ||
37
37
  typ === EnumToken.MathFunctionTokenType) {
38
- if ("var" == arena.strings[arena.stringValue[child]].toLowerCase()) {
38
+ if ("var" === arena.resolveString(arena.stringValue[child]).toLowerCase()) {
39
39
  return null;
40
40
  }
41
41
  }
42
- if (typ == EnumToken.ColorTokenType &&
43
- equalsIgnoreCase("currentcolor", arena.strings[arena.stringValue[child]])) {
42
+ if (typ === EnumToken.ColorTokenType &&
43
+ equalsIgnoreCase("currentcolor", arena.resolveString(arena.stringValue[child]))) {
44
44
  return null;
45
45
  }
46
46
  result.push(child);