@build-qube/papyra-native-wasm32-wasi 0.2.0 → 0.4.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.4.0",
4
4
  "main": "papyra.wasi.cjs",
5
5
  "files": [
6
6
  "papyra.wasm32-wasi.wasm",
@@ -36,7 +36,7 @@
36
36
  "browser": "papyra.wasi-browser.js",
37
37
  "type": "module",
38
38
  "dependencies": {
39
- "@napi-rs/wasm-runtime": "~1.2.3",
39
+ "@napi-rs/wasm-runtime": "~1.2.5",
40
40
  "@emnapi/core": "2.0.0-alpha.4",
41
41
  "@emnapi/runtime": "2.0.0-alpha.4"
42
42
  }
@@ -603,10 +603,15 @@ try {
603
603
  export default __napiModule.exports
604
604
  export const PageImage = __napiModule.exports.PageImage
605
605
  export const PdfDocument = __napiModule.exports.PdfDocument
606
+ export const Sheet = __napiModule.exports.Sheet
607
+ export const TiffImage = __napiModule.exports.TiffImage
608
+ export const Workbook = __napiModule.exports.Workbook
606
609
  export const backendName = __napiModule.exports.backendName
607
610
  export const configureThreadPool = __napiModule.exports.configureThreadPool
608
611
  export const encodeBitmap = __napiModule.exports.encodeBitmap
609
612
  export const encodeBitmapSync = __napiModule.exports.encodeBitmapSync
610
613
  export const ImageFormat = __napiModule.exports.ImageFormat
614
+ export const loadTiff = __napiModule.exports.loadTiff
615
+ export const loadWorkbook = __napiModule.exports.loadWorkbook
611
616
  export const reserveMemory = __napiModule.exports.reserveMemory
612
617
  export const runtime = __napiModule.exports.runtime
package/papyra.wasi.cjs CHANGED
@@ -1,4 +1,4 @@
1
- // napi-rs-artifact-metadata:{"version":2,"rootEntry":"index.js","exports":["PageImage","PdfDocument","backendName","configureThreadPool","encodeBitmap","encodeBitmapSync","ImageFormat","reserveMemory","runtime"],"managedRootEntries":["browser.js","index.js","papyra.wasm","papyra.debug.wasm"]}
1
+ // napi-rs-artifact-metadata:{"version":2,"rootEntry":"index.js","exports":["PageImage","PdfDocument","Sheet","TiffImage","Workbook","backendName","configureThreadPool","encodeBitmap","encodeBitmapSync","ImageFormat","loadTiff","loadWorkbook","reserveMemory","runtime"],"managedRootEntries":["browser.js","index.js","papyra.wasm","papyra.debug.wasm"]}
2
2
  /* eslint-disable */
3
3
  /* prettier-ignore */
4
4
 
@@ -923,10 +923,15 @@ try {
923
923
  module.exports = __napiModule.exports
924
924
  module.exports.PageImage = __napiModule.exports.PageImage
925
925
  module.exports.PdfDocument = __napiModule.exports.PdfDocument
926
+ module.exports.Sheet = __napiModule.exports.Sheet
927
+ module.exports.TiffImage = __napiModule.exports.TiffImage
928
+ module.exports.Workbook = __napiModule.exports.Workbook
926
929
  module.exports.backendName = __napiModule.exports.backendName
927
930
  module.exports.configureThreadPool = __napiModule.exports.configureThreadPool
928
931
  module.exports.encodeBitmap = __napiModule.exports.encodeBitmap
929
932
  module.exports.encodeBitmapSync = __napiModule.exports.encodeBitmapSync
930
933
  module.exports.ImageFormat = __napiModule.exports.ImageFormat
934
+ module.exports.loadTiff = __napiModule.exports.loadTiff
935
+ module.exports.loadWorkbook = __napiModule.exports.loadWorkbook
931
936
  module.exports.reserveMemory = __napiModule.exports.reserveMemory
932
937
  module.exports.runtime = __napiModule.exports.runtime
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,12 +95,147 @@ 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
+ export declare class Sheet {
102
+ get name(): string
103
+ /** The sheet held more cells than `maxCells`, and this is its first whole rows. */
104
+ get truncated(): boolean
105
+ /** One past the last used row, counting from the sheet's first row. */
106
+ get rows(): number
107
+ /** One past the last used column, counting from column A. */
108
+ get cols(): number
109
+ /**
110
+ * Merged regions as flat quads — `rowStart, colStart, rowEnd, colEnd`, inclusive —
111
+ * so a sheet with thousands of them is one allocation, not thousands of objects.
112
+ */
113
+ get merges(): Uint32Array
114
+ /** The styles `CellWindow.styles` indexes. Empty for every format but xlsx. */
115
+ get styles(): Array<CellStyle>
116
+ /** Widths and heights as the author set them. Absent for every format but xlsx. */
117
+ get layout(): SheetLayout | null
118
+ /**
119
+ * `[rowStart, rowEnd) x [colStart, colEnd)`, clamped to the sheet.
120
+ *
121
+ * Synchronous: the sheet is already parsed, and a window is as large as the
122
+ * caller asks for — a screenful is a few thousand cells and well under a
123
+ * millisecond. Ask for a screenful.
124
+ */
125
+ window(rowStart: number, rowEnd: number, colStart: number, colEnd: number): CellWindow
126
+ }
127
+
128
+ export declare class TiffImage {
129
+ /** Every page in directory order, reduced-resolution copies left out. */
130
+ get pages(): Array<TiffPageInfo>
131
+ /** Decode one page to RGBA at no more than the given size, off the JS thread. */
132
+ renderPage(index: number, options?: TiffRenderOptions | undefined | null): Promise<RenderedPage>
133
+ }
134
+
135
+ export declare class Workbook {
136
+ /**
137
+ * The container actually read: `"xlsx"`, `"xlsb"`, `"xls"`, `"ods"`, `"csv"` or
138
+ * `"tsv"`. A macro-enabled workbook reads as `"xlsx"`.
139
+ */
140
+ get format(): string
141
+ get sheets(): Array<SheetInfo>
142
+ /** CSV and TSV only: the encoding the text was decoded from, e.g. `"windows-1252"`. */
143
+ get encoding(): string | null
144
+ /** CSV and TSV only: the delimiter, given or sniffed. */
145
+ get delimiter(): string | null
146
+ /** Read one sheet's cells, off the JS thread. A sheet is read once and kept. */
147
+ sheet(index: number): Promise<Sheet>
148
+ }
149
+
150
+ /**
151
+ * One file embedded in the document. Metadata only; the bytes come from
152
+ * `attachmentData`.
153
+ */
154
+ export interface Attachment {
155
+ /** The name to save the file under — `/UF`, else `/F`, else its key in the tree. */
156
+ name: string
157
+ /** The document's own description of what the file is for. */
158
+ description?: string
159
+ /** e.g. `"application/xml"`. Absent more often than not. */
160
+ mediaType?: string
161
+ /** Length in bytes, uncompressed, as the document claims it. A hint, not a promise. */
162
+ size?: number
163
+ /** ISO 8601. */
164
+ created?: string
165
+ /** ISO 8601. */
166
+ modified?: string
167
+ /**
168
+ * `Source`, `Data`, `Alternative`, `Supplement`, `EncryptedPayload` or
169
+ * `Unspecified` — what the file is to the document. A ZUGFeRD invoice's XML is
170
+ * `Alternative` or `Data`.
171
+ */
172
+ relationship?: string
83
173
  }
84
174
 
85
175
  /** Name of the rendering backend, currently always `"hayro"`. */
86
176
  export declare function backendName(): string
87
177
 
178
+ /** One edge of a cell border. */
179
+ export interface BorderEdge {
180
+ /** `"thin"`, `"medium"`, `"thick"`, `"dashed"`, `"dotted"`, `"double"` or `"hair"`. */
181
+ style: string
182
+ /** `0xRRGGBB`; absent for automatic. */
183
+ color?: number
184
+ }
185
+
186
+ /** How a cell looks. Shared by index: cells name a style, they do not carry one. */
187
+ export interface CellStyle {
188
+ bold: boolean
189
+ italic: boolean
190
+ underline: boolean
191
+ strike: boolean
192
+ /** Font size relative to the workbook's default font. */
193
+ fontScale: number
194
+ /** `0xRRGGBB`; absent for automatic. */
195
+ color?: number
196
+ /** `0xRRGGBB` background; absent for none. */
197
+ fill?: number
198
+ borderTop?: BorderEdge
199
+ borderRight?: BorderEdge
200
+ borderBottom?: BorderEdge
201
+ borderLeft?: BorderEdge
202
+ /**
203
+ * `"left"`, `"center"`, `"right"`, `"justify"`, `"centerContinuous"`, `"fill"` or
204
+ * `"distributed"`. Absent means text left, numbers right.
205
+ */
206
+ horizontal?: string
207
+ /** `"top"`, `"center"`, `"bottom"`, `"justify"` or `"distributed"`. Absent means bottom. */
208
+ vertical?: string
209
+ wrap: boolean
210
+ indent: number
211
+ }
212
+
213
+ /** A rectangle of cells, packed. See `Window` in `papyra-tables`. */
214
+ export interface CellWindow {
215
+ rowStart: number
216
+ colStart: number
217
+ rows: number
218
+ cols: number
219
+ /**
220
+ * One kind tag per cell, row-major: 0 empty, 1 number, 2 text, 3 bool, 4 date,
221
+ * 5 duration, 6 error.
222
+ */
223
+ kinds: Uint8Array
224
+ /**
225
+ * One number per cell: the value, a bool as 0/1, a date's serial, a duration in
226
+ * days. NaN when there is none.
227
+ */
228
+ numbers: Float64Array
229
+ /** Every cell's display text, concatenated. */
230
+ text: string
231
+ /** UTF-16 offsets into `text`, one more than there are cells. */
232
+ offsets: Uint32Array
233
+ /** One index into `Sheet.styles` per cell. 0 is the default style. */
234
+ styles: Uint16Array
235
+ /** The colour a number format chose per cell, as `0x01RRGGBB`; 0 for none. */
236
+ colors: Uint32Array
237
+ }
238
+
88
239
  /**
89
240
  * Size the rayon pool used by `renderPagesAsync`.
90
241
  *
@@ -128,6 +279,24 @@ export declare const enum ImageFormat {
128
279
  Jpeg = 'jpeg'
129
280
  }
130
281
 
282
+ /** Open a TIFF and list its pages, off the JS thread. */
283
+ export declare function loadTiff(data: Uint8Array): Promise<TiffImage>
284
+
285
+ /** Open a spreadsheet or delimited text file. */
286
+ export declare function loadWorkbook(data: Uint8Array, options?: WorkbookOptions | undefined | null): Promise<Workbook>
287
+
288
+ /**
289
+ * The outline walk, off the JS thread.
290
+ *
291
+ * One run of page content owned by a structure element.
292
+ */
293
+ export interface MarkedContent {
294
+ /** 0-based page index. */
295
+ page: number
296
+ /** Matches `TextLine.mcid` on that page. */
297
+ mcid: number
298
+ }
299
+
131
300
  /**
132
301
  * Where an outline entry points. Coordinates are PDF points from the page's
133
302
  * bottom-left; `null` means "leave this axis unchanged".
@@ -225,6 +394,46 @@ export declare function reserveMemory(megabytes: number): number
225
394
  /** `"native"` or `"wasm"`. The wrapper uses this to pick a concurrency strategy. */
226
395
  export declare function runtime(): string
227
396
 
397
+ /** A sheet's entry in the workbook. */
398
+ export interface SheetInfo {
399
+ name: string
400
+ /** `"worksheet"`, `"chartsheet"`, `"dialog"`, `"macro"` or `"vba"`. */
401
+ kind: string
402
+ /** `"visible"`, `"hidden"` or `"veryHidden"`. */
403
+ visibility: string
404
+ }
405
+
406
+ /** Column widths and row heights in pixels, as Excel lays the sheet out. */
407
+ export interface SheetLayout {
408
+ defaultColWidth: number
409
+ defaultRowHeight: number
410
+ /** Inclusive column spans as flat triples: `first, last, width`. Width 0 is hidden. */
411
+ cols: Float64Array
412
+ /** Rows with their own height as flat pairs: `row, height`. Height 0 is hidden. */
413
+ rows: Float64Array
414
+ showGridLines: boolean
415
+ }
416
+
417
+ /** One structure-tree element. Flat and in pre-order; `level` carries the tree. */
418
+ export interface StructEntry {
419
+ /** Standard structure type, after `/RoleMap`: `"H1"`, `"P"`, `"Table"`, `"TD"`, … */
420
+ role: string
421
+ /** The document's own tag, before `/RoleMap`. Equal to `role` unless remapped. */
422
+ rawRole: string
423
+ /** Nesting depth. Top-level elements are 0. */
424
+ level: number
425
+ /** Content this element owns directly. Empty for a pure container. */
426
+ content: Array<MarkedContent>
427
+ /** `/Alt` — replacement text for a figure. */
428
+ alt?: string
429
+ /** `/ActualText` — text replacing the content rather than describing it. */
430
+ actualText?: string
431
+ /** `/Lang` — a BCP 47 tag for this subtree. */
432
+ lang?: string
433
+ /** `/T` — a human-readable title, e.g. a table's caption. */
434
+ title?: string
435
+ }
436
+
228
437
  /**
229
438
  * A run of glyphs sharing one baseline.
230
439
  *
@@ -250,4 +459,50 @@ export interface TextLine {
250
459
  ascent: number
251
460
  /** Extent below the baseline. */
252
461
  descent: number
462
+ /**
463
+ * Marked-content id of the line's first glyph, joining to `StructNode.content` on
464
+ * a tagged page. `null` on an untagged page, and for content outside any sequence.
465
+ */
466
+ mcid?: number
467
+ }
468
+
469
+ /** One page of a TIFF, as shown: `Orientation` already applied. */
470
+ export interface TiffPageInfo {
471
+ width: number
472
+ height: number
473
+ /** Horizontal resolution in dots per inch, when the file states one. */
474
+ xDpi?: number
475
+ /** Vertical resolution in dots per inch, when the file states one. */
476
+ yDpi?: number
477
+ /**
478
+ * `"none"`, `"ccitt-rle"`, `"ccitt-g3"`, `"ccitt-g4"`, `"lzw"`, `"old-jpeg"`,
479
+ * `"jpeg"`, `"deflate"`, `"packbits"` or `"other"`.
480
+ */
481
+ compression: string
482
+ bitsPerSample: number
483
+ samplesPerPixel: number
484
+ /** TIFF `Orientation`, 1–8. */
485
+ orientation: number
486
+ }
487
+
488
+ /** Output limits for a page decode. Both optional; the page is never enlarged. */
489
+ export interface TiffRenderOptions {
490
+ /** Defaults to 4096 x 4096. A float on the JS side, so read as one. */
491
+ maxPixels?: number
492
+ maxWidth?: number
493
+ }
494
+
495
+ /** How to read the bytes. Every field is optional and sniffed when absent. */
496
+ export interface WorkbookOptions {
497
+ /**
498
+ * `"xlsx"`, `"xlsm"`, `"xlsb"`, `"xls"`, `"ods"`, `"csv"` or `"tsv"`. Only needed
499
+ * to call a file TSV, or to skip sniffing.
500
+ */
501
+ format?: string
502
+ /** CSV and TSV only: a single ASCII character. */
503
+ delimiter?: string
504
+ /** CSV and TSV only: a WHATWG encoding label such as `"windows-1252"`. */
505
+ encoding?: string
506
+ /** Cells held per sheet before it is truncated to its first whole rows. */
507
+ maxCells?: number
253
508
  }
Binary file