1import{E as ot}from"./jspdf.es.min-DtorAqlM.js";import{h as rt,t as V,s as X}from"./exportBiblePdf-BJg08xe9.js";import{t as it}from"./nativeDownload-BWDoQRkH.js";import"./index-Cshou3OC.js";import"./bibleApi-DKzoKc5t.js";const x="times",T=595.28,Q=841.89,F=50,D=30,J=11.5,ct=16,N=7,lt=1.8;function H(l=""){return V(X(l)).map(r=>r.text).join("").replace(/[\u00B6\uFFFD]\s*/g,"").replace(/\s+/g," ").trim()}function at(l="",r){const s=[];r!=null&&r!==""&&s.push({t:String(r),sup:!0});let a=!0;return V(X(l)).forEach(n=>{const i=/^\s/.test(n.text);n.text.split(/\s+/).filter(Boolean).forEach((t,h)=>{const d=s[s.length-1],b=h===0&&!i&&!a&&!!d&&!d.sup;s.push({t,italic:n.italic,glue:b})}),a=/\s$/.test(n.text)}),s}function ft(l){const r=new Map;return(s,a,n)=>{const i=`${a}|${n}|${s}`;let t=r.get(i);return t===void 0&&(l.setFont(x,a),l.setFontSize(n),t=l.getTextWidth(s),r.set(i,t)),t}}function ut(l,r){const s=[];let a=null;return l.forEach(n=>{const i=n.sup?r(n.t,"normal",N)+lt:r(n.t,n.italic?"italic":"normal",J),t={...n,w:i};if(s.length&&(n.glue||a&&a.sup)){const h=s[s.length-1];h.parts.push(t),h.w+=i}else s.push({parts:[t],w:i});a=n}),s}function ht(l,r,s){const a=[];let n=[],i=0;return l.forEach(t=>{const h=(n.length?s:0)+t.w;n.length&&i+h>r?(a.push({units:n,w:i}),n=[t],i=t.w):(n.push(t),i+=h)}),n.length&&a.push({units:n,w:i}),a}function R(l,r,s,a,n,i,t){return l.setFont(x,s),l.setFontSize(a),l.splitTextToSize(r,n).map((h,d)=>({kind:"center",text:h,style:s,size:a,color:t,sb:d===0?i:0,h:a*1.4}))}function pt({items:l,bookName:r,chapterText:s,footerLabel:a,fileBase:n,paragraphMode:i=!1}){const t=new ot({unit:"pt",format:"a4"}),h=ft(t),d=T-F*2,b=(d-D)/2,G=h(" ","normal",J);let M="";const z=[];let S=null;const w=()=>{S&&(z.push(S),S=null)};l.forEach(e=>{if(e.isSubscript){M=H(e.text);return}if(e.isColophon){w();const c=H(e.text);c&&z.push({center:!0,text:c,style:"italic",size:9.5,sb:12,color:90});return}if(e.isEndMarker){w();const c=H(e.text).toUpperCase();c&&z.push({center:!0,text:c,style:"bold",size:12,sb:16,color:0});return}if(e.heading){w();const c=String(e.heading);z.push({center:!0,text:c.charAt(0)+c.slice(1).toLowerCase(),style:"bold",size:10.5,sb:12,color:0})}const u=rt(e.text||""),f=at(e.text,e.verse);i&&S&&!u?S.tokens.push(...f):(w(),S={tokens:f,sb:u||i?10:4}),i||w()}),w();const B=[];z.forEach(e=>{if(e.center){B.push(...R(t,e.text,e.style,e.size,b,e.sb,e.color));return}const u=ht(ut(e.tokens,h),b,G);u.forEach((f,c)=>B.push({kind:"flow",units:f.units,w:f.w,justify:c<u.length-1,sb:c===0?e.sb:0,h:ct}))});const K=R(t,r||"","bold",22,d,0,0),_=M?R(t,M,"italic",10.5,d,0,60):[];let v=K.length*26+6+(s?14:0)+18;_.length&&(v+=_.length*14+6);const A=e=>e===0?F+v:F,tt=Q-F-8,I=e=>tt-A(e);let y=[],L=0,W=0,E=0;B.forEach(e=>{let u=E===0?0:e.sb;E+u+e.h>I(L)+.01&&(W===0?W=1:(L+=1,W=0),E=0,u=0),E+=u,y.push({ln:e,page:L,col:W,y:E}),E+=e.h});const P=L,j=y.filter(e=>e.page===P).map(e=>e.ln);if(j.length){let e=0;j.forEach((f,c)=>{e+=(c===0?0:f.sb)+f.h});const u=I(P);for(let f=Math.ceil(e/2);f<=u;f+=1){let c=0,m=0,o=!0;const p=[];for(const g of j){let C=m===0?0:g.sb;if(m+C+g.h>f+.01){if(c===1){o=!1;break}c=1,m=0,C=0}m+=C,p.push({ln:g,page:P,col:c,y:m}),m+=g.h}if(o){y=y.filter(g=>g.page!==P).concat(p);break}}}const O=P+1;for(let e=0;e<O;e+=1){if(e>0&&t.addPage(),e===0){let o=F+22;K.forEach(p=>{t.setFont(x,"bold"),t.setFontSize(22),t.setTextColor(0),t.text(p.text,T/2,o,{align:"center"}),o+=26}),s&&(t.setFont(x,"normal"),t.setFontSize(9),t.setTextColor(110),t.text(String(s).toUpperCase(),T/2,o-8,{align:"center"}),o+=14),_.forEach(p=>{t.setFont(x,"italic"),t.setFontSize(10.5),t.setTextColor(60),t.text(p.text,T/2,o+6,{align:"center"}),o+=14})}const u=y.filter(o=>o.page===e);let f=0,c=!1;if(u.forEach(({ln:o,col:p,y:g})=>{const C=F+p*(b+D),Y=A(e)+g;if(f=Math.max(f,g+o.h),p===1&&(c=!0),o.kind==="center"){t.setFont(x,o.style),t.setFontSize(o.size),t.setTextColor(o.color),t.text(o.text,C+b/2,Y+o.size*1.05,{align:"center"});return}const Z=Y+12,q=o.units.length-1;let U=o.justify&&q>0?(b-o.w)/q:0;(U<0||U>G*3)&&(U=0);let k=C;o.units.forEach((st,nt)=>{nt>
10&&(k+=G+U),st.parts.forEach($=>{$.sup?(t.setFont(x,"normal"),t.setFontSize(N),t.setTextColor(120,30,30),t.text($.t,k,Z-4)):(t.setFont(x,$.italic?"italic":"normal"),t.setFontSize(J),t.setTextColor(0),t.text($.t,k,Z)),k+=$.w})})}),c){const o=F+b+D/2;t.setDrawColor(170),t.setLineWidth(.5),t.line(o,A(e),o,A(e)+f)}t.setFont(x,"normal"),t.setFontSize(8),t.setTextColor(120);const m=r&&s?`${r} â ${s}`:a||r||"";t.text(`${m} â King James Bible â page ${e+1} of ${O}`,T/2,Q-28,{align:"center"})}const et=`KJB-${String(n||r||"chapter").replace(/[^A-Za-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}.pdf`;return{doc:t,name:et}}async function Ft(l){const{doc:r,name:s}=pt(l);await it(r.output("blob"),s)}export{pt as buildChapterPdf,Ft as saveChapterPdf};
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.