postcss-reduce-transforms 5.0.0-rc.2 → 5.0.3

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/dist/index.js +19 -32
  2. package/package.json +10 -12
  3. package/CHANGELOG.md +0 -62
package/dist/index.js CHANGED
@@ -7,11 +7,9 @@ exports.default = void 0;
7
7
 
8
8
  var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser"));
9
9
 
10
- var _cssnanoUtils = require("cssnano-utils");
10
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
11
 
12
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
13
-
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; }
12
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
15
13
 
16
14
  function getValues(list, node, index) {
17
15
  if (index % 2 === 0) {
@@ -55,11 +53,10 @@ function matrix3d(node, values) {
55
53
  }
56
54
  }
57
55
 
58
- const rotate3dMappings = [['rotateX', [1, 0, 0]], // rotate3d(1, 0, 0, a) => rotateX(a)
59
- ['rotateY', [0, 1, 0]], // rotate3d(0, 1, 0, a) => rotateY(a)
60
- ['rotate', [0, 0, 1]] // rotate3d(0, 0, 1, a) => rotate(a)
61
- ];
62
- const rotate3dMatch = (0, _cssnanoUtils.getMatch)(rotate3dMappings);
56
+ const rotate3dMappings = new Map([[[1, 0, 0].toString(), 'rotateX'], // rotate3d(1, 0, 0, a) => rotateX(a)
57
+ [[0, 1, 0].toString(), 'rotateY'], // rotate3d(0, 1, 0, a) => rotateY(a)
58
+ [[0, 0, 1].toString(), 'rotate'] // rotate3d(0, 0, 1, a) => rotate(a)
59
+ ]);
63
60
 
64
61
  function rotate3d(node, values) {
65
62
  if (values.length !== 4) {
@@ -69,9 +66,9 @@ function rotate3d(node, values) {
69
66
  const {
70
67
  nodes
71
68
  } = node;
72
- const match = rotate3dMatch(values.slice(0, 3));
69
+ const match = rotate3dMappings.get(values.slice(0, 3).toString());
73
70
 
74
- if (match.length) {
71
+ if (match) {
75
72
  node.value = match;
76
73
  node.nodes = [nodes[6]];
77
74
  }
@@ -184,15 +181,7 @@ function translate3d(node, values) {
184
181
  }
185
182
  }
186
183
 
187
- const reducers = {
188
- matrix3d,
189
- rotate3d,
190
- rotateZ,
191
- scale,
192
- scale3d,
193
- translate,
194
- translate3d
195
- };
184
+ const reducers = new Map([['matrix3d', matrix3d], ['rotate3d', rotate3d], ['rotateZ', rotateZ], ['scale', scale], ['scale3d', scale3d], ['translate', translate], ['translate3d', translate3d]]);
196
185
 
197
186
  function normalizeReducerName(name) {
198
187
  const lowerCasedName = name.toLowerCase();
@@ -205,15 +194,13 @@ function normalizeReducerName(name) {
205
194
  }
206
195
 
207
196
  function reduce(node) {
208
- const {
209
- nodes,
210
- type,
211
- value
212
- } = node;
213
- const normalizedReducerName = normalizeReducerName(value);
197
+ if (node.type === 'function') {
198
+ const normalizedReducerName = normalizeReducerName(node.value);
199
+ const reducer = reducers.get(normalizedReducerName);
214
200
 
215
- if (type === 'function' && Object.prototype.hasOwnProperty.call(reducers, normalizedReducerName)) {
216
- reducers[normalizedReducerName](node, nodes.reduce(getValues, []));
201
+ if (reducer !== undefined) {
202
+ reducer(node, node.nodes.reduce(getValues, []));
203
+ }
217
204
  }
218
205
 
219
206
  return false;
@@ -224,7 +211,7 @@ function pluginCreator() {
224
211
  postcssPlugin: 'postcss-reduce-transforms',
225
212
 
226
213
  prepare() {
227
- const cache = {};
214
+ const cache = new Map();
228
215
  return {
229
216
  OnceExit(css) {
230
217
  css.walkDecls(/transform$/i, decl => {
@@ -234,14 +221,14 @@ function pluginCreator() {
234
221
  return;
235
222
  }
236
223
 
237
- if (cache[value]) {
238
- decl.value = cache[value];
224
+ if (cache.has(value)) {
225
+ decl.value = cache.get(value);
239
226
  return;
240
227
  }
241
228
 
242
229
  const result = (0, _postcssValueParser.default)(value).walk(reduce).toString();
243
230
  decl.value = result;
244
- cache[value] = result;
231
+ cache.set(value, result);
245
232
  });
246
233
  }
247
234
 
package/package.json CHANGED
@@ -1,13 +1,8 @@
1
1
  {
2
2
  "name": "postcss-reduce-transforms",
3
- "version": "5.0.0-rc.2",
3
+ "version": "5.0.3",
4
4
  "description": "Reduce transform functions with PostCSS.",
5
5
  "main": "dist/index.js",
6
- "scripts": {
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"
10
- },
11
6
  "files": [
12
7
  "LICENSE-MIT",
13
8
  "dist"
@@ -21,8 +16,7 @@
21
16
  },
22
17
  "repository": "cssnano/cssnano",
23
18
  "dependencies": {
24
- "cssnano-utils": "^2.0.0-rc.2",
25
- "postcss-value-parser": "^4.1.0"
19
+ "postcss-value-parser": "^4.2.0"
26
20
  },
27
21
  "bugs": {
28
22
  "url": "https://github.com/cssnano/cssnano/issues"
@@ -31,10 +25,14 @@
31
25
  "node": "^10 || ^12 || >=14.0"
32
26
  },
33
27
  "devDependencies": {
34
- "postcss": "^8.2.1"
28
+ "postcss": "^8.2.15"
35
29
  },
36
30
  "peerDependencies": {
37
- "postcss": "^8.2.1"
31
+ "postcss": "^8.2.15"
32
+ },
33
+ "scripts": {
34
+ "prebuild": "rimraf dist",
35
+ "build": "babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\""
38
36
  },
39
- "gitHead": "5ba19ca54892f76ba6b2b698b4d88adcabd4451b"
40
- }
37
+ "readme": "# [postcss][postcss]-reduce-transforms\n\n> Reduce transform functions with PostCSS.\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-reduce-transforms) do:\n\n```\nnpm install postcss-reduce-transforms --save\n```\n\n## Example\n\nThis module will reduce transform functions where possible. For more examples,\nsee the [tests](src/__tests__/index.js).\n\n### Input\n\n```css\nh1 {\n transform: rotate3d(0, 0, 1, 20deg);\n}\n```\n\n### Output\n\n```css\nh1 {\n transform: rotate(20deg);\n}\n```\n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n## License\n\nMIT © [Ben Briggs](http://beneb.info)\n\n[postcss]: https://github.com/postcss/postcss\n"
38
+ }
package/CHANGELOG.md DELETED
@@ -1,62 +0,0 @@
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-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)
7
-
8
- **Note:** Version bump only for package postcss-reduce-transforms
9
-
10
-
11
-
12
-
13
-
14
- # [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)
15
-
16
- **Note:** Version bump only for package postcss-reduce-transforms
17
-
18
-
19
-
20
-
21
-
22
- # 5.0.0-rc.0 (2021-02-19)
23
-
24
-
25
- ### chore
26
-
27
- * minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
28
-
29
-
30
- ### Features
31
-
32
- * migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
33
- * **postcss-reduce-transforms:** improve optimizations ([#745](https://github.com/cssnano/cssnano/issues/745)) ([b0f0d89](https://github.com/cssnano/cssnano/commit/b0f0d892316d7b77e8033a6dc8d67745043a5072))
34
-
35
-
36
- ### BREAKING CHANGES
37
-
38
- * minimum supported `postcss` version is `8.2.1`
39
- * minimum require version of node is 10.13
40
-
41
-
42
-
43
- ## 4.1.9 (2019-02-12)
44
-
45
-
46
- ### Bug Fixes
47
-
48
- * **fix-postcss-reduce-transforms:** cache ([#691](https://github.com/cssnano/cssnano/issues/691)) ([e07309f](https://github.com/cssnano/cssnano/commit/e07309ff0c07fb36ef2340bbed6b3aee3dad18be))
49
-
50
-
51
- ### Performance Improvements
52
-
53
- * **postcss-reduce-transforms:** increase perf ([#688](https://github.com/cssnano/cssnano/issues/688)) ([84ccba0](https://github.com/cssnano/cssnano/commit/84ccba00cead30e80510525cbcd27ba259c26065))
54
-
55
-
56
-
57
- ## 4.1.1 (2018-09-24)
58
-
59
-
60
- ### Bug Fixes
61
-
62
- * **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)