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 CHANGED
@@ -43,7 +43,7 @@ examples for your environment.
43
43
 
44
44
  ## Contributors
45
45
 
46
- See [CONTRIBUTORS.md](https://github.com/ben-eb/cssnano/blob/master/CONTRIBUTORS.md).
46
+ See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
47
47
 
48
48
 
49
49
  ## License
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
- var angles = {
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
- if (!~decl.value.indexOf('gradient')) {
37
+ const value = decl.value;
38
+
39
+ if (!~value.toLowerCase().indexOf('gradient')) {
34
40
  return;
35
41
  }
36
- decl.value = (0, _postcssValueParser2.default)(decl.value).walk(function (node) {
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
- if (node.value === 'linear-gradient' || node.value === 'repeating-linear-gradient' || node.value === '-webkit-linear-gradient' || node.value === '-webkit-repeating-linear-gradient') {
41
- var args = (0, _cssnanoUtilGetArguments2.default)(node);
42
- if (node.nodes[0].value === 'to' && args[0].length === 3) {
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
- var lastStop = null;
47
- args.forEach(function (arg, index) {
57
+
58
+ let lastStop = null;
59
+
60
+ args.forEach((arg, index) => {
48
61
  if (!arg[2]) {
49
62
  return;
50
63
  }
51
- var isFinalStop = index === args.length - 1;
52
- var thisStop = (0, _postcssValueParser.unit)(arg[2].value);
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
- if (!isFinalStop && lastStop && lastStop.number === '0' && lastStop.unit !== 'deg') {
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
- if (isLessThan(lastStop, thisStop)) {
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
- if (node.value === 'radial-gradient' || node.value === 'repeating-radial-gradient' || node.value === '-webkit-radial-gradient' || node.value === '-webkit-repeating-radial-gradient') {
71
- var _args = (0, _cssnanoUtilGetArguments2.default)(node);
72
- var _lastStop = void 0;
73
- var hasAt = _args[0].find(function (n) {
74
- return n.value === 'at';
75
- });
76
- _args.forEach(function (arg, index) {
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
- var thisStop = (0, _postcssValueParser.unit)(arg[2].value);
81
- if (!_lastStop) {
82
- _lastStop = thisStop;
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
- if (isLessThan(_lastStop, thisStop)) {
164
+
165
+ if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
86
166
  arg[2].value = 0;
87
167
  }
88
- _lastStop = thisStop;
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', function () {
96
- return function (css) {
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.0-rc.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": "^3.0.0"
21
+ "cross-env": "^5.0.0"
22
22
  },
23
- "homepage": "https://github.com/ben-eb/cssnano",
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": "ben-eb/cssnano",
29
+ "repository": "cssnano/cssnano",
30
30
  "dependencies": {
31
- "cssnano-util-get-arguments": "^4.0.0-rc.0",
32
- "postcss": "^6.0.0",
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/ben-eb/cssnano/issues"
37
+ "url": "https://github.com/cssnano/cssnano/issues"
37
38
  },
38
39
  "engines": {
39
- "node": ">=4"
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.