1import{r as o,j as e}from"./vendor-react-C_xdI0Ng.js";import{u as P,A as W,Q as L}from"./index-DbFRh42P.js";function j(r){return Array.from(new Uint8Array(r)).map(i=>i.toString(16).padStart(2,"0")).join("")}function Q({inputFiles:r,onBack:i}){const{runtime:p}=P(),[a,n]=o.useState("idle"),[x,l]=o.useState(""),[f,b]=o.useState(null),[v,k]=o.useState(""),[S,h]=o.useState(!1);o.useEffect(()=>{let t=!0;if(r.length===0){n("error"),l("No files provided to share");return}return(async()=>{var y;try{n("encrypting"),l("Encrypting document locally...");const U=await(await(await p.vfs.read(r[0])).getBlob()).arrayBuffer();if(!t)return;const g=await window.crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),u=window.crypto.getRandomValues(new Uint8Array(12)),B=await window.crypto.subtle.encrypt({name:"AES-GCM",iv:u},g,U);if(!t)return;n("uploading"),l("Uploading encrypted payload...");const E=await window.crypto.subtle.exportKey("raw",g),A=j(E),R=j(u.buffer),z=new Blob([B],{type:"application/octet-stream"}),m=new FormData;m.append("file",z,"secured.pdf");const d=await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:m});if(!d.ok)throw new Error(`Upload server responded with code ${d.status}`);const c=await d.json();if(c.status!=="success"||!((y=c.data)!=null&&y.url))throw new Error("Upload failed to return a valid sharing URL");const D=c.data.url.replace("https://tmpfiles.org/","https://tmpfiles.org/dl/"),w=`${`${window.location.origin}${W}/share`}#url=${encodeURIComponent(D)}&key=${A}&iv=${R}`,T=await L.toDataURL(w,{width:280,margin:2,color:{dark:"#142028",light:"#ffffff"}});t&&(k(w),b(T),n("ready"))}catch(s){console.error("Failed to encrypt/upload file:",s),t&&(n("error"),l((s==null?void 0:s.message)||"Failed to securely upload the PDF."))}})(),()=>{t=!1}},[r,p.vfs]);const C=async()=>{try{await navigator.clipboard.writeText(v),h(!0),setTimeout(()=>h(!1),2e3)}catch(t){console.error("Failed to copy link:",t)}};return e.jsxs("div",{className:"tool-config-root",style:{display:"flex",flexDirection:"column",alignItems:"center",textAlign:"center",width:"100%",maxWidth:"480px",margin:"0 auto",padding:"24px 16px"},children:[e.jsx("h3",{style:{fontSize:"18px",fontWeight:700,marginBottom:"8px",color:"#142028"},children:"Share PDF to Phone"}),e.jsx("p",{className:"tool-config-copy",style:{fontSize:"13px",color:"#636c72",marginBottom:"24px",lineHeight:1.5},children:"Encrypts your document end-to-end and uploads it to a temporary cloud. The encryption key resides in the QR-code itself and is never stored on the server."}),e.jsxs("div",{className:"tool-config-card",style:{width:"100%",padding:"24px",background:"#ffffff",border:"1px solid #e9e9e7",borderRadius:"12px",boxShadow:"0 4px 12px rgba(0,0,0,0.02)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"300px"},children:[(a==="encrypting"||a==="uploading")&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"16px"},children:[e.jsx("div",{className:"wz-spinner",style:{width:"36px",height:"36px",border:"3px solid #e9e9e7",borderTopColor:"#2383e2",borderRadius:"50%",animation:"spin 1s linear infinite"}}),e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"#142028"},children:x}),e.jsx("div",{style:{fontSize:"12px",color:"#888"},children:"This might take a few seconds depending on the file size."})]}),a==="error"&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",color:"#e03e3e"},children:[e.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),e.jsxs("div",{style:{fontSize:"14px",fontWeight:600},children:["Error: ",x]}),e.jsx("button",{className:"btn-ghost",style:{marginTop:"12px",color:"#2383e2"},onClick:i,children:"Try another file"})]}),a==="ready"&&f&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",width:"100%"},children:[e.jsx("div",{style:{background:"#f8f9fa",padding:"12px",borderRadius:"12px",border:"1px dashed #ced4da",marginBottom:"16
1px"},children:e.jsx("img",{src:f,alt:"QR Code Link to PDF",style:{width:"220px",height:"220px",display:"block"}})}),e.jsxs("div",{style:{fontSize:"13px",color:"#2b8a3e",fontWeight:600,display:"flex",alignItems:"center",gap:"4px",marginBottom:"12px"},children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})}),"End-to-End Encrypted Link"]}),e.jsx("div",{style:{fontSize:"12px",color:"#868e96",marginBottom:"20px"},children:"Expires in 60 minutes · Auto-destructs after download"}),e.jsx("div",{style:{display:"flex",width:"100%",gap:"8px"},children:e.jsx("button",{onClick:C,className:"btn-ghost",style:{flex:1,padding:"10px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"8px",border:"1px solid #ced4da",background:"#ffffff",cursor:"pointer",fontWeight:500},children:S?e.jsxs(e.Fragment,{children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#2b8a3e",strokeWidth:"2.5",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),e.jsx("span",{style:{color:"#2b8a3e"},children:"Copied!"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),"Copy Link"]})})})]})]}),e.jsx("div",{className:"tool-config-actions",style:{marginTop:"24px",width:"100%",display:"flex",justifyContent:"center"},children:e.jsx("button",{className:"btn-ghost",onClick:i,style:{padding:"10px 24px",fontSize:"13px",cursor:"pointer",borderRadius:"8px"},children:"Back to Tools"})}),e.jsx("style",{children:` 2 @keyframes spin { 3 to { transform: rotate(360deg); } 4 } 5 `})]})}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.