@laminapdf/wasm 0.2.0-alpha.6 → 0.2.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.
@@ -75,6 +75,30 @@ export class WasmBuilder {
75
75
  }
76
76
  return WasmDocument.__wrap(ret[0]);
77
77
  }
78
+ /**
79
+ * Lays `document` out as tagged pages that flow, after any pages already added, filled from
80
+ * `options.data` first when it is given. The document's profiles are the builder's to set
81
+ * (`profiles` in its options); its warnings are the finished document's.
82
+ *
83
+ * # Errors
84
+ * `builder-finished`; `unknown-option`, `invalid-argument`; `invalid-document` with the JSON
85
+ * Pointer at fault and the closest keys in `didYouMean`; `template-data-missing`,
86
+ * `template-data-type`, `template-too-large`; `unknown-font` and `unknown-image` for a name
87
+ * `resources` lacks; `missing-glyph`, `flow-content-too-large`.
88
+ * @param {unknown} document
89
+ * @param {WasmFlowResources} resources
90
+ * @param {FlowOptionsInit | undefined} options
91
+ * @returns {FlowReportJs}
92
+ */
93
+ flow(document, resources, options) {
94
+ _assertClass(resources, WasmFlowResources);
95
+ let ret;
96
+ ret = wasm.wasmbuilder_flow(this.__wbg_ptr, document, resources.__wbg_ptr, options);
97
+ if (ret[2]) {
98
+ throw takeFromExternrefTable0(ret[1]);
99
+ }
100
+ return takeFromExternrefTable0(ret[0]);
101
+ }
78
102
  /**
79
103
  * Loads a font from its bytes (TrueType or OpenType/CFF) and registers it; it is
80
104
  * subset to the glyphs drawn.
@@ -287,6 +311,25 @@ export class WasmDocument {
287
311
  wasm.__wbg_wasmdocument_free(ptr, 0);
288
312
 
289
313
  }
314
+ /**
315
+ * Makes `bytes`, the whole output of `saveCopy`, the document's saved file (it rebases onto
316
+ * them), once they are written where the document lives; `historyCleared` is the copy's
317
+ * report's.
318
+ *
319
+ * # Errors
320
+ * `nested-transaction`, `saved-not-rebased`; `not-rebased` when `bytes` can't be read.
321
+ * @param {Uint8Array} bytes
322
+ * @param {boolean} historyCleared
323
+ */
324
+ adoptCopy(bytes, historyCleared) {
325
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
326
+ const len0 = WASM_VECTOR_LEN;
327
+ let ret;
328
+ ret = wasm.wasmdocument_adoptCopy(this.__wbg_ptr, ptr0, len0, historyCleared);
329
+ if (ret[1]) {
330
+ throw takeFromExternrefTable0(ret[0]);
331
+ }
332
+ }
290
333
  /**
291
334
  * Applies an op log (`{ "v": 1, "ops": [ … ] }`) as one transaction.
292
335
  *
@@ -418,6 +461,22 @@ export class WasmDocument {
418
461
  }
419
462
  return ret[0] !== 0;
420
463
  }
464
+ /**
465
+ * The document's metadata, read from Info and XMP together, with the fields where they
466
+ * disagree.
467
+ *
468
+ * # Errors
469
+ * Reading errors.
470
+ * @returns {DocumentMetadata}
471
+ */
472
+ metadata() {
473
+ let ret;
474
+ ret = wasm.wasmdocument_metadata(this.__wbg_ptr);
475
+ if (ret[2]) {
476
+ throw takeFromExternrefTable0(ret[1]);
477
+ }
478
+ return takeFromExternrefTable0(ret[0]);
479
+ }
421
480
  /**
422
481
  * The named destination `name`, or `undefined` when the document has none by that name or
423
482
  * it names no page here (the extract and text modules).
@@ -589,6 +648,22 @@ export class WasmDocument {
589
648
  }
590
649
  return WasmPage.__wrap(ret[0]);
591
650
  }
651
+ /**
652
+ * How a save with `options` would go, without saving.
653
+ *
654
+ * # Errors
655
+ * `invalid-argument` / `unknown-option` for bad options; reading errors.
656
+ * @param {SaveOptionsInit | undefined} options
657
+ * @returns {PlannedSaveJs}
658
+ */
659
+ plan(options) {
660
+ let ret;
661
+ ret = wasm.wasmdocument_plan(this.__wbg_ptr, options);
662
+ if (ret[2]) {
663
+ throw takeFromExternrefTable0(ret[1]);
664
+ }
665
+ return takeFromExternrefTable0(ret[0]);
666
+ }
592
667
  /**
593
668
  * The document's properties (the extract and text modules). Reads every object once.
594
669
  *
@@ -636,6 +711,23 @@ export class WasmDocument {
636
711
  }
637
712
  return takeFromExternrefTable0(ret[0]);
638
713
  }
714
+ /**
715
+ * Writes what `save` would and leaves the document as it was: not rebased, its changes
716
+ * still unsaved, the save-time stamp in the copy only (Save a copy).
717
+ *
718
+ * # Errors
719
+ * As `save`; the document is unchanged either way.
720
+ * @param {SaveOptionsInit | undefined} options
721
+ * @returns {{ bytes: Uint8Array<ArrayBuffer>; report: SaveReportJs }}
722
+ */
723
+ saveCopy(options) {
724
+ let ret;
725
+ ret = wasm.wasmdocument_saveCopy(this.__wbg_ptr, options);
726
+ if (ret[2]) {
727
+ throw takeFromExternrefTable0(ret[1]);
728
+ }
729
+ return takeFromExternrefTable0(ret[0]);
730
+ }
639
731
  /**
640
732
  * A save as a job, stepped with a budget of work units (ADR 0028 §3, §4).
641
733
  *
@@ -709,6 +801,22 @@ export class WasmDocument {
709
801
  ret = wasm.wasmdocument_warnings(this.__wbg_ptr);
710
802
  return WasmWarningCursor.__wrap(ret);
711
803
  }
804
+ /**
805
+ * The signature restrictions `op` would break if it were applied and saved.
806
+ *
807
+ * # Errors
808
+ * `invalid-argument` for a value that isn't an op; reading errors.
809
+ * @param {Op} op
810
+ * @returns {ViolationJs[]}
811
+ */
812
+ wouldViolate(op) {
813
+ let ret;
814
+ ret = wasm.wasmdocument_wouldViolate(this.__wbg_ptr, op);
815
+ if (ret[2]) {
816
+ throw takeFromExternrefTable0(ret[1]);
817
+ }
818
+ return takeFromExternrefTable0(ret[0]);
819
+ }
712
820
  }
713
821
  if (Symbol.dispose) WasmDocument.prototype[Symbol.dispose] = WasmDocument.prototype.free;
714
822
 
@@ -779,6 +887,57 @@ export class WasmExtractJob {
779
887
  }
780
888
  if (Symbol.dispose) WasmExtractJob.prototype[Symbol.dispose] = WasmExtractJob.prototype.free;
781
889
 
890
+ /**
891
+ * The fonts and images a document names, by the names it gives them.
892
+ */
893
+ export class WasmFlowResources {
894
+ __destroy_into_raw() {
895
+ const ptr = this.__wbg_ptr;
896
+ this.__wbg_ptr = 0;
897
+ WasmFlowResourcesFinalization.unregister(this);
898
+ return ptr;
899
+ }
900
+ free() {
901
+ const ptr = this.__destroy_into_raw();
902
+ wasm.__wbg_wasmflowresources_free(ptr, 0);
903
+
904
+ }
905
+ /**
906
+ * `font` for the styles that name `name`; the same name again replaces it.
907
+ * @param {string} name
908
+ * @param {WasmFont} font
909
+ */
910
+ font(name, font) {
911
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
912
+ const len0 = WASM_VECTOR_LEN;
913
+ _assertClass(font, WasmFont);
914
+ wasm.wasmflowresources_font(this.__wbg_ptr, ptr0, len0, font.__wbg_ptr);
915
+ }
916
+ /**
917
+ * `image` for the figures that name `name`; the same name again replaces it.
918
+ * @param {string} name
919
+ * @param {WasmImage} image
920
+ */
921
+ image(name, image) {
922
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
923
+ const len0 = WASM_VECTOR_LEN;
924
+ _assertClass(image, WasmImage);
925
+ wasm.wasmflowresources_image(this.__wbg_ptr, ptr0, len0, image.__wbg_ptr);
926
+ }
927
+ /**
928
+ * No fonts and no images.
929
+ */
930
+ constructor() {
931
+ let ret;
932
+ ret = wasm.wasmflowresources_new();
933
+ this.__wbg_ptr = ret;
934
+ Object.defineProperty(this, '__wbg_inst', { value: __wbg_instance_id, writable: true });
935
+ WasmFlowResourcesFinalization.register(this, { ptr: ret, instance: __wbg_instance_id }, this);
936
+ return this;
937
+ }
938
+ }
939
+ if (Symbol.dispose) WasmFlowResources.prototype[Symbol.dispose] = WasmFlowResources.prototype.free;
940
+
782
941
  /**
783
942
  * A font registered with a [`WasmBuilder`].
784
943
  */
@@ -1951,6 +2110,11 @@ const WasmExtractJobFinalization = (typeof FinalizationRegistry === 'undefined')
1951
2110
  : new FinalizationRegistry(({ ptr, instance }) => {
1952
2111
  if (instance === __wbg_instance_id) wasm.__wbg_wasmextractjob_free(ptr, 1);
1953
2112
  });
2113
+ const WasmFlowResourcesFinalization = (typeof FinalizationRegistry === 'undefined')
2114
+ ? { register: () => {}, unregister: () => {} }
2115
+ : new FinalizationRegistry(({ ptr, instance }) => {
2116
+ if (instance === __wbg_instance_id) wasm.__wbg_wasmflowresources_free(ptr, 1);
2117
+ });
1954
2118
  const WasmFontFinalization = (typeof FinalizationRegistry === 'undefined')
1955
2119
  ? { register: () => {}, unregister: () => {} }
1956
2120
  : new FinalizationRegistry(({ ptr, instance }) => {
Binary file
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@laminapdf/wasm",
3
- "version": "0.2.0-alpha.6",
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.",
3
+ "version": "0.2.0",
4
+ "description": "The WebAssembly build of Lamina PDF's Rust core, which @laminapdf/sdk runs on: create, read, edit and save PDFs and extract their text. Use @laminapdf/sdk; this package holds its compiled modules.",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "homepage": "https://laminapdf.com",
7
+ "bugs": {
8
+ "url": "https://github.com/laudebugs/laminapdf/issues"
9
+ },
7
10
  "repository": {
8
11
  "type": "git",
9
12
  "url": "git+https://github.com/laudebugs/laminapdf.git",
@@ -12,7 +15,10 @@
12
15
  "keywords": [
13
16
  "pdf",
14
17
  "wasm",
15
- "webassembly"
18
+ "webassembly",
19
+ "pdf-generation",
20
+ "pdf-editing",
21
+ "text-extraction"
16
22
  ],
17
23
  "type": "module",
18
24
  "sideEffects": false,