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
4 changes: 4 additions & 0 deletions packages/css-calc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes to CSS Calc

### Unreleased (minor)

- Add `onParseError` option to `calc()`.

### 3.0.1

_February 10, 2026_
Expand Down
32 changes: 31 additions & 1 deletion packages/css-calc/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ComponentValue } from '@csstools/css-parser-algorithms';
import { ComponentValue } from '@csstools/css-parser-algorithms';
import type { TokenDimension } from '@csstools/css-tokenizer';
import type { TokenNumber } from '@csstools/css-tokenizer';
import type { TokenPercentage } from '@csstools/css-tokenizer';
Expand All @@ -8,6 +8,14 @@ export declare function calc(css: string, options?: conversionOptions): string;
export declare function calcFromComponentValues(componentValuesList: Array<Array<ComponentValue>>, options?: conversionOptions): Array<Array<ComponentValue>>;

export declare type conversionOptions = {
/**
* If a calc expression can not be solved the parse error might be reported through this callback.
* Not all cases are covered. Open an issue if you need specific errors reported.
*
* Values are recursively visited and at each nesting level an attempt is made to solve the expression.
* Errors can be reported multiple times as a result of this.
*/
onParseError?: (error: ParseError) => void;
/**
* Pass global values as a map of key value pairs.
*/
Expand Down Expand Up @@ -68,4 +76,26 @@ export declare type GlobalsWithStrings = Map<string, TokenDimension | TokenNumbe

export declare const mathFunctionNames: Set<string>;

/**
* Any errors are reported through the `onParseError` callback.
*/
export declare class ParseError extends Error {
/** The index of the start character of the current token. */
sourceStart: number;
/** The index of the end character of the current token. */
sourceEnd: number;
constructor(message: string, sourceStart: number, sourceEnd: number);
}

export declare const ParseErrorMessage: {
UnexpectedAdditionOfDimensionOrPercentageWithNumber: string;
UnexpectedSubtractionOfDimensionOrPercentageWithNumber: string;
};

export declare class ParseErrorWithComponentValues extends ParseError {
/** The associated component values. */
componentValues: Array<ComponentValue>;
constructor(message: string, componentValues: Array<ComponentValue>);
}

export { }
2 changes: 1 addition & 1 deletion packages/css-calc/dist/index.mjs

Large diffs are not rendered by default.

Loading
Loading