@extend-ai/react-docx 0.7.0-alpha.1 → 0.7.0-alpha.2

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
@@ -19,6 +19,34 @@ pnpm add @extend-ai/react-docx react react-dom
19
19
 
20
20
  `react` and `react-dom` are peer dependencies.
21
21
 
22
+ ## WebAssembly Asset
23
+
24
+ DOCX parsing and serialization run in a Rust/WebAssembly module that ships inside this package as `dist/docx_wasm_bg.wasm` (~2.5 MB raw, ~1 MB over the wire with gzip). It is **not** part of the JavaScript bundle:
25
+
26
+ - It loads lazily, on the first call that parses or serializes a document.
27
+ - The loader references it as `new URL("./docx_wasm_bg.wasm", import.meta.url)`, which Vite, webpack 5, Rollup, and Next.js automatically emit as a hashed static asset — no configuration needed.
28
+ - In Node (SSR, tests, scripts) the binary is read from `node_modules` on disk.
29
+
30
+ If you need to host the binary somewhere else (e.g. a CDN), override the source before the first parse:
31
+
32
+ ```ts
33
+ import { setWasmSource } from "@extend-ai/react-docx";
34
+
35
+ setWasmSource("https://cdn.example.com/docx_wasm_bg.wasm");
36
+ // or pass a URL, Response, ArrayBuffer/TypedArray, or compiled WebAssembly.Module
37
+ ```
38
+
39
+ The binary is also exposed as a package subpath, so with Vite you can do:
40
+
41
+ ```ts
42
+ import wasmUrl from "@extend-ai/react-docx/docx_wasm_bg.wasm?url";
43
+ import { setWasmSource } from "@extend-ai/react-docx";
44
+
45
+ setWasmSource(wasmUrl);
46
+ ```
47
+
48
+ You can also call `initWasm()` (optionally with a source) ahead of time to warm the module before the first document is opened.
49
+
22
50
  ## Main Entry Points
23
51
 
24
52
  The package exports two useful levels of API:
@@ -0,0 +1,575 @@
1
+ // ../wasm/src/generated/docx_wasm.js
2
+ function build_doc_model_from_package(_package) {
3
+ let deferred2_0;
4
+ let deferred2_1;
5
+ try {
6
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
7
+ wasm.build_doc_model_from_package(retptr, addBorrowedObject(_package));
8
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
9
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
10
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
11
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
12
+ var ptr1 = r0;
13
+ var len1 = r1;
14
+ if (r3) {
15
+ ptr1 = 0;
16
+ len1 = 0;
17
+ throw takeObject(r2);
18
+ }
19
+ deferred2_0 = ptr1;
20
+ deferred2_1 = len1;
21
+ return getStringFromWasm0(ptr1, len1);
22
+ } finally {
23
+ wasm.__wbindgen_add_to_stack_pointer(16);
24
+ heap[stack_pointer++] = void 0;
25
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
26
+ }
27
+ }
28
+ function model_to_document_xml_from_json_wasm(model_json, base_package) {
29
+ let deferred3_0;
30
+ let deferred3_1;
31
+ try {
32
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
33
+ const ptr0 = passStringToWasm0(model_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
34
+ const len0 = WASM_VECTOR_LEN;
35
+ wasm.model_to_document_xml_from_json_wasm(retptr, ptr0, len0, isLikeNone(base_package) ? 0 : addHeapObject(base_package));
36
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
37
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
38
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
39
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
40
+ var ptr2 = r0;
41
+ var len2 = r1;
42
+ if (r3) {
43
+ ptr2 = 0;
44
+ len2 = 0;
45
+ throw takeObject(r2);
46
+ }
47
+ deferred3_0 = ptr2;
48
+ deferred3_1 = len2;
49
+ return getStringFromWasm0(ptr2, len2);
50
+ } finally {
51
+ wasm.__wbindgen_add_to_stack_pointer(16);
52
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
53
+ }
54
+ }
55
+ function package_to_array_buffer_wasm(_package) {
56
+ try {
57
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
58
+ wasm.package_to_array_buffer_wasm(retptr, addBorrowedObject(_package));
59
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
60
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
61
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
62
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
63
+ if (r3) {
64
+ throw takeObject(r2);
65
+ }
66
+ var v1 = getArrayU8FromWasm0(r0, r1).slice();
67
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
68
+ return v1;
69
+ } finally {
70
+ wasm.__wbindgen_add_to_stack_pointer(16);
71
+ heap[stack_pointer++] = void 0;
72
+ }
73
+ }
74
+ function parse_docx_wasm(bytes) {
75
+ try {
76
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
77
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
78
+ const len0 = WASM_VECTOR_LEN;
79
+ wasm.parse_docx_wasm(retptr, ptr0, len0);
80
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
81
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
82
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
83
+ if (r2) {
84
+ throw takeObject(r1);
85
+ }
86
+ return takeObject(r0);
87
+ } finally {
88
+ wasm.__wbindgen_add_to_stack_pointer(16);
89
+ }
90
+ }
91
+ function serialize_docx_from_json_wasm(model_json, base_package) {
92
+ try {
93
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
94
+ const ptr0 = passStringToWasm0(model_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
95
+ const len0 = WASM_VECTOR_LEN;
96
+ wasm.serialize_docx_from_json_wasm(retptr, ptr0, len0, isLikeNone(base_package) ? 0 : addHeapObject(base_package));
97
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
98
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
99
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
100
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
101
+ if (r3) {
102
+ throw takeObject(r2);
103
+ }
104
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
105
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
106
+ return v2;
107
+ } finally {
108
+ wasm.__wbindgen_add_to_stack_pointer(16);
109
+ }
110
+ }
111
+ function __wbg_get_imports() {
112
+ const import0 = {
113
+ __proto__: null,
114
+ __wbg___wbindgen_debug_string_56c147eb1a51f0c4: function(arg0, arg1) {
115
+ const ret = debugString(getObject(arg1));
116
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
117
+ const len1 = WASM_VECTOR_LEN;
118
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
119
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
120
+ },
121
+ __wbg___wbindgen_is_undefined_4410e3c20a99fa97: function(arg0) {
122
+ const ret = getObject(arg0) === void 0;
123
+ return ret;
124
+ },
125
+ __wbg___wbindgen_string_get_fa2687d531ed17a5: function(arg0, arg1) {
126
+ const obj = getObject(arg1);
127
+ const ret = typeof obj === "string" ? obj : void 0;
128
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
129
+ var len1 = WASM_VECTOR_LEN;
130
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
131
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
132
+ },
133
+ __wbg___wbindgen_throw_bbadd78c1bac3a77: function(arg0, arg1) {
134
+ throw new Error(getStringFromWasm0(arg0, arg1));
135
+ },
136
+ __wbg_parse_246201845d0eb98c: function() {
137
+ return handleError(function(arg0, arg1) {
138
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
139
+ return addHeapObject(ret);
140
+ }, arguments);
141
+ },
142
+ __wbg_stringify_a42c95ea9a7591c9: function() {
143
+ return handleError(function(arg0) {
144
+ const ret = JSON.stringify(getObject(arg0));
145
+ return addHeapObject(ret);
146
+ }, arguments);
147
+ },
148
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
149
+ const ret = getStringFromWasm0(arg0, arg1);
150
+ return addHeapObject(ret);
151
+ },
152
+ __wbindgen_object_drop_ref: function(arg0) {
153
+ takeObject(arg0);
154
+ }
155
+ };
156
+ return {
157
+ __proto__: null,
158
+ "./docx_wasm_bg.js": import0
159
+ };
160
+ }
161
+ function addHeapObject(obj) {
162
+ if (heap_next === heap.length) heap.push(heap.length + 1);
163
+ const idx = heap_next;
164
+ heap_next = heap[idx];
165
+ heap[idx] = obj;
166
+ return idx;
167
+ }
168
+ function addBorrowedObject(obj) {
169
+ if (stack_pointer == 1) throw new Error("out of js stack");
170
+ heap[--stack_pointer] = obj;
171
+ return stack_pointer;
172
+ }
173
+ function debugString(val) {
174
+ const type = typeof val;
175
+ if (type == "number" || type == "boolean" || val == null) {
176
+ return `${val}`;
177
+ }
178
+ if (type == "string") {
179
+ return `"${val}"`;
180
+ }
181
+ if (type == "symbol") {
182
+ const description = val.description;
183
+ if (description == null) {
184
+ return "Symbol";
185
+ } else {
186
+ return `Symbol(${description})`;
187
+ }
188
+ }
189
+ if (type == "function") {
190
+ const name = val.name;
191
+ if (typeof name == "string" && name.length > 0) {
192
+ return `Function(${name})`;
193
+ } else {
194
+ return "Function";
195
+ }
196
+ }
197
+ if (Array.isArray(val)) {
198
+ const length = val.length;
199
+ let debug = "[";
200
+ if (length > 0) {
201
+ debug += debugString(val[0]);
202
+ }
203
+ for (let i = 1; i < length; i++) {
204
+ debug += ", " + debugString(val[i]);
205
+ }
206
+ debug += "]";
207
+ return debug;
208
+ }
209
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
210
+ let className;
211
+ if (builtInMatches && builtInMatches.length > 1) {
212
+ className = builtInMatches[1];
213
+ } else {
214
+ return toString.call(val);
215
+ }
216
+ if (className == "Object") {
217
+ try {
218
+ return "Object(" + JSON.stringify(val) + ")";
219
+ } catch (_) {
220
+ return "Object";
221
+ }
222
+ }
223
+ if (val instanceof Error) {
224
+ return `${val.name}: ${val.message}
225
+ ${val.stack}`;
226
+ }
227
+ return className;
228
+ }
229
+ function dropObject(idx) {
230
+ if (idx < 1028) return;
231
+ heap[idx] = heap_next;
232
+ heap_next = idx;
233
+ }
234
+ function getArrayU8FromWasm0(ptr, len) {
235
+ ptr = ptr >>> 0;
236
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
237
+ }
238
+ var cachedDataViewMemory0 = null;
239
+ function getDataViewMemory0() {
240
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
241
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
242
+ }
243
+ return cachedDataViewMemory0;
244
+ }
245
+ function getStringFromWasm0(ptr, len) {
246
+ return decodeText(ptr >>> 0, len);
247
+ }
248
+ var cachedUint8ArrayMemory0 = null;
249
+ function getUint8ArrayMemory0() {
250
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
251
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
252
+ }
253
+ return cachedUint8ArrayMemory0;
254
+ }
255
+ function getObject(idx) {
256
+ return heap[idx];
257
+ }
258
+ function handleError(f, args) {
259
+ try {
260
+ return f.apply(this, args);
261
+ } catch (e) {
262
+ wasm.__wbindgen_export3(addHeapObject(e));
263
+ }
264
+ }
265
+ var heap = new Array(1024).fill(void 0);
266
+ heap.push(void 0, null, true, false);
267
+ var heap_next = heap.length;
268
+ function isLikeNone(x) {
269
+ return x === void 0 || x === null;
270
+ }
271
+ function passArray8ToWasm0(arg, malloc) {
272
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
273
+ getUint8ArrayMemory0().set(arg, ptr / 1);
274
+ WASM_VECTOR_LEN = arg.length;
275
+ return ptr;
276
+ }
277
+ function passStringToWasm0(arg, malloc, realloc) {
278
+ if (realloc === void 0) {
279
+ const buf = cachedTextEncoder.encode(arg);
280
+ const ptr2 = malloc(buf.length, 1) >>> 0;
281
+ getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
282
+ WASM_VECTOR_LEN = buf.length;
283
+ return ptr2;
284
+ }
285
+ let len = arg.length;
286
+ let ptr = malloc(len, 1) >>> 0;
287
+ const mem = getUint8ArrayMemory0();
288
+ let offset = 0;
289
+ for (; offset < len; offset++) {
290
+ const code = arg.charCodeAt(offset);
291
+ if (code > 127) break;
292
+ mem[ptr + offset] = code;
293
+ }
294
+ if (offset !== len) {
295
+ if (offset !== 0) {
296
+ arg = arg.slice(offset);
297
+ }
298
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
299
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
300
+ const ret = cachedTextEncoder.encodeInto(arg, view);
301
+ offset += ret.written;
302
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
303
+ }
304
+ WASM_VECTOR_LEN = offset;
305
+ return ptr;
306
+ }
307
+ var stack_pointer = 1024;
308
+ function takeObject(idx) {
309
+ const ret = getObject(idx);
310
+ dropObject(idx);
311
+ return ret;
312
+ }
313
+ var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
314
+ cachedTextDecoder.decode();
315
+ var MAX_SAFARI_DECODE_BYTES = 2146435072;
316
+ var numBytesDecoded = 0;
317
+ function decodeText(ptr, len) {
318
+ numBytesDecoded += len;
319
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
320
+ cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
321
+ cachedTextDecoder.decode();
322
+ numBytesDecoded = len;
323
+ }
324
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
325
+ }
326
+ var cachedTextEncoder = new TextEncoder();
327
+ if (!("encodeInto" in cachedTextEncoder)) {
328
+ cachedTextEncoder.encodeInto = function(arg, view) {
329
+ const buf = cachedTextEncoder.encode(arg);
330
+ view.set(buf);
331
+ return {
332
+ read: arg.length,
333
+ written: buf.length
334
+ };
335
+ };
336
+ }
337
+ var WASM_VECTOR_LEN = 0;
338
+ var wasmModule;
339
+ var wasmInstance;
340
+ var wasm;
341
+ function __wbg_finalize_init(instance, module) {
342
+ wasmInstance = instance;
343
+ wasm = instance.exports;
344
+ wasmModule = module;
345
+ cachedDataViewMemory0 = null;
346
+ cachedUint8ArrayMemory0 = null;
347
+ return wasm;
348
+ }
349
+ async function __wbg_load(module, imports) {
350
+ if (typeof Response === "function" && module instanceof Response) {
351
+ if (typeof WebAssembly.instantiateStreaming === "function") {
352
+ try {
353
+ return await WebAssembly.instantiateStreaming(module, imports);
354
+ } catch (e) {
355
+ const validResponse = module.ok && expectedResponseType(module.type);
356
+ if (validResponse && module.headers.get("Content-Type") !== "application/wasm") {
357
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
358
+ } else {
359
+ throw e;
360
+ }
361
+ }
362
+ }
363
+ const bytes = await module.arrayBuffer();
364
+ return await WebAssembly.instantiate(bytes, imports);
365
+ } else {
366
+ const instance = await WebAssembly.instantiate(module, imports);
367
+ if (instance instanceof WebAssembly.Instance) {
368
+ return { instance, module };
369
+ } else {
370
+ return instance;
371
+ }
372
+ }
373
+ function expectedResponseType(type) {
374
+ switch (type) {
375
+ case "basic":
376
+ case "cors":
377
+ case "default":
378
+ return true;
379
+ }
380
+ return false;
381
+ }
382
+ }
383
+ async function __wbg_init(module_or_path) {
384
+ if (wasm !== void 0) return wasm;
385
+ if (module_or_path !== void 0) {
386
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
387
+ ({ module_or_path } = module_or_path);
388
+ } else {
389
+ console.warn("using deprecated parameters for the initialization function; pass a single object instead");
390
+ }
391
+ }
392
+ if (module_or_path === void 0) {
393
+ module_or_path = new URL("docx_wasm_bg.wasm", import.meta.url);
394
+ }
395
+ const imports = __wbg_get_imports();
396
+ if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
397
+ module_or_path = fetch(module_or_path);
398
+ }
399
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
400
+ return __wbg_finalize_init(instance, module);
401
+ }
402
+
403
+ // ../wasm/src/index.ts
404
+ var initPromise;
405
+ var overrideSource;
406
+ function setWasmSource(source) {
407
+ if (initPromise) {
408
+ throw new Error(
409
+ "react-docx: setWasmSource must be called before the first parse/serialize call initializes WASM"
410
+ );
411
+ }
412
+ overrideSource = source;
413
+ }
414
+ async function nodeFsPromises() {
415
+ const proc = globalThis.process;
416
+ if (typeof proc?.getBuiltinModule === "function") {
417
+ return proc.getBuiltinModule("node:fs/promises");
418
+ }
419
+ const dynamicImport = new Function("specifier", "return import(specifier)");
420
+ return dynamicImport("node:fs/promises");
421
+ }
422
+ async function defaultWasmSource() {
423
+ const wasmUrl = new URL("./docx_wasm_bg.wasm", import.meta.url);
424
+ if (wasmUrl.protocol === "file:") {
425
+ const fs = await nodeFsPromises();
426
+ return fs.readFile(wasmUrl);
427
+ }
428
+ return wasmUrl;
429
+ }
430
+ async function initWasm(source) {
431
+ if (!initPromise) {
432
+ const chosen = source ?? overrideSource;
433
+ initPromise = (chosen !== void 0 ? Promise.resolve(chosen) : defaultWasmSource()).then(
434
+ (module_or_path) => __wbg_init({ module_or_path })
435
+ );
436
+ }
437
+ return initPromise;
438
+ }
439
+ function toUint8Array(value) {
440
+ return value instanceof Uint8Array ? value : Uint8Array.from(value);
441
+ }
442
+ function docModelToWasmJson(model) {
443
+ return JSON.stringify(model, (_key, value) => {
444
+ if (value instanceof Uint8Array) {
445
+ return Array.from(value);
446
+ }
447
+ return value;
448
+ });
449
+ }
450
+ function wasmPackageToMaps(raw) {
451
+ const parts = /* @__PURE__ */ new Map();
452
+ for (const [name, part] of Object.entries(raw.parts ?? {})) {
453
+ parts.set(name, {
454
+ name: part.name ?? name,
455
+ content: part.content
456
+ });
457
+ }
458
+ const binaryAssets = /* @__PURE__ */ new Map();
459
+ for (const [name, asset] of Object.entries(raw.binaryAssets ?? {})) {
460
+ binaryAssets.set(name, toUint8Array(asset));
461
+ }
462
+ return { parts, binaryAssets };
463
+ }
464
+ function mapsToWasmPackage(input) {
465
+ const parts = {};
466
+ for (const [name, part] of input.parts.entries()) {
467
+ parts[name] = {
468
+ name: part.name,
469
+ content: part.content
470
+ };
471
+ }
472
+ const binaryAssets = {};
473
+ for (const [name, asset] of input.binaryAssets.entries()) {
474
+ binaryAssets[name] = Array.from(asset);
475
+ }
476
+ return { parts, binaryAssets };
477
+ }
478
+ async function wasmParseDocx(bytes) {
479
+ await initWasm();
480
+ const payload = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
481
+ return parse_docx_wasm(payload);
482
+ }
483
+ async function wasmBuildDocModelFromPackage(pkg) {
484
+ await initWasm();
485
+ const json = build_doc_model_from_package(pkg);
486
+ return JSON.parse(json);
487
+ }
488
+ async function wasmSerializeDocx(model, basePackage) {
489
+ await initWasm();
490
+ const modelJson = docModelToWasmJson(model);
491
+ const bytes = serialize_docx_from_json_wasm(modelJson, basePackage ?? null);
492
+ return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
493
+ }
494
+ async function wasmModelToDocumentXml(model, basePackage) {
495
+ await initWasm();
496
+ return model_to_document_xml_from_json_wasm(docModelToWasmJson(model), basePackage ?? null);
497
+ }
498
+ async function wasmPackageToArrayBuffer(pkg) {
499
+ await initWasm();
500
+ const bytes = package_to_array_buffer_wasm(pkg);
501
+ return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
502
+ }
503
+
504
+ // ../ooxml-core/src/index.ts
505
+ async function parseDocx(input) {
506
+ const wasmPackage = await wasmParseDocx(input);
507
+ const { parts, binaryAssets } = wasmPackageToMaps(wasmPackage);
508
+ return { parts, binaryAssets };
509
+ }
510
+ async function packageToArrayBuffer(pkg) {
511
+ return wasmPackageToArrayBuffer(mapsToWasmPackage(pkg));
512
+ }
513
+ function createMinimalDocxPackage(documentXml = DEFAULT_DOCUMENT_XML) {
514
+ return {
515
+ parts: /* @__PURE__ */ new Map([
516
+ ["[Content_Types].xml", { name: "[Content_Types].xml", content: DEFAULT_CONTENT_TYPES_XML }],
517
+ ["_rels/.rels", { name: "_rels/.rels", content: DEFAULT_ROOT_RELS_XML }],
518
+ ["word/document.xml", { name: "word/document.xml", content: documentXml }],
519
+ [
520
+ "word/_rels/document.xml.rels",
521
+ { name: "word/_rels/document.xml.rels", content: DEFAULT_DOCUMENT_RELS_XML }
522
+ ]
523
+ ]),
524
+ binaryAssets: /* @__PURE__ */ new Map()
525
+ };
526
+ }
527
+ function getPart(pkg, partName) {
528
+ return pkg.parts.get(partName);
529
+ }
530
+ function withPart(pkg, part) {
531
+ const parts = new Map(pkg.parts);
532
+ parts.set(part.name, part);
533
+ return {
534
+ parts,
535
+ binaryAssets: new Map(pkg.binaryAssets)
536
+ };
537
+ }
538
+ var WORD_MAIN_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
539
+ var DEFAULT_DOCUMENT_XML = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
540
+ <w:document xmlns:w="${WORD_MAIN_NS}">
541
+ <w:body>
542
+ <w:p><w:r><w:t/></w:r></w:p>
543
+ <w:sectPr>
544
+ <w:pgSz w:w="12240" w:h="15840"/>
545
+ <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
546
+ </w:sectPr>
547
+ </w:body>
548
+ </w:document>`;
549
+ var DEFAULT_CONTENT_TYPES_XML = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
550
+ <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
551
+ <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
552
+ <Default Extension="xml" ContentType="application/xml"/>
553
+ <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
554
+ </Types>`;
555
+ var DEFAULT_ROOT_RELS_XML = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
556
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
557
+ <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
558
+ </Relationships>`;
559
+ var DEFAULT_DOCUMENT_RELS_XML = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
560
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"/>`;
561
+
562
+ export {
563
+ setWasmSource,
564
+ initWasm,
565
+ mapsToWasmPackage,
566
+ wasmBuildDocModelFromPackage,
567
+ wasmSerializeDocx,
568
+ wasmModelToDocumentXml,
569
+ parseDocx,
570
+ packageToArrayBuffer,
571
+ createMinimalDocxPackage,
572
+ getPart,
573
+ withPart
574
+ };
575
+ //# sourceMappingURL=chunk-BGCGPO6Q.js.map