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.
Files changed (3) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/index.js +132 -201
  3. 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
- "use strict";
1
+ 'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
- value: true
4
+ value: true
5
5
  });
6
- exports.default = void 0;
7
6
 
8
- var _has = _interopRequireDefault(require("has"));
7
+ var _has = require('has');
9
8
 
10
- var _postcss = _interopRequireDefault(require("postcss"));
9
+ var _has2 = _interopRequireDefault(_has);
11
10
 
12
- var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser"));
11
+ var _postcss = require('postcss');
13
12
 
14
- var _cssnanoUtils = require("cssnano-utils");
13
+ var _postcss2 = _interopRequireDefault(_postcss);
15
14
 
16
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
15
+ var _postcssValueParser = require('postcss-value-parser');
17
16
 
18
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+ var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
19
18
 
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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
- if (node.type === 'function' && (node.value === 'var' || node.value === 'env') && node.nodes.length === 1) {
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
- return [...list, value];
33
- }
23
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
34
24
 
35
- return list;
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
- if (values.length !== 16) {
40
- return;
41
- } // matrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1) => matrix(a, b, c, d, tx, ty)
42
-
43
-
44
- 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) {
45
- const {
46
- nodes
47
- } = node;
48
- node.value = 'matrix';
49
- node.nodes = [nodes[0], // a
50
- nodes[1], // ,
51
- nodes[2], // b
52
- nodes[3], // ,
53
- nodes[8], // c
54
- nodes[9], // ,
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]] // rotate3d(0, 0, 1, a) => rotate(a)
67
- ];
68
- const rotate3dMatch = (0, _cssnanoUtils.getMatch)(rotate3dMappings);
53
+ ['rotate', [0, 0, 1]]];
54
+
55
+ const rotate3dMatch = (0, _cssnanoUtilGetMatch2.default)(rotate3dMappings);
69
56
 
70
57
  function rotate3d(node, values) {
71
- if (values.length !== 4) {
72
- return;
73
- }
74
-
75
- const {
76
- nodes
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, values) {
87
- if (values.length !== 1) {
88
- return;
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
- if (values.length !== 2) {
97
- return;
98
- }
99
-
100
- const {
101
- nodes
102
- } = node;
103
- const [first, second] = values; // scale(sx, sy) => scale(sx)
104
-
105
- if (first === second) {
106
- node.nodes = [nodes[0]];
107
- return;
108
- } // scale(sx, 1) => scaleX(sx)
109
-
110
-
111
- if (second === 1) {
112
- node.value = 'scaleX';
113
- node.nodes = [nodes[0]];
114
- return;
115
- } // scale(1, sy) => scaleY(sy)
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
- if (values.length !== 3) {
127
- return;
128
- }
129
-
130
- const {
131
- nodes
132
- } = node;
133
- const [first, second, third] = values; // scale3d(sx, 1, 1) => scaleX(sx)
134
-
135
- if (second === 1 && third === 1) {
136
- node.value = 'scaleX';
137
- node.nodes = [nodes[0]];
138
- return;
139
- } // scale3d(1, sy, 1) => scaleY(sy)
140
-
141
-
142
- if (first === 1 && third === 1) {
143
- node.value = 'scaleY';
144
- node.nodes = [nodes[2]];
145
- return;
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
- if (values.length !== 2) {
158
- return;
159
- }
160
-
161
- const {
162
- nodes
163
- } = node; // translate(tx, 0) => translate(tx)
164
-
165
- if (values[1] === 0) {
166
- node.nodes = [nodes[0]];
167
- return;
168
- } // translate(0, ty) => translateY(ty)
169
-
170
-
171
- if (values[0] === 0) {
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
- if (values.length !== 3) {
180
- return;
181
- }
182
-
183
- const {
184
- nodes
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
- matrix3d,
195
- rotate3d,
196
- rotateZ,
197
- scale,
198
- scale3d,
199
- translate,
200
- translate3d
147
+ matrix3d,
148
+ rotate3d,
149
+ rotateZ,
150
+ scale,
151
+ scale3d,
152
+ translate,
153
+ translate3d
201
154
  };
202
155
 
203
156
  function normalizeReducerName(name) {
204
- const lowerCasedName = name.toLowerCase();
157
+ const lowerCasedName = name.toLowerCase();
205
158
 
206
- if (lowerCasedName === 'rotatez') {
207
- return 'rotateZ';
208
- }
159
+ if (lowerCasedName === 'rotatez') {
160
+ return 'rotateZ';
161
+ }
209
162
 
210
- return lowerCasedName;
163
+ return lowerCasedName;
211
164
  }
212
165
 
213
166
  function reduce(node) {
214
- const {
215
- nodes,
216
- type,
217
- value
218
- } = node;
219
- const normalizedReducerName = normalizeReducerName(value);
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
- var _default = _postcss.default.plugin('postcss-reduce-transforms', () => {
229
- return css => {
230
- const cache = {};
231
- css.walkDecls(/transform$/i, decl => {
232
- const value = decl.value;
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-nightly.2020.9.3",
3
+ "version": "4.0.0",
4
4
  "description": "Reduce transform functions with PostCSS.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
- "prebuild": "",
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-utils": "nightly",
25
- "has": "^1.0.3",
26
- "postcss": "^7.0.16",
27
- "postcss-value-parser": "^3.3.1"
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": ">=10.13.0"
35
+ "node": ">=6.9.0"
34
36
  }
35
- }
37
+ }