@tbela99/css-parser 2.0.1 → 2.2.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.
- package/CHANGELOG.md +86 -1
- package/README.md +15 -7
- package/architecture.png +0 -0
- package/dist/{src/data → data}/properties.json.js +86 -2
- package/dist/{src/data → data}/validation.json.js +4848 -3750
- package/dist/index-umd-web.js +18234 -9498
- package/dist/index.d.ts +1251 -373
- package/dist/{src/lib → lib}/ast/arena-node.js +119 -57
- package/dist/{src/lib → lib}/ast/arena.js +1034 -655
- package/dist/{src/lib → lib}/ast/cache.js +36 -31
- package/dist/{src/lib → lib}/ast/features/calc.js +37 -27
- package/dist/{src/lib → lib}/ast/features/if.js +24 -19
- package/dist/{src/lib → lib}/ast/features/index.js +3 -2
- package/dist/{src/lib → lib}/ast/features/inlinecssvariables.js +42 -23
- package/dist/lib/ast/features/mixin.js +953 -0
- package/dist/{src/lib → lib}/ast/features/prefix.js +82 -69
- package/dist/lib/ast/features/shorthand.js +129 -0
- package/dist/lib/ast/features/transform.js +188 -0
- package/dist/{src/lib → lib}/ast/features/type.js +2 -2
- package/dist/{src/lib → lib}/ast/math/expression.js +150 -150
- package/dist/{src/lib → lib}/ast/math/math.js +8 -8
- package/dist/{src/lib → lib}/ast/minify.js +932 -354
- package/dist/lib/ast/mixins/custom-function.js +393 -0
- package/dist/lib/ast/mixins/utils.js +53 -0
- package/dist/lib/ast/mixins/variables.js +678 -0
- package/dist/lib/ast/strings.js +906 -0
- package/dist/lib/ast/transform/compute.js +560 -0
- package/dist/lib/ast/transform/matrix.js +67 -0
- package/dist/lib/ast/transform/minify.js +325 -0
- package/dist/lib/ast/transform/perspective.js +24 -0
- package/dist/{src/lib → lib}/ast/transform/rotate.js +16 -7
- package/dist/lib/ast/transform/scale.js +43 -0
- package/dist/lib/ast/transform/skew.js +38 -0
- package/dist/lib/ast/transform/translate.js +56 -0
- package/dist/lib/ast/transform/utils.js +390 -0
- package/dist/{src/lib → lib}/ast/types.js +7 -15
- package/dist/{src/lib → lib}/ast/walk.js +19 -19
- package/dist/{src/lib → lib}/fs/resolve.js +15 -15
- package/dist/{src/lib → lib}/parser/declaration/list.js +55 -26
- package/dist/{src/lib → lib}/parser/declaration/map.js +85 -72
- package/dist/{src/lib → lib}/parser/declaration/set.js +32 -27
- package/dist/lib/parser/input.js +85 -0
- package/dist/{src/lib → lib}/parser/linesmap.js +3 -16
- package/dist/{src/lib → lib}/parser/parse.js +852 -619
- package/dist/lib/parser/source.js +71 -0
- package/dist/{src/lib → lib}/parser/tokenize.js +886 -722
- package/dist/{src/lib → lib}/parser/utils/angle.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-container.js +68 -35
- package/dist/{src/lib → lib}/parser/utils/at-rule-font-feature-values.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-generic.js +31 -13
- package/dist/{src/lib → lib}/parser/utils/at-rule-import.js +29 -16
- package/dist/{src/lib → lib}/parser/utils/at-rule-media.js +77 -58
- package/dist/{src/lib → lib}/parser/utils/at-rule-support.js +18 -20
- package/dist/{src/lib → lib}/parser/utils/at-rule-when-else.js +9 -8
- package/dist/{src/lib → lib}/parser/utils/at-rule.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/base64.js +2 -2
- package/dist/lib/parser/utils/cache.js +53 -0
- package/dist/lib/parser/utils/canonical.js +78 -0
- package/dist/lib/parser/utils/codes.js +93 -0
- package/dist/{src/lib → lib}/parser/utils/config.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/declaration.js +67 -49
- package/dist/{src/lib → lib}/parser/utils/eq.js +14 -14
- package/dist/{src/lib → lib}/parser/utils/hash.js +4 -4
- package/dist/lib/parser/utils/selector.js +720 -0
- package/dist/{src/lib → lib}/parser/utils/text.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/token.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/type.js +11 -9
- package/dist/{src/lib → lib}/printer/render.js +536 -243
- package/dist/lib/printer/result.js +148 -0
- package/dist/{src/lib → lib}/printer/sourcemap/lib/codec.js +5 -8
- package/dist/{src/lib → lib}/printer/sourcemap/sourcemap.js +13 -13
- package/dist/lib/printer/writer.js +252 -0
- package/dist/{src/lib → lib}/syntax/color/a98rgb.js +6 -6
- package/dist/{src/lib → lib}/syntax/color/alpha.js +12 -11
- package/dist/{src/lib → lib}/syntax/color/cmyk.js +11 -6
- package/dist/{src/lib → lib}/syntax/color/color-mix.js +78 -67
- package/dist/{src/lib → lib}/syntax/color/color.js +52 -47
- package/dist/{src/lib → lib}/syntax/color/hex.js +17 -17
- package/dist/{src/lib → lib}/syntax/color/hsl.js +8 -8
- package/dist/{src/lib → lib}/syntax/color/hwb.js +6 -7
- package/dist/{src/lib → lib}/syntax/color/lab.js +8 -8
- package/dist/{src/lib → lib}/syntax/color/lch.js +12 -11
- package/dist/{src/lib → lib}/syntax/color/oklab.js +9 -9
- package/dist/{src/lib → lib}/syntax/color/oklch.js +5 -5
- package/dist/{src/lib → lib}/syntax/color/p3.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/prophotorgb.js +4 -4
- package/dist/{src/lib → lib}/syntax/color/rec2020.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/relative-color.js +41 -34
- package/dist/{src/lib → lib}/syntax/color/rgb.js +17 -17
- package/dist/{src/lib → lib}/syntax/color/srgb.js +20 -20
- package/dist/{src/lib → lib}/syntax/color/utils/color-type.js +6 -4
- package/dist/{src/lib → lib}/syntax/color/utils/colorspace.js +12 -14
- package/dist/{src/lib → lib}/syntax/color/utils/components.js +13 -13
- package/dist/{src/lib → lib}/syntax/color/utils/distance.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/utils/make-color.js +6 -4
- package/dist/{src/lib → lib}/syntax/color/utils/matrix.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/xyz.js +5 -10
- package/dist/{src/lib → lib}/syntax/color/xyzd50.js +3 -3
- package/dist/{src/lib → lib}/syntax/constants.js +30 -3
- package/dist/{src/lib → lib}/syntax/syntax.js +151 -116
- package/dist/lib/validation/config.js +173 -0
- package/dist/lib/validation/first.js +571 -0
- package/dist/{src/lib → lib}/validation/match.js +1256 -579
- package/dist/{src/lib → lib}/validation/parser/parse.js +85 -59
- package/dist/{src/lib → lib}/validation/parser/typedef.js +6 -2
- package/dist/{src/lib → lib}/validation/utils/list.js +3 -19
- package/dist/{src/node.js → node.js} +92 -80
- package/dist/{src/types.js → types.js} +2 -2
- package/dist/{src/utils → utils}/sync.js +13 -8
- package/dist/version.d.ts +4 -0
- package/dist/version.js +13 -0
- package/dist/{src/web.js → web.js} +80 -75
- package/package.json +13 -13
- package/dist/package.json.js +0 -10
- package/dist/src/lib/ast/features/shorthand.js +0 -87
- package/dist/src/lib/ast/features/transform.js +0 -85
- package/dist/src/lib/ast/transform/compute.js +0 -358
- package/dist/src/lib/ast/transform/matrix.js +0 -88
- package/dist/src/lib/ast/transform/minify.js +0 -267
- package/dist/src/lib/ast/transform/perspective.js +0 -16
- package/dist/src/lib/ast/transform/scale.js +0 -39
- package/dist/src/lib/ast/transform/skew.js +0 -30
- package/dist/src/lib/ast/transform/translate.js +0 -39
- package/dist/src/lib/ast/transform/utils.js +0 -287
- package/dist/src/lib/parser/source.js +0 -127
- package/dist/src/lib/parser/utils/cache.js +0 -54
- package/dist/src/lib/parser/utils/selector.js +0 -440
- package/dist/src/lib/validation/config.js +0 -120
|
@@ -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.2.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,22 +1,10 @@
|
|
|
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.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
|
-
/**
|
|
9
|
-
* Syntax validation enum
|
|
10
|
-
*/
|
|
11
|
-
var SyntaxValidationResult;
|
|
12
|
-
(function (SyntaxValidationResult) {
|
|
13
|
-
/** valid syntax */
|
|
14
|
-
SyntaxValidationResult[SyntaxValidationResult["Valid"] = 0] = "Valid";
|
|
15
|
-
/** drop invalid syntax */
|
|
16
|
-
SyntaxValidationResult[SyntaxValidationResult["Drop"] = 1] = "Drop";
|
|
17
|
-
/** preserve unknown at-rules, declarations and pseudo-classes */
|
|
18
|
-
SyntaxValidationResult[SyntaxValidationResult["Lenient"] = 2] = "Lenient";
|
|
19
|
-
})(SyntaxValidationResult || (SyntaxValidationResult = {}));
|
|
20
8
|
/**
|
|
21
9
|
* Enum of node statuses
|
|
22
10
|
*/
|
|
@@ -660,6 +648,10 @@ var EnumToken;
|
|
|
660
648
|
* user defined dimension token type
|
|
661
649
|
*/
|
|
662
650
|
EnumToken[EnumToken["UserDefinedDimensionTokenType"] = 140] = "UserDefinedDimensionTokenType";
|
|
651
|
+
/**
|
|
652
|
+
* unicode range token type: `U+0025-00FF`, `U+4??`. the token is rendered as it is
|
|
653
|
+
*/
|
|
654
|
+
EnumToken[EnumToken["UniCodeRange"] = 141] = "UniCodeRange";
|
|
663
655
|
/* aliases */
|
|
664
656
|
/**
|
|
665
657
|
* alias for time token type
|
|
@@ -1017,4 +1009,4 @@ var WalkerEvent;
|
|
|
1017
1009
|
WalkerEvent[WalkerEvent["Leave"] = 2] = "Leave";
|
|
1018
1010
|
})(WalkerEvent || (WalkerEvent = {}));
|
|
1019
1011
|
|
|
1020
|
-
export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, ModuleScopeEnumOptions,
|
|
1012
|
+
export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, ModuleScopeEnumOptions, WalkerEvent, WalkerOptionEnum };
|
|
@@ -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.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { WalkerOptionEnum, EnumAstNodeStatus, WalkerEvent, EnumToken } from './types.js';
|
|
@@ -19,16 +19,16 @@ import { WalkerOptionEnum, EnumAstNodeStatus, WalkerEvent, EnumToken } from './t
|
|
|
19
19
|
function pushValues(arena, stack, value, reverse) {
|
|
20
20
|
const first = stack.length;
|
|
21
21
|
let token = arena.firstToken[value];
|
|
22
|
-
while (token
|
|
22
|
+
while (token !== 0) {
|
|
23
23
|
stack.push(token);
|
|
24
24
|
token = arena.nextSibling[token];
|
|
25
25
|
}
|
|
26
|
-
if ((arena.flags[value] & EnumAstNodeStatus.HasChildren)
|
|
26
|
+
if ((arena.flags[value] & EnumAstNodeStatus.HasChildren) === 0) {
|
|
27
27
|
let child = arena.firstChild[value];
|
|
28
|
-
while (child
|
|
29
|
-
if (arena.dataTypes[child]
|
|
28
|
+
while (child !== 0) {
|
|
29
|
+
if (arena.dataTypes[child] === EnumToken.ListTokenType) {
|
|
30
30
|
token = arena.firstToken[child];
|
|
31
|
-
while (token
|
|
31
|
+
while (token !== 0) {
|
|
32
32
|
stack.push(token);
|
|
33
33
|
token = arena.nextSibling[token];
|
|
34
34
|
}
|
|
@@ -67,7 +67,7 @@ class NodeWalker {
|
|
|
67
67
|
constructor(arena, node, filter, reverse) {
|
|
68
68
|
this.arena = arena;
|
|
69
69
|
this.stack = [node];
|
|
70
|
-
if (filter != null && typeof filter
|
|
70
|
+
if (filter != null && typeof filter === "object") {
|
|
71
71
|
this.filter = filter.filter ?? null;
|
|
72
72
|
this.reverse = filter.reverse === true;
|
|
73
73
|
this.attributes = filter.attributes === true;
|
|
@@ -87,7 +87,7 @@ class NodeWalker {
|
|
|
87
87
|
* @param option
|
|
88
88
|
*/
|
|
89
89
|
expand(node, option) {
|
|
90
|
-
if (typeof option
|
|
90
|
+
if (typeof option === "number" && option & WalkerOptionEnum.IgnoreChildren) {
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
93
|
const arena = this.arena;
|
|
@@ -99,12 +99,12 @@ class NodeWalker {
|
|
|
99
99
|
if (this.children && arena.flags[node] & EnumAstNodeStatus.HasChildren) {
|
|
100
100
|
// children are pushed in reverse so that they are popped in document order
|
|
101
101
|
if (this.reverse) {
|
|
102
|
-
for (let child = arena.firstChild[node]; child
|
|
102
|
+
for (let child = arena.firstChild[node]; child !== 0; child = arena.nextSibling[child]) {
|
|
103
103
|
stack.push(child);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
else {
|
|
107
|
-
for (let child = arena.lastChild[node]; child
|
|
107
|
+
for (let child = arena.lastChild[node]; child !== 0; child = arena.previousSibling[child]) {
|
|
108
108
|
stack.push(child);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -113,7 +113,7 @@ class NodeWalker {
|
|
|
113
113
|
next() {
|
|
114
114
|
const stack = this.stack;
|
|
115
115
|
const filter = this.filter;
|
|
116
|
-
if (this.current
|
|
116
|
+
if (this.current !== 0) {
|
|
117
117
|
this.expand(this.current, this.option);
|
|
118
118
|
this.current = 0;
|
|
119
119
|
}
|
|
@@ -122,7 +122,7 @@ class NodeWalker {
|
|
|
122
122
|
let option = null;
|
|
123
123
|
if (filter != null) {
|
|
124
124
|
option = filter(this.arena, node);
|
|
125
|
-
if (typeof option
|
|
125
|
+
if (typeof option === "number") {
|
|
126
126
|
if (option & WalkerOptionEnum.Ignore) {
|
|
127
127
|
continue;
|
|
128
128
|
}
|
|
@@ -176,7 +176,7 @@ class ValueWalker {
|
|
|
176
176
|
constructor(arena, tokens, filter, reverse) {
|
|
177
177
|
this.arena = arena;
|
|
178
178
|
this.reverse = reverse === true;
|
|
179
|
-
if (typeof tokens
|
|
179
|
+
if (typeof tokens === "number") {
|
|
180
180
|
// the value tokens of a node or a token
|
|
181
181
|
pushValues(arena, this.stack, tokens, this.reverse);
|
|
182
182
|
}
|
|
@@ -191,7 +191,7 @@ class ValueWalker {
|
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
// the filter is read once: no filter object is created
|
|
194
|
-
if (typeof filter
|
|
194
|
+
if (typeof filter === "function") {
|
|
195
195
|
this.fn = filter;
|
|
196
196
|
}
|
|
197
197
|
else if (filter != null) {
|
|
@@ -212,7 +212,7 @@ class ValueWalker {
|
|
|
212
212
|
return (type == null ||
|
|
213
213
|
this.arena.dataTypes[token] == type ||
|
|
214
214
|
(Array.isArray(type) && type.includes(this.arena.dataTypes[token])) ||
|
|
215
|
-
(typeof type
|
|
215
|
+
(typeof type === "function" && type(this.arena, token)));
|
|
216
216
|
}
|
|
217
217
|
/**
|
|
218
218
|
* the tokens returned by the filter are visited too
|
|
@@ -236,7 +236,7 @@ class ValueWalker {
|
|
|
236
236
|
leave(value) {
|
|
237
237
|
const option = this.option;
|
|
238
238
|
// the children are read after the token is visited (it may have been modified)
|
|
239
|
-
if (typeof option
|
|
239
|
+
if (typeof option !== "number" || (option & WalkerOptionEnum.IgnoreChildren) === 0) {
|
|
240
240
|
pushValues(this.arena, this.stack, value, this.reverse);
|
|
241
241
|
}
|
|
242
242
|
if (this.eventType & WalkerEvent.Leave && this.fn != null && this.isValid(value)) {
|
|
@@ -248,7 +248,7 @@ class ValueWalker {
|
|
|
248
248
|
}
|
|
249
249
|
next() {
|
|
250
250
|
const stack = this.stack;
|
|
251
|
-
if (this.current
|
|
251
|
+
if (this.current !== 0) {
|
|
252
252
|
this.leave(this.current);
|
|
253
253
|
this.current = 0;
|
|
254
254
|
}
|
|
@@ -258,7 +258,7 @@ class ValueWalker {
|
|
|
258
258
|
if (this.fn != null && this.eventType & WalkerEvent.Enter && this.isValid(value)) {
|
|
259
259
|
const option = this.fn(this.arena, value, WalkerEvent.Enter);
|
|
260
260
|
this.option = option;
|
|
261
|
-
if (typeof option
|
|
261
|
+
if (typeof option === "number") {
|
|
262
262
|
if (option & WalkerOptionEnum.Stop) {
|
|
263
263
|
break;
|
|
264
264
|
}
|
|
@@ -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.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { memoize } from '../parser/utils/cache.js';
|
|
@@ -29,7 +29,7 @@ function dirname(path) {
|
|
|
29
29
|
let parts = [""];
|
|
30
30
|
for (; i < path.length; i++) {
|
|
31
31
|
const chr = path.charAt(i);
|
|
32
|
-
if (chr
|
|
32
|
+
if (chr === "/") {
|
|
33
33
|
parts.push("");
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
@@ -45,14 +45,14 @@ function dirname(path) {
|
|
|
45
45
|
* @private
|
|
46
46
|
*/
|
|
47
47
|
function splitPath(result) {
|
|
48
|
-
if (result.length
|
|
48
|
+
if (result.length === 0) {
|
|
49
49
|
return { parts: [], i: 0 };
|
|
50
50
|
}
|
|
51
|
-
const parts = result
|
|
51
|
+
const parts = result === "/" ? [] : [""];
|
|
52
52
|
let i = 0;
|
|
53
53
|
for (; i < result.length; i++) {
|
|
54
54
|
const chr = result.charAt(i);
|
|
55
|
-
if (chr
|
|
55
|
+
if (chr === "/") {
|
|
56
56
|
parts.push("");
|
|
57
57
|
}
|
|
58
58
|
// else if (chr == "?" || chr == "#") {
|
|
@@ -74,7 +74,7 @@ function splitPath(result) {
|
|
|
74
74
|
return { parts, i };
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* Normalize path
|
|
78
78
|
* @param path
|
|
79
79
|
* @private
|
|
80
80
|
*/
|
|
@@ -89,16 +89,16 @@ const normalize = memoize(function (path) {
|
|
|
89
89
|
}
|
|
90
90
|
for (; i < path.length; i++) {
|
|
91
91
|
const chr = path.charAt(i);
|
|
92
|
-
if (chr
|
|
93
|
-
if (parts.length
|
|
92
|
+
if (chr === "/") {
|
|
93
|
+
if (parts.length === 0 || parts[parts.length - 1] !== "") {
|
|
94
94
|
parts.push("");
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
else if (chr
|
|
97
|
+
else if (chr === "?" || chr === "#") {
|
|
98
98
|
break;
|
|
99
99
|
}
|
|
100
100
|
else {
|
|
101
|
-
if (parts.length
|
|
101
|
+
if (parts.length === 0) {
|
|
102
102
|
parts.push("");
|
|
103
103
|
}
|
|
104
104
|
parts[parts.length - 1] += chr;
|
|
@@ -109,12 +109,12 @@ const normalize = memoize(function (path) {
|
|
|
109
109
|
// if (parts[k] == ".") {
|
|
110
110
|
// parts.splice(k--, 1);
|
|
111
111
|
// } else
|
|
112
|
-
if (k > 0 && parts[k]
|
|
112
|
+
if (k > 0 && parts[k] === "..") {
|
|
113
113
|
parts.splice(k - 1, 2);
|
|
114
114
|
k -= 2;
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
return (path.charAt(0)
|
|
117
|
+
return (path.charAt(0) === "/" ? "/" : "") + parts.join("/");
|
|
118
118
|
});
|
|
119
119
|
/**
|
|
120
120
|
* diff path
|
|
@@ -126,7 +126,7 @@ const diff = memoize(function (path1, path2) {
|
|
|
126
126
|
let { parts } = splitPath(path1);
|
|
127
127
|
const { parts: dirs } = splitPath(path2);
|
|
128
128
|
for (const p of dirs) {
|
|
129
|
-
if (parts[0]
|
|
129
|
+
if (parts[0] === p) {
|
|
130
130
|
parts.shift();
|
|
131
131
|
}
|
|
132
132
|
else {
|
|
@@ -163,7 +163,7 @@ const resolve = memoize(function (url, currentDirectory, cwd) {
|
|
|
163
163
|
if (windowsPathnameRegexp.test(dir)) {
|
|
164
164
|
dir = dir.replace(windowsPathnameRegexp, "");
|
|
165
165
|
}
|
|
166
|
-
const absolute = dir
|
|
166
|
+
const absolute = dir === "" || url.startsWith("/") || url.startsWith(dir) || windowsPathnameRegexp.test(url)
|
|
167
167
|
? resolvePath(url)
|
|
168
168
|
: resolvePath(dir, url);
|
|
169
169
|
return {
|