postcss-calc 11.1.0 → 11.1.2
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 +38 -8
- package/package.json +6 -5
- package/src/index.js +16 -4
- package/src/lib/convertUnits.js +15 -1
- package/src/lib/node.js +22 -18
- package/src/lib/opaque.js +40 -0
- package/src/lib/parser.js +381 -200
- package/src/lib/serialize.js +49 -16
- package/src/lib/simplify/abs.js +1 -1
- package/src/lib/simplify/bucket.js +18 -23
- package/src/lib/simplify/call.js +8 -1
- package/src/lib/simplify/product.js +7 -4
- package/src/lib/simplify/sum.js +8 -5
- package/src/lib/tokenizer.js +6 -135
- package/src/reduce.js +22 -14
- package/types/lib/convertUnits.d.ts +8 -1
- package/types/lib/node.d.ts +12 -6
- package/types/lib/opaque.d.ts +15 -0
- package/types/lib/parser.d.ts +40 -36
- package/types/lib/serialize.d.ts +4 -0
- package/types/lib/simplify/bucket.d.ts +2 -2
- package/types/lib/tokenizer.d.ts +3 -32
- package/types/reduce.d.ts +4 -1
package/types/lib/parser.d.ts
CHANGED
|
@@ -1,51 +1,55 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export type TokenType = import('./tokenizer.js').TokenType;
|
|
1
|
+
export type CSSToken = import('@csstools/css-tokenizer').CSSToken;
|
|
3
2
|
export type Node = import('./node.js').Node;
|
|
3
|
+
export type Component = string | Node | Component[];
|
|
4
|
+
export type Token = {
|
|
5
|
+
type: 'number' | 'dimension' | 'ident' | 'function' | 'punct' | 'eof';
|
|
6
|
+
value: string | number;
|
|
7
|
+
raw: string;
|
|
8
|
+
unit?: string;
|
|
9
|
+
rawUnit?: string;
|
|
10
|
+
signCharacter?: '+' | '-';
|
|
11
|
+
pos: number;
|
|
12
|
+
ws: boolean;
|
|
13
|
+
};
|
|
4
14
|
export type PrefixParselet = (p: Parser, token: Token) => Node;
|
|
15
|
+
/** Bounded cursor that skips trivia but records whether it preceded a token. */
|
|
5
16
|
declare class Parser {
|
|
6
|
-
|
|
7
|
-
i;
|
|
8
|
-
/** @private @readonly */
|
|
9
|
-
tokens;
|
|
17
|
+
#private;
|
|
10
18
|
/**
|
|
11
|
-
* @param {
|
|
19
|
+
* @param {CSSToken[]} tokens
|
|
20
|
+
* @param {number} start
|
|
21
|
+
* @param {number} end
|
|
22
|
+
* @param {Map<number, number>} [ends]
|
|
12
23
|
*/
|
|
13
|
-
constructor(tokens:
|
|
24
|
+
constructor(tokens: CSSToken[], start: number, end: number, ends?: Map<number, number>);
|
|
25
|
+
/** @return {Map<number, number>} */
|
|
26
|
+
get ends(): Map<number, number>;
|
|
27
|
+
/** @return {number} */
|
|
28
|
+
eofPosition(): number;
|
|
29
|
+
/** @return {Token} */
|
|
30
|
+
read(): Token;
|
|
14
31
|
/** @return {Token} */
|
|
15
32
|
peek(): Token;
|
|
16
33
|
/** @return {Token} */
|
|
17
34
|
next(): Token;
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
35
|
+
/** @return {{start: number, close: number, tokens: CSSToken[], ends: Map<number, number>}} */
|
|
36
|
+
functionRange(): {
|
|
37
|
+
start: number;
|
|
38
|
+
close: number;
|
|
39
|
+
tokens: CSSToken[];
|
|
40
|
+
ends: Map<number, number>;
|
|
41
|
+
};
|
|
42
|
+
/** @param {number} index */
|
|
43
|
+
consumeThrough(index: number): void;
|
|
44
|
+
/** @param {string} value @param {string} [value2] @return {boolean} */
|
|
29
45
|
isPunct(value: string, value2?: string): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* @param {string} value
|
|
32
|
-
* @return {boolean}
|
|
33
|
-
*/
|
|
46
|
+
/** @param {string} value @return {boolean} */
|
|
34
47
|
matchPunct(value: string): boolean;
|
|
35
|
-
/**
|
|
36
|
-
* @param {string} value
|
|
37
|
-
* @return {Token}
|
|
38
|
-
*/
|
|
48
|
+
/** @param {string} value @return {Token} */
|
|
39
49
|
expectPunct(value: string): Token;
|
|
40
|
-
/**
|
|
41
|
-
* @param {number} [minBp]
|
|
42
|
-
* @return {Node}
|
|
43
|
-
*/
|
|
50
|
+
/** @param {number} [minBp] @return {Node} */
|
|
44
51
|
parseExpr(minBp?: number): Node;
|
|
45
52
|
}
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
* @return {Node}
|
|
49
|
-
*/
|
|
50
|
-
declare function parse(tokens: Token[]): Node;
|
|
53
|
+
/** @param {CSSToken[]} tokens @param {number} [start] @param {number} [end] @return {Node} */
|
|
54
|
+
declare function parse(tokens: CSSToken[], start?: number, end?: number): Node;
|
|
51
55
|
export { parse };
|
package/types/lib/serialize.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ export type SerializeOptions = {
|
|
|
11
11
|
* Wrapper name to use when `calc()` is needed. Default `'calc'`.
|
|
12
12
|
*/
|
|
13
13
|
calcName?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Serialize finite negative scalars without a wrapper. Internal selector-only mode.
|
|
16
|
+
*/
|
|
17
|
+
unwrapSingleNegativeNumber?: boolean;
|
|
14
18
|
};
|
|
15
19
|
/**
|
|
16
20
|
* @param {Node} node
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
export type UnitBucket = {
|
|
2
2
|
unit: string;
|
|
3
|
+
rawUnit?: string;
|
|
3
4
|
total: number;
|
|
4
5
|
/**
|
|
5
6
|
* largest |term| accumulated into `total`, for noise detection
|
|
6
7
|
*/
|
|
7
8
|
scale: number;
|
|
8
9
|
base: import('../convertUnits.js').BaseType | null;
|
|
9
|
-
order: number;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* @typedef {object} UnitBucket
|
|
13
13
|
* @property {string} unit
|
|
14
|
+
* @property {string} [rawUnit]
|
|
14
15
|
* @property {number} total
|
|
15
16
|
* @property {number} scale largest |term| accumulated into `total`, for noise detection
|
|
16
17
|
* @property {import('../convertUnits.js').BaseType | null} base
|
|
17
|
-
* @property {number} order
|
|
18
18
|
*/
|
|
19
19
|
/** Mutates `buckets` in place — totals of survivor buckets accumulate the
|
|
20
20
|
* converted values of merged neighbors. Caller must not reuse the input.
|
package/types/lib/tokenizer.d.ts
CHANGED
|
@@ -1,32 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: string;
|
|
5
|
-
/**
|
|
6
|
-
* Present on `dimension` tokens; `%` for percentages.
|
|
7
|
-
*/
|
|
8
|
-
unit?: string;
|
|
9
|
-
pos: number;
|
|
10
|
-
/**
|
|
11
|
-
* Whitespace immediately before — drives the §10.1 `+`/`-` rule.
|
|
12
|
-
*/
|
|
13
|
-
ws: boolean;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* @param {string} input
|
|
17
|
-
* @return {Token[]}
|
|
18
|
-
*/
|
|
19
|
-
declare function tokenize(input: string): Token[];
|
|
20
|
-
/**
|
|
21
|
-
* Convert a slice of an existing CSS token stream into the token subset used
|
|
22
|
-
* by the calculation parser. Token positions remain relative to the original
|
|
23
|
-
* source text, which keeps parse errors useful to adapter callers.
|
|
24
|
-
*
|
|
25
|
-
* @param {import('@csstools/css-tokenizer').CSSToken[]} cssTokens
|
|
26
|
-
* @param {number} eofPosition
|
|
27
|
-
* @param {number} [start]
|
|
28
|
-
* @param {number} [end]
|
|
29
|
-
* @return {Token[]}
|
|
30
|
-
*/
|
|
31
|
-
declare function tokenizeTokens(cssTokens: import('@csstools/css-tokenizer').CSSToken[], eofPosition: number, start?: number, end?: number): Token[];
|
|
32
|
-
export { tokenize, tokenizeTokens };
|
|
1
|
+
/** @param {string} input @return {import('@csstools/css-tokenizer').CSSToken[]} */
|
|
2
|
+
declare function tokenize(input: string): import('@csstools/css-tokenizer').CSSToken[];
|
|
3
|
+
export { tokenize };
|
package/types/reduce.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ import { hasPotentialMathFunction, QUICK_MATH_TEST } from './lib/simplify/call.j
|
|
|
2
2
|
export type ReduceCalcOptions = {
|
|
3
3
|
precision?: number | false;
|
|
4
4
|
warnWhenCannotResolve?: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Serialize finite negative results without a `calc()` wrapper. Defaults to `false`.
|
|
7
|
+
*/
|
|
8
|
+
unwrapSingleNegativeNumber?: boolean;
|
|
5
9
|
/**
|
|
6
10
|
* Invoked when parse/simplify throws.
|
|
7
11
|
*/
|
|
@@ -23,7 +27,6 @@ export type Replacement = {
|
|
|
23
27
|
end: number;
|
|
24
28
|
node: import('./lib/node.js').Node;
|
|
25
29
|
calcName: string;
|
|
26
|
-
matchedName: string;
|
|
27
30
|
};
|
|
28
31
|
/**
|
|
29
32
|
* Simplify every supported CSS math function in a component-value string.
|