@laminapdf/wasm 0.2.0-alpha.4 → 0.2.0-alpha.6

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.
@@ -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` and `invalid-argument` for a wrong size.
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
@@ -32,6 +32,18 @@ export interface Diagnostic {
32
32
  }
33
33
 
34
34
 
35
+
36
+ /** One link on a page, in page space, and what following it does (by `kind`). */
37
+ export type PageLinkJs = {
38
+ /** Its rectangle: `[x0, y0, x1, y1]`, top-left and bottom-right. */
39
+ rect: [number, number, number, number];
40
+ /** The areas that follow it, eight numbers per area; absent when the rectangle is the area. */
41
+ quads?: number[];
42
+ /** Its description (`/Contents`, document text). */
43
+ contents?: string;
44
+ } & LinkToJs;
45
+
46
+
35
47
  /**
36
48
  * A colour for text options (the text module's records).
37
49
  */
@@ -42,6 +54,112 @@ export type ColorInit = number[] | string;
42
54
  */
43
55
  export type ProfileInit = "PDF/UA-1" | "PDF/A-2b" | "PDF/A-2u" | "PDF/A-3b";
44
56
 
57
+ /**
58
+ * A document's properties, for a properties view.
59
+ */
60
+ export interface PropertiesJs {
61
+ /**
62
+ * `/Title`.
63
+ */
64
+ title?: string;
65
+ /**
66
+ * `/Author`.
67
+ */
68
+ author?: string;
69
+ /**
70
+ * `/Subject`.
71
+ */
72
+ subject?: string;
73
+ /**
74
+ * `/Keywords`.
75
+ */
76
+ keywords?: string;
77
+ /**
78
+ * `/Creator`: the application the document was made with.
79
+ */
80
+ creator?: string;
81
+ /**
82
+ * `/Producer`: the application that wrote the PDF.
83
+ */
84
+ producer?: string;
85
+ /**
86
+ * `/CreationDate` as ISO 8601.
87
+ */
88
+ created?: string;
89
+ /**
90
+ * `/ModDate` as ISO 8601.
91
+ */
92
+ modified?: string;
93
+ /**
94
+ * The XMP packet as text.
95
+ */
96
+ xmp?: string;
97
+ /**
98
+ * The PDF version.
99
+ */
100
+ version?: string;
101
+ /**
102
+ * The number of pages.
103
+ */
104
+ pageCount: number;
105
+ /**
106
+ * The file's size in bytes.
107
+ */
108
+ fileSize: number;
109
+ /**
110
+ * The file is linearized ("fast web view").
111
+ */
112
+ linearized: boolean;
113
+ /**
114
+ * The catalog says the document is tagged.
115
+ */
116
+ tagged: boolean;
117
+ /**
118
+ * How the file is encrypted; absent when it isn't.
119
+ */
120
+ encryption?: EncryptionJs;
121
+ /**
122
+ * The fonts the pages use.
123
+ */
124
+ fonts: FontJs[];
125
+ /**
126
+ * The signatures present, not verified.
127
+ */
128
+ signatures: number;
129
+ /**
130
+ * The signature fields' full names.
131
+ */
132
+ signatureFields: string[];
133
+ /**
134
+ * What the document holds besides its pages.
135
+ */
136
+ contains: ContainsJs;
137
+ }
138
+
139
+ /**
140
+ * A font's encoding: a named one (`WinAnsiEncoding`, `Identity-H`), or the font's own.
141
+ */
142
+ export type EncodingJs = { kind: "named"; name: string } | { kind: "custom" };
143
+
144
+ /**
145
+ * A header or footer: text at the start, centre and end, with `{page}`, `{pages}`, `{section}`
146
+ * and `{title}` filled in.
147
+ */
148
+ export interface PageRegionInit {
149
+ /**
150
+ * At the start of the line.
151
+ */
152
+ start?: string;
153
+ /**
154
+ * Centred.
155
+ */
156
+ center?: string;
157
+ /**
158
+ * At the end of the line.
159
+ */
160
+ end?: string;
161
+ }
162
+
45
163
  /**
46
164
  * A job's progress (`laminapdf::Step::Progress`).
47
165
  */
@@ -349,11 +467,55 @@ export interface SetInfo {
349
467
  at?: string;
350
468
  }
351
469
 
470
+ /**
471
+ * How `markdown` lays a document out.
472
+ */
473
+ export interface MarkdownOptionsInit {
474
+ /**
475
+ * The body text's size in points (10.5 by default); headings scale from it.
476
+ */
477
+ size?: number;
478
+ /**
479
+ * A contents page listing headings of levels 1 to `contents`, at the start.
480
+ */
481
+ contents?: number;
482
+ /**
483
+ * The pages (by default A4, 56-point margins, "Page {page} of {pages}" in the footer).
484
+ */
485
+ page?: PageTemplateInit;
486
+ }
487
+
352
488
  /**
353
489
  * How a destination shows its page (§12.3.2.2).
354
490
  */
355
491
  export type FitInit = { type: "page" } | { type: "width"; top?: number } | { type: "height"; left?: number } | { type: "xyz"; left?: number; top?: number; zoom?: number } | { type: "rect"; x: number; y: number; width: number; height: number } | { type: "bounds" };
356
492
 
493
+ /**
494
+ * How a file is encrypted, and what its author permits.
495
+ */
496
+ export interface EncryptionJs {
497
+ /**
498
+ * `/V`.
499
+ */
500
+ version: number;
501
+ /**
502
+ * `/R`.
503
+ */
504
+ revision: number;
505
+ /**
506
+ * The key length in bits.
507
+ */
508
+ keyBits: number;
509
+ /**
510
+ * The cipher streams use.
511
+ */
512
+ cipher: CipherJs;
513
+ /**
514
+ * What `/P` permits; absent when the handler gives no permissions.
515
+ */
516
+ permissions?: PermissionsJs;
517
+ }
518
+
357
519
  /**
358
520
  * How a run of text is drawn.
359
521
  */
@@ -518,6 +680,32 @@ export interface StructureNodeJs {
518
680
  kids: StructureKidJs[];
519
681
  }
520
682
 
683
+ /**
684
+ * One font the document uses.
685
+ */
686
+ export interface FontJs {
687
+ /**
688
+ * Its name without a subset tag.
689
+ */
690
+ name?: string;
691
+ /**
692
+ * `Type0`, `Type1`, `MMType1`, `Type3` or `TrueType`.
693
+ */
694
+ kind?: string;
695
+ /**
696
+ * The file holds the font.
697
+ */
698
+ embedded: boolean;
699
+ /**
700
+ * The file holds only the glyphs used.
701
+ */
702
+ subset: boolean;
703
+ /**
704
+ * Its encoding; absent when the font gives none.
705
+ */
706
+ encoding?: EncodingJs;
707
+ }
708
+
521
709
  /**
522
710
  * One outline item and its children.
523
711
  */
@@ -905,6 +1093,11 @@ export interface DocumentInfoJs {
905
1093
  */
906
1094
  export type PdfVersionInit = "1.4" | "1.5" | "1.6" | "1.7" | "2.0";
907
1095
 
1096
+ /**
1097
+ * The cipher a file's streams use (ISO 32000-2 §7.6): the one list, which the `.d.ts` gets as a union.
1098
+ */
1099
+ export type CipherJs = "rc4" | "aes-128" | "aes-256" | "identity" | "other";
1100
+
908
1101
  /**
909
1102
  * The cross-reference form.
910
1103
  */
@@ -978,6 +1171,32 @@ export interface ModelsInit {
978
1171
  langs?: string[];
979
1172
  }
980
1173
 
1174
+ /**
1175
+ * The pages a Markdown document flows through.
1176
+ */
1177
+ export interface PageTemplateInit {
1178
+ /**
1179
+ * The page's width and height in points.
1180
+ */
1181
+ size: [number, number];
1182
+ /**
1183
+ * Top, right, bottom and left margins in points (72 each by default).
1184
+ */
1185
+ margins?: [number, number, number, number];
1186
+ /**
1187
+ * The header.
1188
+ */
1189
+ header?: PageRegionInit;
1190
+ /**
1191
+ * The footer.
1192
+ */
1193
+ footer?: PageRegionInit;
1194
+ /**
1195
+ * The size of the header and footer text, in the regular font (8 points by default).
1196
+ */
1197
+ furnitureSize?: number;
1198
+ }
1199
+
981
1200
  /**
982
1201
  * The pages an edit touched.
983
1202
  */
@@ -986,6 +1205,11 @@ export interface EditedJs {
986
1205
  * IDs of the pages whose content or attributes changed.
987
1206
  */
988
1207
  touchedPages: string[];
1208
+ /**
1209
+ * Whether the edit changed the document: one that only set values they already had leaves
1210
+ * no step to undo.
1211
+ */
1212
+ changed: boolean;
989
1213
  }
990
1214
 
991
1215
  /**
@@ -1003,11 +1227,77 @@ export type SaveModeJs = "auto" | "incremental" | "fullRewrite";
1003
1227
  */
1004
1228
  export type ExtractFormat = "markdown" | "json" | "text" | "chunks";
1005
1229
 
1230
+ /**
1231
+ * What `markdown` added.
1232
+ */
1233
+ export interface MarkdownReportJs {
1234
+ /**
1235
+ * The pages it added, in order, by ID.
1236
+ */
1237
+ pages: string[];
1238
+ }
1239
+
1006
1240
  /**
1007
1241
  * What `provide` takes.
1008
1242
  */
1009
1243
  export type ModelResultInit = { kind: "layout"; regions: RegionInit[] } | { kind: "ocr"; words: WordInit[] };
1010
1244
 
1245
+ /**
1246
+ * What a document holds besides its pages.
1247
+ */
1248
+ export interface ContainsJs {
1249
+ /**
1250
+ * Some action runs JavaScript.
1251
+ */
1252
+ javascript: boolean;
1253
+ /**
1254
+ * The number of embedded files.
1255
+ */
1256
+ attachments: number;
1257
+ /**
1258
+ * The document has a form with at least one field.
1259
+ */
1260
+ forms: boolean;
1261
+ }
1262
+
1263
+ /**
1264
+ * What a file's author permits: a request to readers, not a lock.
1265
+ */
1266
+ export interface PermissionsJs {
1267
+ /**
1268
+ * Printing.
1269
+ */
1270
+ print: boolean;
1271
+ /**
1272
+ * Printing at full quality.
1273
+ */
1274
+ printHighQuality: boolean;
1275
+ /**
1276
+ * Changing the contents.
1277
+ */
1278
+ modify: boolean;
1279
+ /**
1280
+ * Copying text and graphics.
1281
+ */
1282
+ copy: boolean;
1283
+ /**
1284
+ * Adding or changing annotations.
1285
+ */
1286
+ annotate: boolean;
1287
+ /**
1288
+ * Filling form fields.
1289
+ */
1290
+ fillForms: boolean;
1291
+ /**
1292
+ * Extracting text for accessibility.
1293
+ */
1294
+ accessibility: boolean;
1295
+ /**
1296
+ * Inserting, rotating or deleting pages.
1297
+ */
1298
+ assemble: boolean;
1299
+ }
1300
+
1011
1301
  /**
1012
1302
  * What a run measures.
1013
1303
  */
@@ -1067,6 +1357,25 @@ export interface SaveReportJs {
1067
1357
  */
1068
1358
  export type OutputJs = "whole" | "appendedOnly";
1069
1359
 
1360
+ /**
1361
+ * What an undo or redo did (`laminapdf::Reverted`).
1362
+ */
1363
+ export interface RevertedJs {
1364
+ /**
1365
+ * How it went.
1366
+ */
1367
+ outcome: UndoOutcomeJs;
1368
+ /**
1369
+ * IDs of the pages the undone or redone transaction touched: draw these again.
1370
+ */
1371
+ touchedPages: string[];
1372
+ }
1373
+
1374
+ /**
1375
+ * What following a link does, by `kind`.
1376
+ */
1377
+ export type LinkToJs = { kind: "dest"; target?: TargetJs } | { kind: "named"; name: string; target?: TargetJs } | { kind: "uri"; uri: string } | { kind: "remote"; file?: string } | { kind: "named-action"; name: string } | { kind: "unsupported"; action: string };
1378
+
1070
1379
  /**
1071
1380
  * What happens to hidden text and page furniture.
1072
1381
  */
@@ -1213,6 +1522,13 @@ export class WasmBuilder {
1213
1522
  * `builder-finished`; `invalid-font`, `font-not-embeddable`.
1214
1523
  */
1215
1524
  fontBytes(bytes: Uint8Array): WasmFont;
1525
+ /**
1526
+ * Loads face `index` (from 0) of a font collection (`.ttc`, `.otc`) and registers it.
1527
+ *
1528
+ * # Errors
1529
+ * `builder-finished`; `invalid-font`, `collection-index` (no such face), `font-not-embeddable`.
1530
+ */
1531
+ fontCollection(bytes: Uint8Array, index: number): WasmFont;
1216
1532
  /**
1217
1533
  * The natural language (`/Lang`), a BCP 47 tag.
1218
1534
  *
@@ -1220,6 +1536,17 @@ export class WasmBuilder {
1220
1536
  * `builder-finished`.
1221
1537
  */
1222
1538
  lang(lang: string): void;
1539
+ /**
1540
+ * Lays `markdown` out as tagged pages that flow, after any pages already added; its front
1541
+ * matter's title, language, author and subject become the document's. Its warnings
1542
+ * (`markdown-html-ignored`, `markdown-image-missing`, the flow's) are the finished
1543
+ * document's.
1544
+ *
1545
+ * # Errors
1546
+ * `builder-finished`; `unknown-option`, `invalid-argument`; `missing-glyph`,
1547
+ * `flow-content-too-large`; `unknown-font` at `finish` for a font another builder registered.
1548
+ */
1549
+ markdown(markdown: string, resources: WasmMarkdownOptions, options: MarkdownOptionsInit | undefined): MarkdownReportJs;
1223
1550
  /**
1224
1551
  * The metadata, written as the Info dictionary and an XMP packet.
1225
1552
  *
@@ -1322,6 +1649,10 @@ export class WasmDocument {
1322
1649
  * Reading errors.
1323
1650
  */
1324
1651
  info(): DocumentInfoJs;
1652
+ /**
1653
+ * Whether the file is encrypted (it opened with its password, or the empty one).
1654
+ */
1655
+ isEncrypted(): boolean;
1325
1656
  /**
1326
1657
  * Whether the document says it is tagged (`/MarkInfo /Marked true`; the extract and text modules).
1327
1658
  *
@@ -1390,6 +1721,13 @@ export class WasmDocument {
1390
1721
  * Reading errors.
1391
1722
  */
1392
1723
  pageInfos(): PageInfoJs[];
1724
+ /**
1725
+ * The visible links on page `index`, in annotation order (the extract and text modules).
1726
+ *
1727
+ * # Errors
1728
+ * `page-index-out-of-range`, `data-pending` and the reading errors.
1729
+ */
1730
+ pageLinks(index: number): PageLinkJs[];
1393
1731
  /**
1394
1732
  * A handle on page `index` that follows the page by its ID (F2).
1395
1733
  *
@@ -1397,6 +1735,13 @@ export class WasmDocument {
1397
1735
  * `page-index-out-of-range`; reading errors.
1398
1736
  */
1399
1737
  page(index: number): WasmPage;
1738
+ /**
1739
+ * The document's properties (the extract and text modules). Reads every object once.
1740
+ *
1741
+ * # Errors
1742
+ * `data-pending` and the reading errors.
1743
+ */
1744
+ properties(): PropertiesJs;
1400
1745
  /**
1401
1746
  * Rebases onto `bytes`, the output of a save whose rebase failed (`not-rebased`).
1402
1747
  *
@@ -1405,12 +1750,13 @@ export class WasmDocument {
1405
1750
  */
1406
1751
  rebase(bytes: Uint8Array): void;
1407
1752
  /**
1408
- * Redoes the newest undone transaction; `undefined` when there is nothing to redo.
1753
+ * Redoes the newest undone transaction: how it went and the pages it touched; `undefined`
1754
+ * when there is nothing to redo.
1409
1755
  *
1410
1756
  * # Errors
1411
1757
  * As [`WasmDocument::undo`].
1412
1758
  */
1413
- redo(): UndoOutcomeJs | undefined;
1759
+ redo(): RevertedJs | undefined;
1414
1760
  /**
1415
1761
  * A save as a job, stepped with a budget of work units (ADR 0028 §3, §4).
1416
1762
  *
@@ -1434,12 +1780,13 @@ export class WasmDocument {
1434
1780
  */
1435
1781
  structureTree(): StructureNodeJs[] | undefined;
1436
1782
  /**
1437
- * Undoes the newest transaction; `undefined` when there is nothing to undo.
1783
+ * Undoes the newest transaction: how it went and the pages it touched; `undefined` when
1784
+ * there is nothing to undo.
1438
1785
  *
1439
1786
  * # Errors
1440
1787
  * `nested-transaction`, `saved-not-rebased`; reading errors.
1441
1788
  */
1442
- undo(): UndoOutcomeJs | undefined;
1789
+ undo(): RevertedJs | undefined;
1443
1790
  /**
1444
1791
  * A cursor over the warnings so far (build warnings first), each as the §1 object.
1445
1792
  */
@@ -1537,6 +1884,30 @@ export class WasmImage {
1537
1884
  readonly width: number;
1538
1885
  }
1539
1886
 
1887
+ /**
1888
+ * The fonts and images of a Markdown build, by role and by the target the Markdown names.
1889
+ */
1890
+ export class WasmMarkdownOptions {
1891
+ free(): void;
1892
+ [Symbol.dispose](): void;
1893
+ /**
1894
+ * `font` for `role`: `regular`, `bold` (headings too), `italic`, `boldItalic`, `mono`, or
1895
+ * `fallback` (each call adds one) for characters the others lack.
1896
+ *
1897
+ * # Errors
1898
+ * `invalid-argument` for another role.
1899
+ */
1900
+ font(role: string, font: WasmFont): void;
1901
+ /**
1902
+ * `image` for the images whose target is `target`, as the Markdown writes it.
1903
+ */
1904
+ image(target: string, image: WasmImage): void;
1905
+ /**
1906
+ * No fonts (the standard 14 Helvetica family and Courier) and no images.
1907
+ */
1908
+ constructor();
1909
+ }
1910
+
1540
1911
  /**
1541
1912
  * A page of a [`WasmDocument`], held by its ID (F2): moving pages doesn't retarget it.
1542
1913
  */
@@ -1874,6 +2245,7 @@ export interface InitOutput {
1874
2245
  readonly __wbg_wasmextractjob_free: (a: number, b: number) => void;
1875
2246
  readonly __wbg_wasmfont_free: (a: number, b: number) => void;
1876
2247
  readonly __wbg_wasmimage_free: (a: number, b: number) => void;
2248
+ readonly __wbg_wasmmarkdownoptions_free: (a: number, b: number) => void;
1877
2249
  readonly __wbg_wasmpage_free: (a: number, b: number) => void;
1878
2250
  readonly __wbg_wasmpagebuilder_free: (a: number, b: number) => void;
1879
2251
  readonly __wbg_wasmsavejob_free: (a: number, b: number) => void;
@@ -1886,7 +2258,9 @@ export interface InitOutput {
1886
2258
  readonly wasmbuilder_destination: (a: number, b: number, c: number, d: number, e: any) => [number, number];
1887
2259
  readonly wasmbuilder_finish: (a: number) => [number, number, number];
1888
2260
  readonly wasmbuilder_fontBytes: (a: number, b: number, c: number) => [number, number, number];
2261
+ readonly wasmbuilder_fontCollection: (a: number, b: number, c: number, d: number) => [number, number, number];
1889
2262
  readonly wasmbuilder_lang: (a: number, b: number, c: number) => [number, number];
2263
+ readonly wasmbuilder_markdown: (a: number, b: number, c: number, d: number, e: any) => [number, number, number];
1890
2264
  readonly wasmbuilder_metadata: (a: number, b: any) => [number, number];
1891
2265
  readonly wasmbuilder_new: (a: any) => [number, number, number];
1892
2266
  readonly wasmbuilder_outline: (a: number, b: any) => [number, number, number];
@@ -1900,6 +2274,7 @@ export interface InitOutput {
1900
2274
  readonly wasmdocument_extractJob: (a: number, b: any) => [number, number, number];
1901
2275
  readonly wasmdocument_hasUnsavedChanges: (a: number) => number;
1902
2276
  readonly wasmdocument_info: (a: number) => [number, number, number];
2277
+ readonly wasmdocument_isEncrypted: (a: number) => number;
1903
2278
  readonly wasmdocument_isTagged: (a: number) => [number, number, number];
1904
2279
  readonly wasmdocument_namedDestination: (a: number, b: number, c: number) => [number, number, number];
1905
2280
  readonly wasmdocument_openBytes: (a: number, b: number, c: any) => [number, number, number];
@@ -1910,6 +2285,8 @@ export interface InitOutput {
1910
2285
  readonly wasmdocument_pageCount: (a: number) => [number, number, number];
1911
2286
  readonly wasmdocument_pageInfo: (a: number, b: number) => [number, number, number];
1912
2287
  readonly wasmdocument_pageInfos: (a: number) => [number, number, number];
2288
+ readonly wasmdocument_pageLinks: (a: number, b: number) => [number, number, number];
2289
+ readonly wasmdocument_properties: (a: number) => [number, number, number];
1913
2290
  readonly wasmdocument_rebase: (a: number, b: number, c: number) => [number, number];
1914
2291
  readonly wasmdocument_redo: (a: number) => [number, number, number];
1915
2292
  readonly wasmdocument_save: (a: number, b: any) => [number, number, number];
@@ -1928,6 +2305,9 @@ export interface InitOutput {
1928
2305
  readonly wasmimage_png: (a: number, b: number) => [number, number, number];
1929
2306
  readonly wasmimage_rgba: (a: number, b: number, c: number, d: number) => [number, number, number];
1930
2307
  readonly wasmimage_width: (a: number) => number;
2308
+ readonly wasmmarkdownoptions_font: (a: number, b: number, c: number, d: number) => [number, number];
2309
+ readonly wasmmarkdownoptions_image: (a: number, b: number, c: number, d: number) => void;
2310
+ readonly wasmmarkdownoptions_new: () => number;
1931
2311
  readonly wasmpage_id: (a: number) => [number, number];
1932
2312
  readonly wasmpage_index: (a: number) => [number, number, number];
1933
2313
  readonly wasmpage_info: (a: number) => [number, number, number];