vue-files-preview-inno
Version:
A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.
59 lines (58 loc) • 1.84 kB
JavaScript
import { defineComponent as s, ref as u, watch as i, shallowRef as c, onMounted as f, onBeforeUnmount as m, openBlock as p, createElementBlock as R, createElementVNode as U } from "vue";
import { getFileRenderByFile as _, getFileRenderByUrl as h } from "../../utils/utils.mjs";
const L = { class: "video-preview web-full-screen" }, k = /* @__PURE__ */ s({
__name: "index",
props: {
file: { default: () => null },
url: { default: () => null },
name: {}
},
emits: ["rendered", "error"],
setup(v, { emit: d }) {
const n = v, t = d, e = u(null), o = u(!1);
i(
() => n.file,
(a) => {
a && (e.value && !o.value && URL.revokeObjectURL(e.value), o.value = !1, _(a).then((r) => {
e.value = r, l.value.src = e.value;
}).catch((r) => {
t("error", r);
}));
},
{ immediate: !0 }
), i(
() => n.url,
(a) => {
a && !n.file && (e.value && !o.value && URL.revokeObjectURL(e.value), o.value = !0, h(a).then((r) => {
e.value = r, l.value.src = e.value;
}).catch((r) => {
t("error", r);
}));
},
{ immediate: !0 }
);
const l = c(null);
return f(() => {
l.value.addEventListener("loadedmetadata", () => {
l.value.play(), t("rendered");
}), l.value.addEventListener("error", () => {
t("error", new Error("Video load failed"));
});
}), m(() => {
l.value.pause(), e.value && !o.value && URL.revokeObjectURL(e.value);
}), (a, r) => (p(), R("div", L, [
U("video", {
ref_key: "videoPreviewRef",
ref: l,
class: "player-video-main",
controls: "",
autoplay: "",
crossorigin: "anonymous"
}, null, 512)
]));
}
});
export {
k as default
};
//# sourceMappingURL=index.vue2.mjs.map