UNPKG

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.89 kB
import { defineComponent as T, ref as _, onMounted as b, onUnmounted as E, watch as w, openBlock as M, createElementBlock as P } from "vue"; import { init as v } from "../../../../node_modules/pptx-preview/dist/pptx-preview.es.mjs"; import { getFileRenderByFile as R, getFileRenderByUrl as W } from "../../utils/utils.mjs"; const D = /* @__PURE__ */ T({ __name: "index", props: { file: { default: () => null }, url: { default: () => null }, name: {} }, emits: ["rendered", "error"], setup(C, { emit: g }) { const d = C, s = g, i = _(null); let o = null, r = null, l = 0, f = 0, a = null, c = null; function p() { var u; const e = i.value; if (!e) return 960; const t = e.clientWidth, n = ((u = e.parentElement) == null ? void 0 : u.clientWidth) || 0; return t > 100 ? t : n > 100 ? n : 960; } function m() { if (o) { try { o.destroy(); } catch { } o = null; } i.value && (i.value.innerHTML = ""); } async function x(e) { const t = document.createElement("div"); t.style.cssText = "position:absolute;left:-9999px;top:-9999px;visibility:hidden", document.body.appendChild(t); try { const n = v(t, { width: 100, height: 100, mode: "slide" }); await n.preview(e); const u = n.slideCount; return n.destroy(), u; } finally { document.body.removeChild(t); } } async function h() { if (!i.value || !r) return; m(); const e = p(); f = e; const t = Math.floor(e * 9 / 16); try { l === 0 && (l = await x(r)), o = v(i.value, { width: e, height: t * l, mode: "list" }), await o.preview(r), s("rendered"); } catch (n) { s("error", n instanceof Error ? n : new Error("PPT render failed")); } } function B() { const e = p(); e > 0 && Math.abs(e - f) >= 10 && r && l > 0 && (c && clearTimeout(c), c = setTimeout(() => { h(); }, 300)); } b(() => { i.value && (a = new ResizeObserver(() => B()), a.observe(i.value)); }), E(() => { a == null || a.disconnect(), c && clearTimeout(c), m(); }); async function y(e) { e instanceof ArrayBuffer ? r = e : typeof e == "string" && (r = await (await fetch(e)).arrayBuffer()), l = 0, await h(); } return w( () => d.file, (e) => { e && R(e).then(y).catch((t) => s("error", t)); }, { immediate: !0 } ), w( () => d.url, (e) => { e && !d.file && W(e).then(y).catch((t) => s("error", t)); }, { immediate: !0 } ), (e, t) => (M(), P("div", { ref_key: "pptContainer", ref: i, class: "ppt-preview" }, null, 512)); } }); export { D as default }; //# sourceMappingURL=index.vue2.mjs.map