postcss-minify-params 1.0.5 → 1.2.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/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ # 1.2.2
2
+
3
+ * Resolves an issue where `all and` would be removed from
4
+ `@media not all and (conditions) {}`, causing an invalid media query to
5
+ be output.
6
+
7
+ # 1.2.1
8
+
9
+ * Resolves an issue where `1.2.0` would throw on empty function parentheses.
10
+
11
+ # 1.2.0
12
+
13
+ * Adds support for simplifying `min-aspect-ratio` and `max-aspect-ratio`. For
14
+ example, `@media (min-aspect-ratio: 1280/720) {}` can be minified to
15
+ `@media (min-aspect-ratio:16/9){}`.
16
+
17
+ # 1.1.0
18
+
19
+ * Adds support for removing the unnecessary `all and` from media queries.
20
+
1
21
  # 1.0.1
2
22
 
3
23
  * Refactor to ES6.
package/README.md CHANGED
@@ -29,5 +29,5 @@ See [PostCSS] docs for examples for your environment.
29
29
  MIT © [Bogdan Chadkin](mailto:trysound@yandex.ru)
30
30
 
31
31
  [PostCSS]: https://github.com/postcss/postcss
32
- [ci-img]: https://travis-ci.org/TrySound/postcss-minify-params.svg
33
- [ci]: https://travis-ci.org/TrySound/postcss-minify-params
32
+ [ci-img]: https://travis-ci.org/ben-eb/postcss-minify-params.svg
33
+ [ci]: https://travis-ci.org/ben-eb/postcss-minify-params
package/dist/index.js CHANGED
@@ -4,6 +4,21 @@ var stringify = valueParser.stringify;
4
4
  var sort = require('alphanum-sort');
5
5
  var uniqs = require('uniqs');
6
6
 
7
+ /**
8
+ * Return the greatest common divisor
9
+ * of two numbers.
10
+ */
11
+
12
+ function gcd(a, b) {
13
+ return b ? gcd(b, a % b) : a;
14
+ }
15
+
16
+ function aspectRatio(a, b) {
17
+ var divisor = gcd(a, b);
18
+
19
+ return [a / divisor, b / divisor];
20
+ }
21
+
7
22
  function split(nodes, div) {
8
23
  var result = [];
9
24
  var i, max, node;
@@ -24,6 +39,11 @@ function split(nodes, div) {
24
39
  return result;
25
40
  }
26
41
 
42
+ function removeNode(node) {
43
+ node.value = '';
44
+ node.type = 'word';
45
+ }
46
+
27
47
  module.exports = postcss.plugin('postcss-minify-params', function () {
28
48
  return function (css) {
29
49
  css.walkAtRules(function (rule) {
@@ -33,17 +53,54 @@ module.exports = postcss.plugin('postcss-minify-params', function () {
33
53
 
34
54
  var params = valueParser(rule.params);
35
55
 
36
- params.walk(function (node) {
56
+ params.walk(function (node, index) {
37
57
  if (node.type === 'div' || node.type === 'function') {
38
58
  node.before = node.after = '';
59
+ if (
60
+ node.type === 'function' &&
61
+ node.nodes[4] &&
62
+ node.nodes[0].value.indexOf('-aspect-ratio') === 3
63
+ ) {
64
+ var ref = aspectRatio(
65
+ node.nodes[2].value,
66
+ node.nodes[4].value
67
+ );
68
+ var a = ref[0];
69
+ var b = ref[1];
70
+ node.nodes[2].value = a;
71
+ node.nodes[4].value = b;
72
+ }
39
73
  } else if (node.type === 'space') {
40
74
  node.value = ' ';
75
+ } else if (node.type === 'word') {
76
+ var prevWord = params.nodes[index - 2];
77
+ if (
78
+ node.value === 'all' &&
79
+ rule.name === 'media' &&
80
+ !prevWord
81
+ ) {
82
+ var nextSpace = params.nodes[index + 1];
83
+ var nextWord = params.nodes[index + 2];
84
+ var secondSpace = params.nodes[index + 3];
85
+ if (nextWord && nextWord.value === 'and') {
86
+ removeNode(nextWord);
87
+ removeNode(nextSpace);
88
+ if (secondSpace) {
89
+ removeNode(secondSpace);
90
+ }
91
+ }
92
+ removeNode(node);
93
+ }
41
94
  }
42
95
  }, true);
43
96
 
44
97
  rule.params = sort(uniqs(split(params.nodes, ',')), {
45
98
  insensitive: true
46
99
  }).join();
100
+
101
+ if (!rule.params.length) {
102
+ rule.raws.afterName = '';
103
+ }
47
104
  });
48
105
  };
49
106
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-minify-params",
3
- "version": "1.0.5",
3
+ "version": "1.2.2",
4
4
  "description": "Minify at-rule params with PostCSS",
5
5
  "keywords": [
6
6
  "postcss",
@@ -16,11 +16,11 @@
16
16
  ],
17
17
  "author": "Bogdan Chadkin <trysound@yandex.ru>",
18
18
  "license": "MIT",
19
- "repository": "TrySound/postcss-minify-params",
19
+ "repository": "ben-eb/postcss-minify-params",
20
20
  "bugs": {
21
- "url": "https://github.com/TrySound/postcss-minify-params/issues"
21
+ "url": "https://github.com/ben-eb/postcss-minify-params/issues"
22
22
  },
23
- "homepage": "https://github.com/TrySound/postcss-minify-params",
23
+ "homepage": "https://github.com/ben-eb/postcss-minify-params",
24
24
  "dependencies": {
25
25
  "alphanum-sort": "^1.0.1",
26
26
  "postcss": "^5.0.2",