@tbela99/css-parser 1.4.1 → 1.4.3
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/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
- package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
- package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
- package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
- package/.repl_history +4 -0
- package/CHANGELOG.md +168 -4
- package/README.md +82 -0
- package/badges/coverage.svg +20 -0
- package/deno.lock +2861 -0
- package/dist/config.json.js +33 -1
- package/dist/index-umd-web.js +24393 -18479
- package/dist/index.cjs +27430 -21519
- package/dist/index.d.ts +1403 -933
- package/dist/lib/ast/clone.d.ts +10 -0
- package/dist/lib/ast/clone.js +45 -0
- package/dist/lib/ast/expand.d.ts +14 -0
- package/dist/lib/ast/expand.js +89 -64
- package/dist/lib/ast/features/calc.d.ts +10 -0
- package/dist/lib/ast/features/calc.js +62 -24
- package/dist/lib/ast/features/if.d.ts +10 -0
- package/dist/lib/ast/features/if.js +215 -0
- package/dist/lib/ast/features/index.d.ts +6 -0
- package/dist/lib/ast/features/index.js +1 -0
- package/dist/lib/ast/features/inlinecssvariables.d.ts +15 -0
- package/dist/lib/ast/features/inlinecssvariables.js +32 -27
- package/dist/lib/ast/features/prefix.d.ts +8 -0
- package/dist/lib/ast/features/prefix.js +68 -43
- package/dist/lib/ast/features/shorthand.d.ts +12 -0
- package/dist/lib/ast/features/shorthand.js +6 -9
- package/dist/lib/ast/features/transform.d.ts +10 -0
- package/dist/lib/ast/features/transform.js +9 -13
- package/dist/lib/ast/features/type.d.ts +15 -0
- package/dist/lib/ast/find.d.ts +165 -0
- package/dist/lib/ast/find.js +175 -0
- package/dist/lib/ast/math/expression.d.ts +18 -0
- package/dist/lib/ast/math/expression.js +140 -98
- package/dist/lib/ast/math/math.d.ts +6 -0
- package/dist/lib/ast/math/math.js +30 -41
- package/dist/lib/ast/minify.d.ts +19 -0
- package/dist/lib/ast/minify.js +543 -215
- package/dist/lib/ast/transform/compute.d.ts +8 -0
- package/dist/lib/ast/transform/compute.js +82 -69
- package/dist/lib/ast/transform/matrix.d.ts +22 -0
- package/dist/lib/ast/transform/matrix.js +12 -26
- package/dist/lib/ast/transform/minify.d.ts +5 -0
- package/dist/lib/ast/transform/minify.js +20 -20
- package/dist/lib/ast/transform/perspective.d.ts +3 -0
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.d.ts +12 -0
- package/dist/lib/ast/transform/rotate.js +1 -1
- package/dist/lib/ast/transform/scale.d.ts +6 -0
- package/dist/lib/ast/transform/scale.js +1 -1
- package/dist/lib/ast/transform/skew.d.ts +4 -0
- package/dist/lib/ast/transform/skew.js +1 -1
- package/dist/lib/ast/transform/translate.d.ts +6 -0
- package/dist/lib/ast/transform/translate.js +1 -1
- package/dist/lib/ast/transform/utils.d.ts +9 -0
- package/dist/lib/ast/types.d.ts +903 -0
- package/dist/lib/ast/types.js +277 -23
- package/dist/lib/ast/walk.d.ts +162 -0
- package/dist/lib/ast/walk.js +116 -60
- package/dist/lib/fs/resolve.d.ts +20 -0
- package/dist/lib/fs/resolve.js +37 -45
- package/dist/lib/parser/declaration/list.d.ts +16 -0
- package/dist/lib/parser/declaration/list.js +26 -24
- package/dist/lib/parser/declaration/map.d.ts +15 -0
- package/dist/lib/parser/declaration/map.js +140 -95
- package/dist/lib/parser/declaration/set.d.ts +9 -0
- package/dist/lib/parser/declaration/set.js +30 -25
- package/dist/lib/parser/node.d.ts +7 -0
- package/dist/lib/parser/parse.d.ts +107 -0
- package/dist/lib/parser/parse.js +1454 -1445
- package/dist/lib/parser/tokenize.d.ts +57 -0
- package/dist/lib/parser/tokenize.js +557 -404
- package/dist/lib/parser/utils/at-rule-container.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-container.js +486 -0
- package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
- package/dist/lib/parser/utils/at-rule-generic.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-generic.js +118 -0
- package/dist/lib/parser/utils/at-rule-import.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-import.js +393 -0
- package/dist/lib/parser/utils/at-rule-media.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-media.js +603 -0
- package/dist/lib/parser/utils/at-rule-page.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-page.js +28 -0
- package/dist/lib/parser/utils/at-rule-support.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-support.js +366 -0
- package/dist/lib/parser/utils/at-rule-token.d.ts +1 -0
- package/dist/lib/parser/utils/at-rule-when-else.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
- package/dist/lib/parser/utils/at-rule.d.ts +13 -0
- package/dist/lib/parser/utils/at-rule.js +37 -0
- package/dist/lib/parser/utils/cache.d.ts +6 -0
- package/dist/lib/parser/utils/cache.js +19 -0
- package/dist/lib/parser/utils/config.d.ts +2 -0
- package/dist/lib/parser/utils/config.js +1 -0
- package/dist/lib/parser/utils/declaration-list.d.ts +5 -0
- package/dist/lib/parser/utils/declaration.d.ts +18 -0
- package/dist/lib/parser/utils/declaration.js +569 -91
- package/dist/lib/parser/utils/eq.d.ts +1 -0
- package/dist/lib/parser/utils/hash.d.ts +21 -0
- package/dist/lib/parser/utils/hash.js +1 -1
- package/dist/lib/parser/utils/selector.d.ts +5 -0
- package/dist/lib/parser/utils/selector.js +476 -0
- package/dist/lib/parser/utils/text.d.ts +3 -0
- package/dist/lib/parser/utils/text.js +17 -1
- package/dist/lib/parser/utils/token.d.ts +14 -0
- package/dist/lib/parser/utils/token.js +102 -0
- package/dist/lib/parser/utils/type.d.ts +2 -0
- package/dist/lib/parser/utils/type.js +29 -18
- package/dist/lib/renderer/render.d.ts +28 -0
- package/dist/lib/renderer/render.js +421 -262
- package/dist/lib/renderer/sourcemap/lib/encode.d.ts +1 -0
- package/dist/lib/renderer/sourcemap/sourcemap.d.ts +26 -0
- package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
- package/dist/lib/syntax/color/a98rgb.d.ts +2 -0
- package/dist/lib/syntax/color/a98rgb.js +8 -12
- package/dist/lib/syntax/color/cmyk.d.ts +10 -0
- package/dist/lib/syntax/color/cmyk.js +23 -21
- package/dist/lib/syntax/color/color-mix.d.ts +2 -0
- package/dist/lib/syntax/color/color-mix.js +88 -77
- package/dist/lib/syntax/color/color.d.ts +42 -0
- package/dist/lib/syntax/color/color.js +65 -68
- package/dist/lib/syntax/color/hex.d.ts +16 -0
- package/dist/lib/syntax/color/hex.js +27 -31
- package/dist/lib/syntax/color/hsl.d.ts +20 -0
- package/dist/lib/syntax/color/hsl.js +5 -12
- package/dist/lib/syntax/color/hsv.d.ts +2 -0
- package/dist/lib/syntax/color/hwb.d.ts +21 -0
- package/dist/lib/syntax/color/hwb.js +8 -21
- package/dist/lib/syntax/color/lab.d.ts +25 -0
- package/dist/lib/syntax/color/lab.js +20 -21
- package/dist/lib/syntax/color/lch.d.ts +23 -0
- package/dist/lib/syntax/color/lch.js +13 -15
- package/dist/lib/syntax/color/oklab.d.ts +22 -0
- package/dist/lib/syntax/color/oklab.js +20 -39
- package/dist/lib/syntax/color/oklch.d.ts +20 -0
- package/dist/lib/syntax/color/oklch.js +14 -16
- package/dist/lib/syntax/color/p3.d.ts +6 -0
- package/dist/lib/syntax/color/p3.js +0 -8
- package/dist/lib/syntax/color/prophotorgb.d.ts +2 -0
- package/dist/lib/syntax/color/rec2020.d.ts +2 -0
- package/dist/lib/syntax/color/rec2020.js +9 -13
- package/dist/lib/syntax/color/relativecolor.d.ts +13 -0
- package/dist/lib/syntax/color/relativecolor.js +68 -41
- package/dist/lib/syntax/color/rgb.d.ts +20 -0
- package/dist/lib/syntax/color/rgb.js +14 -18
- package/dist/lib/syntax/color/srgb.d.ts +23 -0
- package/dist/lib/syntax/color/srgb.js +27 -26
- package/dist/lib/syntax/color/utils/components.d.ts +2 -0
- package/dist/lib/syntax/color/utils/components.js +30 -14
- package/dist/lib/syntax/color/utils/distance.d.ts +18 -0
- package/dist/lib/syntax/color/utils/distance.js +1 -8
- package/dist/lib/syntax/color/utils/matrix.d.ts +6 -0
- package/dist/lib/syntax/color/xyz.d.ts +5 -0
- package/dist/lib/syntax/color/xyz.js +8 -20
- package/dist/lib/syntax/color/xyzd50.d.ts +4 -0
- package/dist/lib/syntax/color/xyzd50.js +6 -20
- package/dist/lib/syntax/constants.d.ts +67 -0
- package/dist/lib/syntax/constants.js +436 -0
- package/dist/lib/syntax/syntax.d.ts +38 -0
- package/dist/lib/syntax/syntax.js +533 -568
- package/dist/lib/validation/config.d.ts +14 -0
- package/dist/lib/validation/config.js +72 -33
- package/dist/lib/validation/config.json.js +1159 -74
- package/dist/lib/validation/json.d.ts +2 -0
- package/dist/lib/validation/match.d.ts +38 -0
- package/dist/lib/validation/match.js +2985 -0
- package/dist/lib/validation/parser/parse.d.ts +8 -0
- package/dist/lib/validation/parser/parse.js +684 -935
- package/dist/lib/validation/parser/typedef.d.ts +95 -0
- package/dist/lib/validation/parser/typedef.js +100 -0
- package/dist/lib/validation/utils/list.d.ts +4 -0
- package/dist/lib/validation/utils/list.js +4 -11
- package/dist/lib/validation/utils/whitespace.d.ts +2 -0
- package/dist/lib/validation/utils/whitespace.js +2 -8
- package/dist/node.d.ts +207 -0
- package/dist/node.js +53 -47
- package/dist/web.d.ts +169 -0
- package/dist/web.js +50 -41
- package/package.json +18 -13
- package/playground/index.html +1328 -0
- package/playground/sw.js +55 -0
- package/playground/tree.js +176 -0
- package/dist/lib/syntax/color/utils/constants.js +0 -214
- package/dist/lib/syntax/utils.js +0 -70
- package/dist/lib/validation/at-rules/container.js +0 -342
- package/dist/lib/validation/at-rules/counter-style.js +0 -90
- package/dist/lib/validation/at-rules/custom-media.js +0 -50
- package/dist/lib/validation/at-rules/document.js +0 -89
- package/dist/lib/validation/at-rules/else.js +0 -5
- package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
- package/dist/lib/validation/at-rules/import.js +0 -150
- package/dist/lib/validation/at-rules/keyframes.js +0 -67
- package/dist/lib/validation/at-rules/layer.js +0 -41
- package/dist/lib/validation/at-rules/media.js +0 -255
- package/dist/lib/validation/at-rules/namespace.js +0 -81
- package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
- package/dist/lib/validation/at-rules/page.js +0 -100
- package/dist/lib/validation/at-rules/supports.js +0 -295
- package/dist/lib/validation/at-rules/when.js +0 -185
- package/dist/lib/validation/atrule.js +0 -184
- package/dist/lib/validation/selector.js +0 -36
- package/dist/lib/validation/syntax.js +0 -1073
- package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
- package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
- package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
- package/dist/lib/validation/syntaxes/family-name.js +0 -57
- package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
- package/dist/lib/validation/syntaxes/layer-name.js +0 -57
- package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
- package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
- package/dist/lib/validation/syntaxes/selector-list.js +0 -5
- package/dist/lib/validation/syntaxes/selector.js +0 -5
- package/dist/lib/validation/syntaxes/url.js +0 -40
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Token } from "../../../@types/token.d.ts";
|
|
2
|
+
import type { Matrix } from "./type.d.ts";
|
|
3
|
+
export declare function compute(transformLists: Token[]): {
|
|
4
|
+
matrix: Token;
|
|
5
|
+
cumulative: Token[];
|
|
6
|
+
minified: Token[];
|
|
7
|
+
} | null;
|
|
8
|
+
export declare function computeMatrix(transformList: Token[], matrixVar: Matrix): Matrix | null;
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
import { multiply, toZero, identity } from './utils.js';
|
|
2
|
-
import { EnumToken } from '../types.js';
|
|
3
|
-
import { transformFunctions } from '../../syntax/syntax.js';
|
|
4
|
-
import { length2Px } from '../../syntax/utils.js';
|
|
5
|
-
import '../minify.js';
|
|
6
|
-
import '../walk.js';
|
|
7
|
-
import '../../parser/parse.js';
|
|
8
|
-
import '../../parser/tokenize.js';
|
|
9
|
-
import '../../parser/utils/config.js';
|
|
10
|
-
import { getNumber, getAngle } from '../../syntax/color/color.js';
|
|
11
|
-
import '../../syntax/color/utils/constants.js';
|
|
12
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
2
|
+
import { EnumToken, length2Px } from '../types.js';
|
|
13
3
|
import { stripCommaToken } from '../../validation/utils/list.js';
|
|
14
4
|
import { translateX, translateY, translateZ, translate, translate3d } from './translate.js';
|
|
5
|
+
import { getNumber, getAngle } from '../../syntax/color/color.js';
|
|
15
6
|
import { rotate, rotate3D } from './rotate.js';
|
|
16
7
|
import { scale3d, scale, scaleX, scaleY, scaleZ } from './scale.js';
|
|
17
8
|
import { minify } from './minify.js';
|
|
18
9
|
import { skew, skewX, skewY } from './skew.js';
|
|
19
10
|
import { serialize, matrix } from './matrix.js';
|
|
20
11
|
import { perspective } from './perspective.js';
|
|
12
|
+
import { transformFunctions } from '../../syntax/constants.js';
|
|
21
13
|
|
|
22
14
|
function compute(transformLists) {
|
|
23
15
|
transformLists = transformLists.slice();
|
|
@@ -36,20 +28,21 @@ function compute(transformLists) {
|
|
|
36
28
|
const serialized = serialize(matrix);
|
|
37
29
|
if (cumulative.length > 0) {
|
|
38
30
|
for (let i = 0; i < cumulative.length; i++) {
|
|
39
|
-
if (cumulative[i].typ == EnumToken.IdenTokenType && cumulative[i].val ==
|
|
31
|
+
if (cumulative[i].typ == EnumToken.IdenTokenType && cumulative[i].val == "none") {
|
|
40
32
|
cumulative.splice(i--, 1);
|
|
41
33
|
}
|
|
42
34
|
}
|
|
43
35
|
if (cumulative.length == 0) {
|
|
44
36
|
cumulative.push({
|
|
45
|
-
typ: EnumToken.IdenTokenType,
|
|
37
|
+
typ: EnumToken.IdenTokenType,
|
|
38
|
+
val: "none",
|
|
46
39
|
});
|
|
47
40
|
}
|
|
48
41
|
}
|
|
49
42
|
return {
|
|
50
43
|
matrix: serialize(toZero(matrix)),
|
|
51
44
|
cumulative,
|
|
52
|
-
minified: minify(matrix) ?? [serialized]
|
|
45
|
+
minified: minify(matrix) ?? [serialized],
|
|
53
46
|
};
|
|
54
47
|
}
|
|
55
48
|
function computeMatrix(transformList, matrixVar) {
|
|
@@ -57,19 +50,24 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
57
50
|
let val;
|
|
58
51
|
let i = 0;
|
|
59
52
|
for (; i < transformList.length; i++) {
|
|
60
|
-
if (transformList[i].typ != EnumToken.
|
|
53
|
+
if (transformList[i].typ != EnumToken.TransformFunctionTokenType ||
|
|
54
|
+
!transformFunctions.includes(transformList[i].val)) {
|
|
61
55
|
return null;
|
|
62
56
|
}
|
|
63
57
|
switch (transformList[i].val) {
|
|
64
|
-
case
|
|
65
|
-
case
|
|
66
|
-
case
|
|
67
|
-
case
|
|
68
|
-
case
|
|
58
|
+
case "translate":
|
|
59
|
+
case "translateX":
|
|
60
|
+
case "translateY":
|
|
61
|
+
case "translateZ":
|
|
62
|
+
case "translate3d":
|
|
69
63
|
{
|
|
70
64
|
values.length = 0;
|
|
71
65
|
const children = stripCommaToken(transformList[i].chi.slice());
|
|
72
|
-
const valCount = transformList[i].val ==
|
|
66
|
+
const valCount = transformList[i].val == "translate3d"
|
|
67
|
+
? 3
|
|
68
|
+
: transformList[i].val == "translate"
|
|
69
|
+
? 2
|
|
70
|
+
: 1;
|
|
73
71
|
for (let j = 0; j < children.length; j++) {
|
|
74
72
|
if (children[j].typ == EnumToken.WhitespaceTokenType) {
|
|
75
73
|
continue;
|
|
@@ -83,16 +81,16 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
83
81
|
if (values.length == 0 || values.length > valCount) {
|
|
84
82
|
return null;
|
|
85
83
|
}
|
|
86
|
-
if (transformList[i].val ==
|
|
84
|
+
if (transformList[i].val == "translateX") {
|
|
87
85
|
matrixVar = translateX(values[0], matrixVar);
|
|
88
86
|
}
|
|
89
|
-
else if (transformList[i].val ==
|
|
87
|
+
else if (transformList[i].val == "translateY") {
|
|
90
88
|
matrixVar = translateY(values[0], matrixVar);
|
|
91
89
|
}
|
|
92
|
-
else if (transformList[i].val ==
|
|
90
|
+
else if (transformList[i].val == "translateZ") {
|
|
93
91
|
matrixVar = translateZ(values[0], matrixVar);
|
|
94
92
|
}
|
|
95
|
-
else if (transformList[i].val ==
|
|
93
|
+
else if (transformList[i].val == "translate") {
|
|
96
94
|
matrixVar = translate(values, matrixVar);
|
|
97
95
|
}
|
|
98
96
|
else {
|
|
@@ -101,43 +99,45 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
101
99
|
}
|
|
102
100
|
}
|
|
103
101
|
break;
|
|
104
|
-
case
|
|
105
|
-
case
|
|
106
|
-
case
|
|
107
|
-
case
|
|
108
|
-
case
|
|
102
|
+
case "rotate":
|
|
103
|
+
case "rotateX":
|
|
104
|
+
case "rotateY":
|
|
105
|
+
case "rotateZ":
|
|
106
|
+
case "rotate3d":
|
|
109
107
|
{
|
|
110
108
|
let x = 0;
|
|
111
109
|
let y = 0;
|
|
112
110
|
let z = 0;
|
|
113
111
|
let angle;
|
|
114
112
|
let values = [];
|
|
115
|
-
let valuesCount = transformList[i].val ==
|
|
113
|
+
let valuesCount = transformList[i].val == "rotate3d" ? 4 : 1;
|
|
116
114
|
for (const child of stripCommaToken(transformList[i].chi.slice())) {
|
|
117
115
|
values.push(child);
|
|
118
|
-
if (transformList[i].val ==
|
|
116
|
+
if (transformList[i].val == "rotateX") {
|
|
119
117
|
x = 1;
|
|
120
118
|
}
|
|
121
|
-
else if (transformList[i].val ==
|
|
119
|
+
else if (transformList[i].val == "rotateY") {
|
|
122
120
|
y = 1;
|
|
123
121
|
}
|
|
124
|
-
else if (transformList[i].val ==
|
|
122
|
+
else if (transformList[i].val == "rotate" ||
|
|
123
|
+
transformList[i].val == "rotateZ") {
|
|
125
124
|
z = 1;
|
|
126
125
|
}
|
|
127
126
|
}
|
|
128
127
|
if (values.length != valuesCount) {
|
|
129
128
|
return null;
|
|
130
129
|
}
|
|
131
|
-
if (transformList[i].val ==
|
|
130
|
+
if (transformList[i].val == "rotate3d") {
|
|
132
131
|
x = getNumber(values[0]);
|
|
133
132
|
y = getNumber(values[1]);
|
|
134
133
|
z = getNumber(values[2]);
|
|
135
134
|
}
|
|
136
135
|
angle = getAngle(values.at(-1));
|
|
137
|
-
if ([x, y, z, angle].some(t => typeof t !=
|
|
136
|
+
if ([x, y, z, angle].some((t) => typeof t != "number" || Number.isNaN(+t))) {
|
|
138
137
|
return null;
|
|
139
138
|
}
|
|
140
|
-
if (transformList[i].val ==
|
|
139
|
+
if (transformList[i].val == "rotate" ||
|
|
140
|
+
transformList[i].val == "rotateZ") {
|
|
141
141
|
matrixVar = rotate(angle * 2 * Math.PI, matrixVar);
|
|
142
142
|
}
|
|
143
143
|
else {
|
|
@@ -145,11 +145,11 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
break;
|
|
148
|
-
case
|
|
149
|
-
case
|
|
150
|
-
case
|
|
151
|
-
case
|
|
152
|
-
case
|
|
148
|
+
case "scale":
|
|
149
|
+
case "scaleX":
|
|
150
|
+
case "scaleY":
|
|
151
|
+
case "scaleZ":
|
|
152
|
+
case "scale3d":
|
|
153
153
|
{
|
|
154
154
|
values.length = 0;
|
|
155
155
|
let child;
|
|
@@ -161,14 +161,14 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
161
161
|
}
|
|
162
162
|
values.push(getNumber(child));
|
|
163
163
|
}
|
|
164
|
-
if (transformList[i].val ==
|
|
164
|
+
if (transformList[i].val == "scale3d") {
|
|
165
165
|
if (values.length != 3) {
|
|
166
166
|
return null;
|
|
167
167
|
}
|
|
168
168
|
matrixVar = scale3d(...values, matrixVar);
|
|
169
169
|
break;
|
|
170
170
|
}
|
|
171
|
-
if (transformList[i].val ==
|
|
171
|
+
if (transformList[i].val == "scale") {
|
|
172
172
|
if (values.length != 1 && values.length != 2) {
|
|
173
173
|
return null;
|
|
174
174
|
}
|
|
@@ -178,20 +178,20 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
178
178
|
if (values.length != 1) {
|
|
179
179
|
return null;
|
|
180
180
|
}
|
|
181
|
-
else if (transformList[i].val ==
|
|
181
|
+
else if (transformList[i].val == "scaleX") {
|
|
182
182
|
matrixVar = scaleX(values[0], matrixVar);
|
|
183
183
|
}
|
|
184
|
-
else if (transformList[i].val ==
|
|
184
|
+
else if (transformList[i].val == "scaleY") {
|
|
185
185
|
matrixVar = scaleY(values[0], matrixVar);
|
|
186
186
|
}
|
|
187
|
-
else if (transformList[i].val ==
|
|
187
|
+
else if (transformList[i].val == "scaleZ") {
|
|
188
188
|
matrixVar = scaleZ(values[0], matrixVar);
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
break;
|
|
192
|
-
case
|
|
193
|
-
case
|
|
194
|
-
case
|
|
192
|
+
case "skew":
|
|
193
|
+
case "skewX":
|
|
194
|
+
case "skewY":
|
|
195
195
|
{
|
|
196
196
|
values.length = 0;
|
|
197
197
|
let child;
|
|
@@ -206,18 +206,22 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
206
206
|
value = getAngle(child);
|
|
207
207
|
values.push(value * 2 * Math.PI);
|
|
208
208
|
}
|
|
209
|
-
if (values.length == 0 ||
|
|
209
|
+
if (values.length == 0 ||
|
|
210
|
+
values.length > (transformList[i].val == "skew" ? 2 : 1)) {
|
|
210
211
|
return null;
|
|
211
212
|
}
|
|
212
|
-
if (transformList[i].val ==
|
|
213
|
+
if (transformList[i].val == "skew") {
|
|
213
214
|
matrixVar = skew(values, matrixVar);
|
|
214
215
|
}
|
|
215
216
|
else {
|
|
216
|
-
matrixVar =
|
|
217
|
+
matrixVar =
|
|
218
|
+
transformList[i].val == "skewX"
|
|
219
|
+
? skewX(values[0], matrixVar)
|
|
220
|
+
: skewY(values[0], matrixVar);
|
|
217
221
|
}
|
|
218
222
|
}
|
|
219
223
|
break;
|
|
220
|
-
case
|
|
224
|
+
case "perspective":
|
|
221
225
|
{
|
|
222
226
|
const values = [];
|
|
223
227
|
let child;
|
|
@@ -227,7 +231,7 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
227
231
|
if (child.typ == EnumToken.CommentTokenType || child.typ == EnumToken.WhitespaceTokenType) {
|
|
228
232
|
continue;
|
|
229
233
|
}
|
|
230
|
-
if (child.typ == EnumToken.IdenTokenType && child.val ==
|
|
234
|
+
if (child.typ == EnumToken.IdenTokenType && child.val == "none") {
|
|
231
235
|
values.push(child);
|
|
232
236
|
continue;
|
|
233
237
|
}
|
|
@@ -243,13 +247,17 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
243
247
|
matrixVar = perspective(values[0], matrixVar);
|
|
244
248
|
}
|
|
245
249
|
break;
|
|
246
|
-
case
|
|
247
|
-
case
|
|
250
|
+
case "matrix3d":
|
|
251
|
+
case "matrix":
|
|
248
252
|
{
|
|
249
253
|
const values = [];
|
|
250
254
|
let value;
|
|
251
255
|
for (const token of transformList[i].chi) {
|
|
252
|
-
if ([
|
|
256
|
+
if ([
|
|
257
|
+
EnumToken.WhitespaceTokenType,
|
|
258
|
+
EnumToken.CommentTokenType,
|
|
259
|
+
EnumToken.CommaTokenType,
|
|
260
|
+
].includes(token.typ)) {
|
|
253
261
|
continue;
|
|
254
262
|
}
|
|
255
263
|
value = getNumber(token);
|
|
@@ -258,7 +266,7 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
258
266
|
}
|
|
259
267
|
values.push(value);
|
|
260
268
|
}
|
|
261
|
-
if (transformList[i].val ==
|
|
269
|
+
if (transformList[i].val == "matrix") {
|
|
262
270
|
if (values.length != 6) {
|
|
263
271
|
return null;
|
|
264
272
|
}
|
|
@@ -279,19 +287,22 @@ function splitTransformList(transformList) {
|
|
|
279
287
|
let pattern = null;
|
|
280
288
|
const tokens = [];
|
|
281
289
|
for (let i = 0; i < transformList.length; i++) {
|
|
282
|
-
if (transformList[i].typ == EnumToken.CommentTokenType ||
|
|
290
|
+
if (transformList[i].typ == EnumToken.CommentTokenType ||
|
|
291
|
+
transformList[i].typ == EnumToken.WhitespaceTokenType) {
|
|
283
292
|
continue;
|
|
284
293
|
}
|
|
285
|
-
if (pattern == null ||
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
294
|
+
if (pattern == null ||
|
|
295
|
+
(transformList[i].typ == EnumToken.TransformFunctionTokenType &&
|
|
296
|
+
!transformList[i].val.startsWith(pattern))) {
|
|
297
|
+
if (transformList[i].typ == EnumToken.TransformFunctionTokenType) {
|
|
298
|
+
if (transformList[i].val.startsWith("scale")) {
|
|
299
|
+
pattern = "scale";
|
|
289
300
|
}
|
|
290
|
-
else if (transformList[i].val.startsWith(
|
|
291
|
-
pattern =
|
|
301
|
+
else if (transformList[i].val.startsWith("rotate")) {
|
|
302
|
+
pattern = "rotate";
|
|
292
303
|
}
|
|
293
|
-
else if (transformList[i].val.startsWith(
|
|
294
|
-
pattern =
|
|
304
|
+
else if (transformList[i].val.startsWith("translate")) {
|
|
305
|
+
pattern = "translate";
|
|
295
306
|
}
|
|
296
307
|
else {
|
|
297
308
|
pattern = null;
|
|
@@ -300,7 +311,9 @@ function splitTransformList(transformList) {
|
|
|
300
311
|
continue;
|
|
301
312
|
}
|
|
302
313
|
}
|
|
303
|
-
if (pattern != null &&
|
|
314
|
+
if (pattern != null &&
|
|
315
|
+
transformList[i].typ == EnumToken.TransformFunctionTokenType &&
|
|
316
|
+
transformList[i].val.startsWith(pattern)) {
|
|
304
317
|
tokens[tokens.length - 1].push(transformList[i]);
|
|
305
318
|
continue;
|
|
306
319
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FunctionToken, IdentToken, Token } from "../../../@types/index.d.ts";
|
|
2
|
+
import type { Matrix } from "./type.d.ts";
|
|
3
|
+
export declare function parseMatrix(mat: FunctionToken | IdentToken): Matrix | null;
|
|
4
|
+
export declare function matrix(values: [number, number, number, number, number, number] | [
|
|
5
|
+
number,
|
|
6
|
+
number,
|
|
7
|
+
number,
|
|
8
|
+
number,
|
|
9
|
+
number,
|
|
10
|
+
number,
|
|
11
|
+
number,
|
|
12
|
+
number,
|
|
13
|
+
number,
|
|
14
|
+
number,
|
|
15
|
+
number,
|
|
16
|
+
number,
|
|
17
|
+
number,
|
|
18
|
+
number,
|
|
19
|
+
number,
|
|
20
|
+
number
|
|
21
|
+
]): Matrix | null;
|
|
22
|
+
export declare function serialize(matrix: Matrix): Token;
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { identity, is2DMatrix } from './utils.js';
|
|
2
2
|
import { EnumToken } from '../types.js';
|
|
3
3
|
import { eq } from '../../parser/utils/eq.js';
|
|
4
4
|
import { getNumber } from '../../syntax/color/color.js';
|
|
5
|
-
import '../../syntax/color/utils/constants.js';
|
|
6
|
-
import '../minify.js';
|
|
7
|
-
import '../walk.js';
|
|
8
|
-
import '../../parser/parse.js';
|
|
9
|
-
import '../../parser/tokenize.js';
|
|
10
|
-
import '../../parser/utils/config.js';
|
|
11
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
12
5
|
|
|
13
6
|
function parseMatrix(mat) {
|
|
14
7
|
if (mat.typ == EnumToken.IdenTokenType) {
|
|
15
|
-
return mat.val ==
|
|
8
|
+
return mat.val == "none" ? identity() : null;
|
|
16
9
|
}
|
|
17
10
|
const children = mat.chi.filter((t) => t.typ == EnumToken.NumberTokenType || t.typ == EnumToken.IdenTokenType);
|
|
18
11
|
const values = [];
|
|
@@ -66,46 +59,39 @@ function serialize(matrix) {
|
|
|
66
59
|
if (eq(matrix, identity())) {
|
|
67
60
|
return {
|
|
68
61
|
typ: EnumToken.IdenTokenType,
|
|
69
|
-
val:
|
|
62
|
+
val: "none",
|
|
70
63
|
};
|
|
71
64
|
}
|
|
72
65
|
if (is2DMatrix(matrix)) {
|
|
73
66
|
// https://drafts.csswg.org/css-transforms-2/#two-dimensional-subset
|
|
74
67
|
return {
|
|
75
|
-
typ: EnumToken.
|
|
76
|
-
val:
|
|
77
|
-
chi: [
|
|
78
|
-
matrix[0],
|
|
79
|
-
matrix[1],
|
|
80
|
-
matrix[4],
|
|
81
|
-
matrix[4 + 1],
|
|
82
|
-
matrix[3 * 4],
|
|
83
|
-
matrix[3 * 4 + 1]
|
|
84
|
-
].reduce((acc, t) => {
|
|
68
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
69
|
+
val: "matrix",
|
|
70
|
+
chi: [matrix[0], matrix[1], matrix[4], matrix[4 + 1], matrix[3 * 4], matrix[3 * 4 + 1]].reduce((acc, t) => {
|
|
85
71
|
if (acc.length > 0) {
|
|
86
72
|
acc.push({ typ: EnumToken.CommaTokenType });
|
|
87
73
|
}
|
|
88
74
|
acc.push({
|
|
89
75
|
typ: EnumToken.NumberTokenType,
|
|
90
|
-
val: t
|
|
76
|
+
val: t,
|
|
91
77
|
});
|
|
92
78
|
return acc;
|
|
93
|
-
}, [])
|
|
79
|
+
}, []),
|
|
94
80
|
};
|
|
95
81
|
}
|
|
96
82
|
return {
|
|
97
|
-
typ: EnumToken.
|
|
98
|
-
val:
|
|
83
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
84
|
+
val: "matrix3d",
|
|
99
85
|
chi: matrix.reduce((acc, curr) => {
|
|
100
86
|
if (acc.length > 0) {
|
|
101
87
|
acc.push({ typ: EnumToken.CommaTokenType });
|
|
102
88
|
}
|
|
103
89
|
acc.push({
|
|
104
90
|
typ: EnumToken.NumberTokenType,
|
|
105
|
-
val: curr
|
|
91
|
+
val: curr,
|
|
106
92
|
});
|
|
107
93
|
return acc;
|
|
108
|
-
}, [])
|
|
94
|
+
}, []),
|
|
109
95
|
};
|
|
110
96
|
}
|
|
111
97
|
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { FunctionToken, Token } from "../../../@types/index.d.ts";
|
|
2
|
+
import type { Matrix } from "./type.d.ts";
|
|
3
|
+
export declare function minify(matrix: Matrix): Token[] | null;
|
|
4
|
+
export declare function eqMatrix(a: FunctionToken | Matrix, b: Token[]): boolean;
|
|
5
|
+
export declare function minifyTransformFunctions(transform: FunctionToken): FunctionToken;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { multiply,
|
|
1
|
+
import { multiply, epsilon, decompose, round, toZero, identity } from './utils.js';
|
|
2
2
|
import { EnumToken } from '../types.js';
|
|
3
3
|
import { computeMatrix } from './compute.js';
|
|
4
4
|
import { parseMatrix } from './matrix.js';
|
|
@@ -39,7 +39,7 @@ function minify(matrix) {
|
|
|
39
39
|
if (coordinates.size == 1) {
|
|
40
40
|
if (coordinates.has('x')) {
|
|
41
41
|
result.push({
|
|
42
|
-
typ: EnumToken.
|
|
42
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
43
43
|
val: 'translate',
|
|
44
44
|
chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: 'px' }]
|
|
45
45
|
});
|
|
@@ -48,7 +48,7 @@ function minify(matrix) {
|
|
|
48
48
|
let axis = coordinates.has('y') ? 'y' : 'z';
|
|
49
49
|
let index = axis == 'y' ? 1 : 2;
|
|
50
50
|
result.push({
|
|
51
|
-
typ: EnumToken.
|
|
51
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
52
52
|
val: 'translate' + axis.toUpperCase(),
|
|
53
53
|
chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[index]), unit: 'px' }]
|
|
54
54
|
});
|
|
@@ -56,7 +56,7 @@ function minify(matrix) {
|
|
|
56
56
|
}
|
|
57
57
|
else if (coordinates.has('z')) {
|
|
58
58
|
result.push({
|
|
59
|
-
typ: EnumToken.
|
|
59
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
60
60
|
val: 'translate3d',
|
|
61
61
|
chi: [
|
|
62
62
|
decomposed.translate[0] == 0 ? {
|
|
@@ -75,7 +75,7 @@ function minify(matrix) {
|
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
77
|
result.push({
|
|
78
|
-
typ: EnumToken.
|
|
78
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
79
79
|
val: 'translate',
|
|
80
80
|
chi: [
|
|
81
81
|
{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: 'px' },
|
|
@@ -89,7 +89,7 @@ function minify(matrix) {
|
|
|
89
89
|
const [x, y, z, angle] = decomposed.rotate;
|
|
90
90
|
if (y == 0 && z == 0) {
|
|
91
91
|
result.push({
|
|
92
|
-
typ: EnumToken.
|
|
92
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
93
93
|
val: 'rotateX',
|
|
94
94
|
chi: [
|
|
95
95
|
{
|
|
@@ -102,7 +102,7 @@ function minify(matrix) {
|
|
|
102
102
|
}
|
|
103
103
|
else if (x == 0 && z == 0) {
|
|
104
104
|
result.push({
|
|
105
|
-
typ: EnumToken.
|
|
105
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
106
106
|
val: 'rotateY',
|
|
107
107
|
chi: [
|
|
108
108
|
{
|
|
@@ -115,7 +115,7 @@ function minify(matrix) {
|
|
|
115
115
|
}
|
|
116
116
|
else if (x == 0 && y == 0) {
|
|
117
117
|
result.push({
|
|
118
|
-
typ: EnumToken.
|
|
118
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
119
119
|
val: 'rotate',
|
|
120
120
|
chi: [
|
|
121
121
|
{
|
|
@@ -128,7 +128,7 @@ function minify(matrix) {
|
|
|
128
128
|
}
|
|
129
129
|
else {
|
|
130
130
|
result.push({
|
|
131
|
-
typ: EnumToken.
|
|
131
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
132
132
|
val: 'rotate3d',
|
|
133
133
|
chi: [
|
|
134
134
|
{
|
|
@@ -164,7 +164,7 @@ function minify(matrix) {
|
|
|
164
164
|
}
|
|
165
165
|
if (skew.size == 1) {
|
|
166
166
|
result.push({
|
|
167
|
-
typ: EnumToken.
|
|
167
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
168
168
|
val: 'skew' + (skew.has('x') ? '' : 'Y'),
|
|
169
169
|
chi: [
|
|
170
170
|
{ typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: 'deg' }
|
|
@@ -173,7 +173,7 @@ function minify(matrix) {
|
|
|
173
173
|
}
|
|
174
174
|
else {
|
|
175
175
|
result.push({
|
|
176
|
-
typ: EnumToken.
|
|
176
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
177
177
|
val: 'skew',
|
|
178
178
|
chi: [
|
|
179
179
|
{ typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: 'deg' },
|
|
@@ -197,7 +197,7 @@ function minify(matrix) {
|
|
|
197
197
|
if (scales.size == 1) {
|
|
198
198
|
let prefix = scales.has('x') ? 'X' : scales.has('y') ? 'Y' : 'Z';
|
|
199
199
|
result.push({
|
|
200
|
-
typ: EnumToken.
|
|
200
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
201
201
|
val: 'scale' + prefix,
|
|
202
202
|
chi: [
|
|
203
203
|
{ typ: EnumToken.NumberTokenType, val: round(prefix == 'Z' ? sz : prefix == 'Y' ? sy : sx) }
|
|
@@ -206,7 +206,7 @@ function minify(matrix) {
|
|
|
206
206
|
}
|
|
207
207
|
else if (!scales.has('z')) {
|
|
208
208
|
result.push({
|
|
209
|
-
typ: EnumToken.
|
|
209
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
210
210
|
val: 'scale',
|
|
211
211
|
chi: [
|
|
212
212
|
{ typ: EnumToken.NumberTokenType, val: round(sx) },
|
|
@@ -217,7 +217,7 @@ function minify(matrix) {
|
|
|
217
217
|
}
|
|
218
218
|
else {
|
|
219
219
|
result.push({
|
|
220
|
-
typ: EnumToken.
|
|
220
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
221
221
|
val: 'scale3d',
|
|
222
222
|
chi: [
|
|
223
223
|
{ typ: EnumToken.NumberTokenType, val: round(sx) },
|
|
@@ -296,7 +296,7 @@ function minifyTransformFunctions(transform) {
|
|
|
296
296
|
if (name == 'translate3d' || name == 'translate') {
|
|
297
297
|
if (t.size == 0) {
|
|
298
298
|
return {
|
|
299
|
-
typ: EnumToken.
|
|
299
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
300
300
|
val: 'translate',
|
|
301
301
|
chi: [
|
|
302
302
|
{ typ: EnumToken.NumberTokenType, val: 0 }
|
|
@@ -305,7 +305,7 @@ function minifyTransformFunctions(transform) {
|
|
|
305
305
|
}
|
|
306
306
|
if (t.size == 1) {
|
|
307
307
|
return {
|
|
308
|
-
typ: EnumToken.
|
|
308
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
309
309
|
val: 'translate' + (t.has('x') ? '' : t.has('y') ? 'Y' : 'Z'),
|
|
310
310
|
chi: [
|
|
311
311
|
values[t.has('x') ? 0 : t.has('y') ? 1 : 2]
|
|
@@ -317,7 +317,7 @@ function minifyTransformFunctions(transform) {
|
|
|
317
317
|
return transform;
|
|
318
318
|
}
|
|
319
319
|
return {
|
|
320
|
-
typ: EnumToken.
|
|
320
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
321
321
|
val: 'translate',
|
|
322
322
|
chi: [
|
|
323
323
|
values[0],
|
|
@@ -330,7 +330,7 @@ function minifyTransformFunctions(transform) {
|
|
|
330
330
|
if (name == 'scale3d' || name == 'scale') {
|
|
331
331
|
if (t.size == 0) {
|
|
332
332
|
return {
|
|
333
|
-
typ: EnumToken.
|
|
333
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
334
334
|
val: 'scale',
|
|
335
335
|
chi: [
|
|
336
336
|
{ typ: EnumToken.NumberTokenType, val: 1 }
|
|
@@ -339,7 +339,7 @@ function minifyTransformFunctions(transform) {
|
|
|
339
339
|
}
|
|
340
340
|
if (t.size == 1) {
|
|
341
341
|
return {
|
|
342
|
-
typ: EnumToken.
|
|
342
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
343
343
|
val: 'scale' + (t.has('x') ? 'X' : t.has('y') ? 'Y' : 'Z'),
|
|
344
344
|
chi: [
|
|
345
345
|
values[t.has('x') ? 0 : t.has('y') ? 1 : 2]
|
|
@@ -351,7 +351,7 @@ function minifyTransformFunctions(transform) {
|
|
|
351
351
|
return transform;
|
|
352
352
|
}
|
|
353
353
|
return {
|
|
354
|
-
typ: EnumToken.
|
|
354
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
355
355
|
val: 'scale',
|
|
356
356
|
chi: [
|
|
357
357
|
values[0],
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Matrix } from "./type.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* angle in radian
|
|
4
|
+
* @param angle
|
|
5
|
+
* @param x
|
|
6
|
+
* @param y
|
|
7
|
+
* @param z
|
|
8
|
+
* @param from
|
|
9
|
+
*/
|
|
10
|
+
export declare function rotate3D(angle: number, x: number, y: number, z: number, from: Matrix): Matrix;
|
|
11
|
+
export declare function rotate(angle: number, from: Matrix): Matrix;
|
|
12
|
+
export declare const rotateZ: typeof rotate;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Matrix } from "./type.d.ts";
|
|
2
|
+
export declare function scaleX(x: number, from: Matrix): Matrix;
|
|
3
|
+
export declare function scaleY(y: number, from: Matrix): Matrix;
|
|
4
|
+
export declare function scaleZ(z: number, from: Matrix): Matrix;
|
|
5
|
+
export declare function scale(x: number, y: number, from: Matrix): Matrix;
|
|
6
|
+
export declare function scale3d(x: number, y: number, z: number, from: Matrix): Matrix;
|