@build-qube/papyra-native-wasm32-wasi 0.0.4 → 0.1.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.0.4",
3
+ "version": "0.1.0",
4
4
  "main": "papyra.wasi.cjs",
5
5
  "files": [
6
6
  "papyra.wasm32-wasi.wasm",
@@ -601,8 +601,12 @@ try {
601
601
  throw __attachCleanupErrors(error, cleanupErrors)
602
602
  }
603
603
  export default __napiModule.exports
604
+ export const PageImage = __napiModule.exports.PageImage
604
605
  export const PdfDocument = __napiModule.exports.PdfDocument
605
606
  export const backendName = __napiModule.exports.backendName
606
607
  export const configureThreadPool = __napiModule.exports.configureThreadPool
608
+ export const encodeBitmap = __napiModule.exports.encodeBitmap
609
+ export const encodeBitmapSync = __napiModule.exports.encodeBitmapSync
610
+ export const ImageFormat = __napiModule.exports.ImageFormat
607
611
  export const reserveMemory = __napiModule.exports.reserveMemory
608
612
  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":["PdfDocument","backendName","configureThreadPool","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","backendName","configureThreadPool","encodeBitmap","encodeBitmapSync","ImageFormat","reserveMemory","runtime"],"managedRootEntries":["browser.js","index.js","papyra.wasm","papyra.debug.wasm"]}
2
2
  /* eslint-disable */
3
3
  /* prettier-ignore */
4
4
 
@@ -921,8 +921,12 @@ try {
921
921
  throw rollback.error
922
922
  }
923
923
  module.exports = __napiModule.exports
924
+ module.exports.PageImage = __napiModule.exports.PageImage
924
925
  module.exports.PdfDocument = __napiModule.exports.PdfDocument
925
926
  module.exports.backendName = __napiModule.exports.backendName
926
927
  module.exports.configureThreadPool = __napiModule.exports.configureThreadPool
928
+ module.exports.encodeBitmap = __napiModule.exports.encodeBitmap
929
+ module.exports.encodeBitmapSync = __napiModule.exports.encodeBitmapSync
930
+ module.exports.ImageFormat = __napiModule.exports.ImageFormat
927
931
  module.exports.reserveMemory = __napiModule.exports.reserveMemory
928
932
  module.exports.runtime = __napiModule.exports.runtime
package/papyra.wasi.d.cts CHANGED
@@ -1,5 +1,32 @@
1
1
  /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
+ /**
4
+ * A rendered page kept in Rust, encoded on demand.
5
+ *
6
+ * The pixels deliberately never cross into JS. A 42x30in drawing at 150 DPI is 6.5 MB
7
+ * raw and a fraction of that encoded, so for export the raw buffer is pure overhead.
8
+ * There is no accessor for it: use `renderPageAsync` when you want the pixels, this
9
+ * when you want a file.
10
+ */
11
+ export declare class PageImage {
12
+ get width(): number
13
+ get height(): number
14
+ /** Size of the *raw* bitmap held in Rust. Encoded output is much smaller. */
15
+ get byteLength(): number
16
+ /** Encode off the JS thread. */
17
+ encode(format: ImageFormat, quality?: number | undefined | null, signal?: AbortSignal | undefined | null): Promise<Uint8Array>
18
+ /**
19
+ * Blocks the calling thread. Routed through the same `Task` as the async path so
20
+ * the two cannot drift.
21
+ */
22
+ encodeSync(format: ImageFormat, quality?: number | undefined | null): Uint8Array
23
+ /**
24
+ * Encode straight to a `data:` URL, so neither the pixels nor the encoded bytes
25
+ * cross the boundary — only the finished string does.
26
+ */
27
+ toDataUrl(format: ImageFormat, quality?: number | undefined | null, signal?: AbortSignal | undefined | null): Promise<string>
28
+ }
29
+
3
30
  export declare class PdfDocument {
4
31
  /** Load a PDF from raw bytes. */
5
32
  static load(data: Uint8Array): PdfDocument
@@ -11,6 +38,19 @@ export declare class PdfDocument {
11
38
  renderPage(index: number, dpi?: number | undefined | null): RenderedPage
12
39
  /** Render one page off the JS thread. Several of these run concurrently. */
13
40
  renderPageAsync(index: number, dpi?: number | undefined | null): Promise<RenderedPage>
41
+ /** Render one page and keep it in Rust, for encoding. The pixels never reach JS. */
42
+ renderPageImageAsync(index: number, dpi?: number | undefined | null, signal?: AbortSignal | undefined | null): Promise<PageImage>
43
+ /** Extract the text of one page, off the JS thread. */
44
+ pageTextAsync(index: number): Promise<PageText>
45
+ /** Extract `[start, end)` in one async task, parallelised internally with rayon. */
46
+ pageTextsAsync(start: number, end: number): Promise<Array<PageText>>
47
+ /**
48
+ * Read the document outline (bookmarks), in pre-order.
49
+ *
50
+ * Resolves to an empty array when the document has no outline, which is the
51
+ * common case.
52
+ */
53
+ outline(): Promise<Array<OutlineEntry>>
14
54
  /** Render `[start, end)` in one async task, parallelised internally with rayon. */
15
55
  renderPagesAsync(start: number, end: number, dpi?: number | undefined | null): Promise<Array<RenderedPage>>
16
56
  }
@@ -27,6 +67,55 @@ export declare function backendName(): string
27
67
  */
28
68
  export declare function configureThreadPool(threads: number, stackSizeMb?: number | undefined | null): number
29
69
 
70
+ /** Encode a raw RGBA8 buffer off the JS thread. */
71
+ export declare function encodeBitmap(data: Uint8Array, width: number, height: number, stride: number, format: ImageFormat, quality?: number | undefined | null, signal?: AbortSignal | undefined | null): Promise<Uint8Array>
72
+
73
+ /** Blocks the calling thread. Same `Task` as [`encode_bitmap`]. */
74
+ export declare function encodeBitmapSync(data: Uint8Array, width: number, height: number, stride: number, format: ImageFormat, quality?: number | undefined | null): Uint8Array
75
+
76
+ /**
77
+ * Container for encoded output. Every encoder here is pure Rust, which is what keeps
78
+ * the wasm target buildable — so there is no lossy WebP and no AVIF.
79
+ */
80
+ export declare const enum ImageFormat {
81
+ /** Lossless VP8L. ~3x smaller than PNG on page content, for about the same cost. */
82
+ WebP = 'webp',
83
+ /** Lossless, universally supported. */
84
+ Png = 'png',
85
+ /** The only lossy option, and the only one with a quality knob. No alpha. */
86
+ Jpeg = 'jpeg'
87
+ }
88
+
89
+ /**
90
+ * Where an outline entry points. Coordinates are PDF points from the page's
91
+ * bottom-left; `null` means "leave this axis unchanged".
92
+ */
93
+ export interface OutlineDestination {
94
+ /** 0-based page index. */
95
+ page: number
96
+ /** `"XYZ"`, `"Fit"`, `"FitH"`, `"FitV"`, `"FitR"`, `"FitB"`, `"FitBH"` or `"FitBV"`. */
97
+ kind: string
98
+ left?: number
99
+ top?: number
100
+ right?: number
101
+ bottom?: number
102
+ /** Absent for every kind but `"XYZ"`, where a zoom of 0 also reads as absent. */
103
+ zoom?: number
104
+ }
105
+
106
+ /** One outline entry. Flat and in pre-order; `level` carries the tree. */
107
+ export interface OutlineEntry {
108
+ title: string
109
+ /** Nesting depth. Top-level bookmarks are 0. */
110
+ level: number
111
+ /** `null` for a container with no destination, or one that leaves this document. */
112
+ dest?: OutlineDestination
113
+ bold: boolean
114
+ italic: boolean
115
+ /** The entry should start expanded. */
116
+ open: boolean
117
+ }
118
+
30
119
  export interface PageDimensions {
31
120
  /** Width in PDF points (1/72 inch). */
32
121
  width: number
@@ -34,6 +123,23 @@ export interface PageDimensions {
34
123
  height: number
35
124
  }
36
125
 
126
+ /**
127
+ * The text of one page.
128
+ *
129
+ * Coordinates are the page as rendered at 72 DPI — pixels from the top-left with y
130
+ * increasing downwards, rotation and crop box applied — so scaling to any other
131
+ * render is one multiply.
132
+ */
133
+ export interface PageText {
134
+ lines: Array<TextLine>
135
+ /**
136
+ * Glyphs drawn that no encoding could map back to Unicode. Non-zero with no lines
137
+ * means the page has text that cannot be searched, which is a different answer
138
+ * than a page with no text at all.
139
+ */
140
+ undecodedGlyphs: number
141
+ }
142
+
37
143
  export interface RenderedPage {
38
144
  width: number
39
145
  height: number
@@ -56,3 +162,30 @@ export declare function reserveMemory(megabytes: number): number
56
162
 
57
163
  /** `"native"` or `"wasm"`. The wrapper uses this to pick a concurrency strategy. */
58
164
  export declare function runtime(): string
165
+
166
+ /**
167
+ * A run of glyphs sharing one baseline.
168
+ *
169
+ * Geometry runs along the baseline rather than being a rectangle per character: a
170
+ * page is thousands of glyphs, and four numbers each is far more than a search needs.
171
+ * One origin, one direction and a list of distances reconstructs any substring's
172
+ * quadrilateral exactly, rotated text included.
173
+ */
174
+ export interface TextLine {
175
+ text: string
176
+ /**
177
+ * Distance along the baseline to the start of each character, plus the end of the
178
+ * last — one more entry than the string has characters.
179
+ */
180
+ offsets: Float32Array
181
+ /** Start of the baseline. */
182
+ x: number
183
+ y: number
184
+ /** Unit vector along the baseline. `(1, 0)` for ordinary horizontal text. */
185
+ dx: number
186
+ dy: number
187
+ /** Extent above the baseline, perpendicular to it. */
188
+ ascent: number
189
+ /** Extent below the baseline. */
190
+ descent: number
191
+ }
Binary file