Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
"type": "git",
"url": "https://github.com/postcss/postcss-calc.git"
},
"exports": "./src/index.js",
"types": "types/index.d.ts",
"exports": {
"types": "./types/index.d.ts",
"default": "./src/index.js"
},
"files": [
"src",
"types",
Expand All @@ -35,15 +37,12 @@
"devDependencies": {
"@csstools/css-calc": "^3.2.1",
"@rmenke/css-tokenizer-tests": "^1.2.0",
"@stryker-mutator/core": "^9.6.1",
"@stryker-mutator/tap-runner": "^9.6.1",
"@stryker-mutator/typescript-checker": "^9.6.1",
"@types/node": "^26.1.1",
"fast-check": "^4.9.0",
"oxfmt": "^0.61.0",
"oxlint": "^1.76.0",
"postcss": "^8.5.19",
"typescript": "~6.0.3"
"typescript": "~7.0.2"
},
"dependencies": {
"@csstools/css-tokenizer": "^4.0.0",
Expand Down
1,742 changes: 189 additions & 1,553 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ function transformValue(value, options, result, item) {
}

/**
* @type {import('postcss').PluginCreator<PluginOptions>}
* @param {PluginOptions} [opts]
* @return {import('postcss').Plugin}
*/
Expand All @@ -121,6 +120,10 @@ function pluginCreator(opts) {

return {
postcssPlugin: 'postcss-calc',
/**
* @param {import('postcss').Root} css
* @param {import('postcss').Helpers} helpers
*/
OnceExit(css, { result }) {
css.walk((node) => {
if (node.type === 'decl') {
Expand Down Expand Up @@ -162,4 +165,6 @@ function pluginCreator(opts) {

pluginCreator.postcss = true;

module.exports = pluginCreator;
module.exports = /** @type import('postcss').PluginCreator<PluginOptions>*/ (
pluginCreator
);
29 changes: 0 additions & 29 deletions stryker.conf.mjs

This file was deleted.

29 changes: 10 additions & 19 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
export = pluginCreator;
/**
* @type {import('postcss').PluginCreator<PluginOptions>}
* @param {PluginOptions} [opts]
* @return {import('postcss').Plugin}
*/
declare function pluginCreator(opts?: PluginOptions): import("postcss").Plugin;
declare namespace pluginCreator {
export { postcss, PluginOptions, ResolvedOptions };
}
declare var postcss: true;
type PluginOptions = {
precision?: number | false | undefined;
preserve?: boolean | undefined;
warnWhenCannotResolve?: boolean | undefined;
mediaQueries?: boolean | undefined;
selectors?: boolean | undefined;
declare const _exports: import("postcss").PluginCreator<PluginOptions>;
export = _exports;
export type PluginOptions = {
precision?: number | false;
preserve?: boolean;
warnWhenCannotResolve?: boolean;
mediaQueries?: boolean;
selectors?: boolean;
/**
* Invoked when parse/simplify throws. Replaces the default `result.warn`.
*/
onParseError?: ((error: Error, input: string) => void) | undefined;
onParseError?: (error: Error, input: string) => void;
};
type ResolvedOptions = Required<Omit<PluginOptions, "onParseError">> & Pick<PluginOptions, "onParseError">;
export type ResolvedOptions = Required<Omit<PluginOptions, 'onParseError'>> & Pick<PluginOptions, 'onParseError'>;
42 changes: 23 additions & 19 deletions types/lib/node.d.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
declare const _exports: {
num: typeof num;
dim: typeof dim;
ident: typeof ident;
call: typeof call;
mkSum: typeof mkSum;
mkProduct: typeof mkProduct;
negate: typeof negate;
};
export = _exports;
export type Num = {
type: "Num";
type: 'Num';
value: number;
};
export type Dim = {
type: "Dim";
type: 'Dim';
value: number;
unit: string;
};
export type Ident = {
type: "Ident";
type: 'Ident';
name: string;
};
export type Call = {
type: "Call";
type: 'Call';
name: string;
args: Node[];
};
/**
* Sign is always +1 when node is Num or Dim.
*/
export type SumTerm = {
sign: 1 | -1;
node: Node;
};
export type Sum = {
type: "Sum";
type: 'Sum';
terms: SumTerm[];
};
/**
* exponent +1 = numerator, -1 = denominator.
*/
export type ProductFactor = {
exponent: 1 | -1;
node: Node;
};
export type Product = {
type: "Product";
type: 'Product';
factors: ProductFactor[];
};
export type Node = Num | Dim | Ident | Call | Sum | Product;
Expand All @@ -54,37 +58,37 @@ export type Node = Num | Dim | Ident | Call | Sum | Product;
* @param {number} value
* @return {Num}
*/
export function num(value: number): Num;
declare function num(value: number): Num;
/**
* @param {number} value
* @param {string} unit
* @return {Dim}
*/
export function dim(value: number, unit: string): Dim;
declare function dim(value: number, unit: string): Dim;
/**
* @param {string} name
* @return {Ident}
*/
export function ident(name: string): Ident;
declare function ident(name: string): Ident;
/**
* @param {string} name
* @param {Node[]} args
* @return {Call}
*/
export function call(name: string, args: Node[]): Call;
declare function call(name: string, args: Node[]): Call;
/**
* @param {SumTerm[]} rawTerms
* @return {Node}
*/
export function mkSum(rawTerms: SumTerm[]): Node;
declare function mkSum(rawTerms: SumTerm[]): Node;
/**
* @param {ProductFactor[]} rawFactors
* @return {Node}
*/
export function mkProduct(rawFactors: ProductFactor[]): Node;
declare function mkProduct(rawFactors: ProductFactor[]): Node;
/**
* Negate any node, preserving canonical form.
* @param {Node} node
* @return {Node}
*/
export function negate(node: Node): Node;
declare function negate(node: Node): Node;
29 changes: 16 additions & 13 deletions types/lib/parser.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
export type Token = import("./tokenizer.js").Token;
export type TokenType = import("./tokenizer.js").TokenType;
export type Node = import("./node.js").Node;
declare const _exports: {
parse: typeof parse;
};
export = _exports;
export type Token = import('./tokenizer.js').Token;
export type TokenType = import('./tokenizer.js').TokenType;
export type Node = import('./node.js').Node;
export type PrefixParselet = (p: Parser, token: Token) => Node;
export type InfixParselet = {
lbp: number;
parse: (p: Parser, left: Node, token: Token) => Node;
};
/**
* @param {Token[]} tokens
* @return {Node}
*/
export function parse(tokens: Token[]): Node;
declare class Parser {
/** @private */
i;
/** @private @readonly */
tokens;
/**
* @param {Token[]} tokens
*/
constructor(tokens: Token[]);
/** @private */
private i;
/** @private @readonly */
private readonly tokens;
/** @return {Token} */
peek(): Token;
/** @return {Token} */
Expand All @@ -36,4 +35,8 @@ declare class Parser {
*/
parseExpr(minBp?: number): Node;
}
export {};
/**
* @param {Token[]} tokens
* @return {Node}
*/
declare function parse(tokens: Token[]): Node;
18 changes: 11 additions & 7 deletions types/lib/serialize.d.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
export type Node = import("./node.js").Node;
export type Sum = import("./node.js").Sum;
export type Product = import("./node.js").Product;
export type ProductFactor = import("./node.js").ProductFactor;
declare const _exports: {
serialize: typeof serialize;
};
export = _exports;
export type Node = import('./node.js').Node;
export type Sum = import('./node.js').Sum;
export type Product = import('./node.js').Product;
export type ProductFactor = import('./node.js').ProductFactor;
export type SerializeOptions = {
/**
* Decimal places for numbers. `false` disables rounding. Default 5.
*/
precision?: number | false | undefined;
precision?: number | false;
/**
* Wrapper name to use when `calc()` is needed. Default `'calc'`.
*/
calcName?: string | undefined;
calcName?: string;
};
/**
* @param {Node} node
* @param {SerializeOptions} [opts]
* @return {string}
*/
export function serialize(node: Node, opts?: SerializeOptions): string;
declare function serialize(node: Node, opts?: SerializeOptions): string;
12 changes: 6 additions & 6 deletions types/lib/simplify.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* Recursive simplifier reference, threaded into Sum/Product/Call. Lets
* leaf fold modules avoid circular imports of the entry function.
*/
export type Node = import("./node.js").Node;
declare const _exports: {
simplify: typeof simplify;
};
export = _exports;
export type Node = import('./node.js').Node;
export type SimplifyFn = (node: Node) => Node;
/**
* @typedef {import('./node.js').Node} Node
Expand All @@ -15,4 +15,4 @@ export type SimplifyFn = (node: Node) => Node;
* @param {Node} node
* @return {Node}
*/
export function simplify(node: Node): Node;
declare function simplify(node: Node): Node;
8 changes: 6 additions & 2 deletions types/lib/simplify/abs.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export type Node = import("../node.js").Node;
declare const _exports: {
simplifyAbs: typeof simplifyAbs;
};
export = _exports;
export type Node = import('../node.js').Node;
/** @typedef {import('../node.js').Node} Node */
/**
* @param {Node[]} args
* @return {Node}
*/
export function simplifyAbs(args: Node[]): Node;
declare function simplifyAbs(args: Node[]): Node;
8 changes: 6 additions & 2 deletions types/lib/simplify/atan2.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export type Node = import("../node.js").Node;
declare const _exports: {
simplifyAtan2: typeof simplifyAtan2;
};
export = _exports;
export type Node = import('../node.js').Node;
/** @typedef {import('../node.js').Node} Node */
/**
* @param {Node[]} args
* @return {Node}
*/
export function simplifyAtan2(args: Node[]): Node;
declare function simplifyAtan2(args: Node[]): Node;
8 changes: 6 additions & 2 deletions types/lib/simplify/bucket.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
declare const _exports: {
mergeConvertibleBuckets: typeof mergeConvertibleBuckets;
};
export = _exports;
export type UnitBucket = {
unit: string;
total: number;
/**
* largest |term| accumulated into `total`, for noise detection
*/
scale: number;
base: import("../convertUnits.js").BaseType | null;
base: import('../convertUnits.js').BaseType | null;
order: number;
};
/**
Expand All @@ -21,4 +25,4 @@ export type UnitBucket = {
* @param {UnitBucket[]} buckets
* @return {UnitBucket[]}
*/
export function mergeConvertibleBuckets(buckets: UnitBucket[]): UnitBucket[];
declare function mergeConvertibleBuckets(buckets: UnitBucket[]): UnitBucket[];
12 changes: 8 additions & 4 deletions types/lib/simplify/call.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
export type Node = import("../node.js").Node;
export type SimplifyFn = import("../simplify.js").SimplifyFn;
declare const _exports: {
simplifyCall: typeof simplifyCall;
};
export = _exports;
export type Node = import('../node.js').Node;
export type SimplifyFn = import('../simplify.js').SimplifyFn;
/** @typedef {import('../node.js').Node} Node */
/** @typedef {import('../simplify.js').SimplifyFn} SimplifyFn */
/**
* @param {Extract<Node, { type: 'Call' }>} node
* @param {SimplifyFn} simplify
* @return {Node}
*/
export function simplifyCall(node: Extract<Node, {
type: "Call";
declare function simplifyCall(node: Extract<Node, {
type: 'Call';
}>, simplify: SimplifyFn): Node;
Loading