@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,15 +1,15 @@
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 { getAngle, convertColor } from '../syntax/color/color.js';
9
9
  import { reduceHexValue } from '../syntax/color/hex.js';
10
10
  import { EnumToken, ColorType, EnumAstNodeStatus } from '../ast/types.js';
11
11
  import { SourceMap } from './sourcemap/sourcemap.js';
12
- import { pseudoElements, anglePrecision, urlTokenMatcher, tokensfuncSet } from '../syntax/constants.js';
12
+ import { pseudoElements, anglePrecision, urlTokenMatcher, isFunctionType } from '../syntax/constants.js';
13
13
  import { minifyNumber, toPrecisionAngle, toPrecisionValue, reducegradientBackgroundPosition, reduceConicColorStops, reduceColorStops, parseColor, isWhiteSpace } from '../syntax/syntax.js';
14
14
  import { equalsIgnoreCase } from '../parser/utils/text.js';
15
15
  import { toDegrees } from '../parser/utils/angle.js';
@@ -18,6 +18,8 @@ import { dirname } from '../fs/resolve.js';
18
18
  import { SourceFile } from '../parser/source.js';
19
19
  import { TokenField } from '../ast/arena.js';
20
20
  import { StructuralMemo } from '../ast/cache.js';
21
+ import { Writer, DEFAULT_CAPACITY } from './writer.js';
22
+ import { RenderResult } from './result.js';
21
23
 
22
24
  /**
23
25
  * Rendered strings shared by the renderer.
@@ -42,6 +44,13 @@ class RenderMemo {
42
44
  * collection when no instance is alive, and the optimized code that depends on it discarded (deoptimized)
43
45
  */
44
46
  static shape = new RenderMemo();
47
+ /**
48
+ * cleared memos, reused by the next renders: their buffers are not allocated again. read by the library
49
+ * (see {@link acquire})
50
+ *
51
+ * @internal
52
+ */
53
+ static free = [];
45
54
  /**
46
55
  * rendered declarations (`name:value`), by name and value tokens
47
56
  */
@@ -51,12 +60,16 @@ class RenderMemo {
51
60
  */
52
61
  constructs = new StructuralMemo();
53
62
  /**
54
- * cleared memos, reused by the next renders: their buffers are not allocated again. read by the library
55
- * (see {@link acquire})
56
- *
57
- * @internal
63
+ * location of the declarations in the render buffer, by declaration slot: writer id, start offset, end offset and
64
+ * number of bytes minus the number of UTF-16 code units (4 values per slot). an identical declaration written to the
65
+ * same buffer is copied from there (see {@link Writer.copy})
58
66
  */
59
- static free = [];
67
+ locations = new Int32Array(1024);
68
+ /**
69
+ * rendered values of the declarations (without the name), by declaration slot: a declaration written to another
70
+ * buffer is not rendered again
71
+ */
72
+ values = [];
60
73
  /**
61
74
  * a cleared memo
62
75
  */
@@ -72,9 +85,35 @@ class RenderMemo {
72
85
  if (RenderMemo.free.length < 4 && memo.declarations.footprint + memo.constructs.footprint <= 1 << 20) {
73
86
  memo.declarations.clear();
74
87
  memo.constructs.clear();
88
+ memo.values.length = 0;
89
+ // the writer ids are never reused: the locations are not cleared
75
90
  RenderMemo.free.push(memo);
76
91
  }
77
92
  }
93
+ /**
94
+ * record the location of a declaration in a render buffer
95
+ * @param slot declaration slot
96
+ * @param writer render buffer
97
+ * @param start start offset
98
+ * @param extra value of {@link Writer.extra} at the start offset
99
+ */
100
+ locate(slot, writer, start, extra) {
101
+ let index = slot << 2;
102
+ if (index + 4 > this.locations.length) {
103
+ let size = this.locations.length * 2;
104
+ while (size < index + 4) {
105
+ size *= 2;
106
+ }
107
+ const locations = new Int32Array(size);
108
+ locations.set(this.locations);
109
+ this.locations = locations;
110
+ }
111
+ const locations = this.locations;
112
+ locations[index++] = writer.id;
113
+ locations[index++] = start;
114
+ locations[index++] = writer.length;
115
+ locations[index] = writer.extra - extra;
116
+ }
78
117
  }
79
118
  /**
80
119
  * Render state shared by the nodes and the tokens of a render
@@ -184,7 +223,8 @@ function resolveRenderOptions(options) {
184
223
  }
185
224
  /**
186
225
  * Render nodes with the same options: the options are resolved once and identical values are rendered once.
187
- * Same output as {@link doRender}, used by the minifier to compare the size of the nodes
226
+ * Same output as {@link doRender}, used by the minifier to compare the size of the nodes. The output is not kept: only
227
+ * its size is returned
188
228
  *
189
229
  * @internal
190
230
  */
@@ -230,6 +270,10 @@ class NodeRenderer {
230
270
  * the nodes are rendered without doRender(): no nesting expansion, no parents, no source map
231
271
  */
232
272
  direct;
273
+ /**
274
+ * output buffer, reused by the renders: only the size of the output is read
275
+ */
276
+ writer = new Writer();
233
277
  /**
234
278
  * @param options render options
235
279
  */
@@ -244,11 +288,11 @@ class NodeRenderer {
244
288
  this.resolved.output == null;
245
289
  }
246
290
  /**
247
- * render a node
291
+ * rendered size of a node: the length of the rendered css (UTF-16 code units)
248
292
  * @param arena
249
293
  * @param node
250
294
  */
251
- render(arena, node) {
295
+ size(arena, node) {
252
296
  if (this.arena !== arena) {
253
297
  if (this.arena != null) {
254
298
  this.cache = new RenderCache(new RenderMemo(), this.resolved);
@@ -257,10 +301,39 @@ class NodeRenderer {
257
301
  this.reducer = createReducer(arena, this.resolved, this.cache);
258
302
  }
259
303
  if (!this.direct) {
260
- return doRender(arena, node, this.options, null, this.cache.memo).code;
304
+ return RenderResult.codeLength(doRender(arena, node, this.options, null, this.cache.memo));
261
305
  }
262
- return renderAstNode(arena, node, this.resolved, null, this.location, null, this.errors, this.reducer, this.cache, 0, this.indents);
306
+ // the output is not kept: the buffer is reused
307
+ const writer = this.writer;
308
+ writer.reset();
309
+ renderAstNode(arena, node, this.resolved, null, this.location, null, this.errors, this.reducer, this.cache, writer, 0, this.indents);
310
+ return writer.codeLength;
311
+ }
312
+ }
313
+ /**
314
+ * extra capacity of the render buffer: the output may be larger than the input (beautified minified css, css modules
315
+ * exports, inline source map, ...)
316
+ */
317
+ const OUTPUT_PADDING = 1 << 12;
318
+ /**
319
+ * capacity of the buffer a node is rendered to. the minified or beautified output is usually not larger than the
320
+ * input: the length of the input the node was parsed from, padded
321
+ * - stylesheet: the length of the css parsed into the stylesheet, imported files included
322
+ * - other nodes: the length of their location in the source
323
+ * @param arena
324
+ * @param node
325
+ *
326
+ * @internal
327
+ */
328
+ function outputCapacity(arena, node) {
329
+ let length = 0;
330
+ if (arena.dataTypes[node] === EnumToken.StyleSheetNodeType) {
331
+ length = arena.inputLengths[node] ?? 0;
263
332
  }
333
+ else if (arena.flags[node] & EnumAstNodeStatus.HasLocation) {
334
+ length = arena.getSpanEnd(node) - arena.getSpanStart(node);
335
+ }
336
+ return length > 0 ? length + OUTPUT_PADDING : DEFAULT_CAPACITY;
264
337
  }
265
338
  /**
266
339
  * render ast
@@ -273,9 +346,11 @@ class NodeRenderer {
273
346
  */
274
347
  function doRender(arena, data, options = {}, mapping, memo) {
275
348
  options = resolveRenderOptions(options);
349
+ // estimated from the node to render: the nodes rendered below may be copies
350
+ const capacity = outputCapacity(arena, data);
276
351
  const expandNesting = options.expandNestingRules &&
277
352
  [EnumToken.StyleSheetNodeType, EnumToken.AtRuleNodeType, EnumToken.RuleNodeType].includes(arena.dataTypes[data]) &&
278
- (arena.flags[data] & EnumAstNodeStatus.HasChildren) != 0;
353
+ (arena.flags[data] & EnumAstNodeStatus.HasChildren) !== 0;
279
354
  // temporary stylesheet holding the rendered copy
280
355
  let sheet = 0;
281
356
  if (options.withParents || expandNesting) {
@@ -286,7 +361,7 @@ function doRender(arena, data, options = {}, mapping, memo) {
286
361
  data = arena.clone(data, true);
287
362
  if (options.withParents) {
288
363
  // wrap the node into shallow copies of its ancestors
289
- while (parent != 0) {
364
+ while (parent !== 0) {
290
365
  const clone = arena.clone(parent, false);
291
366
  arena.appendChild(clone, data);
292
367
  data = clone;
@@ -308,13 +383,15 @@ function doRender(arena, data, options = {}, mapping, memo) {
308
383
  // reused by the next renders
309
384
  const ownMemo = memo == null;
310
385
  // inlined: RenderMemo.acquire()
311
- const cache = new RenderCache(memo ?? (RenderMemo.free.pop() ?? new RenderMemo()), options);
386
+ const cache = new RenderCache(memo ?? RenderMemo.free.pop() ?? new RenderMemo(), options);
312
387
  const sourceLocation = {
313
388
  end: 0,
314
389
  };
315
390
  const linesMap = options.sourcemap ? new LineMap() : null;
316
- let code = "";
391
+ // the generated css is written to the buffer. its size is estimated from the input: it should not grow
392
+ const writer = new Writer(capacity);
317
393
  if (mapping != null) {
394
+ let code = "";
318
395
  if (mapping.importMapping != null) {
319
396
  const absolutePath = options.resolve(options.output != null ? dirname(options.output) : dirname(options.src), options.cwd).absolute;
320
397
  for (let [key, value] of Object.entries(mapping.importMapping)) {
@@ -326,6 +403,7 @@ function doRender(arena, data, options = {}, mapping, memo) {
326
403
  }
327
404
  }
328
405
  code += `:export${options.indent}{${options.newLine}${Object.entries(mapping.mapping).reduce((acc, [k, v]) => acc + (acc.length > 0 ? options.newLine : "") + `${options.indent}${k}:${options.indent}${v};`, "")}${options.newLine}}${options.newLine}`;
406
+ writer.write(code);
329
407
  if (sourcemap != null) {
330
408
  move(sourceLocation, linesMap, code);
331
409
  }
@@ -334,18 +412,14 @@ function doRender(arena, data, options = {}, mapping, memo) {
334
412
  // @ts-ignore
335
413
  options.output = options.resolve(options.output, options.cwd).absolute;
336
414
  }
337
- const result = {
338
- code: code +
339
- renderAstNode(arena, data, options, sourcemaps, sourceLocation, linesMap, errors, createReducer(arena, options, cache), cache),
340
- errors,
341
- stats: {
342
- total: `${(performance.now() - startTime).toFixed(2)}ms`,
343
- },
415
+ renderAstNode(arena, data, options, sourcemaps, sourceLocation, linesMap, errors, createReducer(arena, options, cache), cache, writer);
416
+ const stats = {
417
+ total: `${(performance.now() - startTime).toFixed(2)}ms`,
344
418
  };
345
419
  if (ownMemo) {
346
420
  RenderMemo.release(cache.memo);
347
421
  }
348
- if (sheet != 0) {
422
+ if (sheet !== 0) {
349
423
  // drop the temporary stylesheet. the tokens allocated while rendering (color conversion, gradients, ...)
350
424
  // are not attached to the tree either: the memory is not reclaimed, the ids are never reused
351
425
  arena.detach(data);
@@ -358,12 +432,11 @@ function doRender(arena, data, options = {}, mapping, memo) {
358
432
  sourcemap.addSourceContent(source.id, source.file, source.content);
359
433
  }
360
434
  sourcemap.add(sourcemaps.maps);
361
- result.map = sourcemap;
362
435
  if (options.sourcemap === "inline") {
363
- result.code += `\n/*# sourceMappingURL=${result.map.toUrl()} */`;
436
+ writer.write(`\n/*# sourceMappingURL=${sourcemap.toUrl()} */`);
364
437
  }
365
438
  }
366
- return result;
439
+ return new RenderResult(writer.bytes(), errors, stats, sourcemap ?? undefined, writer.codeLength);
367
440
  }
368
441
  /**
369
442
  * Update source map
@@ -380,7 +453,7 @@ function doRender(arena, data, options = {}, mapping, memo) {
380
453
  */
381
454
  function updateSourceMap(arena, node, options, cache, sourcemaps, sourceLocation, linesMap, str) {
382
455
  let offset = 0;
383
- // eat leanding whitespace
456
+ // eat leading whitespace
384
457
  while (offset < str.length && isWhiteSpace(str.charCodeAt(offset))) {
385
458
  offset++;
386
459
  }
@@ -397,7 +470,7 @@ function updateSourceMap(arena, node, options, cache, sourcemaps, sourceLocation
397
470
  // generated position, see LineMap.getOffsets()
398
471
  const line = linesMap.search(sourceLocation.end);
399
472
  const newLine = line + 1;
400
- const newColumn = sourceLocation.end - linesMap.lineStarts[line] + (line == 0 ? 1 : 0);
473
+ const newColumn = sourceLocation.end - linesMap.lineStarts[line] + (line === 0 ? 1 : 0);
401
474
  let records = null;
402
475
  // inlined: source.getFileName()
403
476
  let sourceFileName = source.file || null;
@@ -421,7 +494,8 @@ function updateSourceMap(arena, node, options, cache, sourcemaps, sourceLocation
421
494
  // resolution is relative to the source file
422
495
  const absoluteSourceFileName = options.resolve(sourceFileName, absoluteSourcePath)
423
496
  .absolute;
424
- cache.paths[sourceFileName] = options.resolve(absoluteSourceFileName, absolute).relative;
497
+ cache.paths[sourceFileName] = options.resolve(absoluteSourceFileName, absolute)
498
+ .relative;
425
499
  }
426
500
  sourceFileName = cache.paths[sourceFileName];
427
501
  }
@@ -479,15 +553,15 @@ function move(sourceLocation, linesMap, str, start, end) {
479
553
  for (; i < j; i++) {
480
554
  codepoint = str.charCodeAt(i);
481
555
  sourceLocation.end++;
482
- if (codepoint == 0xa || // \n
483
- codepoint == 0xb || // \v
484
- codepoint == 0xc || // \f
485
- codepoint == 0xd || // \r
486
- codepoint == 0x2028 || // \u2028
487
- codepoint == 0x2029 // \u2029
556
+ if (codepoint === 0xa || // \n
557
+ codepoint === 0xb || // \v
558
+ codepoint === 0xc || // \f
559
+ codepoint === 0xd || // \r
560
+ codepoint === 0x2028 || // \u2028
561
+ codepoint === 0x2029 // \u2029
488
562
  ) {
489
- if (codepoint == 0xd && i + 1 < str.length && str.charCodeAt(i + 1) == 0xa) ;
490
- else if (codepoint == 0xa && i > 0 && str.charCodeAt(i - 1) == 0xd) ;
563
+ if (codepoint === 0xd && i + 1 < str.length && str.charCodeAt(i + 1) === 0xa) ;
564
+ else if (codepoint === 0xa && i > 0 && str.charCodeAt(i - 1) === 0xd) ;
491
565
  else {
492
566
  // inlined: linesMap.addLineStart(sourceLocation.end)
493
567
  linesMap.lineStarts.push(sourceLocation.end);
@@ -496,7 +570,28 @@ function move(sourceLocation, linesMap, str, start, end) {
496
570
  }
497
571
  }
498
572
  /**
499
- * render ast node
573
+ * write an interned string: an ascii string is copied from the string table, the string is not created
574
+ * @param arena
575
+ * @param id
576
+ * @param writer
577
+ */
578
+ function writeString(arena, id, writer) {
579
+ const length = arena.stringLength(id);
580
+ if (length === 0) {
581
+ return;
582
+ }
583
+ writer.reserve(length);
584
+ const written = arena.copyStringAscii(id, writer.buffer, writer.length);
585
+ if (written >= 0) {
586
+ writer.length += written;
587
+ }
588
+ else {
589
+ writer.write(arena.resolveString(id));
590
+ }
591
+ }
592
+ /**
593
+ * render ast node: the rendered css is written to the writer. nothing is written when the node is rendered as an empty
594
+ * string (removed comments, empty rules, ...)
500
595
  * @param arena
501
596
  * @param data node id
502
597
  * @param options
@@ -506,120 +601,213 @@ function move(sourceLocation, linesMap, str, start, end) {
506
601
  * @param errors
507
602
  * @param reducer
508
603
  * @param cache
604
+ * @param writer output
509
605
  * @param level
510
606
  * @param indents
511
607
  *
512
608
  * @internal
513
609
  */
514
- function renderAstNode(arena, data, options, sourcemaps, sourceLocation, linesMap, errors, reducer, cache, level = 0, indents = []) {
610
+ function renderAstNode(arena, data, options, sourcemaps, sourceLocation, linesMap, errors, reducer, cache, writer, level = 0, indents = []) {
515
611
  if (indents.length < level + 1) {
516
612
  indents.push(options.indent.repeat(level));
517
613
  }
518
614
  if (indents.length < level + 2) {
519
615
  indents.push(options.indent.repeat(level + 1));
520
616
  }
521
- // @ts-ignore
522
- let children = "";
523
- let str = "";
524
617
  const indent = indents[level];
525
- const indentSub = indents[level + 1];
526
618
  const typ = arena.dataTypes[data];
527
619
  switch (typ) {
528
620
  case EnumToken.DeclarationNodeType:
529
- return `${arena.strings[arena.name[data]]}:${options.indent}${renderDeclarationValue(arena, data, options.minifyValues, reducer)}`;
621
+ writeString(arena, arena.name[data], writer);
622
+ writer.writeByte(0x3a);
623
+ writer.write(options.indent);
624
+ writer.write(renderDeclarationValue(arena, data, options.minifyValues, reducer));
625
+ return;
530
626
  case EnumToken.CommentNodeType:
531
627
  case EnumToken.CDOCOMMNodeType: {
532
- const val = arena.strings[arena.stringValue[data]];
533
- if (val.startsWith("/*# sourceMappingURL=")) {
628
+ const id = arena.stringValue[data];
629
+ if (arena.stringStartsWith(id, "/*# sourceMappingURL=")) {
534
630
  // ignore sourcemap comment
535
- return "";
631
+ return;
536
632
  }
537
- return !options.removeComments || (options.preserveLicense && val.startsWith("/*!")) ? val : "";
633
+ // the removed comments are not created
634
+ if (!options.removeComments || (options.preserveLicense && arena.stringStartsWith(id, "/*!"))) {
635
+ writeString(arena, id, writer);
636
+ }
637
+ return;
538
638
  }
539
- case EnumToken.StyleSheetNodeType:
540
- for (let node = arena.firstChild[data]; node != 0; node = arena.nextSibling[node]) {
541
- str = renderAstNode(arena, node, options, sourcemaps, sourceLocation, linesMap, errors, reducer, cache, level, indents);
542
- if (str === "") {
543
- continue;
639
+ case EnumToken.StyleSheetNodeType: {
640
+ const newLine = options.newLine;
641
+ let empty = true;
642
+ let mark;
643
+ let markExtra;
644
+ let start;
645
+ for (let node = arena.firstChild[data]; node !== 0; node = arena.nextSibling[node]) {
646
+ mark = writer.length;
647
+ markExtra = writer.extra;
648
+ // the separator is dropped when the node is empty
649
+ if (!empty && newLine !== "") {
650
+ writer.write(newLine);
544
651
  }
545
- if (children.length > 0) {
546
- str = options.newLine + str;
652
+ start = writer.length;
653
+ renderAstNode(arena, node, options, sourcemaps, sourceLocation, linesMap, errors, reducer, cache, writer, level, indents);
654
+ if (writer.length === start) {
655
+ writer.truncate(mark, markExtra);
656
+ continue;
547
657
  }
548
- children += str;
549
- if (sourcemaps != null && str !== "" && options.newLine) {
550
- move(sourceLocation, linesMap, options.newLine);
658
+ empty = false;
659
+ if (sourcemaps != null && newLine) {
660
+ move(sourceLocation, linesMap, newLine);
551
661
  }
552
662
  }
553
- return children;
663
+ return;
664
+ }
554
665
  case EnumToken.AtRuleNodeType:
555
666
  case EnumToken.RuleNodeType:
556
667
  case EnumToken.KeyframesRuleNodeType:
557
668
  case EnumToken.KeyframesAtRuleNodeType: {
558
- const isAtRule = typ == EnumToken.AtRuleNodeType || typ == EnumToken.KeyframesAtRuleNodeType;
559
- const nam = arena.strings[arena.name[data]];
560
- const val = arena.strings[arena.stringValue[data]];
561
- if (isAtRule && !(arena.flags[data] & EnumAstNodeStatus.HasChildren)) {
562
- return `${(indent.length > 0 ? options.newLine : "") + indent}@${nam}${val === "" ? "" : options.indent || " "}${val};`;
669
+ const isAtRule = typ === EnumToken.AtRuleNodeType || typ === EnumToken.KeyframesAtRuleNodeType;
670
+ // the name and the value are copied from the string table: the strings are not created
671
+ const nameId = arena.name[data];
672
+ const valueId = arena.stringValue[data];
673
+ const newLine = options.newLine;
674
+ // start of the node: the node is removed when it has no children
675
+ const start = writer.length;
676
+ const startExtra = writer.extra;
677
+ if (indent.length > 0 && newLine !== "") {
678
+ writer.write(newLine);
679
+ }
680
+ if (indent.length > 0) {
681
+ writer.write(indent);
563
682
  }
683
+ if (isAtRule) {
684
+ writer.writeByte(0x40);
685
+ writeString(arena, nameId, writer);
686
+ if (arena.stringLength(valueId) > 0) {
687
+ writer.write(options.indent || " ");
688
+ writeString(arena, valueId, writer);
689
+ }
690
+ if (!(arena.flags[data] & EnumAstNodeStatus.HasChildren)) {
691
+ // @rule prelude;
692
+ writer.writeByte(0x3b);
693
+ return;
694
+ }
695
+ }
696
+ else {
697
+ writeString(arena, nameId, writer);
698
+ }
699
+ if (options.indent !== "") {
700
+ writer.write(options.indent);
701
+ }
702
+ writer.writeByte(0x7b);
564
703
  // inlined: linesMap.getLineStarts()
565
704
  const lineMapLength = linesMap ? linesMap.lineStarts.length : 0;
566
- const prelude = (indent.length > 0 ? options.newLine : "") +
567
- indent +
568
- (isAtRule
569
- ? `@${nam}${val === "" ? "" : options.indent || " "}${val}${options.indent}{`
570
- : nam + `${options.indent}{`);
705
+ // the prelude is only needed by the source map
706
+ let prelude = "";
571
707
  if (sourcemaps != null) {
708
+ const nam = arena.resolveString(nameId);
709
+ const val = arena.resolveString(valueId);
710
+ prelude =
711
+ (indent.length > 0 ? newLine : "") +
712
+ indent +
713
+ (isAtRule
714
+ ? `@${nam}${val === "" ? "" : options.indent || " "}${val}${options.indent}{`
715
+ : nam + `${options.indent}{`);
572
716
  updateSourceMap(arena, data, options, cache, sourcemaps, sourceLocation, linesMap, prelude);
573
717
  }
718
+ const indentSub = indents[level + 1];
719
+ // the children are written after the prelude
720
+ const body = writer.length;
721
+ let str;
574
722
  let node;
575
723
  let nodeType;
576
- let recordDeclarationSourceMap = typ == EnumToken.AtRuleNodeType;
577
- // rendering of the last child, without its trailing semicolon, appended to the children when the next child
578
- // is rendered. the trailing semicolon of the last child is dropped: it is known from the type of the child,
579
- // the rendered strings are not read (reading a concatenated string flattens it)
580
- let last = "";
724
+ let mark;
725
+ let childStart;
726
+ let recordDeclarationSourceMap = typ === EnumToken.AtRuleNodeType;
727
+ // the last child ends with a semicolon that is not written yet: it is written before the next child.
728
+ // the semicolon that ends the last child is dropped
581
729
  let semicolon = false;
582
- for (node = arena.firstChild[data]; node != 0; node = arena.nextSibling[node]) {
730
+ for (node = arena.firstChild[data]; node !== 0; node = arena.nextSibling[node]) {
583
731
  nodeType = arena.dataTypes[node];
584
- if (nodeType == EnumToken.CommentNodeType) {
585
- const comment = arena.strings[arena.stringValue[node]];
586
- str =
587
- options.removeComments && (!options.preserveLicense || !comment.startsWith("/*!"))
588
- ? ""
589
- : comment;
732
+ if (nodeType === EnumToken.DeclarationNodeType && sourcemaps == null) {
733
+ // fast path: the declaration is written to the buffer
734
+ if (semicolon) {
735
+ writer.writeByte(0x3b);
736
+ }
737
+ if (newLine !== "") {
738
+ writer.write(newLine);
739
+ }
740
+ if (indentSub !== "") {
741
+ writer.write(indentSub);
742
+ }
743
+ writeDeclaration(arena, node, options, cache, reducer, writer);
744
+ semicolon = true;
745
+ continue;
746
+ }
747
+ if (nodeType === EnumToken.CommentNodeType) {
748
+ const commentId = arena.stringValue[node];
749
+ // the removed comments are not created
750
+ if (options.removeComments &&
751
+ (!options.preserveLicense || !arena.stringStartsWith(commentId, "/*!"))) {
752
+ continue;
753
+ }
754
+ str = arena.resolveString(commentId);
590
755
  }
591
- else if (nodeType == EnumToken.DeclarationNodeType) {
756
+ else if (nodeType === EnumToken.DeclarationNodeType) {
592
757
  // the semicolon is not part of the rendered declaration
593
758
  str = renderDeclaration(arena, node, options, cache, reducer);
594
759
  }
595
760
  else {
596
- str = renderAstNode(arena, node, options, sourcemaps, sourceLocation, linesMap, errors, reducer, cache, level + 1, indents);
597
- if (str === "") {
761
+ mark = writer.length;
762
+ if (semicolon) {
763
+ writer.writeByte(0x3b);
764
+ }
765
+ childStart = writer.length;
766
+ renderAstNode(arena, node, options, sourcemaps, sourceLocation, linesMap, errors, reducer, cache, writer, level + 1, indents);
767
+ if (writer.length === childStart) {
768
+ // empty node: the pending semicolon is not written
769
+ writer.length = mark;
598
770
  continue;
599
771
  }
600
- children += semicolon ? last + ";" : last;
601
772
  // at-rules without a block ('@layer name;') end with a semicolon
602
- semicolon = endsWithSemicolon(arena, node, str);
603
- last = semicolon ? str.slice(0, -1) : str;
604
- str = "";
773
+ semicolon = endsWithSemicolon(arena, node, writer);
774
+ if (semicolon) {
775
+ writer.length--;
776
+ }
605
777
  continue;
606
778
  }
607
779
  if (str === "") {
608
780
  continue;
609
781
  }
610
- str = options.newLine + indentSub + str;
611
- children += semicolon ? last + ";" : last;
612
- if (nodeType == EnumToken.DeclarationNodeType) {
613
- last = str;
782
+ if (semicolon) {
783
+ writer.writeByte(0x3b);
784
+ }
785
+ if (sourcemaps == null) {
786
+ // comments
787
+ if (newLine !== "") {
788
+ writer.write(newLine);
789
+ }
790
+ if (indentSub !== "") {
791
+ writer.write(indentSub);
792
+ }
793
+ writer.write(str);
794
+ }
795
+ else {
796
+ str = newLine + indentSub + str;
797
+ writer.write(str);
798
+ }
799
+ if (nodeType === EnumToken.DeclarationNodeType) {
614
800
  semicolon = true;
615
801
  }
616
802
  else {
617
- // comments are flat strings
618
- semicolon = str.charCodeAt(str.length - 1) == 0x3b;
619
- last = semicolon ? str.slice(0, -1) : str;
803
+ // comments
804
+ semicolon = writer.lastByte() === 0x3b;
805
+ if (semicolon) {
806
+ writer.length--;
807
+ }
620
808
  }
621
809
  if (sourcemaps != null) {
622
- if (nodeType == EnumToken.DeclarationNodeType && recordDeclarationSourceMap) {
810
+ if (nodeType === EnumToken.DeclarationNodeType && recordDeclarationSourceMap) {
623
811
  // if declaration is child of at-rule, then record it
624
812
  // .rule {
625
813
  // @media screen {
@@ -631,7 +819,7 @@ function renderAstNode(arena, data, options, sourcemaps, sourceLocation, linesMa
631
819
  else {
632
820
  move(sourceLocation, linesMap, str);
633
821
  }
634
- if (nodeType == EnumToken.DeclarationNodeType) {
822
+ if (nodeType === EnumToken.DeclarationNodeType) {
635
823
  // the semicolon
636
824
  sourceLocation.end++;
637
825
  }
@@ -641,32 +829,45 @@ function renderAstNode(arena, data, options, sourcemaps, sourceLocation, linesMa
641
829
  if (semicolon) {
642
830
  sourceLocation.end--;
643
831
  }
644
- children += last;
645
- if (options.removeEmpty && children === "") {
832
+ // an empty contents block is kept: `@apply --mixin {}` does not use the default contents of the mixin.
833
+ // an empty mixin or custom function is a definition
834
+ if (options.removeEmpty &&
835
+ writer.length === body &&
836
+ !(typ === EnumToken.AtRuleNodeType &&
837
+ (arena.stringEquals(nameId, "apply") ||
838
+ arena.stringEquals(nameId, "mixin") ||
839
+ arena.stringEquals(nameId, "function")))) {
646
840
  if (sourcemaps != null) {
647
841
  sourceLocation.end -= prelude.length;
648
842
  // inlined: linesMap!.getLineStarts()
649
843
  linesMap.lineStarts.length = lineMapLength;
650
844
  }
651
- return "";
845
+ writer.truncate(start, startExtra);
846
+ return;
652
847
  }
653
- const end = options.newLine + indent + `}`;
848
+ if (newLine !== "") {
849
+ writer.write(newLine);
850
+ }
851
+ if (indent !== "") {
852
+ writer.write(indent);
853
+ }
854
+ writer.writeByte(0x7d);
654
855
  if (sourcemaps != null) {
655
- move(sourceLocation, linesMap, end);
856
+ move(sourceLocation, linesMap, newLine + indent + "}");
656
857
  }
657
- return prelude + children + end;
858
+ return;
658
859
  }
659
860
  default:
660
- return "";
861
+ return;
661
862
  }
662
863
  }
663
864
  /**
664
865
  * true if a rendered child node ends with a semicolon
665
866
  * @param arena
666
867
  * @param node child node
667
- * @param rendered rendered child node, not empty
868
+ * @param writer output, the child node is the last node written, it is not empty
668
869
  */
669
- function endsWithSemicolon(arena, node, rendered) {
870
+ function endsWithSemicolon(arena, node, writer) {
670
871
  switch (arena.dataTypes[node]) {
671
872
  case EnumToken.AtRuleNodeType:
672
873
  case EnumToken.KeyframesAtRuleNodeType:
@@ -678,7 +879,7 @@ function endsWithSemicolon(arena, node, rendered) {
678
879
  return false;
679
880
  default:
680
881
  // comments: flat strings
681
- return rendered.charCodeAt(rendered.length - 1) == 0x3b;
882
+ return writer.lastByte() === 0x3b;
682
883
  }
683
884
  }
684
885
  function renderTokenList(tokens, reducer) {
@@ -688,6 +889,34 @@ function renderTokenList(tokens, reducer) {
688
889
  }
689
890
  return result;
690
891
  }
892
+ /**
893
+ * render a declaration without memoization: `name:value`, without the semicolon
894
+ * @param arena
895
+ * @param node declaration
896
+ * @param options
897
+ * @param cache
898
+ * @param reducer
899
+ */
900
+ function renderDeclarationString(arena, node, options, cache, reducer) {
901
+ if (options.minifyValues && isUnminifiedDeclaration(arena, node)) {
902
+ // override options to avoid minifying values for custom properties
903
+ options = { ...options, minifyValues: false };
904
+ // override the reducer
905
+ reducer = createReducer(arena, options, cache);
906
+ }
907
+ return `${arena.resolveString(arena.name[node])}:${options.indent}${renderDeclarationValue(arena, node, options.minifyValues, reducer).trimEnd()}`;
908
+ }
909
+ /**
910
+ * true if the value of the declaration is not minified:
911
+ * - the custom properties
912
+ * - the `initial-value` descriptor of `@property`: the value is parsed with the syntax of the registered custom
913
+ * property, a zero dimension keeps its unit: `0deg` is a valid `<angle>`, `0` is not
914
+ * @param arena
915
+ * @param node declaration
916
+ */
917
+ function isUnminifiedDeclaration(arena, node) {
918
+ return arena.startsWith(node, "nam", "--") || arena.stringEquals(arena.name[node], "initial-value");
919
+ }
691
920
  /**
692
921
  * render a declaration of a block: `name:value`, without the semicolon. identical declarations (same name, same value
693
922
  * tokens) are rendered once per render
@@ -700,19 +929,69 @@ function renderTokenList(tokens, reducer) {
700
929
  function renderDeclaration(arena, node, options, cache, reducer) {
701
930
  const memo = getRenderMemo(cache, options);
702
931
  if (memo == null) {
703
- return `${arena.strings[arena.name[node]]}:${options.indent}${renderDeclarationValue(arena, node, options.minifyValues, reducer).trimEnd()}`;
932
+ return renderDeclarationString(arena, node, options, cache, reducer);
704
933
  }
705
934
  // the name is part of the key
706
935
  const slot = memo.declarations.list(arena, arena.firstToken[node], arena.name[node]);
707
936
  // inlined: memo.declarations.get(slot)
708
937
  let rendered = memo.declarations.values[slot];
709
938
  if (rendered === undefined) {
710
- rendered = `${arena.strings[arena.name[node]]}:${options.indent}${renderDeclarationValue(arena, node, options.minifyValues, reducer).trimEnd()}`;
939
+ rendered = renderDeclarationString(arena, node, options, cache, reducer);
711
940
  // inlined: memo.declarations.set(slot, rendered)
712
941
  memo.declarations.values[slot] = rendered;
713
942
  }
714
943
  return rendered;
715
944
  }
945
+ /**
946
+ * write a declaration of a block: `name:value`, without the semicolon. identical declarations (same name, same value
947
+ * tokens) are rendered and encoded once per render: the bytes written first are copied
948
+ * @param arena
949
+ * @param node declaration
950
+ * @param options
951
+ * @param cache
952
+ * @param reducer
953
+ * @param writer
954
+ */
955
+ function writeDeclaration(arena, node, options, cache, reducer, writer) {
956
+ const memo = getRenderMemo(cache, options);
957
+ let slot = -1;
958
+ if (memo !== null) {
959
+ // the name is part of the key
960
+ slot = memo.declarations.list(arena, arena.firstToken[node], arena.name[node]);
961
+ const index = slot << 2;
962
+ // an identical declaration is already written to the buffer: its bytes are copied
963
+ if (index < memo.locations.length && memo.locations[index] === writer.id) {
964
+ writer.copy(memo.locations[index + 1], memo.locations[index + 2], memo.locations[index + 3]);
965
+ return;
966
+ }
967
+ }
968
+ const start = writer.length;
969
+ const extra = writer.extra;
970
+ // the rendered value of an identical declaration, rendered to another buffer (see NodeRenderer)
971
+ let value = memo === null ? undefined : memo.values[slot];
972
+ if (value === undefined) {
973
+ if (options.minifyValues && isUnminifiedDeclaration(arena, node)) {
974
+ // override options to avoid minifying values for custom properties
975
+ options = { ...options, minifyValues: false };
976
+ // override the reducer
977
+ reducer = createReducer(arena, options, cache);
978
+ }
979
+ value = renderDeclarationValue(arena, node, options.minifyValues, reducer).trimEnd();
980
+ if (memo !== null) {
981
+ memo.values[slot] = value;
982
+ }
983
+ }
984
+ // the parts are written directly: `name`, `:`, `indent`, `value`. the name is copied from the string table
985
+ writeString(arena, arena.name[node], writer);
986
+ writer.writeByte(0x3a);
987
+ if (options.indent !== "") {
988
+ writer.write(options.indent);
989
+ }
990
+ writer.write(value);
991
+ if (memo !== null) {
992
+ memo.locate(slot, writer, start, extra);
993
+ }
994
+ }
716
995
  /**
717
996
  * render the value tokens of a declaration with the reducer. with minifyValues, the whitespace that is not needed is
718
997
  * skipped like {@link filterValues} does, without copying the tokens into an array: the whitespace before
@@ -726,7 +1005,7 @@ function renderDeclarationValue(arena, node, minifyValues, reducer) {
726
1005
  let rendered = "";
727
1006
  let token = arena.firstToken[node];
728
1007
  if (!minifyValues) {
729
- for (; token != 0; token = arena.nextSibling[token]) {
1008
+ for (; token !== 0; token = arena.nextSibling[token]) {
730
1009
  rendered = reducer(rendered, token);
731
1010
  }
732
1011
  return rendered;
@@ -736,37 +1015,37 @@ function renderDeclarationValue(arena, node, minifyValues, reducer) {
736
1015
  let pending = 0;
737
1016
  let check = true;
738
1017
  let dropWhitespace = false;
739
- for (; token != 0; token = arena.nextSibling[token]) {
1018
+ for (; token !== 0; token = arena.nextSibling[token]) {
740
1019
  const type = dataTypes[token];
741
1020
  if (dropWhitespace) {
742
1021
  dropWhitespace = false;
743
- if (type == EnumToken.WhitespaceTokenType) {
1022
+ if (type === EnumToken.WhitespaceTokenType) {
744
1023
  continue;
745
1024
  }
746
1025
  }
747
1026
  if (!check) {
748
1027
  check = true;
749
1028
  }
750
- else if (type == EnumToken.ImportantTokenType &&
751
- pending != 0 &&
1029
+ else if (type === EnumToken.ImportantTokenType &&
1030
+ pending !== 0 &&
752
1031
  dataTypes[pending] === EnumToken.WhitespaceTokenType) {
753
1032
  pending = 0;
754
1033
  check = false;
755
1034
  }
756
- else if (tokensfuncSet.has(type) &&
1035
+ else if (isFunctionType(type) &&
757
1036
  // color keywords and hex colors are not functions
758
- (type != EnumToken.ColorTokenType || arena.firstToken[token] != 0) &&
759
- type != EnumToken.WildCardFunctionTokenType &&
760
- arena.nextSibling[token] != 0 &&
761
- dataTypes[arena.nextSibling[token]] == EnumToken.WhitespaceTokenType) {
1037
+ (type !== EnumToken.ColorTokenType || arena.firstToken[token] !== 0) &&
1038
+ type !== EnumToken.WildCardFunctionTokenType &&
1039
+ arena.nextSibling[token] !== 0 &&
1040
+ dataTypes[arena.nextSibling[token]] === EnumToken.WhitespaceTokenType) {
762
1041
  dropWhitespace = true;
763
1042
  }
764
- if (pending != 0) {
1043
+ if (pending !== 0) {
765
1044
  rendered = reducer(rendered, pending);
766
1045
  }
767
1046
  pending = token;
768
1047
  }
769
- return pending == 0 ? rendered : reducer(rendered, pending);
1048
+ return pending === 0 ? rendered : reducer(rendered, pending);
770
1049
  }
771
1050
  /**
772
1051
  * shared default arguments of {@link renderValue}: no object is created per call. the cache is only written when
@@ -783,11 +1062,11 @@ const defaultCache = Object.create(null);
783
1062
  */
784
1063
  function createReducer(arena, options, cache, errors) {
785
1064
  const reducer = (acc, curr) => {
786
- if (arena.dataTypes[curr] == EnumToken.CommentTokenType && options.removeComments) {
787
- if (!options.preserveLicense || !arena.strings[arena.stringValue[curr]].startsWith("/*!")) {
1065
+ if (arena.dataTypes[curr] === EnumToken.CommentTokenType && options.removeComments) {
1066
+ if (!options.preserveLicense || !arena.resolveString(arena.stringValue[curr]).startsWith("/*!")) {
788
1067
  return acc;
789
1068
  }
790
- return acc + arena.strings[arena.stringValue[curr]];
1069
+ return acc + arena.resolveString(arena.stringValue[curr]);
791
1070
  }
792
1071
  return acc + renderValue(arena, curr, options, cache, reducer);
793
1072
  };
@@ -805,13 +1084,13 @@ function createReducer(arena, options, cache, errors) {
805
1084
  */
806
1085
  function renderReduced(arena, first, options, cache, reducer, errors) {
807
1086
  let result = "";
808
- for (let token = first; token != 0; token = arena.nextSibling[token]) {
1087
+ for (let token = first; token !== 0; token = arena.nextSibling[token]) {
809
1088
  if (reducer != null) {
810
1089
  result = reducer(result, token);
811
1090
  }
812
- else if (arena.dataTypes[token] == EnumToken.CommentTokenType && options.removeComments) {
813
- if (options.preserveLicense && arena.strings[arena.stringValue[token]].startsWith("/*!")) {
814
- result += arena.strings[arena.stringValue[token]];
1091
+ else if (arena.dataTypes[token] === EnumToken.CommentTokenType && options.removeComments) {
1092
+ if (options.preserveLicense && arena.resolveString(arena.stringValue[token]).startsWith("/*!")) {
1093
+ result += arena.resolveString(arena.stringValue[token]);
815
1094
  }
816
1095
  }
817
1096
  else {
@@ -831,7 +1110,7 @@ function renderReduced(arena, first, options, cache, reducer, errors) {
831
1110
  */
832
1111
  function renderList(arena, first, options, cache, reducer, errors) {
833
1112
  let result = "";
834
- for (let token = first; token != 0; token = arena.nextSibling[token]) {
1113
+ for (let token = first; token !== 0; token = arena.nextSibling[token]) {
835
1114
  result += renderValue(arena, token, options, cache, reducer);
836
1115
  }
837
1116
  return result;
@@ -869,54 +1148,56 @@ function renderColor(arena, token, options, cache, reducer, errors) {
869
1148
  if (value != null) {
870
1149
  token = value;
871
1150
  }
872
- if (arena.colorType[token] == ColorType.HEX || arena.colorType[token] == ColorType.LIT) {
873
- return reduceHexValue(arena.strings[arena.stringValue[token]]);
1151
+ if (arena.colorType[token] === ColorType.HEX || arena.colorType[token] === ColorType.LIT) {
1152
+ return reduceHexValue(arena.resolveString(arena.stringValue[token]));
874
1153
  }
875
1154
  }
876
1155
  if (arena.colorType[token] === ColorType.SYS ||
877
1156
  arena.colorType[token] === ColorType.DPSYS ||
878
1157
  arena.colorType[token] === ColorType.NON_STD) {
879
- return arena.strings[arena.stringValue[token]];
1158
+ return arena.resolveString(arena.stringValue[token]);
880
1159
  }
881
- if (arena.colorType[token] == ColorType.HEX || arena.colorType[token] == ColorType.LIT) {
882
- return arena.strings[arena.stringValue[token]];
1160
+ if (arena.colorType[token] === ColorType.HEX || arena.colorType[token] === ColorType.LIT) {
1161
+ return arena.resolveString(arena.stringValue[token]);
883
1162
  }
884
- if (arena.firstToken[token] == 0) {
1163
+ if (arena.firstToken[token] === 0) {
885
1164
  // rendered like a function (no argument)
886
- return ((arena.strings[arena.stringValue[token]] ?? "") +
1165
+ return ((arena.resolveString(arena.stringValue[token]) ?? "") +
887
1166
  "(" +
888
1167
  renderReduced(arena, arena.firstToken[token], options, cache, reducer) +
889
1168
  ")");
890
1169
  }
891
- const fnName = arena.strings[arena.stringValue[token]];
1170
+ const fnName = arena.resolveString(arena.stringValue[token]);
892
1171
  const count = arena.tokenCount(token);
893
1172
  const isLegacy = legacyColorFunctions.has(fnName);
894
1173
  const hasAlpha = alphaColorFunctions.has(fnName);
895
- const useAlpha = (hasAlpha && count == (isLegacy ? 7 : 4)) || ("color" == fnName && count == 5);
1174
+ const useAlpha = (hasAlpha && count === (isLegacy ? 7 : 4)) || ("color" === fnName && count === 5);
896
1175
  let result = "";
897
1176
  let index = 0;
898
- for (let curr = arena.firstToken[token]; curr != 0; curr = arena.nextSibling[curr], index++) {
1177
+ for (let curr = arena.firstToken[token]; curr !== 0; curr = arena.nextSibling[curr], index++) {
899
1178
  if (trailingSeparator.test(result)) {
900
- if (arena.dataTypes[curr] == EnumToken.WhitespaceTokenType) {
1179
+ if (arena.dataTypes[curr] === EnumToken.WhitespaceTokenType) {
901
1180
  result = result.trimEnd();
902
1181
  continue;
903
1182
  }
904
1183
  result = result.trimStart() + renderValue(arena, curr, options, cache);
905
1184
  continue;
906
1185
  }
907
- if (isLegacy && arena.dataTypes[curr] == EnumToken.CommaTokenType) {
1186
+ if (isLegacy && arena.dataTypes[curr] === EnumToken.CommaTokenType) {
908
1187
  result = result.trimEnd() + " ";
909
1188
  }
910
- else if (arena.dataTypes[curr] == EnumToken.WhitespaceTokenType) {
1189
+ else if (arena.dataTypes[curr] === EnumToken.WhitespaceTokenType) {
911
1190
  result = result.trimEnd() + " ";
912
1191
  }
913
- else if (arena.dataTypes[curr] == EnumToken.CommaTokenType ||
914
- (arena.dataTypes[curr] == EnumToken.LiteralTokenType && arena.strings[arena.stringValue[curr]] == "/")) {
915
- result = result.trimEnd() + (arena.dataTypes[curr] == EnumToken.CommaTokenType ? "," : "/");
1192
+ else if (arena.dataTypes[curr] === EnumToken.CommaTokenType ||
1193
+ (arena.dataTypes[curr] === EnumToken.LiteralTokenType && arena.resolveString(arena.stringValue[curr]) === "/")) {
1194
+ result = result.trimEnd() + (arena.dataTypes[curr] === EnumToken.CommaTokenType ? "," : "/");
916
1195
  }
917
1196
  else {
918
1197
  result =
919
- result.trimEnd() + (useAlpha && index == count - 1 ? "/" : " ") + renderValue(arena, curr, options, cache);
1198
+ result.trimEnd() +
1199
+ (useAlpha && index === count - 1 ? "/" : " ") +
1200
+ renderValue(arena, curr, options, cache);
920
1201
  }
921
1202
  }
922
1203
  return (hasAlpha && fnName.endsWith("a") ? fnName.slice(0, -1) : fnName) + "(" + result.trimStart() + ")";
@@ -924,6 +1205,7 @@ function renderColor(arena, token, options, cache, reducer, errors) {
924
1205
  /**
925
1206
  * render ast token. identical constructs (colors and tokens with sub tokens: functions, parentheses, binary
926
1207
  * expressions, ...) are rendered once per render, see {@link RenderMemo}
1208
+ * @param arena
927
1209
  * @param token
928
1210
  * @param options
929
1211
  * @param cache
@@ -932,9 +1214,9 @@ function renderColor(arena, token, options, cache, reducer, errors) {
932
1214
  * @private
933
1215
  */
934
1216
  function renderValue(arena, token, options = defaultRenderOptions, cache = defaultCache, reducer, errors) {
935
- if (arena.dataTypes[token] == EnumToken.ColorTokenType ||
936
- arena.firstToken[token] != 0 ||
937
- arena.firstChild[token] != 0) {
1217
+ if (arena.dataTypes[token] === EnumToken.ColorTokenType ||
1218
+ arena.firstToken[token] !== 0 ||
1219
+ arena.firstChild[token] !== 0) {
938
1220
  const memo = getRenderMemo(cache, options);
939
1221
  if (memo != null) {
940
1222
  const slot = memo.constructs.token(arena, token);
@@ -961,7 +1243,7 @@ function renderValue(arena, token, options = defaultRenderOptions, cache = defau
961
1243
  */
962
1244
  function renderToken(arena, token, options, cache, reducer, errors) {
963
1245
  if (arena.dataTypes[token] === EnumToken.WhenElseFunctionTokenType &&
964
- equalsIgnoreCase(arena.strings[arena.stringValue[token]], "supports")) {
1246
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[token]), "supports")) {
965
1247
  options = { ...options, minifyValues: false, minify: false, convertColor: false };
966
1248
  reducer = null;
967
1249
  }
@@ -985,7 +1267,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
985
1267
  case EnumToken.GeneralEnclosedFunctionTokenDefType:
986
1268
  case EnumToken.CustomFunctionTokenDefType:
987
1269
  case EnumToken.WildCardFunctionTokenDefType:
988
- return arena.strings[arena.stringValue[token]] + "(";
1270
+ return arena.resolveString(arena.stringValue[token]) + "(";
989
1271
  case EnumToken.ListToken:
990
1272
  return renderList(arena, arena.firstToken[token], options, cache);
991
1273
  case EnumToken.BinaryExpressionTokenType: {
@@ -996,16 +1278,16 @@ function renderToken(arena, token, options, cache, reducer, errors) {
996
1278
  const r = (arena.getChildAt(token, TokenField.R) == null ? null : arena.fieldTokens(token, TokenField.R))[0];
997
1279
  if (EnumToken.Mul === op || EnumToken.Div === op) {
998
1280
  let result = "";
999
- if (arena.dataTypes[l] == EnumToken.BinaryExpressionTokenType &&
1000
- (arena.numericValue[l] == EnumToken.Add || arena.numericValue[l] == EnumToken.Sub)) {
1281
+ if (arena.dataTypes[l] === EnumToken.BinaryExpressionTokenType &&
1282
+ (arena.numericValue[l] === EnumToken.Add || arena.numericValue[l] === EnumToken.Sub)) {
1001
1283
  result = "(" + renderValue(arena, l, options, cache) + ")";
1002
1284
  }
1003
1285
  else {
1004
1286
  result = renderValue(arena, l, options, cache);
1005
1287
  }
1006
- result += op == EnumToken.Mul ? "*" : "/";
1007
- if (arena.dataTypes[r] == EnumToken.BinaryExpressionTokenType &&
1008
- (arena.numericValue[r] == EnumToken.Add || arena.numericValue[r] == EnumToken.Sub)) {
1288
+ result += op === EnumToken.Mul ? "*" : "/";
1289
+ if (arena.dataTypes[r] === EnumToken.BinaryExpressionTokenType &&
1290
+ (arena.numericValue[r] === EnumToken.Add || arena.numericValue[r] === EnumToken.Sub)) {
1009
1291
  result += "(" + renderValue(arena, r, options, cache) + ")";
1010
1292
  }
1011
1293
  else {
@@ -1014,7 +1296,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1014
1296
  return result;
1015
1297
  }
1016
1298
  return (renderValue(arena, l, options, cache) +
1017
- (op == EnumToken.Add ? " + " : " - ") +
1299
+ (op === EnumToken.Add ? " + " : " - ") +
1018
1300
  renderValue(arena, r, options, cache));
1019
1301
  }
1020
1302
  case EnumToken.FractionTokenType: {
@@ -1023,7 +1305,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1023
1305
  // inlined: arena.denominator(token)
1024
1306
  const denominator = arena.lastChild[token];
1025
1307
  const fraction = renderValue(arena, numerator) + "/" + renderValue(arena, denominator);
1026
- if (arena.numericValue[denominator] != 0) {
1308
+ if (arena.numericValue[denominator] !== 0) {
1027
1309
  const value = minifyNumber(arena.numericValue[numerator] / arena.numericValue[denominator]);
1028
1310
  if (value.length <= fraction.length) {
1029
1311
  return value;
@@ -1044,17 +1326,17 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1044
1326
  case EnumToken.WrappedValuesTokenType:
1045
1327
  return "{" + renderList(arena, arena.firstToken[token], options, cache) + "}";
1046
1328
  case EnumToken.ColorTokenType: {
1047
- if (arena.colorType[token] == ColorType.LIGHT_DARK ||
1048
- (arena.firstToken[token] != 0 && options.convertColor === false && arena.tokenCount(token) == 2)) {
1329
+ if (arena.colorType[token] === ColorType.LIGHT_DARK ||
1330
+ (arena.firstToken[token] !== 0 && options.convertColor === false && arena.tokenCount(token) === 2)) {
1049
1331
  let result = "";
1050
- for (let curr = arena.firstToken[token]; curr != 0; curr = arena.nextSibling[curr]) {
1332
+ for (let curr = arena.firstToken[token]; curr !== 0; curr = arena.nextSibling[curr]) {
1051
1333
  if (arena.dataTypes[curr] === EnumToken.IdenTokenType) {
1052
1334
  // the token is updated in place
1053
1335
  parseColor(arena, curr);
1054
1336
  }
1055
1337
  result += renderValue(arena, curr, options, cache);
1056
1338
  }
1057
- return arena.strings[arena.stringValue[token]] + "(" + result + ")";
1339
+ return arena.resolveString(arena.stringValue[token]) + "(" + result + ")";
1058
1340
  }
1059
1341
  return renderColor(arena, token, options, cache, reducer);
1060
1342
  }
@@ -1064,9 +1346,9 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1064
1346
  if (arena.dataTypes[arena.firstToken[token]] === EnumToken.BadUrlTokenType) {
1065
1347
  return "url()";
1066
1348
  }
1067
- for (let child = arena.firstToken[token]; child != 0; child = arena.nextSibling[child]) {
1349
+ for (let child = arena.firstToken[token]; child !== 0; child = arena.nextSibling[child]) {
1068
1350
  if (arena.dataTypes[child] === EnumToken.StringTokenType) {
1069
- const val = arena.strings[arena.stringValue[child]];
1351
+ const val = arena.resolveString(arena.stringValue[child]);
1070
1352
  if (val.slice(1, 5) !== "data:" && urlTokenMatcher.test(val)) {
1071
1353
  arena.dataTypes[child] = EnumToken.UrlTokenTokenType;
1072
1354
  // inlined: arena.setStr(child, val.slice(1, -1))
@@ -1082,7 +1364,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1082
1364
  case EnumToken.ImageFunctionTokenType:
1083
1365
  if (options.minifyValues && arena.dataTypes[token] === EnumToken.ImageFunctionTokenType) {
1084
1366
  const slice = arena.tokens(token);
1085
- switch (arena.strings[arena.stringValue[token]]) {
1367
+ switch (arena.resolveString(arena.stringValue[token])) {
1086
1368
  case "linear-gradient":
1087
1369
  case "repeating-linear-gradient":
1088
1370
  {
@@ -1091,12 +1373,12 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1091
1373
  let j;
1092
1374
  let key;
1093
1375
  for (i = 0; i < slice.length; i++) {
1094
- if (arena.dataTypes[slice[i]] == EnumToken.ColorTokenType ||
1376
+ if (arena.dataTypes[slice[i]] === EnumToken.ColorTokenType ||
1095
1377
  arena.dataTypes[slice[i]] === EnumToken.CommaTokenType) {
1096
1378
  break;
1097
1379
  }
1098
- if (arena.dataTypes[slice[i]] == EnumToken.IdenTokenType &&
1099
- equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "to")) {
1380
+ if (arena.dataTypes[slice[i]] === EnumToken.IdenTokenType &&
1381
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "to")) {
1100
1382
  k = i + 1;
1101
1383
  while (k < slice.length &&
1102
1384
  (arena.dataTypes[slice[k]] === EnumToken.WhitespaceTokenType ||
@@ -1105,7 +1387,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1105
1387
  }
1106
1388
  if (k < slice.length && arena.dataTypes[slice[k]] === EnumToken.IdenTokenType) {
1107
1389
  // convert keyword to angle
1108
- key = arena.strings[arena.stringValue[slice[k]]].toLowerCase();
1390
+ key = arena.resolveString(arena.stringValue[slice[k]]).toLowerCase();
1109
1391
  switch (key) {
1110
1392
  case "right":
1111
1393
  slice.splice(i, k - i + 1, arena.createToken(EnumToken.AngleTokenType, 90, "deg"));
@@ -1121,7 +1403,8 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1121
1403
  arena.dataTypes[slice[j]] === EnumToken.CommentTokenType)) {
1122
1404
  j++;
1123
1405
  }
1124
- if (j < slice.length && arena.dataTypes[slice[j]] !== EnumToken.CommaTokenType) {
1406
+ if (j < slice.length &&
1407
+ arena.dataTypes[slice[j]] !== EnumToken.CommaTokenType) {
1125
1408
  i = j - 1;
1126
1409
  break;
1127
1410
  }
@@ -1129,7 +1412,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1129
1412
  if (key === "bottom") {
1130
1413
  // to bottom -> 180deg is the default angle and will be removed
1131
1414
  while (k < slice.length &&
1132
- arena.dataTypes[slice[k]] != EnumToken.CommaTokenType) {
1415
+ arena.dataTypes[slice[k]] !== EnumToken.CommaTokenType) {
1133
1416
  k++;
1134
1417
  }
1135
1418
  slice.splice(i, k - i + 1);
@@ -1142,7 +1425,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1142
1425
  }
1143
1426
  }
1144
1427
  }
1145
- else if (arena.dataTypes[slice[i]] == EnumToken.AngleTokenType) {
1428
+ else if (arena.dataTypes[slice[i]] === EnumToken.AngleTokenType) {
1146
1429
  if ((180 - arena.numericValue[toDegrees(arena, slice[i])]) % 360 === 0) {
1147
1430
  k = i + 1;
1148
1431
  // while (k < slice.length && arena.dataTypes[slice[k]] !== EnumToken.CommaTokenType) {
@@ -1185,16 +1468,16 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1185
1468
  const size = [];
1186
1469
  const colorSpaceDef = [];
1187
1470
  if (arena.dataTypes[slice[i]] === EnumToken.IdenTokenType) {
1188
- if (equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "farthest-corner") ||
1189
- equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "ellipse")) {
1471
+ if (equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "farthest-corner") ||
1472
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "ellipse")) {
1190
1473
  i++;
1191
1474
  }
1192
- else if (equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "closest-side") ||
1193
- equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "closest-corner") ||
1194
- equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "farthest-side")) {
1475
+ else if (equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "closest-side") ||
1476
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "closest-corner") ||
1477
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "farthest-side")) {
1195
1478
  size.push(slice[i++]);
1196
1479
  }
1197
- else if (equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "circle")) {
1480
+ else if (equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "circle")) {
1198
1481
  form.push(slice[i++]);
1199
1482
  }
1200
1483
  while (arena.dataTypes[slice[i]] === EnumToken.WhitespaceTokenType ||
@@ -1203,16 +1486,16 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1203
1486
  }
1204
1487
  }
1205
1488
  if (arena.dataTypes[slice[i]] === EnumToken.IdenTokenType) {
1206
- if (equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "farthest-corner") ||
1207
- equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "ellipse")) {
1489
+ if (equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "farthest-corner") ||
1490
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "ellipse")) {
1208
1491
  i++;
1209
1492
  }
1210
- else if (equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "closest-side") ||
1211
- equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "closest-corner") ||
1212
- equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "farthest-side")) {
1493
+ else if (equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "closest-side") ||
1494
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "closest-corner") ||
1495
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "farthest-side")) {
1213
1496
  size.push(slice[i++]);
1214
1497
  }
1215
- else if (equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "circle")) {
1498
+ else if (equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "circle")) {
1216
1499
  form.push(slice[i++]);
1217
1500
  }
1218
1501
  while (arena.dataTypes[slice[i]] === EnumToken.WhitespaceTokenType ||
@@ -1221,7 +1504,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1221
1504
  }
1222
1505
  }
1223
1506
  if (arena.dataTypes[slice[i]] === EnumToken.IdenTokenType &&
1224
- equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "at")) {
1507
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "at")) {
1225
1508
  i++;
1226
1509
  }
1227
1510
  while (arena.dataTypes[slice[i]] === EnumToken.WhitespaceTokenType ||
@@ -1229,16 +1512,17 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1229
1512
  i++;
1230
1513
  }
1231
1514
  if (arena.dataTypes[slice[i]] === EnumToken.PercentageTokenType ||
1232
- (arena.dataTypes[slice[i]] === EnumToken.NumberTokenType && 0 === arena.numericValue[slice[i]]) ||
1515
+ (arena.dataTypes[slice[i]] === EnumToken.NumberTokenType &&
1516
+ 0 === arena.numericValue[slice[i]]) ||
1233
1517
  (arena.dataTypes[slice[i]] === EnumToken.IdenTokenType &&
1234
- (equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "center") ||
1235
- equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "top") ||
1236
- equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "bottom") ||
1237
- equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "left") ||
1238
- equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "right")))) {
1518
+ (equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "center") ||
1519
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "top") ||
1520
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "bottom") ||
1521
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "left") ||
1522
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "right")))) {
1239
1523
  do {
1240
1524
  if (arena.dataTypes[slice[i]] === EnumToken.IdenTokenType &&
1241
- "in" === arena.strings[arena.stringValue[slice[i]]]) {
1525
+ "in" === arena.resolveString(arena.stringValue[slice[i]])) {
1242
1526
  break;
1243
1527
  }
1244
1528
  positions.push(slice[i]);
@@ -1258,10 +1542,10 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1258
1542
  for (k = 0; k < positions.length; k++) {
1259
1543
  if (arena.dataTypes[positions[k]] === EnumToken.IdenTokenType) {
1260
1544
  if (position1.length === 0) {
1261
- position1 = arena.strings[arena.stringValue[positions[k]]];
1545
+ position1 = arena.resolveString(arena.stringValue[positions[k]]);
1262
1546
  }
1263
1547
  else {
1264
- position2 = arena.strings[arena.stringValue[positions[k]]];
1548
+ position2 = arena.resolveString(arena.stringValue[positions[k]]);
1265
1549
  }
1266
1550
  }
1267
1551
  else if (arena.dataTypes[positions[k]] === EnumToken.PercentageTokenType ||
@@ -1388,7 +1672,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1388
1672
  // i++;
1389
1673
  // }
1390
1674
  if (arena.dataTypes[slice[i]] === EnumToken.IdenTokenType &&
1391
- equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "from")) {
1675
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "from")) {
1392
1676
  angles.push(slice[i++]);
1393
1677
  while (i < slice.length &&
1394
1678
  (arena.dataTypes[slice[i]] === EnumToken.WhitespaceTokenType ||
@@ -1402,7 +1686,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1402
1686
  i++;
1403
1687
  }
1404
1688
  else if (arena.dataTypes[slice[i]] !== EnumToken.CommaTokenType &&
1405
- arena.dataTypes[slice[i]] != EnumToken.IdenTokenType) {
1689
+ arena.dataTypes[slice[i]] !== EnumToken.IdenTokenType) {
1406
1690
  angles.push(slice[i++]);
1407
1691
  }
1408
1692
  while (i < slice.length &&
@@ -1412,7 +1696,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1412
1696
  }
1413
1697
  }
1414
1698
  if (arena.dataTypes[slice[i]] === EnumToken.IdenTokenType &&
1415
- equalsIgnoreCase(arena.strings[arena.stringValue[slice[i]]], "at")) {
1699
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[slice[i]]), "at")) {
1416
1700
  i++;
1417
1701
  while (i < slice.length &&
1418
1702
  (arena.dataTypes[slice[i]] === EnumToken.WhitespaceTokenType ||
@@ -1422,8 +1706,8 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1422
1706
  let position1 = "";
1423
1707
  let position2 = "";
1424
1708
  if (arena.dataTypes[slice[i]] === EnumToken.IdenTokenType &&
1425
- !equalsIgnoreCase("in", arena.strings[arena.stringValue[slice[i]]])) {
1426
- position1 = arena.strings[arena.stringValue[slice[i]]];
1709
+ !equalsIgnoreCase("in", arena.resolveString(arena.stringValue[slice[i]]))) {
1710
+ position1 = arena.resolveString(arena.stringValue[slice[i]]);
1427
1711
  positions.push(slice[i++]);
1428
1712
  }
1429
1713
  else if (arena.dataTypes[slice[i]] === EnumToken.PercentageTokenType ||
@@ -1437,8 +1721,8 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1437
1721
  positions.push(slice[i++]);
1438
1722
  }
1439
1723
  if (arena.dataTypes[slice[i]] === EnumToken.IdenTokenType &&
1440
- !equalsIgnoreCase("in", arena.strings[arena.stringValue[slice[i]]])) {
1441
- position2 = arena.strings[arena.stringValue[slice[i]]];
1724
+ !equalsIgnoreCase("in", arena.resolveString(arena.stringValue[slice[i]]))) {
1725
+ position2 = arena.resolveString(arena.stringValue[slice[i]]);
1442
1726
  positions.push(slice[i++]);
1443
1727
  }
1444
1728
  else if (arena.dataTypes[slice[i]] === EnumToken.PercentageTokenType ||
@@ -1461,7 +1745,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1461
1745
  i++;
1462
1746
  }
1463
1747
  if (arena.dataTypes[slice[i]] === EnumToken.IdenTokenType &&
1464
- equalsIgnoreCase("in", arena.strings[arena.stringValue[slice[i]]])) {
1748
+ equalsIgnoreCase("in", arena.resolveString(arena.stringValue[slice[i]]))) {
1465
1749
  while (i < slice.length && arena.dataTypes[slice[i]] !== EnumToken.CommaTokenType) {
1466
1750
  colorSpaceDef.push(slice[i++]);
1467
1751
  }
@@ -1508,7 +1792,10 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1508
1792
  }
1509
1793
  break;
1510
1794
  }
1511
- return arena.strings[arena.stringValue[token]] + "(" + renderTokenList(slice, reducer ?? createReducer(arena, options, cache)) + ")";
1795
+ return (arena.resolveString(arena.stringValue[token]) +
1796
+ "(" +
1797
+ renderTokenList(slice, reducer ?? createReducer(arena, options, cache)) +
1798
+ ")");
1512
1799
  }
1513
1800
  case EnumToken.TimingFunctionTokenType:
1514
1801
  case EnumToken.PseudoClassFuncTokenType:
@@ -1521,15 +1808,15 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1521
1808
  case EnumToken.GeneralEnclosedFunctionTokenType:
1522
1809
  case EnumToken.CustomFunctionTokenType:
1523
1810
  case EnumToken.WildCardFunctionTokenType:
1524
- if (arena.dataTypes[token] == EnumToken.MathFunctionTokenType && arena.tokenCount(token) == 1) {
1811
+ if (arena.dataTypes[token] === EnumToken.MathFunctionTokenType && arena.tokenCount(token) === 1) {
1525
1812
  // a single argument
1526
1813
  const first = arena.firstToken[token];
1527
1814
  const firstType = arena.dataTypes[first];
1528
- if (firstType != EnumToken.BinaryExpressionTokenType &&
1529
- firstType != EnumToken.FractionTokenType &&
1530
- firstType != EnumToken.IdenTokenType &&
1815
+ if (firstType !== EnumToken.BinaryExpressionTokenType &&
1816
+ firstType !== EnumToken.FractionTokenType &&
1817
+ firstType !== EnumToken.IdenTokenType &&
1531
1818
  !arena.hasFraction(first)) {
1532
- return (arena.strings[arena.stringValue[token]] +
1819
+ return (arena.resolveString(arena.stringValue[token]) +
1533
1820
  "(" +
1534
1821
  renderValue(arena, first, options, cache,
1535
1822
  // the reducer renders with the options of this token
@@ -1537,7 +1824,10 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1537
1824
  ")");
1538
1825
  }
1539
1826
  }
1540
- return (arena.strings[arena.stringValue[token]] ?? "") + "(" + renderReduced(arena, arena.firstToken[token], options, cache, reducer) + ")";
1827
+ return ((arena.resolveString(arena.stringValue[token]) ?? "") +
1828
+ "(" +
1829
+ renderReduced(arena, arena.firstToken[token], options, cache, reducer) +
1830
+ ")");
1541
1831
  case EnumToken.BlockStartTokenType:
1542
1832
  return "{";
1543
1833
  case EnumToken.BlockEndTokenType:
@@ -1608,13 +1898,13 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1608
1898
  let val = arena.hasFraction(token)
1609
1899
  ? renderValue(arena, arena.getFraction(token), options, cache)
1610
1900
  : minifyNumber(arena.numericValue[token]);
1611
- let unit = arena.strings[arena.unit[token]];
1612
- if (arena.dataTypes[token] == EnumToken.AngleTokenType && !val.includes("/")) {
1901
+ let unit = arena.resolveString(arena.unit[token]);
1902
+ if (arena.dataTypes[token] === EnumToken.AngleTokenType && !val.includes("/")) {
1613
1903
  const angle = getAngle(arena, token);
1614
1904
  let v;
1615
1905
  let value = val + unit;
1616
1906
  for (const u of angleUnits) {
1617
- if (arena.strings[arena.unit[token]] == u) {
1907
+ if (arena.resolveString(arena.unit[token]) === u) {
1618
1908
  continue;
1619
1909
  }
1620
1910
  switch (u) {
@@ -1654,20 +1944,20 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1654
1944
  }
1655
1945
  }
1656
1946
  if (val === "0") {
1657
- if (arena.dataTypes[token] == EnumToken.TimeTokenType) {
1947
+ if (arena.dataTypes[token] === EnumToken.TimeTokenType) {
1658
1948
  return "0s";
1659
1949
  }
1660
- if (arena.dataTypes[token] == EnumToken.FrequencyTokenType) {
1950
+ if (arena.dataTypes[token] === EnumToken.FrequencyTokenType) {
1661
1951
  return "0Hz";
1662
1952
  }
1663
1953
  // @ts-ignore
1664
- if (arena.dataTypes[token] == EnumToken.ResolutionTokenType) {
1954
+ if (arena.dataTypes[token] === EnumToken.ResolutionTokenType) {
1665
1955
  return "0x";
1666
1956
  }
1667
- return "0";
1957
+ return options.minifyValues ? "0" : "0" + unit;
1668
1958
  }
1669
- if (arena.dataTypes[token] == EnumToken.TimeTokenType) {
1670
- if (unit == "ms") {
1959
+ if (arena.dataTypes[token] === EnumToken.TimeTokenType) {
1960
+ if (unit === "ms") {
1671
1961
  // @ts-ignore
1672
1962
  const v = minifyNumber(val / 1000);
1673
1963
  if (v.length + 1 <= val.length) {
@@ -1677,17 +1967,17 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1677
1967
  }
1678
1968
  return val + "s";
1679
1969
  }
1680
- if (arena.dataTypes[token] == EnumToken.ResolutionTokenType && unit == "dppx") {
1970
+ if (arena.dataTypes[token] === EnumToken.ResolutionTokenType && unit === "dppx") {
1681
1971
  unit = "x";
1682
1972
  }
1683
1973
  return val.includes("/") ? val.replace("/", unit + "/") : minifyNumber(toPrecisionValue(val)) + unit;
1684
1974
  case EnumToken.FlexTokenType:
1685
1975
  case EnumToken.PercentageTokenType:
1686
- const uni = arena.dataTypes[token] == EnumToken.PercentageTokenType ? "%" : "fr";
1976
+ const uni = arena.dataTypes[token] === EnumToken.PercentageTokenType ? "%" : "fr";
1687
1977
  const perc = arena.hasFraction(token)
1688
1978
  ? renderValue(arena, arena.getFraction(token), options, cache)
1689
1979
  : minifyNumber(arena.numericValue[token]);
1690
- return options.minifyValues && perc == "0"
1980
+ return options.minifyValues && perc === "0"
1691
1981
  ? "0"
1692
1982
  : perc.includes("/")
1693
1983
  ? perc.replace("/", uni + "/")
@@ -1703,19 +1993,19 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1703
1993
  case EnumToken.NaNTokenType:
1704
1994
  return "NaN";
1705
1995
  case EnumToken.AtRuleTokenType:
1706
- return "@" + arena.strings[arena.name[token]];
1996
+ return "@" + arena.resolveString(arena.name[token]);
1707
1997
  case EnumToken.CommentTokenType:
1708
1998
  case EnumToken.CDOCOMMNodeType:
1709
1999
  if (options.removeComments &&
1710
- (!options.preserveLicense || !arena.strings[arena.stringValue[token]].startsWith("/*!"))) {
2000
+ (!options.preserveLicense || !arena.resolveString(arena.stringValue[token]).startsWith("/*!"))) {
1711
2001
  return "";
1712
2002
  }
1713
2003
  case EnumToken.PseudoClassTokenType:
1714
2004
  case EnumToken.PseudoElementTokenType:
1715
2005
  // https://www.w3.org/TR/selectors-4/#single-colon-pseudos
1716
- if (arena.dataTypes[token] == EnumToken.PseudoElementTokenType &&
1717
- pseudoElements.includes(arena.strings[arena.stringValue[token]].slice(1))) {
1718
- return arena.strings[arena.stringValue[token]].slice(1);
2006
+ if (arena.dataTypes[token] === EnumToken.PseudoElementTokenType &&
2007
+ pseudoElements.includes(arena.resolveString(arena.stringValue[token]).slice(1))) {
2008
+ return arena.resolveString(arena.stringValue[token]).slice(1);
1719
2009
  }
1720
2010
  case EnumToken.CssTypeTokenType:
1721
2011
  case EnumToken.UrlTokenTokenType:
@@ -1723,10 +2013,11 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1723
2013
  case EnumToken.IdenTokenType:
1724
2014
  case EnumToken.StringTokenType:
1725
2015
  case EnumToken.LiteralTokenType:
2016
+ case EnumToken.UniCodeRange:
1726
2017
  case EnumToken.DashedIdenTokenType:
1727
2018
  case EnumToken.PseudoPageTokenType:
1728
2019
  case EnumToken.ClassSelectorTokenType:
1729
- return arena.strings[arena.stringValue[token]];
2020
+ return arena.resolveString(arena.stringValue[token]);
1730
2021
  case EnumToken.NestingSelectorTokenType:
1731
2022
  return "&";
1732
2023
  case EnumToken.SupportsQueryUnaryConditionTokenType:
@@ -1754,7 +2045,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1754
2045
  (options.indent ?? "") +
1755
2046
  renderValue(arena, arena.field(token, TokenField.R), options, cache, reducer));
1756
2047
  case EnumToken.DeclarationNodeType:
1757
- return (arena.strings[arena.name[token]] +
2048
+ return (arena.resolveString(arena.name[token]) +
1758
2049
  ":" +
1759
2050
  renderTokenList(options.minifyValues ? filterValues(arena, arena.tokens(token)) : arena.tokens(token), (acc, curr) => acc + renderValue(arena, curr, options, cache, reducer)));
1760
2051
  case EnumToken.MediaQueryUnaryFeatureTokenType:
@@ -1764,12 +2055,12 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1764
2055
  case EnumToken.MediaQueryConditionTokenType: {
1765
2056
  const op = arena.field(token, TokenField.Op);
1766
2057
  const opType = arena.dataTypes[op];
1767
- const indent = opType == EnumToken.LtTokenType ||
1768
- opType == EnumToken.GtTokenType ||
1769
- opType == EnumToken.ColonTokenType ||
1770
- opType == EnumToken.DelimTokenType ||
1771
- opType == EnumToken.LteTokenType ||
1772
- opType == EnumToken.GteTokenType
2058
+ const indent = opType === EnumToken.LtTokenType ||
2059
+ opType === EnumToken.GtTokenType ||
2060
+ opType === EnumToken.ColonTokenType ||
2061
+ opType === EnumToken.DelimTokenType ||
2062
+ opType === EnumToken.LteTokenType ||
2063
+ opType === EnumToken.GteTokenType
1773
2064
  ? ""
1774
2065
  : " ";
1775
2066
  return (renderField(arena, token, TokenField.L, options, cache, reducer) +
@@ -1785,7 +2076,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1785
2076
  renderValue(arena, arena.field(token, TokenField.Op2), options, cache, reducer) +
1786
2077
  renderField(arena, token, TokenField.R, options, cache, reducer));
1787
2078
  case EnumToken.MediaFeatureTokenType:
1788
- return arena.strings[arena.stringValue[token]];
2079
+ return arena.resolveString(arena.stringValue[token]);
1789
2080
  case EnumToken.NotTokenType:
1790
2081
  return "not";
1791
2082
  case EnumToken.OnlyTokenType:
@@ -1810,6 +2101,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1810
2101
  }
1811
2102
  /**
1812
2103
  * Remove whitespace tokens that are not needed
2104
+ * @param arena
1813
2105
  * @param values
1814
2106
  *
1815
2107
  * @internal
@@ -1817,18 +2109,19 @@ function renderToken(arena, token, options, cache, reducer, errors) {
1817
2109
  function filterValues(arena, values) {
1818
2110
  let i = 0;
1819
2111
  for (; i < values.length; i++) {
1820
- if (arena.dataTypes[values[i]] == EnumToken.ImportantTokenType && arena.dataTypes[values[i - 1]] === EnumToken.WhitespaceTokenType) {
2112
+ if (arena.dataTypes[values[i]] === EnumToken.ImportantTokenType &&
2113
+ arena.dataTypes[values[i - 1]] === EnumToken.WhitespaceTokenType) {
1821
2114
  values.splice(i - 1, 1);
1822
2115
  }
1823
- else if (tokensfuncSet.has(arena.dataTypes[values[i]]) &&
2116
+ else if (isFunctionType(arena.dataTypes[values[i]]) &&
1824
2117
  // color keywords and hex colors are not functions
1825
- (arena.dataTypes[values[i]] != EnumToken.ColorTokenType || arena.firstToken[values[i]] != 0) &&
1826
- arena.dataTypes[values[i]] != EnumToken.WildCardFunctionTokenType &&
1827
- arena.dataTypes[values[i + 1]] == EnumToken.WhitespaceTokenType) {
2118
+ (arena.dataTypes[values[i]] !== EnumToken.ColorTokenType || arena.firstToken[values[i]] !== 0) &&
2119
+ arena.dataTypes[values[i]] !== EnumToken.WildCardFunctionTokenType &&
2120
+ arena.dataTypes[values[i + 1]] === EnumToken.WhitespaceTokenType) {
1828
2121
  values.splice(i + 1, 1);
1829
2122
  }
1830
2123
  }
1831
2124
  return values;
1832
2125
  }
1833
2126
 
1834
- export { NodeRenderer, RenderMemo, doRender, filterValues, move, renderValue };
2127
+ export { NodeRenderer, RenderMemo, doRender, filterValues, move, outputCapacity, renderValue };