@reviseio/engine 3.0.0 → 3.1.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 (43) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/assets/{historyMaterializeWorker-Kl0syEbc.js → historyMaterializeWorker-BMHTnStL.js} +131 -130
  3. package/chunks/{AgentHtmlConverter-BnK7NaYA.js → AgentHtmlConverter-B5qstcmM.js} +129 -128
  4. package/chunks/{AgentPageRenderer-DLwq6nAa.js → AgentPageRenderer-JMhCw-hi.js} +4 -4
  5. package/chunks/BlockDiff-C8eiZ-sf.js +45 -0
  6. package/chunks/{CanvasRenderer-Bqsj1S0p.js → CanvasRenderer-C2vAzLWM.js} +12 -12
  7. package/chunks/DocumentCompare-DX4RWeSV.js +10 -0
  8. package/chunks/{DocumentLayoutEngine-7iOYvyVb.js → DocumentLayoutEngine-BhcWXkeu.js} +45 -45
  9. package/chunks/{DocumentMutator-DIrZBuLr.js → DocumentMutator-FEFU1YM0.js} +6 -6
  10. package/chunks/DocumentOutline-BOZoTohH.js +4 -0
  11. package/chunks/{DocumentScrubber-Cz8Q05hF.js → DocumentScrubber-C4N3Qagm.js} +1 -1
  12. package/chunks/{DocumentSession-lXSXqua5.js → DocumentSession-gZHWP7By.js} +1 -1
  13. package/chunks/{DocxConverter-BfDw7777.js → DocxConverter-BOyLn5eZ.js} +709 -703
  14. package/chunks/{DocxGraft-D0uCnGCo.js → DocxGraft-BbE-AaM5.js} +2 -2
  15. package/chunks/{HtmlConverter-7Xj_g9Jr.js → HtmlConverter-BlzwsPEn.js} +3 -3
  16. package/chunks/MarkdownConverter-BHVskVXI.js +59 -0
  17. package/chunks/{OdtConverter-GwRDMnwS.js → OdtConverter-BdmBFOD1.js} +1 -1
  18. package/chunks/{OfficeImportShared-nlMtIUni.js → OfficeImportShared-B2XJgnDO.js} +4 -4
  19. package/chunks/{PdfConverter-yOlWiVIj.js → PdfConverter-DZMCHDAo.js} +6 -6
  20. package/chunks/{RtfConverter--wLd0qrw.js → RtfConverter-RqE-xZcW.js} +66 -66
  21. package/chunks/{TableBorders-C5pNsuxP.js → TableBorders-ARyTi49V.js} +1 -1
  22. package/chunks/TextDecoding-IPbuUqcC.js +2 -0
  23. package/chunks/TextFileDecoder-BZBBejlR.js +10 -0
  24. package/chunks/{TxtConverter-BoRVCDZw.js → TxtConverter-EPQtb6A6.js} +1 -1
  25. package/chunks/{Typography-DAGM5kfI.js → Typography-XR6scRNV.js} +9 -9
  26. package/chunks/XmlConverter-9sFRFaza.js +55 -0
  27. package/chunks/{capture-Dtinb4bY.js → capture-DhGn0CWA.js} +1 -1
  28. package/chunks/{carrier-RNy67HN4.js → carrier-D58g-gw4.js} +1 -1
  29. package/chunks/{chromeImageLayout-bgHYmqTp.js → chromeImageLayout-DeYYS8YP.js} +1 -1
  30. package/chunks/{engine-TnK8N-gT.js → engine-C5fxuZJo.js} +140 -140
  31. package/chunks/{footnoteFlatten-BcKaWzVs.js → footnoteFlatten-coCVFd3c.js} +1 -1
  32. package/chunks/{graftExport-DxAALMHp.js → graftExport-FBGE2qvt.js} +1 -1
  33. package/chunks/{index-CTti7wRd.js → index-Cezk1s_y.js} +4 -4
  34. package/chunks/{serverDocumentSession-BmYdjC6e.js → serverDocumentSession-LMu3kocH.js} +559 -560
  35. package/chunks/{signatures-CU2LMLBp.js → signatures-DsJnnIqV.js} +1 -1
  36. package/chunks/textExtraction-Bqaqt1Kg.js +2 -0
  37. package/engine.js +2 -2
  38. package/package.json +2 -2
  39. package/chunks/BlockDiff-BdlcKY-t.js +0 -42
  40. package/chunks/DocumentCompare-BqyiP87r.js +0 -6
  41. package/chunks/MarkdownConverter-cnW_oePY.js +0 -57
  42. package/chunks/TextFileDecoder--rsVs3NR.js +0 -9
  43. package/chunks/XmlConverter-CO8Z28dX.js +0 -55
@@ -0,0 +1,45 @@
1
+ import{M as xe}from"./engine-C5fxuZJo.js";import{a as le}from"./ParagraphDiffAnalysis-DrmStvmz.js";const ae=new WeakMap,E=t=>{let s=ae.get(t);return s===void 0&&(s=t.children.map(a=>a.text).join(""),ae.
2
+ set(t,s)),s},P=t=>t.trim()?t.trim().split(/\s+/).length:0,Se=/^(?:w14:paraId|w14:textId|w:rsid\w*)$/;function we(t){if(typeof t!="string")return t;try{const s=Object.entries(JSON.parse(t)).filter(([a])=>!Se.
3
+ test(a)).sort(([a],[h])=>a.localeCompare(h));return s.length?JSON.stringify(Object.fromEntries(s)):void 0}catch{return t}}const ce=new WeakMap,u=t=>{let s=ce.get(t);if(s===void 0){const{id:a,children:h,
4
+ oxmlAttrs:B,...A}=t,k=we(B);s=JSON.stringify(k===void 0?A:{...A,oxmlAttrs:k}),ce.set(t,s)}return s},Oe=t=>typeof t=="string"?t.split(",")[0].replace(/['"]/g,"").trim().toLowerCase():t,de=(t,s)=>JSON.stringify(
5
+ Object.entries(t).filter(([a,h])=>!(a==="fontSize"&&h===s)).map(([a,h])=>[a,a==="fontFamily"?Oe(h):h]).sort(([a],[h])=>String(a).localeCompare(String(h)))),q=(t={})=>Object.fromEntries(xe.filter(s=>t[s]!==
6
+ void 0).map(s=>[s,t[s]])),Ne=["comment","footnoteRef","footnotePendingBody","footnotePendingKind","oxmlRange","bookmark"],he=t=>{const s={...t};for(const a of Ne)delete s[a];return s};function ve(t){return{
7
+ ...t,children:t.children.map(s=>({...s,marks:q(s.marks)}))}}function pe(t){return t.type==="paragraph"?`p${u(t)}${E(t)}`:t.type==="list"?`l${u(t)}${t.children.map(s=>u(s)+E(s)).join("\0")}`:JSON.stringify(
8
+ t,(s,a)=>s==="id"?void 0:a)}function Ie(t){return t.type==="paragraph"||t.type==="list"||t.type==="table"}function ee(t,s){const a=JSON.parse(JSON.stringify(t)),h=new Map,B=[],A=k=>{if(!k||typeof k!="\
9
+ object")return;const y=k;if(typeof y.type=="string"&&typeof y.id=="string"){const J=s();h.set(y.id,J),y.id=J}typeof y.docxTablePropertyOverrides=="string"&&B.push(y),Array.isArray(y.children)&&y.children.
10
+ forEach(A)};A(a);for(const k of B)try{const y=JSON.parse(k.docxTablePropertyOverrides);for(const J of["rows","rowExceptions","cells"]){const O=y[J];!O||typeof O!="object"||Array.isArray(O)||(y[J]=Object.
11
+ fromEntries(Object.entries(O).map(([M,m])=>[h.get(M)??M,m])))}k.docxTablePropertyOverrides=JSON.stringify(y)}catch{}return a}function te(t){const s=a=>{if(!a||typeof a!="object")return;const h=a;h.type===
12
+ "text"&&h.marks&&(h.marks=he(h.marks)),h.children?.forEach(s)};return s(t),t}const X=new Map,U=t=>{let s=X.get(t);return s||(s=new Set(t.toLowerCase().match(/[\p{L}\p{N}]+/gu)??[]),X.size>5e4&&X.clear(),
13
+ X.set(t,s)),s};function re(t,s){let a=0;for(const h of t)s.has(h)&&a++;return 2*a/(t.size+s.size||1)}function ne(t,s,a,h,B,A,k,y,J=()=>!1){const O=new Map,M=p=>{const g=a(p);return O.has(g)||O.set(g,`\
14
+ t${O.size}`),O.get(g)+" "},m=le(t.map(M).join(""),s.map(M).join("")).diffs;let $=0,K=0,G=0,L=0;const _=()=>{const p=t.slice(G,$),g=s.slice(L,K);if(p.length===1&&g.length===1&&J(p[0],g[0])){A(p[0],g[0]);
15
+ return}const W=p.map(v=>g.map(I=>h(v,I))),b=Array.from({length:p.length+1},()=>new Float64Array(g.length+1));for(let v=p.length-1;v>=0;v--)for(let I=g.length-1;I>=0;I--)b[v][I]=Math.max(b[v+1][I],b[v][I+
16
+ 1],W[v][I]+b[v+1][I+1]);let w=0,x=0;for(;w<p.length||x<g.length;)w<p.length&&x<g.length&&W[w][x]>0&&b[w][x]===W[w][x]+b[w+1][x+1]?A(p[w++],g[x++]):w<p.length&&(x===g.length||b[w+1][x]>=b[w][x+1])?k(p[w++]):
17
+ y(g[x++])};for(const[p,g]of m){const W=g.trim().split(/\s+/).filter(Boolean).length;if(p===0){_();for(let b=0;b<W;b++)B(t[$++],s[K++]);G=$,L=K}else p===-1?$+=W:K+=W}_()}const Y=8e6,ue=1e6;function je(t,s,a){
18
+ if(t.length*s.length>Y)return null;const{nextId:h,nextBlockId:B,label:A,authorName:k,authorOf:y,pairLoneChanges:J,defaultFontSize:O}=a,M=r=>J?r:()=>!1,m={inlineChanges:0,insertedBlocks:0,deletedBlocks:0,
19
+ unmarkedBlocks:0,insertedWords:0,deletedWords:0},$=r=>y?.(r)??k,K=(r,e,n)=>{const c=$(n);return{[r]:!0,suggestionId:e,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:A,...c?{suggestionAuthorName:c}:
20
+ {}}},G=(r,e)=>{if(!Ie(r))return null;const n=r.type==="paragraph"?r.children[0]?.marks:void 0,c=r.type==="paragraph"?ve(r):r,i=e==="delete"?te(ee(c,B)):c,o=h(),f=$(n),l={id:o,blockId:i.id,source:"manu\
21
+ al",authorType:"human",label:e==="insert"?"Insert":"Delete",...f?{agentName:f}:{}},d=e==="insert"?{...l,type:"block-insert"}:{...l,type:"block-delete",beforeBlock:i},S="children"in i&&i.type!=="table"?
22
+ T(i):"";return e==="insert"?(m.insertedBlocks++,m.insertedWords+=P(S)):(m.deletedBlocks++,m.deletedWords+=P(S)),{...i,structuralSuggestionId:o,structuralSuggestionKind:e,structuralSuggestionRecord:JSON.
23
+ stringify(d)}},L=(r,e,n)=>{const c=[];let i=0;for(const o of r.children){const f=Math.max(e-i,0),l=Math.min(e+n-i,o.text.length);if(l>f&&c.push({...o,text:o.text.slice(f,l)}),i+=o.text.length,i>=e+n)break}
24
+ return c},_=(r,e,n)=>{const c=E(r),i=E(e);if(u(r)!==u(e)||P(c)*P(i)>ue){p(r,"delete",n),p(e,"insert",n);return}const o=[];let f=0,l=0,d="";const S=(R,N)=>{d||(d=h(),m.inlineChanges++);const z=P(R.map(
25
+ j=>j.text).join(""));N==="insertion"?m.insertedWords+=z:m.deletedWords+=z,o.push(...R.map(j=>{const C=q(j.marks);return{...j,marks:{...N==="deletion"?he(C):C,...K(N,d,j.marks)}}}))};for(const[R,N]of le(
26
+ c,i).diffs){if(R===-1)S(L(r,f,N.length),"deletion");else if(R===1)S(L(e,l,N.length),"insertion");else{const z=L(r,f,N.length),j=L(e,l,N.length);let C=0,D=0,F=0,Q=0;for(;C<z.length&&D<j.length;){const H=Math.
27
+ min(z[C].text.length-F,j[D].text.length-Q),oe={...z[C],text:z[C].text.slice(F,F+H)},V={...j[D],text:j[D].text.slice(Q,Q+H)},{bookmark:Ae,...ke}=q(oe.marks),{bookmark:Je,...be}=q(V.marks);de(ke,O)===de(
28
+ be,O)?(d="",o.push({...V,marks:q(V.marks)})):(S([oe],"deletion"),S([V],"insertion")),F+=H,Q+=H,F===z[C].text.length&&(C++,F=0),Q===j[D].text.length&&(D++,Q=0)}}R!==1&&(f+=N.length),R!==-1&&(l+=N.length)}
29
+ n.push({...e,children:o})},p=(r,e,n)=>{if(r.type==="table"){n.push(v(r,e));return}const c=G(r,e);c?n.push(c):(m.unmarkedBlocks++,e==="insert"&&n.push(r))},g=(r,e)=>{if(u(r)!==u(e))return 0;const n=re(
30
+ U(E(r)),U(E(e)));return n>=.5?n:0},W=(r,e,n)=>{const c=()=>{p(r,"delete",n),p(e,"insert",n)};if(r.children.length*e.children.length>Y)return c();const i=[];let o=!1;if(ne(r.children,e.children,l=>u(l)+
31
+ E(l),g,(l,d)=>i.push([l,d]),(l,d)=>i.push([l,d]),()=>o=!0,()=>o=!0,M((l,d)=>u(l)===u(d))),o||i.some(([l,d])=>u(l)!==u(d)||P(E(l))*P(E(d))>ue))return c();const f=[];for(const[l,d]of i)_(l,d,f);n.push({
32
+ ...e,children:f})},b=(r,e)=>{const n=P(T(r));e==="insert"?(m.insertedBlocks++,m.insertedWords+=n):(m.deletedBlocks++,m.deletedWords+=n)},w=(r,e)=>e==="delete"?te(ee(r,B)):r,x=(r,e,n,c)=>{const i=h();return{
33
+ id:i,record:{id:i,type:"table-change",tableId:r,source:"manual",authorType:"human",label:c[n],...k?{agentName:k}:{},tableRevision:{version:1,suggestionKind:n,markers:e.map(([o,f])=>({kind:n==="insert"?
34
+ "row-insert":"row-delete",rowId:o.id,rowIndex:f})),operations:e.map(([o,f])=>({kind:"row",action:n,rowId:o.id,rowIndex:f,row:JSON.parse(JSON.stringify(o))}))}}}},v=(r,e)=>{const n=e==="delete"?te(ee(r,
35
+ B)):r,{id:c,record:i}=x(n.id,n.children.map((o,f)=>[o,f]),e,{insert:"Insert table",delete:"Delete table"});return b(n,e),{...n,structuralSuggestionRecords:JSON.stringify([i]),children:n.children.map(o=>({
36
+ ...o,diffState:e,suggestionId:c}))}},I=(r,e)=>u(r)===u(e)&&r.children.length===e.children.length&&r.children.every((n,c)=>u(n)===u(e.children[c])),fe=(r,e)=>r.children.every((n,c)=>n.children.length*e.
37
+ children[c].children.length<=Y),Z=(r,e)=>I(r,e)&&fe(r,e),se=(r,e)=>({...e,children:e.children.map((n,c)=>({...n,children:ie(r.children[c].children,n.children)}))}),me=(r,e,n)=>{if(u(r)!==u(e)||r.children.
38
+ length*e.children.length>Y){p(r,"delete",n),p(e,"insert",n);return}const c=[],i=[],o=(l,d)=>{const S=w(l,d),{id:R,record:N}=x(e.id,[[S,c.length]],d,{insert:"Insert table row",delete:"Delete table row"});
39
+ i.push(N),b(S,d),c.push({...S,diffState:d,suggestionId:R})},f=l=>pe(l);ne(r.children,e.children,f,(l,d)=>{if(!Z(l,d))return 0;const S=re(U(T(l)),U(T(d)));return S>=.5?S:0},(l,d)=>{Z(l,d)?c.push(se(l,d)):
40
+ (o(l,"delete"),o(d,"insert"))},(l,d)=>c.push(se(l,d)),l=>o(l,"delete"),l=>o(l,"insert"),M(Z)),n.push({...e,children:c,...i.length>0?{structuralSuggestionRecords:JSON.stringify(i)}:{}})},ye=(r,e)=>{if(r.
41
+ type==="paragraph"&&e.type==="paragraph")return g(r,e);if(r.type==="list"&&e.type==="list"&&u(r)===u(e)||r.type==="table"&&e.type==="table"&&u(r)===u(e)){const n=re(U(T(r)),U(T(e)));return n>=.3?n:0}return 0};
42
+ function ie(r,e){const n=[],c=(i,o)=>{i.type==="list"&&o.type==="list"?W(i,o,n):i.type==="table"&&o.type==="table"?me(i,o,n):i.type==="paragraph"&&o.type==="paragraph"?_(i,o,n):n.push(o)};return ne(r,
43
+ e,pe,ye,c,c,i=>p(i,"delete",n),i=>p(i,"insert",n),M((i,o)=>i.type===o.type&&(i.type==="paragraph"||i.type==="list"||i.type==="table")&&u(i)===u(o))),n}return{blocks:ie(t,s),stats:m}}const ge=new WeakMap;
44
+ function T(t){const s=ge.get(t);if(s!==void 0)return s;const a=Be(t);return ge.set(t,a),a}function Be(t){return"children"in t&&Array.isArray(t.children)?t.children.map(s=>{const a=s;return a.type==="t\
45
+ ext"?a.text??"":T(s)}).join(" "):""}export{je as d};
@@ -1,6 +1,6 @@
1
- import{bK as y,l as A,bN as C,x as We,C as Re,a as Ee,bO as Ye,bP as Ue,bp as ze,br as De,bQ as He,bq as _e,bG as je,bM as Ge}from"./engine-TnK8N-gT.js";import{getLayoutBlockSpacingPx as qe,getLayoutMarginTop as Y,
1
+ import{bL as y,l as A,bO as C,x as We,C as Re,a as Ee,bP as Ye,bQ as Ue,bq as ze,bs as De,bR as He,br as _e,bH as je,bN as Ge}from"./engine-C5fxuZJo.js";import{getLayoutBlockSpacingPx as qe,getLayoutMarginTop as Y,
2
2
  getLayoutMarginRight as oe,getLayoutMarginBottom as K,getLayoutMarginLeft as U,getLayoutPageStep as Ke,getLayoutFootnoteInset as ae,getLayoutPageContentTop as Xe}from"./DocumentLayout-CsU5MR-3.js";import{
3
- g as se,f as Ve}from"./Typography-DAGM5kfI.js";import{v as Qe}from"./TableBorders-C5pNsuxP.js";function le(r){if(!r||typeof r!="object")return!1;const e=r;return e.diffState==="insert"&&!!e.suggestionId}
3
+ g as se,f as Ve}from"./Typography-XR6scRNV.js";import{v as Qe}from"./TableBorders-ARyTi49V.js";function le(r){if(!r||typeof r!="object")return!1;const e=r;return e.diffState==="insert"&&!!e.suggestionId}
4
4
  function Je(r,e){return{centerX:r.x-y.blockInsertMarkerMarginXPx,centerY:e+y.blockInsertMarkerOffsetYPx,armLength:y.blockInsertMarkerArmPx}}function ce(r,e,t,n){const{centerX:i,centerY:o,armLength:a}=Je(
5
5
  e,t);r.save(),r.strokeStyle=n.diffInsert,r.lineWidth=y.blockInsertMarkerLineWidthPx,r.lineCap="round",r.beginPath(),r.moveTo(i-a,o),r.lineTo(i+a,o),r.moveTo(i,o-a),r.lineTo(i,o+a),r.stroke(),r.restore()}
6
6
  function Ze(r,e,t,n,i,o,a){const l=a==="insert"?i.diffInsert:i.diffDelete,s=t+Math.max(n/2,8),c=e.left+y.pendingBreakRuleStartPx,f=e.right;r.save(),r.font=`${y.pendingBreakLabelFontSizePx}px Arial, sa\
@@ -57,25 +57,25 @@ e.src);if(!t)return;const n=i=>r.drawImage(i,e.x,e.y,e.width,e.height);if(L(t)){
57
57
  complete=="boolean"?!!(r.complete&&r.naturalWidth>0&&r.naturalHeight>0):!0}function ne(r){const e=O.get(r);if(e&&L(e))return re.delete(r),e;if(e&&!L(e)){const i=re.get(r);if(i){const o=O.get(i);if(o&&
58
58
  L(o))return o}return e}if(typeof Image>"u")return null;const t=re.get(r);if(t){const i=O.get(t);if(i&&L(i)){const o=new Image;return o.crossOrigin="anonymous",ve(o,r),O.set(r,o),i}}const n=new Image;return n.
59
59
  crossOrigin="anonymous",ve(n,r),O.set(r,n),n}function st(r){if(typeof fetch!="function"||!r)return!1;const e=r.trim().toLowerCase();return!(e.startsWith("data:")||e.startsWith("blob:"))}function ve(r,e){
60
- if(!st(e)){r.src=e;return}let t=0;const n=()=>{t+=1,fetch(e,{method:"HEAD"}).then(i=>{if(i.status===200){r.src=e;return}t<Se&&setTimeout(n,ke)}).catch(()=>{t<Se&&setTimeout(n,ke)})};n()}const Me="imag\
61
- e-resize-handle",Pe="image-body",we=12,W=32;class lt{constructor(){this.type="image",this.isTextBased=!1}render(e,t,n,i,o){e.save();const a=o?.renderCtx,l=n.relativeToPage?0:a?.yOffset??0,s=n.y-l,c=n.
60
+ if(!st(e)){r.src=e;return}let t=0;const n=()=>{t+=1,fetch(e,{method:"HEAD"}).then(i=>{if(i.status===200){r.src=e;return}t<Se&&setTimeout(n,ke)}).catch(()=>{t<Se&&setTimeout(n,ke)})};n()}const Pe="imag\
61
+ e-resize-handle",Me="image-body",we=12,W=32;class lt{constructor(){this.type="image",this.isTextBased=!1}render(e,t,n,i,o){e.save();const a=o?.renderCtx,l=n.relativeToPage?0:a?.yOffset??0,s=n.y-l,c=n.
62
62
  width,f=n.height,u=se(e.canvas),h=t.originalFormat||o?.forceImagePlaceholders?null:ne(t.src),g=()=>{e.fillStyle=u.pageBorder,e.globalAlpha=.2,e.fillRect(n.x,s,c,f),e.globalAlpha=1,e.strokeStyle=u.pageBorder,
63
63
  e.strokeRect(n.x,s,c,f),e.fillStyle="#6b7280",e.font="14px sans-serif",e.textAlign="center",e.textBaseline="middle";const p=t.originalFormat?`${t.originalFormat.toUpperCase()} image`:o?.forceImagePlaceholders?
64
64
  "Image unavailable":"Image";e.fillText(p,n.x+c/2,s+f/2)},d=h&&typeof h.complete=="boolean"?!!(h.complete&&h.naturalWidth>0&&h.naturalHeight>0):!0;if(h&&d?e.drawImage(h,n.x,s,c,f):(g(),h&&"onload"in h&&
65
65
  typeof h.onload=="function"&&(h.onload=()=>{typeof requestAnimationFrame=="function"&&requestAnimationFrame(()=>{const p=o?.renderCtx?.ctx??e,b=n.relativeToPage?0:o?.renderCtx?.yOffset??0;p.drawImage(
66
66
  h,n.x,n.y-b,c,f)})})),e.restore(),t.uploading&&(e.save(),e.globalAlpha=.35,e.fillStyle=u.pageBackground,e.fillRect(n.x,s,c,f),e.globalAlpha=1,e.fillStyle=u.selection,e.font="12px sans-serif",e.textAlign=
67
- "center",e.textBaseline="middle",e.fillText("Uploading…",n.x+c/2,s+f/2),e.restore()),o&&!o.isReadOnly){const p=te(t,Me),b=te(t,Pe),v=(t.align??"left")==="right",m=o.activeUIComponentKey===p,M=o.isSelected,
68
- N=o.hoveredUIComponentKey===p||o.hoveredUIComponentKey===b,P=m||N;if((P||M)&&(e.save(),e.strokeStyle=u.selection,e.lineWidth=2,e.strokeRect(n.x,s,c,f),e.restore()),P){const I=Math.max(8,Math.min(we,Math.
67
+ "center",e.textBaseline="middle",e.fillText("Uploading…",n.x+c/2,s+f/2),e.restore()),o&&!o.isReadOnly){const p=te(t,Pe),b=te(t,Me),v=(t.align??"left")==="right",m=o.activeUIComponentKey===p,P=o.isSelected,
68
+ N=o.hoveredUIComponentKey===p||o.hoveredUIComponentKey===b,M=m||N;if((M||P)&&(e.save(),e.strokeStyle=u.selection,e.lineWidth=2,e.strokeRect(n.x,s,c,f),e.restore()),M){const I=Math.max(8,Math.min(we,Math.
69
69
  min(c,f)*.25)),w=Math.max(6,Math.min(I,Math.min(c,f))),R=v?n.x:n.x+c-w,E=s+f-w;e.save(),e.globalAlpha=m?.95:.85,e.fillStyle=m?u.selection:u.pageBackground,e.fillRect(R,E,w,w),e.globalAlpha=1,e.lineWidth=
70
70
  2,e.strokeStyle=u.selection,e.strokeRect(R,E,w,w),e.restore()}}le(t)&&ce(e,n,s,u)}getBounds(e,t,n,i,o,a){const l=o.availableWidth,s=e.width||l,c=e.height||l,f=Math.min(s,l),u=s>0?f/s:1,h=Math.max(Math.
71
71
  round(c*u),1),g=e.align??"left";let d=t;return g==="center"?d=t+Math.max(0,(o.availableWidth-f)/2):g==="right"&&(d=t+Math.max(0,o.availableWidth-f)),{x:d,width:f,units:[{height:h,width:f,x:d}],margins:{
72
72
  top:o.suppressTopSpacingForFirstChild?0:qe(o,12),bottom:0}}}hitTest(e,t,n,i,o,a,l){return t>=i.x&&t<=i.x+i.width&&n>=i.y&&n<=i.y+i.height?{type:"block",bounds:i}:null}getUIComponents(e,t,n,i,o,a,l){if(l?.
73
73
  isReadOnly)return[];const s=()=>{const h=Math.max(8,Math.min(we,Math.min(t.width,t.height)*.25));return Math.max(6,Math.min(h,Math.min(t.width,t.height)))},c=e.align??"left",f=c==="right",u=f?"nesw-re\
74
- size":"nwse-resize";return[{id:Me,cursor:u,getBounds:()=>{const h=s();return{x:f?t.x:t.x+Math.max(t.width-h,0),y:t.y+Math.max(t.height-h,0),width:h,height:h}},onMouseDown:h=>{const g=h.block,d=g.width||
75
- W,p=g.height||W,b=d>0?p/d:1;let v=d,m=p;const M=h.position.x,N=h.position.y,P=h.blockBounds,I=P.x,w=P.y,R=I+d,E=w+p,Ae=P.x+P.width,Ce=I+d/2,j=f?M-I:M-R,Ne=N-E,G=(x,F)=>Math.max(W,Math.min(Math.round(x),
74
+ size":"nwse-resize";return[{id:Pe,cursor:u,getBounds:()=>{const h=s();return{x:f?t.x:t.x+Math.max(t.width-h,0),y:t.y+Math.max(t.height-h,0),width:h,height:h}},onMouseDown:h=>{const g=h.block,d=g.width||
75
+ W,p=g.height||W,b=d>0?p/d:1;let v=d,m=p;const P=h.position.x,N=h.position.y,M=h.blockBounds,I=M.x,w=M.y,R=I+d,E=w+p,Ae=M.x+M.width,Ce=I+d/2,j=f?P-I:P-R,Ne=N-E,G=(x,F)=>Math.max(W,Math.min(Math.round(x),
76
76
  F)),ie=x=>Math.max(W,Math.round(x));return{cursor:u,onMouseMove:x=>{const F=x.layout.availableWidth,q=x.position.x,Fe=x.position.y;let B;if(c==="right"){const T=q-j;B=G(Ae-T,F)}else if(c==="center"){const T=q-
77
77
  j,Oe=Math.max(W/2,T-Ce);B=G(Oe*2,F)}else{const T=q-j;B=G(T-I,F)}let $;if(x.modifiers.shiftKey){const T=Fe-Ne;$=ie(T-w)}else $=ie(B*b);if(Math.abs(B-v)<1&&Math.abs($-m)<1)return;const $e={...x.block,width:B,
78
- height:$};x.api.replaceBlock($e)&&(v=B,m=$)},onMouseUp:x=>{x.api.requestRedraw()},onCancel:()=>{}}}},{id:Pe,cursor:void 0,getBounds:()=>({x:t.x,y:t.y,width:t.width,height:t.height})}]}getFirstCursorPosition(e){
78
+ height:$};x.api.replaceBlock($e)&&(v=B,m=$)},onMouseUp:x=>{x.api.requestRedraw()},onCancel:()=>{}}}},{id:Me,cursor:void 0,getBounds:()=>({x:t.x,y:t.y,width:t.width,height:t.height})}]}getFirstCursorPosition(e){
79
79
  return null}getLastCursorPosition(e){return e.id?{block:e.id,offset:0}:{block:"",offset:0}}getNextCursorPosition(e,t){return null}getPreviousCursorPosition(e,t){return null}getCursorScreenPosition(e,t,n,i,o,a,l,s){
80
80
  const c=(t.offset??0)<=0,f=n.y+n.height;return{x:c?n.x:n.x+n.width,y:f,fontSize:o.fontSize}}getSelectionRects(e,t,n,i,o,a,l,s){return[]}getCharacterAtPoint(e,t,n,i,o,a,l){return null}getCharacterOffset(e,t){
81
81
  return 0}getPositionFromOffset(e,t){}getPlainText(e){return""}getWordCount(e){return 0}getCharCount(e){return 0}isEmpty(e){return!1}canEdit(){return!1}canMergeWith(e){return!1}mergeWith(e,t,n){return e}split(e,t){
@@ -91,13 +91,13 @@ return null}}function ct(r,e,t,n){return{ctx:r,canvas:e,layout:t,textContext:n,c
91
91
  r?.lang);return o&&!i.startsWith(o)&&(i=`${o}, ${i}`),z(i)}function Le(r,e,t,n){let i=r?.fontSize??e;if((r?.superscript||r?.subscript)&&(i=Math.round(i*.7)),r?.code)return`normal ${i}px ${Ge}`;const o=Ie(
92
92
  r,n?.para,n?.doc,t);let a="";r?.italic&&(a+="italic ");let l="normal";return r?.bold&&(l="bold"),`${a}${l} ${i}px ${o}`}function ft(r,e,t=16,n="Arial, sans-serif",i,o){const a=i?Ve(i):t;r.font=Le(e,a,
93
93
  n,{para:i,doc:o})}function ht(r,e,t){if(t.pageless)return{newY:r,pageChanged:!1};const n=Ke(t),i=t.sectionStartY??0,o=t.sectionFirstPageIndex??0,a=r-i-t.textStartY,l=Math.max(0,Math.floor(a/n)),s=i+l*
94
- n,c=K(t),f=s+t.pageHeight-c-ae(t,o+l);if(r+e>f){const u=Y(t);for(let h=1;h<=Be;h++){const g=l+h,d=i+g*n,p=o+g,b=Xe(t,p),v=ae(t,p),m=d+b,M=d+t.pageHeight-c-v;if(b<=u&&v<=0||m+e<=M||h===Be)return{newY:m,
94
+ n,c=K(t),f=s+t.pageHeight-c-ae(t,o+l);if(r+e>f){const u=Y(t);for(let h=1;h<=Be;h++){const g=l+h,d=i+g*n,p=o+g,b=Xe(t,p),v=ae(t,p),m=d+b,P=d+t.pageHeight-c-v;if(b<=u&&v<=0||m+e<=P||h===Be)return{newY:m,
95
95
  pageChanged:!0}}}return{newY:r,pageChanged:!1}}const Be=200;function ut(r,e){const{ctx:t,canvas:n,layout:i}=r,o=typeof window<"u"&&window.devicePixelRatio?window.devicePixelRatio:1,a=n.width/o/e;t.save();
96
96
  const l=r.pageGeometry,s=l?.marginTop??Y(i),c=l?.marginRight??oe(i),f=l?.marginBottom??K(i),u=l?.marginLeft??U(i),h=l?.pageHeight??i.pageHeight;if(Te(r,"back"),r.watermark&&!i.pageless&&Qe(t,r.watermark,
97
97
  a,h),!i.pageless)for(const p of l?.chromeImages??[])at(t,p);const g=!!r.headersContent,d=!!r.footersContent;if((l?l.showPageNumbers:r.pageLayoutSettings?.showPageNumbers)&&!i.pageless){const p=l?.pageNumberPosition??
98
- r.pageLayoutSettings?.pageNumberPosition??"top-right",b=p.startsWith("top");if(!(b?g:d)){const v=p.endsWith("right"),m=12,M=m/2+4,N=v?a-c:u,P=b?Math.max(M,s/2):h-Math.max(M,f/2),I=l?ze(l.renderedPageNumber,
98
+ r.pageLayoutSettings?.pageNumberPosition??"top-right",b=p.startsWith("top");if(!(b?g:d)){const v=p.endsWith("right"),m=12,P=m/2+4,N=v?a-c:u,M=b?Math.max(P,s/2):h-Math.max(P,f/2),I=l?ze(l.renderedPageNumber,
99
99
  l.pageNumberFormat):r.pageLayoutSettings?De(r.pageLayoutSettings,r.currentPage):String(r.currentPage+1);t.fillStyle=r.theme.text,t.font=`normal ${m}px ${z(i.fontFamily)}`,t.textAlign=v?"right":"left",
100
- t.textBaseline="middle",t.fillText(I,N,P)}}gt(r),dt(r),t.restore()}function dt(r){const{ctx:e,layout:t}=r;if(t.pageless)return;const n=r.pageGeometry,i=n?n.pleadingGrid:r.pageLayoutSettings?.pleadingGrid;
100
+ t.textBaseline="middle",t.fillText(I,N,M)}}gt(r),dt(r),t.restore()}function dt(r){const{ctx:e,layout:t}=r;if(t.pageless)return;const n=r.pageGeometry,i=n?n.pleadingGrid:r.pageLayoutSettings?.pleadingGrid;
101
101
  if(!i)return;const o=n?.marginTop??Y(t),a=n?.marginLeft??U(t),l=i.fontSizePx??t.fontSize,s=i.firstBaselinePx??o+l;e.save(),e.fillStyle=r.theme.text,e.font=`normal ${l}px ${z(r.pageFontFamilies?.get(r.
102
102
  currentPage+1)??i.fontFamily??t.fontFamily)}`,e.textAlign="right",e.textBaseline="alphabetic";const c=a-(i.distancePx??14);for(let f=0;f<i.rows;f++)e.fillText(String(f+1),c,s+f*i.pitchPx);e.restore()}
103
103
  function Te(r,e){const{layout:t,pageGeometry:n}=r,i=n?n.pageBorders:r.pageLayoutSettings?.pageBorders;if(!i||t.pageless||i.zOrder!==e)return;const o=72/96;He(r.ctx,_e(i,(n?.pageWidth??t.pageWidth)*o,(n?.
@@ -0,0 +1,10 @@
1
+ import{DocumentSession as m}from"./DocumentSession-gZHWP7By.js";import{g as u,a as f}from"./engine-C5fxuZJo.js";import{F as p}from"./Typography-XR6scRNV.js";import{d as y}from"./BlockDiff-C8eiZ-sf.js";
2
+ const b=[{label:"headers and footers",keys:["chrome","headers","footers"]},{label:"footnotes and endnotes",keys:["notes"]},{label:"page layout",keys:["pageLayout","pageless"]}];function d(s,r){return JSON.
3
+ stringify(r.map(e=>s[e]??null),(e,n)=>e==="id"||e.startsWith("suggestion")?void 0:n)}function c(s,r=[]){for(const e of s){if(!e||typeof e!="object")continue;const n=e;n.numberingChainId&&!r.includes(n.
4
+ numberingChainId)&&r.push(n.numberingChainId),Array.isArray(n.children)&&c(n.children,r)}return r}function h(s,r){return s.map(e=>{if(!e||typeof e!="object")return e;const n=e,t=n.numberingChainId&&r.
5
+ get(n.numberingChainId),i=Array.isArray(n.children)?h(n.children,r):void 0,a=i!==void 0&&i.some((o,g)=>o!==n.children[g]);return!t&&!a?e:{...n,...t?{numberingChainId:t}:{},...a?{children:i}:{}}})}function I(s,r){
6
+ const e=c(s.children),n=c(r.children),t=new Map;n.forEach((a,o)=>{o<e.length&&e[o]!==a&&t.set(a,e[o])});const i=new Set(e);return n.slice(e.length).forEach(a=>{i.has(a)&&t.set(a,`${a}-revised`)}),t.size?
7
+ {...r,children:h(r.children,t)}:r}function l(s){const r=new m(`compare-accept-${u()}`,s);try{const e=r.getDocumentMutator(),n=e.getLiveSuggestionIds();return n.length>0&&e.acceptLiveSuggestions(n),r.getWorkingDocument()}finally{
8
+ r.dispose()}}function k(s,r,e={}){const n=l(s),t=I(n,l(r)),i=y(n.children,t.children,{nextId:()=>`compare-${u()}`,nextBlockId:f,label:e.label??"Compare",authorName:e.authorName,pairLoneChanges:!0,defaultFontSize:t.
9
+ stylesheet?.paragraphStyles.find(o=>o.default)?.runMarks?.fontSize??p.paragraph});if(!i)return null;const a=b.filter(({keys:o})=>d(n,o)!==d(t,o)).map(({label:o})=>o);return{doc:{...t,children:i.blocks},
10
+ stats:i.stats,untrackedRegions:a}}export{l as acceptAllRevisions,k as compareDocuments};
@@ -1,8 +1,8 @@
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,
1
+ import{getLayoutMarginLeft as mt,getLayoutMarginRight as ne,getLayoutMarginBottom as kt,getLayoutMarginTop as Wt,getLayoutBlockSpacingPx as Ve,PAGINATION_EPSILON as rt,createFlowWindowTable as qe,getLayoutPageStep as xe,
2
+ getLayoutFootnoteInset as ke,declaresOwnSpaceBefore as Je,getLayoutPageContentTop as Qe}from"./DocumentLayout-CsU5MR-3.js";import{ap as ye,ae as Me,bu as Yt,bD as Ke,R as we,h as tn,e as en,t as nn,r as on,
3
+ bq as rn,bs as an,a4 as sn,bx as ln,by as oe}from"./engine-C5fxuZJo.js";import{L as cn,i as gn,j as un}from"./Typography-XR6scRNV.js";import{a as dn}from"./chromeImageLayout-DeYYS8YP.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-Cezk1s_y.js";import{v as Ye}from"./CanvasRenderer-C2vAzLWM.js";import{b as wn,c as In}from"./TableGrid-DbroRucl.js";
5
+ import{r as Sn,t as Yn}from"./TableBorders-ARyTi49V.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
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
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
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-=
@@ -77,7 +77,7 @@ const Ft=tt.marks.field==="page"?gt:String(c);return{...tt,text:Ft}})}:W,Lt=l.ch
77
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
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
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))}};
80
+ J=(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
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
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
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)){
@@ -87,14 +87,14 @@ c.blockId):[],w=c?.charOffset===void 0?f[0]:[...f].reverse().find(I=>I.charRange
87
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
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
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):
90
+ 0,Math.min(c,m))}}return l},at=(o,l)=>Math.max(0,Mt(a(o,l))-E),q=(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
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
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
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
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
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
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,
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=qe(m),K=L=>({...a(o,L),pageless:!1,lineHeight:1.25,paragraphSpacing:.25,blockSpacingPx:2,footnotePageInsets:void 0,
98
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
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
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($.
@@ -102,46 +102,46 @@ currentY-.01);tt.set(L.id,$t);for(let wt=$t;wt<=Et;wt++)A.has(wt)||A.set(wt,f(wt
102
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
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
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(
105
+ pageIndex));const g=pt(M,D,q(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
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
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
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
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
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
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.
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 J(M,X,ct),{blocks:M.blocks,fragments:M.
113
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
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
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
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
117
  return e.suppressTopSpacingForFirstChild===!0===t.suppressTopSpacingForFirstChild&&e.siblingSpaceBeforePx===t.siblingSpaceBeforePx&&e.siblingSpaceAfterPx===t.siblingSpaceAfterPx?e:{...e,...t}}function En(e){
118
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?
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):Jt(e)}const An=4;function Ce(e,t,n){const r=e.lastLineTail;return r?
120
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);
121
+ return Jt(e);const i=t.registry.getHandlerForBlock(n);if(!i)return Jt(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
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
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),
124
+ warn(`No handler for block type: ${n.type}`),t.lastLineTail;if(s.pageless)return Jt(e);const a=t.nextBlockIndex++,u=i.getBounds(n,r,t.currentY,t.textContext,s,t.doc),d=qn(t,t.currentY),p=Ce(t,u,d-t.currentY),
125
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<=
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 qt(e,t,n){if(n<=
127
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
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
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
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.
131
+ 0),S.widowControl&&v.length>=2&&(i+=Math.max(v[1].height,0));break}return i}function Jt(e){const{state:t,block:n,x:r,layout:s,followingBlocks:i}=e,a=t.registry.getHandlerForBlock(n);if(!a)return console.
132
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
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),
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&&qt(t,t.currentY,T)&&!qt(t,
135
+ Qt(t),T)&&(Re(t),y=!0)}let F=0,S=0,b=t.currentY,k,E,R,O,ht,V,J,st=Number.POSITIVE_INFINITY,Bt=Number.NEGATIVE_INFINITY,Mt,Nt=0,at,q=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,J=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
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:
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}),J&&J.length>0&&(o.lineExtents=J),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&&!qt(t,t.currentY,M)&&qt(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&&(q=!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&&(J??(J=[])).push({charEnd:T.charRange.end,bottom:t.currentY+M}),ht=ht===void 0?bt:Math.min(ht,bt),V=V===void 0?X:
142
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
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}),
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:q}),
145
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
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
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,
@@ -149,12 +149,12 @@ s,e.doc);return p||(p=[],i.set(n,p)),p.push({x:r,availableWidth:s.availableWidth
149
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
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
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}}}
152
+ pageBreakBefore:!1},ht=t.blocks.length;t.blocks.push(O);const V=t.fragments.length,J=n.children.length>0;let st=!J;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 q={};try{q=Rt({state:t,blocks:n.children,
154
+ x:Mt,layoutForLevel:at,onFirstBlockLayout:()=>{st=!0},suppressTopSpacingForFirstBlock:!0})}finally{Bt()}q.firstBlockStartY!==void 0&&q.firstBlockStartY-S<y&&(y=q.firstBlockStartY-S,O.bounds.y=y),At(t,
155
+ b)&&(J||(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),q.firstBlockStartY!==
157
+ void 0){const Pt=Math.max(t.layout.lineHeight*4,64);if(q.firstBlockStartY-y>Pt+S){const yt=q.firstBlockStartY-S;O.bounds.y=yt,O.bounds.height=Math.max(t.currentY-yt,S+b),Q.bounds={...Q.bounds,...O.bounds}}}
158
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
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
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-
@@ -168,30 +168,30 @@ s,t.blockCount,...b.blocks),e.fragments.splice(i,t.fragmentCount,...b.fragments)
168
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
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
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<
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,J=Un(V);V.pageless||(t.layout={...V,flowWindows:J});
172
+ try{const at=u.units[0]?.data,q=at?.grid??wn(n),it=at?.geometry??In(q,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:q.rows},()=>[]);for(const Z of q.cells)lt[Z.row].push(Z);const Q=new Array(q.rows).fill(0),pt=new Array(q.rows).
174
+ fill(0),Pt=V.pageless?1/0:V.pageHeight-V.textStartY-kt(V);let yt=n.hasHeader===!0&&q.rows>1&&!V.pageless&&!lt[0].some(Z=>Z.rowSpan>1),D=[],T=0,M=0,bt=0;for(let Z=0;Z<q.rows;){let X=Z+1,ct=0;for(let c=Z;c<
175
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
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
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.
178
+ row+Y.rowSpan===q.rows,isLeftCol:Y.col===0,isRightCol:Y.col+Y.colSpan===q.cols,isHeaderCell:n.hasHeader===!0&&c===0,tableBorderColor:F,tableBorderWidth:S,tableBorders:n.borders,tableCellPadding:v,gridRow:Y.
179
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
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.
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=J.indexForY(T),yt=!o&&J.indexForY(t.currentY-rt)===bt&&M<Pt,yt?(D=t.fragments.slice(h),t.layout={
182
+ ...V,flowWindows:{length:J.length,indexForY:J.indexForY,at:c=>{const f=J.at(c);return c>bt?{...f,top:f.top+M}:f}}}):M=0),Z=X}if(yt&&D.length){const Z=J.indexForY(t.currentY-rt);for(let X=bt+1;X<=Z;X++){
183
+ const ct=J.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
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
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
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
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
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
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,
190
+ push(R);const ht=t.fragments.length;let V=!(n.children.length>0);const J=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:!Je(
192
+ n.children[0])})}finally{J()}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 q={x:r,y:R.bounds.y,width:B,height:at},
194
+ it={block:n,blockIndex:d,blockId:n.id||"",fragmentIndex:0,bounds:q,pageNumber:R.pageNumber,data:{type:"table-cell",...a&&{parentTableId:a.parentTableId,tableDiffState:a.tableDiffState,rowDiffState:a.rowDiffState,
195
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
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
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};
@@ -202,11 +202,11 @@ t)return n>t?[{y:t,height:n-t}]:[];const r=e.layout.flowWindows;if(r&&r.length!=
202
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
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
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);
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 qn(e,t=e.currentY){const n=e.layout.flowWindows;if(!n||n.length===0)return Qt(e,t);
206
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
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
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){
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 Jn(e,t){
210
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
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
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.
@@ -215,4 +215,4 @@ return e.blocks.find(n=>n.blockId===t)||null}function to(e,t){return e.blocks[t]
215
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
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
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};
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,Jn as h,re as p};