@laminapdf/wasm 0.2.0-alpha.5 → 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.
@@ -94,6 +118,25 @@ export class WasmBuilder {
94
118
  }
95
119
  return WasmFont.__wrap(ret[0]);
96
120
  }
121
+ /**
122
+ * Loads face `index` (from 0) of a font collection (`.ttc`, `.otc`) and registers it.
123
+ *
124
+ * # Errors
125
+ * `builder-finished`; `invalid-font`, `collection-index` (no such face), `font-not-embeddable`.
126
+ * @param {Uint8Array} bytes
127
+ * @param {number} index
128
+ * @returns {WasmFont}
129
+ */
130
+ fontCollection(bytes, index) {
131
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
132
+ const len0 = WASM_VECTOR_LEN;
133
+ let ret;
134
+ ret = wasm.wasmbuilder_fontCollection(this.__wbg_ptr, ptr0, len0, index);
135
+ if (ret[2]) {
136
+ throw takeFromExternrefTable0(ret[1]);
137
+ }
138
+ return WasmFont.__wrap(ret[0]);
139
+ }
97
140
  /**
98
141
  * The natural language (`/Lang`), a BCP 47 tag.
99
142
  *
@@ -110,6 +153,31 @@ export class WasmBuilder {
110
153
  throw takeFromExternrefTable0(ret[0]);
111
154
  }
112
155
  }
156
+ /**
157
+ * Lays `markdown` out as tagged pages that flow, after any pages already added; its front
158
+ * matter's title, language, author and subject become the document's. Its warnings
159
+ * (`markdown-html-ignored`, `markdown-image-missing`, the flow's) are the finished
160
+ * document's.
161
+ *
162
+ * # Errors
163
+ * `builder-finished`; `unknown-option`, `invalid-argument`; `missing-glyph`,
164
+ * `flow-content-too-large`; `unknown-font` at `finish` for a font another builder registered.
165
+ * @param {string} markdown
166
+ * @param {WasmMarkdownOptions} resources
167
+ * @param {MarkdownOptionsInit | undefined} options
168
+ * @returns {MarkdownReportJs}
169
+ */
170
+ markdown(markdown, resources, options) {
171
+ const ptr0 = passStringToWasm0(markdown, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
172
+ const len0 = WASM_VECTOR_LEN;
173
+ _assertClass(resources, WasmMarkdownOptions);
174
+ let ret;
175
+ ret = wasm.wasmbuilder_markdown(this.__wbg_ptr, ptr0, len0, resources.__wbg_ptr, options);
176
+ if (ret[2]) {
177
+ throw takeFromExternrefTable0(ret[1]);
178
+ }
179
+ return takeFromExternrefTable0(ret[0]);
180
+ }
113
181
  /**
114
182
  * The metadata, written as the Info dictionary and an XMP packet.
115
183
  *
@@ -243,6 +311,25 @@ export class WasmDocument {
243
311
  wasm.__wbg_wasmdocument_free(ptr, 0);
244
312
 
245
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
+ }
246
333
  /**
247
334
  * Applies an op log (`{ "v": 1, "ops": [ … ] }`) as one transaction.
248
335
  *
@@ -350,6 +437,15 @@ export class WasmDocument {
350
437
  }
351
438
  return takeFromExternrefTable0(ret[0]);
352
439
  }
440
+ /**
441
+ * Whether the file is encrypted (it opened with its password, or the empty one).
442
+ * @returns {boolean}
443
+ */
444
+ isEncrypted() {
445
+ let ret;
446
+ ret = wasm.wasmdocument_isEncrypted(this.__wbg_ptr);
447
+ return ret !== 0;
448
+ }
353
449
  /**
354
450
  * Whether the document says it is tagged (`/MarkInfo /Marked true`; the extract and text modules).
355
451
  *
@@ -365,6 +461,22 @@ export class WasmDocument {
365
461
  }
366
462
  return ret[0] !== 0;
367
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
+ }
368
480
  /**
369
481
  * The named destination `name`, or `undefined` when the document has none by that name or
370
482
  * it names no page here (the extract and text modules).
@@ -536,6 +648,22 @@ export class WasmDocument {
536
648
  }
537
649
  return WasmPage.__wrap(ret[0]);
538
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
+ }
539
667
  /**
540
668
  * The document's properties (the extract and text modules). Reads every object once.
541
669
  *
@@ -568,11 +696,12 @@ export class WasmDocument {
568
696
  }
569
697
  }
570
698
  /**
571
- * Redoes the newest undone transaction; `undefined` when there is nothing to redo.
699
+ * Redoes the newest undone transaction: how it went and the pages it touched; `undefined`
700
+ * when there is nothing to redo.
572
701
  *
573
702
  * # Errors
574
703
  * As [`WasmDocument::undo`].
575
- * @returns {UndoOutcomeJs | undefined}
704
+ * @returns {RevertedJs | undefined}
576
705
  */
577
706
  redo() {
578
707
  let ret;
@@ -582,6 +711,23 @@ export class WasmDocument {
582
711
  }
583
712
  return takeFromExternrefTable0(ret[0]);
584
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
+ }
585
731
  /**
586
732
  * A save as a job, stepped with a budget of work units (ADR 0028 §3, §4).
587
733
  *
@@ -631,11 +777,12 @@ export class WasmDocument {
631
777
  return takeFromExternrefTable0(ret[0]);
632
778
  }
633
779
  /**
634
- * Undoes the newest transaction; `undefined` when there is nothing to undo.
780
+ * Undoes the newest transaction: how it went and the pages it touched; `undefined` when
781
+ * there is nothing to undo.
635
782
  *
636
783
  * # Errors
637
784
  * `nested-transaction`, `saved-not-rebased`; reading errors.
638
- * @returns {UndoOutcomeJs | undefined}
785
+ * @returns {RevertedJs | undefined}
639
786
  */
640
787
  undo() {
641
788
  let ret;
@@ -654,6 +801,22 @@ export class WasmDocument {
654
801
  ret = wasm.wasmdocument_warnings(this.__wbg_ptr);
655
802
  return WasmWarningCursor.__wrap(ret);
656
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
+ }
657
820
  }
658
821
  if (Symbol.dispose) WasmDocument.prototype[Symbol.dispose] = WasmDocument.prototype.free;
659
822
 
@@ -724,6 +887,57 @@ export class WasmExtractJob {
724
887
  }
725
888
  if (Symbol.dispose) WasmExtractJob.prototype[Symbol.dispose] = WasmExtractJob.prototype.free;
726
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
+
727
941
  /**
728
942
  * A font registered with a [`WasmBuilder`].
729
943
  */
@@ -893,6 +1107,65 @@ export class WasmImage {
893
1107
  }
894
1108
  if (Symbol.dispose) WasmImage.prototype[Symbol.dispose] = WasmImage.prototype.free;
895
1109
 
1110
+ /**
1111
+ * The fonts and images of a Markdown build, by role and by the target the Markdown names.
1112
+ */
1113
+ export class WasmMarkdownOptions {
1114
+ __destroy_into_raw() {
1115
+ const ptr = this.__wbg_ptr;
1116
+ this.__wbg_ptr = 0;
1117
+ WasmMarkdownOptionsFinalization.unregister(this);
1118
+ return ptr;
1119
+ }
1120
+ free() {
1121
+ const ptr = this.__destroy_into_raw();
1122
+ wasm.__wbg_wasmmarkdownoptions_free(ptr, 0);
1123
+
1124
+ }
1125
+ /**
1126
+ * `font` for `role`: `regular`, `bold` (headings too), `italic`, `boldItalic`, `mono`, or
1127
+ * `fallback` (each call adds one) for characters the others lack.
1128
+ *
1129
+ * # Errors
1130
+ * `invalid-argument` for another role.
1131
+ * @param {string} role
1132
+ * @param {WasmFont} font
1133
+ */
1134
+ font(role, font) {
1135
+ const ptr0 = passStringToWasm0(role, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1136
+ const len0 = WASM_VECTOR_LEN;
1137
+ _assertClass(font, WasmFont);
1138
+ let ret;
1139
+ ret = wasm.wasmmarkdownoptions_font(this.__wbg_ptr, ptr0, len0, font.__wbg_ptr);
1140
+ if (ret[1]) {
1141
+ throw takeFromExternrefTable0(ret[0]);
1142
+ }
1143
+ }
1144
+ /**
1145
+ * `image` for the images whose target is `target`, as the Markdown writes it.
1146
+ * @param {string} target
1147
+ * @param {WasmImage} image
1148
+ */
1149
+ image(target, image) {
1150
+ const ptr0 = passStringToWasm0(target, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1151
+ const len0 = WASM_VECTOR_LEN;
1152
+ _assertClass(image, WasmImage);
1153
+ wasm.wasmmarkdownoptions_image(this.__wbg_ptr, ptr0, len0, image.__wbg_ptr);
1154
+ }
1155
+ /**
1156
+ * No fonts (the standard 14 Helvetica family and Courier) and no images.
1157
+ */
1158
+ constructor() {
1159
+ let ret;
1160
+ ret = wasm.wasmmarkdownoptions_new();
1161
+ this.__wbg_ptr = ret;
1162
+ Object.defineProperty(this, '__wbg_inst', { value: __wbg_instance_id, writable: true });
1163
+ WasmMarkdownOptionsFinalization.register(this, { ptr: ret, instance: __wbg_instance_id }, this);
1164
+ return this;
1165
+ }
1166
+ }
1167
+ if (Symbol.dispose) WasmMarkdownOptions.prototype[Symbol.dispose] = WasmMarkdownOptions.prototype.free;
1168
+
896
1169
  /**
897
1170
  * A page of a [`WasmDocument`], held by its ID (F2): moving pages doesn't retarget it.
898
1171
  */
@@ -1837,6 +2110,11 @@ const WasmExtractJobFinalization = (typeof FinalizationRegistry === 'undefined')
1837
2110
  : new FinalizationRegistry(({ ptr, instance }) => {
1838
2111
  if (instance === __wbg_instance_id) wasm.__wbg_wasmextractjob_free(ptr, 1);
1839
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
+ });
1840
2118
  const WasmFontFinalization = (typeof FinalizationRegistry === 'undefined')
1841
2119
  ? { register: () => {}, unregister: () => {} }
1842
2120
  : new FinalizationRegistry(({ ptr, instance }) => {
@@ -1847,6 +2125,11 @@ const WasmImageFinalization = (typeof FinalizationRegistry === 'undefined')
1847
2125
  : new FinalizationRegistry(({ ptr, instance }) => {
1848
2126
  if (instance === __wbg_instance_id) wasm.__wbg_wasmimage_free(ptr, 1);
1849
2127
  });
2128
+ const WasmMarkdownOptionsFinalization = (typeof FinalizationRegistry === 'undefined')
2129
+ ? { register: () => {}, unregister: () => {} }
2130
+ : new FinalizationRegistry(({ ptr, instance }) => {
2131
+ if (instance === __wbg_instance_id) wasm.__wbg_wasmmarkdownoptions_free(ptr, 1);
2132
+ });
1850
2133
  const WasmPageFinalization = (typeof FinalizationRegistry === 'undefined')
1851
2134
  ? { register: () => {}, unregister: () => {} }
1852
2135
  : 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.5",
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,
@@ -46,11 +52,11 @@
46
52
  "./package.json": "./package.json"
47
53
  },
48
54
  "devDependencies": {
49
- "@types/node": "26.6.5",
55
+ "@types/node": "26.6.6",
50
56
  "ajv": "8.20.0",
51
57
  "esbuild": "0.28.2",
52
58
  "typescript": "7.0.2",
53
- "vitest": "5.0.5",
59
+ "vitest": "5.1.0",
54
60
  "@laminapdf/test-utils": "0.0.0"
55
61
  },
56
62
  "publishConfig": {