pdfjs-vue3 0.1.0 → 0.1.3

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.
@@ -1,268 +1,163 @@
1
- import { defineComponent, ref, watch, onMounted, openBlock, createElementBlock, computed, onBeforeUnmount, createElementVNode, createBlock, unref, createCommentVNode, renderSlot, toDisplayString, shallowRef, Fragment, renderList, withCtx, nextTick } from "vue";
2
- import { renderTextLayer, getDocument, GlobalWorkerOptions } from "pdfjs-dist";
3
- var ZoomType = /* @__PURE__ */ ((ZoomType2) => {
4
- ZoomType2[ZoomType2["Auto"] = 0] = "Auto";
5
- ZoomType2[ZoomType2["WidthFit"] = 1] = "WidthFit";
6
- ZoomType2[ZoomType2["PageFit"] = 2] = "PageFit";
7
- ZoomType2[ZoomType2["Custom"] = 3] = "Custom";
8
- return ZoomType2;
9
- })(ZoomType || {});
10
- var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
11
- function isObject$2(value) {
12
- var type = typeof value;
13
- return value != null && (type == "object" || type == "function");
1
+ import { defineComponent as I, ref as _, watch as P, onMounted as L, openBlock as T, createElementBlock as $, computed as C, onBeforeUnmount as D, createElementVNode as W, createBlock as G, unref as k, createCommentVNode as F, renderSlot as j, toDisplayString as J, shallowRef as B, Fragment as Q, renderList as Z, withCtx as A, nextTick as ie } from "vue";
2
+ import { renderTextLayer as ae, getDocument as le, GlobalWorkerOptions as se } from "pdfjs-dist";
3
+ var S = /* @__PURE__ */ ((e) => (e[e.Auto = 0] = "Auto", e[e.WidthFit = 1] = "WidthFit", e[e.PageFit = 2] = "PageFit", e[e.Custom = 3] = "Custom", e))(S || {}), N = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
4
+ function ue(e) {
5
+ var i = typeof e;
6
+ return e != null && (i == "object" || i == "function");
14
7
  }
15
- var isObject_1 = isObject$2;
16
- var freeGlobal$1 = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
17
- var _freeGlobal = freeGlobal$1;
18
- var freeGlobal = _freeGlobal;
19
- var freeSelf = typeof self == "object" && self && self.Object === Object && self;
20
- var root$2 = freeGlobal || freeSelf || Function("return this")();
21
- var _root = root$2;
22
- var root$1 = _root;
23
- var now$1 = function() {
24
- return root$1.Date.now();
25
- };
26
- var now_1 = now$1;
27
- var reWhitespace = /\s/;
28
- function trimmedEndIndex$1(string) {
29
- var index = string.length;
30
- while (index-- && reWhitespace.test(string.charAt(index))) {
31
- }
32
- return index;
8
+ var ee = ue, ce = typeof N == "object" && N && N.Object === Object && N, de = ce, fe = de, me = typeof self == "object" && self && self.Object === Object && self, ve = fe || me || Function("return this")(), te = ve, pe = te, ge = function() {
9
+ return pe.Date.now();
10
+ }, he = ge, be = /\s/;
11
+ function ye(e) {
12
+ for (var i = e.length; i-- && be.test(e.charAt(i)); )
13
+ ;
14
+ return i;
33
15
  }
34
- var _trimmedEndIndex = trimmedEndIndex$1;
35
- var trimmedEndIndex = _trimmedEndIndex;
36
- var reTrimStart = /^\s+/;
37
- function baseTrim$1(string) {
38
- return string ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, "") : string;
16
+ var we = ye, Te = we, xe = /^\s+/;
17
+ function _e(e) {
18
+ return e && e.slice(0, Te(e) + 1).replace(xe, "");
39
19
  }
40
- var _baseTrim = baseTrim$1;
41
- var root = _root;
42
- var Symbol$3 = root.Symbol;
43
- var _Symbol = Symbol$3;
44
- var Symbol$2 = _Symbol;
45
- var objectProto$1 = Object.prototype;
46
- var hasOwnProperty = objectProto$1.hasOwnProperty;
47
- var nativeObjectToString$1 = objectProto$1.toString;
48
- var symToStringTag$1 = Symbol$2 ? Symbol$2.toStringTag : void 0;
49
- function getRawTag$1(value) {
50
- var isOwn = hasOwnProperty.call(value, symToStringTag$1), tag = value[symToStringTag$1];
20
+ var ze = _e, Se = te, $e = Se.Symbol, oe = $e, H = oe, ne = Object.prototype, Pe = ne.hasOwnProperty, ke = ne.toString, O = H ? H.toStringTag : void 0;
21
+ function je(e) {
22
+ var i = Pe.call(e, O), l = e[O];
51
23
  try {
52
- value[symToStringTag$1] = void 0;
53
- var unmasked = true;
54
- } catch (e) {
55
- }
56
- var result = nativeObjectToString$1.call(value);
57
- if (unmasked) {
58
- if (isOwn) {
59
- value[symToStringTag$1] = tag;
60
- } else {
61
- delete value[symToStringTag$1];
62
- }
24
+ e[O] = void 0;
25
+ var n = !0;
26
+ } catch {
63
27
  }
64
- return result;
28
+ var s = ke.call(e);
29
+ return n && (i ? e[O] = l : delete e[O]), s;
65
30
  }
66
- var _getRawTag = getRawTag$1;
67
- var objectProto = Object.prototype;
68
- var nativeObjectToString = objectProto.toString;
69
- function objectToString$1(value) {
70
- return nativeObjectToString.call(value);
31
+ var Ee = je, Oe = Object.prototype, Ce = Oe.toString;
32
+ function Ne(e) {
33
+ return Ce.call(e);
71
34
  }
72
- var _objectToString = objectToString$1;
73
- var Symbol$1 = _Symbol, getRawTag = _getRawTag, objectToString = _objectToString;
74
- var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
75
- var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : void 0;
76
- function baseGetTag$1(value) {
77
- if (value == null) {
78
- return value === void 0 ? undefinedTag : nullTag;
79
- }
80
- return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
35
+ var Ie = Ne, U = oe, Le = Ee, Me = Ie, We = "[object Null]", Be = "[object Undefined]", K = U ? U.toStringTag : void 0;
36
+ function Ve(e) {
37
+ return e == null ? e === void 0 ? Be : We : K && K in Object(e) ? Le(e) : Me(e);
81
38
  }
82
- var _baseGetTag = baseGetTag$1;
83
- function isObjectLike$1(value) {
84
- return value != null && typeof value == "object";
39
+ var Fe = Ve;
40
+ function Ae(e) {
41
+ return e != null && typeof e == "object";
85
42
  }
86
- var isObjectLike_1 = isObjectLike$1;
87
- var baseGetTag = _baseGetTag, isObjectLike = isObjectLike_1;
88
- var symbolTag = "[object Symbol]";
89
- function isSymbol$1(value) {
90
- return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
43
+ var De = Ae, Ge = Fe, Re = De, He = "[object Symbol]";
44
+ function Ue(e) {
45
+ return typeof e == "symbol" || Re(e) && Ge(e) == He;
91
46
  }
92
- var isSymbol_1 = isSymbol$1;
93
- var baseTrim = _baseTrim, isObject$1 = isObject_1, isSymbol = isSymbol_1;
94
- var NAN = 0 / 0;
95
- var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
96
- var reIsBinary = /^0b[01]+$/i;
97
- var reIsOctal = /^0o[0-7]+$/i;
98
- var freeParseInt = parseInt;
99
- function toNumber$1(value) {
100
- if (typeof value == "number") {
101
- return value;
102
- }
103
- if (isSymbol(value)) {
104
- return NAN;
105
- }
106
- if (isObject$1(value)) {
107
- var other = typeof value.valueOf == "function" ? value.valueOf() : value;
108
- value = isObject$1(other) ? other + "" : other;
47
+ var Ke = Ue, Xe = ze, X = ee, Ye = Ke, Y = 0 / 0, qe = /^[-+]0x[0-9a-f]+$/i, Je = /^0b[01]+$/i, Qe = /^0o[0-7]+$/i, Ze = parseInt;
48
+ function et(e) {
49
+ if (typeof e == "number")
50
+ return e;
51
+ if (Ye(e))
52
+ return Y;
53
+ if (X(e)) {
54
+ var i = typeof e.valueOf == "function" ? e.valueOf() : e;
55
+ e = X(i) ? i + "" : i;
109
56
  }
110
- if (typeof value != "string") {
111
- return value === 0 ? value : +value;
112
- }
113
- value = baseTrim(value);
114
- var isBinary = reIsBinary.test(value);
115
- return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
57
+ if (typeof e != "string")
58
+ return e === 0 ? e : +e;
59
+ e = Xe(e);
60
+ var l = Je.test(e);
61
+ return l || Qe.test(e) ? Ze(e.slice(2), l ? 2 : 8) : qe.test(e) ? Y : +e;
116
62
  }
117
- var toNumber_1 = toNumber$1;
118
- var isObject = isObject_1, now = now_1, toNumber = toNumber_1;
119
- var FUNC_ERROR_TEXT = "Expected a function";
120
- var nativeMax = Math.max, nativeMin = Math.min;
121
- function debounce(func, wait, options) {
122
- var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
123
- if (typeof func != "function") {
124
- throw new TypeError(FUNC_ERROR_TEXT);
63
+ var tt = et, ot = ee, V = he, q = tt, nt = "Expected a function", rt = Math.max, it = Math.min;
64
+ function at(e, i, l) {
65
+ var n, s, m, d, c, u, g = 0, x = !1, h = !1, t = !0;
66
+ if (typeof e != "function")
67
+ throw new TypeError(nt);
68
+ i = q(i) || 0, ot(l) && (x = !!l.leading, h = "maxWait" in l, m = h ? rt(q(l.maxWait) || 0, i) : m, t = "trailing" in l ? !!l.trailing : t);
69
+ function a(v) {
70
+ var z = n, E = s;
71
+ return n = s = void 0, g = v, d = e.apply(E, z), d;
125
72
  }
126
- wait = toNumber(wait) || 0;
127
- if (isObject(options)) {
128
- leading = !!options.leading;
129
- maxing = "maxWait" in options;
130
- maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
131
- trailing = "trailing" in options ? !!options.trailing : trailing;
73
+ function r(v) {
74
+ return g = v, c = setTimeout(p, i), x ? a(v) : d;
132
75
  }
133
- function invokeFunc(time) {
134
- var args = lastArgs, thisArg = lastThis;
135
- lastArgs = lastThis = void 0;
136
- lastInvokeTime = time;
137
- result = func.apply(thisArg, args);
138
- return result;
76
+ function o(v) {
77
+ var z = v - u, E = v - g, R = i - z;
78
+ return h ? it(R, m - E) : R;
139
79
  }
140
- function leadingEdge(time) {
141
- lastInvokeTime = time;
142
- timerId = setTimeout(timerExpired, wait);
143
- return leading ? invokeFunc(time) : result;
80
+ function f(v) {
81
+ var z = v - u, E = v - g;
82
+ return u === void 0 || z >= i || z < 0 || h && E >= m;
144
83
  }
145
- function remainingWait(time) {
146
- var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
147
- return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
84
+ function p() {
85
+ var v = V();
86
+ if (f(v))
87
+ return y(v);
88
+ c = setTimeout(p, o(v));
148
89
  }
149
- function shouldInvoke(time) {
150
- var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
151
- return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
90
+ function y(v) {
91
+ return c = void 0, t && n ? a(v) : (n = s = void 0, d);
152
92
  }
153
- function timerExpired() {
154
- var time = now();
155
- if (shouldInvoke(time)) {
156
- return trailingEdge(time);
157
- }
158
- timerId = setTimeout(timerExpired, remainingWait(time));
93
+ function w() {
94
+ c !== void 0 && clearTimeout(c), g = 0, n = u = s = c = void 0;
159
95
  }
160
- function trailingEdge(time) {
161
- timerId = void 0;
162
- if (trailing && lastArgs) {
163
- return invokeFunc(time);
164
- }
165
- lastArgs = lastThis = void 0;
166
- return result;
96
+ function b() {
97
+ return c === void 0 ? d : y(V());
167
98
  }
168
- function cancel() {
169
- if (timerId !== void 0) {
170
- clearTimeout(timerId);
99
+ function M() {
100
+ var v = V(), z = f(v);
101
+ if (n = arguments, s = this, u = v, z) {
102
+ if (c === void 0)
103
+ return r(u);
104
+ if (h)
105
+ return clearTimeout(c), c = setTimeout(p, i), a(u);
171
106
  }
172
- lastInvokeTime = 0;
173
- lastArgs = lastCallTime = lastThis = timerId = void 0;
174
- }
175
- function flush() {
176
- return timerId === void 0 ? result : trailingEdge(now());
107
+ return c === void 0 && (c = setTimeout(p, i)), d;
177
108
  }
178
- function debounced() {
179
- var time = now(), isInvoking = shouldInvoke(time);
180
- lastArgs = arguments;
181
- lastThis = this;
182
- lastCallTime = time;
183
- if (isInvoking) {
184
- if (timerId === void 0) {
185
- return leadingEdge(lastCallTime);
186
- }
187
- if (maxing) {
188
- clearTimeout(timerId);
189
- timerId = setTimeout(timerExpired, wait);
190
- return invokeFunc(lastCallTime);
191
- }
192
- }
193
- if (timerId === void 0) {
194
- timerId = setTimeout(timerExpired, wait);
195
- }
196
- return result;
197
- }
198
- debounced.cancel = cancel;
199
- debounced.flush = flush;
200
- return debounced;
109
+ return M.cancel = w, M.flush = b, M;
201
110
  }
202
- var debounce_1 = debounce;
203
- var PdfPageText_vue_vue_type_style_index_0_lang = "";
204
- const _sfc_main$3 = /* @__PURE__ */ defineComponent({
111
+ var re = at;
112
+ const lt = /* @__PURE__ */ I({
113
+ __name: "PdfPageText",
205
114
  props: {
206
115
  viewport: null,
207
116
  page: null
208
117
  },
209
- setup(__props) {
210
- const props = __props;
211
- const textContent = ref();
212
- const rootEl = ref();
213
- watch(() => props.page, async (page) => {
214
- textContent.value = await page.getTextContent();
215
- }, { immediate: true });
216
- watch(() => [textContent.value, rootEl.value, props.viewport], () => {
217
- renderText();
118
+ setup(e) {
119
+ const i = e, l = _(), n = _();
120
+ P(() => i.page, async (d) => {
121
+ l.value = await d.getTextContent();
122
+ }, { immediate: !0 }), P(() => [l.value, n.value, i.viewport], () => {
123
+ m();
218
124
  });
219
- let renderTask = void 0;
220
- function renderText() {
221
- const el = rootEl.value;
222
- const text = textContent.value;
223
- const vp = props.viewport;
224
- if (!el || !text || !vp)
225
- return;
226
- if (renderTask) {
227
- renderTask.cancel();
228
- return;
229
- }
230
- while (el.firstChild) {
231
- el.removeChild(el.firstChild);
125
+ let s;
126
+ function m() {
127
+ const d = n.value, c = l.value, u = i.viewport;
128
+ if (!(!d || !c || !u)) {
129
+ if (s) {
130
+ s.cancel();
131
+ return;
132
+ }
133
+ for (; d.firstChild; )
134
+ d.removeChild(d.firstChild);
135
+ s = ae({
136
+ textContent: l.value,
137
+ container: d,
138
+ viewport: u
139
+ }), s.promise.then(() => {
140
+ s = void 0;
141
+ }).catch(() => {
142
+ s = void 0;
143
+ }).finally(() => {
144
+ });
232
145
  }
233
- renderTask = renderTextLayer({
234
- textContent: textContent.value,
235
- container: el,
236
- viewport: vp,
237
- enhanceTextSelection: true
238
- });
239
- renderTask.promise.then(() => {
240
- renderTask = void 0;
241
- }).catch(() => {
242
- renderTask = void 0;
243
- }).finally(() => {
244
- });
245
146
  }
246
- onMounted(() => {
247
- renderText();
248
- });
249
- return (_ctx, _cache) => {
250
- return openBlock(), createElementBlock("div", {
251
- ref_key: "rootEl",
252
- ref: rootEl,
253
- class: "pdf-text-layer"
254
- }, null, 512);
255
- };
147
+ return L(() => {
148
+ m();
149
+ }), (d, c) => (T(), $("div", {
150
+ ref_key: "rootEl",
151
+ ref: n,
152
+ class: "pdf-text-layer"
153
+ }, null, 512));
256
154
  }
257
155
  });
258
- var PdfPage_vue_vue_type_style_index_0_lang = "";
259
- const _hoisted_1 = { class: "pdf-page-layout" };
260
- const _hoisted_2 = { class: "pdf-page-overlay" };
261
- const _hoisted_3 = {
156
+ const st = { class: "pdf-page-layout" }, ut = { class: "pdf-page-overlay" }, ct = {
262
157
  key: 0,
263
158
  class: "pdf-page-number"
264
- };
265
- const _sfc_main$2 = /* @__PURE__ */ defineComponent({
159
+ }, dt = /* @__PURE__ */ I({
160
+ __name: "PdfPage",
266
161
  props: {
267
162
  zoom: null,
268
163
  zoomType: null,
@@ -273,129 +168,84 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
273
168
  observer: null
274
169
  },
275
170
  emits: ["update:zoom"],
276
- setup(__props, { expose, emit: emits }) {
277
- const props = __props;
278
- const canvas = ref();
279
- const rootEl = ref();
280
- const inViewport = ref(false);
281
- const maxAutoWidth = 1100;
282
- expose({ rootEl, inViewport });
283
- const baseScale = 96 / 72;
284
- const pdfScale = computed(() => {
285
- const { width: pageWidth, height: pageHeight } = props.page.getViewport({ scale: baseScale });
286
- const { width: vpWidth, height: vpHeight } = props.viewport;
287
- let wLimit = 0;
288
- let newZoom = 1;
289
- switch (props.zoomType) {
290
- case ZoomType.Auto:
291
- wLimit = Math.min(vpWidth, maxAutoWidth) - 40;
292
- newZoom = wLimit / pageWidth;
293
- return baseScale * newZoom;
294
- case ZoomType.WidthFit:
295
- wLimit = vpWidth - 40;
296
- newZoom = wLimit / pageWidth;
297
- return baseScale * newZoom;
298
- case ZoomType.PageFit:
299
- if (vpWidth > vpHeight) {
300
- newZoom = vpHeight / pageHeight;
301
- return baseScale * newZoom;
302
- } else {
303
- wLimit = vpWidth - 40;
304
- newZoom = wLimit / pageWidth;
305
- return baseScale * newZoom;
306
- }
307
- }
308
- return baseScale * props.zoom;
309
- });
310
- const displayScale = computed(() => {
311
- return pdfScale.value * ((window == null ? void 0 : window.devicePixelRatio) || 1);
312
- });
313
- const pdfViewport = computed(() => {
314
- return props.page.getViewport({ scale: pdfScale.value });
315
- });
316
- const displayViewport = computed(() => {
317
- return props.page.getViewport({ scale: displayScale.value });
318
- });
319
- watch(pdfScale, (newScale) => {
320
- const newZoom = newScale / baseScale;
321
- const delta = Math.abs(newZoom - props.zoom);
322
- if (delta > 0.05) {
323
- emits("update:zoom", newZoom);
171
+ setup(e, { expose: i, emit: l }) {
172
+ const n = e, s = _(), m = _(), d = _(!1), c = 1100;
173
+ i({ rootEl: m, inViewport: d });
174
+ const u = 96 / 72, g = C(() => {
175
+ const { width: o, height: f } = n.page.getViewport({ scale: u }), { width: p, height: y } = n.viewport;
176
+ let w = 0, b = 1;
177
+ switch (n.zoomType) {
178
+ case S.Auto:
179
+ return w = Math.min(p, c) - 40, b = w / o, u * b;
180
+ case S.WidthFit:
181
+ return w = p - 40, b = w / o, u * b;
182
+ case S.PageFit:
183
+ return p > y ? (b = y / f, u * b) : (w = p - 40, b = w / o, u * b);
324
184
  }
325
- }, { immediate: true });
326
- let renderTask;
327
- function renderPage() {
328
- if (!props.page || !canvas.value)
185
+ return u * n.zoom;
186
+ }), x = C(() => g.value * ((window == null ? void 0 : window.devicePixelRatio) || 1)), h = C(() => n.page.getViewport({ scale: g.value })), t = C(() => n.page.getViewport({ scale: x.value }));
187
+ P(g, (o) => {
188
+ const f = o / u;
189
+ Math.abs(f - n.zoom) > 0.05 && l("update:zoom", f);
190
+ }, { immediate: !0 });
191
+ let a;
192
+ function r() {
193
+ if (!n.page || !s.value)
329
194
  return;
330
- const page = props.page;
331
- const pdfVP = pdfViewport.value;
332
- const dispVP = displayViewport.value;
333
- const canvasEl = canvas.value;
334
- canvasEl.width = Math.ceil(dispVP.width);
335
- canvasEl.height = Math.ceil(dispVP.height);
336
- canvasEl.style.width = Math.floor(pdfVP.width) + "px";
337
- canvasEl.style.height = Math.floor(pdfVP.height) + "px";
338
- const context = canvasEl.getContext("2d");
339
- if (!context || !inViewport.value)
195
+ const o = n.page, f = h.value, p = t.value, y = s.value;
196
+ y.width = Math.ceil(p.width), y.height = Math.ceil(p.height), y.style.width = Math.floor(f.width) + "px", y.style.height = Math.floor(f.height) + "px";
197
+ const w = y.getContext("2d");
198
+ if (!w || !d.value)
340
199
  return;
341
- if (renderTask) {
342
- renderTask.cancel();
200
+ if (a) {
201
+ a.cancel();
343
202
  return;
344
203
  }
345
- console.debug(`rendering page ${page.pageNumber}`);
346
- const renderContext = {
347
- canvasContext: context,
348
- viewport: displayViewport.value
204
+ console.debug(`rendering page ${o.pageNumber}`);
205
+ const b = {
206
+ canvasContext: w,
207
+ viewport: t.value
349
208
  };
350
- renderTask = page.render(renderContext);
351
- renderTask.promise.then(() => renderTask = void 0).catch(() => {
352
- renderTask = void 0;
353
- renderPage();
209
+ a = o.render(b), a.promise.then(() => a = void 0).catch(() => {
210
+ a = void 0, r();
354
211
  });
355
212
  }
356
- watch(() => [props.page, displayScale.value, inViewport.value], () => {
357
- renderPage();
358
- }, { immediate: true });
359
- onMounted(() => {
360
- var _a;
361
- renderPage();
362
- if (rootEl.value)
363
- (_a = props.observer) == null ? void 0 : _a.observe(rootEl.value);
364
- });
365
- onBeforeUnmount(() => {
366
- var _a;
367
- if (rootEl.value)
368
- (_a = props.observer) == null ? void 0 : _a.unobserve(rootEl.value);
369
- });
370
- return (_ctx, _cache) => {
371
- return openBlock(), createElementBlock("div", {
372
- ref_key: "rootEl",
373
- ref: rootEl,
374
- class: "pdf-page"
375
- }, [
376
- createElementVNode("div", _hoisted_1, [
377
- createElementVNode("canvas", {
378
- ref_key: "canvas",
379
- ref: canvas
380
- }, null, 512),
381
- createElementVNode("div", _hoisted_2, [
382
- !__props.hideText ? (openBlock(), createBlock(_sfc_main$3, {
383
- key: 0,
384
- viewport: unref(displayViewport),
385
- page: __props.page
386
- }, null, 8, ["viewport", "page"])) : createCommentVNode("", true),
387
- renderSlot(_ctx.$slots, "default", {
388
- width: unref(pdfViewport).width,
389
- height: unref(pdfViewport).height
390
- })
391
- ])
392
- ]),
393
- !__props.hideNumber ? (openBlock(), createElementBlock("div", _hoisted_3, toDisplayString(__props.page.pageNumber), 1)) : createCommentVNode("", true)
394
- ], 512);
395
- };
213
+ return P(() => [n.page, x.value, d.value], () => {
214
+ r();
215
+ }, { immediate: !0 }), L(() => {
216
+ var o;
217
+ r(), m.value && ((o = n.observer) == null || o.observe(m.value));
218
+ }), D(() => {
219
+ var o;
220
+ m.value && ((o = n.observer) == null || o.unobserve(m.value));
221
+ }), (o, f) => (T(), $("div", {
222
+ ref_key: "rootEl",
223
+ ref: m,
224
+ class: "pdf-page"
225
+ }, [
226
+ W("div", st, [
227
+ W("canvas", {
228
+ ref_key: "canvas",
229
+ ref: s
230
+ }, null, 512),
231
+ W("div", ut, [
232
+ e.hideText ? F("", !0) : (T(), G(lt, {
233
+ key: 0,
234
+ viewport: k(t),
235
+ page: e.page
236
+ }, null, 8, ["viewport", "page"])),
237
+ j(o.$slots, "default", { displaySize: k(t) })
238
+ ])
239
+ ]),
240
+ e.hideNumber ? F("", !0) : (T(), $("div", ct, J(e.page.pageNumber), 1))
241
+ ], 512));
396
242
  }
397
243
  });
398
- const _sfc_main$1 = /* @__PURE__ */ defineComponent({
244
+ const ft = {
245
+ key: 0,
246
+ class: "pdf-progress"
247
+ }, mt = /* @__PURE__ */ I({
248
+ __name: "PdfDocument",
399
249
  props: {
400
250
  hideText: { type: Boolean },
401
251
  hideNumber: { type: Boolean },
@@ -405,98 +255,87 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
405
255
  src: null
406
256
  },
407
257
  emits: ["error", "update:zoom"],
408
- setup(__props, { emit: emits }) {
409
- const props = __props;
410
- const pdfDoc = shallowRef();
411
- const pdfPages = shallowRef([]);
412
- const observer = shallowRef();
413
- const rootEl = ref();
414
- const pageComps = ref([]);
415
- function setPageComp(component) {
416
- pageComps.value.push(component);
417
- if (pageComps.value.length == 1)
418
- component.inViewport = true;
258
+ setup(e, { emit: i }) {
259
+ const l = e, n = B(), s = B([]), m = B(), d = _();
260
+ let c = [];
261
+ const u = _(!1), g = _(0);
262
+ function x(t) {
263
+ c.push(t), c.length == 1 && (t.inViewport = !0);
419
264
  }
420
- function cleanupDoc() {
421
- pdfPages.value.forEach((pg) => pg.cleanup());
422
- pdfPages.value = [];
423
- const doc = pdfDoc.value;
424
- if (doc) {
425
- doc.destroy();
426
- pdfDoc.value = void 0;
427
- }
265
+ function h() {
266
+ s.value.forEach((a) => a.cleanup()), s.value = [];
267
+ const t = n.value;
268
+ t && (t.destroy(), n.value = void 0), c = [];
428
269
  }
429
- watch(() => props.src, (src) => {
430
- cleanupDoc();
431
- if (!src)
270
+ return P(() => l.src, (t) => {
271
+ if (h(), !t)
432
272
  return;
433
- getDocument(src).promise.then((doc) => {
434
- pdfDoc.value = doc;
435
- const tasks = [];
436
- for (let i = 1; i <= doc.numPages; i++) {
437
- tasks.push(doc.getPage(i));
438
- }
439
- Promise.all(tasks).then((pages) => {
440
- if (doc === pdfDoc.value)
441
- pdfPages.value = pages;
273
+ const a = le(t);
274
+ u.value = !0, a.onProgress = (r) => {
275
+ r.total && (g.value = r.loaded / r.total);
276
+ }, a.promise.then((r) => {
277
+ n.value = r;
278
+ const o = [];
279
+ for (let f = 1; f <= r.numPages; f++)
280
+ o.push(r.getPage(f));
281
+ Promise.all(o).then((f) => {
282
+ r === n.value && (s.value = f);
442
283
  });
443
- }).catch((err) => {
444
- emits("error", err);
284
+ }).catch((r) => {
285
+ i("error", r);
286
+ }).finally(() => {
287
+ u.value = !1;
445
288
  });
446
- }, { immediate: true });
447
- onMounted(() => {
448
- observer.value = new IntersectionObserver(debounce_1((entries) => {
449
- entries.forEach((entry) => {
450
- const foundComp = pageComps.value.find((comp) => (comp == null ? void 0 : comp.rootEl) === entry.target);
451
- if (foundComp) {
452
- foundComp.inViewport = entry.isIntersecting;
453
- }
289
+ }, { immediate: !0 }), L(() => {
290
+ m.value = new IntersectionObserver(re((t) => {
291
+ t.forEach((a) => {
292
+ const r = c.find((o) => (o == null ? void 0 : o.rootEl) === a.target);
293
+ r && (r.inViewport = a.isIntersecting);
454
294
  });
455
295
  }, 50), {
456
296
  rootMargin: "0px"
457
297
  });
458
- });
459
- onBeforeUnmount(() => {
460
- var _a;
461
- cleanupDoc();
462
- (_a = observer.value) == null ? void 0 : _a.disconnect();
463
- });
464
- return (_ctx, _cache) => {
465
- return openBlock(), createElementBlock("div", {
466
- ref_key: "rootEl",
467
- ref: rootEl
468
- }, [
469
- (openBlock(true), createElementBlock(Fragment, null, renderList(unref(pdfPages), (page) => {
470
- return openBlock(), createBlock(_sfc_main$2, {
471
- ref_for: true,
472
- ref: setPageComp,
473
- key: page.pageNumber,
474
- page,
475
- "hide-number": __props.hideNumber,
476
- "hide-text": __props.hideText,
477
- "zoom-type": __props.zoomType,
478
- zoom: __props.zoom,
479
- "onUpdate:zoom": _cache[0] || (_cache[0] = ($event) => emits("update:zoom", $event)),
480
- observer: unref(observer),
481
- viewport: __props.viewport
482
- }, {
483
- default: withCtx(({ width, height }) => [
484
- renderSlot(_ctx.$slots, "default", {
485
- doc: unref(pdfDoc),
486
- page,
487
- width,
488
- height
489
- })
490
- ]),
491
- _: 2
492
- }, 1032, ["page", "hide-number", "hide-text", "zoom-type", "zoom", "observer", "viewport"]);
493
- }), 128))
494
- ], 512);
495
- };
298
+ }), D(() => {
299
+ var t;
300
+ h(), (t = m.value) == null || t.disconnect();
301
+ }), (t, a) => (T(), $("div", {
302
+ ref_key: "rootEl",
303
+ ref: d
304
+ }, [
305
+ j(t.$slots, "loading", {
306
+ src: l.src,
307
+ loading: u.value,
308
+ progress: g.value
309
+ }, () => [
310
+ u.value ? (T(), $("p", ft, "loading " + J(Math.ceil(100 * g.value)) + "%", 1)) : F("", !0)
311
+ ]),
312
+ (T(!0), $(Q, null, Z(k(s), (r) => (T(), G(dt, {
313
+ ref_for: !0,
314
+ ref: x,
315
+ key: r.pageNumber,
316
+ page: r,
317
+ "hide-number": e.hideNumber,
318
+ "hide-text": e.hideText,
319
+ "zoom-type": e.zoomType,
320
+ zoom: e.zoom,
321
+ "onUpdate:zoom": a[0] || (a[0] = (o) => i("update:zoom", o)),
322
+ observer: k(m),
323
+ viewport: e.viewport
324
+ }, {
325
+ default: A(({ displaySize: o }) => [
326
+ j(t.$slots, "default", {
327
+ doc: k(n),
328
+ page: r,
329
+ displaySize: o
330
+ })
331
+ ]),
332
+ _: 2
333
+ }, 1032, ["page", "hide-number", "hide-text", "zoom-type", "zoom", "observer", "viewport"]))), 128))
334
+ ], 512));
496
335
  }
497
336
  });
498
- var PdfHost_vue_vue_type_style_index_0_lang = "";
499
- const _sfc_main = /* @__PURE__ */ defineComponent({
337
+ const gt = /* @__PURE__ */ I({
338
+ __name: "PdfHost",
500
339
  props: {
501
340
  workerSrc: null,
502
341
  sources: null,
@@ -506,110 +345,90 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
506
345
  hideNumber: { type: Boolean }
507
346
  },
508
347
  emits: ["update:zoom", "update:zoomType"],
509
- setup(__props, { expose, emit: emits }) {
510
- const props = __props;
511
- const rootEl = ref();
512
- expose({
513
- zoomIn,
514
- zoomOut
515
- });
516
- watch(() => props.workerSrc, (js) => {
517
- if (js)
518
- GlobalWorkerOptions.workerSrc = js;
519
- }, { immediate: true });
520
- function onMouseWheel(e) {
521
- if (e.ctrlKey) {
522
- e.preventDefault();
523
- if (e.deltaY < 0) {
524
- zoomIn();
525
- } else {
526
- zoomOut();
527
- }
528
- }
348
+ setup(e, { expose: i, emit: l }) {
349
+ const n = e, s = _();
350
+ i({
351
+ zoomIn: x,
352
+ zoomOut: h
353
+ }), P(() => n.workerSrc, (t) => {
354
+ t && (se.workerSrc = t);
355
+ }, { immediate: !0 });
356
+ function m(t) {
357
+ t.ctrlKey && (t.preventDefault(), t.deltaY < 0 ? x() : h());
529
358
  }
530
- function onKeydown(e) {
531
- if (e.ctrlKey) {
532
- if (e.key === "0" || e.which == 48) {
533
- emits("update:zoomType", ZoomType.Auto);
534
- }
535
- }
359
+ function d(t) {
360
+ t.ctrlKey && (t.key === "0" || t.which == 48) && l("update:zoomType", S.Auto);
536
361
  }
537
- const viewport = ref({ width: 0, height: 0 });
538
- const updateViewport = debounce_1(() => {
539
- const root2 = rootEl.value;
540
- if (root2) {
541
- viewport.value = {
542
- width: root2.offsetWidth,
543
- height: root2.offsetHeight
544
- };
545
- }
362
+ const c = _({ width: 0, height: 0 }), u = re(() => {
363
+ const t = s.value;
364
+ t && (c.value = {
365
+ width: t.offsetWidth,
366
+ height: t.offsetHeight
367
+ });
546
368
  }, 100);
547
- function fitZoom(zoom) {
548
- const overage = zoom % 0.25;
549
- return Number((zoom - overage).toFixed(2));
369
+ function g(t) {
370
+ const a = t % 0.25;
371
+ return Number((t - a).toFixed(2));
550
372
  }
551
- function zoomIn() {
552
- const proposed = fitZoom((props.zoom || 1) + 0.25);
553
- emits("update:zoom", Math.min(proposed, 2));
554
- emits("update:zoomType", ZoomType.Custom);
373
+ function x() {
374
+ const t = g((n.zoom || 1) + 0.25);
375
+ l("update:zoom", Math.min(t, 2)), l("update:zoomType", S.Custom);
555
376
  }
556
- function zoomOut() {
557
- const proposed = fitZoom((props.zoom || 1) - 0.25);
558
- emits("update:zoom", Math.max(proposed, 0.25));
559
- emits("update:zoomType", ZoomType.Custom);
377
+ function h() {
378
+ const t = g((n.zoom || 1) - 0.25);
379
+ l("update:zoom", Math.max(t, 0.25)), l("update:zoomType", S.Custom);
560
380
  }
561
- watch(() => props.zoom, (newZoom, oldZoom) => {
562
- const root2 = rootEl.value;
563
- if (root2 && newZoom && oldZoom) {
564
- const curTop = root2.scrollTop;
565
- const curLeft = root2.scrollLeft;
566
- const ratio = newZoom / oldZoom;
567
- nextTick(() => {
568
- root2.scrollTop = curTop * ratio;
569
- root2.scrollLeft = curLeft * ratio;
381
+ return P(() => n.zoom, (t, a) => {
382
+ const r = s.value;
383
+ if (r && t && a) {
384
+ const o = r.scrollTop, f = r.scrollLeft, p = t / a;
385
+ ie(() => {
386
+ r.scrollTop = o * p, r.scrollLeft = f * p;
570
387
  });
571
388
  }
572
- });
573
- onMounted(() => {
574
- window.addEventListener("resize", updateViewport);
575
- updateViewport();
576
- });
577
- onBeforeUnmount(() => {
578
- window.removeEventListener("resize", updateViewport);
579
- });
580
- return (_ctx, _cache) => {
581
- return openBlock(), createElementBlock("div", {
582
- ref_key: "rootEl",
583
- ref: rootEl,
584
- onWheel: onMouseWheel,
585
- onKeydown,
586
- tabindex: "0",
587
- class: "pdf-host"
588
- }, [
589
- (openBlock(true), createElementBlock(Fragment, null, renderList(__props.sources, (src) => {
590
- return openBlock(), createBlock(_sfc_main$1, {
591
- viewport: viewport.value,
592
- src,
593
- "hide-number": !!__props.hideNumber,
594
- "hide-text": !!__props.hideText,
595
- "zoom-type": __props.zoomType || unref(ZoomType).Auto,
596
- zoom: __props.zoom || 1,
597
- "onUpdate:zoom": _cache[0] || (_cache[0] = ($event) => emits("update:zoom", $event))
598
- }, {
599
- default: withCtx(({ doc, page, width, height }) => [
600
- renderSlot(_ctx.$slots, "page", {
601
- doc,
602
- page,
603
- width,
604
- height
605
- })
606
- ]),
607
- _: 2
608
- }, 1032, ["viewport", "src", "hide-number", "hide-text", "zoom-type", "zoom"]);
609
- }), 256)),
610
- renderSlot(_ctx.$slots, "default")
611
- ], 544);
612
- };
389
+ }), L(() => {
390
+ window.addEventListener("resize", u), u();
391
+ }), D(() => {
392
+ window.removeEventListener("resize", u);
393
+ }), (t, a) => (T(), $("div", {
394
+ ref_key: "rootEl",
395
+ ref: s,
396
+ onWheel: m,
397
+ onKeydown: d,
398
+ tabindex: "0",
399
+ class: "pdf-host"
400
+ }, [
401
+ (T(!0), $(Q, null, Z(e.sources, (r) => (T(), G(mt, {
402
+ viewport: c.value,
403
+ src: r,
404
+ "hide-number": !!e.hideNumber,
405
+ "hide-text": !!e.hideText,
406
+ "zoom-type": e.zoomType || k(S).Auto,
407
+ zoom: e.zoom || 1,
408
+ "onUpdate:zoom": a[0] || (a[0] = (o) => l("update:zoom", o))
409
+ }, {
410
+ loading: A(({ loading: o, progress: f }) => [
411
+ j(t.$slots, "loading", {
412
+ source: r,
413
+ loading: o,
414
+ progress: f
415
+ })
416
+ ]),
417
+ default: A(({ doc: o, page: f, displaySize: p }) => [
418
+ j(t.$slots, "page", {
419
+ source: r,
420
+ doc: o,
421
+ page: f,
422
+ displaySize: p
423
+ })
424
+ ]),
425
+ _: 2
426
+ }, 1032, ["viewport", "src", "hide-number", "hide-text", "zoom-type", "zoom"]))), 256)),
427
+ j(t.$slots, "default")
428
+ ], 544));
613
429
  }
614
430
  });
615
- export { _sfc_main as PdfHost, ZoomType };
431
+ export {
432
+ gt as PdfHost,
433
+ S as ZoomType
434
+ };