vue-files-preview-inno
Version:
A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.
3 lines (2 loc) • 1.95 kB
JavaScript
;const r=require("vue"),v=require("../../../../node_modules/pptx-preview/dist/pptx-preview.es.js"),C=require("../../utils/utils.js"),T=r.defineComponent({__name:"index",props:{file:{default:()=>null},url:{default:()=>null},name:{}},emits:["rendered","error"],setup(_,{emit:g}){const f=_,u=g,i=r.ref(null);let l=null,o=null,c=0,p=0,s=null,a=null;function h(){var d;const e=i.value;if(!e)return 960;const t=e.clientWidth,n=((d=e.parentElement)==null?void 0:d.clientWidth)||0;return t>100?t:n>100?n:960}function m(){if(l){try{l.destroy()}catch{}l=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.init(t,{width:100,height:100,mode:"slide"});await n.preview(e);const d=n.slideCount;return n.destroy(),d}finally{document.body.removeChild(t)}}async function w(){if(!i.value||!o)return;m();const e=h();p=e;const t=Math.floor(e*9/16);try{c===0&&(c=await x(o)),l=v.init(i.value,{width:e,height:t*c,mode:"list"}),await l.preview(o),u("rendered")}catch(n){u("error",n instanceof Error?n:new Error("PPT render failed"))}}function B(){const e=h();e>0&&Math.abs(e-p)>=10&&o&&c>0&&(a&&clearTimeout(a),a=setTimeout(()=>{w()},300))}r.onMounted(()=>{i.value&&(s=new ResizeObserver(()=>B()),s.observe(i.value))}),r.onUnmounted(()=>{s==null||s.disconnect(),a&&clearTimeout(a),m()});async function y(e){e instanceof ArrayBuffer?o=e:typeof e=="string"&&(o=await(await fetch(e)).arrayBuffer()),c=0,await w()}return r.watch(()=>f.file,e=>{e&&C.getFileRenderByFile(e).then(y).catch(t=>u("error",t))},{immediate:!0}),r.watch(()=>f.url,e=>{e&&!f.file&&C.getFileRenderByUrl(e).then(y).catch(t=>u("error",t))},{immediate:!0}),(e,t)=>(r.openBlock(),r.createElementBlock("div",{ref_key:"pptContainer",ref:i,class:"ppt-preview"},null,512))}});module.exports=T;
//# sourceMappingURL=index.vue2.js.map