@novnox/grid 0.0.0-stage → 1.0.0

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.
@@ -0,0 +1,74 @@
1
+ import { NoxGrid } from './grid';
2
+ import { type PrintOptions } from './print';
3
+ import { type LoadSheetOptions, type WorkbookData } from './sheetData';
4
+ import type { GridOptions } from './types';
5
+ export interface BookSheetOptions extends GridOptions {
6
+ name: string;
7
+ }
8
+ export interface BookOptions {
9
+ sheets?: BookSheetOptions[];
10
+ /** Add a sheet with the tab's [+] button (default true). */
11
+ allowAddSheets?: boolean;
12
+ /** Reorder sheets by dragging tabs (default true). */
13
+ allowMoveSheets?: boolean;
14
+ /** Rename a sheet by double-clicking its tab (default true). */
15
+ allowRenameSheets?: boolean;
16
+ /** Default options for new sheets. */
17
+ defaults?: GridOptions;
18
+ }
19
+ /**
20
+ * NoxGrid workbook (sheet tabs). Same concept as the desktop NoxGridBook.
21
+ * ```ts
22
+ * const book = new NoxGridBook(el, { sheets: [{ name: 'Orders', columns }, { name: 'Data', rowCount: 10 }] });
23
+ * book.sheet('Orders').setFormula(0, 0, '=Data!A1*2');
24
+ * ```
25
+ */
26
+ export declare class NoxGridBook {
27
+ readonly host: HTMLElement;
28
+ readonly root: HTMLDivElement;
29
+ private readonly area;
30
+ private readonly tabs;
31
+ private readonly entries;
32
+ private active;
33
+ private readonly listeners;
34
+ allowAddSheets: boolean;
35
+ allowMoveSheets: boolean;
36
+ allowRenameSheets: boolean;
37
+ defaults: GridOptions;
38
+ constructor(host: HTMLElement, o?: BookOptions);
39
+ /** Number of sheets. */
40
+ get sheetCount(): number;
41
+ /** Sheet names. */
42
+ get sheetNames(): string[];
43
+ /** Gets a sheet's grid by index or name; undefined if not found. */
44
+ sheet(key: number | string): NoxGrid | undefined;
45
+ indexOf(key: number | string): number;
46
+ get activeSheet(): number;
47
+ set activeSheet(i: number);
48
+ get activeGrid(): NoxGrid | undefined;
49
+ /** Registers a handler called when the active sheet changes. */
50
+ onActiveSheetChanged(fn: (index: number) => void): () => void;
51
+ /** Adds a sheet (named Sheet2… if no name is given). Returns the new grid. */
52
+ addSheet(name?: string, options?: GridOptions, index?: number): NoxGrid;
53
+ /** Removes a sheet (the last remaining sheet cannot be removed). Formulas referencing it become #REF!. */
54
+ removeSheet(key: number | string): boolean;
55
+ /** Renames a sheet. References in other sheets' formulas are updated too. */
56
+ renameSheet(key: number | string, newName: string): boolean;
57
+ /** Moves a sheet to a new position (the active sheet stays the same). */
58
+ moveSheet(from: number, to: number): void;
59
+ /** Loads workbook data (replaces all sheets). */
60
+ loadWorkbookData(book: WorkbookData, options?: LoadSheetOptions): void;
61
+ /** Workbook data to send to the server. */
62
+ toWorkbookData(options?: {
63
+ headerRow?: boolean;
64
+ }): WorkbookData;
65
+ /** Prints all sheets (each sheet on a new page, titled with the sheet name). */
66
+ printAll(options?: PrintOptions): Promise<void>;
67
+ toPrintHtml(options?: PrintOptions): string;
68
+ destroy(): void;
69
+ private nextName;
70
+ private uniqueName;
71
+ private renderTabs;
72
+ private onTabDown;
73
+ private beginRename;
74
+ }
@@ -0,0 +1,79 @@
1
+ import type { GridModel } from './model';
2
+ import type { CellRange, CellValue } from './types';
3
+ /** Condition operator (same concept as the desktop NoxConditionOperator). */
4
+ export type ConditionOperator = 'equal' | 'notEqual' | 'greater' | 'greaterOrEqual' | 'less' | 'lessOrEqual' | 'between' | 'notBetween' | 'contains' | 'beginsWith' | 'endsWith' | 'blank' | 'notBlank' | 'expression' | 'colorScale';
5
+ /** Information passed to an expression rule. */
6
+ export interface ConditionContext {
7
+ row: number;
8
+ col: number;
9
+ value: CellValue;
10
+ /** Gets the value of another column in the same row (by index or name). */
11
+ get(col: number | string): CellValue;
12
+ }
13
+ /** Conditional format options. */
14
+ export interface ConditionalFormatOptions {
15
+ operator: ConditionOperator;
16
+ /** Columns to apply to (by index or name). All columns if omitted. */
17
+ columns?: Array<number | string>;
18
+ /** Range to apply to. All rows if omitted. */
19
+ range?: CellRange;
20
+ value1?: CellValue;
21
+ value2?: CellValue;
22
+ /** Predicate for operator 'expression'. */
23
+ test?: (ctx: ConditionContext) => boolean;
24
+ backColor?: string;
25
+ foreColor?: string;
26
+ bold?: boolean;
27
+ italic?: boolean;
28
+ strikeout?: boolean;
29
+ /** Applies to the entire row when the condition matches (evaluated on the first of `columns`). */
30
+ entireRow?: boolean;
31
+ /** When matched, later rules are not evaluated. */
32
+ stopIfTrue?: boolean;
33
+ minColor?: string;
34
+ midColor?: string;
35
+ maxColor?: string;
36
+ }
37
+ /** Conditional format result. */
38
+ export interface ConditionalLook {
39
+ backColor?: string;
40
+ foreColor?: string;
41
+ bold?: boolean;
42
+ italic?: boolean;
43
+ strikeout?: boolean;
44
+ }
45
+ /** Conditional format rule. */
46
+ export declare class ConditionalFormat {
47
+ options: ConditionalFormatOptions;
48
+ constructor(options: ConditionalFormatOptions);
49
+ }
50
+ /** Collection of conditional format rules (earlier rules take precedence). */
51
+ export declare class ConditionalFormatCollection {
52
+ private readonly model;
53
+ private readonly changed;
54
+ private list;
55
+ private scaleCache;
56
+ private version;
57
+ constructor(model: GridModel, changed: () => void);
58
+ get count(): number;
59
+ get(i: number): ConditionalFormat;
60
+ [Symbol.iterator](): Iterator<ConditionalFormat>;
61
+ add(o: ConditionalFormatOptions): ConditionalFormat;
62
+ /** Adds an expression rule. */
63
+ addExpression(columns: Array<number | string> | undefined, test: (ctx: ConditionContext) => boolean, look: ConditionalLook, entireRow?: boolean): ConditionalFormat;
64
+ /** Adds a color scale (minimum color → maximum color). */
65
+ addColorScale(columns: Array<number | string>, minColor: string, maxColor: string, midColor?: string): ConditionalFormat;
66
+ remove(f: ConditionalFormat): void;
67
+ clear(): void;
68
+ /** Recomputes color scale ranges after values change. */
69
+ invalidate(): void;
70
+ /** Gets the conditional format for a cell. */
71
+ evaluate(r: number, c: number): ConditionalLook | null;
72
+ private columnsOf;
73
+ private matches;
74
+ private scaleColor;
75
+ }
76
+ /** Blends two colors. */
77
+ export declare function mix(a: string, b: string, t: number): string;
78
+ /** "#rgb", "#rrggbb", "rgb(r,g,b)" → [r,g,b] */
79
+ export declare function parseColor(s: string): [number, number, number];
@@ -0,0 +1,129 @@
1
+ import type { CellValue, SortSpec } from './types';
2
+ /**
3
+ * Why a value changed (same idea as the desktop NoxGridChangeReason):
4
+ * 'edit' typed by the user, 'toggle' check box clicked or Space, 'paste' pasted, 'delete' cleared with the Delete key,
5
+ * 'replace' find and replace, 'undo' / 'redo' undo and redo, 'code' set by the app (setValue, data changes and so on).
6
+ */
7
+ export type ValueChangeSource = 'edit' | 'toggle' | 'paste' | 'delete' | 'replace' | 'undo' | 'redo' | 'code';
8
+ /** Grid events and their arguments. */
9
+ export interface GridEventMap {
10
+ /**
11
+ * Fired for each cell whose value changes, including undo and redo. `source` tells why.
12
+ * `nested` is true when the change was made inside another cellValueChanged handler (e.g. a computed column);
13
+ * its `source` stays the reason of the first change. Skip such changes with `if (e.nested) return;`.
14
+ * Undo and redo replay them with the same `nested`, once per cell.
15
+ */
16
+ cellValueChanged: {
17
+ row: number;
18
+ col: number;
19
+ oldValue: CellValue;
20
+ newValue: CellValue;
21
+ source: ValueChangeSource;
22
+ nested: boolean;
23
+ };
24
+ /** Fired when the current cell or selection changes. */
25
+ selectionChanged: {
26
+ row: number;
27
+ col: number;
28
+ };
29
+ cellClick: {
30
+ row: number;
31
+ col: number;
32
+ event: MouseEvent;
33
+ };
34
+ cellDoubleClick: {
35
+ row: number;
36
+ col: number;
37
+ event: MouseEvent;
38
+ };
39
+ /** Fired when a button column is clicked. */
40
+ buttonClick: {
41
+ row: number;
42
+ col: number;
43
+ };
44
+ /** Fired before editing starts (set cancel = true to prevent it). */
45
+ beginEdit: {
46
+ row: number;
47
+ col: number;
48
+ cancel: boolean;
49
+ };
50
+ endEdit: {
51
+ row: number;
52
+ col: number;
53
+ cancelled: boolean;
54
+ };
55
+ /** Fired when an input value fails formatting or validation. */
56
+ dataError: {
57
+ row: number;
58
+ col: number;
59
+ text: string;
60
+ message: string;
61
+ };
62
+ sorted: {
63
+ specs: SortSpec[];
64
+ };
65
+ filtered: {
66
+ col: number;
67
+ };
68
+ columnResized: {
69
+ col: number;
70
+ width: number;
71
+ };
72
+ /** Fired for each column when the footer row is calculated. Change `value` to show your own value (e.g. a ratio of two sums). */
73
+ footerValue: {
74
+ col: number;
75
+ value: CellValue;
76
+ };
77
+ /**
78
+ * The header check box was clicked, before anything changes (like the desktop HeaderCheckChanging). `checked` is the state
79
+ * the shown rows will get; set `cancel` to keep them as they are. Order: headerCheckChanging, then cellValueChanged
80
+ * (source 'toggle') for each changed cell, then headerCheckChanged.
81
+ */
82
+ headerCheckChanging: {
83
+ col: number;
84
+ checked: boolean;
85
+ cancel: boolean;
86
+ };
87
+ /** The header check box of a check column was clicked; the shown rows are now all checked (true) or all unchecked (false). */
88
+ headerCheckChanged: {
89
+ col: number;
90
+ checked: boolean;
91
+ };
92
+ /**
93
+ * For each cell a paste is about to change (like the desktop CellPasting): `text` is the pasted text, `value` the value the grid
94
+ * would put in. Change `value` to put something else, or set `cancel` to skip the cell. Not raised for formulas copied inside the grid.
95
+ */
96
+ cellPasting: {
97
+ row: number;
98
+ col: number;
99
+ text: string;
100
+ value: CellValue;
101
+ cancel: boolean;
102
+ };
103
+ /**
104
+ * After a paste (Ctrl+V or pasteText): the pasted area, how many cells changed, rows added by pasteAddsRows, and lines or
105
+ * columns of the text that did not fit and were dropped (droppedRows > 0 means part of the text was not pasted).
106
+ */
107
+ pasted: {
108
+ row: number;
109
+ col: number;
110
+ rowCount: number;
111
+ colCount: number;
112
+ changed: number;
113
+ addedRows: number;
114
+ droppedRows: number;
115
+ droppedColumns: number;
116
+ };
117
+ undo: Record<string, never>;
118
+ redo: Record<string, never>;
119
+ }
120
+ export type GridEventName = keyof GridEventMap;
121
+ export type GridEventHandler<K extends GridEventName> = (e: GridEventMap[K]) => void;
122
+ /** Simple event emitter. */
123
+ export declare class Emitter {
124
+ private handlers;
125
+ on<K extends GridEventName>(name: K, fn: GridEventHandler<K>): () => void;
126
+ off<K extends GridEventName>(name: K, fn: GridEventHandler<K>): void;
127
+ has(name: GridEventName): boolean;
128
+ emit<K extends GridEventName>(name: K, e: GridEventMap[K]): void;
129
+ }
@@ -0,0 +1,37 @@
1
+ import type { NoxGrid } from './grid';
2
+ import type { CellAddress } from './types';
3
+ export interface FindOptions {
4
+ /** Case-sensitive match. */
5
+ matchCase?: boolean;
6
+ /** Match the entire cell contents. */
7
+ wholeCell?: boolean;
8
+ /** Search only in this column. */
9
+ inColumn?: number | string;
10
+ /** Search upward. */
11
+ backwards?: boolean;
12
+ }
13
+ /** Finds the next matching cell (visible rows and columns, wrapping from end to start). Selects it and returns its position if found. */
14
+ export declare function findNext(g: NoxGrid, text: string, o?: FindOptions): CellAddress | null;
15
+ /** Replaces the current cell if it matches, then finds the next one. */
16
+ export declare function replaceOne(g: NoxGrid, text: string, rep: string, o?: FindOptions): boolean;
17
+ /** Replaces all matches (a single undo step). Returns the number of cells replaced. */
18
+ export declare function replaceAll(g: NoxGrid, text: string, rep: string, o?: FindOptions): number;
19
+ /** Find dialog. */
20
+ export declare class FindPanel {
21
+ private readonly g;
22
+ readonly el: HTMLDivElement;
23
+ private readonly what;
24
+ private readonly withText;
25
+ private readonly replaceRow;
26
+ private readonly status;
27
+ private readonly matchCase;
28
+ private readonly wholeCell;
29
+ private readonly inColumn;
30
+ lastText: string;
31
+ constructor(g: NoxGrid);
32
+ options(): FindOptions;
33
+ open(replace: boolean): void;
34
+ get isOpen(): boolean;
35
+ next(backwards: boolean): void;
36
+ close(): void;
37
+ }
@@ -0,0 +1,6 @@
1
+ import type { GridModel } from './model';
2
+ import type { CellValue } from './types';
3
+ /** Calculates the footer value of a column (by its `footer` function). */
4
+ export declare function calcFooter(m: GridModel, c: number): CellValue;
5
+ /** Footer display text. */
6
+ export declare function footerText(m: GridModel, c: number, value: CellValue): string;
@@ -0,0 +1,21 @@
1
+ import type { CellValue } from './types';
2
+ /** Whether the value is a date. */
3
+ export declare function isDate(v: unknown): v is Date;
4
+ /**
5
+ * Converts a value to display text.
6
+ * Number formats: Excel style ("#,##0.00", "0%", "\"₩\"#,##0", positive;negative;zero sections) and .NET style ("N2", "F1", "P0").
7
+ * Date formats: yyyy yy MM M dd d HH H hh h mm ss tt.
8
+ */
9
+ export declare function formatValue(v: CellValue, format?: string): string;
10
+ /** Formats a date. */
11
+ export declare function formatDate(d: Date, format: string): string;
12
+ /** Formats a number. */
13
+ export declare function formatNumber(v: number, format: string): string;
14
+ /** Parses input text as a number (commas and % allowed). Returns null on failure. */
15
+ export declare function parseNumber(text: string): number | null;
16
+ /** Parses input text as a date (yyyy-MM-dd, yyyy/MM/dd, yyyy.MM.dd, yyyyMMdd, hh:mm[:ss]). Returns null on failure. */
17
+ export declare function parseDate(text: string): Date | null;
18
+ /** Compares values for sorting (empty values always last, numbers < text). */
19
+ export declare function compareValues(a: CellValue, b: CellValue): number;
20
+ /** Whether two values are equal (for merging and filtering). */
21
+ export declare function sameValue(a: CellValue, b: CellValue): boolean;
@@ -0,0 +1,25 @@
1
+ import type { Node } from './nodes';
2
+ import { type EValue, type FValue, type FormulaSheet } from './values';
3
+ export declare function formulaVersion(): number;
4
+ /** Forces all formula results to be recalculated. */
5
+ export declare function invalidateFormulas(): void;
6
+ /** Computation target (implemented by NoxFormula). */
7
+ export interface Computable {
8
+ readonly root: Node;
9
+ cached: FValue;
10
+ cacheVersion: number;
11
+ evaluating: boolean;
12
+ }
13
+ export declare function evaluateFormula(f: Computable, sheet: FormulaSheet, row: number, col: number): FValue;
14
+ /** Evaluates a syntax tree. */
15
+ export declare class Evaluator {
16
+ readonly sheet: FormulaSheet;
17
+ readonly row: number;
18
+ readonly col: number;
19
+ constructor(sheet: FormulaSheet, row: number, col: number);
20
+ /** Evaluates to a value or a RangeValue. */
21
+ eval(n: Node): EValue;
22
+ /** Evaluates to a single value (for a range, the cell in the same row or column; for a single cell, its value). */
23
+ scalar(n: Node): FValue;
24
+ deref(v: EValue): FValue;
25
+ }
@@ -0,0 +1,56 @@
1
+ import { type Computable } from './engine';
2
+ import { type Node } from './nodes';
3
+ import { type FValue, type FormulaSheet } from './values';
4
+ /**
5
+ * Cell formula (Excel style; same syntax and functions as the desktop NoxFormula).
6
+ * References: A1 = first row, first column. Examples: `=SUM(A1:A10)`, `=B2*C2`, `=IF(D2>=60,"Pass","Fail")`.
7
+ */
8
+ export declare class NoxFormula implements Computable {
9
+ readonly root: Node;
10
+ /** @internal */ cached: FValue;
11
+ /** @internal */ cacheVersion: number;
12
+ /** @internal */ evaluating: boolean;
13
+ private _text;
14
+ /** @internal */
15
+ constructor(root: Node);
16
+ /** Parses a formula (the leading "=" is optional). Throws FormulaSyntaxError on invalid syntax. */
17
+ static parse(text: string): NoxFormula;
18
+ /** Parses a formula; returns null on invalid syntax. */
19
+ static tryParse(text: string): NoxFormula | null;
20
+ /** Formula text (without '='). */
21
+ get text(): string;
22
+ toString(): string;
23
+ clone(): NoxFormula;
24
+ /** Evaluates as if located in cell (row, col) of the sheet (result is cached). */
25
+ evaluate(sheet: FormulaSheet, row: number, col: number): FValue;
26
+ /** Evaluates once without caching. */
27
+ evaluateOnce(sheet: FormulaSheet, row: number, col: number): FValue;
28
+ /** Names of the available functions. */
29
+ static get functionNames(): string[];
30
+ /**
31
+ * Registers a custom function. Arguments are an array of evaluated values (ranges as 2D arrays, empty cells as null).
32
+ * Replaces an existing function with the same name. Built-in function names cannot be used.
33
+ */
34
+ static registerFunction(name: string, fn: (args: unknown[]) => unknown): void;
35
+ static unregisterFunction(name: string): boolean;
36
+ static isFunctionDefined(name: string): boolean;
37
+ /** Forces all formula results to be recalculated. */
38
+ static invalidate(): void;
39
+ /** @internal */
40
+ changed(): void;
41
+ private done;
42
+ /** Shifts rows at or after `index` by `count` in references whose sheet name satisfies `targets`. */
43
+ insertRows(targets: (sheet: string | null) => boolean, index: number, count: number): boolean;
44
+ /** `count` rows starting at `index` were removed: references to them become #REF!, ranges shrink. */
45
+ removeRows(targets: (sheet: string | null) => boolean, index: number, count: number): boolean;
46
+ /** Remaps column positions. map(old position) = new position, or -1 if removed. */
47
+ remapColumns(targets: (sheet: string | null) => boolean, map: (c: number) => number): boolean;
48
+ /** Shifts relative references by dRow, dCol as if moved to another cell (copy, sort). Out-of-bounds references become #REF!. */
49
+ offset(dRow: number, dCol: number): boolean;
50
+ /** Renames the sheet in references (null means the formula's own sheet). */
51
+ mapSheets(map: (sheet: string) => string | null): boolean;
52
+ /** Whether the formula uses the SUBTOTAL function. */
53
+ get isSubtotal(): boolean;
54
+ /** Whether the formula has no #REF!, unknown names, or missing functions. */
55
+ get isFullySupported(): boolean;
56
+ }
@@ -0,0 +1,18 @@
1
+ import type { Evaluator } from './engine';
2
+ import type { Node } from './nodes';
3
+ import { type EValue, type FValue } from './values';
4
+ export declare function functionNames(): string[];
5
+ export declare function isBuiltInFunction(name: string): boolean;
6
+ export declare function isFunctionDefined(name: string): boolean;
7
+ export declare function registerFunction(name: string, fn: (args: unknown[]) => unknown): void;
8
+ export declare function unregisterFunction(name: string): boolean;
9
+ export declare function callFunction(ev: Evaluator, name: string, args: Node[]): EValue;
10
+ /** mode 0 rounds, 1 rounds up (away from zero), -1 rounds down (toward zero). */
11
+ export declare function roundCore(x: number, digits: number, mode: number): number;
12
+ /** TEXT function: formats with an Excel format string. */
13
+ export declare function formatText(v: FValue, excelFormat: string): FValue;
14
+ /** Converts an Excel format to a grid format (isDate for dates). Returns null for the General format. */
15
+ export declare function convertExcelFormat(fmt: string): {
16
+ format: string;
17
+ isDate: boolean;
18
+ } | null;
@@ -0,0 +1,71 @@
1
+ import type { FormulaError } from './values';
2
+ export declare const MAX_INDEX = 2147483647;
3
+ export type Node = LiteralNode | EmptyArgNode | RefNode | AreaNode | UnaryNode | PercentNode | BinaryNode | FuncNode | ParenNode | NameNode;
4
+ export interface LiteralNode {
5
+ t: 'lit';
6
+ value: number | string | boolean | FormulaError;
7
+ }
8
+ export interface EmptyArgNode {
9
+ t: 'empty';
10
+ }
11
+ export interface RefNode {
12
+ t: 'ref';
13
+ sheet: string | null;
14
+ row: number;
15
+ col: number;
16
+ rowAbs: boolean;
17
+ colAbs: boolean;
18
+ invalid: boolean;
19
+ }
20
+ export type AreaKind = 'cells' | 'columns' | 'rows';
21
+ export interface AreaNode {
22
+ t: 'area';
23
+ sheet: string | null;
24
+ kind: AreaKind;
25
+ r1: number;
26
+ c1: number;
27
+ r2: number;
28
+ c2: number;
29
+ r1Abs: boolean;
30
+ c1Abs: boolean;
31
+ r2Abs: boolean;
32
+ c2Abs: boolean;
33
+ invalid: boolean;
34
+ }
35
+ export interface UnaryNode {
36
+ t: 'unary';
37
+ op: '-' | '+';
38
+ operand: Node;
39
+ }
40
+ export interface PercentNode {
41
+ t: 'pct';
42
+ operand: Node;
43
+ }
44
+ export interface BinaryNode {
45
+ t: 'bin';
46
+ op: string;
47
+ left: Node;
48
+ right: Node;
49
+ }
50
+ export interface FuncNode {
51
+ t: 'func';
52
+ /** Uppercase name (without the _xlfn. prefix). */
53
+ name: string;
54
+ args: Node[];
55
+ }
56
+ export interface ParenNode {
57
+ t: 'paren';
58
+ inner: Node;
59
+ }
60
+ export interface NameNode {
61
+ t: 'name';
62
+ name: string;
63
+ }
64
+ /** Child nodes. */
65
+ export declare function children(n: Node): Node[];
66
+ /** The node itself and all descendants. */
67
+ export declare function walk(root: Node): Generator<Node>;
68
+ /** Deep copy. */
69
+ export declare function cloneNode(n: Node): Node;
70
+ /** Normalizes a range to top-left / bottom-right order. */
71
+ export declare function normalizeArea(a: AreaNode): void;
@@ -0,0 +1,6 @@
1
+ import { type Node } from './nodes';
2
+ export declare function isAsciiLetter(ch: string): boolean;
3
+ export declare function isNameStart(ch: string): boolean;
4
+ export declare function isNameChar(ch: string): boolean;
5
+ /** Parses "=SUM(A1:A3)" or "SUM(A1:A3)". Throws FormulaSyntaxError on invalid syntax. */
6
+ export declare function parseFormula(text: string): Node;
@@ -0,0 +1,95 @@
1
+ /** Formula error value. Appears as a cell value; its text is a code such as #DIV/0!. */
2
+ export declare class FormulaError {
3
+ readonly code: string;
4
+ static readonly DivideByZero: FormulaError;
5
+ static readonly Value: FormulaError;
6
+ static readonly Reference: FormulaError;
7
+ static readonly Name: FormulaError;
8
+ static readonly NotAvailable: FormulaError;
9
+ static readonly Number: FormulaError;
10
+ static readonly NullIntersection: FormulaError;
11
+ static readonly Circular: FormulaError;
12
+ static readonly all: readonly FormulaError[];
13
+ private constructor();
14
+ toString(): string;
15
+ /** Finds an error by code (null if not found). */
16
+ static fromCode(code: string): FormulaError | null;
17
+ }
18
+ /** Formula syntax error. */
19
+ export declare class FormulaSyntaxError extends Error {
20
+ readonly position: number;
21
+ constructor(message: string, position: number);
22
+ }
23
+ /** Sheet that formulas read values from (implemented by the grid). */
24
+ export interface FormulaSheet {
25
+ readonly rowCount: number;
26
+ readonly columnCount: number;
27
+ /** Cell value (computed value for formula cells). null if out of range. */
28
+ getValue(row: number, col: number): unknown;
29
+ /** Finds a sheet by name. A null or empty name means this sheet; null if not found. */
30
+ findSheet(name: string | null): FormulaSheet | null;
31
+ /** Whether the cell contains a SUBTOTAL formula. */
32
+ isSubtotalCell(row: number, col: number): boolean;
33
+ /** Whether the row is hidden (SUBTOTAL 101-111). */
34
+ isRowHidden(row: number): boolean;
35
+ }
36
+ /** Value during formula evaluation. */
37
+ export type FValue = number | string | boolean | Date | FormulaError | null;
38
+ export type EValue = FValue | RangeValue;
39
+ /** Range value (function argument). Values are read from the sheet on access. */
40
+ export declare class RangeValue {
41
+ readonly sheet: FormulaSheet;
42
+ readonly r1: number;
43
+ readonly c1: number;
44
+ readonly r2: number;
45
+ readonly c2: number;
46
+ constructor(sheet: FormulaSheet, r1: number, c1: number, r2: number, c2: number);
47
+ get rows(): number;
48
+ get columns(): number;
49
+ get isSingleCell(): boolean;
50
+ get lastRow(): number;
51
+ get lastColumn(): number;
52
+ get(i: number, j: number): FValue;
53
+ /** Cells that may have values (row-major). Trailing empty cells are skipped. */
54
+ values(): Generator<FValue>;
55
+ get cellCount(): number;
56
+ }
57
+ export declare function toOADate(d: Date): number;
58
+ export declare function fromOADate(n: number): Date;
59
+ export declare function isDateValue(v: unknown): v is Date;
60
+ /** Cell value → formula value: empty text is an empty cell, numeric text is a number (codes with leading zeros stay text). */
61
+ export declare function fromCell(v: unknown): FValue;
62
+ /** Numeric text (thousands separators allowed). */
63
+ export declare function tryParseNumber(s: string): number | null;
64
+ /** Finalizes a result: empty cell → 0, range → error. */
65
+ export declare function finalValue(v: EValue): FValue;
66
+ export declare function num(d: number): number | FormulaError;
67
+ export declare function dateOrNumber(d: number): Date | number | FormulaError;
68
+ /** Converts to a number (empty cell 0, TRUE 1, dates as serial numbers, numeric or date text). Returns null if not possible. */
69
+ export declare function tryNumber(v: unknown): number | null;
70
+ export declare function tryBool(v: unknown): boolean | null;
71
+ export declare function toText(v: unknown): string;
72
+ /** Integers as-is, otherwise 15 significant digits. */
73
+ export declare function formatNumber(d: number): string;
74
+ /** Case-insensitive text comparison. */
75
+ export declare function compareText(a: string, b: string): number;
76
+ /** Excel comparison: numbers < text < booleans; text is case-insensitive. */
77
+ export declare function compare(a: unknown, b: unknown): number;
78
+ /** Equal if equal within 15 digits (0.1+0.2 = 0.3). */
79
+ export declare function numbersEqual(x: number, y: number): boolean;
80
+ export declare function isNumberLike(v: unknown): v is number | Date;
81
+ export declare function asNumber(v: number | Date): number;
82
+ /** Converts * ? ~ wildcards to a regex (case-insensitive, full match). */
83
+ export declare function wildcardRegex(pattern: string, anchored?: boolean): RegExp;
84
+ /** COUNTIF/SUMIF criteria (">10", "<>Done", "A*", 5). */
85
+ export declare class Criteria {
86
+ private readonly op;
87
+ private readonly value;
88
+ private readonly isNumber;
89
+ private readonly number;
90
+ private readonly pattern;
91
+ private constructor();
92
+ static parse(criteria: unknown): Criteria;
93
+ matches(cell: FValue): boolean;
94
+ private test;
95
+ }
@@ -0,0 +1,8 @@
1
+ import type { Node } from './nodes';
2
+ /** 0 → A, 25 → Z, 26 → AA */
3
+ export declare function columnName(index: number): string;
4
+ /** A1-style cell name (zero-based row and column). */
5
+ export declare function cellName(row: number, col: number): string;
6
+ export declare function writeFormula(node: Node): string;
7
+ /** Whether the sheet name needs quoting. */
8
+ export declare function needsQuotes(sheet: string): boolean;