1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-pdflib-BC_rCeQu.js","assets/vendor-react-C_xdI0Ng.js"])))=>i.map(i=>d[i]); 2import{_ as D,l as Y}from"./index-BLFiW9lJ.js";import{s as H}from"./pdf-image-extractor-Kdr-7SCz.js";import{c as p,n as j,a as G,b as U,d as K,e as X}from"./studio-text-edit-applier-miNTUOpW.js";import{n as J}from"./infer-source-text-style-CB_Q6F8k.js";import{t as q}from"./protect-error-messages-BH7xE7XP.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"./feature-flag-QAeryYXU.js";import"./qpdf-errors-DkY-DiA5.js";import"./protect-errors-CmaV3kPR.js";let V=null;function L(t,e,o){return Math.max(e,Math.min(o,t))}function F(t){return L(t,0,1)}function Q(t){return!Array.isArray(t)||t.length<4?8:Math.hypot(t[2]??0,t[3]??0)||Math.hypot(t[0]??0,t[1]??0)||8}function Z(t,e){const[o,a,r,n,s,i]=t,[l,c,d,f,m,g]=e;return[o*l+r*c,a*l+n*c,o*d+r*f,a*d+n*f,o*m+r*g+s,a*m+n*g+i]}async function tt(){return V||(V=(async()=>{const t=[()=>D(()=>import("./vendor-pdfjs-Oio34r9s.js").then(e=>e.p),[]),()=>D(()=>import("./vendor-pdfjs-Oio34r9s.js").then(e=>e.c),[]),()=>D(()=>import("./vendor-pdfjs-Oio34r9s.js").then(e=>e.c),[])];for(const e of t)try{const o=await e();if(o&&typeof o.getDocument=="function"){if(o.GlobalWorkerOptions&&!o.GlobalWorkerOptions.workerSrc){const a=[()=>D(()=>import("./vendor-pdfjs-Oio34r9s.js").then(r=>r.a),[]),()=>D(()=>import("./vendor-pdfjs-Oio34r9s.js").then(r=>r.b),[])];for(const r of a)try{const n=await r();if(n.default){o.GlobalWorkerOptions.workerSrc=n.default;break}}catch{}}return o}}catch{}return null})()),V}async function et(t,e,o=2){var g;const a=await tt();if(!a)return{spans:[],pageCount:1,width:595,height:842};const r=new Uint8Array(t),s=await a.getDocument({data:r,disableWorker:!0,verbosity:((g=a.VerbosityLevel)==null?void 0:g.ERRORS)??0}).promise,i=await s.getPage(e),l=i.getViewport({scale:1}),c=i.getViewport({scale:o}),d=await i.getTextContent(),f=d.styles,m=[];for(let h=0;h<d.items.length;h+=1){const y=d.items[h];if(!y||typeof y.str!="string"||y.str.trim().length===0||!Array.isArray(y.transform))continue;const _=Z(c.transform,y.transform),x=_[4],I=_[5],S=Q(y.transform),E=Math.hypot(_[2],_[3])||Number(y.height)*o||S*o,w=f[y.fontName];let T=E;w!=null&&w.ascent?T=w.ascent*E:w!=null&&w.descent&&(T=(1+w.descent)*E);let b=E*.18;w!=null&&w.descent&&(b=Math.abs(w.descent)*E);const v=E*y.str.length*.46,k=Math.max(1,Number(y.width)*o||v),P=Math.max(1,Number(y.height)*o||E*1.1),N=I-T;m.push({id:`span-${e}-${h}`,text:y.str,xRatio:F(x/c.width),yRatio:F(N/c.height),widthRatio:L(k/c.width,.001,1),heightRatio:L(P/c.height,.001,1),fontSizeRatio:L(S/l.height,.004,.25),ascentRatio:F(T/c.height),descentRatio:F(b/c.height),fontName:y.fontName,fontFamilyHint:w==null?void 0:w.fontFamily,pageHeightPt:l.height,transform:y.transform})}return{spans:m,pageCount:s.numPages,width:c.width,height:c.height}}const ot=2e3,z=2e4;function R(t,e){const o=new Error(t);throw o.code=e,o}function u(t,e){return(typeof t!="number"||!Number.isFinite(t))&&R(`Invalid numeric field: ${e}`,"STUDIO_EDIT_INVALID_PAYLOAD"),t}function A(t,e){return p(u(t,e),0,1)}function O(t){return p(u(t,"opacity"),0,1)}function at(t){typeof t.text!="string"&&R("Invalid text element payload: text must be a string","STUDIO_EDIT_INVALID_PAYLOAD");const e=t.text.replace(/[\r\n]+/gu," ").slice(0,z);return{id:typeof t.id=="string"&&t.id.trim().length>0?t.id:crypto.randomUUID(),type:"text",x:A(t.x,"text.x"),y:A(t.y,"text.y"),w:p(u(t.w,"text.w"),.001,1),h:p(u(t.h,"text.h"),.001,1),text:e,color:U(t.color),fontSize:p(u(t.fontSize,"text.fontSize"),4,144),fontFamily:G(t.fontFamily),fontWeight:t.fontWeight==="bold"?"bold":"normal",fontStyle:t.fontStyle==="italic"?"italic":"normal",textAlign:j(t.textAlign),lineHeight:p(u(t.lineHeight??1.2,"text.lineHeight"),.8,3),letterSpacing:p(u(t.letterSpacing??0,"text.letterSpacing"),-2,20),opacity:O(t.opacity),ascent:typeof t.ascent=="number"&&Number.isFinite(t.ascent)?p(t.ascent,0,512):void 0,sourceFontName:typeof t.sourceFontName=="string"&&t.sourceFontName.trim().length>0?t.sourceFontName.trim().slice(0,128):void 0,sourceFontFamilyHint:typeof t.sourceFontFamilyHint=="string"&&t.sourceFontFamilyHint.trim().length>0?t.sourceFontFamilyHint.trim().slice(0,128):void 0,sourceFontSizeRatio:typeof t.sourceFontSizeRatio=="number"&&Number.isFinite(t.sourceFontSizeRatio)?p(t.sourceFontSizeRatio,.004,.25):void 0,baselineRatio:typeof t.baselineRatio=="number"&&Number.isFinite(t.baselineRatio)?p(t.baselineRatio,0,1):void 0,originalRect:J(t.originalRect)}}function rt(t){return(!Array.isArray(t)||t.length<4||t.length%2!==0)&&R("Invalid stroke payload: points must be an even array with at least 4 numbers","STUDIO_EDIT_INVALID_PAYLOAD"),t.map((e,o)=>A(e,`stroke.points[${o}]`))}function nt(t){if(t==null)return;Array.isArray(t)||R("Invalid stroke payload: paths must be an array","STUDIO_EDIT_INVALID_PAYLOAD");const e=t.map((o,a)=>((!Array.isArray(o)||o.length<4||o.length%2!==0)&&R(`Invalid stroke payload: paths[${a}] must be an even array with at least 4 numbers`,"STUDIO_EDIT_INVALID_PAYLOAD"),o.map((r,n)=>A(r,`stroke.paths[${a}][${n}]`))));return e.length>0?e:void 0}function it(t){return{id:typeof t.id=="string"&&t.id.trim().length>0?t.id:crypto.randomUUID(),type:"stroke",points:rt(t.points),paths:nt(t.paths),color:U(t.color),width:p(u(t.width,"stroke.width"),.1,64),opacity:O(t.opacity)}}function st(t){return{id:typeof t.id=="string"&&t.id.trim().length>0?t.id:crypto.randomUUID(),type:"rect",x:A(t.x,"rect.x"),y:A(t.y,"rect.y"),w:p(u(t.w,"rect.w"),.001,1),h:p(u(t.h,"rect.h"),.001,1),fill:K(t.fill),stroke:U(t.stroke),strokeWidth:p(u(t.strokeWidth,"rect.strokeWidth"),0,32),op
2acity:O(t.opacity)}}function ct(t){typeof t.dataUrl!="string"&&R("Invalid image payload: dataUrl must be a string","STUDIO_EDIT_INVALID_PAYLOAD");const e=t.dataUrl.trim();return/^data:image\/(png|jpeg|jpg);base64,[a-z0-9+/=]+$/iu.test(e)||R("Unsupported image payload format","STUDIO_EDIT_INVALID_PAYLOAD"),e.length>6e6&&R("Image payload is too large","STUDIO_EDIT_TOO_LARGE"),{id:typeof t.id=="string"&&t.id.trim().length>0?t.id:crypto.randomUUID(),type:"image",x:A(t.x,"image.x"),y:A(t.y,"image.y"),w:p(u(t.w,"image.w"),.001,1),h:p(u(t.h,"image.h"),.001,1),opacity:O(t.opacity),dataUrl:e}}function lt(t){const e=t.formType==="checkbox"||t.formType==="radio"||t.formType==="multiline"||t.formType==="dropdown"?t.formType:"text",o=typeof t.defaultValue=="string"?t.defaultValue:"",a=e==="dropdown"?(Array.isArray(t.options)?t.options:[]).filter(r=>typeof r=="string").map(r=>r.trim()).filter(r=>r.length>0).slice(0,50):void 0;return{id:typeof t.id=="string"&&t.id.trim().length>0?t.id:crypto.randomUUID(),type:"form-field",formType:e,name:typeof t.name=="string"&&t.name.trim().length>0?t.name.trim().slice(0,120):void 0,x:A(t.x,"formField.x"),y:A(t.y,"formField.y"),w:p(u(t.w,"formField.w"),.001,1),h:p(u(t.h,"formField.h"),.001,1),defaultValue:o.slice(0,z),options:a,required:!!t.required,fontSize:p(u(t.fontSize,"formField.fontSize"),4,144),opacity:O(t.opacity)}}function dt(t){return typeof t.text!="string"&&R("Invalid watermark payload: text must be a string","STUDIO_EDIT_INVALID_PAYLOAD"),{id:typeof t.id=="string"&&t.id.trim().length>0?t.id:crypto.randomUUID(),type:"watermark",x:A(t.x,"watermark.x"),y:A(t.y,"watermark.y"),w:p(u(t.w,"watermark.w"),.001,1),h:p(u(t.h,"watermark.h"),.001,1),text:t.text.replace(/[\r\n]+/gu," ").slice(0,z),color:U(t.color),fontSize:p(u(t.fontSize,"watermark.fontSize"),4,144),fontFamily:G(t.fontFamily),fontWeight:t.fontWeight==="bold"?"bold":"normal",fontStyle:t.fontStyle==="italic"?"italic":"normal",opacity:O(t.opacity),rotation:p(u(t.rotation,"watermark.rotation"),-180,180),repeatEnabled:!!t.repeatEnabled,repeatCols:Math.max(1,Math.min(12,Math.floor(u(t.repeatCols,"watermark.repeatCols")))),repeatRows:Math.max(1,Math.min(12,Math.floor(u(t.repeatRows,"watermark.repeatRows")))),repeatGapX:p(u(t.repeatGapX,"watermark.repeatGapX"),0,.5),repeatGapY:p(u(t.repeatGapY,"watermark.repeatGapY"),0,.5)}}function ft(t){const e=u(t.pageIndex,"pageIndex"),o=Math.max(0,Math.floor(e));Array.isArray(t.elements)||R("Invalid payload: elements must be an array","STUDIO_EDIT_INVALID_PAYLOAD"),t.elements.length>ot&&R(`Too many edit elements: ${t.elements.length}`,"STUDIO_EDIT_TOO_LARGE");const a=[];for(const r of t.elements){(!r||typeof r!="object"||!("type"in r))&&R("Invalid edit element entry","STUDIO_EDIT_INVALID_PAYLOAD");const n=r;if(n.type==="text"){a.push(at(n));continue}if(n.type==="stroke"){a.push(it(n));continue}if(n.type==="rect"){a.push(st(n));continue}if(n.type==="image"){a.push(ct(n));continue}if(n.type==="form-field"){a.push(lt(n));continue}if(n.type==="watermark"){a.push(dt(n));continue}R(`Unsupported edit element type: ${n.type}`,"STUDIO_EDIT_UNSUPPORTED_ELEMENT")}return{pageIndex:o,elements:a}}function M(t){if(t.type!=="rect")return!1;const e=String(t.fill||"").trim().toLowerCase(),o=String(t.stroke||"").trim().toLowerCase();return(e==="#ffffff"||e==="#fff")&&(o==="transparent"||o==="#000000"||o==="#ffffff"||o==="#fff")&&(t.strokeWidth??0)<=.001&&(t.opacity??1)>=.99}function yt(t){return t.some(o=>o.type==="text")?!1:t.some(M)}async function pt(t,e,o,a=0){const r=new Set;let n=0;for(const s of e)M(s)&&(n+=1);if(n===0)return{redactedStrings:[],redactionCount:0};try{const s=await ut(t,e,a);for(const i of s)i.length>0&&r.add(i)}catch{}return{redactedStrings:Array.from(r),redactionCount:n}}async function ut(t,e,o=0){var n;const a=[];if(e.filter(s=>s.type==="rect").length===0)return a;try{const s=await $();if(!s)return a;const l=await s.getDocument({data:new Uint8Array(t),disableWorker:!0,verbosity:((n=s.VerbosityLevel)==null?void 0:n.ERRORS)??0}).promise;if(l.numPages===0)return a;const c=Math.min(Math.max(o+1,1),l.numPages),d=await l.getPage(c),f=d.getViewport({scale:1}),m=await d.getTextContent(),g=f.width,h=f.height;for(const y of e)if(y.type==="rect"){if(!M(y))continue;const _=y.x,x=y.y,I=y.w,S=y.h,w=(m.items??[]).filter(T=>{var N,W;if(typeof T.str!="string"||!T.str.trim())return!1;const b=((N=T.transform)==null?void 0:N[4])??0,v=((W=T.transform)==null?void 0:W[5])??0,k=b/g,P=1-v/h;return k>=_-.02&&k<=_+I+.02&&P>=x-.02&&P<=x+S+.02}).map(T=>T.str).join(" ").trim();w.length>1&&a.push(w)}}catch{}return a}let C=null;async function $(){return C||(C=(async()=>{const t=[()=>D(()=>import("./vendor-pdfjs-Oio34r9s.js").then(e=>e.p),[]),()=>D(()=>import("./vendor-pdfjs-Oio34r9s.js").then(e=>e.c),[]),()=>D(()=>import("./vendor-pdfjs-Oio34r9s.js").then(e=>e.c),[])];for(const e of t)try{const o=await e();if(o&&typeof o.getDocument=="function")return o}catch{}return null})()),C}async function mt(t,e){if(e.length===0)return{id:"text_extract",result:"skip",message:"No redacted strings to verify"};try{const a=(await gt(t)).toLowerCase(),r=[];for(const n of e){if(n.length<3)continue;const s=n.toLowerCase().trim();s.length!==0&&a.includes(s)&&r.push(n)}return r.length>0?{id:"text_extract",result:"fail",message:`${r.length} redacted string(s) found in output text layer`}:{id:"text_extract",result:"pass"}}catch(o){return{id:"text_extract",result:"fail",message:`Text extraction check error: ${o instanceof Error?o.message:"Unknown"}`}}}async function gt(t){var e;try{const o=await $();if(o){const c=await o.getDocument({data:new Uint8Array(t),disableWorker:!0,verbosity:((e=o.VerbosityLevel)==null?void 0:e.ERRORS)??0}).promise,d=[];for(let f=1;f<=c.numPages;f+=1){const h=((await(await c.getPage(f)).getTextContent()).items??[]).map(y=>
2typeof y.str=="string"?y.str:"").filter(Boolean);d.push(h.join(" "))}return d.join(` 3`)}const{PDFDocument:a,PDFName:r}=await D(async()=>{const{PDFDocument:l,PDFName:c}=await import("./vendor-pdflib-BC_rCeQu.js").then(d=>d.c);return{PDFDocument:l,PDFName:c}},__vite__mapDeps([0,1])),n=await a.load(t),{extractPdfTextSegments:s}=await D(async()=>{const{extractPdfTextSegments:l}=await import("./pdf-content-stream-parser-DVMg55u3.js");return{extractPdfTextSegments:l}},[]),i=[];for(let l=0;l<n.getPageCount();l+=1){const d=n.getPage(l).node.get(r.of("Contents"));if(!d){i.push("");continue}const f=n.context.lookup(d),m=[];if(f&&typeof f.size=="function"&&typeof f.get=="function"){const h=Number(f.size());for(let y=0;y<h;y+=1)m.push(n.context.lookup(f.get(y)))}else m.push(f);const g=[];for(const h of m)if(!(!h||typeof h.getContents!="function"))try{const y=h.getContents(),_=new TextDecoder("latin1").decode(y);g.push(...s(_))}catch{}i.push(g.join(" ").trim())}return i.join(` 4`).trim()}catch{return""}}async function ht(t){var e;try{const{PDFDocument:o}=await D(async()=>{const{PDFDocument:n}=await import("./vendor-pdflib-BC_rCeQu.js").then(s=>s.c);return{PDFDocument:n}},__vite__mapDeps([0,1])),a=await o.load(t),r=(e=a.getInfoDict)==null?void 0:e.call(a);return{id:"metadata_xmp",result:"pass"}}catch(o){return{id:"metadata_xmp",result:"fail",message:`Metadata check error: ${o instanceof Error?o.message:"Unknown"}`}}}async function _t(t){try{const{PDFDocument:e,PDFName:o}=await D(async()=>{const{PDFDocument:r,PDFName:n}=await import("./vendor-pdflib-BC_rCeQu.js").then(s=>s.c);return{PDFDocument:r,PDFName:n}},__vite__mapDeps([0,1])),a=await e.load(t);for(let r=0;r<a.getPageCount();r+=1){const s=a.getPage(r).node.get(o.of("Annots"));if(!s)continue;const i=a.context.lookup(s);if(!i||typeof i.size!="function")continue;const l=Number(i.size());for(let c=0;c<l;c+=1){const d=i.get(c),f=a.context.lookup(d);if(!f||typeof f.get!="function")continue;const m=f.get(o.of("Subtype"));if(m&&String(m)==="/Redact")return{id:"annotations",result:"fail",message:`Found /Redact annotation on page ${r+1}`}}}return{id:"annotations",result:"pass"}}catch(e){return{id:"annotations",result:"fail",message:`Annotations check error: ${e instanceof Error?e.message:"Unknown"}`}}}function wt(t){return t.replace(/\\/g,"\\\\").replace(/\(/g,"\\(").replace(/\)/g,"\\)").replace(/\r/g,"\\r").replace(/\n/g,"\\n")}async function Et(t,e,o){if(e.length===0)return{id:"raw_bytes",result:"skip",message:"No redacted strings to verify"};try{const r=new TextDecoder("utf-8",{fatal:!1}).decode(t),n=new TextDecoder("latin1").decode(t),s=[];for(const i of e){if(i.length<3)continue;if(r.includes(i)||n.includes(i)){s.push(i);continue}const l=wt(i);if(r.includes(l)||n.includes(l)){s.push(i);continue}const c=[];for(let d=0;d<i.length;d+=1){const f=i.charCodeAt(d);c.push(f.toString(16).toUpperCase().padStart(4,"0"))}if(c.length>0){const d=`<FEFF${c.join("")}>`;if(r.includes(d)||n.includes(d)){s.push(i);continue}}}return s.length>0?{id:"raw_bytes",result:"fail",message:`${s.length} redacted string(s) found in raw PDF bytes`}:{id:"raw_bytes",result:"pass"}}catch(a){return{id:"raw_bytes",result:"fail",message:`Raw bytes check error: ${a instanceof Error?a.message:"Unknown"}`}}}async function B(t){const e=t.buffer.slice(0,t.byteLength),o=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(o)).map(r=>r.toString(16).padStart(2,"0")).join("")}async function Tt(t){const e=new TextEncoder().encode(t),o=e.buffer.slice(0,e.byteLength),a=await crypto.subtle.digest("SHA-256",o);return Array.from(new Uint8Array(a)).map(n=>n.toString(16).padStart(2,"0")).join("")}function Dt(t){const e={};for(const o of t.checks)e[o.id]=o.result;return{format:"localpdf-certificate/v1",createdAt:new Date().toISOString(),tool:"studio.edit.redact",appVersion:t.appVersion,inputSha256:t.inputSha256,outputSha256:t.outputSha256,redactedStringHashes:t.redactedStringHashes,checks:e,stats:t.stats}}async function Rt(t,e,o,a,r=0){const{redactedStrings:n,redactionCount:s}=await pt(t,o,a,r),[i,l,c,d]=await Promise.all([mt(e,n),ht(e),_t(e),Et(e,n)]),f=[i,l,c,d],m=f.every(E=>
4E.result==="pass"),g=f.every(E=>E.result==="skip"),h=await B(t),y=await B(e),_=[];for(const E of n)E.length>=3&&_.push(`sha256:${await Tt(E)}`);let x=0;try{const{PDFDocument:E}=await D(async()=>{const{PDFDocument:T}=await import("./vendor-pdflib-BC_rCeQu.js").then(b=>b.c);return{PDFDocument:T}},__vite__mapDeps([0,1]));x=(await E.load(e)).getPageCount()}catch{x=0}const I={pages:x,redactionCount:s},S=Dt({inputSha256:h,outputSha256:y,redactedStringHashes:_,checks:f,stats:I,appVersion:a});return{passed:m,checks:f,redactedStringHashes:_,stats:I,certificate:m&&!g?S:void 0}}async function vt(t,e,o){try{if(t.payload.type==="GET_PDF_PAGE_COUNT"){const a=Date.now(),{fileId:r,bytes:n,mimeType:s}=t.payload.payload,i=(m,g,h)=>{o==null||o({id:t.id,type:"EVENT",payload:{type:"DIAGNOSTIC",payload:{channel:"PAGE_COUNT",stage:m,fileId:r,durationMs:g,note:h}}})};i("WORKER_COMMAND_RECEIVED");let l=n,c=s;if(l===void 0){const m=Date.now();i("WORKER_FS_READ_START");const g=await e.fs.read(r);i("WORKER_FS_READ_DONE",Date.now()-m);const h=Date.now();i("WORKER_GET_TYPE_START"),c=await g.getType(),i("WORKER_GET_TYPE_DONE",Date.now()-h,c);const y=Date.now();i("WORKER_GET_BLOB_START");const _=await g.getBlob();i("WORKER_GET_BLOB_DONE",Date.now()-y);const x=Date.now();i("WORKER_ARRAY_BUFFER_START"),l=new Uint8Array(await _.arrayBuffer()),i("WORKER_ARRAY_BUFFER_DONE",Date.now()-x,`${l.byteLength} bytes`)}else i("WORKER_INLINE_BYTES_RECEIVED",void 0,`${l.byteLength} bytes`);const d=Date.now();i("WORKER_PARSE_START");const f=await Y(l,c);return i("WORKER_PARSE_DONE",Date.now()-d,`pages=${f}`),i("WORKER_COMMAND_DONE",Date.now()-a),{id:t.id,type:"EVENT",payload:{type:"PAGE_COUNT_RESULT",payload:{fileId:r,pageCount:f}}}}if(t.payload.type==="GET_PDF_TEXT_LAYER"){const{fileId:a,pageNumber:r,bytes:n}=t.payload.payload;let s=n;if(s===void 0){const c=await(await e.fs.read(a)).getBlob();s=new Uint8Array(await c.arrayBuffer())}const i=await et(s,r);return{id:t.id,type:"EVENT",payload:{type:"TEXT_LAYER_RESULT",payload:{fileId:a,pageNumber:r,spans:i.spans,width:i.width,height:i.height,pageCount:i.pageCount}}}}if(t.payload.type==="GET_PDF_IMAGE_CANDIDATES"){const{fileId:a,pageNumber:r,bytes:n}=t.payload.payload;let s=n;if(s===void 0){const d=await(await e.fs.read(a)).getBlob();s=new Uint8Array(await d.arrayBuffer())}const i=new Uint8Array(s.byteLength);i.set(s);const l=await H(new Blob([i.buffer],{type:"application/pdf"}),{pageNumbers:[r]});return{id:t.id,type:"EVENT",payload:{type:"IMAGE_CANDIDATES_RESULT",payload:{fileId:a,pageNumber:r,candidates:l}}}}if(t.payload.type==="APPLY_STUDIO_TEXT_EDITS"){const{fileId:a}=t.payload.payload,{pageIndex:r,elements:n}=ft({pageIndex:t.payload.payload.pageIndex,elements:t.payload.payload.elements}),i=await(await e.fs.read(a)).getBlob(),l=new Uint8Array(await i.arrayBuffer()),{outputBytes:c,overflowDetected:d,trueReplaceApplied:f,trueReplaceFallbackReason:m}=await X({sourceBytes:l,pageIndex:r,elements:n}),g=new Uint8Array(c.byteLength);g.set(c);const h=new Blob([g.buffer],{type:"application/pdf"}),y=await e.fs.write(h);let _;if(yt(n))try{const I=await Rt(l,g,n,"studio",r);_={passed:I.passed,checks:I.checks.map(S=>`${S.id}:${S.result}`),certificateJson:I.certificate?JSON.stringify(I.certificate,null,2):void 0}}catch{_={passed:!1,checks:["error:verify_crashed"]}}return{id:t.id,type:"EVENT",payload:{type:"STUDIO_TEXT_EDITS_APPLIED",payload:{fileId:a,pageIndex:r,outputId:y.id,overflowDetected:d,trueReplaceApplied:f,trueReplaceFallbackReason:m,redactVerify:_}}}}if(t.payload.type==="PROCESS_TOOL"){const{toolId:a,inputIds:r,options:n}=t.payload.payload,l=await(await e.registry.get(a).logicLoader()).run({inputIds:r,options:n,fs:e.fs,emitProgress:c=>{const d=typeof c=="number"?c:c.progress,f=typeof c=="number"?void 0:c.detail;o==null||o({id:t.id,type:"EVENT",payload:{type:"PROGRESS",payload:{progress:d,detail:f}}})}});return{id:t.id,type:"EVENT",payload:{type:"RESULT",payload:{outputIds:l.outputIds}}}}if(t.payload.type==="READ_FILE"){const a=await e.fs.read(t.payload.payload.fileId);return{id:t.id,type:"EVENT",payload:{type:"RESULT",payload:{outputIds:[a.id]}}}}return{id:t.id,type:"EVENT",payload:{type:"ERROR",payload:{message:"Unknown command",code:"UNKNOWN_COMMAND"}}}}catch(a){const r=q(a),n=r;return{id:t.id,type:"EVENT",payload:{type:"ERROR",payload:{message:r.message,code:typeof n.code=="string"?n.code:"WORKER_RUNTIME_ERROR"}}}}}export{vt as executeWorkerCommand};
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.