@coloop-ai/xlsx-wasm 0.1.0 → 0.2.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/README.md CHANGED
@@ -15,6 +15,8 @@ It gives you everything IronCalc reads from a workbook: values as stored and as
15
15
  npm install @coloop-ai/xlsx-wasm
16
16
  ```
17
17
 
18
+ It needs Node 20.19 or later. `xlsx.wasm` is one WebAssembly file for every platform: there are no native builds.
19
+
18
20
  ## Usage
19
21
 
20
22
  ```ts
@@ -40,13 +42,13 @@ try {
40
42
 
41
43
  | Method | Returns |
42
44
  | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
43
- | `Workbook.open(bytes)` | A workbook, read from the bytes of an `.xlsx` file. |
45
+ | `Workbook.open(bytes, options?)` | A workbook, read from the bytes of an `.xlsx` file. `options.maxMemory` caps the workbook's memory, in bytes. |
44
46
  | `describe()` | Metadata, defined names, Excel tables, the styles in use, and each sheet with its visibility, used range, frozen panes, merged cells, hidden rows and columns, comments, links and conditional formats. |
45
47
  | `cells(sheet, area?)` | The non-empty cells of a sheet, or of an area of it: value, displayed text, formula, style and spill. |
46
48
  | `evaluate(sheet, formulas, mode?)` | One result per formula: a value, or the rows of an array. A reference without a sheet name refers to `sheet`. |
47
49
  | `recalculate()` | The formula cells whose value differs between the saved workbook and a full recalculation. |
48
50
  | `formatValue(value, format)` | A number formatted with an Excel number format. |
49
- | `close()` | Frees the workbook. |
51
+ | `close()` | Ends the workbook: later calls throw `closed`. |
50
52
 
51
53
  Sheets are numbered from 0, rows and columns from 1. Every method throws an `XlsxError` whose `kind` is `invalid_workbook`, `invalid_request`, `out_of_memory`, `crashed` or `closed`.
52
54
 
@@ -59,7 +61,7 @@ Sheets are numbered from 0, rows and columns from 1. Every method throws an `Xls
59
61
 
60
62
  ## Sandbox and limits
61
63
 
62
- Each workbook runs in its own WebAssembly instance, with a WASI layer written in JavaScript ([@bjorn3/browser_wasi_shim](https://github.com/bjorn3/browser_wasi_shim)). The instance gets the workbook's bytes and nothing else: no file system, no network, no environment variables and no bridge to JavaScript. Its memory is capped at 256 MiB. A workbook that needs more ends with `out_of_memory`, and later calls on it throw the same error.
64
+ Each workbook runs in its own WebAssembly instance, with a WASI layer written in JavaScript ([@bjorn3/browser_wasi_shim](https://github.com/bjorn3/browser_wasi_shim)). The instance gets the workbook's bytes and nothing else: no file system, no network, no environment variables and no bridge to JavaScript. Its memory grows up to `maxMemory`, rounded down to whole 64 KiB pages, or up to the WebAssembly engine's limit without it (4 GiB in Node). A workbook that needs more ends with `out_of_memory`, and later calls on it throw the same error.
63
65
 
64
66
  Calls are synchronous. Run them in a worker thread if they must not block the event loop.
65
67
 
package/dist/index.cjs CHANGED
@@ -35,21 +35,83 @@ var XlsxError = class extends Error {
35
35
  }
36
36
  };
37
37
  //#endregion
38
+ //#region src/memory-import.ts
39
+ const HEADER_BYTES = 8;
40
+ const IMPORT_SECTION = 2;
41
+ const FUNCTION_IMPORT = 0;
42
+ const MEMORY_IMPORT = 2;
43
+ function readMinimumPages(program) {
44
+ const reader = new ModuleReader(program, HEADER_BYTES);
45
+ while (reader.hasMore()) {
46
+ const section = reader.readByte();
47
+ const size = reader.readU32();
48
+ if (section !== IMPORT_SECTION) {
49
+ reader.skip(size);
50
+ continue;
51
+ }
52
+ for (let left = reader.readU32(); left > 0; left -= 1) {
53
+ reader.skip(reader.readU32());
54
+ reader.skip(reader.readU32());
55
+ const kind = reader.readByte();
56
+ if (kind === MEMORY_IMPORT) {
57
+ reader.readByte();
58
+ return reader.readU32();
59
+ }
60
+ if (kind !== FUNCTION_IMPORT) throw new TypeError("xlsx.wasm imports only functions and a memory.");
61
+ reader.readU32();
62
+ }
63
+ }
64
+ throw new TypeError("xlsx.wasm does not import a memory.");
65
+ }
66
+ var ModuleReader = class {
67
+ bytes;
68
+ offset;
69
+ constructor(bytes, offset) {
70
+ this.bytes = bytes;
71
+ this.offset = offset;
72
+ }
73
+ hasMore() {
74
+ return this.offset < this.bytes.length;
75
+ }
76
+ readByte() {
77
+ const byte = this.bytes[this.offset];
78
+ if (byte === void 0) throw new TypeError("xlsx.wasm ends in the middle of a section.");
79
+ this.offset += 1;
80
+ return byte;
81
+ }
82
+ readU32() {
83
+ let value = 0;
84
+ for (let shift = 0;; shift += 7) {
85
+ const byte = this.readByte();
86
+ value += (byte & 127) * 2 ** shift;
87
+ if (byte < 128) return value;
88
+ }
89
+ }
90
+ skip(length) {
91
+ this.offset += length;
92
+ }
93
+ };
94
+ //#endregion
38
95
  //#region src/program.ts
39
96
  const PROGRAM = new URL("../xlsx.wasm", require("url").pathToFileURL(__filename).href);
97
+ const PAGE_BYTES = 65536;
40
98
  const OUT_OF_MEMORY = "memory allocation of";
41
99
  const encoder = new TextEncoder();
42
100
  const decoder = new TextDecoder();
43
- let compiled = null;
101
+ let loading = null;
44
102
  var ProgramInstance = class ProgramInstance {
103
+ memory;
45
104
  exports;
46
105
  stderr;
47
106
  failure = null;
48
- constructor(exports, stderr) {
107
+ constructor(memory, exports, stderr) {
108
+ this.memory = memory;
49
109
  this.exports = exports;
50
110
  this.stderr = stderr;
51
111
  }
52
- static async start() {
112
+ static async start(maxMemory) {
113
+ const program = await loadProgram();
114
+ const memory = createMemory(program.minimumPages, maxMemory);
53
115
  const stderr = new OutputBuffer();
54
116
  const wasi = new _bjorn3_browser_wasi_shim.WASI(["xlsx"], [], [
55
117
  new _bjorn3_browser_wasi_shim.OpenFile(new _bjorn3_browser_wasi_shim.File([])),
@@ -58,9 +120,12 @@ var ProgramInstance = class ProgramInstance {
58
120
  stderr.push(chunk);
59
121
  })
60
122
  ], { debug: false });
61
- const exports = toExports(await WebAssembly.instantiate(await loadProgram(), { wasi_snapshot_preview1: wasi.wasiImport }));
62
- wasi.initialize({ exports: { memory: exports.memory } });
63
- return new ProgramInstance(exports, stderr);
123
+ const instance = await WebAssembly.instantiate(program.module, {
124
+ env: { memory },
125
+ wasi_snapshot_preview1: wasi.wasiImport
126
+ });
127
+ wasi.initialize({ exports: { memory } });
128
+ return new ProgramInstance(memory, toExports(instance), stderr);
64
129
  }
65
130
  open(bytes) {
66
131
  return this.run((exports) => {
@@ -83,7 +148,7 @@ var ProgramInstance = class ProgramInstance {
83
148
  try {
84
149
  const length = invoke(this.exports);
85
150
  const pointer = this.exports.response();
86
- return decoder.decode(new Uint8Array(this.exports.memory.buffer, pointer, length));
151
+ return decoder.decode(new Uint8Array(this.memory.buffer, pointer, length));
87
152
  } catch (cause) {
88
153
  if (cause instanceof WebAssembly.RuntimeError) {
89
154
  this.failure = toTrapError(this.stderr.toText(), cause);
@@ -94,19 +159,30 @@ var ProgramInstance = class ProgramInstance {
94
159
  }
95
160
  write(bytes) {
96
161
  const pointer = this.exports.alloc(bytes.length);
97
- new Uint8Array(this.exports.memory.buffer, pointer, bytes.length).set(bytes);
162
+ new Uint8Array(this.memory.buffer, pointer, bytes.length).set(bytes);
98
163
  return pointer;
99
164
  }
100
165
  };
101
166
  function loadProgram() {
102
- compiled ??= (0, node_fs_promises.readFile)(PROGRAM).then((bytes) => WebAssembly.compile(bytes));
103
- return compiled;
167
+ loading ??= (0, node_fs_promises.readFile)(PROGRAM).then(async (bytes) => ({
168
+ module: await WebAssembly.compile(bytes),
169
+ minimumPages: readMinimumPages(bytes)
170
+ }));
171
+ return loading;
172
+ }
173
+ function createMemory(minimumPages, maxMemory) {
174
+ if (maxMemory === void 0) return new WebAssembly.Memory({ initial: minimumPages });
175
+ const maximumPages = Math.floor(maxMemory / PAGE_BYTES);
176
+ if (maximumPages < minimumPages) throw new RangeError(`maxMemory is ${String(maxMemory)} bytes; xlsx.wasm needs at least ${String(minimumPages * PAGE_BYTES)}.`);
177
+ return new WebAssembly.Memory({
178
+ initial: minimumPages,
179
+ maximum: maximumPages
180
+ });
104
181
  }
105
182
  function toExports(instance) {
106
- const { memory, xlsx_alloc: alloc, xlsx_open: open, xlsx_call: call, xlsx_response: response } = instance.exports;
107
- if (!(memory instanceof WebAssembly.Memory) || typeof alloc !== "function" || typeof open !== "function" || typeof call !== "function" || typeof response !== "function") throw new TypeError("xlsx.wasm does not export the expected functions.");
183
+ const { xlsx_alloc: alloc, xlsx_open: open, xlsx_call: call, xlsx_response: response } = instance.exports;
184
+ if (typeof alloc !== "function" || typeof open !== "function" || typeof call !== "function" || typeof response !== "function") throw new TypeError("xlsx.wasm does not export the expected functions.");
108
185
  return {
109
- memory,
110
186
  alloc: (length) => toAddress(Reflect.apply(alloc, null, [length])),
111
187
  open: (pointer, length) => toAddress(Reflect.apply(open, null, [pointer, length])),
112
188
  call: (pointer, length) => toAddress(Reflect.apply(call, null, [pointer, length])),
@@ -118,7 +194,7 @@ function toAddress(value) {
118
194
  return value >>> 0;
119
195
  }
120
196
  function toTrapError(stderr, cause) {
121
- if (stderr.includes(OUT_OF_MEMORY)) return new XlsxError("out_of_memory", "The workbook needed more memory than xlsx.wasm may use.");
197
+ if (stderr.includes(OUT_OF_MEMORY)) return new XlsxError("out_of_memory", "The workbook needed more memory than maxMemory allows.");
122
198
  return new XlsxError("crashed", stderr.trim() || cause.message);
123
199
  }
124
200
  var OutputBuffer = class {
@@ -305,8 +381,8 @@ var Workbook = class Workbook {
305
381
  constructor(program) {
306
382
  this.program = program;
307
383
  }
308
- static async open(bytes) {
309
- const program = await ProgramInstance.start();
384
+ static async open(bytes, { maxMemory } = {}) {
385
+ const program = await ProgramInstance.start(maxMemory);
310
386
  parse(zod.null(), program.open(bytes));
311
387
  return new Workbook(program);
312
388
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["WASI","OpenFile","File","ConsoleStdout","z","z"],"sources":["../src/error.ts","../src/program.ts","../src/schema.ts","../src/index.ts"],"sourcesContent":["export type XlsxErrorKind =\n | 'invalid_workbook'\n | 'invalid_request'\n | 'out_of_memory'\n | 'crashed'\n | 'closed'\n\nexport class XlsxError extends Error {\n public readonly kind: XlsxErrorKind\n\n public constructor(kind: XlsxErrorKind, message: string) {\n super(message)\n this.name = 'XlsxError'\n this.kind = kind\n }\n}\n","import { ConsoleStdout, File, OpenFile, WASI } from '@bjorn3/browser_wasi_shim'\nimport { readFile } from 'node:fs/promises'\nimport { XlsxError } from './error'\n\nconst PROGRAM = new URL('../xlsx.wasm', import.meta.url)\n\nconst OUT_OF_MEMORY = 'memory allocation of'\n\nconst encoder = new TextEncoder()\n\nconst decoder = new TextDecoder()\n\nlet compiled: Promise<WebAssembly.Module> | null = null\n\ntype Exports = {\n memory: WebAssembly.Memory\n alloc: (length: number) => number\n open: (pointer: number, length: number) => number\n call: (pointer: number, length: number) => number\n response: () => number\n}\n\nexport class ProgramInstance {\n private readonly exports: Exports\n private readonly stderr: OutputBuffer\n private failure: XlsxError | null = null\n\n private constructor(exports: Exports, stderr: OutputBuffer) {\n this.exports = exports\n this.stderr = stderr\n }\n\n public static async start(): Promise<ProgramInstance> {\n const stderr = new OutputBuffer()\n const wasi = new WASI(\n ['xlsx'],\n [],\n [\n new OpenFile(new File([])),\n new ConsoleStdout(() => undefined),\n new ConsoleStdout((chunk) => {\n stderr.push(chunk)\n }),\n ],\n { debug: false },\n )\n const instance = await WebAssembly.instantiate(await loadProgram(), {\n wasi_snapshot_preview1: wasi.wasiImport,\n })\n const exports = toExports(instance)\n wasi.initialize({ exports: { memory: exports.memory } })\n return new ProgramInstance(exports, stderr)\n }\n\n public open(bytes: Uint8Array): string {\n return this.run((exports) => {\n const pointer = this.write(bytes)\n return exports.open(pointer, bytes.length)\n })\n }\n\n public call(request: unknown): string {\n const bytes = encoder.encode(JSON.stringify(request))\n return this.run((exports) => {\n const pointer = this.write(bytes)\n return exports.call(pointer, bytes.length)\n })\n }\n\n public close(): void {\n this.failure ??= new XlsxError('closed', 'The workbook is closed.')\n }\n\n private run(invoke: (exports: Exports) => number): string {\n if (this.failure !== null) {\n throw this.failure\n }\n try {\n const length = invoke(this.exports)\n const pointer = this.exports.response()\n return decoder.decode(\n new Uint8Array(this.exports.memory.buffer, pointer, length),\n )\n } catch (cause) {\n if (cause instanceof WebAssembly.RuntimeError) {\n this.failure = toTrapError(this.stderr.toText(), cause)\n throw this.failure\n }\n throw cause\n }\n }\n\n private write(bytes: Uint8Array): number {\n const pointer = this.exports.alloc(bytes.length)\n new Uint8Array(this.exports.memory.buffer, pointer, bytes.length).set(bytes)\n return pointer\n }\n}\n\nfunction loadProgram(): Promise<WebAssembly.Module> {\n compiled ??= readFile(PROGRAM).then((bytes) => WebAssembly.compile(bytes))\n return compiled\n}\n\nfunction toExports(instance: WebAssembly.Instance): Exports {\n const {\n memory,\n xlsx_alloc: alloc,\n xlsx_open: open,\n xlsx_call: call,\n xlsx_response: response,\n } = instance.exports\n if (\n !(memory instanceof WebAssembly.Memory) ||\n typeof alloc !== 'function' ||\n typeof open !== 'function' ||\n typeof call !== 'function' ||\n typeof response !== 'function'\n ) {\n throw new TypeError('xlsx.wasm does not export the expected functions.')\n }\n return {\n memory,\n alloc: (length) => toAddress(Reflect.apply(alloc, null, [length])),\n open: (pointer, length) =>\n toAddress(Reflect.apply(open, null, [pointer, length])),\n call: (pointer, length) =>\n toAddress(Reflect.apply(call, null, [pointer, length])),\n response: () => toAddress(Reflect.apply(response, null, [])),\n }\n}\n\nfunction toAddress(value: unknown): number {\n if (typeof value !== 'number') {\n throw new TypeError('xlsx.wasm returned a value that is not a number.')\n }\n return value >>> 0\n}\n\nfunction toTrapError(\n stderr: string,\n cause: WebAssembly.RuntimeError,\n): XlsxError {\n if (stderr.includes(OUT_OF_MEMORY)) {\n return new XlsxError(\n 'out_of_memory',\n 'The workbook needed more memory than xlsx.wasm may use.',\n )\n }\n return new XlsxError('crashed', stderr.trim() || cause.message)\n}\n\nclass OutputBuffer {\n private readonly chunks: Uint8Array[] = []\n\n public push(chunk: Uint8Array): void {\n this.chunks.push(chunk.slice())\n }\n\n public toText(): string {\n return Buffer.concat(this.chunks).toString('utf-8')\n }\n}\n","import * as z from 'zod'\n\nexport type Area = z.infer<typeof Area>\nexport const Area = z.object({\n firstRow: z.number().int(),\n firstColumn: z.number().int(),\n lastRow: z.number().int(),\n lastColumn: z.number().int(),\n})\n\nexport type CellValue = z.infer<typeof CellValue>\nexport const CellValue = z.discriminatedUnion('type', [\n z.object({ type: z.literal('empty') }),\n z.object({ type: z.literal('number'), value: z.number() }),\n z.object({ type: z.literal('text'), value: z.string() }),\n z.object({ type: z.literal('boolean'), value: z.boolean() }),\n z.object({ type: z.literal('error'), value: z.string() }),\n])\n\nexport type Color = z.infer<typeof Color>\nexport const Color = z\n .discriminatedUnion('kind', [\n z.object({ kind: z.literal('rgb'), hex: z.string() }),\n z.object({ kind: z.literal('theme'), index: z.number(), tint: z.number() }),\n ])\n .nullable()\n\nexport type BorderSide = z.infer<typeof BorderSide>\nexport const BorderSide = z\n .object({ style: z.string(), color: Color })\n .nullable()\n\nexport type Style = z.infer<typeof Style>\nexport const Style = z.object({\n numberFormat: z.string(),\n font: z.object({\n name: z.string(),\n size: z.number(),\n bold: z.boolean(),\n italic: z.boolean(),\n underline: z.boolean(),\n strike: z.boolean(),\n color: Color,\n }),\n fill: Color,\n alignment: z\n .object({\n horizontal: z.string(),\n vertical: z.string(),\n wrapText: z.boolean(),\n })\n .nullable(),\n borders: z.object({\n top: BorderSide,\n right: BorderSide,\n bottom: BorderSide,\n left: BorderSide,\n }),\n})\n\nexport type SheetState = z.infer<typeof SheetState>\nexport const SheetState = z.enum(['visible', 'hidden', 'very_hidden'])\n\nexport type Sheet = z.infer<typeof Sheet>\nexport const Sheet = z.object({\n index: z.number().int(),\n name: z.string(),\n state: SheetState,\n color: Color,\n extent: Area.nullable(),\n frozenRows: z.number().int(),\n frozenColumns: z.number().int(),\n merged: z.array(Area),\n hiddenRows: z.array(z.number().int()),\n hiddenColumns: z.array(\n z.object({ first: z.number().int(), last: z.number().int() }),\n ),\n comments: z.array(\n z.object({\n row: z.number().int(),\n column: z.number().int(),\n author: z.string(),\n text: z.string(),\n }),\n ),\n links: z.array(\n z.object({\n row: z.number().int(),\n column: z.number().int(),\n kind: z.enum(['external', 'internal']),\n target: z.string(),\n tooltip: z.string().nullable(),\n }),\n ),\n conditionalFormats: z.array(\n z.object({\n range: z.string(),\n kind: z.string(),\n priority: z.number().int(),\n }),\n ),\n})\n\nexport type WorkbookDescription = z.infer<typeof WorkbookDescription>\nexport const WorkbookDescription = z.object({\n metadata: z.object({\n application: z.string(),\n appVersion: z.string(),\n creator: z.string(),\n lastModifiedBy: z.string(),\n created: z.string(),\n lastModified: z.string(),\n }),\n locale: z.string(),\n timezone: z.string(),\n definedNames: z.array(\n z.object({\n name: z.string(),\n sheet: z.number().int().nullable(),\n formula: z.string(),\n }),\n ),\n tables: z.array(\n z.object({\n name: z.string(),\n displayName: z.string(),\n sheet: z.number().int().nullable(),\n range: z.string(),\n headerRows: z.number().int(),\n totalsRows: z.number().int(),\n columns: z.array(z.string()),\n hasFilters: z.boolean(),\n }),\n ),\n styles: z.record(z.string(), Style),\n sheets: z.array(Sheet),\n})\n\nexport type Spill = z.infer<typeof Spill>\nexport const Spill = z\n .discriminatedUnion('kind', [\n z.object({ kind: z.literal('anchor'), range: Area }),\n z.object({\n kind: z.literal('part'),\n anchor: z.object({ row: z.number().int(), column: z.number().int() }),\n }),\n ])\n .nullable()\n\nexport type Cell = z.infer<typeof Cell>\nexport const Cell = z.object({\n row: z.number().int(),\n column: z.number().int(),\n value: CellValue,\n text: z.string(),\n formula: z.string().nullable(),\n style: z.number().int(),\n spill: Spill,\n})\n\nexport type EvaluationResult = z.infer<typeof EvaluationResult>\nexport const EvaluationResult = z.discriminatedUnion('kind', [\n z.object({ kind: z.literal('value'), value: CellValue }),\n z.object({ kind: z.literal('array'), rows: z.array(z.array(CellValue)) }),\n])\n\nexport type CellChange = z.infer<typeof CellChange>\nexport const CellChange = z.object({\n sheet: z.number().int(),\n row: z.number().int(),\n column: z.number().int(),\n saved: CellValue,\n recalculated: CellValue,\n})\n\nexport type ProgramErrorKind = z.infer<typeof ProgramErrorKind>\nexport const ProgramErrorKind = z.enum(['invalid_workbook', 'invalid_request'])\n\nexport type ProgramResponse = z.infer<typeof ProgramResponse>\nexport const ProgramResponse = z.union([\n z.object({\n error: z.object({ kind: ProgramErrorKind, message: z.string() }),\n }),\n z.object({ ok: z.unknown() }),\n])\n","import * as z from 'zod'\nimport { XlsxError } from './error'\nimport { ProgramInstance } from './program'\nimport {\n type Area,\n Cell,\n CellChange,\n EvaluationResult,\n ProgramResponse,\n WorkbookDescription,\n} from './schema'\n\nexport { XlsxError, type XlsxErrorKind } from './error'\nexport type {\n Area,\n BorderSide,\n Cell,\n CellChange,\n CellValue,\n Color,\n EvaluationResult,\n Sheet,\n SheetState,\n Spill,\n Style,\n WorkbookDescription,\n} from './schema'\n\nexport type EvaluationMode = 'saved' | 'recalculated'\n\nexport class Workbook {\n private readonly program: ProgramInstance\n\n private constructor(program: ProgramInstance) {\n this.program = program\n }\n\n public static async open(bytes: Uint8Array): Promise<Workbook> {\n const program = await ProgramInstance.start()\n parse(z.null(), program.open(bytes))\n return new Workbook(program)\n }\n\n public describe(): WorkbookDescription {\n return this.call(WorkbookDescription, { method: 'describe' })\n }\n\n public cells(sheet: number, area?: Area): Cell[] {\n return this.call(z.array(Cell), {\n method: 'cells',\n params: { sheet, area: area ?? null },\n })\n }\n\n public evaluate(\n sheet: number,\n formulas: readonly string[],\n mode: EvaluationMode = 'saved',\n ): EvaluationResult[] {\n return this.call(z.array(EvaluationResult), {\n method: 'evaluate',\n params: { sheet, formulas, mode },\n })\n }\n\n public recalculate(): CellChange[] {\n return this.call(z.array(CellChange), { method: 'recalculate' })\n }\n\n public formatValue(value: number, format: string): string {\n return this.call(z.string(), {\n method: 'format_value',\n params: { value, format },\n })\n }\n\n public close(): void {\n this.program.close()\n }\n\n private call<Schema extends z.ZodType>(\n schema: Schema,\n request: unknown,\n ): z.output<Schema> {\n return parse(schema, this.program.call(request))\n }\n}\n\nfunction parse<Schema extends z.ZodType>(\n schema: Schema,\n text: string,\n): z.output<Schema> {\n const response = ProgramResponse.parse(JSON.parse(text))\n if ('error' in response) {\n throw new XlsxError(response.error.kind, response.error.message)\n }\n return schema.parse(response.ok)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAa,YAAb,cAA+B,MAAM;CACnC;CAEA,YAAmB,MAAqB,SAAiB;EACvD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;;ACXA,MAAM,UAAU,IAAI,IAAI,gBAAA,QAAA,KAAA,CAAA,CAAA,cAAA,UAAA,CAAA,CAAA,IAA+B;AAEvD,MAAM,gBAAgB;AAEtB,MAAM,UAAU,IAAI,YAAY;AAEhC,MAAM,UAAU,IAAI,YAAY;AAEhC,IAAI,WAA+C;AAUnD,IAAa,kBAAb,MAAa,gBAAgB;CAC3B;CACA;CACA,UAAoC;CAEpC,YAAoB,SAAkB,QAAsB;EAC1D,KAAK,UAAU;EACf,KAAK,SAAS;CAChB;CAEA,aAAoB,QAAkC;EACpD,MAAM,SAAS,IAAI,aAAa;EAChC,MAAM,OAAO,IAAIA,0BAAAA,KACf,CAAC,MAAM,GACP,CAAC,GACD;GACE,IAAIC,0BAAAA,SAAS,IAAIC,0BAAAA,KAAK,CAAC,CAAC,CAAC;GACzB,IAAIC,0BAAAA,oBAAoB,KAAA,CAAS;GACjC,IAAIA,0BAAAA,eAAe,UAAU;IAC3B,OAAO,KAAK,KAAK;GACnB,CAAC;EACH,GACA,EAAE,OAAO,MAAM,CACjB;EAIA,MAAM,UAAU,UAAU,MAHH,YAAY,YAAY,MAAM,YAAY,GAAG,EAClE,wBAAwB,KAAK,WAC/B,CAAC,CACiC;EAClC,KAAK,WAAW,EAAE,SAAS,EAAE,QAAQ,QAAQ,OAAO,EAAE,CAAC;EACvD,OAAO,IAAI,gBAAgB,SAAS,MAAM;CAC5C;CAEA,KAAY,OAA2B;EACrC,OAAO,KAAK,KAAK,YAAY;GAC3B,MAAM,UAAU,KAAK,MAAM,KAAK;GAChC,OAAO,QAAQ,KAAK,SAAS,MAAM,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ACA,UACA,OAAuB,SACH;EACpB,OAAO,KAAK,KAAKA,IAAE,MAAM,gBAAgB,GAAG;GAC1C,QAAQ;GACR,QAAQ;IAAE;IAAO;IAAU;GAAK;EAClC,CAAC;CACH;CAEA,cAAmC;EACjC,OAAO,KAAK,KAAKA,IAAE,MAAM,UAAU,GAAG,EAAE,QAAQ,cAAc,CAAC;CACjE;CAEA,YAAmB,OAAe,QAAwB;EACxD,OAAO,KAAK,KAAKA,IAAE,OAAO,GAAG;GAC3B,QAAQ;GACR,QAAQ;IAAE;IAAO;GAAO;EAC1B,CAAC;CACH;CAEA,QAAqB;EACnB,KAAK,QAAQ,MAAM;CACrB;CAEA,KACE,QACA,SACkB;EAClB,OAAO,MAAM,QAAQ,KAAK,QAAQ,KAAK,OAAO,CAAC;CACjD;AACF;AAEA,SAAS,MACP,QACA,MACkB;CAClB,MAAM,WAAW,gBAAgB,MAAM,KAAK,MAAM,IAAI,CAAC;CACvD,IAAI,WAAW,UACb,MAAM,IAAI,UAAU,SAAS,MAAM,MAAM,SAAS,MAAM,OAAO;CAEjE,OAAO,OAAO,MAAM,SAAS,EAAE;AACjC"}
1
+ {"version":3,"file":"index.cjs","names":["WASI","OpenFile","File","ConsoleStdout","z","z"],"sources":["../src/error.ts","../src/memory-import.ts","../src/program.ts","../src/schema.ts","../src/index.ts"],"sourcesContent":["import type { ProgramErrorKind } from './schema'\n\nexport type XlsxErrorKind =\n ProgramErrorKind | 'out_of_memory' | 'crashed' | 'closed'\n\nexport class XlsxError extends Error {\n public readonly kind: XlsxErrorKind\n\n public constructor(kind: XlsxErrorKind, message: string) {\n super(message)\n this.name = 'XlsxError'\n this.kind = kind\n }\n}\n","const HEADER_BYTES = 8\n\nconst IMPORT_SECTION = 2\n\nconst FUNCTION_IMPORT = 0\n\nconst MEMORY_IMPORT = 2\n\nexport function readMinimumPages(program: Uint8Array): number {\n const reader = new ModuleReader(program, HEADER_BYTES)\n while (reader.hasMore()) {\n const section = reader.readByte()\n const size = reader.readU32()\n if (section !== IMPORT_SECTION) {\n reader.skip(size)\n continue\n }\n for (let left = reader.readU32(); left > 0; left -= 1) {\n reader.skip(reader.readU32())\n reader.skip(reader.readU32())\n const kind = reader.readByte()\n if (kind === MEMORY_IMPORT) {\n reader.readByte()\n return reader.readU32()\n }\n if (kind !== FUNCTION_IMPORT) {\n throw new TypeError('xlsx.wasm imports only functions and a memory.')\n }\n reader.readU32()\n }\n }\n throw new TypeError('xlsx.wasm does not import a memory.')\n}\n\nclass ModuleReader {\n private readonly bytes: Uint8Array\n private offset: number\n\n public constructor(bytes: Uint8Array, offset: number) {\n this.bytes = bytes\n this.offset = offset\n }\n\n public hasMore(): boolean {\n return this.offset < this.bytes.length\n }\n\n public readByte(): number {\n const byte = this.bytes[this.offset]\n if (byte === undefined) {\n throw new TypeError('xlsx.wasm ends in the middle of a section.')\n }\n this.offset += 1\n return byte\n }\n\n public readU32(): number {\n let value = 0\n for (let shift = 0; ; shift += 7) {\n const byte = this.readByte()\n value += (byte & 0x7f) * 2 ** shift\n if (byte < 0x80) {\n return value\n }\n }\n }\n\n public skip(length: number): void {\n this.offset += length\n }\n}\n","import { ConsoleStdout, File, OpenFile, WASI } from '@bjorn3/browser_wasi_shim'\nimport { readFile } from 'node:fs/promises'\nimport { XlsxError } from './error'\nimport { readMinimumPages } from './memory-import'\nimport type { ProgramRequest } from './schema'\n\nconst PROGRAM = new URL('../xlsx.wasm', import.meta.url)\n\nconst PAGE_BYTES = 65_536\n\nconst OUT_OF_MEMORY = 'memory allocation of'\n\nconst encoder = new TextEncoder()\n\nconst decoder = new TextDecoder()\n\nlet loading: Promise<Program> | null = null\n\ntype Exports = {\n alloc: (length: number) => number\n open: (pointer: number, length: number) => number\n call: (pointer: number, length: number) => number\n response: () => number\n}\n\nexport class ProgramInstance {\n private readonly memory: WebAssembly.Memory\n private readonly exports: Exports\n private readonly stderr: OutputBuffer\n private failure: XlsxError | null = null\n\n private constructor(\n memory: WebAssembly.Memory,\n exports: Exports,\n stderr: OutputBuffer,\n ) {\n this.memory = memory\n this.exports = exports\n this.stderr = stderr\n }\n\n public static async start(\n maxMemory: number | undefined,\n ): Promise<ProgramInstance> {\n const program = await loadProgram()\n const memory = createMemory(program.minimumPages, maxMemory)\n const stderr = new OutputBuffer()\n const wasi = new WASI(\n ['xlsx'],\n [],\n [\n new OpenFile(new File([])),\n new ConsoleStdout(() => undefined),\n new ConsoleStdout((chunk) => {\n stderr.push(chunk)\n }),\n ],\n { debug: false },\n )\n const instance = await WebAssembly.instantiate(program.module, {\n env: { memory },\n wasi_snapshot_preview1: wasi.wasiImport,\n })\n wasi.initialize({ exports: { memory } })\n return new ProgramInstance(memory, toExports(instance), stderr)\n }\n\n public open(bytes: Uint8Array): string {\n return this.run((exports) => {\n const pointer = this.write(bytes)\n return exports.open(pointer, bytes.length)\n })\n }\n\n public call(request: ProgramRequest): string {\n const bytes = encoder.encode(JSON.stringify(request))\n return this.run((exports) => {\n const pointer = this.write(bytes)\n return exports.call(pointer, bytes.length)\n })\n }\n\n public close(): void {\n this.failure ??= new XlsxError('closed', 'The workbook is closed.')\n }\n\n private run(invoke: (exports: Exports) => number): string {\n if (this.failure !== null) {\n throw this.failure\n }\n try {\n const length = invoke(this.exports)\n const pointer = this.exports.response()\n return decoder.decode(new Uint8Array(this.memory.buffer, pointer, length))\n } catch (cause) {\n if (cause instanceof WebAssembly.RuntimeError) {\n this.failure = toTrapError(this.stderr.toText(), cause)\n throw this.failure\n }\n throw cause\n }\n }\n\n private write(bytes: Uint8Array): number {\n const pointer = this.exports.alloc(bytes.length)\n new Uint8Array(this.memory.buffer, pointer, bytes.length).set(bytes)\n return pointer\n }\n}\n\ntype Program = { module: WebAssembly.Module; minimumPages: number }\n\nfunction loadProgram(): Promise<Program> {\n loading ??= readFile(PROGRAM).then(async (bytes) => ({\n module: await WebAssembly.compile(bytes),\n minimumPages: readMinimumPages(bytes),\n }))\n return loading\n}\n\nfunction createMemory(\n minimumPages: number,\n maxMemory: number | undefined,\n): WebAssembly.Memory {\n if (maxMemory === undefined) {\n return new WebAssembly.Memory({ initial: minimumPages })\n }\n const maximumPages = Math.floor(maxMemory / PAGE_BYTES)\n if (maximumPages < minimumPages) {\n throw new RangeError(\n `maxMemory is ${String(maxMemory)} bytes; xlsx.wasm needs at least ${String(minimumPages * PAGE_BYTES)}.`,\n )\n }\n return new WebAssembly.Memory({\n initial: minimumPages,\n maximum: maximumPages,\n })\n}\n\nfunction toExports(instance: WebAssembly.Instance): Exports {\n const {\n xlsx_alloc: alloc,\n xlsx_open: open,\n xlsx_call: call,\n xlsx_response: response,\n } = instance.exports\n if (\n typeof alloc !== 'function' ||\n typeof open !== 'function' ||\n typeof call !== 'function' ||\n typeof response !== 'function'\n ) {\n throw new TypeError('xlsx.wasm does not export the expected functions.')\n }\n return {\n alloc: (length) => toAddress(Reflect.apply(alloc, null, [length])),\n open: (pointer, length) =>\n toAddress(Reflect.apply(open, null, [pointer, length])),\n call: (pointer, length) =>\n toAddress(Reflect.apply(call, null, [pointer, length])),\n response: () => toAddress(Reflect.apply(response, null, [])),\n }\n}\n\nfunction toAddress(value: unknown): number {\n if (typeof value !== 'number') {\n throw new TypeError('xlsx.wasm returned a value that is not a number.')\n }\n return value >>> 0\n}\n\nfunction toTrapError(\n stderr: string,\n cause: WebAssembly.RuntimeError,\n): XlsxError {\n if (stderr.includes(OUT_OF_MEMORY)) {\n return new XlsxError(\n 'out_of_memory',\n 'The workbook needed more memory than maxMemory allows.',\n )\n }\n return new XlsxError('crashed', stderr.trim() || cause.message)\n}\n\nclass OutputBuffer {\n private readonly chunks: Uint8Array[] = []\n\n public push(chunk: Uint8Array): void {\n this.chunks.push(chunk.slice())\n }\n\n public toText(): string {\n return Buffer.concat(this.chunks).toString('utf-8')\n }\n}\n","import * as z from 'zod'\n\nexport type Area = z.infer<typeof Area>\nexport const Area = z.object({\n firstRow: z.number().int(),\n firstColumn: z.number().int(),\n lastRow: z.number().int(),\n lastColumn: z.number().int(),\n})\n\nexport type CellValue = z.infer<typeof CellValue>\nexport const CellValue = z.discriminatedUnion('type', [\n z.object({ type: z.literal('empty') }),\n z.object({ type: z.literal('number'), value: z.number() }),\n z.object({ type: z.literal('text'), value: z.string() }),\n z.object({ type: z.literal('boolean'), value: z.boolean() }),\n z.object({ type: z.literal('error'), value: z.string() }),\n])\n\nexport type Color = z.infer<typeof Color>\nexport const Color = z\n .discriminatedUnion('kind', [\n z.object({ kind: z.literal('rgb'), hex: z.string() }),\n z.object({ kind: z.literal('theme'), index: z.number(), tint: z.number() }),\n ])\n .nullable()\n\nexport type BorderSide = z.infer<typeof BorderSide>\nexport const BorderSide = z\n .object({ style: z.string(), color: Color })\n .nullable()\n\nexport type Style = z.infer<typeof Style>\nexport const Style = z.object({\n numberFormat: z.string(),\n font: z.object({\n name: z.string(),\n size: z.number(),\n bold: z.boolean(),\n italic: z.boolean(),\n underline: z.boolean(),\n strike: z.boolean(),\n color: Color,\n }),\n fill: Color,\n alignment: z\n .object({\n horizontal: z.string(),\n vertical: z.string(),\n wrapText: z.boolean(),\n })\n .nullable(),\n borders: z.object({\n top: BorderSide,\n right: BorderSide,\n bottom: BorderSide,\n left: BorderSide,\n }),\n})\n\nexport type SheetState = z.infer<typeof SheetState>\nexport const SheetState = z.enum(['visible', 'hidden', 'very_hidden'])\n\nexport type Sheet = z.infer<typeof Sheet>\nexport const Sheet = z.object({\n index: z.number().int(),\n name: z.string(),\n state: SheetState,\n color: Color,\n extent: Area.nullable(),\n frozenRows: z.number().int(),\n frozenColumns: z.number().int(),\n merged: z.array(Area),\n hiddenRows: z.array(z.number().int()),\n hiddenColumns: z.array(\n z.object({ first: z.number().int(), last: z.number().int() }),\n ),\n comments: z.array(\n z.object({\n row: z.number().int(),\n column: z.number().int(),\n author: z.string(),\n text: z.string(),\n }),\n ),\n links: z.array(\n z.object({\n row: z.number().int(),\n column: z.number().int(),\n kind: z.enum(['external', 'internal']),\n target: z.string(),\n tooltip: z.string().nullable(),\n }),\n ),\n conditionalFormats: z.array(\n z.object({\n range: z.string(),\n kind: z.string(),\n priority: z.number().int(),\n }),\n ),\n})\n\nexport type WorkbookDescription = z.infer<typeof WorkbookDescription>\nexport const WorkbookDescription = z.object({\n metadata: z.object({\n application: z.string(),\n appVersion: z.string(),\n creator: z.string(),\n lastModifiedBy: z.string(),\n created: z.string(),\n lastModified: z.string(),\n }),\n locale: z.string(),\n timezone: z.string(),\n definedNames: z.array(\n z.object({\n name: z.string(),\n sheet: z.number().int().nullable(),\n formula: z.string(),\n }),\n ),\n tables: z.array(\n z.object({\n name: z.string(),\n displayName: z.string(),\n sheet: z.number().int().nullable(),\n range: z.string(),\n headerRows: z.number().int(),\n totalsRows: z.number().int(),\n columns: z.array(z.string()),\n hasFilters: z.boolean(),\n }),\n ),\n styles: z.record(z.string(), Style),\n sheets: z.array(Sheet),\n})\n\nexport type Spill = z.infer<typeof Spill>\nexport const Spill = z\n .discriminatedUnion('kind', [\n z.object({ kind: z.literal('anchor'), range: Area }),\n z.object({\n kind: z.literal('part'),\n anchor: z.object({ row: z.number().int(), column: z.number().int() }),\n }),\n ])\n .nullable()\n\nexport type Cell = z.infer<typeof Cell>\nexport const Cell = z.object({\n row: z.number().int(),\n column: z.number().int(),\n value: CellValue,\n text: z.string(),\n formula: z.string().nullable(),\n style: z.number().int(),\n spill: Spill,\n})\n\nexport type EvaluationResult = z.infer<typeof EvaluationResult>\nexport const EvaluationResult = z.discriminatedUnion('kind', [\n z.object({ kind: z.literal('value'), value: CellValue }),\n z.object({ kind: z.literal('array'), rows: z.array(z.array(CellValue)) }),\n])\n\nexport type CellChange = z.infer<typeof CellChange>\nexport const CellChange = z.object({\n sheet: z.number().int(),\n row: z.number().int(),\n column: z.number().int(),\n saved: CellValue,\n recalculated: CellValue,\n})\n\nexport type EvaluationMode = 'saved' | 'recalculated'\n\nexport type ProgramRequest =\n | { method: 'describe' }\n | { method: 'cells'; params: { sheet: number; area: Area | null } }\n | {\n method: 'evaluate'\n params: {\n sheet: number\n formulas: readonly string[]\n mode: EvaluationMode\n }\n }\n | { method: 'recalculate' }\n | { method: 'format_value'; params: { value: number; format: string } }\n\nexport type ProgramErrorKind = z.infer<typeof ProgramErrorKind>\nexport const ProgramErrorKind = z.enum(['invalid_workbook', 'invalid_request'])\n\nexport type ProgramResponse = z.infer<typeof ProgramResponse>\nexport const ProgramResponse = z.union([\n z.object({\n error: z.object({ kind: ProgramErrorKind, message: z.string() }),\n }),\n z.object({ ok: z.unknown() }),\n])\n","import * as z from 'zod'\nimport { XlsxError } from './error'\nimport { ProgramInstance } from './program'\nimport {\n type Area,\n Cell,\n CellChange,\n type EvaluationMode,\n EvaluationResult,\n type ProgramRequest,\n ProgramResponse,\n WorkbookDescription,\n} from './schema'\n\nexport { XlsxError, type XlsxErrorKind } from './error'\nexport type {\n Area,\n BorderSide,\n Cell,\n CellChange,\n CellValue,\n Color,\n EvaluationMode,\n EvaluationResult,\n Sheet,\n SheetState,\n Spill,\n Style,\n WorkbookDescription,\n} from './schema'\n\nexport type WorkbookOptions = { maxMemory?: number }\n\nexport class Workbook {\n private readonly program: ProgramInstance\n\n private constructor(program: ProgramInstance) {\n this.program = program\n }\n\n public static async open(\n bytes: Uint8Array,\n { maxMemory }: WorkbookOptions = {},\n ): Promise<Workbook> {\n const program = await ProgramInstance.start(maxMemory)\n parse(z.null(), program.open(bytes))\n return new Workbook(program)\n }\n\n public describe(): WorkbookDescription {\n return this.call(WorkbookDescription, { method: 'describe' })\n }\n\n public cells(sheet: number, area?: Area): Cell[] {\n return this.call(z.array(Cell), {\n method: 'cells',\n params: { sheet, area: area ?? null },\n })\n }\n\n public evaluate(\n sheet: number,\n formulas: readonly string[],\n mode: EvaluationMode = 'saved',\n ): EvaluationResult[] {\n return this.call(z.array(EvaluationResult), {\n method: 'evaluate',\n params: { sheet, formulas, mode },\n })\n }\n\n public recalculate(): CellChange[] {\n return this.call(z.array(CellChange), { method: 'recalculate' })\n }\n\n public formatValue(value: number, format: string): string {\n return this.call(z.string(), {\n method: 'format_value',\n params: { value, format },\n })\n }\n\n public close(): void {\n this.program.close()\n }\n\n private call<Schema extends z.ZodType>(\n schema: Schema,\n request: ProgramRequest,\n ): z.output<Schema> {\n return parse(schema, this.program.call(request))\n }\n}\n\nfunction parse<Schema extends z.ZodType>(\n schema: Schema,\n text: string,\n): z.output<Schema> {\n const response = ProgramResponse.parse(JSON.parse(text))\n if ('error' in response) {\n throw new XlsxError(response.error.kind, response.error.message)\n }\n return schema.parse(response.ok)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAa,YAAb,cAA+B,MAAM;CACnC;CAEA,YAAmB,MAAqB,SAAiB;EACvD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;;ACbA,MAAM,eAAe;AAErB,MAAM,iBAAiB;AAEvB,MAAM,kBAAkB;AAExB,MAAM,gBAAgB;AAEtB,SAAgB,iBAAiB,SAA6B;CAC5D,MAAM,SAAS,IAAI,aAAa,SAAS,YAAY;CACrD,OAAO,OAAO,QAAQ,GAAG;EACvB,MAAM,UAAU,OAAO,SAAS;EAChC,MAAM,OAAO,OAAO,QAAQ;EAC5B,IAAI,YAAY,gBAAgB;GAC9B,OAAO,KAAK,IAAI;GAChB;EACF;EACA,KAAK,IAAI,OAAO,OAAO,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG;GACrD,OAAO,KAAK,OAAO,QAAQ,CAAC;GAC5B,OAAO,KAAK,OAAO,QAAQ,CAAC;GAC5B,MAAM,OAAO,OAAO,SAAS;GAC7B,IAAI,SAAS,eAAe;IAC1B,OAAO,SAAS;IAChB,OAAO,OAAO,QAAQ;GACxB;GACA,IAAI,SAAS,iBACX,MAAM,IAAI,UAAU,gDAAgD;GAEtE,OAAO,QAAQ;EACjB;CACF;CACA,MAAM,IAAI,UAAU,qCAAqC;AAC3D;AAEA,IAAM,eAAN,MAAmB;CACjB;CACA;CAEA,YAAmB,OAAmB,QAAgB;EACpD,KAAK,QAAQ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MAAM,WAAW,gBAAgB,MAAM,KAAK,MAAM,IAAI,CAAC;CACvD,IAAI,WAAW,UACb,MAAM,IAAI,UAAU,SAAS,MAAM,MAAM,SAAS,MAAM,OAAO;CAEjE,OAAO,OAAO,MAAM,SAAS,EAAE;AACjC"}
package/dist/index.d.cts CHANGED
@@ -477,20 +477,30 @@ declare const CellChange: z.ZodObject<{
477
477
  value: z.ZodString;
478
478
  }, z.core.$strip>], "type">;
479
479
  }, z.core.$strip>;
480
+ type EvaluationMode = 'saved' | 'recalculated';
481
+ type ProgramErrorKind = z.infer<typeof ProgramErrorKind>;
482
+ declare const ProgramErrorKind: z.ZodEnum<{
483
+ invalid_workbook: "invalid_workbook";
484
+ invalid_request: "invalid_request";
485
+ }>;
480
486
  //#endregion
481
487
  //#region src/error.d.ts
482
- type XlsxErrorKind = 'invalid_workbook' | 'invalid_request' | 'out_of_memory' | 'crashed' | 'closed';
488
+ type XlsxErrorKind = ProgramErrorKind | 'out_of_memory' | 'crashed' | 'closed';
483
489
  declare class XlsxError extends Error {
484
490
  readonly kind: XlsxErrorKind;
485
491
  constructor(kind: XlsxErrorKind, message: string);
486
492
  }
487
493
  //#endregion
488
494
  //#region src/index.d.ts
489
- type EvaluationMode = 'saved' | 'recalculated';
495
+ type WorkbookOptions = {
496
+ maxMemory?: number;
497
+ };
490
498
  declare class Workbook {
491
499
  private readonly program;
492
500
  private constructor();
493
- static open(bytes: Uint8Array): Promise<Workbook>;
501
+ static open(bytes: Uint8Array, {
502
+ maxMemory
503
+ }?: WorkbookOptions): Promise<Workbook>;
494
504
  describe(): WorkbookDescription;
495
505
  cells(sheet: number, area?: Area): Cell[];
496
506
  evaluate(sheet: number, formulas: readonly string[], mode?: EvaluationMode): EvaluationResult[];
@@ -500,5 +510,5 @@ declare class Workbook {
500
510
  private call;
501
511
  }
502
512
  //#endregion
503
- export { type Area, type BorderSide, type Cell, type CellChange, type CellValue, type Color, EvaluationMode, type EvaluationResult, type Sheet, type SheetState, type Spill, type Style, Workbook, type WorkbookDescription, XlsxError, type XlsxErrorKind };
513
+ export { type Area, type BorderSide, type Cell, type CellChange, type CellValue, type Color, type EvaluationMode, type EvaluationResult, type Sheet, type SheetState, type Spill, type Style, Workbook, type WorkbookDescription, WorkbookOptions, XlsxError, type XlsxErrorKind };
504
514
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/schema.ts","../src/error.ts","../src/index.ts"],"mappings":";;;KAEY,IAAA,GAAO,CAAA,CAAE,KAAK,QAAQ,IAAA;AAAA,cACrB,IAAA,EAAI,CAAA,CAAA,SAAA;;;;;;KAOL,SAAA,GAAY,CAAA,CAAE,KAAK,QAAQ,SAAA;AAAA,cAC1B,SAAA,EAAS,CAAA,CAAA,qBAAA,EAAA,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;KAQV,KAAA,GAAQ,CAAA,CAAE,KAAK,QAAQ,KAAA;AAAA,cACtB,KAAA,EAAK,CAAA,CAAA,WAAA,CAAA,CAAA,CAAA,qBAAA,EAAA,CAAA,CAAA,SAAA;;;;;;;;KAON,UAAA,GAAa,CAAA,CAAE,KAAK,QAAQ,UAAA;AAAA,cAC3B,UAAA,EAAU,CAAA,CAAA,WAAA,CAAA,CAAA,CAAA,SAAA;;;;;;;;;;;KAIX,KAAA,GAAQ,CAAA,CAAE,KAAK,QAAQ,KAAA;AAAA,cACtB,KAAA,EAAK,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA2BN,UAAA,GAAa,CAAA,CAAE,KAAK,QAAQ,UAAA;AAAA,cAC3B,UAAA,EAAU,CAAA,CAAA,OAAA;;;;;KAEX,KAAA,GAAQ,CAAA,CAAE,KAAK,QAAQ,KAAA;AAAA,cACtB,KAAA,EAAK,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,OAIa,IAAA,CAClB,KAAA,EAAO,UAAA;IACL;EAAA,IAAa,eAAA,GACd,OAAA,CAAQ,QAAA;EAMJ,QAAA,IAAY,mBAAA;EAIZ,KAAA,CAAM,KAAA,UAAe,IAAA,GAAO,IAAA,GAAO,IAAA;EAOnC,QAAA,CACL,KAAA,UACA,QAAA,qBACA,IAAA,GAAM,cAAA,GACL,gBAAA;EAOI,WAAA,IAAe,UAAA;EAIf,WAAA,CAAY,KAAA,UAAe,MAAA;EAO3B,KAAA;EAAA,QAIC,IAAA;AAAA"}
package/dist/index.d.mts CHANGED
@@ -477,20 +477,30 @@ declare const CellChange: z.ZodObject<{
477
477
  value: z.ZodString;
478
478
  }, z.core.$strip>], "type">;
479
479
  }, z.core.$strip>;
480
+ type EvaluationMode = 'saved' | 'recalculated';
481
+ type ProgramErrorKind = z.infer<typeof ProgramErrorKind>;
482
+ declare const ProgramErrorKind: z.ZodEnum<{
483
+ invalid_workbook: "invalid_workbook";
484
+ invalid_request: "invalid_request";
485
+ }>;
480
486
  //#endregion
481
487
  //#region src/error.d.ts
482
- type XlsxErrorKind = 'invalid_workbook' | 'invalid_request' | 'out_of_memory' | 'crashed' | 'closed';
488
+ type XlsxErrorKind = ProgramErrorKind | 'out_of_memory' | 'crashed' | 'closed';
483
489
  declare class XlsxError extends Error {
484
490
  readonly kind: XlsxErrorKind;
485
491
  constructor(kind: XlsxErrorKind, message: string);
486
492
  }
487
493
  //#endregion
488
494
  //#region src/index.d.ts
489
- type EvaluationMode = 'saved' | 'recalculated';
495
+ type WorkbookOptions = {
496
+ maxMemory?: number;
497
+ };
490
498
  declare class Workbook {
491
499
  private readonly program;
492
500
  private constructor();
493
- static open(bytes: Uint8Array): Promise<Workbook>;
501
+ static open(bytes: Uint8Array, {
502
+ maxMemory
503
+ }?: WorkbookOptions): Promise<Workbook>;
494
504
  describe(): WorkbookDescription;
495
505
  cells(sheet: number, area?: Area): Cell[];
496
506
  evaluate(sheet: number, formulas: readonly string[], mode?: EvaluationMode): EvaluationResult[];
@@ -500,5 +510,5 @@ declare class Workbook {
500
510
  private call;
501
511
  }
502
512
  //#endregion
503
- export { type Area, type BorderSide, type Cell, type CellChange, type CellValue, type Color, EvaluationMode, type EvaluationResult, type Sheet, type SheetState, type Spill, type Style, Workbook, type WorkbookDescription, XlsxError, type XlsxErrorKind };
513
+ export { type Area, type BorderSide, type Cell, type CellChange, type CellValue, type Color, type EvaluationMode, type EvaluationResult, type Sheet, type SheetState, type Spill, type Style, Workbook, type WorkbookDescription, WorkbookOptions, XlsxError, type XlsxErrorKind };
504
514
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/schema.ts","../src/error.ts","../src/index.ts"],"mappings":";;;KAEY,IAAA,GAAO,CAAA,CAAE,KAAK,QAAQ,IAAA;AAAA,cACrB,IAAA,EAAI,CAAA,CAAA,SAAA;;;;;;KAOL,SAAA,GAAY,CAAA,CAAE,KAAK,QAAQ,SAAA;AAAA,cAC1B,SAAA,EAAS,CAAA,CAAA,qBAAA,EAAA,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;KAQV,KAAA,GAAQ,CAAA,CAAE,KAAK,QAAQ,KAAA;AAAA,cACtB,KAAA,EAAK,CAAA,CAAA,WAAA,CAAA,CAAA,CAAA,qBAAA,EAAA,CAAA,CAAA,SAAA;;;;;;;;KAON,UAAA,GAAa,CAAA,CAAE,KAAK,QAAQ,UAAA;AAAA,cAC3B,UAAA,EAAU,CAAA,CAAA,WAAA,CAAA,CAAA,CAAA,SAAA;;;;;;;;;;;KAIX,KAAA,GAAQ,CAAA,CAAE,KAAK,QAAQ,KAAA;AAAA,cACtB,KAAA,EAAK,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA2BN,UAAA,GAAa,CAAA,CAAE,KAAK,QAAQ,UAAA;AAAA,cAC3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A;EAAA,SACb,IAAA,EAAM,aAAA;cAEH,IAAA,EAAM,aAAA,EAAe,OAAA;AAAA;;;KCuB9B,eAAA;EAAoB,SAAS;AAAA;AAAA,cAE5B,QAAA;EAAA,iBACM,OAAA;EAAA,QAEV,WAAA;EAAA,OAIa,IAAA,CAClB,KAAA,EAAO,UAAA;IACL;EAAA,IAAa,eAAA,GACd,OAAA,CAAQ,QAAA;EAMJ,QAAA,IAAY,mBAAA;EAIZ,KAAA,CAAM,KAAA,UAAe,IAAA,GAAO,IAAA,GAAO,IAAA;EAOnC,QAAA,CACL,KAAA,UACA,QAAA,qBACA,IAAA,GAAM,cAAA,GACL,gBAAA;EAOI,WAAA,IAAe,UAAA;EAIf,WAAA,CAAY,KAAA,UAAe,MAAA;EAO3B,KAAA;EAAA,QAIC,IAAA;AAAA"}
package/dist/index.mjs CHANGED
@@ -11,21 +11,83 @@ var XlsxError = class extends Error {
11
11
  }
12
12
  };
13
13
  //#endregion
14
+ //#region src/memory-import.ts
15
+ const HEADER_BYTES = 8;
16
+ const IMPORT_SECTION = 2;
17
+ const FUNCTION_IMPORT = 0;
18
+ const MEMORY_IMPORT = 2;
19
+ function readMinimumPages(program) {
20
+ const reader = new ModuleReader(program, HEADER_BYTES);
21
+ while (reader.hasMore()) {
22
+ const section = reader.readByte();
23
+ const size = reader.readU32();
24
+ if (section !== IMPORT_SECTION) {
25
+ reader.skip(size);
26
+ continue;
27
+ }
28
+ for (let left = reader.readU32(); left > 0; left -= 1) {
29
+ reader.skip(reader.readU32());
30
+ reader.skip(reader.readU32());
31
+ const kind = reader.readByte();
32
+ if (kind === MEMORY_IMPORT) {
33
+ reader.readByte();
34
+ return reader.readU32();
35
+ }
36
+ if (kind !== FUNCTION_IMPORT) throw new TypeError("xlsx.wasm imports only functions and a memory.");
37
+ reader.readU32();
38
+ }
39
+ }
40
+ throw new TypeError("xlsx.wasm does not import a memory.");
41
+ }
42
+ var ModuleReader = class {
43
+ bytes;
44
+ offset;
45
+ constructor(bytes, offset) {
46
+ this.bytes = bytes;
47
+ this.offset = offset;
48
+ }
49
+ hasMore() {
50
+ return this.offset < this.bytes.length;
51
+ }
52
+ readByte() {
53
+ const byte = this.bytes[this.offset];
54
+ if (byte === void 0) throw new TypeError("xlsx.wasm ends in the middle of a section.");
55
+ this.offset += 1;
56
+ return byte;
57
+ }
58
+ readU32() {
59
+ let value = 0;
60
+ for (let shift = 0;; shift += 7) {
61
+ const byte = this.readByte();
62
+ value += (byte & 127) * 2 ** shift;
63
+ if (byte < 128) return value;
64
+ }
65
+ }
66
+ skip(length) {
67
+ this.offset += length;
68
+ }
69
+ };
70
+ //#endregion
14
71
  //#region src/program.ts
15
72
  const PROGRAM = new URL("../xlsx.wasm", import.meta.url);
73
+ const PAGE_BYTES = 65536;
16
74
  const OUT_OF_MEMORY = "memory allocation of";
17
75
  const encoder = new TextEncoder();
18
76
  const decoder = new TextDecoder();
19
- let compiled = null;
77
+ let loading = null;
20
78
  var ProgramInstance = class ProgramInstance {
79
+ memory;
21
80
  exports;
22
81
  stderr;
23
82
  failure = null;
24
- constructor(exports, stderr) {
83
+ constructor(memory, exports, stderr) {
84
+ this.memory = memory;
25
85
  this.exports = exports;
26
86
  this.stderr = stderr;
27
87
  }
28
- static async start() {
88
+ static async start(maxMemory) {
89
+ const program = await loadProgram();
90
+ const memory = createMemory(program.minimumPages, maxMemory);
29
91
  const stderr = new OutputBuffer();
30
92
  const wasi = new WASI(["xlsx"], [], [
31
93
  new OpenFile(new File([])),
@@ -34,9 +96,12 @@ var ProgramInstance = class ProgramInstance {
34
96
  stderr.push(chunk);
35
97
  })
36
98
  ], { debug: false });
37
- const exports = toExports(await WebAssembly.instantiate(await loadProgram(), { wasi_snapshot_preview1: wasi.wasiImport }));
38
- wasi.initialize({ exports: { memory: exports.memory } });
39
- return new ProgramInstance(exports, stderr);
99
+ const instance = await WebAssembly.instantiate(program.module, {
100
+ env: { memory },
101
+ wasi_snapshot_preview1: wasi.wasiImport
102
+ });
103
+ wasi.initialize({ exports: { memory } });
104
+ return new ProgramInstance(memory, toExports(instance), stderr);
40
105
  }
41
106
  open(bytes) {
42
107
  return this.run((exports) => {
@@ -59,7 +124,7 @@ var ProgramInstance = class ProgramInstance {
59
124
  try {
60
125
  const length = invoke(this.exports);
61
126
  const pointer = this.exports.response();
62
- return decoder.decode(new Uint8Array(this.exports.memory.buffer, pointer, length));
127
+ return decoder.decode(new Uint8Array(this.memory.buffer, pointer, length));
63
128
  } catch (cause) {
64
129
  if (cause instanceof WebAssembly.RuntimeError) {
65
130
  this.failure = toTrapError(this.stderr.toText(), cause);
@@ -70,19 +135,30 @@ var ProgramInstance = class ProgramInstance {
70
135
  }
71
136
  write(bytes) {
72
137
  const pointer = this.exports.alloc(bytes.length);
73
- new Uint8Array(this.exports.memory.buffer, pointer, bytes.length).set(bytes);
138
+ new Uint8Array(this.memory.buffer, pointer, bytes.length).set(bytes);
74
139
  return pointer;
75
140
  }
76
141
  };
77
142
  function loadProgram() {
78
- compiled ??= readFile(PROGRAM).then((bytes) => WebAssembly.compile(bytes));
79
- return compiled;
143
+ loading ??= readFile(PROGRAM).then(async (bytes) => ({
144
+ module: await WebAssembly.compile(bytes),
145
+ minimumPages: readMinimumPages(bytes)
146
+ }));
147
+ return loading;
148
+ }
149
+ function createMemory(minimumPages, maxMemory) {
150
+ if (maxMemory === void 0) return new WebAssembly.Memory({ initial: minimumPages });
151
+ const maximumPages = Math.floor(maxMemory / PAGE_BYTES);
152
+ if (maximumPages < minimumPages) throw new RangeError(`maxMemory is ${String(maxMemory)} bytes; xlsx.wasm needs at least ${String(minimumPages * PAGE_BYTES)}.`);
153
+ return new WebAssembly.Memory({
154
+ initial: minimumPages,
155
+ maximum: maximumPages
156
+ });
80
157
  }
81
158
  function toExports(instance) {
82
- const { memory, xlsx_alloc: alloc, xlsx_open: open, xlsx_call: call, xlsx_response: response } = instance.exports;
83
- if (!(memory instanceof WebAssembly.Memory) || typeof alloc !== "function" || typeof open !== "function" || typeof call !== "function" || typeof response !== "function") throw new TypeError("xlsx.wasm does not export the expected functions.");
159
+ const { xlsx_alloc: alloc, xlsx_open: open, xlsx_call: call, xlsx_response: response } = instance.exports;
160
+ if (typeof alloc !== "function" || typeof open !== "function" || typeof call !== "function" || typeof response !== "function") throw new TypeError("xlsx.wasm does not export the expected functions.");
84
161
  return {
85
- memory,
86
162
  alloc: (length) => toAddress(Reflect.apply(alloc, null, [length])),
87
163
  open: (pointer, length) => toAddress(Reflect.apply(open, null, [pointer, length])),
88
164
  call: (pointer, length) => toAddress(Reflect.apply(call, null, [pointer, length])),
@@ -94,7 +170,7 @@ function toAddress(value) {
94
170
  return value >>> 0;
95
171
  }
96
172
  function toTrapError(stderr, cause) {
97
- if (stderr.includes(OUT_OF_MEMORY)) return new XlsxError("out_of_memory", "The workbook needed more memory than xlsx.wasm may use.");
173
+ if (stderr.includes(OUT_OF_MEMORY)) return new XlsxError("out_of_memory", "The workbook needed more memory than maxMemory allows.");
98
174
  return new XlsxError("crashed", stderr.trim() || cause.message);
99
175
  }
100
176
  var OutputBuffer = class {
@@ -281,8 +357,8 @@ var Workbook = class Workbook {
281
357
  constructor(program) {
282
358
  this.program = program;
283
359
  }
284
- static async open(bytes) {
285
- const program = await ProgramInstance.start();
360
+ static async open(bytes, { maxMemory } = {}) {
361
+ const program = await ProgramInstance.start(maxMemory);
286
362
  parse(z.null(), program.open(bytes));
287
363
  return new Workbook(program);
288
364
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/error.ts","../src/program.ts","../src/schema.ts","../src/index.ts"],"sourcesContent":["export type XlsxErrorKind =\n | 'invalid_workbook'\n | 'invalid_request'\n | 'out_of_memory'\n | 'crashed'\n | 'closed'\n\nexport class XlsxError extends Error {\n public readonly kind: XlsxErrorKind\n\n public constructor(kind: XlsxErrorKind, message: string) {\n super(message)\n this.name = 'XlsxError'\n this.kind = kind\n }\n}\n","import { ConsoleStdout, File, OpenFile, WASI } from '@bjorn3/browser_wasi_shim'\nimport { readFile } from 'node:fs/promises'\nimport { XlsxError } from './error'\n\nconst PROGRAM = new URL('../xlsx.wasm', import.meta.url)\n\nconst OUT_OF_MEMORY = 'memory allocation of'\n\nconst encoder = new TextEncoder()\n\nconst decoder = new TextDecoder()\n\nlet compiled: Promise<WebAssembly.Module> | null = null\n\ntype Exports = {\n memory: WebAssembly.Memory\n alloc: (length: number) => number\n open: (pointer: number, length: number) => number\n call: (pointer: number, length: number) => number\n response: () => number\n}\n\nexport class ProgramInstance {\n private readonly exports: Exports\n private readonly stderr: OutputBuffer\n private failure: XlsxError | null = null\n\n private constructor(exports: Exports, stderr: OutputBuffer) {\n this.exports = exports\n this.stderr = stderr\n }\n\n public static async start(): Promise<ProgramInstance> {\n const stderr = new OutputBuffer()\n const wasi = new WASI(\n ['xlsx'],\n [],\n [\n new OpenFile(new File([])),\n new ConsoleStdout(() => undefined),\n new ConsoleStdout((chunk) => {\n stderr.push(chunk)\n }),\n ],\n { debug: false },\n )\n const instance = await WebAssembly.instantiate(await loadProgram(), {\n wasi_snapshot_preview1: wasi.wasiImport,\n })\n const exports = toExports(instance)\n wasi.initialize({ exports: { memory: exports.memory } })\n return new ProgramInstance(exports, stderr)\n }\n\n public open(bytes: Uint8Array): string {\n return this.run((exports) => {\n const pointer = this.write(bytes)\n return exports.open(pointer, bytes.length)\n })\n }\n\n public call(request: unknown): string {\n const bytes = encoder.encode(JSON.stringify(request))\n return this.run((exports) => {\n const pointer = this.write(bytes)\n return exports.call(pointer, bytes.length)\n })\n }\n\n public close(): void {\n this.failure ??= new XlsxError('closed', 'The workbook is closed.')\n }\n\n private run(invoke: (exports: Exports) => number): string {\n if (this.failure !== null) {\n throw this.failure\n }\n try {\n const length = invoke(this.exports)\n const pointer = this.exports.response()\n return decoder.decode(\n new Uint8Array(this.exports.memory.buffer, pointer, length),\n )\n } catch (cause) {\n if (cause instanceof WebAssembly.RuntimeError) {\n this.failure = toTrapError(this.stderr.toText(), cause)\n throw this.failure\n }\n throw cause\n }\n }\n\n private write(bytes: Uint8Array): number {\n const pointer = this.exports.alloc(bytes.length)\n new Uint8Array(this.exports.memory.buffer, pointer, bytes.length).set(bytes)\n return pointer\n }\n}\n\nfunction loadProgram(): Promise<WebAssembly.Module> {\n compiled ??= readFile(PROGRAM).then((bytes) => WebAssembly.compile(bytes))\n return compiled\n}\n\nfunction toExports(instance: WebAssembly.Instance): Exports {\n const {\n memory,\n xlsx_alloc: alloc,\n xlsx_open: open,\n xlsx_call: call,\n xlsx_response: response,\n } = instance.exports\n if (\n !(memory instanceof WebAssembly.Memory) ||\n typeof alloc !== 'function' ||\n typeof open !== 'function' ||\n typeof call !== 'function' ||\n typeof response !== 'function'\n ) {\n throw new TypeError('xlsx.wasm does not export the expected functions.')\n }\n return {\n memory,\n alloc: (length) => toAddress(Reflect.apply(alloc, null, [length])),\n open: (pointer, length) =>\n toAddress(Reflect.apply(open, null, [pointer, length])),\n call: (pointer, length) =>\n toAddress(Reflect.apply(call, null, [pointer, length])),\n response: () => toAddress(Reflect.apply(response, null, [])),\n }\n}\n\nfunction toAddress(value: unknown): number {\n if (typeof value !== 'number') {\n throw new TypeError('xlsx.wasm returned a value that is not a number.')\n }\n return value >>> 0\n}\n\nfunction toTrapError(\n stderr: string,\n cause: WebAssembly.RuntimeError,\n): XlsxError {\n if (stderr.includes(OUT_OF_MEMORY)) {\n return new XlsxError(\n 'out_of_memory',\n 'The workbook needed more memory than xlsx.wasm may use.',\n )\n }\n return new XlsxError('crashed', stderr.trim() || cause.message)\n}\n\nclass OutputBuffer {\n private readonly chunks: Uint8Array[] = []\n\n public push(chunk: Uint8Array): void {\n this.chunks.push(chunk.slice())\n }\n\n public toText(): string {\n return Buffer.concat(this.chunks).toString('utf-8')\n }\n}\n","import * as z from 'zod'\n\nexport type Area = z.infer<typeof Area>\nexport const Area = z.object({\n firstRow: z.number().int(),\n firstColumn: z.number().int(),\n lastRow: z.number().int(),\n lastColumn: z.number().int(),\n})\n\nexport type CellValue = z.infer<typeof CellValue>\nexport const CellValue = z.discriminatedUnion('type', [\n z.object({ type: z.literal('empty') }),\n z.object({ type: z.literal('number'), value: z.number() }),\n z.object({ type: z.literal('text'), value: z.string() }),\n z.object({ type: z.literal('boolean'), value: z.boolean() }),\n z.object({ type: z.literal('error'), value: z.string() }),\n])\n\nexport type Color = z.infer<typeof Color>\nexport const Color = z\n .discriminatedUnion('kind', [\n z.object({ kind: z.literal('rgb'), hex: z.string() }),\n z.object({ kind: z.literal('theme'), index: z.number(), tint: z.number() }),\n ])\n .nullable()\n\nexport type BorderSide = z.infer<typeof BorderSide>\nexport const BorderSide = z\n .object({ style: z.string(), color: Color })\n .nullable()\n\nexport type Style = z.infer<typeof Style>\nexport const Style = z.object({\n numberFormat: z.string(),\n font: z.object({\n name: z.string(),\n size: z.number(),\n bold: z.boolean(),\n italic: z.boolean(),\n underline: z.boolean(),\n strike: z.boolean(),\n color: Color,\n }),\n fill: Color,\n alignment: z\n .object({\n horizontal: z.string(),\n vertical: z.string(),\n wrapText: z.boolean(),\n })\n .nullable(),\n borders: z.object({\n top: BorderSide,\n right: BorderSide,\n bottom: BorderSide,\n left: BorderSide,\n }),\n})\n\nexport type SheetState = z.infer<typeof SheetState>\nexport const SheetState = z.enum(['visible', 'hidden', 'very_hidden'])\n\nexport type Sheet = z.infer<typeof Sheet>\nexport const Sheet = z.object({\n index: z.number().int(),\n name: z.string(),\n state: SheetState,\n color: Color,\n extent: Area.nullable(),\n frozenRows: z.number().int(),\n frozenColumns: z.number().int(),\n merged: z.array(Area),\n hiddenRows: z.array(z.number().int()),\n hiddenColumns: z.array(\n z.object({ first: z.number().int(), last: z.number().int() }),\n ),\n comments: z.array(\n z.object({\n row: z.number().int(),\n column: z.number().int(),\n author: z.string(),\n text: z.string(),\n }),\n ),\n links: z.array(\n z.object({\n row: z.number().int(),\n column: z.number().int(),\n kind: z.enum(['external', 'internal']),\n target: z.string(),\n tooltip: z.string().nullable(),\n }),\n ),\n conditionalFormats: z.array(\n z.object({\n range: z.string(),\n kind: z.string(),\n priority: z.number().int(),\n }),\n ),\n})\n\nexport type WorkbookDescription = z.infer<typeof WorkbookDescription>\nexport const WorkbookDescription = z.object({\n metadata: z.object({\n application: z.string(),\n appVersion: z.string(),\n creator: z.string(),\n lastModifiedBy: z.string(),\n created: z.string(),\n lastModified: z.string(),\n }),\n locale: z.string(),\n timezone: z.string(),\n definedNames: z.array(\n z.object({\n name: z.string(),\n sheet: z.number().int().nullable(),\n formula: z.string(),\n }),\n ),\n tables: z.array(\n z.object({\n name: z.string(),\n displayName: z.string(),\n sheet: z.number().int().nullable(),\n range: z.string(),\n headerRows: z.number().int(),\n totalsRows: z.number().int(),\n columns: z.array(z.string()),\n hasFilters: z.boolean(),\n }),\n ),\n styles: z.record(z.string(), Style),\n sheets: z.array(Sheet),\n})\n\nexport type Spill = z.infer<typeof Spill>\nexport const Spill = z\n .discriminatedUnion('kind', [\n z.object({ kind: z.literal('anchor'), range: Area }),\n z.object({\n kind: z.literal('part'),\n anchor: z.object({ row: z.number().int(), column: z.number().int() }),\n }),\n ])\n .nullable()\n\nexport type Cell = z.infer<typeof Cell>\nexport const Cell = z.object({\n row: z.number().int(),\n column: z.number().int(),\n value: CellValue,\n text: z.string(),\n formula: z.string().nullable(),\n style: z.number().int(),\n spill: Spill,\n})\n\nexport type EvaluationResult = z.infer<typeof EvaluationResult>\nexport const EvaluationResult = z.discriminatedUnion('kind', [\n z.object({ kind: z.literal('value'), value: CellValue }),\n z.object({ kind: z.literal('array'), rows: z.array(z.array(CellValue)) }),\n])\n\nexport type CellChange = z.infer<typeof CellChange>\nexport const CellChange = z.object({\n sheet: z.number().int(),\n row: z.number().int(),\n column: z.number().int(),\n saved: CellValue,\n recalculated: CellValue,\n})\n\nexport type ProgramErrorKind = z.infer<typeof ProgramErrorKind>\nexport const ProgramErrorKind = z.enum(['invalid_workbook', 'invalid_request'])\n\nexport type ProgramResponse = z.infer<typeof ProgramResponse>\nexport const ProgramResponse = z.union([\n z.object({\n error: z.object({ kind: ProgramErrorKind, message: z.string() }),\n }),\n z.object({ ok: z.unknown() }),\n])\n","import * as z from 'zod'\nimport { XlsxError } from './error'\nimport { ProgramInstance } from './program'\nimport {\n type Area,\n Cell,\n CellChange,\n EvaluationResult,\n ProgramResponse,\n WorkbookDescription,\n} from './schema'\n\nexport { XlsxError, type XlsxErrorKind } from './error'\nexport type {\n Area,\n BorderSide,\n Cell,\n CellChange,\n CellValue,\n Color,\n EvaluationResult,\n Sheet,\n SheetState,\n Spill,\n Style,\n WorkbookDescription,\n} from './schema'\n\nexport type EvaluationMode = 'saved' | 'recalculated'\n\nexport class Workbook {\n private readonly program: ProgramInstance\n\n private constructor(program: ProgramInstance) {\n this.program = program\n }\n\n public static async open(bytes: Uint8Array): Promise<Workbook> {\n const program = await ProgramInstance.start()\n parse(z.null(), program.open(bytes))\n return new Workbook(program)\n }\n\n public describe(): WorkbookDescription {\n return this.call(WorkbookDescription, { method: 'describe' })\n }\n\n public cells(sheet: number, area?: Area): Cell[] {\n return this.call(z.array(Cell), {\n method: 'cells',\n params: { sheet, area: area ?? null },\n })\n }\n\n public evaluate(\n sheet: number,\n formulas: readonly string[],\n mode: EvaluationMode = 'saved',\n ): EvaluationResult[] {\n return this.call(z.array(EvaluationResult), {\n method: 'evaluate',\n params: { sheet, formulas, mode },\n })\n }\n\n public recalculate(): CellChange[] {\n return this.call(z.array(CellChange), { method: 'recalculate' })\n }\n\n public formatValue(value: number, format: string): string {\n return this.call(z.string(), {\n method: 'format_value',\n params: { value, format },\n })\n }\n\n public close(): void {\n this.program.close()\n }\n\n private call<Schema extends z.ZodType>(\n schema: Schema,\n request: unknown,\n ): z.output<Schema> {\n return parse(schema, this.program.call(request))\n }\n}\n\nfunction parse<Schema extends z.ZodType>(\n schema: Schema,\n text: string,\n): z.output<Schema> {\n const response = ProgramResponse.parse(JSON.parse(text))\n if ('error' in response) {\n throw new XlsxError(response.error.kind, response.error.message)\n }\n return schema.parse(response.ok)\n}\n"],"mappings":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AAO;EAC1B,CAAC;CACH;CAEA,QAAqB;EACnB,KAAK,QAAQ,MAAM;CACrB;CAEA,KACE,QACA,SACkB;EAClB,OAAO,MAAM,QAAQ,KAAK,QAAQ,KAAK,OAAO,CAAC;CACjD;AACF;AAEA,SAAS,MACP,QACA,MACkB;CAClB,MAAM,WAAW,gBAAgB,MAAM,KAAK,MAAM,IAAI,CAAC;CACvD,IAAI,WAAW,UACb,MAAM,IAAI,UAAU,SAAS,MAAM,MAAM,SAAS,MAAM,OAAO;CAEjE,OAAO,OAAO,MAAM,SAAS,EAAE;AACjC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/error.ts","../src/memory-import.ts","../src/program.ts","../src/schema.ts","../src/index.ts"],"sourcesContent":["import type { ProgramErrorKind } from './schema'\n\nexport type XlsxErrorKind =\n ProgramErrorKind | 'out_of_memory' | 'crashed' | 'closed'\n\nexport class XlsxError extends Error {\n public readonly kind: XlsxErrorKind\n\n public constructor(kind: XlsxErrorKind, message: string) {\n super(message)\n this.name = 'XlsxError'\n this.kind = kind\n }\n}\n","const HEADER_BYTES = 8\n\nconst IMPORT_SECTION = 2\n\nconst FUNCTION_IMPORT = 0\n\nconst MEMORY_IMPORT = 2\n\nexport function readMinimumPages(program: Uint8Array): number {\n const reader = new ModuleReader(program, HEADER_BYTES)\n while (reader.hasMore()) {\n const section = reader.readByte()\n const size = reader.readU32()\n if (section !== IMPORT_SECTION) {\n reader.skip(size)\n continue\n }\n for (let left = reader.readU32(); left > 0; left -= 1) {\n reader.skip(reader.readU32())\n reader.skip(reader.readU32())\n const kind = reader.readByte()\n if (kind === MEMORY_IMPORT) {\n reader.readByte()\n return reader.readU32()\n }\n if (kind !== FUNCTION_IMPORT) {\n throw new TypeError('xlsx.wasm imports only functions and a memory.')\n }\n reader.readU32()\n }\n }\n throw new TypeError('xlsx.wasm does not import a memory.')\n}\n\nclass ModuleReader {\n private readonly bytes: Uint8Array\n private offset: number\n\n public constructor(bytes: Uint8Array, offset: number) {\n this.bytes = bytes\n this.offset = offset\n }\n\n public hasMore(): boolean {\n return this.offset < this.bytes.length\n }\n\n public readByte(): number {\n const byte = this.bytes[this.offset]\n if (byte === undefined) {\n throw new TypeError('xlsx.wasm ends in the middle of a section.')\n }\n this.offset += 1\n return byte\n }\n\n public readU32(): number {\n let value = 0\n for (let shift = 0; ; shift += 7) {\n const byte = this.readByte()\n value += (byte & 0x7f) * 2 ** shift\n if (byte < 0x80) {\n return value\n }\n }\n }\n\n public skip(length: number): void {\n this.offset += length\n }\n}\n","import { ConsoleStdout, File, OpenFile, WASI } from '@bjorn3/browser_wasi_shim'\nimport { readFile } from 'node:fs/promises'\nimport { XlsxError } from './error'\nimport { readMinimumPages } from './memory-import'\nimport type { ProgramRequest } from './schema'\n\nconst PROGRAM = new URL('../xlsx.wasm', import.meta.url)\n\nconst PAGE_BYTES = 65_536\n\nconst OUT_OF_MEMORY = 'memory allocation of'\n\nconst encoder = new TextEncoder()\n\nconst decoder = new TextDecoder()\n\nlet loading: Promise<Program> | null = null\n\ntype Exports = {\n alloc: (length: number) => number\n open: (pointer: number, length: number) => number\n call: (pointer: number, length: number) => number\n response: () => number\n}\n\nexport class ProgramInstance {\n private readonly memory: WebAssembly.Memory\n private readonly exports: Exports\n private readonly stderr: OutputBuffer\n private failure: XlsxError | null = null\n\n private constructor(\n memory: WebAssembly.Memory,\n exports: Exports,\n stderr: OutputBuffer,\n ) {\n this.memory = memory\n this.exports = exports\n this.stderr = stderr\n }\n\n public static async start(\n maxMemory: number | undefined,\n ): Promise<ProgramInstance> {\n const program = await loadProgram()\n const memory = createMemory(program.minimumPages, maxMemory)\n const stderr = new OutputBuffer()\n const wasi = new WASI(\n ['xlsx'],\n [],\n [\n new OpenFile(new File([])),\n new ConsoleStdout(() => undefined),\n new ConsoleStdout((chunk) => {\n stderr.push(chunk)\n }),\n ],\n { debug: false },\n )\n const instance = await WebAssembly.instantiate(program.module, {\n env: { memory },\n wasi_snapshot_preview1: wasi.wasiImport,\n })\n wasi.initialize({ exports: { memory } })\n return new ProgramInstance(memory, toExports(instance), stderr)\n }\n\n public open(bytes: Uint8Array): string {\n return this.run((exports) => {\n const pointer = this.write(bytes)\n return exports.open(pointer, bytes.length)\n })\n }\n\n public call(request: ProgramRequest): string {\n const bytes = encoder.encode(JSON.stringify(request))\n return this.run((exports) => {\n const pointer = this.write(bytes)\n return exports.call(pointer, bytes.length)\n })\n }\n\n public close(): void {\n this.failure ??= new XlsxError('closed', 'The workbook is closed.')\n }\n\n private run(invoke: (exports: Exports) => number): string {\n if (this.failure !== null) {\n throw this.failure\n }\n try {\n const length = invoke(this.exports)\n const pointer = this.exports.response()\n return decoder.decode(new Uint8Array(this.memory.buffer, pointer, length))\n } catch (cause) {\n if (cause instanceof WebAssembly.RuntimeError) {\n this.failure = toTrapError(this.stderr.toText(), cause)\n throw this.failure\n }\n throw cause\n }\n }\n\n private write(bytes: Uint8Array): number {\n const pointer = this.exports.alloc(bytes.length)\n new Uint8Array(this.memory.buffer, pointer, bytes.length).set(bytes)\n return pointer\n }\n}\n\ntype Program = { module: WebAssembly.Module; minimumPages: number }\n\nfunction loadProgram(): Promise<Program> {\n loading ??= readFile(PROGRAM).then(async (bytes) => ({\n module: await WebAssembly.compile(bytes),\n minimumPages: readMinimumPages(bytes),\n }))\n return loading\n}\n\nfunction createMemory(\n minimumPages: number,\n maxMemory: number | undefined,\n): WebAssembly.Memory {\n if (maxMemory === undefined) {\n return new WebAssembly.Memory({ initial: minimumPages })\n }\n const maximumPages = Math.floor(maxMemory / PAGE_BYTES)\n if (maximumPages < minimumPages) {\n throw new RangeError(\n `maxMemory is ${String(maxMemory)} bytes; xlsx.wasm needs at least ${String(minimumPages * PAGE_BYTES)}.`,\n )\n }\n return new WebAssembly.Memory({\n initial: minimumPages,\n maximum: maximumPages,\n })\n}\n\nfunction toExports(instance: WebAssembly.Instance): Exports {\n const {\n xlsx_alloc: alloc,\n xlsx_open: open,\n xlsx_call: call,\n xlsx_response: response,\n } = instance.exports\n if (\n typeof alloc !== 'function' ||\n typeof open !== 'function' ||\n typeof call !== 'function' ||\n typeof response !== 'function'\n ) {\n throw new TypeError('xlsx.wasm does not export the expected functions.')\n }\n return {\n alloc: (length) => toAddress(Reflect.apply(alloc, null, [length])),\n open: (pointer, length) =>\n toAddress(Reflect.apply(open, null, [pointer, length])),\n call: (pointer, length) =>\n toAddress(Reflect.apply(call, null, [pointer, length])),\n response: () => toAddress(Reflect.apply(response, null, [])),\n }\n}\n\nfunction toAddress(value: unknown): number {\n if (typeof value !== 'number') {\n throw new TypeError('xlsx.wasm returned a value that is not a number.')\n }\n return value >>> 0\n}\n\nfunction toTrapError(\n stderr: string,\n cause: WebAssembly.RuntimeError,\n): XlsxError {\n if (stderr.includes(OUT_OF_MEMORY)) {\n return new XlsxError(\n 'out_of_memory',\n 'The workbook needed more memory than maxMemory allows.',\n )\n }\n return new XlsxError('crashed', stderr.trim() || cause.message)\n}\n\nclass OutputBuffer {\n private readonly chunks: Uint8Array[] = []\n\n public push(chunk: Uint8Array): void {\n this.chunks.push(chunk.slice())\n }\n\n public toText(): string {\n return Buffer.concat(this.chunks).toString('utf-8')\n }\n}\n","import * as z from 'zod'\n\nexport type Area = z.infer<typeof Area>\nexport const Area = z.object({\n firstRow: z.number().int(),\n firstColumn: z.number().int(),\n lastRow: z.number().int(),\n lastColumn: z.number().int(),\n})\n\nexport type CellValue = z.infer<typeof CellValue>\nexport const CellValue = z.discriminatedUnion('type', [\n z.object({ type: z.literal('empty') }),\n z.object({ type: z.literal('number'), value: z.number() }),\n z.object({ type: z.literal('text'), value: z.string() }),\n z.object({ type: z.literal('boolean'), value: z.boolean() }),\n z.object({ type: z.literal('error'), value: z.string() }),\n])\n\nexport type Color = z.infer<typeof Color>\nexport const Color = z\n .discriminatedUnion('kind', [\n z.object({ kind: z.literal('rgb'), hex: z.string() }),\n z.object({ kind: z.literal('theme'), index: z.number(), tint: z.number() }),\n ])\n .nullable()\n\nexport type BorderSide = z.infer<typeof BorderSide>\nexport const BorderSide = z\n .object({ style: z.string(), color: Color })\n .nullable()\n\nexport type Style = z.infer<typeof Style>\nexport const Style = z.object({\n numberFormat: z.string(),\n font: z.object({\n name: z.string(),\n size: z.number(),\n bold: z.boolean(),\n italic: z.boolean(),\n underline: z.boolean(),\n strike: z.boolean(),\n color: Color,\n }),\n fill: Color,\n alignment: z\n .object({\n horizontal: z.string(),\n vertical: z.string(),\n wrapText: z.boolean(),\n })\n .nullable(),\n borders: z.object({\n top: BorderSide,\n right: BorderSide,\n bottom: BorderSide,\n left: BorderSide,\n }),\n})\n\nexport type SheetState = z.infer<typeof SheetState>\nexport const SheetState = z.enum(['visible', 'hidden', 'very_hidden'])\n\nexport type Sheet = z.infer<typeof Sheet>\nexport const Sheet = z.object({\n index: z.number().int(),\n name: z.string(),\n state: SheetState,\n color: Color,\n extent: Area.nullable(),\n frozenRows: z.number().int(),\n frozenColumns: z.number().int(),\n merged: z.array(Area),\n hiddenRows: z.array(z.number().int()),\n hiddenColumns: z.array(\n z.object({ first: z.number().int(), last: z.number().int() }),\n ),\n comments: z.array(\n z.object({\n row: z.number().int(),\n column: z.number().int(),\n author: z.string(),\n text: z.string(),\n }),\n ),\n links: z.array(\n z.object({\n row: z.number().int(),\n column: z.number().int(),\n kind: z.enum(['external', 'internal']),\n target: z.string(),\n tooltip: z.string().nullable(),\n }),\n ),\n conditionalFormats: z.array(\n z.object({\n range: z.string(),\n kind: z.string(),\n priority: z.number().int(),\n }),\n ),\n})\n\nexport type WorkbookDescription = z.infer<typeof WorkbookDescription>\nexport const WorkbookDescription = z.object({\n metadata: z.object({\n application: z.string(),\n appVersion: z.string(),\n creator: z.string(),\n lastModifiedBy: z.string(),\n created: z.string(),\n lastModified: z.string(),\n }),\n locale: z.string(),\n timezone: z.string(),\n definedNames: z.array(\n z.object({\n name: z.string(),\n sheet: z.number().int().nullable(),\n formula: z.string(),\n }),\n ),\n tables: z.array(\n z.object({\n name: z.string(),\n displayName: z.string(),\n sheet: z.number().int().nullable(),\n range: z.string(),\n headerRows: z.number().int(),\n totalsRows: z.number().int(),\n columns: z.array(z.string()),\n hasFilters: z.boolean(),\n }),\n ),\n styles: z.record(z.string(), Style),\n sheets: z.array(Sheet),\n})\n\nexport type Spill = z.infer<typeof Spill>\nexport const Spill = z\n .discriminatedUnion('kind', [\n z.object({ kind: z.literal('anchor'), range: Area }),\n z.object({\n kind: z.literal('part'),\n anchor: z.object({ row: z.number().int(), column: z.number().int() }),\n }),\n ])\n .nullable()\n\nexport type Cell = z.infer<typeof Cell>\nexport const Cell = z.object({\n row: z.number().int(),\n column: z.number().int(),\n value: CellValue,\n text: z.string(),\n formula: z.string().nullable(),\n style: z.number().int(),\n spill: Spill,\n})\n\nexport type EvaluationResult = z.infer<typeof EvaluationResult>\nexport const EvaluationResult = z.discriminatedUnion('kind', [\n z.object({ kind: z.literal('value'), value: CellValue }),\n z.object({ kind: z.literal('array'), rows: z.array(z.array(CellValue)) }),\n])\n\nexport type CellChange = z.infer<typeof CellChange>\nexport const CellChange = z.object({\n sheet: z.number().int(),\n row: z.number().int(),\n column: z.number().int(),\n saved: CellValue,\n recalculated: CellValue,\n})\n\nexport type EvaluationMode = 'saved' | 'recalculated'\n\nexport type ProgramRequest =\n | { method: 'describe' }\n | { method: 'cells'; params: { sheet: number; area: Area | null } }\n | {\n method: 'evaluate'\n params: {\n sheet: number\n formulas: readonly string[]\n mode: EvaluationMode\n }\n }\n | { method: 'recalculate' }\n | { method: 'format_value'; params: { value: number; format: string } }\n\nexport type ProgramErrorKind = z.infer<typeof ProgramErrorKind>\nexport const ProgramErrorKind = z.enum(['invalid_workbook', 'invalid_request'])\n\nexport type ProgramResponse = z.infer<typeof ProgramResponse>\nexport const ProgramResponse = z.union([\n z.object({\n error: z.object({ kind: ProgramErrorKind, message: z.string() }),\n }),\n z.object({ ok: z.unknown() }),\n])\n","import * as z from 'zod'\nimport { XlsxError } from './error'\nimport { ProgramInstance } from './program'\nimport {\n type Area,\n Cell,\n CellChange,\n type EvaluationMode,\n EvaluationResult,\n type ProgramRequest,\n ProgramResponse,\n WorkbookDescription,\n} from './schema'\n\nexport { XlsxError, type XlsxErrorKind } from './error'\nexport type {\n Area,\n BorderSide,\n Cell,\n CellChange,\n CellValue,\n Color,\n EvaluationMode,\n EvaluationResult,\n Sheet,\n SheetState,\n Spill,\n Style,\n WorkbookDescription,\n} from './schema'\n\nexport type WorkbookOptions = { maxMemory?: number }\n\nexport class Workbook {\n private readonly program: ProgramInstance\n\n private constructor(program: ProgramInstance) {\n this.program = program\n }\n\n public static async open(\n bytes: Uint8Array,\n { maxMemory }: WorkbookOptions = {},\n ): Promise<Workbook> {\n const program = await ProgramInstance.start(maxMemory)\n parse(z.null(), program.open(bytes))\n return new Workbook(program)\n }\n\n public describe(): WorkbookDescription {\n return this.call(WorkbookDescription, { method: 'describe' })\n }\n\n public cells(sheet: number, area?: Area): Cell[] {\n return this.call(z.array(Cell), {\n method: 'cells',\n params: { sheet, area: area ?? null },\n })\n }\n\n public evaluate(\n sheet: number,\n formulas: readonly string[],\n mode: EvaluationMode = 'saved',\n ): EvaluationResult[] {\n return this.call(z.array(EvaluationResult), {\n method: 'evaluate',\n params: { sheet, formulas, mode },\n })\n }\n\n public recalculate(): CellChange[] {\n return this.call(z.array(CellChange), { method: 'recalculate' })\n }\n\n public formatValue(value: number, format: string): string {\n return this.call(z.string(), {\n method: 'format_value',\n params: { value, format },\n })\n }\n\n public close(): void {\n this.program.close()\n }\n\n private call<Schema extends z.ZodType>(\n schema: Schema,\n request: ProgramRequest,\n ): z.output<Schema> {\n return parse(schema, this.program.call(request))\n }\n}\n\nfunction parse<Schema extends z.ZodType>(\n schema: Schema,\n text: string,\n): z.output<Schema> {\n const response = ProgramResponse.parse(JSON.parse(text))\n if ('error' in response) {\n throw new XlsxError(response.error.kind, response.error.message)\n }\n return schema.parse(response.ok)\n}\n"],"mappings":";;;;AAKA,IAAa,YAAb,cAA+B,MAAM;CACnC;CAEA,YAAmB,MAAqB,SAA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IAAE;IAAO,MAAM,QAAQ;GAAK;EACtC,CAAC;CACH;CAEA,SACE,OACA,UACA,OAAuB,SACH;EACpB,OAAO,KAAK,KAAK,EAAE,MAAM,gBAAgB,GAAG;GAC1C,QAAQ;GACR,QAAQ;IAAE;IAAO;IAAU;GAAK;EAClC,CAAC;CACH;CAEA,cAAmC;EACjC,OAAO,KAAK,KAAK,EAAE,MAAM,UAAU,GAAG,EAAE,QAAQ,cAAc,CAAC;CACjE;CAEA,YAAmB,OAAe,QAAwB;EACxD,OAAO,KAAK,KAAK,EAAE,OAAO,GAAG;GAC3B,QAAQ;GACR,QAAQ;IAAE;IAAO;GAAO;EAC1B,CAAC;CACH;CAEA,QAAqB;EACnB,KAAK,QAAQ,MAAM;CACrB;CAEA,KACE,QACA,SACkB;EAClB,OAAO,MAAM,QAAQ,KAAK,QAAQ,KAAK,OAAO,CAAC;CACjD;AACF;AAEA,SAAS,MACP,QACA,MACkB;CAClB,MAAM,WAAW,gBAAgB,MAAM,KAAK,MAAM,IAAI,CAAC;CACvD,IAAI,WAAW,UACb,MAAM,IAAI,UAAU,SAAS,MAAM,MAAM,SAAS,MAAM,OAAO;CAEjE,OAAO,OAAO,MAAM,SAAS,EAAE;AACjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coloop-ai/xlsx-wasm",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Read Excel workbooks as Excel shows them: a sandboxed WebAssembly binding to the IronCalc spreadsheet engine.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,7 +29,19 @@
29
29
  ],
30
30
  "sideEffects": false,
31
31
  "engines": {
32
- "node": ">=18.0.0"
32
+ "node": ">=20.19.0"
33
+ },
34
+ "packageManager": "pnpm@10.33.1",
35
+ "scripts": {
36
+ "build": "tsdown --config tsdown.config.ts",
37
+ "build:wasm": "cd rust && cargo build --release && cp target/wasm32-wasip1/release/xlsx.wasm ../xlsx.wasm",
38
+ "format": "prettier --check .",
39
+ "format:write": "prettier --write .",
40
+ "lint": "eslint .",
41
+ "notices": "cd rust && cargo about generate --fail about.hbs --output-file ../THIRD-PARTY-NOTICES.md",
42
+ "prepublishOnly": "pnpm run build:wasm && pnpm run notices && pnpm run tc && pnpm run lint && pnpm run test --run && pnpm run build",
43
+ "tc": "tsc -p tsconfig.json --pretty --noEmit",
44
+ "test": "vitest"
33
45
  },
34
46
  "dependencies": {
35
47
  "@bjorn3/browser_wasi_shim": "^0.4.2",
@@ -59,15 +71,5 @@
59
71
  "require": "./dist/index.cjs"
60
72
  },
61
73
  "./package.json": "./package.json"
62
- },
63
- "scripts": {
64
- "build": "tsdown --config tsdown.config.ts",
65
- "build:wasm": "cd rust && cargo build --release && cp target/wasm32-wasip1/release/xlsx.wasm ../xlsx.wasm",
66
- "format": "prettier --check .",
67
- "format:write": "prettier --write .",
68
- "lint": "eslint .",
69
- "notices": "cd rust && cargo about generate --fail about.hbs --output-file ../THIRD-PARTY-NOTICES.md",
70
- "tc": "tsc -p tsconfig.json --pretty --noEmit",
71
- "test": "vitest"
72
74
  }
73
- }
75
+ }
package/xlsx.wasm CHANGED
Binary file