@tbela99/css-parser 1.3.3 → 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 (46) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +20 -17
  3. package/dist/index-umd-web.js +1031 -571
  4. package/dist/index.cjs +1031 -566
  5. package/dist/index.d.ts +247 -171
  6. package/dist/lib/ast/expand.js +5 -10
  7. package/dist/lib/ast/features/calc.js +3 -2
  8. package/dist/lib/ast/features/inlinecssvariables.js +5 -3
  9. package/dist/lib/ast/features/prefix.js +1 -1
  10. package/dist/lib/ast/features/shorthand.js +1 -0
  11. package/dist/lib/ast/features/transform.js +13 -19
  12. package/dist/lib/ast/minify.js +5 -2
  13. package/dist/lib/ast/transform/compute.js +2 -4
  14. package/dist/lib/ast/transform/matrix.js +20 -20
  15. package/dist/lib/ast/transform/minify.js +105 -12
  16. package/dist/lib/ast/transform/rotate.js +11 -11
  17. package/dist/lib/ast/transform/scale.js +6 -6
  18. package/dist/lib/ast/transform/skew.js +4 -4
  19. package/dist/lib/ast/transform/translate.js +3 -3
  20. package/dist/lib/ast/transform/utils.js +30 -37
  21. package/dist/lib/ast/types.js +14 -2
  22. package/dist/lib/ast/walk.js +61 -49
  23. package/dist/lib/fs/resolve.js +6 -3
  24. package/dist/lib/parser/declaration/list.js +3 -1
  25. package/dist/lib/parser/parse.js +345 -305
  26. package/dist/lib/parser/tokenize.js +11 -13
  27. package/dist/lib/renderer/render.js +2 -2
  28. package/dist/lib/syntax/syntax.js +36 -18
  29. package/dist/lib/validation/at-rules/container.js +11 -0
  30. package/dist/lib/validation/at-rules/counter-style.js +11 -0
  31. package/dist/lib/validation/at-rules/font-feature-values.js +11 -0
  32. package/dist/lib/validation/at-rules/keyframes.js +11 -0
  33. package/dist/lib/validation/at-rules/layer.js +11 -0
  34. package/dist/lib/validation/at-rules/media.js +11 -0
  35. package/dist/lib/validation/at-rules/page-margin-box.js +11 -0
  36. package/dist/lib/validation/at-rules/page.js +11 -0
  37. package/dist/lib/validation/at-rules/supports.js +11 -0
  38. package/dist/lib/validation/at-rules/when.js +11 -0
  39. package/dist/lib/validation/config.js +0 -2
  40. package/dist/lib/validation/config.json.js +21 -1
  41. package/dist/lib/validation/parser/parse.js +53 -2
  42. package/dist/lib/validation/syntax.js +199 -36
  43. package/dist/node.js +17 -12
  44. package/dist/web.js +11 -11
  45. package/package.json +6 -3
  46. package/dist/lib/validation/parser/types.js +0 -54
@@ -16,14 +16,11 @@ import '../syntax/color/utils/constants.js';
16
16
  */
17
17
  function expand(ast) {
18
18
  const result = { ...ast, chi: [] };
19
- // @ts-ignore
20
19
  for (let i = 0; i < ast.chi.length; i++) {
21
- // @ts-ignore
22
20
  const node = ast.chi[i];
23
21
  if (node.typ == EnumToken.RuleNodeType) {
24
22
  // @ts-ignore
25
23
  result.chi.push(...expandRule(node));
26
- // i += expanded.length - 1;
27
24
  }
28
25
  else if (node.typ == EnumToken.AtRuleNodeType && 'chi' in node) {
29
26
  let hasRule = false;
@@ -38,6 +35,10 @@ function expand(ast) {
38
35
  // @ts-ignore
39
36
  result.chi.push({ ...(hasRule ? expand(node) : node) });
40
37
  }
38
+ else {
39
+ // @ts-ignore
40
+ result.chi.push(node);
41
+ }
41
42
  }
42
43
  return result;
43
44
  }
@@ -220,13 +221,7 @@ function replaceCompoundLiteral(selector, replace) {
220
221
  return 1;
221
222
  }
222
223
  return b == '&' ? -1 : 0;
223
- }).reduce((acc, curr) => {
224
- // if (acc.length > 0 && curr == '&' && (replace.charAt(0) != '.' || replace.includes(' '))) {
225
- //
226
- // return acc + ':is(' + replace + ')';
227
- // }
228
- return acc + (curr == '&' ? replace : curr);
229
- }, '');
224
+ }).reduce((acc, curr) => acc + (curr == '&' ? replace : curr), '');
230
225
  }
231
226
 
232
227
  export { expand, replaceCompound };
@@ -1,5 +1,5 @@
1
1
  import { EnumToken } from '../types.js';
2
- import { walkValues, WalkerValueEvent, WalkerOptionEnum } from '../walk.js';
2
+ import { walkValues, WalkerEvent, WalkerOptionEnum } from '../walk.js';
3
3
  import { evaluate } from '../math/expression.js';
4
4
  import { renderToken } from '../../renderer/render.js';
5
5
  import '../../renderer/sourcemap/lib/encode.js';
@@ -11,6 +11,7 @@ import '../../parser/utils/config.js';
11
11
  import { FeatureWalkMode } from './type.js';
12
12
 
13
13
  class ComputeCalcExpressionFeature {
14
+ accept = new Set([EnumToken.RuleNodeType, EnumToken.AtRuleNodeType]);
14
15
  get ordering() {
15
16
  return 1;
16
17
  }
@@ -33,7 +34,7 @@ class ComputeCalcExpressionFeature {
33
34
  }
34
35
  const set = new Set;
35
36
  for (const { value, parent } of walkValues(node.val, node, {
36
- event: WalkerValueEvent.Enter,
37
+ event: WalkerEvent.Enter,
37
38
  // @ts-ignore
38
39
  fn(node, parent) {
39
40
  if (parent != null &&
@@ -52,6 +52,7 @@ function replace(node, variableScope) {
52
52
  }
53
53
  }
54
54
  class InlineCssVariablesFeature {
55
+ accept = new Set([EnumToken.RuleNodeType, EnumToken.AtRuleNodeType]);
55
56
  get ordering() {
56
57
  return 0;
57
58
  }
@@ -65,9 +66,10 @@ class InlineCssVariablesFeature {
65
66
  }
66
67
  }
67
68
  run(ast, options = {}, parent, context) {
68
- if (!('chi' in ast)) {
69
- return null;
70
- }
69
+ // if (!('chi' in ast)) {
70
+ //
71
+ // return null;
72
+ // }
71
73
  if (!('variableScope' in context)) {
72
74
  context.variableScope = new Map;
73
75
  }
@@ -1,6 +1,5 @@
1
1
  import { EnumToken, SyntaxValidationResult } from '../types.js';
2
2
  import { getSyntaxConfig } from '../../validation/config.js';
3
- import '../../validation/parser/types.js';
4
3
  import '../../validation/parser/parse.js';
5
4
  import { splitRule } from '../minify.js';
6
5
  import { walkValues } from '../walk.js';
@@ -121,6 +120,7 @@ class ComputePrefixFeature {
121
120
  }
122
121
  }
123
122
  }
123
+ // @ts-ignore
124
124
  if (SyntaxValidationResult.Valid == evaluateSyntax({ ...node, val: nodes }, {}).valid) {
125
125
  node.val = nodes;
126
126
  }
@@ -10,6 +10,7 @@ import '../../renderer/sourcemap/lib/encode.js';
10
10
  import { FeatureWalkMode } from './type.js';
11
11
 
12
12
  class ComputeShorthandFeature {
13
+ accept = new Set([EnumToken.RuleNodeType, EnumToken.AtRuleNodeType, EnumToken.KeyFramesRuleNodeType]);
13
14
  get ordering() {
14
15
  return 3;
15
16
  }
@@ -9,10 +9,11 @@ import '../../syntax/color/utils/constants.js';
9
9
  import { filterValues, renderToken } from '../../renderer/render.js';
10
10
  import '../../renderer/sourcemap/lib/encode.js';
11
11
  import { compute } from '../transform/compute.js';
12
- import { eqMatrix } from '../transform/minify.js';
12
+ import { minifyTransformFunctions, eqMatrix } from '../transform/minify.js';
13
13
  import { FeatureWalkMode } from './type.js';
14
14
 
15
15
  class TransformCssFeature {
16
+ accept = new Set([EnumToken.RuleNodeType, EnumToken.KeyFramesRuleNodeType]);
16
17
  get ordering() {
17
18
  return 4;
18
19
  }
@@ -39,28 +40,21 @@ class TransformCssFeature {
39
40
  if (node.typ != EnumToken.DeclarationNodeType || !node.nam.match(/^(-[a-z]+-)?transform$/)) {
40
41
  continue;
41
42
  }
42
- const children = node.val.reduce((acc, curr) => {
43
- if (curr.typ == EnumToken.FunctionTokenType && 'skew' == curr.val.toLowerCase()) {
44
- if (curr.chi.length == 3) {
45
- if (curr.chi[2].val == 0) {
46
- curr.chi.length = 1;
47
- curr.val = 'skew';
48
- }
49
- else if (curr.chi[0].val == 0) {
50
- curr.chi = [curr.chi[2]];
51
- curr.val = 'skewY';
52
- }
53
- }
54
- }
55
- acc.push(curr);
56
- return acc;
57
- }, []);
43
+ const children = [];
44
+ for (const child of node.val) {
45
+ children.push(child.typ == EnumToken.FunctionTokenType ? minifyTransformFunctions(child) : child);
46
+ }
58
47
  consumeWhitespace(children);
59
- let { matrix, cumulative, minified } = compute(children) ?? {};
48
+ let { matrix, cumulative, minified } = compute(children) ?? {
49
+ matrix: null,
50
+ cumulative: null,
51
+ minified: null
52
+ };
60
53
  if (matrix == null || cumulative == null || minified == null) {
54
+ node.val = children;
61
55
  continue;
62
56
  }
63
- let r = [filterValues(node.val.slice())];
57
+ let r = [filterValues(children)];
64
58
  if (eqMatrix(matrix, cumulative)) {
65
59
  r.push(cumulative);
66
60
  }
@@ -61,7 +61,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
61
61
  }
62
62
  replacement = parent;
63
63
  for (const feature of options.features) {
64
- if ((feature.processMode & FeatureWalkMode.Pre) === 0) {
64
+ if ((feature.processMode & FeatureWalkMode.Pre) === 0 || (feature.accept != null && !feature.accept.has(parent.typ))) {
65
65
  continue;
66
66
  }
67
67
  const result = feature.run(replacement, options, parent.parent ?? ast, context, FeatureWalkMode.Pre);
@@ -100,7 +100,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
100
100
  replacement = parent;
101
101
  if (postprocess) {
102
102
  for (const feature of options.features) {
103
- if ((feature.processMode & FeatureWalkMode.Post) === 0) {
103
+ if ((feature.processMode & FeatureWalkMode.Post) === 0 || (feature.accept != null && !feature.accept.has(parent.typ))) {
104
104
  continue;
105
105
  }
106
106
  const result = feature.run(replacement, options, parent.parent ?? ast, context, FeatureWalkMode.Post);
@@ -231,6 +231,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
231
231
  continue;
232
232
  }
233
233
  if (previous?.typ == EnumToken.AtRuleNodeType &&
234
+ node.nam != 'font-face' &&
234
235
  previous.nam == node.nam &&
235
236
  previous.val == node.val) {
236
237
  if ('chi' in node) {
@@ -379,7 +380,9 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
379
380
  break;
380
381
  }
381
382
  if (shouldMerge) {
383
+ // @ts-ignore
382
384
  if (((node.typ == EnumToken.RuleNodeType || node.typ == EnumToken.KeyFramesRuleNodeType) && node.sel == previous.sel) ||
385
+ // @ts-ignore
383
386
  (node.typ == EnumToken.AtRuleNodeType) && node.val != 'font-face' && node.val == previous.val) {
384
387
  // @ts-ignore
385
388
  node.chi.unshift(...previous.chi);
@@ -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) {
@@ -156,10 +156,6 @@ function minify(matrix) {
156
156
  }
157
157
  }
158
158
  if (transforms.has('skew')) {
159
- // if (round(decomposed.skew[0]) == 0) {
160
- //
161
- // skew.delete('x');
162
- // }
163
159
  if (round(decomposed.skew[1]) == 0) {
164
160
  skew.delete('y');
165
161
  }
@@ -199,7 +195,7 @@ function minify(matrix) {
199
195
  scales.delete('x');
200
196
  }
201
197
  if (scales.size == 1) {
202
- let prefix = scales.has('x') ? '' : scales.has('y') ? 'Y' : 'Z';
198
+ let prefix = scales.has('x') ? 'X' : scales.has('y') ? 'Y' : 'Z';
203
199
  result.push({
204
200
  typ: EnumToken.FunctionTokenType,
205
201
  val: 'scale' + prefix,
@@ -242,13 +238,9 @@ function minify(matrix) {
242
238
  ] : result;
243
239
  }
244
240
  function eqMatrix(a, b) {
245
- // console.error(JSON.stringify({a, b}, null, 1));
246
241
  let mat = identity();
247
242
  let tmp = identity();
248
- // @ts-ignore
249
243
  const data = (Array.isArray(a) ? a : parseMatrix(a));
250
- // toZero(data);
251
- // console.error({data});
252
244
  for (const transform of b) {
253
245
  tmp = computeMatrix([transform], identity());
254
246
  if (tmp == null) {
@@ -256,8 +248,6 @@ function eqMatrix(a, b) {
256
248
  }
257
249
  mat = multiply(mat, tmp);
258
250
  }
259
- // toZero(mat);
260
- // console.error({mat});
261
251
  if (mat == null) {
262
252
  return false;
263
253
  }
@@ -270,5 +260,108 @@ function eqMatrix(a, b) {
270
260
  }
271
261
  return true;
272
262
  }
263
+ function minifyTransformFunctions(transform) {
264
+ const name = transform.val.toLowerCase();
265
+ if ('skewx' == name) {
266
+ transform.val = 'skew';
267
+ return transform;
268
+ }
269
+ if (!['translate', 'translate3d', 'scale', 'scale3d'].includes(name)) {
270
+ return transform;
271
+ }
272
+ const values = [];
273
+ for (const token of transform.chi) {
274
+ if (token.typ == EnumToken.CommentTokenType || token.typ == EnumToken.WhitespaceTokenType || token.typ == EnumToken.CommaTokenType) {
275
+ continue;
276
+ }
277
+ if (![EnumToken.NumberTokenType, EnumToken.LengthTokenType, EnumToken.AngleTokenType, EnumToken.PercentageTokenType].includes(token.typ)) {
278
+ return transform;
279
+ }
280
+ if (token.typ == EnumToken.PercentageTokenType && typeof token.val == 'number' && name.startsWith('scale')) {
281
+ Object.assign(token, { typ: EnumToken.NumberTokenType, val: token.val / 100 });
282
+ }
283
+ values.push(token);
284
+ }
285
+ if ((name == 'translate' || name == 'scale') && values.length > 2) {
286
+ return transform;
287
+ }
288
+ const ignoredValue = name.startsWith('scale') ? 1 : 0;
289
+ const t = new Set(['x', 'y', 'z']);
290
+ let i = 3;
291
+ while (i--) {
292
+ if (values.length <= i || values[i].val == ignoredValue) {
293
+ t.delete(i == 0 ? 'x' : i == 1 ? 'y' : 'z');
294
+ }
295
+ }
296
+ if (name == 'translate3d' || name == 'translate') {
297
+ if (t.size == 0) {
298
+ return {
299
+ typ: EnumToken.FunctionTokenType,
300
+ val: 'translate',
301
+ chi: [
302
+ { typ: EnumToken.NumberTokenType, val: 0 }
303
+ ]
304
+ };
305
+ }
306
+ if (t.size == 1) {
307
+ return {
308
+ typ: EnumToken.FunctionTokenType,
309
+ val: 'translate' + (t.has('x') ? '' : t.has('y') ? 'Y' : 'Z'),
310
+ chi: [
311
+ values[t.has('x') ? 0 : t.has('y') ? 1 : 2]
312
+ ]
313
+ };
314
+ }
315
+ if (t.size == 2) {
316
+ if (t.has('z')) {
317
+ return transform;
318
+ }
319
+ return {
320
+ typ: EnumToken.FunctionTokenType,
321
+ val: 'translate',
322
+ chi: [
323
+ values[0],
324
+ { typ: EnumToken.CommaTokenType },
325
+ values[1]
326
+ ]
327
+ };
328
+ }
329
+ }
330
+ if (name == 'scale3d' || name == 'scale') {
331
+ if (t.size == 0) {
332
+ return {
333
+ typ: EnumToken.FunctionTokenType,
334
+ val: 'scale',
335
+ chi: [
336
+ { typ: EnumToken.NumberTokenType, val: 1 }
337
+ ]
338
+ };
339
+ }
340
+ if (t.size == 1) {
341
+ return {
342
+ typ: EnumToken.FunctionTokenType,
343
+ val: 'scale' + (t.has('x') ? 'X' : t.has('y') ? 'Y' : 'Z'),
344
+ chi: [
345
+ values[t.has('x') ? 0 : t.has('y') ? 1 : 2]
346
+ ]
347
+ };
348
+ }
349
+ if (t.size == 2) {
350
+ if (t.has('z')) {
351
+ return transform;
352
+ }
353
+ return {
354
+ typ: EnumToken.FunctionTokenType,
355
+ val: 'scale',
356
+ chi: [
357
+ values[0],
358
+ { typ: EnumToken.CommaTokenType },
359
+ values[1]
360
+ ]
361
+ };
362
+ }
363
+ }
364
+ return transform;
365
+ }
273
366
 
274
- export { eqMatrix, minify };
367
+ export { eqMatrix, minify, minifyTransformFunctions };
@@ -17,23 +17,23 @@ function rotate3D(angle, x, y, z, from) {
17
17
  x *= unit;
18
18
  y *= unit;
19
19
  z *= unit;
20
- matrix[0 * 4 + 0] = 1 - 2 * (y * y + z * z) * sq;
21
- matrix[0 * 4 + 1] = 2 * (x * y * sq + z * sc);
22
- matrix[0 * 4 + 2] = 2 * (x * z * sq - y * sc);
23
- matrix[1 * 4 + 0] = 2 * (x * y * sq - z * sc);
24
- matrix[1 * 4 + 1] = 1 - 2 * (x * x + z * z) * sq;
25
- matrix[1 * 4 + 2] = 2 * (y * z * sq + x * sc);
26
- matrix[2 * 4 + 0] = 2 * (x * z * sq + y * sc);
20
+ matrix[0] = 1 - 2 * (y * y + z * z) * sq;
21
+ matrix[1] = 2 * (x * y * sq + z * sc);
22
+ matrix[2] = 2 * (x * z * sq - y * sc);
23
+ matrix[4] = 2 * (x * y * sq - z * sc);
24
+ matrix[4 + 1] = 1 - 2 * (x * x + z * z) * sq;
25
+ matrix[4 + 2] = 2 * (y * z * sq + x * sc);
26
+ matrix[2 * 4] = 2 * (x * z * sq + y * sc);
27
27
  matrix[2 * 4 + 1] = 2 * (y * z * sq - x * sc);
28
28
  matrix[2 * 4 + 2] = 1 - 2 * (x * x + y * y) * sq;
29
29
  return multiply(from, matrix);
30
30
  }
31
31
  function rotate(angle, from) {
32
32
  const matrix = identity();
33
- matrix[0 * 4 + 0] = Math.cos(angle);
34
- matrix[0 * 4 + 1] = Math.sin(angle);
35
- matrix[1 * 4 + 0] = -Math.sin(angle);
36
- matrix[1 * 4 + 1] = Math.cos(angle);
33
+ matrix[0] = Math.cos(angle);
34
+ matrix[1] = Math.sin(angle);
35
+ matrix[4] = -Math.sin(angle);
36
+ matrix[4 + 1] = Math.cos(angle);
37
37
  return multiply(from, matrix);
38
38
  }
39
39
 
@@ -2,12 +2,12 @@ import { identity, multiply } from './utils.js';
2
2
 
3
3
  function scaleX(x, from) {
4
4
  const matrix = identity();
5
- matrix[0 * 4 + 0] = x;
5
+ matrix[0] = x;
6
6
  return multiply(from, matrix);
7
7
  }
8
8
  function scaleY(y, from) {
9
9
  const matrix = identity();
10
- matrix[1 * 4 + 1] = y;
10
+ matrix[4 + 1] = y;
11
11
  return multiply(from, matrix);
12
12
  }
13
13
  function scaleZ(z, from) {
@@ -17,14 +17,14 @@ function scaleZ(z, from) {
17
17
  }
18
18
  function scale(x, y, from) {
19
19
  const matrix = identity();
20
- matrix[0 * 4 + 0] = x;
21
- matrix[1 * 4 + 1] = y;
20
+ matrix[0] = x;
21
+ matrix[4 + 1] = y;
22
22
  return multiply(from, matrix);
23
23
  }
24
24
  function scale3d(x, y, z, from) {
25
25
  const matrix = identity();
26
- matrix[0 * 4 + 0] = x;
27
- matrix[1 * 4 + 1] = y;
26
+ matrix[0] = x;
27
+ matrix[4 + 1] = y;
28
28
  matrix[2 * 4 + 2] = z;
29
29
  return multiply(from, matrix);
30
30
  }
@@ -2,20 +2,20 @@ import { identity, multiply } from './utils.js';
2
2
 
3
3
  function skewX(x, from) {
4
4
  const matrix = identity();
5
- matrix[1 * 4 + 0] = Math.tan(x);
5
+ matrix[4] = Math.tan(x);
6
6
  return multiply(from, matrix);
7
7
  }
8
8
  function skewY(y, from) {
9
9
  const matrix = identity();
10
- matrix[0 * 4 + 1] = Math.tan(y);
10
+ matrix[1] = Math.tan(y);
11
11
  return multiply(from, matrix);
12
12
  }
13
13
  // convert angle to radian
14
14
  function skew(values, from) {
15
15
  const matrix = identity();
16
- matrix[1 * 4 + 0] = Math.tan(values[0]);
16
+ matrix[4] = Math.tan(values[0]);
17
17
  if (values.length > 1) {
18
- matrix[0 * 4 + 1] = Math.tan(values[1]);
18
+ matrix[1] = Math.tan(values[1]);
19
19
  }
20
20
  return multiply(from, matrix);
21
21
  }
@@ -2,7 +2,7 @@ import { identity, multiply } from './utils.js';
2
2
 
3
3
  function translateX(x, from) {
4
4
  const matrix = identity();
5
- matrix[3 * 4 + 0] = x;
5
+ matrix[3 * 4] = x;
6
6
  return multiply(from, matrix);
7
7
  }
8
8
  function translateY(y, from) {
@@ -17,13 +17,13 @@ function translateZ(z, from) {
17
17
  }
18
18
  function translate(translate, from) {
19
19
  const matrix = identity();
20
- matrix[3 * 4 + 0] = translate[0];
20
+ matrix[3 * 4] = translate[0];
21
21
  matrix[3 * 4 + 1] = translate[1] ?? 0;
22
22
  return multiply(from, matrix);
23
23
  }
24
24
  function translate3d(translate, from) {
25
25
  const matrix = identity();
26
- matrix[3 * 4 + 0] = translate[0];
26
+ matrix[3 * 4] = translate[0];
27
27
  matrix[3 * 4 + 1] = translate[1];
28
28
  matrix[3 * 4 + 2] = translate[2];
29
29
  return multiply(from, matrix);