@silurus/ooxml 0.75.5 → 0.76.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.
Files changed (52) hide show
  1. package/README.md +66 -28
  2. package/dist/bounded-raw-part-cache-C6ro6Ezf.js +254 -0
  3. package/dist/{find-cursor-Dc5iM6s7.js → canvas-viewer-mechanics-CwVSOYke.js} +192 -64
  4. package/dist/{document-pull-client-BcNYhoAG.js → document-pull-client-DQNen8c4.js} +3620 -3597
  5. package/dist/docx-DYRguRRi.js +1301 -0
  6. package/dist/docx.mjs +4 -6
  7. package/dist/docx_parser_bg.wasm +0 -0
  8. package/dist/index.mjs +3 -3
  9. package/dist/{line-distribute-B8sqT8kC.js → line-distribute-C1r2zvji.js} +141 -141
  10. package/dist/{line-metrics-D9gqQWHl.js → line-metrics-BdCACYlq.js} +4026 -1170
  11. package/dist/math.mjs +1 -1
  12. package/dist/node.mjs +779 -465
  13. package/dist/pptx-B-EJp83T.js +1735 -0
  14. package/dist/pptx.mjs +5 -7
  15. package/dist/pptx_parser_bg.wasm +0 -0
  16. package/dist/{render-CalC7GX4.js → render-CLcpSi0m.js} +11 -18
  17. package/dist/render-worker-host-Bkf1jUcW.js +27 -0
  18. package/dist/render-worker-host-CKOmXdyr.js +27 -0
  19. package/dist/render-worker-host-DWLyqwI3.js +27 -0
  20. package/dist/resource-measurement-E_S_iau4.js +119 -0
  21. package/dist/session-B4Y54cbT.js +730 -0
  22. package/dist/{renderer-B9R6F_QY.js → slide-pull-client-WCuYCjio.js} +973 -820
  23. package/dist/types/docx.d.ts +1181 -3994
  24. package/dist/types/index.d.ts +2733 -8171
  25. package/dist/types/math.d.ts +8 -33
  26. package/dist/types/node.d.ts +1852 -4433
  27. package/dist/types/pptx.d.ts +1030 -3678
  28. package/dist/types/xlsx.d.ts +1291 -3262
  29. package/dist/worksheet-pull-client-YzjJMOns.js +455 -0
  30. package/dist/xlsx-BBmmZNQn.js +6362 -0
  31. package/dist/xlsx.mjs +5 -7
  32. package/dist/xlsx_parser_bg.wasm +0 -0
  33. package/package.json +14 -7
  34. package/dist/bounded-raw-part-cache-BTfZD_Sz.js +0 -1248
  35. package/dist/docx-DjF8FgoP.js +0 -1274
  36. package/dist/duotone-bitmap-by-path-CWsSJkJu.js +0 -28
  37. package/dist/hyperlink-D85FexTa.js +0 -27
  38. package/dist/pptx-C17xP8AV.js +0 -1705
  39. package/dist/pptx-Dl8tOSmP.js +0 -822
  40. package/dist/preload-BEouWnlI.js +0 -132
  41. package/dist/render-worker-host-BG3a7brz.js +0 -27
  42. package/dist/render-worker-host-CsB-dPJv.js +0 -27
  43. package/dist/render-worker-host-Cyv5Hkbh.js +0 -27
  44. package/dist/resource-measurement-6aReN3K0.js +0 -93
  45. package/dist/slide-pull-client-D_T0AIoX.js +0 -175
  46. package/dist/svg-image-by-path-C1M3N2pT.js +0 -1623
  47. package/dist/worksheet-pull-worker-DCei8u-4.js +0 -347
  48. package/dist/xlsx-BaH9irS0.js +0 -5515
  49. /package/dist/{highlight-rect-cCvVU-MW.js → highlight-rect-CAkCWJ37.js} +0 -0
  50. /package/dist/{mathjax-Dqo857oC.js → mathjax-CMjda8Ip.js} +0 -0
  51. /package/dist/{transfer-3QEJrsJa.js → transfer-DCu4c2BL.js} +0 -0
  52. /package/dist/{visible-index-CKvgpUrf.js → visible-index-CgyJLAS_.js} +0 -0
package/dist/node.mjs CHANGED
@@ -1,14 +1,245 @@
1
1
  import { t as e } from "./chunk-DmhlhrBa.js";
2
- import { D as t, N as n, O as r, T as i, a, c as o, f as s, i as c, k as l, m as u, o as d, p as f, r as p, u as m } from "./bounded-raw-part-cache-BTfZD_Sz.js";
3
- import { c as h, n as ee, o as g, r as te, s as ne } from "./document-pull-client-BcNYhoAG.js";
4
- import { f as re, i as _, p as ie, t as ae } from "./svg-image-by-path-C1M3N2pT.js";
5
- import { t as oe } from "./transfer-3QEJrsJa.js";
6
- import { d as se, n as ce, t as le, u as ue } from "./worksheet-pull-worker-DCei8u-4.js";
7
- import { c as de, i as fe, n as pe, o as me, r as he, s as ge, t as _e } from "./pptx-Dl8tOSmP.js";
8
- import { i as ve, n as ye, o as be, r as xe, t as Se } from "./render-CalC7GX4.js";
2
+ import { t } from "./slide-pull-client-WCuYCjio.js";
3
+ import { B as n, Et as r, F as i, H as a, I as o, It as s, Lt as c, P as l, R as u, U as d, W as ee, at as f, hn as p, kt as m, ot as h, q as te, rt as g, st as ne } from "./line-metrics-BdCACYlq.js";
4
+ import { t as re } from "./bounded-raw-part-cache-C6ro6Ezf.js";
5
+ import { a as ie, c as ae, i as oe, l as se, r as ce, u as le } from "./document-pull-client-DQNen8c4.js";
6
+ import { t as ue } from "./transfer-DCu4c2BL.js";
7
+ import { a as de, c as fe, d as pe, l as me, o as he, r as ge, s as _e, t as ve, u as ye } from "./worksheet-pull-client-YzjJMOns.js";
8
+ import { a as be, i as xe, n as Se, r as Ce } from "./session-B4Y54cbT.js";
9
+ import { a as we, n as Te, r as Ee, t as De } from "./render-CLcpSi0m.js";
10
+ import { existsSync as Oe, readFileSync as ke } from "node:fs";
11
+ import { fileURLToPath as Ae } from "node:url";
12
+ import { basename as je, dirname as Me, resolve as Ne } from "node:path";
13
+ import { createRequire as Pe } from "node:module";
14
+ //#region packages/core/src/internal/owned-session.ts
15
+ async function _(e, t) {
16
+ let n = await e(), r;
17
+ try {
18
+ return await t(n);
19
+ } catch (e) {
20
+ throw r = e, e;
21
+ } finally {
22
+ try {
23
+ await n.close();
24
+ } catch (e) {
25
+ if (r === void 0) throw e;
26
+ }
27
+ }
28
+ }
29
+ //#endregion
30
+ //#region packages/core/src/internal/in-process-pull-transport.ts
31
+ var v = class {
32
+ nextRequestId = 1;
33
+ terminated = !1;
34
+ constructor(e, t) {
35
+ this.dispatch = e, this.terminateHost = t;
36
+ }
37
+ async request(e, t, n) {
38
+ if (this.terminated) throw Error("pull transport terminated");
39
+ if (n?.signal?.aborted) {
40
+ n.onCancel?.(this.nextRequestId, "abort");
41
+ let e = /* @__PURE__ */ Error("worker request aborted");
42
+ throw e.name = "AbortError", e;
43
+ }
44
+ let r = e(this.nextRequestId++), i;
45
+ if (await this.dispatch(r, (e) => {
46
+ i = e;
47
+ }), i === void 0) throw Error("in-process pull host did not respond");
48
+ return i;
49
+ }
50
+ forgetOrphaned(e) {}
51
+ terminate() {
52
+ this.terminated || (this.terminated = !0, this.terminateHost());
53
+ }
54
+ };
55
+ //#endregion
56
+ //#region packages/node/src/wasm-loader.ts
57
+ function Fe(e) {
58
+ return new WebAssembly.Module(ke(e));
59
+ }
60
+ function y(e, t = Fe) {
61
+ let n = {};
62
+ return () => n.value ??= t(e());
63
+ }
64
+ function Ie(e, t, n) {
65
+ let r = Me(Ae(e)), i = Ne(r, t);
66
+ if (Oe(i)) return i;
67
+ let a = Ne(r, je(t));
68
+ return Oe(a) || !n ? a : Pe(e).resolve(n);
69
+ }
70
+ //#endregion
71
+ //#region packages/node/src/pptx.ts
72
+ var Le = y(() => Ie(import.meta.url, "pptx_parser_bg.wasm", "@silurus/ooxml-pptx/wasm-binary"));
73
+ async function Re(e, t = {}) {
74
+ return ze(e, t);
75
+ }
76
+ async function ze(e, t = {}) {
77
+ let n = await Se(He(e), Le(), t);
78
+ return new Be(n.closeArchive, n.archive, n.bootstrap, n.metrics, t.signal);
79
+ }
80
+ var Be = class {
81
+ slideCount;
82
+ slideWidth;
83
+ slideHeight;
84
+ slidePull;
85
+ slideClient;
86
+ transport;
87
+ started = !1;
88
+ closed = !1;
89
+ closePromise;
90
+ usage;
91
+ consumedSlides = 0;
92
+ resourceFailure;
93
+ renderTail = Promise.resolve();
94
+ fetchImage = (e, t) => this.getPartInternal(e, t, (t) => t.extract_image(e));
95
+ fetchMedia = (e) => this.getPartInternal(e, "application/octet-stream", (t) => t.extract_media(e));
96
+ rawParts = new re({
97
+ maxEntries: 64,
98
+ maxBytes: te
99
+ });
100
+ constructor(e, n, r, i, a) {
101
+ this.closeArchive = e, this.archive = n, this.bootstrap = r, this.metrics = i, this.signal = a, this.slideCount = r.slideCount, this.slideWidth = r.slideWidth, this.slideHeight = r.slideHeight, this.slidePull = new xe(() => this.archive), this.transport = new v((e, t) => this.slidePull.dispatchSafely(e, t), () => void 0), this.slideClient = new t({
102
+ slideCount: this.slideCount,
103
+ transport: this.transport,
104
+ open: async (e, t) => {
105
+ this.slidePull.reserveOpen(t), await this.slidePull.open(e, t);
106
+ },
107
+ onUsage: (e) => {
108
+ this.usage = e, this.metrics.observeUsage(e);
109
+ }
110
+ });
111
+ }
112
+ materialize(e) {
113
+ return {
114
+ slideWidth: this.slideWidth,
115
+ slideHeight: this.slideHeight,
116
+ slides: e,
117
+ defaultTextColor: this.bootstrap.defaultTextColor,
118
+ majorFont: this.bootstrap.majorFont,
119
+ minorFont: this.bootstrap.minorFont,
120
+ ...this.bootstrap.hlinkColor ? { hlinkColor: this.bootstrap.hlinkColor } : {},
121
+ ...this.bootstrap.folHlinkColor ? { folHlinkColor: this.bootstrap.folHlinkColor } : {}
122
+ };
123
+ }
124
+ get resourceUsage() {
125
+ return this.closed ? this.usage : this.refreshResourceUsage();
126
+ }
127
+ async getImage(e, t) {
128
+ return this.assertOpen(), this.getPartInternal(e, t, (t) => t.extract_image(e)).catch((e) => this.failOperation(e));
129
+ }
130
+ async getMedia(e, t = "application/octet-stream") {
131
+ return this.assertOpen(), this.getPartInternal(e, t, (t) => t.extract_media(e)).catch((e) => this.failOperation(e));
132
+ }
133
+ async renderSlide(e, t, n) {
134
+ return this.assertOpen(), this.enqueueRender(async () => {
135
+ b(this.signal);
136
+ let { renderSlideNode: r } = await import("./render-CLcpSi0m.js").then((e) => e.i);
137
+ await r(e, {
138
+ slideWidth: this.slideWidth,
139
+ slideHeight: this.slideHeight,
140
+ slides: [t],
141
+ defaultTextColor: this.bootstrap.defaultTextColor,
142
+ majorFont: this.bootstrap.majorFont,
143
+ minorFont: this.bootstrap.minorFont,
144
+ ...this.bootstrap.hlinkColor ? { hlinkColor: this.bootstrap.hlinkColor } : {},
145
+ ...this.bootstrap.folHlinkColor ? { folHlinkColor: this.bootstrap.folHlinkColor } : {}
146
+ }, 0, {
147
+ ...n,
148
+ fetchImage: this.fetchImage,
149
+ fetchMedia: this.fetchMedia
150
+ }), b(this.signal);
151
+ }).catch((e) => this.failOperation(e));
152
+ }
153
+ [Symbol.asyncIterator]() {
154
+ return this.slides();
155
+ }
156
+ async *slides() {
157
+ if (this.closed) throw Error("PPTX presentation session is closed");
158
+ if (this.started) throw Error("PPTX presentation session is one-pass and was already consumed");
159
+ this.started = !0;
160
+ let e;
161
+ try {
162
+ for (let e = 0; e < this.slideCount; e += 1) {
163
+ b(this.signal);
164
+ let t = await this.slideClient.load(e);
165
+ if (!t) throw Error(`PPTX slide ${e} was not decoded`);
166
+ this.usage ??= await this.slidePull.run(() => be((e) => e(this.archive))), this.metrics.observeUsage(this.usage), this.consumedSlides = e + 1, yield t;
167
+ }
168
+ } catch (t) {
169
+ throw e = f(t) ?? t, this.metrics.fail(e), e;
170
+ } finally {
171
+ try {
172
+ await this.close();
173
+ } catch (t) {
174
+ if (e === void 0) throw t;
175
+ }
176
+ }
177
+ }
178
+ close() {
179
+ return this.closePromise ? this.closePromise : (this.closed = !0, this.slideClient.cancelAll(), this.closePromise = this.release(), this.closePromise);
180
+ }
181
+ async release() {
182
+ let e;
183
+ await this.renderTail, m(this.fetchImage), r(this.fetchImage);
184
+ try {
185
+ await this.slidePull.reset();
186
+ } catch (t) {
187
+ e = f(t) ?? t;
188
+ }
189
+ this.transport.terminate(), this.rawParts.clear();
190
+ try {
191
+ this.closeArchive();
192
+ } catch (t) {
193
+ e ??= f(t) ?? t;
194
+ }
195
+ if (e !== void 0) throw this.metrics.fail(e), e;
196
+ this.metrics.checkpoint("presentation session closed"), this.metrics.succeed({ slides: this.consumedSlides });
197
+ }
198
+ enqueueRender(e) {
199
+ let t = this.renderTail.then(e, e);
200
+ return this.renderTail = t.then(() => void 0, () => void 0), t;
201
+ }
202
+ getPartInternal(e, t, n) {
203
+ return this.rawParts.get(e, t, () => {
204
+ b(this.signal);
205
+ let e = n(this.archive);
206
+ return this.refreshResourceUsage(), new Blob([e], { type: t });
207
+ });
208
+ }
209
+ refreshResourceUsage() {
210
+ try {
211
+ this.usage = g(this.archive.resource_usage()), this.metrics.observeUsage(this.usage);
212
+ } catch {}
213
+ return this.usage;
214
+ }
215
+ assertOpen() {
216
+ if (this.closed) throw Error("PPTX presentation session is closed");
217
+ if (this.resourceFailure) throw this.resourceFailure;
218
+ }
219
+ failOperation(e) {
220
+ let t = f(e) ?? e;
221
+ throw t instanceof p && (this.resourceFailure ??= t), this.metrics.fail(t), t;
222
+ }
223
+ };
224
+ async function Ve(e, t = {}) {
225
+ return _(() => ze(e, t), async (e) => {
226
+ let t = [];
227
+ for await (let n of e.slides()) t.push(n);
228
+ return e.materialize(t);
229
+ });
230
+ }
231
+ function He(e) {
232
+ return e instanceof Uint8Array ? e : new Uint8Array(e);
233
+ }
234
+ function b(e) {
235
+ if (!e?.aborted) return;
236
+ let t = /* @__PURE__ */ Error("PPTX presentation session was aborted");
237
+ throw t.name = "AbortError", t;
238
+ }
239
+ //#endregion
9
240
  //#region packages/docx/src/document-pull-worker.ts
10
- var Ce = Math.max(f, u), we = class {
11
- coordinator = new d();
241
+ var Ue = Math.max(d, ee), We = class {
242
+ coordinator = new o();
12
243
  host = null;
13
244
  identity = null;
14
245
  constructor(e, t = (e) => e(this.requireArchive())) {
@@ -20,9 +251,9 @@ var Ce = Math.max(f, u), we = class {
20
251
  t.open_document_cursor(e.operationId, e.generation);
21
252
  });
22
253
  let t = 0;
23
- this.identity = e, this.host = new a({
254
+ this.identity = e, this.host = new i({
24
255
  ...e,
25
- maxByteCredit: Ce,
256
+ maxByteCredit: Ue,
26
257
  coordinator: this.coordinator,
27
258
  driver: {
28
259
  pull: (n) => {
@@ -30,9 +261,9 @@ var Ce = Math.max(f, u), we = class {
30
261
  try {
31
262
  r = this.executeArchive((r) => r.pull_document_chunk(t, e.operationId, e.generation, n));
32
263
  } catch (e) {
33
- throw l(e, n, Ce) || e;
264
+ throw ne(e, n, Ue) || e;
34
265
  }
35
- let i = oe(r);
266
+ let i = ue(r);
36
267
  return {
37
268
  payload: i,
38
269
  byteLength: i.byteLength,
@@ -49,27 +280,27 @@ var Ce = Math.max(f, u), we = class {
49
280
  close: () => this.executeArchive((e) => e.close_document_session()),
50
281
  resourceUsage: () => {
51
282
  let e = this.executeArchive((e) => e.document_cursor_resource_usage?.());
52
- return e ? i(e) : void 0;
283
+ return e ? g(e) : void 0;
53
284
  }
54
285
  }
55
286
  });
56
287
  }
57
288
  dispatch(e, t) {
58
289
  return !this.host || !this.identity ? (t({
59
- protocol: c,
290
+ protocol: l,
60
291
  kind: "error",
61
292
  sessionId: e.sessionId,
62
293
  operationId: e.operationId,
63
294
  generation: e.generation,
64
295
  requestId: e.requestId,
65
- error: r(/* @__PURE__ */ Error("DOCX document pull session is not open"))
296
+ error: h(/* @__PURE__ */ Error("DOCX document pull session is not open"))
66
297
  }), Promise.resolve()) : this.host.dispatch(e, t);
67
298
  }
68
299
  async reset() {
69
300
  if (this.host) try {
70
301
  this.archive() && this.executeArchive((e) => e.close_document_session());
71
302
  } finally {
72
- this.host = null, this.identity = null, this.coordinator = new d();
303
+ this.host = null, this.identity = null, this.coordinator = new o();
73
304
  }
74
305
  }
75
306
  requireArchive() {
@@ -77,181 +308,181 @@ var Ce = Math.max(f, u), we = class {
77
308
  if (!e) throw Error("No docx loaded");
78
309
  return e;
79
310
  }
80
- }, Te = /* @__PURE__ */ e({
81
- DocxArchive: () => v,
82
- default: () => Le,
83
- docx_to_markdown: () => Ee,
84
- extract_image: () => De,
85
- initSync: () => Ie,
86
- parse_docx: () => Oe,
87
- reinit: () => Re
88
- }), v = class {
311
+ }, Ge = /* @__PURE__ */ e({
312
+ DocxArchive: () => x,
313
+ default: () => rt,
314
+ docx_to_markdown: () => Ke,
315
+ extract_image: () => qe,
316
+ initSync: () => nt,
317
+ parse_docx: () => Je,
318
+ reinit: () => it
319
+ }), x = class {
89
320
  __destroy_into_raw() {
90
321
  let e = this.__wbg_ptr;
91
- return this.__wbg_ptr = 0, Ae.unregister(this), e;
322
+ return this.__wbg_ptr = 0, Xe.unregister(this), e;
92
323
  }
93
324
  free() {
94
325
  let e = this.__destroy_into_raw();
95
- M.__wbg_docxarchive_free(e, 0);
326
+ F.__wbg_docxarchive_free(e, 0);
96
327
  }
97
328
  acknowledge_document_chunk(e, t, n) {
98
- let r = M.docxarchive_acknowledge_document_chunk(this.__wbg_ptr, e, t, n);
99
- if (r[1]) throw D(r[0]);
329
+ let r = F.docxarchive_acknowledge_document_chunk(this.__wbg_ptr, e, t, n);
330
+ if (r[1]) throw A(r[0]);
100
331
  }
101
332
  assert_healthy() {
102
- let e = M.docxarchive_assert_healthy(this.__wbg_ptr);
103
- if (e[1]) throw D(e[0]);
333
+ let e = F.docxarchive_assert_healthy(this.__wbg_ptr);
334
+ if (e[1]) throw A(e[0]);
104
335
  }
105
336
  cancel_document_cursor() {
106
- M.docxarchive_cancel_document_cursor(this.__wbg_ptr);
337
+ F.docxarchive_cancel_document_cursor(this.__wbg_ptr);
107
338
  }
108
339
  close_document_session() {
109
- M.docxarchive_close_document_session(this.__wbg_ptr);
340
+ F.docxarchive_close_document_session(this.__wbg_ptr);
110
341
  }
111
342
  document_chunk_done() {
112
- let e = M.docxarchive_document_chunk_done(this.__wbg_ptr);
113
- if (e[2]) throw D(e[1]);
343
+ let e = F.docxarchive_document_chunk_done(this.__wbg_ptr);
344
+ if (e[2]) throw A(e[1]);
114
345
  return e[0] !== 0;
115
346
  }
116
347
  document_cursor_resource_usage() {
117
- let e = M.docxarchive_document_cursor_resource_usage(this.__wbg_ptr);
118
- if (e[3]) throw D(e[2]);
119
- var t = y(e[0], e[1]).slice();
120
- return M.__wbindgen_free(e[0], e[1] * 1, 1), t;
348
+ let e = F.docxarchive_document_cursor_resource_usage(this.__wbg_ptr);
349
+ if (e[3]) throw A(e[2]);
350
+ var t = S(e[0], e[1]).slice();
351
+ return F.__wbindgen_free(e[0], e[1] * 1, 1), t;
121
352
  }
122
353
  extract_image(e) {
123
- let t = E(e, M.__wbindgen_malloc, M.__wbindgen_realloc), n = j, r = M.docxarchive_extract_image(this.__wbg_ptr, t, n);
124
- if (r[3]) throw D(r[2]);
125
- var i = y(r[0], r[1]).slice();
126
- return M.__wbindgen_free(r[0], r[1] * 1, 1), i;
354
+ let t = k(e, F.__wbindgen_malloc, F.__wbindgen_realloc), n = P, r = F.docxarchive_extract_image(this.__wbg_ptr, t, n);
355
+ if (r[3]) throw A(r[2]);
356
+ var i = S(r[0], r[1]).slice();
357
+ return F.__wbindgen_free(r[0], r[1] * 1, 1), i;
127
358
  }
128
- constructor(e, t, n) {
129
- let r = T(e, M.__wbindgen_malloc), i = j, a = M.docxarchive_new(r, i, !w(t), w(t) ? BigInt(0) : t, !w(n), w(n) ? BigInt(0) : n);
130
- if (a[2]) throw D(a[1]);
131
- return this.__wbg_ptr = a[0] >>> 0, Ae.register(this, this.__wbg_ptr, this), this;
359
+ constructor(e, t, n, r) {
360
+ let i = O(e, F.__wbindgen_malloc), a = P, o = F.docxarchive_new(i, a, !D(t), D(t) ? BigInt(0) : t, !D(n), D(n) ? BigInt(0) : n, !D(r), D(r) ? BigInt(0) : r);
361
+ if (o[2]) throw A(o[1]);
362
+ return this.__wbg_ptr = o[0] >>> 0, Xe.register(this, this.__wbg_ptr, this), this;
132
363
  }
133
364
  open_document_cursor(e, t) {
134
- let n = M.docxarchive_open_document_cursor(this.__wbg_ptr, e, t);
135
- if (n[1]) throw D(n[0]);
365
+ let n = F.docxarchive_open_document_cursor(this.__wbg_ptr, e, t);
366
+ if (n[1]) throw A(n[0]);
136
367
  }
137
368
  parse() {
138
- let e = M.docxarchive_parse(this.__wbg_ptr);
139
- if (e[3]) throw D(e[2]);
140
- var t = y(e[0], e[1]).slice();
141
- return M.__wbindgen_free(e[0], e[1] * 1, 1), t;
369
+ let e = F.docxarchive_parse(this.__wbg_ptr);
370
+ if (e[3]) throw A(e[2]);
371
+ var t = S(e[0], e[1]).slice();
372
+ return F.__wbindgen_free(e[0], e[1] * 1, 1), t;
142
373
  }
143
374
  pull_document_chunk(e, t, n, r) {
144
- let i = M.docxarchive_pull_document_chunk(this.__wbg_ptr, e, t, n, r);
145
- if (i[3]) throw D(i[2]);
146
- var a = y(i[0], i[1]).slice();
147
- return M.__wbindgen_free(i[0], i[1] * 1, 1), a;
375
+ let i = F.docxarchive_pull_document_chunk(this.__wbg_ptr, e, t, n, r);
376
+ if (i[3]) throw A(i[2]);
377
+ var a = S(i[0], i[1]).slice();
378
+ return F.__wbindgen_free(i[0], i[1] * 1, 1), a;
148
379
  }
149
380
  resource_usage() {
150
- let e = M.docxarchive_resource_usage(this.__wbg_ptr);
151
- if (e[3]) throw D(e[2]);
152
- var t = y(e[0], e[1]).slice();
153
- return M.__wbindgen_free(e[0], e[1] * 1, 1), t;
381
+ let e = F.docxarchive_resource_usage(this.__wbg_ptr);
382
+ if (e[3]) throw A(e[2]);
383
+ var t = S(e[0], e[1]).slice();
384
+ return F.__wbindgen_free(e[0], e[1] * 1, 1), t;
154
385
  }
155
386
  to_markdown() {
156
387
  let e, t;
157
388
  try {
158
- let i = M.docxarchive_to_markdown(this.__wbg_ptr);
389
+ let i = F.docxarchive_to_markdown(this.__wbg_ptr);
159
390
  var n = i[0], r = i[1];
160
- if (i[3]) throw n = 0, r = 0, D(i[2]);
161
- return e = n, t = r, x(n, r);
391
+ if (i[3]) throw n = 0, r = 0, A(i[2]);
392
+ return e = n, t = r, w(n, r);
162
393
  } finally {
163
- M.__wbindgen_free(e, t, 1);
394
+ F.__wbindgen_free(e, t, 1);
164
395
  }
165
396
  }
166
397
  };
167
- Symbol.dispose && (v.prototype[Symbol.dispose] = v.prototype.free);
168
- function Ee(e, t, n) {
398
+ Symbol.dispose && (x.prototype[Symbol.dispose] = x.prototype.free);
399
+ function Ke(e, t, n) {
169
400
  let r, i;
170
401
  try {
171
- let s = T(e, M.__wbindgen_malloc), c = j, l = M.docx_to_markdown(s, c, !w(t), w(t) ? BigInt(0) : t, !w(n), w(n) ? BigInt(0) : n);
402
+ let s = O(e, F.__wbindgen_malloc), c = P, l = F.docx_to_markdown(s, c, !D(t), D(t) ? BigInt(0) : t, !D(n), D(n) ? BigInt(0) : n);
172
403
  var a = l[0], o = l[1];
173
- if (l[3]) throw a = 0, o = 0, D(l[2]);
174
- return r = a, i = o, x(a, o);
404
+ if (l[3]) throw a = 0, o = 0, A(l[2]);
405
+ return r = a, i = o, w(a, o);
175
406
  } finally {
176
- M.__wbindgen_free(r, i, 1);
407
+ F.__wbindgen_free(r, i, 1);
177
408
  }
178
409
  }
179
- function De(e, t, n, r) {
180
- let i = T(e, M.__wbindgen_malloc), a = j, o = E(t, M.__wbindgen_malloc, M.__wbindgen_realloc), s = j, c = M.extract_image(i, a, o, s, !w(n), w(n) ? BigInt(0) : n, !w(r), w(r) ? BigInt(0) : r);
181
- if (c[3]) throw D(c[2]);
182
- var l = y(c[0], c[1]).slice();
183
- return M.__wbindgen_free(c[0], c[1] * 1, 1), l;
410
+ function qe(e, t, n, r) {
411
+ let i = O(e, F.__wbindgen_malloc), a = P, o = k(t, F.__wbindgen_malloc, F.__wbindgen_realloc), s = P, c = F.extract_image(i, a, o, s, !D(n), D(n) ? BigInt(0) : n, !D(r), D(r) ? BigInt(0) : r);
412
+ if (c[3]) throw A(c[2]);
413
+ var l = S(c[0], c[1]).slice();
414
+ return F.__wbindgen_free(c[0], c[1] * 1, 1), l;
184
415
  }
185
- function Oe(e, t, n) {
186
- let r = T(e, M.__wbindgen_malloc), i = j, a = M.parse_docx(r, i, !w(t), w(t) ? BigInt(0) : t, !w(n), w(n) ? BigInt(0) : n);
187
- if (a[3]) throw D(a[2]);
188
- var o = y(a[0], a[1]).slice();
189
- return M.__wbindgen_free(a[0], a[1] * 1, 1), o;
416
+ function Je(e, t, n) {
417
+ let r = O(e, F.__wbindgen_malloc), i = P, a = F.parse_docx(r, i, !D(t), D(t) ? BigInt(0) : t, !D(n), D(n) ? BigInt(0) : n);
418
+ if (a[3]) throw A(a[2]);
419
+ var o = S(a[0], a[1]).slice();
420
+ return F.__wbindgen_free(a[0], a[1] * 1, 1), o;
190
421
  }
191
- function ke() {
422
+ function Ye() {
192
423
  return {
193
424
  __proto__: null,
194
425
  "./docx_parser_bg.js": {
195
426
  __proto__: null,
196
427
  __wbg___wbindgen_throw_6b64449b9b9ed33c: function(e, t) {
197
- throw Error(x(e, t));
428
+ throw Error(w(e, t));
198
429
  },
199
430
  __wbg_error_a6fa202b58aa1cd3: function(e, t) {
200
431
  let n, r;
201
432
  try {
202
- n = e, r = t, console.error(x(e, t));
433
+ n = e, r = t, console.error(w(e, t));
203
434
  } finally {
204
- M.__wbindgen_free(n, r, 1);
435
+ F.__wbindgen_free(n, r, 1);
205
436
  }
206
437
  },
207
438
  __wbg_new_227d7c05414eb861: function() {
208
439
  return /* @__PURE__ */ Error();
209
440
  },
210
441
  __wbg_stack_3b0d974bbf31e44f: function(e, t) {
211
- let n = t.stack, r = E(n, M.__wbindgen_malloc, M.__wbindgen_realloc), i = j;
212
- je().setInt32(e + 4, i, !0), je().setInt32(e + 0, r, !0);
442
+ let n = t.stack, r = k(n, F.__wbindgen_malloc, F.__wbindgen_realloc), i = P;
443
+ Ze().setInt32(e + 4, i, !0), Ze().setInt32(e + 0, r, !0);
213
444
  },
214
445
  __wbindgen_cast_0000000000000001: function(e, t) {
215
- return x(e, t);
446
+ return w(e, t);
216
447
  },
217
448
  __wbindgen_init_externref_table: function() {
218
- let e = M.__wbindgen_externrefs, t = e.grow(4);
449
+ let e = F.__wbindgen_externrefs, t = e.grow(4);
219
450
  e.set(0, void 0), e.set(t + 0, void 0), e.set(t + 1, null), e.set(t + 2, !0), e.set(t + 3, !1);
220
451
  }
221
452
  }
222
453
  };
223
454
  }
224
- var Ae = typeof FinalizationRegistry > "u" ? {
455
+ var Xe = typeof FinalizationRegistry > "u" ? {
225
456
  register: () => {},
226
457
  unregister: () => {}
227
- } : new FinalizationRegistry((e) => M.__wbg_docxarchive_free(e >>> 0, 1));
228
- function y(e, t) {
229
- return e >>>= 0, C().subarray(e / 1, e / 1 + t);
458
+ } : new FinalizationRegistry((e) => F.__wbg_docxarchive_free(e >>> 0, 1));
459
+ function S(e, t) {
460
+ return e >>>= 0, E().subarray(e / 1, e / 1 + t);
230
461
  }
231
- var b = null;
232
- function je() {
233
- return (b === null || b.buffer.detached === !0 || b.buffer.detached === void 0 && b.buffer !== M.memory.buffer) && (b = new DataView(M.memory.buffer)), b;
462
+ var C = null;
463
+ function Ze() {
464
+ return (C === null || C.buffer.detached === !0 || C.buffer.detached === void 0 && C.buffer !== F.memory.buffer) && (C = new DataView(F.memory.buffer)), C;
234
465
  }
235
- function x(e, t) {
236
- return e >>>= 0, Ne(e, t);
466
+ function w(e, t) {
467
+ return e >>>= 0, $e(e, t);
237
468
  }
238
- var S = null;
239
- function C() {
240
- return (S === null || S.byteLength === 0) && (S = new Uint8Array(M.memory.buffer)), S;
469
+ var T = null;
470
+ function E() {
471
+ return (T === null || T.byteLength === 0) && (T = new Uint8Array(F.memory.buffer)), T;
241
472
  }
242
- function w(e) {
473
+ function D(e) {
243
474
  return e == null;
244
475
  }
245
- function T(e, t) {
476
+ function O(e, t) {
246
477
  let n = t(e.length * 1, 1) >>> 0;
247
- return C().set(e, n / 1), j = e.length, n;
478
+ return E().set(e, n / 1), P = e.length, n;
248
479
  }
249
- function E(e, t, n) {
480
+ function k(e, t, n) {
250
481
  if (n === void 0) {
251
- let n = A.encode(e), r = t(n.length, 1) >>> 0;
252
- return C().subarray(r, r + n.length).set(n), j = n.length, r;
482
+ let n = N.encode(e), r = t(n.length, 1) >>> 0;
483
+ return E().subarray(r, r + n.length).set(n), P = n.length, r;
253
484
  }
254
- let r = e.length, i = t(r, 1) >>> 0, a = C(), o = 0;
485
+ let r = e.length, i = t(r, 1) >>> 0, a = E(), o = 0;
255
486
  for (; o < r; o++) {
256
487
  let t = e.charCodeAt(o);
257
488
  if (t > 127) break;
@@ -259,40 +490,40 @@ function E(e, t, n) {
259
490
  }
260
491
  if (o !== r) {
261
492
  o !== 0 && (e = e.slice(o)), i = n(i, r, r = o + e.length * 3, 1) >>> 0;
262
- let t = C().subarray(i + o, i + r), a = A.encodeInto(e, t);
493
+ let t = E().subarray(i + o, i + r), a = N.encodeInto(e, t);
263
494
  o += a.written, i = n(i, r, o, 1) >>> 0;
264
495
  }
265
- return j = o, i;
496
+ return P = o, i;
266
497
  }
267
- function D(e) {
268
- let t = M.__wbindgen_externrefs.get(e);
269
- return M.__externref_table_dealloc(e), t;
498
+ function A(e) {
499
+ let t = F.__wbindgen_externrefs.get(e);
500
+ return F.__externref_table_dealloc(e), t;
270
501
  }
271
- var O = new TextDecoder("utf-8", {
502
+ var j = new TextDecoder("utf-8", {
272
503
  ignoreBOM: !0,
273
504
  fatal: !0
274
505
  });
275
- O.decode();
276
- var Me = 2146435072, k = 0;
277
- function Ne(e, t) {
278
- return k += t, k >= Me && (O = new TextDecoder("utf-8", {
506
+ j.decode();
507
+ var Qe = 2146435072, M = 0;
508
+ function $e(e, t) {
509
+ return M += t, M >= Qe && (j = new TextDecoder("utf-8", {
279
510
  ignoreBOM: !0,
280
511
  fatal: !0
281
- }), O.decode(), k = t), O.decode(C().subarray(e, e + t));
512
+ }), j.decode(), M = t), j.decode(E().subarray(e, e + t));
282
513
  }
283
- var A = new TextEncoder();
284
- "encodeInto" in A || (A.encodeInto = function(e, t) {
285
- let n = A.encode(e);
514
+ var N = new TextEncoder();
515
+ "encodeInto" in N || (N.encodeInto = function(e, t) {
516
+ let n = N.encode(e);
286
517
  return t.set(n), {
287
518
  read: e.length,
288
519
  written: n.length
289
520
  };
290
521
  });
291
- var j = 0, M;
292
- function Pe(e, t) {
293
- return M = e.exports, b = null, S = null, M.__wbindgen_start(), M;
522
+ var P = 0, F;
523
+ function et(e, t) {
524
+ return F = e.exports, C = null, T = null, F.__wbindgen_start(), F;
294
525
  }
295
- async function Fe(e, t) {
526
+ async function tt(e, t) {
296
527
  if (typeof Response == "function" && e instanceof Response) {
297
528
  if (typeof WebAssembly.instantiateStreaming == "function") try {
298
529
  return await WebAssembly.instantiateStreaming(e, t);
@@ -318,76 +549,139 @@ async function Fe(e, t) {
318
549
  return !1;
319
550
  }
320
551
  }
321
- function Ie(e) {
322
- if (M !== void 0) return M;
552
+ function nt(e) {
553
+ if (F !== void 0) return F;
323
554
  e !== void 0 && (Object.getPrototypeOf(e) === Object.prototype ? {module: e} = e : console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));
324
- let t = ke();
325
- return e instanceof WebAssembly.Module || (e = new WebAssembly.Module(e)), Pe(new WebAssembly.Instance(e, t), e);
555
+ let t = Ye();
556
+ return e instanceof WebAssembly.Module || (e = new WebAssembly.Module(e)), et(new WebAssembly.Instance(e, t), e);
326
557
  }
327
- async function Le(e) {
328
- if (M !== void 0) return M;
558
+ async function rt(e) {
559
+ if (F !== void 0) return F;
329
560
  e !== void 0 && (Object.getPrototypeOf(e) === Object.prototype ? {module_or_path: e} = e : console.warn("using deprecated parameters for the initialization function; pass a single object instead"));
330
- let t = ke();
561
+ let t = Ye();
331
562
  (typeof e == "string" || typeof Request == "function" && e instanceof Request || typeof URL == "function" && e instanceof URL) && (e = fetch(e));
332
- let { instance: n, module: r } = await Fe(await e, t);
333
- return Pe(n, r);
563
+ let { instance: n, module: r } = await tt(await e, t);
564
+ return et(n, r);
334
565
  }
335
- async function Re(e) {
336
- return M = void 0, b = null, S = null, Le(e);
566
+ async function it(e) {
567
+ return F = void 0, C = null, T = null, rt(e);
337
568
  }
338
569
  //#endregion
339
- //#region packages/node/src/docx.ts
340
- var ze = !1;
341
- function Be() {
342
- ze ||= (me(Te, ge(import.meta.url, "../../docx/src/wasm/docx_parser_bg.wasm")), !0);
343
- }
344
- function Ve(e) {
345
- Be();
346
- let t = Oe(e instanceof Uint8Array ? e : new Uint8Array(e));
347
- return h(JSON.parse(new TextDecoder().decode(t)));
348
- }
349
- async function He(e, n) {
350
- let r = m(n ?? {}), i = new o({
351
- enabled: r.debug || r.onResourceMetrics !== void 0,
570
+ //#region packages/docx/src/internal/node-acquisition.ts
571
+ var at, I;
572
+ function ot(e) {
573
+ if (!I) at = e, I = new Ce(Ge, e);
574
+ else if (at !== e) throw Error("DOCX runtime was already initialized with another WebAssembly.Module");
575
+ return I;
576
+ }
577
+ async function st(e, t, r, i) {
578
+ let o = n(r), s = new u({
579
+ enabled: o.debug || o.onResourceMetrics !== void 0,
352
580
  format: "docx",
353
581
  mode: "node",
354
582
  scope: "session",
355
- policy: r.policy,
356
- onMetrics: r.onResourceMetrics,
357
- emitToConsole: r.debug
583
+ policy: o.policy,
584
+ onMetrics: o.onResourceMetrics,
585
+ emitToConsole: o.debug
358
586
  });
359
- i.setSourceBytes(Ke(e).byteLength);
360
- let a = v, c, l, u;
587
+ s.setSourceBytes(e.byteLength);
588
+ let c, l, d;
361
589
  try {
362
- if (!n?.factory) throw TypeError("openDocxDocument requires a canvas factory");
363
- N(n.signal), Be();
364
- let [t, o] = s(r.policy);
365
- c = new a(Ke(e), t, o), i.checkpoint("container ready"), l = new we(() => c);
366
- let d = {
590
+ lt(r.signal);
591
+ let [n, u, ee] = a(o.policy), f = x;
592
+ c = await ot(t).open(() => new f(e, n, u, ee), {
593
+ signal: r.signal,
594
+ abortError: ut,
595
+ disposeOnAbort: (e) => e.free()
596
+ }), lt(r.signal);
597
+ let p = c.proxy;
598
+ s.checkpoint("container ready"), l = new We(() => p);
599
+ let m = {
367
600
  sessionId: 1,
368
601
  operationId: 1,
369
602
  generation: 1
370
603
  };
371
- l.open(d), u = new de((e, t) => l?.dispatch(e, t), () => void 0);
372
- let f, p = await ee(u, d, {
373
- signal: n.signal,
604
+ l.open(m), d = new v((e, t) => l?.dispatch(e, t), () => void 0);
605
+ let h, te = await i(d, m, {
606
+ signal: r.signal,
374
607
  onUsage: (e) => {
375
- f = e, i.observeUsage(e);
608
+ h = e, s.observeUsage(e);
376
609
  }
377
610
  });
378
- f ??= Ge(c.document_cursor_resource_usage()), i.observeUsage(f), i.checkpoint("model streamed"), await l.reset(), u.terminate(), N(n.signal);
379
- let m = n.factory.createCanvas(1, 1), h = ne(p.source, { measureContext: m.getContext("2d") }), g = We(n.currentDate), re = te(p.source, h, g).layoutVariants.defaultLayout, _ = new Ue(c, p.source, h, re, n.factory, g, f, i, n.signal);
380
- return i.observeUsage(_.resourceUsage), i.checkpoint("pagination ready"), _;
611
+ return h ??= ct(p.document_cursor_resource_usage()), s.observeUsage(h), s.checkpoint("model streamed"), await l.reset(), d.terminate(), {
612
+ archive: p,
613
+ result: te,
614
+ usage: h,
615
+ metrics: s,
616
+ closeArchive: () => c?.close((e) => e.free())
617
+ };
381
618
  } catch (e) {
382
- await l?.reset().catch(() => void 0), u?.terminate();
619
+ await l?.reset().catch(() => void 0), d?.terminate();
383
620
  try {
384
- c?.free();
621
+ c?.close((e) => e.free());
385
622
  } catch {}
386
- let n = t(e) ?? e;
387
- throw i.fail(n), n;
623
+ let t = f(e) ?? e;
624
+ throw s.fail(t), t;
388
625
  }
389
626
  }
390
- var Ue = class {
627
+ function ct(e) {
628
+ try {
629
+ return g(e);
630
+ } catch {
631
+ return;
632
+ }
633
+ }
634
+ function lt(e) {
635
+ if (e?.aborted) throw ut();
636
+ }
637
+ function ut() {
638
+ let e = /* @__PURE__ */ Error("DOCX document session was aborted");
639
+ return e.name = "AbortError", e;
640
+ }
641
+ //#endregion
642
+ //#region packages/node/src/docx.ts
643
+ var dt = y(() => Ie(import.meta.url, "docx_parser_bg.wasm", "@silurus/ooxml-docx/wasm-binary"));
644
+ async function ft(e, t) {
645
+ if (!t?.factory) throw TypeError("openDocxDocument requires a canvas factory");
646
+ let n = await st(gt(e), dt(), t, (e, t, n) => ce(e, t, n));
647
+ try {
648
+ L(t.signal);
649
+ let e = t.factory.createCanvas(1, 1), r = se(n.result, { measureContext: e.getContext("2d") }), i = ht(t.currentDate), a = ie(n.result, r, i).layoutVariants.defaultLayout, o = new mt(n.closeArchive, n.archive, n.result, r, a, t.factory, i, n.usage, n.metrics, t.signal);
650
+ return n.metrics.observeUsage(o.resourceUsage), n.metrics.checkpoint("pagination ready"), o;
651
+ } catch (e) {
652
+ try {
653
+ n.closeArchive();
654
+ } catch {}
655
+ let t = f(e) ?? e;
656
+ throw n.metrics.fail(t), t;
657
+ }
658
+ }
659
+ async function pt(e, t = {}) {
660
+ return _(async () => {
661
+ let n = await st(gt(e), dt(), t, (e, t, n) => oe(e, t, n)), r = !1;
662
+ return {
663
+ acquired: n,
664
+ markSucceeded: () => {
665
+ r = !0;
666
+ },
667
+ close: async () => {
668
+ try {
669
+ n.closeArchive(), r && n.metrics.succeed({ documents: 1 });
670
+ } catch (e) {
671
+ throw n.metrics.fail(e), e;
672
+ }
673
+ }
674
+ };
675
+ }, async ({ acquired: e, markSucceeded: t }) => {
676
+ try {
677
+ let n = le(e.result);
678
+ return e.metrics.checkpoint("document materialized", e.usage), t(), n;
679
+ } catch (t) {
680
+ throw e.metrics.fail(t), t;
681
+ }
682
+ });
683
+ }
684
+ var mt = class {
391
685
  pageCount;
392
686
  sizes;
393
687
  lastResourceUsage;
@@ -399,13 +693,13 @@ var Ue = class {
399
693
  resourceFailure = null;
400
694
  fetchImage = async (e, t) => {
401
695
  let n = this.archive.extract_image(e);
402
- return new Blob([new Uint8Array(n).slice()], { type: t });
696
+ return new Blob([n], { type: t });
403
697
  };
404
- constructor(e, t, n, r, i, a, o, s, c) {
405
- this.archive = e, this.factory = i, this.defaultCurrentDateMs = a, this.metrics = s, this.signal = c, this.state = {
406
- source: t,
407
- services: n
408
- }, this.pageCount = r.pages.length, this.lastResourceUsage = o, this.sizes = Object.freeze(r.pages.map((e) => Object.freeze({
698
+ constructor(e, t, n, r, i, a, o, s, c, l) {
699
+ this.closeArchive = e, this.archive = t, this.factory = a, this.defaultCurrentDateMs = o, this.metrics = c, this.signal = l, this.state = {
700
+ source: n,
701
+ services: r
702
+ }, this.pageCount = i.pages.length, this.lastResourceUsage = s, this.sizes = Object.freeze(i.pages.map((e) => Object.freeze({
409
703
  widthPt: e.geometry.widthPt,
410
704
  heightPt: e.geometry.heightPt
411
705
  })));
@@ -415,7 +709,7 @@ var Ue = class {
415
709
  }
416
710
  refreshResourceUsage() {
417
711
  try {
418
- this.lastResourceUsage = i(this.archive.resource_usage()), this.metrics.observeUsage(this.lastResourceUsage);
712
+ this.lastResourceUsage = g(this.archive.resource_usage()), this.metrics.observeUsage(this.lastResourceUsage);
419
713
  } catch {}
420
714
  return this.lastResourceUsage;
421
715
  }
@@ -427,27 +721,27 @@ var Ue = class {
427
721
  [Symbol.asyncIterator]() {
428
722
  return this.pages();
429
723
  }
430
- renderPage(e, r = {}) {
724
+ renderPage(e, t = {}) {
431
725
  return this.closed ? Promise.reject(/* @__PURE__ */ Error("DOCX document session is closed")) : this.resourceFailure ? Promise.reject(this.resourceFailure) : (this.pageSize(e), this.enqueueRender(async () => {
432
- N(this.signal);
433
- let t = this.requireState(), n = this.factory.createCanvas(1, 1);
434
- return await be(this.factory, () => g(t.source, n, e, {
435
- ...r,
726
+ L(this.signal);
727
+ let n = this.requireState(), r = this.factory.createCanvas(1, 1);
728
+ return await we(this.factory, () => ae(n.source, r, e, {
729
+ ...t,
436
730
  currentDate: this.defaultCurrentDateMs,
437
731
  defaultCurrentDateMs: this.defaultCurrentDateMs,
438
- layoutServices: t.services,
732
+ layoutServices: n.services,
439
733
  fetchImage: this.fetchImage
440
- })), N(this.signal), n;
734
+ })), L(this.signal), r;
441
735
  }).catch((e) => {
442
- let r = t(e) ?? e;
443
- throw r instanceof n && (this.resourceFailure ??= r), this.metrics.fail(r), r;
736
+ let t = f(e) ?? e;
737
+ throw t instanceof p && (this.resourceFailure ??= t), this.metrics.fail(t), t;
444
738
  }));
445
739
  }
446
740
  async *pages(e = {}) {
447
741
  if (this.closed) throw Error("DOCX document session is closed");
448
742
  if (this.pagesStarted) throw Error("DOCX page stream is one-pass and was already consumed");
449
743
  this.pagesStarted = !0;
450
- let n;
744
+ let t;
451
745
  try {
452
746
  for (let t = 0; t < this.pageCount; t += 1) {
453
747
  let n = await this.renderPage(t, e), r = this.pageSize(t);
@@ -458,12 +752,12 @@ var Ue = class {
458
752
  };
459
753
  }
460
754
  } catch (e) {
461
- throw n = t(e) ?? e, n;
755
+ throw t = f(e) ?? e, t;
462
756
  } finally {
463
757
  try {
464
758
  await this.close();
465
759
  } catch (e) {
466
- if (n === void 0) throw e;
760
+ if (t === void 0) throw e;
467
761
  }
468
762
  }
469
763
  }
@@ -475,12 +769,12 @@ var Ue = class {
475
769
  return this.renderTail = t.then(() => void 0, () => void 0), t;
476
770
  }
477
771
  async release() {
478
- await this.renderTail, _(this.fetchImage), ae(this.fetchImage), this.state = null;
772
+ await this.renderTail, m(this.fetchImage), r(this.fetchImage), this.state = null;
479
773
  try {
480
- this.archive.free();
774
+ this.closeArchive();
481
775
  } catch (e) {
482
- let n = t(e) ?? e;
483
- throw this.metrics.fail(n), n;
776
+ let t = f(e) ?? e;
777
+ throw this.metrics.fail(t), t;
484
778
  }
485
779
  this.metrics.checkpoint("document session closed", this.lastResourceUsage), this.metrics.succeed({ pages: this.pageCount });
486
780
  }
@@ -489,215 +783,194 @@ var Ue = class {
489
783
  return this.state;
490
784
  }
491
785
  };
492
- function We(e) {
786
+ function ht(e) {
493
787
  let t = e instanceof Date ? e.getTime() : e ?? Date.now();
494
788
  if (!Number.isFinite(t)) throw RangeError("currentDate must resolve to finite epoch milliseconds");
495
789
  return t;
496
790
  }
497
- function Ge(e) {
498
- try {
499
- return i(e);
500
- } catch (e) {
501
- if (String(e).includes("document cursor usage is unavailable")) return;
502
- throw e;
503
- }
504
- }
505
- function Ke(e) {
791
+ function gt(e) {
506
792
  return e instanceof Uint8Array ? e : new Uint8Array(e);
507
793
  }
508
- function N(e) {
794
+ function L(e) {
509
795
  if (!e?.aborted) return;
510
796
  let t = /* @__PURE__ */ Error("DOCX document session was aborted");
511
797
  throw t.name = "AbortError", t;
512
798
  }
513
799
  //#endregion
514
800
  //#region packages/xlsx/src/wasm/xlsx_parser.js
515
- var qe = /* @__PURE__ */ e({
516
- XlsxArchive: () => P,
517
- default: () => at,
518
- extract_image: () => Je,
519
- initSync: () => it,
520
- parse_sheet: () => Ye,
521
- parse_xlsx: () => Xe,
522
- reinit: () => ot,
523
- xlsx_to_markdown: () => Ze
524
- }), P = class {
801
+ var _t = /* @__PURE__ */ e({
802
+ XlsxArchive: () => R,
803
+ default: () => kt,
804
+ extract_image: () => vt,
805
+ initSync: () => Ot,
806
+ parse_xlsx: () => yt,
807
+ reinit: () => At,
808
+ xlsx_to_markdown: () => bt
809
+ }), R = class {
525
810
  __destroy_into_raw() {
526
811
  let e = this.__wbg_ptr;
527
- return this.__wbg_ptr = 0, $e.unregister(this), e;
812
+ return this.__wbg_ptr = 0, St.unregister(this), e;
528
813
  }
529
814
  free() {
530
815
  let e = this.__destroy_into_raw();
531
- J.__wbg_xlsxarchive_free(e, 0);
816
+ Q.__wbg_xlsxarchive_free(e, 0);
532
817
  }
533
818
  acknowledge_sheet_cursor_terminal() {
534
- let e = J.xlsxarchive_acknowledge_sheet_cursor_terminal(this.__wbg_ptr);
535
- if (e[1]) throw U(e[0]);
819
+ let e = Q.xlsxarchive_acknowledge_sheet_cursor_terminal(this.__wbg_ptr);
820
+ if (e[1]) throw q(e[0]);
536
821
  }
537
822
  assert_healthy() {
538
- let e = J.xlsxarchive_assert_healthy(this.__wbg_ptr);
539
- if (e[1]) throw U(e[0]);
823
+ let e = Q.xlsxarchive_assert_healthy(this.__wbg_ptr);
824
+ if (e[1]) throw q(e[0]);
540
825
  }
541
826
  cancel_sheet_cursor() {
542
- J.xlsxarchive_cancel_sheet_cursor(this.__wbg_ptr);
827
+ Q.xlsxarchive_cancel_sheet_cursor(this.__wbg_ptr);
543
828
  }
544
829
  close_sheet_cursor() {
545
- J.xlsxarchive_close_sheet_cursor(this.__wbg_ptr);
830
+ Q.xlsxarchive_close_sheet_cursor(this.__wbg_ptr);
546
831
  }
547
832
  extract_image(e) {
548
- let t = H(e, J.__wbindgen_malloc, J.__wbindgen_realloc), n = q, r = J.xlsxarchive_extract_image(this.__wbg_ptr, t, n);
549
- if (r[3]) throw U(r[2]);
550
- var i = F(r[0], r[1]).slice();
551
- return J.__wbindgen_free(r[0], r[1] * 1, 1), i;
833
+ let t = K(e, Q.__wbindgen_malloc, Q.__wbindgen_realloc), n = Z, r = Q.xlsxarchive_extract_image(this.__wbg_ptr, t, n);
834
+ if (r[3]) throw q(r[2]);
835
+ var i = z(r[0], r[1]).slice();
836
+ return Q.__wbindgen_free(r[0], r[1] * 1, 1), i;
552
837
  }
553
- constructor(e, t, n) {
554
- let r = V(e, J.__wbindgen_malloc), i = q, a = J.xlsxarchive_new(r, i, !B(t), B(t) ? BigInt(0) : t, !B(n), B(n) ? BigInt(0) : n);
555
- if (a[2]) throw U(a[1]);
556
- return this.__wbg_ptr = a[0] >>> 0, $e.register(this, this.__wbg_ptr, this), this;
838
+ constructor(e, t, n, r) {
839
+ let i = G(e, Q.__wbindgen_malloc), a = Z, o = Q.xlsxarchive_new(i, a, !W(t), W(t) ? BigInt(0) : t, !W(n), W(n) ? BigInt(0) : n, !W(r), W(r) ? BigInt(0) : r);
840
+ if (o[2]) throw q(o[1]);
841
+ return this.__wbg_ptr = o[0] >>> 0, St.register(this, this.__wbg_ptr, this), this;
557
842
  }
558
843
  open_sheet_cursor(e, t) {
559
- let n = H(t, J.__wbindgen_malloc, J.__wbindgen_realloc), r = q, i = J.xlsxarchive_open_sheet_cursor(this.__wbg_ptr, e, n, r);
560
- if (i[1]) throw U(i[0]);
844
+ let n = K(t, Q.__wbindgen_malloc, Q.__wbindgen_realloc), r = Z, i = Q.xlsxarchive_open_sheet_cursor(this.__wbg_ptr, e, n, r);
845
+ if (i[1]) throw q(i[0]);
561
846
  }
562
847
  parse() {
563
- let e = J.xlsxarchive_parse(this.__wbg_ptr);
564
- if (e[3]) throw U(e[2]);
565
- var t = F(e[0], e[1]).slice();
566
- return J.__wbindgen_free(e[0], e[1] * 1, 1), t;
567
- }
568
- parse_sheet(e, t) {
569
- let n = H(t, J.__wbindgen_malloc, J.__wbindgen_realloc), r = q, i = J.xlsxarchive_parse_sheet(this.__wbg_ptr, e, n, r);
570
- if (i[3]) throw U(i[2]);
571
- var a = F(i[0], i[1]).slice();
572
- return J.__wbindgen_free(i[0], i[1] * 1, 1), a;
848
+ let e = Q.xlsxarchive_parse(this.__wbg_ptr);
849
+ if (e[3]) throw q(e[2]);
850
+ var t = z(e[0], e[1]).slice();
851
+ return Q.__wbindgen_free(e[0], e[1] * 1, 1), t;
573
852
  }
574
853
  pull_sheet_cursor(e) {
575
- let t = J.xlsxarchive_pull_sheet_cursor(this.__wbg_ptr, e);
576
- if (t[3]) throw U(t[2]);
577
- var n = F(t[0], t[1]).slice();
578
- return J.__wbindgen_free(t[0], t[1] * 1, 1), n;
854
+ let t = Q.xlsxarchive_pull_sheet_cursor(this.__wbg_ptr, e);
855
+ if (t[3]) throw q(t[2]);
856
+ var n = z(t[0], t[1]).slice();
857
+ return Q.__wbindgen_free(t[0], t[1] * 1, 1), n;
579
858
  }
580
859
  resource_usage() {
581
- let e = J.xlsxarchive_resource_usage(this.__wbg_ptr);
582
- if (e[3]) throw U(e[2]);
583
- var t = F(e[0], e[1]).slice();
584
- return J.__wbindgen_free(e[0], e[1] * 1, 1), t;
860
+ let e = Q.xlsxarchive_resource_usage(this.__wbg_ptr);
861
+ if (e[3]) throw q(e[2]);
862
+ var t = z(e[0], e[1]).slice();
863
+ return Q.__wbindgen_free(e[0], e[1] * 1, 1), t;
585
864
  }
586
865
  sheet_cursor_pull_finished() {
587
- return J.xlsxarchive_sheet_cursor_pull_finished(this.__wbg_ptr) !== 0;
866
+ return Q.xlsxarchive_sheet_cursor_pull_finished(this.__wbg_ptr) !== 0;
588
867
  }
589
868
  sheet_cursor_resource_usage() {
590
- let e = J.xlsxarchive_sheet_cursor_resource_usage(this.__wbg_ptr);
591
- if (e[3]) throw U(e[2]);
592
- var t = F(e[0], e[1]).slice();
593
- return J.__wbindgen_free(e[0], e[1] * 1, 1), t;
869
+ let e = Q.xlsxarchive_sheet_cursor_resource_usage(this.__wbg_ptr);
870
+ if (e[3]) throw q(e[2]);
871
+ var t = z(e[0], e[1]).slice();
872
+ return Q.__wbindgen_free(e[0], e[1] * 1, 1), t;
594
873
  }
595
874
  to_markdown() {
596
875
  let e, t;
597
876
  try {
598
- let i = J.xlsxarchive_to_markdown(this.__wbg_ptr);
877
+ let i = Q.xlsxarchive_to_markdown(this.__wbg_ptr);
599
878
  var n = i[0], r = i[1];
600
- if (i[3]) throw n = 0, r = 0, U(i[2]);
601
- return e = n, t = r, L(n, r);
879
+ if (i[3]) throw n = 0, r = 0, q(i[2]);
880
+ return e = n, t = r, V(n, r);
602
881
  } finally {
603
- J.__wbindgen_free(e, t, 1);
882
+ Q.__wbindgen_free(e, t, 1);
604
883
  }
605
884
  }
606
885
  };
607
- Symbol.dispose && (P.prototype[Symbol.dispose] = P.prototype.free);
608
- function Je(e, t, n, r) {
609
- let i = V(e, J.__wbindgen_malloc), a = q, o = H(t, J.__wbindgen_malloc, J.__wbindgen_realloc), s = q, c = J.extract_image(i, a, o, s, !B(n), B(n) ? BigInt(0) : n, !B(r), B(r) ? BigInt(0) : r);
610
- if (c[3]) throw U(c[2]);
611
- var l = F(c[0], c[1]).slice();
612
- return J.__wbindgen_free(c[0], c[1] * 1, 1), l;
613
- }
614
- function Ye(e, t, n, r, i) {
615
- let a = V(e, J.__wbindgen_malloc), o = q, s = H(n, J.__wbindgen_malloc, J.__wbindgen_realloc), c = q, l = J.parse_sheet(a, o, t, s, c, !B(r), B(r) ? BigInt(0) : r, !B(i), B(i) ? BigInt(0) : i);
616
- if (l[3]) throw U(l[2]);
617
- var u = F(l[0], l[1]).slice();
618
- return J.__wbindgen_free(l[0], l[1] * 1, 1), u;
619
- }
620
- function Xe(e, t, n) {
621
- let r = V(e, J.__wbindgen_malloc), i = q, a = J.parse_xlsx(r, i, !B(t), B(t) ? BigInt(0) : t, !B(n), B(n) ? BigInt(0) : n);
622
- if (a[3]) throw U(a[2]);
623
- var o = F(a[0], a[1]).slice();
624
- return J.__wbindgen_free(a[0], a[1] * 1, 1), o;
625
- }
626
- function Ze(e, t, n) {
886
+ Symbol.dispose && (R.prototype[Symbol.dispose] = R.prototype.free);
887
+ function vt(e, t, n, r) {
888
+ let i = G(e, Q.__wbindgen_malloc), a = Z, o = K(t, Q.__wbindgen_malloc, Q.__wbindgen_realloc), s = Z, c = Q.extract_image(i, a, o, s, !W(n), W(n) ? BigInt(0) : n, !W(r), W(r) ? BigInt(0) : r);
889
+ if (c[3]) throw q(c[2]);
890
+ var l = z(c[0], c[1]).slice();
891
+ return Q.__wbindgen_free(c[0], c[1] * 1, 1), l;
892
+ }
893
+ function yt(e, t, n) {
894
+ let r = G(e, Q.__wbindgen_malloc), i = Z, a = Q.parse_xlsx(r, i, !W(t), W(t) ? BigInt(0) : t, !W(n), W(n) ? BigInt(0) : n);
895
+ if (a[3]) throw q(a[2]);
896
+ var o = z(a[0], a[1]).slice();
897
+ return Q.__wbindgen_free(a[0], a[1] * 1, 1), o;
898
+ }
899
+ function bt(e, t, n) {
627
900
  let r, i;
628
901
  try {
629
- let s = V(e, J.__wbindgen_malloc), c = q, l = J.xlsx_to_markdown(s, c, !B(t), B(t) ? BigInt(0) : t, !B(n), B(n) ? BigInt(0) : n);
902
+ let s = G(e, Q.__wbindgen_malloc), c = Z, l = Q.xlsx_to_markdown(s, c, !W(t), W(t) ? BigInt(0) : t, !W(n), W(n) ? BigInt(0) : n);
630
903
  var a = l[0], o = l[1];
631
- if (l[3]) throw a = 0, o = 0, U(l[2]);
632
- return r = a, i = o, L(a, o);
904
+ if (l[3]) throw a = 0, o = 0, q(l[2]);
905
+ return r = a, i = o, V(a, o);
633
906
  } finally {
634
- J.__wbindgen_free(r, i, 1);
907
+ Q.__wbindgen_free(r, i, 1);
635
908
  }
636
909
  }
637
- function Qe() {
910
+ function xt() {
638
911
  return {
639
912
  __proto__: null,
640
913
  "./xlsx_parser_bg.js": {
641
914
  __proto__: null,
642
915
  __wbg___wbindgen_throw_6b64449b9b9ed33c: function(e, t) {
643
- throw Error(L(e, t));
916
+ throw Error(V(e, t));
644
917
  },
645
918
  __wbg_error_a6fa202b58aa1cd3: function(e, t) {
646
919
  let n, r;
647
920
  try {
648
- n = e, r = t, console.error(L(e, t));
921
+ n = e, r = t, console.error(V(e, t));
649
922
  } finally {
650
- J.__wbindgen_free(n, r, 1);
923
+ Q.__wbindgen_free(n, r, 1);
651
924
  }
652
925
  },
653
926
  __wbg_new_227d7c05414eb861: function() {
654
927
  return /* @__PURE__ */ Error();
655
928
  },
656
929
  __wbg_stack_3b0d974bbf31e44f: function(e, t) {
657
- let n = t.stack, r = H(n, J.__wbindgen_malloc, J.__wbindgen_realloc), i = q;
658
- et().setInt32(e + 4, i, !0), et().setInt32(e + 0, r, !0);
930
+ let n = t.stack, r = K(n, Q.__wbindgen_malloc, Q.__wbindgen_realloc), i = Z;
931
+ Ct().setInt32(e + 4, i, !0), Ct().setInt32(e + 0, r, !0);
659
932
  },
660
933
  __wbindgen_cast_0000000000000001: function(e, t) {
661
- return L(e, t);
934
+ return V(e, t);
662
935
  },
663
936
  __wbindgen_init_externref_table: function() {
664
- let e = J.__wbindgen_externrefs, t = e.grow(4);
937
+ let e = Q.__wbindgen_externrefs, t = e.grow(4);
665
938
  e.set(0, void 0), e.set(t + 0, void 0), e.set(t + 1, null), e.set(t + 2, !0), e.set(t + 3, !1);
666
939
  }
667
940
  }
668
941
  };
669
942
  }
670
- var $e = typeof FinalizationRegistry > "u" ? {
943
+ var St = typeof FinalizationRegistry > "u" ? {
671
944
  register: () => {},
672
945
  unregister: () => {}
673
- } : new FinalizationRegistry((e) => J.__wbg_xlsxarchive_free(e >>> 0, 1));
674
- function F(e, t) {
675
- return e >>>= 0, z().subarray(e / 1, e / 1 + t);
946
+ } : new FinalizationRegistry((e) => Q.__wbg_xlsxarchive_free(e >>> 0, 1));
947
+ function z(e, t) {
948
+ return e >>>= 0, U().subarray(e / 1, e / 1 + t);
676
949
  }
677
- var I = null;
678
- function et() {
679
- return (I === null || I.buffer.detached === !0 || I.buffer.detached === void 0 && I.buffer !== J.memory.buffer) && (I = new DataView(J.memory.buffer)), I;
950
+ var B = null;
951
+ function Ct() {
952
+ return (B === null || B.buffer.detached === !0 || B.buffer.detached === void 0 && B.buffer !== Q.memory.buffer) && (B = new DataView(Q.memory.buffer)), B;
680
953
  }
681
- function L(e, t) {
682
- return e >>>= 0, nt(e, t);
954
+ function V(e, t) {
955
+ return e >>>= 0, Tt(e, t);
683
956
  }
684
- var R = null;
685
- function z() {
686
- return (R === null || R.byteLength === 0) && (R = new Uint8Array(J.memory.buffer)), R;
957
+ var H = null;
958
+ function U() {
959
+ return (H === null || H.byteLength === 0) && (H = new Uint8Array(Q.memory.buffer)), H;
687
960
  }
688
- function B(e) {
961
+ function W(e) {
689
962
  return e == null;
690
963
  }
691
- function V(e, t) {
964
+ function G(e, t) {
692
965
  let n = t(e.length * 1, 1) >>> 0;
693
- return z().set(e, n / 1), q = e.length, n;
966
+ return U().set(e, n / 1), Z = e.length, n;
694
967
  }
695
- function H(e, t, n) {
968
+ function K(e, t, n) {
696
969
  if (n === void 0) {
697
- let n = K.encode(e), r = t(n.length, 1) >>> 0;
698
- return z().subarray(r, r + n.length).set(n), q = n.length, r;
970
+ let n = X.encode(e), r = t(n.length, 1) >>> 0;
971
+ return U().subarray(r, r + n.length).set(n), Z = n.length, r;
699
972
  }
700
- let r = e.length, i = t(r, 1) >>> 0, a = z(), o = 0;
973
+ let r = e.length, i = t(r, 1) >>> 0, a = U(), o = 0;
701
974
  for (; o < r; o++) {
702
975
  let t = e.charCodeAt(o);
703
976
  if (t > 127) break;
@@ -705,40 +978,40 @@ function H(e, t, n) {
705
978
  }
706
979
  if (o !== r) {
707
980
  o !== 0 && (e = e.slice(o)), i = n(i, r, r = o + e.length * 3, 1) >>> 0;
708
- let t = z().subarray(i + o, i + r), a = K.encodeInto(e, t);
981
+ let t = U().subarray(i + o, i + r), a = X.encodeInto(e, t);
709
982
  o += a.written, i = n(i, r, o, 1) >>> 0;
710
983
  }
711
- return q = o, i;
984
+ return Z = o, i;
712
985
  }
713
- function U(e) {
714
- let t = J.__wbindgen_externrefs.get(e);
715
- return J.__externref_table_dealloc(e), t;
986
+ function q(e) {
987
+ let t = Q.__wbindgen_externrefs.get(e);
988
+ return Q.__externref_table_dealloc(e), t;
716
989
  }
717
- var W = new TextDecoder("utf-8", {
990
+ var J = new TextDecoder("utf-8", {
718
991
  ignoreBOM: !0,
719
992
  fatal: !0
720
993
  });
721
- W.decode();
722
- var tt = 2146435072, G = 0;
723
- function nt(e, t) {
724
- return G += t, G >= tt && (W = new TextDecoder("utf-8", {
994
+ J.decode();
995
+ var wt = 2146435072, Y = 0;
996
+ function Tt(e, t) {
997
+ return Y += t, Y >= wt && (J = new TextDecoder("utf-8", {
725
998
  ignoreBOM: !0,
726
999
  fatal: !0
727
- }), W.decode(), G = t), W.decode(z().subarray(e, e + t));
1000
+ }), J.decode(), Y = t), J.decode(U().subarray(e, e + t));
728
1001
  }
729
- var K = new TextEncoder();
730
- "encodeInto" in K || (K.encodeInto = function(e, t) {
731
- let n = K.encode(e);
1002
+ var X = new TextEncoder();
1003
+ "encodeInto" in X || (X.encodeInto = function(e, t) {
1004
+ let n = X.encode(e);
732
1005
  return t.set(n), {
733
1006
  read: e.length,
734
1007
  written: n.length
735
1008
  };
736
1009
  });
737
- var q = 0, J;
738
- function Y(e, t) {
739
- return J = e.exports, I = null, R = null, J.__wbindgen_start(), J;
1010
+ var Z = 0, Q;
1011
+ function Et(e, t) {
1012
+ return Q = e.exports, B = null, H = null, Q.__wbindgen_start(), Q;
740
1013
  }
741
- async function rt(e, t) {
1014
+ async function Dt(e, t) {
742
1015
  if (typeof Response == "function" && e instanceof Response) {
743
1016
  if (typeof WebAssembly.instantiateStreaming == "function") try {
744
1017
  return await WebAssembly.instantiateStreaming(e, t);
@@ -764,86 +1037,96 @@ async function rt(e, t) {
764
1037
  return !1;
765
1038
  }
766
1039
  }
767
- function it(e) {
768
- if (J !== void 0) return J;
1040
+ function Ot(e) {
1041
+ if (Q !== void 0) return Q;
769
1042
  e !== void 0 && (Object.getPrototypeOf(e) === Object.prototype ? {module: e} = e : console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));
770
- let t = Qe();
771
- return e instanceof WebAssembly.Module || (e = new WebAssembly.Module(e)), Y(new WebAssembly.Instance(e, t), e);
1043
+ let t = xt();
1044
+ return e instanceof WebAssembly.Module || (e = new WebAssembly.Module(e)), Et(new WebAssembly.Instance(e, t), e);
772
1045
  }
773
- async function at(e) {
774
- if (J !== void 0) return J;
1046
+ async function kt(e) {
1047
+ if (Q !== void 0) return Q;
775
1048
  e !== void 0 && (Object.getPrototypeOf(e) === Object.prototype ? {module_or_path: e} = e : console.warn("using deprecated parameters for the initialization function; pass a single object instead"));
776
- let t = Qe();
1049
+ let t = xt();
777
1050
  (typeof e == "string" || typeof Request == "function" && e instanceof Request || typeof URL == "function" && e instanceof URL) && (e = fetch(e));
778
- let { instance: n, module: r } = await rt(await e, t);
779
- return Y(n, r);
1051
+ let { instance: n, module: r } = await Dt(await e, t);
1052
+ return Et(n, r);
780
1053
  }
781
- async function ot(e) {
782
- return J = void 0, I = null, R = null, at(e);
1054
+ async function At(e) {
1055
+ return Q = void 0, B = null, H = null, kt(e);
783
1056
  }
784
1057
  //#endregion
785
- //#region packages/node/src/xlsx.ts
786
- var st = !1;
787
- function X() {
788
- st ||= (me(qe, ge(import.meta.url, "../../xlsx/src/wasm/xlsx_parser_bg.wasm")), !0);
789
- }
790
- function Z(e) {
791
- X();
792
- let t = Xe(Q(e));
793
- return JSON.parse(new TextDecoder().decode(t));
794
- }
795
- function ct(e, t, n) {
796
- X();
797
- let r = Ye(Q(e), t, n);
798
- return JSON.parse(new TextDecoder().decode(r));
799
- }
800
- function lt(e, t, n) {
801
- return se(ct(e, t, n), Z(e).sharedStrings);
1058
+ //#region packages/xlsx/src/internal/node-acquisition.ts
1059
+ var jt, Mt;
1060
+ function Nt(e) {
1061
+ if (!Mt) jt = e, Mt = new Ce(_t, e);
1062
+ else if (jt !== e) throw Error("XLSX runtime was already initialized with another WebAssembly.Module");
1063
+ return Mt;
802
1064
  }
803
- function ut(e) {
804
- let t = Z(e), n = {};
805
- for (let r = 0; r < t.workbook.sheets.length; r++) {
806
- let i = t.workbook.sheets[r];
807
- n[i.name] = se(ct(e, r, i.name), t.sharedStrings);
808
- }
809
- return {
810
- workbook: t.workbook,
811
- worksheets: n
812
- };
813
- }
814
- async function dt(e, n = {}) {
815
- let r = m(n), i = new o({
816
- enabled: r.debug || r.onResourceMetrics !== void 0,
1065
+ async function Pt(e, t, r = {}) {
1066
+ let i = n(r), o = new u({
1067
+ enabled: i.debug || i.onResourceMetrics !== void 0,
817
1068
  format: "xlsx",
818
1069
  mode: "node",
819
1070
  scope: "session",
820
- policy: r.policy,
821
- onMetrics: r.onResourceMetrics,
822
- emitToConsole: r.debug
823
- }), a = Q(e);
824
- i.setSourceBytes(a.byteLength);
825
- let c;
1071
+ policy: i.policy,
1072
+ onMetrics: i.onResourceMetrics,
1073
+ emitToConsole: i.debug
1074
+ });
1075
+ o.setSourceBytes(e.byteLength);
1076
+ let s;
826
1077
  try {
827
- $(n.signal), X();
828
- let [e, t] = s(r.policy);
829
- c = pt(P, a, e, t);
830
- let o = JSON.parse(new TextDecoder().decode(c.parse())), l = mt(c.resource_usage());
831
- return i.observeUsage(l), i.checkpoint("workbook index ready"), new ft(c, o, i, l, n.signal);
1078
+ It(r.signal);
1079
+ let [n, c, l] = a(i.policy), u = R;
1080
+ s = await Nt(t).open(() => new u(e, n, c, l), {
1081
+ signal: r.signal,
1082
+ abortError: Lt,
1083
+ disposeOnAbort: (e) => e.free()
1084
+ }), It(r.signal);
1085
+ let d = s.proxy, ee = JSON.parse(new TextDecoder().decode(d.parse())), f = Ft(d.resource_usage());
1086
+ return o.observeUsage(f), o.checkpoint("workbook index ready"), {
1087
+ archive: d,
1088
+ workbookIndex: ee,
1089
+ usage: f,
1090
+ metrics: o,
1091
+ closeArchive: () => s?.close((e) => e.free())
1092
+ };
832
1093
  } catch (e) {
833
1094
  try {
834
- c?.free();
1095
+ s?.close((e) => e.free());
835
1096
  } catch {}
836
- let n = t(e) ?? e;
837
- throw i.fail(n), n;
1097
+ let t = f(e) ?? e;
1098
+ throw o.fail(t), t;
838
1099
  }
839
1100
  }
840
- var ft = class {
1101
+ function Ft(e) {
1102
+ try {
1103
+ return g(e);
1104
+ } catch (e) {
1105
+ if (String(e).includes("worksheet cursor usage is unavailable")) return;
1106
+ throw e;
1107
+ }
1108
+ }
1109
+ function It(e) {
1110
+ if (e?.aborted) throw Lt();
1111
+ }
1112
+ function Lt() {
1113
+ let e = /* @__PURE__ */ Error("XLSX workbook session was aborted");
1114
+ return e.name = "AbortError", e;
1115
+ }
1116
+ //#endregion
1117
+ //#region packages/node/src/xlsx.ts
1118
+ var Rt = y(() => Ie(import.meta.url, "xlsx_parser_bg.wasm", "@silurus/ooxml-xlsx/wasm-binary"));
1119
+ async function $(e, t = {}) {
1120
+ let n = await Pt(Kt(e), Rt(), t);
1121
+ return new zt(n.closeArchive, n.archive, n.workbookIndex, n.metrics, n.usage, t.signal);
1122
+ }
1123
+ var zt = class {
1124
+ workbookIndex;
841
1125
  sheetCount;
842
1126
  sheetNames;
843
1127
  pull;
844
1128
  transport;
845
- workbook;
846
- nextOperationId = 1;
1129
+ worksheetPullClient;
847
1130
  active;
848
1131
  closed = !1;
849
1132
  closePromise;
@@ -851,13 +1134,22 @@ var ft = class {
851
1134
  completedWorksheets = 0;
852
1135
  rowBatches = 0;
853
1136
  emittedRows = 0;
854
- constructor(e, t, n, r, i) {
855
- this.archive = e, this.metrics = n, this.signal = i, this.workbook = t, this.sheetNames = Object.freeze(t.workbook.sheets.map((e) => e.name)), this.sheetCount = this.sheetNames.length, this.lastUsage = r, this.pull = new le(() => this.archive), this.transport = new de((e, t) => this.pull.dispatchSafely(e, t), () => void 0);
1137
+ constructor(e, t, n, r, i, a) {
1138
+ this.closeArchive = e, this.archive = t, this.metrics = r, this.signal = a, this.workbookIndex = Wt(n), this.sheetNames = Object.freeze(this.workbookIndex.workbook.sheets.map((e) => e.name)), this.sheetCount = this.sheetNames.length, this.lastUsage = i, this.pull = new ge(() => this.archive), this.transport = new v((e, t) => this.pull.dispatchSafely(e, t), () => void 0), this.worksheetPullClient = new ve({
1139
+ transport: this.transport,
1140
+ sharedStrings: n.sharedStrings,
1141
+ open: async (e, t, n) => {
1142
+ this.pull.reserveOpen(n), await this.pull.open(e, t, n);
1143
+ },
1144
+ onUsage: (e) => {
1145
+ this.lastUsage = e, this.metrics.observeUsage(e);
1146
+ }
1147
+ });
856
1148
  }
857
1149
  get resourceUsage() {
858
1150
  if (this.closed) return this.lastUsage;
859
1151
  try {
860
- this.lastUsage = mt(this.archive.resource_usage());
1152
+ this.lastUsage = Gt(this.archive.resource_usage());
861
1153
  } catch {}
862
1154
  return this.lastUsage;
863
1155
  }
@@ -865,59 +1157,40 @@ var ft = class {
865
1157
  if (this.closed) throw Error("XLSX workbook session is closed");
866
1158
  if (this.active) throw Error("another XLSX worksheet row stream is already active");
867
1159
  if (!Number.isSafeInteger(e) || e < 0) throw RangeError("sheetIndex must be a non-negative safe integer");
868
- let n = this.requireSheetName(e);
869
- $(this.signal);
870
- let r = this.nextOperationId++, i = {
871
- identity: {
872
- sessionId: r,
873
- operationId: r,
874
- generation: 1
875
- },
876
- terminalAcknowledged: !1
877
- };
878
- this.active = i;
879
- let a;
1160
+ let t = this.requireSheetName(e), n = {};
1161
+ this.active = n;
1162
+ let r;
880
1163
  try {
881
- this.pull.reserveOpen(i.identity), await this.pull.open(e, n, i.identity);
882
- let t = new p(this.transport, {
883
- ...i.identity,
884
- maxByteCredit: ce
885
- });
886
- for (i.client = t;;) {
1164
+ for await (let n of this.worksheetPullClient.stream(e, t, this.signal)) {
887
1165
  if (this.closed) throw Error("XLSX workbook session is closed");
888
- $(this.signal);
889
- let e = await t.pull(ce, { signal: this.signal });
890
- this.lastUsage = e.usage ?? this.lastUsage, this.metrics.observeUsage(e.usage);
891
- let n = JSON.parse(new TextDecoder().decode(new Uint8Array(e.payload)));
892
- if (e.done !== (n.kind === "finished")) throw Error("worksheet cursor terminal marker mismatch");
893
1166
  if (n.kind === "rows") {
894
- ue(n.rows, this.requireWorkbook().sharedStrings), this.rowBatches += 1, this.emittedRows += n.rows.length, yield {
1167
+ this.rowBatches += 1, this.emittedRows += n.rows.length, yield {
895
1168
  kind: "rows",
896
1169
  rows: n.rows,
897
- sequence: e.sequence,
898
- wireBytes: e.byteLength,
899
- usage: e.usage
900
- }, await e.ack({ signal: this.signal });
1170
+ sequence: n.sequence,
1171
+ wireBytes: n.wireBytes,
1172
+ usage: n.usage
1173
+ };
901
1174
  continue;
902
1175
  }
903
- n.worksheet.rows = [], yield {
1176
+ yield {
904
1177
  kind: "finished",
905
1178
  worksheet: n.worksheet,
906
- sequence: e.sequence,
907
- wireBytes: e.byteLength,
908
- usage: e.usage
909
- }, await e.ack({ signal: this.signal }), i.terminalAcknowledged = !0, this.completedWorksheets += 1, this.metrics.checkpoint("worksheet stream complete", e.usage);
910
- return;
1179
+ sequence: n.sequence,
1180
+ wireBytes: n.wireBytes,
1181
+ usage: n.usage
1182
+ };
911
1183
  }
1184
+ this.completedWorksheets += 1, this.metrics.checkpoint("worksheet stream complete", this.lastUsage);
912
1185
  } catch (e) {
913
- throw a = t(e) ?? e, this.metrics.fail(a), await this.close().catch(() => void 0), a;
1186
+ throw r = f(e) ?? e, this.metrics.fail(r), await this.close().catch(() => void 0), r;
914
1187
  } finally {
915
1188
  try {
916
- await this.cleanupOperation(i, a === void 0 ? "closed" : "request-error");
1189
+ await this.cleanupOperation(n, r === void 0 ? "closed" : "request-error");
917
1190
  } catch (e) {
918
- if (a === void 0) {
919
- let n = t(e) ?? e;
920
- throw this.metrics.fail(n), await this.close().catch(() => void 0), n;
1191
+ if (r === void 0) {
1192
+ let t = f(e) ?? e;
1193
+ throw this.metrics.fail(t), await this.close().catch(() => void 0), t;
921
1194
  }
922
1195
  }
923
1196
  }
@@ -925,34 +1198,34 @@ var ft = class {
925
1198
  close() {
926
1199
  return this.closePromise ? this.closePromise : (this.closed = !0, this.closePromise = this.release(), this.closePromise);
927
1200
  }
928
- cleanupOperation(e, n) {
1201
+ cleanupOperation(e, t) {
929
1202
  return e.cleanupPromise ||= (async () => {
930
- let r;
931
- if (e.client && !e.terminalAcknowledged) try {
932
- await e.client.cancel(n);
1203
+ let n;
1204
+ try {
1205
+ await this.worksheetPullClient.cancelAll(t);
933
1206
  } catch (e) {
934
- r = t(e) ?? e;
1207
+ n = f(e) ?? e;
935
1208
  }
936
1209
  try {
937
1210
  await this.pull.reset();
938
1211
  } catch (e) {
939
- r ??= t(e) ?? e;
1212
+ n ??= f(e) ?? e;
940
1213
  }
941
- if (this.active === e && (this.active = void 0), r !== void 0) throw r;
1214
+ if (this.active === e && (this.active = void 0), n !== void 0) throw n;
942
1215
  })(), e.cleanupPromise;
943
1216
  }
944
1217
  async release() {
945
1218
  let e;
946
1219
  if (this.active) try {
947
1220
  await this.cleanupOperation(this.active, "closed");
948
- } catch (n) {
949
- e = t(n) ?? n;
1221
+ } catch (t) {
1222
+ e = f(t) ?? t;
950
1223
  }
951
- this.transport.terminate(), this.workbook = null;
1224
+ this.transport.terminate();
952
1225
  try {
953
- this.archive.free();
954
- } catch (n) {
955
- e ??= t(n) ?? n;
1226
+ this.closeArchive();
1227
+ } catch (t) {
1228
+ e ??= f(t) ?? t;
956
1229
  }
957
1230
  if (e !== void 0) throw this.metrics.fail(e), e;
958
1231
  this.metrics.checkpoint("workbook session closed", this.lastUsage), this.metrics.succeed({
@@ -961,38 +1234,79 @@ var ft = class {
961
1234
  rows: this.emittedRows
962
1235
  });
963
1236
  }
964
- requireWorkbook() {
965
- if (!this.workbook) throw Error("XLSX workbook session is closed");
966
- return this.workbook;
967
- }
968
1237
  requireSheetName(e) {
969
- let t = this.requireWorkbook().workbook.sheets[e];
1238
+ let t = this.workbookIndex.workbook.sheets[e];
970
1239
  if (!t) throw RangeError(`Sheet index ${e} out of range`);
971
1240
  return t.name;
972
1241
  }
973
1242
  };
974
- function pt(e, n, r, i) {
975
- try {
976
- return new e(n, r, i);
977
- } catch (e) {
978
- throw t(e) ?? e;
979
- }
1243
+ async function Bt(e, t = {}) {
1244
+ return _(() => $(e, t), async (e) => structuredClone(e.workbookIndex));
1245
+ }
1246
+ async function Vt(e, t, n = {}) {
1247
+ return _(() => $(e, n), async (e) => (await Ut(e, t)).worksheet);
980
1248
  }
981
- function mt(e) {
1249
+ async function Ht(e, t = {}) {
1250
+ return _(() => $(e, t), async (e) => {
1251
+ let t = [], n = {
1252
+ rows: 0,
1253
+ cells: 0,
1254
+ ownedUtf8Bytes: 0,
1255
+ jsonBytes: 0
1256
+ };
1257
+ for (let r = 0; r < e.sheetCount; r += 1) {
1258
+ let i = await Ut(e, r), a = de(n, i.usage);
1259
+ _e(a, "materialize-workbook", void 0, i.resourceUsage), n = a, t.push(i.worksheet);
1260
+ }
1261
+ return {
1262
+ workbookIndex: structuredClone(e.workbookIndex),
1263
+ worksheets: Object.freeze(t)
1264
+ };
1265
+ });
1266
+ }
1267
+ async function Ut(e, t) {
1268
+ let n = [], r = {
1269
+ rows: 0,
1270
+ cells: 0,
1271
+ ownedUtf8Bytes: 0
1272
+ }, i, a, o;
1273
+ for await (let s of e.worksheetRows(t)) if (o = s.usage ?? o, s.kind === "rows") {
1274
+ let e = he(r, pe(s.rows));
1275
+ me(e, "materialize-worksheet", void 0, o), n.push(...s.rows), r = e;
1276
+ } else {
1277
+ a = s.worksheet, a.rows = a.parseError ? [] : n;
1278
+ let e = ye(a, a.parseError ? {
1279
+ rows: 0,
1280
+ cells: 0,
1281
+ ownedUtf8Bytes: 0
1282
+ } : r);
1283
+ me(e, "materialize-worksheet", void 0, o), fe(e.jsonBytes, "materialize-worksheet", void 0, o), r = e, i = e;
1284
+ }
1285
+ if (!a || !i) throw Error(`XLSX worksheet ${t} did not produce a terminal model`);
1286
+ return {
1287
+ worksheet: a,
1288
+ usage: i,
1289
+ resourceUsage: o
1290
+ };
1291
+ }
1292
+ function Wt(e, t = /* @__PURE__ */ new WeakSet()) {
1293
+ if (typeof e != "object" || !e) return e;
1294
+ let n = e;
1295
+ if (t.has(n)) return e;
1296
+ t.add(n);
1297
+ for (let e of Object.values(n)) Wt(e, t);
1298
+ return Object.freeze(e);
1299
+ }
1300
+ function Gt(e) {
982
1301
  try {
983
- return i(e);
1302
+ return g(e);
984
1303
  } catch (e) {
985
1304
  if (String(e).includes("worksheet cursor usage is unavailable")) return;
986
1305
  throw e;
987
1306
  }
988
1307
  }
989
- function Q(e) {
1308
+ function Kt(e) {
990
1309
  return e instanceof Uint8Array ? e : new Uint8Array(e);
991
1310
  }
992
- function $(e) {
993
- if (!e?.aborted) return;
994
- let t = /* @__PURE__ */ Error("XLSX workbook session was aborted");
995
- throw t.name = "AbortError", t;
996
- }
997
1311
  //#endregion
998
- export { re as OoxmlDecodedImageLimitError, n as OoxmlResourceLimitError, _e as extractPptxImage, pe as extractPptxMedia, Se as installImageBitmapShim, ye as installOffscreenCanvasShim, ie as isOoxmlDecodedImageLimitError, xe as makeSourceBufferFetchImage, He as openDocxDocument, he as openPptxPresentation, dt as openXlsxWorkbook, Ve as parseDocx, fe as parsePptx, Z as parseXlsx, ut as parseXlsxAllSheets, lt as parseXlsxSheet, ve as renderSlideNode };
1312
+ export { s as OoxmlDecodedImageLimitError, p as OoxmlResourceLimitError, De as installImageBitmapShim, Te as installOffscreenCanvasShim, c as isOoxmlDecodedImageLimitError, pt as materializeDocxDocument, Ve as materializePptxPresentation, Ht as materializeXlsxWorkbook, Bt as materializeXlsxWorkbookIndex, Vt as materializeXlsxWorksheet, ft as openDocxDocument, Re as openPptxPresentation, $ as openXlsxWorkbook, Ee as renderSlideNode };