@ansonlai/docx-redline-js 0.1.3 → 0.1.6

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 (42) hide show
  1. package/AGENTS.md +91 -5
  2. package/ARCHITECTURE.md +62 -9
  3. package/README.md +94 -3
  4. package/core/types.js +35 -8
  5. package/core/word-xml.js +90 -0
  6. package/dist/docx-redline-js.esm.js +1149 -367
  7. package/dist/docx-redline-js.esm.js.map +4 -4
  8. package/dist/docx-redline-js.esm.min.js +78 -74
  9. package/dist/docx-redline-js.esm.min.js.map +4 -4
  10. package/docs/VALIDATION.md +48 -0
  11. package/docs/plans/2026-03-01-release-0.1.4-design.md +31 -0
  12. package/docs/plans/2026-03-01-release-0.1.4.md +108 -0
  13. package/engine/format-application.js +13 -14
  14. package/engine/format-span-application.js +7 -6
  15. package/engine/formatting-removal.js +15 -12
  16. package/engine/oxml-engine.js +146 -55
  17. package/engine/reconstruction-mapper.js +35 -8
  18. package/engine/reconstruction-mode.js +14 -13
  19. package/engine/reconstruction-writer.js +97 -78
  20. package/engine/rpr-helpers.js +34 -32
  21. package/engine/run-builders.js +150 -39
  22. package/engine/surgical-diff-application.js +216 -0
  23. package/engine/surgical-mode.js +84 -519
  24. package/engine/surgical-run-splitting.js +96 -0
  25. package/engine/surgical-spans.js +169 -0
  26. package/engine/table-cell-context.js +15 -13
  27. package/engine/table-mode.js +39 -35
  28. package/index.d.ts +148 -0
  29. package/index.js +26 -19
  30. package/package.json +8 -1
  31. package/pipeline/ingestion-export.js +1 -0
  32. package/pipeline/ingestion-paragraph.js +37 -12
  33. package/pipeline/ingestion-table.js +11 -8
  34. package/scripts/build.mjs +35 -0
  35. package/scripts/check-types.mjs +28 -0
  36. package/scripts/export-validation-fixtures.mjs +68 -0
  37. package/scripts/run-tests.mjs +43 -0
  38. package/scripts/word-com-smoke.ps1 +48 -0
  39. package/services/comment-locator.js +10 -9
  40. package/services/revision-comment-management.js +501 -0
  41. package/services/standalone-operation-runner.js +119 -69
  42. package/services/table-reconciliation.js +7 -8
@@ -1,16 +1,16 @@
1
- var Jn=Object.create;var wr=Object.defineProperty;var qn=Object.getOwnPropertyDescriptor;var Qn=Object.getOwnPropertyNames;var ea=Object.getPrototypeOf,ta=Object.prototype.hasOwnProperty;var ra=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var na=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Qn(t))!ta.call(e,a)&&a!==r&&wr(e,a,{get:()=>t[a],enumerable:!(n=qn(t,a))||n.enumerable});return e};var aa=(e,t,r)=>(r=e!=null?Jn(ea(e)):{},na(t||!e||!e.__esModule?wr(r,"default",{value:e,enumerable:!0}):r,e));var Rr=ra((vs,Be)=>{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,O=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(O,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(O,s)),l&&c.push(new y.Diff(O,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(O,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],f=l[1],m=l[2],u=l[3],p=l[4],g=this.diff_main(c,m,r,n),d=this.diff_main(f,u,r,n);return g.concat([new y.Diff(O,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(O,""));for(var o=0,s=0,l=0,c="",f="";o<i.length;){switch(i[o][0]){case F:l++,f+=i[o][1];break;case $:s++,c+=i[o][1];break;case O:if(s>=1&&l>=1){i.splice(o-s-l,s+l),o=o-s-l;for(var m=this.diff_main(c,f,!1,r),u=m.length-1;u>=0;u--)i.splice(o,0,m[u]);o=o+m.length}l=0,s=0,c="",f="";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),f=0;f<s;f++)l[f]=-1,c[f]=-1;l[o+1]=0,c[o+1]=0;for(var m=n-a,u=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(u){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(!u){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),f=this.diff_main(s,l,!1,a);return c.concat(f)};y.prototype.diff_linesToChars_=function(e,t){var r=[],n={};r[0]="";function a(l){for(var c="",f=0,m=-1,u=r.length;m<l.length-1;){m=l.indexOf(`
2
- `,f),m==-1&&(m=l.length-1);var p=l.substring(f,m+1);(n.hasOwnProperty?n.hasOwnProperty(p):n[p]!==void 0)?c+=String.fromCharCode(n[p]):(u==i&&(p=l.substring(f),m=l.length),c+=String.fromCharCode(u),n[p]=u,r[u++]=p),f=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,f,m,u;e.length>t.length?(c=l[0],f=l[1],m=l[2],u=l[3]):(m=l[0],u=l[1],c=l[2],f=l[3]);var p=l[4];return[c,f,m,u,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]==O?(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 f=e[i-1][1],m=e[i][1],u=this.diff_commonOverlap_(f,m),p=this.diff_commonOverlap_(m,f);u>=p?(u>=f.length/2||u>=m.length/2)&&(e.splice(i,0,new y.Diff(O,m.substring(0,u))),e[i-1][1]=f.substring(0,f.length-u),e[i+1][1]=m.substring(u),i++):(p>=f.length/2||p>=m.length/2)&&(e.splice(i,0,new y.Diff(O,f.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]=f.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]==O&&e[r+1][0]==O){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,f=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 u=t(n,a)+t(a,i);u>=m&&(m=u,l=n,c=a,f=i)}e[r-1][1]!=l&&(l?e[r-1][1]=l:(e.splice(r-1,1),r--),e[r][1]=c,f?e[r+1][1]=f:(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]==O?(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(O,""));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 O: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]==O?e[t-r-n-1][1]+=i.substring(0,o):(e.splice(0,0,new y.Diff(O,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]==O?(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]==O&&e[t+1][0]==O&&(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 O: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 O: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 O: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(O,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,f,m=t.length+e.length,u,p=0;p<t.length;p++){for(c=0,f=m;c<f;)i(p,r+f)<=o?c=f:m=f,f=Math.floor((m-c)/2+c);m=f;var g=Math.max(1,r-f+1),d=Math.min(r+f,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|((u[h+1]|u[h])<<1|1)|u[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;u=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(O,a));var i=t.substring(e.start2+e.length1,e.start2+e.length1+n);i&&e.diffs.push(new y.Diff(O,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,f=n,m=n,u=0;u<a.length;u++){var p=a[u][0],g=a[u][1];switch(!s&&p!==O&&(o.start1=l,o.start2=c),p){case F:o.diffs[s++]=a[u],o.length2+=g.length,m=m.substring(0,c)+g+m.substring(c);break;case $:o.length1+=g.length,o.diffs[s++]=a[u],m=m.substring(0,c)+m.substring(c+g.length);break;case O:g.length<=2*this.Patch_Margin&&s&&a.length!=u+1?(o.diffs[s++]=a[u],o.length1+=g.length,o.length2+=g.length):g.length>=2*this.Patch_Margin&&s&&(this.patch_addContext_(o,f),i.push(o),o=new y.patch_obj,s=0,f=m,l=c);break}p!==F&&(l+=g.length),p!==$&&(c+=g.length)}return s&&(this.patch_addContext_(o,f),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 f;if(c==-1?f=t.substring(l,l+s.length):f=t.substring(l,c+this.Match_MaxBits),s==f)t=t.substring(0,l)+this.diff_text2(e[i].diffs)+t.substring(l+s.length);else{var m=this.diff_main(s,f,!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 u=0,p,g=0;g<e[i].diffs.length;g++){var d=e[i].diffs[g];d[0]!==O&&(p=this.diff_xIndex(m,u)),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,u+d[1].length))),d[0]!==$&&(u+=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]!=O)i.unshift(new y.Diff(O,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]!=O)i.push(new y.Diff(O,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(O,o)));n.diffs.length!==0&&s.length1<t-this.Patch_Margin;){var c=n.diffs[0][0],f=n.diffs[0][1];c===F?(s.length2+=f.length,i+=f.length,s.diffs.push(n.diffs.shift()),l=!1):c===$&&s.diffs.length==1&&s.diffs[0][0]==O&&f.length>2*t?(s.length1+=f.length,a+=f.length,l=!1,s.diffs.push(new y.Diff(c,f)),n.diffs.shift()):(f=f.substring(0,t-s.length1-this.Patch_Margin),s.length1+=f.length,a+=f.length,c===O?(s.length2+=f.length,i+=f.length):l=!1,s.diffs.push(new y.Diff(c,f)),f==n.diffs[0][1]?n.diffs.shift():n.diffs[0][1]=n.diffs[0][1].substring(f.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]===O?s.diffs[s.diffs.length-1][1]+=m:s.diffs.push(new y.Diff(O,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(O,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 O:n=" ";break}r[a+1]=n+encodeURI(this.diffs[a][1])+`
5
- `}return r.join("").replace(/%20/g," ")};Be.exports=y;Be.exports.diff_match_patch=y;Be.exports.DIFF_DELETE=$;Be.exports.DIFF_INSERT=F;Be.exports.DIFF_EQUAL=O});var Ke=globalThis.DOMParser,Ve=globalThis.XMLSerializer;function ia(e={}){e.DOMParser&&(Ke=e.DOMParser),e.XMLSerializer&&(Ve=e.XMLSerializer)}function B(){if(!Ke&&globalThis.DOMParser&&(Ke=globalThis.DOMParser),!Ke)throw new Error("DOMParser is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new Ke}function J(){if(!Ve&&globalThis.XMLSerializer&&(Ve=globalThis.XMLSerializer),!Ve)throw new Error("XMLSerializer is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new Ve}function br(e,t="text/xml"){return B().parseFromString(e,t)}function j(e){return J().serializeToString(e)}var ft=console,Mt=Object.freeze({silent:0,error:1,warn:2,info:3}),oa=typeof process<"u"&&process?.env?.NODE_ENV==="production"?"warn":"info",Lt=oa;function sa(e){let t=String(e||"").toLowerCase();return Object.prototype.hasOwnProperty.call(Mt,t)?t:Lt}function _t(e){return Mt[Lt]>=Mt[e]}function la(e,t={}){ft=e||console,t.level&&(Lt=sa(t.level))}function A(...e){_t("info")&&(ft.log||(()=>{}))(...e)}function Se(...e){_t("warn")&&(ft.warn||(()=>{}))(...e)}function K(...e){_t("error")&&(ft.error||(()=>{}))(...e)}var xr="Author",Nr="Unknown";function ca(e){xr=typeof e=="string"&&e.trim()?e.trim():"Author"}function G(){return xr}function ua(e){Nr=typeof e=="string"&&e.trim()?e.trim():"Unknown"}function Bt(){return Nr}var fa=[{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 fa){let l,c=s.regex.source||s.regex.toString().replace(/^\/|\/[gimuy]*$/g,""),f="g"+(s.regex.ignoreCase?"i":""),m=new RegExp(c,f);for(;(l=m.exec(e))!==null;)n.push({start:l.index,end:l.index+l[0].length,fullMatch:l[0],innerText:s.isEscaped?ma(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 f=r.length;t.push({start:c,end:f,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 he(e,t,r){return e.filter(n=>n.start<r&&n.end>t)}function $t(...e){let t={};for(let r of e)r&&Object.assign(t,r);return t}function ma(e){return e?e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#039;/g,"'"):""}var mt=String.raw`(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|\d+\.|[ivxlcIVXLC]+\.|[-*\u2022])`,vr=new RegExp(`^(\\s*)((?:${mt})\\s+)`),Tr=new RegExp(`^(\\s*)((?:${mt})\\s*)`),pa=new RegExp(`^(\\s*)((?:${mt})\\s+)`,"m"),ga=new RegExp(`^(\\s*)((?:${mt})\\s*)`,"m");function yr(e){return typeof e!="string"?!1:e.includes(`
6
- `)&&pa.test(e)}function pt(e){return typeof e!="string"?!1:e.includes(`
7
- `)&&ga.test(e.trim())}function ue(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?Tr:vr;return e.match(n)}function we(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?Tr:vr;return e.replace(n,"")}var I="http://schemas.openxmlformats.org/wordprocessingml/2006/main";var re=Object.freeze({EQUAL:"equal",DELETE:"delete",INSERT:"insert"}),C=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"}),Le=Object.freeze({SDT:"sdt",SMART_TAG:"smartTag",CUSTOM_XML:"customXml",FIELD_COMPLEX:"fldComplex"}),Er=Object.freeze({PARAGRAPH:"paragraph",BULLET_LIST:"bullet_list",NUMBERED_LIST:"numbered_list",TABLE:"table"}),_=Object.freeze({DECIMAL:"decimal",LOWER_ALPHA:"lowerLetter",UPPER_ALPHA:"upperLetter",LOWER_ROMAN:"lowerRoman",UPPER_ROMAN:"upperRoman",BULLET:"bullet",OUTLINE:"outline"}),V=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 da=1e3;function be(){return da++}function ae(e=new Date){return e.toISOString()}function fe(e){let t=typeof e=="string"&&e.trim()?e.trim():G();return{id:be(),author:t,date:ae()}}var Pr=`
8
- `,ha=Pr.length;function Sr(e,t){return e<t-1}function _e(e,t,r){return Sr(t,r)?e+Pr:e}function Ie(e,t,r){return Sr(t,r)?e+ha:e}function Y(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 Ir(e,t,r,n=`w:${r}`){let a=z(e,t,r);return a.length>0?a:Y(e,n)}function Ar(e,t,r,n=`w:${r}`){let a=D(e,t,r);return a||M(e,n)}function U(e){return M(e,"parsererror")}function Ft(e){return Array.from(e?.childNodes||[])}function kr(e){return Array.from(e.attributes).map(t=>`${t.name}="${t.value}"`).join(" ")}function Xt(e,t,r=""){return!e||e.namespaceURI!==t?!1:r?e.localName===r:!0}var Dt=0;function gt(e,t={}){let r=[],n="",a=t.xmlDoc||null;if(!e&&!a)return{runModel:r,acceptedText:n,pPr:null};try{let i=a||B().parseFromString(e,"application/xml"),o=U(i);if(o)return K("OOXML parse error:",o.textContent),{runModel:r,acceptedText:n,pPr:null};let s=z(i,I,"p");return s.length===0?(Se("No paragraphs found in OOXML"),{runModel:r,acceptedText:n,pPr:null}):Cr(s,{includeParagraphBoundaries:!0})}catch(i){return K("Error ingesting OOXML:",i),{runModel:r,acceptedText:n,pPr:null}}}function zt(e){return e?Cr([e],{includeParagraphBoundaries:!1}):{runModel:[],acceptedText:"",pPr:null}}function Wt(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 Cr(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:C.PARAGRAPH_START,pPrElement:c||null,startOffset:i,endOffset:i,text:""});let f=Ze(l,i,n);a+=f.text,i=a.length,r&&(a=_e(a,s,e.length),i=Ie(i,s,e.length))}return{runModel:n,acceptedText:a,pPr:o}}function Ze(e,t,r){let n=t,a="",i=wa(r);for(let o of Ft(e)){if(Xt(o,I,"pPr")||Xt(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 wa(e){let t=new Map;return t.set("sdt",(r,n)=>{let a=`sdt_${Dt++}`,i=D(r,I,"sdtPr"),o=D(r,I,"sdtContent");e.push({kind:C.CONTAINER_START,containerKind:Le.SDT,containerId:a,propertiesXml:i?j(i):"",startOffset:n,endOffset:n,text:""});let s=o?Ze(o,n,e):{offset:n,text:""};return e.push({kind:C.CONTAINER_END,containerKind:Le.SDT,containerId:a,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("smartTag",(r,n)=>{let a=`smartTag_${Dt++}`;e.push({kind:C.CONTAINER_START,containerKind:Le.SMART_TAG,containerId:a,propertiesXml:kr(r),startOffset:n,endOffset:n,text:""});let i=Ze(r,n,e);return e.push({kind:C.CONTAINER_END,containerKind:Le.SMART_TAG,containerId:a,startOffset:i.offset,endOffset:i.offset,text:""}),i}),t.set("del",(r,n)=>{let a=xa(r,n);return a&&e.push(a),{offset:n,text:""}}),t.set("bookmarkStart",(r,n)=>(e.push({kind:C.BOOKMARK,nodeXml:j(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("bookmarkEnd",(r,n)=>(e.push({kind:C.BOOKMARK,nodeXml:j(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("ins",(r,n)=>Ze(r,n,e)),t.set("hyperlink",(r,n)=>{let a=`hyperlink_${Dt++}`,i=r.getAttribute("r:id")||"",o=r.getAttribute("w:anchor")||"";e.push({kind:C.CONTAINER_START,containerKind:"hyperlink",containerId:a,propertiesXml:JSON.stringify({rId:i,anchor:o}),startOffset:n,endOffset:n,text:""});let s=Ze(r,n,e);return e.push({kind:C.CONTAINER_END,containerKind:"hyperlink",containerId:a,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("r",(r,n)=>{let a=ba(r,n);return!a||!a.text?{offset:n,text:""}:(e.push(a),{offset:n+a.text.length,text:a.text})}),t}function ba(e,t){let r=Ar(e,I,"rPr"),n=r?j(r):"",a="";for(let i of Ft(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:C.TEXT,text:a,rPrXml:n,startOffset:t,endOffset:t+a.length}:null}function xa(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:C.DELETION,text:n,rPrXml:"",startOffset:t,endOffset:t,author:r,nodeXml:j(e)}:null}function Ut(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 f=a[c],m=z(f,I,"tc"),u=0;for(let p=0;p<m.length;p++){let g=m[p],d=D(g,I,"tcPr");for(;u<n&&o[c][u]!==null;)u++;if(u>=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(u);E?(E.cell.rowSpan++,N={gridRow:c,gridCol:u,rowSpan:0,colSpan:h,tcNode:g,blocks:[],tcPrXml:Ht(d),isMergeOrigin:!1,isMergeContinuation:!0,mergeOrigin:E.cell}):N=Na(c,u,h,g,d)}else{let E=Or(g);if(N={gridRow:c,gridCol:u,rowSpan:1,colSpan:h,tcNode:g,blocks:E,tcPrXml:Ht(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(u+b,{originRow:c,cell:N});else for(let b=0;b<h;b++)l.delete(u+b)}for(let E=0;E<h;E++){let b=u+E;b<n&&(o[c][b]=N,s.set(`${c},${b}`,N))}u+=h}}return{rowCount:i,colCount:n,grid:o,cellMap:s,tblPrXml:va(e),tblGridXml:Ta(e),trPrList:Array.from(a).map(c=>ya(c))}}function Na(e,t,r,n,a){let i=Or(n);return{gridRow:e,gridCol:t,rowSpan:1,colSpan:r,tcNode:n,blocks:i,tcPrXml:Ht(a),isMergeOrigin:!1,isMergeContinuation:!1,getText:()=>i.map(o=>o.acceptedText).join(`
11
- `)}}function Or(e){return Ir(e,I,"p").map(r=>{let{runModel:n,acceptedText:a,pPr:i}=zt(r);return{runModel:n,acceptedText:a,pPr:i}})}function Ht(e){return e?j(e):"<w:tcPr/>"}function va(e){let t=D(e,I,"tblPr");return t?j(t):"<w:tblPr/>"}function Ta(e){let t=D(e,I,"tblGrid");return t?j(t):"<w:tblGrid/>"}function ya(e){let t=D(e,I,"trPr");return t?j(t):"<w:trPr/>"}var Lr=aa(Rr(),1);var Mr=new Lr.diff_match_patch;function Ea(e,t){let r=[],n=new Map;function a(l){let c=[],f=/(\S+)(\s*)/g,m;for(;(m=f.exec(l))!==null;)m[1]&&c.push(m[1]),m[2]&&c.push(m[2]);return c}function i(l){let c="";for(let f of l)if(n.has(f))c+=String.fromCharCode(n.get(f));else{let m=r.length;r.push(f),n.set(f,m),c+=String.fromCharCode(m)}return c}let o=a(e),s=a(t);return{chars1:i(o),chars2:i(s),wordArray:r}}function Pa(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 Ye(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}=Ea(e,t),s=Mr.diff_main(a,i);return n&&Mr.diff_cleanupSemantic(s),Pa(s,o)}function dt(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=Ye(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 Sa=/\s+xmlns:[^=]+="[^"]*"/g;function ht(e,t){let r=Ra(t),n=[],a=0;for(let i of e){if(i.kind!==C.TEXT&&i.kind!==C.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 wt(e,t,r){let{generateRedlines:n,author:a}=r,i=[],o=new Set,s=Ma(t),l=Ca(e),c=Oa(s.nonInsertOps),f={containerStack:[],lastParagraphStartIndex:-1,currentParagraphPPrXml:"",currentParagraphPPrElement:null};for(let u of e){if(u.kind===C.CONTAINER_START){f.containerStack.push(u.containerId),i.push({...u});continue}if(u.kind===C.CONTAINER_END){f.containerStack.pop(),i.push({...u});continue}if(u.kind===C.PARAGRAPH_START){f.currentParagraphPPrXml=typeof u.pPrXml=="string"?u.pPrXml:"",f.currentParagraphPPrElement=u.pPrElement||null,i.push({...u}),f.lastParagraphStartIndex=i.length-1;continue}if(u.kind===C.BOOKMARK||u.kind===C.DELETION){i.push({...u});continue}let p=c(u.startOffset,u.endOffset),g=s.insertOpsByStartOffset.get(u.startOffset)||[];for(let d of g)o.has(d)||(o.add(d),Ia({insertOp:d,splitModel:e,styleLookup:l,patchedModel:i,state:f,options:r,generateRedlines:n,author:a}));if(!p||p.type===re.EQUAL){i.push({...u,containerContext:f.containerStack.length>0?f.containerStack[f.containerStack.length-1]:null});continue}p.type===re.DELETE&&n&&i.push({...u,kind:C.DELETION,author:a,containerContext:f.containerStack.length>0?f.containerStack[f.containerStack.length-1]:null})}let m=e.length>0?Math.max(...e.map(u=>u.endOffset)):0;for(let u of s.sortedInsertOps){if(u.startOffset<m||o.has(u))continue;let p=e[e.length-1];i.push({kind:n?C.INSERTION:C.TEXT,text:u.text,rPrXml:p?.rPrXml||"",startOffset:u.startOffset,endOffset:u.startOffset+u.text.length,author:n?a:void 0})}return i}function Ia(e){let{insertOp:t,splitModel:r,styleLookup:n,patchedModel:a,state:i,options:o,generateRedlines:s,author:l}=e,c=t.text.split(`
12
- `),f=ka(n,t.startOffset,t.text);for(let m=0;m<c.length;m++){let u=Aa(c[m],o.numberingService,i),p=u.lineText;if(m>0){let g=_r(i);u.isListLine&&u.numId&&(g=o.numberingService.buildListPPr(u.numId,u.ilvl)),a.push({kind:C.PARAGRAPH_START,pPrXml:g,startOffset:t.startOffset,endOffset:t.startOffset,text:""}),i.currentParagraphPPrXml=g,i.currentParagraphPPrElement=null,i.lastParagraphStartIndex=a.length-1}else if(u.isListLine&&u.numId&&i.lastParagraphStartIndex>=0){let g=o.numberingService.buildListPPr(u.numId,u.ilvl);a[i.lastParagraphStartIndex].pPrXml=g,a[i.lastParagraphStartIndex].pPrElement=null,i.currentParagraphPPrXml=g,i.currentParagraphPPrElement=null,A(`[Patching] Converted current paragraph to list item: numId=${u.numId}, ilvl=${u.ilvl}`)}(p.length>0||m>0)&&a.push({kind:s?C.INSERTION:C.TEXT,text:p,rPrXml:f?.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 Aa(e,t,r){if(!t)return{lineText:e,isListLine:!1,numId:null,ilvl:0};let n=ue(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),f=_r(r),m=we(e,{allowZeroSpaceAfterMarker:!0}),u=f.match(/w:numId w:val="(\d+)"/),p=f.match(/w:ilvl w:val="(\d+)"/),g=u?u[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 _r(e){return e.currentParagraphPPrXml?e.currentParagraphPPrXml:e.currentParagraphPPrElement?(e.currentParagraphPPrXml=j(e.currentParagraphPPrElement).replace(Sa,""),e.currentParagraphPPrXml):""}function ka(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 Ca(e){let t=e.filter(a=>a.kind===C.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 Oa(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 Ra(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 Ma(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 Xr="http://schemas.openxmlformats.org/wordprocessingml/2006/main",La="http://schemas.openxmlformats.org/officeDocument/2006/relationships",_a="http://schemas.microsoft.com/office/2006/xmlPackage",Br="http://schemas.openxmlformats.org/package/2006/relationships",Ba='<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>',$r='<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/>';var $a=`
13
- <w:numbering xmlns:w="${Xr}">
1
+ var Ga=Object.create;var Kr=Object.defineProperty;var Va=Object.getOwnPropertyDescriptor;var Ka=Object.getOwnPropertyNames;var Za=Object.getPrototypeOf,Ya=Object.prototype.hasOwnProperty;var Ja=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var qa=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Ka(t))!Ya.call(e,a)&&a!==r&&Kr(e,a,{get:()=>t[a],enumerable:!(n=Va(t,a))||n.enumerable});return e};var Qa=(e,t,r)=>(r=e!=null?Ga(Za(e)):{},qa(t||!e||!e.__esModule?Kr(r,"default",{value:e,enumerable:!0}):r,e));var cn=Ja((yl,Ge)=>{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,O=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(O,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(O,s)),l&&c.push(new T.Diff(O,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(O,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(O,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(O,""));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 O: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,P;b==-h||b!=h&&l[x-1]<l[x+1]?P=l[x+1]:P=l[x-1]+1;for(var v=P-b;P<n&&v<a&&e.charAt(P)==t.charAt(v);)P++,v++;if(l[x]=P,P>n)g+=2;else if(v>a)p+=2;else if(f){var E=i+m-b;if(E>=0&&E<s&&c[E]!=-1){var N=n-c[E];if(P>=N)return this.diff_bisectSplit_(e,t,P,v,r)}}}for(var y=-h+d;y<=h-w;y+=2){var E=i+y,N;y==-h||y!=h&&c[E-1]<c[E+1]?N=c[E+1]:N=c[E-1]+1;for(var C=N-y;N<n&&C<a&&e.charAt(n-N-1)==t.charAt(a-C-1);)N++,C++;if(c[E]=N,N>n)w+=2;else if(C>a)d+=2;else if(!f){var x=i+m-y;if(x>=0&&x<s&&l[x]!=-1){var P=l[x],v=i+P-x;if(N=n-N,P>=N)return this.diff_bisectSplit_(e,t,P,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="",P,v,E,N;(b=d.indexOf(h,b+1))!=-1;){var y=a.diff_commonPrefix(g.substring(w),d.substring(b)),C=a.diff_commonSuffix(g.substring(0,w),d.substring(0,b));x.length<C+y&&(x=d.substring(b-C,b)+d.substring(b,b+y),P=g.substring(0,w-C),v=g.substring(w+y),E=d.substring(0,b-C),N=d.substring(b+y))}return x.length*2>=g.length?[P,v,E,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]==O?(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(O,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(O,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_),P=b&&w.match(T.whitespaceRegex_),v=x&&d.match(T.linebreakRegex_),E=P&&w.match(T.linebreakRegex_),N=v&&p.match(T.blanklineEndRegex_),y=E&&g.match(T.blanklineStartRegex_);return N||y?5:v||E?4:h&&!x&&P?3:x||P?2:h||b?1:0}for(var r=1;r<e.length-1;){if(e[r-1][0]==O&&e[r+1][0]==O){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]==O?(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(O,""));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 O: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]==O?e[t-r-n-1][1]+=o.substring(0,i):(e.splice(0,0,new T.Diff(O,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]==O?(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]==O&&e[t+1][0]==O&&(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 O: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 O: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 O: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(O,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(P,v){var E=P/t.length,N=Math.abs(r-v);return a.Match_Distance?E+N/a.Match_Distance:N?1:E}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(O,a));var o=t.substring(e.start2+e.length1,e.start2+e.length1+n);o&&e.diffs.push(new T.Diff(O,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!==O&&(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 O: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]!==O&&(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]!=O)o.unshift(new T.Diff(O,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]!=O)o.push(new T.Diff(O,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(O,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]==O&&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===O?(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]===O?s.diffs[s.diffs.length-1][1]+=m:s.diffs.push(new T.Diff(O,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(O,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 O:n=" ";break}r[a+1]=n+encodeURI(this.diffs[a][1])+`
5
+ `}return r.join("").replace(/%20/g," ")};Ge.exports=T;Ge.exports.diff_match_patch=T;Ge.exports.DIFF_DELETE=D;Ge.exports.DIFF_INSERT=W;Ge.exports.DIFF_EQUAL=O});var at=globalThis.DOMParser,ot=globalThis.XMLSerializer;function eo(e={}){e.DOMParser&&(at=e.DOMParser),e.XMLSerializer&&(ot=e.XMLSerializer)}function B(){if(!at&&globalThis.DOMParser&&(at=globalThis.DOMParser),!at)throw new Error("DOMParser is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new at}function Q(){if(!ot&&globalThis.XMLSerializer&&(ot=globalThis.XMLSerializer),!ot)throw new Error("XMLSerializer is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new ot}function Zr(e,t="text/xml"){return B().parseFromString(e,t)}function K(e){return Q().serializeToString(e)}var yt=console,qt=Object.freeze({silent:0,error:1,warn:2,info:3}),to=typeof process<"u"&&process?.env?.NODE_ENV==="production"?"warn":"info",Qt=to;function ro(e){let t=String(e||"").toLowerCase();return Object.prototype.hasOwnProperty.call(qt,t)?t:Qt}function er(e){return qt[Qt]>=qt[e]}function no(e,t={}){yt=e||console,t.level&&(Qt=ro(t.level))}function I(...e){er("info")&&(yt.log||(()=>{}))(...e)}function Oe(...e){er("warn")&&(yt.warn||(()=>{}))(...e)}function Y(...e){er("error")&&(yt.error||(()=>{}))(...e)}var Yr="Author",Jr="Unknown";function ao(e){Yr=typeof e=="string"&&e.trim()?e.trim():"Author"}function J(){return Yr}function oo(e){Jr=typeof e=="string"&&e.trim()?e.trim():"Unknown"}function tr(){return Jr}var io=[{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 io){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?so(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 rr(...e){let t={};for(let r of e)r&&Object.assign(t,r);return t}function so(e){return e?e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#039;/g,"'"):""}var Pt=String.raw`(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|\d+\.|[ivxlcIVXLC]+\.|[-*\u2022])`,qr=new RegExp(`^(\\s*)((?:${Pt})\\s+)`),Qr=new RegExp(`^(\\s*)((?:${Pt})\\s*)`),lo=new RegExp(`^(\\s*)((?:${Pt})\\s+)`,"m"),co=new RegExp(`^(\\s*)((?:${Pt})\\s*)`,"m");function en(e){return typeof e!="string"?!1:e.includes(`
6
+ `)&&lo.test(e)}function Et(e){return typeof e!="string"?!1:e.includes(`
7
+ `)&&co.test(e.trim())}function be(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?Qr:qr;return e.match(n)}function Pe(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?Qr:qr;return e.replace(n,"")}var S="http://schemas.openxmlformats.org/wordprocessingml/2006/main";var ce=Object.freeze({EQUAL:"equal",DELETE:"delete",INSERT:"insert"}),k=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"}),He=Object.freeze({SDT:"sdt",SMART_TAG:"smartTag",CUSTOM_XML:"customXml",FIELD_COMPLEX:"fldComplex"}),tn=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 St=1e3;function nr(){return St++}function ar(e=new Date){return e.toISOString()}function ee(e){let t=typeof e=="string"&&e.trim()?e.trim():J();return{id:nr(),author:t,date:ar()}}function or(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>=St&&(St=t+1),St}var rn=`
8
+ `,uo=rn.length;function nn(e,t){return e<t-1}function Ue(e,t,r){return nn(t,r)?e+rn:e}function Me(e,t,r){return nn(t,r)?e+uo:e}function Ee(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:Ee(e,n)}function Ct(e,t,r,n=`w:${r}`){let a=H(e,t,r);return a||$(e,n)}function j(e){return $(e,"parsererror")}function ir(e){return Array.from(e?.childNodes||[])}function an(e){return Array.from(e.attributes).map(t=>`${t.name}="${t.value}"`).join(" ")}function sr(e,t,r=""){return!e||e.namespaceURI!==t?!1:r?e.localName===r:!0}var lr=0;function It(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 Y("OOXML parse error:",i.textContent),{runModel:r,acceptedText:n,pPr:null};let s=V(o,S,"p");return s.length===0?(Oe("No paragraphs found in OOXML"),{runModel:r,acceptedText:n,pPr:null}):sn(s,{includeParagraphBoundaries:!0})}catch(o){return Y("Error ingesting OOXML:",o),{runModel:r,acceptedText:n,pPr:null}}}function cr(e){return e?sn([e],{includeParagraphBoundaries:!1}):{runModel:[],acceptedText:"",pPr:null}}function ur(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 sn(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:k.PARAGRAPH_START,pPrElement:c||null,startOffset:o,endOffset:o,text:""});let u=je(l,o,n);a+=u.text,o=a.length,r&&(a=Ue(a,s,e.length),o=Me(o,s,e.length))}return{runModel:n,acceptedText:a,pPr:i}}function je(e,t,r){let n=t,a="",o=fo(r);for(let i of ir(e)){if(sr(i,S,"pPr")||sr(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 fo(e){let t=new Map;t.set("sdt",(r,n)=>{let a=`sdt_${lr++}`,o=H(r,S,"sdtPr"),i=H(r,S,"sdtContent");e.push({kind:k.CONTAINER_START,containerKind:He.SDT,containerId:a,propertiesXml:o?K(o):"",startOffset:n,endOffset:n,text:""});let s=i?je(i,n,e):{offset:n,text:""};return e.push({kind:k.CONTAINER_END,containerKind:He.SDT,containerId:a,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("smartTag",(r,n)=>{let a=`smartTag_${lr++}`;e.push({kind:k.CONTAINER_START,containerKind:He.SMART_TAG,containerId:a,propertiesXml:an(r),startOffset:n,endOffset:n,text:""});let o=je(r,n,e);return e.push({kind:k.CONTAINER_END,containerKind:He.SMART_TAG,containerId:a,startOffset:o.offset,endOffset:o.offset,text:""}),o}),t.set("del",(r,n)=>{let a=on(r,n);return a&&e.push(a),{offset:n,text:""}}),t.set("moveFrom",(r,n)=>{let a=on(r,n);return a&&e.push(a),{offset:n,text:""}}),t.set("moveTo",(r,n)=>je(r,n,e));for(let r of["moveFromRangeStart","moveFromRangeEnd","moveToRangeStart","moveToRangeEnd"])t.set(r,(n,a)=>(e.push({kind:k.BOOKMARK,nodeXml:K(n),startOffset:a,endOffset:a,text:""}),{offset:a,text:""}));return t.set("bookmarkStart",(r,n)=>(e.push({kind:k.BOOKMARK,nodeXml:K(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("bookmarkEnd",(r,n)=>(e.push({kind:k.BOOKMARK,nodeXml:K(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("ins",(r,n)=>je(r,n,e)),t.set("hyperlink",(r,n)=>{let a=`hyperlink_${lr++}`,o=r.getAttribute("r:id")||"",i=r.getAttribute("w:anchor")||"";e.push({kind:k.CONTAINER_START,containerKind:"hyperlink",containerId:a,propertiesXml:JSON.stringify({rId:o,anchor:i}),startOffset:n,endOffset:n,text:""});let s=je(r,n,e);return e.push({kind:k.CONTAINER_END,containerKind:"hyperlink",containerId:a,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("r",(r,n)=>{let a=mo(r,n);return!a||!a.text?{offset:n,text:""}:(e.push(a),{offset:n+a.text.length,text:a.text})}),t}function mo(e,t){let r=Ct(e,S,"rPr"),n=r?K(r):"",a="";for(let o of ir(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:k.TEXT,text:a,rPrXml:n,startOffset:t,endOffset:t+a.length}:null}function on(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:k.DELETION,text:n,rPrXml:"",startOffset:t,endOffset:t,author:r,nodeXml:K(e)}:null}function mr(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,P=x?.getAttribute("w:val"),v=x!==null,E;if(v&&P!=="restart"){let N=c.get(p);N?(N.cell.rowSpan++,E={gridRow:u,gridCol:p,rowSpan:0,colSpan:b,tcNode:d,blocks:[],tcPrXml:fr(w),isMergeOrigin:!1,isMergeContinuation:!0,mergeOrigin:N.cell}):E=po(u,p,b,d,w)}else{let N=ln(d);if(E={gridRow:u,gridCol:p,rowSpan:1,colSpan:b,tcNode:d,blocks:N,tcPrXml:fr(w),isMergeOrigin:v&&P==="restart",isMergeContinuation:!1,getText:()=>N.map(y=>y.acceptedText).join(`
10
+ `)},v&&P==="restart")for(let y=0;y<b;y++)c.set(p+y,{originRow:u,cell:E});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]=E,l.set(`${u},${y}`,E))}p+=b}}return{rowCount:a,colCount:i,grid:s,cellMap:l,tblPrXml:go(e),tblGridXml:ho(e),trPrList:Array.from(n).map(u=>wo(u))}}function po(e,t,r,n,a){let o=ln(n);return{gridRow:e,gridCol:t,rowSpan:1,colSpan:r,tcNode:n,blocks:o,tcPrXml:fr(a),isMergeOrigin:!1,isMergeContinuation:!1,getText:()=>o.map(i=>i.acceptedText).join(`
11
+ `)}}function ln(e){return ue(e,S,"p").map(r=>{let{runModel:n,acceptedText:a,pPr:o}=cr(r);return{runModel:n,acceptedText:a,pPr:o}})}function fr(e){return e?K(e):"<w:tcPr/>"}function go(e){let t=H(e,S,"tblPr");return t?K(t):"<w:tblPr/>"}function ho(e){let t=H(e,S,"tblGrid");return t?K(t):"<w:tblGrid/>"}function wo(e){let t=H(e,S,"trPr");return t?K(t):"<w:trPr/>"}var fn=Qa(cn(),1);var un=new fn.diff_match_patch;function bo(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 xo(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 it(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}=bo(e,t),s=un.diff_main(a,o);return n&&un.diff_cleanupSemantic(s),xo(s,i)}function At(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=it(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 No=/\s+xmlns:[^=]+="[^"]*"/g;function Rt(e,t){let r=So(t),n=[],a=0;for(let o of e){if(o.kind!==k.TEXT&&o.kind!==k.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 kt(e,t,r){let{generateRedlines:n,author:a}=r,o=[],i=new Set,s=Co(t),l=Po(e),c=Eo(s.nonInsertOps),u={containerStack:[],lastParagraphStartIndex:-1,currentParagraphPPrXml:"",currentParagraphPPrElement:null};for(let f of e){if(f.kind===k.CONTAINER_START){u.containerStack.push(f.containerId),o.push({...f});continue}if(f.kind===k.CONTAINER_END){u.containerStack.pop(),o.push({...f});continue}if(f.kind===k.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===k.BOOKMARK||f.kind===k.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),vo({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:k.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?k.INSERTION:k.TEXT,text:f.text,rPrXml:p?.rPrXml||"",startOffset:f.startOffset,endOffset:f.startOffset+f.text.length,author:n?a:void 0})}return o}function vo(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=yo(n,t.startOffset,t.text);for(let m=0;m<c.length;m++){let f=To(c[m],i.numberingService,o),p=f.lineText;if(m>0){let g=mn(o);f.isListLine&&f.numId&&(g=i.numberingService.buildListPPr(f.numId,f.ilvl)),a.push({kind:k.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,I(`[Patching] Converted current paragraph to list item: numId=${f.numId}, ilvl=${f.ilvl}`)}(p.length>0||m>0)&&a.push({kind:s?k.INSERTION:k.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 To(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=mn(r),m=Pe(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 mn(e){return e.currentParagraphPPrXml?e.currentParagraphPPrXml:e.currentParagraphPPrElement?(e.currentParagraphPPrXml=K(e.currentParagraphPPrElement).replace(No,""),e.currentParagraphPPrXml):""}function yo(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 Po(e){let t=e.filter(a=>a.kind===k.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 Eo(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 So(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 Co(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 hn="http://schemas.openxmlformats.org/wordprocessingml/2006/main",Io="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Ao="http://schemas.microsoft.com/office/2006/xmlPackage",pn="http://schemas.openxmlformats.org/package/2006/relationships",Ro='<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>',gn='<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/>';var ko=`
13
+ <w:numbering xmlns:w="${hn}">
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 Jn=Object.create;var wr=Object.defineProperty;var qn=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 Fa(e){return e?e.replace(/<\?xml[^>]*\?>/g,""):""}function Dr(e,t=!0){let r=t?` xmlns:r="${La}"`:"";return`<w:document xmlns:w="${Xr}"${r}><w:body>${e}</w:body></w:document>`}function Fr(e){return`
22
+ </w:numbering>`.trim();function Oo(e){return e?e.replace(/<\?xml[^>]*\?>/g,""):""}function wn(e,t=!0){let r=t?` xmlns:r="${Io}"`:"";return`<w:document xmlns:w="${hn}"${r}><w:body>${e}</w:body></w:document>`}function dn(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
- ${Fa(e)}
25
+ ${Oo(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="${_a}">
27
+ </pkg:part>`}function bn(e,t="",r=""){return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
28
+ <pkg:package xmlns:pkg="${Ao}">
29
29
  <pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml">
30
30
  <pkg:xmlData>
31
- <Relationships xmlns="${Br}">
32
- ${Ba}
31
+ <Relationships xmlns="${pn}">
32
+ ${Ro}
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="${Br}">
38
+ <Relationships xmlns="${pn}">
39
39
  ${t}
40
40
  </Relationships>
41
41
  </pkg:xmlData>
@@ -45,7 +45,7 @@ var Jn=Object.create;var wr=Object.defineProperty;var qn=Object.getOwnPropertyDe
45
45
  ${e}
46
46
  </pkg:xmlData>
47
47
  </pkg:part>
48
- </pkg:package>`}function Wr(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=Dr(i,!0),s="",l="";return n?(s=$r,l+=Fr(n)):r&&(s=$r,l+=Fr($a)),zr(o,s,l)}function Hr(e){let t=Dr(e,!0);return zr(t)}var Xa=/\s+xmlns:[^=]+="[^"]*"/g;function ie(e,t,r=[],n={}){let a=Da(n),{author:i,generateRedlines:o}=a,s=[],l="",c=null,f=[];function m(){if(f.length>0||s.length===0){let u="";l?u=Ae(l):c?(l=Ae(j(c)),u=l):t&&(typeof t=="string"?u=t:u=j(t),u=Ae(u)),s.push(`<w:p>${u}${f.join("")}</w:p>`),f=[]}}for(let u of e)switch(u.kind){case C.PARAGRAPH_START:(f.length>0||s.length>0)&&m(),l=u.pPrXml||"",c=u.pPrElement||null;break;case C.TEXT:f.push(Ur(u,r,a));break;case C.DELETION:o&&f.push(za(u,a));break;case C.INSERTION:o?f.push(Wa(u,r,a)):f.push(Ur(u,r,a));break;case C.BOOKMARK:case C.HYPERLINK:u.nodeXml&&f.push(Ae(u.nodeXml));break;case C.CONTAINER_START:if(u.containerKind==="sdt")f.push(`<w:sdt>${u.propertiesXml}<w:sdtContent>`);else if(u.containerKind==="smartTag")f.push(`<w:smartTag ${u.propertiesXml}>`);else if(u.containerKind==="hyperlink"){let p=JSON.parse(u.propertiesXml),g=p.rId?` r:id="${p.rId}"`:"",d=p.anchor?` w:anchor="${p.anchor}"`:"";f.push(`<w:hyperlink${g}${d}>`)}break;case C.CONTAINER_END:u.containerKind==="sdt"?f.push("</w:sdtContent></w:sdt>"):u.containerKind==="smartTag"?f.push("</w:smartTag>"):u.containerKind==="hyperlink"&&f.push("</w:hyperlink>");break;default:Se("Unknown run kind:",u.kind)}return m(),s.join("")}function Da(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 Ur(e,t,r={}){let n=he(t,e.startOffset,e.endOffset),a=r?.font??null,i=e.rPrXml?Ae(e.rPrXml):"";if(a&&(i=jt(i,a)),n.length===0)return xe(e.text,i);let o=[],s=0,l=e.text,c=e.startOffset;for(let f of n){let m=Math.max(0,f.start-c),u=Math.min(l.length,f.end-c);m>s&&o.push(xe(l.slice(s,m),i));let p=jr(i,f.format);o.push(xe(l.slice(m,u),p)),s=u}return s<l.length&&o.push(xe(l.slice(s),i)),o.join("")}function xe(e,t){return e?`<w:r>${t||""}<w:t xml:space="preserve">${ee(e)}</w:t></w:r>`:""}function za(e,t={}){let r=fe(t.author??G()),n=t.font??null,a=e.rPrXml?Ae(e.rPrXml):"";return n&&(a=jt(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 Wa(e,t,r={}){let n=fe(r.author??G()),a=r.font??null,i=he(t,e.startOffset,e.endOffset),o="",s=e.rPrXml?Ae(e.rPrXml):"";if(a&&(s=jt(s,a)),i.length===0)o=xe(e.text,s);else{let l=0,c=e.text,f=e.startOffset;for(let m of i){let u=Math.max(0,m.start-f),p=Math.min(c.length,m.end-f);u>l&&(o+=xe(c.slice(l,u),s));let g=jr(s,m.format);o+=xe(c.slice(u,p),g),l=p}l<c.length&&(o+=xe(c.slice(l),s))}return`<w:ins w:id="${n.id}" w:author="${ee(n.author)}" w:date="${n.date}">`+o+"</w:ins>"}function jt(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 jr(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 Ne(e,t={}){let r=Ha(t);return Wr(e,r)}function Ha(e){return typeof e=="boolean"?{includeNumbering:e}:!e||typeof e!="object"?{}:{includeNumbering:e.includeNumbering??!1,numberingXml:e.numberingXml??null,appendTrailingParagraph:e.appendTrailingParagraph??!0}}function Ae(e){return e?e.replace(Xa,""):""}var Je=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||_.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===_.OUTLINE)return"3";if(n===_.DECIMAL)return"2";if(n===_.BULLET)return"1";if((r?parseInt(r.ilvl||"0"):0)===0&&n!==_.DECIMAL&&n!==_.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||V.PERIOD}]}),this.contextMap.set(i,o),o}return"2"}detectNumberingFormat(t){let r=(t||"").trim();if(!r)return{format:_.BULLET,suffix:V.NONE,depth:0};if(/^[-*•]$/.test(r))return{format:_.BULLET,suffix:V.NONE,depth:0};let n=r.match(/^(\d+(?:\.\d+)+)\.?$/);if(n){let a=n[1].split(".").length-1;return{format:_.OUTLINE,suffix:V.PERIOD,depth:a}}return/^\([a-z]\)$/.test(r)?{format:_.LOWER_ALPHA,suffix:V.PAREN_BOTH,depth:0}:/^\([ivxlc]+\)$/i.test(r)?{format:r===r.toLowerCase()?_.LOWER_ROMAN:_.UPPER_ROMAN,suffix:V.PAREN_BOTH,depth:0}:/^\(\d+\)$/.test(r)?{format:_.DECIMAL,suffix:V.PAREN_BOTH,depth:0}:/^\d+\.$/.test(r)?{format:_.DECIMAL,suffix:V.PERIOD,depth:0}:/^[a-z]\.$/.test(r)?{format:_.LOWER_ALPHA,suffix:V.PERIOD,depth:0}:/^[A-Z]\.$/.test(r)?{format:_.UPPER_ALPHA,suffix:V.PERIOD,depth:0}:/^[ivxlc]+\.$/i.test(r)?{format:r===r.toLowerCase()?_.LOWER_ROMAN:_.UPPER_ROMAN,suffix:V.PERIOD,depth:0}:/^\d+/.test(r)?{format:_.DECIMAL,suffix:V.PERIOD,depth:0}:{format:_.BULLET,suffix:V.NONE,depth:0}}formatToOoxmlNumFmt(t){return{[_.DECIMAL]:"decimal",[_.LOWER_ALPHA]:"lowerLetter",[_.UPPER_ALPHA]:"upperLetter",[_.LOWER_ROMAN]:"lowerRoman",[_.UPPER_ROMAN]:"upperRoman",[_.BULLET]:"bullet",[_.OUTLINE]:"decimal"}[t]||"decimal"}suffixToOoxmlLevelText(t,r,n=0){if(t===_.BULLET)return"\u2022";let a=`%${n+1}`;if(t===_.OUTLINE)return Array(n+1).fill(0).map((i,o)=>`%${o+1}`).join(".")+".";switch(r){case V.PERIOD:return`${a}.`;case V.PAREN_RIGHT:return`${a})`;case V.PAREN_BOTH:return`(${a})`;default:return a}}buildListPPr(t,r,n={}){return`
48
+ </pkg:package>`}function xn(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=wn(o,!0),s="",l="";return n?(s=gn,l+=dn(n)):r&&(s=gn,l+=dn(ko)),bn(i,s,l)}function Nn(e){let t=wn(e,!0);return bn(t)}var Mo=/\s+xmlns:[^=]+="[^"]*"/g;function fe(e,t,r=[],n={}){let a=Lo(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 k.PARAGRAPH_START:(u.length>0||s.length>0)&&m(),l=f.pPrXml||"",c=f.pPrElement||null;break;case k.TEXT:u.push(vn(f,r,a));break;case k.DELETION:i&&u.push(_o(f,a));break;case k.INSERTION:i?u.push(Bo(f,r,a)):u.push(vn(f,r,a));break;case k.BOOKMARK:case k.HYPERLINK:f.nodeXml&&u.push(Le(f.nodeXml));break;case k.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 k.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:Oe("Unknown run kind:",f.kind)}return m(),s.join("")}function Lo(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 vn(e,t,r={}){let n=we(t,e.startOffset,e.endOffset),a=r?.font??null,o=e.rPrXml?Le(e.rPrXml):"";if(a&&(o=pr(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=Tn(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=pr(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 Bo(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=pr(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=Tn(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 pr(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 Tn(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 Ce(e,t={}){let r=Fo(t);return xn(e,r)}function Fo(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(Mo,""):""}var st=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 Jn=Object.create;var wr=Object.defineProperty;var qn=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,26 +80,26 @@ var Jn=Object.create;var wr=Object.defineProperty;var qn=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 f=10+c;o+=`
84
- <w:abstractNum w:abstractNumId="${f}">
83
+ </w:abstractNum>`,i="",s="";return r.forEach((l,c)=>{let u=10+c;i+=`
84
+ <w:abstractNum w:abstractNumId="${u}">
85
85
  <w:multiLevelType w:val="multilevel"/>
86
- ${l.levels.map((m,u)=>`
87
- <w:lvl w:ilvl="${u}">
86
+ ${l.levels.map((m,f)=>`
87
+ <w:lvl w:ilvl="${f}">
88
88
  <w:start w:val="1"/>
89
89
  <w:numFmt w:val="${this.formatToOoxmlNumFmt(m.format)}"/>
90
- <w:lvlText w:val="${this.suffixToOoxmlLevelText(m.format,m.suffix,u)}"/>
90
+ <w:lvlText w:val="${this.suffixToOoxmlLevelText(m.format,m.suffix,f)}"/>
91
91
  <w:lvlJc w:val="left"/>
92
- <w:pPr><w:ind w:left="${720*(u+1)}" w:hanging="360"/></w:pPr>
92
+ <w:pPr><w:ind w:left="${720*(f+1)}" w:hanging="360"/></w:pPr>
93
93
  </w:lvl>`).join("")}
94
94
  </w:abstractNum>`,s+=`
95
95
  <w:num w:numId="${l.numId}">
96
- <w:abstractNumId w:val="${f}"/>
96
+ <w:abstractNumId w:val="${u}"/>
97
97
  </w:num>`}),`
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 Jn=Object.create;var wr=Object.defineProperty;var qn=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=ae(),i=r?be():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,73 +123,77 @@ var Jn=Object.create;var wr=Object.defineProperty;var qn=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>`,f=e.hasHeader?[e.headers,...e.rows]:e.rows,m="";for(let p=0;p<f.length;p++){let g=e.hasHeader&&p===0,d=f[p]||[],w="";for(let x=0;x<o;x++){let v=d[x]||"",{cleanText:T,formatHints:N}=q(v),E=[{kind:r?C.INSERTION:C.TEXT,text:T,rPrXml:g?"<w:rPr><w:b/></w:rPr>":"",author:n,startOffset:0,endOffset:T.length}],b=ie(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 u=`<w:tbl>${s}${c}${m}</w:tbl>`;return r&&i&&(u=`<w:ins w:id="${i}" w:author="${ee(n)}" w:date="${a}">${u}</w:ins>`),u}function Gr(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 f=0;f<e.colCount;f++){let m=e.grid[l]?.[f],u=c?.[f];m&&(m.isMergeContinuation||f>m.gridCol||u!==void 0&&m.getText()!==u&&r.push({type:"cell_modify",gridRow:l,gridCol:f,originalCell:m,newText:u}))}}return r}function Kr(e,t,r){let{generateRedlines:n,author:a}=r,i=Ua(t),o="";for(let l=0;l<e.rowCount;l++){let c=i.rowDeleteByRow.get(l)||null;if(c&&!n)continue;let f="",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=ja(p,g.newText,r):d=Ga(p.blocks),f+=Ka(p,d,r),m+=p.colSpan}let u=e.trPrList[l]||"<w:trPr/>";if(c&&n){let p=fe(a),g=`<w:del w:id="${p.id}" w:author="${ee(p.author)}" w:date="${p.date}"/>`;u.includes("</w:trPr>")?u=u.replace("</w:trPr>",`${g}</w:trPr>`):u=`<w:trPr>${g}</w:trPr>`}o+=`<w:tr>${u}${f}</w:tr>`}let s=i.rowInsertOperations;for(let l of s){let c="",f=n?fe(a):null;for(let u of l.cells){let{cleanText:p,formatHints:g}=q(u),d=[{kind:n?C.INSERTION:C.TEXT,text:p,rPrXml:"",author:a,startOffset:0,endOffset:p.length}],w=ie(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="${f.id}" w:author="${ee(f.author)}" w:date="${f.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:P}=ne(b),v=[{kind:r?k.INSERTION:k.TEXT,text:x,rPrXml:p?"<w:rPr><w:b/></w:rPr>":"",author:n,startOffset:0,endOffset:x.length}],E=fe(v,null,P,{author:n,generateRedlines:r});d+=`<w:tc><w:tcPr><w:tcW w:w="0" w:type="auto"/></w:tcPr>${E}</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 yn(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 Pn(e,t,r){let{generateRedlines:n,author:a}=r,o=$o(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=Xo(p,g.newText,r):d=Do(p.blocks),u+=zo(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?k.INSERTION:k.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 Ua(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 ja(e,t,r){let{generateRedlines:n,author:a}=r,{cleanText:i,formatHints:o}=q(t),s=e.getText(),l=dt(s,i),c=e.blocks[0]||{runModel:[],pPr:null},f=ht(c.runModel,l),m=wt(f,l,{generateRedlines:n,author:a,formatHints:o});return ie(m,c.pPr,o,{author:a,generateRedlines:n})}function Ga(e){return e.map(t=>ie(t.runModel,t.pPr,[],{})).join("")}function Ka(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 oe(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 Vr(e){let{cleanText:t,numberingContext:r,originalRunModel:n=[],originalText:a="",generateRedlines:i=!0,author:o="AI",font:s=null,numberingService:l}=e,c=Za(t),f=Va(c),m=f.map(N=>N.raw),u=[],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=Gt(m);A(`[ListGen] Detected indentation step: ${g} spaces/chars`);let d=f.find(N=>N.marker)?.marker||"",{format:w}=l.detectNumberingFormat(d);A(`[ListGen] Detected primary marker: "${d}", format: ${w}`);for(let N=0;N<f.length;N++){let E=Ya(f,N);if(E){let P=oe(E.tableText);if(P.headers.length>0||P.rows.length>0){i&&u.length===0&&p.length>0&&u.push(ie(p,null,[],{author:o,generateRedlines:i,font:s})),u.push(ke(P,{generateRedlines:i,author:o})),N=E.endIndex;continue}}let b=f[N],S=Ja(b,N,g,r,l,i,o,s,p);u.push(S.ooxml)}let h=l.generateNumberingXml(),T=u.join("")+"<w:p><w:pPr></w:pPr></w:p>";return A(`[ListGen] \u2705 Generated OOXML for ${u.length} list items, total length: ${T.length}`),A(`[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 Gt(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 Va(e){return e.split(`
134
- `).filter(t=>t.trim().length>0).map(t=>{let r=ue(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 Za(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=ue(o);if(!l)return e;let c=we(o),f=ue(c);if(!f)return e;let m=(l[2]||"").trim(),u=(f[2]||"").trim();if(!m||!u||m===u)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 A(`[ListGen] Normalized ${a} composite list markers (e.g., "- A." -> "A.").`),i.join(`
136
- `)}function Ya(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 Ja(e,t,r,n,a,i,o,s,l){let c="",f="";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];f=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);f=we(e.raw);let x=a.getOrCreateNumId({type:g.format},n);c=a.buildListPPr(x,h)}else f=e.raw;let{cleanText:m,formatHints:u}=q(f),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:ie(p,c,u,{author:o,generateRedlines:i,font:s})}}var qa=new Set(["officeonline","officeweb","web"]);function Qa(e){return e?qa.has(String(e).toLowerCase()):!1}function ei(){return typeof process<"u"&&process?.env?.NODE_ENV==="production"}function ti(){return new Promise(e=>setTimeout(e,0))}var Ce=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 Je,this.font=t.font||null,this.platform=t.platform??Bt(),this.isWebPlatform=t.isWebPlatform??Qa(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||B().parseFromString(t,"application/xml"),o=D(i,"*","p"),{runModel:s,acceptedText:l,pPr:c}=gt(t,{xmlDoc:i}),f=o?Wt(o):null;A(`[Reconcile] Ingested ${s.length} runs, ${l.length} chars, numbering:`,f),await this.maybeYield(s.length,Math.max(l.length,r?.length||0));let{cleanText:m,formatHints:u}=q(r);A(`[Reconcile] Preprocessed: ${u.length} format hints`),await this.maybeYield(s.length,Math.max(l.length,m.length));let p=yr(m),g=pt(m),d=p||g;if(!p&&g&&A("[Reconcile] List-target detected via loose marker parsing; bypassing no-op short-circuit for structural conversion."),l===m&&u.length===0&&!d)return A("[Reconcile] No changes detected"),{ooxml:t,isValid:!0,warnings:["No changes detected"]};let w=Math.max(l.length,m.length)<this.disableSemanticCleanupOverChars,h=dt(l,m,{cleanupSemantic:w});w||A("[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===C.PARAGRAPH_START).length;if(A(`[Reconcile] isTargetList: ${d}, paragraphCount: ${x}`),d)return A("[Reconcile] \u{1F3AF} ENTERING LIST GENERATION PATH"),A(`[Reconcile] cleanText preview: ${m.substring(0,100)}...`),A(`[Reconcile] acceptedText preview: ${l.substring(0,100)}...`),this.executeListGeneration(m,f,s);A(`[Reconcile] Computed ${h.length} diff operations`);let v=ht(s,h);A(`[Reconcile] Split into ${v.length} runs`);let T=wt(v,h,{generateRedlines:this.generateRedlines,author:this.author,formatHints:u,numberingService:this.numberingService});A(`[Reconcile] Patched model has ${T.length} runs`),await this.maybeYield(T.length,Math.max(l.length,m.length));let N=ie(T,c,u,{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 K("[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=B().parseFromString(n,"application/xml"),o=U(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&&ei()):!1}async maybeYield(t,r){this.enableEventLoopYielding&&(t<=this.yieldRunThreshold&&r<=this.yieldCharThreshold||await ti())}wrapForInsertion(t,r={}){return Ne(t,r)}async executeListGeneration(t,r,n,a=""){return Vr({cleanText:t,numberingContext:r,originalRunModel:n,originalText:a,generateRedlines:this.generateRedlines,author:this.author,font:this.font,numberingService:this.numberingService})}detectIndentationStep(t){return Gt(t)}executeTableGeneration(t){let r=oe(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 qe=["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 $e(e,t){let r=qe.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=qe.indexOf(i.nodeName);if((o===-1?999:o)>n){e.insertBefore(t,i),a=!0;break}}a||e.appendChild(t)}function ri(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 f of Array.from(t.childNodes))l.has(f.nodeName)&&c.push(f);for(let f of c)t.removeChild(f)}if(a){let c=e.createElement("w:b");c.setAttribute("w:val",n==="add"?"1":"0"),$e(t,c);let f=e.createElement("w:bCs");f.setAttribute("w:val",n==="add"?"1":"0"),$e(t,f)}if(i){let c=e.createElement("w:i");c.setAttribute("w:val",n==="add"?"1":"0"),$e(t,c);let f=e.createElement("w:iCs");f.setAttribute("w:val",n==="add"?"1":"0"),$e(t,f)}if(o){let c=e.createElement("w:u");c.setAttribute("w:val",n==="add"?"single":"none"),$e(t,c)}if(s){let c=e.createElement("w:strike");c.setAttribute("w:val",n==="add"?"1":"0"),$e(t,c)}}function Zr(e,t,r){ri(e,t,r,"remove")}function Qe(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=bt(r,!1)),r.nodeName==="w:i"&&(t.italic=bt(r,!1)),r.nodeName==="w:u"&&(t.underline=bt(r,!0)),r.nodeName==="w:strike"&&(t.strikethrough=bt(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 bt(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 Yr="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function ce(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===Yr&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function ni(e){return!e||e.nodeType!==1||e.namespaceURI!==Yr?!1:e.localName==="del"||e.localName==="moveFrom"}function Jr(e){let t=[],r=Array.from(e?.childNodes||[]).reverse();for(;r.length>0;){let n=r.pop();if(!n||n.nodeType!==1||ni(n))continue;if(ce(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 me(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 qr(e){let t=[],r=0;for(let n=0;n<e.length;n++){let a=e[n],i=Jr(a);for(let o of i){let s=M(o,"w:rPr");Array.from(o.childNodes||[]).forEach(l=>{if(ce(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(ce(l,"br")||ce(l,"cr")||ce(l,"tab")||ce(l,"noBreakHyphen"))&&(t.push({charStart:r,charEnd:r+1,textElement:l,runElement:o,paragraph:a,container:o.parentNode,rPr:s}),r+=1)})}r=Ie(r,n,e.length)}return{textSpans:t,charOffset:r}}function ai(e,t,r,n,a,i=null){let o=null;for(let c of Array.from(e.childNodes))if(ce(c,"rPr")){o=c;break}let s=Qe(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(ce(c,"t")){let f=c.textContent||"";if(f.length>0){let m=l,u=l+f.length;n.push({charStart:m,charEnd:u,textElement:c,runElement:e,paragraph:t,rPr:o,format:{...s}}),s.hasFormatting&&a.push({start:m,end:u,format:{...s},run:e,rPr:o}),l=u}}return l}function Qr(e){let t=[],r=[],n=0,a=me(e);for(let i=0;i<a.length;i++){let o=a[i],s=null;for(let f of Array.from(o.childNodes))if(ce(f,"pPr")){for(let m of Array.from(f.childNodes))if(ce(m,"rPr")){s=m;break}break}let l=Qe(s);l.hasFormatting&&A(`[OxmlEngine] Found paragraph-level formatting: ${JSON.stringify(l)}`);let c=Jr(o);for(let f of c)n=ai(f,o,n,r,t,l);n=Ie(n,i,a.length)}return A(`[OxmlEngine] Extracted ${r.length} text spans, ${t.length} format hints`),{existingFormatHints:t,textSpans:r,paragraphs:a}}function ve(e,t,r,n){let a=e.createElement(t==="ins"?"w:ins":"w:del"),i=fe(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 se(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 xt(e,t,r,n,a,i,o){if(!t)return[];let s=new Set([0,t.length]);for(let f of n){let m=Math.max(0,f.start-a),u=Math.min(t.length,f.end-a);m>=0&&m<t.length&&s.add(m),u>0&&u<=t.length&&s.add(u)}let l=Array.from(s).sort((f,m)=>f-m),c=[];for(let f=0;f<l.length-1;f++){let m=l[f],u=l[f+1],p=t.slice(m,u);if(!p)continue;let g=a+m,d=a+u,w=n.filter(v=>v.start<=g&&v.end>=d),h={};w.forEach(v=>{v.format&&Object.assign(h,v.format)});let x=Fe(e,r,h,i,o);c.push(Kt(e,p,x,!1))}return c}function Kt(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 Fe(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&&ii(e,i,n,t);let s=(l,c,f=null,m="0")=>{let u=e.createElement(l);c?f&&u.setAttribute("w:val",f):m&&u.setAttribute("w:val",m);let p=qe.indexOf(l),g=p===-1?999:p,d=!1;for(let w of Array.from(i.childNodes)){if(w.nodeType!==1)continue;let h=qe.indexOf(w.nodeName);if((h===-1?999:h)>g){i.insertBefore(u,w),d=!0;break}}d||i.appendChild(u)};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 Vt(e,t,r,n,a){let i=e.createElement("w:rPrChange");i.setAttribute("w:id",String(fe(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 ii(e,t,r,n){Vt(e,t,r,ae(),n||t)}var oi="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function Xe(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===oi&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function Nt(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((u,p)=>u.charStart-p.charStart),c=si(l),f=Zt(c),m=f.trim();a.push({paragraph:o,spans:l,text:c,normalizedText:f,normalizedTrim:m,startOffset:i}),i+=f.length,i=Ie(i,s,t.length)}),a}function en(e,t){if(!t)return null;let r=Zt(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 tn(e,t){let r=Zt(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,f=l.normalizedText.length;if(s>=c&&s<=c+f){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 rn(e){let t=e;for(;t;){if(Xe(t,"p"))return t;t=t.parentNode}return null}function si(e){if(!e||e.length===0)return"";let t="";for(let r of e){if(!r||!r.textElement)continue;let n=r.textElement;Xe(n,"t")?t+=r.textElement.textContent||"":Xe(n,"tab")?t+=" ":Xe(n,"br")||Xe(n,"cr")?t+=`
139
- `:Xe(n,"noBreakHyphen")&&(t+="\u2011")}return t}function Zt(e){return e?e.replace(/\r/g,`
140
- `).replace(/\u00a0/g," "):""}function nn(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],f=li(e,l,c);if(!f){o++;continue}i.push(f[0]),l=f[1],o++}i.push(l)}return i}function li(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=se(e,s,t.rPr,!1),f=se(e,l,t.rPr,!1);a.insertBefore(c,n),a.insertBefore(f,n),a.removeChild(n);let m=c.getElementsByTagName("w:t")[0],u=f.getElementsByTagName("w:t")[0];return[{...t,charEnd:r,textElement:m,runElement:c},{...t,charStart:r,textElement:u,runElement:f}]}var ci="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function ui(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===ci&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function fi(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 an(e,t,r,n,a,i=!0){let o=!1,s=new Set,l=ae();A(`[OxmlEngine] Surgical format removal: ${r.length} hints to process (using w:rPrChange)`);for(let c of r){let f=c.run;if(s.has(f)||(s.add(f),!f.parentNode))continue;A("[OxmlEngine] Processing run for surgical format removal, format:",c.format);let m=M(f,"w:rPr");m||(m=e.createElement("w:rPr"),f.insertBefore(m,f.firstChild)),i&&Vt(e,m,a||G(),l),Zr(e,m,c.format),o=!0}return o?(A("[OxmlEngine] Surgical format removal completed successfully (Pure Format Mode)"),{oxml:n.serializeToString(e),hasChanges:!0}):(A("[OxmlEngine] No format changes were applied"),{oxml:n.serializeToString(e),hasChanges:!1})}function mi(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 u of r)l.push(u.start,u.end);let f=nn(e,t,l).slice().sort((u,p)=>u.charStart-p.charStart||u.charEnd-p.charEnd),m=pi(r);for(let u of f){if(!u||!u.textElement||!ui(u.textElement,"t"))continue;let p=m(u.charStart,u.charEnd);if(p.length===0)continue;let g=$t(...p.map(k=>k.format)),d={bold:!!g.bold,italic:!!g.italic,underline:!!g.underline,strikethrough:!!g.strikethrough},w=u.format||Qe(u.rPr),h={bold:!!w.bold,italic:!!w.italic,underline:!!w.underline,strikethrough:!!w.strikethrough};if(!["bold","italic","underline","strikethrough"].some(k=>d[k]!==h[k])||s.has(u.runElement)||(s.add(u.runElement),!(u.textElement.textContent||""))||!u.runElement.parentNode)continue;let E=u.runElement,b=M(E,"w:rPr"),S=Fe(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(k=>P.appendChild(k))}o=!0}return{oxml:n.serializeToString(e),hasChanges:o}}function on(e,t,r,n,a,i=!0,o=null){let s=fi(o),l=s.paragraphs||me(e),c=s.textSpans||[];if(s.textSpans||({textSpans:c}=qr(l)),!c||c.length===0)return Se("[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 f=s.paragraphInfos||Nt(e,l,c),{targetInfo:m,matchOffset:u}=tn(f,t);if(!m||!m.spans||m.spans.length===0)return Se("[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+u,end:w.end+u}));return mi(e,g,d,n,a,i)}function pi(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 gi="http://schemas.microsoft.com/office/word/2010/wordml";function sn(e,t,r={}){let{targetParagraphId:n=null}=r,a=Y(e,"w:tbl");if(a.length===0)return{hasTableWrapper:!1,isTableCellParagraph:!1,paragraphs:[],paragraph:null,tableElement:null};let o=me(e).filter(l=>{let c=l.parentNode;for(;c;){if(c.nodeName==="w:tc")return!0;c=c.parentNode}return!1});A(`[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 f=hi(c);return f&&f.toUpperCase()===l})||null,s?A(`[OxmlEngine] Found target paragraph by paraId: "${n}"`):A(`[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 f=Y(c,"w:t"),m="";for(let u of f)m+=u.textContent||"";if(m.trim()===l){s=c,A(`[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 et(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 A(`[OxmlEngine] Stripping table wrapper, serializing ${n.length} paragraphs`),A(`[OxmlEngine] Paragraph XML preview: ${a.substring(0,200)}...`),di(a)}function di(e){return Hr(e)}function hi(e){if(!e)return null;let t=typeof e.getAttributeNS=="function"?e.getAttributeNS(gi,"paraId"):null;return t||e.getAttribute("w14:paraId")||e.getAttribute("w:paraId")||e.getAttribute("paraId")||null}function cn(e,t,r,n,a,i,o=!0,s=null){let l="",c=[],f=s?[s]:me(e);f.forEach((w,h)=>{let x=w.parentNode;for(let v=w.firstChild;v;v=v.nextSibling)if(v.nodeName==="w:r"){let T=ln(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=ln(T,w,x,l.length,c);l+=N.text}}l=_e(l,h,f.length)});let m=Ye(l,r),u=Ni(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;un(u,v,T,N=>{let E=Math.max(N.charStart,v),b=Math.min(N.charEnd,T),S=b-E,P=E-v,k=g+P,R=k+S,ne=he(i,k,R);wi(e,N,E,b,ne,a,o)}),p+=x,g+=x}else if(w===-1)bi(e,u,p,p+h.length,d,a,o),p+=h.length;else if(w===1){let x=h.replace(/\n/g," ");x.trim().length>0&&xi(e,u,p,x,d,a,i,g,o),g+=h.length}return{oxml:n.serializeToString(e),hasChanges:!0}}function wi(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},f={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]!==f[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=se(e,x,l,!1);p.insertBefore(b,t.runElement)}let N=Fe(e,l,s,i,o),E=Kt(e,v,N,!1);if(p.insertBefore(E,t.runElement),T.length>0){let b=se(e,T,l,!1);p.insertBefore(b,t.runElement)}p.removeChild(t.runElement)}function ln(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 bi(e,t,r,n,a,i,o){un(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),f=s.textElement.textContent||"",m=f.substring(0,l),u=f.substring(l,c),p=f.substring(c);if(u.length===0)return;let g=s.runElement.parentNode;if(g){if(m.length===0&&p.length===0){let d=se(e,u,s.rPr,!0);if(o){let w=ve(e,"del",d,i);g.insertBefore(w,s.runElement)}g.removeChild(s.runElement)}else{let d=s.runElement;if(m.length>0){let h=se(e,m,s.rPr,!1);g.insertBefore(h,d)}let w=se(e,u,s.rPr,!0);if(o){let h=ve(e,"del",w,i);g.insertBefore(h,d)}if(p.length>0){let h=se(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 xi(e,t,r,n,a,i,o=[],s=0,l=!0){let c=Ti(t,r);if(!c&&r>0&&(c=yi(t,r)),!c&&r>0&&(c=Ei(t,r)),!c&&t.spans.length>0&&(c=t.spans[t.spans.length-1]),c){let f=he(o,s,s+n.length),m=c.rPr,u=c.runElement.parentNode;if(u){let p=r===c.charStart?c.runElement:c.runElement.nextSibling;if(f.length===0){let g=se(e,n,m,!1);if(l){let d=ve(e,"ins",g,i);u.insertBefore(d,p)}else u.insertBefore(g,p)}else{let g=xt(e,n,m,f,s,i,l);if(l){let d=ve(e,"ins",null,i);g.forEach(w=>d.appendChild(w)),u.insertBefore(d,p)}else g.forEach(d=>u.insertBefore(d,p))}}}}function Ni(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 Yt(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 vi(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 un(e,t,r,n){if(r<=t||e.spans.length===0)return;let a=Yt(e.ends,t);for(;a<e.spans.length;){let i=e.spans[a];if(i.charStart>=r)break;n(i),a++}}function Ti(e,t){if(e.spans.length===0)return null;let r=Yt(e.starts,t)-1;if(r<0)return null;let n=e.spans[r];return t>=n.charStart&&t<n.charEnd?n:null}function yi(e,t){let r=vi(e.ends,t);return r<e.spans.length&&e.ends[r]===t?e.spans[r]:null}function Ei(e,t){let r=Yt(e.ends,t)-1;return r>=0?e.spans[r]:null}function fn(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 Pi(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 mn(e,t){let r=e.documentElement,n=r.nodeName==="w:body"||r.nodeName.endsWith(":package"),a=me(e),i=M(e,"w:body");!i&&n&&(i=r);let o="",s=[],l=[],c=[],f=new Map,m=new Map,u=57344,p=new Set;a.forEach((S,P)=>{let k=o.length;Array.from(S.childNodes).forEach(H=>{o=Si(H,o,s,c,f,m,u),f.size>m.size&&u++}),o=_e(o,P,a.length);let R=o.length,ne=M(S,"w:pPr"),Z=S.parentNode;Z&&p.add(Z),l.push({start:k,end:R,pPr:ne,container:Z||i})});let g=t;m.forEach((S,P)=>{let k=P.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");g=g.replace(new RegExp(k,"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=fn(l),v=fn(s),T=Pi(c);return{paragraphs:a,body:i||e,paragraphMap:l,paragraphStarts:h,propertyMap:s,sentinelMap:c,sentinelMapByStart:T,referenceMap:f,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 k=v.at(S);return k?Math.min(k.end-S,P):1},isParagraphStart:S=>h.has(S)}}function Si(e,t,r,n,a,i,o){return e.nodeName==="w:r"?Ii(e,t,r,n,a,i,o):e.nodeName==="w:hyperlink"?Ai(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 Ii(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 f=c.textContent||"";f.length>0&&(r.push({start:s.length,end:s.length+f.length,rPr:l}),s+=f)}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 f=M(c,"w:txbxContent"),m=c.nodeName==="w:pict"&&!!f;n.push({start:s.length,node:c,isTextBox:m,originalContainer:m?f: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 f=c.getAttribute("w:id");if(f){let u=`{{__${c.nodeName==="w:footnoteReference"?"FN":"EN"}_${f}__}}`,p=String.fromCharCode(o);a.set(p,c),i.set(u,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 Ai(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");Y(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 gn(e,t,r,n,a,i,o=!0){let{paragraphs:s,paragraphMap:l,containerFragments:c,sentinelMapByStart:f,referenceMap:m,replacementContainers:u,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",k=0;for(;k<S.length;){let R=N+k,ne=g(R),Z=d(R,S.length-k),H=S.substring(k,k+Z);pn(e,H,P,ne.rPr,ne.wrapper,R,v,c,f,m,u,p,h,a,i,E,o),b===0&&(E+=Z),k+=Z}N+=S.length;continue}if(b===1){let P=N>0&&!w(N)?g(N-1):g(N);pn(e,S,"insert",P.rPr,P.wrapper,N,v,c,f,m,u,p,h,a,i,E,o),E+=S.length}}return s.forEach(b=>{b.parentNode&&b.parentNode.removeChild(b)}),c.forEach((b,S)=>{let k=u.get(S)||S;if(k.nodeType===9){let R=b.firstChild;if(R)for(k.appendChild(R);b.firstChild;)k.documentElement.appendChild(b.firstChild);return}k.appendChild(b)}),{oxml:n.serializeToString(e),hasChanges:!0}}function pn(e,t,r,n,a,i,o,s,l,c,f,m,u,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 k=e.createElement("w:r");k.appendChild(P.node.cloneNode(!0)),v.appendChild(k)}else v.appendChild(P.node.cloneNode(!0))}),N===`
143
- `){if(r!=="delete"){let P=m(h),k=u(P.pPr),R=s.get(P.container);R&&(R.appendChild(k),v=k)}h++,r!=="delete"&&x++;return}if(N==="\uFFFC"){let P=E.find(k=>!k.isCommentMarker)||E[0];if(P){let k=P.node.cloneNode(!0);if(P.isTextBox&&P.originalContainer){let R=M(k,"w:txbxContent");if(R){for(;R.firstChild;)R.removeChild(R.firstChild);f.set(P.originalContainer,R)}}v.appendChild(k)}h++,r!=="delete"&&x++;return}if(c.has(N)){if(r!=="delete"){let P=c.get(N);if(P){let k=P.cloneNode(!0),R=e.createElement("w:r");n&&R.appendChild(n.cloneNode(!0)),R.appendChild(k),v.appendChild(R)}}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 k=e.createElement("w:delText");if(k.setAttribute("xml:space","preserve"),k.textContent=N,P.appendChild(k),w){let R=ve(e,"del",P,p);S.appendChild(R)}}else{let P=he(g,x,x+N.length),k=xt(e,N,n,P,x,p,w);if(r==="insert"&&w){let R=ve(e,"ins",null,p);k.forEach(ne=>R.appendChild(ne)),S.appendChild(R)}else k.forEach(R=>S.appendChild(R))}r!=="delete"&&(x+=N.length),h+=N.length})}function Jt(e,t,r,n,a,i,o=!0){let s=mn(e,r);if(s.paragraphs.length===0)return{oxml:n.serializeToString(e),hasChanges:!1};let l=Ye(s.originalFullText,s.processedModifiedText);return gn(e,l,s,n,a,i,o)}function Te(e,t){return{oxml:e.serializeToString(t),hasChanges:!1}}function dn(e,t,r,n,a,i=!0){let o=Y(e,"w:tbl"),s=oe(t),l=s.rows.length>0||s.headers.length>0;if(o.length===0||!l)return Te(r,e);let c=o[0],f=Ut(c),m=Gr(f,s);if(m.length===0)return Te(r,e);let p=Kr(f,m,{generateRedlines:i,author:a}),g=`<root xmlns:w="${I}">${p}</root>`,w=(n||B()).parseFromString(g,"application/xml"),h=U(w);if(h)return K("[OxmlEngine] Failed to parse reconciled table OOXML:",h.textContent),Te(r,e);let x=M(w,"w:tbl");if(!x)return K("[OxmlEngine] No table found in reconciled OOXML"),Te(r,e);let v=e.importNode(x,!0);return c.parentNode.replaceChild(v,c),{oxml:r.serializeToString(e),hasChanges:!0}}function hn(e,t,r,n,a,i){let o=oe(t);if(!o||o.rows.length===0&&o.headers.length===0)return A("[OxmlEngine] Failed to parse table data from Markdown"),Te(r,e);let s=ke(o,{generateRedlines:i,author:a}),l=n||B(),c=l.parseFromString(`<root xmlns:w="${I}">${s}</root>`,"application/xml"),f=U(c);if(f)return K("[OxmlEngine] Failed to parse generated table OOXML:",f.textContent),Te(r,e);let m=D(c,I,"tbl");if(m||(m=D(c,I,"ins")),!m)return K("[OxmlEngine] No table element found in generated OOXML"),Te(r,e);let u=e,p=z(u,I,"p");if(p.length===0)return A("[OxmlEngine] No paragraphs found to replace"),Te(r,u);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))),u=h,p=z(u,I,"p"),g=p[0],d=g.parentNode}let w=u.importNode(m,!0);if(i){let h=ae();p.forEach(x=>{z(x,I,"r").forEach(T=>{z(T,I,"t").forEach(b=>{let S=b.textContent||"";if(S.trim()){let P=u.createElementNS(I,"w:delText");P.textContent=S,b.parentNode.replaceChild(P,b)}});let E=u.createElementNS(I,"w:del");E.setAttribute("w:id",String(be())),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),A("[OxmlEngine] Text-to-table transformation complete"),{oxml:r.serializeToString(u),hasChanges:!0}}async function qt(e,t,r,n={}){let a=n.generateRedlines??!0,i=n.author||G(),o=B(),s=J(),l=()=>({oxml:e,hasChanges:!1}),c;try{c=o.parseFromString(e,"text/xml")}catch(H){return K("[OxmlEngine] Failed to parse OXML:",H),l()}let f=U(c);if(f)return K("[OxmlEngine] XML parse error:",f.textContent),l();let m=sn(c,t,n);if(m.hasTableWrapper&&m.targetParagraph&&!n._isolatedTableCell){A("[OxmlEngine] Isolating table-cell paragraph before diff");let H=et(c,m.targetParagraph,s);return qt(H,t,r,{...n,_isolatedTableCell:!0})}let u=wn(r),{cleanText:p,formatHints:g}=q(u),d=p.trim()!==t.trim(),w=g.length>0,{existingFormatHints:h,textSpans:x,paragraphs:v}=Qr(c),T=h.length>0,N=null,E=()=>(N||(N=Nt(c,v,x)),N),b=(H=null)=>{let X=on(c,t,g,s,i,a,H);return X.useNativeApi?(A("[OxmlEngine] Format-only surgical fallback signal encountered; retrying with OOXML reconstruction fallback"),Jt(c,t,p,s,i,g,a)):X};A(`[OxmlEngine] Text changes: ${d}, New format hints: ${g.length}, Existing format hints: ${h.length}`);let S=!d&&!w&&T;if(!d&&!w&&!T)return A("[OxmlEngine] No text changes, no format hints, and no existing formatting detected"),l();if(S){A("[OxmlEngine] Format REMOVAL detected: applying surgical replacement in OOXML");let H=m,X=H.targetParagraph||null;if(!X){let ut=en(E(),t);ut&&(X=ut.paragraph)}let Pe=h;X&&(Pe=h.filter(ut=>rn(ut.run)===X));let hr=an(c,x,Pe,s,i,a);return H.hasTableWrapper&&X?{oxml:et(c,X,s),hasChanges:hr.hasChanges}:hr}if(!d&&w){A(`[OxmlEngine] Format-only change detected: ${g.length} format hints`);let H=m,X={textSpans:x,paragraphs:v,paragraphInfos:E()};if(H.hasTableWrapper&&H.targetParagraph){A("[OxmlEngine] Table cell context: applying formatting to target paragraph only");let Pe=b(X);return A("[OxmlEngine] Stripping table wrapper for table cell paragraph (format-only)"),{oxml:et(c,H.targetParagraph,s),hasChanges:Pe.hasChanges}}return b(X)}let k=Y(c,"w:tbl").length>0,R=/^\|.+\|/.test(p.trim())&&p.includes(`
144
- `),ne=pt(p),Z=m;if(A(`[OxmlEngine] Mode: ${k?"SURGICAL":"RECONSTRUCTION"}, formatHints: ${g.length}, isMarkdownTable: ${R}, isTargetList: ${ne}, isTableCellParagraph: ${Z.isTableCellParagraph}`),R&&!k)return A("[OxmlEngine] Text-to-table transformation: generating new table from Markdown"),hn(c,p,s,o,i,a);if(k&&R)return dn(c,p,s,o,i,a);if(k){let H=Z.hasTableWrapper&&Z.targetParagraph?Z.targetParagraph:null;H&&A("[OxmlEngine] Table cell edit: scoping surgical mode to target paragraph");let X=cn(c,t,p,s,i,g,a,H);return Z.hasTableWrapper&&X.hasChanges&&Z.targetParagraph?(A("[OxmlEngine] Stripping table wrapper for table cell paragraph (surgical mode)"),{oxml:et(c,Z.targetParagraph,s),hasChanges:!0}):X}if(ne){A("[OxmlEngine] \u{1F3AF} Using reconciliation pipeline for list generation");let X=await new Ce({author:i,generateRedlines:a}).execute(e,r,{xmlDoc:c});if(X.isValid&&X.ooxml&&X.ooxml!==e){A(`[OxmlEngine] Wrapping list OOXML with numbering definitions, includeNumbering=${X.includeNumbering}`);let Pe=Ne(X.ooxml,{includeNumbering:X.includeNumbering??!0,numberingXml:X.numberingXml});return A(`[OxmlEngine] \u2705 Wrapped OOXML length: ${Pe.length}`),{oxml:Pe,hasChanges:!0}}return l()}return Jt(c,t,p,s,i,g,a)}function wn(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 $o(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 Xo(e,t,r){let{generateRedlines:n,author:a}=r,{cleanText:o,formatHints:i}=ne(t),s=e.getText(),l=At(s,o),c=e.blocks[0]||{runModel:[],pPr:null},u=Rt(c.runModel,l),m=kt(u,l,{generateRedlines:n,author:a,formatHints:i});return fe(m,c.pPr,i,{author:a,generateRedlines:n})}function Do(e){return e.map(t=>fe(t.runModel,t.pPr,[],{})).join("")}function zo(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 En(e){let{cleanText:t,numberingContext:r,originalRunModel:n=[],originalText:a="",generateRedlines:o=!0,author:i="AI",font:s=null,numberingService:l}=e,c=Ho(t),u=Wo(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=gr(m);I(`[ListGen] Detected indentation step: ${g} spaces/chars`);let d=u.find(v=>v.marker)?.marker||"",{format:w}=l.detectNumberingFormat(d);I(`[ListGen] Detected primary marker: "${d}", format: ${w}`);for(let v=0;v<u.length;v++){let E=Uo(u,v);if(E){let C=me(E.tableText);if(C.headers.length>0||C.rows.length>0){o&&f.length===0&&p.length>0&&f.push(fe(p,null,[],{author:i,generateRedlines:o,font:s})),f.push(_e(C,{generateRedlines:o,author:i})),v=E.endIndex;continue}}let N=u[v],y=jo(N,v,g,r,l,o,i,s,p);f.push(y.ooxml)}let h=l.generateNumberingXml(),P=f.join("")+"<w:p><w:pPr></w:pPr></w:p>";return I(`[ListGen] \u2705 Generated OOXML for ${f.length} list items, total length: ${P.length}`),I(`[ListGen] First 200 chars: ${P.substring(0,200)}...`),{ooxml:P,isValid:!0,warnings:["Paragraph expanded to list fragment"],type:"fragment",includeNumbering:!0,numberingXml:h}}function gr(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 Wo(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 Ho(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=Pe(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 I(`[ListGen] Normalized ${a} composite list markers (e.g., "- A." -> "A.").`),o.join(`
136
+ `)}function Uo(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 jo(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=Pe(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 Go=new Set(["officeonline","officeweb","web"]);function Vo(e){return e?Go.has(String(e).toLowerCase()):!1}function Ko(){return typeof process<"u"&&process?.env?.NODE_ENV==="production"}function Zo(){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 st,this.font=t.font||null,this.platform=t.platform??tr(),this.isWebPlatform=t.isWebPlatform??Vo(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}=It(t,{xmlDoc:o}),u=i?ur(i):null;I(`[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);I(`[Reconcile] Preprocessed: ${f.length} format hints`),await this.maybeYield(s.length,Math.max(l.length,m.length));let p=en(m),g=Et(m),d=p||g;if(!p&&g&&I("[Reconcile] List-target detected via loose marker parsing; bypassing no-op short-circuit for structural conversion."),l===m&&f.length===0&&!d)return I("[Reconcile] No changes detected"),{ooxml:t,isValid:!0,warnings:["No changes detected"]};let w=Math.max(l.length,m.length)<this.disableSemanticCleanupOverChars,h=At(l,m,{cleanupSemantic:w});w||I("[Reconcile] Skipping semantic diff cleanup for large web payload"),await this.maybeYield(s.length,Math.max(l.length,m.length));let b=s.filter(E=>E.kind===k.PARAGRAPH_START).length;if(I(`[Reconcile] isTargetList: ${d}, paragraphCount: ${b}`),d)return I("[Reconcile] \u{1F3AF} ENTERING LIST GENERATION PATH"),I(`[Reconcile] cleanText preview: ${m.substring(0,100)}...`),I(`[Reconcile] acceptedText preview: ${l.substring(0,100)}...`),this.executeListGeneration(m,u,s);I(`[Reconcile] Computed ${h.length} diff operations`);let x=Rt(s,h);I(`[Reconcile] Split into ${x.length} runs`);let P=kt(x,h,{generateRedlines:this.generateRedlines,author:this.author,formatHints:f,numberingService:this.numberingService});I(`[Reconcile] Patched model has ${P.length} runs`),await this.maybeYield(P.length,Math.max(l.length,m.length));let v=fe(P,c,f,{author:this.author,generateRedlines:this.generateRedlines});if(this.shouldRunValidation()){let E=this.validateBasic(v);E.isValid||a.push(...E.errors)}return{ooxml:v,isValid:a.length===0,warnings:a}}catch(o){return Y("[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&&Ko()):!1}async maybeYield(t,r){this.enableEventLoopYielding&&(t<=this.yieldRunThreshold&&r<=this.yieldCharThreshold||await Zo())}wrapForInsertion(t,r={}){return Ce(t,r)}async executeListGeneration(t,r,n,a=""){return En({cleanText:t,numberingContext:r,originalRunModel:n,originalText:a,generateRedlines:this.generateRedlines,author:this.author,font:this.font,numberingService:this.numberingService})}detectIndentationStep(t){return gr(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 Yo(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 dr(e){return["ins","del","moveFrom","moveTo","moveFromRangeStart","moveFromRangeEnd","moveToRangeStart","moveToRangeEnd","rPrChange","pPrChange","cellIns","cellDel"].some(r=>Yo(e,r).length>0)}function Jo(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:Jo(e.oxml)}}var lt=["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 Ve(e,t){let r=lt.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=lt.indexOf(o.nodeName);if((i===-1?999:i)>n){e.insertBefore(t,o),a=!0;break}}a||e.appendChild(t)}function qo(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"),Ve(t,c);let u=A(e,"w:bCs");u.setAttribute("w:val",n==="add"?"1":"0"),Ve(t,u)}if(o){let c=A(e,"w:i");c.setAttribute("w:val",n==="add"?"1":"0"),Ve(t,c);let u=A(e,"w:iCs");u.setAttribute("w:val",n==="add"?"1":"0"),Ve(t,u)}if(i){let c=A(e,"w:u");c.setAttribute("w:val",n==="add"?"single":"none"),Ve(t,c)}if(s){let c=A(e,"w:strike");c.setAttribute("w:val",n==="add"?"1":"0"),Ve(t,c)}}function Sn(e,t,r){qo(e,t,r,"remove")}function ct(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=Ot(r,!1)),r.nodeName==="w:i"&&(t.italic=Ot(r,!1)),r.nodeName==="w:u"&&(t.underline=Ot(r,!0)),r.nodeName==="w:strike"&&(t.strikethrough=Ot(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 Ot(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 Cn="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function de(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===Cn&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function Qo(e){return!e||e.nodeType!==1||e.namespaceURI!==Cn?!1:e.localName==="del"||e.localName==="moveFrom"}function In(e){let t=[],r=Array.from(e?.childNodes||[]).reverse();for(;r.length>0;){let n=r.pop();if(!n||n.nodeType!==1||Qo(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 An(e){let t=[],r=0;for(let n=0;n<e.length;n++){let a=e[n],o=In(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 ei(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=ct(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 Rn(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=ct(s);l.hasFormatting&&I(`[OxmlEngine] Found paragraph-level formatting: ${JSON.stringify(l)}`);let c=In(i);for(let u of c)n=ei(u,i,n,r,t,l);n=Me(n,o,a.length)}return I(`[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 kn(e,t){return Array.from(e?.childNodes||[]).find(r=>r.nodeType===1&&(r.localName===t||r.nodeName===`w:${t}`))||null}function ti(e,t){let r=kn(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 ri(e,t){let r=kn(t,"rPr");return r?t.lastChild!==r&&t.appendChild(r):(r=A(e,"w:rPr"),t.appendChild(r)),r}function On(e,t,r,n){let a=ti(e,t),o=ri(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 Mn(e,t,r){return On(e,t,r,"ins")}function Mt(e,t,r){return On(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 Ln(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 Lt(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=Ke(e,r,h,o,i);c.push(hr(e,p,b,!1))}return c}function hr(e,t,r,n){let a=A(e,"w:r");if(r&&a.appendChild(r),!n)return Ln(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 Ln(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 Ke(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&&ni(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=lt.indexOf(l),g=p===-1?999:p,d=!1;for(let w of Array.from(o.childNodes)){if(w.nodeType!==1)continue;let h=lt.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 wr(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 ni(e,t,r,n){wr(e,t,r,null,n||t)}var ai="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function Ze(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===ai&&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=oi(l),u=br(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=br(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 Bn(e,t){let r=br(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 Fn(e){let t=e;for(;t;){if(Ze(t,"p"))return t;t=t.parentNode}return null}function oi(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 br(e){return e?e.replace(/\r/g,`
141
+ `).replace(/\u00a0/g," "):""}function $n(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=ii(e,l,c);if(!u){i++;continue}o.push(u[0]),l=u[1],i++}o.push(l)}return o}function ii(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 si="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function li(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 ci(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 Xn(e,t,r,n,a,o=!0){let i=!1,s=new Set;I(`[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;I("[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&&wr(e,u,a||J()),Sn(e,u,l.format),i=!0}return i?(I("[OxmlEngine] Surgical format removal completed successfully (Pure Format Mode)"),{oxml:n.serializeToString(e),hasChanges:!0}):(I("[OxmlEngine] No format changes were applied"),{oxml:n.serializeToString(e),hasChanges:!1})}function ui(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=$n(e,t,l).slice().sort((f,p)=>f.charStart-p.charStart||f.charEnd-p.charEnd),m=fi(r);for(let f of u){if(!f||!f.textElement||!li(f.textElement,"t"))continue;let p=m(f.charStart,f.charEnd);if(p.length===0)continue;let g=rr(...p.map(R=>R.format)),d={bold:!!g.bold,italic:!!g.italic,underline:!!g.underline,strikethrough:!!g.strikethrough},w=f.format||ct(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 E=f.runElement,N=$(E,"w:rPr"),y=Ke(e,N,d,a||J(),o),C=N;if(!C)E.insertBefore(y,E.firstChild);else{for(;C.firstChild;)C.removeChild(C.firstChild);Array.from(y.childNodes).forEach(R=>C.appendChild(R))}i=!0}return{oxml:n.serializeToString(e),hasChanges:i}}function Dn(e,t,r,n,a,o=!0,i=null){let s=ci(i),l=s.paragraphs||xe(e),c=s.textSpans||[];if(s.textSpans||({textSpans:c}=An(l)),!c||c.length===0)return Oe("[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}=Bn(u,t);if(!m||!m.spans||m.spans.length===0)return Oe("[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 ui(e,g,d,n,a,o)}function fi(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 mi="http://schemas.microsoft.com/office/word/2010/wordml";function zn(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});I(`[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=gi(c);return u&&u.toUpperCase()===l})||null,s?I(`[OxmlEngine] Found target paragraph by paraId: "${n}"`):I(`[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,I(`[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 ut(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 I(`[OxmlEngine] Stripping table wrapper, serializing ${n.length} paragraphs`),I(`[OxmlEngine] Paragraph XML preview: ${a.substring(0,200)}...`),pi(a)}function pi(e){return Nn(e)}function gi(e){if(!e)return null;let t=typeof e.getAttributeNS=="function"?e.getAttributeNS(mi,"paraId"):null;return t||e.getAttribute("w14:paraId")||e.getAttribute("w:paraId")||e.getAttribute("paraId")||null}function xr(e){return z(e,"t")?e.textContent||"":z(e,"br")||z(e,"cr")?`
142
+ `:z(e,"tab")?" ":z(e,"noBreakHyphen")?"\u2011":""}function Nr(e){return z(e,"t")||z(e,"br")||z(e,"cr")||z(e,"tab")||z(e,"noBreakHyphen")}function Hn(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+=Wn(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+=Wn(s,n,o,t.length,r).text);t=Ue(t,a,e.length)}),{fullText:t,textSpans:r}}function Wn(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(Nr(l)){let c=xr(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 Un(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 Bt(e,t,r,n){if(r<=t||e.spans.length===0)return;let a=vr(e.ends,t);for(;a<e.spans.length;){let o=e.spans[a];if(o.charStart>=r)break;n(o),a++}}function jn(e,t){if(e.spans.length===0)return null;let r=vr(e.starts,t)-1;if(r<0)return null;let n=e.spans[r];return t>=n.charStart&&t<n.charEnd?n:null}function Gn(e,t){let r=di(e.ends,t);return r<e.spans.length&&e.ends[r]===t?e.spans[r]:null}function Vn(e,t){let r=vr(e.ends,t)-1;return r>=0?e.spans[r]:null}function vr(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 di(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 Tr(e){let t=[],r=0;for(let n of Array.from(e.childNodes||[])){if(z(n,"rPr")||!Nr(n))continue;let a=xr(n);a.length!==0&&(t.push({node:n,start:r,end:r+a.length,text:a}),r+=a.length)}return t}function ft(e){return e.length===0?0:e[e.length-1].end}function Ye(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(hi(e,i.node,m,a))}),o}function yr(e,t,r){let n=A(e,"w:r");return r&&n.appendChild(r.cloneNode(!0)),t.forEach(a=>n.appendChild(a)),n}function mt(e,t,r,n,a){if(n.length===0)return null;let o=yr(e,n,a);return t.insertBefore(o,r),o}function hi(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 Kn(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),P=g.substring(h);if(b.length>0){let N=$e(e,b,l,!1);p.insertBefore(N,t.runElement)}let v=Ke(e,l,s,o,i),E=hr(e,x,v,!1);if(p.insertBefore(E,t.runElement),P.length>0){let N=$e(e,P,l,!1);p.insertBefore(N,t.runElement)}return p.removeChild(t.runElement),!0}function Zn(e,t,r,n,a,o){let i=[];if(Bt(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=Tr(u);if(f.length===0)return;let p=1/0,g=-1/0;if(c.forEach(b=>{let x=f.find(E=>E.node===b.textElement);if(!x)return;let P=Math.max(0,r-b.charStart),v=Math.min(b.charEnd-b.charStart,n-b.charStart);v<=P||(p=Math.min(p,x.start+P),g=Math.max(g,x.start+v))}),!Number.isFinite(p)||g<=p)return;let d=Ye(e,f,0,p,!1),w=Ye(e,f,p,g,!0),h=Ye(e,f,g,ft(f),!1);if(mt(e,m,u,d,c[0].rPr),o&&w.length>0){let b=yr(e,w,c[0].rPr),x=Fe(e,"del",b,a);m.insertBefore(x,u)}mt(e,m,u,h,c[0].rPr),m.removeChild(u),l=!0}),l}function Yn(e,t,r,n,a,o=[],i=0,s=!0,l=null){let c=jn(t,r);if(!c&&r>0&&(c=Gn(t,r)),!c&&r>0&&(c=Vn(t,r)),!c&&t.spans.length>0&&(c=t.spans[t.spans.length-1]),!c)return l?(Ft(e,l,null,n,null,a,o,i,s),!0):!1;let u=c.runElement.parentNode;if(!u)return l?(Ft(e,l,null,n,c.rPr,a,o,i,s),!0):!1;let m=Tr(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:ft(m);if(p>0&&p<ft(m)){let d=Ye(e,m,0,p,!1),w=Ye(e,m,p,ft(m),!1);return mt(e,u,c.runElement,d,c.rPr),Ft(e,u,c.runElement,n,c.rPr,a,o,i,s),mt(e,u,c.runElement,w,c.rPr),u.removeChild(c.runElement),!0}let g=r<=c.charStart?c.runElement:c.runElement.nextSibling;return Ft(e,u,g,n,c.rPr,a,o,i,s),!0}function Ft(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=Lt(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 Jn(e,t,r,n,a,o,i=!0,s=null){let l=s?[s]:xe(e),{fullText:c,textSpans:u}=Hn(l),m=it(c,r),f=Un(u),p=0,g=0,d=!1;for(let[w,h]of m)if(w===0){let b=h.length,x=p,P=p+b;Bt(f,x,P,v=>{let E=Math.max(v.charStart,x),N=Math.min(v.charEnd,P),y=N-E,C=E-x,R=g+C,M=R+y,L=we(o,R,M);Kn(e,v,E,N,L,a,i)&&(d=!0)}),p+=b,g+=b}else if(w===-1)Zn(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&&Yn(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 qn(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 wi(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 Qn(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,C)=>{let R=i.length;Array.from(y.childNodes).forEach(ye=>{i=xi(ye,i,s,c,u,m,f),u.size>m.size&&f++}),i=Ue(i,C,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,C)=>{let R=C.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");g=g.replace(new RegExp(R,"g"),y)}),g=bi(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=qn(l),x=qn(s),P=wi(c);return{paragraphs:a,body:o||e,paragraphMap:l,paragraphStarts:h,propertyMap:s,sentinelMap:c,sentinelMapByStart:P,referenceMap:u,tokenToCharMap:m,containerFragments:d,replacementContainers:w,originalFullText:i,processedModifiedText:g,getParagraphInfo:y=>{let C=b.at(y);return C||(l.length>0?l[l.length-1]:{start:0,end:0,pPr:null,container:o||e})},getRunProperties:y=>{let C=x.at(y);return C?{rPr:C.rPr,wrapper:C.wrapper}:{rPr:null}},getPropertySpanLength:(y,C)=>{let R=x.at(y);return R?Math.min(R.end-y,C):1},isParagraphStart:y=>h.has(y)}}function bi(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 xi(e,t,r,n,a,o,i){return e.nodeName==="w:r"?Ni(e,t,r,n,a,o,i):e.nodeName==="w:hyperlink"?vi(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 Ni(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 vi(e,t,r){let n=t;return Array.from(e.childNodes).forEach(a=>{if(a.nodeName!=="w:r")return;let o=$(a,"w:rPr");Ee(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 ta(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 C=A(e,"w:p");return y&&C.appendChild(y.cloneNode(!0)),C},b=p(0),x=h(b.pPr),P=c.get(b.container);P&&P.appendChild(x);let v=0,E=0,N=new WeakSet;for(let[y,C]of t){if(y===0||y===-1){let R=y===0?"equal":"delete",M=0;for(;M<C.length;){let L=v+M,le=g(L),ye=d(L,C.length-M),he=C.substring(M,M+ye);x=ea(e,he,R,le.rPr,le.wrapper,L,x,c,u,m,f,p,h,a,o,E,i,N).currentParagraph,y===0&&(E+=ye),M+=ye}v+=C.length;continue}if(y===1){let R=v>0&&!w(v)?g(v-1):g(v);x=ea(e,C,"insert",R.rPr,R.wrapper,v,x,c,u,m,f,p,h,a,o,E,i,N).currentParagraph,E+=C.length}}return s.forEach(y=>{y.parentNode&&y.parentNode.removeChild(y)}),c.forEach((y,C)=>{let M=f.get(C)||C;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 ea(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,P=i;return t.split(/([\n\uFFFC]|[\uE000-\uF8FF])/).forEach(E=>{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)),P.appendChild(M)}else P.appendChild(R.node.cloneNode(!0))}),E===`
145
+ `){let R=m(b+1),M=f(R.pPr);w&&r==="insert"?Mn(e,M,p):w&&r==="delete"&&Mt(e,M,p);let L=s.get(R.container);L&&(L.appendChild(M),P=M),b++,r!=="delete"&&x++;return}if(E==="\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)}}P.appendChild(M)}b++,r!=="delete"&&x++;return}if(c.has(E)){if(r!=="delete"){let R=c.get(E);if(R){let M=R.cloneNode(!0),L=A(e,"w:r");n&&L.appendChild(n.cloneNode(!0)),L.appendChild(M),P.appendChild(L)}}b++,r!=="delete"&&x++;return}if(E.length===0)return;let C=P;if(a){let R=a.cloneNode(!1);C=R,P.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=E,R.appendChild(M),w){let L=Fe(e,"del",R,p);C.appendChild(L)}}else{let R=we(g,x,x+E.length),M=Lt(e,E,n,R,x,p,w);if(r==="insert"&&w){let L=Fe(e,"ins",null,p);M.forEach(le=>L.appendChild(le)),C.appendChild(L)}else M.forEach(L=>C.appendChild(L))}r!=="delete"&&(x+=E.length),b+=E.length}),{currentParagraph:P}}function Pr(e,t,r,n,a,o,i=!0){let s=Qn(e,r);if(s.paragraphs.length===0)return te({oxml:n.serializeToString(e),hasChanges:!1});let l=it(s.originalFullText,s.processedModifiedText);return te(ta(e,l,s,n,a,o,i))}function Ie(e,t){return te({oxml:e.serializeToString(t),hasChanges:!1})}function ra(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 Ie(r,e);let c=i[0],u=mr(c),m=yn(u,s);if(m.length===0)return Ie(r,e);let p=Pn(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 Y("[OxmlEngine] Failed to parse reconciled table OOXML:",h.textContent),Ie(r,e);let b=Ct(w,S,"tbl");if(!b)return Y("[OxmlEngine] No table found in reconciled OOXML"),Ie(r,e);let x=e.importNode(b,!0);return c.parentNode.replaceChild(x,c),te({oxml:r.serializeToString(e),hasChanges:!0})}function na(e,t,r,n,a,o){let i=me(t);if(!i||i.rows.length===0&&i.headers.length===0)return I("[OxmlEngine] Failed to parse table data from Markdown"),Ie(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 Y("[OxmlEngine] Failed to parse generated table OOXML:",u.textContent),Ie(r,e);let m=H(c,S,"tbl");if(m||(m=H(c,S,"ins")),!m)return Y("[OxmlEngine] No table element found in generated OOXML"),Ie(r,e);let f=e,p=V(f,S,"p");if(p.length===0)return I("[OxmlEngine] No paragraphs found to replace"),Ie(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=>{Mt(f,h,a),V(h,S,"r").forEach(x=>{V(x,S,"t").forEach(N=>{let y=N.textContent||"";if(y.trim()){let C=A(f,"w:delText");C.textContent=y,N.parentNode.replaceChild(C,N)}});let v=A(f,"w:del"),E=ee(a);v.setAttribute("w:id",String(E.id)),v.setAttribute("w:author",E.author),v.setAttribute("w:date",E.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),I("[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 ia(e){return typeof e=="string"?e.trim().toLowerCase():""}function Ti(e){return!!e&&e.nodeType===1}function Ae(e,t){return Ti(e)&&e.namespaceURI===S&&String(e.localName||"").toLowerCase()===t.toLowerCase()}function re(e,t){return Array.from(e.getElementsByTagNameNS(S,t))}function Er(e={}){if(e?.allAuthors===!0)return{valid:!0,allAuthors:!0,normalizedAuthor:""};let t=ia(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=ia(Xe(e,"author"));return!!r&&r===t.normalizedAuthor}function Sr(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 Z(e){return e?.parentNode?(e.parentNode.removeChild(e),!0):!1}function $t(e){let t=e?.parentNode;if(!t)return!1;for(;e.firstChild;)t.insertBefore(e.firstChild,e);return t.removeChild(e),!0}function Xt(e){let t=e?.parentNode;return Ae(t,"trPr")&&Ae(t?.parentNode,"tr")}function Cr(e){let t=e?.parentNode,r=t?.parentNode,n=r?.parentNode;return Ae(t,"rPr")&&Ae(r,"pPr")&&Ae(n,"p")}function sa(e){return Cr(e)?e.parentNode.parentNode.parentNode:null}function yi(e){let t=e?.nextSibling||null;for(;t;){if(Ae(t,"p"))return t;t=t.nextSibling}return null}function la(e){if(!e?.parentNode)return!1;let t=yi(e);if(!t)return Z(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 Z(e)}function Ir(e,t={}){let r=[],n=Er(t);if(!n.valid)return{oxml:e,hasChanges:!1,acceptedCount:0,warnings:[n.warning]};let a=Sr(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(Cr(c)){Z(c)&&(s+=1);continue}if(Xt(c)){Z(c)&&(s+=1);continue}$t(c)&&(s+=1)}for(let c of re(o,"del")){if(!c.parentNode||!ie(c,n))continue;let u=sa(c);if(u){la(u)&&(s+=1);continue}if(Xt(c)){let m=c.parentNode?.parentNode;Z(m)&&(s+=1);continue}Z(c)&&(s+=1)}for(let c of re(o,"moveFrom"))!c.parentNode||!ie(c,n)||Z(c)&&(s+=1);for(let c of re(o,"moveTo"))!c.parentNode||!ie(c,n)||$t(c)&&(s+=1);s+=ca(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)||Z(u)&&(s+=1);return{oxml:i.serializeToString(o),hasChanges:s>0,acceptedCount:s,warnings:r}}function aa(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 Pi(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 Z(e);let a=Array.from(e.childNodes||[]).find(i=>i.nodeType===1&&i.namespaceURI===S&&String(i.localName||"").toLowerCase()===n.toLowerCase());if(!a)return Z(e);let o=Array.from(a.childNodes||[]);for(;r.firstChild;)r.removeChild(r.firstChild);for(let i of o){let s=Ei(r.ownerDocument,i);r.appendChild(s)}return!0}function Ei(e,t){return e&&typeof e.importNode=="function"?e.importNode(t,!0):t.cloneNode(!0)}function oa(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 ca(e,t){let r=0,n=oa(e,"moveFromRangeStart",t),a=oa(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))&&Z(c)&&(r+=1)}return r}function Si(e,t={}){let r=[],n=Er(t);if(!n.valid)return{oxml:e,hasChanges:!1,rejectedCount:0,warnings:[n.warning]};let a=Sr(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=sa(c);if(u){la(u)&&(s+=1);continue}if(Xt(c)){let m=c.parentNode?.parentNode;Z(m)&&(s+=1);continue}Z(c)&&(s+=1)}for(let c of re(o,"del"))if(!(!c.parentNode||!ie(c,n))){if(Cr(c)){Z(c)&&(s+=1);continue}if(Xt(c)){Z(c)&&(s+=1);continue}aa(o,c),$t(c)&&(s+=1)}for(let c of re(o,"moveFrom"))!c.parentNode||!ie(c,n)||(aa(o,c),$t(c)&&(s+=1));for(let c of re(o,"moveTo"))!c.parentNode||!ie(c,n)||Z(c)&&(s+=1);s+=ca(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)||Pi(u,c)&&(s+=1);return{oxml:i.serializeToString(o),hasChanges:s>0,rejectedCount:s,warnings:r}}function Ci(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 Ii(e,t){let r=0;for(let n of e){let a=Xe(n,"id");!a||!t.has(a)||Z(n)&&(r+=1)}return r}function Ai(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 Ri(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"&&Ai(o.parentNode)){Z(o.parentNode)&&(r+=1);continue}Z(o)&&(r+=1)}}return r}function ki(e,t={}){let r=[],n=Er(t);if(!n.valid)return{oxml:e,hasChanges:!1,commentsRemoved:0,referencesRemoved:0,warnings:[n.warning]};let a=Sr(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}=Ci(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=Ii(l,s),u=Ri(o,s);return{oxml:i.serializeToString(o),hasChanges:c>0||u>0,commentsRemoved:c,referencesRemoved:u,warnings:r}}async function Ar(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 Y("[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 Y("[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(or(u),dr(u))if((n.existingRevisions||"reject-input")==="accept-all-first"){I("[OxmlEngine] Existing revisions detected; accepting all input revisions before redlining"),e=Ir(e,{allAuthors:!0}).oxml,u=i.parseFromString(e,"text/xml");let ge=j(u);if(ge)return Y("[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."}});or(u)}else return I("[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=zn(u,t,n);if(f.hasTableWrapper&&f.targetParagraph&&!n._isolatedTableCell){I("[OxmlEngine] Isolating table-cell paragraph before diff");let U=ut(u,f.targetParagraph,s);return Ar(U,t,r,{...n,_isolatedTableCell:!0})}let p=fa(r),{cleanText:g,formatHints:d}=ne(p),w=g.trim()!==t.trim(),h=d.length>0,{existingFormatHints:b,textSpans:x,paragraphs:P}=Rn(u),v=b.length>0,E=x.map(U=>Oi(U)).join("");if(w&&typeof t=="string"&&t.trim()&&!t.includes(`
146
+ `)&&!E.includes(t.trim())&&!E.replace(/[\t\n\u2011]/g,"").includes(t.trim().replace(/[\t\n\u2011]/g,""))&&!ua(E).includes(ua(t)))return I("[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,P,x)),N),C=(U=null)=>{let X=Dn(u,t,d,s,o,a,U);return X.useNativeApi?(I("[OxmlEngine] Format-only surgical fallback signal encountered; retrying with OOXML reconstruction fallback"),Pr(u,t,g,s,o,d,a)):X};I(`[OxmlEngine] Text changes: ${w}, New format hints: ${d.length}, Existing format hints: ${b.length}`);let R=!w&&!h&&v;if(!w&&!h&&!v)return I("[OxmlEngine] No text changes, no format hints, and no existing formatting detected"),c();if(R){I("[OxmlEngine] Format REMOVAL detected: applying surgical replacement in OOXML");let U=f,X=U.targetParagraph||null;if(!X){let Tt=_n(y(),t);Tt&&(X=Tt.paragraph)}let ge=b;X&&(ge=b.filter(Tt=>Fn(Tt.run)===X));let Vr=Xn(u,x,ge,s,o,a);return U.hasTableWrapper&&X?l({oxml:ut(u,X,s),hasChanges:Vr.hasChanges}):l(Vr)}if(!w&&h){I(`[OxmlEngine] Format-only change detected: ${d.length} format hints`);let U=f,X={textSpans:x,paragraphs:P,paragraphInfos:y()};if(U.hasTableWrapper&&U.targetParagraph){I("[OxmlEngine] Table cell context: applying formatting to target paragraph only");let ge=C(X);return I("[OxmlEngine] Stripping table wrapper for table cell paragraph (format-only)"),l({oxml:ut(u,U.targetParagraph,s),hasChanges:ge.hasChanges})}return l(C(X))}let L=ue(u,S,"tbl").length>0,le=/^\|.+\|/.test(g.trim())&&g.includes(`
147
+ `),ye=Et(g),he=f;if(I(`[OxmlEngine] Mode: ${L?"SURGICAL":"RECONSTRUCTION"}, formatHints: ${d.length}, isMarkdownTable: ${le}, isTargetList: ${ye}, isTableCellParagraph: ${he.isTableCellParagraph}`),le&&!L)return I("[OxmlEngine] Text-to-table transformation: generating new table from Markdown"),l(na(u,g,s,i,o,a));if(L&&le)return l(ra(u,g,s,i,o,a));if(L){let U=he.hasTableWrapper&&he.targetParagraph?he.targetParagraph:null;U&&I("[OxmlEngine] Table cell edit: scoping surgical mode to target paragraph");let X=Jn(u,t,g,s,o,d,a,U);return he.hasTableWrapper&&X.hasChanges&&he.targetParagraph?(I("[OxmlEngine] Stripping table wrapper for table cell paragraph (surgical mode)"),l({oxml:ut(u,he.targetParagraph,s),hasChanges:!0})):l(X)}if(ye){I("[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){I(`[OxmlEngine] Wrapping list OOXML with numbering definitions, includeNumbering=${X.includeNumbering}`);let ge=Ce(X.ooxml,{includeNumbering:X.includeNumbering??!0,numberingXml:X.numberingXml});return I(`[OxmlEngine] \u2705 Wrapped OOXML length: ${ge.length}`),l({oxml:ge,hasChanges:!0})}return c()}return l(Pr(u,t,g,s,o,d,a))}function ua(e){return String(e||"").replace(/[\t\n\u2011]/g," ").replace(/\s+/g," ").trim()}function Oi(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 fa(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 pe(e){return br(e,"application/xml")}function Oe(e){return j(e)}function Qt(e){return Array.from(e||[])}var te="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function er(e,t){if(!e)return[];if(typeof e.getElementsByTagNameNS=="function"){let n=Qt(e.getElementsByTagNameNS("*",t));if(n.length>0)return n}if(typeof e.getElementsByTagName!="function")return[];let r=Qt(e.getElementsByTagName(`w:${t}`));return r.length>0?r:Qt(e.getElementsByTagName(t))}function ki(e){return er(e,"t").map(r=>r.textContent||"").join("")}function W(e){return e?ki(e):""}function ge(e){if(!e)return[];let t=er(e,"body"),r=t.length>0?t[0]:e;return er(r,"p")}function L(e){return String(e||"").replace(/\s+/g," ").trim()}function nr(e){let t=String(e||"").trim();return/^\|.+\|/.test(t)&&t.includes(`
147
- `)}function ar(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 Ci(e){return e==null?"":String(e).replace(/^\s*\[P\d+(?:\.\d+)?\]\s*/i,"").trim()}function Oi(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 bn(e,t){return!Number.isInteger(t)||t<1?null:ge(e)[t-1]||null}function De(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 vt(e,t){let r=ge(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 tr(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=ge(e),i=String(t||"").trim();if(!i)return null;let o=vt(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 f=0,m=null,u=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=>u.has(x)).length/Math.max(u.size,1);h>f&&h>.5&&(f=h,m=p)}return m?(n(`[Fuzzy] Best word-overlap match (${(f*100).toFixed(0)}%): "${W(m).trim().slice(0,60)}..."`),m):null}function xn(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=ar(t.targetRef);if(o){let s=bn(e,o);if(s){if(i){let l=vt(e,i),c=W(s).trim(),f=L(c),m=L(i),u=f!==m;if(u&&l&&l!==s)return r(`[Target] [P${o}] drifted for ${a}; using strict text rematch.`),{paragraph:l,resolvedBy:"strict_text_after_ref_drift"};if(u){let p=tr(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=vt(e,i);if(s)return{paragraph:s,resolvedBy:"strict_text"};let l=tr(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 Nn(e){return!!De(e,"tbl")}function Ri(e,t){let r=L(t);if(!r)return[];let n=ge(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:Nn(o)})}return a}function Mi(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 Li(e){let t=ge(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:Nn(a)})}return r}function rr(e,t={}){let r=typeof t.onInfo=="function"?t.onInfo:()=>{},n=xn(e,t),a=ar(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 f=[];if(o&&f.push(o),i.text){let u=L(i.text);u&&!f.some(p=>L(p)===u)&&f.push(i.text)}let m=null;for(let u of f){let p=Ri(e,u),g=Mi(p,a,i.inTable);if(g&&(m||(m=g),g.paragraph!==n.paragraph)){m=g;break}}if(m&&m.paragraph!==n.paragraph){let u=t.opType||"operation";return r(`[Target] [P${a}] appears stale after prior edits; using strict text rematch for ${u}.`),{paragraph:m.paragraph,resolvedBy:"strict_text_after_ref_drift"}}return n}function _i(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=rr(e,{targetRef:t,opType:a,targetRefSnapshot:i,onInfo:o,onWarn:s})?.paragraph;if(!l)return null;let c=rr(e,{targetRef:r,opType:a,targetRefSnapshot:i,onInfo:o,onWarn:s})?.paragraph;if(!c)return null;let f=Array.from(e.getElementsByTagNameNS("*","p")),m=f.indexOf(l),u=f.indexOf(c);if(m<0||u<m)return null;let p=f.slice(m,u+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 Tt(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 vn(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 Bi(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 Tn=/^(?:(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|[ivxlcIVXLC]+\.|[-*+\u2022]))\s+/;function En(e){let t=String(e||"").trim(),r=0;for(;r<4&&Tn.test(t);)t=t.replace(Tn,"").trimStart(),r++;return t.trim()}function Pn(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"?Bi(s):null,text:En(o[3])});continue}r.push({kind:"text",text:i.trim()})}return{items:r,hasListMarkers:n}}function yn(e,t,r){return`${" ".repeat(Math.max(0,e))}${t==="numbered"?"1.":"-"} ${String(r||"").trim()}`.trimEnd()}function tt(e,t){return L(e)===L(t)}function yt(e,t,r){return Number.isInteger(e?.outlineLevel)?Math.max(0,e.outlineLevel):Math.max(0,t+((e?.level||0)-r))}function $i(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"?tt(n.text,t):!1}function Fi(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 Xi(e,t,r,n){let a=e[0],i=e.slice(1).filter(o=>o.kind==="list");if(a?.kind==="text"&&tt(a.text,t)&&i.length>0){let o=i[0].level;return i.map(s=>({ilvl:yt(s,r,o),markerType:s.markerType||n,text:s.text}))}if(e.every(o=>o.kind==="list")){let o=e[0];if(!o||!tt(o.text,t))return null;let s=o.level;return e.slice(1).map(l=>({ilvl:yt(l,r,s),markerType:l.markerType||n,text:l.text})).filter(l=>l.text)}return null}function de(e){if(!e)return null;let t=Tt(e,"pPr");if(!t)return null;let r=Tt(t,"numPr");if(!r)return null;let n=Tt(r,"numId");if(!n)return null;let a=vn(n);if(!a)return null;let i=Tt(r,"ilvl"),o=vn(i),s=Number.parseInt(o||"0",10);return{numId:String(a),ilvl:Number.isFinite(s)?s:0}}function Sn(e){let t=de(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=de(n[i-1]);if(!s||s.numId!==t.numId)break;i--}let o=a;for(;o<n.length-1;){let s=de(n[o+1]);if(!s||s.numId!==t.numId)break;o++}return n.slice(i,o+1)}function Di(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
- `)||!de(e))return null;let s=Sn(e);if(!s||s.length===0)return null;let l=Pn(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",u=s.map(b=>({paragraph:b,list:de(b),text:String(W(b)||"").trim()})),p=s.indexOf(e);if(p<0)return null;let g=Math.min(...u.map(b=>b.list?.ilvl??0)),d=u.map(b=>yn((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"&&tt(h.text,c)&&x.length>0){let b=Math.max(0,(u[p].list?.ilvl??0)-g),S=x[0].level;w=[{level:b,markerType:m,text:u[p].text},...x.map(P=>({level:yt(P,b,S),markerType:P.markerType||m,text:P.text}))]}else if(l.items.every(b=>b.kind==="list")){let b=Math.max(0,(u[p].list?.ilvl??0)-g),S=l.items[0].level;w=l.items.map(P=>({level:yt(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=>yn(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 zi(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=de(e);if(!o)return null;let s=Pn(i);if(!s.hasListMarkers||s.items.length<2)return null;let l=L(r.currentParagraphText||W(e)),f=s.items.filter(p=>p.kind==="list")[0]?.markerType||"bullet",m=Math.max(0,o.ilvl),u=Xi(s.items,l,m,f);return!u||u.length===0?(a("[List] Could not derive insertion-only entries from multiline list edit."),null):($i(s.items,l,m)&&(u=Fi(u,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:u})}function rt(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=ue(o,{allowZeroSpaceAfterMarker:!1});if(s){let l=s[1]||"",c=s[2].trim(),f=we(o,{allowZeroSpaceAfterMarker:!1}).trim(),m=Math.floor(l.length/2),u=/^[-*+\u2022]$/.test(c);n.push({type:u?"bullet":"numbered",level:m,text:f,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 ir(e){return!e||!Array.isArray(e.items)?!1:e.items.some(t=>t?.type==="numbered"||t?.type==="bullet")}function or(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 Wi(e,t,r){let n=new Map,a=[];for(let i of e){let o=Math.max(0,Number(i?.level)||0);for(let f of Array.from(n.keys()))f>o&&n.delete(f);let s=(n.get(o)||0)+1;n.set(o,s);let l=Ui(s,t,r),c=" ".repeat(o*4);a.push(`${c}${l} ${i.text||""}`.trimEnd())}return a.join(`
153
- `)}function Hi(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(),f=null,m=c.match(n);return m&&(f=m[1].trim()||null,c=c.replace(n,"")),{text:c.trim(),level:l,removedMarker:f}})}function Ui(e,t,r){if(t==="bullet")return"-";switch(r){case"lowerAlpha":return`${In(e,!1)}.`;case"upperAlpha":return`${In(e,!0)}.`;case"lowerRoman":return`${An(e,!1)}.`;case"upperRoman":return`${An(e,!0)}.`;case"decimal":default:return`${e}.`}}function In(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 An(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 Et(e){let t=String(e||"");if(!t.trim()||t.includes(`
154
- `))return null;let r=rt(t);if(!r||!ir(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"?or(a||"1."):"bullet";return{type:n.type,marker:a,numberingStyle:i,startAt:Gi(a,i),contentText:String(n.text||"").trim(),normalizedContent:L(String(n.text||""))}}function ji(e){let t=Et(e);return t?String(t.contentText||"").trim():String(e||"").trim()}function Gi(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 Ki(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 Vi(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 Zi(e,t){!e||!(e.explicitByNumberingKey instanceof Map)||t&&e.explicitByNumberingKey.delete(String(t))}function ze(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 Yi(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 f=ze(l,"pPr");if(f||(f=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:pPr"),l.insertBefore(f,l.firstChild)),a){let g=ze(f,"pPrChange");g&&f.removeChild(g)}if(i){let g=ze(f,"listPr");g&&f.removeChild(g)}let m=ze(f,"numPr");m||(m=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:numPr"),f.appendChild(m));let u=ze(m,"ilvl");u||(u=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:ilvl"),m.appendChild(u)),u.setAttribute("w:val",String(n));let p=ze(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 Ji(e){let r=B().parseFromString(String(e||""),"application/xml");return U(r)?null:ge(r)[0]||null}function qi(e){return e?String(e).replace(/<w:p>\s*<w:pPr>\s*<\/w:pPr>\s*<\/w:p>\s*$/i,""):""}function Qi(e,t){for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return null}function We(e,t){let r=Qi(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function kn(e,t){e.setAttribute("w:val",String(t))}function eo(e){let r=B().parseFromString(String(e||""),"application/xml");if(U(r))return null;let i=ge(r)[0]||null;if(!i)return null;let o=Array.from(i.getElementsByTagNameNS("*","numId"));for(let s of o){let l=We(s,["w:val","val"]);if(l!=null)return String(l)}return null}function to(e,t,r,n={}){if(!e||!t||!Number.isInteger(r)||r<1)return e;let a=n.setAbstractStartOverride!==!1,i=B(),o=J(),s=i.parseFromString(String(e||""),"application/xml");if(U(s))return e;let f=Array.from(s.getElementsByTagNameNS("*","num")).find(d=>{let w=We(d,["w:numId","numId"]);return w!=null&&String(w)===String(t)});if(!f)return e;let m=Array.from(f.getElementsByTagNameNS("*","abstractNumId"))[0]||null,u=We(m,["w:val","val"]),p=Array.from(f.getElementsByTagNameNS("*","lvlOverride")).find(d=>We(d,["w:ilvl","ilvl"])===0)||null;p||(p=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:lvlOverride"),p.setAttribute("w:ilvl","0"),f.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)),kn(g,r),a&&u!=null){let w=Array.from(s.getElementsByTagNameNS("*","abstractNum")).find(h=>{let x=We(h,["w:abstractNumId","abstractNumId"]);return x!=null&&x===u})||null;if(w){let h=Array.from(w.getElementsByTagNameNS("*","lvl")).find(v=>We(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)),kn(x,r)}}return o.serializeToString(s)}function sr(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=Ji(t);if(!i)return null;let o=de(i);if(o&&!a)return null;let s=q(n).cleanText||n,l=Et(n)||Et(s);if(!l)return null;let c=Et(r),f=L(r)===L(s),m=!!c&&c.type===l.type&&c.normalizedContent===l.normalizedContent;return!f&&!m?null:{listInput:`${l.marker} ${l.contentText}`.trim(),numberingKey:`${l.type}:${l.numberingStyle}:single`,originalText:r,wasListParagraph:!!o,startAt:l.startAt}}async function Pt(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 Ce({author:r,generateRedlines:n})).executeListGeneration(e.listInput,null,null,String(e.originalText||"")),o=i?.oxml||i?.ooxml||"",s=qi(o),l=eo(s),c=to(i?.numberingXml||null,l,Number.isInteger(e?.startAt)?e.startAt:null,{setAbstractStartOverride:t.setAbstractStartOverride}),f=i?.isValid!==!1;return!s||!f?{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 St(e,t){return e?Array.from(e.childNodes||[]).filter(r=>r&&r.nodeType===1&&r.namespaceURI===te&&r.localName===t):[]}function ro(e){return String(e||"").replace(/\|/g,"\\|").replace(/\r?\n/g,"<br>")}function no(e){let t=St(e,"tr"),r=t.map(a=>St(a,"tc").map(o=>{let s=St(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 ao(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=>ro(l)).join(" | ")} |`;return[o(n),o(a),...i.map(o)].join(`
156
- `)}function io(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 Cn(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 oo(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(!Cn(l))break;a.push(i),i=s}return a.length>1?a:null}function so(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
- `)||nr(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||De(e,"tbl"),l=De(e,"tr"),c=De(e,"tc");if(!s||!l||!c)return null;let f=L(r.currentParagraphText||W(e)),m=L(o[0]);if(f&&m&&m!==f)return a("[Table] Multiline cell text did not anchor to original cell text; skipping table-row synthesis heuristic."),null;let{matrix:u,rowElements:p,columnCount:g}=no(s);if(u.length===0||g===0)return null;let d=p.indexOf(l),h=St(l,"tc").indexOf(c);if(d<0||h<0||h>=g)return null;u[d][h]=o[0];let x=io(u[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<u.length&&!L(u[N][h]))if(x)for(let b=0;b<g;b++)L(u[N][b])||(u[N][b]=E);else u[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;u.splice(Math.min(N,u.length),0,b)}}let v=ao(u,g);return v?(n("[Table] Synthesized full markdown table from multiline cell edit for table-scope reconciliation."),v):null}function He(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 Ue(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 lo(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 f=pe(e),m=Array.from(f.getElementsByTagNameNS("*","abstractNum")),u=Array.from(f.getElementsByTagNameNS("*","num"));for(let p of m){let g=He(p,["w:abstractNumId","abstractNumId"]);g!=null&&i.add(g)}for(let p of u){let g=He(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:Ue(l,a,n),nextAbstractNumId:Ue(c,i,n),usedNumIds:a,usedAbstractNumIds:i,minId:r,maxPreferred:n}}function co(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=Ue(e.nextNumId,e.usedNumIds,e.maxPreferred),e.nextAbstractNumId=Ue(e.nextAbstractNumId,e.usedAbstractNumIds,e.maxPreferred),e)}function at(e,t="num"){let r=co(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=Ue(a+1,r.usedAbstractNumIds,r.maxPreferred)):(r.usedNumIds.add(a),r.nextNumId=Ue(a+1,r.usedNumIds,r.maxPreferred)),a)}function uo(e){let t=at(e,"num"),r=at(e,"abstract");return t==null||r==null?null:{numId:t,abstractNumId:r}}function lr(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:e.getElementsByTagName("parsererror").length>0}function It(e,t){return!!(e&&e.nodeType===1&&e.namespaceURI===te&&e.localName===t)}function On(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 fo(e,t){for(let r of t||[]){let n=e?.getAttribute?.(r);if(n!=null&&n!=="")return n}return null}function nt(e,t){let r=fo(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function Rn(e,t,r){e?.setAttribute?.(t,String(r))}function cr(e,t){e?.setAttribute?.("w:val",String(t))}function mo(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)cr(a,t)}}function po(e){for(let t of e||[]){let r=Array.from(t?.getElementsByTagNameNS?.("*","numId")||[]);for(let n of r){let a=nt(n,["w:val","val"]);if(a!=null)return String(a)}}return null}function go(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,u)=>`%${u+1}`).join(".")+".",f=720*(l+1);return`
150
+ `),t}function Ne(e){return Zr(e,"application/xml")}function De(e){return K(e)}function Rr(e){return Array.from(e||[])}var se="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function kr(e,t){if(!e)return[];if(typeof e.getElementsByTagNameNS=="function"){let n=Rr(e.getElementsByTagNameNS("*",t));if(n.length>0)return n}if(typeof e.getElementsByTagName!="function")return[];let r=Rr(e.getElementsByTagName(`w:${t}`));return r.length>0?r:Rr(e.getElementsByTagName(t))}function Mi(e){return kr(e,"t").map(r=>r.textContent||"").join("")}function G(e){return e?Mi(e):""}function ve(e){if(!e)return[];let t=kr(e,"body"),r=t.length>0?t[0]:e;return kr(r,"p")}function _(e){return String(e||"").replace(/\s+/g," ").trim()}function Lr(e){let t=String(e||"").trim();return/^\|.+\|/.test(t)&&t.includes(`
151
+ `)}function _r(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 Li(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 ma(e,t){return!Number.isInteger(t)||t<1?null:ve(e)[t-1]||null}function Je(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 Dt(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 Or(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=ve(e),o=String(t||"").trim();if(!o)return null;let i=Dt(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 pa(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=_r(t.targetRef);if(i){let s=ma(e,i);if(s){if(o){let l=Dt(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=Or(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=Dt(e,o);if(s)return{paragraph:s,resolvedBy:"strict_text"};let l=Or(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 ga(e){return!!Je(e,"tbl")}function Bi(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:ga(i)})}return a}function Fi(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 $i(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:ga(a)})}return r}function Mr(e,t={}){let r=typeof t.onInfo=="function"?t.onInfo:()=>{},n=pa(e,t),a=_r(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=Bi(e,f),g=Fi(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 Xi(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=Mr(e,{targetRef:t,opType:a,targetRefSnapshot:o,onInfo:i,onWarn:s})?.paragraph;if(!l)return null;let c=Mr(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 zt(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 da(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 Di(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 ha=/^(?:(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|[ivxlcIVXLC]+\.|[-*+\u2022]))\s+/;function ba(e){let t=String(e||"").trim(),r=0;for(;r<4&&ha.test(t);)t=t.replace(ha,"").trimStart(),r++;return t.trim()}function xa(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"?Di(s):null,text:ba(i[3])});continue}r.push({kind:"text",text:o.trim()})}return{items:r,hasListMarkers:n}}function wa(e,t,r){return`${" ".repeat(Math.max(0,e))}${t==="numbered"?"1.":"-"} ${String(r||"").trim()}`.trimEnd()}function pt(e,t){return _(e)===_(t)}function Wt(e,t,r){return Number.isInteger(e?.outlineLevel)?Math.max(0,e.outlineLevel):Math.max(0,t+((e?.level||0)-r))}function zi(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"?pt(n.text,t):!1}function Wi(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 Hi(e,t,r,n){let a=e[0],o=e.slice(1).filter(i=>i.kind==="list");if(a?.kind==="text"&&pt(a.text,t)&&o.length>0){let i=o[0].level;return o.map(s=>({ilvl:Wt(s,r,i),markerType:s.markerType||n,text:s.text}))}if(e.every(i=>i.kind==="list")){let i=e[0];if(!i||!pt(i.text,t))return null;let s=i.level;return e.slice(1).map(l=>({ilvl:Wt(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=zt(e,"pPr");if(!t)return null;let r=zt(t,"numPr");if(!r)return null;let n=zt(r,"numId");if(!n)return null;let a=da(n);if(!a)return null;let o=zt(r,"ilvl"),i=da(o),s=Number.parseInt(i||"0",10);return{numId:String(a),ilvl:Number.isFinite(s)?s:0}}function Na(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 Ui(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=Na(e);if(!s||s.length===0)return null;let l=xa(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=>wa((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"&&pt(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(C=>({level:Wt(C,N,y),markerType:C.markerType||m,text:C.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(C=>({level:Wt(C,N,y),markerType:C.markerType||m,text:C.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=>wa(N.level,N.markerType,N.text)),P=d.slice(0,p).concat(x).concat(d.slice(p+1)),v=d.join(`
153
+ `),E=P.join(`
154
+ `);return E===v?null:(n("[List] Expanded single-item list edit to contiguous list block for stable middle insertion."),{paragraphs:s,originalText:v,modifiedText:E})}function ji(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=xa(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=Hi(s.items,l,m,u);return!f||f.length===0?(a("[List] Could not derive insertion-only entries from multiline list edit."),null):(zi(s.items,l,m)&&(f=Wi(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 gt(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=Pe(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 Br(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 Gi(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=Ki(s,t,r),c=" ".repeat(i*4);a.push(`${c}${l} ${o.text||""}`.trimEnd())}return a.join(`
157
+ `)}function Vi(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 Ki(e,t,r){if(t==="bullet")return"-";switch(r){case"lowerAlpha":return`${va(e,!1)}.`;case"upperAlpha":return`${va(e,!0)}.`;case"lowerRoman":return`${Ta(e,!1)}.`;case"upperRoman":return`${Ta(e,!0)}.`;case"decimal":default:return`${e}.`}}function va(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 Ta(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 Ht(e){let t=String(e||"");if(!t.trim()||t.includes(`
158
+ `))return null;let r=gt(t);if(!r||!Br(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"?Fr(a||"1."):"bullet";return{type:n.type,marker:a,numberingStyle:o,startAt:Yi(a,o),contentText:String(n.text||"").trim(),normalizedContent:_(String(n.text||""))}}function Zi(e){let t=Ht(e);return t?String(t.contentText||"").trim():String(e||"").trim()}function Yi(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 Ji(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 qi(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 Qi(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 es(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 ts(e){let r=B().parseFromString(String(e||""),"application/xml");return j(r)?null:ve(r)[0]||null}function rs(e){return e?String(e).replace(/<w:p>\s*<w:pPr>\s*<\/w:pPr>\s*<\/w:p>\s*$/i,""):""}function ns(e,t){for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return null}function Qe(e,t){let r=ns(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function ya(e,t){e.setAttribute("w:val",String(t))}function as(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=Qe(s,["w:val","val"]);if(l!=null)return String(l)}return null}function os(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=Qe(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=Qe(m,["w:val","val"]),p=Array.from(u.getElementsByTagNameNS("*","lvlOverride")).find(d=>Qe(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)),ya(g,r),a&&f!=null){let w=Array.from(s.getElementsByTagNameNS("*","abstractNum")).find(h=>{let b=Qe(h,["w:abstractNumId","abstractNumId"]);return b!=null&&b===f})||null;if(w){let h=Array.from(w.getElementsByTagNameNS("*","lvl")).find(x=>Qe(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)),ya(b,r)}}return i.serializeToString(s)}function $r(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=ts(t);if(!o)return null;let i=Te(o);if(i&&!a)return null;let s=ne(n).cleanText||n,l=Ht(n)||Ht(s);if(!l)return null;let c=Ht(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 Ut(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=rs(i),l=as(s),c=os(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"]}}function jt(e,t){return e?Array.from(e.childNodes||[]).filter(r=>r&&r.nodeType===1&&r.namespaceURI===se&&r.localName===t):[]}function is(e){return String(e||"").replace(/\|/g,"\\|").replace(/\r?\n/g,"<br>")}function ss(e){let t=jt(e,"tr"),r=t.map(a=>jt(a,"tc").map(i=>{let s=jt(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 ls(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=>is(l)).join(" | ")} |`;return[i(n),i(a),...o.map(i)].join(`
160
+ `)}function cs(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 Pa(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 us(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(!Pa(l))break;a.push(o),o=s}return a.length>1?a:null}function fs(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
+ `)||Lr(o))return null;let i=o.split(/\r?\n/g).map(P=>P.trim()).filter(Boolean);if(i.length<2)return null;let s=r.tableElement||Je(e,"tbl"),l=Je(e,"tr"),c=Je(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}=ss(s);if(f.length===0||g===0)return null;let d=p.indexOf(l),h=jt(l,"tc").indexOf(c);if(d<0||h<0||h>=g)return null;f[d][h]=i[0];let b=cs(f[d]);b&&n("[Table] Symmetric row detected; mirroring inserted row values across columns.");for(let P=1;P<i.length;P++){let v=d+P,E=i[P];if(v<f.length&&!_(f[v][h]))if(b)for(let N=0;N<g;N++)_(f[v][N])||(f[v][N]=E);else f[v][h]=E;else{let N=new Array(g).fill("");if(b)for(let y=0;y<g;y++)N[y]=E;else N[h]=E;f.splice(Math.min(v,f.length),0,N)}}let x=ls(f,g);return x?(n("[Table] Synthesized full markdown table from multiline cell edit for table-scope reconciliation."),x):null}function et(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 tt(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 ms(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=et(p,["w:abstractNumId","abstractNumId"]);g!=null&&o.add(g)}for(let p of f){let g=et(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:tt(l,a,n),nextAbstractNumId:tt(c,o,n),usedNumIds:a,usedAbstractNumIds:o,minId:r,maxPreferred:n}}function ps(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=tt(e.nextNumId,e.usedNumIds,e.maxPreferred),e.nextAbstractNumId=tt(e.nextAbstractNumId,e.usedAbstractNumIds,e.maxPreferred),e)}function ht(e,t="num"){let r=ps(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=tt(a+1,r.usedAbstractNumIds,r.maxPreferred)):(r.usedNumIds.add(a),r.nextNumId=tt(a+1,r.usedNumIds,r.maxPreferred)),a)}function gs(e){let t=ht(e,"num"),r=ht(e,"abstract");return t==null||r==null?null:{numId:t,abstractNumId:r}}function Xr(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:e.getElementsByTagName("parsererror").length>0}function Gt(e,t){return!!(e&&e.nodeType===1&&e.namespaceURI===se&&e.localName===t)}function Ea(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 ds(e,t){for(let r of t||[]){let n=e?.getAttribute?.(r);if(n!=null&&n!=="")return n}return null}function dt(e,t){let r=ds(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function Sa(e,t,r){e?.setAttribute?.(t,String(r))}function Dr(e,t){e?.setAttribute?.("w:val",String(t))}function hs(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)Dr(a,t)}}function ws(e){for(let t of e||[]){let r=Array.from(t?.getElementsByTagNameNS?.("*","numId")||[]);for(let n of r){let a=dt(n,["w:val","val"]);if(a!=null)return String(a)}}return null}function bs(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"/>
161
165
  <w:lvlText w:val="${c}"/>
162
166
  <w:lvlJc w:val="left"/>
163
- <w:pPr><w:ind w:left="${f}" w:hanging="360"/></w:pPr>
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 ho(e,t,r){let n=pe(e);if(lr(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 f=nt(c,["w:abstractNumId","abstractNumId"]);if(f==null)continue;let m=at(r,"abstract");m!=null&&(a.set(f,m),Rn(c,"w:abstractNumId",m))}let s=Array.from(n.getElementsByTagNameNS("*","num"));for(let c of s){let f=nt(c,["w:numId","numId"]);if(f==null)continue;let m=at(r,"num");if(m==null)continue;i.set(f,m),Rn(c,"w:numId",m);let u=Array.from(c.getElementsByTagNameNS("*","abstractNumId"))[0]||null;if(u){let p=nt(u,["w:val","val"]);p!=null&&a.has(p)&&cr(u,a.get(p))}}let l=Array.isArray(t)?t.map(c=>c?.cloneNode?c.cloneNode(!0):c):[];for(let c of l){let f=Array.from(c?.getElementsByTagNameNS?.("*","numId")||[]);for(let m of f){let u=nt(m,["w:val","val"]);u!=null&&i.has(u)&&cr(m,i.get(u))}}return{numberingXml:Oe(n),replacementNodes:l}}function wo(e,t){let r=String(e||""),n=String(t||"");if(!n.trim())return r;if(!r.trim())return n;try{let a=pe(r),i=pe(n);if(lr(a)||lr(i))return r;let o=a.documentElement,s=i.documentElement;if(!o||!s)return r;let l=new Set(Array.from(o.childNodes||[]).filter(f=>It(f,"abstractNum")).map(f=>He(f,["w:abstractNumId","abstractNumId"])).filter(f=>f!=null)),c=new Set(Array.from(o.childNodes||[]).filter(f=>It(f,"num")).map(f=>He(f,["w:numId","numId"])).filter(f=>f!=null));for(let f of Array.from(s.childNodes||[])){if(!It(f,"abstractNum"))continue;let m=He(f,["w:abstractNumId","abstractNumId"]);m==null||l.has(m)||(On(o,a.importNode(f,!0),"abstract"),l.add(m))}for(let f of Array.from(s.childNodes||[])){if(!It(f,"num"))continue;let m=He(f,["w:numId","numId"]);m==null||c.has(m)||(On(o,a.importNode(f,!0),"num"),c.add(m))}return Oe(a)}catch{return r}}function bo(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:!!U(e)}function Mn(e){let t=typeof e=="string"?e:String(e||"");if(!t.trim())return null;try{let n=B().parseFromString(t,"application/xml");return bo(n)?null:n}catch{return null}}function Ln(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 ur(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 ye(e,t){return Array.from(e?.getElementsByTagNameNS?.(I,t)||[])}function it(e,t){if(!e)return"";for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return""}function xo(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 No(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 vo(e){let t=ur(e,"rPr");if(!t)return{bold:!1,italic:!1};let r=ye(t,"rStyle")[0]||null,n=it(r,["w:val","val"]).toLowerCase(),a=n.includes("strong")||n.includes("bold"),i=n.includes("italic")||n.includes("emphasis");return{bold:ye(t,"b").length>0||a,italic:ye(t,"i").length>0||i}}function _n(e){let t=[],r=Array.from(e?.getElementsByTagNameNS?.(I,"r")||[]);for(let n of r){if(xo(n,"del",e))continue;let a=No(n);a&&t.push({text:a,...vo(n)})}return t}function fr(e){return String(e||"").replace(/\r/g,"").split(`
180
+ </w:numbering>`.trim()}function xs(e,t,r){let n=Ne(e);if(Xr(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=dt(c,["w:abstractNumId","abstractNumId"]);if(u==null)continue;let m=ht(r,"abstract");m!=null&&(a.set(u,m),Sa(c,"w:abstractNumId",m))}let s=Array.from(n.getElementsByTagNameNS("*","num"));for(let c of s){let u=dt(c,["w:numId","numId"]);if(u==null)continue;let m=ht(r,"num");if(m==null)continue;o.set(u,m),Sa(c,"w:numId",m);let f=Array.from(c.getElementsByTagNameNS("*","abstractNumId"))[0]||null;if(f){let p=dt(f,["w:val","val"]);p!=null&&a.has(p)&&Dr(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=dt(m,["w:val","val"]);f!=null&&o.has(f)&&Dr(m,o.get(f))}}return{numberingXml:De(n),replacementNodes:l}}function Ns(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(Xr(a)||Xr(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=>Gt(u,"abstractNum")).map(u=>et(u,["w:abstractNumId","abstractNumId"])).filter(u=>u!=null)),c=new Set(Array.from(i.childNodes||[]).filter(u=>Gt(u,"num")).map(u=>et(u,["w:numId","numId"])).filter(u=>u!=null));for(let u of Array.from(s.childNodes||[])){if(!Gt(u,"abstractNum"))continue;let m=et(u,["w:abstractNumId","abstractNumId"]);m==null||l.has(m)||(Ea(i,a.importNode(u,!0),"abstract"),l.add(m))}for(let u of Array.from(s.childNodes||[])){if(!Gt(u,"num"))continue;let m=et(u,["w:numId","numId"]);m==null||c.has(m)||(Ea(i,a.importNode(u,!0),"num"),c.add(m))}return De(a)}catch{return r}}function vs(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:!!j(e)}function Ia(e){let t=typeof e=="string"?e:String(e||"");if(!t.trim())return null;try{let n=B().parseFromString(t,"application/xml");return vs(n)?null:n}catch{return null}}function Aa(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 zr(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 wt(e,t){if(!e)return"";for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return""}function Ca(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 Ts(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 ys(e){let t=zr(e,"rPr");if(!t)return{bold:!1,italic:!1};let r=Re(t,"rStyle")[0]||null,n=wt(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 Ra(e){let t=[],r=Array.from(e?.getElementsByTagNameNS?.(S,"r")||[]);for(let n of r){if(Ca(n,"del",e)||Ca(n,"moveFrom",e))continue;let a=Ts(n);a&&t.push({text:a,...ys(n)})}return t}function Wr(e){return String(e||"").replace(/\r/g,"").split(`
178
182
  `).map(r=>r.replace(/[ \t]+/g," ").trim()).join(`
179
- `).trim()}function To(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 yo(e){let t=ur(e,"pPr");if(!t)return null;let r=ye(t,"pStyle")[0]||null,n=it(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=ye(t,"outlineLvl")[0]||null,i=it(a,["w:val","val"]),o=Number.parseInt(i,10);return Number.isInteger(o)&&o>=0?Math.min(o+1,6):null}function Eo(e){let t=ur(e,"pPr");if(!t)return null;let r=ye(t,"numPr")[0]||null;if(!r)return null;let n=ye(r,"ilvl")[0]||null,a=ye(r,"numId")[0]||null,i=Number.parseInt(it(n,["w:val","val"]),10),o=it(a,["w:val","val"]);return{level:Number.isInteger(i)&&i>=0?i:0,marker:o==="1"?"-":"1."}}function Po(e){let t=_n(e).map(r=>r.text).join("");return fr(t)}function So(e){let r=_n(e).map(o=>To(o.text,o)).join(""),n=fr(r);if(!n)return"";let a=yo(e);if(a!=null)return`${"#".repeat(a)} ${n}`;let i=Eo(e);return i?`${" ".repeat(i.level)}${i.marker} ${n}`:n}function Io(e){let t=Mn(e);if(!t)return"";let r=Ln(t);return r.length===0?fr(t.documentElement?.textContent||""):r.map(Po).join(`
183
+ `).trim()}function Ps(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 Es(e){let t=zr(e,"pPr");if(!t)return null;let r=Re(t,"pStyle")[0]||null,n=wt(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=wt(a,["w:val","val"]),i=Number.parseInt(o,10);return Number.isInteger(i)&&i>=0?Math.min(i+1,6):null}function Ss(e){let t=zr(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(wt(n,["w:val","val"]),10),i=wt(a,["w:val","val"]);return{level:Number.isInteger(o)&&o>=0?o:0,marker:i==="1"?"-":"1."}}function Cs(e){let t=Ra(e).map(r=>r.text).join("");return Wr(t)}function Is(e){let r=Ra(e).map(i=>Ps(i.text,i)).join(""),n=Wr(r);if(!n)return"";let a=Es(e);if(a!=null)return`${"#".repeat(a)} ${n}`;let o=Ss(e);return o?`${" ".repeat(o.level)}${o.marker} ${n}`:n}function As(e){let t=Ia(e);if(!t)return"";let r=Aa(t);return r.length===0?Wr(t.documentElement?.textContent||""):r.map(Cs).join(`
180
184
 
181
- `).trim()}function Ao(e){let t=Mn(e);if(!t)return"";let r=Ln(t);return r.length===0?"":r.map(So).join(`
185
+ `).trim()}function Rs(e){let t=Ia(e);if(!t)return"";let r=Aa(t);return r.length===0?"":r.map(Is).join(`
182
186
 
183
- `).trim()}function mr(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 Hr(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 pr(e){if(!e||e.length===0)return`<w:comments xmlns:w="${I}"></w:comments>`;let t=e.map(r=>mr(r.id,r.author,r.content,r.date)).join(`
188
- `);return`<w:comments xmlns:w="${I}">
191
+ </w:comment>`}function Ur(e){if(!e||e.length===0)return`<w:comments xmlns:w="${S}"></w:comments>`;let t=e.map(r=>Hr(r.id,r.author,r.content,r.date)).join(`
192
+ `);return`<w:comments xmlns:w="${S}">
189
193
  ${t}
190
- </w:comments>`}function At(e){let t=Y(e,"w:r"),r=[],n="";for(let a of t){let i=n.length,o=Y(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 ko(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:f}of e.runOffsets)r>=c&&r<f&&(a=l,o=r-c),n>c&&n<=f&&(i=l,s=n-c);return{found:!0,startRun:a,startOffset:o,endRun:i,endOffset:s}}function ot(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 Bn(e,t,r,n,a=null){let i=a||At(t),o=ko(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"),f=e.createElementNS(I,"w:commentReference");if(f.setAttribute("w:id",String(n)),c.appendChild(f),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(ot(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(ot(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(ot(e,h,d),o.startRun)}m.textContent=w}o.startRun.parentNode.insertBefore(s,o.startRun);let u=o.endRun||o.startRun,p=M(u,"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(u,"w:rPr");u.nextSibling?u.parentNode.insertBefore(ot(e,h,w),u.nextSibling):u.parentNode.appendChild(ot(e,h,w))}}return u.nextSibling?(u.parentNode.insertBefore(l,u.nextSibling),l.parentNode.insertBefore(c,l.nextSibling)):(u.parentNode.appendChild(l),u.parentNode.appendChild(c)),!0}var je="http://schemas.microsoft.com/office/2006/xmlPackage",st="http://schemas.openxmlformats.org/package/2006/relationships";function $n(e,t){let r=B(),n=J(),a=r.parseFromString(e,"text/xml"),i=U(a);if(i)return K("[CommentEngine] Failed to parse package:",i.textContent),e;let o=a.documentElement,s=a.createElementNS(je,"pkg:part");s.setAttribute("pkg:name","/word/comments.xml"),s.setAttribute("pkg:contentType","application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml");let l=a.createElementNS(je,"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,je,"part").find(u=>u.getAttribute("pkg:name")==="/word/_rels/document.xml.rels");if(m){let u=z(m,je,"xmlData");if(u.length>0){let p=z(u[0],st,"Relationships");if(p.length>0){let g=p[0],d=z(g,st,"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(st,"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 u=a.createElementNS(je,"pkg:part");u.setAttribute("pkg:name","/word/_rels/document.xml.rels"),u.setAttribute("pkg:contentType","application/vnd.openxmlformats-package.relationships+xml");let p=a.createElementNS(je,"pkg:xmlData"),g=a.createElementNS(st,"Relationships"),d=a.createElementNS(st,"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),u.appendChild(p),o.appendChild(u)}return n.serializeToString(a)}function Co(e,t,r){try{let n=t.parseFromString(e,"text/xml"),a=U(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 Oo(e,t,r={}){let n=r?.author||G(),a=ae(),i=[],o=[];if(!t||t.length===0)return{oxml:e,commentsApplied:0,warnings:["No comments to inject"]};let s=B(),l=J(),c=Co(e,s,g=>`Failed to parse OXML: ${g}`);if(!c.xmlDoc)return K("[CommentEngine] Parse failure:",c.warning),{oxml:e,commentsApplied:0,warnings:[c.warning]};let f=c.xmlDoc,m=Y(f,"w:p");A(`[CommentEngine] Found ${m.length} paragraphs, processing ${t.length} comment requests`);let u=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}u.set(d,(u.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=At(w),p.set(d,h));let x=be(),v=Bn(f,w,g.textToFind,x,h),T=(u.get(d)||1)-1;if(u.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,At(w)):p.delete(d)}return o.length===0?{oxml:e,commentsApplied:0,warnings:i}:{oxml:l.serializeToString(f),commentsXml:pr(o),commentsApplied:o.length,warnings:i}}function Ro(e,t){return $n(e,t)}function Fn(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 Mo(e,t,r){if(!t||!e)return e;let n=pe(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"),f=Array.from(c).map(m=>m.textContent).join("");if(f.includes(t)||f===t){let m=l.getElementsByTagNameNS(a,"rPr");if(m.length>0){let u=m[0],p=Fn(u,r);p?u.parentNode&&u.parentNode.replaceChild(p,u):u.remove()}}}return Oe(n)}var Lo={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 _o(e,t,r="yellow",n={}){let a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",i=Lo[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(u=>{u.nodeName!=="w:rPrChange"&&c.appendChild(u.cloneNode(!0))}));let f=l.getElementsByTagNameNS(a,"highlight");Array.from(f).forEach(u=>u.remove());let m=e.createElementNS(a,"w:highlight");if(m.setAttributeNS(a,"w:val",i),l.appendChild(m),o&&c){let u=e.createElementNS(a,"w:rPrChange");u.setAttributeNS(a,"w:id",Math.floor(Math.random()*9999999).toString()),u.setAttributeNS(a,"w:author",s),u.setAttributeNS(a,"w:date",new Date().toISOString()),u.appendChild(c);let p=l.getElementsByTagNameNS(a,"rPrChange");Array.from(p).forEach(g=>g.remove()),l.appendChild(u)}return l}function Bo(e,t,r="yellow",n={}){if(!t||!e)return e;let a=pe(e),i="http://schemas.openxmlformats.org/wordprocessingml/2006/main",o=l=>{let c=l.getElementsByTagNameNS(i,"t");return Array.from(c).map(f=>f.textContent).join("")},s=Array.from(a.getElementsByTagNameNS(i,"r"));for(let l=0;l<s.length;l++){let c=s[l],f=o(c);if(!f)continue;let m=f.indexOf(t);if(m===-1)continue;let u=c.parentNode;if(!u){console.warn("[Highlight] Run parent is null; skipping. Likely already processed.");continue}let p=f.substring(0,m),g=f.substring(m,m+t.length),d=f.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=_o(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)}u.replaceChild(w,c)}return Oe(a)}var Q="http://schemas.openxmlformats.org/wordprocessingml/2006/main",$o="http://schemas.openxmlformats.org/package/2006/content-types",Fo="http://schemas.openxmlformats.org/package/2006/relationships",Dn="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",zn="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",Wn="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",Hn="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",Xn="word/document.xml",kt="word/numbering.xml",lt="word/comments.xml",Re="[Content_Types].xml",Me="word/_rels/document.xml.rels";function Ee(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 Ct(e){return!!e&&e.nodeType===1&&e.namespaceURI===Q&&e.localName==="sectPr"}function dr(e){return e.getElementsByTagNameNS("*","body")[0]||null}function Un(e){for(let t of Array.from(e.childNodes||[]))if(Ct(t))return t;return null}function Xo(e,t){let r=Un(e);r?e.insertBefore(t,r):e.appendChild(t)}function jn(e){let t=dr(e);if(!t)return;let r=Un(t);if(!r)return;let n=r.nextSibling;for(;n;){let a=n.nextSibling;n.nodeType===1&&t.insertBefore(n,r),n=a}}function Do(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 gr(e){return e.getAttribute("pkg:name")||e.getAttribute("name")||""}function zo(e){let t=B(),r=J(),n=t.parseFromString(e,"application/xml"),a=Array.from(n.getElementsByTagNameNS("*","part")),i=a.find(u=>gr(u)==="/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(u=>u.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(u=>u.nodeType===1&&!Ct(u)):[s],f=a.find(u=>gr(u)==="/word/numbering.xml"),m=null;if(f){let u=f.getElementsByTagNameNS("*","xmlData")[0],p=u?Array.from(u.childNodes||[]).find(g=>g.nodeType===1):null;p&&(m=r.serializeToString(p))}return{replacementNodes:c,numberingXml:m,sourceType:"package"}}function Wo(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 zo(e);if(e.includes("<w:document")){let o=B().parseFromString(e,"application/xml"),s=o.getElementsByTagNameNS("*","body")[0];return{replacementNodes:s?Array.from(s.childNodes||[]).filter(c=>c.nodeType===1&&!Ct(c)):Array.from(o.childNodes||[]).filter(c=>c.nodeType===1),numberingXml:null,sourceType:"document"}}let t=`<root xmlns:w="${Q}">${e}</root>`,n=B().parseFromString(t,"application/xml");return{replacementNodes:Array.from(n.documentElement.childNodes||[]).filter(i=>i.nodeType===1),numberingXml:null,sourceType:"fragment"}}function Gn(e,t,r){if(Array.from(e.getElementsByTagNameNS("*","Override")).some(o=>(o.getAttribute("PartName")||"").toLowerCase()===String(t).toLowerCase()))return!1;let i=e.createElementNS($o,"Override");return i.setAttribute("PartName",t),i.setAttribute("ContentType",r),e.documentElement.appendChild(i),!0}function Kn(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")||"",f=Number.parseInt(c.replace(/^rId/i,""),10);Number.isFinite(f)&&(o=Math.max(o,f))}let s=e.createElementNS(Fo,"Relationship");return s.setAttribute("Id",`rId${o+1}`),s.setAttribute("Type",t),s.setAttribute("Target",r),n.appendChild(s),!0}async function le(e,t){let r=e.file(t);return r?r.async("string"):null}async function Ho(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 le(e,kt),s=o||null;for(let u of i){if(!s){s=u;continue}s=a?a(s,u):u}n(o?"[Demo] Merging numbering.xml payload(s) into existing numbering definitions":"[Demo] Adding numbering.xml"),e.file(kt,s);let l=B(),c=J(),f=await le(e,Re);if(f){let u=l.parseFromString(f,"application/xml");Gn(u,"/word/numbering.xml",zn)&&e.file(Re,c.serializeToString(u))}let m=await le(e,Me);if(m){let u=l.parseFromString(m,"application/xml");Kn(u,Dn,"numbering.xml")&&e.file(Me,c.serializeToString(u))}}async function Uo(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{};if(!t)return;let a=B(),i=J(),o=await le(e,lt);if(!o)n("[Demo] Adding comments.xml"),e.file(lt,t);else{let c=Ee(o,"word/comments.xml (existing)"),f=Ee(t,"word/comments.xml (incoming)"),m=c.documentElement,u=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(f.documentElement.getElementsByTagNameNS(Q,"comment"))){let g=p.getAttribute("w:id")||p.getAttribute("id");if(g&&u.has(g))throw new Error(`Duplicate comment id: ${g}`);m.appendChild(c.importNode(p,!0))}e.file(lt,i.serializeToString(c))}let s=await le(e,Re);if(s){let c=a.parseFromString(s,"application/xml");Gn(c,"/word/comments.xml",Hn)&&e.file(Re,i.serializeToString(c))}let l=await le(e,Me);if(l){let c=a.parseFromString(l,"application/xml");Kn(c,Wn,"comments.xml")&&e.file(Me,i.serializeToString(c))}}async function jo(e){let t=await le(e,Xn);if(!t)throw new Error("Validation failed: missing word/document.xml");let r=Ee(t,Xn);jn(r);let n=dr(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=>Ct(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 le(e,kt),f=await le(e,lt);if(c)Ee(c,kt);else if(s)throw new Error("Validation failed: numbering used but part missing");if(f)Ee(f,lt);else if(l)throw new Error("Validation failed: comments used but part missing");let m=await le(e,Re);if(!m)throw new Error(`Validation failed: missing ${Re}`);let u=Ee(m,Re),p=await le(e,Me);if(!p)throw new Error(`Validation failed: missing ${Me}`);let g=Ee(p,Me);if(c){let d=Array.from(u.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/numbering.xml"&&(h.getAttribute("ContentType")||"")===zn),w=Array.from(g.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===Dn);if(!d)throw new Error("Validation failed: numbering CT override missing");if(!w)throw new Error("Validation failed: numbering rel missing")}if(f){let d=Array.from(u.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/comments.xml"&&(h.getAttribute("ContentType")||"")===Hn),w=Array.from(g.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===Wn);if(!d)throw new Error("Validation failed: comments CT override missing");if(!w)throw new Error("Validation failed: comments rel missing")}}var Ge=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 Zn(e){return!e||typeof e!="string"?e||"":e.replace(/\\n/g,`
191
- `).replace(/\\t/g," ").replace(/\\r/g,"\r")}function Go(e={}){let t=e.originalText||"",r=Zn(e.newContent||""),n=rt(r)||{type:"text",items:[]};return r.includes(`
192
- `)&&n.type!=="text"?{kind:Ge.STRUCTURED_LIST_DIRECT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!0,isOriginalEmpty:Vn(t),hasInlineFormatting:Ot(r),hasBlockElements:Rt(r),hasMarkdownTable:ct(r)}}:Vn(t)?Ot(r)?{kind:Ge.EMPTY_FORMATTED_TEXT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!0,hasBlockElements:Rt(r),hasMarkdownTable:ct(r)}}:{kind:Ge.EMPTY_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!1,hasBlockElements:Rt(r),hasMarkdownTable:ct(r)}}:Rt(r)?{kind:Ge.BLOCK_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:Ot(r),hasBlockElements:!0,hasMarkdownTable:ct(r)}}:{kind:Ge.OOXML_ENGINE,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:Ot(r),hasBlockElements:!1,hasMarkdownTable:ct(r)}}}function Vn(e){return!e||e.trim().length===0}function ct(e){if(!e||!e.includes("|"))return!1;let t=oe(e);return t.rows.length>0||t.headers.length>0}function Ot(e){return e?/(\*\*.+?\*\*|\*.+?\*|__.+?__|_.+?_|`.+?`|~~.+?~~|\+\+.+?\+\+)/.test(e):!1}function Rt(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 Vt(e){let t=Ee(e,"w:r"),r=[],n="";for(let a of t){let o=n.length,i=Ee(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 ks(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 bt(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 ka(e,t,r,n,a=null){let o=a||Vt(t),i=ks(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),P=$(g,"w:rPr"),v=g.parentNode;return h&&v.insertBefore(bt(e,P,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(bt(e,P,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(bt(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(bt(e,h,w),f.nextSibling):f.parentNode.appendChild(bt(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 rt="http://schemas.microsoft.com/office/2006/xmlPackage",xt="http://schemas.openxmlformats.org/package/2006/relationships";function Oa(e,t){let r=B(),n=Q(),a=r.parseFromString(e,"text/xml"),o=j(a);if(o)return Y("[CommentEngine] Failed to parse package:",o.textContent),e;let i=a.documentElement,s=a.createElementNS(rt,"pkg:part");s.setAttribute("pkg:name","/word/comments.xml"),s.setAttribute("pkg:contentType","application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml");let l=a.createElementNS(rt,"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,rt,"part").find(f=>f.getAttribute("pkg:name")==="/word/_rels/document.xml.rels");if(m){let f=V(m,rt,"xmlData");if(f.length>0){let p=V(f[0],xt,"Relationships");if(p.length>0){let g=p[0],d=V(g,xt,"Relationship");if(!d.some(h=>h.getAttribute("Type")?.includes("comments"))){let h=0;d.forEach(x=>{let P=x.getAttribute("Id"),v=parseInt(P?.replace("rId","")||"0",10);v>h&&(h=v)});let b=a.createElementNS(xt,"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(rt,"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(rt,"pkg:xmlData"),g=a.createElementNS(xt,"Relationships"),d=a.createElementNS(xt,"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 Os(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 Ms(e,t,r={}){let n=r?.author||J(),a=ar(),o=[],i=[];if(!t||t.length===0)return{oxml:e,commentsApplied:0,warnings:["No comments to inject"]};let s=B(),l=Q(),c=Os(e,s,g=>`Failed to parse OXML: ${g}`);if(!c.xmlDoc)return Y("[CommentEngine] Parse failure:",c.warning),{oxml:e,commentsApplied:0,warnings:[c.warning]};let u=c.xmlDoc,m=Ee(u,"w:p");I(`[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=Vt(w),p.set(d,h));let b=nr(),x=ka(u,w,g.textToFind,b,h),P=(f.get(d)||1)-1;if(f.set(d,P),!x){o.push(`Could not find "${g.textToFind.substring(0,30)}..." in paragraph ${g.paragraphIndex}`),P===0&&p.delete(d);continue}i.push({id:b,content:g.commentContent,author:n,date:a}),P>0?p.set(d,Vt(w)):p.delete(d)}return i.length===0?{oxml:e,commentsApplied:0,warnings:o}:{oxml:l.serializeToString(u),commentsXml:Ur(i),commentsApplied:i.length,warnings:o}}function Ls(e,t){return Oa(e,t)}function Ma(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 _s(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=Ma(f,r);p?f.parentNode&&f.parentNode.replaceChild(p,f):f.remove()}}}return De(n)}var Bs={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 Fs(e,t,r="yellow",n={}){let a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",o=Bs[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 $s(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(P=>P.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 P=h.getElementsByTagNameNS(o,"rPr"),v=P.length>0?P[0]:null,E=Fs(a,v,r,n);v?h.replaceChild(E,v):h.insertBefore(E,h.firstChild),w.appendChild(h)}if(d.length>0){let h=c.cloneNode(!0),b=h.getElementsByTagNameNS(o,"t");Array.from(b).forEach(P=>P.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",Xs="http://schemas.openxmlformats.org/package/2006/content-types",Ds="http://schemas.openxmlformats.org/package/2006/relationships",_a="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",Ba="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",Fa="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",$a="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",La="word/document.xml",Kt="word/numbering.xml",Nt="word/comments.xml",ze="[Content_Types].xml",We="word/_rels/document.xml.rels";function ke(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 Zt(e){return!!e&&e.nodeType===1&&e.namespaceURI===ae&&e.localName==="sectPr"}function Gr(e){return e.getElementsByTagNameNS("*","body")[0]||null}function Xa(e){for(let t of Array.from(e.childNodes||[]))if(Zt(t))return t;return null}function zs(e,t){let r=Xa(e);r?e.insertBefore(t,r):e.appendChild(t)}function Da(e){let t=Gr(e);if(!t)return;let r=Xa(t);if(!r)return;let n=r.nextSibling;for(;n;){let a=n.nextSibling;n.nodeType===1&&t.insertBefore(n,r),n=a}}function Ws(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 jr(e){return e.getAttribute("pkg:name")||e.getAttribute("name")||""}function Hs(e){let t=B(),r=Q(),n=t.parseFromString(e,"application/xml"),a=Array.from(n.getElementsByTagNameNS("*","part")),o=a.find(f=>jr(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&&!Zt(f)):[s],u=a.find(f=>jr(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 Us(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 Hs(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&&!Zt(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 za(e,t,r){if(Array.from(e.getElementsByTagNameNS("*","Override")).some(i=>(i.getAttribute("PartName")||"").toLowerCase()===String(t).toLowerCase()))return!1;let o=e.createElementNS(Xs,"Override");return o.setAttribute("PartName",t),o.setAttribute("ContentType",r),e.documentElement.appendChild(o),!0}function Wa(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(Ds,"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 js(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,Kt),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(Kt,s);let l=B(),c=Q(),u=await pe(e,ze);if(u){let f=l.parseFromString(u,"application/xml");za(f,"/word/numbering.xml",Ba)&&e.file(ze,c.serializeToString(f))}let m=await pe(e,We);if(m){let f=l.parseFromString(m,"application/xml");Wa(f,_a,"numbering.xml")&&e.file(We,c.serializeToString(f))}}async function Gs(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{};if(!t)return;let a=B(),o=Q(),i=await pe(e,Nt);if(!i)n("[Demo] Adding comments.xml"),e.file(Nt,t);else{let c=ke(i,"word/comments.xml (existing)"),u=ke(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(Nt,o.serializeToString(c))}let s=await pe(e,ze);if(s){let c=a.parseFromString(s,"application/xml");za(c,"/word/comments.xml",$a)&&e.file(ze,o.serializeToString(c))}let l=await pe(e,We);if(l){let c=a.parseFromString(l,"application/xml");Wa(c,Fa,"comments.xml")&&e.file(We,o.serializeToString(c))}}async function Vs(e){let t=await pe(e,La);if(!t)throw new Error("Validation failed: missing word/document.xml");let r=ke(t,La);Da(r);let n=Gr(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=>Zt(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,Kt),u=await pe(e,Nt);if(c)ke(c,Kt);else if(s)throw new Error("Validation failed: numbering used but part missing");if(u)ke(u,Nt);else if(l)throw new Error("Validation failed: comments used but part missing");let m=await pe(e,ze);if(!m)throw new Error(`Validation failed: missing ${ze}`);let f=ke(m,ze),p=await pe(e,We);if(!p)throw new Error(`Validation failed: missing ${We}`);let g=ke(p,We);if(c){let d=Array.from(f.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/numbering.xml"&&(h.getAttribute("ContentType")||"")===Ba),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")||"")===$a),w=Array.from(g.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===Fa);if(!d)throw new Error("Validation failed: comments CT override missing");if(!w)throw new Error("Validation failed: comments rel missing")}}var nt=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 Ua(e){return!e||typeof e!="string"?e||"":e.replace(/\\n/g,`
195
+ `).replace(/\\t/g," ").replace(/\\r/g,"\r")}function Ks(e={}){let t=e.originalText||"",r=Ua(e.newContent||""),n=gt(r)||{type:"text",items:[]};return r.includes(`
196
+ `)&&n.type!=="text"?{kind:nt.STRUCTURED_LIST_DIRECT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!0,isOriginalEmpty:Ha(t),hasInlineFormatting:Yt(r),hasBlockElements:Jt(r),hasMarkdownTable:vt(r)}}:Ha(t)?Yt(r)?{kind:nt.EMPTY_FORMATTED_TEXT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!0,hasBlockElements:Jt(r),hasMarkdownTable:vt(r)}}:{kind:nt.EMPTY_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!1,hasBlockElements:Jt(r),hasMarkdownTable:vt(r)}}:Jt(r)?{kind:nt.BLOCK_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:Yt(r),hasBlockElements:!0,hasMarkdownTable:vt(r)}}:{kind:nt.OOXML_ENGINE,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:Yt(r),hasBlockElements:!1,hasMarkdownTable:vt(r)}}}function Ha(e){return!e||e.trim().length===0}function vt(e){if(!e||!e.includes("|"))return!1;let t=me(e);return t.rows.length>0||t.headers.length>0}function Yt(e){return e?/(\*\*.+?\*\*|\*.+?\*|__.+?__|_.+?_|`.+?`|~~.+?~~|\+\+.+?\+\+)/.test(e):!1}function Jt(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 Ko(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 Yn(e,t,r,n={}){let a=await qt(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 cf(e,t,r,n={}){let a=typeof e=="string"?e:"",i=typeof r=="string"?r:String(r||""),o;try{o=oe(i)}catch{o={headers:[],rows:[]}}return(o?.headers?.length||0)>0||(o?.rows?.length||0)>0?{...await Yn(a,t||"",i,n),isMarkdownTable:!0,tableData:o}:{oxml:a,hasChanges:!1,isMarkdownTable:!1,warnings:["Could not parse Markdown table from input."]}}async function uf(e,t,r,n={}){let a=n.listFallbackAllowExistingList!==!1,i=sr({oxml:e,originalText:t,modifiedText:r,allowExistingList:a}),o=n.preferListStructuralFallback!==!1,s=[];if(i&&o){let p=await Pt(i,{author:n.author,generateRedlines:n.generateRedlines,pipeline:n.listFallbackPipeline});if(p?.hasChanges&&p?.oxml){let g=Ne(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 Yn(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 Pt(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 f=Ne(c.oxml,{includeNumbering:c.includeNumbering??!0,numberingXml:c.numberingXml}),m=Array.isArray(l?.warnings)?l.warnings:[],u=Array.isArray(c?.warnings)?c.warnings:[];return{...l,oxml:f,hasChanges:!0,warnings:[...m,...s,...u],listStructuralFallbackApplied:!0,listStructuralFallbackKey:c.listStructuralFallbackKey||null,listStructuralFallbackNumberingXml:c.numberingXml||null}}export{Le as ContainerKind,Er as ContentType,re as DiffOp,I as NS_W,Je as NumberingService,Ce as ReconciliationPipeline,Ge as RoutePlanKind,C as RunKind,te as WORD_MAIN_NS,Mo as applyFormattingRemovalToOoxml,Bo as applyHighlightToOoxml,Yn as applyRedlineToOxml,uf as applyRedlineToOxmlWithListFallback,mr as buildCommentElement,pr as buildCommentsPartXml,go as buildExplicitDecimalMultilevelNumberingXml,Wi as buildListMarkdown,Go as buildReconciliationPlan,sr as buildSingleLineListStructuralFallbackPlan,Li as buildTargetReferenceSnapshot,Zi as clearSingleLineListFallbackExplicitSequence,Sn as collectContiguousListParagraphBlock,la as configureLogger,ia as configureXmlProvider,lo as createDynamicNumberingIdState,Yi as enforceListBindingOnParagraphNodes,Uo as ensureCommentsArtifactsInZip,Ho as ensureNumberingArtifactsInZip,ee as escapeXml,Pt as executeSingleLineListStructuralFallback,po as extractFirstParagraphNumId,Ko as extractParagraphIdFromOoxml,Wo as extractReplacementNodesFromOoxml,De as findContainingWordElement,tr as findParagraphByBestTextMatch,bn as findParagraphByReference,vt as findParagraphByStrictText,ke as generateTableOoxml,dr as getBodyElementFromDocument,G as getDefaultAuthor,ge as getDocumentParagraphNodes,gr as getPackagePartName,de as getParagraphListInfo,W as getParagraphText,Bt as getPlatform,ir as hasListItems,or as inferNumberingStyleFromMarker,oo as inferTableReplacementParagraphBlock,gt as ingestOoxml,Ao as ingestWordOoxmlToMarkdown,Io as ingestWordOoxmlToPlainText,Oo as injectCommentsIntoOoxml,Ro as injectCommentsIntoPackage,Xo as insertBodyElementBeforeSectPr,Cn as isLikelyStructuredTableSourceParagraph,nr as isMarkdownTableText,wo as mergeNumberingXmlBySchemaOrder,jn as normalizeBodySectionOrderStandalone,Zn as normalizeContentEscapesForRouting,Hi as normalizeListItemsWithLevels,L as normalizeWhitespaceForTargeting,mo as overwriteParagraphNumIds,rt as parseMarkdownListContent,pe as parseOoxml,ar as parseParagraphReference,Ee as parseXmlStrictStandalone,zi as planListInsertionOnlyEdit,q as preprocessMarkdown,cf as reconcileMarkdownTableOoxml,Vi as recordSingleLineListFallbackExplicitSequence,ho as remapNumberingPayloadForDocument,Fn as removeFormattingFromRPr,at as reserveNextNumberingId,uo as reserveNextNumberingIdPair,_i as resolveParagraphRangeByRefs,Ki as resolveSingleLineListFallbackNumberingAction,xn as resolveTargetParagraph,rr as resolveTargetParagraphWithSnapshot,wn as sanitizeAiResponse,Do as sanitizeNestedParagraphsInTables,Oe as serializeOoxml,ie as serializeToOoxml,ca as setDefaultAuthor,ua as setPlatform,Oi as splitLeadingParagraphMarker,Ci as stripLeadingParagraphMarker,En as stripRedundantLeadingListMarkers,ji as stripSingleLineListMarkerPrefix,Di as synthesizeExpandedListScopeEdit,so as synthesizeTableMarkdownFromMultilineCellEdit,jo as validateDocxPackage,Ne as wrapInDocumentFragment};
198
+ `);return t||r||n||a||o||i||s||l||c}function Zs(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 ja(e,t,r,n={}){let a=await Ar(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 Um(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 ja(a,t||"",o,n),isMarkdownTable:!0,tableData:i}:{oxml:a,hasChanges:!1,isMarkdownTable:!1,warnings:["Could not parse Markdown table from input."]}}async function jm(e,t,r,n={}){let a=n.listFallbackAllowExistingList!==!1,o=$r({oxml:e,originalText:t,modifiedText:r,allowExistingList:a}),i=n.preferListStructuralFallback!==!1,s=[];if(o&&i){let p=await Ut(o,{author:n.author,generateRedlines:n.generateRedlines,pipeline:n.listFallbackPipeline});if(p?.hasChanges&&p?.oxml){let g=Ce(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 ja(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 Ut(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=Ce(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{He as ContainerKind,tn as ContentType,ce as DiffOp,S as NS_W,st as NumberingService,Be as ReconciliationPipeline,nt as RoutePlanKind,k as RunKind,se as WORD_MAIN_NS,Ir as acceptTrackedChangesInOoxml,_s as applyFormattingRemovalToOoxml,$s as applyHighlightToOoxml,ja as applyRedlineToOxml,jm as applyRedlineToOxmlWithListFallback,Hr as buildCommentElement,Ur as buildCommentsPartXml,bs as buildExplicitDecimalMultilevelNumberingXml,Gi as buildListMarkdown,Ks as buildReconciliationPlan,$r as buildSingleLineListStructuralFallbackPlan,$i as buildTargetReferenceSnapshot,Qi as clearSingleLineListFallbackExplicitSequence,Na as collectContiguousListParagraphBlock,no as configureLogger,eo as configureXmlProvider,dr as containsTrackedChanges,ms as createDynamicNumberingIdState,ki as deleteCommentsByAuthorInOoxml,es as enforceListBindingOnParagraphNodes,Gs as ensureCommentsArtifactsInZip,js as ensureNumberingArtifactsInZip,oe as escapeXml,Ut as executeSingleLineListStructuralFallback,ws as extractFirstParagraphNumId,Zs as extractParagraphIdFromOoxml,Us as extractReplacementNodesFromOoxml,Je as findContainingWordElement,Or as findParagraphByBestTextMatch,ma as findParagraphByReference,Dt as findParagraphByStrictText,_e as generateTableOoxml,Gr as getBodyElementFromDocument,J as getDefaultAuthor,ve as getDocumentParagraphNodes,jr as getPackagePartName,Te as getParagraphListInfo,G as getParagraphText,tr as getPlatform,Br as hasListItems,Fr as inferNumberingStyleFromMarker,us as inferTableReplacementParagraphBlock,It as ingestOoxml,Rs as ingestWordOoxmlToMarkdown,As as ingestWordOoxmlToPlainText,Ms as injectCommentsIntoOoxml,Ls as injectCommentsIntoPackage,zs as insertBodyElementBeforeSectPr,Pa as isLikelyStructuredTableSourceParagraph,Lr as isMarkdownTableText,Ns as mergeNumberingXmlBySchemaOrder,Da as normalizeBodySectionOrderStandalone,Ua as normalizeContentEscapesForRouting,Vi as normalizeListItemsWithLevels,_ as normalizeWhitespaceForTargeting,hs as overwriteParagraphNumIds,gt as parseMarkdownListContent,Ne as parseOoxml,_r as parseParagraphReference,ke as parseXmlStrictStandalone,ji as planListInsertionOnlyEdit,ne as preprocessMarkdown,Um as reconcileMarkdownTableOoxml,qi as recordSingleLineListFallbackExplicitSequence,Si as rejectTrackedChangesInOoxml,xs as remapNumberingPayloadForDocument,Ma as removeFormattingFromRPr,ht as reserveNextNumberingId,gs as reserveNextNumberingIdPair,Xi as resolveParagraphRangeByRefs,Ji as resolveSingleLineListFallbackNumberingAction,pa as resolveTargetParagraph,Mr as resolveTargetParagraphWithSnapshot,fa as sanitizeAiResponse,Ws as sanitizeNestedParagraphsInTables,De as serializeOoxml,fe as serializeToOoxml,ao as setDefaultAuthor,oo as setPlatform,_i as splitLeadingParagraphMarker,Li as stripLeadingParagraphMarker,ba as stripRedundantLeadingListMarkers,Zi as stripSingleLineListMarkerPrefix,Ui as synthesizeExpandedListScopeEdit,fs as synthesizeTableMarkdownFromMultilineCellEdit,Vs as validateDocxPackage,Ce as wrapInDocumentFragment};
195
199
  //# sourceMappingURL=docx-redline-js.esm.min.js.map