1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-mammoth-B-gX-_UO.js","assets/vendor-react-C_xdI0Ng.js","assets/vendor-excel--wYEJF5V.js","assets/vendor-pdflib-BC_rCeQu.js"])))=>i.map(i=>d[i]); 2import{_ as j}from"./index-BLFiW9lJ.js";import{c as Bt}from"./qpdf-engine-CRfM6CvT.js";import{Q as Dt}from"./qpdf-errors-DkY-DiA5.js";import{f as Et}from"./fontkit.es-MhQaB983.js";import"./vendor-react-C_xdI0Ng.js";import"./vendor-pdflib-BC_rCeQu.js";const mt=[80,75],tt=[208,207,17,224,161,177,26,225],at='"Noto Sans","Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji","Segoe UI Symbol","Arial Unicode MS","Noto Sans Symbols 2","Noto Sans CJK SC","Noto Sans CJK JP","Noto Sans Devanagari","PingFang SC","Hiragino Sans","Yu Gothic","Microsoft YaHei","Mangal","Kohinoor Devanagari",sans-serif';function Lt(t){return t.length>=2&&t[0]===mt[0]&&t[1]===mt[1]}function _t(t){if(t.length<tt.length)return!1;for(let e=0;e<tt.length;e+=1)if(t[e]!==tt[e])return!1;return!0}function Ht(t){return t.replace(/ /gi," ").replace(/&/gi,"&").replace(/</gi,"<").replace(/>/gi,">").replace(/"/gi,'"').replace(/'/gi,"'")}function it(t){return t.replace(/\r/g,"").replace(/\t/g," ").replace(/[ ]+/g," ").trim()}function G(t){const e=Ht(t.replace(/<[^>]+>/g," "));return it(e.replace(/\breturn\s+true\s*;\s*}/gi," ").replace(/\bfunction\s+\w+\s*\([^)]*\)\s*{/gi," "))}function Mt(t,e){const a=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=new RegExp(`${a}\\s*=\\s*["']([^"']+)["']`,"i").exec(t);return(o==null?void 0:o[1])??""}function rt(t){return t.replace(/<a\b([^>]*)>([\s\S]*?)<\/a>/gi,(e,a,n)=>{const o=Mt(a,"href").trim(),r=G(n);return r.length===0?o.length>0?o:"":o.length===0?r:`${r} (${o})`})}function Ut(t){const e=[],a=/<tr[^>]*>([\s\S]*?)<\/tr>/gi;let n=a.exec(t);for(;n;){const o=n[1],r=/<(?:td|th)[^>]*>([\s\S]*?)<\/(?:td|th)>/gi,i=[];let w=r.exec(o);for(;w;){const h=G(rt(w[1]));h.length>0&&i.push(h),w=r.exec(o)}i.length>0&&e.push(i.join(" | ")),n=a.exec(t)}return e}function $t(t){const e=t.replace(/<script[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?<\/style>/gi," ").replace(/<!--[\s\S]*?-->/g," ").replace(/\n/g," "),a=[],n=/<(h1|h2|h3|p|table|ol|ul)\b[^>]*>[\s\S]*?<\/\1>|<img\b[^>]*>/gi;let o=n.exec(e);for(;o;){const i=o[0];if(/^<img\b/i.exec(i)){const p=Mt(i,"src");p.startsWith("data:image/")?a.push({kind:"image",text:"[Image]",imageDataUrl:p}):a.push({kind:"image",text:"[Image omitted in local mode]"}),o=n.exec(e);continue}const h=/^<(h1|h2|h3|p|table|ol|ul)\b[^>]*>([\s\S]*?)<\/\1>$/i.exec(i);if(!h){o=n.exec(e);continue}const c=h[1].toLowerCase(),u=h[2];if(c==="table"){const p=Ut(u);p.length>0&&a.push({kind:"table",text:p.join(` 3`)}),o=n.exec(e);continue}if(c==="ol"||c==="ul"){const p=/<li\b[^>]*>([\s\S]*?)<\/li>/gi;let R=p.exec(u),d=1;for(;R;){const S=G(rt(R[1]));if(S.length>0){const H=c==="ol"?`${d}. `:"⢠";a.push({kind:"list",text:`${H}${S}`}),d+=1}R=p.exec(u)}o=n.exec(e);continue}const T=G(rt(u));if(T.length===0){o=n.exec(e);continue}c==="h1"?a.push({kind:"heading1",text:T,headingLevel:1}):c==="h2"?a.push({kind:"heading2",text:T,headingLevel:2}):c==="h3"?a.push({kind:"heading3",text:T,headingLevel:3}):a.push({kind:"paragraph",text:T}),o=n.exec(e)}if(a.length>0)return a;const r=G(e);return r.length===0?[{kind:"blank",text:""}]:r.split(` 4`).map(i=>it(i)).filter(i=>i.length>0).map(i=>({kind:"paragraph",text:i}))}function It(t,e){return t==="high"?{defaultFontSize:12,lineHeight:1.45,paragraphGap:6,leftRightMargin:48,topBottomMargin:52,compressStreams:!e}:t==="min"?{defaultFontSize:10,lineHeight:1.25,paragraphGap:4,leftRightMargin:36,topBottomMargin:42,compressStreams:!e}:{defaultFontSize:11,lineHeight:1.35,paragraphGap:5,leftRightMargin:42,topBottomMargin:48,compressStreams:!e}}function Wt(t){const e=t==null?void 0:t.quality,a=e==="high"||e==="min"?e:"standard",n=(t==null?void 0:t.pdfA)===!0,o=(t==null?void 0:t.protectWithPassword)===!0,r=typeof(t==null?void 0:t.password)=="string"?t.password.trim():"",i=(t==null?void 0:t.searchablePdf)!==!1;return{quality:a,pdfA:n,protectWithPassword:o,password:r,searchablePdf:i}}function Nt(t,e){const a=Math.max(.65,Math.min(1,e));return{defaultFontSize:Math.max(8.5,t.defaultFontSize*a),lineHeight:Math.max(1.08,t.lineHeight*(.95+a*.05)),paragraphGap:Math.max(2,Math.round(t.paragraphGap*a)),leftRightMargin:Math.max(18,Math.round(t.leftRightMargin*a)),topBottomMargin:Math.max(20,Math.round(t.topBottomMargin*a)),compressStream
4s:t.compressStreams}}function Ot(t,e){return t==="heading1"?Math.round(e*1.7):t==="heading2"?Math.round(e*1.45):t==="heading3"?Math.round(e*1.25):t==="table"?Math.max(9,Math.round(e*.95)):e}function J(t,e){return t==="heading1"?e.paragraphGap+4:t==="heading2"?e.paragraphGap+3:t==="heading3"||t==="table"?e.paragraphGap+2:t==="blank"?e.paragraphGap+4:e.paragraphGap}function pt(t,e,a,n,o,r){return t-a>=n?t:(o(),r()-e)}function jt(t){if(typeof atob=="function"){const e=atob(t),a=new Uint8Array(e.length);for(let n=0;n<e.length;n+=1)a[n]=e.charCodeAt(n);return a}throw new Error("Base64 decoding is unavailable in this runtime")}function Gt(t){const e=/^data:([^;]+);base64,(.+)$/i.exec(t.trim());if(!e)return null;const a=e[1].toLowerCase(),n=e[2];return{mimeType:a,bytes:jt(n)}}async function et(t){let e=t;if(typeof self<"u"&&self.location&&!t.startsWith("http://")&&!t.startsWith("https://")&&!t.startsWith("blob:")&&!t.startsWith("data:")){const n=self.location.protocol==="blob:"?self.location.origin:self.location.href;e=new URL(t,n).href}const a=await fetch(e);if(!a.ok)throw new Error(`Failed to load font: ${e}`);return new Uint8Array(await a.arrayBuffer())}async function zt(){const[t,e,a]=await Promise.all([j(()=>import("./noto-sans-latin-400-normal-DZbyGt1h.js"),[]),j(()=>import("./noto-sans-cyrillic-400-normal-C2Ud1djk.js"),[]),j(()=>import("./noto-sans-cyrillic-ext-400-normal-B_TeKTr_.js"),[])]);return{latinUrl:t.default,cyrillicUrl:e.default,cyrillicExtUrl:a.default}}function St(t){return new RegExp("\\p{Script=Cyrillic}","u").test(t)}function qt(t){return/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u.test(t)}function Kt(t){return new RegExp("\\p{Script=Devanagari}","u").test(t)}function Vt(t){return St(t)||qt(t)||Kt(t)}function xt(t,e){return!e&&Vt(t)}function ot(t,e){const a=Math.max(1,Math.round(t)),n=Math.max(1,Math.round(e));if(typeof OffscreenCanvas<"u"){const o=new OffscreenCanvas(a,n),r=o.getContext("2d");return r?{canvas:o,context:r}:null}if(typeof document<"u"){const o=document.createElement("canvas");o.width=a,o.height=n;const r=o.getContext("2d");if(r)return{canvas:o,context:r}}return null}async function nt(t,e,a,n,o){const r=ot(Math.max(16,e),Math.max(16,a+10));if(!r)return null;const i=r.context,w=o?"700":"400";i.font=`${w} ${n}px ${at}`;const h=i.measureText(t),c=Math.max(8,Math.ceil(h.width)+6),u=Math.min(Math.max(8,e),c),T=Math.max(a+8,Math.ceil(n*1.5)),p=ot(u,T);if(!p)return null;const{canvas:R,context:d}=p;d.clearRect(0,0,u,T),d.fillStyle="#111",d.textBaseline="top",d.font=`${w} ${n}px ${at}`,d.fillText(t,0,1,u);let S=null;return typeof OffscreenCanvas<"u"&&R instanceof OffscreenCanvas?S=await R.convertToBlob({type:"image/png"}):typeof HTMLCanvasElement<"u"&&R instanceof HTMLCanvasElement&&(S=await new Promise(W=>R.toBlob(W,"image/png"))),S?{bytes:new Uint8Array(await S.arrayBuffer()),width:u,height:T}:null}function Jt(t,e,a,n){const o=t.split(` 5`),r=[];for(const i of o){const w=i.trim();if(w.length===0)continue;const h=w.split(/\s+/);let c="";for(const u of h){const T=c.length>0?`${c} ${u}`:u;if(e.widthOfTextAtSize(T,a)<=n){c=T;continue}if(c.length>0&&r.push(c),e.widthOfTextAtSize(u,a)<=n){c=u;continue}let p="";for(const R of Array.from(u)){const d=`${p}${R}`;e.widthOfTextAtSize(d,a)<=n?p=d:(p.length>0&&r.push(p),p=R)}c=p}c.length>0&&r.push(c)}return r.length>0?r:[""]}function wt(t,e,a){const n=ot(Math.max(16,e),Math.max(16,Math.ceil(a*1.6)));if(!n)return t.split(` 6`).map(i=>i.trim()).filter(i=>i.length>0);const o=n.context;o.font=`${a}px ${at}`;const r=[];for(const i of t.split(` 7`)){const w=i.trim();if(w.length===0)continue;let h="";for(const c of Array.from(w)){const u=`${h}${c}`;o.measureText(u).width<=e?h=u:(h.length>0&&r.push(h),h=c)}h.length>0&&r.push(h)}return r.length>0?r:[""]}function yt(t,e,a){let n=0;for(const o of Array.from(e))Tt(t,o,a)&&(n+=1);return n}function Tt(t,e,a){if(typeof t.widthOfTextAtSize!="function")return!1;try{const n=t.widthOfTextAtSize(e.length>0?e:" ",a);return Number.isFinite(n)}catch{return!1}}function Qt(t,e,a){return Tt(t,e,a)}function Yt(t){return t>=126976&&t<=129791||t>=8592&&t<=8703||t>=8960&&t<=9215||t>=9312&&t<=9471||t>=9632&&t<=9727||t>=9728&&t<=10175||t>=11008&&t<=11263||t===8205||t===65039}function bt(t){const e=t.codePointAt(0);return typeof e!="number"?!1:Yt(e)}async function Xt(t,e){const a={arrayBuffer:e};try{const[n,o]=await Promise.all([t.convertToHtml(a),t.extractRawText(a)]);return{html:n.value,text:o.value}}catch(n){const o=typeof Buffer<"u",r=n instanceof Error?n.message:"";if(!(o&&/could not find file in options/i.test(r)))throw n;const w={buffer:Buffer.from(e)},[h,c]=await Promise.all([t.convertToHtml(w),t.extractRawText(w)]);return{html:h.value,text:c.value}}}function Zt(t,e,a,n,o){const{PDFName:r,PDFNumber:i,PDFArray:w}=t,h=r.of("Annots"),c=e.context.obj([i.of(n.x),i.of(n.y),i.of(n.x+n.width),i.of(n.y+n.height)]),u=e.context.obj([i.of(0),i.of(0),i.of(0)]),T=e.context.obj([o,r.of("Fit")]),p=e.context.obj({S:r.of("GoTo"),D:T}),R=e.context.obj({Type:r.of("Annot"),Subtype:r.of("Link"),Rect:c,Border:u,A:p}),d=e.context.register(R);let S=a.node.lookupMaybe(h,w);if(!S){const H=e.context.obj([]);a.node.set(h,H),S=H}S.push(d)}function te(t,e,a,n,o){const{PDFName:r,PDFNumber:i,PDFString:w,PDFArray:h}=t,c=r.of("Annots"),u=e.context.obj([i.of(n.x),i.of(n.y),i.of(n.x+n.width),i.of(n.y+n.height)]),T=e.context.obj([i.of(0),i.of(0),i.of(0)]),p=e.context.obj({S:r.of("URI"),URI:w.of(o)}),R=e.context.obj({Type:r.of("Annot"),Subtype:r.of("Link"),Rect:u,Border:T,A:p}),d=e.context.register(R);let S=a.node.lookupMaybe(c,h);if(!S){const H=e.context.obj([]);a.node.set(c,H),S=H}S.push(d)}async function ee(t,e,a){if(!e.protectWithPassword)return t;if(!e.password)throw new Dt("PROTECT_INVALID_OPTIONS","Password is required when protection is enabled.");
7return(await a()).encrypt(t,{userPassword:e.password,ownerPassword:e.password,keyLength:256})}async function ne({inputIds:t,fs:e,options:a,emitProgress:n},o){if(t.length===0)throw new Error("Word to PDF requires at least one input file");const r=Wt(a),i=await j(()=>import("./vendor-mammoth-B-gX-_UO.js").then(d=>d.i),__vite__mapDeps([0,1,2])),{PDFDocument:w,StandardFonts:h,PDFArray:c,PDFName:u,PDFNumber:T,PDFString:p}=await j(async()=>{const{PDFDocument:d,StandardFonts:S,PDFArray:H,PDFName:W,PDFNumber:z,PDFString:q}=await import("./vendor-pdflib-BC_rCeQu.js").then(N=>N.c);return{PDFDocument:d,StandardFonts:S,PDFArray:H,PDFName:W,PDFNumber:z,PDFString:q}},__vite__mapDeps([3,1])),R=[];for(let d=0;d<t.length;d+=1){const S=await e.read(t[d]),W=await(await S.getBlob()).arrayBuffer(),z=new Uint8Array(W);if(_t(z))throw new Error("Legacy .doc is not supported in secure local mode. Save as .docx and retry.");if(!Lt(z))throw new Error(`Unsupported Word file format for ${t[d]}. Please upload a .docx file.`);const q=await Xt(i,W),N=$t(q.html);if(N.length===1&&N[0].kind==="blank"){const l=it(q.text);l.length>0&&(N[0]={kind:"paragraph",text:l})}const st=It(r.quality,r.pdfA),Q=[595.28,841.89],At=[1],Ft=async l=>{var dt;const m=await w.create();m.setTitle(`${S.getName().replace(/\.[^.]+$/,"")||"Document"} (Converted)`),m.setCreator("LocalPDF"),m.setSubject(r.pdfA?"Archive conversion profile (best-effort)":"Word to PDF conversion"),m.setKeywords(r.pdfA?["word","pdf","pdfa","best-effort"]:["word","pdf","conversion"]);let L=await m.embedFont(h.Helvetica),K=L,V=L;try{m.registerFontkit(Et);const{latinUrl:s,cyrillicUrl:f,cyrillicExtUrl:x}=await zt(),[y,A,_]=await Promise.all([et(s),et(f),et(x)]);L=await m.embedFont(y,{subset:!0}),K=await m.embedFont(A,{subset:!0}),V=await m.embedFont(_,{subset:!0})}catch{}const $=(s,f=12)=>{const y=St(s)?[K,V,L]:[L,K,V];for(const F of y)if(Qt(F,s,f))return F;let A=L,_=yt(L,s,f);for(const F of[K,V]){const P=yt(F,s,f);P>_&&(A=F,_=P)}return A},kt=async(s,f,x,y,A,_,F)=>{const P=Array.from(s.length>0?s:" ");let M=f,g=P[0]??" ",b=$(g,y),C=bt(g);const B=async()=>{if(g.length!==0){if(C){const D=Math.max(8,Math.round(f+_-M)),k=await nt(g,D,Math.round(A),Math.round(y),F);if(k){const O=await m.embedPng(k.bytes);E.drawImage(O,{x:M,y:x-Math.max(0,k.height-A),width:k.width,height:k.height}),M+=k.width;return}}E.drawText(g,{x:M,y:x,size:y,font:b}),M+=b.widthOfTextAtSize(g,y)}};for(let D=1;D<P.length;D+=1){const k=P[D],O=$(k,y),Z=bt(k);if(Z===C&&(Z||O===b)){g+=k;continue}await B(),g=k,b=O,C=Z}await B()},ct=(s,f)=>{let x=0;for(const y of Array.from(s)){const A=$(y,f);try{x+=A.widthOfTextAtSize(y,f)}catch{x+=Math.max(2,f*.55)}}return x};let E=m.addPage(Q),U=0;const I=new Set,X=[],Ct=E.getWidth(),lt=E.getHeight();let v=lt-l.topBottomMargin;const ht=()=>{U>=0&&!I.has(U)&&v-l.topBottomMargin>lt*.85||(E=m.addPage(Q),U+=1,v=E.getHeight()-l.topBottomMargin)},ft=()=>E.getHeight();for(const s of N){const f=Ot(s.kind,l.defaultFontSize),x=Math.max(10,Math.round(f*l.lineHeight)),y=Ct-l.leftRightMargin*2;if(s.kind==="blank"){v-=J(s.kind,l);continue}if(s.kind==="image"){const F=y,P=r.quality==="high"?180:r.quality==="min"?100:140,M=Math.max(68,Math.round(P*(l.defaultFontSize/st.defaultFontSize)));if(v=pt(v,l.topBottomMargin,l.topBottomMargin,M+J(s.kind,l),ht,ft),(dt=s.imageDataUrl)!=null&&dt.startsWith("data:image/"))try{const g=Gt(s.imageDataUrl);if(!g)throw new Error("Invalid image payload");const b=g.mimeType==="image/png"?await m.embedPng(g.bytes):await m.embedJpg(g.bytes);E.drawImage(b,{x:l.leftRightMargin,y:v-M,width:F,height:M}),I.add(U)}catch{const g=$(s.text);E.drawText("[Image]",{x:l.leftRightMargin,y:v-x,size:f,font:g}),I.add(U)}else{const g=$(s.text);E.drawText(s.text,{x:l.leftRightMargin,y:v-x,size:f,font:g}),I.add(U)}v-=M+J(s.kind,l);continue}let A;try{A=xt(s.text,r.searchablePdf)?wt(s.text,y,f):Jt(s.text,$(s.text,f),f,y)}catch{A=wt(s.text,y,f)}let _=!1;for(const F of A){let P=x,M=null;const g=F.length>0?F:" ";if(xt(g,r.searchablePdf)&&(M=await nt(g,Math.round(y),Math.round(x),Math.round(f),s.kind.startsWith("heading")),M&&(P=Math.max(x,M.height))),v=pt(v,l.topBottomMargin,l.to
7pBottomMargin,P,ht,ft),M){const b=await m.embedPng(M.bytes);E.drawImage(b,{x:l.leftRightMargin,y:v-M.height,width:M.width,height:M.height}),I.add(U)}else{try{await kt(g,l.leftRightMargin,v-x,f,x,y,s.kind.startsWith("heading"))}catch{const B=await nt(g,Math.round(y),Math.round(x),Math.round(f),s.kind.startsWith("heading"));if(B){const D=await m.embedPng(B.bytes);E.drawImage(D,{x:l.leftRightMargin,y:v-B.height,width:B.width,height:B.height}),P=Math.max(P,B.height)}}I.add(U);const b=/https?:\/\/[^\s)]+/gi;let C=b.exec(g);for(;C;){const B=C[0],D=g.slice(0,C.index),k=l.leftRightMargin+ct(D,f),O=Math.max(8,ct(B,f));te({PDFArray:c,PDFName:u,PDFNumber:T,PDFString:p},m,E,{x:k,y:v-x-1,width:O,height:x+3},B),C=b.exec(g)}}if(s.headingLevel&&!_&&F.trim().length>0){const b=E;b.ref&&(X.push({title:F.trim(),level:s.headingLevel,pageRef:b.ref}),_=!0)}v-=P}v-=J(s.kind,l)}if(X.length>0){const s=m.insertPage(0,Q),f=$("Table of Contents",18),x=$("Contents",11),y=b=>{const C=b.replace(/[^\x20-\x7E]/g,"");return C.trim().length>0?C:"Section"},A=l.leftRightMargin,_=s.getHeight()-l.topBottomMargin;try{s.drawText("Table of Contents",{x:A,y:_,size:18,font:f})}catch{s.drawText("Table of Contents",{x:A,y:_,size:18,font:L})}let F=_-30;const P=16,M=Math.max(1,Math.floor((s.getHeight()-l.topBottomMargin*2-40)/P)),g=X.slice(0,M);for(const b of g){const C=(b.level-1)*14,B=b.title.length>110?`${b.title.slice(0,107)}...`:b.title;let D=B,k=0;try{s.drawText(D,{x:A+C,y:F,size:11,font:x}),k=x.widthOfTextAtSize(D,11)}catch{D=y(B),s.drawText(D,{x:A+C,y:F,size:11,font:L}),k=L.widthOfTextAtSize(D,11)}Zt({PDFArray:c,PDFName:u,PDFNumber:T},m,s,{x:A+C,y:F-2,width:k,height:P},b.pageRef),F-=P}}!I.has(U)&&m.getPageCount()>1&&m.removePage(U);const gt=await m.save({useObjectStreams:!1}),ut=new Uint8Array(gt.byteLength);return ut.set(gt),{blob:new Blob([ut],{type:"application/pdf"}),pageCount:m.getPageCount()}};let Y=null;for(const l of At){const m=Nt(st,l),L=await Ft(m);if(Y=L.blob,L.pageCount>=1)break}if(!Y)throw new Error("Failed to render output PDF");const Rt=await ee(Y,r,o),Pt=await e.write(Rt);R.push(Pt.id);const vt=Math.round((d+1)/t.length*100);n==null||n(vt)}return{outputIds:R}}const le=async t=>ne(t,Bt);export{le as run,ne as runWordToPdf};
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.