import {c}from'./chunk-5UCYRCUV.mjs';import {f,E,Y,O,W as W$1,m,n}from'./chunk-L7HQCG64.mjs';import {b}from'./chunk-JHTTIFGA.mjs';import {f as f$1}from'./chunk-KNY7SXPJ.mjs';function be(e,n){let i=e.floating;if(!i)return  false;let r=f(e,n),t=0;i.tblpX!==void 0?t=i.tblpX:i.tblpXSpec?i.tblpXSpec==="left"||i.tblpXSpec==="inside"?t=0:i.tblpXSpec==="right"||i.tblpXSpec==="outside"?t=n-r:i.tblpXSpec==="center"&&(t=(n-r)/2):e.justification==="center"?t=(n-r)/2:e.justification==="right"&&(t=n-r);let o=i.leftFromText??0,l=i.rightFromText??0,a=t-o,s=n-(t+r)-l;return a<E&&s<E}function We(e,n,i){for(let r=0;r<e.length;r++){let t=e[r];t.kind==="table"&&t.floating&&be(t,n[r]??i)&&(e[r]={...t,floating:void 0});}}function ne(e,n){if(e.pages.length===0)return null;let i=e.pageGap??0,r=0,t=null,o=1/0;for(let l=0;l<e.pages.length;l++){let a=e.pages[l],s=a.size?.h??e.pageSize.h,f=r,u=f+s;if(n.y>=f&&n.y<u)return {pageIndex:l,page:a,pageY:n.y-f};let c=f+s/2,m=Math.abs(n.y-c);m<o&&(o=m,t=l),r=u+i;}if(t!==null){let l=e.pages[t],a=D(e,t);return {pageIndex:t,page:l,pageY:Math.max(0,Math.min(n.y-a,l.size?.h??e.pageSize.h))}}return null}function D(e,n){let i=e.pageGap??0,r=0;for(let t=0;t<n&&t<e.pages.length;t++){let l=e.pages[t].size?.h??e.pageSize.h;r+=l+i;}return r}function Ge(e,n){return ne(e,{y:n})?.pageIndex??null}function oe(e,n){return e.findIndex(i=>i.id===n)}function Ue(e,n){let i=0;for(let r=e.fromLine;r<e.toLine&&r<n.lines.length;r++)i+=n.lines[r].lineHeight;return i}function xe(e,n,i,r){let t=[...e.page.fragments].sort((o,l)=>{let a=o.y-l.y;return Math.abs(a)>.5?a:o.x-l.x});for(let o of t){let l=oe(n,o.blockId);if(l===-1)continue;let a=n[l],s=i[l];if(!a||!s)continue;let f;if(o.kind==="paragraph"){if(a.kind!=="paragraph"||s.kind!=="paragraph")continue;f=Ue(o,s);}else if(o.kind==="table")f=o.height;else if(o.kind==="image")f=o.height;else continue;let u=r.x>=o.x&&r.x<=o.x+o.width,c=r.y>=o.y&&r.y<=o.y+f;if(u&&c)return {fragment:o,block:a,measure:s,pageIndex:e.pageIndex,localX:r.x-o.x,localY:r.y-o.y}}return null}function Ve(e,n,i,r){for(let t of e.page.fragments){if(t.kind!=="image")continue;let o=oe(n,t.blockId);if(o===-1)continue;let l=n[o],a=i[o];if(!l||!a)continue;let s=r.x>=t.x&&r.x<=t.x+t.width,f=r.y>=t.y&&r.y<=t.y+t.height;if(s&&f)return {fragment:t,block:l,measure:a,pageIndex:e.pageIndex,localX:r.x-t.x,localY:r.y-t.y}}return null}function Te(e,n,i,r){for(let t of e.page.fragments){if(t.kind!=="table")continue;let o=t,l=r.x>=o.x&&r.x<=o.x+o.width,a=r.y>=o.y&&r.y<=o.y+o.height;if(!l||!a)continue;let s=oe(n,o.blockId);if(s===-1)continue;let f=n[s],u=i[s];if(!f||f.kind!=="table"||!u||u.kind!=="table")continue;let c=f,m=u,h=r.x-o.x,x=r.y-o.y,d=o.headerRowCount??0,g=d>0&&o.continuesFromPrev?Y(m,d):0,p=0,b=-1;if(m.rows.length===0||c.rows.length===0)continue;if(g>0&&x<g){let F=0;for(let P=0;P<d&&P<m.rows.length;P++){let L=m.rows[P];if(x>=F&&x<F+L.height){b=P;break}F+=L.height;}b===-1&&(b=0);}else {let F=x-g;for(let P=o.fromRow;P<o.toRow&&P<m.rows.length;P++){let L=m.rows[P];if(F>=p&&F<p+L.height){b=P;break}p+=L.height;}}if(b===-1&&(b=Math.min(o.toRow-1,m.rows.length-1),b<o.fromRow))continue;let k=m.rows[b],H=c.rows[b];if(!k||!H)continue;let M=0,T=-1;if(k.cells.length===0||H.cells.length===0)continue;for(let F=0;F<k.cells.length;F++){let P=k.cells[F];if(h>=M&&h<M+P.width){T=F;break}M+=P.width;}if(T===-1&&(T=k.cells.length-1,T<0))continue;let S=k.cells[T],w=H.cells[T];if(!S||!w)continue;let y=0;if(g>0&&b<d)for(let F=0;F<b;F++)y+=m.rows[F]?.height??0;else {y=g;for(let F=o.fromRow;F<b;F++)y+=m.rows[F]?.height??0;}let B=0;for(let F=0;F<T;F++)B+=k.cells[F]?.width??0;let A,I;if(w.blocks&&w.blocks.length>0){let F=w.blocks[0],P=S.blocks[0];F.kind==="paragraph"&&P?.kind==="paragraph"&&(A=F,I=P);}let E=h-B,C=x-y;return {fragment:o,block:c,measure:m,pageIndex:e.pageIndex,rowIndex:b,colIndex:T,cellBlock:A,cellMeasure:I,cellLocalX:Math.max(0,E),cellLocalY:Math.max(0,C)}}return null}function $e(e,n,i,r){let t={pageHit:null,fragmentHit:null,tableCellHit:null};if(t.pageHit=ne(e,r),!t.pageHit)return t;let o=D(e,t.pageHit.pageIndex),l={x:r.x,y:r.y-o};return t.fragmentHit=xe(t.pageHit,n,i,l),t.fragmentHit?.fragment.kind==="table"&&(t.tableCellHit=Te(t.pageHit,n,i,l)),t}function qe(e){if(e.pages.length===0)return 0;let n=e.pageGap??0,i=0;for(let r=0;r<e.pages.length;r++){let t=e.pages[r];i+=t.size?.h??e.pageSize.h,r<e.pages.length-1&&(i+=n);}return i}function je(e,n){return D(e,n)}function Je(e,n){if(n<0||n>=e.pages.length)return null;let i=D(e,n),t=e.pages[n].size?.h??e.pageSize.h;return {top:i,bottom:i+t}}function re(e){return {fontFamily:e.fontFamily??"Arial",fontSize:e.fontSize??12,bold:e.bold,italic:e.italic,letterSpacing:e.letterSpacing}}function ke(e,n){let i=[];for(let r=n.fromRun;r<=n.toRun&&r<e.runs.length;r++){let t=e.runs[r];if(t){if(t.kind==="tab"||t.kind==="image"||t.kind==="lineBreak"){i.push(t);continue}if(t.kind==="text"){let o=t.text??"",l=r===n.fromRun,a=r===n.toRun;if(l||a){let s=l?n.fromChar:0,f=a?n.toChar:o.length,u=o.slice(s,f);u.length>0&&i.push({...t,text:u});}else i.push(t);}}}return i}function Fe(e,n){let i,r,t=e.pmStart??0,o=0;for(let l=0;l<e.runs.length&&l<=n.toRun;l++){let a=e.runs[l];a&&(l<n.fromRun?a.kind==="text"?o+=(a.text??"").length:(a.kind==="tab"||a.kind==="lineBreak"||a.kind==="image")&&(o+=1):l===n.fromRun&&(o+=n.fromChar,i=t+o,a.kind==="text"&&(o=n.fromChar)));}if(i!==void 0){let l=0;for(let a=n.fromRun;a<=n.toRun&&a<e.runs.length;a++){let s=e.runs[a];if(s)if(s.kind==="text"){let f=s.text??"",u=a===n.fromRun?n.fromChar:0,c=a===n.toRun?n.toChar:f.length;l+=c-u;}else (s.kind==="tab"||s.kind==="lineBreak"||s.kind==="image")&&(l+=1);}r=i+l;}return {pmStart:i,pmEnd:r}}function Ke(e,n,i,r){let t=0;for(let o=i;o<r&&o<e.lines.length;o++){let a=e.lines[o].lineHeight;if(n>=t&&n<t+a)return o;t+=a;}return r>i?Math.min(r-1,e.lines.length-1):null}function Qe(e,n$1,i,r){let{pmStart:t,pmEnd:o}=Fe(e,n$1);if(t===void 0||o===void 0)return {charOffset:0,pmPosition:e.pmStart??0};let l=e.attrs?.alignment??"left",a=0;l==="center"?a=Math.max(0,(r-n$1.width)/2):l==="right"&&(a=Math.max(0,r-n$1.width));let s=Math.max(0,i-a);if(s<=0)return {charOffset:0,pmPosition:t};let f=ke(e,n$1);if(f.length===0)return {charOffset:0,pmPosition:t};let u=0,c=0;for(let h of f){if(h.kind==="tab"){let x=h.width??48,d=u+x;if(s<=d){let g=u+x/2;return s<g?{charOffset:c,pmPosition:t+c}:{charOffset:c+1,pmPosition:t+c+1}}u=d,c+=1;continue}if(h.kind==="image"){let x=h.width,d=u+x;if(s<=d){let g=u+x/2;return s<g?{charOffset:c,pmPosition:t+c}:{charOffset:c+1,pmPosition:t+c+1}}u=d,c+=1;continue}if(h.kind==="lineBreak"){if(s>=u)return {charOffset:c,pmPosition:t+c};c+=1;continue}if(h.kind==="text"){let x=h.text??"";if(x.length===0)continue;let d=re(h),g=m(x,d),p=u+g.width;if(s<=p){let b=s-u,k=n(b,g.charWidths),H=c+k;return {charOffset:H,pmPosition:t+H}}u=p,c+=x.length;}}return {charOffset:o-t,pmPosition:o}}function ie(e){let{fragment:n,block:i,measure:r,localX:t,localY:o}=e;if(n.kind!=="paragraph"||i.kind!=="paragraph"||r.kind!=="paragraph")return null;let l=n,a=i,s=r,f=Ke(s,o,l.fromLine,l.toLine);if(f===null)return null;let u=s.lines[f];if(!u)return null;let c=0;for(let k=l.fromLine;k<f;k++)c+=s.lines[k]?.lineHeight??0;let m=a.attrs?.indent,h=m?.left??0,x=m?.right??0,d=Math.max(0,n.width-h-x),g=t-h,{charOffset:p,pmPosition:b}=Qe(a,u,g,d);return {pmPosition:b,charOffset:p,lineIndex:f}}function Me(e){let{cellBlock:n,cellMeasure:i,cellLocalX:r,cellLocalY:t}=e;if(!n||!i)return null;let o={fragment:{kind:"paragraph",blockId:n.id,x:0,y:0,width:i.lines.reduce((a,s)=>Math.max(a,s.width),100),fromLine:0,toLine:i.lines.length,height:i.totalHeight},block:n,measure:i,pageIndex:e.pageIndex,localX:r,localY:t};return ie(o)?.pmPosition??null}function Ze(e,n){if(n)return Me(n);if(!e)return null;let{fragment:i}=e;return i.kind==="paragraph"?ie(e)?.pmPosition??null:i.kind==="image"?i.pmStart??null:null}function ye(e,n,i,r){let t=e.pmStart??0,o=e.pmEnd??t;if(i<t||i>o)return null;let l=i-t;for(let a=0;a<n.lines.length;a++){let s=n.lines[a],{pmStart:f,pmEnd:u}=Fe(e,s);if(f===void 0||u===void 0)continue;let c=f-t,m$1=u-t;if(l>=c&&l<=m$1){let h=l-c,x=ke(e,s),d=0,g=0;for(let p of x)if(p.kind==="tab"){if(h<=g+1)return h<=g?{x:d,lineIndex:a}:{x:d+(p.width??48),lineIndex:a};d+=p.width??48,g+=1;}else if(p.kind==="image"){if(h<=g+1)return h<=g?{x:d,lineIndex:a}:{x:d+p.width,lineIndex:a};d+=p.width,g+=1;}else if(p.kind==="lineBreak"){if(h<=g)return {x:d,lineIndex:a};g+=1;}else if(p.kind==="text"){let b=p.text??"";if(h<=g+b.length){let M=h-g,T=re(p),S=m(b.slice(0,M),T);return {x:d+S.width,lineIndex:a}}let k=re(p),H=m(b,k);d+=H.width,g+=b.length;}return {x:d,lineIndex:a}}}return null}function et(e,n,i,r,t,o,l){let a=ye(e,n,i);if(!a)return null;let s=e.attrs?.alignment??"left",f=e.attrs?.indent,u=f?.left??0,c=f?.right??0,m=Math.max(0,o-u-c),h=n.lines[a.lineIndex];if(!h)return null;let x=0;s==="center"?x=Math.max(0,(m-h.width)/2):s==="right"&&(x=Math.max(0,m-h.width));let d=0;for(let g=l;g<a.lineIndex;g++)d+=n.lines[g]?.lineHeight??0;return {x:r+u+x+a.x,y:t+d,height:h.lineHeight}}function tt(e,n,i={}){let r=i.scope??"body",t=r==="body"?"layout-page-content":`layout-page-${r}`,o=`.${t} .layout-table-cell`,l=e.querySelectorAll(`.${t} .layout-table-cell-selected`);for(let c of Array.from(l))c.classList.remove("layout-table-cell-selected");let a=n.selection;if(!("$anchorCell"in a&&typeof a.forEachCell=="function")||!a.forEachCell)return;let f=[];a.forEachCell((c,m)=>{f.push([m,m+c.nodeSize]);});let u=e.querySelectorAll(o);for(let c of Array.from(u)){let m=c,h=m.dataset.pmStart;if(h===void 0)continue;let x=Number(h);for(let[d,g]of f)if(x>=d&&x<g){m.classList.add("layout-table-cell-selected");break}}}function He(e){return {fontFamily:e.fontFamily??"Arial",fontSize:e.fontSize??12,bold:e.bold,italic:e.italic,letterSpacing:e.letterSpacing}}function ae(e,n){return e.findIndex(i=>i.id===n)}function U(e,n){let r=(e.pmStart??0)+1,t=0,o;for(let s=0;s<e.runs.length&&s<=n.toRun;s++){let f=e.runs[s];if(f){if(s<n.fromRun)f.kind==="text"?t+=(f.text??"").length:t+=1;else if(s===n.fromRun){t+=n.fromChar,o=r+t;break}}}o===void 0&&(o=r);let l=0;for(let s=n.fromRun;s<=n.toRun&&s<e.runs.length;s++){let f=e.runs[s];if(f)if(f.kind==="text"){let u=f.text??"",c=s===n.fromRun?n.fromChar:0,m=s===n.toRun?n.toChar:u.length;l+=m-c;}else l+=1;}let a=o+l;return {pmStart:o,pmEnd:a}}function Pe(e,n,i,r){let t=[];for(let o=0;o<n.lines.length;o++){let l=n.lines[o],a=U(e,l);a.pmStart===void 0||a.pmEnd===void 0||a.pmEnd>i&&a.pmStart<r&&t.push({line:l,index:o});}return t}function W(e,n,i){let r=U(e,n);return r.pmStart===void 0?0:Math.max(0,i-r.pmStart)}function G(e,n,i,r){let t=0,o=0;for(let l=n.fromRun;l<=n.toRun&&l<e.runs.length;l++){let a=e.runs[l];if(a){if(a.kind==="tab"){let s=a.width??48;if(o+1>=i)return i<=o?t:t+s;t+=s,o+=1;continue}if(a.kind==="image"){let s=a.width;if(o+1>=i)return i<=o?t:t+s;t+=s,o+=1;continue}if(a.kind==="lineBreak"){if(i<=o)return t;o+=1;continue}if(a.kind==="text"){let s=a.text??"",f=l===n.fromRun,u=l===n.toRun,c=f?n.fromChar:0,m$1=u?n.toChar:s.length,h=s.slice(c,m$1);if(o+h.length>=i){let g=i-o,p=He(a),b=m(h.slice(0,g),p);return t+b.width}let x=He(a),d=m(h,x);t+=d.width,o+=h.length;}}}return t}function J(e,n){let i=0;for(let r=0;r<n&&r<e.lines.length;r++)i+=e.lines[r].lineHeight;return i}function nt(e,n,i,r,t){if(r===t)return [];let o=Math.min(r,t),l=Math.max(r,t),a=[];for(let s=0;s<e.pages.length;s++){let f=e.pages[s],u=D(e,s);for(let c of f.fragments){if(c.kind==="paragraph"){let m=ae(n,c.blockId);if(m===-1)continue;let h=n[m],x=i[m];if(!h||h.kind!=="paragraph"||!x||x.kind!=="paragraph")continue;let d=h,g=x,p=c,b=Pe(d,g,o,l);for(let{line:k,index:H}of b){if(H<p.fromLine||H>=p.toLine)continue;let M=U(d,k);if(M.pmStart===void 0||M.pmEnd===void 0)continue;let T=Math.max(M.pmStart,o),S=Math.min(M.pmEnd,l);if(T>=S)continue;let w=W(d,k,T),y=W(d,k,S),R=d.attrs?.indent,B=R?.left??0,A=R?.right??0,I=Math.max(0,c.width-B-A),E=G(d,k,w),C=G(d,k,y),F=d.attrs?.alignment??"left",P=0;F==="center"?P=Math.max(0,(I-k.width)/2):F==="right"&&(P=Math.max(0,I-k.width));let L=J(g,H)-J(g,p.fromLine),v=c.x+B+P+Math.min(E,C),Y=Math.max(1,Math.abs(C-E)),z=c.y+L;a.push({x:v,y:z+u,width:Y,height:k.lineHeight,pageIndex:s});}}if(c.kind==="table"){let m=ae(n,c.blockId);if(m===-1)continue;let h=n[m],x=i[m];if(!h||h.kind!=="table"||!x||x.kind!=="table")continue;let d=h,g=x,p=c,b=[],k=0;for(let y=0;y<g.rows.length;y++)b.push(Math.round(k)),k+=g.rows[y]?.height??0;b.push(Math.round(k));let H=p.headerRowCount??0,M=H>0&&p.continuesFromPrev?Y(g,H):0,T=(b[p.fromRow]??0)+(p.topClip??0),S=p.bottomClip!==void 0?Math.round(p.height):M+((b[p.toRow]??0)-T),w=y=>M+(y-T);for(let y=p.fromRow;y<p.toRow&&y<d.rows.length;y++){let R=d.rows[y],B=g.rows[y];if(!R||!B)continue;let A=b[y]??0,I=0;for(let E=0;E<R.cells.length;E++){let C=R.cells[E],F=B.cells[E];if(!C||!F)continue;let P=C.padding?.top??0,L=O(C.blocks,F.blocks,P);for(let v=0;v<C.blocks.length;v++){let Y=C.blocks[v],z=F.blocks[v];if(!Y||Y.kind!=="paragraph"||!z||z.kind!=="paragraph")continue;let X=Y,_e=z,Oe=L.lineTops[v]??[],Xe=Pe(X,_e,o,l);for(let{line:_,index:Ne}of Xe){let q=U(X,_);if(q.pmStart===void 0||q.pmEnd===void 0)continue;let se=Math.max(q.pmStart,o),ce=Math.min(q.pmEnd,l);if(se>=ce)continue;let Q=w(A+(Oe[Ne]??0));if(Q+_.lineHeight<=M||Q>=S)continue;let Ye=W(X,_,se),ze=W(X,_,ce),ue=G(X,_,Ye,F.width),fe=G(X,_,ze,F.width);a.push({x:p.x+I+Math.min(ue,fe),y:p.y+Q+u,width:Math.max(1,Math.abs(fe-ue)),height:_.lineHeight,pageIndex:s});}}I+=F.width;}}}if(c.kind==="image"){let m=c.pmStart??0;(c.pmEnd??m+1)>o&&m<l&&a.push({x:c.x,y:c.y+u,width:c.width,height:c.height,pageIndex:s});}}}return a}function ot(e,n,i,r,t=0){for(let o=Math.max(0,t);o<e.pages.length;o++){let l=e.pages[o],a=D(e,o);for(let s of l.fragments){if(s.kind==="paragraph"){let f=ae(n,s.blockId);if(f===-1)continue;let u=n[f],c=i[f];if(!u||u.kind!=="paragraph"||!c||c.kind!=="paragraph")continue;let m=u,h=c,x=s,d=m.pmStart??0,g=m.pmEnd??d;if(r<d||r>g)continue;for(let p=x.fromLine;p<x.toLine;p++){let b=h.lines[p];if(!b)continue;let k=U(m,b);if(!(k.pmStart===void 0||k.pmEnd===void 0)&&r>=k.pmStart&&r<=k.pmEnd){let H=W(m,b,r),M=m.attrs?.indent,T=M?.left??0,S=M?.right??0,w=Math.max(0,s.width-T-S),y=G(m,b,H),R=m.attrs?.alignment??"left",B=0;R==="center"?B=Math.max(0,(w-b.width)/2):R==="right"&&(B=Math.max(0,w-b.width));let A=J(h,p)-J(h,x.fromLine);return {x:s.x+T+B+y,y:s.y+A+a,height:b.lineHeight,pageIndex:o}}}}if(s.kind==="image"){let f=s.pmStart??0,u=s.pmEnd??f+1;if(r>=f&&r<=u){let c=r===f?0:s.width;return {x:s.x+c,y:s.y+a,height:s.height,pageIndex:o}}}}}return null}function rt(e){return e.length<=1?false:new Set(e.map(i=>i.pageIndex)).size>1}function it(e){let n=new Map;for(let i of e){let r=n.get(i.pageIndex)??[];r.push(i),n.set(i.pageIndex,r);}return n}function at(e){if(e.kind!=="paragraph")return  false;let n=e.attrs;return n?!!(n.borders?.top||n.borders?.bottom||n.spacingExplicit?.before||n.spacingExplicit?.after):false}function we(e){return Se(e)}function Se(e){let n=new Set;for(let i=1;i<e.length;i++){let r=e[i-1],t=e[i];r.kind==="table"&&t.kind==="paragraph"&&(t.runs.length>0||at(t)||n.add(i));}return e.map((i,r)=>{if(i.kind==="table")return lt(i);if(i.kind!=="paragraph")return i;let t=n.has(r),o=i.attrs?.spacingExplicit,l=i.attrs?.spacing?.before!=null,a=i.attrs?.spacing?.after!=null,s=l&&!o?.before,f=a&&!o?.after,u=s||f;if(!u&&!t)return i;let c=i.attrs;return u&&c?.spacing&&(c={...c,spacing:{...c.spacing,before:o?.before?c.spacing.before:void 0,after:o?.after?c.spacing.after:void 0}}),t&&(c={...c??{},suppressEmptyParagraphHeight:true}),{...i,attrs:c}})}function lt(e){let n=false,i=e.rows.map(r=>{let t=false,o=r.cells.map(l=>{let a=Se(l.blocks);return a.some((f,u)=>f!==l.blocks[u])?(t=true,{...l,blocks:a}):l});return t?(n=true,{...r,cells:o}):r});return n?{...e,rows:i}:e}function st(e){return e?.align??e?.alignment}function Be(e,n,i,r){let t=r.section==="header"?r.margins.header??48:r.pageSize.h-(r.margins.footer??48)-i,o=e.position?.vertical;if(!o)return n;let l=st(o),a=o.posOffset!==void 0?f$1(o.posOffset):void 0;if(o.relativeTo==="page"){if(a!==void 0)return a-t;if(l==="top")return -t;if(l==="bottom")return r.pageSize.h-e.height-t;if(l==="center")return (r.pageSize.h-e.height)/2-t}if(o.relativeTo==="margin"){let s=r.margins.top,f=r.pageSize.h-r.margins.top-r.margins.bottom;if(a!==void 0)return s+a-t;if(l==="top")return s-t;if(l==="bottom")return s+f-e.height-t;if(l==="center")return s+(f-e.height)/2-t}return a!==void 0?n+a:n}function Re(e){switch(e.kind){case "paragraph":case "table":return  true;case "image":return !e.anchor?.isAnchored;case "textBox":return e.displayMode===void 0||e.displayMode==="inline";default:return  false}}function ct(e){return e?e.kind==="paragraph"||e.kind==="table"?e.totalHeight:e.kind==="image"||e.kind==="textBox"?e.height:0:0}function Ie(e,n,i,r){let t=0,o=0,l=0;for(let a=0;a<e.length;a++){let s=e[a],f=n[a];if(!(!s||!f)){if(s.kind==="paragraph"&&f.kind==="paragraph"){let u=l,c=u+f.totalHeight;t=Math.min(t,u),o=Math.max(o,c);for(let m of s.runs){if(m.kind!=="image"||!m.position)continue;let h=Be(m,u,i,r);t=Math.min(t,h),o=Math.max(o,h+m.height);}l=c;}else if(s.kind==="table"&&f.kind==="table"){let u=l+f.totalHeight;t=Math.min(t,l),o=Math.max(o,u),l=u;}else if(s.kind==="image"&&f.kind==="image"){let u=l+f.height;t=Math.min(t,l),o=Math.max(o,u),l=u;}else if(s.kind==="textBox"&&f.kind==="textBox"){let u=l+f.height;t=Math.min(t,l),o=Math.max(o,u),s.displayMode!=="float"&&(l=u);}}}return {visualTop:t,visualBottom:o}}function ut(e,n,i,r){if(!e||!e.content||e.content.length===0)return;let t=b(e.content,{styles:r.styles??void 0,theme:r.theme??null,defaultTabStopTwips:r.defaultTabStopTwips??null});return Ce(t,n,i,r)}function Ce(e,n,i,r){let t=c(e,{theme:r.theme??void 0});if(t.length===0)return;let o=we(t),l=r.measureBlocks(o,n),a=0,s=0;for(let c=0;c<o.length;c++){let m=ct(l[c]);a+=m,Re(o[c])&&(s+=m);}let{visualTop:f,visualBottom:u}=Ie(o,l,a,i);return {blocks:o,measures:l,height:a,flowHeight:s,visualTop:f,visualBottom:u}}var K={header:null,footer:null};function ft(){K.header=null,K.footer=null;}function Ee(e,n){let i=n.querySelectorAll(`.layout-page-${e}`);if(i.length===0)return null;let r=n.defaultView,t=r?r.innerHeight/2:0,o=i[0],l=1/0;for(let c of Array.from(i)){let m=c.getBoundingClientRect(),h=Math.abs((m.top+m.bottom)/2-t);h<l&&(l=h,o=c);}let a=K[e];if(a&&a.host===o&&a.host.isConnected)return a;let s=Array.from(o.querySelectorAll("span[data-pm-start][data-pm-end]")),f=Array.from(o.querySelectorAll("[data-pm-start][data-pm-end]")),u={host:o,spans:s,ranged:f};return K[e]=u,u}function dt(e,n,i=globalThis.document){let r=e.state.selection;if(!r.empty)return null;let t=r.head,o=Ee(n,i);if(!o)return null;let{host:l,spans:a}=o;for(let d of a){let g=Number(d.dataset.pmStart),p=Number(d.dataset.pmEnd);if(!(!Number.isFinite(g)||!Number.isFinite(p))&&t>=g&&t<=p){let b=l.ownerDocument.createRange(),k=l.ownerDocument.createTreeWalker(d,NodeFilter.SHOW_TEXT),H=t-g,M=k.nextNode();for(;M;){let w=M.data.length;if(H<=w){try{b.setStart(M,H),b.setEnd(M,H);let y=b.getClientRects()[0]??b.getBoundingClientRect();if(y&&y.height>0)return {top:y.top,left:y.left,height:y.height}}catch{}break}H-=w,M=k.nextNode();}let T=d.getBoundingClientRect(),S=(t-g)/Math.max(1,p-g);return {top:T.top,left:T.left+T.width*S,height:T.height}}}let s=l.querySelector(`[data-pm-start="${t}"]`);if(s){let d=s.getBoundingClientRect();return {top:d.top,left:d.left+1,height:d.height||16}}let f=o.ranged,u=null,c=1/0;for(let d of f){let g=Number(d.dataset.pmStart),p=Number(d.dataset.pmEnd);if(!Number.isFinite(g)||!Number.isFinite(p)||t<g||t>p)continue;let b=p-g;b<c&&(c=b,u=d);}if(u){let d=u.getBoundingClientRect(),g=Number(u.dataset.pmEnd),p=t>=g;return {top:d.top,left:p?d.right:d.left+1,height:d.height||16}}let m=null,h=-1/0;for(let d of f){let g=Number(d.dataset.pmStart);Number.isFinite(g)&&(g>t||g>h&&(h=g,m=d));}if(m){let d=m.getBoundingClientRect();return {top:d.top,left:d.right,height:d.height||16}}let x=l.getBoundingClientRect();return {top:x.top+2,left:x.left+2,height:16}}function mt(e,n,i=globalThis.document){let r=e.state.selection;if(r.empty)return [];let t=r.from,o=r.to,l=[],a=Ee(n,i);if(!a)return l;let{host:s,spans:f}=a;for(let u of f){let c=Number(u.dataset.pmStart),m=Number(u.dataset.pmEnd);if(!Number.isFinite(c)||!Number.isFinite(m)||m<=t||c>=o)continue;if(u.classList.contains("layout-run-tab")){let p=u.getBoundingClientRect();l.push({top:p.top,left:p.left,width:p.width,height:p.height});continue}let h=null;if(u.firstChild?.nodeType===Node.TEXT_NODE?h=u.firstChild:u.firstChild?.nodeType===Node.ELEMENT_NODE&&u.firstChild.tagName==="A"&&u.firstChild.firstChild?.nodeType===Node.TEXT_NODE&&(h=u.firstChild.firstChild),!h)continue;let x=Math.max(0,t-c),d=Math.min(h.length,o-c);if(x>=d)continue;let g=s.ownerDocument.createRange();g.setStart(h,x),g.setEnd(h,d);for(let p of Array.from(g.getClientRects()))l.push({top:p.top,left:p.left,width:p.width,height:p.height});}return l}function Le(e){return e?e.flowHeight??e.height:0}function gt(e){let{pageSize:n,margins:i,finalMargins:r,bodyBlocks:t,headers:o,footers:l,warn:a}=e,s=i.header??48,f=i.footer??48,u=i.top-s,c=i.bottom-f,m=Math.max(0,...(o??[]).map(Le)),h=Math.max(0,...(l??[]).map(Le)),x=m>u,d=h>c;if(!x&&!d)return {margins:i,finalMargins:r};let g=Math.max(0,n.h-24),p=false,b=M=>{let T={...M};return x&&(T.top=Math.max(M.top,s+m)),d&&(T.bottom=Math.max(M.bottom,f+h)),T.top+T.bottom>g&&(p=true,T.bottom=Math.max(0,Math.min(T.bottom,g-T.top)),T.top+T.bottom>g&&(T.top=Math.max(0,g-T.bottom))),T},k=b(i),H=b(r);if(t)for(let M of t){if(M.kind!=="sectionBreak")continue;let T=M;T.margins&&(T.margins=b(T.margins));}return p&&a&&a(`[layout] header/footer content exceeds page height; clamping margins to preserve a content area. pageHeight=${Math.round(n.h)} headerBand=${Math.round(m)} footerBand=${Math.round(h)} top=${Math.round(k.top)} bottom=${Math.round(k.bottom)}`),{margins:k,finalMargins:H}}var Ae=816,De=1056,V=96,le=48;function $(e){return Math.round(e/1440*96)}function N(e,n){return e!=null?$(e):n}function ht(e){return {w:e?.pageWidth?$(e.pageWidth):Ae,h:e?.pageHeight?$(e.pageHeight):De}}function pt(e){return {top:N(e?.marginTop,V),right:N(e?.marginRight,V),bottom:N(e?.marginBottom,V),left:N(e?.marginLeft,V),header:N(e?.headerDistance,le),footer:N(e?.footerDistance,le)}}function bt(e,n){let i={header:null,footer:null,firstHeader:null,firstFooter:null};if(!e?.package)return i;let r=e.package.headers,t=e.package.footers,o=null,l=null,a=null,s=null;if(r&&n?.headerReferences){let f=n.headerReferences.find(c=>c.type==="default");f?.rId&&(o=r.get(f.rId)??null);let u=n.headerReferences.find(c=>c.type==="first");u?.rId&&(a=r.get(u.rId)??null);}if(t&&n?.footerReferences){let f=n.footerReferences.find(c=>c.type==="default");f?.rId&&(l=t.get(f.rId)??null);let u=n.footerReferences.find(c=>c.type==="first");u?.rId&&(s=t.get(u.rId)??null);}return n?.titlePg||(!o&&a&&(o=a),!l&&s&&(l=s)),{header:o,footer:l,firstHeader:a,firstFooter:s}}function xt(e){let n=e?.columnCount??1;if(n<=1)return;let i=$(e?.columnSpace??720);return {count:n,gap:i,equalWidth:e?.equalWidth??true,separator:e?.separator}}function ve(e){let n=e.pageSize.w-e.margins.left-e.margins.right,i=e.columns;return !i||i.count<=1?n:Math.floor((n-(i.count-1)*i.gap)/i.count)}function Tt(e,n,i){let{configs:r,breakIndices:t}=W$1(e,n,i),o=0,l=[];for(let a=0;a<e.length;a++)l.push(ve(r[o]??n)),o<t.length&&a===t[o]&&o++;return l}export{ut as A,Ce as B,ft as C,dt as D,mt as E,gt as F,Ae as G,De as H,V as I,le as J,$ as K,ht as L,pt as M,bt as N,xt as O,ve as P,Tt as Q,be as a,We as b,ne as c,D as d,Ge as e,xe as f,Ve as g,Te as h,$e as i,qe as j,je as k,Je as l,ie as m,Me as n,Ze as o,ye as p,et as q,tt as r,nt as s,ot as t,rt as u,it as v,we as w,Be as x,Re as y,Ie as z};