postcss-minify-params 4.0.0-rc.0 → 4.0.1
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/CHANGELOG.md +4 -0
- package/README.md +3 -3
- package/dist/index.js +38 -25
- package/package.json +9 -8
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -28,12 +28,12 @@ See [PostCSS] docs for examples for your environment.
|
|
|
28
28
|
|
|
29
29
|
## Contributors
|
|
30
30
|
|
|
31
|
-
See [CONTRIBUTORS.md](https://github.com/
|
|
31
|
+
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
|
|
32
32
|
|
|
33
33
|
## License
|
|
34
34
|
|
|
35
35
|
MIT © [Bogdan Chadkin](mailto:trysound@yandex.ru)
|
|
36
36
|
|
|
37
37
|
[PostCSS]: https://github.com/postcss/postcss
|
|
38
|
-
[ci-img]: https://travis-ci.org/
|
|
39
|
-
[ci]: https://travis-ci.org/
|
|
38
|
+
[ci-img]: https://travis-ci.org/cssnano/postcss-minify-params.svg
|
|
39
|
+
[ci]: https://travis-ci.org/cssnano/postcss-minify-params
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _browserslist = require('browserslist');
|
|
8
|
+
|
|
9
|
+
var _browserslist2 = _interopRequireDefault(_browserslist);
|
|
8
10
|
|
|
9
11
|
var _postcss = require('postcss');
|
|
10
12
|
|
|
@@ -38,15 +40,13 @@ function gcd(a, b) {
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
function aspectRatio(a, b) {
|
|
41
|
-
|
|
43
|
+
const divisor = gcd(a, b);
|
|
42
44
|
|
|
43
45
|
return [a / divisor, b / divisor];
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
function split(args) {
|
|
47
|
-
return args.map(
|
|
48
|
-
return (0, _postcssValueParser.stringify)(arg);
|
|
49
|
-
}).join('');
|
|
49
|
+
return args.map(arg => (0, _postcssValueParser.stringify)(arg)).join('');
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
function removeNode(node) {
|
|
@@ -54,39 +54,41 @@ function removeNode(node) {
|
|
|
54
54
|
node.type = 'word';
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function transform(rule) {
|
|
58
|
-
|
|
57
|
+
function transform(legacy, rule) {
|
|
58
|
+
// We should not re-arrange parameters for css-modules' @value
|
|
59
|
+
// at-rule. For example:
|
|
60
|
+
//
|
|
61
|
+
// @value vertical, center from "./foo.css";
|
|
62
|
+
if (!rule.params || rule.name.toLowerCase() === 'value') {
|
|
59
63
|
return;
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
|
|
66
|
+
const params = (0, _postcssValueParser2.default)(rule.params);
|
|
63
67
|
|
|
64
|
-
params.walk(
|
|
68
|
+
params.walk((node, index) => {
|
|
65
69
|
if (node.type === 'div' || node.type === 'function') {
|
|
66
70
|
node.before = node.after = '';
|
|
67
|
-
if (node.type === 'function' && node.nodes[4] && node.nodes[0].value.indexOf('-aspect-ratio') === 3) {
|
|
68
|
-
|
|
69
|
-
_aspectRatio2 = _slicedToArray(_aspectRatio, 2),
|
|
70
|
-
a = _aspectRatio2[0],
|
|
71
|
-
b = _aspectRatio2[1];
|
|
72
|
-
|
|
71
|
+
if (node.type === 'function' && node.nodes[4] && node.nodes[0].value.toLowerCase().indexOf('-aspect-ratio') === 3) {
|
|
72
|
+
const [a, b] = aspectRatio(node.nodes[2].value, node.nodes[4].value);
|
|
73
73
|
node.nodes[2].value = a;
|
|
74
74
|
node.nodes[4].value = b;
|
|
75
75
|
}
|
|
76
76
|
} else if (node.type === 'space') {
|
|
77
77
|
node.value = ' ';
|
|
78
78
|
} else {
|
|
79
|
-
|
|
80
|
-
if (node.value === 'all' && rule.name === 'media' && !prevWord) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
const prevWord = params.nodes[index - 2];
|
|
80
|
+
if (node.value.toLowerCase() === 'all' && rule.name.toLowerCase() === 'media' && !prevWord) {
|
|
81
|
+
const nextWord = params.nodes[index + 2];
|
|
82
|
+
if (!legacy || nextWord) {
|
|
83
|
+
removeNode(node);
|
|
84
|
+
}
|
|
85
|
+
if (nextWord && nextWord.value.toLowerCase() === 'and') {
|
|
86
|
+
const nextSpace = params.nodes[index + 1];
|
|
87
|
+
const secondSpace = params.nodes[index + 3];
|
|
85
88
|
removeNode(nextWord);
|
|
86
89
|
removeNode(nextSpace);
|
|
87
90
|
removeNode(secondSpace);
|
|
88
91
|
}
|
|
89
|
-
removeNode(node);
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
94
|
}, true);
|
|
@@ -100,9 +102,20 @@ function transform(rule) {
|
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
|
|
103
|
-
|
|
104
|
-
return
|
|
105
|
-
|
|
105
|
+
function hasAllBug(browser) {
|
|
106
|
+
return ~['ie 10', 'ie 11'].indexOf(browser);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
exports.default = _postcss2.default.plugin('postcss-minify-params', () => {
|
|
110
|
+
return (css, result) => {
|
|
111
|
+
const resultOpts = result.opts || {};
|
|
112
|
+
const browsers = (0, _browserslist2.default)(null, {
|
|
113
|
+
stats: resultOpts.stats,
|
|
114
|
+
path: __dirname,
|
|
115
|
+
env: resultOpts.env
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return css.walkAtRules(transform.bind(null, browsers.some(hasAllBug)));
|
|
106
119
|
};
|
|
107
120
|
});
|
|
108
121
|
module.exports = exports['default'];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-minify-params",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Minify at-rule params with PostCSS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"postcss",
|
|
@@ -16,15 +16,16 @@
|
|
|
16
16
|
],
|
|
17
17
|
"author": "Bogdan Chadkin <trysound@yandex.ru>",
|
|
18
18
|
"license": "MIT",
|
|
19
|
-
"repository": "
|
|
19
|
+
"repository": "cssnano/cssnano",
|
|
20
20
|
"bugs": {
|
|
21
|
-
"url": "https://github.com/
|
|
21
|
+
"url": "https://github.com/cssnano/cssnano/issues"
|
|
22
22
|
},
|
|
23
|
-
"homepage": "https://github.com/
|
|
23
|
+
"homepage": "https://github.com/cssnano/cssnano",
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"alphanum-sort": "^1.0.0",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"browserslist": "^4.0.0",
|
|
27
|
+
"cssnano-util-get-arguments": "^4.0.0",
|
|
28
|
+
"postcss": "^7.0.0",
|
|
28
29
|
"postcss-value-parser": "^3.0.0",
|
|
29
30
|
"uniqs": "^2.0.0"
|
|
30
31
|
},
|
|
@@ -33,9 +34,9 @@
|
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"babel-cli": "^6.0.0",
|
|
36
|
-
"cross-env": "^
|
|
37
|
+
"cross-env": "^5.0.0"
|
|
37
38
|
},
|
|
38
39
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
40
|
+
"node": ">=6.9.0"
|
|
40
41
|
}
|
|
41
42
|
}
|