postcss-minify-params 5.0.1 → 5.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-minify-params",
3
- "version": "5.0.1",
3
+ "version": "5.0.5",
4
4
  "description": "Minify at-rule params with PostCSS",
5
5
  "keywords": [
6
6
  "postcss",
@@ -10,9 +10,10 @@
10
10
  "optimise",
11
11
  "params"
12
12
  ],
13
- "main": "dist/index.js",
13
+ "main": "src/index.js",
14
14
  "files": [
15
- "dist"
15
+ "src",
16
+ "LICENSE"
16
17
  ],
17
18
  "author": "Bogdan Chadkin <trysound@yandex.ru>",
18
19
  "license": "MIT",
@@ -22,16 +23,9 @@
22
23
  },
23
24
  "homepage": "https://github.com/cssnano/cssnano",
24
25
  "dependencies": {
25
- "alphanum-sort": "^1.0.2",
26
- "browserslist": "^4.16.0",
27
- "cssnano-utils": "^2.0.1",
28
- "postcss-value-parser": "^4.1.0",
29
- "uniqs": "^2.0.0"
30
- },
31
- "scripts": {
32
- "prebuild": "del-cli dist",
33
- "build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\"",
34
- "prepublish": "yarn build"
26
+ "browserslist": "^4.16.6",
27
+ "cssnano-utils": "^3.0.2",
28
+ "postcss-value-parser": "^4.2.0"
35
29
  },
36
30
  "engines": {
37
31
  "node": "^10 || ^12 || >=14.0"
@@ -42,5 +36,5 @@
42
36
  "peerDependencies": {
43
37
  "postcss": "^8.2.15"
44
38
  },
45
- "gitHead": "28c247175032fa03f04911cde56ad82d74d211cc"
46
- }
39
+ "readme": "# postcss-minify-params [![Build Status][ci-img]][ci]\n\n> Minify at-rule params with PostCSS.\n\n```css\n@media only screen and ( min-width: 400px, min-height: 500px ) {\n h2{\n color:blue\n }\n}\n```\n\n```css\n@media only screen and (min-width:400px,min-height:500px) {\n h2{\n color:blue\n }\n}\n```\n\n## Usage\n\n```js\npostcss([ require('postcss-minify-params') ])\n```\n\nSee [PostCSS] docs for examples for your environment.\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n## License\n\nMIT © [Bogdan Chadkin](mailto:trysound@yandex.ru)\n\n[PostCSS]: https://github.com/postcss/postcss\n[ci-img]: https://travis-ci.org/cssnano/postcss-minify-params.svg\n[ci]: https://travis-ci.org/cssnano/postcss-minify-params\n"
40
+ }
package/src/index.js ADDED
@@ -0,0 +1,119 @@
1
+ 'use strict';
2
+ const browserslist = require('browserslist');
3
+ const valueParser = require('postcss-value-parser');
4
+ const { getArguments } = require('cssnano-utils');
5
+
6
+ /**
7
+ * Return the greatest common divisor
8
+ * of two numbers.
9
+ */
10
+
11
+ function gcd(a, b) {
12
+ return b ? gcd(b, a % b) : a;
13
+ }
14
+
15
+ function aspectRatio(a, b) {
16
+ const divisor = gcd(a, b);
17
+
18
+ return [a / divisor, b / divisor];
19
+ }
20
+
21
+ function split(args) {
22
+ return args.map((arg) => valueParser.stringify(arg)).join('');
23
+ }
24
+
25
+ function removeNode(node) {
26
+ node.value = '';
27
+ node.type = 'word';
28
+ }
29
+
30
+ function sortAndDedupe(items) {
31
+ const a = [...new Set(items)];
32
+ a.sort();
33
+ return a.join();
34
+ }
35
+
36
+ function transform(legacy, rule) {
37
+ const ruleName = rule.name.toLowerCase();
38
+
39
+ // We should re-arrange parameters only for `@media` and `@supports` at-rules
40
+ if (!rule.params || !['media', 'supports'].includes(ruleName)) {
41
+ return;
42
+ }
43
+
44
+ const params = valueParser(rule.params);
45
+
46
+ params.walk((node, index) => {
47
+ if (node.type === 'div' || node.type === 'function') {
48
+ node.before = node.after = '';
49
+
50
+ if (
51
+ node.type === 'function' &&
52
+ node.nodes[4] &&
53
+ node.nodes[0].value.toLowerCase().indexOf('-aspect-ratio') === 3
54
+ ) {
55
+ const [a, b] = aspectRatio(
56
+ Number(node.nodes[2].value),
57
+ Number(node.nodes[4].value)
58
+ );
59
+
60
+ node.nodes[2].value = a.toString();
61
+ node.nodes[4].value = b.toString();
62
+ }
63
+ } else if (node.type === 'space') {
64
+ node.value = ' ';
65
+ } else {
66
+ const prevWord = params.nodes[index - 2];
67
+
68
+ if (
69
+ node.value.toLowerCase() === 'all' &&
70
+ rule.name.toLowerCase() === 'media' &&
71
+ !prevWord
72
+ ) {
73
+ const nextWord = params.nodes[index + 2];
74
+
75
+ if (!legacy || nextWord) {
76
+ removeNode(node);
77
+ }
78
+
79
+ if (nextWord && nextWord.value.toLowerCase() === 'and') {
80
+ const nextSpace = params.nodes[index + 1];
81
+ const secondSpace = params.nodes[index + 3];
82
+
83
+ removeNode(nextWord);
84
+ removeNode(nextSpace);
85
+ removeNode(secondSpace);
86
+ }
87
+ }
88
+ }
89
+ }, true);
90
+
91
+ rule.params = sortAndDedupe(getArguments(params).map(split));
92
+
93
+ if (!rule.params.length) {
94
+ rule.raws.afterName = '';
95
+ }
96
+ }
97
+
98
+ function hasAllBug(browser) {
99
+ return ['ie 10', 'ie 11'].includes(browser);
100
+ }
101
+
102
+ function pluginCreator(options = {}) {
103
+ const browsers = browserslist(null, {
104
+ stats: options.stats,
105
+ path: __dirname,
106
+ env: options.env,
107
+ });
108
+
109
+ return {
110
+ postcssPlugin: 'postcss-minify-params',
111
+
112
+ OnceExit(css) {
113
+ css.walkAtRules(transform.bind(null, browsers.some(hasAllBug)));
114
+ },
115
+ };
116
+ }
117
+
118
+ pluginCreator.postcss = true;
119
+ module.exports = pluginCreator;
package/CHANGELOG.md DELETED
@@ -1,78 +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.1](https://github.com/cssnano/cssnano/compare/postcss-minify-params@5.0.0...postcss-minify-params@5.0.1) (2021-05-19)
7
-
8
- **Note:** Version bump only for package postcss-minify-params
9
-
10
-
11
-
12
-
13
-
14
- # [5.0.0](https://github.com/cssnano/cssnano/compare/postcss-minify-params@5.0.0-rc.2...postcss-minify-params@5.0.0) (2021-04-06)
15
-
16
- **Note:** Version bump only for package postcss-minify-params
17
-
18
-
19
-
20
-
21
-
22
- # [5.0.0-rc.2](https://github.com/cssnano/cssnano/compare/postcss-minify-params@5.0.0-rc.1...postcss-minify-params@5.0.0-rc.2) (2021-03-15)
23
-
24
- **Note:** Version bump only for package postcss-minify-params
25
-
26
-
27
-
28
-
29
-
30
- # [5.0.0-rc.1](https://github.com/cssnano/cssnano/compare/postcss-minify-params@5.0.0-rc.0...postcss-minify-params@5.0.0-rc.1) (2021-03-04)
31
-
32
- **Note:** Version bump only for package postcss-minify-params
33
-
34
-
35
-
36
-
37
-
38
- # 5.0.0-rc.0 (2021-02-19)
39
-
40
-
41
- ### chore
42
-
43
- * minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
44
-
45
-
46
- ### Features
47
-
48
- * migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
49
-
50
-
51
- ### BREAKING CHANGES
52
-
53
- * minimum supported `postcss` version is `8.2.1`
54
- * minimum require version of node is 10.13
55
-
56
-
57
-
58
- ## 4.1.9 (2019-02-12)
59
-
60
-
61
- ### Bug Fixes
62
-
63
- * do not mangle `[@page](https://github.com/page) :first` rules ([#678](https://github.com/cssnano/cssnano/issues/678)) ([69aab0b](https://github.com/cssnano/cssnano/commit/69aab0b527198979e2232a57554cf888ad868231))
64
-
65
-
66
- ### Performance Improvements
67
-
68
- * **postcss-minify-params:** increase perf ([e06a24e](https://github.com/cssnano/cssnano/commit/e06a24e44aae8935290b7bc05d9da51b99367d2b))
69
-
70
-
71
-
72
- ## 4.1.1 (2018-09-24)
73
-
74
-
75
- ### Bug Fixes
76
-
77
- * add `browserslist` to dependencies for `postcss-minify-params` ([#594](https://github.com/cssnano/cssnano/issues/594)) ([9d40806](https://github.com/cssnano/cssnano/commit/9d40806151026dcd2272dc22a76009b27224d512))
78
- * **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 DELETED
@@ -1,117 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _browserslist = _interopRequireDefault(require("browserslist"));
9
-
10
- var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser"));
11
-
12
- var _alphanumSort = _interopRequireDefault(require("alphanum-sort"));
13
-
14
- var _uniqs = _interopRequireDefault(require("uniqs"));
15
-
16
- var _cssnanoUtils = require("cssnano-utils");
17
-
18
- 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); }
19
-
20
- 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; }
21
-
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
- /**
25
- * Return the greatest common divisor
26
- * of two numbers.
27
- */
28
- function gcd(a, b) {
29
- return b ? gcd(b, a % b) : a;
30
- }
31
-
32
- function aspectRatio(a, b) {
33
- const divisor = gcd(a, b);
34
- return [a / divisor, b / divisor];
35
- }
36
-
37
- function split(args) {
38
- return args.map(arg => (0, _postcssValueParser.stringify)(arg)).join('');
39
- }
40
-
41
- function removeNode(node) {
42
- node.value = '';
43
- node.type = 'word';
44
- }
45
-
46
- function transform(legacy, rule) {
47
- const ruleName = rule.name.toLowerCase(); // We should re-arrange parameters only for `@media` and `@supports` at-rules
48
-
49
- if (!rule.params || !['media', 'supports'].includes(ruleName)) {
50
- return;
51
- }
52
-
53
- const params = (0, _postcssValueParser.default)(rule.params);
54
- params.walk((node, index) => {
55
- if (node.type === 'div' || node.type === 'function') {
56
- node.before = node.after = '';
57
-
58
- if (node.type === 'function' && node.nodes[4] && node.nodes[0].value.toLowerCase().indexOf('-aspect-ratio') === 3) {
59
- const [a, b] = aspectRatio(node.nodes[2].value, node.nodes[4].value);
60
- node.nodes[2].value = a;
61
- node.nodes[4].value = b;
62
- }
63
- } else if (node.type === 'space') {
64
- node.value = ' ';
65
- } else {
66
- const prevWord = params.nodes[index - 2];
67
-
68
- if (node.value.toLowerCase() === 'all' && rule.name.toLowerCase() === 'media' && !prevWord) {
69
- const nextWord = params.nodes[index + 2];
70
-
71
- if (!legacy || nextWord) {
72
- removeNode(node);
73
- }
74
-
75
- if (nextWord && nextWord.value.toLowerCase() === 'and') {
76
- const nextSpace = params.nodes[index + 1];
77
- const secondSpace = params.nodes[index + 3];
78
- removeNode(nextWord);
79
- removeNode(nextSpace);
80
- removeNode(secondSpace);
81
- }
82
- }
83
- }
84
- }, true);
85
- rule.params = (0, _alphanumSort.default)((0, _uniqs.default)((0, _cssnanoUtils.getArguments)(params).map(split)), {
86
- insensitive: true
87
- }).join();
88
-
89
- if (!rule.params.length) {
90
- rule.raws.afterName = '';
91
- }
92
- }
93
-
94
- function hasAllBug(browser) {
95
- return ~['ie 10', 'ie 11'].indexOf(browser);
96
- }
97
-
98
- function pluginCreator(options = {}) {
99
- const browsers = (0, _browserslist.default)(null, {
100
- stats: options.stats,
101
- path: __dirname,
102
- env: options.env
103
- });
104
- return {
105
- postcssPlugin: 'postcss-minify-params',
106
-
107
- OnceExit(css) {
108
- css.walkAtRules(transform.bind(null, browsers.some(hasAllBug)));
109
- }
110
-
111
- };
112
- }
113
-
114
- pluginCreator.postcss = true;
115
- var _default = pluginCreator;
116
- exports.default = _default;
117
- module.exports = exports.default;