@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,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
|
}
|
|
@@ -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
|
|