@tbela99/css-parser 1.5.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +10 -10
  3. package/dist/index-umd-web.js +5998 -4972
  4. package/dist/index.cjs +6001 -4977
  5. package/dist/index.d.ts +52 -38
  6. package/dist/lib/ast/expand.js +21 -7
  7. package/dist/lib/ast/features/calc.js +17 -55
  8. package/dist/lib/ast/features/if.js +7 -3
  9. package/dist/lib/ast/features/inlinecssvariables.js +6 -5
  10. package/dist/lib/ast/features/prefix.js +41 -44
  11. package/dist/lib/ast/features/shorthand.js +10 -5
  12. package/dist/lib/ast/features/transform.js +2 -2
  13. package/dist/lib/ast/math/expression.js +207 -34
  14. package/dist/lib/ast/minify.js +121 -24
  15. package/dist/lib/ast/node.js +5 -3
  16. package/dist/lib/ast/transform/compute.js +37 -5
  17. package/dist/lib/ast/transform/minify.js +7 -7
  18. package/dist/lib/ast/transform/perspective.js +1 -1
  19. package/dist/lib/ast/transform/rotate.js +1 -1
  20. package/dist/lib/ast/transform/scale.js +1 -1
  21. package/dist/lib/ast/transform/skew.js +1 -1
  22. package/dist/lib/ast/transform/translate.js +1 -1
  23. package/dist/lib/ast/transform/utils.js +46 -18
  24. package/dist/lib/ast/walk.js +28 -4
  25. package/dist/{config.json.js → lib/data/properties.json.js} +106 -0
  26. package/dist/lib/{validation/config.json.js → data/validation.json.js} +14 -8
  27. package/dist/lib/fs/resolve.js +11 -2
  28. package/dist/lib/parser/declaration/list.js +22 -7
  29. package/dist/lib/parser/declaration/map.js +26 -8
  30. package/dist/lib/parser/declaration/set.js +3 -1
  31. package/dist/lib/parser/linesmap.js +2 -4
  32. package/dist/lib/parser/parse.js +393 -231
  33. package/dist/lib/parser/tokenize.js +1478 -819
  34. package/dist/lib/parser/utils/at-rule-container.js +28 -196
  35. package/dist/lib/parser/utils/at-rule-generic.js +6 -7
  36. package/dist/lib/parser/utils/at-rule-import.js +17 -13
  37. package/dist/lib/parser/utils/at-rule-media.js +36 -19
  38. package/dist/lib/parser/utils/at-rule-support.js +19 -9
  39. package/dist/lib/parser/utils/at-rule-when-else.js +11 -38
  40. package/dist/lib/parser/utils/at-rule.js +0 -18
  41. package/dist/lib/parser/utils/config.js +1 -1
  42. package/dist/lib/parser/utils/declaration.js +40 -97
  43. package/dist/lib/parser/utils/hash.js +4 -4
  44. package/dist/lib/parser/utils/selector.js +179 -224
  45. package/dist/lib/parser/utils/text.js +4 -2
  46. package/dist/lib/renderer/render.js +104 -74
  47. package/dist/lib/renderer/sourcemap/lib/codec.js +3 -3
  48. package/dist/lib/renderer/sourcemap/sourcemap.js +2 -5
  49. package/dist/lib/syntax/color/a98rgb.js +14 -4
  50. package/dist/lib/syntax/color/cmyk.js +14 -21
  51. package/dist/lib/syntax/color/color-mix.js +21 -34
  52. package/dist/lib/syntax/color/color.js +32 -49
  53. package/dist/lib/syntax/color/hsl.js +15 -15
  54. package/dist/lib/syntax/color/hwb.js +18 -17
  55. package/dist/lib/syntax/color/lab.js +17 -17
  56. package/dist/lib/syntax/color/lch.js +13 -13
  57. package/dist/lib/syntax/color/oklab.js +10 -11
  58. package/dist/lib/syntax/color/oklch.js +15 -18
  59. package/dist/lib/syntax/color/p3.js +18 -12
  60. package/dist/lib/syntax/color/prophotorgb.js +26 -28
  61. package/dist/lib/syntax/color/rec2020.js +8 -4
  62. package/dist/lib/syntax/color/relative-color.js +26 -10
  63. package/dist/lib/syntax/color/srgb.js +9 -7
  64. package/dist/lib/syntax/color/utils/distance.js +1 -1
  65. package/dist/lib/syntax/color/xyz.js +2 -2
  66. package/dist/lib/syntax/color/xyzd50.js +2 -2
  67. package/dist/lib/syntax/constants.js +13 -3
  68. package/dist/lib/syntax/syntax.js +32 -108
  69. package/dist/lib/validation/config.js +1 -1
  70. package/dist/lib/validation/match.js +29 -26
  71. package/dist/lib/validation/parser/parse.js +7 -3
  72. package/dist/node.js +16 -9
  73. package/dist/types.d.ts +5 -1
  74. package/dist/types.js +4 -0
  75. package/dist/utils/sync.js +22 -1
  76. package/dist/web.js +13 -4
  77. package/package.json +4 -4
  78. package/llms.txt +0 -80
@@ -1,4 +1,4 @@
1
- import { mathFuncs, LOC } from '../../syntax/constants.js';
1
+ import { mathFuncs, LOCEND, LOCSTA, LOCSRCID } from '../../syntax/constants.js';
2
2
  import { EnumToken } from '../types.js';
3
3
  import { rem, compute } from './math.js';
4
4
 
@@ -28,7 +28,9 @@ function evaluate(tokens) {
28
28
  if (acc.length > 0) {
29
29
  acc.push({ typ: EnumToken.CommaTokenType });
30
30
  }
31
- acc.push(...t);
31
+ for (const token of t) {
32
+ acc.push(token);
33
+ }
32
34
  return acc;
33
35
  });
34
36
  const result = evaluateFunc(tokens[0]);
@@ -58,7 +60,9 @@ function evaluate(tokens) {
58
60
  // @ts-ignore
59
61
  val: Math[nodes[0].val.toUpperCase()],
60
62
  typ: EnumToken.NumberTokenType,
61
- [LOC]: nodes[0][LOC],
63
+ [LOCSRCID]: nodes[0][LOCSRCID],
64
+ [LOCSTA]: nodes[0][LOCSTA],
65
+ [LOCEND]: nodes[0][LOCEND],
62
66
  },
63
67
  ];
64
68
  }
@@ -78,11 +82,19 @@ function evaluate(tokens) {
78
82
  token = {
79
83
  typ: EnumToken.ListToken,
80
84
  chi: [nodes[i], nodes[i + 1]],
81
- [LOC]: { ...nodes[i][LOC], end: nodes[i + 1][LOC].end },
85
+ [LOCSRCID]: nodes[i][LOCSRCID],
86
+ [LOCSTA]: nodes[i][LOCSTA],
87
+ [LOCEND]: nodes[i + 1][LOCEND],
82
88
  };
83
89
  }
84
90
  else {
85
- token = doEvaluate(nodes[i + 1], { typ: EnumToken.NumberTokenType, val: -1, [LOC]: nodes[i + 1][LOC] }, EnumToken.Mul);
91
+ token = doEvaluate(nodes[i + 1], {
92
+ typ: EnumToken.NumberTokenType,
93
+ val: -1,
94
+ [LOCSRCID]: nodes[i + 1][LOCSRCID],
95
+ [LOCSTA]: nodes[i + 1][LOCSTA],
96
+ [LOCEND]: nodes[i + 1][LOCEND],
97
+ }, EnumToken.Mul);
86
98
  }
87
99
  i++;
88
100
  }
@@ -97,16 +109,28 @@ function evaluate(tokens) {
97
109
  const token = curr[1].reduce((acc, curr) => doEvaluate(acc, curr, EnumToken.Add));
98
110
  if (token.typ != EnumToken.BinaryExpressionTokenType) {
99
111
  if ("val" in token && +token.val < 0) {
100
- acc.push({ typ: EnumToken.Sub, [LOC]: token[LOC] }, {
112
+ acc.push({
113
+ typ: EnumToken.Sub,
114
+ [LOCSRCID]: token[LOCSRCID],
115
+ [LOCSTA]: token[LOCSTA],
116
+ [LOCEND]: token[LOCEND],
117
+ }, {
101
118
  ...token,
102
119
  val: -token.val,
103
- [LOC]: token[LOC],
120
+ [LOCSRCID]: token[LOCSRCID],
121
+ [LOCSTA]: token[LOCSTA],
122
+ [LOCEND]: token[LOCEND],
104
123
  });
105
124
  return acc;
106
125
  }
107
126
  }
108
127
  if (acc.length > 0 && curr[0] != EnumToken.ListToken) {
109
- acc.push({ typ: EnumToken.Add, [LOC]: token[LOC] });
128
+ acc.push({
129
+ typ: EnumToken.Add,
130
+ [LOCSRCID]: token[LOCSRCID],
131
+ [LOCSTA]: token[LOCSTA],
132
+ [LOCEND]: token[LOCEND],
133
+ });
110
134
  }
111
135
  acc.push(token);
112
136
  return acc;
@@ -124,7 +148,9 @@ function doEvaluate(l, r, op) {
124
148
  op,
125
149
  l,
126
150
  r,
127
- [LOC]: { ...l[LOC], end: (r?.[LOC] ?? l[LOC])?.end },
151
+ [LOCSRCID]: l[LOCSRCID],
152
+ [LOCSTA]: l[LOCSTA],
153
+ [LOCEND]: r?.[LOCEND] ?? l[LOCEND],
128
154
  };
129
155
  if (!isScalarToken(l) || !isScalarToken(r) || (l.typ == r.typ && "unit" in l && "unit" in r && l.unit != r.unit)) {
130
156
  return defaultReturn;
@@ -162,15 +188,39 @@ function doEvaluate(l, r, op) {
162
188
  if (typeof v1 == "number" && l.typ == EnumToken.PercentageTokenType) {
163
189
  v1 = {
164
190
  typ: EnumToken.FractionTokenType,
165
- l: { typ: EnumToken.NumberTokenType, val: v1, [LOC]: l[LOC] },
166
- r: { typ: EnumToken.NumberTokenType, val: 100, [LOC]: r[LOC] },
191
+ l: {
192
+ typ: EnumToken.NumberTokenType,
193
+ val: v1,
194
+ [LOCSRCID]: l[LOCSRCID],
195
+ [LOCSTA]: l[LOCSTA],
196
+ [LOCEND]: l[LOCEND],
197
+ },
198
+ r: {
199
+ typ: EnumToken.NumberTokenType,
200
+ val: 100,
201
+ [LOCSRCID]: r[LOCSRCID],
202
+ [LOCSTA]: r[LOCSTA],
203
+ [LOCEND]: r[LOCEND],
204
+ },
167
205
  };
168
206
  }
169
207
  else if (typeof v2 == "number" && r.typ == EnumToken.PercentageTokenType) {
170
208
  v2 = {
171
209
  typ: EnumToken.FractionTokenType,
172
- l: { typ: EnumToken.NumberTokenType, val: v2, [LOC]: l[LOC] },
173
- r: { typ: EnumToken.NumberTokenType, val: 100, [LOC]: r[LOC] },
210
+ l: {
211
+ typ: EnumToken.NumberTokenType,
212
+ val: v2,
213
+ [LOCSRCID]: l[LOCSRCID],
214
+ [LOCSTA]: l[LOCSTA],
215
+ [LOCEND]: l[LOCEND],
216
+ },
217
+ r: {
218
+ typ: EnumToken.NumberTokenType,
219
+ val: 100,
220
+ [LOCSRCID]: r[LOCSRCID],
221
+ [LOCSTA]: r[LOCSTA],
222
+ [LOCEND]: r[LOCEND],
223
+ },
174
224
  };
175
225
  }
176
226
  }
@@ -181,7 +231,9 @@ function doEvaluate(l, r, op) {
181
231
  ...(l.typ === EnumToken.NumberTokenType || l.typ === EnumToken.IdenTokenType ? r : l),
182
232
  typ,
183
233
  val /* : typeof val == 'number' ? minifyNumber(val) : val */,
184
- [LOC]: { ...l[LOC], end: (r?.[LOC] ?? l?.[LOC])?.end },
234
+ [LOCSRCID]: l[LOCSRCID],
235
+ [LOCSTA]: l[LOCSTA],
236
+ [LOCEND]: r?.[LOCEND] ?? l[LOCEND],
185
237
  };
186
238
  if (token.typ == EnumToken.IdenTokenType) {
187
239
  // @ts-ignore
@@ -210,25 +262,66 @@ function evaluateFunc(token) {
210
262
  case "sign":
211
263
  case "sqrt":
212
264
  case "exp": {
265
+ if (token.val == "tan" || token.val == "atan") {
266
+ for (let i = 0; i < values.length; i++) {
267
+ if (values[i].typ == EnumToken.NumberTokenType) {
268
+ values[i] = Object.assign(values[i], { typ: EnumToken.AngleTokenType, unit: "rad" });
269
+ }
270
+ else if (values[i].typ == EnumToken.AngleTokenType && values[i].unit != "rad") {
271
+ switch (values[i].unit) {
272
+ case "deg":
273
+ Object.assign(values[i], {
274
+ unit: "rad",
275
+ val: values[i].val * (Math.PI / 180),
276
+ });
277
+ break;
278
+ case "grad":
279
+ Object.assign(values[i], {
280
+ unit: "rad",
281
+ val: values[i].val * (Math.PI / 200),
282
+ });
283
+ break;
284
+ case "turn":
285
+ Object.assign(values[i], {
286
+ unit: "rad",
287
+ val: values[i].val * (2 * Math.PI),
288
+ });
289
+ break;
290
+ }
291
+ }
292
+ }
293
+ }
213
294
  const value = evaluate(values);
214
295
  // @ts-ignore
215
- let val = value[0].typ == EnumToken.NumberTokenType
296
+ let val = value[0].typ == EnumToken.NumberTokenType ||
297
+ value[0].typ == EnumToken.AngleTokenType ||
298
+ value[0].typ == EnumToken.PercentageTokenType
216
299
  ? +value[0].val
217
300
  : // @ts-expect-error
218
301
  value[0].l.val / value[0].r.val;
219
302
  return [
220
- {
221
- typ: EnumToken.NumberTokenType,
222
- val: Math[token.val](val),
223
- [LOC]: value[0][LOC],
224
- },
303
+ token.val == "tan" || token.val == "atan"
304
+ ? {
305
+ typ: EnumToken.AngleTokenType,
306
+ val: Math[token.val](val),
307
+ unit: "rad",
308
+ [LOCSRCID]: value[0][LOCSRCID],
309
+ [LOCSTA]: value[0][LOCSTA],
310
+ [LOCEND]: value[0][LOCEND],
311
+ }
312
+ : {
313
+ typ: token.val == "sign" ? EnumToken.NumberTokenType : value[0].typ,
314
+ val: Math[token.val](val),
315
+ [LOCSRCID]: value[0][LOCSRCID],
316
+ [LOCSTA]: value[0][LOCSTA],
317
+ [LOCEND]: value[0][LOCEND],
318
+ },
225
319
  ];
226
320
  }
227
321
  case "hypot": {
228
322
  const chi = values.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType, EnumToken.CommaTokenType].includes(t.typ));
229
323
  let all = [];
230
324
  let ref = chi[0];
231
- let value = 0;
232
325
  for (let i = 0; i < chi.length; i++) {
233
326
  // @ts-ignore
234
327
  const val = getValue(chi[i]);
@@ -236,21 +329,64 @@ function evaluateFunc(token) {
236
329
  return null;
237
330
  }
238
331
  all.push(val);
239
- value += val * val;
240
332
  }
241
333
  return [
242
334
  {
243
335
  ...ref,
244
- val: +Math.sqrt(value).toFixed(rem(...all)),
245
- [LOC]: token[LOC],
336
+ val: Math.hypot(...all),
337
+ [LOCSRCID]: token[LOCSRCID],
338
+ [LOCSTA]: token[LOCSTA],
339
+ [LOCEND]: token[LOCEND],
246
340
  },
247
341
  ];
248
342
  }
343
+ case "mod":
249
344
  case "atan2":
250
345
  case "pow":
251
- case "rem":
252
- case "mod": {
346
+ case "rem": {
347
+ {
348
+ let typ = token.chi[0]?.typ;
349
+ for (let i = 1; i < token.chi.length; i++) {
350
+ if (token.chi[i].typ == EnumToken.WhitespaceTokenType ||
351
+ token.chi[i].typ == EnumToken.CommaTokenType ||
352
+ token.chi[i].typ == EnumToken.CommentTokenType) {
353
+ continue;
354
+ }
355
+ if (token.chi[i].typ != typ) {
356
+ return null;
357
+ }
358
+ }
359
+ }
253
360
  const chi = values.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ));
361
+ if (token.val == "atan2") {
362
+ for (let i = 0; i < chi.length; i++) {
363
+ if (chi[i].typ == EnumToken.NumberTokenType) {
364
+ chi[i] = Object.assign(chi[i], { typ: EnumToken.AngleTokenType, unit: "rad" });
365
+ }
366
+ else if (chi[i].typ == EnumToken.AngleTokenType && chi[i].unit != "rad") {
367
+ switch (chi[i].unit) {
368
+ case "deg":
369
+ Object.assign(chi[i], {
370
+ unit: "rad",
371
+ val: chi[i].val * (Math.PI / 180),
372
+ });
373
+ break;
374
+ case "grad":
375
+ Object.assign(chi[i], {
376
+ unit: "rad",
377
+ val: chi[i].val * (Math.PI / 200),
378
+ });
379
+ break;
380
+ case "turn":
381
+ Object.assign(chi[i], {
382
+ unit: "rad",
383
+ val: chi[i].val * (2 * Math.PI),
384
+ });
385
+ break;
386
+ }
387
+ }
388
+ }
389
+ }
254
390
  // https://developer.mozilla.org/en-US/docs/Web/CSS/mod
255
391
  const v1 = evaluate([chi[0]]);
256
392
  const v2 = evaluate([chi[2]]);
@@ -271,7 +407,9 @@ function evaluateFunc(token) {
271
407
  {
272
408
  ...v1[0],
273
409
  val: Math.pow(val1, val2),
274
- [LOC]: token[LOC],
410
+ [LOCSRCID]: token[LOCSRCID],
411
+ [LOCSTA]: token[LOCSTA],
412
+ [LOCEND]: token[LOCEND],
275
413
  },
276
414
  ];
277
415
  }
@@ -280,8 +418,12 @@ function evaluateFunc(token) {
280
418
  {
281
419
  ...{},
282
420
  ...v1[0],
421
+ typ: EnumToken.AngleTokenType,
422
+ unit: "rad",
283
423
  val: Math.atan2(val1, val2),
284
- [LOC]: token[LOC],
424
+ [LOCSRCID]: token[LOCSRCID],
425
+ [LOCSTA]: token[LOCSTA],
426
+ [LOCEND]: token[LOCEND],
285
427
  },
286
428
  ];
287
429
  }
@@ -289,7 +431,9 @@ function evaluateFunc(token) {
289
431
  {
290
432
  ...v1[0],
291
433
  val: val2 == 0 ? val1 : val1 - Math.floor(val1 / val2) * val2,
292
- [LOC]: token[LOC],
434
+ [LOCSRCID]: token[LOCSRCID],
435
+ [LOCSTA]: token[LOCSTA],
436
+ [LOCEND]: token[LOCEND],
293
437
  },
294
438
  ];
295
439
  }
@@ -326,7 +470,9 @@ function evaluateFunc(token) {
326
470
  {
327
471
  ...values[0],
328
472
  val: Math.log(val1) / Math.log(val2),
329
- [LOC]: token[LOC],
473
+ [LOCSRCID]: token[LOCSRCID],
474
+ [LOCSTA]: token[LOCSTA],
475
+ [LOCEND]: token[LOCEND],
330
476
  },
331
477
  ];
332
478
  }
@@ -362,7 +508,15 @@ function evaluateFunc(token) {
362
508
  : Math.ceil(val / val2) * val2;
363
509
  }
364
510
  // @ts-ignore
365
- return [{ ...values[0], val, [LOC]: token[LOC] }];
511
+ return [
512
+ {
513
+ ...values[0],
514
+ val,
515
+ [LOCSRCID]: token[LOCSRCID],
516
+ [LOCSTA]: token[LOCSTA],
517
+ [LOCEND]: token[LOCEND],
518
+ },
519
+ ];
366
520
  }
367
521
  }
368
522
  }
@@ -380,7 +534,18 @@ function inlineExpression(token) {
380
534
  result.push(token);
381
535
  }
382
536
  else {
383
- result.push(...inlineExpression(token.l), { typ: token.op, [LOC]: token[LOC] }, ...inlineExpression(token.r));
537
+ for (const child of inlineExpression(token.l)) {
538
+ result.push(child);
539
+ }
540
+ result.push({
541
+ typ: token.op,
542
+ [LOCSRCID]: token[LOCSRCID],
543
+ [LOCSTA]: token[LOCSTA],
544
+ [LOCEND]: token[LOCEND],
545
+ });
546
+ for (const child of inlineExpression(token.r)) {
547
+ result.push(child);
548
+ }
384
549
  }
385
550
  }
386
551
  else {
@@ -443,7 +608,13 @@ function factorToken(token) {
443
608
  token.val == "calc")) {
444
609
  if ((token.typ == EnumToken.MathFunctionTokenType || token.typ == EnumToken.FunctionTokenType) &&
445
610
  token.val == "calc") {
446
- token = { ...token, typ: EnumToken.ParensTokenType, [LOC]: token[LOC] };
611
+ token = {
612
+ ...token,
613
+ typ: EnumToken.ParensTokenType,
614
+ [LOCSRCID]: token[LOCSRCID],
615
+ [LOCSTA]: token[LOCSTA],
616
+ [LOCEND]: token[LOCEND],
617
+ };
447
618
  // @ts-ignore
448
619
  delete token.val;
449
620
  }
@@ -481,7 +652,9 @@ function factor(tokens, ops) {
481
652
  : getArithmeticOperation(tokens[i].val),
482
653
  l: factorToken(tokens[i - 1]),
483
654
  r: factorToken(tokens[i + 1]),
484
- [LOC]: { ...tokens[i - 1][LOC], end: tokens[i + 1][LOC]?.end },
655
+ [LOCSRCID]: tokens[i - 1][LOCSRCID],
656
+ [LOCSTA]: tokens[i - 1][LOCSTA],
657
+ [LOCEND]: tokens[i + 1][LOCEND],
485
658
  });
486
659
  i--;
487
660
  }
@@ -6,10 +6,9 @@ import { EnumToken } from './types.js';
6
6
  import { isWhiteSpace, isIdent, isFunction, isIdentStart } from '../syntax/syntax.js';
7
7
  import { FeatureWalkMode } from './features/type.js';
8
8
  import { trimArray } from '../validation/match.js';
9
- import { TOKENS, PARENT, OPTIMIZED, RAW, combinators, LOC } from '../syntax/constants.js';
9
+ import { TOKENS, PARENT, OPTIMIZED, RAW, combinators, LOCEND, LOCSTA, LOCSRCID } from '../syntax/constants.js';
10
10
  import { replaceNodeOrValue } from '../parser/utils/token.js';
11
11
  import { parseString } from '../parser/parse.js';
12
- import { tokenize } from '../parser/tokenize.js';
13
12
  import { replaceCompound } from './expand.js';
14
13
 
15
14
  const notEndingWith = ["(", "["].concat(combinators);
@@ -219,7 +218,9 @@ function transformAtRuleMediaPrelude(values) {
219
218
  },
220
219
  l: val1,
221
220
  r: val2,
222
- [LOC]: value[LOC],
221
+ [LOCSRCID]: value[LOCSRCID],
222
+ [LOCSTA]: value[LOCSTA],
223
+ [LOCEND]: value[LOCEND],
223
224
  },
224
225
  ],
225
226
  };
@@ -286,7 +287,9 @@ function minifyAtRuleMedia(tokens) {
286
287
  typ: EnumToken.CommaTokenType,
287
288
  });
288
289
  }
289
- acc.push(...t);
290
+ for (const token of t) {
291
+ acc.push(token);
292
+ }
290
293
  return acc;
291
294
  }, []));
292
295
  }
@@ -304,7 +307,15 @@ function reduce(acc, curr) {
304
307
  // trim :is()
305
308
  if (curr[0] == "&") {
306
309
  if (curr[1] == " " && !isIdent(curr[2]) && !isFunction(curr[2])) {
307
- curr.splice(0, 2);
310
+ const all = new Array(Math.max(curr.length - 2, 0));
311
+ let write = 0;
312
+ for (let read = 2; read < curr.length; read++) {
313
+ all[write++] = curr[read];
314
+ }
315
+ curr.length = 0;
316
+ for (let index = 0; index < write; index++) {
317
+ curr[index] = all[index];
318
+ }
308
319
  }
309
320
  }
310
321
  acc.push(curr.join(""));
@@ -366,7 +377,9 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
366
377
  node.sel === previous.sel) {
367
378
  // do not merge keyframes
368
379
  // https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@keyframes#resolving_duplicates
369
- previous.chi.push(...node.chi);
380
+ for (const child of node.chi) {
381
+ previous.chi.push(child);
382
+ }
370
383
  // @ts-ignore
371
384
  ast.chi.splice(i, 1);
372
385
  previous = ast?.chi?.[nodeIndex] ?? null;
@@ -398,7 +411,9 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
398
411
  minifyAtRuleMedia(slice);
399
412
  if (slice.length !== node[TOKENS].length) {
400
413
  node[TOKENS].length = 0;
401
- node[TOKENS].push(...slice);
414
+ for (const token of slice) {
415
+ node[TOKENS].push(token);
416
+ }
402
417
  node.val = slice.reduce((acc, curr, index, arr) => acc +
403
418
  (curr.typ === EnumToken.CommentTokenType ||
404
419
  (curr.typ === EnumToken.WhitespaceTokenType &&
@@ -450,8 +465,9 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
450
465
  previous.nam === node.nam &&
451
466
  previous.val === node.val) {
452
467
  if ("chi" in node) {
453
- // @ts-ignore
454
- previous.chi.push(...node.chi);
468
+ for (const child of node.chi) {
469
+ previous.chi.push(child);
470
+ }
455
471
  if (!hasDeclaration(previous)) {
456
472
  context.nodes.delete(previous);
457
473
  doMinify(previous, options, recursive, errors, nestingContent, context);
@@ -577,19 +593,40 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
577
593
  if (optimized.length > 1) {
578
594
  const check = optimized.at(-2);
579
595
  if (!combinators.includes(check)) {
580
- let last = optimized.pop();
596
+ const last = optimized[optimized.length - 1];
597
+ const all = new Array(Math.max(optimized.length - 1, 0));
598
+ let write = 0;
599
+ for (let read = 0; read < optimized.length - 1; read++) {
600
+ all[write++] = optimized[read];
601
+ }
602
+ optimized.length = 0;
603
+ for (let index = 0; index < write; index++) {
604
+ optimized[index] = all[index];
605
+ }
581
606
  wrap = false;
582
607
  rule =
583
608
  optimized.join("") +
584
609
  `:is(${selector
585
610
  .map((s) => {
611
+ const next = s[0] == "&" ? new Array(s.length) : new Array(s.length + 1);
612
+ let write = 0;
586
613
  if (s[0] == "&") {
587
- s.splice(0, 1, last);
614
+ next[write++] = last;
615
+ for (let read = 1; read < s.length; read++) {
616
+ next[write++] = s[read];
617
+ }
588
618
  }
589
619
  else {
590
- s.unshift(last);
620
+ next[write++] = last;
621
+ for (let read = 0; read < s.length; read++) {
622
+ next[write++] = s[read];
623
+ }
591
624
  }
592
- return s.join("");
625
+ const rebuilt = new Array(write);
626
+ for (let index = 0; index < write; index++) {
627
+ rebuilt[index] = next[index];
628
+ }
629
+ return rebuilt.join("");
593
630
  })
594
631
  .join(",")})`;
595
632
  }
@@ -598,7 +635,20 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
598
635
  rule = selector
599
636
  .map((s) => {
600
637
  if (s[0] == "&") {
601
- s.splice(0, 1, ...node[OPTIMIZED].optimized);
638
+ const replacement = node[OPTIMIZED].optimized;
639
+ const all = new Array(Math.max(s.length - 1 + replacement.length, 0));
640
+ let write = 0;
641
+ for (let read = 0; read < replacement.length; read++) {
642
+ all[write++] = replacement[read];
643
+ }
644
+ for (let read = 1; read < s.length; read++) {
645
+ all[write++] = s[read];
646
+ }
647
+ const rebuilt = new Array(write);
648
+ for (let index = 0; index < write; index++) {
649
+ rebuilt[index] = all[index];
650
+ }
651
+ return rebuilt.join("");
602
652
  }
603
653
  return s.join("");
604
654
  })
@@ -666,8 +716,15 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
666
716
  node.nam !== "font-face" &&
667
717
  // @ts-ignore
668
718
  node.nam === previous.nam)) {
719
+ const array = [];
720
+ for (let i = 0; i < previous.chi.length; i++) {
721
+ array.push(previous.chi[i]);
722
+ }
723
+ for (let i = 0; i < node.chi.length; i++) {
724
+ array.push(node.chi[i]);
725
+ }
669
726
  // @ts-ignore
670
- node.chi.unshift(...previous.chi);
727
+ node.chi = array;
671
728
  doMinify(node, options, recursive, errors, nestingContent, context);
672
729
  ast.chi.splice(nodeIndex, 1);
673
730
  previous = ast.chi[--i];
@@ -823,18 +880,42 @@ function optimizeSelector(selector) {
823
880
  while (optimized.length > 0) {
824
881
  const last = optimized.at(-1);
825
882
  if (last == " " || combinators.includes(last)) {
826
- optimized.pop();
883
+ const all = new Array(Math.max(optimized.length - 1, 0));
884
+ let write = 0;
885
+ for (let read = 0; read < optimized.length - 1; read++) {
886
+ all[write++] = optimized[read];
887
+ }
888
+ optimized.length = 0;
889
+ for (let index = 0; index < write; index++) {
890
+ optimized[index] = all[index];
891
+ }
827
892
  continue;
828
893
  }
829
894
  break;
830
895
  }
831
896
  for (let i1 = 0; i1 < selector.length; i1++) {
832
- selector[i1].splice(0, optimized.length);
897
+ const all = new Array(Math.max(selector[i1].length - optimized.length, 0));
898
+ let write = 0;
899
+ for (let read = optimized.length; read < selector[i1].length; read++) {
900
+ all[write++] = selector[i1][read];
901
+ }
902
+ selector[i1].length = 0;
903
+ for (let index = 0; index < write; index++) {
904
+ selector[i1][index] = all[index];
905
+ }
833
906
  }
834
907
  let reducible = optimized.length == 1;
835
908
  if (optimized[0] == "&") {
836
909
  if (optimized[1] == " ") {
837
- optimized.splice(0, 2);
910
+ const all = new Array(Math.max(optimized.length - 2, 0));
911
+ let write = 0;
912
+ for (let read = 2; read < optimized.length; read++) {
913
+ all[write++] = optimized[read];
914
+ }
915
+ optimized.length = 0;
916
+ for (let index = 0; index < write; index++) {
917
+ optimized[index] = all[index];
918
+ }
838
919
  }
839
920
  }
840
921
  if (optimized.length == 0 || optimized[0].charAt(0) == "&" || selector.length == 1) {
@@ -1016,7 +1097,9 @@ function reduceSelector(acc, curr) {
1016
1097
  if (acc.length > 0) {
1017
1098
  acc.push(",");
1018
1099
  }
1019
- acc.push(...curr);
1100
+ for (const c of curr) {
1101
+ acc.push(c);
1102
+ }
1020
1103
  return acc;
1021
1104
  }, []);
1022
1105
  }
@@ -1144,7 +1227,7 @@ function matchSelectors(selector1, selector2) {
1144
1227
  */
1145
1228
  function fixSelector(node) {
1146
1229
  if (node.sel.includes("&")) {
1147
- const attributes = [...tokenize(node.sel)].map((t) => t.token); // parseString(node.sel);
1230
+ const attributes = parseString(node.sel);
1148
1231
  for (const attr of walkValues(attributes)) {
1149
1232
  if (attr.value.typ == EnumToken.PseudoClassFuncTokenType &&
1150
1233
  attr.value.val == ":is") {
@@ -1185,9 +1268,13 @@ function wrapNodes(previous, node, match, ast, reducer, i, nodeIndex) {
1185
1268
  [RAW]: match.match.map((t) => t.slice()),
1186
1269
  };
1187
1270
  if (pSel == "&" || pSel === "") {
1188
- wrapper.chi.push(...previous.chi);
1271
+ for (const child of previous.chi) {
1272
+ wrapper.chi.push(child);
1273
+ }
1189
1274
  if (nSel == "&" || nSel === "") {
1190
- wrapper.chi.push(...node.chi);
1275
+ for (const child of node.chi) {
1276
+ wrapper.chi.push(child);
1277
+ }
1191
1278
  }
1192
1279
  else {
1193
1280
  wrapper.chi.push(node);
@@ -1415,7 +1502,15 @@ function reduceRuleSelector(node) {
1415
1502
  if (selector.length > 1 &&
1416
1503
  selector[0] == "&" &&
1417
1504
  (combinators.includes(selector[1]) || !/^[a-zA-Z:]/.test(selector[1]))) {
1418
- selector.shift();
1505
+ const all = new Array(Math.max(selector.length - 1, 0));
1506
+ let write = 0;
1507
+ for (let read = 1; read < selector.length; read++) {
1508
+ all[write++] = selector[read];
1509
+ }
1510
+ selector.length = 0;
1511
+ for (let index = 0; index < write; index++) {
1512
+ selector[index] = all[index];
1513
+ }
1419
1514
  }
1420
1515
  }
1421
1516
  const unique = new Set();
@@ -1426,7 +1521,9 @@ function reduceRuleSelector(node) {
1426
1521
  acc.push(",");
1427
1522
  }
1428
1523
  unique.add(sig);
1429
- acc.push(...curr);
1524
+ for (const c of curr) {
1525
+ acc.push(c);
1526
+ }
1430
1527
  }
1431
1528
  return acc;
1432
1529
  }, []);