postcss-reduce-transforms 4.0.0-rc.2 → 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/README.md +1 -1
- package/dist/index.js +31 -45
- package/package.json +7 -7
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,13 +22,9 @@ 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
|
}
|
|
35
29
|
return list;
|
|
36
30
|
}
|
|
@@ -38,8 +32,7 @@ function getValues(list, _ref, index) {
|
|
|
38
32
|
function matrix3d(node, values) {
|
|
39
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)
|
|
40
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) {
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
const { nodes } = node;
|
|
43
36
|
node.value = 'matrix';
|
|
44
37
|
node.nodes = [nodes[0], // a
|
|
45
38
|
nodes[1], // ,
|
|
@@ -55,16 +48,15 @@ function matrix3d(node, values) {
|
|
|
55
48
|
}
|
|
56
49
|
}
|
|
57
50
|
|
|
58
|
-
|
|
51
|
+
const rotate3dMappings = [['rotateX', [1, 0, 0]], // rotate3d(1, 0, 0, a) => rotateX(a)
|
|
59
52
|
['rotateY', [0, 1, 0]], // rotate3d(0, 1, 0, a) => rotateY(a)
|
|
60
53
|
['rotate', [0, 0, 1]]];
|
|
61
54
|
|
|
62
|
-
|
|
55
|
+
const rotate3dMatch = (0, _cssnanoUtilGetMatch2.default)(rotate3dMappings);
|
|
63
56
|
|
|
64
57
|
function rotate3d(node, values) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
var match = rotate3dMatch(values.slice(0, 3));
|
|
58
|
+
const { nodes } = node;
|
|
59
|
+
const match = rotate3dMatch(values.slice(0, 3));
|
|
68
60
|
if (match.length) {
|
|
69
61
|
node.value = match;
|
|
70
62
|
node.nodes = [nodes[6]];
|
|
@@ -77,18 +69,12 @@ function rotateZ(node) {
|
|
|
77
69
|
}
|
|
78
70
|
|
|
79
71
|
function scale(node, values) {
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
const { nodes } = node;
|
|
82
73
|
if (!nodes[2]) {
|
|
83
74
|
return;
|
|
84
75
|
}
|
|
85
|
-
|
|
86
|
-
var _values = _slicedToArray(values, 2),
|
|
87
|
-
first = _values[0],
|
|
88
|
-
second = _values[1];
|
|
76
|
+
const [first, second] = values;
|
|
89
77
|
// scale(sx, sy) => scale(sx)
|
|
90
|
-
|
|
91
|
-
|
|
92
78
|
if (first === second) {
|
|
93
79
|
node.nodes = [nodes[0]];
|
|
94
80
|
return;
|
|
@@ -108,15 +94,9 @@ function scale(node, values) {
|
|
|
108
94
|
}
|
|
109
95
|
|
|
110
96
|
function scale3d(node, values) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
var _values2 = _slicedToArray(values, 3),
|
|
114
|
-
first = _values2[0],
|
|
115
|
-
second = _values2[1],
|
|
116
|
-
third = _values2[2];
|
|
97
|
+
const { nodes } = node;
|
|
98
|
+
const [first, second, third] = values;
|
|
117
99
|
// scale3d(sx, 1, 1) => scaleX(sx)
|
|
118
|
-
|
|
119
|
-
|
|
120
100
|
if (second === 1 && third === 1) {
|
|
121
101
|
node.value = 'scaleX';
|
|
122
102
|
node.nodes = [nodes[0]];
|
|
@@ -137,8 +117,7 @@ function scale3d(node, values) {
|
|
|
137
117
|
}
|
|
138
118
|
|
|
139
119
|
function translate(node, values) {
|
|
140
|
-
|
|
141
|
-
|
|
120
|
+
const { nodes } = node;
|
|
142
121
|
if (!nodes[2]) {
|
|
143
122
|
return;
|
|
144
123
|
}
|
|
@@ -156,16 +135,15 @@ function translate(node, values) {
|
|
|
156
135
|
}
|
|
157
136
|
|
|
158
137
|
function translate3d(node, values) {
|
|
159
|
-
|
|
138
|
+
const { nodes } = node;
|
|
160
139
|
// translate3d(0, 0, tz) => translateZ(tz)
|
|
161
|
-
|
|
162
140
|
if (values[0] === 0 && values[1] === 0) {
|
|
163
141
|
node.value = 'translateZ';
|
|
164
142
|
node.nodes = [nodes[4]];
|
|
165
143
|
}
|
|
166
144
|
}
|
|
167
145
|
|
|
168
|
-
|
|
146
|
+
const reducers = {
|
|
169
147
|
matrix3d,
|
|
170
148
|
rotate3d,
|
|
171
149
|
rotateZ,
|
|
@@ -175,20 +153,28 @@ var reducers = {
|
|
|
175
153
|
translate3d
|
|
176
154
|
};
|
|
177
155
|
|
|
178
|
-
function
|
|
179
|
-
|
|
180
|
-
type = node.type,
|
|
181
|
-
value = node.value;
|
|
156
|
+
function normalizeReducerName(name) {
|
|
157
|
+
const lowerCasedName = name.toLowerCase();
|
|
182
158
|
|
|
183
|
-
if (
|
|
184
|
-
|
|
159
|
+
if (lowerCasedName === 'rotatez') {
|
|
160
|
+
return 'rotateZ';
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return lowerCasedName;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function reduce(node) {
|
|
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, []));
|
|
185
171
|
}
|
|
186
172
|
return false;
|
|
187
173
|
}
|
|
188
174
|
|
|
189
|
-
exports.default = _postcss2.default.plugin('postcss-reduce-transforms',
|
|
190
|
-
return
|
|
191
|
-
css.walkDecls(/transform
|
|
175
|
+
exports.default = _postcss2.default.plugin('postcss-reduce-transforms', () => {
|
|
176
|
+
return css => {
|
|
177
|
+
css.walkDecls(/transform$/i, decl => {
|
|
192
178
|
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(reduce).toString();
|
|
193
179
|
});
|
|
194
180
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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": {
|
|
@@ -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
28
|
"postcss": "^6.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
|
}
|