@tbela99/css-parser 2.1.0 → 2.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 (130) hide show
  1. package/CHANGELOG.md +66 -1
  2. package/README.md +14 -7
  3. package/architecture.png +0 -0
  4. package/dist/{src/lib/ast → ast}/arena-node.js +10 -10
  5. package/dist/{src/lib/ast → ast}/arena.js +304 -139
  6. package/dist/{src/lib/ast → ast}/cache.js +40 -24
  7. package/dist/{src/lib/ast → ast}/features/calc.js +11 -9
  8. package/dist/{src/lib/ast → ast}/features/if.js +6 -6
  9. package/dist/ast/features/index.d.ts +7 -0
  10. package/dist/{src/lib/ast → ast}/features/index.js +3 -2
  11. package/dist/{src/lib/ast → ast}/features/inlinecssvariables.js +12 -10
  12. package/dist/ast/features/mixin.js +953 -0
  13. package/dist/{src/lib/ast → ast}/features/prefix.js +39 -39
  14. package/dist/ast/features/shorthand.js +129 -0
  15. package/dist/ast/features/transform.js +188 -0
  16. package/dist/{src/lib/ast → ast}/features/type.js +2 -2
  17. package/dist/{src/lib/ast → ast}/math/expression.js +24 -24
  18. package/dist/{src/lib/ast → ast}/math/math.js +2 -2
  19. package/dist/{src/lib/ast → ast}/minify.js +745 -201
  20. package/dist/ast/mixins/custom-function.js +393 -0
  21. package/dist/ast/mixins/utils.js +53 -0
  22. package/dist/ast/mixins/variables.js +678 -0
  23. package/dist/ast/strings.js +910 -0
  24. package/dist/ast/transform/compute.js +560 -0
  25. package/dist/ast/transform/matrix.js +67 -0
  26. package/dist/ast/transform/minify.js +325 -0
  27. package/dist/ast/transform/perspective.js +24 -0
  28. package/dist/{src/lib/ast → ast}/transform/rotate.js +16 -7
  29. package/dist/ast/transform/scale.js +43 -0
  30. package/dist/ast/transform/skew.js +38 -0
  31. package/dist/ast/transform/translate.js +56 -0
  32. package/dist/ast/transform/utils.js +390 -0
  33. package/dist/{src/lib/ast → ast}/types.js +2 -2
  34. package/dist/{src/lib/ast → ast}/walk.js +2 -2
  35. package/dist/{src/data → data}/properties.json.js +86 -2
  36. package/dist/{src/data → data}/validation.json.js +30 -21
  37. package/dist/{src/lib/fs → fs}/resolve.js +2 -2
  38. package/dist/index-umd-web.js +19727 -10719
  39. package/dist/index.d.ts +738 -100
  40. package/dist/{src/node.js → node.js} +70 -52
  41. package/dist/{src/lib/parser → parser}/declaration/list.js +25 -8
  42. package/dist/{src/lib/parser → parser}/declaration/map.js +15 -15
  43. package/dist/{src/lib/parser → parser}/declaration/set.js +5 -5
  44. package/dist/{src/lib/parser → parser}/input.js +18 -3
  45. package/dist/{src/lib/parser → parser}/linesmap.js +2 -2
  46. package/dist/{src/lib/parser → parser}/parse.js +444 -278
  47. package/dist/{src/lib/parser → parser}/source.js +3 -3
  48. package/dist/{src/lib/parser → parser}/tokenize.js +480 -312
  49. package/dist/{src/lib/parser → parser}/utils/angle.js +3 -3
  50. package/dist/{src/lib/parser → parser}/utils/at-rule-container.js +12 -12
  51. package/dist/{src/lib/parser → parser}/utils/at-rule-font-feature-values.js +3 -3
  52. package/dist/{src/lib/parser → parser}/utils/at-rule-generic.js +7 -7
  53. package/dist/{src/lib/parser → parser}/utils/at-rule-import.js +10 -10
  54. package/dist/{src/lib/parser → parser}/utils/at-rule-media.js +14 -14
  55. package/dist/{src/lib/parser → parser}/utils/at-rule-support.js +9 -14
  56. package/dist/{src/lib/parser → parser}/utils/at-rule-when-else.js +6 -6
  57. package/dist/{src/lib/parser → parser}/utils/at-rule.js +3 -3
  58. package/dist/{src/lib/parser → parser}/utils/base64.js +2 -2
  59. package/dist/parser/utils/cache.js +53 -0
  60. package/dist/parser/utils/canonical.js +78 -0
  61. package/dist/parser/utils/codes.js +93 -0
  62. package/dist/{src/lib/parser → parser}/utils/config.js +3 -3
  63. package/dist/{src/lib/parser → parser}/utils/declaration.js +31 -26
  64. package/dist/{src/lib/parser → parser}/utils/eq.js +2 -2
  65. package/dist/{src/lib/parser → parser}/utils/hash.js +2 -2
  66. package/dist/{src/lib/parser → parser}/utils/selector.js +339 -87
  67. package/dist/{src/lib/parser → parser}/utils/text.js +2 -2
  68. package/dist/{src/lib/parser → parser}/utils/token.js +2 -2
  69. package/dist/{src/lib/parser → parser}/utils/type.js +9 -7
  70. package/dist/{src/lib/printer/sourcemap → printer}/lib/codec.js +2 -2
  71. package/dist/{src/lib/printer → printer}/render.js +582 -153
  72. package/dist/printer/result.js +148 -0
  73. package/dist/{src/lib/printer/sourcemap → printer}/sourcemap.js +4 -3
  74. package/dist/printer/writer.js +252 -0
  75. package/dist/{src/lib/syntax → syntax}/color/a98rgb.js +2 -2
  76. package/dist/{src/lib/syntax → syntax}/color/alpha.js +10 -10
  77. package/dist/{src/lib/syntax → syntax}/color/cmyk.js +2 -2
  78. package/dist/{src/lib/syntax → syntax}/color/color-mix.js +18 -18
  79. package/dist/{src/lib/syntax → syntax}/color/color.js +18 -18
  80. package/dist/{src/lib/syntax → syntax}/color/hex.js +3 -3
  81. package/dist/{src/lib/syntax → syntax}/color/hsl.js +2 -2
  82. package/dist/{src/lib/syntax → syntax}/color/hwb.js +2 -2
  83. package/dist/{src/lib/syntax → syntax}/color/lab.js +2 -2
  84. package/dist/{src/lib/syntax → syntax}/color/lch.js +2 -2
  85. package/dist/{src/lib/syntax → syntax}/color/oklab.js +2 -2
  86. package/dist/{src/lib/syntax → syntax}/color/oklch.js +3 -3
  87. package/dist/{src/lib/syntax → syntax}/color/p3.js +2 -2
  88. package/dist/{src/lib/syntax → syntax}/color/prophotorgb.js +2 -2
  89. package/dist/{src/lib/syntax → syntax}/color/rec2020.js +2 -2
  90. package/dist/{src/lib/syntax → syntax}/color/relative-color.js +14 -14
  91. package/dist/{src/lib/syntax → syntax}/color/rgb.js +4 -4
  92. package/dist/{src/lib/syntax → syntax}/color/srgb.js +5 -5
  93. package/dist/{src/lib/syntax → syntax}/color/utils/color-type.js +4 -4
  94. package/dist/{src/lib/syntax → syntax}/color/utils/colorspace.js +10 -10
  95. package/dist/{src/lib/syntax → syntax}/color/utils/components.js +5 -5
  96. package/dist/{src/lib/syntax → syntax}/color/utils/distance.js +2 -2
  97. package/dist/{src/lib/syntax → syntax}/color/utils/make-color.js +3 -3
  98. package/dist/{src/lib/syntax → syntax}/color/utils/matrix.js +2 -2
  99. package/dist/{src/lib/syntax → syntax}/color/xyz.js +2 -2
  100. package/dist/{src/lib/syntax → syntax}/color/xyzd50.js +2 -2
  101. package/dist/{src/lib/syntax → syntax}/constants.js +27 -4
  102. package/dist/{src/lib/syntax → syntax}/syntax.js +37 -29
  103. package/dist/{src/types.js → types.js} +2 -2
  104. package/dist/{src/utils → utils}/sync.js +12 -7
  105. package/dist/validation/compiled/builtins.js +32 -0
  106. package/dist/validation/compiled/runtime.js +705 -0
  107. package/dist/validation/compiled/syntaxes.js +1620 -0
  108. package/dist/{src/lib/validation → validation}/config.js +63 -16
  109. package/dist/validation/first.js +574 -0
  110. package/dist/{src/lib/validation → validation}/match.js +376 -161
  111. package/dist/{src/lib/validation → validation}/parser/parse.js +2 -2
  112. package/dist/{src/lib/validation → validation}/parser/typedef.js +2 -2
  113. package/dist/{src/lib/validation → validation}/utils/list.js +3 -19
  114. package/dist/version.js +13 -0
  115. package/dist/{src/web.js → web.js} +68 -55
  116. package/package.json +15 -13
  117. package/dist/package.json.js +0 -10
  118. package/dist/src/lib/ast/features/shorthand.js +0 -95
  119. package/dist/src/lib/ast/features/transform.js +0 -90
  120. package/dist/src/lib/ast/transform/compute.js +0 -362
  121. package/dist/src/lib/ast/transform/matrix.js +0 -88
  122. package/dist/src/lib/ast/transform/minify.js +0 -267
  123. package/dist/src/lib/ast/transform/perspective.js +0 -16
  124. package/dist/src/lib/ast/transform/scale.js +0 -39
  125. package/dist/src/lib/ast/transform/skew.js +0 -30
  126. package/dist/src/lib/ast/transform/translate.js +0 -39
  127. package/dist/src/lib/ast/transform/utils.js +0 -287
  128. package/dist/src/lib/parser/utils/cache.js +0 -54
  129. package/dist/types.d.ts +0 -21
  130. package/dist/utils/sync.d.ts +0 -16
@@ -0,0 +1,390 @@
1
+ /*
2
+ CSS parser, minifier and validator for node, deno, bun and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 2.3.0
6
+ License: MIT
7
+ */
8
+ import { epsilon } from '../../syntax/constants.js';
9
+
10
+ /**
11
+ * Matrix operations of the transform functions. The matrices are `Float64Array(16)` in column-major order.
12
+ *
13
+ * The operations write into matrices provided by the caller (no allocation): the computation of a transform list uses
14
+ * a few module level scratch matrices. The arithmetic is performed in the same order as the textbook formulas, the
15
+ * results do not depend on the buffers used.
16
+ *
17
+ * @module
18
+ * @internal
19
+ */
20
+ /**
21
+ * the identity matrix. must not be modified
22
+ */
23
+ const identityMatrix = new Float64Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
24
+ /**
25
+ * reset a matrix to the identity matrix
26
+ * @param matrix
27
+ */
28
+ function setIdentity(matrix) {
29
+ matrix.set(identityMatrix);
30
+ return matrix;
31
+ }
32
+ /**
33
+ * true if the values of the matrix are equal (`===`) to the values of the identity matrix
34
+ * @param matrix
35
+ */
36
+ function isIdentity(matrix) {
37
+ return (matrix[0] === 1 &&
38
+ matrix[1] === 0 &&
39
+ matrix[2] === 0 &&
40
+ matrix[3] === 0 &&
41
+ matrix[4] === 0 &&
42
+ matrix[5] === 1 &&
43
+ matrix[6] === 0 &&
44
+ matrix[7] === 0 &&
45
+ matrix[8] === 0 &&
46
+ matrix[9] === 0 &&
47
+ matrix[10] === 1 &&
48
+ matrix[11] === 0 &&
49
+ matrix[12] === 0 &&
50
+ matrix[13] === 0 &&
51
+ matrix[14] === 0 &&
52
+ matrix[15] === 1);
53
+ }
54
+ /**
55
+ * multiply two matrices: `result = matrixA × matrixB`. `result` can be one of the operands
56
+ * @param matrixA
57
+ * @param matrixB
58
+ * @param result
59
+ */
60
+ function multiplyInto(matrixA, matrixB, result) {
61
+ const a0 = matrixA[0];
62
+ const a1 = matrixA[1];
63
+ const a2 = matrixA[2];
64
+ const a3 = matrixA[3];
65
+ const a4 = matrixA[4];
66
+ const a5 = matrixA[5];
67
+ const a6 = matrixA[6];
68
+ const a7 = matrixA[7];
69
+ const a8 = matrixA[8];
70
+ const a9 = matrixA[9];
71
+ const a10 = matrixA[10];
72
+ const a11 = matrixA[11];
73
+ const a12 = matrixA[12];
74
+ const a13 = matrixA[13];
75
+ const a14 = matrixA[14];
76
+ const a15 = matrixA[15];
77
+ for (let column = 0; column < 16; column += 4) {
78
+ const b0 = matrixB[column];
79
+ const b1 = matrixB[column + 1];
80
+ const b2 = matrixB[column + 2];
81
+ const b3 = matrixB[column + 3];
82
+ result[column] = a0 * b0 + a4 * b1 + a8 * b2 + a12 * b3;
83
+ result[column + 1] = a1 * b0 + a5 * b1 + a9 * b2 + a13 * b3;
84
+ result[column + 2] = a2 * b0 + a6 * b1 + a10 * b2 + a14 * b3;
85
+ result[column + 3] = a3 * b0 + a7 * b1 + a11 * b2 + a15 * b3;
86
+ }
87
+ return result;
88
+ }
89
+ /**
90
+ * augmented matrix of {@link inverse}
91
+ */
92
+ const augmented = new Float64Array(32);
93
+ /**
94
+ * inverse of a matrix, used to extract the perspective. the result is a shared buffer (its first 16 values), valid
95
+ * until the next call
96
+ * @param matrix
97
+ */
98
+ function inverse(matrix) {
99
+ // Create augmented matrix [matrix | identity]
100
+ for (let row = 0; row < 4; row++) {
101
+ for (let j = 0; j < 4; j++) {
102
+ augmented[row * 8 + j] = matrix[row * 4 + j];
103
+ augmented[row * 8 + 4 + j] = row === j ? 1 : 0;
104
+ }
105
+ }
106
+ // Gaussian elimination with partial pivoting
107
+ for (let col = 0; col < 4; col++) {
108
+ // Find pivot row with maximum absolute value
109
+ let maxRow = col;
110
+ let maxVal = Math.abs(augmented[col * 4 + col]);
111
+ for (let row = col + 1; row < 4; row++) {
112
+ const val = Math.abs(augmented[row * 4 + col]);
113
+ if (val > maxVal) {
114
+ maxVal = val;
115
+ maxRow = row;
116
+ }
117
+ }
118
+ // Check for singularity
119
+ if (maxVal < epsilon) {
120
+ return null;
121
+ }
122
+ // Swap rows if necessary
123
+ if (maxRow !== col) {
124
+ const swap = augmented[col];
125
+ augmented[col] = augmented[maxRow];
126
+ augmented[maxRow] = swap;
127
+ }
128
+ // Scale pivot row to make pivot element 1
129
+ const pivot = augmented[col * 4 + col];
130
+ for (let j = 0; j < 8; j++) {
131
+ augmented[col * 4 + j] /= pivot;
132
+ }
133
+ // Eliminate column in other rows
134
+ for (let row = 0; row < 4; row++) {
135
+ if (row !== col) {
136
+ const factor = augmented[row * 4 + col];
137
+ for (let j = 0; j < 8; j++) {
138
+ augmented[row * 4 + j] -= factor * augmented[col * 4 + j];
139
+ }
140
+ }
141
+ }
142
+ }
143
+ // the inverse is read from the first 16 values
144
+ return augmented;
145
+ }
146
+ /**
147
+ * the powers of 10 that are exactly represented by a double
148
+ */
149
+ const powersOf10 = new Float64Array(23).map((_, i) => Number("1e" + i));
150
+ /**
151
+ * same value as `+value.toPrecision(6)`, computed without creating a string when the result does not depend on the
152
+ * rounding errors of the computation.
153
+ *
154
+ * `toPrecision(6)` rounds the exact value to the integer `n` (`10^5 <= n < 10^6`) times a power of 10 (`10^-k`),
155
+ * the decimal string is then parsed to the nearest double. `value × 10^k` is computed with an error below `1.2e-10`
156
+ * (`10^k` is exact, the product is correctly rounded): the rounding to `n` is exact unless the product is close to a
157
+ * tie. `n` and `10^k` are exact doubles: `n / 10^k` is the double nearest to the exact quotient, the value of the
158
+ * parsed string. the other cases (ties, very small or very large values, `NaN`, infinite values) use `toPrecision()`
159
+ * @param value
160
+ */
161
+ function toPrecision6(value) {
162
+ const abs = value < 0 ? -value : value;
163
+ if (abs >= 1e-15 && abs < 1e21) {
164
+ const k = 5 - Math.floor(Math.log10(abs));
165
+ const scaled = k >= 0 ? abs * powersOf10[k] : abs / powersOf10[-k];
166
+ // the exponent computed from the logarithm is exact
167
+ if (scaled >= 1e5 && scaled < 999999.5) {
168
+ let n = Math.floor(scaled);
169
+ const fraction = scaled - n;
170
+ // not close to a tie
171
+ if (fraction < 0.499999 || fraction > 0.500001) {
172
+ if (fraction > 0.5) {
173
+ n++;
174
+ }
175
+ const result = k >= 0 ? n / powersOf10[k] : n * powersOf10[-k];
176
+ return value < 0 ? -result : result;
177
+ }
178
+ }
179
+ }
180
+ return +value.toPrecision(6);
181
+ }
182
+ /**
183
+ * round a number to 6 significant digits, or to the nearest integer when it is closer than `epsilon`
184
+ * @param number
185
+ */
186
+ function round(number) {
187
+ const rounded = Math.round(number);
188
+ return Math.abs(rounded - number) <= epsilon ? rounded : toPrecision6(number);
189
+ }
190
+ /**
191
+ * working copy of the matrix being decomposed
192
+ */
193
+ const decomposeBuffer = new Float64Array(16);
194
+ /**
195
+ * decompose a matrix: translate → rotate → skew → scale. the matrix is not modified
196
+ *
197
+ * `translate3d(25.9808px, 0, 15px) rotateY(60deg) skewX(49.9999deg) scale(1, 1.2)`
198
+ * @param original
199
+ * @param result receives the decomposition
200
+ * @returns false if the matrix cannot be decomposed
201
+ */
202
+ function decompose(original, result) {
203
+ const matrix = decomposeBuffer;
204
+ // Normalize last row
205
+ if (original[15] === 0) {
206
+ return false;
207
+ }
208
+ matrix.set(original);
209
+ for (let i = 0; i < 16; i++)
210
+ matrix[i] /= matrix[15];
211
+ // Perspective extraction
212
+ result.perspectiveX = 0;
213
+ result.perspectiveY = 0;
214
+ result.perspectiveZ = 0;
215
+ result.perspectiveW = 1;
216
+ if (matrix[3] !== 0 || matrix[7] !== 0 || matrix[11] !== 0) {
217
+ const r0 = matrix[3];
218
+ const r1 = matrix[7];
219
+ const r2 = matrix[11];
220
+ const r3 = matrix[15];
221
+ const inverted = inverse(original);
222
+ if (inverted === null) {
223
+ return false;
224
+ }
225
+ // dot product of the right hand side and of the rows of the transposed inverse
226
+ result.perspectiveX = r0 * inverted[0] + r1 * inverted[4] + r2 * inverted[8] + r3 * inverted[12];
227
+ result.perspectiveY = r0 * inverted[1] + r1 * inverted[5] + r2 * inverted[9] + r3 * inverted[13];
228
+ result.perspectiveZ = r0 * inverted[2] + r1 * inverted[6] + r2 * inverted[10] + r3 * inverted[14];
229
+ result.perspectiveW = r0 * inverted[3] + r1 * inverted[7] + r2 * inverted[11] + r3 * inverted[15];
230
+ // Clear perspective from matrix
231
+ matrix[3] = 0;
232
+ matrix[7] = 0;
233
+ matrix[11] = 0;
234
+ matrix[15] = 1;
235
+ }
236
+ // Translation
237
+ result.translateX = matrix[12];
238
+ result.translateY = matrix[13];
239
+ result.translateZ = matrix[14];
240
+ // the 3x3 matrix
241
+ const row00 = matrix[0];
242
+ const row01 = matrix[1];
243
+ const row02 = matrix[2];
244
+ const row10 = matrix[4];
245
+ const row11 = matrix[5];
246
+ const row12 = matrix[6];
247
+ const row20 = matrix[8];
248
+ const row21 = matrix[9];
249
+ const row22 = matrix[10];
250
+ const cross0 = row11 * row22 - row12 * row21;
251
+ const cross1 = row12 * row20 - row10 * row22;
252
+ const cross2 = row10 * row21 - row11 * row20;
253
+ // Compute scale
254
+ const scaleX = Math.hypot(row00, row01, row02);
255
+ // normalized row 0
256
+ let norm = Math.sqrt(row00 * row00 + row01 * row01 + row02 * row02);
257
+ const row0Norm0 = norm === 0 ? 0 : row00 / norm;
258
+ const row0Norm1 = norm === 0 ? 0 : row01 / norm;
259
+ const row0Norm2 = norm === 0 ? 0 : row02 / norm;
260
+ const skewXY = row0Norm0 * row10 + row0Norm1 * row11 + row0Norm2 * row12;
261
+ const row1Proj0 = row10 - skewXY * row0Norm0;
262
+ const row1Proj1 = row11 - skewXY * row0Norm1;
263
+ const row1Proj2 = row12 - skewXY * row0Norm2;
264
+ const scaleY = Math.hypot(row1Proj0, row1Proj1, row1Proj2);
265
+ // normalized projection of row 1
266
+ norm = Math.sqrt(row1Proj0 * row1Proj0 + row1Proj1 * row1Proj1 + row1Proj2 * row1Proj2);
267
+ const row1Norm0 = norm === 0 ? 0 : row1Proj0 / norm;
268
+ const row1Norm1 = norm === 0 ? 0 : row1Proj1 / norm;
269
+ const row1Norm2 = norm === 0 ? 0 : row1Proj2 / norm;
270
+ const skewXZ = row0Norm0 * row20 + row0Norm1 * row21 + row0Norm2 * row22;
271
+ const skewYZ = row1Norm0 * row20 + row1Norm1 * row21 + row1Norm2 * row22;
272
+ const row2Proj0 = row20 - skewXZ * row0Norm0 - skewYZ * row1Norm0;
273
+ const row2Proj1 = row21 - skewXZ * row0Norm1 - skewYZ * row1Norm1;
274
+ const row2Proj2 = row22 - skewXZ * row0Norm2 - skewYZ * row1Norm2;
275
+ // normalized projection of row 2
276
+ norm = Math.sqrt(row2Proj0 * row2Proj0 + row2Proj1 * row2Proj1 + row2Proj2 * row2Proj2);
277
+ const row2Norm0 = norm === 0 ? 0 : row2Proj0 / norm;
278
+ const row2Norm1 = norm === 0 ? 0 : row2Proj1 / norm;
279
+ const row2Norm2 = norm === 0 ? 0 : row2Proj2 / norm;
280
+ const determinant = row00 * cross0 + row01 * cross1 + row02 * cross2;
281
+ const scaleZ = Math.hypot(row2Proj0, row2Proj1, row2Proj2) * (determinant < 0 ? -1 : 1);
282
+ // Build rotation matrix from orthonormalized vectors
283
+ const r00 = row0Norm0, r01 = row1Norm0, r02 = row2Norm0;
284
+ const r10 = row0Norm1, r11 = row1Norm1, r12 = row2Norm1;
285
+ const r20 = row0Norm2, r21 = row1Norm2, r22 = row2Norm2;
286
+ // Convert to quaternion
287
+ const trace = r00 + r11 + r22;
288
+ let qw, qx, qy, qz;
289
+ if (trace > 0) {
290
+ const s = 0.5 / Math.sqrt(trace + 1.0);
291
+ qw = 0.25 / s;
292
+ qx = (r21 - r12) * s;
293
+ qy = (r02 - r20) * s;
294
+ qz = (r10 - r01) * s;
295
+ }
296
+ else if (r00 > r11 && r00 > r22) {
297
+ const s = 2.0 * Math.sqrt(1.0 + r00 - r11 - r22);
298
+ qw = (r21 - r12) / s;
299
+ qx = 0.25 * s;
300
+ qy = (r01 + r10) / s;
301
+ qz = (r02 + r20) / s;
302
+ }
303
+ else if (r11 > r22) {
304
+ const s = 2.0 * Math.sqrt(1.0 + r11 - r00 - r22);
305
+ qw = (r02 - r20) / s;
306
+ qx = (r01 + r10) / s;
307
+ qy = 0.25 * s;
308
+ qz = (r12 + r21) / s;
309
+ }
310
+ else {
311
+ const s = 2.0 * Math.sqrt(1.0 + r22 - r00 - r11);
312
+ qw = (r10 - r01) / s;
313
+ qx = (r02 + r20) / s;
314
+ qy = (r12 + r21) / s;
315
+ qz = 0.25 * s;
316
+ }
317
+ qx = toZeroValue(qx);
318
+ qy = toZeroValue(qy);
319
+ qz = toZeroValue(qz);
320
+ // smallest non zero absolute value of the axis components
321
+ let q = 0;
322
+ let abs = Math.abs(qx);
323
+ if (q === 0 || (abs > 0 && abs < q)) {
324
+ q = abs;
325
+ }
326
+ abs = Math.abs(qy);
327
+ if (q === 0 || (abs > 0 && abs < q)) {
328
+ q = abs;
329
+ }
330
+ abs = Math.abs(qz);
331
+ if (q === 0 || (abs > 0 && abs < q)) {
332
+ q = abs;
333
+ }
334
+ if (q > 0) {
335
+ qx /= q;
336
+ qy /= q;
337
+ qz /= q;
338
+ }
339
+ result.rotateX = qx;
340
+ result.rotateY = qy;
341
+ result.rotateZ = qz;
342
+ result.rotateAngle = Object.is(qw, 0) ? 0 : (2 * Math.acos(qw) * 180) / Math.PI;
343
+ result.scaleX = scaleX;
344
+ result.scaleY = scaleY;
345
+ result.scaleZ = scaleZ;
346
+ result.skewXY = skewXY;
347
+ result.skewXZ = skewXZ;
348
+ result.skewYZ = skewYZ;
349
+ return true;
350
+ }
351
+ /**
352
+ * a value close to 0 (`epsilon`) is set to 0, the other values are rounded to 6 significant digits
353
+ * @param value
354
+ */
355
+ function toZeroValue(value) {
356
+ if (Math.abs(value) <= epsilon) {
357
+ return 0;
358
+ }
359
+ // the integers that have at most 6 digits are not changed by the rounding: no string is created
360
+ if (Number.isInteger(value) && value < 1e6 && value > -1e6) {
361
+ return value;
362
+ }
363
+ return toPrecision6(value);
364
+ }
365
+ /**
366
+ * apply {@link toZeroValue} to the values of a matrix
367
+ * @param matrix
368
+ */
369
+ function toZero(matrix) {
370
+ for (let i = 0; i < 16; i++) {
371
+ matrix[i] = toZeroValue(matrix[i]);
372
+ }
373
+ return matrix;
374
+ }
375
+ // https://drafts.csswg.org/css-transforms-1/#2d-matrix
376
+ function is2DMatrix(matrix) {
377
+ // m13,m14, m23, m24, m31, m32, m34, m43 are all 0
378
+ return (matrix[2] === 0 &&
379
+ matrix[3] === 0 &&
380
+ matrix[6] === 0 &&
381
+ matrix[7] === 0 &&
382
+ matrix[8] === 0 &&
383
+ matrix[9] === 0 &&
384
+ matrix[11] === 0 &&
385
+ matrix[14] === 0 &&
386
+ matrix[10] === 1 &&
387
+ matrix[15] === 1);
388
+ }
389
+
390
+ export { decompose, identityMatrix, is2DMatrix, isIdentity, multiplyInto, round, setIdentity, toPrecision6, toZero, toZeroValue };
@@ -1,8 +1,8 @@
1
1
  /*
2
- CSS parser, minifier and validator for node and the browser
2
+ CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.1.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  /**
@@ -1,8 +1,8 @@
1
1
  /*
2
- CSS parser, minifier and validator for node and the browser
2
+ CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.1.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { WalkerOptionEnum, EnumAstNodeStatus, WalkerEvent, EnumToken } from './types.js';
@@ -1,8 +1,8 @@
1
1
  /*
2
- CSS parser, minifier and validator for node and the browser
2
+ CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.1.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  var properties = {
@@ -88,6 +88,50 @@ var properties = {
88
88
  "margin-left": {
89
89
  shorthand: "margin"
90
90
  },
91
+ "margin-inline": {
92
+ shorthand: "margin-inline",
93
+ properties: [
94
+ "margin-inline-start",
95
+ "margin-inline-end"
96
+ ],
97
+ types: [
98
+ "Length",
99
+ "Perc"
100
+ ],
101
+ multiple: false,
102
+ separator: null,
103
+ keywords: [
104
+ "auto"
105
+ ]
106
+ },
107
+ "margin-inline-start": {
108
+ shorthand: "margin-inline"
109
+ },
110
+ "margin-inline-end": {
111
+ shorthand: "margin-inline"
112
+ },
113
+ "margin-block": {
114
+ shorthand: "margin-block",
115
+ properties: [
116
+ "margin-block-start",
117
+ "margin-block-end"
118
+ ],
119
+ types: [
120
+ "Length",
121
+ "Perc"
122
+ ],
123
+ multiple: false,
124
+ separator: null,
125
+ keywords: [
126
+ "auto"
127
+ ]
128
+ },
129
+ "margin-block-start": {
130
+ shorthand: "margin-block"
131
+ },
132
+ "margin-block-end": {
133
+ shorthand: "margin-block"
134
+ },
91
135
  padding: {
92
136
  shorthand: "padding",
93
137
  properties: [
@@ -115,6 +159,44 @@ var properties = {
115
159
  "padding-left": {
116
160
  shorthand: "padding"
117
161
  },
162
+ "padding-inline": {
163
+ shorthand: "padding-inline",
164
+ properties: [
165
+ "padding-inline-start",
166
+ "padding-inline-end"
167
+ ],
168
+ types: [
169
+ "Length",
170
+ "Perc"
171
+ ],
172
+ keywords: [
173
+ ]
174
+ },
175
+ "padding-inline-start": {
176
+ shorthand: "padding-inline"
177
+ },
178
+ "padding-inline-end": {
179
+ shorthand: "padding-inline"
180
+ },
181
+ "padding-block": {
182
+ shorthand: "padding-block",
183
+ properties: [
184
+ "padding-block-start",
185
+ "padding-block-end"
186
+ ],
187
+ types: [
188
+ "Length",
189
+ "Perc"
190
+ ],
191
+ keywords: [
192
+ ]
193
+ },
194
+ "padding-block-start": {
195
+ shorthand: "padding-block"
196
+ },
197
+ "padding-block-end": {
198
+ shorthand: "padding-block"
199
+ },
118
200
  "scroll-margin": {
119
201
  shorthand: "scroll-margin",
120
202
  properties: [
@@ -872,6 +954,8 @@ var map = {
872
954
  ]
873
955
  },
874
956
  "text-emphasis-color": {
957
+ keywords: [
958
+ ],
875
959
  "default": [
876
960
  "currentcolor"
877
961
  ],