pdfjs-vue3 0.1.8 → 0.1.9

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": "pdfjs-vue3",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Using pdfjs to display PDFs as a vue 3 component.",
5
5
  "author": "Eugene Wang",
6
6
  "license": "Apache-2.0",
@@ -36,18 +36,18 @@
36
36
  "preview": "vite preview"
37
37
  },
38
38
  "peerDependencies": {
39
- "pdfjs-dist": "^3.6.172",
40
- "vue": "^3.2.47"
39
+ "pdfjs-dist": "^3.11.174",
40
+ "vue": "^3.3.4"
41
41
  },
42
42
  "devDependencies": {
43
- "@babel/types": "^7.21.5",
44
- "@types/lodash": "^4.14.194",
45
- "@types/node": "^18.16.6",
46
- "@vitejs/plugin-vue": "^4.2.1",
43
+ "@babel/types": "^7.23.0",
44
+ "@types/lodash": "^4.14.199",
45
+ "@types/node": "^18.18.4",
46
+ "@vitejs/plugin-vue": "^4.4.0",
47
47
  "lodash": "^4.17.21",
48
- "modern-normalize": "^1.1.0",
49
- "typescript": "^5.0.4",
50
- "vite": "^4.3.5",
51
- "vue-tsc": "^1.6.4"
48
+ "modern-normalize": "^2.0.0",
49
+ "typescript": "^5.2.2",
50
+ "vite": "^4.4.11",
51
+ "vue-tsc": "^1.8.18"
52
52
  }
53
53
  }
@@ -1,482 +0,0 @@
1
- import { defineComponent as N, ref as P, watch as j, onMounted as L, openBlock as x, createElementBlock as $, computed as M, onBeforeUnmount as G, createElementVNode as W, createBlock as R, unref as k, createCommentVNode as D, renderSlot as E, toDisplayString as Q, shallowRef as B, Fragment as Z, renderList as ee, withCtx as F, nextTick as ie } from "vue";
2
- import { renderTextLayer as ae, getDocument as le, GlobalWorkerOptions as se } from "pdfjs-dist";
3
- var S = /* @__PURE__ */ ((e) => (e[e.Auto = 0] = "Auto", e[e.WidthFit = 1] = "WidthFit", e[e.PageFit = 2] = "PageFit", e[e.Custom = 3] = "Custom", e))(S || {}), I = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
4
- function ue(e) {
5
- return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
6
- }
7
- function ce(e) {
8
- var i = typeof e;
9
- return e != null && (i == "object" || i == "function");
10
- }
11
- var te = ce, de = typeof I == "object" && I && I.Object === Object && I, fe = de, pe = fe, me = typeof self == "object" && self && self.Object === Object && self, ve = pe || me || Function("return this")(), oe = ve, ge = oe, he = function() {
12
- return ge.Date.now();
13
- }, be = he, ye = /\s/;
14
- function we(e) {
15
- for (var i = e.length; i-- && ye.test(e.charAt(i)); )
16
- ;
17
- return i;
18
- }
19
- var Te = we, xe = Te, Pe = /^\s+/;
20
- function _e(e) {
21
- return e && e.slice(0, xe(e) + 1).replace(Pe, "");
22
- }
23
- var ze = _e, Se = oe, $e = Se.Symbol, ne = $e, U = ne, re = Object.prototype, ke = re.hasOwnProperty, je = re.toString, C = U ? U.toStringTag : void 0;
24
- function Ee(e) {
25
- var i = ke.call(e, C), l = e[C];
26
- try {
27
- e[C] = void 0;
28
- var n = !0;
29
- } catch {
30
- }
31
- var s = je.call(e);
32
- return n && (i ? e[C] = l : delete e[C]), s;
33
- }
34
- var Oe = Ee, Ce = Object.prototype, Me = Ce.toString;
35
- function Ie(e) {
36
- return Me.call(e);
37
- }
38
- var Ne = Ie, K = ne, Le = Oe, We = Ne, Be = "[object Null]", Ve = "[object Undefined]", X = K ? K.toStringTag : void 0;
39
- function De(e) {
40
- return e == null ? e === void 0 ? Ve : Be : X && X in Object(e) ? Le(e) : We(e);
41
- }
42
- var Fe = De;
43
- function Ae(e) {
44
- return e != null && typeof e == "object";
45
- }
46
- var Ge = Ae, Re = Fe, He = Ge, Ue = "[object Symbol]";
47
- function Ke(e) {
48
- return typeof e == "symbol" || He(e) && Re(e) == Ue;
49
- }
50
- var Xe = Ke, Ye = ze, Y = te, qe = Xe, q = 0 / 0, Je = /^[-+]0x[0-9a-f]+$/i, Qe = /^0b[01]+$/i, Ze = /^0o[0-7]+$/i, et = parseInt;
51
- function tt(e) {
52
- if (typeof e == "number")
53
- return e;
54
- if (qe(e))
55
- return q;
56
- if (Y(e)) {
57
- var i = typeof e.valueOf == "function" ? e.valueOf() : e;
58
- e = Y(i) ? i + "" : i;
59
- }
60
- if (typeof e != "string")
61
- return e === 0 ? e : +e;
62
- e = Ye(e);
63
- var l = Qe.test(e);
64
- return l || Ze.test(e) ? et(e.slice(2), l ? 2 : 8) : Je.test(e) ? q : +e;
65
- }
66
- var ot = tt, nt = te, V = be, J = ot, rt = "Expected a function", it = Math.max, at = Math.min;
67
- function lt(e, i, l) {
68
- var n, s, b, g, d, u, y = 0, T = !1, w = !1, o = !0;
69
- if (typeof e != "function")
70
- throw new TypeError(rt);
71
- i = J(i) || 0, nt(l) && (T = !!l.leading, w = "maxWait" in l, b = w ? it(J(l.maxWait) || 0, i) : b, o = "trailing" in l ? !!l.trailing : o);
72
- function c(v) {
73
- var z = n, O = s;
74
- return n = s = void 0, y = v, g = e.apply(O, z), g;
75
- }
76
- function f(v) {
77
- return y = v, d = setTimeout(t, i), T ? c(v) : g;
78
- }
79
- function a(v) {
80
- var z = v - u, O = v - y, H = i - z;
81
- return w ? at(H, b - O) : H;
82
- }
83
- function h(v) {
84
- var z = v - u, O = v - y;
85
- return u === void 0 || z >= i || z < 0 || w && O >= b;
86
- }
87
- function t() {
88
- var v = V();
89
- if (h(v))
90
- return r(v);
91
- d = setTimeout(t, a(v));
92
- }
93
- function r(v) {
94
- return d = void 0, o && n ? c(v) : (n = s = void 0, g);
95
- }
96
- function p() {
97
- d !== void 0 && clearTimeout(d), y = 0, n = u = s = d = void 0;
98
- }
99
- function m() {
100
- return d === void 0 ? g : r(V());
101
- }
102
- function _() {
103
- var v = V(), z = h(v);
104
- if (n = arguments, s = this, u = v, z) {
105
- if (d === void 0)
106
- return f(u);
107
- if (w)
108
- return clearTimeout(d), d = setTimeout(t, i), c(u);
109
- }
110
- return d === void 0 && (d = setTimeout(t, i)), g;
111
- }
112
- return _.cancel = p, _.flush = m, _;
113
- }
114
- var st = lt;
115
- const A = /* @__PURE__ */ ue(st), ut = /* @__PURE__ */ N({
116
- __name: "PdfPageText",
117
- props: {
118
- viewport: null,
119
- page: null
120
- },
121
- setup(e) {
122
- const i = e, l = P(), n = P();
123
- j(() => i.page, async (g) => {
124
- l.value = await g.getTextContent();
125
- }, { immediate: !0 }), j(() => [l.value, n.value, i.viewport], () => {
126
- b();
127
- });
128
- let s;
129
- function b() {
130
- const g = n.value, d = l.value, u = i.viewport;
131
- if (!(!g || !d || !u)) {
132
- if (s) {
133
- s.cancel();
134
- return;
135
- }
136
- for (; g.firstChild; )
137
- g.removeChild(g.firstChild);
138
- s = ae({
139
- textContentSource: d,
140
- container: g,
141
- viewport: u
142
- // enhanceTextSelection: true
143
- }), s.promise.then(() => {
144
- s = void 0;
145
- }).catch(() => {
146
- s = void 0;
147
- }).finally(() => {
148
- });
149
- }
150
- }
151
- return L(() => {
152
- b();
153
- }), (g, d) => (x(), $("div", {
154
- ref_key: "rootEl",
155
- ref: n,
156
- class: "pdf-text-layer"
157
- }, null, 512));
158
- }
159
- });
160
- const ct = { class: "pdf-page-layout" }, dt = { class: "pdf-page-overlay" }, ft = {
161
- key: 0,
162
- class: "pdf-page-number"
163
- }, pt = /* @__PURE__ */ N({
164
- __name: "PdfPage",
165
- props: {
166
- zoom: null,
167
- zoomType: null,
168
- hideText: { type: Boolean },
169
- hideNumber: { type: Boolean },
170
- viewport: null,
171
- page: null,
172
- observer: null
173
- },
174
- emits: ["update:zoom"],
175
- setup(e, { expose: i, emit: l }) {
176
- const n = e, s = P(), b = P(), g = P(!1), d = 1100;
177
- i({ rootEl: b, inViewport: g });
178
- const u = 96 / 72, y = M(() => {
179
- const { width: a, height: h } = n.page.getViewport({ scale: u }), { width: t, height: r } = n.viewport;
180
- let p = 0, m = 1;
181
- switch (n.zoomType) {
182
- case S.Auto:
183
- return p = Math.min(t, d) - 40, m = p / a, u * m;
184
- case S.WidthFit:
185
- return p = t - 40, m = p / a, u * m;
186
- case S.PageFit:
187
- return t > r ? (m = r / h, u * m) : (p = t - 40, m = p / a, u * m);
188
- }
189
- return u * n.zoom;
190
- }), T = M(() => y.value * ((window == null ? void 0 : window.devicePixelRatio) || 1)), w = M(() => n.page.getViewport({ scale: y.value })), o = M(() => n.page.getViewport({ scale: T.value }));
191
- j(y, (a) => {
192
- const h = a / u;
193
- Math.abs(h - n.zoom) > 0.05 && l("update:zoom", h);
194
- }, { immediate: !0 });
195
- let c;
196
- function f() {
197
- if (!n.page || !s.value)
198
- return;
199
- const a = n.page, h = w.value, t = o.value, r = s.value;
200
- r.width = Math.ceil(t.width), r.height = Math.ceil(t.height), r.style.width = Math.floor(h.width) + "px", r.style.height = Math.floor(h.height) + "px";
201
- const p = r.getContext("2d");
202
- if (!p || !g.value)
203
- return;
204
- if (c) {
205
- c.cancel();
206
- return;
207
- }
208
- console.debug(`rendering page ${a.pageNumber}`);
209
- const m = {
210
- canvasContext: p,
211
- viewport: o.value
212
- };
213
- c = a.render(m), c.promise.then(() => c = void 0).catch(() => {
214
- c = void 0, f();
215
- });
216
- }
217
- return j(() => [n.page, T.value, g.value], () => {
218
- f();
219
- }, { immediate: !0 }), L(() => {
220
- var a;
221
- f(), b.value && ((a = n.observer) == null || a.observe(b.value));
222
- }), G(() => {
223
- var a;
224
- b.value && ((a = n.observer) == null || a.unobserve(b.value));
225
- }), (a, h) => (x(), $("div", {
226
- ref_key: "rootEl",
227
- ref: b,
228
- class: "pdf-page"
229
- }, [
230
- W("div", ct, [
231
- W("canvas", {
232
- ref_key: "canvas",
233
- ref: s
234
- }, null, 512),
235
- W("div", dt, [
236
- e.hideText ? D("", !0) : (x(), R(ut, {
237
- key: 0,
238
- viewport: k(o),
239
- page: e.page
240
- }, null, 8, ["viewport", "page"])),
241
- E(a.$slots, "default", { displaySize: k(o) })
242
- ])
243
- ]),
244
- e.hideNumber ? D("", !0) : (x(), $("div", ft, Q(e.page.pageNumber), 1))
245
- ], 512));
246
- }
247
- });
248
- const mt = {
249
- key: 0,
250
- class: "pdf-progress"
251
- }, vt = /* @__PURE__ */ N({
252
- __name: "PdfDocument",
253
- props: {
254
- hideText: { type: Boolean },
255
- hideNumber: { type: Boolean },
256
- zoomType: null,
257
- zoom: null,
258
- viewport: null,
259
- src: null
260
- },
261
- emits: ["error", "update:zoom"],
262
- setup(e, { emit: i }) {
263
- const l = e, n = B(), s = B([]), b = B(), g = P();
264
- let d = [];
265
- const u = P(!1), y = P(0);
266
- function T(o) {
267
- o && (d.push(o), d.length == 1 && (o.inViewport = !0));
268
- }
269
- function w() {
270
- s.value.forEach((c) => c.cleanup()), s.value = [];
271
- const o = n.value;
272
- o && (o.destroy(), n.value = void 0), d = [];
273
- }
274
- return j(() => l.src, (o) => {
275
- if (w(), !o)
276
- return;
277
- const c = le(o);
278
- u.value = !0, c.onProgress = (f) => {
279
- f.total && (y.value = f.loaded / f.total);
280
- }, c.promise.then((f) => {
281
- n.value = f;
282
- const a = [];
283
- for (let h = 1; h <= f.numPages; h++)
284
- a.push(f.getPage(h));
285
- Promise.all(a).then((h) => {
286
- f === n.value && (s.value = h);
287
- });
288
- }).catch((f) => {
289
- i("error", f);
290
- }).finally(() => {
291
- u.value = !1;
292
- });
293
- }, { immediate: !0 }), L(() => {
294
- b.value = new IntersectionObserver(A((o) => {
295
- o.forEach((c) => {
296
- const f = d.find((a) => (a == null ? void 0 : a.rootEl) === c.target);
297
- f && (f.inViewport = c.isIntersecting);
298
- });
299
- }, 50), {
300
- // root: rootEl.value,
301
- rootMargin: "0px"
302
- });
303
- }), G(() => {
304
- var o;
305
- w(), (o = b.value) == null || o.disconnect();
306
- }), (o, c) => (x(), $("div", {
307
- ref_key: "rootEl",
308
- ref: g
309
- }, [
310
- E(o.$slots, "loading", {
311
- src: l.src,
312
- loading: u.value,
313
- progress: y.value
314
- }, () => [
315
- u.value ? (x(), $("p", mt, "loading " + Q(Math.ceil(100 * y.value)) + "%", 1)) : D("", !0)
316
- ]),
317
- (x(!0), $(Z, null, ee(k(s), (f) => (x(), R(pt, {
318
- ref_for: !0,
319
- ref: T,
320
- key: f.pageNumber,
321
- page: f,
322
- "hide-number": e.hideNumber,
323
- "hide-text": e.hideText,
324
- "zoom-type": e.zoomType,
325
- zoom: e.zoom,
326
- "onUpdate:zoom": c[0] || (c[0] = (a) => i("update:zoom", a)),
327
- observer: k(b),
328
- viewport: e.viewport
329
- }, {
330
- default: F(({ displaySize: a }) => [
331
- E(o.$slots, "default", {
332
- doc: k(n),
333
- page: f,
334
- displaySize: a
335
- })
336
- ]),
337
- _: 2
338
- }, 1032, ["page", "hide-number", "hide-text", "zoom-type", "zoom", "observer", "viewport"]))), 128))
339
- ], 512));
340
- }
341
- });
342
- const bt = /* @__PURE__ */ N({
343
- __name: "PdfHost",
344
- props: {
345
- workerSrc: null,
346
- sources: null,
347
- zoomType: null,
348
- zoom: null,
349
- hideText: { type: Boolean },
350
- hideNumber: { type: Boolean },
351
- enablePinchZoom: { type: Boolean }
352
- },
353
- emits: ["update:zoom", "update:zoomType"],
354
- setup(e, { expose: i, emit: l }) {
355
- const n = e, s = P();
356
- i({
357
- /**
358
- * Try to increase zoom to the next level, up to 200%.
359
- */
360
- zoomIn: T,
361
- /**
362
- * Try to decrease zoom to the next level, down to 25%.
363
- */
364
- zoomOut: w
365
- }), j(() => n.workerSrc, (t) => {
366
- t && (se.workerSrc = t);
367
- }, { immediate: !0 });
368
- function b(t) {
369
- t.ctrlKey && (t.preventDefault(), t.deltaY < 0 ? T() : w());
370
- }
371
- function g(t) {
372
- t.ctrlKey && (t.key === "0" || t.which == 48) && l("update:zoomType", S.Auto);
373
- }
374
- const d = P({ width: 0, height: 0 }), u = A(() => {
375
- const t = s.value;
376
- t && (d.value = {
377
- width: t.offsetWidth,
378
- height: t.offsetHeight
379
- });
380
- }, 100);
381
- function y(t) {
382
- const r = t % 0.25;
383
- return Number((t - r).toFixed(2));
384
- }
385
- function T() {
386
- const t = y((n.zoom || 1) + 0.25);
387
- l("update:zoom", Math.min(t, 2)), l("update:zoomType", S.Custom);
388
- }
389
- function w() {
390
- const t = y((n.zoom || 1) - 0.25);
391
- l("update:zoom", Math.max(t, 0.25)), l("update:zoomType", S.Custom);
392
- }
393
- j(() => n.zoom, (t, r) => {
394
- const p = s.value;
395
- if (p && t && r) {
396
- const m = p.scrollTop, _ = p.scrollLeft, v = t / r;
397
- ie(() => {
398
- p.scrollTop = m * v, p.scrollLeft = _ * v;
399
- });
400
- }
401
- }), L(() => {
402
- window.addEventListener("resize", u), u();
403
- }), G(() => {
404
- window.removeEventListener("resize", u);
405
- });
406
- const o = [];
407
- let c = -1;
408
- function f(t) {
409
- n.enablePinchZoom && o.push(t);
410
- }
411
- const a = A((t) => {
412
- if (n.enablePinchZoom) {
413
- for (let r = 0; r < o.length; r++)
414
- if (t.pointerId === o[r].pointerId) {
415
- o[r] = t;
416
- break;
417
- }
418
- if (o.length === 2) {
419
- const r = Math.abs(o[0].clientX - o[1].clientX), p = Math.abs(o[0].clientY - o[1].clientY), m = Math.sqrt(Math.pow(r, 2) + Math.pow(p, 2));
420
- c > 0 && (m > c && T(), m < c && w()), c = m;
421
- }
422
- }
423
- }, 10);
424
- function h(t) {
425
- if (n.enablePinchZoom) {
426
- for (let r = 0; r < o.length; r++)
427
- if (o[r].pointerId === t.pointerId) {
428
- o.splice(r, 1);
429
- break;
430
- }
431
- o.length < 2 && (c = -1);
432
- }
433
- }
434
- return (t, r) => (x(), $("div", {
435
- ref_key: "rootEl",
436
- ref: s,
437
- onWheel: b,
438
- onKeydown: g,
439
- onPointerdown: f,
440
- onPointermove: r[1] || (r[1] = //@ts-ignore
441
- (...p) => k(a) && k(a)(...p)),
442
- onPointerup: h,
443
- onPointercancel: h,
444
- onPointerleave: h,
445
- onPointerout: h,
446
- tabindex: "0",
447
- class: "pdf-host"
448
- }, [
449
- (x(!0), $(Z, null, ee(e.sources, (p) => (x(), R(vt, {
450
- viewport: d.value,
451
- src: p,
452
- "hide-number": !!e.hideNumber,
453
- "hide-text": !!e.hideText,
454
- "zoom-type": e.zoomType || k(S).Auto,
455
- zoom: e.zoom || 1,
456
- "onUpdate:zoom": r[0] || (r[0] = (m) => l("update:zoom", m))
457
- }, {
458
- loading: F(({ loading: m, progress: _ }) => [
459
- E(t.$slots, "loading", {
460
- source: p,
461
- loading: m,
462
- progress: _
463
- })
464
- ]),
465
- default: F(({ doc: m, page: _, displaySize: v }) => [
466
- E(t.$slots, "page", {
467
- source: p,
468
- doc: m,
469
- page: _,
470
- displaySize: v
471
- })
472
- ]),
473
- _: 2
474
- }, 1032, ["viewport", "src", "hide-number", "hide-text", "zoom-type", "zoom"]))), 256)),
475
- E(t.$slots, "default")
476
- ], 544));
477
- }
478
- });
479
- export {
480
- bt as PdfHost,
481
- S as ZoomType
482
- };
@@ -1 +0,0 @@
1
- (function(x,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("pdfjs-dist")):typeof define=="function"&&define.amd?define(["exports","vue","pdfjs-dist"],t):(x=typeof globalThis<"u"?globalThis:x||self,t(x.pdfjsVue3={},x.Vue,x.pdfjsLib))})(this,function(x,t,$){"use strict";var P=(e=>(e[e.Auto=0]="Auto",e[e.WidthFit=1]="WidthFit",e[e.PageFit=2]="PageFit",e[e.Custom=3]="Custom",e))(P||{}),B=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function G(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function U(e){var a=typeof e;return e!=null&&(a=="object"||a=="function")}var O=U,H=typeof B=="object"&&B&&B.Object===Object&&B,q=H,K=q,X=typeof self=="object"&&self&&self.Object===Object&&self,Y=K||X||Function("return this")(),M=Y,J=M,Q=function(){return J.Date.now()},Z=Q,ee=/\s/;function te(e){for(var a=e.length;a--&&ee.test(e.charAt(a)););return a}var oe=te,ne=oe,re=/^\s+/;function ie(e){return e&&e.slice(0,ne(e)+1).replace(re,"")}var ae=ie,le=M,ce=le.Symbol,N=ce,I=N,V=Object.prototype,se=V.hasOwnProperty,de=V.toString,S=I?I.toStringTag:void 0;function fe(e){var a=se.call(e,S),c=e[S];try{e[S]=void 0;var r=!0}catch{}var s=de.call(e);return r&&(a?e[S]=c:delete e[S]),s}var ue=fe,pe=Object.prototype,me=pe.toString;function he(e){return me.call(e)}var ge=he,L=N,be=ue,ye=ge,we="[object Null]",ve="[object Undefined]",W=L?L.toStringTag:void 0;function Te(e){return e==null?e===void 0?ve:we:W&&W in Object(e)?be(e):ye(e)}var ke=Te;function xe(e){return e!=null&&typeof e=="object"}var Pe=xe,_e=ke,ze=Pe,Se="[object Symbol]";function Ee(e){return typeof e=="symbol"||ze(e)&&_e(e)==Se}var Be=Ee,$e=ae,F=O,je=Be,D=0/0,Ce=/^[-+]0x[0-9a-f]+$/i,Oe=/^0b[01]+$/i,Me=/^0o[0-7]+$/i,Ne=parseInt;function Ie(e){if(typeof e=="number")return e;if(je(e))return D;if(F(e)){var a=typeof e.valueOf=="function"?e.valueOf():e;e=F(a)?a+"":a}if(typeof e!="string")return e===0?e:+e;e=$e(e);var c=Oe.test(e);return c||Me.test(e)?Ne(e.slice(2),c?2:8):Ce.test(e)?D:+e}var Ve=Ie,Le=O,j=Z,A=Ve,We="Expected a function",Fe=Math.max,De=Math.min;function Ae(e,a,c){var r,s,w,b,u,d,v=0,k=!1,T=!1,n=!0;if(typeof e!="function")throw new TypeError(We);a=A(a)||0,Le(c)&&(k=!!c.leading,T="maxWait"in c,w=T?Fe(A(c.maxWait)||0,a):w,n="trailing"in c?!!c.trailing:n);function f(g){var z=r,E=s;return r=s=void 0,v=g,b=e.apply(E,z),b}function p(g){return v=g,u=setTimeout(o,a),k?f(g):b}function l(g){var z=g-d,E=g-v,R=a-z;return T?De(R,w-E):R}function y(g){var z=g-d,E=g-v;return d===void 0||z>=a||z<0||T&&E>=w}function o(){var g=j();if(y(g))return i(g);u=setTimeout(o,l(g))}function i(g){return u=void 0,n&&r?f(g):(r=s=void 0,b)}function m(){u!==void 0&&clearTimeout(u),v=0,r=d=s=u=void 0}function h(){return u===void 0?b:i(j())}function _(){var g=j(),z=y(g);if(r=arguments,s=this,d=g,z){if(u===void 0)return p(d);if(T)return clearTimeout(u),u=setTimeout(o,a),f(d)}return u===void 0&&(u=setTimeout(o,a)),b}return _.cancel=m,_.flush=h,_}var Re=Ae;const C=G(Re),Ge=t.defineComponent({__name:"PdfPageText",props:{viewport:null,page:null},setup(e){const a=e,c=t.ref(),r=t.ref();t.watch(()=>a.page,async b=>{c.value=await b.getTextContent()},{immediate:!0}),t.watch(()=>[c.value,r.value,a.viewport],()=>{w()});let s;function w(){const b=r.value,u=c.value,d=a.viewport;if(!(!b||!u||!d)){if(s){s.cancel();return}for(;b.firstChild;)b.removeChild(b.firstChild);s=$.renderTextLayer({textContentSource:u,container:b,viewport:d}),s.promise.then(()=>{s=void 0}).catch(()=>{s=void 0}).finally(()=>{})}}return t.onMounted(()=>{w()}),(b,u)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"rootEl",ref:r,class:"pdf-text-layer"},null,512))}}),Qe="",Ue={class:"pdf-page-layout"},He={class:"pdf-page-overlay"},qe={key:0,class:"pdf-page-number"},Ke=t.defineComponent({__name:"PdfPage",props:{zoom:null,zoomType:null,hideText:{type:Boolean},hideNumber:{type:Boolean},viewport:null,page:null,observer:null},emits:["update:zoom"],setup(e,{expose:a,emit:c}){const r=e,s=t.ref(),w=t.ref(),b=t.ref(!1),u=1100;a({rootEl:w,inViewport:b});const d=96/72,v=t.computed(()=>{const{width:l,height:y}=r.page.getViewport({scale:d}),{width:o,height:i}=r.viewport;let m=0,h=1;switch(r.zoomType){case P.Auto:return m=Math.min(o,u)-40,h=m/l,d*h;case P.WidthFit:return m=o-40,h=m/l,d*h;case P.PageFit:return o>i?(h=i/y,d*h):(m=o-40,h=m/l,d*h)}return d*r.zoom}),k=t.computed(()=>v.value*((window==null?void 0:window.devicePixelRatio)||1)),T=t.computed(()=>r.page.getViewport({scale:v.value})),n=t.computed(()=>r.page.getViewport({scale:k.value}));t.watch(v,l=>{const y=l/d;Math.abs(y-r.zoom)>.05&&c("update:zoom",y)},{immediate:!0});let f;function p(){if(!r.page||!s.value)return;const l=r.page,y=T.value,o=n.value,i=s.value;i.width=Math.ceil(o.width),i.height=Math.ceil(o.height),i.style.width=Math.floor(y.width)+"px",i.style.height=Math.floor(y.height)+"px";const m=i.getContext("2d");if(!m||!b.value)return;if(f){f.cancel();return}console.debug(`rendering page ${l.pageNumber}`);const h={canvasContext:m,viewport:n.value};f=l.render(h),f.promise.then(()=>f=void 0).catch(()=>{f=void 0,p()})}return t.watch(()=>[r.page,k.value,b.value],()=>{p()},{immediate:!0}),t.onMounted(()=>{var l;p(),w.value&&((l=r.observer)==null||l.observe(w.value))}),t.onBeforeUnmount(()=>{var l;w.value&&((l=r.observer)==null||l.unobserve(w.value))}),(l,y)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"rootEl",ref:w,class:"pdf-page"},[t.createElementVNode("div",Ue,[t.createElementVNode("canvas",{ref_key:"canvas",ref:s},null,512),t.createElementVNode("div",He,[e.hideText?t.createCommentVNode("",!0):(t.openBlock(),t.createBlock(Ge,{key:0,viewport:t.unref(n),page:e.page},null,8,["viewport","page"])),t.renderSlot(l.$slots,"default",{displaySize:t.unref(n)})])]),e.hideNumber?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock("div",qe,t.toDisplayString(e.page.pageNumber),1))],512))}}),Ze="",Xe={key:0,class:"pdf-progress"},Ye=t.defineComponent({__name:"PdfDocument",props:{hideText:{type:Boolean},hideNumber:{type:Boolean},zoomType:null,zoom:null,viewport:null,src:null},emits:["error","update:zoom"],setup(e,{emit:a}){const c=e,r=t.shallowRef(),s=t.shallowRef([]),w=t.shallowRef(),b=t.ref();let u=[];const d=t.ref(!1),v=t.ref(0);function k(n){n&&(u.push(n),u.length==1&&(n.inViewport=!0))}function T(){s.value.forEach(f=>f.cleanup()),s.value=[];const n=r.value;n&&(n.destroy(),r.value=void 0),u=[]}return t.watch(()=>c.src,n=>{if(T(),!n)return;const f=$.getDocument(n);d.value=!0,f.onProgress=p=>{p.total&&(v.value=p.loaded/p.total)},f.promise.then(p=>{r.value=p;const l=[];for(let y=1;y<=p.numPages;y++)l.push(p.getPage(y));Promise.all(l).then(y=>{p===r.value&&(s.value=y)})}).catch(p=>{a("error",p)}).finally(()=>{d.value=!1})},{immediate:!0}),t.onMounted(()=>{w.value=new IntersectionObserver(C(n=>{n.forEach(f=>{const p=u.find(l=>(l==null?void 0:l.rootEl)===f.target);p&&(p.inViewport=f.isIntersecting)})},50),{rootMargin:"0px"})}),t.onBeforeUnmount(()=>{var n;T(),(n=w.value)==null||n.disconnect()}),(n,f)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"rootEl",ref:b},[t.renderSlot(n.$slots,"loading",{src:c.src,loading:d.value,progress:v.value},()=>[d.value?(t.openBlock(),t.createElementBlock("p",Xe,"loading "+t.toDisplayString(Math.ceil(100*v.value))+"%",1)):t.createCommentVNode("",!0)]),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(s),p=>(t.openBlock(),t.createBlock(Ke,{ref_for:!0,ref:k,key:p.pageNumber,page:p,"hide-number":e.hideNumber,"hide-text":e.hideText,"zoom-type":e.zoomType,zoom:e.zoom,"onUpdate:zoom":f[0]||(f[0]=l=>a("update:zoom",l)),observer:t.unref(w),viewport:e.viewport},{default:t.withCtx(({displaySize:l})=>[t.renderSlot(n.$slots,"default",{doc:t.unref(r),page:p,displaySize:l})]),_:2},1032,["page","hide-number","hide-text","zoom-type","zoom","observer","viewport"]))),128))],512))}}),et="",Je=t.defineComponent({__name:"PdfHost",props:{workerSrc:null,sources:null,zoomType:null,zoom:null,hideText:{type:Boolean},hideNumber:{type:Boolean},enablePinchZoom:{type:Boolean}},emits:["update:zoom","update:zoomType"],setup(e,{expose:a,emit:c}){const r=e,s=t.ref();a({zoomIn:k,zoomOut:T}),t.watch(()=>r.workerSrc,o=>{o&&($.GlobalWorkerOptions.workerSrc=o)},{immediate:!0});function w(o){o.ctrlKey&&(o.preventDefault(),o.deltaY<0?k():T())}function b(o){o.ctrlKey&&(o.key==="0"||o.which==48)&&c("update:zoomType",P.Auto)}const u=t.ref({width:0,height:0}),d=C(()=>{const o=s.value;o&&(u.value={width:o.offsetWidth,height:o.offsetHeight})},100);function v(o){const i=o%.25;return Number((o-i).toFixed(2))}function k(){const o=v((r.zoom||1)+.25);c("update:zoom",Math.min(o,2)),c("update:zoomType",P.Custom)}function T(){const o=v((r.zoom||1)-.25);c("update:zoom",Math.max(o,.25)),c("update:zoomType",P.Custom)}t.watch(()=>r.zoom,(o,i)=>{const m=s.value;if(m&&o&&i){const h=m.scrollTop,_=m.scrollLeft,g=o/i;t.nextTick(()=>{m.scrollTop=h*g,m.scrollLeft=_*g})}}),t.onMounted(()=>{window.addEventListener("resize",d),d()}),t.onBeforeUnmount(()=>{window.removeEventListener("resize",d)});const n=[];let f=-1;function p(o){r.enablePinchZoom&&n.push(o)}const l=C(o=>{if(r.enablePinchZoom){for(let i=0;i<n.length;i++)if(o.pointerId===n[i].pointerId){n[i]=o;break}if(n.length===2){const i=Math.abs(n[0].clientX-n[1].clientX),m=Math.abs(n[0].clientY-n[1].clientY),h=Math.sqrt(Math.pow(i,2)+Math.pow(m,2));f>0&&(h>f&&k(),h<f&&T()),f=h}}},10);function y(o){if(r.enablePinchZoom){for(let i=0;i<n.length;i++)if(n[i].pointerId===o.pointerId){n.splice(i,1);break}n.length<2&&(f=-1)}}return(o,i)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"rootEl",ref:s,onWheel:w,onKeydown:b,onPointerdown:p,onPointermove:i[1]||(i[1]=(...m)=>t.unref(l)&&t.unref(l)(...m)),onPointerup:y,onPointercancel:y,onPointerleave:y,onPointerout:y,tabindex:"0",class:"pdf-host"},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.sources,m=>(t.openBlock(),t.createBlock(Ye,{viewport:u.value,src:m,"hide-number":!!e.hideNumber,"hide-text":!!e.hideText,"zoom-type":e.zoomType||t.unref(P).Auto,zoom:e.zoom||1,"onUpdate:zoom":i[0]||(i[0]=h=>c("update:zoom",h))},{loading:t.withCtx(({loading:h,progress:_})=>[t.renderSlot(o.$slots,"loading",{source:m,loading:h,progress:_})]),default:t.withCtx(({doc:h,page:_,displaySize:g})=>[t.renderSlot(o.$slots,"page",{source:m,doc:h,page:_,displaySize:g})]),_:2},1032,["viewport","src","hide-number","hide-text","zoom-type","zoom"]))),256)),t.renderSlot(o.$slots,"default")],544))}}),tt="";x.PdfHost=Je,x.ZoomType=P,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
package/dist/style.css DELETED
@@ -1 +0,0 @@
1
- .pdf-text-layer{position:absolute;text-align:initial;left:0;top:0;right:0;bottom:0;overflow:hidden;opacity:.2;line-height:1;text-size-adjust:none}.pdf-text-layer span,.pdf-text-layer br{color:transparent;position:absolute;white-space:pre;cursor:text;transform-origin:0% 0%}.pdf-text-layer span.markedContent{top:0;height:0}.pdf-text-layer .highlight{margin:-1px;padding:1px;background-color:#b400aa;border-radius:4px}.pdf-text-layer .highlight.appended{position:initial}.pdf-text-layer .highlight.begin{border-radius:4px 0 0 4px}.pdf-text-layer .highlight.end{border-radius:0 4px 4px 0}.pdf-text-layer .highlight.middle{border-radius:0}.pdf-text-layer .highlight.selected{background-color:#006400}.pdf-text-layer ::selection{background:rgb(0,153,255)}.pdf-text-layer br::selection{background:transparent}.pdf-text-layer .endOfContent{display:block;position:absolute;left:0;top:100%;right:0;bottom:0;z-index:-1;cursor:default;user-select:none}.pdf-text-layer .endOfContent.active{top:0}.pdf-page{margin:1rem auto;display:flex;flex-direction:column}.pdf-page-layout{position:relative;display:flex;margin-bottom:.5rem;margin:auto;background:#fff;filter:drop-shadow(0 1px 2px rgb(0 0 0 / .1)) drop-shadow(0 1px 1px rgb(0 0 0 / .06))}.pdf-page-number{text-align:center;line-height:1.5}.pdf-page-overlay{position:absolute;top:0;left:0;right:0;bottom:0}.pdf-progress{text-align:center;padding:1rem}.pdf-host{height:100%;overflow:auto;padding:1rem 0;background:gainsboro;touch-action:pan-x pan-y}.pdf-host:focus{outline:none}
@@ -1,105 +0,0 @@
1
- import { PdfSource, ZoomType } from './types';
2
- declare function zoomIn(): void;
3
- declare function zoomOut(): void;
4
- declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_TypePropsToRuntimeProps<{
5
- /**
6
- * Pdfjs's worker script url. Must be set if haven't been set elsewhere.
7
- */
8
- workerSrc?: string | undefined;
9
- /**
10
- * Array of pdf sources to display.
11
- */
12
- sources: PdfSource[];
13
- /**
14
- * Type of zoom used. Defaults to Auto.
15
- */
16
- zoomType?: ZoomType | undefined;
17
- /**
18
- * Display zoom percentage if using custom zoom, defaults to 1 (100%).
19
- */
20
- zoom?: number | undefined;
21
- /**
22
- * Hides the selectable text layer.
23
- */
24
- hideText?: boolean | undefined;
25
- /**
26
- * Hides page number display.
27
- */
28
- hideNumber?: boolean | undefined;
29
- /**
30
- * Experimental flag to enable pinch zoom gesture.
31
- */
32
- enablePinchZoom?: boolean | undefined;
33
- }>, {
34
- /**
35
- * Try to increase zoom to the next level, up to 200%.
36
- */
37
- zoomIn: typeof zoomIn;
38
- /**
39
- * Try to decrease zoom to the next level, down to 25%.
40
- */
41
- zoomOut: typeof zoomOut;
42
- }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
43
- "update:zoom": (zoom: number) => void;
44
- "update:zoomType": (zoomType: ZoomType) => void;
45
- }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
46
- /**
47
- * Pdfjs's worker script url. Must be set if haven't been set elsewhere.
48
- */
49
- workerSrc?: string | undefined;
50
- /**
51
- * Array of pdf sources to display.
52
- */
53
- sources: PdfSource[];
54
- /**
55
- * Type of zoom used. Defaults to Auto.
56
- */
57
- zoomType?: ZoomType | undefined;
58
- /**
59
- * Display zoom percentage if using custom zoom, defaults to 1 (100%).
60
- */
61
- zoom?: number | undefined;
62
- /**
63
- * Hides the selectable text layer.
64
- */
65
- hideText?: boolean | undefined;
66
- /**
67
- * Hides page number display.
68
- */
69
- hideNumber?: boolean | undefined;
70
- /**
71
- * Experimental flag to enable pinch zoom gesture.
72
- */
73
- enablePinchZoom?: boolean | undefined;
74
- }>>> & {
75
- "onUpdate:zoom"?: ((zoom: number) => any) | undefined;
76
- "onUpdate:zoomType"?: ((zoomType: ZoomType) => any) | undefined;
77
- }, {}>, {
78
- loading?(_: {
79
- source: PdfSource;
80
- loading: boolean;
81
- progress: number;
82
- }): any;
83
- page?(_: {
84
- source: PdfSource;
85
- doc: import("pdfjs-dist/types/src/display/api").PDFDocumentProxy | undefined;
86
- page: import("pdfjs-dist/types/src/display/api").PDFPageProxy;
87
- displaySize: import("pdfjs-dist/types/src/display/display_utils").PageViewport;
88
- }): any;
89
- default?(_: {}): any;
90
- }>;
91
- export default _default;
92
- type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
93
- type __VLS_TypePropsToRuntimeProps<T> = {
94
- [K in keyof T]-?: {} extends Pick<T, K> ? {
95
- type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
96
- } : {
97
- type: import('vue').PropType<T[K]>;
98
- required: true;
99
- };
100
- };
101
- type __VLS_WithTemplateSlots<T, S> = T & {
102
- new (): {
103
- $slots: S;
104
- };
105
- };
package/types/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export { default as PdfHost } from './PdfHost.vue';
2
- export { ZoomType } from './types';
3
- export type { PdfSource } from './types';
package/types/types.d.ts DELETED
@@ -1,27 +0,0 @@
1
- import { PDFDataRangeTransport } from 'pdfjs-dist';
2
- import type { TypedArray, DocumentInitParameters } from 'pdfjs-dist/types/src/display/api';
3
- /**
4
- * Types of zooms supported in pdf display.
5
- */
6
- export declare enum ZoomType {
7
- /**
8
- * Auto zoom to fit width of host until a certain limit.
9
- */
10
- Auto = 0,
11
- /**
12
- * Fits width of host with no limit.
13
- */
14
- WidthFit = 1,
15
- /**
16
- * Fits whole page in the host.
17
- */
18
- PageFit = 2,
19
- /**
20
- * Custom zoom value percentage.
21
- */
22
- Custom = 3
23
- }
24
- /**
25
- * Source of pdf to display in the host.
26
- */
27
- export type PdfSource = string | URL | PDFDataRangeTransport | TypedArray | DocumentInitParameters;