PageSourceSearch

https://www.ihatepdf.cv/assets/PdfToHandwritingTool-CviPQETa.js

js ihatepdf.cv collected 2026-09-30 17:26:04 UTC 43,908 bytes, 11 lines download raw bytes

1import{r as S,j as e}from"./react-vendor-D653VjAu.js";const It="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js",Ze="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js",Dt="https://unpkg.com/[email protected]/dist/pdf-lib.min.js";function Le(t){return new Promise((n,r)=>{if(document.querySelector(`script[src="${t}"]`))return n();const i=document.createElement("script");i.src=t,i.onload=n,i.onerror=()=>r(new Error("Failed to load "+t)),document.head.appendChild(i)})}function Qe(t){return new Promise((n,r)=>{const i=new Image;i.onload=()=>n(i),i.onerror=r,i.src=t})}const X=({children:t,size:n=16,className:r=""})=>e.jsx("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:r,children:t}),Tt=t=>e.jsxs(X,{...t,children:[e.jsx("polyline",{points:"16 16 12 12 8 16"}),e.jsx("line",{x1:"12",y1:"12",x2:"12",y2:"21"}),e.jsx("path",{d:"M20.39 18.39A5 5 0 0018 9h-1.26A8 8 0 103 16.3"})]}),Lt=t=>e.jsxs(X,{...t,children:[e.jsx("polyline",{points:"8 17 12 21 16 17"}),e.jsx("line",{x1:"12",y1:"12",x2:"12",y2:"21"}),e.jsx("path",{d:"M20.88 18.09A5 5 0 0018 9h-1.26A8 8 0 103 16.09"})]}),Be=t=>e.jsxs(X,{...t,children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),je=t=>e.jsxs(X,{...t,className:`animate-spin ${t.className||""}`,children:[e.jsx("path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"}),e.jsx("path",{d:"M21 3v5h-5"})]}),et=t=>e.jsxs(X,{...t,children:[e.jsx("path",{d:"M12 19l7-7 3 3-7 7-3-3z"}),e.jsx("path",{d:"M18 13l-1.5-7.5L2 2l3.5 14.5L13 18l5-5z"}),e.jsx("path",{d:"M2 2l7.586 7.586"}),e.jsx("circle",{cx:"11",cy:"11",r:"2"})]}),tt=t=>e.jsx(X,{...t,children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),Ft=t=>e.jsxs(X,{...t,children:[e.jsx("path",{d:"M3 7v6h6"}),e.jsx("path",{d:"M21 17a9 9 0 00-9-9 9 9 0 00-6 2.3L3 13"})]}),nt=t=>e.jsx(X,{...t,children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})}),At=t=>e.jsxs(X,{...t,children:[e.jsx("path",{d:"M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"}),e.jsx("circle",{cx:"12",cy:"13",r:"4"})]}),Et=t=>e.jsx(X,{...t,children:e.jsx("path",{d:"M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z"})}),Wt=t=>e.jsxs(X,{...t,children:[e.jsx("polyline",{points:"4 7 4 4 20 4 20 7"}),e.jsx("line",{x1:"9",y1:"20",x2:"15",y2:"20"}),e.jsx("line",{x1:"12",y1:"4",x2:"12",y2:"20"})]}),st=t=>e.jsxs(X,{...t,children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),e.jsx("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),e.jsx("polyline",{points:"21 15 16 10 5 21"})]}),O=560,$e=.2,Q=.72,ae=(Q-$e)*O,ke=Q*O,$t={Lowercase:"abcdefghijklmnopqrstuvwxyz".split(""),Uppercase:"ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),Numbers:"0123456789".split(""),Punctuation:`. , ' " ! ? ; : - ( ) / & @ # % $ + =`.split(" ")},K=Object.values($t).flat(),Bt="https://fonts.googleapis.com/css2?family=Caveat:wght@500&family=Patrick+Hand&family=Dancing+Script:wght@500&display=swap",ze=[{id:"casual",label:"Casual",css:"'Caveat', 'Segoe Print', 'Bradley Hand', cursive",probe:"32px Caveat"},{id:"neat",label:"Neat",css:"'Patrick Hand', 'Comic Sans MS', 'Segoe Print', cursive",probe:"32px 'Patrick Hand'"},{id:"cursive",label:"Cursive",css:"'Dancing Script', 'Snell Roundhand', 'Brush Script MT', cursive",probe:"32px 'Dancing Script'"}];function _t(){return new Promise(t=>{if(!document.querySelector("link[data-hw-fonts]")){const i=document.createElement("link");i.rel="stylesheet",i.href=Bt,i.setAttribute("data-hw-fonts","1"),document.head.appendChild(i)}let n=!1;const r=()=>{n||(n=!0,t())};Promise.all(ze.map(i=>document.fonts.load(i.probe).catch(()=>{}))).then(r).catch(r),setTimeout(r,4e3)})}const Fe=[{id:"blue",label:"Blue",color:"#1a3a8f"},{id:"black",label:"Black",color:"#1a1a1a"},{id:"darkblue",label:"Navy",color:"#0d1b3e"},{id:"teal",label:"Teal",color:"#0f5a52"},{id:"red",label:"Red",color:"#9a1b1b"}],Ae=[{id:"fine",label:"Fine",w:0},{id:"medium",label:"Medium",w:5},{id:"bold",label:"Bold",w:11}],Ut=[{id:"ruled",label:"Ruled"},{id:"yellow",label:"Legal"},{id:"plain",label:"Plain"},{id:"grid",label:"Grid"}],ct="hw_glyphs_v1",_e=3;function Ot(t){const n={};for(const r in t){const i=t[r];
1Array.isArray(i)?n[r]=i.filter(Boolean).slice(0,_e):i&&i.img&&(n[r]=[i])}return n}const Ht=()=>{try{return Ot(JSON.parse(localStorage.getItem(ct))||{})}catch{return{}}},Ee=t=>{try{localStorage.setItem(ct,JSON.stringify(t))}catch{}};function Ce(t){const n=t.width,r=t.height,l=t.getContext("2d").getImageData(0,0,n,r).data;let u=n,c=r,a=-1,d=-1;for(let x=0;x<r;x++)for(let g=0;g<n;g++)l[(x*n+g)*4+3]>12&&(g<u&&(u=g),g>a&&(a=g),x<c&&(c=x),x>d&&(d=x));if(a<0)return null;const p=a-u+1,w=d-c+1,b=document.createElement("canvas");return b.width=p,b.height=w,b.getContext("2d").drawImage(t,u,c,p,w,0,0,p,w),{canvas:b,w:p,h:w,offsetTop:c}}const Se={};function Gt(){for(const t in Se)delete Se[t]}function Xt(t,n){if(t===" ")return null;let r=Se[n];if(!r){const c=document.createElement("canvas");c.width=O,c.height=O;const a=c.getContext("2d");let d=ae/.68;a.clearRect(0,0,O,O),a.fillStyle="#111",a.textBaseline="alphabetic",a.font=`${d}px ${n}`,a.fillText("H",20,ke);const p=Ce(c);p&&(d*=ae/p.h),r=d,Se[n]=r}const i=document.createElement("canvas");i.width=O,i.height=O;const l=i.getContext("2d");l.clearRect(0,0,O,O),l.fillStyle="#111",l.textBaseline="alphabetic",l.textAlign="left",l.font=`${r}px ${n}`,l.fillText(t,40,ke);const u=Ce(i);return u?{canvas:u.canvas,w:u.w,h:u.h,baseline:ke-u.offsetTop}:null}function qt(t,n,r,i,l=0){const u=document.createElement("canvas");u.width=n,u.height=r;const c=u.getContext("2d");if(l>0){const a=l;for(const[d,p]of[[-a,0],[a,0],[0,-a],[0,a],[-a,-a],[a,a],[-a,a],[a,-a]])c.drawImage(t,d,p,n,r)}return c.drawImage(t,0,0,n,r),c.globalCompositeOperation="source-in",c.fillStyle=i,c.fillRect(0,0,n,r),u}function dt(t,n,r=0){const i=n+"|"+r;return t._c||(t._c={}),t._c[i]||(t._c[i]=qt(t.raw,t.w,t.h,n,r)),t._c[i]}const Yt=1240,Jt=1754,We={a4:{px:[1240,1754],pt:[595.28,841.89],label:"A4"},letter:{px:[1275,1650],pt:[612,792],label:"Letter"},legal:{px:[1275,2100],pt:[612,1008],label:"Legal"}};function Vt(t,n,r,i,l,u){if(n==="yellow"?t.fillStyle="#fdf6d3":n==="plain"?t.fillStyle="#ffffff":t.fillStyle="#fffffb",t.fillRect(0,0,l,u),n==="grid"){t.strokeStyle="#d6e4f0",t.lineWidth=1;for(let c=0;c<=l;c+=34)t.beginPath(),t.moveTo(c,0),t.lineTo(c,u),t.stroke();for(let c=0;c<=u;c+=34)t.beginPath(),t.moveTo(0,c),t.lineTo(l,c),t.stroke();return}if(n!=="plain"){t.strokeStyle=n==="yellow"?"#c8bd7a":"#cdd9ec",t.lineWidth=1.4;for(let c=i+6;c<u-60;c+=r)t.beginPath(),t.moveTo(60,c),t.lineTo(l-50,c),t.stroke();t.strokeStyle="#e7a0a8",t.lineWidth=2,t.beginPath(),t.moveTo(108,40),t.lineTo(108,u-40),t.stroke()}}function ht(t){let n=t>>>0;return()=>(n=n*1664525+1013904223>>>0,n/4294967296)}function at(t,n,r){const{paper:i,fontSize:l,lineSpacing:u,slantDeg:c,messiness:a}=r,d=r.inkColor||"#1a3a8f",p=r.penWeight||0,w=r.pageW||Yt,b=r.pageH||Jt,x=l/ae,g=l*u,C=130,z=w-70,j=120,f=b-110,v=l*.34,N=l*.03,k=c*Math.PI/180,P=ht((2654435761^t.length)+(r.seed||0)*2654435761),T=W=>{const $=n.get(W);if(!$)return null;const G=$.variants;return G[Math.floor(P()*G.length)%G.length]},F=[];let h,o,y=0;const M=()=>{h=document.createElement("canvas"),h.width=w,h.height=b,o=h.getContext("2d"),Vt(o,i,g,j,w,b),F.push(h)};M();let m=C,R=j+l;const A=W=>{if(!W){m+=v;return}const $=W.w*x,G=W.h*x,Y=k+(P()-.5)*a*.14,ie=(P()-.5)*a*l*.09+y,q=1+(P()-.5)*a*.1;o.save(),o.globalAlpha=1-P()*a*.22,o.translate(m,R+ie),o.rotate(Y),o.scale(q,q),o.drawImage(dt(W,d,p),0,-W.baseline*x,$,G),o.restore(),m+=$+N+(P()-.5)*a*l*.05},E=(W=0)=>{m=C,R+=g+W,y=(P()-.5)*a*l*.14,R>f&&(M(),R=j+l)};y=(P()-.5)*a*l*.14;const H=t.replace(/\r\n/g,`
2`).split(/\n{2,}/).map(W=>W.replace(/\s*\n\s*/g," ").trim()).filter(Boolean);for(let W=0;W<H.length;W++){const $=H[W].split(/\s+/);for(const G of $){const Y=[...G].map(T);let ie=0;for(const q of Y)ie+=q?q.w*x+N:v;m>C&&m+ie>z&&E();for(const q of Y)A(q);m+=v,m>z&&E()}W<H.length-1?E(g*.35):E()}return F}const Kt=t=>{let n=2166136261;for(let r=0;r<t.length;r++)n^=t.charCodeAt(r),n=Math.imul(n,16777619);return n>>>0};function Zt(t,n,r,i,l,u,c,a){const d=t.data,p=Math.cos(a),w=Math.sin(a),b=(z,j)=>{z=z<0?0:z>=n?n-1:z|0,j=j<0?0:j>=r?r-1:j|0;const f=(j*n+z)*4;return[d[f],d[f+1],d[f+2]]},x=[[i-5*p,l-5*w],[i+(u+5)*p,l+(u+5)*w],[i+u*.5*p-w*c*.55,l+u*.5*w+p*c*.55],[i+u*.25*p-w*c*.55,l+u*.25*w+p*c*.55]];let g=-1,C=[255,255,255];for(const[z,j]of x){const f=b(z,j),v=.299*f[0]+.587*f[1]+.114*f[2];v>g&&(g=v,C=f)}return C}function Qt(t,n,r,i,l,u,c,a){const d=t.data,p=Math.max(0,i|0),w=Math.min(n,i+u|0),b=Math.max(0,l-c*.8|0),x=Math.min(r,l+c*.2|0);let g=0,C=0,z=0,j=0;for(let f=b;f<x;f++)for(let v=p;v<w;v++){const N=(f*n+v)*4,k=d[N]-a[0],P=d[N+1]-a[1],T=d[N+2]-a[2];k*k+P*P+T*T>1600&&(g+=d[N],C+=d[N+1],z+=d[N+2],j++)}return j?`rgb(${g/j|0},${C/j|0},${z/j|0})`:null}function en(t,n,r,i,l,u,c){const a=l/ae,d=u.penWeight?Math.max(1,Math.round(u.penWeight*.6)):0,p=l*.05,w=l*.32,b=ht(Kt(n)+(u.seed||0)*2654435761),x=[...n].map(f=>{if(f===" ")return null;const v=r.get(f);return v?v.variants[Math.floor(b()*v.variants.length)%v.variants.length]:null});let g=0;for(const f of x)g+=f?f.w*a+p:w;const C=Math.max(.32,Math.min(1.18,i/(g||1))),z=u.slantDeg*Math.PI/180;t.save(),t.scale(C,1);let j=0;for(const f of x){if(!f){j+=w;continue}const v=f.w*a,N=f.h*a,k=z+(b()-.5)*u.messiness*.1,P=(b()-.5)*u.messiness*l*.06;t.save(),t.translate(j,P),t.rotate(k),t.drawImage(dt(f,c,d),0,-f.baseline*a,v,N),t.restore(
2),j+=v+p}t.restore()}async function it(t,n,r,i,l){const{PDFDocument:u}=window.PDFLib,c=window.pdfjsLib.Util,a=await window.pdfjsLib.getDocument({data:t.slice()}).promise,d=l!=null,p=d?Math.min(Math.max(1,l),a.numPages):1,w=d?p:a.numPages,b=[],x=[];for(let C=p;C<=w;C++){i?.(C,a.numPages);const z=await a.getPage(C),j=z.getViewport({scale:1});let f=2;Math.max(j.width,j.height)*f>4e3&&(f=4e3/Math.max(j.width,j.height));const N=z.getViewport({scale:f}),k=document.createElement("canvas");k.width=Math.floor(N.width),k.height=Math.floor(N.height);const P=k.getContext("2d",{willReadFrequently:!0});P.fillStyle="#ffffff",P.fillRect(0,0,k.width,k.height),await z.render({canvasContext:P,viewport:N}).promise;const T=P.getImageData(0,0,k.width,k.height),F=await z.getTextContent();for(const h of F.items){const o=h.str;if(!o||!o.trim())continue;const y=c.transform(N.transform,h.transform),M=Math.hypot(y[2],y[3]);if(M<4)continue;const m=(h.width||0)*f;if(m<1)continue;const R=Math.atan2(y[1],y[0]),A=y[4],E=y[5],H=Zt(T,k.width,k.height,A,E,m,M,R),W=r.autoColor&&Qt(T,k.width,k.height,A,E,m,M,H)||r.inkColor;P.save(),P.translate(A,E),P.rotate(R),P.fillStyle=`rgb(${H[0]},${H[1]},${H[2]})`,P.fillRect(-M*.12,-M*.86,m+M*.24,M*1.12),en(P,o,n,m,M,r,W),P.restore()}b.push(k),x.push([j.width,j.height]),z.cleanup?.()}if(d)return{canvases:b,sizes:x,numPages:a.numPages};const g=await u.create();for(let C=0;C<b.length;C++){i?.(b.length+C,b.length);const z=await fetch(b[C].toDataURL("image/png")).then(k=>k.arrayBuffer()),j=await g.embedPng(z),[f,v]=x[C];g.addPage([f,v]).drawImage(j,{x:0,y:0,width:f,height:v})}return{bytes:await g.save(),numPages:a.numPages}}async function tn(t,n){const r=await window.pdfjsLib.getDocument({data:t.slice()}).promise;let i="";for(let l=1;l<=r.numPages;l++){n?.(l,r.numPages);const u=await r.getPage(l),c=await u.getTextContent();let a=null;for(const d of c.items)!d.str&&!d.hasEOL||(a&&Math.abs((d.transform?.[5]??0)-a)>4&&!i.endsWith(`
3`)&&(i+=`
4`),i+=d.str,d.hasEOL&&!i.endsWith(`
5`)&&(i+=`
6`),a=d.transform?.[5]??a);i+=`
7
8`,u.cleanup?.()}return i.replace(/\n{3,}/g,`
9
10`).trim()}function nn({initialChar:t,glyphs:n,onSaveGlyph:r,onClose:i}){const[l,u]=S.useState(Math.max(0,K.indexOf(t))),c=K[l],a=S.useRef(null),d=S.useRef([]),p=S.useRef(null),[w,b]=S.useState(0),x=300,g=S.useCallback(()=>{const h=a.current;if(!h)return;const o=h.getContext("2d");o.setTransform(1,0,0,1,0,0),o.clearRect(0,0,h.width,h.height);const y=h.width/x;o.setTransform(y,0,0,y,0,0),o.strokeStyle="#111",o.lineWidth=4.5,o.lineCap="round",o.lineJoin="round";const M=[...d.current];p.current&&M.push(p.current);for(const m of M){if(m.length<2){m.length&&(o.beginPath(),o.arc(m[0].x,m[0].y,2.2,0,7),o.fillStyle="#111",o.fill());continue}o.beginPath(),o.moveTo(m[0].x,m[0].y);for(let R=1;R<m.length-1;R++){const A=(m[R].x+m[R+1].x)/2,E=(m[R].y+m[R+1].y)/2;o.quadraticCurveTo(m[R].x,m[R].y,A,E)}o.lineTo(m[m.length-1].x,m[m.length-1].y),o.stroke()}},[]);S.useEffect(()=>{const h=a.current,o=window.devicePixelRatio||1;h.width=x*o,h.height=x*o,d.current=[],p.current=null,g()},[l,g]);const C=h=>{const o=a.current.getBoundingClientRect();return{x:(h.clientX-o.left)/o.width*x,y:(h.clientY-o.top)/o.height*x}},z=h=>{h.preventDefault(),a.current.setPointerCapture?.(h.pointerId),p.current=[C(h)],g()},j=h=>{p.current&&(p.current.push(C(h)),g())},f=()=>{p.current&&(d.current.push(p.current),p.current=null,b(d.current.length),g())},v=()=>{d.current.pop(),b(d.current.length),g()},N=()=>{d.current=[],p.current=null,b(0),g()},k=()=>{if(!d.current.length)return!1;const h=document.createElement("canvas");h.width=O,h.height=O;const o=h.getContext("2d"),y=O/x;o.strokeStyle="#111",o.lineWidth=4.5*y,o.lineCap="round",o.lineJoin="round",o.fillStyle="#111";for(const m of d.current){if(m.length<2){m.length&&(o.beginPath(),o.arc(m[0].x*y,m[0].y*y,2.2*y,0,7),o.fill());continue}o.beginPath(),o.moveTo(m[0].x*y,m[0].y*y);for(let R=1;R<m.length-1;R++){const A=(m[R].x+m[R+1].x)/2*y,E=(m[R].y+m[R+1].y)/2*y;o.quadraticCurveTo(m[R].x*y,m[R].y*y,A,E)}o.lineTo(m[m.length-1].x*y,m[m.length-1].y*y),o.stroke()}const M=Ce(h);return M?(r(c,{img:M.canvas.toDataURL("image/png"),w:M.w,h:M.h,baseline:ke-M.offsetTop}),!0):!1},P=h=>{b(0),u(o=>Math.max(0,Math.min(K.length-1,o+h)))},T=()=>{k(),P(1)},F=K.filter(h=>n[h]).length;return e.jsx("div",{onClick:i,style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.8)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",padding:16},children:e.jsxs("div",{onClick:h=>h.stopPropagation(),style:{background:"#18181b",border:"1px solid rgba(255,255,255,0.1)",borderRadius:16,padding:20,width:380,maxWidth:"100%"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[e.jsx("div",{style:{color:"#fff",fontWeight:800,fontSize:14},children:"Write this letter"}),e.jsx("button",{"aria-label":"Close",onClick:i,style:{background:"none",border:"none",color:"#a1a1aa",cursor:"pointer"},children:e.jsx(Be,{size:18})})]}),e.jsxs("div",{style:{color:"#71717a",fontSize:11,marginBottom:12},children:[F,"/",K.length," letters personalised · trace the ghost guide"]}),e.jsxs("div",{style:{position:"relative",width:x,height:x,margin:"0 auto",borderRadius:12,overflow:"hidden",background:"#fbfbf7",border:"1px solid rgba(0,0,0,0.15)"},children:[e.jsxs("svg",{width:x,height:x,style:{position:"absolute",inset:0},children:[[$e,.45,Q,.92].map((h,o)=>e.jsx("line",{x1:"0",x2:x,y1:h*x,y2:h*x,stroke:h===Q?"#9db7e0":"#e2e2dc",strokeWidth:h===Q?1.5:1,strokeDasharray:h===Q?"0":"5 5"},o)),e.jsx("text",{x:x/2,y:Q*x,textAnchor:"middle",fontSize:(Q-$e)*x*1.35,fill:"rgba(0,0,0,0.07)",fontFamily:ze[0].css,children:c})]}),e.jsx("canvas",{ref:a,style:{position:"absolute",inset:0,width:x,height:x,touchAction:"none",cursor:"crosshair"},onPointerDown:z,onPointerMove:j,onPointerUp:f,onPointerLeave:f}),e.jsx("div",{style:{position:"absolute",top:8,left:10,fontSize:34,fontWeight:800,color:"#e4e4e7"},children:c}),n[c]&&e.jsx("div",{style:{position:"absolute",top:8,right:10,fontSize:10,
10color:"#16a34a",fontWeight:700},children:"✓ saved"})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:12},children:[e.jsxs("button",{onClick:v,disabled:!w,style:se(w?"#3f3f46":"#27272a","#e4e4e7"),children:[e.jsx(Ft,{size:13})," Undo"]}),e.jsx("button",{onClick:N,style:se("#3f3f46","#e4e4e7"),children:"Clear"}),e.jsx("button",{onClick:()=>P(-1),disabled:l===0,style:se("#3f3f46","#e4e4e7"),children:"‹ Prev"})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:8},children:[e.jsx("button",{onClick:()=>P(1),style:{...se("#27272a","#a1a1aa"),flex:1},children:"Skip"}),e.jsx("button",{onClick:T,style:{...se("#fafafa","#18181b"),flex:2,fontWeight:800},children:"Save & Next ›"})]})]})})}const se=(t,n)=>({display:"flex",alignItems:"center",justifyContent:"center",gap:5,flex:1,height:36,borderRadius:9,border:"none",background:t,color:n,fontSize:12,fontWeight:600,cursor:"pointer"}),ot="https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js";function sn(){return new Promise((t,n)=>{if(window.Tesseract)return t(window.Tesseract);if(document.querySelector(`script[src="${ot}"]`)){const l=setInterval(()=>{window.Tesseract&&(clearInterval(l),t(window.Tesseract))},100);return}const i=document.createElement("script");i.src=ot,i.onload=()=>t(window.Tesseract),i.onerror=()=>n(new Error("Failed to load the OCR engine")),document.head.appendChild(i)})}function an(t,n){let r=0;for(let a=0;a<256;a++)r+=a*t[a];let i=0,l=0,u=-1,c=127;for(let a=0;a<256;a++){if(l+=t[a],!l)continue;const d=n-l;if(!d)break;i+=a*t[a];const p=i/l,w=(r-i)/d,b=l*d*(p-w)*(p-w);b>=u&&(u=b,c=a)}return c}function on(t){const n=t.width,r=t.height,i=n*r,l=t.getContext("2d",{willReadFrequently:!0}).getImageData(0,0,n,r).data,u=new Float32Array(i);for(let h=0,o=0;h<i;h++,o+=4)u[h]=.299*l[o]+.587*l[o+1]+.114*l[o+2];const c=Math.max(10,Math.min(60,Math.round(Math.max(n,r)/20))),a=Math.ceil(n/c),d=Math.ceil(r/c),p=new Float32Array(a*d);for(let h=0;h<d;h++)for(let o=0;o<a;o++){let y=0;const M=Math.min(n,(o+1)*c),m=Math.min(r,(h+1)*c);for(let R=h*c;R<m;R++)for(let A=o*c;A<M;A++){const E=u[R*n+A];E>y&&(y=E)}p[h*a+o]=y}const w=new Float32Array(a*d);for(let h=0;h<d;h++)for(let o=0;o<a;o++){let y=0;for(let M=-1;M<=1;M++){const m=h+M;if(!(m<0||m>=d))for(let R=-1;R<=1;R++){const A=o+R;if(A<0||A>=a)continue;const E=p[m*a+A];E>y&&(y=E)}}w[h*a+o]=y}const b=(h,o)=>w[Math.min(d-1,o/c|0)*a+Math.min(a-1,h/c|0)]||1,x=new Float32Array(i),g=new Uint32Array(256);for(let h=0;h<r;h++)for(let o=0;o<n;o++){const y=h*n+o;let M=1-u[y]/Math.max(1,b(o,h));M=M<0?0:M>1?1:M,x[y]=M,g[M*255|0]++}let C=an(g,i)/255;C=Math.max(.12,C);const z=.04,j=document.createElement("canvas");j.width=n,j.height=r;const f=j.getContext("2d"),v=f.createImageData(n,r),N=v.data,k=document.createElement("canvas");k.width=n,k.height=r;const P=k.getContext("2d"),T=P.createImageData(n,r),F=T.data;for(let h=0;h<i;h++){let o=(x[h]-(C-z))/(2*z);o=o<0?0:o>1?1:o;const y=h*4,M=(1-o)*255|0;F[y]=F[y+1]=F[y+2]=M,F[y+3]=255,o>.01&&(N[y+3]=o*255|0)}return f.putImageData(v,0,0),P.putImageData(T,0,0),{inkCanvas:j,ocrCanvas:k}}const rt=/^[A-Za-z0-9.,'"!?;:\-()/&@#%$+=]$/,de=(()=>{const t={},n=(r,i,l)=>{for(const u of r)t[u]=[i,l]};return n("acemnorsuvwxz",.54,.02),n("bdfhkl",1,.02),n("t",.86,.02),n("i",.74,.02),n("gpqy",.54,.36),n("j",.74,.36),n("ABCDEFGHIJKLMNOPQRSTUVWXYZ",1,.02),n("0123456789",1,.02),n(".",.1,0),n(",;",.12,.16),n(`'"`,1,-.6),n("-",.42,-.3),n("()/",.92,.12),n("?!&@#%$+=",1,.02),n(":",.54,0),t})();
10function rn(t,n,r){const i=t.width,l=t.height,u=t.getContext("2d"),c=u.getImageData(0,0,i,l),a=c.data,d=new Uint8Array(i*l),p=[];let w=!1;for(let b=0;b<l;b++)for(let x=0;x<i;x++){const g=b*i+x;if(d[g]||a[g*4+3]<=12)continue;const C=[];let z=x,j=x;for(p.length=0,p.push(g),d[g]=1;p.length;){const N=p.pop();C.push(N);const k=N%i,P=N/i|0;k<z&&(z=k),k>j&&(j=k);for(let T=-1;T<=1;T++)for(let F=-1;F<=1;F++){if(!F&&!T)continue;const h=k+F,o=P+T;if(h<0||o<0||h>=i||o>=l)continue;const y=o*i+h;!d[y]&&a[y*4+3]>12&&(d[y]=1,p.push(y))}}const f=j-z+1,v=Math.min(j,r)-Math.max(z,n)+1;if(v<f*.45&&v<(r-n+1)*.3){for(const N of C)a[N*4+3]=0;w=!0}}w&&u.putImageData(c,0,0)}function lt(t,n,r){const i=de[r];if(!i)return null;const l=Math.round((n.x1-n.x0)*.18)+2,u=Math.round((n.y1-n.y0)*.18)+2,c=Math.max(0,Math.round(n.x0-l)),a=Math.max(0,Math.round(n.y0-u)),d=Math.min(t.width,Math.round(n.x1+l)),p=Math.min(t.height,Math.round(n.y1+u)),w=d-c,b=p-a;if(w<3||b<3)return null;const x=document.createElement("canvas");x.width=w,x.height=b,x.getContext("2d").drawImage(t,c,a,w,b,0,0,w,b),rn(x,Math.round(n.x0)-c,Math.round(n.x1)-c);const g=Ce(x);if(!g||g.h<6||g.w<2)return null;const[C,z]=i,f=Math.max(.08,C+z)*ae/g.h;if(f>30||f<.02)return null;const v=Math.max(1,Math.round(g.w*f)),N=Math.max(1,Math.round(g.h*f));if(v>1400||N>900)return null;const k=document.createElement("canvas");return k.width=v,k.height=N,k.getContext("2d").drawImage(g.canvas,0,0,v,N),{img:k.toDataURL("image/png"),w:v,h:N,baseline:C*ae}}async function ln(t,n){n?.("Preparing image…");const i=Math.min(1,1800/Math.max(t.naturalWidth,t.naturalHeight)),l=Math.max(1,Math.round(t.naturalWidth*i)),u=Math.max(1,Math.round(t.naturalHeight*i)),c=document.createElement("canvas");c.width=l,c.height=u,c.getContext("2d").drawImage(t,0,0,l,u),n?.("Cleaning the ink…");const{inkCanvas:a,ocrCanvas:d}=on(c);n?.("Reading your handwriting…");const w=await(await sn()).createWorker("eng",1,{logger:()=>{}});let b;try{({data:b}=await w.recognize(d,{},{blocks:!0}))}finally{await w.terminate()}n?.("Cutting out letters…");const x=[];for(const C of b.blocks||[])for(const z of C.paragraphs||[])for(const j of z.lines||[])x.push(j);const g=[];for(const C of x){const z=[];for(const f of C.words||[])for(const v of f.symbols||[])v.bbox&&z.push(v);const j=z.filter(f=>f.text&&rt.test(f.text.trim()));if(j.length)for(const f of j){if((f.confidence??0)<40)continue;const v=f.text.trim(),N=lt(a,f.bbox,v);N&&(N.ch=v,N.conf=Math.round(f.confidence||0),g.push(N))}else for(const f of C.words||[]){const N=[...(f.text||"").trim()].filter(o=>rt.test(o));if(!N.length||!f.bbox)continue;const{x0:k,y0:P,x1:T,y1:F}=f.bbox,h=(T-k)/N.length;N.forEach((o,y)=>{const M=lt(a,{x0:k+y*h,y0:P,x1:k+(y+1)*h,y1:F},o);M&&(M.ch=o,M.conf=Math.round(f.confidence||0),g.push(M))})}}return g}function cn({dets:t,onApply:n,onClose:r}){const[i,l]=S.useState(()=>t.map(a=>a.ch||"")),u=i.filter(a=>a.trim()).length,c=()=>{const a={};t.forEach((d,p)=>{const w=(i[p]||"").trim().slice(0,1);if(!w)return;let{w:b,h:x,baseline:g}=d;if(w!==d.ch&&de[w]&&de[d.ch]){const[C,z]=de[d.ch],[j,f]=de[w],v=Math.max(.08,j+f)/Math.max(.08,C+z);b=Math.max(1,Math.round(b*v)),x=Math.max(1,Math.round(x*v)),g=j*ae}(a[w]=a[w]||[]).push({img:d.img,w:b,h:x,baseline:g})});for(const d in a)a[d]=a[d].slice(0,_e);n(a)};return e.jsx("div",{onClick:r,style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.8)",zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",padding:16},children:e.jsxs("div",{onClick:a=>a.stopPropagation(),style:{background:"#18181b",border:"1px solid rgba(255,255,255,0.1)",borderRadius:16,padding:20,width:560,maxWidth:"100%",maxHeight:"85vh",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:4},children:[e.jsx("div",{style:{color:"#fff",fontWeight:800,fontSize:14},children:"Check the detected letters"}),e.jsx("button",{"aria-label":"Close",onClick:r,style:{background:"none",border:"none",color:"#a1a1aa",cursor:"pointer"},children:e.jsx(Be,{size:18})})]}),e.jsxs("div",{style:{color:"#71717a",fontSize:11,marginBottom:14},children:[t.length," letters found · fix any wrong labels, clear a box to skip it. ",u," will be saved."]}),e.jsx("div",{style:{overflowY:"auto",display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(64px, 1fr))",gap:10,paddingRight:4},children:t.map((a,d)=>e.jsxs("div",{style:{border:"1px solid rgba(255,255,255,0.1)",borderRadius:10,padding:6,background:"#0c0c0e",display:"flex",flexDirection:"column",alignItems:"center",gap:5},children:[e.jsx("div",{style:{height:44,display:"flex",alignItems:"center",justifyContent:"center",background:"repeating-conic-gradient(#27272a 0% 25%, #3f3f46 0% 50%) 50% / 10px 10px",borderRadius:6,width:"100%"},children:e.jsx("img",{src:a.img,alt:a.ch,style:{maxHeight:40,maxWidth:"90%"}})}),e.jsx("input",{value:i[d],onChange:p=>{const w=p.target.value.slice(-1);l(b=>b.map((x,g)=>g===d?w:x))}
10,maxLength:1,style:{width:34,height:30,textAlign:"center",background:i[d]?"#27272a":"#3f1d1d",border:"1px solid rgba(255,255,255,0.12)",borderRadius:6,color:"#fff",fontSize:15,fontWeight:700}})]},d))}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:16},children:[e.jsx("button",{onClick:r,style:{...se("#3f3f46","#e4e4e7"),flex:1},children:"Cancel"}),e.jsxs("button",{onClick:c,disabled:!u,style:{...se("#fafafa","#18181b"),flex:2,fontWeight:800,opacity:u?1:.4,cursor:u?"pointer":"not-allowed"},children:["Add ",u," letter",u===1?"":"s"," to my handwriting"]})]})]})})}function hn({showNotification:t,defaultSrcMode:n="pdf"}){const[r,i]=S.useState(!1),[l,u]=S.useState(Ht),[c,a]=S.useState(null),[d,p]=S.useState("casual"),[w,b]=S.useState(null),[x,g]=S.useState(!1),[C,z]=S.useState(""),[j,f]=S.useState(!1);S.useEffect(()=>{let s=!0;return _t().then(()=>{s&&(Gt(),f(!0))}),()=>{s=!1}},[]);const[v,N]=S.useState(n),[k,P]=S.useState("original"),[T,F]=S.useState(null),[h,o]=S.useState(""),[y,M]=S.useState(""),[m,R]=S.useState(!1),[A,E]=S.useState("ruled"),[H,W]=S.useState("a4"),[$,G]=S.useState("auto"),[Y,ie]=S.useState("#1a3a8f"),[q,ut]=S.useState("medium"),[Ne,xt]=S.useState(34),[Me,ft]=S.useState(2),[Pe,gt]=S.useState(-3),[Re,pt]=S.useState(.5),[Ue,mt]=S.useState(0),[Oe,he]=S.useState(null),[le,ue]=S.useState(0),[oe,ee]=S.useState(0),[xe,fe]=S.useState(!1),[He,Z]=S.useState(""),Ge=S.useRef(),te=S.useRef(null),Xe=S.useRef(),bt=async s=>{if(!s||!s.type.startsWith("image/")){t?.("Please choose a photo of your handwriting","error");return}g(!0),z("Preparing…");try{const I=await Qe(URL.createObjectURL(s)),L=await ln(I,D=>z(D));L.length?b(L):t?.("Couldn't read any letters — try a clearer, flatter photo with good light.","error")}catch(I){t?.("Scan failed: "+I.message,"error")}finally{g(!1),z("")}};S.useEffect(()=>{Promise.all([Le(It),Le(Dt)]).then(()=>Le(Ze).catch(()=>{})).then(()=>{window.pdfjsLib&&!window.pdfjsLib.GlobalWorkerOptions.workerSrc&&(window.pdfjsLib.GlobalWorkerOptions.workerSrc=Ze),i(!!window.pdfjsLib&&!!window.PDFLib)}).catch(s=>t?.("Library load failed: "+s.message,"error"))},[t]);const wt=$==="custom"?Y:(Fe.find(s=>s.id===$)||Fe[0]).color,qe=ze.find(s=>s.id===d).css,J=v==="pdf"?h:y,V=v==="pdf"&&k==="original",re=K.filter(s=>l[s]&&l[s].length).length,yt=(Ae.find(s=>s.id===q)||Ae[1]).w,jt=(s,I)=>{u(L=>{const D={...L,[s]:[I]};return Ee(D),D})},vt=s=>{u(I=>{const L={...I};for(const D in s){const B=s[D];!B||!B.length||(L[D]=[...B,...L[D]||[]].slice(0,_e))}return Ee(L),L})},kt=()=>{u({}),Ee({})},ge=S.useCallback(async s=>{const I=new Map,L=[...new Set(s)];for(const D of L){if(D===" "||D===`
11`)continue;const B=l[D];if(B&&B.length){const _=[];for(const U of B){const ne=await Qe(U.img);_.push({raw:ne,w:U.w,h:U.h,baseline:U.baseline})}I.set(D,{variants:_})}else{const _=Xt(D,qe);_&&I.set(D,{variants:[{raw:_.canvas,w:_.w,h:_.h,baseline:_.baseline}]})}}return I},[l,qe]),zt=V&&$==="auto",Ie=We[H]||We.a4,pe={paper:A,fontSize:Ne,lineSpacing:Me,slantDeg:Pe,messiness:Re,inkColor:wt,autoColor:zt,penWeight:yt,seed:Ue,pageW:Ie.px[0],pageH:Ie.px[1]};S.useEffect(()=>{let s=!1;const I=setTimeout(async()=>{try{if(V){if(!te.current){he(null),ue(0);return}const _=await ge(J||"");if(s)return;const{canvases:U,numPages:ne}=await it(te.current,_,pe,null,(oe||0)+1);if(s)return;ue(ne),he(U[0]?U[0].toDataURL("image/png"):null);return}if(!J.trim()){he(null),ue(0);return}const L=await ge(J.slice(0,8e3));if(s)return;const D=at(J,L,pe);if(s)return;ue(D.length);const B=Math.min(oe,D.length-1);he(D[B].toDataURL("image/png"))}catch{}},200);return()=>{s=!0,clearTimeout(I)}},[J,v,k,A,H,$,Y,q,d,Ne,Me,Pe,Re,Ue,oe,l,j]);const Ye=async s=>{if(!s||s.type!=="application/pdf"&&!/\.pdf$/i.test(s.name)){t?.("Please choose a PDF","error");return}F(s),o(""),ee(0),te.current=null,fe(!0),Z("Extracting text…");try{const I=new Uint8Array(await s.arrayBuffer());te.current=I;const L=await tn(I,(D,B)=>Z(`Reading page ${D}/${B}…`));L.trim()||t?.("No selectable text found — this PDF looks scanned. Run OCR first, or paste text.","error"),o(L)}catch(I){t?.("Could not read PDF: "+I.message,"error")}finally{fe(!1),Z("")}},Je=(s,I)=>{const L=new Blob([s],{type:"application/pdf"}),D=URL.createObjectURL(L),B=document.createElement("a"),_=T?T.name.replace(/\.pdf$/i,""):"notes";B.href=D,B.download=`${_}_handwritten.pdf`,B.click(),setTimeout(()=>URL.revokeObjectURL(D),4e3),t?.(I,"success")},Ct=async()=>{fe(!0),Z("Building your handwriting…");try{if(V){if(!te.current)return;const U=await ge(h),{bytes:ne,numPages:Te}=await it(te.current,U,pe,(Ke,ye)=>Z(`Rendering page ${Math.min(Ke,ye)}/${ye}…`));Je(ne,`Downloaded ${Te}-page handwritten PDF (original layout kept)`);return}if(!J.trim())return;const s=await ge(J),I=at(J,s,pe);Z("Assembling PDF…");const{PDFDocument:L}=window.PDFLib,D=await L.create(),[B,_]=Ie.pt;for(let U=0;U<I.length;U++){Z(`Adding page ${U+1}/${I.length}…`);const ne=await fetch(I[U].toDataURL("image/png")).then(ye=>ye.arrayBuffer()),Te=await D.embedPng(ne);D.addPage([B,_]).drawImage(Te,{x:0,y:0,width:B,height:_})}Je(await D.save(),`Downloaded ${I.length}-page handwritten PDF`)}catch(s){t?.("Error: "+s.message,"error")}finally{fe(!1),Z("")}},me=s=>`px-3 py-1.5 rounded-lg text-xs font-bold border transition-all ${s?"bg-zinc-800 border-zinc-500 text-white ring-1 ring-zinc-400":"bg-zinc-900 border-zinc-800 text-zinc-400 hover:border-zinc-600 hover:text-zinc-200"}`,be="surface-raised rounded-2xl p-4 sm:p-5",we="text-[10px] font-bold text-zinc-500 uppercase tracking-wider mb-1.5",De=({n:s,title:I,right:L})=>e.jsxs("div",{className:"flex items-center gap-2.5 mb-4",children:[e.jsx("span",{className:"w-5 h-5 rounded-full bg-zinc-100 text-zinc-900 text-[10px] font-black flex items-center justify-center shrink-0",children:s}),e.jsx("span",{className:"text-[11px] font-black text-zinc-200 uppercase tracking-[1.5px]",children:I}),L&&e.jsx("span",{className:"ml-auto",children:L})]}),ce=({children:s})=>e.jsx("span",{className:"shrink-0 whitespace-nowrap inline-flex items-center gap-1 text-[10px] font-semibold text-zinc-300 bg-zinc-900/70 border border-zinc-800 rounded-full px-2.5 py-1",children:s}),St=Math.round(re/K.length*100),Nt=!xe&&r&&J.trim(),Mt=()=>mt(s=>s+1),Pt=()=>ee(s=>Math.max(0,s-1)),Rt=()=>ee(s=>Math.min((le||1)-1,s+1)),Ve=s=>`w-7 h-7 rounded-full border-2 transition-all ${s?"border-white scale-110":"border-zinc-700 hover:scale-105"}`;return e.jsxs("div",{className:"flex flex-col max-w-5xl mx-auto w-full px-4 sm:px-5 pt-2 pb-[max(3rem,env(safe-area-inset-bottom))]",children:[c&&e.jsx(nn,{initialChar:c===!0?K[0]:c,glyphs:l,onSaveGlyph:jt,onClose:()=>a(null)}),w&&e.jsx(cn,{dets:w,onApply:s=>
11{vt(s),b(null),t?.("Handwriting added from your photo","success")},onClose:()=>b(null)}),e.jsxs("div",{className:"mb-7",children:[e.jsxs("h1",{className:"text-2xl sm:text-[30px] leading-[1.15] font-black text-white tracking-tight",children:[n==="text"?"Turn your text into":"Turn any PDF into"," ",e.jsx("span",{className:"underline decoration-zinc-700 decoration-2 underline-offset-[6px]",children:"your handwriting"})]}),e.jsx("p",{className:"text-zinc-400 text-sm mt-2.5 max-w-xl leading-relaxed",children:n==="text"?"Type or paste anything and get it back as handwritten notes. Nothing is ever uploaded.":"Keep the original page layout, or rewrite onto notebook paper. Nothing is ever uploaded."}),e.jsxs("div",{className:"flex gap-2 mt-4 overflow-x-auto -mx-4 px-4 sm:mx-0 sm:px-0 sm:flex-wrap [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:[e.jsxs(ce,{children:[e.jsx(nt,{size:11,className:"text-emerald-400"})," 100% private"]}),e.jsx(ce,{children:"No upload"}),e.jsx(ce,{children:"No watermark"}),e.jsx(ce,{children:"No sign-up"}),e.jsx(ce,{children:"Free"})]})]}),e.jsxs("div",{className:"grid lg:grid-cols-[1fr_390px] gap-5 items-start",children:[e.jsxs("div",{className:"flex flex-col gap-4 min-w-0",children:[e.jsxs("div",{className:be,children:[e.jsx(De,{n:"1",title:"Your handwriting",right:re>0?e.jsx("button",{onClick:kt,className:"text-[10px] font-semibold text-zinc-500 hover:text-zinc-200 transition-colors",children:"Reset"}):null}),e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"text-sm font-bold text-zinc-100",children:re>0?`${re} of ${K.length} letters are yours`:"Using a handwriting font"}),e.jsx("div",{className:"text-[11px] text-zinc-500 mt-0.5 leading-relaxed",children:"Snap a photo of any note in your handwriting and we'll read your letters automatically — or draw them in."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-1",children:[e.jsx("button",{onClick:()=>Xe.current?.click(),disabled:x,className:"px-3 py-2.5 rounded-xl text-xs font-black text-zinc-900 flex items-center justify-center gap-1.5 bg-zinc-100 hover:bg-white transition-all active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed",children:x?e.jsxs(e.Fragment,{children:[e.jsx(je,{size:13})," Scanning…"]}):e.jsxs(e.Fragment,{children:[e.jsx(At,{size:13})," ",e.jsx("span",{className:"whitespace-nowrap",children:"Scan a photo"})]})}),e.jsxs("button",{onClick:()=>a(!0),className:"px-3 py-2.5 rounded-xl text-xs font-bold text-zinc-200 flex items-center justify-center gap-1.5 bg-zinc-800 border border-zinc-700 hover:bg-zinc-700 transition-all active:scale-95",children:[e.jsx(et,{size:13})," ",re>0?"Edit / draw":"Draw letters"]})]}),e.jsx("input",{ref:Xe,type:"file",accept:"image/*",className:"hidden",onChange:s=>bt(s.target.files[0])}),x&&C&&e.jsxs("div",{className:"text-[10px] text-zinc-500 mt-2 flex items-center gap-1.5",children:[e.jsx(Et,{size:11,className:"text-zinc-400"}),C]}),re>0&&e.jsx("div",{className:"h-1.5 rounded-full bg-zinc-800 overflow-hidden mb-3.5",children:e.jsx("div",{className:"h-full bg-zinc-100 transition-all",style:{width:`${St}%`}})}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-[10px] text-zinc-500",children:"Font style:"}),ze.map(s=>e.jsx("button",{onClick:()=>p(s.id),className:me(d===s.id),style:{fontFamily:s.css,fontSize:15},children:s.label},s.id))]})]}),e.jsxs("div",{className:be,children:[e.jsx(De,{n:"2",title:"Content"}),e.jsx("div",{className:"inline-flex p-1 rounded-xl bg-zinc-800/60 border border-zinc-800 mb-3",children:[{id:"pdf",label:"From PDF",Icon:st},{id:"text",label:"Type / paste",Icon:Wt}].map(s=>e.jsxs("button",{onClick:()=>{N(s.id),ee(0)},className:`flex items-center gap-1.5 px-3.5 py-1.5 rounded-lg text-xs font-bold transition-all ${v===s.id?"bg-zinc-100 text-zinc-900":"text-zinc-400 hover:text-zinc-200"}`,children:[e.jsx(s.Icon,{size:13})," ",s.label]},s.id))}),v==="pdf"?T?e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-zinc-800/50 border border-zinc-700 rounded-xl",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-zinc-800 border border-zinc-700 flex items-center justify-center shrink-0",children:e.jsx(st,{size:15,className:"text-zinc-300"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-zinc-100 truncate",children:T.name}),e.jsx("div",{className:"text-[10px] text-zinc-500",children:h?`${h.length.toLocaleStr
11ing()} characters ready`:"reading…"})]}),e.jsx("button",{"aria-label":"Remove file",onClick:()=>{F(null),o(""),te.current=null,ee(0)},className:"p-1.5 text-zinc-500 hover:text-zinc-200 hover:bg-zinc-700 rounded-lg transition-all",children:e.jsx(Be,{size:14})})]}):e.jsxs("div",{onDragOver:s=>{s.preventDefault(),R(!0)},onDragLeave:()=>R(!1),onDrop:s=>{s.preventDefault(),R(!1),Ye(s.dataTransfer.files[0])},onClick:()=>Ge.current?.click(),className:`group flex flex-col items-center justify-center gap-3 border-2 border-dashed rounded-2xl cursor-pointer transition-all py-12 px-8 ${m?"border-zinc-400 bg-zinc-800/40":"border-zinc-700 hover:border-zinc-500 hover:bg-zinc-900/60"}`,children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-zinc-800 border border-zinc-700 flex items-center justify-center group-hover:scale-105 transition-transform",children:e.jsx(Tt,{size:20,className:"text-zinc-300"})}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-white font-bold text-sm",children:"Drop a PDF here"}),e.jsx("div",{className:"text-zinc-500 text-xs",children:"or click to browse — never leaves your device"})]}),e.jsx("input",{ref:Ge,type:"file",accept:"application/pdf",className:"hidden",onChange:s=>Ye(s.target.files[0])})]}):e.jsx("textarea",{value:y,onChange:s=>{M(s.target.value),ee(0)},placeholder:"Type or paste the text you want in handwriting…",className:"w-full h-32 bg-zinc-950/60 border border-zinc-800 rounded-xl p-3 text-sm text-zinc-200 placeholder-zinc-600 resize-y focus:outline-none focus:border-zinc-500 focus:ring-1 focus:ring-zinc-600"}),v==="pdf"&&e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 mt-3",children:[{id:"original",title:"Keep original design",desc:"Same pages, images & layout — only text becomes handwritten, in place."},{id:"notebook",title:"Notebook paper",desc:"Reflow the text onto fresh ruled or plain paper."}].map(s=>e.jsxs("button",{onClick:()=>{P(s.id),ee(0),s.id==="notebook"&&$==="auto"&&G("blue")},className:`relative text-left p-3 rounded-xl border transition-all ${k===s.id?"bg-zinc-800 border-zinc-500 ring-1 ring-zinc-400":"bg-zinc-900 border-zinc-800 hover:border-zinc-600"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-black text-zinc-100",children:s.title}),k===s.id&&e.jsx(tt,{size:12,className:"text-zinc-100 ml-auto"})]}),e.jsx("div",{className:"text-[9px] text-zinc-500 mt-1 leading-relaxed",children:s.desc})]},s.id))})]}),e.jsxs("div",{className:be,children:[e.jsx(De,{n:"3",title:"Style",right:e.jsx("button",{onClick:Mt,title:"Re-roll the natural variation",className:"inline-flex items-center gap-1 text-[10px] font-bold text-zinc-400 hover:text-white bg-zinc-800/80 border border-zinc-700 rounded-lg px-2 py-1 transition-colors active:scale-95",children:"↻ Shuffle"})}),!V&&e.jsxs("div",{className:"grid grid-cols-2 gap-4 mb-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:we,children:"Paper"}),e.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Ut.map(s=>e.jsx("button",{onClick:()=>E(s.id),className:me(A===s.id),children:s.label},s.id))})]}),e.jsxs("div",{children:[e.jsx("div",{className:we,children:"Page size"}),e.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Object.entries(We).map(([s,I])=>e.jsx("button",{onClick:()=>W(s),className:me(H===s),children:I.label},s))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:we,children:["Ink",V&&$==="auto"&&e.jsxs("span",{className:"text-zinc-400 normal-case tracking-normal",children:[" ","· matching original"]})]}),e.jsxs("div",{className:"flex gap-1.5 items-center flex-wrap",children:[V&&e.jsx("button",{onClick:()=>G("auto"),title:"Match each text's original colour",className:`h-7 px-2.5 rounded-full border-2 text-[9px] font-black transition-all ${$==="auto"?"border-white text-white bg-zinc-700":"border-zinc-700 text-zinc-300 bg-zinc-800"}`,children:"Auto"}),Fe.map(s=>e.jsx("button",{onClick:()=>G(s.id),"aria-label":s.label,className:Ve($===s.id),style:{background:s.
11color}},s.id)),e.jsxs("label",{title:"Custom colour",className:`relative ${Ve($==="custom")} ${$==="custom"?"":"border-dashed"} cursor-pointer flex items-center justify-center`,style:{background:Y},children:[e.jsx("input",{type:"color",value:Y,onChange:s=>{ie(s.target.value),G("custom")},className:"absolute inset-0 opacity-0 cursor-pointer"}),e.jsx("span",{className:"text-white text-[11px] font-black drop-shadow",children:"+"})]})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:we,children:"Pen thickness"}),e.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Ae.map(s=>e.jsx("button",{onClick:()=>ut(s.id),className:me(q===s.id),children:s.label},s.id))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4 mt-4",children:[!V&&e.jsx(ve,{label:"Size",value:Ne,min:24,max:48,step:1,onChange:xt}),!V&&e.jsx(ve,{label:"Spacing",value:Me,min:1.5,max:2.8,step:.1,onChange:ft,fmt:s=>s.toFixed(1)}),e.jsx(ve,{label:"Slant",value:Pe,min:-10,max:6,step:1,onChange:gt,fmt:s=>`${s}°`}),e.jsx(ve,{label:"Messiness",value:Re,min:0,max:1,step:.05,onChange:pt,fmt:s=>`${Math.round(s*100)}%`})]}),V&&e.jsxs("div",{className:"text-[10px] text-zinc-500 mt-3 leading-relaxed flex items-start gap-1.5",children:[e.jsx(tt,{size:12,className:"text-emerald-400 mt-0.5 shrink-0"}),"Size & spacing follow the original document — handwriting is fit to each line so nothing shifts."]})]})]}),e.jsxs("aside",{className:"lg:sticky lg:top-4 flex flex-col gap-3",children:[e.jsxs("div",{className:be+" p-3",children:[e.jsxs("div",{className:"flex items-center justify-between px-1 mb-2",children:[e.jsxs("span",{className:"text-[11px] font-black text-zinc-300 uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-400 animate-pulse"}),"Live preview"]}),le>1&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:Pt,disabled:oe===0,"aria-label":"Previous page",className:"w-6 h-6 rounded-md bg-zinc-800 border border-zinc-700 text-zinc-300 text-sm leading-none flex items-center justify-center disabled:opacity-30 hover:bg-zinc-700 transition-colors",children:"‹"}),e.jsxs("span",{className:"text-[10px] text-zinc-400 tabular-nums w-14 text-center",children:[oe+1," / ",le]}),e.jsx("button",{onClick:Rt,disabled:oe>=le-1,"aria-label":"Next page",className:"w-6 h-6 rounded-md bg-zinc-800 border border-zinc-700 text-zinc-300 text-sm leading-none flex items-center justify-center disabled:opacity-30 hover:bg-zinc-700 transition-colors",children:"›"})]}),le===1&&e.jsx("span",{className:"text-[10px] text-zinc-500",children:"1 page"})]}),e.jsx("div",{className:"rounded-xl bg-zinc-950 border border-zinc-800/80 flex items-center justify-center min-h-[360px] p-4",children:Oe?e.jsx("img",{src:Oe,alt:"handwritten preview",className:"max-w-full max-h-[560px] w-auto rounded-md ring-1 ring-black/30 shadow-[0_24px_60px_-15px_rgba(0,0,0,0.75)]"}):e.jsxs("div",{className:"text-zinc-600 text-xs flex flex-col items-center gap-2.5 py-14 text-center px-6",children:[xe?e.jsx(je,{size:20,className:"text-zinc-400"}):e.jsx(et,{size:22,className:"text-zinc-700"}),xe?He||"Working…":"Add a PDF or some text to see your handwriting appear here"]})})]}),e.jsx("button",{onClick:Ct,disabled:!Nt,className:"w-full flex items-center justify-center gap-2 py-4 rounded-2xl font-black text-sm text-zinc-900 bg-zinc-100 enabled:hover:bg-white disabled:opacity-40 disabled:cursor-not-allowed transition-all active:scale-[0.99]",children:xe?e.jsxs(e.Fragment,{children:[e.jsx(je,{size:16})," ",He||"Working…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Lt,{size:16})," Download Handwritten PDF"]})}),e.jsx("div",{className:"text-[10px] text-zinc-600 text-center flex items-center justify-center gap-1.5",children:r?e.jsxs(e.Fragment,{children:[e.jsx(nt,{size:11,className:"text-emerald-500/70"})," PDF · no watermark · never uploaded"]}):e.jsxs(e.Fragment,{children:[e.jsx(je,{size:11})," Loading libraries…"]})})]})]})]})}function ve({label:t,value:n,min:r,max:i,step:l,onChange:u,fmt:c}){return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-[10px] text-zinc-500 mb-1.5",children:[e.jsx("span",{className:"font-medium",children:t}),e.jsx("span",{className:"text-zinc-300 tabular-nums",children:c?c(n):n})]}),e.jsx("input",{type:"range",min:r,max:i,step:l,value:n,onChange:a=>u(parseFloat(a.target.value)),className:"w-full",style:{accentColor:"#e4e4e7"}})]})}export{hn 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.