postcss-normalize-positions 4.0.0-nightly.2020.9.9 → 4.0.1
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 +4 -0
- package/dist/index.js +91 -189
- package/package.json +12 -9
package/CHANGELOG.md
ADDED
package/dist/index.js
CHANGED
|
@@ -1,208 +1,110 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
7
6
|
|
|
8
|
-
var _postcss = require(
|
|
7
|
+
var _postcss = require('postcss');
|
|
9
8
|
|
|
10
|
-
var _postcssValueParser =
|
|
9
|
+
var _postcssValueParser = require('postcss-value-parser');
|
|
11
10
|
|
|
12
|
-
var
|
|
11
|
+
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
17
|
-
|
|
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; }
|
|
19
|
-
|
|
20
|
-
const directionKeywords = ['top', 'right', 'bottom', 'left', 'center'];
|
|
21
|
-
const center = '50%';
|
|
22
|
-
const horizontal = {
|
|
23
|
-
right: '100%',
|
|
24
|
-
left: '0'
|
|
25
|
-
};
|
|
26
|
-
const verticalValue = {
|
|
27
|
-
bottom: '100%',
|
|
28
|
-
top: '0'
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
function isCommaNode(node) {
|
|
32
|
-
return node.type === 'div' && node.value === ',';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function isVariableFunctionNode(node) {
|
|
36
|
-
if (node.type !== 'function') {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return ['var', 'env'].includes(node.value.toLowerCase());
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function isMathFunctionNode(node) {
|
|
44
|
-
if (node.type !== 'function') {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return ['calc', 'min', 'max', 'clamp'].includes(node.value.toLowerCase());
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function isNumberNode(node) {
|
|
52
|
-
if (node.type !== 'word') {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const value = parseFloat(node.value);
|
|
57
|
-
return !isNaN(value);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function isDimensionNode(node) {
|
|
61
|
-
if (node.type !== 'word') {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const parsed = (0, _postcssValueParser.unit)(node.value);
|
|
66
|
-
|
|
67
|
-
if (!parsed) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return parsed.unit !== '';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function transform(value) {
|
|
75
|
-
const parsed = (0, _postcssValueParser.default)(value);
|
|
76
|
-
const ranges = [];
|
|
77
|
-
let rangeIndex = 0;
|
|
78
|
-
let shouldContinue = true;
|
|
79
|
-
parsed.nodes.forEach((node, index) => {
|
|
80
|
-
// After comma (`,`) follows next background
|
|
81
|
-
if (isCommaNode(node)) {
|
|
82
|
-
rangeIndex += 1;
|
|
83
|
-
shouldContinue = true;
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
13
|
+
var _cssnanoUtilGetArguments = require('cssnano-util-get-arguments');
|
|
86
14
|
|
|
87
|
-
|
|
88
|
-
return;
|
|
89
|
-
} // After separator (`/`) follows `background-size` values
|
|
90
|
-
// Avoid them
|
|
15
|
+
var _cssnanoUtilGetArguments2 = _interopRequireDefault(_cssnanoUtilGetArguments);
|
|
91
16
|
|
|
17
|
+
var _has = require('has');
|
|
92
18
|
|
|
93
|
-
|
|
94
|
-
shouldContinue = false;
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
19
|
+
var _has2 = _interopRequireDefault(_has);
|
|
97
20
|
|
|
98
|
-
|
|
99
|
-
ranges[rangeIndex] = {
|
|
100
|
-
start: null,
|
|
101
|
-
end: null
|
|
102
|
-
};
|
|
103
|
-
} // Do not try to be processed `var and `env` function inside background
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (isVariableFunctionNode(node)) {
|
|
107
|
-
shouldContinue = false;
|
|
108
|
-
ranges[rangeIndex].start = null;
|
|
109
|
-
ranges[rangeIndex].end = null;
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const isPositionKeyword = node.type === 'word' && directionKeywords.includes(node.value.toLowerCase()) || isDimensionNode(node) || isNumberNode(node) || isMathFunctionNode(node);
|
|
114
|
-
|
|
115
|
-
if (ranges[rangeIndex].start === null && isPositionKeyword) {
|
|
116
|
-
ranges[rangeIndex].start = index;
|
|
117
|
-
ranges[rangeIndex].end = index;
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (ranges[rangeIndex].start !== null) {
|
|
122
|
-
if (node.type === 'space') {
|
|
123
|
-
return;
|
|
124
|
-
} else if (isPositionKeyword) {
|
|
125
|
-
ranges[rangeIndex].end = index;
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
ranges.forEach(range => {
|
|
133
|
-
if (range.start === null) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const nodes = parsed.nodes.slice(range.start, range.end + 1);
|
|
138
|
-
|
|
139
|
-
if (nodes.length > 3) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const firstNode = nodes[0].value.toLowerCase();
|
|
144
|
-
const secondNode = nodes[2] && nodes[2].value ? nodes[2].value.toLowerCase() : null;
|
|
145
|
-
|
|
146
|
-
if (nodes.length === 1 || secondNode === 'center') {
|
|
147
|
-
if (secondNode) {
|
|
148
|
-
nodes[2].value = nodes[1].value = '';
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const map = Object.assign({}, horizontal, {
|
|
152
|
-
center
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
if ((0, _has.default)(map, firstNode)) {
|
|
156
|
-
nodes[0].value = map[firstNode];
|
|
157
|
-
}
|
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
158
22
|
|
|
159
|
-
|
|
160
|
-
}
|
|
23
|
+
const directions = ['top', 'right', 'bottom', 'left', 'center'];
|
|
161
24
|
|
|
162
|
-
|
|
163
|
-
nodes[0].value = nodes[1].value = '';
|
|
25
|
+
const center = '50%';
|
|
164
26
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
27
|
+
const horizontal = {
|
|
28
|
+
right: '100%',
|
|
29
|
+
left: '0'
|
|
30
|
+
};
|
|
168
31
|
|
|
169
|
-
|
|
170
|
-
|
|
32
|
+
const vertical = {
|
|
33
|
+
bottom: '100%',
|
|
34
|
+
top: '0'
|
|
35
|
+
};
|
|
171
36
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
37
|
+
function transform(decl) {
|
|
38
|
+
const values = (0, _postcssValueParser2.default)(decl.value);
|
|
39
|
+
const args = (0, _cssnanoUtilGetArguments2.default)(values);
|
|
40
|
+
const relevant = [];
|
|
41
|
+
args.forEach(arg => {
|
|
42
|
+
relevant.push({
|
|
43
|
+
start: null,
|
|
44
|
+
end: null
|
|
45
|
+
});
|
|
46
|
+
arg.forEach((part, index) => {
|
|
47
|
+
const isPosition = ~directions.indexOf(part.value.toLowerCase()) || (0, _postcssValueParser.unit)(part.value);
|
|
48
|
+
const len = relevant.length - 1;
|
|
49
|
+
if (relevant[len].start === null && isPosition) {
|
|
50
|
+
relevant[len].start = index;
|
|
51
|
+
relevant[len].end = index;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (relevant[len].start !== null) {
|
|
55
|
+
if (part.type === 'space') {
|
|
56
|
+
return;
|
|
57
|
+
} else if (isPosition) {
|
|
58
|
+
relevant[len].end = index;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
relevant.forEach((range, index) => {
|
|
66
|
+
if (range.start === null) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const position = args[index].slice(range.start, range.end + 1);
|
|
70
|
+
if (position.length > 3) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const firstValue = position[0].value.toLowerCase();
|
|
74
|
+
const secondValue = position[2] && position[2].value ? position[2].value.toLowerCase() : null;
|
|
75
|
+
if (position.length === 1 || secondValue === 'center') {
|
|
76
|
+
if (secondValue) {
|
|
77
|
+
position[2].value = position[1].value = '';
|
|
78
|
+
}
|
|
79
|
+
const map = Object.assign({}, horizontal, {
|
|
80
|
+
center
|
|
81
|
+
});
|
|
82
|
+
if ((0, _has2.default)(map, firstValue)) {
|
|
83
|
+
position[0].value = map[firstValue];
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (firstValue === 'center' && ~directions.indexOf(secondValue)) {
|
|
88
|
+
position[0].value = position[1].value = '';
|
|
89
|
+
if ((0, _has2.default)(horizontal, secondValue)) {
|
|
90
|
+
position[2].value = horizontal[secondValue];
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if ((0, _has2.default)(horizontal, firstValue) && (0, _has2.default)(vertical, secondValue)) {
|
|
95
|
+
position[0].value = horizontal[firstValue];
|
|
96
|
+
position[2].value = vertical[secondValue];
|
|
97
|
+
return;
|
|
98
|
+
} else if ((0, _has2.default)(vertical, firstValue) && (0, _has2.default)(horizontal, secondValue)) {
|
|
99
|
+
position[0].value = horizontal[secondValue];
|
|
100
|
+
position[2].value = vertical[firstValue];
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
decl.value = values.toString();
|
|
183
105
|
}
|
|
184
106
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const cache = {};
|
|
188
|
-
css.walkDecls(/^(background(-position)?|(-\w+-)?perspective-origin)$/i, decl => {
|
|
189
|
-
const value = decl.value;
|
|
190
|
-
|
|
191
|
-
if (!value) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (cache[value]) {
|
|
196
|
-
decl.value = cache[value];
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const result = transform(value);
|
|
201
|
-
decl.value = result;
|
|
202
|
-
cache[value] = result;
|
|
203
|
-
});
|
|
204
|
-
};
|
|
107
|
+
exports.default = (0, _postcss.plugin)('postcss-normalize-positions', () => {
|
|
108
|
+
return css => css.walkDecls(/^(background(-position)?|(-webkit-)?perspective-origin)$/i, transform);
|
|
205
109
|
});
|
|
206
|
-
|
|
207
|
-
exports.default = _default;
|
|
208
|
-
module.exports = exports.default;
|
|
110
|
+
module.exports = exports['default'];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-normalize-positions",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Normalize keyword values for position into length values.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
"LICENSE-MIT"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
-
"
|
|
12
|
-
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
|
|
13
|
-
"prepublish": ""
|
|
11
|
+
"prepublish": "cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/"
|
|
14
12
|
},
|
|
15
13
|
"keywords": [
|
|
16
14
|
"css",
|
|
@@ -18,6 +16,10 @@
|
|
|
18
16
|
"postcss-plugin"
|
|
19
17
|
],
|
|
20
18
|
"license": "MIT",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"babel-cli": "^6.0.0",
|
|
21
|
+
"cross-env": "^5.0.0"
|
|
22
|
+
},
|
|
21
23
|
"homepage": "https://github.com/cssnano/cssnano",
|
|
22
24
|
"author": {
|
|
23
25
|
"name": "Ben Briggs",
|
|
@@ -26,14 +28,15 @@
|
|
|
26
28
|
},
|
|
27
29
|
"repository": "cssnano/cssnano",
|
|
28
30
|
"dependencies": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"postcss
|
|
31
|
+
"cssnano-util-get-arguments": "^4.0.0",
|
|
32
|
+
"has": "^1.0.0",
|
|
33
|
+
"postcss": "^7.0.0",
|
|
34
|
+
"postcss-value-parser": "^3.0.0"
|
|
32
35
|
},
|
|
33
36
|
"bugs": {
|
|
34
37
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
35
38
|
},
|
|
36
39
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
40
|
+
"node": ">=6.9.0"
|
|
38
41
|
}
|
|
39
|
-
}
|
|
42
|
+
}
|