@betteroffice/xlsx 0.0.2 → 0.0.4

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,8 +1,8 @@
1
1
  # @betteroffice/xlsx
2
2
 
3
- Framework-free core for the BetterOffice XLSX editor — display list, viewport
4
- math, and the wasm loader. The Rust engine (parse, calc, render) is compiled to
5
- WebAssembly and bundled in, so there is no separate asset to host.
3
+ Framework-free core for the BetterOffice XLSX editor — the Rust engine (parse,
4
+ calc, render) compiled to WebAssembly, plus display-list, viewport, hit-test, and
5
+ accessibility helpers.
6
6
 
7
7
  > **Experimental (`0.0.x`).** The API is unstable and may change in any release.
8
8
 
@@ -10,6 +10,33 @@ WebAssembly and bundled in, so there is no separate asset to host.
10
10
  bun add @betteroffice/xlsx
11
11
  ```
12
12
 
13
- For a React integration, see [`@betteroffice/xlsx-react`](https://www.npmjs.com/package/@betteroffice/xlsx-react).
13
+ Most apps want the turnkey React component in
14
+ [`@betteroffice/xlsx-react`](https://www.npmjs.com/package/@betteroffice/xlsx-react).
15
+ Reach for this package directly to render a spreadsheet onto your own canvas.
16
+
17
+ ## Usage
18
+
19
+ ```ts
20
+ import { initWasm, openWorkbook } from "@betteroffice/xlsx";
21
+
22
+ await initWasm();
23
+ const bytes = new Uint8Array(await file.arrayBuffer());
24
+ const workbook = openWorkbook(bytes);
25
+ ```
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
+
37
+ From the returned handle you compose the geometry and rendering helpers this
38
+ package exports onto your own `<canvas>` 2D context — `paintDisplayList`,
39
+ `cellAtPoint` / `cellRect` / `rangeRect` (hit-testing), the `viewport` math,
40
+ `buildA11yGrid`, and `toTsv` / `fromTsv` (clipboard).
14
41
 
15
42
  Docs: https://betteroffice.dev · Apache-2.0.
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
  /**
@@ -186,9 +186,11 @@ interface WorkbookHandle {
186
186
  isProposalsAvailable(): boolean;
187
187
  dispose(): void;
188
188
  }
189
+ type WasmInitInput = InitInput | Promise<InitInput>;
190
+ /** Initialize the workbook engine. Concurrent calls share the same attempt. */
191
+ declare function initWasm(input?: WasmInitInput): Promise<void>;
189
192
  /**
190
- * Whether the embedded wasm core can initialize in this environment. Attempts
191
- * init (idempotent) and reports success so callers can degrade explicitly.
193
+ * Whether this environment exposes the WebAssembly runtime required by the core.
192
194
  */
193
195
  declare function isWasmAvailable(): boolean;
194
196
  /**
@@ -213,4 +215,4 @@ declare function openWorkbook(bytes: Uint8Array): WorkbookHandle;
213
215
  */
214
216
  declare function wasmVersion(): string;
215
217
 
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 };
218
+ export { 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 };