postcss-calc 11.0.0 → 11.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/package.json +5 -5
- package/src/lib/serialize.js +21 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-calc",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "PostCSS plugin to reduce calc()",
|
|
6
6
|
"keywords": [
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
"devEngines": {
|
|
35
35
|
"packageManager": {
|
|
36
36
|
"name": "pnpm",
|
|
37
|
-
"version": "11.
|
|
37
|
+
"version": "11.24.0"
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@csstools/css-calc": "^3.3.0",
|
|
42
42
|
"@rmenke/css-tokenizer-tests": "^1.2.0",
|
|
43
|
-
"@types/node": "^26.
|
|
43
|
+
"@types/node": "^26.3.0",
|
|
44
44
|
"fast-check": "^4.9.0",
|
|
45
|
-
"oxfmt": "^0.
|
|
46
|
-
"oxlint": "^1.
|
|
45
|
+
"oxfmt": "^0.65.0",
|
|
46
|
+
"oxlint": "^1.80.0",
|
|
47
47
|
"postcss": "^8.5.26",
|
|
48
48
|
"typescript": "~7.0.2"
|
|
49
49
|
},
|
package/src/lib/serialize.js
CHANGED
|
@@ -59,6 +59,25 @@ function degenerateKeyword(v) {
|
|
|
59
59
|
return v > 0 ? 'infinity' : '-infinity';
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Serialize a finite CSS number. CSS numbers may omit the zero before a
|
|
64
|
+
* fractional value between -1 and 1 (`.5`, `-.5`). Scientific notation is
|
|
65
|
+
* left untouched because it already has no leading zero to remove.
|
|
66
|
+
*
|
|
67
|
+
* @param {number} v
|
|
68
|
+
* @return {string}
|
|
69
|
+
*/
|
|
70
|
+
function serializeNumber(v) {
|
|
71
|
+
const text = String(v);
|
|
72
|
+
if (text.startsWith('0.')) {
|
|
73
|
+
return text.slice(1);
|
|
74
|
+
}
|
|
75
|
+
if (text.startsWith('-0.')) {
|
|
76
|
+
return `-${text.slice(2)}`;
|
|
77
|
+
}
|
|
78
|
+
return text;
|
|
79
|
+
}
|
|
80
|
+
|
|
62
81
|
/**
|
|
63
82
|
* @param {Node} node
|
|
64
83
|
* @param {SerializeOptions} [opts]
|
|
@@ -127,7 +146,7 @@ function serializeExpr(node, prec) {
|
|
|
127
146
|
if (isDegenerate(node.value)) {
|
|
128
147
|
return degenerateKeyword(node.value);
|
|
129
148
|
}
|
|
130
|
-
return
|
|
149
|
+
return serializeNumber(round(node.value, prec));
|
|
131
150
|
case 'Dim':
|
|
132
151
|
if (isDegenerate(node.value)) {
|
|
133
152
|
// Nested degenerate Dim wraps in calc() so the `<kw> * 1<unit>` form
|
|
@@ -135,7 +154,7 @@ function serializeExpr(node, prec) {
|
|
|
135
154
|
// inside a Product — `0 * Dim(Infinity, px)` would re-fold as NaN.
|
|
136
155
|
return `calc(${degenerateKeyword(node.value)} * 1${node.unit})`;
|
|
137
156
|
}
|
|
138
|
-
return `${round(node.value, prec)}${node.unit}`;
|
|
157
|
+
return `${serializeNumber(round(node.value, prec))}${node.unit}`;
|
|
139
158
|
case 'Ident':
|
|
140
159
|
return node.name;
|
|
141
160
|
case 'Call': {
|