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