@reviseio/engine 0.0.0-stage → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/FONT-LICENSE-HAN-EXT-B.txt +91 -0
  3. package/FONT-LICENSE-KATEX.txt +95 -0
  4. package/FONT-LICENSE-LIBERATION.txt +102 -0
  5. package/FONT-LICENSE-NOTO-MULTILINGUAL.txt +93 -0
  6. package/FONT-LICENSE-NOTO-SANS-SC.txt +93 -0
  7. package/FONT-LICENSE-NOTO.txt +94 -0
  8. package/FONT-LICENSE-SOURCE-CODE-PRO.txt +94 -0
  9. package/FONT-LICENSE-SOURCE-SERIF-4.txt +93 -0
  10. package/LICENSE +141 -0
  11. package/README.md +11 -2
  12. package/THIRD-PARTY-NOTICES.md +3376 -0
  13. package/assets/historyMaterializeWorker-Kl0syEbc.js +618 -0
  14. package/chunks/AgentHtmlConverter-BnK7NaYA.js +379 -0
  15. package/chunks/AgentPageRenderViews-BTLjPZJQ.js +2 -0
  16. package/chunks/AgentPageRenderer-DLwq6nAa.js +180 -0
  17. package/chunks/BidiText-Bkp4Y90s.js +160 -0
  18. package/chunks/BlockDiff-BdlcKY-t.js +42 -0
  19. package/chunks/CanvasRenderer-Bqsj1S0p.js +110 -0
  20. package/chunks/ColorParserFull-BKH72fK8.js +446 -0
  21. package/chunks/DocumentCompare-BqyiP87r.js +6 -0
  22. package/chunks/DocumentLayout-CsU5MR-3.js +12 -0
  23. package/chunks/DocumentLayoutEngine-7iOYvyVb.js +218 -0
  24. package/chunks/DocumentMutator-DIrZBuLr.js +13 -0
  25. package/chunks/DocumentScrubber-Cz8Q05hF.js +21 -0
  26. package/chunks/DocumentSession-lXSXqua5.js +1 -0
  27. package/chunks/DocumentStylesheet-CEEt18sr.js +7 -0
  28. package/chunks/DocxConverter-BfDw7777.js +1236 -0
  29. package/chunks/DocxGraft-D0uCnGCo.js +8 -0
  30. package/chunks/HorizontalRuleOrnaments-gmUZ3R7Q.js +3 -0
  31. package/chunks/HtmlConverter-7Xj_g9Jr.js +267 -0
  32. package/chunks/ListNumbering-Qlu6AuRZ.js +23 -0
  33. package/chunks/MarkdownConverter-cnW_oePY.js +57 -0
  34. package/chunks/MathRenderer-Bz9WEVvF.js +68 -0
  35. package/chunks/OdtConverter-GwRDMnwS.js +125 -0
  36. package/chunks/OfficeImportShared-nlMtIUni.js +30 -0
  37. package/chunks/PageNumeralFonts-BWzI061X.js +5 -0
  38. package/chunks/ParagraphDiffAnalysis-DrmStvmz.js +36 -0
  39. package/chunks/PdfConverter-yOlWiVIj.js +457 -0
  40. package/chunks/RtfConverter--wLd0qrw.js +186 -0
  41. package/chunks/TableBorders-C5pNsuxP.js +32 -0
  42. package/chunks/TableGrid-DbroRucl.js +12 -0
  43. package/chunks/TextFileDecoder--rsVs3NR.js +9 -0
  44. package/chunks/TxtConverter-BoRVCDZw.js +14 -0
  45. package/chunks/Typography-DAGM5kfI.js +28 -0
  46. package/chunks/UnicodeUtils-CXtusU4g.js +10 -0
  47. package/chunks/XmlConverter-CO8Z28dX.js +55 -0
  48. package/chunks/_commonjsHelpers-DaMA6jEr.js +2 -0
  49. package/chunks/_revise-sdk-lazy-harfbuzz-CDWdjF9f.js +1 -0
  50. package/chunks/base64-Di1bxoXD.js +1 -0
  51. package/chunks/browser-module-CFmqfGkE.js +1791 -0
  52. package/chunks/bundle.min-DRpfgV69.js +782 -0
  53. package/chunks/capture-Dtinb4bY.js +11 -0
  54. package/chunks/carrier-RNy67HN4.js +6 -0
  55. package/chunks/chromeImageLayout-bgHYmqTp.js +18 -0
  56. package/chunks/engine-TnK8N-gT.js +520 -0
  57. package/chunks/footnoteFlatten-BcKaWzVs.js +6 -0
  58. package/chunks/graftExport-DxAALMHp.js +104 -0
  59. package/chunks/html2canvas.esm-CntiHiYW.js +997 -0
  60. package/chunks/index-BWdRWxoH.js +1807 -0
  61. package/chunks/index-CTti7wRd.js +1002 -0
  62. package/chunks/index.es-CI0QPo8w.js +780 -0
  63. package/chunks/jspdf.es.min-DU74zN8b.js +1792 -0
  64. package/chunks/jszip.min-CPW0h1Kx.js +476 -0
  65. package/chunks/katex-DWj8TvwO.js +1462 -0
  66. package/chunks/pdf-BLWDCiFF.js +1828 -0
  67. package/chunks/purify.es-BwLardii.js +107 -0
  68. package/chunks/serverDocumentSession-BmYdjC6e.js +1011 -0
  69. package/chunks/signatures-CU2LMLBp.js +21 -0
  70. package/chunks/suggestionAuthorship-B-IuLQlE.js +1 -0
  71. package/chunks/web-tree-sitter-BXGZGnNj.js +2 -0
  72. package/chunks/xmlScan-DXjt2cTS.js +8 -0
  73. package/engine.d.ts +179 -0
  74. package/engine.js +3 -0
  75. package/package.json +64 -4
  76. package/serverToolContract.d.ts +420 -0
  77. package/serverToolInputs.generated.d.ts +264 -0
@@ -0,0 +1,218 @@
1
+ import{getLayoutMarginLeft as mt,getLayoutMarginRight as ne,getLayoutMarginBottom as kt,getLayoutMarginTop as Wt,getLayoutBlockSpacingPx as Ve,PAGINATION_EPSILON as rt,createFlowWindowTable as Je,getLayoutPageStep as xe,
2
+ getLayoutFootnoteInset as ke,declaresOwnSpaceBefore as qe,getLayoutPageContentTop as Qe}from"./DocumentLayout-CsU5MR-3.js";import{ap as ye,ae as Me,bt as Yt,bC as Ke,R as we,h as tn,e as en,t as nn,r as on,
3
+ bp as rn,br as an,a4 as sn,bw as ln,bx as oe}from"./engine-TnK8N-gT.js";import{L as cn,i as gn,j as un}from"./Typography-DAGM5kfI.js";import{a as dn}from"./chromeImageLayout-bgHYmqTp.js";import{t as hn,
4
+ u as pn,a as fn,l as mn,m as bn,d as Ie,s as xn,v as kn,x as _t,f as yn,i as Se,h as Mn}from"./index-CTti7wRd.js";import{v as Ye}from"./CanvasRenderer-Bqsj1S0p.js";import{b as wn,c as In}from"./TableGrid-DbroRucl.js";
5
+ import{r as Sn,t as Yn}from"./TableBorders-C5pNsuxP.js";const Be=48,Bn=10;function Ne(e,t,n,r,s){const i=(n.columnCount??1)>1?Math.max(1,n.pageWidth-mt(n)-ne(n)):n.availableWidth,a=i/3,u=s??e.children,
6
+ d=[0,1,2].map(S=>{const b=u[S];if(!b)return Be;if(b.borders)return i;const k=hn(b,t,n,r)+Bn;return Math.max(Be,Math.min(k,i))}),p=[a,a,a],B=d.map((S,b)=>Math.max(0,S-p[b])),x=d.map((S,b)=>Math.max(0,p[b]-
7
+ S)),y=B.reduce((S,b)=>S+b,0),v=x.reduce((S,b)=>S+b,0);if(y>0&&v>0){const S=Math.min(y,v);for(let b=0;b<3;b++)B[b]>0?p[b]+=B[b]/y*S:x[b]>0&&(p[b]-=x[b]/v*S)}const F=[0,1,2].map(S=>{const b=u[S];return!b||
8
+ !b.children.some(k=>k.type==="text"&&k.text!=="")});for(let S=0;S<3;S++){let b=d[S]-p[S];if(!(b<=0||F[S]))for(let k=0;k<3&&b>0;k++){if(k===S||!F[k])continue;const E=Math.min(p[k],b);p[k]-=E,p[S]+=E,b-=
9
+ E}}return[p[0],p[1],p[2]]}function Nn(e){const t=pn();if(!t)return e;const n=t.mode==="accept"?"delete":"insert",r=u=>t.suggestionIds.includes(u);let s=null;for(const u of e){const{id:d,kind:p}=ve(u);
10
+ if(!d||!r(d)||p!=="insert"&&p!=="delete")continue;s??(s=new Map);const B=s.get(d)??new Set;B.add(p),s.set(d,B)}if(!s)return e;const i=u=>s.get(u)?.size===2;let a=null;for(let u=0;u<e.length;u++){const d=e[u],
11
+ p=vn(d,n,r,i);p&&!a?a=e.slice(0,u):!p&&a&&a.push(d)}return a??e}function ve(e){const t=e,n=t.structuralSuggestionId??t.suggestionId;return{id:typeof n=="string"&&n.length>0?n:void 0,kind:t.structuralSuggestionKind??
12
+ t.diffState}}function vn(e,t,n,r){const{id:s,kind:i}=ve(e);if(!s||i!==t||!n(s))return!1;const a=Pn(e,s);return a==="block-insert"||a==="block-delete"?a===(t==="delete"?"block-delete":"block-insert"):a!==
13
+ null&&a!=="inline-text"||!Pe(e)&&!r(s)?!1:Fe(e,s,t)}function Pn(e,t){const n=e.structuralSuggestionRecord;if(typeof n!="string")return null;try{const r=JSON.parse(n);return r.id!==t||typeof r.type!="s\
14
+ tring"||r.blockId!==void 0&&r.blockId!==e.id?null:r.type}catch{return null}}function Pe(e){if(!e||typeof e!="object")return!1;const t=e;return t.type==="text"?typeof t.text=="string"&&t.text.length>0:
15
+ typeof t.type=="string"&&ye(t.type)?!1:Array.isArray(t.children)&&t.children.some(Pe)}function Fe(e,t,n){if(!e||typeof e!="object")return!0;const r=e;if(r.type==="text"){if(typeof r.text=="string"&&r.
16
+ text.length===0)return!0;const i=r.marks??{};return i.suggestionId===t&&!!(n==="delete"?i.deletion:i.insertion)}const s=r.structuralSuggestionId??r.suggestionId;return typeof s=="string"&&s&&s!==t?!1:
17
+ typeof r.type=="string"&&ye(r.type)?!0:Array.isArray(r.children)?r.children.every(i=>Fe(i,t,n)):!0}function re(e){if(e.type!=="paragraph")return{keepNext:!1,keepLines:!1,widowControl:!1};const t=e;return{
18
+ keepNext:t.keepNext??!!t.heading,keepLines:!!t.keepLines,widowControl:t.widowControl!==!1}}const ae=3;function Fn(e){if(!e)return;const{lineRange:t,charRange:n,unitRange:r,fragmentIndex:s,pageNumber:i,
19
+ backgroundFill:a,data:u}=e;return{lineRange:t,charRange:n,unitRange:r,fragmentIndex:s,pageNumber:i,...a?{backgroundFill:a}:{},data:u}}function Tn(e,t){const n=[];let r=[];for(const s of e)r.push(s),s.
20
+ type==="section-break"&&(n.push({blocks:r,rawSettings:s.layout}),r=[]);return n.push({blocks:r,rawSettings:t}),n}function Te(e,t,n){if(!n)return{...e};const r=we(t,n),{pageWidth:s,pageHeight:i}=en(r),
21
+ a=r.columnCount,u=nn(r.columnGapTwips),d=Math.max(1,s-r.marginLeftPx-r.marginRightPx);return{...e,pageWidth:s,pageHeight:i,pageMargin:r.marginLeftPx,pageMarginTop:r.marginTopPx,pageMarginRight:r.marginRightPx,
22
+ pageMarginBottom:r.marginBottomPx,pageMarginLeft:r.marginLeftPx,availableWidth:Ie(d,a,u),columnCount:a,columnGapPx:u,textStartY:r.marginTopPx,hyphenationEnabled:r.hyphenationEnabled,lineNumbering:r.lineNumbering}}
23
+ const Hn=32,Ln=ln.paddingPx;function He(e){return e.children.filter(t=>t.type==="text").reduce((t,n)=>t+n.text.length,0)}function Cn(e,t){const n=e.children.reduce((a,u,d)=>a+He(u)+(d<e.children.length-
24
+ 1?1:0),0),r=Math.max(0,Math.min(t,n));let s=0,i=0;for(let a=0;a<e.children.length;a++){const u=e.children[a],d=He(u),p=_t(u),B=p.visibleText.length;if(r<=s+d)return i+p.toVisibleOffset(r-s);if(s+=d,i+=
25
+ B,a<e.children.length-1){if(r<=s+1)return i+(r-s);s+=1,i+=1}}return i}function Rn(e,t,n){const r=t.getCharacterOffset(e,n);return e.type==="paragraph"?_t(e).toVisibleOffset(r):e.type==="list"?Cn(e,r):
26
+ r}function Wn(e,t,n){const r=fn(),s=(o,l)=>({doc:e,layout:o,textContext:t,registry:r,blocks:[],fragments:[],currentY:l,currentPage:1,totalHeight:l,pageStep:o.pageless?0:o.pageHeight+o.pageSpacing,nextBlockIndex:0,
27
+ pageBreakListeners:[],suppressTopSpacingForNextBlock:!1}),i=(o,l,h=!1)=>{const g=Nn(o),c=Tn(g,e.pageLayout),f=c.map((A,xt)=>xt===c.length-1?Te(l,e.pageLayout,e.pageLayout):Te(l,e.pageLayout,A.rawSettings)),
28
+ w=f.some(A=>(A.columnCount??1)>1);if(c.length===1&&!w||l.pageless){const A=s(l,Wt(l));return l.lineNumbering&&!l.pageless&&(A.lineNumberMarks=[]),A.trackLineExtents=h,Rt({state:A,blocks:g,x:mt(l),layoutForLevel:l,
29
+ suppressTopSpacingForFirstBlock:!0}),A.totalHeight=A.currentY,l.pageless||(A.sectionRuntime={runs:[{blocks:g,rawSettings:e.pageLayout}],layouts:[l],startPageIndexes:[0],sectionStartTops:[0]}),A}const Y=[],
30
+ H=[],m=s(f[0],0);m.blocks=[],m.fragments=[],m.currentY=0,m.totalHeight=0,m.currentPage=1,m.trackLineExtents=h,f.some(A=>A.lineNumbering)&&(m.lineNumberMarks=[]);let j=-1,K=0,I=null,U=0,gt=!1;const $=()=>{
31
+ gt||(gt=!0,console.warn("Column layout projection clamped a fragment outside its pagination window; a column may render overflowing content."))},Lt=A=>{const xt=A.blocks[A.blocks.length-1];return xt?.
32
+ type==="section-break"?xt:void 0};return c.forEach((A,xt)=>{const W=f[xt],tt=xt>0?Lt(c[xt-1]):void 0,Ft=xt>0&&tt?.breakType==="continuous",L=mn(Ft,I&&{width:I.pageWidth,height:I.pageHeight},{width:W.pageWidth,
33
+ height:W.pageHeight}),ut=L?j:j+1,et=L?K:I?K+I.pageHeight+I.pageSpacing:0,Dt=L?bn(U,Ve(W,0),et,Wt(W)):et+Wt(W);W.sectionStartY=et,W.sectionFirstPageIndex=ut,Y.push(ut),H.push(et);const Tt=Math.max(1,Math.
34
+ round(W.columnCount??1)),dt=Math.max(0,W.columnGapPx??Ke),Xt=Ie(W.pageWidth-mt(W)-ne(W),Tt,dt),$t=yn(Xt,dt),Et=W.pageHeight+W.pageSpacing,wt=Wt(W),ce=N=>{const _=new Map,nt=z=>{const G=Math.floor(z/Tt),
35
+ C=z%Tt,ot=ut+G,ft=G===0?Dt-et:wt,Ct=ke(W,ot),Ot=W.pageHeight-kt(W)-Ct,St=N?.pageOffset===G?Math.min(Ot,ft+N.height):Ot;return{top:z*Et+ft,bottom:z*Et+St,full:N?.pageOffset!==G&&ft<=wt&&Ct<=0,pageIndex:G,
36
+ columnIndex:C,actualContentTop:et+G*Et+ft}},P=z=>{let G=_.get(z);return G||(G=nt(z),_.set(z,G)),G};return{at:P,indexForY:z=>{if(P(0).top>z+rt)return 0;let G=1;for(;P(G).top<=z+rt;)G*=2;let C=G>>1,ot=C;
37
+ for(;C<=G;){const ft=C+G>>1;P(ft).top<=z+rt?(ot=ft,C=ft+1):G=ft-1}return ot}}},$e=new Map,ge=(N,_)=>{const nt={...W,sectionStartY:0,sectionFirstPageIndex:0,availableWidth:Xt,columnCount:Tt,columnGapPx:dt,
38
+ flowWindows:N},P=s(nt,N.at(0).top);P.nextBlockIndex=m.nextBlockIndex,P.trackLineExtents=h,P.boundsMemo=$e,W.lineNumbering&&(P.lineNumberMarks=[]);const z=_?.resume;if(z){const{snapshot:C,from:ot}=z;P.
39
+ blocks=ot.blocks.slice(0,C.blocksLen),P.fragments=ot.fragments.slice(0,C.fragmentsLen),P.currentY=C.currentY,P.currentPage=C.currentPage,P.totalHeight=C.totalHeight,P.nextBlockIndex=C.nextBlockIndex,P.
40
+ suppressTopSpacingForNextBlock=C.suppressTopSpacingForNextBlock,P.lastLineTail=C.lastLineTail,P.lineNumberMarks&&ot.lineNumberMarks&&(P.lineNumberMarks=ot.lineNumberMarks.slice(0,C.lineNumberMarksLen))}
41
+ const G=_?.recordSnapshots;return Rt({state:P,blocks:z?A.blocks.slice(z.snapshot.blockCount):A.blocks,x:mt(W),layoutForLevel:nt,suppressTopSpacingForFirstBlock:!z,onBlockLaidOut:G?C=>{G.push({blockCount:C+
42
+ 1,blocksLen:P.blocks.length,fragmentsLen:P.fragments.length,currentY:P.currentY,currentPage:P.currentPage,totalHeight:P.totalHeight,nextBlockIndex:P.nextBlockIndex,suppressTopSpacingForNextBlock:P.suppressTopSpacingForNextBlock,
43
+ lastLineTail:P.lastLineTail,lineNumberMarksLen:P.lineNumberMarks?.length??0})}:void 0}),P.totalHeight=P.currentY,P},Kt=(N,_)=>N.indexForY(Math.max(_.currentY-rt,N.at(0).top)),_e=Lt(A)?.breakType==="co\
44
+ ntinuous",ue=xn(Tt,_e)&&A.blocks.length>0;let vt=ce();const de=[];let Ht=ge(vt,ue?{recordSnapshots:de}:void 0),te=Kt(vt,Ht);if(ue){const N=vt.at(te).pageIndex,_=N*Tt,nt=vt.at(_),P=Math.max(1,nt.bottom-
45
+ nt.top),z=vt.at(Math.max(0,_-1)).top;let G;for(const St of de)if(St.currentY<z-rt)G=St;else break;const C=G?{resume:{snapshot:G,from:Ht}}:void 0;let ot=1,ft=Math.ceil(P),Ct=Ht,Ot=vt;for(let St=0;St<11&&
46
+ ot<=ft;St++){const jt=Math.ceil((ot+ft)/2),Vt=ce({pageOffset:N,height:jt}),be=ge(Vt,C),Ze=Kt(Vt,be);Vt.at(Ze).pageIndex<=N?(Ct=be,Ot=Vt,ft=jt-1):ot=jt+1}Ht=Ct,vt=Ot,te=Kt(vt,Ht)}const zt=N=>{const _=vt.
47
+ indexForY(N),nt=vt.at(_);return{windowIndex:_,window:nt,xOffset:nt.columnIndex*$t,y:nt.actualContentTop+Math.max(0,N-nt.top),pageNumber:ut+nt.pageIndex+1}},Zt=[],he=new Map;for(const N of Ht.fragments){
48
+ const _=N.bounds.y,nt=_+N.bounds.height,P=N.lineExtents;let z=0,G=_,C=!1;for(;G<nt-rt||!C;){const ot=zt(G),ft=Math.min(nt,ot.window.bottom),Ct=Math.max(0,ft-G),Ot=ft>=nt-rt||Ct<=0;Ct<=0&&N.bounds.height>
49
+ rt&&$();let St;if(P)for(St=[];z<P.length&&(Ot||P[z].bottom<=ft+rt);)St.push({charEnd:P[z].charEnd,bottom:ot.y+(P[z].bottom-G)}),z+=1;const jt=he.get(N.blockIndex)??0;if(Zt.push({...N,fragmentIndex:jt,
50
+ bounds:{...N.bounds,x:N.bounds.x+ot.xOffset,y:ot.y,height:Ct>0?Ct:N.bounds.height},pageNumber:ot.pageNumber,lineExtents:St&&St.length>0?St:void 0}),he.set(N.blockIndex,jt+1),C=!0,Ot)break;G=vt.at(ot.windowIndex+
51
+ 1).top}}const ee=new Map;for(const N of Zt){const _=ee.get(N.blockIndex)??[];_.push(N),ee.set(N.blockIndex,_)}const Ue=Ht.blocks.map(N=>{const _=ee.get(N.blockIndex)??[];if(_.length===0){const C=zt(N.
52
+ bounds.y);return{...N,bounds:{...N.bounds,x:N.bounds.x+C.xOffset,y:C.y},pageNumber:C.pageNumber}}const nt=Math.min(..._.map(C=>C.bounds.x)),P=Math.min(..._.map(C=>C.bounds.y)),z=Math.max(..._.map(C=>C.
53
+ bounds.x+C.bounds.width)),G=Math.max(..._.map(C=>C.bounds.y+C.bounds.height));return{...N,bounds:{...N.bounds,x:nt,y:P,width:z-nt,height:G-P},pageNumber:_[0].pageNumber}});if(m.blocks.push(...Ue),m.fragments.
54
+ push(...Zt),m.nextBlockIndex=Ht.nextBlockIndex,m.lineNumberMarks!==void 0&&Ht.lineNumberMarks)for(const N of Ht.lineNumberMarks){const _=zt(N.y);m.lineNumberMarks.push({...N,y:_.y,pageNumber:_.pageNumber})}
55
+ const pe=vt.at(te).pageIndex;j=ut+pe,K=et+pe*Et,I=W;const ze=j+1,fe=Zt.filter(N=>N.pageNumber===ze).map(N=>N.bounds.y+N.bounds.height),me=zt(Ht.currentY);U=Math.max(me.y,...fe.length>0?fe:[me.y]),m.currentY=
56
+ U,m.totalHeight=Math.max(m.totalHeight,U),m.currentPage=Math.max(m.currentPage,j+1),m.layout=W,m.pageStep=Et}),m.sectionRuntime={runs:c,layouts:f,startPageIndexes:Y,sectionStartTops:H},m},a=(o,l)=>{const h=o.
57
+ sectionRuntime;if(!h)return n;let g=h.startPageIndexes.length-1;for(;g>0&&l<h.startPageIndexes[g];)g--;return h.layouts[g]},u=(o,l)=>{const h=o.sectionRuntime;if(!h)return l*(n.pageHeight+n.pageSpacing);
58
+ let g=h.startPageIndexes.length-1;for(;g>0&&l<h.startPageIndexes[g];)g--;const c=h.layouts[g],f=c.pageHeight+c.pageSpacing;return h.sectionStartTops[g]+(l-h.startPageIndexes[g])*f},d=(o,l)=>{const h=o.
59
+ sectionRuntime;if(!h)return Math.max(0,Math.floor((l-n.textStartY)/(n.pageHeight+n.pageSpacing)));let g=h.startPageIndexes.length-1;for(;g>0&&l<h.sectionStartTops[g];)g--;const c=h.layouts[g],f=c.pageHeight+
60
+ c.pageSpacing;return h.startPageIndexes[g]+Math.max(0,Math.floor((l-h.sectionStartTops[g]-c.textStartY)/f))},p=(o,l)=>{const h=o.sectionRuntime;if(!h)return;const g=h.layouts.length,c=h.layouts.map((H,m)=>{
61
+ const j=h.runs[m].rawSettings,K=we(e.pageLayout,j);return{layout:H,raw:j,resolved:K,step:H.pageHeight+H.pageSpacing,marginTop:Wt(H),marginRight:ne(H),marginBottom:kt(H),marginLeft:mt(H)}}),f=[];let w=0,
62
+ Y=0;for(let H=0;H<l;H++){for(;w<g-1&&H>=h.startPageIndexes[w+1];)w++;const m=c[w];H===0||H===h.startPageIndexes[w]&&(w<g-1?m.raw?.pageNumberStart!==void 0:e.pageLayout?.pageNumberRestart===!0)?Y=m.resolved.
63
+ pageNumberStart:Y+=1,f.push({pageIndex:H,sectionIndex:w,pageTop:h.sectionStartTops[w]+(H-h.startPageIndexes[w])*m.step,pageWidth:m.layout.pageWidth,pageHeight:m.layout.pageHeight,marginTop:m.marginTop,
64
+ marginRight:m.marginRight,marginBottom:m.marginBottom,marginLeft:m.marginLeft,showPageNumbers:m.resolved.showPageNumbers,pageNumberPosition:m.resolved.pageNumberPosition,renderedPageNumber:Y,pageNumberFormat:m.
65
+ resolved.pageNumberFormat,lineNumbering:m.resolved.lineNumbering,pleadingGrid:m.resolved.pleadingGrid,pageBorders:m.resolved.pageBorders,sectionFirstPage:H===h.startPageIndexes[w],...e.chromeImages?.length&&
66
+ !n.pageless?{chromeImages:dn({chrome:e.chrome??[],records:e.chromeImages,pageNumber:H+1,isFirstPage:H===0,sectionIndex:w,pageWidth:m.layout.pageWidth,pageHeight:m.layout.pageHeight,marginTop:m.marginTop,
67
+ marginRight:m.marginRight,marginBottom:m.marginBottom,marginLeft:m.marginLeft})}:{}})}return f},B=[...e.notes??[],...e.children.filter(o=>o.type==="footnote")],x=(e.chrome?.length??0)>0;if(B.length===
68
+ 0&&!x){const o=i(e.children,n),l=Math.max(1,o.currentPage,Ut(o));return{blocks:o.blocks,fragments:o.fragments,totalHeight:o.totalHeight,pageCount:l,pageGeometries:p(o,l),...o.lineNumberMarks!==void 0?
69
+ {lineNumberMarks:o.lineNumberMarks}:{}}}const y=e.children.filter(o=>o.type!=="footnote"&&o.type!=="header-footer"),v=[],F=o=>{if(!o||typeof o!="object")return;if(Array.isArray(o)){o.forEach(F);return}
70
+ const l=o;l.type!=="footnote"&&(l.marks?.footnoteRef&&!v.includes(l.marks.footnoteRef)&&v.push(l.marks.footnoteRef),F(l.children))};F(y);const S=[...v.map(o=>B.find(l=>l.id===o)).filter(o=>!!o),...B.filter(
71
+ o=>!v.includes(o.id))],b=S.filter(o=>o.noteKind!=="endnote"),k=S.filter(o=>o.noteKind==="endnote");b.forEach((o,l)=>{o.footnoteNumber=Me(l+1,"footnote")}),k.forEach((o,l)=>{o.footnoteNumber=Me(l+1,"en\
72
+ dnote")});const E=Yt.separatorSpacePx,R=[],O=Math.max(Yt.separatorWidthMinPx,n.availableWidth*Yt.separatorWidthFraction),ht=(o,l,h,g)=>{const c=o.layout,f=s(Gt(c),h);f.nextBlockIndex=o.nextBlockIndex,
73
+ Rt({state:f,blocks:l,x:mt(c),layoutForLevel:Gt(c),suppressTopSpacingForFirstBlock:!0});for(const w of f.blocks)w.pageNumber=g,o.blocks.push(w);for(const w of f.fragments)w.pageNumber=g,o.fragments.push(
74
+ w);return o.nextBlockIndex=f.nextBlockIndex,f.currentY},V=(o,l,h,g,c,f)=>{const w=a(o,g),Y=u(o,g),H=Wt(w),m=kt(w),j=12,K=h?Y+Math.max(j/2+4,H/2):Y+w.pageHeight-Math.max(j/2+4,m/2),I=mt(w),U=on(e.pageLayout),
75
+ gt=f?rn(f.renderedPageNumber,f.pageNumberFormat):an(U,g),$=W=>W.children.some(tt=>tt.type==="text"&&tt.marks?.field)?{...W,children:W.children.map(tt=>{if(tt.type!=="text"||!tt.marks?.field)return tt;
76
+ const Ft=tt.marks.field==="page"?gt:String(c);return{...tt,text:Ft}})}:W,Lt=l.children.slice(0,3).map((W,tt)=>{const Ft=$(W),L=sn[tt];return L&&!Ft.align?{...Ft,align:L}:Ft}),A=Ne(l,t,w,e,Lt),xt=[0,A[0],
77
+ A[0]+A[1]];l.children.forEach((W,tt)=>{if(tt>2)return;const Ft=Lt[tt],L=A[tt],ut=I+xt[tt],et=s({...w,pageless:!0,availableWidth:L,columnCount:1},0);et.nextBlockIndex=o.nextBlockIndex,Rt({state:et,blocks:[
78
+ Ft],x:ut,layoutForLevel:{...w,pageless:!0,availableWidth:L,columnCount:1},suppressTopSpacingForFirstBlock:!0});const Dt=et.currentY,Tt=K-Dt/2;for(const dt of et.blocks)dt.pageNumber=g+1,dt.bounds={...dt.
79
+ bounds,y:dt.bounds.y+Tt},o.blocks.push(dt);for(const dt of et.fragments)dt.pageNumber=g+1,dt.isChrome=!0,dt.bounds={...dt.bounds,y:dt.bounds.y+Tt},o.fragments.push(dt);o.nextBlockIndex=et.nextBlockIndex})},
80
+ q=(o,l,h)=>{if(n.pageless)return;const g=new Set;for(let c=0;c<l;c++)for(const f of[!0,!1]){const w=tn(e.chrome??[],f?"header":"footer",c+1,h?.[c]?.sectionIndex);w&&(V(o,w,f,c,l,h?.[c]),g.add(w.id))}};
81
+ if(n.pageless){const o=i(y,n),l=[];for(const h of[b,k]){if(h.length===0)continue;const g=o.currentY+E;R.push({x:mt(n),y:g,width:O}),o.currentY=g+10,Rt({state:o,blocks:h,x:mt(n),layoutForLevel:Gt(n),suppressTopSpacingForFirstBlock:!0}),
82
+ l.push({x:mt(n),y:g,width:n.availableWidth,height:Math.max(0,o.currentY-g)})}return o.totalHeight=o.currentY,{blocks:o.blocks,fragments:o.fragments,totalHeight:o.totalHeight,pageCount:1,footnoteSeparators:R,
83
+ footnoteAreas:l}}const st=new Map;(o=>{const l=(h,g,c)=>{if(!h||typeof h!="object")return;if(Array.isArray(h)){h.forEach(w=>l(w,g,c));return}const f=h;if(f.marks?.footnoteRef&&!st.has(f.marks.footnoteRef)){
84
+ const w=c?.value,Y=g.type==="paragraph"&&w!==void 0?_t(g).toVisibleOffset(w):void 0;st.set(f.marks.footnoteRef,{blockId:g.id??"",charOffset:Y})}f.type==="text"&&c&&(c.value+=f.text?.length??0),l(f.children,
85
+ g,c)};for(const h of o)l(h,h,h.type==="paragraph"?{value:0}:void 0)})(y);const Bt=o=>{const l=new Map,h=Math.max(0,o.currentPage-1);for(const g of b){const c=st.get(g.id),f=c?o.fragments.filter(I=>I.blockId===
86
+ c.blockId):[],w=c?.charOffset===void 0?f[0]:[...f].reverse().find(I=>I.charRange&&c.charOffset>=I.charRange.start&&c.charOffset<=I.charRange.end),Y=c?o.blocks.find(I=>I.blockId===c.blockId):void 0,H=w?.
87
+ pageNumber??Y?.pageNumber;if(H===void 0){l.set(g.id,{pageIndex:h});continue}const m=Math.max(0,H-1),j=w??Y;let K;if(j){const I=a(o,m),U=u(o,m)+I.pageHeight-kt(I),gt=w?.lineExtents&&c?.charOffset!==void 0?
88
+ w.lineExtents.find($=>$.charEnd>=c.charOffset)?.bottom:void 0;K=Math.min(gt??j.bounds.y+j.bounds.height,U)}l.set(g.id,{pageIndex:m,keepBottomY:K})}return l},Mt=o=>Math.max(E,o.pageHeight-Wt(o)-kt(o)),
89
+ Nt=o=>{const l=[];for(const h of o.fragments){const g=h.bounds.y,c=g+h.bounds.height,f=d(o,g),w=d(o,Math.max(g,c-.01));for(let Y=f;Y<=w;Y++){const H=a(o,Y),m=u(o,Y)+H.pageHeight-kt(H);l[Y]=Math.max(l[Y]??
90
+ 0,Math.min(c,m))}}return l},at=(o,l)=>Math.max(0,Mt(a(o,l))-E),J=(o,l,h)=>{const g=Nt(o),c=Math.max(o.currentPage,Ut(o)),f=Math.max(n.lineHeight,n.fontSize*cn.paragraph),w=I=>I.type==="paragraph"?gn(I):
91
+ I.type==="list"?n.fontSize*un(I):f,Y=[],H=[];for(const I of o.fragments){const U=d(o,I.bounds.y),gt=Y[U];gt!==void 0&&I.bounds.y>=gt||(Y[U]=I.bounds.y,H[U]=w(I.block))}const m=I=>Math.max(32,Yt.minimumBodyLinesBeforeFootnotes*
92
+ (H[I]??f)),j=new Map;for(const I of b){const U=l.get(I.id),gt=h.get(I.id)??U?.pageIndex??0;!U||U.keepBottomY===void 0||gt!==U.pageIndex||j.set(U.pageIndex,Math.max(j.get(U.pageIndex)??0,U.keepBottomY))}
93
+ const K=[];for(let I=0;I<c;I++){const U=a(o,I),gt=u(o,I),$=gt+Wt(U),Lt=gt+U.pageHeight-kt(U),A=g[I];if(A===void 0){K[I]=at(o,I);continue}const xt=Math.max(j.get(I)??0,Math.min(A,$+m(I)));K[I]=Math.max(
94
+ 0,Lt-E-xt-Yt.bodyKeepSlackPx)}return K},it=(o,l)=>{const h=Math.max(o.currentPage,Ut(o)),g=[];for(let c=0;c<h;c++)g[c]=Math.max(0,Math.min(at(o,c),(l[c]??0)-E));return g};let lt;const Q=()=>{if(lt===void 0){
95
+ const o=s(Gt(n),0);Rt({state:o,blocks:b,x:mt(n),layoutForLevel:Gt(n),suppressTopSpacingForFirstBlock:!0}),lt=Math.max(o.currentY,0)}return lt},pt=(o,l,h,g)=>{const c=L=>L<h.length?Math.max(0,h[L]??0):
96
+ at(o,L),f=L=>{const ut=a(o,L);return u(o,L)+ut.pageHeight-kt(ut)-c(L)},w=L=>{const ut=a(o,L);return u(o,L)+ut.pageHeight-kt(ut)},Y=Math.max(48,Mt(n)/2),H=Math.max(o.currentPage,Ut(o),h.length)+Math.ceil(
97
+ Q()/Y)+4,m=[];for(let L=0;L<H;L++)m.push({top:f(L),bottom:w(L),full:c(L)>=at(o,L)-.01,pageIndex:L});const j=Je(m),K=L=>({...a(o,L),pageless:!1,lineHeight:1.25,paragraphSpacing:.25,blockSpacingPx:2,footnotePageInsets:void 0,
98
+ pageContentTopOffsets:void 0,flowWindows:j}),I=L=>j.at(j.indexForY(L)).pageIndex,U=b[0],gt=l.get(U.id)??0,$=s(K(gt),f(gt));$.nextBlockIndex=g,$.currentPage=gt+1;const Lt=[],A=new Map,xt=new Set,W=new Map,
99
+ tt=new Map;for(const L of b){const ut=I($.currentY),et=Math.max(l.get(L.id)??0,ut),Dt=et>ut,Tt=Dt||$.blocks.length===0;Dt&&($.currentY=f(et),$.currentPage=Math.max($.currentPage,et+1)),$.layout=K(et),
100
+ $.pageStep=xe($.layout);const dt=$.blocks.length;Rt({state:$,blocks:[L],x:mt($.layout),layoutForLevel:$.layout,suppressTopSpacingForFirstBlock:Tt});const Xt=$.blocks[dt],$t=Xt?I(Xt.bounds.y):et,Et=I($.
101
+ currentY-.01);tt.set(L.id,$t);for(let wt=$t;wt<=Et;wt++)A.has(wt)||A.set(wt,f(wt)),wt>$t&&xt.add(wt),W.set(wt,Math.max(W.get(wt)??0,wt<Et?w(wt):$.currentY))}for(const[L,ut]of W)Lt[L]=Math.max(0,ut-f(L));
102
+ const Ft=Math.max(0,...W.keys());return{heights:Lt,windowTops:A,continuationPages:xt,startPageByNote:tt,blocks:$.blocks,fragments:$.fragments,endY:$.currentY,lastPageIndex:Ft,nextBlockIndex:$.nextBlockIndex}},
103
+ Pt=(o,l)=>{const h=[];return l.heights.forEach((g,c)=>{if(!g||g<=0)return;const f=a(o,c);h[c]=Math.min(E+g,Mt(f))}),h},yt=(o,l)=>{const h=Math.max(o.length,l.length);for(let g=0;g<h;g++)if(Math.abs((o[g]??
104
+ 0)-(l[g]??0))>.25)return!1;return!0},D=new Map;let T=[],M=i(y,n,b.length>0),bt=M.currentY;const Z=[];if(b.length>0){for(let l=0;l<8;l++){const h=Bt(M);for(const[f,w]of h)D.set(f,Math.max(D.get(f)??0,w.
105
+ pageIndex));const g=pt(M,D,J(M,h,D),0);for(const[f,w]of g.startPageByNote)D.set(f,Math.max(D.get(f)??0,w));const c=Pt(M,g);if(yt(c,T))break;T=c,M=i(y,{...n,footnotePageInsets:T},!0)}bt=M.currentY;const o=pt(
106
+ M,D,it(M,T),M.nextBlockIndex);M.blocks.push(...o.blocks),M.fragments.push(...o.fragments),M.nextBlockIndex=o.nextBlockIndex,M.currentY=Math.max(M.currentY,o.endY),M.totalHeight=Math.max(M.totalHeight,
107
+ o.endY),M.currentPage=Math.max(M.currentPage,o.lastPageIndex+1);for(const[l,h]of[...o.windowTops].sort((g,c)=>g[0]-c[0])){const g=a(M,l),c=h-8;R.push({pageIndex:l,x:mt(g),y:c,width:o.continuationPages.
108
+ has(l)?g.availableWidth:Math.max(96,g.availableWidth*.3)}),Z.push({pageIndex:l,x:mt(g),y:c,width:g.availableWidth,height:u(M,l)+g.pageHeight-kt(g)-c})}}let X=Math.max(1,M.currentPage,Ut(M));if(k.length>
109
+ 0){const o=X-1,l=u(M,o)+n.pageHeight-kt(n),h=Z.filter(I=>I.pageIndex===o).reduce((I,U)=>Math.min(I,U.y),Number.POSITIVE_INFINITY),g=Math.min(l,h),c=bt+Yt.inlineEndnoteGapPx,f=s(Gt(n),c+Yt.separatorToContentPx);
110
+ f.nextBlockIndex=M.nextBlockIndex,Rt({state:f,blocks:k,x:mt(n),layoutForLevel:Gt(n),suppressTopSpacingForFirstBlock:!0});const w=f.currentY<=g,Y=w?o:X,H=u(M,Y)+n.textStartY,m=w?c:H+Yt.newPageSeparatorOffsetPx;
111
+ R.push({pageIndex:Y,x:mt(n),y:m,width:O});const j=ht(M,k,m+Yt.separatorToContentPx,Y+1);Z.push({pageIndex:Y,x:mt(n),y:m,width:n.availableWidth,height:Math.max(u(M,Y)+n.pageHeight-kt(n),j)-m}),M.currentY=
112
+ Math.max(M.currentY,j),M.totalHeight=Math.max(M.totalHeight,j);const K=It(M,j)??X;X=Math.max(Y+1,K),M.currentPage=Math.max(M.currentPage,X)}const ct=p(M,X);return q(M,X,ct),{blocks:M.blocks,fragments:M.
113
+ fragments,totalHeight:M.totalHeight,pageCount:X,footnoteSeparators:R,footnoteAreas:Z,pageGeometries:ct,...M.lineNumberMarks!==void 0?{lineNumberMarks:M.lineNumberMarks}:{}}}function Rt(e){const{state:t,
114
+ blocks:n,x:r,layoutForLevel:s,onFirstBlockLayout:i,suppressTopSpacingForFirstBlock:a=!1,onBlockLaidOut:u}=e;let d,p,B=!1;for(let x=0;x<n.length;x++){const y=n[x],v=t.blocks.length,F=t.suppressTopSpacingForNextBlock,
115
+ S=a&&x===0||F;F&&(t.suppressTopSpacingForNextBlock=!1);const b=Le(s,{suppressTopSpacingForFirstChild:S,...kn(n,x)});En({state:t,block:y,x:r,layout:b,followingBlocks:n.slice(x+1,x+4)});const k=t.blocks.
116
+ length>v?t.blocks[t.blocks.length-1]:void 0;if(k){B||(B=!0,d=k.bounds.y,i?.(k));const E=k.bounds.y+k.bounds.height;p=p===void 0?E:Math.max(p,E)}u?.(x)}return{firstBlockStartY:d,lastBlockEndY:p}}function Le(e,t){
117
+ return e.suppressTopSpacingForFirstChild===!0===t.suppressTopSpacingForFirstChild&&e.siblingSpaceBeforePx===t.siblingSpaceBeforePx&&e.siblingSpaceAfterPx===t.siblingSpaceAfterPx?e:{...e,...t}}function En(e){
118
+ e.state.lastLineTail=On(e)}function On(e){const{block:t}=e;if(t.type==="container"){Ee({...e,block:t});return}if(t.type==="footnote"){Xn({...e,block:t});return}if(t.type==="table"){Vn({...e,block:t});
119
+ return}if(t.type==="table-cell"){se({...e,block:t});return}return t.type==="page-break"?Dn({...e,block:t}):t.type==="section-break"?Gn(e):qt(e)}const An=4;function Ce(e,t,n){const r=e.lastLineTail;return r?
120
+ {x:r.x+An,y:r.y,width:t.width,height:Math.max(Math.min(16,r.height),0)}:{x:t.x,y:e.currentY,width:t.width,height:Math.max(Math.min(16,n),0)}}function Gn(e){const{state:t,block:n,x:r,layout:s}=e;if(s.pageless)
121
+ return qt(e);const i=t.registry.getHandlerForBlock(n);if(!i)return qt(e);const a=t.nextBlockIndex++,u=i.getBounds(n,r,t.currentY,t.textContext,s,t.doc),d=Ce(t,u,Qt(t,t.currentY)-t.currentY),p=It(t,d.y);
122
+ return t.blocks.push({block:n,blockIndex:a,blockId:n.id??"",bounds:d,pageNumber:p,pageBreakBefore:!1}),t.fragments.push({block:n,blockIndex:a,blockId:n.id??"",fragmentIndex:0,bounds:d,pageNumber:p,data:{
123
+ type:"section-break"}}),{x:d.x+d.width,y:d.y,height:Math.max(d.height,t.lastLineTail?.height??0)}}function Dn(e){const{state:t,block:n,x:r,layout:s}=e,i=t.registry.getHandlerForBlock(n);if(!i)return console.
124
+ warn(`No handler for block type: ${n.type}`),t.lastLineTail;if(s.pageless)return qt(e);const a=t.nextBlockIndex++,u=i.getBounds(n,r,t.currentY,t.textContext,s,t.doc),d=Jn(t,t.currentY),p=Ce(t,u,d-t.currentY),
125
+ B=It(t,p.y),x={block:n,blockIndex:a,blockId:n.id??"",bounds:p,pageNumber:B,pageBreakBefore:!1},y={block:n,blockIndex:a,blockId:n.id??"",fragmentIndex:0,bounds:p,pageNumber:B,data:{type:"page-break"}};
126
+ t.blocks.push(x),t.fragments.push(y),t.currentY=d,t.totalHeight=t.currentY,t.currentPage=Math.max(t.currentPage,It(t,d)??t.currentPage),t.suppressTopSpacingForNextBlock=!0,le(t,d)}function Jt(e,t,n){if(n<=
127
+ 0||e.layout.pageless||e.pageStep<=0)return!1;const r=e.layout.flowWindows;return(r&&r.length!==0?De(t,n,r):Ye(t,n,e.layout)).pageChanged}function Re(e){const t=Qt(e);t>e.currentY&&(e.currentY=t,le(e,t))}
128
+ function jn(e,t,n,r,s){if(!n||n.length===0)return 0;let i=0,a=t;for(let u=0;u<n.length&&u<ae;u++){const d=n[u];if(!d||d.type!=="paragraph")break;const p=e.registry.getHandlerForBlock(d);if(!p)break;const B=Le(
129
+ s,{suppressTopSpacingForFirstChild:!1,siblingSpaceBeforePx:Mn(a,d),siblingSpaceAfterPx:Se(d,n[u+1])}),x=Se(a,d)??(a.type==="paragraph"&&Number.isFinite(a.spaceAfter)?Math.max(0,a.spaceAfter??0):0);a=d;
130
+ const y=We(e,p,d,r,B),v=y.units??[];if(v.length===0)break;const F=x+(y.margins?.top??0),S=re(d);if(S.keepNext&&u<ae-1){i+=F+v.reduce((b,k)=>b+Math.max(k.height,0),0);continue}i+=F+Math.max(v[0].height,
131
+ 0),S.widowControl&&v.length>=2&&(i+=Math.max(v[1].height,0));break}return i}function qt(e){const{state:t,block:n,x:r,layout:s,followingBlocks:i}=e,a=t.registry.getHandlerForBlock(n);if(!a)return console.
132
+ warn(`No handler for block type: ${n.type}`),t.lastLineTail;const u=t.nextBlockIndex++,d=We(t,a,n,r,s),p=d.margins?.top??0,B=d.margins?.bottom??0;t.currentY+=p;const x=d.units.length>0?d.units:[];x.length===
133
+ 0&&console.warn(`Block handler for type ${n.type} returned no layout units; layout may be incorrect.`);let y=!1;const v=re(n);if(!s.pageless&&t.pageStep>0&&x.length>0){const D=x.reduce((M,bt)=>M+Math.
134
+ max(bt.height,0),0);let T=0;v.keepLines?T=D:v.widowControl&&x.length>=2&&(T=Math.max(x[0].height,0)+Math.max(x[1].height,0)),v.keepNext&&(T=Math.max(T,D+jn(t,n,i,r,s))),T>0&&Jt(t,t.currentY,T)&&!Jt(t,
135
+ Qt(t),T)&&(Re(t),y=!0)}let F=0,S=0,b=t.currentY,k,E,R,O,ht,V,q,st=Number.POSITIVE_INFINITY,Bt=Number.NEGATIVE_INFINITY,Mt,Nt=0,at,J=y;const it=[],lt=(D,T)=>{S=D,b=T,k=void 0,E=void 0,R=void 0,O=void 0,
136
+ ht=void 0,V=void 0,q=void 0},Q=D=>{if(D<=S){lt(D,t.currentY);return}const T=t.currentY-b;if(T<=0){lt(D,t.currentY);return}const M=ht??d.x,bt=V!==void 0&&ht!==void 0?V-ht:d.width,Z=Math.max(bt,d.width),
137
+ X={x:M,y:b,width:Z,height:T};let ct;!t.layout.pageless&&t.pageStep>0&&(ct=It(t,X.y));const o={block:n,blockIndex:u,blockId:n.id??"",fragmentIndex:F,bounds:X,pageNumber:ct,unitRange:{start:S,end:D}};k!==
138
+ void 0&&E!==void 0&&E>=k&&(o.lineRange={start:k,end:E}),R!==void 0&&O!==void 0&&O>=R&&(o.charRange={start:R,end:O}),q&&q.length>0&&(o.lineExtents=q),F===0&&(at=ct),it.push(o),F+=1,Mt=Mt??X.y,Nt+=X.height,
139
+ lt(D,t.currentY)};let pt;for(let D=0;D<x.length;D++){const T=x[D],M=Math.max(T.height,0),bt=T.x??d.x,Z=T.width,X=bt+Z,ct=v.widowControl&&x.length>=3&&D===x.length-2&&!Jt(t,t.currentY,M)&&Jt(t,t.currentY+
140
+ M,Math.max(x[D+1].height,0));ct&&Re(t),(ct||At(t,M))&&(S<D?Q(D):F===0&&(J=!0),lt(D,t.currentY)),k===void 0&&T.lineRange&&(k=T.lineRange.start),T.lineRange&&(E=T.lineRange.end),R===void 0&&T.charRange&&
141
+ (R=T.charRange.start),T.charRange&&(O=T.charRange.end),t.trackLineExtents&&T.charRange&&(q??(q=[])).push({charEnd:T.charRange.end,bottom:t.currentY+M}),ht=ht===void 0?bt:Math.min(ht,bt),V=V===void 0?X:
142
+ Math.max(V,X),st=Math.min(st,bt),Bt=Math.max(Bt,X),t.lineNumberMarks!==void 0&&t.layout.lineNumbering&&T.lineRange&&t.lineNumberMarks.push({y:t.currentY,height:M,...T.baselineOffset!==void 0?{baselineOffset:T.
143
+ baselineOffset}:{},pageNumber:It(t,t.currentY)}),pt={unit:T,fallbackX:X,y:t.currentY,height:M},t.currentY+=M}Q(x.length);const Pt={x:Number.isFinite(st)?st:d.x,y:Mt??t.currentY,width:Number.isFinite(st)&&
144
+ Number.isFinite(Bt)?Math.max(Bt-st,d.width):d.width,height:Nt,margins:d.margins};t.blocks.push({block:n,blockIndex:u,blockId:n.id??"",bounds:Pt,pageNumber:t.layout.pageless?void 0:at,pageBreakBefore:J}),
145
+ t.fragments.push(...it),t.currentY+=B,t.totalHeight=t.currentY;const yt=pt;if(!(!a.isTextBased||!yt))return{get x(){return yt.unit.textEndX??yt.fallbackX},y:yt.y,height:yt.height}}function We(e,t,n,r,s){
146
+ const i=e.boundsMemo;if(!i)return t.getBounds(n,r,e.currentY,e.textContext,s,e.doc);const a=s.suppressTopSpacingForFirstChild===!0,{siblingSpaceBeforePx:u,siblingSpaceAfterPx:d}=s;let p=i.get(n);const B=p?.
147
+ find(y=>y.x===r&&y.availableWidth===s.availableWidth&&y.suppressTopSpacing===a&&y.siblingSpaceBeforePx===u&&y.siblingSpaceAfterPx===d);if(B)return B.result;const x=t.getBounds(n,r,e.currentY,e.textContext,
148
+ s,e.doc);return p||(p=[],i.set(n,p)),p.push({x:r,availableWidth:s.availableWidth,suppressTopSpacing:a,siblingSpaceBeforePx:u,siblingSpaceAfterPx:d,result:x}),x}function Gt(e){return{...e,pageless:!0,lineHeight:1.25,
149
+ paragraphSpacing:.25,blockSpacingPx:Yt.blockSpacingPx}}function Ee(e){const{state:t,block:n,x:r,layout:s,paddingOverride:i,fragmentType:a}=e,u=t.registry.getHandlerForBlock(n);if(!u){console.warn(`No \
150
+ handler for block type: ${n.type}`);return}const d=t.nextBlockIndex++,p=u.getBounds(n,r,t.currentY,t.textContext,s,t.doc),B=p.margins?.top??0,x=p.margins?.bottom??0;t.currentY+=B;let y=t.currentY,v=!1;
151
+ const F=Math.max(0,n.padding??Ln),S=i?.top??F,b=i?.bottom??F,k=i?.left??F,E=i?.right??F,R=p.width??s.availableWidth,O={block:n,blockIndex:d,blockId:n.id??"",bounds:{x:r,y,width:R,height:0,margins:p.margins},
152
+ pageBreakBefore:!1},ht=t.blocks.length;t.blocks.push(O);const V=t.fragments.length,q=n.children.length>0;let st=!q;const Bt=ie(t,Pt=>{st||(y=Pt,O.bounds.y=Pt,v=!0)});At(t,1e-4)&&(y=t.currentY,O.bounds.
153
+ y=y,v=!0),At(t,S)&&(y=t.currentY,O.bounds.y=y,v=!0),t.currentY+=S;const Mt=r+k,Nt=Math.max(s.availableWidth-k-E,Hn),at=Math.abs(Nt-s.availableWidth)<.5?s:Xe(s,Nt);let J={};try{J=Rt({state:t,blocks:n.children,
154
+ x:Mt,layoutForLevel:at,onFirstBlockLayout:()=>{st=!0},suppressTopSpacingForFirstBlock:!0})}finally{Bt()}J.firstBlockStartY!==void 0&&J.firstBlockStartY-S<y&&(y=J.firstBlockStartY-S,O.bounds.y=y),At(t,
155
+ b)&&(q||(y=t.currentY,O.bounds.y=y,v=!0)),t.currentY+=b;const it=Math.max(t.currentY-y,S+b);O.bounds={...O.bounds,y,height:it,width:R,margins:p.margins},O.pageBreakBefore=v,O.pageNumber=It(t,O.bounds.
156
+ y);const lt={x:r,y:O.bounds.y,width:R,height:it},Q={block:n,blockIndex:d,blockId:n.id||"",fragmentIndex:0,bounds:lt,pageNumber:O.pageNumber,data:{type:a??"container"}};if(t.fragments.splice(V,0,Q),J.firstBlockStartY!==
157
+ void 0){const Pt=Math.max(t.layout.lineHeight*4,64);if(J.firstBlockStartY-y>Pt+S){const yt=J.firstBlockStartY-S;O.bounds.y=yt,O.bounds.height=Math.max(t.currentY-yt,S+b),Q.bounds={...Q.bounds,...O.bounds}}}
158
+ t.blocks[ht]=O;const pt=It(t,O.bounds.y);O.pageNumber=pt,Q.pageNumber=pt,t.currentY+=x,t.totalHeight=t.currentY}function Xn(e){Ee({...e,block:e.block,paddingOverride:{top:Yt.verticalPaddingPx,bottom:Yt.
159
+ verticalPaddingPx,left:Yt.gutterPx,right:0},fragmentType:"footnote"})}const Oe=oe.cellPaddingPx,$n=oe.borderColor,_n=oe.borderWidthPx;function Un(e){if(e.flowWindows)return e.flowWindows;const t=xe(e),
160
+ n=e.sectionStartY??0,r=e.sectionFirstPageIndex??0;return{indexForY:s=>Math.max(0,Math.floor((s-n-e.textStartY+rt)/t)),at:s=>{const i=Qe(e,r+s),a=ke(e,r+s),u=n+s*t;return{top:u+i,bottom:u+e.pageHeight-
161
+ kt(e)-a,full:i<=Wt(e)&&a<=0,pageIndex:r+s}}}}function Ae(e,t,n){if(e.layout.pageless||n<=0)return t+n;const r=e.layout.flowWindows;let s=r.indexForY(t);for(;n>rt;){const i=r.at(s);t=Math.max(t,i.top);
162
+ const a=Math.max(0,i.bottom-t);if(n<=a+rt)return t+n;if(n-=a,r.length!==void 0&&s+1>=r.length)return i.bottom+n;t=r.at(++s).top}return t}function zn(e,t,n){return je(e,t,n).reduce((r,s)=>r+s.height,0)}
163
+ function Zn(e,t,n,r){const{blockIndex:s,fragmentIndex:i,params:a}=t,u=e.blocks[s].bounds.y,d=a.block.verticalAlign,p=zn(e,u,n)-(a.measuredHeight??0);if(r&&d&&d!=="top"&&p>rt){const v=k=>{const E={...e,
164
+ blocks:[],fragments:[],currentY:u,nextBlockIndex:e.blocks[s].blockIndex,pageBreakListeners:[],lineNumberMarks:void 0,lastLineTail:void 0,suppressTopSpacingForNextBlock:!1};return se({...a,state:E,rowHeight:void 0,
165
+ contentOffset:k}),E};let F=p*(d==="middle"?.5:1),S=v(F),b;if(S.currentY<=n+rt)b=S;else{let k=0;for(let E=0;E<16&&F-k>.01;E++){const R=(k+F)/2;S=v(R),S.currentY<=n+rt?(b=S,k=R):F=R}}b&&(e.blocks.splice(
166
+ s,t.blockCount,...b.blocks),e.fragments.splice(i,t.fragmentCount,...b.fragments))}const B=e.blocks[s];B.bounds.height=Math.max(0,n-u);const x=e.fragments[i],y=je(e,u,n);y.length&&e.fragments.splice(i,
167
+ 1,...y.map((v,F)=>({...x,fragmentIndex:F,bounds:{...x.bounds,y:v.y,height:v.height},pageNumber:It(e,v.y),data:F>0?structuredClone(x.data):x.data})))}function Vn(e){const{state:t,block:n,x:r,layout:s}=e,
168
+ i=t.registry.getHandlerForBlock(n);if(!i){console.warn(`No handler for block type: ${n.type}`);return}const a=t.nextBlockIndex++,u=i.getBounds(n,r,t.currentY,t.textContext,s,t.doc),d=u.margins?.top??0,
169
+ p=u.margins?.bottom??0;t.currentY+=d;let B=t.currentY,x=!1;const y=u.width,v=Number.isFinite(n.cellPadding)?Math.max(0,Math.round(n.cellPadding)):Oe,F=n.borderColor??$n,S=Number.isFinite(n.borderWidth)?
170
+ Math.max(0,Number(n.borderWidth)):_n,b=u.x,k={block:n,blockIndex:a,blockId:n.id??"",bounds:{x:b,y:B,width:y,height:0,margins:u.margins},pageBreakBefore:!1},E=t.blocks.length;t.blocks.push(k);const R=t.
171
+ fragments.length;let O=!(n.children.length>0);const ht=ie(t,at=>{O||(B=at,k.bounds.y=at,x=!0)});At(t,1e-4)&&(B=t.currentY,k.bounds.y=B,x=!0);const V=t.layout,q=Un(V);V.pageless||(t.layout={...V,flowWindows:q});
172
+ try{const at=u.units[0]?.data,J=at?.grid??wn(n),it=at?.geometry??In(J,y,n.columnWidths,(Z,X)=>{const ct={...s,availableWidth:X,tableCellPadding:v};return t.registry.getHandlerForBlock(Z)?.getBounds(Z,
173
+ 0,0,t.textContext,ct,t.doc).units.reduce((o,l)=>o+l.height,0)??0}),lt=Array.from({length:J.rows},()=>[]);for(const Z of J.cells)lt[Z.row].push(Z);const Q=new Array(J.rows).fill(0),pt=new Array(J.rows).
174
+ fill(0),Pt=V.pageless?1/0:V.pageHeight-V.textStartY-kt(V);let yt=n.hasHeader===!0&&J.rows>1&&!V.pageless&&!lt[0].some(Z=>Z.rowSpan>1),D=[],T=0,M=0,bt=0;for(let Z=0;Z<J.rows;){let X=Z+1,ct=0;for(let c=Z;c<
175
+ X;c++){ct+=it.rowHeights[c];for(const f of lt[c])X=Math.max(X,f.row+f.rowSpan)}const o=ct>Pt-(Z>0?M:0);o?At(t,1e-4):At(t,ct),O=!0;const l=t.currentY,h=t.fragments.length,g=[];for(let c=Z;c<X;c++){const f=t.
176
+ currentY;let w=o?Ae(t,f,it.rowHeights[c]):f+it.rowHeights[c];for(const Y of lt[c]){t.currentY=f;const H={state:t,block:Y.cell,x:b+it.colLefts[Y.col],layout:{...s,availableWidth:it.cellWidth(Y),tableCellPadding:v},
177
+ measuredHeight:it.measuredCellHeight(Y),rowHeight:o?void 0:it.cellHeight(Y),cellEdgeInfo:{parentTableId:n.id??"",tableDiffState:n.diffState,rowDiffState:n.children[c].diffState,isTopRow:c===0,isBottomRow:Y.
178
+ row+Y.rowSpan===J.rows,isLeftCol:Y.col===0,isRightCol:Y.col+Y.colSpan===J.cols,isHeaderCell:n.hasHeader===!0&&c===0,tableBorderColor:F,tableBorderWidth:S,tableBorders:n.borders,tableCellPadding:v,gridRow:Y.
179
+ row,gridCol:Y.col,rowSpan:Y.rowSpan,colSpan:Y.colSpan}},m=t.blocks.length,j=t.fragments.length,K=t.lineNumberMarks;t.lineNumberMarks=void 0;try{se(H)}finally{t.lineNumberMarks=K}const I=Y.row+Y.rowSpan-
180
+ 1;pt[I]=Math.max(pt[I],t.currentY),g.push({params:H,gc:Y,blockIndex:m,fragmentIndex:j,blockCount:t.blocks.length-m,fragmentCount:t.fragments.length-j})}w=Math.max(w,pt[c]),Q[c]=w,t.currentY=w}for(let c=g.
181
+ length-1;c>=0;c--){const f=g[c];Zn(t,f,Q[f.gc.row+f.gc.rowSpan-1],o)}Z===0&&yt&&(T=l,M=t.currentY-T,bt=q.indexForY(T),yt=!o&&q.indexForY(t.currentY-rt)===bt&&M<Pt,yt?(D=t.fragments.slice(h),t.layout={
182
+ ...V,flowWindows:{length:q.length,indexForY:q.indexForY,at:c=>{const f=q.at(c);return c>bt?{...f,top:f.top+M}:f}}}):M=0),Z=X}if(yt&&D.length){const Z=q.indexForY(t.currentY-rt);for(let X=bt+1;X<=Z;X++){
183
+ const ct=q.at(X).top-T;for(const o of D){const l={...o.bounds,y:o.bounds.y+ct};t.fragments.push({...o,bounds:l,repeatedHeader:!0,pageNumber:It(t,l.y),lineExtents:o.lineExtents?.map(h=>({...h,bottom:h.
184
+ bottom+ct})),data:{...structuredClone(o.data),repeatedHeader:!0}})}}}}finally{t.layout=V,ht()}const st=Math.max(t.currentY-B,0);k.bounds={...k.bounds,y:B,height:st,width:y,margins:u.margins},k.pageBreakBefore=
185
+ x,k.pageNumber=It(t,k.bounds.y);const Bt={x:b,y:k.bounds.y,width:y,height:st},Mt={block:n,blockIndex:a,blockId:n.id||"",fragmentIndex:0,bounds:Bt,pageNumber:k.pageNumber,data:{type:"table"}};t.fragments.
186
+ splice(R,0,Mt),t.blocks[E]=k;const Nt=It(t,k.bounds.y);k.pageNumber=Nt,Mt.pageNumber=Nt,t.currentY+=p,t.totalHeight=t.currentY}function se(e){const{state:t,block:n,x:r,layout:s,rowHeight:i,cellEdgeInfo:a}=e,
187
+ u=t.registry.getHandlerForBlock(n);if(!u){console.warn(`No handler for block type: ${n.type}`);return}const d=t.nextBlockIndex++,p=e.measuredHeight??u.getBounds(n,r,t.currentY,t.textContext,s,t.doc).units.
188
+ reduce((Q,pt)=>Q+Math.max(pt.height,0),0),B=s.availableWidth,x=Sn(a?.tableCellPadding??Oe,n.padding),y=Math.max(p,x.top+x.bottom),v=i!==void 0?Math.max(i,0):y,F=Math.max(0,v-y),S=n.verticalAlign??"top",
189
+ b=e.contentOffset??(S==="bottom"?F:S==="middle"?F/2:0);let k=t.currentY,E=!1;const R={block:n,blockIndex:d,blockId:n.id??"",bounds:{x:r,y:k,width:B,height:0},pageBreakBefore:!1},O=t.blocks.length;t.blocks.
190
+ push(R);const ht=t.fragments.length;let V=!(n.children.length>0);const q=ie(t,Q=>{!V&&t.fragments.length===ht&&(k=Q,R.bounds.y=Q,E=!0)});b>0&&(t.currentY=Ae(t,t.currentY,b)),At(t,x.top)&&(k=t.currentY,
191
+ R.bounds.y=k,E=!0),t.currentY+=x.top;const st=r+x.left,Bt=Yn(B,x),Mt=Xe(s,Bt);try{Rt({state:t,blocks:n.children,x:st,layoutForLevel:Mt,onFirstBlockLayout:()=>{V=!0},suppressTopSpacingForFirstBlock:!qe(
192
+ n.children[0])})}finally{q()}if(n.backgroundColor)for(let Q=ht;Q<t.fragments.length;Q++){const pt=t.fragments[Q];pt.backgroundFill===void 0&&(pt.backgroundFill=n.backgroundColor)}t.currentY+=x.bottom;
193
+ const Nt=Math.max(t.currentY-k,x.top+x.bottom),at=Math.max(i??0,Nt);R.bounds={...R.bounds,y:k,height:at,width:B},R.pageBreakBefore=E,R.pageNumber=It(t,R.bounds.y);const J={x:r,y:R.bounds.y,width:B,height:at},
194
+ it={block:n,blockIndex:d,blockId:n.id||"",fragmentIndex:0,bounds:J,pageNumber:R.pageNumber,data:{type:"table-cell",...a&&{parentTableId:a.parentTableId,tableDiffState:a.tableDiffState,rowDiffState:a.rowDiffState,
195
+ isTopRow:a.isTopRow,isBottomRow:a.isBottomRow,isLeftCol:a.isLeftCol,isRightCol:a.isRightCol,isHeaderCell:a.isHeaderCell,tableBorderColor:a.tableBorderColor,tableBorderWidth:a.tableBorderWidth,...a.tableBorders?
196
+ {tableBorders:a.tableBorders}:{},tableCellPadding:a.tableCellPadding,gridRow:a.gridRow,gridCol:a.gridCol,rowSpan:a.rowSpan,colSpan:a.colSpan}}};t.fragments.splice(ht,0,it),t.blocks[O]=R;const lt=It(t,
197
+ R.bounds.y);R.pageNumber=lt,it.pageNumber=lt,i!==void 0&&(t.currentY=k+at),t.totalHeight=t.currentY}const Ge=1e4;function De(e,t,n){const r=n.indexForY(e);if(e+t<=n.at(r).bottom)return{newY:e,pageChanged:!1};
198
+ const s=n.length!==void 0?n.length-1:r+Ge;for(let i=r+1;i<=s;i++){const a=n.at(i);if(a.full||a.top+t<=a.bottom||i===s)return i===s&&n.length===void 0&&console.warn("Flow-window scan hit its defensive \
199
+ cap without finding a window that accepts the content; window geometry is broken."),{newY:a.top,pageChanged:!0}}return{newY:e,pageChanged:!1}}function At(e,t){if(t<=0||e.layout.pageless)return!1;const n=e.
200
+ layout.flowWindows,r=n&&n.length!==0?De(e.currentY,t,n):Ye(e.currentY,t,e.layout);return r.pageChanged?(e.currentY=r.newY,le(e,r.newY),!0):!1}function je(e,t,n){if(e.layout.pageless||e.pageStep<=0||n<=
201
+ t)return n>t?[{y:t,height:n-t}]:[];const r=e.layout.flowWindows;if(r&&r.length!==0){const x=[];let y=t,v=r.indexForY(y);for(;y<n-rt;){const F=Math.min(n,r.at(v).bottom);if(F>y&&x.push({y,height:F-y}),
202
+ v+=1,r.length!==void 0&&v>=r.length){n>F&&x.push({y:F,height:n-F});break}y=Math.max(F,r.at(v).top)}return x}const{textStartY:s,pageHeight:i}=e.layout,a=e.layout.sectionStartY??0,u=kt(e.layout),d=[];let p=t,
203
+ B=Math.floor(Math.max(p-a-s,0)/e.pageStep);for(;p<n-rt;){const x=a+B*e.pageStep+i-u,y=Math.min(n,x);y>p&&d.push({y:p,height:y-p}),B+=1,p=Math.max(y,a+B*e.pageStep+s)}return d}function Qt(e,t=e.currentY){
204
+ if(e.layout.pageless||e.pageStep<=0)return t;const n=e.layout.flowWindows;if(n&&n.length!==0){const i=n.indexForY(t);return n.length!==void 0&&i+1>=n.length?t:n.at(i+1).top}const r=e.layout.sectionStartY??
205
+ 0,s=Math.floor(Math.max(t-r-e.layout.textStartY,0)/e.pageStep);return r+(s+1)*e.pageStep+e.layout.textStartY}function Jn(e,t=e.currentY){const n=e.layout.flowWindows;if(!n||n.length===0)return Qt(e,t);
206
+ const r=n.indexForY(t),s=n.at(r).pageIndex,i=n.length!==void 0?n.length-1:r+Ge;for(let a=r+1;a<=i;a++){const u=n.at(a);if(u.pageIndex>s)return u.top}return t}function It(e,t){if(e.layout.pageless||e.pageStep<=
207
+ 0)return;const n=e.layout.flowWindows;if(n&&n.length!==0){const a=n.at(n.indexForY(t)).pageIndex+1;return e.currentPage=Math.max(e.currentPage,a),a}const r=e.layout.sectionStartY??0,s=Math.floor(Math.
208
+ max(t-r-e.layout.textStartY,0)/e.pageStep),i=(e.layout.sectionFirstPageIndex??0)+s+1;return e.currentPage=Math.max(e.currentPage,i),i}function Ut(e){if(e.layout.pageless||e.pageStep<=0)return 1;const t=e.
209
+ layout.sectionStartY??0,n=Math.max(e.totalHeight,e.currentY,t+e.layout.textStartY),r=Math.max(n-t-e.layout.textStartY-rt,0);return(e.layout.sectionFirstPageIndex??0)+Math.floor(r/e.pageStep)+1}function qn(e,t){
210
+ const n=Math.max(1,e.pageHeight-e.textStartY-kt(e)),r=Math.max(e.textStartY,t.totalHeight),s=e.pageHeight+e.pageSpacing;let i;if(e.pageless||s<=0)i=(r-e.textStartY)/n;else{const a=Math.max(1,t.pageCount),
211
+ u=(t.pageGeometries?.[a-1]?.pageTop??(a-1)*s)+e.textStartY,d=Math.max(0,r-u),p=Math.max(.1,Math.min(1,d/n));i=a===1?p:a-1+p}return Math.round(Math.max(.1,i)*10)/10}function Xe(e,t){return{...e,availableWidth:t}}
212
+ function ie(e,t){return e.pageBreakListeners.push(t),()=>{const n=e.pageBreakListeners.lastIndexOf(t);n>=0&&e.pageBreakListeners.splice(n,1)}}function le(e,t){if(e.pageBreakListeners.length!==0)for(const n of e.
213
+ pageBreakListeners)try{n(t)}catch(r){console.error("Error in page break listener",r)}}function Qn(e,t,n){return e.fragments.filter(r=>{const{bounds:s}=r;return s.y+s.height>=t&&s.y<=n})}function Kn(e,t){
214
+ return e.blocks.find(n=>n.blockId===t)||null}function to(e,t){return e.blocks[t]||null}function eo(e,t,n,r,s){if(!n.id)return null;const i=e.fragments.filter(a=>a.blockId===n.id&&!a.repeatedHeader);if(i.
215
+ length===0)return null;if(i.length===1)return i[0];if(r.isTextBased&&r.getCharacterOffset){const a=Rn(n,r,t);for(let u=0;u<i.length;u++){const d=i[u];if(d.charRange&&a>=d.charRange.start&&a<=d.charRange.
216
+ end){const p=i[u+1]?.charRange;if(a===d.charRange.end&&p&&p.start<=a){const B=(n.type==="paragraph"?_t(n).visibleText:n.type==="list"?n.children.map(x=>_t(x).visibleText).join(`
217
+ `):void 0)?.[p.start-1];if(B===" "||B===`
218
+ `)continue}return d}}}return i[0]}export{ae as K,eo as a,Fn as b,Wn as c,to as d,Ne as e,Qn as f,Kn as g,qn as h,re as p};