1import{f as Ot}from"./worker-entrypoint-Cpi_3YOf.js";const pt={width:595.28,height:841.89},Lt={width:841.89,height:595.28},yt=9,bt=9,$=12,xt=8,q=12,Ct=4,Et=3,R=20,v=20,At=20,J={r:.96,g:.96,b:.96},K={r:.85,g:.85,b:.85},p={r:.1,g:.1,b:.1};function Nt(t){return t.length>=4&&t[0]===80&&t[1]===75}function Pt(t){return t.length>=8&&t[0]===208&&t[1]===207&&t[2]===17&&t[3]===224&&t[4]===161&&t[5]===177&&t[6]===26&&t[7]===225}function Dt(t){return Nt(t)||Pt(t)}function St(t){if(t==null)return null;if(typeof t=="number"||typeof t=="string")return t;if(t instanceof Date)return t.toISOString();if(typeof t=="boolean")return t?"TRUE":"FALSE";if(typeof t=="object"){if("result"in t)return St(t.result);if("text"in t&&typeof t.text=="string")return t.text;if("richText"in t&&Array.isArray(t.richText))return t.richText.map(n=>n.text??"").join("")}return String(t)}function Q(t){return t==null?"":String(t).trim()}function tt(t){const n=t.reduce((r,e)=>Math.max(r,e.length),0);return n===0?[]:t.map(r=>r.length===n?r:[...r,...Array.from({length:n-r.length},()=>null)])}function kt(t){let n=0;for(let r=0;r<t.length;r+=1)n=n*26+(t.charCodeAt(r)-64);return n-1}function $t(t){const n=new Set;if(!Array.isArray(t))return n;for(const r of t){if(typeof r!="string")continue;const[e,a=e]=r.split(":"),o=e.match(/^([A-Z]+)/i),i=a.match(/^([A-Z]+)/i);if(!o||!i)continue;const s=kt(o[1].toUpperCase()),c=kt(i[1].toUpperCase());for(let l=Math.min(s,c);l<=Math.max(s,c);l+=1)n.add(l)}return n}function Ut(t,n=new Set){var o;const r=tt(t),e=((o=r[0])==null?void 0:o.length)??0,a=[];for(let i=0;i<e;i+=1){if(n.has(i)){a.push(i);continue}let s=!1;for(let c=0;c<r.length;c+=1)if(Q(r[c][i])!==""){s=!0;break}s&&a.push(i)}return a}function Wt(t,n=new Set){const r=tt(t);if(r.length===0)return[];const e=Ut(r,n);return e.length===0?r.map(()=>[]):r.map(a=>e.map(o=>a[o]??null))}function zt(t){const n=Q(t);if(!n)return 42;const r=n.split(/\r?\n/).reduce((e,a)=>Math.max(e,a.length),0);return Math.min(260,Math.max(42,16+r*5.6))}function Gt(t){var a;const n=tt(t),r=((a=n[0])==null?void 0:a.length)??0,e=Array.from({length:r},()=>42);for(const o of n)for(let i=0;i<r;i+=1)e[i]=Math.max(e[i],zt(o[i]??null));return e}function et(t){return t.reduce((n,r)=>n+r,0)}function Zt(t,n){return n<=t?"portrait":"landscape"}function jt(t,n,r=1){if(t.length===0)return[];if(et(t)<=n)return[t.map((c,l)=>l)];const e=Math.max(0,Math.min(r,Math.max(0,t.length-1))),a=Array.from({length:e},(c,l)=>l),o=Array.from({length:t.length-e},(c,l)=>l+e),i=[];let s=0;for(;s<o.length;){const c=[...a];let l=a.reduce((d,u)=>d+t[u],0);for(;s<o.length;){const d=o[s],u=t[d];if(c.length>a.length&&l+u>n)break;if(c.length===a.length&&l+u>n){c.push(d),s+=1;break}c.push(d),l+=u,s+=1}c.length===a.length&&s<o.length&&(c.push(o[s]),s+=1),i.push(c)}return i.length>0?i:[t.map((c,l)=>l)]}function Xt(t,n){const r=et(t);if(r<=n||r===0)return t;const e=n/r;return t.map(a=>Math.max(18,a*e))}function Ht(t,n){return t.map(r=>n.map(e=>r[e]??null))}function I(t){return new RegExp("\\p{Script=Cyrillic}","u").test(t)}function Vt(t){const n=t.match(/\S+\s*|\s+/g);return n&&n.length>0?n:[t]}function Yt(t,n,r,e){const a=[];let o="";for(const i of t){const s=o+i;o.length>0&&W(n,s,r)>e?(a.push(o),o=i):o=s}return o.length>0&&a.push(o),a.length>0?a:[t]}function qt(t,n,r,e){const a=t.replace(/\r\n/g,` 2`).split(` 3`),o=[];for(const i of a){const s=i.trim();if(!s){o.push("");continue}const c=Vt(s);let l="";for(const d of c){const u=l+d;if(l&&W(n,u,r)>e){if(o.push(l.trimEnd()),l=d.trimStart(),W(n,l,r)>e){const y=Yt(l,n,r,e);o.push(...y.slice(0,-1)),l=y[y.length-1]??""}}else l=u}l.trim().length>0&&o.push(l.trimEnd())}return o.length>0?o:[""]}function W(t,n,r){try{return t.widthOfTextAtSize(n,r)}catch{return t.widthOfTextAtSize(Bt(n),r)}}function vt(t){if(!t)return[];const n=[];let r="",e=I(t[0]??"");for(const a of t){const o=I(a);if(r.length>0&&o!==e){n.push({text:r,isCyrillic:e}),r=a,e=o;continue}r+=a}return r.length>0&&n.push({text:r,isCyrillic:e}),n}function Tt(t,n,r,e,a,o,i,s,c){let l=r;const d=vt(n);for(const u of d){const y=u.isCyrillic?i:o;let b=u.text;
3try{t.drawText(b,{x:l,y:e,font:y,size:a,color:c(s.r,s.g,s.b)})}catch{b=Bt(b),t.drawText(b,{x:l,y:e,font:o,size:a,color:c(s.r,s.g,s.b)})}const M=u.isCyrillic?i:o;l+=W(M,b,a)}}function Jt(t){if(typeof t!="string"||t.trim()==="")return()=>!0;const n=t.split(",").map(e=>e.trim()).filter(Boolean);if(n.length===0)return()=>!0;const r=[];for(const e of n){const a=/^(\d+)-(\d+)$/.exec(e);if(a){const i=Number(a[1]),s=Number(a[2]);if(!Number.isInteger(i)||!Number.isInteger(s)||i<1||s<i)throw new Error(`Invalid page range: "${e}"`);r.push({start:i,end:s});continue}if(!/^\d+$/.test(e))throw new Error(`Invalid page token: "${e}"`);const o=Number(e);if(!Number.isInteger(o)||o<1)throw new Error(`Invalid page number: "${e}"`);r.push({start:o,end:o})}return e=>r.some(a=>e>=a.start&&e<=a.end)}async function U(t){if(t.startsWith("data:")){const e=/^data:[^;]+;base64,(.+)$/i.exec(t);if(!e)throw new Error("Unsupported data URL font payload");if(typeof atob!="function")throw new Error("Base64 decoder is unavailable in current runtime");const a=atob(e[1]),o=new Uint8Array(a.length);for(let i=0;i<a.length;i+=1)o[i]=a.charCodeAt(i);return o}let n=t;if(typeof self<"u"&&self.location&&!t.startsWith("http://")&&!t.startsWith("https://")&&!t.startsWith("blob:")&&!t.startsWith("data:")){const e=self.location.protocol==="blob:"?self.location.origin:self.location.href;n=new URL(t,e).href}const r=await fetch(n);if(!r.ok)throw new Error(`Failed to load font: ${r.status} ${n}`);return new Uint8Array(await r.arrayBuffer())}async function Kt(){try{const[t,n]=await Promise.all([import("./noto-sans-latin-400-normal-7G8cbq1D.js"),import("./noto-sans-cyrillic-400-normal-CbhKfp2x.js")]);return{latinBytes:await U(t.default),cyrillicBytes:await U(n.default)}}catch{}try{const[t,n]=await Promise.all([import("./noto-sans-latin-400-normal-DgXudELe.js"),import("./noto-sans-cyrillic-400-normal-BviOoXf6.js")]);return{latinBytes:await U(t.default),cyrillicBytes:await U(n.default)}}catch{return null}}async function Qt(t,n){const{PDFDocument:r}=await import("./worker-entrypoint-Cpi_3YOf.js").then(function(c){return c.r}),e=await r.load(await t.arrayBuffer()),a=[];for(let c=0;c<e.getPageCount();c+=1)n(c+1)&&a.push(c);if(a.length===0)throw new Error("No pages matched selected range");const o=await r.create(),i=await o.copyPages(e,a);for(const c of i)o.addPage(c);const s=new Uint8Array(await o.save());return new Blob([s],{type:"application/pdf"})}function Bt(t){return t.replace(/[^\x20-\x7E]/g,"?")}const oe=async({inputIds:t,fs:n,emitProgress:r,options:e})=>{var M,nt;if(t.length===0)throw new Error("Excel to PDF requires at least one input file");const o=(M=(await import("./exceljs.min-CT7m8Rfe.js").then(function(g){return g.e})).default)==null?void 0:M.Workbook;if(!o)throw new Error("Excel parser is unavailable: Workbook constructor not found");const{PDFDocument:i,StandardFonts:s,rgb:c}=await import("./worker-entrypoint-Cpi_3YOf.js").then(function(g){return g.r}),l=[],d=(e==null?void 0:e.range)==="active-sheet"?"active-sheet":"workbook",u=(e==null?void 0:e.showGrid)!==!1,y=(e==null?void 0:e.autoOrientation)===!1&&(e==null?void 0:e.orientation)==="portrait"?"portrait":(e==null?void 0:e.autoOrientation)===!1&&(e==null?void 0:e.orientation)==="landscape"?"landscape":null,b=Jt(e==null?void 0:e.pageSelection);for(let g=0;g<t.length;g+=1){const rt=await(await n.read(t[g])).getBlob().then(f=>f.arrayBuffer()),Rt=new Uint8Array(rt);if(!Dt(Rt))throw new Error(`Failed to parse Excel file ${t[g]}: unsupported container format`);const _=new o;if(await _.xlsx.load(rt),_.worksheets.length===0)throw new Error(`Failed to parse Excel file ${t[g]}: no sheets found`);const x=await i.create();let C=await x.embedFont(s.Helvetica),F=C,z=!1;try{x.registerFontkit(Ot);const f=await Kt();if(!f)throw new Error("Noto font payload unavailable");const{latinBytes:O,cyrillicBytes:Z}=f;C=await x.embedFont(O,{subset:!0}),F=await x.embedFont(Z,{subset:!0}),z=!0}catch{}const ot=d==="active-sheet"?_.worksheets.slice(0,1):_.worksheets,It=Array.isArray(e==null?void 0:e.selectedSheets)?e.selectedSheets.filter(f=>typeof f=="string"&&f.trim().length>0):[],at=new Set(It.map(f=>f.trim())),it=at.size>0?ot.filter(f=>at.has(f.name)):ot;if(it.some(f=>
3I(f.name))&&!z)throw new Error("Cyrillic font is unavailable in this runtime. Cannot render sheet names without replacing text.");let ct=0;for(const f of it){const O=[];f.eachRow({includeEmpty:!0},A=>{const N=Array.isArray(A.values)?A.values.slice(1):[];O.push(N.map(P=>St(P)))});const Z=$t((nt=f.model)==null?void 0:nt.merges),S=Wt(O,Z);if(S.length===0||S[0]&&S[0].length===0)continue;const j=Gt(S),Ft=pt.width-R*2,E=(y??Zt(Ft,et(j)))==="portrait"?pt:Lt,st=E.width-R*2,L=jt(j,st,S[0].length>1?1:0);for(let A=0;A<L.length;A+=1){const N=L[A],P=Ht(S,N),lt=P[0]??[],ft=P.slice(1),ht=Xt(N.map(B=>j[B]),st);let X=0;const ut=B=>{ct+=1;const w=x.addPage([E.width,E.height]),m=L.length>1?` (${A+1}/${L.length})`:"",dt=`Sheet: ${f.name}${m}`;return Tt(w,dt,R,E.height-v-$,$,C,F,p,c),B||w.drawText("(continued)",{x:E.width-R-60,y:E.height-v-$,font:C,size:xt,color:c(p.r,p.g,p.b)}),w.drawText(`Page ${ct}`,{x:R,y:At-4,font:C,size:xt,color:c(p.r,p.g,p.b)}),{page:w,y:E.height-v-$-14,bodyBottom:At+10}};let k=ut(!0);const H=(B,w)=>{const m=B.map(h=>{const T=Q(h),Y=I(T)?F:C;return{text:T,font:Y,lines:[]}});for(let h=0;h<m.length;h+=1){const T=Math.max(8,ht[h]-Ct*2);m[h].lines=qt(m[h].text,m[h].font,w?bt:yt,T)}const D=Math.max(1,...m.map(h=>h.lines.length))*q+Et*2;k.y-D<k.bodyBottom&&!w&&(k=ut(!1),H(lt,!0));let V=R;const gt=k.y;for(let h=0;h<B.length;h+=1){const T=ht[h];u&&k.page.drawRectangle({x:V,y:gt-D,width:T,height:D,borderWidth:.5,borderColor:c(K.r,K.g,K.b),color:w?c(J.r,J.g,J.b):void 0,opacity:1});const Y=m[h].lines;let wt=gt-Et-q+2;for(const mt of Y){if(I(mt)&&!z)throw new Error("Cyrillic font is unavailable in this runtime. Cannot render table text without replacement.");Tt(k.page,mt,V+Ct,wt,w?bt:yt,C,F,p,c),wt-=q}V+=T}k.y-=D};for(H(lt,!0);X<ft.length;)H(ft[X],!1),X+=1}}if(x.getPageCount()===0)throw new Error(`Failed to parse Excel file ${t[g]}: no renderable sheet data found`);const Mt=new Uint8Array(await x.save());let G=new Blob([Mt],{type:"application/pdf"});typeof(e==null?void 0:e.pageSelection)=="string"&&e.pageSelection.trim()!==""&&(G=await Qt(G,b));const _t=await n.write(G);l.push(_t.id),r==null||r(Math.round((g+1)/t.length*100))}return{outputIds:l}};export{Ut as findNonEmptyColumnIndexes,Jt as parsePageSelection,oe as run,jt as splitIntoColumnBands,Wt as stripEmptyColumns};
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.