postcss-reduce-transforms 4.0.2 → 5.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 +70 -0
  2. package/dist/index.js +192 -155
  3. package/package.json +15 -12
package/CHANGELOG.md ADDED
@@ -0,0 +1,70 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [5.0.0](https://github.com/cssnano/cssnano/compare/postcss-reduce-transforms@5.0.0-rc.2...postcss-reduce-transforms@5.0.0) (2021-04-06)
7
+
8
+ **Note:** Version bump only for package postcss-reduce-transforms
9
+
10
+
11
+
12
+
13
+
14
+ # [5.0.0-rc.2](https://github.com/cssnano/cssnano/compare/postcss-reduce-transforms@5.0.0-rc.1...postcss-reduce-transforms@5.0.0-rc.2) (2021-03-15)
15
+
16
+ **Note:** Version bump only for package postcss-reduce-transforms
17
+
18
+
19
+
20
+
21
+
22
+ # [5.0.0-rc.1](https://github.com/cssnano/cssnano/compare/postcss-reduce-transforms@5.0.0-rc.0...postcss-reduce-transforms@5.0.0-rc.1) (2021-03-04)
23
+
24
+ **Note:** Version bump only for package postcss-reduce-transforms
25
+
26
+
27
+
28
+
29
+
30
+ # 5.0.0-rc.0 (2021-02-19)
31
+
32
+
33
+ ### chore
34
+
35
+ * minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
36
+
37
+
38
+ ### Features
39
+
40
+ * migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
41
+ * **postcss-reduce-transforms:** improve optimizations ([#745](https://github.com/cssnano/cssnano/issues/745)) ([b0f0d89](https://github.com/cssnano/cssnano/commit/b0f0d892316d7b77e8033a6dc8d67745043a5072))
42
+
43
+
44
+ ### BREAKING CHANGES
45
+
46
+ * minimum supported `postcss` version is `8.2.1`
47
+ * minimum require version of node is 10.13
48
+
49
+
50
+
51
+ ## 4.1.9 (2019-02-12)
52
+
53
+
54
+ ### Bug Fixes
55
+
56
+ * **fix-postcss-reduce-transforms:** cache ([#691](https://github.com/cssnano/cssnano/issues/691)) ([e07309f](https://github.com/cssnano/cssnano/commit/e07309ff0c07fb36ef2340bbed6b3aee3dad18be))
57
+
58
+
59
+ ### Performance Improvements
60
+
61
+ * **postcss-reduce-transforms:** increase perf ([#688](https://github.com/cssnano/cssnano/issues/688)) ([84ccba0](https://github.com/cssnano/cssnano/commit/84ccba00cead30e80510525cbcd27ba259c26065))
62
+
63
+
64
+
65
+ ## 4.1.1 (2018-09-24)
66
+
67
+
68
+ ### Bug Fixes
69
+
70
+ * **postcss-merge-longhand:** not mangle border output ([#555](https://github.com/cssnano/cssnano/issues/555)) ([9a70605](https://github.com/cssnano/cssnano/commit/9a706050b621e7795a9bf74eb7110b5c81804ffe)), closes [#553](https://github.com/cssnano/cssnano/issues/553) [#554](https://github.com/cssnano/cssnano/issues/554)
package/dist/index.js CHANGED
@@ -1,220 +1,257 @@
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;
6
7
 
7
- var _has = require('has');
8
+ var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser"));
8
9
 
9
- var _has2 = _interopRequireDefault(_has);
10
+ var _cssnanoUtils = require("cssnano-utils");
10
11
 
11
- var _postcss = require('postcss');
12
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
12
13
 
13
- var _postcss2 = _interopRequireDefault(_postcss);
14
+ 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; }
14
15
 
15
- var _postcssValueParser = require('postcss-value-parser');
16
+ function getValues(list, node, index) {
17
+ if (index % 2 === 0) {
18
+ let value = NaN;
16
19
 
17
- var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
18
-
19
- var _cssnanoUtilGetMatch = require('cssnano-util-get-match');
20
-
21
- var _cssnanoUtilGetMatch2 = _interopRequireDefault(_cssnanoUtilGetMatch);
22
-
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
-
25
- function getValues(list, { value }, index) {
26
- if (index % 2 === 0) {
27
- return [...list, parseFloat(value)];
20
+ if (node.type === 'function' && (node.value === 'var' || node.value === 'env') && node.nodes.length === 1) {
21
+ value = (0, _postcssValueParser.stringify)(node.nodes);
22
+ } else if (node.type === 'word') {
23
+ value = parseFloat(node.value);
28
24
  }
29
25
 
30
- return list;
26
+ return [...list, value];
27
+ }
28
+
29
+ return list;
31
30
  }
32
31
 
33
32
  function matrix3d(node, values) {
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)
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) {
36
- const { nodes } = node;
37
-
38
- node.value = 'matrix';
39
- node.nodes = [nodes[0], // a
40
- nodes[1], // ,
41
- nodes[2], // b
42
- nodes[3], // ,
43
- nodes[8], // c
44
- nodes[9], // ,
45
- nodes[10], // d
46
- nodes[11], // ,
47
- nodes[24], // tx
48
- nodes[25], // ,
49
- nodes[26]];
50
- }
33
+ if (values.length !== 16) {
34
+ return;
35
+ } // matrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1) => matrix(a, b, c, d, tx, ty)
36
+
37
+
38
+ 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) {
39
+ const {
40
+ nodes
41
+ } = node;
42
+ node.value = 'matrix';
43
+ node.nodes = [nodes[0], // a
44
+ nodes[1], // ,
45
+ nodes[2], // b
46
+ nodes[3], // ,
47
+ nodes[8], // c
48
+ nodes[9], // ,
49
+ nodes[10], // d
50
+ nodes[11], // ,
51
+ nodes[24], // tx
52
+ nodes[25], // ,
53
+ nodes[26] // ty
54
+ ];
55
+ }
51
56
  }
52
57
 
53
58
  const rotate3dMappings = [['rotateX', [1, 0, 0]], // rotate3d(1, 0, 0, a) => rotateX(a)
54
59
  ['rotateY', [0, 1, 0]], // rotate3d(0, 1, 0, a) => rotateY(a)
55
- ['rotate', [0, 0, 1]]];
56
-
57
- const rotate3dMatch = (0, _cssnanoUtilGetMatch2.default)(rotate3dMappings);
60
+ ['rotate', [0, 0, 1]] // rotate3d(0, 0, 1, a) => rotate(a)
61
+ ];
62
+ const rotate3dMatch = (0, _cssnanoUtils.getMatch)(rotate3dMappings);
58
63
 
59
64
  function rotate3d(node, values) {
60
- const { nodes } = node;
61
- const match = rotate3dMatch(values.slice(0, 3));
62
-
63
- if (match.length) {
64
- node.value = match;
65
- node.nodes = [nodes[6]];
66
- }
65
+ if (values.length !== 4) {
66
+ return;
67
+ }
68
+
69
+ const {
70
+ nodes
71
+ } = node;
72
+ const match = rotate3dMatch(values.slice(0, 3));
73
+
74
+ if (match.length) {
75
+ node.value = match;
76
+ node.nodes = [nodes[6]];
77
+ }
67
78
  }
68
79
 
69
- function rotateZ(node) {
70
- // rotateZ(rz) => rotate(rz)
71
- node.value = 'rotate';
72
- }
80
+ function rotateZ(node, values) {
81
+ if (values.length !== 1) {
82
+ return;
83
+ } // rotateZ(rz) => rotate(rz)
73
84
 
74
- function scale(node, values) {
75
- const { nodes } = node;
76
85
 
77
- if (!nodes[2]) {
78
- return;
79
- }
86
+ node.value = 'rotate';
87
+ }
80
88
 
81
- const [first, second] = values;
89
+ function scale(node, values) {
90
+ if (values.length !== 2) {
91
+ return;
92
+ }
82
93
 
83
- // scale(sx, sy) => scale(sx)
84
- if (first === second) {
85
- node.nodes = [nodes[0]];
94
+ const {
95
+ nodes
96
+ } = node;
97
+ const [first, second] = values; // scale(sx, sy) => scale(sx)
86
98
 
87
- return;
88
- }
99
+ if (first === second) {
100
+ node.nodes = [nodes[0]];
101
+ return;
102
+ } // scale(sx, 1) => scaleX(sx)
89
103
 
90
- // scale(sx, 1) => scaleX(sx)
91
- if (second === 1) {
92
- node.value = 'scaleX';
93
- node.nodes = [nodes[0]];
94
104
 
95
- return;
96
- }
105
+ if (second === 1) {
106
+ node.value = 'scaleX';
107
+ node.nodes = [nodes[0]];
108
+ return;
109
+ } // scale(1, sy) => scaleY(sy)
97
110
 
98
- // scale(1, sy) => scaleY(sy)
99
- if (first === 1) {
100
- node.value = 'scaleY';
101
- node.nodes = [nodes[2]];
102
111
 
103
- return;
104
- }
112
+ if (first === 1) {
113
+ node.value = 'scaleY';
114
+ node.nodes = [nodes[2]];
115
+ return;
116
+ }
105
117
  }
106
118
 
107
119
  function scale3d(node, values) {
108
- const { nodes } = node;
109
- const [first, second, third] = values;
110
-
111
- // scale3d(sx, 1, 1) => scaleX(sx)
112
- if (second === 1 && third === 1) {
113
- node.value = 'scaleX';
114
- node.nodes = [nodes[0]];
115
-
116
- return;
117
- }
118
-
119
- // scale3d(1, sy, 1) => scaleY(sy)
120
- if (first === 1 && third === 1) {
121
- node.value = 'scaleY';
122
- node.nodes = [nodes[2]];
123
-
124
- return;
125
- }
126
-
127
- // scale3d(1, 1, sz) => scaleZ(sz)
128
- if (first === 1 && second === 1) {
129
- node.value = 'scaleZ';
130
- node.nodes = [nodes[4]];
131
-
132
- return;
133
- }
120
+ if (values.length !== 3) {
121
+ return;
122
+ }
123
+
124
+ const {
125
+ nodes
126
+ } = node;
127
+ const [first, second, third] = values; // scale3d(sx, 1, 1) => scaleX(sx)
128
+
129
+ if (second === 1 && third === 1) {
130
+ node.value = 'scaleX';
131
+ node.nodes = [nodes[0]];
132
+ return;
133
+ } // scale3d(1, sy, 1) => scaleY(sy)
134
+
135
+
136
+ if (first === 1 && third === 1) {
137
+ node.value = 'scaleY';
138
+ node.nodes = [nodes[2]];
139
+ return;
140
+ } // scale3d(1, 1, sz) => scaleZ(sz)
141
+
142
+
143
+ if (first === 1 && second === 1) {
144
+ node.value = 'scaleZ';
145
+ node.nodes = [nodes[4]];
146
+ return;
147
+ }
134
148
  }
135
149
 
136
150
  function translate(node, values) {
137
- const { nodes } = node;
151
+ if (values.length !== 2) {
152
+ return;
153
+ }
138
154
 
139
- if (!nodes[2]) {
140
- return;
141
- }
142
-
143
- // translate(tx, 0) => translate(tx)
144
- if (values[1] === 0) {
145
- node.nodes = [nodes[0]];
155
+ const {
156
+ nodes
157
+ } = node; // translate(tx, 0) => translate(tx)
146
158
 
147
- return;
148
- }
159
+ if (values[1] === 0) {
160
+ node.nodes = [nodes[0]];
161
+ return;
162
+ } // translate(0, ty) => translateY(ty)
149
163
 
150
- // translate(0, ty) => translateY(ty)
151
- if (values[0] === 0) {
152
- node.value = 'translateY';
153
- node.nodes = [nodes[2]];
154
164
 
155
- return;
156
- }
165
+ if (values[0] === 0) {
166
+ node.value = 'translateY';
167
+ node.nodes = [nodes[2]];
168
+ return;
169
+ }
157
170
  }
158
171
 
159
172
  function translate3d(node, values) {
160
- const { nodes } = node;
161
-
162
- // translate3d(0, 0, tz) => translateZ(tz)
163
- if (values[0] === 0 && values[1] === 0) {
164
- node.value = 'translateZ';
165
- node.nodes = [nodes[4]];
166
- }
173
+ if (values.length !== 3) {
174
+ return;
175
+ }
176
+
177
+ const {
178
+ nodes
179
+ } = node; // translate3d(0, 0, tz) => translateZ(tz)
180
+
181
+ if (values[0] === 0 && values[1] === 0) {
182
+ node.value = 'translateZ';
183
+ node.nodes = [nodes[4]];
184
+ }
167
185
  }
168
186
 
169
187
  const reducers = {
170
- matrix3d,
171
- rotate3d,
172
- rotateZ,
173
- scale,
174
- scale3d,
175
- translate,
176
- translate3d
188
+ matrix3d,
189
+ rotate3d,
190
+ rotateZ,
191
+ scale,
192
+ scale3d,
193
+ translate,
194
+ translate3d
177
195
  };
178
196
 
179
197
  function normalizeReducerName(name) {
180
- const lowerCasedName = name.toLowerCase();
198
+ const lowerCasedName = name.toLowerCase();
181
199
 
182
- if (lowerCasedName === 'rotatez') {
183
- return 'rotateZ';
184
- }
200
+ if (lowerCasedName === 'rotatez') {
201
+ return 'rotateZ';
202
+ }
185
203
 
186
- return lowerCasedName;
204
+ return lowerCasedName;
187
205
  }
188
206
 
189
207
  function reduce(node) {
190
- const { nodes, type, value } = node;
191
- const normalizedReducerName = normalizeReducerName(value);
192
-
193
- if (type === 'function' && (0, _has2.default)(reducers, normalizedReducerName)) {
194
- reducers[normalizedReducerName](node, nodes.reduce(getValues, []));
195
- }
196
-
197
- return false;
208
+ const {
209
+ nodes,
210
+ type,
211
+ value
212
+ } = node;
213
+ const normalizedReducerName = normalizeReducerName(value);
214
+
215
+ if (type === 'function' && Object.prototype.hasOwnProperty.call(reducers, normalizedReducerName)) {
216
+ reducers[normalizedReducerName](node, nodes.reduce(getValues, []));
217
+ }
218
+
219
+ return false;
198
220
  }
199
221
 
200
- exports.default = _postcss2.default.plugin('postcss-reduce-transforms', () => {
201
- return css => {
202
- const cache = {};
222
+ function pluginCreator() {
223
+ return {
224
+ postcssPlugin: 'postcss-reduce-transforms',
203
225
 
204
- css.walkDecls(/transform$/i, decl => {
226
+ prepare() {
227
+ const cache = {};
228
+ return {
229
+ OnceExit(css) {
230
+ css.walkDecls(/transform$/i, decl => {
205
231
  const value = decl.value;
206
232
 
207
- if (cache[value]) {
208
- decl.value = cache[value];
209
-
210
- return;
233
+ if (!value) {
234
+ return;
211
235
  }
212
236
 
213
- const result = (0, _postcssValueParser2.default)(value).walk(reduce).toString();
237
+ if (cache[value]) {
238
+ decl.value = cache[value];
239
+ return;
240
+ }
214
241
 
242
+ const result = (0, _postcssValueParser.default)(value).walk(reduce).toString();
215
243
  decl.value = result;
216
244
  cache[value] = result;
217
- });
218
- };
219
- });
220
- module.exports = exports['default'];
245
+ });
246
+ }
247
+
248
+ };
249
+ }
250
+
251
+ };
252
+ }
253
+
254
+ pluginCreator.postcss = true;
255
+ var _default = pluginCreator;
256
+ exports.default = _default;
257
+ module.exports = exports.default;
package/package.json CHANGED
@@ -1,20 +1,18 @@
1
1
  {
2
2
  "name": "postcss-reduce-transforms",
3
- "version": "4.0.2",
3
+ "version": "5.0.0",
4
4
  "description": "Reduce transform functions with PostCSS.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
- "prepublish": "cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/"
7
+ "prebuild": "del-cli dist",
8
+ "build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
9
+ "prepublish": "yarn build"
8
10
  },
9
11
  "files": [
10
12
  "LICENSE-MIT",
11
13
  "dist"
12
14
  ],
13
15
  "license": "MIT",
14
- "devDependencies": {
15
- "babel-cli": "^6.0.0",
16
- "cross-env": "^5.0.0"
17
- },
18
16
  "homepage": "https://github.com/cssnano/cssnano",
19
17
  "author": {
20
18
  "name": "Ben Briggs",
@@ -23,15 +21,20 @@
23
21
  },
24
22
  "repository": "cssnano/cssnano",
25
23
  "dependencies": {
26
- "cssnano-util-get-match": "^4.0.0",
27
- "has": "^1.0.0",
28
- "postcss": "^7.0.0",
29
- "postcss-value-parser": "^3.0.0"
24
+ "cssnano-utils": "^2.0.0",
25
+ "postcss-value-parser": "^4.1.0"
30
26
  },
31
27
  "bugs": {
32
28
  "url": "https://github.com/cssnano/cssnano/issues"
33
29
  },
34
30
  "engines": {
35
- "node": ">=6.9.0"
36
- }
31
+ "node": "^10 || ^12 || >=14.0"
32
+ },
33
+ "devDependencies": {
34
+ "postcss": "^8.2.1"
35
+ },
36
+ "peerDependencies": {
37
+ "postcss": "^8.2.1"
38
+ },
39
+ "gitHead": "0e2c3bf5835bafcdc8783bef66f730a24194c8f3"
37
40
  }