pdfjs-vue3 0.1.11 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pdfjs-vue3.css +2 -0
- package/dist/pdfjs-vue3.es.js +329 -443
- package/dist/pdfjs-vue3.umd.js +1 -1
- package/package.json +13 -12
- package/types/PdfHost.vue.d.ts +52 -60
- package/types/types.d.ts +1 -2
- package/dist/style.css +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
.pdf-text-layer{--lightningcss-light:initial;--lightningcss-dark: ;color-scheme:light only;text-align:initial;opacity:1;-webkit-text-size-adjust:none;-moz-text-size-adjust:none;text-size-adjust:none;forced-color-adjust:none;transform-origin:0 0;caret-color:canvastext;z-index:0;line-height:1;position:absolute;inset:0;overflow:clip}.pdf-text-layer.highlighting{touch-action:none}.pdf-text-layer :is(span,br){color:#0000;white-space:pre;cursor:text;transform-origin:0 0;position:absolute}.pdf-text-layer{--min-font-size:1;--text-scale-factor:calc(var(--total-scale-factor) * var(--min-font-size));--min-font-size-inv:calc(1 / var(--min-font-size))}.pdf-text-layer>:not(.markedContent),.pdf-text-layer .markedContent span:not(.markedContent){z-index:1;--font-height:0;font-size:calc(var(--text-scale-factor) * var(--font-height));--scale-x:1;--rotate:0deg;transform:rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv))}.pdf-text-layer .markedContent{display:contents}.pdf-text-layer span[role=img]{-webkit-user-select:none;user-select:none;cursor:default}.pdf-text-layer .highlight{--highlight-bg-color:#b400aa40;--highlight-selected-bg-color:#00640040;--highlight-backdrop-filter:none;--highlight-selected-backdrop-filter:none}@media screen and (forced-colors:active){.pdf-text-layer .highlight{--highlight-bg-color:transparent;--highlight-selected-bg-color:transparent;--highlight-backdrop-filter:var(--hcm-highlight-filter);--highlight-selected-backdrop-filter:var(--hcm-highlight-selected-filter)}}.pdf-text-layer .highlight{background-color:var(--highlight-bg-color);-webkit-backdrop-filter:var(--highlight-backdrop-filter);backdrop-filter:var(--highlight-backdrop-filter);border-radius:4px;margin:-1px;padding:1px}.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:var(--highlight-selected-bg-color);-webkit-backdrop-filter:var(--highlight-selected-backdrop-filter);backdrop-filter:var(--highlight-selected-backdrop-filter);scroll-margin-top:50px}.pdf-text-layer ::selection{background:#0000ff40;background:color-mix(in srgb, AccentColor, transparent 75%)}.pdf-text-layer br::selection{background:0 0}.pdf-text-layer .endOfContent{z-index:0;cursor:default;-webkit-user-select:none;user-select:none;display:block;position:absolute;inset:100% 0 0}.pdf-text-layer.selecting .endOfContent{top:0}.textLayerImages{-webkit-user-select:none;user-select:none;position:absolute;inset:0}.textLayerImages canvas{transform-origin:0 0;position:absolute}.pdf-page{flex-direction:column;margin:1rem auto;display:flex}.pdf-page-layout{filter:drop-shadow(0 1px 2px #0000001a)drop-shadow(0 1px 1px #0000000f);background:#fff;margin:auto;display:flex;position:relative}.pdf-page-number{text-align:center;line-height:1.5}.pdf-page-overlay{position:absolute;inset:0}.pdf-progress{text-align:center;padding:1rem}.pdf-host{touch-action:pan-x pan-y;background:#dcdcdc;height:100%;padding:1rem 0;overflow:auto}.pdf-host:focus{outline:none}
|
|
2
|
+
/*$vite$:1*/
|
package/dist/pdfjs-vue3.es.js
CHANGED
|
@@ -1,448 +1,334 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
import { Fragment as e, computed as t, createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, defineComponent as o, nextTick as s, onBeforeUnmount as c, onMounted as l, openBlock as u, ref as d, renderList as f, renderSlot as p, shallowRef as m, toDisplayString as h, toValue as g, unref as _, watch as v, withCtx as y } from "vue";
|
|
2
|
+
import { GlobalWorkerOptions as b, TextLayer as x, getDocument as S } from "pdfjs-dist";
|
|
3
|
+
//#region src/types.ts
|
|
4
|
+
var C = /* @__PURE__ */ function(e) {
|
|
5
|
+
return e[e.Auto = 0] = "Auto", e[e.WidthFit = 1] = "WidthFit", e[e.PageFit = 2] = "PageFit", e[e.Custom = 3] = "Custom", e;
|
|
6
|
+
}({}), w = /* @__PURE__ */ o({
|
|
7
|
+
__name: "PdfPageText",
|
|
8
|
+
props: {
|
|
9
|
+
viewport: {},
|
|
10
|
+
page: {}
|
|
11
|
+
},
|
|
12
|
+
setup(e) {
|
|
13
|
+
let t = e, n = d(), r;
|
|
14
|
+
v(() => [t.viewport, t.page], () => {
|
|
15
|
+
a();
|
|
16
|
+
});
|
|
17
|
+
async function a() {
|
|
18
|
+
let e = n.value, i = t.viewport;
|
|
19
|
+
if (!(!e || !i)) {
|
|
20
|
+
for (r &&= (r.cancel(), void 0); e.firstChild;) e.removeChild(e.firstChild);
|
|
21
|
+
r = new x({
|
|
22
|
+
textContentSource: t.page.streamTextContent(),
|
|
23
|
+
container: e,
|
|
24
|
+
viewport: i
|
|
25
|
+
}), await r.render();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return l(() => {
|
|
29
|
+
a();
|
|
30
|
+
}), (e, t) => (u(), i("div", {
|
|
31
|
+
ref_key: "rootEl",
|
|
32
|
+
ref: n,
|
|
33
|
+
class: "pdf-text-layer"
|
|
34
|
+
}, null, 512));
|
|
35
|
+
}
|
|
36
|
+
}), T = { class: "pdf-page-layout" }, E = { class: "pdf-page-overlay" }, D = {
|
|
37
|
+
key: 0,
|
|
38
|
+
class: "pdf-page-number"
|
|
39
|
+
}, O = 1100, k = 96 / 72, A = /* @__PURE__ */ o({
|
|
40
|
+
__name: "PdfPage",
|
|
41
|
+
props: {
|
|
42
|
+
zoom: {},
|
|
43
|
+
zoomType: {},
|
|
44
|
+
hideText: { type: Boolean },
|
|
45
|
+
hideNumber: { type: Boolean },
|
|
46
|
+
viewport: {},
|
|
47
|
+
page: {},
|
|
48
|
+
observer: {}
|
|
49
|
+
},
|
|
50
|
+
emits: ["update:zoom"],
|
|
51
|
+
setup(e, { expose: o, emit: s }) {
|
|
52
|
+
let f = e, m = s, g = d(), _ = d(), y = d(!1);
|
|
53
|
+
o({
|
|
54
|
+
rootEl: _,
|
|
55
|
+
inViewport: y
|
|
56
|
+
});
|
|
57
|
+
let b = t(() => {
|
|
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);
|
|
63
|
+
}
|
|
64
|
+
return k * f.zoom;
|
|
65
|
+
}), x = t(() => b.value * (window?.devicePixelRatio || 1)), S = t(() => f.page.getViewport({ scale: b.value })), A = t(() => f.page.getViewport({ scale: x.value }));
|
|
66
|
+
v(b, (e) => {
|
|
67
|
+
let t = e / k;
|
|
68
|
+
Math.abs(t - f.zoom) > .05 && m("update:zoom", t);
|
|
69
|
+
}, { immediate: !0 });
|
|
70
|
+
let j;
|
|
71
|
+
function M() {
|
|
72
|
+
if (!f.page || !g.value) return;
|
|
73
|
+
let e = f.page, t = S.value, n = A.value, r = g.value;
|
|
74
|
+
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 = _.value;
|
|
76
|
+
i && (i.style.width = r.style.width, i.style.height = r.style.height);
|
|
77
|
+
let a = r.getContext("2d");
|
|
78
|
+
if (!(!a || !y.value)) {
|
|
79
|
+
if (j) {
|
|
80
|
+
j.cancel();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
j = e.render({
|
|
84
|
+
canvas: r,
|
|
85
|
+
canvasContext: a,
|
|
86
|
+
viewport: A.value
|
|
87
|
+
}), j.promise.then(() => j = void 0).catch(() => {
|
|
88
|
+
j = void 0, M();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return v(() => [
|
|
93
|
+
f.page,
|
|
94
|
+
x.value,
|
|
95
|
+
y.value
|
|
96
|
+
], () => {
|
|
97
|
+
M();
|
|
98
|
+
}, { immediate: !0 }), l(() => {
|
|
99
|
+
M(), _.value && f.observer?.observe(_.value);
|
|
100
|
+
}), c(() => {
|
|
101
|
+
_.value && f.observer?.unobserve(_.value);
|
|
102
|
+
}), (t, o) => (u(), i("div", {
|
|
103
|
+
ref_key: "rootEl",
|
|
104
|
+
ref: _,
|
|
105
|
+
class: "pdf-page"
|
|
106
|
+
}, [a("div", T, [a("canvas", {
|
|
107
|
+
ref_key: "canvas",
|
|
108
|
+
ref: g
|
|
109
|
+
}, null, 512), a("div", E, [e.hideText ? r("", !0) : (u(), n(w, {
|
|
110
|
+
key: 0,
|
|
111
|
+
viewport: A.value,
|
|
112
|
+
page: e.page
|
|
113
|
+
}, null, 8, ["viewport", "page"])), p(t.$slots, "default", { displaySize: A.value })])]), e.hideNumber ? r("", !0) : (u(), i("div", D, h(e.page.pageNumber), 1))], 512));
|
|
114
|
+
}
|
|
115
|
+
}), j = {
|
|
116
|
+
key: 0,
|
|
117
|
+
class: "pdf-progress"
|
|
118
|
+
}, M = /* @__PURE__ */ o({
|
|
119
|
+
__name: "PdfDocument",
|
|
120
|
+
props: {
|
|
121
|
+
hideText: { type: Boolean },
|
|
122
|
+
hideNumber: { type: Boolean },
|
|
123
|
+
zoomType: {},
|
|
124
|
+
zoom: {},
|
|
125
|
+
viewport: {},
|
|
126
|
+
src: {}
|
|
127
|
+
},
|
|
128
|
+
emits: ["error", "update:zoom"],
|
|
129
|
+
setup(t, { emit: a }) {
|
|
130
|
+
let o = t, s = a, g = m(), _ = m([]), b = m(), x = d(), C = [], w = d(!1), T = d(0);
|
|
131
|
+
function E(e) {
|
|
132
|
+
e && (C.push(e), C.length == 1 && (e.inViewport = !0));
|
|
133
|
+
}
|
|
134
|
+
function D() {
|
|
135
|
+
_.value.forEach((e) => e.cleanup()), _.value = [];
|
|
136
|
+
let e = g.value;
|
|
137
|
+
e && (e.destroy(), g.value = void 0), C = [];
|
|
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;
|
|
146
|
+
let t = [];
|
|
147
|
+
for (let n = 1; n <= e.numPages; n++) t.push(e.getPage(n));
|
|
148
|
+
Promise.all(t).then((t) => {
|
|
149
|
+
e === g.value && (_.value = t);
|
|
150
|
+
});
|
|
151
|
+
}).catch((e) => {
|
|
152
|
+
s("error", e);
|
|
153
|
+
}).finally(() => {
|
|
154
|
+
w.value = !1;
|
|
155
|
+
});
|
|
156
|
+
}, { immediate: !0 }), l(() => {
|
|
157
|
+
b.value = new IntersectionObserver((e) => {
|
|
158
|
+
e.forEach((e) => {
|
|
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", {
|
|
166
|
+
ref_key: "rootEl",
|
|
167
|
+
ref: x
|
|
168
|
+
}, [p(a.$slots, "loading", {
|
|
169
|
+
src: o.src,
|
|
170
|
+
loading: w.value,
|
|
171
|
+
progress: T.value
|
|
172
|
+
}, () => [w.value ? (u(), i("p", j, "loading " + h(Math.ceil(100 * T.value)) + "%", 1)) : r("", !0)]), (u(!0), i(e, null, f(_.value, (e) => (u(), n(A, {
|
|
173
|
+
ref_for: !0,
|
|
174
|
+
ref: E,
|
|
175
|
+
key: e.pageNumber,
|
|
176
|
+
page: e,
|
|
177
|
+
"hide-number": t.hideNumber,
|
|
178
|
+
"hide-text": t.hideText,
|
|
179
|
+
"zoom-type": t.zoomType,
|
|
180
|
+
zoom: t.zoom,
|
|
181
|
+
"onUpdate:zoom": c[0] ||= (e) => s("update:zoom", e),
|
|
182
|
+
observer: b.value,
|
|
183
|
+
viewport: t.viewport
|
|
184
|
+
}, {
|
|
185
|
+
default: y(({ displaySize: t }) => [p(a.$slots, "default", {
|
|
186
|
+
doc: g.value,
|
|
187
|
+
page: e,
|
|
188
|
+
displaySize: t
|
|
189
|
+
})]),
|
|
190
|
+
_: 2
|
|
191
|
+
}, 1032, [
|
|
192
|
+
"page",
|
|
193
|
+
"hide-number",
|
|
194
|
+
"hide-text",
|
|
195
|
+
"zoom-type",
|
|
196
|
+
"zoom",
|
|
197
|
+
"observer",
|
|
198
|
+
"viewport"
|
|
199
|
+
]))), 128))], 512));
|
|
200
|
+
}
|
|
48
201
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
},
|
|
63
|
-
emits: ["update:zoom"],
|
|
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
|
-
}
|
|
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
|
-
}, { immediate: !0 });
|
|
84
|
-
let g;
|
|
85
|
-
function t() {
|
|
86
|
-
if (!n.page || !l.value)
|
|
87
|
-
return;
|
|
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
|
-
return;
|
|
95
|
-
if (g) {
|
|
96
|
-
g.cancel();
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
console.debug(`rendering page ${o.pageNumber}`);
|
|
100
|
-
const I = {
|
|
101
|
-
canvasContext: b,
|
|
102
|
-
viewport: y.value
|
|
103
|
-
};
|
|
104
|
-
g = o.render(I), g.promise.then(() => g = void 0).catch(() => {
|
|
105
|
-
g = void 0, t();
|
|
106
|
-
});
|
|
107
|
-
}
|
|
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
|
-
ref_key: "rootEl",
|
|
118
|
-
ref: f,
|
|
119
|
-
class: "pdf-page"
|
|
120
|
-
}, [
|
|
121
|
-
L("div", de, [
|
|
122
|
-
L("canvas", {
|
|
123
|
-
ref_key: "canvas",
|
|
124
|
-
ref: l
|
|
125
|
-
}, null, 512),
|
|
126
|
-
L("div", ce, [
|
|
127
|
-
o.hideText ? V("", !0) : (w(), D(le, {
|
|
128
|
-
key: 0,
|
|
129
|
-
viewport: y.value,
|
|
130
|
-
page: o.page
|
|
131
|
-
}, null, 8, ["viewport", "page"])),
|
|
132
|
-
P(o.$slots, "default", { displaySize: y.value })
|
|
133
|
-
])
|
|
134
|
-
]),
|
|
135
|
-
o.hideNumber ? V("", !0) : (w(), S("div", fe, q(o.page.pageNumber), 1))
|
|
136
|
-
], 512));
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
const me = {
|
|
140
|
-
key: 0,
|
|
141
|
-
class: "pdf-progress"
|
|
142
|
-
}, ge = /* @__PURE__ */ C({
|
|
143
|
-
__name: "PdfDocument",
|
|
144
|
-
props: {
|
|
145
|
-
hideText: { type: Boolean },
|
|
146
|
-
hideNumber: { type: Boolean },
|
|
147
|
-
zoomType: {},
|
|
148
|
-
zoom: {},
|
|
149
|
-
viewport: {},
|
|
150
|
-
src: {}
|
|
151
|
-
},
|
|
152
|
-
emits: ["error", "update:zoom"],
|
|
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
|
-
}
|
|
160
|
-
function g() {
|
|
161
|
-
l.value.forEach((o) => o.cleanup()), l.value = [];
|
|
162
|
-
const t = n.value;
|
|
163
|
-
t && (t.destroy(), n.value = void 0), s = [];
|
|
164
|
-
}
|
|
165
|
-
return $(() => u.src, (t) => {
|
|
166
|
-
if (g(), !t)
|
|
167
|
-
return;
|
|
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
|
-
});
|
|
179
|
-
}).catch((r) => {
|
|
180
|
-
i("error", r);
|
|
181
|
-
}).finally(() => {
|
|
182
|
-
p.value = !1;
|
|
183
|
-
});
|
|
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
|
-
});
|
|
190
|
-
}, {
|
|
191
|
-
// root: rootEl.value,
|
|
192
|
-
rootMargin: "0px"
|
|
193
|
-
});
|
|
194
|
-
}), A(() => {
|
|
195
|
-
var t;
|
|
196
|
-
g(), (t = f.value) == null || t.disconnect();
|
|
197
|
-
}), (t, o) => (w(), S("div", {
|
|
198
|
-
ref_key: "rootEl",
|
|
199
|
-
ref: c
|
|
200
|
-
}, [
|
|
201
|
-
P(t.$slots, "loading", {
|
|
202
|
-
src: u.src,
|
|
203
|
-
loading: p.value,
|
|
204
|
-
progress: h.value
|
|
205
|
-
}, () => [
|
|
206
|
-
p.value ? (w(), S("p", me, "loading " + q(Math.ceil(100 * h.value)) + "%", 1)) : V("", !0)
|
|
207
|
-
]),
|
|
208
|
-
(w(!0), S(J, null, Q(l.value, (r) => (w(), D(ve, {
|
|
209
|
-
ref_for: !0,
|
|
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
|
-
}, {
|
|
221
|
-
default: F(({ displaySize: a }) => [
|
|
222
|
-
P(t.$slots, "default", {
|
|
223
|
-
doc: n.value,
|
|
224
|
-
page: r,
|
|
225
|
-
displaySize: a
|
|
226
|
-
})
|
|
227
|
-
]),
|
|
228
|
-
_: 2
|
|
229
|
-
}, 1032, ["page", "hide-number", "hide-text", "zoom-type", "zoom", "observer", "viewport"]))), 128))
|
|
230
|
-
], 512));
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
var E = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
234
|
-
function he(e) {
|
|
235
|
-
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
236
|
-
}
|
|
237
|
-
function be(e) {
|
|
238
|
-
var i = typeof e;
|
|
239
|
-
return e != null && (i == "object" || i == "function");
|
|
240
|
-
}
|
|
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
|
-
;
|
|
247
|
-
return i;
|
|
248
|
-
}
|
|
249
|
-
var je = ke, Oe = je, Ee = /^\s+/;
|
|
250
|
-
function Ce(e) {
|
|
251
|
-
return e && e.slice(0, Oe(e) + 1).replace(Ee, "");
|
|
252
|
-
}
|
|
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
|
-
try {
|
|
257
|
-
e[j] = void 0;
|
|
258
|
-
var n = !0;
|
|
259
|
-
} catch {
|
|
260
|
-
}
|
|
261
|
-
var l = We.call(e);
|
|
262
|
-
return n && (i ? e[j] = u : delete e[j]), l;
|
|
263
|
-
}
|
|
264
|
-
var Ve = Be, Fe = Object.prototype, Ae = Fe.toString;
|
|
265
|
-
function De(e) {
|
|
266
|
-
return Ae.call(e);
|
|
267
|
-
}
|
|
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
|
-
}
|
|
272
|
-
var Ye = Xe;
|
|
273
|
-
function qe(e) {
|
|
274
|
-
return e != null && typeof e == "object";
|
|
275
|
-
}
|
|
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;
|
|
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;
|
|
279
215
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return u || st.test(e) ? ut(e.slice(2), u ? 2 : 8) : it.test(e) ? X : +e;
|
|
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
|
+
};
|
|
295
230
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
var n, l, f, c, s, p, h = 0, y = !1, g = !1, t = !0;
|
|
299
|
-
if (typeof e != "function")
|
|
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
|
-
}
|
|
306
|
-
function r(m) {
|
|
307
|
-
return h = m, s = setTimeout(v, i), y ? o(m) : c;
|
|
308
|
-
}
|
|
309
|
-
function a(m) {
|
|
310
|
-
var T = m - p, k = m - h, G = i - T;
|
|
311
|
-
return g ? vt(G, f - k) : G;
|
|
312
|
-
}
|
|
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
|
-
}
|
|
317
|
-
function v() {
|
|
318
|
-
var m = B();
|
|
319
|
-
if (d(m))
|
|
320
|
-
return b(m);
|
|
321
|
-
s = setTimeout(v, a(m));
|
|
322
|
-
}
|
|
323
|
-
function b(m) {
|
|
324
|
-
return s = void 0, t && n ? o(m) : (n = l = void 0, c);
|
|
325
|
-
}
|
|
326
|
-
function I() {
|
|
327
|
-
s !== void 0 && clearTimeout(s), h = 0, n = p = l = s = void 0;
|
|
328
|
-
}
|
|
329
|
-
function re() {
|
|
330
|
-
return s === void 0 ? c : b(B());
|
|
331
|
-
}
|
|
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
|
-
if (g)
|
|
338
|
-
return clearTimeout(s), s = setTimeout(v, i), o(p);
|
|
339
|
-
}
|
|
340
|
-
return s === void 0 && (s = setTimeout(v, i)), c;
|
|
341
|
-
}
|
|
342
|
-
return M.cancel = I, M.flush = re, M;
|
|
231
|
+
function I(e, t = 200, n = {}) {
|
|
232
|
+
return P(F(t, n), e);
|
|
343
233
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
], 544));
|
|
443
|
-
}
|
|
234
|
+
//#endregion
|
|
235
|
+
//#region src/PdfHost.vue
|
|
236
|
+
var L = /* @__PURE__ */ o({
|
|
237
|
+
__name: "PdfHost",
|
|
238
|
+
props: {
|
|
239
|
+
workerSrc: {},
|
|
240
|
+
sources: {},
|
|
241
|
+
zoomType: {},
|
|
242
|
+
zoom: {},
|
|
243
|
+
hideText: { type: Boolean },
|
|
244
|
+
hideNumber: { type: Boolean }
|
|
245
|
+
},
|
|
246
|
+
emits: ["update:zoom", "update:zoomType"],
|
|
247
|
+
setup(t, { expose: r, emit: a }) {
|
|
248
|
+
let o = t, m = a, h = d();
|
|
249
|
+
r({
|
|
250
|
+
zoomIn: E,
|
|
251
|
+
zoomOut: D
|
|
252
|
+
}), v(() => o.workerSrc, (e) => {
|
|
253
|
+
e && (b.workerSrc = e);
|
|
254
|
+
}, { immediate: !0 });
|
|
255
|
+
function g(e) {
|
|
256
|
+
e.ctrlKey && (e.preventDefault(), e.deltaY < 0 ? E() : D());
|
|
257
|
+
}
|
|
258
|
+
function x(e) {
|
|
259
|
+
e.ctrlKey && (e.key === "0" || e.which == 48) && m("update:zoomType", C.Auto);
|
|
260
|
+
}
|
|
261
|
+
let S = d({
|
|
262
|
+
width: 0,
|
|
263
|
+
height: 0
|
|
264
|
+
}), w = I(() => {
|
|
265
|
+
let e = h.value;
|
|
266
|
+
e && (S.value = {
|
|
267
|
+
width: e.offsetWidth,
|
|
268
|
+
height: e.offsetHeight
|
|
269
|
+
});
|
|
270
|
+
}, 100);
|
|
271
|
+
function T(e) {
|
|
272
|
+
let t = e % .25;
|
|
273
|
+
return Number((e - t).toFixed(2));
|
|
274
|
+
}
|
|
275
|
+
function E() {
|
|
276
|
+
let e = T((o.zoom || 1) + .25);
|
|
277
|
+
m("update:zoom", Math.min(e, 2)), m("update:zoomType", C.Custom);
|
|
278
|
+
}
|
|
279
|
+
function D() {
|
|
280
|
+
let e = T((o.zoom || 1) - .25);
|
|
281
|
+
m("update:zoom", Math.max(e, .25)), m("update:zoomType", C.Custom);
|
|
282
|
+
}
|
|
283
|
+
return v(() => o.zoom, (e, t) => {
|
|
284
|
+
let n = h.value;
|
|
285
|
+
if (n && e && t) {
|
|
286
|
+
let r = n.scrollTop, i = n.scrollLeft, a = e / t;
|
|
287
|
+
s(() => {
|
|
288
|
+
n.scrollTop = r * a, n.scrollLeft = i * a;
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}), l(() => {
|
|
292
|
+
window.addEventListener("resize", w), w();
|
|
293
|
+
}), c(() => {
|
|
294
|
+
window.removeEventListener("resize", w);
|
|
295
|
+
}), (r, a) => (u(), i("div", {
|
|
296
|
+
ref_key: "rootEl",
|
|
297
|
+
ref: h,
|
|
298
|
+
onWheel: g,
|
|
299
|
+
onKeydown: x,
|
|
300
|
+
tabindex: "0",
|
|
301
|
+
class: "pdf-host"
|
|
302
|
+
}, [(u(!0), i(e, null, f(t.sources, (e) => (u(), n(M, {
|
|
303
|
+
viewport: S.value,
|
|
304
|
+
src: e,
|
|
305
|
+
"hide-number": !!t.hideNumber,
|
|
306
|
+
"hide-text": !!t.hideText,
|
|
307
|
+
"zoom-type": t.zoomType || _(C).Auto,
|
|
308
|
+
zoom: t.zoom || 1,
|
|
309
|
+
"onUpdate:zoom": a[0] ||= (e) => m("update:zoom", e)
|
|
310
|
+
}, {
|
|
311
|
+
loading: y(({ loading: t, progress: n }) => [p(r.$slots, "loading", {
|
|
312
|
+
source: e,
|
|
313
|
+
loading: t,
|
|
314
|
+
progress: n
|
|
315
|
+
})]),
|
|
316
|
+
default: y(({ doc: t, page: n, displaySize: i }) => [p(r.$slots, "page", {
|
|
317
|
+
source: e,
|
|
318
|
+
doc: t,
|
|
319
|
+
page: n,
|
|
320
|
+
displaySize: i
|
|
321
|
+
})]),
|
|
322
|
+
_: 2
|
|
323
|
+
}, 1032, [
|
|
324
|
+
"viewport",
|
|
325
|
+
"src",
|
|
326
|
+
"hide-number",
|
|
327
|
+
"hide-text",
|
|
328
|
+
"zoom-type",
|
|
329
|
+
"zoom"
|
|
330
|
+
]))), 256)), p(r.$slots, "default")], 544));
|
|
331
|
+
}
|
|
444
332
|
});
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
z as ZoomType
|
|
448
|
-
};
|
|
333
|
+
//#endregion
|
|
334
|
+
export { L as PdfHost, C as ZoomType };
|
package/dist/pdfjs-vue3.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
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});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdfjs-vue3",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Using pdfjs to display PDFs as a vue 3 component.",
|
|
5
5
|
"author": "Eugene Wang",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
],
|
|
22
22
|
"types": "./types/index.d.ts",
|
|
23
23
|
"main": "./dist/pdfjs-vue3.umd.js",
|
|
24
|
-
|
|
24
|
+
"style": "./dist/style.css",
|
|
25
25
|
"module": "./dist/pdfjs-vue3.es.js",
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
@@ -36,18 +36,19 @@
|
|
|
36
36
|
"preview": "vite preview"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"pdfjs-dist": "^
|
|
40
|
-
"vue": "^3.
|
|
39
|
+
"pdfjs-dist": "^5.6.205",
|
|
40
|
+
"vue": "^3.5.32"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/types": "^7.23.0",
|
|
44
|
-
"@types/
|
|
45
|
-
"@
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
"@types/node": "^25.5.2",
|
|
45
|
+
"@vitejs/plugin-vue": "^6.0.5",
|
|
46
|
+
"modern-normalize": "^3.0.1",
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
|
+
"vite": "^8.0.3",
|
|
49
|
+
"vue-tsc": "^3.2.6"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@vueuse/core": "^14.2.1"
|
|
52
53
|
}
|
|
53
54
|
}
|
package/types/PdfHost.vue.d.ts
CHANGED
|
@@ -1,27 +1,50 @@
|
|
|
1
1
|
import { PdfSource, ZoomType } from './types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
/**
|
|
4
|
+
* Pdfjs's worker script url. Must be set if haven't been set elsewhere.
|
|
5
|
+
*/
|
|
6
|
+
workerSrc?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Array of pdf sources to display.
|
|
9
|
+
*/
|
|
10
|
+
sources: PdfSource[];
|
|
11
|
+
/**
|
|
12
|
+
* Type of zoom used. Defaults to Auto.
|
|
13
|
+
*/
|
|
14
|
+
zoomType?: ZoomType;
|
|
15
|
+
/**
|
|
16
|
+
* Display zoom percentage if using custom zoom, defaults to 1 (100%).
|
|
17
|
+
*/
|
|
18
|
+
zoom?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Hides the selectable text layer.
|
|
21
|
+
*/
|
|
22
|
+
hideText?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Hides page number display.
|
|
25
|
+
*/
|
|
26
|
+
hideNumber?: boolean;
|
|
27
|
+
};
|
|
2
28
|
declare function zoomIn(): void;
|
|
3
29
|
declare function zoomOut(): void;
|
|
4
|
-
declare
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
type: import("vue").PropType<boolean>;
|
|
23
|
-
};
|
|
24
|
-
}, {
|
|
30
|
+
declare var __VLS_10: {
|
|
31
|
+
source: PdfSource;
|
|
32
|
+
loading: boolean;
|
|
33
|
+
progress: number;
|
|
34
|
+
}, __VLS_13: {
|
|
35
|
+
source: PdfSource;
|
|
36
|
+
doc: import("pdfjs-dist/types/src/display/api").PDFDocumentProxy | undefined;
|
|
37
|
+
page: import("pdfjs-dist/types/src/display/api").PDFPageProxy;
|
|
38
|
+
displaySize: import("pdfjs-dist/types/src/display/display_utils").PageViewport;
|
|
39
|
+
}, __VLS_15: {};
|
|
40
|
+
type __VLS_Slots = {} & {
|
|
41
|
+
loading?: (props: typeof __VLS_10) => any;
|
|
42
|
+
} & {
|
|
43
|
+
page?: (props: typeof __VLS_13) => any;
|
|
44
|
+
} & {
|
|
45
|
+
default?: (props: typeof __VLS_15) => any;
|
|
46
|
+
};
|
|
47
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {
|
|
25
48
|
/**
|
|
26
49
|
* Try to increase zoom to the next level, up to 200%.
|
|
27
50
|
*/
|
|
@@ -30,48 +53,17 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
|
|
|
30
53
|
* Try to decrease zoom to the next level, down to 25%.
|
|
31
54
|
*/
|
|
32
55
|
zoomOut: typeof zoomOut;
|
|
33
|
-
},
|
|
34
|
-
"update:zoom": (zoom: number) =>
|
|
35
|
-
"update:zoomType": (zoomType: ZoomType) =>
|
|
36
|
-
}, string, import("vue").
|
|
37
|
-
workerSrc: {
|
|
38
|
-
type: import("vue").PropType<string>;
|
|
39
|
-
};
|
|
40
|
-
sources: {
|
|
41
|
-
type: import("vue").PropType<PdfSource[]>;
|
|
42
|
-
required: true;
|
|
43
|
-
};
|
|
44
|
-
zoomType: {
|
|
45
|
-
type: import("vue").PropType<ZoomType>;
|
|
46
|
-
};
|
|
47
|
-
zoom: {
|
|
48
|
-
type: import("vue").PropType<number>;
|
|
49
|
-
};
|
|
50
|
-
hideText: {
|
|
51
|
-
type: import("vue").PropType<boolean>;
|
|
52
|
-
};
|
|
53
|
-
hideNumber: {
|
|
54
|
-
type: import("vue").PropType<boolean>;
|
|
55
|
-
};
|
|
56
|
-
}>> & {
|
|
56
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
57
|
+
"update:zoom": (zoom: number) => any;
|
|
58
|
+
"update:zoomType": (zoomType: ZoomType) => any;
|
|
59
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
57
60
|
"onUpdate:zoom"?: ((zoom: number) => any) | undefined;
|
|
58
61
|
"onUpdate:zoomType"?: ((zoomType: ZoomType) => any) | undefined;
|
|
59
|
-
}, {}, {}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
loading: boolean;
|
|
63
|
-
progress: number;
|
|
64
|
-
}): any;
|
|
65
|
-
page?(_: {
|
|
66
|
-
source: PdfSource;
|
|
67
|
-
doc: import("pdfjs-dist/types/src/display/api").PDFDocumentProxy | undefined;
|
|
68
|
-
page: import("pdfjs-dist/types/src/display/api").PDFPageProxy;
|
|
69
|
-
displaySize: import("pdfjs-dist/types/src/display/display_utils").PageViewport;
|
|
70
|
-
}): any;
|
|
71
|
-
default?(_: {}): any;
|
|
72
|
-
}>;
|
|
62
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
63
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
64
|
+
declare const _default: typeof __VLS_export;
|
|
73
65
|
export default _default;
|
|
74
|
-
type
|
|
66
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
75
67
|
new (): {
|
|
76
68
|
$slots: S;
|
|
77
69
|
};
|
package/types/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PDFDataRangeTransport } from 'pdfjs-dist';
|
|
2
1
|
import type { TypedArray, DocumentInitParameters } from 'pdfjs-dist/types/src/display/api';
|
|
3
2
|
/**
|
|
4
3
|
* Types of zooms supported in pdf display.
|
|
@@ -24,4 +23,4 @@ export declare enum ZoomType {
|
|
|
24
23
|
/**
|
|
25
24
|
* Source of pdf to display in the host.
|
|
26
25
|
*/
|
|
27
|
-
export type PdfSource = string | URL |
|
|
26
|
+
export type PdfSource = string | URL | TypedArray | ArrayBuffer | DocumentInitParameters;
|
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;-webkit-user-select:none;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}
|