@ansonlai/docx-redline-js 0.1.4 → 0.2.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 (47) hide show
  1. package/AGENTS.md +53 -4
  2. package/ARCHITECTURE.md +75 -11
  3. package/README.md +62 -3
  4. package/core/redline-validation.js +156 -0
  5. package/core/types.js +35 -8
  6. package/core/word-xml.js +90 -0
  7. package/dist/docx-redline-js.esm.js +3195 -2592
  8. package/dist/docx-redline-js.esm.js.map +4 -4
  9. package/dist/docx-redline-js.esm.min.js +71 -67
  10. package/dist/docx-redline-js.esm.min.js.map +4 -4
  11. package/docs/VALIDATION.md +104 -0
  12. package/docs/plans/2026-03-01-release-0.1.4-design.md +31 -0
  13. package/docs/plans/2026-03-01-release-0.1.4.md +108 -0
  14. package/docs/plans/2026-05-31-architectural changes.md +591 -0
  15. package/engine/format-application.js +13 -14
  16. package/engine/format-span-application.js +7 -6
  17. package/engine/formatting-removal.js +15 -12
  18. package/engine/oxml-engine.js +146 -55
  19. package/engine/reconstruction-mapper.js +35 -8
  20. package/engine/reconstruction-mode.js +14 -13
  21. package/engine/reconstruction-writer.js +97 -78
  22. package/engine/rpr-helpers.js +34 -32
  23. package/engine/run-builders.js +150 -39
  24. package/engine/surgical-diff-application.js +216 -0
  25. package/engine/surgical-mode.js +84 -519
  26. package/engine/surgical-run-splitting.js +96 -0
  27. package/engine/surgical-spans.js +169 -0
  28. package/engine/table-cell-context.js +15 -13
  29. package/engine/table-mode.js +39 -35
  30. package/index.d.ts +172 -0
  31. package/index.js +50 -47
  32. package/package.json +10 -2
  33. package/pipeline/ingestion-export.js +1 -0
  34. package/pipeline/ingestion-paragraph.js +37 -12
  35. package/pipeline/ingestion-table.js +11 -8
  36. package/scripts/build.mjs +40 -0
  37. package/scripts/check-types.mjs +29 -0
  38. package/scripts/export-validation-fixtures.mjs +125 -0
  39. package/scripts/lib/minimal-zip.mjs +155 -0
  40. package/scripts/run-tests.mjs +43 -0
  41. package/scripts/validate-fixtures-xsd.sh +37 -0
  42. package/scripts/word-com-differential.ps1 +133 -0
  43. package/scripts/word-com-smoke.ps1 +48 -0
  44. package/services/comment-locator.js +10 -9
  45. package/services/revision-comment-management.js +115 -1
  46. package/services/standalone-operation-runner.js +119 -69
  47. package/services/table-reconciliation.js +7 -8
@@ -1,16 +1,16 @@
1
- var sa=Object.create;var Pr=Object.defineProperty;var la=Object.getOwnPropertyDescriptor;var ca=Object.getOwnPropertyNames;var ua=Object.getPrototypeOf,fa=Object.prototype.hasOwnProperty;var ma=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var pa=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of ca(t))!fa.call(e,a)&&a!==r&&Pr(e,a,{get:()=>t[a],enumerable:!(n=la(t,a))||n.enumerable});return e};var ga=(e,t,r)=>(r=e!=null?sa(ua(e)):{},pa(t||!e||!e.__esModule?Pr(r,"default",{value:e,enumerable:!0}):r,e));var Dr=ma((Ws,Xe)=>{var y=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32},$=-1,F=1,k=0;y.Diff=function(e,t){return[e,t]};y.prototype.diff_main=function(e,t,r,n){typeof n>"u"&&(this.Diff_Timeout<=0?n=Number.MAX_VALUE:n=new Date().getTime()+this.Diff_Timeout*1e3);var a=n;if(e==null||t==null)throw new Error("Null input. (diff_main)");if(e==t)return e?[new y.Diff(k,e)]:[];typeof r>"u"&&(r=!0);var i=r,o=this.diff_commonPrefix(e,t),s=e.substring(0,o);e=e.substring(o),t=t.substring(o),o=this.diff_commonSuffix(e,t);var l=e.substring(e.length-o);e=e.substring(0,e.length-o),t=t.substring(0,t.length-o);var c=this.diff_compute_(e,t,i,a);return s&&c.unshift(new y.Diff(k,s)),l&&c.push(new y.Diff(k,l)),this.diff_cleanupMerge(c),c};y.prototype.diff_compute_=function(e,t,r,n){var a;if(!e)return[new y.Diff(F,t)];if(!t)return[new y.Diff($,e)];var i=e.length>t.length?e:t,o=e.length>t.length?t:e,s=i.indexOf(o);if(s!=-1)return a=[new y.Diff(F,i.substring(0,s)),new y.Diff(k,o),new y.Diff(F,i.substring(s+o.length))],e.length>t.length&&(a[0][0]=a[2][0]=$),a;if(o.length==1)return[new y.Diff($,e),new y.Diff(F,t)];var l=this.diff_halfMatch_(e,t);if(l){var c=l[0],u=l[1],m=l[2],f=l[3],p=l[4],g=this.diff_main(c,m,r,n),d=this.diff_main(u,f,r,n);return g.concat([new y.Diff(k,p)],d)}return r&&e.length>100&&t.length>100?this.diff_lineMode_(e,t,n):this.diff_bisect_(e,t,n)};y.prototype.diff_lineMode_=function(e,t,r){var n=this.diff_linesToChars_(e,t);e=n.chars1,t=n.chars2;var a=n.lineArray,i=this.diff_main(e,t,!1,r);this.diff_charsToLines_(i,a),this.diff_cleanupSemantic(i),i.push(new y.Diff(k,""));for(var o=0,s=0,l=0,c="",u="";o<i.length;){switch(i[o][0]){case F:l++,u+=i[o][1];break;case $:s++,c+=i[o][1];break;case k:if(s>=1&&l>=1){i.splice(o-s-l,s+l),o=o-s-l;for(var m=this.diff_main(c,u,!1,r),f=m.length-1;f>=0;f--)i.splice(o,0,m[f]);o=o+m.length}l=0,s=0,c="",u="";break}o++}return i.pop(),i};y.prototype.diff_bisect_=function(e,t,r){for(var n=e.length,a=t.length,i=Math.ceil((n+a)/2),o=i,s=2*i,l=new Array(s),c=new Array(s),u=0;u<s;u++)l[u]=-1,c[u]=-1;l[o+1]=0,c[o+1]=0;for(var m=n-a,f=m%2!=0,p=0,g=0,d=0,w=0,h=0;h<i&&!(new Date().getTime()>r);h++){for(var x=-h+p;x<=h-g;x+=2){var v=o+x,T;x==-h||x!=h&&l[v-1]<l[v+1]?T=l[v+1]:T=l[v-1]+1;for(var N=T-x;T<n&&N<a&&e.charAt(T)==t.charAt(N);)T++,N++;if(l[v]=T,T>n)g+=2;else if(N>a)p+=2;else if(f){var E=o+m-x;if(E>=0&&E<s&&c[E]!=-1){var b=n-c[E];if(T>=b)return this.diff_bisectSplit_(e,t,T,N,r)}}}for(var S=-h+d;S<=h-w;S+=2){var E=o+S,b;S==-h||S!=h&&c[E-1]<c[E+1]?b=c[E+1]:b=c[E-1]+1;for(var P=b-S;b<n&&P<a&&e.charAt(n-b-1)==t.charAt(a-P-1);)b++,P++;if(c[E]=b,b>n)w+=2;else if(P>a)d+=2;else if(!f){var v=o+m-S;if(v>=0&&v<s&&l[v]!=-1){var T=l[v],N=o+T-v;if(b=n-b,T>=b)return this.diff_bisectSplit_(e,t,T,N,r)}}}}return[new y.Diff($,e),new y.Diff(F,t)]};y.prototype.diff_bisectSplit_=function(e,t,r,n,a){var i=e.substring(0,r),o=t.substring(0,n),s=e.substring(r),l=t.substring(n),c=this.diff_main(i,o,!1,a),u=this.diff_main(s,l,!1,a);return c.concat(u)};y.prototype.diff_linesToChars_=function(e,t){var r=[],n={};r[0]="";function a(l){for(var c="",u=0,m=-1,f=r.length;m<l.length-1;){m=l.indexOf(`
2
- `,u),m==-1&&(m=l.length-1);var p=l.substring(u,m+1);(n.hasOwnProperty?n.hasOwnProperty(p):n[p]!==void 0)?c+=String.fromCharCode(n[p]):(f==i&&(p=l.substring(u),m=l.length),c+=String.fromCharCode(f),n[p]=f,r[f++]=p),u=m+1}return c}var i=4e4,o=a(e);i=65535;var s=a(t);return{chars1:o,chars2:s,lineArray:r}};y.prototype.diff_charsToLines_=function(e,t){for(var r=0;r<e.length;r++){for(var n=e[r][1],a=[],i=0;i<n.length;i++)a[i]=t[n.charCodeAt(i)];e[r][1]=a.join("")}};y.prototype.diff_commonPrefix=function(e,t){if(!e||!t||e.charAt(0)!=t.charAt(0))return 0;for(var r=0,n=Math.min(e.length,t.length),a=n,i=0;r<a;)e.substring(i,a)==t.substring(i,a)?(r=a,i=r):n=a,a=Math.floor((n-r)/2+r);return a};y.prototype.diff_commonSuffix=function(e,t){if(!e||!t||e.charAt(e.length-1)!=t.charAt(t.length-1))return 0;for(var r=0,n=Math.min(e.length,t.length),a=n,i=0;r<a;)e.substring(e.length-a,e.length-i)==t.substring(t.length-a,t.length-i)?(r=a,i=r):n=a,a=Math.floor((n-r)/2+r);return a};y.prototype.diff_commonOverlap_=function(e,t){var r=e.length,n=t.length;if(r==0||n==0)return 0;r>n?e=e.substring(r-n):r<n&&(t=t.substring(0,r));var a=Math.min(r,n);if(e==t)return a;for(var i=0,o=1;;){var s=e.substring(a-o),l=t.indexOf(s);if(l==-1)return i;o+=l,(l==0||e.substring(a-o)==t.substring(0,o))&&(i=o,o++)}};y.prototype.diff_halfMatch_=function(e,t){if(this.Diff_Timeout<=0)return null;var r=e.length>t.length?e:t,n=e.length>t.length?t:e;if(r.length<4||n.length*2<r.length)return null;var a=this;function i(g,d,w){for(var h=g.substring(w,w+Math.floor(g.length/4)),x=-1,v="",T,N,E,b;(x=d.indexOf(h,x+1))!=-1;){var S=a.diff_commonPrefix(g.substring(w),d.substring(x)),P=a.diff_commonSuffix(g.substring(0,w),d.substring(0,x));v.length<P+S&&(v=d.substring(x-P,x)+d.substring(x,x+S),T=g.substring(0,w-P),N=g.substring(w+S),E=d.substring(0,x-P),b=d.substring(x+S))}return v.length*2>=g.length?[T,N,E,b,v]:null}var o=i(r,n,Math.ceil(r.length/4)),s=i(r,n,Math.ceil(r.length/2)),l;if(!o&&!s)return null;s?o?l=o[4].length>s[4].length?o:s:l=s:l=o;var c,u,m,f;e.length>t.length?(c=l[0],u=l[1],m=l[2],f=l[3]):(m=l[0],f=l[1],c=l[2],u=l[3]);var p=l[4];return[c,u,m,f,p]};y.prototype.diff_cleanupSemantic=function(e){for(var t=!1,r=[],n=0,a=null,i=0,o=0,s=0,l=0,c=0;i<e.length;)e[i][0]==k?(r[n++]=i,o=l,s=c,l=0,c=0,a=e[i][1]):(e[i][0]==F?l+=e[i][1].length:c+=e[i][1].length,a&&a.length<=Math.max(o,s)&&a.length<=Math.max(l,c)&&(e.splice(r[n-1],0,new y.Diff($,a)),e[r[n-1]+1][0]=F,n--,n--,i=n>0?r[n-1]:-1,o=0,s=0,l=0,c=0,a=null,t=!0)),i++;for(t&&this.diff_cleanupMerge(e),this.diff_cleanupSemanticLossless(e),i=1;i<e.length;){if(e[i-1][0]==$&&e[i][0]==F){var u=e[i-1][1],m=e[i][1],f=this.diff_commonOverlap_(u,m),p=this.diff_commonOverlap_(m,u);f>=p?(f>=u.length/2||f>=m.length/2)&&(e.splice(i,0,new y.Diff(k,m.substring(0,f))),e[i-1][1]=u.substring(0,u.length-f),e[i+1][1]=m.substring(f),i++):(p>=u.length/2||p>=m.length/2)&&(e.splice(i,0,new y.Diff(k,u.substring(0,p))),e[i-1][0]=F,e[i-1][1]=m.substring(0,m.length-p),e[i+1][0]=$,e[i+1][1]=u.substring(p),i++),i++}i++}};y.prototype.diff_cleanupSemanticLossless=function(e){function t(p,g){if(!p||!g)return 6;var d=p.charAt(p.length-1),w=g.charAt(0),h=d.match(y.nonAlphaNumericRegex_),x=w.match(y.nonAlphaNumericRegex_),v=h&&d.match(y.whitespaceRegex_),T=x&&w.match(y.whitespaceRegex_),N=v&&d.match(y.linebreakRegex_),E=T&&w.match(y.linebreakRegex_),b=N&&p.match(y.blanklineEndRegex_),S=E&&g.match(y.blanklineStartRegex_);return b||S?5:N||E?4:h&&!v&&T?3:v||T?2:h||x?1:0}for(var r=1;r<e.length-1;){if(e[r-1][0]==k&&e[r+1][0]==k){var n=e[r-1][1],a=e[r][1],i=e[r+1][1],o=this.diff_commonSuffix(n,a);if(o){var s=a.substring(a.length-o);n=n.substring(0,n.length-o),a=s+a.substring(0,a.length-o),i=s+i}for(var l=n,c=a,u=i,m=t(n,a)+t(a,i);a.charAt(0)===i.charAt(0);){n+=a.charAt(0),a=a.substring(1)+i.charAt(0),i=i.substring(1);var f=t(n,a)+t(a,i);f>=m&&(m=f,l=n,c=a,u=i)}e[r-1][1]!=l&&(l?e[r-1][1]=l:(e.splice(r-1,1),r--),e[r][1]=c,u?e[r+1][1]=u:(e.splice(r+1,1),r--))}r++}};y.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/;y.whitespaceRegex_=/\s/;y.linebreakRegex_=/[\r\n]/;y.blanklineEndRegex_=/\n\r?\n$/;y.blanklineStartRegex_=/^\r?\n\r?\n/;y.prototype.diff_cleanupEfficiency=function(e){for(var t=!1,r=[],n=0,a=null,i=0,o=!1,s=!1,l=!1,c=!1;i<e.length;)e[i][0]==k?(e[i][1].length<this.Diff_EditCost&&(l||c)?(r[n++]=i,o=l,s=c,a=e[i][1]):(n=0,a=null),l=c=!1):(e[i][0]==$?c=!0:l=!0,a&&(o&&s&&l&&c||a.length<this.Diff_EditCost/2&&o+s+l+c==3)&&(e.splice(r[n-1],0,new y.Diff($,a)),e[r[n-1]+1][0]=F,n--,a=null,o&&s?(l=c=!0,n=0):(n--,i=n>0?r[n-1]:-1,l=c=!1),t=!0)),i++;t&&this.diff_cleanupMerge(e)};y.prototype.diff_cleanupMerge=function(e){e.push(new y.Diff(k,""));for(var t=0,r=0,n=0,a="",i="",o;t<e.length;)switch(e[t][0]){case F:n++,i+=e[t][1],t++;break;case $:r++,a+=e[t][1],t++;break;case k:r+n>1?(r!==0&&n!==0&&(o=this.diff_commonPrefix(i,a),o!==0&&(t-r-n>0&&e[t-r-n-1][0]==k?e[t-r-n-1][1]+=i.substring(0,o):(e.splice(0,0,new y.Diff(k,i.substring(0,o))),t++),i=i.substring(o),a=a.substring(o)),o=this.diff_commonSuffix(i,a),o!==0&&(e[t][1]=i.substring(i.length-o)+e[t][1],i=i.substring(0,i.length-o),a=a.substring(0,a.length-o))),t-=r+n,e.splice(t,r+n),a.length&&(e.splice(t,0,new y.Diff($,a)),t++),i.length&&(e.splice(t,0,new y.Diff(F,i)),t++),t++):t!==0&&e[t-1][0]==k?(e[t-1][1]+=e[t][1],e.splice(t,1)):t++,n=0,r=0,a="",i="";break}e[e.length-1][1]===""&&e.pop();var s=!1;for(t=1;t<e.length-1;)e[t-1][0]==k&&e[t+1][0]==k&&(e[t][1].substring(e[t][1].length-e[t-1][1].length)==e[t-1][1]?(e[t][1]=e[t-1][1]+e[t][1].substring(0,e[t][1].length-e[t-1][1].length),e[t+1][1]=e[t-1][1]+e[t+1][1],e.splice(t-1,1),s=!0):e[t][1].substring(0,e[t+1][1].length)==e[t+1][1]&&(e[t-1][1]+=e[t+1][1],e[t][1]=e[t][1].substring(e[t+1][1].length)+e[t+1][1],e.splice(t+1,1),s=!0)),t++;s&&this.diff_cleanupMerge(e)};y.prototype.diff_xIndex=function(e,t){var r=0,n=0,a=0,i=0,o;for(o=0;o<e.length&&(e[o][0]!==F&&(r+=e[o][1].length),e[o][0]!==$&&(n+=e[o][1].length),!(r>t));o++)a=r,i=n;return e.length!=o&&e[o][0]===$?i:i+(t-a)};y.prototype.diff_prettyHtml=function(e){for(var t=[],r=/&/g,n=/</g,a=/>/g,i=/\n/g,o=0;o<e.length;o++){var s=e[o][0],l=e[o][1],c=l.replace(r,"&amp;").replace(n,"&lt;").replace(a,"&gt;").replace(i,"&para;<br>");switch(s){case F:t[o]='<ins style="background:#e6ffe6;">'+c+"</ins>";break;case $:t[o]='<del style="background:#ffe6e6;">'+c+"</del>";break;case k:t[o]="<span>"+c+"</span>";break}}return t.join("")};y.prototype.diff_text1=function(e){for(var t=[],r=0;r<e.length;r++)e[r][0]!==F&&(t[r]=e[r][1]);return t.join("")};y.prototype.diff_text2=function(e){for(var t=[],r=0;r<e.length;r++)e[r][0]!==$&&(t[r]=e[r][1]);return t.join("")};y.prototype.diff_levenshtein=function(e){for(var t=0,r=0,n=0,a=0;a<e.length;a++){var i=e[a][0],o=e[a][1];switch(i){case F:r+=o.length;break;case $:n+=o.length;break;case k:t+=Math.max(r,n),r=0,n=0;break}}return t+=Math.max(r,n),t};y.prototype.diff_toDelta=function(e){for(var t=[],r=0;r<e.length;r++)switch(e[r][0]){case F:t[r]="+"+encodeURI(e[r][1]);break;case $:t[r]="-"+e[r][1].length;break;case k:t[r]="="+e[r][1].length;break}return t.join(" ").replace(/%20/g," ")};y.prototype.diff_fromDelta=function(e,t){for(var r=[],n=0,a=0,i=t.split(/\t/g),o=0;o<i.length;o++){var s=i[o].substring(1);switch(i[o].charAt(0)){case"+":try{r[n++]=new y.Diff(F,decodeURI(s))}catch{throw new Error("Illegal escape in diff_fromDelta: "+s)}break;case"-":case"=":var l=parseInt(s,10);if(isNaN(l)||l<0)throw new Error("Invalid number in diff_fromDelta: "+s);var c=e.substring(a,a+=l);i[o].charAt(0)=="="?r[n++]=new y.Diff(k,c):r[n++]=new y.Diff($,c);break;default:if(i[o])throw new Error("Invalid diff operation in diff_fromDelta: "+i[o])}}if(a!=e.length)throw new Error("Delta length ("+a+") does not equal source text length ("+e.length+").");return r};y.prototype.match_main=function(e,t,r){if(e==null||t==null||r==null)throw new Error("Null input. (match_main)");return r=Math.max(0,Math.min(r,e.length)),e==t?0:e.length?e.substring(r,r+t.length)==t?r:this.match_bitap_(e,t,r):-1};y.prototype.match_bitap_=function(e,t,r){if(t.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var n=this.match_alphabet_(t),a=this;function i(T,N){var E=T/t.length,b=Math.abs(r-N);return a.Match_Distance?E+b/a.Match_Distance:b?1:E}var o=this.Match_Threshold,s=e.indexOf(t,r);s!=-1&&(o=Math.min(i(0,s),o),s=e.lastIndexOf(t,r+t.length),s!=-1&&(o=Math.min(i(0,s),o)));var l=1<<t.length-1;s=-1;for(var c,u,m=t.length+e.length,f,p=0;p<t.length;p++){for(c=0,u=m;c<u;)i(p,r+u)<=o?c=u:m=u,u=Math.floor((m-c)/2+c);m=u;var g=Math.max(1,r-u+1),d=Math.min(r+u,e.length)+t.length,w=Array(d+2);w[d+1]=(1<<p)-1;for(var h=d;h>=g;h--){var x=n[e.charAt(h-1)];if(p===0?w[h]=(w[h+1]<<1|1)&x:w[h]=(w[h+1]<<1|1)&x|((f[h+1]|f[h])<<1|1)|f[h+1],w[h]&l){var v=i(p,h-1);if(v<=o)if(o=v,s=h-1,s>r)g=Math.max(1,2*r-s);else break}}if(i(p+1,r)>o)break;f=w}return s};y.prototype.match_alphabet_=function(e){for(var t={},r=0;r<e.length;r++)t[e.charAt(r)]=0;for(var r=0;r<e.length;r++)t[e.charAt(r)]|=1<<e.length-r-1;return t};y.prototype.patch_addContext_=function(e,t){if(t.length!=0){if(e.start2===null)throw Error("patch not initialized");for(var r=t.substring(e.start2,e.start2+e.length1),n=0;t.indexOf(r)!=t.lastIndexOf(r)&&r.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)n+=this.Patch_Margin,r=t.substring(e.start2-n,e.start2+e.length1+n);n+=this.Patch_Margin;var a=t.substring(e.start2-n,e.start2);a&&e.diffs.unshift(new y.Diff(k,a));var i=t.substring(e.start2+e.length1,e.start2+e.length1+n);i&&e.diffs.push(new y.Diff(k,i)),e.start1-=a.length,e.start2-=a.length,e.length1+=a.length+i.length,e.length2+=a.length+i.length}};y.prototype.patch_make=function(e,t,r){var n,a;if(typeof e=="string"&&typeof t=="string"&&typeof r>"u")n=e,a=this.diff_main(n,t,!0),a.length>2&&(this.diff_cleanupSemantic(a),this.diff_cleanupEfficiency(a));else if(e&&typeof e=="object"&&typeof t>"u"&&typeof r>"u")a=e,n=this.diff_text1(a);else if(typeof e=="string"&&t&&typeof t=="object"&&typeof r>"u")n=e,a=t;else if(typeof e=="string"&&typeof t=="string"&&r&&typeof r=="object")n=e,a=r;else throw new Error("Unknown call format to patch_make.");if(a.length===0)return[];for(var i=[],o=new y.patch_obj,s=0,l=0,c=0,u=n,m=n,f=0;f<a.length;f++){var p=a[f][0],g=a[f][1];switch(!s&&p!==k&&(o.start1=l,o.start2=c),p){case F:o.diffs[s++]=a[f],o.length2+=g.length,m=m.substring(0,c)+g+m.substring(c);break;case $:o.length1+=g.length,o.diffs[s++]=a[f],m=m.substring(0,c)+m.substring(c+g.length);break;case k:g.length<=2*this.Patch_Margin&&s&&a.length!=f+1?(o.diffs[s++]=a[f],o.length1+=g.length,o.length2+=g.length):g.length>=2*this.Patch_Margin&&s&&(this.patch_addContext_(o,u),i.push(o),o=new y.patch_obj,s=0,u=m,l=c);break}p!==F&&(l+=g.length),p!==$&&(c+=g.length)}return s&&(this.patch_addContext_(o,u),i.push(o)),i};y.prototype.patch_deepCopy=function(e){for(var t=[],r=0;r<e.length;r++){var n=e[r],a=new y.patch_obj;a.diffs=[];for(var i=0;i<n.diffs.length;i++)a.diffs[i]=new y.Diff(n.diffs[i][0],n.diffs[i][1]);a.start1=n.start1,a.start2=n.start2,a.length1=n.length1,a.length2=n.length2,t[r]=a}return t};y.prototype.patch_apply=function(e,t){if(e.length==0)return[t,[]];e=this.patch_deepCopy(e);var r=this.patch_addPadding(e);t=r+t+r,this.patch_splitMax(e);for(var n=0,a=[],i=0;i<e.length;i++){var o=e[i].start2+n,s=this.diff_text1(e[i].diffs),l,c=-1;if(s.length>this.Match_MaxBits?(l=this.match_main(t,s.substring(0,this.Match_MaxBits),o),l!=-1&&(c=this.match_main(t,s.substring(s.length-this.Match_MaxBits),o+s.length-this.Match_MaxBits),(c==-1||l>=c)&&(l=-1))):l=this.match_main(t,s,o),l==-1)a[i]=!1,n-=e[i].length2-e[i].length1;else{a[i]=!0,n=l-o;var u;if(c==-1?u=t.substring(l,l+s.length):u=t.substring(l,c+this.Match_MaxBits),s==u)t=t.substring(0,l)+this.diff_text2(e[i].diffs)+t.substring(l+s.length);else{var m=this.diff_main(s,u,!1);if(s.length>this.Match_MaxBits&&this.diff_levenshtein(m)/s.length>this.Patch_DeleteThreshold)a[i]=!1;else{this.diff_cleanupSemanticLossless(m);for(var f=0,p,g=0;g<e[i].diffs.length;g++){var d=e[i].diffs[g];d[0]!==k&&(p=this.diff_xIndex(m,f)),d[0]===F?t=t.substring(0,l+p)+d[1]+t.substring(l+p):d[0]===$&&(t=t.substring(0,l+p)+t.substring(l+this.diff_xIndex(m,f+d[1].length))),d[0]!==$&&(f+=d[1].length)}}}}}return t=t.substring(r.length,t.length-r.length),[t,a]};y.prototype.patch_addPadding=function(e){for(var t=this.Patch_Margin,r="",n=1;n<=t;n++)r+=String.fromCharCode(n);for(var n=0;n<e.length;n++)e[n].start1+=t,e[n].start2+=t;var a=e[0],i=a.diffs;if(i.length==0||i[0][0]!=k)i.unshift(new y.Diff(k,r)),a.start1-=t,a.start2-=t,a.length1+=t,a.length2+=t;else if(t>i[0][1].length){var o=t-i[0][1].length;i[0][1]=r.substring(i[0][1].length)+i[0][1],a.start1-=o,a.start2-=o,a.length1+=o,a.length2+=o}if(a=e[e.length-1],i=a.diffs,i.length==0||i[i.length-1][0]!=k)i.push(new y.Diff(k,r)),a.length1+=t,a.length2+=t;else if(t>i[i.length-1][1].length){var o=t-i[i.length-1][1].length;i[i.length-1][1]+=r.substring(0,o),a.length1+=o,a.length2+=o}return r};y.prototype.patch_splitMax=function(e){for(var t=this.Match_MaxBits,r=0;r<e.length;r++)if(!(e[r].length1<=t)){var n=e[r];e.splice(r--,1);for(var a=n.start1,i=n.start2,o="";n.diffs.length!==0;){var s=new y.patch_obj,l=!0;for(s.start1=a-o.length,s.start2=i-o.length,o!==""&&(s.length1=s.length2=o.length,s.diffs.push(new y.Diff(k,o)));n.diffs.length!==0&&s.length1<t-this.Patch_Margin;){var c=n.diffs[0][0],u=n.diffs[0][1];c===F?(s.length2+=u.length,i+=u.length,s.diffs.push(n.diffs.shift()),l=!1):c===$&&s.diffs.length==1&&s.diffs[0][0]==k&&u.length>2*t?(s.length1+=u.length,a+=u.length,l=!1,s.diffs.push(new y.Diff(c,u)),n.diffs.shift()):(u=u.substring(0,t-s.length1-this.Patch_Margin),s.length1+=u.length,a+=u.length,c===k?(s.length2+=u.length,i+=u.length):l=!1,s.diffs.push(new y.Diff(c,u)),u==n.diffs[0][1]?n.diffs.shift():n.diffs[0][1]=n.diffs[0][1].substring(u.length))}o=this.diff_text2(s.diffs),o=o.substring(o.length-this.Patch_Margin);var m=this.diff_text1(n.diffs).substring(0,this.Patch_Margin);m!==""&&(s.length1+=m.length,s.length2+=m.length,s.diffs.length!==0&&s.diffs[s.diffs.length-1][0]===k?s.diffs[s.diffs.length-1][1]+=m:s.diffs.push(new y.Diff(k,m))),l||e.splice(++r,0,s)}}};y.prototype.patch_toText=function(e){for(var t=[],r=0;r<e.length;r++)t[r]=e[r];return t.join("")};y.prototype.patch_fromText=function(e){var t=[];if(!e)return t;for(var r=e.split(`
3
- `),n=0,a=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;n<r.length;){var i=r[n].match(a);if(!i)throw new Error("Invalid patch string: "+r[n]);var o=new y.patch_obj;for(t.push(o),o.start1=parseInt(i[1],10),i[2]===""?(o.start1--,o.length1=1):i[2]=="0"?o.length1=0:(o.start1--,o.length1=parseInt(i[2],10)),o.start2=parseInt(i[3],10),i[4]===""?(o.start2--,o.length2=1):i[4]=="0"?o.length2=0:(o.start2--,o.length2=parseInt(i[4],10)),n++;n<r.length;){var s=r[n].charAt(0);try{var l=decodeURI(r[n].substring(1))}catch{throw new Error("Illegal escape in patch_fromText: "+l)}if(s=="-")o.diffs.push(new y.Diff($,l));else if(s=="+")o.diffs.push(new y.Diff(F,l));else if(s==" ")o.diffs.push(new y.Diff(k,l));else{if(s=="@")break;if(s!=="")throw new Error('Invalid patch mode "'+s+'" in: '+l)}n++}}return t};y.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0};y.patch_obj.prototype.toString=function(){var e,t;this.length1===0?e=this.start1+",0":this.length1==1?e=this.start1+1:e=this.start1+1+","+this.length1,this.length2===0?t=this.start2+",0":this.length2==1?t=this.start2+1:t=this.start2+1+","+this.length2;for(var r=["@@ -"+e+" +"+t+` @@
4
- `],n,a=0;a<this.diffs.length;a++){switch(this.diffs[a][0]){case F:n="+";break;case $:n="-";break;case k:n=" ";break}r[a+1]=n+encodeURI(this.diffs[a][1])+`
5
- `}return r.join("").replace(/%20/g," ")};Xe.exports=y;Xe.exports.diff_match_patch=y;Xe.exports.DIFF_DELETE=$;Xe.exports.DIFF_INSERT=F;Xe.exports.DIFF_EQUAL=k});var Ye=globalThis.DOMParser,Je=globalThis.XMLSerializer;function da(e={}){e.DOMParser&&(Ye=e.DOMParser),e.XMLSerializer&&(Je=e.XMLSerializer)}function _(){if(!Ye&&globalThis.DOMParser&&(Ye=globalThis.DOMParser),!Ye)throw new Error("DOMParser is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new Ye}function Z(){if(!Je&&globalThis.XMLSerializer&&(Je=globalThis.XMLSerializer),!Je)throw new Error("XMLSerializer is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new Je}function Sr(e,t="text/xml"){return _().parseFromString(e,t)}function j(e){return Z().serializeToString(e)}var dt=console,Ft=Object.freeze({silent:0,error:1,warn:2,info:3}),ha=typeof process<"u"&&process?.env?.NODE_ENV==="production"?"warn":"info",Xt=ha;function wa(e){let t=String(e||"").toLowerCase();return Object.prototype.hasOwnProperty.call(Ft,t)?t:Xt}function Dt(e){return Ft[Xt]>=Ft[e]}function ba(e,t={}){dt=e||console,t.level&&(Xt=wa(t.level))}function C(...e){Dt("info")&&(dt.log||(()=>{}))(...e)}function Ce(...e){Dt("warn")&&(dt.warn||(()=>{}))(...e)}function V(...e){Dt("error")&&(dt.error||(()=>{}))(...e)}var Ir="Author",Cr="Unknown";function xa(e){Ir=typeof e=="string"&&e.trim()?e.trim():"Author"}function G(){return Ir}function Na(e){Cr=typeof e=="string"&&e.trim()?e.trim():"Unknown"}function zt(){return Cr}var va=[{regex:/<b>(.+?)<\/b>/i,format:{bold:!0}},{regex:/<strong>(.+?)<\/strong>/i,format:{bold:!0}},{regex:/<i>(.+?)<\/i>/i,format:{italic:!0}},{regex:/<em>(.+?)<\/em>/i,format:{italic:!0}},{regex:/<u>(.+?)<\/u>/i,format:{underline:!0}},{regex:/<s>(.+?)<\/s>/i,format:{strikethrough:!0}},{regex:/<strike>(.+?)<\/strike>/i,format:{strikethrough:!0}},{regex:/<del>(.+?)<\/del>/i,format:{strikethrough:!0}},{regex:/&lt;b&gt;(.+?)&lt;\/b&gt;/i,format:{bold:!0},isEscaped:!0},{regex:/&lt;strong&gt;(.+?)&lt;\/strong&gt;/i,format:{bold:!0},isEscaped:!0},{regex:/&lt;i&gt;(.+?)&lt;\/i&gt;/i,format:{italic:!0},isEscaped:!0},{regex:/&lt;em&gt;(.+?)&lt;\/em&gt;/i,format:{italic:!0},isEscaped:!0},{regex:/&lt;u&gt;(.+?)&lt;\/u&gt;/i,format:{underline:!0},isEscaped:!0},{regex:/&lt;s&gt;(.+?)&lt;\/s&gt;/i,format:{strikethrough:!0},isEscaped:!0},{regex:/\*\*\*(.+?)\*\*\*/,format:{bold:!0,italic:!0}},{regex:/\*\*\+\+(.+?)\+\+\*\*/,format:{bold:!0,underline:!0}},{regex:/\*\*(.+?)\*\*/,format:{bold:!0}},{regex:/__(.+?)__/,format:{bold:!0}},{regex:/\+\+(.+?)\+\+/,format:{underline:!0}},{regex:/~~(.+?)~~/,format:{strikethrough:!0}},{regex:/~(.+?)~/,format:{strikethrough:!0}},{regex:/\*(?!\*)(.+?)\*(?!\*)/,format:{italic:!0}},{regex:/_(?!_)(.+?)_(?!_)/,format:{italic:!0}}];function q(e){if(!e)return{cleanText:"",formatHints:[]};let t=[],r="",n=[];for(let s of va){let l,c=s.regex.source||s.regex.toString().replace(/^\/|\/[gimuy]*$/g,""),u="g"+(s.regex.ignoreCase?"i":""),m=new RegExp(c,u);for(;(l=m.exec(e))!==null;)n.push({start:l.index,end:l.index+l[0].length,fullMatch:l[0],innerText:s.isEscaped?Ta(l[1]):l[1],format:s.format}),l.index===m.lastIndex&&m.lastIndex++}n.sort((s,l)=>s.start-l.start||l.end-s.end);let a=[],i=0;for(let s of n)s.start>=i&&(a.push(s),i=s.end);let o=0;for(let s of a){r+=e.slice(o,s.start);let l=q(s.innerText),c=r.length;r+=l.cleanText;let u=r.length;t.push({start:c,end:u,format:s.format});for(let m of l.formatHints)t.push({start:c+m.start,end:c+m.end,format:m.format});o=s.end}return r+=e.slice(o),{cleanText:r,formatHints:t}}function be(e,t,r){return e.filter(n=>n.start<r&&n.end>t)}function Wt(...e){let t={};for(let r of e)r&&Object.assign(t,r);return t}function Ta(e){return e?e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#039;/g,"'"):""}var ht=String.raw`(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|\d+\.|[ivxlcIVXLC]+\.|[-*\u2022])`,Ar=new RegExp(`^(\\s*)((?:${ht})\\s+)`),Rr=new RegExp(`^(\\s*)((?:${ht})\\s*)`),ya=new RegExp(`^(\\s*)((?:${ht})\\s+)`,"m"),Ea=new RegExp(`^(\\s*)((?:${ht})\\s*)`,"m");function kr(e){return typeof e!="string"?!1:e.includes(`
6
- `)&&ya.test(e)}function wt(e){return typeof e!="string"?!1:e.includes(`
7
- `)&&Ea.test(e.trim())}function fe(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?Rr:Ar;return e.match(n)}function xe(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?Rr:Ar;return e.replace(n,"")}var I="http://schemas.openxmlformats.org/wordprocessingml/2006/main";var re=Object.freeze({EQUAL:"equal",DELETE:"delete",INSERT:"insert"}),R=Object.freeze({TEXT:"run",DELETION:"deletion",INSERTION:"insertion",HYPERLINK:"hyperlink",BOOKMARK:"bookmark",FIELD:"field",CONTAINER_START:"container_start",CONTAINER_END:"container_end",PARAGRAPH_START:"paragraph_start"}),$e=Object.freeze({SDT:"sdt",SMART_TAG:"smartTag",CUSTOM_XML:"customXml",FIELD_COMPLEX:"fldComplex"}),Or=Object.freeze({PARAGRAPH:"paragraph",BULLET_LIST:"bullet_list",NUMBERED_LIST:"numbered_list",TABLE:"table"}),B=Object.freeze({DECIMAL:"decimal",LOWER_ALPHA:"lowerLetter",UPPER_ALPHA:"upperLetter",LOWER_ROMAN:"lowerRoman",UPPER_ROMAN:"upperRoman",BULLET:"bullet",OUTLINE:"outline"}),K=Object.freeze({PERIOD:"period",PAREN_RIGHT:"parenRight",PAREN_BOTH:"parenBoth",NONE:"none"});function ee(e){return e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;"):""}var Pa=1e3;function Ne(){return Pa++}function ie(e=new Date){return e.toISOString()}function me(e){let t=typeof e=="string"&&e.trim()?e.trim():G();return{id:Ne(),author:t,date:ie()}}var Mr=`
8
- `,Sa=Mr.length;function Lr(e,t){return e<t-1}function Fe(e,t,r){return Lr(t,r)?e+Mr:e}function Ae(e,t,r){return Lr(t,r)?e+Sa:e}function J(e,t){return!e||typeof e.getElementsByTagName!="function"?[]:Array.from(e.getElementsByTagName(t))}function M(e,t){if(!e||typeof e.getElementsByTagName!="function")return null;let r=e.getElementsByTagName(t);return r.length>0?r[0]:null}function z(e,t,r){return!e||typeof e.getElementsByTagNameNS!="function"?[]:Array.from(e.getElementsByTagNameNS(t,r))}function D(e,t,r){if(!e||typeof e.getElementsByTagNameNS!="function")return null;let n=e.getElementsByTagNameNS(t,r);return n.length>0?n[0]:null}function _r(e,t,r,n=`w:${r}`){let a=z(e,t,r);return a.length>0?a:J(e,n)}function Br(e,t,r,n=`w:${r}`){let a=D(e,t,r);return a||M(e,n)}function H(e){return M(e,"parsererror")}function Ht(e){return Array.from(e?.childNodes||[])}function $r(e){return Array.from(e.attributes).map(t=>`${t.name}="${t.value}"`).join(" ")}function Ut(e,t,r=""){return!e||e.namespaceURI!==t?!1:r?e.localName===r:!0}var jt=0;function bt(e,t={}){let r=[],n="",a=t.xmlDoc||null;if(!e&&!a)return{runModel:r,acceptedText:n,pPr:null};try{let i=a||_().parseFromString(e,"application/xml"),o=H(i);if(o)return V("OOXML parse error:",o.textContent),{runModel:r,acceptedText:n,pPr:null};let s=z(i,I,"p");return s.length===0?(Ce("No paragraphs found in OOXML"),{runModel:r,acceptedText:n,pPr:null}):Fr(s,{includeParagraphBoundaries:!0})}catch(i){return V("Error ingesting OOXML:",i),{runModel:r,acceptedText:n,pPr:null}}}function Gt(e){return e?Fr([e],{includeParagraphBoundaries:!1}):{runModel:[],acceptedText:"",pPr:null}}function Vt(e){let t=D(e,I,"pPr");if(!t)return null;let r=D(t,I,"numPr");if(!r)return null;let n=D(r,I,"numId"),a=D(r,I,"ilvl");if(!n)return null;let i=n.getAttribute("w:val"),o=i==="1"?"bullet":i==="2"?"numbered":"unknown";return{numId:i,ilvl:parseInt(a?.getAttribute("w:val")||"0",10),type:o}}function Fr(e,t={}){let r=t.includeParagraphBoundaries??!0,n=[],a="",i=0,o=null;for(let s=0;s<e.length;s++){let l=e[s],c=D(l,I,"pPr");s===0&&(o=c),n.push({kind:R.PARAGRAPH_START,pPrElement:c||null,startOffset:i,endOffset:i,text:""});let u=qe(l,i,n);a+=u.text,i=a.length,r&&(a=Fe(a,s,e.length),i=Ae(i,s,e.length))}return{runModel:n,acceptedText:a,pPr:o}}function qe(e,t,r){let n=t,a="",i=Ia(r);for(let o of Ht(e)){if(Ut(o,I,"pPr")||Ut(o,I,"proofErr"))continue;let s=i.get(o.localName);if(!s)continue;let l=s(o,n);n=l.offset,a+=l.text}return{offset:n,text:a}}function Ia(e){let t=new Map;return t.set("sdt",(r,n)=>{let a=`sdt_${jt++}`,i=D(r,I,"sdtPr"),o=D(r,I,"sdtContent");e.push({kind:R.CONTAINER_START,containerKind:$e.SDT,containerId:a,propertiesXml:i?j(i):"",startOffset:n,endOffset:n,text:""});let s=o?qe(o,n,e):{offset:n,text:""};return e.push({kind:R.CONTAINER_END,containerKind:$e.SDT,containerId:a,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("smartTag",(r,n)=>{let a=`smartTag_${jt++}`;e.push({kind:R.CONTAINER_START,containerKind:$e.SMART_TAG,containerId:a,propertiesXml:$r(r),startOffset:n,endOffset:n,text:""});let i=qe(r,n,e);return e.push({kind:R.CONTAINER_END,containerKind:$e.SMART_TAG,containerId:a,startOffset:i.offset,endOffset:i.offset,text:""}),i}),t.set("del",(r,n)=>{let a=Aa(r,n);return a&&e.push(a),{offset:n,text:""}}),t.set("bookmarkStart",(r,n)=>(e.push({kind:R.BOOKMARK,nodeXml:j(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("bookmarkEnd",(r,n)=>(e.push({kind:R.BOOKMARK,nodeXml:j(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("ins",(r,n)=>qe(r,n,e)),t.set("hyperlink",(r,n)=>{let a=`hyperlink_${jt++}`,i=r.getAttribute("r:id")||"",o=r.getAttribute("w:anchor")||"";e.push({kind:R.CONTAINER_START,containerKind:"hyperlink",containerId:a,propertiesXml:JSON.stringify({rId:i,anchor:o}),startOffset:n,endOffset:n,text:""});let s=qe(r,n,e);return e.push({kind:R.CONTAINER_END,containerKind:"hyperlink",containerId:a,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("r",(r,n)=>{let a=Ca(r,n);return!a||!a.text?{offset:n,text:""}:(e.push(a),{offset:n+a.text.length,text:a.text})}),t}function Ca(e,t){let r=Br(e,I,"rPr"),n=r?j(r):"",a="";for(let i of Ht(e)){let o=i.nodeName;o.endsWith(":t")||o==="t"?a+=i.textContent||"":o.endsWith(":br")||o==="br"||o.endsWith(":cr")||o==="cr"?a+=`
9
- `:o.endsWith(":tab")||o==="tab"?a+=" ":(o.endsWith(":noBreakHyphen")||o==="noBreakHyphen")&&(a+="\u2011")}return a?{kind:R.TEXT,text:a,rPrXml:n,startOffset:t,endOffset:t+a.length}:null}function Aa(e,t){let r=e.getAttribute("w:author")||"",n="",a=z(e,I,"delText");for(let o of a)n+=o.textContent||"";let i=z(e,I,"r");for(let o of i){let s=z(o,I,"delText");for(let l of s)n+=l.textContent||""}return n?{kind:R.DELETION,text:n,rPrXml:"",startOffset:t,endOffset:t,author:r,nodeXml:j(e)}:null}function Zt(e){let t=D(e,I,"tblGrid"),n=(t?z(t,I,"gridCol"):[]).length,a=z(e,I,"tr"),i=a.length,o=Array.from({length:i},()=>Array.from({length:n},()=>null)),s=new Map,l=new Map;for(let c=0;c<a.length;c++){let u=a[c],m=z(u,I,"tc"),f=0;for(let p=0;p<m.length;p++){let g=m[p],d=D(g,I,"tcPr");for(;f<n&&o[c][f]!==null;)f++;if(f>=n)break;let w=d?D(d,I,"gridSpan")||M(d,"w:gridSpan"):null,h=parseInt(w?.getAttribute("w:val")||"1",10),x=d?D(d,I,"vMerge")||M(d,"w:vMerge"):null,v=x?.getAttribute("w:val"),T=x!==null,N;if(T&&v!=="restart"){let E=l.get(f);E?(E.cell.rowSpan++,N={gridRow:c,gridCol:f,rowSpan:0,colSpan:h,tcNode:g,blocks:[],tcPrXml:Kt(d),isMergeOrigin:!1,isMergeContinuation:!0,mergeOrigin:E.cell}):N=Ra(c,f,h,g,d)}else{let E=Xr(g);if(N={gridRow:c,gridCol:f,rowSpan:1,colSpan:h,tcNode:g,blocks:E,tcPrXml:Kt(d),isMergeOrigin:T&&v==="restart",isMergeContinuation:!1,getText:()=>E.map(b=>b.acceptedText).join(`
10
- `)},T&&v==="restart")for(let b=0;b<h;b++)l.set(f+b,{originRow:c,cell:N});else for(let b=0;b<h;b++)l.delete(f+b)}for(let E=0;E<h;E++){let b=f+E;b<n&&(o[c][b]=N,s.set(`${c},${b}`,N))}f+=h}}return{rowCount:i,colCount:n,grid:o,cellMap:s,tblPrXml:ka(e),tblGridXml:Oa(e),trPrList:Array.from(a).map(c=>Ma(c))}}function Ra(e,t,r,n,a){let i=Xr(n);return{gridRow:e,gridCol:t,rowSpan:1,colSpan:r,tcNode:n,blocks:i,tcPrXml:Kt(a),isMergeOrigin:!1,isMergeContinuation:!1,getText:()=>i.map(o=>o.acceptedText).join(`
11
- `)}}function Xr(e){return _r(e,I,"p").map(r=>{let{runModel:n,acceptedText:a,pPr:i}=Gt(r);return{runModel:n,acceptedText:a,pPr:i}})}function Kt(e){return e?j(e):"<w:tcPr/>"}function ka(e){let t=D(e,I,"tblPr");return t?j(t):"<w:tblPr/>"}function Oa(e){let t=D(e,I,"tblGrid");return t?j(t):"<w:tblGrid/>"}function Ma(e){let t=D(e,I,"trPr");return t?j(t):"<w:trPr/>"}var Wr=ga(Dr(),1);var zr=new Wr.diff_match_patch;function La(e,t){let r=[],n=new Map;function a(l){let c=[],u=/(\S+)(\s*)/g,m;for(;(m=u.exec(l))!==null;)m[1]&&c.push(m[1]),m[2]&&c.push(m[2]);return c}function i(l){let c="";for(let u of l)if(n.has(u))c+=String.fromCharCode(n.get(u));else{let m=r.length;r.push(u),n.set(u,m),c+=String.fromCharCode(m)}return c}let o=a(e),s=a(t);return{chars1:i(o),chars2:i(s),wordArray:r}}function _a(e,t){let r=[];for(let[n,a]of e){let i=[];for(let o=0;o<a.length;o++){let s=a.charCodeAt(o);s<t.length&&i.push(t[s])}r.push([n,i.join("")])}return r}function Qe(e,t,r={}){if(e===t)return[[0,e]];if(!e)return[[1,t]];if(!t)return[[-1,e]];let{cleanupSemantic:n=!0}=r,{chars1:a,chars2:i,wordArray:o}=La(e,t),s=zr.diff_main(a,i);return n&&zr.diff_cleanupSemantic(s),_a(s,o)}function xt(e,t,r={}){if(e===t)return[{type:re.EQUAL,startOffset:0,endOffset:e.length,text:e}];if(!e)return[{type:re.INSERT,startOffset:0,endOffset:0,text:t}];if(!t)return[{type:re.DELETE,startOffset:0,endOffset:e.length,text:e}];let n=Qe(e,t,r),a=[],i=0;for(let[o,s]of n)o===0?(a.push({type:re.EQUAL,startOffset:i,endOffset:i+s.length,text:s}),i+=s.length):o===-1?(a.push({type:re.DELETE,startOffset:i,endOffset:i+s.length,text:s}),i+=s.length):o===1&&a.push({type:re.INSERT,startOffset:i,endOffset:i,text:s});return a}var Ba=/\s+xmlns:[^=]+="[^"]*"/g;function Nt(e,t){let r=Wa(t),n=[],a=0;for(let i of e){if(i.kind!==R.TEXT&&i.kind!==R.HYPERLINK){n.push(i);continue}for(;a<r.length&&r[a]<=i.startOffset;)a++;let o=a,s=i.startOffset,l=!1;for(;o<r.length;){let c=r[o];if(c>=i.endOffset)break;c>s&&(l=!0,n.push({...i,text:i.text.slice(s-i.startOffset,c-i.startOffset),startOffset:s,endOffset:c}),s=c),o++}if(a=o,!l){n.push(i);continue}n.push({...i,text:i.text.slice(s-i.startOffset),startOffset:s,endOffset:i.endOffset})}return n}function vt(e,t,r){let{generateRedlines:n,author:a}=r,i=[],o=new Set,s=Ha(t),l=Da(e),c=za(s.nonInsertOps),u={containerStack:[],lastParagraphStartIndex:-1,currentParagraphPPrXml:"",currentParagraphPPrElement:null};for(let f of e){if(f.kind===R.CONTAINER_START){u.containerStack.push(f.containerId),i.push({...f});continue}if(f.kind===R.CONTAINER_END){u.containerStack.pop(),i.push({...f});continue}if(f.kind===R.PARAGRAPH_START){u.currentParagraphPPrXml=typeof f.pPrXml=="string"?f.pPrXml:"",u.currentParagraphPPrElement=f.pPrElement||null,i.push({...f}),u.lastParagraphStartIndex=i.length-1;continue}if(f.kind===R.BOOKMARK||f.kind===R.DELETION){i.push({...f});continue}let p=c(f.startOffset,f.endOffset),g=s.insertOpsByStartOffset.get(f.startOffset)||[];for(let d of g)o.has(d)||(o.add(d),$a({insertOp:d,splitModel:e,styleLookup:l,patchedModel:i,state:u,options:r,generateRedlines:n,author:a}));if(!p||p.type===re.EQUAL){i.push({...f,containerContext:u.containerStack.length>0?u.containerStack[u.containerStack.length-1]:null});continue}p.type===re.DELETE&&n&&i.push({...f,kind:R.DELETION,author:a,containerContext:u.containerStack.length>0?u.containerStack[u.containerStack.length-1]:null})}let m=e.length>0?Math.max(...e.map(f=>f.endOffset)):0;for(let f of s.sortedInsertOps){if(f.startOffset<m||o.has(f))continue;let p=e[e.length-1];i.push({kind:n?R.INSERTION:R.TEXT,text:f.text,rPrXml:p?.rPrXml||"",startOffset:f.startOffset,endOffset:f.startOffset+f.text.length,author:n?a:void 0})}return i}function $a(e){let{insertOp:t,splitModel:r,styleLookup:n,patchedModel:a,state:i,options:o,generateRedlines:s,author:l}=e,c=t.text.split(`
12
- `),u=Xa(n,t.startOffset,t.text);for(let m=0;m<c.length;m++){let f=Fa(c[m],o.numberingService,i),p=f.lineText;if(m>0){let g=Hr(i);f.isListLine&&f.numId&&(g=o.numberingService.buildListPPr(f.numId,f.ilvl)),a.push({kind:R.PARAGRAPH_START,pPrXml:g,startOffset:t.startOffset,endOffset:t.startOffset,text:""}),i.currentParagraphPPrXml=g,i.currentParagraphPPrElement=null,i.lastParagraphStartIndex=a.length-1}else if(f.isListLine&&f.numId&&i.lastParagraphStartIndex>=0){let g=o.numberingService.buildListPPr(f.numId,f.ilvl);a[i.lastParagraphStartIndex].pPrXml=g,a[i.lastParagraphStartIndex].pPrElement=null,i.currentParagraphPPrXml=g,i.currentParagraphPPrElement=null,C(`[Patching] Converted current paragraph to list item: numId=${f.numId}, ilvl=${f.ilvl}`)}(p.length>0||m>0)&&a.push({kind:s?R.INSERTION:R.TEXT,text:p,rPrXml:u?.rPrXml||"",startOffset:t.startOffset,endOffset:t.startOffset+p.length,author:s?l:void 0,containerContext:i.containerStack.length>0?i.containerStack[i.containerStack.length-1]:null})}}function Fa(e,t,r){if(!t)return{lineText:e,isListLine:!1,numId:null,ilvl:0};let n=fe(e,{allowZeroSpaceAfterMarker:!0});if(!n)return{lineText:e,isListLine:!1,numId:null,ilvl:0};let a=n[2].trim(),i=t.detectNumberingFormat(a),o=e.match(/^(\s*)/),s=o?o[1].length:0,l=s>=4?4:2,c=Math.floor(s/l),u=Hr(r),m=xe(e,{allowZeroSpaceAfterMarker:!0}),f=u.match(/w:numId w:val="(\d+)"/),p=u.match(/w:ilvl w:val="(\d+)"/),g=f?f[1]:null,d=p?parseInt(p[1],10):0,w=t.getOrCreateNumId({type:i.format},{numId:g,type:"unknown"}),h=i.format==="outline"?Math.min(8,i.depth):Math.min(8,c+d);return{lineText:m,isListLine:!0,numId:w,ilvl:h}}function Hr(e){return e.currentParagraphPPrXml?e.currentParagraphPPrXml:e.currentParagraphPPrElement?(e.currentParagraphPPrXml=j(e.currentParagraphPPrElement).replace(Ba,""),e.currentParagraphPPrXml):""}function Xa(e,t,r){let n=e.findRunBefore(t),a=e.findRunAfter(t);return!n&&!a?null:n?a?r&&r.endsWith(" ")?a:(r&&r.startsWith(" "),n):n:a}function Da(e){let t=e.filter(a=>a.kind===R.TEXT),r=t.map(a=>a.startOffset),n=t.map(a=>a.endOffset);return{findRunBefore(a){let i=0,o=n.length-1,s=-1;for(;i<=o;){let l=i+o>>1;n[l]<=a?(s=l,i=l+1):o=l-1}return s>=0?t[s]:null},findRunAfter(a){let i=0,o=r.length-1,s=-1;for(;i<=o;){let l=i+o>>1;r[l]>=a?(s=l,o=l-1):i=l+1}return s>=0?t[s]:null}}}function za(e){let t=0;return(r,n)=>{for(;t<e.length&&e[t].endOffset<=r;)t++;let a=e[t];return a&&a.startOffset<=r&&a.endOffset>=n?a:null}}function Wa(e){let t=new Set;for(let r of e)t.add(r.startOffset),t.add(r.endOffset);return Array.from(t).sort((r,n)=>r-n)}function Ha(e){let t=new Map,r=[],n=[];for(let a of e){if(a.type===re.INSERT){t.has(a.startOffset)||t.set(a.startOffset,[]),t.get(a.startOffset).push(a),n.push(a);continue}r.push(a)}return r.sort((a,i)=>a.startOffset-i.startOffset||a.endOffset-i.endOffset),n.sort((a,i)=>a.startOffset-i.startOffset||a.endOffset-i.endOffset),{insertOpsByStartOffset:t,nonInsertOps:r,sortedInsertOps:n}}var Vr="http://schemas.openxmlformats.org/wordprocessingml/2006/main",Ua="http://schemas.openxmlformats.org/officeDocument/2006/relationships",ja="http://schemas.microsoft.com/office/2006/xmlPackage",Ur="http://schemas.openxmlformats.org/package/2006/relationships",Ga='<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>',jr='<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/>';var Va=`
13
- <w:numbering xmlns:w="${Vr}">
1
+ var Ya=Object.create;var qr=Object.defineProperty;var Za=Object.getOwnPropertyDescriptor;var Ja=Object.getOwnPropertyNames;var qa=Object.getPrototypeOf,Qa=Object.prototype.hasOwnProperty;var eo=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var to=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Ja(t))!Qa.call(e,a)&&a!==r&&qr(e,a,{get:()=>t[a],enumerable:!(n=Za(t,a))||n.enumerable});return e};var ro=(e,t,r)=>(r=e!=null?Ya(qa(e)):{},to(t||!e||!e.__esModule?qr(r,"default",{value:e,enumerable:!0}):r,e));var mn=eo((kl,Ve)=>{var T=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32},D=-1,W=1,k=0;T.Diff=function(e,t){return[e,t]};T.prototype.diff_main=function(e,t,r,n){typeof n>"u"&&(this.Diff_Timeout<=0?n=Number.MAX_VALUE:n=new Date().getTime()+this.Diff_Timeout*1e3);var a=n;if(e==null||t==null)throw new Error("Null input. (diff_main)");if(e==t)return e?[new T.Diff(k,e)]:[];typeof r>"u"&&(r=!0);var o=r,i=this.diff_commonPrefix(e,t),s=e.substring(0,i);e=e.substring(i),t=t.substring(i),i=this.diff_commonSuffix(e,t);var l=e.substring(e.length-i);e=e.substring(0,e.length-i),t=t.substring(0,t.length-i);var c=this.diff_compute_(e,t,o,a);return s&&c.unshift(new T.Diff(k,s)),l&&c.push(new T.Diff(k,l)),this.diff_cleanupMerge(c),c};T.prototype.diff_compute_=function(e,t,r,n){var a;if(!e)return[new T.Diff(W,t)];if(!t)return[new T.Diff(D,e)];var o=e.length>t.length?e:t,i=e.length>t.length?t:e,s=o.indexOf(i);if(s!=-1)return a=[new T.Diff(W,o.substring(0,s)),new T.Diff(k,i),new T.Diff(W,o.substring(s+i.length))],e.length>t.length&&(a[0][0]=a[2][0]=D),a;if(i.length==1)return[new T.Diff(D,e),new T.Diff(W,t)];var l=this.diff_halfMatch_(e,t);if(l){var c=l[0],u=l[1],m=l[2],f=l[3],p=l[4],g=this.diff_main(c,m,r,n),d=this.diff_main(u,f,r,n);return g.concat([new T.Diff(k,p)],d)}return r&&e.length>100&&t.length>100?this.diff_lineMode_(e,t,n):this.diff_bisect_(e,t,n)};T.prototype.diff_lineMode_=function(e,t,r){var n=this.diff_linesToChars_(e,t);e=n.chars1,t=n.chars2;var a=n.lineArray,o=this.diff_main(e,t,!1,r);this.diff_charsToLines_(o,a),this.diff_cleanupSemantic(o),o.push(new T.Diff(k,""));for(var i=0,s=0,l=0,c="",u="";i<o.length;){switch(o[i][0]){case W:l++,u+=o[i][1];break;case D:s++,c+=o[i][1];break;case k:if(s>=1&&l>=1){o.splice(i-s-l,s+l),i=i-s-l;for(var m=this.diff_main(c,u,!1,r),f=m.length-1;f>=0;f--)o.splice(i,0,m[f]);i=i+m.length}l=0,s=0,c="",u="";break}i++}return o.pop(),o};T.prototype.diff_bisect_=function(e,t,r){for(var n=e.length,a=t.length,o=Math.ceil((n+a)/2),i=o,s=2*o,l=new Array(s),c=new Array(s),u=0;u<s;u++)l[u]=-1,c[u]=-1;l[i+1]=0,c[i+1]=0;for(var m=n-a,f=m%2!=0,p=0,g=0,d=0,w=0,h=0;h<o&&!(new Date().getTime()>r);h++){for(var b=-h+p;b<=h-g;b+=2){var x=i+b,E;b==-h||b!=h&&l[x-1]<l[x+1]?E=l[x+1]:E=l[x-1]+1;for(var v=E-b;E<n&&v<a&&e.charAt(E)==t.charAt(v);)E++,v++;if(l[x]=E,E>n)g+=2;else if(v>a)p+=2;else if(f){var P=i+m-b;if(P>=0&&P<s&&c[P]!=-1){var N=n-c[P];if(E>=N)return this.diff_bisectSplit_(e,t,E,v,r)}}}for(var y=-h+d;y<=h-w;y+=2){var P=i+y,N;y==-h||y!=h&&c[P-1]<c[P+1]?N=c[P+1]:N=c[P-1]+1;for(var I=N-y;N<n&&I<a&&e.charAt(n-N-1)==t.charAt(a-I-1);)N++,I++;if(c[P]=N,N>n)w+=2;else if(I>a)d+=2;else if(!f){var x=i+m-y;if(x>=0&&x<s&&l[x]!=-1){var E=l[x],v=i+E-x;if(N=n-N,E>=N)return this.diff_bisectSplit_(e,t,E,v,r)}}}}return[new T.Diff(D,e),new T.Diff(W,t)]};T.prototype.diff_bisectSplit_=function(e,t,r,n,a){var o=e.substring(0,r),i=t.substring(0,n),s=e.substring(r),l=t.substring(n),c=this.diff_main(o,i,!1,a),u=this.diff_main(s,l,!1,a);return c.concat(u)};T.prototype.diff_linesToChars_=function(e,t){var r=[],n={};r[0]="";function a(l){for(var c="",u=0,m=-1,f=r.length;m<l.length-1;){m=l.indexOf(`
2
+ `,u),m==-1&&(m=l.length-1);var p=l.substring(u,m+1);(n.hasOwnProperty?n.hasOwnProperty(p):n[p]!==void 0)?c+=String.fromCharCode(n[p]):(f==o&&(p=l.substring(u),m=l.length),c+=String.fromCharCode(f),n[p]=f,r[f++]=p),u=m+1}return c}var o=4e4,i=a(e);o=65535;var s=a(t);return{chars1:i,chars2:s,lineArray:r}};T.prototype.diff_charsToLines_=function(e,t){for(var r=0;r<e.length;r++){for(var n=e[r][1],a=[],o=0;o<n.length;o++)a[o]=t[n.charCodeAt(o)];e[r][1]=a.join("")}};T.prototype.diff_commonPrefix=function(e,t){if(!e||!t||e.charAt(0)!=t.charAt(0))return 0;for(var r=0,n=Math.min(e.length,t.length),a=n,o=0;r<a;)e.substring(o,a)==t.substring(o,a)?(r=a,o=r):n=a,a=Math.floor((n-r)/2+r);return a};T.prototype.diff_commonSuffix=function(e,t){if(!e||!t||e.charAt(e.length-1)!=t.charAt(t.length-1))return 0;for(var r=0,n=Math.min(e.length,t.length),a=n,o=0;r<a;)e.substring(e.length-a,e.length-o)==t.substring(t.length-a,t.length-o)?(r=a,o=r):n=a,a=Math.floor((n-r)/2+r);return a};T.prototype.diff_commonOverlap_=function(e,t){var r=e.length,n=t.length;if(r==0||n==0)return 0;r>n?e=e.substring(r-n):r<n&&(t=t.substring(0,r));var a=Math.min(r,n);if(e==t)return a;for(var o=0,i=1;;){var s=e.substring(a-i),l=t.indexOf(s);if(l==-1)return o;i+=l,(l==0||e.substring(a-i)==t.substring(0,i))&&(o=i,i++)}};T.prototype.diff_halfMatch_=function(e,t){if(this.Diff_Timeout<=0)return null;var r=e.length>t.length?e:t,n=e.length>t.length?t:e;if(r.length<4||n.length*2<r.length)return null;var a=this;function o(g,d,w){for(var h=g.substring(w,w+Math.floor(g.length/4)),b=-1,x="",E,v,P,N;(b=d.indexOf(h,b+1))!=-1;){var y=a.diff_commonPrefix(g.substring(w),d.substring(b)),I=a.diff_commonSuffix(g.substring(0,w),d.substring(0,b));x.length<I+y&&(x=d.substring(b-I,b)+d.substring(b,b+y),E=g.substring(0,w-I),v=g.substring(w+y),P=d.substring(0,b-I),N=d.substring(b+y))}return x.length*2>=g.length?[E,v,P,N,x]:null}var i=o(r,n,Math.ceil(r.length/4)),s=o(r,n,Math.ceil(r.length/2)),l;if(!i&&!s)return null;s?i?l=i[4].length>s[4].length?i:s:l=s:l=i;var c,u,m,f;e.length>t.length?(c=l[0],u=l[1],m=l[2],f=l[3]):(m=l[0],f=l[1],c=l[2],u=l[3]);var p=l[4];return[c,u,m,f,p]};T.prototype.diff_cleanupSemantic=function(e){for(var t=!1,r=[],n=0,a=null,o=0,i=0,s=0,l=0,c=0;o<e.length;)e[o][0]==k?(r[n++]=o,i=l,s=c,l=0,c=0,a=e[o][1]):(e[o][0]==W?l+=e[o][1].length:c+=e[o][1].length,a&&a.length<=Math.max(i,s)&&a.length<=Math.max(l,c)&&(e.splice(r[n-1],0,new T.Diff(D,a)),e[r[n-1]+1][0]=W,n--,n--,o=n>0?r[n-1]:-1,i=0,s=0,l=0,c=0,a=null,t=!0)),o++;for(t&&this.diff_cleanupMerge(e),this.diff_cleanupSemanticLossless(e),o=1;o<e.length;){if(e[o-1][0]==D&&e[o][0]==W){var u=e[o-1][1],m=e[o][1],f=this.diff_commonOverlap_(u,m),p=this.diff_commonOverlap_(m,u);f>=p?(f>=u.length/2||f>=m.length/2)&&(e.splice(o,0,new T.Diff(k,m.substring(0,f))),e[o-1][1]=u.substring(0,u.length-f),e[o+1][1]=m.substring(f),o++):(p>=u.length/2||p>=m.length/2)&&(e.splice(o,0,new T.Diff(k,u.substring(0,p))),e[o-1][0]=W,e[o-1][1]=m.substring(0,m.length-p),e[o+1][0]=D,e[o+1][1]=u.substring(p),o++),o++}o++}};T.prototype.diff_cleanupSemanticLossless=function(e){function t(p,g){if(!p||!g)return 6;var d=p.charAt(p.length-1),w=g.charAt(0),h=d.match(T.nonAlphaNumericRegex_),b=w.match(T.nonAlphaNumericRegex_),x=h&&d.match(T.whitespaceRegex_),E=b&&w.match(T.whitespaceRegex_),v=x&&d.match(T.linebreakRegex_),P=E&&w.match(T.linebreakRegex_),N=v&&p.match(T.blanklineEndRegex_),y=P&&g.match(T.blanklineStartRegex_);return N||y?5:v||P?4:h&&!x&&E?3:x||E?2:h||b?1:0}for(var r=1;r<e.length-1;){if(e[r-1][0]==k&&e[r+1][0]==k){var n=e[r-1][1],a=e[r][1],o=e[r+1][1],i=this.diff_commonSuffix(n,a);if(i){var s=a.substring(a.length-i);n=n.substring(0,n.length-i),a=s+a.substring(0,a.length-i),o=s+o}for(var l=n,c=a,u=o,m=t(n,a)+t(a,o);a.charAt(0)===o.charAt(0);){n+=a.charAt(0),a=a.substring(1)+o.charAt(0),o=o.substring(1);var f=t(n,a)+t(a,o);f>=m&&(m=f,l=n,c=a,u=o)}e[r-1][1]!=l&&(l?e[r-1][1]=l:(e.splice(r-1,1),r--),e[r][1]=c,u?e[r+1][1]=u:(e.splice(r+1,1),r--))}r++}};T.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/;T.whitespaceRegex_=/\s/;T.linebreakRegex_=/[\r\n]/;T.blanklineEndRegex_=/\n\r?\n$/;T.blanklineStartRegex_=/^\r?\n\r?\n/;T.prototype.diff_cleanupEfficiency=function(e){for(var t=!1,r=[],n=0,a=null,o=0,i=!1,s=!1,l=!1,c=!1;o<e.length;)e[o][0]==k?(e[o][1].length<this.Diff_EditCost&&(l||c)?(r[n++]=o,i=l,s=c,a=e[o][1]):(n=0,a=null),l=c=!1):(e[o][0]==D?c=!0:l=!0,a&&(i&&s&&l&&c||a.length<this.Diff_EditCost/2&&i+s+l+c==3)&&(e.splice(r[n-1],0,new T.Diff(D,a)),e[r[n-1]+1][0]=W,n--,a=null,i&&s?(l=c=!0,n=0):(n--,o=n>0?r[n-1]:-1,l=c=!1),t=!0)),o++;t&&this.diff_cleanupMerge(e)};T.prototype.diff_cleanupMerge=function(e){e.push(new T.Diff(k,""));for(var t=0,r=0,n=0,a="",o="",i;t<e.length;)switch(e[t][0]){case W:n++,o+=e[t][1],t++;break;case D:r++,a+=e[t][1],t++;break;case k:r+n>1?(r!==0&&n!==0&&(i=this.diff_commonPrefix(o,a),i!==0&&(t-r-n>0&&e[t-r-n-1][0]==k?e[t-r-n-1][1]+=o.substring(0,i):(e.splice(0,0,new T.Diff(k,o.substring(0,i))),t++),o=o.substring(i),a=a.substring(i)),i=this.diff_commonSuffix(o,a),i!==0&&(e[t][1]=o.substring(o.length-i)+e[t][1],o=o.substring(0,o.length-i),a=a.substring(0,a.length-i))),t-=r+n,e.splice(t,r+n),a.length&&(e.splice(t,0,new T.Diff(D,a)),t++),o.length&&(e.splice(t,0,new T.Diff(W,o)),t++),t++):t!==0&&e[t-1][0]==k?(e[t-1][1]+=e[t][1],e.splice(t,1)):t++,n=0,r=0,a="",o="";break}e[e.length-1][1]===""&&e.pop();var s=!1;for(t=1;t<e.length-1;)e[t-1][0]==k&&e[t+1][0]==k&&(e[t][1].substring(e[t][1].length-e[t-1][1].length)==e[t-1][1]?(e[t][1]=e[t-1][1]+e[t][1].substring(0,e[t][1].length-e[t-1][1].length),e[t+1][1]=e[t-1][1]+e[t+1][1],e.splice(t-1,1),s=!0):e[t][1].substring(0,e[t+1][1].length)==e[t+1][1]&&(e[t-1][1]+=e[t+1][1],e[t][1]=e[t][1].substring(e[t+1][1].length)+e[t+1][1],e.splice(t+1,1),s=!0)),t++;s&&this.diff_cleanupMerge(e)};T.prototype.diff_xIndex=function(e,t){var r=0,n=0,a=0,o=0,i;for(i=0;i<e.length&&(e[i][0]!==W&&(r+=e[i][1].length),e[i][0]!==D&&(n+=e[i][1].length),!(r>t));i++)a=r,o=n;return e.length!=i&&e[i][0]===D?o:o+(t-a)};T.prototype.diff_prettyHtml=function(e){for(var t=[],r=/&/g,n=/</g,a=/>/g,o=/\n/g,i=0;i<e.length;i++){var s=e[i][0],l=e[i][1],c=l.replace(r,"&amp;").replace(n,"&lt;").replace(a,"&gt;").replace(o,"&para;<br>");switch(s){case W:t[i]='<ins style="background:#e6ffe6;">'+c+"</ins>";break;case D:t[i]='<del style="background:#ffe6e6;">'+c+"</del>";break;case k:t[i]="<span>"+c+"</span>";break}}return t.join("")};T.prototype.diff_text1=function(e){for(var t=[],r=0;r<e.length;r++)e[r][0]!==W&&(t[r]=e[r][1]);return t.join("")};T.prototype.diff_text2=function(e){for(var t=[],r=0;r<e.length;r++)e[r][0]!==D&&(t[r]=e[r][1]);return t.join("")};T.prototype.diff_levenshtein=function(e){for(var t=0,r=0,n=0,a=0;a<e.length;a++){var o=e[a][0],i=e[a][1];switch(o){case W:r+=i.length;break;case D:n+=i.length;break;case k:t+=Math.max(r,n),r=0,n=0;break}}return t+=Math.max(r,n),t};T.prototype.diff_toDelta=function(e){for(var t=[],r=0;r<e.length;r++)switch(e[r][0]){case W:t[r]="+"+encodeURI(e[r][1]);break;case D:t[r]="-"+e[r][1].length;break;case k:t[r]="="+e[r][1].length;break}return t.join(" ").replace(/%20/g," ")};T.prototype.diff_fromDelta=function(e,t){for(var r=[],n=0,a=0,o=t.split(/\t/g),i=0;i<o.length;i++){var s=o[i].substring(1);switch(o[i].charAt(0)){case"+":try{r[n++]=new T.Diff(W,decodeURI(s))}catch{throw new Error("Illegal escape in diff_fromDelta: "+s)}break;case"-":case"=":var l=parseInt(s,10);if(isNaN(l)||l<0)throw new Error("Invalid number in diff_fromDelta: "+s);var c=e.substring(a,a+=l);o[i].charAt(0)=="="?r[n++]=new T.Diff(k,c):r[n++]=new T.Diff(D,c);break;default:if(o[i])throw new Error("Invalid diff operation in diff_fromDelta: "+o[i])}}if(a!=e.length)throw new Error("Delta length ("+a+") does not equal source text length ("+e.length+").");return r};T.prototype.match_main=function(e,t,r){if(e==null||t==null||r==null)throw new Error("Null input. (match_main)");return r=Math.max(0,Math.min(r,e.length)),e==t?0:e.length?e.substring(r,r+t.length)==t?r:this.match_bitap_(e,t,r):-1};T.prototype.match_bitap_=function(e,t,r){if(t.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var n=this.match_alphabet_(t),a=this;function o(E,v){var P=E/t.length,N=Math.abs(r-v);return a.Match_Distance?P+N/a.Match_Distance:N?1:P}var i=this.Match_Threshold,s=e.indexOf(t,r);s!=-1&&(i=Math.min(o(0,s),i),s=e.lastIndexOf(t,r+t.length),s!=-1&&(i=Math.min(o(0,s),i)));var l=1<<t.length-1;s=-1;for(var c,u,m=t.length+e.length,f,p=0;p<t.length;p++){for(c=0,u=m;c<u;)o(p,r+u)<=i?c=u:m=u,u=Math.floor((m-c)/2+c);m=u;var g=Math.max(1,r-u+1),d=Math.min(r+u,e.length)+t.length,w=Array(d+2);w[d+1]=(1<<p)-1;for(var h=d;h>=g;h--){var b=n[e.charAt(h-1)];if(p===0?w[h]=(w[h+1]<<1|1)&b:w[h]=(w[h+1]<<1|1)&b|((f[h+1]|f[h])<<1|1)|f[h+1],w[h]&l){var x=o(p,h-1);if(x<=i)if(i=x,s=h-1,s>r)g=Math.max(1,2*r-s);else break}}if(o(p+1,r)>i)break;f=w}return s};T.prototype.match_alphabet_=function(e){for(var t={},r=0;r<e.length;r++)t[e.charAt(r)]=0;for(var r=0;r<e.length;r++)t[e.charAt(r)]|=1<<e.length-r-1;return t};T.prototype.patch_addContext_=function(e,t){if(t.length!=0){if(e.start2===null)throw Error("patch not initialized");for(var r=t.substring(e.start2,e.start2+e.length1),n=0;t.indexOf(r)!=t.lastIndexOf(r)&&r.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)n+=this.Patch_Margin,r=t.substring(e.start2-n,e.start2+e.length1+n);n+=this.Patch_Margin;var a=t.substring(e.start2-n,e.start2);a&&e.diffs.unshift(new T.Diff(k,a));var o=t.substring(e.start2+e.length1,e.start2+e.length1+n);o&&e.diffs.push(new T.Diff(k,o)),e.start1-=a.length,e.start2-=a.length,e.length1+=a.length+o.length,e.length2+=a.length+o.length}};T.prototype.patch_make=function(e,t,r){var n,a;if(typeof e=="string"&&typeof t=="string"&&typeof r>"u")n=e,a=this.diff_main(n,t,!0),a.length>2&&(this.diff_cleanupSemantic(a),this.diff_cleanupEfficiency(a));else if(e&&typeof e=="object"&&typeof t>"u"&&typeof r>"u")a=e,n=this.diff_text1(a);else if(typeof e=="string"&&t&&typeof t=="object"&&typeof r>"u")n=e,a=t;else if(typeof e=="string"&&typeof t=="string"&&r&&typeof r=="object")n=e,a=r;else throw new Error("Unknown call format to patch_make.");if(a.length===0)return[];for(var o=[],i=new T.patch_obj,s=0,l=0,c=0,u=n,m=n,f=0;f<a.length;f++){var p=a[f][0],g=a[f][1];switch(!s&&p!==k&&(i.start1=l,i.start2=c),p){case W:i.diffs[s++]=a[f],i.length2+=g.length,m=m.substring(0,c)+g+m.substring(c);break;case D:i.length1+=g.length,i.diffs[s++]=a[f],m=m.substring(0,c)+m.substring(c+g.length);break;case k:g.length<=2*this.Patch_Margin&&s&&a.length!=f+1?(i.diffs[s++]=a[f],i.length1+=g.length,i.length2+=g.length):g.length>=2*this.Patch_Margin&&s&&(this.patch_addContext_(i,u),o.push(i),i=new T.patch_obj,s=0,u=m,l=c);break}p!==W&&(l+=g.length),p!==D&&(c+=g.length)}return s&&(this.patch_addContext_(i,u),o.push(i)),o};T.prototype.patch_deepCopy=function(e){for(var t=[],r=0;r<e.length;r++){var n=e[r],a=new T.patch_obj;a.diffs=[];for(var o=0;o<n.diffs.length;o++)a.diffs[o]=new T.Diff(n.diffs[o][0],n.diffs[o][1]);a.start1=n.start1,a.start2=n.start2,a.length1=n.length1,a.length2=n.length2,t[r]=a}return t};T.prototype.patch_apply=function(e,t){if(e.length==0)return[t,[]];e=this.patch_deepCopy(e);var r=this.patch_addPadding(e);t=r+t+r,this.patch_splitMax(e);for(var n=0,a=[],o=0;o<e.length;o++){var i=e[o].start2+n,s=this.diff_text1(e[o].diffs),l,c=-1;if(s.length>this.Match_MaxBits?(l=this.match_main(t,s.substring(0,this.Match_MaxBits),i),l!=-1&&(c=this.match_main(t,s.substring(s.length-this.Match_MaxBits),i+s.length-this.Match_MaxBits),(c==-1||l>=c)&&(l=-1))):l=this.match_main(t,s,i),l==-1)a[o]=!1,n-=e[o].length2-e[o].length1;else{a[o]=!0,n=l-i;var u;if(c==-1?u=t.substring(l,l+s.length):u=t.substring(l,c+this.Match_MaxBits),s==u)t=t.substring(0,l)+this.diff_text2(e[o].diffs)+t.substring(l+s.length);else{var m=this.diff_main(s,u,!1);if(s.length>this.Match_MaxBits&&this.diff_levenshtein(m)/s.length>this.Patch_DeleteThreshold)a[o]=!1;else{this.diff_cleanupSemanticLossless(m);for(var f=0,p,g=0;g<e[o].diffs.length;g++){var d=e[o].diffs[g];d[0]!==k&&(p=this.diff_xIndex(m,f)),d[0]===W?t=t.substring(0,l+p)+d[1]+t.substring(l+p):d[0]===D&&(t=t.substring(0,l+p)+t.substring(l+this.diff_xIndex(m,f+d[1].length))),d[0]!==D&&(f+=d[1].length)}}}}}return t=t.substring(r.length,t.length-r.length),[t,a]};T.prototype.patch_addPadding=function(e){for(var t=this.Patch_Margin,r="",n=1;n<=t;n++)r+=String.fromCharCode(n);for(var n=0;n<e.length;n++)e[n].start1+=t,e[n].start2+=t;var a=e[0],o=a.diffs;if(o.length==0||o[0][0]!=k)o.unshift(new T.Diff(k,r)),a.start1-=t,a.start2-=t,a.length1+=t,a.length2+=t;else if(t>o[0][1].length){var i=t-o[0][1].length;o[0][1]=r.substring(o[0][1].length)+o[0][1],a.start1-=i,a.start2-=i,a.length1+=i,a.length2+=i}if(a=e[e.length-1],o=a.diffs,o.length==0||o[o.length-1][0]!=k)o.push(new T.Diff(k,r)),a.length1+=t,a.length2+=t;else if(t>o[o.length-1][1].length){var i=t-o[o.length-1][1].length;o[o.length-1][1]+=r.substring(0,i),a.length1+=i,a.length2+=i}return r};T.prototype.patch_splitMax=function(e){for(var t=this.Match_MaxBits,r=0;r<e.length;r++)if(!(e[r].length1<=t)){var n=e[r];e.splice(r--,1);for(var a=n.start1,o=n.start2,i="";n.diffs.length!==0;){var s=new T.patch_obj,l=!0;for(s.start1=a-i.length,s.start2=o-i.length,i!==""&&(s.length1=s.length2=i.length,s.diffs.push(new T.Diff(k,i)));n.diffs.length!==0&&s.length1<t-this.Patch_Margin;){var c=n.diffs[0][0],u=n.diffs[0][1];c===W?(s.length2+=u.length,o+=u.length,s.diffs.push(n.diffs.shift()),l=!1):c===D&&s.diffs.length==1&&s.diffs[0][0]==k&&u.length>2*t?(s.length1+=u.length,a+=u.length,l=!1,s.diffs.push(new T.Diff(c,u)),n.diffs.shift()):(u=u.substring(0,t-s.length1-this.Patch_Margin),s.length1+=u.length,a+=u.length,c===k?(s.length2+=u.length,o+=u.length):l=!1,s.diffs.push(new T.Diff(c,u)),u==n.diffs[0][1]?n.diffs.shift():n.diffs[0][1]=n.diffs[0][1].substring(u.length))}i=this.diff_text2(s.diffs),i=i.substring(i.length-this.Patch_Margin);var m=this.diff_text1(n.diffs).substring(0,this.Patch_Margin);m!==""&&(s.length1+=m.length,s.length2+=m.length,s.diffs.length!==0&&s.diffs[s.diffs.length-1][0]===k?s.diffs[s.diffs.length-1][1]+=m:s.diffs.push(new T.Diff(k,m))),l||e.splice(++r,0,s)}}};T.prototype.patch_toText=function(e){for(var t=[],r=0;r<e.length;r++)t[r]=e[r];return t.join("")};T.prototype.patch_fromText=function(e){var t=[];if(!e)return t;for(var r=e.split(`
3
+ `),n=0,a=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;n<r.length;){var o=r[n].match(a);if(!o)throw new Error("Invalid patch string: "+r[n]);var i=new T.patch_obj;for(t.push(i),i.start1=parseInt(o[1],10),o[2]===""?(i.start1--,i.length1=1):o[2]=="0"?i.length1=0:(i.start1--,i.length1=parseInt(o[2],10)),i.start2=parseInt(o[3],10),o[4]===""?(i.start2--,i.length2=1):o[4]=="0"?i.length2=0:(i.start2--,i.length2=parseInt(o[4],10)),n++;n<r.length;){var s=r[n].charAt(0);try{var l=decodeURI(r[n].substring(1))}catch{throw new Error("Illegal escape in patch_fromText: "+l)}if(s=="-")i.diffs.push(new T.Diff(D,l));else if(s=="+")i.diffs.push(new T.Diff(W,l));else if(s==" ")i.diffs.push(new T.Diff(k,l));else{if(s=="@")break;if(s!=="")throw new Error('Invalid patch mode "'+s+'" in: '+l)}n++}}return t};T.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0};T.patch_obj.prototype.toString=function(){var e,t;this.length1===0?e=this.start1+",0":this.length1==1?e=this.start1+1:e=this.start1+1+","+this.length1,this.length2===0?t=this.start2+",0":this.length2==1?t=this.start2+1:t=this.start2+1+","+this.length2;for(var r=["@@ -"+e+" +"+t+` @@
4
+ `],n,a=0;a<this.diffs.length;a++){switch(this.diffs[a][0]){case W:n="+";break;case D:n="-";break;case k:n=" ";break}r[a+1]=n+encodeURI(this.diffs[a][1])+`
5
+ `}return r.join("").replace(/%20/g," ")};Ve.exports=T;Ve.exports.diff_match_patch=T;Ve.exports.DIFF_DELETE=D;Ve.exports.DIFF_INSERT=W;Ve.exports.DIFF_EQUAL=k});var ot=globalThis.DOMParser,it=globalThis.XMLSerializer;function no(e={}){e.DOMParser&&(ot=e.DOMParser),e.XMLSerializer&&(it=e.XMLSerializer)}function B(){if(!ot&&globalThis.DOMParser&&(ot=globalThis.DOMParser),!ot)throw new Error("DOMParser is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new ot}function Q(){if(!it&&globalThis.XMLSerializer&&(it=globalThis.XMLSerializer),!it)throw new Error("XMLSerializer is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new it}function Pt(e,t="text/xml"){return B().parseFromString(e,t)}function K(e){return Q().serializeToString(e)}var St=console,rr=Object.freeze({silent:0,error:1,warn:2,info:3}),ao=typeof process<"u"&&process?.env?.NODE_ENV==="production"?"warn":"info",nr=ao;function oo(e){let t=String(e||"").toLowerCase();return Object.prototype.hasOwnProperty.call(rr,t)?t:nr}function ar(e){return rr[nr]>=rr[e]}function io(e,t={}){St=e||console,t.level&&(nr=oo(t.level))}function C(...e){ar("info")&&(St.log||(()=>{}))(...e)}function ke(...e){ar("warn")&&(St.warn||(()=>{}))(...e)}function Z(...e){ar("error")&&(St.error||(()=>{}))(...e)}var Qr="Author",en="Unknown";function so(e){Qr=typeof e=="string"&&e.trim()?e.trim():"Author"}function J(){return Qr}function lo(e){en=typeof e=="string"&&e.trim()?e.trim():"Unknown"}function or(){return en}var co=[{regex:/<b>(.+?)<\/b>/i,format:{bold:!0}},{regex:/<strong>(.+?)<\/strong>/i,format:{bold:!0}},{regex:/<i>(.+?)<\/i>/i,format:{italic:!0}},{regex:/<em>(.+?)<\/em>/i,format:{italic:!0}},{regex:/<u>(.+?)<\/u>/i,format:{underline:!0}},{regex:/<s>(.+?)<\/s>/i,format:{strikethrough:!0}},{regex:/<strike>(.+?)<\/strike>/i,format:{strikethrough:!0}},{regex:/<del>(.+?)<\/del>/i,format:{strikethrough:!0}},{regex:/&lt;b&gt;(.+?)&lt;\/b&gt;/i,format:{bold:!0},isEscaped:!0},{regex:/&lt;strong&gt;(.+?)&lt;\/strong&gt;/i,format:{bold:!0},isEscaped:!0},{regex:/&lt;i&gt;(.+?)&lt;\/i&gt;/i,format:{italic:!0},isEscaped:!0},{regex:/&lt;em&gt;(.+?)&lt;\/em&gt;/i,format:{italic:!0},isEscaped:!0},{regex:/&lt;u&gt;(.+?)&lt;\/u&gt;/i,format:{underline:!0},isEscaped:!0},{regex:/&lt;s&gt;(.+?)&lt;\/s&gt;/i,format:{strikethrough:!0},isEscaped:!0},{regex:/\*\*\*(.+?)\*\*\*/,format:{bold:!0,italic:!0}},{regex:/\*\*\+\+(.+?)\+\+\*\*/,format:{bold:!0,underline:!0}},{regex:/\*\*(.+?)\*\*/,format:{bold:!0}},{regex:/__(.+?)__/,format:{bold:!0}},{regex:/\+\+(.+?)\+\+/,format:{underline:!0}},{regex:/~~(.+?)~~/,format:{strikethrough:!0}},{regex:/~(.+?)~/,format:{strikethrough:!0}},{regex:/\*(?!\*)(.+?)\*(?!\*)/,format:{italic:!0}},{regex:/_(?!_)(.+?)_(?!_)/,format:{italic:!0}}];function ne(e){if(!e)return{cleanText:"",formatHints:[]};let t=[],r="",n=[];for(let s of co){let l,c=s.regex.source||s.regex.toString().replace(/^\/|\/[gimuy]*$/g,""),u="g"+(s.regex.ignoreCase?"i":""),m=new RegExp(c,u);for(;(l=m.exec(e))!==null;)n.push({start:l.index,end:l.index+l[0].length,fullMatch:l[0],innerText:s.isEscaped?uo(l[1]):l[1],format:s.format}),l.index===m.lastIndex&&m.lastIndex++}n.sort((s,l)=>s.start-l.start||l.end-s.end);let a=[],o=0;for(let s of n)s.start>=o&&(a.push(s),o=s.end);let i=0;for(let s of a){r+=e.slice(i,s.start);let l=ne(s.innerText),c=r.length;r+=l.cleanText;let u=r.length;t.push({start:c,end:u,format:s.format});for(let m of l.formatHints)t.push({start:c+m.start,end:c+m.end,format:m.format});i=s.end}return r+=e.slice(i),{cleanText:r,formatHints:t}}function we(e,t,r){return e.filter(n=>n.start<r&&n.end>t)}function ir(...e){let t={};for(let r of e)r&&Object.assign(t,r);return t}function uo(e){return e?e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#039;/g,"'"):""}var It=String.raw`(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|\d+\.|[ivxlcIVXLC]+\.|[-*\u2022])`,tn=new RegExp(`^(\\s*)((?:${It})\\s+)`),rn=new RegExp(`^(\\s*)((?:${It})\\s*)`),fo=new RegExp(`^(\\s*)((?:${It})\\s+)`,"m"),mo=new RegExp(`^(\\s*)((?:${It})\\s*)`,"m");function nn(e){return typeof e!="string"?!1:e.includes(`
6
+ `)&&fo.test(e)}function Ct(e){return typeof e!="string"?!1:e.includes(`
7
+ `)&&mo.test(e.trim())}function be(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?rn:tn;return e.match(n)}function Ee(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?rn:tn;return e.replace(n,"")}var S="http://schemas.openxmlformats.org/wordprocessingml/2006/main";var ce=Object.freeze({EQUAL:"equal",DELETE:"delete",INSERT:"insert"}),O=Object.freeze({TEXT:"run",DELETION:"deletion",INSERTION:"insertion",HYPERLINK:"hyperlink",BOOKMARK:"bookmark",FIELD:"field",CONTAINER_START:"container_start",CONTAINER_END:"container_end",PARAGRAPH_START:"paragraph_start"}),Ue=Object.freeze({SDT:"sdt",SMART_TAG:"smartTag",CUSTOM_XML:"customXml",FIELD_COMPLEX:"fldComplex"}),an=Object.freeze({PARAGRAPH:"paragraph",BULLET_LIST:"bullet_list",NUMBERED_LIST:"numbered_list",TABLE:"table"}),F=Object.freeze({DECIMAL:"decimal",LOWER_ALPHA:"lowerLetter",UPPER_ALPHA:"upperLetter",LOWER_ROMAN:"lowerRoman",UPPER_ROMAN:"upperRoman",BULLET:"bullet",OUTLINE:"outline"}),q=Object.freeze({PERIOD:"period",PAREN_RIGHT:"parenRight",PAREN_BOTH:"parenBoth",NONE:"none"});function oe(e){return e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;"):""}var At=1e3;function sr(){return At++}function lr(e=new Date){return e.toISOString()}function ee(e){let t=typeof e=="string"&&e.trim()?e.trim():J();return{id:sr(),author:t,date:lr()}}function cr(e){let t=-1,r=Array.from(e?.getElementsByTagName?.("*")||[]);for(let n of r)for(let a of Array.from(n.attributes||[])){if((a.localName||"").toLowerCase()!=="id")continue;let o=Number.parseInt(a.value,10);Number.isFinite(o)&&(t=Math.max(t,o))}return t>=At&&(At=t+1),At}var on=`
8
+ `,po=on.length;function sn(e,t){return e<t-1}function je(e,t,r){return sn(t,r)?e+on:e}function Me(e,t,r){return sn(t,r)?e+po:e}function Pe(e,t){return!e||typeof e.getElementsByTagName!="function"?[]:Array.from(e.getElementsByTagName(t))}function $(e,t){if(!e||typeof e.getElementsByTagName!="function")return null;let r=e.getElementsByTagName(t);return r.length>0?r[0]:null}function V(e,t,r){return!e||typeof e.getElementsByTagNameNS!="function"?[]:Array.from(e.getElementsByTagNameNS(t,r))}function H(e,t,r){if(!e||typeof e.getElementsByTagNameNS!="function")return null;let n=e.getElementsByTagNameNS(t,r);return n.length>0?n[0]:null}function ue(e,t,r,n=`w:${r}`){let a=V(e,t,r);return a.length>0?a:Pe(e,n)}function Rt(e,t,r,n=`w:${r}`){let a=H(e,t,r);return a||$(e,n)}function j(e){return $(e,"parsererror")}function ur(e){return Array.from(e?.childNodes||[])}function ln(e){return Array.from(e.attributes).map(t=>`${t.name}="${t.value}"`).join(" ")}function fr(e,t,r=""){return!e||e.namespaceURI!==t?!1:r?e.localName===r:!0}var mr=0;function Ot(e,t={}){let r=[],n="",a=t.xmlDoc||null;if(!e&&!a)return{runModel:r,acceptedText:n,pPr:null};try{let o=a||B().parseFromString(e,"application/xml"),i=j(o);if(i)return Z("OOXML parse error:",i.textContent),{runModel:r,acceptedText:n,pPr:null};let s=V(o,S,"p");return s.length===0?(ke("No paragraphs found in OOXML"),{runModel:r,acceptedText:n,pPr:null}):un(s,{includeParagraphBoundaries:!0})}catch(o){return Z("Error ingesting OOXML:",o),{runModel:r,acceptedText:n,pPr:null}}}function pr(e){return e?un([e],{includeParagraphBoundaries:!1}):{runModel:[],acceptedText:"",pPr:null}}function gr(e){let t=H(e,S,"pPr");if(!t)return null;let r=H(t,S,"numPr");if(!r)return null;let n=H(r,S,"numId"),a=H(r,S,"ilvl");if(!n)return null;let o=n.getAttribute("w:val"),i=o==="1"?"bullet":o==="2"?"numbered":"unknown";return{numId:o,ilvl:parseInt(a?.getAttribute("w:val")||"0",10),type:i}}function un(e,t={}){let r=t.includeParagraphBoundaries??!0,n=[],a="",o=0,i=null;for(let s=0;s<e.length;s++){let l=e[s],c=H(l,S,"pPr");s===0&&(i=c),n.push({kind:O.PARAGRAPH_START,pPrElement:c||null,startOffset:o,endOffset:o,text:""});let u=Ge(l,o,n);a+=u.text,o=a.length,r&&(a=je(a,s,e.length),o=Me(o,s,e.length))}return{runModel:n,acceptedText:a,pPr:i}}function Ge(e,t,r){let n=t,a="",o=go(r);for(let i of ur(e)){if(fr(i,S,"pPr")||fr(i,S,"proofErr"))continue;let s=o.get(i.localName);if(!s)continue;let l=s(i,n);n=l.offset,a+=l.text}return{offset:n,text:a}}function go(e){let t=new Map;t.set("sdt",(r,n)=>{let a=`sdt_${mr++}`,o=H(r,S,"sdtPr"),i=H(r,S,"sdtContent");e.push({kind:O.CONTAINER_START,containerKind:Ue.SDT,containerId:a,propertiesXml:o?K(o):"",startOffset:n,endOffset:n,text:""});let s=i?Ge(i,n,e):{offset:n,text:""};return e.push({kind:O.CONTAINER_END,containerKind:Ue.SDT,containerId:a,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("smartTag",(r,n)=>{let a=`smartTag_${mr++}`;e.push({kind:O.CONTAINER_START,containerKind:Ue.SMART_TAG,containerId:a,propertiesXml:ln(r),startOffset:n,endOffset:n,text:""});let o=Ge(r,n,e);return e.push({kind:O.CONTAINER_END,containerKind:Ue.SMART_TAG,containerId:a,startOffset:o.offset,endOffset:o.offset,text:""}),o}),t.set("del",(r,n)=>{let a=cn(r,n);return a&&e.push(a),{offset:n,text:""}}),t.set("moveFrom",(r,n)=>{let a=cn(r,n);return a&&e.push(a),{offset:n,text:""}}),t.set("moveTo",(r,n)=>Ge(r,n,e));for(let r of["moveFromRangeStart","moveFromRangeEnd","moveToRangeStart","moveToRangeEnd"])t.set(r,(n,a)=>(e.push({kind:O.BOOKMARK,nodeXml:K(n),startOffset:a,endOffset:a,text:""}),{offset:a,text:""}));return t.set("bookmarkStart",(r,n)=>(e.push({kind:O.BOOKMARK,nodeXml:K(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("bookmarkEnd",(r,n)=>(e.push({kind:O.BOOKMARK,nodeXml:K(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("ins",(r,n)=>Ge(r,n,e)),t.set("hyperlink",(r,n)=>{let a=`hyperlink_${mr++}`,o=r.getAttribute("r:id")||"",i=r.getAttribute("w:anchor")||"";e.push({kind:O.CONTAINER_START,containerKind:"hyperlink",containerId:a,propertiesXml:JSON.stringify({rId:o,anchor:i}),startOffset:n,endOffset:n,text:""});let s=Ge(r,n,e);return e.push({kind:O.CONTAINER_END,containerKind:"hyperlink",containerId:a,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("r",(r,n)=>{let a=ho(r,n);return!a||!a.text?{offset:n,text:""}:(e.push(a),{offset:n+a.text.length,text:a.text})}),t}function ho(e,t){let r=Rt(e,S,"rPr"),n=r?K(r):"",a="";for(let o of ur(e)){let i=o.nodeName;i.endsWith(":t")||i==="t"?a+=o.textContent||"":i.endsWith(":br")||i==="br"||i.endsWith(":cr")||i==="cr"?a+=`
9
+ `:i.endsWith(":tab")||i==="tab"?a+=" ":(i.endsWith(":noBreakHyphen")||i==="noBreakHyphen")&&(a+="\u2011")}return a?{kind:O.TEXT,text:a,rPrXml:n,startOffset:t,endOffset:t+a.length}:null}function cn(e,t){let r=e.getAttribute("w:author")||"",n="",a=V(e,S,"delText");for(let i of a)n+=i.textContent||"";let o=V(e,S,"r");for(let i of o){let s=V(i,S,"delText");for(let l of s)n+=l.textContent||""}return n?{kind:O.DELETION,text:n,rPrXml:"",startOffset:t,endOffset:t,author:r,nodeXml:K(e)}:null}function hr(e){let t=H(e,S,"tblGrid"),r=t?V(t,S,"gridCol"):[],n=ue(e,S,"tr"),a=n.length,o=n.reduce((u,m)=>{let f=ue(m,S,"tc");return Math.max(u,f.length)},0),i=r.length||o,s=Array.from({length:a},()=>Array.from({length:i},()=>null)),l=new Map,c=new Map;for(let u=0;u<n.length;u++){let m=n[u],f=ue(m,S,"tc"),p=0;for(let g=0;g<f.length;g++){let d=f[g],w=H(d,S,"tcPr");for(;p<i&&s[u][p]!==null;)p++;if(p>=i)break;let h=w?H(w,S,"gridSpan")||$(w,"w:gridSpan"):null,b=parseInt(h?.getAttribute("w:val")||"1",10),x=w?H(w,S,"vMerge")||$(w,"w:vMerge"):null,E=x?.getAttribute("w:val"),v=x!==null,P;if(v&&E!=="restart"){let N=c.get(p);N?(N.cell.rowSpan++,P={gridRow:u,gridCol:p,rowSpan:0,colSpan:b,tcNode:d,blocks:[],tcPrXml:dr(w),isMergeOrigin:!1,isMergeContinuation:!0,mergeOrigin:N.cell}):P=wo(u,p,b,d,w)}else{let N=fn(d);if(P={gridRow:u,gridCol:p,rowSpan:1,colSpan:b,tcNode:d,blocks:N,tcPrXml:dr(w),isMergeOrigin:v&&E==="restart",isMergeContinuation:!1,getText:()=>N.map(y=>y.acceptedText).join(`
10
+ `)},v&&E==="restart")for(let y=0;y<b;y++)c.set(p+y,{originRow:u,cell:P});else for(let y=0;y<b;y++)c.delete(p+y)}for(let N=0;N<b;N++){let y=p+N;y<i&&(s[u][y]=P,l.set(`${u},${y}`,P))}p+=b}}return{rowCount:a,colCount:i,grid:s,cellMap:l,tblPrXml:bo(e),tblGridXml:xo(e),trPrList:Array.from(n).map(u=>No(u))}}function wo(e,t,r,n,a){let o=fn(n);return{gridRow:e,gridCol:t,rowSpan:1,colSpan:r,tcNode:n,blocks:o,tcPrXml:dr(a),isMergeOrigin:!1,isMergeContinuation:!1,getText:()=>o.map(i=>i.acceptedText).join(`
11
+ `)}}function fn(e){return ue(e,S,"p").map(r=>{let{runModel:n,acceptedText:a,pPr:o}=pr(r);return{runModel:n,acceptedText:a,pPr:o}})}function dr(e){return e?K(e):"<w:tcPr/>"}function bo(e){let t=H(e,S,"tblPr");return t?K(t):"<w:tblPr/>"}function xo(e){let t=H(e,S,"tblGrid");return t?K(t):"<w:tblGrid/>"}function No(e){let t=H(e,S,"trPr");return t?K(t):"<w:trPr/>"}var gn=ro(mn(),1);var pn=new gn.diff_match_patch;function vo(e,t){let r=[],n=new Map;function a(l){let c=[],u=/(\S+)(\s*)/g,m;for(;(m=u.exec(l))!==null;)m[1]&&c.push(m[1]),m[2]&&c.push(m[2]);return c}function o(l){let c="";for(let u of l)if(n.has(u))c+=String.fromCharCode(n.get(u));else{let m=r.length;r.push(u),n.set(u,m),c+=String.fromCharCode(m)}return c}let i=a(e),s=a(t);return{chars1:o(i),chars2:o(s),wordArray:r}}function To(e,t){let r=[];for(let[n,a]of e){let o=[];for(let i=0;i<a.length;i++){let s=a.charCodeAt(i);s<t.length&&o.push(t[s])}r.push([n,o.join("")])}return r}function st(e,t,r={}){if(e===t)return[[0,e]];if(!e)return[[1,t]];if(!t)return[[-1,e]];let{cleanupSemantic:n=!0}=r,{chars1:a,chars2:o,wordArray:i}=vo(e,t),s=pn.diff_main(a,o);return n&&pn.diff_cleanupSemantic(s),To(s,i)}function kt(e,t,r={}){if(e===t)return[{type:ce.EQUAL,startOffset:0,endOffset:e.length,text:e}];if(!e)return[{type:ce.INSERT,startOffset:0,endOffset:0,text:t}];if(!t)return[{type:ce.DELETE,startOffset:0,endOffset:e.length,text:e}];let n=st(e,t,r),a=[],o=0;for(let[i,s]of n)i===0?(a.push({type:ce.EQUAL,startOffset:o,endOffset:o+s.length,text:s}),o+=s.length):i===-1?(a.push({type:ce.DELETE,startOffset:o,endOffset:o+s.length,text:s}),o+=s.length):i===1&&a.push({type:ce.INSERT,startOffset:o,endOffset:o,text:s});return a}var yo=/\s+xmlns:[^=]+="[^"]*"/g;function Mt(e,t){let r=Ao(t),n=[],a=0;for(let o of e){if(o.kind!==O.TEXT&&o.kind!==O.HYPERLINK){n.push(o);continue}for(;a<r.length&&r[a]<=o.startOffset;)a++;let i=a,s=o.startOffset,l=!1;for(;i<r.length;){let c=r[i];if(c>=o.endOffset)break;c>s&&(l=!0,n.push({...o,text:o.text.slice(s-o.startOffset,c-o.startOffset),startOffset:s,endOffset:c}),s=c),i++}if(a=i,!l){n.push(o);continue}n.push({...o,text:o.text.slice(s-o.startOffset),startOffset:s,endOffset:o.endOffset})}return n}function Lt(e,t,r){let{generateRedlines:n,author:a}=r,o=[],i=new Set,s=Ro(t),l=Io(e),c=Co(s.nonInsertOps),u={containerStack:[],lastParagraphStartIndex:-1,currentParagraphPPrXml:"",currentParagraphPPrElement:null};for(let f of e){if(f.kind===O.CONTAINER_START){u.containerStack.push(f.containerId),o.push({...f});continue}if(f.kind===O.CONTAINER_END){u.containerStack.pop(),o.push({...f});continue}if(f.kind===O.PARAGRAPH_START){u.currentParagraphPPrXml=typeof f.pPrXml=="string"?f.pPrXml:"",u.currentParagraphPPrElement=f.pPrElement||null,o.push({...f}),u.lastParagraphStartIndex=o.length-1;continue}if(f.kind===O.BOOKMARK||f.kind===O.DELETION){o.push({...f});continue}let p=c(f.startOffset,f.endOffset),g=s.insertOpsByStartOffset.get(f.startOffset)||[];for(let d of g)i.has(d)||(i.add(d),Eo({insertOp:d,splitModel:e,styleLookup:l,patchedModel:o,state:u,options:r,generateRedlines:n,author:a}));if(!p||p.type===ce.EQUAL){o.push({...f,containerContext:u.containerStack.length>0?u.containerStack[u.containerStack.length-1]:null});continue}p.type===ce.DELETE&&n&&o.push({...f,kind:O.DELETION,author:a,containerContext:u.containerStack.length>0?u.containerStack[u.containerStack.length-1]:null})}let m=e.length>0?Math.max(...e.map(f=>f.endOffset)):0;for(let f of s.sortedInsertOps){if(f.startOffset<m||i.has(f))continue;let p=e[e.length-1];o.push({kind:n?O.INSERTION:O.TEXT,text:f.text,rPrXml:p?.rPrXml||"",startOffset:f.startOffset,endOffset:f.startOffset+f.text.length,author:n?a:void 0})}return o}function Eo(e){let{insertOp:t,splitModel:r,styleLookup:n,patchedModel:a,state:o,options:i,generateRedlines:s,author:l}=e,c=t.text.split(`
12
+ `),u=So(n,t.startOffset,t.text);for(let m=0;m<c.length;m++){let f=Po(c[m],i.numberingService,o),p=f.lineText;if(m>0){let g=dn(o);f.isListLine&&f.numId&&(g=i.numberingService.buildListPPr(f.numId,f.ilvl)),a.push({kind:O.PARAGRAPH_START,pPrXml:g,startOffset:t.startOffset,endOffset:t.startOffset,text:""}),o.currentParagraphPPrXml=g,o.currentParagraphPPrElement=null,o.lastParagraphStartIndex=a.length-1}else if(f.isListLine&&f.numId&&o.lastParagraphStartIndex>=0){let g=i.numberingService.buildListPPr(f.numId,f.ilvl);a[o.lastParagraphStartIndex].pPrXml=g,a[o.lastParagraphStartIndex].pPrElement=null,o.currentParagraphPPrXml=g,o.currentParagraphPPrElement=null,C(`[Patching] Converted current paragraph to list item: numId=${f.numId}, ilvl=${f.ilvl}`)}(p.length>0||m>0)&&a.push({kind:s?O.INSERTION:O.TEXT,text:p,rPrXml:u?.rPrXml||"",startOffset:t.startOffset,endOffset:t.startOffset+p.length,author:s?l:void 0,containerContext:o.containerStack.length>0?o.containerStack[o.containerStack.length-1]:null})}}function Po(e,t,r){if(!t)return{lineText:e,isListLine:!1,numId:null,ilvl:0};let n=be(e,{allowZeroSpaceAfterMarker:!0});if(!n)return{lineText:e,isListLine:!1,numId:null,ilvl:0};let a=n[2].trim(),o=t.detectNumberingFormat(a),i=e.match(/^(\s*)/),s=i?i[1].length:0,l=s>=4?4:2,c=Math.floor(s/l),u=dn(r),m=Ee(e,{allowZeroSpaceAfterMarker:!0}),f=u.match(/w:numId w:val="(\d+)"/),p=u.match(/w:ilvl w:val="(\d+)"/),g=f?f[1]:null,d=p?parseInt(p[1],10):0,w=t.getOrCreateNumId({type:o.format},{numId:g,type:"unknown"}),h=o.format==="outline"?Math.min(8,o.depth):Math.min(8,c+d);return{lineText:m,isListLine:!0,numId:w,ilvl:h}}function dn(e){return e.currentParagraphPPrXml?e.currentParagraphPPrXml:e.currentParagraphPPrElement?(e.currentParagraphPPrXml=K(e.currentParagraphPPrElement).replace(yo,""),e.currentParagraphPPrXml):""}function So(e,t,r){let n=e.findRunBefore(t),a=e.findRunAfter(t);return!n&&!a?null:n?a?r&&r.endsWith(" ")?a:(r&&r.startsWith(" "),n):n:a}function Io(e){let t=e.filter(a=>a.kind===O.TEXT),r=t.map(a=>a.startOffset),n=t.map(a=>a.endOffset);return{findRunBefore(a){let o=0,i=n.length-1,s=-1;for(;o<=i;){let l=o+i>>1;n[l]<=a?(s=l,o=l+1):i=l-1}return s>=0?t[s]:null},findRunAfter(a){let o=0,i=r.length-1,s=-1;for(;o<=i;){let l=o+i>>1;r[l]>=a?(s=l,i=l-1):o=l+1}return s>=0?t[s]:null}}}function Co(e){let t=0;return(r,n)=>{for(;t<e.length&&e[t].endOffset<=r;)t++;let a=e[t];return a&&a.startOffset<=r&&a.endOffset>=n?a:null}}function Ao(e){let t=new Set;for(let r of e)t.add(r.startOffset),t.add(r.endOffset);return Array.from(t).sort((r,n)=>r-n)}function Ro(e){let t=new Map,r=[],n=[];for(let a of e){if(a.type===ce.INSERT){t.has(a.startOffset)||t.set(a.startOffset,[]),t.get(a.startOffset).push(a),n.push(a);continue}r.push(a)}return r.sort((a,o)=>a.startOffset-o.startOffset||a.endOffset-o.endOffset),n.sort((a,o)=>a.startOffset-o.startOffset||a.endOffset-o.endOffset),{insertOpsByStartOffset:t,nonInsertOps:r,sortedInsertOps:n}}var xn="http://schemas.openxmlformats.org/wordprocessingml/2006/main",Oo="http://schemas.openxmlformats.org/officeDocument/2006/relationships",ko="http://schemas.microsoft.com/office/2006/xmlPackage",hn="http://schemas.openxmlformats.org/package/2006/relationships",Mo='<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>',wn='<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/>';var Lo=`
13
+ <w:numbering xmlns:w="${xn}">
14
14
  <w:abstractNum w:abstractNumId="0">
15
15
  <w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText w:val="&#8226;"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr></w:lvl>
16
16
  </w:abstractNum>
@@ -19,23 +19,23 @@ var sa=Object.create;var Pr=Object.defineProperty;var la=Object.getOwnPropertyDe
19
19
  </w:abstractNum>
20
20
  <w:num w:numId="1"><w:abstractNumId w:val="0"/></w:num>
21
21
  <w:num w:numId="2"><w:abstractNumId w:val="1"/></w:num>
22
- </w:numbering>`.trim();function Ka(e){return e?e.replace(/<\?xml[^>]*\?>/g,""):""}function Kr(e,t=!0){let r=t?` xmlns:r="${Ua}"`:"";return`<w:document xmlns:w="${Vr}"${r}><w:body>${e}</w:body></w:document>`}function Gr(e){return`
22
+ </w:numbering>`.trim();function _o(e){return e?e.replace(/<\?xml[^>]*\?>/g,""):""}function Nn(e,t=!0){let r=t?` xmlns:r="${Oo}"`:"";return`<w:document xmlns:w="${xn}"${r}><w:body>${e}</w:body></w:document>`}function bn(e){return`
23
23
  <pkg:part pkg:name="/word/numbering.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml">
24
24
  <pkg:xmlData>
25
- ${Ka(e)}
25
+ ${_o(e)}
26
26
  </pkg:xmlData>
27
- </pkg:part>`}function Zr(e,t="",r=""){return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
28
- <pkg:package xmlns:pkg="${ja}">
27
+ </pkg:part>`}function vn(e,t="",r=""){return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
28
+ <pkg:package xmlns:pkg="${ko}">
29
29
  <pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml">
30
30
  <pkg:xmlData>
31
- <Relationships xmlns="${Ur}">
32
- ${Ga}
31
+ <Relationships xmlns="${hn}">
32
+ ${Mo}
33
33
  </Relationships>
34
34
  </pkg:xmlData>
35
35
  </pkg:part>
36
36
  <pkg:part pkg:name="/word/_rels/document.xml.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml">
37
37
  <pkg:xmlData>
38
- <Relationships xmlns="${Ur}">
38
+ <Relationships xmlns="${hn}">
39
39
  ${t}
40
40
  </Relationships>
41
41
  </pkg:xmlData>
@@ -45,7 +45,7 @@ var sa=Object.create;var Pr=Object.defineProperty;var la=Object.getOwnPropertyDe
45
45
  ${e}
46
46
  </pkg:xmlData>
47
47
  </pkg:part>
48
- </pkg:package>`}function Yr(e,t={}){let{includeNumbering:r=!1,numberingXml:n=null,appendTrailingParagraph:a=!0}=t,i=a?`${e}<w:p><w:pPr></w:pPr></w:p>`:e,o=Kr(i,!0),s="",l="";return n?(s=jr,l+=Gr(n)):r&&(s=jr,l+=Gr(Va)),Zr(o,s,l)}function Jr(e){let t=Kr(e,!0);return Zr(t)}var Za=/\s+xmlns:[^=]+="[^"]*"/g;function oe(e,t,r=[],n={}){let a=Ya(n),{author:i,generateRedlines:o}=a,s=[],l="",c=null,u=[];function m(){if(u.length>0||s.length===0){let f="";l?f=Re(l):c?(l=Re(j(c)),f=l):t&&(typeof t=="string"?f=t:f=j(t),f=Re(f)),s.push(`<w:p>${f}${u.join("")}</w:p>`),u=[]}}for(let f of e)switch(f.kind){case R.PARAGRAPH_START:(u.length>0||s.length>0)&&m(),l=f.pPrXml||"",c=f.pPrElement||null;break;case R.TEXT:u.push(qr(f,r,a));break;case R.DELETION:o&&u.push(Ja(f,a));break;case R.INSERTION:o?u.push(qa(f,r,a)):u.push(qr(f,r,a));break;case R.BOOKMARK:case R.HYPERLINK:f.nodeXml&&u.push(Re(f.nodeXml));break;case R.CONTAINER_START:if(f.containerKind==="sdt")u.push(`<w:sdt>${f.propertiesXml}<w:sdtContent>`);else if(f.containerKind==="smartTag")u.push(`<w:smartTag ${f.propertiesXml}>`);else if(f.containerKind==="hyperlink"){let p=JSON.parse(f.propertiesXml),g=p.rId?` r:id="${p.rId}"`:"",d=p.anchor?` w:anchor="${p.anchor}"`:"";u.push(`<w:hyperlink${g}${d}>`)}break;case R.CONTAINER_END:f.containerKind==="sdt"?u.push("</w:sdtContent></w:sdt>"):f.containerKind==="smartTag"?u.push("</w:smartTag>"):f.containerKind==="hyperlink"&&u.push("</w:hyperlink>");break;default:Ce("Unknown run kind:",f.kind)}return m(),s.join("")}function Ya(e){if(typeof e=="string")return{author:G(),generateRedlines:!0,font:e};let t=e&&typeof e=="object"?e:{};return{author:typeof t.author=="string"&&t.author.trim()?t.author.trim():G(),generateRedlines:t.generateRedlines??!0,font:t.font??null}}function qr(e,t,r={}){let n=be(t,e.startOffset,e.endOffset),a=r?.font??null,i=e.rPrXml?Re(e.rPrXml):"";if(a&&(i=Yt(i,a)),n.length===0)return ve(e.text,i);let o=[],s=0,l=e.text,c=e.startOffset;for(let u of n){let m=Math.max(0,u.start-c),f=Math.min(l.length,u.end-c);m>s&&o.push(ve(l.slice(s,m),i));let p=Qr(i,u.format);o.push(ve(l.slice(m,f),p)),s=f}return s<l.length&&o.push(ve(l.slice(s),i)),o.join("")}function ve(e,t){return e?`<w:r>${t||""}<w:t xml:space="preserve">${ee(e)}</w:t></w:r>`:""}function Ja(e,t={}){let r=me(t.author??G()),n=t.font??null,a=e.rPrXml?Re(e.rPrXml):"";return n&&(a=Yt(a,n)),`<w:del w:id="${r.id}" w:author="${ee(r.author)}" w:date="${r.date}"><w:r>${a}<w:delText xml:space="preserve">${ee(e.text)}</w:delText></w:r></w:del>`}function qa(e,t,r={}){let n=me(r.author??G()),a=r.font??null,i=be(t,e.startOffset,e.endOffset),o="",s=e.rPrXml?Re(e.rPrXml):"";if(a&&(s=Yt(s,a)),i.length===0)o=ve(e.text,s);else{let l=0,c=e.text,u=e.startOffset;for(let m of i){let f=Math.max(0,m.start-u),p=Math.min(c.length,m.end-u);f>l&&(o+=ve(c.slice(l,f),s));let g=Qr(s,m.format);o+=ve(c.slice(f,p),g),l=p}l<c.length&&(o+=ve(c.slice(l),s))}return`<w:ins w:id="${n.id}" w:author="${ee(n.author)}" w:date="${n.date}">`+o+"</w:ins>"}function Yt(e,t){if(!t)return e;let r="";return e&&(r=e.replace(/<\/?w:rPr[^>]*>/g,"")),r.includes("<w:rFonts")?r=r.replace(/<w:rFonts[^>]*\/>/,`<w:rFonts w:ascii="${t}" w:hAnsi="${t}"/>`):r=`<w:rFonts w:ascii="${t}" w:hAnsi="${t}"/>`+r,`<w:rPr>${r}</w:rPr>`}function Qr(e,t){if(!t||Object.keys(t).length===0)return e;let r="";return e&&(r=e.replace(/<\/?w:rPr[^>]*>/g,"")),t.bold&&!r.includes("<w:b")&&(r="<w:b/>"+r),t.italic&&!r.includes("<w:i")&&(r="<w:i/>"+r),t.underline&&!r.includes("<w:u")&&(r='<w:u w:val="single"/>'+r),t.strikethrough&&!r.includes("<w:strike")&&(r="<w:strike/>"+r),`<w:rPr>${r}</w:rPr>`}function Te(e,t={}){let r=Qa(t);return Yr(e,r)}function Qa(e){return typeof e=="boolean"?{includeNumbering:e}:!e||typeof e!="object"?{}:{includeNumbering:e.includeNumbering??!1,numberingXml:e.numberingXml??null,appendTrailingParagraph:e.appendTrailingParagraph??!0}}function Re(e){return e?e.replace(Za,""):""}var et=class{constructor(){this.contextMap=new Map,this.nextNumId=1e3,this.customConfigs=[]}registerExistingNumId(t,r){this.contextMap.set(t,r)}getOrCreateNumId(t,r=null){let n=t.type||B.BULLET;if(r&&r.numId&&(r.type===n||r.type==="unknown"))return r.numId;if(this.contextMap.has(n))return this.contextMap.get(n);if(n===B.OUTLINE)return"3";if(n===B.DECIMAL)return"2";if(n===B.BULLET)return"1";if((r?parseInt(r.ilvl||"0"):0)===0&&n!==B.DECIMAL&&n!==B.BULLET){let i=`custom_${n}`;if(this.contextMap.has(i))return this.contextMap.get(i);let o=String(this.nextNumId++);return this.customConfigs.push({numId:o,levels:[{format:n,suffix:t.suffix||K.PERIOD}]}),this.contextMap.set(i,o),o}return"2"}detectNumberingFormat(t){let r=(t||"").trim();if(!r)return{format:B.BULLET,suffix:K.NONE,depth:0};if(/^[-*•]$/.test(r))return{format:B.BULLET,suffix:K.NONE,depth:0};let n=r.match(/^(\d+(?:\.\d+)+)\.?$/);if(n){let a=n[1].split(".").length-1;return{format:B.OUTLINE,suffix:K.PERIOD,depth:a}}return/^\([a-z]\)$/.test(r)?{format:B.LOWER_ALPHA,suffix:K.PAREN_BOTH,depth:0}:/^\([ivxlc]+\)$/i.test(r)?{format:r===r.toLowerCase()?B.LOWER_ROMAN:B.UPPER_ROMAN,suffix:K.PAREN_BOTH,depth:0}:/^\(\d+\)$/.test(r)?{format:B.DECIMAL,suffix:K.PAREN_BOTH,depth:0}:/^\d+\.$/.test(r)?{format:B.DECIMAL,suffix:K.PERIOD,depth:0}:/^[a-z]\.$/.test(r)?{format:B.LOWER_ALPHA,suffix:K.PERIOD,depth:0}:/^[A-Z]\.$/.test(r)?{format:B.UPPER_ALPHA,suffix:K.PERIOD,depth:0}:/^[ivxlc]+\.$/i.test(r)?{format:r===r.toLowerCase()?B.LOWER_ROMAN:B.UPPER_ROMAN,suffix:K.PERIOD,depth:0}:/^\d+/.test(r)?{format:B.DECIMAL,suffix:K.PERIOD,depth:0}:{format:B.BULLET,suffix:K.NONE,depth:0}}formatToOoxmlNumFmt(t){return{[B.DECIMAL]:"decimal",[B.LOWER_ALPHA]:"lowerLetter",[B.UPPER_ALPHA]:"upperLetter",[B.LOWER_ROMAN]:"lowerRoman",[B.UPPER_ROMAN]:"upperRoman",[B.BULLET]:"bullet",[B.OUTLINE]:"decimal"}[t]||"decimal"}suffixToOoxmlLevelText(t,r,n=0){if(t===B.BULLET)return"\u2022";let a=`%${n+1}`;if(t===B.OUTLINE)return Array(n+1).fill(0).map((i,o)=>`%${o+1}`).join(".")+".";switch(r){case K.PERIOD:return`${a}.`;case K.PAREN_RIGHT:return`${a})`;case K.PAREN_BOTH:return`(${a})`;default:return a}}buildListPPr(t,r,n={}){return`
48
+ </pkg:package>`}function Tn(e,t={}){let{includeNumbering:r=!1,numberingXml:n=null,appendTrailingParagraph:a=!0}=t,o=a?`${e}<w:p><w:pPr></w:pPr></w:p>`:e,i=Nn(o,!0),s="",l="";return n?(s=wn,l+=bn(n)):r&&(s=wn,l+=bn(Lo)),vn(i,s,l)}function yn(e){let t=Nn(e,!0);return vn(t)}var Bo=/\s+xmlns:[^=]+="[^"]*"/g;function fe(e,t,r=[],n={}){let a=Fo(n),{author:o,generateRedlines:i}=a,s=[],l="",c=null,u=[];function m(){if(u.length>0||s.length===0){let f="";l?f=Le(l):c?(l=Le(K(c)),f=l):t&&(typeof t=="string"?f=t:f=K(t),f=Le(f)),s.push(`<w:p>${f}${u.join("")}</w:p>`),u=[]}}for(let f of e)switch(f.kind){case O.PARAGRAPH_START:(u.length>0||s.length>0)&&m(),l=f.pPrXml||"",c=f.pPrElement||null;break;case O.TEXT:u.push(En(f,r,a));break;case O.DELETION:i&&u.push($o(f,a));break;case O.INSERTION:i?u.push(Xo(f,r,a)):u.push(En(f,r,a));break;case O.BOOKMARK:case O.HYPERLINK:f.nodeXml&&u.push(Le(f.nodeXml));break;case O.CONTAINER_START:if(f.containerKind==="sdt")u.push(`<w:sdt>${f.propertiesXml}<w:sdtContent>`);else if(f.containerKind==="smartTag")u.push(`<w:smartTag ${f.propertiesXml}>`);else if(f.containerKind==="hyperlink"){let p=JSON.parse(f.propertiesXml),g=p.rId?` r:id="${p.rId}"`:"",d=p.anchor?` w:anchor="${p.anchor}"`:"";u.push(`<w:hyperlink${g}${d}>`)}break;case O.CONTAINER_END:f.containerKind==="sdt"?u.push("</w:sdtContent></w:sdt>"):f.containerKind==="smartTag"?u.push("</w:smartTag>"):f.containerKind==="hyperlink"&&u.push("</w:hyperlink>");break;default:ke("Unknown run kind:",f.kind)}return m(),s.join("")}function Fo(e){if(typeof e=="string")return{author:J(),generateRedlines:!0,font:e};let t=e&&typeof e=="object"?e:{};return{author:typeof t.author=="string"&&t.author.trim()?t.author.trim():J(),generateRedlines:t.generateRedlines??!0,font:t.font??null}}function En(e,t,r={}){let n=we(t,e.startOffset,e.endOffset),a=r?.font??null,o=e.rPrXml?Le(e.rPrXml):"";if(a&&(o=wr(o,a)),n.length===0)return Se(e.text,o);let i=[],s=0,l=e.text,c=e.startOffset;for(let u of n){let m=Math.max(0,u.start-c),f=Math.min(l.length,u.end-c);m>s&&i.push(Se(l.slice(s,m),o));let p=Pn(o,u.format);i.push(Se(l.slice(m,f),p)),s=f}return s<l.length&&i.push(Se(l.slice(s),o)),i.join("")}function Se(e,t){return e?`<w:r>${t||""}<w:t xml:space="preserve">${oe(e)}</w:t></w:r>`:""}function $o(e,t={}){let r=ee(t.author??J()),n=t.font??null,a=e.rPrXml?Le(e.rPrXml):"";return n&&(a=wr(a,n)),`<w:del w:id="${r.id}" w:author="${oe(r.author)}" w:date="${r.date}"><w:r>${a}<w:delText xml:space="preserve">${oe(e.text)}</w:delText></w:r></w:del>`}function Xo(e,t,r={}){let n=ee(r.author??J()),a=r.font??null,o=we(t,e.startOffset,e.endOffset),i="",s=e.rPrXml?Le(e.rPrXml):"";if(a&&(s=wr(s,a)),o.length===0)i=Se(e.text,s);else{let l=0,c=e.text,u=e.startOffset;for(let m of o){let f=Math.max(0,m.start-u),p=Math.min(c.length,m.end-u);f>l&&(i+=Se(c.slice(l,f),s));let g=Pn(s,m.format);i+=Se(c.slice(f,p),g),l=p}l<c.length&&(i+=Se(c.slice(l),s))}return`<w:ins w:id="${n.id}" w:author="${oe(n.author)}" w:date="${n.date}">`+i+"</w:ins>"}function wr(e,t){if(!t)return e;let r="";return e&&(r=e.replace(/<\/?w:rPr[^>]*>/g,"")),r.includes("<w:rFonts")?r=r.replace(/<w:rFonts[^>]*\/>/,`<w:rFonts w:ascii="${t}" w:hAnsi="${t}"/>`):r=`<w:rFonts w:ascii="${t}" w:hAnsi="${t}"/>`+r,`<w:rPr>${r}</w:rPr>`}function Pn(e,t){if(!t||Object.keys(t).length===0)return e;let r="";return e&&(r=e.replace(/<\/?w:rPr[^>]*>/g,"")),t.bold&&!r.includes("<w:b")&&(r="<w:b/>"+r),t.italic&&!r.includes("<w:i")&&(r="<w:i/>"+r),t.underline&&!r.includes("<w:u")&&(r='<w:u w:val="single"/>'+r),t.strikethrough&&!r.includes("<w:strike")&&(r="<w:strike/>"+r),`<w:rPr>${r}</w:rPr>`}function Ie(e,t={}){let r=Do(t);return Tn(e,r)}function Do(e){return typeof e=="boolean"?{includeNumbering:e}:!e||typeof e!="object"?{}:{includeNumbering:e.includeNumbering??!1,numberingXml:e.numberingXml??null,appendTrailingParagraph:e.appendTrailingParagraph??!0}}function Le(e){return e?e.replace(Bo,""):""}var lt=class{constructor(){this.contextMap=new Map,this.nextNumId=1e3,this.customConfigs=[]}registerExistingNumId(t,r){this.contextMap.set(t,r)}getOrCreateNumId(t,r=null){let n=t.type||F.BULLET;if(r&&r.numId&&(r.type===n||r.type==="unknown"))return r.numId;if(this.contextMap.has(n))return this.contextMap.get(n);if(n===F.OUTLINE)return"3";if(n===F.DECIMAL)return"2";if(n===F.BULLET)return"1";if((r?parseInt(r.ilvl||"0"):0)===0&&n!==F.DECIMAL&&n!==F.BULLET){let o=`custom_${n}`;if(this.contextMap.has(o))return this.contextMap.get(o);let i=String(this.nextNumId++);return this.customConfigs.push({numId:i,levels:[{format:n,suffix:t.suffix||q.PERIOD}]}),this.contextMap.set(o,i),i}return"2"}detectNumberingFormat(t){let r=(t||"").trim();if(!r)return{format:F.BULLET,suffix:q.NONE,depth:0};if(/^[-*•]$/.test(r))return{format:F.BULLET,suffix:q.NONE,depth:0};let n=r.match(/^(\d+(?:\.\d+)+)\.?$/);if(n){let a=n[1].split(".").length-1;return{format:F.OUTLINE,suffix:q.PERIOD,depth:a}}return/^\([a-z]\)$/.test(r)?{format:F.LOWER_ALPHA,suffix:q.PAREN_BOTH,depth:0}:/^\([ivxlc]+\)$/i.test(r)?{format:r===r.toLowerCase()?F.LOWER_ROMAN:F.UPPER_ROMAN,suffix:q.PAREN_BOTH,depth:0}:/^\(\d+\)$/.test(r)?{format:F.DECIMAL,suffix:q.PAREN_BOTH,depth:0}:/^\d+\.$/.test(r)?{format:F.DECIMAL,suffix:q.PERIOD,depth:0}:/^[a-z]\.$/.test(r)?{format:F.LOWER_ALPHA,suffix:q.PERIOD,depth:0}:/^[A-Z]\.$/.test(r)?{format:F.UPPER_ALPHA,suffix:q.PERIOD,depth:0}:/^[ivxlc]+\.$/i.test(r)?{format:r===r.toLowerCase()?F.LOWER_ROMAN:F.UPPER_ROMAN,suffix:q.PERIOD,depth:0}:/^\d+/.test(r)?{format:F.DECIMAL,suffix:q.PERIOD,depth:0}:{format:F.BULLET,suffix:q.NONE,depth:0}}formatToOoxmlNumFmt(t){return{[F.DECIMAL]:"decimal",[F.LOWER_ALPHA]:"lowerLetter",[F.UPPER_ALPHA]:"upperLetter",[F.LOWER_ROMAN]:"lowerRoman",[F.UPPER_ROMAN]:"upperRoman",[F.BULLET]:"bullet",[F.OUTLINE]:"decimal"}[t]||"decimal"}suffixToOoxmlLevelText(t,r,n=0){if(t===F.BULLET)return"\u2022";let a=`%${n+1}`;if(t===F.OUTLINE)return Array(n+1).fill(0).map((o,i)=>`%${i+1}`).join(".")+".";switch(r){case q.PERIOD:return`${a}.`;case q.PAREN_RIGHT:return`${a})`;case q.PAREN_BOTH:return`(${a})`;default:return a}}buildListPPr(t,r,n={}){return`
49
49
  <w:pPr>${n.includeListParagraphStyle===!0?`
50
50
  <w:pStyle w:val="ListParagraph"/>`:""}
51
51
  <w:numPr>
@@ -72,7 +72,7 @@ var sa=Object.create;var Pr=Object.defineProperty;var la=Object.getOwnPropertyDe
72
72
  <w:lvl w:ilvl="2"><w:start w:val="1"/><w:numFmt w:val="lowerRoman"/><w:lvlText w:val="(%3)"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="2160" w:hanging="360"/></w:pPr></w:lvl>
73
73
  <w:lvl w:ilvl="3"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="(%4)"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="2880" w:hanging="360"/></w:pPr></w:lvl>
74
74
  <w:lvl w:ilvl="4"><w:start w:val="1"/><w:numFmt w:val="lowerLetter"/><w:lvlText w:val="%5."/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="3600" w:hanging="360"/></w:pPr></w:lvl>
75
- </w:abstractNum>`,i=`
75
+ </w:abstractNum>`,o=`
76
76
  <w:abstractNum w:abstractNumId="2">
77
77
  <w:multiLevelType w:val="multilevel"/>
78
78
  <w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1."/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr></w:lvl>
@@ -80,7 +80,7 @@ var sa=Object.create;var Pr=Object.defineProperty;var la=Object.getOwnPropertyDe
80
80
  <w:lvl w:ilvl="2"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1.%2.%3"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="2160" w:hanging="360"/></w:pPr></w:lvl>
81
81
  <w:lvl w:ilvl="3"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1.%2.%3.%4"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="2880" w:hanging="360"/></w:pPr></w:lvl>
82
82
  <w:lvl w:ilvl="4"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1.%2.%3.%4.%5"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="3600" w:hanging="360"/></w:pPr></w:lvl>
83
- </w:abstractNum>`,o="",s="";return r.forEach((l,c)=>{let u=10+c;o+=`
83
+ </w:abstractNum>`,i="",s="";return r.forEach((l,c)=>{let u=10+c;i+=`
84
84
  <w:abstractNum w:abstractNumId="${u}">
85
85
  <w:multiLevelType w:val="multilevel"/>
86
86
  ${l.levels.map((m,f)=>`
@@ -98,8 +98,8 @@ var sa=Object.create;var Pr=Object.defineProperty;var la=Object.getOwnPropertyDe
98
98
  <w:numbering xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
99
99
  ${n}
100
100
  ${a}
101
- ${i}
102
101
  ${o}
102
+ ${i}
103
103
  <w:num w:numId="1">
104
104
  <w:abstractNumId w:val="0"/>
105
105
  </w:num>
@@ -110,7 +110,7 @@ var sa=Object.create;var Pr=Object.defineProperty;var la=Object.getOwnPropertyDe
110
110
  <w:abstractNumId w:val="2"/>
111
111
  </w:num>
112
112
  ${s}
113
- </w:numbering>`}};function ke(e,t={}){let{generateRedlines:r=!1,author:n="AI"}=t,a=ie(),i=r?Ne():null,o=e.headers?.length||e.rows?.[0]?.length||1,s=`
113
+ </w:numbering>`}};function _e(e,t={}){let{generateRedlines:r=!1,author:n="AI"}=t,a=r?ee(n):null,o=e.headers?.length||e.rows?.[0]?.length||1,i=`
114
114
  <w:tblPr>
115
115
  <w:tblW w:w="5000" w:type="pct"/>
116
116
  <w:tblBorders>
@@ -123,38 +123,42 @@ var sa=Object.create;var Pr=Object.defineProperty;var la=Object.getOwnPropertyDe
123
123
  </w:tblBorders>
124
124
  <w:tblLook w:val="04A0" w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="1"/>
125
125
  </w:tblPr>
126
- `.trim(),c=`<w:tblGrid>${Array(o).fill("<w:gridCol/>").join("")}</w:tblGrid>`,u=e.hasHeader?[e.headers,...e.rows]:e.rows,m="";for(let p=0;p<u.length;p++){let g=e.hasHeader&&p===0,d=u[p]||[],w="";for(let x=0;x<o;x++){let v=d[x]||"",{cleanText:T,formatHints:N}=q(v),E=[{kind:r?R.INSERTION:R.TEXT,text:T,rPrXml:g?"<w:rPr><w:b/></w:rPr>":"",author:n,startOffset:0,endOffset:T.length}],b=oe(E,null,N,{author:n,generateRedlines:r});w+=`<w:tc><w:tcPr><w:tcW w:w="0" w:type="auto"/></w:tcPr>${b}</w:tc>`}m+=`<w:tr><w:trPr/>${w}</w:tr>`}let f=`<w:tbl>${s}${c}${m}</w:tbl>`;return r&&i&&(f=`<w:ins w:id="${i}" w:author="${ee(n)}" w:date="${a}">${f}</w:ins>`),f}function en(e,t){let r=[],{headers:n,rows:a,hasHeader:i}=t,o=i?[n,...a]:a,s=Math.max(e.rowCount,o.length);for(let l=0;l<s;l++){if(l>=e.rowCount&&o[l]){r.push({type:"row_insert",gridRow:l,cells:o[l]});continue}if(l<e.rowCount&&!o[l]){r.push({type:"row_delete",gridRow:l});continue}let c=o[l];for(let u=0;u<e.colCount;u++){let m=e.grid[l]?.[u],f=c?.[u];m&&(m.isMergeContinuation||u>m.gridCol||f!==void 0&&m.getText()!==f&&r.push({type:"cell_modify",gridRow:l,gridCol:u,originalCell:m,newText:f}))}}return r}function tn(e,t,r){let{generateRedlines:n,author:a}=r,i=ei(t),o="";for(let l=0;l<e.rowCount;l++){let c=i.rowDeleteByRow.get(l)||null;if(c&&!n)continue;let u="",m=0;for(;m<e.colCount;){let p=e.grid[l][m];if(!p){m++;continue}if(p.isMergeContinuation){m++;continue}let g=i.cellModifyByCoordinate.get(`${l}:${m}`)||null,d;g?d=ti(p,g.newText,r):d=ri(p.blocks),u+=ni(p,d,r),m+=p.colSpan}let f=e.trPrList[l]||"<w:trPr/>";if(c&&n){let p=me(a),g=`<w:del w:id="${p.id}" w:author="${ee(p.author)}" w:date="${p.date}"/>`;f.includes("</w:trPr>")?f=f.replace("</w:trPr>",`${g}</w:trPr>`):f=`<w:trPr>${g}</w:trPr>`}o+=`<w:tr>${f}${u}</w:tr>`}let s=i.rowInsertOperations;for(let l of s){let c="",u=n?me(a):null;for(let f of l.cells){let{cleanText:p,formatHints:g}=q(f),d=[{kind:n?R.INSERTION:R.TEXT,text:p,rPrXml:"",author:a,startOffset:0,endOffset:p.length}],w=oe(d,null,g,{author:a,generateRedlines:n});c+=`<w:tc><w:tcPr><w:tcW w:w="0" w:type="auto"/></w:tcPr>${w}</w:tc>`}let m="<w:trPr/>";n&&(m=`<w:trPr><w:ins w:id="${u.id}" w:author="${ee(u.author)}" w:date="${u.date}"/></w:trPr>`),o+=`<w:tr>${m}${c}</w:tr>`}return`
126
+ `.trim(),l=`<w:tblGrid>${Array(o).fill("<w:gridCol/>").join("")}</w:tblGrid>`,c=e.hasHeader?[e.headers,...e.rows]:e.rows,u="";for(let f=0;f<c.length;f++){let p=e.hasHeader&&f===0,g=c[f]||[],d="";for(let h=0;h<o;h++){let b=g[h]||"",{cleanText:x,formatHints:E}=ne(b),v=[{kind:r?O.INSERTION:O.TEXT,text:x,rPrXml:p?"<w:rPr><w:b/></w:rPr>":"",author:n,startOffset:0,endOffset:x.length}],P=fe(v,null,E,{author:n,generateRedlines:r});d+=`<w:tc><w:tcPr><w:tcW w:w="0" w:type="auto"/></w:tcPr>${P}</w:tc>`}u+=`<w:tr><w:trPr/>${d}</w:tr>`}let m=`<w:tbl>${i}${l}${u}</w:tbl>`;return a&&(m=`<w:ins w:id="${a.id}" w:author="${oe(a.author)}" w:date="${a.date}">${m}</w:ins>`),m}function Sn(e,t){let r=[],{headers:n,rows:a,hasHeader:o}=t,i=o?[n,...a]:a,s=Math.max(e.rowCount,i.length);for(let l=0;l<s;l++){if(l>=e.rowCount&&i[l]){r.push({type:"row_insert",gridRow:l,cells:i[l]});continue}if(l<e.rowCount&&!i[l]){r.push({type:"row_delete",gridRow:l});continue}let c=i[l];for(let u=0;u<e.colCount;u++){let m=e.grid[l]?.[u],f=c?.[u];m&&(m.isMergeContinuation||u>m.gridCol||f!==void 0&&m.getText()!==f&&r.push({type:"cell_modify",gridRow:l,gridCol:u,originalCell:m,newText:f}))}}return r}function In(e,t,r){let{generateRedlines:n,author:a}=r,o=zo(t),i="";for(let l=0;l<e.rowCount;l++){let c=o.rowDeleteByRow.get(l)||null;if(c&&!n)continue;let u="",m=0;for(;m<e.colCount;){let p=e.grid[l][m];if(!p){m++;continue}if(p.isMergeContinuation){m++;continue}let g=o.cellModifyByCoordinate.get(`${l}:${m}`)||null,d;g?d=Wo(p,g.newText,r):d=Ho(p.blocks),u+=Uo(p,d,r),m+=p.colSpan}let f=e.trPrList[l]||"<w:trPr/>";if(c&&n){let p=ee(a),g=`<w:del w:id="${p.id}" w:author="${oe(p.author)}" w:date="${p.date}"/>`;f.includes("</w:trPr>")?f=f.replace("</w:trPr>",`${g}</w:trPr>`):f=`<w:trPr>${g}</w:trPr>`}i+=`<w:tr>${f}${u}</w:tr>`}let s=o.rowInsertOperations;for(let l of s){let c="",u=n?ee(a):null;for(let f of l.cells){let{cleanText:p,formatHints:g}=ne(f),d=[{kind:n?O.INSERTION:O.TEXT,text:p,rPrXml:"",author:a,startOffset:0,endOffset:p.length}],w=fe(d,null,g,{author:a,generateRedlines:n});c+=`<w:tc><w:tcPr><w:tcW w:w="0" w:type="auto"/></w:tcPr>${w}</w:tc>`}let m="<w:trPr/>";n&&(m=`<w:trPr><w:ins w:id="${u.id}" w:author="${oe(u.author)}" w:date="${u.date}"/></w:trPr>`),i+=`<w:tr>${m}${c}</w:tr>`}return`
127
127
  <w:tbl>
128
128
  ${e.tblPrXml}
129
129
  ${e.tblGridXml}
130
- ${o}
130
+ ${i}
131
131
  </w:tbl>
132
- `}function ei(e){let t=new Map,r=new Map,n=[];for(let a of e)a.type==="row_delete"?t.set(a.gridRow,a):a.type==="cell_modify"?r.set(`${a.gridRow}:${a.gridCol}`,a):a.type==="row_insert"&&n.push(a);return n.sort((a,i)=>a.gridRow-i.gridRow),{rowDeleteByRow:t,cellModifyByCoordinate:r,rowInsertOperations:n}}function ti(e,t,r){let{generateRedlines:n,author:a}=r,{cleanText:i,formatHints:o}=q(t),s=e.getText(),l=xt(s,i),c=e.blocks[0]||{runModel:[],pPr:null},u=Nt(c.runModel,l),m=vt(u,l,{generateRedlines:n,author:a,formatHints:o});return oe(m,c.pPr,o,{author:a,generateRedlines:n})}function ri(e){return e.map(t=>oe(t.runModel,t.pPr,[],{})).join("")}function ni(e,t,r){let n=e.tcPrXml;return e.colSpan>1&&!n.includes("gridSpan")?n=n.replace("</w:tcPr>",`<w:gridSpan w:val="${e.colSpan}"/></w:tcPr>`):e.colSpan>1&&n==="<w:tcPr/>"&&(n=`<w:tcPr><w:gridSpan w:val="${e.colSpan}"/></w:tcPr>`),e.rowSpan>1&&e.isMergeOrigin&&!n.includes("vMerge")?n=n.replace("</w:tcPr>",'<w:vMerge w:val="restart"/></w:tcPr>'):e.rowSpan>1&&e.isMergeOrigin&&n==="<w:tcPr/>"&&(n='<w:tcPr><w:vMerge w:val="restart"/></w:tcPr>'),`<w:tc>${n}${t}</w:tc>`}function se(e){let t=e.split(`
133
- `).map(o=>o.trim()).filter(o=>o.startsWith("|"));if(t.length===0)return{headers:[],rows:[],hasHeader:!1};let r=o=>{let s=o.replace(/\s+/g,"");return/^\|:?-{3,}:?(\|:?-{3,}:?)+\|?$/.test(s)},n=t.some(r),i=t.filter(o=>!r(o)).map(o=>o.split("|").slice(1,-1).map(s=>s.trim()));return n?{headers:i[0]||[],rows:i.slice(1),hasHeader:!0}:{headers:[],rows:i,hasHeader:!1}}async function rn(e){let{cleanText:t,numberingContext:r,originalRunModel:n=[],originalText:a="",generateRedlines:i=!0,author:o="AI",font:s=null,numberingService:l}=e,c=ii(t),u=ai(c),m=u.map(N=>N.raw),f=[],p=[];if(i){if(n&&n.length>0)p=n.filter(N=>N.kind==="text"||N.kind==="run").map(N=>({...N,kind:"deletion",author:o}));else if(a&&a.trim().length>0){let N=a.trim();p=[{kind:"deletion",text:N,author:o,startOffset:0,endOffset:N.length}]}}let g=Jt(m);C(`[ListGen] Detected indentation step: ${g} spaces/chars`);let d=u.find(N=>N.marker)?.marker||"",{format:w}=l.detectNumberingFormat(d);C(`[ListGen] Detected primary marker: "${d}", format: ${w}`);for(let N=0;N<u.length;N++){let E=oi(u,N);if(E){let P=se(E.tableText);if(P.headers.length>0||P.rows.length>0){i&&f.length===0&&p.length>0&&f.push(oe(p,null,[],{author:o,generateRedlines:i,font:s})),f.push(ke(P,{generateRedlines:i,author:o})),N=E.endIndex;continue}}let b=u[N],S=si(b,N,g,r,l,i,o,s,p);f.push(S.ooxml)}let h=l.generateNumberingXml(),T=f.join("")+"<w:p><w:pPr></w:pPr></w:p>";return C(`[ListGen] \u2705 Generated OOXML for ${f.length} list items, total length: ${T.length}`),C(`[ListGen] First 200 chars: ${T.substring(0,200)}...`),{ooxml:T,isValid:!0,warnings:["Paragraph expanded to list fragment"],type:"fragment",includeNumbering:!0,numberingXml:h}}function Jt(e){let t=e.map(n=>n.match(/^(\s*)/)[0].length).filter(n=>n>0).sort((n,a)=>n-a);if(t.length===0)return 2;let r=t[0];for(let n=1;n<t.length;n++){let a=t[n]-t[n-1];a>0&&a<r&&(r=a)}return r||2}function ai(e){return e.split(`
134
- `).filter(t=>t.trim().length>0).map(t=>{let r=fe(t),n=t.match(/^\s*(#{1,9})\s+(.*)/);return{raw:t,marker:r?r[2].trim():"",headerMatch:n,indentSize:t.match(/^(\s*)/)?.[1].length||0,isTableLine:/^\s*\|/.test(t),isTableSeparator:/^\s*\|?[\s:-]*-[-\s|:]*\|?\s*$/.test(t)}})}function ii(e){let t=String(e||"").split(`
135
- `),r=t.map((o,s)=>({line:o,index:s})).filter(o=>o.line.trim().length>0);if(r.length<2)return e;let n=[],a=0;for(let{line:o,index:s}of r){let l=fe(o);if(!l)return e;let c=xe(o),u=fe(c);if(!u)return e;let m=(l[2]||"").trim(),f=(u[2]||"").trim();if(!m||!f||m===f)return e;let g=`${l[1]||""}${c.trimStart()}`;n.push({index:s,rewritten:g}),a++}if(a<2)return e;let i=t.slice();for(let o of n)i[o.index]=o.rewritten;return C(`[ListGen] Normalized ${a} composite list markers (e.g., "- A." -> "A.").`),i.join(`
136
- `)}function oi(e,t){let r=e[t],n=e[t+1];if(!r?.isTableLine||!n?.isTableLine||!n?.isTableSeparator)return null;let a=[],i=t;for(;i<e.length&&e[i].isTableLine;)a.push(e[i].raw),i++;return{tableText:a.join(`
137
- `),endIndex:i-1}}function si(e,t,r,n,a,i,o,s,l){let c="",u="";if(e.headerMatch){let g=Math.min(e.headerMatch[1].length,9),d=Math.min(g-1,8),w=[32,28,26,24,22,20,20,20,20],h=w[g-1]||w[w.length-1];u=e.headerMatch[2].trim(),c=`<w:pPr><w:pStyle w:val="Heading${g}"/><w:outlineLvl w:val="${d}"/><w:rPr><w:b/><w:sz w:val="${h}"/><w:szCs w:val="${h}"/></w:rPr></w:pPr>`}else if(e.marker){let g=a.detectNumberingFormat(e.marker),d=r>0?Math.floor(e.indentSize/r):0,w=n?.ilvl||0,h=g.format==="outline"?Math.min(8,g.depth):Math.min(8,d+w);u=xe(e.raw);let x=a.getOrCreateNumId({type:g.format},n);c=a.buildListPPr(x,h)}else u=e.raw;let{cleanText:m,formatHints:f}=q(u),p=[];return t===0&&l.length>0&&p.push(...l),p.push({kind:i?"insertion":"run",text:m,author:o,startOffset:0,endOffset:m.length}),{ooxml:oe(p,c,f,{author:o,generateRedlines:i,font:s})}}var li=new Set(["officeonline","officeweb","web"]);function ci(e){return e?li.has(String(e).toLowerCase()):!1}function ui(){return typeof process<"u"&&process?.env?.NODE_ENV==="production"}function fi(){return new Promise(e=>setTimeout(e,0))}var Oe=class{constructor(t={}){this.generateRedlines=t.generateRedlines??!0,this.author=t.author??"AI",this.validateOutput=t.validateOutput??!0,this.validationMode=t.validationMode??"auto",this.numberingService=t.numberingService||new et,this.font=t.font||null,this.platform=t.platform??zt(),this.isWebPlatform=t.isWebPlatform??ci(this.platform),this.enableEventLoopYielding=t.enableEventLoopYielding??this.isWebPlatform,this.yieldRunThreshold=t.yieldRunThreshold??50,this.yieldCharThreshold=t.yieldCharThreshold??5e3,this.disableSemanticCleanupOverChars=t.disableSemanticCleanupOverChars??(this.isWebPlatform?8e3:Number.POSITIVE_INFINITY)}async execute(t,r,n={}){let a=[];try{let i=n.xmlDoc||_().parseFromString(t,"application/xml"),o=D(i,"*","p"),{runModel:s,acceptedText:l,pPr:c}=bt(t,{xmlDoc:i}),u=o?Vt(o):null;C(`[Reconcile] Ingested ${s.length} runs, ${l.length} chars, numbering:`,u),await this.maybeYield(s.length,Math.max(l.length,r?.length||0));let{cleanText:m,formatHints:f}=q(r);C(`[Reconcile] Preprocessed: ${f.length} format hints`),await this.maybeYield(s.length,Math.max(l.length,m.length));let p=kr(m),g=wt(m),d=p||g;if(!p&&g&&C("[Reconcile] List-target detected via loose marker parsing; bypassing no-op short-circuit for structural conversion."),l===m&&f.length===0&&!d)return C("[Reconcile] No changes detected"),{ooxml:t,isValid:!0,warnings:["No changes detected"]};let w=Math.max(l.length,m.length)<this.disableSemanticCleanupOverChars,h=xt(l,m,{cleanupSemantic:w});w||C("[Reconcile] Skipping semantic diff cleanup for large web payload"),await this.maybeYield(s.length,Math.max(l.length,m.length));let x=s.filter(E=>E.kind===R.PARAGRAPH_START).length;if(C(`[Reconcile] isTargetList: ${d}, paragraphCount: ${x}`),d)return C("[Reconcile] \u{1F3AF} ENTERING LIST GENERATION PATH"),C(`[Reconcile] cleanText preview: ${m.substring(0,100)}...`),C(`[Reconcile] acceptedText preview: ${l.substring(0,100)}...`),this.executeListGeneration(m,u,s);C(`[Reconcile] Computed ${h.length} diff operations`);let v=Nt(s,h);C(`[Reconcile] Split into ${v.length} runs`);let T=vt(v,h,{generateRedlines:this.generateRedlines,author:this.author,formatHints:f,numberingService:this.numberingService});C(`[Reconcile] Patched model has ${T.length} runs`),await this.maybeYield(T.length,Math.max(l.length,m.length));let N=oe(T,c,f,{author:this.author,generateRedlines:this.generateRedlines});if(this.shouldRunValidation()){let E=this.validateBasic(N);E.isValid||a.push(...E.errors)}return{ooxml:N,isValid:a.length===0,warnings:a}}catch(i){return V("[Reconcile] Pipeline error:",i),{ooxml:t,isValid:!1,warnings:[`Pipeline error: ${i.message}`]}}}validateBasic(t){let r=[];try{let n=`<root xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">${t}</root>`,i=_().parseFromString(n,"application/xml"),o=H(i);o&&r.push("Generated OOXML is not well-formed XML: "+o.textContent.substring(0,100)),t.includes("<w:p")||r.push("Generated OOXML missing paragraph element")}catch(n){r.push(`Validation error: ${n.message}`)}return{isValid:r.length===0,errors:r}}shouldRunValidation(){return this.validateOutput?this.validationMode==="always"?!0:this.validationMode==="never"?!1:!(this.isWebPlatform&&ui()):!1}async maybeYield(t,r){this.enableEventLoopYielding&&(t<=this.yieldRunThreshold&&r<=this.yieldCharThreshold||await fi())}wrapForInsertion(t,r={}){return Te(t,r)}async executeListGeneration(t,r,n,a=""){return rn({cleanText:t,numberingContext:r,originalRunModel:n,originalText:a,generateRedlines:this.generateRedlines,author:this.author,font:this.font,numberingService:this.numberingService})}detectIndentationStep(t){return Jt(t)}executeTableGeneration(t){let r=se(t);return r.rows.length===0&&r.headers.length===0?{ooxml:"",isValid:!1,warnings:["Could not parse Markdown table"]}:{ooxml:ke(r,{generateRedlines:this.generateRedlines,author:this.author}),isValid:!0,warnings:[],includeNumbering:!1}}};var tt=["w:rStyle","w:rFonts","w:b","w:bCs","w:i","w:iCs","w:caps","w:smallCaps","w:strike","w:dstrike","w:outline","w:shadow","w:emboss","w:imprint","w:noProof","w:snapToGrid","w:vanish","w:webHidden","w:color","w:spacing","w:w","w:kern","w:position","w:sz","w:szCs","w:highlight","w:u","w:effect","w:bdr","w:shd","w:fitText","w:vertAlign","w:rtl","w:cs","w:em","w:lang","w:eastAsianLayout","w:specVanish","w:oMath"];function De(e,t){let r=tt.indexOf(t.nodeName),n=r===-1?999:r,a=!1;for(let i of Array.from(e.childNodes)){if(i.nodeType!==1)continue;let o=tt.indexOf(i.nodeName);if((o===-1?999:o)>n){e.insertBefore(t,i),a=!0;break}}a||e.appendChild(t)}function mi(e,t,r,n){if(!t||!r)return;let a=!!r.bold,i=!!r.italic,o=!!r.underline,s=!!r.strikethrough,l=new Set;if(a&&(l.add("w:b"),l.add("w:bCs")),i&&(l.add("w:i"),l.add("w:iCs")),o&&l.add("w:u"),s&&l.add("w:strike"),l.size>0){let c=[];for(let u of Array.from(t.childNodes))l.has(u.nodeName)&&c.push(u);for(let u of c)t.removeChild(u)}if(a){let c=e.createElement("w:b");c.setAttribute("w:val",n==="add"?"1":"0"),De(t,c);let u=e.createElement("w:bCs");u.setAttribute("w:val",n==="add"?"1":"0"),De(t,u)}if(i){let c=e.createElement("w:i");c.setAttribute("w:val",n==="add"?"1":"0"),De(t,c);let u=e.createElement("w:iCs");u.setAttribute("w:val",n==="add"?"1":"0"),De(t,u)}if(o){let c=e.createElement("w:u");c.setAttribute("w:val",n==="add"?"single":"none"),De(t,c)}if(s){let c=e.createElement("w:strike");c.setAttribute("w:val",n==="add"?"1":"0"),De(t,c)}}function nn(e,t,r){mi(e,t,r,"remove")}function rt(e){let t={bold:!1,italic:!1,underline:!1,strikethrough:!1,hasFormatting:!1};if(!e)return t;for(let r of Array.from(e.childNodes))if(r.nodeName==="w:b"&&(t.bold=Tt(r,!1)),r.nodeName==="w:i"&&(t.italic=Tt(r,!1)),r.nodeName==="w:u"&&(t.underline=Tt(r,!0)),r.nodeName==="w:strike"&&(t.strikethrough=Tt(r,!1)),r.nodeName==="w:rStyle"){let n=r.getAttribute("w:val");if(n){let a=n.toLowerCase();(a.includes("bold")||a.includes("strong"))&&(t.bold=!0),(a.includes("italic")||a.includes("emphasis"))&&(t.italic=!0),a.includes("underline")&&(t.underline=!0)}}return t.hasFormatting=t.bold||t.italic||t.underline||t.strikethrough,t}function Tt(e,t){let n=(e.getAttribute("w:val")||e.getAttribute("val")||"").toLowerCase();return n?t?n!=="none"&&n!=="0"&&n!=="false"&&n!=="off":n!=="0"&&n!=="false"&&n!=="off":!0}var an="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function ue(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===an&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function pi(e){return!e||e.nodeType!==1||e.namespaceURI!==an?!1:e.localName==="del"||e.localName==="moveFrom"}function on(e){let t=[],r=Array.from(e?.childNodes||[]).reverse();for(;r.length>0;){let n=r.pop();if(!n||n.nodeType!==1||pi(n))continue;if(ue(n,"r")){t.push(n);continue}let a=Array.from(n.childNodes||[]);for(let i=a.length-1;i>=0;i-=1)r.push(a[i])}return t}function pe(e){let t=new Set(["comment","footnote","endnote"]);return z(e,"*","p").filter(n=>{let a=n.parentNode;for(;a&&a.nodeName;){let i=String(a.localName||"").toLowerCase();if(t.has(i))return!1;a=a.parentNode}return!0})}function sn(e){let t=[],r=0;for(let n=0;n<e.length;n++){let a=e[n],i=on(a);for(let o of i){let s=M(o,"w:rPr");Array.from(o.childNodes||[]).forEach(l=>{if(ue(l,"t")){let c=l.textContent||"";c.length>0&&(t.push({charStart:r,charEnd:r+c.length,textElement:l,runElement:o,paragraph:a,container:o.parentNode,rPr:s}),r+=c.length)}else(ue(l,"br")||ue(l,"cr")||ue(l,"tab")||ue(l,"noBreakHyphen"))&&(t.push({charStart:r,charEnd:r+1,textElement:l,runElement:o,paragraph:a,container:o.parentNode,rPr:s}),r+=1)})}r=Ae(r,n,e.length)}return{textSpans:t,charOffset:r}}function gi(e,t,r,n,a,i=null){let o=null;for(let c of Array.from(e.childNodes))if(ue(c,"rPr")){o=c;break}let s=rt(o);i&&(i.bold&&!s.bold&&(s.bold=!0),i.italic&&!s.italic&&(s.italic=!0),i.underline&&!s.underline&&(s.underline=!0),i.strikethrough&&!s.strikethrough&&(s.strikethrough=!0)),s.hasFormatting=s.bold||s.italic||s.underline||s.strikethrough;let l=r;for(let c of Array.from(e.childNodes))if(ue(c,"t")){let u=c.textContent||"";if(u.length>0){let m=l,f=l+u.length;n.push({charStart:m,charEnd:f,textElement:c,runElement:e,paragraph:t,rPr:o,format:{...s}}),s.hasFormatting&&a.push({start:m,end:f,format:{...s},run:e,rPr:o}),l=f}}return l}function ln(e){let t=[],r=[],n=0,a=pe(e);for(let i=0;i<a.length;i++){let o=a[i],s=null;for(let u of Array.from(o.childNodes))if(ue(u,"pPr")){for(let m of Array.from(u.childNodes))if(ue(m,"rPr")){s=m;break}break}let l=rt(s);l.hasFormatting&&C(`[OxmlEngine] Found paragraph-level formatting: ${JSON.stringify(l)}`);let c=on(o);for(let u of c)n=gi(u,o,n,r,t,l);n=Ae(n,i,a.length)}return C(`[OxmlEngine] Extracted ${r.length} text spans, ${t.length} format hints`),{existingFormatHints:t,textSpans:r,paragraphs:a}}function ye(e,t,r,n){let a=e.createElement(t==="ins"?"w:ins":"w:del"),i=me(n);return a.setAttribute("w:id",String(i.id)),a.setAttribute("w:author",i.author),a.setAttribute("w:date",i.date),r&&a.appendChild(r),a}function le(e,t,r,n){let a=e.createElement("w:r");r&&a.appendChild(r.cloneNode(!0));let i=e.createElement(n?"w:delText":"w:t");return i.setAttribute("xml:space","preserve"),i.textContent=t,a.appendChild(i),a}function yt(e,t,r,n,a,i,o){if(!t)return[];let s=new Set([0,t.length]);for(let u of n){let m=Math.max(0,u.start-a),f=Math.min(t.length,u.end-a);m>=0&&m<t.length&&s.add(m),f>0&&f<=t.length&&s.add(f)}let l=Array.from(s).sort((u,m)=>u-m),c=[];for(let u=0;u<l.length-1;u++){let m=l[u],f=l[u+1],p=t.slice(m,f);if(!p)continue;let g=a+m,d=a+f,w=n.filter(v=>v.start<=g&&v.end>=d),h={};w.forEach(v=>{v.format&&Object.assign(h,v.format)});let x=ze(e,r,h,i,o);c.push(qt(e,p,x,!1))}return c}function qt(e,t,r,n){let a=e.createElement("w:r");r&&a.appendChild(r);let i=e.createElement(n?"w:delText":"w:t");return i.setAttribute("xml:space","preserve"),i.textContent=t,a.appendChild(i),a}function ze(e,t,r,n,a){let i=e.createElement("w:rPr");t&&Array.from(t.childNodes).forEach(l=>{["w:b","w:bCs","w:i","w:iCs","w:u","w:strike","w:rPrChange"].includes(l.nodeName)||i.appendChild(l.cloneNode(!0))});let o=r||{bold:!1,italic:!1,underline:!1,strikethrough:!1};n&&a&&di(e,i,n,t);let s=(l,c,u=null,m="0")=>{let f=e.createElement(l);c?u&&f.setAttribute("w:val",u):m&&f.setAttribute("w:val",m);let p=tt.indexOf(l),g=p===-1?999:p,d=!1;for(let w of Array.from(i.childNodes)){if(w.nodeType!==1)continue;let h=tt.indexOf(w.nodeName);if((h===-1?999:h)>g){i.insertBefore(f,w),d=!0;break}}d||i.appendChild(f)};return s("w:b",!!o.bold,"1","0"),s("w:bCs",!!o.bold,"1","0"),s("w:i",!!o.italic,"1","0"),s("w:iCs",!!o.italic,"1","0"),s("w:u",!!o.underline,"single","none"),s("w:strike",!!o.strikethrough,"1","0"),i}function Qt(e,t,r,n,a){let i=e.createElement("w:rPrChange");i.setAttribute("w:id",String(me(r).id)),i.setAttribute("w:author",r),i.setAttribute("w:date",n);let o=e.createElement("w:rPr"),s=a||t;Array.from(s.childNodes).forEach(c=>{c.nodeName!=="w:rPrChange"&&o.appendChild(c.cloneNode(!0))}),i.appendChild(o);let l=M(t,"w:rPrChange");return l&&t.removeChild(l),t.appendChild(i),i}function di(e,t,r,n){Qt(e,t,r,ie(),n||t)}var hi="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function We(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===hi&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function Et(e,t,r){let n=new Map;for(let o of r)!o||!o.paragraph||(n.has(o.paragraph)||n.set(o.paragraph,[]),n.get(o.paragraph).push(o));let a=[],i=0;return t.forEach((o,s)=>{let l=(n.get(o)||[]).slice().sort((f,p)=>f.charStart-p.charStart),c=wi(l),u=er(c),m=u.trim();a.push({paragraph:o,spans:l,text:c,normalizedText:u,normalizedTrim:m,startOffset:i}),i+=u.length,i=Ae(i,s,t.length)}),a}function cn(e,t){if(!t)return null;let r=er(t),n=r.trim();if(!n)return null;for(let a of e)if(a.normalizedText===r)return a;for(let a of e)if(a.normalizedTrim===n)return a;return null}function un(e,t){let r=er(t),n=r.trim(),a=null,i=0;for(let o of e)if(o.normalizedText===r)return a=o,{targetInfo:a,matchOffset:i};if(n.length>0){for(let o of e)if(o.normalizedTrim===n)return a=o,{targetInfo:a,matchOffset:i}}if(n.length>0){let s=e.map(l=>l.normalizedText).join(`
138
- `).indexOf(n);if(s!==-1)for(let l of e){let c=l.startOffset,u=l.normalizedText.length;if(s>=c&&s<=c+u){a=l,i=s-c;break}}}if(!a&&e.length===1&&r.length>0){let o=e[0],s=o.normalizedTrim||"";if(s.length>0){let l=r.indexOf(s);l>=0&&(a=o,i=-l)}}return{targetInfo:a,matchOffset:i}}function fn(e){let t=e;for(;t;){if(We(t,"p"))return t;t=t.parentNode}return null}function wi(e){if(!e||e.length===0)return"";let t="";for(let r of e){if(!r||!r.textElement)continue;let n=r.textElement;We(n,"t")?t+=r.textElement.textContent||"":We(n,"tab")?t+=" ":We(n,"br")||We(n,"cr")?t+=`
139
- `:We(n,"noBreakHyphen")&&(t+="\u2011")}return t}function er(e){return e?e.replace(/\r/g,`
140
- `).replace(/\u00a0/g," "):""}function mn(e,t,r){let n=Array.from(new Set(r)).sort((s,l)=>s-l);if(n.length===0||t.length===0)return[...t];let a=[...t].sort((s,l)=>s.charStart-l.charStart||s.charEnd-l.charEnd),i=[],o=0;for(let s of a){for(;o<n.length&&n[o]<=s.charStart;)o++;let l=s;for(;o<n.length&&n[o]<l.charEnd;){let c=n[o],u=bi(e,l,c);if(!u){o++;continue}i.push(u[0]),l=u[1],o++}i.push(l)}return i}function bi(e,t,r){let n=t.runElement,a=n.parentNode;if(!a)return null;let i=t.textElement.textContent||"",o=r-t.charStart,s=i.substring(0,o),l=i.substring(o);if(s.length===0||l.length===0)return null;let c=le(e,s,t.rPr,!1),u=le(e,l,t.rPr,!1);a.insertBefore(c,n),a.insertBefore(u,n),a.removeChild(n);let m=c.getElementsByTagName("w:t")[0],f=u.getElementsByTagName("w:t")[0];return[{...t,charEnd:r,textElement:m,runElement:c},{...t,charStart:r,textElement:f,runElement:u}]}var xi="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function Ni(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===xi&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function vi(e){return Array.isArray(e)?{textSpans:e,paragraphs:null,paragraphInfos:null}:!e||typeof e!="object"?{textSpans:null,paragraphs:null,paragraphInfos:null}:{textSpans:Array.isArray(e.textSpans)?e.textSpans:null,paragraphs:Array.isArray(e.paragraphs)?e.paragraphs:null,paragraphInfos:Array.isArray(e.paragraphInfos)?e.paragraphInfos:null}}function pn(e,t,r,n,a,i=!0){let o=!1,s=new Set,l=ie();C(`[OxmlEngine] Surgical format removal: ${r.length} hints to process (using w:rPrChange)`);for(let c of r){let u=c.run;if(s.has(u)||(s.add(u),!u.parentNode))continue;C("[OxmlEngine] Processing run for surgical format removal, format:",c.format);let m=M(u,"w:rPr");m||(m=e.createElement("w:rPr"),u.insertBefore(m,u.firstChild)),i&&Qt(e,m,a||G(),l),nn(e,m,c.format),o=!0}return o?(C("[OxmlEngine] Surgical format removal completed successfully (Pure Format Mode)"),{oxml:n.serializeToString(e),hasChanges:!0}):(C("[OxmlEngine] No format changes were applied"),{oxml:n.serializeToString(e),hasChanges:!1})}function Ti(e,t,r,n,a,i=!0){let o=!1,s=new Set;if(!t||t.length===0)return{oxml:n.serializeToString(e),hasChanges:!1};let l=[];for(let f of r)l.push(f.start,f.end);let u=mn(e,t,l).slice().sort((f,p)=>f.charStart-p.charStart||f.charEnd-p.charEnd),m=yi(r);for(let f of u){if(!f||!f.textElement||!Ni(f.textElement,"t"))continue;let p=m(f.charStart,f.charEnd);if(p.length===0)continue;let g=Wt(...p.map(A=>A.format)),d={bold:!!g.bold,italic:!!g.italic,underline:!!g.underline,strikethrough:!!g.strikethrough},w=f.format||rt(f.rPr),h={bold:!!w.bold,italic:!!w.italic,underline:!!w.underline,strikethrough:!!w.strikethrough};if(!["bold","italic","underline","strikethrough"].some(A=>d[A]!==h[A])||s.has(f.runElement)||(s.add(f.runElement),!(f.textElement.textContent||""))||!f.runElement.parentNode)continue;let E=f.runElement,b=M(E,"w:rPr"),S=ze(e,b,d,a||G(),i),P=b;if(!P)E.insertBefore(S,E.firstChild);else{for(;P.firstChild;)P.removeChild(P.firstChild);Array.from(S.childNodes).forEach(A=>P.appendChild(A))}o=!0}return{oxml:n.serializeToString(e),hasChanges:o}}function gn(e,t,r,n,a,i=!0,o=null){let s=vi(o),l=s.paragraphs||pe(e),c=s.textSpans||[];if(s.textSpans||({textSpans:c}=sn(l)),!c||c.length===0)return Ce("[OxmlEngine] No spans available for surgical format-only change; requesting caller fallback strategy"),{hasChanges:!0,useNativeApi:!0,formatHints:r,originalText:t};if(!r||r.length===0)return{oxml:n.serializeToString(e),hasChanges:!1};let u=s.paragraphInfos||Et(e,l,c),{targetInfo:m,matchOffset:f}=un(u,t);if(!m||!m.spans||m.spans.length===0)return Ce("[OxmlEngine] Unable to pinpoint target paragraph for surgical format-only change; requesting caller fallback strategy"),{hasChanges:!0,useNativeApi:!0,formatHints:r,originalText:t};let p=m.spans[0].charStart,g=m.spans.map(w=>({...w,charStart:w.charStart-p,charEnd:w.charEnd-p})),d=r.map(w=>({...w,start:w.start+f,end:w.end+f}));return Ti(e,g,d,n,a,i)}function yi(e){let t=(e||[]).slice().sort((a,i)=>a.start-i.start||a.end-i.end),r=[],n=0;return(a,i)=>{for(;n<t.length&&t[n].start<i;)r.push(t[n]),n++;for(let o=r.length-1;o>=0;o--)r[o].end<=a&&r.splice(o,1);return r.filter(o=>o.start<i&&o.end>a)}}var Ei="http://schemas.microsoft.com/office/word/2010/wordml";function dn(e,t,r={}){let{targetParagraphId:n=null}=r,a=J(e,"w:tbl");if(a.length===0)return{hasTableWrapper:!1,isTableCellParagraph:!1,paragraphs:[],paragraph:null,tableElement:null};let o=pe(e).filter(l=>{let c=l.parentNode;for(;c;){if(c.nodeName==="w:tc")return!0;c=c.parentNode}return!1});C(`[OxmlEngine] Table wrapper detected: ${a.length} tables, ${o.length} paragraphs in cells`);let s=null;if(n){let l=String(n).toUpperCase();s=o.find(c=>{let u=Si(c);return u&&u.toUpperCase()===l})||null,s?C(`[OxmlEngine] Found target paragraph by paraId: "${n}"`):C(`[OxmlEngine] paraId "${n}" not found in wrapper, falling back to text match`)}if(t&&t.trim()){let l=t.trim();if(!s)for(let c of o){let u=J(c,"w:t"),m="";for(let f of u)m+=f.textContent||"";if(m.trim()===l){s=c,C(`[OxmlEngine] Found target paragraph by text match: "${l.substring(0,30)}..."`);break}}}return{hasTableWrapper:!0,isTableCellParagraph:o.length>0,targetParagraph:s,paragraphs:o,paragraph:s||o[0]||null,tableElement:a[0]}}function nt(e,t,r){let n=Array.isArray(t)?t:[t],a="";for(let i of n){if(!i)continue;let o=r.serializeToString(i);o=o.replace(/\s+xmlns:w="[^"]*"/g,""),o=o.replace(/\s+xmlns:r="[^"]*"/g,""),o=o.replace(/\s+xmlns:wp="[^"]*"/g,""),a+=o}return C(`[OxmlEngine] Stripping table wrapper, serializing ${n.length} paragraphs`),C(`[OxmlEngine] Paragraph XML preview: ${a.substring(0,200)}...`),Pi(a)}function Pi(e){return Jr(e)}function Si(e){if(!e)return null;let t=typeof e.getAttributeNS=="function"?e.getAttributeNS(Ei,"paraId"):null;return t||e.getAttribute("w14:paraId")||e.getAttribute("w:paraId")||e.getAttribute("paraId")||null}function wn(e,t,r,n,a,i,o=!0,s=null){let l="",c=[],u=s?[s]:pe(e);u.forEach((w,h)=>{let x=w.parentNode;for(let v=w.firstChild;v;v=v.nextSibling)if(v.nodeName==="w:r"){let T=hn(v,w,x,l.length,c);l+=T.text}else if(v.nodeName==="w:hyperlink"){for(let T=v.firstChild;T;T=T.nextSibling)if(T.nodeName==="w:r"){let N=hn(T,w,x,l.length,c);l+=N.text}}l=Fe(l,h,u.length)});let m=Qe(l,r),f=Ri(c),p=0,g=0,d=new Set;for(let[w,h]of m)if(w===0){let x=h.length,v=p,T=p+x;bn(f,v,T,N=>{let E=Math.max(N.charStart,v),b=Math.min(N.charEnd,T),S=b-E,P=E-v,A=g+P,O=A+S,ae=be(i,A,O);Ii(e,N,E,b,ae,a,o)}),p+=x,g+=x}else if(w===-1)Ci(e,f,p,p+h.length,d,a,o),p+=h.length;else if(w===1){let x=h.replace(/\n/g," ");x.trim().length>0&&Ai(e,f,p,x,d,a,i,g,o),g+=h.length}return{oxml:n.serializeToString(e),hasChanges:!0}}function Ii(e,t,r,n,a,i,o){let s={};a.length>0&&a.forEach(b=>Object.assign(s,b.format));let l=t.rPr,c=b=>{if(!l)return!1;for(let S=l.firstChild;S;S=S.nextSibling)if(S.nodeName===b)return!0;return!1},u={bold:c("w:b"),italic:c("w:i"),underline:c("w:u"),strikethrough:c("w:strike")};if(!["bold","italic","underline","strikethrough"].some(b=>!!s[b]!==u[b]))return;let p=t.runElement.parentNode;if(!p)return;let g=t.textElement.textContent||"",d=t.charStart,w=r-d,h=n-d,x=g.substring(0,w),v=g.substring(w,h),T=g.substring(h);if(x.length>0){let b=le(e,x,l,!1);p.insertBefore(b,t.runElement)}let N=ze(e,l,s,i,o),E=qt(e,v,N,!1);if(p.insertBefore(E,t.runElement),T.length>0){let b=le(e,T,l,!1);p.insertBefore(b,t.runElement)}p.removeChild(t.runElement)}function hn(e,t,r,n,a){let i=M(e,"w:rPr"),o=n,s=[];for(let l=e.firstChild;l;l=l.nextSibling)if(l.nodeName==="w:t"){let c=l.textContent||"";c.length>0&&(a.push({charStart:o,charEnd:o+c.length,textElement:l,runElement:e,paragraph:t,container:r,rPr:i}),o+=c.length,s.push(c))}else l.nodeName==="w:br"||l.nodeName==="w:cr"?(a.push({charStart:o,charEnd:o+1,textElement:l,runElement:e,paragraph:t,container:r,rPr:i}),o+=1,s.push(`
141
- `)):l.nodeName==="w:tab"?(a.push({charStart:o,charEnd:o+1,textElement:l,runElement:e,paragraph:t,container:r,rPr:i}),o+=1,s.push(" ")):l.nodeName==="w:noBreakHyphen"&&(a.push({charStart:o,charEnd:o+1,textElement:l,runElement:e,paragraph:t,container:r,rPr:i}),o+=1,s.push("\u2011"));return{nextOffset:o,text:s.join("")}}function Ci(e,t,r,n,a,i,o){bn(t,r,n,s=>{if(a.has(s.textElement))return;let l=Math.max(0,r-s.charStart),c=Math.min(s.charEnd-s.charStart,n-s.charStart),u=s.textElement.textContent||"",m=u.substring(0,l),f=u.substring(l,c),p=u.substring(c);if(f.length===0)return;let g=s.runElement.parentNode;if(g){if(m.length===0&&p.length===0){let d=le(e,f,s.rPr,!0);if(o){let w=ye(e,"del",d,i);g.insertBefore(w,s.runElement)}g.removeChild(s.runElement)}else{let d=s.runElement;if(m.length>0){let h=le(e,m,s.rPr,!1);g.insertBefore(h,d)}let w=le(e,f,s.rPr,!0);if(o){let h=ye(e,"del",w,i);g.insertBefore(h,d)}if(p.length>0){let h=le(e,p,s.rPr,!1);g.insertBefore(h,d),s.runElement=h,s.textElement=M(h,"w:t")||M(h,"t")}g.removeChild(d)}a.add(s.textElement)}})}function Ai(e,t,r,n,a,i,o=[],s=0,l=!0){let c=Oi(t,r);if(!c&&r>0&&(c=Mi(t,r)),!c&&r>0&&(c=Li(t,r)),!c&&t.spans.length>0&&(c=t.spans[t.spans.length-1]),c){let u=be(o,s,s+n.length),m=c.rPr,f=c.runElement.parentNode;if(f){let p=r===c.charStart?c.runElement:c.runElement.nextSibling;if(u.length===0){let g=le(e,n,m,!1);if(l){let d=ye(e,"ins",g,i);f.insertBefore(d,p)}else f.insertBefore(g,p)}else{let g=yt(e,n,m,u,s,i,l);if(l){let d=ye(e,"ins",null,i);g.forEach(w=>d.appendChild(w)),f.insertBefore(d,p)}else g.forEach(d=>f.insertBefore(d,p))}}}}function Ri(e){let t=e.slice().sort((a,i)=>a.charStart-i.charStart||a.charEnd-i.charEnd),r=t.map(a=>a.charStart),n=t.map(a=>a.charEnd);return{spans:t,starts:r,ends:n}}function tr(e,t){let r=0,n=e.length;for(;r<n;){let a=r+n>>1;e[a]<=t?r=a+1:n=a}return r}function ki(e,t){let r=0,n=e.length;for(;r<n;){let a=r+n>>1;e[a]<t?r=a+1:n=a}return r}function bn(e,t,r,n){if(r<=t||e.spans.length===0)return;let a=tr(e.ends,t);for(;a<e.spans.length;){let i=e.spans[a];if(i.charStart>=r)break;n(i),a++}}function Oi(e,t){if(e.spans.length===0)return null;let r=tr(e.starts,t)-1;if(r<0)return null;let n=e.spans[r];return t>=n.charStart&&t<n.charEnd?n:null}function Mi(e,t){let r=ki(e.ends,t);return r<e.spans.length&&e.ends[r]===t?e.spans[r]:null}function Li(e,t){let r=tr(e.ends,t)-1;return r>=0?e.spans[r]:null}function xn(e){let t=0;return{at(r){for(;t<e.length&&e[t].end<=r;)t++;let n=e[t];return n&&n.start<=r&&r<n.end?n:null}}}function _i(e){let t=new Map;return e.forEach(r=>{t.has(r.start)||t.set(r.start,[]),t.get(r.start).push(r)}),t}function Nn(e,t){let r=e.documentElement,n=r.nodeName==="w:body"||r.nodeName.endsWith(":package"),a=pe(e),i=M(e,"w:body");!i&&n&&(i=r);let o="",s=[],l=[],c=[],u=new Map,m=new Map,f=57344,p=new Set;a.forEach((S,P)=>{let A=o.length;Array.from(S.childNodes).forEach(U=>{o=Bi(U,o,s,c,u,m,f),u.size>m.size&&f++}),o=Fe(o,P,a.length);let O=o.length,ae=M(S,"w:pPr"),Y=S.parentNode;Y&&p.add(Y),l.push({start:A,end:O,pPr:ae,container:Y||i})});let g=t;m.forEach((S,P)=>{let A=P.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");g=g.replace(new RegExp(A,"g"),S)});let d=new Map;p.forEach(S=>{d.set(S,e.createDocumentFragment())}),i&&!d.has(i)&&d.set(i,e.createDocumentFragment()),d.has(e)||d.set(e,e.createDocumentFragment());let w=new Map,h=new Set(l.map(S=>S.start)),x=xn(l),v=xn(s),T=_i(c);return{paragraphs:a,body:i||e,paragraphMap:l,paragraphStarts:h,propertyMap:s,sentinelMap:c,sentinelMapByStart:T,referenceMap:u,tokenToCharMap:m,containerFragments:d,replacementContainers:w,originalFullText:o,processedModifiedText:g,getParagraphInfo:S=>{let P=x.at(S);return P||(l.length>0?l[l.length-1]:{start:0,end:0,pPr:null,container:i||e})},getRunProperties:S=>{let P=v.at(S);return P?{rPr:P.rPr,wrapper:P.wrapper}:{rPr:null}},getPropertySpanLength:(S,P)=>{let A=v.at(S);return A?Math.min(A.end-S,P):1},isParagraphStart:S=>h.has(S)}}function Bi(e,t,r,n,a,i,o){return e.nodeName==="w:r"?$i(e,t,r,n,a,i,o):e.nodeName==="w:hyperlink"?Fi(e,t,r):["w:sdt","w:oMath","m:oMath","w:bookmarkStart","w:bookmarkEnd"].includes(e.nodeName)?(n.push({start:t.length,node:e}),t+"\uFFFC"):(["w:commentRangeStart","w:commentRangeEnd"].includes(e.nodeName)&&n.push({start:t.length,node:e,isCommentMarker:!0}),t)}function $i(e,t,r,n,a,i,o){let s=t,l=M(e,"w:rPr");return Array.from(e.childNodes).forEach(c=>{if(c.nodeName==="w:t"){let u=c.textContent||"";u.length>0&&(r.push({start:s.length,end:s.length+u.length,rPr:l}),s+=u)}else if(c.nodeName==="w:br"||c.nodeName==="w:cr")s+=`
142
- `,r.push({start:s.length-1,end:s.length,rPr:l});else if(c.nodeName==="w:tab")s+=" ",r.push({start:s.length-1,end:s.length,rPr:l});else if(c.nodeName==="w:noBreakHyphen")s+="\u2011",r.push({start:s.length-1,end:s.length,rPr:l});else if(["w:drawing","w:pict","w:object","w:fldChar","w:instrText","w:sym"].includes(c.nodeName)){let u=M(c,"w:txbxContent"),m=c.nodeName==="w:pict"&&!!u;n.push({start:s.length,node:c,isTextBox:m,originalContainer:m?u:void 0}),s+="\uFFFC",r.push({start:s.length-1,end:s.length,rPr:l})}else if(c.nodeName==="w:footnoteReference"||c.nodeName==="w:endnoteReference"){let u=c.getAttribute("w:id");if(u){let f=`{{__${c.nodeName==="w:footnoteReference"?"FN":"EN"}_${u}__}}`,p=String.fromCharCode(o);a.set(p,c),i.set(f,p),s+=p,r.push({start:s.length-1,end:s.length,rPr:l})}}else c.nodeName==="w:commentReference"&&n.push({start:s.length,node:c,isCommentMarker:!0})}),s}function Fi(e,t,r){let n=t;return Array.from(e.childNodes).forEach(a=>{if(a.nodeName!=="w:r")return;let i=M(a,"w:rPr");J(a,"w:t").forEach(s=>{let l=s.textContent||"";l.length!==0&&(r.push({start:n.length,end:n.length+l.length,rPr:i,wrapper:e}),n+=l)})}),n}function Tn(e,t,r,n,a,i,o=!0){let{paragraphs:s,paragraphMap:l,containerFragments:c,sentinelMapByStart:u,referenceMap:m,replacementContainers:f,getParagraphInfo:p,getRunProperties:g,getPropertySpanLength:d,isParagraphStart:w}=r,h=b=>{let S=e.createElement("w:p");return b&&S.appendChild(b.cloneNode(!0)),S},x=p(0),v=h(x.pPr),T=c.get(x.container);T&&T.appendChild(v);let N=0,E=0;for(let[b,S]of t){if(b===0||b===-1){let P=b===0?"equal":"delete",A=0;for(;A<S.length;){let O=N+A,ae=g(O),Y=d(O,S.length-A),U=S.substring(A,A+Y);vn(e,U,P,ae.rPr,ae.wrapper,O,v,c,u,m,f,p,h,a,i,E,o),b===0&&(E+=Y),A+=Y}N+=S.length;continue}if(b===1){let P=N>0&&!w(N)?g(N-1):g(N);vn(e,S,"insert",P.rPr,P.wrapper,N,v,c,u,m,f,p,h,a,i,E,o),E+=S.length}}return s.forEach(b=>{b.parentNode&&b.parentNode.removeChild(b)}),c.forEach((b,S)=>{let A=f.get(S)||S;if(A.nodeType===9){let O=b.firstChild;if(O)for(A.appendChild(O);b.firstChild;)A.documentElement.appendChild(b.firstChild);return}A.appendChild(b)}),{oxml:n.serializeToString(e),hasChanges:!0}}function vn(e,t,r,n,a,i,o,s,l,c,u,m,f,p,g=[],d=0,w=!0){let h=i,x=d,v=o;t.split(/([\n\uFFFC]|[\uE000-\uF8FF])/).forEach(N=>{let E=l.get(h)||[];if(E.filter(P=>P.isCommentMarker).forEach(P=>{if(P.node.nodeName==="w:commentReference"){let A=e.createElement("w:r");A.appendChild(P.node.cloneNode(!0)),v.appendChild(A)}else v.appendChild(P.node.cloneNode(!0))}),N===`
143
- `){if(r!=="delete"){let P=m(h),A=f(P.pPr),O=s.get(P.container);O&&(O.appendChild(A),v=A)}h++,r!=="delete"&&x++;return}if(N==="\uFFFC"){let P=E.find(A=>!A.isCommentMarker)||E[0];if(P){let A=P.node.cloneNode(!0);if(P.isTextBox&&P.originalContainer){let O=M(A,"w:txbxContent");if(O){for(;O.firstChild;)O.removeChild(O.firstChild);u.set(P.originalContainer,O)}}v.appendChild(A)}h++,r!=="delete"&&x++;return}if(c.has(N)){if(r!=="delete"){let P=c.get(N);if(P){let A=P.cloneNode(!0),O=e.createElement("w:r");n&&O.appendChild(n.cloneNode(!0)),O.appendChild(A),v.appendChild(O)}}h++,r!=="delete"&&x++;return}if(N.length===0)return;let S=v;if(a){let P=a.cloneNode(!1);S=P,v.appendChild(P)}if(r==="delete"){let P=e.createElement("w:r");n&&P.appendChild(n.cloneNode(!0));let A=e.createElement("w:delText");if(A.setAttribute("xml:space","preserve"),A.textContent=N,P.appendChild(A),w){let O=ye(e,"del",P,p);S.appendChild(O)}}else{let P=be(g,x,x+N.length),A=yt(e,N,n,P,x,p,w);if(r==="insert"&&w){let O=ye(e,"ins",null,p);A.forEach(ae=>O.appendChild(ae)),S.appendChild(O)}else A.forEach(O=>S.appendChild(O))}r!=="delete"&&(x+=N.length),h+=N.length})}function rr(e,t,r,n,a,i,o=!0){let s=Nn(e,r);if(s.paragraphs.length===0)return{oxml:n.serializeToString(e),hasChanges:!1};let l=Qe(s.originalFullText,s.processedModifiedText);return Tn(e,l,s,n,a,i,o)}function Ee(e,t){return{oxml:e.serializeToString(t),hasChanges:!1}}function yn(e,t,r,n,a,i=!0){let o=J(e,"w:tbl"),s=se(t),l=s.rows.length>0||s.headers.length>0;if(o.length===0||!l)return Ee(r,e);let c=o[0],u=Zt(c),m=en(u,s);if(m.length===0)return Ee(r,e);let p=tn(u,m,{generateRedlines:i,author:a}),g=`<root xmlns:w="${I}">${p}</root>`,w=(n||_()).parseFromString(g,"application/xml"),h=H(w);if(h)return V("[OxmlEngine] Failed to parse reconciled table OOXML:",h.textContent),Ee(r,e);let x=M(w,"w:tbl");if(!x)return V("[OxmlEngine] No table found in reconciled OOXML"),Ee(r,e);let v=e.importNode(x,!0);return c.parentNode.replaceChild(v,c),{oxml:r.serializeToString(e),hasChanges:!0}}function En(e,t,r,n,a,i){let o=se(t);if(!o||o.rows.length===0&&o.headers.length===0)return C("[OxmlEngine] Failed to parse table data from Markdown"),Ee(r,e);let s=ke(o,{generateRedlines:i,author:a}),l=n||_(),c=l.parseFromString(`<root xmlns:w="${I}">${s}</root>`,"application/xml"),u=H(c);if(u)return V("[OxmlEngine] Failed to parse generated table OOXML:",u.textContent),Ee(r,e);let m=D(c,I,"tbl");if(m||(m=D(c,I,"ins")),!m)return V("[OxmlEngine] No table element found in generated OOXML"),Ee(r,e);let f=e,p=z(f,I,"p");if(p.length===0)return C("[OxmlEngine] No paragraphs found to replace"),Ee(r,f);let g=p[0],d=g.parentNode;if(d&&d.nodeType===9){let h=l.parseFromString(`<w:document xmlns:w="${I}"><w:body/></w:document>`,"application/xml"),x=D(h,I,"body");p.forEach(v=>x.appendChild(h.importNode(v,!0))),f=h,p=z(f,I,"p"),g=p[0],d=g.parentNode}let w=f.importNode(m,!0);if(i){let h=ie();p.forEach(x=>{z(x,I,"r").forEach(T=>{z(T,I,"t").forEach(b=>{let S=b.textContent||"";if(S.trim()){let P=f.createElementNS(I,"w:delText");P.textContent=S,b.parentNode.replaceChild(P,b)}});let E=f.createElementNS(I,"w:del");E.setAttribute("w:id",String(Ne())),E.setAttribute("w:author",a),E.setAttribute("w:date",h),T.parentNode.insertBefore(E,T),E.appendChild(T)})})}else p.slice(1).forEach(h=>h.parentNode.removeChild(h));return d.insertBefore(w,g),i||d.removeChild(g),C("[OxmlEngine] Text-to-table transformation complete"),{oxml:r.serializeToString(f),hasChanges:!0}}async function nr(e,t,r,n={}){let a=n.generateRedlines??!0,i=n.author||G(),o=_(),s=Z(),l=()=>({oxml:e,hasChanges:!1}),c;try{c=o.parseFromString(e,"text/xml")}catch(U){return V("[OxmlEngine] Failed to parse OXML:",U),l()}let u=H(c);if(u)return V("[OxmlEngine] XML parse error:",u.textContent),l();let m=dn(c,t,n);if(m.hasTableWrapper&&m.targetParagraph&&!n._isolatedTableCell){C("[OxmlEngine] Isolating table-cell paragraph before diff");let U=nt(c,m.targetParagraph,s);return nr(U,t,r,{...n,_isolatedTableCell:!0})}let f=Pn(r),{cleanText:p,formatHints:g}=q(f),d=p.trim()!==t.trim(),w=g.length>0,{existingFormatHints:h,textSpans:x,paragraphs:v}=ln(c),T=h.length>0,N=null,E=()=>(N||(N=Et(c,v,x)),N),b=(U=null)=>{let X=gn(c,t,g,s,i,a,U);return X.useNativeApi?(C("[OxmlEngine] Format-only surgical fallback signal encountered; retrying with OOXML reconstruction fallback"),rr(c,t,p,s,i,g,a)):X};C(`[OxmlEngine] Text changes: ${d}, New format hints: ${g.length}, Existing format hints: ${h.length}`);let S=!d&&!w&&T;if(!d&&!w&&!T)return C("[OxmlEngine] No text changes, no format hints, and no existing formatting detected"),l();if(S){C("[OxmlEngine] Format REMOVAL detected: applying surgical replacement in OOXML");let U=m,X=U.targetParagraph||null;if(!X){let gt=cn(E(),t);gt&&(X=gt.paragraph)}let Ie=h;X&&(Ie=h.filter(gt=>fn(gt.run)===X));let Er=pn(c,x,Ie,s,i,a);return U.hasTableWrapper&&X?{oxml:nt(c,X,s),hasChanges:Er.hasChanges}:Er}if(!d&&w){C(`[OxmlEngine] Format-only change detected: ${g.length} format hints`);let U=m,X={textSpans:x,paragraphs:v,paragraphInfos:E()};if(U.hasTableWrapper&&U.targetParagraph){C("[OxmlEngine] Table cell context: applying formatting to target paragraph only");let Ie=b(X);return C("[OxmlEngine] Stripping table wrapper for table cell paragraph (format-only)"),{oxml:nt(c,U.targetParagraph,s),hasChanges:Ie.hasChanges}}return b(X)}let A=J(c,"w:tbl").length>0,O=/^\|.+\|/.test(p.trim())&&p.includes(`
144
- `),ae=wt(p),Y=m;if(C(`[OxmlEngine] Mode: ${A?"SURGICAL":"RECONSTRUCTION"}, formatHints: ${g.length}, isMarkdownTable: ${O}, isTargetList: ${ae}, isTableCellParagraph: ${Y.isTableCellParagraph}`),O&&!A)return C("[OxmlEngine] Text-to-table transformation: generating new table from Markdown"),En(c,p,s,o,i,a);if(A&&O)return yn(c,p,s,o,i,a);if(A){let U=Y.hasTableWrapper&&Y.targetParagraph?Y.targetParagraph:null;U&&C("[OxmlEngine] Table cell edit: scoping surgical mode to target paragraph");let X=wn(c,t,p,s,i,g,a,U);return Y.hasTableWrapper&&X.hasChanges&&Y.targetParagraph?(C("[OxmlEngine] Stripping table wrapper for table cell paragraph (surgical mode)"),{oxml:nt(c,Y.targetParagraph,s),hasChanges:!0}):X}if(ae){C("[OxmlEngine] \u{1F3AF} Using reconciliation pipeline for list generation");let X=await new Oe({author:i,generateRedlines:a}).execute(e,r,{xmlDoc:c});if(X.isValid&&X.ooxml&&X.ooxml!==e){C(`[OxmlEngine] Wrapping list OOXML with numbering definitions, includeNumbering=${X.includeNumbering}`);let Ie=Te(X.ooxml,{includeNumbering:X.includeNumbering??!0,numberingXml:X.numberingXml});return C(`[OxmlEngine] \u2705 Wrapped OOXML length: ${Ie.length}`),{oxml:Ie,hasChanges:!0}}return l()}return rr(c,t,p,s,i,g,a)}function Pn(e){let t=e;return t=t.replace(/^(Here is the redline:|Here is the text:|Sure, I can help:|Here's the updated text:)\s*/i,""),t=t.replace(/\$\\text\{/g,"").replace(/\}\$/g,""),t=t.replace(/\$([^0-9\n]+?)\$/g,"$1"),t=t.replace(/\\r\\n/g,`
132
+ `}function zo(e){let t=new Map,r=new Map,n=[];for(let a of e)a.type==="row_delete"?t.set(a.gridRow,a):a.type==="cell_modify"?r.set(`${a.gridRow}:${a.gridCol}`,a):a.type==="row_insert"&&n.push(a);return n.sort((a,o)=>a.gridRow-o.gridRow),{rowDeleteByRow:t,cellModifyByCoordinate:r,rowInsertOperations:n}}function Wo(e,t,r){let{generateRedlines:n,author:a}=r,{cleanText:o,formatHints:i}=ne(t),s=e.getText(),l=kt(s,o),c=e.blocks[0]||{runModel:[],pPr:null},u=Mt(c.runModel,l),m=Lt(u,l,{generateRedlines:n,author:a,formatHints:i});return fe(m,c.pPr,i,{author:a,generateRedlines:n})}function Ho(e){return e.map(t=>fe(t.runModel,t.pPr,[],{})).join("")}function Uo(e,t,r){let n=e.tcPrXml;return e.colSpan>1&&!n.includes("gridSpan")?n=n.replace("</w:tcPr>",`<w:gridSpan w:val="${e.colSpan}"/></w:tcPr>`):e.colSpan>1&&n==="<w:tcPr/>"&&(n=`<w:tcPr><w:gridSpan w:val="${e.colSpan}"/></w:tcPr>`),e.rowSpan>1&&e.isMergeOrigin&&!n.includes("vMerge")?n=n.replace("</w:tcPr>",'<w:vMerge w:val="restart"/></w:tcPr>'):e.rowSpan>1&&e.isMergeOrigin&&n==="<w:tcPr/>"&&(n='<w:tcPr><w:vMerge w:val="restart"/></w:tcPr>'),`<w:tc>${n}${t}</w:tc>`}function me(e){let t=e.split(`
133
+ `).map(i=>i.trim()).filter(i=>i.startsWith("|"));if(t.length===0)return{headers:[],rows:[],hasHeader:!1};let r=i=>{let s=i.replace(/\s+/g,"");return/^\|:?-{3,}:?(\|:?-{3,}:?)+\|?$/.test(s)},n=t.some(r),o=t.filter(i=>!r(i)).map(i=>i.split("|").slice(1,-1).map(s=>s.trim()));return n?{headers:o[0]||[],rows:o.slice(1),hasHeader:!0}:{headers:[],rows:o,hasHeader:!1}}async function Cn(e){let{cleanText:t,numberingContext:r,originalRunModel:n=[],originalText:a="",generateRedlines:o=!0,author:i="AI",font:s=null,numberingService:l}=e,c=Go(t),u=jo(c),m=u.map(v=>v.raw),f=[],p=[];if(o){if(n&&n.length>0)p=n.filter(v=>v.kind==="text"||v.kind==="run").map(v=>({...v,kind:"deletion",author:i}));else if(a&&a.trim().length>0){let v=a.trim();p=[{kind:"deletion",text:v,author:i,startOffset:0,endOffset:v.length}]}}let g=br(m);C(`[ListGen] Detected indentation step: ${g} spaces/chars`);let d=u.find(v=>v.marker)?.marker||"",{format:w}=l.detectNumberingFormat(d);C(`[ListGen] Detected primary marker: "${d}", format: ${w}`);for(let v=0;v<u.length;v++){let P=Vo(u,v);if(P){let I=me(P.tableText);if(I.headers.length>0||I.rows.length>0){o&&f.length===0&&p.length>0&&f.push(fe(p,null,[],{author:i,generateRedlines:o,font:s})),f.push(_e(I,{generateRedlines:o,author:i})),v=P.endIndex;continue}}let N=u[v],y=Ko(N,v,g,r,l,o,i,s,p);f.push(y.ooxml)}let h=l.generateNumberingXml(),E=f.join("")+"<w:p><w:pPr></w:pPr></w:p>";return C(`[ListGen] \u2705 Generated OOXML for ${f.length} list items, total length: ${E.length}`),C(`[ListGen] First 200 chars: ${E.substring(0,200)}...`),{ooxml:E,isValid:!0,warnings:["Paragraph expanded to list fragment"],type:"fragment",includeNumbering:!0,numberingXml:h}}function br(e){let t=e.map(n=>n.match(/^(\s*)/)[0].length).filter(n=>n>0).sort((n,a)=>n-a);if(t.length===0)return 2;let r=t[0];for(let n=1;n<t.length;n++){let a=t[n]-t[n-1];a>0&&a<r&&(r=a)}return r||2}function jo(e){return e.split(`
134
+ `).filter(t=>t.trim().length>0).map(t=>{let r=be(t),n=t.match(/^\s*(#{1,9})\s+(.*)/);return{raw:t,marker:r?r[2].trim():"",headerMatch:n,indentSize:t.match(/^(\s*)/)?.[1].length||0,isTableLine:/^\s*\|/.test(t),isTableSeparator:/^\s*\|?[\s:-]*-[-\s|:]*\|?\s*$/.test(t)}})}function Go(e){let t=String(e||"").split(`
135
+ `),r=t.map((i,s)=>({line:i,index:s})).filter(i=>i.line.trim().length>0);if(r.length<2)return e;let n=[],a=0;for(let{line:i,index:s}of r){let l=be(i);if(!l)return e;let c=Ee(i),u=be(c);if(!u)return e;let m=(l[2]||"").trim(),f=(u[2]||"").trim();if(!m||!f||m===f)return e;let g=`${l[1]||""}${c.trimStart()}`;n.push({index:s,rewritten:g}),a++}if(a<2)return e;let o=t.slice();for(let i of n)o[i.index]=i.rewritten;return C(`[ListGen] Normalized ${a} composite list markers (e.g., "- A." -> "A.").`),o.join(`
136
+ `)}function Vo(e,t){let r=e[t],n=e[t+1];if(!r?.isTableLine||!n?.isTableLine||!n?.isTableSeparator)return null;let a=[],o=t;for(;o<e.length&&e[o].isTableLine;)a.push(e[o].raw),o++;return{tableText:a.join(`
137
+ `),endIndex:o-1}}function Ko(e,t,r,n,a,o,i,s,l){let c="",u="";if(e.headerMatch){let g=Math.min(e.headerMatch[1].length,9),d=Math.min(g-1,8),w=[32,28,26,24,22,20,20,20,20],h=w[g-1]||w[w.length-1];u=e.headerMatch[2].trim(),c=`<w:pPr><w:pStyle w:val="Heading${g}"/><w:outlineLvl w:val="${d}"/><w:rPr><w:b/><w:sz w:val="${h}"/><w:szCs w:val="${h}"/></w:rPr></w:pPr>`}else if(e.marker){let g=a.detectNumberingFormat(e.marker),d=r>0?Math.floor(e.indentSize/r):0,w=n?.ilvl||0,h=g.format==="outline"?Math.min(8,g.depth):Math.min(8,d+w);u=Ee(e.raw);let b=a.getOrCreateNumId({type:g.format},n);c=a.buildListPPr(b,h)}else u=e.raw;let{cleanText:m,formatHints:f}=ne(u),p=[];return t===0&&l.length>0&&p.push(...l),p.push({kind:o?"insertion":"run",text:m,author:i,startOffset:0,endOffset:m.length}),{ooxml:fe(p,c,f,{author:i,generateRedlines:o,font:s})}}var Yo=new Set(["officeonline","officeweb","web"]);function Zo(e){return e?Yo.has(String(e).toLowerCase()):!1}function Jo(){return typeof process<"u"&&process?.env?.NODE_ENV==="production"}function qo(){return new Promise(e=>setTimeout(e,0))}var Be=class{constructor(t={}){this.generateRedlines=t.generateRedlines??!0,this.author=t.author??"AI",this.validateOutput=t.validateOutput??!0,this.validationMode=t.validationMode??"auto",this.numberingService=t.numberingService||new lt,this.font=t.font||null,this.platform=t.platform??or(),this.isWebPlatform=t.isWebPlatform??Zo(this.platform),this.enableEventLoopYielding=t.enableEventLoopYielding??this.isWebPlatform,this.yieldRunThreshold=t.yieldRunThreshold??50,this.yieldCharThreshold=t.yieldCharThreshold??5e3,this.disableSemanticCleanupOverChars=t.disableSemanticCleanupOverChars??(this.isWebPlatform?8e3:Number.POSITIVE_INFINITY)}async execute(t,r,n={}){let a=[];try{let o=n.xmlDoc||B().parseFromString(t,"application/xml"),i=H(o,"*","p"),{runModel:s,acceptedText:l,pPr:c}=Ot(t,{xmlDoc:o}),u=i?gr(i):null;C(`[Reconcile] Ingested ${s.length} runs, ${l.length} chars, numbering:`,u),await this.maybeYield(s.length,Math.max(l.length,r?.length||0));let{cleanText:m,formatHints:f}=ne(r);C(`[Reconcile] Preprocessed: ${f.length} format hints`),await this.maybeYield(s.length,Math.max(l.length,m.length));let p=nn(m),g=Ct(m),d=p||g;if(!p&&g&&C("[Reconcile] List-target detected via loose marker parsing; bypassing no-op short-circuit for structural conversion."),l===m&&f.length===0&&!d)return C("[Reconcile] No changes detected"),{ooxml:t,isValid:!0,warnings:["No changes detected"]};let w=Math.max(l.length,m.length)<this.disableSemanticCleanupOverChars,h=kt(l,m,{cleanupSemantic:w});w||C("[Reconcile] Skipping semantic diff cleanup for large web payload"),await this.maybeYield(s.length,Math.max(l.length,m.length));let b=s.filter(P=>P.kind===O.PARAGRAPH_START).length;if(C(`[Reconcile] isTargetList: ${d}, paragraphCount: ${b}`),d)return C("[Reconcile] \u{1F3AF} ENTERING LIST GENERATION PATH"),C(`[Reconcile] cleanText preview: ${m.substring(0,100)}...`),C(`[Reconcile] acceptedText preview: ${l.substring(0,100)}...`),this.executeListGeneration(m,u,s);C(`[Reconcile] Computed ${h.length} diff operations`);let x=Mt(s,h);C(`[Reconcile] Split into ${x.length} runs`);let E=Lt(x,h,{generateRedlines:this.generateRedlines,author:this.author,formatHints:f,numberingService:this.numberingService});C(`[Reconcile] Patched model has ${E.length} runs`),await this.maybeYield(E.length,Math.max(l.length,m.length));let v=fe(E,c,f,{author:this.author,generateRedlines:this.generateRedlines});if(this.shouldRunValidation()){let P=this.validateBasic(v);P.isValid||a.push(...P.errors)}return{ooxml:v,isValid:a.length===0,warnings:a}}catch(o){return Z("[Reconcile] Pipeline error:",o),{ooxml:t,isValid:!1,warnings:[`Pipeline error: ${o.message}`]}}}validateBasic(t){let r=[];try{let n=`<root xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">${t}</root>`,o=B().parseFromString(n,"application/xml"),i=j(o);i&&r.push("Generated OOXML is not well-formed XML: "+i.textContent.substring(0,100)),t.includes("<w:p")||r.push("Generated OOXML missing paragraph element")}catch(n){r.push(`Validation error: ${n.message}`)}return{isValid:r.length===0,errors:r}}shouldRunValidation(){return this.validateOutput?this.validationMode==="always"?!0:this.validationMode==="never"?!1:!(this.isWebPlatform&&Jo()):!1}async maybeYield(t,r){this.enableEventLoopYielding&&(t<=this.yieldRunThreshold&&r<=this.yieldCharThreshold||await qo())}wrapForInsertion(t,r={}){return Ie(t,r)}async executeListGeneration(t,r,n,a=""){return Cn({cleanText:t,numberingContext:r,originalRunModel:n,originalText:a,generateRedlines:this.generateRedlines,author:this.author,font:this.font,numberingService:this.numberingService})}detectIndentationStep(t){return br(t)}executeTableGeneration(t){let r=me(t);return r.rows.length===0&&r.headers.length===0?{ooxml:"",isValid:!1,warnings:["Could not parse Markdown table"]}:{ooxml:_e(r,{generateRedlines:this.generateRedlines,author:this.author}),isValid:!0,warnings:[],includeNumbering:!1}}};function z(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===S&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function A(e,t){return typeof e.createElementNS=="function"?e.createElementNS(S,t):e.createElement(t)}function Qo(e,t){let r=Array.from(e?.getElementsByTagNameNS?.(S,t)||[]);return r.length>0?r:Array.from(e?.getElementsByTagName?.("*")||[]).filter(n=>z(n,t))}function xr(e){return["ins","del","moveFrom","moveTo","moveFromRangeStart","moveFromRangeEnd","moveToRangeStart","moveToRangeEnd","rPrChange","pPrChange","cellIns","cellDel"].some(r=>Qo(e,r).length>0)}function ei(e){let t=String(e||"").trim();return/^<\?xml\b[^>]*>\s*<pkg:package\b/i.test(t)||/^<pkg:package\b/i.test(t)?"package":/^<\?xml\b[^>]*>\s*<(?:w:)?document\b/i.test(t)||/^<(?:w:)?document\b/i.test(t)?"document":"fragment"}function te(e){return!e||typeof e!="object"||e.sourceType||typeof e.oxml!="string"?e:{...e,sourceType:ei(e.oxml)}}var ct=["w:rStyle","w:rFonts","w:b","w:bCs","w:i","w:iCs","w:caps","w:smallCaps","w:strike","w:dstrike","w:outline","w:shadow","w:emboss","w:imprint","w:noProof","w:snapToGrid","w:vanish","w:webHidden","w:color","w:spacing","w:w","w:kern","w:position","w:sz","w:szCs","w:highlight","w:u","w:effect","w:bdr","w:shd","w:fitText","w:vertAlign","w:rtl","w:cs","w:em","w:lang","w:eastAsianLayout","w:specVanish","w:oMath"];function Ke(e,t){let r=ct.indexOf(t.nodeName),n=r===-1?999:r,a=!1;for(let o of Array.from(e.childNodes)){if(o.nodeType!==1)continue;let i=ct.indexOf(o.nodeName);if((i===-1?999:i)>n){e.insertBefore(t,o),a=!0;break}}a||e.appendChild(t)}function ti(e,t,r,n){if(!t||!r)return;let a=!!r.bold,o=!!r.italic,i=!!r.underline,s=!!r.strikethrough,l=new Set;if(a&&(l.add("w:b"),l.add("w:bCs")),o&&(l.add("w:i"),l.add("w:iCs")),i&&l.add("w:u"),s&&l.add("w:strike"),l.size>0){let c=[];for(let u of Array.from(t.childNodes))l.has(u.nodeName)&&c.push(u);for(let u of c)t.removeChild(u)}if(a){let c=A(e,"w:b");c.setAttribute("w:val",n==="add"?"1":"0"),Ke(t,c);let u=A(e,"w:bCs");u.setAttribute("w:val",n==="add"?"1":"0"),Ke(t,u)}if(o){let c=A(e,"w:i");c.setAttribute("w:val",n==="add"?"1":"0"),Ke(t,c);let u=A(e,"w:iCs");u.setAttribute("w:val",n==="add"?"1":"0"),Ke(t,u)}if(i){let c=A(e,"w:u");c.setAttribute("w:val",n==="add"?"single":"none"),Ke(t,c)}if(s){let c=A(e,"w:strike");c.setAttribute("w:val",n==="add"?"1":"0"),Ke(t,c)}}function An(e,t,r){ti(e,t,r,"remove")}function ut(e){let t={bold:!1,italic:!1,underline:!1,strikethrough:!1,hasFormatting:!1};if(!e)return t;for(let r of Array.from(e.childNodes))if(r.nodeName==="w:b"&&(t.bold=_t(r,!1)),r.nodeName==="w:i"&&(t.italic=_t(r,!1)),r.nodeName==="w:u"&&(t.underline=_t(r,!0)),r.nodeName==="w:strike"&&(t.strikethrough=_t(r,!1)),r.nodeName==="w:rStyle"){let n=r.getAttribute("w:val");if(n){let a=n.toLowerCase();(a.includes("bold")||a.includes("strong"))&&(t.bold=!0),(a.includes("italic")||a.includes("emphasis"))&&(t.italic=!0),a.includes("underline")&&(t.underline=!0)}}return t.hasFormatting=t.bold||t.italic||t.underline||t.strikethrough,t}function _t(e,t){let n=(e.getAttribute("w:val")||e.getAttribute("val")||"").toLowerCase();return n?t?n!=="none"&&n!=="0"&&n!=="false"&&n!=="off":n!=="0"&&n!=="false"&&n!=="off":!0}var Rn="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function de(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===Rn&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function ri(e){return!e||e.nodeType!==1||e.namespaceURI!==Rn?!1:e.localName==="del"||e.localName==="moveFrom"}function On(e){let t=[],r=Array.from(e?.childNodes||[]).reverse();for(;r.length>0;){let n=r.pop();if(!n||n.nodeType!==1||ri(n))continue;if(de(n,"r")){t.push(n);continue}let a=Array.from(n.childNodes||[]);for(let o=a.length-1;o>=0;o-=1)r.push(a[o])}return t}function xe(e){let t=new Set(["comment","footnote","endnote"]);return V(e,"*","p").filter(n=>{let a=n.parentNode;for(;a&&a.nodeName;){let o=String(a.localName||"").toLowerCase();if(t.has(o))return!1;a=a.parentNode}return!0})}function kn(e){let t=[],r=0;for(let n=0;n<e.length;n++){let a=e[n],o=On(a);for(let i of o){let s=$(i,"w:rPr");Array.from(i.childNodes||[]).forEach(l=>{if(de(l,"t")){let c=l.textContent||"";c.length>0&&(t.push({charStart:r,charEnd:r+c.length,textElement:l,runElement:i,paragraph:a,container:i.parentNode,rPr:s}),r+=c.length)}else(de(l,"br")||de(l,"cr")||de(l,"tab")||de(l,"noBreakHyphen"))&&(t.push({charStart:r,charEnd:r+1,textElement:l,runElement:i,paragraph:a,container:i.parentNode,rPr:s}),r+=1)})}r=Me(r,n,e.length)}return{textSpans:t,charOffset:r}}function ni(e,t,r,n,a,o=null){let i=null;for(let c of Array.from(e.childNodes))if(de(c,"rPr")){i=c;break}let s=ut(i);o&&(o.bold&&!s.bold&&(s.bold=!0),o.italic&&!s.italic&&(s.italic=!0),o.underline&&!s.underline&&(s.underline=!0),o.strikethrough&&!s.strikethrough&&(s.strikethrough=!0)),s.hasFormatting=s.bold||s.italic||s.underline||s.strikethrough;let l=r;for(let c of Array.from(e.childNodes))if(de(c,"t")){let u=c.textContent||"";if(u.length>0){let m=l,f=l+u.length;n.push({charStart:m,charEnd:f,textElement:c,runElement:e,paragraph:t,rPr:i,format:{...s}}),s.hasFormatting&&a.push({start:m,end:f,format:{...s},run:e,rPr:i}),l=f}}return l}function Mn(e){let t=[],r=[],n=0,a=xe(e);for(let o=0;o<a.length;o++){let i=a[o],s=null;for(let u of Array.from(i.childNodes))if(de(u,"pPr")){for(let m of Array.from(u.childNodes))if(de(m,"rPr")){s=m;break}break}let l=ut(s);l.hasFormatting&&C(`[OxmlEngine] Found paragraph-level formatting: ${JSON.stringify(l)}`);let c=On(i);for(let u of c)n=ni(u,i,n,r,t,l);n=Me(n,o,a.length)}return C(`[OxmlEngine] Extracted ${r.length} text spans, ${t.length} format hints`),{existingFormatHints:t,textSpans:r,paragraphs:a}}function Fe(e,t,r,n){let a=A(e,t==="ins"?"w:ins":"w:del"),o=ee(n);return a.setAttribute("w:id",String(o.id)),a.setAttribute("w:author",o.author),a.setAttribute("w:date",o.date),r&&a.appendChild(r),a}function Ln(e,t){return Array.from(e?.childNodes||[]).find(r=>r.nodeType===1&&(r.localName===t||r.nodeName===`w:${t}`))||null}function ai(e,t){let r=Ln(t,"pPr");return r?t.firstChild!==r&&t.insertBefore(r,t.firstChild||null):(r=A(e,"w:pPr"),t.insertBefore(r,t.firstChild||null)),r}function oi(e,t){let r=Ln(t,"rPr");return r?t.lastChild!==r&&t.appendChild(r):(r=A(e,"w:rPr"),t.appendChild(r)),r}function _n(e,t,r,n){let a=ai(e,t),o=oi(e,a);for(let l of Array.from(o.childNodes||[]))l.nodeType===1&&(l.localName==="ins"||l.localName==="del"||l.nodeName==="w:ins"||l.nodeName==="w:del")&&o.removeChild(l);let i=A(e,n==="ins"?"w:ins":"w:del"),s=ee(r);return i.setAttribute("w:id",String(s.id)),i.setAttribute("w:author",s.author),i.setAttribute("w:date",s.date),o.appendChild(i),i}function Bn(e,t,r){return _n(e,t,r,"ins")}function Bt(e,t,r){return _n(e,t,r,"del")}function $e(e,t,r,n){let a=A(e,"w:r");if(r&&a.appendChild(r.cloneNode(!0)),!n)return Fn(e,a,t),a;let o=A(e,n?"w:delText":"w:t");return o.setAttribute("xml:space","preserve"),o.textContent=t,a.appendChild(o),a}function Ft(e,t,r,n,a,o,i){if(!t)return[];let s=new Set([0,t.length]);for(let u of n){let m=Math.max(0,u.start-a),f=Math.min(t.length,u.end-a);m>=0&&m<t.length&&s.add(m),f>0&&f<=t.length&&s.add(f)}let l=Array.from(s).sort((u,m)=>u-m),c=[];for(let u=0;u<l.length-1;u++){let m=l[u],f=l[u+1],p=t.slice(m,f);if(!p)continue;let g=a+m,d=a+f,w=n.filter(x=>x.start<=g&&x.end>=d),h={};w.forEach(x=>{x.format&&Object.assign(h,x.format)});let b=Ye(e,r,h,o,i);c.push(Nr(e,p,b,!1))}return c}function Nr(e,t,r,n){let a=A(e,"w:r");if(r&&a.appendChild(r),!n)return Fn(e,a,t),a;let o=A(e,n?"w:delText":"w:t");return o.setAttribute("xml:space","preserve"),o.textContent=t,a.appendChild(o),a}function Fn(e,t,r){let a=String(r||"").split(/(\t|\n|\u2011)/);for(let o of a){if(!o)continue;if(o===" "){t.appendChild(A(e,"w:tab"));continue}if(o===`
138
+ `){t.appendChild(A(e,"w:br"));continue}if(o==="\u2011"){t.appendChild(A(e,"w:noBreakHyphen"));continue}let i=A(e,"w:t");/^\s|\s$/.test(o)&&i.setAttribute("xml:space","preserve"),i.textContent=o,t.appendChild(i)}}function Ye(e,t,r,n,a){let o=A(e,"w:rPr");t&&Array.from(t.childNodes).forEach(l=>{["w:b","w:bCs","w:i","w:iCs","w:u","w:strike","w:rPrChange"].includes(l.nodeName)||o.appendChild(l.cloneNode(!0))});let i=r||{bold:!1,italic:!1,underline:!1,strikethrough:!1};n&&a&&ii(e,o,n,t);let s=(l,c,u=null,m="0")=>{let f=A(e,l);c?u&&f.setAttribute("w:val",u):m&&f.setAttribute("w:val",m);let p=ct.indexOf(l),g=p===-1?999:p,d=!1;for(let w of Array.from(o.childNodes)){if(w.nodeType!==1)continue;let h=ct.indexOf(w.nodeName);if((h===-1?999:h)>g){o.insertBefore(f,w),d=!0;break}}d||o.appendChild(f)};return s("w:b",!!i.bold,"1","0"),s("w:bCs",!!i.bold,"1","0"),s("w:i",!!i.italic,"1","0"),s("w:iCs",!!i.italic,"1","0"),s("w:u",!!i.underline,"single","none"),s("w:strike",!!i.strikethrough,"1","0"),o}function vr(e,t,r,n,a){let o=A(e,"w:rPrChange"),i=ee(r);o.setAttribute("w:id",String(i.id)),o.setAttribute("w:author",i.author),o.setAttribute("w:date",n||i.date);let s=A(e,"w:rPr"),l=a||t;Array.from(l.childNodes).forEach(u=>{u.nodeName!=="w:rPrChange"&&s.appendChild(u.cloneNode(!0))}),o.appendChild(s);let c=$(t,"w:rPrChange");return c&&t.removeChild(c),t.appendChild(o),o}function ii(e,t,r,n){vr(e,t,r,null,n||t)}var si="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function Ze(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===si&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function $t(e,t,r){let n=new Map;for(let i of r)!i||!i.paragraph||(n.has(i.paragraph)||n.set(i.paragraph,[]),n.get(i.paragraph).push(i));let a=[],o=0;return t.forEach((i,s)=>{let l=(n.get(i)||[]).slice().sort((f,p)=>f.charStart-p.charStart),c=li(l),u=Tr(c),m=u.trim();a.push({paragraph:i,spans:l,text:c,normalizedText:u,normalizedTrim:m,startOffset:o}),o+=u.length,o=Me(o,s,t.length)}),a}function $n(e,t){if(!t)return null;let r=Tr(t),n=r.trim();if(!n)return null;for(let a of e)if(a.normalizedText===r)return a;for(let a of e)if(a.normalizedTrim===n)return a;return null}function Xn(e,t){let r=Tr(t),n=r.trim(),a=null,o=0;for(let i of e)if(i.normalizedText===r)return a=i,{targetInfo:a,matchOffset:o};if(n.length>0){for(let i of e)if(i.normalizedTrim===n)return a=i,{targetInfo:a,matchOffset:o}}if(n.length>0){let s=e.map(l=>l.normalizedText).join(`
139
+ `).indexOf(n);if(s!==-1)for(let l of e){let c=l.startOffset,u=l.normalizedText.length;if(s>=c&&s<=c+u){a=l,o=s-c;break}}}if(!a&&e.length===1&&r.length>0){let i=e[0],s=i.normalizedTrim||"";if(s.length>0){let l=r.indexOf(s);l>=0&&(a=i,o=-l)}}return{targetInfo:a,matchOffset:o}}function Dn(e){let t=e;for(;t;){if(Ze(t,"p"))return t;t=t.parentNode}return null}function li(e){if(!e||e.length===0)return"";let t="";for(let r of e){if(!r||!r.textElement)continue;let n=r.textElement;Ze(n,"t")?t+=r.textElement.textContent||"":Ze(n,"tab")?t+=" ":Ze(n,"br")||Ze(n,"cr")?t+=`
140
+ `:Ze(n,"noBreakHyphen")&&(t+="\u2011")}return t}function Tr(e){return e?e.replace(/\r/g,`
141
+ `).replace(/\u00a0/g," "):""}function zn(e,t,r){let n=Array.from(new Set(r)).sort((s,l)=>s-l);if(n.length===0||t.length===0)return[...t];let a=[...t].sort((s,l)=>s.charStart-l.charStart||s.charEnd-l.charEnd),o=[],i=0;for(let s of a){for(;i<n.length&&n[i]<=s.charStart;)i++;let l=s;for(;i<n.length&&n[i]<l.charEnd;){let c=n[i],u=ci(e,l,c);if(!u){i++;continue}o.push(u[0]),l=u[1],i++}o.push(l)}return o}function ci(e,t,r){let n=t.runElement,a=n.parentNode;if(!a)return null;let o=t.textElement.textContent||"",i=r-t.charStart,s=o.substring(0,i),l=o.substring(i);if(s.length===0||l.length===0)return null;let c=$e(e,s,t.rPr,!1),u=$e(e,l,t.rPr,!1);a.insertBefore(c,n),a.insertBefore(u,n),a.removeChild(n);let m=c.getElementsByTagName("w:t")[0],f=u.getElementsByTagName("w:t")[0];return[{...t,charEnd:r,textElement:m,runElement:c},{...t,charStart:r,textElement:f,runElement:u}]}var ui="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function fi(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===ui&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function mi(e){return Array.isArray(e)?{textSpans:e,paragraphs:null,paragraphInfos:null}:!e||typeof e!="object"?{textSpans:null,paragraphs:null,paragraphInfos:null}:{textSpans:Array.isArray(e.textSpans)?e.textSpans:null,paragraphs:Array.isArray(e.paragraphs)?e.paragraphs:null,paragraphInfos:Array.isArray(e.paragraphInfos)?e.paragraphInfos:null}}function Wn(e,t,r,n,a,o=!0){let i=!1,s=new Set;C(`[OxmlEngine] Surgical format removal: ${r.length} hints to process (using w:rPrChange)`);for(let l of r){let c=l.run;if(s.has(c)||(s.add(c),!c.parentNode))continue;C("[OxmlEngine] Processing run for surgical format removal, format:",l.format);let u=$(c,"w:rPr");u||(u=A(e,"w:rPr"),c.insertBefore(u,c.firstChild)),o&&vr(e,u,a||J()),An(e,u,l.format),i=!0}return i?(C("[OxmlEngine] Surgical format removal completed successfully (Pure Format Mode)"),{oxml:n.serializeToString(e),hasChanges:!0}):(C("[OxmlEngine] No format changes were applied"),{oxml:n.serializeToString(e),hasChanges:!1})}function pi(e,t,r,n,a,o=!0){let i=!1,s=new Set;if(!t||t.length===0)return{oxml:n.serializeToString(e),hasChanges:!1};let l=[];for(let f of r)l.push(f.start,f.end);let u=zn(e,t,l).slice().sort((f,p)=>f.charStart-p.charStart||f.charEnd-p.charEnd),m=gi(r);for(let f of u){if(!f||!f.textElement||!fi(f.textElement,"t"))continue;let p=m(f.charStart,f.charEnd);if(p.length===0)continue;let g=ir(...p.map(R=>R.format)),d={bold:!!g.bold,italic:!!g.italic,underline:!!g.underline,strikethrough:!!g.strikethrough},w=f.format||ut(f.rPr),h={bold:!!w.bold,italic:!!w.italic,underline:!!w.underline,strikethrough:!!w.strikethrough};if(!["bold","italic","underline","strikethrough"].some(R=>d[R]!==h[R])||s.has(f.runElement)||(s.add(f.runElement),!(f.textElement.textContent||""))||!f.runElement.parentNode)continue;let P=f.runElement,N=$(P,"w:rPr"),y=Ye(e,N,d,a||J(),o),I=N;if(!I)P.insertBefore(y,P.firstChild);else{for(;I.firstChild;)I.removeChild(I.firstChild);Array.from(y.childNodes).forEach(R=>I.appendChild(R))}i=!0}return{oxml:n.serializeToString(e),hasChanges:i}}function Hn(e,t,r,n,a,o=!0,i=null){let s=mi(i),l=s.paragraphs||xe(e),c=s.textSpans||[];if(s.textSpans||({textSpans:c}=kn(l)),!c||c.length===0)return ke("[OxmlEngine] No spans available for surgical format-only change; requesting caller fallback strategy"),{hasChanges:!0,useNativeApi:!0,formatHints:r,originalText:t};if(!r||r.length===0)return{oxml:n.serializeToString(e),hasChanges:!1};let u=s.paragraphInfos||$t(e,l,c),{targetInfo:m,matchOffset:f}=Xn(u,t);if(!m||!m.spans||m.spans.length===0)return ke("[OxmlEngine] Unable to pinpoint target paragraph for surgical format-only change; requesting caller fallback strategy"),{hasChanges:!0,useNativeApi:!0,formatHints:r,originalText:t};let p=m.spans[0].charStart,g=m.spans.map(w=>({...w,charStart:w.charStart-p,charEnd:w.charEnd-p})),d=r.map(w=>({...w,start:w.start+f,end:w.end+f}));return pi(e,g,d,n,a,o)}function gi(e){let t=(e||[]).slice().sort((a,o)=>a.start-o.start||a.end-o.end),r=[],n=0;return(a,o)=>{for(;n<t.length&&t[n].start<o;)r.push(t[n]),n++;for(let i=r.length-1;i>=0;i--)r[i].end<=a&&r.splice(i,1);return r.filter(i=>i.start<o&&i.end>a)}}var di="http://schemas.microsoft.com/office/word/2010/wordml";function Un(e,t,r={}){let{targetParagraphId:n=null}=r,a=ue(e,S,"tbl");if(a.length===0)return{hasTableWrapper:!1,isTableCellParagraph:!1,paragraphs:[],paragraph:null,tableElement:null};let i=xe(e).filter(l=>{let c=l.parentNode;for(;c;){if(z(c,"tc"))return!0;c=c.parentNode}return!1});C(`[OxmlEngine] Table wrapper detected: ${a.length} tables, ${i.length} paragraphs in cells`);let s=null;if(n){let l=String(n).toUpperCase();s=i.find(c=>{let u=wi(c);return u&&u.toUpperCase()===l})||null,s?C(`[OxmlEngine] Found target paragraph by paraId: "${n}"`):C(`[OxmlEngine] paraId "${n}" not found in wrapper, falling back to text match`)}if(t&&t.trim()){let l=t.trim();if(!s)for(let c of i){let u=ue(c,S,"t"),m="";for(let f of u)m+=f.textContent||"";if(m.trim()===l){s=c,C(`[OxmlEngine] Found target paragraph by text match: "${l.substring(0,30)}..."`);break}}}return{hasTableWrapper:!0,isTableCellParagraph:i.length>0,targetParagraph:s,paragraphs:i,paragraph:s||i[0]||null,tableElement:a[0]}}function ft(e,t,r){let n=Array.isArray(t)?t:[t],a="";for(let o of n){if(!o)continue;let i=r.serializeToString(o);i=i.replace(/\s+xmlns:w="[^"]*"/g,""),i=i.replace(/\s+xmlns:r="[^"]*"/g,""),i=i.replace(/\s+xmlns:wp="[^"]*"/g,""),a+=i}return C(`[OxmlEngine] Stripping table wrapper, serializing ${n.length} paragraphs`),C(`[OxmlEngine] Paragraph XML preview: ${a.substring(0,200)}...`),hi(a)}function hi(e){return yn(e)}function wi(e){if(!e)return null;let t=typeof e.getAttributeNS=="function"?e.getAttributeNS(di,"paraId"):null;return t||e.getAttribute("w14:paraId")||e.getAttribute("w:paraId")||e.getAttribute("paraId")||null}function yr(e){return z(e,"t")?e.textContent||"":z(e,"br")||z(e,"cr")?`
142
+ `:z(e,"tab")?" ":z(e,"noBreakHyphen")?"\u2011":""}function Er(e){return z(e,"t")||z(e,"br")||z(e,"cr")||z(e,"tab")||z(e,"noBreakHyphen")}function Gn(e){let t="",r=[];return e.forEach((n,a)=>{let o=n.parentNode;for(let i=n.firstChild;i;i=i.nextSibling)if(z(i,"r"))t+=jn(i,n,o,t.length,r).text;else if(z(i,"hyperlink"))for(let s=i.firstChild;s;s=s.nextSibling)z(s,"r")&&(t+=jn(s,n,o,t.length,r).text);t=je(t,a,e.length)}),{fullText:t,textSpans:r}}function jn(e,t,r,n,a){let o=$(e,"w:rPr"),i=n,s=[];for(let l=e.firstChild;l;l=l.nextSibling)if(z(l,"t")){let c=l.textContent||"";if(c.length===0)continue;a.push({charStart:i,charEnd:i+c.length,textElement:l,runElement:e,paragraph:t,container:r,rPr:o}),i+=c.length,s.push(c)}else if(Er(l)){let c=yr(l);a.push({charStart:i,charEnd:i+1,textElement:l,runElement:e,paragraph:t,container:r,rPr:o}),i+=1,s.push(c)}return{text:s.join("")}}function Vn(e){let t=e.slice().sort((a,o)=>a.charStart-o.charStart||a.charEnd-o.charEnd),r=t.map(a=>a.charStart),n=t.map(a=>a.charEnd);return{spans:t,starts:r,ends:n}}function Xt(e,t,r,n){if(r<=t||e.spans.length===0)return;let a=Pr(e.ends,t);for(;a<e.spans.length;){let o=e.spans[a];if(o.charStart>=r)break;n(o),a++}}function Kn(e,t){if(e.spans.length===0)return null;let r=Pr(e.starts,t)-1;if(r<0)return null;let n=e.spans[r];return t>=n.charStart&&t<n.charEnd?n:null}function Yn(e,t){let r=bi(e.ends,t);return r<e.spans.length&&e.ends[r]===t?e.spans[r]:null}function Zn(e,t){let r=Pr(e.ends,t)-1;return r>=0?e.spans[r]:null}function Pr(e,t){let r=0,n=e.length;for(;r<n;){let a=r+n>>1;e[a]<=t?r=a+1:n=a}return r}function bi(e,t){let r=0,n=e.length;for(;r<n;){let a=r+n>>1;e[a]<t?r=a+1:n=a}return r}function Sr(e){let t=[],r=0;for(let n of Array.from(e.childNodes||[])){if(z(n,"rPr")||!Er(n))continue;let a=yr(n);a.length!==0&&(t.push({node:n,start:r,end:r+a.length,text:a}),r+=a.length)}return t}function mt(e){return e.length===0?0:e[e.length-1].end}function Je(e,t,r,n,a){let o=[];return n<=r||t.forEach(i=>{let s=Math.max(r,i.start),l=Math.min(n,i.end);if(l<=s)return;let c=s-i.start,u=l-i.start,m=i.text.slice(c,u);o.push(xi(e,i.node,m,a))}),o}function Ir(e,t,r){let n=A(e,"w:r");return r&&n.appendChild(r.cloneNode(!0)),t.forEach(a=>n.appendChild(a)),n}function pt(e,t,r,n,a){if(n.length===0)return null;let o=Ir(e,n,a);return t.insertBefore(o,r),o}function xi(e,t,r,n){if(n){let o=A(e,"w:delText");return o.setAttribute("xml:space","preserve"),o.textContent=r,o}if(z(t,"t")){let o=t.cloneNode(!1);return o.textContent=r,/^\s|\s$/.test(r)&&o.setAttribute("xml:space","preserve"),o}if(r===`
143
+ `&&(z(t,"br")||z(t,"cr"))||r===" "&&z(t,"tab")||r==="\u2011"&&z(t,"noBreakHyphen"))return t.cloneNode(!0);let a=A(e,"w:t");return a.setAttribute("xml:space","preserve"),a.textContent=r,a}function Jn(e,t,r,n,a,o,i){let s={};a.length>0&&a.forEach(N=>Object.assign(s,N.format));let l=t.rPr,c=N=>{if(!l)return!1;for(let y=l.firstChild;y;y=y.nextSibling)if(z(y,N))return!0;return!1},u={bold:c("b"),italic:c("i"),underline:c("u"),strikethrough:c("strike")};if(!["bold","italic","underline","strikethrough"].some(N=>!!s[N]!==u[N]))return!1;let p=t.runElement.parentNode;if(!p)return!1;let g=t.textElement.textContent||"",d=t.charStart,w=r-d,h=n-d,b=g.substring(0,w),x=g.substring(w,h),E=g.substring(h);if(b.length>0){let N=$e(e,b,l,!1);p.insertBefore(N,t.runElement)}let v=Ye(e,l,s,o,i),P=Nr(e,x,v,!1);if(p.insertBefore(P,t.runElement),E.length>0){let N=$e(e,E,l,!1);p.insertBefore(N,t.runElement)}return p.removeChild(t.runElement),!0}function qn(e,t,r,n,a,o){let i=[];if(Xt(t,r,n,c=>{i.push(c)}),i.length===0)return!1;let s=new Map;i.forEach(c=>{c.runElement?.parentNode&&(s.has(c.runElement)||s.set(c.runElement,[]),s.get(c.runElement).push(c))});let l=!1;return s.forEach((c,u)=>{let m=u.parentNode;if(!m)return;let f=Sr(u);if(f.length===0)return;let p=1/0,g=-1/0;if(c.forEach(b=>{let x=f.find(P=>P.node===b.textElement);if(!x)return;let E=Math.max(0,r-b.charStart),v=Math.min(b.charEnd-b.charStart,n-b.charStart);v<=E||(p=Math.min(p,x.start+E),g=Math.max(g,x.start+v))}),!Number.isFinite(p)||g<=p)return;let d=Je(e,f,0,p,!1),w=Je(e,f,p,g,!0),h=Je(e,f,g,mt(f),!1);if(pt(e,m,u,d,c[0].rPr),o&&w.length>0){let b=Ir(e,w,c[0].rPr),x=Fe(e,"del",b,a);m.insertBefore(x,u)}pt(e,m,u,h,c[0].rPr),m.removeChild(u),l=!0}),l}function Qn(e,t,r,n,a,o=[],i=0,s=!0,l=null){let c=Kn(t,r);if(!c&&r>0&&(c=Yn(t,r)),!c&&r>0&&(c=Zn(t,r)),!c&&t.spans.length>0&&(c=t.spans[t.spans.length-1]),!c)return l?(Dt(e,l,null,n,null,a,o,i,s),!0):!1;let u=c.runElement.parentNode;if(!u)return l?(Dt(e,l,null,n,c.rPr,a,o,i,s),!0):!1;let m=Sr(c.runElement),f=m.find(d=>d.node===c.textElement),p=f?f.start+Math.max(0,Math.min(r-c.charStart,c.charEnd-c.charStart)):r<=c.charStart?0:mt(m);if(p>0&&p<mt(m)){let d=Je(e,m,0,p,!1),w=Je(e,m,p,mt(m),!1);return pt(e,u,c.runElement,d,c.rPr),Dt(e,u,c.runElement,n,c.rPr,a,o,i,s),pt(e,u,c.runElement,w,c.rPr),u.removeChild(c.runElement),!0}let g=r<=c.charStart?c.runElement:c.runElement.nextSibling;return Dt(e,u,g,n,c.rPr,a,o,i,s),!0}function Dt(e,t,r,n,a,o,i,s,l){let c=we(i,s,s+n.length);if(c.length===0){let m=$e(e,n,a,!1);if(l){let f=Fe(e,"ins",m,o);t.insertBefore(f,r)}else t.insertBefore(m,r);return}let u=Ft(e,n,a,c,s,o,l);if(l){let m=Fe(e,"ins",null,o);u.forEach(f=>m.appendChild(f)),t.insertBefore(m,r)}else u.forEach(m=>t.insertBefore(m,r))}function ea(e,t,r,n,a,o,i=!0,s=null){let l=s?[s]:xe(e),{fullText:c,textSpans:u}=Gn(l),m=st(c,r),f=Vn(u),p=0,g=0,d=!1;for(let[w,h]of m)if(w===0){let b=h.length,x=p,E=p+b;Xt(f,x,E,v=>{let P=Math.max(v.charStart,x),N=Math.min(v.charEnd,E),y=N-P,I=P-x,R=g+I,M=R+y,L=we(o,R,M);Jn(e,v,P,N,L,a,i)&&(d=!0)}),p+=b,g+=b}else if(w===-1)qn(e,f,p,p+h.length,a,i)&&(d=!0),p+=h.length;else if(w===1){let b=h.replace(/\n/g," ");b.trim().length>0&&Qn(e,f,p,b,a,o,g,i,l[0]||null)&&(d=!0),g+=h.length}return te({oxml:n.serializeToString(e),hasChanges:d})}function ta(e){let t=0;return{at(r){for(;t<e.length&&e[t].end<=r;)t++;let n=e[t];return n&&n.start<=r&&r<n.end?n:null}}}function Ni(e){let t=new Map;return e.forEach(r=>{t.has(r.start)||t.set(r.start,[]),t.get(r.start).push(r)}),t}function ra(e,t){let r=e.documentElement,n=r.nodeName==="w:body"||r.nodeName.endsWith(":package"),a=xe(e),o=$(e,"w:body");!o&&n&&(o=r);let i="",s=[],l=[],c=[],u=new Map,m=new Map,f=57344,p=new Set;a.forEach((y,I)=>{let R=i.length;Array.from(y.childNodes).forEach(ye=>{i=Ti(ye,i,s,c,u,m,f),u.size>m.size&&f++}),i=je(i,I,a.length);let M=i.length,L=$(y,"w:pPr"),le=y.parentNode;le&&p.add(le),l.push({start:R,end:M,pPr:L,container:le||o})});let g=t;m.forEach((y,I)=>{let R=I.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");g=g.replace(new RegExp(R,"g"),y)}),g=vi(i,g,u);let d=new Map;p.forEach(y=>{d.set(y,e.createDocumentFragment())}),o&&!d.has(o)&&d.set(o,e.createDocumentFragment()),d.has(e)||d.set(e,e.createDocumentFragment());let w=new Map,h=new Set(l.map(y=>y.start)),b=ta(l),x=ta(s),E=Ni(c);return{paragraphs:a,body:o||e,paragraphMap:l,paragraphStarts:h,propertyMap:s,sentinelMap:c,sentinelMapByStart:E,referenceMap:u,tokenToCharMap:m,containerFragments:d,replacementContainers:w,originalFullText:i,processedModifiedText:g,getParagraphInfo:y=>{let I=b.at(y);return I||(l.length>0?l[l.length-1]:{start:0,end:0,pPr:null,container:o||e})},getRunProperties:y=>{let I=x.at(y);return I?{rPr:I.rPr,wrapper:I.wrapper}:{rPr:null}},getPropertySpanLength:(y,I)=>{let R=x.at(y);return R?Math.min(R.end-y,I):1},isParagraphStart:y=>h.has(y)}}function vi(e,t,r){let n=t;for(let a of r.keys()){if(n.includes(a))continue;let o=e.indexOf(a);if(o<0)continue;let i=e.slice(0,o),s=e.slice(o+a.length);if(i&&n.startsWith(i)){n=`${n.slice(0,i.length)}${a}${n.slice(i.length)}`;continue}if(s&&n.endsWith(s)){let l=n.length-s.length;n=`${n.slice(0,l)}${a}${n.slice(l)}`}}return n}function Ti(e,t,r,n,a,o,i){return e.nodeName==="w:r"?yi(e,t,r,n,a,o,i):e.nodeName==="w:hyperlink"?Ei(e,t,r):["w:sdt","w:oMath","m:oMath","w:bookmarkStart","w:bookmarkEnd"].includes(e.nodeName)?(n.push({start:t.length,node:e}),t+"\uFFFC"):(["w:commentRangeStart","w:commentRangeEnd"].includes(e.nodeName)&&n.push({start:t.length,node:e,isCommentMarker:!0}),t)}function yi(e,t,r,n,a,o,i){let s=t,l=$(e,"w:rPr");return Array.from(e.childNodes).forEach(c=>{if(c.nodeName==="w:t"){let u=c.textContent||"";u.length>0&&(r.push({start:s.length,end:s.length+u.length,rPr:l}),s+=u)}else if(c.nodeName==="w:br"||c.nodeName==="w:cr")s+=`
144
+ `,r.push({start:s.length-1,end:s.length,rPr:l});else if(c.nodeName==="w:tab")s+=" ",r.push({start:s.length-1,end:s.length,rPr:l});else if(c.nodeName==="w:noBreakHyphen")s+="\u2011",r.push({start:s.length-1,end:s.length,rPr:l});else if(["w:drawing","w:pict","w:object","w:fldChar","w:instrText","w:sym"].includes(c.nodeName)){let u=$(c,"w:txbxContent"),m=c.nodeName==="w:pict"&&!!u;n.push({start:s.length,node:c,isTextBox:m,originalContainer:m?u:void 0}),s+="\uFFFC",r.push({start:s.length-1,end:s.length,rPr:l})}else if(c.nodeName==="w:footnoteReference"||c.nodeName==="w:endnoteReference"){let u=c.getAttribute("w:id");if(u){let f=`{{__${c.nodeName==="w:footnoteReference"?"FN":"EN"}_${u}__}}`,p=String.fromCharCode(i);a.set(p,c),o.set(f,p),s+=p,r.push({start:s.length-1,end:s.length,rPr:l})}}else c.nodeName==="w:commentReference"&&n.push({start:s.length,node:c,isCommentMarker:!0})}),s}function Ei(e,t,r){let n=t;return Array.from(e.childNodes).forEach(a=>{if(a.nodeName!=="w:r")return;let o=$(a,"w:rPr");Pe(a,"w:t").forEach(s=>{let l=s.textContent||"";l.length!==0&&(r.push({start:n.length,end:n.length+l.length,rPr:o,wrapper:e}),n+=l)})}),n}function aa(e,t,r,n,a,o,i=!0){let{paragraphs:s,paragraphMap:l,containerFragments:c,sentinelMapByStart:u,referenceMap:m,replacementContainers:f,getParagraphInfo:p,getRunProperties:g,getPropertySpanLength:d,isParagraphStart:w}=r,h=y=>{let I=A(e,"w:p");return y&&I.appendChild(y.cloneNode(!0)),I},b=p(0),x=h(b.pPr),E=c.get(b.container);E&&E.appendChild(x);let v=0,P=0,N=new WeakSet;for(let[y,I]of t){if(y===0||y===-1){let R=y===0?"equal":"delete",M=0;for(;M<I.length;){let L=v+M,le=g(L),ye=d(L,I.length-M),he=I.substring(M,M+ye);x=na(e,he,R,le.rPr,le.wrapper,L,x,c,u,m,f,p,h,a,o,P,i,N).currentParagraph,y===0&&(P+=ye),M+=ye}v+=I.length;continue}if(y===1){let R=v>0&&!w(v)?g(v-1):g(v);x=na(e,I,"insert",R.rPr,R.wrapper,v,x,c,u,m,f,p,h,a,o,P,i,N).currentParagraph,P+=I.length}}return s.forEach(y=>{y.parentNode&&y.parentNode.removeChild(y)}),c.forEach((y,I)=>{let M=f.get(I)||I;if(M.nodeType===9){let L=y.firstChild;if(L)for(M.appendChild(L);y.firstChild;)M.documentElement.appendChild(y.firstChild);return}M.appendChild(y)}),{oxml:n.serializeToString(e),hasChanges:!0}}function na(e,t,r,n,a,o,i,s,l,c,u,m,f,p,g=[],d=0,w=!0,h=new WeakSet){let b=o,x=d,E=i;return t.split(/([\n\uFFFC]|[\uE000-\uF8FF])/).forEach(P=>{let N=l.get(b)||[];if(N.filter(R=>R.isCommentMarker&&!h.has(R.node)).forEach(R=>{if(h.add(R.node),R.node.nodeName==="w:commentReference"){let M=A(e,"w:r");M.appendChild(R.node.cloneNode(!0)),E.appendChild(M)}else E.appendChild(R.node.cloneNode(!0))}),P===`
145
+ `){let R=m(b+1),M=f(R.pPr);w&&r==="insert"?Bn(e,M,p):w&&r==="delete"&&Bt(e,M,p);let L=s.get(R.container);L&&(L.appendChild(M),E=M),b++,r!=="delete"&&x++;return}if(P==="\uFFFC"){let R=N.find(M=>!M.isCommentMarker)||N[0];if(R){let M=R.node.cloneNode(!0);if(R.isTextBox&&R.originalContainer){let L=$(M,"w:txbxContent");if(L){for(;L.firstChild;)L.removeChild(L.firstChild);u.set(R.originalContainer,L)}}E.appendChild(M)}b++,r!=="delete"&&x++;return}if(c.has(P)){if(r!=="delete"){let R=c.get(P);if(R){let M=R.cloneNode(!0),L=A(e,"w:r");n&&L.appendChild(n.cloneNode(!0)),L.appendChild(M),E.appendChild(L)}}b++,r!=="delete"&&x++;return}if(P.length===0)return;let I=E;if(a){let R=a.cloneNode(!1);I=R,E.appendChild(R)}if(r==="delete"){let R=A(e,"w:r");n&&R.appendChild(n.cloneNode(!0));let M=A(e,"w:delText");if(M.setAttribute("xml:space","preserve"),M.textContent=P,R.appendChild(M),w){let L=Fe(e,"del",R,p);I.appendChild(L)}}else{let R=we(g,x,x+P.length),M=Ft(e,P,n,R,x,p,w);if(r==="insert"&&w){let L=Fe(e,"ins",null,p);M.forEach(le=>L.appendChild(le)),I.appendChild(L)}else M.forEach(L=>I.appendChild(L))}r!=="delete"&&(x+=P.length),b+=P.length}),{currentParagraph:E}}function Cr(e,t,r,n,a,o,i=!0){let s=ra(e,r);if(s.paragraphs.length===0)return te({oxml:n.serializeToString(e),hasChanges:!1});let l=st(s.originalFullText,s.processedModifiedText);return te(aa(e,l,s,n,a,o,i))}function Ce(e,t){return te({oxml:e.serializeToString(t),hasChanges:!1})}function oa(e,t,r,n,a,o=!0){let i=ue(e,S,"tbl"),s=me(t),l=s.rows.length>0||s.headers.length>0;if(i.length===0||!l)return Ce(r,e);let c=i[0],u=hr(c),m=Sn(u,s);if(m.length===0)return Ce(r,e);let p=In(u,m,{generateRedlines:o,author:a}),g=`<root xmlns:w="${S}">${p}</root>`,w=(n||B()).parseFromString(g,"application/xml"),h=j(w);if(h)return Z("[OxmlEngine] Failed to parse reconciled table OOXML:",h.textContent),Ce(r,e);let b=Rt(w,S,"tbl");if(!b)return Z("[OxmlEngine] No table found in reconciled OOXML"),Ce(r,e);let x=e.importNode(b,!0);return c.parentNode.replaceChild(x,c),te({oxml:r.serializeToString(e),hasChanges:!0})}function ia(e,t,r,n,a,o){let i=me(t);if(!i||i.rows.length===0&&i.headers.length===0)return C("[OxmlEngine] Failed to parse table data from Markdown"),Ce(r,e);let s=_e(i,{generateRedlines:o,author:a}),l=n||B(),c=l.parseFromString(`<root xmlns:w="${S}">${s}</root>`,"application/xml"),u=j(c);if(u)return Z("[OxmlEngine] Failed to parse generated table OOXML:",u.textContent),Ce(r,e);let m=H(c,S,"tbl");if(m||(m=H(c,S,"ins")),!m)return Z("[OxmlEngine] No table element found in generated OOXML"),Ce(r,e);let f=e,p=V(f,S,"p");if(p.length===0)return C("[OxmlEngine] No paragraphs found to replace"),Ce(r,f);let g=p[0],d=g.parentNode;if(d&&d.nodeType===9){let h=l.parseFromString(`<w:document xmlns:w="${S}"><w:body/></w:document>`,"application/xml"),b=H(h,S,"body");p.forEach(x=>b.appendChild(h.importNode(x,!0))),f=h,p=V(f,S,"p"),g=p[0],d=g.parentNode}let w=f.importNode(m,!0);return o?p.forEach(h=>{Bt(f,h,a),V(h,S,"r").forEach(x=>{V(x,S,"t").forEach(N=>{let y=N.textContent||"";if(y.trim()){let I=A(f,"w:delText");I.textContent=y,N.parentNode.replaceChild(I,N)}});let v=A(f,"w:del"),P=ee(a);v.setAttribute("w:id",String(P.id)),v.setAttribute("w:author",P.author),v.setAttribute("w:date",P.date),x.parentNode.insertBefore(v,x),v.appendChild(x)})}):p.slice(1).forEach(h=>h.parentNode.removeChild(h)),d.insertBefore(w,g),o||d.removeChild(g),C("[OxmlEngine] Text-to-table transformation complete"),te({oxml:r.serializeToString(f),hasChanges:!0})}function Xe(e,t){if(!e||!e.attributes)return"";for(let r of Array.from(e.attributes))if((r.localName||"").toLowerCase()===t.toLowerCase())return String(r.value||"");return String(e.getAttribute?.(`w:${t}`)||e.getAttribute?.(t)||"")}function ca(e){return typeof e=="string"?e.trim().toLowerCase():""}function Pi(e){return!!e&&e.nodeType===1}function Ae(e,t){return Pi(e)&&e.namespaceURI===S&&String(e.localName||"").toLowerCase()===t.toLowerCase()}function re(e,t){return Array.from(e.getElementsByTagNameNS(S,t))}function Ar(e={}){if(e?.allAuthors===!0)return{valid:!0,allAuthors:!0,normalizedAuthor:""};let t=ca(e?.author);return t?{valid:!0,allAuthors:!1,normalizedAuthor:t}:{valid:!1,allAuthors:!1,normalizedAuthor:"",warning:"No author provided. Pass { author } or set { allAuthors: true }."}}function ie(e,t){if(t.allAuthors)return!0;let r=ca(Xe(e,"author"));return!!r&&r===t.normalizedAuthor}function Rr(e,t){let n=B().parseFromString(e,"application/xml"),a=j(n);return a?{xmlDoc:null,serializer:null,warning:`${t}: ${a.textContent||"parse error"}`}:{xmlDoc:n,serializer:Q(),warning:null}}function Y(e){return e?.parentNode?(e.parentNode.removeChild(e),!0):!1}function zt(e){let t=e?.parentNode;if(!t)return!1;for(;e.firstChild;)t.insertBefore(e.firstChild,e);return t.removeChild(e),!0}function Wt(e){let t=e?.parentNode;return Ae(t,"trPr")&&Ae(t?.parentNode,"tr")}function Or(e){let t=e?.parentNode,r=t?.parentNode,n=r?.parentNode;return Ae(t,"rPr")&&Ae(r,"pPr")&&Ae(n,"p")}function ua(e){return Or(e)?e.parentNode.parentNode.parentNode:null}function Si(e){let t=e?.nextSibling||null;for(;t;){if(Ae(t,"p"))return t;t=t.nextSibling}return null}function fa(e){if(!e?.parentNode)return!1;let t=Si(e);if(!t)return Y(e);let r=Array.from(e.childNodes||[]).filter(a=>!Ae(a,"pPr")),n=t.firstChild||null;for(let a of r)t.insertBefore(a,n);return Y(e)}function kr(e,t={}){let r=[],n=Ar(t);if(!n.valid)return{oxml:e,hasChanges:!1,acceptedCount:0,warnings:[n.warning]};let a=Rr(e,"Failed to parse OOXML");if(!a.xmlDoc)return{oxml:e,hasChanges:!1,acceptedCount:0,warnings:[a.warning]};let{xmlDoc:o,serializer:i}=a,s=0;for(let c of re(o,"ins"))if(!(!c.parentNode||!ie(c,n))){if(Or(c)){Y(c)&&(s+=1);continue}if(Wt(c)){Y(c)&&(s+=1);continue}zt(c)&&(s+=1)}for(let c of re(o,"del")){if(!c.parentNode||!ie(c,n))continue;let u=ua(c);if(u){fa(u)&&(s+=1);continue}if(Wt(c)){let m=c.parentNode?.parentNode;Y(m)&&(s+=1);continue}Y(c)&&(s+=1)}for(let c of re(o,"moveFrom"))!c.parentNode||!ie(c,n)||Y(c)&&(s+=1);for(let c of re(o,"moveTo"))!c.parentNode||!ie(c,n)||zt(c)&&(s+=1);s+=ma(o,n);let l=["rPrChange","pPrChange","tblPrChange","trPrChange","tcPrChange"];for(let c of l)for(let u of re(o,c))!u.parentNode||!ie(u,n)||Y(u)&&(s+=1);return{oxml:i.serializeToString(o),hasChanges:s>0,acceptedCount:s,warnings:r}}function sa(e,t){for(let r of Array.from(t.getElementsByTagNameNS(S,"delText"))){let n=A(e,"w:t"),a=r.getAttribute("xml:space");for(a&&n.setAttribute("xml:space",a);r.firstChild;)n.appendChild(r.firstChild);r.parentNode?.replaceChild(n,r)}}function Ii(e,t){let r=e?.parentNode;if(!r)return!1;let n=t.endsWith("Change")?t.slice(0,-6):"";if(!n||String(r.localName||"").toLowerCase()!==n.toLowerCase()||r.namespaceURI!==S)return Y(e);let a=Array.from(e.childNodes||[]).find(i=>i.nodeType===1&&i.namespaceURI===S&&String(i.localName||"").toLowerCase()===n.toLowerCase());if(!a)return Y(e);let o=Array.from(a.childNodes||[]);for(;r.firstChild;)r.removeChild(r.firstChild);for(let i of o){let s=Ci(r.ownerDocument,i);r.appendChild(s)}return!0}function Ci(e,t){return e&&typeof e.importNode=="function"?e.importNode(t,!0):t.cloneNode(!0)}function la(e,t,r){let n=new Set;for(let a of re(e,t)){if(!ie(a,r))continue;let o=Xe(a,"id");o&&n.add(o)}return n}function ma(e,t){let r=0,n=la(e,"moveFromRangeStart",t),a=la(e,"moveToRangeStart",t),o=[["moveFromRangeStart",n,!0],["moveFromRangeEnd",n,!1],["moveToRangeStart",a,!0],["moveToRangeEnd",a,!1]];for(let[i,s,l]of o)for(let c of re(e,i)){if(!c.parentNode)continue;let u=Xe(c,"id");u&&(t.allAuthors||s.has(u)||l&&ie(c,t))&&Y(c)&&(r+=1)}return r}function Ai(e,t={}){let r=[],n=Ar(t);if(!n.valid)return{oxml:e,hasChanges:!1,rejectedCount:0,warnings:[n.warning]};let a=Rr(e,"Failed to parse OOXML");if(!a.xmlDoc)return{oxml:e,hasChanges:!1,rejectedCount:0,warnings:[a.warning]};let{xmlDoc:o,serializer:i}=a,s=0;for(let c of re(o,"ins")){if(!c.parentNode||!ie(c,n))continue;let u=ua(c);if(u){fa(u)&&(s+=1);continue}if(Wt(c)){let m=c.parentNode?.parentNode;Y(m)&&(s+=1);continue}Y(c)&&(s+=1)}for(let c of re(o,"del"))if(!(!c.parentNode||!ie(c,n))){if(Or(c)){Y(c)&&(s+=1);continue}if(Wt(c)){Y(c)&&(s+=1);continue}sa(o,c),zt(c)&&(s+=1)}for(let c of re(o,"moveFrom"))!c.parentNode||!ie(c,n)||(sa(o,c),zt(c)&&(s+=1));for(let c of re(o,"moveTo"))!c.parentNode||!ie(c,n)||Y(c)&&(s+=1);s+=ma(o,n);let l=["rPrChange","pPrChange","tblPrChange","trPrChange","tcPrChange"];for(let c of l)for(let u of re(o,c))!u.parentNode||!ie(u,n)||Ii(u,c)&&(s+=1);return{oxml:i.serializeToString(o),hasChanges:s>0,rejectedCount:s,warnings:r}}function Ri(e,t){let r=new Set,n=re(e,"comment");for(let a of n){if(!ie(a,t))continue;let o=Xe(a,"id");o&&r.add(o)}return{targetIds:r,commentNodes:n}}function Oi(e,t){let r=0;for(let n of e){let a=Xe(n,"id");!a||!t.has(a)||Y(n)&&(r+=1)}return r}function ki(e){return Ae(e,"r")?Array.from(e.childNodes||[]).filter(r=>{if(r.nodeType===3)return String(r.nodeValue||"").trim().length>0;if(r.nodeType!==1)return!1;if(r.namespaceURI!==S)return!0;let n=String(r.localName||"").toLowerCase();return n!=="rpr"&&n!=="commentreference"}).length===0:!1}function Mi(e,t){let r=0,n=["commentRangeStart","commentRangeEnd","commentReference"];for(let a of n)for(let o of re(e,a)){if(!o.parentNode)continue;let i=Xe(o,"id");if(!(!i||!t.has(i))){if(a==="commentReference"&&ki(o.parentNode)){Y(o.parentNode)&&(r+=1);continue}Y(o)&&(r+=1)}}return r}function Li(e,t={}){let r=[],n=Ar(t);if(!n.valid)return{oxml:e,hasChanges:!1,commentsRemoved:0,referencesRemoved:0,warnings:[n.warning]};let a=Rr(e,"Failed to parse OOXML");if(!a.xmlDoc)return{oxml:e,hasChanges:!1,commentsRemoved:0,referencesRemoved:0,warnings:[a.warning]};let{xmlDoc:o,serializer:i}=a,{targetIds:s,commentNodes:l}=Ri(o,n);if(n.allAuthors)for(let m of["commentRangeStart","commentRangeEnd","commentReference"])for(let f of re(o,m)){let p=Xe(f,"id");p&&s.add(p)}let c=Oi(l,s),u=Mi(o,s);return{oxml:i.serializeToString(o),hasChanges:c>0||u>0,commentsRemoved:c,referencesRemoved:u,warnings:r}}async function Mr(e,t,r,n={}){let a=n.generateRedlines??!0,o=n.author||J(),i=B(),s=Q(),l=U=>{let X={...U};return X.status||(X.status=X.hasChanges?"ok":"no-op"),te(X)},c=()=>l({oxml:e,hasChanges:!1}),u;try{u=i.parseFromString(e,"text/xml")}catch(U){return Z("[OxmlEngine] Failed to parse OXML:",U),l({oxml:e,hasChanges:!1,status:"error",error:{code:"PARSE_ERROR",message:"Could not parse OOXML input."}})}let m=j(u);if(m)return Z("[OxmlEngine] XML parse error:",m.textContent),l({oxml:e,hasChanges:!1,status:"error",error:{code:"PARSE_ERROR",message:m.textContent||"Could not parse OOXML input."}});if(cr(u),xr(u))if((n.existingRevisions||"reject-input")==="accept-all-first"){C("[OxmlEngine] Existing revisions detected; accepting all input revisions before redlining"),e=kr(e,{allAuthors:!0}).oxml,u=i.parseFromString(e,"text/xml");let ge=j(u);if(ge)return Z("[OxmlEngine] XML parse error after accepting existing revisions:",ge.textContent),l({oxml:e,hasChanges:!1,status:"error",error:{code:"PARSE_ERROR",message:"Could not parse OOXML after accepting existing revisions."}});cr(u)}else return C("[OxmlEngine] Existing revisions detected; rejecting input per existingRevisions policy"),l({oxml:e,hasChanges:!1,status:"error",error:{code:"EXISTING_REVISIONS",message:'Input OOXML contains existing tracked changes. Pass existingRevisions: "accept-all-first" to normalize before redlining.'}});let f=Un(u,t,n);if(f.hasTableWrapper&&f.targetParagraph&&!n._isolatedTableCell){C("[OxmlEngine] Isolating table-cell paragraph before diff");let U=ft(u,f.targetParagraph,s);return Mr(U,t,r,{...n,_isolatedTableCell:!0})}let p=ga(r),{cleanText:g,formatHints:d}=ne(p),w=g.trim()!==t.trim(),h=d.length>0,{existingFormatHints:b,textSpans:x,paragraphs:E}=Mn(u),v=b.length>0,P=x.map(U=>_i(U)).join("");if(w&&typeof t=="string"&&t.trim()&&!t.includes(`
146
+ `)&&!P.includes(t.trim())&&!P.replace(/[\t\n\u2011]/g,"").includes(t.trim().replace(/[\t\n\u2011]/g,""))&&!pa(P).includes(pa(t)))return C("[OxmlEngine] Target text not found in OOXML"),l({oxml:e,hasChanges:!1,status:"error",error:{code:"TARGET_NOT_FOUND",message:"Original text was not found in the supplied OOXML."}});let N=null,y=()=>(N||(N=$t(u,E,x)),N),I=(U=null)=>{let X=Hn(u,t,d,s,o,a,U);return X.useNativeApi?(C("[OxmlEngine] Format-only surgical fallback signal encountered; retrying with OOXML reconstruction fallback"),Cr(u,t,g,s,o,d,a)):X};C(`[OxmlEngine] Text changes: ${w}, New format hints: ${d.length}, Existing format hints: ${b.length}`);let R=!w&&!h&&v;if(!w&&!h&&!v)return C("[OxmlEngine] No text changes, no format hints, and no existing formatting detected"),c();if(R){C("[OxmlEngine] Format REMOVAL detected: applying surgical replacement in OOXML");let U=f,X=U.targetParagraph||null;if(!X){let Et=$n(y(),t);Et&&(X=Et.paragraph)}let ge=b;X&&(ge=b.filter(Et=>Dn(Et.run)===X));let Jr=Wn(u,x,ge,s,o,a);return U.hasTableWrapper&&X?l({oxml:ft(u,X,s),hasChanges:Jr.hasChanges}):l(Jr)}if(!w&&h){C(`[OxmlEngine] Format-only change detected: ${d.length} format hints`);let U=f,X={textSpans:x,paragraphs:E,paragraphInfos:y()};if(U.hasTableWrapper&&U.targetParagraph){C("[OxmlEngine] Table cell context: applying formatting to target paragraph only");let ge=I(X);return C("[OxmlEngine] Stripping table wrapper for table cell paragraph (format-only)"),l({oxml:ft(u,U.targetParagraph,s),hasChanges:ge.hasChanges})}return l(I(X))}let L=ue(u,S,"tbl").length>0,le=/^\|.+\|/.test(g.trim())&&g.includes(`
147
+ `),ye=Ct(g),he=f;if(C(`[OxmlEngine] Mode: ${L?"SURGICAL":"RECONSTRUCTION"}, formatHints: ${d.length}, isMarkdownTable: ${le}, isTargetList: ${ye}, isTableCellParagraph: ${he.isTableCellParagraph}`),le&&!L)return C("[OxmlEngine] Text-to-table transformation: generating new table from Markdown"),l(ia(u,g,s,i,o,a));if(L&&le)return l(oa(u,g,s,i,o,a));if(L){let U=he.hasTableWrapper&&he.targetParagraph?he.targetParagraph:null;U&&C("[OxmlEngine] Table cell edit: scoping surgical mode to target paragraph");let X=ea(u,t,g,s,o,d,a,U);return he.hasTableWrapper&&X.hasChanges&&he.targetParagraph?(C("[OxmlEngine] Stripping table wrapper for table cell paragraph (surgical mode)"),l({oxml:ft(u,he.targetParagraph,s),hasChanges:!0})):l(X)}if(ye){C("[OxmlEngine] \u{1F3AF} Using reconciliation pipeline for list generation");let X=await new Be({author:o,generateRedlines:a}).execute(e,r,{xmlDoc:u});if(X.isValid&&X.ooxml&&X.ooxml!==e){C(`[OxmlEngine] Wrapping list OOXML with numbering definitions, includeNumbering=${X.includeNumbering}`);let ge=Ie(X.ooxml,{includeNumbering:X.includeNumbering??!0,numberingXml:X.numberingXml});return C(`[OxmlEngine] \u2705 Wrapped OOXML length: ${ge.length}`),l({oxml:ge,hasChanges:!0})}return c()}return l(Cr(u,t,g,s,o,d,a))}function pa(e){return String(e||"").replace(/[\t\n\u2011]/g," ").replace(/\s+/g," ").trim()}function _i(e){let t=e?.textElement,r=String(t?.localName||t?.nodeName||"").replace(/^.*:/,"");return r==="tab"?" ":r==="br"||r==="cr"?`
148
+ `:r==="noBreakHyphen"?"\u2011":t?.textContent||""}function ga(e){let t=e;return t=t.replace(/^(Here is the redline:|Here is the text:|Sure, I can help:|Here's the updated text:)\s*/i,""),t=t.replace(/\$\\text\{/g,"").replace(/\}\$/g,""),t=t.replace(/\$([^0-9\n]+?)\$/g,"$1"),t=t.replace(/\\r\\n/g,`
145
149
  `).replace(/\\n/g,`
146
- `),t}function ge(e){return Sr(e,"application/xml")}function Me(e){return j(e)}function ar(e){return Array.from(e||[])}var te="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function ir(e,t){if(!e)return[];if(typeof e.getElementsByTagNameNS=="function"){let n=ar(e.getElementsByTagNameNS("*",t));if(n.length>0)return n}if(typeof e.getElementsByTagName!="function")return[];let r=ar(e.getElementsByTagName(`w:${t}`));return r.length>0?r:ar(e.getElementsByTagName(t))}function Xi(e){return ir(e,"t").map(r=>r.textContent||"").join("")}function W(e){return e?Xi(e):""}function de(e){if(!e)return[];let t=ir(e,"body"),r=t.length>0?t[0]:e;return ir(r,"p")}function L(e){return String(e||"").replace(/\s+/g," ").trim()}function lr(e){let t=String(e||"").trim();return/^\|.+\|/.test(t)&&t.includes(`
147
- `)}function cr(e){if(e==null)return null;if(typeof e=="number"&&Number.isInteger(e)&&e>0)return e;let t=String(e).trim();if(!t)return null;let r=t.match(/^\[?P(\d+)(?:\.\d+)?\]?$/i);if(r)return Number.parseInt(r[1],10);let n=t.match(/^(\d+)$/);return n?Number.parseInt(n[1],10):null}function Di(e){return e==null?"":String(e).replace(/^\s*\[P\d+(?:\.\d+)?\]\s*/i,"").trim()}function zi(e){let t=String(e||""),r=t.match(/^\s*\[P(\d+)(?:\.\d+)?\]\s*/i);return r?{text:t.replace(/^\s*\[P\d+(?:\.\d+)?\]\s*/i,"").trim(),targetRef:Number.parseInt(r[1],10)}:{text:t.trim(),targetRef:null}}function Sn(e,t){return!Number.isInteger(t)||t<1?null:de(e)[t-1]||null}function He(e,t,r=te){let n=e;for(;n;){if(n.nodeType===1&&n.namespaceURI===r&&n.localName===t)return n;n=n.parentNode}return null}function Pt(e,t){let r=de(e),n=String(t||"").trim();if(!n)return null;let a=r.find(o=>W(o).trim()===n);if(a)return a;let i=L(n);return r.find(o=>L(W(o))===i)||null}function or(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=de(e),i=String(t||"").trim();if(!i)return null;let o=Pt(e,i);if(o)return o;let s=L(i),l=a.find(p=>{let g=L(W(p));return g.length>10&&s.startsWith(g)});if(l)return n(`[Fuzzy] Prefix match (target starts with paragraph): "${W(l).trim().slice(0,60)}..."`),l;let c=a.find(p=>{let g=L(W(p));return g.length>15&&s.includes(g)});if(c)return n(`[Fuzzy] Contains match: "${W(c).trim().slice(0,60)}..."`),c;let u=0,m=null,f=new Set(s.toLowerCase().split(/\s+/).filter(p=>p.length>2));for(let p of a){let g=W(p).trim();if(!g)continue;let h=L(g).toLowerCase().split(/\s+/).filter(x=>x.length>2).filter(x=>f.has(x)).length/Math.max(f.size,1);h>u&&h>.5&&(u=h,m=p)}return m?(n(`[Fuzzy] Best word-overlap match (${(u*100).toFixed(0)}%): "${W(m).trim().slice(0,60)}..."`),m):null}function In(e,t={}){let r=typeof t.onInfo=="function"?t.onInfo:()=>{},n=typeof t.onWarn=="function"?t.onWarn:()=>{},a=t.opType||"operation",i=String(t.targetText||"").trim(),o=cr(t.targetRef);if(o){let s=Sn(e,o);if(s){if(i){let l=Pt(e,i),c=W(s).trim(),u=L(c),m=L(i),f=u!==m;if(f&&l&&l!==s)return r(`[Target] [P${o}] drifted for ${a}; using strict text rematch.`),{paragraph:l,resolvedBy:"strict_text_after_ref_drift"};if(f){let p=or(e,i,{onInfo:r});if(p&&p!==s)return r(`[Target] [P${o}] drifted for ${a}; using fuzzy text rematch.`),{paragraph:p,resolvedBy:"fuzzy_text_after_ref_drift"};r(`[Target] Using [P${o}] fallback for ${a}; target text drifted.`)}else l&&l!==s&&r(`[Target] [P${o}] disambiguated duplicate target text for ${a}.`)}else r(`[Target] Using [P${o}] fallback for ${a}.`);return{paragraph:s,resolvedBy:"ref"}}n(`[WARN] Target reference [P${o}] not found; falling back to text matching for ${a}.`)}if(i){let s=Pt(e,i);if(s)return{paragraph:s,resolvedBy:"strict_text"};let l=or(e,i,{onInfo:r});if(l)return{paragraph:l,resolvedBy:"fuzzy_text"}}throw i?new Error(`Target paragraph not found: "${i}"`):o?new Error(`Target paragraph reference not found: [P${o}]`):new Error('Operation target missing: provide "target" text or "targetRef" ([P#]).')}function Cn(e){return!!He(e,"tbl")}function Wi(e,t){let r=L(t);if(!r)return[];let n=de(e),a=[];for(let i=0;i<n.length;i++){let o=n[i],s=W(o).trim();s&&L(s)===r&&a.push({paragraph:o,index:i+1,inTable:Cn(o)})}return a}function Hi(e,t,r=null){if(!Array.isArray(e)||e.length===0)return null;let n=e.slice();if(typeof r=="boolean"){let a=n.filter(i=>i.inTable===r);a.length>0&&(n=a)}return Number.isInteger(t)&&t>0&&n.sort((a,i)=>Math.abs(a.index-t)-Math.abs(i.index-t)),n[0]||null}function Ui(e){let t=de(e),r=new Map;for(let n=0;n<t.length;n++){let a=t[n],i=W(a).trim();r.set(n+1,{text:i,normalizedText:L(i),inTable:Cn(a)})}return r}function sr(e,t={}){let r=typeof t.onInfo=="function"?t.onInfo:()=>{},n=In(e,t),a=cr(t.targetRef);if(!a||n?.resolvedBy!=="ref")return n;let i=t.targetRefSnapshot instanceof Map&&t.targetRefSnapshot.get(a)||null;if(!i)return n;let o=String(t.targetText||"").trim(),s=o||i.text||"",l=L(s);if(!l||L(W(n.paragraph))===l)return n;let u=[];if(o&&u.push(o),i.text){let f=L(i.text);f&&!u.some(p=>L(p)===f)&&u.push(i.text)}let m=null;for(let f of u){let p=Wi(e,f),g=Hi(p,a,i.inTable);if(g&&(m||(m=g),g.paragraph!==n.paragraph)){m=g;break}}if(m&&m.paragraph!==n.paragraph){let f=t.opType||"operation";return r(`[Target] [P${a}] appears stale after prior edits; using strict text rematch for ${f}.`),{paragraph:m.paragraph,resolvedBy:"strict_text_after_ref_drift"}}return n}function ji(e,t,r,n={}){if(!e||!t||!r)return null;let a=n?.opType||"redline",i=n?.targetRefSnapshot||null,o=typeof n?.onInfo=="function"?n.onInfo:()=>{},s=typeof n?.onWarn=="function"?n.onWarn:()=>{},l=sr(e,{targetRef:t,opType:a,targetRefSnapshot:i,onInfo:o,onWarn:s})?.paragraph;if(!l)return null;let c=sr(e,{targetRef:r,opType:a,targetRefSnapshot:i,onInfo:o,onWarn:s})?.paragraph;if(!c)return null;let u=Array.from(e.getElementsByTagNameNS("*","p")),m=u.indexOf(l),f=u.indexOf(c);if(m<0||f<m)return null;let p=u.slice(m,f+1);if(p.length===0)return null;let g=p[0]?.parentNode||null;return!g||!p.every(d=>d&&d.parentNode===g)?null:p}function St(e,t){if(!e||typeof e.getElementsByTagNameNS!="function")return null;let r=e.getElementsByTagNameNS(te,t);if(r.length>0)return r[0];let n=e.getElementsByTagNameNS("*",t);return n.length>0?n[0]:null}function An(e){if(!e)return null;if(typeof e.getAttributeNS=="function"){let t=e.getAttributeNS(te,"val");if(t)return t}return e.getAttribute("w:val")||e.getAttribute("val")||null}function Gi(e){let t=String(e||"").trim();if(!/^\d+(?:\.\d+)+\.?$/.test(t))return null;let r=t.replace(/\.$/,"").split(".");return Math.max(0,r.length-1)}var Rn=/^(?:(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|[ivxlcIVXLC]+\.|[-*+\u2022]))\s+/;function On(e){let t=String(e||"").trim(),r=0;for(;r<4&&Rn.test(t);)t=t.replace(Rn,"").trimStart(),r++;return t.trim()}function Mn(e){let t=String(e||"").split(/\r?\n/g),r=[],n=!1;for(let a of t){let i=a.trimEnd();if(!i.trim())continue;let o=i.match(/^(\s*)((?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|[ivxlcIVXLC]+\.|[-*+\u2022]))\s+(.*)$/);if(o){n=!0;let s=o[2],l=/^[-*+\u2022]$/.test(s)?"bullet":"numbered",c=Math.floor((o[1]||"").length/2);r.push({kind:"list",markerType:l,level:c,marker:s,outlineLevel:l==="numbered"?Gi(s):null,text:On(o[3])});continue}r.push({kind:"text",text:i.trim()})}return{items:r,hasListMarkers:n}}function kn(e,t,r){return`${" ".repeat(Math.max(0,e))}${t==="numbered"?"1.":"-"} ${String(r||"").trim()}`.trimEnd()}function at(e,t){return L(e)===L(t)}function It(e,t,r){return Number.isInteger(e?.outlineLevel)?Math.max(0,e.outlineLevel):Math.max(0,t+((e?.level||0)-r))}function Vi(e,t,r){if(!Array.isArray(e)||e.length<2||!Number.isInteger(r)||r<1)return!1;let n=e[0],a=e.slice(1).filter(i=>i.kind==="list");return a.length===0||a.some(i=>i.markerType!=="bullet")||a.some(i=>Number.isInteger(i.outlineLevel))?!1:n?.kind==="text"||n?.kind==="list"&&n.markerType==="numbered"?at(n.text,t):!1}function Ki(e,t){return e.map(r=>{let n=Math.max(0,(r.ilvl||0)-t);return{...r,ilvl:Math.min(8,t+1+n)}})}function Zi(e,t,r,n){let a=e[0],i=e.slice(1).filter(o=>o.kind==="list");if(a?.kind==="text"&&at(a.text,t)&&i.length>0){let o=i[0].level;return i.map(s=>({ilvl:It(s,r,o),markerType:s.markerType||n,text:s.text}))}if(e.every(o=>o.kind==="list")){let o=e[0];if(!o||!at(o.text,t))return null;let s=o.level;return e.slice(1).map(l=>({ilvl:It(l,r,s),markerType:l.markerType||n,text:l.text})).filter(l=>l.text)}return null}function he(e){if(!e)return null;let t=St(e,"pPr");if(!t)return null;let r=St(t,"numPr");if(!r)return null;let n=St(r,"numId");if(!n)return null;let a=An(n);if(!a)return null;let i=St(r,"ilvl"),o=An(i),s=Number.parseInt(o||"0",10);return{numId:String(a),ilvl:Number.isFinite(s)?s:0}}function Ln(e){let t=he(e);if(!t)return null;let r=e.parentNode;if(!r)return null;let n=Array.from(r.childNodes||[]).filter(s=>s&&s.nodeType===1&&s.namespaceURI===te&&s.localName==="p"),a=n.indexOf(e);if(a<0)return null;let i=a;for(;i>0;){let s=he(n[i-1]);if(!s||s.numId!==t.numId)break;i--}let o=a;for(;o<n.length-1;){let s=he(n[o+1]);if(!s||s.numId!==t.numId)break;o++}return n.slice(i,o+1)}function Yi(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=typeof r.onWarn=="function"?r.onWarn:()=>{},i=String(t||"");if(!i.includes(`
148
- `)||!he(e))return null;let s=Ln(e);if(!s||s.length===0)return null;let l=Mn(i);if(!l.hasListMarkers||l.items.length<2)return null;let c=L(r.currentParagraphText||W(e)),m=l.items.filter(b=>b.kind==="list")[0]?.markerType||"bullet",f=s.map(b=>({paragraph:b,list:he(b),text:String(W(b)||"").trim()})),p=s.indexOf(e);if(p<0)return null;let g=Math.min(...f.map(b=>b.list?.ilvl??0)),d=f.map(b=>kn((b.list?.ilvl??0)-g,m,b.text)),w=null,h=l.items[0],x=l.items.slice(1).filter(b=>b.kind==="list");if(h?.kind==="text"&&at(h.text,c)&&x.length>0){let b=Math.max(0,(f[p].list?.ilvl??0)-g),S=x[0].level;w=[{level:b,markerType:m,text:f[p].text},...x.map(P=>({level:It(P,b,S),markerType:P.markerType||m,text:P.text}))]}else if(l.items.every(b=>b.kind==="list")){let b=Math.max(0,(f[p].list?.ilvl??0)-g),S=l.items[0].level;w=l.items.map(P=>({level:It(P,b,S),markerType:P.markerType||m,text:P.text}))}else return a("[List] Multiline list edit did not match supported insertion/replace patterns; skipping list-block synthesis."),null;let v=w.map(b=>kn(b.level,b.markerType,b.text)),T=d.slice(0,p).concat(v).concat(d.slice(p+1)),N=d.join(`
149
- `),E=T.join(`
150
- `);return E===N?null:(n("[List] Expanded single-item list edit to contiguous list block for stable middle insertion."),{paragraphs:s,originalText:N,modifiedText:E})}function Ji(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=typeof r.onWarn=="function"?r.onWarn:()=>{},i=String(t||"");if(!i.includes(`
151
- `))return null;let o=he(e);if(!o)return null;let s=Mn(i);if(!s.hasListMarkers||s.items.length<2)return null;let l=L(r.currentParagraphText||W(e)),u=s.items.filter(p=>p.kind==="list")[0]?.markerType||"bullet",m=Math.max(0,o.ilvl),f=Zi(s.items,l,m,u);return!f||f.length===0?(a("[List] Could not derive insertion-only entries from multiline list edit."),null):(Vi(s.items,l,m)&&(f=Ki(f,m),n("[List] Promoted bullet insertion to child depth for nested numbered-list intent.")),n("[List] Planned insertion-only list redline entries (no block rewrite)."),{targetParagraph:e,numId:o.numId,entries:f})}function it(e){if(!e)return null;let t=String(e).trim();if(!t)return null;let r=t.split(`
152
- `),n=[];for(let o of r){if(!o.trim())continue;let s=fe(o,{allowZeroSpaceAfterMarker:!1});if(s){let l=s[1]||"",c=s[2].trim(),u=xe(o,{allowZeroSpaceAfterMarker:!1}).trim(),m=Math.floor(l.length/2),f=/^[-*+\u2022]$/.test(c);n.push({type:f?"bullet":"numbered",level:m,text:u,marker:c});continue}n.push({type:"text",level:0,text:o.trim()})}if(n.length===0)return null;let a=n.some(o=>o.type==="numbered"),i=n.some(o=>o.type==="bullet");return{type:a?"numbered":i?"bullet":"text",items:n}}function ur(e){return!e||!Array.isArray(e.items)?!1:e.items.some(t=>t?.type==="numbered"||t?.type==="bullet")}function fr(e){let t=(e||"").trim();return!t||/^\d+(?:\.\d+)*\.?$/.test(t)||/^\(\d+\)$/.test(t)?"decimal":/^[ivxlcdm]+\.$/.test(t)?"lowerRoman":/^[IVXLCDM]{2,}\.$/.test(t)?"upperRoman":/^[a-z]\.$/.test(t)?"lowerAlpha":/^[A-Z]\.$/.test(t)?"upperAlpha":"decimal"}function qi(e,t,r){let n=new Map,a=[];for(let i of e){let o=Math.max(0,Number(i?.level)||0);for(let u of Array.from(n.keys()))u>o&&n.delete(u);let s=(n.get(o)||0)+1;n.set(o,s);let l=eo(s,t,r),c=" ".repeat(o*4);a.push(`${c}${l} ${i.text||""}`.trimEnd())}return a.join(`
153
- `)}function Qi(e,t={}){let r=Math.max(1,Number(t.indentSpaces)||4),n=/^((?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|\d+\.|[ivxlcIVXLC]+\.|[-*•])\s*)/;return(e||[]).map(a=>{let i=String(a??""),o=i.match(/^(\s*)/),s=o?o[1].length:0,l=Math.floor(s/r),c=i.trim(),u=null,m=c.match(n);return m&&(u=m[1].trim()||null,c=c.replace(n,"")),{text:c.trim(),level:l,removedMarker:u}})}function eo(e,t,r){if(t==="bullet")return"-";switch(r){case"lowerAlpha":return`${_n(e,!1)}.`;case"upperAlpha":return`${_n(e,!0)}.`;case"lowerRoman":return`${Bn(e,!1)}.`;case"upperRoman":return`${Bn(e,!0)}.`;case"decimal":default:return`${e}.`}}function _n(e,t=!1){let r=Math.max(1,Number(e)||1),n="";for(;r>0;)r-=1,n=String.fromCharCode(97+r%26)+n,r=Math.floor(r/26);return t?n.toUpperCase():n}function Bn(e,t=!1){let r=Math.max(1,Number(e)||1),n=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]],a="";for(let[i,o]of n)for(;r>=i;)a+=o,r-=i;return t?a:a.toLowerCase()}function Ct(e){let t=String(e||"");if(!t.trim()||t.includes(`
154
- `))return null;let r=it(t);if(!r||!ur(r)||!Array.isArray(r.items)||r.items.length!==1)return null;let n=r.items[0];if(!n||n.type!=="numbered"&&n.type!=="bullet")return null;let a=String(n.marker||"").trim(),i=n.type==="numbered"?fr(a||"1."):"bullet";return{type:n.type,marker:a,numberingStyle:i,startAt:ro(a,i),contentText:String(n.text||"").trim(),normalizedContent:L(String(n.text||""))}}function to(e){let t=Ct(e);return t?String(t.contentText||"").trim():String(e||"").trim()}function ro(e,t){if(t!=="decimal")return null;let r=String(e||"").trim().match(/^(\d+)\.?$/);if(!r)return null;let n=Number.parseInt(r[1],10);return Number.isFinite(n)&&n>0?n:null}function no(e,t=null){let r=e?.numberingKey?String(e.numberingKey):null,n=Number.isInteger(e?.startAt)&&e.startAt>0?e.startAt:null;if(!r)return{type:"none",numberingKey:null,startAt:n,numId:null};if(n==null)return{type:"sharedByStyle",numberingKey:r,startAt:null,numId:null};let a=t?.explicitByNumberingKey;if(!(a instanceof Map))return{type:"explicitIsolated",numberingKey:r,startAt:n,numId:null};let i=a.get(r)||null;return i&&i.numId!=null&&Number.isInteger(i.nextStartAt)&&i.nextStartAt===n?{type:"explicitReuse",numberingKey:r,startAt:n,numId:String(i.numId)}:{type:"explicitStartNew",numberingKey:r,startAt:n,numId:null}}function ao(e,t,r,n){!e||!(e.explicitByNumberingKey instanceof Map)||!t||r==null||!Number.isInteger(n)||n<1||e.explicitByNumberingKey.set(String(t),{numId:String(r),nextStartAt:n+1})}function io(e,t){!e||!(e.explicitByNumberingKey instanceof Map)||t&&e.explicitByNumberingKey.delete(String(t))}function Ue(e,t){return e&&Array.from(e.childNodes||[]).find(r=>r&&r.nodeType===1&&r.namespaceURI==="http://schemas.openxmlformats.org/wordprocessingml/2006/main"&&r.localName===t)||null}function oo(e,t={}){let r=t?.numId;if(r==null)return 0;let n=Number.isInteger(t?.ilvl)?Math.max(0,t.ilvl):0,a=t?.clearParagraphPropertyChanges!==!1,i=t?.removeListPropertyNode!==!1,o=(Array.isArray(e)?e:[]).filter(l=>l&&l.nodeType===1&&l.localName==="p"),s=0;for(let l of o){let c=l.ownerDocument;if(!c)continue;let u=Ue(l,"pPr");if(u||(u=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:pPr"),l.insertBefore(u,l.firstChild)),a){let g=Ue(u,"pPrChange");g&&u.removeChild(g)}if(i){let g=Ue(u,"listPr");g&&u.removeChild(g)}let m=Ue(u,"numPr");m||(m=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:numPr"),u.appendChild(m));let f=Ue(m,"ilvl");f||(f=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:ilvl"),m.appendChild(f)),f.setAttribute("w:val",String(n));let p=Ue(m,"numId");p||(p=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:numId"),m.appendChild(p)),p.setAttribute("w:val",String(r)),s++}return s}function so(e){let r=_().parseFromString(String(e||""),"application/xml");return H(r)?null:de(r)[0]||null}function lo(e){return e?String(e).replace(/<w:p>\s*<w:pPr>\s*<\/w:pPr>\s*<\/w:p>\s*$/i,""):""}function co(e,t){for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return null}function je(e,t){let r=co(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function $n(e,t){e.setAttribute("w:val",String(t))}function uo(e){let r=_().parseFromString(String(e||""),"application/xml");if(H(r))return null;let i=de(r)[0]||null;if(!i)return null;let o=Array.from(i.getElementsByTagNameNS("*","numId"));for(let s of o){let l=je(s,["w:val","val"]);if(l!=null)return String(l)}return null}function fo(e,t,r,n={}){if(!e||!t||!Number.isInteger(r)||r<1)return e;let a=n.setAbstractStartOverride!==!1,i=_(),o=Z(),s=i.parseFromString(String(e||""),"application/xml");if(H(s))return e;let u=Array.from(s.getElementsByTagNameNS("*","num")).find(d=>{let w=je(d,["w:numId","numId"]);return w!=null&&String(w)===String(t)});if(!u)return e;let m=Array.from(u.getElementsByTagNameNS("*","abstractNumId"))[0]||null,f=je(m,["w:val","val"]),p=Array.from(u.getElementsByTagNameNS("*","lvlOverride")).find(d=>je(d,["w:ilvl","ilvl"])===0)||null;p||(p=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:lvlOverride"),p.setAttribute("w:ilvl","0"),u.appendChild(p));let g=Array.from(p.getElementsByTagNameNS("*","startOverride"))[0]||null;if(g||(g=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:startOverride"),p.appendChild(g)),$n(g,r),a&&f!=null){let w=Array.from(s.getElementsByTagNameNS("*","abstractNum")).find(h=>{let x=je(h,["w:abstractNumId","abstractNumId"]);return x!=null&&x===f})||null;if(w){let h=Array.from(w.getElementsByTagNameNS("*","lvl")).find(v=>je(v,["w:ilvl","ilvl"])===0)||null;h||(h=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:lvl"),h.setAttribute("w:ilvl","0"),w.appendChild(h));let x=Array.from(h.getElementsByTagNameNS("*","start"))[0]||null;x||(x=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:start"),h.insertBefore(x,h.firstChild)),$n(x,r)}}return o.serializeToString(s)}function mr(e={}){let t=String(e.oxml||""),r=String(e.originalText||""),n=String(e.modifiedText||""),a=e.allowExistingList===!0;if(!t.trim()||!n.trim())return null;let i=so(t);if(!i)return null;let o=he(i);if(o&&!a)return null;let s=q(n).cleanText||n,l=Ct(n)||Ct(s);if(!l)return null;let c=Ct(r),u=L(r)===L(s),m=!!c&&c.type===l.type&&c.normalizedContent===l.normalizedContent;return!u&&!m?null:{listInput:`${l.marker} ${l.contentText}`.trim(),numberingKey:`${l.type}:${l.numberingStyle}:single`,originalText:r,wasListParagraph:!!o,startAt:l.startAt}}async function At(e,t={}){if(!e||!e.listInput)return{hasChanges:!1,oxml:"",numberingXml:null,includeNumbering:!1,listStructuralFallbackApplied:!1,listStructuralFallbackKey:null,warnings:["Single-line list fallback plan missing"]};let r=t.author||"AI",n=t.generateRedlines??!0,i=await(t.pipeline||new Oe({author:r,generateRedlines:n})).executeListGeneration(e.listInput,null,null,String(e.originalText||"")),o=i?.oxml||i?.ooxml||"",s=lo(o),l=uo(s),c=fo(i?.numberingXml||null,l,Number.isInteger(e?.startAt)?e.startAt:null,{setAbstractStartOverride:t.setAbstractStartOverride}),u=i?.isValid!==!1;return!s||!u?{hasChanges:!1,oxml:"",numberingXml:null,includeNumbering:!1,listStructuralFallbackApplied:!1,listStructuralFallbackKey:e.numberingKey||null,warnings:["Single-line list fallback produced no valid OOXML"]}:{hasChanges:!0,oxml:s,numberingXml:c,includeNumbering:!0,listStructuralFallbackApplied:!0,listStructuralFallbackKey:e.numberingKey||null,listStructuralFallbackStartAt:Number.isInteger(e?.startAt)?e.startAt:null,warnings:["Single-line list structural fallback applied"]}}function Rt(e,t){return e?Array.from(e.childNodes||[]).filter(r=>r&&r.nodeType===1&&r.namespaceURI===te&&r.localName===t):[]}function mo(e){return String(e||"").replace(/\|/g,"\\|").replace(/\r?\n/g,"<br>")}function po(e){let t=Rt(e,"tr"),r=t.map(a=>Rt(a,"tc").map(o=>{let s=Rt(o,"p");return s.length===0?L(W(o)):s.map(c=>L(W(c))).filter(Boolean).join(`
155
- `)})),n=r.reduce((a,i)=>Math.max(a,i.length),0);return r.forEach(a=>{for(;a.length<n;)a.push("")}),{matrix:r,rowElements:t,columnCount:n}}function go(e,t){if(!Array.isArray(e)||e.length===0||t<=0)return null;let r=e.map(s=>{let l=Array.isArray(s)?s.slice(0,t):[];for(;l.length<t;)l.push("");return l}),n=r[0],a=new Array(t).fill("---"),i=r.slice(1),o=s=>`| ${s.map(l=>mo(l)).join(" | ")} |`;return[o(n),o(a),...i.map(o)].join(`
156
- `)}function ho(e){if(!Array.isArray(e)||e.length<2)return!1;let t=e.map(r=>L(r)).filter(Boolean);return t.length<2?!1:t.every(r=>r===t[0])}function Fn(e){let t=String(e||"").trim();return t?!!(/^and$/i.test(t)||/^\[.*\]$/.test(t)||/^\(.*\)$/.test(t)||/:\s*$/.test(t)||t.length<=90&&!/[.!?]$/.test(t)&&/[:\[\]()]/.test(t)||/^[\[(]/.test(t)):!1}function wo(e,t={}){let r=Number.isInteger(t?.maxScan)&&t.maxScan>0?t.maxScan:10,n=typeof t?.getParagraphText=="function"?t.getParagraphText:W;if(!e||!e.parentNode)return null;let a=[e],i=e.nextSibling,o=0;for(;i&&o<r;){o+=1;let s=i.nextSibling;if(i.nodeType!==1||i.namespaceURI!==te||i.localName!=="p"){i=s;continue}let l=String(n(i)||"").trim();if(!l){if(a.length>1)break;i=s;continue}if(!Fn(l))break;a.push(i),i=s}return a.length>1?a:null}function bo(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=typeof r.onWarn=="function"?r.onWarn:()=>{},i=String(t||"");if(!i.includes(`
157
- `)||lr(i))return null;let o=i.split(/\r?\n/g).map(T=>T.trim()).filter(Boolean);if(o.length<2)return null;let s=r.tableElement||He(e,"tbl"),l=He(e,"tr"),c=He(e,"tc");if(!s||!l||!c)return null;let u=L(r.currentParagraphText||W(e)),m=L(o[0]);if(u&&m&&m!==u)return a("[Table] Multiline cell text did not anchor to original cell text; skipping table-row synthesis heuristic."),null;let{matrix:f,rowElements:p,columnCount:g}=po(s);if(f.length===0||g===0)return null;let d=p.indexOf(l),h=Rt(l,"tc").indexOf(c);if(d<0||h<0||h>=g)return null;f[d][h]=o[0];let x=ho(f[d]);x&&n("[Table] Symmetric row detected; mirroring inserted row values across columns.");for(let T=1;T<o.length;T++){let N=d+T,E=o[T];if(N<f.length&&!L(f[N][h]))if(x)for(let b=0;b<g;b++)L(f[N][b])||(f[N][b]=E);else f[N][h]=E;else{let b=new Array(g).fill("");if(x)for(let S=0;S<g;S++)b[S]=E;else b[h]=E;f.splice(Math.min(N,f.length),0,b)}}let v=go(f,g);return v?(n("[Table] Synthesized full markdown table from multiline cell edit for table-scope reconciliation."),v):null}function Ge(e,t){if(!e||!Array.isArray(t))return null;for(let r of t){let n=e.getAttribute(r);if(n==null||n==="")continue;let a=Number.parseInt(String(n),10);if(Number.isFinite(a))return a}return null}function Ve(e,t,r=null){let n=Number.isInteger(e)&&e>0?e:1,a=t instanceof Set?t:new Set;for(;a.has(n);)n+=1;if(Number.isInteger(r)&&r>0&&n>r){for(let i=1;i<=r;i+=1)if(!a.has(i))return i}return n}function xo(e,t={}){let r=Number.isInteger(t?.minId)&&t.minId>0?t.minId:1,n=Number.isInteger(t?.maxPreferred)&&t.maxPreferred>=r?t.maxPreferred:32767,a=new Set,i=new Set;if(String(e||"").trim())try{let u=ge(e),m=Array.from(u.getElementsByTagNameNS("*","abstractNum")),f=Array.from(u.getElementsByTagNameNS("*","num"));for(let p of m){let g=Ge(p,["w:abstractNumId","abstractNumId"]);g!=null&&i.add(g)}for(let p of f){let g=Ge(p,["w:numId","numId"]);g!=null&&a.add(g)}}catch{}let o=a.size>0?Math.max(...a):0,s=i.size>0?Math.max(...i):0,l=Math.max(r,o+1),c=Math.max(r,s+1);return{nextNumId:Ve(l,a,n),nextAbstractNumId:Ve(c,i,n),usedNumIds:a,usedAbstractNumIds:i,minId:r,maxPreferred:n}}function No(e){return!e||typeof e!="object"?null:(e.usedNumIds instanceof Set||(e.usedNumIds=new Set),e.usedAbstractNumIds instanceof Set||(e.usedAbstractNumIds=new Set),(!Number.isInteger(e.minId)||e.minId<1)&&(e.minId=1),(!Number.isInteger(e.maxPreferred)||e.maxPreferred<e.minId)&&(e.maxPreferred=32767),(!Number.isInteger(e.nextNumId)||e.nextNumId<e.minId)&&(e.nextNumId=e.minId),(!Number.isInteger(e.nextAbstractNumId)||e.nextAbstractNumId<e.minId)&&(e.nextAbstractNumId=e.minId),e.nextNumId=Ve(e.nextNumId,e.usedNumIds,e.maxPreferred),e.nextAbstractNumId=Ve(e.nextAbstractNumId,e.usedAbstractNumIds,e.maxPreferred),e)}function st(e,t="num"){let r=No(e);if(!r)return null;let n=t==="abstract",a=n?r.nextAbstractNumId:r.nextNumId;return!Number.isInteger(a)||a<1?null:(n?(r.usedAbstractNumIds.add(a),r.nextAbstractNumId=Ve(a+1,r.usedAbstractNumIds,r.maxPreferred)):(r.usedNumIds.add(a),r.nextNumId=Ve(a+1,r.usedNumIds,r.maxPreferred)),a)}function vo(e){let t=st(e,"num"),r=st(e,"abstract");return t==null||r==null?null:{numId:t,abstractNumId:r}}function pr(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:e.getElementsByTagName("parsererror").length>0}function kt(e,t){return!!(e&&e.nodeType===1&&e.namespaceURI===te&&e.localName===t)}function Xn(e,t,r){if(!e||!t)return;let n=Array.from(e.childNodes||[]).filter(i=>i&&i.nodeType===1&&i.namespaceURI===te),a=null;r==="abstract"?a=n.find(i=>i.localName==="num"||i.localName==="numIdMacAtCleanup")||null:a=n.find(i=>i.localName==="numIdMacAtCleanup")||null,a?e.insertBefore(t,a):e.appendChild(t)}function To(e,t){for(let r of t||[]){let n=e?.getAttribute?.(r);if(n!=null&&n!=="")return n}return null}function ot(e,t){let r=To(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function Dn(e,t,r){e?.setAttribute?.(t,String(r))}function gr(e,t){e?.setAttribute?.("w:val",String(t))}function yo(e,t){if(!(!Array.isArray(e)||t==null))for(let r of e){let n=Array.from(r?.getElementsByTagNameNS?.("*","numId")||[]);for(let a of n)gr(a,t)}}function Eo(e){for(let t of e||[]){let r=Array.from(t?.getElementsByTagNameNS?.("*","numId")||[]);for(let n of r){let a=ot(n,["w:val","val"]);if(a!=null)return String(a)}}return null}function Po(e,t,r){let n=String(e),a=String(t),i=Number.isInteger(r)&&r>0?r:1,o=Array.from({length:9},(s,l)=>{let c=Array.from({length:l+1},(m,f)=>`%${f+1}`).join(".")+".",u=720*(l+1);return`
150
+ `),t}function Ne(e){return Pt(e,"application/xml")}function De(e){return K(e)}function Lr(e){return Array.from(e||[])}var se="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function _r(e,t){if(!e)return[];if(typeof e.getElementsByTagNameNS=="function"){let n=Lr(e.getElementsByTagNameNS("*",t));if(n.length>0)return n}if(typeof e.getElementsByTagName!="function")return[];let r=Lr(e.getElementsByTagName(`w:${t}`));return r.length>0?r:Lr(e.getElementsByTagName(t))}function Bi(e){return _r(e,"t").map(r=>r.textContent||"").join("")}function G(e){return e?Bi(e):""}function ve(e){if(!e)return[];let t=_r(e,"body"),r=t.length>0?t[0]:e;return _r(r,"p")}function _(e){return String(e||"").replace(/\s+/g," ").trim()}function $r(e){let t=String(e||"").trim();return/^\|.+\|/.test(t)&&t.includes(`
151
+ `)}function Xr(e){if(e==null)return null;if(typeof e=="number"&&Number.isInteger(e)&&e>0)return e;let t=String(e).trim();if(!t)return null;let r=t.match(/^\[?P(\d+)(?:\.\d+)?\]?$/i);if(r)return Number.parseInt(r[1],10);let n=t.match(/^(\d+)$/);return n?Number.parseInt(n[1],10):null}function Fi(e){return e==null?"":String(e).replace(/^\s*\[P\d+(?:\.\d+)?\]\s*/i,"").trim()}function $i(e){let t=String(e||""),r=t.match(/^\s*\[P(\d+)(?:\.\d+)?\]\s*/i);return r?{text:t.replace(/^\s*\[P\d+(?:\.\d+)?\]\s*/i,"").trim(),targetRef:Number.parseInt(r[1],10)}:{text:t.trim(),targetRef:null}}function da(e,t){return!Number.isInteger(t)||t<1?null:ve(e)[t-1]||null}function qe(e,t,r=se){let n=e;for(;n;){if(n.nodeType===1&&n.namespaceURI===r&&n.localName===t)return n;n=n.parentNode}return null}function Ht(e,t){let r=ve(e),n=String(t||"").trim();if(!n)return null;let a=r.find(i=>G(i).trim()===n);if(a)return a;let o=_(n);return r.find(i=>_(G(i))===o)||null}function Br(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=ve(e),o=String(t||"").trim();if(!o)return null;let i=Ht(e,o);if(i)return i;let s=_(o),l=a.find(p=>{let g=_(G(p));return g.length>10&&s.startsWith(g)});if(l)return n(`[Fuzzy] Prefix match (target starts with paragraph): "${G(l).trim().slice(0,60)}..."`),l;let c=a.find(p=>{let g=_(G(p));return g.length>15&&s.includes(g)});if(c)return n(`[Fuzzy] Contains match: "${G(c).trim().slice(0,60)}..."`),c;let u=0,m=null,f=new Set(s.toLowerCase().split(/\s+/).filter(p=>p.length>2));for(let p of a){let g=G(p).trim();if(!g)continue;let h=_(g).toLowerCase().split(/\s+/).filter(b=>b.length>2).filter(b=>f.has(b)).length/Math.max(f.size,1);h>u&&h>.5&&(u=h,m=p)}return m?(n(`[Fuzzy] Best word-overlap match (${(u*100).toFixed(0)}%): "${G(m).trim().slice(0,60)}..."`),m):null}function ha(e,t={}){let r=typeof t.onInfo=="function"?t.onInfo:()=>{},n=typeof t.onWarn=="function"?t.onWarn:()=>{},a=t.opType||"operation",o=String(t.targetText||"").trim(),i=Xr(t.targetRef);if(i){let s=da(e,i);if(s){if(o){let l=Ht(e,o),c=G(s).trim(),u=_(c),m=_(o),f=u!==m;if(f&&l&&l!==s)return r(`[Target] [P${i}] drifted for ${a}; using strict text rematch.`),{paragraph:l,resolvedBy:"strict_text_after_ref_drift"};if(f){let p=Br(e,o,{onInfo:r});if(p&&p!==s)return r(`[Target] [P${i}] drifted for ${a}; using fuzzy text rematch.`),{paragraph:p,resolvedBy:"fuzzy_text_after_ref_drift"};r(`[Target] Using [P${i}] fallback for ${a}; target text drifted.`)}else l&&l!==s&&r(`[Target] [P${i}] disambiguated duplicate target text for ${a}.`)}else r(`[Target] Using [P${i}] fallback for ${a}.`);return{paragraph:s,resolvedBy:"ref"}}n(`[WARN] Target reference [P${i}] not found; falling back to text matching for ${a}.`)}if(o){let s=Ht(e,o);if(s)return{paragraph:s,resolvedBy:"strict_text"};let l=Br(e,o,{onInfo:r});if(l)return{paragraph:l,resolvedBy:"fuzzy_text"}}throw o?new Error(`Target paragraph not found: "${o}"`):i?new Error(`Target paragraph reference not found: [P${i}]`):new Error('Operation target missing: provide "target" text or "targetRef" ([P#]).')}function wa(e){return!!qe(e,"tbl")}function Xi(e,t){let r=_(t);if(!r)return[];let n=ve(e),a=[];for(let o=0;o<n.length;o++){let i=n[o],s=G(i).trim();s&&_(s)===r&&a.push({paragraph:i,index:o+1,inTable:wa(i)})}return a}function Di(e,t,r=null){if(!Array.isArray(e)||e.length===0)return null;let n=e.slice();if(typeof r=="boolean"){let a=n.filter(o=>o.inTable===r);a.length>0&&(n=a)}return Number.isInteger(t)&&t>0&&n.sort((a,o)=>Math.abs(a.index-t)-Math.abs(o.index-t)),n[0]||null}function zi(e){let t=ve(e),r=new Map;for(let n=0;n<t.length;n++){let a=t[n],o=G(a).trim();r.set(n+1,{text:o,normalizedText:_(o),inTable:wa(a)})}return r}function Fr(e,t={}){let r=typeof t.onInfo=="function"?t.onInfo:()=>{},n=ha(e,t),a=Xr(t.targetRef);if(!a||n?.resolvedBy!=="ref")return n;let o=t.targetRefSnapshot instanceof Map&&t.targetRefSnapshot.get(a)||null;if(!o)return n;let i=String(t.targetText||"").trim(),s=i||o.text||"",l=_(s);if(!l||_(G(n.paragraph))===l)return n;let u=[];if(i&&u.push(i),o.text){let f=_(o.text);f&&!u.some(p=>_(p)===f)&&u.push(o.text)}let m=null;for(let f of u){let p=Xi(e,f),g=Di(p,a,o.inTable);if(g&&(m||(m=g),g.paragraph!==n.paragraph)){m=g;break}}if(m&&m.paragraph!==n.paragraph){let f=t.opType||"operation";return r(`[Target] [P${a}] appears stale after prior edits; using strict text rematch for ${f}.`),{paragraph:m.paragraph,resolvedBy:"strict_text_after_ref_drift"}}return n}function Wi(e,t,r,n={}){if(!e||!t||!r)return null;let a=n?.opType||"redline",o=n?.targetRefSnapshot||null,i=typeof n?.onInfo=="function"?n.onInfo:()=>{},s=typeof n?.onWarn=="function"?n.onWarn:()=>{},l=Fr(e,{targetRef:t,opType:a,targetRefSnapshot:o,onInfo:i,onWarn:s})?.paragraph;if(!l)return null;let c=Fr(e,{targetRef:r,opType:a,targetRefSnapshot:o,onInfo:i,onWarn:s})?.paragraph;if(!c)return null;let u=Array.from(e.getElementsByTagNameNS("*","p")),m=u.indexOf(l),f=u.indexOf(c);if(m<0||f<m)return null;let p=u.slice(m,f+1);if(p.length===0)return null;let g=p[0]?.parentNode||null;return!g||!p.every(d=>d&&d.parentNode===g)?null:p}function Ut(e,t){if(!e||typeof e.getElementsByTagNameNS!="function")return null;let r=e.getElementsByTagNameNS(se,t);if(r.length>0)return r[0];let n=e.getElementsByTagNameNS("*",t);return n.length>0?n[0]:null}function ba(e){if(!e)return null;if(typeof e.getAttributeNS=="function"){let t=e.getAttributeNS(se,"val");if(t)return t}return e.getAttribute("w:val")||e.getAttribute("val")||null}function Hi(e){let t=String(e||"").trim();if(!/^\d+(?:\.\d+)+\.?$/.test(t))return null;let r=t.replace(/\.$/,"").split(".");return Math.max(0,r.length-1)}var xa=/^(?:(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|[ivxlcIVXLC]+\.|[-*+\u2022]))\s+/;function va(e){let t=String(e||"").trim(),r=0;for(;r<4&&xa.test(t);)t=t.replace(xa,"").trimStart(),r++;return t.trim()}function Ta(e){let t=String(e||"").split(/\r?\n/g),r=[],n=!1;for(let a of t){let o=a.trimEnd();if(!o.trim())continue;let i=o.match(/^(\s*)((?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|[ivxlcIVXLC]+\.|[-*+\u2022]))\s+(.*)$/);if(i){n=!0;let s=i[2],l=/^[-*+\u2022]$/.test(s)?"bullet":"numbered",c=Math.floor((i[1]||"").length/2);r.push({kind:"list",markerType:l,level:c,marker:s,outlineLevel:l==="numbered"?Hi(s):null,text:va(i[3])});continue}r.push({kind:"text",text:o.trim()})}return{items:r,hasListMarkers:n}}function Na(e,t,r){return`${" ".repeat(Math.max(0,e))}${t==="numbered"?"1.":"-"} ${String(r||"").trim()}`.trimEnd()}function gt(e,t){return _(e)===_(t)}function jt(e,t,r){return Number.isInteger(e?.outlineLevel)?Math.max(0,e.outlineLevel):Math.max(0,t+((e?.level||0)-r))}function Ui(e,t,r){if(!Array.isArray(e)||e.length<2||!Number.isInteger(r)||r<1)return!1;let n=e[0],a=e.slice(1).filter(o=>o.kind==="list");return a.length===0||a.some(o=>o.markerType!=="bullet")||a.some(o=>Number.isInteger(o.outlineLevel))?!1:n?.kind==="text"||n?.kind==="list"&&n.markerType==="numbered"?gt(n.text,t):!1}function ji(e,t){return e.map(r=>{let n=Math.max(0,(r.ilvl||0)-t);return{...r,ilvl:Math.min(8,t+1+n)}})}function Gi(e,t,r,n){let a=e[0],o=e.slice(1).filter(i=>i.kind==="list");if(a?.kind==="text"&&gt(a.text,t)&&o.length>0){let i=o[0].level;return o.map(s=>({ilvl:jt(s,r,i),markerType:s.markerType||n,text:s.text}))}if(e.every(i=>i.kind==="list")){let i=e[0];if(!i||!gt(i.text,t))return null;let s=i.level;return e.slice(1).map(l=>({ilvl:jt(l,r,s),markerType:l.markerType||n,text:l.text})).filter(l=>l.text)}return null}function Te(e){if(!e)return null;let t=Ut(e,"pPr");if(!t)return null;let r=Ut(t,"numPr");if(!r)return null;let n=Ut(r,"numId");if(!n)return null;let a=ba(n);if(!a)return null;let o=Ut(r,"ilvl"),i=ba(o),s=Number.parseInt(i||"0",10);return{numId:String(a),ilvl:Number.isFinite(s)?s:0}}function ya(e){let t=Te(e);if(!t)return null;let r=e.parentNode;if(!r)return null;let n=Array.from(r.childNodes||[]).filter(s=>s&&s.nodeType===1&&s.namespaceURI===se&&s.localName==="p"),a=n.indexOf(e);if(a<0)return null;let o=a;for(;o>0;){let s=Te(n[o-1]);if(!s||s.numId!==t.numId)break;o--}let i=a;for(;i<n.length-1;){let s=Te(n[i+1]);if(!s||s.numId!==t.numId)break;i++}return n.slice(o,i+1)}function Vi(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=typeof r.onWarn=="function"?r.onWarn:()=>{},o=String(t||"");if(!o.includes(`
152
+ `)||!Te(e))return null;let s=ya(e);if(!s||s.length===0)return null;let l=Ta(o);if(!l.hasListMarkers||l.items.length<2)return null;let c=_(r.currentParagraphText||G(e)),m=l.items.filter(N=>N.kind==="list")[0]?.markerType||"bullet",f=s.map(N=>({paragraph:N,list:Te(N),text:String(G(N)||"").trim()})),p=s.indexOf(e);if(p<0)return null;let g=Math.min(...f.map(N=>N.list?.ilvl??0)),d=f.map(N=>Na((N.list?.ilvl??0)-g,m,N.text)),w=null,h=l.items[0],b=l.items.slice(1).filter(N=>N.kind==="list");if(h?.kind==="text"&&gt(h.text,c)&&b.length>0){let N=Math.max(0,(f[p].list?.ilvl??0)-g),y=b[0].level;w=[{level:N,markerType:m,text:f[p].text},...b.map(I=>({level:jt(I,N,y),markerType:I.markerType||m,text:I.text}))]}else if(l.items.every(N=>N.kind==="list")){let N=Math.max(0,(f[p].list?.ilvl??0)-g),y=l.items[0].level;w=l.items.map(I=>({level:jt(I,N,y),markerType:I.markerType||m,text:I.text}))}else return a("[List] Multiline list edit did not match supported insertion/replace patterns; skipping list-block synthesis."),null;let x=w.map(N=>Na(N.level,N.markerType,N.text)),E=d.slice(0,p).concat(x).concat(d.slice(p+1)),v=d.join(`
153
+ `),P=E.join(`
154
+ `);return P===v?null:(n("[List] Expanded single-item list edit to contiguous list block for stable middle insertion."),{paragraphs:s,originalText:v,modifiedText:P})}function Ki(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=typeof r.onWarn=="function"?r.onWarn:()=>{},o=String(t||"");if(!o.includes(`
155
+ `))return null;let i=Te(e);if(!i)return null;let s=Ta(o);if(!s.hasListMarkers||s.items.length<2)return null;let l=_(r.currentParagraphText||G(e)),u=s.items.filter(p=>p.kind==="list")[0]?.markerType||"bullet",m=Math.max(0,i.ilvl),f=Gi(s.items,l,m,u);return!f||f.length===0?(a("[List] Could not derive insertion-only entries from multiline list edit."),null):(Ui(s.items,l,m)&&(f=ji(f,m),n("[List] Promoted bullet insertion to child depth for nested numbered-list intent.")),n("[List] Planned insertion-only list redline entries (no block rewrite)."),{targetParagraph:e,numId:i.numId,entries:f})}function dt(e){if(!e)return null;let t=String(e).trim();if(!t)return null;let r=t.split(`
156
+ `),n=[];for(let i of r){if(!i.trim())continue;let s=be(i,{allowZeroSpaceAfterMarker:!1});if(s){let l=s[1]||"",c=s[2].trim(),u=Ee(i,{allowZeroSpaceAfterMarker:!1}).trim(),m=Math.floor(l.length/2),f=/^[-*+\u2022]$/.test(c);n.push({type:f?"bullet":"numbered",level:m,text:u,marker:c});continue}n.push({type:"text",level:0,text:i.trim()})}if(n.length===0)return null;let a=n.some(i=>i.type==="numbered"),o=n.some(i=>i.type==="bullet");return{type:a?"numbered":o?"bullet":"text",items:n}}function Dr(e){return!e||!Array.isArray(e.items)?!1:e.items.some(t=>t?.type==="numbered"||t?.type==="bullet")}function zr(e){let t=(e||"").trim();return!t||/^\d+(?:\.\d+)*\.?$/.test(t)||/^\(\d+\)$/.test(t)?"decimal":/^[ivxlcdm]+\.$/.test(t)?"lowerRoman":/^[IVXLCDM]{2,}\.$/.test(t)?"upperRoman":/^[a-z]\.$/.test(t)?"lowerAlpha":/^[A-Z]\.$/.test(t)?"upperAlpha":"decimal"}function Yi(e,t,r){let n=new Map,a=[];for(let o of e){let i=Math.max(0,Number(o?.level)||0);for(let u of Array.from(n.keys()))u>i&&n.delete(u);let s=(n.get(i)||0)+1;n.set(i,s);let l=Ji(s,t,r),c=" ".repeat(i*4);a.push(`${c}${l} ${o.text||""}`.trimEnd())}return a.join(`
157
+ `)}function Zi(e,t={}){let r=Math.max(1,Number(t.indentSpaces)||4),n=/^((?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|\d+\.|[ivxlcIVXLC]+\.|[-*•])\s*)/;return(e||[]).map(a=>{let o=String(a??""),i=o.match(/^(\s*)/),s=i?i[1].length:0,l=Math.floor(s/r),c=o.trim(),u=null,m=c.match(n);return m&&(u=m[1].trim()||null,c=c.replace(n,"")),{text:c.trim(),level:l,removedMarker:u}})}function Ji(e,t,r){if(t==="bullet")return"-";switch(r){case"lowerAlpha":return`${Ea(e,!1)}.`;case"upperAlpha":return`${Ea(e,!0)}.`;case"lowerRoman":return`${Pa(e,!1)}.`;case"upperRoman":return`${Pa(e,!0)}.`;case"decimal":default:return`${e}.`}}function Ea(e,t=!1){let r=Math.max(1,Number(e)||1),n="";for(;r>0;)r-=1,n=String.fromCharCode(97+r%26)+n,r=Math.floor(r/26);return t?n.toUpperCase():n}function Pa(e,t=!1){let r=Math.max(1,Number(e)||1),n=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]],a="";for(let[o,i]of n)for(;r>=o;)a+=i,r-=o;return t?a:a.toLowerCase()}function Gt(e){let t=String(e||"");if(!t.trim()||t.includes(`
158
+ `))return null;let r=dt(t);if(!r||!Dr(r)||!Array.isArray(r.items)||r.items.length!==1)return null;let n=r.items[0];if(!n||n.type!=="numbered"&&n.type!=="bullet")return null;let a=String(n.marker||"").trim(),o=n.type==="numbered"?zr(a||"1."):"bullet";return{type:n.type,marker:a,numberingStyle:o,startAt:Qi(a,o),contentText:String(n.text||"").trim(),normalizedContent:_(String(n.text||""))}}function qi(e){let t=Gt(e);return t?String(t.contentText||"").trim():String(e||"").trim()}function Qi(e,t){if(t!=="decimal")return null;let r=String(e||"").trim().match(/^(\d+)\.?$/);if(!r)return null;let n=Number.parseInt(r[1],10);return Number.isFinite(n)&&n>0?n:null}function es(e,t=null){let r=e?.numberingKey?String(e.numberingKey):null,n=Number.isInteger(e?.startAt)&&e.startAt>0?e.startAt:null;if(!r)return{type:"none",numberingKey:null,startAt:n,numId:null};if(n==null)return{type:"sharedByStyle",numberingKey:r,startAt:null,numId:null};let a=t?.explicitByNumberingKey;if(!(a instanceof Map))return{type:"explicitIsolated",numberingKey:r,startAt:n,numId:null};let o=a.get(r)||null;return o&&o.numId!=null&&Number.isInteger(o.nextStartAt)&&o.nextStartAt===n?{type:"explicitReuse",numberingKey:r,startAt:n,numId:String(o.numId)}:{type:"explicitStartNew",numberingKey:r,startAt:n,numId:null}}function ts(e,t,r,n){!e||!(e.explicitByNumberingKey instanceof Map)||!t||r==null||!Number.isInteger(n)||n<1||e.explicitByNumberingKey.set(String(t),{numId:String(r),nextStartAt:n+1})}function rs(e,t){!e||!(e.explicitByNumberingKey instanceof Map)||t&&e.explicitByNumberingKey.delete(String(t))}function Qe(e,t){return e&&Array.from(e.childNodes||[]).find(r=>r&&r.nodeType===1&&r.namespaceURI==="http://schemas.openxmlformats.org/wordprocessingml/2006/main"&&r.localName===t)||null}function ns(e,t={}){let r=t?.numId;if(r==null)return 0;let n=Number.isInteger(t?.ilvl)?Math.max(0,t.ilvl):0,a=t?.clearParagraphPropertyChanges!==!1,o=t?.removeListPropertyNode!==!1,i=(Array.isArray(e)?e:[]).filter(l=>l&&l.nodeType===1&&l.localName==="p"),s=0;for(let l of i){let c=l.ownerDocument;if(!c)continue;let u=Qe(l,"pPr");if(u||(u=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:pPr"),l.insertBefore(u,l.firstChild)),a){let g=Qe(u,"pPrChange");g&&u.removeChild(g)}if(o){let g=Qe(u,"listPr");g&&u.removeChild(g)}let m=Qe(u,"numPr");m||(m=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:numPr"),u.appendChild(m));let f=Qe(m,"ilvl");f||(f=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:ilvl"),m.appendChild(f)),f.setAttribute("w:val",String(n));let p=Qe(m,"numId");p||(p=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:numId"),m.appendChild(p)),p.setAttribute("w:val",String(r)),s++}return s}function as(e){let r=B().parseFromString(String(e||""),"application/xml");return j(r)?null:ve(r)[0]||null}function os(e){return e?String(e).replace(/<w:p>\s*<w:pPr>\s*<\/w:pPr>\s*<\/w:p>\s*$/i,""):""}function is(e,t){for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return null}function et(e,t){let r=is(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function Sa(e,t){e.setAttribute("w:val",String(t))}function ss(e){let r=B().parseFromString(String(e||""),"application/xml");if(j(r))return null;let o=ve(r)[0]||null;if(!o)return null;let i=Array.from(o.getElementsByTagNameNS("*","numId"));for(let s of i){let l=et(s,["w:val","val"]);if(l!=null)return String(l)}return null}function ls(e,t,r,n={}){if(!e||!t||!Number.isInteger(r)||r<1)return e;let a=n.setAbstractStartOverride!==!1,o=B(),i=Q(),s=o.parseFromString(String(e||""),"application/xml");if(j(s))return e;let u=Array.from(s.getElementsByTagNameNS("*","num")).find(d=>{let w=et(d,["w:numId","numId"]);return w!=null&&String(w)===String(t)});if(!u)return e;let m=Array.from(u.getElementsByTagNameNS("*","abstractNumId"))[0]||null,f=et(m,["w:val","val"]),p=Array.from(u.getElementsByTagNameNS("*","lvlOverride")).find(d=>et(d,["w:ilvl","ilvl"])===0)||null;p||(p=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:lvlOverride"),p.setAttribute("w:ilvl","0"),u.appendChild(p));let g=Array.from(p.getElementsByTagNameNS("*","startOverride"))[0]||null;if(g||(g=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:startOverride"),p.appendChild(g)),Sa(g,r),a&&f!=null){let w=Array.from(s.getElementsByTagNameNS("*","abstractNum")).find(h=>{let b=et(h,["w:abstractNumId","abstractNumId"]);return b!=null&&b===f})||null;if(w){let h=Array.from(w.getElementsByTagNameNS("*","lvl")).find(x=>et(x,["w:ilvl","ilvl"])===0)||null;h||(h=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:lvl"),h.setAttribute("w:ilvl","0"),w.appendChild(h));let b=Array.from(h.getElementsByTagNameNS("*","start"))[0]||null;b||(b=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:start"),h.insertBefore(b,h.firstChild)),Sa(b,r)}}return i.serializeToString(s)}function Wr(e={}){let t=String(e.oxml||""),r=String(e.originalText||""),n=String(e.modifiedText||""),a=e.allowExistingList===!0;if(!t.trim()||!n.trim())return null;let o=as(t);if(!o)return null;let i=Te(o);if(i&&!a)return null;let s=ne(n).cleanText||n,l=Gt(n)||Gt(s);if(!l)return null;let c=Gt(r),u=_(r)===_(s),m=!!c&&c.type===l.type&&c.normalizedContent===l.normalizedContent;return!u&&!m?null:{listInput:`${l.marker} ${l.contentText}`.trim(),numberingKey:`${l.type}:${l.numberingStyle}:single`,originalText:r,wasListParagraph:!!i,startAt:l.startAt}}async function Vt(e,t={}){if(!e||!e.listInput)return{hasChanges:!1,oxml:"",numberingXml:null,includeNumbering:!1,listStructuralFallbackApplied:!1,listStructuralFallbackKey:null,warnings:["Single-line list fallback plan missing"]};let r=t.author||"AI",n=t.generateRedlines??!0,o=await(t.pipeline||new Be({author:r,generateRedlines:n})).executeListGeneration(e.listInput,null,null,String(e.originalText||"")),i=o?.oxml||o?.ooxml||"",s=os(i),l=ss(s),c=ls(o?.numberingXml||null,l,Number.isInteger(e?.startAt)?e.startAt:null,{setAbstractStartOverride:t.setAbstractStartOverride}),u=o?.isValid!==!1;return!s||!u?{hasChanges:!1,oxml:"",numberingXml:null,includeNumbering:!1,listStructuralFallbackApplied:!1,listStructuralFallbackKey:e.numberingKey||null,warnings:["Single-line list fallback produced no valid OOXML"]}:{hasChanges:!0,oxml:s,numberingXml:c,includeNumbering:!0,listStructuralFallbackApplied:!0,listStructuralFallbackKey:e.numberingKey||null,listStructuralFallbackStartAt:Number.isInteger(e?.startAt)?e.startAt:null,warnings:["Single-line list structural fallback applied"]}}var cs=new Set(["ins","del","rPrChange","pPrChange"]),us=/^\d{4}-\d{2}-\d{2}T/;function Kt(e){return String(e?.localName||e?.nodeName||"").replace(/^.*:/,"")}function ht(e,t){return Array.from(e.getElementsByTagName("*")).filter(r=>Kt(r)===t)}function ze(e,t){return e.getAttribute(`w:${t}`)||e.getAttribute(t)||""}function fs(e){return e.getAttribute("xml:space")||e.getAttribute("space")||e.getAttributeNS?.("http://www.w3.org/XML/1998/namespace","space")||""}function ms(e){return Kt(e.parentNode)==="rPr"}function ps(e){let t=r=>{let n=Pt(r),a=n.getElementsByTagName("parsererror")[0];if(a)throw new Error(a.textContent||"XML parse error");return n};try{return{doc:t(e)}}catch{try{return{doc:t(`<w:root xmlns:w="${S}">${e}</w:root>`)}}catch(r){return{error:r?.message||"XML parse error"}}}}function gs(e){let t=[],r=(u,m,f)=>t.push({code:u,severity:m,message:f});if(typeof e!="string"||e.trim()==="")return r("PARSE_ERROR","error","Input is not a non-empty OOXML string."),{valid:!1,issues:t};let{doc:n,error:a}=ps(e);if(!n)return r("PARSE_ERROR","error",`OOXML does not parse as XML: ${a}`),{valid:!1,issues:t};let o=ht(n,"ins"),i=ht(n,"del"),s=o.concat(i);for(let u of s){let m=Array.from(u.getElementsByTagName("*")).filter(f=>f!==u&&["ins","del"].includes(Kt(f)));m.length>0&&r("NESTED_REVISION","error",`<${u.nodeName}> (w:id="${ze(u,"id")}") contains nested <${m[0].nodeName}>.`)}for(let u of i)ht(u,"t").length>0&&r("DEL_CONTAINS_T","error",`<w:del> (w:id="${ze(u,"id")}") contains <w:t>; deleted text must use <w:delText>.`);for(let u of s){let m=[];ze(u,"id")||m.push("w:id"),ze(u,"author")||m.push("w:author"),us.test(ze(u,"date"))||m.push("w:date"),m.length>0&&r("MISSING_REVISION_METADATA","error",`<${u.nodeName}> is missing or has malformed ${m.join(", ")}.`)}let l=new Set;for(let u of Array.from(n.getElementsByTagName("*"))){if(!cs.has(Kt(u)))continue;let m=ze(u,"id");m&&(l.has(m)&&r("DUPLICATE_REVISION_ID","error",`Revision id ${m} appears more than once.`),l.add(m))}let c=ht(n,"t").concat(ht(n,"delText"));for(let u of c){let m=u.textContent||"";/^\s|\s$/.test(m)&&fs(u)!=="preserve"&&r("MISSING_SPACE_PRESERVE","error",`<${u.nodeName}> has boundary whitespace without xml:space="preserve".`),m===""&&r("EMPTY_TEXT_ELEMENT","warning",`<${u.nodeName}> is empty.`)}for(let u of s){if(ms(u))continue;Array.from(u.childNodes||[]).some(f=>f.nodeType===1)||r("EMPTY_REVISION_WRAPPER","warning",`<${u.nodeName}> (w:id="${ze(u,"id")}") wraps no content.`)}return{valid:!t.some(u=>u.severity==="error"),issues:t}}function Yt(e,t){return e?Array.from(e.childNodes||[]).filter(r=>r&&r.nodeType===1&&r.namespaceURI===se&&r.localName===t):[]}function ds(e){return String(e||"").replace(/\|/g,"\\|").replace(/\r?\n/g,"<br>")}function hs(e){let t=Yt(e,"tr"),r=t.map(a=>Yt(a,"tc").map(i=>{let s=Yt(i,"p");return s.length===0?_(G(i)):s.map(c=>_(G(c))).filter(Boolean).join(`
159
+ `)})),n=r.reduce((a,o)=>Math.max(a,o.length),0);return r.forEach(a=>{for(;a.length<n;)a.push("")}),{matrix:r,rowElements:t,columnCount:n}}function ws(e,t){if(!Array.isArray(e)||e.length===0||t<=0)return null;let r=e.map(s=>{let l=Array.isArray(s)?s.slice(0,t):[];for(;l.length<t;)l.push("");return l}),n=r[0],a=new Array(t).fill("---"),o=r.slice(1),i=s=>`| ${s.map(l=>ds(l)).join(" | ")} |`;return[i(n),i(a),...o.map(i)].join(`
160
+ `)}function bs(e){if(!Array.isArray(e)||e.length<2)return!1;let t=e.map(r=>_(r)).filter(Boolean);return t.length<2?!1:t.every(r=>r===t[0])}function Ia(e){let t=String(e||"").trim();return t?!!(/^and$/i.test(t)||/^\[.*\]$/.test(t)||/^\(.*\)$/.test(t)||/:\s*$/.test(t)||t.length<=90&&!/[.!?]$/.test(t)&&/[:\[\]()]/.test(t)||/^[\[(]/.test(t)):!1}function xs(e,t={}){let r=Number.isInteger(t?.maxScan)&&t.maxScan>0?t.maxScan:10,n=typeof t?.getParagraphText=="function"?t.getParagraphText:G;if(!e||!e.parentNode)return null;let a=[e],o=e.nextSibling,i=0;for(;o&&i<r;){i+=1;let s=o.nextSibling;if(o.nodeType!==1||o.namespaceURI!==se||o.localName!=="p"){o=s;continue}let l=String(n(o)||"").trim();if(!l){if(a.length>1)break;o=s;continue}if(!Ia(l))break;a.push(o),o=s}return a.length>1?a:null}function Ns(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=typeof r.onWarn=="function"?r.onWarn:()=>{},o=String(t||"");if(!o.includes(`
161
+ `)||$r(o))return null;let i=o.split(/\r?\n/g).map(E=>E.trim()).filter(Boolean);if(i.length<2)return null;let s=r.tableElement||qe(e,"tbl"),l=qe(e,"tr"),c=qe(e,"tc");if(!s||!l||!c)return null;let u=_(r.currentParagraphText||G(e)),m=_(i[0]);if(u&&m&&m!==u)return a("[Table] Multiline cell text did not anchor to original cell text; skipping table-row synthesis heuristic."),null;let{matrix:f,rowElements:p,columnCount:g}=hs(s);if(f.length===0||g===0)return null;let d=p.indexOf(l),h=Yt(l,"tc").indexOf(c);if(d<0||h<0||h>=g)return null;f[d][h]=i[0];let b=bs(f[d]);b&&n("[Table] Symmetric row detected; mirroring inserted row values across columns.");for(let E=1;E<i.length;E++){let v=d+E,P=i[E];if(v<f.length&&!_(f[v][h]))if(b)for(let N=0;N<g;N++)_(f[v][N])||(f[v][N]=P);else f[v][h]=P;else{let N=new Array(g).fill("");if(b)for(let y=0;y<g;y++)N[y]=P;else N[h]=P;f.splice(Math.min(v,f.length),0,N)}}let x=ws(f,g);return x?(n("[Table] Synthesized full markdown table from multiline cell edit for table-scope reconciliation."),x):null}function tt(e,t){if(!e||!Array.isArray(t))return null;for(let r of t){let n=e.getAttribute(r);if(n==null||n==="")continue;let a=Number.parseInt(String(n),10);if(Number.isFinite(a))return a}return null}function rt(e,t,r=null){let n=Number.isInteger(e)&&e>0?e:1,a=t instanceof Set?t:new Set;for(;a.has(n);)n+=1;if(Number.isInteger(r)&&r>0&&n>r){for(let o=1;o<=r;o+=1)if(!a.has(o))return o}return n}function vs(e,t={}){let r=Number.isInteger(t?.minId)&&t.minId>0?t.minId:1,n=Number.isInteger(t?.maxPreferred)&&t.maxPreferred>=r?t.maxPreferred:32767,a=new Set,o=new Set;if(String(e||"").trim())try{let u=Ne(e),m=Array.from(u.getElementsByTagNameNS("*","abstractNum")),f=Array.from(u.getElementsByTagNameNS("*","num"));for(let p of m){let g=tt(p,["w:abstractNumId","abstractNumId"]);g!=null&&o.add(g)}for(let p of f){let g=tt(p,["w:numId","numId"]);g!=null&&a.add(g)}}catch{}let i=a.size>0?Math.max(...a):0,s=o.size>0?Math.max(...o):0,l=Math.max(r,i+1),c=Math.max(r,s+1);return{nextNumId:rt(l,a,n),nextAbstractNumId:rt(c,o,n),usedNumIds:a,usedAbstractNumIds:o,minId:r,maxPreferred:n}}function Ts(e){return!e||typeof e!="object"?null:(e.usedNumIds instanceof Set||(e.usedNumIds=new Set),e.usedAbstractNumIds instanceof Set||(e.usedAbstractNumIds=new Set),(!Number.isInteger(e.minId)||e.minId<1)&&(e.minId=1),(!Number.isInteger(e.maxPreferred)||e.maxPreferred<e.minId)&&(e.maxPreferred=32767),(!Number.isInteger(e.nextNumId)||e.nextNumId<e.minId)&&(e.nextNumId=e.minId),(!Number.isInteger(e.nextAbstractNumId)||e.nextAbstractNumId<e.minId)&&(e.nextAbstractNumId=e.minId),e.nextNumId=rt(e.nextNumId,e.usedNumIds,e.maxPreferred),e.nextAbstractNumId=rt(e.nextAbstractNumId,e.usedAbstractNumIds,e.maxPreferred),e)}function bt(e,t="num"){let r=Ts(e);if(!r)return null;let n=t==="abstract",a=n?r.nextAbstractNumId:r.nextNumId;return!Number.isInteger(a)||a<1?null:(n?(r.usedAbstractNumIds.add(a),r.nextAbstractNumId=rt(a+1,r.usedAbstractNumIds,r.maxPreferred)):(r.usedNumIds.add(a),r.nextNumId=rt(a+1,r.usedNumIds,r.maxPreferred)),a)}function ys(e){let t=bt(e,"num"),r=bt(e,"abstract");return t==null||r==null?null:{numId:t,abstractNumId:r}}function Hr(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:e.getElementsByTagName("parsererror").length>0}function Zt(e,t){return!!(e&&e.nodeType===1&&e.namespaceURI===se&&e.localName===t)}function Ca(e,t,r){if(!e||!t)return;let n=Array.from(e.childNodes||[]).filter(o=>o&&o.nodeType===1&&o.namespaceURI===se),a=null;r==="abstract"?a=n.find(o=>o.localName==="num"||o.localName==="numIdMacAtCleanup")||null:a=n.find(o=>o.localName==="numIdMacAtCleanup")||null,a?e.insertBefore(t,a):e.appendChild(t)}function Es(e,t){for(let r of t||[]){let n=e?.getAttribute?.(r);if(n!=null&&n!=="")return n}return null}function wt(e,t){let r=Es(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function Aa(e,t,r){e?.setAttribute?.(t,String(r))}function Ur(e,t){e?.setAttribute?.("w:val",String(t))}function Ps(e,t){if(!(!Array.isArray(e)||t==null))for(let r of e){let n=Array.from(r?.getElementsByTagNameNS?.("*","numId")||[]);for(let a of n)Ur(a,t)}}function Ss(e){for(let t of e||[]){let r=Array.from(t?.getElementsByTagNameNS?.("*","numId")||[]);for(let n of r){let a=wt(n,["w:val","val"]);if(a!=null)return String(a)}}return null}function Is(e,t,r){let n=String(e),a=String(t),o=Number.isInteger(r)&&r>0?r:1,i=Array.from({length:9},(s,l)=>{let c=Array.from({length:l+1},(m,f)=>`%${f+1}`).join(".")+".",u=720*(l+1);return`
158
162
  <w:lvl w:ilvl="${l}">
159
163
  <w:start w:val="1"/>
160
164
  <w:numFmt w:val="decimal"/>
@@ -162,34 +166,34 @@ var sa=Object.create;var Pr=Object.defineProperty;var la=Object.getOwnPropertyDe
162
166
  <w:lvlJc w:val="left"/>
163
167
  <w:pPr><w:ind w:left="${u}" w:hanging="360"/></w:pPr>
164
168
  </w:lvl>`}).join("");return`
165
- <w:numbering xmlns:w="${te}">
169
+ <w:numbering xmlns:w="${se}">
166
170
  <w:abstractNum w:abstractNumId="${a}">
167
171
  <w:multiLevelType w:val="multilevel"/>
168
- ${o}
172
+ ${i}
169
173
  </w:abstractNum>
170
174
  <w:num w:numId="${n}">
171
175
  <w:abstractNumId w:val="${a}"/>
172
176
  <w:lvlOverride w:ilvl="0">
173
- <w:startOverride w:val="${i}"/>
177
+ <w:startOverride w:val="${o}"/>
174
178
  </w:lvlOverride>
175
179
  </w:num>
176
- </w:numbering>`.trim()}function So(e,t,r){let n=ge(e);if(pr(n))return{numberingXml:String(e||""),replacementNodes:Array.isArray(t)?t.map(c=>c?.cloneNode?c.cloneNode(!0):c):[]};let a=new Map,i=new Map,o=Array.from(n.getElementsByTagNameNS("*","abstractNum"));for(let c of o){let u=ot(c,["w:abstractNumId","abstractNumId"]);if(u==null)continue;let m=st(r,"abstract");m!=null&&(a.set(u,m),Dn(c,"w:abstractNumId",m))}let s=Array.from(n.getElementsByTagNameNS("*","num"));for(let c of s){let u=ot(c,["w:numId","numId"]);if(u==null)continue;let m=st(r,"num");if(m==null)continue;i.set(u,m),Dn(c,"w:numId",m);let f=Array.from(c.getElementsByTagNameNS("*","abstractNumId"))[0]||null;if(f){let p=ot(f,["w:val","val"]);p!=null&&a.has(p)&&gr(f,a.get(p))}}let l=Array.isArray(t)?t.map(c=>c?.cloneNode?c.cloneNode(!0):c):[];for(let c of l){let u=Array.from(c?.getElementsByTagNameNS?.("*","numId")||[]);for(let m of u){let f=ot(m,["w:val","val"]);f!=null&&i.has(f)&&gr(m,i.get(f))}}return{numberingXml:Me(n),replacementNodes:l}}function Io(e,t){let r=String(e||""),n=String(t||"");if(!n.trim())return r;if(!r.trim())return n;try{let a=ge(r),i=ge(n);if(pr(a)||pr(i))return r;let o=a.documentElement,s=i.documentElement;if(!o||!s)return r;let l=new Set(Array.from(o.childNodes||[]).filter(u=>kt(u,"abstractNum")).map(u=>Ge(u,["w:abstractNumId","abstractNumId"])).filter(u=>u!=null)),c=new Set(Array.from(o.childNodes||[]).filter(u=>kt(u,"num")).map(u=>Ge(u,["w:numId","numId"])).filter(u=>u!=null));for(let u of Array.from(s.childNodes||[])){if(!kt(u,"abstractNum"))continue;let m=Ge(u,["w:abstractNumId","abstractNumId"]);m==null||l.has(m)||(Xn(o,a.importNode(u,!0),"abstract"),l.add(m))}for(let u of Array.from(s.childNodes||[])){if(!kt(u,"num"))continue;let m=Ge(u,["w:numId","numId"]);m==null||c.has(m)||(Xn(o,a.importNode(u,!0),"num"),c.add(m))}return Me(a)}catch{return r}}function Co(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:!!H(e)}function zn(e){let t=typeof e=="string"?e:String(e||"");if(!t.trim())return null;try{let n=_().parseFromString(t,"application/xml");return Co(n)?null:n}catch{return null}}function Wn(e){if(!e)return[];let t=Array.from(e.getElementsByTagNameNS(I,"p"));return t.length>0?t:Array.from(e.getElementsByTagNameNS("*","p")).filter(r=>r?.localName==="p")}function dr(e,t){let r=Array.from(e?.childNodes||[]);for(let n of r)if(n?.nodeType===1&&n.namespaceURI===I&&n.localName===t)return n;return null}function Pe(e,t){return Array.from(e?.getElementsByTagNameNS?.(I,t)||[])}function lt(e,t){if(!e)return"";for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return""}function Ao(e,t,r){let n=e?.parentNode||null;for(;n&&n!==r;){if(n.nodeType===1&&n.namespaceURI===I&&n.localName===t)return!0;n=n.parentNode}return!1}function Ro(e){let t="";for(let r of Array.from(e?.childNodes||[]))!r||r.nodeType!==1||r.namespaceURI!==I||(r.localName==="t"?t+=r.textContent||"":r.localName==="tab"?t+=" ":r.localName==="br"||r.localName==="cr"?t+=`
177
- `:r.localName==="noBreakHyphen"&&(t+="\u2011"));return t}function ko(e){let t=dr(e,"rPr");if(!t)return{bold:!1,italic:!1};let r=Pe(t,"rStyle")[0]||null,n=lt(r,["w:val","val"]).toLowerCase(),a=n.includes("strong")||n.includes("bold"),i=n.includes("italic")||n.includes("emphasis");return{bold:Pe(t,"b").length>0||a,italic:Pe(t,"i").length>0||i}}function Hn(e){let t=[],r=Array.from(e?.getElementsByTagNameNS?.(I,"r")||[]);for(let n of r){if(Ao(n,"del",e))continue;let a=Ro(n);a&&t.push({text:a,...ko(n)})}return t}function hr(e){return String(e||"").replace(/\r/g,"").split(`
180
+ </w:numbering>`.trim()}function Cs(e,t,r){let n=Ne(e);if(Hr(n))return{numberingXml:String(e||""),replacementNodes:Array.isArray(t)?t.map(c=>c?.cloneNode?c.cloneNode(!0):c):[]};let a=new Map,o=new Map,i=Array.from(n.getElementsByTagNameNS("*","abstractNum"));for(let c of i){let u=wt(c,["w:abstractNumId","abstractNumId"]);if(u==null)continue;let m=bt(r,"abstract");m!=null&&(a.set(u,m),Aa(c,"w:abstractNumId",m))}let s=Array.from(n.getElementsByTagNameNS("*","num"));for(let c of s){let u=wt(c,["w:numId","numId"]);if(u==null)continue;let m=bt(r,"num");if(m==null)continue;o.set(u,m),Aa(c,"w:numId",m);let f=Array.from(c.getElementsByTagNameNS("*","abstractNumId"))[0]||null;if(f){let p=wt(f,["w:val","val"]);p!=null&&a.has(p)&&Ur(f,a.get(p))}}let l=Array.isArray(t)?t.map(c=>c?.cloneNode?c.cloneNode(!0):c):[];for(let c of l){let u=Array.from(c?.getElementsByTagNameNS?.("*","numId")||[]);for(let m of u){let f=wt(m,["w:val","val"]);f!=null&&o.has(f)&&Ur(m,o.get(f))}}return{numberingXml:De(n),replacementNodes:l}}function As(e,t){let r=String(e||""),n=String(t||"");if(!n.trim())return r;if(!r.trim())return n;try{let a=Ne(r),o=Ne(n);if(Hr(a)||Hr(o))return r;let i=a.documentElement,s=o.documentElement;if(!i||!s)return r;let l=new Set(Array.from(i.childNodes||[]).filter(u=>Zt(u,"abstractNum")).map(u=>tt(u,["w:abstractNumId","abstractNumId"])).filter(u=>u!=null)),c=new Set(Array.from(i.childNodes||[]).filter(u=>Zt(u,"num")).map(u=>tt(u,["w:numId","numId"])).filter(u=>u!=null));for(let u of Array.from(s.childNodes||[])){if(!Zt(u,"abstractNum"))continue;let m=tt(u,["w:abstractNumId","abstractNumId"]);m==null||l.has(m)||(Ca(i,a.importNode(u,!0),"abstract"),l.add(m))}for(let u of Array.from(s.childNodes||[])){if(!Zt(u,"num"))continue;let m=tt(u,["w:numId","numId"]);m==null||c.has(m)||(Ca(i,a.importNode(u,!0),"num"),c.add(m))}return De(a)}catch{return r}}function Rs(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:!!j(e)}function Oa(e){let t=typeof e=="string"?e:String(e||"");if(!t.trim())return null;try{let n=B().parseFromString(t,"application/xml");return Rs(n)?null:n}catch{return null}}function ka(e){if(!e)return[];let t=Array.from(e.getElementsByTagNameNS(S,"p"));return t.length>0?t:Array.from(e.getElementsByTagNameNS("*","p")).filter(r=>r?.localName==="p")}function jr(e,t){let r=Array.from(e?.childNodes||[]);for(let n of r)if(n?.nodeType===1&&n.namespaceURI===S&&n.localName===t)return n;return null}function Re(e,t){return Array.from(e?.getElementsByTagNameNS?.(S,t)||[])}function xt(e,t){if(!e)return"";for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return""}function Ra(e,t,r){let n=e?.parentNode||null;for(;n&&n!==r;){if(n.nodeType===1&&n.namespaceURI===S&&n.localName===t)return!0;n=n.parentNode}return!1}function Os(e){let t="";for(let r of Array.from(e?.childNodes||[]))!r||r.nodeType!==1||r.namespaceURI!==S||(r.localName==="t"?t+=r.textContent||"":r.localName==="tab"?t+=" ":r.localName==="br"||r.localName==="cr"?t+=`
181
+ `:r.localName==="noBreakHyphen"&&(t+="\u2011"));return t}function ks(e){let t=jr(e,"rPr");if(!t)return{bold:!1,italic:!1};let r=Re(t,"rStyle")[0]||null,n=xt(r,["w:val","val"]).toLowerCase(),a=n.includes("strong")||n.includes("bold"),o=n.includes("italic")||n.includes("emphasis");return{bold:Re(t,"b").length>0||a,italic:Re(t,"i").length>0||o}}function Ma(e){let t=[],r=Array.from(e?.getElementsByTagNameNS?.(S,"r")||[]);for(let n of r){if(Ra(n,"del",e)||Ra(n,"moveFrom",e))continue;let a=Os(n);a&&t.push({text:a,...ks(n)})}return t}function Gr(e){return String(e||"").replace(/\r/g,"").split(`
178
182
  `).map(r=>r.replace(/[ \t]+/g," ").trim()).join(`
179
- `).trim()}function Oo(e,t){let r=String(e||"");if(!r)return"";if(!t?.bold&&!t?.italic)return r;let n=r.match(/^(\s*)([\s\S]*?)(\s*)$/);if(!n)return r;let a=n[1]||"",i=n[2]||"",o=n[3]||"";if(!i.trim())return r;let s=i;return t.bold&&t.italic?s=`***${i}***`:t.bold?s=`**${i}**`:t.italic&&(s=`*${i}*`),`${a}${s}${o}`}function Mo(e){let t=dr(e,"pPr");if(!t)return null;let r=Pe(t,"pStyle")[0]||null,n=lt(r,["w:val","val"]);if(n){let s=n.match(/^heading\s*([1-9])$/i);if(s){let l=Number.parseInt(s[1],10);if(Number.isInteger(l))return Math.min(Math.max(l,1),6)}}let a=Pe(t,"outlineLvl")[0]||null,i=lt(a,["w:val","val"]),o=Number.parseInt(i,10);return Number.isInteger(o)&&o>=0?Math.min(o+1,6):null}function Lo(e){let t=dr(e,"pPr");if(!t)return null;let r=Pe(t,"numPr")[0]||null;if(!r)return null;let n=Pe(r,"ilvl")[0]||null,a=Pe(r,"numId")[0]||null,i=Number.parseInt(lt(n,["w:val","val"]),10),o=lt(a,["w:val","val"]);return{level:Number.isInteger(i)&&i>=0?i:0,marker:o==="1"?"-":"1."}}function _o(e){let t=Hn(e).map(r=>r.text).join("");return hr(t)}function Bo(e){let r=Hn(e).map(o=>Oo(o.text,o)).join(""),n=hr(r);if(!n)return"";let a=Mo(e);if(a!=null)return`${"#".repeat(a)} ${n}`;let i=Lo(e);return i?`${" ".repeat(i.level)}${i.marker} ${n}`:n}function $o(e){let t=zn(e);if(!t)return"";let r=Wn(t);return r.length===0?hr(t.documentElement?.textContent||""):r.map(_o).join(`
183
+ `).trim()}function Ms(e,t){let r=String(e||"");if(!r)return"";if(!t?.bold&&!t?.italic)return r;let n=r.match(/^(\s*)([\s\S]*?)(\s*)$/);if(!n)return r;let a=n[1]||"",o=n[2]||"",i=n[3]||"";if(!o.trim())return r;let s=o;return t.bold&&t.italic?s=`***${o}***`:t.bold?s=`**${o}**`:t.italic&&(s=`*${o}*`),`${a}${s}${i}`}function Ls(e){let t=jr(e,"pPr");if(!t)return null;let r=Re(t,"pStyle")[0]||null,n=xt(r,["w:val","val"]);if(n){let s=n.match(/^heading\s*([1-9])$/i);if(s){let l=Number.parseInt(s[1],10);if(Number.isInteger(l))return Math.min(Math.max(l,1),6)}}let a=Re(t,"outlineLvl")[0]||null,o=xt(a,["w:val","val"]),i=Number.parseInt(o,10);return Number.isInteger(i)&&i>=0?Math.min(i+1,6):null}function _s(e){let t=jr(e,"pPr");if(!t)return null;let r=Re(t,"numPr")[0]||null;if(!r)return null;let n=Re(r,"ilvl")[0]||null,a=Re(r,"numId")[0]||null,o=Number.parseInt(xt(n,["w:val","val"]),10),i=xt(a,["w:val","val"]);return{level:Number.isInteger(o)&&o>=0?o:0,marker:i==="1"?"-":"1."}}function Bs(e){let t=Ma(e).map(r=>r.text).join("");return Gr(t)}function Fs(e){let r=Ma(e).map(i=>Ms(i.text,i)).join(""),n=Gr(r);if(!n)return"";let a=Ls(e);if(a!=null)return`${"#".repeat(a)} ${n}`;let o=_s(e);return o?`${" ".repeat(o.level)}${o.marker} ${n}`:n}function $s(e){let t=Oa(e);if(!t)return"";let r=ka(t);return r.length===0?Gr(t.documentElement?.textContent||""):r.map(Bs).join(`
180
184
 
181
- `).trim()}function Fo(e){let t=zn(e);if(!t)return"";let r=Wn(t);return r.length===0?"":r.map(Bo).join(`
185
+ `).trim()}function Xs(e){let t=Oa(e);if(!t)return"";let r=ka(t);return r.length===0?"":r.map(Fs).join(`
182
186
 
183
- `).trim()}function wr(e,t,r,n){let a=t.split(" ").map(s=>s[0]).join("").toUpperCase()||"AI",i=ee(r),o=ee(t);return`<w:comment w:id="${e}" w:author="${o}" w:date="${n}" w:initials="${a}">
187
+ `).trim()}function Vr(e,t,r,n){let a=t.split(" ").map(s=>s[0]).join("").toUpperCase()||"AI",o=oe(r),i=oe(t);return`<w:comment w:id="${e}" w:author="${i}" w:date="${n}" w:initials="${a}">
184
188
  <w:p>
185
- <w:r><w:t>${i}</w:t></w:r>
189
+ <w:r><w:t>${o}</w:t></w:r>
186
190
  </w:p>
187
- </w:comment>`}function br(e){if(!e||e.length===0)return`<w:comments xmlns:w="${I}"></w:comments>`;let t=e.map(r=>wr(r.id,r.author,r.content,r.date)).join(`
188
- `);return`<w:comments xmlns:w="${I}">
191
+ </w:comment>`}function Kr(e){if(!e||e.length===0)return`<w:comments xmlns:w="${S}"></w:comments>`;let t=e.map(r=>Vr(r.id,r.author,r.content,r.date)).join(`
192
+ `);return`<w:comments xmlns:w="${S}">
189
193
  ${t}
190
- </w:comments>`}function Ot(e){let t=J(e,"w:r"),r=[],n="";for(let a of t){let i=n.length,o=J(a,"w:t");for(let s of o)n+=s.textContent||"";r.push({run:a,start:i,end:n.length})}return{fullText:n,runOffsets:r}}function Xo(e,t){let r=e.fullText.indexOf(t);if(r===-1)return{found:!1};let n=r+t.length,a=null,i=null,o=0,s=0;for(let{run:l,start:c,end:u}of e.runOffsets)r>=c&&r<u&&(a=l,o=r-c),n>c&&n<=u&&(i=l,s=n-c);return{found:!0,startRun:a,startOffset:o,endRun:i,endOffset:s}}function ct(e,t,r){let n=e.createElementNS(I,"w:r");t&&n.appendChild(t.cloneNode(!0));let a=e.createElementNS(I,"w:t");return a.setAttribute("xml:space","preserve"),a.textContent=r,n.appendChild(a),n}function Un(e,t,r,n,a=null){let i=a||Ot(t),o=Xo(i,r);if(!o.found||!o.startRun)return!1;let s=e.createElementNS(I,"w:commentRangeStart");s.setAttribute("w:id",String(n));let l=e.createElementNS(I,"w:commentRangeEnd");l.setAttribute("w:id",String(n));let c=e.createElementNS(I,"w:r"),u=e.createElementNS(I,"w:commentReference");if(u.setAttribute("w:id",String(n)),c.appendChild(u),o.startRun===o.endRun){let g=o.startRun,d=M(g,"w:t");if(!d)return g.parentNode.insertBefore(s,g),g.nextSibling?(g.parentNode.insertBefore(l,g.nextSibling),l.parentNode.insertBefore(c,l.nextSibling)):(g.parentNode.appendChild(l),g.parentNode.appendChild(c)),!0;let w=d.textContent||"",h=w.substring(0,o.startOffset),x=w.substring(o.startOffset,o.endOffset),v=w.substring(o.endOffset),T=M(g,"w:rPr"),N=g.parentNode;return h&&N.insertBefore(ct(e,T,h),g),N.insertBefore(s,g),d.textContent=x,g.nextSibling?N.insertBefore(l,g.nextSibling):N.appendChild(l),N.insertBefore(c,l.nextSibling||null),v&&N.insertBefore(ct(e,T,v),c.nextSibling||null),!0}let m=M(o.startRun,"w:t");if(m&&o.startOffset>0){let g=m.textContent||"",d=g.substring(0,o.startOffset),w=g.substring(o.startOffset);if(d){let h=M(o.startRun,"w:rPr");o.startRun.parentNode.insertBefore(ct(e,h,d),o.startRun)}m.textContent=w}o.startRun.parentNode.insertBefore(s,o.startRun);let f=o.endRun||o.startRun,p=M(f,"w:t");if(p&&o.endOffset<(p.textContent||"").length){let g=p.textContent||"",d=g.substring(0,o.endOffset),w=g.substring(o.endOffset);if(p.textContent=d,w){let h=M(f,"w:rPr");f.nextSibling?f.parentNode.insertBefore(ct(e,h,w),f.nextSibling):f.parentNode.appendChild(ct(e,h,w))}}return f.nextSibling?(f.parentNode.insertBefore(l,f.nextSibling),l.parentNode.insertBefore(c,l.nextSibling)):(f.parentNode.appendChild(l),f.parentNode.appendChild(c)),!0}var Ke="http://schemas.microsoft.com/office/2006/xmlPackage",ut="http://schemas.openxmlformats.org/package/2006/relationships";function jn(e,t){let r=_(),n=Z(),a=r.parseFromString(e,"text/xml"),i=H(a);if(i)return V("[CommentEngine] Failed to parse package:",i.textContent),e;let o=a.documentElement,s=a.createElementNS(Ke,"pkg:part");s.setAttribute("pkg:name","/word/comments.xml"),s.setAttribute("pkg:contentType","application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml");let l=a.createElementNS(Ke,"pkg:xmlData"),c=r.parseFromString(t,"text/xml");l.appendChild(a.importNode(c.documentElement,!0)),s.appendChild(l),o.appendChild(s);let m=z(o,Ke,"part").find(f=>f.getAttribute("pkg:name")==="/word/_rels/document.xml.rels");if(m){let f=z(m,Ke,"xmlData");if(f.length>0){let p=z(f[0],ut,"Relationships");if(p.length>0){let g=p[0],d=z(g,ut,"Relationship");if(!d.some(h=>h.getAttribute("Type")?.includes("comments"))){let h=0;d.forEach(v=>{let T=v.getAttribute("Id"),N=parseInt(T?.replace("rId","")||"0",10);N>h&&(h=N)});let x=a.createElementNS(ut,"Relationship");x.setAttribute("Id",`rId${h+1}`),x.setAttribute("Type","http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"),x.setAttribute("Target","comments.xml"),g.appendChild(x)}}}}else{let f=a.createElementNS(Ke,"pkg:part");f.setAttribute("pkg:name","/word/_rels/document.xml.rels"),f.setAttribute("pkg:contentType","application/vnd.openxmlformats-package.relationships+xml");let p=a.createElementNS(Ke,"pkg:xmlData"),g=a.createElementNS(ut,"Relationships"),d=a.createElementNS(ut,"Relationship");d.setAttribute("Id","rId1"),d.setAttribute("Type","http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"),d.setAttribute("Target","comments.xml"),g.appendChild(d),p.appendChild(g),f.appendChild(p),o.appendChild(f)}return n.serializeToString(a)}function Do(e,t,r){try{let n=t.parseFromString(e,"text/xml"),a=H(n);return a?{xmlDoc:null,warning:r(a.textContent||"parse error")}:{xmlDoc:n,warning:null}}catch(n){return{xmlDoc:null,warning:r(n.message)}}}function zo(e,t,r={}){let n=r?.author||G(),a=ie(),i=[],o=[];if(!t||t.length===0)return{oxml:e,commentsApplied:0,warnings:["No comments to inject"]};let s=_(),l=Z(),c=Do(e,s,g=>`Failed to parse OXML: ${g}`);if(!c.xmlDoc)return V("[CommentEngine] Parse failure:",c.warning),{oxml:e,commentsApplied:0,warnings:[c.warning]};let u=c.xmlDoc,m=J(u,"w:p");C(`[CommentEngine] Found ${m.length} paragraphs, processing ${t.length} comment requests`);let f=new Map;for(let g of t){let d=g.paragraphIndex-1;if(d<0||d>=m.length){i.push(`Paragraph ${g.paragraphIndex} out of range (1-${m.length})`);continue}f.set(d,(f.get(d)||0)+1)}let p=new Map;for(let g of t){let d=g.paragraphIndex-1;if(d<0||d>=m.length)continue;let w=m[d],h=p.get(d);h||(h=Ot(w),p.set(d,h));let x=Ne(),v=Un(u,w,g.textToFind,x,h),T=(f.get(d)||1)-1;if(f.set(d,T),!v){i.push(`Could not find "${g.textToFind.substring(0,30)}..." in paragraph ${g.paragraphIndex}`),T===0&&p.delete(d);continue}o.push({id:x,content:g.commentContent,author:n,date:a}),T>0?p.set(d,Ot(w)):p.delete(d)}return o.length===0?{oxml:e,commentsApplied:0,warnings:i}:{oxml:l.serializeToString(u),commentsXml:br(o),commentsApplied:o.length,warnings:i}}function Wo(e,t){return jn(e,t)}function ft(e,t){if(!e||!e.attributes)return"";for(let r of Array.from(e.attributes))if((r.localName||"").toLowerCase()===t.toLowerCase())return String(r.value||"");return String(e.getAttribute?.(`w:${t}`)||e.getAttribute?.(t)||"")}function Gn(e){return typeof e=="string"?e.trim().toLowerCase():""}function Ho(e){return!!e&&e.nodeType===1}function xr(e,t){return Ho(e)&&e.namespaceURI===I&&String(e.localName||"").toLowerCase()===t.toLowerCase()}function we(e,t){return Array.from(e.getElementsByTagNameNS(I,t))}function Nr(e={}){if(e?.allAuthors===!0)return{valid:!0,allAuthors:!0,normalizedAuthor:""};let t=Gn(e?.author);return t?{valid:!0,allAuthors:!1,normalizedAuthor:t}:{valid:!1,allAuthors:!1,normalizedAuthor:"",warning:"No author provided. Pass { author } or set { allAuthors: true }."}}function Le(e,t){if(t.allAuthors)return!0;let r=Gn(ft(e,"author"));return!!r&&r===t.normalizedAuthor}function vr(e,t){let n=_().parseFromString(e,"application/xml"),a=H(n);return a?{xmlDoc:null,serializer:null,warning:`${t}: ${a.textContent||"parse error"}`}:{xmlDoc:n,serializer:Z(),warning:null}}function ne(e){return e?.parentNode?(e.parentNode.removeChild(e),!0):!1}function Vn(e){let t=e?.parentNode;if(!t)return!1;for(;e.firstChild;)t.insertBefore(e.firstChild,e);return t.removeChild(e),!0}function Mt(e){let t=e?.parentNode;return xr(t,"trPr")&&xr(t?.parentNode,"tr")}function Uo(e,t={}){let r=[],n=Nr(t);if(!n.valid)return{oxml:e,hasChanges:!1,acceptedCount:0,warnings:[n.warning]};let a=vr(e,"Failed to parse OOXML");if(!a.xmlDoc)return{oxml:e,hasChanges:!1,acceptedCount:0,warnings:[a.warning]};let{xmlDoc:i,serializer:o}=a,s=0;for(let c of we(i,"ins"))if(!(!c.parentNode||!Le(c,n))){if(Mt(c)){ne(c)&&(s+=1);continue}Vn(c)&&(s+=1)}for(let c of we(i,"del"))if(!(!c.parentNode||!Le(c,n))){if(Mt(c)){let u=c.parentNode?.parentNode;ne(u)&&(s+=1);continue}ne(c)&&(s+=1)}let l=["rPrChange","pPrChange","tblPrChange","trPrChange","tcPrChange"];for(let c of l)for(let u of we(i,c))!u.parentNode||!Le(u,n)||ne(u)&&(s+=1);return{oxml:o.serializeToString(i),hasChanges:s>0,acceptedCount:s,warnings:r}}function jo(e,t){for(let r of Array.from(t.getElementsByTagNameNS(I,"delText"))){let n=e.createElementNS(I,"w:t"),a=r.getAttribute("xml:space");for(a&&n.setAttribute("xml:space",a);r.firstChild;)n.appendChild(r.firstChild);r.parentNode?.replaceChild(n,r)}}function Go(e,t){let r=e?.parentNode;if(!r)return!1;let n=t.endsWith("Change")?t.slice(0,-6):"";if(!n||String(r.localName||"").toLowerCase()!==n.toLowerCase()||r.namespaceURI!==I)return ne(e);let a=Array.from(e.childNodes||[]).find(o=>o.nodeType===1&&o.namespaceURI===I&&String(o.localName||"").toLowerCase()===n.toLowerCase());if(!a)return ne(e);let i=Array.from(a.childNodes||[]);for(;r.firstChild;)r.removeChild(r.firstChild);for(let o of i){let s=Vo(r.ownerDocument,o);r.appendChild(s)}return!0}function Vo(e,t){return e&&typeof e.importNode=="function"?e.importNode(t,!0):t.cloneNode(!0)}function Ko(e,t={}){let r=[],n=Nr(t);if(!n.valid)return{oxml:e,hasChanges:!1,rejectedCount:0,warnings:[n.warning]};let a=vr(e,"Failed to parse OOXML");if(!a.xmlDoc)return{oxml:e,hasChanges:!1,rejectedCount:0,warnings:[a.warning]};let{xmlDoc:i,serializer:o}=a,s=0;for(let c of we(i,"ins"))if(!(!c.parentNode||!Le(c,n))){if(Mt(c)){let u=c.parentNode?.parentNode;ne(u)&&(s+=1);continue}ne(c)&&(s+=1)}for(let c of we(i,"del"))if(!(!c.parentNode||!Le(c,n))){if(Mt(c)){ne(c)&&(s+=1);continue}jo(i,c),Vn(c)&&(s+=1)}let l=["rPrChange","pPrChange","tblPrChange","trPrChange","tcPrChange"];for(let c of l)for(let u of we(i,c))!u.parentNode||!Le(u,n)||Go(u,c)&&(s+=1);return{oxml:o.serializeToString(i),hasChanges:s>0,rejectedCount:s,warnings:r}}function Zo(e,t){let r=new Set,n=we(e,"comment");for(let a of n){if(!Le(a,t))continue;let i=ft(a,"id");i&&r.add(i)}return{targetIds:r,commentNodes:n}}function Yo(e,t){let r=0;for(let n of e){let a=ft(n,"id");!a||!t.has(a)||ne(n)&&(r+=1)}return r}function Jo(e){return xr(e,"r")?Array.from(e.childNodes||[]).filter(r=>{if(r.nodeType===3)return String(r.nodeValue||"").trim().length>0;if(r.nodeType!==1)return!1;if(r.namespaceURI!==I)return!0;let n=String(r.localName||"").toLowerCase();return n!=="rpr"&&n!=="commentreference"}).length===0:!1}function qo(e,t){let r=0,n=["commentRangeStart","commentRangeEnd","commentReference"];for(let a of n)for(let i of we(e,a)){if(!i.parentNode)continue;let o=ft(i,"id");if(!(!o||!t.has(o))){if(a==="commentReference"&&Jo(i.parentNode)){ne(i.parentNode)&&(r+=1);continue}ne(i)&&(r+=1)}}return r}function Qo(e,t={}){let r=[],n=Nr(t);if(!n.valid)return{oxml:e,hasChanges:!1,commentsRemoved:0,referencesRemoved:0,warnings:[n.warning]};let a=vr(e,"Failed to parse OOXML");if(!a.xmlDoc)return{oxml:e,hasChanges:!1,commentsRemoved:0,referencesRemoved:0,warnings:[a.warning]};let{xmlDoc:i,serializer:o}=a,{targetIds:s,commentNodes:l}=Zo(i,n);if(n.allAuthors)for(let m of["commentRangeStart","commentRangeEnd","commentReference"])for(let f of we(i,m)){let p=ft(f,"id");p&&s.add(p)}let c=Yo(l,s),u=qo(i,s);return{oxml:o.serializeToString(i),hasChanges:c>0||u>0,commentsRemoved:c,referencesRemoved:u,warnings:r}}function Kn(e,t=["all"]){if(!e)return null;let r=e.cloneNode(!0);if(t.includes("all"))["w:b","w:i","w:u","w:strike","w:dstrike","w:color","w:sz","w:szCs","w:rFonts","w:highlight","w:vertAlign","w:spacing","w:w","w:kern","w:position"].forEach(a=>{r.querySelectorAll(`${a}, ${a.replace("w:","")}`).forEach(o=>o.remove())});else{let n={bold:"w:b",italic:"w:i",underline:"w:u",strikethrough:"w:strike",doubleStrike:"w:dstrike",color:"w:color",highlight:"w:highlight",fontSize:"w:sz",fontSizeCs:"w:szCs",fontFamily:"w:rFonts",superscript:"w:vertAlign",subscript:"w:vertAlign"};t.forEach(a=>{let i=n[a];i&&r.querySelectorAll(`${i}, ${i.replace("w:","")}`).forEach(s=>s.remove())})}return r.children.length>0?r:null}function es(e,t,r){if(!t||!e)return e;let n=ge(e),a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",i=n.getElementsByTagNameNS(a,"r"),o=n.getElementsByTagNameNS(a,"ins"),s=[...Array.from(i)];for(let l of o){let c=l.getElementsByTagNameNS(a,"r");s.push(...Array.from(c))}for(let l of s){let c=l.getElementsByTagNameNS(a,"t"),u=Array.from(c).map(m=>m.textContent).join("");if(u.includes(t)||u===t){let m=l.getElementsByTagNameNS(a,"rPr");if(m.length>0){let f=m[0],p=Kn(f,r);p?f.parentNode&&f.parentNode.replaceChild(p,f):f.remove()}}}return Me(n)}var ts={yellow:"yellow",green:"green",cyan:"cyan",magenta:"magenta",blue:"blue",red:"red",darkblue:"darkBlue",darkcyan:"darkCyan",darkgreen:"darkGreen",darkmagenta:"darkMagenta",darkred:"darkRed",darkyellow:"darkYellow",gray25:"lightGray",gray50:"darkGray",black:"black",white:"white"};function rs(e,t,r="yellow",n={}){let a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",i=ts[r.toLowerCase()]||"yellow",o=n?.generateRedlines??!1,s=n?.author||G(),l=t;l?l=t.cloneNode(!0):l=e.createElementNS(a,"w:rPr");let c=null;o&&(c=e.createElementNS(a,"w:rPr"),Array.from(l.childNodes).forEach(f=>{f.nodeName!=="w:rPrChange"&&c.appendChild(f.cloneNode(!0))}));let u=l.getElementsByTagNameNS(a,"highlight");Array.from(u).forEach(f=>f.remove());let m=e.createElementNS(a,"w:highlight");if(m.setAttributeNS(a,"w:val",i),l.appendChild(m),o&&c){let f=e.createElementNS(a,"w:rPrChange");f.setAttributeNS(a,"w:id",Math.floor(Math.random()*9999999).toString()),f.setAttributeNS(a,"w:author",s),f.setAttributeNS(a,"w:date",new Date().toISOString()),f.appendChild(c);let p=l.getElementsByTagNameNS(a,"rPrChange");Array.from(p).forEach(g=>g.remove()),l.appendChild(f)}return l}function ns(e,t,r="yellow",n={}){if(!t||!e)return e;let a=ge(e),i="http://schemas.openxmlformats.org/wordprocessingml/2006/main",o=l=>{let c=l.getElementsByTagNameNS(i,"t");return Array.from(c).map(u=>u.textContent).join("")},s=Array.from(a.getElementsByTagNameNS(i,"r"));for(let l=0;l<s.length;l++){let c=s[l],u=o(c);if(!u)continue;let m=u.indexOf(t);if(m===-1)continue;let f=c.parentNode;if(!f){console.warn("[Highlight] Run parent is null; skipping. Likely already processed.");continue}let p=u.substring(0,m),g=u.substring(m,m+t.length),d=u.substring(m+t.length),w=a.createDocumentFragment();if(p.length>0){let h=c.cloneNode(!0),x=h.getElementsByTagNameNS(i,"t");Array.from(x).forEach(T=>T.remove());let v=a.createElementNS(i,"w:t");v.setAttribute("xml:space","preserve"),v.textContent=p,h.appendChild(v),w.appendChild(h)}if(g.length>0){let h=c.cloneNode(!0),x=h.getElementsByTagNameNS(i,"t");Array.from(x).forEach(b=>b.remove());let v=a.createElementNS(i,"w:t");v.setAttribute("xml:space","preserve"),v.textContent=g,h.appendChild(v);let T=h.getElementsByTagNameNS(i,"rPr"),N=T.length>0?T[0]:null,E=rs(a,N,r,n);N?h.replaceChild(E,N):h.insertBefore(E,h.firstChild),w.appendChild(h)}if(d.length>0){let h=c.cloneNode(!0),x=h.getElementsByTagNameNS(i,"t");Array.from(x).forEach(T=>T.remove());let v=a.createElementNS(i,"w:t");v.setAttribute("xml:space","preserve"),v.textContent=d,h.appendChild(v),w.appendChild(h)}f.replaceChild(w,c)}return Me(a)}var Q="http://schemas.openxmlformats.org/wordprocessingml/2006/main",as="http://schemas.openxmlformats.org/package/2006/content-types",is="http://schemas.openxmlformats.org/package/2006/relationships",Yn="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",Jn="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",qn="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",Qn="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",Zn="word/document.xml",Lt="word/numbering.xml",mt="word/comments.xml",_e="[Content_Types].xml",Be="word/_rels/document.xml.rels";function Se(e,t="xml"){let n=_().parseFromString(e,"application/xml"),a=n.getElementsByTagName("parsererror")[0];if(a)throw new Error(`[XML parse error] ${t}: ${a.textContent||"Unknown"}`);return n}function _t(e){return!!e&&e.nodeType===1&&e.namespaceURI===Q&&e.localName==="sectPr"}function yr(e){return e.getElementsByTagNameNS("*","body")[0]||null}function ea(e){for(let t of Array.from(e.childNodes||[]))if(_t(t))return t;return null}function os(e,t){let r=ea(e);r?e.insertBefore(t,r):e.appendChild(t)}function ta(e){let t=yr(e);if(!t)return;let r=ea(t);if(!r)return;let n=r.nextSibling;for(;n;){let a=n.nextSibling;n.nodeType===1&&t.insertBefore(n,r),n=a}}function ss(e,t={}){let r=typeof t?.onInfo=="function"?t.onInfo:()=>{},n=e.getElementsByTagNameNS(Q,"tc"),a=0;for(let i of Array.from(n)){let o=Array.from(i.childNodes||[]).filter(s=>s.nodeType===1&&s.namespaceURI===Q&&s.localName==="p");for(let s of o){let l=Array.from(s.childNodes||[]).filter(c=>c.nodeType===1&&c.namespaceURI===Q&&c.localName==="p");for(let c of l)i.insertBefore(c,s),a+=1}}return a>0&&r(`[Sanitize] Fixed ${a} nested w:p element(s) in table cells`),a}function Tr(e){return e.getAttribute("pkg:name")||e.getAttribute("name")||""}function ls(e){let t=_(),r=Z(),n=t.parseFromString(e,"application/xml"),a=Array.from(n.getElementsByTagNameNS("*","part")),i=a.find(f=>Tr(f)==="/word/document.xml");if(!i)throw new Error("Package output missing /word/document.xml part");let o=i.getElementsByTagNameNS("*","xmlData")[0];if(!o)throw new Error("Package document part missing pkg:xmlData");let s=Array.from(o.childNodes||[]).find(f=>f.nodeType===1);if(!s)throw new Error("Package document part missing XML payload");let l=s.getElementsByTagNameNS("*","body")[0],c=l?Array.from(l.childNodes||[]).filter(f=>f.nodeType===1&&!_t(f)):[s],u=a.find(f=>Tr(f)==="/word/numbering.xml"),m=null;if(u){let f=u.getElementsByTagNameNS("*","xmlData")[0],p=f?Array.from(f.childNodes||[]).find(g=>g.nodeType===1):null;p&&(m=r.serializeToString(p))}return{replacementNodes:c,numberingXml:m,sourceType:"package"}}function cs(e){if(typeof e!="string"||!e.trim())throw new Error("Reconciliation engine returned no OOXML payload for this operation");if(e.includes("<pkg:package"))return ls(e);if(e.includes("<w:document")){let o=_().parseFromString(e,"application/xml"),s=o.getElementsByTagNameNS("*","body")[0];return{replacementNodes:s?Array.from(s.childNodes||[]).filter(c=>c.nodeType===1&&!_t(c)):Array.from(o.childNodes||[]).filter(c=>c.nodeType===1),numberingXml:null,sourceType:"document"}}let t=`<root xmlns:w="${Q}">${e}</root>`,n=_().parseFromString(t,"application/xml");return{replacementNodes:Array.from(n.documentElement.childNodes||[]).filter(i=>i.nodeType===1),numberingXml:null,sourceType:"fragment"}}function ra(e,t,r){if(Array.from(e.getElementsByTagNameNS("*","Override")).some(o=>(o.getAttribute("PartName")||"").toLowerCase()===String(t).toLowerCase()))return!1;let i=e.createElementNS(as,"Override");return i.setAttribute("PartName",t),i.setAttribute("ContentType",r),e.documentElement.appendChild(i),!0}function na(e,t,r){let n=e.getElementsByTagNameNS("*","Relationships")[0]||e.documentElement,a=Array.from(n.getElementsByTagNameNS("*","Relationship"));if(a.some(l=>(l.getAttribute("Type")||"")===t))return!1;let o=0;for(let l of a){let c=l.getAttribute("Id")||"",u=Number.parseInt(c.replace(/^rId/i,""),10);Number.isFinite(u)&&(o=Math.max(o,u))}let s=e.createElementNS(is,"Relationship");return s.setAttribute("Id",`rId${o+1}`),s.setAttribute("Type",t),s.setAttribute("Target",r),n.appendChild(s),!0}async function ce(e,t){let r=e.file(t);return r?r.async("string"):null}async function us(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{},a=typeof r?.mergeNumberingXml=="function"?r.mergeNumberingXml:null,i=(Array.isArray(t)?t:[t]).filter(Boolean);if(i.length===0)return;let o=await ce(e,Lt),s=o||null;for(let f of i){if(!s){s=f;continue}s=a?a(s,f):f}n(o?"[Demo] Merging numbering.xml payload(s) into existing numbering definitions":"[Demo] Adding numbering.xml"),e.file(Lt,s);let l=_(),c=Z(),u=await ce(e,_e);if(u){let f=l.parseFromString(u,"application/xml");ra(f,"/word/numbering.xml",Jn)&&e.file(_e,c.serializeToString(f))}let m=await ce(e,Be);if(m){let f=l.parseFromString(m,"application/xml");na(f,Yn,"numbering.xml")&&e.file(Be,c.serializeToString(f))}}async function fs(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{};if(!t)return;let a=_(),i=Z(),o=await ce(e,mt);if(!o)n("[Demo] Adding comments.xml"),e.file(mt,t);else{let c=Se(o,"word/comments.xml (existing)"),u=Se(t,"word/comments.xml (incoming)"),m=c.documentElement,f=new Set(Array.from(m.getElementsByTagNameNS(Q,"comment")).map(p=>p.getAttribute("w:id")||p.getAttribute("id")).filter(Boolean));for(let p of Array.from(u.documentElement.getElementsByTagNameNS(Q,"comment"))){let g=p.getAttribute("w:id")||p.getAttribute("id");if(g&&f.has(g))throw new Error(`Duplicate comment id: ${g}`);m.appendChild(c.importNode(p,!0))}e.file(mt,i.serializeToString(c))}let s=await ce(e,_e);if(s){let c=a.parseFromString(s,"application/xml");ra(c,"/word/comments.xml",Qn)&&e.file(_e,i.serializeToString(c))}let l=await ce(e,Be);if(l){let c=a.parseFromString(l,"application/xml");na(c,qn,"comments.xml")&&e.file(Be,i.serializeToString(c))}}async function ms(e){let t=await ce(e,Zn);if(!t)throw new Error("Validation failed: missing word/document.xml");let r=Se(t,Zn);ta(r);let n=yr(r);if(!n)throw new Error("Validation failed: word/document.xml has no w:body");let a=Array.from(n.childNodes||[]).filter(d=>d.nodeType===1),i=a.map((d,w)=>({node:d,index:w})).filter(d=>_t(d.node)).map(d=>d.index);if(i.length>1)throw new Error("Validation failed: multiple body-level w:sectPr");if(i.length===1&&i[0]!==a.length-1)throw new Error("Validation failed: w:sectPr not last");let o=r.getElementsByTagNameNS(Q,"tc");for(let d of Array.from(o))for(let w of Array.from(d.childNodes||[]).filter(h=>h.nodeType===1))if(w.namespaceURI===Q&&w.localName==="p"&&Array.from(w.childNodes||[]).some(x=>x.nodeType===1&&x.namespaceURI===Q&&x.localName==="p"))throw new Error("Validation failed: nested w:p");let s=r.getElementsByTagNameNS(Q,"numPr").length>0,l=r.getElementsByTagNameNS(Q,"commentRangeStart").length>0||r.getElementsByTagNameNS(Q,"commentRangeEnd").length>0||r.getElementsByTagNameNS(Q,"commentReference").length>0,c=await ce(e,Lt),u=await ce(e,mt);if(c)Se(c,Lt);else if(s)throw new Error("Validation failed: numbering used but part missing");if(u)Se(u,mt);else if(l)throw new Error("Validation failed: comments used but part missing");let m=await ce(e,_e);if(!m)throw new Error(`Validation failed: missing ${_e}`);let f=Se(m,_e),p=await ce(e,Be);if(!p)throw new Error(`Validation failed: missing ${Be}`);let g=Se(p,Be);if(c){let d=Array.from(f.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/numbering.xml"&&(h.getAttribute("ContentType")||"")===Jn),w=Array.from(g.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===Yn);if(!d)throw new Error("Validation failed: numbering CT override missing");if(!w)throw new Error("Validation failed: numbering rel missing")}if(u){let d=Array.from(f.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/comments.xml"&&(h.getAttribute("ContentType")||"")===Qn),w=Array.from(g.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===qn);if(!d)throw new Error("Validation failed: comments CT override missing");if(!w)throw new Error("Validation failed: comments rel missing")}}var Ze=Object.freeze({STRUCTURED_LIST_DIRECT:"structured_list_direct",EMPTY_FORMATTED_TEXT:"empty_formatted_text",EMPTY_HTML:"empty_html",BLOCK_HTML:"block_html",OOXML_ENGINE:"ooxml_engine"});function ia(e){return!e||typeof e!="string"?e||"":e.replace(/\\n/g,`
191
- `).replace(/\\t/g," ").replace(/\\r/g,"\r")}function ps(e={}){let t=e.originalText||"",r=ia(e.newContent||""),n=it(r)||{type:"text",items:[]};return r.includes(`
192
- `)&&n.type!=="text"?{kind:Ze.STRUCTURED_LIST_DIRECT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!0,isOriginalEmpty:aa(t),hasInlineFormatting:Bt(r),hasBlockElements:$t(r),hasMarkdownTable:pt(r)}}:aa(t)?Bt(r)?{kind:Ze.EMPTY_FORMATTED_TEXT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!0,hasBlockElements:$t(r),hasMarkdownTable:pt(r)}}:{kind:Ze.EMPTY_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!1,hasBlockElements:$t(r),hasMarkdownTable:pt(r)}}:$t(r)?{kind:Ze.BLOCK_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:Bt(r),hasBlockElements:!0,hasMarkdownTable:pt(r)}}:{kind:Ze.OOXML_ENGINE,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:Bt(r),hasBlockElements:!1,hasMarkdownTable:pt(r)}}}function aa(e){return!e||e.trim().length===0}function pt(e){if(!e||!e.includes("|"))return!1;let t=se(e);return t.rows.length>0||t.headers.length>0}function Bt(e){return e?/(\*\*.+?\*\*|\*.+?\*|__.+?__|_.+?_|`.+?`|~~.+?~~|\+\+.+?\+\+)/.test(e):!1}function $t(e){if(!e)return!1;let t=/^[\s]*[-*+]\s+/m.test(e),r=/^[\s]*\d+\.\s+/m.test(e),n=/^[\s]*\d+\.\d+(?:\.\d+)*\.?\s+/m.test(e),a=/^[\s]*[A-Za-z]\.\s+/m.test(e),i=/^[\s]*[ivxlcIVXLC]+\.\s+/m.test(e),o=/^[\s]*\([a-z]\)\s+/m.test(e),s=/\|.*\|.*\n/.test(e),l=/^#{1,9}\s/m.test(e),c=e.includes(`
194
+ </w:comments>`}function Jt(e){let t=Pe(e,"w:r"),r=[],n="";for(let a of t){let o=n.length,i=Pe(a,"w:t");for(let s of i)n+=s.textContent||"";r.push({run:a,start:o,end:n.length})}return{fullText:n,runOffsets:r}}function Ds(e,t){let r=e.fullText.indexOf(t);if(r===-1)return{found:!1};let n=r+t.length,a=null,o=null,i=0,s=0;for(let{run:l,start:c,end:u}of e.runOffsets)r>=c&&r<u&&(a=l,i=r-c),n>c&&n<=u&&(o=l,s=n-c);return{found:!0,startRun:a,startOffset:i,endRun:o,endOffset:s}}function Nt(e,t,r){let n=A(e,"w:r");t&&n.appendChild(t.cloneNode(!0));let a=A(e,"w:t");return a.setAttribute("xml:space","preserve"),a.textContent=r,n.appendChild(a),n}function La(e,t,r,n,a=null){let o=a||Jt(t),i=Ds(o,r);if(!i.found||!i.startRun)return!1;let s=A(e,"w:commentRangeStart");s.setAttribute("w:id",String(n));let l=A(e,"w:commentRangeEnd");l.setAttribute("w:id",String(n));let c=A(e,"w:r"),u=A(e,"w:commentReference");if(u.setAttribute("w:id",String(n)),c.appendChild(u),i.startRun===i.endRun){let g=i.startRun,d=$(g,"w:t");if(!d)return g.parentNode.insertBefore(s,g),g.nextSibling?(g.parentNode.insertBefore(l,g.nextSibling),l.parentNode.insertBefore(c,l.nextSibling)):(g.parentNode.appendChild(l),g.parentNode.appendChild(c)),!0;let w=d.textContent||"",h=w.substring(0,i.startOffset),b=w.substring(i.startOffset,i.endOffset),x=w.substring(i.endOffset),E=$(g,"w:rPr"),v=g.parentNode;return h&&v.insertBefore(Nt(e,E,h),g),v.insertBefore(s,g),d.textContent=b,g.nextSibling?v.insertBefore(l,g.nextSibling):v.appendChild(l),v.insertBefore(c,l.nextSibling||null),x&&v.insertBefore(Nt(e,E,x),c.nextSibling||null),!0}let m=$(i.startRun,"w:t");if(m&&i.startOffset>0){let g=m.textContent||"",d=g.substring(0,i.startOffset),w=g.substring(i.startOffset);if(d){let h=$(i.startRun,"w:rPr");i.startRun.parentNode.insertBefore(Nt(e,h,d),i.startRun)}m.textContent=w}i.startRun.parentNode.insertBefore(s,i.startRun);let f=i.endRun||i.startRun,p=$(f,"w:t");if(p&&i.endOffset<(p.textContent||"").length){let g=p.textContent||"",d=g.substring(0,i.endOffset),w=g.substring(i.endOffset);if(p.textContent=d,w){let h=$(f,"w:rPr");f.nextSibling?f.parentNode.insertBefore(Nt(e,h,w),f.nextSibling):f.parentNode.appendChild(Nt(e,h,w))}}return f.nextSibling?(f.parentNode.insertBefore(l,f.nextSibling),l.parentNode.insertBefore(c,l.nextSibling)):(f.parentNode.appendChild(l),f.parentNode.appendChild(c)),!0}var nt="http://schemas.microsoft.com/office/2006/xmlPackage",vt="http://schemas.openxmlformats.org/package/2006/relationships";function _a(e,t){let r=B(),n=Q(),a=r.parseFromString(e,"text/xml"),o=j(a);if(o)return Z("[CommentEngine] Failed to parse package:",o.textContent),e;let i=a.documentElement,s=a.createElementNS(nt,"pkg:part");s.setAttribute("pkg:name","/word/comments.xml"),s.setAttribute("pkg:contentType","application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml");let l=a.createElementNS(nt,"pkg:xmlData"),c=r.parseFromString(t,"text/xml");l.appendChild(a.importNode(c.documentElement,!0)),s.appendChild(l),i.appendChild(s);let m=V(i,nt,"part").find(f=>f.getAttribute("pkg:name")==="/word/_rels/document.xml.rels");if(m){let f=V(m,nt,"xmlData");if(f.length>0){let p=V(f[0],vt,"Relationships");if(p.length>0){let g=p[0],d=V(g,vt,"Relationship");if(!d.some(h=>h.getAttribute("Type")?.includes("comments"))){let h=0;d.forEach(x=>{let E=x.getAttribute("Id"),v=parseInt(E?.replace("rId","")||"0",10);v>h&&(h=v)});let b=a.createElementNS(vt,"Relationship");b.setAttribute("Id",`rId${h+1}`),b.setAttribute("Type","http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"),b.setAttribute("Target","comments.xml"),g.appendChild(b)}}}}else{let f=a.createElementNS(nt,"pkg:part");f.setAttribute("pkg:name","/word/_rels/document.xml.rels"),f.setAttribute("pkg:contentType","application/vnd.openxmlformats-package.relationships+xml");let p=a.createElementNS(nt,"pkg:xmlData"),g=a.createElementNS(vt,"Relationships"),d=a.createElementNS(vt,"Relationship");d.setAttribute("Id","rId1"),d.setAttribute("Type","http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"),d.setAttribute("Target","comments.xml"),g.appendChild(d),p.appendChild(g),f.appendChild(p),i.appendChild(f)}return n.serializeToString(a)}function zs(e,t,r){try{let n=t.parseFromString(e,"text/xml"),a=j(n);return a?{xmlDoc:null,warning:r(a.textContent||"parse error")}:{xmlDoc:n,warning:null}}catch(n){return{xmlDoc:null,warning:r(n.message)}}}function Ws(e,t,r={}){let n=r?.author||J(),a=lr(),o=[],i=[];if(!t||t.length===0)return{oxml:e,commentsApplied:0,warnings:["No comments to inject"]};let s=B(),l=Q(),c=zs(e,s,g=>`Failed to parse OXML: ${g}`);if(!c.xmlDoc)return Z("[CommentEngine] Parse failure:",c.warning),{oxml:e,commentsApplied:0,warnings:[c.warning]};let u=c.xmlDoc,m=Pe(u,"w:p");C(`[CommentEngine] Found ${m.length} paragraphs, processing ${t.length} comment requests`);let f=new Map;for(let g of t){let d=g.paragraphIndex-1;if(d<0||d>=m.length){o.push(`Paragraph ${g.paragraphIndex} out of range (1-${m.length})`);continue}f.set(d,(f.get(d)||0)+1)}let p=new Map;for(let g of t){let d=g.paragraphIndex-1;if(d<0||d>=m.length)continue;let w=m[d],h=p.get(d);h||(h=Jt(w),p.set(d,h));let b=sr(),x=La(u,w,g.textToFind,b,h),E=(f.get(d)||1)-1;if(f.set(d,E),!x){o.push(`Could not find "${g.textToFind.substring(0,30)}..." in paragraph ${g.paragraphIndex}`),E===0&&p.delete(d);continue}i.push({id:b,content:g.commentContent,author:n,date:a}),E>0?p.set(d,Jt(w)):p.delete(d)}return i.length===0?{oxml:e,commentsApplied:0,warnings:o}:{oxml:l.serializeToString(u),commentsXml:Kr(i),commentsApplied:i.length,warnings:o}}function Hs(e,t){return _a(e,t)}function Ba(e,t=["all"]){if(!e)return null;let r=e.cloneNode(!0);if(t.includes("all"))["w:b","w:i","w:u","w:strike","w:dstrike","w:color","w:sz","w:szCs","w:rFonts","w:highlight","w:vertAlign","w:spacing","w:w","w:kern","w:position"].forEach(a=>{r.querySelectorAll(`${a}, ${a.replace("w:","")}`).forEach(i=>i.remove())});else{let n={bold:"w:b",italic:"w:i",underline:"w:u",strikethrough:"w:strike",doubleStrike:"w:dstrike",color:"w:color",highlight:"w:highlight",fontSize:"w:sz",fontSizeCs:"w:szCs",fontFamily:"w:rFonts",superscript:"w:vertAlign",subscript:"w:vertAlign"};t.forEach(a=>{let o=n[a];o&&r.querySelectorAll(`${o}, ${o.replace("w:","")}`).forEach(s=>s.remove())})}return r.children.length>0?r:null}function Us(e,t,r){if(!t||!e)return e;let n=Ne(e),a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",o=n.getElementsByTagNameNS(a,"r"),i=n.getElementsByTagNameNS(a,"ins"),s=[...Array.from(o)];for(let l of i){let c=l.getElementsByTagNameNS(a,"r");s.push(...Array.from(c))}for(let l of s){let c=l.getElementsByTagNameNS(a,"t"),u=Array.from(c).map(m=>m.textContent).join("");if(u.includes(t)||u===t){let m=l.getElementsByTagNameNS(a,"rPr");if(m.length>0){let f=m[0],p=Ba(f,r);p?f.parentNode&&f.parentNode.replaceChild(p,f):f.remove()}}}return De(n)}var js={yellow:"yellow",green:"green",cyan:"cyan",magenta:"magenta",blue:"blue",red:"red",darkblue:"darkBlue",darkcyan:"darkCyan",darkgreen:"darkGreen",darkmagenta:"darkMagenta",darkred:"darkRed",darkyellow:"darkYellow",gray25:"lightGray",gray50:"darkGray",black:"black",white:"white"};function Gs(e,t,r="yellow",n={}){let a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",o=js[r.toLowerCase()]||"yellow",i=n?.generateRedlines??!1,s=n?.author||J(),l=t;l?l=t.cloneNode(!0):l=A(e,"w:rPr");let c=null;i&&(c=A(e,"w:rPr"),Array.from(l.childNodes).forEach(f=>{f.nodeName!=="w:rPrChange"&&c.appendChild(f.cloneNode(!0))}));let u=l.getElementsByTagNameNS(a,"highlight");Array.from(u).forEach(f=>f.remove());let m=A(e,"w:highlight");if(m.setAttributeNS(a,"w:val",o),l.appendChild(m),i&&c){let f=A(e,"w:rPrChange"),p=ee(s);f.setAttribute("w:id",String(p.id)),f.setAttribute("w:author",p.author),f.setAttribute("w:date",p.date),f.appendChild(c);let g=l.getElementsByTagNameNS(a,"rPrChange");Array.from(g).forEach(d=>d.remove()),l.appendChild(f)}return l}function Vs(e,t,r="yellow",n={}){if(!t||!e)return e;let a=Ne(e),o="http://schemas.openxmlformats.org/wordprocessingml/2006/main",i=l=>{let c=l.getElementsByTagNameNS(o,"t");return Array.from(c).map(u=>u.textContent).join("")},s=Array.from(a.getElementsByTagNameNS(o,"r"));for(let l=0;l<s.length;l++){let c=s[l],u=i(c);if(!u)continue;let m=u.indexOf(t);if(m===-1)continue;let f=c.parentNode;if(!f){console.warn("[Highlight] Run parent is null; skipping. Likely already processed.");continue}let p=u.substring(0,m),g=u.substring(m,m+t.length),d=u.substring(m+t.length),w=a.createDocumentFragment();if(p.length>0){let h=c.cloneNode(!0),b=h.getElementsByTagNameNS(o,"t");Array.from(b).forEach(E=>E.remove());let x=A(a,"w:t");x.setAttribute("xml:space","preserve"),x.textContent=p,h.appendChild(x),w.appendChild(h)}if(g.length>0){let h=c.cloneNode(!0),b=h.getElementsByTagNameNS(o,"t");Array.from(b).forEach(N=>N.remove());let x=A(a,"w:t");x.setAttribute("xml:space","preserve"),x.textContent=g,h.appendChild(x);let E=h.getElementsByTagNameNS(o,"rPr"),v=E.length>0?E[0]:null,P=Gs(a,v,r,n);v?h.replaceChild(P,v):h.insertBefore(P,h.firstChild),w.appendChild(h)}if(d.length>0){let h=c.cloneNode(!0),b=h.getElementsByTagNameNS(o,"t");Array.from(b).forEach(E=>E.remove());let x=A(a,"w:t");x.setAttribute("xml:space","preserve"),x.textContent=d,h.appendChild(x),w.appendChild(h)}f.replaceChild(w,c)}return De(a)}var ae="http://schemas.openxmlformats.org/wordprocessingml/2006/main",Ks="http://schemas.openxmlformats.org/package/2006/content-types",Ys="http://schemas.openxmlformats.org/package/2006/relationships",$a="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",Xa="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",Da="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",za="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",Fa="word/document.xml",qt="word/numbering.xml",Tt="word/comments.xml",We="[Content_Types].xml",He="word/_rels/document.xml.rels";function Oe(e,t="xml"){let n=B().parseFromString(e,"application/xml"),a=n.getElementsByTagName("parsererror")[0];if(a)throw new Error(`[XML parse error] ${t}: ${a.textContent||"Unknown"}`);return n}function Qt(e){return!!e&&e.nodeType===1&&e.namespaceURI===ae&&e.localName==="sectPr"}function Zr(e){return e.getElementsByTagNameNS("*","body")[0]||null}function Wa(e){for(let t of Array.from(e.childNodes||[]))if(Qt(t))return t;return null}function Zs(e,t){let r=Wa(e);r?e.insertBefore(t,r):e.appendChild(t)}function Ha(e){let t=Zr(e);if(!t)return;let r=Wa(t);if(!r)return;let n=r.nextSibling;for(;n;){let a=n.nextSibling;n.nodeType===1&&t.insertBefore(n,r),n=a}}function Js(e,t={}){let r=typeof t?.onInfo=="function"?t.onInfo:()=>{},n=e.getElementsByTagNameNS(ae,"tc"),a=0;for(let o of Array.from(n)){let i=Array.from(o.childNodes||[]).filter(s=>s.nodeType===1&&s.namespaceURI===ae&&s.localName==="p");for(let s of i){let l=Array.from(s.childNodes||[]).filter(c=>c.nodeType===1&&c.namespaceURI===ae&&c.localName==="p");for(let c of l)o.insertBefore(c,s),a+=1}}return a>0&&r(`[Sanitize] Fixed ${a} nested w:p element(s) in table cells`),a}function Yr(e){return e.getAttribute("pkg:name")||e.getAttribute("name")||""}function qs(e){let t=B(),r=Q(),n=t.parseFromString(e,"application/xml"),a=Array.from(n.getElementsByTagNameNS("*","part")),o=a.find(f=>Yr(f)==="/word/document.xml");if(!o)throw new Error("Package output missing /word/document.xml part");let i=o.getElementsByTagNameNS("*","xmlData")[0];if(!i)throw new Error("Package document part missing pkg:xmlData");let s=Array.from(i.childNodes||[]).find(f=>f.nodeType===1);if(!s)throw new Error("Package document part missing XML payload");let l=s.getElementsByTagNameNS("*","body")[0],c=l?Array.from(l.childNodes||[]).filter(f=>f.nodeType===1&&!Qt(f)):[s],u=a.find(f=>Yr(f)==="/word/numbering.xml"),m=null;if(u){let f=u.getElementsByTagNameNS("*","xmlData")[0],p=f?Array.from(f.childNodes||[]).find(g=>g.nodeType===1):null;p&&(m=r.serializeToString(p))}return{replacementNodes:c,numberingXml:m,sourceType:"package"}}function Qs(e){if(typeof e!="string"||!e.trim())throw new Error("Reconciliation engine returned no OOXML payload for this operation");if(e.includes("<pkg:package"))return qs(e);if(e.includes("<w:document")){let i=B().parseFromString(e,"application/xml"),s=i.getElementsByTagNameNS("*","body")[0];return{replacementNodes:s?Array.from(s.childNodes||[]).filter(c=>c.nodeType===1&&!Qt(c)):Array.from(i.childNodes||[]).filter(c=>c.nodeType===1),numberingXml:null,sourceType:"document"}}let t=`<root xmlns:w="${ae}">${e}</root>`,n=B().parseFromString(t,"application/xml");return{replacementNodes:Array.from(n.documentElement.childNodes||[]).filter(o=>o.nodeType===1),numberingXml:null,sourceType:"fragment"}}function Ua(e,t,r){if(Array.from(e.getElementsByTagNameNS("*","Override")).some(i=>(i.getAttribute("PartName")||"").toLowerCase()===String(t).toLowerCase()))return!1;let o=e.createElementNS(Ks,"Override");return o.setAttribute("PartName",t),o.setAttribute("ContentType",r),e.documentElement.appendChild(o),!0}function ja(e,t,r){let n=e.getElementsByTagNameNS("*","Relationships")[0]||e.documentElement,a=Array.from(n.getElementsByTagNameNS("*","Relationship"));if(a.some(l=>(l.getAttribute("Type")||"")===t))return!1;let i=0;for(let l of a){let c=l.getAttribute("Id")||"",u=Number.parseInt(c.replace(/^rId/i,""),10);Number.isFinite(u)&&(i=Math.max(i,u))}let s=e.createElementNS(Ys,"Relationship");return s.setAttribute("Id",`rId${i+1}`),s.setAttribute("Type",t),s.setAttribute("Target",r),n.appendChild(s),!0}async function pe(e,t){let r=e.file(t);return r?r.async("string"):null}async function el(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{},a=typeof r?.mergeNumberingXml=="function"?r.mergeNumberingXml:null,o=(Array.isArray(t)?t:[t]).filter(Boolean);if(o.length===0)return;let i=await pe(e,qt),s=i||null;for(let f of o){if(!s){s=f;continue}s=a?a(s,f):f}n(i?"[Demo] Merging numbering.xml payload(s) into existing numbering definitions":"[Demo] Adding numbering.xml"),e.file(qt,s);let l=B(),c=Q(),u=await pe(e,We);if(u){let f=l.parseFromString(u,"application/xml");Ua(f,"/word/numbering.xml",Xa)&&e.file(We,c.serializeToString(f))}let m=await pe(e,He);if(m){let f=l.parseFromString(m,"application/xml");ja(f,$a,"numbering.xml")&&e.file(He,c.serializeToString(f))}}async function tl(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{};if(!t)return;let a=B(),o=Q(),i=await pe(e,Tt);if(!i)n("[Demo] Adding comments.xml"),e.file(Tt,t);else{let c=Oe(i,"word/comments.xml (existing)"),u=Oe(t,"word/comments.xml (incoming)"),m=c.documentElement,f=new Set(Array.from(m.getElementsByTagNameNS(ae,"comment")).map(p=>p.getAttribute("w:id")||p.getAttribute("id")).filter(Boolean));for(let p of Array.from(u.documentElement.getElementsByTagNameNS(ae,"comment"))){let g=p.getAttribute("w:id")||p.getAttribute("id");if(g&&f.has(g))throw new Error(`Duplicate comment id: ${g}`);m.appendChild(c.importNode(p,!0))}e.file(Tt,o.serializeToString(c))}let s=await pe(e,We);if(s){let c=a.parseFromString(s,"application/xml");Ua(c,"/word/comments.xml",za)&&e.file(We,o.serializeToString(c))}let l=await pe(e,He);if(l){let c=a.parseFromString(l,"application/xml");ja(c,Da,"comments.xml")&&e.file(He,o.serializeToString(c))}}async function rl(e){let t=await pe(e,Fa);if(!t)throw new Error("Validation failed: missing word/document.xml");let r=Oe(t,Fa);Ha(r);let n=Zr(r);if(!n)throw new Error("Validation failed: word/document.xml has no w:body");let a=Array.from(n.childNodes||[]).filter(d=>d.nodeType===1),o=a.map((d,w)=>({node:d,index:w})).filter(d=>Qt(d.node)).map(d=>d.index);if(o.length>1)throw new Error("Validation failed: multiple body-level w:sectPr");if(o.length===1&&o[0]!==a.length-1)throw new Error("Validation failed: w:sectPr not last");let i=r.getElementsByTagNameNS(ae,"tc");for(let d of Array.from(i))for(let w of Array.from(d.childNodes||[]).filter(h=>h.nodeType===1))if(w.namespaceURI===ae&&w.localName==="p"&&Array.from(w.childNodes||[]).some(b=>b.nodeType===1&&b.namespaceURI===ae&&b.localName==="p"))throw new Error("Validation failed: nested w:p");let s=r.getElementsByTagNameNS(ae,"numPr").length>0,l=r.getElementsByTagNameNS(ae,"commentRangeStart").length>0||r.getElementsByTagNameNS(ae,"commentRangeEnd").length>0||r.getElementsByTagNameNS(ae,"commentReference").length>0,c=await pe(e,qt),u=await pe(e,Tt);if(c)Oe(c,qt);else if(s)throw new Error("Validation failed: numbering used but part missing");if(u)Oe(u,Tt);else if(l)throw new Error("Validation failed: comments used but part missing");let m=await pe(e,We);if(!m)throw new Error(`Validation failed: missing ${We}`);let f=Oe(m,We),p=await pe(e,He);if(!p)throw new Error(`Validation failed: missing ${He}`);let g=Oe(p,He);if(c){let d=Array.from(f.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/numbering.xml"&&(h.getAttribute("ContentType")||"")===Xa),w=Array.from(g.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===$a);if(!d)throw new Error("Validation failed: numbering CT override missing");if(!w)throw new Error("Validation failed: numbering rel missing")}if(u){let d=Array.from(f.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/comments.xml"&&(h.getAttribute("ContentType")||"")===za),w=Array.from(g.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===Da);if(!d)throw new Error("Validation failed: comments CT override missing");if(!w)throw new Error("Validation failed: comments rel missing")}}var at=Object.freeze({STRUCTURED_LIST_DIRECT:"structured_list_direct",EMPTY_FORMATTED_TEXT:"empty_formatted_text",EMPTY_HTML:"empty_html",BLOCK_HTML:"block_html",OOXML_ENGINE:"ooxml_engine"});function Va(e){return!e||typeof e!="string"?e||"":e.replace(/\\n/g,`
195
+ `).replace(/\\t/g," ").replace(/\\r/g,"\r")}function nl(e={}){let t=e.originalText||"",r=Va(e.newContent||""),n=dt(r)||{type:"text",items:[]};return r.includes(`
196
+ `)&&n.type!=="text"?{kind:at.STRUCTURED_LIST_DIRECT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!0,isOriginalEmpty:Ga(t),hasInlineFormatting:er(r),hasBlockElements:tr(r),hasMarkdownTable:yt(r)}}:Ga(t)?er(r)?{kind:at.EMPTY_FORMATTED_TEXT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!0,hasBlockElements:tr(r),hasMarkdownTable:yt(r)}}:{kind:at.EMPTY_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!1,hasBlockElements:tr(r),hasMarkdownTable:yt(r)}}:tr(r)?{kind:at.BLOCK_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:er(r),hasBlockElements:!0,hasMarkdownTable:yt(r)}}:{kind:at.OOXML_ENGINE,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:er(r),hasBlockElements:!1,hasMarkdownTable:yt(r)}}}function Ga(e){return!e||e.trim().length===0}function yt(e){if(!e||!e.includes("|"))return!1;let t=me(e);return t.rows.length>0||t.headers.length>0}function er(e){return e?/(\*\*.+?\*\*|\*.+?\*|__.+?__|_.+?_|`.+?`|~~.+?~~|\+\+.+?\+\+)/.test(e):!1}function tr(e){if(!e)return!1;let t=/^[\s]*[-*+]\s+/m.test(e),r=/^[\s]*\d+\.\s+/m.test(e),n=/^[\s]*\d+\.\d+(?:\.\d+)*\.?\s+/m.test(e),a=/^[\s]*[A-Za-z]\.\s+/m.test(e),o=/^[\s]*[ivxlcIVXLC]+\.\s+/m.test(e),i=/^[\s]*\([a-z]\)\s+/m.test(e),s=/\|.*\|.*\n/.test(e),l=/^#{1,9}\s/m.test(e),c=e.includes(`
193
197
 
194
- `);return t||r||n||a||i||o||s||l||c}function gs(e){if(!e||typeof e!="string")return null;let t=e.match(/\b(?:w14:paraId|w:paraId|paraId)="([^"]+)"/i);return t?t[1]:null}async function oa(e,t,r,n={}){let a=await nr(e,t,r,n);if(a?.useNativeApi&&typeof a?.oxml!="string"){let i=Array.isArray(a?.warnings)?a.warnings:[];return{...a,oxml:e,hasChanges:!1,warnings:[...i,"Standalone mode cannot execute native Word API fallback for this operation."]}}return a}async function Lf(e,t,r,n={}){let a=typeof e=="string"?e:"",i=typeof r=="string"?r:String(r||""),o;try{o=se(i)}catch{o={headers:[],rows:[]}}return(o?.headers?.length||0)>0||(o?.rows?.length||0)>0?{...await oa(a,t||"",i,n),isMarkdownTable:!0,tableData:o}:{oxml:a,hasChanges:!1,isMarkdownTable:!1,warnings:["Could not parse Markdown table from input."]}}async function _f(e,t,r,n={}){let a=n.listFallbackAllowExistingList!==!1,i=mr({oxml:e,originalText:t,modifiedText:r,allowExistingList:a}),o=n.preferListStructuralFallback!==!1,s=[];if(i&&o){let p=await At(i,{author:n.author,generateRedlines:n.generateRedlines,pipeline:n.listFallbackPipeline});if(p?.hasChanges&&p?.oxml){let g=Te(p.oxml,{includeNumbering:p.includeNumbering??!0,numberingXml:p.numberingXml}),d=Array.isArray(p?.warnings)?p.warnings:[];return{oxml:g,hasChanges:!0,warnings:d,listStructuralFallbackApplied:!0,listStructuralFallbackKey:p.listStructuralFallbackKey||null,listStructuralFallbackNumberingXml:p.numberingXml||null}}s=Array.isArray(p?.warnings)?p.warnings:[]}let l=await oa(e,t,r,n);if(!i)return{...l,warnings:[...Array.isArray(l?.warnings)?l.warnings:[],...s],listStructuralFallbackApplied:!1};if(o)return{...l,warnings:[...Array.isArray(l?.warnings)?l.warnings:[],...s],listStructuralFallbackApplied:!1};if(l?.hasChanges)return{...l,listStructuralFallbackApplied:!1};let c=await At(i,{author:n.author,generateRedlines:n.generateRedlines,pipeline:n.listFallbackPipeline});if(!c?.hasChanges||!c?.oxml){let p=Array.isArray(l?.warnings)?l.warnings:[],g=Array.isArray(c?.warnings)?c.warnings:[];return{...l,warnings:[...p,...g],listStructuralFallbackApplied:!1}}let u=Te(c.oxml,{includeNumbering:c.includeNumbering??!0,numberingXml:c.numberingXml}),m=Array.isArray(l?.warnings)?l.warnings:[],f=Array.isArray(c?.warnings)?c.warnings:[];return{...l,oxml:u,hasChanges:!0,warnings:[...m,...s,...f],listStructuralFallbackApplied:!0,listStructuralFallbackKey:c.listStructuralFallbackKey||null,listStructuralFallbackNumberingXml:c.numberingXml||null}}export{$e as ContainerKind,Or as ContentType,re as DiffOp,I as NS_W,et as NumberingService,Oe as ReconciliationPipeline,Ze as RoutePlanKind,R as RunKind,te as WORD_MAIN_NS,Uo as acceptTrackedChangesInOoxml,es as applyFormattingRemovalToOoxml,ns as applyHighlightToOoxml,oa as applyRedlineToOxml,_f as applyRedlineToOxmlWithListFallback,wr as buildCommentElement,br as buildCommentsPartXml,Po as buildExplicitDecimalMultilevelNumberingXml,qi as buildListMarkdown,ps as buildReconciliationPlan,mr as buildSingleLineListStructuralFallbackPlan,Ui as buildTargetReferenceSnapshot,io as clearSingleLineListFallbackExplicitSequence,Ln as collectContiguousListParagraphBlock,ba as configureLogger,da as configureXmlProvider,xo as createDynamicNumberingIdState,Qo as deleteCommentsByAuthorInOoxml,oo as enforceListBindingOnParagraphNodes,fs as ensureCommentsArtifactsInZip,us as ensureNumberingArtifactsInZip,ee as escapeXml,At as executeSingleLineListStructuralFallback,Eo as extractFirstParagraphNumId,gs as extractParagraphIdFromOoxml,cs as extractReplacementNodesFromOoxml,He as findContainingWordElement,or as findParagraphByBestTextMatch,Sn as findParagraphByReference,Pt as findParagraphByStrictText,ke as generateTableOoxml,yr as getBodyElementFromDocument,G as getDefaultAuthor,de as getDocumentParagraphNodes,Tr as getPackagePartName,he as getParagraphListInfo,W as getParagraphText,zt as getPlatform,ur as hasListItems,fr as inferNumberingStyleFromMarker,wo as inferTableReplacementParagraphBlock,bt as ingestOoxml,Fo as ingestWordOoxmlToMarkdown,$o as ingestWordOoxmlToPlainText,zo as injectCommentsIntoOoxml,Wo as injectCommentsIntoPackage,os as insertBodyElementBeforeSectPr,Fn as isLikelyStructuredTableSourceParagraph,lr as isMarkdownTableText,Io as mergeNumberingXmlBySchemaOrder,ta as normalizeBodySectionOrderStandalone,ia as normalizeContentEscapesForRouting,Qi as normalizeListItemsWithLevels,L as normalizeWhitespaceForTargeting,yo as overwriteParagraphNumIds,it as parseMarkdownListContent,ge as parseOoxml,cr as parseParagraphReference,Se as parseXmlStrictStandalone,Ji as planListInsertionOnlyEdit,q as preprocessMarkdown,Lf as reconcileMarkdownTableOoxml,ao as recordSingleLineListFallbackExplicitSequence,Ko as rejectTrackedChangesInOoxml,So as remapNumberingPayloadForDocument,Kn as removeFormattingFromRPr,st as reserveNextNumberingId,vo as reserveNextNumberingIdPair,ji as resolveParagraphRangeByRefs,no as resolveSingleLineListFallbackNumberingAction,In as resolveTargetParagraph,sr as resolveTargetParagraphWithSnapshot,Pn as sanitizeAiResponse,ss as sanitizeNestedParagraphsInTables,Me as serializeOoxml,oe as serializeToOoxml,xa as setDefaultAuthor,Na as setPlatform,zi as splitLeadingParagraphMarker,Di as stripLeadingParagraphMarker,On as stripRedundantLeadingListMarkers,to as stripSingleLineListMarkerPrefix,Yi as synthesizeExpandedListScopeEdit,bo as synthesizeTableMarkdownFromMultilineCellEdit,ms as validateDocxPackage,Te as wrapInDocumentFragment};
198
+ `);return t||r||n||a||o||i||s||l||c}function al(e){if(!e||typeof e!="string")return null;let t=e.match(/\b(?:w14:paraId|w:paraId|paraId)="([^"]+)"/i);return t?t[1]:null}async function Ka(e,t,r,n={}){let a=await Mr(e,t,r,n);if(a?.useNativeApi&&typeof a?.oxml!="string"){let o=Array.isArray(a?.warnings)?a.warnings:[];return te({...a,oxml:e,hasChanges:!1,warnings:[...o,"Standalone mode cannot execute native Word API fallback for this operation."]})}return a}async function rp(e,t,r,n={}){let a=typeof e=="string"?e:"",o=typeof r=="string"?r:String(r||""),i;try{i=me(o)}catch{i={headers:[],rows:[]}}return(i?.headers?.length||0)>0||(i?.rows?.length||0)>0?{...await Ka(a,t||"",o,n),isMarkdownTable:!0,tableData:i}:{oxml:a,hasChanges:!1,isMarkdownTable:!1,warnings:["Could not parse Markdown table from input."]}}async function np(e,t,r,n={}){let a=n.listFallbackAllowExistingList!==!1,o=Wr({oxml:e,originalText:t,modifiedText:r,allowExistingList:a}),i=n.preferListStructuralFallback!==!1,s=[];if(o&&i){let p=await Vt(o,{author:n.author,generateRedlines:n.generateRedlines,pipeline:n.listFallbackPipeline});if(p?.hasChanges&&p?.oxml){let g=Ie(p.oxml,{includeNumbering:p.includeNumbering??!0,numberingXml:p.numberingXml}),d=Array.isArray(p?.warnings)?p.warnings:[];return te({oxml:g,hasChanges:!0,warnings:d,listStructuralFallbackApplied:!0,listStructuralFallbackKey:p.listStructuralFallbackKey||null,listStructuralFallbackNumberingXml:p.numberingXml||null})}s=Array.isArray(p?.warnings)?p.warnings:[]}let l=await Ka(e,t,r,n);if(!o)return{...l,warnings:[...Array.isArray(l?.warnings)?l.warnings:[],...s],listStructuralFallbackApplied:!1};if(i)return{...l,warnings:[...Array.isArray(l?.warnings)?l.warnings:[],...s],listStructuralFallbackApplied:!1};if(l?.hasChanges)return{...l,listStructuralFallbackApplied:!1};let c=await Vt(o,{author:n.author,generateRedlines:n.generateRedlines,pipeline:n.listFallbackPipeline});if(!c?.hasChanges||!c?.oxml){let p=Array.isArray(l?.warnings)?l.warnings:[],g=Array.isArray(c?.warnings)?c.warnings:[];return{...l,warnings:[...p,...g],listStructuralFallbackApplied:!1}}let u=Ie(c.oxml,{includeNumbering:c.includeNumbering??!0,numberingXml:c.numberingXml}),m=Array.isArray(l?.warnings)?l.warnings:[],f=Array.isArray(c?.warnings)?c.warnings:[];return te({...l,oxml:u,hasChanges:!0,warnings:[...m,...s,...f],listStructuralFallbackApplied:!0,listStructuralFallbackKey:c.listStructuralFallbackKey||null,listStructuralFallbackNumberingXml:c.numberingXml||null})}export{Ue as ContainerKind,an as ContentType,ce as DiffOp,S as NS_W,lt as NumberingService,Be as ReconciliationPipeline,at as RoutePlanKind,O as RunKind,se as WORD_MAIN_NS,kr as acceptTrackedChangesInOoxml,Us as applyFormattingRemovalToOoxml,Vs as applyHighlightToOoxml,Ka as applyRedlineToOxml,np as applyRedlineToOxmlWithListFallback,Vr as buildCommentElement,Kr as buildCommentsPartXml,Is as buildExplicitDecimalMultilevelNumberingXml,Yi as buildListMarkdown,nl as buildReconciliationPlan,Wr as buildSingleLineListStructuralFallbackPlan,zi as buildTargetReferenceSnapshot,rs as clearSingleLineListFallbackExplicitSequence,ya as collectContiguousListParagraphBlock,io as configureLogger,no as configureXmlProvider,xr as containsTrackedChanges,vs as createDynamicNumberingIdState,Li as deleteCommentsByAuthorInOoxml,ns as enforceListBindingOnParagraphNodes,tl as ensureCommentsArtifactsInZip,el as ensureNumberingArtifactsInZip,oe as escapeXml,Vt as executeSingleLineListStructuralFallback,Ss as extractFirstParagraphNumId,al as extractParagraphIdFromOoxml,Qs as extractReplacementNodesFromOoxml,qe as findContainingWordElement,Br as findParagraphByBestTextMatch,da as findParagraphByReference,Ht as findParagraphByStrictText,_e as generateTableOoxml,Zr as getBodyElementFromDocument,J as getDefaultAuthor,ve as getDocumentParagraphNodes,Yr as getPackagePartName,Te as getParagraphListInfo,G as getParagraphText,or as getPlatform,Dr as hasListItems,zr as inferNumberingStyleFromMarker,xs as inferTableReplacementParagraphBlock,Ot as ingestOoxml,Xs as ingestWordOoxmlToMarkdown,$s as ingestWordOoxmlToPlainText,Ws as injectCommentsIntoOoxml,Hs as injectCommentsIntoPackage,Zs as insertBodyElementBeforeSectPr,Ia as isLikelyStructuredTableSourceParagraph,$r as isMarkdownTableText,As as mergeNumberingXmlBySchemaOrder,Ha as normalizeBodySectionOrderStandalone,Va as normalizeContentEscapesForRouting,Zi as normalizeListItemsWithLevels,_ as normalizeWhitespaceForTargeting,Ps as overwriteParagraphNumIds,dt as parseMarkdownListContent,Ne as parseOoxml,Xr as parseParagraphReference,Oe as parseXmlStrictStandalone,Ki as planListInsertionOnlyEdit,ne as preprocessMarkdown,rp as reconcileMarkdownTableOoxml,ts as recordSingleLineListFallbackExplicitSequence,Ai as rejectTrackedChangesInOoxml,Cs as remapNumberingPayloadForDocument,Ba as removeFormattingFromRPr,bt as reserveNextNumberingId,ys as reserveNextNumberingIdPair,Wi as resolveParagraphRangeByRefs,es as resolveSingleLineListFallbackNumberingAction,ha as resolveTargetParagraph,Fr as resolveTargetParagraphWithSnapshot,ga as sanitizeAiResponse,Js as sanitizeNestedParagraphsInTables,De as serializeOoxml,fe as serializeToOoxml,so as setDefaultAuthor,lo as setPlatform,$i as splitLeadingParagraphMarker,Fi as stripLeadingParagraphMarker,va as stripRedundantLeadingListMarkers,qi as stripSingleLineListMarkerPrefix,Vi as synthesizeExpandedListScopeEdit,Ns as synthesizeTableMarkdownFromMultilineCellEdit,rl as validateDocxPackage,gs as validateRedlineOoxml,Ie as wrapInDocumentFragment};
195
199
  //# sourceMappingURL=docx-redline-js.esm.min.js.map