@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,14 +1,14 @@
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 { PropertySet } from './set.js';
9
9
  import { getConfig } from '../utils/config.js';
10
10
  import { PropertyMap } from './map.js';
11
- import { EnumAstNodeStatus, EnumToken } from '../../ast/types.js';
11
+ import { EnumToken, EnumAstNodeStatus } from '../../ast/types.js';
12
12
  import { getParsedSyntax } from '../../validation/config.js';
13
13
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
14
14
  import { isValidDeclarationValue } from '../../validation/match.js';
@@ -74,6 +74,20 @@ class DeclarationMemo {
74
74
  return key;
75
75
  }
76
76
  }
77
+ /**
78
+ * true if the value of a declaration contains var(), env() or if()
79
+ * @param arena
80
+ * @param declaration
81
+ */
82
+ function hasWildCardFunction(arena, declaration) {
83
+ for (const token of arena.tokens(declaration)) {
84
+ if (arena.dataTypes[token] === EnumToken.WildCardFunctionTokenType ||
85
+ arena.dataTypes[token] === EnumToken.WildCardFunctionTokenDefType) {
86
+ return true;
87
+ }
88
+ }
89
+ return false;
90
+ }
77
91
  /**
78
92
  * Represents a list of property declarations, compute shorthand and remove duplicate declarations.
79
93
  */
@@ -94,28 +108,24 @@ class PropertyList {
94
108
  * keys shared by the lists that use the same arena
95
109
  */
96
110
  memo;
111
+ /**
112
+ * syntaxes of the descriptors of the at-rule that contains the declarations: `result` in `@function`. the
113
+ * declarations that are not validated are validated with them
114
+ */
115
+ descriptors;
97
116
  /**
98
117
  *
99
118
  * @param arena
100
119
  * @param options
101
120
  * @param memo keys shared by the lists that use the same arena
121
+ * @param descriptors syntaxes of the descriptors of the at-rule that contains the declarations
102
122
  */
103
- constructor(arena, options = {}, memo = null) {
123
+ constructor(arena, options = {}, memo = null, descriptors = null) {
104
124
  this.arena = arena;
105
125
  this.options = options;
106
126
  this.declarations = new Map();
107
127
  this.memo = memo ?? new DeclarationMemo();
108
- }
109
- /**
110
- * add declarations
111
- * @param declarations node ids
112
- * @returns
113
- */
114
- add(declarations) {
115
- for (const declaration of declarations) {
116
- this.addDeclaration(declaration);
117
- }
118
- return this;
128
+ this.descriptors = descriptors;
119
129
  }
120
130
  /**
121
131
  * add a declaration
@@ -126,9 +136,9 @@ class PropertyList {
126
136
  let syntaxRules = null;
127
137
  const arena = this.arena;
128
138
  name =
129
- arena.dataTypes[declaration] != EnumToken.DeclarationNodeType
139
+ arena.dataTypes[declaration] !== EnumToken.DeclarationNodeType
130
140
  ? null
131
- : arena.strings[arena.name[declaration]];
141
+ : arena.resolveString(arena.name[declaration]);
132
142
  // do not compute shorthand for invalid declarations
133
143
  if (name == null) {
134
144
  this.declarations.set(this.memo.key(arena, declaration), declaration);
@@ -159,7 +169,9 @@ class PropertyList {
159
169
  return this;
160
170
  }
161
171
  if (arena.flags[declaration] & EnumAstNodeStatus.Unvalidated) {
162
- syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, lowercase(name));
172
+ syntaxRules =
173
+ this.descriptors?.[lowercase(name)] ??
174
+ getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, lowercase(name));
163
175
  if (syntaxRules != null) {
164
176
  arena.flags[declaration] |=
165
177
  (isValidDeclarationValue(arena, syntaxRules, declaration, this.options)
@@ -198,20 +210,28 @@ class PropertyList {
198
210
  // @ts-ignore
199
211
  shorthand = config.property[propertyName];
200
212
  }
213
+ // the value of a shorthand that contains var(), env() or if() cannot be expanded: the longhands that follow
214
+ // it are not merged into it. `background: var(--bg); background-clip: text`
215
+ if (shorthand === name &&
216
+ (shortHandType === "map" || shortHandType === "set") &&
217
+ hasWildCardFunction(arena, declaration)) {
218
+ this.declarations.set(this.memo.key(arena, declaration), declaration);
219
+ return this;
220
+ }
201
221
  if (this.declarations.has(shorthand)) {
202
222
  let existing = this.declarations.get(shorthand);
203
223
  if (existing instanceof PropertySet || existing instanceof PropertyMap) {
204
224
  existing = existing.declarations.get(name);
205
225
  }
206
226
  if (existing != null &&
207
- typeof existing == "number" &&
227
+ typeof existing === "number" &&
208
228
  arena.flags[existing] & EnumAstNodeStatus.ImportantDeclaration &&
209
- arena.flags[declaration] & ~EnumAstNodeStatus.ImportantDeclaration) {
229
+ (arena.flags[declaration] & EnumAstNodeStatus.ImportantDeclaration) == 0) {
210
230
  return this;
211
231
  }
212
232
  }
213
233
  // @ts-ignore
214
- if (shortHandType == "map") {
234
+ if (shortHandType === "map") {
215
235
  let owner = this;
216
236
  const mapName =
217
237
  // @ts-ignore
@@ -225,8 +245,9 @@ class PropertyList {
225
245
  owner = this.declarations.get(mapName);
226
246
  }
227
247
  else if (!this.declarations.has(shorthand)) {
248
+ this.declarations.set(shorthand,
228
249
  // @ts-ignore
229
- this.declarations.set(shorthand, new PropertyMap(arena, config.map[shorthand], this.memo));
250
+ new PropertyMap(arena, config.map[shorthand], this.memo));
230
251
  }
231
252
  if (owner == this) {
232
253
  // @ts-ignore
@@ -243,7 +264,7 @@ class PropertyList {
243
264
  }
244
265
  }
245
266
  // @ts-ignore
246
- else if (shortHandType == "set") {
267
+ else if (shortHandType === "set") {
247
268
  // @ts-ignore
248
269
  if (!this.declarations.has(shorthand)) {
249
270
  // @ts-ignore
@@ -260,6 +281,14 @@ class PropertyList {
260
281
  if (shorthand != null) {
261
282
  this.mapValues(declaration, shorthand);
262
283
  }
284
+ const existing = this.declarations.get(propertyName);
285
+ // a previous declaration with the same name takes precedence when it is !important and the new one is not
286
+ if (existing != null &&
287
+ typeof existing === "number" &&
288
+ arena.flags[existing] & EnumAstNodeStatus.ImportantDeclaration &&
289
+ (arena.flags[declaration] & EnumAstNodeStatus.ImportantDeclaration) == 0) {
290
+ return this;
291
+ }
263
292
  this.declarations.set(propertyName, declaration);
264
293
  }
265
294
  return this;
@@ -293,7 +322,7 @@ class PropertyList {
293
322
  default: {
294
323
  for (const v of set) {
295
324
  if (arena.dataTypes[v] === EnumToken.IdenTokenType) {
296
- const value = arena.strings[arena.stringValue[v]].toLowerCase();
325
+ const value = arena.resolveString(arena.stringValue[v]).toLowerCase();
297
326
  if (value === pattern || new RegExp(`(^|\|)${pattern}(\||$)`).test(value)) {
298
327
  val.push(v);
299
328
  set.delete(v);
@@ -317,14 +346,14 @@ class PropertyList {
317
346
  }
318
347
  for (const val of declarationValues) {
319
348
  if (arena.dataTypes[val] === EnumToken.IdenTokenType) {
320
- name = arena.strings[arena.stringValue[val]].toLowerCase();
349
+ name = arena.resolveString(arena.stringValue[val]).toLowerCase();
321
350
  if (mapping.mapping[name] != null) {
322
351
  const typ = EnumToken[mapping.mapping[name].typ];
323
352
  arena.resetToken(val, typ, mapping.mapping[name].val);
324
353
  }
325
354
  }
326
355
  }
327
- if (values != declarationValues) {
356
+ if (values !== declarationValues) {
328
357
  arena.setTokenList(declaration, values);
329
358
  }
330
359
  }
@@ -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 { eqToken } from '../utils/eq.js';
@@ -40,8 +40,8 @@ function configToken(arena, config) {
40
40
  */
41
41
  function matchConfigToken(arena, token, config) {
42
42
  return (config != null &&
43
- arena.dataTypes[token] == configType(config) &&
44
- (config.val == null || arena.strings[arena.stringValue[token]] == config.val));
43
+ arena.dataTypes[token] === configType(config) &&
44
+ (config.val == null || arena.resolveString(arena.stringValue[token]) === config.val));
45
45
  }
46
46
  /**
47
47
  * map of declarations that can be merged into a single shorthand declaration.
@@ -78,16 +78,13 @@ class PropertyMap {
78
78
  this.pattern = config.pattern.split(/\s/);
79
79
  }
80
80
  /**
81
- * tokens of a value (default values of the properties, ...)
82
- * @param value
81
+ *
82
+ * @param declaration
83
83
  */
84
- parse(value) {
85
- return this.memo == null ? parseString(this.arena, value) : this.memo.parse(this.arena, value);
86
- }
87
84
  add(declaration) {
88
85
  const arena = this.arena;
89
- const nam = arena.strings[arena.name[declaration]];
90
- if (nam == this.config.shorthand) {
86
+ const nam = arena.resolveString(arena.name[declaration]);
87
+ if (nam === this.config.shorthand) {
91
88
  this.declarations.clear();
92
89
  this.declarations.set(nam, declaration);
93
90
  this.matchTypes(declaration);
@@ -111,13 +108,13 @@ class PropertyMap {
111
108
  // let current: number = 0;
112
109
  const props = this.config.properties[property];
113
110
  for (let i = 0; i < acc.length; i++) {
114
- if (arena.dataTypes[acc[i]] == EnumToken.CommentTokenType ||
115
- arena.dataTypes[acc[i]] == EnumToken.WhitespaceTokenType) {
111
+ if (arena.dataTypes[acc[i]] === EnumToken.CommentTokenType ||
112
+ arena.dataTypes[acc[i]] === EnumToken.WhitespaceTokenType) {
116
113
  acc.splice(i, 1);
117
114
  i--;
118
115
  continue;
119
116
  }
120
- if (this.propertyNames.get(acc[i]) == property || matchType(arena, acc[i], props)) {
117
+ if (this.propertyNames.get(acc[i]) === property || matchType(arena, acc[i], props)) {
121
118
  if ("prefix" in props && props.previous != null && !(props.previous in tokens)) {
122
119
  return acc;
123
120
  }
@@ -125,7 +122,7 @@ class PropertyMap {
125
122
  tokens[property] = [[acc[i]]];
126
123
  }
127
124
  else {
128
- if (current == tokens[property].length) {
125
+ if (current === tokens[property].length) {
129
126
  tokens[property].push([acc[i]]);
130
127
  }
131
128
  else {
@@ -157,12 +154,14 @@ class PropertyMap {
157
154
  // default
158
155
  if (props.default.length > 0) {
159
156
  // inlined: this.parse(props.default[0])
160
- const defaults = this.memo == null ? parseString(this.arena, props.default[0]) : this.memo.parse(this.arena, props.default[0]);
157
+ const defaults = this.memo == null
158
+ ? parseString(this.arena, props.default[0])
159
+ : this.memo.parse(this.arena, props.default[0]);
161
160
  if (!(property in tokens)) {
162
161
  tokens[property] = [[...defaults]];
163
162
  }
164
163
  else {
165
- if (current == tokens[property].length) {
164
+ if (current === tokens[property].length) {
166
165
  tokens[property].push([]);
167
166
  for (let i = 0; i < defaults.length; i++) {
168
167
  tokens[property][current].push(defaults[i]);
@@ -179,7 +178,7 @@ class PropertyMap {
179
178
  return acc;
180
179
  }, val[current]));
181
180
  }
182
- if (values.length == 0) {
181
+ if (values.length === 0) {
183
182
  this.declarations = Object.entries(tokens).reduce((acc, curr) => {
184
183
  acc.set(curr[0], arena.createDeclaration(EnumToken.DeclarationNodeType, curr[0], curr[1].reduce((acc, curr) => {
185
184
  if (acc.length > 0) {
@@ -240,23 +239,25 @@ class PropertyMap {
240
239
  for (const value of declarations.values()) {
241
240
  if (value instanceof PropertyMap) {
242
241
  for (const [k, v] of value.declarations) {
243
- if (k == value.config.shorthand) {
242
+ if (k === value.config.shorthand) {
244
243
  const values = arena.tokens(v);
245
244
  for (const [key] of Object.entries(value.config.properties)) {
246
245
  mapped[key] = arena.clone(v);
247
246
  const mappedValues = [];
248
247
  for (let i = 0; i < values.length; i++) {
249
- if (key == value.propertyNames.get(values[i])) {
248
+ if (key === value.propertyNames.get(values[i])) {
250
249
  if (mappedValues.length > 0) {
251
250
  mappedValues.push(arena.createToken(EnumToken.WhitespaceTokenType));
252
251
  }
253
252
  mappedValues.push(value.take(values[i]));
254
253
  }
255
254
  }
256
- if (mappedValues.length == 0) {
255
+ if (mappedValues.length === 0) {
257
256
  mappedValues.push(
258
257
  // inlined: this.parse((value as PropertyMap).config.properties[key].default[0])
259
- ...(this.memo == null ? parseString(this.arena, value.config.properties[key].default[0]) : this.memo.parse(this.arena, value.config.properties[key].default[0])));
258
+ ...(this.memo == null
259
+ ? parseString(this.arena, value.config.properties[key].default[0])
260
+ : this.memo.parse(this.arena, value.config.properties[key].default[0])));
260
261
  }
261
262
  arena.setTokenList(mapped[key], mappedValues);
262
263
  }
@@ -269,7 +270,7 @@ class PropertyMap {
269
270
  else {
270
271
  // a property set has no name
271
272
  key =
272
- value instanceof PropertySet ? "undefined" : arena.strings[arena.name[value]];
273
+ value instanceof PropertySet ? "undefined" : arena.resolveString(arena.name[value]);
273
274
  mapped[key] = value;
274
275
  }
275
276
  }
@@ -324,7 +325,7 @@ class PropertyMap {
324
325
  if (!cache.has(t)) {
325
326
  cache.set(t, renderValue(arena, t, { minify: true }));
326
327
  }
327
- if (arena.dataTypes[t] == typ && separator == cache.get(t)) {
328
+ if (arena.dataTypes[t] === typ && separator === cache.get(t)) {
328
329
  this.removeDefaults(map, value);
329
330
  value = [];
330
331
  values.push(value);
@@ -350,19 +351,20 @@ class PropertyMap {
350
351
  acc.push(configToken(arena, sep));
351
352
  }
352
353
  for (const cr of curr) {
353
- if (arena.dataTypes[cr] == EnumToken.WhitespaceTokenType &&
354
+ if (arena.dataTypes[cr] === EnumToken.WhitespaceTokenType &&
354
355
  acc.length > 0 &&
355
- arena.dataTypes[acc[acc.length - 1]] == EnumToken.WhitespaceTokenType) {
356
+ arena.dataTypes[acc[acc.length - 1]] === EnumToken.WhitespaceTokenType) {
356
357
  continue;
357
358
  }
358
359
  acc.push(cr);
359
360
  }
360
361
  return acc;
361
362
  }, []);
362
- while (result.length > 0 && arena.dataTypes[result[result.length - 1]] == EnumToken.WhitespaceTokenType) {
363
+ while (result.length > 0 &&
364
+ arena.dataTypes[result[result.length - 1]] === EnumToken.WhitespaceTokenType) {
363
365
  result.pop();
364
366
  }
365
- while (result.length > 0 && arena.dataTypes[result[0]] == EnumToken.WhitespaceTokenType) {
367
+ while (result.length > 0 && arena.dataTypes[result[0]] === EnumToken.WhitespaceTokenType) {
366
368
  result.shift();
367
369
  }
368
370
  arena.setTokenList(declaration, result);
@@ -385,20 +387,22 @@ class PropertyMap {
385
387
  for (const declaration of values) {
386
388
  dec = removeDefaults(declaration);
387
389
  for (const t of arena.tokens(dec)) {
388
- if (arena.dataTypes[t] == EnumToken.ImportantTokenType) {
390
+ if (arena.dataTypes[t] === EnumToken.ImportantTokenType) {
389
391
  isImportant = true;
390
392
  }
391
- if (filtered.length == 0 &&
392
- arena.dataTypes[t] != EnumToken.WhitespaceTokenType &&
393
- arena.dataTypes[t] != EnumToken.ImportantTokenType) {
393
+ if (filtered.length === 0 &&
394
+ arena.dataTypes[t] !== EnumToken.WhitespaceTokenType &&
395
+ arena.dataTypes[t] !== EnumToken.ImportantTokenType) {
394
396
  filtered.push(dec);
395
397
  }
396
398
  }
397
399
  }
398
- if (filtered.length == 0 && this.config.default.length > 0) {
400
+ if (filtered.length === 0 && this.config.default.length > 0) {
399
401
  filtered.push(arena.createDeclaration(EnumToken.DeclarationNodeType, this.config.shorthand,
400
402
  // inlined: this.parse(this.config.default[0])
401
- this.memo == null ? parseString(this.arena, this.config.default[0]) : this.memo.parse(this.arena, this.config.default[0]), null, null));
403
+ this.memo == null
404
+ ? parseString(this.arena, this.config.default[0])
405
+ : this.memo.parse(this.arena, this.config.default[0]), null, null));
402
406
  if (isImportant) {
403
407
  arena.appendToken(filtered[0], arena.createToken(EnumToken.ImportantTokenType));
404
408
  }
@@ -409,8 +413,8 @@ class PropertyMap {
409
413
  if (declaration instanceof PropertySet || declaration instanceof PropertyMap) {
410
414
  continue;
411
415
  }
412
- const nam = arena.strings[arena.name[declaration]];
413
- const config = nam == this.config.shorthand ? this.config : (propertiesMapping[nam] ?? this.config);
416
+ const nam = arena.resolveString(arena.name[declaration]);
417
+ const config = nam === this.config.shorthand ? this.config : (propertiesMapping[nam] ?? this.config);
414
418
  if (!("mapping" in config)) {
415
419
  continue;
416
420
  }
@@ -419,12 +423,14 @@ class PropertyMap {
419
423
  for (const [key, val] of Object.entries(config.mapping)) {
420
424
  // inlined: this.parse(key)
421
425
  const keys = this.memo == null ? parseString(this.arena, key) : this.memo.parse(this.arena, key);
422
- if (keys.length != declarationValues.length) {
426
+ if (keys.length !== declarationValues.length) {
423
427
  continue;
424
428
  }
425
429
  if (keys.every((k, index) => eqToken(arena, k, declarationValues[index]))) {
426
430
  // inlined: this.parse(val as string)
427
- arena.setTokenList(declaration, this.memo == null ? parseString(this.arena, val) : this.memo.parse(this.arena, val));
431
+ arena.setTokenList(declaration, this.memo == null
432
+ ? parseString(this.arena, val)
433
+ : this.memo.parse(this.arena, val));
428
434
  break;
429
435
  }
430
436
  }
@@ -455,27 +461,27 @@ class PropertyMap {
455
461
  for (const val of arena.tokens(declaration)) {
456
462
  if (matchConfigToken(arena, val, separator)) {
457
463
  current++;
458
- if (tokens[curr[0]].length == current) {
464
+ if (tokens[curr[0]].length === current) {
459
465
  tokens[curr[0]].push([]);
460
466
  }
461
467
  continue;
462
468
  }
463
469
  const valType = arena.dataTypes[val];
464
- if (valType == EnumToken.WhitespaceTokenType || valType == EnumToken.CommentTokenType) {
470
+ if (valType === EnumToken.WhitespaceTokenType || valType === EnumToken.CommentTokenType) {
465
471
  continue;
466
472
  }
467
473
  if (props.multiple &&
468
474
  props.separator != null &&
469
475
  configType(props.separator) === valType &&
470
476
  (valType === EnumToken.CommaTokenType ||
471
- props.separator.val == arena.strings[arena.stringValue[val]])) {
477
+ props.separator.val === arena.resolveString(arena.stringValue[val]))) {
472
478
  continue;
473
479
  }
474
480
  match = matchType(arena, val, curr[1]);
475
481
  if (isShorthand) {
476
482
  isShorthand = match;
477
483
  }
478
- if (this.propertyNames.get(val) == property || match) {
484
+ if (this.propertyNames.get(val) === property || match) {
479
485
  if (!(curr[0] in tokens)) {
480
486
  tokens[curr[0]] = [[]];
481
487
  }
@@ -494,7 +500,7 @@ class PropertyMap {
494
500
  return acc;
495
501
  }, []);
496
502
  // grid-template
497
- if (this.config.shorthand == "grid-template" && patterns.length == Object.keys(tokens).length) {
503
+ if (this.config.shorthand === "grid-template" && patterns.length === Object.keys(tokens).length) {
498
504
  const k = tokens[patterns[0]][0].length;
499
505
  const l = tokens[patterns[1]][0].length;
500
506
  const j = k < l ? k : l;
@@ -537,12 +543,12 @@ class PropertyMap {
537
543
  !Object.values(tokens).every((v) =>
538
544
  // `v` holds token groups: only single token groups were type checked by the former
539
545
  // `arena.dataTypes[group]` lookup (the group is converted to a string key)
540
- v.filter((t) => t.length != 1 || arena.dataTypes[t[0]] != EnumToken.CommentTokenType).length === count)) {
546
+ v.filter((t) => t.length !== 1 || arena.dataTypes[t[0]] !== EnumToken.CommentTokenType).length === count)) {
541
547
  // @ts-ignore
542
548
  iterable = declarations.values();
543
549
  }
544
550
  else if (hasMapping) {
545
- if (patterns.length == Object.keys(tokens).length) {
551
+ if (patterns.length === Object.keys(tokens).length) {
546
552
  const declaration = arena.clone(declarations.get(patterns[0]));
547
553
  const declarationValues = arena.tokens(declaration);
548
554
  arena.name[declaration] = arena.internString(this.config.shorthand);
@@ -574,7 +580,7 @@ class PropertyMap {
574
580
  .reduce((acc, curr) => {
575
581
  const props = propertiesMapping[curr[0]];
576
582
  for (let i = 0; i < curr[1].length; i++) {
577
- if (acc.length == i) {
583
+ if (acc.length === i) {
578
584
  acc.push([]);
579
585
  }
580
586
  // if (acc[acc.length - 1].length > 0) {
@@ -614,8 +620,8 @@ class PropertyMap {
614
620
  EnumToken.CommentTokenType,
615
621
  EnumToken.IdenTokenType,
616
622
  ].includes(arena.dataTypes[v]) ||
617
- (arena.dataTypes[v] == EnumToken.IdenTokenType &&
618
- !propertiesMapping[curr[0]].default.includes(arena.strings[arena.stringValue[v]]))) {
623
+ (arena.dataTypes[v] === EnumToken.IdenTokenType &&
624
+ !propertiesMapping[curr[0]].default.includes(arena.resolveString(arena.stringValue[v])))) {
619
625
  doFilterDefault = false;
620
626
  break;
621
627
  }
@@ -623,13 +629,13 @@ class PropertyMap {
623
629
  }
624
630
  // remove default values
625
631
  const filtered = values.filter((val) => {
626
- if (arena.dataTypes[val] == EnumToken.WhitespaceTokenType ||
627
- arena.dataTypes[val] == EnumToken.CommentTokenType) {
632
+ if (arena.dataTypes[val] === EnumToken.WhitespaceTokenType ||
633
+ arena.dataTypes[val] === EnumToken.CommentTokenType) {
628
634
  return false;
629
635
  }
630
636
  return (!doFilterDefault ||
631
- !(arena.dataTypes[val] == EnumToken.IdenTokenType &&
632
- props.default.includes(arena.strings[arena.stringValue[val]])));
637
+ !(arena.dataTypes[val] === EnumToken.IdenTokenType &&
638
+ props.default.includes(arena.resolveString(arena.stringValue[val]))));
633
639
  });
634
640
  if (filtered.length > 0 ||
635
641
  !(this.requiredCount == requiredCount && propertiesMapping[curr[0]].required)) {
@@ -643,15 +649,17 @@ class PropertyMap {
643
649
  values.length <= props.constraints.mapping.max) {
644
650
  let i = values.length;
645
651
  while (i--) {
646
- if (arena.dataTypes[values[i]] == EnumToken.IdenTokenType &&
652
+ if (arena.dataTypes[values[i]] === EnumToken.IdenTokenType &&
647
653
  // @ts-expect-error
648
- arena.strings[arena.stringValue[values[i]]] in props.mapping) {
649
- // inlined: this.parse(props.mapping[arena.strings[arena.stringValue[values[i]]]])
654
+ arena.resolveString(arena.stringValue[values[i]]) in props.mapping) {
655
+ // inlined: this.parse(props.mapping[arena.resolveString(arena.stringValue[values[i]])])
650
656
  values.splice(i, 1, ...(this.memo == null
651
- ? // @ts-ignore
652
- parseString(this.arena, props.mapping[arena.strings[arena.stringValue[values[i]]]])
653
- : // @ts-ignore
654
- this.memo.parse(this.arena, props.mapping[arena.strings[arena.stringValue[values[i]]]])));
657
+ ? parseString(this.arena,
658
+ // @ts-ignore
659
+ props.mapping[arena.resolveString(arena.stringValue[values[i]])])
660
+ : this.memo.parse(this.arena,
661
+ // @ts-ignore
662
+ props.mapping[arena.resolveString(arena.stringValue[values[i]])])));
655
663
  }
656
664
  }
657
665
  }
@@ -679,10 +687,12 @@ class PropertyMap {
679
687
  if (acc.length > 0) {
680
688
  acc.push(configToken(arena, separator));
681
689
  }
682
- if (curr.length == 0 && this.config.default.length > 0) {
690
+ if (curr.length === 0 && this.config.default.length > 0) {
683
691
  curr.push(
684
692
  // inlined: this.parse(this.config.default[0])
685
- ...(this.memo == null ? parseString(this.arena, this.config.default[0]) : this.memo.parse(this.arena, this.config.default[0])).reduce((acc, curr) => {
693
+ ...(this.memo == null
694
+ ? parseString(this.arena, this.config.default[0])
695
+ : this.memo.parse(this.arena, this.config.default[0])).reduce((acc, curr) => {
686
696
  if (acc.length > 0) {
687
697
  acc.push(arena.createToken(EnumToken.WhitespaceTokenType));
688
698
  }
@@ -710,12 +720,15 @@ class PropertyMap {
710
720
  this.config.mapping[val]));
711
721
  }
712
722
  }
713
- if (values.length == 1 &&
714
- arena.stringValue[values[0]] != 0 &&
715
- this.config.default.includes(arena.strings[arena.stringValue[values[0]]].toLowerCase()) &&
716
- this.config.default[0] != arena.strings[arena.stringValue[values[0]]].toLowerCase()) {
723
+ if (values.length === 1 &&
724
+ arena.stringValue[values[0]] !== 0 &&
725
+ this.config.default.includes(arena.resolveString(arena.stringValue[values[0]]).toLowerCase()) &&
726
+ this.config.default[0] !== arena.resolveString(arena.stringValue[values[0]]).toLowerCase()) {
717
727
  // inlined: this.parse(this.config.default[0])
718
- values = this.memo == null ? parseString(this.arena, this.config.default[0]) : this.memo.parse(this.arena, this.config.default[0]);
728
+ values =
729
+ this.memo == null
730
+ ? parseString(this.arena, this.config.default[0])
731
+ : this.memo.parse(this.arena, this.config.default[0]);
719
732
  }
720
733
  iterable = [
721
734
  arena.createDeclaration(EnumToken.DeclarationNodeType, this.config.shorthand, values, null, null),
@@ -742,7 +755,7 @@ class PropertyMap {
742
755
  iterable = iterators.pop();
743
756
  v = iterable.next();
744
757
  }
745
- if (v.done && iterators.length == 0) {
758
+ if (v.done && iterators.length === 0) {
746
759
  break;
747
760
  }
748
761
  }
@@ -756,7 +769,7 @@ class PropertyMap {
756
769
  * @param token
757
770
  */
758
771
  take(token) {
759
- if (this.arena.parents[token] == 0) {
772
+ if (this.arena.parents[token] === 0) {
760
773
  return token;
761
774
  }
762
775
  const clone = this.arena.clone(token, true);
@@ -797,10 +810,10 @@ class PropertyMap {
797
810
  if (map.has(key)) {
798
811
  for (const v of val) {
799
812
  // missing
800
- if (map.get(v) == 1) {
813
+ if (map.get(v) === 1) {
801
814
  let i = declarationValues.length;
802
815
  while (i--) {
803
- if (this.propertyNames.get(declarationValues[i]) == key) {
816
+ if (this.propertyNames.get(declarationValues[i]) === key) {
804
817
  const val = arena.clone(declarationValues[i], true);
805
818
  this.propertyNames.set(val, v);
806
819
  declarationValues.splice(i, 0, val, arena.createToken(EnumToken.WhitespaceTokenType));
@@ -823,14 +836,14 @@ class PropertyMap {
823
836
  continue;
824
837
  }
825
838
  const v = val.value.join(" ");
826
- if (config.default.includes(v) || (value.length == 1 && this.config.default.includes(v))) {
839
+ if (config.default.includes(v) || (value.length === 1 && this.config.default.includes(v))) {
827
840
  for (const token of value) {
828
841
  if (val.t.includes(token)) {
829
842
  let index = value.indexOf(token);
830
843
  value.splice(index, 1);
831
844
  if (config.prefix != null) {
832
845
  while (index-- > 0) {
833
- if (this.arena.dataTypes[value[index]] == EnumToken.WhitespaceTokenType) {
846
+ if (this.arena.dataTypes[value[index]] === EnumToken.WhitespaceTokenType) {
834
847
  continue;
835
848
  }
836
849
  if (matchConfigToken(this.arena, value[index], config.prefix)) {