postcss-normalize-positions 5.0.4 → 5.1.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.
- package/package.json +4 -2
- package/src/index.js +46 -15
- package/types/index.d.ts +9 -0
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-normalize-positions",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Normalize keyword values for position into length values.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
6
7
|
"files": [
|
|
7
8
|
"src",
|
|
8
|
-
"LICENSE-MIT"
|
|
9
|
+
"LICENSE-MIT",
|
|
10
|
+
"types"
|
|
9
11
|
],
|
|
10
12
|
"keywords": [
|
|
11
13
|
"css",
|
package/src/index.js
CHANGED
|
@@ -14,10 +14,18 @@ const verticalValue = new Map([
|
|
|
14
14
|
]);
|
|
15
15
|
const mathFunctions = new Set(['calc', 'min', 'max', 'clamp']);
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @param {valueParser.Node} node
|
|
19
|
+
* @return {boolean}
|
|
20
|
+
*/
|
|
17
21
|
function isCommaNode(node) {
|
|
18
22
|
return node.type === 'div' && node.value === ',';
|
|
19
23
|
}
|
|
20
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @param {valueParser.Node} node
|
|
27
|
+
* @return {boolean}
|
|
28
|
+
*/
|
|
21
29
|
function isVariableFunctionNode(node) {
|
|
22
30
|
if (node.type !== 'function') {
|
|
23
31
|
return false;
|
|
@@ -26,6 +34,10 @@ function isVariableFunctionNode(node) {
|
|
|
26
34
|
return ['var', 'env'].includes(node.value.toLowerCase());
|
|
27
35
|
}
|
|
28
36
|
|
|
37
|
+
/**
|
|
38
|
+
* @param {valueParser.Node} node
|
|
39
|
+
* @return {boolean}
|
|
40
|
+
*/
|
|
29
41
|
function isMathFunctionNode(node) {
|
|
30
42
|
if (node.type !== 'function') {
|
|
31
43
|
return false;
|
|
@@ -33,6 +45,10 @@ function isMathFunctionNode(node) {
|
|
|
33
45
|
return mathFunctions.has(node.value.toLowerCase());
|
|
34
46
|
}
|
|
35
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @param {valueParser.Node} node
|
|
50
|
+
* @return {boolean}
|
|
51
|
+
*/
|
|
36
52
|
function isNumberNode(node) {
|
|
37
53
|
if (node.type !== 'word') {
|
|
38
54
|
return false;
|
|
@@ -43,6 +59,10 @@ function isNumberNode(node) {
|
|
|
43
59
|
return !isNaN(value);
|
|
44
60
|
}
|
|
45
61
|
|
|
62
|
+
/**
|
|
63
|
+
* @param {valueParser.Node} node
|
|
64
|
+
* @return {boolean}
|
|
65
|
+
*/
|
|
46
66
|
function isDimensionNode(node) {
|
|
47
67
|
if (node.type !== 'word') {
|
|
48
68
|
return false;
|
|
@@ -57,8 +77,13 @@ function isDimensionNode(node) {
|
|
|
57
77
|
return parsed.unit !== '';
|
|
58
78
|
}
|
|
59
79
|
|
|
80
|
+
/**
|
|
81
|
+
* @param {string} value
|
|
82
|
+
* @return {string}
|
|
83
|
+
*/
|
|
60
84
|
function transform(value) {
|
|
61
85
|
const parsed = valueParser(value);
|
|
86
|
+
/** @type {({start: number, end: number} | {start: null, end: null})[]} */
|
|
62
87
|
const ranges = [];
|
|
63
88
|
let rangeIndex = 0;
|
|
64
89
|
let shouldContinue = true;
|
|
@@ -150,37 +175,43 @@ function transform(value) {
|
|
|
150
175
|
const map = new Map([...horizontal, ['center', center]]);
|
|
151
176
|
|
|
152
177
|
if (map.has(firstNode)) {
|
|
153
|
-
nodes[0].value = map.get(firstNode);
|
|
178
|
+
nodes[0].value = /** @type {string}*/ (map.get(firstNode));
|
|
154
179
|
}
|
|
155
180
|
|
|
156
181
|
return;
|
|
157
182
|
}
|
|
158
183
|
|
|
159
|
-
if (
|
|
160
|
-
|
|
184
|
+
if (secondNode !== null) {
|
|
185
|
+
if (firstNode === 'center' && directionKeywords.has(secondNode)) {
|
|
186
|
+
nodes[0].value = nodes[1].value = '';
|
|
161
187
|
|
|
162
|
-
|
|
163
|
-
|
|
188
|
+
if (horizontal.has(secondNode)) {
|
|
189
|
+
nodes[2].value = /** @type {string} */ (horizontal.get(secondNode));
|
|
190
|
+
}
|
|
191
|
+
return;
|
|
164
192
|
}
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
193
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
194
|
+
if (horizontal.has(firstNode) && verticalValue.has(secondNode)) {
|
|
195
|
+
nodes[0].value = /** @type {string} */ (horizontal.get(firstNode));
|
|
196
|
+
nodes[2].value = /** @type {string} */ (verticalValue.get(secondNode));
|
|
171
197
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
198
|
+
return;
|
|
199
|
+
} else if (verticalValue.has(firstNode) && horizontal.has(secondNode)) {
|
|
200
|
+
nodes[0].value = /** @type {string} */ (horizontal.get(secondNode));
|
|
201
|
+
nodes[2].value = /** @type {string} */ (verticalValue.get(firstNode));
|
|
176
202
|
|
|
177
|
-
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
178
205
|
}
|
|
179
206
|
});
|
|
180
207
|
|
|
181
208
|
return parsed.toString();
|
|
182
209
|
}
|
|
183
210
|
|
|
211
|
+
/**
|
|
212
|
+
* @type {import('postcss').PluginCreator<void>}
|
|
213
|
+
* @return {import('postcss').Plugin}
|
|
214
|
+
*/
|
|
184
215
|
function pluginCreator() {
|
|
185
216
|
return {
|
|
186
217
|
postcssPlugin: 'postcss-normalize-positions',
|
package/types/index.d.ts
ADDED