@tbela99/css-parser 1.3.2 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +59 -20
- package/dist/index-umd-web.js +1846 -1075
- package/dist/index.cjs +1941 -1202
- package/dist/index.d.ts +914 -181
- package/dist/lib/ast/expand.js +5 -10
- package/dist/lib/ast/features/calc.js +8 -8
- package/dist/lib/ast/features/inlinecssvariables.js +9 -8
- package/dist/lib/ast/features/prefix.js +5 -15
- package/dist/lib/ast/features/shorthand.js +5 -6
- package/dist/lib/ast/features/transform.js +18 -25
- package/dist/lib/ast/features/type.js +4 -2
- package/dist/lib/ast/minify.js +56 -112
- package/dist/lib/ast/transform/compute.js +2 -4
- package/dist/lib/ast/transform/matrix.js +20 -20
- package/dist/lib/ast/transform/minify.js +105 -12
- package/dist/lib/ast/transform/rotate.js +11 -11
- package/dist/lib/ast/transform/scale.js +6 -6
- package/dist/lib/ast/transform/skew.js +4 -4
- package/dist/lib/ast/transform/translate.js +3 -3
- package/dist/lib/ast/transform/utils.js +30 -37
- package/dist/lib/ast/types.js +16 -4
- package/dist/lib/ast/walk.js +172 -70
- package/dist/lib/fs/resolve.js +12 -7
- package/dist/lib/parser/declaration/list.js +3 -1
- package/dist/lib/parser/parse.js +441 -161
- package/dist/lib/parser/tokenize.js +12 -14
- package/dist/lib/renderer/render.js +7 -7
- package/dist/lib/syntax/color/cmyk.js +6 -3
- package/dist/lib/syntax/color/color-mix.js +2 -3
- package/dist/lib/syntax/color/color.js +28 -6
- package/dist/lib/syntax/color/hex.js +3 -0
- package/dist/lib/syntax/color/hsl.js +18 -7
- package/dist/lib/syntax/color/hwb.js +3 -3
- package/dist/lib/syntax/color/lab.js +4 -4
- package/dist/lib/syntax/color/lch.js +7 -4
- package/dist/lib/syntax/color/oklab.js +4 -4
- package/dist/lib/syntax/color/oklch.js +18 -6
- package/dist/lib/syntax/color/relativecolor.js +9 -56
- package/dist/lib/syntax/color/srgb.js +1 -1
- package/dist/lib/syntax/syntax.js +36 -18
- package/dist/lib/validation/at-rules/container.js +11 -0
- package/dist/lib/validation/at-rules/counter-style.js +11 -0
- package/dist/lib/validation/at-rules/font-feature-values.js +11 -0
- package/dist/lib/validation/at-rules/keyframes.js +11 -0
- package/dist/lib/validation/at-rules/layer.js +11 -0
- package/dist/lib/validation/at-rules/media.js +11 -0
- package/dist/lib/validation/at-rules/page-margin-box.js +11 -0
- package/dist/lib/validation/at-rules/page.js +11 -0
- package/dist/lib/validation/at-rules/supports.js +11 -0
- package/dist/lib/validation/at-rules/when.js +11 -0
- package/dist/lib/validation/config.js +0 -2
- package/dist/lib/validation/config.json.js +21 -9
- package/dist/lib/validation/parser/parse.js +53 -2
- package/dist/lib/validation/syntax.js +199 -36
- package/dist/node.js +63 -36
- package/dist/web.js +84 -25
- package/package.json +7 -5
- package/dist/lib/validation/parser/types.js +0 -54
|
@@ -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
|
|
21
|
-
matrix[
|
|
22
|
-
matrix[
|
|
23
|
-
matrix[
|
|
24
|
-
matrix[
|
|
25
|
-
matrix[
|
|
26
|
-
matrix[2 * 4
|
|
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
|
|
34
|
-
matrix[
|
|
35
|
-
matrix[
|
|
36
|
-
matrix[
|
|
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
|
|
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[
|
|
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
|
|
21
|
-
matrix[
|
|
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
|
|
27
|
-
matrix[
|
|
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[
|
|
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[
|
|
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[
|
|
16
|
+
matrix[4] = Math.tan(values[0]);
|
|
17
17
|
if (values.length > 1) {
|
|
18
|
-
matrix[
|
|
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
|
|
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
|
|
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
|
|
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);
|
|
@@ -2,9 +2,6 @@ const epsilon = 1e-5;
|
|
|
2
2
|
function identity() {
|
|
3
3
|
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
4
4
|
}
|
|
5
|
-
function pLength(point) {
|
|
6
|
-
return Math.sqrt(point[0] * point[0] + point[1] * point[1] + point[2] * point[2]);
|
|
7
|
-
}
|
|
8
5
|
function normalize(point) {
|
|
9
6
|
const [x, y, z] = point;
|
|
10
7
|
const norm = Math.sqrt(point[0] * point[0] + point[1] * point[1] + point[2] * point[2]);
|
|
@@ -32,8 +29,14 @@ function multiply(matrixA, matrixB) {
|
|
|
32
29
|
function inverse(matrix) {
|
|
33
30
|
// Create augmented matrix [matrix | identity]
|
|
34
31
|
let augmented = [
|
|
35
|
-
|
|
36
|
-
1, 0, 0, 0,
|
|
32
|
+
...matrix.slice(0, 4),
|
|
33
|
+
1, 0, 0, 0,
|
|
34
|
+
...matrix.slice(4, 8),
|
|
35
|
+
0, 1, 0, 0,
|
|
36
|
+
...matrix.slice(8, 12),
|
|
37
|
+
0, 0, 1, 0,
|
|
38
|
+
...matrix.slice(12, 16),
|
|
39
|
+
0, 0, 0, 1
|
|
37
40
|
];
|
|
38
41
|
// Gaussian elimination with partial pivoting
|
|
39
42
|
for (let col = 0; col < 4; col++) {
|
|
@@ -73,24 +76,9 @@ function inverse(matrix) {
|
|
|
73
76
|
// Extract the inverse from the right side of the augmented matrix
|
|
74
77
|
return augmented.slice(0, 16);
|
|
75
78
|
}
|
|
76
|
-
// function transpose(matrix: Matrix): Matrix {
|
|
77
|
-
// // Crée une nouvelle matrice vide 4x4
|
|
78
|
-
// // @ts-ignore
|
|
79
|
-
// let transposed: Matrix = [[], [], [], []] as Matrix;
|
|
80
|
-
//
|
|
81
|
-
// // Parcourt chaque ligne et colonne pour transposer
|
|
82
|
-
// for (let i = 0; i < 4; i++) {
|
|
83
|
-
//
|
|
84
|
-
// for (let j = 0; j < 4; j++) {
|
|
85
|
-
//
|
|
86
|
-
// transposed[j][i] = matrix[i][j];
|
|
87
|
-
// }
|
|
88
|
-
// }
|
|
89
|
-
//
|
|
90
|
-
// return transposed;
|
|
91
|
-
// }
|
|
92
79
|
function round(number) {
|
|
93
|
-
|
|
80
|
+
const rounded = Math.round(number);
|
|
81
|
+
return Math.abs(rounded - number) <= epsilon ? rounded : +number.toPrecision(6);
|
|
94
82
|
}
|
|
95
83
|
// translate3d(25.9808px, 0, 15px ) rotateY(60deg) skewX(49.9999deg) scale(1, 1.2)
|
|
96
84
|
// translate → rotate → skew → scale
|
|
@@ -113,7 +101,7 @@ function decompose(original) {
|
|
|
113
101
|
perspectiveMatrix[15] = 1;
|
|
114
102
|
// @ts-ignore
|
|
115
103
|
const inverted = inverse(original.slice());
|
|
116
|
-
if (
|
|
104
|
+
if (inverted === null) {
|
|
117
105
|
return null;
|
|
118
106
|
}
|
|
119
107
|
const transposedInverse = transposeMatrix4(inverted);
|
|
@@ -134,8 +122,13 @@ function decompose(original) {
|
|
|
134
122
|
const row0 = [matrix[0], matrix[1], matrix[2]];
|
|
135
123
|
const row1 = [matrix[4], matrix[5], matrix[6]];
|
|
136
124
|
const row2 = [matrix[8], matrix[9], matrix[10]];
|
|
125
|
+
const cross = [
|
|
126
|
+
row1[1] * row2[2] - row1[2] * row2[1],
|
|
127
|
+
row1[2] * row2[0] - row1[0] * row2[2],
|
|
128
|
+
row1[0] * row2[1] - row1[1] * row2[0],
|
|
129
|
+
];
|
|
137
130
|
// Compute scale
|
|
138
|
-
const scaleX =
|
|
131
|
+
const scaleX = Math.hypot(...row0);
|
|
139
132
|
const row0Norm = normalize(row0);
|
|
140
133
|
const skewXY = dot(row0Norm, row1);
|
|
141
134
|
const row1Proj = [
|
|
@@ -143,7 +136,7 @@ function decompose(original) {
|
|
|
143
136
|
row1[1] - skewXY * row0Norm[1],
|
|
144
137
|
row1[2] - skewXY * row0Norm[2]
|
|
145
138
|
];
|
|
146
|
-
const scaleY =
|
|
139
|
+
const scaleY = Math.hypot(...row1Proj);
|
|
147
140
|
const row1Norm = normalize(row1Proj);
|
|
148
141
|
const skewXZ = dot(row0Norm, row2);
|
|
149
142
|
const skewYZ = dot(row1Norm, row2);
|
|
@@ -152,8 +145,9 @@ function decompose(original) {
|
|
|
152
145
|
row2[1] - skewXZ * row0Norm[1] - skewYZ * row1Norm[1],
|
|
153
146
|
row2[2] - skewXZ * row0Norm[2] - skewYZ * row1Norm[2]
|
|
154
147
|
];
|
|
155
|
-
const scaleZ = pLength(row2Proj);
|
|
156
148
|
const row2Norm = normalize(row2Proj);
|
|
149
|
+
const determinant = row0[0] * cross[0] + row0[1] * cross[1] + row0[2] * cross[2];
|
|
150
|
+
const scaleZ = Math.hypot(...row2Proj) * (determinant < 0 ? -1 : 1);
|
|
157
151
|
// Build rotation matrix from orthonormalized vectors
|
|
158
152
|
const r00 = row0Norm[0], r01 = row1Norm[0], r02 = row2Norm[0];
|
|
159
153
|
const r10 = row0Norm[1], r11 = row1Norm[1], r12 = row2Norm[1];
|
|
@@ -190,7 +184,6 @@ function decompose(original) {
|
|
|
190
184
|
qz = 0.25 * s;
|
|
191
185
|
}
|
|
192
186
|
[qx, qy, qz] = toZero([qx, qy, qz]);
|
|
193
|
-
// const q = gcd(qx, gcd(qy, qz));
|
|
194
187
|
let q = [Math.abs(qx), Math.abs(qy), Math.abs(qz)].reduce((acc, curr) => {
|
|
195
188
|
if (acc == 0 || (curr > 0 && curr < acc)) {
|
|
196
189
|
acc = curr;
|
|
@@ -235,16 +228,16 @@ function toZero(v) {
|
|
|
235
228
|
// https://drafts.csswg.org/css-transforms-1/#2d-matrix
|
|
236
229
|
function is2DMatrix(matrix) {
|
|
237
230
|
// m13,m14, m23, m24, m31, m32, m34, m43 are all 0
|
|
238
|
-
return matrix[
|
|
239
|
-
matrix[
|
|
240
|
-
matrix[
|
|
241
|
-
matrix[
|
|
242
|
-
matrix[
|
|
243
|
-
matrix[
|
|
244
|
-
matrix[
|
|
245
|
-
matrix[
|
|
246
|
-
matrix[
|
|
247
|
-
matrix[
|
|
231
|
+
return matrix[2] === 0 &&
|
|
232
|
+
matrix[3] === 0 &&
|
|
233
|
+
matrix[6] === 0 &&
|
|
234
|
+
matrix[7] === 0 &&
|
|
235
|
+
matrix[8] === 0 &&
|
|
236
|
+
matrix[9] === 0 &&
|
|
237
|
+
matrix[11] === 0 &&
|
|
238
|
+
matrix[14] === 0 &&
|
|
239
|
+
matrix[10] === 1 &&
|
|
240
|
+
matrix[15] === 1;
|
|
248
241
|
}
|
|
249
242
|
|
|
250
243
|
export { decompose, epsilon, identity, is2DMatrix, multiply, round, toZero };
|
package/dist/lib/ast/types.js
CHANGED
|
@@ -19,14 +19,26 @@ var ValidationLevel;
|
|
|
19
19
|
* disable validation
|
|
20
20
|
*/
|
|
21
21
|
ValidationLevel[ValidationLevel["None"] = 0] = "None";
|
|
22
|
+
/**
|
|
23
|
+
* validate selectors
|
|
24
|
+
*/
|
|
25
|
+
ValidationLevel[ValidationLevel["Selector"] = 1] = "Selector";
|
|
26
|
+
/**
|
|
27
|
+
* validate at-rules
|
|
28
|
+
*/
|
|
29
|
+
ValidationLevel[ValidationLevel["AtRule"] = 2] = "AtRule";
|
|
30
|
+
/**
|
|
31
|
+
* validate declarations
|
|
32
|
+
*/
|
|
33
|
+
ValidationLevel[ValidationLevel["Declaration"] = 4] = "Declaration";
|
|
22
34
|
/**
|
|
23
35
|
* validate selectors and at-rules
|
|
24
36
|
*/
|
|
25
|
-
ValidationLevel[ValidationLevel["Default"] =
|
|
37
|
+
ValidationLevel[ValidationLevel["Default"] = 3] = "Default";
|
|
26
38
|
/**
|
|
27
39
|
* validate selectors, at-rules and declarations
|
|
28
40
|
*/
|
|
29
|
-
ValidationLevel[ValidationLevel["All"] =
|
|
41
|
+
ValidationLevel[ValidationLevel["All"] = 7] = "All"; // selectors + at-rules + declarations
|
|
30
42
|
})(ValidationLevel || (ValidationLevel = {}));
|
|
31
43
|
/**
|
|
32
44
|
* enum of all token types
|
|
@@ -330,7 +342,7 @@ var EnumToken;
|
|
|
330
342
|
/**
|
|
331
343
|
* keyframe rule node type
|
|
332
344
|
*/
|
|
333
|
-
EnumToken[EnumToken["
|
|
345
|
+
EnumToken[EnumToken["KeyFramesRuleNodeType"] = 73] = "KeyFramesRuleNodeType";
|
|
334
346
|
/**
|
|
335
347
|
* class selector token type
|
|
336
348
|
*/
|
|
@@ -410,7 +422,7 @@ var EnumToken;
|
|
|
410
422
|
/**
|
|
411
423
|
* keyframe at rule node type
|
|
412
424
|
*/
|
|
413
|
-
EnumToken[EnumToken["
|
|
425
|
+
EnumToken[EnumToken["KeyframesAtRuleNodeType"] = 93] = "KeyframesAtRuleNodeType";
|
|
414
426
|
/**
|
|
415
427
|
* invalid declaration node type
|
|
416
428
|
*/
|