postcss-minify-params 5.0.5 → 5.1.2
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 +5 -3
- package/src/index.js +48 -4
- package/types/index.d.ts +11 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-minify-params",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.2",
|
|
4
4
|
"description": "Minify at-rule params with PostCSS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"postcss",
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
"params"
|
|
12
12
|
],
|
|
13
13
|
"main": "src/index.js",
|
|
14
|
+
"types": "types/index.d.ts",
|
|
14
15
|
"files": [
|
|
15
16
|
"src",
|
|
16
|
-
"LICENSE"
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"types"
|
|
17
19
|
],
|
|
18
20
|
"author": "Bogdan Chadkin <trysound@yandex.ru>",
|
|
19
21
|
"license": "MIT",
|
|
@@ -24,7 +26,7 @@
|
|
|
24
26
|
"homepage": "https://github.com/cssnano/cssnano",
|
|
25
27
|
"dependencies": {
|
|
26
28
|
"browserslist": "^4.16.6",
|
|
27
|
-
"cssnano-utils": "^3.0
|
|
29
|
+
"cssnano-utils": "^3.1.0",
|
|
28
30
|
"postcss-value-parser": "^4.2.0"
|
|
29
31
|
},
|
|
30
32
|
"engines": {
|
package/src/index.js
CHANGED
|
@@ -6,33 +6,58 @@ const { getArguments } = require('cssnano-utils');
|
|
|
6
6
|
/**
|
|
7
7
|
* Return the greatest common divisor
|
|
8
8
|
* of two numbers.
|
|
9
|
+
*
|
|
10
|
+
* @param {number} a
|
|
11
|
+
* @param {number} b
|
|
12
|
+
* @return {number}
|
|
9
13
|
*/
|
|
10
|
-
|
|
11
14
|
function gcd(a, b) {
|
|
12
15
|
return b ? gcd(b, a % b) : a;
|
|
13
16
|
}
|
|
14
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @param {number} a
|
|
20
|
+
* @param {number} b
|
|
21
|
+
* @return {[number, number]}
|
|
22
|
+
*/
|
|
15
23
|
function aspectRatio(a, b) {
|
|
16
24
|
const divisor = gcd(a, b);
|
|
17
25
|
|
|
18
26
|
return [a / divisor, b / divisor];
|
|
19
27
|
}
|
|
20
28
|
|
|
29
|
+
/**
|
|
30
|
+
* @param {valueParser.Node[]} args
|
|
31
|
+
* @return {string}
|
|
32
|
+
*/
|
|
21
33
|
function split(args) {
|
|
22
34
|
return args.map((arg) => valueParser.stringify(arg)).join('');
|
|
23
35
|
}
|
|
24
36
|
|
|
37
|
+
/**
|
|
38
|
+
* @param {valueParser.Node} node
|
|
39
|
+
* @return {void}
|
|
40
|
+
*/
|
|
25
41
|
function removeNode(node) {
|
|
26
42
|
node.value = '';
|
|
27
43
|
node.type = 'word';
|
|
28
44
|
}
|
|
29
45
|
|
|
46
|
+
/**
|
|
47
|
+
* @param {unknown[]} items
|
|
48
|
+
* @return {string}
|
|
49
|
+
*/
|
|
30
50
|
function sortAndDedupe(items) {
|
|
31
51
|
const a = [...new Set(items)];
|
|
32
52
|
a.sort();
|
|
33
53
|
return a.join();
|
|
34
54
|
}
|
|
35
55
|
|
|
56
|
+
/**
|
|
57
|
+
* @param {boolean} legacy
|
|
58
|
+
* @param {import('postcss').AtRule} rule
|
|
59
|
+
* @return {void}
|
|
60
|
+
*/
|
|
36
61
|
function transform(legacy, rule) {
|
|
37
62
|
const ruleName = rule.name.toLowerCase();
|
|
38
63
|
|
|
@@ -44,11 +69,21 @@ function transform(legacy, rule) {
|
|
|
44
69
|
const params = valueParser(rule.params);
|
|
45
70
|
|
|
46
71
|
params.walk((node, index) => {
|
|
47
|
-
if (node.type === 'div'
|
|
72
|
+
if (node.type === 'div') {
|
|
48
73
|
node.before = node.after = '';
|
|
49
|
-
|
|
74
|
+
} else if (node.type === 'function') {
|
|
75
|
+
node.before = '';
|
|
76
|
+
if (
|
|
77
|
+
node.nodes[0] &&
|
|
78
|
+
node.nodes[0].type === 'word' &&
|
|
79
|
+
node.nodes[0].value.startsWith('--') &&
|
|
80
|
+
node.nodes[2] === undefined
|
|
81
|
+
) {
|
|
82
|
+
node.after = ' ';
|
|
83
|
+
} else {
|
|
84
|
+
node.after = '';
|
|
85
|
+
}
|
|
50
86
|
if (
|
|
51
|
-
node.type === 'function' &&
|
|
52
87
|
node.nodes[4] &&
|
|
53
88
|
node.nodes[0].value.toLowerCase().indexOf('-aspect-ratio') === 3
|
|
54
89
|
) {
|
|
@@ -95,10 +130,19 @@ function transform(legacy, rule) {
|
|
|
95
130
|
}
|
|
96
131
|
}
|
|
97
132
|
|
|
133
|
+
/**
|
|
134
|
+
* @param {string} browser
|
|
135
|
+
* @return {boolean}
|
|
136
|
+
*/
|
|
98
137
|
function hasAllBug(browser) {
|
|
99
138
|
return ['ie 10', 'ie 11'].includes(browser);
|
|
100
139
|
}
|
|
101
140
|
|
|
141
|
+
/**
|
|
142
|
+
* @type {import('postcss').PluginCreator<browserslist.Options>}
|
|
143
|
+
* @param {browserslist.Options} options
|
|
144
|
+
* @return {import('postcss').Plugin}
|
|
145
|
+
*/
|
|
102
146
|
function pluginCreator(options = {}) {
|
|
103
147
|
const browsers = browserslist(null, {
|
|
104
148
|
stats: options.stats,
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export = pluginCreator;
|
|
2
|
+
/**
|
|
3
|
+
* @type {import('postcss').PluginCreator<browserslist.Options>}
|
|
4
|
+
* @param {browserslist.Options} options
|
|
5
|
+
* @return {import('postcss').Plugin}
|
|
6
|
+
*/
|
|
7
|
+
declare function pluginCreator(options?: browserslist.Options): import('postcss').Plugin;
|
|
8
|
+
declare namespace pluginCreator {
|
|
9
|
+
const postcss: true;
|
|
10
|
+
}
|
|
11
|
+
import browserslist = require("browserslist");
|