PageSourceSearch

https://kerneltools.dev/assets/PdfEditor-DSTXFLls.js

js kerneltools.dev collected 2026-10-02 01:52:36 UTC 43,992 bytes, 1 lines download raw bytes

1import{u as Da,r as c,j as a}from"./index-j7I9Tmll.js";import{P as he,a as F,b as Lt,c as Ve,e as Ot,f as Wt,g as _t,h as Jt,i as Zt,S as it,d as Na,r as Re}from"./PDFButton-D40prZLX.js";import{getDocument as Sa,PasswordResponses as Ta,GlobalWorkerOptions as Ra}from"./pdf-TtSH7s3_.js";import{p as Ea}from"./pdf.worker.min-DT7iqwIP.js";import{h as qt,M as lt,b as ct,c as ut,d as pt,f as pe,m as Mt,e as Bt,u as Ia,t as $a,g as Ut,i as zt,s as Gt,p as Ht,S as Aa,j as La,k as Oa,l as Ma,n as Ba,r as Ua,o as za,q as Ga,v as Ha,w as dt,x as Ka,y as Wa,z as _a,A as Ja,B as Za,C as qa,D as Va}from"./pdfEditor-C_FHqbws.js";import{recognizePdfPageLocally as Ya}from"./ocr-C5xob1iL.js";import"./browser-cLhBeQPl.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";function ht(r){return r.slice()}async function Qa(r,i,{forceRebuild:d=!1,password:n=void 0}={}){const o=await he.load(ht(r),n===void 0?{}:{password:n});if(!d&&!qt(i))return{output:o,pages:o.getPages(),rebuilt:!1};const g=await he.create(),m=[];for(const l of i){if(l.blank){m.push(g.addPage([l.width,l.height]));continue}const[y]=await g.copyPages(o,[l.sourceIndex]);m.push(g.addPage(y))}return{output:g,pages:m,rebuilt:!0}}async function Xa(r,i){return en([r,i],{validate:!1})}async function en(r,{validate:i=!0,onProgress:d=()=>{}}={}){const n=await he.create();let o=0,g=0;for await(const m of r){o+=1,g+=m.byteLength;try{if(i){if(g>lt)throw new Error("Choose PDFs totaling no more than 100 MB.");for(const v of[ct(m),ut(m)])if(v.level==="reject")throw new Error(v.message)}const l=await he.load(ht(m));if(i){const v=pt({pageCount:l.getPageCount()});if(v.level==="reject")throw new Error(v.message);if(pt({pageCount:n.getPageCount()+l.getPageCount()}).level==="reject")throw new Error("The merged PDF would exceed the 250-page limit.");if(["Outlines","AcroForm","StructTreeRoot","Names","OCProperties"].some(p=>l.catalog.has(F.of(p)))||l.getPages().some(p=>{var P;return((P=p.node.Annots())==null?void 0:P.size())>0}))throw new Error("This PDF contains bookmarks, forms, annotations, links, tags, layers, or named resources that this merge tool cannot safely preserve. Use a plain PDF copy.")}(await n.copyPages(l,l.getPageIndices())).forEach(v=>n.addPage(v)),d(o)}catch(l){const y=/encrypted|password/i.test(l.message)?"Password-protected PDFs are not supported by Merge PDF.":l.message;throw new Error(`File ${o}: ${y}`)}}if(o<2)throw new Error("Choose at least two PDF files to merge.");return n.save()}function Vt(r){return r.catalog.has(F.of("Outlines"))}async function tn(r,i=void 0){const d=await he.load(ht(r),i==null?{}:{password:i});return Vt(d)}function an(r,i,d,n){const o=r.context.obj({Type:F.of("Annot"),Subtype:F.of("Link"),Rect:r.context.obj([n.x,n.y,n.x+n.width,n.y+n.height]),Border:r.context.obj([0,0,1]),Dest:r.context.obj([d.ref,F.of("Fit")])});i.node.addAnnot(r.context.register(o))}function nn(r,i,d,n){var p;if(!i.length)return{added:0,skipped:0,existing:!1};const o=new Map(n.map((P,S)=>[P.id,d[S]])),g=i.filter(P=>{var S;return((S=P.title)==null?void 0:S.trim())&&o.has(P.pageId)}),m=Vt(r);if(!g.length)return{added:0,skipped:i.length,existing:m};const l=m?r.catalog.get(F.of("Outlines")):r.context.register(r.context.obj({Type:F.of("Outlines"),Count:g.length})),y=r.context.lookup(l,Lt),v=g.map(P=>r.context.obj({Title:Ve.of(P.title.trim()),Parent:l,Dest:r.context.obj([o.get(P.pageId).ref,F.of("Fit")])})),h=v.map(P=>r.context.register(P));v.forEach((P,S)=>{S>0&&P.set(F.of("Prev"),h[S-1]),S<h.length-1&&P.set(F.of("Next"),h[S+1])});const T=y.get(F.of("Last"));if(T?(r.context.lookup(T,Lt).set(F.of("Next"),h[0]),v[0].set(F.of("Prev"),T)):y.set(F.of("First"),h[0]),y.set(F.of("Last"),h.at(-1)),m){const P=((p=r.context.lookupMaybe(y.get(F.of("Count")),Ot))==null?void 0:p.asNumber())||0;y.set(F.of("Count"),Ot.of(P+g.length))}else r.catalog.set(F.of("Outlines"),l);return{added:g.length,skipped:i.length-g.length,existing:m}}Ra.workerSrc=Ea;const sn=1.25,on=.22;function Yt(r){return r.slice(0)}async function rn(r){let i=!1,d=0,n=!1,o=null;const g=Sa({data:Yt(r)});g.onPassword=(m,l)=>{i=!0,d+=1;const y=l===Ta.INCORRECT_PASSWORD;if(d>3){n=!0,g.destroy();return}const v=window.prompt(y?"That password did not open this PDF. Enter the password again:":"Enter this PDF password to preview it:");if(v===null){n=!0,g.destroy();return}o=v,m(v)};try{return{preview:await g.promise,loadingTask:g,passwordProtected:i,password:o}}
1catch(m){if(n){const l=new Error("Password prompt cancelled");throw l.name="PasswordPromptCancelled",l}throw m}}async function dn(r,i){return(await he.load(Yt(r),i===null?{}:{password:i})).getForm().getFields().map(n=>{const o={name:n.getName(),value:""};return n instanceof Wt?{...o,type:"text",value:n.getText()||""}:n instanceof _t?{...o,type:"checkbox",value:n.isChecked()}:n instanceof Jt?{...o,type:"dropdown",value:n.getSelected()[0]||"",options:n.getOptions()}:n instanceof Zt?{...o,type:"radio",value:n.getSelected()||"",options:n.getOptions()}:{...o,type:"unsupported"}}).filter(n=>n.type!=="unsupported")}function ln(r,i){const d=r.getForm();d.getFields().forEach(n=>{const o=i[n.getName()];o!==void 0&&(n instanceof Wt&&n.setText(String(o)),n instanceof _t&&(o?n.check():n.uncheck()),n instanceof Jt&&o&&n.select(String(o)),n instanceof Zt&&o&&n.select(String(o)))}),d.updateFieldAppearances()}function cn(r,i,d){const n=r.getForm(),o={x:d.x,y:d.y,width:d.width,height:d.height};if(d.type==="checkbox"&&n.createCheckBox(d.name).addToPage(i,o),d.type==="dropdown"){const g=n.createDropdown(d.name);g.addOptions(d.options),g.addToPage(i,o)}if(d.type==="text"&&n.createTextField(d.name).addToPage(i,o),d.type==="radio"){const g=n.createRadioGroup(d.name);d.options.forEach((m,l)=>g.addOptionToPage(m,i,{x:d.x,y:d.y-l*(d.height+8),width:d.width,height:d.height}))}}function un(r,i,d){const{x:n,y:o,width:g,height:m,text:l,type:y}=d,v=[n,o,n+g,o+m],h={Type:F.of("Annot"),Rect:r.context.obj(v),F:4},T=y==="note"?r.context.obj({...h,Subtype:F.of("Text"),Contents:Ve.of(l),T:Ve.of("Kernel PDF Editor"),C:r.context.obj([.08,.35,.82])}):r.context.obj({...h,Subtype:F.of(y==="highlight"?"Highlight":"StrikeOut"),QuadPoints:r.context.obj([n,o+m,n+g,o+m,n,o,n+g,o]),C:r.context.obj(y==="highlight"?[1,.85,0]:[.85,.15,.15]),CA:.45}),p=r.context.register(T);i.node.addAnnot(p)}function pn(r,i,d){const n=r.context.obj({Type:F.of("Annot"),Subtype:F.of("Link"),Rect:r.context.obj([d.x,d.y,d.x+d.width,d.y+d.height]),Border:r.context.obj([0,0,1]),A:r.context.obj({Type:F.of("Action"),S:F.of("URI"),URI:Ve.of(d.url)})});i.node.addAnnot(r.context.register(n))}async function hn(r){const i=await createImageBitmap(r),d={width:i.width,height:i.height};return i.close(),d}async function gn(r,i){const n=await(await r.getPage(i+1)).getTextContent();return n.items.filter(o=>{var g,m,l;return((g=o.str)==null?void 0:g.trim())&&Math.abs(((m=o.transform)==null?void 0:m[1])||0)<.01&&Math.abs(((l=o.transform)==null?void 0:l[2])||0)<.01}).map((o,g)=>{var l,y;const m=Za((l=n.styles[o.fontName])==null?void 0:l.fontFamily,o.fontName);return{id:`${i}-${g}-${o.transform[4]}-${o.transform[5]}`,sourceIndex:i,text:o.str,x:o.transform[4],y:o.transform[5],width:Math.max(1,o.width),height:Math.max(6,Math.abs(o.transform[3])),sourceFont:((y=n.styles[o.fontName])==null?void 0:y.fontFamily)||o.fontName||"Unknown",fontKind:m.kind,fontLabel:m.label,fontExact:m.exact}})}function fn(r,i,d){let n=Math.max(6,i.height),o=[],g=0;for(;n>=6&&(g=n*1.2,o=Va(i.text,i.width,l=>d.widthOfTextAtSize(l,n)),!(o.length*g<=i.height+2));)n-=.5;n<6&&(n=6);const m=i.y+i.height-n;o.forEach((l,y)=>{const v=d.widthOfTextAtSize(l,n),h=i.align==="center"?i.x+(i.width-v)/2:i.align==="right"?i.x+i.width-v:i.x;r.drawText(l,{x:h,y:m-y*g,size:n,font:d,color:Re(0,0,0)})})}function Kt({document:r,pageIndex:i,rotation:d=0,scale:n,className:o,onClick:g,onViewport:m,blankSize:l}){const y=c.useRef(null),[v,h]=c.useState(null);return c.useEffect(()=>{let T=!1,p;async function P(){if(!y.current)return;if(l){const[V,Y]=l,z=y.current,Z={width:V*n,height:Y*n},L=z.getContext("2d",{alpha:!1});z.width=Math.ceil(Z.width),z.height=Math.ceil(Z.height),L.fillStyle="#ffffff",L.fillRect(0,0,z.width,z.height),L.strokeStyle="#d9e2ef",L.lineWidth=Math.max(1,n),L.strokeRect(0,0,z.width,z.height),T||(h(Z),m==null||m(Z));return}if(!r)return;const S=await r.getPage(i+1),_=S.getViewport({scale:n,rotation:(S.rotate+d)%360}),J=y.current,Ee=J.getContext("2d",{alpha:!1});J.width=Math.ceil(_.width),J.height=Math.ceil(_.height),T||(h(_),m==null||m(_)),p=S.render({canvasContext:Ee,viewport:_}),await p.promise}return P().catch(()=>{}),()=>{T=!0,p==null||p.cancel()}},[l==null?void 0:l[0],l==null?void 0:l[1],r,m,i,d,n]),a.jsx("canvas",{ref:y,className:o,onClick:T=>g==null?void 0:g(T,y.current,v)})}function kn(){Da({title:"Online PDF Editor: Forms, Pages & Notes | Kernel DevTools",description:"Reorder PDF pages, fill forms, add notes and images, and download your edited document. Kernel PDF Editor processes files in your browser.",structuredData:{"@context":"https://schema.org","@type":"WebApplication",name:"Kernel PDF Editor",applicationCategory:"UtilitiesApplication",operatingSystem:"Web",url:"https://kerneltools.dev/pdf-editor",description:"An in-browser PDF workspace for page operations, forms, annotations, and image overlays."}});const r=c.useRef(null),i=c.useRef(null),d=c.useRef(null),n=c.useRef(new Set),o=c.useRef(0),[g,m]=c.useState(null),[l,y]=c.useState(null),v=c.useRef(null),[h,T]=c.useState([]),[p,P]=c.useState(0),[S,_]=c.useState(""),[J,Ee]=c.useState(null),[V,Y]=c.useState(1),[z,Z]=c.useState(!1),[L,ae]=c.useState([]),[Ie,gt]=c.useState("Note"),[G,ft]=c.useState("note"),[ge,$e]=c.useState(!1),[Q,mt]=c.useState([]),[fe,Ae]=c.useState({}),[Ye,xt]=c.useState(0),[me,bt]=c.useState(!1),[ne,se]=c.useState([]),[X,wt]=c.useState("text"),[xe,yt]=c.useState("field"),[vt,Pt]=c.useState(""),[be,Le]=c.useState(!1),[we,oe]=c.useState([]),[Oe,Qe]=c.useState("external"),[Me,Xe]=c.useState("https://"),[Be,et]=c.useState(""),[ye,Ue]=c.useState(!1),[ze,re]=c.useState([]),[Ge,He]=c.useState(""),[O,ee]=c.useState([]),[I,te]=c.useState(null),[Ke,ve]=c.useState([]),[Pe,tt]=c.useState(""),[We,_e]=c.useState(""),[jt,kt]=c.useState("#ffffff"),[Ft,Ct]=c.useState("left"),[Dt,Je]=c.useState(""),[ie,de]=c.useState([]),[le,Qt]=c.useState(null),[Nt,Xt]=c.useState({}),[H,Ze]=c.useState({header:"",footer:"",pageNumbers:!1}),[B,je]=c.useState({past:[],future:[]}
1),[C,St]=c.useState(null),[ea,s]=c.useState(""),[D,$]=c.useState(!1),[A,Tt]=c.useState(!1),[ke,Rt]=c.useState(null),j=sn*V;c.useEffect(()=>()=>{var e;return(e=v.current)==null?void 0:e.destroy()},[]),c.useEffect(()=>()=>n.current.forEach(e=>URL.revokeObjectURL(e)),[]),c.useEffect(()=>{let e=!1;if(!(!l||!h[p])){if(h[p].blank){ve([]);return}return gn(l,h[p].sourceIndex).then(t=>{e||(ve(t.map(u=>({...u,pageId:h[p].id}))),tt(""),_e(""),Je(""))}).catch(()=>{e||ve([])}),()=>{e=!0}}},[l,h,p]);function at(){return{pages:h,annotations:L,formValues:fe,createdFormFields:ne,images:O,selectedImageId:I,textReplacements:ie,links:we,bookmarks:ze,documentLayout:H}}function Et(e){T(e.pages),ae(e.annotations),Ae(e.formValues),se(e.createdFormFields),ee(e.images),te(e.selectedImageId),de(e.textReplacements),oe(e.links),re(e.bookmarks||[]),Ze(e.documentLayout||{header:"",footer:"",pageNumbers:!1}),P(Math.min(p,Math.max(0,e.pages.length-1)))}function R(){je(e=>({past:Ut(e.past,at()),future:[]}))}function It(){const e=B.past.at(-1);if(!e)return;const t=at();Et(e),je({past:B.past.slice(0,-1),future:[t,...B.future]}),s("Undid edit.")}function $t(){const e=B.future[0];if(!e)return;const t=at();Et(e),je({past:Ut(B.past,t),future:B.future.slice(1)}),s("Redid edit.")}c.useEffect(()=>{function e(t){!(t.ctrlKey||t.metaKey)||t.key.toLowerCase()!=="z"||(t.preventDefault(),t.shiftKey?$t():It())}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)});async function nt(e,{skipDiscard:t=!1}={}){var f;if(!e)return;if(!zt(e)){s("Choose a PDF file.");return}if(!t&&Gt(!!l,B.past.length)&&!window.confirm("Opening another PDF will discard edits that have not been downloaded. Continue?")){s("Kept current PDF and edits.");return}const u=Ht(e.size);if(u==="reject"){s(`This PDF is ${pe(e.size)}. PDFs over ${pe(lt)} are not opened.`);return}if(u==="confirm"&&!window.confirm(`This ${pe(e.size)} PDF may take time and memory to open in this browser. Continue?`)){s("Large PDF was not opened.");return}$(!0),s("Opening PDF…");try{const k=new Uint8Array(await e.arrayBuffer()),N=ct(k);if(N.level==="reject"){s(N.message);return}const E=ut(k);if(E.level==="reject"){s(E.message);return}const W=await rn(k),{preview:w,loadingTask:U,passwordProtected:rt,password:Ne}=W,b=await Promise.all(Array.from({length:Math.min(w.numPages,Aa)},(q,Se)=>w.getPage(Se+1).then(Te=>Te.getTextContent()).then(Te=>Te.items.filter(Ca=>{var At;return(At=Ca.str)==null?void 0:At.trim()}).length))),M=pt({pageCount:w.numPages,sampledTextItemCounts:b});if(M.level==="reject"){U.destroy(),s(M.message);return}const ue=await tn(k,Ne).catch(()=>!0);(f=v.current)==null||f.destroy(),v.current=U,m(k),Rt(Ne),y(w),Tt(!1),T(La(w.numPages));const qe=await dn(k,Ne).catch(()=>[]),Fa=await Promise.all(Array.from({length:w.numPages},(q,Se)=>w.getPage(Se+1).then(Te=>Te.getAnnotations())));n.current.forEach(q=>URL.revokeObjectURL(q)),n.current.clear(),P(0),_(e.name),Ee({bytes:e.size,pages:w.numPages}),Y(1),ae([]),ee([]),te(null),ve([]),de([]),se([]),oe([]),Qe("external"),Xe("https://"),et(""),Ue(!1),re([]),He(""),Ze({header:"",footer:"",pageNumbers:!1}),je({past:[],future:[]}),$e(!1),Le(!1),mt(qe),Ae(Object.fromEntries(qe.map(q=>[q.name,q.value]))),xt(Fa.reduce((q,Se)=>q+Se.length,0)),bt(ue),s(rt?`${w.numPages} page${w.numPages===1?"":"s"} ready — the password stays only in this tab and the downloaded edit is re-encrypted with it.`:`${w.numPages} page${w.numPages===1?"":"s"} ready — edits stay in this browser.${ue?" Existing bookmarks are preserved; page rearrangement, extraction, splitting, and merging are unavailable.":""}${M.level==="warn"?` ${M.message}`:""}`)}catch(k){s(Oa(k))}finally{$(!1)}}function ta(){var e;Gt(!!l,B.past.length)&&!window.confirm("Close this PDF and discard edits that have not been downloaded?")||((e=v.current)==null||e.destroy(),v.current=null,n.current.forEach(t=>URL.revokeObjectURL(t)),n.current.clear(),m(null),Rt(null),y(null),Tt(!1),T([]),P(0),_(""),Ee(null),Y(1),ae([]),gt("Note"),ft("note"),$e(!1),mt([]),Ae({}),xt(0),bt(!1),se([]),wt("text"),yt("field"),Pt(""),Le(!1),oe([]),Qe("external"),Xe("https://"),et(""),Ue(!1),re([]),He(""),ee([]),te(null),ve([]),tt(""),_e(""),kt("#ffffff"),Ct("left"),Je(""),de([]),Ze({header:"",footer:"",pageNumbers:!1}),je({past:[],future:[]}
1),St(null),s("PDF closed. Drop or choose another PDF to begin."))}function aa(e){var t;(t=e.dataTransfer)!=null&&t.types.includes("Files")&&(e.preventDefault(),o.current+=1,Z(!0))}function na(e){var t;(t=e.dataTransfer)!=null&&t.types.includes("Files")&&(e.preventDefault(),e.dataTransfer.dropEffect="copy")}function sa(e){var t;(t=e.dataTransfer)!=null&&t.types.includes("Files")&&(e.preventDefault(),o.current=Math.max(0,o.current-1),o.current||Z(!1))}function oa(e){var t,u;(t=e.dataTransfer)!=null&&t.types.includes("Files")&&(e.preventDefault(),o.current=0,Z(!1),D||nt((u=e.dataTransfer.files)==null?void 0:u[0]))}function ra(e){var t;e.key!=="Enter"&&e.key!==" "||(e.preventDefault(),D||(t=r.current)==null||t.click())}function Fe(e,t=p,u=!0){if(A){s("This password-protected PDF is open for preview only. Editing and export are disabled.");return}u&&R(),T(e),P(Math.max(0,Math.min(t,e.length-1)))}function ia(){if(A){s("This password-protected PDF is open for preview only. Editing and export are disabled.");return}if(h.length<=1){s("A PDF must keep at least one page.");return}const e=h[p];R(),Fe(h.filter((t,u)=>u!==p),p,!1),ae(L.filter(t=>t.pageId!==e.id)),se(ne.filter(t=>t.pageId!==e.id)),ee(O.filter(t=>t.pageId!==e.id)),de(ie.filter(t=>t.pageId!==e.id)),oe(we.filter(t=>t.pageId!==e.id)),re(ze.filter(t=>t.pageId!==e.id)),s("Page removed from this export.")}function da(){const e=Ma(C,j),t=Ba(e.width,e.height),u=[...h.slice(0,p+1),t,...h.slice(p+1)];Fe(u,p+1),s("Blank page added after the current page.")}function la(){Fe(Ua(h,p)),s("Page rotated 90° clockwise.")}async function ca(e){if(A){s("This password-protected PDF is open for preview only. Editing and export are disabled.");return}if(!e)return;if(!(["image/jpeg","image/png"].includes(e.type)||/\.(jpe?g|png)$/i.test(e.name))){s("Choose a PNG or JPEG image.");return}if(!C||!x){s("Wait for the selected page preview, then add an image.");return}$(!0),s("Adding image…");try{const{width:u,height:f}=await hn(e),k=C.width/j,N=C.height/j,E=URL.createObjectURL(e);n.current.add(E);const W={id:crypto.randomUUID(),pageId:x.id,name:e.name,mimeType:e.type==="image/png"||/\.png$/i.test(e.name)?"image/png":"image/jpeg",bytes:new Uint8Array(await e.arrayBuffer()),url:E,...za(u,f,k,N)};R(),ee(w=>[...w,W]),te(W.id),s("Image added. Adjust its position or size before downloading.")}catch{s("This image could not be read. Choose a PNG or JPEG image.")}finally{$(!1)}}function ce(e){if(A){s("This password-protected PDF is open for preview only. Editing and export are disabled.");return}I&&(R(),ee(t=>Ga(t,I,e)))}function ua(){if(A){s("This password-protected PDF is open for preview only. Editing and export are disabled.");return}I&&(O.find(e=>e.id===I),R(),ee(e=>e.filter(t=>t.id!==I)),te(null),s("Image removed from this export."))}function pa(){if(A){s("This password-protected PDF is open for preview only. Editing and export are disabled.");return}const e=Ke.find(t=>t.id===Pe);!e||!We.trim()||(R(),de(t=>[...t,Ha(e,We.trim(),jt,{align:Ft,height:Number(Dt)||e.height})]),s("Visual text replacement added. The original PDF text remains underneath the cover."))}async function ha(){const e=h[p];if(!l||!e||e.blank){s("OCR is available only for an original PDF page.");return}$(!0),s("Preparing the selected page for OCR…");try{const t=await l.getPage(e.sourceIndex+1),u=await Ya(t,{rotation:(t.rotate+e.rotation)%360,onProgress:f=>s(`OCR: ${f}`)});Xt(f=>({...f,[e.id]:u})),s(u?"OCR complete. Review and copy the extracted text below.":"OCR completed, but no readable English text was detected on this page.")}catch(t){s(`OCR could not finish: ${(t==null?void 0:t.message)||"unknown error"}`)}finally{$(!1)}}function ga(e,t,u){if(A){s("This password-protected PDF is open for preview only. Editing and export are disabled.");return}if(be){xa(e,t,u);return}if(ye){fa(e,t,u);return}if(!ge||!t||!u||G==="note"&&!Ie.trim())return;const f=dt(e,t,u),k={x:f.x/j,y:f.y/j};R(),ae([...L,{id:crypto.randomUUID(),pageId:h[p].id,...Ka(G,k,Ie.trim())}]),$e(!1),s(`${G==="note"?"Text note":G==="highlight"?"Highlight":"Strikeout"} added. It will be saved as a PDF annotation.`)}function fa(e,t,u){if(A){s("This password-protected PDF is open for preview only. Editing and export are disabled.");return}const f=Oe==="internal";if(!t||!u||!f&&!Bt(Me)||f&&!h.some(E=>E.id===Be)){s(f?"Choose a destination page for this internal link.":"Links must start with https: or mailto:.");return}const k=dt(e,t,u),N={x:k.x/j,y:k.y/j};R(),oe(E=>[...E,{pageId:h[p].id,...f?Wa(N,Be):_a(N,Me.trim())}]),Ue(!1),s(`${f?"Internal page link":"External link"} added. It will be interactive in the downloaded PDF.`)}function ma(){if(A){s("This password-protected PDF is open for preview only. Editing and export are disabled.");return}!x||!Ge.trim()||(R(),re(e=>[...e,{id:crypto.randomUUID(),title:Ge.trim(),pageId:x.id}]),He(""),s("Bookmark added for this page. It will appear in compatible PDF viewers after download."))}function xa(e,t,u){if(A){s("This password-protected PDF is open for preview only. Editing and export are disabled.");return}if(!t||!u||!xe.trim())return;if(new Set([...Q.map(w=>w.name),...ne.map(w=>w.name)]).has(xe.trim())){s("Form field names must be unique.");return}const k=X==="dropdown"||X==="radio",N=k?vt.split(",").map(w=>
1w.trim()).filter(Boolean):[];if(k&&!N.length){s("Add at least one option.");return}const E=dt(e,t,u),W={x:E.x/j,y:E.y/j};R(),se(w=>[...w,{pageId:h[p].id,...Ja(X,W,xe.trim(),N)}]),Le(!1),s(`New ${X} field added. It will be interactive in the downloaded PDF.`)}function st(e,t){if(A){s("This password-protected PDF is open for preview only. Editing and export are disabled.");return}R(),Ae(u=>({...u,[e]:t}))}function ot(e){if(A){s("This password-protected PDF is open for preview only. Editing and export are disabled.");return}R(),Ze(t=>({...t,...e}))}async function Ce(e,{forceRebuild:t=!1}={}){const u=t||qt(e);if(u&&Q.length)throw new Error("form-structure");if(u&&me)throw new Error("outline-structure");const{output:f,pages:k}=await Qa(g,e,{forceRebuild:t,password:ke===null?void 0:ke});u||ln(f,fe);const N={sans:await f.embedFont(it.Helvetica),serif:await f.embedFont(it.TimesRoman),mono:await f.embedFont(it.Courier)};for(const[W,w]of k.entries()){const U=e[W];U.rotation&&w.setRotation(Na((w.getRotation().angle+U.rotation)%360)),L.filter(b=>b.pageId===U.id).forEach(b=>un(f,w,b)),we.filter(b=>b.pageId===U.id).forEach(b=>{if(b.targetPageId){const M=e.findIndex(ue=>ue.id===b.targetPageId);M>=0&&an(f,w,k[M],b)}else pn(f,w,b)}),ie.filter(b=>b.pageId===U.id).forEach(b=>{const[M,ue,qe]=qa(b.background);w.drawRectangle({x:b.x-1,y:b.y-2,width:b.width+2,height:b.height+4,color:Re(M,ue,qe)}),fn(w,b,N[b.fontKind])}),ne.filter(b=>b.pageId===U.id).forEach(b=>cn(f,w,b));for(const b of O.filter(M=>M.pageId===U.id)){const M=b.mimeType==="image/png"?await f.embedPng(b.bytes):await f.embedJpg(b.bytes);w.drawImage(M,{x:b.x,y:b.y,width:b.width,height:b.height})}const{width:rt,height:Ne}=w.getSize();if(H.header.trim()&&w.drawText(H.header.trim(),{x:36,y:Ne-24,size:9,font:N.sans,color:Re(.2,.25,.32)}),H.footer.trim()&&w.drawText(H.footer.trim(),{x:36,y:16,size:9,font:N.sans,color:Re(.2,.25,.32)}),H.pageNumbers){const b=`${W+1} / ${k.length}`;w.drawText(b,{x:rt-36-N.sans.widthOfTextAtSize(b,9),y:16,size:9,font:N.sans,color:Re(.2,.25,.32)})}}const E=nn(f,ze,k,e);return E.existing&&E.added&&s("Downloaded PDF preserves its existing bookmark hierarchy and appends your new first-level bookmarks."),ke!==null&&f.encrypt({userPassword:ke,ownerPassword:ke}),f.save()}function De(e,t){const u=URL.createObjectURL(new Blob([e],{type:"application/pdf"})),f=document.createElement("a");f.href=u,f.download=`${S.replace(/\.pdf$/i,"")}-${t}.pdf`,f.click(),URL.revokeObjectURL(u)}async function ba(){if(!(!g||D)){$(!0),s("Preparing download…");try{const e=await Ce(h);De(e,"edited"),s("Downloaded your edited PDF.")}catch(e){s((e==null?void 0:e.message)==="form-structure"?"PDFs with existing form fields must keep their original page order and rotation. Download form edits before changing pages.":(e==null?void 0:e.message)==="outline-structure"?"PDFs with existing bookmark hierarchies must keep their original page order. This preserves their bookmarks.":"Could not export this PDF. Encrypted or unusually structured files are not supported yet.")}finally{$(!1)}}}async function wa(){const e=ie.map(t=>({oldText:t.sourceText,newText:t.text,expectedCount:1}));if(!g||!e.length||e.some(t=>!/^[\x20-\x7e]+$/.test(t.oldText)||!/^[\x20-\x7e]+$/.test(t.newText)||/[()\\]/.test(t.oldText+t.newText)||t.newText.length>t.oldText.length)){s("Strict source edits require printable ASCII replacements no longer than the original selected text.");return}$(!0),s("Submitting protected source-text job…");try{const t=new FormData;t.set("operation","content-edit"),t.set("textEdits",JSON.stringify(e)),t.set("file",new Blob([g],{type:"application/pdf"}),S||"document.pdf");const u=await fetch("/api/pdf-jobs",{method:"POST",body:t}),f=await u.json();if(!u.ok)throw new Error(f.error||"Submission failed");Qt({id:f.id,accessToken:f.accessToken}),s("Protected source-text job queued. Check result status below; it expires in 24 hours.")}catch(t){s(t instanceof Error?t.message:"Could not queue source-text job.")}finally{$(!1)}}async function ya(){if(!le)return;const e=await fetch(`/api/pdf-jobs/${le.id}`,{headers:{Authorization:`Bearer ${le.accessToken}`}}),t=await e.json();if(!e.ok){s("Source-text job is unavailable or expired.");return}if(t.job.status==="succeeded"){const u=await fetch(`/api/pdf-jobs/${le.
1id}/download`,{headers:{Authorization:`Bearer ${le.accessToken}`}});if(!u.ok){s("Processed PDF is not available yet.");return}De(new Uint8Array(await u.arrayBuffer()),"source-edited"),s("Downloaded source-edited PDF.")}else s(`Source-text job: ${t.job.status}${t.job.detail?` — ${t.job.detail}`:""}`)}async function va(){if(!(!g||D)){$(!0),s("Preparing selected page…");try{const e=await Ce([h[p]],{forceRebuild:!0});De(e,`page-${p+1}`),s(`Downloaded page ${p+1}.`)}catch(e){s((e==null?void 0:e.message)==="form-structure"?"Existing PDF form fields cannot be safely extracted yet. Download the full edited PDF instead.":(e==null?void 0:e.message)==="outline-structure"?"Existing PDF bookmark hierarchies cannot be safely extracted yet. Download the full edited PDF instead.":"Could not extract this page from the PDF.")}finally{$(!1)}}}async function Pa(){if(!(!g||D||p===h.length-1)){$(!0),s("Preparing split PDFs…");try{const e=await Ce(h.slice(0,p+1),{forceRebuild:!0}),t=await Ce(h.slice(p+1),{forceRebuild:!0});De(e,`pages-1-${p+1}`),De(t,`pages-${p+2}-${h.length}`),s("Downloaded two PDF parts.")}catch(e){s((e==null?void 0:e.message)==="form-structure"?"Existing PDF form fields cannot be safely split yet. Download the full edited PDF instead.":(e==null?void 0:e.message)==="outline-structure"?"Existing PDF bookmark hierarchies cannot be safely split yet. Download the full edited PDF instead.":"Could not split this PDF.")}finally{$(!1)}}}async function ja(e){if(!e||!g||D)return;if(!zt(e)){s("Choose a PDF file to merge.");return}const t=Ht(e.size);if(t==="reject"){s(`PDFs over ${pe(lt)} are not merged.`);return}if(t==="confirm"&&!window.confirm(`This ${pe(e.size)} PDF may take time and memory to merge in this browser. Continue?`)){s("Large PDF was not merged.");return}if(Q.length){s("PDFs with existing form fields cannot be safely merged yet. Download form edits before merging.");return}if(me){s("PDFs with existing bookmark hierarchies cannot be safely merged yet. Download form edits before merging.");return}$(!0),s("Merging PDFs…");try{const u=await Ce(h),f=new Uint8Array(await e.arrayBuffer()),k=ct(f);if(k.level==="reject"){s(k.message);return}const N=ut(f);if(N.level==="reject"){s(N.message);return}const E=await Xa(u,f);await nt(new File([E],`${S.replace(/\.pdf$/i,"")}-merged.pdf`,{type:"application/pdf"}),{skipDiscard:!0}),s("PDF merged. Review the combined pages before downloading.")}catch{s("Could not merge these PDFs. Encrypted or unusually structured files are not supported yet.")}finally{$(!1)}}const x=h[p],K=!!(Q.length||me||A),ka=A?"This password-protected PDF is available for preview only. Editing and export are disabled because encryption cannot be safely preserved.":me?"This PDF has an existing bookmark hierarchy. Page rearrangement, rotation, insertion, removal, extraction, splitting, and merging stay unavailable so the hierarchy is preserved.":Q.length?"This PDF has existing form fields. Page rearrangement, rotation, insertion, removal, extraction, splitting, and merging stay unavailable so form widgets are preserved.":"";return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"page-hero pdf-editor-hero",children:a.jsxs("div",{className:"page-hero-inner",children:[a.jsx("div",{className:"section-eyebrow",children:"In-browser workspace"}),a.jsx("h1",{children:"PDF Editor"}),a.jsx("p",{children:"Organize pages, fill existing form fields, add annotations and images, and make visual text replacements without uploading your document. Password-protected files can be previewed in your browser; editing stays disabled until their encryption can be safely preserved."})]})}),a.jsxs("div",{className:"pdf-editor","aria-busy":D,"aria-describedby":l?"pdf-editor-status":void 0,children:[l?a.jsxs("section",{className:"pdf-workspace",children:[a.jsxs("aside",{className:"pdf-thumbnails","aria-label":"PDF pages",children:[a.jsxs("div",{className:"pdf-sidebar-head",children:[a.jsx("strong",{children:"Pages"}),a.jsx("span",{children:h.length})]}),h.map((e,t)=>a.jsxs("button",{className:`pdf-thumbnail${t===p?" is-selected":""}`,onClick:()=>P(t),"aria-current":t===p?"page":void 0,"aria-label":`Select page ${t+1}
1${t===p?", current page":""}`,children:[a.jsx(Kt,{document:l,pageIndex:e.sourceIndex,rotation:e.rotation,scale:on,blankSize:e.blank?[e.width,e.height]:null,className:"pdf-thumbnail-canvas"}),a.jsxs("span",{children:["Page ",t+1]})]},e.id))]}),a.jsxs("div",{className:"pdf-stage",children:[a.jsxs("div",{className:"pdf-stage-bar",children:[a.jsx("span",{className:"pdf-file-name",children:S}),a.jsx("span",{children:J&&`${pe(J.bytes)} · ${J.pages} page${J.pages===1?"":"s"}`}),B.past.length>0&&a.jsx("span",{className:"pdf-unsaved-status",children:"Edits not downloaded"}),a.jsxs("span",{"aria-live":"polite","aria-atomic":"true",children:["Page ",p+1," of ",h.length]}),a.jsxs("span",{className:"pdf-page-navigation",role:"group","aria-label":"Page navigation",children:[a.jsx("button",{onClick:()=>P(e=>Math.max(0,e-1)),disabled:p===0,"aria-label":"Previous page",children:"Previous"}),a.jsx("button",{onClick:()=>P(e=>Math.min(h.length-1,e+1)),disabled:p===h.length-1,"aria-label":"Next page",children:"Next"})]}),a.jsxs("span",{className:"pdf-stage-actions",role:"group","aria-label":"Document and preview controls",children:[a.jsx("button",{onClick:()=>Y(e=>Math.max(.5,e-.25)),disabled:V<=.5,"aria-label":"Zoom out",children:"−"}),a.jsxs("span",{"aria-live":"polite",children:["Preview zoom ",Math.round(V*100),"%"]}),a.jsx("button",{onClick:()=>Y(e=>Math.min(2,e+.25)),disabled:V>=2,"aria-label":"Zoom in",children:"+"}),a.jsx("button",{onClick:()=>Y(1),disabled:V===1,"aria-label":"Reset preview zoom to 100%",children:"Fit"}),a.jsx("button",{onClick:()=>{var e;return(e=r.current)==null?void 0:e.click()},disabled:D,children:"Open another PDF"}),a.jsx("button",{onClick:ta,disabled:D,children:"Close PDF"}),a.jsxs("span",{className:"pdf-history-controls",role:"group","aria-label":"Edit history",children:[a.jsx("button",{onClick:It,disabled:!B.past.length,"aria-label":"Undo, Control or Command Z",children:"Undo · Ctrl/⌘Z"}),a.jsx("button",{onClick:$t,disabled:!B.future.length,"aria-label":"Redo, Control or Command Shift Z",children:"Redo · Ctrl/⌘⇧Z"})]})]})]}),a.jsx("div",{className:`pdf-page-wrap${ge||be||ye?" is-adding-note":""}`,children:x&&a.jsxs("div",{className:"pdf-page-layer",children:[a.jsx(Kt,{document:l,pageIndex:x.sourceIndex,rotation:x.rotation,scale:j,blankSize:x.blank?[x.width,x.height]:null,className:"pdf-page-canvas",onClick:ga,onViewport:St}),C&&L.filter(e=>e.pageId===x.id).map(e=>a.jsx("span",{className:`pdf-annotation-preview pdf-annotation-${e.type}`,style:{left:`${e.x/(C.width/j)*100}%`,bottom:`${e.y/(C.height/j)*100}%`,width:`${e.width/(C.width/j)*100}%`,height:`${e.height/(C.height/j)*100}%`},children:e.type==="note"?"●":""},e.id)),C&&ne.filter(e=>e.pageId===x.id).map(e=>a.jsx("span",{className:`pdf-form-preview pdf-form-preview-${e.type}`,style:{left:`${e.x/(C.width/j)*100}%`,bottom:`${e.y/(C.height/j)*100}%`,width:`${e.width/(C.width/j)*100}%`,height:`${e.height/(C.height/j)*100}%`},children:e.type==="checkbox"?"✓":e.type==="radio"?"◉":e.name},e.id)),C&&we.filter(e=>e.pageId===x.id).map(e=>a.jsx("span",{className:"pdf-link-preview",style:{left:`${e.x/(C.width/j)*100}%`,bottom:`${e.y/(C.height/j)*100}%`,width:`${e.width/(C.width/j)*100}%`,height:`${e.height/(C.height/j)*100}%`},children:e.targetPageId?"↪ Page link":"↗ Link"},e.id)),C&&O.filter(e=>e.pageId===x.id).map(e=>a.jsx("button",{className:`pdf-image-preview${e.id===I?" is-selected":""}`,onClick:()=>te(e.id),style:{left:`${e.x/(C.width/j)*100}%`,bottom:`${e.y/(C.height/j)*100}%`,width:`${e.width/(C.width/j)*100}%`,height:`${e.height/(C.height/j)*100}%`},"aria-label":`Select ${e.name}`,children:a.jsx("img",{src:e.url,alt:""})},e.id))]})})]}),a.jsxs("aside",{className:"pdf-properties",children:[a.jsx("h2",{children:"Page tools"}),K&&a.jsx("p",{className:"pdf-existing-annotations",role:"note",children:ka}),a.jsx("button",{className:"btn btn-ghost",onClick:()=>Fe(Mt(h,p,p-1),p-1),disabled:K||p===0,children:"Move earlier"}),a.jsx("button",{className:"btn btn-ghost",onClick:()=>Fe(Mt(h,p,p+1),p+1),disabled:K||p===h.length-1,children:"Move later"}),a.jsx("button",{className:"btn btn-ghost",onClick:da,disabled:K,children:"Add blank page"}),a.jsx("button",{className:"btn btn-ghost",onClick:la,disabled:K,children:"Rotate 90°"}),a.jsx("button",{className:"btn btn-ghost pdf-danger",onClick:ia,disabled:K,children:"Remove page"}),a.jsx("button",{className:"btn btn-ghost",onClick:va,disabled:D||K,children:"Extract this page"}),a.jsx("button",{className:"btn btn-ghost",onClick:Pa,disabled:D||K||p===h.length-1,children:"Split after this page"}),a.jsx("button",{className:"btn btn-ghost",onClick:()=>{var e;return(e=i.current)==null?void 0:e.click()},disabled:D||K,children:"Merge another PDF"}
1),a.jsxs("fieldset",{className:"pdf-edit-controls",disabled:A,children:[a.jsxs("div",{className:"pdf-note-controls",children:[a.jsx("h2",{children:"Annotations"}),a.jsxs("select",{"aria-label":"Annotation type",value:G,onChange:e=>ft(e.target.value),children:[a.jsx("option",{value:"note",children:"Comment note"}),a.jsx("option",{value:"highlight",children:"Highlight"}),a.jsx("option",{value:"strikeout",children:"Strikeout"})]}),G==="note"&&a.jsx("input",{"aria-label":"Comment note",value:Ie,maxLength:250,onChange:e=>gt(e.target.value)}),a.jsx("button",{className:`btn ${ge?"btn-primary":"btn-ghost"}`,onClick:()=>$e(e=>!e),disabled:G==="note"&&!Ie.trim(),"aria-pressed":ge,children:ge?"Click the page…":`Add ${G==="note"?"note":G}`}),L.filter(e=>e.pageId===(x==null?void 0:x.id)).map(e=>a.jsxs("button",{className:"pdf-annotation-remove",onClick:()=>{R(),ae(L.filter(t=>t.id!==e.id))},children:["Remove ",e.type]},e.id)),Ye>0&&a.jsxs("p",{className:"pdf-existing-annotations",children:[Ye," existing annotation",Ye===1?"":"s"," preserved."]})]}),Q.length>0&&a.jsxs("div",{className:"pdf-form-controls",children:[a.jsx("h2",{children:"Existing form fields"}),Q.map(e=>a.jsxs("label",{children:[e.name,e.type==="checkbox"?a.jsx("input",{type:"checkbox",checked:!!fe[e.name],onChange:t=>st(e.name,t.target.checked)}):e.type==="dropdown"||e.type==="radio"?a.jsxs("select",{value:fe[e.name]||"",onChange:t=>st(e.name,t.target.value),children:[a.jsx("option",{value:"",children:"Choose…"}),e.options.map(t=>a.jsx("option",{value:t,children:t},t))]}):a.jsx("input",{value:fe[e.name]||"",onChange:t=>st(e.name,t.target.value)})]},e.name))]}),a.jsxs("div",{className:"pdf-create-form-controls",children:[a.jsx("h2",{children:"Create form field"}),a.jsxs("select",{"aria-label":"New form field type",value:X,onChange:e=>wt(e.target.value),children:[a.jsx("option",{value:"text",children:"Text field"}),a.jsx("option",{value:"checkbox",children:"Checkbox"}),a.jsx("option",{value:"dropdown",children:"Dropdown"}),a.jsx("option",{value:"radio",children:"Radio group"})]}),a.jsx("input",{"aria-label":"New form field name",value:xe,maxLength:80,onChange:e=>yt(e.target.value)}),(X==="dropdown"||X==="radio")&&a.jsx("input",{"aria-label":"Form field options",value:vt,placeholder:"Option A, Option B",onChange:e=>Pt(e.target.value)}),a.jsx("button",{className:`btn ${be?"btn-primary":"btn-ghost"}`,onClick:()=>Le(e=>!e),disabled:!xe.trim(),"aria-pressed":be,children:be?"Click the page…":"Place field"}),ne.filter(e=>e.pageId===(x==null?void 0:x.id)).map(e=>a.jsxs("button",{className:"pdf-annotation-remove",onClick:()=>{R(),se(t=>t.filter(u=>u.id!==e.id))},children:["Remove ",e.name]},e.id))]}),a.jsxs("div",{className:"pdf-link-controls",children:[a.jsx("h2",{children:"Hyperlinks"}),a.jsxs("select",{"aria-label":"Link destination type",value:Oe,onChange:e=>Qe(e.target.value),children:[a.jsx("option",{value:"external",children:"External URL"}),a.jsx("option",{value:"internal",children:"Another page"})]}),Oe==="external"?a.jsx("input",{"aria-label":"Link URL",value:Me,onChange:e=>Xe(e.target.value)}):a.jsxs("select",{"aria-label":"Internal link destination page",value:Be,onChange:e=>et(e.target.value),children:[a.jsx("option",{value:"",children:"Choose a page…"}),h.map((e,t)=>a.jsxs("option",{value:e.id,children:["Page ",t+1]},e.id))]}),a.jsx("button",{className:`btn ${ye?"btn-primary":"btn-ghost"}`,onClick:()=>Ue(e=>!e),disabled:Oe==="external"?!Bt(Me):!Be,"aria-pressed":ye,children:ye?"Click the page…":"Place link"}),we.filter(e=>e.pageId===(x==null?void 0:x.id)).map(e=>a.jsxs("button",{className:"pdf-annotation-remove",onClick:()=>{R(),oe(t=>t.filter(u=>u.id!==e.id))},children:["Remove ",e.targetPageId?`link to ${h.findIndex(t=>t.id===e.targetPageId)+1>0?`page ${h.findIndex(t=>t.id===e.targetPageId)+1}`:"removed page"}`:e.url]},e.id))]}),a.jsxs("div",{className:"pdf-link-controls",children:[a.jsx("h2",{children:"Bookmarks"}),a.jsx("p",{id:"pdf-bookmark-help",className:"pdf-existing-annotations",children:me?"This PDF has an existing bookmark hierarchy. It is preserved; new first-level bookmarks are appended without changing existing entries.":"Add a first-level bookmark for the current page."}),a.jsx("input",{"aria-label":"Bookmark title","aria-describedby":"pdf-bookmark-help",value:Ge,maxLength:160,placeholder:"Bookmark title",onCh
1ange:e=>He(e.target.value)}),a.jsx("button",{className:"btn btn-ghost",onClick:ma,disabled:!Ge.trim(),children:"Bookmark current page"}),ze.map(e=>a.jsxs("button",{className:"pdf-annotation-remove",onClick:()=>{R(),re(t=>t.filter(u=>u.id!==e.id))},children:["Remove “",e.title,"”"]},e.id))]}),a.jsxs("div",{className:"pdf-link-controls",children:[a.jsx("h2",{children:"Document layout"}),a.jsx("input",{"aria-label":"Header text",value:H.header,maxLength:160,placeholder:"Header text",onChange:e=>ot({header:e.target.value})}),a.jsx("input",{"aria-label":"Footer text",value:H.footer,maxLength:160,placeholder:"Footer text",onChange:e=>ot({footer:e.target.value})}),a.jsxs("label",{className:"pdf-replacement-option",children:[a.jsx("input",{type:"checkbox",checked:H.pageNumbers,onChange:e=>ot({pageNumbers:e.target.checked})})," Add page numbers on export"]})]}),a.jsxs("div",{className:"pdf-text-controls",children:[a.jsx("h2",{children:"Visual text replacement"}),a.jsx("p",{children:"Uses a cover and Helvetica overlay; it does not rewrite the original text stream."}),a.jsxs("select",{"aria-label":"Detected text",value:Pe,onChange:e=>{const t=Ke.find(u=>u.id===e.target.value);tt(e.target.value),_e((t==null?void 0:t.text)||""),Je((t==null?void 0:t.height)||"")},children:[a.jsx("option",{value:"",children:"Choose detected text…"}),Ke.map(e=>a.jsx("option",{value:e.id,children:e.text.slice(0,80)},e.id))]}),Pe&&(()=>{const e=Ke.find(u=>u.id===Pe),t=e&&Ia(e.text);return e&&a.jsxs("p",{className:"pdf-font-status",children:["Source: ",e.sourceFont,". Export: ",e.fontLabel,e.fontExact?".":" fallback — visual match may differ."," ",t.characters," Unicode character",t.characters===1?"":"s","; ",t.nonAscii," non-ASCII. ",$a(e)]})})(),a.jsx("input",{"aria-label":"Replacement text",value:We,maxLength:500,onChange:e=>_e(e.target.value)}),a.jsxs("label",{className:"pdf-replacement-option",children:["Alignment ",a.jsxs("select",{"aria-label":"Text alignment",value:Ft,onChange:e=>Ct(e.target.value),children:[a.jsx("option",{value:"left",children:"Left"}),a.jsx("option",{value:"center",children:"Center"}),a.jsx("option",{value:"right",children:"Right"})]})]}),a.jsxs("label",{className:"pdf-replacement-option",children:["Cover height ",a.jsx("input",{"aria-label":"Cover height",type:"number",min:"6",value:Dt,onChange:e=>Je(e.target.value)})]}),a.jsxs("label",{className:"pdf-cover-color",children:["Cover color ",a.jsx("input",{"aria-label":"Cover color",type:"color",value:jt,onChange:e=>kt(e.target.value)})]}),a.jsx("button",{className:"btn btn-ghost",onClick:pa,disabled:!Pe||!We.trim(),children:"Add visual replacement"}),a.jsx("button",{className:"btn btn-ghost",onClick:wa,disabled:!ie.length||D,children:"Process compatible replacements in source PDF"}),le&&a.jsx("button",{className:"btn btn-ghost",onClick:ya,disabled:D,children:"Check source-edit job"}),ie.filter(e=>e.pageId===(x==null?void 0:x.id)).map(e=>a.jsxs("button",{className:"pdf-annotation-remove",onClick:()=>{R(),de(t=>t.filter(u=>u.id!==e.id))},children:["Remove “",e.text.slice(0,30),"”"]},e.id))]})]}),a.jsxs("div",{className:"pdf-ocr-controls",children:[a.jsx("h2",{children:"Scan text (OCR)"}),a.jsx("p",{children:"Renders only this page to an in-memory canvas and recognizes English text in a browser worker. The page image and recognized text are never uploaded; OCR does not modify the PDF."}),a.jsx("button",{className:"btn btn-ghost",onClick:ha,disabled:D||(x==null?void 0:x.blank),children:D?"Working…":"Recognize this page"}),Object.hasOwn(Nt,x==null?void 0:x.id)&&a.jsx("textarea",{className:"pdf-ocr-result","aria-label":"Recognized page text",value:Nt[x.id],readOnly:!0,placeholder:"No readable English text found."})]}),a.jsxs("div",{className:"pdf-image-controls",children:[a.jsx("h2",{children:"Images"}),a.jsx("button",{className:"btn btn-ghost",onClick:()=>{var e;return(e=d.current)==null?void 0:e.click()},disabled:D,children:"Add PNG or JPEG"}),O.filter(e=>e.pageId===(x==null?void 0:x.id)).map(e=>a.jsx("button",{className:`pdf-image-list-item${e.id===I?" is-selected":""}`,onClick:()=>te(e.id),children:e.name},e.id)),I&&O.some(e=>e.id===I&&e.pageId===(x==null?void 0:x.id))&&a.jsxs("div",{className:"pdf-image-adjust",children:[a.jsx("button",{onClick:()=>ce({x:Math.max(0,O.find(e=>e.id===I).x-10)}),children:"←"}),a.jsx("button",{onClick:()=>ce({y:O.find(e=>e.id===I).y+10}),children:"↑"}),a.jsx("button",{onClick:()=>ce({y:Math.max(0,O.find(e=>e.id===I).y-10)}),children:"↓"}),a.jsx("button",{onClick:()=>ce({x:O.find(e=>e.id===I).x+10}),children:"→"}),a.jsx("button",{onClick:()=>{const e=O.find(t=>
1t.id===I);ce({width:e.width*.9,height:e.height*.9})},children:"Smaller"}),a.jsx("button",{onClick:()=>{const e=O.find(t=>t.id===I);ce({width:e.width*1.1,height:e.height*1.1})},children:"Larger"}),a.jsx("button",{className:"pdf-annotation-remove",onClick:ua,children:"Remove image"})]})]}),a.jsx("button",{className:"btn btn-primary pdf-export",onClick:ba,disabled:D||A,children:"Download edited PDF"})]})]}):a.jsxs("section",{className:`pdf-editor-empty${z?" is-dropping":""}`,onDragEnter:aa,onDragOver:na,onDragLeave:sa,onDrop:oa,onClick:()=>{var e;return!D&&((e=r.current)==null?void 0:e.click())},onKeyDown:ra,tabIndex:0,role:"button","aria-label":"Choose a PDF file","aria-describedby":"pdf-drop-hint",children:[a.jsx("div",{className:"pdf-editor-icon",children:"PDF"}),a.jsx("h2",{children:"Open a PDF to begin"}),a.jsx("p",{id:"pdf-drop-hint",children:"Drop a PDF here or choose one from your device. Your file is processed in this tab and is never sent to Kernel’s servers."}),a.jsx("span",{className:"btn btn-primary",children:"Choose PDF"})]}),a.jsx("input",{ref:r,className:"pdf-file-input",type:"file",accept:"application/pdf,.pdf",onChange:e=>{var t;nt((t=e.target.files)==null?void 0:t[0]),e.target.value=""}}),a.jsx("input",{ref:i,className:"pdf-file-input",type:"file",accept:"application/pdf,.pdf",onChange:e=>{var t;ja((t=e.target.files)==null?void 0:t[0]),e.target.value=""}}),a.jsx("input",{ref:d,className:"pdf-file-input",type:"file",accept:"image/png,image/jpeg,.png,.jpg,.jpeg",onChange:e=>{var t;ca((t=e.target.files)==null?void 0:t[0]),e.target.value=""}}),a.jsx("p",{id:"pdf-editor-status",className:"pdf-editor-status",role:"status","aria-live":"polite","aria-atomic":"true",children:ea})]})]})}export{kn 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.