@tbela99/css-parser 1.2.0 → 1.3.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 (55) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +2 -2
  3. package/dist/index-umd-web.js +483 -849
  4. package/dist/index.cjs +483 -849
  5. package/dist/index.d.ts +107 -11
  6. package/dist/lib/ast/features/calc.js +1 -25
  7. package/dist/lib/ast/features/inlinecssvariables.js +0 -19
  8. package/dist/lib/ast/features/transform.js +2 -2
  9. package/dist/lib/ast/math/expression.js +26 -149
  10. package/dist/lib/ast/math/math.js +8 -8
  11. package/dist/lib/ast/transform/compute.js +4 -37
  12. package/dist/lib/ast/transform/matrix.js +33 -34
  13. package/dist/lib/ast/transform/minify.js +32 -51
  14. package/dist/lib/ast/transform/perspective.js +1 -1
  15. package/dist/lib/ast/transform/rotate.js +13 -13
  16. package/dist/lib/ast/transform/scale.js +8 -8
  17. package/dist/lib/ast/transform/skew.js +4 -4
  18. package/dist/lib/ast/transform/translate.js +8 -8
  19. package/dist/lib/ast/transform/utils.js +31 -39
  20. package/dist/lib/ast/types.js +91 -2
  21. package/dist/lib/parser/declaration/set.js +2 -2
  22. package/dist/lib/parser/parse.js +34 -12
  23. package/dist/lib/parser/tokenize.js +28 -40
  24. package/dist/lib/parser/utils/type.js +1 -1
  25. package/dist/lib/renderer/render.js +36 -27
  26. package/dist/lib/syntax/color/cmyk.js +2 -2
  27. package/dist/lib/syntax/color/color-mix.js +11 -12
  28. package/dist/lib/syntax/color/color.js +7 -7
  29. package/dist/lib/syntax/color/hsl.js +4 -4
  30. package/dist/lib/syntax/color/hwb.js +27 -8
  31. package/dist/lib/syntax/color/lab.js +4 -4
  32. package/dist/lib/syntax/color/lch.js +4 -4
  33. package/dist/lib/syntax/color/oklab.js +4 -4
  34. package/dist/lib/syntax/color/oklch.js +4 -4
  35. package/dist/lib/syntax/color/relativecolor.js +1 -1
  36. package/dist/lib/syntax/color/rgb.js +4 -4
  37. package/dist/lib/syntax/color/utils/components.js +15 -3
  38. package/dist/lib/syntax/color/utils/distance.js +11 -1
  39. package/dist/lib/syntax/syntax.js +8 -17
  40. package/dist/lib/syntax/utils.js +1 -1
  41. package/dist/lib/validation/at-rules/document.js +1 -1
  42. package/dist/lib/validation/at-rules/import.js +4 -4
  43. package/dist/lib/validation/at-rules/keyframes.js +0 -11
  44. package/dist/lib/validation/at-rules/supports.js +6 -6
  45. package/dist/lib/validation/config.js +0 -4
  46. package/dist/lib/validation/parser/parse.js +0 -8
  47. package/dist/lib/validation/selector.js +0 -9
  48. package/dist/lib/validation/syntax.js +14 -134
  49. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -11
  50. package/dist/lib/validation/syntaxes/family-name.js +0 -32
  51. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -11
  52. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -26
  53. package/dist/lib/validation/syntaxes/url.js +0 -33
  54. package/dist/lib/validation/utils/list.js +0 -8
  55. package/package.json +1 -1
@@ -1,7 +1,13 @@
1
1
  import { EnumToken } from '../types.js';
2
2
  import { rem, compute } from './math.js';
3
3
  import { mathFuncs } from '../../syntax/syntax.js';
4
- import { minifyNumber } from '../../syntax/utils.js';
4
+ import '../minify.js';
5
+ import '../walk.js';
6
+ import '../../parser/parse.js';
7
+ import '../../parser/tokenize.js';
8
+ import '../../parser/utils/config.js';
9
+ import '../../syntax/color/utils/constants.js';
10
+ import '../../renderer/sourcemap/lib/encode.js';
5
11
 
6
12
  /**
7
13
  * evaluate an array of tokens
@@ -32,12 +38,7 @@ function evaluate(tokens) {
32
38
  });
33
39
  return evaluateFunc(tokens[0]);
34
40
  }
35
- // try {
36
41
  nodes = inlineExpression(evaluateExpression(buildExpression(tokens)));
37
- // } catch (e) {
38
- //
39
- // return tokens;
40
- // }
41
42
  if (nodes.length <= 1) {
42
43
  if (nodes.length == 1) {
43
44
  if (nodes[0].typ == EnumToken.BinaryExpressionTokenType) {
@@ -48,7 +49,7 @@ function evaluate(tokens) {
48
49
  return [{
49
50
  ...nodes[0],
50
51
  // @ts-ignore
51
- val: '' + Math[nodes[0].val.toUpperCase()],
52
+ val: Math[nodes[0].val.toUpperCase()],
52
53
  typ: EnumToken.NumberTokenType
53
54
  }];
54
55
  }
@@ -68,7 +69,7 @@ function evaluate(tokens) {
68
69
  token = { typ: EnumToken.ListToken, chi: [nodes[i], nodes[i + 1]] };
69
70
  }
70
71
  else {
71
- token = doEvaluate(nodes[i + 1], { typ: EnumToken.NumberTokenType, val: '-1' }, EnumToken.Mul);
72
+ token = doEvaluate(nodes[i + 1], { typ: EnumToken.NumberTokenType, val: -1 }, EnumToken.Mul);
72
73
  }
73
74
  i++;
74
75
  }
@@ -83,7 +84,7 @@ function evaluate(tokens) {
83
84
  const token = curr[1].reduce((acc, curr) => doEvaluate(acc, curr, EnumToken.Add));
84
85
  if (token.typ != EnumToken.BinaryExpressionTokenType) {
85
86
  if ('val' in token && +token.val < 0) {
86
- acc.push({ typ: EnumToken.Sub }, { ...token, val: String(-token.val) });
87
+ acc.push({ typ: EnumToken.Sub }, { ...token, val: -token.val });
87
88
  return acc;
88
89
  }
89
90
  }
@@ -110,73 +111,37 @@ function doEvaluate(l, r, op) {
110
111
  if (!isScalarToken(l) || !isScalarToken(r) || (l.typ == r.typ && 'unit' in l && 'unit' in r && l.unit != r.unit)) {
111
112
  return defaultReturn;
112
113
  }
113
- // if (l.typ == EnumToken.FunctionTokenType) {
114
- //
115
- // const val: Token[] = evaluateFunc(l as FunctionToken);
116
- //
117
- // if (val.length == 1) {
118
- //
119
- // l = val[0];
120
- // } else {
121
- //
122
- // return defaultReturn;
123
- // }
124
- // }
125
114
  if (r.typ == EnumToken.FunctionTokenType) {
126
115
  const val = evaluateFunc(r);
127
116
  if (val.length == 1) {
128
117
  r = val[0];
129
118
  }
130
- // else {
131
- //
132
- // return defaultReturn;
133
- // }
134
119
  }
135
- // if (l.typ == EnumToken.FunctionTokenType) {
136
- //
137
- // const val = evaluateFunc(l as FunctionToken);
138
- //
139
- // if (val.length == 1) {
140
- //
141
- // l = val[0];
142
- // }
143
- // }
144
120
  if ((op == EnumToken.Add || op == EnumToken.Sub)) {
145
121
  // @ts-ignore
146
122
  if (l.typ != r.typ) {
147
123
  return defaultReturn;
148
124
  }
149
125
  }
150
- // else if (
151
- // op == EnumToken.Mul &&
152
- // ![EnumToken.NumberTokenType, EnumToken.PercentageTokenType].includes(l.typ) &&
153
- // ![EnumToken.NumberTokenType, EnumToken.PercentageTokenType].includes(r.typ)) {
154
- //
155
- // return defaultReturn;
156
- // }
157
126
  let typ = l.typ == EnumToken.NumberTokenType ? r.typ : (r.typ == EnumToken.NumberTokenType ? l.typ : (l.typ == EnumToken.PercentageTokenType ? r.typ : l.typ));
158
127
  // @ts-ignore
159
128
  let v1 = l.val?.typ == EnumToken.FractionTokenType ? l.val : getValue(l);
160
129
  // @ts-ignore
161
130
  let v2 = r.val?.typ == EnumToken.FractionTokenType ? r.val : getValue(r);
162
- // if (v1 == null || v2 == null) {
163
- //
164
- // return defaultReturn;
165
- // }
166
131
  if (op == EnumToken.Mul) {
167
132
  if (l.typ != EnumToken.NumberTokenType && r.typ != EnumToken.NumberTokenType) {
168
133
  if (typeof v1 == 'number' && l.typ == EnumToken.PercentageTokenType) {
169
134
  v1 = {
170
135
  typ: EnumToken.FractionTokenType,
171
- l: { typ: EnumToken.NumberTokenType, val: String(v1) },
172
- r: { typ: EnumToken.NumberTokenType, val: '100' }
136
+ l: { typ: EnumToken.NumberTokenType, val: v1 },
137
+ r: { typ: EnumToken.NumberTokenType, val: 100 }
173
138
  };
174
139
  }
175
140
  else if (typeof v2 == 'number' && r.typ == EnumToken.PercentageTokenType) {
176
141
  v2 = {
177
142
  typ: EnumToken.FractionTokenType,
178
- l: { typ: EnumToken.NumberTokenType, val: String(v2) },
179
- r: { typ: EnumToken.NumberTokenType, val: '100' }
143
+ l: { typ: EnumToken.NumberTokenType, val: v2 },
144
+ r: { typ: EnumToken.NumberTokenType, val: 100 }
180
145
  };
181
146
  }
182
147
  }
@@ -186,7 +151,7 @@ function doEvaluate(l, r, op) {
186
151
  const token = {
187
152
  ...(l.typ == EnumToken.NumberTokenType ? r : l),
188
153
  typ,
189
- val: typeof val == 'number' ? minifyNumber(val) : val
154
+ val /* : typeof val == 'number' ? minifyNumber(val) : val */
190
155
  };
191
156
  if (token.typ == EnumToken.IdenTokenType) {
192
157
  // @ts-ignore
@@ -195,26 +160,10 @@ function doEvaluate(l, r, op) {
195
160
  return token;
196
161
  }
197
162
  function getValue(t) {
198
- // if (t.typ == EnumToken.FunctionTokenType) {
199
- //
200
- // v1 = evaluateFunc(t as FunctionToken);
201
- //
202
- // if (v1.length != 1 || v1[0].typ == EnumToken.BinaryExpressionTokenType) {
203
- //
204
- // return null;
205
- // }
206
- //
207
- // t = v1[0] as NumberToken | IdentToken;
208
- // }
209
163
  if (t.typ == EnumToken.IdenTokenType) {
210
164
  // @ts-ignore
211
165
  return Math[t.val.toUpperCase()];
212
166
  }
213
- // if ((t.val as FractionToken).typ == EnumToken.FractionTokenType) {
214
- //
215
- // // @ts-ignore
216
- // return (t.val as FractionToken).l.val / (t.val as FractionToken).r.val;
217
- // }
218
167
  // @ts-ignore
219
168
  return t.typ == EnumToken.FractionTokenType ? t.l.val / t.r.val : +t.val;
220
169
  }
@@ -232,15 +181,11 @@ function evaluateFunc(token) {
232
181
  case 'sqrt':
233
182
  case 'exp': {
234
183
  const value = evaluate(values);
235
- // if (value.length != 1 || (value[0].typ != EnumToken.NumberTokenType && value[0].typ != EnumToken.FractionTokenType) || (value[0].typ == EnumToken.FractionTokenType && (+(value[0] as FractionToken).r.val == 0 || !Number.isFinite(+(value[0] as FractionToken).l.val) || !Number.isFinite(+(value[0] as FractionToken).r.val)))) {
236
- //
237
- // return value;
238
- // }
239
184
  // @ts-ignore
240
185
  let val = value[0].typ == EnumToken.NumberTokenType ? +value[0].val : value[0].l.val / value[0].r.val;
241
186
  return [{
242
187
  typ: EnumToken.NumberTokenType,
243
- val: '' + Math[token.val](val)
188
+ val: Math[token.val](val)
244
189
  }];
245
190
  }
246
191
  case 'hypot': {
@@ -248,29 +193,16 @@ function evaluateFunc(token) {
248
193
  let all = [];
249
194
  let ref = chi[0];
250
195
  let value = 0;
251
- // if (![EnumToken.NumberTokenType, EnumToken.PercentageTokenType].includes(ref.typ) && !('unit' in ref)) {
252
- //
253
- // return [token];
254
- // }
255
196
  for (let i = 0; i < chi.length; i++) {
256
- // @ts-ignore
257
- // if (chi[i].typ != ref.typ || ('unit' in chi[i] && 'unit' in ref && chi[i].unit != ref.unit)) {
258
- //
259
- // return [token];
260
- // }
261
197
  // @ts-ignore
262
198
  const val = getValue(chi[i]);
263
- // if (val == null) {
264
- //
265
- // return [token];
266
- // }
267
199
  all.push(val);
268
200
  value += val * val;
269
201
  }
270
202
  return [
271
203
  {
272
204
  ...ref,
273
- val: Math.sqrt(value).toFixed(rem(...all))
205
+ val: +(Math.sqrt(value).toFixed(rem(...all)))
274
206
  }
275
207
  ];
276
208
  }
@@ -279,48 +211,18 @@ function evaluateFunc(token) {
279
211
  case 'rem':
280
212
  case 'mod': {
281
213
  const chi = values.filter(t => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ));
282
- // if (chi.length != 3 || chi[1].typ != EnumToken.CommaTokenType) {
283
- //
284
- // return [token];
285
- // }
286
- // if (token.val == 'pow' && (chi[0].typ != EnumToken.NumberTokenType || chi[2].typ != EnumToken.NumberTokenType)) {
287
- //
288
- // return [token];
289
- // }
290
- // if (['rem', 'mod'].includes(token.val) &&
291
- // (
292
- // chi[0].typ != chi[2].typ) || (
293
- // 'unit' in chi[0] && 'unit' in chi[2] &&
294
- // chi[0].unit != chi[2].unit
295
- // )) {
296
- //
297
- // return [token];
298
- // }
299
214
  // https://developer.mozilla.org/en-US/docs/Web/CSS/mod
300
215
  const v1 = evaluate([chi[0]]);
301
216
  const v2 = evaluate([chi[2]]);
302
- [EnumToken.PercentageTokenType, EnumToken.DimensionTokenType, EnumToken.AngleTokenType, EnumToken.NumberTokenType, EnumToken.LengthTokenType, EnumToken.TimeTokenType, EnumToken.FrequencyTokenType, EnumToken.ResolutionTokenType];
303
- // if (v1.length != 1 || v2.length != 1 || !types.includes(v1[0].typ) || !types.includes(v2[0].typ) || (v1[0] as DimensionToken).unit != (v2[0] as DimensionToken).unit) {
304
- //
305
- // return [token];
306
- // }
307
217
  // @ts-ignore
308
218
  const val1 = getValue(v1[0]);
309
219
  // @ts-ignore
310
220
  const val2 = getValue(v2[0]);
311
- // if (val1 == null || val2 == null || (v1[0].typ != v2[0].typ && val1 != 0 && val2 != 0)) {
312
- //
313
- // return [token];
314
- // }
315
221
  if (token.val == 'rem') {
316
- // if (val2 == 0) {
317
- //
318
- // return [token];
319
- // }
320
222
  return [
321
223
  {
322
224
  ...v1[0],
323
- val: (val1 % val2).toFixed(rem(val1, val2))
225
+ val: +((val1 % val2).toFixed(rem(val1, val2)))
324
226
  }
325
227
  ];
326
228
  }
@@ -328,7 +230,7 @@ function evaluateFunc(token) {
328
230
  return [
329
231
  {
330
232
  ...v1[0],
331
- val: String(Math.pow(val1, val2))
233
+ val: Math.pow(val1, val2)
332
234
  }
333
235
  ];
334
236
  }
@@ -336,14 +238,14 @@ function evaluateFunc(token) {
336
238
  return [
337
239
  {
338
240
  ...{}, ...v1[0],
339
- val: String(Math.atan2(val1, val2))
241
+ val: Math.atan2(val1, val2)
340
242
  }
341
243
  ];
342
244
  }
343
245
  return [
344
246
  {
345
247
  ...v1[0],
346
- val: String(val2 == 0 ? val1 : val1 - (Math.floor(val1 / val2) * val2))
248
+ val: val2 == 0 ? val1 : val1 - (Math.floor(val1 / val2) * val2)
347
249
  }
348
250
  ];
349
251
  }
@@ -361,10 +263,6 @@ function evaluateFunc(token) {
361
263
  continue;
362
264
  }
363
265
  const result = evaluate([curr]);
364
- // if (result.length != 1 || result[0].typ == EnumToken.FunctionTokenType) {
365
- //
366
- // return [token];
367
- // }
368
266
  const key = result[0].typ + ('unit' in result[0] ? result[0].unit : '');
369
267
  if (!valuesMap.has(key)) {
370
268
  valuesMap.set(key, []);
@@ -374,24 +272,12 @@ function evaluateFunc(token) {
374
272
  if (valuesMap.size == 1) {
375
273
  const values = valuesMap.values().next().value;
376
274
  if (token.val == 'log') {
377
- // if (values[0].typ != EnumToken.NumberTokenType || values.length > 2) {
378
- //
379
- // return [token];
380
- // }
381
275
  const val1 = getValue(values[0]);
382
276
  const val2 = values.length == 2 ? getValue(values[1]) : null;
383
- // if (values.length == 1) {
384
- //
385
- // return [
386
- // {
387
- // ...values[0],
388
- // val: String(Math.log(val1))
389
- // } as DimensionToken | AngleToken | NumberToken | LengthToken | TimeToken | FrequencyToken | ResolutionToken];
390
- // }
391
277
  return [
392
278
  {
393
279
  ...values[0],
394
- val: String(Math.log(val1) / Math.log(val2))
280
+ val: Math.log(val1) / Math.log(val2)
395
281
  }
396
282
  ];
397
283
  }
@@ -415,10 +301,6 @@ function evaluateFunc(token) {
415
301
  if (token.val == 'round') {
416
302
  let val = getValue(values[0]);
417
303
  let val2 = getValue(values[1]);
418
- // if (Number.isNaN(val) || Number.isNaN(val2)) {
419
- //
420
- // return [token];
421
- // }
422
304
  if (strategy == null || strategy == 'down') {
423
305
  val = val - (val % val2);
424
306
  }
@@ -426,11 +308,10 @@ function evaluateFunc(token) {
426
308
  val = strategy == 'to-zero' ? Math.trunc(val / val2) * val2 : (strategy == 'nearest' ? Math.round(val / val2) * val2 : Math.ceil(val / val2) * val2);
427
309
  }
428
310
  // @ts-ignore
429
- return [{ ...values[0], val: String(val) }];
311
+ return [{ ...values[0], val }];
430
312
  }
431
313
  }
432
314
  }
433
- // return [token];
434
315
  }
435
316
  return [token];
436
317
  }
@@ -440,10 +321,6 @@ function evaluateFunc(token) {
440
321
  */
441
322
  function inlineExpression(token) {
442
323
  const result = [];
443
- // if (token.typ == EnumToken.ParensTokenType && (token as ParensToken).chi.length == 1) {
444
- //
445
- // result.push((token as ParensToken).chi[0]);
446
- // } else
447
324
  if (token.typ == EnumToken.BinaryExpressionTokenType) {
448
325
  if ([EnumToken.Mul, EnumToken.Div].includes(token.op)) {
449
326
  result.push(token);
@@ -482,7 +359,7 @@ function isScalarToken(token) {
482
359
  }
483
360
  /**
484
361
  *
485
- * generate binary expression tree
362
+ * generate a binary expression tree
486
363
  * @param tokens
487
364
  */
488
365
  function buildExpression(tokens) {
@@ -502,7 +379,7 @@ function getArithmeticOperation(op) {
502
379
  }
503
380
  /**
504
381
  *
505
- * generate binary expression tree
382
+ * generate a binary expression tree
506
383
  * @param token
507
384
  */
508
385
  function factorToken(token) {
@@ -517,7 +394,7 @@ function factorToken(token) {
517
394
  return token;
518
395
  }
519
396
  /**
520
- * generate binary expression tree
397
+ * generate a binary expression tree
521
398
  * @param tokens
522
399
  * @param ops
523
400
  */
@@ -52,20 +52,20 @@ function compute(a, b, op) {
52
52
  const r2 = minifyNumber(r[0]) + '/' + minifyNumber(r[1]);
53
53
  return minifyNumber(result).length < r2.length ? result : {
54
54
  typ: EnumToken.FractionTokenType,
55
- l: { typ: EnumToken.NumberTokenType, val: minifyNumber(r[0]) },
56
- r: { typ: EnumToken.NumberTokenType, val: minifyNumber(r[1]) }
55
+ l: { typ: EnumToken.NumberTokenType, val: r[0] },
56
+ r: { typ: EnumToken.NumberTokenType, val: r[1] }
57
57
  };
58
58
  }
59
59
  }
60
60
  let l1 = typeof a == 'number' ? {
61
61
  typ: EnumToken.FractionTokenType,
62
- l: { typ: EnumToken.NumberTokenType, val: minifyNumber(a) },
63
- r: { typ: EnumToken.NumberTokenType, val: '1' }
62
+ l: { typ: EnumToken.NumberTokenType, val: a },
63
+ r: { typ: EnumToken.NumberTokenType, val: 1 }
64
64
  } : a;
65
65
  let r1 = typeof b == 'number' ? {
66
66
  typ: EnumToken.FractionTokenType,
67
- l: { typ: EnumToken.NumberTokenType, val: minifyNumber(b) },
68
- r: { typ: EnumToken.NumberTokenType, val: '1' }
67
+ l: { typ: EnumToken.NumberTokenType, val: b },
68
+ r: { typ: EnumToken.NumberTokenType, val: 1 }
69
69
  } : b;
70
70
  let l2;
71
71
  let r2;
@@ -103,8 +103,8 @@ function compute(a, b, op) {
103
103
  const result = a2[0] / a2[1];
104
104
  return minifyNumber(result).length <= minifyNumber(a2[0]).length + 1 + minifyNumber(a2[1]).length ? result : {
105
105
  typ: EnumToken.FractionTokenType,
106
- l: { typ: EnumToken.NumberTokenType, val: minifyNumber(a2[0]) },
107
- r: { typ: EnumToken.NumberTokenType, val: minifyNumber(a2[1]) }
106
+ l: { typ: EnumToken.NumberTokenType, val: a2[0] },
107
+ r: { typ: EnumToken.NumberTokenType, val: a2[1] }
108
108
  };
109
109
  }
110
110
  function rem(...a) {
@@ -1,4 +1,4 @@
1
- import { multiply, identity } from './utils.js';
1
+ import { multiply, toZero, identity } from './utils.js';
2
2
  import { EnumToken } from '../types.js';
3
3
  import { transformFunctions } from '../../syntax/syntax.js';
4
4
  import { length2Px } from '../../syntax/utils.js';
@@ -22,10 +22,6 @@ import { perspective } from './perspective.js';
22
22
  function compute(transformLists) {
23
23
  transformLists = transformLists.slice();
24
24
  stripCommaToken(transformLists);
25
- // if (transformLists.length == 0) {
26
- //
27
- // return null;
28
- // }
29
25
  let matrix = identity();
30
26
  let mat;
31
27
  const cumulative = [];
@@ -50,8 +46,10 @@ function compute(transformLists) {
50
46
  });
51
47
  }
52
48
  }
49
+ // console.error({matrix});
50
+ // matrix = toZero(matrix) as Matrix;
53
51
  return {
54
- matrix: serialize(matrix),
52
+ matrix: serialize(toZero(matrix)),
55
53
  cumulative,
56
54
  minified: minify(matrix) ?? [serialized]
57
55
  };
@@ -61,10 +59,6 @@ function computeMatrix(transformList, matrixVar) {
61
59
  let val;
62
60
  let i = 0;
63
61
  for (; i < transformList.length; i++) {
64
- // if (transformList[i].typ == EnumToken.WhitespaceTokenType) {
65
- //
66
- // continue;
67
- // }
68
62
  if (transformList[i].typ != EnumToken.FunctionTokenType || !transformFunctions.includes(transformList[i].val)) {
69
63
  return null;
70
64
  }
@@ -77,16 +71,7 @@ function computeMatrix(transformList, matrixVar) {
77
71
  {
78
72
  values.length = 0;
79
73
  const children = stripCommaToken(transformList[i].chi.slice());
80
- // if (children == null || children.length == 0) {
81
- //
82
- // return null;
83
- // }
84
74
  const valCount = transformList[i].val == 'translate3d' || transformList[i].val == 'translate' ? 3 : 1;
85
- // if (children.length == 1 && children[0].typ == EnumToken.IdenTokenType && (children[0] as IdentToken).val == 'none') {
86
- //
87
- // values.fill(0, 0, valCount);
88
- //
89
- // } else {
90
75
  for (let j = 0; j < children.length; j++) {
91
76
  if (children[j].typ == EnumToken.WhitespaceTokenType) {
92
77
  continue;
@@ -97,7 +82,6 @@ function computeMatrix(transformList, matrixVar) {
97
82
  }
98
83
  values.push(val);
99
84
  }
100
- // }
101
85
  if (values.length == 0 || values.length > valCount) {
102
86
  return null;
103
87
  }
@@ -132,10 +116,6 @@ function computeMatrix(transformList, matrixVar) {
132
116
  let values = [];
133
117
  let valuesCount = transformList[i].val == 'rotate3d' ? 4 : 1;
134
118
  for (const child of stripCommaToken(transformList[i].chi.slice())) {
135
- // if (child.typ == EnumToken.WhitespaceTokenType) {
136
- //
137
- // continue;
138
- // }
139
119
  values.push(child);
140
120
  if (transformList[i].val == 'rotateX') {
141
121
  x = 1;
@@ -178,19 +158,11 @@ function computeMatrix(transformList, matrixVar) {
178
158
  const children = stripCommaToken(transformList[i].chi.slice());
179
159
  for (let k = 0; k < children.length; k++) {
180
160
  child = children[k];
181
- // if (child.typ == EnumToken.CommentTokenType || child.typ == EnumToken.WhitespaceTokenType) {
182
- //
183
- // continue;
184
- // }
185
161
  if (child.typ != EnumToken.NumberTokenType) {
186
162
  return null;
187
163
  }
188
164
  values.push(getNumber(child));
189
165
  }
190
- // if (values.length == 0) {
191
- //
192
- // return null;
193
- // }
194
166
  if (transformList[i].val == 'scale3d') {
195
167
  if (values.length != 3) {
196
168
  return null;
@@ -234,10 +206,6 @@ function computeMatrix(transformList, matrixVar) {
234
206
  continue;
235
207
  }
236
208
  value = getAngle(child);
237
- // if (value == null) {
238
- //
239
- // return null;
240
- // }
241
209
  values.push(value * 2 * Math.PI);
242
210
  }
243
211
  if (values.length == 0 || (values.length > (transformList[i].val == 'skew' ? 2 : 1))) {
@@ -278,7 +246,6 @@ function computeMatrix(transformList, matrixVar) {
278
246
  }
279
247
  break;
280
248
  case 'matrix3d':
281
- // return null;
282
249
  case 'matrix':
283
250
  {
284
251
  const values = [];
@@ -1,4 +1,4 @@
1
- import { toZero, is2DMatrix, identity } from './utils.js';
1
+ import { is2DMatrix, identity } from './utils.js';
2
2
  import { EnumToken } from '../types.js';
3
3
  import { eq } from '../../parser/utils/eq.js';
4
4
  import { getNumber } from '../../syntax/color/color.js';
@@ -9,7 +9,6 @@ import '../../parser/parse.js';
9
9
  import '../../parser/tokenize.js';
10
10
  import '../../parser/utils/config.js';
11
11
  import '../../renderer/sourcemap/lib/encode.js';
12
- import { minifyNumber } from '../../syntax/utils.js';
13
12
 
14
13
  function parseMatrix(mat) {
15
14
  if (mat.typ == EnumToken.IdenTokenType) {
@@ -31,30 +30,30 @@ function parseMatrix(mat) {
31
30
  function matrix(values) {
32
31
  const matrix = identity();
33
32
  if (values.length === 6) {
34
- matrix[0][0] = values[0];
35
- matrix[0][1] = values[1];
36
- matrix[1][0] = values[2];
37
- matrix[1][1] = values[3];
38
- matrix[3][0] = values[4];
39
- matrix[3][1] = values[5];
33
+ matrix[0 * 4 + 0] = values[0];
34
+ matrix[0 * 4 + 1] = values[1];
35
+ matrix[1 * 4 + 0] = values[2];
36
+ matrix[1 * 4 + 1] = values[3];
37
+ matrix[3 * 4 + 0] = values[4];
38
+ matrix[3 * 4 + 1] = values[5];
40
39
  }
41
40
  else if (values.length === 16) {
42
- matrix[0][0] = values[0];
43
- matrix[0][1] = values[1];
44
- matrix[0][2] = values[2];
45
- matrix[0][3] = values[3];
46
- matrix[1][0] = values[4];
47
- matrix[1][1] = values[5];
48
- matrix[1][2] = values[6];
49
- matrix[1][3] = values[7];
50
- matrix[2][0] = values[8];
51
- matrix[2][1] = values[9];
52
- matrix[2][2] = values[10];
53
- matrix[2][3] = values[11];
54
- matrix[3][0] = values[12];
55
- matrix[3][1] = values[13];
56
- matrix[3][2] = values[14];
57
- matrix[3][3] = values[15];
41
+ matrix[0 * 4 + 0] = values[0];
42
+ matrix[0 * 4 + 1] = values[1];
43
+ matrix[0 * 4 + 2] = values[2];
44
+ matrix[0 * 4 + 3] = values[3];
45
+ matrix[1 * 4 + 0] = values[4];
46
+ matrix[1 * 4 + 1] = values[5];
47
+ matrix[1 * 4 + 2] = values[6];
48
+ matrix[1 * 4 + 3] = values[7];
49
+ matrix[2 * 4 + 0] = values[8];
50
+ matrix[2 * 4 + 1] = values[9];
51
+ matrix[2 * 4 + 2] = values[10];
52
+ matrix[2 * 4 + 3] = values[11];
53
+ matrix[3 * 4 + 0] = values[12];
54
+ matrix[3 * 4 + 1] = values[13];
55
+ matrix[3 * 4 + 2] = values[14];
56
+ matrix[3 * 4 + 3] = values[15];
58
57
  }
59
58
  else {
60
59
  return null;
@@ -62,7 +61,7 @@ function matrix(values) {
62
61
  return matrix;
63
62
  }
64
63
  function serialize(matrix) {
65
- matrix = matrix.map(t => toZero(t.slice()));
64
+ matrix = matrix.slice();
66
65
  // @ts-ignore
67
66
  if (eq(matrix, identity())) {
68
67
  return {
@@ -76,19 +75,19 @@ function serialize(matrix) {
76
75
  typ: EnumToken.FunctionTokenType,
77
76
  val: 'matrix',
78
77
  chi: [
79
- matrix[0][0],
80
- matrix[0][1],
81
- matrix[1][0],
82
- matrix[1][1],
83
- matrix[3][0],
84
- matrix[3][1]
78
+ matrix[0 * 4 + 0],
79
+ matrix[0 * 4 + 1],
80
+ matrix[1 * 4 + 0],
81
+ matrix[1 * 4 + 1],
82
+ matrix[3 * 4 + 0],
83
+ matrix[3 * 4 + 1]
85
84
  ].reduce((acc, t) => {
86
85
  if (acc.length > 0) {
87
86
  acc.push({ typ: EnumToken.CommaTokenType });
88
87
  }
89
88
  acc.push({
90
89
  typ: EnumToken.NumberTokenType,
91
- val: minifyNumber(t)
90
+ val: t
92
91
  });
93
92
  return acc;
94
93
  }, [])
@@ -97,13 +96,13 @@ function serialize(matrix) {
97
96
  return {
98
97
  typ: EnumToken.FunctionTokenType,
99
98
  val: 'matrix3d',
100
- chi: matrix.flat().reduce((acc, curr) => {
99
+ chi: matrix.reduce((acc, curr) => {
101
100
  if (acc.length > 0) {
102
101
  acc.push({ typ: EnumToken.CommaTokenType });
103
102
  }
104
103
  acc.push({
105
104
  typ: EnumToken.NumberTokenType,
106
- val: minifyNumber(curr)
105
+ val: curr
107
106
  });
108
107
  return acc;
109
108
  }, [])