@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,379 @@
1
+ import{f as K,h as Kt,u as Vt}from"./CanvasRenderer-Bqsj1S0p.js";import{b as X,e as Jt}from"./TableGrid-DbroRucl.js";import{r as et,aO as z,aP as gt,e as Gt,aQ as Xt,z as ft,aR as Zt,aS as Qt,aT as nt,
2
+ aU as Yt,W as bt,aV as yt,Q as xt,O as te,aW as $t,N as ee,a as J,C as kt,aX as ne,aY as ie,aZ as oe,a_ as re,a$ as se}from"./engine-TnK8N-gT.js";import{e as ae,r as vt,s as ce,p as le,i as de}from"./ListNumbering-Qlu6AuRZ.js";
3
+ import{i as At}from"./HorizontalRuleOrnaments-gmUZ3R7Q.js";import{d as he}from"./DocumentStylesheet-CEEt18sr.js";import{a as St,c as It,d as wt,b as Ct,e as pe,f as ue,s as Tt,g as Ft,h as Nt,i as me,
4
+ j as ge}from"./TableBorders-C5pNsuxP.js";import{h as V,H as fe,D as be}from"./Typography-DAGM5kfI.js";const Bt=/<!--[^]*?-->|<\/?[a-zA-Z][\w:-]*(?:\s+(?:[^"'<>]|"[^"]*"|'[^']*')*)?\s*\/?>/g,Ht={amp:"&",
5
+ lt:"<",gt:">",quot:'"',AMP:"&",LT:"<",GT:">",QUOT:'"',apos:"'",nbsp:" ",lsquo:"‘",rsquo:"’",sbquo:"‚",ldquo:"“",rdquo:"”",bdquo:"„",laquo:"«",raquo:"»",lsaquo:"‹",rsaquo:"›",ensp:" ",
6
+ emsp:" ",thinsp:" ",ndash:"–",mdash:"—",hellip:"…",copy:"©",reg:"®",trade:"™"},ye=/[\u0085\u2028\u2029]/g;function Lt(u){return u.replace(ye," ")}function xe(u){return u.replace(/\\+(["'])/g,
7
+ "$1")}function it(u){return xe(u.replace(/&(#(?:\d+|x[0-9a-f]+)|[a-z]+);/gi,(t,e)=>{if(!e.startsWith("#"))return Object.prototype.hasOwnProperty.call(Ht,e)?Ht[e]:t;const n=e[1].toLowerCase()==="x",i=Number.
8
+ parseInt(e.slice(n?2:1),n?16:10);return i>=0&&i<=1114111&&!(i>=55296&&i<=57343)?String.fromCodePoint(i):t}))}function ot(u){return u.search(Bt)>=0}function G(u){return it(u.replace(Bt,t=>/^<br\b/i.test(
9
+ t)?`
10
+ `:""))}function Et(u){const t=it(u);return[...new Set(ot(u)?[u,t,G(u)]:[u,t])]}function rt(u,t,e="prefer-exact",n){if(n&&e!=="normalized"){const i=Mt(u,n,t);if(i.length)return i}for(const i of Et(t)){
11
+ const o=Ot(u,i,e);if(o.length)return o}return[]}function Z(u){return u.replace(/<\/?comment-thread\b[^>]*>/gi,"")}function Pt(u,t){return ct(Z(u),Z(t))}function Mt(u,t,e){if(!ot(e))return[];t=Z(t);const n=G(
12
+ t);return n.length!==u.length||at(n)!==at(u)?[]:Pt(t,e).map(({start:i,end:o})=>({start:G(t.slice(0,i)).length,end:G(t.slice(0,o)).length})).filter(i=>i.end>i.start)}function st(u){let t="";const e=[],
13
+ n=[];for(let i=0;i<u.length;i++){const o=i;let r=zt(u[i]);if(/[\s\u0085]/u.test(r)){for(;i+1<u.length&&/[\s\u0085]/u.test(u[i+1]);)i++;r=" "}t+=r,e.push(o),n.push(i+1)}return{text:t,starts:e,ends:n}}function zt(u){
14
+ return/[\s\u0085]/u.test(u)?" ":/[\u2018-\u201b\u2039\u203a\uff07]/u.test(u)?"'":/[\u201c-\u201f\u00ab\u00bb\uff02]/u.test(u)?'"':u}function at(u){let t="";for(let e=0;e<u.length;e++){const n=zt(u[e]);
15
+ t+=/[\u2012-\u2014]/u.test(n)?"-":n}return t}function ct(u,t){if(!t)return[];const e=[];let n=0;for(;n<=u.length-t.length;){const i=u.indexOf(t,n);if(i<0)break;e.push({start:i,end:i+t.length}),n=i+1}return e}
16
+ function Ot(u,t,e="prefer-exact"){if(e!=="normalized"){const o=ct(u,t);if(o.length>0||e==="exact")return o}const n=st(u),i=st(t).text;return i.trim()?ct(n.text,i).map(({start:o,end:r})=>({start:n.starts[o],
17
+ end:n.ends[r-1]})):[]}function $e(u,t,e,n,i){for(const o of["exact","normalized"]){const r=i?i(t,o):rt(u,t,o,n),a=i?i(e,o):rt(u,e,o,n),s=[];let c=0;for(const l of r){for(;c<a.length&&a[c].start<l.end;)
18
+ c++;for(let p=c;p<a.length;p++)if(s.push({start:l.start,end:a[p].end}),s.length===2)return s}if(s.length)return s}return[]}function lt(u){if(!u)return;const t=u.trim().match(/^(\d+(?:\.\d+)?|\.\d+)(px|pt|in)?$/i);
19
+ if(!t)return;const e=parseFloat(t[1]);if(Number.isFinite(e))switch(t[2]?.toLowerCase()){case"pt":return e*4/3;case"in":return e*96;default:return e}}function Rt(u){const t=u.match(/(?:^|;)\s*margin:\s*([^;]+)/i)?.[1];
20
+ if(!t)return;const e=t.trim().split(/\s+/);if(e.length<1||e.length>4)return;const[n,i=n,o=n,r=i]=e;return{top:n,right:i,bottom:o,left:r}}function ke(u){const t={},e=Rt(u),n=u.match(/(?:^|;)\s*margin-top:\s*([^;]+)/i)?.[1]??
21
+ e?.top,i=u.match(/(?:^|;)\s*margin-bottom:\s*([^;]+)/i)?.[1]??e?.bottom,o=lt(n);o!==void 0&&(t.spaceBefore=Math.round(o*100)/100);const r=lt(i);r!==void 0&&(t.spaceAfter=Math.round(r*100)/100);const a=u.
22
+ match(/(?:^|;)\s*line-height:\s*([\d.]+)\s*(?:;|$)/i);if(a){const s=parseFloat(a[1]);Number.isFinite(s)&&s>=.5&&s<=4&&(t.lineSpacing=s)}return t}class U extends Error{constructor(t,e,n="validation",i=!1,o="\
23
+ unchanged",r){super(e),this.code=t,this.phase=n,this.retryable=i,this.mutationOutcome=o,this.details=r,this.name="SemanticToolError"}}function ve(u){return u instanceof U?{code:u.code,phase:u.phase,retryable:u.
24
+ retryable,mutationOutcome:u.mutationOutcome,details:u.details}:void 0}const Dt=24e3,jt=25;function Ae(u,t,e){const n={type:"doc",children:u},i=u.findIndex(s=>!!K({...n,children:[s]},t)),o=u.findIndex(
25
+ s=>!!K({...n,children:[s]},e)),r=u.flatMap((s,c)=>{if(s.type!=="table"||s.children.length<jt)return[s];const l=s.children.findIndex(g=>g.children.some(y=>!!K(y,t))),p=s.children.findIndex(g=>g.children.
26
+ some(y=>!!K(y,e)));if(!((i<0||c>=i)&&(o<0||c<=o))||l<0&&p<0&&i===o)return[];const m=X(s),f=Jt(m,{top:l<0?0:l,bottom:p<0?m.rows-1:p,left:0,right:m.cols-1}),d=f.top,h=f.bottom;return[{...s,children:s.children.
27
+ filter((g,y)=>s.hasHeader&&y===0||y>=d&&y<=h)}]});if(JSON.stringify(r).length<=Dt)return r;const a=[t,e].flatMap((s,c)=>{if(c&&s===t)return[];for(const l of u){const p=K({type:"doc",children:[l]},s);if(p)
28
+ return[p]}return[]});return JSON.stringify(a).length<=Dt?a:[]}const _t=u=>u.replace(/\\+u([0-9a-fA-F]{4})/g,(t,e)=>String.fromCharCode(Number.parseInt(e,16)));function Wt(u,t){if(!u)return;const e=u.trim().
29
+ toLowerCase();if(!e||e==="normal")return;const n=e.match(/^(-?\d+(?:\.\d+)?|-?\.\d+)(px|pt|em|rem|pc|in|cm|mm)?$/);if(!n)return;const i=parseFloat(n[1]);if(Number.isFinite(i))switch(n[2]??"px"){case"p\
30
+ x":return i;case"pt":return i*(96/72);case"em":return i*(t??16);case"rem":return i*16;case"pc":return i*16;case"in":return i*96;case"cm":return i*(96/2.54);case"mm":return i*(96/25.4);default:return}}
31
+ function Se(u){const t=u?.trim().match(/^([\d.]+)(px|pt)?$/i);if(!t)return;const e=parseFloat(t[1]);if(Number.isFinite(e))return t[2]?.toLowerCase()==="pt"?e*4/3:e}function Ie(u){if(!u)return;const t=i=>u.
32
+ match(new RegExp(`(?:^|;)\\s*${i}\\s*:\\s*([^;]+)`,"i"))?.[1]?.trim(),e=St(t("border")),n={};for(const i of["top","bottom","left","right"]){const o=u.match(new RegExp(`border-${i}:\\s*([\\d.]+)px\\s+(sol\
33
+ id|double|dashed|dotted|none)\\s+(#[0-9a-fA-F]{3,8}|[a-zA-Z]+)`,"i"));let r;if(o){const s=o[2].toLowerCase();r={width:s==="none"?0:parseFloat(o[1]),style:s==="solid"?"single":s,color:o[3]}}else{const s=St(
34
+ t(`border-${i}`))??e;s&&(r={...s})}if(!r)continue;const a=Se(t(`padding-${i}`));a!==void 0&&a>0&&(r.space=Math.round(a*100)/100),n[i]=r}return Object.keys(n).length>0?JSON.stringify(n):void 0}const we=new Set(
35
+ ["p","center","h1","h2","h3","h4","h5","h6","ul","ol","div","table","pre","img","latex","page-break","section-break","toc","hr","docx-raw"]),Ce=/[&<>"']/,Te=/[&<>"']/g,Fe={"&":"&amp;","<":"&lt;",">":"\
36
+ &gt;",'"':"&quot;","'":"&#039;"};function Ne(u){return Fe[u]??u}function Be(u){const t=u.trim();if(t.length<2)return t;const e=[['"','"'],["'","'"],["“","”"],["‘","’"]];for(const[n,i]of e)if(t.
37
+ startsWith(n)&&t.endsWith(i))return t.slice(n.length,t.length-i.length).trim();return t}let Q=null;function dt(u){return Q||(Q=new DOMParser().parseFromString("","text/html")),Q.body.innerHTML=u.replace(
38
+ /<!--[\s\S]*?-->|<\/?[a-z][a-z0-9-]*(?:[^<>"']|"[^"]*"|'[^']*')*>/gi,t=>{const e=t.match(/^<(page-break|section-break|docx-raw|toc)(?=[\s/>])/i);return e&&/\/\s*>$/.test(t)?t.replace(/\/\s*>$/,`></${e[1]}\
39
+ >`):t}),Q}function He(u,t={}){return!u||t.code||t.latex?u:_t(u.replace(/\\+(["'])/g,"$1"))}function qt(u){const t=new Set;function e(n){if("id"in n&&n.id&&t.add(n.id),n.type!=="paragraph"){if(n.type===
40
+ "list")for(const i of n.children)i.id&&t.add(i.id);else if(n.type==="container")for(const i of n.children)e(i);else if(n.type==="table")for(const i of n.children){i.id&&t.add(i.id);for(const o of i.children){
41
+ o.id&&t.add(o.id);for(const r of o.children)e(r)}}}}for(const n of u.children)e(n);return t}function C(u,t){if(!t?.validIds)return u||J();if(u&&t.validIds.has(u)&&!t.usedIds.has(u))return t.usedIds.add(
42
+ u),u;let e=J();for(;t.usedIds.has(e);)e=J();return t.usedIds.add(e),e}const Y=class{static createParsingContext(t){const e=new Map,n=i=>{i.type==="image"&&e.set(i.id,i),"children"in i&&i.children.forEach(
43
+ n)};n(t);for(const i of t.notes??[])n(i);return{imagesById:e,validIds:qt(t),indentStepPx:this.resolveIndentStepPx(t),documentFontFamily:this.findOmittableDocumentFontFamily(t)}}static toAgentHtml(t,e={}){
44
+ const n=this.resolveOmittableDocumentFontFamily(t,e),i=this.pageLayoutToHtmlComment(t),o=[...t.children,...t.notes??[]].map(r=>this.blockToHtml(r,t,n,e)).filter(r=>r.length>0).join(`
45
+ `);return i&&o.length>0?`${i}
46
+ ${o}`:i||o}static toInternalImageHtml(t){return this.imageBlockToHtml(t,!0)}static toInternalHtml(t){return this.toAgentHtml(t,{scanDocumentFontFamily:!1,includeImageSources:!0,includeZeroListLevels:!0})}static pageLayoutToHtmlComment(t){
47
+ const e=t.pageless===!0;if(!t.pageLayout&&!e)return null;const n=et(t.pageLayout),i=this.formatInchesForComment(z(n.marginTopPx)),o=this.formatInchesForComment(z(n.marginRightPx)),r=this.formatInchesForComment(
48
+ z(n.marginBottomPx)),a=this.formatInchesForComment(z(n.marginLeftPx)),s=this.formatInchesForComment(z(n.indentStepPx)),c=this.formatInchesForComment(z(n.blockSpacingPx)),l=n.marginTopPx===n.marginRightPx&&
49
+ n.marginTopPx===n.marginBottomPx&&n.marginTopPx===n.marginLeftPx?` margin-in="${i}"`:"",p=this.getEffectivePageNumberSettings(t,n),m=` show-page-numbers="${p.showPageNumbers?"true":"false"}" page-numb\
50
+ er-position="${p.pageNumberPosition}" page-number-start="${n.pageNumberStart}"${n.pageNumberFormat!=="decimal"?` page-number-format="${n.pageNumberFormat}"`:""}`,f=this.formatInchesForComment(gt(n.columnGapTwips));
51
+ return`<!--revise-page-layout${e?' pageless="true"':""} page-size="${n.pageSize}" orientation="${n.orientation}" margin-top-in="${i}" margin-right-in="${o}" margin-bottom-in="${r}" margin-left-in="${a}\
52
+ "${l} indent-in="${s}" block-spacing-in="${c}" column-count="${n.columnCount}" column-gap-in="${f}"${m}-->`}static formatInchesForComment(t){return Number.isFinite(t)?t.toFixed(2).replace(/\.00$/,"").
53
+ replace(/(\.\d)0$/,"$1"):"0"}static toDocumentOverview(t,e){const n=t.children.length,i=e?.pendingChangeCounts,o=e?.measurements,r=$=>{if(!i)return 0;const x=i instanceof Map?i.get($):i[$];return typeof x==
54
+ "number"&&Number.isFinite(x)?Math.max(0,Math.floor(x)):0},a=[],s=[],c=[];for(let $=0;$<t.children.length;$++){const x=t.children[$];x.id&&r(x.id)>0&&c.push($),x.type==="paragraph"&&x.heading!==void 0&&
55
+ x.heading<=2?a.push($):x.type!=="image"&&s.push($)}const l=a.length>this.MAX_OVERVIEW_BLOCKS?Math.ceil(a.length/this.MAX_OVERVIEW_BLOCKS):1,p=l>1?a.filter(($,x)=>x%l===0):a,m=Math.max(0,this.MAX_OVERVIEW_BLOCKS-
56
+ p.length),f=[];let d=1;if(m>0&&s.length>0){d=Math.max(1,Math.ceil(s.length/m));for(let $=0;$<s.length;$++)$%d===0&&f.push(s[$])}const h=Array.from(new Set([...p,...f,...c])).sort(($,x)=>$-x),g=n-1;g>=
57
+ 0&&!h.includes(g)&&h.push(g);const y=h.map($=>{const x=this.getBlockId(t.children[$]),A=r(x),k=o?.blocks?.get(x);return{index:$,id:x,type:this.getBlockTypeLabel(t.children[$]),preview:this.getBlockPreview(
58
+ t.children[$]),...k?.wordCount!==void 0?{wordCount:k.wordCount}:{},...k?.pageStart!==void 0?{pageStart:k.pageStart,pageEnd:k.pageEnd}:{},...A>0?{pendingChangeCount:A}:{},isLast:$===g}});return{title:t.
59
+ title||"Untitled",totalBlocks:n,...o?{totalWords:o.wordCount,totalParagraphs:o.paragraphCount}:{},...o?.pageCount!==void 0?{pageCount:o.pageCount}:{},blockIds:y,samplingInterval:Math.max(l,d),...o?.sections&&
60
+ o.sections.length>0?{sections:o.sections}:{}}}static toDocumentLayoutContext(t){const e=et(t.pageLayout),n=Gt(e),i=this.getEffectivePageNumberSettings(t,e);return{pageless:t.pageless===!0,pageSize:e.pageSize,
61
+ orientation:e.orientation,pageWidth:this.formatInchesLength(z(n.pageWidth)),pageHeight:this.formatInchesLength(z(n.pageHeight)),marginTop:this.formatInchesLength(z(e.marginTopPx)),marginRight:this.formatInchesLength(
62
+ z(e.marginRightPx)),marginBottom:this.formatInchesLength(z(e.marginBottomPx)),marginLeft:this.formatInchesLength(z(e.marginLeftPx)),indentStep:this.formatInchesLength(z(e.indentStepPx)),blockSpacing:this.
63
+ formatInchesLength(z(e.blockSpacingPx)),columnCount:e.columnCount,columnGap:this.formatInchesLength(gt(e.columnGapTwips)),showPageNumbers:i.showPageNumbers,pageNumberPosition:i.pageNumberPosition,pageNumberStart:e.
64
+ pageNumberStart,...e.pageNumberFormat!=="decimal"?{pageNumberFormat:e.pageNumberFormat}:{},pageBorders:e.pageBorders,...e.pageNumberRestart?{pageNumberRestart:!0}:{}}}static getEffectivePageNumberSettings(t,e){
65
+ for(const n of t.chrome??[])for(let i=0;i<n.children.length;i+=1){const o=n.children[i],r=s=>{if(!s||typeof s!="object")return!1;if(Array.isArray(s))return s.some(r);const c=s;return c.marks?.field===
66
+ "page"||r(c.children)};if(!r(o))continue;const a=i===0?"left":i===2?"right":null;return{showPageNumbers:!0,pageNumberPosition:a?`${n.side==="header"?"top":"bottom"}-${a}`:e.pageNumberPosition}}return{
67
+ showPageNumbers:e.showPageNumbers,pageNumberPosition:e.pageNumberPosition}}static formatInchesLength(t){return`${this.formatInchesForComment(t)}in`}static formatOverview(t){const e=[];if(e.push(`Docum\
68
+ ent: "${t.title}"`),e.push(`Total blocks: ${t.totalBlocks}`),t.totalWords!==void 0&&e.push(`Total words: ${t.totalWords}`),t.totalParagraphs!==void 0&&e.push(`Total paragraphs: ${t.totalParagraphs}`),
69
+ t.pageCount!==void 0&&e.push(`Pages: ${t.pageCount}`),t.sections&&t.sections.length>0){e.push(""),e.push("Sections (inclusive ranges):");for(const n of t.sections){const i=this.formatOverviewPageRange(
70
+ n.pageStart,n.pageEnd);e.push(`[${n.startIndex}-${n.endIndex} inclusive] [#${n.startBlockId}-#${n.endBlockId} inclusive] h${n.headingLevel} "${n.title}" words=${n.wordCount} paragraphs=${n.paragraphCount}${i?
71
+ ` pages=${i}`:""}`)}}t.samplingInterval>1&&e.push(`(Showing every ${t.samplingInterval}${this.ordinalSuffix(t.samplingInterval)} block ID)`),e.push(""),e.push("Block IDs:");for(const n of t.blockIds){
72
+ const i=n.preview?` — ${n.preview}`:"",o=n.wordCount!==void 0?` words=${n.wordCount}`:"",r=this.formatOverviewPageRange(n.pageStart,n.pageEnd),a=r?` pages=${r}`:"",s=n.isLast?" [LAST BLOCK]":"",c=n.
73
+ pendingChangeCount&&n.pendingChangeCount>0?` [${n.pendingChangeCount} pending ${n.pendingChangeCount===1?"change":"changes"}]`:"";e.push(`[${n.index}] ${n.id} (${n.type})${o}${a}${c}${i}${s}`)}return e.
74
+ join(`
75
+ `)}static formatOverviewPageRange(t,e){return t===void 0||e===void 0?"":t===e?`${t}`:`${t}-${e}`}static extractBlocksById(t,e,n){const i=Kt(t,e);return i===-1?null:this.extractBlocksByIndex(t,i,n)}static extractBlocksByIndex(t,e,n,i={}){
76
+ const o=Math.max(0,Math.min(e,t.children.length)),r=Math.min(n,100),a=Math.min(o+r,t.children.length),s=this.resolveOmittableDocumentFontFamily(t,i);return{html:t.children.slice(o,a).map(c=>this.blockToHtml(
77
+ c,t,s)).filter(c=>c.length>0).join(`
78
+ `),startIndex:o,endIndex:a-1,totalBlocks:t.children.length}}static formatBlockRange(t){const e=[];return e.push(`Showing blocks ${t.startIndex}-${t.endIndex} of ${t.totalBlocks} total:`),e.push(""),e.
79
+ push(t.html),e.join(`
80
+ `)}static searchDocument(t,e){const n=[],i=e.map(r=>{if(r.startsWith("regex:")){const a=r.slice(6);try{const s=new RegExp(a,"i");return{query:r,match:c=>s.test(c)}}catch{return{query:r,match:s=>s.toLowerCase().
81
+ includes(a.toLowerCase())}}}else{const a=Be(r).toLowerCase();return{query:r,match:s=>s.toLowerCase().includes(a)}}}),o=[...t.children,...t.notes??[]];for(let r=0;r<o.length;r++){const a=o[r],s=this.getBlockPlainText(
82
+ a),c=this.getBlockId(a),l=[];for(const p of i)p.match(s)&&l.push(p.query);l.length>0&&c&&n.push({blockId:c,blockIndex:r,matchedQueries:l})}return n}static findHighlights(t,e){const n=e?V(e):void 0;if(e&&
83
+ !n)return[];const i=[];for(let o=0;o<t.children.length;o++){const r=t.children[o],a=this.getBlockId(r);if(!a)continue;const s=Array.from(this.collectHighlightColors(r));s.length!==0&&(n&&!s.includes(n)||
84
+ i.push({blockId:a,blockIndex:o,matchedColors:n?[n]:s}))}return i}static extractSpecificBlocks(t,e,n,i={}){const o=[],r=[],a=[],s=[],c=new Set,l=this.resolveOmittableDocumentFontFamily(t,i),p=[...t.children,
85
+ ...t.notes??[]],m=this.findTopLevelIndexesByBlockId(t,e),f=n&&n.length>0?this.buildSelectionInfoForBlocks(p,n):null;for(const d of e){const h=m.get(d);if(h===void 0){r.push(d);continue}const g=p[h],y=this.
86
+ getBlockId(g);if(!y){r.push(d);continue}if(o.push(d),c.has(y))continue;c.add(y);const $=f?.get(y),x=this.blockToHtmlWithSelections(g,t,$,l,f??void 0);a.push(x),s.push({id:y,blockIndex:h,html:x})}return{
87
+ html:a.filter(d=>d.length>0).join(`
88
+ `),foundIds:o,missingIds:r,foundBlocks:s}}static renderSubtree(t,e){return this.blockToHtml(t,e,void 0,{scanDocumentFontFamily:!1})}static renderTableRow(t,e,n){const i=t.children.findIndex(r=>r.id===
89
+ e.id),o=this.tableRowToHtml(t,e,i,X(t),n);return`<table_row table_id="${this.escapeAttribute(t.id)}" id="${this.escapeAttribute(e.id)}" row_index="${i}">
90
+ ${o}
91
+ </table_row>`}static renderTopLevelBlocks(t,e,n={}){const i=this.resolveOmittableDocumentFontFamily(t,n),o=[],r=new Set;for(const a of e){if(r.has(a)||a<0||a>=t.children.length)continue;r.add(a);const s=t.
92
+ children[a],c=this.getBlockId(s);c&&o.push({id:c,blockIndex:a,html:this.blockToHtml(s,t,i)})}return o}static buildSelectionInfoForBlocks(t,e){const n=[],i=new Map,o=a=>{if(a.type==="paragraph"||a.type===
93
+ "list"){if(n.push(a.id),a.type==="list"){let s=0;for(const c of a.children){const l=c.children.reduce((p,m)=>p+m.text.length,0);i.set(c.id,{listId:a.id,offset:s,length:l}),s+=l+1}}}else if("children"in
94
+ a)for(const s of a.children)o(s)};t.forEach(o);const r=e.map(a=>{const s=i.get(a.startBlock),c=i.get(a.endBlock);return{...a,startBlock:s?.listId??a.startBlock,endBlock:c?.listId??a.endBlock,startOffset:s?
95
+ s.offset+(a.startOffset??0):a.startOffset,endOffset:c?c.offset+(a.endOffset??c.length):a.endOffset}});return this.buildSelectionInfoForMultiple(n,r)}static buildSelectionInfoForMultiple(t,e){const n=new Map;
96
+ for(const i of e){let o=i,r=t.indexOf(o.startBlock),a=t.indexOf(o.endBlock);if(!(r===-1||a===-1)){(r>a||r===a&&o.startOffset!==void 0&&o.endOffset!==void 0&&o.startOffset>o.endOffset)&&([r,a]=[a,r],o=
97
+ {...o,startOffset:o.endOffset,endOffset:o.startOffset});for(let s=r;s<=a;s++){const c=t[s],l={};s===r&&(l.startOffset=o.startOffset),s===a&&(l.endOffset=o.endOffset),n.has(c)||n.set(c,[]),n.get(c).push(
98
+ l)}}}return n}static blockToHtmlWithSelections(t,e,n,i,o){if(t.type==="paragraph"&&n&&n.length>0)return this.paragraphToHtmlWithSelections(t,e,n,i);if(t.type==="list"&&n?.length)return this.listToHtml(
99
+ t,i,e,{},n);const r=this.blockToHtml(t,e,i);if(!o?.size||!("children"in t))return r;const a=[],s=l=>{const p=o.get(l.id);(l.type==="paragraph"||l.type==="list")&&p?.length?a.push({block:l,ranges:p}):"\
100
+ children"in l&&l.type!=="list"&&l.children.forEach(m=>s(m))};if(t.children.forEach(l=>s(l)),!a.length)return r;const c=document.createElement("div");c.innerHTML=r;for(const l of a){const p=Array.from(
101
+ c.querySelectorAll("[id]")).find(m=>m.id===l.block.id);p&&(p.outerHTML=this.blockToHtmlWithSelections(l.block,e,l.ranges,i))}return c.innerHTML}static paragraphToHtmlWithSelections(t,e,n,i){if(t.type!==
102
+ "paragraph")return"";const o=t.heading?this.extractUniformTextFontSize(t.children):void 0,r=this.textNodesToHtmlWithSelections(t.children,e,n,i,t),a=[];t.align&&a.push(`text-align: ${t.align}`),this.appendParagraphIndentStyles(
103
+ a,t,this.resolveIndentStepPx(e)),t.heading&&o!==void 0&&a.push(`font-size: ${o}px`);const s=a.length>0?` style="${a.join("; ")}"`:"",c=t.id?` id="${this.escapeHtml(t.id)}"`:"",l=t.styleId?` data-style\
104
+ -id="${this.escapeHtml(t.styleId)}"`:"",p=t.tabStops?` data-tab-stops="${this.escapeHtml(t.tabStops)}"`:"",m=t.direction?` dir="${t.direction}"`:"";return t.heading?`<h${t.heading}${c}${m}${l}${p}${s}\
105
+ >${r}</h${t.heading}>`:`<p${c}${m}${l}${p}${s}>${r}</p>`}static textNodesToHtmlWithSelections(t,e,n,i,o){const r=this.extractUniformTextFontFamily(t);let a=0;for(const d of t)d.type==="text"&&(a+=d.text.
106
+ length);const s=[];n.forEach((d,h)=>{const g=d.startOffset??0,y=d.endOffset??a;s.push({pos:g,type:"open",idx:h}),s.push({pos:y,type:"close",idx:h})}),s.sort((d,h)=>d.pos!==h.pos?d.pos-h.pos:d.type==="\
107
+ open"&&h.type==="close"?-1:d.type==="close"&&h.type==="open"?1:0);let c=0,l=0;const p=[],m=o?.heading?this.extractUniformTextFontSize(t):void 0,f=this.coalesceAdjacentTextNodesForHtml(t,r,o?.heading?m:
108
+ void 0,i);for(const d of f)if(d.type==="text"){const h=d.text,g=c,y=c+h.length;let $=0;for(;l<s.length&&s[l].pos<=y;){const x=s[l];if(x.pos>g+$){const A=h.slice($,x.pos-g);p.push(this.textToHtmlWithMarks(
109
+ A,d.marks,o,e,m,r,i)),$=x.pos-g}p.push(x.type==="open"?"<user-selection>":"</user-selection>"),l++}if($<h.length){const x=h.slice($);p.push(this.textToHtmlWithMarks(x,d.marks,o,e,m,r,i))}c=y}for(;l<s.
110
+ length;){const d=s[l];p.push(d.type==="open"?"<user-selection>":"</user-selection>"),l++}return p.join("")}static textToHtmlWithMarks(t,e,n,i,o,r,a){let s=this.escapeHtml(t);if(s=s.replace(/\r\n|\r|\n/g,
111
+ "<br>"),e){const c=[];if(e.fontFamily){const d=r??Vt(void 0,n,i,this.DEFAULT_FONT_FAMILY);e.fontFamily!==d&&e.fontFamily!==a&&c.push(`font-family: ${this.escapeHtml(e.fontFamily)}`)}if(e.bold&&(s=`<b>${s}\
112
+ </b>`),e.italic&&(s=`<i>${s}</i>`),e.underline&&(s=`<u>${s}</u>`),e.strikethrough&&(s=`<s>${s}</s>`),e.code&&(s=`<code>${s}</code>`),e.latex&&(s=`<latex-inline>${s}</latex-inline>`),e.superscript||e.footnoteRef||
113
+ e.footnotePendingBody){const d=[];e.footnoteRef&&d.push(`data-footnote-ref="${this.escapeHtml(e.footnoteRef)}"`),e.footnotePendingBody!==void 0&&(d.push(`data-footnote="${this.escapeHtml(e.footnotePendingBody)}\
114
+ "`),e.footnotePendingKind==="endnote"&&d.push('data-note-kind="endnote"')),s=`<sup${d.length>0?` ${d.join(" ")}`:""}>${s}</sup>`}e.subscript&&(s=`<sub>${s}</sub>`),e.fontSize&&!(n?.heading&&o===e.fontSize)&&
115
+ c.push(`font-size: ${e.fontSize}px`),e.color&&c.push(`color: ${this.escapeHtml(e.color)}`),e.doubleStrikethrough&&c.push("text-decoration: line-through double"),e.smallCaps&&c.push("font-variant: smal\
116
+ l-caps"),e.allCaps&&c.push("text-transform: uppercase"),typeof e.letterSpacing=="number"&&Number.isFinite(e.letterSpacing)&&c.push(`letter-spacing: ${e.letterSpacing}px`);const l=[];c.length>0&&l.push(
117
+ `style="${c.join("; ")}"`);const p=Xt(e);p.length>0&&l.push(`data-docx-explicit-false-marks="${p.join(",")}"`);const m=ft(e.docxRunPropertyResets);m&&l.push(`data-docx-run-property-resets="${m}"`),l.length>
118
+ 0&&(s=`<span ${l.join(" ")}>${s}</span>`),e.hidden&&(s=`<span data-word-hidden="true">${s}</span>`),e.bookmark&&(s=`<span data-bookmark="${this.escapeHtml(e.bookmark)}">${s}</span>`),e.fieldInstr&&(s=
119
+ `<span data-field-instr="${this.escapeHtml(e.fieldInstr)}">${s}</span>`);const f=V(e.backgroundColor);f&&(s=`<mark color="${this.escapeHtml(f)}">${s}</mark>`),e.link&&(s=`<a href="${this.escapeHtml(e.
120
+ link)}">${s}</a>`),e.comment&&i&&(s=this.wrapWithCommentThreads(s,e.comment.split(","),i))}return s}static formatSpecificBlocks(t){const e=[],n=t.foundBlocks&&t.foundBlocks.length>0?t.foundBlocks.length:
121
+ t.foundIds.length;if(t.missingIds.length>0&&(e.push(`Note: ${t.missingIds.length} block(s) not found: ${t.missingIds.join(", ")}`),e.push("")),e.push(`Showing ${n} block(s):`),e.push(""),t.foundBlocks&&
122
+ t.foundBlocks.length>0)for(let i=0;i<t.foundBlocks.length;i++){const o=t.foundBlocks[i];if(i>0){const r=t.foundBlocks[i-1],a=o.blockIndex-r.blockIndex-1;if(a>0){const s=a===1?"block":"blocks";e.push(`\
123
+ (${a} ${s} omitted...)`)}}e.push(o.html)}else e.push(t.html);return e.join(`
124
+ `)}static getBlockId(t){return"id"in t&&t.id?t.id:""}static getBlockTypeLabel(t){return t.type==="paragraph"&&t.heading!==void 0&&t.heading>=1&&t.heading<=6?`h${t.heading}`:t.type}static getBlockPreview(t){
125
+ const e=this.getBlockPlainText(t).split(/\s+/).filter(i=>i.length>0),n=e.slice(0,10).join(" ");return e.length>10?n+"...":n}static getBlockPlainText(t){switch(t.type){case"paragraph":return t.children.
126
+ map(e=>e.type==="text"?e.text:"").join("");case"list":return t.children.map(e=>e.children.map(n=>n.type==="text"?n.text:"").join("")).join(" ");case"code":return t.content||"";case"table":return"[tabl\
127
+ e] "+t.children.flatMap(e=>e.children).map(e=>this.getBlockPlainText(e)).join(" ");case"table-cell":case"container":case"footnote":return t.children.map(e=>this.getBlockPlainText(e)).join(" ");case"im\
128
+ age":return`[image${t.alt?`: ${t.alt}`:""}]`;case"math":return`[math: ${t.content||""}]`;case"docx-raw":return`[${t.tagName}${t.detail?`: ${t.detail}`:""}]`;case"page-break":return"[page break]";case"\
129
+ section-break":return"[section break]";case"toc":return"[table of contents]";default:return""}}static collectHighlightColors(t,e=new Set){switch(t.type){case"paragraph":for(const n of t.children){const i=V(
130
+ n.marks?.backgroundColor);i&&e.add(i)}break;case"list":for(const n of t.children)for(const i of n.children){const o=V(i.marks?.backgroundColor);o&&e.add(o)}break;case"container":for(const n of t.children)
131
+ this.collectHighlightColors(n,e);break;case"table":for(const n of t.children)for(const i of n.children)for(const o of i.children)this.collectHighlightColors(o,e);break}return e}static ordinalSuffix(t){
132
+ const e=["th","st","nd","rd"],n=t%100;return e[(n-20)%10]||e[n]||e[0]}static blockToHtml(t,e,n,i={}){let o;switch(t.type){case"placeholder":o="";break;case"image":o=this.imageBlockToHtml(t,i.includeImageSources);
133
+ break;case"list":o=this.listToHtml(t,n,e,i);break;case"container":o=this.containerToHtml(t,e,n,i);break;case"table":o=this.tableToHtml(t,e,n,i);break;case"table-cell":o=this.tableCellToHtml(t,e,n,i);break;case"\
134
+ paragraph":o=this.paragraphToHtml(t,e,n);break;case"code":o=this.codeBlockToHtml(t);break;case"math":o=this.mathBlockToHtml(t);break;case"page-break":o=this.pageBreakToHtml(t);break;case"docx-raw":o=this.
135
+ docxRawToHtml(t);break;case"section-break":o=this.sectionBreakToHtml(t);break;case"toc":o=this.tocToHtml(t);break;case"header-footer":o="";break;case"footnote":o=this.footnoteToHtml(t,e,n,i);break;default:
136
+ o="";break}if(!o||!e||!("id"in t)||!t.id)return o;const r=(e.comments??[]).filter(a=>!a.parentId&&a.anchorBlockId===t.id).map(a=>a.id);return this.wrapWithCommentThreads(o,r,e)}static footnoteToHtml(t,e,n,i={}){
137
+ const o=t.children.map(r=>this.blockToHtml(r,e,n,i)).filter(Boolean).join("");return`<aside data-footnote data-note-kind="${t.noteKind==="endnote"?"endnote":"footnote"}" id="${t.id}">${o}</aside>`}static docxRawToHtml(t){
138
+ const e=t.id?` id="${this.escapeAttribute(t.id)}"`:"",n=t.detail?` detail="${this.escapeAttribute(t.detail)}"`:"";return`<docx-raw${e} tag="${this.escapeAttribute(t.tagName)}"${n} />`}static pageBreakToHtml(t){
139
+ return`<page-break${t.id?` id="${this.escapeAttribute(t.id)}"`:""} />`}static sectionBreakToHtml(t){const e=t.id?` id="${this.escapeAttribute(t.id)}"`:"",n=t.breakType?` break-type="${this.escapeAttribute(
140
+ t.breakType)}"`:"",i=t.layout?` layout="${this.escapeAttribute(JSON.stringify(t.layout))}"`:"";return`<section-break${e}${n}${i} />`}static tocToHtml(t){const e=t.id?` id="${this.escapeAttribute(t.id)}\
141
+ "`:"",n=[];t.direction&&n.push(`direction: ${t.direction}`),t.align&&n.push(`text-align: ${t.align}`),t.fontFamily&&n.push(`font-family: ${t.fontFamily}`),t.fontSize&&n.push(`font-size: ${t.fontSize}p\
142
+ x`),t.color&&n.push(`color: ${t.color}`);const i=n.length>0?` style="${this.escapeAttribute(n.join("; "))}"`:"";return`<toc${e} levels="${Zt(t)}"${t.direction?` dir="${t.direction}"`:""}${i}></toc>`}static codeBlockToHtml(t){
143
+ const e=t.language?.trim().toLowerCase();if(e==="latex"||e==="latex-inline"){const r=t.id?` id="${this.escapeAttribute(t.id)}"`:"",a=e==="latex-inline"?' display="inline"':"",s=this.escapeHtml(t.content||
144
+ "");return`<latex${r}${a}>${s}</latex>`}const n=t.id?` id="${this.escapeAttribute(t.id)}"`:"",i=t.language?` language="${this.escapeAttribute(t.language)}"`:"",o=this.escapeHtml(t.content||"");return`\
145
+ <pre${n}${i}>${o}</pre>`}static mathBlockToHtml(t){const e=t.id?` id="${this.escapeAttribute(t.id)}"`:"",n=t.displayMode&&t.displayMode!=="block"?` display="${t.displayMode}"`:"",i=t.align&&t.align!==
146
+ "center"?` align="${t.align}"`:"",o=this.escapeHtml(t.content||"");return`<latex${e}${n}${i}>${o}</latex>`}static paragraphToHtml(t,e,n){if(t.type!=="paragraph")return"";const i=this.paragraphCarriesNonRuleLayout(
147
+ t)?null:Qt(t);if(i){const d=t.id?` id="${this.escapeHtml(t.id)}"`:"",h=At(i.style),g=i.width===nt.width&&i.color.toLowerCase()===nt.color.toLowerCase(),y=h?` data-rule="${i.style}"`:"";let $="";if(!g||
148
+ !h&&i.style!==nt.style){const x=h||i.style==="single"?"solid":i.style;$=` style="border-bottom: ${i.width}px ${x} ${i.color}"`}return`<hr${d}${y}${$} />`}const o=this.extractUniformTextFontFamily(t.children),
149
+ r=t.heading?this.extractUniformTextFontSize(t.children):void 0,a=this.coalesceAdjacentTextNodesForHtml(t.children,o,t.heading?r:void 0,n).map(d=>d.type==="text"?this.textNodeToHtml(d,t,e,r,o,n):"").join(
150
+ ""),s=[];t.align&&s.push(`text-align: ${t.align}`),this.appendParagraphIndentStyles(s,t,this.resolveIndentStepPx(e)),t.heading&&r!==void 0&&s.push(`font-size: ${r}px`),o&&o!==n&&s.push(`font-family: ${this.
151
+ escapeAttribute(o)}`);const c=s.length>0?` style="${s.join("; ")}"`:"",l=t.id?` id="${this.escapeHtml(t.id)}"`:"",p=t.styleId?` data-style-id="${this.escapeHtml(t.styleId)}"`:"",m=t.tabStops?` data-ta\
152
+ b-stops="${this.escapeHtml(t.tabStops)}"`:"",f=t.direction?` dir="${t.direction}"`:"";return t.heading?`<h${t.heading}${l}${f}${p}${m}${c}>${a}</h${t.heading}>`:`<p${l}${f}${p}${m}${c}>${a}</p>`}static paragraphCarriesNonRuleLayout(t){
153
+ if(t.spaceBefore!==void 0||t.spaceAfter!==void 0||t.lineSpacing!==void 0||t.keepNext||t.keepLines||t.widowControl===!1)return!0;if(!t.borders)return!1;try{const e=JSON.parse(t.borders)?.bottom;return typeof e?.
154
+ space=="number"&&e.space>0}catch{return!1}}static textNodeToHtml(t,e,n,i,o,r){return this.textToHtmlWithMarks(t.text,t.marks,e,n,i,o,r)}static coalesceAdjacentTextNodesForHtml(t,e,n,i){if(t.length<=1)
155
+ return t;const o=[];let r=null;for(const a of t){const s=this.getTextSerializationKey(a.marks,e,n,i),c=o[o.length-1];if(c&&r===s){c.text+=a.text;continue}o.push({...a,marks:a.marks?{...a.marks}:void 0}),
156
+ r=s}return o}static getTextSerializationKey(t,e,n,i){const o=t?.fontFamily&&t.fontFamily!==e&&t.fontFamily!==i?t.fontFamily:null,r=t?.fontSize!==void 0&&t.fontSize!==n?t.fontSize:null;return JSON.stringify(
157
+ [o,r,t?.bold,t?.italic,t?.underline,t?.strikethrough,t?.doubleStrikethrough,t?.code,t?.latex,t?.superscript,t?.subscript,t?.footnoteRef,t?.footnotePendingBody,t?.footnotePendingKind,t?.color,V(t?.backgroundColor)??
158
+ null,t?.smallCaps,t?.allCaps,t?.letterSpacing,t?.hidden,t?.bookmark,t?.fieldInstr,t?.link,t?.comment,ft(t?.docxRunPropertyResets)])}static wrapWithCommentThreads(t,e,n){const i=Array.from(new Set(e.map(
159
+ o=>o.trim()).filter(Boolean))).sort();for(const o of i.reverse()){const r=(n.comments??[]).find(p=>p.id===o&&!p.parentId),a=r?this.collectCommentThreadRecords(r.id,n):[],s=this.serializeCommentTranscript(
160
+ a),c=r?.resolved===!0?"true":"false",l=r?.suggestionId?` suggestion-id="${this.escapeAttribute(r.suggestionId)}"`:"";t=`<comment-thread id="${this.escapeAttribute(o)}" resolved="${c}"${l} transcript="${this.
161
+ escapeAttribute(s)}">${t}</comment-thread>`}return t}static collectCommentThreadRecords(t,e){const n=e.comments??[],i=new Set([t]);let o=!0;for(;o;){o=!1;for(const r of n)r.parentId&&i.has(r.parentId)&&
162
+ !i.has(r.id)&&(i.add(r.id),o=!0)}return n.filter(r=>i.has(r.id)).sort((r,a)=>(r.createdAt??"").localeCompare(a.createdAt??""))}static serializeCommentTranscript(t){const e=t.length<=20?t:[t[0],...t.slice(
163
+ -19)],n=(s,c)=>{const l=s.agentName??s.author,p=(s.authorType??"human")==="ai"?" (AI)":"",m=(s.createdAt??"").slice(0,10),f=s.bodyMd.replace(/\s+/g," ").trim(),d=f.length>c?`${f.slice(0,c)}…`:f;return`${l}${p}${m?
164
+ ` on ${m}`:""}: ${d}`},i=(s,c)=>(c?["(older replies omitted)",...s]:s).join(" — "),o=t.length>e.length;let r=i(e.map(s=>n(s,2e3)),o);if(r.length<=4e3)return r;const a=Math.max(80,Math.floor(4e3/Math.
165
+ max(1,e.length)-60));return r=i(e.map(s=>n(s,a)),!0),r.length<=4e3?r:i(e.slice(-5).map(s=>n(s,300)),!0)}static normalizeAgentHighlightColor(t){return V(t)}static escapeHtml(t){const e=Lt(t);return Ce.
166
+ test(e)?e.replace(Te,Ne):e}static escapeAttribute(t){return this.escapeHtml(t)}static resolveFontToCss(t){if(this.isDisallowedFontFamilyValue(t))throw new Error('font-family does not support CSS-wide \
167
+ values like "inherit"; use a concrete font family such as "Arial, sans-serif".');if(t.includes(",")||t.includes("'")||t.includes('"'))return t;const e=Yt.find(n=>n.value===t.toLowerCase());return e?e.
168
+ cssValue:t}static isDisallowedFontFamilyValue(t){const e=t.trim().replace(/\s*!important\s*$/i,"").trim().toLowerCase();return["inherit","initial","unset","revert","revert-layer"].includes(e)}static extractFontSizeFromStyle(t){
169
+ const e=t.match(/font-size:\s*(\d+(?:\.\d+)?)(px|pt)?/i);if(!e)return;const n=parseFloat(e[1]);if(Number.isFinite(n))return e[2]?.toLowerCase()==="pt"?n*4/3:n}static extractTextStyleMarksFromStyle(t){
170
+ const e={},n=this.extractFontSizeFromStyle(t);n!==void 0&&n>0&&(e.fontSize=n),this.parseCssFontWeightToBold(t)&&(e.bold=!0),/(?:^|;)\s*font-style:\s*(italic|oblique)/i.test(t)&&(e.italic=!0);const i=t.
171
+ match(/(?:^|;)\s*color:\s*([^;]+)/i);if(i){const a=bt(i[1].trim());a&&!yt(a)&&(e.color=a)}const o=t.match(/(?:^|;)\s*letter-spacing:\s*([^;]+)/i);if(o){const a=Wt(o[1].trim(),e.fontSize);a!==void 0&&(e.
172
+ letterSpacing=a)}const r=t.match(/(?:^|;)\s*font-family:\s*([^;]+)/i);if(r){const a=r[1].trim();this.isDisallowedFontFamilyValue(a)||(e.fontFamily=this.resolveFontToCss(a))}return e}static parseCssFontWeightToBold(t){
173
+ const e=t.match(/(?:^|;)\s*font-weight:\s*([^;]+)/i);if(!e)return;const n=e[1].trim().toLowerCase();if(n==="bold"||n==="bolder")return!0;if(n==="normal"||n==="lighter")return!1;const i=parseInt(n,10);
174
+ if(Number.isFinite(i))return i>=600}static resolveIndentStepPx(t){return et(t?.pageLayout).indentStepPx}static applyParagraphElementAttributes(t,e,n){const i=e.getAttribute("style");if(i){const s=this.
175
+ extractParagraphStyleAttributes(i,n);s.align&&(t.align=s.align),s.leftIndent!==void 0&&(t.leftIndent=s.leftIndent),s.firstLineIndent!==void 0&&(t.firstLineIndent=s.firstLineIndent),s.keepNext&&(t.keepNext=
176
+ !0),s.keepLines&&(t.keepLines=!0),s.widowControl===!1&&(t.widowControl=!1);const c=s;c.borders&&(t.borders=c.borders),c.shading&&(t.shading=c.shading),this.applyParagraphSpacingAttributes(t,s)}const o=e.
177
+ getAttribute("data-style-id");o&&(t.styleId=o);const r=e.getAttribute("data-tab-stops");r&&(t.tabStops=r);const a=e.getAttribute("dir")?.trim().toLowerCase();(a==="rtl"||a==="ltr")&&(t.direction=a)}static applyParagraphSpacingAttributes(t,e){
178
+ e.spaceBefore!==void 0&&(t.spaceBefore=e.spaceBefore),e.spaceAfter!==void 0&&(t.spaceAfter=e.spaceAfter),e.lineSpacing!==void 0&&(t.lineSpacing=e.lineSpacing)}static cssLengthToPx(t){return lt(t)}static extractParagraphStyleAttributes(t,e=this.
179
+ resolveIndentStepPx()){const n={};/break-after:\s*avoid/i.test(t)&&(n.keepNext=!0),/break-inside:\s*avoid/i.test(t)&&(n.keepLines=!0),/(?:^|;)\s*(?:widows|orphans):\s*1\b/i.test(t)&&(n.widowControl=!1);
180
+ {const p=Ie(t);p&&(n.borders=p);const m=t.match(/(?:^|;)\s*background-color:\s*(#[0-9a-fA-F]{3,8}|transparent)/i);m&&(n.shading=m[1])}const i=t.match(/text-align:\s*([^;]+)/i);if(i){const p=i[1].trim().
181
+ toLowerCase();(p==="left"||p==="center"||p==="right"||p==="justify")&&(n.align=p)}Object.assign(n,ke(t));const o=Rt(t)?.left,r=t.match(/margin-left:\s*([^;]+)/i),a=this.cssLengthToPx(o)?o:void 0,s=xt(
182
+ r?.[1]??a,{indentStepPx:e});s!==void 0&&(n.leftIndent=s);const c=t.match(/text-indent:\s*([^;]+)/i),l=xt(c?.[1],{indentStepPx:e,firstLine:!0});return l!==void 0&&(n.firstLineIndent=l),n}static appendParagraphIndentStyles(t,e,n){
183
+ const i=e.leftIndent===0?0:te(e.leftIndent);i!==void 0&&t.push(`margin-left: ${$t(i,n)}px`);const o=e.firstLineIndent===0?0:ee(e.firstLineIndent);if(o!==void 0&&t.push(`text-indent: ${Math.sign(o)*$t(
184
+ Math.abs(o),n)}px`),typeof e.spaceBefore=="number"&&t.push(`margin-top: ${e.spaceBefore}px`),typeof e.spaceAfter=="number"&&t.push(`margin-bottom: ${e.spaceAfter}px`),typeof e.lineSpacing=="number"&&t.
185
+ push(`line-height: ${e.lineSpacing}`),e.keepNext&&t.push("break-after: avoid"),e.keepLines&&t.push("break-inside: avoid"),e.widowControl===!1&&t.push("orphans: 1"),e.shading&&t.push(`background-color:\
186
+ ${e.shading}`),e.borders)try{const r=JSON.parse(e.borders);for(const a of["top","bottom","left","right"]){const s=r[a];if(!s)continue;const c=s.style==="none"?"none":s.style==="double"||s.style==="da\
187
+ shed"||s.style==="dotted"?s.style:"solid";t.push(`border-${a}: ${s.style==="none"?0:s.width??1}px ${c} ${s.color??"#000000"}`),typeof s.space=="number"&&s.space>0&&t.push(`padding-${a}: ${s.space}px`)}}catch{}}static extractUniformTextFontFamily(t){
188
+ let e,n=!1;for(const i of t){if(i.type!=="text"||i.text.length===0)continue;const o=i.marks?.fontFamily;if(o===void 0)return;if(e===void 0)e=o;else if(e!==o)return;n=!0}return n?e:void 0}static extractUniformTextFontSize(t){
189
+ let e,n=!1;for(const i of t){if(i.type!=="text"||i.text.length===0)continue;const o=i.marks?.fontSize;if(o===void 0)return;if(e===void 0)e=o;else if(e!==o)return;n=!0}return n?e:void 0}static findOmittableDocumentFontFamily(t){
190
+ if(!t)return;const e=new Set,n=o=>{for(const r of o)if(!(r.type!=="text"||r.text.length===0)&&(e.add(r.marks?.fontFamily??this.DEFAULT_FONT_FAMILY),e.size>1))return},i=o=>{if(!(e.size>1))switch(o.type){case"\
191
+ paragraph":n(o.children);break;case"list":for(const r of o.children)if(n(r.children),e.size>1)return;break;case"container":for(const r of o.children)if(i(r),e.size>1)return;break;case"table":for(const r of o.
192
+ children)for(const a of r.children)for(const s of a.children)if(i(s),e.size>1)return;break;case"table-cell":for(const r of o.children)if(i(r),e.size>1)return;break}};for(const o of t.children)if(i(o),
193
+ e.size>1)return;return e.size===1?Array.from(e)[0]:void 0}static resolveOmittableDocumentFontFamily(t,e={}){if(e.scanDocumentFontFamily!==!1)return this.findOmittableDocumentFontFamily(t)}static findTopLevelIndexesByBlockId(t,e){
194
+ const n=new Map,i=new Set(e);if(i.size===0)return n;const o=[...t.children,...t.notes??[]];for(let r=0;r<o.length;r++){const a=this.getBlockId(o[r]);if(a&&i.has(a)&&(n.set(a,r),i.delete(a),i.size===0))
195
+ return n}for(let r=0;r<o.length&&(this.collectRequestedBlockIndexesForTopLevel(o[r],i,n,{topLevelIndex:r,includeRootBlock:!1}),i.size!==0);r++);return n}static collectRequestedBlockIndexesForTopLevel(t,e,n,i){
196
+ if(e.size!==0&&!(i.includeRootBlock&&t.id&&e.has(t.id)&&(n.set(t.id,i.topLevelIndex),e.delete(t.id),e.size===0)))switch(t.type){case"list":for(const o of t.children)if(o.id&&e.has(o.id)&&(n.set(o.id,i.
197
+ topLevelIndex),e.delete(o.id),e.size===0))return;break;case"container":case"table-cell":case"footnote":for(const o of t.children)if(this.collectRequestedBlockIndexesForTopLevel(o,e,n,{topLevelIndex:i.
198
+ topLevelIndex,includeRootBlock:!0}),e.size===0)return;break;case"table":for(const o of t.children){if(o.id&&e.has(o.id)&&(n.set(o.id,i.topLevelIndex),e.delete(o.id),e.size===0))return;for(const r of o.
199
+ children){if(r.id&&e.has(r.id)&&(n.set(r.id,i.topLevelIndex),e.delete(r.id),e.size===0))return;for(const a of r.children)if(this.collectRequestedBlockIndexesForTopLevel(a,e,n,{topLevelIndex:i.topLevelIndex,
200
+ includeRootBlock:!0}),e.size===0)return}}break}}static imageBlockToHtml(t,e=!1){const n=t.alt?` alt="${this.escapeAttribute(t.alt)}"`:"",i=t.align?` align="${t.align}" data-align="${t.align}"`:"",o=this.
201
+ getImageStyle(t),r=o?` style="${o}"`:"",a=Math.max(1,Math.round(t.width)),s=Math.max(1,Math.round(t.height)),c=t.sourceUrl?` data-source-url="${this.escapeAttribute(t.sourceUrl)}"`:"",l=e?` src="${this.
202
+ escapeAttribute(t.src)}"`:' data-image-source="hidden"';return`<img id="${this.escapeAttribute(t.id)}"${l}${c} width="${a}" height="${s}"${n}${i}${r}>`}static listToHtml(t,e,n,i={},o){const r=t.variant===
203
+ "ordered"?"ol":"ul",a=new Map;let s=0;for(const x of t.children){const A=x.children.reduce((v,b)=>v+b.text.length,0),k=(o??[]).flatMap(v=>{const b=Math.max(0,(v.startOffset??0)-s),S=Math.min(A,(v.endOffset??
204
+ 1/0)-s);return b<S?[{startOffset:b,endOffset:S}]:[]});k.length&&a.set(x,k),s+=A+1}const c=(x,A)=>{const k=[];let v=0;for(;v<x.length;){const b=x[v],S=b.indentLevel||0;if(S<A)break;if(S>=A){const I=this.
205
+ extractUniformTextFontFamily(b.children),E=[...b.lineSpacing!==void 0?[`line-height: ${b.lineSpacing}`]:[],...b.spaceBefore!==void 0?[`margin-top: ${b.spaceBefore}px`]:[],...b.spaceAfter!==void 0?[`ma\
206
+ rgin-bottom: ${b.spaceAfter}px`]:[]];I&&I!==e&&E.push(`font-family: ${this.escapeHtml(I)}`);const F=E.length>0?` style="${E.join("; ")}"`:"",N=b.id?` id="${this.escapeAttribute(b.id)}"`:"",P=b.direction?
207
+ ` dir="${b.direction}"`:"",D=S!==0||i.includeZeroListLevels?` data-indent-level="${S}"`:"",W=`${N}${F}${P}${D}`,B=a.get(b),j=B?this.textNodesToHtmlWithSelections(b.children,n,B,e):this.coalesceAdjacentTextNodesForHtml(
208
+ b.children,I,void 0,e).map(M=>M.type==="text"?this.textNodeToHtml(M,void 0,n,void 0,I,e):"").join(""),R=[];let T=v+1;for(;T<x.length&&(x[T].indentLevel||0)>S;)R.push(x[T]),T++;let H=j;if(R.length>0){const M=t.
209
+ variant==="ordered"?"ol":"ul",_=`<${M}>${c(R,S+1)}</${M}>`;H=j+_}if(t.variant==="todo"&&(H=`<input type="checkbox"${b.checked?" checked":""}>${H}`),n&&b.id){const M=(n.comments??[]).filter(_=>!_.parentId&&
210
+ _.anchorBlockId===b.id).map(_=>_.id);H=this.wrapWithCommentThreads(H,M,n)}k.push(`<li${W}>${H}</li>`),v=T}else v++}return k.join("")},l=c(t.children,0),p=t.id?` id="${this.escapeAttribute(t.id)}"`:"",
211
+ m=t.variant==="ordered"?ae((n?vt(n).get(t.id):void 0)??ce(t)):1,f=t.variant==="ordered"&&m!==1?` start="${m}"`:"",d=[...t.lineSpacing!==void 0?[`line-height: ${t.lineSpacing}`]:[],...t.spaceBefore!==void 0?
212
+ [`margin-top: ${t.spaceBefore}px`]:[],...t.spaceAfter!==void 0?[`margin-bottom: ${t.spaceAfter}px`]:[]],h=d.length?` style="${d.join("; ")}"`:"",g=t.contextualSpacing!==void 0?` data-contextual-spacin\
213
+ g="${t.contextualSpacing}"`:"",y=t.numberingChainId?` data-numbering-chain-id="${this.escapeAttribute(t.numberingChainId)}" data-start-number="${t.startNumber??""}" data-effective-start="${m}"`:"",$=t.
214
+ numberingFormat?` data-numbering-format="${this.escapeAttribute(t.numberingFormat)}"`:"";return`<${r}${p}${f}${h}${g}${y}${$}>${l}</${r}>`}static containerToHtml(t,e,n,i={}){const o=t.id?` id="${this.
215
+ escapeAttribute(t.id)}"`:"",r=[];t.borderColor&&r.push(`border-color: ${this.escapeHtml(t.borderColor)}`),t.padding!==void 0&&r.push(`padding: ${t.padding}px`);const a=r.length>0?` style="${r.join("; ")}\
216
+ "`:"",s=t.children.map(c=>this.blockToHtml(c,e,n,i)).filter(c=>c.length>0).join(`
217
+ `);return`<div class="container"${o}${a}>
218
+ ${s}
219
+ </div>`}static tableToHtml(t,e,n,i={}){const o=t.id?` id="${this.escapeAttribute(t.id)}"`:"",r=["border-collapse: collapse"];t.tableWidth!==void 0?r.push(`width: ${t.tableWidth}px`):r.push("width: 100\
220
+ %"),t.align&&t.align!=="left"&&(t.align==="center"?r.push("margin-left: auto","margin-right: auto"):t.align==="right"&&r.push("margin-left: auto","margin-right: 0")),t.borderColor&&r.push(`border-colo\
221
+ r: ${this.escapeHtml(t.borderColor)}`);const a=It(t.borders);let s="";if(a){for(const m of["top","right","bottom","left"]){const f=a[m];f&&r.push(`border-${m}: ${wt(f)}`)}s=` data-borders="${this.escapeAttribute(
222
+ t.borders)}"`}const c=` style="${r.join("; ")}"`,l=X(t),p=t.children.map((m,f)=>this.tableRowToHtml(t,m,f,l,e,n,i)).join(`
223
+ `);return`<table${o}${s}${c}>
224
+ ${p}
225
+ </table>`}static tableRowToHtml(t,e,n,i,o,r,a={}){const s=[];if(o){const d=h=>{const g=h;if(g.type==="list"){g.variant==="ordered"&&s.push([g.id,vt(o).get(g.id??"")]);return}for(const y of g.children??
226
+ [])d(y)};d(e)}const c=JSON.stringify([e,s,t.columnWidths,t.hasHeader&&n===0,r,o?.stylesheet,o?.comments,o?.pageLayout,a,e.children.map(d=>{const h=i.byId.get(d.id);return h?[h.col,h.rowSpan,h.colSpan]:
227
+ null})]),l=this.tableRowHtmlCache.get(e);if(l?.key===c)return l.html;const p=t.hasHeader&&n===0?"th":"td",m=e.children.map((d,h)=>{const g=d.id?` id="${this.escapeAttribute(d.id)}"`:"",y=i.byId.get(d.
228
+ id);let $="";y&&y.colSpan>1&&($+=` colspan="${y.colSpan}"`),y&&y.rowSpan>1&&($+=` rowspan="${y.rowSpan}"`);const x=y?` data-grid-column="${y.col}"`:' data-grid-unplaced="true"';let A;if(y){let F=0;for(let N=y.
229
+ col;N<y.col+y.colSpan;N++)F+=t.columnWidths[N]||0;A=F>0?F:void 0}else A=t.columnWidths[h];const k=[];let v="";const b=Ct(d.borders);if(b){for(const F of["top","right","bottom","left"]){const N=b[F];N&&
230
+ k.push(`border-${F}: ${wt(N)}`)}v+=` data-borders="${this.escapeAttribute(d.borders)}"`}else k.push("border: 1px solid #ccc");const S=pe(d.padding);S?k.push(`padding: ${ue(S)}`):k.push("padding: 8px"),
231
+ A!==void 0&&k.push(`width: ${A}%`),d.verticalAlign&&k.push(`vertical-align: ${d.verticalAlign}`),d.backgroundColor&&k.push(`background-color: ${this.escapeHtml(d.backgroundColor)}`);const I=` style="${k.
232
+ join("; ")}"`,E=d.children.map(F=>this.blockToHtml(F,o,r,a)).filter(F=>F.length>0).join("");return`<${p}${g}${$}${v}${I}${x}>${E}</${p}>`}).join(""),f=`<tr${e.id?` id="${this.escapeAttribute(e.id)}"`:
233
+ ""}>${m}</tr>`;return this.tableRowHtmlCache.set(e,{key:c,html:f}),f}static tableCellToHtml(t,e,n,i={}){const o=t.id?` id="${this.escapeAttribute(t.id)}"`:"",r=["border: 1px solid #ccc","padding: 8px"];
234
+ t.verticalAlign&&r.push(`vertical-align: ${t.verticalAlign}`),t.backgroundColor&&r.push(`background-color: ${this.escapeHtml(t.backgroundColor)}`);const a=` style="${r.join("; ")}"`,s=t.children.map(c=>this.
235
+ blockToHtml(c,e,n,i)).filter(c=>c.length>0).join(`
236
+ `);return`<div class="table-cell"${o}${a}>
237
+ ${s}
238
+ </div>`}static parsePositiveImageDimension(t,e){const n=t.getAttribute(e);if(!n)return;const i=Number.parseInt(n,10);return Number.isFinite(i)&&i>0?i:void 0}static parseImageSourceUrl(t){const e=t.getAttribute(
239
+ "data-source-url")?.trim();if(e)try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"?n.href:void 0}catch{return}}static parseSingleImageParagraph(t,e){if(t.textContent?.trim())return null;
240
+ let n=t,i=null;for(;;){const l=Array.from(n.children);if(l.length!==1)return null;const p=l[0],m=p.tagName.toLowerCase();if(m==="img"){i=p;break}if(m!=="span")return null;n=p}const o=this.parsePositiveImageDimension(
241
+ i,"data-revise-natural-width"),r=this.parsePositiveImageDimension(i,"data-revise-natural-height"),a=this.parseImageElement(i,e);if(!a)return null;if(!a.align){const l=t.getAttribute("style");if(l){const p=l.
242
+ match(/text-align:\s*([^;]+)/);if(p){const m=p[1].trim();(m==="left"||m==="center"||m==="right")&&(a.align=m)}}}const s=l=>{const p=l.trim().match(/^(\d+(?:\.\d+)?)px$/i);if(!p)return;const m=Number(p[1]);
243
+ return Number.isFinite(m)&&m>0?Math.round(m):void 0};let c=i.parentElement;for(;c&&c!==t;){const l=c.getAttribute("style")??"",p=l.match(/(?:^|;)\s*width\s*:\s*([^;]+)/i),m=l.match(/(?:^|;)\s*height\s*:\s*([^;]+)/i),
244
+ f=p?s(p[1]):void 0,d=m?s(m[1]):void 0,h=i.getAttribute("style")??"";if(f!==void 0&&d!==void 0&&/(?:^|;)\s*transform\s*:/i.test(h))a.width=f,a.height=d;else if(f!==void 0){const g=o??a.width,y=r??a.height;
245
+ a.width=f,a.height=Math.max(1,Math.round(f*y/g))}else if(d!==void 0){const g=o??a.width,y=r??a.height;a.height=d,a.width=Math.max(1,Math.round(d*g/y))}if(f!==void 0||d!==void 0)break;c=c.parentElement}
246
+ return a}static parseImageElement(t,e){const n=e?.imageReferences?.get(t);if(n){e?.remainingImageReferences?.delete(t);const h={...n,id:e?.imageIdsToPreserve?.has(n.id)?C(n.id,e):C(null,e)};h.width=this.
247
+ parsePositiveImageDimension(t,"width")??h.width,h.height=this.parsePositiveImageDimension(t,"height")??h.height,t.hasAttribute("alt")&&(h.alt=t.getAttribute("alt")||void 0);const g=this.parseImageAlign(
248
+ t);return g&&(h.align=g),h}const i=t.getAttribute("src");if(!i)return null;e?.remainingImageReferences?.delete(t);const o=this.parsePositiveImageDimension(t,"width"),r=this.parsePositiveImageDimension(
249
+ t,"height"),a=this.parsePositiveImageDimension(t,"data-revise-natural-width"),s=this.parsePositiveImageDimension(t,"data-revise-natural-height"),c=t.getAttribute("alt")||void 0,l=this.parseImageAlign(
250
+ t),p=this.parseImageSourceUrl(t);let m=o??a??200,f=r??s??200;a&&s&&(o?f=Math.max(1,Math.round(o*s/a)):r&&(m=Math.max(1,Math.round(r*a/s))));const d={type:"image",id:J(),src:i,width:m,height:f};return c&&
251
+ (d.alt=c),l&&(d.align=l),p&&(d.sourceUrl=p),d}static parseListElement(t,e,n=0){const i=t.tagName.toLowerCase();if(i!=="ul"&&i!=="ol")return null;let o=i==="ol"?"ordered":"unordered";const r=(d,h,g={},y=Math.
252
+ min(n+2,8))=>{const $=[],x=d.getAttribute("style"),A=x?{...g,...this.extractTextStyleMarksFromStyle(x)}:g;for(const k of Array.from(d.children))if(k.tagName.toLowerCase()==="li"){const v=document.createElement(
253
+ "div");let b=!1;const S=[];for(const T of Array.from(k.childNodes))if(T.nodeType===Node.ELEMENT_NODE){const H=T,M=H.tagName.toLowerCase();M==="ul"||M==="ol"?(b=!0,S.push(H)):v.appendChild(T.cloneNode(
254
+ !0))}else v.appendChild(T.cloneNode(!0));const I=k.getAttribute("style"),E=I?{...A,...this.extractTextStyleMarksFromStyle(I)}:A,F=v.querySelector('input[type="checkbox"]');F&&(o="todo",F.remove());const N=this.
255
+ parseHtmlElement(v,E),P={type:"list-item",id:C(k.getAttribute("id"),e),children:N.length>0?N:[{type:"text",text:"",marks:{}}]};F&&(P.checked=F.hasAttribute("checked"));const D=k.getAttribute("dir")??I?.
256
+ match(/(?:^|;)\s*direction:\s*(rtl|ltr)\s*(?:;|$)/i)?.[1];if((D==="rtl"||D==="ltr")&&(P.direction=D),I){const T=this.extractParagraphStyleAttributes(I);for(const H of["lineSpacing","spaceBefore","spac\
257
+ eAfter"])T[H]!==void 0&&(P[H]=T[H])}const W=k.getAttribute("data-indent-level"),B=W!==null?Number(W):NaN,j=Number.isInteger(B)&&B>=0&&B<=8,R=j?B:h;if(R>0&&(P.indentLevel=R),$.push(P),b)for(const T of S){
258
+ const H=j?Math.max(y,Math.min(R+2,8)):y,M=r(T,Math.min(R+1,H),E,H);$.push(...M)}}return $},a=r(t,n);if(a.length===0)return null;const s={type:"list",id:C(t.getAttribute("id"),e),variant:o,children:a};
259
+ if(o==="ordered"){const d=t.getAttribute("start");if(d){const h=parseInt(d,10);!isNaN(h)&&h!==1&&(s.startNumber=h)}}const c=t.getAttribute("style");if(c){const d=this.extractParagraphStyleAttributes(c);
260
+ for(const g of["spaceBefore","spaceAfter"])d[g]!==void 0&&(s[g]=d[g]);const h=c.match(/(?:^|;)\s*line-height:\s*([\d.]+)\s*(?:;|$)/i);if(h){const g=parseFloat(h[1]);Number.isFinite(g)&&g>=.5&&g<=4&&(s.
261
+ lineSpacing=g)}}const l=t.getAttribute("data-contextual-spacing");(l==="true"||l==="false")&&(s.contextualSpacing=l==="true");const p=t.getAttribute("data-numbering-chain-id");if(p&&o==="ordered"){s.numberingChainId=
262
+ p;const d=t.getAttribute("data-start-number"),h=Number(t.getAttribute("data-effective-start")),g=Number(t.getAttribute("start")??1);t.hasAttribute("start")&&Number.isInteger(h)&&h>0&&Number.isInteger(
263
+ g)&&g>0&&g!==h?s.startNumber=g:d===""?delete s.startNumber:d!==null&&Number.isInteger(Number(d))&&Number(d)>0&&(s.startNumber=Number(d))}const m=t.getAttribute("data-numbering-format");m&&le(m)&&(s.numberingFormat=
264
+ m);const f=t.getAttribute("style");if(f){const d=f.match(/font-family:\s*([^;]+)/);if(d){const h=this.resolveFontToCss(d[1].trim());for(const g of s.children)for(const y of g.children)y.type==="text"&&
265
+ (y.marks||(y.marks={}),y.marks.fontFamily||(y.marks.fontFamily=h))}}return s}static parseContainerElement(t,e,n){const i=C(t.getAttribute("id"),n),o=t.getAttribute("style");let r,a;if(o){const p=o.match(
266
+ /border-color:\s*([^;]+)/);p&&(r=p[1].trim());const m=o.match(/padding:\s*(\d+)px/);m&&(a=parseInt(m[1],10))}const s=this.resolveIndentStepPx(e?.existingDocument),c=[];for(const p of Array.from(t.children)){
267
+ const m=p.tagName.toLowerCase();if(m==="p"||m.match(/^h[1-6]$/)){const f=m.match(/^h([1-6])$/),d=p.getAttribute("style"),h=this.parseHtmlElement(p,d?this.extractTextStyleMarksFromStyle(d):{}),g={type:"\
268
+ paragraph",id:C(p.getAttribute("id"),n),children:h.length>0?h:[{type:"text",text:"",marks:{}}]};f&&(g.heading=parseInt(f[1])),this.applyParagraphElementAttributes(g,p,s),c.push(g)}else if(m==="ul"||m===
269
+ "ol"){const f=this.parseListElement(p,n);f&&c.push(f)}else if(m==="hr")c.push(this.parseHrElement(p,n));else if(m==="img"){const f=this.parseImageElement(p,n);f&&c.push(f)}else if(m==="div"&&p.classList.
270
+ contains("container")){const f=this.parseContainerElement(p,e,n);f&&c.push(f)}}if(c.length===0)return null;const l={type:"container",id:i,children:c};return r&&(l.borderColor=r),a!==void 0&&(l.padding=
271
+ a),l}static parseTableElement(t,e,n){const i=C(t.getAttribute("id"),n),o=this.resolveIndentStepPx(e?.existingDocument),r=t.getAttribute("style");let a,s,c;if(r){const v=r.match(/width:\s*(\d+)px/);v&&
272
+ (a=parseInt(v[1],10));const b=r.match(/border-color:\s*([^;]+)/);b&&(s=b[1].trim()),/margin-left:\s*auto/.test(r)&&/margin-right:\s*auto/.test(r)?c="center":/margin-left:\s*auto/.test(r)&&/margin-right:\s*0/.
273
+ test(r)&&(c="right")}const l=[],p=new Map;let m=!1;const f=Array.from(t.rows);for(let v=0;v<f.length;v++){const b=f[v],S=[],I=b.querySelectorAll(":scope > td, :scope > th");v===0&&I.length>0&&I[0].tagName.
274
+ toLowerCase()==="th"&&(m=!0);for(let F=0;F<I.length;F++){const N=I[F],P=N.getAttribute("style");let D,W;if(P){const w=P.match(/vertical-align:\s*([^;]+)/);if(w){const q=w[1].trim();(q==="top"||q==="mi\
275
+ ddle"||q==="bottom")&&(D=q)}const L=P.match(/background-color:\s*([^;]+)/);L&&(W=L[1].trim())}const B=[],j=N.children,R=Array.from(j).every(w=>!/^(p|h[1-6]|ul|ol|table|img|hr|div|blockquote|pre)$/.test(
276
+ w.tagName.toLowerCase()));if(j.length===0){const w=N.textContent||"";B.push({type:"paragraph",id:C(null,n),children:[{type:"text",text:w,marks:{}}]})}else if(R){const w=this.parseHtmlElement(N,{});B.push(
277
+ {type:"paragraph",id:C(null,n),children:w.length>0?w:[{type:"text",text:"",marks:{}}]})}else for(const w of Array.from(j)){const L=w.tagName.toLowerCase(),q=L==="img"?this.parseImageElement(w,n):L==="\
278
+ p"?this.parseSingleImageParagraph(w,n):null;if(q){B.push(q);continue}if(L==="p"||L.match(/^h[1-6]$/)){const O=L.match(/^h([1-6])$/),ut=w.getAttribute("style"),mt=this.parseHtmlElement(w,ut?this.extractTextStyleMarksFromStyle(
279
+ ut):{}),tt={type:"paragraph",id:C(w.getAttribute("id"),n),children:mt.length>0?mt:[{type:"text",text:"",marks:{}}]};O&&(tt.heading=parseInt(O[1])),this.applyParagraphElementAttributes(tt,w,o),B.push(tt)}else if(L===
280
+ "ul"||L==="ol"){const O=this.parseListElement(w,n);O&&B.push(O)}else if(L==="hr")B.push(this.parseHrElement(w,n));else if(L==="table"){const O=this.parseTableElement(w,e,n);O&&B.push(O)}else{const O=w.
281
+ textContent||"";O.trim()&&B.push({type:"paragraph",id:C(null,n),children:[{type:"text",text:O,marks:{}}]})}}B.length===0&&B.push({type:"paragraph",id:C(null,n),children:[{type:"text",text:"",marks:{}}]});
282
+ const T={type:"table-cell",id:C(N.getAttribute("id"),n),children:B},H=P?.match(/width:\s*([\d.]+)%/);if(H){const w=parseFloat(H[1]);Number.isFinite(w)&&w>0&&p.set(T,w)}D&&(T.verticalAlign=D),W&&(T.backgroundColor=
283
+ W);const M=Ct(N.getAttribute("data-borders")),_=M?Tt(M):Ft(Nt(P));if(_&&(T.borders=_),P){const w=P.match(/(?:^|;)\s*padding\s*:\s*([^;]+)/i),L=me(w?.[1]);L&&!(L.top===8&&L.right===8&&L.bottom===8&&L.left===
284
+ 8)&&(T.padding=ge(L))}const ht=this.parseSpanAttribute(N.getAttribute("colspan")),pt=this.parseSpanAttribute(N.getAttribute("rowspan"));ht>1&&(T.colSpan=ht),pt>1&&(T.rowSpan=pt),S.push(T)}const E=C(b.
285
+ getAttribute("id"),n);l.push({type:"table-row",id:E,children:S})}if(!l.some(v=>v.children.length>0))return null;const d=X({children:l,columnWidths:[]}),h=d.cols||1,g=new Array(h).fill(0),y=new Array(h).
286
+ fill(!1);for(const v of d.cells){if(v.colSpan!==1||y[v.col])continue;const b=p.get(v.cell);b!==void 0&&(g[v.col]=b,y[v.col]=!0)}const $=y.filter(v=>!v).length;if($>0){const v=g.reduce((S,I)=>S+I,0),b=Math.
287
+ max(1,(100-v)/$);for(let S=0;S<h;S++)y[S]||(g[S]=b)}const x={type:"table",id:i,columnWidths:g,children:l};a!==void 0&&(x.tableWidth=a),c&&(x.align=c),s&&(x.borderColor=s),m&&(x.hasHeader=m);const A=It(
288
+ t.getAttribute("data-borders")),k=A?Tt(A):Ft(Nt(r));return k&&(x.borders=k),x}static parseSpanAttribute(t){const e=parseInt(t||"1",10);return Number.isFinite(e)?Math.min(Math.max(1,e),1e3):1}static parseCodeBlockElement(t,e){
289
+ const n=C(t.getAttribute("id"),e);let i;const o=t.getAttribute("language"),r=t.getAttribute("data-language");if(o)i=o;else if(r)i=r;else{const c=t.className.split(" ");for(const l of c)if(l.startsWith(
290
+ "language-")){i=l.substring(9);break}}let a="";const s=t.querySelector("code");return s?a=s.textContent||"":a=t.textContent||"",{type:"code",id:n,content:a,language:i}}static parseMathElement(t,e){const n=C(
291
+ t.getAttribute("id"),e);let i="block";t.getAttribute("display")==="inline"&&(i="inline");const o=t.textContent||"",r=kt(t,"align"),a={type:"math",id:n,content:o,displayMode:i};return(r==="left"||r==="\
292
+ center"||r==="right")&&(a.align=r),a}static parseHrElement(t,e){let n;const i=t.getAttribute("style");if(i){const r=i.match(/border(?:-bottom)?:\s*([\d.]+)px\s+(solid|double|dashed|dotted)\s+(#[0-9a-fA-F]{3,8}|[a-zA-Z]+)/i);
293
+ if(r){const a=r[2].toLowerCase();n={width:parseFloat(r[1]),style:a==="solid"?"single":a,color:r[3]}}}const o=t.getAttribute("data-rule");return At(o??void 0)&&(n={...n,style:o}),{type:"paragraph",id:C(
294
+ t.getAttribute("id"),e),children:[{type:"text",text:"",marks:{}}],borders:ne(n)}}static parsePageBreakElement(t,e){return{type:"page-break",id:C(t.getAttribute("id"),e)}}static parseDocxRawElement(t,e){
295
+ const n=t.getAttribute("origin");return{type:"docx-raw",id:C(t.getAttribute("id"),e),xml:"",tagName:t.getAttribute("tag")||"unknown",...t.getAttribute("detail")?{detail:t.getAttribute("detail")}:{},origin:n===
296
+ "body"?"body":"run"}}static parseTocElement(t,e){const n={type:"toc",...ie(t),id:C(t.getAttribute("id"),e)},i=t.getAttribute("levels");if(i){const o=parseInt(i,10);Number.isFinite(o)&&o>=1&&o<=6&&(n.levels=
297
+ o)}return Object.assign(n,oe(t.getAttribute("style"))),n}static parseSectionBreakElement(t,e){const n={type:"section-break",id:C(t.getAttribute("id"),e)},i=t.getAttribute("break-type");(i==="nextPage"||
298
+ i==="continuous"||i==="evenPage"||i==="oddPage")&&(n.breakType=i);const o=t.getAttribute("layout");if(o)try{const r=JSON.parse(o);r&&typeof r=="object"&&!Array.isArray(r)&&(n.layout=r)}catch{}return n}static parseCenterElement(t,e,n){
299
+ const i=[],o=Array.from(t.children);for(const a of o){const s=a.tagName.toLowerCase();if(s==="p"||s.match(/^h[1-6]$/)){const c=s.match(/^h([1-6])$/),l=this.parseHtmlElement(a),p={type:"paragraph",id:C(
300
+ a.getAttribute("id"),n),children:l.length>0?l:[{type:"text",text:"",marks:{}}],align:"center"};c&&(p.heading=parseInt(c[1])),i.push(p);continue}if(s==="img"){const c=this.parseImageElement(a,n);c&&(c.
301
+ align=c.align??"center",i.push(c));continue}if(s==="table"){const c=this.parseTableElement(a,e,n);c&&(c.align=c.align??"center",i.push(c));continue}if(s==="pre"){const c=this.parseCodeBlockElement(a,n);
302
+ c&&i.push(c);continue}if(s==="latex"){i.push(this.parseMathElement(a,n));continue}if(s==="page-break"){i.push(this.parsePageBreakElement(a,n));continue}if(s==="docx-raw"){i.push(this.parseDocxRawElement(
303
+ a,n));continue}if(s==="section-break"){i.push(this.parseSectionBreakElement(a,n));continue}if(s==="toc"){i.push(this.parseTocElement(a,n));continue}if(s==="hr"){i.push(this.parseHrElement(a,n));continue}
304
+ if(s==="ul"||s==="ol"){const c=this.parseListElement(a,n);c&&i.push(c);continue}}if(i.length>0)return i;const r=this.parseHtmlElement(t);return[{type:"paragraph",id:C(t.getAttribute("id"),n),align:"ce\
305
+ nter",children:r.length>0?r:[{type:"text",text:"",marks:{}}]}]}static parseImageAlign(t){const e=kt(t,"align");if(e==="left"||e==="center"||e==="right")return e;const n=t.getAttribute("data-align");if(n===
306
+ "left"||n==="center"||n==="right")return n;const i=t.getAttribute("style")||"";if(i.includes("margin-left: auto")&&i.includes("margin-right: auto"))return"center";if(i.includes("margin-left: auto"))return"\
307
+ right";if(i.includes("margin-right: auto"))return"left"}static getImageStyle(t){const e=["display: block","max-width: 100%","height: auto"];switch(t.align){case"center":e.push("margin-left: auto","mar\
308
+ gin-right: auto");break;case"right":e.push("margin-left: auto");break;case"left":e.push("margin-right: auto");break}return e.join("; ")}static escapePreContent(t){return t.replace(/<pre(\s[^>]*)?>(([\s\S](?!<\/pre>))*[\s\S]?)<\/pre>/gi,
309
+ (e,n,i)=>{if(!i)return e;const o=i.match(/^(\s*)<code(\s[^>]*)?>(([\s\S](?!<\/code>))*[\s\S]?)<\/code>(\s*)$/i);if(o){const[,a,s,c,,l]=o,p=this.escapeCodeContent(c||"");return`<pre${n||""}>${a||""}<co\
310
+ de${s||""}>${p}</code>${l||""}</pre>`}const r=this.escapeCodeContent(i);return`<pre${n||""}>${r}</pre>`})}static escapeCodeContent(t){return t.replace(/&(?!(lt|gt|amp|quot|apos|nbsp|#\d+|#x[0-9a-fA-F]+);)/g,
311
+ "&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}static coalesceAdjacentBareListFragments(t){if(t.length<2)return t;const e=[];let n=!1;for(const i of t){const o=dt(i),r=Array.from(o.body.childNodes),
312
+ a=r.filter(l=>l.nodeType===Node.ELEMENT_NODE||l.nodeType===Node.TEXT_NODE&&l.textContent?.trim()),s=l=>l?.nodeType===Node.ELEMENT_NODE&&l.tagName.toLowerCase()==="li",c=a.length===0&&r.some(l=>l.nodeType===
313
+ Node.COMMENT_NODE);n&&(s(a[0])||c)?e[e.length-1]+=i:e.push(i),c||(n=s(a.at(-1)))}return e}static fromAgentHtml(t,e){t=this.escapePreContent(t);const n=e?.parsingContext??(e?.existingDocument?this.createParsingContext(
314
+ e.existingDocument):void 0),i=n?.validIds,o=e?.preserveImageReferenceIds?i??new Set:e?.replacementBlock?qt({children:[e.replacementBlock]}):new Set,r={validIds:i,usedIds:new Set,imageIdsToPreserve:o,imageReferences:new Map,
315
+ remainingImageReferences:new Set};e={...e,parsingContext:n};let a=dt(t),s;const c=Array.from(a.body.children).some(h=>h.tagName.toLowerCase()==="li");for(const h of Array.from(a.body.childNodes))if(h.
316
+ nodeType!==Node.COMMENT_NODE){if(h.nodeType===Node.TEXT_NODE){if(c&&h.textContent?.trim()){s=void 0;const g=a.createElement("p");a.body.insertBefore(g,h),g.appendChild(h)}continue}if(h.nodeType!==Node.
317
+ ELEMENT_NODE||h.tagName.toLowerCase()!=="li"){s=void 0;continue}s||(s=a.createElement("ul"),a.body.insertBefore(s,h)),s.appendChild(h)}Array.from(a.body.children).some(h=>we.has(h.tagName.toLowerCase()))||
318
+ (a=dt(`<p>${t}</p>`));const l=new Set,p=Array.from(a.body.querySelectorAll("img"));for(const h of p){r.remainingImageReferences.add(h);const g=h.getAttribute("id")??"",y=g?n?.imagesById?.get(g):void 0,
319
+ $=h.getAttribute("data-image-id"),x=h.getAttribute("src")??"",A=x.startsWith("#")?x.slice(1):void 0;if($!==null||A!==void 0){const v=$??A,b=n?.imagesById?.get(v);if(!b?.src||A!==void 0&&A!==v||y&&y.id!==
320
+ v||x&&A===void 0&&x!==v&&x!==b.src)throw new U("invalid_image_reference",`Image reference "${v}" is missing or contradicts the supplied source. Copy an existing image with <img src="IMAGE_ID"> using t\
321
+ he exact id from the document.`);r.imageReferences.set(h,b);continue}const k=n?.imagesById?.get(h.getAttribute("src")??"");if(k){r.imageReferences.set(h,k);continue}if(x&&x!==y?.src&&!/^(?:https?:\/\/|data:image\/|blob:)/i.
322
+ test(x))throw new U("invalid_image_reference",`Image source "${x}" is not a known image id or an absolute image URL. Copy an existing image with <img src="IMAGE_ID"> using its exact document id, or pr\
323
+ ovide an absolute image URL.`);if(!h.getAttribute("src")){const v=!g&&e?.replacementBlock?.type==="image"&&p.length===1?n?.imagesById?.get(e.replacementBlock.id):void 0,b=y??v;if(!b?.src)throw new U("\
324
+ invalid_image_reference",`${h.getAttribute("data-image-source")==="hidden"?"Cannot resolve hidden image":"Image"} ${g?'"'+g+'"':"without an id"} has no valid source. Supply src, copy a verified existi\
325
+ ng image with <img src="IMAGE_ID"> using its exact document id, or resize an explicitly targeted image block.`);if(l.has(b.id))throw new U("invalid_image_reference",`Image "${b.id}" is referenced more\
326
+ than once. Each existing image may appear only once in replacement HTML.`);l.add(b.id),r.imageReferences.set(h,b);continue}y?.src===h.getAttribute("src")&&r.imageReferences.set(h,y)}const m=Array.from(
327
+ a.body.children),f=e?.parsingContext?.indentStepPx??this.resolveIndentStepPx(e?.existingDocument),d=[];m.length===0&&a.body.textContent&&d.push({type:"paragraph",id:C(null,r),children:[{type:"text",text:a.
328
+ body.textContent||"",marks:{}}]});for(const h of m){const g=h.tagName.toLowerCase();if(g==="img"){const b=this.parseImageElement(h,r);b&&d.push(b);continue}if(g==="ul"||g==="ol"){const b=this.parseListElement(
329
+ h,r,e?.listItemBaseIndent);b&&d.push(b);continue}if(g==="div"&&h.classList.contains("container")){const b=this.parseContainerElement(h,e,r);b&&d.push(b);continue}if(g==="table"){const b=this.parseTableElement(
330
+ h,e,r);b&&d.push(b);continue}if(g==="pre"){const b=this.parseCodeBlockElement(h,r);b&&d.push(b);continue}if(g==="p"){const b=this.parseSingleImageParagraph(h,r);if(b){d.push(b);continue}}if(g==="latex"){
331
+ const b=this.parseMathElement(h,r);d.push(b);continue}if(g==="page-break"){d.push(this.parsePageBreakElement(h,r));continue}if(g==="docx-raw"){d.push(this.parseDocxRawElement(h,r));continue}if(g==="se\
332
+ ction-break"){d.push(this.parseSectionBreakElement(h,r));continue}if(g==="toc"){d.push(this.parseTocElement(h,r));continue}if(g==="center"){d.push(...this.parseCenterElement(h,e,r));continue}if(g==="h\
333
+ r"){d.push(this.parseHrElement(h,r));continue}const y=g.match(/^h([1-6])$/),$=h.getAttribute("style");let x,A;if($){const b=$.match(/font-family:\s*([^;]+)/);b&&(x=this.resolveFontToCss(b[1].trim())),
334
+ A=this.extractFontSizeFromStyle($)}const k=C(h.getAttribute("id"),r),v=$?this.extractTextStyleMarksFromStyle($):{};if(y){const b=parseInt(y[1]),S=this.parseHtmlElement(h,v,e?.preserveExplicitMarkResets),
335
+ I={type:"paragraph",id:k,heading:b,children:S.length>0?S:[{type:"text",text:"",marks:{}}]};if(x)for(const E of I.children)E.type==="text"&&(E.marks||(E.marks={}),E.marks.fontFamily||(E.marks.fontFamily=
336
+ x));A!==void 0&&this.ensureTextNodesHaveFontSize(I.children,A),this.applyParagraphElementAttributes(I,h,f),d.push(I)}else{const b=this.parseHtmlElement(h,v,e?.preserveExplicitMarkResets),S={type:"para\
337
+ graph",id:k,children:b.length>0?b:[{type:"text",text:"",marks:{}}]};if(x)for(const I of S.children)I.type==="text"&&(I.marks||(I.marks={}),I.marks.fontFamily||(I.marks.fontFamily=x));this.applyParagraphElementAttributes(
338
+ S,h,f),d.push(S)}}if(r.remainingImageReferences.size>0){const h=Array.from(r.remainingImageReferences,g=>g.getAttribute("id")||"(new image)").join(", ");throw new U("invalid_image_reference",`Image(s)\
339
+ ${h||"without ids"} are in unsupported HTML positions. Put each image directly in a table cell or as its own image block; mixed text/image paragraphs and list items are not supported.`)}return d.length===
340
+ 0&&d.push(re()),he(d,e?.existingDocument?.stylesheet),this.applyInheritedFontStyling(d,e),de(()=>C(null,r),d),this.hydrateDocxRawPlaceholders(d,e?.existingDocument),{type:"doc",children:d}}static hydrateDocxRawPlaceholders(t,e){
341
+ for(let n=t.length-1;n>=0;n--){const i=t[n];if(i.type==="docx-raw"){if(i.xml)continue;const r=i.id&&e?K(e,i.id):void 0;r&&r.type==="docx-raw"&&r.xml?(i.xml=r.xml,i.tagName=r.tagName,r.detail&&(i.detail=
342
+ r.detail),i.origin=r.origin):t.splice(n,1);continue}const o=i.children;Array.isArray(o)&&o.length>0&&o.filter(r=>typeof r=="object"&&r!==null&&typeof r.type=="string"&&r.type!=="text").length>0&&this.
343
+ hydrateDocxRawPlaceholders(o,e)}}static parseHtmlElement(t,e={},n=!1){const i=[];let o;const r=(a,s={})=>{if(a.nodeType===Node.TEXT_NODE){const c=He(a.textContent||"",s);c&&i.push({type:"text",text:c,
344
+ marks:{...s}})}else if(a.nodeType===Node.ELEMENT_NODE){const c=a,l={...s};switch(c.tagName.toLowerCase()){case"b":case"strong":l.bold=!0;break;case"i":case"em":l.italic=!0;break;case"u":l.underline=!0;
345
+ break;case"s":case"strike":l.strikethrough=!0;break;case"code":l.code=!0;break;case"l":case"latex-inline":l.latex=!0;break;case"sup":{l.superscript=!0;const f=c.getAttribute("data-footnote-ref");f&&(l.
346
+ footnoteRef=f);const d=c.getAttribute("data-footnote");d!==null&&(l.footnoteRef=f??J(),l.footnotePendingBody=d,c.getAttribute("data-note-kind")==="endnote"&&(l.footnotePendingKind="endnote"));break}case"\
347
+ sub":l.subscript=!0;break;case"mark":{const f=c.getAttribute("color"),d=this.normalizeAgentHighlightColor(f);if(f!==null&&!d)throw new Error(`Unsupported highlight color ${JSON.stringify(f)}. Use one \
348
+ of: ${fe.join(", ")}.`);l.backgroundColor=d??be}break;case"a":const p=c.getAttribute("href");p&&(l.link=p);break;case"comment-thread":{const f=c.getAttribute("id")?.trim();if(f){const d=l.comment?.split(
349
+ ",").map(h=>h.trim()).filter(Boolean);l.comment=[...d??[],f].join(",")}break}case"br":i.push({type:"text",text:`
350
+ `,marks:{...s}});return;case"span":se(l,c.getAttribute("data-docx-explicit-false-marks"),c.getAttribute("data-docx-run-property-resets")),c.getAttribute("data-word-hidden")==="true"&&(l.hidden=!0);{const f=c.
351
+ getAttribute("data-bookmark");f&&(l.bookmark=f);const d=c.getAttribute("data-field-instr");d&&(l.fieldInstr=d);const h=c.getAttribute("data-word-lang");h&&(l.lang=h);const g=c.getAttribute("data-dynam\
352
+ ic-field");(g==="page"||g==="numPages")&&(l.field=g);const y=c.getAttribute("data-sdt-inline");y&&(l.sdtInline=y),c.getAttribute("data-ai-generated")==="true"&&(l.aiGenerated=!0);const $=c.getAttribute(
353
+ "data-html-class");$&&(l.__htmlClassName=$)}const m=c.getAttribute("style");if(m){const f=m.match(/font-family:\s*([^;]+)/);f&&(l.fontFamily=this.resolveFontToCss(f[1].trim()));const d=this.extractFontSizeFromStyle(
354
+ m);d!==void 0&&(l.fontSize=d);const h=this.parseCssFontWeightToBold(m);h===!0?l.bold=!0:h===!1&&(n?l.bold=!1:delete l.bold);const g=m.match(/(?:^|;)\s*font-style:\s*([^;]+)/i);if(g){const k=g[1].trim().
355
+ toLowerCase();k==="italic"||k==="oblique"?l.italic=!0:k==="normal"&&(n?l.italic=!1:delete l.italic)}const y=m.match(/background-color:\s*([^;]+)/i);if(y){const k=this.normalizeAgentHighlightColor(y[1].
356
+ trim());k&&(l.backgroundColor=k)}const $=m.match(/(?:^|;)\s*color:\s*([^;]+)/i);if($){const k=bt($[1].trim());k&&!yt(k)&&(l.color=k)}const x=m.match(/text-decoration:\s*([^;]+)/i);if(x){const k=x[1].toLowerCase();
357
+ if(k.trim()==="none")for(const v of["underline","strikethrough","doubleStrikethrough"])n?l[v]=!1:delete l[v];k.includes("line-through")&&(k.includes("double")?l.doubleStrikethrough=!0:l.strikethrough=
358
+ !0)}/font-variant:\s*small-caps/i.test(m)&&(l.smallCaps=!0),/text-transform:\s*uppercase/i.test(m)&&(l.allCaps=!0);const A=m.match(/letter-spacing:\s*([^;]+)/i);if(A){const k=Wt(A[1],l.fontSize);k!==void 0&&
359
+ (l.letterSpacing=k)}}break}c.tagName.toLowerCase()!=="img"&&(o=l);for(const p of Array.from(a.childNodes))r(p,l)}};for(const a of Array.from(t.childNodes))r(a,{...e});if(i.length===0){const a=o??e;if(Object.
360
+ keys(a).length>0)return[{type:"text",text:"",marks:{...a}}]}return i}static insertionFontFor(t){const e=this.extractBlockFontStyling(t);return{fontFamily:e.fontFamily,fontSize:this.fontSizeKind(t)==="\
361
+ body"?e.fontSize:void 0}}static applyInheritedFontStyling(t,e){const n=this.extractBlockFontStyling(e?.replacementBlock),i=e?.insertionFont??this.extractBlockFontStyling(e?.previousBlock);let o=n.fontFamily??
362
+ i.fontFamily??(e?.parsingContext?e.parsingContext.documentFontFamily:this.findOmittableDocumentFontFamily(e?.existingDocument));const r=e?.replacementBlock??e?.previousBlock,a=new Map([[!e?.replacementBlock&&
363
+ e?.insertionFont?"body":this.fontSizeKind(r),e?.replacementBlock?n.fontSize:i.fontSize]]);for(const s of t){if(s.type==="table"){this.applyInheritedFontStylingToTable(s,o,a.get("body"));continue}if(s.
364
+ type!=="paragraph"&&s.type!=="list")continue;const c=this.fontSizeKind(s),l=a.get(c);if(s.type==="paragraph")this.ensureTextNodesHaveFontStyling(s.children,o,l);else if(s.type==="list")for(const m of s.
365
+ children)this.ensureTextNodesHaveFontStyling(m.children,o,l);const p=this.extractBlockFontStyling(s);o=p.fontFamily??o,p.fontSize!==void 0&&a.set(c,p.fontSize)}}static applyInheritedFontStylingToTable(t,e,n){
366
+ for(const i of t.children)for(const o of i.children)for(const r of o.children)r.type==="table"?this.applyInheritedFontStylingToTable(r,e,n):(r.type==="paragraph"||r.type==="list")&&this.ensureTextNodesHaveFontStyling(
367
+ r.children,e,this.fontSizeKind(r)==="body"?n:void 0)}static fontSizeKind(t){return t?.type==="paragraph"&&t.heading?t.heading:"body"}static extractBlockFontStyling(t){if(!t)return{};const e=[];if(t.type===
368
+ "paragraph")for(const o of t.children)o.type==="text"&&!o.marks?.footnoteRef&&e.push(o);else if(t.type==="list")for(const o of t.children)for(const r of o.children)r.type==="text"&&!r.marks?.footnoteRef&&
369
+ e.push(r);else if(t.type==="table"){const o=r=>{for(const a of r)if(a.type==="table")for(const s of a.children)for(const c of s.children)o(c.children);else if(a.type==="paragraph"&&!a.heading||a.type===
370
+ "list"){const s=a.type==="list"?a.children.flatMap(c=>c.children):a.children;for(const c of s)c.type==="text"&&c.text&&!c.marks?.footnoteRef&&e.push(c)}};o([t])}if(e.length===0)return{};const n=e[0].marks?.
371
+ fontFamily,i=e[0].marks?.fontSize;return{fontFamily:e.every(o=>o.marks?.fontFamily===n)?n:void 0,fontSize:e.every(o=>o.marks?.fontSize===i)?i:void 0}}static ensureTextNodesHaveFontStyling(t,e,n){t.forEach(
372
+ i=>{i.type==="text"?(i.marks=i.marks?{...i.marks}:{},!i.marks.fontFamily&&e&&(i.marks.fontFamily=e),i.marks.fontSize===void 0&&n!==void 0&&(i.marks.fontSize=n)):i.children&&this.ensureTextNodesHaveFontStyling(
373
+ i.children,e,n)})}static ensureTextNodesHaveFontSize(t,e){for(const n of t)n.type==="text"&&(n.marks=n.marks?{...n.marks}:{},n.marks.fontSize||(n.marks.fontSize=e))}static formatLockedSelectionContext(t){
374
+ if(!t||t.length===0)return null;const e=[];for(const n of t){const i=n.contextBlocks?Ae(n.contextBlocks,n.startBlock,n.endBlock):void 0;if(!i||i.length===0){e.push(`<selection_context_omitted start_id\
375
+ ="${this.escapeAttribute(n.startBlock)}" end_id="${this.escapeAttribute(n.endBlock)}">Selection context exceeds the size limit. Read the actual target before editing; this marker is not document conte\
376
+ nt.</selection_context_omitted>`);continue}const o=this.buildSelectionInfoForBlocks(i,[n]);for(const r of i){const a=this.getBlockId(r),s=o?.get(a);e.push(this.blockToHtmlWithSelections(r,void 0,s,void 0,
377
+ o))}}return e.length===0?null:e.filter(n=>n.length>0).join(`
378
+ `)}};Y.DEFAULT_FONT_FAMILY="Arial, sans-serif",Y.MAX_OVERVIEW_BLOCKS=50,Y.tableRowHtmlCache=new WeakMap;let Ut=Y;const Le=Object.freeze(Object.defineProperty({__proto__:null,AgentHtmlConverter:Ut},Symbol.
379
+ toStringTag,{value:"Module"}));export{Ut as A,U as S,jt as a,rt as b,ot as c,it as d,$e as e,Ot as f,_t as g,at as h,Mt as i,ve as j,Z as k,Pt as l,Et as m,st as n,G as o,Le as p,Lt as s};
@@ -0,0 +1,2 @@
1
+ const s=["show-tracked-changes","show-with-tracked-changes-accepted","show-before-tracked-changes"],c="show-tracked-changes";function t(e){return typeof e=="string"&&s.includes(e)}export{s as A,c as D,
2
+ t as i};