postcss-normalize-positions 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
@@ -16,7 +16,7 @@ npm install postcss-normalize-positions --save
16
16
 
17
17
  ```css
18
18
  div {
19
- background-position: bottom right
19
+ background-position: bottom left;
20
20
  }
21
21
  ```
22
22
 
@@ -24,7 +24,7 @@ div {
24
24
 
25
25
  ```css
26
26
  div {
27
- background-position: 100% 100%
27
+ background-position:0 100%;
28
28
  }
29
29
  ```
30
30
 
@@ -35,7 +35,7 @@ examples for your environment.
35
35
 
36
36
  ## Contributors
37
37
 
38
- See [CONTRIBUTORS.md](https://github.com/ben-eb/cssnano/blob/master/CONTRIBUTORS.md).
38
+ See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
39
39
 
40
40
  ## License
41
41
 
package/dist/index.js CHANGED
@@ -20,96 +20,130 @@ var _has2 = _interopRequireDefault(_has);
20
20
 
21
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
22
 
23
- var directions = ['top', 'right', 'bottom', 'left', 'center'];
23
+ const directions = ['top', 'right', 'bottom', 'left', 'center'];
24
24
 
25
- var center = '50%';
25
+ const center = '50%';
26
26
 
27
- var horizontal = {
27
+ const horizontal = {
28
28
  right: '100%',
29
29
  left: '0'
30
30
  };
31
31
 
32
- var vertical = {
32
+ const vertical = {
33
33
  bottom: '100%',
34
34
  top: '0'
35
35
  };
36
36
 
37
- function transform(decl) {
38
- var values = (0, _postcssValueParser2.default)(decl.value);
39
- var args = (0, _cssnanoUtilGetArguments2.default)(values);
40
- var relevant = [];
41
- args.forEach(function (arg) {
37
+ function transform(value) {
38
+ const parsed = (0, _postcssValueParser2.default)(value);
39
+ const args = (0, _cssnanoUtilGetArguments2.default)(parsed);
40
+ const relevant = [];
41
+
42
+ args.forEach(arg => {
42
43
  relevant.push({
43
44
  start: null,
44
45
  end: null
45
46
  });
46
- arg.forEach(function (part, index) {
47
- var isPosition = ~directions.indexOf(part.value) || (0, _postcssValueParser.unit)(part.value);
48
- var len = relevant.length - 1;
47
+
48
+ arg.forEach((part, index) => {
49
+ const isPosition = ~directions.indexOf(part.value.toLowerCase()) || (0, _postcssValueParser.unit)(part.value);
50
+ const len = relevant.length - 1;
51
+
49
52
  if (relevant[len].start === null && isPosition) {
50
53
  relevant[len].start = index;
51
54
  relevant[len].end = index;
55
+
52
56
  return;
53
57
  }
58
+
54
59
  if (relevant[len].start !== null) {
55
60
  if (part.type === 'space') {
56
61
  return;
57
62
  } else if (isPosition) {
58
63
  relevant[len].end = index;
64
+
59
65
  return;
60
66
  }
67
+
61
68
  return;
62
69
  }
63
70
  });
64
71
  });
65
- relevant.forEach(function (range, index) {
72
+
73
+ relevant.forEach((range, index) => {
66
74
  if (range.start === null) {
67
75
  return;
68
76
  }
69
- var position = args[index].slice(range.start, range.end + 1);
77
+
78
+ const position = args[index].slice(range.start, range.end + 1);
79
+
70
80
  if (position.length > 3) {
71
81
  return;
72
82
  }
73
- if (position.length === 1 || position[2].value === 'center') {
74
- if (position[2]) {
83
+
84
+ const firstValue = position[0].value.toLowerCase();
85
+ const secondValue = position[2] && position[2].value ? position[2].value.toLowerCase() : null;
86
+
87
+ if (position.length === 1 || secondValue === 'center') {
88
+ if (secondValue) {
75
89
  position[2].value = position[1].value = '';
76
90
  }
77
- var value = position[0].value;
78
91
 
79
- var map = Object.assign({}, horizontal, {
92
+ const map = Object.assign({}, horizontal, {
80
93
  center
81
94
  });
82
- if ((0, _has2.default)(map, value)) {
83
- position[0].value = map[value];
95
+
96
+ if ((0, _has2.default)(map, firstValue)) {
97
+ position[0].value = map[firstValue];
84
98
  }
99
+
85
100
  return;
86
101
  }
87
- if (position[0].value === 'center' && ~directions.indexOf(position[2].value)) {
102
+
103
+ if (firstValue === 'center' && ~directions.indexOf(secondValue)) {
88
104
  position[0].value = position[1].value = '';
89
- var _value = position[2].value;
90
105
 
91
- if ((0, _has2.default)(horizontal, _value)) {
92
- position[2].value = horizontal[_value];
106
+ if ((0, _has2.default)(horizontal, secondValue)) {
107
+ position[2].value = horizontal[secondValue];
93
108
  }
109
+
94
110
  return;
95
111
  }
96
- if ((0, _has2.default)(horizontal, position[0].value) && (0, _has2.default)(vertical, position[2].value)) {
97
- position[0].value = horizontal[position[0].value];
98
- position[2].value = vertical[position[2].value];
112
+
113
+ if ((0, _has2.default)(horizontal, firstValue) && (0, _has2.default)(vertical, secondValue)) {
114
+ position[0].value = horizontal[firstValue];
115
+ position[2].value = vertical[secondValue];
116
+
99
117
  return;
100
- } else if ((0, _has2.default)(vertical, position[0].value) && (0, _has2.default)(horizontal, position[2].value)) {
101
- var first = position[0].value;
102
- position[0].value = horizontal[position[2].value];
103
- position[2].value = vertical[first];
118
+ } else if ((0, _has2.default)(vertical, firstValue) && (0, _has2.default)(horizontal, secondValue)) {
119
+ position[0].value = horizontal[secondValue];
120
+ position[2].value = vertical[firstValue];
121
+
104
122
  return;
105
123
  }
106
124
  });
107
- decl.value = values.toString();
125
+
126
+ return parsed.toString();
108
127
  }
109
128
 
110
- exports.default = (0, _postcss.plugin)('postcss-normalize-positions', function () {
111
- return function (css) {
112
- return css.walkDecls(/^(background(-position)?|(-webkit-)?perspective-origin)$/i, transform);
129
+ exports.default = (0, _postcss.plugin)('postcss-normalize-positions', () => {
130
+ return css => {
131
+ const cache = {};
132
+
133
+ css.walkDecls(/^(background(-position)?|(-webkit-)?perspective-origin)$/i, decl => {
134
+ const value = decl.value;
135
+
136
+ if (cache[value]) {
137
+ decl.value = cache[value];
138
+
139
+ return;
140
+ }
141
+
142
+ const result = transform(value);
143
+
144
+ decl.value = result;
145
+ cache[value] = result;
146
+ });
113
147
  };
114
148
  });
115
149
  module.exports = exports['default'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-normalize-positions",
3
- "version": "4.0.0-rc.0",
3
+ "version": "4.0.2",
4
4
  "description": "Normalize keyword values for position into length values.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -18,25 +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",
31
+ "cssnano-util-get-arguments": "^4.0.0",
32
32
  "has": "^1.0.0",
33
- "postcss": "^6.0.0",
33
+ "postcss": "^7.0.0",
34
34
  "postcss-value-parser": "^3.0.0"
35
35
  },
36
36
  "bugs": {
37
- "url": "https://github.com/ben-eb/cssnano/issues"
37
+ "url": "https://github.com/cssnano/cssnano/issues"
38
38
  },
39
39
  "engines": {
40
- "node": ">=4"
40
+ "node": ">=6.9.0"
41
41
  }
42
42
  }
package/CHANGELOG.md DELETED
@@ -1,4 +0,0 @@
1
- # 4.0.0-rc.0
2
-
3
- * Initial commit. This module was previously part of other cssnano modules and
4
- has been extracted out.