lms/public/build/assets/document-viewer-ddYP-zYy.js
2025-12-15 12:26:23 +01:00

2 lines
3.0 KiB
JavaScript

import{u as v,r as N,j as e,l as y,aT as p,v as x}from"./vendor-BKmmeuxg.js";const F=({src:t,fileName:c,className:h,...f})=>{const{props:g}=v(),{translate:w}=g,{frontend:s}=w,i=N.useMemo(()=>{const n=o=>{var l;return((l=o.split("?")[0].split(".").pop())==null?void 0:l.toLowerCase())||""},d=o=>{const m=["pdf"],u=["doc","docx","xls","xlsx","ppt","pptx","odt","ods","odp"],l=["jpg","jpeg","png","gif","bmp","webp","svg"],j=["txt","rtf","csv"];return m.includes(o)?"pdf":u.includes(o)?"office":l.includes(o)?"image":j.includes(o)?"text":"unsupported"},r=n(t),a=d(r);return{extension:r,type:a}},[t]),b=()=>{const n="h-full max-h-[calc(100vh-60px)] min-h-[80vh] w-full";switch(i.type){case"pdf":return e.jsx("iframe",{src:t,width:"100%",height:"100%",allowFullScreen:!0,title:s.pdf_document,className:n});case"office":{const d=`https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(t)}`;return e.jsxs("div",{className:"relative h-full",children:[e.jsx("iframe",{src:d,width:"100%",height:"100%",allowFullScreen:!0,title:`${i.extension.toUpperCase()} Document`,className:n,onError:()=>{const r=`https://docs.google.com/gview?url=${encodeURIComponent(t)}&embedded=true`,a=document.querySelector('iframe[src*="officeapps.live.com"]');a&&(a.src=r)}}),e.jsxs("div",{className:"absolute top-2 right-2 flex gap-2",children:[e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"bg-white/90 hover:bg-white p-2 rounded-md shadow-sm transition-colors",title:s.open_in_new_tab,children:e.jsx(p,{className:"w-4 h-4 text-gray-600"})}),e.jsx("a",{href:t,download:c,className:"bg-white/90 hover:bg-white p-2 rounded-md shadow-sm transition-colors",title:s.download_document,children:e.jsx(x,{className:"w-4 h-4 text-gray-600"})})]})]})}case"image":return e.jsx("div",{className:"flex items-center justify-center h-full bg-gray-50",children:e.jsx("img",{src:t,alt:c||s.document,className:"max-w-full max-h-full object-contain"})});case"text":return e.jsx("iframe",{src:t,width:"100%",height:"100%",title:s.text_document,className:n});default:return e.jsxs("div",{className:"flex flex-col items-center justify-center h-full bg-gray-50 text-gray-600",children:[e.jsx(y,{className:"w-16 h-16 mb-4 text-gray-400"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:s.unsupported_document_format}),e.jsx("p",{className:"text-sm text-center mb-6 max-w-md",children:s.document_format_cannot_be_previewed.replace("{extension}",i.extension)}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors",children:[e.jsx(p,{className:"w-4 h-4"}),s.open_in_new_tab_button]}),e.jsxs("a",{href:t,download:c,className:"inline-flex items-center gap-2 px-4 py-2 bg-gray-600 text-white rounded-md hover:bg-gray-700 transition-colors",children:[e.jsx(x,{className:"w-4 h-4"}),s.download]})]})]})}};return e.jsx("div",{className:`h-full ${h||""}`,...f,children:b()})};export{F as default};