vue-files-preview-inno
Version:
A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.
97 lines (96 loc) • 2.95 kB
JavaScript
import { defineComponent as P, ref as n, watch as p, openBlock as k, createElementBlock as K, normalizeStyle as B, createElementVNode as c } from "vue";
import "../../../../node_modules/epubjs/src/book.mjs";
import "../../../../node_modules/@xmldom/xmldom/lib/dom.mjs";
import "../../../../node_modules/@xmldom/xmldom/lib/dom-parser.mjs";
import "../../../../node_modules/epubjs/src/rendition.mjs";
import "../../../../node_modules/epubjs/src/contents.mjs";
import "../../../../node_modules/epubjs/src/layout.mjs";
import D from "../../../../node_modules/epubjs/src/epub.mjs";
import { getFileRenderByFile as A, getFileRenderByUrl as E } from "../../utils/utils.mjs";
import { onKeyStroke as f } from "../../../../node_modules/@vueuse/core/dist/index.mjs";
const j = /* @__PURE__ */ P({
__name: "index",
props: {
file: { default: () => null },
url: { default: () => null },
name: {},
width: { default: () => "100%" },
height: { default: () => "100%" }
},
emits: ["rendered", "error"],
setup(i, { emit: m }) {
const u = i, a = m, h = n(), d = n(), o = n(1), v = n(), w = n(!1), r = n(), l = n();
function s(e) {
r.value = D(e), l.value = r.value.renderTo("epub-viewer", {
width: "100%",
height: "calc(100vh - 80px)",
flow: "scrolled",
allowScriptedContent: !0
}), r.value.ready.then(() => {
h.value = r.value.navigation, d.value = r.value.locations, w.value = !0, v.value = d.value.length(), l.value.display(), a("rendered");
}).catch((t) => {
a("error", t);
});
}
p(
() => u.file,
(e) => {
e && A(e).then((t) => {
s(t);
}).catch((t) => {
a("error", t);
});
},
{ immediate: !0 }
), p(
() => u.url,
(e) => {
e && !u.file && E(e).then((t) => {
s(t);
}).catch((t) => {
a("error", t);
});
},
{ immediate: !0 }
);
function b() {
l.value && (l.value.prev(), o.value--, o.value < 1 && (o.value = 1));
}
function y() {
l.value && (l.value.next(), o.value++, o.value > v.value && (o.value = v.value));
}
function g(e) {
e.preventDefault();
}
function x(e) {
e.preventDefault();
}
return f("ArrowLeft", () => {
b();
}), f("ArrowRight", () => {
y();
}), (e, t) => (k(), K("div", {
class: "epub-preview epub-box",
style: B({ width: i.width, height: i.height })
}, [
c("button", {
class: "btn",
style: { display: "none" },
onKeydown: g
}, " Prev ", 32),
t[0] || (t[0] = c("div", {
id: "epub-viewer",
class: "epub-viewer"
}, null, -1)),
c("button", {
class: "btn",
style: { display: "none" },
onKeydown: x
}, " Next ", 32)
], 4));
}
});
export {
j as default
};
//# sourceMappingURL=index.vue2.mjs.map