postcss-minify-gradients 4.0.1 → 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/dist/index.js +46 -7
- package/package.json +1 -1
- package/CHANGELOG.md +0 -34
package/dist/index.js
CHANGED
|
@@ -30,80 +30,109 @@ const angles = {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
function isLessThan(a, b) {
|
|
33
|
-
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);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
function optimise(decl) {
|
|
37
|
-
|
|
37
|
+
const value = decl.value;
|
|
38
|
+
|
|
39
|
+
if (!~value.toLowerCase().indexOf('gradient')) {
|
|
38
40
|
return;
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
|
|
43
|
+
decl.value = (0, _postcssValueParser2.default)(value).walk(node => {
|
|
41
44
|
if (node.type !== 'function' || !node.nodes.length) {
|
|
42
45
|
return false;
|
|
43
46
|
}
|
|
47
|
+
|
|
44
48
|
const lowerCasedValue = node.value.toLowerCase();
|
|
49
|
+
|
|
45
50
|
if (lowerCasedValue === 'linear-gradient' || lowerCasedValue === 'repeating-linear-gradient' || lowerCasedValue === '-webkit-linear-gradient' || lowerCasedValue === '-webkit-repeating-linear-gradient') {
|
|
46
51
|
let args = (0, _cssnanoUtilGetArguments2.default)(node);
|
|
52
|
+
|
|
47
53
|
if (node.nodes[0].value.toLowerCase() === 'to' && args[0].length === 3) {
|
|
48
54
|
node.nodes = node.nodes.slice(2);
|
|
49
55
|
node.nodes[0].value = angles[node.nodes[0].value.toLowerCase()];
|
|
50
56
|
}
|
|
57
|
+
|
|
51
58
|
let lastStop = null;
|
|
59
|
+
|
|
52
60
|
args.forEach((arg, index) => {
|
|
53
61
|
if (!arg[2]) {
|
|
54
62
|
return;
|
|
55
63
|
}
|
|
64
|
+
|
|
56
65
|
let isFinalStop = index === args.length - 1;
|
|
57
66
|
let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
|
|
67
|
+
|
|
58
68
|
if (lastStop === null) {
|
|
59
69
|
lastStop = thisStop;
|
|
70
|
+
|
|
60
71
|
if (!isFinalStop && lastStop && lastStop.number === '0' && lastStop.unit.toLowerCase() !== 'deg') {
|
|
61
72
|
arg[1].value = arg[2].value = '';
|
|
62
73
|
}
|
|
74
|
+
|
|
63
75
|
return;
|
|
64
76
|
}
|
|
65
|
-
|
|
77
|
+
|
|
78
|
+
if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
|
|
66
79
|
arg[2].value = 0;
|
|
67
80
|
}
|
|
81
|
+
|
|
68
82
|
lastStop = thisStop;
|
|
83
|
+
|
|
69
84
|
if (isFinalStop && arg[2].value === '100%') {
|
|
70
85
|
arg[1].value = arg[2].value = '';
|
|
71
86
|
}
|
|
72
87
|
});
|
|
88
|
+
|
|
73
89
|
return false;
|
|
74
90
|
}
|
|
91
|
+
|
|
75
92
|
if (lowerCasedValue === 'radial-gradient' || lowerCasedValue === 'repeating-radial-gradient') {
|
|
76
93
|
let args = (0, _cssnanoUtilGetArguments2.default)(node);
|
|
77
94
|
let lastStop;
|
|
95
|
+
|
|
78
96
|
const hasAt = args[0].find(n => n.value.toLowerCase() === 'at');
|
|
97
|
+
|
|
79
98
|
args.forEach((arg, index) => {
|
|
80
99
|
if (!arg[2] || !index && hasAt) {
|
|
81
100
|
return;
|
|
82
101
|
}
|
|
102
|
+
|
|
83
103
|
let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
|
|
104
|
+
|
|
84
105
|
if (!lastStop) {
|
|
85
106
|
lastStop = thisStop;
|
|
107
|
+
|
|
86
108
|
return;
|
|
87
109
|
}
|
|
88
|
-
|
|
110
|
+
|
|
111
|
+
if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
|
|
89
112
|
arg[2].value = 0;
|
|
90
113
|
}
|
|
114
|
+
|
|
91
115
|
lastStop = thisStop;
|
|
92
116
|
});
|
|
117
|
+
|
|
93
118
|
return false;
|
|
94
119
|
}
|
|
120
|
+
|
|
95
121
|
if (lowerCasedValue === '-webkit-radial-gradient' || lowerCasedValue === '-webkit-repeating-radial-gradient') {
|
|
96
122
|
let args = (0, _cssnanoUtilGetArguments2.default)(node);
|
|
97
123
|
let lastStop;
|
|
124
|
+
|
|
98
125
|
args.forEach(arg => {
|
|
99
126
|
let color;
|
|
100
127
|
let stop;
|
|
128
|
+
|
|
101
129
|
if (arg[2] !== undefined) {
|
|
102
130
|
if (arg[0].type === 'function') {
|
|
103
131
|
color = `${arg[0].value}(${(0, _postcssValueParser.stringify)(arg[0].nodes)})`;
|
|
104
132
|
} else {
|
|
105
133
|
color = arg[0].value;
|
|
106
134
|
}
|
|
135
|
+
|
|
107
136
|
if (arg[2].type === 'function') {
|
|
108
137
|
stop = `${arg[2].value}(${(0, _postcssValueParser.stringify)(arg[2].nodes)})`;
|
|
109
138
|
} else {
|
|
@@ -113,23 +142,33 @@ function optimise(decl) {
|
|
|
113
142
|
if (arg[0].type === 'function') {
|
|
114
143
|
color = `${arg[0].value}(${(0, _postcssValueParser.stringify)(arg[0].nodes)})`;
|
|
115
144
|
}
|
|
145
|
+
|
|
116
146
|
color = arg[0].value;
|
|
117
147
|
}
|
|
118
|
-
|
|
148
|
+
|
|
149
|
+
color = color.toLowerCase();
|
|
150
|
+
|
|
151
|
+
const colorStop = stop || stop === 0 ? (0, _isColorStop2.default)(color, stop.toLowerCase()) : (0, _isColorStop2.default)(color);
|
|
119
152
|
|
|
120
153
|
if (!colorStop || !arg[2]) {
|
|
121
154
|
return;
|
|
122
155
|
}
|
|
156
|
+
|
|
123
157
|
let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
|
|
158
|
+
|
|
124
159
|
if (!lastStop) {
|
|
125
160
|
lastStop = thisStop;
|
|
161
|
+
|
|
126
162
|
return;
|
|
127
163
|
}
|
|
128
|
-
|
|
164
|
+
|
|
165
|
+
if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
|
|
129
166
|
arg[2].value = 0;
|
|
130
167
|
}
|
|
168
|
+
|
|
131
169
|
lastStop = thisStop;
|
|
132
170
|
});
|
|
171
|
+
|
|
133
172
|
return false;
|
|
134
173
|
}
|
|
135
174
|
}).toString();
|
package/package.json
CHANGED
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.
|