@betteroffice/xlsx 0.0.3 → 0.0.5

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/dist/index.d.cts DELETED
@@ -1,216 +0,0 @@
1
- import { DisplayList } from './headless.cjs';
2
- export { A11yCell, A11yColumnHeader, A11yGrid, A11yRow, A11yStrings, CellAddr, CellInput, CellRange, Direction, DrawCmd, FillRectCmd, GridMeta, KeyInput, LineCmd, MoveOpts, Rect, Selection, SelectionAction, SelectionLimits, TextAlign, TextCmd, TrackOffsets, ViewportState, VisibleCells, VisibleRange, buildA11yGrid, cellAtPoint, cellCount, cellRect, clampScroll, extendTo, fromTsv, moveFocus, normalizeRange, rangeContains, rangeRect, selectionAt, selectionKeyReducer, toTsv, totalExtent, trackCount, uniformOffsets, visibleCells, visibleRange } from './headless.cjs';
3
-
4
- /**
5
- * Canvas2D backend for the display list — the browser paint target.
6
- *
7
- * DOM canvas types are used deliberately here; this file is the browser backend
8
- * and is excluded from the pure seam (viewport/ + display-list/). The function
9
- * is otherwise pure: it reads a plain display list and issues draw calls, with
10
- * no allocation of app state and no reads back from the canvas.
11
- */
12
-
13
- /**
14
- * Paint a display list into a 2D context. `dpr` maps device-independent list
15
- * coordinates onto the backing store, so callers size the canvas at
16
- * `width * dpr` × `height * dpr` and this sets the matching transform.
17
- */
18
- declare function paintDisplayList(ctx: CanvasRenderingContext2D, dl: DisplayList, dpr: number): void;
19
-
20
- /**
21
- * Wasm loader for the xlsx-wasm core.
22
- *
23
- * The core is embedded as base64 (`generated/wasmBase64.ts`) and initialized
24
- * synchronously on first use — no fetch, no external asset, so it works
25
- * identically in the browser, bun, node, SSR, and CI (needs a CSP allowing
26
- * `wasm-unsafe-eval`). Callers never see the JSON-string boundary: `openWorkbook`
27
- * returns a typed {@link WorkbookHandle} and wasm throws surface as `Error`.
28
- */
29
-
30
- /**
31
- * A scrolled window into a sheet, in content pixels from the sheet origin — the
32
- * argument the renderer needs to build a frame. Mirrors the Rust `Viewport`.
33
- */
34
- interface Viewport {
35
- x: number;
36
- y: number;
37
- width: number;
38
- height: number;
39
- }
40
- /**
41
- * Chrome-facing sheet metadata: tab names, active index, and the scrollable
42
- * content extent of the active sheet. Mirrors the Rust `SheetInfo`.
43
- */
44
- interface SheetInfo {
45
- sheetNames: string[];
46
- activeSheet: number;
47
- contentWidth: number;
48
- contentHeight: number;
49
- }
50
- /**
51
- * Result of any mutating call: whether it changed the workbook and the
52
- * (possibly grown) sheet metadata. Mirrors the Rust `EditResult`.
53
- *
54
- * `changed` lists the a1 addresses (on the active sheet) of *other* cells whose
55
- * displayed value moved as a fallout of the edit — the dependents the recalc
56
- * pass recomputed. It excludes the directly edited cell(s) and is omitted by
57
- * cores built before the recalc engine, so treat it as additive.
58
- */
59
- interface EditResult {
60
- applied: boolean;
61
- sheetInfo: SheetInfo;
62
- changed?: string[];
63
- }
64
- /**
65
- * The editable view of one cell: A1 address, the exact string the user would
66
- * edit (formulas as `=...`, guarded literals with a leading `'`), and whether
67
- * that string is a formula. Mirrors the Rust `CellEdit`.
68
- */
69
- interface CellEdit {
70
- a1: string;
71
- input: string;
72
- isFormula: boolean;
73
- }
74
- /** One cell of a batch edit: target coordinates plus the raw user input. */
75
- interface CellInputEdit {
76
- row: number;
77
- col: number;
78
- input: string;
79
- }
80
- /**
81
- * One edit inside a proposal. Same shape as {@link CellInputEdit} plus the
82
- * sheet index — a proposal's cells carry their own sheet on the wire, so it
83
- * can span sheets rather than being pinned to the active one.
84
- */
85
- interface ProposalEdit extends CellInputEdit {
86
- sheet: number;
87
- }
88
- /**
89
- * One cell of a pending proposal: where it lands and the *formatted display
90
- * texts* before/after applying it. `oldText`/`newText` are what the grid shows,
91
- * not the raw input — the ghost decoration paints `newText` directly. Mirrors
92
- * the Rust proposal cell.
93
- */
94
- interface ProposalCell {
95
- sheet: number;
96
- row: number;
97
- col: number;
98
- a1: string;
99
- oldText: string;
100
- newText: string;
101
- }
102
- /**
103
- * A pending, un-applied set of cell changes an agent has staged for human
104
- * review. `note` is the agent's rationale (may be null); `cells` are the
105
- * per-cell before/after previews. Applying it is one undo step.
106
- */
107
- interface Proposal {
108
- id: string;
109
- agentId: string;
110
- note: string | null;
111
- cells: ProposalCell[];
112
- }
113
- /**
114
- * Thrown by {@link WorkbookHandle.acceptProposal} when the workbook changed
115
- * under a proposal since it was staged (an edit touched one of its base cells)
116
- * and `force` was not set. `cells` are the a1 addresses that moved, so the UI
117
- * can name them and offer a force-apply.
118
- */
119
- declare class StaleProposalError extends Error {
120
- readonly cells: string[];
121
- constructor(cells: string[]);
122
- }
123
- /**
124
- * A typed handle over an open workbook, hiding the wasm object and its JSON
125
- * boundary. Call {@link WorkbookHandle.dispose} to free the wasm memory.
126
- */
127
- interface WorkbookHandle {
128
- sheetInfo(): SheetInfo;
129
- displayList(viewport: Viewport): DisplayList;
130
- setActiveSheet(index: number): void;
131
- /**
132
- * apply one user input to a cell (parses number/bool/formula/text) and
133
- * recalc its transitive dependents. one undo step; moved dependents come back
134
- * in `EditResult.changed`.
135
- */
136
- editCell(sheet: number, row: number, col: number, input: string): EditResult;
137
- /** apply a batch of inputs (paste path) as one undo step; dependents recalc. */
138
- editCells(sheet: number, edits: CellInputEdit[]): EditResult;
139
- /** raw op-list escape hatch for structural ops (insert/delete rows, merges…). */
140
- applyOps(ops: unknown[]): EditResult;
141
- undo(): EditResult;
142
- redo(): EditResult;
143
- /** the editable view of one cell (formula bar / in-cell editor prefill). */
144
- cell(sheet: number, row: number, col: number): CellEdit;
145
- /** row-major editable views for a range, e.g. "A1:C3" (clipboard copy). */
146
- rangeCells(sheet: number, range: string): CellEdit[][];
147
- /**
148
- * render the current sheet viewport to png bytes via the native raster
149
- * backend — the same display list the canvas paints, rasterized server-side.
150
- * throws if the embedded wasm was built without png export (the `raster`
151
- * cargo feature); guard with {@link isPngExportAvailable}.
152
- */
153
- renderPng(viewport: Viewport): Uint8Array;
154
- /**
155
- * render an a1 range (default: the used range) at an optional scale to png.
156
- * dimensions are capped wasm-side; same availability guard as renderPng.
157
- */
158
- renderRangePng(opts?: {
159
- range?: string;
160
- scale?: number;
161
- }): Uint8Array;
162
- /** serialize the workbook back to .xlsx bytes. */
163
- save(): Uint8Array;
164
- /**
165
- * stage an agent's proposed edits for human review without applying them.
166
- * returns the {@link Proposal} with per-cell formatted before/after previews.
167
- * throws if the embedded wasm predates proposals; guard with
168
- * {@link WorkbookHandle.isProposalsAvailable}.
169
- */
170
- propose(agentId: string, note: string | null, edits: ProposalEdit[]): Proposal;
171
- /** every pending proposal, oldest first. empty when none or unsupported. */
172
- listProposals(): Proposal[];
173
- /**
174
- * apply a pending proposal as one undo step and recalc dependents. throws
175
- * {@link StaleProposalError} when the base changed since it was staged and
176
- * `force` is not set; pass `{ force: true }` to apply anyway.
177
- */
178
- acceptProposal(id: string, opts?: {
179
- force?: boolean;
180
- }): EditResult & {
181
- proposalId: string;
182
- };
183
- /** drop a pending proposal without applying it; false when the id was unknown. */
184
- rejectProposal(id: string): boolean;
185
- /** whether the embedded wasm core was built with the proposals api. */
186
- isProposalsAvailable(): boolean;
187
- dispose(): void;
188
- }
189
- /**
190
- * Whether the embedded wasm core can initialize in this environment. Attempts
191
- * init (idempotent) and reports success so callers can degrade explicitly.
192
- */
193
- declare function isWasmAvailable(): boolean;
194
- /**
195
- * Whether the embedded wasm core was built with png export (the `raster` cargo
196
- * feature). The wasm-bindgen method only exists on the class when compiled in,
197
- * so chrome can disable an export control instead of calling and catching.
198
- */
199
- declare function isPngExportAvailable(): boolean;
200
- /**
201
- * Whether the embedded wasm core exposes the proposals api (propose / accept /
202
- * reject / list). The methods only exist on the class when compiled in, so the
203
- * UI can hide proposal chrome and degrade gracefully against an older module.
204
- */
205
- declare function isProposalsAvailable(): boolean;
206
- /**
207
- * Open a workbook from raw `.xlsx` bytes, initializing the core if needed.
208
- * Throws an `Error` if the bytes are not a readable workbook.
209
- */
210
- declare function openWorkbook(bytes: Uint8Array): WorkbookHandle;
211
- /**
212
- * The crate version string, for asserting wasm/js parity.
213
- */
214
- declare function wasmVersion(): string;
215
-
216
- export { type CellEdit, type CellInputEdit, DisplayList, type EditResult, type Proposal, type ProposalCell, type ProposalEdit, type SheetInfo, StaleProposalError, type Viewport, type WorkbookHandle, isPngExportAvailable, isProposalsAvailable, isWasmAvailable, openWorkbook, paintDisplayList, wasmVersion };