1import{l as k}from"./index-BLFiW9lJ.js";import{e as B,c as e,t as i,f as F,b as S,s as E,n as M,g as v}from"./studio-text-edit-applier-miNTUOpW.js";import"./vendor-react-C_xdI0Ng.js";import"./vendor-pdflib-BC_rCeQu.js";import"./fontkit.es-MhQaB983.js";import"./pdf-content-stream-parser-DVMg55u3.js";import"./infer-source-text-style-CB_Q6F8k.js";import"./feature-flag-QAeryYXU.js";function $(r){return e(i(r,1),.5,3)}function W(r){if(!r||typeof r!="object")return;const l=r,p=e(i(l.x,Number.NaN)/100,0,1),a=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([p,a,s,n].every(Number.isFinite))return{x:p,y:a,w:s,h:n}}function C(r,l,p,a){const s=r+p/2,n=l+a/2,d=p/2,u=a/2,c=32,t=[];for(let h=0;h<=c;h+=1){const f=h/c*Math.PI*2;t.push(e(s+Math.cos(f)*d,0,1),e(n+Math.sin(f)*u,0,1))}return t}function P(r){const l=Array.isArray(r==null?void 0:r.elements)?r.elements:Array.isArray(r==null?void 0:r.edits)?r.edits:[],p=new Map;for(let a=0;a<l.length;a+=1){const s=l[a];if(!s||typeof s!="object")continue;const n=s,d=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=p.get(d)??[];if(u==="line"){const o=n;c.push({id:`pdf-editor-${d}-${a}`,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)}),p.set(d,c);continue}if(u==="rect"||u==="whiteout"||u==="circle"){const o=n,y=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-${d}-${a}`,type:"stroke",points:C(y,m,N,b),color:z,width:Math.max(.1,A),opacity:F(o.opacity)}),p.set(d,c);continue}c.push({id:`pdf-editor-${d}-${a}`,type:"rect",x:y,y:m,w:N,h:b,fill:u==="whiteout"?"#ffffff":"transparent",stroke:z,strokeWidth:u==="whiteout"?0:A,opacity:F(o.opacity)}),p.set(d,c);continue}const t=n,h=E(t.text);
1if(!h)continue;const f=$(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-${d}-${a}`,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((f-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}:{}}),p.set(d,c)}return Array.from(p.entries()).sort((a,s)=>a[0]-s[0]).map(([a,s])=>({pageIndex:a,elements:s}))}const G=async r=>{const{inputIds:l,fs:p,options:a,emitProgress:s}=r,n=r.signal;if(l.length===0)throw new Error("PDF Editor requires at least one input file");const d=P(a),u=[];for(let c=0;c<l.length;c+=1){const h=await(await p.read(l[c])).getBlob();let f=new Uint8Array(await h.arrayBuffer());if(d.length>0){const R=await k(f,"application/pdf"),o=d.filter(y=>y.pageIndex<R);if(o.length>0)for(let y=0;y<o.length;y+=1){n==null||n.throwIfAborted();const m=o[y];f=(await B({sourceBytes:f,pageIndex:m.pageIndex,elements:m.elements,signal:n})).outputBytes;const b=(y+1)/o.length,z=(c+b)/l.length*100;s==null||s(Math.round(e(z,0,100)))}}const g=new Uint8Array(f.byteLength);g.set(f);const w=await p.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{G 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.