@reviseio/engine 3.0.1 → 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 (39) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/assets/{historyMaterializeWorker-Kl0syEbc.js → historyMaterializeWorker-BMHTnStL.js} +131 -130
  3. package/chunks/{AgentHtmlConverter-CnnB8-WI.js → AgentHtmlConverter-B5qstcmM.js} +129 -128
  4. package/chunks/{AgentPageRenderer-DLgUGrGy.js → AgentPageRenderer-JMhCw-hi.js} +4 -4
  5. package/chunks/BlockDiff-C8eiZ-sf.js +45 -0
  6. package/chunks/{CanvasRenderer-C1Vegx9Y.js → CanvasRenderer-C2vAzLWM.js} +12 -12
  7. package/chunks/DocumentCompare-DX4RWeSV.js +10 -0
  8. package/chunks/{DocumentLayoutEngine-C62pyGVf.js → DocumentLayoutEngine-BhcWXkeu.js} +45 -45
  9. package/chunks/{DocumentMutator-Bat_oLBQ.js → DocumentMutator-FEFU1YM0.js} +6 -6
  10. package/chunks/DocumentOutline-BOZoTohH.js +4 -0
  11. package/chunks/{DocumentScrubber-BZQn_z92.js → DocumentScrubber-C4N3Qagm.js} +1 -1
  12. package/chunks/{DocumentSession-BDcazSEv.js → DocumentSession-gZHWP7By.js} +1 -1
  13. package/chunks/{DocxConverter-BC31uYIL.js → DocxConverter-BOyLn5eZ.js} +709 -703
  14. package/chunks/{DocxGraft-L10HXM3U.js → DocxGraft-BbE-AaM5.js} +2 -2
  15. package/chunks/{HtmlConverter-C5ihhZ6G.js → HtmlConverter-BlzwsPEn.js} +3 -3
  16. package/chunks/MarkdownConverter-BHVskVXI.js +59 -0
  17. package/chunks/{OdtConverter-c1fTWoAt.js → OdtConverter-BdmBFOD1.js} +1 -1
  18. package/chunks/{OfficeImportShared-CrOpHpJ-.js → OfficeImportShared-B2XJgnDO.js} +4 -4
  19. package/chunks/{PdfConverter-DX7fsRH5.js → PdfConverter-DZMCHDAo.js} +6 -6
  20. package/chunks/{RtfConverter-hbJ2529G.js → RtfConverter-RqE-xZcW.js} +2 -2
  21. package/chunks/{TableBorders-DVhdvo6f.js → TableBorders-ARyTi49V.js} +1 -1
  22. package/chunks/{TxtConverter-YHv5FXWb.js → TxtConverter-EPQtb6A6.js} +1 -1
  23. package/chunks/{Typography-B4gndEdB.js → Typography-XR6scRNV.js} +9 -9
  24. package/chunks/{XmlConverter-BRRluy9k.js → XmlConverter-9sFRFaza.js} +1 -1
  25. package/chunks/{capture-i_dPkQIS.js → capture-DhGn0CWA.js} +1 -1
  26. package/chunks/{carrier-pYM9xf6x.js → carrier-D58g-gw4.js} +1 -1
  27. package/chunks/{chromeImageLayout-BiQ3Iz1-.js → chromeImageLayout-DeYYS8YP.js} +1 -1
  28. package/chunks/{engine-LMUnxdm2.js → engine-C5fxuZJo.js} +139 -139
  29. package/chunks/{footnoteFlatten-EE85Hjre.js → footnoteFlatten-coCVFd3c.js} +1 -1
  30. package/chunks/{graftExport-G-dG7Vcc.js → graftExport-FBGE2qvt.js} +1 -1
  31. package/chunks/{index-BLb10wQt.js → index-Cezk1s_y.js} +4 -4
  32. package/chunks/{serverDocumentSession-DGDU5Lh3.js → serverDocumentSession-LMu3kocH.js} +559 -560
  33. package/chunks/{signatures-DTNDS2PH.js → signatures-DsJnnIqV.js} +1 -1
  34. package/chunks/textExtraction-Bqaqt1Kg.js +2 -0
  35. package/engine.js +2 -2
  36. package/package.json +2 -2
  37. package/chunks/BlockDiff-B6-aJxHo.js +0 -42
  38. package/chunks/DocumentCompare-C8295s35.js +0 -6
  39. package/chunks/MarkdownConverter-DofaSeC4.js +0 -57
@@ -1,50 +1,51 @@
1
- import{f as K,h as Kt,u as Vt}from"./CanvasRenderer-C1Vegx9Y.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-LMUnxdm2.js";import{e as ae,r as vt,s as ce,p as le,i as de}from"./ListNumbering-Qlu6AuRZ.js";
1
+ import{f as V,h as Kt,u as Vt}from"./CanvasRenderer-C2vAzLWM.js";import{b as Z,e as Jt}from"./TableGrid-DbroRucl.js";import{r as nt,aO as z,aP as gt,e as Gt,aQ as Xt,z as ft,aR as Zt,aS as Qt,aT as it,
2
+ aU as Yt,W as bt,aV as yt,Q as xt,O as te,aW as $t,N as ee,a as G,C as kt,aX as ne,aY as ie,aZ as oe,a_ as re,a$ as se}from"./engine-C5fxuZJo.js";import{e as ae,r as vt,s as ce,p as le,i as de}from"./ListNumbering-Qlu6AuRZ.js";
3
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-DVhdvo6f.js";import{h as V,H as fe,D as be}from"./Typography-B4gndEdB.js";const Bt=/<!--[^]*?-->|<\/?[a-zA-Z][\w:-]*(?:\s+(?:[^"'<>]|"[^"]*"|'[^']*')*)?\s*\/?>/g,Ht={amp:"&",
4
+ j as ge}from"./TableBorders-ARyTi49V.js";import{h as J,H as fe,D as be}from"./Typography-XR6scRNV.js";const Bt=/<!--[^]*?-->|<\/?[a-zA-Z][\w:-]*(?:\s+(?:[^"'<>]|"[^"]*"|'[^']*')*)?\s*\/?>/g,Lt={amp:"&",
5
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(
6
+ emsp:" ",thinsp:" ",ndash:"–",mdash:"—",hellip:"…",copy:"©",reg:"®",trade:"™"},ye=/[\u0085\u2028\u2029]/g;function Ht(u){return u.replace(ye," ")}function xe(u){return u.replace(/\\+(["'])/g,
7
+ "$1")}function ot(u){return xe(u.replace(/&(#(?:\d+|x[0-9a-f]+)|[a-z]+);/gi,(t,e)=>{if(!e.startsWith("#"))return Object.prototype.hasOwnProperty.call(Lt,e)?Lt[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 rt(u){return u.search(Bt)>=0}function X(u){return ot(u.replace(Bt,t=>/^<br\b/i.test(
9
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);
10
+ `:""))}function Et(u){const t=ot(u);return[...new Set(rt(u)?[u,t,X(u)]:[u,t])]}function st(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=zt(u,i,e);if(o.length)return o}return[]}function Q(u){return u.replace(/<\/?comment-thread\b[^>]*>/gi,"")}function Pt(u,t){return lt(Q(u),Q(t))}function Mt(u,t,e){if(!rt(e))return[];t=Q(t);const n=X(
12
+ t);return n.length!==u.length||ct(n)!==ct(u)?[]:Pt(t,e).map(({start:i,end:o})=>({start:X(t.slice(0,i)).length,end:X(t.slice(0,o)).length})).filter(i=>i.end>i.start)}function at(u){let t="";const e=[],
13
+ n=[];for(let i=0;i<u.length;i++){const o=i;let r=Ot(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 Ot(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 ct(u){let t="";for(let e=0;e<u.length;e++){const n=Ot(u[e]);
15
+ t+=/[\u2012-\u2014]/u.test(n)?"-":n}return t}function lt(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 zt(u,t,e="prefer-exact"){if(e!=="normalized"){const o=lt(u,t);if(o.length>0||e==="exact")return o}const n=at(u),i=at(t).text;return i.trim()?lt(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):st(u,t,o,n),a=i?i(e,o):st(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 dt(u){if(!u)return;const t=u.trim().match(/^(\d+(?:\.\d+)?|\.\d+)(px|pt|in)?$/i);
19
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
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().
21
+ e?.top,i=u.match(/(?:^|;)\s*margin-bottom:\s*([^;]+)/i)?.[1]??e?.bottom,o=dt(n);o!==void 0&&(t.spaceBefore=Math.round(o*100)/100);const r=dt(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 K 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 K?{code:u.code,phase:u.phase,retryable:u.
24
+ retryable,mutationOutcome:u.mutationOutcome,details:u.details}:void 0}const jt=24e3,Dt=25;function Ae(u,t,e){const n={type:"doc",children:u},i=u.findIndex(s=>!!V({...n,children:[s]},t)),o=u.findIndex(
25
+ s=>!!V({...n,children:[s]},e)),r=u.flatMap((s,c)=>{if(s.type!=="table"||s.children.length<Dt)return[s];const l=s.children.findIndex(g=>g.children.some(y=>!!V(y,t))),p=s.children.findIndex(g=>g.children.
26
+ some(y=>!!V(y,e)));if(!((i<0||c>=i)&&(o<0||c<=o))||l<0&&p<0&&i===o)return[];const m=Z(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<=jt)return r;const a=[t,e].flatMap((s,c)=>{if(c&&s===t)return[];for(const l of u){const p=V({type:"doc",children:[l]},s);if(p)
28
+ return[p]}return[]});return JSON.stringify(a).length<=jt?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
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
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(`
31
+ function Se(u){return u.tagName.toLowerCase()==="del"&&u.hasAttribute("data-change-id")}function Ie(u){const t=u?.trim().match(/^([\d.]+)(px|pt)?$/i);if(!t)return;const e=parseFloat(t[1]);if(Number.isFinite(
32
+ e))return t[2]?.toLowerCase()==="pt"?e*4/3:e}function we(u){if(!u)return;const t=i=>u.match(new RegExp(`(?:^|;)\\s*${i}\\s*:\\s*([^;]+)`,"i"))?.[1]?.trim(),e=St(t("border")),n={};for(const i of["top",
33
+ "bottom","left","right"]){const o=u.match(new RegExp(`border-${i}:\\s*([\\d.]+)px\\s+(solid|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=
34
+ {width:s==="none"?0:parseFloat(o[1]),style:s==="solid"?"single":s,color:o[3]}}else{const s=St(t(`border-${i}`))??e;s&&(r={...s})}if(!r)continue;const a=Ie(t(`padding-${i}`));a!==void 0&&a>0&&(r.space=
35
+ Math.round(a*100)/100),n[i]=r}return Object.keys(n).length>0?JSON.stringify(n):void 0}const Ce=new Set(["p","center","h1","h2","h3","h4","h5","h6","ul","ol","div","table","pre","img","latex","page-bre\
36
+ ak","section-break","toc","hr","docx-raw"]),Te=/[&<>"']/,Fe=/[&<>"']/g,Ne={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#039;"};function Be(u){return Ne[u]??u}function Le(u){const t=u.trim();if(t.
37
+ length<2)return t;const e=[['"','"'],["'","'"],["“","”"],["‘","’"]];for(const[n,i]of e)if(t.startsWith(n)&&t.endsWith(i))return t.slice(n.length,t.length-i.length).trim();return t}let Y=null;function ht(u){
38
+ return Y||(Y=new DOMParser().parseFromString("","text/html")),Y.body.innerHTML=u.replace(/<!--[\s\S]*?-->|<\/?[a-z][a-z0-9-]*(?:[^<>"']|"[^"]*"|'[^']*')*>/gi,t=>{const e=t.match(/^<(page-break|section-break|docx-raw|toc)(?=[\s/>])/i);
39
+ return e&&/\/\s*>$/.test(t)?t.replace(/\/\s*>$/,`></${e[1]}>`):t}),Y}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("i\
40
+ d"in n&&n.id&&t.add(n.id),n.type!=="paragraph"){if(n.type==="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.
41
+ children){i.id&&t.add(i.id);for(const o of i.children){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||G();if(u&&t.
42
+ validIds.has(u)&&!t.usedIds.has(u))return t.usedIds.add(u),u;let e=G();for(;t.usedIds.has(e);)e=G();return t.usedIds.add(e),e}const tt=class{static createParsingContext(t){const e=new Map,n=i=>{i.type===
43
+ "image"&&e.set(i.id,i),"children"in i&&i.children.forEach(n)};n(t);for(const i of t.notes??[])n(i);return{imagesById:e,validIds:qt(t),indentStepPx:this.resolveIndentStepPx(t),documentFontFamily:this.findOmittableDocumentFontFamily(
44
+ t)}}static toAgentHtml(t,e={}){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>
45
+ 0).join(`
45
46
  `);return i&&o.length>0?`${i}
46
47
  ${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
+ const e=t.pageless===!0;if(!t.pageLayout&&!e)return null;const n=nt(t.pageLayout),i=this.formatInchesForComment(z(n.marginTopPx)),o=this.formatInchesForComment(z(n.marginRightPx)),r=this.formatInchesForComment(
48
49
  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
50
  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
51
  er-position="${p.pageNumberPosition}" page-number-start="${n.pageNumberStart}"${n.pageNumberFormat!=="decimal"?` page-number-format="${n.pageNumberFormat}"`:""}`,f=this.formatInchesForComment(gt(n.columnGapTwips));
@@ -57,7 +58,7 @@ p.length),f=[];let d=1;if(m>0&&s.length>0){d=Math.max(1,Math.ceil(s.length/m));f
57
58
  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
59
  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
60
  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
+ o.sections.length>0?{sections:o.sections}:{}}}static toDocumentLayoutContext(t){const e=nt(t.pageLayout),n=Gt(e),i=this.getEffectivePageNumberSettings(t,e);return{pageless:t.pageless===!0,pageSize:e.pageSize,
61
62
  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
63
  z(e.marginRightPx)),marginBottom:this.formatInchesLength(z(e.marginBottomPx)),marginLeft:this.formatInchesLength(z(e.marginLeftPx)),indentStep:this.formatInchesLength(z(e.indentStepPx)),blockSpacing:this.
63
64
  formatInchesLength(z(e.blockSpacingPx)),columnCount:e.columnCount,columnGap:this.formatInchesLength(gt(e.columnGapTwips)),showPageNumbers:i.showPageNumbers,pageNumberPosition:i.pageNumberPosition,pageNumberStart:e.
@@ -78,15 +79,15 @@ c,t,s)).filter(c=>c.length>0).join(`
78
79
  `),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
80
  push(t.html),e.join(`
80
81
  `)}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&&
82
+ includes(a.toLowerCase())}}}else{const a=Le(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(
83
+ 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?J(e):void 0;if(e&&
83
84
  !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
85
  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
86
  ...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
87
  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
88
  html:a.filter(d=>d.length>0).join(`
88
89
  `),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
+ e.id),o=this.tableRowToHtml(t,e,i,Z(t),n);return`<table_row table_id="${this.escapeAttribute(t.id)}" id="${this.escapeAttribute(e.id)}" row_index="${i}">
90
91
  ${o}
91
92
  </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
93
  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===
@@ -116,7 +117,7 @@ c.push(`font-size: ${e.fontSize}px`),e.color&&c.push(`color: ${this.escapeHtml(e
116
117
  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
118
  `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
119
  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
+ `<span data-field-instr="${this.escapeHtml(e.fieldInstr)}">${s}</span>`);const f=J(e.backgroundColor);f&&(s=`<mark color="${this.escapeHtml(f)}">${s}</mark>`),e.link&&(s=`<a href="${this.escapeHtml(e.
120
121
  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
122
  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
123
  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(`\
@@ -126,8 +127,8 @@ const e=this.getBlockPlainText(t).split(/\s+/).filter(i=>i.length>0),n=e.slice(0
126
127
  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
128
  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
129
  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)
130
+ 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=J(
131
+ n.marks?.backgroundColor);i&&e.add(i)}break;case"list":for(const n of t.children)for(const i of n.children){const o=J(i.marks?.backgroundColor);o&&e.add(o)}break;case"container":for(const n of t.children)
131
132
  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
133
  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
134
  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"\
@@ -144,8 +145,8 @@ const e=t.language?.trim().toLowerCase();if(e==="latex"||e==="latex-inline"){con
144
145
  "");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
146
  <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
147
  "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),
148
+ t)?null:Qt(t);if(i){const d=t.id?` id="${this.escapeHtml(t.id)}"`:"",h=At(i.style),g=i.width===it.width&&i.color.toLowerCase()===it.color.toLowerCase(),y=h?` data-rule="${i.style}"`:"";let $="";if(!g||
149
+ !h&&i.style!==it.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
150
  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
151
  ""),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
152
  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\
@@ -154,7 +155,7 @@ if(t.spaceBefore!==void 0||t.spaceAfter!==void 0||t.lineSpacing!==void 0||t.keep
154
155
  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
156
  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
157
  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
+ [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,J(t?.backgroundColor)??
158
159
  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
160
  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
161
  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.
@@ -162,8 +163,8 @@ escapeAttribute(s)}">${t}</comment-thread>`}return t}static collectCommentThread
162
163
  !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
164
  -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
165
  ` 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 \
166
+ 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 J(t)}static escapeHtml(t){const e=Ht(t);return Te.
167
+ test(e)?e.replace(Fe,Be):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
168
  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
169
  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
170
  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){
@@ -171,13 +172,13 @@ const e={},n=this.extractFontSizeFromStyle(t);n!==void 0&&n>0&&(e.fontSize=n),th
171
172
  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
173
  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
174
  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
+ if(Number.isFinite(i))return i>=600}static resolveIndentStepPx(t){return nt(t?.pageLayout).indentStepPx}static applyParagraphElementAttributes(t,e,n){const i=e.getAttribute("style");if(i){const s=this.
175
176
  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
177
  !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
178
  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
+ 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 dt(t)}static extractParagraphStyleAttributes(t,e=this.
179
180
  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
+ {const p=we(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
182
  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
183
  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
184
  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(
@@ -203,33 +204,33 @@ escapeAttribute(t.src)}"`:' data-image-source="hidden"';return`<img id="${this.e
203
204
  "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
205
  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
206
  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(`
207
+ rgin-bottom: ${b.spaceAfter}px`]:[]];I&&I!==e&&E.push(`font-family: ${this.escapeHtml(I)}`);const T=E.length>0?` style="${E.join("; ")}"`:"",F=b.id?` id="${this.escapeAttribute(b.id)}"`:"",P=b.direction?
208
+ ` dir="${b.direction}"`:"",_=S!==0||i.includeZeroListLevels?` data-indent-level="${S}"`:"",D=b.heading?` data-heading="${b.heading}"`:"",M=`${F}${T}${P}${_}${D}`,R=a.get(b),q=R?this.textNodesToHtmlWithSelections(
209
+ b.children,n,R,e):this.coalesceAdjacentTextNodesForHtml(b.children,I,void 0,e).map(O=>O.type==="text"?this.textNodeToHtml(O,void 0,n,void 0,I,e):"").join(""),H=[];let L=v+1;for(;L<x.length&&(x[L].indentLevel||
210
+ 0)>S;)H.push(x[L]),L++;let N=q;if(H.length>0){const O=t.variant==="ordered"?"ol":"ul",W=`<${O}>${c(H,S+1)}</${O}>`;N=q+W}if(t.variant==="todo"&&(N=`<input type="checkbox"${b.checked?" checked":""}>${N}`),
211
+ n&&b.id){const O=(n.comments??[]).filter(W=>!W.parentId&&W.anchorBlockId===b.id).map(W=>W.id);N=this.wrapWithCommentThreads(N,O,n)}k.push(`<li${M}>${N}</li>`),v=L}else v++}return k.join("")},l=c(t.children,
212
+ 0),p=t.id?` id="${this.escapeAttribute(t.id)}"`:"",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\
213
+ -height: ${t.lineSpacing}`]:[],...t.spaceBefore!==void 0?[`margin-top: ${t.spaceBefore}px`]:[],...t.spaceAfter!==void 0?[`margin-bottom: ${t.spaceAfter}px`]:[]],h=d.length?` style="${d.join("; ")}"`:"",
214
+ g=t.contextualSpacing!==void 0?` data-contextual-spacing="${t.contextualSpacing}"`:"",y=t.numberingChainId?` data-numbering-chain-id="${this.escapeAttribute(t.numberingChainId)}" data-start-number="${t.
215
+ startNumber??""}" data-effective-start="${m}"`:"",$=t.numberingFormat?` data-numbering-format="${this.escapeAttribute(t.numberingFormat)}"`:"";return`<${r}${p}${f}${h}${g}${y}${$}>${l}</${r}>`}static containerToHtml(t,e,n,i={}){
216
+ const o=t.id?` id="${this.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>
217
+ 0?` style="${r.join("; ")}"`:"",s=t.children.map(c=>this.blockToHtml(c,e,n,i)).filter(c=>c.length>0).join(`
217
218
  `);return`<div class="container"${o}${a}>
218
219
  ${s}
219
220
  </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
221
  %"),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
222
  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
+ t.borders)}"`}const c=` style="${r.join("; ")}"`,l=Z(t),p=t.children.map((m,f)=>this.tableRowToHtml(t,m,f,l,e,n,i)).join(`
223
224
  `);return`<table${o}${s}${c}>
224
225
  ${p}
225
226
  </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
227
  [])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
228
  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"),
229
+ 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 T=0;for(let F=y.
230
+ col;F<y.col+y.colSpan;F++)T+=t.columnWidths[F]||0;A=T>0?T:void 0}else A=t.columnWidths[h];const k=[];let v="";const b=Ct(d.borders);if(b){for(const T of["top","right","bottom","left"]){const F=b[T];F&&
231
+ k.push(`border-${T}: ${wt(F)}`)}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
232
  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
+ join("; ")}"`,E=d.children.map(T=>this.blockToHtml(T,o,r,a)).filter(T=>T.length>0).join("");return`<${p}${g}${$}${v}${I}${x}>${E}</${p}>`}).join(""),f=`<tr${e.id?` id="${this.escapeAttribute(e.id)}"`:
233
234
  ""}>${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
235
  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
236
  blockToHtml(c,e,n,i)).filter(c=>c.length>0).join(`
@@ -247,49 +248,49 @@ return a}static parseImageElement(t,e){const n=e?.imageReferences?.get(t);if(n){
247
248
  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
249
  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
250
  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
+ 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:G(),src:i,width:m,height:f};return c&&
251
252
  (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
253
  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);
254
+ "div");let b=!1;const S=[];for(const L of Array.from(k.childNodes))if(L.nodeType===Node.ELEMENT_NODE){const N=L,O=N.tagName.toLowerCase();O==="ul"||O==="ol"?(b=!0,S.push(N)):v.appendChild(L.cloneNode(
255
+ !0))}else v.appendChild(L.cloneNode(!0));const I=k.getAttribute("style"),E=I?{...A,...this.extractTextStyleMarksFromStyle(I)}:A,T=v.querySelector('input[type="checkbox"]');T&&(o="todo",T.remove());const F=this.
256
+ parseHtmlElement(v,E),P={type:"list-item",id:C(k.getAttribute("id"),e),children:F.length>0?F:[{type:"text",text:"",marks:{}}]};T&&(P.checked=T.hasAttribute("checked"));const _=k.getAttribute("dir")??I?.
257
+ match(/(?:^|;)\s*direction:\s*(rtl|ltr)\s*(?:;|$)/i)?.[1];if((_==="rtl"||_==="ltr")&&(P.direction=_),I){const L=this.extractParagraphStyleAttributes(I);for(const N of["lineSpacing","spaceBefore","spac\
258
+ eAfter"])L[N]!==void 0&&(P[N]=L[N])}const D=Number(k.getAttribute("data-heading"));Number.isInteger(D)&&D>=1&&D<=6&&(P.heading=D);const M=k.getAttribute("data-indent-level"),R=M!==null?Number(M):NaN,q=Number.
259
+ isInteger(R)&&R>=0&&R<=8,H=q?R:h;if(H>0&&(P.indentLevel=H),$.push(P),b)for(const L of S){const N=q?Math.max(y,Math.min(H+2,8)):y,O=r(L,Math.min(H+1,N),E,N);$.push(...O)}}return $},a=r(t,n);if(a.length===
260
+ 0)return null;const s={type:"list",id:C(t.getAttribute("id"),e),variant:o,children:a};if(o==="ordered"){const d=t.getAttribute("start");if(d){const h=parseInt(d,10);!isNaN(h)&&h!==1&&(s.startNumber=h)}}
261
+ const c=t.getAttribute("style");if(c){const d=this.extractParagraphStyleAttributes(c);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);
262
+ if(h){const g=parseFloat(h[1]);Number.isFinite(g)&&g>=.5&&g<=4&&(s.lineSpacing=g)}}const l=t.getAttribute("data-contextual-spacing");(l==="true"||l==="false")&&(s.contextualSpacing=l==="true");const p=t.
263
+ getAttribute("data-numbering-chain-id");if(p&&o==="ordered"){s.numberingChainId=p;const d=t.getAttribute("data-start-number"),h=Number(t.getAttribute("data-effective-start")),g=Number(t.getAttribute("\
264
+ start")??1);t.hasAttribute("start")&&Number.isInteger(h)&&h>0&&Number.isInteger(g)&&g>0&&g!==h?s.startNumber=g:d===""?delete s.startNumber:d!==null&&Number.isInteger(Number(d))&&Number(d)>0&&(s.startNumber=
265
+ Number(d))}const m=t.getAttribute("data-numbering-format");m&&le(m)&&(s.numberingFormat=m);const f=t.getAttribute("style");if(f){const d=f.match(/font-family:\s*([^;]+)/);if(d){const h=this.resolveFontToCss(
266
+ d[1].trim());for(const g of s.children)for(const y of g.children)y.type==="text"&&(y.marks||(y.marks={}),y.marks.fontFamily||(y.marks.fontFamily=h))}}return s}static parseContainerElement(t,e,n){const i=C(
267
+ t.getAttribute("id"),n),o=t.getAttribute("style");let r,a;if(o){const p=o.match(/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.
268
+ resolveIndentStepPx(e?.existingDocument),c=[];for(const p of Array.from(t.children)){const m=p.tagName.toLowerCase();if(m==="p"||m.match(/^h[1-6]$/)){const f=m.match(/^h([1-6])$/),d=p.getAttribute("st\
269
+ yle"),h=this.parseHtmlElement(p,d?this.extractTextStyleMarksFromStyle(d):{}),g={type:"paragraph",id:C(p.getAttribute("id"),n),children:h.length>0?h:[{type:"text",text:"",marks:{}}]};f&&(g.heading=parseInt(
270
+ f[1])),this.applyParagraphElementAttributes(g,p,s),c.push(g)}else if(m==="ul"||m==="ol"){const f=this.parseListElement(p,n);f&&c.push(f)}else if(m==="hr")c.push(this.parseHrElement(p,n));else if(m==="\
271
+ img"){const f=this.parseImageElement(p,n);f&&c.push(f)}else if(m==="div"&&p.classList.contains("container")){const f=this.parseContainerElement(p,e,n);f&&c.push(f)}}if(c.length===0)return null;const l={
272
+ type:"container",id:i,children:c};return r&&(l.borderColor=r),a!==void 0&&(l.padding=a),l}static parseTableElement(t,e,n){const i=C(t.getAttribute("id"),n),o=this.resolveIndentStepPx(e?.existingDocument),
273
+ r=t.getAttribute("style");let a,s,c;if(r){const v=r.match(/width:\s*(\d+)px/);v&&(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/.
274
+ test(r)?c="center":/margin-left:\s*auto/.test(r)&&/margin-right:\s*0/.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(
275
+ ":scope > td, :scope > th");v===0&&I.length>0&&I[0].tagName.toLowerCase()==="th"&&(m=!0);for(let T=0;T<I.length;T++){const F=I[T],P=F.getAttribute("style");let _,D;if(P){const w=P.match(/vertical-align:\s*([^;]+)/);
276
+ if(w){const U=w[1].trim();(U==="top"||U==="middle"||U==="bottom")&&(_=U)}const B=P.match(/background-color:\s*([^;]+)/);B&&(D=B[1].trim())}const M=[],R=F.children,q=Array.from(R).every(w=>!/^(p|h[1-6]|ul|ol|table|img|hr|div|blockquote|pre)$/.
277
+ test(w.tagName.toLowerCase()));if(R.length===0){const w=F.textContent||"";M.push({type:"paragraph",id:C(null,n),children:[{type:"text",text:w,marks:{}}]})}else if(q){const w=this.parseHtmlElement(F,{});
278
+ M.push({type:"paragraph",id:C(null,n),children:w.length>0?w:[{type:"text",text:"",marks:{}}]})}else for(const w of Array.from(R)){const B=w.tagName.toLowerCase(),U=B==="img"?this.parseImageElement(w,n):
279
+ B==="p"?this.parseSingleImageParagraph(w,n):null;if(U){M.push(U);continue}if(B==="p"||B.match(/^h[1-6]$/)){const j=B.match(/^h([1-6])$/),ut=w.getAttribute("style"),mt=this.parseHtmlElement(w,ut?this.extractTextStyleMarksFromStyle(
280
+ ut):{}),et={type:"paragraph",id:C(w.getAttribute("id"),n),children:mt.length>0?mt:[{type:"text",text:"",marks:{}}]};j&&(et.heading=parseInt(j[1])),this.applyParagraphElementAttributes(et,w,o),M.push(et)}else if(B===
281
+ "ul"||B==="ol"){const j=this.parseListElement(w,n);j&&M.push(j)}else if(B==="hr")M.push(this.parseHrElement(w,n));else if(B==="table"){const j=this.parseTableElement(w,e,n);j&&M.push(j)}else{const j=w.
282
+ textContent||"";j.trim()&&M.push({type:"paragraph",id:C(null,n),children:[{type:"text",text:j,marks:{}}]})}}M.length===0&&M.push({type:"paragraph",id:C(null,n),children:[{type:"text",text:"",marks:{}}]});
283
+ const H={type:"table-cell",id:C(F.getAttribute("id"),n),children:M},L=P?.match(/width:\s*([\d.]+)%/);if(L){const w=parseFloat(L[1]);Number.isFinite(w)&&w>0&&p.set(H,w)}_&&(H.verticalAlign=_),D&&(H.backgroundColor=
284
+ D);const N=Ct(F.getAttribute("data-borders")),O=N?Tt(N):Ft(Nt(P));if(O&&(H.borders=O),P){const w=P.match(/(?:^|;)\s*padding\s*:\s*([^;]+)/i),B=me(w?.[1]);B&&!(B.top===8&&B.right===8&&B.bottom===8&&B.left===
285
+ 8)&&(H.padding=ge(B))}const W=this.parseSpanAttribute(F.getAttribute("colspan")),pt=this.parseSpanAttribute(F.getAttribute("rowspan"));W>1&&(H.colSpan=W),pt>1&&(H.rowSpan=pt),S.push(H)}const E=C(b.getAttribute(
286
+ "id"),n);l.push({type:"table-row",id:E,children:S})}if(!l.some(v=>v.children.length>0))return null;const d=Z({children:l,columnWidths:[]}),h=d.cols||1,g=new Array(h).fill(0),y=new Array(h).fill(!1);for(const v of d.
287
+ 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.max(1,(100-v)/$);for(let S=0;S<
288
+ 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(t.getAttribute("data-borders")),
289
+ 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){const n=C(
290
+ 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("language\
291
+ -")){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(t.
292
+ 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==="ce\
293
+ nter"||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
294
  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
295
  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
296
  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===
@@ -308,21 +309,21 @@ right";if(i.includes("margin-right: auto"))return"left"}static getImageStyle(t){
308
309
  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
310
  (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
311
  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
+ "&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=ht(i),r=Array.from(o.body.childNodes),
312
313
  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
314
  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
315
  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
+ remainingImageReferences:new Set};e={...e,parsingContext:n};let a=ht(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
317
  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,
318
+ 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=>Ce.has(h.tagName.toLowerCase()))||
319
+ (a=ht(`<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
320
  $=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
+ v||x&&A===void 0&&x!==v&&x!==b.src)throw new K("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
322
  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("\
323
+ test(x))throw new K("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\
324
+ 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 K("\
324
325
  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
+ 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 K("invalid_image_reference",`Image "${b.id}" is referenced more\
326
327
  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
328
  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
329
  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(
@@ -335,18 +336,18 @@ A=this.extractFontSizeFromStyle($)}const k=C(h.getAttribute("id"),r),v=$?this.ex
335
336
  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
337
  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
338
  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
+ 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 K("invalid_image_reference",`Image(s)\
339
340
  ${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
341
  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
+ 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?V(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
343
  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
344
  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:`
345
+ marks:{...s}})}else if(a.nodeType===Node.ELEMENT_NODE){const c=a;if(Se(c))return;const l={...s};switch(c.tagName.toLowerCase()){case"b":case"strong":l.bold=!0;break;case"i":case"em":l.italic=!0;break;case"\
346
+ u":l.underline=!0;break;case"s":case"strike":case"del":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(
347
+ "data-footnote-ref");f&&(l.footnoteRef=f);const d=c.getAttribute("data-footnote");d!==null&&(l.footnoteRef=f??G(),l.footnotePendingBody=d,c.getAttribute("data-note-kind")==="endnote"&&(l.footnotePendingKind=
348
+ "endnote"));break}case"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.
349
+ stringify(f)}. Use one 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){
350
+ const d=l.comment?.split(",").map(h=>h.trim()).filter(Boolean);l.comment=[...d??[],f].join(",")}break}case"br":i.push({type:"text",text:`
350
351
  `,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
352
  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
353
  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(
@@ -375,5 +376,5 @@ if(!t||t.length===0)return null;const e=[];for(const n of t){const i=n.contextBl
375
376
  ="${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
377
  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
378
  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};
379
+ `)}};tt.DEFAULT_FONT_FAMILY="Arial, sans-serif",tt.MAX_OVERVIEW_BLOCKS=50,tt.tableRowHtmlCache=new WeakMap;let Ut=tt;const Ee=Object.freeze(Object.defineProperty({__proto__:null,AgentHtmlConverter:Ut},
380
+ Symbol.toStringTag,{value:"Module"}));export{Ut as A,K as S,Dt as a,st as b,rt as c,ot as d,$e as e,zt as f,_t as g,ct as h,Mt as i,ve as j,Q as k,Pt as l,Et as m,at as n,X as o,Ee as p,Ht as s};
@@ -1,7 +1,7 @@
1
- import*as E from"yjs";import{S as G}from"./AgentHtmlConverter-CnnB8-WI.js";import{r as ct,f as Jt,D as Xt}from"./DocumentMutator-Bat_oLBQ.js";import{p as lt,f as Q,h as Vt,y as dt}from"./engine-LMUnxdm2.js";
2
- import{D as Z,i as Qt}from"./AgentPageRenderViews-BTLjPZJQ.js";import{g as gt,c as Zt,d as ft,a as tt,w as ht,b as te,e as ee}from"./CanvasRenderer-C1Vegx9Y.js";import{g as et}from"./Typography-B4gndEdB.js";
3
- import{g as oe,a as B,c as ut,b as ne}from"./index-BLb10wQt.js";import{c as ae,f as j,b as _,g as q,a as ie,d as ot,e as se}from"./DocumentLayoutEngine-C62pyGVf.js";import{getLayoutMarginTop as mt,getLayoutMarginRight as re,
4
- getLayoutMarginBottom as pt,getLayoutMarginLeft as z,layoutForBlockBounds as yt}from"./DocumentLayout-CsU5MR-3.js";import{r as ce,g as le,e as de}from"./MathRenderer-Bz9WEVvF.js";import{p as ge}from"./TableBorders-DVhdvo6f.js";
1
+ import*as E from"yjs";import{S as G}from"./AgentHtmlConverter-B5qstcmM.js";import{r as ct,f as Jt,D as Xt}from"./DocumentMutator-FEFU1YM0.js";import{p as lt,f as Q,h as Vt,y as dt}from"./engine-C5fxuZJo.js";
2
+ import{D as Z,i as Qt}from"./AgentPageRenderViews-BTLjPZJQ.js";import{g as gt,c as Zt,d as ft,a as tt,w as ht,b as te,e as ee}from"./CanvasRenderer-C2vAzLWM.js";import{g as et}from"./Typography-XR6scRNV.js";
3
+ import{g as oe,a as B,c as ut,b as ne}from"./index-Cezk1s_y.js";import{c as ae,f as j,b as _,g as q,a as ie,d as ot,e as se}from"./DocumentLayoutEngine-BhcWXkeu.js";import{getLayoutMarginTop as mt,getLayoutMarginRight as re,
4
+ getLayoutMarginBottom as pt,getLayoutMarginLeft as z,layoutForBlockBounds as yt}from"./DocumentLayout-CsU5MR-3.js";import{r as ce,g as le,e as de}from"./MathRenderer-Bz9WEVvF.js";import{p as ge}from"./TableBorders-ARyTi49V.js";
5
5
  import{r as fe}from"./BidiText-Bkp4Y90s.js";import{g as he}from"./PageNumeralFonts-BWzI061X.js";function bt(t,e){const n=e?.saturation,o=e?.lightness,i=e?.hueRange??[0,360];let a=5381;for(let d=0;d<t.
6
6
  length;d++)a=(a<<5)+a+t.charCodeAt(d),a|=0;const s=Math.abs(a)%1e3,[l,r]=i,c=Math.max(0,r-l);return`hsl(${l+s%(c||360)} ${n}% ${o}%)`}const xt=class U{constructor(){this.cache=new Map,this.loadingImages=
7
7
  new Set,this.failedImages=new Set}static getInstance(){return U.instance||(U.instance=new U),U.instance}getImage(e){return this.cache.get(e)||(this.failedImages.has(e)||this.loadingImages.has(e)||this.