1import{g as k,a as B,c as e,t as i,n as F,b as S,s as E,d as M,h as v}from"./worker-entrypoint-qNcG03R4.js";function $(a){return e(i(a,1),.5,3)}function W(a){if(!a||typeof a!="object")return;const l=a,d=e(i(l.x,Number.NaN)/100,0,1),r=e(i(l.y,Number.NaN)/100,0,1),s=e(i(l.w,Number.NaN)/100,.001,1),n=e(i(l.h,Number.NaN)/100,.001,1);if([d,r,s,n].every(Number.isFinite))return{x:d,y:r,w:s,h:n}}function C(a,l,d,r){const s=a+d/2,n=l+r/2,p=d/2,u=r/2,c=32,t=[];for(let h=0;h<=c;h+=1){const y=h/c*Math.PI*2;t.push(e(s+Math.cos(y)*p,0,1),e(n+Math.sin(y)*u,0,1))}return t}function P(a){const l=Array.isArray(a==null?void 0:a.elements)?a.elements:Array.isArray(a==null?void 0:a.edits)?a.edits:[],d=new Map;for(let r=0;r<l.length;r+=1){const s=l[r];if(!s||typeof s!="object")continue;const n=s,p=Math.max(0,Math.floor(i(n.pageIndex,0))),u=n.type==="line"||n.type==="rect"||n.type==="whiteout"||n.type==="circle"||n.type==="text"?n.type:"text",c=d.get(p)??[];if(u==="line"){const o=n;c.push({id:`pdf-editor-${p}-${r}`,type:"stroke",points:[e(i(o.x1Ratio,10)/100,0,1),e(i(o.y1Ratio,10)/100,0,1),e(i(o.x2Ratio,30)/100,0,1),e(i(o.y2Ratio,30)/100,0,1)],color:S(o.color),width:e(i(o.strokeWidth,2),.1,32),opacity:F(o.opacity)}),d.set(p,c);continue}if(u==="rect"||u==="whiteout"||u==="circle"){const o=n,f=e(i(o.xRatio,10)/100,0,1),m=e(i(o.yRatio,10)/100,0,1),N=e(i(o.widthRatio,20)/100,.001,1),b=e(i(o.heightRatio,10)/100,.001,1),z=u==="whiteout"?"#ffffff":S(o.color),I=e(i(o.strokeWidth,2),0,32),A=u==="whiteout"?0:I;if(u==="circle"){c.push({id:`pdf-editor-${p}-${r}`,type:"stroke",points:C(f,m,N,b),color:z,width:Math.max(.1,A),opacity:F(o.opacity)}),d.set(p,c);continue}c.push({id:`pdf-editor-${p}-${r}`,type:"rect",x:f,y:m,w:N,h:b,fill:u==="whiteout"?"#ffffff":"transparent",stroke:z,strokeWidth:u==="whiteout"?0:A,opacity:F(o.opacity)}),d.set(p,c);continue}const t=n,h=E(t.text);
1if(!h)continue;const y=$(t.horizontalScaling),g=typeof t.ascentRatio=="number"&&Number.isFinite(t.ascentRatio)?t.ascentRatio:void 0,w=typeof t.descentRatio=="number"&&Number.isFinite(t.descentRatio)?t.descentRatio:void 0,x=typeof t.sourceFontSizeRatio=="number"&&Number.isFinite(t.sourceFontSizeRatio)?t.sourceFontSizeRatio:void 0,R=W(t.originalRect);c.push({id:`pdf-editor-${p}-${r}`,type:"text",x:e(i(t.xRatio,10)/100,0,1),y:e(i(t.yRatio,10)/100,0,1),w:e(i(t.widthRatio,30)/100,.001,1),h:e(i(t.heightRatio,8)/100,.001,1),text:h,color:S(t.color),fontSize:e(i(t.fontSize,16),4,144),fontFamily:v(t.fontFamily),fontWeight:t.bold===!0?"bold":"normal",fontStyle:t.italic===!0?"italic":"normal",textAlign:M(t.textAlign),lineHeight:1.2,letterSpacing:e((y-1)*3,-2,20),opacity:F(t.opacity),...g!==void 0?{ascentRatio:g}:{},...w!==void 0?{descentRatio:w}:{},...x!==void 0?{sourceFontSizeRatio:x}:{},...R?{originalRect:R}:{}}),d.set(p,c)}return Array.from(d.entries()).sort((r,s)=>r[0]-s[0]).map(([r,s])=>({pageIndex:r,elements:s}))}const j=async a=>{const{inputIds:l,fs:d,options:r,emitProgress:s}=a,n=a.signal;if(l.length===0)throw new Error("PDF Editor requires at least one input file");const p=P(r),u=[];for(let c=0;c<l.length;c+=1){const h=await(await d.read(l[c])).getBlob();let y=new Uint8Array(await h.arrayBuffer());if(p.length>0){const R=await k(y,"application/pdf"),o=p.filter(f=>f.pageIndex<R);if(o.length>0)for(let f=0;f<o.length;f+=1){n==null||n.throwIfAborted();const m=o[f];y=(await B({sourceBytes:y,pageIndex:m.pageIndex,elements:m.elements,signal:n})).outputBytes;const b=(f+1)/o.length,z=(c+b)/l.length*100;s==null||s(Math.round(e(z,0,100)))}}const g=new Uint8Array(y.byteLength);g.set(y);const w=await d.write(new Blob([g],{type:"application/pdf"}));u.push(w.id);const x=Math.round((c+1)/l.length*100);s==null||s(x)}return{outputIds:u}};export{j as run};
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.