@extend-ai/react-docx 0.7.0-alpha.4 → 0.7.0-alpha.5
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/dist/{chunk-XLGR633U.js → chunk-2SXGXGWO.js} +4 -64
- package/dist/chunk-2SXGXGWO.js.map +1 -0
- package/dist/chunk-P3B3Q7Y6.js +422 -0
- package/dist/chunk-P3B3Q7Y6.js.map +1 -0
- package/dist/chunk-QOXSE6WY.js +73 -0
- package/dist/chunk-QOXSE6WY.js.map +1 -0
- package/dist/docx-import-worker.cjs +710 -0
- package/dist/docx-import-worker.cjs.map +1 -0
- package/dist/docx-import-worker.d.cts +2 -0
- package/dist/docx-import-worker.d.ts +2 -0
- package/dist/docx-import-worker.js +61 -0
- package/dist/docx-import-worker.js.map +1 -0
- package/dist/docx_wasm_bg.wasm +0 -0
- package/dist/index.cjs +1196 -497
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +91 -2
- package/dist/index.d.ts +91 -2
- package/dist/index.js +886 -618
- package/dist/index.js.map +1 -1
- package/dist/src-NDPFDRVM.js +14 -0
- package/dist/{src-IT7QNDVM.js → src-PJYTN6DB.js} +3 -2
- package/dist/src-PJYTN6DB.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-XLGR633U.js.map +0 -1
- /package/dist/{src-IT7QNDVM.js.map → src-NDPFDRVM.js.map} +0 -0
|
@@ -0,0 +1,710 @@
|
|
|
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
|
+
|
|
7
|
+
// ../../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
|
+
});
|
|
16
|
+
|
|
17
|
+
// ../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) {
|
|
45
|
+
try {
|
|
46
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
47
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
|
|
48
|
+
const len0 = WASM_VECTOR_LEN;
|
|
49
|
+
wasm.parse_docx_wasm(retptr, ptr0, len0);
|
|
50
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
51
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
52
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
53
|
+
if (r2) {
|
|
54
|
+
throw takeObject(r1);
|
|
55
|
+
}
|
|
56
|
+
return takeObject(r0);
|
|
57
|
+
} finally {
|
|
58
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function __wbg_get_imports() {
|
|
62
|
+
const import0 = {
|
|
63
|
+
__proto__: null,
|
|
64
|
+
__wbg___wbindgen_debug_string_56c147eb1a51f0c4: function(arg0, arg1) {
|
|
65
|
+
const ret = debugString(getObject(arg1));
|
|
66
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
67
|
+
const len1 = WASM_VECTOR_LEN;
|
|
68
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
69
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
70
|
+
},
|
|
71
|
+
__wbg___wbindgen_is_null_ced4761460071341: function(arg0) {
|
|
72
|
+
const ret = getObject(arg0) === null;
|
|
73
|
+
return ret;
|
|
74
|
+
},
|
|
75
|
+
__wbg___wbindgen_is_object_3a2c414391dbf751: function(arg0) {
|
|
76
|
+
const val = getObject(arg0);
|
|
77
|
+
const ret = typeof val === "object" && val !== null;
|
|
78
|
+
return ret;
|
|
79
|
+
},
|
|
80
|
+
__wbg___wbindgen_is_undefined_4410e3c20a99fa97: function(arg0) {
|
|
81
|
+
const ret = getObject(arg0) === void 0;
|
|
82
|
+
return ret;
|
|
83
|
+
},
|
|
84
|
+
__wbg___wbindgen_string_get_fa2687d531ed17a5: function(arg0, arg1) {
|
|
85
|
+
const obj = getObject(arg1);
|
|
86
|
+
const ret = typeof obj === "string" ? obj : void 0;
|
|
87
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
88
|
+
var len1 = WASM_VECTOR_LEN;
|
|
89
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
90
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
91
|
+
},
|
|
92
|
+
__wbg___wbindgen_throw_bbadd78c1bac3a77: function(arg0, arg1) {
|
|
93
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
94
|
+
},
|
|
95
|
+
__wbg_create_00e11a7cefe80760: function(arg0) {
|
|
96
|
+
const ret = Object.create(getObject(arg0));
|
|
97
|
+
return addHeapObject(ret);
|
|
98
|
+
},
|
|
99
|
+
__wbg_get_52a8a619f7b88df6: function() {
|
|
100
|
+
return handleError(function(arg0, arg1) {
|
|
101
|
+
const ret = Reflect.get(getObject(arg0), getObject(arg1));
|
|
102
|
+
return addHeapObject(ret);
|
|
103
|
+
}, arguments);
|
|
104
|
+
},
|
|
105
|
+
__wbg_get_unchecked_46e778e3cec74b5e: function(arg0, arg1) {
|
|
106
|
+
const ret = getObject(arg0)[arg1 >>> 0];
|
|
107
|
+
return addHeapObject(ret);
|
|
108
|
+
},
|
|
109
|
+
__wbg_instanceof_ArrayBuffer_a581da923203f29f: function(arg0) {
|
|
110
|
+
let result;
|
|
111
|
+
try {
|
|
112
|
+
result = getObject(arg0) instanceof ArrayBuffer;
|
|
113
|
+
} catch (_) {
|
|
114
|
+
result = false;
|
|
115
|
+
}
|
|
116
|
+
const ret = result;
|
|
117
|
+
return ret;
|
|
118
|
+
},
|
|
119
|
+
__wbg_instanceof_Uint8Array_b6fe1ac89eba107e: function(arg0) {
|
|
120
|
+
let result;
|
|
121
|
+
try {
|
|
122
|
+
result = getObject(arg0) instanceof Uint8Array;
|
|
123
|
+
} catch (_) {
|
|
124
|
+
result = false;
|
|
125
|
+
}
|
|
126
|
+
const ret = result;
|
|
127
|
+
return ret;
|
|
128
|
+
},
|
|
129
|
+
__wbg_isArray_139f48e3c057ede8: function(arg0) {
|
|
130
|
+
const ret = Array.isArray(getObject(arg0));
|
|
131
|
+
return ret;
|
|
132
|
+
},
|
|
133
|
+
__wbg_keys_bd51ff67a9b04698: function(arg0) {
|
|
134
|
+
const ret = Object.keys(getObject(arg0));
|
|
135
|
+
return addHeapObject(ret);
|
|
136
|
+
},
|
|
137
|
+
__wbg_length_68a9d5278d084f4f: function(arg0) {
|
|
138
|
+
const ret = getObject(arg0).length;
|
|
139
|
+
return ret;
|
|
140
|
+
},
|
|
141
|
+
__wbg_length_fb04d16d7bdf6d4c: function(arg0) {
|
|
142
|
+
const ret = getObject(arg0).length;
|
|
143
|
+
return ret;
|
|
144
|
+
},
|
|
145
|
+
__wbg_new_20b778a4c5c691c3: function() {
|
|
146
|
+
const ret = new Object();
|
|
147
|
+
return addHeapObject(ret);
|
|
148
|
+
},
|
|
149
|
+
__wbg_new_b06772b280cc6e52: function(arg0) {
|
|
150
|
+
const ret = new Uint8Array(getObject(arg0));
|
|
151
|
+
return addHeapObject(ret);
|
|
152
|
+
},
|
|
153
|
+
__wbg_new_from_slice_bb2d1778c0b87eb1: function(arg0, arg1) {
|
|
154
|
+
const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
|
|
155
|
+
return addHeapObject(ret);
|
|
156
|
+
},
|
|
157
|
+
__wbg_parse_246201845d0eb98c: function() {
|
|
158
|
+
return handleError(function(arg0, arg1) {
|
|
159
|
+
const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
|
|
160
|
+
return addHeapObject(ret);
|
|
161
|
+
}, arguments);
|
|
162
|
+
},
|
|
163
|
+
__wbg_prototypesetcall_956c7493c68e29b4: function(arg0, arg1, arg2) {
|
|
164
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
|
|
165
|
+
},
|
|
166
|
+
__wbg_set_a6ba3ac0e634b822: function() {
|
|
167
|
+
return handleError(function(arg0, arg1, arg2) {
|
|
168
|
+
const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
|
|
169
|
+
return ret;
|
|
170
|
+
}, arguments);
|
|
171
|
+
},
|
|
172
|
+
__wbg_stringify_a42c95ea9a7591c9: function() {
|
|
173
|
+
return handleError(function(arg0) {
|
|
174
|
+
const ret = JSON.stringify(getObject(arg0));
|
|
175
|
+
return addHeapObject(ret);
|
|
176
|
+
}, arguments);
|
|
177
|
+
},
|
|
178
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
179
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
180
|
+
return addHeapObject(ret);
|
|
181
|
+
},
|
|
182
|
+
__wbindgen_object_drop_ref: function(arg0) {
|
|
183
|
+
takeObject(arg0);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
return {
|
|
187
|
+
__proto__: null,
|
|
188
|
+
"./docx_wasm_bg.js": import0
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function addHeapObject(obj) {
|
|
192
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
193
|
+
const idx = heap_next;
|
|
194
|
+
heap_next = heap[idx];
|
|
195
|
+
heap[idx] = obj;
|
|
196
|
+
return idx;
|
|
197
|
+
}
|
|
198
|
+
function addBorrowedObject(obj) {
|
|
199
|
+
if (stack_pointer == 1) throw new Error("out of js stack");
|
|
200
|
+
heap[--stack_pointer] = obj;
|
|
201
|
+
return stack_pointer;
|
|
202
|
+
}
|
|
203
|
+
function debugString(val) {
|
|
204
|
+
const type = typeof val;
|
|
205
|
+
if (type == "number" || type == "boolean" || val == null) {
|
|
206
|
+
return `${val}`;
|
|
207
|
+
}
|
|
208
|
+
if (type == "string") {
|
|
209
|
+
return `"${val}"`;
|
|
210
|
+
}
|
|
211
|
+
if (type == "symbol") {
|
|
212
|
+
const description = val.description;
|
|
213
|
+
if (description == null) {
|
|
214
|
+
return "Symbol";
|
|
215
|
+
} else {
|
|
216
|
+
return `Symbol(${description})`;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (type == "function") {
|
|
220
|
+
const name = val.name;
|
|
221
|
+
if (typeof name == "string" && name.length > 0) {
|
|
222
|
+
return `Function(${name})`;
|
|
223
|
+
} else {
|
|
224
|
+
return "Function";
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (Array.isArray(val)) {
|
|
228
|
+
const length = val.length;
|
|
229
|
+
let debug = "[";
|
|
230
|
+
if (length > 0) {
|
|
231
|
+
debug += debugString(val[0]);
|
|
232
|
+
}
|
|
233
|
+
for (let i = 1; i < length; i++) {
|
|
234
|
+
debug += ", " + debugString(val[i]);
|
|
235
|
+
}
|
|
236
|
+
debug += "]";
|
|
237
|
+
return debug;
|
|
238
|
+
}
|
|
239
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
240
|
+
let className;
|
|
241
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
242
|
+
className = builtInMatches[1];
|
|
243
|
+
} else {
|
|
244
|
+
return toString.call(val);
|
|
245
|
+
}
|
|
246
|
+
if (className == "Object") {
|
|
247
|
+
try {
|
|
248
|
+
return "Object(" + JSON.stringify(val) + ")";
|
|
249
|
+
} catch (_) {
|
|
250
|
+
return "Object";
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (val instanceof Error) {
|
|
254
|
+
return `${val.name}: ${val.message}
|
|
255
|
+
${val.stack}`;
|
|
256
|
+
}
|
|
257
|
+
return className;
|
|
258
|
+
}
|
|
259
|
+
function dropObject(idx) {
|
|
260
|
+
if (idx < 1028) return;
|
|
261
|
+
heap[idx] = heap_next;
|
|
262
|
+
heap_next = idx;
|
|
263
|
+
}
|
|
264
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
265
|
+
ptr = ptr >>> 0;
|
|
266
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
267
|
+
}
|
|
268
|
+
function getDataViewMemory0() {
|
|
269
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
|
|
270
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
271
|
+
}
|
|
272
|
+
return cachedDataViewMemory0;
|
|
273
|
+
}
|
|
274
|
+
function getStringFromWasm0(ptr, len) {
|
|
275
|
+
return decodeText(ptr >>> 0, len);
|
|
276
|
+
}
|
|
277
|
+
function getUint8ArrayMemory0() {
|
|
278
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
279
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
280
|
+
}
|
|
281
|
+
return cachedUint8ArrayMemory0;
|
|
282
|
+
}
|
|
283
|
+
function getObject(idx) {
|
|
284
|
+
return heap[idx];
|
|
285
|
+
}
|
|
286
|
+
function handleError(f, args) {
|
|
287
|
+
try {
|
|
288
|
+
return f.apply(this, args);
|
|
289
|
+
} catch (e) {
|
|
290
|
+
wasm.__wbindgen_export3(addHeapObject(e));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function isLikeNone(x) {
|
|
294
|
+
return x === void 0 || x === null;
|
|
295
|
+
}
|
|
296
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
297
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
298
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
299
|
+
WASM_VECTOR_LEN = arg.length;
|
|
300
|
+
return ptr;
|
|
301
|
+
}
|
|
302
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
303
|
+
if (realloc === void 0) {
|
|
304
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
305
|
+
const ptr2 = malloc(buf.length, 1) >>> 0;
|
|
306
|
+
getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
|
|
307
|
+
WASM_VECTOR_LEN = buf.length;
|
|
308
|
+
return ptr2;
|
|
309
|
+
}
|
|
310
|
+
let len = arg.length;
|
|
311
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
312
|
+
const mem = getUint8ArrayMemory0();
|
|
313
|
+
let offset = 0;
|
|
314
|
+
for (; offset < len; offset++) {
|
|
315
|
+
const code = arg.charCodeAt(offset);
|
|
316
|
+
if (code > 127) break;
|
|
317
|
+
mem[ptr + offset] = code;
|
|
318
|
+
}
|
|
319
|
+
if (offset !== len) {
|
|
320
|
+
if (offset !== 0) {
|
|
321
|
+
arg = arg.slice(offset);
|
|
322
|
+
}
|
|
323
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
324
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
325
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
326
|
+
offset += ret.written;
|
|
327
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
328
|
+
}
|
|
329
|
+
WASM_VECTOR_LEN = offset;
|
|
330
|
+
return ptr;
|
|
331
|
+
}
|
|
332
|
+
function takeObject(idx) {
|
|
333
|
+
const ret = getObject(idx);
|
|
334
|
+
dropObject(idx);
|
|
335
|
+
return ret;
|
|
336
|
+
}
|
|
337
|
+
function decodeText(ptr, len) {
|
|
338
|
+
numBytesDecoded += len;
|
|
339
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
340
|
+
cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
|
|
341
|
+
cachedTextDecoder.decode();
|
|
342
|
+
numBytesDecoded = len;
|
|
343
|
+
}
|
|
344
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
345
|
+
}
|
|
346
|
+
function __wbg_finalize_init(instance, module2) {
|
|
347
|
+
wasmInstance = instance;
|
|
348
|
+
wasm = instance.exports;
|
|
349
|
+
wasmModule = module2;
|
|
350
|
+
cachedDataViewMemory0 = null;
|
|
351
|
+
cachedUint8ArrayMemory0 = null;
|
|
352
|
+
return wasm;
|
|
353
|
+
}
|
|
354
|
+
async function __wbg_load(module2, imports) {
|
|
355
|
+
if (typeof Response === "function" && module2 instanceof Response) {
|
|
356
|
+
if (typeof WebAssembly.instantiateStreaming === "function") {
|
|
357
|
+
try {
|
|
358
|
+
return await WebAssembly.instantiateStreaming(module2, imports);
|
|
359
|
+
} catch (e) {
|
|
360
|
+
const validResponse = module2.ok && expectedResponseType(module2.type);
|
|
361
|
+
if (validResponse && module2.headers.get("Content-Type") !== "application/wasm") {
|
|
362
|
+
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);
|
|
363
|
+
} else {
|
|
364
|
+
throw e;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const bytes = await module2.arrayBuffer();
|
|
369
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
370
|
+
} else {
|
|
371
|
+
const instance = await WebAssembly.instantiate(module2, imports);
|
|
372
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
373
|
+
return { instance, module: module2 };
|
|
374
|
+
} else {
|
|
375
|
+
return instance;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
function expectedResponseType(type) {
|
|
379
|
+
switch (type) {
|
|
380
|
+
case "basic":
|
|
381
|
+
case "cors":
|
|
382
|
+
case "default":
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
async function __wbg_init(module_or_path) {
|
|
389
|
+
if (wasm !== void 0) return wasm;
|
|
390
|
+
if (module_or_path !== void 0) {
|
|
391
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
392
|
+
({ module_or_path } = module_or_path);
|
|
393
|
+
} else {
|
|
394
|
+
console.warn("using deprecated parameters for the initialization function; pass a single object instead");
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (module_or_path === void 0) {
|
|
398
|
+
module_or_path = new URL("docx_wasm_bg.wasm", importMetaUrl);
|
|
399
|
+
}
|
|
400
|
+
const imports = __wbg_get_imports();
|
|
401
|
+
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
|
|
402
|
+
module_or_path = fetch(module_or_path);
|
|
403
|
+
}
|
|
404
|
+
const { instance, module: module2 } = await __wbg_load(await module_or_path, imports);
|
|
405
|
+
return __wbg_finalize_init(instance, module2);
|
|
406
|
+
}
|
|
407
|
+
var cachedDataViewMemory0, cachedUint8ArrayMemory0, heap, heap_next, stack_pointer, cachedTextDecoder, MAX_SAFARI_DECODE_BYTES, numBytesDecoded, cachedTextEncoder, WASM_VECTOR_LEN, wasmModule, wasmInstance, wasm;
|
|
408
|
+
var init_docx_wasm = __esm({
|
|
409
|
+
"../wasm/src/generated/docx_wasm.js"() {
|
|
410
|
+
"use strict";
|
|
411
|
+
init_cjs_shims();
|
|
412
|
+
cachedDataViewMemory0 = null;
|
|
413
|
+
cachedUint8ArrayMemory0 = null;
|
|
414
|
+
heap = new Array(1024).fill(void 0);
|
|
415
|
+
heap.push(void 0, null, true, false);
|
|
416
|
+
heap_next = heap.length;
|
|
417
|
+
stack_pointer = 1024;
|
|
418
|
+
cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
|
|
419
|
+
cachedTextDecoder.decode();
|
|
420
|
+
MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
421
|
+
numBytesDecoded = 0;
|
|
422
|
+
cachedTextEncoder = new TextEncoder();
|
|
423
|
+
if (!("encodeInto" in cachedTextEncoder)) {
|
|
424
|
+
cachedTextEncoder.encodeInto = function(arg, view) {
|
|
425
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
426
|
+
view.set(buf);
|
|
427
|
+
return {
|
|
428
|
+
read: arg.length,
|
|
429
|
+
written: buf.length
|
|
430
|
+
};
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
WASM_VECTOR_LEN = 0;
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
// ../wasm/src/index.ts
|
|
438
|
+
async function nodeFsPromises() {
|
|
439
|
+
const proc = globalThis.process;
|
|
440
|
+
if (typeof proc?.getBuiltinModule === "function") {
|
|
441
|
+
return proc.getBuiltinModule("node:fs/promises");
|
|
442
|
+
}
|
|
443
|
+
const dynamicImport = new Function("specifier", "return import(specifier)");
|
|
444
|
+
return dynamicImport("node:fs/promises");
|
|
445
|
+
}
|
|
446
|
+
async function defaultWasmSource() {
|
|
447
|
+
const wasmUrl = new URL("./docx_wasm_bg.wasm", importMetaUrl);
|
|
448
|
+
if (wasmUrl.protocol === "file:") {
|
|
449
|
+
const fs = await nodeFsPromises();
|
|
450
|
+
return fs.readFile(wasmUrl);
|
|
451
|
+
}
|
|
452
|
+
return wasmUrl;
|
|
453
|
+
}
|
|
454
|
+
async function initWasm(source) {
|
|
455
|
+
if (!initPromise) {
|
|
456
|
+
const chosen = source ?? overrideSource;
|
|
457
|
+
initPromise = (chosen !== void 0 ? Promise.resolve(chosen) : defaultWasmSource()).then((module_or_path) => __wbg_init({ module_or_path })).catch((error) => {
|
|
458
|
+
if (error instanceof WebAssembly.CompileError) {
|
|
459
|
+
throw new Error(
|
|
460
|
+
`react-docx: the bundled WebAssembly binary failed to compile. It requires WebAssembly SIMD support (Chrome 91+, Firefox 89+, Safari 16.4+, Node 16.4+). Original error: ${error.message}`,
|
|
461
|
+
{ cause: error }
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
throw error;
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
return initPromise;
|
|
468
|
+
}
|
|
469
|
+
function toUint8Array(value) {
|
|
470
|
+
return value instanceof Uint8Array ? value : Uint8Array.from(value);
|
|
471
|
+
}
|
|
472
|
+
function wasmPackageToMaps(raw) {
|
|
473
|
+
const parts = /* @__PURE__ */ new Map();
|
|
474
|
+
for (const [name, part] of Object.entries(raw.parts ?? {})) {
|
|
475
|
+
parts.set(name, {
|
|
476
|
+
name: part.name ?? name,
|
|
477
|
+
content: part.content
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
const binaryAssets = /* @__PURE__ */ new Map();
|
|
481
|
+
for (const [name, asset] of Object.entries(raw.binaryAssets ?? {})) {
|
|
482
|
+
binaryAssets.set(name, toUint8Array(asset));
|
|
483
|
+
}
|
|
484
|
+
return { parts, binaryAssets };
|
|
485
|
+
}
|
|
486
|
+
function mapsToWasmPackage(input) {
|
|
487
|
+
const parts = {};
|
|
488
|
+
for (const [name, part] of input.parts.entries()) {
|
|
489
|
+
parts[name] = {
|
|
490
|
+
name: part.name,
|
|
491
|
+
content: part.content
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
const binaryAssets = {};
|
|
495
|
+
for (const [name, asset] of input.binaryAssets.entries()) {
|
|
496
|
+
binaryAssets[name] = asset;
|
|
497
|
+
}
|
|
498
|
+
return { parts, binaryAssets };
|
|
499
|
+
}
|
|
500
|
+
async function wasmParseDocx(bytes) {
|
|
501
|
+
await initWasm();
|
|
502
|
+
const payload = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
503
|
+
return parse_docx_wasm(payload);
|
|
504
|
+
}
|
|
505
|
+
async function wasmBuildDocModelFromPackage(pkg) {
|
|
506
|
+
await initWasm();
|
|
507
|
+
const json = build_doc_model_from_package(pkg);
|
|
508
|
+
return JSON.parse(json);
|
|
509
|
+
}
|
|
510
|
+
var initPromise, overrideSource;
|
|
511
|
+
var init_src = __esm({
|
|
512
|
+
"../wasm/src/index.ts"() {
|
|
513
|
+
"use strict";
|
|
514
|
+
init_cjs_shims();
|
|
515
|
+
init_docx_wasm();
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
// ../ooxml-core/src/index.ts
|
|
520
|
+
async function parseDocx(input) {
|
|
521
|
+
const wasmPackage = await wasmParseDocx(input);
|
|
522
|
+
const { parts, binaryAssets } = wasmPackageToMaps(wasmPackage);
|
|
523
|
+
return { parts, binaryAssets };
|
|
524
|
+
}
|
|
525
|
+
var WORD_MAIN_NS, DEFAULT_DOCUMENT_XML;
|
|
526
|
+
var init_src2 = __esm({
|
|
527
|
+
"../ooxml-core/src/index.ts"() {
|
|
528
|
+
"use strict";
|
|
529
|
+
init_cjs_shims();
|
|
530
|
+
init_src();
|
|
531
|
+
WORD_MAIN_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
532
|
+
DEFAULT_DOCUMENT_XML = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
533
|
+
<w:document xmlns:w="${WORD_MAIN_NS}">
|
|
534
|
+
<w:body>
|
|
535
|
+
<w:p><w:r><w:t/></w:r></w:p>
|
|
536
|
+
<w:sectPr>
|
|
537
|
+
<w:pgSz w:w="12240" w:h="15840"/>
|
|
538
|
+
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
|
|
539
|
+
</w:sectPr>
|
|
540
|
+
</w:body>
|
|
541
|
+
</w:document>`;
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
// src/docx-import-worker.ts
|
|
546
|
+
init_cjs_shims();
|
|
547
|
+
|
|
548
|
+
// ../doc-model/src/index.ts
|
|
549
|
+
init_cjs_shims();
|
|
550
|
+
init_src();
|
|
551
|
+
|
|
552
|
+
// ../doc-model/src/normalize.ts
|
|
553
|
+
init_cjs_shims();
|
|
554
|
+
function normalizeUint8Array(value) {
|
|
555
|
+
if (value instanceof Uint8Array) {
|
|
556
|
+
return value;
|
|
557
|
+
}
|
|
558
|
+
if (Array.isArray(value)) {
|
|
559
|
+
return Uint8Array.from(value);
|
|
560
|
+
}
|
|
561
|
+
return void 0;
|
|
562
|
+
}
|
|
563
|
+
function normalizeParagraphChild(child) {
|
|
564
|
+
if (child.type !== "image") {
|
|
565
|
+
return child;
|
|
566
|
+
}
|
|
567
|
+
const image = child;
|
|
568
|
+
const data = normalizeUint8Array(image.data);
|
|
569
|
+
if (data === image.data) {
|
|
570
|
+
return child;
|
|
571
|
+
}
|
|
572
|
+
return {
|
|
573
|
+
...image,
|
|
574
|
+
data
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
function normalizeTableCellContent(node) {
|
|
578
|
+
if (node.type === "table") {
|
|
579
|
+
return normalizeDocNode(node);
|
|
580
|
+
}
|
|
581
|
+
return {
|
|
582
|
+
...node,
|
|
583
|
+
children: node.children.map(normalizeParagraphChild)
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
function normalizeDocNode(node) {
|
|
587
|
+
if (node.type === "paragraph") {
|
|
588
|
+
return {
|
|
589
|
+
...node,
|
|
590
|
+
children: node.children.map(normalizeParagraphChild)
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
return {
|
|
594
|
+
...node,
|
|
595
|
+
rows: node.rows.map((row) => ({
|
|
596
|
+
...row,
|
|
597
|
+
cells: row.cells.map((cell) => ({
|
|
598
|
+
...cell,
|
|
599
|
+
nodes: cell.nodes.map(normalizeTableCellContent)
|
|
600
|
+
}))
|
|
601
|
+
}))
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
function normalizeDocModel(model) {
|
|
605
|
+
return {
|
|
606
|
+
...model,
|
|
607
|
+
nodes: model.nodes.map(normalizeDocNode),
|
|
608
|
+
metadata: {
|
|
609
|
+
...model.metadata,
|
|
610
|
+
headerSections: model.metadata.headerSections.map((section) => ({
|
|
611
|
+
...section,
|
|
612
|
+
nodes: section.nodes.map(normalizeDocNode)
|
|
613
|
+
})),
|
|
614
|
+
footerSections: model.metadata.footerSections.map((section) => ({
|
|
615
|
+
...section,
|
|
616
|
+
nodes: section.nodes.map(normalizeDocNode)
|
|
617
|
+
})),
|
|
618
|
+
sections: model.metadata.sections?.map((section) => ({
|
|
619
|
+
...section,
|
|
620
|
+
headerSections: section.headerSections.map((header) => ({
|
|
621
|
+
...header,
|
|
622
|
+
nodes: header.nodes.map(normalizeDocNode)
|
|
623
|
+
})),
|
|
624
|
+
footerSections: section.footerSections.map((footer) => ({
|
|
625
|
+
...footer,
|
|
626
|
+
nodes: footer.nodes.map(normalizeDocNode)
|
|
627
|
+
}))
|
|
628
|
+
})),
|
|
629
|
+
footnotes: model.metadata.footnotes?.map((note) => ({
|
|
630
|
+
...note,
|
|
631
|
+
nodes: note.nodes?.map(normalizeDocNode)
|
|
632
|
+
})),
|
|
633
|
+
endnotes: model.metadata.endnotes?.map((note) => ({
|
|
634
|
+
...note,
|
|
635
|
+
nodes: note.nodes?.map(normalizeDocNode)
|
|
636
|
+
}))
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// ../doc-model/src/types.ts
|
|
642
|
+
init_cjs_shims();
|
|
643
|
+
|
|
644
|
+
// ../doc-model/src/clone.ts
|
|
645
|
+
init_cjs_shims();
|
|
646
|
+
|
|
647
|
+
// ../doc-model/src/index.ts
|
|
648
|
+
async function buildDocModel(pkg) {
|
|
649
|
+
const wasmPackage = mapsToWasmPackage({
|
|
650
|
+
parts: pkg.parts,
|
|
651
|
+
binaryAssets: pkg.binaryAssets
|
|
652
|
+
});
|
|
653
|
+
const model = await wasmBuildDocModelFromPackage(wasmPackage);
|
|
654
|
+
return normalizeDocModel(model);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// src/docx-import-worker.ts
|
|
658
|
+
init_src2();
|
|
659
|
+
function performanceNow() {
|
|
660
|
+
return typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
|
|
661
|
+
}
|
|
662
|
+
function serializeError(error) {
|
|
663
|
+
if (error instanceof Error) {
|
|
664
|
+
return {
|
|
665
|
+
name: error.name,
|
|
666
|
+
message: error.message,
|
|
667
|
+
stack: error.stack
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
return {
|
|
671
|
+
message: String(error)
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
self.addEventListener(
|
|
675
|
+
"message",
|
|
676
|
+
async (event) => {
|
|
677
|
+
const request = event.data;
|
|
678
|
+
if (!request || request.type !== "import-docx") {
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
try {
|
|
682
|
+
const startedAt = performanceNow();
|
|
683
|
+
const pkg = await parseDocx(request.buffer);
|
|
684
|
+
const parsedAt = performanceNow();
|
|
685
|
+
const model = await buildDocModel(pkg);
|
|
686
|
+
const finishedAt = performanceNow();
|
|
687
|
+
const timings = {
|
|
688
|
+
totalMs: finishedAt - startedAt,
|
|
689
|
+
parseMs: parsedAt - startedAt,
|
|
690
|
+
buildModelMs: finishedAt - parsedAt
|
|
691
|
+
};
|
|
692
|
+
const response = {
|
|
693
|
+
id: request.id,
|
|
694
|
+
type: "success",
|
|
695
|
+
package: pkg,
|
|
696
|
+
model,
|
|
697
|
+
timings
|
|
698
|
+
};
|
|
699
|
+
self.postMessage(response);
|
|
700
|
+
} catch (error) {
|
|
701
|
+
const response = {
|
|
702
|
+
id: request.id,
|
|
703
|
+
type: "error",
|
|
704
|
+
error: serializeError(error)
|
|
705
|
+
};
|
|
706
|
+
self.postMessage(response);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
);
|
|
710
|
+
//# sourceMappingURL=docx-import-worker.cjs.map
|