@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/README.md CHANGED
@@ -1,9 +1,8 @@
1
1
  # @betteroffice/xlsx
2
2
 
3
3
  Framework-free core for the BetterOffice XLSX editor — the Rust engine (parse,
4
- calc, render) compiled to WebAssembly and bundled in, plus display-list,
5
- viewport, hit-test, and accessibility helpers. There's no separate wasm asset to
6
- host.
4
+ calc, render) compiled to WebAssembly, plus display-list, viewport, hit-test, and
5
+ accessibility helpers.
7
6
 
8
7
  > **Experimental (`0.0.x`).** The API is unstable and may change in any release.
9
8
 
@@ -18,13 +17,23 @@ Reach for this package directly to render a spreadsheet onto your own canvas.
18
17
  ## Usage
19
18
 
20
19
  ```ts
21
- import { openWorkbook } from "@betteroffice/xlsx";
20
+ import { initWasm, openWorkbook } from "@betteroffice/xlsx";
22
21
 
23
- // parse + load into the wasm engine (calc-ready)
22
+ await initWasm();
24
23
  const bytes = new Uint8Array(await file.arrayBuffer());
25
24
  const workbook = openWorkbook(bytes);
26
25
  ```
27
26
 
27
+ `initWasm()` fetches the packaged wasm asset once in browsers. Pass wasm bytes or
28
+ a precompiled `WebAssembly.Module` explicitly in runtimes that cannot fetch the
29
+ asset URL.
30
+
31
+ ## Development
32
+
33
+ The generated `.wasm` binary is intentionally not committed. From the repository
34
+ root, install `wasm-pack` 0.15.0 and run `bun run build:xlsx-wasm`. Package builds,
35
+ tests, demo startup, and CI run this step automatically.
36
+
28
37
  From the returned handle you compose the geometry and rendering helpers this
29
38
  package exports onto your own `<canvas>` 2D context — `paintDisplayList`,
30
39
  `cellAtPoint` / `cellRect` / `rangeRect` (hit-testing), the `viewport` math,
Binary file
package/dist/index.d.ts CHANGED
@@ -17,14 +17,14 @@ export { A11yCell, A11yColumnHeader, A11yGrid, A11yRow, A11yStrings, CellAddr, C
17
17
  */
18
18
  declare function paintDisplayList(ctx: CanvasRenderingContext2D, dl: DisplayList, dpr: number): void;
19
19
 
20
+ type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
21
+
20
22
  /**
21
23
  * Wasm loader for the xlsx-wasm core.
22
24
  *
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`.
25
+ * Call {@link initWasm} once before opening workbooks. The default browser path
26
+ * streams the packaged wasm asset; non-fetch environments can pass bytes or a
27
+ * precompiled module. Callers never see the JSON-string boundary.
28
28
  */
29
29
 
30
30
  /**
@@ -60,6 +60,10 @@ interface EditResult {
60
60
  applied: boolean;
61
61
  sheetInfo: SheetInfo;
62
62
  changed?: string[];
63
+ limitedCells?: string[];
64
+ }
65
+ interface CalculationStatus {
66
+ limitedCells: string[];
63
67
  }
64
68
  /**
65
69
  * The editable view of one cell: A1 address, the exact string the user would
@@ -126,6 +130,7 @@ declare class StaleProposalError extends Error {
126
130
  */
127
131
  interface WorkbookHandle {
128
132
  sheetInfo(): SheetInfo;
133
+ calculationStatus(): CalculationStatus;
129
134
  displayList(viewport: Viewport): DisplayList;
130
135
  setActiveSheet(index: number): void;
131
136
  /**
@@ -186,9 +191,11 @@ interface WorkbookHandle {
186
191
  isProposalsAvailable(): boolean;
187
192
  dispose(): void;
188
193
  }
194
+ type WasmInitInput = InitInput | Promise<InitInput>;
195
+ /** Initialize the workbook engine. Concurrent calls share the same attempt. */
196
+ declare function initWasm(input?: WasmInitInput): Promise<void>;
189
197
  /**
190
- * Whether the embedded wasm core can initialize in this environment. Attempts
191
- * init (idempotent) and reports success so callers can degrade explicitly.
198
+ * Whether this environment exposes the WebAssembly runtime required by the core.
192
199
  */
193
200
  declare function isWasmAvailable(): boolean;
194
201
  /**
@@ -213,4 +220,4 @@ declare function openWorkbook(bytes: Uint8Array): WorkbookHandle;
213
220
  */
214
221
  declare function wasmVersion(): string;
215
222
 
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 };
223
+ export { type CalculationStatus, type CellEdit, type CellInputEdit, DisplayList, type EditResult, type Proposal, type ProposalCell, type ProposalEdit, type SheetInfo, StaleProposalError, type Viewport, type WasmInitInput, type WorkbookHandle, initWasm, isPngExportAvailable, isProposalsAvailable, isWasmAvailable, openWorkbook, paintDisplayList, wasmVersion };