postcss-normalize-positions 5.0.0 → 5.0.4
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/package.json +8 -13
- package/src/index.js +217 -0
- package/CHANGELOG.md +0 -71
- package/dist/index.js +0 -209
package/package.json
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-normalize-positions",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.4",
|
|
4
4
|
"description": "Normalize keyword values for position into length values.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
7
|
-
"
|
|
7
|
+
"src",
|
|
8
8
|
"LICENSE-MIT"
|
|
9
9
|
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"prebuild": "del-cli dist",
|
|
12
|
-
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
|
|
13
|
-
"prepublish": "yarn build"
|
|
14
|
-
},
|
|
15
10
|
"keywords": [
|
|
16
11
|
"css",
|
|
17
12
|
"postcss",
|
|
@@ -26,7 +21,7 @@
|
|
|
26
21
|
},
|
|
27
22
|
"repository": "cssnano/cssnano",
|
|
28
23
|
"dependencies": {
|
|
29
|
-
"postcss-value-parser": "^4.
|
|
24
|
+
"postcss-value-parser": "^4.2.0"
|
|
30
25
|
},
|
|
31
26
|
"bugs": {
|
|
32
27
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
@@ -35,10 +30,10 @@
|
|
|
35
30
|
"node": "^10 || ^12 || >=14.0"
|
|
36
31
|
},
|
|
37
32
|
"devDependencies": {
|
|
38
|
-
"postcss": "^8.2.
|
|
33
|
+
"postcss": "^8.2.15"
|
|
39
34
|
},
|
|
40
35
|
"peerDependencies": {
|
|
41
|
-
"postcss": "^8.2.
|
|
36
|
+
"postcss": "^8.2.15"
|
|
42
37
|
},
|
|
43
|
-
"
|
|
44
|
-
}
|
|
38
|
+
"readme": "# [postcss][postcss]-normalize-positions\n\n> Normalize positions with PostCSS.\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-normalize-positions) do:\n\n```\nnpm install postcss-normalize-positions --save\n```\n\n## Example\n\n### Input\n\n```css\ndiv {\n background-position: bottom left;\n}\n```\n\n### Output\n\n```css\ndiv {\n background-position:0 100%;\n}\n``` \n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n## License\n\nMIT © [Ben Briggs](http://beneb.info)\n\n[postcss]: https://github.com/postcss/postcss\n"
|
|
39
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const valueParser = require('postcss-value-parser');
|
|
3
|
+
|
|
4
|
+
const directionKeywords = new Set(['top', 'right', 'bottom', 'left', 'center']);
|
|
5
|
+
|
|
6
|
+
const center = '50%';
|
|
7
|
+
const horizontal = new Map([
|
|
8
|
+
['right', '100%'],
|
|
9
|
+
['left', '0'],
|
|
10
|
+
]);
|
|
11
|
+
const verticalValue = new Map([
|
|
12
|
+
['bottom', '100%'],
|
|
13
|
+
['top', '0'],
|
|
14
|
+
]);
|
|
15
|
+
const mathFunctions = new Set(['calc', 'min', 'max', 'clamp']);
|
|
16
|
+
|
|
17
|
+
function isCommaNode(node) {
|
|
18
|
+
return node.type === 'div' && node.value === ',';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isVariableFunctionNode(node) {
|
|
22
|
+
if (node.type !== 'function') {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return ['var', 'env'].includes(node.value.toLowerCase());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isMathFunctionNode(node) {
|
|
30
|
+
if (node.type !== 'function') {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return mathFunctions.has(node.value.toLowerCase());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isNumberNode(node) {
|
|
37
|
+
if (node.type !== 'word') {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const value = parseFloat(node.value);
|
|
42
|
+
|
|
43
|
+
return !isNaN(value);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isDimensionNode(node) {
|
|
47
|
+
if (node.type !== 'word') {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const parsed = valueParser.unit(node.value);
|
|
52
|
+
|
|
53
|
+
if (!parsed) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return parsed.unit !== '';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function transform(value) {
|
|
61
|
+
const parsed = valueParser(value);
|
|
62
|
+
const ranges = [];
|
|
63
|
+
let rangeIndex = 0;
|
|
64
|
+
let shouldContinue = true;
|
|
65
|
+
|
|
66
|
+
parsed.nodes.forEach((node, index) => {
|
|
67
|
+
// After comma (`,`) follows next background
|
|
68
|
+
if (isCommaNode(node)) {
|
|
69
|
+
rangeIndex += 1;
|
|
70
|
+
shouldContinue = true;
|
|
71
|
+
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!shouldContinue) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// After separator (`/`) follows `background-size` values
|
|
80
|
+
// Avoid them
|
|
81
|
+
if (node.type === 'div' && node.value === '/') {
|
|
82
|
+
shouldContinue = false;
|
|
83
|
+
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!ranges[rangeIndex]) {
|
|
88
|
+
ranges[rangeIndex] = {
|
|
89
|
+
start: null,
|
|
90
|
+
end: null,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Do not try to be processed `var and `env` function inside background
|
|
95
|
+
if (isVariableFunctionNode(node)) {
|
|
96
|
+
shouldContinue = false;
|
|
97
|
+
ranges[rangeIndex].start = null;
|
|
98
|
+
ranges[rangeIndex].end = null;
|
|
99
|
+
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const isPositionKeyword =
|
|
104
|
+
(node.type === 'word' &&
|
|
105
|
+
directionKeywords.has(node.value.toLowerCase())) ||
|
|
106
|
+
isDimensionNode(node) ||
|
|
107
|
+
isNumberNode(node) ||
|
|
108
|
+
isMathFunctionNode(node);
|
|
109
|
+
|
|
110
|
+
if (ranges[rangeIndex].start === null && isPositionKeyword) {
|
|
111
|
+
ranges[rangeIndex].start = index;
|
|
112
|
+
ranges[rangeIndex].end = index;
|
|
113
|
+
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (ranges[rangeIndex].start !== null) {
|
|
118
|
+
if (node.type === 'space') {
|
|
119
|
+
return;
|
|
120
|
+
} else if (isPositionKeyword) {
|
|
121
|
+
ranges[rangeIndex].end = index;
|
|
122
|
+
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
ranges.forEach((range) => {
|
|
131
|
+
if (range.start === null) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const nodes = parsed.nodes.slice(range.start, range.end + 1);
|
|
136
|
+
|
|
137
|
+
if (nodes.length > 3) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const firstNode = nodes[0].value.toLowerCase();
|
|
142
|
+
const secondNode =
|
|
143
|
+
nodes[2] && nodes[2].value ? nodes[2].value.toLowerCase() : null;
|
|
144
|
+
|
|
145
|
+
if (nodes.length === 1 || secondNode === 'center') {
|
|
146
|
+
if (secondNode) {
|
|
147
|
+
nodes[2].value = nodes[1].value = '';
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const map = new Map([...horizontal, ['center', center]]);
|
|
151
|
+
|
|
152
|
+
if (map.has(firstNode)) {
|
|
153
|
+
nodes[0].value = map.get(firstNode);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (firstNode === 'center' && directionKeywords.has(secondNode)) {
|
|
160
|
+
nodes[0].value = nodes[1].value = '';
|
|
161
|
+
|
|
162
|
+
if (horizontal.has(secondNode)) {
|
|
163
|
+
nodes[2].value = horizontal.get(secondNode);
|
|
164
|
+
}
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (horizontal.has(firstNode) && verticalValue.has(secondNode)) {
|
|
169
|
+
nodes[0].value = horizontal.get(firstNode);
|
|
170
|
+
nodes[2].value = verticalValue.get(secondNode);
|
|
171
|
+
|
|
172
|
+
return;
|
|
173
|
+
} else if (verticalValue.has(firstNode) && horizontal.has(secondNode)) {
|
|
174
|
+
nodes[0].value = horizontal.get(secondNode);
|
|
175
|
+
nodes[2].value = verticalValue.get(firstNode);
|
|
176
|
+
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
return parsed.toString();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function pluginCreator() {
|
|
185
|
+
return {
|
|
186
|
+
postcssPlugin: 'postcss-normalize-positions',
|
|
187
|
+
|
|
188
|
+
OnceExit(css) {
|
|
189
|
+
const cache = new Map();
|
|
190
|
+
|
|
191
|
+
css.walkDecls(
|
|
192
|
+
/^(background(-position)?|(-\w+-)?perspective-origin)$/i,
|
|
193
|
+
(decl) => {
|
|
194
|
+
const value = decl.value;
|
|
195
|
+
|
|
196
|
+
if (!value) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (cache.has(value)) {
|
|
201
|
+
decl.value = cache.get(value);
|
|
202
|
+
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const result = transform(value);
|
|
207
|
+
|
|
208
|
+
decl.value = result;
|
|
209
|
+
cache.set(value, result);
|
|
210
|
+
}
|
|
211
|
+
);
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
pluginCreator.postcss = true;
|
|
217
|
+
module.exports = pluginCreator;
|
package/CHANGELOG.md
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
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-normalize-positions@5.0.0-rc.2...postcss-normalize-positions@5.0.0) (2021-04-06)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package postcss-normalize-positions
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# [5.0.0-rc.2](https://github.com/cssnano/cssnano/compare/postcss-normalize-positions@5.0.0-rc.1...postcss-normalize-positions@5.0.0-rc.2) (2021-03-15)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package postcss-normalize-positions
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# [5.0.0-rc.1](https://github.com/cssnano/cssnano/compare/postcss-normalize-positions@5.0.0-rc.0...postcss-normalize-positions@5.0.0-rc.1) (2021-03-04)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package postcss-normalize-positions
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# 5.0.0-rc.0 (2021-02-19)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
### Bug Fixes
|
|
34
|
-
|
|
35
|
-
* **postcss-normalize-positions:** correct optimize math (`calc` and etc) and variable functions (`var` and `env`) ([#750](https://github.com/cssnano/cssnano/issues/750)) ([a81e8df](https://github.com/cssnano/cssnano/commit/a81e8dfc1ad26067d5a9efab8081072cd4b15c44))
|
|
36
|
-
* **postcss-normalize-repeat-style:** better handle css variables ([#753](https://github.com/cssnano/cssnano/issues/753)) ([7e18b0c](https://github.com/cssnano/cssnano/commit/7e18b0cbcd7cb5de58e60ab4ef1900a4d8eeefec))
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
### chore
|
|
40
|
-
|
|
41
|
-
* minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
### Features
|
|
45
|
-
|
|
46
|
-
* migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
### BREAKING CHANGES
|
|
50
|
-
|
|
51
|
-
* minimum supported `postcss` version is `8.2.1`
|
|
52
|
-
* minimum require version of node is 10.13
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
## 4.1.9 (2019-02-12)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
### Performance Improvements
|
|
60
|
-
|
|
61
|
-
* **postcss-normalize-positions:** increase perf ([#694](https://github.com/cssnano/cssnano/issues/694)) ([95639da](https://github.com/cssnano/cssnano/commit/95639da5659aef112586b9334a1e13ac0b61a525))
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
## 4.1.1 (2018-09-24)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
### Bug Fixes
|
|
69
|
-
|
|
70
|
-
* handle uppercase property and values on `postcss-normalize-positions` ([#607](https://github.com/cssnano/cssnano/issues/607)) ([c521423](https://github.com/cssnano/cssnano/commit/c521423d5939039b771ba1b12fad5fe377a6c612))
|
|
71
|
-
* **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
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser"));
|
|
9
|
-
|
|
10
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
11
|
-
|
|
12
|
-
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; }
|
|
13
|
-
|
|
14
|
-
const directionKeywords = ['top', 'right', 'bottom', 'left', 'center'];
|
|
15
|
-
const center = '50%';
|
|
16
|
-
const horizontal = {
|
|
17
|
-
right: '100%',
|
|
18
|
-
left: '0'
|
|
19
|
-
};
|
|
20
|
-
const verticalValue = {
|
|
21
|
-
bottom: '100%',
|
|
22
|
-
top: '0'
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
function isCommaNode(node) {
|
|
26
|
-
return node.type === 'div' && node.value === ',';
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function isVariableFunctionNode(node) {
|
|
30
|
-
if (node.type !== 'function') {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return ['var', 'env'].includes(node.value.toLowerCase());
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function isMathFunctionNode(node) {
|
|
38
|
-
if (node.type !== 'function') {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return ['calc', 'min', 'max', 'clamp'].includes(node.value.toLowerCase());
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function isNumberNode(node) {
|
|
46
|
-
if (node.type !== 'word') {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const value = parseFloat(node.value);
|
|
51
|
-
return !isNaN(value);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function isDimensionNode(node) {
|
|
55
|
-
if (node.type !== 'word') {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const parsed = (0, _postcssValueParser.unit)(node.value);
|
|
60
|
-
|
|
61
|
-
if (!parsed) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return parsed.unit !== '';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function transform(value) {
|
|
69
|
-
const parsed = (0, _postcssValueParser.default)(value);
|
|
70
|
-
const ranges = [];
|
|
71
|
-
let rangeIndex = 0;
|
|
72
|
-
let shouldContinue = true;
|
|
73
|
-
parsed.nodes.forEach((node, index) => {
|
|
74
|
-
// After comma (`,`) follows next background
|
|
75
|
-
if (isCommaNode(node)) {
|
|
76
|
-
rangeIndex += 1;
|
|
77
|
-
shouldContinue = true;
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (!shouldContinue) {
|
|
82
|
-
return;
|
|
83
|
-
} // After separator (`/`) follows `background-size` values
|
|
84
|
-
// Avoid them
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (node.type === 'div' && node.value === '/') {
|
|
88
|
-
shouldContinue = false;
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (!ranges[rangeIndex]) {
|
|
93
|
-
ranges[rangeIndex] = {
|
|
94
|
-
start: null,
|
|
95
|
-
end: null
|
|
96
|
-
};
|
|
97
|
-
} // Do not try to be processed `var and `env` function inside background
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (isVariableFunctionNode(node)) {
|
|
101
|
-
shouldContinue = false;
|
|
102
|
-
ranges[rangeIndex].start = null;
|
|
103
|
-
ranges[rangeIndex].end = null;
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const isPositionKeyword = node.type === 'word' && directionKeywords.includes(node.value.toLowerCase()) || isDimensionNode(node) || isNumberNode(node) || isMathFunctionNode(node);
|
|
108
|
-
|
|
109
|
-
if (ranges[rangeIndex].start === null && isPositionKeyword) {
|
|
110
|
-
ranges[rangeIndex].start = index;
|
|
111
|
-
ranges[rangeIndex].end = index;
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (ranges[rangeIndex].start !== null) {
|
|
116
|
-
if (node.type === 'space') {
|
|
117
|
-
return;
|
|
118
|
-
} else if (isPositionKeyword) {
|
|
119
|
-
ranges[rangeIndex].end = index;
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
ranges.forEach(range => {
|
|
127
|
-
if (range.start === null) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const nodes = parsed.nodes.slice(range.start, range.end + 1);
|
|
132
|
-
|
|
133
|
-
if (nodes.length > 3) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const firstNode = nodes[0].value.toLowerCase();
|
|
138
|
-
const secondNode = nodes[2] && nodes[2].value ? nodes[2].value.toLowerCase() : null;
|
|
139
|
-
|
|
140
|
-
if (nodes.length === 1 || secondNode === 'center') {
|
|
141
|
-
if (secondNode) {
|
|
142
|
-
nodes[2].value = nodes[1].value = '';
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const map = Object.assign({}, horizontal, {
|
|
146
|
-
center
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
if (Object.prototype.hasOwnProperty.call(map, firstNode)) {
|
|
150
|
-
nodes[0].value = map[firstNode];
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (firstNode === 'center' && directionKeywords.includes(secondNode)) {
|
|
157
|
-
nodes[0].value = nodes[1].value = '';
|
|
158
|
-
|
|
159
|
-
if (Object.prototype.hasOwnProperty.call(horizontal, secondNode)) {
|
|
160
|
-
nodes[2].value = horizontal[secondNode];
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (Object.prototype.hasOwnProperty.call(horizontal, firstNode) && Object.prototype.hasOwnProperty.call(verticalValue, secondNode)) {
|
|
167
|
-
nodes[0].value = horizontal[firstNode];
|
|
168
|
-
nodes[2].value = verticalValue[secondNode];
|
|
169
|
-
return;
|
|
170
|
-
} else if (Object.prototype.hasOwnProperty.call(verticalValue, firstNode) && Object.prototype.hasOwnProperty.call(horizontal, secondNode)) {
|
|
171
|
-
nodes[0].value = horizontal[secondNode];
|
|
172
|
-
nodes[2].value = verticalValue[firstNode];
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
return parsed.toString();
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function pluginCreator() {
|
|
180
|
-
return {
|
|
181
|
-
postcssPlugin: 'postcss-normalize-positions',
|
|
182
|
-
|
|
183
|
-
OnceExit(css) {
|
|
184
|
-
const cache = {};
|
|
185
|
-
css.walkDecls(/^(background(-position)?|(-\w+-)?perspective-origin)$/i, decl => {
|
|
186
|
-
const value = decl.value;
|
|
187
|
-
|
|
188
|
-
if (!value) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (cache[value]) {
|
|
193
|
-
decl.value = cache[value];
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const result = transform(value);
|
|
198
|
-
decl.value = result;
|
|
199
|
-
cache[value] = result;
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
pluginCreator.postcss = true;
|
|
207
|
-
var _default = pluginCreator;
|
|
208
|
-
exports.default = _default;
|
|
209
|
-
module.exports = exports.default;
|