postcss-reduce-transforms 4.0.0-rc.0 → 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/README.md +1 -1
- package/dist/index.js +63 -39
- package/package.json +8 -8
- package/CHANGELOG.md +0 -26
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
8
|
-
|
|
9
7
|
var _has = require('has');
|
|
10
8
|
|
|
11
9
|
var _has2 = _interopRequireDefault(_has);
|
|
@@ -24,21 +22,18 @@ var _cssnanoUtilGetMatch2 = _interopRequireDefault(_cssnanoUtilGetMatch);
|
|
|
24
22
|
|
|
25
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
26
24
|
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
function getValues(list, _ref, index) {
|
|
30
|
-
var value = _ref.value;
|
|
31
|
-
|
|
25
|
+
function getValues(list, { value }, index) {
|
|
32
26
|
if (index % 2 === 0) {
|
|
33
|
-
return [
|
|
27
|
+
return [...list, parseFloat(value)];
|
|
34
28
|
}
|
|
29
|
+
|
|
35
30
|
return list;
|
|
36
31
|
}
|
|
37
32
|
|
|
38
33
|
function matrix3d(node, values) {
|
|
39
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)
|
|
40
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) {
|
|
41
|
-
|
|
36
|
+
const { nodes } = node;
|
|
42
37
|
|
|
43
38
|
node.value = 'matrix';
|
|
44
39
|
node.nodes = [nodes[0], // a
|
|
@@ -55,16 +50,16 @@ function matrix3d(node, values) {
|
|
|
55
50
|
}
|
|
56
51
|
}
|
|
57
52
|
|
|
58
|
-
|
|
53
|
+
const rotate3dMappings = [['rotateX', [1, 0, 0]], // rotate3d(1, 0, 0, a) => rotateX(a)
|
|
59
54
|
['rotateY', [0, 1, 0]], // rotate3d(0, 1, 0, a) => rotateY(a)
|
|
60
55
|
['rotate', [0, 0, 1]]];
|
|
61
56
|
|
|
62
|
-
|
|
57
|
+
const rotate3dMatch = (0, _cssnanoUtilGetMatch2.default)(rotate3dMappings);
|
|
63
58
|
|
|
64
59
|
function rotate3d(node, values) {
|
|
65
|
-
|
|
60
|
+
const { nodes } = node;
|
|
61
|
+
const match = rotate3dMatch(values.slice(0, 3));
|
|
66
62
|
|
|
67
|
-
var match = rotate3dMatch(values.slice(0, 3));
|
|
68
63
|
if (match.length) {
|
|
69
64
|
node.value = match;
|
|
70
65
|
node.nodes = [nodes[6]];
|
|
@@ -77,95 +72,101 @@ function rotateZ(node) {
|
|
|
77
72
|
}
|
|
78
73
|
|
|
79
74
|
function scale(node, values) {
|
|
80
|
-
|
|
75
|
+
const { nodes } = node;
|
|
81
76
|
|
|
82
77
|
if (!nodes[2]) {
|
|
83
78
|
return;
|
|
84
79
|
}
|
|
85
80
|
|
|
86
|
-
|
|
87
|
-
first = _values[0],
|
|
88
|
-
second = _values[1];
|
|
89
|
-
// scale(sx, sy) => scale(sx)
|
|
90
|
-
|
|
81
|
+
const [first, second] = values;
|
|
91
82
|
|
|
83
|
+
// scale(sx, sy) => scale(sx)
|
|
92
84
|
if (first === second) {
|
|
93
85
|
node.nodes = [nodes[0]];
|
|
86
|
+
|
|
94
87
|
return;
|
|
95
88
|
}
|
|
89
|
+
|
|
96
90
|
// scale(sx, 1) => scaleX(sx)
|
|
97
91
|
if (second === 1) {
|
|
98
92
|
node.value = 'scaleX';
|
|
99
93
|
node.nodes = [nodes[0]];
|
|
94
|
+
|
|
100
95
|
return;
|
|
101
96
|
}
|
|
97
|
+
|
|
102
98
|
// scale(1, sy) => scaleY(sy)
|
|
103
99
|
if (first === 1) {
|
|
104
100
|
node.value = 'scaleY';
|
|
105
101
|
node.nodes = [nodes[2]];
|
|
102
|
+
|
|
106
103
|
return;
|
|
107
104
|
}
|
|
108
105
|
}
|
|
109
106
|
|
|
110
107
|
function scale3d(node, values) {
|
|
111
|
-
|
|
108
|
+
const { nodes } = node;
|
|
109
|
+
const [first, second, third] = values;
|
|
112
110
|
|
|
113
|
-
var _values2 = _slicedToArray(values, 3),
|
|
114
|
-
first = _values2[0],
|
|
115
|
-
second = _values2[1],
|
|
116
|
-
third = _values2[2];
|
|
117
111
|
// scale3d(sx, 1, 1) => scaleX(sx)
|
|
118
|
-
|
|
119
|
-
|
|
120
112
|
if (second === 1 && third === 1) {
|
|
121
113
|
node.value = 'scaleX';
|
|
122
114
|
node.nodes = [nodes[0]];
|
|
115
|
+
|
|
123
116
|
return;
|
|
124
117
|
}
|
|
118
|
+
|
|
125
119
|
// scale3d(1, sy, 1) => scaleY(sy)
|
|
126
120
|
if (first === 1 && third === 1) {
|
|
127
121
|
node.value = 'scaleY';
|
|
128
122
|
node.nodes = [nodes[2]];
|
|
123
|
+
|
|
129
124
|
return;
|
|
130
125
|
}
|
|
126
|
+
|
|
131
127
|
// scale3d(1, 1, sz) => scaleZ(sz)
|
|
132
128
|
if (first === 1 && second === 1) {
|
|
133
129
|
node.value = 'scaleZ';
|
|
134
130
|
node.nodes = [nodes[4]];
|
|
131
|
+
|
|
135
132
|
return;
|
|
136
133
|
}
|
|
137
134
|
}
|
|
138
135
|
|
|
139
136
|
function translate(node, values) {
|
|
140
|
-
|
|
137
|
+
const { nodes } = node;
|
|
141
138
|
|
|
142
139
|
if (!nodes[2]) {
|
|
143
140
|
return;
|
|
144
141
|
}
|
|
142
|
+
|
|
145
143
|
// translate(tx, 0) => translate(tx)
|
|
146
144
|
if (values[1] === 0) {
|
|
147
145
|
node.nodes = [nodes[0]];
|
|
146
|
+
|
|
148
147
|
return;
|
|
149
148
|
}
|
|
149
|
+
|
|
150
150
|
// translate(0, ty) => translateY(ty)
|
|
151
151
|
if (values[0] === 0) {
|
|
152
152
|
node.value = 'translateY';
|
|
153
153
|
node.nodes = [nodes[2]];
|
|
154
|
+
|
|
154
155
|
return;
|
|
155
156
|
}
|
|
156
157
|
}
|
|
157
158
|
|
|
158
159
|
function translate3d(node, values) {
|
|
159
|
-
|
|
160
|
-
// translate3d(0, 0, tz) => translateZ(tz)
|
|
160
|
+
const { nodes } = node;
|
|
161
161
|
|
|
162
|
+
// translate3d(0, 0, tz) => translateZ(tz)
|
|
162
163
|
if (values[0] === 0 && values[1] === 0) {
|
|
163
164
|
node.value = 'translateZ';
|
|
164
165
|
node.nodes = [nodes[4]];
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
|
|
168
|
-
|
|
169
|
+
const reducers = {
|
|
169
170
|
matrix3d,
|
|
170
171
|
rotate3d,
|
|
171
172
|
rotateZ,
|
|
@@ -175,21 +176,44 @@ var reducers = {
|
|
|
175
176
|
translate3d
|
|
176
177
|
};
|
|
177
178
|
|
|
179
|
+
function normalizeReducerName(name) {
|
|
180
|
+
const lowerCasedName = name.toLowerCase();
|
|
181
|
+
|
|
182
|
+
if (lowerCasedName === 'rotatez') {
|
|
183
|
+
return 'rotateZ';
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return lowerCasedName;
|
|
187
|
+
}
|
|
188
|
+
|
|
178
189
|
function reduce(node) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
value = node.value;
|
|
190
|
+
const { nodes, type, value } = node;
|
|
191
|
+
const normalizedReducerName = normalizeReducerName(value);
|
|
182
192
|
|
|
183
|
-
if (type === 'function' && (0, _has2.default)(reducers,
|
|
184
|
-
reducers[
|
|
193
|
+
if (type === 'function' && (0, _has2.default)(reducers, normalizedReducerName)) {
|
|
194
|
+
reducers[normalizedReducerName](node, nodes.reduce(getValues, []));
|
|
185
195
|
}
|
|
196
|
+
|
|
186
197
|
return false;
|
|
187
198
|
}
|
|
188
199
|
|
|
189
|
-
exports.default = _postcss2.default.plugin('postcss-reduce-transforms',
|
|
190
|
-
return
|
|
191
|
-
|
|
192
|
-
|
|
200
|
+
exports.default = _postcss2.default.plugin('postcss-reduce-transforms', () => {
|
|
201
|
+
return css => {
|
|
202
|
+
const cache = {};
|
|
203
|
+
|
|
204
|
+
css.walkDecls(/transform$/i, decl => {
|
|
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;
|
|
193
217
|
});
|
|
194
218
|
};
|
|
195
219
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-reduce-transforms",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Reduce transform functions with PostCSS.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,25 +13,25 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"babel-cli": "^6.0.0",
|
|
16
|
-
"cross-env": "^
|
|
16
|
+
"cross-env": "^5.0.0"
|
|
17
17
|
},
|
|
18
|
-
"homepage": "https://github.com/
|
|
18
|
+
"homepage": "https://github.com/cssnano/cssnano",
|
|
19
19
|
"author": {
|
|
20
20
|
"name": "Ben Briggs",
|
|
21
21
|
"email": "beneb.info@gmail.com",
|
|
22
22
|
"url": "http://beneb.info"
|
|
23
23
|
},
|
|
24
|
-
"repository": "
|
|
24
|
+
"repository": "cssnano/cssnano",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"cssnano-util-get-match": "^4.0.0
|
|
26
|
+
"cssnano-util-get-match": "^4.0.0",
|
|
27
27
|
"has": "^1.0.0",
|
|
28
|
-
"postcss": "^
|
|
28
|
+
"postcss": "^7.0.0",
|
|
29
29
|
"postcss-value-parser": "^3.0.0"
|
|
30
30
|
},
|
|
31
31
|
"bugs": {
|
|
32
|
-
"url": "https://github.com/
|
|
32
|
+
"url": "https://github.com/cssnano/cssnano/issues"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
|
-
"node": ">=
|
|
35
|
+
"node": ">=6.9.0"
|
|
36
36
|
}
|
|
37
37
|
}
|
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.
|