PageSourceSearch

https://www.ihatepdf.cv/assets/PdfEditorLabTool-TFYj1wTy.js

js ihatepdf.cv collected 2026-09-30 17:26:39 UTC 67,677 bytes, 3 lines download raw bytes

1import{r as a,j as t}from"./react-vendor-D653VjAu.js";import{l as Zn}from"./loaders-DEO62ofM.js";import{e as Jn,b as qn,a as Qn,c as es,d as Vt,s as ts,f as ns,r as ss,g as rs,m as as,h as ls,i as Zt,j as Jt,k as os,l as is,v as cs,P as Ct,n as st,o as qt,C as ds,E as us,M as hs,T as pn,H as ps,p as xs,q as xn,A as fs,t as gs,I as fn,u as gn,S as ms,R as bs,B as mn,w as bn,x as Pe,y as ws,z as ys,D as js,F as wn,G as ks,J as Qt,K as en,L as vs,N as Ns,O as Cs,Q as Ss,U as yn,V as Rs,W as Ps}from"./images-YZCR5j67.js";import{t as rt,e as tn,r as Es,a as $s}from"./signature-D5L3rz-k.js";import{F as zs}from"./flask-conical-ChzGJBL8.js";import{U as nn,E as Ds,D as Ts,T as sn,a as Fs}from"./upload-cmGtel1R.js";import{F as Ms,Z as Ls,a as Os,L as rn,R as jn}from"./zoom-out-uk1-4cLZ.js";import{U as Is,R as As,L as Ws,X as Et,C as Hs,a as Bs,P as Us}from"./x-COszN7pq.js";import{C as Ks}from"./chevron-right-y--aGESZ.js";import{P as _s,S as kn,G as vn}from"./square-6sX9BSu1.js";import{C as an}from"./chevron-up-BkEex09_.js";import{C as $t}from"./chevron-down-5QTsBsYM.js";import{C as Xs}from"./circle-check-Pzy2jfHg.js";import"./index-B3kPJoIs.js";const Me=[.6,.75,.9,1,1.25,1.5,2,2.5],lt=u=>{const m=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(u||"");return m?[parseInt(m[1],16),parseInt(m[2],16),parseInt(m[3],16)]:[0,0,0]},Ys={serif:'Georgia, "Times New Roman", Times, serif',"sans-serif":'"Helvetica Neue", Helvetica, Arial, sans-serif',monospace:'ui-monospace, Menlo, Consolas, "Courier New", monospace'},zt=u=>ts(u);function Gs(u,m,b){const y=[];let p=null;const F=(k,h)=>{if(!k)return;const N=b.has(h)&&h||p||m;if(!N)return;p=N;const E=y[y.length-1];if(E&&E.key===N)E.text+=k;else{const M=b.get(N);if(!M)return;y.push({...M,text:k,key:N})}},C=k=>{for(const h of k.childNodes)if(h.nodeType===Node.TEXT_NODE){const N=h.parentElement?.closest("[data-style]");F(h.nodeValue,N?.dataset?.style)}else h.nodeName==="BR"?F(`
2`,h.parentElement?.closest("[data-style]")?.dataset?.style):C(h)};return C(u),y}function Vs(u){const m=window.getSelection();if(!m||!m.rangeCount||!u.contains(m.anchorNode))return null;const b=m.getRangeAt(0).cloneRange();return b.selectNodeContents(u),b.setEnd(m.getRangeAt(0).endContainer,m.getRangeAt(0).endOffset),b.toString().length}function Zs(u,m){if(m==null)return;const b=document.createTreeWalker(u,NodeFilter.SHOW_TEXT);let y=0,p;for(;p=b.nextNode();){const F=p.nodeValue.length;if(y+F>=m){const C=document.createRange();C.setStart(p,m-y),C.collapse(!0);const k=window.getSelection();k.removeAllRanges(),k.addRange(C);return}y+=F}u.focus({preventScroll:!0})}function ln(u,m,b){u.style.fontFamily=m.fontFamily,u.style.fontWeight=m.fontWeight,u.style.fontStyle=m.fontStyle,u.style.fontSize=`${m.fontSizePx}px`,u.style.lineHeight=`${b}px`,u.style.wordSpacing=m.wordSpacing?`${m.wordSpacing}px`:"",u.style.letterSpacing=m.letterSpacing?`${m.letterSpacing}px`:""}function on(u,m){const b=document.createDocumentFragment();for(const y of m){const p=document.createElement("span");p.dataset.style=zt(y),p.textContent=y.text,b.appendChild(p)}u.replaceChildren(b)}const Js={justifyContent:"safe center"},St=4,cn=[{id:"select",label:"Select",Icon:hs,key:"V"},{id:"text",label:"Text box",Icon:pn,key:"T"},{id:"highlight",label:"Highlight",Icon:ps,key:"H"},{id:"ink",label:"Draw",Icon:_s,key:"D"},{id:"rect",label:"Rectangle",Icon:kn,key:"R"},{id:"ellipse",label:"Ellipse",Icon:xs,key:"O"},{id:"line",label:"Line",Icon:xn,key:"L"},{id:"arrow",label:"Arrow",Icon:fs,key:"A"},{id:"whiteout",label:"Erase area",Icon:gs,key:"E"},{id:"image",label:"Image",Icon:fn,key:"I"},{id:"signature",label:"Signature",Icon:gn,key:"S"}],dn=[{id:"'Segoe Script','Bradley Hand','Snell Roundhand',cursive",label:"Casual"},{id:"'Snell Roundhand','Apple Chancery','Lucida Handwriting',cursive",label:"Formal"},{id:"'Brush Script MT','Segoe Script',cursive",label:"Brush"},{id:"'Courier New',monospace",label:"Typed"}],Nn=["nw","n","ne","e","se","s","sw","w"],qs=new Date().toTimeString().slice(0,8),at=new Set(["highlight","whiteout"]),Rt={left:yn,center:Ss,right:Cs,justify:Ns},Qs=[{id:"auto",label:"Original"},{id:"sans-serif",label:"Sans"},{id:"serif",label:"Serif"},{id:"monospace",label:"Mono"}];function wr(){const[u,m]=a.useState(""),[b,y]=a.useState(null),[p,F]=a.use
2State(null),[C,k]=a.useState(0),[h,N]=a.useState(1),[E,M]=a.useState(1),[x,W]=a.useState(""),[te,B]=a.useState(""),[c,ue]=a.useState(null),H=a.useRef(null),K=a.useRef(null),Q=a.useRef(null),_=a.useRef(null),ne=a.useRef(null),he=a.useRef(new Map),X=a.useRef(new Map),je=a.useRef(new Map),j=a.useRef(new Map),[Y,g]=a.useState({}),[$,D]=a.useState({}),[U,I]=a.useState(null),[ae,se]=a.useState(0),G=a.useRef({past:[],future:[]}),[pe,ot]=a.useState({past:0,future:0}),[le,Oe]=a.useState({}),[ee,me]=a.useState("select"),[oe,xe]=a.useState(null),[Z,it]=a.useState(null),ct=a.useRef(null),Dt=a.useRef(null),Ee=a.useRef(!1),[de,Ne]=a.useState(null),[fe,Ie]=a.useState({}),[Ae,Tt]=a.useState(!1),[We,Cn]=a.useState({}),[Ft,He]=a.useState(!1),[$e,Sn]=a.useState(""),[Mt,Rn]=a.useState(""),[ze,dt]=a.useState(null),[Be,Pn]=a.useState(!1),[ut,ht]=a.useState(!1),[En,Ue]=a.useState(!1),Ke=a.useRef(null),[ge,pt]=a.useState(null),xt=a.useRef(null),_e=a.useCallback(e=>`${h}:${e}`,[h]);a.useEffect(()=>{},[]),a.useEffect(()=>{const e=document.title;document.title="PDF editor lab — internal POC";let n=document.querySelector('meta[name="robots"]');const s=!n;n||(n=document.createElement("meta"),n.name="robots",document.head.appendChild(n));const r=n.content;return n.content="noindex, nofollow",()=>
2{document.title=e,s?n.remove():n.content=r}},[]);const Ce=a.useCallback(()=>JSON.stringify({edits:Y,objects:le,pageOrder:de,pageRotate:fe}),[Y,le,de,fe]),Xe=a.useCallback(e=>{const n=JSON.parse(e);g(n.edits||{}),Oe(n.objects||{}),Ne(n.pageOrder??null),Ie(n.pageRotate||{}),I(null),xe(null),se(s=>s+1)},[]),T=a.useCallback(()=>{G.current.past.push(Ce()),G.current.past.length>80&&G.current.past.shift(),G.current.future.length=0,ot({past:G.current.past.length,future:0})},[Ce]),De=T,ft=a.useCallback(()=>{const e=G.current;e.past.length&&(e.future.push(Ce()),Xe(e.past.pop()),ot({past:e.past.length,future:e.future.length}))},[Ce,Xe]),gt=a.useCallback(()=>{const e=G.current;e.future.length&&(e.past.push(Ce()),Xe(e.future.pop()),ot({past:e.past.length,future:e.future.length}))},[Ce,Xe]),[Ye,mt]=a.useState({}),be=a.useMemo(()=>{if(!c?.docImages)return[];const e=c.viewport.scale;return c.docImages.map(n=>{const s=Ye[`${h}:${n.key}`];return{...n,x:s?.x!=null?s.x*e:n.x,y:s?.y!=null?s.y*e:n.y,w:s?.w!=null?s.w*e:n.w,h:s?.h!=null?s.h*e:n.h,origin:{x:n.x,y:n.y,w:n.w,h:n.h},edit:s||null,dirty:!!s,removed:!!s?.removed,replacedWith:s?.dataUrl||null}})},[c,Ye,h]),L=a.useMemo(()=>be.find(e=>e.key===oe)||null,[be,oe]),bt=a.useCallback((e,n,{history:s=!0}={})=>{s&&T(),mt(r=>{const l=`${h}:${e}`;return{...r,[l]:{...r[l]||{},...n}}})},[h,T]),$n=a.useCallback(e=>{T(),mt(n=>{const s={...n};return delete s[`${h}:${e}`],s})},[h,T]),Lt=a.useRef(null),zn=a.useCallback(async e=>{if(!e||!L)return;const n=await new Promise(r=>{const l=new FileReader;l.onload=()=>r(l.result),l.readAsDataURL(e)}),s=c.viewport.scale;bt(L.key,{dataUrl:n,x:L.x/s,y:L.y/s,w:L.w/s,h:L.h/s})},[L,c,bt]),Ot=async e=>{if(e){B(""),pt(null),W("Opening…");try{const n=await Zn();await ys();const s=new Uint8Array(await e.arrayBuffer());y(s);const r=await n.getDocument({data:s.slice(0),fontExtraProperties:!0}).promise;F(r),k(r.numPages),N(1),m(e.name),g({}),he.current.clear(),j.current.clear(),D({}),Oe({}),xe(null),Ne(null),Ie({}),G.current={past:[],future:[]}}catch(n){B(/password|encrypt/i.test(n?.message||"")?"This PDF is password-protected — remove the password first.":`Could not open the file: ${n.message}`)}finally{W("")}}};a.useEffect(()=>{if(!p)return;let e=!1;return(async()=>{W("Reading page…");try{const n=await p.getPage(h),s=Math.min(window.devicePixelRatio||1,2),r=n.getViewport({scale:E}),l=n.getViewport({scale:E*s}),i=H.current;if(!i)return;if(i.width=l.width,i.height=l.height,i.style.width=`${r.width}px`,i.style.height=`${r.height}px`,ne.current)try{ne.current.cancel()}catch{}const f=i.getContext("2d",{willReadFrequently:!0});if(f.fillStyle="#fff",f.fillRect(0,0,i.width,i.height),ne.current=n.render({canvasContext:f,viewport:l}),await ne.current.promise,e)return;try{await document.fonts.ready}catch{}if(e)return;const{items:o,fonts:d}=await Jn(n,r);if(e)return;const w=qn(o);for(const R of w)R.fontDesc=d.get(R.fontKey)||null;let z=[];try{z=await Qn(n,r);for(const R of z)R.dataUrl=es(R.bitmap,R.naturalW,R.naturalH)}catch{}if(e)return;const S=K.current;S&&(S.width=l.width,S.height=l.height,S.style.width=`${r.width}px`,S.style.height=`${r.height}px`,S.getContext("2d").clearRect(0,0,S.width,S.height)),he.current.clear(),ue({viewport:r,blocks:w,fonts:d,docImages:z,dpr:s,w:r.width,h:r.height}),I(null),se(R=>R+1)}catch(n){n?.name!=="RenderingCancelledException"&&B(`Render failed: ${n.message}`)}finally{e||W("")}})(),()=>{e=!0}},[p,h,E]);const O=a.useMemo(()=>{if(!c)return[];const e=c.viewport.scale;return c.blocks.map(n=>{const s=Y[`${h}:${n.id}`]||null,r=!!s?.flowing,l=s?.runs??Vt(n,{softBreak:r?" ":`
3`}),i=n.fontDesc,f=s?.sizePt?s.sizePt*e/n.fontSize:1,o=Math.max(n.fontSize*f*1.02,n.leading*f),d=new Map;for(const ce of l){const P=zt(ce),Qe=d.get(P);Qe?Qe.text+=ce.text:d.set(P,{run:ce,text:ce.text})}const w=ns(n),z=new Map;for(const[ce,{run:P,text:Qe}]of d){const et=c.fonts.get(P.fontKey)||i,Fe=P.sizePt!=null?P.sizePt*e:P.fontSize*f;let re=ss(et,Qe);const Nt=P.family&&P.family!=="auto"?P.family:null;Nt?re={...re,mode:"substituted",klass:Nt,cssFamily:Ys[Nt],cssWeight:P.bold??et?.bold?"700":"400",cssStyle:P.italic??et?.italic?"italic":"normal",reason:"font replaced by hand"}:(P.bold!=null||P.italic!=null)&&(re={...re,cssWeight:P.bold?"700":P.bold===!1?"400":re.cssWeight,cssStyle:P.italic?"italic":P.italic===!1?"normal":re.cssStyle});const Gn=rs(re,Fe);let Xt=0,Yt=0;const Re=P.bold!=null||P.italic!=null||P.family||P.sizePt!=null?null:w.get(`${P.fontKey}|${P.fontSize.toFixed(2)}`);if(Re&&f===1&&Re.width>0){const Vn=as(Re.text,re,Fe),tt=Re.width-Vn,nt=(Re.text.match(/ /g)||[]).length;if(nt>0&&Math.abs(tt/nt)<.6*Fe)Xt=tt/nt;else if(!nt){const Gt=Math.max(Re.text.length,1);Math.abs(tt/Gt)<.09*Fe&&(Yt=tt/Gt)}}
3z.set(ce,{key:ce,run:P,desc:et,resolved:re,cssFont:Gn,fontSizePx:Fe,wordSpacing:Xt,letterSpacing:Yt,color:P.color||null,fontFamily:re.cssFamily,fontWeight:re.cssWeight,fontStyle:re.cssStyle})}const S=ls([...z.values()].map(ce=>ce.cssFont),o),R=Math.cos(n.angle),ye=Math.sin(n.angle),Je=n.firstBaseline-S,qe=(s?.dxPt||0)*e,vt=(s?.dyPt||0)*e,_t=z.get(zt({fontKey:n.fontKey,fontSize:n.fontSize}))||[...z.values()][0]||null;return{block:n,edit:s,runs:l,desc:i,styles:z,dominant:_t,lineHeightPx:o,fontSizePx:_t?.fontSizePx??n.fontSize,left:n.u0*R-Je*ye+qe,top:n.u0*ye+Je*R+vt,width:(s?.widthPt??n.measure/e)*e+(s?.widthPt?0:2),align:s?.align||n.align,color:s?.color||$[`${h}:${n.id}`]||null,embedded:[...z.values()].every(ce=>ce.resolved.mode==="embedded"),flowing:r,dirty:!!s&&(s.runs!=null||s.dirty)}})},[c,Y,$,h]);a.useEffect(()=>{},[c,O,Y,b,U]);const Dn=a.useMemo(()=>{const e=new Map;for(const n of O)e.set(n.block.id,n);return e},[O]),Se=a.useCallback(e=>{const n=_e(e.id),s=he.current;if(s.has(n))return s.get(n);const r=H.current;if(!r||!c)return null;const l=2+.1*e.fontSize,i={x:e.left-l,y:e.top-l,w:e.width+l*2,h:e.height+l*2},f=Zt(r,i,c.dpr);return s.set(n,f),f},[_e,c]),It=a.useRef(new Map),Ge=a.useCallback(e=>{const n=`${h}:${e.key}`,s=It.current;if(s.has(n))return s.get(n);const r=H.current;if(!r||!c)return null;const l=1,i={x:e.origin.x-l,y:e.origin.y-l,w:e.origin.w+l*2,h:e.origin.h+l*2},f=Zt(r,i,c.dpr),o={rect:i,color:f.background};return s.set(n,o),o},[h,c]);a.useEffect(()=>{It.current.clear()},[c]),a.useEffect(()=>{const e=K.current;if(!e||!c)return;const n=e.getContext("2d");n.clearRect(0,0,e.width,e.height);const s=c.dpr;for(const r of O){const l=r.block.id===U;if(!r.dirty&&!l)continue;const i=Se(r.block);i&&(i.flat?(n.fillStyle=`rgb(${i.flat[0]},${i.flat[1]},${i.flat[2]})`,n.fillRect(i.rect.x*s,i.rect.y*s,i.rect.w*s,i.rect.h*s)):n.drawImage(i.patch,i.rect.x*s,i.rect.y*s))}for(const r of be){if(!r.dirty)continue;const l=Ge(r);l&&(n.fillStyle=`rgb(${l.color.join(",")})`,n.fillRect(l.rect.x*s,l.rect.y*s,l.rect.w*s,l.rect.h*s))}},[O,U,c,Se,be,Ge]),a.useEffect(()=>{for(const e of O){const n=X.current.get(e.block.id);n&&on(n,e.runs)}},[ae]),a.useEffect(()=>{for(const e of O){const n=X.current.get(e.block.id);if(!n)continue;const s=e.dirty||e.block.id===U,r=`rgb(${(e.color||[0,0,0]).join(",")})`;for(const l of n.querySelectorAll("[data-style]")){const i=e.styles.get(l.dataset.style)||e.dominant;i&&(ln(l,i,e.lineHeightPx),l.style.color=s?i.color?`rgb(${i.color.join(",")})`:r:"transparent")}}},[O,U]);const Tn=a.useCallback((e,n,{history:s=!0}={})=>{s&&De(),g(r=>{const l=`${h}:${e}`,i=r[l]||{};return{...r,[l]:{...i,...n}}})},[h,De]),At=a.useCallback(e=>{I(e.block.id);const n=_e(e.block.id);if(!$[n]){const s=Se(e.block);s&&D(r=>r[n]?r:{...r,[n]:s.ink})}},[Se,_e,$]),Ve=a.useCallback(e=>{const n=X.current.get(e.block.id);if(!n)return;const s=Vs(n),r=Vt(e.block,{softBreak:" "});on(n,r),n.style.whiteSpace="pre-wrap";for(const l of n.querySelectorAll("[data-style]")){const i=e.styles.get(l.dataset.style)||e.dominant;i&&(ln(l,i,e.lineHeightPx),l.style.color=i.color?`rgb(${i.color.join(",")})`:`rgb(${(e.color||[0,0,0]).join(",")})`)}Zs(n,s),g(l=>{const i=`${h}:${e.block.id}`;return{...l,[i]:{...l[i]||{},flowing:!0}}})},[h]),Fn=a.useCallback((e,n)=>{if(e.flowing||n.metaKey||n.ctrlKey||n.altKey)return;(n.key.length===1||n.key==="Backspace"||n.key==="Delete"||n.key==="Enter")&&Ve(e)},[Ve]),Wt=a.useCallback(()=>{ht(!0),clearTimeout(Ke.current),Ke.current=setTimeout(()=>ht(!1),1500)},[]);a.useEffect(()=>{if(!ut)return;const e=()=>{clearTimeout(Ke.current),ht(!1)};return window.addEventListener("pointermove",e,{once:!0}),()=>window.removeEventListener("pointermove",e)},[ut]),a.useEffect(()=>()=>clearTimeout(Ke.current),[]);const Mn=a.useCallback((e,n)=>{Wt();const s=e.dominant?.key||null,r=new Map([...e.styles.values()].map(i=>[i.key,i.run])),l=Gs(n.currentTarget,s,r);g(i=>{const f=`${h}:${e.block.id}`;return{...i,[f]:{...i[f]||{},runs:l,dirty:!0}}})},[h,Wt]),Ln=a.useCallback((e,n)=>{const s=X.current.get(e.block.id),r=s?Jt(s):null,l=e.runs.reduce((d,w)=>d+w.text.length,0),{start:i,end:f}=r||{start:0,end:l};T();const o=os(e.runs,i,f,n);g(d=>{const w=`${h}:${e.block.id}`;return{...d,[w]:{...d[w]||{},runs:o,dirty:!0}}}),se(d=>d+1),r&&requestAnimationFrame(()=>{const d=X.current.get(e.block.id);d&&is(d,i,f)})},[h,T]),On=a.useCallback((e,n)=>{const s=X.current.get(e.block.id),r=s?Jt(s):null,l=e.runs.reduce((o,d)=>o+d.text.length,0),{start:i,end:f}=r||{start:0,end:l};return cs(e.runs,i,f,n)},[]),In=a.useCallback(e=>{De(),g(n=>{const s={...n};return delete s[`${h}:${e}`],s}),I(null),se(n=>n+1)},[h,De]);a.useEffect(()=>{const e=s=>{const r=xt.current;if(!r||!c)return;if(!r.live){if(Math.hypot(s.clientX-r.x0,s.clientY-r.y0)<St)return;r.live=!0,r.snapshot()}
3const l=c.viewport.scale,i=(s.clientX-r.x0)/l,f=(s.clientY-r.y0)/l;g(o=>{const d=`${h}:${r.id}`,w=o[d]||{};return r.mode==="move"?{...o,[d]:{...w,dxPt:r.dx0+i,dyPt:r.dy0+f,dirty:!0}}:{...o,[d]:{...w,widthPt:Math.max(20,r.w0+i),dirty:!0}}})},n=()=>{xt.current=null};return window.addEventListener("pointermove",e),window.addEventListener("pointerup",n),()=>{window.removeEventListener("pointermove",e),window.removeEventListener("pointerup",n)}},[h,c]);const Ht=(e,n,s)=>{s.preventDefault(),s.stopPropagation();const r=c.viewport.scale;xt.current={id:e.block.id,mode:n,x0:s.clientX,y0:s.clientY,dx0:e.edit?.dxPt||0,dy0:e.edit?.dyPt||0,w0:e.width/r,live:!1,snapshot:De}},Te=a.useMemo(()=>le[h]||[],[le,h]),v=a.useMemo(()=>Te.find(e=>e.id===oe)||null,[Te,oe]),Ze=a.useCallback((e,n)=>{const s=H.current;if(!s||!c)return{x:0,y:0};const r=s.getBoundingClientRect(),l=c.viewport.scale;return{x:(e-r.left)/l,y:(n-r.top)/l}},[c]),we=a.useCallback((e,{history:n=!0}={})=>{n&&T(),Oe(s=>({...s,[h]:e(s[h]||[])}))},[h,T]),ke=a.useCallback(e=>{we(n=>[...n,e]),xe(e.id)},[we]),ie=a.useCallback((e,n,s)=>we(r=>r.map(l=>l.id===e?{...l,...n}:l),s),[we]),wt=a.useCallback(e=>{we(n=>n.filter(s=>s.id!==e)),xe(null)},[we]),Bt=a.useCallback((e,n)=>we(s=>{const r=s.findIndex(o=>o.id===e);if(r<0)return s;const l=Math.max(0,Math.min(s.length-1,r+n));if(r===l)return s;const i=[...s],[f]=i.splice(r,1);return i.splice(l,0,f),i}),[we]),An=a.useCallback(e=>{if(e.button!==0||!c)return;if(ee==="select"){(e.target===e.currentTarget||e.target.tagName==="CANVAS")&&(xe(null),I(null));return}if(ee==="image"){Dt.current?.click();return}if(ee==="signature"){Ue(!0);return}e.preventDefault();const n=Ze(e.clientX,e.clientY),s=Ct.has(ee)?st(ee,{points:[[n.x,n.y]]}):st(ee,{x:n.x,y:n.y,w:0,h:0});s._origin=n,it(s)},[ee,c,Ze]);a.useEffect(()=>{if(!Z)return;const e=s=>{const r=Ze(s.clientX,s.clientY);it(l=>{if(!l)return l;if(l.kind==="ink")return{...l,points:[...l.points,[r.x,r.y]]};if(Ct.has(l.kind))return{...l,points:[l._origin&&[l._origin.x,l._origin.y],[r.x,r.y]].filter(Boolean)};let{x:i,y:f,w:o,h:d}=js(l._origin.x,l._origin.y,r.x,r.y);if(s.shiftKey){const w=Math.max(o,d);r.x<l._origin.x&&(i=l._origin.x-w),r.y<l._origin.y&&(f=l._origin.y-w),o=w,d=w}return{...l,x:i,y:f,w:o,h:d}})},n=()=>{it(s=>{if(!s)return null;const r=wn(s),l=Ct.has(s.kind)?s.points.length>1&&(r.w>2||r.h>2):r.w>3&&r.h>3;if(s.kind==="text"){const i=r.w>12&&r.h>8?r:{x:r.x,y:r.y,w:180,h:22},{_origin:f,...o}=s;ke({...o,...i,text:""})}else if(l){const{_origin:i,...f}=s;ke(s.kind==="ink"?{...f,points:ks(s.points)}:f)}return null}),me(s=>Ee.current?s:"select")};return window.addEventListener("pointermove",e),window.addEventListener("pointerup",n,{once:!0}),()=>{window.removeEventListener("pointermove",e),window.removeEventListener("pointerup",n)}},[Z,Ze,ke]),a.useEffect(()=>{const e=s=>{const r=ct.current;if(!r||!c)return;const l=c.viewport.scale,i=(s.clientX-r.x0)/l,f=(s.clientY-r.y0)/l;if(!r.live){if(Math.hypot(s.clientX-r.x0,s.clientY-r.y0)<St)return;r.live=!0,T()}Oe(o=>({...o,[r.page]:(o[r.page]||[]).map(d=>d.id!==r.id?d:r.handle?Qt(r.base,r.handle,i,f):en(r.base,i,f))}))},n=()=>{ct.current=null};return window.addEventListener("pointermove",e),window.addEventListener("pointerup",n),()=>{window.removeEventListener("pointermove",e),window.removeEventListener("pointerup",n)}},[c,T]);const yt=a.useRef(null);a.useEffect(()=>{const e=s=>{const r=yt.current;if(!r||!c)return;const l=c.viewport.scale;if(!r.live){if(Math.hypot(s.clientX-r.x0,s.clientY-r.y0)<St)return;r.live=!0,T()}const i=(s.clientX-r.x0)/l,f=(s.clientY-r.y0)/l,o=r.handle?Qt({kind:"image",...r.base},r.handle,i,f,8):en({kind:"image",...r.base},i,f);mt(d=>({...d,[r.k]:{...d[r.k]||{},x:o.x,y:o.y,w:o.w,h:o.h}}))},n=()=>{yt.current=null};return window.addEventListener("pointermove",e),window.addEventListener("pointerup",n),()=>{window.removeEventListener("pointermove",e),window.removeEventListener("pointerup",n)}},[c,T]);const Wn=a.useCallback((e,n,s)=>{s.preventDefault(),s.stopPropagation(),xe(e.key),I(null);const r=c.viewport.scale;yt.current={k:`${h}:${e.key}`,handle:n,base:{x:e.x/r,y:e.y/r,w:e.w/r,h:e.h/r},x0:s.clientX,y0:s.clientY,live:!1}},[h,c]),jt=a.useCallback((e,n,s)=>{s.preventDefault(),s.stopPropagation(),xe(e.id),ct.current={id:e.id,page:h,handle:n,base:e,x0:s.clientX,y0:s.clientY,live:!1}},[h]),Hn=a.useCallback(e=>{if(Ue(!1),me("select"),!e||!c)return;const n=e.toDataURL("image/png"),s=c.w/c.viewport.scale,r=c.h/c.viewport.scale,l=Math.min(s*.34,e.width),i=e.height/e.width*l;ke(st("image",{x:(s-l)/2,y:Math.min(r-i-24,r*.72),w:l,h:i,dataUrl:n,naturalW:e.width,naturalH:e.height}))},[c,ke]),Bn=a.useCallback(async e=>{if(!e||!c)return;const n=await new Promise(w=>{const z=new FileReader;z.onload=()=>
3w(z.result),z.readAsDataURL(e)}),s=await new Promise((w,z)=>{const S=new Image;S.onload=()=>w(S),S.onerror=z,S.src=n}),r=c.w/c.viewport.scale,l=c.h/c.viewport.scale,i=r*.5,f=Math.min(1,i/s.naturalWidth),o=s.naturalWidth*f,d=s.naturalHeight*f;ke(st("image",{x:(r-o)/2,y:(l-d)/2,w:o,h:d,dataUrl:n,naturalW:s.naturalWidth,naturalH:s.naturalHeight})),me("select")},[c,ke]),V=a.useMemo(()=>de||Array.from({length:C},(e,n)=>n),[de,C]),Un=a.useCallback((e,n)=>{T(),Ie(s=>({...s,[e]:(((s[e]||0)+n)%360+360)%360}))},[T]),Kn=a.useCallback(e=>{V.length<=1||(T(),Ne(V.filter(n=>n!==e)))},[V,T]),_n=a.useCallback(e=>{T();const n=V.indexOf(e),s=[...V];s.splice(n+1,0,e),Ne(s)},[V,T]),Ut=a.useCallback((e,n)=>{const s=V.indexOf(e),r=s+n;if(s<0||r<0||r>=V.length)return;T();const l=[...V],[i]=l.splice(s,1);l.splice(r,0,i),Ne(l)},[V,T]);a.useEffect(()=>{if(!Ae||!p)return;let e=!1;return(async()=>{for(const n of V){if(e)return;if(!We[n])try{const s=await p.getPage(n+1),r=s.getViewport({scale:.22}),l=document.createElement("canvas");if(l.width=r.width,l.height=r.height,await s.render({canvasContext:l.getContext("2d"),viewport:r}).promise,e)return;Cn(i=>({...i,[n]:l.toDataURL("image/jpeg",.6)}))}catch{}}})(),()=>{e=!0}},[Ae,p,V,We]);const Kt=a.useCallback(e=>{if(!e||!c){dt(null);return}const n=e.toLowerCase(),s=[];for(const r of O){const l=r.runs.map(f=>f.text).join("");let i=0;for(;;){const f=l.toLowerCase().indexOf(n,i);if(f<0)break;s.push({blockId:r.block.id,at:f}),i=f+n.length}}dt({query:e,count:s.length,hits:s}),s.length&&(I(s[0].blockId),X.current.get(s[0].blockId)?.scrollIntoView({block:"center"}))},[O,c]),Xn=a.useCallback((e,n)=>{if(!e)return;const s=e.toLowerCase();T();let r=0;g(l=>{const i={...l};for(const f of O){const o=f.runs.map(w=>({...w}));let d=!1;for(const w of o){let z="",S=0;for(;;){const R=w.text.toLowerCase().indexOf(s,S);if(R<0)break;z+=w.text.slice(S,R)+n,S=R+e.length,d=!0,r++}d&&(w.text=z+w.text.slice(S))}if(d){const w=`${h}:${f.block.id}`;i[w]={...i[w]||{},runs:o.filter(z=>z.text!==""),flowing:!0,dirty:!0}}}return i}),se(l=>l+1),dt({query:e,count:0,replaced:r,hits:[]})},[O,h,T]);a.useEffect(()=>{const e=n=>{if(!n.target.closest?.("[data-block], [data-textbox]"))return;const s=_.current;if(!s)return;const r=s.scrollLeft,l=s.scrollTop,i=window.scrollX,f=window.scrollY;let o=!0;const d=()=>{o&&(s.scrollLeft!==r&&(s.scrollLeft=r),s.scrollTop!==l&&(s.scrollTop=l),(window.scrollX!==i||window.scrollY!==f)&&window.scrollTo(i,f))};document.addEventListener("focusin",d,!0),s.addEventListener("scroll",d,!0),window.addEventListener("scroll",d,!0);const w=()=>{o=!1,document.removeEventListener("focusin",d,!0),s.removeEventListener("scroll",d,!0),window.removeEventListener("scroll",d,!0)};requestAnimationFrame(()=>requestAnimationFrame(w))};return document.addEventListener("pointerdown",e,!0),()=>document.removeEventListener("pointerdown",e,!0)},[]),a.useEffect(()=>{if(!U)return;const e=n=>{if(n.target.closest?.("[data-block-toolbar]"))return;const s=n.target.closest?.("[data-block]");if(s){s.dataset.block!==U&&I(null);return}I(null);const r=X.current.get(U),l=window.getSelection();l&&r?.contains(l.anchorNode)&&l.removeAllRanges(),r?.blur()};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[U]),a.useEffect(()=>{const e=n=>{const s=n.metaKey||n.ctrlKey,r=n.target?.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(n.target?.tagName);if(s&&n.key.toLowerCase()==="z"){n.preventDefault(),n.shiftKey?gt():ft();return}if(s&&n.key.toLowerCase()==="f"){n.preventDefault(),He(!0);return}if(n.key==="Escape"){X.current.get(U)?.blur(),I(null),xe(null),He(!1),me("select");return}if(r||s)return;if((n.key==="Delete"||n.key==="Backspace")&&oe){n.preventDefault(),wt(oe);return}const l=cn.find(i=>i.key.toLowerCase()===n.key.toLowerCase());l&&(me(l.id),Ee.current=!1)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ft,gt,U,oe,wt]);const kt=a.useCallback(()=>{if(!c)return;const e=O.filter(o=>o.dirty),n=[...le[h]||[]],s=be.filter(o=>o.dirty);if(!e.length&&!n.length&&!s.length){j.current.delete(h);return}const r=[],l=[];for(const o of e){const d=Se(o.block);d&&r.push({rect:d.rect,flat:d.flat,patch:d.patch});const w=X.current.get(o.block.id);if(!w)continue;const z=o.color||d?.ink||[0,0,0],S=qt(w,o.lineHeightPx,R=>(o.styles.get(R)||o.dominant)?.cssFont).map(R=>{const ye=o.styles.get(R.styleKey)||o.dominant;return{...R,color:z,fontSizePx:ye?.fontSizePx??o.fontSizePx,fontDesc:ye?.desc??o.desc,resolved:ye?.resolved}}).filter(R=>R.resolved&&R.fontDesc);S.length&&l.push({left:o.left,top:o.top,angle:o.block.angle,words:S})}const i=c.viewport.scale;for(const o of n.filter(d=>d.kind==="text"&&d.text)){const d=je.current.get(o.id);if(!d)continue;const w=(o.fontSizePt||12)*i,z=w*1.25,S=getComputedStyle(d),R=`${S.fontStyle} ${S.fontWeight} ${w}px ${S.fontFamily}`,ye={mode:"substituted",klass:o.klass||"sans-serif",cssFamily:S.fontFamily,cssWeight:S.fontWeight,cssStyle:S.fontStyle},Je={key:`tb:${o.id}`,bold:!!o.bold,italic:!!o.italic,embedded:!1},qe=qt(d,z,()=>R).map(vt=>({...vt,color:o.color||[17,24,39],fontSizePx:w,fontDesc:Je,resolved:ye}));qe.length&&l.push({left:o.x*i,top:o.y*i,angle:0,words:qe})}for(const o of be){if(!o.dirty)continue;const d=Ge(o);d&&r.push({rect:d.rect,flat:d.color,patch:null});const w=o.replacedWith||o.dataUrl;o.removed||!w||n.push({id:`docimg:${o.key}`,kind:"image",x:o.x/i,y:o.y/i,w:o.w/i,h:o.h/i,dataUrl:w,opacity:1,_fromDoc:!0})}const f=n.filter(o=>o.kind!=="text").map(o=>({...o,x:o.x*i,y:o.y*i,w:o.w*i,h:o.h*i,strokeWidth:(o.strokeWidth||0)*i,points:o.points?.map(([d,w])=>[d*i,w*i])}));j.current.set(h,{pageNumber:h,viewport:c.viewport,patches:r,draws:l,objects:f})},[c,O,h,Se,le,be,Ge]);a.useEffect(()=>()=>kt(),[kt]);const Yn=async()=>
3{if(!(!b||!c)){W("Building PDF…"),B(""),pt(null);try{kt();const e=[...j.current.values()].filter(o=>o.patches.length||o.draws.length||o.objects?.length).sort((o,d)=>o.pageNumber-d.pageNumber);if(!(e.length||de||Object.keys(fe).length)){B("Nothing has been edited yet."),W("");return}const s=de||Object.keys(fe).length?{order:de,rotate:fe}:null,r=await vs(b.slice(0),e,s),l=new Blob([r.bytes],{type:"application/pdf"}),i=URL.createObjectURL(l),f=document.createElement("a");f.href=i,f.download=u.replace(/\.pdf$/i,"")+"-edited.pdf",f.click(),setTimeout(()=>URL.revokeObjectURL(i),4e3),pt({...r.stats,warnings:r.warnings,size:l.size,pages:e.length})}catch(e){B(`Export failed: ${e.message}`)}finally{W("")}}},J=a.useMemo(()=>{const e=O.filter(o=>o.embedded).length,n=O.filter(o=>o.dirty).length,s=new Set(Object.keys(Y).filter(o=>Y[o]&&(Y[o].runs!=null||Y[o].dirty)).map(o=>Number(o.split(":")[0])));for(const o of Object.keys(Ye))s.add(Number(o.split(":")[0]));for(const[o,d]of Object.entries(le))d?.length&&s.add(Number(o));for(const[o,d]of Object.entries(le))d?.length&&s.add(Number(o));const r=Object.values(le).reduce((o,d)=>o+(d?.length||0),0),l=!!de||Object.keys(fe).length>0,i=O.filter(o=>o.block.lines.length>1).length,f=O.reduce((o,d)=>o+d.block.lines.filter(w=>w.breakAfter==="hard").length,0);return{total:O.length,embedded:e,dirty:n,multi:i,hard:f,editedPages:s,objectCount:r,pagesChanged:l,objectsHere:(le[h]||[]).length}},[O,Y,Ye,le,de,fe,h]),q=U?Dn.get(U):null;return t.jsxs("div",{className:"relative min-h-screen bg-neutral-950 text-neutral-200",children:[t.jsx("header",{className:"sticky top-0 z-30 border-b border-neutral-800 bg-neutral-900/95 backdrop-blur",children:t.jsxs("div",{className:"flex flex-wrap items-center gap-3 px-4 py-2.5",children:[t.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-neutral-100",children:[t.jsx(zs,{size:16,className:"text-blue-400"}),"PDF editor lab",t.jsx("span",{className:"rounded bg-blue-500/15 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-blue-300",children:"POC"}),t.jsx("span",{title:"Build timestamp — if this does not change after an edit, you are on a cached build",className:"rounded bg-neutral-800 px-1.5 py-0.5 font-mono text-[9px] text-neutral-500",children:qs})]}),t.jsxs("label",{className:"flex cursor-pointer items-center gap-1.5 rounded-md border border-neutral-700 bg-neutral-800 px-2.5 py-1.5 text-xs hover:bg-neutral-750 hover:border-neutral-600",children:[t.jsx(nn,{size:13}),u?"Change file":"Open PDF",t.jsx("input",{type:"file",accept:"application/pdf,.pdf",className:"hidden",onChange:e=>Ot(e.target.files?.[0])})]}),u&&t.jsxs("span",{className:"flex items-center gap-1.5 truncate text-xs text-neutral-400",children:[t.jsx(Ms,{size:12})," ",u]}),t.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[t.jsx("button",{onClick:ft,disabled:!pe.past,"aria-label":"Undo",title:"Undo (⌘Z)",className:"rounded p-1.5 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-100 disabled:opacity-30",children:t.jsx(Is,{size:15})}),t.jsx("button",{onClick:gt,disabled:!pe.future,"aria-label":"Redo",title:"Redo (⇧⌘Z)",className:"rounded p-1.5 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-100 disabled:opacity-30",children:t.jsx(As,{size:15})}),t.jsx("span",{className:"mx-1 h-5 w-px bg-neutral-800"}),t.jsx("button",{onClick:()=>N(e=>Math.max(1,e-1)),disabled:h<=1,"aria-label":"Previous page",className:"rounded p-1.5 text-neutral-400 hover:bg-neutral-800 disabled:opacity-30",children:t.jsx(ds,{size:15})}),t.jsx("span",{className:"min-w-[62px] text-center text-xs tabular-nums text-neutral-400",children:C?`${h} / ${C}`:"—"}),t.jsx("button",{onClick:()=>N(e=>Math.min(C,e+1)),disabled:h>=C,"aria-label":"Next page",className:"rounded p-1.5 text-neutral-400 hover:bg-neutral-800 disabled:opacity-30",children:t.jsx(Ks,{size:15})}),t.jsx("span",{className:"mx-1 h-5 w-px bg-neutral-800"}),t.jsx("button",{onClick:()=>M(e=>Me[Math.max(0,Me.indexOf(e)-1)]??e),"aria-label":"Zoom out",className:"rounded p-1.5 text-neutral-400 hover:bg-neutral-800",children:t.jsx(Ls,{size:15})}),t.jsxs("span",{className:"min-w-[44px] text-center text-xs tabular-nums text-neutral-400",children:[Math.round(E*100),"%"]}),t.jsx("button",{onClick:()=>M(e=>Me[Math.min(Me.length-1,Me.indexOf(e)+1)]??e),"aria-label":"Zoom in",className:"rounded p-1.5 text-neutral-400 hover:bg-neutral-800",children:t.jsx(Os,{size:15})}),t.jsx("span",{className:"mx-1 h-5 w-px bg-neutral-800"}),t.jsx("button",{onClick:()=>Pn(e=>!e),"aria-label":"Toggle block outlines",title:"Show what the grouper decided",className:`rounded p-1.5 hover:bg-neutral-800 ${Be?"text-blue-400":"text-neutral-400"}`,children:Be?t.jsx(Ds,{size:15}):t.jsx(us,{size:15})}),t.jsxs("button",{onClick:Yn,disabled:!p||!J.editedPages.size&&!J.pagesChanged||!!x,className:"ml-1 flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-blue-500 disabled:opacity-40",children:[x==="Building PDF…"?t.jsx(rn,{size:13,className:"animate-spin"}):t.jsx(Ts,{size:13}),"Download"]})]})]})}),t.jsxs("div",{className:"flex",children:[p&&t.jsxs("nav",{className:"flex w-12 shrink-0 flex-col items-center gap-1 border-r border-neutral-800 bg-neutral-900/60 py-2",children:[cn.map(e=>{const n=e.Icon,{id:s,label:r,key:l}=e;return t.jsxs("button",{"aria-label":r,title:`${r} (${l})`,onClick:()=>{me(s),Ee.current=!1,s==="signature"&&Ue(!0)},onDoubleClick:()=>{me(s),Ee.current=!0},className:`relative flex h-9 w-9 items-center justify-center rounded-md transition ${ee===s?"bg-blue-600 text-white":"text-neutral-400 hover:bg-neutral-800 hover:text-neutral-100"}`,children:[t.jsx(n,{size:16}),ee===s&&Ee.current&&t.jsx("span",{className:"absolute bottom-0.5 right-0.5 h-1.5 w-1.5 rounded-full bg-white"})]},s)}),t.jsx("span",{className:"my-1 h-px w-6 bg-neutral-800"}),t.jsx("button",{"aria-label":"Pages",title:"Page thumbnails",onClick:()=>Tt(e=>!e),className:`flex h-9 w-9 items-center justify-center rounded-md transition ${Ae?"bg-neutral-700 text-white":"text-neutral-400 hover:bg-neutral-800"}`,children:t.jsx(Ws,{size:16})}),t.jsx("button",{"aria-label":"Find and replace",title:"Find and replace (⌘F)",onClick:()=>He(e=>!e),className:`flex h-9 w-9 items-center justify-center rounded-md transition ${Ft?"bg-neutral-700 text-white":"text-neutral-400 hover:bg-neutral-800"}`,children:t.jsx(ms,{size:16})})]}),p&&Ae&&t.jsxs("aside",{className:"w-[150px] shrink-0 overflow-auto border-r border-neutral-800 bg-neutral-900/60 p-2",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between px-1",children:[t.jsx("span",{className:"text-[11px] font-semibold text-neutral-300",children:"Pages"}),t.jsx("button",{"aria-label":"Close pages panel",onClick:()=>Tt(!1),className:"rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200",children:t.jsx(Et,{size:12})})]}),t.jsx("ol",{className:"space-y-2",children:V.map((e,n)=>t.jsxs("li",{className:`group relative rounded border p-1 ${h===e+1?"border-blue-500 bg-blue-500/10":"border-neutral-800 hover:border-neutral-600"}`,children:[t.jsxs("button",{onClick:()=>N(e+1),className:"block w-full","aria-label":`Go to page ${n+1}`,children:[We[e]?t.jsx("img",{src:We[e],alt:"",className:"mx-auto max-h-32 w-auto bg-white shadow",style:{transform:`rotate(${fe[e]||0}deg)`}}):t.jsx("div",{className:"mx-auto flex h-28 w-full items-center justify-center bg-neutral-800 text-[10px] text-neutral-500",children:"…"}),t.jsxs("span",{className:"mt-1 block text-center text-[10px] text-neutral-400",children:[n+1,e+1!==n+1&&t.jsxs("span",{className:"text-neutral-600",children:[" (was ",e+1,")"]})]})]}),t.jsxs("div",{className:"mt-1 flex justify-center gap-0.5 opacity-0 transition group-hover:opacity-100",children:[t.jsx("button",{"aria-label":"Rotate page",title:"Rotate 90°",onClick:()=>Un(e,90),className:"rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-white",children:t.jsx(bs,{size:11})}),t.jsx("button",{"aria-label":"Duplicate page",title:"Duplicate",onClick:()=>_n(e),className:"rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-white",children:t.jsx(Hs,{size:11})}),t.jsx("button",{"aria-label":"Move page up",title:"Move up",onClick:()=>Ut(e,-1),disabled:n===0,className:"rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-white disabled:opacity-30",children:t.jsx(an,{size:11})}),t.jsx("button",{"aria-label":"Move page down",title:"Move down",onClick:()=>Ut(e,1),disabled:n===V.length-1,className:"rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-white disabled:opacity-30",children:t.jsx($t,{size:11})}),t.jsx("button",{"aria-label":"Delete page",title:"Delete",onClick:()=>Kn(e),disabled:V.length<=1,className:"rounded p-1 text-neutral-400 hover:bg-red-950 hover:text-red-300 disabled:opacity-30",children:t.jsx(sn,{size:11})})]})]},`${e}-${n}`))}),(de||Object.keys(fe).length>0)&&t.jsx("button",{onClick:()=>{T(),Ne(null),Ie({})},className:"mt-3 w-full rounded border border-neutral-700 bg-neutral-800 px-2 py-1 text-[10px] text-neutral-300 hover:bg-neutral-700",children:"Reset page changes"})]}),En&&t.jsx(nr,{onCancel:()=>{Ue(!1),me("select")},onCommit:Hn}),t.jsx("input",{ref:Dt,type:"file",accept:"image/png,image/jpeg",className:"hidden",onChange:e=>{Bn(e.target.files?.[0]),e.target.value=""}}),p&&Ft&&t.jsxs("div",{className:"absolute right-[320px] top-14 z-40 w-72 rounded-lg border border-neutral-700 bg-neutral-900 p-3 shadow-2xl shadow-black/60",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-[11px] font-semibold text-neutral-200",children:"Find & replace"}),t.jsx("button",{"aria-label":"Close find",onClick:()=>He(!1),className:"rounded p-0.5 text-neutral-500 hover:bg-neutral-800 hover:text-neutral-200",children:t.jsx(Et,{size:12})})]}
3),t.jsx("input",{"aria-label":"Find",autoFocus:!0,value:$e,onChange:e=>Sn(e.target.value),onKeyDown:e=>e.key==="Enter"&&Kt($e),placeholder:"Find on this page",className:"mb-1.5 w-full rounded border border-neutral-700 bg-neutral-800 px-2 py-1.5 text-[11px] text-neutral-100 outline-none focus:border-blue-500"}),t.jsx("input",{"aria-label":"Replace with",value:Mt,onChange:e=>Rn(e.target.value),placeholder:"Replace with",className:"mb-2 w-full rounded border border-neutral-700 bg-neutral-800 px-2 py-1.5 text-[11px] text-neutral-100 outline-none focus:border-blue-500"}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("button",{onClick:()=>Kt($e),className:"flex-1 rounded bg-neutral-800 px-2 py-1 text-[11px] text-neutral-200 hover:bg-neutral-700",children:"Find"}),t.jsx("button",{onClick:()=>Xn($e,Mt),disabled:!$e,className:"flex-1 rounded bg-blue-600 px-2 py-1 text-[11px] text-white hover:bg-blue-500 disabled:opacity-40",children:"Replace all"})]}),ze&&t.jsx("p",{className:"mt-2 text-[10px] text-neutral-400",children:ze.replaced!=null?`Replaced ${ze.replaced} on this page.`:`${ze.count} match${ze.count===1?"":"es"} on this page.`})]}),t.jsx("input",{ref:Lt,type:"file",accept:"image/png,image/jpeg",className:"hidden",onChange:e=>{zn(e.target.files?.[0]),e.target.value=""}}),t.jsxs("main",{ref:_,className:"flex-1 overflow-auto p-6",onMouseDown:e=>{e.target===e.currentTarget&&I(null)},children:[!p&&t.jsxs("label",{className:"mx-auto mt-16 flex max-w-lg cursor-pointer flex-col items-center gap-3 rounded-xl border-2 border-dashed border-neutral-700 bg-neutral-900/50 px-8 py-16 text-center hover:border-blue-600 hover:bg-neutral-900",children:[t.jsx(nn,{size:28,className:"text-neutral-500"}),t.jsx("span",{className:"text-sm font-medium text-neutral-300",children:"Open a PDF to edit its text"}),t.jsx("span",{className:"max-w-sm text-xs leading-relaxed text-neutral-500",children:"Everything runs in this tab. Click any paragraph and type — the caret, selection and wrapping are the browser's own, in the document's own font."}),t.jsx("input",{type:"file",accept:"application/pdf,.pdf",className:"hidden",onChange:e=>Ot(e.target.files?.[0])})]}),p&&t.jsx("div",{className:"flex",style:Js,children:t.jsxs("div",{ref:Q,className:"relative shadow-2xl shadow-black/60",onPointerDown:An,style:{width:c?.w,height:c?.h,cursor:ee==="select"?"default":"crosshair"},children:[t.jsx("canvas",{ref:H,className:"block bg-white"}),t.jsx("canvas",{ref:K,className:"pointer-events-none absolute left-0 top-0"}),c&&t.jsx(un,{objects:Te.filter(e=>at.has(e.kind)),draft:Z&&at.has(Z.kind)?Z:null,scale:c.viewport.scale,w:c.w,h:c.h,selId:oe,tool:ee,onPointerDownObject:jt}),q&&c&&t.jsx(sr,{v:q,scale:c.viewport.scale,stageW:c.w,onFormat:e=>Ln(q,e),onAlign:e=>Tn(q.block.id,{align:e,dirty:!0}),stateOf:e=>On(q,e),dimmed:ut,onRevert:()=>In(q.block.id),onDragStart:e=>Ht(q,"move",e)},q.block.id),O.map(e=>{const n=e.block.id===U;return t.jsxs("div",{className:"absolute",style:{left:e.left,top:e.top,width:e.width,transform:e.block.angle?`rotate(${e.block.angle}rad)`:void 0,transformOrigin:"0 0"},children:[t.jsx("div",{ref:s=>{s?X.current.set(e.block.id,s):X.current.delete(e.block.id)},contentEditable:"plaintext-only",suppressContentEditableWarning:!0,spellCheck:!1,"data-block":e.block.id,onFocus:()=>At(e),onMouseDown:()=>At(e),onKeyDown:s=>Fn(e,s),onCompositionStart:()=>!e.flowing&&Ve(e),onInput:s=>Mn(e,s),onPaste:s=>{s.preventDefault(),e.flowing||Ve(e);const r=s.clipboardData.getData("text/plain");document.execCommand("insertText",!1,r)},className:["outline-none",n?"ring-2 ring-blue-500/80":Be?"ring-1 ring-emerald-400/40":"hover:ring-1 hover:ring-blue-400/50"].join(" "),style:{fontFamily:e.dominant?.fontFamily,fontWeight:e.dominant?.fontWeight,fontStyle:e.dominant?.fontStyle,fontSize:e.dominant?`${e.dominant.fontSizePx}px`:void 0,lineHeight:`${e.lineHeightPx}px`,textAlign:e.align,boxSizing:"border-box",paddingLeft:e.block.padLeft||void 0,textIndent:e.block.textIndent||void 0,whiteSpace:e.flowing?"pre-wrap":"pre",color:"transparent",caretColor:`rgb(${(e.color||[0,0,0]).join(",")}
3)`,cursor:"text",minHeight:e.lineHeightPx}}),n&&t.jsx(t.Fragment,{children:t.jsxs("div",{onPointerDown:s=>Ht(e,"width",s),title:"Drag to change the line width",className:"group absolute left-full top-0 ml-1 flex h-full w-3.5 cursor-ew-resize items-center justify-center",children:[t.jsx("div",{className:"h-full w-0.5 bg-blue-500/40 transition group-hover:bg-blue-500/80"}),t.jsx("div",{className:"absolute top-1/2 h-3 w-3 -translate-y-1/2 rounded-full border-2 border-white bg-blue-500 shadow transition group-hover:scale-125"})]})}),Be&&t.jsxs("span",{className:"pointer-events-none absolute -top-3.5 left-0 whitespace-nowrap rounded bg-emerald-500/90 px-1 text-[9px] font-medium leading-3 text-black",children:[e.block.lines.length,"L",e.embedded?" · own font":" · substituted"]})]},e.block.id)}),t.jsx(er,{images:be,selKey:oe,tool:ee,onPointerDownImage:Wn}),c&&t.jsx(un,{objects:Te.filter(e=>!at.has(e.kind)&&e.kind!=="text"),draft:Z&&!at.has(Z.kind)&&Z.kind!=="text"?Z:null,scale:c.viewport.scale,w:c.w,h:c.h,selId:oe,tool:ee,onPointerDownObject:jt}),c&&Te.filter(e=>e.kind==="text").map(e=>t.jsx(tr,{o:e,scale:c.viewport.scale,selected:e.id===oe,registerEl:n=>{n?je.current.set(e.id,n):je.current.delete(e.id)},onSelect:()=>{xe(e.id),I(null)},onChange:n=>ie(e.id,{text:n},{history:!1}),onDragStart:n=>jt(e,null,n)},e.id)),c&&Z&&Z.kind==="text"&&t.jsx("div",{className:"pointer-events-none absolute border border-dashed border-blue-500",style:{left:Z.x*c.viewport.scale,top:Z.y*c.viewport.scale,width:Z.w*c.viewport.scale,height:Z.h*c.viewport.scale}})]})})]}),t.jsxs("aside",{className:"w-[300px] shrink-0 border-l border-neutral-800 bg-neutral-900/60 p-4 text-xs",children:[x&&t.jsxs("div",{className:"mb-3 flex items-center gap-2 rounded-md bg-neutral-800 px-2.5 py-2 text-neutral-300",children:[t.jsx(rn,{size:13,className:"animate-spin"})," ",x]}),te&&t.jsxs("div",{className:"mb-3 flex items-start gap-2 rounded-md border border-red-900/60 bg-red-950/50 px-2.5 py-2 text-red-300",children:[t.jsx(Fs,{size:13,className:"mt-0.5 shrink-0"}),t.jsx("span",{children:te})]}),L&&t.jsxs("section",{className:"mb-5",children:[t.jsxs("h2",{className:"mb-2 flex items-center justify-between font-semibold text-neutral-100",children:[t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx(fn,{size:13})," Page image"]}),L.dirty&&t.jsx("button",{"aria-label":"Restore image",title:"Put it back where the PDF had it",onClick:()=>$n(L.key),className:"rounded p-1 text-neutral-400 hover:bg-neutral-800 hover:text-neutral-100",children:t.jsx(jn,{size:13})})]}),t.jsxs("div",{className:"space-y-2 rounded-md border border-neutral-800 bg-neutral-950/50 p-2 text-[11px]",children:[t.jsx(A,{k:"Source size",v:`${L.naturalW} × ${L.naturalH} px`}),t.jsx(A,{k:"On page",v:`${(L.w/c.viewport.scale).toFixed(0)} × ${(L.h/c.viewport.scale).toFixed(0)} pt`}),t.jsx(A,{k:"State",v:L.removed?"removed":L.dirty?"edited":"untouched",tone:L.dirty?"warn":"good"}),t.jsxs("div",{className:"flex gap-1.5 pt-1",children:[t.jsx("button",{onClick:()=>Lt.current?.click(),className:"flex-1 rounded border border-neutral-700 bg-neutral-800 px-2 py-1 hover:bg-neutral-700",children:"Replace…"}),t.jsx("button",{onClick:()=>bt(L.key,{removed:!L.removed}),className:"flex-1 rounded border border-neutral-700 bg-neutral-800 px-2 py-1 hover:bg-neutral-700",children:L.removed?"Restore":"Remove"})]}),!L.dataUrl&&t.jsx("p",{className:"text-amber-400",children:"The pixels for this image did not decode, so it can be removed but not moved."})]})]}),v&&t.jsxs("section",{className:"mb-5",children:[t.jsxs("h2",{className:"mb-2 flex items-center justify-between font-semibold text-neutral-100",children:[t.jsxs("span",{className:"flex items-center gap-1.5 capitalize",children:[t.jsx(kn,{size:13})," ",v.kind]}),t.jsx("button",{"aria-label":"Delete object",title:"Delete (⌫)",onClick:()=>wt(v.id),className:"rounded p-1 text-neutral-400 hover:bg-red-950 hover:text-red-300",children:t.jsx(sn,{size:13})})]}),t.jsxs("div",{className:"space-y-2 rounded-md border border-neutral-800 bg-neutral-950/50 p-2",children:[v.kind==="text"?t.jsxs(t.Fragment,{children:[t.jsx(hn,{label:"Colour",value:v.color||[17,24,39],onChange:e=>ie(v.id,{color:e})}),t.jsx(Pt,{label:"Size",value:v.fontSizePt,min:4,step:.5,onChange:e=>ie(v.id,{fontSizePt:e})}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"w-14 shrink-0 text-neutral-500",children:"Style"}),t.jsxs("select",{"aria-label":"Text box font",value:v.klass,onChange:e=>ie(v.id,{klass:e.target.value}),className:"flex-1 rounded border border-neutral-700 bg-neutral-800 px-1.5 py-1 text-[11px]",children:[t.jsx("option",{value:"sans-serif",children:"Sans"}),t.jsx("option",{value:"serif",children:"Serif"}),t.jsx("option",{value:"monospace",children:"Mono"})]}),t.jsx("button",{"aria-label":"Bold",onClick:()=>ie(v.id,{bold:!v.bold}),className:`rounded border border-neutral-700 px-1.5 py-1 ${v.bold?"bg-blue-600 text-white":"bg-neutral-800"}`,children:t.jsx(mn,{size:11})}),t.jsx("button",{"aria-label":"Italic",onClick:()=>ie(v.id,{italic:!v.italic}),className:`rounded border border-neutral-700 px-1.5 py-1 ${v.italic?"bg-blue-600 text-white":"bg-neutral-800"}`,children:t.jsx(bn,{size:11})})]})]}):t.jsxs(t.Fragment,{children:[v.stroke&&t.jsx(hn,{label:"Stroke",value:v.stroke,onChange:e=>ie(v.id,{stroke:e})}),v.kind!=="line"&&v.kind!=="arrow"&&v.kind!=="ink"&&t.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[t.jsx("span",{className:"w-14 shrink-0 text-neutral-500",children:"Fill"}),t.jsx("input",{"aria-label":"Fill colour",type:"color",value:Pe(v.fill||[255,255,255]),onChange:e=>ie(v.id,{fill:lt(e.target.value)}),className:"h-5 w-8 cursor-pointer rounded border border-neutral-700 bg-transparent"}),t.jsx("button",{onClick:()=>ie(v.id,{fill:v.fill?null:[255,255,255]}),className:"rounded border border-neutral-700 bg-neutral-800 px-1.5 py-0.5 text-[10px] hover:bg-neutral-700",children:v.fill?"Remove":"Add"})]}),v.kind!=="image"&&t.jsx(Pt,{label:"Width",value:v.strokeWidth,min:0,step:.5,onChange:e=>ie(v.id,{strokeWidth:e})}),t.jsx(Pt,{label:"Opacity",value:Math.round((v.opacity??1)*100),min:5,max:100,step:5,suffix:"%",onChange:e=>ie(v.id,{opacity:e/100})})]}),t.jsxs("div",{className:"flex items-center gap-1.5 pt-0.5",children:[t.jsx("span",{className:"w-14 shrink-0 text-[11px] text-neutral-500",children:"Order"}),t.jsx("button",{"aria-label":"Bring forward",title:"Bring forward",onClick:()=>Bt(v.id,1),className:"rounded border border-neutral-700 bg-neutral-800 px-1.5 py-1 hover:bg-neutral-700",children:t.jsx(an,{size:11})}),t.jsx("button",{"aria-label":"Send backward",title:"Send backward",onClick:()=>Bt(v.id,-1),className:"rounded border border-neutral-700 bg-neutral-800 px-1.5 py-1 hover:bg-neutral-700",children:t.jsx($t,{size:11})})]})]})]}),q?t.jsxs("section",{className:"mb-5",children:[t.jsxs("h2",{className:"mb-2 flex items-center gap-1.5 font-semibold text-neutral-100",children:[t.jsx(pn,{size:13})," Selected paragraph"]}),t.jsxs("dl",{className:"space-y-1 rounded-md border border-neutral-800 bg-neutral-950/50 p-2 text-[11px] text-neutral-400",children:[t.jsx(A,{k:"Lines",v:`${q.block.lines.length} (${q.block.lines.filter(e=>e.breakAfter==="hard").length} kept as hard breaks)`}),t.jsx(A,{k:"Measure",v:`${(q.width/c.viewport.scale).toFixed(1)} pt`}),t.jsx(A,{k:"Styles in run",v:q.styles.size})]}),t.jsx("ul",{className:"mt-2 space-y-1.5",children:[...q.styles.values()].map(e=>t.jsxs("li",{className:"rounded-md border border-neutral-800 bg-neutral-950/50 p-2 text-[11px]",children:[t.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("span",{className:"truncate text-neutral-300",children:ws(e.desc)}),t.jsxs("span",{className:"shrink-0 tabular-nums text-neutral-500",children:[(e.fontSizePx/c.viewport.scale).toFixed(1)," pt"]})]}),t.jsx("div",{className:e.resolved.mode==="embedded"?"text-emerald-400":"text-amber-400",children:e.resolved.mode==="embedded"?"drawn with the document's own font":`substituted ${e.resolved.klass} — ${e.resolved.reason}`}),t.jsx("div",{className:"text-neutral-500",children:e.wordSpacing?`fitted with ${e.wordSpacing>0?"+":""}${e.wordSpacing.toFixed(2)}px word-spacing`:e.letterSpacing?`fitted with ${e.letterSpacing>0?"+":""}${e.letterSpacing.toFixed(2)}px letter-spacing`:"no width correction needed"})]},e.key))})]}):p&&t.jsx("p",{className:"mb-5 rounded-md border border-neutral-800 bg-neutral-950/50 p-2.5 text-[11px] leading-relaxed text-neutral-400",children:"Click any paragraph to edit it. Nothing should visibly move when you do — if the text shifts, the font substitution is what you are seeing, and the panel will say so."}),p&&t.jsxs("section",{className:"mb-5",children:[t.jsx("h2",{className:"mb-2 font-semibold text-neutral-100",children:"This page"}),t.jsxs("dl",{className:"space-y-1 rounded-md border border-neutral-800 bg-neutral-950/50 p-2 text-[11px] text-neutral-400",children:[t.jsx(A,{k:"Paragraphs found",v:J.total}),t.jsx(A,{k:"Multi-line",v:J.multi}),t.jsx(A,{k:"Hard breaks kept",v:J.hard}),t.jsx(A,{k:"Using the doc's font",v:`${J.embedded} of ${J.total}`,tone:J.embedded===J.total?"good":"warn"}),t.jsx(A,{k:"Edited",v:J.dirty}),t.jsx(A,{k:"Objects here",v:J.objectsHere}),J.objectCount>J.objectsHere&&t.jsx(A,{k:"Objects in doc",v:J.objectCount}),J.pagesChanged&&t.jsx(A,{k:"Page order",v:`${V.length} of ${C}`,tone:"warn"})]})]}),ge&&t.jsxs("section",{children:[t.jsxs("h2",{className:"mb-2 flex items-center gap-1.5 font-semibold text-neutral-100",children:[t.jsx(Xs,{size:13,className:"text-emerald-400"})," Exported"]}),t.jsxs("dl",{className:"space-y-1 rounded-md border border-neutral-800 bg-neutral-950/50 p-2 text-[11px] text-neutral-400",children:[t.jsx(A,{k:"Words drawn",v:ge.words}),t.jsx(A,{k:"Patches",v:ge.patches}),t.jsx(A,{k:"Fonts re-embedded",v:ge.embeddedFonts}),t.jsx(A,{k:"Fonts substituted",v:ge.substitutedFonts}),t.jsx(A,{k:"Pages touched",v:ge.pages}),t.jsx(A,{k:"Size",v:`${(ge.size/1024).toFixed(0)} KB`})]}),t.jsx("p",{className:"mt-2 rounded-md border border-amber-900/50 bg-amber-950/30 p-2 text-[11px] leading-relaxed text-amber-300",children:"Known gap: the replaced text is covered, not deleted. The original page content is left byte-for-byte intact, so the old words are still in the file's text layer under the patch and will come back if you copy out of the PDF. Fixing it means editing the page's content stream to drop the covered text-showing operators — not a redaction tool as it stands."}),ge.warnings?.length>0&&t.jsx("ul",{className:"mt-2 space-y-1 rounded-md border border-amber-900/50 bg-amber-950/30 p-2 text-[11px] text-amber-300",children:ge.warnings.map((e,n)=>t.jsxs("li",{children:["· ",e]},n))})]})]})]})]})}
3function er({images:u,selKey:m,tool:b,onPointerDownImage:y}){return t.jsx(t.Fragment,{children:u.map(p=>{const F=p.key===m,C=p.replacedWith||p.dataUrl;return t.jsxs("div",{children:[p.dirty&&!p.removed&&C&&t.jsx("img",{src:C,alt:"",draggable:!1,className:"pointer-events-none absolute",style:{left:p.x,top:p.y,width:p.w,height:p.h}}),t.jsx("div",{onPointerDown:k=>b==="select"&&y(p,null,k),title:p.removed?"Removed image":"Image — drag to move",className:`absolute ${F?"ring-2 ring-blue-500":"hover:ring-2 hover:ring-blue-400/60"} ${p.removed?"border border-dashed border-red-500/60":""}`,style:{left:p.x,top:p.y,width:p.w,height:p.h,pointerEvents:b==="select"?"auto":"none",cursor:"move"}}),F&&Nn.map(k=>{const h=p.x+(k.includes("w")?0:k.includes("e")?p.w:p.w/2),N=p.y+(k.includes("n")?0:k.includes("s")?p.h:p.h/2);return t.jsx("div",{onPointerDown:E=>y(p,k,E),className:"absolute z-10 h-2.5 w-2.5 rounded-sm border-2 border-blue-500 bg-white",style:{left:h-5,top:N-5,cursor:`${k}-resize`}},k)})]},p.key)})})}function tr({o:u,scale:m,selected:b,registerEl:y,onSelect:p,onChange:F,onDragStart:C}){const k=a.useRef(null);a.useEffect(()=>{k.current&&k.current.innerText!==(u.text||"")&&(k.current.innerText=u.text||"")},[u.id]);const h=(u.fontSizePt||12)*m;return t.jsxs("div",{className:"absolute",style:{left:u.x*m,top:u.y*m,width:u.w*m},children:[t.jsx("div",{ref:N=>{k.current=N,y(N)},"data-textbox":u.id,contentEditable:"plaintext-only",suppressContentEditableWarning:!0,spellCheck:!1,onPointerDown:N=>{N.stopPropagation(),p()},onInput:N=>F(N.currentTarget.innerText.replace(/\n$/,"")),onPaste:N=>{N.preventDefault(),document.execCommand("insertText",!1,N.clipboardData.getData("text/plain"))},className:`outline-none ${b?"ring-2 ring-blue-500/80":"hover:ring-1 hover:ring-blue-400/50"}`,style:{minHeight:h*1.25,fontFamily:u.klass==="serif"?'Georgia, "Times New Roman", serif':u.klass==="monospace"?"ui-monospace, Menlo, Consolas, monospace":'"Helvetica Neue", Helvetica, Arial, sans-serif',fontSize:h,lineHeight:`${h*1.25}px`,fontWeight:u.bold?700:400,fontStyle:u.italic?"italic":"normal",color:`rgb(${(u.color||[17,24,39]).join(",")})`,whiteSpace:"pre-wrap",textAlign:u.align||"left",cursor:"text"}}),b&&t.jsx("div",{onPointerDown:C,title:"Drag to move this text box",className:"absolute -left-4 top-0 flex h-6 w-3.5 cursor-move items-center justify-center rounded bg-blue-500/70 text-white hover:bg-blue-500",children:t.jsx(vn,{size:11})})]})}function un({objects:u,draft:m,scale:b,w:y,h:p,selId:F,tool:C,onPointerDownObject:k}){const h=m?[...u,m]:u,N=x=>{const W=x.stroke?`rgb(${x.stroke.join(",")})`:"none",B={fill:x.fill?`rgb(${x.fill.join(",")})`:"none",stroke:W,strokeWidth:x.strokeWidth||0,opacity:x.opacity??1,vectorEffect:"non-scaling-stroke"},c=K=>k?.(x,null,K),ue=C==="select"&&x.id!==m?.id,H={pointerEvents:ue?"auto":"none",cursor:ue?"move":"inherit"};if(x.kind==="image")return t.jsx("image",{href:x.dataUrl,x:x.x,y:x.y,width:x.w,height:x.h,opacity:x.opacity??1,style:H,onPointerDown:c,preserveAspectRatio:"none"},x.id);if(x.kind==="ellipse")return t.jsx("ellipse",{cx:x.x+x.w/2,cy:x.y+x.h/2,rx:Math.max(x.w/2,0),ry:Math.max(x.h/2,0),...B,style:H,onPointerDown:c},x.id);if(x.kind==="ink")return t.jsx("path",{d:Rs(x.points),fill:"none",stroke:W,strokeWidth:x.strokeWidth,strokeLinecap:"round",strokeLinejoin:"round",opacity:x.opacity??1,vectorEffect:"non-scaling-stroke",style:H,onPointerDown:c},x.id);if(x.kind==="line"||x.kind==="arrow"){const K=x.points||[];if(K.length<2)return null;const Q=x.kind==="arrow"?Ps(K,x.strokeWidth):null;return t.jsxs("g",{style:H,onPointerDown:c,opacity:x.opacity??1,children:[t.jsx("polyline",{points:K.map(_=>_.join(",")).join(" "),fill:"none",stroke:W,strokeWidth:x.strokeWidth,strokeLinecap:"round",vectorEffect:"non-scaling-stroke"}),Q&&t.jsx("polygon",{points:Q.map(_=>_.join(",")).join(" "),fill:W,stroke:"none"}),t.jsx("polyline",{points:K.map(_=>_.join(",")).join(" "),fill:"none",stroke:"transparent",strokeWidth:Math.max(10/b,x.strokeWidth)})]},x.id)}return t.jsx("rect",{x:x.x,y:x.y,width:Math.max(x.w,0),height:Math.max(x.h,0),...B,style:H,onPointerDown:c},x.id)},E=u.find(x=>x.id===F),M=E?wn(E):null;return t.jsxs("svg",{className:"absolute left-0 top-0",width:y,height:p,viewB
3ox:`0 0 ${y/b} ${p/b}`,style:{pointerEvents:"none",overflow:"visible"},children:[h.map(N),M&&t.jsxs("g",{children:[t.jsx("rect",{x:M.x,y:M.y,width:M.w,height:M.h,fill:"none",stroke:"#3b82f6",strokeWidth:1,strokeDasharray:"4 3",vectorEffect:"non-scaling-stroke",pointerEvents:"none"}),Nn.map(x=>{const W=M.x+(x.includes("w")?0:x.includes("e")?M.w:M.w/2),te=M.y+(x.includes("n")?0:x.includes("s")?M.h:M.h/2),B=4/b;return t.jsx("rect",{x:W-B,y:te-B,width:B*2,height:B*2,fill:"#fff",stroke:"#3b82f6",strokeWidth:1.5,vectorEffect:"non-scaling-stroke",style:{pointerEvents:"auto",cursor:`${x}-resize`},onPointerDown:c=>k?.(E,x,c)},x)})]})]})}function nr({onCancel:u,onCommit:m}){const[b,y]=a.useState("draw"),[p,F]=a.useState(.5),[C,k]=a.useState(""),[h,N]=a.useState(dn[0].id),[E,M]=a.useState([17,24,39]),[x,W]=a.useState(null),[te,B]=a.useState(!1),[c,ue]=a.useState(null),H=a.useRef(null),K=a.useRef(!1),Q=a.useRef([]),_=a.useRef(null),ne=a.useCallback(()=>{const g=H.current;if(!g)return;const $=g.getContext("2d");$.clearRect(0,0,g.width,g.height),$.lineCap="round",$.lineJoin="round",$.strokeStyle=`rgb(${E.join(",")})`;for(const D of Q.current){if(D.length<2)continue;$.lineWidth=2.4,$.beginPath(),$.moveTo(D[0][0],D[0][1]);for(let I=1;I<D.length-1;I++){const[ae,se]=D[I],[G,pe]=D[I+1];$.quadraticCurveTo(ae,se,(ae+G)/2,(se+pe)/2)}const U=D[D.length-1];$.lineTo(U[0],U[1]),$.stroke()}},[E]);a.useEffect(()=>{ne()},[ne]);const he=g=>{const $=H.current,D=$.getBoundingClientRect();return[(g.clientX-D.left)/D.width*$.width,(g.clientY-D.top)/D.height*$.height]},X=a.useCallback(async g=>{if(!g)return;const $=await new Promise(se=>{const G=new FileReader;G.onload=()=>se(G.result),G.readAsDataURL(g)}),D=await new Promise((se,G)=>{const pe=new Image;pe.onload=()=>se(pe),pe.onerror=G,pe.src=$}),I=Math.min(1,1400/Math.max(D.naturalWidth,D.naturalHeight)),ae=document.createElement("canvas");ae.width=Math.round(D.naturalWidth*I),ae.height=Math.round(D.naturalHeight*I),ae.getContext("2d").drawImage(D,0,0,ae.width,ae.height),W(ae)},[]);a.useEffect(()=>{if(b!=="upload"||!x)return;let g=!0;const $=setTimeout(()=>{try{const D=rt(tn(x,p));g&&ue(D.toDataURL("image/png"))}catch{g&&ue(null)}},60);return()=>{g=!1,clearTimeout($)}},[b,x,p]);const je=()=>{if(b==="draw"){const g=H.current;return!g||!te?null:rt(g)}return b==="type"?C.trim()?rt(Es(C,{font:h,color:E})):null:x?$s(rt(tn(x,p)),E):null},j=b==="draw"&&te||b==="type"&&C.trim().length>0||b==="upload"&&!!x,Y=(g,$)=>t.jsx("button",{onClick:()=>y(g),className:`flex-1 rounded-md px-2 py-1.5 text-[11px] font-medium transition-colors ${b===g?"bg-blue-600 text-white":"text-neutral-300 hover:bg-white/10"}`,children:$},g);return t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-6",onMouseDown:g=>g.target===g.currentTarget&&u(),children:t.jsxs("div",{className:"w-[420px] rounded-xl border border-white/10 bg-neutral-900 p-4 shadow-2xl shadow-black/70",children:[t.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[t.jsxs("h2",{className:"flex items-center gap-1.5 text-sm font-semibold text-neutral-100",children:[t.jsx(gn,{size:14})," Add a signature"]}),t.jsx("button",{"aria-label":"Close",onClick:u,className:"rounded p-1 text-neutral-500 hover:bg-white/10 hover:text-neutral-200",children:t.jsx(Et,{size:14})})]}),t.jsxs("div",{className:"mb-3 flex gap-1 rounded-lg bg-neutral-950/60 p-1",children:[Y("draw","Draw"),Y("upload","Photo or scan"),Y("type","Type")]}),b==="draw"&&t.jsxs("div",{children:[t.jsx("canvas",{ref:H,width:760,height:260,className:"w-full cursor-crosshair rounded-lg border border-white/10 bg-white",style:{touchAction:"none"},onPointerDown:g=>{g.currentTarget.setPointerCapture(g.pointerId),K.current=!0,Q.current.push([he(g)]),B(!0)},onPointerMove:g=>{K.current&&(Q.current[Q.current.length-1].push(he(g)),ne())},onPointerUp:()=>{K.current=!1}}),t.jsx("p",{className:"mt-1.5 text-[10px] text-neutral-500",children:"Sign with a mouse, trackpad or finger."})]}),b==="upload"&&t.jsxs("div",{children:[t.jsx("div",{className:"flex min-h-[150px] items-center justify-center rounded-lg border border-dashed border-white/15 bg-[repeating-conic-gradient(#2a2a2a_0%_25%,#222_0%_50%)] bg-[length:16px_16px] p-2",children:c?t.jsx("img",{src:c,alt:"Extracted signature",className:"max-h-36"}):t.jsx("button",{onClick:()=>_.current?.click(),className:"rounded-md border border-white/15 bg-neutral-800 px-3 py-1.5 text-[11px] text-neutral-200 hover:bg-neutral-700",children:"Choose a photo or scan…"})}),t.jsx("input",{ref:_,type:"file",accept:"image/*",className:"hidden",onChange:g=>{X(g.target.files?.[0]),g.target.value=""}}),x&&t.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[t.jsx("span",{className:"w-20 shrink-0 text-[11px] text-neutral-500",children:"Keep faint ink"}),t.jsx("input",{"aria-label":"Sensitivity",type:"range",min:"0",max:"1",step:"0.02",value:p,onChange:g=>F(parseFloat(g.target.value)),className:"flex-1 accent-blue-500"}),t.jsx("button",{onClick:()=>_.current?.click(),className:"rounded border border-white/15 bg-neutral-800 px-2 py-1 text-[10px] text-neutral-300 hover:bg-neutral-700",children:"Replace"})]}),t.jsx("p",{className:"mt-1.5 text-[10px] text-neutral-500",children:"The paper is removed automatically — shadows and uneven lighting included."})]}),b==="type"&&t.jsxs("div",{children:[t.jsx("input",{autoFocus:!0,value:C,onChange:g=>k(g.target.value),placeholder:"Your name",className:"mb-2 w-full rounded-md border border-white/10 bg-neutral-800 px-2.5 py-2 text-[13px] text-neutral-100 outline-none focus:border-blue-500"}),t.jsx("div",{className:"mb-2 flex gap-1",children:dn.map(g=>t.jsx("button",{onClick:()=>N(g.id),className:`flex-1 rounded-md px-2 py-1 text-[11px] transition-colors ${h===g.id?"bg-blue-600 text-white":"bg-neutral-800 text-neutral-300 hover:bg-neutral-700"}`,children:g.label},g.id))}),t.jsx("div",{className:"flex min-h-[90px] items-center justify-center rounded-lg border border-white/10 bg-white px-3",children:t.jsx("span",{style:{font:`44px ${h}`,color:`rgb(${E.join(",")})`},children:C||"Your name"})})]}),t.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[t.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-neutral-400",children:["Ink",t.jsx("input",{"aria-label":"Ink colour",type:"color",value:Pe(E),onChange:g=>M(lt(g.target.value)),className:"h-6 w-8 cursor-pointer rounded border border-white/15 bg-transparent"})]}),b==="draw"&&t.jsx("button",{onClick:()=>{Q.current=[],B(!1),ne()},className:"rounded-md border border-white/10 bg-neutral-800 px-2.5 py-1.5 text-[11px] text-neutral-300 hover:bg-neutral-700",children:"Clear"}),t.jsx("div",{className:"flex-1"}),t.jsx("button",{onClick:u,className:"rounded-md px-3 py-1.5 text-[11px] text-neutral-400 hover:bg-white/10 hover:text-neutral-200",children:"Cancel"}),t.jsxs("button",{disabled:!j,onClick:()=>{const g=je();g&&m(g)},className:"flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-[11px] font-medium text-white hover:bg-blue-500 disabled:opacity-40",children:[t.jsx(Bs,{size:12})," Place signature"]})]})]})})}function ve({on:u,label:m,onClick:b,children:y,wide:p}){return t.jsx("button",{type:"button","aria-label":m,title:m,onMouseDown:F=>F.preventDefault(),onClick:b,className:`flex h-7 items-center justify-center rounded-md text-[13px] transition-colors ${p?"gap-1 px-1.5":"w-7"} ${u?"bg-blue-600 text-white shadow-sm shadow-blue-900/40":"text-neutral-300 hover:bg-white/10 hover:text-white"}`,children:y})}function Le(){return t.jsx("span",{className:"mx-1 h-5 w-px bg-white/10"})}function sr({v:u,scale:m,stageW:b,onFormat:y,stateOf:p,onRevert:F,onDragStart:C,onAlign:k,dimmed:h}
3){const N=a.useRef(null),[E,M]=a.useState({w:0,h:36}),[x,W]=a.useState(!1);a.useEffect(()=>{N.current&&M({w:N.current.offsetWidth,h:N.current.offsetHeight})},[u.block.id,u.styles.size]);const te=8,c=u.top>E.h+te?u.top-E.h-te:u.top+u.block.height+te,ue=Math.max(0,Math.min(u.left,Math.max(0,b-E.w-4))),H=p("bold")===!0,K=p("italic")===!0,Q=p("sizePt"),_=Q??u.block.fontSize/m,ne=Q===void 0&&u.runs.length>1,he=p("color")||u.color||[0,0,0],X=p("family")||"auto",je=Rt[u.align]||yn;return t.jsxs("div",{ref:N,"data-block-toolbar":"",onMouseDown:j=>j.preventDefault(),className:`absolute z-30 flex items-center rounded-xl border border-white/10 bg-neutral-900/95 px-1.5 py-1 shadow-xl shadow-black/60 ring-1 ring-black/40 backdrop-blur-md transition-opacity duration-200 ${h?"pointer-events-none opacity-20":"opacity-100"}`,style:{left:ue,top:c},children:[t.jsx("div",{onPointerDown:C,onMouseDown:j=>j.stopPropagation(),title:"Drag to move this paragraph",className:"flex h-7 w-5 cursor-grab items-center justify-center rounded-md text-neutral-500 transition-colors hover:bg-white/10 hover:text-neutral-200 active:cursor-grabbing",children:t.jsx(vn,{size:13})}),t.jsx(Le,{}),t.jsx("select",{"aria-label":"Font",title:"Typeface — “Original” keeps the document's own font",value:X,onMouseDown:j=>j.stopPropagation(),onChange:j=>y({family:j.target.value==="auto"?null:j.target.value}),className:"h-7 cursor-pointer appearance-none rounded-md bg-transparent pl-1.5 pr-4 text-[12px] text-neutral-200 outline-none transition-colors hover:bg-white/10 focus:bg-white/10",style:{backgroundImage:`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'><path d='M0 0l4 5 4-5z' fill='%23888'/></svg>")`,backgroundRepeat:"no-repeat",backgroundPosition:"right 4px center"},children:Qs.map(j=>t.jsx("option",{value:j.id,className:"bg-neutral-900",children:j.label},j.id))}),t.jsx(Le,{}),t.jsxs("div",{className:"flex items-center",children:[t.jsx(ve,{label:"Smaller",onClick:()=>y({sizePt:Math.max(1,+(_-.5).toFixed(2))}),children:t.jsx(xn,{size:12})}),t.jsx("input",{"aria-label":"Font size in points",type:"number",step:"0.5",min:"1",value:ne?"":_.toFixed(1),placeholder:ne?"––":void 0,onMouseDown:j=>j.stopPropagation(),onChange:j=>y({sizePt:parseFloat(j.target.value)||1}),className:"h-7 w-10 rounded-md bg-transparent text-center text-[12px] tabular-nums text-neutral-100 outline-none transition-colors hover:bg-white/10 focus:bg-white/10"}),t.jsx(ve,{label:"Larger",onClick:()=>y({sizePt:+(_+.5).toFixed(2)}),children:t.jsx(Us,{size:12})})]}),t.jsx(Le,{}),t.jsx(ve,{label:"Bold",on:H,onClick:()=>y({bold:H?null:!0}),children:t.jsx(mn,{size:13})}),t.jsx(ve,{label:"Italic",on:K,onClick:()=>y({italic:K?null:!0}),children:t.jsx(bn,{size:13})}),t.jsxs("label",{title:"Text colour",onMouseDown:j=>j.stopPropagation(),className:"relative flex h-7 w-7 cursor-pointer flex-col items-center justify-center gap-px rounded-md transition-colors hover:bg-white/10",children:[t.jsx("span",{className:"text-[11px] font-semibold leading-none text-neutral-200",children:"A"}),t.jsx("span",{className:"h-[3px] w-4 rounded-full ring-1 ring-black/50",style:{background:Pe(he)}}),t.jsx("input",{"aria-label":"Text colour",type:"color",value:Pe(he),onChange:j=>y({color:lt(j.target.value)}),className:"absolute inset-0 cursor-pointer opacity-0"})]}),t.jsx(Le,{}),t.jsxs("div",{className:"relative",children:[t.jsxs(ve,{label:"Alignment",on:x,wide:!0,onClick:()=>W(j=>!j),children:[t.jsx(je,{size:13}),t.jsx($t,{size:10,className:"opacity-60"})]}),x&&t.jsx("div",{className:"absolute left-0 top-8 flex gap-0.5 rounded-lg border border-white/10 bg-neutral-900/97 p-1 shadow-xl shadow-black/60 backdrop-blur-md",children:Object.keys(Rt).map(j=>{const Y=Rt[j];return t.jsx(ve,{label:`Align ${j}`,on:u.align===j,onClick:()=>{k(j),W(!1)},children:t.jsx(Y,{size:13})},j)})})]}),t.jsx(Le,{}),t.jsx(ve,{label:"Revert this paragraph",onClick:F,children:t.jsx(jn,{size:13})})]})}function hn({label:u,value:m,onChange:b}){return t.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[t.jsx("span",{className:"w-14 shrink-0 text-neutral-500",children:u}),t.jsx("input",{"aria-label":u,type:"color",value:Pe(m),onChange:y=>b(lt(y.target.value)),className:"h-5 w-8 cursor-pointer rounded border border-neutral-700 bg-transparent"}),t.jsx("code",{className:"text-neutral-500",children:Pe(m)})]})}function Pt({label:u,value:m,onChange:b,min:y,max:p,step:F=1,suffix:C}){return t.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[t.jsx("span",{className:"w-14 shrink-0 text-neutral-500",children:u}),t.jsx("input",{"aria-label":u,type:"number",value:m,min:y,max:p,step:F,onChange:k=>b(parseFloat(k.target.value)||0),className:"w-16 rounded border border-neutral-700 bg-neutral-800 px-1.5 py-1 tabular-nums"}),C&&t.jsx("span",{className:"text-neutral-500",children:C})]})}function A({k:u,v:m,tone:b}){return t.jsxs("div",{className:"flex justify-between gap-3",children:[t.jsx("dt",{className:"shrink-0 text-neutral-500",children:u}),t.jsx("dd",{className:`text-right ${b==="good"?"text-emerald-400":b==="warn"?"text-amber-400":"text-neutral-300"}`,children:m})]})}
3export{wr 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.