@tbela99/css-parser 1.3.2 → 1.3.4

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 (59) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +59 -20
  3. package/dist/index-umd-web.js +1846 -1075
  4. package/dist/index.cjs +1941 -1202
  5. package/dist/index.d.ts +914 -181
  6. package/dist/lib/ast/expand.js +5 -10
  7. package/dist/lib/ast/features/calc.js +8 -8
  8. package/dist/lib/ast/features/inlinecssvariables.js +9 -8
  9. package/dist/lib/ast/features/prefix.js +5 -15
  10. package/dist/lib/ast/features/shorthand.js +5 -6
  11. package/dist/lib/ast/features/transform.js +18 -25
  12. package/dist/lib/ast/features/type.js +4 -2
  13. package/dist/lib/ast/minify.js +56 -112
  14. package/dist/lib/ast/transform/compute.js +2 -4
  15. package/dist/lib/ast/transform/matrix.js +20 -20
  16. package/dist/lib/ast/transform/minify.js +105 -12
  17. package/dist/lib/ast/transform/rotate.js +11 -11
  18. package/dist/lib/ast/transform/scale.js +6 -6
  19. package/dist/lib/ast/transform/skew.js +4 -4
  20. package/dist/lib/ast/transform/translate.js +3 -3
  21. package/dist/lib/ast/transform/utils.js +30 -37
  22. package/dist/lib/ast/types.js +16 -4
  23. package/dist/lib/ast/walk.js +172 -70
  24. package/dist/lib/fs/resolve.js +12 -7
  25. package/dist/lib/parser/declaration/list.js +3 -1
  26. package/dist/lib/parser/parse.js +441 -161
  27. package/dist/lib/parser/tokenize.js +12 -14
  28. package/dist/lib/renderer/render.js +7 -7
  29. package/dist/lib/syntax/color/cmyk.js +6 -3
  30. package/dist/lib/syntax/color/color-mix.js +2 -3
  31. package/dist/lib/syntax/color/color.js +28 -6
  32. package/dist/lib/syntax/color/hex.js +3 -0
  33. package/dist/lib/syntax/color/hsl.js +18 -7
  34. package/dist/lib/syntax/color/hwb.js +3 -3
  35. package/dist/lib/syntax/color/lab.js +4 -4
  36. package/dist/lib/syntax/color/lch.js +7 -4
  37. package/dist/lib/syntax/color/oklab.js +4 -4
  38. package/dist/lib/syntax/color/oklch.js +18 -6
  39. package/dist/lib/syntax/color/relativecolor.js +9 -56
  40. package/dist/lib/syntax/color/srgb.js +1 -1
  41. package/dist/lib/syntax/syntax.js +36 -18
  42. package/dist/lib/validation/at-rules/container.js +11 -0
  43. package/dist/lib/validation/at-rules/counter-style.js +11 -0
  44. package/dist/lib/validation/at-rules/font-feature-values.js +11 -0
  45. package/dist/lib/validation/at-rules/keyframes.js +11 -0
  46. package/dist/lib/validation/at-rules/layer.js +11 -0
  47. package/dist/lib/validation/at-rules/media.js +11 -0
  48. package/dist/lib/validation/at-rules/page-margin-box.js +11 -0
  49. package/dist/lib/validation/at-rules/page.js +11 -0
  50. package/dist/lib/validation/at-rules/supports.js +11 -0
  51. package/dist/lib/validation/at-rules/when.js +11 -0
  52. package/dist/lib/validation/config.js +0 -2
  53. package/dist/lib/validation/config.json.js +21 -9
  54. package/dist/lib/validation/parser/parse.js +53 -2
  55. package/dist/lib/validation/syntax.js +199 -36
  56. package/dist/node.js +63 -36
  57. package/dist/web.js +84 -25
  58. package/package.json +7 -5
  59. package/dist/lib/validation/parser/types.js +0 -54
@@ -1,4 +1,4 @@
1
- import { parseString } from '../parser/parse.js';
1
+ import { replaceToken, parseString } from '../parser/parse.js';
2
2
  import '../parser/tokenize.js';
3
3
  import '../parser/utils/config.js';
4
4
  import { EnumToken } from './types.js';
@@ -29,6 +29,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
29
29
  let preprocess = false;
30
30
  let postprocess = false;
31
31
  let parents;
32
+ let replacement;
32
33
  if (!('features' in options)) {
33
34
  // @ts-ignore
34
35
  options = {
@@ -38,82 +39,92 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
38
39
  removePrefix: false,
39
40
  features: [], ...options
40
41
  };
41
- // @ts-ignore
42
42
  for (const feature of features) {
43
43
  feature.register(options);
44
44
  }
45
45
  options.features.sort((a, b) => a.ordering - b.ordering);
46
46
  }
47
47
  for (const feature of options.features) {
48
- if (feature.preProcess) {
48
+ if (feature.processMode & FeatureWalkMode.Pre) {
49
49
  preprocess = true;
50
50
  }
51
- if (feature.postProcess) {
51
+ if (feature.processMode & FeatureWalkMode.Post) {
52
52
  postprocess = true;
53
53
  }
54
54
  }
55
55
  if (preprocess) {
56
- parents = [ast];
56
+ parents = new Set([ast]);
57
57
  for (const parent of parents) {
58
58
  if (parent.typ == EnumToken.CommentTokenType ||
59
59
  parent.typ == EnumToken.CDOCOMMTokenType) {
60
- Object.defineProperty(parent, 'parent', {
61
- ...definedPropertySettings,
62
- value: parent
63
- });
64
60
  continue;
65
61
  }
62
+ replacement = parent;
66
63
  for (const feature of options.features) {
67
- if (!feature.preProcess) {
64
+ if ((feature.processMode & FeatureWalkMode.Pre) === 0 || (feature.accept != null && !feature.accept.has(parent.typ))) {
68
65
  continue;
69
66
  }
70
- feature.run(parent, options, parent.parent ?? ast, context, FeatureWalkMode.Pre);
67
+ const result = feature.run(replacement, options, parent.parent ?? ast, context, FeatureWalkMode.Pre);
68
+ if (result != null) {
69
+ replacement = result;
70
+ }
71
+ }
72
+ if (replacement != parent && parent.parent != null) {
73
+ // @ts-ignore
74
+ replaceToken(parent.parent, parent, replacement);
71
75
  }
72
- if (('chi' in parent)) {
76
+ if (('chi' in replacement)) {
73
77
  // @ts-ignore
74
- for (const node of parent.chi) {
75
- parents.push(Object.defineProperty(node, 'parent', {
78
+ for (const node of replacement.chi) {
79
+ parents.add(Object.defineProperty(node, 'parent', {
76
80
  ...definedPropertySettings,
77
- value: parent
81
+ value: replacement
78
82
  }));
79
83
  }
80
84
  }
81
85
  }
82
86
  for (const feature of options.features) {
83
- if (feature.preProcess && 'cleanup' in feature) {
87
+ if ((feature.processMode & FeatureWalkMode.Pre) && 'cleanup' in feature) {
84
88
  // @ts-ignore
85
89
  feature.cleanup(ast, options, context, FeatureWalkMode.Pre);
86
90
  }
87
91
  }
88
92
  }
89
93
  doMinify(ast, options, recursive, errors, nestingContent, context);
90
- parents = [ast];
94
+ parents = new Set([ast]);
91
95
  for (const parent of parents) {
92
96
  if (parent.typ == EnumToken.CommentTokenType ||
93
97
  parent.typ == EnumToken.CDOCOMMTokenType) {
94
98
  continue;
95
99
  }
100
+ replacement = parent;
96
101
  if (postprocess) {
97
102
  for (const feature of options.features) {
98
- if (!feature.postProcess) {
103
+ if ((feature.processMode & FeatureWalkMode.Post) === 0 || (feature.accept != null && !feature.accept.has(parent.typ))) {
99
104
  continue;
100
105
  }
101
- feature.run(parent, options, parent.parent ?? ast, context, FeatureWalkMode.Post);
106
+ const result = feature.run(replacement, options, parent.parent ?? ast, context, FeatureWalkMode.Post);
107
+ if (result != null) {
108
+ replacement = result;
109
+ }
102
110
  }
103
111
  }
104
- if (('chi' in parent)) {
112
+ if (replacement != null && replacement != parent && parent.parent != null) {
105
113
  // @ts-ignore
106
- for (const node of parent.chi) {
107
- parents.push(Object.defineProperty(node, 'parent', {
114
+ replaceToken(parent.parent, parent, replacement);
115
+ }
116
+ if (('chi' in replacement)) {
117
+ for (const node of replacement.chi) {
118
+ parents.add(Object.defineProperty(node, 'parent', {
108
119
  ...definedPropertySettings,
109
- value: parent
120
+ value: replacement
110
121
  }));
111
122
  }
112
123
  }
113
124
  }
114
125
  if (postprocess) {
115
126
  for (const feature of options.features) {
116
- if (feature.postProcess && 'cleanup' in feature) {
127
+ if (feature.processMode & FeatureWalkMode.Post && 'cleanup' in feature) {
117
128
  // @ts-ignore
118
129
  feature.cleanup(ast, options, context, FeatureWalkMode.Post);
119
130
  }
@@ -125,12 +136,10 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
125
136
  * reduce selectors
126
137
  * @param acc
127
138
  * @param curr
128
- * @param index
129
- * @param array
130
139
  *
131
140
  * @private
132
141
  */
133
- function reduce(acc, curr, index, array) {
142
+ function reduce(acc, curr) {
134
143
  // trim :is()
135
144
  // if (array.length == 1 && array[0][0] == ':is(' && array[0].at(-1) == ')') {
136
145
  //
@@ -171,21 +180,18 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
171
180
  }
172
181
  let i = 0;
173
182
  let previous = null;
174
- let node;
183
+ let node = null;
175
184
  let nodeIndex = -1;
176
- // @ts-ignore
177
185
  for (; i < ast.chi.length; i++) {
178
- // @ts-ignore
179
186
  if (ast.chi[i].typ == EnumToken.CommentNodeType) {
180
187
  continue;
181
188
  }
182
- // @ts-ignore
183
189
  node = ast.chi[i];
184
190
  if (node.typ == EnumToken.AtRuleNodeType && node.nam == 'font-face') {
185
191
  continue;
186
192
  }
187
- if (node.typ == EnumToken.KeyframeAtRuleNodeType) {
188
- if (previous?.typ == EnumToken.KeyframeAtRuleNodeType &&
193
+ if (node.typ == EnumToken.KeyframesAtRuleNodeType) {
194
+ if (previous?.typ == EnumToken.KeyframesAtRuleNodeType &&
189
195
  node.nam == previous.nam &&
190
196
  node.val == previous.val) {
191
197
  ast.chi?.splice(nodeIndex--, 1);
@@ -193,15 +199,11 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
193
199
  i = nodeIndex;
194
200
  continue;
195
201
  }
196
- if (node.chi.length > 0) {
197
- doMinify(node, options, true, errors, nestingContent, context);
198
- }
199
202
  }
200
- else if (node.typ == EnumToken.KeyFrameRuleNodeType) {
201
- if (previous?.typ == EnumToken.KeyFrameRuleNodeType &&
203
+ else if (node.typ == EnumToken.KeyFramesRuleNodeType) {
204
+ if (previous?.typ == EnumToken.KeyFramesRuleNodeType &&
202
205
  node.sel == previous.sel) {
203
206
  previous.chi.push(...node.chi);
204
- // @ts-ignore
205
207
  ast.chi.splice(i--, 1);
206
208
  continue;
207
209
  }
@@ -223,25 +225,26 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
223
225
  }
224
226
  }
225
227
  else if (node.typ == EnumToken.AtRuleNodeType) {
226
- // @ts-ignore
227
228
  if (node.nam == 'media' && ['all', '', null].includes(node.val)) {
228
- // @ts-ignore
229
229
  ast.chi?.splice(i, 1, ...node.chi);
230
230
  i--;
231
231
  continue;
232
232
  }
233
- // @ts-ignore
234
233
  if (previous?.typ == EnumToken.AtRuleNodeType &&
234
+ node.nam != 'font-face' &&
235
235
  previous.nam == node.nam &&
236
236
  previous.val == node.val) {
237
237
  if ('chi' in node) {
238
238
  // @ts-ignore
239
239
  previous.chi.push(...node.chi);
240
+ if (!hasDeclaration(previous)) {
241
+ context.nodes.delete(previous);
242
+ doMinify(previous, options, recursive, errors, nestingContent, context);
243
+ }
240
244
  }
241
245
  ast?.chi?.splice(i--, 1);
242
246
  continue;
243
247
  }
244
- // @ts-ignore
245
248
  if (!hasDeclaration(node)) {
246
249
  doMinify(node, options, recursive, errors, nestingContent, context);
247
250
  }
@@ -252,47 +255,33 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
252
255
  // @ts-ignore
253
256
  else if (node.typ == EnumToken.RuleNodeType) {
254
257
  reduceRuleSelector(node);
255
- let wrapper;
258
+ let wrapper = null;
256
259
  let match;
257
- // @ts-ignore
258
260
  if (options.nestingRules) {
259
- // @ts-ignore
260
261
  if (previous?.typ == EnumToken.RuleNodeType) {
261
- // @ts-ignore
262
262
  reduceRuleSelector(previous);
263
263
  // @ts-ignore
264
264
  match = matchSelectors(previous.raw, node.raw, ast.typ);
265
- // @ts-ignore
266
265
  if (match != null) {
267
- // @ts-ignore
268
266
  wrapper = wrapNodes(previous, node, match, ast, reducer, i, nodeIndex);
269
267
  nodeIndex = i - 1;
270
- // @ts-ignore
271
268
  previous = ast.chi[nodeIndex];
272
269
  }
273
270
  }
274
- // @ts-ignore
275
271
  if (wrapper != null) {
276
- // @ts-ignore
277
272
  while (i < ast.chi.length) {
278
- // @ts-ignore
279
273
  const nextNode = ast.chi[i];
280
- // @ts-ignore
281
274
  if (nextNode.typ != EnumToken.RuleNodeType) {
282
275
  break;
283
276
  }
284
277
  reduceRuleSelector(nextNode);
285
- // @ts-ignore
286
- match = matchSelectors(wrapper.raw, nextNode.raw, ast.typ);
287
- // @ts-ignore
278
+ match = matchSelectors(wrapper.raw, nextNode.raw);
288
279
  if (match == null) {
289
280
  break;
290
281
  }
291
- // @ts-ignore
292
282
  wrapper = wrapNodes(wrapper, nextNode, match, ast, reducer, i, nodeIndex);
293
283
  }
294
284
  nodeIndex = --i;
295
- // @ts-ignore
296
285
  previous = ast.chi[nodeIndex];
297
286
  doMinify(wrapper, options, recursive, errors, nestingContent, context);
298
287
  continue;
@@ -339,7 +328,6 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
339
328
  curr.unshift('&');
340
329
  wrap = false;
341
330
  }
342
- // @ts-ignore
343
331
  acc.push(curr);
344
332
  return acc;
345
333
  }, []);
@@ -365,82 +353,67 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
365
353
  }
366
354
  }
367
355
  if (rule == null) {
368
- rule = selector.map(s => {
356
+ rule = selector.map((s) => {
369
357
  if (s[0] == '&') {
370
358
  s.splice(0, 1, ...node.optimized.optimized);
371
359
  }
372
360
  return s.join('');
373
361
  }).join(',');
374
362
  }
375
- // @ts-ignore
376
363
  let sel = wrap ? node.optimized.optimized.join('') + `:is(${rule})` : rule;
377
364
  if (sel.length < node.sel.length) {
378
365
  node.sel = sel;
379
366
  }
380
367
  }
368
+ doMinify(node, options, recursive, errors, nestingContent, context);
381
369
  }
382
- // @ts-ignore
383
370
  if (previous != null) {
384
- // @ts-ignore
385
371
  if ('chi' in previous && ('chi' in node)) {
386
- // @ts-ignore
387
372
  if (previous.typ == node.typ) {
388
373
  let shouldMerge = true;
389
- // @ts-ignore
390
374
  let k = previous.chi.length;
391
375
  while (k-- > 0) {
392
- // @ts-ignore
393
376
  if (previous.chi[k].typ == EnumToken.CommentNodeType) {
394
377
  continue;
395
378
  }
396
- // @ts-ignore
397
379
  shouldMerge = previous.chi[k].typ == EnumToken.DeclarationNodeType;
398
380
  break;
399
381
  }
400
382
  if (shouldMerge) {
401
383
  // @ts-ignore
402
- if (((node.typ == EnumToken.RuleNodeType || node.typ == EnumToken.KeyFrameRuleNodeType) && node.sel == previous.sel) ||
384
+ if (((node.typ == EnumToken.RuleNodeType || node.typ == EnumToken.KeyFramesRuleNodeType) && node.sel == previous.sel) ||
403
385
  // @ts-ignore
404
386
  (node.typ == EnumToken.AtRuleNodeType) && node.val != 'font-face' && node.val == previous.val) {
405
387
  // @ts-ignore
406
388
  node.chi.unshift(...previous.chi);
407
- // @ts-ignore
389
+ doMinify(node, options, recursive, errors, nestingContent, context);
408
390
  ast.chi.splice(nodeIndex, 1);
409
- i--;
410
- previous = node;
391
+ previous = ast.chi[--i];
411
392
  nodeIndex = i;
412
393
  continue;
413
394
  }
414
- else if (node.typ == previous?.typ && [EnumToken.KeyFrameRuleNodeType, EnumToken.RuleNodeType].includes(node.typ)) {
395
+ else if (node.typ == previous?.typ && [EnumToken.KeyFramesRuleNodeType, EnumToken.RuleNodeType].includes(node.typ)) {
415
396
  const intersect = diff(previous, node, reducer, options);
416
397
  if (intersect != null) {
417
398
  if (intersect.node1.chi.length == 0) {
418
- // @ts-ignore
419
399
  ast.chi.splice(i--, 1);
420
400
  }
421
401
  else {
422
- // @ts-ignore
423
402
  ast.chi.splice(i--, 1, intersect.node1);
424
403
  }
425
404
  if (intersect.node2.chi.length == 0) {
426
- // @ts-ignore
427
405
  ast.chi.splice(nodeIndex, 1, intersect.result);
428
406
  i--;
429
- // @ts-ignore
430
407
  if (nodeIndex == i) {
431
408
  nodeIndex = i;
432
409
  }
433
410
  }
434
411
  else {
435
- // @ts-ignore
436
412
  ast.chi.splice(nodeIndex, 1, intersect.result, intersect.node2);
437
- // @ts-ignore
438
413
  i = (nodeIndex ?? 0) + 1;
439
414
  }
440
415
  reduceRuleSelector(intersect.result);
441
- // @ts-ignore
442
416
  if (node != ast.chi[i]) {
443
- // @ts-ignore
444
417
  node = ast.chi[i];
445
418
  }
446
419
  previous = intersect.result;
@@ -449,9 +422,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
449
422
  }
450
423
  }
451
424
  }
452
- // @ts-ignore
453
425
  if (recursive && previous != node) {
454
- // @ts-ignore
455
426
  if (!hasDeclaration(previous)) {
456
427
  doMinify(previous, options, recursive, errors, nestingContent, context);
457
428
  }
@@ -459,9 +430,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
459
430
  }
460
431
  }
461
432
  if (!nestingContent &&
462
- // @ts-ignore
463
433
  previous != null &&
464
- // previous.optimized != null &&
465
434
  previous.typ == EnumToken.RuleNodeType &&
466
435
  previous.sel.includes('&')) {
467
436
  fixSelector(previous);
@@ -469,20 +438,15 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
469
438
  previous = node;
470
439
  nodeIndex = i;
471
440
  }
472
- // @ts-ignore
473
441
  if (recursive && node != null && ('chi' in node)) {
474
- // @ts-ignore
475
- if (node.typ == EnumToken.KeyframeAtRuleNodeType || !node.chi.some(n => n.typ == EnumToken.DeclarationNodeType)) {
476
- // @ts-ignore
442
+ if (node.typ == EnumToken.KeyframesAtRuleNodeType || !node.chi.some(n => n.typ == EnumToken.DeclarationNodeType)) {
477
443
  if (!(node.typ == EnumToken.AtRuleNodeType && node.nam != 'font-face')) {
478
444
  doMinify(node, options, recursive, errors, nestingContent, context);
479
445
  }
480
446
  }
481
447
  }
482
448
  if (!nestingContent &&
483
- // @ts-ignore
484
449
  node != null &&
485
- // previous.optimized != null &&
486
450
  node.typ == EnumToken.RuleNodeType &&
487
451
  node.sel.includes('&')) {
488
452
  fixSelector(node);
@@ -633,7 +597,6 @@ function splitRule(buffer) {
633
597
  }
634
598
  if (chr == ',') {
635
599
  if (str !== '') {
636
- // @ts-ignore
637
600
  result.at(-1).push(str);
638
601
  str = '';
639
602
  }
@@ -642,7 +605,6 @@ function splitRule(buffer) {
642
605
  }
643
606
  if (chr == '.') {
644
607
  if (str !== '') {
645
- // @ts-ignore
646
608
  result.at(-1).push(str);
647
609
  str = '';
648
610
  }
@@ -651,20 +613,17 @@ function splitRule(buffer) {
651
613
  }
652
614
  if (combinators.includes(chr)) {
653
615
  if (str !== '') {
654
- // @ts-ignore
655
616
  result.at(-1).push(str);
656
617
  str = '';
657
618
  }
658
619
  if (chr == '|' && buffer.charAt(i + 1) == '|') {
659
620
  chr += buffer.charAt(++i);
660
621
  }
661
- // @ts-ignore
662
622
  result.at(-1).push(chr);
663
623
  continue;
664
624
  }
665
625
  if (chr == ':') {
666
626
  if (str !== '') {
667
- // @ts-ignore
668
627
  result.at(-1).push(str);
669
628
  str = '';
670
629
  }
@@ -706,7 +665,6 @@ function splitRule(buffer) {
706
665
  }
707
666
  }
708
667
  if (str !== '') {
709
- // @ts-ignore
710
668
  result.at(-1).push(str);
711
669
  }
712
670
  return result;
@@ -771,7 +729,7 @@ function reduceSelector(acc, curr) {
771
729
  *
772
730
  * @private
773
731
  */
774
- function matchSelectors(selector1, selector2 /*, parentType: EnumToken, errors: ErrorDescription[] */) {
732
+ function matchSelectors(selector1, selector2) {
775
733
  let match = [[]];
776
734
  const j = Math.min(selector1.reduce((acc, curr) => Math.min(acc, curr.length), selector1.length > 0 ? selector1[0].length : 0), selector2.reduce((acc, curr) => Math.min(acc, curr.length), selector2.length > 0 ? selector2[0].length : 0));
777
735
  let i = 0;
@@ -846,7 +804,6 @@ function matchSelectors(selector1, selector2 /*, parentType: EnumToken, errors:
846
804
  * @private
847
805
  */
848
806
  function fixSelector(node) {
849
- // @ts-ignore
850
807
  if (node.sel.includes('&')) {
851
808
  const attributes = parseString(node.sel);
852
809
  for (const attr of walkValues(attributes)) {
@@ -881,40 +838,27 @@ function wrapNodes(previous, node, match, ast, reducer, i, nodeIndex) {
881
838
  let nSel = match.selector2.reduce(reducer, []).join(',');
882
839
  // @ts-ignore
883
840
  const wrapper = { ...previous, chi: [], sel: match.match.reduce(reducer, []).join(',') };
884
- // @ts-ignore
885
841
  Object.defineProperty(wrapper, 'raw', {
886
842
  ...definedPropertySettings,
887
- // @ts-ignore
888
843
  value: match.match.map(t => t.slice())
889
844
  });
890
845
  if (pSel == '&' || pSel === '') {
891
- // @ts-ignore
892
846
  wrapper.chi.push(...previous.chi);
893
- // @ts-ignore
894
847
  if ((nSel == '&' || nSel === '')) {
895
- // @ts-ignore
896
848
  wrapper.chi.push(...node.chi);
897
849
  }
898
850
  else {
899
- // @ts-ignore
900
851
  wrapper.chi.push(node);
901
852
  }
902
853
  }
903
854
  else {
904
- // @ts-ignore
905
855
  wrapper.chi.push(previous, node);
906
856
  }
907
- // @ts-ignore
908
857
  ast.chi.splice(i, 1, wrapper);
909
- // @ts-ignore
910
858
  ast.chi.splice(nodeIndex, 1);
911
- // @ts-ignore
912
859
  previous.sel = pSel;
913
- // @ts-ignore
914
860
  previous.raw = match.selector1;
915
- // @ts-ignore
916
861
  node.sel = nSel;
917
- // @ts-ignore
918
862
  node.raw = match.selector2;
919
863
  reduceRuleSelector(wrapper);
920
864
  return wrapper;
@@ -46,8 +46,6 @@ function compute(transformLists) {
46
46
  });
47
47
  }
48
48
  }
49
- // console.error({matrix});
50
- // matrix = toZero(matrix) as Matrix;
51
49
  return {
52
50
  matrix: serialize(toZero(matrix)),
53
51
  cumulative,
@@ -71,7 +69,7 @@ function computeMatrix(transformList, matrixVar) {
71
69
  {
72
70
  values.length = 0;
73
71
  const children = stripCommaToken(transformList[i].chi.slice());
74
- const valCount = transformList[i].val == 'translate3d' || transformList[i].val == 'translate' ? 3 : 1;
72
+ const valCount = transformList[i].val == 'translate3d' ? 3 : transformList[i].val == 'translate' ? 2 : 1;
75
73
  for (let j = 0; j < children.length; j++) {
76
74
  if (children[j].typ == EnumToken.WhitespaceTokenType) {
77
75
  continue;
@@ -158,7 +156,7 @@ function computeMatrix(transformList, matrixVar) {
158
156
  const children = stripCommaToken(transformList[i].chi.slice());
159
157
  for (let k = 0; k < children.length; k++) {
160
158
  child = children[k];
161
- if (child.typ != EnumToken.NumberTokenType) {
159
+ if (child.typ != EnumToken.NumberTokenType && child.typ != EnumToken.PercentageTokenType) {
162
160
  return null;
163
161
  }
164
162
  values.push(getNumber(child));
@@ -30,27 +30,27 @@ function parseMatrix(mat) {
30
30
  function matrix(values) {
31
31
  const matrix = identity();
32
32
  if (values.length === 6) {
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];
33
+ matrix[0] = values[0];
34
+ matrix[1] = values[1];
35
+ matrix[4] = values[2];
36
+ matrix[4 + 1] = values[3];
37
+ matrix[3 * 4] = values[4];
38
38
  matrix[3 * 4 + 1] = values[5];
39
39
  }
40
40
  else if (values.length === 16) {
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];
41
+ matrix[0] = values[0];
42
+ matrix[1] = values[1];
43
+ matrix[2] = values[2];
44
+ matrix[3] = values[3];
45
+ matrix[4] = values[4];
46
+ matrix[4 + 1] = values[5];
47
+ matrix[4 + 2] = values[6];
48
+ matrix[4 + 3] = values[7];
49
+ matrix[2 * 4] = values[8];
50
50
  matrix[2 * 4 + 1] = values[9];
51
51
  matrix[2 * 4 + 2] = values[10];
52
52
  matrix[2 * 4 + 3] = values[11];
53
- matrix[3 * 4 + 0] = values[12];
53
+ matrix[3 * 4] = values[12];
54
54
  matrix[3 * 4 + 1] = values[13];
55
55
  matrix[3 * 4 + 2] = values[14];
56
56
  matrix[3 * 4 + 3] = values[15];
@@ -75,11 +75,11 @@ function serialize(matrix) {
75
75
  typ: EnumToken.FunctionTokenType,
76
76
  val: 'matrix',
77
77
  chi: [
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],
78
+ matrix[0],
79
+ matrix[1],
80
+ matrix[4],
81
+ matrix[4 + 1],
82
+ matrix[3 * 4],
83
83
  matrix[3 * 4 + 1]
84
84
  ].reduce((acc, t) => {
85
85
  if (acc.length > 0) {