PageSourceSearch

https://klasoo.com/assets/PDFViewer-bKD1l7ed.js

js klasoo.com collected 2026-09-30 06:30:41 UTC 5,790 bytes, 1 lines download raw bytes

1import{r,j as t}from"./vendor-react-BtGqQFvK.js";import{D as H,P as $,p as z,G as X}from"./vendor-pdfjs-DR9d1ngv.js";import{B as j,gd as Z,ge as _,aY as G,l as I}from"./app-shell-CMj3qzLx.js";import{parseStorageUrl as K,signPath as V}from"./privateStorageUrl-BI_-1ez0.js";import{u as q}from"./vendor-i18n-Duo0qcql.js";import"./vendor-utils-BPqL1lCz.js";import"./vendor-charts-DxRerMpt.js";import"./vendor-ui-zUh5tm1d.js";import"./vendor-supabase-PhdYWwdx.js";import"./vendor-query-CzlW6vM0.js";import"./vendor-motion-D4fhTsRL.js";X.workerSrc=z;const de=({url:l,title:P,allowDownload:T=!0,onLastPageReached:N})=>{const{t:i}=q(),[f,R]=r.useState(0),[u,m]=r.useState(1),[J,C]=r.useState(.25),v=r.useRef(!1),[y,g]=r.useState(null),[M,w]=r.useState(!0),[S,b]=r.useState(null),p=r.useRef(null),E=r.useRef(!1),o=r.useRef(null),L=r.useCallback(()=>{if(E.current||!p.current||f<=0)return;const e=p.current;e.scrollHeight-e.scrollTop-e.clientHeight<50&&(E.current=!0,N?.())},[f,N]),k=e=>{const s=e[0].clientX-e[1].clientX,a=e[0].clientY-e[1].clientY;return Math.hypot(s,a)},U=r.useCallback(e=>{e.touches.length===2&&(o.current={startDist:k(e.touches),startScale:u})},[u]);r.useCallback(e=>{if(e.touches.length===2&&o.current){e.preventDefault();const a=k(e.touches)/o.current.startDist,h=Math.min(4,Math.max(.25,o.current.startScale*a));m(h)}},[]);const F=r.useCallback(e=>{e.touches.length<2&&(o.current=null)},[]),A=r.useCallback(e=>{(e.ctrlKey||e.metaKey)&&(e.preventDefault(),m(s=>Math.min(4,Math.max(.25,s-e.deltaY*.003))))},[]);r.useEffect(()=>{const e=p.current;if(!e)return;const s=a=>{if(a.touches.length===2&&o.current){a.preventDefault();const h=a.touches[0].clientX-a.touches[1].clientX,n=a.touches[0].clientY-a.touches[1].clientY,x=Math.hypot(h,n)/o.current.startDist,d=Math.min(4,Math.max(.25,o.current.startScale*x));m(d)}};return e.addEventListener("touchmove",s,{passive:!1}),()=>e.removeEventListener("touchmove",s)},[]),r.useEffect(()=>{E.current=!1},[l]),r.useEffect(()=>{let e=null,s=!1;const a=async n=>{const c=await fetch(n);if(!c.ok)throw new Error(`HTTP ${c.status}: ${c.statusText}`);if((c.headers.get("content-type")||"").includes("application/json")){const d=await c.json().catch(()=>({}));throw new Error(d.message||`HTTP ${c.status}`)}return c.blob()};return(async()=>{w(!0),b(null),g(null);try{let n;try{n=await a(l)}catch(x){const d=K(l);if(!d)throw x;const D=await V(d.bucket,d.path);if(!D)throw x;n=await a(D)}if(s)return;const c=URL.createObjectURL(n);e=c,g(c)}catch(n){if(s)return;I.error("PDF fetch error",n instanceof Error?n:new Error(String(n))),b(n instanceof Error?n.message:"Error loading PDF")}finally{s||w(!1)}})(),()=>{s=!0,e&&URL.revokeObjectURL(e)}},[l]);async function O(e){R(e.numPages);try{const a=(await e.getPage(1)).getViewport({scale:1}),h=p.current?.clientWidth??800,n=Math.max(.25,Math.min(1,(h-32)/a.width));C(n),v.current||m(n)}catch{}}const B=()=>{v.current=!0,m(e=>Math.min(e+.2,4))},W=()=>{v.current=!0,m(e=>Math.max(e-.2,.25))},Y=()=>{const e=document.createElement("a");e.href=y||l,e.download=P||"document.pdf",e.target="_blank",document.body.appendChild(e),e.click(),document.body.removeChild(e)};return M?t.jsx("div",{className:"flex items-center justify-center p-8 bg-card border rounded-lg",children:t.jsx("div",{className:"text-muted-foreground",children:i("pdf.loading","Cargando PDF...")})}):S&&!y?t.jsxs("div",{className:"flex flex-col items-center justify-center p-8 bg-card border rounded-lg gap-3",children:[t.jsxs("div",{className:"text-destructive",children:[i("pdf.loadError","Error loading PDF"),": ",S]}),t.jsx(j,{variant:"outline",size:"sm",onClick:()=>{b(null),w(!0),g(null),fetch(l).then(e=>{if(!e.ok)throw new Error(`HTTP ${e.status}`);return e.blob()}).then(e=>{g(URL.createObjectURL(e))}).catch(e=>{b(e instanceof Error?e.message:"Error")}).finally(()=>w(!1))},children:i("common.retry","Reintentar")})]}):t.jsxs("div",{className:"flex flex-col w-full bg-card border rounded-lg overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 p-2 sm:p-3 border-b bg-muted/30 shrink-0",children:[t.jsxs("span",{className:"text-xs sm:text-sm font-medium whitespace-nowrap",children:[f," ",f===1?i("pdf.page","página"):i("pdf.pages","páginas")]}),t.jsxs("div",{className:"flex items-center gap-1 sm:gap-2",children:[t.jsx(j,{variant:"ghost",size:"sm",onClick:W,disabled:u<=.25,className:"h-8 w-8 p-0",children:t.jsx(Z,{className:"h-3.5 w-3.5"})}),t.jsxs("span",{className:"text-xs sm:text-sm font-medium whitespace-nowrap min-w-[40px] sm:min-w-[60px] text-center",children:[Math.round(u*100),"%"]}),t.jsx(j,{variant:"ghost",size:"sm",onClick:B,disabled:u>=4,className:"h-8 w-8 p-0",children:t.jsx(_,{className:"h-3.5 w-3.5"})}),T&&t.jsx(j,{variant:"ghost",size:"sm",onClick:Y,className:"h-8 w-8 p-0",children:t.jsx(G,{className:"h-3.5 w-3.5"})})]})]}),t.jsx("div",{ref:p,onScroll:L,onTouchStart:U,onTouchEnd:F,onWheel:A,className:"campus-pdf-scroll h-[88vh] overflow-auto bg-muted/10 p-2 sm:p-3",style:{touchAction:"pan-x pan-y",overscrollBehavior:"contain"},children:t.jsx("div",{className:"flex flex-col items-center gap-4 w-max min-w-full mx-auto",children:t.jsx(H,{file:y||l,onLoadSuccess:O,loading:t.jsx("div",{className:"flex items-center justify-center p-8",children:t.jsx("div",{className:"text-muted-foreground",children:i("pdf.loading","Cargando PDF...")})}),error:t.jsx("div",{className:"flex items-center justify-center p-8",children:t.jsx("div",{className:"text-destructive",children:i("pdf.loadError","Error loading PDF")})}),children:Array.from(new Array(f),(e,s)=>t.jsx("div",{className:"mb-4 shadow-lg bg-card",children:t.jsx($,{pageNumber:s+1,scale:u,renderTextLayer:!0,renderAnnotationLayer:!0,className:"mx-auto"})},`page_${s+1}`))})})})]})};export{de as PDFViewer};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.