@extend-ai/react-docx 0.9.0 → 0.9.1

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.
@@ -1,52 +1,16 @@
1
1
  "use strict";
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __esm = (fn, res) => function __init() {
4
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
- };
6
2
 
7
3
  // ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
8
- var getImportMetaUrl, importMetaUrl;
9
- var init_cjs_shims = __esm({
10
- "../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js"() {
11
- "use strict";
12
- getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
13
- importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
14
- }
15
- });
4
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
5
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
16
6
 
17
7
  // ../wasm/src/generated/docx_wasm.js
18
- function build_doc_model_from_package(_package) {
19
- let deferred2_0;
20
- let deferred2_1;
21
- try {
22
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
23
- wasm.build_doc_model_from_package(retptr, addBorrowedObject(_package));
24
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
25
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
26
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
27
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
28
- var ptr1 = r0;
29
- var len1 = r1;
30
- if (r3) {
31
- ptr1 = 0;
32
- len1 = 0;
33
- throw takeObject(r2);
34
- }
35
- deferred2_0 = ptr1;
36
- deferred2_1 = len1;
37
- return getStringFromWasm0(ptr1, len1);
38
- } finally {
39
- wasm.__wbindgen_add_to_stack_pointer(16);
40
- heap[stack_pointer++] = void 0;
41
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
42
- }
43
- }
44
- function parse_docx_wasm(bytes) {
8
+ function build_doc_model_from_bytes(bytes) {
45
9
  try {
46
10
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
47
11
  const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
48
12
  const len0 = WASM_VECTOR_LEN;
49
- wasm.parse_docx_wasm(retptr, ptr0, len0);
13
+ wasm.build_doc_model_from_bytes(retptr, ptr0, len0);
50
14
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
51
15
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
52
16
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -162,6 +126,10 @@ function __wbg_get_imports() {
162
126
  const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
163
127
  return addHeapObject(ret);
164
128
  },
129
+ __wbg_now_c1f9831c87b83a0b: function() {
130
+ const ret = performance.now();
131
+ return ret;
132
+ },
165
133
  __wbg_parse_246201845d0eb98c: function() {
166
134
  return handleError(function(arg0, arg1) {
167
135
  const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
@@ -187,7 +155,11 @@ function __wbg_get_imports() {
187
155
  return addHeapObject(ret);
188
156
  }, arguments);
189
157
  },
190
- __wbindgen_cast_0000000000000001: function(arg0, arg1) {
158
+ __wbindgen_cast_0000000000000001: function(arg0) {
159
+ const ret = arg0;
160
+ return addHeapObject(ret);
161
+ },
162
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
191
163
  const ret = getStringFromWasm0(arg0, arg1);
192
164
  return addHeapObject(ret);
193
165
  },
@@ -207,11 +179,6 @@ function addHeapObject(obj) {
207
179
  heap[idx] = obj;
208
180
  return idx;
209
181
  }
210
- function addBorrowedObject(obj) {
211
- if (stack_pointer == 1) throw new Error("out of js stack");
212
- heap[--stack_pointer] = obj;
213
- return stack_pointer;
214
- }
215
182
  function debugString(val) {
216
183
  const type = typeof val;
217
184
  if (type == "number" || type == "boolean" || val == null) {
@@ -277,6 +244,7 @@ function getArrayU8FromWasm0(ptr, len) {
277
244
  ptr = ptr >>> 0;
278
245
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
279
246
  }
247
+ var cachedDataViewMemory0 = null;
280
248
  function getDataViewMemory0() {
281
249
  if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
282
250
  cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
@@ -286,6 +254,7 @@ function getDataViewMemory0() {
286
254
  function getStringFromWasm0(ptr, len) {
287
255
  return decodeText(ptr >>> 0, len);
288
256
  }
257
+ var cachedUint8ArrayMemory0 = null;
289
258
  function getUint8ArrayMemory0() {
290
259
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
291
260
  cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
@@ -302,6 +271,9 @@ function handleError(f, args) {
302
271
  wasm.__wbindgen_export3(addHeapObject(e));
303
272
  }
304
273
  }
274
+ var heap = new Array(1024).fill(void 0);
275
+ heap.push(void 0, null, true, false);
276
+ var heap_next = heap.length;
305
277
  function isLikeNone(x) {
306
278
  return x === void 0 || x === null;
307
279
  }
@@ -346,6 +318,10 @@ function takeObject(idx) {
346
318
  dropObject(idx);
347
319
  return ret;
348
320
  }
321
+ var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
322
+ cachedTextDecoder.decode();
323
+ var MAX_SAFARI_DECODE_BYTES = 2146435072;
324
+ var numBytesDecoded = 0;
349
325
  function decodeText(ptr, len) {
350
326
  numBytesDecoded += len;
351
327
  if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
@@ -355,6 +331,21 @@ function decodeText(ptr, len) {
355
331
  }
356
332
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
357
333
  }
334
+ var cachedTextEncoder = new TextEncoder();
335
+ if (!("encodeInto" in cachedTextEncoder)) {
336
+ cachedTextEncoder.encodeInto = function(arg, view) {
337
+ const buf = cachedTextEncoder.encode(arg);
338
+ view.set(buf);
339
+ return {
340
+ read: arg.length,
341
+ written: buf.length
342
+ };
343
+ };
344
+ }
345
+ var WASM_VECTOR_LEN = 0;
346
+ var wasmModule;
347
+ var wasmInstance;
348
+ var wasm;
358
349
  function __wbg_finalize_init(instance, module2) {
359
350
  wasmInstance = instance;
360
351
  wasm = instance.exports;
@@ -416,37 +407,10 @@ async function __wbg_init(module_or_path) {
416
407
  const { instance, module: module2 } = await __wbg_load(await module_or_path, imports);
417
408
  return __wbg_finalize_init(instance, module2);
418
409
  }
419
- var cachedDataViewMemory0, cachedUint8ArrayMemory0, heap, heap_next, stack_pointer, cachedTextDecoder, MAX_SAFARI_DECODE_BYTES, numBytesDecoded, cachedTextEncoder, WASM_VECTOR_LEN, wasmModule, wasmInstance, wasm;
420
- var init_docx_wasm = __esm({
421
- "../wasm/src/generated/docx_wasm.js"() {
422
- "use strict";
423
- init_cjs_shims();
424
- cachedDataViewMemory0 = null;
425
- cachedUint8ArrayMemory0 = null;
426
- heap = new Array(1024).fill(void 0);
427
- heap.push(void 0, null, true, false);
428
- heap_next = heap.length;
429
- stack_pointer = 1024;
430
- cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
431
- cachedTextDecoder.decode();
432
- MAX_SAFARI_DECODE_BYTES = 2146435072;
433
- numBytesDecoded = 0;
434
- cachedTextEncoder = new TextEncoder();
435
- if (!("encodeInto" in cachedTextEncoder)) {
436
- cachedTextEncoder.encodeInto = function(arg, view) {
437
- const buf = cachedTextEncoder.encode(arg);
438
- view.set(buf);
439
- return {
440
- read: arg.length,
441
- written: buf.length
442
- };
443
- };
444
- }
445
- WASM_VECTOR_LEN = 0;
446
- }
447
- });
448
410
 
449
411
  // ../wasm/src/index.ts
412
+ var initPromise;
413
+ var overrideSource;
450
414
  function setWasmSource(source) {
451
415
  if (initPromise) {
452
416
  throw new Error(
@@ -513,78 +477,13 @@ function wasmPackageToMaps(raw) {
513
477
  warnings: Array.isArray(raw.warnings) ? [...raw.warnings] : []
514
478
  };
515
479
  }
516
- function mapsToWasmPackage(input) {
517
- const parts = {};
518
- for (const [name, part] of input.parts.entries()) {
519
- parts[name] = {
520
- name: part.name,
521
- content: part.content
522
- };
523
- }
524
- const binaryAssets = {};
525
- for (const [name, asset] of input.binaryAssets.entries()) {
526
- binaryAssets[name] = asset;
527
- }
528
- return {
529
- parts,
530
- binaryAssets,
531
- ...input.warnings && input.warnings.length > 0 ? { warnings: [...input.warnings] } : {}
532
- };
533
- }
534
- async function wasmParseDocx(bytes) {
480
+ async function wasmBuildDocModelFromBytes(bytes) {
535
481
  await initWasm();
536
482
  const payload = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
537
- return parse_docx_wasm(payload);
483
+ return build_doc_model_from_bytes(payload);
538
484
  }
539
- async function wasmBuildDocModelFromPackage(pkg) {
540
- await initWasm();
541
- const json = build_doc_model_from_package(pkg);
542
- return JSON.parse(json);
543
- }
544
- var initPromise, overrideSource;
545
- var init_src = __esm({
546
- "../wasm/src/index.ts"() {
547
- "use strict";
548
- init_cjs_shims();
549
- init_docx_wasm();
550
- }
551
- });
552
-
553
- // ../ooxml-core/src/index.ts
554
- async function parseDocx(input) {
555
- const wasmPackage = await wasmParseDocx(input);
556
- const { parts, binaryAssets, warnings } = wasmPackageToMaps(wasmPackage);
557
- return { parts, binaryAssets, ...warnings.length > 0 ? { warnings } : {} };
558
- }
559
- var WORD_MAIN_NS, DEFAULT_DOCUMENT_XML;
560
- var init_src2 = __esm({
561
- "../ooxml-core/src/index.ts"() {
562
- "use strict";
563
- init_cjs_shims();
564
- init_src();
565
- WORD_MAIN_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
566
- DEFAULT_DOCUMENT_XML = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
567
- <w:document xmlns:w="${WORD_MAIN_NS}">
568
- <w:body>
569
- <w:p><w:r><w:t/></w:r></w:p>
570
- <w:sectPr>
571
- <w:pgSz w:w="12240" w:h="15840"/>
572
- <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
573
- </w:sectPr>
574
- </w:body>
575
- </w:document>`;
576
- }
577
- });
578
-
579
- // src/docx-import-worker.ts
580
- init_cjs_shims();
581
-
582
- // ../doc-model/src/index.ts
583
- init_cjs_shims();
584
- init_src();
585
485
 
586
486
  // ../doc-model/src/normalize.ts
587
- init_cjs_shims();
588
487
  function normalizeUint8Array(value) {
589
488
  if (value instanceof Uint8Array) {
590
489
  return value;
@@ -672,32 +571,58 @@ function normalizeDocModel(model) {
672
571
  };
673
572
  }
674
573
 
675
- // ../doc-model/src/types.ts
676
- init_cjs_shims();
677
-
678
- // ../doc-model/src/block-id.ts
679
- init_cjs_shims();
680
-
681
- // ../doc-model/src/clone.ts
682
- init_cjs_shims();
683
-
684
- // ../doc-model/src/freeze.ts
685
- init_cjs_shims();
686
-
687
574
  // ../doc-model/src/index.ts
688
- async function buildDocModel(pkg) {
689
- const wasmPackage = mapsToWasmPackage({
690
- parts: pkg.parts,
691
- binaryAssets: pkg.binaryAssets,
692
- warnings: pkg.warnings
693
- });
694
- const model = await wasmBuildDocModelFromPackage(wasmPackage);
695
- return normalizeDocModel(model);
575
+ async function buildDocModelFromBytes(bytes) {
576
+ const startedAt = performance.now();
577
+ const result = await wasmBuildDocModelFromBytes(bytes);
578
+ const builtAt = performance.now();
579
+ const { parts, binaryAssets, warnings } = wasmPackageToMaps(result.package);
580
+ const pkg = { parts, binaryAssets, ...warnings.length > 0 ? { warnings } : {} };
581
+ const model = normalizeDocModel(result.model);
582
+ const finishedAt = performance.now();
583
+ const buildModelMs = result.timings.buildModelMs + finishedAt - builtAt;
584
+ return {
585
+ package: pkg,
586
+ model,
587
+ timings: {
588
+ parseMs: Math.max(0, builtAt - startedAt - result.timings.buildModelMs),
589
+ buildModelMs,
590
+ totalMs: finishedAt - startedAt
591
+ }
592
+ };
593
+ }
594
+
595
+ // src/import-transferables.ts
596
+ function collectImportTransferables(value) {
597
+ const buffers = /* @__PURE__ */ new Set();
598
+ const visited = /* @__PURE__ */ new Set();
599
+ const pending = [value];
600
+ while (pending.length > 0) {
601
+ const current = pending.pop();
602
+ if (!current || typeof current !== "object" || visited.has(current)) {
603
+ continue;
604
+ }
605
+ visited.add(current);
606
+ if (current instanceof ArrayBuffer) {
607
+ buffers.add(current);
608
+ } else if (ArrayBuffer.isView(current)) {
609
+ if (current.buffer instanceof ArrayBuffer) {
610
+ buffers.add(current.buffer);
611
+ }
612
+ } else if (current instanceof Map) {
613
+ for (const [key, entry] of current) {
614
+ pending.push(key, entry);
615
+ }
616
+ } else {
617
+ for (const entry of Object.values(current)) {
618
+ pending.push(entry);
619
+ }
620
+ }
621
+ }
622
+ return [...buffers];
696
623
  }
697
624
 
698
625
  // src/docx-import-worker.ts
699
- init_src2();
700
- init_src();
701
626
  function performanceNow() {
702
627
  return typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
703
628
  }
@@ -725,23 +650,23 @@ self.addEventListener(
725
650
  setWasmSource(request.wasmSource);
726
651
  }
727
652
  const startedAt = performanceNow();
728
- const pkg = await parseDocx(request.buffer);
729
- const parsedAt = performanceNow();
730
- const model = await buildDocModel(pkg);
653
+ const result = await buildDocModelFromBytes(request.buffer);
731
654
  const finishedAt = performanceNow();
732
655
  const timings = {
733
656
  totalMs: finishedAt - startedAt,
734
- parseMs: parsedAt - startedAt,
735
- buildModelMs: finishedAt - parsedAt
657
+ parseMs: result.timings.parseMs,
658
+ buildModelMs: result.timings.buildModelMs
736
659
  };
737
660
  const response = {
738
661
  id: request.id,
739
662
  type: "success",
740
- package: pkg,
741
- model,
663
+ package: result.package,
664
+ model: result.model,
742
665
  timings
743
666
  };
744
- self.postMessage(response);
667
+ self.postMessage(response, {
668
+ transfer: collectImportTransferables(response)
669
+ });
745
670
  } catch (error) {
746
671
  const response = {
747
672
  id: request.id,