@tbela99/css-parser 1.4.3 → 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 +192 -2
- package/README.md +69 -1120
- package/dist/config.json.js +43 -2
- package/dist/index-umd-web.js +17226 -15037
- package/dist/index.cjs +16889 -14705
- package/dist/index.d.ts +1804 -1684
- package/dist/lib/ast/clone.js +4 -3
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/calc.js +59 -54
- package/dist/lib/ast/features/if.js +22 -16
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +343 -6
- package/dist/lib/ast/features/transform.js +7 -4
- package/dist/lib/ast/find.js +5 -5
- package/dist/lib/ast/math/expression.js +12 -8
- package/dist/lib/ast/minify.js +28 -33
- package/dist/lib/ast/transform/minify.js +135 -131
- package/dist/lib/ast/transform/utils.js +3 -2
- package/dist/lib/ast/types.js +69 -8
- package/dist/lib/ast/walk.js +4 -5
- package/dist/lib/fs/resolve.js +71 -57
- package/dist/lib/parser/declaration/list.js +92 -3
- package/dist/lib/parser/declaration/map.js +5 -5
- package/dist/lib/parser/parse.js +528 -466
- package/dist/lib/parser/tokenize.js +110 -4
- package/dist/lib/parser/utils/angle.js +29 -0
- package/dist/lib/parser/utils/at-rule-container.js +2 -2
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +2 -2
- package/dist/lib/parser/utils/at-rule-generic.js +1 -1
- package/dist/lib/parser/utils/at-rule-media.js +2 -2
- package/dist/lib/parser/utils/at-rule-support.js +73 -8
- package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
- package/dist/lib/parser/utils/at-rule.js +2 -8
- package/dist/lib/parser/utils/declaration.js +179 -76
- package/dist/lib/parser/utils/selector.js +53 -11
- package/dist/lib/parser/utils/token.js +13 -11
- package/dist/lib/renderer/render.js +501 -59
- package/dist/lib/syntax/color/alpha.js +64 -0
- package/dist/lib/syntax/color/cmyk.js +2 -2
- package/dist/lib/syntax/color/color-mix.js +283 -220
- package/dist/lib/syntax/color/color.js +37 -28
- package/dist/lib/syntax/color/hex.js +2 -2
- package/dist/lib/syntax/color/hsl.js +3 -3
- package/dist/lib/syntax/color/hwb.js +7 -7
- package/dist/lib/syntax/color/lab.js +5 -5
- package/dist/lib/syntax/color/lch.js +4 -4
- package/dist/lib/syntax/color/oklab.js +3 -3
- package/dist/lib/syntax/color/oklch.js +3 -3
- package/dist/lib/syntax/color/relativecolor.js +97 -12
- package/dist/lib/syntax/color/srgb.js +5 -5
- 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 +7 -3
- package/dist/lib/syntax/color/utils/distance.js +21 -4
- package/dist/lib/syntax/color/utils/make-color.js +56 -0
- package/dist/lib/syntax/color/xyz.js +2 -2
- package/dist/lib/syntax/constants.js +29 -1
- package/dist/lib/syntax/syntax.js +307 -39
- package/dist/lib/validation/config.js +2 -2
- package/dist/lib/validation/config.json.js +32 -17
- package/dist/lib/validation/match.js +239 -104
- package/dist/lib/validation/parser/parse.js +0 -1
- package/dist/lib/validation/parser/typedef.js +6 -0
- package/dist/node.js +64 -22
- package/dist/web.js +65 -18
- package/package.json +26 -15
- package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.repl_history +0 -4
- package/badges/coverage.svg +0 -20
- package/deno.lock +0 -2861
- package/dist/lib/ast/clone.d.ts +0 -10
- package/dist/lib/ast/expand.d.ts +0 -14
- package/dist/lib/ast/features/calc.d.ts +0 -10
- package/dist/lib/ast/features/if.d.ts +0 -10
- package/dist/lib/ast/features/index.d.ts +0 -6
- package/dist/lib/ast/features/inlinecssvariables.d.ts +0 -15
- package/dist/lib/ast/features/prefix.d.ts +0 -8
- package/dist/lib/ast/features/shorthand.d.ts +0 -12
- package/dist/lib/ast/features/transform.d.ts +0 -10
- package/dist/lib/ast/features/type.d.ts +0 -15
- package/dist/lib/ast/find.d.ts +0 -165
- package/dist/lib/ast/math/expression.d.ts +0 -18
- package/dist/lib/ast/math/math.d.ts +0 -6
- package/dist/lib/ast/minify.d.ts +0 -19
- package/dist/lib/ast/transform/compute.d.ts +0 -8
- package/dist/lib/ast/transform/matrix.d.ts +0 -22
- package/dist/lib/ast/transform/minify.d.ts +0 -5
- package/dist/lib/ast/transform/perspective.d.ts +0 -3
- package/dist/lib/ast/transform/rotate.d.ts +0 -12
- package/dist/lib/ast/transform/scale.d.ts +0 -6
- package/dist/lib/ast/transform/skew.d.ts +0 -4
- package/dist/lib/ast/transform/translate.d.ts +0 -6
- package/dist/lib/ast/transform/utils.d.ts +0 -9
- package/dist/lib/ast/types.d.ts +0 -903
- package/dist/lib/ast/walk.d.ts +0 -162
- package/dist/lib/fs/resolve.d.ts +0 -20
- package/dist/lib/parser/declaration/list.d.ts +0 -16
- package/dist/lib/parser/declaration/map.d.ts +0 -15
- package/dist/lib/parser/declaration/set.d.ts +0 -9
- package/dist/lib/parser/node.d.ts +0 -7
- package/dist/lib/parser/parse.d.ts +0 -107
- package/dist/lib/parser/tokenize.d.ts +0 -57
- package/dist/lib/parser/utils/at-rule-container.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-generic.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-import.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-media.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.js +0 -28
- package/dist/lib/parser/utils/at-rule-support.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-token.d.ts +0 -1
- package/dist/lib/parser/utils/at-rule-when-else.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule.d.ts +0 -13
- package/dist/lib/parser/utils/cache.d.ts +0 -6
- package/dist/lib/parser/utils/config.d.ts +0 -2
- package/dist/lib/parser/utils/declaration-list.d.ts +0 -5
- package/dist/lib/parser/utils/declaration.d.ts +0 -18
- package/dist/lib/parser/utils/eq.d.ts +0 -1
- package/dist/lib/parser/utils/hash.d.ts +0 -21
- package/dist/lib/parser/utils/selector.d.ts +0 -5
- package/dist/lib/parser/utils/text.d.ts +0 -3
- package/dist/lib/parser/utils/token.d.ts +0 -14
- package/dist/lib/parser/utils/type.d.ts +0 -2
- package/dist/lib/renderer/render.d.ts +0 -28
- package/dist/lib/renderer/sourcemap/lib/encode.d.ts +0 -1
- package/dist/lib/renderer/sourcemap/sourcemap.d.ts +0 -26
- package/dist/lib/syntax/color/a98rgb.d.ts +0 -2
- package/dist/lib/syntax/color/cmyk.d.ts +0 -10
- package/dist/lib/syntax/color/color-mix.d.ts +0 -2
- package/dist/lib/syntax/color/color.d.ts +0 -42
- package/dist/lib/syntax/color/hex.d.ts +0 -16
- package/dist/lib/syntax/color/hsl.d.ts +0 -20
- package/dist/lib/syntax/color/hsv.d.ts +0 -2
- package/dist/lib/syntax/color/hwb.d.ts +0 -21
- package/dist/lib/syntax/color/lab.d.ts +0 -25
- package/dist/lib/syntax/color/lch.d.ts +0 -23
- package/dist/lib/syntax/color/oklab.d.ts +0 -22
- package/dist/lib/syntax/color/oklch.d.ts +0 -20
- package/dist/lib/syntax/color/p3.d.ts +0 -6
- package/dist/lib/syntax/color/prophotorgb.d.ts +0 -2
- package/dist/lib/syntax/color/rec2020.d.ts +0 -2
- package/dist/lib/syntax/color/relativecolor.d.ts +0 -13
- package/dist/lib/syntax/color/rgb.d.ts +0 -20
- package/dist/lib/syntax/color/srgb.d.ts +0 -23
- package/dist/lib/syntax/color/utils/components.d.ts +0 -2
- package/dist/lib/syntax/color/utils/distance.d.ts +0 -18
- package/dist/lib/syntax/color/utils/matrix.d.ts +0 -6
- package/dist/lib/syntax/color/xyz.d.ts +0 -5
- package/dist/lib/syntax/color/xyzd50.d.ts +0 -4
- package/dist/lib/syntax/constants.d.ts +0 -67
- package/dist/lib/syntax/syntax.d.ts +0 -38
- package/dist/lib/validation/config.d.ts +0 -14
- package/dist/lib/validation/json.d.ts +0 -2
- package/dist/lib/validation/match.d.ts +0 -38
- package/dist/lib/validation/parser/parse.d.ts +0 -8
- package/dist/lib/validation/parser/typedef.d.ts +0 -95
- package/dist/lib/validation/utils/list.d.ts +0 -4
- package/dist/lib/validation/utils/whitespace.d.ts +0 -2
- package/dist/node.d.ts +0 -207
- package/dist/web.d.ts +0 -169
- package/playground/index.html +0 -1328
- package/playground/sw.js +0 -55
- package/playground/tree.js +0 -176
|
@@ -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
45
|
typ: EnumToken.TransformFunctionTokenType,
|
|
43
|
-
val:
|
|
44
|
-
chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit:
|
|
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
54
|
typ: EnumToken.TransformFunctionTokenType,
|
|
52
|
-
val:
|
|
53
|
-
chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[index]), unit:
|
|
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
62
|
typ: EnumToken.TransformFunctionTokenType,
|
|
60
|
-
val:
|
|
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
85
|
typ: EnumToken.TransformFunctionTokenType,
|
|
79
|
-
val:
|
|
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
99
|
typ: EnumToken.TransformFunctionTokenType,
|
|
93
|
-
val:
|
|
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
112
|
typ: EnumToken.TransformFunctionTokenType,
|
|
106
|
-
val:
|
|
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
125
|
typ: EnumToken.TransformFunctionTokenType,
|
|
119
|
-
val:
|
|
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
138
|
typ: EnumToken.TransformFunctionTokenType,
|
|
132
|
-
val:
|
|
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
174
|
typ: EnumToken.TransformFunctionTokenType,
|
|
168
|
-
val:
|
|
169
|
-
chi: [
|
|
170
|
-
{ typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: 'deg' }
|
|
171
|
-
]
|
|
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
181
|
typ: EnumToken.TransformFunctionTokenType,
|
|
177
|
-
val:
|
|
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
205
|
typ: EnumToken.TransformFunctionTokenType,
|
|
201
|
-
val:
|
|
202
|
-
chi: [
|
|
203
|
-
{ typ: EnumToken.NumberTokenType, val: round(prefix == 'Z' ? sz : prefix == 'Y' ? sy : sx) }
|
|
204
|
-
]
|
|
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
212
|
typ: EnumToken.TransformFunctionTokenType,
|
|
210
|
-
val:
|
|
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
223
|
typ: EnumToken.TransformFunctionTokenType,
|
|
221
|
-
val:
|
|
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
319
|
typ: EnumToken.TransformFunctionTokenType,
|
|
300
|
-
val:
|
|
301
|
-
chi: [
|
|
302
|
-
{ typ: EnumToken.NumberTokenType, val: 0 }
|
|
303
|
-
]
|
|
320
|
+
val: "translate",
|
|
321
|
+
chi: [{ typ: EnumToken.NumberTokenType, val: 0 }],
|
|
304
322
|
};
|
|
305
323
|
}
|
|
306
324
|
if (t.size == 1) {
|
|
307
325
|
return {
|
|
308
326
|
typ: EnumToken.TransformFunctionTokenType,
|
|
309
|
-
val:
|
|
310
|
-
chi: [
|
|
311
|
-
values[t.has('x') ? 0 : t.has('y') ? 1 : 2]
|
|
312
|
-
]
|
|
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
336
|
typ: EnumToken.TransformFunctionTokenType,
|
|
321
|
-
val:
|
|
322
|
-
chi: [
|
|
323
|
-
values[0],
|
|
324
|
-
{ typ: EnumToken.CommaTokenType },
|
|
325
|
-
values[1]
|
|
326
|
-
]
|
|
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
345
|
typ: EnumToken.TransformFunctionTokenType,
|
|
334
|
-
val:
|
|
335
|
-
chi: [
|
|
336
|
-
{ typ: EnumToken.NumberTokenType, val: 1 }
|
|
337
|
-
]
|
|
346
|
+
val: "scale",
|
|
347
|
+
chi: [{ typ: EnumToken.NumberTokenType, val: 1 }],
|
|
338
348
|
};
|
|
339
349
|
}
|
|
340
350
|
if (t.size == 1) {
|
|
341
351
|
return {
|
|
342
352
|
typ: EnumToken.TransformFunctionTokenType,
|
|
343
|
-
val:
|
|
344
|
-
chi: [
|
|
345
|
-
values[t.has('x') ? 0 : t.has('y') ? 1 : 2]
|
|
346
|
-
]
|
|
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
362
|
typ: EnumToken.TransformFunctionTokenType,
|
|
355
|
-
val:
|
|
356
|
-
chi: [
|
|
357
|
-
values[0],
|
|
358
|
-
{ typ: EnumToken.CommaTokenType },
|
|
359
|
-
values[1]
|
|
360
|
-
]
|
|
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 };
|
package/dist/lib/ast/types.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Syntax validation enum
|
|
3
3
|
*/
|
|
4
4
|
var SyntaxValidationResult;
|
|
5
5
|
(function (SyntaxValidationResult) {
|
|
@@ -11,7 +11,46 @@ var SyntaxValidationResult;
|
|
|
11
11
|
SyntaxValidationResult[SyntaxValidationResult["Lenient"] = 2] = "Lenient";
|
|
12
12
|
})(SyntaxValidationResult || (SyntaxValidationResult = {}));
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Enum of node statuses
|
|
15
|
+
*/
|
|
16
|
+
var EnumAstNodeStatus;
|
|
17
|
+
(function (EnumAstNodeStatus) {
|
|
18
|
+
/**
|
|
19
|
+
* Node passed validation
|
|
20
|
+
*/
|
|
21
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Validated"] = 0] = "Validated";
|
|
22
|
+
/**
|
|
23
|
+
* Node is invalid
|
|
24
|
+
*/
|
|
25
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Invalid"] = 1] = "Invalid";
|
|
26
|
+
/**
|
|
27
|
+
* node is not validated
|
|
28
|
+
*/
|
|
29
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Unvalidated"] = 2] = "Unvalidated";
|
|
30
|
+
/**
|
|
31
|
+
* Node did not pass validation, but is preserved.
|
|
32
|
+
*/
|
|
33
|
+
EnumAstNodeStatus[EnumAstNodeStatus["ValidationFailed"] = 3] = "ValidationFailed";
|
|
34
|
+
/**
|
|
35
|
+
* Parsing the node is not supported yet or the node syntax definition does not exist.
|
|
36
|
+
*/
|
|
37
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Unknown"] = 4] = "Unknown";
|
|
38
|
+
/**
|
|
39
|
+
* Failed to parse the node.
|
|
40
|
+
*/
|
|
41
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Unparsed"] = 5] = "Unparsed";
|
|
42
|
+
/**
|
|
43
|
+
* Node is disallowed in the context
|
|
44
|
+
*/
|
|
45
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Disallowed"] = 6] = "Disallowed";
|
|
46
|
+
/**
|
|
47
|
+
* Node is malformed
|
|
48
|
+
*/
|
|
49
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Malformed"] = 7] = "Malformed";
|
|
50
|
+
})(EnumAstNodeStatus || (EnumAstNodeStatus = {}));
|
|
51
|
+
/**
|
|
52
|
+
* Enum of validation levels
|
|
53
|
+
* @deprecated
|
|
15
54
|
*/
|
|
16
55
|
var ValidationLevel;
|
|
17
56
|
(function (ValidationLevel) {
|
|
@@ -39,9 +78,13 @@ var ValidationLevel;
|
|
|
39
78
|
* validate selectors, at-rules and declarations
|
|
40
79
|
*/
|
|
41
80
|
ValidationLevel[ValidationLevel["All"] = 7] = "All";
|
|
81
|
+
/**
|
|
82
|
+
* Report only. Apply validation and report nodes that are marked as invalid
|
|
83
|
+
*/
|
|
84
|
+
ValidationLevel[ValidationLevel["ReportOnly"] = 8] = "ReportOnly";
|
|
42
85
|
})(ValidationLevel || (ValidationLevel = {}));
|
|
43
86
|
/**
|
|
44
|
-
*
|
|
87
|
+
* Enum of all token types
|
|
45
88
|
*/
|
|
46
89
|
var EnumToken;
|
|
47
90
|
(function (EnumToken) {
|
|
@@ -372,7 +415,8 @@ var EnumToken;
|
|
|
372
415
|
*/
|
|
373
416
|
EnumToken[EnumToken["NestingSelectorTokenType"] = 80] = "NestingSelectorTokenType";
|
|
374
417
|
/**
|
|
375
|
-
*
|
|
418
|
+
* Invalid rule token type
|
|
419
|
+
* @deprecated
|
|
376
420
|
*/
|
|
377
421
|
EnumToken[EnumToken["InvalidRuleNodeType"] = 81] = "InvalidRuleNodeType";
|
|
378
422
|
/**
|
|
@@ -384,7 +428,8 @@ var EnumToken;
|
|
|
384
428
|
*/
|
|
385
429
|
EnumToken[EnumToken["InvalidAttrTokenType"] = 83] = "InvalidAttrTokenType";
|
|
386
430
|
/**
|
|
387
|
-
*
|
|
431
|
+
* Invalid at rule token type
|
|
432
|
+
* @deprecated
|
|
388
433
|
*/
|
|
389
434
|
EnumToken[EnumToken["InvalidAtRuleNodeType"] = 84] = "InvalidAtRuleNodeType";
|
|
390
435
|
/**
|
|
@@ -424,7 +469,8 @@ var EnumToken;
|
|
|
424
469
|
*/
|
|
425
470
|
EnumToken[EnumToken["KeyframesAtRuleNodeType"] = 93] = "KeyframesAtRuleNodeType";
|
|
426
471
|
/**
|
|
427
|
-
* invalid declaration node type
|
|
472
|
+
* invalid declaration node type.
|
|
473
|
+
* @deprecated
|
|
428
474
|
*/
|
|
429
475
|
EnumToken[EnumToken["InvalidDeclarationNodeType"] = 94] = "InvalidDeclarationNodeType";
|
|
430
476
|
/* css module nodes */
|
|
@@ -721,7 +767,7 @@ var EnumToken;
|
|
|
721
767
|
EnumToken[EnumToken["TimelineFunction"] = 16] = "TimelineFunction";
|
|
722
768
|
})(EnumToken || (EnumToken = {}));
|
|
723
769
|
/**
|
|
724
|
-
*
|
|
770
|
+
* Supported color types enum
|
|
725
771
|
*/
|
|
726
772
|
var ColorType;
|
|
727
773
|
(function (ColorType) {
|
|
@@ -825,6 +871,10 @@ var ColorType;
|
|
|
825
871
|
* custom color
|
|
826
872
|
*/
|
|
827
873
|
ColorType[ColorType["CUSTOM_COLOR"] = 24] = "CUSTOM_COLOR";
|
|
874
|
+
/**
|
|
875
|
+
* alpha() color function
|
|
876
|
+
*/
|
|
877
|
+
ColorType[ColorType["ALPHA"] = 25] = "ALPHA";
|
|
828
878
|
/**
|
|
829
879
|
* alias for rgba
|
|
830
880
|
*/
|
|
@@ -842,6 +892,9 @@ var ColorType;
|
|
|
842
892
|
*/
|
|
843
893
|
ColorType[ColorType["DEVICE_CMYK"] = 7] = "DEVICE_CMYK";
|
|
844
894
|
})(ColorType || (ColorType = {}));
|
|
895
|
+
/**
|
|
896
|
+
* Supported module case transform
|
|
897
|
+
*/
|
|
845
898
|
var ModuleCaseTransformEnum;
|
|
846
899
|
(function (ModuleCaseTransformEnum) {
|
|
847
900
|
/**
|
|
@@ -865,6 +918,9 @@ var ModuleCaseTransformEnum;
|
|
|
865
918
|
*/
|
|
866
919
|
ModuleCaseTransformEnum[ModuleCaseTransformEnum["DashCaseOnly"] = 16] = "DashCaseOnly";
|
|
867
920
|
})(ModuleCaseTransformEnum || (ModuleCaseTransformEnum = {}));
|
|
921
|
+
/**
|
|
922
|
+
* Supported module scope
|
|
923
|
+
*/
|
|
868
924
|
var ModuleScopeEnumOptions;
|
|
869
925
|
(function (ModuleScopeEnumOptions) {
|
|
870
926
|
/**
|
|
@@ -905,6 +961,11 @@ var ModuleScopeEnumOptions;
|
|
|
905
961
|
ModuleScopeEnumOptions[ModuleScopeEnumOptions["Shortest"] = 512] = "Shortest";
|
|
906
962
|
})(ModuleScopeEnumOptions || (ModuleScopeEnumOptions = {}));
|
|
907
963
|
// https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Values_and_units#absolute_length_units
|
|
964
|
+
/**
|
|
965
|
+
* Convert length to px
|
|
966
|
+
* @param value
|
|
967
|
+
* @returns
|
|
968
|
+
*/
|
|
908
969
|
function length2Px(value) {
|
|
909
970
|
let result = null;
|
|
910
971
|
if (value.typ == EnumToken.NumberTokenType) {
|
|
@@ -965,4 +1026,4 @@ function minifyNumber(val) {
|
|
|
965
1026
|
return val;
|
|
966
1027
|
}
|
|
967
1028
|
|
|
968
|
-
export { ColorType, EnumToken, ModuleCaseTransformEnum, ModuleScopeEnumOptions, SyntaxValidationResult, ValidationLevel, length2Px, minifyNumber };
|
|
1029
|
+
export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, ModuleScopeEnumOptions, SyntaxValidationResult, ValidationLevel, length2Px, minifyNumber };
|