1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdflib-vendor-D5hwEezb.js","assets/react-vendor-DbVP0aMU.js"])))=>i.map(i=>d[i]); 2import{_}from"./pdf-vendor-D7HrI6pR.js";import{m as L,j as e,X as C,l as I,F as S}from"./index-C0SOoweL.js";import{r as o}from"./react-vendor-DbVP0aMU.js";import{T as G}from"./ToolUpload-CBkNWrrX.js";import{l as O,f as E}from"./download-DFhLbSJS.js";import{G as T}from"./grip-vertical-Bxj_CHuE.js";import{D as W}from"./download-BBPfn1tx.js";import"./upload-cloud-D625IgnK.js";function Q(){const[p,m]=o.useState([]),[v,N]=o.useState(!1),[u,x]=o.useState(null),[D,f]=o.useState(""),h=o.useRef(null),{toast:P}=L(),k=o.useCallback(async t=>{if(t.length!==0){N(!0),f(""),x(null);try{const{PDFDocument:a}=await _(async()=>{const{PDFDocument:g}=await import("./pdflib-vendor-D5hwEezb.js");return{PDFDocument:g}},__vite__mapDeps([0,1])),r=await a.create();for(const g of t){const R=URL.createObjectURL(g),s=await O(R);URL.revokeObjectURL(R);const l=document.createElement("canvas");l.width=s.naturalWidth,l.height=s.naturalHeight,l.getContext("2d").drawImage(s,0,0);let b;if(g.type==="image/png"){const w=await new Promise((y,i)=>{l.toBlob(d=>{if(!d){i(new Error("Failed to convert"));return}d.arrayBuffer().then(j=>y(new Uint8Array(j))).catch(i)},"image/png")});b=await r.embedPng(w)}else{const w=await new Promise((y,i)=>{l.toBlob(d=>{if(!d){i(new Error("Failed"));return}d.arrayBuffer().then(j=>y(new Uint8Array(j))).catch(i)},"image/jpeg",.92)});b=await r.embedJpg(w)}r.addPage([s.naturalWidth,s.naturalHeight]).drawImage(b,{x:0,y:0,width:s.naturalWidth,height:s.naturalHeight})}const n=await r.save(),c=new Blob([n],{type:"application/pdf"});x(c),P("success","Done",`${t.length} image${t.length>1?"s":""} converted to PDF`)}catch{f("Failed to convert images. Please try different files.")}finally{N(!1)}}},[P]),F=t=>{m(t),k(t)},B=(t,a)=>{m(r=>{const n=[...r],[c]=n.splice(t,1);return n.splice(a,0,c),n})},U=()=>{if(!u)return;const t=document.createElement("a");t.href=URL.createObjectURL(u),t.download="converted.pdf",t.click()};return e.jsx("div",{className:"mx-auto max-w-2xl space-y-5",children:p.length===0?e.jsx(G,{accept:"image/*",multiple:!0,onFiles:F,label:"Drop images here or click to browse â JPG, PNG, WEBP"}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Drag rows to reorder pages"}),e.jsx("div",{className:"space-y-2",children:p.map((t,a)=>e.jsxs("div",{draggable:!0,onDragStart:()=>h.current=a,onDragOver:r=>r.preventDefault(),onDrop:()=>{h.current!==null&&B(h.current,a)},className:"flex cursor-grab items-center gap-3 rounded-xl border border-border bg-card px-4 py-3 active:cursor-grabbing",children:[e.jsx(T,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:`flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-primary/10 3 text-xs font-semibold text-primary`,children:a+1}),e.jsx("span",{className:"flex-1 truncate text-sm font-medium text-foreground",children:t.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:E(t.size)}),e.jsx("button",{onClick:()=>{const r=p.filter((n,c)=>c!==a);m(r),r.length===0?x(null):k(r)},className:"rounded-lg p-1.5 text-muted-foreground transition-colors hover:bg-secondary hover:text-foreground","aria-label":"Remove page",children:e.jsx(C,{className:"h-4 w-4"})})]},a))}),D&&e.jsx("p",{className:"rounded-xl bg-error/10 px-4 py-3 text-sm text-error",children:D}),v&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(I,{className:"h-5 w-5 animate-spin"})," Generating PDFâ¦"]}),u&&!v&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3 rounded-xl border border-border bg-card px-4 py-3",children:[e.jsx(S,{className:"h-5 w-5 shrink-0 text-success"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"converted.pdf"}),e.jsxs("p",{className:"text-xs text-success",children:[E(u.size)," â ready to download"]})]})]}),e.jsxs("button",{onClick:U,className:`inline-flex w-full items-center justify-center gap-2 rounded-xl bg-primary px-4 py-3.5 4 text-sm font-semibold text-primary-foreground transition-colors hover:bg-primary-600`,children:[e.jsx(W,{className:"h-4 w-4"})," Download PDF"]})]}),e.jsx("button",{onClick:()=>{m([]),x(null),f("")},className:"text-xs text-muted-foreground hover:text-foreground",children:"Start over"})]})})}export{Q as default};
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.