@laminapdf/wasm 0.2.0-alpha.6 → 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,48 @@ 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
+ }
231
+ /**
232
+ * Makes `bytes`, the whole output of `saveCopy`, the document's saved file (it rebases onto
233
+ * them), once they are written where the document lives; `historyCleared` is the copy's
234
+ * report's.
235
+ *
236
+ * # Errors
237
+ * `nested-transaction`, `saved-not-rebased`; `not-rebased` when `bytes` can't be read.
238
+ * @param {Uint8Array} bytes
239
+ * @param {boolean} historyCleared
240
+ */
241
+ adoptCopy(bytes, historyCleared) {
242
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
243
+ const len0 = WASM_VECTOR_LEN;
244
+ let ret;
245
+ ret = wasm.wasmdocument_adoptCopy(this.__wbg_ptr, ptr0, len0, historyCleared);
246
+ if (ret[1]) {
247
+ throw takeFromExternrefTable0(ret[0]);
248
+ }
249
+ }
208
250
  /**
209
251
  * Applies an op log (`{ "v": 1, "ops": [ … ] }`) as one transaction.
210
252
  *
@@ -240,6 +282,24 @@ export class WasmDocument {
240
282
  }
241
283
  return takeFromExternrefTable0(ret[0]);
242
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
+ }
243
303
  /**
244
304
  * An extraction stepped a page at a time, whose models the host runs: each step returns
245
305
  * its progress, with the result it waits for under `request` (render that page at `dpi`,
@@ -259,6 +319,23 @@ export class WasmDocument {
259
319
  }
260
320
  return WasmExtractJob.__wrap(ret[0]);
261
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
+ }
262
339
  /**
263
340
  * The document's text for retrieval and LLMs, as one string: Markdown, plain text, the
264
341
  * `laminapdf.extract/1` JSON, or the chunks as a JSON array (the extract and text modules).
@@ -312,6 +389,21 @@ export class WasmDocument {
312
389
  }
313
390
  return takeFromExternrefTable0(ret[0]);
314
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
+ }
315
407
  /**
316
408
  * Whether the file is encrypted (it opened with its password, or the empty one).
317
409
  * @returns {boolean}
@@ -336,6 +428,42 @@ export class WasmDocument {
336
428
  }
337
429
  return ret[0] !== 0;
338
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
+ }
451
+ /**
452
+ * The document's metadata, read from Info and XMP together, with the fields where they
453
+ * disagree.
454
+ *
455
+ * # Errors
456
+ * Reading errors.
457
+ * @returns {DocumentMetadata}
458
+ */
459
+ metadata() {
460
+ let ret;
461
+ ret = wasm.wasmdocument_metadata(this.__wbg_ptr);
462
+ if (ret[2]) {
463
+ throw takeFromExternrefTable0(ret[1]);
464
+ }
465
+ return takeFromExternrefTable0(ret[0]);
466
+ }
339
467
  /**
340
468
  * The named destination `name`, or `undefined` when the document has none by that name or
341
469
  * it names no page here (the extract and text modules).
@@ -355,6 +483,21 @@ export class WasmDocument {
355
483
  }
356
484
  return takeFromExternrefTable0(ret[0]);
357
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
+ }
358
501
  /**
359
502
  * Opens a document from its bytes.
360
503
  *
@@ -411,6 +554,23 @@ export class WasmDocument {
411
554
  }
412
555
  return takeFromExternrefTable0(ret[0]);
413
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
+ }
414
574
  /**
415
575
  * A handle on the page with `id` (`p12.0`).
416
576
  *
@@ -507,6 +667,22 @@ export class WasmDocument {
507
667
  }
508
668
  return WasmPage.__wrap(ret[0]);
509
669
  }
670
+ /**
671
+ * How a save with `options` would go, without saving.
672
+ *
673
+ * # Errors
674
+ * `invalid-argument` / `unknown-option` for bad options; reading errors.
675
+ * @param {SaveOptionsInit | undefined} options
676
+ * @returns {PlannedSaveJs}
677
+ */
678
+ plan(options) {
679
+ let ret;
680
+ ret = wasm.wasmdocument_plan(this.__wbg_ptr, options);
681
+ if (ret[2]) {
682
+ throw takeFromExternrefTable0(ret[1]);
683
+ }
684
+ return takeFromExternrefTable0(ret[0]);
685
+ }
510
686
  /**
511
687
  * The document's properties (the extract and text modules). Reads every object once.
512
688
  *
@@ -582,6 +758,23 @@ export class WasmDocument {
582
758
  wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
583
759
  }
584
760
  }
761
+ /**
762
+ * Writes what `save` would and leaves the document as it was: not rebased, its changes
763
+ * still unsaved, the save-time stamp in the copy only (Save a copy).
764
+ *
765
+ * # Errors
766
+ * As `save`; the document is unchanged either way.
767
+ * @param {SaveOptionsInit | undefined} options
768
+ * @returns {{ bytes: Uint8Array<ArrayBuffer>; report: SaveReportJs }}
769
+ */
770
+ saveCopy(options) {
771
+ let ret;
772
+ ret = wasm.wasmdocument_saveCopy(this.__wbg_ptr, options);
773
+ if (ret[2]) {
774
+ throw takeFromExternrefTable0(ret[1]);
775
+ }
776
+ return takeFromExternrefTable0(ret[0]);
777
+ }
585
778
  /**
586
779
  * A save as a job, stepped with a budget of work units (ADR 0028 §3, §4).
587
780
  *
@@ -614,6 +807,26 @@ export class WasmDocument {
614
807
  }
615
808
  return takeFromExternrefTable0(ret[0]);
616
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
+ }
617
830
  /**
618
831
  * The structure tree's top-level elements in reading order, or `undefined` without one (the
619
832
  * extract and text modules, beside `WasmPage.text`, whose runs it links by MCID).
@@ -630,6 +843,21 @@ export class WasmDocument {
630
843
  }
631
844
  return takeFromExternrefTable0(ret[0]);
632
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
+ }
633
861
  /**
634
862
  * Undoes the newest transaction: how it went and the pages it touched; `undefined` when
635
863
  * there is nothing to undo.
@@ -655,6 +883,37 @@ export class WasmDocument {
655
883
  ret = wasm.wasmdocument_warnings(this.__wbg_ptr);
656
884
  return WasmWarningCursor.__wrap(ret);
657
885
  }
886
+ /**
887
+ * The signature restrictions `op` would break if it were applied and saved.
888
+ *
889
+ * # Errors
890
+ * `invalid-argument` for a value that isn't an op; reading errors.
891
+ * @param {Op} op
892
+ * @returns {ViolationJs[]}
893
+ */
894
+ wouldViolate(op) {
895
+ let ret;
896
+ ret = wasm.wasmdocument_wouldViolate(this.__wbg_ptr, op);
897
+ if (ret[2]) {
898
+ throw takeFromExternrefTable0(ret[1]);
899
+ }
900
+ return takeFromExternrefTable0(ret[0]);
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
+ }
658
917
  }
659
918
  if (Symbol.dispose) WasmDocument.prototype[Symbol.dispose] = WasmDocument.prototype.free;
660
919
 
@@ -825,6 +1084,44 @@ export class WasmImage {
825
1084
  }
826
1085
  if (Symbol.dispose) WasmImage.prototype[Symbol.dispose] = WasmImage.prototype.free;
827
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
+
828
1125
  /**
829
1126
  * A page of a [`WasmDocument`], held by its ID (F2): moving pages doesn't retarget it.
830
1127
  */
@@ -1579,6 +1876,27 @@ export function hasText() {
1579
1876
  return ret !== 0;
1580
1877
  }
1581
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
+
1582
1900
  /**
1583
1901
  * The crate version (`@laminapdf/wasm`'s).
1584
1902
  * @returns {string}
@@ -1623,14 +1941,48 @@ function __wbg_get_imports() {
1623
1941
  __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
1624
1942
  throw new Error(getStringFromWasm0(arg0, arg1));
1625
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
+ },
1626
1966
  __wbg_keys_440be172f17c0265: function(arg0) {
1627
1967
  const ret = Object.keys(arg0);
1628
1968
  return ret;
1629
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
+ },
1630
1978
  __wbg_new_617a8cdb8bb1130e: function() {
1631
1979
  const ret = new Object();
1632
1980
  return ret;
1633
1981
  },
1982
+ __wbg_new_ee2291f50781bf1d: function() {
1983
+ const ret = new Array();
1984
+ return ret;
1985
+ },
1634
1986
  __wbg_new_from_slice_37a3c3a194266cb8: function(arg0, arg1) {
1635
1987
  const ret = new Uint32Array(getArrayU32FromWasm0(arg0, arg1));
1636
1988
  return ret;
@@ -1651,6 +2003,13 @@ function __wbg_get_imports() {
1651
2003
  const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
1652
2004
  return ret;
1653
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
+ },
1654
2013
  __wbg_set_145a351398b48c65: function() { return handleError(function (arg0, arg1, arg2) {
1655
2014
  const ret = Reflect.set(arg0, arg1, arg2);
1656
2015
  return ret;
@@ -1666,6 +2025,10 @@ function __wbg_get_imports() {
1666
2025
  const ret = JSON.stringify(arg0);
1667
2026
  return ret;
1668
2027
  }, arguments); },
2028
+ __wbg_wasmdocument_new: function(arg0) {
2029
+ const ret = WasmDocument.__wrap(arg0);
2030
+ return ret;
2031
+ },
1669
2032
  __wbindgen_generic_0000000000000001: function(arg0) {
1670
2033
  // Cast intrinsic for `F64 -> Externref`.
1671
2034
  const ret = arg0;
@@ -1721,6 +2084,11 @@ const WasmImageFinalization = (typeof FinalizationRegistry === 'undefined')
1721
2084
  : new FinalizationRegistry(({ ptr, instance }) => {
1722
2085
  if (instance === __wbg_instance_id) wasm.__wbg_wasmimage_free(ptr, 1);
1723
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
+ });
1724
2092
  const WasmPageFinalization = (typeof FinalizationRegistry === 'undefined')
1725
2093
  ? { register: () => {}, unregister: () => {} }
1726
2094
  : new FinalizationRegistry(({ ptr, instance }) => {
Binary file
Binary file