@kakemono/wasm 0.0.0-stage → 0.22.3

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,509 @@
1
+ /* @ts-self-types="./kakemono_wasm.d.ts" */
2
+
3
+ /**
4
+ * A PDF, Word document, Excel workbook, EPUB book or web page, read and
5
+ * analysed once: every output written from it shares that analysis.
6
+ */
7
+ class Document {
8
+ static __wrap(ptr) {
9
+ const obj = Object.create(Document.prototype);
10
+ obj.__wbg_ptr = ptr;
11
+ DocumentFinalization.register(obj, obj.__wbg_ptr, obj);
12
+ return obj;
13
+ }
14
+ __destroy_into_raw() {
15
+ const ptr = this.__wbg_ptr;
16
+ this.__wbg_ptr = 0;
17
+ DocumentFinalization.unregister(this);
18
+ return ptr;
19
+ }
20
+ free() {
21
+ const ptr = this.__destroy_into_raw();
22
+ wasm.__wbg_document_free(ptr, 0);
23
+ }
24
+ /**
25
+ * The structure of the document (its blocks in reading order), as the
26
+ * command line's `--json` writes it.
27
+ * @returns {any}
28
+ */
29
+ analyze() {
30
+ const ret = wasm.document_analyze(this.__wbg_ptr);
31
+ if (ret[2]) {
32
+ throw takeFromExternrefTable0(ret[1]);
33
+ }
34
+ return takeFromExternrefTable0(ret[0]);
35
+ }
36
+ /**
37
+ * The input format: `'pdf'`, `'docx'`, `'doc'`, `'xlsx'`, `'epub'` or
38
+ * `'html'`.
39
+ * @returns {string}
40
+ */
41
+ get format() {
42
+ let deferred1_0;
43
+ let deferred1_1;
44
+ try {
45
+ const ret = wasm.document_format(this.__wbg_ptr);
46
+ deferred1_0 = ret[0];
47
+ deferred1_1 = ret[1];
48
+ return getStringFromWasm0(ret[0], ret[1]);
49
+ } finally {
50
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
51
+ }
52
+ }
53
+ /**
54
+ * Reads and analyses the bytes of a document (a PDF, a Word document,
55
+ * an Excel workbook, an EPUB book or a web page).
56
+ * @param {Uint8Array | number[]} data
57
+ * @param {OpenOptions} opts
58
+ * @returns {Document}
59
+ */
60
+ static fromBytes(data, opts) {
61
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
62
+ const len0 = WASM_VECTOR_LEN;
63
+ const ret = wasm.document_fromBytes(ptr0, len0, opts);
64
+ if (ret[2]) {
65
+ throw takeFromExternrefTable0(ret[1]);
66
+ }
67
+ return Document.__wrap(ret[0]);
68
+ }
69
+ /**
70
+ * The number of pages of a PDF (0 for the formats that have none).
71
+ * @returns {number}
72
+ */
73
+ get pageCount() {
74
+ const ret = wasm.document_pageCount(this.__wbg_ptr);
75
+ return ret >>> 0;
76
+ }
77
+ /**
78
+ * The title of the document, when it has one.
79
+ * @returns {string | undefined}
80
+ */
81
+ get title() {
82
+ const ret = wasm.document_title(this.__wbg_ptr);
83
+ let v1;
84
+ if (ret[0] !== 0) {
85
+ v1 = getStringFromWasm0(ret[0], ret[1]);
86
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
87
+ }
88
+ return v1;
89
+ }
90
+ /**
91
+ * Chunks for retrieval (RAG), cut at sentence ends and headed by their
92
+ * section.
93
+ * @param {ChunkOptions} opts
94
+ * @returns {Chunk[]}
95
+ */
96
+ toChunks(opts) {
97
+ const ret = wasm.document_toChunks(this.__wbg_ptr, opts);
98
+ if (ret[2]) {
99
+ throw takeFromExternrefTable0(ret[1]);
100
+ }
101
+ return takeFromExternrefTable0(ret[0]);
102
+ }
103
+ /**
104
+ * A Word document (`.docx`).
105
+ * @param {DocxOptions} opts
106
+ * @returns {BinaryOutput}
107
+ */
108
+ toDocx(opts) {
109
+ const ret = wasm.document_toDocx(this.__wbg_ptr, opts);
110
+ if (ret[2]) {
111
+ throw takeFromExternrefTable0(ret[1]);
112
+ }
113
+ return takeFromExternrefTable0(ret[0]);
114
+ }
115
+ /**
116
+ * An EPUB 3 book.
117
+ * @param {EpubOptions} opts
118
+ * @returns {BinaryOutput}
119
+ */
120
+ toEpub(opts) {
121
+ const ret = wasm.document_toEpub(this.__wbg_ptr, opts);
122
+ if (ret[2]) {
123
+ throw takeFromExternrefTable0(ret[1]);
124
+ }
125
+ return takeFromExternrefTable0(ret[0]);
126
+ }
127
+ /**
128
+ * An HTML page; its pictures are inline unless `inlineImages` is false.
129
+ * @param {HtmlOptions} opts
130
+ * @returns {TextOutput}
131
+ */
132
+ toHtml(opts) {
133
+ const ret = wasm.document_toHtml(this.__wbg_ptr, opts);
134
+ if (ret[2]) {
135
+ throw takeFromExternrefTable0(ret[1]);
136
+ }
137
+ return takeFromExternrefTable0(ret[0]);
138
+ }
139
+ /**
140
+ * The editable JSON and its picture files.
141
+ * @param {JsonOptions} opts
142
+ * @returns {TextOutput}
143
+ */
144
+ toJson(opts) {
145
+ const ret = wasm.document_toJson(this.__wbg_ptr, opts);
146
+ if (ret[2]) {
147
+ throw takeFromExternrefTable0(ret[1]);
148
+ }
149
+ return takeFromExternrefTable0(ret[0]);
150
+ }
151
+ /**
152
+ * LaTeX source and its picture files.
153
+ * @param {LatexOptions} opts
154
+ * @returns {TextOutput}
155
+ */
156
+ toLatex(opts) {
157
+ const ret = wasm.document_toLatex(this.__wbg_ptr, opts);
158
+ if (ret[2]) {
159
+ throw takeFromExternrefTable0(ret[1]);
160
+ }
161
+ return takeFromExternrefTable0(ret[0]);
162
+ }
163
+ /**
164
+ * Markdown and its picture files.
165
+ * @param {MarkdownOptions} opts
166
+ * @returns {TextOutput}
167
+ */
168
+ toMarkdown(opts) {
169
+ const ret = wasm.document_toMarkdown(this.__wbg_ptr, opts);
170
+ if (ret[2]) {
171
+ throw takeFromExternrefTable0(ret[1]);
172
+ }
173
+ return takeFromExternrefTable0(ret[0]);
174
+ }
175
+ /**
176
+ * A Word document, workbook or EPUB book laid out in pages, as a PDF.
177
+ * @returns {BinaryOutput}
178
+ */
179
+ toPdf() {
180
+ const ret = wasm.document_toPdf(this.__wbg_ptr);
181
+ if (ret[2]) {
182
+ throw takeFromExternrefTable0(ret[1]);
183
+ }
184
+ return takeFromExternrefTable0(ret[0]);
185
+ }
186
+ /**
187
+ * Typst source and its picture files.
188
+ * @param {TypstOptions} opts
189
+ * @returns {TextOutput}
190
+ */
191
+ toTypst(opts) {
192
+ const ret = wasm.document_toTypst(this.__wbg_ptr, opts);
193
+ if (ret[2]) {
194
+ throw takeFromExternrefTable0(ret[1]);
195
+ }
196
+ return takeFromExternrefTable0(ret[0]);
197
+ }
198
+ /**
199
+ * The warnings of applying `content`: blocks that kept their own text.
200
+ * @returns {string[]}
201
+ */
202
+ get warnings() {
203
+ const ret = wasm.document_warnings(this.__wbg_ptr);
204
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]);
205
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
206
+ return v1;
207
+ }
208
+ }
209
+ if (Symbol.dispose) Document.prototype[Symbol.dispose] = Document.prototype.free;
210
+ exports.Document = Document;
211
+
212
+ /**
213
+ * Adds a TrueType or OpenType font (or a collection) to those documents
214
+ * are laid out and SVG text drawn with: WebAssembly has no installed
215
+ * fonts, and laying out a Word document or a workbook as a PDF needs one.
216
+ * Returns its number of faces.
217
+ * @param {Uint8Array | number[]} data
218
+ * @returns {number}
219
+ */
220
+ function addFont(data) {
221
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
222
+ const len0 = WASM_VECTOR_LEN;
223
+ const ret = wasm.addFont(ptr0, len0);
224
+ if (ret[2]) {
225
+ throw takeFromExternrefTable0(ret[1]);
226
+ }
227
+ return ret[0] >>> 0;
228
+ }
229
+ exports.addFont = addFont;
230
+
231
+ /**
232
+ * Logs a panic's message to `console.error` before the module aborts.
233
+ */
234
+ function start() {
235
+ wasm.start();
236
+ }
237
+ exports.start = start;
238
+
239
+ /**
240
+ * The version of kakemono.
241
+ * @returns {string}
242
+ */
243
+ function version() {
244
+ let deferred1_0;
245
+ let deferred1_1;
246
+ try {
247
+ const ret = wasm.version();
248
+ deferred1_0 = ret[0];
249
+ deferred1_1 = ret[1];
250
+ return getStringFromWasm0(ret[0], ret[1]);
251
+ } finally {
252
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
253
+ }
254
+ }
255
+ exports.version = version;
256
+ function __wbg_get_imports() {
257
+ const import0 = {
258
+ __proto__: null,
259
+ __wbg___wbindgen_is_null_c22311b1cc228e3a: function(arg0) {
260
+ const ret = arg0 === null;
261
+ return ret;
262
+ },
263
+ __wbg___wbindgen_is_object_8b968c3ab8e96595: function(arg0) {
264
+ const val = arg0;
265
+ const ret = typeof(val) === 'object' && val !== null;
266
+ return ret;
267
+ },
268
+ __wbg___wbindgen_is_undefined_be5b34249ff1fc15: function(arg0) {
269
+ const ret = arg0 === undefined;
270
+ return ret;
271
+ },
272
+ __wbg___wbindgen_string_get_7ce8eee7fd327545: function(arg0, arg1) {
273
+ const obj = arg1;
274
+ const ret = typeof(obj) === 'string' ? obj : undefined;
275
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
276
+ var len1 = WASM_VECTOR_LEN;
277
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 1, len1, true);
278
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 0, ptr1, true);
279
+ },
280
+ __wbg___wbindgen_throw_4c88d8bf264fd984: function(arg0, arg1) {
281
+ throw new Error(getStringFromWasm0(arg0, arg1));
282
+ },
283
+ __wbg_assign_6b6bb30388088072: function(arg0, arg1) {
284
+ const ret = Object.assign(arg0, arg1);
285
+ return ret;
286
+ },
287
+ __wbg_error_757e9472f8410341: function(arg0, arg1) {
288
+ let deferred0_0;
289
+ let deferred0_1;
290
+ try {
291
+ deferred0_0 = arg0;
292
+ deferred0_1 = arg1;
293
+ console.error(getStringFromWasm0(arg0, arg1));
294
+ } finally {
295
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
296
+ }
297
+ },
298
+ __wbg_get_2080c49015e35254: function() { return handleError(function (arg0, arg1) {
299
+ const ret = Reflect.get(arg0, arg1);
300
+ return ret;
301
+ }, arguments); },
302
+ __wbg_new_37eb45aaf5eeb820: function() {
303
+ const ret = new Array();
304
+ return ret;
305
+ },
306
+ __wbg_new_787b9fb330d55d78: function(arg0, arg1) {
307
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
308
+ return ret;
309
+ },
310
+ __wbg_new_bb74001155cb8ca8: function() {
311
+ const ret = new Error();
312
+ return ret;
313
+ },
314
+ __wbg_new_cd4348290afae586: function() {
315
+ const ret = new Object();
316
+ return ret;
317
+ },
318
+ __wbg_new_from_slice_b8daf545a41c6aa0: function(arg0, arg1) {
319
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
320
+ return ret;
321
+ },
322
+ __wbg_parse_c3f72b5a24f83c01: function() { return handleError(function (arg0, arg1) {
323
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
324
+ return ret;
325
+ }, arguments); },
326
+ __wbg_push_c9f4893fc209f768: function(arg0, arg1) {
327
+ const ret = arg0.push(arg1);
328
+ return ret;
329
+ },
330
+ __wbg_set_2793479888329cb6: function() { return handleError(function (arg0, arg1, arg2) {
331
+ const ret = Reflect.set(arg0, arg1, arg2);
332
+ return ret;
333
+ }, arguments); },
334
+ __wbg_set_name_822e3903f3184979: function(arg0, arg1, arg2) {
335
+ arg0.name = getStringFromWasm0(arg1, arg2);
336
+ },
337
+ __wbg_stack_575c4e0918581b9c: function(arg0, arg1) {
338
+ const ret = arg1.stack;
339
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
340
+ const len1 = WASM_VECTOR_LEN;
341
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 1, len1, true);
342
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 0, ptr1, true);
343
+ },
344
+ __wbg_stringify_0a0fbf2ef722380a: function() { return handleError(function (arg0) {
345
+ const ret = JSON.stringify(arg0);
346
+ return ret;
347
+ }, arguments); },
348
+ __wbindgen_generic_0000000000000001: function(arg0) {
349
+ // Cast intrinsic for `F64 -> Externref`.
350
+ const ret = arg0;
351
+ return ret;
352
+ },
353
+ __wbindgen_generic_0000000000000002: function(arg0, arg1) {
354
+ // Cast intrinsic for `Ref(String) -> Externref`.
355
+ const ret = getStringFromWasm0(arg0, arg1);
356
+ return ret;
357
+ },
358
+ __wbindgen_init_externref_table: function() {
359
+ const table = wasm.__wbindgen_externrefs;
360
+ table.set(0, undefined);
361
+ table.set(1024, undefined);
362
+ table.set(1025, null);
363
+ table.set(1026, true);
364
+ table.set(1027, false);
365
+ },
366
+ };
367
+ return {
368
+ __proto__: null,
369
+ "./kakemono_wasm_bg.js": import0,
370
+ };
371
+ }
372
+
373
+ const DocumentFinalization = (typeof FinalizationRegistry === 'undefined')
374
+ ? { register: () => {}, unregister: () => {} }
375
+ : new FinalizationRegistry(ptr => wasm.__wbg_document_free(ptr, 1));
376
+
377
+ function addToExternrefTable0(obj) {
378
+ const idx = wasm.__externref_table_alloc();
379
+ wasm.__wbindgen_externrefs.set(idx, obj);
380
+ return idx;
381
+ }
382
+
383
+ function getArrayJsValueFromWasm0(ptr, len) {
384
+ ptr = ptr >>> 0;
385
+ const mem = getDataViewMemory0();
386
+ const result = [];
387
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
388
+ result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
389
+ }
390
+ wasm.__externref_drop_slice(ptr, len);
391
+ return result;
392
+ }
393
+
394
+ function getArrayU8FromWasm0(ptr, len) {
395
+ ptr = ptr >>> 0;
396
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
397
+ }
398
+
399
+ let cachedDataViewMemory0 = null;
400
+ function getDataViewMemory0() {
401
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
402
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
403
+ }
404
+ return cachedDataViewMemory0;
405
+ }
406
+
407
+ function getStringFromWasm0(ptr, len) {
408
+ ptr = ptr >>> 0;
409
+ return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
410
+ }
411
+
412
+ let cachedUint8ArrayMemory0 = null;
413
+ function getUint8ArrayMemory0() {
414
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
415
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
416
+ }
417
+ return cachedUint8ArrayMemory0;
418
+ }
419
+
420
+ function handleError(f, args) {
421
+ try {
422
+ return f.apply(this, args);
423
+ } catch (e) {
424
+ const idx = addToExternrefTable0(e);
425
+ wasm.__wbindgen_exn_store(idx);
426
+ }
427
+ }
428
+
429
+ function isLikeNone(x) {
430
+ return x === undefined || x === null;
431
+ }
432
+
433
+ function passArray8ToWasm0(arg, malloc) {
434
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
435
+ getUint8ArrayMemory0().set(arg, ptr / 1);
436
+ WASM_VECTOR_LEN = arg.length;
437
+ return ptr;
438
+ }
439
+
440
+ function passStringToWasm0(arg, malloc, realloc) {
441
+ if (realloc === undefined) {
442
+ const buf = cachedTextEncoder.encode(arg);
443
+ const ptr = malloc(buf.length, 1) >>> 0;
444
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
445
+ WASM_VECTOR_LEN = buf.length;
446
+ return ptr;
447
+ }
448
+
449
+ let len = arg.length;
450
+ let ptr = malloc(len, 1) >>> 0;
451
+
452
+ const mem = getUint8ArrayMemory0();
453
+
454
+ let offset = 0;
455
+
456
+ for (; offset < len; offset++) {
457
+ const code = arg.charCodeAt(offset);
458
+ if (code > 0x7F) break;
459
+ mem[ptr + offset] = code;
460
+ }
461
+ if (offset !== len) {
462
+ if (offset !== 0) {
463
+ arg = arg.slice(offset);
464
+ }
465
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
466
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
467
+ const ret = cachedTextEncoder.encodeInto(arg, view);
468
+
469
+ offset += ret.written;
470
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
471
+ }
472
+
473
+ WASM_VECTOR_LEN = offset;
474
+ return ptr;
475
+ }
476
+
477
+ function takeFromExternrefTable0(idx) {
478
+ const value = wasm.__wbindgen_externrefs.get(idx);
479
+ wasm.__externref_table_dealloc(idx);
480
+ return value;
481
+ }
482
+
483
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
484
+ cachedTextDecoder.decode();
485
+ function decodeText(bytes) {
486
+ return cachedTextDecoder.decode(bytes);
487
+ }
488
+
489
+ const cachedTextEncoder = new TextEncoder();
490
+
491
+ if (!('encodeInto' in cachedTextEncoder)) {
492
+ cachedTextEncoder.encodeInto = function (arg, view) {
493
+ const buf = cachedTextEncoder.encode(arg);
494
+ view.set(buf);
495
+ return {
496
+ read: arg.length,
497
+ written: buf.length
498
+ };
499
+ };
500
+ }
501
+
502
+ let WASM_VECTOR_LEN = 0;
503
+
504
+ const wasmPath = `${__dirname}/kakemono_wasm_bg.wasm`;
505
+ const wasmBytes = require('fs').readFileSync(wasmPath);
506
+ const wasmModule = new WebAssembly.Module(wasmBytes);
507
+ let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
508
+ let wasm = wasmInstance.exports;
509
+ wasm.__wbindgen_start();
Binary file
@@ -0,0 +1,31 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_document_free: (a: number, b: number) => void;
5
+ export const addFont: (a: number, b: number) => [number, number, number];
6
+ export const document_analyze: (a: number) => [number, number, number];
7
+ export const document_format: (a: number) => [number, number];
8
+ export const document_fromBytes: (a: number, b: number, c: any) => [number, number, number];
9
+ export const document_pageCount: (a: number) => number;
10
+ export const document_title: (a: number) => [number, number];
11
+ export const document_toChunks: (a: number, b: any) => [number, number, number];
12
+ export const document_toDocx: (a: number, b: any) => [number, number, number];
13
+ export const document_toEpub: (a: number, b: any) => [number, number, number];
14
+ export const document_toHtml: (a: number, b: any) => [number, number, number];
15
+ export const document_toJson: (a: number, b: any) => [number, number, number];
16
+ export const document_toLatex: (a: number, b: any) => [number, number, number];
17
+ export const document_toMarkdown: (a: number, b: any) => [number, number, number];
18
+ export const document_toPdf: (a: number) => [number, number, number];
19
+ export const document_toTypst: (a: number, b: any) => [number, number, number];
20
+ export const document_warnings: (a: number) => [number, number];
21
+ export const start: () => void;
22
+ export const version: () => [number, number];
23
+ export const __wbindgen_malloc: (a: number, b: number) => number;
24
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
25
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
26
+ export const __wbindgen_exn_store: (a: number) => void;
27
+ export const __externref_table_alloc: () => number;
28
+ export const __wbindgen_externrefs: WebAssembly.Table;
29
+ export const __externref_table_dealloc: (a: number) => void;
30
+ export const __externref_drop_slice: (a: number, b: number) => void;
31
+ export const __wbindgen_start: () => void;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}