postcss-reduce-transforms 4.0.0-nightly.2020.9.3 → 4.0.0
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 +26 -0
- package/dist/index.js +132 -201
- package/package.json +12 -10
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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.
|
package/dist/index.js
CHANGED
|
@@ -1,251 +1,182 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
7
6
|
|
|
8
|
-
var _has =
|
|
7
|
+
var _has = require('has');
|
|
9
8
|
|
|
10
|
-
var
|
|
9
|
+
var _has2 = _interopRequireDefault(_has);
|
|
11
10
|
|
|
12
|
-
var
|
|
11
|
+
var _postcss = require('postcss');
|
|
13
12
|
|
|
14
|
-
var
|
|
13
|
+
var _postcss2 = _interopRequireDefault(_postcss);
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
var _postcssValueParser = require('postcss-value-parser');
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function getValues(list, node, index) {
|
|
23
|
-
if (index % 2 === 0) {
|
|
24
|
-
let value = NaN;
|
|
19
|
+
var _cssnanoUtilGetMatch = require('cssnano-util-get-match');
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
value = (0, _postcssValueParser.stringify)(node.nodes);
|
|
28
|
-
} else if (node.type === 'word') {
|
|
29
|
-
value = parseFloat(node.value);
|
|
30
|
-
}
|
|
21
|
+
var _cssnanoUtilGetMatch2 = _interopRequireDefault(_cssnanoUtilGetMatch);
|
|
31
22
|
|
|
32
|
-
|
|
33
|
-
}
|
|
23
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
34
24
|
|
|
35
|
-
|
|
25
|
+
function getValues(list, { value }, index) {
|
|
26
|
+
if (index % 2 === 0) {
|
|
27
|
+
return [...list, parseFloat(value)];
|
|
28
|
+
}
|
|
29
|
+
return list;
|
|
36
30
|
}
|
|
37
31
|
|
|
38
32
|
function matrix3d(node, values) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
nodes[10], // d
|
|
56
|
-
nodes[11], // ,
|
|
57
|
-
nodes[24], // tx
|
|
58
|
-
nodes[25], // ,
|
|
59
|
-
nodes[26] // ty
|
|
60
|
-
];
|
|
61
|
-
}
|
|
33
|
+
// 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
|
+
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
|
+
const { nodes } = node;
|
|
36
|
+
node.value = 'matrix';
|
|
37
|
+
node.nodes = [nodes[0], // a
|
|
38
|
+
nodes[1], // ,
|
|
39
|
+
nodes[2], // b
|
|
40
|
+
nodes[3], // ,
|
|
41
|
+
nodes[8], // c
|
|
42
|
+
nodes[9], // ,
|
|
43
|
+
nodes[10], // d
|
|
44
|
+
nodes[11], // ,
|
|
45
|
+
nodes[24], // tx
|
|
46
|
+
nodes[25], // ,
|
|
47
|
+
nodes[26]];
|
|
48
|
+
}
|
|
62
49
|
}
|
|
63
50
|
|
|
64
51
|
const rotate3dMappings = [['rotateX', [1, 0, 0]], // rotate3d(1, 0, 0, a) => rotateX(a)
|
|
65
52
|
['rotateY', [0, 1, 0]], // rotate3d(0, 1, 0, a) => rotateY(a)
|
|
66
|
-
['rotate', [0, 0, 1]]
|
|
67
|
-
|
|
68
|
-
const rotate3dMatch = (0,
|
|
53
|
+
['rotate', [0, 0, 1]]];
|
|
54
|
+
|
|
55
|
+
const rotate3dMatch = (0, _cssnanoUtilGetMatch2.default)(rotate3dMappings);
|
|
69
56
|
|
|
70
57
|
function rotate3d(node, values) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
} = node;
|
|
78
|
-
const match = rotate3dMatch(values.slice(0, 3));
|
|
79
|
-
|
|
80
|
-
if (match.length) {
|
|
81
|
-
node.value = match;
|
|
82
|
-
node.nodes = [nodes[6]];
|
|
83
|
-
}
|
|
58
|
+
const { nodes } = node;
|
|
59
|
+
const match = rotate3dMatch(values.slice(0, 3));
|
|
60
|
+
if (match.length) {
|
|
61
|
+
node.value = match;
|
|
62
|
+
node.nodes = [nodes[6]];
|
|
63
|
+
}
|
|
84
64
|
}
|
|
85
65
|
|
|
86
|
-
function rotateZ(node
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
} // rotateZ(rz) => rotate(rz)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
node.value = 'rotate';
|
|
66
|
+
function rotateZ(node) {
|
|
67
|
+
// rotateZ(rz) => rotate(rz)
|
|
68
|
+
node.value = 'rotate';
|
|
93
69
|
}
|
|
94
70
|
|
|
95
71
|
function scale(node, values) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (first === 1) {
|
|
119
|
-
node.value = 'scaleY';
|
|
120
|
-
node.nodes = [nodes[2]];
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
72
|
+
const { nodes } = node;
|
|
73
|
+
if (!nodes[2]) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const [first, second] = values;
|
|
77
|
+
// scale(sx, sy) => scale(sx)
|
|
78
|
+
if (first === second) {
|
|
79
|
+
node.nodes = [nodes[0]];
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// scale(sx, 1) => scaleX(sx)
|
|
83
|
+
if (second === 1) {
|
|
84
|
+
node.value = 'scaleX';
|
|
85
|
+
node.nodes = [nodes[0]];
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// scale(1, sy) => scaleY(sy)
|
|
89
|
+
if (first === 1) {
|
|
90
|
+
node.value = 'scaleY';
|
|
91
|
+
node.nodes = [nodes[2]];
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
123
94
|
}
|
|
124
95
|
|
|
125
96
|
function scale3d(node, values) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
} // scale3d(1, 1, sz) => scaleZ(sz)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (first === 1 && second === 1) {
|
|
150
|
-
node.value = 'scaleZ';
|
|
151
|
-
node.nodes = [nodes[4]];
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
97
|
+
const { nodes } = node;
|
|
98
|
+
const [first, second, third] = values;
|
|
99
|
+
// scale3d(sx, 1, 1) => scaleX(sx)
|
|
100
|
+
if (second === 1 && third === 1) {
|
|
101
|
+
node.value = 'scaleX';
|
|
102
|
+
node.nodes = [nodes[0]];
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
// scale3d(1, sy, 1) => scaleY(sy)
|
|
106
|
+
if (first === 1 && third === 1) {
|
|
107
|
+
node.value = 'scaleY';
|
|
108
|
+
node.nodes = [nodes[2]];
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
// scale3d(1, 1, sz) => scaleZ(sz)
|
|
112
|
+
if (first === 1 && second === 1) {
|
|
113
|
+
node.value = 'scaleZ';
|
|
114
|
+
node.nodes = [nodes[4]];
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
154
117
|
}
|
|
155
118
|
|
|
156
119
|
function translate(node, values) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
node.value = 'translateY';
|
|
173
|
-
node.nodes = [nodes[2]];
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
120
|
+
const { nodes } = node;
|
|
121
|
+
if (!nodes[2]) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
// translate(tx, 0) => translate(tx)
|
|
125
|
+
if (values[1] === 0) {
|
|
126
|
+
node.nodes = [nodes[0]];
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// translate(0, ty) => translateY(ty)
|
|
130
|
+
if (values[0] === 0) {
|
|
131
|
+
node.value = 'translateY';
|
|
132
|
+
node.nodes = [nodes[2]];
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
176
135
|
}
|
|
177
136
|
|
|
178
137
|
function translate3d(node, values) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
} = node; // translate3d(0, 0, tz) => translateZ(tz)
|
|
186
|
-
|
|
187
|
-
if (values[0] === 0 && values[1] === 0) {
|
|
188
|
-
node.value = 'translateZ';
|
|
189
|
-
node.nodes = [nodes[4]];
|
|
190
|
-
}
|
|
138
|
+
const { nodes } = node;
|
|
139
|
+
// translate3d(0, 0, tz) => translateZ(tz)
|
|
140
|
+
if (values[0] === 0 && values[1] === 0) {
|
|
141
|
+
node.value = 'translateZ';
|
|
142
|
+
node.nodes = [nodes[4]];
|
|
143
|
+
}
|
|
191
144
|
}
|
|
192
145
|
|
|
193
146
|
const reducers = {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
147
|
+
matrix3d,
|
|
148
|
+
rotate3d,
|
|
149
|
+
rotateZ,
|
|
150
|
+
scale,
|
|
151
|
+
scale3d,
|
|
152
|
+
translate,
|
|
153
|
+
translate3d
|
|
201
154
|
};
|
|
202
155
|
|
|
203
156
|
function normalizeReducerName(name) {
|
|
204
|
-
|
|
157
|
+
const lowerCasedName = name.toLowerCase();
|
|
205
158
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
159
|
+
if (lowerCasedName === 'rotatez') {
|
|
160
|
+
return 'rotateZ';
|
|
161
|
+
}
|
|
209
162
|
|
|
210
|
-
|
|
163
|
+
return lowerCasedName;
|
|
211
164
|
}
|
|
212
165
|
|
|
213
166
|
function reduce(node) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
type,
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (type === 'function' && (0, _has.default)(reducers, normalizedReducerName)) {
|
|
222
|
-
reducers[normalizedReducerName](node, nodes.reduce(getValues, []));
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return false;
|
|
167
|
+
const { nodes, type, value } = node;
|
|
168
|
+
const normalizedReducerName = normalizeReducerName(value);
|
|
169
|
+
if (type === 'function' && (0, _has2.default)(reducers, normalizedReducerName)) {
|
|
170
|
+
reducers[normalizedReducerName](node, nodes.reduce(getValues, []));
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
226
173
|
}
|
|
227
174
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (!value) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (cache[value]) {
|
|
239
|
-
decl.value = cache[value];
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const result = (0, _postcssValueParser.default)(value).walk(reduce).toString();
|
|
244
|
-
decl.value = result;
|
|
245
|
-
cache[value] = result;
|
|
246
|
-
});
|
|
247
|
-
};
|
|
175
|
+
exports.default = _postcss2.default.plugin('postcss-reduce-transforms', () => {
|
|
176
|
+
return css => {
|
|
177
|
+
css.walkDecls(/transform$/i, decl => {
|
|
178
|
+
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(reduce).toString();
|
|
179
|
+
});
|
|
180
|
+
};
|
|
248
181
|
});
|
|
249
|
-
|
|
250
|
-
exports.default = _default;
|
|
251
|
-
module.exports = exports.default;
|
|
182
|
+
module.exports = exports['default'];
|
package/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-reduce-transforms",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Reduce transform functions with PostCSS.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
|
|
9
|
-
"prepublish": ""
|
|
7
|
+
"prepublish": "cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/"
|
|
10
8
|
},
|
|
11
9
|
"files": [
|
|
12
10
|
"LICENSE-MIT",
|
|
13
11
|
"dist"
|
|
14
12
|
],
|
|
15
13
|
"license": "MIT",
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"babel-cli": "^6.0.0",
|
|
16
|
+
"cross-env": "^5.0.0"
|
|
17
|
+
},
|
|
16
18
|
"homepage": "https://github.com/cssnano/cssnano",
|
|
17
19
|
"author": {
|
|
18
20
|
"name": "Ben Briggs",
|
|
@@ -21,15 +23,15 @@
|
|
|
21
23
|
},
|
|
22
24
|
"repository": "cssnano/cssnano",
|
|
23
25
|
"dependencies": {
|
|
24
|
-
"cssnano-
|
|
25
|
-
"has": "^1.0.
|
|
26
|
-
"postcss": "^
|
|
27
|
-
"postcss-value-parser": "^3.
|
|
26
|
+
"cssnano-util-get-match": "^4.0.0",
|
|
27
|
+
"has": "^1.0.0",
|
|
28
|
+
"postcss": "^6.0.0",
|
|
29
|
+
"postcss-value-parser": "^3.0.0"
|
|
28
30
|
},
|
|
29
31
|
"bugs": {
|
|
30
32
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
31
33
|
},
|
|
32
34
|
"engines": {
|
|
33
|
-
"node": ">=
|
|
35
|
+
"node": ">=6.9.0"
|
|
34
36
|
}
|
|
35
|
-
}
|
|
37
|
+
}
|