@tbela99/css-parser 1.4.2 → 1.4.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 +354 -4
- package/README.md +69 -1077
- package/dist/config.json.js +76 -3
- package/dist/index-umd-web.js +26838 -18743
- package/dist/index.cjs +26819 -18731
- package/dist/index.d.ts +2471 -1884
- package/dist/lib/ast/clone.js +46 -0
- package/dist/lib/ast/expand.js +90 -65
- package/dist/lib/ast/features/calc.js +86 -43
- package/dist/lib/ast/features/if.js +221 -0
- package/dist/lib/ast/features/index.js +1 -0
- package/dist/lib/ast/features/inlinecssvariables.js +33 -28
- package/dist/lib/ast/features/prefix.js +406 -44
- package/dist/lib/ast/features/shorthand.js +6 -9
- package/dist/lib/ast/features/transform.js +14 -15
- package/dist/lib/ast/find.js +175 -0
- package/dist/lib/ast/math/expression.js +145 -99
- package/dist/lib/ast/math/math.js +30 -41
- package/dist/lib/ast/minify.js +551 -232
- package/dist/lib/ast/transform/compute.js +82 -69
- package/dist/lib/ast/transform/matrix.js +12 -26
- package/dist/lib/ast/transform/minify.js +154 -150
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.js +1 -1
- package/dist/lib/ast/transform/scale.js +1 -1
- package/dist/lib/ast/transform/skew.js +1 -1
- package/dist/lib/ast/transform/translate.js +1 -1
- package/dist/lib/ast/transform/utils.js +3 -2
- package/dist/lib/ast/types.js +345 -30
- package/dist/lib/ast/walk.js +119 -64
- package/dist/lib/fs/resolve.js +94 -88
- package/dist/lib/parser/declaration/list.js +117 -26
- package/dist/lib/parser/declaration/map.js +141 -96
- package/dist/lib/parser/declaration/set.js +30 -25
- package/dist/lib/parser/parse.js +1810 -1739
- package/dist/lib/parser/tokenize.js +662 -403
- package/dist/lib/parser/utils/angle.js +29 -0
- package/dist/lib/parser/utils/at-rule-container.js +486 -0
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
- package/dist/lib/parser/utils/at-rule-generic.js +118 -0
- package/dist/lib/parser/utils/at-rule-import.js +393 -0
- package/dist/lib/parser/utils/at-rule-media.js +603 -0
- package/dist/lib/parser/utils/at-rule-support.js +431 -0
- package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
- package/dist/lib/parser/utils/at-rule.js +31 -0
- package/dist/lib/parser/utils/cache.js +19 -0
- package/dist/lib/parser/utils/config.js +1 -0
- package/dist/lib/parser/utils/declaration.js +672 -91
- package/dist/lib/parser/utils/hash.js +1 -1
- package/dist/lib/parser/utils/selector.js +518 -0
- package/dist/lib/parser/utils/text.js +17 -1
- package/dist/lib/parser/utils/token.js +104 -0
- package/dist/lib/parser/utils/type.js +29 -18
- package/dist/lib/renderer/render.js +870 -269
- package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
- package/dist/lib/syntax/color/a98rgb.js +8 -12
- package/dist/lib/syntax/color/alpha.js +64 -0
- package/dist/lib/syntax/color/cmyk.js +23 -21
- package/dist/lib/syntax/color/color-mix.js +311 -237
- package/dist/lib/syntax/color/color.js +98 -92
- package/dist/lib/syntax/color/hex.js +29 -33
- package/dist/lib/syntax/color/hsl.js +7 -14
- package/dist/lib/syntax/color/hwb.js +14 -27
- package/dist/lib/syntax/color/lab.js +23 -24
- package/dist/lib/syntax/color/lch.js +16 -18
- package/dist/lib/syntax/color/oklab.js +21 -40
- package/dist/lib/syntax/color/oklch.js +16 -18
- package/dist/lib/syntax/color/p3.js +0 -8
- package/dist/lib/syntax/color/rec2020.js +9 -13
- package/dist/lib/syntax/color/relativecolor.js +160 -48
- package/dist/lib/syntax/color/rgb.js +14 -18
- package/dist/lib/syntax/color/srgb.js +30 -29
- package/dist/lib/syntax/color/utils/color-type.js +18 -0
- package/dist/lib/syntax/color/utils/colorspace.js +46 -0
- package/dist/lib/syntax/color/utils/components.js +36 -16
- package/dist/lib/syntax/color/utils/distance.js +21 -11
- package/dist/lib/syntax/color/utils/make-color.js +56 -0
- package/dist/lib/syntax/color/xyz.js +10 -22
- package/dist/lib/syntax/color/xyzd50.js +6 -20
- package/dist/lib/syntax/constants.js +464 -0
- package/dist/lib/syntax/syntax.js +825 -592
- package/dist/lib/validation/config.js +72 -33
- package/dist/lib/validation/config.json.js +1185 -85
- package/dist/lib/validation/match.js +3120 -0
- package/dist/lib/validation/parser/parse.js +683 -935
- package/dist/lib/validation/parser/typedef.js +106 -0
- package/dist/lib/validation/utils/list.js +4 -11
- package/dist/lib/validation/utils/whitespace.js +2 -8
- package/dist/node.js +102 -57
- package/dist/web.js +100 -48
- package/package.json +31 -17
- 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
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { multiply,
|
|
1
|
+
import { multiply, decompose, round, toZero, identity } from './utils.js';
|
|
2
|
+
import { epsilon } from '../../syntax/constants.js';
|
|
2
3
|
import { EnumToken } from '../types.js';
|
|
3
4
|
import { computeMatrix } from './compute.js';
|
|
4
5
|
import { parseMatrix } from './matrix.js';
|
|
@@ -9,233 +10,237 @@ function minify(matrix) {
|
|
|
9
10
|
if (decomposed == null) {
|
|
10
11
|
return null;
|
|
11
12
|
}
|
|
12
|
-
const transforms = new Set([
|
|
13
|
-
const scales = new Set([
|
|
14
|
-
const skew = new Set([
|
|
13
|
+
const transforms = new Set(["translate", "scale", "skew", "perspective", "rotate"]);
|
|
14
|
+
const scales = new Set(["x", "y", "z"]);
|
|
15
|
+
const skew = new Set(["x", "y"]);
|
|
15
16
|
let result = [];
|
|
16
17
|
// check identity
|
|
17
|
-
if (round(decomposed.translate[0]) == 0 &&
|
|
18
|
-
|
|
18
|
+
if (round(decomposed.translate[0]) == 0 &&
|
|
19
|
+
round(decomposed.translate[1]) == 0 &&
|
|
20
|
+
round(decomposed.translate[2]) == 0) {
|
|
21
|
+
transforms.delete("translate");
|
|
19
22
|
}
|
|
20
23
|
if (round(decomposed.scale[0]) == 1 && round(decomposed.scale[1]) == 1 && round(decomposed.scale[2]) == 1) {
|
|
21
|
-
transforms.delete(
|
|
24
|
+
transforms.delete("scale");
|
|
22
25
|
}
|
|
23
26
|
if (round(decomposed.skew[0]) == 0 && round(decomposed.skew[1]) == 0) {
|
|
24
|
-
transforms.delete(
|
|
27
|
+
transforms.delete("skew");
|
|
25
28
|
}
|
|
26
29
|
if (round(decomposed.perspective[2]) == 0) {
|
|
27
|
-
transforms.delete(
|
|
30
|
+
transforms.delete("perspective");
|
|
28
31
|
}
|
|
29
32
|
if (round(decomposed.rotate[3]) == 0) {
|
|
30
|
-
transforms.delete(
|
|
33
|
+
transforms.delete("rotate");
|
|
31
34
|
}
|
|
32
|
-
if (transforms.has(
|
|
33
|
-
let coordinates = new Set([
|
|
35
|
+
if (transforms.has("translate")) {
|
|
36
|
+
let coordinates = new Set(["x", "y", "z"]);
|
|
34
37
|
for (let i = 0; i < 3; i++) {
|
|
35
38
|
if (round(decomposed.translate[i]) == 0) {
|
|
36
|
-
coordinates.delete(i == 0 ?
|
|
39
|
+
coordinates.delete(i == 0 ? "x" : i == 1 ? "y" : "z");
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
if (coordinates.size == 1) {
|
|
40
|
-
if (coordinates.has(
|
|
43
|
+
if (coordinates.has("x")) {
|
|
41
44
|
result.push({
|
|
42
|
-
typ: EnumToken.
|
|
43
|
-
val:
|
|
44
|
-
chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit:
|
|
45
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
46
|
+
val: "translate",
|
|
47
|
+
chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: "px" }],
|
|
45
48
|
});
|
|
46
49
|
}
|
|
47
50
|
else {
|
|
48
|
-
let axis = coordinates.has(
|
|
49
|
-
let index = axis ==
|
|
51
|
+
let axis = coordinates.has("y") ? "y" : "z";
|
|
52
|
+
let index = axis == "y" ? 1 : 2;
|
|
50
53
|
result.push({
|
|
51
|
-
typ: EnumToken.
|
|
52
|
-
val:
|
|
53
|
-
chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[index]), unit:
|
|
54
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
55
|
+
val: "translate" + axis.toUpperCase(),
|
|
56
|
+
chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[index]), unit: "px" }],
|
|
54
57
|
});
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
|
-
else if (coordinates.has(
|
|
60
|
+
else if (coordinates.has("z")) {
|
|
58
61
|
result.push({
|
|
59
|
-
typ: EnumToken.
|
|
60
|
-
val:
|
|
62
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
63
|
+
val: "translate3d",
|
|
61
64
|
chi: [
|
|
62
|
-
decomposed.translate[0] == 0
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
decomposed.translate[0] == 0
|
|
66
|
+
? {
|
|
67
|
+
typ: EnumToken.NumberTokenType,
|
|
68
|
+
val: 0,
|
|
69
|
+
}
|
|
70
|
+
: { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: "px" },
|
|
66
71
|
{ typ: EnumToken.CommaTokenType },
|
|
67
|
-
decomposed.translate[1] == 0
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
decomposed.translate[1] == 0
|
|
73
|
+
? {
|
|
74
|
+
typ: EnumToken.NumberTokenType,
|
|
75
|
+
val: 0,
|
|
76
|
+
}
|
|
77
|
+
: { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit: "px" },
|
|
71
78
|
{ typ: EnumToken.CommaTokenType },
|
|
72
|
-
{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[2]), unit:
|
|
73
|
-
]
|
|
79
|
+
{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[2]), unit: "px" },
|
|
80
|
+
],
|
|
74
81
|
});
|
|
75
82
|
}
|
|
76
83
|
else {
|
|
77
84
|
result.push({
|
|
78
|
-
typ: EnumToken.
|
|
79
|
-
val:
|
|
85
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
86
|
+
val: "translate",
|
|
80
87
|
chi: [
|
|
81
|
-
{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit:
|
|
88
|
+
{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: "px" },
|
|
82
89
|
{ typ: EnumToken.CommaTokenType },
|
|
83
|
-
{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit:
|
|
84
|
-
]
|
|
90
|
+
{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit: "px" },
|
|
91
|
+
],
|
|
85
92
|
});
|
|
86
93
|
}
|
|
87
94
|
}
|
|
88
|
-
if (transforms.has(
|
|
95
|
+
if (transforms.has("rotate")) {
|
|
89
96
|
const [x, y, z, angle] = decomposed.rotate;
|
|
90
97
|
if (y == 0 && z == 0) {
|
|
91
98
|
result.push({
|
|
92
|
-
typ: EnumToken.
|
|
93
|
-
val:
|
|
99
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
100
|
+
val: "rotateX",
|
|
94
101
|
chi: [
|
|
95
102
|
{
|
|
96
103
|
typ: EnumToken.AngleTokenType,
|
|
97
104
|
val: round(angle),
|
|
98
|
-
unit:
|
|
99
|
-
}
|
|
100
|
-
]
|
|
105
|
+
unit: "deg",
|
|
106
|
+
},
|
|
107
|
+
],
|
|
101
108
|
});
|
|
102
109
|
}
|
|
103
110
|
else if (x == 0 && z == 0) {
|
|
104
111
|
result.push({
|
|
105
|
-
typ: EnumToken.
|
|
106
|
-
val:
|
|
112
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
113
|
+
val: "rotateY",
|
|
107
114
|
chi: [
|
|
108
115
|
{
|
|
109
116
|
typ: EnumToken.AngleTokenType,
|
|
110
117
|
val: round(angle),
|
|
111
|
-
unit:
|
|
112
|
-
}
|
|
113
|
-
]
|
|
118
|
+
unit: "deg",
|
|
119
|
+
},
|
|
120
|
+
],
|
|
114
121
|
});
|
|
115
122
|
}
|
|
116
123
|
else if (x == 0 && y == 0) {
|
|
117
124
|
result.push({
|
|
118
|
-
typ: EnumToken.
|
|
119
|
-
val:
|
|
125
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
126
|
+
val: "rotate",
|
|
120
127
|
chi: [
|
|
121
128
|
{
|
|
122
129
|
typ: EnumToken.AngleTokenType,
|
|
123
130
|
val: round(angle),
|
|
124
|
-
unit:
|
|
125
|
-
}
|
|
126
|
-
]
|
|
131
|
+
unit: "deg",
|
|
132
|
+
},
|
|
133
|
+
],
|
|
127
134
|
});
|
|
128
135
|
}
|
|
129
136
|
else {
|
|
130
137
|
result.push({
|
|
131
|
-
typ: EnumToken.
|
|
132
|
-
val:
|
|
138
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
139
|
+
val: "rotate3d",
|
|
133
140
|
chi: [
|
|
134
141
|
{
|
|
135
142
|
typ: EnumToken.NumberTokenType,
|
|
136
|
-
val: round(x)
|
|
143
|
+
val: round(x),
|
|
137
144
|
},
|
|
138
145
|
{ typ: EnumToken.CommaTokenType },
|
|
139
146
|
{
|
|
140
147
|
typ: EnumToken.NumberTokenType,
|
|
141
|
-
val: round(y)
|
|
148
|
+
val: round(y),
|
|
142
149
|
},
|
|
143
150
|
{ typ: EnumToken.CommaTokenType },
|
|
144
151
|
{
|
|
145
152
|
typ: EnumToken.NumberTokenType,
|
|
146
|
-
val: round(z)
|
|
153
|
+
val: round(z),
|
|
147
154
|
},
|
|
148
155
|
{ typ: EnumToken.CommaTokenType },
|
|
149
156
|
{
|
|
150
157
|
typ: EnumToken.AngleTokenType,
|
|
151
158
|
val: round(angle),
|
|
152
|
-
unit:
|
|
153
|
-
}
|
|
154
|
-
]
|
|
159
|
+
unit: "deg",
|
|
160
|
+
},
|
|
161
|
+
],
|
|
155
162
|
});
|
|
156
163
|
}
|
|
157
164
|
}
|
|
158
|
-
if (transforms.has(
|
|
165
|
+
if (transforms.has("skew")) {
|
|
159
166
|
if (round(decomposed.skew[1]) == 0) {
|
|
160
|
-
skew.delete(
|
|
167
|
+
skew.delete("y");
|
|
161
168
|
}
|
|
162
169
|
for (let i = 0; i < 2; i++) {
|
|
163
|
-
decomposed.skew[i] = round(Math.atan(decomposed.skew[i]) * 180 / Math.PI);
|
|
170
|
+
decomposed.skew[i] = round((Math.atan(decomposed.skew[i]) * 180) / Math.PI);
|
|
164
171
|
}
|
|
165
172
|
if (skew.size == 1) {
|
|
166
173
|
result.push({
|
|
167
|
-
typ: EnumToken.
|
|
168
|
-
val:
|
|
169
|
-
chi: [
|
|
170
|
-
{ typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: 'deg' }
|
|
171
|
-
]
|
|
174
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
175
|
+
val: "skew" + (skew.has("x") ? "" : "Y"),
|
|
176
|
+
chi: [{ typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: "deg" }],
|
|
172
177
|
});
|
|
173
178
|
}
|
|
174
179
|
else {
|
|
175
180
|
result.push({
|
|
176
|
-
typ: EnumToken.
|
|
177
|
-
val:
|
|
181
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
182
|
+
val: "skew",
|
|
178
183
|
chi: [
|
|
179
|
-
{ typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit:
|
|
184
|
+
{ typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: "deg" },
|
|
180
185
|
{ typ: EnumToken.CommaTokenType },
|
|
181
|
-
{ typ: EnumToken.AngleTokenType, val: round(decomposed.skew[1]), unit:
|
|
182
|
-
]
|
|
186
|
+
{ typ: EnumToken.AngleTokenType, val: round(decomposed.skew[1]), unit: "deg" },
|
|
187
|
+
],
|
|
183
188
|
});
|
|
184
189
|
}
|
|
185
190
|
}
|
|
186
|
-
if (transforms.has(
|
|
191
|
+
if (transforms.has("scale")) {
|
|
187
192
|
const [sx, sy, sz] = toZero(decomposed.scale);
|
|
188
193
|
if (sz == 1) {
|
|
189
|
-
scales.delete(
|
|
194
|
+
scales.delete("z");
|
|
190
195
|
}
|
|
191
196
|
if (sy == 1) {
|
|
192
|
-
scales.delete(
|
|
197
|
+
scales.delete("y");
|
|
193
198
|
}
|
|
194
199
|
if (sx == 1) {
|
|
195
|
-
scales.delete(
|
|
200
|
+
scales.delete("x");
|
|
196
201
|
}
|
|
197
202
|
if (scales.size == 1) {
|
|
198
|
-
let prefix = scales.has(
|
|
203
|
+
let prefix = scales.has("x") ? "X" : scales.has("y") ? "Y" : "Z";
|
|
199
204
|
result.push({
|
|
200
|
-
typ: EnumToken.
|
|
201
|
-
val:
|
|
202
|
-
chi: [
|
|
203
|
-
{ typ: EnumToken.NumberTokenType, val: round(prefix == 'Z' ? sz : prefix == 'Y' ? sy : sx) }
|
|
204
|
-
]
|
|
205
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
206
|
+
val: "scale" + prefix,
|
|
207
|
+
chi: [{ typ: EnumToken.NumberTokenType, val: round(prefix == "Z" ? sz : prefix == "Y" ? sy : sx) }],
|
|
205
208
|
});
|
|
206
209
|
}
|
|
207
|
-
else if (!scales.has(
|
|
210
|
+
else if (!scales.has("z")) {
|
|
208
211
|
result.push({
|
|
209
|
-
typ: EnumToken.
|
|
210
|
-
val:
|
|
212
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
213
|
+
val: "scale",
|
|
211
214
|
chi: [
|
|
212
215
|
{ typ: EnumToken.NumberTokenType, val: round(sx) },
|
|
213
216
|
{ typ: EnumToken.CommaTokenType },
|
|
214
217
|
{ typ: EnumToken.NumberTokenType, val: round(sy) },
|
|
215
|
-
]
|
|
218
|
+
],
|
|
216
219
|
});
|
|
217
220
|
}
|
|
218
221
|
else {
|
|
219
222
|
result.push({
|
|
220
|
-
typ: EnumToken.
|
|
221
|
-
val:
|
|
223
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
224
|
+
val: "scale3d",
|
|
222
225
|
chi: [
|
|
223
226
|
{ typ: EnumToken.NumberTokenType, val: round(sx) },
|
|
224
227
|
{ typ: EnumToken.CommaTokenType },
|
|
225
228
|
{ typ: EnumToken.NumberTokenType, val: round(sy) },
|
|
226
229
|
{ typ: EnumToken.CommaTokenType },
|
|
227
|
-
{ typ: EnumToken.NumberTokenType, val: round(sz) }
|
|
228
|
-
]
|
|
230
|
+
{ typ: EnumToken.NumberTokenType, val: round(sz) },
|
|
231
|
+
],
|
|
229
232
|
});
|
|
230
233
|
}
|
|
231
234
|
}
|
|
232
235
|
// identity
|
|
233
|
-
return result.length == 0 || (result.length == 1 && eqMatrix(identity(), result))
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
return result.length == 0 || (result.length == 1 && eqMatrix(identity(), result))
|
|
237
|
+
? [
|
|
238
|
+
{
|
|
239
|
+
typ: EnumToken.IdenTokenType,
|
|
240
|
+
val: "none",
|
|
241
|
+
},
|
|
242
|
+
]
|
|
243
|
+
: result;
|
|
239
244
|
}
|
|
240
245
|
function eqMatrix(a, b) {
|
|
241
246
|
let mat = identity();
|
|
@@ -262,102 +267,101 @@ function eqMatrix(a, b) {
|
|
|
262
267
|
}
|
|
263
268
|
function minifyTransformFunctions(transform) {
|
|
264
269
|
const name = transform.val.toLowerCase();
|
|
265
|
-
if (
|
|
266
|
-
transform.val =
|
|
270
|
+
if ("skewx" == name) {
|
|
271
|
+
transform.val = "skew";
|
|
267
272
|
return transform;
|
|
268
273
|
}
|
|
269
|
-
if (![
|
|
274
|
+
if (!["translate", "translate3d", "scale", "scale3d"].includes(name)) {
|
|
270
275
|
return transform;
|
|
271
276
|
}
|
|
272
277
|
const values = [];
|
|
273
278
|
for (const token of transform.chi) {
|
|
274
|
-
if (token.typ == EnumToken.CommentTokenType ||
|
|
279
|
+
if (token.typ == EnumToken.CommentTokenType ||
|
|
280
|
+
token.typ == EnumToken.WhitespaceTokenType ||
|
|
281
|
+
token.typ == EnumToken.CommaTokenType) {
|
|
275
282
|
continue;
|
|
276
283
|
}
|
|
277
|
-
if (![
|
|
284
|
+
if (![
|
|
285
|
+
EnumToken.NumberTokenType,
|
|
286
|
+
EnumToken.LengthTokenType,
|
|
287
|
+
EnumToken.AngleTokenType,
|
|
288
|
+
EnumToken.PercentageTokenType,
|
|
289
|
+
].includes(token.typ)) {
|
|
278
290
|
return transform;
|
|
279
291
|
}
|
|
280
|
-
if (token.typ == EnumToken.PercentageTokenType &&
|
|
281
|
-
|
|
292
|
+
if (token.typ == EnumToken.PercentageTokenType &&
|
|
293
|
+
typeof token.val == "number" &&
|
|
294
|
+
name.startsWith("scale")) {
|
|
295
|
+
Object.assign(token, {
|
|
296
|
+
typ: EnumToken.NumberTokenType,
|
|
297
|
+
val: token.val / 100,
|
|
298
|
+
});
|
|
282
299
|
}
|
|
283
300
|
values.push(token);
|
|
284
301
|
}
|
|
285
|
-
if (
|
|
302
|
+
if (values.length == 0) {
|
|
286
303
|
return transform;
|
|
287
304
|
}
|
|
288
|
-
|
|
289
|
-
|
|
305
|
+
if ((name == "translate" || name == "scale") && values.length > 2) {
|
|
306
|
+
return transform;
|
|
307
|
+
}
|
|
308
|
+
const ignoredValue = name.startsWith("scale") ? 1 : 0;
|
|
309
|
+
const t = new Set(["x", "y", "z"]);
|
|
290
310
|
let i = 3;
|
|
291
311
|
while (i--) {
|
|
292
312
|
if (values.length <= i || values[i].val == ignoredValue) {
|
|
293
|
-
t.delete(i == 0 ?
|
|
313
|
+
t.delete(i == 0 ? "x" : i == 1 ? "y" : "z");
|
|
294
314
|
}
|
|
295
315
|
}
|
|
296
|
-
if (name ==
|
|
316
|
+
if (name == "translate3d" || name == "translate") {
|
|
297
317
|
if (t.size == 0) {
|
|
298
318
|
return {
|
|
299
|
-
typ: EnumToken.
|
|
300
|
-
val:
|
|
301
|
-
chi: [
|
|
302
|
-
{ typ: EnumToken.NumberTokenType, val: 0 }
|
|
303
|
-
]
|
|
319
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
320
|
+
val: "translate",
|
|
321
|
+
chi: [{ typ: EnumToken.NumberTokenType, val: 0 }],
|
|
304
322
|
};
|
|
305
323
|
}
|
|
306
324
|
if (t.size == 1) {
|
|
307
325
|
return {
|
|
308
|
-
typ: EnumToken.
|
|
309
|
-
val:
|
|
310
|
-
chi: [
|
|
311
|
-
values[t.has('x') ? 0 : t.has('y') ? 1 : 2]
|
|
312
|
-
]
|
|
326
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
327
|
+
val: "translate" + (t.has("x") ? "" : t.has("y") ? "Y" : "Z"),
|
|
328
|
+
chi: [values[t.has("x") ? 0 : t.has("y") ? 1 : 2]],
|
|
313
329
|
};
|
|
314
330
|
}
|
|
315
331
|
if (t.size == 2) {
|
|
316
|
-
if (t.has(
|
|
332
|
+
if (t.has("z")) {
|
|
317
333
|
return transform;
|
|
318
334
|
}
|
|
319
335
|
return {
|
|
320
|
-
typ: EnumToken.
|
|
321
|
-
val:
|
|
322
|
-
chi: [
|
|
323
|
-
values[0],
|
|
324
|
-
{ typ: EnumToken.CommaTokenType },
|
|
325
|
-
values[1]
|
|
326
|
-
]
|
|
336
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
337
|
+
val: "translate",
|
|
338
|
+
chi: [values[0], { typ: EnumToken.CommaTokenType }, values[1]],
|
|
327
339
|
};
|
|
328
340
|
}
|
|
329
341
|
}
|
|
330
|
-
if (name ==
|
|
342
|
+
if (name == "scale3d" || name == "scale") {
|
|
331
343
|
if (t.size == 0) {
|
|
332
344
|
return {
|
|
333
|
-
typ: EnumToken.
|
|
334
|
-
val:
|
|
335
|
-
chi: [
|
|
336
|
-
{ typ: EnumToken.NumberTokenType, val: 1 }
|
|
337
|
-
]
|
|
345
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
346
|
+
val: "scale",
|
|
347
|
+
chi: [{ typ: EnumToken.NumberTokenType, val: 1 }],
|
|
338
348
|
};
|
|
339
349
|
}
|
|
340
350
|
if (t.size == 1) {
|
|
341
351
|
return {
|
|
342
|
-
typ: EnumToken.
|
|
343
|
-
val:
|
|
344
|
-
chi: [
|
|
345
|
-
values[t.has('x') ? 0 : t.has('y') ? 1 : 2]
|
|
346
|
-
]
|
|
352
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
353
|
+
val: "scale" + (t.has("x") ? "X" : t.has("y") ? "Y" : "Z"),
|
|
354
|
+
chi: [values[t.has("x") ? 0 : t.has("y") ? 1 : 2]],
|
|
347
355
|
};
|
|
348
356
|
}
|
|
349
357
|
if (t.size == 2) {
|
|
350
|
-
if (t.has(
|
|
358
|
+
if (t.has("z")) {
|
|
351
359
|
return transform;
|
|
352
360
|
}
|
|
353
361
|
return {
|
|
354
|
-
typ: EnumToken.
|
|
355
|
-
val:
|
|
356
|
-
chi: [
|
|
357
|
-
values[0],
|
|
358
|
-
{ typ: EnumToken.CommaTokenType },
|
|
359
|
-
values[1]
|
|
360
|
-
]
|
|
362
|
+
typ: EnumToken.TransformFunctionTokenType,
|
|
363
|
+
val: "scale",
|
|
364
|
+
chi: [values[0], { typ: EnumToken.CommaTokenType }, values[1]],
|
|
361
365
|
};
|
|
362
366
|
}
|
|
363
367
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { epsilon } from '../../syntax/constants.js';
|
|
2
|
+
|
|
2
3
|
function identity() {
|
|
3
4
|
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
4
5
|
}
|
|
@@ -240,4 +241,4 @@ function is2DMatrix(matrix) {
|
|
|
240
241
|
matrix[15] === 1;
|
|
241
242
|
}
|
|
242
243
|
|
|
243
|
-
export { decompose,
|
|
244
|
+
export { decompose, identity, is2DMatrix, multiply, round, toZero };
|