@laminapdf/wasm 0.2.0 → 0.3.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.
@@ -205,6 +205,29 @@ export class WasmDocument {
205
205
  wasm.__wbg_wasmdocument_free(ptr, 0);
206
206
 
207
207
  }
208
+ /**
209
+ * Adds another PDF as a source document: `{ id, pages }`, its ID (64 hex digits, the
210
+ * SHA-256 of `bytes`) and its page IDs in order. An encrypted one opens with `password`,
211
+ * which no op ever holds.
212
+ *
213
+ * # Errors
214
+ * `wrong-password`, `password-required`, and the errors of a file that doesn't open.
215
+ * @param {Uint8Array} bytes
216
+ * @param {string | null} [password]
217
+ * @returns {{ id: string; pages: string[] }}
218
+ */
219
+ addSource(bytes, password) {
220
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
221
+ const len0 = WASM_VECTOR_LEN;
222
+ var ptr1 = isLikeNone(password) ? 0 : passStringToWasm0(password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
223
+ var len1 = WASM_VECTOR_LEN;
224
+ let ret;
225
+ ret = wasm.wasmdocument_addSource(this.__wbg_ptr, ptr0, len0, ptr1, len1);
226
+ if (ret[2]) {
227
+ throw takeFromExternrefTable0(ret[1]);
228
+ }
229
+ return takeFromExternrefTable0(ret[0]);
230
+ }
208
231
  /**
209
232
  * Makes `bytes`, the whole output of `saveCopy`, the document's saved file (it rebases onto
210
233
  * them), once they are written where the document lives; `historyCleared` is the copy's
@@ -259,6 +282,24 @@ export class WasmDocument {
259
282
  }
260
283
  return takeFromExternrefTable0(ret[0]);
261
284
  }
285
+ /**
286
+ * `view` (page space) on page `page` as the destination the outline and named-destination
287
+ * ops take, in the page's user space (the extract and text modules).
288
+ *
289
+ * # Errors
290
+ * `invalid-argument` for a view that isn't one; `page-index-out-of-range`; reading errors.
291
+ * @param {number} page
292
+ * @param {TargetViewJs} view
293
+ * @returns {ExplicitDestination}
294
+ */
295
+ destinationAt(page, view) {
296
+ let ret;
297
+ ret = wasm.wasmdocument_destinationAt(this.__wbg_ptr, page, view);
298
+ if (ret[2]) {
299
+ throw takeFromExternrefTable0(ret[1]);
300
+ }
301
+ return takeFromExternrefTable0(ret[0]);
302
+ }
262
303
  /**
263
304
  * An extraction stepped a page at a time, whose models the host runs: each step returns
264
305
  * its progress, with the result it waits for under `request` (render that page at `dpi`,
@@ -278,6 +319,23 @@ export class WasmDocument {
278
319
  }
279
320
  return WasmExtractJob.__wrap(ret[0]);
280
321
  }
322
+ /**
323
+ * A new document of `pages` of this one, in the order given.
324
+ *
325
+ * # Errors
326
+ * `invalid-argument` for a value that isn't a list of page IDs, `unknown-page`; reading
327
+ * errors.
328
+ * @param {string[]} pages
329
+ * @returns {WasmDocument}
330
+ */
331
+ extractPages(pages) {
332
+ let ret;
333
+ ret = wasm.wasmdocument_extractPages(this.__wbg_ptr, pages);
334
+ if (ret[2]) {
335
+ throw takeFromExternrefTable0(ret[1]);
336
+ }
337
+ return WasmDocument.__wrap(ret[0]);
338
+ }
281
339
  /**
282
340
  * The document's text for retrieval and LLMs, as one string: Markdown, plain text, the
283
341
  * `laminapdf.extract/1` JSON, or the chunks as a JSON array (the extract and text modules).
@@ -331,6 +389,21 @@ export class WasmDocument {
331
389
  }
332
390
  return takeFromExternrefTable0(ret[0]);
333
391
  }
392
+ /**
393
+ * How the document asks to be shown when it opens (the extract and text modules).
394
+ *
395
+ * # Errors
396
+ * `data-pending` and the reading errors.
397
+ * @returns {InitialViewJs}
398
+ */
399
+ initialView() {
400
+ let ret;
401
+ ret = wasm.wasmdocument_initialView(this.__wbg_ptr);
402
+ if (ret[2]) {
403
+ throw takeFromExternrefTable0(ret[1]);
404
+ }
405
+ return takeFromExternrefTable0(ret[0]);
406
+ }
334
407
  /**
335
408
  * Whether the file is encrypted (it opened with its password, or the empty one).
336
409
  * @returns {boolean}
@@ -355,6 +428,26 @@ export class WasmDocument {
355
428
  }
356
429
  return ret[0] !== 0;
357
430
  }
431
+ /**
432
+ * A new document of `inputs` (each `{ bytes, password?, title? }`) one after another,
433
+ * with their bookmarks, named destinations, form fields, layers and page labels; `options`
434
+ * as `mergeDocuments`' (`outline`, `fields`).
435
+ *
436
+ * # Errors
437
+ * `invalid-argument` / `unknown-option` for bad values, `wrong-password`,
438
+ * `password-required`, and the errors of a file that doesn't open.
439
+ * @param {{ bytes: Uint8Array; password?: string; title?: string }[]} inputs
440
+ * @param {MergeOptions | undefined} options
441
+ * @returns {WasmDocument}
442
+ */
443
+ static merge(inputs, options) {
444
+ let ret;
445
+ ret = wasm.wasmdocument_merge(inputs, options);
446
+ if (ret[2]) {
447
+ throw takeFromExternrefTable0(ret[1]);
448
+ }
449
+ return WasmDocument.__wrap(ret[0]);
450
+ }
358
451
  /**
359
452
  * The document's metadata, read from Info and XMP together, with the fields where they
360
453
  * disagree.
@@ -390,6 +483,21 @@ export class WasmDocument {
390
483
  }
391
484
  return takeFromExternrefTable0(ret[0]);
392
485
  }
486
+ /**
487
+ * Every named destination, sorted by name (the extract and text modules).
488
+ *
489
+ * # Errors
490
+ * `data-pending` and the reading errors.
491
+ * @returns {NamedDestinationJs[]}
492
+ */
493
+ namedDestinations() {
494
+ let ret;
495
+ ret = wasm.wasmdocument_namedDestinations(this.__wbg_ptr);
496
+ if (ret[2]) {
497
+ throw takeFromExternrefTable0(ret[1]);
498
+ }
499
+ return takeFromExternrefTable0(ret[0]);
500
+ }
393
501
  /**
394
502
  * Opens a document from its bytes.
395
503
  *
@@ -446,6 +554,23 @@ export class WasmDocument {
446
554
  }
447
555
  return takeFromExternrefTable0(ret[0]);
448
556
  }
557
+ /**
558
+ * The annotations on page `index`, in the order of its `/Annots`, every subtype included
559
+ * (the extract and text modules).
560
+ *
561
+ * # Errors
562
+ * `page-index-out-of-range`, `data-pending` and the reading errors.
563
+ * @param {number} index
564
+ * @returns {PageAnnotationJs[]}
565
+ */
566
+ pageAnnotations(index) {
567
+ let ret;
568
+ ret = wasm.wasmdocument_pageAnnotations(this.__wbg_ptr, index);
569
+ if (ret[2]) {
570
+ throw takeFromExternrefTable0(ret[1]);
571
+ }
572
+ return takeFromExternrefTable0(ret[0]);
573
+ }
449
574
  /**
450
575
  * A handle on the page with `id` (`p12.0`).
451
576
  *
@@ -682,6 +807,26 @@ export class WasmDocument {
682
807
  }
683
808
  return takeFromExternrefTable0(ret[0]);
684
809
  }
810
+ /**
811
+ * This document cut into new ones: `{ count: n }` parts of `n` pages, `{ ranges: [[id, …],
812
+ * …] }` one part per list of page IDs, or `{ bookmarks: level }` a part from each bookmark
813
+ * at that depth (1: the top level). Each part carries what its pages reach and the
814
+ * bookmarks that go to them.
815
+ *
816
+ * # Errors
817
+ * `invalid-argument` / `unknown-option` for a value that isn't one of those, `unknown-page`,
818
+ * `no-pages-left` for an empty list; reading errors.
819
+ * @param {{ readonly count: number } | { readonly ranges: readonly (readonly string[])[] } | { readonly bookmarks: number }} by
820
+ * @returns {WasmDocument[]}
821
+ */
822
+ split(by) {
823
+ let ret;
824
+ ret = wasm.wasmdocument_split(this.__wbg_ptr, by);
825
+ if (ret[2]) {
826
+ throw takeFromExternrefTable0(ret[1]);
827
+ }
828
+ return takeFromExternrefTable0(ret[0]);
829
+ }
685
830
  /**
686
831
  * The structure tree's top-level elements in reading order, or `undefined` without one (the
687
832
  * extract and text modules, beside `WasmPage.text`, whose runs it links by MCID).
@@ -698,6 +843,21 @@ export class WasmDocument {
698
843
  }
699
844
  return takeFromExternrefTable0(ret[0]);
700
845
  }
846
+ /**
847
+ * The document's article threads; empty without any (the extract and text modules).
848
+ *
849
+ * # Errors
850
+ * `data-pending` and the reading errors.
851
+ * @returns {ThreadJs[]}
852
+ */
853
+ threads() {
854
+ let ret;
855
+ ret = wasm.wasmdocument_threads(this.__wbg_ptr);
856
+ if (ret[2]) {
857
+ throw takeFromExternrefTable0(ret[1]);
858
+ }
859
+ return takeFromExternrefTable0(ret[0]);
860
+ }
701
861
  /**
702
862
  * Undoes the newest transaction: how it went and the pages it touched; `undefined` when
703
863
  * there is nothing to undo.
@@ -739,6 +899,21 @@ export class WasmDocument {
739
899
  }
740
900
  return takeFromExternrefTable0(ret[0]);
741
901
  }
902
+ /**
903
+ * The document's XMP packet as text, with the edits made so far.
904
+ *
905
+ * # Errors
906
+ * Reading errors.
907
+ * @returns {XmpTextJs}
908
+ */
909
+ xmpPacket() {
910
+ let ret;
911
+ ret = wasm.wasmdocument_xmpPacket(this.__wbg_ptr);
912
+ if (ret[2]) {
913
+ throw takeFromExternrefTable0(ret[1]);
914
+ }
915
+ return takeFromExternrefTable0(ret[0]);
916
+ }
742
917
  }
743
918
  if (Symbol.dispose) WasmDocument.prototype[Symbol.dispose] = WasmDocument.prototype.free;
744
919
 
@@ -909,6 +1084,44 @@ export class WasmImage {
909
1084
  }
910
1085
  if (Symbol.dispose) WasmImage.prototype[Symbol.dispose] = WasmImage.prototype.free;
911
1086
 
1087
+ /**
1088
+ * The images of [`images_to_pdf`], in page order. Images are JavaScript-owned objects, which a
1089
+ * record can't carry, so they are added one by one.
1090
+ */
1091
+ export class WasmImageList {
1092
+ __destroy_into_raw() {
1093
+ const ptr = this.__wbg_ptr;
1094
+ this.__wbg_ptr = 0;
1095
+ WasmImageListFinalization.unregister(this);
1096
+ return ptr;
1097
+ }
1098
+ free() {
1099
+ const ptr = this.__destroy_into_raw();
1100
+ wasm.__wbg_wasmimagelist_free(ptr, 0);
1101
+
1102
+ }
1103
+ /**
1104
+ * An empty list.
1105
+ */
1106
+ constructor() {
1107
+ let ret;
1108
+ ret = wasm.wasmimagelist_new();
1109
+ this.__wbg_ptr = ret;
1110
+ Object.defineProperty(this, '__wbg_inst', { value: __wbg_instance_id, writable: true });
1111
+ WasmImageListFinalization.register(this, { ptr: ret, instance: __wbg_instance_id }, this);
1112
+ return this;
1113
+ }
1114
+ /**
1115
+ * Adds `image` as the next page. The image stays usable: the list holds its own copy.
1116
+ * @param {WasmImage} image
1117
+ */
1118
+ push(image) {
1119
+ _assertClass(image, WasmImage);
1120
+ wasm.wasmimagelist_push(this.__wbg_ptr, image.__wbg_ptr);
1121
+ }
1122
+ }
1123
+ if (Symbol.dispose) WasmImageList.prototype[Symbol.dispose] = WasmImageList.prototype.free;
1124
+
912
1125
  /**
913
1126
  * A page of a [`WasmDocument`], held by its ID (F2): moving pages doesn't retarget it.
914
1127
  */
@@ -1663,6 +1876,27 @@ export function hasText() {
1663
1876
  return ret !== 0;
1664
1877
  }
1665
1878
 
1879
+ /**
1880
+ * A new document with one page per image of `images`, in order: a JPEG embedded as it is, a PNG
1881
+ * with its transparency, each drawn the way up its EXIF orientation says.
1882
+ *
1883
+ * # Errors
1884
+ * `invalid-geometry` for no images, a negative margin or resolution, or a page too small for its
1885
+ * margins; `unknown-option`, `invalid-argument` for bad options.
1886
+ * @param {WasmImageList} images
1887
+ * @param {ImagesOptionsInit | undefined} options
1888
+ * @returns {WasmDocument}
1889
+ */
1890
+ export function imagesToPdf(images, options) {
1891
+ _assertClass(images, WasmImageList);
1892
+ let ret;
1893
+ ret = wasm.imagesToPdf(images.__wbg_ptr, options);
1894
+ if (ret[2]) {
1895
+ throw takeFromExternrefTable0(ret[1]);
1896
+ }
1897
+ return WasmDocument.__wrap(ret[0]);
1898
+ }
1899
+
1666
1900
  /**
1667
1901
  * The crate version (`@laminapdf/wasm`'s).
1668
1902
  * @returns {string}
@@ -1707,14 +1941,48 @@ function __wbg_get_imports() {
1707
1941
  __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
1708
1942
  throw new Error(getStringFromWasm0(arg0, arg1));
1709
1943
  },
1944
+ __wbg_get_31af05bd4842a84f: function() { return handleError(function (arg0, arg1) {
1945
+ const ret = Reflect.get(arg0, arg1);
1946
+ return ret;
1947
+ }, arguments); },
1948
+ __wbg_get_unchecked_288889d017702237: function(arg0, arg1) {
1949
+ const ret = arg0[arg1 >>> 0];
1950
+ return ret;
1951
+ },
1952
+ __wbg_instanceof_Uint8Array_828cef2aaacafc31: function(arg0) {
1953
+ let result;
1954
+ try {
1955
+ result = arg0 instanceof Uint8Array;
1956
+ } catch (_) {
1957
+ result = false;
1958
+ }
1959
+ const ret = result;
1960
+ return ret;
1961
+ },
1962
+ __wbg_isArray_e15a2ff68ffdbef2: function(arg0) {
1963
+ const ret = Array.isArray(arg0);
1964
+ return ret;
1965
+ },
1710
1966
  __wbg_keys_440be172f17c0265: function(arg0) {
1711
1967
  const ret = Object.keys(arg0);
1712
1968
  return ret;
1713
1969
  },
1970
+ __wbg_length_7f3c00c40364105e: function(arg0) {
1971
+ const ret = arg0.length;
1972
+ return ret;
1973
+ },
1974
+ __wbg_length_d4bdea10311bd9cf: function(arg0) {
1975
+ const ret = arg0.length;
1976
+ return ret;
1977
+ },
1714
1978
  __wbg_new_617a8cdb8bb1130e: function() {
1715
1979
  const ret = new Object();
1716
1980
  return ret;
1717
1981
  },
1982
+ __wbg_new_ee2291f50781bf1d: function() {
1983
+ const ret = new Array();
1984
+ return ret;
1985
+ },
1718
1986
  __wbg_new_from_slice_37a3c3a194266cb8: function(arg0, arg1) {
1719
1987
  const ret = new Uint32Array(getArrayU32FromWasm0(arg0, arg1));
1720
1988
  return ret;
@@ -1735,6 +2003,13 @@ function __wbg_get_imports() {
1735
2003
  const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
1736
2004
  return ret;
1737
2005
  }, arguments); },
2006
+ __wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
2007
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
2008
+ },
2009
+ __wbg_push_2baf45db356cf468: function(arg0, arg1) {
2010
+ const ret = arg0.push(arg1);
2011
+ return ret;
2012
+ },
1738
2013
  __wbg_set_145a351398b48c65: function() { return handleError(function (arg0, arg1, arg2) {
1739
2014
  const ret = Reflect.set(arg0, arg1, arg2);
1740
2015
  return ret;
@@ -1750,6 +2025,10 @@ function __wbg_get_imports() {
1750
2025
  const ret = JSON.stringify(arg0);
1751
2026
  return ret;
1752
2027
  }, arguments); },
2028
+ __wbg_wasmdocument_new: function(arg0) {
2029
+ const ret = WasmDocument.__wrap(arg0);
2030
+ return ret;
2031
+ },
1753
2032
  __wbindgen_generic_0000000000000001: function(arg0) {
1754
2033
  // Cast intrinsic for `F64 -> Externref`.
1755
2034
  const ret = arg0;
@@ -1805,6 +2084,11 @@ const WasmImageFinalization = (typeof FinalizationRegistry === 'undefined')
1805
2084
  : new FinalizationRegistry(({ ptr, instance }) => {
1806
2085
  if (instance === __wbg_instance_id) wasm.__wbg_wasmimage_free(ptr, 1);
1807
2086
  });
2087
+ const WasmImageListFinalization = (typeof FinalizationRegistry === 'undefined')
2088
+ ? { register: () => {}, unregister: () => {} }
2089
+ : new FinalizationRegistry(({ ptr, instance }) => {
2090
+ if (instance === __wbg_instance_id) wasm.__wbg_wasmimagelist_free(ptr, 1);
2091
+ });
1808
2092
  const WasmPageFinalization = (typeof FinalizationRegistry === 'undefined')
1809
2093
  ? { register: () => {}, unregister: () => {} }
1810
2094
  : new FinalizationRegistry(({ ptr, instance }) => {
Binary file
Binary file