@laminapdf/wasm 0.2.0-alpha.3 → 0.2.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/lamina_pdf_base.d.ts +3 -2
- package/dist/lamina_pdf_base.js +2 -1
- package/dist/lamina_pdf_base.wasm +0 -0
- package/dist/lamina_pdf_extract.d.ts +539 -2
- package/dist/lamina_pdf_extract.js +218 -1
- package/dist/lamina_pdf_extract.wasm +0 -0
- package/dist/lamina_pdf_render_hayro.d.ts +7 -4
- package/dist/lamina_pdf_render_hayro.js +10 -4
- package/dist/lamina_pdf_render_hayro.wasm +0 -0
- package/dist/lamina_pdf_text.d.ts +542 -3
- package/dist/lamina_pdf_text.js +190 -1
- package/dist/lamina_pdf_text.wasm +0 -0
- package/package.json +1 -1
package/dist/lamina_pdf_text.js
CHANGED
|
@@ -278,6 +278,25 @@ export class WasmDocument {
|
|
|
278
278
|
}
|
|
279
279
|
return takeFromExternrefTable0(ret[0]);
|
|
280
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* An extraction stepped a page at a time, whose models the host runs: each step returns
|
|
283
|
+
* its progress, with the result it waits for under `request` (render that page at `dpi`,
|
|
284
|
+
* run the model, hand the result to `provide`), and once every page is done, the output in
|
|
285
|
+
* `options.format` (the extract and text modules).
|
|
286
|
+
*
|
|
287
|
+
* # Errors
|
|
288
|
+
* As `extract`, for the options and the pages asked for.
|
|
289
|
+
* @param {ExtractInit} options
|
|
290
|
+
* @returns {WasmExtractJob}
|
|
291
|
+
*/
|
|
292
|
+
extractJob(options) {
|
|
293
|
+
let ret;
|
|
294
|
+
ret = wasm.wasmdocument_extractJob(this.__wbg_ptr, options);
|
|
295
|
+
if (ret[2]) {
|
|
296
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
297
|
+
}
|
|
298
|
+
return WasmExtractJob.__wrap(ret[0]);
|
|
299
|
+
}
|
|
281
300
|
/**
|
|
282
301
|
* The document's text for retrieval and LLMs, as one string: Markdown, plain text, the
|
|
283
302
|
* `laminapdf.extract/1` JSON, or the chunks as a JSON array (the extract and text modules).
|
|
@@ -331,6 +350,40 @@ export class WasmDocument {
|
|
|
331
350
|
}
|
|
332
351
|
return takeFromExternrefTable0(ret[0]);
|
|
333
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* Whether the document says it is tagged (`/MarkInfo /Marked true`; the extract and text modules).
|
|
355
|
+
*
|
|
356
|
+
* # Errors
|
|
357
|
+
* Reading errors.
|
|
358
|
+
* @returns {boolean}
|
|
359
|
+
*/
|
|
360
|
+
isTagged() {
|
|
361
|
+
let ret;
|
|
362
|
+
ret = wasm.wasmdocument_isTagged(this.__wbg_ptr);
|
|
363
|
+
if (ret[2]) {
|
|
364
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
365
|
+
}
|
|
366
|
+
return ret[0] !== 0;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* The named destination `name`, or `undefined` when the document has none by that name or
|
|
370
|
+
* it names no page here (the extract and text modules).
|
|
371
|
+
*
|
|
372
|
+
* # Errors
|
|
373
|
+
* `data-pending` and the reading errors.
|
|
374
|
+
* @param {string} name
|
|
375
|
+
* @returns {TargetJs | undefined}
|
|
376
|
+
*/
|
|
377
|
+
namedDestination(name) {
|
|
378
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
379
|
+
const len0 = WASM_VECTOR_LEN;
|
|
380
|
+
let ret;
|
|
381
|
+
ret = wasm.wasmdocument_namedDestination(this.__wbg_ptr, ptr0, len0);
|
|
382
|
+
if (ret[2]) {
|
|
383
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
384
|
+
}
|
|
385
|
+
return takeFromExternrefTable0(ret[0]);
|
|
386
|
+
}
|
|
334
387
|
/**
|
|
335
388
|
* Opens a document from its bytes.
|
|
336
389
|
*
|
|
@@ -371,6 +424,22 @@ export class WasmDocument {
|
|
|
371
424
|
}
|
|
372
425
|
return WasmDocument.__wrap(ret[0]);
|
|
373
426
|
}
|
|
427
|
+
/**
|
|
428
|
+
* The outline's top-level items, each with its children; empty without an outline (the
|
|
429
|
+
* extract and text modules).
|
|
430
|
+
*
|
|
431
|
+
* # Errors
|
|
432
|
+
* `data-pending` and the reading errors.
|
|
433
|
+
* @returns {OutlineNodeJs[]}
|
|
434
|
+
*/
|
|
435
|
+
outline() {
|
|
436
|
+
let ret;
|
|
437
|
+
ret = wasm.wasmdocument_outline(this.__wbg_ptr);
|
|
438
|
+
if (ret[2]) {
|
|
439
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
440
|
+
}
|
|
441
|
+
return takeFromExternrefTable0(ret[0]);
|
|
442
|
+
}
|
|
374
443
|
/**
|
|
375
444
|
* A handle on the page with `id` (`p12.0`).
|
|
376
445
|
*
|
|
@@ -435,6 +504,22 @@ export class WasmDocument {
|
|
|
435
504
|
}
|
|
436
505
|
return takeFromExternrefTable0(ret[0]);
|
|
437
506
|
}
|
|
507
|
+
/**
|
|
508
|
+
* The visible links on page `index`, in annotation order (the extract and text modules).
|
|
509
|
+
*
|
|
510
|
+
* # Errors
|
|
511
|
+
* `page-index-out-of-range`, `data-pending` and the reading errors.
|
|
512
|
+
* @param {number} index
|
|
513
|
+
* @returns {PageLinkJs[]}
|
|
514
|
+
*/
|
|
515
|
+
pageLinks(index) {
|
|
516
|
+
let ret;
|
|
517
|
+
ret = wasm.wasmdocument_pageLinks(this.__wbg_ptr, index);
|
|
518
|
+
if (ret[2]) {
|
|
519
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
520
|
+
}
|
|
521
|
+
return takeFromExternrefTable0(ret[0]);
|
|
522
|
+
}
|
|
438
523
|
/**
|
|
439
524
|
* A handle on page `index` that follows the page by its ID (F2).
|
|
440
525
|
*
|
|
@@ -451,6 +536,21 @@ export class WasmDocument {
|
|
|
451
536
|
}
|
|
452
537
|
return WasmPage.__wrap(ret[0]);
|
|
453
538
|
}
|
|
539
|
+
/**
|
|
540
|
+
* The document's properties (the extract and text modules). Reads every object once.
|
|
541
|
+
*
|
|
542
|
+
* # Errors
|
|
543
|
+
* `data-pending` and the reading errors.
|
|
544
|
+
* @returns {PropertiesJs}
|
|
545
|
+
*/
|
|
546
|
+
properties() {
|
|
547
|
+
let ret;
|
|
548
|
+
ret = wasm.wasmdocument_properties(this.__wbg_ptr);
|
|
549
|
+
if (ret[2]) {
|
|
550
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
551
|
+
}
|
|
552
|
+
return takeFromExternrefTable0(ret[0]);
|
|
553
|
+
}
|
|
454
554
|
/**
|
|
455
555
|
* Rebases onto `bytes`, the output of a save whose rebase failed (`not-rebased`).
|
|
456
556
|
*
|
|
@@ -514,6 +614,22 @@ export class WasmDocument {
|
|
|
514
614
|
}
|
|
515
615
|
return takeFromExternrefTable0(ret[0]);
|
|
516
616
|
}
|
|
617
|
+
/**
|
|
618
|
+
* The structure tree's top-level elements in reading order, or `undefined` without one (the
|
|
619
|
+
* extract and text modules, beside `WasmPage.text`, whose runs it links by MCID).
|
|
620
|
+
*
|
|
621
|
+
* # Errors
|
|
622
|
+
* Reading errors.
|
|
623
|
+
* @returns {StructureNodeJs[] | undefined}
|
|
624
|
+
*/
|
|
625
|
+
structureTree() {
|
|
626
|
+
let ret;
|
|
627
|
+
ret = wasm.wasmdocument_structureTree(this.__wbg_ptr);
|
|
628
|
+
if (ret[2]) {
|
|
629
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
630
|
+
}
|
|
631
|
+
return takeFromExternrefTable0(ret[0]);
|
|
632
|
+
}
|
|
517
633
|
/**
|
|
518
634
|
* Undoes the newest transaction; `undefined` when there is nothing to undo.
|
|
519
635
|
*
|
|
@@ -541,6 +657,73 @@ export class WasmDocument {
|
|
|
541
657
|
}
|
|
542
658
|
if (Symbol.dispose) WasmDocument.prototype[Symbol.dispose] = WasmDocument.prototype.free;
|
|
543
659
|
|
|
660
|
+
/**
|
|
661
|
+
* An extraction in progress, from `WasmDocument.extractJob`; it holds its document weakly.
|
|
662
|
+
*/
|
|
663
|
+
export class WasmExtractJob {
|
|
664
|
+
static __wrap(ptr) {
|
|
665
|
+
const obj = Object.create(WasmExtractJob.prototype);
|
|
666
|
+
obj.__wbg_ptr = ptr;
|
|
667
|
+
Object.defineProperty(obj, '__wbg_inst', { value: __wbg_instance_id, writable: true });
|
|
668
|
+
|
|
669
|
+
WasmExtractJobFinalization.register(obj, { ptr, instance: __wbg_instance_id }, obj);
|
|
670
|
+
return obj;
|
|
671
|
+
}
|
|
672
|
+
__destroy_into_raw() {
|
|
673
|
+
const ptr = this.__wbg_ptr;
|
|
674
|
+
this.__wbg_ptr = 0;
|
|
675
|
+
WasmExtractJobFinalization.unregister(this);
|
|
676
|
+
return ptr;
|
|
677
|
+
}
|
|
678
|
+
free() {
|
|
679
|
+
const ptr = this.__destroy_into_raw();
|
|
680
|
+
wasm.__wbg_wasmextractjob_free(ptr, 0);
|
|
681
|
+
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Stops the job: its next step fails with `cancelled`.
|
|
685
|
+
*/
|
|
686
|
+
cancel() {
|
|
687
|
+
wasm.wasmextractjob_cancel(this.__wbg_ptr);
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Hands the job the result of its open request: `{ kind: "layout", regions }` or
|
|
691
|
+
* `{ kind: "ocr", words }`, boxes as `[x, y, width, height]` in top-left points.
|
|
692
|
+
*
|
|
693
|
+
* # Errors
|
|
694
|
+
* `model-result-unexpected` when nothing was asked for or `result` is the other kind;
|
|
695
|
+
* `invalid-argument` / `unknown-option` for a malformed result.
|
|
696
|
+
* @param {ModelResultInit} result
|
|
697
|
+
*/
|
|
698
|
+
provide(result) {
|
|
699
|
+
let ret;
|
|
700
|
+
ret = wasm.wasmextractjob_provide(this.__wbg_ptr, result);
|
|
701
|
+
if (ret[1]) {
|
|
702
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Extracts up to `budget` pages: `{ state: "progress", done, total, phase, request? }` or
|
|
707
|
+
* `{ state: "done", output }`, the output in the job's format. While `request` is set, a
|
|
708
|
+
* step does nothing until `provide` answers it.
|
|
709
|
+
*
|
|
710
|
+
* # Errors
|
|
711
|
+
* `cancelled`, `document-changed`, `job-finished`, `disposed` when the document is freed,
|
|
712
|
+
* and the reading errors.
|
|
713
|
+
* @param {number} budget
|
|
714
|
+
* @returns {({ state: "progress" } & ExtractProgressJs) | { state: "done"; output: string }}
|
|
715
|
+
*/
|
|
716
|
+
step(budget) {
|
|
717
|
+
let ret;
|
|
718
|
+
ret = wasm.wasmextractjob_step(this.__wbg_ptr, budget);
|
|
719
|
+
if (ret[2]) {
|
|
720
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
721
|
+
}
|
|
722
|
+
return takeFromExternrefTable0(ret[0]);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
if (Symbol.dispose) WasmExtractJob.prototype[Symbol.dispose] = WasmExtractJob.prototype.free;
|
|
726
|
+
|
|
544
727
|
/**
|
|
545
728
|
* A font registered with a [`WasmBuilder`].
|
|
546
729
|
*/
|
|
@@ -828,7 +1011,8 @@ export class WasmPageBuilder {
|
|
|
828
1011
|
}
|
|
829
1012
|
/**
|
|
830
1013
|
* Opens an artifact until the matching `endTag`: `kind` is `layout`, `page`, `pagination`
|
|
831
|
-
* or `background
|
|
1014
|
+
* or `background`, or a pagination artifact that says what it is: `header` (attached to the
|
|
1015
|
+
* top edge), `footer` (the bottom) or `watermark`.
|
|
832
1016
|
*
|
|
833
1017
|
* # Errors
|
|
834
1018
|
* `invalid-argument` for another kind.
|
|
@@ -1648,6 +1832,11 @@ const WasmDocumentFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
|
1648
1832
|
: new FinalizationRegistry(({ ptr, instance }) => {
|
|
1649
1833
|
if (instance === __wbg_instance_id) wasm.__wbg_wasmdocument_free(ptr, 1);
|
|
1650
1834
|
});
|
|
1835
|
+
const WasmExtractJobFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1836
|
+
? { register: () => {}, unregister: () => {} }
|
|
1837
|
+
: new FinalizationRegistry(({ ptr, instance }) => {
|
|
1838
|
+
if (instance === __wbg_instance_id) wasm.__wbg_wasmextractjob_free(ptr, 1);
|
|
1839
|
+
});
|
|
1651
1840
|
const WasmFontFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1652
1841
|
? { register: () => {}, unregister: () => {} }
|
|
1653
1842
|
: new FinalizationRegistry(({ ptr, instance }) => {
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@laminapdf/wasm",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.5",
|
|
4
4
|
"description": "Lamina PDF's WebAssembly modules and their wasm-bindgen glue: lamina_pdf_base (open, read, edit, save, vector and image pages), lamina_pdf_text (all of base plus fonts and text) and lamina_pdf_extract (all of base plus text extraction); and lamina_pdf_render_hayro, laminapdf-render's hayro adapter, which @laminapdf/render-hayro wraps. Generated into dist/ by `cargo xtask wasm`; @laminapdf/sdk is the API to use.",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"homepage": "https://laminapdf.com",
|