@p10node/office-engine 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +65 -2
- package/dist/DocViewer-Cv4LaMB_.js +9342 -0
- package/dist/DocViewer-Cv4LaMB_.js.map +1 -0
- package/dist/THIRD_PARTY_LICENSES.txt +79 -0
- package/dist/assets/worker-CJfZ05I7.js.map +1 -0
- package/dist/collab-BzN1ZI-z.js +1984 -0
- package/dist/collab-BzN1ZI-z.js.map +1 -0
- package/dist/collab.js +2 -0
- package/dist/core.js +2 -0
- package/dist/default-worker-B5CGBnic.js +9193 -0
- package/dist/default-worker-B5CGBnic.js.map +1 -0
- package/dist/embed.js +83 -0
- package/dist/embed.js.map +1 -0
- package/dist/index.js +5 -0
- package/dist/office-engine.embed.js +33 -0
- package/dist/office-engine.worker.js +9092 -0
- package/dist/types/collab/codec.d.ts +3 -0
- package/dist/types/collab/docx.d.ts +166 -0
- package/dist/types/collab/hosts.d.ts +24 -0
- package/dist/types/collab/hub.d.ts +41 -0
- package/dist/types/collab/index.d.ts +43 -0
- package/dist/types/collab/pptx-ops.d.ts +60 -0
- package/dist/types/collab/pptx-worker.d.ts +35 -0
- package/dist/types/collab/pptx.d.ts +47 -0
- package/dist/types/collab/protocol.d.ts +76 -0
- package/dist/types/collab/react.d.ts +23 -0
- package/dist/types/collab/session.d.ts +115 -0
- package/dist/types/collab/transport.d.ts +47 -0
- package/dist/types/collab/xlsx-ops.d.ts +72 -0
- package/dist/types/collab/xlsx-worker.d.ts +29 -0
- package/dist/types/collab/xlsx.d.ts +51 -0
- package/dist/types/core/color.d.ts +25 -0
- package/dist/types/core/default-worker.d.ts +1 -0
- package/dist/types/core/docx/numbering.d.ts +33 -0
- package/dist/types/core/docx/parser.d.ts +126 -0
- package/dist/types/core/docx/spec.d.ts +4 -0
- package/dist/types/core/docx/styles.d.ts +63 -0
- package/dist/types/core/docx/types.d.ts +325 -0
- package/dist/types/core/docx/writer.d.ts +35 -0
- package/dist/types/core/fonts.d.ts +1 -0
- package/dist/types/core/index.d.ts +15 -0
- package/dist/types/core/opc.d.ts +56 -0
- package/dist/types/core/pptx/edit.d.ts +10 -0
- package/dist/types/core/pptx/parser.d.ts +52 -0
- package/dist/types/core/pptx/types.d.ts +238 -0
- package/dist/types/core/raw.d.ts +40 -0
- package/dist/types/core/source.d.ts +65 -0
- package/dist/types/core/theme.d.ts +11 -0
- package/dist/types/core/units.d.ts +7 -0
- package/dist/types/core/worker/client.d.ts +48 -0
- package/dist/types/core/worker/engine.d.ts +27 -0
- package/dist/types/core/worker/protocol.d.ts +112 -0
- package/dist/types/core/worker/worker.d.ts +1 -0
- package/dist/types/core/xlsx/calc.d.ts +31 -0
- package/dist/types/core/xlsx/editor.d.ts +95 -0
- package/dist/types/core/xlsx/formula/assist.d.ts +35 -0
- package/dist/types/core/xlsx/formula/catalog.d.ts +14 -0
- package/dist/types/core/xlsx/formula/dates.d.ts +23 -0
- package/dist/types/core/xlsx/formula/evaluate.d.ts +33 -0
- package/dist/types/core/xlsx/formula/fn-date.d.ts +2 -0
- package/dist/types/core/xlsx/formula/fn-logic.d.ts +3 -0
- package/dist/types/core/xlsx/formula/fn-lookup.d.ts +3 -0
- package/dist/types/core/xlsx/formula/fn-math.d.ts +3 -0
- package/dist/types/core/xlsx/formula/fn-stats.d.ts +3 -0
- package/dist/types/core/xlsx/formula/fn-text.d.ts +3 -0
- package/dist/types/core/xlsx/formula/fn.d.ts +64 -0
- package/dist/types/core/xlsx/formula/format.d.ts +5 -0
- package/dist/types/core/xlsx/formula/functions.d.ts +4 -0
- package/dist/types/core/xlsx/formula/index.d.ts +17 -0
- package/dist/types/core/xlsx/formula/lexer.d.ts +54 -0
- package/dist/types/core/xlsx/formula/parser.d.ts +53 -0
- package/dist/types/core/xlsx/formula/refs.d.ts +23 -0
- package/dist/types/core/xlsx/formula/transform.d.ts +21 -0
- package/dist/types/core/xlsx/formula/types.d.ts +59 -0
- package/dist/types/core/xlsx/formula/values.d.ts +49 -0
- package/dist/types/core/xlsx/numfmt.d.ts +11 -0
- package/dist/types/core/xlsx/structure.d.ts +31 -0
- package/dist/types/core/xlsx/styles.d.ts +17 -0
- package/dist/types/core/xlsx/types.d.ts +193 -0
- package/dist/types/core/xlsx/workbook.d.ts +94 -0
- package/dist/types/core/xml.d.ts +80 -0
- package/dist/types/core/zip.d.ts +35 -0
- package/dist/types/core/zipwrite.d.ts +9 -0
- package/dist/types/embed.d.ts +30 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/react/DocViewer.d.ts +43 -0
- package/dist/types/react/common/ContextMenu.d.ts +21 -0
- package/dist/types/react/common/Dialog.d.ts +27 -0
- package/dist/types/react/common/Slots.d.ts +18 -0
- package/dist/types/react/common/Status.d.ts +6 -0
- package/dist/types/react/common/ZoomControl.d.ts +6 -0
- package/dist/types/react/common/hooks.d.ts +20 -0
- package/dist/types/react/docx/DocxEditor.d.ts +172 -0
- package/dist/types/react/docx/DocxToolbar.d.ts +18 -0
- package/dist/types/react/docx/DocxView.d.ts +8 -0
- package/dist/types/react/docx/FindBar.d.ts +22 -0
- package/dist/types/react/docx/html.d.ts +8 -0
- package/dist/types/react/docx/render.d.ts +24 -0
- package/dist/types/react/docx/tables.d.ts +20 -0
- package/dist/types/react/edit/Toolbar.d.ts +130 -0
- package/dist/types/react/edit/input.d.ts +81 -0
- package/dist/types/react/edit/rich.d.ts +40 -0
- package/dist/types/react/injectStyles.d.ts +4 -0
- package/dist/types/react/pptx/PptxEditor.d.ts +95 -0
- package/dist/types/react/pptx/PptxToolbar.d.ts +36 -0
- package/dist/types/react/pptx/PptxView.d.ts +24 -0
- package/dist/types/react/pptx/Presenter.d.ts +9 -0
- package/dist/types/react/pptx/Slide.d.ts +28 -0
- package/dist/types/react/pptx/geometry.d.ts +5 -0
- package/dist/types/react/useDocument.d.ts +11 -0
- package/dist/types/react/xlsx/XlsxToolbar.d.ts +27 -0
- package/dist/types/react/xlsx/XlsxView.d.ts +16 -0
- package/dist/types/react/xlsx/axis.d.ts +19 -0
- package/dist/xlsx-ops-CsjNpMI0.js +244 -0
- package/dist/xlsx-ops-CsjNpMI0.js.map +1 -0
- package/package.json +80 -4
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type RefAddr } from './refs';
|
|
2
|
+
export interface FormulaRef {
|
|
3
|
+
/** span in the full text (including the leading '=') */
|
|
4
|
+
s: number;
|
|
5
|
+
e: number;
|
|
6
|
+
text: string;
|
|
7
|
+
ref: RefAddr;
|
|
8
|
+
}
|
|
9
|
+
export interface FormulaContext {
|
|
10
|
+
/** identifier right before the caret (to autocomplete); span in the full text */
|
|
11
|
+
word?: {
|
|
12
|
+
s: number;
|
|
13
|
+
e: number;
|
|
14
|
+
text: string;
|
|
15
|
+
call: boolean;
|
|
16
|
+
};
|
|
17
|
+
/** innermost function call around the caret; arg is 0-based */
|
|
18
|
+
call?: {
|
|
19
|
+
name: string;
|
|
20
|
+
arg: number;
|
|
21
|
+
};
|
|
22
|
+
/** a reference can be inserted at the caret */
|
|
23
|
+
pointable: boolean;
|
|
24
|
+
refs: FormulaRef[];
|
|
25
|
+
}
|
|
26
|
+
export declare const isFormula: (text: string) => boolean;
|
|
27
|
+
/** Context of the caret inside formula `text` (full cell text, starting with '='). */
|
|
28
|
+
export declare function formulaContext(text: string, caret: number): FormulaContext;
|
|
29
|
+
/** Reference text for a selected block (`A1`, `A1:B3`, `A:A`, `1:1`), sheet-qualified when `sheet` is given. */
|
|
30
|
+
export declare function rangeText(r0: number, c0: number, r1: number, c1: number, sheet?: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* What Excel does on Enter: upper-cases function names, references and booleans,
|
|
33
|
+
* closes an unterminated string and open parentheses.
|
|
34
|
+
*/
|
|
35
|
+
export declare function closeFormula(text: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface FnInfo {
|
|
2
|
+
name: string;
|
|
3
|
+
args: string[];
|
|
4
|
+
/** last argument repeats (`...`) */
|
|
5
|
+
variadic: boolean;
|
|
6
|
+
desc: string;
|
|
7
|
+
}
|
|
8
|
+
/** All functions offered to the user, sorted by name. */
|
|
9
|
+
export declare function functionCatalog(): FnInfo[];
|
|
10
|
+
export declare function functionInfo(name: string): FnInfo | undefined;
|
|
11
|
+
/** Functions whose name starts with `prefix` (case-insensitive). */
|
|
12
|
+
export declare function suggestFunctions(prefix: string, limit?: number): FnInfo[];
|
|
13
|
+
/** Index of the signature argument to highlight for the `arg`-th (0-based) argument being typed. */
|
|
14
|
+
export declare function argSlot(f: FnInfo, arg: number): number;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Date serials (1900 system with the Lotus leap-year bug, or 1904), date/time text parsing, TEXT() formatting. */
|
|
2
|
+
export declare function getDate1904(): boolean;
|
|
3
|
+
export declare function setDate1904(v: boolean): void;
|
|
4
|
+
/** Serial for y/m/d (m 1-based; month/day overflow normalized like DATE()). */
|
|
5
|
+
export declare function ymdToSerial(y: number, m: number, d: number): number;
|
|
6
|
+
export interface DateParts {
|
|
7
|
+
y: number;
|
|
8
|
+
m: number;
|
|
9
|
+
d: number;
|
|
10
|
+
/** 0 = Sunday */
|
|
11
|
+
dow: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function serialToYmd(serial: number): DateParts;
|
|
14
|
+
/** Seconds of the day (rounded to the nearest second). */
|
|
15
|
+
export declare function serialSeconds(serial: number): number;
|
|
16
|
+
export declare function daysInMonth(y: number, m: number): number;
|
|
17
|
+
/** Serial of a JS Date using its local calendar components. */
|
|
18
|
+
export declare function dateToSerial(dt: Date): number;
|
|
19
|
+
/** Parse date/time text: `yyyy-mm-dd [time]`, `m/d/yyyy [time]`, `hh:mm[:ss] [AM/PM]`. */
|
|
20
|
+
export declare function parseDateText(s: string): number | null;
|
|
21
|
+
export declare function splitSections(fmt: string): string[];
|
|
22
|
+
export declare function isDateFormat(sec: string): boolean;
|
|
23
|
+
export declare function formatDate(serial: number, sec: string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Ev } from './fn';
|
|
2
|
+
import { type Ast, type BinOp } from './parser';
|
|
3
|
+
import { type CellProvider, type EvalContext, type Value } from './types';
|
|
4
|
+
import { RangeV, type Val } from './values';
|
|
5
|
+
export declare function binop(op: BinOp, a: Value, b: Value): Value;
|
|
6
|
+
type Operand = Value | Value[][];
|
|
7
|
+
export declare class Evaluator implements Ev {
|
|
8
|
+
readonly provider: CellProvider;
|
|
9
|
+
readonly sheet: string | undefined;
|
|
10
|
+
readonly r: number;
|
|
11
|
+
readonly c: number;
|
|
12
|
+
constructor(ctx: EvalContext);
|
|
13
|
+
eval(ast: Ast, top: boolean): Val;
|
|
14
|
+
private ref;
|
|
15
|
+
private rangeOp;
|
|
16
|
+
private call;
|
|
17
|
+
hasSheet(name: string): boolean;
|
|
18
|
+
now(): Date;
|
|
19
|
+
cell(sheet: string | undefined, r: number, c: number): Value;
|
|
20
|
+
/** Clip whole-row/whole-column style ranges to the provider's used extent. */
|
|
21
|
+
private clip;
|
|
22
|
+
forEach(rg: RangeV, cb: (v: Value, i: number, j: number) => void): void;
|
|
23
|
+
toArray(v: Val): Value[][];
|
|
24
|
+
/** Implicit intersection of a range with the formula cell's row/column. */
|
|
25
|
+
intersect(rg: RangeV): Value;
|
|
26
|
+
scalar(v: Val): Value;
|
|
27
|
+
operand(v: Val, top: boolean): Operand;
|
|
28
|
+
}
|
|
29
|
+
/** Evaluate a parsed formula for the cell at ctx.{sheet,r,c}. Never throws; errors come back as FormulaError. */
|
|
30
|
+
export declare function evaluate(ast: Ast, ctx: EvalContext): Value;
|
|
31
|
+
/** Parse + evaluate. Syntax errors evaluate to #NAME?. */
|
|
32
|
+
export declare function evaluateFormula(text: string, ctx: EvalContext): Value;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** Function-definition plumbing: evaluator interface, arity, array lifting, argument visitors. */
|
|
2
|
+
import type { Ast } from './parser';
|
|
3
|
+
import { FormulaError, type Value } from './types';
|
|
4
|
+
import { RangeV, type Val } from './values';
|
|
5
|
+
/** What a function implementation may ask of the evaluator. */
|
|
6
|
+
export interface Ev {
|
|
7
|
+
readonly sheet: string | undefined;
|
|
8
|
+
/** 0-based formula cell position */
|
|
9
|
+
readonly r: number;
|
|
10
|
+
readonly c: number;
|
|
11
|
+
eval(ast: Ast, top: boolean): Val;
|
|
12
|
+
cell(sheet: string | undefined, r: number, c: number): Value;
|
|
13
|
+
/** visit cells of a range (whole-row/col ranges clipped to the provider's bounds) */
|
|
14
|
+
forEach(rg: RangeV, cb: (v: Value, i: number, j: number) => void): void;
|
|
15
|
+
/** 2-D values of a range/array/scalar (clipped like forEach); unions -> #VALUE! thrown */
|
|
16
|
+
toArray(v: Val): Value[][];
|
|
17
|
+
/** single value: 1x1 range -> cell, larger range -> implicit intersection, array -> top-left */
|
|
18
|
+
scalar(v: Val): Value;
|
|
19
|
+
/** operator operand: scalar, or 2-D data when array-evaluated (top=false) */
|
|
20
|
+
operand(v: Val, top: boolean): Value | Value[][];
|
|
21
|
+
hasSheet(name: string): boolean;
|
|
22
|
+
now(): Date;
|
|
23
|
+
}
|
|
24
|
+
export type EagerFn = (args: Val[], ev: Ev, top: boolean) => Val;
|
|
25
|
+
export type LazyFn = (args: Ast[], ev: Ev, top: boolean) => Val;
|
|
26
|
+
export type FnDef =
|
|
27
|
+
/** args evaluated first; `scalarArgs` => args inherit the caller's top-level (implicit intersection) context */
|
|
28
|
+
{
|
|
29
|
+
kind: 'eager';
|
|
30
|
+
min: number;
|
|
31
|
+
max: number;
|
|
32
|
+
scalarArgs: boolean;
|
|
33
|
+
fn: EagerFn;
|
|
34
|
+
}
|
|
35
|
+
/** receives unevaluated args (IF, IFERROR, CHOOSE, ...) */
|
|
36
|
+
| {
|
|
37
|
+
kind: 'lazy';
|
|
38
|
+
min: number;
|
|
39
|
+
max: number;
|
|
40
|
+
fn: LazyFn;
|
|
41
|
+
};
|
|
42
|
+
export declare const INF: number;
|
|
43
|
+
/** Run f, converting a thrown FormulaError into a value. */
|
|
44
|
+
export declare function guard<T>(f: () => T): T | FormulaError;
|
|
45
|
+
/** Pick (i,j) from 2-D data with 1-row/1-col broadcasting; out of shape -> #N/A. */
|
|
46
|
+
export declare function pick(d: Value[][], i: number, j: number): Value;
|
|
47
|
+
/**
|
|
48
|
+
* Scalar function, lifted element-wise over array arguments (array formulas / SUMPRODUCT(LEN(A1:A3))).
|
|
49
|
+
* At the formula top level a multi-cell range argument is implicitly intersected instead.
|
|
50
|
+
*/
|
|
51
|
+
export declare function S(min: number, max: number, f: (a: Value[], ev: Ev) => Value): FnDef;
|
|
52
|
+
/** Function taking ranges/arrays as-is (args evaluated in array context). */
|
|
53
|
+
export declare function A(min: number, max: number, fn: EagerFn): FnDef;
|
|
54
|
+
/** Lazy function (receives ASTs). */
|
|
55
|
+
export declare function L(min: number, max: number, fn: LazyFn): FnDef;
|
|
56
|
+
/** Visit every value of an argument: cells/array items via `inRange`, direct scalars via `direct`. */
|
|
57
|
+
export declare function visit(a: Val, ev: Ev, inRange: (v: Value) => void, direct: (v: Value) => void): void;
|
|
58
|
+
/** Numbers of aggregate args: ranges contribute numbers only, direct scalars coerce; errors throw. */
|
|
59
|
+
export declare function eachNum(args: Val[], ev: Ev, cb: (n: number) => void): void;
|
|
60
|
+
export declare function nums(args: Val[], ev: Ev): number[];
|
|
61
|
+
/** Flatten a range/array to a row-major list. */
|
|
62
|
+
export declare function flat(d: Value[][]): Value[];
|
|
63
|
+
/** Optional numeric arg i (missing argument => 0 like Excel; absent => def). */
|
|
64
|
+
export declare function opt(a: Value[], i: number, def: number): number;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Value } from './types';
|
|
2
|
+
/** Round half away from zero to d decimals, removing binary noise first. */
|
|
3
|
+
export declare function roundHalf(x: number, d: number): number;
|
|
4
|
+
/** TEXT(value, format). Throws FormulaError on invalid input. */
|
|
5
|
+
export declare function formatText(v: Value, fmt: string): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Excel formula engine: parse, evaluate, rewrite (fill / insert-delete / rename) and dependency extraction. */
|
|
2
|
+
export { ERROR_CODES, FormulaError, MAX_COL, MAX_ROW } from './types';
|
|
3
|
+
export type { CellProvider, CellRef, ErrorCode, EvalContext, RangeRef, Value } from './types';
|
|
4
|
+
export { FormulaSyntaxError } from './lexer';
|
|
5
|
+
export { parseFormula } from './parser';
|
|
6
|
+
export type { Ast, BinOp } from './parser';
|
|
7
|
+
export type { RefAddr } from './refs';
|
|
8
|
+
export { colIndex, colName, quoteSheet } from './refs';
|
|
9
|
+
export { evaluate, evaluateFormula } from './evaluate';
|
|
10
|
+
export { references, renameSheetInFormula, shiftFormula, translateFormula } from './transform';
|
|
11
|
+
export type { ShiftOp } from './transform';
|
|
12
|
+
export { supportedFunctions } from './functions';
|
|
13
|
+
export { numToText, parseNumberText } from './values';
|
|
14
|
+
export { closeFormula, formulaContext, isFormula, rangeText } from './assist';
|
|
15
|
+
export type { FormulaContext, FormulaRef } from './assist';
|
|
16
|
+
export { argSlot, functionCatalog, functionInfo, suggestFunctions } from './catalog';
|
|
17
|
+
export type { FnInfo } from './catalog';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Tokenizer for OOXML formula text (no leading '='). Tokens carry source spans so transforms can splice text. */
|
|
2
|
+
import { type RefAddr } from './refs';
|
|
3
|
+
import { type ErrorCode } from './types';
|
|
4
|
+
export declare class FormulaSyntaxError extends Error {
|
|
5
|
+
readonly pos: number;
|
|
6
|
+
constructor(message: string, pos: number);
|
|
7
|
+
}
|
|
8
|
+
interface Span {
|
|
9
|
+
s: number;
|
|
10
|
+
e: number;
|
|
11
|
+
}
|
|
12
|
+
export type Token = Span & ({
|
|
13
|
+
t: 'num';
|
|
14
|
+
v: number;
|
|
15
|
+
} | {
|
|
16
|
+
t: 'str';
|
|
17
|
+
v: string;
|
|
18
|
+
} | {
|
|
19
|
+
t: 'bool';
|
|
20
|
+
v: boolean;
|
|
21
|
+
} | {
|
|
22
|
+
t: 'err';
|
|
23
|
+
v: ErrorCode;
|
|
24
|
+
sheet?: string;
|
|
25
|
+
} | {
|
|
26
|
+
t: 'ref';
|
|
27
|
+
ref: RefAddr;
|
|
28
|
+
sheetText?: string;
|
|
29
|
+
} | {
|
|
30
|
+
t: 'func';
|
|
31
|
+
v: string;
|
|
32
|
+
} | {
|
|
33
|
+
t: 'name';
|
|
34
|
+
v: string;
|
|
35
|
+
sheet?: string;
|
|
36
|
+
} | {
|
|
37
|
+
t: 'op';
|
|
38
|
+
v: string;
|
|
39
|
+
} | {
|
|
40
|
+
t: 'punc';
|
|
41
|
+
v: string;
|
|
42
|
+
} | {
|
|
43
|
+
t: 'ws';
|
|
44
|
+
});
|
|
45
|
+
/** Try to read an A1 reference (cell, area, A:B, 1:2) at i. */
|
|
46
|
+
export declare function readRef(src: string, i: number): {
|
|
47
|
+
ref: RefAddr;
|
|
48
|
+
end: number;
|
|
49
|
+
} | null;
|
|
50
|
+
export declare function stripFnPrefix(name: string): string;
|
|
51
|
+
export declare function tokenize(src: string): Token[];
|
|
52
|
+
/** Parse a plain reference string (INDIRECT): `A1`, `Sheet1!A1:B2`, `'x y'!C:C`, `3:3`. */
|
|
53
|
+
export declare function parseRefText(text: string): RefAddr | null;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { RefAddr } from './refs';
|
|
2
|
+
import type { ErrorCode, Value } from './types';
|
|
3
|
+
export type BinOp = '+' | '-' | '*' | '/' | '^' | '&' | '=' | '<>' | '<' | '>' | '<=' | '>=';
|
|
4
|
+
export type Ast = {
|
|
5
|
+
type: 'num';
|
|
6
|
+
value: number;
|
|
7
|
+
} | {
|
|
8
|
+
type: 'str';
|
|
9
|
+
value: string;
|
|
10
|
+
} | {
|
|
11
|
+
type: 'bool';
|
|
12
|
+
value: boolean;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'err';
|
|
15
|
+
code: ErrorCode;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'missing';
|
|
18
|
+
} | {
|
|
19
|
+
type: 'ref';
|
|
20
|
+
ref: RefAddr;
|
|
21
|
+
} | {
|
|
22
|
+
type: 'name';
|
|
23
|
+
name: string;
|
|
24
|
+
sheet?: string;
|
|
25
|
+
} | {
|
|
26
|
+
type: 'array';
|
|
27
|
+
rows: Value[][];
|
|
28
|
+
} | {
|
|
29
|
+
type: 'unary';
|
|
30
|
+
op: '-' | '+';
|
|
31
|
+
arg: Ast;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'percent';
|
|
34
|
+
arg: Ast;
|
|
35
|
+
} | {
|
|
36
|
+
type: 'binary';
|
|
37
|
+
op: BinOp;
|
|
38
|
+
left: Ast;
|
|
39
|
+
right: Ast;
|
|
40
|
+
} | {
|
|
41
|
+
type: 'range';
|
|
42
|
+
left: Ast;
|
|
43
|
+
right: Ast;
|
|
44
|
+
} | {
|
|
45
|
+
type: 'union';
|
|
46
|
+
items: Ast[];
|
|
47
|
+
} | {
|
|
48
|
+
type: 'call';
|
|
49
|
+
name: string;
|
|
50
|
+
args: Ast[];
|
|
51
|
+
};
|
|
52
|
+
/** Parse formula text (OOXML stored form, without '='; a leading '=' is tolerated). Throws FormulaSyntaxError. */
|
|
53
|
+
export declare function parseFormula(text: string): Ast;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Parsed A1 reference as written in a formula (0-based, inclusive, normalized r0<=r1, c0<=c1). */
|
|
2
|
+
export interface RefAddr {
|
|
3
|
+
sheet?: string;
|
|
4
|
+
kind: 'cell' | 'area' | 'cols' | 'rows';
|
|
5
|
+
r0: number;
|
|
6
|
+
c0: number;
|
|
7
|
+
r1: number;
|
|
8
|
+
c1: number;
|
|
9
|
+
ar0: boolean;
|
|
10
|
+
ac0: boolean;
|
|
11
|
+
ar1: boolean;
|
|
12
|
+
ac1: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function colName(c: number): string;
|
|
15
|
+
export declare function colIndex(letters: string): number;
|
|
16
|
+
export declare function sameSheet(a: string | undefined, b: string | undefined): boolean;
|
|
17
|
+
/** Sheet name as it must appear before '!' (quoted when needed). */
|
|
18
|
+
export declare function quoteSheet(name: string): string;
|
|
19
|
+
/** Reference text. `sheetText` (raw prefix without '!') is reused when given to preserve original quoting. */
|
|
20
|
+
export declare function fmtRef(a: RefAddr, sheetText?: string): string;
|
|
21
|
+
/** Swap ends (with their $ flags) so r0<=r1 and c0<=c1. Mutates. */
|
|
22
|
+
export declare function normalizeRef(a: RefAddr): RefAddr;
|
|
23
|
+
export declare function refInBounds(a: RefAddr): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Ast } from './parser';
|
|
2
|
+
import { type CellRef, type RangeRef } from './types';
|
|
3
|
+
/** Copy/fill: shift relative parts of every reference by (dr, dc). Out-of-sheet results become #REF!. */
|
|
4
|
+
export declare function translateFormula(text: string, dr: number, dc: number): string;
|
|
5
|
+
export interface ShiftOp {
|
|
6
|
+
/** sheet whose rows/cols change (undefined: the formula's own sheet) */
|
|
7
|
+
sheet?: string;
|
|
8
|
+
/** sheet the formula lives on (unqualified refs belong to it; undefined: same as `sheet`) */
|
|
9
|
+
formulaSheet?: string;
|
|
10
|
+
axis: 'row' | 'col';
|
|
11
|
+
/** 0-based index of the first inserted/deleted row/col */
|
|
12
|
+
at: number;
|
|
13
|
+
/** >0 insert count, <0 delete count */
|
|
14
|
+
delta: number;
|
|
15
|
+
}
|
|
16
|
+
/** Rewrite references after inserting/deleting rows or columns. */
|
|
17
|
+
export declare function shiftFormula(text: string, op: ShiftOp): string;
|
|
18
|
+
/** Rename sheet qualifiers (`Old!A1`, `'Old'!A1:B2`, `Old!#REF!`, `Old!Name`). */
|
|
19
|
+
export declare function renameSheetInFormula(text: string, oldName: string, newName: string): string;
|
|
20
|
+
/** Every cell/range the formula reads directly (static references; INDIRECT/OFFSET targets are dynamic). */
|
|
21
|
+
export declare function references(ast: Ast): (CellRef | RangeRef)[];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** Core value / reference / provider types of the formula engine. */
|
|
2
|
+
export type ErrorCode = '#DIV/0!' | '#VALUE!' | '#REF!' | '#NAME?' | '#N/A' | '#NUM!' | '#NULL!';
|
|
3
|
+
/** ERROR.TYPE order (1-based). */
|
|
4
|
+
export declare const ERROR_CODES: readonly ErrorCode[];
|
|
5
|
+
export declare class FormulaError {
|
|
6
|
+
readonly code: ErrorCode;
|
|
7
|
+
constructor(code: ErrorCode);
|
|
8
|
+
toString(): string;
|
|
9
|
+
}
|
|
10
|
+
/** null = empty cell */
|
|
11
|
+
export type Value = number | string | boolean | FormulaError | null;
|
|
12
|
+
/** 0-based cell reference. */
|
|
13
|
+
export interface CellRef {
|
|
14
|
+
sheet?: string;
|
|
15
|
+
r: number;
|
|
16
|
+
c: number;
|
|
17
|
+
absR: boolean;
|
|
18
|
+
absC: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** 0-based inclusive range. Whole column A:A => r0=0, r1=MAX_ROW; whole row 1:1 => c0=0, c1=MAX_COL. */
|
|
21
|
+
export interface RangeRef {
|
|
22
|
+
sheet?: string;
|
|
23
|
+
r0: number;
|
|
24
|
+
c0: number;
|
|
25
|
+
r1: number;
|
|
26
|
+
c1: number;
|
|
27
|
+
}
|
|
28
|
+
export interface CellProvider {
|
|
29
|
+
/** value of a cell; formula cells return their current computed value */
|
|
30
|
+
value(sheet: string | undefined, r: number, c: number): Value;
|
|
31
|
+
/** used extent of a sheet, to clip whole-row/column ranges (optional) */
|
|
32
|
+
bounds?(sheet: string | undefined): {
|
|
33
|
+
rows: number;
|
|
34
|
+
cols: number;
|
|
35
|
+
};
|
|
36
|
+
/** sheet exists? (unknown sheet -> #REF!) optional */
|
|
37
|
+
hasSheet?(name: string): boolean;
|
|
38
|
+
date1904?: boolean;
|
|
39
|
+
now?(): Date;
|
|
40
|
+
}
|
|
41
|
+
export interface EvalContext {
|
|
42
|
+
provider: CellProvider;
|
|
43
|
+
/** sheet the formula lives on (unqualified refs resolve here) */
|
|
44
|
+
sheet?: string;
|
|
45
|
+
/** 0-based position of the formula cell */
|
|
46
|
+
r: number;
|
|
47
|
+
c: number;
|
|
48
|
+
}
|
|
49
|
+
export declare const MAX_ROW = 1048575;
|
|
50
|
+
export declare const MAX_COL = 16383;
|
|
51
|
+
export declare const ERR: {
|
|
52
|
+
readonly DIV0: FormulaError;
|
|
53
|
+
readonly VALUE: FormulaError;
|
|
54
|
+
readonly REF: FormulaError;
|
|
55
|
+
readonly NAME: FormulaError;
|
|
56
|
+
readonly NA: FormulaError;
|
|
57
|
+
readonly NUM: FormulaError;
|
|
58
|
+
readonly NULL: FormulaError;
|
|
59
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { FormulaError, type Value } from './types';
|
|
2
|
+
/** Reference to a rectangular block of cells (0-based inclusive). */
|
|
3
|
+
export declare class RangeV {
|
|
4
|
+
readonly sheet: string | undefined;
|
|
5
|
+
readonly r0: number;
|
|
6
|
+
readonly c0: number;
|
|
7
|
+
readonly r1: number;
|
|
8
|
+
readonly c1: number;
|
|
9
|
+
constructor(sheet: string | undefined, r0: number, c0: number, r1: number, c1: number);
|
|
10
|
+
get h(): number;
|
|
11
|
+
get w(): number;
|
|
12
|
+
}
|
|
13
|
+
/** In-memory array (array constants and array-evaluated results). Always at least 1x1. */
|
|
14
|
+
export declare class ArrayV {
|
|
15
|
+
readonly data: Value[][];
|
|
16
|
+
constructor(data: Value[][]);
|
|
17
|
+
get h(): number;
|
|
18
|
+
get w(): number;
|
|
19
|
+
}
|
|
20
|
+
/** Multi-area reference `(A1:B2,D4)`. */
|
|
21
|
+
export declare class UnionV {
|
|
22
|
+
readonly areas: RangeV[];
|
|
23
|
+
constructor(areas: RangeV[]);
|
|
24
|
+
}
|
|
25
|
+
export type Val = Value | RangeV | ArrayV | UnionV;
|
|
26
|
+
export declare const isErr: (v: unknown) => v is FormulaError;
|
|
27
|
+
/** Numeric text -> number (plain, 1,234.5, 50%, $3, 1E3, dates, times); null when not numeric. */
|
|
28
|
+
export declare function parseNumberText(s: string): number | null;
|
|
29
|
+
/** Excel "General" text of a number (15 significant digits). */
|
|
30
|
+
export declare function numToText(n: number): string;
|
|
31
|
+
export declare function toNum(v: Value): number | FormulaError;
|
|
32
|
+
export declare function toStr(v: Value): string | FormulaError;
|
|
33
|
+
export declare function toBool(v: Value): boolean | FormulaError;
|
|
34
|
+
export declare function num(v: Value): number;
|
|
35
|
+
export declare function int(v: Value): number;
|
|
36
|
+
export declare function str(v: Value): string;
|
|
37
|
+
export declare function bool(v: Value): boolean;
|
|
38
|
+
/** Throw if v is an error, else return it. */
|
|
39
|
+
export declare function check<T extends Value>(v: T): Exclude<T, FormulaError>;
|
|
40
|
+
export declare function numEq(a: number, b: number): boolean;
|
|
41
|
+
/** Excel ordering: numbers < text < booleans; text case-insensitive; empty adopts the other side's type. Errors not allowed. */
|
|
42
|
+
export declare function compare(a: Value, b: Value): number;
|
|
43
|
+
/** Lookup equality: same type, text case-insensitive. */
|
|
44
|
+
export declare function valueEq(a: Value, b: Value): boolean;
|
|
45
|
+
export declare const hasWildcard: (s: string) => boolean;
|
|
46
|
+
export declare function wildcardRe(pat: string, anchored?: boolean): RegExp;
|
|
47
|
+
export type Matcher = (v: Value) => boolean;
|
|
48
|
+
/** Criteria of COUNTIF/SUMIF/...: "<5", ">=10", "<>x", "=abc", "a*c", 3, TRUE, "" (blank). */
|
|
49
|
+
export declare function criteria(crit: Value): Matcher;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Excel number-format subset: General, fixed/grouped/percent/scientific/fraction, dates & times, sections & colors. */
|
|
2
|
+
export declare const BUILTIN_FORMATS: Record<number, string>;
|
|
3
|
+
export declare function isDateFormat(fmt: string): boolean;
|
|
4
|
+
export declare function formatGeneral(v: number): string;
|
|
5
|
+
export declare function serialToDate(serial: number, date1904?: boolean): Date;
|
|
6
|
+
export interface Formatted {
|
|
7
|
+
text: string;
|
|
8
|
+
color?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function formatValue(v: number, fmt: string | undefined, date1904?: boolean): Formatted;
|
|
11
|
+
export declare function formatText(s: string, fmt: string | undefined): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ColInfo, Merge, Range } from './types';
|
|
2
|
+
import { type SheetData } from './workbook';
|
|
3
|
+
export interface Snapshot {
|
|
4
|
+
rows: (unknown[] | undefined)[];
|
|
5
|
+
formulas: Map<number, string>;
|
|
6
|
+
merges: Merge[];
|
|
7
|
+
colInfo: ColInfo[];
|
|
8
|
+
rowAttrs: Map<number, {
|
|
9
|
+
ht?: number;
|
|
10
|
+
hidden?: boolean;
|
|
11
|
+
}>;
|
|
12
|
+
autoRowH: Map<number, number>;
|
|
13
|
+
maxRow: number;
|
|
14
|
+
maxCol: number;
|
|
15
|
+
frozen: {
|
|
16
|
+
rows: number;
|
|
17
|
+
cols: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare function snapshot(d: SheetData): Snapshot;
|
|
21
|
+
export declare function restore(d: SheetData, s: Snapshot): void;
|
|
22
|
+
/** shared formulas → explicit per-cell formulas (needed before rows/cols move) */
|
|
23
|
+
export declare function materializeShared(d: SheetData): void;
|
|
24
|
+
/** Moves rows or columns; delta > 0 inserts at `at`, delta < 0 deletes -delta starting at `at`. */
|
|
25
|
+
export declare function shiftSheet(d: SheetData, sheetName: string, axis: 'row' | 'col', at: number, delta: number, others: {
|
|
26
|
+
name: string;
|
|
27
|
+
d: SheetData;
|
|
28
|
+
}[]): void;
|
|
29
|
+
export declare function setMerge(d: SheetData, range: Range, merge: boolean): void;
|
|
30
|
+
export declare function setColWidth(d: SheetData, c0: number, c1: number, px: number): void;
|
|
31
|
+
export declare function setRowHeight(d: SheetData, r0: number, r1: number, px: number): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Theme } from '../theme';
|
|
2
|
+
import { type XEl } from '../xml';
|
|
3
|
+
import type { CellCss } from './types';
|
|
4
|
+
export interface XfInfo {
|
|
5
|
+
numFmt: string;
|
|
6
|
+
/** font size in pt */
|
|
7
|
+
fontPt: number;
|
|
8
|
+
css: CellCss;
|
|
9
|
+
/** explicit horizontal alignment */
|
|
10
|
+
hAlign?: string;
|
|
11
|
+
wrap: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface SheetStyles {
|
|
14
|
+
xfs: XfInfo[];
|
|
15
|
+
baseFont: CellCss;
|
|
16
|
+
}
|
|
17
|
+
export declare function parseSheetStyles(root: XEl | undefined, theme: Theme): SheetStyles;
|