office-oxide-wasm 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.
@@ -0,0 +1,14 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_wasmdocument_free: (a: number, b: number) => void;
5
+ export const wasmdocument_formatName: (a: number, b: number) => void;
6
+ export const wasmdocument_new: (a: number, b: number, c: number, d: number, e: number) => void;
7
+ export const wasmdocument_plainText: (a: number, b: number) => void;
8
+ export const wasmdocument_toHtml: (a: number, b: number) => void;
9
+ export const wasmdocument_toIr: (a: number, b: number) => void;
10
+ export const wasmdocument_toMarkdown: (a: number, b: number) => void;
11
+ export const __wbindgen_export: (a: number, b: number) => number;
12
+ export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
13
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
14
+ export const __wbindgen_export3: (a: number, b: number, c: number) => void;
@@ -0,0 +1,34 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * A parsed Office document for use in JavaScript/WASM.
6
+ */
7
+ export class WasmDocument {
8
+ free(): void;
9
+ [Symbol.dispose](): void;
10
+ /**
11
+ * Return the format name: "docx", "xlsx", or "pptx".
12
+ */
13
+ formatName(): string;
14
+ /**
15
+ * Create a new document from raw bytes and a format string ("docx", "xlsx", "pptx").
16
+ */
17
+ constructor(data: Uint8Array, format: string);
18
+ /**
19
+ * Extract plain text from the document.
20
+ */
21
+ plainText(): string;
22
+ /**
23
+ * Convert the document to an HTML fragment.
24
+ */
25
+ toHtml(): string;
26
+ /**
27
+ * Convert the document to a JSON IR representation.
28
+ */
29
+ toIr(): any;
30
+ /**
31
+ * Convert the document to markdown.
32
+ */
33
+ toMarkdown(): string;
34
+ }
@@ -0,0 +1,318 @@
1
+ /* @ts-self-types="./office_oxide.d.ts" */
2
+
3
+ /**
4
+ * A parsed Office document for use in JavaScript/WASM.
5
+ */
6
+ class WasmDocument {
7
+ __destroy_into_raw() {
8
+ const ptr = this.__wbg_ptr;
9
+ this.__wbg_ptr = 0;
10
+ WasmDocumentFinalization.unregister(this);
11
+ return ptr;
12
+ }
13
+ free() {
14
+ const ptr = this.__destroy_into_raw();
15
+ wasm.__wbg_wasmdocument_free(ptr, 0);
16
+ }
17
+ /**
18
+ * Return the format name: "docx", "xlsx", or "pptx".
19
+ * @returns {string}
20
+ */
21
+ formatName() {
22
+ let deferred1_0;
23
+ let deferred1_1;
24
+ try {
25
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
26
+ wasm.wasmdocument_formatName(retptr, this.__wbg_ptr);
27
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
28
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
29
+ deferred1_0 = r0;
30
+ deferred1_1 = r1;
31
+ return getStringFromWasm0(r0, r1);
32
+ } finally {
33
+ wasm.__wbindgen_add_to_stack_pointer(16);
34
+ wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
35
+ }
36
+ }
37
+ /**
38
+ * Create a new document from raw bytes and a format string ("docx", "xlsx", "pptx").
39
+ * @param {Uint8Array} data
40
+ * @param {string} format
41
+ */
42
+ constructor(data, format) {
43
+ try {
44
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
45
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
46
+ const len0 = WASM_VECTOR_LEN;
47
+ const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export, wasm.__wbindgen_export2);
48
+ const len1 = WASM_VECTOR_LEN;
49
+ wasm.wasmdocument_new(retptr, ptr0, len0, ptr1, len1);
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
+ this.__wbg_ptr = r0 >>> 0;
57
+ WasmDocumentFinalization.register(this, this.__wbg_ptr, this);
58
+ return this;
59
+ } finally {
60
+ wasm.__wbindgen_add_to_stack_pointer(16);
61
+ }
62
+ }
63
+ /**
64
+ * Extract plain text from the document.
65
+ * @returns {string}
66
+ */
67
+ plainText() {
68
+ let deferred1_0;
69
+ let deferred1_1;
70
+ try {
71
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
72
+ wasm.wasmdocument_plainText(retptr, this.__wbg_ptr);
73
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
74
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
75
+ deferred1_0 = r0;
76
+ deferred1_1 = r1;
77
+ return getStringFromWasm0(r0, r1);
78
+ } finally {
79
+ wasm.__wbindgen_add_to_stack_pointer(16);
80
+ wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
81
+ }
82
+ }
83
+ /**
84
+ * Convert the document to an HTML fragment.
85
+ * @returns {string}
86
+ */
87
+ toHtml() {
88
+ let deferred1_0;
89
+ let deferred1_1;
90
+ try {
91
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
92
+ wasm.wasmdocument_toHtml(retptr, this.__wbg_ptr);
93
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
94
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
95
+ deferred1_0 = r0;
96
+ deferred1_1 = r1;
97
+ return getStringFromWasm0(r0, r1);
98
+ } finally {
99
+ wasm.__wbindgen_add_to_stack_pointer(16);
100
+ wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
101
+ }
102
+ }
103
+ /**
104
+ * Convert the document to a JSON IR representation.
105
+ * @returns {any}
106
+ */
107
+ toIr() {
108
+ try {
109
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
110
+ wasm.wasmdocument_toIr(retptr, this.__wbg_ptr);
111
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
112
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
113
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
114
+ if (r2) {
115
+ throw takeObject(r1);
116
+ }
117
+ return takeObject(r0);
118
+ } finally {
119
+ wasm.__wbindgen_add_to_stack_pointer(16);
120
+ }
121
+ }
122
+ /**
123
+ * Convert the document to markdown.
124
+ * @returns {string}
125
+ */
126
+ toMarkdown() {
127
+ let deferred1_0;
128
+ let deferred1_1;
129
+ try {
130
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
131
+ wasm.wasmdocument_toMarkdown(retptr, this.__wbg_ptr);
132
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
133
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
134
+ deferred1_0 = r0;
135
+ deferred1_1 = r1;
136
+ return getStringFromWasm0(r0, r1);
137
+ } finally {
138
+ wasm.__wbindgen_add_to_stack_pointer(16);
139
+ wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
140
+ }
141
+ }
142
+ }
143
+ if (Symbol.dispose) WasmDocument.prototype[Symbol.dispose] = WasmDocument.prototype.free;
144
+ exports.WasmDocument = WasmDocument;
145
+
146
+ function __wbg_get_imports() {
147
+ const import0 = {
148
+ __proto__: null,
149
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
150
+ const ret = String(getObject(arg1));
151
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
152
+ const len1 = WASM_VECTOR_LEN;
153
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
154
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
155
+ },
156
+ __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
157
+ throw new Error(getStringFromWasm0(arg0, arg1));
158
+ },
159
+ __wbg_new_a70fbab9066b301f: function() {
160
+ const ret = new Array();
161
+ return addHeapObject(ret);
162
+ },
163
+ __wbg_new_ab79df5bd7c26067: function() {
164
+ const ret = new Object();
165
+ return addHeapObject(ret);
166
+ },
167
+ __wbg_set_282384002438957f: function(arg0, arg1, arg2) {
168
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
169
+ },
170
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
171
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
172
+ },
173
+ __wbindgen_cast_0000000000000001: function(arg0) {
174
+ // Cast intrinsic for `F64 -> Externref`.
175
+ const ret = arg0;
176
+ return addHeapObject(ret);
177
+ },
178
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
179
+ // Cast intrinsic for `Ref(String) -> Externref`.
180
+ const ret = getStringFromWasm0(arg0, arg1);
181
+ return addHeapObject(ret);
182
+ },
183
+ __wbindgen_object_clone_ref: function(arg0) {
184
+ const ret = getObject(arg0);
185
+ return addHeapObject(ret);
186
+ },
187
+ __wbindgen_object_drop_ref: function(arg0) {
188
+ takeObject(arg0);
189
+ },
190
+ };
191
+ return {
192
+ __proto__: null,
193
+ "./office_oxide_bg.js": import0,
194
+ };
195
+ }
196
+
197
+ const WasmDocumentFinalization = (typeof FinalizationRegistry === 'undefined')
198
+ ? { register: () => {}, unregister: () => {} }
199
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmdocument_free(ptr >>> 0, 1));
200
+
201
+ function addHeapObject(obj) {
202
+ if (heap_next === heap.length) heap.push(heap.length + 1);
203
+ const idx = heap_next;
204
+ heap_next = heap[idx];
205
+
206
+ heap[idx] = obj;
207
+ return idx;
208
+ }
209
+
210
+ function dropObject(idx) {
211
+ if (idx < 1028) return;
212
+ heap[idx] = heap_next;
213
+ heap_next = idx;
214
+ }
215
+
216
+ let cachedDataViewMemory0 = null;
217
+ function getDataViewMemory0() {
218
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
219
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
220
+ }
221
+ return cachedDataViewMemory0;
222
+ }
223
+
224
+ function getStringFromWasm0(ptr, len) {
225
+ ptr = ptr >>> 0;
226
+ return decodeText(ptr, len);
227
+ }
228
+
229
+ let cachedUint8ArrayMemory0 = null;
230
+ function getUint8ArrayMemory0() {
231
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
232
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
233
+ }
234
+ return cachedUint8ArrayMemory0;
235
+ }
236
+
237
+ function getObject(idx) { return heap[idx]; }
238
+
239
+ let heap = new Array(1024).fill(undefined);
240
+ heap.push(undefined, null, true, false);
241
+
242
+ let heap_next = heap.length;
243
+
244
+ function passArray8ToWasm0(arg, malloc) {
245
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
246
+ getUint8ArrayMemory0().set(arg, ptr / 1);
247
+ WASM_VECTOR_LEN = arg.length;
248
+ return ptr;
249
+ }
250
+
251
+ function passStringToWasm0(arg, malloc, realloc) {
252
+ if (realloc === undefined) {
253
+ const buf = cachedTextEncoder.encode(arg);
254
+ const ptr = malloc(buf.length, 1) >>> 0;
255
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
256
+ WASM_VECTOR_LEN = buf.length;
257
+ return ptr;
258
+ }
259
+
260
+ let len = arg.length;
261
+ let ptr = malloc(len, 1) >>> 0;
262
+
263
+ const mem = getUint8ArrayMemory0();
264
+
265
+ let offset = 0;
266
+
267
+ for (; offset < len; offset++) {
268
+ const code = arg.charCodeAt(offset);
269
+ if (code > 0x7F) break;
270
+ mem[ptr + offset] = code;
271
+ }
272
+ if (offset !== len) {
273
+ if (offset !== 0) {
274
+ arg = arg.slice(offset);
275
+ }
276
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
277
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
278
+ const ret = cachedTextEncoder.encodeInto(arg, view);
279
+
280
+ offset += ret.written;
281
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
282
+ }
283
+
284
+ WASM_VECTOR_LEN = offset;
285
+ return ptr;
286
+ }
287
+
288
+ function takeObject(idx) {
289
+ const ret = getObject(idx);
290
+ dropObject(idx);
291
+ return ret;
292
+ }
293
+
294
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
295
+ cachedTextDecoder.decode();
296
+ function decodeText(ptr, len) {
297
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
298
+ }
299
+
300
+ const cachedTextEncoder = new TextEncoder();
301
+
302
+ if (!('encodeInto' in cachedTextEncoder)) {
303
+ cachedTextEncoder.encodeInto = function (arg, view) {
304
+ const buf = cachedTextEncoder.encode(arg);
305
+ view.set(buf);
306
+ return {
307
+ read: arg.length,
308
+ written: buf.length
309
+ };
310
+ };
311
+ }
312
+
313
+ let WASM_VECTOR_LEN = 0;
314
+
315
+ const wasmPath = `${__dirname}/office_oxide_bg.wasm`;
316
+ const wasmBytes = require('fs').readFileSync(wasmPath);
317
+ const wasmModule = new WebAssembly.Module(wasmBytes);
318
+ let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
Binary file
@@ -0,0 +1,14 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_wasmdocument_free: (a: number, b: number) => void;
5
+ export const wasmdocument_formatName: (a: number, b: number) => void;
6
+ export const wasmdocument_new: (a: number, b: number, c: number, d: number, e: number) => void;
7
+ export const wasmdocument_plainText: (a: number, b: number) => void;
8
+ export const wasmdocument_toHtml: (a: number, b: number) => void;
9
+ export const wasmdocument_toIr: (a: number, b: number) => void;
10
+ export const wasmdocument_toMarkdown: (a: number, b: number) => void;
11
+ export const __wbindgen_export: (a: number, b: number) => number;
12
+ export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
13
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
14
+ export const __wbindgen_export3: (a: number, b: number, c: number) => void;
package/package.json ADDED
@@ -0,0 +1,95 @@
1
+ {
2
+ "name": "office-oxide-wasm",
3
+ "version": "0.1.0",
4
+ "description": "Fast Office document processing (DOCX/XLSX/PPTX/DOC/XLS/PPT) compiled to WebAssembly. Rust core, zero JS dependencies. Works in Node.js, bundlers, and browsers.",
5
+ "license": "MIT OR Apache-2.0",
6
+ "author": "Yury Fedoseev",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/yfedoseev/office_oxide.git"
10
+ },
11
+ "homepage": "https://oxide.fyi",
12
+ "bugs": {
13
+ "url": "https://github.com/yfedoseev/office_oxide/issues"
14
+ },
15
+ "engines": {
16
+ "node": ">=18"
17
+ },
18
+ "type": "module",
19
+ "main": "./node/office_oxide.js",
20
+ "module": "./bundler/office_oxide.js",
21
+ "browser": "./web/office_oxide.js",
22
+ "types": "./bundler/office_oxide.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./bundler/office_oxide.d.ts",
26
+ "node": {
27
+ "require": "./node/office_oxide.js",
28
+ "default": "./node/office_oxide.js"
29
+ },
30
+ "browser": {
31
+ "import": "./web/office_oxide.js",
32
+ "default": "./web/office_oxide.js"
33
+ },
34
+ "import": "./bundler/office_oxide.js",
35
+ "default": "./bundler/office_oxide.js"
36
+ },
37
+ "./node": {
38
+ "types": "./node/office_oxide.d.ts",
39
+ "default": "./node/office_oxide.js"
40
+ },
41
+ "./web": {
42
+ "types": "./web/office_oxide.d.ts",
43
+ "default": "./web/office_oxide.js"
44
+ },
45
+ "./bundler": {
46
+ "types": "./bundler/office_oxide.d.ts",
47
+ "default": "./bundler/office_oxide.js"
48
+ },
49
+ "./package.json": "./package.json"
50
+ },
51
+ "sideEffects": [
52
+ "./web/office_oxide.js",
53
+ "./bundler/office_oxide.js"
54
+ ],
55
+ "files": [
56
+ "node/office_oxide.js",
57
+ "node/office_oxide.d.ts",
58
+ "node/office_oxide_bg.wasm",
59
+ "node/office_oxide_bg.wasm.d.ts",
60
+ "bundler/office_oxide.js",
61
+ "bundler/office_oxide_bg.js",
62
+ "bundler/office_oxide.d.ts",
63
+ "bundler/office_oxide_bg.wasm",
64
+ "bundler/office_oxide_bg.wasm.d.ts",
65
+ "web/office_oxide.js",
66
+ "web/office_oxide.d.ts",
67
+ "web/office_oxide_bg.wasm",
68
+ "web/office_oxide_bg.wasm.d.ts",
69
+ "README.md",
70
+ "LICENSE-MIT",
71
+ "LICENSE-APACHE"
72
+ ],
73
+ "keywords": [
74
+ "docx",
75
+ "xlsx",
76
+ "pptx",
77
+ "doc",
78
+ "xls",
79
+ "ppt",
80
+ "office",
81
+ "wasm",
82
+ "webassembly",
83
+ "text-extraction",
84
+ "document-parser",
85
+ "rust",
86
+ "rust-wasm",
87
+ "serverless",
88
+ "node",
89
+ "browser",
90
+ "zero-dependency",
91
+ "typescript",
92
+ "esm",
93
+ "cjs"
94
+ ]
95
+ }
@@ -0,0 +1,73 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * A parsed Office document for use in JavaScript/WASM.
6
+ */
7
+ export class WasmDocument {
8
+ free(): void;
9
+ [Symbol.dispose](): void;
10
+ /**
11
+ * Return the format name: "docx", "xlsx", or "pptx".
12
+ */
13
+ formatName(): string;
14
+ /**
15
+ * Create a new document from raw bytes and a format string ("docx", "xlsx", "pptx").
16
+ */
17
+ constructor(data: Uint8Array, format: string);
18
+ /**
19
+ * Extract plain text from the document.
20
+ */
21
+ plainText(): string;
22
+ /**
23
+ * Convert the document to an HTML fragment.
24
+ */
25
+ toHtml(): string;
26
+ /**
27
+ * Convert the document to a JSON IR representation.
28
+ */
29
+ toIr(): any;
30
+ /**
31
+ * Convert the document to markdown.
32
+ */
33
+ toMarkdown(): string;
34
+ }
35
+
36
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
37
+
38
+ export interface InitOutput {
39
+ readonly memory: WebAssembly.Memory;
40
+ readonly __wbg_wasmdocument_free: (a: number, b: number) => void;
41
+ readonly wasmdocument_formatName: (a: number, b: number) => void;
42
+ readonly wasmdocument_new: (a: number, b: number, c: number, d: number, e: number) => void;
43
+ readonly wasmdocument_plainText: (a: number, b: number) => void;
44
+ readonly wasmdocument_toHtml: (a: number, b: number) => void;
45
+ readonly wasmdocument_toIr: (a: number, b: number) => void;
46
+ readonly wasmdocument_toMarkdown: (a: number, b: number) => void;
47
+ readonly __wbindgen_export: (a: number, b: number) => number;
48
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
49
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
50
+ readonly __wbindgen_export3: (a: number, b: number, c: number) => void;
51
+ }
52
+
53
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
54
+
55
+ /**
56
+ * Instantiates the given `module`, which can either be bytes or
57
+ * a precompiled `WebAssembly.Module`.
58
+ *
59
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
60
+ *
61
+ * @returns {InitOutput}
62
+ */
63
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
64
+
65
+ /**
66
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
67
+ * for everything else, calls `WebAssembly.instantiate` directly.
68
+ *
69
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
70
+ *
71
+ * @returns {Promise<InitOutput>}
72
+ */
73
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;