postcss-minify-gradients 4.0.2 → 5.0.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.
Files changed (3) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/index.js +134 -128
  3. package/package.json +16 -12
package/CHANGELOG.md ADDED
@@ -0,0 +1,69 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [5.0.0](https://github.com/cssnano/cssnano/compare/postcss-minify-gradients@5.0.0-rc.2...postcss-minify-gradients@5.0.0) (2021-04-06)
7
+
8
+ **Note:** Version bump only for package postcss-minify-gradients
9
+
10
+
11
+
12
+
13
+
14
+ # [5.0.0-rc.2](https://github.com/cssnano/cssnano/compare/postcss-minify-gradients@5.0.0-rc.1...postcss-minify-gradients@5.0.0-rc.2) (2021-03-15)
15
+
16
+ **Note:** Version bump only for package postcss-minify-gradients
17
+
18
+
19
+
20
+
21
+
22
+ # [5.0.0-rc.1](https://github.com/cssnano/cssnano/compare/postcss-minify-gradients@5.0.0-rc.0...postcss-minify-gradients@5.0.0-rc.1) (2021-03-04)
23
+
24
+ **Note:** Version bump only for package postcss-minify-gradients
25
+
26
+
27
+
28
+
29
+
30
+ # 5.0.0-rc.0 (2021-02-19)
31
+
32
+
33
+ ### Bug Fixes
34
+
35
+ * **postcss-minify-gradients:** don't break gradients with `var` and `env` functions ([#735](https://github.com/cssnano/cssnano/issues/735)) ([7fabd9d](https://github.com/cssnano/cssnano/commit/7fabd9d03c81142c5854d0c0a50bee15ed86c219))
36
+
37
+
38
+ ### chore
39
+
40
+ * minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
41
+
42
+
43
+ ### Features
44
+
45
+ * migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
46
+
47
+
48
+ ### BREAKING CHANGES
49
+
50
+ * minimum supported `postcss` version is `8.2.1`
51
+ * minimum require version of node is 10.13
52
+
53
+
54
+
55
+ ## 4.1.9 (2019-02-12)
56
+
57
+
58
+ ### Bug Fixes
59
+
60
+ * **postcss-minify-gradients:** handle uppercase ([#706](https://github.com/cssnano/cssnano/issues/706)) ([acd5d0e](https://github.com/cssnano/cssnano/commit/acd5d0eb59e76fe62b70faad89d6ee0f76f798ef))
61
+
62
+
63
+
64
+ ## 4.1.1 (2018-09-24)
65
+
66
+
67
+ ### Bug Fixes
68
+
69
+ * **postcss-merge-longhand:** not mangle border output ([#555](https://github.com/cssnano/cssnano/issues/555)) ([9a70605](https://github.com/cssnano/cssnano/commit/9a706050b621e7795a9bf74eb7110b5c81804ffe)), closes [#553](https://github.com/cssnano/cssnano/issues/553) [#554](https://github.com/cssnano/cssnano/issues/554)
package/dist/index.js CHANGED
@@ -1,180 +1,186 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
- value: true
4
+ value: true
5
5
  });
6
+ exports.default = void 0;
6
7
 
7
- var _postcss = require('postcss');
8
+ var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser"));
8
9
 
9
- var _postcss2 = _interopRequireDefault(_postcss);
10
+ var _cssnanoUtils = require("cssnano-utils");
10
11
 
11
- var _postcssValueParser = require('postcss-value-parser');
12
+ var _isColorStop = _interopRequireDefault(require("is-color-stop"));
12
13
 
13
- var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
14
-
15
- var _cssnanoUtilGetArguments = require('cssnano-util-get-arguments');
16
-
17
- var _cssnanoUtilGetArguments2 = _interopRequireDefault(_cssnanoUtilGetArguments);
18
-
19
- var _isColorStop = require('is-color-stop');
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
15
 
21
- var _isColorStop2 = _interopRequireDefault(_isColorStop);
16
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
22
17
 
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
24
19
 
25
20
  const angles = {
26
- top: '0deg',
27
- right: '90deg',
28
- bottom: '180deg',
29
- left: '270deg'
21
+ top: '0deg',
22
+ right: '90deg',
23
+ bottom: '180deg',
24
+ left: '270deg'
30
25
  };
31
26
 
32
27
  function isLessThan(a, b) {
33
- return a.unit.toLowerCase() === b.unit.toLowerCase() && parseFloat(a.number) >= parseFloat(b.number);
28
+ return a.unit.toLowerCase() === b.unit.toLowerCase() && parseFloat(a.number) >= parseFloat(b.number);
34
29
  }
35
30
 
36
31
  function optimise(decl) {
37
- const value = decl.value;
38
-
39
- if (!~value.toLowerCase().indexOf('gradient')) {
40
- return;
41
- }
42
-
43
- decl.value = (0, _postcssValueParser2.default)(value).walk(node => {
44
- if (node.type !== 'function' || !node.nodes.length) {
45
- return false;
46
- }
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) {
54
- node.nodes = node.nodes.slice(2);
55
- node.nodes[0].value = angles[node.nodes[0].value.toLowerCase()];
56
- }
32
+ const value = decl.value;
57
33
 
58
- let lastStop = null;
34
+ if (!value) {
35
+ return;
36
+ }
59
37
 
60
- args.forEach((arg, index) => {
61
- if (!arg[2]) {
62
- return;
63
- }
38
+ const normalizedValue = value.toLowerCase();
64
39
 
65
- let isFinalStop = index === args.length - 1;
66
- let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
40
+ if (normalizedValue.includes('var(') || normalizedValue.includes('env(')) {
41
+ return;
42
+ }
67
43
 
68
- if (lastStop === null) {
69
- lastStop = thisStop;
44
+ if (!normalizedValue.includes('gradient')) {
45
+ return;
46
+ }
70
47
 
71
- if (!isFinalStop && lastStop && lastStop.number === '0' && lastStop.unit.toLowerCase() !== 'deg') {
72
- arg[1].value = arg[2].value = '';
73
- }
74
-
75
- return;
76
- }
48
+ decl.value = (0, _postcssValueParser.default)(value).walk(node => {
49
+ if (node.type !== 'function' || !node.nodes.length) {
50
+ return false;
51
+ }
77
52
 
78
- if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
79
- arg[2].value = 0;
80
- }
53
+ const lowerCasedValue = node.value.toLowerCase();
81
54
 
82
- lastStop = thisStop;
55
+ if (lowerCasedValue === 'linear-gradient' || lowerCasedValue === 'repeating-linear-gradient' || lowerCasedValue === '-webkit-linear-gradient' || lowerCasedValue === '-webkit-repeating-linear-gradient') {
56
+ let args = (0, _cssnanoUtils.getArguments)(node);
83
57
 
84
- if (isFinalStop && arg[2].value === '100%') {
85
- arg[1].value = arg[2].value = '';
86
- }
87
- });
58
+ if (node.nodes[0].value.toLowerCase() === 'to' && args[0].length === 3) {
59
+ node.nodes = node.nodes.slice(2);
60
+ node.nodes[0].value = angles[node.nodes[0].value.toLowerCase()];
61
+ }
88
62
 
89
- return false;
63
+ let lastStop = null;
64
+ args.forEach((arg, index) => {
65
+ if (!arg[2]) {
66
+ return;
90
67
  }
91
68
 
92
- if (lowerCasedValue === 'radial-gradient' || lowerCasedValue === 'repeating-radial-gradient') {
93
- let args = (0, _cssnanoUtilGetArguments2.default)(node);
94
- let lastStop;
69
+ let isFinalStop = index === args.length - 1;
70
+ let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
95
71
 
96
- const hasAt = args[0].find(n => n.value.toLowerCase() === 'at');
72
+ if (lastStop === null) {
73
+ lastStop = thisStop;
97
74
 
98
- args.forEach((arg, index) => {
99
- if (!arg[2] || !index && hasAt) {
100
- return;
101
- }
75
+ if (!isFinalStop && lastStop && lastStop.number === '0' && lastStop.unit.toLowerCase() !== 'deg') {
76
+ arg[1].value = arg[2].value = '';
77
+ }
102
78
 
103
- let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
104
-
105
- if (!lastStop) {
106
- lastStop = thisStop;
79
+ return;
80
+ }
107
81
 
108
- return;
109
- }
82
+ if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
83
+ arg[2].value = 0;
84
+ }
110
85
 
111
- if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
112
- arg[2].value = 0;
113
- }
86
+ lastStop = thisStop;
114
87
 
115
- lastStop = thisStop;
116
- });
88
+ if (isFinalStop && arg[2].value === '100%') {
89
+ arg[1].value = arg[2].value = '';
90
+ }
91
+ });
92
+ return false;
93
+ }
117
94
 
118
- return false;
95
+ if (lowerCasedValue === 'radial-gradient' || lowerCasedValue === 'repeating-radial-gradient') {
96
+ let args = (0, _cssnanoUtils.getArguments)(node);
97
+ let lastStop;
98
+ const hasAt = args[0].find(n => n.value.toLowerCase() === 'at');
99
+ args.forEach((arg, index) => {
100
+ if (!arg[2] || !index && hasAt) {
101
+ return;
119
102
  }
120
103
 
121
- if (lowerCasedValue === '-webkit-radial-gradient' || lowerCasedValue === '-webkit-repeating-radial-gradient') {
122
- let args = (0, _cssnanoUtilGetArguments2.default)(node);
123
- let lastStop;
104
+ let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
124
105
 
125
- args.forEach(arg => {
126
- let color;
127
- let stop;
106
+ if (!lastStop) {
107
+ lastStop = thisStop;
108
+ return;
109
+ }
128
110
 
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
- }
111
+ if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
112
+ arg[2].value = 0;
113
+ }
135
114
 
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
- }
115
+ lastStop = thisStop;
116
+ });
117
+ return false;
118
+ }
145
119
 
146
- color = arg[0].value;
147
- }
120
+ if (lowerCasedValue === '-webkit-radial-gradient' || lowerCasedValue === '-webkit-repeating-radial-gradient') {
121
+ let args = (0, _cssnanoUtils.getArguments)(node);
122
+ let lastStop;
123
+ args.forEach(arg => {
124
+ let color;
125
+ let stop;
126
+
127
+ if (arg[2] !== undefined) {
128
+ if (arg[0].type === 'function') {
129
+ color = `${arg[0].value}(${(0, _postcssValueParser.stringify)(arg[0].nodes)})`;
130
+ } else {
131
+ color = arg[0].value;
132
+ }
133
+
134
+ if (arg[2].type === 'function') {
135
+ stop = `${arg[2].value}(${(0, _postcssValueParser.stringify)(arg[2].nodes)})`;
136
+ } else {
137
+ stop = arg[2].value;
138
+ }
139
+ } else {
140
+ if (arg[0].type === 'function') {
141
+ color = `${arg[0].value}(${(0, _postcssValueParser.stringify)(arg[0].nodes)})`;
142
+ }
143
+
144
+ color = arg[0].value;
145
+ }
148
146
 
149
- color = color.toLowerCase();
147
+ color = color.toLowerCase();
148
+ const colorStop = stop || stop === 0 ? (0, _isColorStop.default)(color, stop.toLowerCase()) : (0, _isColorStop.default)(color);
150
149
 
151
- const colorStop = stop || stop === 0 ? (0, _isColorStop2.default)(color, stop.toLowerCase()) : (0, _isColorStop2.default)(color);
150
+ if (!colorStop || !arg[2]) {
151
+ return;
152
+ }
152
153
 
153
- if (!colorStop || !arg[2]) {
154
- return;
155
- }
154
+ let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
156
155
 
157
- let thisStop = (0, _postcssValueParser.unit)(arg[2].value);
156
+ if (!lastStop) {
157
+ lastStop = thisStop;
158
+ return;
159
+ }
158
160
 
159
- if (!lastStop) {
160
- lastStop = thisStop;
161
+ if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
162
+ arg[2].value = 0;
163
+ }
161
164
 
162
- return;
163
- }
165
+ lastStop = thisStop;
166
+ });
167
+ return false;
168
+ }
169
+ }).toString();
170
+ }
164
171
 
165
- if (lastStop && thisStop && isLessThan(lastStop, thisStop)) {
166
- arg[2].value = 0;
167
- }
172
+ function pluginCreator() {
173
+ return {
174
+ postcssPlugin: 'postcss-minify-gradients',
168
175
 
169
- lastStop = thisStop;
170
- });
176
+ OnceExit(css) {
177
+ css.walkDecls(optimise);
178
+ }
171
179
 
172
- return false;
173
- }
174
- }).toString();
180
+ };
175
181
  }
176
182
 
177
- exports.default = _postcss2.default.plugin('postcss-minify-gradients', () => {
178
- return css => css.walkDecls(optimise);
179
- });
180
- module.exports = exports['default'];
183
+ pluginCreator.postcss = true;
184
+ var _default = pluginCreator;
185
+ exports.default = _default;
186
+ module.exports = exports.default;
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "postcss-minify-gradients",
3
- "version": "4.0.2",
3
+ "version": "5.0.0",
4
4
  "description": "Minify gradient parameters with PostCSS.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
- "prepublish": "cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/"
7
+ "prebuild": "del-cli dist",
8
+ "build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
9
+ "prepublish": "yarn build"
8
10
  },
9
11
  "files": [
10
12
  "LICENSE-MIT",
@@ -16,10 +18,6 @@
16
18
  "postcss-plugin"
17
19
  ],
18
20
  "license": "MIT",
19
- "devDependencies": {
20
- "babel-cli": "^6.0.0",
21
- "cross-env": "^5.0.0"
22
- },
23
21
  "homepage": "https://github.com/cssnano/cssnano",
24
22
  "author": {
25
23
  "name": "Ben Briggs",
@@ -28,15 +26,21 @@
28
26
  },
29
27
  "repository": "cssnano/cssnano",
30
28
  "dependencies": {
31
- "cssnano-util-get-arguments": "^4.0.0",
32
- "is-color-stop": "^1.0.0",
33
- "postcss": "^7.0.0",
34
- "postcss-value-parser": "^3.0.0"
29
+ "cssnano-utils": "^2.0.0",
30
+ "is-color-stop": "^1.1.0",
31
+ "postcss-value-parser": "^4.1.0"
35
32
  },
36
33
  "bugs": {
37
34
  "url": "https://github.com/cssnano/cssnano/issues"
38
35
  },
39
36
  "engines": {
40
- "node": ">=6.9.0"
41
- }
37
+ "node": "^10 || ^12 || >=14.0"
38
+ },
39
+ "devDependencies": {
40
+ "postcss": "^8.2.1"
41
+ },
42
+ "peerDependencies": {
43
+ "postcss": "^8.2.1"
44
+ },
45
+ "gitHead": "0e2c3bf5835bafcdc8783bef66f730a24194c8f3"
42
46
  }