oxidocs 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # oxidocs
2
+
3
+ A Word-compatible `.docx` layout and rendering engine, compiled to
4
+ WebAssembly — parse, lay out, edit and PDF-export Microsoft Word documents
5
+ entirely in the browser (or any JS runtime).
6
+
7
+ **Early development.** The API is 0.x and unstable; development happens in
8
+ the open at <https://gitlab.com/Ryujiyasu/oxi>. The engine core is also
9
+ published on crates.io as [`oxidocs`](https://crates.io/crates/oxidocs).
10
+
11
+ ## What it does
12
+
13
+ - Parses OOXML WordprocessingML (`.docx`) into a structured document model
14
+ - Lays out documents with a line/page model measured against Microsoft
15
+ Word's own rendering — including Japanese typography: kinsoku line
16
+ breaking, document grid (docGrid), ruby, vertical writing
17
+ - Edits text with incremental re-layout, and exports to PDF (embedded CJK
18
+ fonts included)
19
+
20
+ ## How fidelity is measured
21
+
22
+ Layout is verified continuously against Word as the oracle: per-paragraph
23
+ pagination equality (100% on the current 87-document corpus of real-world
24
+ Japanese government/legal documents) and per-page SSIM pixel comparison.
25
+
26
+ ## Usage
27
+
28
+ ```js
29
+ import init, { parse_document, layout_document, docx_to_pdf } from 'oxidocs';
30
+
31
+ await init();
32
+ const bytes = new Uint8Array(await file.arrayBuffer());
33
+ const doc = parse_document(bytes); // structured document model
34
+ const pages = layout_document(bytes); // laid-out pages (positions in pt)
35
+ const pdf = docx_to_pdf(bytes); // Uint8Array (PDF)
36
+ ```
37
+
38
+ ## License
39
+
40
+ MIT OR Apache-2.0 (bindings). The engine core is MPL-2.0.
@@ -0,0 +1,131 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Build a .docx from a content structure.
6
+ * `content`: JS array of block objects:
7
+ * { type: "paragraph", runs: [{text, bold?, italic?, underline?, strikethrough?, font_family?, font_size?, color?}], alignment?, heading_level?, line_height? }
8
+ * { type: "table", rows: [[{text, bold?}]] }
9
+ */
10
+ export function build_docx(content: any): Uint8Array;
11
+
12
+ /**
13
+ * Build a .docx from content, using a template docx for styles/theme/numbering.
14
+ * Preserves original formatting while replacing document content.
15
+ */
16
+ export function build_docx_with_template(content: any, template: Uint8Array): Uint8Array;
17
+
18
+ /**
19
+ * Create a blank .docx file and return it as bytes.
20
+ * Can be used to create a new document from scratch.
21
+ */
22
+ export function create_blank_docx(): Uint8Array;
23
+
24
+ /**
25
+ * Convert a .docx file to PDF bytes.
26
+ * Parses the docx, runs layout, and converts positioned elements to PDF.
27
+ */
28
+ export function docx_to_pdf(data: Uint8Array): Uint8Array;
29
+
30
+ /**
31
+ * Edit a .docx file and return the modified bytes.
32
+ *
33
+ * `data`: original .docx bytes
34
+ * `edits`: JS array of `{paragraph_index, run_index, new_text}` objects
35
+ *
36
+ * Returns the modified .docx as `Uint8Array`.
37
+ */
38
+ export function edit_docx(data: Uint8Array, edits: any): Uint8Array;
39
+
40
+ /**
41
+ * Apply structural edits to a .docx file.
42
+ *
43
+ * `data`: original .docx bytes
44
+ * `edits`: JS array of edit operation objects. Each object has a `type` field:
45
+ *
46
+ * Text operations:
47
+ * { type: "set_run_text", paragraph_index, run_index, new_text }
48
+ * { type: "insert_paragraph", index, text, style?, para_style? }
49
+ * { type: "delete_paragraph", index }
50
+ * { type: "insert_run", paragraph_index, run_index, text, style? }
51
+ * { type: "delete_run", paragraph_index, run_index }
52
+ *
53
+ * Formatting:
54
+ * { type: "set_run_format", paragraph_index, run_index, style }
55
+ * { type: "set_paragraph_format", paragraph_index, style }
56
+ *
57
+ * Tables:
58
+ * { type: "insert_table", index, rows, cols, content?, col_widths_pt? }
59
+ * { type: "insert_table_row", table_index, row_index, cells }
60
+ * { type: "delete_table_row", table_index, row_index }
61
+ * { type: "set_cell_text", table_index, row, col, text }
62
+ *
63
+ * Images:
64
+ * { type: "insert_image", index, data (base64), width_pt, height_pt, content_type }
65
+ *
66
+ * style (RunProps): { bold?, italic?, underline?, font_family?, font_size?, color?, highlight? }
67
+ * para_style (ParaProps): { alignment?, space_before?, space_after?, line_spacing?, indent_left?, style_id? }
68
+ */
69
+ export function edit_docx_advanced(data: Uint8Array, edits: any): Uint8Array;
70
+
71
+ /**
72
+ * Fast text edit + re-layout using cached document (skips docx parse).
73
+ * Returns layout result. Also updates the cached docx bytes.
74
+ */
75
+ export function edit_text_and_relayout(paragraph_index: number, run_index: number, new_text: string): any;
76
+
77
+ export function init(): void;
78
+
79
+ /**
80
+ * Load a document, cache it, and return layout result.
81
+ * Subsequent calls to `edit_text_and_relayout` will reuse the cached parse.
82
+ */
83
+ export function layout_document(data: Uint8Array): any;
84
+
85
+ export function parse_document(data: Uint8Array): any;
86
+
87
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
88
+
89
+ export interface InitOutput {
90
+ readonly memory: WebAssembly.Memory;
91
+ readonly build_docx: (a: any) => [number, number, number, number];
92
+ readonly build_docx_with_template: (a: any, b: number, c: number) => [number, number, number, number];
93
+ readonly create_blank_docx: () => [number, number];
94
+ readonly docx_to_pdf: (a: number, b: number) => [number, number, number, number];
95
+ readonly edit_docx: (a: number, b: number, c: any) => [number, number, number, number];
96
+ readonly edit_docx_advanced: (a: number, b: number, c: any) => [number, number, number, number];
97
+ readonly edit_text_and_relayout: (a: number, b: number, c: number, d: number) => [number, number, number];
98
+ readonly layout_document: (a: number, b: number) => [number, number, number];
99
+ readonly parse_document: (a: number, b: number) => [number, number, number];
100
+ readonly init: () => void;
101
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
102
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
103
+ readonly __wbindgen_exn_store: (a: number) => void;
104
+ readonly __externref_table_alloc: () => number;
105
+ readonly __wbindgen_externrefs: WebAssembly.Table;
106
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
107
+ readonly __externref_table_dealloc: (a: number) => void;
108
+ readonly __wbindgen_start: () => void;
109
+ }
110
+
111
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
112
+
113
+ /**
114
+ * Instantiates the given `module`, which can either be bytes or
115
+ * a precompiled `WebAssembly.Module`.
116
+ *
117
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
118
+ *
119
+ * @returns {InitOutput}
120
+ */
121
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
122
+
123
+ /**
124
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
125
+ * for everything else, calls `WebAssembly.instantiate` directly.
126
+ *
127
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
128
+ *
129
+ * @returns {Promise<InitOutput>}
130
+ */
131
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,718 @@
1
+ /* @ts-self-types="./oxidocs_wasm.d.ts" */
2
+
3
+ /**
4
+ * Build a .docx from a content structure.
5
+ * `content`: JS array of block objects:
6
+ * { type: "paragraph", runs: [{text, bold?, italic?, underline?, strikethrough?, font_family?, font_size?, color?}], alignment?, heading_level?, line_height? }
7
+ * { type: "table", rows: [[{text, bold?}]] }
8
+ * @param {any} content
9
+ * @returns {Uint8Array}
10
+ */
11
+ export function build_docx(content) {
12
+ const ret = wasm.build_docx(content);
13
+ if (ret[3]) {
14
+ throw takeFromExternrefTable0(ret[2]);
15
+ }
16
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
17
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
18
+ return v1;
19
+ }
20
+
21
+ /**
22
+ * Build a .docx from content, using a template docx for styles/theme/numbering.
23
+ * Preserves original formatting while replacing document content.
24
+ * @param {any} content
25
+ * @param {Uint8Array} template
26
+ * @returns {Uint8Array}
27
+ */
28
+ export function build_docx_with_template(content, template) {
29
+ const ptr0 = passArray8ToWasm0(template, wasm.__wbindgen_malloc);
30
+ const len0 = WASM_VECTOR_LEN;
31
+ const ret = wasm.build_docx_with_template(content, ptr0, len0);
32
+ if (ret[3]) {
33
+ throw takeFromExternrefTable0(ret[2]);
34
+ }
35
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
36
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
37
+ return v2;
38
+ }
39
+
40
+ /**
41
+ * Create a blank .docx file and return it as bytes.
42
+ * Can be used to create a new document from scratch.
43
+ * @returns {Uint8Array}
44
+ */
45
+ export function create_blank_docx() {
46
+ const ret = wasm.create_blank_docx();
47
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
48
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
49
+ return v1;
50
+ }
51
+
52
+ /**
53
+ * Convert a .docx file to PDF bytes.
54
+ * Parses the docx, runs layout, and converts positioned elements to PDF.
55
+ * @param {Uint8Array} data
56
+ * @returns {Uint8Array}
57
+ */
58
+ export function docx_to_pdf(data) {
59
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
60
+ const len0 = WASM_VECTOR_LEN;
61
+ const ret = wasm.docx_to_pdf(ptr0, len0);
62
+ if (ret[3]) {
63
+ throw takeFromExternrefTable0(ret[2]);
64
+ }
65
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
66
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
67
+ return v2;
68
+ }
69
+
70
+ /**
71
+ * Edit a .docx file and return the modified bytes.
72
+ *
73
+ * `data`: original .docx bytes
74
+ * `edits`: JS array of `{paragraph_index, run_index, new_text}` objects
75
+ *
76
+ * Returns the modified .docx as `Uint8Array`.
77
+ * @param {Uint8Array} data
78
+ * @param {any} edits
79
+ * @returns {Uint8Array}
80
+ */
81
+ export function edit_docx(data, edits) {
82
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
83
+ const len0 = WASM_VECTOR_LEN;
84
+ const ret = wasm.edit_docx(ptr0, len0, edits);
85
+ if (ret[3]) {
86
+ throw takeFromExternrefTable0(ret[2]);
87
+ }
88
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
89
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
90
+ return v2;
91
+ }
92
+
93
+ /**
94
+ * Apply structural edits to a .docx file.
95
+ *
96
+ * `data`: original .docx bytes
97
+ * `edits`: JS array of edit operation objects. Each object has a `type` field:
98
+ *
99
+ * Text operations:
100
+ * { type: "set_run_text", paragraph_index, run_index, new_text }
101
+ * { type: "insert_paragraph", index, text, style?, para_style? }
102
+ * { type: "delete_paragraph", index }
103
+ * { type: "insert_run", paragraph_index, run_index, text, style? }
104
+ * { type: "delete_run", paragraph_index, run_index }
105
+ *
106
+ * Formatting:
107
+ * { type: "set_run_format", paragraph_index, run_index, style }
108
+ * { type: "set_paragraph_format", paragraph_index, style }
109
+ *
110
+ * Tables:
111
+ * { type: "insert_table", index, rows, cols, content?, col_widths_pt? }
112
+ * { type: "insert_table_row", table_index, row_index, cells }
113
+ * { type: "delete_table_row", table_index, row_index }
114
+ * { type: "set_cell_text", table_index, row, col, text }
115
+ *
116
+ * Images:
117
+ * { type: "insert_image", index, data (base64), width_pt, height_pt, content_type }
118
+ *
119
+ * style (RunProps): { bold?, italic?, underline?, font_family?, font_size?, color?, highlight? }
120
+ * para_style (ParaProps): { alignment?, space_before?, space_after?, line_spacing?, indent_left?, style_id? }
121
+ * @param {Uint8Array} data
122
+ * @param {any} edits
123
+ * @returns {Uint8Array}
124
+ */
125
+ export function edit_docx_advanced(data, edits) {
126
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
127
+ const len0 = WASM_VECTOR_LEN;
128
+ const ret = wasm.edit_docx_advanced(ptr0, len0, edits);
129
+ if (ret[3]) {
130
+ throw takeFromExternrefTable0(ret[2]);
131
+ }
132
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
133
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
134
+ return v2;
135
+ }
136
+
137
+ /**
138
+ * Fast text edit + re-layout using cached document (skips docx parse).
139
+ * Returns layout result. Also updates the cached docx bytes.
140
+ * @param {number} paragraph_index
141
+ * @param {number} run_index
142
+ * @param {string} new_text
143
+ * @returns {any}
144
+ */
145
+ export function edit_text_and_relayout(paragraph_index, run_index, new_text) {
146
+ const ptr0 = passStringToWasm0(new_text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
147
+ const len0 = WASM_VECTOR_LEN;
148
+ const ret = wasm.edit_text_and_relayout(paragraph_index, run_index, ptr0, len0);
149
+ if (ret[2]) {
150
+ throw takeFromExternrefTable0(ret[1]);
151
+ }
152
+ return takeFromExternrefTable0(ret[0]);
153
+ }
154
+
155
+ export function init() {
156
+ wasm.init();
157
+ }
158
+
159
+ /**
160
+ * Load a document, cache it, and return layout result.
161
+ * Subsequent calls to `edit_text_and_relayout` will reuse the cached parse.
162
+ * @param {Uint8Array} data
163
+ * @returns {any}
164
+ */
165
+ export function layout_document(data) {
166
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
167
+ const len0 = WASM_VECTOR_LEN;
168
+ const ret = wasm.layout_document(ptr0, len0);
169
+ if (ret[2]) {
170
+ throw takeFromExternrefTable0(ret[1]);
171
+ }
172
+ return takeFromExternrefTable0(ret[0]);
173
+ }
174
+
175
+ /**
176
+ * @param {Uint8Array} data
177
+ * @returns {any}
178
+ */
179
+ export function parse_document(data) {
180
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
181
+ const len0 = WASM_VECTOR_LEN;
182
+ const ret = wasm.parse_document(ptr0, len0);
183
+ if (ret[2]) {
184
+ throw takeFromExternrefTable0(ret[1]);
185
+ }
186
+ return takeFromExternrefTable0(ret[0]);
187
+ }
188
+
189
+ function __wbg_get_imports() {
190
+ const import0 = {
191
+ __proto__: null,
192
+ __wbg_Error_83742b46f01ce22d: function(arg0, arg1) {
193
+ const ret = Error(getStringFromWasm0(arg0, arg1));
194
+ return ret;
195
+ },
196
+ __wbg_Number_a5a435bd7bbec835: function(arg0) {
197
+ const ret = Number(arg0);
198
+ return ret;
199
+ },
200
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
201
+ const ret = String(arg1);
202
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
203
+ const len1 = WASM_VECTOR_LEN;
204
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
205
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
206
+ },
207
+ __wbg___wbindgen_bigint_get_as_i64_447a76b5c6ef7bda: function(arg0, arg1) {
208
+ const v = arg1;
209
+ const ret = typeof(v) === 'bigint' ? v : undefined;
210
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
211
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
212
+ },
213
+ __wbg___wbindgen_boolean_get_c0f3f60bac5a78d1: function(arg0) {
214
+ const v = arg0;
215
+ const ret = typeof(v) === 'boolean' ? v : undefined;
216
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
217
+ },
218
+ __wbg___wbindgen_debug_string_5398f5bb970e0daa: function(arg0, arg1) {
219
+ const ret = debugString(arg1);
220
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
221
+ const len1 = WASM_VECTOR_LEN;
222
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
223
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
224
+ },
225
+ __wbg___wbindgen_in_41dbb8413020e076: function(arg0, arg1) {
226
+ const ret = arg0 in arg1;
227
+ return ret;
228
+ },
229
+ __wbg___wbindgen_is_bigint_e2141d4f045b7eda: function(arg0) {
230
+ const ret = typeof(arg0) === 'bigint';
231
+ return ret;
232
+ },
233
+ __wbg___wbindgen_is_function_3c846841762788c1: function(arg0) {
234
+ const ret = typeof(arg0) === 'function';
235
+ return ret;
236
+ },
237
+ __wbg___wbindgen_is_object_781bc9f159099513: function(arg0) {
238
+ const val = arg0;
239
+ const ret = typeof(val) === 'object' && val !== null;
240
+ return ret;
241
+ },
242
+ __wbg___wbindgen_is_string_7ef6b97b02428fae: function(arg0) {
243
+ const ret = typeof(arg0) === 'string';
244
+ return ret;
245
+ },
246
+ __wbg___wbindgen_is_undefined_52709e72fb9f179c: function(arg0) {
247
+ const ret = arg0 === undefined;
248
+ return ret;
249
+ },
250
+ __wbg___wbindgen_jsval_eq_ee31bfad3e536463: function(arg0, arg1) {
251
+ const ret = arg0 === arg1;
252
+ return ret;
253
+ },
254
+ __wbg___wbindgen_jsval_loose_eq_5bcc3bed3c69e72b: function(arg0, arg1) {
255
+ const ret = arg0 == arg1;
256
+ return ret;
257
+ },
258
+ __wbg___wbindgen_number_get_34bb9d9dcfa21373: function(arg0, arg1) {
259
+ const obj = arg1;
260
+ const ret = typeof(obj) === 'number' ? obj : undefined;
261
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
262
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
263
+ },
264
+ __wbg___wbindgen_string_get_395e606bd0ee4427: function(arg0, arg1) {
265
+ const obj = arg1;
266
+ const ret = typeof(obj) === 'string' ? obj : undefined;
267
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
268
+ var len1 = WASM_VECTOR_LEN;
269
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
270
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
271
+ },
272
+ __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
273
+ throw new Error(getStringFromWasm0(arg0, arg1));
274
+ },
275
+ __wbg_call_e133b57c9155d22c: function() { return handleError(function (arg0, arg1) {
276
+ const ret = arg0.call(arg1);
277
+ return ret;
278
+ }, arguments); },
279
+ __wbg_done_08ce71ee07e3bd17: function(arg0) {
280
+ const ret = arg0.done;
281
+ return ret;
282
+ },
283
+ __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
284
+ let deferred0_0;
285
+ let deferred0_1;
286
+ try {
287
+ deferred0_0 = arg0;
288
+ deferred0_1 = arg1;
289
+ console.error(getStringFromWasm0(arg0, arg1));
290
+ } finally {
291
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
292
+ }
293
+ },
294
+ __wbg_fromCodePoint_4a02c6dcced1d233: function() { return handleError(function (arg0) {
295
+ const ret = String.fromCodePoint(arg0 >>> 0);
296
+ return ret;
297
+ }, arguments); },
298
+ __wbg_get_326e41e095fb2575: function() { return handleError(function (arg0, arg1) {
299
+ const ret = Reflect.get(arg0, arg1);
300
+ return ret;
301
+ }, arguments); },
302
+ __wbg_get_unchecked_329cfe50afab7352: function(arg0, arg1) {
303
+ const ret = arg0[arg1 >>> 0];
304
+ return ret;
305
+ },
306
+ __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
307
+ const ret = arg0[arg1];
308
+ return ret;
309
+ },
310
+ __wbg_instanceof_ArrayBuffer_101e2bf31071a9f6: function(arg0) {
311
+ let result;
312
+ try {
313
+ result = arg0 instanceof ArrayBuffer;
314
+ } catch (_) {
315
+ result = false;
316
+ }
317
+ const ret = result;
318
+ return ret;
319
+ },
320
+ __wbg_instanceof_Uint8Array_740438561a5b956d: function(arg0) {
321
+ let result;
322
+ try {
323
+ result = arg0 instanceof Uint8Array;
324
+ } catch (_) {
325
+ result = false;
326
+ }
327
+ const ret = result;
328
+ return ret;
329
+ },
330
+ __wbg_isArray_33b91feb269ff46e: function(arg0) {
331
+ const ret = Array.isArray(arg0);
332
+ return ret;
333
+ },
334
+ __wbg_isSafeInteger_ecd6a7f9c3e053cd: function(arg0) {
335
+ const ret = Number.isSafeInteger(arg0);
336
+ return ret;
337
+ },
338
+ __wbg_iterator_d8f549ec8fb061b1: function() {
339
+ const ret = Symbol.iterator;
340
+ return ret;
341
+ },
342
+ __wbg_length_b3416cf66a5452c8: function(arg0) {
343
+ const ret = arg0.length;
344
+ return ret;
345
+ },
346
+ __wbg_length_ea16607d7b61445b: function(arg0) {
347
+ const ret = arg0.length;
348
+ return ret;
349
+ },
350
+ __wbg_new_227d7c05414eb861: function() {
351
+ const ret = new Error();
352
+ return ret;
353
+ },
354
+ __wbg_new_49d5571bd3f0c4d4: function() {
355
+ const ret = new Map();
356
+ return ret;
357
+ },
358
+ __wbg_new_5f486cdf45a04d78: function(arg0) {
359
+ const ret = new Uint8Array(arg0);
360
+ return ret;
361
+ },
362
+ __wbg_new_a70fbab9066b301f: function() {
363
+ const ret = new Array();
364
+ return ret;
365
+ },
366
+ __wbg_new_ab79df5bd7c26067: function() {
367
+ const ret = new Object();
368
+ return ret;
369
+ },
370
+ __wbg_next_11b99ee6237339e3: function() { return handleError(function (arg0) {
371
+ const ret = arg0.next();
372
+ return ret;
373
+ }, arguments); },
374
+ __wbg_next_e01a967809d1aa68: function(arg0) {
375
+ const ret = arg0.next;
376
+ return ret;
377
+ },
378
+ __wbg_prototypesetcall_d62e5099504357e6: function(arg0, arg1, arg2) {
379
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
380
+ },
381
+ __wbg_set_282384002438957f: function(arg0, arg1, arg2) {
382
+ arg0[arg1 >>> 0] = arg2;
383
+ },
384
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
385
+ arg0[arg1] = arg2;
386
+ },
387
+ __wbg_set_bf7251625df30a02: function(arg0, arg1, arg2) {
388
+ const ret = arg0.set(arg1, arg2);
389
+ return ret;
390
+ },
391
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
392
+ const ret = arg1.stack;
393
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
394
+ const len1 = WASM_VECTOR_LEN;
395
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
396
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
397
+ },
398
+ __wbg_value_21fc78aab0322612: function(arg0) {
399
+ const ret = arg0.value;
400
+ return ret;
401
+ },
402
+ __wbindgen_cast_0000000000000001: function(arg0) {
403
+ // Cast intrinsic for `F64 -> Externref`.
404
+ const ret = arg0;
405
+ return ret;
406
+ },
407
+ __wbindgen_cast_0000000000000002: function(arg0) {
408
+ // Cast intrinsic for `I64 -> Externref`.
409
+ const ret = arg0;
410
+ return ret;
411
+ },
412
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
413
+ // Cast intrinsic for `Ref(String) -> Externref`.
414
+ const ret = getStringFromWasm0(arg0, arg1);
415
+ return ret;
416
+ },
417
+ __wbindgen_cast_0000000000000004: function(arg0) {
418
+ // Cast intrinsic for `U64 -> Externref`.
419
+ const ret = BigInt.asUintN(64, arg0);
420
+ return ret;
421
+ },
422
+ __wbindgen_init_externref_table: function() {
423
+ const table = wasm.__wbindgen_externrefs;
424
+ const offset = table.grow(4);
425
+ table.set(0, undefined);
426
+ table.set(offset + 0, undefined);
427
+ table.set(offset + 1, null);
428
+ table.set(offset + 2, true);
429
+ table.set(offset + 3, false);
430
+ },
431
+ };
432
+ return {
433
+ __proto__: null,
434
+ "./oxidocs_wasm_bg.js": import0,
435
+ };
436
+ }
437
+
438
+ function addToExternrefTable0(obj) {
439
+ const idx = wasm.__externref_table_alloc();
440
+ wasm.__wbindgen_externrefs.set(idx, obj);
441
+ return idx;
442
+ }
443
+
444
+ function debugString(val) {
445
+ // primitive types
446
+ const type = typeof val;
447
+ if (type == 'number' || type == 'boolean' || val == null) {
448
+ return `${val}`;
449
+ }
450
+ if (type == 'string') {
451
+ return `"${val}"`;
452
+ }
453
+ if (type == 'symbol') {
454
+ const description = val.description;
455
+ if (description == null) {
456
+ return 'Symbol';
457
+ } else {
458
+ return `Symbol(${description})`;
459
+ }
460
+ }
461
+ if (type == 'function') {
462
+ const name = val.name;
463
+ if (typeof name == 'string' && name.length > 0) {
464
+ return `Function(${name})`;
465
+ } else {
466
+ return 'Function';
467
+ }
468
+ }
469
+ // objects
470
+ if (Array.isArray(val)) {
471
+ const length = val.length;
472
+ let debug = '[';
473
+ if (length > 0) {
474
+ debug += debugString(val[0]);
475
+ }
476
+ for(let i = 1; i < length; i++) {
477
+ debug += ', ' + debugString(val[i]);
478
+ }
479
+ debug += ']';
480
+ return debug;
481
+ }
482
+ // Test for built-in
483
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
484
+ let className;
485
+ if (builtInMatches && builtInMatches.length > 1) {
486
+ className = builtInMatches[1];
487
+ } else {
488
+ // Failed to match the standard '[object ClassName]'
489
+ return toString.call(val);
490
+ }
491
+ if (className == 'Object') {
492
+ // we're a user defined class or Object
493
+ // JSON.stringify avoids problems with cycles, and is generally much
494
+ // easier than looping through ownProperties of `val`.
495
+ try {
496
+ return 'Object(' + JSON.stringify(val) + ')';
497
+ } catch (_) {
498
+ return 'Object';
499
+ }
500
+ }
501
+ // errors
502
+ if (val instanceof Error) {
503
+ return `${val.name}: ${val.message}\n${val.stack}`;
504
+ }
505
+ // TODO we could test for more things here, like `Set`s and `Map`s.
506
+ return className;
507
+ }
508
+
509
+ function getArrayU8FromWasm0(ptr, len) {
510
+ ptr = ptr >>> 0;
511
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
512
+ }
513
+
514
+ let cachedDataViewMemory0 = null;
515
+ function getDataViewMemory0() {
516
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
517
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
518
+ }
519
+ return cachedDataViewMemory0;
520
+ }
521
+
522
+ function getStringFromWasm0(ptr, len) {
523
+ ptr = ptr >>> 0;
524
+ return decodeText(ptr, len);
525
+ }
526
+
527
+ let cachedUint8ArrayMemory0 = null;
528
+ function getUint8ArrayMemory0() {
529
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
530
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
531
+ }
532
+ return cachedUint8ArrayMemory0;
533
+ }
534
+
535
+ function handleError(f, args) {
536
+ try {
537
+ return f.apply(this, args);
538
+ } catch (e) {
539
+ const idx = addToExternrefTable0(e);
540
+ wasm.__wbindgen_exn_store(idx);
541
+ }
542
+ }
543
+
544
+ function isLikeNone(x) {
545
+ return x === undefined || x === null;
546
+ }
547
+
548
+ function passArray8ToWasm0(arg, malloc) {
549
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
550
+ getUint8ArrayMemory0().set(arg, ptr / 1);
551
+ WASM_VECTOR_LEN = arg.length;
552
+ return ptr;
553
+ }
554
+
555
+ function passStringToWasm0(arg, malloc, realloc) {
556
+ if (realloc === undefined) {
557
+ const buf = cachedTextEncoder.encode(arg);
558
+ const ptr = malloc(buf.length, 1) >>> 0;
559
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
560
+ WASM_VECTOR_LEN = buf.length;
561
+ return ptr;
562
+ }
563
+
564
+ let len = arg.length;
565
+ let ptr = malloc(len, 1) >>> 0;
566
+
567
+ const mem = getUint8ArrayMemory0();
568
+
569
+ let offset = 0;
570
+
571
+ for (; offset < len; offset++) {
572
+ const code = arg.charCodeAt(offset);
573
+ if (code > 0x7F) break;
574
+ mem[ptr + offset] = code;
575
+ }
576
+ if (offset !== len) {
577
+ if (offset !== 0) {
578
+ arg = arg.slice(offset);
579
+ }
580
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
581
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
582
+ const ret = cachedTextEncoder.encodeInto(arg, view);
583
+
584
+ offset += ret.written;
585
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
586
+ }
587
+
588
+ WASM_VECTOR_LEN = offset;
589
+ return ptr;
590
+ }
591
+
592
+ function takeFromExternrefTable0(idx) {
593
+ const value = wasm.__wbindgen_externrefs.get(idx);
594
+ wasm.__externref_table_dealloc(idx);
595
+ return value;
596
+ }
597
+
598
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
599
+ cachedTextDecoder.decode();
600
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
601
+ let numBytesDecoded = 0;
602
+ function decodeText(ptr, len) {
603
+ numBytesDecoded += len;
604
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
605
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
606
+ cachedTextDecoder.decode();
607
+ numBytesDecoded = len;
608
+ }
609
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
610
+ }
611
+
612
+ const cachedTextEncoder = new TextEncoder();
613
+
614
+ if (!('encodeInto' in cachedTextEncoder)) {
615
+ cachedTextEncoder.encodeInto = function (arg, view) {
616
+ const buf = cachedTextEncoder.encode(arg);
617
+ view.set(buf);
618
+ return {
619
+ read: arg.length,
620
+ written: buf.length
621
+ };
622
+ };
623
+ }
624
+
625
+ let WASM_VECTOR_LEN = 0;
626
+
627
+ let wasmModule, wasm;
628
+ function __wbg_finalize_init(instance, module) {
629
+ wasm = instance.exports;
630
+ wasmModule = module;
631
+ cachedDataViewMemory0 = null;
632
+ cachedUint8ArrayMemory0 = null;
633
+ wasm.__wbindgen_start();
634
+ return wasm;
635
+ }
636
+
637
+ async function __wbg_load(module, imports) {
638
+ if (typeof Response === 'function' && module instanceof Response) {
639
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
640
+ try {
641
+ return await WebAssembly.instantiateStreaming(module, imports);
642
+ } catch (e) {
643
+ const validResponse = module.ok && expectedResponseType(module.type);
644
+
645
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
646
+ 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);
647
+
648
+ } else { throw e; }
649
+ }
650
+ }
651
+
652
+ const bytes = await module.arrayBuffer();
653
+ return await WebAssembly.instantiate(bytes, imports);
654
+ } else {
655
+ const instance = await WebAssembly.instantiate(module, imports);
656
+
657
+ if (instance instanceof WebAssembly.Instance) {
658
+ return { instance, module };
659
+ } else {
660
+ return instance;
661
+ }
662
+ }
663
+
664
+ function expectedResponseType(type) {
665
+ switch (type) {
666
+ case 'basic': case 'cors': case 'default': return true;
667
+ }
668
+ return false;
669
+ }
670
+ }
671
+
672
+ function initSync(module) {
673
+ if (wasm !== undefined) return wasm;
674
+
675
+
676
+ if (module !== undefined) {
677
+ if (Object.getPrototypeOf(module) === Object.prototype) {
678
+ ({module} = module)
679
+ } else {
680
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
681
+ }
682
+ }
683
+
684
+ const imports = __wbg_get_imports();
685
+ if (!(module instanceof WebAssembly.Module)) {
686
+ module = new WebAssembly.Module(module);
687
+ }
688
+ const instance = new WebAssembly.Instance(module, imports);
689
+ return __wbg_finalize_init(instance, module);
690
+ }
691
+
692
+ async function __wbg_init(module_or_path) {
693
+ if (wasm !== undefined) return wasm;
694
+
695
+
696
+ if (module_or_path !== undefined) {
697
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
698
+ ({module_or_path} = module_or_path)
699
+ } else {
700
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
701
+ }
702
+ }
703
+
704
+ if (module_or_path === undefined) {
705
+ module_or_path = new URL('oxidocs_wasm_bg.wasm', import.meta.url);
706
+ }
707
+ const imports = __wbg_get_imports();
708
+
709
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
710
+ module_or_path = fetch(module_or_path);
711
+ }
712
+
713
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
714
+
715
+ return __wbg_finalize_init(instance, module);
716
+ }
717
+
718
+ export { initSync, __wbg_init as default };
Binary file
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "oxidocs",
3
+ "type": "module",
4
+ "description": "WebAssembly bindings for Oxidocs — Word-compatible .docx parsing, layout, rendering and PDF export",
5
+ "version": "0.1.0",
6
+ "license": "MIT OR Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://gitlab.com/Ryujiyasu/oxi.git"
10
+ },
11
+ "files": [
12
+ "oxidocs_wasm_bg.wasm",
13
+ "oxidocs_wasm.js",
14
+ "oxidocs_wasm.d.ts",
15
+ "README.md"
16
+ ],
17
+ "main": "oxidocs_wasm.js",
18
+ "types": "oxidocs_wasm.d.ts",
19
+ "sideEffects": [
20
+ "./snippets/*"
21
+ ],
22
+ "keywords": [
23
+ "docx",
24
+ "word",
25
+ "ooxml",
26
+ "layout",
27
+ "wasm",
28
+ "document",
29
+ "pdf"
30
+ ],
31
+ "homepage": "https://gitlab.com/Ryujiyasu/oxi"
32
+ }