PdfPreviewModal-Bxccllsw.js 5.4 KB

12
  1. const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-CaTYEs2g.js","assets/index-82a1Eqef.js","assets/chunk-aKtaBQYM.js","assets/index-DDT9pHR2.css"])))=>i.map(i=>d[i]);
  2. import{i as e}from"./chunk-aKtaBQYM.js";import{a as t,c as n,d as r,f as i,h as a,i as o,m as s,n as c,o as l,p as u,r as d,s as f,t as p,u as m}from"./index-82a1Eqef.js";var h=e(a(),1),g=i();function _(e){let t=document.createElement(`canvas`);t.width=256,t.height=256;let n=t.getContext(`2d`);if(!n)return Promise.resolve(null);n.fillStyle=`#ffffff`,n.fillRect(0,0,256,256);let r=256/Math.max(e.width,e.height),i=e.width*r,a=e.height*r;return n.drawImage(e,(256-i)/2,(256-a)/2,i,a),new Promise(e=>t.toBlob(e,`image/png`))}function v({libraryFileId:e,filename:i,fileSize:a,onClose:v,onSnapshot:y}){let{t:b}=s(),x=(0,h.useRef)(null),S=(0,h.useRef)(null),C=(0,h.useRef)(null),w=(0,h.useRef)(!1),T=(0,h.useRef)(y);(0,h.useEffect)(()=>{T.current=y});let[E,D]=(0,h.useState)(null),[O,k]=(0,h.useState)(1),[A,j]=(0,h.useState)(1),[M,N]=(0,h.useState)(null),[P,F]=(0,h.useState)(!0);(0,h.useEffect)(()=>{let e=e=>{e.key===`Escape`&&v()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[v]),(0,h.useEffect)(()=>{let t=!1,n=null;if(D(null),N(null),k(1),F(!0),a>52428800){N(b(`fileManager.preview.tooLarge`,{size:p(a)})),F(!1);return}let r={},i=d();return i&&(r.Authorization=`Bearer ${i}`),(async()=>{let i=await fetch(c.getLibraryFileDownloadUrl(e),{headers:r});if(!i.ok)throw Error(`HTTP ${i.status}`);let a=await i.arrayBuffer(),o=await u(()=>import(`./pdf-CaTYEs2g.js`),__vite__mapDeps([0,1,2,3]));o.GlobalWorkerOptions.workerSrc||(o.GlobalWorkerOptions.workerSrc=(await u(async()=>{let{default:e}=await import(`./pdf.worker.min-DpOxPwGP.js`);return{default:e}},[])).default),n=o.getDocument({data:new Uint8Array(a)});let s=await n.promise;t||D(s)})().catch(()=>{t||(N(b(`fileManager.preview.error`)),F(!1))}),()=>{t=!0,C.current?.cancel(),C.current=null,n?.destroy()}},[e,a,b]),(0,h.useEffect)(()=>{if(!E)return;let e=!1;return F(!0),(async()=>{let t=await E.getPage(O),n=S.current,r=x.current;if(!n||!r||e)return;let i=t.getViewport({scale:1}),a=Math.max((r.clientWidth-32)/i.width,.1),o=Math.min(window.devicePixelRatio||1,2),s=t.getViewport({scale:a*A*o});n.width=s.width,n.height=s.height,n.style.width=`${s.width/o}px`,n.style.height=`${s.height/o}px`,C.current?.cancel();let c=t.render({canvas:n,viewport:s});if(C.current=c,await c.promise,!e&&(F(!1),O===1&&T.current&&!w.current)){w.current=!0;let t=await _(n);t&&!e&&T.current?.(t)}})().catch(t=>{!e&&t?.name!==`RenderingCancelledException`&&(N(b(`fileManager.preview.error`)),F(!1))}),()=>{e=!0}},[E,O,A,b]);let I=E?.numPages??0;return(0,g.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,g.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-5xl h-[85vh] border border-bambu-dark-tertiary flex flex-col`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,g.jsx)(n,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,g.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:i})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[E&&I>1&&(0,g.jsxs)(`div`,{className:`flex items-center gap-1 mr-2`,children:[(0,g.jsx)(`button`,{onClick:()=>k(e=>Math.max(1,e-1)),disabled:O<=1,className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":b(`fileManager.preview.prevPage`),children:(0,g.jsx)(m,{className:`w-4 h-4`})}),(0,g.jsx)(`span`,{className:`text-sm text-bambu-gray whitespace-nowrap`,children:b(`fileManager.preview.page`,{current:O,total:I})}),(0,g.jsx)(`button`,{onClick:()=>k(e=>Math.min(I,e+1)),disabled:O>=I,className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":b(`fileManager.preview.nextPage`),children:(0,g.jsx)(r,{className:`w-4 h-4`})})]}),E&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`button`,{onClick:()=>j(e=>Math.max(.4,e*.8)),className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors`,"aria-label":b(`fileManager.preview.zoomOut`),children:(0,g.jsx)(o,{className:`w-4 h-4`})}),(0,g.jsx)(`button`,{onClick:()=>j(e=>Math.min(4,e*1.25)),className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors`,"aria-label":b(`fileManager.preview.zoomIn`),children:(0,g.jsx)(t,{className:`w-4 h-4`})})]}),(0,g.jsx)(`button`,{onClick:v,className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors`,"aria-label":b(`common.close`),children:(0,g.jsx)(l,{className:`w-5 h-5`})})]})]}),(0,g.jsxs)(`div`,{ref:x,className:`relative flex-1 min-h-0 overflow-auto bg-bambu-dark rounded-b-lg p-4`,children:[M?(0,g.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,g.jsx)(`p`,{className:`text-bambu-gray text-center`,children:M})}):(0,g.jsx)(`div`,{className:`flex justify-center min-w-fit`,children:(0,g.jsx)(`canvas`,{ref:S,className:`shadow-lg`})}),!M&&P&&(0,g.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,g.jsx)(f,{className:`w-8 h-8 text-bambu-green animate-spin`})})]})]})})}export{v as PdfPreviewModal};