@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
@@ -36,26 +36,12 @@ function minify(matrix) {
36
36
  coordinates.delete(i == 0 ? 'x' : i == 1 ? 'y' : 'z');
37
37
  }
38
38
  }
39
- // if (coordinates.size == 3) {
40
- //
41
- // result.push({
42
- // typ: EnumToken.FunctionTokenType,
43
- // val: 'translate3d',
44
- // chi: [
45
- // {typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]) + '', unit: 'px'},
46
- // {typ: EnumToken.CommaTokenType},
47
- // {typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]) + '', unit: 'px'},
48
- // {typ: EnumToken.CommaTokenType},
49
- // {typ: EnumToken.LengthTokenType, val: round(decomposed.translate[2]) + '', unit: 'px'}
50
- // ]
51
- // })
52
- // } else
53
39
  if (coordinates.size == 1) {
54
40
  if (coordinates.has('x')) {
55
41
  result.push({
56
42
  typ: EnumToken.FunctionTokenType,
57
43
  val: 'translate',
58
- chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]) + '', unit: 'px' }]
44
+ chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: 'px' }]
59
45
  });
60
46
  }
61
47
  else {
@@ -64,7 +50,7 @@ function minify(matrix) {
64
50
  result.push({
65
51
  typ: EnumToken.FunctionTokenType,
66
52
  val: 'translate' + axis.toUpperCase(),
67
- chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[index]) + '', unit: 'px' }]
53
+ chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[index]), unit: 'px' }]
68
54
  });
69
55
  }
70
56
  }
@@ -75,15 +61,15 @@ function minify(matrix) {
75
61
  chi: [
76
62
  decomposed.translate[0] == 0 ? {
77
63
  typ: EnumToken.NumberTokenType,
78
- 'val': '0'
79
- } : { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]) + '', unit: 'px' },
64
+ val: 0
65
+ } : { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: 'px' },
80
66
  { typ: EnumToken.CommaTokenType },
81
67
  decomposed.translate[1] == 0 ? {
82
68
  typ: EnumToken.NumberTokenType,
83
- 'val': '0'
84
- } : { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]) + '', unit: 'px' },
69
+ val: 0
70
+ } : { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit: 'px' },
85
71
  { typ: EnumToken.CommaTokenType },
86
- { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[2]) + '', unit: 'px' }
72
+ { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[2]), unit: 'px' }
87
73
  ]
88
74
  });
89
75
  }
@@ -92,9 +78,9 @@ function minify(matrix) {
92
78
  typ: EnumToken.FunctionTokenType,
93
79
  val: 'translate',
94
80
  chi: [
95
- { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]) + '', unit: 'px' },
81
+ { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: 'px' },
96
82
  { typ: EnumToken.CommaTokenType },
97
- { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]) + '', unit: 'px' }
83
+ { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit: 'px' }
98
84
  ]
99
85
  });
100
86
  }
@@ -108,7 +94,7 @@ function minify(matrix) {
108
94
  chi: [
109
95
  {
110
96
  typ: EnumToken.AngleTokenType,
111
- val: '' + round(angle),
97
+ val: round(angle),
112
98
  unit: 'deg'
113
99
  }
114
100
  ]
@@ -121,7 +107,7 @@ function minify(matrix) {
121
107
  chi: [
122
108
  {
123
109
  typ: EnumToken.AngleTokenType,
124
- val: '' + round(angle),
110
+ val: round(angle),
125
111
  unit: 'deg'
126
112
  }
127
113
  ]
@@ -134,7 +120,7 @@ function minify(matrix) {
134
120
  chi: [
135
121
  {
136
122
  typ: EnumToken.AngleTokenType,
137
- val: '' + round(angle),
123
+ val: round(angle),
138
124
  unit: 'deg'
139
125
  }
140
126
  ]
@@ -147,22 +133,22 @@ function minify(matrix) {
147
133
  chi: [
148
134
  {
149
135
  typ: EnumToken.NumberTokenType,
150
- val: '' + round(x)
136
+ val: round(x)
151
137
  },
152
138
  { typ: EnumToken.CommaTokenType },
153
139
  {
154
140
  typ: EnumToken.NumberTokenType,
155
- val: '' + round(y)
141
+ val: round(y)
156
142
  },
157
143
  { typ: EnumToken.CommaTokenType },
158
144
  {
159
145
  typ: EnumToken.NumberTokenType,
160
- val: '' + round(z)
146
+ val: round(z)
161
147
  },
162
148
  { typ: EnumToken.CommaTokenType },
163
149
  {
164
150
  typ: EnumToken.AngleTokenType,
165
- val: '' + round(angle),
151
+ val: round(angle),
166
152
  unit: 'deg'
167
153
  }
168
154
  ]
@@ -185,7 +171,7 @@ function minify(matrix) {
185
171
  typ: EnumToken.FunctionTokenType,
186
172
  val: 'skew' + (skew.has('x') ? '' : 'Y'),
187
173
  chi: [
188
- { typ: EnumToken.AngleTokenType, val: '' + round(decomposed.skew[0]), unit: 'deg' }
174
+ { typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: 'deg' }
189
175
  ]
190
176
  });
191
177
  }
@@ -194,9 +180,9 @@ function minify(matrix) {
194
180
  typ: EnumToken.FunctionTokenType,
195
181
  val: 'skew',
196
182
  chi: [
197
- { typ: EnumToken.AngleTokenType, val: '' + round(decomposed.skew[0]), unit: 'deg' },
183
+ { typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: 'deg' },
198
184
  { typ: EnumToken.CommaTokenType },
199
- { typ: EnumToken.AngleTokenType, val: '' + round(decomposed.skew[1]), unit: 'deg' }
185
+ { typ: EnumToken.AngleTokenType, val: round(decomposed.skew[1]), unit: 'deg' }
200
186
  ]
201
187
  });
202
188
  }
@@ -218,7 +204,7 @@ function minify(matrix) {
218
204
  typ: EnumToken.FunctionTokenType,
219
205
  val: 'scale' + prefix,
220
206
  chi: [
221
- { typ: EnumToken.NumberTokenType, val: '' + round(prefix == 'Z' ? sz : prefix == 'Y' ? sy : sx) }
207
+ { typ: EnumToken.NumberTokenType, val: round(prefix == 'Z' ? sz : prefix == 'Y' ? sy : sx) }
222
208
  ]
223
209
  });
224
210
  }
@@ -227,9 +213,9 @@ function minify(matrix) {
227
213
  typ: EnumToken.FunctionTokenType,
228
214
  val: 'scale',
229
215
  chi: [
230
- { typ: EnumToken.NumberTokenType, val: '' + round(sx) },
216
+ { typ: EnumToken.NumberTokenType, val: round(sx) },
231
217
  { typ: EnumToken.CommaTokenType },
232
- { typ: EnumToken.NumberTokenType, val: '' + round(sy) },
218
+ { typ: EnumToken.NumberTokenType, val: round(sy) },
233
219
  ]
234
220
  });
235
221
  }
@@ -238,25 +224,15 @@ function minify(matrix) {
238
224
  typ: EnumToken.FunctionTokenType,
239
225
  val: 'scale3d',
240
226
  chi: [
241
- { typ: EnumToken.NumberTokenType, val: '' + round(sx) },
227
+ { typ: EnumToken.NumberTokenType, val: round(sx) },
242
228
  { typ: EnumToken.CommaTokenType },
243
- { typ: EnumToken.NumberTokenType, val: '' + round(sy) },
229
+ { typ: EnumToken.NumberTokenType, val: round(sy) },
244
230
  { typ: EnumToken.CommaTokenType },
245
- { typ: EnumToken.NumberTokenType, val: '' + round(sz) }
231
+ { typ: EnumToken.NumberTokenType, val: round(sz) }
246
232
  ]
247
233
  });
248
234
  }
249
235
  }
250
- // if (transforms.has('perspective')) {
251
- //
252
- // result.push({
253
- // typ: EnumToken.FunctionTokenType,
254
- // val: 'perspective',
255
- // chi: [
256
- // {typ: EnumToken.Length, val: '' + round(1 / decomposed.perspective[2]), unit: 'px'},
257
- // ]
258
- // });
259
- // }
260
236
  // identity
261
237
  return result.length == 0 || (result.length == 1 && eqMatrix(identity(), result)) ? [
262
238
  {
@@ -266,10 +242,13 @@ function minify(matrix) {
266
242
  ] : result;
267
243
  }
268
244
  function eqMatrix(a, b) {
245
+ // console.error(JSON.stringify({a, b}, null, 1));
269
246
  let mat = identity();
270
247
  let tmp = identity();
271
248
  // @ts-ignore
272
- const data = Array.isArray(a) ? a : parseMatrix(a);
249
+ const data = (Array.isArray(a) ? a : parseMatrix(a));
250
+ // toZero(data);
251
+ // console.error({data});
273
252
  for (const transform of b) {
274
253
  tmp = computeMatrix([transform], identity());
275
254
  if (tmp == null) {
@@ -277,12 +256,14 @@ function eqMatrix(a, b) {
277
256
  }
278
257
  mat = multiply(mat, tmp);
279
258
  }
259
+ // toZero(mat);
260
+ // console.error({mat});
280
261
  if (mat == null) {
281
262
  return false;
282
263
  }
283
264
  for (let i = 0; i < 4; i++) {
284
265
  for (let j = 0; j < 4; j++) {
285
- if (Math.abs(mat[i][j] - data[i][j]) > epsilon) {
266
+ if (Math.abs(mat[i * 4 + j] - data[i * 4 + j]) > epsilon) {
286
267
  return false;
287
268
  }
288
269
  }
@@ -3,7 +3,7 @@ import { identity, multiply } from './utils.js';
3
3
  function perspective(x, from) {
4
4
  const matrix = identity();
5
5
  // @ts-ignore
6
- matrix[2][3] = typeof x == 'object' && x.val == 'none' ? 0 : x == 0 ? Number.NEGATIVE_INFINITY : -1 / x;
6
+ matrix[2 * 4 + 3] = typeof x == 'object' && x.val == 'none' ? 0 : x == 0 ? Number.NEGATIVE_INFINITY : -1 / x;
7
7
  return multiply(from, matrix);
8
8
  }
9
9
 
@@ -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][0] = 1 - 2 * (y * y + z * z) * sq;
21
- matrix[0][1] = 2 * (x * y * sq + z * sc);
22
- matrix[0][2] = 2 * (x * z * sq - y * sc);
23
- matrix[1][0] = 2 * (x * y * sq - z * sc);
24
- matrix[1][1] = 1 - 2 * (x * x + z * z) * sq;
25
- matrix[1][2] = 2 * (y * z * sq + x * sc);
26
- matrix[2][0] = 2 * (x * z * sq + y * sc);
27
- matrix[2][1] = 2 * (y * z * sq - x * sc);
28
- matrix[2][2] = 1 - 2 * (x * x + y * y) * sq;
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);
27
+ matrix[2 * 4 + 1] = 2 * (y * z * sq - x * sc);
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][0] = Math.cos(angle);
34
- matrix[0][1] = Math.sin(angle);
35
- matrix[1][0] = -Math.sin(angle);
36
- matrix[1][1] = Math.cos(angle);
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);
37
37
  return multiply(from, matrix);
38
38
  }
39
39
 
@@ -2,30 +2,30 @@ import { identity, multiply } from './utils.js';
2
2
 
3
3
  function scaleX(x, from) {
4
4
  const matrix = identity();
5
- matrix[0][0] = x;
5
+ matrix[0 * 4 + 0] = x;
6
6
  return multiply(from, matrix);
7
7
  }
8
8
  function scaleY(y, from) {
9
9
  const matrix = identity();
10
- matrix[1][1] = y;
10
+ matrix[1 * 4 + 1] = y;
11
11
  return multiply(from, matrix);
12
12
  }
13
13
  function scaleZ(z, from) {
14
14
  const matrix = identity();
15
- matrix[2][2] = z;
15
+ matrix[2 * 4 + 2] = z;
16
16
  return multiply(from, matrix);
17
17
  }
18
18
  function scale(x, y, from) {
19
19
  const matrix = identity();
20
- matrix[0][0] = x;
21
- matrix[1][1] = y;
20
+ matrix[0 * 4 + 0] = x;
21
+ matrix[1 * 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][0] = x;
27
- matrix[1][1] = y;
28
- matrix[2][2] = z;
26
+ matrix[0 * 4 + 0] = x;
27
+ matrix[1 * 4 + 1] = y;
28
+ matrix[2 * 4 + 2] = z;
29
29
  return multiply(from, matrix);
30
30
  }
31
31
 
@@ -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][0] = Math.tan(x);
5
+ matrix[1 * 4 + 0] = 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][1] = Math.tan(y);
10
+ matrix[0 * 4 + 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][0] = Math.tan(values[0]);
16
+ matrix[1 * 4 + 0] = Math.tan(values[0]);
17
17
  if (values.length > 1) {
18
- matrix[0][1] = Math.tan(values[1]);
18
+ matrix[0 * 4 + 1] = Math.tan(values[1]);
19
19
  }
20
20
  return multiply(from, matrix);
21
21
  }
@@ -2,30 +2,30 @@ import { identity, multiply } from './utils.js';
2
2
 
3
3
  function translateX(x, from) {
4
4
  const matrix = identity();
5
- matrix[3][0] = x;
5
+ matrix[3 * 4 + 0] = x;
6
6
  return multiply(from, matrix);
7
7
  }
8
8
  function translateY(y, from) {
9
9
  const matrix = identity();
10
- matrix[3][1] = y;
10
+ matrix[3 * 4 + 1] = y;
11
11
  return multiply(from, matrix);
12
12
  }
13
13
  function translateZ(z, from) {
14
14
  const matrix = identity();
15
- matrix[3][2] = z;
15
+ matrix[3 * 4 + 2] = z;
16
16
  return multiply(from, matrix);
17
17
  }
18
18
  function translate(translate, from) {
19
19
  const matrix = identity();
20
- matrix[3][0] = translate[0];
21
- matrix[3][1] = translate[1] ?? 0;
20
+ matrix[3 * 4 + 0] = translate[0];
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][0] = translate[0];
27
- matrix[3][1] = translate[1];
28
- matrix[3][2] = translate[2];
26
+ matrix[3 * 4 + 0] = translate[0];
27
+ matrix[3 * 4 + 1] = translate[1];
28
+ matrix[3 * 4 + 2] = translate[2];
29
29
  return multiply(from, matrix);
30
30
  }
31
31
 
@@ -1,9 +1,8 @@
1
1
  const epsilon = 1e-5;
2
2
  function identity() {
3
- return [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
3
+ return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
4
4
  }
5
5
  function pLength(point) {
6
- // Calcul de la norme euclidienne
7
6
  return Math.sqrt(point[0] * point[0] + point[1] * point[1] + point[2] * point[2]);
8
7
  }
9
8
  function normalize(point) {
@@ -12,23 +11,19 @@ function normalize(point) {
12
11
  return norm === 0 ? [0, 0, 0] : [x / norm, y / norm, z / norm];
13
12
  }
14
13
  function dot(point1, point2) {
15
- // if (point1.length === 4 && point2.length === 4) {
16
- //
17
- // return point1[0] * point2[0] + point1[1] * point2[1] + point1[2] * point2[2] + point1[3] * point2[3];
18
- // }
19
- let result = 0;
20
- for (let i = 0; i < point1.length; i++) {
21
- result += point1[i] * point2[i];
14
+ if (point1.length === 4 && point2.length === 4) {
15
+ return point1[0] * point2[0] + point1[1] * point2[1] + point1[2] * point2[2] + point1[3] * point2[3];
22
16
  }
23
- return result;
24
- // return point1[0] * point2[0] + point1[1] * point2[1] + point1[2] * point2[2];
17
+ return point1[0] * point2[0] + point1[1] * point2[1] + point1[2] * point2[2];
25
18
  }
26
19
  function multiply(matrixA, matrixB) {
27
- let result = Array(4).fill(0).map(() => Array(4).fill(0));
20
+ let result = new Array(16).fill(0);
28
21
  for (let i = 0; i < 4; i++) {
29
22
  for (let j = 0; j < 4; j++) {
30
23
  for (let k = 0; k < 4; k++) {
31
- result[j][i] += matrixA[k][i] * matrixB[j][k];
24
+ // Utiliser l'indexation linéaire pour accéder aux éléments
25
+ // Pour une matrice 4x4, l'index est (row * 4 + col)
26
+ result[j * 4 + i] += matrixA[k * 4 + i] * matrixB[j * 4 + k];
32
27
  }
33
28
  }
34
29
  }
@@ -36,20 +31,17 @@ function multiply(matrixA, matrixB) {
36
31
  }
37
32
  function inverse(matrix) {
38
33
  // Create augmented matrix [matrix | identity]
39
- let augmented = matrix.map((row, i) => [
40
- ...row,
41
- ...(i === 0 ? [1, 0, 0, 0] :
42
- i === 1 ? [0, 1, 0, 0] :
43
- i === 2 ? [0, 0, 1, 0] :
44
- [0, 0, 0, 1])
45
- ]);
34
+ let augmented = [
35
+ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1,
36
+ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1
37
+ ];
46
38
  // Gaussian elimination with partial pivoting
47
39
  for (let col = 0; col < 4; col++) {
48
40
  // Find pivot row with maximum absolute value
49
41
  let maxRow = col;
50
- let maxVal = Math.abs(augmented[col][col]);
42
+ let maxVal = Math.abs(augmented[col * 4 + col]);
51
43
  for (let row = col + 1; row < 4; row++) {
52
- let val = Math.abs(augmented[row][col]);
44
+ let val = Math.abs(augmented[row * 4 + col]);
53
45
  if (val > maxVal) {
54
46
  maxVal = val;
55
47
  maxRow = row;
@@ -64,22 +56,22 @@ function inverse(matrix) {
64
56
  [augmented[col], augmented[maxRow]] = [augmented[maxRow], augmented[col]];
65
57
  }
66
58
  // Scale pivot row to make pivot element 1
67
- let pivot = augmented[col][col];
59
+ let pivot = augmented[col * 4 + col];
68
60
  for (let j = 0; j < 8; j++) {
69
- augmented[col][j] /= pivot;
61
+ augmented[col * 4 + j] /= pivot;
70
62
  }
71
63
  // Eliminate column in other rows
72
64
  for (let row = 0; row < 4; row++) {
73
65
  if (row !== col) {
74
- let factor = augmented[row][col];
66
+ let factor = augmented[row * 4 + col];
75
67
  for (let j = 0; j < 8; j++) {
76
- augmented[row][j] -= factor * augmented[col][j];
68
+ augmented[row * 4 + j] -= factor * augmented[col * 4 + j];
77
69
  }
78
70
  }
79
71
  }
80
72
  }
81
73
  // Extract the inverse from the right side of the augmented matrix
82
- return augmented.map(row => row.slice(4));
74
+ return augmented.slice(0, 16);
83
75
  }
84
76
  // function transpose(matrix: Matrix): Matrix {
85
77
  // // Crée une nouvelle matrice vide 4x4
@@ -103,7 +95,7 @@ function round(number) {
103
95
  // translate3d(25.9808px, 0, 15px ) rotateY(60deg) skewX(49.9999deg) scale(1, 1.2)
104
96
  // translate → rotate → skew → scale
105
97
  function decompose(original) {
106
- const matrix = original.flat();
98
+ const matrix = original.slice();
107
99
  // Normalize last row
108
100
  if (matrix[15] === 0) {
109
101
  return null;
@@ -120,7 +112,7 @@ function decompose(original) {
120
112
  perspectiveMatrix[11] = 0;
121
113
  perspectiveMatrix[15] = 1;
122
114
  // @ts-ignore
123
- const inverted = inverse(original.reduce((acc, row, i) => acc.concat([row.slice()]), []))?.flat?.();
115
+ const inverted = inverse(original.slice());
124
116
  if (!inverted) {
125
117
  return null;
126
118
  }
@@ -243,16 +235,16 @@ function toZero(v) {
243
235
  // https://drafts.csswg.org/css-transforms-1/#2d-matrix
244
236
  function is2DMatrix(matrix) {
245
237
  // m13,m14, m23, m24, m31, m32, m34, m43 are all 0
246
- return matrix[0][2] === 0 &&
247
- matrix[0][3] === 0 &&
248
- matrix[1][2] === 0 &&
249
- matrix[1][3] === 0 &&
250
- matrix[2][0] === 0 &&
251
- matrix[2][1] === 0 &&
252
- matrix[2][3] === 0 &&
253
- matrix[3][2] === 0 &&
254
- matrix[2][2] === 1 &&
255
- matrix[3][3] === 1;
238
+ return matrix[0 * 4 + 2] === 0 &&
239
+ matrix[0 * 4 + 3] === 0 &&
240
+ matrix[1 * 4 + 2] === 0 &&
241
+ matrix[1 * 4 + 3] === 0 &&
242
+ matrix[2 * 4 + 0] === 0 &&
243
+ matrix[2 * 4 + 1] === 0 &&
244
+ matrix[2 * 4 + 3] === 0 &&
245
+ matrix[3 * 4 + 2] === 0 &&
246
+ matrix[2 * 4 + 2] === 1 &&
247
+ matrix[3 * 4 + 3] === 1;
256
248
  }
257
249
 
258
250
  export { decompose, epsilon, identity, is2DMatrix, multiply, round, toZero };
@@ -1,8 +1,14 @@
1
+ /**
2
+ * syntax validation enum
3
+ */
1
4
  var SyntaxValidationResult;
2
5
  (function (SyntaxValidationResult) {
6
+ /** valid syntax */
3
7
  SyntaxValidationResult[SyntaxValidationResult["Valid"] = 0] = "Valid";
8
+ /** drop invalid syntax */
4
9
  SyntaxValidationResult[SyntaxValidationResult["Drop"] = 1] = "Drop";
5
- SyntaxValidationResult[SyntaxValidationResult["Lenient"] = 2] = "Lenient"; /* preserve unknown at-rules, declarations and pseudo-classes */
10
+ /** preserve unknown at-rules, declarations and pseudo-classes */
11
+ SyntaxValidationResult[SyntaxValidationResult["Lenient"] = 2] = "Lenient";
6
12
  })(SyntaxValidationResult || (SyntaxValidationResult = {}));
7
13
  /**
8
14
  * validation level enum
@@ -154,35 +160,118 @@ var EnumToken;
154
160
  EnumToken[EnumToken["TimingFunction"] = 17] = "TimingFunction";
155
161
  EnumToken[EnumToken["TimelineFunction"] = 16] = "TimelineFunction";
156
162
  })(EnumToken || (EnumToken = {}));
157
- // xyz-d65 is an alias for xyz
163
+ /**
164
+ * color types enum
165
+ */
158
166
  var ColorType;
159
167
  (function (ColorType) {
168
+ /**
169
+ * system colors
170
+ */
160
171
  ColorType[ColorType["SYS"] = 0] = "SYS";
172
+ /**
173
+ * deprecated system colors
174
+ */
161
175
  ColorType[ColorType["DPSYS"] = 1] = "DPSYS";
176
+ /**
177
+ * colors as literals
178
+ */
162
179
  ColorType[ColorType["LIT"] = 2] = "LIT";
180
+ /**
181
+ * colors as hex values
182
+ */
163
183
  ColorType[ColorType["HEX"] = 3] = "HEX";
184
+ /**
185
+ * colors as rgb values
186
+ */
164
187
  ColorType[ColorType["RGBA"] = 4] = "RGBA";
188
+ /**
189
+ * colors as hsl values
190
+ */
165
191
  ColorType[ColorType["HSLA"] = 5] = "HSLA";
192
+ /**
193
+ * colors as hwb values
194
+ */
166
195
  ColorType[ColorType["HWB"] = 6] = "HWB";
196
+ /**
197
+ * colors as cmyk values
198
+ */
167
199
  ColorType[ColorType["CMYK"] = 7] = "CMYK";
200
+ /**
201
+ * colors as oklab values
202
+ * */
168
203
  ColorType[ColorType["OKLAB"] = 8] = "OKLAB";
204
+ /**
205
+ * colors as oklch values
206
+ * */
169
207
  ColorType[ColorType["OKLCH"] = 9] = "OKLCH";
208
+ /**
209
+ * colors as lab values
210
+ */
170
211
  ColorType[ColorType["LAB"] = 10] = "LAB";
212
+ /**
213
+ * colors as lch values
214
+ */
171
215
  ColorType[ColorType["LCH"] = 11] = "LCH";
216
+ /**
217
+ * colors using color() function
218
+ */
172
219
  ColorType[ColorType["COLOR"] = 12] = "COLOR";
220
+ /**
221
+ * color using srgb values
222
+ */
173
223
  ColorType[ColorType["SRGB"] = 13] = "SRGB";
224
+ /**
225
+ * color using prophoto-rgb values
226
+ */
174
227
  ColorType[ColorType["PROPHOTO_RGB"] = 14] = "PROPHOTO_RGB";
228
+ /**
229
+ * color using a98-rgb values
230
+ */
175
231
  ColorType[ColorType["A98_RGB"] = 15] = "A98_RGB";
232
+ /**
233
+ * color using rec2020 values
234
+ */
176
235
  ColorType[ColorType["REC2020"] = 16] = "REC2020";
236
+ /**
237
+ * color using display-p3 values
238
+ */
177
239
  ColorType[ColorType["DISPLAY_P3"] = 17] = "DISPLAY_P3";
240
+ /**
241
+ * color using srgb-linear values
242
+ */
178
243
  ColorType[ColorType["SRGB_LINEAR"] = 18] = "SRGB_LINEAR";
244
+ /**
245
+ * color using xyz-d50 values
246
+ */
179
247
  ColorType[ColorType["XYZ_D50"] = 19] = "XYZ_D50";
248
+ /**
249
+ * color using xyz-d65 values
250
+ */
180
251
  ColorType[ColorType["XYZ_D65"] = 20] = "XYZ_D65";
252
+ /**
253
+ * light-dark() color function
254
+ */
181
255
  ColorType[ColorType["LIGHT_DARK"] = 21] = "LIGHT_DARK";
256
+ /**
257
+ * color-mix() color function
258
+ */
182
259
  ColorType[ColorType["COLOR_MIX"] = 22] = "COLOR_MIX";
260
+ /**
261
+ * alias for rgba
262
+ */
183
263
  ColorType[ColorType["RGB"] = 4] = "RGB";
264
+ /**
265
+ * alias for hsl
266
+ */
184
267
  ColorType[ColorType["HSL"] = 5] = "HSL";
268
+ /**
269
+ * alias for xyz-d65
270
+ */
185
271
  ColorType[ColorType["XYZ"] = 20] = "XYZ";
272
+ /**
273
+ * alias for cmyk
274
+ */
186
275
  ColorType[ColorType["DEVICE_CMYK"] = 7] = "DEVICE_CMYK";
187
276
  })(ColorType || (ColorType = {}));
188
277
 
@@ -15,7 +15,7 @@ function dedup(values) {
15
15
  while (i-- > 1) {
16
16
  const t = value[i];
17
17
  const k = value[i == 1 ? 0 : i % 2];
18
- if (t.val == k.val && t.val == '0') {
18
+ if (t.val == k.val && t.val == 0) {
19
19
  if ((t.typ == EnumToken.NumberTokenType && isLength(k)) ||
20
20
  (k.typ == EnumToken.NumberTokenType && isLength(t)) ||
21
21
  (isLength(k) || isLength(t))) {
@@ -52,7 +52,7 @@ class PropertySet {
52
52
  // @ts-ignore
53
53
  for (let token of this.declarations.get(this.config.shorthand).val) {
54
54
  // @ts-ignore
55
- if (this.config.types.some(t => token.typ == EnumToken[t]) || (token.typ == EnumToken.NumberTokenType && token.val == '0' &&
55
+ if (this.config.types.some(t => token.typ == EnumToken[t]) || (token.typ == EnumToken.NumberTokenType && token.val == 0 &&
56
56
  (this.config.types.includes('Length') ||
57
57
  this.config.types.includes('Angle') ||
58
58
  this.config.types.includes('Dimension')))) {