postcss-reduce-transforms 4.0.1 → 4.0.2
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/dist/index.js +39 -1
- package/package.json +1 -1
- package/CHANGELOG.md +0 -26
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ function getValues(list, { value }, index) {
|
|
|
26
26
|
if (index % 2 === 0) {
|
|
27
27
|
return [...list, parseFloat(value)];
|
|
28
28
|
}
|
|
29
|
+
|
|
29
30
|
return list;
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -33,6 +34,7 @@ function matrix3d(node, values) {
|
|
|
33
34
|
// matrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1) => matrix(a, b, c, d, tx, ty)
|
|
34
35
|
if (values[15] && values[2] === 0 && values[3] === 0 && values[6] === 0 && values[7] === 0 && values[8] === 0 && values[9] === 0 && values[10] === 1 && values[11] === 0 && values[14] === 0 && values[15] === 1) {
|
|
35
36
|
const { nodes } = node;
|
|
37
|
+
|
|
36
38
|
node.value = 'matrix';
|
|
37
39
|
node.nodes = [nodes[0], // a
|
|
38
40
|
nodes[1], // ,
|
|
@@ -57,6 +59,7 @@ const rotate3dMatch = (0, _cssnanoUtilGetMatch2.default)(rotate3dMappings);
|
|
|
57
59
|
function rotate3d(node, values) {
|
|
58
60
|
const { nodes } = node;
|
|
59
61
|
const match = rotate3dMatch(values.slice(0, 3));
|
|
62
|
+
|
|
60
63
|
if (match.length) {
|
|
61
64
|
node.value = match;
|
|
62
65
|
node.nodes = [nodes[6]];
|
|
@@ -70,25 +73,33 @@ function rotateZ(node) {
|
|
|
70
73
|
|
|
71
74
|
function scale(node, values) {
|
|
72
75
|
const { nodes } = node;
|
|
76
|
+
|
|
73
77
|
if (!nodes[2]) {
|
|
74
78
|
return;
|
|
75
79
|
}
|
|
80
|
+
|
|
76
81
|
const [first, second] = values;
|
|
82
|
+
|
|
77
83
|
// scale(sx, sy) => scale(sx)
|
|
78
84
|
if (first === second) {
|
|
79
85
|
node.nodes = [nodes[0]];
|
|
86
|
+
|
|
80
87
|
return;
|
|
81
88
|
}
|
|
89
|
+
|
|
82
90
|
// scale(sx, 1) => scaleX(sx)
|
|
83
91
|
if (second === 1) {
|
|
84
92
|
node.value = 'scaleX';
|
|
85
93
|
node.nodes = [nodes[0]];
|
|
94
|
+
|
|
86
95
|
return;
|
|
87
96
|
}
|
|
97
|
+
|
|
88
98
|
// scale(1, sy) => scaleY(sy)
|
|
89
99
|
if (first === 1) {
|
|
90
100
|
node.value = 'scaleY';
|
|
91
101
|
node.nodes = [nodes[2]];
|
|
102
|
+
|
|
92
103
|
return;
|
|
93
104
|
}
|
|
94
105
|
}
|
|
@@ -96,46 +107,58 @@ function scale(node, values) {
|
|
|
96
107
|
function scale3d(node, values) {
|
|
97
108
|
const { nodes } = node;
|
|
98
109
|
const [first, second, third] = values;
|
|
110
|
+
|
|
99
111
|
// scale3d(sx, 1, 1) => scaleX(sx)
|
|
100
112
|
if (second === 1 && third === 1) {
|
|
101
113
|
node.value = 'scaleX';
|
|
102
114
|
node.nodes = [nodes[0]];
|
|
115
|
+
|
|
103
116
|
return;
|
|
104
117
|
}
|
|
118
|
+
|
|
105
119
|
// scale3d(1, sy, 1) => scaleY(sy)
|
|
106
120
|
if (first === 1 && third === 1) {
|
|
107
121
|
node.value = 'scaleY';
|
|
108
122
|
node.nodes = [nodes[2]];
|
|
123
|
+
|
|
109
124
|
return;
|
|
110
125
|
}
|
|
126
|
+
|
|
111
127
|
// scale3d(1, 1, sz) => scaleZ(sz)
|
|
112
128
|
if (first === 1 && second === 1) {
|
|
113
129
|
node.value = 'scaleZ';
|
|
114
130
|
node.nodes = [nodes[4]];
|
|
131
|
+
|
|
115
132
|
return;
|
|
116
133
|
}
|
|
117
134
|
}
|
|
118
135
|
|
|
119
136
|
function translate(node, values) {
|
|
120
137
|
const { nodes } = node;
|
|
138
|
+
|
|
121
139
|
if (!nodes[2]) {
|
|
122
140
|
return;
|
|
123
141
|
}
|
|
142
|
+
|
|
124
143
|
// translate(tx, 0) => translate(tx)
|
|
125
144
|
if (values[1] === 0) {
|
|
126
145
|
node.nodes = [nodes[0]];
|
|
146
|
+
|
|
127
147
|
return;
|
|
128
148
|
}
|
|
149
|
+
|
|
129
150
|
// translate(0, ty) => translateY(ty)
|
|
130
151
|
if (values[0] === 0) {
|
|
131
152
|
node.value = 'translateY';
|
|
132
153
|
node.nodes = [nodes[2]];
|
|
154
|
+
|
|
133
155
|
return;
|
|
134
156
|
}
|
|
135
157
|
}
|
|
136
158
|
|
|
137
159
|
function translate3d(node, values) {
|
|
138
160
|
const { nodes } = node;
|
|
161
|
+
|
|
139
162
|
// translate3d(0, 0, tz) => translateZ(tz)
|
|
140
163
|
if (values[0] === 0 && values[1] === 0) {
|
|
141
164
|
node.value = 'translateZ';
|
|
@@ -166,16 +189,31 @@ function normalizeReducerName(name) {
|
|
|
166
189
|
function reduce(node) {
|
|
167
190
|
const { nodes, type, value } = node;
|
|
168
191
|
const normalizedReducerName = normalizeReducerName(value);
|
|
192
|
+
|
|
169
193
|
if (type === 'function' && (0, _has2.default)(reducers, normalizedReducerName)) {
|
|
170
194
|
reducers[normalizedReducerName](node, nodes.reduce(getValues, []));
|
|
171
195
|
}
|
|
196
|
+
|
|
172
197
|
return false;
|
|
173
198
|
}
|
|
174
199
|
|
|
175
200
|
exports.default = _postcss2.default.plugin('postcss-reduce-transforms', () => {
|
|
176
201
|
return css => {
|
|
202
|
+
const cache = {};
|
|
203
|
+
|
|
177
204
|
css.walkDecls(/transform$/i, decl => {
|
|
178
|
-
|
|
205
|
+
const value = decl.value;
|
|
206
|
+
|
|
207
|
+
if (cache[value]) {
|
|
208
|
+
decl.value = cache[value];
|
|
209
|
+
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const result = (0, _postcssValueParser2.default)(value).walk(reduce).toString();
|
|
214
|
+
|
|
215
|
+
decl.value = result;
|
|
216
|
+
cache[value] = result;
|
|
179
217
|
});
|
|
180
218
|
};
|
|
181
219
|
});
|
package/package.json
CHANGED
package/CHANGELOG.md
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# 4.0.0-rc.0
|
|
2
|
-
|
|
3
|
-
* Breaking: Drops support for Node 0.12, we now require at least Node 4.
|
|
4
|
-
* Breaking: Update PostCSS to 6.0.0.
|
|
5
|
-
|
|
6
|
-
# 1.0.4
|
|
7
|
-
|
|
8
|
-
* Refactor the main module, slight performance tweak and ±0.9K less file size
|
|
9
|
-
on disk.
|
|
10
|
-
|
|
11
|
-
# 1.0.3
|
|
12
|
-
|
|
13
|
-
* The `translate(tx, 0)` compression was changed from `translateX(tx)`
|
|
14
|
-
to `translate(tx)`.
|
|
15
|
-
|
|
16
|
-
# 1.0.2
|
|
17
|
-
|
|
18
|
-
* Fixes an incorrect conversion of `translate(5, 5)` to `translate(5)`.
|
|
19
|
-
|
|
20
|
-
# 1.0.1
|
|
21
|
-
|
|
22
|
-
* Performance improvements (thanks to @TrySound).
|
|
23
|
-
|
|
24
|
-
# 1.0.0
|
|
25
|
-
|
|
26
|
-
* Initial release.
|