postcss-minify-gradients 5.0.6 → 5.1.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.
- package/package.json +5 -3
- package/src/index.js +24 -5
- package/src/isColorStop.js +14 -3
- package/types/index.d.ts +9 -0
- package/types/isColorStop.d.ts +2 -0
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-minify-gradients",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Minify gradient parameters with PostCSS.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
6
7
|
"files": [
|
|
7
8
|
"LICENSE-MIT",
|
|
8
|
-
"src"
|
|
9
|
+
"src",
|
|
10
|
+
"types"
|
|
9
11
|
],
|
|
10
12
|
"keywords": [
|
|
11
13
|
"css",
|
|
@@ -22,7 +24,7 @@
|
|
|
22
24
|
"repository": "cssnano/cssnano",
|
|
23
25
|
"dependencies": {
|
|
24
26
|
"colord": "^2.9.1",
|
|
25
|
-
"cssnano-utils": "^3.0
|
|
27
|
+
"cssnano-utils": "^3.1.0",
|
|
26
28
|
"postcss-value-parser": "^4.2.0"
|
|
27
29
|
},
|
|
28
30
|
"bugs": {
|
package/src/index.js
CHANGED
|
@@ -10,13 +10,21 @@ const angles = {
|
|
|
10
10
|
left: '270deg',
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @param {valueParser.Dimension} a
|
|
15
|
+
* @param {valueParser.Dimension} b
|
|
16
|
+
* @return {boolean}
|
|
17
|
+
*/
|
|
13
18
|
function isLessThan(a, b) {
|
|
14
19
|
return (
|
|
15
20
|
a.unit.toLowerCase() === b.unit.toLowerCase() &&
|
|
16
21
|
parseFloat(a.number) >= parseFloat(b.number)
|
|
17
22
|
);
|
|
18
23
|
}
|
|
19
|
-
|
|
24
|
+
/**
|
|
25
|
+
* @param {import('postcss').Declaration} decl
|
|
26
|
+
* @return {void}
|
|
27
|
+
*/
|
|
20
28
|
function optimise(decl) {
|
|
21
29
|
const value = decl.value;
|
|
22
30
|
|
|
@@ -55,10 +63,16 @@ function optimise(decl) {
|
|
|
55
63
|
args[0].length === 3
|
|
56
64
|
) {
|
|
57
65
|
node.nodes = node.nodes.slice(2);
|
|
58
|
-
node.nodes[0].value =
|
|
66
|
+
node.nodes[0].value =
|
|
67
|
+
angles[
|
|
68
|
+
/** @type {'top'|'right'|'bottom'|'left'}*/ (
|
|
69
|
+
node.nodes[0].value.toLowerCase()
|
|
70
|
+
)
|
|
71
|
+
];
|
|
59
72
|
}
|
|
60
73
|
|
|
61
|
-
|
|
74
|
+
/** @type {valueParser.Dimension | false} */
|
|
75
|
+
let lastStop;
|
|
62
76
|
|
|
63
77
|
args.forEach((arg, index) => {
|
|
64
78
|
if (arg.length !== 3) {
|
|
@@ -68,7 +82,7 @@ function optimise(decl) {
|
|
|
68
82
|
let isFinalStop = index === args.length - 1;
|
|
69
83
|
let thisStop = valueParser.unit(arg[2].value);
|
|
70
84
|
|
|
71
|
-
if (lastStop ===
|
|
85
|
+
if (lastStop === undefined) {
|
|
72
86
|
lastStop = thisStop;
|
|
73
87
|
|
|
74
88
|
if (
|
|
@@ -102,6 +116,7 @@ function optimise(decl) {
|
|
|
102
116
|
lowerCasedValue === 'repeating-radial-gradient'
|
|
103
117
|
) {
|
|
104
118
|
let args = getArguments(node);
|
|
119
|
+
/** @type {valueParser.Dimension | false} */
|
|
105
120
|
let lastStop;
|
|
106
121
|
|
|
107
122
|
const hasAt = args[0].find((n) => n.value.toLowerCase() === 'at');
|
|
@@ -134,6 +149,7 @@ function optimise(decl) {
|
|
|
134
149
|
lowerCasedValue === '-webkit-repeating-radial-gradient'
|
|
135
150
|
) {
|
|
136
151
|
let args = getArguments(node);
|
|
152
|
+
/** @type {valueParser.Dimension | false} */
|
|
137
153
|
let lastStop;
|
|
138
154
|
|
|
139
155
|
args.forEach((arg) => {
|
|
@@ -191,7 +207,10 @@ function optimise(decl) {
|
|
|
191
207
|
})
|
|
192
208
|
.toString();
|
|
193
209
|
}
|
|
194
|
-
|
|
210
|
+
/**
|
|
211
|
+
* @type {import('postcss').PluginCreator<void>}
|
|
212
|
+
* @return {import('postcss').Plugin}
|
|
213
|
+
*/
|
|
195
214
|
function pluginCreator() {
|
|
196
215
|
return {
|
|
197
216
|
postcssPlugin: 'postcss-minify-gradients',
|
package/src/isColorStop.js
CHANGED
|
@@ -3,7 +3,7 @@ const { unit } = require('postcss-value-parser');
|
|
|
3
3
|
const { colord, extend } = require('colord');
|
|
4
4
|
const namesPlugin = require('colord/plugins/names');
|
|
5
5
|
|
|
6
|
-
extend([namesPlugin]);
|
|
6
|
+
extend([/** @type {any} */ (namesPlugin)]);
|
|
7
7
|
|
|
8
8
|
/* Code derived from https://github.com/pigcan/is-color-stop */
|
|
9
9
|
|
|
@@ -25,10 +25,17 @@ const lengthUnits = new Set([
|
|
|
25
25
|
'%',
|
|
26
26
|
]);
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} input
|
|
30
|
+
* @return {boolean}
|
|
31
|
+
*/
|
|
28
32
|
function isCSSLengthUnit(input) {
|
|
29
33
|
return lengthUnits.has(input.toUpperCase());
|
|
30
34
|
}
|
|
31
|
-
|
|
35
|
+
/**
|
|
36
|
+
* @param {string|undefined} str
|
|
37
|
+
* @return {boolean}
|
|
38
|
+
*/
|
|
32
39
|
function isStop(str) {
|
|
33
40
|
if (str) {
|
|
34
41
|
let stop = false;
|
|
@@ -45,7 +52,11 @@ function isStop(str) {
|
|
|
45
52
|
}
|
|
46
53
|
return true;
|
|
47
54
|
}
|
|
48
|
-
|
|
55
|
+
/**
|
|
56
|
+
* @param {string} color
|
|
57
|
+
* @param {string} [stop]
|
|
58
|
+
* @return {boolean}
|
|
59
|
+
*/
|
|
49
60
|
module.exports = function isColorStop(color, stop) {
|
|
50
61
|
return colord(color).isValid() && isStop(stop);
|
|
51
62
|
};
|
package/types/index.d.ts
ADDED