@build-qube/papyra-native-wasm32-wasi 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@build-qube/papyra-native-wasm32-wasi",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "main": "papyra.wasi.cjs",
5
5
  "files": [
6
6
  "papyra.wasm32-wasi.wasm",
package/papyra.wasi.d.cts CHANGED
@@ -37,18 +37,18 @@ export declare class PdfDocument {
37
37
  get pdfVersion(): string | null
38
38
  pageSize(index: number): PageDimensions
39
39
  /** Render one page on the calling thread. Blocks; prefer `renderPageAsync`. */
40
- renderPage(index: number, dpi?: number | undefined | null): RenderedPage
40
+ renderPage(index: number, dpi?: number | undefined | null, annotations?: boolean | undefined | null): RenderedPage
41
41
  /** Render one page off the JS thread. Several of these run concurrently. */
42
- renderPageAsync(index: number, dpi?: number | undefined | null): Promise<RenderedPage>
42
+ renderPageAsync(index: number, dpi?: number | undefined | null, annotations?: boolean | undefined | null): Promise<RenderedPage>
43
43
  /** Render one page and keep it in Rust, for encoding. The pixels never reach JS. */
44
- renderPageImageAsync(index: number, dpi?: number | undefined | null, signal?: AbortSignal | undefined | null): Promise<PageImage>
44
+ renderPageImageAsync(index: number, dpi?: number | undefined | null, annotations?: boolean | undefined | null, signal?: AbortSignal | undefined | null): Promise<PageImage>
45
45
  /**
46
46
  * Convert one page to a standalone SVG document, off the JS thread.
47
47
  *
48
48
  * There is no DPI: an SVG carries the page's own point dimensions and rasterises at
49
49
  * whatever size it is drawn.
50
50
  */
51
- renderPageSvgAsync(index: number, whiteBackground?: boolean | undefined | null, signal?: AbortSignal | undefined | null): Promise<string>
51
+ renderPageSvgAsync(index: number, whiteBackground?: boolean | undefined | null, annotations?: boolean | undefined | null, signal?: AbortSignal | undefined | null): Promise<string>
52
52
  /** Extract the text of one page, off the JS thread. */
53
53
  pageTextAsync(index: number): Promise<PageText>
54
54
  /** Extract `[start, end)` in one async task, parallelised internally with rayon. */
@@ -60,6 +60,22 @@ export declare class PdfDocument {
60
60
  * common case.
61
61
  */
62
62
  outline(): Promise<Array<OutlineEntry>>
63
+ /**
64
+ * Read the document structure tree (tagged PDF), in pre-order.
65
+ *
66
+ * Resolves to an empty array when the document is untagged, which is the common
67
+ * case. Join to text through `TextLine.mcid` and `StructEntry.content`.
68
+ */
69
+ structTree(): Promise<Array<StructEntry>>
70
+ /**
71
+ * List the files embedded in the document, in the order it files them.
72
+ *
73
+ * Resolves to an empty array when there are none, which is the common case.
74
+ * Metadata only — fetch the bytes with `attachmentData`.
75
+ */
76
+ attachments(): Promise<Array<Attachment>>
77
+ /** Decompress one embedded file, by its index in `attachments`. */
78
+ attachmentData(index: number): Promise<Uint8Array>
63
79
  /**
64
80
  * Read the document information dictionary.
65
81
  *
@@ -79,7 +95,32 @@ export declare class PdfDocument {
79
95
  */
80
96
  pageLabels(): Promise<Array<string>>
81
97
  /** Render `[start, end)` in one async task, parallelised internally with rayon. */
82
- renderPagesAsync(start: number, end: number, dpi?: number | undefined | null): Promise<Array<RenderedPage>>
98
+ renderPagesAsync(start: number, end: number, dpi?: number | undefined | null, annotations?: boolean | undefined | null): Promise<Array<RenderedPage>>
99
+ }
100
+
101
+ /**
102
+ * One file embedded in the document. Metadata only; the bytes come from
103
+ * `attachmentData`.
104
+ */
105
+ export interface Attachment {
106
+ /** The name to save the file under — `/UF`, else `/F`, else its key in the tree. */
107
+ name: string
108
+ /** The document's own description of what the file is for. */
109
+ description?: string
110
+ /** e.g. `"application/xml"`. Absent more often than not. */
111
+ mediaType?: string
112
+ /** Length in bytes, uncompressed, as the document claims it. A hint, not a promise. */
113
+ size?: number
114
+ /** ISO 8601. */
115
+ created?: string
116
+ /** ISO 8601. */
117
+ modified?: string
118
+ /**
119
+ * `Source`, `Data`, `Alternative`, `Supplement`, `EncryptedPayload` or
120
+ * `Unspecified` — what the file is to the document. A ZUGFeRD invoice's XML is
121
+ * `Alternative` or `Data`.
122
+ */
123
+ relationship?: string
83
124
  }
84
125
 
85
126
  /** Name of the rendering backend, currently always `"hayro"`. */
@@ -128,6 +169,18 @@ export declare const enum ImageFormat {
128
169
  Jpeg = 'jpeg'
129
170
  }
130
171
 
172
+ /**
173
+ * The outline walk, off the JS thread.
174
+ *
175
+ * One run of page content owned by a structure element.
176
+ */
177
+ export interface MarkedContent {
178
+ /** 0-based page index. */
179
+ page: number
180
+ /** Matches `TextLine.mcid` on that page. */
181
+ mcid: number
182
+ }
183
+
131
184
  /**
132
185
  * Where an outline entry points. Coordinates are PDF points from the page's
133
186
  * bottom-left; `null` means "leave this axis unchanged".
@@ -225,6 +278,26 @@ export declare function reserveMemory(megabytes: number): number
225
278
  /** `"native"` or `"wasm"`. The wrapper uses this to pick a concurrency strategy. */
226
279
  export declare function runtime(): string
227
280
 
281
+ /** One structure-tree element. Flat and in pre-order; `level` carries the tree. */
282
+ export interface StructEntry {
283
+ /** Standard structure type, after `/RoleMap`: `"H1"`, `"P"`, `"Table"`, `"TD"`, … */
284
+ role: string
285
+ /** The document's own tag, before `/RoleMap`. Equal to `role` unless remapped. */
286
+ rawRole: string
287
+ /** Nesting depth. Top-level elements are 0. */
288
+ level: number
289
+ /** Content this element owns directly. Empty for a pure container. */
290
+ content: Array<MarkedContent>
291
+ /** `/Alt` — replacement text for a figure. */
292
+ alt?: string
293
+ /** `/ActualText` — text replacing the content rather than describing it. */
294
+ actualText?: string
295
+ /** `/Lang` — a BCP 47 tag for this subtree. */
296
+ lang?: string
297
+ /** `/T` — a human-readable title, e.g. a table's caption. */
298
+ title?: string
299
+ }
300
+
228
301
  /**
229
302
  * A run of glyphs sharing one baseline.
230
303
  *
@@ -250,4 +323,9 @@ export interface TextLine {
250
323
  ascent: number
251
324
  /** Extent below the baseline. */
252
325
  descent: number
326
+ /**
327
+ * Marked-content id of the line's first glyph, joining to `StructNode.content` on
328
+ * a tagged page. `null` on an untagged page, and for content outside any sequence.
329
+ */
330
+ mcid?: number
253
331
  }
Binary file