postcss-calc 11.1.2 → 11.2.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/README.md +40 -18
- package/package.json +18 -14
- package/src/index.js +8 -5
- package/src/lib/analyze.js +272 -0
- package/src/lib/block-index.js +118 -0
- package/src/lib/compile.js +80 -0
- package/src/lib/functions.js +394 -0
- package/src/lib/limits.js +49 -0
- package/src/lib/node.js +63 -21
- package/src/lib/opaque.js +12 -32
- package/src/lib/parser.js +373 -328
- package/src/lib/print.js +75 -0
- package/src/lib/regex.js +4 -0
- package/src/lib/scan.js +61 -0
- package/src/lib/serialize.js +626 -223
- package/src/lib/simplify/call.js +5 -98
- package/src/lib/simplify/round.js +4 -4
- package/src/lib/simplify/sum.js +14 -5
- package/src/lib/simplify.js +20 -5
- package/src/reduce.js +46 -115
- package/types/index.d.ts +4 -0
- package/types/lib/analyze.d.ts +45 -0
- package/types/lib/block-index.d.ts +35 -0
- package/types/lib/calculation-type.d.ts +18 -0
- package/types/lib/compile.d.ts +37 -0
- package/types/lib/functions.d.ts +58 -0
- package/types/lib/limits.d.ts +8 -0
- package/types/lib/node.d.ts +19 -3
- package/types/lib/opaque.d.ts +8 -14
- package/types/lib/parser.d.ts +42 -48
- package/types/lib/print.d.ts +16 -0
- package/types/lib/regex.d.ts +2 -0
- package/types/lib/scan.d.ts +35 -0
- package/types/lib/serialize.d.ts +19 -2
- package/types/lib/simplify/call.d.ts +4 -18
- package/types/lib/simplify/round.d.ts +3 -1
- package/types/lib/simplify.d.ts +5 -2
- package/types/reduce.d.ts +47 -6
- package/src/lib/tokenizer.js +0 -10
- package/types/lib/tokenizer.d.ts +0 -3
package/src/lib/opaque.js
CHANGED
|
@@ -1,40 +1,20 @@
|
|
|
1
|
-
// Private metadata for opaque function contents (including var() fallbacks).
|
|
2
|
-
// Keeping it in a WeakMap means the public calculation AST remains unchanged.
|
|
3
1
|
/** @typedef {import('./node.js').Node} Node */
|
|
4
|
-
/** @typedef {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
components.set(node, tree);
|
|
10
|
-
return node;
|
|
11
|
-
}
|
|
12
|
-
/** @param {Extract<Node, {type: 'Call'}>} node */
|
|
13
|
-
function getComponents(node) {
|
|
14
|
-
return components.get(node);
|
|
15
|
-
}
|
|
16
|
-
/** @param {Component[]} tree @param {(node: Node) => Node} simplify @return {Component[]} */
|
|
17
|
-
function simplifyComponents(tree, simplify) {
|
|
18
|
-
return tree.map((part) => {
|
|
2
|
+
/** @typedef {import('./node.js').OpaqueComponent} OpaqueComponent */
|
|
3
|
+
|
|
4
|
+
/** @param {OpaqueComponent[]} components @param {(node: Node) => Node} simplify @return {OpaqueComponent[]} */
|
|
5
|
+
function simplifyComponents(components, simplify) {
|
|
6
|
+
return components.map((part) => {
|
|
19
7
|
if (typeof part === 'string') return part;
|
|
20
8
|
if (Array.isArray(part)) return simplifyComponents(part, simplify);
|
|
21
9
|
return simplify(part);
|
|
22
10
|
});
|
|
23
11
|
}
|
|
24
|
-
/** @param {
|
|
25
|
-
function serializeComponents(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
else
|
|
30
|
-
result += serializeComponents(part, serialize);
|
|
31
|
-
else result += serialize(part);
|
|
12
|
+
/** @param {OpaqueComponent[]} components @param {string[]} buffer @param {(node: Node, buffer: string[]) => void} serialize @return {void} */
|
|
13
|
+
function serializeComponents(components, buffer, serialize) {
|
|
14
|
+
for (const part of components) {
|
|
15
|
+
if (typeof part === 'string') buffer.push(part);
|
|
16
|
+
else if (Array.isArray(part)) serializeComponents(part, buffer, serialize);
|
|
17
|
+
else serialize(part, buffer);
|
|
32
18
|
}
|
|
33
|
-
return result;
|
|
34
19
|
}
|
|
35
|
-
export {
|
|
36
|
-
getComponents,
|
|
37
|
-
setComponents,
|
|
38
|
-
simplifyComponents,
|
|
39
|
-
serializeComponents,
|
|
40
|
-
};
|
|
20
|
+
export { simplifyComponents, serializeComponents };
|