postcss-minify-gradients 4.0.0-rc.0 → 4.0.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/README.md +1 -1
- package/dist/index.js +110 -30
- package/package.json +9 -8
- package/CHANGELOG.md +0 -34
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,9 +16,13 @@ var _cssnanoUtilGetArguments = require('cssnano-util-get-arguments');
|
|
|
16
16
|
|
|
17
17
|
var _cssnanoUtilGetArguments2 = _interopRequireDefault(_cssnanoUtilGetArguments);
|
|
18
18
|
|
|
19
|
+
var _isColorStop = require('is-color-stop');
|
|
20
|
+
|
|
21
|
+
var _isColorStop2 = _interopRequireDefault(_isColorStop);
|
|
22
|
+
|
|
19
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
const angles = {
|
|
22
26
|
top: '0deg',
|
|
23
27
|
right: '90deg',
|
|
24
28
|
bottom: '180deg',
|
|
@@ -26,75 +30,151 @@ var angles = {
|
|
|
26
30
|
};
|
|
27
31
|
|
|
28
32
|
function isLessThan(a, b) {
|
|
29
|
-
return a.unit === b.unit && parseFloat(a.number) >= parseFloat(b.number);
|
|
33
|
+
return a.unit.toLowerCase() === b.unit.toLowerCase() && parseFloat(a.number) >= parseFloat(b.number);
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
function optimise(decl) {
|
|
33
|
-
|
|
37
|
+
const value = decl.value;
|
|
38
|
+
|
|
39
|
+
if (!~value.toLowerCase().indexOf('gradient')) {
|
|
34
40
|
return;
|
|
35
41
|
}
|
|
36
|
-
|
|
42
|
+
|
|
43
|
+
decl.value = (0, _postcssValueParser2.default)(value).walk(node => {
|
|
37
44
|
if (node.type !== 'function' || !node.nodes.length) {
|
|
38
45
|
return false;
|
|
39
46
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
|
|
48
|
+
const lowerCasedValue = node.value.toLowerCase();
|
|
49
|
+
|
|
50
|
+
if (lowerCasedValue === 'linear-gradient' || lowerCasedValue === 'repeating-linear-gradient' || lowerCasedValue === '-webkit-linear-gradient' || lowerCasedValue === '-webkit-repeating-linear-gradient') {
|
|
51
|
+
let args = (0, _cssnanoUtilGetArguments2.default)(node);
|
|
52
|
+
|
|
53
|
+
if (node.nodes[0].value.toLowerCase() === 'to' && args[0].length === 3) {
|
|
43
54
|
node.nodes = node.nodes.slice(2);
|
|
44
|
-
node.nodes[0].value = angles[node.nodes[0].value];
|
|
55
|
+
node.nodes[0].value = angles[node.nodes[0].value.toLowerCase()];
|
|
45
56
|
}
|
|
46
|
-
|
|
47
|
-
|
|
57
|
+
|
|
58
|
+
let lastStop = null;
|
|
59
|
+
|
|
60
|
+
args.forEach((arg, index) => {
|
|
48
61
|
if (!arg[2]) {
|
|
49
62
|
return;
|
|
50
63
|
}
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
|
|
65
|
+
let isFinalStop = index === args.length - 1;
|
|
66
|
+
let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
|
|
67
|
+
|
|
53
68
|
if (lastStop === null) {
|
|
54
69
|
lastStop = thisStop;
|
|
55
|
-
|
|
70
|
+
|
|
71
|
+
if (!isFinalStop && lastStop && lastStop.number === '0' && lastStop.unit.toLowerCase() !== 'deg') {
|
|
56
72
|
arg[1].value = arg[2].value = '';
|
|
57
73
|
}
|
|
74
|
+
|
|
58
75
|
return;
|
|
59
76
|
}
|
|
60
|
-
|
|
77
|
+
|
|
78
|
+
if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
|
|
61
79
|
arg[2].value = 0;
|
|
62
80
|
}
|
|
81
|
+
|
|
63
82
|
lastStop = thisStop;
|
|
83
|
+
|
|
64
84
|
if (isFinalStop && arg[2].value === '100%') {
|
|
65
85
|
arg[1].value = arg[2].value = '';
|
|
66
86
|
}
|
|
67
87
|
});
|
|
88
|
+
|
|
68
89
|
return false;
|
|
69
90
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
91
|
+
|
|
92
|
+
if (lowerCasedValue === 'radial-gradient' || lowerCasedValue === 'repeating-radial-gradient') {
|
|
93
|
+
let args = (0, _cssnanoUtilGetArguments2.default)(node);
|
|
94
|
+
let lastStop;
|
|
95
|
+
|
|
96
|
+
const hasAt = args[0].find(n => n.value.toLowerCase() === 'at');
|
|
97
|
+
|
|
98
|
+
args.forEach((arg, index) => {
|
|
77
99
|
if (!arg[2] || !index && hasAt) {
|
|
78
100
|
return;
|
|
79
101
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
102
|
+
|
|
103
|
+
let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
|
|
104
|
+
|
|
105
|
+
if (!lastStop) {
|
|
106
|
+
lastStop = thisStop;
|
|
107
|
+
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
|
|
112
|
+
arg[2].value = 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
lastStop = thisStop;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (lowerCasedValue === '-webkit-radial-gradient' || lowerCasedValue === '-webkit-repeating-radial-gradient') {
|
|
122
|
+
let args = (0, _cssnanoUtilGetArguments2.default)(node);
|
|
123
|
+
let lastStop;
|
|
124
|
+
|
|
125
|
+
args.forEach(arg => {
|
|
126
|
+
let color;
|
|
127
|
+
let stop;
|
|
128
|
+
|
|
129
|
+
if (arg[2] !== undefined) {
|
|
130
|
+
if (arg[0].type === 'function') {
|
|
131
|
+
color = `${arg[0].value}(${(0, _postcssValueParser.stringify)(arg[0].nodes)})`;
|
|
132
|
+
} else {
|
|
133
|
+
color = arg[0].value;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (arg[2].type === 'function') {
|
|
137
|
+
stop = `${arg[2].value}(${(0, _postcssValueParser.stringify)(arg[2].nodes)})`;
|
|
138
|
+
} else {
|
|
139
|
+
stop = arg[2].value;
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
if (arg[0].type === 'function') {
|
|
143
|
+
color = `${arg[0].value}(${(0, _postcssValueParser.stringify)(arg[0].nodes)})`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
color = arg[0].value;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
color = color.toLowerCase();
|
|
150
|
+
|
|
151
|
+
const colorStop = stop || stop === 0 ? (0, _isColorStop2.default)(color, stop.toLowerCase()) : (0, _isColorStop2.default)(color);
|
|
152
|
+
|
|
153
|
+
if (!colorStop || !arg[2]) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
|
|
158
|
+
|
|
159
|
+
if (!lastStop) {
|
|
160
|
+
lastStop = thisStop;
|
|
161
|
+
|
|
83
162
|
return;
|
|
84
163
|
}
|
|
85
|
-
|
|
164
|
+
|
|
165
|
+
if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
|
|
86
166
|
arg[2].value = 0;
|
|
87
167
|
}
|
|
88
|
-
|
|
168
|
+
|
|
169
|
+
lastStop = thisStop;
|
|
89
170
|
});
|
|
171
|
+
|
|
90
172
|
return false;
|
|
91
173
|
}
|
|
92
174
|
}).toString();
|
|
93
175
|
}
|
|
94
176
|
|
|
95
|
-
exports.default = _postcss2.default.plugin('postcss-minify-gradients',
|
|
96
|
-
return
|
|
97
|
-
return css.walkDecls(optimise);
|
|
98
|
-
};
|
|
177
|
+
exports.default = _postcss2.default.plugin('postcss-minify-gradients', () => {
|
|
178
|
+
return css => css.walkDecls(optimise);
|
|
99
179
|
});
|
|
100
180
|
module.exports = exports['default'];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-minify-gradients",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Minify gradient parameters with PostCSS.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,24 +18,25 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"babel-cli": "^6.0.0",
|
|
21
|
-
"cross-env": "^
|
|
21
|
+
"cross-env": "^5.0.0"
|
|
22
22
|
},
|
|
23
|
-
"homepage": "https://github.com/
|
|
23
|
+
"homepage": "https://github.com/cssnano/cssnano",
|
|
24
24
|
"author": {
|
|
25
25
|
"name": "Ben Briggs",
|
|
26
26
|
"email": "beneb.info@gmail.com",
|
|
27
27
|
"url": "http://beneb.info"
|
|
28
28
|
},
|
|
29
|
-
"repository": "
|
|
29
|
+
"repository": "cssnano/cssnano",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"cssnano-util-get-arguments": "^4.0.0
|
|
32
|
-
"
|
|
31
|
+
"cssnano-util-get-arguments": "^4.0.0",
|
|
32
|
+
"is-color-stop": "^1.0.0",
|
|
33
|
+
"postcss": "^7.0.0",
|
|
33
34
|
"postcss-value-parser": "^3.0.0"
|
|
34
35
|
},
|
|
35
36
|
"bugs": {
|
|
36
|
-
"url": "https://github.com/
|
|
37
|
+
"url": "https://github.com/cssnano/cssnano/issues"
|
|
37
38
|
},
|
|
38
39
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
40
|
+
"node": ">=6.9.0"
|
|
40
41
|
}
|
|
41
42
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# 4.0.0-rc.0
|
|
2
|
-
|
|
3
|
-
* Breaking: Drops support for Node 0.12, we now require at least Node 4.
|
|
4
|
-
* Breaking: Update PostCSS to 6.0.0.
|
|
5
|
-
* Better handling of color stop positions in radial gradients, the module now
|
|
6
|
-
correctly accounts for the first set of parameters potentially being
|
|
7
|
-
directional and not stop values.
|
|
8
|
-
|
|
9
|
-
# 1.0.5
|
|
10
|
-
|
|
11
|
-
* Resolves a crash on empty `linear-gradient()` functions.
|
|
12
|
-
|
|
13
|
-
# 1.0.4
|
|
14
|
-
|
|
15
|
-
* Resolves an issue where `0` was being removed from intermediate colour stops
|
|
16
|
-
if preceding colour stops contained `calc()` (thanks to @jaybekster).
|
|
17
|
-
|
|
18
|
-
# 1.0.3
|
|
19
|
-
|
|
20
|
-
* Resolves an issue where `0` was being incorrectly stripped from the final
|
|
21
|
-
colour stop value.
|
|
22
|
-
|
|
23
|
-
# 1.0.2
|
|
24
|
-
|
|
25
|
-
* Resolves an issue where the module would incorrectly parse floating
|
|
26
|
-
point numbers.
|
|
27
|
-
|
|
28
|
-
# 1.0.1
|
|
29
|
-
|
|
30
|
-
* Reduce function iterations (thanks to @TrySound).
|
|
31
|
-
|
|
32
|
-
# 1.0.0
|
|
33
|
-
|
|
34
|
-
* Initial release.
|