react-pdf-viewer-wasm 0.1.1 → 0.1.2
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/dist/index.mjs +137 -137
- package/dist/pdf-core/loadPdfEngine.d.ts +14 -7
- package/package.json +3 -2
- package/readme.md +39 -0
- package/dist/pdf_core_bg.wasm +0 -0
package/dist/index.mjs
CHANGED
|
@@ -15,7 +15,7 @@ var l = Object.defineProperty, u = /* @__PURE__ */ ((e, t) => {
|
|
|
15
15
|
get_page_count: () => p,
|
|
16
16
|
get_page_dimensions: () => m,
|
|
17
17
|
get_text_chars: () => h,
|
|
18
|
-
initSync: () =>
|
|
18
|
+
initSync: () => ae,
|
|
19
19
|
initialize: () => g,
|
|
20
20
|
initialize_pdfium_render: () => _,
|
|
21
21
|
open_document: () => v,
|
|
@@ -25,59 +25,59 @@ var l = Object.defineProperty, u = /* @__PURE__ */ ((e, t) => {
|
|
|
25
25
|
write_block_from_callback_wasm: () => S
|
|
26
26
|
});
|
|
27
27
|
function d(e) {
|
|
28
|
-
let t =
|
|
29
|
-
if (t[1]) throw
|
|
28
|
+
let t = W.close_document(e);
|
|
29
|
+
if (t[1]) throw R(t[0]);
|
|
30
30
|
}
|
|
31
31
|
function f(e, t) {
|
|
32
|
-
let n =
|
|
33
|
-
if (n[3]) throw
|
|
34
|
-
var r =
|
|
35
|
-
return n[0] !== 0 &&
|
|
32
|
+
let n = W.extract_text(e, t);
|
|
33
|
+
if (n[3]) throw R(n[2]);
|
|
34
|
+
var r = O(n[0], n[1]);
|
|
35
|
+
return n[0] !== 0 && W.__wbindgen_free(n[0], n[1], 1), r;
|
|
36
36
|
}
|
|
37
37
|
function p(e) {
|
|
38
|
-
let t =
|
|
39
|
-
if (t[2]) throw
|
|
38
|
+
let t = W.get_page_count(e);
|
|
39
|
+
if (t[2]) throw R(t[1]);
|
|
40
40
|
return t[0] >>> 0;
|
|
41
41
|
}
|
|
42
42
|
function m(e, t) {
|
|
43
|
-
let n =
|
|
44
|
-
if (n[3]) throw
|
|
45
|
-
var r =
|
|
46
|
-
return
|
|
43
|
+
let n = W.get_page_dimensions(e, t);
|
|
44
|
+
if (n[3]) throw R(n[2]);
|
|
45
|
+
var r = E(n[0], n[1]).slice();
|
|
46
|
+
return W.__wbindgen_free(n[0], n[1] * 4, 4), r;
|
|
47
47
|
}
|
|
48
48
|
function h(e, t) {
|
|
49
|
-
let n =
|
|
50
|
-
if (n[3]) throw
|
|
51
|
-
var r =
|
|
52
|
-
return n[0] !== 0 &&
|
|
49
|
+
let n = W.get_text_chars(e, t);
|
|
50
|
+
if (n[3]) throw R(n[2]);
|
|
51
|
+
var r = O(n[0], n[1]);
|
|
52
|
+
return n[0] !== 0 && W.__wbindgen_free(n[0], n[1], 1), r;
|
|
53
53
|
}
|
|
54
54
|
function g() {
|
|
55
|
-
let e =
|
|
56
|
-
if (e[1]) throw
|
|
55
|
+
let e = W.initialize();
|
|
56
|
+
if (e[1]) throw R(e[0]);
|
|
57
57
|
}
|
|
58
58
|
function _(e, t, n) {
|
|
59
|
-
return
|
|
59
|
+
return W.initialize_pdfium_render(e, t, n) !== 0;
|
|
60
60
|
}
|
|
61
61
|
function v(e, t) {
|
|
62
|
-
let n =
|
|
63
|
-
var i =
|
|
64
|
-
let o =
|
|
65
|
-
if (o[2]) throw
|
|
62
|
+
let n = ne(e, W.__wbindgen_malloc), r = U;
|
|
63
|
+
var i = I(t) ? 0 : L(t, W.__wbindgen_malloc, W.__wbindgen_realloc), a = U;
|
|
64
|
+
let o = W.open_document(n, r, i, a);
|
|
65
|
+
if (o[2]) throw R(o[1]);
|
|
66
66
|
return o[0] >>> 0;
|
|
67
67
|
}
|
|
68
68
|
function y(e, t, n, r) {
|
|
69
|
-
return
|
|
69
|
+
return W.read_block_from_callback_wasm(e, t, n, r);
|
|
70
70
|
}
|
|
71
71
|
function b(e, t, n, r) {
|
|
72
|
-
let i =
|
|
73
|
-
if (i[2]) throw
|
|
74
|
-
return
|
|
72
|
+
let i = W.render_page(e, t, n, r);
|
|
73
|
+
if (i[2]) throw R(i[1]);
|
|
74
|
+
return R(i[0]);
|
|
75
75
|
}
|
|
76
76
|
function x() {
|
|
77
|
-
|
|
77
|
+
W.start();
|
|
78
78
|
}
|
|
79
79
|
function S(e, t, n) {
|
|
80
|
-
return
|
|
80
|
+
return W.write_block_from_callback_wasm(e, t, n);
|
|
81
81
|
}
|
|
82
82
|
function C() {
|
|
83
83
|
return {
|
|
@@ -85,8 +85,8 @@ function C() {
|
|
|
85
85
|
"./pdf_core_bg.js": {
|
|
86
86
|
__proto__: null,
|
|
87
87
|
__wbg___wbindgen_debug_string_0e68cf47c9cbd9b0: function(e, t) {
|
|
88
|
-
let n =
|
|
89
|
-
|
|
88
|
+
let n = L(T(t), W.__wbindgen_malloc, W.__wbindgen_realloc), r = U;
|
|
89
|
+
A().setInt32(e + 4, r, !0), A().setInt32(e + 0, n, !0);
|
|
90
90
|
},
|
|
91
91
|
__wbg___wbindgen_is_object_edb6b15aa3afe12e: function(e) {
|
|
92
92
|
let t = e;
|
|
@@ -100,24 +100,24 @@ function C() {
|
|
|
100
100
|
},
|
|
101
101
|
__wbg___wbindgen_number_get_1dc732b810cb937c: function(e, t) {
|
|
102
102
|
let n = t, r = typeof n == "number" ? n : void 0;
|
|
103
|
-
|
|
103
|
+
A().setFloat64(e + 8, I(r) ? 0 : r, !0), A().setInt32(e + 0, !I(r), !0);
|
|
104
104
|
},
|
|
105
105
|
__wbg___wbindgen_string_get_92ab86bb19cbc12f: function(e, t) {
|
|
106
106
|
let n = t, r = typeof n == "string" ? n : void 0;
|
|
107
|
-
var i =
|
|
108
|
-
|
|
107
|
+
var i = I(r) ? 0 : L(r, W.__wbindgen_malloc, W.__wbindgen_realloc), a = U;
|
|
108
|
+
A().setInt32(e + 4, a, !0), A().setInt32(e + 0, i, !0);
|
|
109
109
|
},
|
|
110
110
|
__wbg___wbindgen_throw_5d9e815e6fdf150f: function(e, t) {
|
|
111
|
-
var n =
|
|
111
|
+
var n = O(e, t);
|
|
112
112
|
throw Error(n);
|
|
113
113
|
},
|
|
114
114
|
__wbg_apply_5d9aa7604c2490a8: function() {
|
|
115
|
-
return
|
|
115
|
+
return F(function(e, t, n) {
|
|
116
116
|
return e.apply(t, n);
|
|
117
117
|
}, arguments);
|
|
118
118
|
},
|
|
119
119
|
__wbg_call_6bcf8d3e20937e46: function() {
|
|
120
|
-
return
|
|
120
|
+
return F(function(e, t, n) {
|
|
121
121
|
return e.call(t, n);
|
|
122
122
|
}, arguments);
|
|
123
123
|
},
|
|
@@ -125,17 +125,17 @@ function C() {
|
|
|
125
125
|
console.debug(e);
|
|
126
126
|
},
|
|
127
127
|
__wbg_decode_ec8279b49e2f79cf: function() {
|
|
128
|
-
return
|
|
129
|
-
let i =
|
|
130
|
-
|
|
128
|
+
return F(function(e, t, n, r) {
|
|
129
|
+
let i = L(t.decode(D(n, r)), W.__wbindgen_malloc, W.__wbindgen_realloc), a = U;
|
|
130
|
+
A().setInt32(e + 4, a, !0), A().setInt32(e + 0, i, !0);
|
|
131
131
|
}, arguments);
|
|
132
132
|
},
|
|
133
133
|
__wbg_error_756c5934221e6fee: function(e) {
|
|
134
134
|
console.error(e);
|
|
135
135
|
},
|
|
136
136
|
__wbg_error_757e9472f8410341: function(e, t) {
|
|
137
|
-
var n =
|
|
138
|
-
e !== 0 &&
|
|
137
|
+
var n = O(e, t);
|
|
138
|
+
e !== 0 && W.__wbindgen_free(e, t, 1), console.error(n);
|
|
139
139
|
},
|
|
140
140
|
__wbg_from_a39669ce566077da: function(e) {
|
|
141
141
|
return Array.from(e);
|
|
@@ -144,12 +144,12 @@ function C() {
|
|
|
144
144
|
return e.getTime();
|
|
145
145
|
},
|
|
146
146
|
__wbg_get_97dc2df9d87d0f6a: function() {
|
|
147
|
-
return
|
|
147
|
+
return F(function(e, t) {
|
|
148
148
|
return e.get(t >>> 0);
|
|
149
149
|
}, arguments);
|
|
150
150
|
},
|
|
151
151
|
__wbg_get_989d0a1309644f2b: function() {
|
|
152
|
-
return
|
|
152
|
+
return F(function(e, t) {
|
|
153
153
|
return Reflect.get(e, t);
|
|
154
154
|
}, arguments);
|
|
155
155
|
},
|
|
@@ -190,11 +190,11 @@ function C() {
|
|
|
190
190
|
return [];
|
|
191
191
|
},
|
|
192
192
|
__wbg_new_from_slice_4ee02165f9de919e: function(e, t) {
|
|
193
|
-
return new Uint8Array(
|
|
193
|
+
return new Uint8Array(D(e, t));
|
|
194
194
|
},
|
|
195
195
|
__wbg_new_with_label_aad02dde1eb03f9b: function() {
|
|
196
|
-
return
|
|
197
|
-
var n =
|
|
196
|
+
return F(function(e, t) {
|
|
197
|
+
var n = O(e, t);
|
|
198
198
|
return new TextDecoder(n);
|
|
199
199
|
}, arguments);
|
|
200
200
|
},
|
|
@@ -232,7 +232,7 @@ function C() {
|
|
|
232
232
|
];
|
|
233
233
|
},
|
|
234
234
|
__wbg_prototypesetcall_ae9f5e7459250748: function(e, t, n) {
|
|
235
|
-
Uint8Array.prototype.set.call(
|
|
235
|
+
Uint8Array.prototype.set.call(D(e, t), n);
|
|
236
236
|
},
|
|
237
237
|
__wbg_push_bfdf956ba476f65b: function(e, t) {
|
|
238
238
|
return e.push(t);
|
|
@@ -241,7 +241,7 @@ function C() {
|
|
|
241
241
|
e[t >>> 0] = n;
|
|
242
242
|
},
|
|
243
243
|
__wbg_set_361ed22a3b8802e9: function() {
|
|
244
|
-
return
|
|
244
|
+
return F(function(e, t, n) {
|
|
245
245
|
e.set(t >>> 0, n);
|
|
246
246
|
}, arguments);
|
|
247
247
|
},
|
|
@@ -252,24 +252,24 @@ function C() {
|
|
|
252
252
|
return e.slice(t >>> 0, n >>> 0);
|
|
253
253
|
},
|
|
254
254
|
__wbg_stack_3b0d974bbf31e44f: function(e, t) {
|
|
255
|
-
let n = t.stack, r =
|
|
256
|
-
|
|
255
|
+
let n = t.stack, r = L(n, W.__wbindgen_malloc, W.__wbindgen_realloc), i = U;
|
|
256
|
+
A().setInt32(e + 4, i, !0), A().setInt32(e + 0, r, !0);
|
|
257
257
|
},
|
|
258
258
|
__wbg_static_accessor_GLOBAL_8eb4cd83130a11a0: function() {
|
|
259
259
|
let e = typeof global > "u" ? null : global;
|
|
260
|
-
return
|
|
260
|
+
return I(e) ? 0 : w(e);
|
|
261
261
|
},
|
|
262
262
|
__wbg_static_accessor_GLOBAL_THIS_1e7044f654e934db: function() {
|
|
263
263
|
let e = typeof globalThis > "u" ? null : globalThis;
|
|
264
|
-
return
|
|
264
|
+
return I(e) ? 0 : w(e);
|
|
265
265
|
},
|
|
266
266
|
__wbg_static_accessor_SELF_d8b50611246a6d92: function() {
|
|
267
267
|
let e = typeof self > "u" ? null : self;
|
|
268
|
-
return
|
|
268
|
+
return I(e) ? 0 : w(e);
|
|
269
269
|
},
|
|
270
270
|
__wbg_static_accessor_WINDOW_fd0bc376bf0f8b42: function() {
|
|
271
271
|
let e = typeof window > "u" ? null : window;
|
|
272
|
-
return
|
|
272
|
+
return I(e) ? 0 : w(e);
|
|
273
273
|
},
|
|
274
274
|
__wbg_subarray_1daff70dde20c145: function(e, t, n) {
|
|
275
275
|
return e.subarray(t >>> 0, n >>> 0);
|
|
@@ -281,21 +281,21 @@ function C() {
|
|
|
281
281
|
return e;
|
|
282
282
|
},
|
|
283
283
|
__wbindgen_generic_0000000000000002: function(e, t) {
|
|
284
|
-
return
|
|
284
|
+
return O(e, t);
|
|
285
285
|
},
|
|
286
286
|
__wbindgen_generic_0000000000000003: function(e, t) {
|
|
287
|
-
return
|
|
287
|
+
return D(e, t);
|
|
288
288
|
},
|
|
289
289
|
__wbindgen_init_externref_table: function() {
|
|
290
|
-
let e =
|
|
290
|
+
let e = W.__wbindgen_externrefs, t = e.grow(4);
|
|
291
291
|
e.set(0, void 0), e.set(t + 0, void 0), e.set(t + 1, null), e.set(t + 2, !0), e.set(t + 3, !1);
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
};
|
|
295
295
|
}
|
|
296
296
|
function w(e) {
|
|
297
|
-
let t =
|
|
298
|
-
return
|
|
297
|
+
let t = W.__externref_table_alloc();
|
|
298
|
+
return W.__wbindgen_externrefs.set(t, e), t;
|
|
299
299
|
}
|
|
300
300
|
function T(e) {
|
|
301
301
|
let t = typeof e;
|
|
@@ -325,54 +325,54 @@ function T(e) {
|
|
|
325
325
|
}
|
|
326
326
|
return e instanceof Error ? `${e.name}: ${e.message}\n${e.stack}` : r;
|
|
327
327
|
}
|
|
328
|
-
function ee(e, t) {
|
|
329
|
-
return e >>>= 0, te().subarray(e / 4, e / 4 + t);
|
|
330
|
-
}
|
|
331
328
|
function E(e, t) {
|
|
332
|
-
return e >>>= 0,
|
|
329
|
+
return e >>>= 0, ee().subarray(e / 4, e / 4 + t);
|
|
333
330
|
}
|
|
334
331
|
function D(e, t) {
|
|
335
|
-
return e
|
|
332
|
+
return e >>>= 0, P().subarray(e / 1, e / 1 + t);
|
|
336
333
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
return (O === null || O.buffer.detached === !0 || O.buffer.detached === void 0 && O.buffer !== H.memory.buffer) && (O = new DataView(H.memory.buffer)), O;
|
|
334
|
+
function O(e, t) {
|
|
335
|
+
return e === 0 ? te(t) : M(e, t);
|
|
340
336
|
}
|
|
341
|
-
var
|
|
342
|
-
function
|
|
343
|
-
return (
|
|
337
|
+
var k = null;
|
|
338
|
+
function A() {
|
|
339
|
+
return (k === null || k.buffer.detached === !0 || k.buffer.detached === void 0 && k.buffer !== W.memory.buffer) && (k = new DataView(W.memory.buffer)), k;
|
|
344
340
|
}
|
|
345
|
-
|
|
346
|
-
|
|
341
|
+
var j = null;
|
|
342
|
+
function ee() {
|
|
343
|
+
return (j === null || j.byteLength === 0) && (j = new Float32Array(W.memory.buffer)), j;
|
|
347
344
|
}
|
|
348
|
-
function
|
|
349
|
-
return
|
|
345
|
+
function te(e) {
|
|
346
|
+
return W.__wbindgen_externrefs.get(e);
|
|
350
347
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
return (j === null || j.byteLength === 0) && (j = new Uint8Array(H.memory.buffer)), j;
|
|
348
|
+
function M(e, t) {
|
|
349
|
+
return V(e >>> 0, t);
|
|
354
350
|
}
|
|
355
|
-
|
|
351
|
+
var N = null;
|
|
352
|
+
function P() {
|
|
353
|
+
return (N === null || N.byteLength === 0) && (N = new Uint8Array(W.memory.buffer)), N;
|
|
354
|
+
}
|
|
355
|
+
function F(e, t) {
|
|
356
356
|
try {
|
|
357
357
|
return e.apply(this, t);
|
|
358
358
|
} catch (e) {
|
|
359
359
|
let t = w(e);
|
|
360
|
-
|
|
360
|
+
W.__wbindgen_exn_store(t);
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
|
-
function
|
|
363
|
+
function I(e) {
|
|
364
364
|
return e == null;
|
|
365
365
|
}
|
|
366
|
-
function
|
|
366
|
+
function ne(e, t) {
|
|
367
367
|
let n = t(e.length * 1, 1) >>> 0;
|
|
368
|
-
return
|
|
368
|
+
return P().set(e, n / 1), U = e.length, n;
|
|
369
369
|
}
|
|
370
|
-
function
|
|
370
|
+
function L(e, t, n) {
|
|
371
371
|
if (n === void 0) {
|
|
372
|
-
let n =
|
|
373
|
-
return
|
|
372
|
+
let n = H.encode(e), r = t(n.length, 1) >>> 0;
|
|
373
|
+
return P().subarray(r, r + n.length).set(n), U = n.length, r;
|
|
374
374
|
}
|
|
375
|
-
let r = e.length, i = t(r, 1) >>> 0, a =
|
|
375
|
+
let r = e.length, i = t(r, 1) >>> 0, a = P(), o = 0;
|
|
376
376
|
for (; o < r; o++) {
|
|
377
377
|
let t = e.charCodeAt(o);
|
|
378
378
|
if (t > 127) break;
|
|
@@ -380,40 +380,40 @@ function F(e, t, n) {
|
|
|
380
380
|
}
|
|
381
381
|
if (o !== r) {
|
|
382
382
|
o !== 0 && (e = e.slice(o)), i = n(i, r, r = o + e.length * 3, 1) >>> 0;
|
|
383
|
-
let t =
|
|
383
|
+
let t = P().subarray(i + o, i + r), a = H.encodeInto(e, t);
|
|
384
384
|
o += a.written, i = n(i, r, o, 1) >>> 0;
|
|
385
385
|
}
|
|
386
|
-
return
|
|
386
|
+
return U = o, i;
|
|
387
387
|
}
|
|
388
|
-
function
|
|
389
|
-
let t =
|
|
390
|
-
return
|
|
388
|
+
function R(e) {
|
|
389
|
+
let t = W.__wbindgen_externrefs.get(e);
|
|
390
|
+
return W.__externref_table_dealloc(e), t;
|
|
391
391
|
}
|
|
392
|
-
var
|
|
392
|
+
var z = new TextDecoder("utf-8", {
|
|
393
393
|
ignoreBOM: !0,
|
|
394
394
|
fatal: !0
|
|
395
395
|
});
|
|
396
|
-
|
|
397
|
-
var
|
|
398
|
-
function
|
|
399
|
-
return
|
|
396
|
+
z.decode();
|
|
397
|
+
var re = 2146435072, B = 0;
|
|
398
|
+
function V(e, t) {
|
|
399
|
+
return B += t, B >= re && (z = new TextDecoder("utf-8", {
|
|
400
400
|
ignoreBOM: !0,
|
|
401
401
|
fatal: !0
|
|
402
|
-
}),
|
|
402
|
+
}), z.decode(), B = t), z.decode(P().subarray(e, e + t));
|
|
403
403
|
}
|
|
404
|
-
var
|
|
405
|
-
"encodeInto" in
|
|
406
|
-
let n =
|
|
404
|
+
var H = new TextEncoder();
|
|
405
|
+
"encodeInto" in H || (H.encodeInto = function(e, t) {
|
|
406
|
+
let n = H.encode(e);
|
|
407
407
|
return t.set(n), {
|
|
408
408
|
read: e.length,
|
|
409
409
|
written: n.length
|
|
410
410
|
};
|
|
411
411
|
});
|
|
412
|
-
var
|
|
413
|
-
function
|
|
414
|
-
return
|
|
412
|
+
var U = 0, W;
|
|
413
|
+
function G(e, t) {
|
|
414
|
+
return W = e.exports, k = null, j = null, N = null, W.__wbindgen_start(), W;
|
|
415
415
|
}
|
|
416
|
-
async function
|
|
416
|
+
async function ie(e, t) {
|
|
417
417
|
if (typeof Response == "function" && e instanceof Response) {
|
|
418
418
|
if (!e.ok) throw Error(`failed to fetch Wasm: ${e.status} ${e.statusText} fetching '${e.url}'`);
|
|
419
419
|
if (typeof WebAssembly.instantiateStreaming == "function") try {
|
|
@@ -441,28 +441,28 @@ async function W(e, t) {
|
|
|
441
441
|
return !1;
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
|
-
function
|
|
445
|
-
if (
|
|
444
|
+
function ae(e) {
|
|
445
|
+
if (W !== void 0) return W;
|
|
446
446
|
e !== void 0 && (Object.getPrototypeOf(e) === Object.prototype ? {module: e} = e : console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));
|
|
447
447
|
let t = C();
|
|
448
|
-
return e instanceof WebAssembly.Module || (e = new WebAssembly.Module(e)),
|
|
448
|
+
return e instanceof WebAssembly.Module || (e = new WebAssembly.Module(e)), G(new WebAssembly.Instance(e, t), e);
|
|
449
449
|
}
|
|
450
450
|
async function K(e) {
|
|
451
|
-
if (
|
|
451
|
+
if (W !== void 0) return W;
|
|
452
452
|
e !== void 0 && (Object.getPrototypeOf(e) === Object.prototype ? {module_or_path: e} = e : console.warn("using deprecated parameters for the initialization function; pass a single object instead")), e === void 0 && (e = new URL("/pdf_core_bg.wasm", "" + import.meta.url));
|
|
453
453
|
let t = C();
|
|
454
454
|
(typeof e == "string" || typeof Request == "function" && e instanceof Request || typeof URL == "function" && e instanceof URL) && (e = fetch(e));
|
|
455
|
-
let { instance: n, module: r } = await
|
|
456
|
-
return
|
|
455
|
+
let { instance: n, module: r } = await ie(await e, t);
|
|
456
|
+
return G(n, r);
|
|
457
457
|
}
|
|
458
458
|
//#endregion
|
|
459
|
-
//#region src/pdf-core/
|
|
460
|
-
var q = "
|
|
461
|
-
function ce(e) {
|
|
462
|
-
if (X) throw Error("setPdfiumSource() must be called before the first <Document> is rendered. The pdfium engine has already started loading.");
|
|
463
|
-
J = e.jsUrl, Y = e.wasmUrl;
|
|
464
|
-
}
|
|
459
|
+
//#region src/pdf-core/loadPdfEngine.ts
|
|
460
|
+
var q = "https://cdn.jsdelivr.net/npm/pdf-viewer-assets@1.1.0", oe = `${q}/pdfium.js`, se = `${q}/pdfium.wasm`, ce = `${q}/pdf_core_bg.wasm`, J = oe, Y = se, X = ce, Z = null;
|
|
465
461
|
function le(e) {
|
|
462
|
+
if (Z) throw Error("setPdfiumSource() must be called before the first <Document> is rendered. The pdfium engine has already started loading.");
|
|
463
|
+
J = e.jsUrl, Y = e.wasmUrl, X = e.coreWasmUrl;
|
|
464
|
+
}
|
|
465
|
+
function ue(e) {
|
|
466
466
|
return new Promise((t, n) => {
|
|
467
467
|
if (document.querySelector(`script[src="${e}"]`)) {
|
|
468
468
|
t();
|
|
@@ -472,23 +472,23 @@ function le(e) {
|
|
|
472
472
|
r.src = e, r.onload = () => t(), r.onerror = () => n(/* @__PURE__ */ Error(`Failed to load script: ${e}`)), document.head.appendChild(r);
|
|
473
473
|
});
|
|
474
474
|
}
|
|
475
|
-
function
|
|
476
|
-
return
|
|
477
|
-
await
|
|
475
|
+
function Q() {
|
|
476
|
+
return Z || (Z = (async () => {
|
|
477
|
+
await ue(J);
|
|
478
478
|
let e = await window.PDFiumModule({ locateFile: () => Y });
|
|
479
|
-
if (await K({ module_or_path:
|
|
479
|
+
if (await K({ module_or_path: X }), !_(e, u, !1)) throw Error("Failed to initialize pdfium-render");
|
|
480
480
|
return g(), u;
|
|
481
|
-
})(),
|
|
481
|
+
})(), Z);
|
|
482
482
|
}
|
|
483
483
|
//#endregion
|
|
484
484
|
//#region src/components/Document.tsx
|
|
485
|
-
var
|
|
486
|
-
function
|
|
487
|
-
let e = n(
|
|
485
|
+
var $ = e(null);
|
|
486
|
+
function de() {
|
|
487
|
+
let e = n($);
|
|
488
488
|
if (!e) throw Error("Page must be used inside a Document");
|
|
489
489
|
return e;
|
|
490
490
|
}
|
|
491
|
-
async function
|
|
491
|
+
async function fe(e, t) {
|
|
492
492
|
if (e instanceof Uint8Array) return e;
|
|
493
493
|
if (e instanceof File) return new Uint8Array(await e.arrayBuffer());
|
|
494
494
|
let n = await fetch(e);
|
|
@@ -505,7 +505,7 @@ async function ue(e, t) {
|
|
|
505
505
|
for (let e of a) s.set(e, c), c += e.length;
|
|
506
506
|
return s;
|
|
507
507
|
}
|
|
508
|
-
var
|
|
508
|
+
var pe = t(function({ file: e, className: t, scale: n = 1, rotate: c = 0, error: l = "Failed to load PDF file.", loading: u = "Loading PDF…", noData: d = "No PDF file specified.", children: f, onLoadSuccess: p, onLoadError: m, onLoadProgress: h, onSourceSuccess: g, onSourceError: _, onPassword: v }, y) {
|
|
509
509
|
let [b, x] = o(null), [S, C] = o("loading"), w = a(null);
|
|
510
510
|
i(y, () => w.current), r(() => {
|
|
511
511
|
if (!e) {
|
|
@@ -515,7 +515,7 @@ var de = t(function({ file: e, className: t, scale: n = 1, rotate: c = 0, error:
|
|
|
515
515
|
let t = !1;
|
|
516
516
|
return C("loading"), (async () => {
|
|
517
517
|
try {
|
|
518
|
-
let n = await
|
|
518
|
+
let n = await Q(), r = await fe(e, (e, t) => {
|
|
519
519
|
h?.({
|
|
520
520
|
loaded: e,
|
|
521
521
|
total: t
|
|
@@ -565,7 +565,7 @@ var de = t(function({ file: e, className: t, scale: n = 1, rotate: c = 0, error:
|
|
|
565
565
|
}) : /* @__PURE__ */ s("div", {
|
|
566
566
|
className: T,
|
|
567
567
|
ref: w,
|
|
568
|
-
children: /* @__PURE__ */ s(
|
|
568
|
+
children: /* @__PURE__ */ s($.Provider, {
|
|
569
569
|
value: {
|
|
570
570
|
docHandle: b,
|
|
571
571
|
scale: n,
|
|
@@ -581,12 +581,12 @@ var de = t(function({ file: e, className: t, scale: n = 1, rotate: c = 0, error:
|
|
|
581
581
|
});
|
|
582
582
|
//#endregion
|
|
583
583
|
//#region src/components/TextLayer.tsx
|
|
584
|
-
function
|
|
584
|
+
function me({ docHandle: e, pageIndex: t, scale: n, pageWidthPts: i, pageHeightPts: a }) {
|
|
585
585
|
let [c, l] = o([]);
|
|
586
586
|
return r(() => {
|
|
587
587
|
let n = !1;
|
|
588
588
|
return (async () => {
|
|
589
|
-
let r = (await
|
|
589
|
+
let r = (await Q()).get_text_chars(e, t);
|
|
590
590
|
n || l(JSON.parse(r));
|
|
591
591
|
})(), () => {
|
|
592
592
|
n = !0;
|
|
@@ -621,12 +621,12 @@ function fe({ docHandle: e, pageIndex: t, scale: n, pageWidthPts: i, pageHeightP
|
|
|
621
621
|
}
|
|
622
622
|
//#endregion
|
|
623
623
|
//#region src/components/Page.tsx
|
|
624
|
-
function
|
|
625
|
-
let l =
|
|
624
|
+
function he({ pageIndex: e, scale: t, rotate: n, textSelectable: i = !0 }) {
|
|
625
|
+
let l = de(), u = t ?? l.scale, d = n ?? l.rotate, f = a(null), [p, m] = o(null);
|
|
626
626
|
return r(() => {
|
|
627
627
|
let t = !1;
|
|
628
628
|
return (async () => {
|
|
629
|
-
let n = await
|
|
629
|
+
let n = await Q(), [r, i] = n.get_page_dimensions(l.docHandle, e), a = d === 90 || d === 270, o = a ? i : r, s = a ? r : i, c = Math.round(o * u), p = Math.round(s * u), h = n.render_page(l.docHandle, e, u, d);
|
|
630
630
|
if (t || !f.current) return;
|
|
631
631
|
let g = f.current;
|
|
632
632
|
g.width = c, g.height = p, g.getContext("2d").putImageData(new ImageData(new Uint8ClampedArray(h), c, p), 0, 0), m({
|
|
@@ -649,7 +649,7 @@ function pe({ pageIndex: e, scale: t, rotate: n, textSelectable: i = !0 }) {
|
|
|
649
649
|
children: [/* @__PURE__ */ s("canvas", {
|
|
650
650
|
ref: f,
|
|
651
651
|
style: { display: "block" }
|
|
652
|
-
}), i && p && /* @__PURE__ */ s(
|
|
652
|
+
}), i && p && /* @__PURE__ */ s(me, {
|
|
653
653
|
docHandle: l.docHandle,
|
|
654
654
|
pageIndex: e,
|
|
655
655
|
scale: u,
|
|
@@ -659,4 +659,4 @@ function pe({ pageIndex: e, scale: t, rotate: n, textSelectable: i = !0 }) {
|
|
|
659
659
|
});
|
|
660
660
|
}
|
|
661
661
|
//#endregion
|
|
662
|
-
export {
|
|
662
|
+
export { pe as Document, he as Page, le as setPdfiumSource };
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import * as PdfCore from './pdf_core.js';
|
|
2
2
|
/**
|
|
3
|
-
* Override where the pdfium engine
|
|
4
|
-
* Call this
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* Override where the pdfium engine files are loaded from.
|
|
4
|
+
* Call this ONCE before rendering any <Document>, e.g. in your app's entry file.
|
|
5
|
+
*
|
|
6
|
+
* Use this if you need to self-host the binaries instead of loading them from
|
|
7
|
+
* the default CDN (e.g. offline apps, corporate networks, strict CSP policies).
|
|
8
|
+
*
|
|
9
|
+
* Download all three files from:
|
|
10
|
+
* https://cdn.jsdelivr.net/npm/pdf-viewer-assets@1.1.0/
|
|
11
|
+
*
|
|
12
|
+
* Put them in your app's `public/` folder, then call:
|
|
7
13
|
*
|
|
8
|
-
* Example:
|
|
9
14
|
* setPdfiumSource({
|
|
10
|
-
* jsUrl:
|
|
11
|
-
* wasmUrl:
|
|
15
|
+
* jsUrl: '/pdfium.js',
|
|
16
|
+
* wasmUrl: '/pdfium.wasm',
|
|
17
|
+
* coreWasmUrl: '/pdf_core_bg.wasm',
|
|
12
18
|
* });
|
|
13
19
|
*/
|
|
14
20
|
export declare function setPdfiumSource(options: {
|
|
15
21
|
jsUrl: string;
|
|
16
22
|
wasmUrl: string;
|
|
23
|
+
coreWasmUrl: string;
|
|
17
24
|
}): void;
|
|
18
25
|
export declare function loadPdfEngine(): Promise<typeof PdfCore>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-pdf-viewer-wasm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A React PDF viewer powered by Rust + WebAssembly, using pdfium as the rendering backend.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
|
-
"dist"
|
|
16
|
+
"dist",
|
|
17
|
+
"!dist/pdf_core_bg.wasm"
|
|
17
18
|
],
|
|
18
19
|
"peerDependencies": {
|
|
19
20
|
"react": ">=18.0.0",
|
package/readme.md
CHANGED
|
@@ -31,6 +31,45 @@ That's it. You don't need to download or configure anything else — this librar
|
|
|
31
31
|
|
|
32
32
|
---
|
|
33
33
|
|
|
34
|
+
## Vite setup (required)
|
|
35
|
+
|
|
36
|
+
Add the following to your app's `vite.config.ts`. This is needed because the library's WASM file must be served to the browser, and the browser requires special security headers to run it:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import react from '@vitejs/plugin-react'
|
|
40
|
+
import { defineConfig } from 'vite'
|
|
41
|
+
import { createReadStream, existsSync } from 'fs'
|
|
42
|
+
import { resolve } from 'path'
|
|
43
|
+
|
|
44
|
+
function servePdfCoreWasm() {
|
|
45
|
+
return {
|
|
46
|
+
name: 'serve-pdf-core-wasm',
|
|
47
|
+
configureServer(server: any) {
|
|
48
|
+
server.middlewares.use('/pdf_core_bg.wasm', (_req: any, res: any, next: any) => {
|
|
49
|
+
const wasmPath = resolve(
|
|
50
|
+
import.meta.dirname,
|
|
51
|
+
'node_modules/react-pdf-viewer-wasm/dist/pdf_core_bg.wasm'
|
|
52
|
+
)
|
|
53
|
+
if (!existsSync(wasmPath)) return next()
|
|
54
|
+
res.setHeader('Content-Type', 'application/wasm')
|
|
55
|
+
createReadStream(wasmPath).pipe(res)
|
|
56
|
+
})
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default defineConfig({
|
|
62
|
+
plugins: [react(), servePdfCoreWasm()],
|
|
63
|
+
server: {
|
|
64
|
+
headers: {
|
|
65
|
+
// Required for pdfium.wasm (uses SharedArrayBuffer)
|
|
66
|
+
'Cross-Origin-Opener-Policy': 'same-origin',
|
|
67
|
+
'Cross-Origin-Embedder-Policy': 'require-corp',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
34
73
|
## Showing your first PDF
|
|
35
74
|
|
|
36
75
|
```tsx
|
package/dist/pdf_core_bg.wasm
DELETED
|
Binary file
|