@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
|
@@ -240,6 +240,25 @@ export class WasmDocument {
|
|
|
240
240
|
}
|
|
241
241
|
return takeFromExternrefTable0(ret[0]);
|
|
242
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* An extraction stepped a page at a time, whose models the host runs: each step returns
|
|
245
|
+
* its progress, with the result it waits for under `request` (render that page at `dpi`,
|
|
246
|
+
* run the model, hand the result to `provide`), and once every page is done, the output in
|
|
247
|
+
* `options.format` (the extract and text modules).
|
|
248
|
+
*
|
|
249
|
+
* # Errors
|
|
250
|
+
* As `extract`, for the options and the pages asked for.
|
|
251
|
+
* @param {ExtractInit} options
|
|
252
|
+
* @returns {WasmExtractJob}
|
|
253
|
+
*/
|
|
254
|
+
extractJob(options) {
|
|
255
|
+
let ret;
|
|
256
|
+
ret = wasm.wasmdocument_extractJob(this.__wbg_ptr, options);
|
|
257
|
+
if (ret[2]) {
|
|
258
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
259
|
+
}
|
|
260
|
+
return WasmExtractJob.__wrap(ret[0]);
|
|
261
|
+
}
|
|
243
262
|
/**
|
|
244
263
|
* The document's text for retrieval and LLMs, as one string: Markdown, plain text, the
|
|
245
264
|
* `laminapdf.extract/1` JSON, or the chunks as a JSON array (the extract and text modules).
|
|
@@ -293,6 +312,40 @@ export class WasmDocument {
|
|
|
293
312
|
}
|
|
294
313
|
return takeFromExternrefTable0(ret[0]);
|
|
295
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Whether the document says it is tagged (`/MarkInfo /Marked true`; the extract and text modules).
|
|
317
|
+
*
|
|
318
|
+
* # Errors
|
|
319
|
+
* Reading errors.
|
|
320
|
+
* @returns {boolean}
|
|
321
|
+
*/
|
|
322
|
+
isTagged() {
|
|
323
|
+
let ret;
|
|
324
|
+
ret = wasm.wasmdocument_isTagged(this.__wbg_ptr);
|
|
325
|
+
if (ret[2]) {
|
|
326
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
327
|
+
}
|
|
328
|
+
return ret[0] !== 0;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* The named destination `name`, or `undefined` when the document has none by that name or
|
|
332
|
+
* it names no page here (the extract and text modules).
|
|
333
|
+
*
|
|
334
|
+
* # Errors
|
|
335
|
+
* `data-pending` and the reading errors.
|
|
336
|
+
* @param {string} name
|
|
337
|
+
* @returns {TargetJs | undefined}
|
|
338
|
+
*/
|
|
339
|
+
namedDestination(name) {
|
|
340
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
341
|
+
const len0 = WASM_VECTOR_LEN;
|
|
342
|
+
let ret;
|
|
343
|
+
ret = wasm.wasmdocument_namedDestination(this.__wbg_ptr, ptr0, len0);
|
|
344
|
+
if (ret[2]) {
|
|
345
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
346
|
+
}
|
|
347
|
+
return takeFromExternrefTable0(ret[0]);
|
|
348
|
+
}
|
|
296
349
|
/**
|
|
297
350
|
* Opens a document from its bytes.
|
|
298
351
|
*
|
|
@@ -333,6 +386,22 @@ export class WasmDocument {
|
|
|
333
386
|
}
|
|
334
387
|
return WasmDocument.__wrap(ret[0]);
|
|
335
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* The outline's top-level items, each with its children; empty without an outline (the
|
|
391
|
+
* extract and text modules).
|
|
392
|
+
*
|
|
393
|
+
* # Errors
|
|
394
|
+
* `data-pending` and the reading errors.
|
|
395
|
+
* @returns {OutlineNodeJs[]}
|
|
396
|
+
*/
|
|
397
|
+
outline() {
|
|
398
|
+
let ret;
|
|
399
|
+
ret = wasm.wasmdocument_outline(this.__wbg_ptr);
|
|
400
|
+
if (ret[2]) {
|
|
401
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
402
|
+
}
|
|
403
|
+
return takeFromExternrefTable0(ret[0]);
|
|
404
|
+
}
|
|
336
405
|
/**
|
|
337
406
|
* A handle on the page with `id` (`p12.0`).
|
|
338
407
|
*
|
|
@@ -397,6 +466,22 @@ export class WasmDocument {
|
|
|
397
466
|
}
|
|
398
467
|
return takeFromExternrefTable0(ret[0]);
|
|
399
468
|
}
|
|
469
|
+
/**
|
|
470
|
+
* The visible links on page `index`, in annotation order (the extract and text modules).
|
|
471
|
+
*
|
|
472
|
+
* # Errors
|
|
473
|
+
* `page-index-out-of-range`, `data-pending` and the reading errors.
|
|
474
|
+
* @param {number} index
|
|
475
|
+
* @returns {PageLinkJs[]}
|
|
476
|
+
*/
|
|
477
|
+
pageLinks(index) {
|
|
478
|
+
let ret;
|
|
479
|
+
ret = wasm.wasmdocument_pageLinks(this.__wbg_ptr, index);
|
|
480
|
+
if (ret[2]) {
|
|
481
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
482
|
+
}
|
|
483
|
+
return takeFromExternrefTable0(ret[0]);
|
|
484
|
+
}
|
|
400
485
|
/**
|
|
401
486
|
* A handle on page `index` that follows the page by its ID (F2).
|
|
402
487
|
*
|
|
@@ -413,6 +498,21 @@ export class WasmDocument {
|
|
|
413
498
|
}
|
|
414
499
|
return WasmPage.__wrap(ret[0]);
|
|
415
500
|
}
|
|
501
|
+
/**
|
|
502
|
+
* The document's properties (the extract and text modules). Reads every object once.
|
|
503
|
+
*
|
|
504
|
+
* # Errors
|
|
505
|
+
* `data-pending` and the reading errors.
|
|
506
|
+
* @returns {PropertiesJs}
|
|
507
|
+
*/
|
|
508
|
+
properties() {
|
|
509
|
+
let ret;
|
|
510
|
+
ret = wasm.wasmdocument_properties(this.__wbg_ptr);
|
|
511
|
+
if (ret[2]) {
|
|
512
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
513
|
+
}
|
|
514
|
+
return takeFromExternrefTable0(ret[0]);
|
|
515
|
+
}
|
|
416
516
|
/**
|
|
417
517
|
* Rebases onto `bytes`, the output of a save whose rebase failed (`not-rebased`).
|
|
418
518
|
*
|
|
@@ -444,6 +544,34 @@ export class WasmDocument {
|
|
|
444
544
|
}
|
|
445
545
|
return takeFromExternrefTable0(ret[0]);
|
|
446
546
|
}
|
|
547
|
+
/**
|
|
548
|
+
* The document for reader mode, as JSON: whether it can be shown and why not, its
|
|
549
|
+
* language, its blocks in the structure tree's order (figures, formulas and tables as crops
|
|
550
|
+
* with their alternate text) and the checks' measures (the extract module only).
|
|
551
|
+
*
|
|
552
|
+
* # Errors
|
|
553
|
+
* `data-pending` and the reading errors.
|
|
554
|
+
* @returns {string}
|
|
555
|
+
*/
|
|
556
|
+
reflow() {
|
|
557
|
+
let deferred2_0;
|
|
558
|
+
let deferred2_1;
|
|
559
|
+
try {
|
|
560
|
+
let ret;
|
|
561
|
+
ret = wasm.wasmdocument_reflow(this.__wbg_ptr);
|
|
562
|
+
var ptr1 = ret[0];
|
|
563
|
+
var len1 = ret[1];
|
|
564
|
+
if (ret[3]) {
|
|
565
|
+
ptr1 = 0; len1 = 0;
|
|
566
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
567
|
+
}
|
|
568
|
+
deferred2_0 = ptr1;
|
|
569
|
+
deferred2_1 = len1;
|
|
570
|
+
return getStringFromWasm0(ptr1, len1);
|
|
571
|
+
} finally {
|
|
572
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
447
575
|
/**
|
|
448
576
|
* A save as a job, stepped with a budget of work units (ADR 0028 §3, §4).
|
|
449
577
|
*
|
|
@@ -476,6 +604,22 @@ export class WasmDocument {
|
|
|
476
604
|
}
|
|
477
605
|
return takeFromExternrefTable0(ret[0]);
|
|
478
606
|
}
|
|
607
|
+
/**
|
|
608
|
+
* The structure tree's top-level elements in reading order, or `undefined` without one (the
|
|
609
|
+
* extract and text modules, beside `WasmPage.text`, whose runs it links by MCID).
|
|
610
|
+
*
|
|
611
|
+
* # Errors
|
|
612
|
+
* Reading errors.
|
|
613
|
+
* @returns {StructureNodeJs[] | undefined}
|
|
614
|
+
*/
|
|
615
|
+
structureTree() {
|
|
616
|
+
let ret;
|
|
617
|
+
ret = wasm.wasmdocument_structureTree(this.__wbg_ptr);
|
|
618
|
+
if (ret[2]) {
|
|
619
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
620
|
+
}
|
|
621
|
+
return takeFromExternrefTable0(ret[0]);
|
|
622
|
+
}
|
|
479
623
|
/**
|
|
480
624
|
* Undoes the newest transaction; `undefined` when there is nothing to undo.
|
|
481
625
|
*
|
|
@@ -503,6 +647,73 @@ export class WasmDocument {
|
|
|
503
647
|
}
|
|
504
648
|
if (Symbol.dispose) WasmDocument.prototype[Symbol.dispose] = WasmDocument.prototype.free;
|
|
505
649
|
|
|
650
|
+
/**
|
|
651
|
+
* An extraction in progress, from `WasmDocument.extractJob`; it holds its document weakly.
|
|
652
|
+
*/
|
|
653
|
+
export class WasmExtractJob {
|
|
654
|
+
static __wrap(ptr) {
|
|
655
|
+
const obj = Object.create(WasmExtractJob.prototype);
|
|
656
|
+
obj.__wbg_ptr = ptr;
|
|
657
|
+
Object.defineProperty(obj, '__wbg_inst', { value: __wbg_instance_id, writable: true });
|
|
658
|
+
|
|
659
|
+
WasmExtractJobFinalization.register(obj, { ptr, instance: __wbg_instance_id }, obj);
|
|
660
|
+
return obj;
|
|
661
|
+
}
|
|
662
|
+
__destroy_into_raw() {
|
|
663
|
+
const ptr = this.__wbg_ptr;
|
|
664
|
+
this.__wbg_ptr = 0;
|
|
665
|
+
WasmExtractJobFinalization.unregister(this);
|
|
666
|
+
return ptr;
|
|
667
|
+
}
|
|
668
|
+
free() {
|
|
669
|
+
const ptr = this.__destroy_into_raw();
|
|
670
|
+
wasm.__wbg_wasmextractjob_free(ptr, 0);
|
|
671
|
+
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Stops the job: its next step fails with `cancelled`.
|
|
675
|
+
*/
|
|
676
|
+
cancel() {
|
|
677
|
+
wasm.wasmextractjob_cancel(this.__wbg_ptr);
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Hands the job the result of its open request: `{ kind: "layout", regions }` or
|
|
681
|
+
* `{ kind: "ocr", words }`, boxes as `[x, y, width, height]` in top-left points.
|
|
682
|
+
*
|
|
683
|
+
* # Errors
|
|
684
|
+
* `model-result-unexpected` when nothing was asked for or `result` is the other kind;
|
|
685
|
+
* `invalid-argument` / `unknown-option` for a malformed result.
|
|
686
|
+
* @param {ModelResultInit} result
|
|
687
|
+
*/
|
|
688
|
+
provide(result) {
|
|
689
|
+
let ret;
|
|
690
|
+
ret = wasm.wasmextractjob_provide(this.__wbg_ptr, result);
|
|
691
|
+
if (ret[1]) {
|
|
692
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Extracts up to `budget` pages: `{ state: "progress", done, total, phase, request? }` or
|
|
697
|
+
* `{ state: "done", output }`, the output in the job's format. While `request` is set, a
|
|
698
|
+
* step does nothing until `provide` answers it.
|
|
699
|
+
*
|
|
700
|
+
* # Errors
|
|
701
|
+
* `cancelled`, `document-changed`, `job-finished`, `disposed` when the document is freed,
|
|
702
|
+
* and the reading errors.
|
|
703
|
+
* @param {number} budget
|
|
704
|
+
* @returns {({ state: "progress" } & ExtractProgressJs) | { state: "done"; output: string }}
|
|
705
|
+
*/
|
|
706
|
+
step(budget) {
|
|
707
|
+
let ret;
|
|
708
|
+
ret = wasm.wasmextractjob_step(this.__wbg_ptr, budget);
|
|
709
|
+
if (ret[2]) {
|
|
710
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
711
|
+
}
|
|
712
|
+
return takeFromExternrefTable0(ret[0]);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
if (Symbol.dispose) WasmExtractJob.prototype[Symbol.dispose] = WasmExtractJob.prototype.free;
|
|
716
|
+
|
|
506
717
|
/**
|
|
507
718
|
* An image to draw (decoded or passed through once, shared by every use).
|
|
508
719
|
*/
|
|
@@ -721,7 +932,8 @@ export class WasmPageBuilder {
|
|
|
721
932
|
}
|
|
722
933
|
/**
|
|
723
934
|
* Opens an artifact until the matching `endTag`: `kind` is `layout`, `page`, `pagination`
|
|
724
|
-
* or `background
|
|
935
|
+
* or `background`, or a pagination artifact that says what it is: `header` (attached to the
|
|
936
|
+
* top edge), `footer` (the bottom) or `watermark`.
|
|
725
937
|
*
|
|
726
938
|
* # Errors
|
|
727
939
|
* `invalid-argument` for another kind.
|
|
@@ -1488,6 +1700,11 @@ const WasmDocumentFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
|
1488
1700
|
: new FinalizationRegistry(({ ptr, instance }) => {
|
|
1489
1701
|
if (instance === __wbg_instance_id) wasm.__wbg_wasmdocument_free(ptr, 1);
|
|
1490
1702
|
});
|
|
1703
|
+
const WasmExtractJobFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1704
|
+
? { register: () => {}, unregister: () => {} }
|
|
1705
|
+
: new FinalizationRegistry(({ ptr, instance }) => {
|
|
1706
|
+
if (instance === __wbg_instance_id) wasm.__wbg_wasmextractjob_free(ptr, 1);
|
|
1707
|
+
});
|
|
1491
1708
|
const WasmImageFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1492
1709
|
? { register: () => {}, unregister: () => {} }
|
|
1493
1710
|
: new FinalizationRegistry(({ ptr, instance }) => {
|
|
Binary file
|
|
@@ -35,12 +35,15 @@ export class HayroDocument {
|
|
|
35
35
|
*/
|
|
36
36
|
plan(page: number, scale: number, x: number, y: number, width: number, height: number, rotation: number, flags: number, background?: number | null): Uint32Array;
|
|
37
37
|
/**
|
|
38
|
-
* Renders the request into `out` (exactly `width × height × 4` bytes, straight RGBA)
|
|
38
|
+
* Renders the request into `out` (exactly `width × height × 4` bytes, straight RGBA), in
|
|
39
|
+
* the page appearance `appearance` (0 original, 1 sepia, 2 dark, 3 high contrast with `ink`
|
|
40
|
+
* and `paper` as `0xRRGGBBAA`; the colours are ignored otherwise).
|
|
39
41
|
*
|
|
40
42
|
* # Errors
|
|
41
|
-
* As [`HayroDocument::plan`], plus `render-failed
|
|
43
|
+
* As [`HayroDocument::plan`], plus `render-failed`, and `invalid-argument` for a wrong size
|
|
44
|
+
* or an unknown appearance.
|
|
42
45
|
*/
|
|
43
|
-
render(page: number, scale: number, x: number, y: number, width: number, height: number, rotation: number, flags: number, background: number | null | undefined, out: Uint8Array): void;
|
|
46
|
+
render(page: number, scale: number, x: number, y: number, width: number, height: number, rotation: number, flags: number, background: number | null | undefined, appearance: number, ink: number, paper: number, out: Uint8Array): void;
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
/**
|
|
@@ -78,7 +81,7 @@ export interface InitOutput {
|
|
|
78
81
|
readonly hayrodocument_page: (a: number, b: number) => [number, number, number, number];
|
|
79
82
|
readonly hayrodocument_pageCount: (a: number) => number;
|
|
80
83
|
readonly hayrodocument_plan: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => [number, number, number, number];
|
|
81
|
-
readonly hayrodocument_render: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: any) => [number, number];
|
|
84
|
+
readonly hayrodocument_render: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: any) => [number, number];
|
|
82
85
|
readonly inputbuffer_new: (a: number) => [number, number, number];
|
|
83
86
|
readonly inputbuffer_write: (a: number, b: number, c: number, d: number) => [number, number];
|
|
84
87
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
@@ -95,10 +95,13 @@ export class HayroDocument {
|
|
|
95
95
|
return v1;
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
|
-
* Renders the request into `out` (exactly `width × height × 4` bytes, straight RGBA)
|
|
98
|
+
* Renders the request into `out` (exactly `width × height × 4` bytes, straight RGBA), in
|
|
99
|
+
* the page appearance `appearance` (0 original, 1 sepia, 2 dark, 3 high contrast with `ink`
|
|
100
|
+
* and `paper` as `0xRRGGBBAA`; the colours are ignored otherwise).
|
|
99
101
|
*
|
|
100
102
|
* # Errors
|
|
101
|
-
* As [`HayroDocument::plan`], plus `render-failed
|
|
103
|
+
* As [`HayroDocument::plan`], plus `render-failed`, and `invalid-argument` for a wrong size
|
|
104
|
+
* or an unknown appearance.
|
|
102
105
|
* @param {number} page
|
|
103
106
|
* @param {number} scale
|
|
104
107
|
* @param {number} x
|
|
@@ -108,12 +111,15 @@ export class HayroDocument {
|
|
|
108
111
|
* @param {number} rotation
|
|
109
112
|
* @param {number} flags
|
|
110
113
|
* @param {number | null | undefined} background
|
|
114
|
+
* @param {number} appearance
|
|
115
|
+
* @param {number} ink
|
|
116
|
+
* @param {number} paper
|
|
111
117
|
* @param {Uint8Array} out
|
|
112
118
|
*/
|
|
113
|
-
render(page, scale, x, y, width, height, rotation, flags, background, out) {
|
|
119
|
+
render(page, scale, x, y, width, height, rotation, flags, background, appearance, ink, paper, out) {
|
|
114
120
|
var ptr0 = passArray8ToWasm0(out, wasm.__wbindgen_malloc);
|
|
115
121
|
var len0 = WASM_VECTOR_LEN;
|
|
116
|
-
const ret = wasm.hayrodocument_render(this.__wbg_ptr, page, scale, x, y, width, height, rotation, flags, isLikeNone(background) ? Number.MAX_SAFE_INTEGER : (background) >>> 0, ptr0, len0, out);
|
|
122
|
+
const ret = wasm.hayrodocument_render(this.__wbg_ptr, page, scale, x, y, width, height, rotation, flags, isLikeNone(background) ? Number.MAX_SAFE_INTEGER : (background) >>> 0, appearance, ink, paper, ptr0, len0, out);
|
|
117
123
|
if (ret[1]) {
|
|
118
124
|
throw takeFromExternrefTable0(ret[0]);
|
|
119
125
|
}
|
|
Binary file
|