@eternalheart/vue-file-preview 1.7.0 → 1.7.2

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.
Files changed (46) hide show
  1. package/README.md +2 -0
  2. package/README.zh-CN.md +2 -0
  3. package/lib/FilePreviewContent.vue.d.ts +9 -1
  4. package/lib/FilePreviewEmbed.vue.d.ts +6 -1
  5. package/lib/FilePreviewModal.vue.d.ts +6 -1
  6. package/lib/chunks/{EmptyState.vue_vue_type_script_setup_true_lang--ZOobbGi.mjs → EmptyState.vue_vue_type_script_setup_true_lang-Dna6LmVT.mjs} +1 -1
  7. package/lib/chunks/{avifLoader-CAUzjn-d-CnJpGYJ2.mjs → avifLoader-CAUzjn-d-dPsP28D5.mjs} +1 -1
  8. package/lib/chunks/{heicLoader-D_9PukkA-g_dLrWLP.mjs → heicLoader-D_9PukkA-T-k1DSgY.mjs} +1 -1
  9. package/lib/chunks/{index-c-pYJEmH.mjs → index-B5hprvcF.mjs} +1747 -1709
  10. package/lib/chunks/index-BN__EwfT.mjs +333 -0
  11. package/lib/chunks/{index-z9RqL2wI.mjs → index-BPutNVAf.mjs} +453 -453
  12. package/lib/chunks/{index-BfOWoMpY.mjs → index-B_Spz6Wn.mjs} +77 -77
  13. package/lib/chunks/{index-D5IF9F-D.mjs → index-BjHEHkZ8.mjs} +22 -22
  14. package/lib/chunks/{index-LPGxJDnT.mjs → index-BlZ6RmeR.mjs} +18 -18
  15. package/lib/chunks/{index-CrVQPnFj.mjs → index-C95y29OL.mjs} +18 -18
  16. package/lib/chunks/{index-DFeKS8tR.mjs → index-CegPYMyO.mjs} +22 -22
  17. package/lib/chunks/{index-C4hIk6pa.mjs → index-CqOGKCyE.mjs} +2 -2
  18. package/lib/chunks/{index-6XZXYqbp.mjs → index-Cv3Sg87O.mjs} +29 -32
  19. package/lib/chunks/{index-zLQlyNR2.mjs → index-DHba2Axz.mjs} +62 -62
  20. package/lib/chunks/{index-CWPdNhoe.mjs → index-DInI3RTN.mjs} +60 -60
  21. package/lib/chunks/{index-C8lyQPe3.mjs → index-DXzvgRuo.mjs} +3 -3
  22. package/lib/chunks/{index-BPSzwMOC.mjs → index-DcvlMm9Q.mjs} +46 -46
  23. package/lib/chunks/index-Dnyl1HQk.mjs +51 -0
  24. package/lib/chunks/{index-aKiIuKKx.mjs → index-JjVQZbDt.mjs} +50 -50
  25. package/lib/chunks/{index-DZe0BxAB.mjs → index-QPk2c2Tl.mjs} +20 -20
  26. package/lib/chunks/{index-DM8Dfl-m.mjs → index-TZv0MqBH.mjs} +15 -15
  27. package/lib/chunks/{index-BzwJ0VWu.mjs → index-cRhwUlQN.mjs} +33 -33
  28. package/lib/chunks/{index-BYQ9S7Mk.mjs → index-dOxDeWYi.mjs} +30 -30
  29. package/lib/chunks/{index-Bg8poMIm.mjs → index-eNZr1h6f.mjs} +29 -29
  30. package/lib/chunks/{index-Bf94DwQu.mjs → index-oJF-hur2.mjs} +24 -24
  31. package/lib/chunks/{jp2Loader-Dig19xyo-fCO1knZ0.mjs → jp2Loader-Dig19xyo-hrIg_KJ3.mjs} +1 -1
  32. package/lib/chunks/{psdLoader-C0tKUXXl-DihMskai.mjs → psdLoader-C0tKUXXl-B2cJ4s7t.mjs} +1 -1
  33. package/lib/chunks/{rawLoader-C-tPeFAB-BSfDPl-z.mjs → rawLoader-C-tPeFAB-BNV-Wmzr.mjs} +1 -1
  34. package/lib/chunks/{tiffLoader-BlhByX8w-JY5DaTre.mjs → tiffLoader-BlhByX8w-BzSrLE9Y.mjs} +1 -1
  35. package/lib/chunks/{useShikiHighlight-C-ztcJBE.mjs → useShikiHighlight-CpL0RAQg.mjs} +1 -1
  36. package/lib/composables/usePreviewEvents.d.ts +2 -2
  37. package/lib/composables/useRequest.d.ts +8 -2
  38. package/lib/core/events.d.ts +18 -1
  39. package/lib/core/index.d.ts +1 -1
  40. package/lib/index.cjs +54 -54
  41. package/lib/index.css +1 -1
  42. package/lib/index.d.ts +1 -1
  43. package/lib/index.mjs +5 -5
  44. package/package.json +1 -1
  45. package/lib/chunks/index-C41YET0_.mjs +0 -51
  46. package/lib/chunks/index-GFcSJEwj.mjs +0 -330
@@ -0,0 +1,333 @@
1
+ import { defineComponent as fe, ref as v, watch as Z, onMounted as pe, onBeforeUnmount as ve, openBlock as d, createElementBlock as g, createBlock as de, createCommentVNode as M, createElementVNode as f, toDisplayString as L, unref as q, normalizeStyle as z, createVNode as he, Fragment as G, renderList as ee } from "vue";
2
+ import me from "@likecoin/epub-ts";
3
+ import { List as ge, ChevronLeft as be, ChevronRight as we, Minimize2 as xe, Maximize2 as ye, X as ke } from "lucide-vue-next";
4
+ import { u as _e, a as Te, b as ze, N as Ce, J as Se } from "./index-B5hprvcF.mjs";
5
+ import { _ as Me } from "./RendererError.vue_vue_type_script_setup_true_lang-FmkMQHB8.mjs";
6
+ import { T as We } from "./base.types-DaftHyg7.mjs";
7
+ const Ee = { class: "vfp-relative vfp-w-full vfp-h-full vfp-flex vfp-justify-center vfp-bg-surface-1 vfp-overflow-hidden" }, $e = {
8
+ key: 1,
9
+ class: "vfp-absolute vfp-inset-0 vfp-renderer-loading vfp-z-10"
10
+ }, He = { class: "vfp-renderer-loading-content" }, Re = { class: "vfp-renderer-loading-text" }, Le = {
11
+ class: "vfp-flex vfp-items-center vfp-justify-between vfp-flex-shrink-0",
12
+ style: { padding: "12px 16px", "border-bottom": "1px solid rgba(255,255,255,0.1)" }
13
+ }, Ae = { style: { color: "white", "font-weight": "500", "font-size": "14px" } }, Fe = {
14
+ class: "vfp-flex-1 vfp-overflow-y-auto",
15
+ style: { padding: "8px 4px" }
16
+ }, Pe = ["title", "onClick", "onMouseenter", "onMouseleave"], Be = ["title", "onClick", "onMouseenter", "onMouseleave"], De = 794, je = /* @__PURE__ */ fe({
17
+ __name: "index",
18
+ props: {
19
+ url: {}
20
+ },
21
+ setup(te, { expose: oe }) {
22
+ const A = te, I = new We(), { t: p } = _e(), ae = Te(), F = ze(), b = v(1), y = v(1), l = v(null), W = v(!0), k = v(null), w = v(!1), x = v([]), s = v(!1), P = v("");
23
+ Z([b, y, w, s, () => x.value.length], () => {
24
+ I.notify();
25
+ });
26
+ let u = null, e = null, _ = 0, T = null;
27
+ const V = () => {
28
+ var t;
29
+ try {
30
+ (t = e == null ? void 0 : e.destroy) == null || t.call(e);
31
+ } catch {
32
+ }
33
+ try {
34
+ u == null || u.destroy();
35
+ } catch {
36
+ }
37
+ e = null, u = null, _ = 0, T = null;
38
+ }, re = () => {
39
+ e == null || e.prev();
40
+ }, le = () => {
41
+ e == null || e.next();
42
+ }, ne = () => {
43
+ w.value = !w.value, setTimeout(() => {
44
+ l.value && e && (e.resize(l.value.offsetWidth, l.value.offsetHeight), T && e.display(T), D());
45
+ }, 350);
46
+ }, se = () => {
47
+ s.value = !s.value;
48
+ }, X = (t) => {
49
+ P.value = t, e == null || e.display(t), s.value = !1;
50
+ }, c = (t) => t === P.value;
51
+ oe({
52
+ getToolbarGroups: () => [
53
+ {
54
+ items: [
55
+ {
56
+ type: "button",
57
+ icon: ge,
58
+ tooltip: p.value("toolbar.toc"),
59
+ action: se,
60
+ disabled: x.value.length === 0,
61
+ active: s.value
62
+ }
63
+ ]
64
+ },
65
+ {
66
+ items: [
67
+ {
68
+ type: "button",
69
+ icon: be,
70
+ tooltip: p.value("toolbar.prev_page"),
71
+ action: re,
72
+ disabled: b.value <= 1
73
+ },
74
+ {
75
+ type: "text",
76
+ content: `${b.value} / ${y.value}`,
77
+ minWidth: "4rem"
78
+ },
79
+ {
80
+ type: "button",
81
+ icon: we,
82
+ tooltip: p.value("toolbar.next_page"),
83
+ action: le,
84
+ disabled: b.value >= y.value
85
+ }
86
+ ]
87
+ },
88
+ {
89
+ items: [
90
+ {
91
+ type: "button",
92
+ icon: w.value ? xe : ye,
93
+ tooltip: w.value ? p.value("toolbar.normal_width") : p.value("toolbar.full_width"),
94
+ action: ne,
95
+ active: w.value
96
+ }
97
+ ]
98
+ }
99
+ ],
100
+ onToolbarChange: (t) => I.subscribe(t)
101
+ });
102
+ const j = async () => {
103
+ if (F.begin(A.url), !!l.value) {
104
+ W.value = !0, k.value = null, x.value = [], s.value = !1, l.value.innerHTML = "", V();
105
+ try {
106
+ const t = await ae.value(A.url);
107
+ if (!t.ok)
108
+ throw new Ce(
109
+ new Se("request.failed", { status: t.status })
110
+ );
111
+ const n = await t.arrayBuffer(), o = me(n);
112
+ u = o;
113
+ const S = new Promise((h, a) => {
114
+ o.on("openFailed", (m) => {
115
+ a(m instanceof Error ? m : new Error("EPUB open failed"));
116
+ });
117
+ });
118
+ e = o.renderTo(l.value, {
119
+ manager: "continuous",
120
+ flow: "scrolled",
121
+ width: "100%",
122
+ height: "100%"
123
+ }), e.themes.register("default", {
124
+ body: {
125
+ background: "#ffffff !important",
126
+ color: "#1a1a1a !important",
127
+ "font-family": '"Noto Serif SC", "Source Han Serif SC", Georgia, "Times New Roman", serif !important',
128
+ "font-size": "16px !important",
129
+ "line-height": "2 !important",
130
+ padding: "40px 60px !important",
131
+ "max-width": "100% !important",
132
+ "box-sizing": "border-box !important",
133
+ "word-break": "break-word !important",
134
+ "overflow-wrap": "break-word !important"
135
+ },
136
+ p: { "text-indent": "2em !important", margin: "0.8em 0 !important" },
137
+ h1: { "text-align": "center !important", margin: "1.5em 0 1em !important" },
138
+ h2: { margin: "1.2em 0 0.8em !important" },
139
+ h3: { margin: "1em 0 0.6em !important" },
140
+ img: { "max-width": "100% !important", height: "auto !important" },
141
+ a: { color: "#2563eb !important", "text-decoration": "none !important" }
142
+ }), e.themes.select("default"), await Promise.race([u.ready, S]), u.locations.generate(1024).then(() => {
143
+ var m;
144
+ if (!u) return;
145
+ _ = u.locations.length();
146
+ const h = e == null ? void 0 : e.currentLocation(), a = ((m = h == null ? void 0 : h.start) == null ? void 0 : m.location) ?? 0;
147
+ b.value = a + 1, y.value = _;
148
+ }).catch(() => {
149
+ });
150
+ const r = await Promise.race([u.loaded.navigation, S]);
151
+ Array.isArray(r == null ? void 0 : r.toc) && (x.value = r.toc), await Promise.race([e.display(), S]), W.value = !1, F.ready(), b.value = 1, y.value = _ || 1, e.on("relocated", (h) => {
152
+ var J, K, Q;
153
+ const a = h;
154
+ if ((J = a == null ? void 0 : a.start) != null && J.cfi && (T = a.start.cfi), (K = a == null ? void 0 : a.start) != null && K.href) {
155
+ const N = a.start.href, O = [], Y = (ce) => {
156
+ for (const H of ce) {
157
+ const R = H.href.split("#")[0];
158
+ R && (N === R || N.endsWith("/" + R) || N.endsWith(R)) && O.push(H.href), H.subitems && Y(H.subitems);
159
+ }
160
+ };
161
+ Y(x.value), O.length === 1 && (P.value = O[0]);
162
+ }
163
+ const m = (Q = a == null ? void 0 : a.start) == null ? void 0 : Q.location;
164
+ typeof m == "number" && _ > 0 && (b.value = m + 1, y.value = _);
165
+ });
166
+ } catch (t) {
167
+ console.error(p.value("epub.load_failed") + ":", t), k.value = p.value("epub.load_failed"), W.value = !1, F.error(t);
168
+ }
169
+ }
170
+ };
171
+ let E = null, C = null, $ = { width: 0, height: 0 }, U = !0;
172
+ const ie = () => {
173
+ if (!(!l.value || !e)) {
174
+ if (e.resize(l.value.offsetWidth, l.value.offsetHeight), T)
175
+ try {
176
+ e.display(T);
177
+ } catch {
178
+ }
179
+ D();
180
+ }
181
+ }, ue = () => {
182
+ l.value && (E = new ResizeObserver(() => {
183
+ if (!l.value) return;
184
+ if (U) {
185
+ U = !1, $ = { width: l.value.offsetWidth, height: l.value.offsetHeight };
186
+ return;
187
+ }
188
+ const t = { width: l.value.offsetWidth, height: l.value.offsetHeight }, n = Math.abs($.width - t.width), o = Math.abs($.height - t.height);
189
+ n < 10 && o < 10 || ($ = t, C !== null && clearTimeout(C), C = window.setTimeout(ie, 350));
190
+ }), E.observe(l.value));
191
+ };
192
+ let i = null;
193
+ const B = () => {
194
+ var n;
195
+ if (!i) return;
196
+ const t = i;
197
+ if (t.scrollTop + t.clientHeight >= t.scrollHeight - 200)
198
+ try {
199
+ const o = e == null ? void 0 : e.manager;
200
+ (n = o == null ? void 0 : o.check) == null || n.call(o, 500, 500);
201
+ } catch {
202
+ }
203
+ }, D = () => {
204
+ i && (i.removeEventListener("scroll", B), i = null);
205
+ const t = () => {
206
+ var n;
207
+ i = ((n = l.value) == null ? void 0 : n.querySelector(".epub-container")) ?? null, i ? i.addEventListener("scroll", B, { passive: !0 }) : requestAnimationFrame(t);
208
+ };
209
+ requestAnimationFrame(t);
210
+ };
211
+ return pe(() => {
212
+ j(), ue(), D();
213
+ }), Z(() => A.url, (t) => {
214
+ t && j();
215
+ }), ve(() => {
216
+ E && E.disconnect(), C !== null && clearTimeout(C), i == null || i.removeEventListener("scroll", B), V();
217
+ }), (t, n) => (d(), g("div", Ee, [
218
+ k.value ? (d(), de(Me, {
219
+ key: 0,
220
+ message: k.value,
221
+ class: "vfp-absolute vfp-inset-0"
222
+ }, null, 8, ["message"])) : M("", !0),
223
+ W.value && !k.value ? (d(), g("div", $e, [
224
+ f("div", He, [
225
+ n[2] || (n[2] = f("div", { class: "vfp-renderer-spinner" }, null, -1)),
226
+ f("span", Re, L(q(p)("common.loading")), 1)
227
+ ])
228
+ ])) : M("", !0),
229
+ x.value.length > 0 ? (d(), g("div", {
230
+ key: 2,
231
+ class: "vfp-absolute vfp-inset-0 vfp-z-20 vfp-flex",
232
+ style: z({ opacity: s.value ? 1 : 0, pointerEvents: s.value ? "auto" : "none", transition: "opacity 0.3s" })
233
+ }, [
234
+ f("div", {
235
+ class: "vfp-w-72 vfp-h-full vfp-flex vfp-flex-col",
236
+ style: z({
237
+ maxWidth: "80%",
238
+ background: "rgba(0,0,0,0.9)",
239
+ backdropFilter: "blur(12px)",
240
+ borderRight: "1px solid rgba(255,255,255,0.1)",
241
+ boxShadow: "0 25px 50px -12px rgba(0,0,0,0.25)",
242
+ transform: s.value ? "translateX(0)" : "translateX(-100%)",
243
+ transition: "transform 0.3s ease"
244
+ })
245
+ }, [
246
+ f("div", Le, [
247
+ f("span", Ae, L(q(p)("toolbar.toc")), 1),
248
+ f("button", {
249
+ style: { color: "rgba(255,255,255,0.6)", background: "none", border: "none", cursor: "pointer", padding: "4px" },
250
+ onClick: n[0] || (n[0] = (o) => s.value = !1)
251
+ }, [
252
+ he(q(ke), { style: { width: "16px", height: "16px" } })
253
+ ])
254
+ ]),
255
+ f("div", Fe, [
256
+ (d(!0), g(G, null, ee(x.value, (o, S) => (d(), g(G, {
257
+ key: `${o.href}-${S}`
258
+ }, [
259
+ f("button", {
260
+ style: z({
261
+ width: "100%",
262
+ textAlign: "left",
263
+ padding: "8px 12px",
264
+ fontSize: "14px",
265
+ color: c(o.href) ? "white" : "rgba(255,255,255,0.7)",
266
+ fontWeight: c(o.href) ? "500" : "400",
267
+ background: c(o.href) ? "rgba(255,255,255,0.15)" : "none",
268
+ border: "none",
269
+ cursor: "pointer",
270
+ borderRadius: "4px",
271
+ overflow: "hidden",
272
+ textOverflow: "ellipsis",
273
+ whiteSpace: "nowrap",
274
+ display: "block",
275
+ transition: "all 0.15s"
276
+ }),
277
+ title: o.label,
278
+ onClick: (r) => X(o.href),
279
+ onMouseenter: (r) => !c(o.href) && (r.target.style.background = "rgba(255,255,255,0.1)"),
280
+ onMouseleave: (r) => !c(o.href) && (r.target.style.background = "none")
281
+ }, L(o.label.trim()), 45, Pe),
282
+ o.subitems && o.subitems.length > 0 ? (d(!0), g(G, { key: 0 }, ee(o.subitems, (r, h) => (d(), g("button", {
283
+ key: `${r.href}-${h}`,
284
+ style: z({
285
+ width: "100%",
286
+ textAlign: "left",
287
+ padding: "8px 12px 8px 28px",
288
+ fontSize: "13px",
289
+ color: c(r.href) ? "white" : "rgba(255,255,255,0.6)",
290
+ fontWeight: c(r.href) ? "500" : "400",
291
+ background: c(r.href) ? "rgba(255,255,255,0.15)" : "none",
292
+ border: "none",
293
+ cursor: "pointer",
294
+ borderRadius: "4px",
295
+ overflow: "hidden",
296
+ textOverflow: "ellipsis",
297
+ whiteSpace: "nowrap",
298
+ display: "block",
299
+ transition: "all 0.15s"
300
+ }),
301
+ title: r.label,
302
+ onClick: (a) => X(r.href),
303
+ onMouseenter: (a) => !c(r.href) && (a.target.style.background = "rgba(255,255,255,0.1)"),
304
+ onMouseleave: (a) => !c(r.href) && (a.target.style.background = "none")
305
+ }, L(r.label.trim()), 45, Be))), 128)) : M("", !0)
306
+ ], 64))), 128))
307
+ ])
308
+ ], 4),
309
+ f("div", {
310
+ class: "vfp-flex-1",
311
+ style: z({ background: s.value ? "rgba(0,0,0,0.3)" : "transparent", transition: "background 0.3s" }),
312
+ onClick: n[1] || (n[1] = (o) => s.value = !1)
313
+ }, null, 4)
314
+ ], 4)) : M("", !0),
315
+ k.value ? M("", !0) : (d(), g("div", {
316
+ key: 3,
317
+ ref_key: "viewerRef",
318
+ ref: l,
319
+ class: "vfp-h-full vfp-bg-surface-toolbar",
320
+ style: z({
321
+ width: w.value ? "100%" : `${De}px`,
322
+ maxWidth: "100%",
323
+ transition: "width 0.3s ease",
324
+ boxShadow: "0 1px 3px rgba(0,0,0,0.12)",
325
+ overflow: "hidden"
326
+ })
327
+ }, null, 4))
328
+ ]));
329
+ }
330
+ });
331
+ export {
332
+ je as default
333
+ };