pdfjs-vue3 0.2.0 → 0.2.1
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 +244 -177
- package/dist/pdfjs-vue3.umd.js +1 -1
- package/package.json +2 -4
package/dist/pdfjs-vue3.es.js
CHANGED
|
@@ -1,42 +1,44 @@
|
|
|
1
|
-
import { Fragment as e, computed as t, createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, defineComponent as o,
|
|
2
|
-
import { GlobalWorkerOptions as
|
|
1
|
+
import { Fragment as e, computed as t, createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, defineComponent as o, getCurrentInstance as s, getCurrentScope as c, hasInjectionContext as l, inject as u, nextTick as d, onBeforeUnmount as f, onMounted as p, openBlock as m, readonly as h, ref as g, renderList as _, renderSlot as v, shallowRef as y, toDisplayString as b, toValue as x, unref as S, watch as C, watchEffect as w, withCtx as T } from "vue";
|
|
2
|
+
import { GlobalWorkerOptions as E, RenderingCancelledException as D, TextLayer as O, getDocument as k } from "pdfjs-dist";
|
|
3
3
|
//#region src/types.ts
|
|
4
|
-
var
|
|
4
|
+
var A = /* @__PURE__ */ function(e) {
|
|
5
5
|
return e[e.Auto = 0] = "Auto", e[e.WidthFit = 1] = "WidthFit", e[e.PageFit = 2] = "PageFit", e[e.Custom = 3] = "Custom", e;
|
|
6
|
-
}({}),
|
|
6
|
+
}({}), j = /* @__PURE__ */ o({
|
|
7
7
|
__name: "PdfPageText",
|
|
8
8
|
props: {
|
|
9
9
|
viewport: {},
|
|
10
10
|
page: {}
|
|
11
11
|
},
|
|
12
12
|
setup(e) {
|
|
13
|
-
let t = e, n =
|
|
14
|
-
|
|
13
|
+
let t = e, n = g(), r;
|
|
14
|
+
C(() => [t.viewport, t.page], () => {
|
|
15
15
|
a();
|
|
16
16
|
});
|
|
17
17
|
async function a() {
|
|
18
18
|
let e = n.value, i = t.viewport;
|
|
19
19
|
if (!(!e || !i)) {
|
|
20
20
|
for (r &&= (r.cancel(), void 0); e.firstChild;) e.removeChild(e.firstChild);
|
|
21
|
-
r = new
|
|
21
|
+
r = new O({
|
|
22
22
|
textContentSource: t.page.streamTextContent(),
|
|
23
23
|
container: e,
|
|
24
24
|
viewport: i
|
|
25
|
-
}), await r.render();
|
|
25
|
+
}), await r.render().catch(() => {});
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
return
|
|
28
|
+
return p(() => {
|
|
29
29
|
a();
|
|
30
|
-
}), (
|
|
30
|
+
}), f(() => {
|
|
31
|
+
r &&= (r.cancel(), void 0);
|
|
32
|
+
}), (e, t) => (m(), i("div", {
|
|
31
33
|
ref_key: "rootEl",
|
|
32
34
|
ref: n,
|
|
33
35
|
class: "pdf-text-layer"
|
|
34
36
|
}, null, 512));
|
|
35
37
|
}
|
|
36
|
-
}),
|
|
38
|
+
}), M = { class: "pdf-page-layout" }, N = { class: "pdf-page-overlay" }, P = {
|
|
37
39
|
key: 0,
|
|
38
40
|
class: "pdf-page-number"
|
|
39
|
-
},
|
|
41
|
+
}, F = 1100, I = 96 / 72, L = /* @__PURE__ */ o({
|
|
40
42
|
__name: "PdfPage",
|
|
41
43
|
props: {
|
|
42
44
|
zoom: {},
|
|
@@ -45,77 +47,191 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
45
47
|
hideNumber: { type: Boolean },
|
|
46
48
|
viewport: {},
|
|
47
49
|
page: {},
|
|
48
|
-
|
|
50
|
+
devicePixelRatio: {}
|
|
49
51
|
},
|
|
50
52
|
emits: ["update:zoom"],
|
|
51
|
-
setup(e, {
|
|
52
|
-
let
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
let { width: e, height: t } = f.page.getViewport({ scale: k }), { width: n, height: r } = f.viewport, i = 0, a = 1;
|
|
59
|
-
switch (f.zoomType) {
|
|
60
|
-
case C.Auto: return i = Math.min(n, O) - 40, a = i / e, k * a;
|
|
61
|
-
case C.WidthFit: return i = n - 40, a = i / e, k * a;
|
|
62
|
-
case C.PageFit: return n > r ? (a = r / t, k * a) : (i = n - 40, a = i / e, k * a);
|
|
53
|
+
setup(e, { emit: o }) {
|
|
54
|
+
let s = e, c = o, l = g(), u = g(), d = g(!1), h, _ = t(() => {
|
|
55
|
+
let { width: e, height: t } = s.page.getViewport({ scale: I }), { width: n, height: r } = s.viewport, i = 0, a = 1;
|
|
56
|
+
switch (s.zoomType) {
|
|
57
|
+
case A.Auto: return i = Math.min(n, F) - 40, a = i / e, I * a;
|
|
58
|
+
case A.WidthFit: return i = n - 40, a = i / e, I * a;
|
|
59
|
+
case A.PageFit: return n > r ? (a = r / t, I * a) : (i = n - 40, a = i / e, I * a);
|
|
63
60
|
}
|
|
64
|
-
return
|
|
65
|
-
}),
|
|
66
|
-
|
|
67
|
-
let t = e /
|
|
68
|
-
Math.abs(t -
|
|
61
|
+
return I * s.zoom;
|
|
62
|
+
}), y = t(() => _.value * (s.devicePixelRatio || 1)), x = t(() => s.page.getViewport({ scale: _.value })), S = t(() => s.page.getViewport({ scale: y.value }));
|
|
63
|
+
C(_, (e) => {
|
|
64
|
+
let t = e / I;
|
|
65
|
+
Math.abs(t - s.zoom) > .05 && c("update:zoom", t);
|
|
69
66
|
}, { immediate: !0 });
|
|
70
|
-
let
|
|
71
|
-
function
|
|
72
|
-
if (!
|
|
73
|
-
let e =
|
|
67
|
+
let w;
|
|
68
|
+
function T() {
|
|
69
|
+
if (!s.page || !l.value) return;
|
|
70
|
+
let e = s.page, t = x.value, n = S.value, r = l.value;
|
|
74
71
|
r.width = Math.ceil(n.width), r.height = Math.ceil(n.height), r.style.width = Math.floor(t.width) + "px", r.style.height = Math.floor(t.height) + "px";
|
|
75
|
-
let i =
|
|
72
|
+
let i = u.value;
|
|
76
73
|
i && (i.style.width = r.style.width, i.style.height = r.style.height);
|
|
77
74
|
let a = r.getContext("2d");
|
|
78
|
-
if (!(!a || !
|
|
79
|
-
if (
|
|
80
|
-
|
|
75
|
+
if (!(!a || !d.value)) {
|
|
76
|
+
if (w) {
|
|
77
|
+
w.cancel();
|
|
81
78
|
return;
|
|
82
79
|
}
|
|
83
|
-
|
|
80
|
+
console.debug(`rendering page ${e.pageNumber} with zoom ${s.zoom} (scale ${_.value})`), w = e.render({
|
|
84
81
|
canvas: r,
|
|
85
82
|
canvasContext: a,
|
|
86
|
-
viewport:
|
|
87
|
-
}),
|
|
88
|
-
|
|
83
|
+
viewport: S.value
|
|
84
|
+
}), w.promise.then(() => w = void 0).catch((e) => {
|
|
85
|
+
w = void 0, e instanceof D && T();
|
|
89
86
|
});
|
|
90
87
|
}
|
|
91
88
|
}
|
|
92
|
-
return
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
return C(() => [
|
|
90
|
+
s.page,
|
|
91
|
+
y.value,
|
|
92
|
+
d.value
|
|
96
93
|
], () => {
|
|
97
|
-
|
|
98
|
-
}, { immediate: !0 }),
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
94
|
+
T();
|
|
95
|
+
}, { immediate: !0 }), p(() => {
|
|
96
|
+
let e = u.value;
|
|
97
|
+
e && (h = new IntersectionObserver(([e]) => {
|
|
98
|
+
d.value = e.isIntersecting;
|
|
99
|
+
}, { rootMargin: "200px 0px" }), h.observe(e)), T();
|
|
100
|
+
}), f(() => {
|
|
101
|
+
h?.disconnect(), h = void 0, w &&= (w.cancel(), void 0);
|
|
102
|
+
}), (t, o) => (m(), i("div", {
|
|
103
103
|
ref_key: "rootEl",
|
|
104
|
-
ref:
|
|
104
|
+
ref: u,
|
|
105
105
|
class: "pdf-page"
|
|
106
|
-
}, [a("div",
|
|
106
|
+
}, [a("div", M, [a("canvas", {
|
|
107
107
|
ref_key: "canvas",
|
|
108
|
-
ref:
|
|
109
|
-
}, null, 512), a("div",
|
|
108
|
+
ref: l
|
|
109
|
+
}, null, 512), a("div", N, [e.hideText ? r("", !0) : (m(), n(j, {
|
|
110
110
|
key: 0,
|
|
111
|
-
viewport:
|
|
111
|
+
viewport: x.value,
|
|
112
112
|
page: e.page
|
|
113
|
-
}, null, 8, ["viewport", "page"])),
|
|
113
|
+
}, null, 8, ["viewport", "page"])), v(t.$slots, "default", { displaySize: x.value })])]), e.hideNumber ? r("", !0) : (m(), i("div", P, b(e.page.pageNumber), 1))], 512));
|
|
114
|
+
}
|
|
115
|
+
}), R = /* @__PURE__ */ new WeakMap(), z = (...e) => {
|
|
116
|
+
let t = e[0], n = s()?.proxy ?? c();
|
|
117
|
+
if (n == null && !l()) throw Error("injectLocal must be called in setup");
|
|
118
|
+
return n && R.has(n) && t in R.get(n) ? R.get(n)[t] : u(...e);
|
|
119
|
+
}, B = typeof window < "u" && typeof document < "u";
|
|
120
|
+
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
|
|
121
|
+
var V = Object.prototype.toString, H = (e) => V.call(e) === "[object Object]", U = () => {};
|
|
122
|
+
function W(e, t) {
|
|
123
|
+
function n(...n) {
|
|
124
|
+
return new Promise((r, i) => {
|
|
125
|
+
Promise.resolve(e(() => t.apply(this, n), {
|
|
126
|
+
fn: t,
|
|
127
|
+
thisArg: this,
|
|
128
|
+
args: n
|
|
129
|
+
})).then(r).catch(i);
|
|
130
|
+
});
|
|
114
131
|
}
|
|
115
|
-
|
|
132
|
+
return n;
|
|
133
|
+
}
|
|
134
|
+
function G(e, t = {}) {
|
|
135
|
+
let n, r, i = U, a = (e) => {
|
|
136
|
+
clearTimeout(e), i(), i = U;
|
|
137
|
+
}, o;
|
|
138
|
+
return (s) => {
|
|
139
|
+
let c = x(e), l = x(t.maxWait);
|
|
140
|
+
return n && a(n), c <= 0 || l !== void 0 && l <= 0 ? (r &&= (a(r), void 0), Promise.resolve(s())) : new Promise((e, u) => {
|
|
141
|
+
i = t.rejectOnCancel ? u : e, o = s, l && !r && (r = setTimeout(() => {
|
|
142
|
+
n && a(n), r = void 0, e(o());
|
|
143
|
+
}, l)), n = setTimeout(() => {
|
|
144
|
+
r && a(r), r = void 0, e(s());
|
|
145
|
+
}, c);
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function K(e) {
|
|
150
|
+
return e.endsWith("rem") ? Number.parseFloat(e) * 16 : Number.parseFloat(e);
|
|
151
|
+
}
|
|
152
|
+
function q(e) {
|
|
153
|
+
return Array.isArray(e) ? e : [e];
|
|
154
|
+
}
|
|
155
|
+
function J(e, t = 200, n = {}) {
|
|
156
|
+
return W(G(t, n), e);
|
|
157
|
+
}
|
|
158
|
+
function Y(e, t, n) {
|
|
159
|
+
return C(e, t, {
|
|
160
|
+
...n,
|
|
161
|
+
immediate: !0
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region node_modules/@vueuse/core/dist/index.js
|
|
166
|
+
var X = B ? window : void 0;
|
|
167
|
+
B && window.document, B && window.navigator, B && window.location;
|
|
168
|
+
function Z(e) {
|
|
169
|
+
let t = x(e);
|
|
170
|
+
return t?.$el ?? t;
|
|
171
|
+
}
|
|
172
|
+
function Q(...e) {
|
|
173
|
+
let n = (e, t, n, r) => (e.addEventListener(t, n, r), () => e.removeEventListener(t, n, r)), r = t(() => {
|
|
174
|
+
let t = q(x(e[0])).filter((e) => e != null);
|
|
175
|
+
return t.every((e) => typeof e != "string") ? t : void 0;
|
|
176
|
+
});
|
|
177
|
+
return Y(() => [
|
|
178
|
+
r.value?.map((e) => Z(e)) ?? [X].filter((e) => e != null),
|
|
179
|
+
q(x(r.value ? e[1] : e[0])),
|
|
180
|
+
q(S(r.value ? e[2] : e[1])),
|
|
181
|
+
x(r.value ? e[3] : e[2])
|
|
182
|
+
], ([e, t, r, i], a, o) => {
|
|
183
|
+
if (!e?.length || !t?.length || !r?.length) return;
|
|
184
|
+
let s = H(i) ? { ...i } : i, c = e.flatMap((e) => t.flatMap((t) => r.map((r) => n(e, t, r, s))));
|
|
185
|
+
o(() => {
|
|
186
|
+
c.forEach((e) => e());
|
|
187
|
+
});
|
|
188
|
+
}, { flush: "post" });
|
|
189
|
+
}
|
|
190
|
+
function $() {
|
|
191
|
+
let e = y(!1), t = s();
|
|
192
|
+
return t && p(() => {
|
|
193
|
+
e.value = !0;
|
|
194
|
+
}, t), e;
|
|
195
|
+
}
|
|
196
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
197
|
+
function ee(e) {
|
|
198
|
+
let n = $();
|
|
199
|
+
return t(() => (n.value, !!e()));
|
|
200
|
+
}
|
|
201
|
+
var te = Symbol("vueuse-ssr-width");
|
|
202
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
203
|
+
function ne() {
|
|
204
|
+
let e = l() ? z(te, null) : null;
|
|
205
|
+
return typeof e == "number" ? e : void 0;
|
|
206
|
+
}
|
|
207
|
+
function re(e, n = {}) {
|
|
208
|
+
let { window: r = X, ssrWidth: i = /* @__PURE__ */ ne() } = n, a = /* @__PURE__ */ ee(() => r && "matchMedia" in r && typeof r.matchMedia == "function"), o = y(typeof i == "number"), s = y(), c = y(!1);
|
|
209
|
+
return w(() => {
|
|
210
|
+
if (o.value) {
|
|
211
|
+
o.value = !a.value, c.value = x(e).split(",").some((e) => {
|
|
212
|
+
let t = e.includes("not all"), n = e.match(/\(\s*min-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/), r = e.match(/\(\s*max-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/), a = !!(n || r);
|
|
213
|
+
return n && a && (a = i >= K(n[1])), r && a && (a = i <= K(r[1])), t ? !a : a;
|
|
214
|
+
});
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
a.value && (s.value = r.matchMedia(x(e)), c.value = s.value.matches);
|
|
218
|
+
}), Q(s, "change", (e) => {
|
|
219
|
+
c.value = e.matches;
|
|
220
|
+
}, { passive: !0 }), t(() => c.value);
|
|
221
|
+
}
|
|
222
|
+
function ie(e = {}) {
|
|
223
|
+
let { window: t = X } = e, n = y(1), r = re(() => `(resolution: ${n.value}dppx)`, e), i = U;
|
|
224
|
+
return t && (i = Y(r, () => n.value = t.devicePixelRatio)), {
|
|
225
|
+
pixelRatio: h(n),
|
|
226
|
+
stop: i
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/PdfDocument.vue?vue&type=script&setup=true&lang.ts
|
|
231
|
+
var ae = {
|
|
116
232
|
key: 0,
|
|
117
233
|
class: "pdf-progress"
|
|
118
|
-
},
|
|
234
|
+
}, oe = /* @__PURE__ */ o({
|
|
119
235
|
__name: "PdfDocument",
|
|
120
236
|
props: {
|
|
121
237
|
hideText: { type: Boolean },
|
|
@@ -127,63 +243,49 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
127
243
|
},
|
|
128
244
|
emits: ["error", "update:zoom"],
|
|
129
245
|
setup(t, { emit: a }) {
|
|
130
|
-
let o = t, s = a,
|
|
131
|
-
function
|
|
132
|
-
|
|
246
|
+
let o = t, s = a, { pixelRatio: c } = ie(), l = y(), u = y([]), d = g(), p = g(!1), h = g(0), x;
|
|
247
|
+
async function w() {
|
|
248
|
+
x &&= (await x.destroy(), void 0), u.value.forEach((e) => e.cleanup()), u.value = [];
|
|
249
|
+
let e = l.value;
|
|
250
|
+
e && (e.destroy(), l.value = void 0);
|
|
133
251
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return v(() => o.src, (e) => {
|
|
140
|
-
if (D(), !e) return;
|
|
141
|
-
let t = S(e);
|
|
142
|
-
w.value = !0, t.onProgress = (e) => {
|
|
143
|
-
e.total && (T.value = e.loaded / e.total);
|
|
144
|
-
}, t.promise.then((e) => {
|
|
145
|
-
g.value = e;
|
|
252
|
+
return C(() => o.src, async (e) => {
|
|
253
|
+
await w(), e && (x = k(e), p.value = !0, x.onProgress = (e) => {
|
|
254
|
+
e.total && (h.value = e.loaded / e.total);
|
|
255
|
+
}, x.promise.then((e) => {
|
|
256
|
+
l.value = e;
|
|
146
257
|
let t = [];
|
|
147
258
|
for (let n = 1; n <= e.numPages; n++) t.push(e.getPage(n));
|
|
148
259
|
Promise.all(t).then((t) => {
|
|
149
|
-
e ===
|
|
260
|
+
e === l.value && (u.value = t);
|
|
150
261
|
});
|
|
151
262
|
}).catch((e) => {
|
|
152
263
|
s("error", e);
|
|
153
264
|
}).finally(() => {
|
|
154
|
-
|
|
155
|
-
});
|
|
156
|
-
}, { immediate: !0 }),
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
let t = C.find((t) => t?.rootEl === e.target);
|
|
160
|
-
t && (t.inViewport = e.isIntersecting);
|
|
161
|
-
});
|
|
162
|
-
}, { rootMargin: "0px" });
|
|
163
|
-
}), c(() => {
|
|
164
|
-
D(), b.value?.disconnect();
|
|
165
|
-
}), (a, c) => (u(), i("div", {
|
|
265
|
+
p.value = !1;
|
|
266
|
+
}));
|
|
267
|
+
}, { immediate: !0 }), f(() => {
|
|
268
|
+
w();
|
|
269
|
+
}), (a, f) => (m(), i("div", {
|
|
166
270
|
ref_key: "rootEl",
|
|
167
|
-
ref:
|
|
168
|
-
}, [
|
|
271
|
+
ref: d
|
|
272
|
+
}, [v(a.$slots, "loading", {
|
|
169
273
|
src: o.src,
|
|
170
|
-
loading:
|
|
171
|
-
progress:
|
|
172
|
-
}, () => [
|
|
173
|
-
ref_for: !0,
|
|
174
|
-
ref: E,
|
|
274
|
+
loading: p.value,
|
|
275
|
+
progress: h.value
|
|
276
|
+
}, () => [p.value ? (m(), i("p", ae, "loading " + b(Math.ceil(100 * h.value)) + "%", 1)) : r("", !0)]), (m(!0), i(e, null, _(u.value, (e) => (m(), n(L, {
|
|
175
277
|
key: e.pageNumber,
|
|
176
278
|
page: e,
|
|
177
279
|
"hide-number": t.hideNumber,
|
|
178
280
|
"hide-text": t.hideText,
|
|
179
281
|
"zoom-type": t.zoomType,
|
|
180
282
|
zoom: t.zoom,
|
|
181
|
-
"onUpdate:zoom":
|
|
182
|
-
|
|
183
|
-
|
|
283
|
+
"onUpdate:zoom": f[0] ||= (e) => s("update:zoom", e),
|
|
284
|
+
viewport: t.viewport,
|
|
285
|
+
"device-pixel-ratio": S(c)
|
|
184
286
|
}, {
|
|
185
|
-
default:
|
|
186
|
-
doc:
|
|
287
|
+
default: T(({ displaySize: t }) => [v(a.$slots, "default", {
|
|
288
|
+
doc: l.value,
|
|
187
289
|
page: e,
|
|
188
290
|
displaySize: t
|
|
189
291
|
})]),
|
|
@@ -194,46 +296,11 @@ var C = /* @__PURE__ */ function(e) {
|
|
|
194
296
|
"hide-text",
|
|
195
297
|
"zoom-type",
|
|
196
298
|
"zoom",
|
|
197
|
-
"
|
|
198
|
-
"
|
|
299
|
+
"viewport",
|
|
300
|
+
"device-pixel-ratio"
|
|
199
301
|
]))), 128))], 512));
|
|
200
302
|
}
|
|
201
|
-
})
|
|
202
|
-
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
|
|
203
|
-
var N = () => {};
|
|
204
|
-
function P(e, t) {
|
|
205
|
-
function n(...n) {
|
|
206
|
-
return new Promise((r, i) => {
|
|
207
|
-
Promise.resolve(e(() => t.apply(this, n), {
|
|
208
|
-
fn: t,
|
|
209
|
-
thisArg: this,
|
|
210
|
-
args: n
|
|
211
|
-
})).then(r).catch(i);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
return n;
|
|
215
|
-
}
|
|
216
|
-
function F(e, t = {}) {
|
|
217
|
-
let n, r, i = N, a = (e) => {
|
|
218
|
-
clearTimeout(e), i(), i = N;
|
|
219
|
-
}, o;
|
|
220
|
-
return (s) => {
|
|
221
|
-
let c = g(e), l = g(t.maxWait);
|
|
222
|
-
return n && a(n), c <= 0 || l !== void 0 && l <= 0 ? (r &&= (a(r), void 0), Promise.resolve(s())) : new Promise((e, u) => {
|
|
223
|
-
i = t.rejectOnCancel ? u : e, o = s, l && !r && (r = setTimeout(() => {
|
|
224
|
-
n && a(n), r = void 0, e(o());
|
|
225
|
-
}, l)), n = setTimeout(() => {
|
|
226
|
-
r && a(r), r = void 0, e(s());
|
|
227
|
-
}, c);
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
function I(e, t = 200, n = {}) {
|
|
232
|
-
return P(F(t, n), e);
|
|
233
|
-
}
|
|
234
|
-
//#endregion
|
|
235
|
-
//#region src/PdfHost.vue
|
|
236
|
-
var L = /* @__PURE__ */ o({
|
|
303
|
+
}), se = /* @__PURE__ */ o({
|
|
237
304
|
__name: "PdfHost",
|
|
238
305
|
props: {
|
|
239
306
|
workerSrc: {},
|
|
@@ -245,75 +312,75 @@ var L = /* @__PURE__ */ o({
|
|
|
245
312
|
},
|
|
246
313
|
emits: ["update:zoom", "update:zoomType"],
|
|
247
314
|
setup(t, { expose: r, emit: a }) {
|
|
248
|
-
let o = t,
|
|
315
|
+
let o = t, s = a, c = g();
|
|
249
316
|
r({
|
|
250
|
-
zoomIn:
|
|
251
|
-
zoomOut:
|
|
252
|
-
}),
|
|
253
|
-
e && (
|
|
317
|
+
zoomIn: x,
|
|
318
|
+
zoomOut: w
|
|
319
|
+
}), C(() => o.workerSrc, (e) => {
|
|
320
|
+
e && (E.workerSrc = e);
|
|
254
321
|
}, { immediate: !0 });
|
|
255
|
-
function
|
|
256
|
-
e.ctrlKey && (e.preventDefault(), e.deltaY < 0 ?
|
|
322
|
+
function l(e) {
|
|
323
|
+
e.ctrlKey && (e.preventDefault(), e.deltaY < 0 ? x() : w());
|
|
257
324
|
}
|
|
258
|
-
function
|
|
259
|
-
e.ctrlKey && (e.key === "0" || e.which == 48) &&
|
|
325
|
+
function u(e) {
|
|
326
|
+
e.ctrlKey && (e.key === "0" || e.which == 48) && s("update:zoomType", A.Auto);
|
|
260
327
|
}
|
|
261
|
-
let
|
|
328
|
+
let h = g({
|
|
262
329
|
width: 0,
|
|
263
330
|
height: 0
|
|
264
|
-
}),
|
|
265
|
-
let e =
|
|
266
|
-
e && (
|
|
331
|
+
}), y = J(() => {
|
|
332
|
+
let e = c.value;
|
|
333
|
+
e && (h.value = {
|
|
267
334
|
width: e.offsetWidth,
|
|
268
335
|
height: e.offsetHeight
|
|
269
336
|
});
|
|
270
337
|
}, 100);
|
|
271
|
-
function
|
|
338
|
+
function b(e) {
|
|
272
339
|
let t = e % .25;
|
|
273
340
|
return Number((e - t).toFixed(2));
|
|
274
341
|
}
|
|
275
|
-
function
|
|
276
|
-
let e =
|
|
277
|
-
|
|
342
|
+
function x() {
|
|
343
|
+
let e = b((o.zoom || 1) + .25);
|
|
344
|
+
s("update:zoom", Math.min(e, 2)), s("update:zoomType", A.Custom);
|
|
278
345
|
}
|
|
279
|
-
function
|
|
280
|
-
let e =
|
|
281
|
-
|
|
346
|
+
function w() {
|
|
347
|
+
let e = b((o.zoom || 1) - .25);
|
|
348
|
+
s("update:zoom", Math.max(e, .25)), s("update:zoomType", A.Custom);
|
|
282
349
|
}
|
|
283
|
-
return
|
|
284
|
-
let n =
|
|
350
|
+
return C(() => o.zoom, (e, t) => {
|
|
351
|
+
let n = c.value;
|
|
285
352
|
if (n && e && t) {
|
|
286
353
|
let r = n.scrollTop, i = n.scrollLeft, a = e / t;
|
|
287
|
-
|
|
354
|
+
d(() => {
|
|
288
355
|
n.scrollTop = r * a, n.scrollLeft = i * a;
|
|
289
356
|
});
|
|
290
357
|
}
|
|
291
|
-
}),
|
|
292
|
-
window.addEventListener("resize",
|
|
293
|
-
}),
|
|
294
|
-
window.removeEventListener("resize",
|
|
295
|
-
}), (r, a) => (
|
|
358
|
+
}), p(() => {
|
|
359
|
+
window.addEventListener("resize", y), y();
|
|
360
|
+
}), f(() => {
|
|
361
|
+
window.removeEventListener("resize", y);
|
|
362
|
+
}), (r, a) => (m(), i("div", {
|
|
296
363
|
ref_key: "rootEl",
|
|
297
|
-
ref:
|
|
298
|
-
onWheel:
|
|
299
|
-
onKeydown:
|
|
364
|
+
ref: c,
|
|
365
|
+
onWheel: l,
|
|
366
|
+
onKeydown: u,
|
|
300
367
|
tabindex: "0",
|
|
301
368
|
class: "pdf-host"
|
|
302
|
-
}, [(
|
|
303
|
-
viewport:
|
|
369
|
+
}, [(m(!0), i(e, null, _(t.sources, (e) => (m(), n(oe, {
|
|
370
|
+
viewport: h.value,
|
|
304
371
|
src: e,
|
|
305
372
|
"hide-number": !!t.hideNumber,
|
|
306
373
|
"hide-text": !!t.hideText,
|
|
307
|
-
"zoom-type": t.zoomType ||
|
|
374
|
+
"zoom-type": t.zoomType || S(A).Auto,
|
|
308
375
|
zoom: t.zoom || 1,
|
|
309
|
-
"onUpdate:zoom": a[0] ||= (e) =>
|
|
376
|
+
"onUpdate:zoom": a[0] ||= (e) => s("update:zoom", e)
|
|
310
377
|
}, {
|
|
311
|
-
loading:
|
|
378
|
+
loading: T(({ loading: t, progress: n }) => [v(r.$slots, "loading", {
|
|
312
379
|
source: e,
|
|
313
380
|
loading: t,
|
|
314
381
|
progress: n
|
|
315
382
|
})]),
|
|
316
|
-
default:
|
|
383
|
+
default: T(({ doc: t, page: n, displaySize: i }) => [v(r.$slots, "page", {
|
|
317
384
|
source: e,
|
|
318
385
|
doc: t,
|
|
319
386
|
page: n,
|
|
@@ -327,8 +394,8 @@ var L = /* @__PURE__ */ o({
|
|
|
327
394
|
"hide-text",
|
|
328
395
|
"zoom-type",
|
|
329
396
|
"zoom"
|
|
330
|
-
]))), 256)),
|
|
397
|
+
]))), 256)), v(r.$slots, "default")], 544));
|
|
331
398
|
}
|
|
332
399
|
});
|
|
333
400
|
//#endregion
|
|
334
|
-
export {
|
|
401
|
+
export { se as PdfHost, A as ZoomType };
|
package/dist/pdfjs-vue3.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,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):(e=typeof globalThis<`u`?globalThis:e||self,t(e.pdfjsVue3={},e.Vue,e.pdfjsLib))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=function(e){return e[e.Auto=0]=`Auto`,e[e.WidthFit=1]=`WidthFit`,e[e.PageFit=2]=`PageFit`,e[e.Custom=3]=`Custom`,e}({}),i=(0,t.defineComponent)({__name:`PdfPageText`,props:{viewport:{},page:{}},setup(e){let r=e,i=(0,t.ref)(),a;(0,t.watch)(()=>[r.viewport,r.page],()=>{o()});async function o(){let e=i.value,t=r.viewport;if(!(!e||!t)){for(a&&=(a.cancel(),void 0);e.firstChild;)e.removeChild(e.firstChild);a=new n.TextLayer({textContentSource:r.page.streamTextContent(),container:e,viewport:t}),await a.render()}}return(0,t.onMounted)(()=>{o()}),(e,n)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`rootEl`,ref:i,class:`pdf-text-layer`},null,512))}}),a={class:`pdf-page-layout`},o={class:`pdf-page-overlay`},s={key:0,class:`pdf-page-number`},c=1100,l=96/72,u=(0,t.defineComponent)({__name:`PdfPage`,props:{zoom:{},zoomType:{},hideText:{type:Boolean},hideNumber:{type:Boolean},viewport:{},page:{},observer:{}},emits:[`update:zoom`],setup(e,{expose:n,emit:u}){let d=e,f=u,p=(0,t.ref)(),m=(0,t.ref)(),h=(0,t.ref)(!1);n({rootEl:m,inViewport:h});let g=(0,t.computed)(()=>{let{width:e,height:t}=d.page.getViewport({scale:l}),{width:n,height:i}=d.viewport,a=0,o=1;switch(d.zoomType){case r.Auto:return a=Math.min(n,c)-40,o=a/e,l*o;case r.WidthFit:return a=n-40,o=a/e,l*o;case r.PageFit:return n>i?(o=i/t,l*o):(a=n-40,o=a/e,l*o)}return l*d.zoom}),_=(0,t.computed)(()=>g.value*(window?.devicePixelRatio||1)),v=(0,t.computed)(()=>d.page.getViewport({scale:g.value})),y=(0,t.computed)(()=>d.page.getViewport({scale:_.value}));(0,t.watch)(g,e=>{let t=e/l;Math.abs(t-d.zoom)>.05&&f(`update:zoom`,t)},{immediate:!0});let b;function x(){if(!d.page||!p.value)return;let e=d.page,t=v.value,n=y.value,r=p.value;r.width=Math.ceil(n.width),r.height=Math.ceil(n.height),r.style.width=Math.floor(t.width)+`px`,r.style.height=Math.floor(t.height)+`px`;let i=m.value;i&&(i.style.width=r.style.width,i.style.height=r.style.height);let a=r.getContext(`2d`);if(!(!a||!h.value)){if(b){b.cancel();return}b=e.render({canvas:r,canvasContext:a,viewport:y.value}),b.promise.then(()=>b=void 0).catch(()=>{b=void 0,x()})}}return(0,t.watch)(()=>[d.page,_.value,h.value],()=>{x()},{immediate:!0}),(0,t.onMounted)(()=>{x(),m.value&&d.observer?.observe(m.value)}),(0,t.onBeforeUnmount)(()=>{m.value&&d.observer?.unobserve(m.value)}),(n,r)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`rootEl`,ref:m,class:`pdf-page`},[(0,t.createElementVNode)(`div`,a,[(0,t.createElementVNode)(`canvas`,{ref_key:`canvas`,ref:p},null,512),(0,t.createElementVNode)(`div`,o,[e.hideText?(0,t.createCommentVNode)(``,!0):((0,t.openBlock)(),(0,t.createBlock)(i,{key:0,viewport:y.value,page:e.page},null,8,[`viewport`,`page`])),(0,t.renderSlot)(n.$slots,`default`,{displaySize:y.value})])]),e.hideNumber?(0,t.createCommentVNode)(``,!0):((0,t.openBlock)(),(0,t.createElementBlock)(`div`,s,(0,t.toDisplayString)(e.page.pageNumber),1))],512))}}),d={key:0,class:`pdf-progress`},f=(0,t.defineComponent)({__name:`PdfDocument`,props:{hideText:{type:Boolean},hideNumber:{type:Boolean},zoomType:{},zoom:{},viewport:{},src:{}},emits:[`error`,`update:zoom`],setup(e,{emit:r}){let i=e,a=r,o=(0,t.shallowRef)(),s=(0,t.shallowRef)([]),c=(0,t.shallowRef)(),l=(0,t.ref)(),f=[],p=(0,t.ref)(!1),m=(0,t.ref)(0);function h(e){e&&(f.push(e),f.length==1&&(e.inViewport=!0))}function g(){s.value.forEach(e=>e.cleanup()),s.value=[];let e=o.value;e&&(e.destroy(),o.value=void 0),f=[]}return(0,t.watch)(()=>i.src,e=>{if(g(),!e)return;let t=(0,n.getDocument)(e);p.value=!0,t.onProgress=e=>{e.total&&(m.value=e.loaded/e.total)},t.promise.then(e=>{o.value=e;let t=[];for(let n=1;n<=e.numPages;n++)t.push(e.getPage(n));Promise.all(t).then(t=>{e===o.value&&(s.value=t)})}).catch(e=>{a(`error`,e)}).finally(()=>{p.value=!1})},{immediate:!0}),(0,t.onMounted)(()=>{c.value=new IntersectionObserver(e=>{e.forEach(e=>{let t=f.find(t=>t?.rootEl===e.target);t&&(t.inViewport=e.isIntersecting)})},{rootMargin:`0px`})}),(0,t.onBeforeUnmount)(()=>{g(),c.value?.disconnect()}),(n,r)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`rootEl`,ref:l},[(0,t.renderSlot)(n.$slots,`loading`,{src:i.src,loading:p.value,progress:m.value},()=>[p.value?((0,t.openBlock)(),(0,t.createElementBlock)(`p`,d,`loading `+(0,t.toDisplayString)(Math.ceil(100*m.value))+`%`,1)):(0,t.createCommentVNode)(``,!0)]),((0,t.openBlock)(!0),(0,t.createElementBlock)(t.Fragment,null,(0,t.renderList)(s.value,i=>((0,t.openBlock)(),(0,t.createBlock)(u,{ref_for:!0,ref:h,key:i.pageNumber,page:i,"hide-number":e.hideNumber,"hide-text":e.hideText,"zoom-type":e.zoomType,zoom:e.zoom,"onUpdate:zoom":r[0]||=e=>a(`update:zoom`,e),observer:c.value,viewport:e.viewport},{default:(0,t.withCtx)(({displaySize:e})=>[(0,t.renderSlot)(n.$slots,`default`,{doc:o.value,page:i,displaySize:e})]),_:2},1032,[`page`,`hide-number`,`hide-text`,`zoom-type`,`zoom`,`observer`,`viewport`]))),128))],512))}});typeof WorkerGlobalScope<`u`&&globalThis instanceof WorkerGlobalScope;var p=()=>{};function m(e,t){function n(...n){return new Promise((r,i)=>{Promise.resolve(e(()=>t.apply(this,n),{fn:t,thisArg:this,args:n})).then(r).catch(i)})}return n}function h(e,n={}){let r,i,a=p,o=e=>{clearTimeout(e),a(),a=p},s;return c=>{let l=(0,t.toValue)(e),u=(0,t.toValue)(n.maxWait);return r&&o(r),l<=0||u!==void 0&&u<=0?(i&&=(o(i),void 0),Promise.resolve(c())):new Promise((e,t)=>{a=n.rejectOnCancel?t:e,s=c,u&&!i&&(i=setTimeout(()=>{r&&o(r),i=void 0,e(s())},u)),r=setTimeout(()=>{i&&o(i),i=void 0,e(c())},l)})}}function g(e,t=200,n={}){return m(h(t,n),e)}e.PdfHost=(0,t.defineComponent)({__name:`PdfHost`,props:{workerSrc:{},sources:{},zoomType:{},zoom:{},hideText:{type:Boolean},hideNumber:{type:Boolean}},emits:[`update:zoom`,`update:zoomType`],setup(e,{expose:i,emit:a}){let o=e,s=a,c=(0,t.ref)();i({zoomIn:h,zoomOut:_}),(0,t.watch)(()=>o.workerSrc,e=>{e&&(n.GlobalWorkerOptions.workerSrc=e)},{immediate:!0});function l(e){e.ctrlKey&&(e.preventDefault(),e.deltaY<0?h():_())}function u(e){e.ctrlKey&&(e.key===`0`||e.which==48)&&s(`update:zoomType`,r.Auto)}let d=(0,t.ref)({width:0,height:0}),p=g(()=>{let e=c.value;e&&(d.value={width:e.offsetWidth,height:e.offsetHeight})},100);function m(e){let t=e%.25;return Number((e-t).toFixed(2))}function h(){let e=m((o.zoom||1)+.25);s(`update:zoom`,Math.min(e,2)),s(`update:zoomType`,r.Custom)}function _(){let e=m((o.zoom||1)-.25);s(`update:zoom`,Math.max(e,.25)),s(`update:zoomType`,r.Custom)}return(0,t.watch)(()=>o.zoom,(e,n)=>{let r=c.value;if(r&&e&&n){let i=r.scrollTop,a=r.scrollLeft,o=e/n;(0,t.nextTick)(()=>{r.scrollTop=i*o,r.scrollLeft=a*o})}}),(0,t.onMounted)(()=>{window.addEventListener(`resize`,p),p()}),(0,t.onBeforeUnmount)(()=>{window.removeEventListener(`resize`,p)}),(n,i)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`rootEl`,ref:c,onWheel:l,onKeydown:u,tabindex:`0`,class:`pdf-host`},[((0,t.openBlock)(!0),(0,t.createElementBlock)(t.Fragment,null,(0,t.renderList)(e.sources,a=>((0,t.openBlock)(),(0,t.createBlock)(f,{viewport:d.value,src:a,"hide-number":!!e.hideNumber,"hide-text":!!e.hideText,"zoom-type":e.zoomType||(0,t.unref)(r).Auto,zoom:e.zoom||1,"onUpdate:zoom":i[0]||=e=>s(`update:zoom`,e)},{loading:(0,t.withCtx)(({loading:e,progress:r})=>[(0,t.renderSlot)(n.$slots,`loading`,{source:a,loading:e,progress:r})]),default:(0,t.withCtx)(({doc:e,page:r,displaySize:i})=>[(0,t.renderSlot)(n.$slots,`page`,{source:a,doc:e,page:r,displaySize:i})]),_:2},1032,[`viewport`,`src`,`hide-number`,`hide-text`,`zoom-type`,`zoom`]))),256)),(0,t.renderSlot)(n.$slots,`default`)],544))}}),e.ZoomType=r});
|
|
1
|
+
(function(e,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):(e=typeof globalThis<`u`?globalThis:e||self,t(e.pdfjsVue3={},e.Vue,e.pdfjsLib))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=function(e){return e[e.Auto=0]=`Auto`,e[e.WidthFit=1]=`WidthFit`,e[e.PageFit=2]=`PageFit`,e[e.Custom=3]=`Custom`,e}({}),i=(0,t.defineComponent)({__name:`PdfPageText`,props:{viewport:{},page:{}},setup(e){let r=e,i=(0,t.ref)(),a;(0,t.watch)(()=>[r.viewport,r.page],()=>{o()});async function o(){let e=i.value,t=r.viewport;if(!(!e||!t)){for(a&&=(a.cancel(),void 0);e.firstChild;)e.removeChild(e.firstChild);a=new n.TextLayer({textContentSource:r.page.streamTextContent(),container:e,viewport:t}),await a.render().catch(()=>{})}}return(0,t.onMounted)(()=>{o()}),(0,t.onBeforeUnmount)(()=>{a&&=(a.cancel(),void 0)}),(e,n)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`rootEl`,ref:i,class:`pdf-text-layer`},null,512))}}),a={class:`pdf-page-layout`},o={class:`pdf-page-overlay`},s={key:0,class:`pdf-page-number`},c=1100,l=96/72,u=(0,t.defineComponent)({__name:`PdfPage`,props:{zoom:{},zoomType:{},hideText:{type:Boolean},hideNumber:{type:Boolean},viewport:{},page:{},devicePixelRatio:{}},emits:[`update:zoom`],setup(e,{emit:u}){let d=e,f=u,p=(0,t.ref)(),m=(0,t.ref)(),h=(0,t.ref)(!1),g,_=(0,t.computed)(()=>{let{width:e,height:t}=d.page.getViewport({scale:l}),{width:n,height:i}=d.viewport,a=0,o=1;switch(d.zoomType){case r.Auto:return a=Math.min(n,c)-40,o=a/e,l*o;case r.WidthFit:return a=n-40,o=a/e,l*o;case r.PageFit:return n>i?(o=i/t,l*o):(a=n-40,o=a/e,l*o)}return l*d.zoom}),v=(0,t.computed)(()=>_.value*(d.devicePixelRatio||1)),y=(0,t.computed)(()=>d.page.getViewport({scale:_.value})),b=(0,t.computed)(()=>d.page.getViewport({scale:v.value}));(0,t.watch)(_,e=>{let t=e/l;Math.abs(t-d.zoom)>.05&&f(`update:zoom`,t)},{immediate:!0});let x;function S(){if(!d.page||!p.value)return;let e=d.page,t=y.value,r=b.value,i=p.value;i.width=Math.ceil(r.width),i.height=Math.ceil(r.height),i.style.width=Math.floor(t.width)+`px`,i.style.height=Math.floor(t.height)+`px`;let a=m.value;a&&(a.style.width=i.style.width,a.style.height=i.style.height);let o=i.getContext(`2d`);if(!(!o||!h.value)){if(x){x.cancel();return}console.debug(`rendering page ${e.pageNumber} with zoom ${d.zoom} (scale ${_.value})`),x=e.render({canvas:i,canvasContext:o,viewport:b.value}),x.promise.then(()=>x=void 0).catch(e=>{x=void 0,e instanceof n.RenderingCancelledException&&S()})}}return(0,t.watch)(()=>[d.page,v.value,h.value],()=>{S()},{immediate:!0}),(0,t.onMounted)(()=>{let e=m.value;e&&(g=new IntersectionObserver(([e])=>{h.value=e.isIntersecting},{rootMargin:`200px 0px`}),g.observe(e)),S()}),(0,t.onBeforeUnmount)(()=>{g?.disconnect(),g=void 0,x&&=(x.cancel(),void 0)}),(n,r)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`rootEl`,ref:m,class:`pdf-page`},[(0,t.createElementVNode)(`div`,a,[(0,t.createElementVNode)(`canvas`,{ref_key:`canvas`,ref:p},null,512),(0,t.createElementVNode)(`div`,o,[e.hideText?(0,t.createCommentVNode)(``,!0):((0,t.openBlock)(),(0,t.createBlock)(i,{key:0,viewport:y.value,page:e.page},null,8,[`viewport`,`page`])),(0,t.renderSlot)(n.$slots,`default`,{displaySize:y.value})])]),e.hideNumber?(0,t.createCommentVNode)(``,!0):((0,t.openBlock)(),(0,t.createElementBlock)(`div`,s,(0,t.toDisplayString)(e.page.pageNumber),1))],512))}}),d=new WeakMap,f=(...e)=>{let n=e[0],r=(0,t.getCurrentInstance)()?.proxy??(0,t.getCurrentScope)();if(r==null&&!(0,t.hasInjectionContext)())throw Error(`injectLocal must be called in setup`);return r&&d.has(r)&&n in d.get(r)?d.get(r)[n]:(0,t.inject)(...e)},p=typeof window<`u`&&typeof document<`u`;typeof WorkerGlobalScope<`u`&&globalThis instanceof WorkerGlobalScope;var m=Object.prototype.toString,h=e=>m.call(e)===`[object Object]`,g=()=>{};function _(e,t){function n(...n){return new Promise((r,i)=>{Promise.resolve(e(()=>t.apply(this,n),{fn:t,thisArg:this,args:n})).then(r).catch(i)})}return n}function v(e,n={}){let r,i,a=g,o=e=>{clearTimeout(e),a(),a=g},s;return c=>{let l=(0,t.toValue)(e),u=(0,t.toValue)(n.maxWait);return r&&o(r),l<=0||u!==void 0&&u<=0?(i&&=(o(i),void 0),Promise.resolve(c())):new Promise((e,t)=>{a=n.rejectOnCancel?t:e,s=c,u&&!i&&(i=setTimeout(()=>{r&&o(r),i=void 0,e(s())},u)),r=setTimeout(()=>{i&&o(i),i=void 0,e(c())},l)})}}function y(e){return e.endsWith(`rem`)?Number.parseFloat(e)*16:Number.parseFloat(e)}function b(e){return Array.isArray(e)?e:[e]}function x(e,t=200,n={}){return _(v(t,n),e)}function S(e,n,r){return(0,t.watch)(e,n,{...r,immediate:!0})}var C=p?window:void 0;p&&window.document,p&&window.navigator,p&&window.location;function w(e){let n=(0,t.toValue)(e);return n?.$el??n}function T(...e){let n=(e,t,n,r)=>(e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)),r=(0,t.computed)(()=>{let n=b((0,t.toValue)(e[0])).filter(e=>e!=null);return n.every(e=>typeof e!=`string`)?n:void 0});return S(()=>[r.value?.map(e=>w(e))??[C].filter(e=>e!=null),b((0,t.toValue)(r.value?e[1]:e[0])),b((0,t.unref)(r.value?e[2]:e[1])),(0,t.toValue)(r.value?e[3]:e[2])],([e,t,r,i],a,o)=>{if(!e?.length||!t?.length||!r?.length)return;let s=h(i)?{...i}:i,c=e.flatMap(e=>t.flatMap(t=>r.map(r=>n(e,t,r,s))));o(()=>{c.forEach(e=>e())})},{flush:`post`})}function E(){let e=(0,t.shallowRef)(!1),n=(0,t.getCurrentInstance)();return n&&(0,t.onMounted)(()=>{e.value=!0},n),e}function D(e){let n=E();return(0,t.computed)(()=>(n.value,!!e()))}var O=Symbol(`vueuse-ssr-width`);function k(){let e=(0,t.hasInjectionContext)()?f(O,null):null;return typeof e==`number`?e:void 0}function A(e,n={}){let{window:r=C,ssrWidth:i=k()}=n,a=D(()=>r&&`matchMedia`in r&&typeof r.matchMedia==`function`),o=(0,t.shallowRef)(typeof i==`number`),s=(0,t.shallowRef)(),c=(0,t.shallowRef)(!1);return(0,t.watchEffect)(()=>{if(o.value){o.value=!a.value,c.value=(0,t.toValue)(e).split(`,`).some(e=>{let t=e.includes(`not all`),n=e.match(/\(\s*min-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/),r=e.match(/\(\s*max-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/),a=!!(n||r);return n&&a&&(a=i>=y(n[1])),r&&a&&(a=i<=y(r[1])),t?!a:a});return}a.value&&(s.value=r.matchMedia((0,t.toValue)(e)),c.value=s.value.matches)}),T(s,`change`,e=>{c.value=e.matches},{passive:!0}),(0,t.computed)(()=>c.value)}function j(e={}){let{window:n=C}=e,r=(0,t.shallowRef)(1),i=A(()=>`(resolution: ${r.value}dppx)`,e),a=g;return n&&(a=S(i,()=>r.value=n.devicePixelRatio)),{pixelRatio:(0,t.readonly)(r),stop:a}}var M={key:0,class:`pdf-progress`},N=(0,t.defineComponent)({__name:`PdfDocument`,props:{hideText:{type:Boolean},hideNumber:{type:Boolean},zoomType:{},zoom:{},viewport:{},src:{}},emits:[`error`,`update:zoom`],setup(e,{emit:r}){let i=e,a=r,{pixelRatio:o}=j(),s=(0,t.shallowRef)(),c=(0,t.shallowRef)([]),l=(0,t.ref)(),d=(0,t.ref)(!1),f=(0,t.ref)(0),p;async function m(){p&&=(await p.destroy(),void 0),c.value.forEach(e=>e.cleanup()),c.value=[];let e=s.value;e&&(e.destroy(),s.value=void 0)}return(0,t.watch)(()=>i.src,async e=>{await m(),e&&(p=(0,n.getDocument)(e),d.value=!0,p.onProgress=e=>{e.total&&(f.value=e.loaded/e.total)},p.promise.then(e=>{s.value=e;let t=[];for(let n=1;n<=e.numPages;n++)t.push(e.getPage(n));Promise.all(t).then(t=>{e===s.value&&(c.value=t)})}).catch(e=>{a(`error`,e)}).finally(()=>{d.value=!1}))},{immediate:!0}),(0,t.onBeforeUnmount)(()=>{m()}),(n,r)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`rootEl`,ref:l},[(0,t.renderSlot)(n.$slots,`loading`,{src:i.src,loading:d.value,progress:f.value},()=>[d.value?((0,t.openBlock)(),(0,t.createElementBlock)(`p`,M,`loading `+(0,t.toDisplayString)(Math.ceil(100*f.value))+`%`,1)):(0,t.createCommentVNode)(``,!0)]),((0,t.openBlock)(!0),(0,t.createElementBlock)(t.Fragment,null,(0,t.renderList)(c.value,i=>((0,t.openBlock)(),(0,t.createBlock)(u,{key:i.pageNumber,page:i,"hide-number":e.hideNumber,"hide-text":e.hideText,"zoom-type":e.zoomType,zoom:e.zoom,"onUpdate:zoom":r[0]||=e=>a(`update:zoom`,e),viewport:e.viewport,"device-pixel-ratio":(0,t.unref)(o)},{default:(0,t.withCtx)(({displaySize:e})=>[(0,t.renderSlot)(n.$slots,`default`,{doc:s.value,page:i,displaySize:e})]),_:2},1032,[`page`,`hide-number`,`hide-text`,`zoom-type`,`zoom`,`viewport`,`device-pixel-ratio`]))),128))],512))}});e.PdfHost=(0,t.defineComponent)({__name:`PdfHost`,props:{workerSrc:{},sources:{},zoomType:{},zoom:{},hideText:{type:Boolean},hideNumber:{type:Boolean}},emits:[`update:zoom`,`update:zoomType`],setup(e,{expose:i,emit:a}){let o=e,s=a,c=(0,t.ref)();i({zoomIn:m,zoomOut:h}),(0,t.watch)(()=>o.workerSrc,e=>{e&&(n.GlobalWorkerOptions.workerSrc=e)},{immediate:!0});function l(e){e.ctrlKey&&(e.preventDefault(),e.deltaY<0?m():h())}function u(e){e.ctrlKey&&(e.key===`0`||e.which==48)&&s(`update:zoomType`,r.Auto)}let d=(0,t.ref)({width:0,height:0}),f=x(()=>{let e=c.value;e&&(d.value={width:e.offsetWidth,height:e.offsetHeight})},100);function p(e){let t=e%.25;return Number((e-t).toFixed(2))}function m(){let e=p((o.zoom||1)+.25);s(`update:zoom`,Math.min(e,2)),s(`update:zoomType`,r.Custom)}function h(){let e=p((o.zoom||1)-.25);s(`update:zoom`,Math.max(e,.25)),s(`update:zoomType`,r.Custom)}return(0,t.watch)(()=>o.zoom,(e,n)=>{let r=c.value;if(r&&e&&n){let i=r.scrollTop,a=r.scrollLeft,o=e/n;(0,t.nextTick)(()=>{r.scrollTop=i*o,r.scrollLeft=a*o})}}),(0,t.onMounted)(()=>{window.addEventListener(`resize`,f),f()}),(0,t.onBeforeUnmount)(()=>{window.removeEventListener(`resize`,f)}),(n,i)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`rootEl`,ref:c,onWheel:l,onKeydown:u,tabindex:`0`,class:`pdf-host`},[((0,t.openBlock)(!0),(0,t.createElementBlock)(t.Fragment,null,(0,t.renderList)(e.sources,a=>((0,t.openBlock)(),(0,t.createBlock)(N,{viewport:d.value,src:a,"hide-number":!!e.hideNumber,"hide-text":!!e.hideText,"zoom-type":e.zoomType||(0,t.unref)(r).Auto,zoom:e.zoom||1,"onUpdate:zoom":i[0]||=e=>s(`update:zoom`,e)},{loading:(0,t.withCtx)(({loading:e,progress:r})=>[(0,t.renderSlot)(n.$slots,`loading`,{source:a,loading:e,progress:r})]),default:(0,t.withCtx)(({doc:e,page:r,displaySize:i})=>[(0,t.renderSlot)(n.$slots,`page`,{source:a,doc:e,page:r,displaySize:i})]),_:2},1032,[`viewport`,`src`,`hide-number`,`hide-text`,`zoom-type`,`zoom`]))),256)),(0,t.renderSlot)(n.$slots,`default`)],544))}}),e.ZoomType=r});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdfjs-vue3",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
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,6 +36,7 @@
|
|
|
36
36
|
"preview": "vite preview"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
+
"@vueuse/core": "^14.2.1",
|
|
39
40
|
"pdfjs-dist": "^5.6.205",
|
|
40
41
|
"vue": "^3.5.32"
|
|
41
42
|
},
|
|
@@ -47,8 +48,5 @@
|
|
|
47
48
|
"typescript": "^5.9.3",
|
|
48
49
|
"vite": "^8.0.3",
|
|
49
50
|
"vue-tsc": "^3.2.6"
|
|
50
|
-
},
|
|
51
|
-
"dependencies": {
|
|
52
|
-
"@vueuse/core": "^14.2.1"
|
|
53
51
|
}
|
|
54
52
|
}
|