djvu-rs 0.28.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/LICENSE +21 -0
- package/README.md +803 -0
- package/djvu_rs.d.ts +321 -0
- package/djvu_rs.js +56 -0
- package/package.json +44 -0
- package/scalar/LICENSE +21 -0
- package/scalar/README.md +803 -0
- package/scalar/djvu_rs.d.ts +318 -0
- package/scalar/djvu_rs.js +702 -0
- package/scalar/djvu_rs_bg.wasm +0 -0
- package/scalar/djvu_rs_bg.wasm.d.ts +53 -0
- package/simd128/LICENSE +21 -0
- package/simd128/README.md +803 -0
- package/simd128/djvu_rs.d.ts +318 -0
- package/simd128/djvu_rs.js +702 -0
- package/simd128/djvu_rs_bg.wasm +0 -0
- package/simd128/djvu_rs_bg.wasm.d.ts +53 -0
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
/* @ts-self-types="./djvu_rs.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A parsed DjVu document.
|
|
5
|
+
*
|
|
6
|
+
* Created from raw bytes via [`WasmDocument::from_bytes`].
|
|
7
|
+
*/
|
|
8
|
+
export class WasmDocument {
|
|
9
|
+
static __wrap(ptr) {
|
|
10
|
+
const obj = Object.create(WasmDocument.prototype);
|
|
11
|
+
obj.__wbg_ptr = ptr;
|
|
12
|
+
WasmDocumentFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
13
|
+
return obj;
|
|
14
|
+
}
|
|
15
|
+
__destroy_into_raw() {
|
|
16
|
+
const ptr = this.__wbg_ptr;
|
|
17
|
+
this.__wbg_ptr = 0;
|
|
18
|
+
WasmDocumentFinalization.unregister(this);
|
|
19
|
+
return ptr;
|
|
20
|
+
}
|
|
21
|
+
free() {
|
|
22
|
+
const ptr = this.__destroy_into_raw();
|
|
23
|
+
wasm.__wbg_wasmdocument_free(ptr, 0);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parse a DjVu document from a byte buffer.
|
|
27
|
+
*
|
|
28
|
+
* The buffer is moved into a shared backing store and bundled pages
|
|
29
|
+
* materialize lazily on first access (#609) — the same owned-bytes path
|
|
30
|
+
* as the native `Document::from_bytes` (LAZY_PAGE_CONSTRUCT), instead of
|
|
31
|
+
* the eager parser that copied every page at open time. The JS-visible
|
|
32
|
+
* signature is unchanged (pass a `Uint8Array`); the JS→wasm transfer is
|
|
33
|
+
* the single unavoidable copy.
|
|
34
|
+
*
|
|
35
|
+
* Throws a JavaScript `Error` if the bytes are not a valid DjVu file.
|
|
36
|
+
* @param {Uint8Array} data
|
|
37
|
+
* @returns {WasmDocument}
|
|
38
|
+
*/
|
|
39
|
+
static from_bytes(data) {
|
|
40
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
41
|
+
const len0 = WASM_VECTOR_LEN;
|
|
42
|
+
const ret = wasm.wasmdocument_from_bytes(ptr0, len0);
|
|
43
|
+
if (ret[2]) {
|
|
44
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
45
|
+
}
|
|
46
|
+
return WasmDocument.__wrap(ret[0]);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Return a handle to page `index` (0-based).
|
|
50
|
+
*
|
|
51
|
+
* Throws if `index >= page_count()`.
|
|
52
|
+
* @param {number} index
|
|
53
|
+
* @returns {WasmPage}
|
|
54
|
+
*/
|
|
55
|
+
page(index) {
|
|
56
|
+
const ret = wasm.wasmdocument_page(this.__wbg_ptr, index);
|
|
57
|
+
if (ret[2]) {
|
|
58
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
59
|
+
}
|
|
60
|
+
return WasmPage.__wrap(ret[0]);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Total number of pages in the document.
|
|
64
|
+
* @returns {number}
|
|
65
|
+
*/
|
|
66
|
+
page_count() {
|
|
67
|
+
const ret = wasm.wasmdocument_page_count(this.__wbg_ptr);
|
|
68
|
+
return ret >>> 0;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Render a contiguous batch of pages at `target_dpi`, returning one
|
|
72
|
+
* [`WasmPixmap`] per page in input order (#610).
|
|
73
|
+
*
|
|
74
|
+
* With the opt-in `wasm-threads` build (rayon Web-Worker pool via
|
|
75
|
+
* `initThreadPool`), pages render concurrently as coarse one-page tasks —
|
|
76
|
+
* the threading shape WASM_THREADS measured as viable (fine-grained
|
|
77
|
+
* compositor parallelism regressed ~9× and stays disabled). Without the
|
|
78
|
+
* pool the batch renders sequentially with identical results.
|
|
79
|
+
*
|
|
80
|
+
* Memory is bounded by the caller-chosen batch size: `count` full-size
|
|
81
|
+
* pixmaps are alive at once. Failed pages yield an error for the whole
|
|
82
|
+
* batch (all-or-nothing keeps the ordering contract simple).
|
|
83
|
+
* @param {number} target_dpi
|
|
84
|
+
* @param {number} start
|
|
85
|
+
* @param {number} count
|
|
86
|
+
* @returns {WasmPixmap[]}
|
|
87
|
+
*/
|
|
88
|
+
render_pages_batch(target_dpi, start, count) {
|
|
89
|
+
const ret = wasm.wasmdocument_render_pages_batch(this.__wbg_ptr, target_dpi, start, count);
|
|
90
|
+
if (ret[3]) {
|
|
91
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
92
|
+
}
|
|
93
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]);
|
|
94
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
95
|
+
return v1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (Symbol.dispose) WasmDocument.prototype[Symbol.dispose] = WasmDocument.prototype.free;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* A single page within a [`WasmDocument`].
|
|
102
|
+
*/
|
|
103
|
+
export class WasmPage {
|
|
104
|
+
static __wrap(ptr) {
|
|
105
|
+
const obj = Object.create(WasmPage.prototype);
|
|
106
|
+
obj.__wbg_ptr = ptr;
|
|
107
|
+
WasmPageFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
108
|
+
return obj;
|
|
109
|
+
}
|
|
110
|
+
__destroy_into_raw() {
|
|
111
|
+
const ptr = this.__wbg_ptr;
|
|
112
|
+
this.__wbg_ptr = 0;
|
|
113
|
+
WasmPageFinalization.unregister(this);
|
|
114
|
+
return ptr;
|
|
115
|
+
}
|
|
116
|
+
free() {
|
|
117
|
+
const ptr = this.__destroy_into_raw();
|
|
118
|
+
wasm.__wbg_wasmpage_free(ptr, 0);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Number of BG44 background chunks on this page.
|
|
122
|
+
*
|
|
123
|
+
* Determines how many refinement steps are available via
|
|
124
|
+
* [`render_progressive`]. Returns `0` for bilevel-only pages.
|
|
125
|
+
* @returns {number}
|
|
126
|
+
*/
|
|
127
|
+
bg44_chunk_count() {
|
|
128
|
+
const ret = wasm.wasmpage_bg44_chunk_count(this.__wbg_ptr);
|
|
129
|
+
return ret >>> 0;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Native DPI stored in the INFO chunk.
|
|
133
|
+
* @returns {number}
|
|
134
|
+
*/
|
|
135
|
+
dpi() {
|
|
136
|
+
const ret = wasm.wasmpage_dpi(this.__wbg_ptr);
|
|
137
|
+
return ret >>> 0;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Output height in pixels when rendered at `target_dpi`.
|
|
141
|
+
* @param {number} target_dpi
|
|
142
|
+
* @returns {number}
|
|
143
|
+
*/
|
|
144
|
+
height_at(target_dpi) {
|
|
145
|
+
const ret = wasm.wasmpage_height_at(this.__wbg_ptr, target_dpi);
|
|
146
|
+
return ret >>> 0;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Render the page at `target_dpi` and return raw RGBA pixels
|
|
150
|
+
* (`Uint8ClampedArray`, suitable for `new ImageData(pixels, w, h)`).
|
|
151
|
+
*
|
|
152
|
+
* Throws on decode error.
|
|
153
|
+
* @param {number} target_dpi
|
|
154
|
+
* @returns {Uint8ClampedArray}
|
|
155
|
+
*/
|
|
156
|
+
render(target_dpi) {
|
|
157
|
+
const ret = wasm.wasmpage_render(this.__wbg_ptr, target_dpi);
|
|
158
|
+
if (ret[2]) {
|
|
159
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
160
|
+
}
|
|
161
|
+
return takeFromExternrefTable0(ret[0]);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Fast coarse render — decodes only the first BG44 chunk (~5 ms for a
|
|
165
|
+
* typical color page).
|
|
166
|
+
*
|
|
167
|
+
* Returns `undefined` for bilevel-only pages (no BG44 data); use
|
|
168
|
+
* [`render`] for those. For color pages the result is a blurry but
|
|
169
|
+
* instantly visible preview; call [`render_progressive`] or [`render`]
|
|
170
|
+
* on a Web Worker to produce the final image.
|
|
171
|
+
*
|
|
172
|
+
* Throws on decode error.
|
|
173
|
+
* @param {number} target_dpi
|
|
174
|
+
* @returns {Uint8ClampedArray | undefined}
|
|
175
|
+
*/
|
|
176
|
+
render_coarse(target_dpi) {
|
|
177
|
+
const ret = wasm.wasmpage_render_coarse(this.__wbg_ptr, target_dpi);
|
|
178
|
+
if (ret[2]) {
|
|
179
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
180
|
+
}
|
|
181
|
+
return takeFromExternrefTable0(ret[0]);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Render into a caller-owned [`WasmPixmap`], reusing its Rust-side
|
|
185
|
+
* allocation (#611). No JS-side allocation, no wasm→JS copy — consume
|
|
186
|
+
* the pixels via [`WasmPixmap::view`].
|
|
187
|
+
* @param {number} target_dpi
|
|
188
|
+
* @param {WasmPixmap} out
|
|
189
|
+
*/
|
|
190
|
+
render_into_pixmap(target_dpi, out) {
|
|
191
|
+
_assertClass(out, WasmPixmap);
|
|
192
|
+
const ret = wasm.wasmpage_render_into_pixmap(this.__wbg_ptr, target_dpi, out.__wbg_ptr);
|
|
193
|
+
if (ret[1]) {
|
|
194
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Progressive render — decodes BG44 chunks 0..=`chunk_n` plus all
|
|
199
|
+
* foreground layers (JB2 mask, text).
|
|
200
|
+
*
|
|
201
|
+
* `chunk_n = 0` is equivalent to [`render_coarse`] but also composites
|
|
202
|
+
* the mask. Each subsequent call with `chunk_n += 1` adds one more
|
|
203
|
+
* wavelet refinement pass. After the last chunk the result is identical
|
|
204
|
+
* to [`render`].
|
|
205
|
+
*
|
|
206
|
+
* Use [`bg44_chunk_count`] to find the maximum valid `chunk_n`
|
|
207
|
+
* (`bg44_chunk_count() - 1`).
|
|
208
|
+
*
|
|
209
|
+
* Throws on decode error or if `chunk_n` is out of range.
|
|
210
|
+
* @param {number} target_dpi
|
|
211
|
+
* @param {number} chunk_n
|
|
212
|
+
* @returns {Uint8ClampedArray}
|
|
213
|
+
*/
|
|
214
|
+
render_progressive(target_dpi, chunk_n) {
|
|
215
|
+
const ret = wasm.wasmpage_render_progressive(this.__wbg_ptr, target_dpi, chunk_n);
|
|
216
|
+
if (ret[2]) {
|
|
217
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
218
|
+
}
|
|
219
|
+
return takeFromExternrefTable0(ret[0]);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Progressive render into a caller-owned [`WasmPixmap`] (#611): the same
|
|
223
|
+
* refinement semantics as [`render_progressive`](Self::render_progressive),
|
|
224
|
+
* but an N-pass progressive session reuses one buffer instead of
|
|
225
|
+
* allocating and copying N full frames.
|
|
226
|
+
* @param {number} target_dpi
|
|
227
|
+
* @param {number} chunk_n
|
|
228
|
+
* @param {WasmPixmap} out
|
|
229
|
+
*/
|
|
230
|
+
render_progressive_into_pixmap(target_dpi, chunk_n, out) {
|
|
231
|
+
_assertClass(out, WasmPixmap);
|
|
232
|
+
const ret = wasm.wasmpage_render_progressive_into_pixmap(this.__wbg_ptr, target_dpi, chunk_n, out.__wbg_ptr);
|
|
233
|
+
if (ret[1]) {
|
|
234
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Render one full-quality tile, returning a [`WasmPixmap`] whose
|
|
239
|
+
* `width()`/`height()` give the (possibly clipped) tile dimensions.
|
|
240
|
+
*
|
|
241
|
+
* Byte-identical to the matching rectangle of [`render`](Self::render);
|
|
242
|
+
* assembled from the page's composited-tile cache (cache state never
|
|
243
|
+
* changes bytes, only latency).
|
|
244
|
+
*
|
|
245
|
+
* Throws on decode error or a grid violation.
|
|
246
|
+
* @param {number} target_dpi
|
|
247
|
+
* @param {number} tile_size
|
|
248
|
+
* @param {number} col
|
|
249
|
+
* @param {number} row
|
|
250
|
+
* @returns {WasmPixmap}
|
|
251
|
+
*/
|
|
252
|
+
render_tile(target_dpi, tile_size, col, row) {
|
|
253
|
+
const ret = wasm.wasmpage_render_tile(this.__wbg_ptr, target_dpi, tile_size, col, row);
|
|
254
|
+
if (ret[2]) {
|
|
255
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
256
|
+
}
|
|
257
|
+
return WasmPixmap.__wrap(ret[0]);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Render one full-quality tile into a caller-owned [`WasmPixmap`]
|
|
261
|
+
* (#611 pattern): a pan/zoom session reuses one Rust-side allocation
|
|
262
|
+
* per on-screen tile slot instead of allocating per frame.
|
|
263
|
+
* @param {number} target_dpi
|
|
264
|
+
* @param {number} tile_size
|
|
265
|
+
* @param {number} col
|
|
266
|
+
* @param {number} row
|
|
267
|
+
* @param {WasmPixmap} out
|
|
268
|
+
*/
|
|
269
|
+
render_tile_into_pixmap(target_dpi, tile_size, col, row, out) {
|
|
270
|
+
_assertClass(out, WasmPixmap);
|
|
271
|
+
const ret = wasm.wasmpage_render_tile_into_pixmap(this.__wbg_ptr, target_dpi, tile_size, col, row, out.__wbg_ptr);
|
|
272
|
+
if (ret[1]) {
|
|
273
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Render one tile at progressive quality step `chunk_n` (BG44 chunks
|
|
278
|
+
* `0..=chunk_n` only), byte-identical to the tile's rectangle of
|
|
279
|
+
* [`render_progressive`](Self::render_progressive) with the same
|
|
280
|
+
* `chunk_n`. Partial-quality tiles are never cached.
|
|
281
|
+
*
|
|
282
|
+
* On bilevel pages (no BG44 data) `chunk_n = 0` is the full render.
|
|
283
|
+
* Throws on decode error, a grid violation, or `chunk_n` out of range.
|
|
284
|
+
* @param {number} target_dpi
|
|
285
|
+
* @param {number} tile_size
|
|
286
|
+
* @param {number} col
|
|
287
|
+
* @param {number} row
|
|
288
|
+
* @param {number} chunk_n
|
|
289
|
+
* @returns {WasmPixmap}
|
|
290
|
+
*/
|
|
291
|
+
render_tile_progressive(target_dpi, tile_size, col, row, chunk_n) {
|
|
292
|
+
const ret = wasm.wasmpage_render_tile_progressive(this.__wbg_ptr, target_dpi, tile_size, col, row, chunk_n);
|
|
293
|
+
if (ret[2]) {
|
|
294
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
295
|
+
}
|
|
296
|
+
return WasmPixmap.__wrap(ret[0]);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Extract the plain text content of this page from the TXTz/TXTa layer.
|
|
300
|
+
*
|
|
301
|
+
* Returns `undefined` (JS `None`) if the page has no text layer.
|
|
302
|
+
* Throws a JavaScript `Error` on decode failure.
|
|
303
|
+
* @returns {string | undefined}
|
|
304
|
+
*/
|
|
305
|
+
text() {
|
|
306
|
+
const ret = wasm.wasmpage_text(this.__wbg_ptr);
|
|
307
|
+
if (ret[3]) {
|
|
308
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
309
|
+
}
|
|
310
|
+
let v1;
|
|
311
|
+
if (ret[0] !== 0) {
|
|
312
|
+
v1 = getStringFromWasm0(ret[0], ret[1]);
|
|
313
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
314
|
+
}
|
|
315
|
+
return v1;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Return text zone data for this page, scaled to match a render at `target_dpi`.
|
|
319
|
+
*
|
|
320
|
+
* Returns a JSON string — array of `{"t":"…","x":N,"y":N,"w":N,"h":N}` objects,
|
|
321
|
+
* one per leaf text zone, with pixel coordinates identical to the canvas produced
|
|
322
|
+
* by `render(target_dpi)`. Leaf zones are the finest granularity stored in the
|
|
323
|
+
* text layer (word-level for richly OCR'd files, line-level otherwise).
|
|
324
|
+
*
|
|
325
|
+
* Returns `null` if the page has no text layer.
|
|
326
|
+
* Throws a JavaScript `Error` on decode failure.
|
|
327
|
+
* @param {number} target_dpi
|
|
328
|
+
* @returns {string | undefined}
|
|
329
|
+
*/
|
|
330
|
+
text_zones_json(target_dpi) {
|
|
331
|
+
const ret = wasm.wasmpage_text_zones_json(this.__wbg_ptr, target_dpi);
|
|
332
|
+
if (ret[3]) {
|
|
333
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
334
|
+
}
|
|
335
|
+
let v1;
|
|
336
|
+
if (ret[0] !== 0) {
|
|
337
|
+
v1 = getStringFromWasm0(ret[0], ret[1]);
|
|
338
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
339
|
+
}
|
|
340
|
+
return v1;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Number of tile columns at `target_dpi` for `tile_size`-pixel tiles.
|
|
344
|
+
*
|
|
345
|
+
* Tiles live in display space: tile `(col, row)` starts at canvas pixel
|
|
346
|
+
* `(col * tile_size, row * tile_size)`; edge tiles are clipped, never
|
|
347
|
+
* padded, so blitting every tile covers the canvas exactly once.
|
|
348
|
+
* @param {number} target_dpi
|
|
349
|
+
* @param {number} tile_size
|
|
350
|
+
* @returns {number}
|
|
351
|
+
*/
|
|
352
|
+
tile_cols(target_dpi, tile_size) {
|
|
353
|
+
const ret = wasm.wasmpage_tile_cols(this.__wbg_ptr, target_dpi, tile_size);
|
|
354
|
+
if (ret[2]) {
|
|
355
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
356
|
+
}
|
|
357
|
+
return ret[0] >>> 0;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Number of tile rows at `target_dpi` for `tile_size`-pixel tiles.
|
|
361
|
+
* @param {number} target_dpi
|
|
362
|
+
* @param {number} tile_size
|
|
363
|
+
* @returns {number}
|
|
364
|
+
*/
|
|
365
|
+
tile_rows(target_dpi, tile_size) {
|
|
366
|
+
const ret = wasm.wasmpage_tile_rows(this.__wbg_ptr, target_dpi, tile_size);
|
|
367
|
+
if (ret[2]) {
|
|
368
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
369
|
+
}
|
|
370
|
+
return ret[0] >>> 0;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Output width in pixels when rendered at `target_dpi`.
|
|
374
|
+
* @param {number} target_dpi
|
|
375
|
+
* @returns {number}
|
|
376
|
+
*/
|
|
377
|
+
width_at(target_dpi) {
|
|
378
|
+
const ret = wasm.wasmpage_width_at(this.__wbg_ptr, target_dpi);
|
|
379
|
+
return ret >>> 0;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (Symbol.dispose) WasmPage.prototype[Symbol.dispose] = WasmPage.prototype.free;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* A Rust-owned RGBA pixel buffer that stays alive as long as JS holds the
|
|
386
|
+
* handle, so pixels can be consumed **without** the per-frame
|
|
387
|
+
* `Uint8ClampedArray` allocation + full-buffer copy the plain `render*`
|
|
388
|
+
* methods pay.
|
|
389
|
+
*
|
|
390
|
+
* Two usage modes:
|
|
391
|
+
* - **Zero-copy view**: [`view`](WasmPixmap::view) returns a typed-array view
|
|
392
|
+
* directly into wasm linear memory. Consume it immediately (e.g.
|
|
393
|
+
* `ctx.putImageData(new ImageData(pm.view(), pm.width(), pm.height()), 0, 0)`
|
|
394
|
+
* — `ImageData` copies). The view is invalidated by wasm memory growth and
|
|
395
|
+
* by dropping/re-rendering the pixmap; never store it.
|
|
396
|
+
* - **Buffer reuse**: pass the same `WasmPixmap` back to
|
|
397
|
+
* [`render_into_pixmap`](WasmPage::render_into_pixmap) /
|
|
398
|
+
* [`render_progressive_into_pixmap`](WasmPage::render_progressive_into_pixmap)
|
|
399
|
+
* — the Rust-side allocation is reused across frames (a progressive
|
|
400
|
+
* session allocates once instead of once per refinement pass).
|
|
401
|
+
*
|
|
402
|
+
* The existing copying `render*` methods are unchanged for callers that need
|
|
403
|
+
* independently owned JS bytes.
|
|
404
|
+
*/
|
|
405
|
+
export class WasmPixmap {
|
|
406
|
+
static __wrap(ptr) {
|
|
407
|
+
const obj = Object.create(WasmPixmap.prototype);
|
|
408
|
+
obj.__wbg_ptr = ptr;
|
|
409
|
+
WasmPixmapFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
410
|
+
return obj;
|
|
411
|
+
}
|
|
412
|
+
__destroy_into_raw() {
|
|
413
|
+
const ptr = this.__wbg_ptr;
|
|
414
|
+
this.__wbg_ptr = 0;
|
|
415
|
+
WasmPixmapFinalization.unregister(this);
|
|
416
|
+
return ptr;
|
|
417
|
+
}
|
|
418
|
+
free() {
|
|
419
|
+
const ptr = this.__destroy_into_raw();
|
|
420
|
+
wasm.__wbg_wasmpixmap_free(ptr, 0);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* RGBA byte length (`width * height * 4`).
|
|
424
|
+
* @returns {number}
|
|
425
|
+
*/
|
|
426
|
+
byte_length() {
|
|
427
|
+
const ret = wasm.wasmpixmap_byte_length(this.__wbg_ptr);
|
|
428
|
+
return ret >>> 0;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Pixel height of the last render written into this pixmap.
|
|
432
|
+
* @returns {number}
|
|
433
|
+
*/
|
|
434
|
+
height() {
|
|
435
|
+
const ret = wasm.wasmpixmap_height(this.__wbg_ptr);
|
|
436
|
+
return ret >>> 0;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* An empty pixmap for use with the `*_into_pixmap` methods.
|
|
440
|
+
*/
|
|
441
|
+
constructor() {
|
|
442
|
+
const ret = wasm.wasmpixmap_new();
|
|
443
|
+
this.__wbg_ptr = ret;
|
|
444
|
+
WasmPixmapFinalization.register(this, this.__wbg_ptr, this);
|
|
445
|
+
return this;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Copy the pixels into a fresh, independently owned
|
|
449
|
+
* `Uint8ClampedArray` (same guarantee as the plain `render` API).
|
|
450
|
+
* @returns {Uint8ClampedArray}
|
|
451
|
+
*/
|
|
452
|
+
to_bytes() {
|
|
453
|
+
const ret = wasm.wasmpixmap_to_bytes(this.__wbg_ptr);
|
|
454
|
+
return ret;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Zero-copy `Uint8ClampedArray` view into wasm memory.
|
|
458
|
+
*
|
|
459
|
+
* Valid only until the next wasm memory growth, the next render into
|
|
460
|
+
* this pixmap, or the pixmap being freed — consume it immediately and
|
|
461
|
+
* never store it. `new ImageData(view, w, h)` copies, so canvas
|
|
462
|
+
* consumption is safe.
|
|
463
|
+
* @returns {Uint8ClampedArray}
|
|
464
|
+
*/
|
|
465
|
+
view() {
|
|
466
|
+
const ret = wasm.wasmpixmap_view(this.__wbg_ptr);
|
|
467
|
+
return ret;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Pixel width of the last render written into this pixmap.
|
|
471
|
+
* @returns {number}
|
|
472
|
+
*/
|
|
473
|
+
width() {
|
|
474
|
+
const ret = wasm.wasmpixmap_width(this.__wbg_ptr);
|
|
475
|
+
return ret >>> 0;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
if (Symbol.dispose) WasmPixmap.prototype[Symbol.dispose] = WasmPixmap.prototype.free;
|
|
479
|
+
function __wbg_get_imports() {
|
|
480
|
+
const import0 = {
|
|
481
|
+
__proto__: null,
|
|
482
|
+
__wbg_Error_408e67f47ca7b58b: function(arg0, arg1) {
|
|
483
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
484
|
+
return ret;
|
|
485
|
+
},
|
|
486
|
+
__wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
|
|
487
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
488
|
+
},
|
|
489
|
+
__wbg_length_13032799523c5735: function(arg0) {
|
|
490
|
+
const ret = arg0.length;
|
|
491
|
+
return ret;
|
|
492
|
+
},
|
|
493
|
+
__wbg_new_with_length_5d351ffdb6e3397d: function(arg0) {
|
|
494
|
+
const ret = new Uint8ClampedArray(arg0 >>> 0);
|
|
495
|
+
return ret;
|
|
496
|
+
},
|
|
497
|
+
__wbg_set_5c15d3c5973de97a: function(arg0, arg1, arg2) {
|
|
498
|
+
arg0.set(getArrayU8FromWasm0(arg1, arg2));
|
|
499
|
+
},
|
|
500
|
+
__wbg_wasmpixmap_new: function(arg0) {
|
|
501
|
+
const ret = WasmPixmap.__wrap(arg0);
|
|
502
|
+
return ret;
|
|
503
|
+
},
|
|
504
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
505
|
+
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8ClampedArray")`.
|
|
506
|
+
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
507
|
+
return ret;
|
|
508
|
+
},
|
|
509
|
+
__wbindgen_init_externref_table: function() {
|
|
510
|
+
const table = wasm.__wbindgen_externrefs;
|
|
511
|
+
const offset = table.grow(4);
|
|
512
|
+
table.set(0, undefined);
|
|
513
|
+
table.set(offset + 0, undefined);
|
|
514
|
+
table.set(offset + 1, null);
|
|
515
|
+
table.set(offset + 2, true);
|
|
516
|
+
table.set(offset + 3, false);
|
|
517
|
+
},
|
|
518
|
+
};
|
|
519
|
+
return {
|
|
520
|
+
__proto__: null,
|
|
521
|
+
"./djvu_rs_bg.js": import0,
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const WasmDocumentFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
526
|
+
? { register: () => {}, unregister: () => {} }
|
|
527
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmdocument_free(ptr, 1));
|
|
528
|
+
const WasmPageFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
529
|
+
? { register: () => {}, unregister: () => {} }
|
|
530
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmpage_free(ptr, 1));
|
|
531
|
+
const WasmPixmapFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
532
|
+
? { register: () => {}, unregister: () => {} }
|
|
533
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmpixmap_free(ptr, 1));
|
|
534
|
+
|
|
535
|
+
function _assertClass(instance, klass) {
|
|
536
|
+
if (!(instance instanceof klass)) {
|
|
537
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
542
|
+
ptr = ptr >>> 0;
|
|
543
|
+
const mem = getDataViewMemory0();
|
|
544
|
+
const result = [];
|
|
545
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
546
|
+
result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
|
|
547
|
+
}
|
|
548
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
549
|
+
return result;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
553
|
+
ptr = ptr >>> 0;
|
|
554
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
let cachedDataViewMemory0 = null;
|
|
558
|
+
function getDataViewMemory0() {
|
|
559
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
560
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
561
|
+
}
|
|
562
|
+
return cachedDataViewMemory0;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
function getStringFromWasm0(ptr, len) {
|
|
566
|
+
return decodeText(ptr >>> 0, len);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
let cachedUint8ArrayMemory0 = null;
|
|
570
|
+
function getUint8ArrayMemory0() {
|
|
571
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
572
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
573
|
+
}
|
|
574
|
+
return cachedUint8ArrayMemory0;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
578
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
579
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
580
|
+
WASM_VECTOR_LEN = arg.length;
|
|
581
|
+
return ptr;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function takeFromExternrefTable0(idx) {
|
|
585
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
586
|
+
wasm.__externref_table_dealloc(idx);
|
|
587
|
+
return value;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
591
|
+
cachedTextDecoder.decode();
|
|
592
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
593
|
+
let numBytesDecoded = 0;
|
|
594
|
+
function decodeText(ptr, len) {
|
|
595
|
+
numBytesDecoded += len;
|
|
596
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
597
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
598
|
+
cachedTextDecoder.decode();
|
|
599
|
+
numBytesDecoded = len;
|
|
600
|
+
}
|
|
601
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
let WASM_VECTOR_LEN = 0;
|
|
605
|
+
|
|
606
|
+
let wasmModule, wasmInstance, wasm;
|
|
607
|
+
function __wbg_finalize_init(instance, module) {
|
|
608
|
+
wasmInstance = instance;
|
|
609
|
+
wasm = instance.exports;
|
|
610
|
+
wasmModule = module;
|
|
611
|
+
cachedDataViewMemory0 = null;
|
|
612
|
+
cachedUint8ArrayMemory0 = null;
|
|
613
|
+
wasm.__wbindgen_start();
|
|
614
|
+
return wasm;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
async function __wbg_load(module, imports) {
|
|
618
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
619
|
+
if (!module.ok) {
|
|
620
|
+
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
624
|
+
try {
|
|
625
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
626
|
+
} catch (e) {
|
|
627
|
+
const validResponse = expectedResponseType(module.type);
|
|
628
|
+
|
|
629
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
630
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
631
|
+
|
|
632
|
+
} else { throw e; }
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
const bytes = await module.arrayBuffer();
|
|
637
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
638
|
+
} else {
|
|
639
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
640
|
+
|
|
641
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
642
|
+
return { instance, module };
|
|
643
|
+
} else {
|
|
644
|
+
return instance;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function expectedResponseType(type) {
|
|
649
|
+
switch (type) {
|
|
650
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
651
|
+
}
|
|
652
|
+
return false;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function initSync(module) {
|
|
657
|
+
if (wasm !== undefined) return wasm;
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
if (module !== undefined) {
|
|
661
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
662
|
+
({module} = module)
|
|
663
|
+
} else {
|
|
664
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const imports = __wbg_get_imports();
|
|
669
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
670
|
+
module = new WebAssembly.Module(module);
|
|
671
|
+
}
|
|
672
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
673
|
+
return __wbg_finalize_init(instance, module);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
async function __wbg_init(module_or_path) {
|
|
677
|
+
if (wasm !== undefined) return wasm;
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
if (module_or_path !== undefined) {
|
|
681
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
682
|
+
({module_or_path} = module_or_path)
|
|
683
|
+
} else {
|
|
684
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
if (module_or_path === undefined) {
|
|
689
|
+
module_or_path = new URL('djvu_rs_bg.wasm', import.meta.url);
|
|
690
|
+
}
|
|
691
|
+
const imports = __wbg_get_imports();
|
|
692
|
+
|
|
693
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
694
|
+
module_or_path = fetch(module_or_path);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
698
|
+
|
|
699
|
+
return __wbg_finalize_init(instance, module);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|