1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/StudioEditWorkspace-Bw-PfBMm.js","assets/vendor-react-C_xdI0Ng.js","assets/StudioDialog-Bz_0GjSD.js","assets/linear-icon-BS_Bu1OG.js","assets/vendor-icons-CmfhFn4k.js","assets/infer-source-text-style-CB_Q6F8k.js","assets/index-DbFRh42P.js","assets/index-3PvMbFPA.css","assets/protect-errors-CmaV3kPR.js","assets/preview-service-CUDLI67J.js","assets/history-store-Bah29A3T.js","assets/feature-flag-QAeryYXU.js","assets/StudioConvertWorkspace-dZysDiVu.js","assets/AutoTocStudioPanel-DMajUVgG.js","assets/noto-sans-cyrillic-700-normal-B3rv6UnQ.js","assets/noto-sans-latin-400-normal-DZbyGt1h.js","assets/noto-sans-latin-ext-400-normal-ChgRUxkZ.js","assets/noto-sans-cyrillic-400-normal-C2Ud1djk.js","assets/PdfInfoStudioPanel-ClLm4KQ6.js","assets/pdf-info-client-CO7HLkbQ.js"])))=>i.map(i=>d[i]); 2var bn=Object.defineProperty;var vn=(n,o,s)=>o in n?bn(n,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[o]=s;var ot=(n,o,s)=>vn(n,typeof o!="symbol"?o+"":o,s);import{u as ct,a as D,s as De,p as In,t as Cn,b as Dn,d as Pn,o as jn,e as dt,f as Dt,c as kn,r as Sn,g as En,_ as ut}from"./index-DbFRh42P.js";import{r as c,R as We,j as e,k as Pt,u as Nn,i as _n}from"./vendor-react-C_xdI0Ng.js";import{b as rt,a as Tn,C as Mn,g as Rn,i as Ht}from"./canvas-tools-D-8v7jH3.js";import{u as Kt,G as Pe,R as le,I as qt,T as Me,C as An,S as On,L as Ln}from"./vendor-konva-ZjxRZeak.js";import{u as ve}from"./history-store-Bah29A3T.js";import{L as ge}from"./linear-icon-BS_Bu1OG.js";import{c as wt,g as Un,n as Fn,S as Wn,a as Hn}from"./StudioDialog-Bz_0GjSD.js";import{d as Bn}from"./preview-service-CUDLI67J.js";import"./vendor-icons-CmfhFn4k.js";import"./infer-source-text-style-CB_Q6F8k.js";const Jt={maxWorkspaces:3,maxPagesPerDocument:Number.POSITIVE_INFINITY},zn={maxWorkspaces:Number.POSITIVE_INFINITY,maxPagesPerDocument:Number.POSITIVE_INFINITY};function Zt(n){return Number.isFinite(n)?Math.max(0,Math.floor(n)):Number.POSITIVE_INFINITY}function Qt(n){return n==="pro"||n==="trial"?zn:Jt}function Te(n){const o=Jt.maxPagesPerDocument,s=Number.isFinite(o)?`Free supports documents up to ${o} pages`:"This document exceeds the Free page limit";return n?`${s}. Upgrade to Pro to ${n}.`:`${s}.`}function Ct(n,o){const s=Qt(n.plan),a=Zt(o);return Number.isFinite(s.maxWorkspaces)?a<s.maxWorkspaces?{allowed:!0,current:a,limit:s.maxWorkspaces}:{allowed:!1,reason:"workspace_limit",current:a,limit:s.maxWorkspaces}:{allowed:!0,current:a,limit:s.maxWorkspaces}}function ze(n,o){const s=Qt(n.plan),a=Zt(o);return Number.isFinite(s.maxPagesPerDocument)?a<=s.maxPagesPerDocument?{allowed:!0,current:a,limit:s.maxPagesPerDocument}:{allowed:!1,reason:"page_limit",current:a,limit:s.maxPagesPerDocument}:{allowed:!0,current:a,limit:s.maxPagesPerDocument}}function Bt(n,o,s){const a=Ct(n,o);return a.allowed?ze(n,s):a}const Yn=16,Se=[];function Xn(){const n=document.createElement("canvas"),o=n.getContext("2d");return{canvas:n,ctx:o}}function $n(n,o){for(const i of Se)if(!i.inUse&&i.width>=n&&i.height>=o)return i.inUse=!0,i.canvas.width=n,i.canvas.height=o,{canvas:i.canvas,ctx:i.ctx,width:n,height:o};for(const i of Se)if(!i.inUse)return i.inUse=!0,i.width=n,i.height=o,i.canvas.width=n,i.canvas.height=o,{canvas:i.canvas,ctx:i.ctx,width:n,height:o};const{canvas:s,ctx:a}=Xn();if(s.width=n,s.height=o,Se.push({canvas:s,ctx:a,inUse:!0,width:n,height:o}),Se.length>Yn){const i=Se.find(d=>!d.inUse);i&&Se.splice(Se.indexOf(i),1)}return{canvas:s,ctx:a,width:n,height:o}}function jt(n){for(const o of Se)if(o.canvas===n){o.inUse=!1,o.ctx.clearRect(0,0,o.width,o.height);return}}const at=new Set;let bt=!1,st=null;const Gn=1500,Vn=2500,Kn=5e3;function qn(){if(typeof performance>"u"||!("memory"in performance))return null;const n=performance.memory;return n&&typeof n.usedJSHeapSize=="number"?n.usedJSHeapSize/(1024*1024):null}function Jn(){const n=qn();if(n!==null&&(n>Vn||n>Gn))for(const o of at)o()}function Zn(n){return at.add(n),bt||(bt=!0,st=setInterval(Jn,Kn)),()=>{at.delete(n),at.size===0&&st&&(clearInterval(st),st=null,bt=!1)}}const Qn=30,eo=10,fe=new Map;function to(n){const o=fe.get(n);return o&&(fe.delete(n),fe.set(n,o)),o}function no(n,o){if(fe.size>=Qn){const s=fe.keys().next().value;if(s){const a=fe.get(s);a&&jt(a),fe.delete(s)}}fe.set(n,o)}function oo(n){for(;fe.size>n;){const o=fe.keys().next().value;if(!o)break;const s=fe.get(o);s&&jt(s),fe.delete(o)}}let zt=null;function so(){zt||(zt=Zn(()=>{oo(eo),ro()}))}const ao=5,we=new Map;async function io(n,o){const s=we.get(n);if(s)return we.delete(n),we.set(n,s),s;const a=(async()=>{try{const i=await rt(),y=await(await(await o.vfs.read(n)).getBlob()).arrayBuffer();return await i.getDocument({data:new Uint8Array(y)}).promise}catch(i){throw we.delete(n),i}})();if(we.size>
2=ao){const i=we.keys().next().value;if(i){const d=we.get(i);if(we.delete(i),d)try{await(await d).destroy()}catch(P){console.error("Failed to destroy cached pdf document:",P)}}}return we.set(n,a),a}async function ro(){const n=Array.from(we.values());we.clear();for(const o of n)try{await(await o).destroy()}catch{}}function Yt(n,o,s,a){const l=n.scaleX()||1,b=o.absolutePosition(),g={x:b.x+100*l,y:b.y+140*l};for(const E of n.find(".document")){const h=E.id(),W=s.find(A=>A.id===h);if(!W)continue;const _=E.getAbsoluteTransform().copy().invert().point(g),$=Math.min(W.pages.length||1,a),J=Math.ceil(W.pages.length/$)||1,p=Math.max(220,$*220),te=Math.max(310,J*310);if(_.x>=-30&&_.x<=p+30&&_.y>=-50&&_.y<=te+50)return{targetDocId:h,targetDocNode:E}}return{targetDocId:null,targetDocNode:null}}const lo=({page:n,docId:o,x:s,y:a,currentIndex:i,shouldPrefetchOnly:d=!1})=>{const P=c.useRef(null),{runtime:y}=ct(),S=ve(C=>C.createCheckpoint),[L]=Kt(n.thumbnailUrl),[l,b]=We.useState(null),[g,E]=We.useState(!1),[h,W]=We.useState(null),N=D(C=>C.documents),_=D(C=>C.gridColumns),$=D(C=>C.studioViewScale),J=D(C=>C.detachPage),p=D(C=>C.selection),te=D(C=>C.setSelection),A=D(C=>C.setActiveDocument),K=p.some(C=>C.pageId===n.id),R=D(C=>C.movePage),m=We.useMemo(()=>d?2:K?$>=1.35?3:2.5:$>=1.35?3:2,[K,d,$]),de=C=>{C.cancelBubble=!0},se=C=>{C.cancelBubble=!0,C.target.moveToTop()},v=C=>{C.cancelBubble=!0;const U=C.target,q=U.getStage();if(!q)return;const{targetDocId:T}=Yt(q,U,N,_);if(!T||T===o){h&&W(null);return}if((h==null?void 0:h.docId)===T)return;const X=N.find(B=>B.id===T);W({docId:T,name:(X==null?void 0:X.name)??"workspace"})},w=C=>{C.cancelBubble=!0,W(null);const U=C.target,q=U.getStage();if(!q)return;const T=q.getPointerPosition();if(!T)return;const X=q.getAbsoluteTransform().copy().invert(),B=X.point(T),ae=200,ce=280,xe=20,Re=30,G=ae+xe,Z=ce+Re,{targetDocId:pe,targetDocNode:Ee}=Yt(q,U,N,_),Ye=q.scaleX()||1,Ke=U.absolutePosition(),me={x:Ke.x+100*Ye,y:Ke.y+140*Ye},ne=N.find(ye=>ye.id===o);let Xe=G,ie=Z;if(ne){const ye=Math.min(ne.pages.length||1,_),je=Math.ceil(ne.pages.length/ye)||1;Xe=Math.max(G,ye*G),ie=Math.max(Z,je*Z)}const Y=((ne==null?void 0:ne.x)??0)-30,ht=((ne==null?void 0:ne.x)??0)+Xe+30,Ie=((ne==null?void 0:ne.y)??0)-50,$e=((ne==null?void 0:ne.y)??0)+ie+50,qe=!ne||B.x<Y||B.x>ht||B.y<Ie||B.y>$e;if(pe&&Ee&&!(pe===o&&qe)){const ye=N.find(Ze=>Ze.id===pe);if(ye&&pe!==o&&!ze(y.billing.getContext(),ye.pages.length+1).allowed){De(y.telemetry,Te("keep adding pages"),void 0,{toolId:"studio",trigger:"page_limit_25"});return}const Ae=Ee.getAbsoluteTransform().copy().invert().point(me),Ge=Math.max(0,Math.min(_-1,Math.round(Ae.x/G))),Je=Math.max(0,Math.round(Ae.y/Z))*_+Ge;R(o,n.id,pe,Je),pe!==o&&y.telemetry.track({type:"STUDIO_MERGE_COMPLETED",runId:crypto.randomUUID(),sourceDocId:o,targetDocId:pe,pageCount:1,method:"drag"}),S(y.vfs,"move_page",pe===o?"Moved page within workspace":"Moved page to another workspace")}else{const ye=U.absolutePosition(),je=X.point(ye);J(o,n.id,je.x,je.y),S(y.vfs,"move_page","Detached page")}},M=C=>{var X,B;C.cancelBubble=!0,A(o);const U=D.getState().selection,q=C.evt.shiftKey||C.evt.altKey||((B=(X=C.evt).getModifierState)==null?void 0:B.call(X,"Alt")),T=U.some(ae=>ae.pageId===n.id);te(q?T?U.filter(ae=>ae.pageId!==n.id):[...U,{docId:o,pageId:n.id}]:[{docId:o,pageId:n.id}])};if(We.useEffect(()=>{so();let C=!0;const U=`${n.fileId}_${n.pageIndex}_${m}`,q=to(U);if(q){b(q);return}const T=async()=>{if(g)return;E(!0);let B=null;try{const ae=await io(n.fileId,y);if(!C)return;const ce=await ae.getPage(n.pageIndex+1),xe=ce.getViewport({scale:m});B=$n(xe.width,xe.height),await ce.render({canvasContext:B.ctx,viewport:xe,canvas:B.canvas}).promise,C&&(no(U,B.canvas),b(B.canvas))}catch(ae){console.error("Failed to render high-res page:",ae),B&&jt(B.canvas)}finally{C&&E(!1)}},X=setTimeout(()=>{T()},150);return()=>{C=!1,clearTimeout(X)}},[m,n.fileId,n.pageIndex,y.vfs]),d)return null;const z=180,O=250;return e.jsxs(Pe,{ref:P,id:n.id,name:"page-object",x:s,y:a,draggable:!0,onMouseDown:de,onTouchStart:de,onDragStart:se,onDragMove:v,onDragEnd:w,onClick:M,rotation:n.rotation,children:[e.jsx(le,{width:z,height:O,fill:"#ffffff",stroke:"#e9e9e7",strokeWidth:1,shadowColor:"#000000",shadowBlur:16,shadowOpacity:.1,shadowOffset:{x:0,y:4},cornerRadius:4}),(l||L)&&(()=>{const C=l||L;if(!C)return null;const U=C.width/C.height,q=z/O;let T=z,X=O,B=0,ae=0;return U>q?(T=z,X=z/U,ae=(O-X)/2):(X=O,T=O*U,B=(z-T)/2),e.jsx(qt,{image:C,width:T,height:X,x:B,y:ae,imageSmoothingEnabled:!l,cornerRadius:4})})(),e.jsxs(Pe,{x:z-24,y:O-24,children:[e.jsx(le,{width:20,height:20,fill:"#f1f1ef",stroke:"#e9e9e7",strokeWidth:1,cornerRadius:4}),e.jsx(Me,{text:`${i+1}`,fill:"#b3b3af",fontSize:10,x:5,y:5,align:"center"})]}),e.jsx(le,{width:z,height:O,fill:"transparent",stroke:K?"#2383e2":"transparent",strokeWidth:2,cornerRadius:4,shadowColor:K?"#2383e2":"transparent",shadowBlur:K?8:0,shadowOpacity:.3,listening:!1}),h&&e.jsxs(Pe,{y:-46,listening:!1,children:[e.jsx(le,{width:z,height:38,fill:"#142028",opacity:.92,cornerRadius:5}),e.jsx(Me,{text:`Release to merge 3into ${h.name}`,fill:"#f9f5ee",fontSize:11,lineHeight:1.35,width:z,height:38,align:"center",verticalAlign:"middle"})]})]})},co=({doc:n,gridColumnsOverride:o})=>{const[s,a]=We.useState(!1),i=D(w=>w.updateDocument),d=D(w=>w.setRenamingDocId),P=D(w=>w.activeDocumentId),y=D(w=>w.setActiveDocument),S=D(w=>w.selection),L=D(w=>w.setSelection),l=D(w=>
3w.gridColumns),b=o??l,g=D(w=>w.viewportSize),E=D(w=>w.studioViewPosition),h=D(w=>w.studioViewScale),W=w=>{w.target.name()==="document"&&i(n.id,{x:w.target.x(),y:w.target.y()})},N=200,_=280,$=20,J=30,p=4,te=54,A=10,K=Math.min(n.pages.length||1,b),R=Math.ceil(n.pages.length/K)||1,m=Math.max(N+$,K*(N+$)),de=R*(_+J),se=Math.max(120,m-te),v=P===n.id&&S.length===0;return e.jsxs(Pe,{x:n.x,y:n.y,draggable:!0,onDragStart:w=>{w.cancelBubble=!0},onDragEnd:W,onMouseDown:()=>{y(n.id),L([])},name:"document",id:n.id,onDragEnter:()=>a(!0),onDragLeave:()=>a(!1),onDrop:()=>a(!1),children:[e.jsx(le,{width:m+A*2,height:de+A*2+10+32,x:-A,y:-32,fill:"#e8e8e6",stroke:"transparent",cornerRadius:6,shadowColor:"#000000",shadowBlur:40,shadowOpacity:.12,shadowOffset:{x:0,y:8},listening:!1}),e.jsx(le,{width:m+A*2,height:de+A*2+10+32,x:-A,y:-32,fill:"transparent",stroke:"transparent",cornerRadius:6,shadowColor:"#000000",shadowBlur:10,shadowOpacity:.08,shadowOffset:{x:0,y:2},listening:!1}),e.jsx(le,{width:m+A*2,height:30,x:-A,y:-32,fill:"#ffffff",stroke:s?"#2383e2":"#e9e9e7",strokeWidth:1,cornerRadius:[6,6,0,0]}),e.jsx(le,{width:m+A*2,height:1,x:-A,y:-2,fill:"#e9e9e7",listening:!1}),e.jsx(le,{width:m+A*2,height:de+A*2+10,x:-A,y:-1,fill:"#ffffff",stroke:s?"#2383e2":"#e9e9e7",strokeWidth:1,cornerRadius:[0,0,6,6]}),v&&e.jsx(le,{width:m+A*2,height:de+A*2+10+32,x:-A,y:-32,fill:"transparent",stroke:"#2383e2",strokeWidth:2,cornerRadius:6,listening:!1}),e.jsxs(Pe,{y:-32,onClick:w=>{w.cancelBubble=!0,d(n.id)},style:{cursor:"pointer"},children:[e.jsx(An,{x:4,y:15,radius:p,fill:n.isModified?"#dfab01":"#0f7b6c"}),e.jsx(Me,{text:n.name,x:15,y:7,fill:"#1a1a18",fontSize:12,fontStyle:"500",width:se-60,wrap:"none",ellipsis:!0}),e.jsx(Me,{text:`${n.pages.length} page${n.pages.length===1?"":"s"}`,x:se-50,y:7,fill:"#b3b3af",fontSize:11,align:"right",width:50})]}),n.pages.length===0&&e.jsxs(Pe,{x:A,y:A,children:[e.jsx(le,{width:N,height:_,fillLinearGradientStartPoint:{x:10,y:10},fillLinearGradientEndPoint:{x:N+10,y:_+10},fillLinearGradientColorStops:[0,"#ffffff",1,"#f1f1ef"],stroke:"#e9e9e7",strokeWidth:1.5,dash:[8,6],cornerRadius:12}),e.jsx(Me,{text:"Drop pages here",fill:"#b3b3af",fontSize:14,fontStyle:"bold",align:"center",verticalAlign:"middle",width:N,height:_})]}),n.pages.map((w,M)=>{const z=M%b,O=Math.floor(M/b),C=A+z*(N+$),U=A+O*(_+J),q=(n.x+C)*h+E.x,T=(n.y+U)*h+E.y,X=N*h,B=_*h,ae=g.width*.5,ce=g.height*.5,xe=g.width*1.5,Re=g.height*1.5,G=q+X+ae>=0&&q-ae<=g.width&&T+B+ce>=0&&T-ce<=g.height,Z=q+X+xe>=0&&q-xe<=g.width&&T+B+Re>=0&&T-Re<=g.height;if(!G&&!Z)return null;const pe=!G&&Z;return e.jsx(lo,{page:w,docId:n.id,x:C,y:U,currentIndex:M,shouldPrefetchOnly:pe},w.id)})]})},uo=({page:n})=>{const{runtime:o}=ct(),[s]=Kt(n.thumbnailUrl),a=ve(l=>l.createCheckpoint),i=D(l=>l.attachDetachedPage),d=D(l=>l.moveDetachedPage),P=D(l=>l.removeDetachedPage),y=D(l=>l.activeDocumentId),S=D(l=>l.gridColumns),L=l=>{l.cancelBubble=!0;const b=l.target,g=b.getStage();if(!g||!g.getPointerPosition())return;let h=null,W=null;const N=200,_=280,$=20,J=30,p=N+$,te=_+J,A=g.scaleX()||1,K=b.absolutePosition(),R={x:K.x+90*A,y:K.y+125*A},m=g.find(".document");for(const v of m){const w=v.id(),M=D.getState().documents.find(X=>X.id===w);if(!M)continue;const O=v.getAbsoluteTransform().copy().invert().point(R),C=Math.min(M.pages.length||1,S),U=Math.ceil(M.pages.length/C)||1,q=Math.max(p,C*p),T=Math.max(te,U*te);if(O.x>=-30&&O.x<=q+30&&O.y>=-50&&O.y<=T+50){h=w,W=v;break}}if(h&&W){const v=D.getState().documents.find(U=>U.id===h);if(v&&!ze(o.billing.getContext(),v.pages.length+1).allowed){De(o.telemetry,Te("keep adding pages"),void 0,{toolId:"studio",trigger:"page_limit_25"});return}const M=W.getAbsoluteTransform().copy().invert().point(R),z=Math.max(0,Math.min(S-1,Math.round(M.x/p))),C=Math.max(0,Math.round(M.y/te))*S+z;i(n.id,h,C),a(o.vfs,"move_page","Attached page to workspace");return}const se=g.getAbsoluteTransform().copy().invert().point(K);d(n.id,se.x,se.y),a(o.vfs,"move_page","Moved detached page")};return e.jsxs(Pe,{id:`detached-${n.id}`,name:"detached-page-object",x:n.x,y:n.y,draggable:!0,onClick:l=>{if(l.cancelBubble=!0,!y)return;const b=D.getState().documents.find(g=>g.id===y);if(b&&!ze(o.billing.getContext(),b.pages.length+1).allowed){De(o.telemetry,Te("keep adding pages"),void 0,{toolId:"studio",trigger:"page_limit_25"});return}i(n.id,y),a(o.vfs,"move_page","Attached page to active workspace")},onDragStart:l=>{l.cancelBubble=!0,l.target.moveToTop()},onDragEnd:L,rotation:n.rotation,children:[e.jsx(le,{width:180,height:250,fill:"white",shadowBlur:10,shadowOpacity:.3,cornerRadius:4}),s&&(()=>{const l=s.width/s.height,b=180/250;let g=180,E=250,h=0,W=0;return l>b?(g=180,E=180/l,W=(250-E)/2):(E=250,g=250*l,h=(180-g)/2),e.jsx(qt,{image:s,width:g,height:E,x:h,y:W,imageSmoothingEnabled:!1,cornerRadius:4})})(),e.jsxs(Pe,{x:0,y:-24,children:[e.jsx(le,{width:180,height:20,fill:"rgba(15, 23, 42, 0.75)",cornerRadius:4}),e.jsx(Me,{text:"Detached page",fill:"#dbeafe",fontSize:11,x:8,y:4})]}),e.jsxs(Pe,{x:162,y:-8,onClick:l=>{l.cancelBubble=!0,P(n.id),a(o.vfs,"delete_page","Deleted detached page")},onMouseEnter:l=>{var g;const b=(g=l.target.getStage())==null?void 0:g.container();b&&(b.style.cursor="pointer")},onMouseLeave:l=>{var g;const b=(g=l.target.getStage())==null?void 0:g.container();b&&(b.style.cursor="default")},children:[e.jsx(le,{width:24,height:24,fill:"#ef4444",cornerRadius:12,shadowBlur:4,shadowOpacity:.3,x:-12,y:-12}),e.jsx(Me,{text:"â",fill:"white",fontSize:14,fontStyle:"bold",x:-6,y:-7})]}),e.jsx(le,{width:180,height:250,fill:"transparent",stroke:"rgba(147, 197, 253, 0.8)",strokeWidth:1.5,dash:[7,5],cornerRadius:4})]})},ho=[{tool:"text",icon:"text",label:"Text",description:"Add and edit text elements on PDF pages"},{tool:"annotate",icon:"highlighter",label:"Annotate",description:"Highlight text, draw shapes, and add notes"},{tool:"sign",icon:"signature",label:"Sign",description:"Draw, type, or upload your signature to sign PDF"},{tool:"whiteout",icon:"eraser",label:"Whiteout",description:"Permanently erase sensitive content from PDF"},{tool:"watermark",icon:"stamp",label:"Watermark",description:"Add text or image watermarks to all pages"},{tool:"forms",icon:"file-input",label:"Forms",description:"Add fillable fields like text boxes, checkboxes, and dropdowns"},{tool:"protect",icon:"lock",label:"Protect",description:"Encrypt PDF with passwords and restrict permissions"}],po=[{tool:"ocr-pdf",icon:"ocr",label:"OCR",description:"Recognize text in scanned PDFs and make them searchable"},{tool:"auto-toc",icon:"edit",label:"TOC",description:"Auto-detect headings and generate an interactive table of contents with bookmarks"},{tool:"pdf-to-jpg",icon:"image",label:"PDF to JPG",description:"Convert PDF pages to JPEG images"},{tool:"compress-pdf",icon:"compress",label:"Compress",description:"Reduce PDF file size while maintaining quality"},{tool:"extract-images",icon:"image",label:"Extract Images",description:"Extract all embedded images from PDF document"}],mo=[{tool:"pdf-info",icon:"file-input",label:"PDF Info",description:"Inspect pages, PDF version, encryption, fonts, and metadata locally"}];function vt({tool:n,icon:o,label:s,description:a,activeTool:i,disabled:d,onClick:P}){const y=i===n;return e.jsxs("button",{type:"button",className:`studio-tool-rail-btn${y?" active":""}`,onClick:P,disabled:d,"aria-pressed":y,title:a||s,children:[e.jsx(ge,{name:o,size:20}),e.jsx("span",{className:"studio-tool-rail-collapsible-text",children:s}),n==="auto-toc"&&e.jsx("span",{className:"studio-tool-rail-badge-new studio-tool-rail-collapsible-text",children:"NEW"})]})}function en({activeTool:n,onToolClick:o,onUpload:s,hasFiles:a,onHistoryToggle:i,isHistoryOpen:d,plan:P,attentionOnUpload:y=!1,selectedPageCount:S=0,activeWorkspaceName:L,mergeTargets:l=[],onMergePages:b,onSplitPages:g,onDeletePages:E,onAfterSelect:h}){const[W,N]=c.useState(!1),_=S>0,$=a&&!!b&&l.length>0,J=a&&_&&!!g,p=a&&_&&!!E,te=_?`${S} page${S===1?"":"s"} selected`:L?`whole ${L}`:"select pages first",A=()=>{if(!(!$||!b)){if(l.length===1){N(!1),b(l[0].id),h==null||h();return}N(R=>!R)}},K=R=>{o(R),h==null||h()};return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:`studio-tool-rail-btn studio-tool-rail-upload-btn${y?" studio-tool-rail-btn--attention":""}`,onClick:()=>{s(),h==null||h()},title:"Upload files",children:[e.jsx(ge,{name:"upload",size:20}),e.jsx("span",{className:"studio-tool-rail-collapsible-text",children:"Upload"})]}),e.jsxs("div",{className:"studio-tool-rail-section",children:[e.jsx("div",{className:"studio-tool-rail-section-label studio-tool-rail-collapsible-text",children:"PAGES"}),e.jsxs("button",{type:"button",className:"studio-tool-rail-btn",onClick:A,disabled:!$,"aria-expanded":W,title:`Merge ${te} into another workspace`,children:[e.jsx(ge,{name:"merge",size:20}),e.jsx("span",{className:"studio-tool-rail-collapsible-text",children:"Merge"})]}),W&&l.length>1&&e.jsx("div",{className:"studio-tool-rail-merge-targets",children:l.map(R=>e.jsx("button",{type:"button",className:"studio-tool-rail-target-btn",onClick:()=>{N(!1),b==null||b(R.id),h==null||h()},children:R.name},R.id))}),e.jsxs("button",{type:"button",className:"studio-tool-rail-btn",onClick:()=>{g==null||g(),h==null||h()},disabled:!J,title:_?`Split ${te}
3 into a new workspace`:"Select pages to split into a new workspace",children:[e.jsx(ge,{name:"split",size:20}),e.jsx("span",{className:"studio-tool-rail-collapsible-text",children:"Split"})]}),e.jsxs("button",{type:"button",className:"studio-tool-rail-btn",onClick:()=>{E==null||E(),h==null||h()},disabled:!p,title:"Delete selected pages (Delete)",children:[e.jsx(ge,{name:"delete-pages",size:20}),e.jsx("span",{className:"studio-tool-rail-collapsible-text",children:"Delete"})]}),e.jsx("div",{className:"studio-tool-rail-scope studio-tool-rail-collapsible-text",children:te})]}),e.jsxs("div",{className:"studio-tool-rail-section",children:[e.jsx("div",{className:"studio-tool-rail-section-label studio-tool-rail-collapsible-text",children:"EDIT"}),ho.map(R=>e.jsx(vt,{tool:R.tool,icon:R.icon,label:R.label,description:R.description,activeTool:n,disabled:!a,onClick:()=>{K(R.tool)}},R.tool))]}),e.jsxs("div",{className:"studio-tool-rail-section",children:[e.jsx("div",{className:"studio-tool-rail-section-label studio-tool-rail-collapsible-text",children:"CONVERT"}),po.map(R=>e.jsx(vt,{tool:R.tool,icon:R.icon,label:R.label,description:R.description,activeTool:n,disabled:!a,onClick:()=>{K(R.tool)}},R.tool))]}),e.jsxs("div",{className:"studio-tool-rail-section",children:[e.jsx("div",{className:"studio-tool-rail-section-label studio-tool-rail-collapsible-text",children:"INSPECT"}),mo.map(R=>e.jsx(vt,{tool:R.tool,icon:R.icon,label:R.label,description:R.description,activeTool:n,disabled:!a,onClick:()=>{K(R.tool)}},R.tool))]}),e.jsx("div",{className:"studio-tool-rail-divider"}),e.jsx("div",{className:"studio-tool-rail-ext-section",children:e.jsxs("a",{href:"https://chromewebstore.google.com/detail/localpdf-private-pdf-comp/mjidkeobnlijdjmioniboflmoelmckfl",target:"_blank",rel:"noopener noreferrer",className:"studio-tool-rail-btn studio-tool-rail-ext-link",title:"Install Chrome extension for one-click PDF editing",children:[e.jsx(ge,{name:"download",size:20}),e.jsx("span",{className:"studio-tool-rail-collapsible-text",children:"Get Chrome Extension"})]})}),e.jsx("div",{className:"studio-tool-rail-divider"}),e.jsxs("div",{className:"studio-tool-rail-bottom",children:[e.jsxs("button",{type:"button",className:`studio-tool-rail-btn${d?" active":""}`,onClick:()=>{i==null||i(),h==null||h()},disabled:!i,"aria-pressed":!!d,title:d?"Hide history":"Show history",children:[e.jsx(ge,{name:"history",size:20}),e.jsx("span",{className:"studio-tool-rail-collapsible-text",children:"History"})]}),P==="pro"?e.jsx("div",{className:"studio-rail-plan-badge studio-rail-plan-badge--pro studio-tool-rail-collapsible-text",children:"Pro"}):e.jsx("div",{className:"studio-rail-plan-badge studio-rail-plan-badge--free studio-tool-rail-collapsible-text",children:"Free"})]})]})}function go(n){return e.jsx("div",{className:"studio-tool-rail-anchor",children:e.jsx("aside",{className:"studio-tool-rail","aria-label":"Studio tools",children:e.jsx(en,{...n})})})}function fo({open:n,onClose:o,...s}){return c.useEffect(()=>{if(!n)return;const a=i=>{i.key==="Escape"&&o()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[o,n]),n?Pt.createPortal(e.jsx("div",{className:"studio-tool-sheet-backdrop",onClick:o,role:"presentation",children:e.jsxs("div",{className:"studio-tool-sheet",role:"dialog","aria-modal":"true","aria-label":"Studio tools",onClick:a=>a.stopPropagation(),children:[e.jsx("div",{className:"studio-tool-sheet-handle","aria-hidden":"true"}),e.jsxs("div",{className:"studio-tool-sheet-head",children:[e.jsx("span",{className:"studio-tool-sheet-title",children:"Tools"}),e.jsx("button",{type:"button",className:"studio-tool-sheet-close",onClick:o,"aria-label":"Close tools",children:"â"})]}),e.jsx("div",{className:"studio-tool-sheet-body",children:e.jsx(en,{...s,onAfterSelect:o})})]})}),document.body):null}const Ce=class Ce{static createCanvasFactory(){return{create:(o,s)=>{const a=document.createElement("canvas");a.width=o,a.height=s;const i=a.getContext("2d");if(!i)throw new Error("Canvas factory failed to get 2d context");return{canvas:a,context:i}},reset:(o,s,a)=>{o.canvas.width=s,o.canvas.height=a},destroy:o=>{o.canvas.width=0,o.canvas.height=0}}}static async generateThumbnail(o,s){var L;const a=await rt(),i=((L=a.VerbosityLevel)==null?void 0:L.ERRORS)??0,P=await a.getDocument({data:new Uint8Array(o.slice(0)),verbosity:i}).promise,y=await P.getPage(s+1),S=await this.generateThumbnailFromPage(y);return await P.destroy(),S}static async generateThumbnailFromPage(o){const s=o.getViewport({scale:1}),a=Ce.MIN_THUMBNAIL_WIDTH_PX/Math.max(1,s.width),i=Math.min(Ce.MAX_RENDER_SCALE,Math.max(Ce.MIN_RENDER_SCALE,a)),d=o.getViewport({scale:i}),P=document.createElement("canvas"),y=P.getContext("2d");if(P.height=d.height,P.width=d.width,y)return y.imageSmoothingEnabled=!0,y.imageSmoothingQuality="high",await o.render({canvasContext:y,viewport:d,canvas:P,annotationMode:0,canvasFactory:Ce.createCanvasFactory()}).promise,P.toDataURL("image/png");throw new Error("Canvas context not available")}};ot(Ce,"MIN_THUMBNAIL_WIDTH_PX",1400),ot(Ce,"MIN_RENDER_SCALE",1),ot(Ce,"MAX_RENDER_SCALE",4);let lt=Ce;function xo(n){const o=Math.max(0,Date.now()-n),s=Math.floor(o/1e3),a=Math.floor(s/60),i=Math.floor(a/60),d=Math.floor(i/24);return d>0?`${d} day${d>1?"s":""} ago`:i>0?`${i} hour${i>1?"s":""} ago`:a>0?`${a} minute${a>
31?"s":""} ago`:"Just now"}function yo(){const n=ve(i=>i.timeline),o=ve(i=>i.historyIndex),s=ve(i=>i.restoreCheckpoint),a=c.useRef(null);return c.useEffect(()=>{a.current&&(a.current.scrollTop=a.current.scrollHeight)},[n.length]),n.length===0?e.jsxs("div",{className:"studio-timeline empty",children:[e.jsx(ge,{name:"history",className:"linear-icon-large opacity-50 mb-4"}),e.jsx("p",{children:"History is empty."}),e.jsx("span",{className:"text-xs opacity-60",children:"Actions will appear here."})]}):e.jsxs("div",{className:"studio-timeline-container",ref:a,children:[e.jsx("div",{className:"studio-timeline-header",children:e.jsx("h3",{children:"Version History"})}),e.jsx("div",{className:"studio-timeline-list",children:n.map((i,d)=>{const P=d===o,y=d>o,S=!!i.snapshot;return e.jsxs("div",{className:`timeline-item ${P?"current":""} ${y?"future":""} ${S?"checkpoint":"event"}`,children:[e.jsxs("div",{className:"timeline-marker",children:[e.jsx("div",{className:"timeline-dot"}),d<n.length-1&&e.jsx("div",{className:"timeline-line"})]}),e.jsxs("div",{className:"timeline-content",children:[e.jsxs("div",{className:"timeline-label",children:[e.jsx("span",{className:"timeline-type",children:i.type.replace("_"," ").toUpperCase()}),e.jsx("span",{className:"timeline-text",children:i.label}),i.isManualVersion&&e.jsx("span",{className:"timeline-version-badge",children:"Version"})]}),e.jsx("div",{className:"timeline-meta",children:xo(i.timestamp)}),S&&!P&&e.jsx("button",{type:"button",className:"timeline-restore-btn",onClick:()=>s(d),children:"Restore"})]})]},i.id)})})]})}function wo({element:n,onUpdate:o,onDelete:s,onDuplicate:a,onDeselect:i,onActivateMove:d,bgColor:P,onBgColorChange:y}){const S=c.useRef(null),L=n.type==="text",[l,b]=c.useState(()=>({x:Math.max(20,window.innerWidth/2-200),y:Math.max(20,window.innerHeight-120)})),g=c.useRef(!1),E=c.useRef({x:0,y:0});c.useEffect(()=>{if(!L)return;let N=0;const _=()=>{const $=`[data-editor-element-id="${n.id}"]`,J=document.querySelector($),p=S.current;if(J&&p){const te=J.getBoundingClientRect(),A=p.getBoundingClientRect(),K=Math.min(Math.max(12,te.left+te.width/2-A.width/2),Math.max(12,window.innerWidth-A.width-12)),R=Math.max(12,te.top-A.height-10);b({x:K,y:R})}N=window.requestAnimationFrame(_)};return N=window.requestAnimationFrame(_),()=>{window.cancelAnimationFrame(N)}},[n.id,L]),c.useEffect(()=>{const N=$=>{g.current&&(b(J=>({x:J.x+($.clientX-E.current.x),y:J.y+($.clientY-E.current.y)})),E.current={x:$.clientX,y:$.clientY})},_=()=>{g.current=!1};return window.addEventListener("pointermove",N),window.addEventListener("pointerup",_),()=>{window.removeEventListener("pointermove",N),window.removeEventListener("pointerup",_)}},[]);const h=N=>{if(!L&&!N.target.closest("button, input, select")){N.stopPropagation(),g.current=!0,E.current={x:N.clientX,y:N.clientY};try{N.currentTarget.setPointerCapture(N.pointerId)}catch{}}},W=()=>{if(n.type!=="text")return e.jsx("div",{ref:S,className:"studio-floating-properties-panel",style:{left:l.x,top:l.y,cursor:"grab"},onPointerDown:h,children:s&&e.jsx("button",{type:"button",className:"studio-floating-btn delete",onClick:s,title:"Delete",children:e.jsx(ge,{name:"x"})})});const N=n;return e.jsxs("div",{ref:S,className:"studio-floating-properties-panel",style:{left:l.x,top:l.y,cursor:L?"default":"grab"},onPointerDown:h,children:[e.jsxs("div",{className:"studio-floating-group",children:[e.jsx("button",{type:"button",className:`studio-floating-btn ${N.fontWeight==="bold"?"active":""}`,onClick:()=>o({fontWeight:N.fontWeight==="bold"?"normal":"bold"}),title:"Bold",children:e.jsx("span",{className:"font-icon-b",style:{fontWeight:700},children:"B"})}),e.jsx("button",{type:"button",className:`studio-floating-btn ${N.fontStyle==="italic"?"active":""}`,onClick:()=>o({fontStyle:N.fontStyle==="italic"?"normal":"italic"}),title:"Italic",children:e.jsx("span",{className:"font-icon-i",style:{fontStyle:"italic"},children:"I"})})]}),e.jsx("div",{className:"studio-floating-divider"}),e.jsxs("div",{className:"studio-floating-group",children:[e.jsxs("select",{className:"studio-floating-select font-family","aria-label":"Font family",title:"Font family",value:N.fontFamily,onChange:_=>o({fontFamily:_.target.value}),children:[e.jsx("option",{value:"roboto",style:{fontWeight:600},children:"Roboto (Latin/Cyrillic)"}),e.jsx("option",{value:"noto",children:"Noto Sans (International)"}),e.jsx("option",{value:"noto-arabic",children:"Noto Sans Arabic"}),e.jsx("option",{value:"noto-cjk",children:"Noto Sans CJK"}),e.jsx("option",{value:"noto-devanagari",children:"Noto Sans Devanagari"}),e.jsx("option",{value:"sora",children:"Helvetica"}),e.jsx("option",{value:"times",children:"Times New Roman"}),e.jsx("option",{value:"mono",children:"Courier"})]}),e.jsx("div",{className:"studio-floating-input-wrap",children:e.jsx("input",{type:"number",className:"studio-floating-input","data-testid":"studio-floating-font-size","aria-label":"Font size",title:"Font size",value:N.fontSize,min:8,max:96,onChange:_=>o({fontSize:wt(Number(_.target.value)||16,8,96)})})}),e.jsx("div",{className:"studio-floating-input-wrap",children:e.jsx("input",{type:"number",className:"studio-floating-input","data-testid":"studio-floating-line-height","aria-label":"Line height",value:N.lineHeight,min:.8,max:3,step:.05,title:"Line height",onCh
3ange:_=>o({lineHeight:wt(Number(_.target.value)||1.2,.8,3)})})}),e.jsx("div",{className:"studio-floating-input-wrap",children:e.jsx("input",{type:"number",className:"studio-floating-input","data-testid":"studio-floating-letter-spacing","aria-label":"Letter spacing",value:N.letterSpacing,min:-2,max:20,step:.2,title:"Letter spacing",onChange:_=>o({letterSpacing:wt(Number(_.target.value)||0,-2,20)})})})]}),e.jsx("div",{className:"studio-floating-divider"}),e.jsxs("div",{className:"studio-floating-group",children:[e.jsx("div",{className:"studio-floating-color-wrap",children:e.jsx("input",{type:"color",className:"studio-floating-color",value:N.color,onChange:_=>o({color:_.target.value}),title:"Text Color"})}),y&&e.jsx("div",{className:"studio-floating-color-wrap",children:e.jsx("input",{type:"color",className:"studio-floating-color",value:P||"#ffffff",onChange:_=>y(_.target.value),title:"Background Color"})})]}),e.jsx("div",{className:"studio-floating-divider"}),e.jsx("div",{className:"studio-floating-group",children:e.jsx("button",{type:"button",className:"studio-floating-btn",onClick:()=>{if(d){d();return}i==null||i()},title:"Move text",children:e.jsx(ge,{name:"move-horizontal",size:18})})})]})};return Pt.createPortal(W(),document.body)}function bo({stageRef:n}){const{runtime:o}=ct(),s=D(v=>v.activeEditPageId),a=D(v=>v.editSession),i=D(v=>v.documents),d=D(v=>v.updatePage),P=D(v=>v.updateDocument),y=D(v=>v.clearEditSession),S=D(v=>v.setActiveEditPageId),L=ve(v=>v.createCheckpoint),[l,b]=c.useState([]),[g,E]=c.useState(null),[h,W]=c.useState(!1),[N,_]=c.useState(null),[$,J]=c.useState([]),[p,te]=c.useState(!1),[A,K]=c.useState(null),R=c.useMemo(()=>Un(),[]),m=c.useMemo(()=>{if(!s)return null;for(const v of i){const w=v.pages.find(M=>M.id===s);if(w)return w}return null},[s,i]);c.useEffect(()=>{if(!s||!n.current)return;let v;const w=()=>{const M=n.current;if(!M)return;const z=M.find("#"+s)[0];if(!z)return;const O=z.getClientRect(),C=M.scaleX();E(U=>U&&Math.abs(U.x-O.x)<.5&&Math.abs(U.y-O.y)<.5&&Math.abs(U.w-O.width)<.5&&Math.abs(U.h-O.height)<.5&&Math.abs(U.scale-C)<.005?U:{x:O.x,y:O.y,w:O.width,h:O.height,scale:C}),v=requestAnimationFrame(w)};return v=requestAnimationFrame(w),()=>cancelAnimationFrame(v)},[s,n]),c.useEffect(()=>{if(!m)return;const v=new AbortController;return(async()=>{try{const w={id:crypto.randomUUID(),type:"COMMAND",payload:{type:"GET_PDF_TEXT_LAYER",payload:{fileId:m.fileId,pageNumber:m.pageIndex+1}}},M=await o.workerOrchestrator.dispatch(w,void 0,v.signal);M.payload.type==="TEXT_LAYER_RESULT"&&J(Fn(M.payload.payload.spans))}catch{}})(),()=>v.abort()},[m,o]);const de=async()=>{if(!(!m||h)){W(!0);try{const v={id:crypto.randomUUID(),type:"COMMAND",payload:{type:"APPLY_STUDIO_TEXT_EDITS",payload:{fileId:m.fileId,pageIndex:m.pageIndex,elements:l}}},w=await o.workerOrchestrator.dispatch(v);if(w.payload.type==="STUDIO_TEXT_EDITS_APPLIED"){const M=w.payload.payload.redactVerify;if(M&&a){const O=In(M,crypto.randomUUID());Cn(o.telemetry,O),P(a.docId,{lastRedactVerify:O}),O.passed||_("Redaction checks incomplete â PDF download allowed, certificate only when all pass.")}else a&&P(a.docId,{lastRedactVerify:void 0});const z=await Bn.getPdfPagePreview(o,w.payload.payload.outputId,m.pageIndex+1,{scale:2});d(a.docId,m.id,{fileId:w.payload.payload.outputId,thumbnailUrl:(z==null?void 0:z.thumbnailUrl)??m.thumbnailUrl}),await L(o.vfs,"edit_save","Saved inline edits"),se()}}catch{_(R.saveFailed)}finally{W(!1)}}},se=()=>{S(null),y()};return!s||!g||!m?null:e.jsxs("div",{className:"studio-inplace-editor-overlay",style:{position:"fixed",left:g.x,top:g.y,width:g.w,height:g.h,zIndex:1e3,pointerEvents:"none"},children:[e.jsxs("div",{style:{position:"relative",width:"100%",height:"100%",pointerEvents:"auto"},children:[e.jsx(Wn,{page:m,width:g.w,height:g.h,activeTool:(a==null?void 0:a.activeTool)??null,onActiveToolChange:v=>{},isSelectMode:p,setIsSelectMode:te,textLayerSpans:$,elements:l,onElementsChange:b,selectedElementId:A,onSelectedElementIdChange:K,onFinish:de,onDiscard:se}),A&&l.find(v=>v.id===A)&&e.jsx(wo,{element:l.find(v=>v.id===A),onUpdate:v=>{b(w=>w.map(M=>M.id===A?{...M,...v}:M))},onDelete:()=>{b(v=>v.filter(w=>w.id!==A)),K(null)},onDuplicate:()=>{const v=l.find(O=>O.id===A);if(!v)return;const w=crypto.randomUUID(),M="x"in v?v.x+.05:.05,z="y"in v?v.y+.05:.05;b(O=>[...O,{...v,id:w,x:M,y:z}]),K(w)},onDeselect:()=>K(null)}),N&&e.jsx("div",{className:"studio-inplace-error",children:N})]}),e.jsx("div",{style:{position:"fixed",inset:0,zIndex:-1,pointerEvents:"auto"}
3,onPointerDown:v=>{v.target===v.currentTarget&&se()}})]})}const vo=["OCR PDF â text recognition in scans and images","PDF Editor â modify text, images, and annotations","Password protection & encryption","Convert to/from Word, Excel, JPG","Delete, rotate, and reorder pages","Extract images from PDFs","Up to 500 MB per file","No ads, no daily limits"];function Io({toolId:n,toolName:o,reason:s,details:a,onClose:i}){const d=Dn(),P=()=>{d&&(Pn("paywall_cta_clicked",{source:"paywall_modal",toolId:n,trigger:s,destination:d.url,plan:"pro",variant:d.variant,userState:"local",hadPriorSuccessfulRun:!0}),jn(d.url,{source:"paywall_modal",trigger:s,plan:"pro",variant:d.variant,userState:"local",hadPriorSuccessfulRun:!0}))};return e.jsx("div",{className:"paywall-overlay",onClick:i,children:e.jsxs("div",{className:"paywall-modal",onClick:y=>y.stopPropagation(),children:[e.jsx("button",{className:"paywall-close",onClick:i,"aria-label":"Close",children:e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),e.jsx("div",{className:"paywall-lock-icon",children:e.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}),e.jsx("h2",{className:"paywall-title",children:o}),e.jsxs("p",{className:"paywall-subtitle",children:["This feature requires ",e.jsx("strong",{children:"LocalPDF Pro"})]}),a&&e.jsx("p",{className:"paywall-details",children:a}),e.jsx("div",{className:"paywall-divider"}),e.jsxs("div",{className:"paywall-features",children:[e.jsx("p",{className:"paywall-features-title",children:"With Pro you get:"}),e.jsx("ul",{className:"paywall-feature-list",children:vo.map(y=>e.jsxs("li",{className:"paywall-feature-item",children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2.5",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),e.jsx("span",{children:y})]},y))})]}),e.jsx("button",{className:"btn-primary paywall-cta",onClick:P,children:e.jsxs("span",{className:"btn-inline",children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),d?d.label:"Upgrade to Pro"]})}),e.jsx("p",{className:"paywall-note",children:"One-time payment â no subscription, no renewal"})]})})}function tn(n,o,s){const a=new Set(o.filter(d=>d.docId===s).map(d=>d.pageId));if(a.size===0)return[];const i=n.find(d=>d.id===s);return i?i.pages.filter(d=>a.has(d.id)):[]}function kt(n){const o=dt.getState();for(const s of n){if(s.allowEmpty)continue;const a=o.documents.find(i=>i.id===s.id);a&&a.pages.length===0&&o.removeDocument(s.id)}}function Co(n,o){const{sourceDocId:s,targetDocId:a,selection:i,method:d}=o;if(s===a)return 0;const P=dt.getState(),y=P.documents.find(h=>h.id===s),S=P.documents.find(h=>h.id===a);if(!y||!S)return 0;const L=tn(P.documents,i,s),l=L.length>0?L:y.pages;if(l.length===0)return 0;const b=new Set(l.map(h=>h.id)),g=P.documents.map(h=>h.id===s?{...h,isModified:!0,pages:h.pages.filter(W=>!b.has(W.id))}:h.id===a?{...h,isModified:!0,pages:[...h.pages,...l]}:h);P.setDocuments(g),kt([y]);const E=Dt.getState();return E.setSelection(E.selection.filter(h=>!b.has(h.pageId))),E.setActiveDocument(a),n.telemetry.track({type:"STUDIO_MERGE_COMPLETED",runId:crypto.randomUUID(),sourceDocId:s,targetDocId:a,pageCount:l.length,method:d}),ve.getState().createCheckpoint(n.vfs,"move_page",`Merged ${l.length} page${l.length===1?"":"s"} into ${S.name}`),l.length}function Do(n,o){const{sourceDocId:s,selection:a,target:i}=o,d=dt.getState(),P=d.documents.find(E=>E.id===s);if(!P)return 0;const y=tn(d.documents,a,s),S=y.length>0?y:P.pages;if(S.length===0)return 0;const L=new Set(S.map(E=>E.id)),l={id:i.id,name:i.name,x:i.x,y:i.y,pages:S,allowEmpty:!1,includeInExport:!0,isModified:!0},b=d.documents.map(E=>E.id===s?{...E,isModified:!0,pages:E.pages.filter(h=>!L.has(h.id))}:E);d.setDocuments([...b,l]),kt([P]);const g=Dt.getState();return g.setSelection(S.map(E=>({docId:l.id,pageId:E.id}))),g.setActiveDocument(l.id),n.telemetry.track({type:"STUDIO_SPLIT_COMPLETED",runId:crypto.randomUUID(),sourceDocId:s,newDocId:l.id,pageCount:S.length,method:"button"}),ve.getState().createCheckpoint(n.vfs,"space_new",`Split ${S.length} page${S.length===1?"":"s"} into a new workspace`),S.length}function Po(n,o){const{selection:s,method:a}=o;if(s.length===0)return 0;const i=dt.getState(),d=new Set(s.map(l=>l.pageId)),P=new Set(i.documents.flatMap(l=>l.pages.map(b=>b.id))),y=[...d].filter(l=>P.has(l)).length;if(y===0)return 0;
3const S=i.documents.length,L=i.documents.map(l=>({...l,isModified:!0,pages:l.pages.filter(b=>!d.has(b.id))}));return i.setDocuments(L),kt(i.documents),Dt.getState().setSelection([]),n.telemetry.track({type:"STUDIO_DELETE_PAGES",runId:crypto.randomUUID(),pageCount:y,workspaceCount:S,method:a}),ve.getState().createCheckpoint(n.vfs,"delete_page",`Deleted ${y} page${y===1?"":"s"}`),y}const jo=c.lazy(async()=>({default:(await ut(()=>import("./StudioEditWorkspace-Bw-PfBMm.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11]))).StudioEditWorkspace})),ko=c.lazy(async()=>({default:(await ut(()=>import("./StudioConvertWorkspace-dZysDiVu.js"),__vite__mapDeps([12,1,3,4,6,7,9,10]))).StudioConvertWorkspace})),So=c.lazy(async()=>({default:(await ut(()=>import("./AutoTocStudioPanel-DMajUVgG.js"),__vite__mapDeps([13,1,3,4,14,6,7,15,16,17]))).AutoTocStudioPanel})),Eo=c.lazy(async()=>({default:(await ut(()=>import("./PdfInfoStudioPanel-ClLm4KQ6.js"),__vite__mapDeps([18,1,3,4,19,6,7]))).PdfInfoStudioPanel})),No=52,_o=760,It=1,Xt=10,nn=200,on=280,St=20,$t=80,To=80,it=48,Gt=56,Mo=on+St+40,Ro=.35,Ao=6,Vt=1.2,Oo=[...Mn];function Lo(n){const o=n.trim(),s=o.toLowerCase();return s.endsWith("(protected)")||s.endsWith("(protected).pdf")?o:s.endsWith(".pdf")?`${o.slice(0,-4)} (protected).pdf`:`${o} (protected)`}function Uo(n){if(!n||typeof n!="object")return!1;const o=n,s=typeof o.name=="string"?o.name.toLowerCase():"",a=typeof o.code=="number"?o.code:null,i=typeof o.message=="string"?o.message.toLowerCase():"";return s.includes("passwordexception")||i.includes("passwordexception")||i.includes("encrypted")||a===1||a===2}function _e(n){return Math.min(Ao,Math.max(Ro,n))}async function Fo(n){if(!n.type.startsWith("image/"))return n;const o=n.type==="image/png"?"image/png":"image/jpeg";if(typeof createImageBitmap!="function"||typeof document>"u")return n;try{const s=await createImageBitmap(n);try{const a=document.createElement("canvas");a.width=s.width,a.height=s.height;const i=a.getContext("2d");if(!i)return n;i.drawImage(s,0,0);const d=await new Promise(S=>a.toBlob(S,o,.92));if(!d)return n;const P=o==="image/png"?"png":"jpg",y=n.name.replace(/\.[^.]+$/u,"");return new File([d],`${y||"image"}.${P}`,{type:o})}finally{s.close()}}catch{return n}}function He(n,o){const s=Math.min(n||1,o);return Math.max(240,s*(nn+St)+20)}function Be(n,o){const s=Math.min(n||1,o),a=Math.ceil(n/s)||1;return Math.max(Mo,a*(on+St)+60)}function Wo(n,o,s,a){if(o.length===0)return[];const i=$t,d=Math.max(To,...n.map(b=>b.y+Be(b.pages.length,a)+Gt)),P=Math.max(420,s-$t*2),y=[];let S=i,L=d,l=0;for(const b of o){const g=He(b.pages.length,a),E=Be(b.pages.length,a);S!==i&&S-i+g>P&&(S=i,L+=l+Gt,l=0),y.push({...b,x:S,y:L}),S+=g+it,l=Math.max(l,E)}return y}function Ho(n,o){let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,d=Number.NEGATIVE_INFINITY;for(const P of n){const y=He(P.pages.length,o),S=Be(P.pages.length,o);s=Math.min(s,P.x-20),a=Math.min(a,P.y-40),i=Math.max(i,P.x+y+20),d=Math.max(d,P.y+S+20)}return{minX:s,minY:a,maxX:i,maxY:d}}function es({onFilesDropped:n}){var At,Ot;const o=c.useRef(crypto.randomUUID()),[s,a]=c.useState({width:window.innerWidth,height:window.innerHeight}),i=D(t=>t.studioViewScale),d=D(t=>t.studioViewPosition),P=D(t=>t.setStudioViewport),y=D(t=>t.gridColumns),S=D(t=>t.setGridColumns),[L,l]=c.useState(i),[b,g]=c.useState(d),E=c.useRef(null),h=c.useRef(null),W=c.useRef(null),N=Math.max(1,Math.ceil(window.devicePixelRatio||1)),_=c.useRef(null),$=Nn(),J=_n(),{runtime:p}=ct(),[te,A]=c.useState(()=>p.billing.getContext());c.useEffect(()=>p.billing.subscribe(t=>{A(t)}),[p.billing]);const K=D(t=>t.isDraggingFile),R=D(t=>t.setDraggingFile),m=D(t=>t.documents),de=D(t=>t.detachedPages),se=D(t=>t.addDocument),v=D(t=>t.setDocuments),w=D(t=>t.setActiveDocument),M=D(t=>t.activeDocumentId),z=ve(t=>t.createCheckpoint),O=D(t=>t.isHistoryOpen),C=D(t=>t.setHistoryOpen),U=D(t=>t.renamingDocId),q=D(t=>t.setRenamingDocId),T=D(t=>t.selection),X=D(t=>t.setSelection),B=D(t=>t.setInteractionMode),ae=D(t=>t.startEditSession);D(t=>t.setActiveEditPageId);const ce=D(t=>t.editSession),xe=D(t=>t.clearEditSession),Re=D(t=>t.updateDocument),G=c.useMemo(()=>m.find(t=>
3t.id===M)??null,[M,m]),Z=m.length>0||de.length>0,pe=c.useMemo(()=>m.filter(t=>t.id!==M).map(t=>({id:t.id,name:t.name})),[M,m]),Ee=c.useRef([]),[Ye,Ke]=c.useState(!1),me=s.width<=_o,[ne,Xe]=c.useState(!1),ie=me?It:y,Y=c.useMemo(()=>({width:Math.max(0,s.width-(me?0:No)),height:s.height}),[s.height,s.width,me]);c.useEffect(()=>{_.current=M},[M]);const ht=c.useMemo(()=>{const r=document.createElement("canvas");r.width=20,r.height=20;const u=r.getContext("2d");return u&&(u.fillStyle="#f0efed",u.fillRect(0,0,20,20),u.fillStyle="#b4b4b0",u.beginPath(),u.arc(20/2,20/2,1,0,Math.PI*2),u.fill()),r},[]),[Ie,$e]=c.useState(null),[qe,ye]=c.useState(null),[je,Ae]=c.useState(!1),Ge=c.useRef(null),[pt]=c.useState(()=>{if(typeof window>"u")return!1;const t=new URLSearchParams(window.location.search).get("tool");return!t||!Tn(t)?!1:(Ge.current=t,!0)}),[Je,Ze]=c.useState(()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches);c.useEffect(()=>{var u;if(typeof window.matchMedia!="function")return;const t=window.matchMedia("(pointer: coarse)"),r=()=>Ze(t.matches);return(u=t.addEventListener)==null||u.call(t,"change",r),()=>{var x;return(x=t.removeEventListener)==null?void 0:x.call(t,"change",r)}},[]),c.useEffect(()=>{P(L,b,Y)},[Y,P,b,L]);const Oe=c.useCallback(t=>{p.telemetry.track({type:"UI_TOAST_SHOWN",runId:o.current,toolId:"studio",message:t,level:"error"})},[p.telemetry]),ke=c.useCallback(t=>{if(t.length===0){l(1),g({x:0,y:0});return}if(me){const F=t.find(V=>V.id===_.current)??t[0],oe=He(F.pages.length,It),ee=_e((Y.width-Xt*2)/oe),ue=Be(F.pages.length,It);l(ee),g({x:(Y.width-oe*ee)/2-F.x*ee,y:Math.max(Xt,(Y.height-ue*ee)/2)-F.y*ee});return}const r=Ho(t,ie),u=Math.max(1,r.maxX-r.minX),x=Math.max(1,r.maxY-r.minY),I=56,k=_e(Math.min((Y.width-I*2)/u,(Y.height-I*2)/x)),j=u*k,H=x*k,Q=(Y.width-j)/2-r.minX*k,f=(Y.height-H)/2-r.minY*k;l(k),g({x:Q,y:f})},[Y.height,Y.width,me,ie]),Et=c.useCallback(()=>{const t=T.length>=1?(()=>{const I=T[0],k=m.find(H=>H.id===I.docId)??null,j=(k==null?void 0:k.pages.find(H=>H.id===I.pageId))??null;return k&&j?{doc:k,page:j}:null})():null,r=G!=null&&G.pages[0]?{doc:G,page:G.pages[0]}:null,u=m.find(I=>I.pages[0])??null,x=(u==null?void 0:u.pages[0])??null;return t??r??(u&&x?{doc:u,page:x}:null)},[G,m,T]);c.useCallback(t=>{if(L>=1.4)return;const u=He(t.pages.length,ie),x=Be(t.pages.length,ie),I=56,k=_e(Math.min((Y.width-I*2)/u,(Y.height-I*2)/x)),j=Math.max(1.4,k),H=u*j,Q=x*j,f=(Y.width-H)/2-t.x*j,F=(Y.height-Q)/2-t.y*j;l(j),g({x:f,y:F})},[Y.height,Y.width,ie,L]);const Qe=c.useCallback(()=>{$e(null),xe(),B(null)},[xe,B]),Nt=c.useCallback(t=>{const r=Et();r&&(ae({docId:r.doc.id,pageId:r.page.id,pageIndex:r.page.pageIndex,fileId:r.page.fileId,initialTool:t}),X([{docId:r.doc.id,pageId:r.page.id}]),B("edit"),$e("edit"))},[Et,ae,X,B]),_t=c.useCallback(t=>{Z&&(B("convert"),$e(t))},[Z,B]),mt=c.useCallback(t=>{p.billing.getContext(),Oo.includes(t)?Nt(t):_t(t)},[Nt,_t,p.billing,p.telemetry]),sn=c.useCallback(()=>{C(!O)},[O,C]);c.useEffect(()=>{const t=Ge.current;!t||!pt||!Z||m.some(r=>r.pages.length>0)&&(Ge.current=null,mt(t))},[m,mt,Z,pt]);const an=c.useCallback(()=>{const t=p.billing.getContext(),r=Bt(t,m.length,0);if(!r.allowed){De(p.telemetry,r.reason==="workspace_limit"?"Free includes up to 3 workspaces. Upgrade to Pro for unlimited workspaces.":Te("open larger PDFs"),void 0,{toolId:"studio",trigger:r.reason==="workspace_limit"?"workspace_limit_3":"page_limit_25"});return}const u=m.reduce((I,k)=>Math.max(I,k.y+120),80),x=crypto.randomUUID();se({id:x,name:`Workspace ${m.length+1}`,x:100,y:Z?u+40:100,pages:[],allowEmpty:!0,includeInExport:!0,isModified:!0}),w(x),z(p.vfs,"system","Created Workspace")},[se,z,m,Z,p.billing,p.telemetry,p.vfs,w]),rn=Ie==="edit"?(ce==null?void 0:ce.activeTool)??null:Ie??(ce==null?void 0:ce.activeTool)??null,Le=c.useCallback((t,r)=>{const u=L,x=r==="in"?Vt:1/Vt,I=_e(u*x);if(Math.abs(I-u)<1e-4)return;const k=(t.x-b.x)/u,j=(t.y-b.y)/u,H=t.x-k*I,Q=t.y-j*I;l(I),g({x:H,y:Q})},[b.x,b.y,L]);c.useEffect(()=>{var Q;if(!me)return;const t=(Q=W.current)==null?void 0:Q.container();if(!t)return;let r=0,u=1,x=null;const I=f=>{const F=t.getBoundingClientRect();return{x:(f[0].clientX+f[1].clientX)/2-F.left,y:(f[0].clientY+f[1].clientY)/2-F.top}},k=f=>{if(f.touches.length!==2)return;const F=W.current;if(!F)return;
3F.stopDrag(),f.preventDefault(),r=Math.max(1,Math.hypot(f.touches[0].clientX-f.touches[1].clientX,f.touches[0].clientY-f.touches[1].clientY)),u=F.scaleX();const oe=I(f.touches);x={x:(oe.x-F.x())/u,y:(oe.y-F.y())/u}},j=f=>{if(f.touches.length!==2||!x)return;const F=W.current;if(!F)return;f.preventDefault();const oe=Math.max(1,Math.hypot(f.touches[0].clientX-f.touches[1].clientX,f.touches[0].clientY-f.touches[1].clientY)),ee=_e(u*(oe/r)),ue=I(f.touches);F.scale({x:ee,y:ee}),F.position({x:ue.x-x.x*ee,y:ue.y-x.y*ee}),F.batchDraw()},H=f=>{if(f.touches.length>=2||!x)return;x=null;const F=W.current;F&&(l(_e(F.scaleX())),g({x:F.x(),y:F.y()}))};return t.addEventListener("touchstart",k,{passive:!1}),t.addEventListener("touchmove",j,{passive:!1}),t.addEventListener("touchend",H),t.addEventListener("touchcancel",H),()=>{t.removeEventListener("touchstart",k),t.removeEventListener("touchmove",j),t.removeEventListener("touchend",H),t.removeEventListener("touchcancel",H)}},[me]);const Tt=c.useCallback(async t=>{const r=await rt(),u=await p.vfs.read(t),I=await(await u.getBlob()).arrayBuffer(),j=await r.getDocument({data:new Uint8Array(I)}).promise,H=j.numPages,Q=[];for(let f=0;f<H;f++){const F=await j.getPage(f+1),oe=await lt.generateThumbnailFromPage(F);Q.push({id:crypto.randomUUID(),fileId:t,pageIndex:f,thumbnailUrl:oe,rotation:0})}return await j.destroy(),{name:u.getName(),pages:Q}},[p.vfs]),Mt=c.useCallback(async(t,r)=>{const u=await p.vfs.read(t),x=r.pages.map(I=>({id:crypto.randomUUID(),fileId:t,pageIndex:I.pageIndex,thumbnailUrl:I.thumbnailUrl,rotation:I.rotation}));return{name:u.getName(),pages:x}},[p.vfs]),gt=c.useCallback(t=>{t&&(w(t.activeDocumentId),X(t.selection),B(t.interactionMode),l(_e(t.viewScale)),g(t.viewPosition))},[w,B,X]);c.useEffect(()=>{const t=()=>{E.current&&a({width:E.current.offsetWidth,height:E.current.offsetHeight})};return window.addEventListener("resize",t),t(),()=>window.removeEventListener("resize",t)},[]);const ln=c.useCallback(t=>{t.preventDefault(),R(!0)},[R]),cn=c.useCallback(t=>{t.preventDefault(),R(!1)},[R]),Ne=c.useCallback(async(t,r)=>{var j,H,Q;const u=[],x=[];if(t.length===0)return;r&&(n==null||n(t));const I=p.billing.getContext();if(!kn(p.telemetry,I.plan,t.length))return;for(let f of t){let F=null;try{if(!Ct(I,m.length+u.length).allowed){De(p.telemetry,"Free includes up to 3 workspaces. Upgrade to Pro for unlimited workspaces.",void 0,{toolId:"studio",trigger:"workspace_limit_3"});break}if(f.type.startsWith("image/")){const he=await Fo(f),{PDFDocument:tt}=await Rn(),Fe=await tt.create(),Ut=await he.arrayBuffer();let nt;if(he.type==="image/jpeg"||he.type==="image/jpg"||he.type==="image/webp")nt=await Fe.embedJpg(Ut);else if(he.type==="image/png")nt=await Fe.embedPng(Ut);else throw new Error(`Unsupported image type: ${he.type}`);const{width:Ft,height:Wt}=nt.scale(1);Fe.addPage([Ft,Wt]).drawImage(nt,{x:0,y:0,width:Ft,height:Wt});const yn=await Fe.save(),wn=f.name.substring(0,f.name.lastIndexOf("."))||f.name;f=new File([yn],`${wn}.pdf`,{type:"application/pdf"})}const ee=await rt(),ue=await p.vfs.write(f);F=ue.id;const V=await f.arrayBuffer(),be=await ee.getDocument({data:new Uint8Array(V)}).promise,et=be.numPages;if(!Bt(I,m.length+u.length,et).allowed){De(p.telemetry,Te("open larger PDFs"),void 0,{toolId:"studio",trigger:"page_limit_25"}),await be.destroy(),await p.vfs.delete(ue.id).catch(()=>{}),F=null;continue}const Ue=[];for(let he=0;he<et;he++){const tt=await be.getPage(he+1),Fe=await lt.generateThumbnailFromPage(tt);Ue.push({id:crypto.randomUUID(),fileId:ue.id,pageIndex:he,thumbnailUrl:Fe,rotation:0})}await be.destroy(),x.push(f),u.push({id:crypto.randomUUID(),name:f.name,pages:Ue,isModified:!1})}catch(oe){if(F&&await p.vfs.delete(F).catch(()=>{}),console.error("Failed to load file into Studio:",oe),Ht(oe))Oe("Storage quota exceeded. Close some documents or clear the workspace and try again.");else{const ee=oe instanceof Error?oe.message:"Failed to load file into Studio.";Oe(ee)}}}const k=Wo(m,u,Y.width,ie);for(const f of k)se(f);x.length>0&&I.plan==="basic"&&Sn(x.length),k.length>0&&(p.telemetry.track({type:"APP_FILE_UPLOADED",flowId:En(),toolId:"studio",fileCount:x.length,mimeCategory:(j=x[0])!=null&&j.type.startsWith("image/")?"image":((H=x[0])==null?void 0:H.type)==="application/pdf"?"pdf":((Q=x[0])==null?void 0:Q.type.split("/")[0])||"unknown",totalBytes:x.reduce((f,F)=>f+F.size,0),source:"studio"}),Ae(!1),ke([...m,...k]),z(p.vfs,"upload",`Uploaded ${k.length} ${k.length===1?"file":"files"}`))},[se,Y.width,z,m,ke,ie,Oe,n,p.telemetry,p.vfs]),dn=c.useCallback(async t=>{t.preventDefault(),R(!1),await Ne(Array.from(t.dataTransfer.files),!0)},[Ne,R]),un=c.useCallback(async t=>{const r=Array.from(t.target.files??[]);await Ne(r,!1),t.target.value=""},[Ne]),Ve=c.useCallback(()=>{var t;Ae(!1),(t=h.current)==null||t.click()},[]),hn=c.useCallback(()=>
3{p.telemetry.track({type:"STUDIO_EMPTY_STATE_CTA",runId:o.current,action:"upload"}),Ve()},[Ve,p.telemetry]),ft=c.useCallback(()=>{if(T.length===0)return!1;const t=new Set(T.map(u=>u.pageId)),r=[];for(const u of m)for(const x of u.pages)t.has(x.id)&&r.push(x);return r.length===0?!1:(Ee.current=r,Ke(!0),!0)},[m,T]),xt=c.useCallback(()=>{if(!M||Ee.current.length===0)return!1;const t=m.find(j=>j.id===M);if(!t)return!1;const r=p.billing.getContext(),u=t.pages.length+Ee.current.length;if(!ze(r,u).allowed)return De(p.telemetry,Te("keep adding pages"),void 0,{toolId:"studio",trigger:"page_limit_25"}),!1;const I=Ee.current.map(j=>({...j,id:crypto.randomUUID()})),k=m.map(j=>j.id!==M?j:{...j,pages:[...j.pages,...I],isModified:!0});return v(k),X(I.map(j=>({docId:M,pageId:j.id}))),!0},[M,m,p.telemetry,p.billing,v,X]),pn=c.useCallback(t=>{var x,I;const r=T.filter(k=>k.docId!==t);if(T.length>0&&r.length===0)return;const u=((x=r[0])==null?void 0:x.docId)??M??((I=m.find(k=>k.id!==t))==null?void 0:I.id);!u||u===t||Co(p,{sourceDocId:u,targetDocId:t,selection:T,method:"button"})},[M,m,p,T]),mn=c.useCallback(()=>{const t=M;if(!t)return;const r=m.find(I=>I.id===t);if(!r)return;const u={id:crypto.randomUUID(),name:`${r.name} (split)`,x:r.x+He(r.pages.length,ie)+it,y:r.y};Do(p,{sourceDocId:t,selection:T,target:u})>0&&ke(D.getState().documents)},[M,m,ke,ie,p,T]),yt=c.useCallback(t=>Po(p,{selection:T,method:t})>0,[p,T]);c.useEffect(()=>{const t=r=>{const u=r.target;if(u&&(u.tagName==="INPUT"||u.tagName==="TEXTAREA"||u.isContentEditable))return;const I=r.key.toLowerCase(),k=r.ctrlKey||r.metaKey,j=(r.ctrlKey||r.metaKey)&&I==="o",H=!r.ctrlKey&&!r.metaKey&&!r.altKey&&I==="u",Q=k&&!r.shiftKey&&!r.altKey&&I==="c",f=k&&!r.shiftKey&&!r.altKey&&I==="v";if(!k&&(r.key==="Delete"||r.key==="Backspace")&&T.length>0){yt("keyboard")&&r.preventDefault();return}if(Q){ft()&&r.preventDefault();return}if(f){xt()&&r.preventDefault();return}!j&&!H||(r.preventDefault(),Ve())};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[ft,yt,Ve,xt,T.length]);const gn=c.useCallback(t=>{const r=t.target,u=!!(r!=null&&r.findAncestor(".document",!0)),x=!!(r!=null&&r.findAncestor(".page-object",!0)),I=!!(r!=null&&r.findAncestor(".detached-page-object",!0));if(!u&&!x&&!I)return;t.evt.preventDefault();const k=W.current;if(!k)return;const j=k.getPointerPosition();j&&Le(j,t.evt.deltaY>0?"out":"in")},[Le]),fn=c.useCallback(()=>{Le({x:Y.width/2,y:Y.height/2},"in")},[Y.height,Y.width,Le]),xn=c.useCallback(()=>{Le({x:Y.width/2,y:Y.height/2},"out")},[Y.height,Y.width,Le]);c.useEffect(()=>{const t=$.state??null,r=t==null?void 0:t.studioToolResult,u=t==null?void 0:t.studioReturnContext;if(!r||r.outputIds.length===0){(t==null?void 0:t.source)==="studio"&&u&&(gt(u),J("/studio",{replace:!0,state:null}));return}let x=!1;return(async()=>{var k;const I=[];try{const{outputIds:j,studioContext:H}=r,Q=(H==null?void 0:H.documentId)??((k=H==null?void 0:H.selectedPages[0])==null?void 0:k.docId)??null,f=Q?m.find(V=>V.id===Q)??null:null,F=u!=null&&u.activeDocumentId?m.find(V=>V.id===u.activeDocumentId)??null:null,oe=f??F,ee=[],ue=p.billing.getContext();for(let V=0;V<j.length;V+=1){let re;try{re=await Tt(j[V])}catch(Ue){const he=Uo(Ue);if(r.toolId==="protect-pdf"&&he&&oe)re=await Mt(j[V],oe);else throw I.push(j[V]),Ue}if(x)break;if(f&&r.toolId==="protect-pdf"&&V>0){I.push(j[V]);continue}if((!f||r.toolId!=="protect-pdf")&&!Ct(ue,m.length+ee.length).allowed){De(p.telemetry,"Free includes up to 3 workspaces. Upgrade to Pro for unlimited workspaces.",void 0,{toolId:"studio",trigger:"workspace_limit_3"}),I.push(...j.slice(V));break}if(!ze(ue,re.pages.length).allowed){De(p.telemetry,Te("open larger PDFs"),void 0,{toolId:"studio",trigger:"page_limit_25"}),I.push(j[V]);continue}const et=f?f.x+He(f.pages.length,ie)+it+V*(nn+it):100,Lt=f?f.y:100+V*(Be(re.pages.length,ie)+50);ee.push({id:crypto.randomUUID(),name:re.name,x:et,y:Lt,pages:re.pages,isModified:!0})}if(ee.length>0){if(r.toolId==="protect-pdf"&&f){const V=ee[0],re=m.map(be=>be.id!==f.id?be:{...be,name:Lo(be.name),pages:V.pages,isModified:!0});v(re),w(f.id)}else if(f){const V=m.findIndex(re=>re.id===f.id);if(V>=0){const re=[...m];re.splice(V+1,0,...ee),v(re)}else for(const re of ee)se(re)}else for(const V of ee)se(V);await z(p.vfs,"convert",`Executed ${r.toolId}`)}X([])}catch(j){if(!x)if(console.error("Failed to apply tool result in Studio:",j),Ht(j))Oe("Storage quota exceeded.
3Close some documents or clear the workspace and try again.");else{const H=j instanceof Error?j.message:"Failed to apply tool result in Studio.";Oe(H)}}finally{for(const j of I)await p.vfs.delete(j).catch(()=>{});x||(gt(u),J("/studio",{replace:!0,state:null}))}})(),()=>{x=!0}},[se,gt,Tt,Mt,z,m,ke,$.state,J,v,w,B,X,ie,Oe,p.billing,p.telemetry]),c.useEffect(()=>{if(m.length===0){l(1),g({x:0,y:0});return}ke(m)},[m.length,ke]),c.useEffect(()=>{const t=async()=>{let u=!1;try{u=await new Promise(x=>{const I=indexedDB.open("localpdf-transfer",1);I.onupgradeneeded=()=>{const k=I.result;k.objectStoreNames.contains("transfer-files")||k.createObjectStore("transfer-files",{keyPath:"id"})},I.onsuccess=()=>{const k=I.result;if(!k.objectStoreNames.contains("transfer-files")){k.close(),x(!1);return}const j=k.transaction("transfer-files","readwrite"),H=j.objectStore("transfer-files"),Q=H.get("pending");Q.onsuccess=()=>{const f=Q.result;if(f){const{blob:F,name:oe,type:ee}=f,ue=new File([F],oe,{type:ee});H.delete("pending"),Ne([ue],!0),x(!0)}else x(!1)},j.oncomplete=()=>{k.close()},j.onerror=()=>{k.close(),x(!1)}},I.onerror=()=>{x(!1)}})}catch(x){console.error("Failed to retrieve file from IndexedDB transfer",x)}if(u)return!0;try{const x=window.sessionStorage.getItem("localpdf_transfer_file");if(x){const{name:I,type:k,dataUrl:j}=JSON.parse(x);window.sessionStorage.removeItem("localpdf_transfer_file");const Q=await(await fetch(j)).blob(),f=new File([Q],I,{type:k});return Ne([f],!0),!0}}catch(x){console.error("Failed to retrieve file from sessionStorage transfer",x)}return!1};(async()=>{var I,k;const u=await t();new URLSearchParams(window.location.search).get("upload")==="1"&&(u||((I=navigator.userActivation)!=null&&I.isActive?(k=h.current)==null||k.click():Ae(!0)),J("/studio",{replace:!0,state:$.state}))})()},[Ne,J,$.state]);const Rt={activeTool:rn,onToolClick:mt,onUpload:Ve,hasFiles:Z,onNewSpace:an,onHistoryToggle:sn,isHistoryOpen:O,plan:te.plan,attentionOnUpload:je,selectedPageCount:T.length,activeWorkspaceName:G==null?void 0:G.name,mergeTargets:pe,onMergePages:pn,onSplitPages:mn,onDeletePages:()=>{yt("button")}};return e.jsxs("div",{ref:E,className:`studio-shell-container ${K?"dragging":""}`,onDragOver:ln,onDragLeave:cn,onDrop:dn,children:[e.jsxs("div",{className:"studio-shell-workspace",children:[e.jsx(go,{...Rt}),me&&Z&&e.jsxs("button",{type:"button",className:`studio-mobile-tools-fab${ne?" active":""}`,onClick:()=>{Xe(t=>!t)},"aria-expanded":ne,"aria-label":"Open tools",children:[e.jsx(ge,{name:"tool",size:18}),e.jsx("span",{children:"Tools"})]}),e.jsxs("div",{className:"studio-shell-canvas",children:[e.jsx(On,{ref:W,width:Y.width,height:Y.height,pixelRatio:N,draggable:Z,x:b.x,y:b.y,scaleX:L,scaleY:L,onWheel:gn,onDragEnd:t=>{t.target===t.currentTarget&&g({x:t.currentTarget.x(),y:t.currentTarget.y()})},children:e.jsxs(Ln,{children:[e.jsx(le,{x:-5e3,y:-5e3,width:1e4,height:1e4,fillPatternImage:ht,fillPatternRepeat:"repeat"}),Z&&e.jsxs(e.Fragment,{children:[m.map(t=>e.jsx(co,{doc:t,gridColumnsOverride:me?ie:void 0},t.id)),de.map(t=>e.jsx(uo,{page:t},t.id))]})]})}),!Z&&e.jsxs("div",{className:"studio-empty-state","aria-live":"polite",children:[e.jsx("div",{className:"studio-empty-state-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsx("h2",{className:"studio-empty-state-title",children:Je?"Upload a PDF to get started":"Drop a PDF to get started"}),e.jsxs("p",{className:"studio-empty-state-copy",children:["All processing happens locally.",e.jsx("br",{}),"Your files never leave your device."]}),e.jsx("div",{className:"studio-empty-state-actions",children:e.jsxs("button",{type:"button",className:`studio-upload-btn studio-empty-state-upload-btn${je?" studio-upload-btn--attention":""}`,onClick:hn,children:[e.jsx(ge,{name:"upload",size:18}),"Upload PDF"]})}),Je?e.jsx("div",{className:"studio-empty-state-hints","aria-label":"Studio tips",children:e.jsx("span",{className:"studio-empty-state-hint-sep",children:"Tap Tools to merge, split, delete or convert pages"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"studio-empty-state-hints","aria-label":"Studio shortcuts",children:[e.jsx("span",{className:"studio-empty-state-hint",children:"U"}),e.jsx("span",{className:"studio-empty-state-hint-sep",children:"upload"}),e.jsx("span",{className:"studio-empty-state-hint-sep",children:"·"}),e.jsx("span",{className:"studio-empty-state-hint",children:"âO"}),e.jsx("span",{className:"studio-empty-state-hint-sep",children:"open"}),e.jsx("span",{className:"studio-empty-state-hint-sep",children:"·"}),e.jsx("span",{className:"studio-empty-state-hint",children:"drag & drop"})]}),e.jsx("div",{className:"studio-empty-state-hints","aria-label":"Studio tips",children:e.jsx("span",{className:"studio-empty-state-hint-sep",children:"Drag a page onto another workspace to merge them"})})]})]}
3),e.jsxs("div",{className:"studio-viewport-controls animate-fade-in",children:[e.jsx("button",{className:"studio-viewport-btn",onClick:xn,title:"Zoom out",disabled:!Z,children:"â"}),e.jsxs("span",{className:"studio-viewport-scale",children:[Math.round(L*100),"%"]}),e.jsx("button",{className:"studio-viewport-btn",onClick:fn,title:"Zoom in",disabled:!Z,children:"+"}),e.jsx("button",{className:"studio-viewport-btn studio-viewport-btn-fit",onClick:()=>ke(m),title:"Fit to screen",disabled:!Z,children:"Fit"}),e.jsx("span",{className:"studio-viewport-bar-divider studio-viewport-desktop-only"}),e.jsxs("span",{className:"studio-viewport-desktop-only studio-viewport-grid-group",children:[e.jsx("button",{className:`studio-viewport-btn ${y===3?"active":""}`,onClick:()=>S(3),title:"Grid: 3 columns",disabled:!Z,children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7"})]})}),e.jsx("button",{className:`studio-viewport-btn ${y===5?"active":""}`,onClick:()=>S(5),title:"Grid: 5 columns overview",disabled:!Z,children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"9",x2:"21",y2:"9"}),e.jsx("line",{x1:"3",y1:"15",x2:"21",y2:"15"}),e.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"}),e.jsx("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})})]}),e.jsx("span",{className:"studio-viewport-bar-divider studio-viewport-desktop-only"}),e.jsx("button",{className:"studio-viewport-btn studio-viewport-desktop-only",onClick:()=>{ft()},title:"Copy selected pages (Ctrl/Cmd+C)",disabled:T.length===0,style:T.length===0?{opacity:.4}:void 0,children:"Copy"}),e.jsx("button",{className:"studio-viewport-btn studio-viewport-desktop-only",onClick:()=>{xt()},title:"Paste copied pages (Ctrl/Cmd+V)",disabled:T.length===0||!M||!Ye,style:!Ye||T.length===0?{opacity:.4}:void 0,children:"Paste"}),e.jsx("span",{className:"studio-viewport-spacer"}),T.length>0&&e.jsxs("span",{className:"studio-viewport-selection-count",title:`${T.length} selected pages`,children:[T.length," selected"]}),e.jsx("button",{className:`studio-viewport-btn ${O?"active":""}`,onClick:()=>C(!O),title:O?"Hide history":"Show history",children:"History"})]})]})]}),e.jsx("input",{ref:h,type:"file",accept:"application/pdf,image/png,image/jpeg,image/webp",multiple:!0,className:"hidden",onChange:un}),O&&e.jsx(yo,{}),e.jsx(bo,{stageRef:W}),me&&e.jsx(fo,{open:ne,onClose:()=>{Xe(!1)},...Rt}),Ie&&Pt.createPortal(e.jsx("div",{className:"studio-tool-overlay",children:e.jsx(c.Suspense,{fallback:null,children:Ie==="edit"?e.jsx(jo,{onClose:Qe}):Ie==="auto-toc"?e.jsx(So,{onClose:Qe,inputFileId:((At=G==null?void 0:G.pages[0])==null?void 0:At.fileId)??"",fileName:(G==null?void 0:G.name)??"document.pdf",runtime:p}):Ie==="pdf-info"?e.jsx(Eo,{onClose:Qe,inputFileId:((Ot=G==null?void 0:G.pages[0])==null?void 0:Ot.fileId)??"",fileName:(G==null?void 0:G.name)??"document.pdf",runtime:p}):e.jsx(ko,{onClose:Qe,initialTool:Ie})})}),document.body),qe&&e.jsx(Io,{toolId:"studio",toolName:"Studio Tool",reason:"PRO_REQUIRED",details:qe,onClose:()=>ye(null)}),U&&(()=>{const t=m.find(r=>r.id===U);return t?e.jsx(Hn,{type:"prompt",title:"Rename workspace",defaultValue:t.name,onConfirm:r=>{Re(U,{name:r}),z(p.vfs,"space_rename",`Renamed to ${r}`),q(null)},onCancel:()=>q(null)}):null})()]})}export{es as StudioShell};
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.