@ansonlai/docx-redline-js 0.1.6 → 0.2.1

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.
@@ -1,16 +1,16 @@
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}">
1
+ var Ya=Object.create;var Qr=Object.defineProperty;var Za=Object.getOwnPropertyDescriptor;var Ja=Object.getOwnPropertyNames;var qa=Object.getPrototypeOf,Qa=Object.prototype.hasOwnProperty;var eo=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}};var to=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Ja(t))!Qa.call(e,a)&&a!==r&&Qr(e,a,{get:()=>t[a],enumerable:!(n=Za(t,a))||n.enumerable});return e};var ro=(e,t,r)=>(r=e!=null?Ya(qa(e)):{},to(t||!e||!e.__esModule?Qr(r,"default",{value:e,enumerable:!0}):r,e));var mn=eo((Ol,Ye)=>{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,z=1,k=0;T.Diff=function(e,t){return[e,t]};T.prototype.diff_main=function(e,t,r,n){typeof n>"u"&&(this.Diff_Timeout<=0?n=Number.MAX_VALUE:n=new Date().getTime()+this.Diff_Timeout*1e3);var a=n;if(e==null||t==null)throw new Error("Null input. (diff_main)");if(e==t)return e?[new T.Diff(k,e)]:[];typeof r>"u"&&(r=!0);var o=r,i=this.diff_commonPrefix(e,t),s=e.substring(0,i);e=e.substring(i),t=t.substring(i),i=this.diff_commonSuffix(e,t);var l=e.substring(e.length-i);e=e.substring(0,e.length-i),t=t.substring(0,t.length-i);var c=this.diff_compute_(e,t,o,a);return s&&c.unshift(new T.Diff(k,s)),l&&c.push(new T.Diff(k,l)),this.diff_cleanupMerge(c),c};T.prototype.diff_compute_=function(e,t,r,n){var a;if(!e)return[new T.Diff(z,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(z,o.substring(0,s)),new T.Diff(k,i),new T.Diff(z,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(z,t)];var l=this.diff_halfMatch_(e,t);if(l){var c=l[0],u=l[1],m=l[2],f=l[3],p=l[4],g=this.diff_main(c,m,r,n),d=this.diff_main(u,f,r,n);return g.concat([new T.Diff(k,p)],d)}return r&&e.length>100&&t.length>100?this.diff_lineMode_(e,t,n):this.diff_bisect_(e,t,n)};T.prototype.diff_lineMode_=function(e,t,r){var n=this.diff_linesToChars_(e,t);e=n.chars1,t=n.chars2;var a=n.lineArray,o=this.diff_main(e,t,!1,r);this.diff_charsToLines_(o,a),this.diff_cleanupSemantic(o),o.push(new T.Diff(k,""));for(var i=0,s=0,l=0,c="",u="";i<o.length;){switch(o[i][0]){case z:l++,u+=o[i][1];break;case D:s++,c+=o[i][1];break;case k:if(s>=1&&l>=1){o.splice(i-s-l,s+l),i=i-s-l;for(var m=this.diff_main(c,u,!1,r),f=m.length-1;f>=0;f--)o.splice(i,0,m[f]);i=i+m.length}l=0,s=0,c="",u="";break}i++}return o.pop(),o};T.prototype.diff_bisect_=function(e,t,r){for(var n=e.length,a=t.length,o=Math.ceil((n+a)/2),i=o,s=2*o,l=new Array(s),c=new Array(s),u=0;u<s;u++)l[u]=-1,c[u]=-1;l[i+1]=0,c[i+1]=0;for(var m=n-a,f=m%2!=0,p=0,g=0,d=0,w=0,h=0;h<o&&!(new Date().getTime()>r);h++){for(var b=-h+p;b<=h-g;b+=2){var x=i+b,P;b==-h||b!=h&&l[x-1]<l[x+1]?P=l[x+1]:P=l[x-1]+1;for(var N=P-b;P<n&&N<a&&e.charAt(P)==t.charAt(N);)P++,N++;if(l[x]=P,P>n)g+=2;else if(N>a)p+=2;else if(f){var v=i+m-b;if(v>=0&&v<s&&c[v]!=-1){var y=n-c[v];if(P>=y)return this.diff_bisectSplit_(e,t,P,N,r)}}}for(var E=-h+d;E<=h-w;E+=2){var v=i+E,y;E==-h||E!=h&&c[v-1]<c[v+1]?y=c[v+1]:y=c[v-1]+1;for(var I=y-E;y<n&&I<a&&e.charAt(n-y-1)==t.charAt(a-I-1);)y++,I++;if(c[v]=y,y>n)w+=2;else if(I>a)d+=2;else if(!f){var x=i+m-E;if(x>=0&&x<s&&l[x]!=-1){var P=l[x],N=i+P-x;if(y=n-y,P>=y)return this.diff_bisectSplit_(e,t,P,N,r)}}}}return[new T.Diff(D,e),new T.Diff(z,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,N,v,y;(b=d.indexOf(h,b+1))!=-1;){var E=a.diff_commonPrefix(g.substring(w),d.substring(b)),I=a.diff_commonSuffix(g.substring(0,w),d.substring(0,b));x.length<I+E&&(x=d.substring(b-I,b)+d.substring(b,b+E),P=g.substring(0,w-I),N=g.substring(w+E),v=d.substring(0,b-I),y=d.substring(b+E))}return x.length*2>=g.length?[P,N,v,y,x]:null}var i=o(r,n,Math.ceil(r.length/4)),s=o(r,n,Math.ceil(r.length/2)),l;if(!i&&!s)return null;s?i?l=i[4].length>s[4].length?i:s:l=s:l=i;var c,u,m,f;e.length>t.length?(c=l[0],u=l[1],m=l[2],f=l[3]):(m=l[0],f=l[1],c=l[2],u=l[3]);var p=l[4];return[c,u,m,f,p]};T.prototype.diff_cleanupSemantic=function(e){for(var t=!1,r=[],n=0,a=null,o=0,i=0,s=0,l=0,c=0;o<e.length;)e[o][0]==k?(r[n++]=o,i=l,s=c,l=0,c=0,a=e[o][1]):(e[o][0]==z?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]=z,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]==z){var u=e[o-1][1],m=e[o][1],f=this.diff_commonOverlap_(u,m),p=this.diff_commonOverlap_(m,u);f>=p?(f>=u.length/2||f>=m.length/2)&&(e.splice(o,0,new T.Diff(k,m.substring(0,f))),e[o-1][1]=u.substring(0,u.length-f),e[o+1][1]=m.substring(f),o++):(p>=u.length/2||p>=m.length/2)&&(e.splice(o,0,new T.Diff(k,u.substring(0,p))),e[o-1][0]=z,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_),N=x&&d.match(T.linebreakRegex_),v=P&&w.match(T.linebreakRegex_),y=N&&p.match(T.blanklineEndRegex_),E=v&&g.match(T.blanklineStartRegex_);return y||E?5:N||v?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]==k&&e[r+1][0]==k){var n=e[r-1][1],a=e[r][1],o=e[r+1][1],i=this.diff_commonSuffix(n,a);if(i){var s=a.substring(a.length-i);n=n.substring(0,n.length-i),a=s+a.substring(0,a.length-i),o=s+o}for(var l=n,c=a,u=o,m=t(n,a)+t(a,o);a.charAt(0)===o.charAt(0);){n+=a.charAt(0),a=a.substring(1)+o.charAt(0),o=o.substring(1);var f=t(n,a)+t(a,o);f>=m&&(m=f,l=n,c=a,u=o)}e[r-1][1]!=l&&(l?e[r-1][1]=l:(e.splice(r-1,1),r--),e[r][1]=c,u?e[r+1][1]=u:(e.splice(r+1,1),r--))}r++}};T.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/;T.whitespaceRegex_=/\s/;T.linebreakRegex_=/[\r\n]/;T.blanklineEndRegex_=/\n\r?\n$/;T.blanklineStartRegex_=/^\r?\n\r?\n/;T.prototype.diff_cleanupEfficiency=function(e){for(var t=!1,r=[],n=0,a=null,o=0,i=!1,s=!1,l=!1,c=!1;o<e.length;)e[o][0]==k?(e[o][1].length<this.Diff_EditCost&&(l||c)?(r[n++]=o,i=l,s=c,a=e[o][1]):(n=0,a=null),l=c=!1):(e[o][0]==D?c=!0:l=!0,a&&(i&&s&&l&&c||a.length<this.Diff_EditCost/2&&i+s+l+c==3)&&(e.splice(r[n-1],0,new T.Diff(D,a)),e[r[n-1]+1][0]=z,n--,a=null,i&&s?(l=c=!0,n=0):(n--,o=n>0?r[n-1]:-1,l=c=!1),t=!0)),o++;t&&this.diff_cleanupMerge(e)};T.prototype.diff_cleanupMerge=function(e){e.push(new T.Diff(k,""));for(var t=0,r=0,n=0,a="",o="",i;t<e.length;)switch(e[t][0]){case z:n++,o+=e[t][1],t++;break;case D:r++,a+=e[t][1],t++;break;case k:r+n>1?(r!==0&&n!==0&&(i=this.diff_commonPrefix(o,a),i!==0&&(t-r-n>0&&e[t-r-n-1][0]==k?e[t-r-n-1][1]+=o.substring(0,i):(e.splice(0,0,new T.Diff(k,o.substring(0,i))),t++),o=o.substring(i),a=a.substring(i)),i=this.diff_commonSuffix(o,a),i!==0&&(e[t][1]=o.substring(o.length-i)+e[t][1],o=o.substring(0,o.length-i),a=a.substring(0,a.length-i))),t-=r+n,e.splice(t,r+n),a.length&&(e.splice(t,0,new T.Diff(D,a)),t++),o.length&&(e.splice(t,0,new T.Diff(z,o)),t++),t++):t!==0&&e[t-1][0]==k?(e[t-1][1]+=e[t][1],e.splice(t,1)):t++,n=0,r=0,a="",o="";break}e[e.length-1][1]===""&&e.pop();var s=!1;for(t=1;t<e.length-1;)e[t-1][0]==k&&e[t+1][0]==k&&(e[t][1].substring(e[t][1].length-e[t-1][1].length)==e[t-1][1]?(e[t][1]=e[t-1][1]+e[t][1].substring(0,e[t][1].length-e[t-1][1].length),e[t+1][1]=e[t-1][1]+e[t+1][1],e.splice(t-1,1),s=!0):e[t][1].substring(0,e[t+1][1].length)==e[t+1][1]&&(e[t-1][1]+=e[t+1][1],e[t][1]=e[t][1].substring(e[t+1][1].length)+e[t+1][1],e.splice(t+1,1),s=!0)),t++;s&&this.diff_cleanupMerge(e)};T.prototype.diff_xIndex=function(e,t){var r=0,n=0,a=0,o=0,i;for(i=0;i<e.length&&(e[i][0]!==z&&(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 z:t[i]='<ins style="background:#e6ffe6;">'+c+"</ins>";break;case D:t[i]='<del style="background:#ffe6e6;">'+c+"</del>";break;case k:t[i]="<span>"+c+"</span>";break}}return t.join("")};T.prototype.diff_text1=function(e){for(var t=[],r=0;r<e.length;r++)e[r][0]!==z&&(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 z:r+=i.length;break;case D:n+=i.length;break;case k:t+=Math.max(r,n),r=0,n=0;break}}return t+=Math.max(r,n),t};T.prototype.diff_toDelta=function(e){for(var t=[],r=0;r<e.length;r++)switch(e[r][0]){case z:t[r]="+"+encodeURI(e[r][1]);break;case D:t[r]="-"+e[r][1].length;break;case k:t[r]="="+e[r][1].length;break}return t.join(" ").replace(/%20/g," ")};T.prototype.diff_fromDelta=function(e,t){for(var r=[],n=0,a=0,o=t.split(/\t/g),i=0;i<o.length;i++){var s=o[i].substring(1);switch(o[i].charAt(0)){case"+":try{r[n++]=new T.Diff(z,decodeURI(s))}catch{throw new Error("Illegal escape in diff_fromDelta: "+s)}break;case"-":case"=":var l=parseInt(s,10);if(isNaN(l)||l<0)throw new Error("Invalid number in diff_fromDelta: "+s);var c=e.substring(a,a+=l);o[i].charAt(0)=="="?r[n++]=new T.Diff(k,c):r[n++]=new T.Diff(D,c);break;default:if(o[i])throw new Error("Invalid diff operation in diff_fromDelta: "+o[i])}}if(a!=e.length)throw new Error("Delta length ("+a+") does not equal source text length ("+e.length+").");return r};T.prototype.match_main=function(e,t,r){if(e==null||t==null||r==null)throw new Error("Null input. (match_main)");return r=Math.max(0,Math.min(r,e.length)),e==t?0:e.length?e.substring(r,r+t.length)==t?r:this.match_bitap_(e,t,r):-1};T.prototype.match_bitap_=function(e,t,r){if(t.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var n=this.match_alphabet_(t),a=this;function o(P,N){var v=P/t.length,y=Math.abs(r-N);return a.Match_Distance?v+y/a.Match_Distance:y?1:v}var i=this.Match_Threshold,s=e.indexOf(t,r);s!=-1&&(i=Math.min(o(0,s),i),s=e.lastIndexOf(t,r+t.length),s!=-1&&(i=Math.min(o(0,s),i)));var l=1<<t.length-1;s=-1;for(var c,u,m=t.length+e.length,f,p=0;p<t.length;p++){for(c=0,u=m;c<u;)o(p,r+u)<=i?c=u:m=u,u=Math.floor((m-c)/2+c);m=u;var g=Math.max(1,r-u+1),d=Math.min(r+u,e.length)+t.length,w=Array(d+2);w[d+1]=(1<<p)-1;for(var h=d;h>=g;h--){var b=n[e.charAt(h-1)];if(p===0?w[h]=(w[h+1]<<1|1)&b:w[h]=(w[h+1]<<1|1)&b|((f[h+1]|f[h])<<1|1)|f[h+1],w[h]&l){var x=o(p,h-1);if(x<=i)if(i=x,s=h-1,s>r)g=Math.max(1,2*r-s);else break}}if(o(p+1,r)>i)break;f=w}return s};T.prototype.match_alphabet_=function(e){for(var t={},r=0;r<e.length;r++)t[e.charAt(r)]=0;for(var r=0;r<e.length;r++)t[e.charAt(r)]|=1<<e.length-r-1;return t};T.prototype.patch_addContext_=function(e,t){if(t.length!=0){if(e.start2===null)throw Error("patch not initialized");for(var r=t.substring(e.start2,e.start2+e.length1),n=0;t.indexOf(r)!=t.lastIndexOf(r)&&r.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)n+=this.Patch_Margin,r=t.substring(e.start2-n,e.start2+e.length1+n);n+=this.Patch_Margin;var a=t.substring(e.start2-n,e.start2);a&&e.diffs.unshift(new T.Diff(k,a));var o=t.substring(e.start2+e.length1,e.start2+e.length1+n);o&&e.diffs.push(new T.Diff(k,o)),e.start1-=a.length,e.start2-=a.length,e.length1+=a.length+o.length,e.length2+=a.length+o.length}};T.prototype.patch_make=function(e,t,r){var n,a;if(typeof e=="string"&&typeof t=="string"&&typeof r>"u")n=e,a=this.diff_main(n,t,!0),a.length>2&&(this.diff_cleanupSemantic(a),this.diff_cleanupEfficiency(a));else if(e&&typeof e=="object"&&typeof t>"u"&&typeof r>"u")a=e,n=this.diff_text1(a);else if(typeof e=="string"&&t&&typeof t=="object"&&typeof r>"u")n=e,a=t;else if(typeof e=="string"&&typeof t=="string"&&r&&typeof r=="object")n=e,a=r;else throw new Error("Unknown call format to patch_make.");if(a.length===0)return[];for(var o=[],i=new T.patch_obj,s=0,l=0,c=0,u=n,m=n,f=0;f<a.length;f++){var p=a[f][0],g=a[f][1];switch(!s&&p!==k&&(i.start1=l,i.start2=c),p){case z:i.diffs[s++]=a[f],i.length2+=g.length,m=m.substring(0,c)+g+m.substring(c);break;case D:i.length1+=g.length,i.diffs[s++]=a[f],m=m.substring(0,c)+m.substring(c+g.length);break;case k:g.length<=2*this.Patch_Margin&&s&&a.length!=f+1?(i.diffs[s++]=a[f],i.length1+=g.length,i.length2+=g.length):g.length>=2*this.Patch_Margin&&s&&(this.patch_addContext_(i,u),o.push(i),i=new T.patch_obj,s=0,u=m,l=c);break}p!==z&&(l+=g.length),p!==D&&(c+=g.length)}return s&&(this.patch_addContext_(i,u),o.push(i)),o};T.prototype.patch_deepCopy=function(e){for(var t=[],r=0;r<e.length;r++){var n=e[r],a=new T.patch_obj;a.diffs=[];for(var o=0;o<n.diffs.length;o++)a.diffs[o]=new T.Diff(n.diffs[o][0],n.diffs[o][1]);a.start1=n.start1,a.start2=n.start2,a.length1=n.length1,a.length2=n.length2,t[r]=a}return t};T.prototype.patch_apply=function(e,t){if(e.length==0)return[t,[]];e=this.patch_deepCopy(e);var r=this.patch_addPadding(e);t=r+t+r,this.patch_splitMax(e);for(var n=0,a=[],o=0;o<e.length;o++){var i=e[o].start2+n,s=this.diff_text1(e[o].diffs),l,c=-1;if(s.length>this.Match_MaxBits?(l=this.match_main(t,s.substring(0,this.Match_MaxBits),i),l!=-1&&(c=this.match_main(t,s.substring(s.length-this.Match_MaxBits),i+s.length-this.Match_MaxBits),(c==-1||l>=c)&&(l=-1))):l=this.match_main(t,s,i),l==-1)a[o]=!1,n-=e[o].length2-e[o].length1;else{a[o]=!0,n=l-i;var u;if(c==-1?u=t.substring(l,l+s.length):u=t.substring(l,c+this.Match_MaxBits),s==u)t=t.substring(0,l)+this.diff_text2(e[o].diffs)+t.substring(l+s.length);else{var m=this.diff_main(s,u,!1);if(s.length>this.Match_MaxBits&&this.diff_levenshtein(m)/s.length>this.Patch_DeleteThreshold)a[o]=!1;else{this.diff_cleanupSemanticLossless(m);for(var f=0,p,g=0;g<e[o].diffs.length;g++){var d=e[o].diffs[g];d[0]!==k&&(p=this.diff_xIndex(m,f)),d[0]===z?t=t.substring(0,l+p)+d[1]+t.substring(l+p):d[0]===D&&(t=t.substring(0,l+p)+t.substring(l+this.diff_xIndex(m,f+d[1].length))),d[0]!==D&&(f+=d[1].length)}}}}}return t=t.substring(r.length,t.length-r.length),[t,a]};T.prototype.patch_addPadding=function(e){for(var t=this.Patch_Margin,r="",n=1;n<=t;n++)r+=String.fromCharCode(n);for(var n=0;n<e.length;n++)e[n].start1+=t,e[n].start2+=t;var a=e[0],o=a.diffs;if(o.length==0||o[0][0]!=k)o.unshift(new T.Diff(k,r)),a.start1-=t,a.start2-=t,a.length1+=t,a.length2+=t;else if(t>o[0][1].length){var i=t-o[0][1].length;o[0][1]=r.substring(o[0][1].length)+o[0][1],a.start1-=i,a.start2-=i,a.length1+=i,a.length2+=i}if(a=e[e.length-1],o=a.diffs,o.length==0||o[o.length-1][0]!=k)o.push(new T.Diff(k,r)),a.length1+=t,a.length2+=t;else if(t>o[o.length-1][1].length){var i=t-o[o.length-1][1].length;o[o.length-1][1]+=r.substring(0,i),a.length1+=i,a.length2+=i}return r};T.prototype.patch_splitMax=function(e){for(var t=this.Match_MaxBits,r=0;r<e.length;r++)if(!(e[r].length1<=t)){var n=e[r];e.splice(r--,1);for(var a=n.start1,o=n.start2,i="";n.diffs.length!==0;){var s=new T.patch_obj,l=!0;for(s.start1=a-i.length,s.start2=o-i.length,i!==""&&(s.length1=s.length2=i.length,s.diffs.push(new T.Diff(k,i)));n.diffs.length!==0&&s.length1<t-this.Patch_Margin;){var c=n.diffs[0][0],u=n.diffs[0][1];c===z?(s.length2+=u.length,o+=u.length,s.diffs.push(n.diffs.shift()),l=!1):c===D&&s.diffs.length==1&&s.diffs[0][0]==k&&u.length>2*t?(s.length1+=u.length,a+=u.length,l=!1,s.diffs.push(new T.Diff(c,u)),n.diffs.shift()):(u=u.substring(0,t-s.length1-this.Patch_Margin),s.length1+=u.length,a+=u.length,c===k?(s.length2+=u.length,o+=u.length):l=!1,s.diffs.push(new T.Diff(c,u)),u==n.diffs[0][1]?n.diffs.shift():n.diffs[0][1]=n.diffs[0][1].substring(u.length))}i=this.diff_text2(s.diffs),i=i.substring(i.length-this.Patch_Margin);var m=this.diff_text1(n.diffs).substring(0,this.Patch_Margin);m!==""&&(s.length1+=m.length,s.length2+=m.length,s.diffs.length!==0&&s.diffs[s.diffs.length-1][0]===k?s.diffs[s.diffs.length-1][1]+=m:s.diffs.push(new T.Diff(k,m))),l||e.splice(++r,0,s)}}};T.prototype.patch_toText=function(e){for(var t=[],r=0;r<e.length;r++)t[r]=e[r];return t.join("")};T.prototype.patch_fromText=function(e){var t=[];if(!e)return t;for(var r=e.split(`
3
+ `),n=0,a=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;n<r.length;){var o=r[n].match(a);if(!o)throw new Error("Invalid patch string: "+r[n]);var i=new T.patch_obj;for(t.push(i),i.start1=parseInt(o[1],10),o[2]===""?(i.start1--,i.length1=1):o[2]=="0"?i.length1=0:(i.start1--,i.length1=parseInt(o[2],10)),i.start2=parseInt(o[3],10),o[4]===""?(i.start2--,i.length2=1):o[4]=="0"?i.length2=0:(i.start2--,i.length2=parseInt(o[4],10)),n++;n<r.length;){var s=r[n].charAt(0);try{var l=decodeURI(r[n].substring(1))}catch{throw new Error("Illegal escape in patch_fromText: "+l)}if(s=="-")i.diffs.push(new T.Diff(D,l));else if(s=="+")i.diffs.push(new T.Diff(z,l));else if(s==" ")i.diffs.push(new T.Diff(k,l));else{if(s=="@")break;if(s!=="")throw new Error('Invalid patch mode "'+s+'" in: '+l)}n++}}return t};T.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0};T.patch_obj.prototype.toString=function(){var e,t;this.length1===0?e=this.start1+",0":this.length1==1?e=this.start1+1:e=this.start1+1+","+this.length1,this.length2===0?t=this.start2+",0":this.length2==1?t=this.start2+1:t=this.start2+1+","+this.length2;for(var r=["@@ -"+e+" +"+t+` @@
4
+ `],n,a=0;a<this.diffs.length;a++){switch(this.diffs[a][0]){case z:n="+";break;case D:n="-";break;case k:n=" ";break}r[a+1]=n+encodeURI(this.diffs[a][1])+`
5
+ `}return r.join("").replace(/%20/g," ")};Ye.exports=T;Ye.exports.diff_match_patch=T;Ye.exports.DIFF_DELETE=D;Ye.exports.DIFF_INSERT=z;Ye.exports.DIFF_EQUAL=k});var st=globalThis.DOMParser,lt=globalThis.XMLSerializer;function no(e={}){e.DOMParser&&(st=e.DOMParser),e.XMLSerializer&&(lt=e.XMLSerializer)}function B(){if(!st&&globalThis.DOMParser&&(st=globalThis.DOMParser),!st)throw new Error("DOMParser is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new st}function Q(){if(!lt&&globalThis.XMLSerializer&&(lt=globalThis.XMLSerializer),!lt)throw new Error("XMLSerializer is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new lt}function St(e,t="text/xml"){return B().parseFromString(e,t)}function K(e){return Q().serializeToString(e)}var It=console,nr=Object.freeze({silent:0,error:1,warn:2,info:3}),ao=typeof process<"u"&&process?.env?.NODE_ENV==="production"?"warn":"info",ar=ao;function oo(e){let t=String(e||"").toLowerCase();return Object.prototype.hasOwnProperty.call(nr,t)?t:ar}function or(e){return nr[ar]>=nr[e]}function io(e,t={}){It=e||console,t.level&&(ar=oo(t.level))}function C(...e){or("info")&&(It.log||(()=>{}))(...e)}function Le(...e){or("warn")&&(It.warn||(()=>{}))(...e)}function Z(...e){or("error")&&(It.error||(()=>{}))(...e)}var en="Author",tn="Unknown";function so(e){en=typeof e=="string"&&e.trim()?e.trim():"Author"}function J(){return en}function lo(e){tn=typeof e=="string"&&e.trim()?e.trim():"Unknown"}function ir(){return tn}var co=[{regex:/<b>(.+?)<\/b>/i,format:{bold:!0}},{regex:/<strong>(.+?)<\/strong>/i,format:{bold:!0}},{regex:/<i>(.+?)<\/i>/i,format:{italic:!0}},{regex:/<em>(.+?)<\/em>/i,format:{italic:!0}},{regex:/<u>(.+?)<\/u>/i,format:{underline:!0}},{regex:/<s>(.+?)<\/s>/i,format:{strikethrough:!0}},{regex:/<strike>(.+?)<\/strike>/i,format:{strikethrough:!0}},{regex:/<del>(.+?)<\/del>/i,format:{strikethrough:!0}},{regex:/&lt;b&gt;(.+?)&lt;\/b&gt;/i,format:{bold:!0},isEscaped:!0},{regex:/&lt;strong&gt;(.+?)&lt;\/strong&gt;/i,format:{bold:!0},isEscaped:!0},{regex:/&lt;i&gt;(.+?)&lt;\/i&gt;/i,format:{italic:!0},isEscaped:!0},{regex:/&lt;em&gt;(.+?)&lt;\/em&gt;/i,format:{italic:!0},isEscaped:!0},{regex:/&lt;u&gt;(.+?)&lt;\/u&gt;/i,format:{underline:!0},isEscaped:!0},{regex:/&lt;s&gt;(.+?)&lt;\/s&gt;/i,format:{strikethrough:!0},isEscaped:!0},{regex:/\*\*\*(.+?)\*\*\*/,format:{bold:!0,italic:!0}},{regex:/\*\*\+\+(.+?)\+\+\*\*/,format:{bold:!0,underline:!0}},{regex:/\*\*(.+?)\*\*/,format:{bold:!0}},{regex:/__(.+?)__/,format:{bold:!0}},{regex:/\+\+(.+?)\+\+/,format:{underline:!0}},{regex:/~~(.+?)~~/,format:{strikethrough:!0}},{regex:/~(.+?)~/,format:{strikethrough:!0}},{regex:/\*(?!\*)(.+?)\*(?!\*)/,format:{italic:!0}},{regex:/_(?!_)(.+?)_(?!_)/,format:{italic:!0}}];function ne(e){if(!e)return{cleanText:"",formatHints:[]};let t=[],r="",n=[];for(let s of co){let l,c=s.regex.source||s.regex.toString().replace(/^\/|\/[gimuy]*$/g,""),u="g"+(s.regex.ignoreCase?"i":""),m=new RegExp(c,u);for(;(l=m.exec(e))!==null;)n.push({start:l.index,end:l.index+l[0].length,fullMatch:l[0],innerText:s.isEscaped?uo(l[1]):l[1],format:s.format}),l.index===m.lastIndex&&m.lastIndex++}n.sort((s,l)=>s.start-l.start||l.end-s.end);let a=[],o=0;for(let s of n)s.start>=o&&(a.push(s),o=s.end);let i=0;for(let s of a){r+=e.slice(i,s.start);let l=ne(s.innerText),c=r.length;r+=l.cleanText;let u=r.length;t.push({start:c,end:u,format:s.format});for(let m of l.formatHints)t.push({start:c+m.start,end:c+m.end,format:m.format});i=s.end}return r+=e.slice(i),{cleanText:r,formatHints:t}}function we(e,t,r){return e.filter(n=>n.start<r&&n.end>t)}function sr(...e){let t={};for(let r of e)r&&Object.assign(t,r);return t}function uo(e){return e?e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#039;/g,"'"):""}var Ct=String.raw`(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|\d+\.|[ivxlcIVXLC]+\.|[-*\u2022])`,rn=new RegExp(`^(\\s*)((?:${Ct})\\s+)`),nn=new RegExp(`^(\\s*)((?:${Ct})\\s*)`),fo=new RegExp(`^(\\s*)((?:${Ct})\\s+)`,"m"),mo=new RegExp(`^(\\s*)((?:${Ct})\\s*)`,"m");function an(e){return typeof e!="string"?!1:e.includes(`
6
+ `)&&fo.test(e)}function At(e){return typeof e!="string"?!1:e.includes(`
7
+ `)&&mo.test(e.trim())}function be(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?nn:rn;return e.match(n)}function Pe(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?nn:rn;return e.replace(n,"")}var S="http://schemas.openxmlformats.org/wordprocessingml/2006/main";var ce=Object.freeze({EQUAL:"equal",DELETE:"delete",INSERT:"insert"}),O=Object.freeze({TEXT:"run",DELETION:"deletion",INSERTION:"insertion",HYPERLINK:"hyperlink",BOOKMARK:"bookmark",FIELD:"field",CONTAINER_START:"container_start",CONTAINER_END:"container_end",PARAGRAPH_START:"paragraph_start"}),Ge=Object.freeze({SDT:"sdt",SMART_TAG:"smartTag",CUSTOM_XML:"customXml",FIELD_COMPLEX:"fldComplex"}),on=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 Rt=1e3;function lr(){return Rt++}function cr(e=new Date){return e.toISOString()}function ee(e){let t=typeof e=="string"&&e.trim()?e.trim():J();return{id:lr(),author:t,date:cr()}}function ur(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>=Rt&&(Rt=t+1),Rt}function sn(e,t){return e<t-1}function Ve(e,t,r){return sn(t,r)?e+`
8
+ `:e}function _e(e,t,r){return sn(t,r)?e+1:e}function Se(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:Se(e,n)}function Ot(e,t,r,n=`w:${r}`){let a=H(e,t,r);return a||$(e,n)}function j(e){return $(e,"parsererror")}function fr(e){return Array.from(e?.childNodes||[])}function ln(e){return Array.from(e.attributes).map(t=>`${t.name}="${t.value}"`).join(" ")}function mr(e,t,r=""){return!e||e.namespaceURI!==t?!1:r?e.localName===r:!0}var pr=0;function kt(e,t={}){let r=[],n="",a=t.xmlDoc||null;if(!e&&!a)return{runModel:r,acceptedText:n,pPr:null};try{let o=a||B().parseFromString(e,"application/xml"),i=j(o);if(i)return Z("OOXML parse error:",i.textContent),{runModel:r,acceptedText:n,pPr:null};let s=V(o,S,"p");return s.length===0?(Le("No paragraphs found in OOXML"),{runModel:r,acceptedText:n,pPr:null}):un(s,{includeParagraphBoundaries:!0})}catch(o){return Z("Error ingesting OOXML:",o),{runModel:r,acceptedText:n,pPr:null}}}function gr(e){return e?un([e],{includeParagraphBoundaries:!1}):{runModel:[],acceptedText:"",pPr:null}}function dr(e){let t=H(e,S,"pPr");if(!t)return null;let r=H(t,S,"numPr");if(!r)return null;let n=H(r,S,"numId"),a=H(r,S,"ilvl");if(!n)return null;let o=n.getAttribute("w:val"),i=o==="1"?"bullet":o==="2"?"numbered":"unknown";return{numId:o,ilvl:parseInt(a?.getAttribute("w:val")||"0",10),type:i}}function un(e,t={}){let r=t.includeParagraphBoundaries??!0,n=[],a="",o=0,i=null;for(let s=0;s<e.length;s++){let l=e[s],c=H(l,S,"pPr");s===0&&(i=c),n.push({kind:O.PARAGRAPH_START,pPrElement:c||null,startOffset:o,endOffset:o,text:""});let u=Ke(l,o,n);a+=u.text,o=a.length,r&&(a=Ve(a,s,e.length),o=_e(o,s,e.length))}return{runModel:n,acceptedText:a,pPr:i}}function Ke(e,t,r){let n=t,a="",o=po(r);for(let i of fr(e)){if(mr(i,S,"pPr")||mr(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 po(e){let t=new Map;t.set("sdt",(r,n)=>{let a=`sdt_${pr++}`,o=H(r,S,"sdtPr"),i=H(r,S,"sdtContent");e.push({kind:O.CONTAINER_START,containerKind:Ge.SDT,containerId:a,propertiesXml:o?K(o):"",startOffset:n,endOffset:n,text:""});let s=i?Ke(i,n,e):{offset:n,text:""};return e.push({kind:O.CONTAINER_END,containerKind:Ge.SDT,containerId:a,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("smartTag",(r,n)=>{let a=`smartTag_${pr++}`;e.push({kind:O.CONTAINER_START,containerKind:Ge.SMART_TAG,containerId:a,propertiesXml:ln(r),startOffset:n,endOffset:n,text:""});let o=Ke(r,n,e);return e.push({kind:O.CONTAINER_END,containerKind:Ge.SMART_TAG,containerId:a,startOffset:o.offset,endOffset:o.offset,text:""}),o}),t.set("del",(r,n)=>{let a=cn(r,n);return a&&e.push(a),{offset:n,text:""}}),t.set("moveFrom",(r,n)=>{let a=cn(r,n);return a&&e.push(a),{offset:n,text:""}}),t.set("moveTo",(r,n)=>Ke(r,n,e));for(let r of["moveFromRangeStart","moveFromRangeEnd","moveToRangeStart","moveToRangeEnd"])t.set(r,(n,a)=>(e.push({kind:O.BOOKMARK,nodeXml:K(n),startOffset:a,endOffset:a,text:""}),{offset:a,text:""}));return t.set("bookmarkStart",(r,n)=>(e.push({kind:O.BOOKMARK,nodeXml:K(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("bookmarkEnd",(r,n)=>(e.push({kind:O.BOOKMARK,nodeXml:K(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("ins",(r,n)=>Ke(r,n,e)),t.set("hyperlink",(r,n)=>{let a=`hyperlink_${pr++}`,o=r.getAttribute("r:id")||"",i=r.getAttribute("w:anchor")||"";e.push({kind:O.CONTAINER_START,containerKind:"hyperlink",containerId:a,propertiesXml:JSON.stringify({rId:o,anchor:i}),startOffset:n,endOffset:n,text:""});let s=Ke(r,n,e);return e.push({kind:O.CONTAINER_END,containerKind:"hyperlink",containerId:a,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("r",(r,n)=>{let a=go(r,n);return!a||!a.text?{offset:n,text:""}:(e.push(a),{offset:n+a.text.length,text:a.text})}),t}function go(e,t){let r=Ot(e,S,"rPr"),n=r?K(r):"",a="";for(let o of fr(e)){let i=o.nodeName;i.endsWith(":t")||i==="t"?a+=o.textContent||"":i.endsWith(":br")||i==="br"||i.endsWith(":cr")||i==="cr"?a+=`
9
+ `:i.endsWith(":tab")||i==="tab"?a+=" ":(i.endsWith(":noBreakHyphen")||i==="noBreakHyphen")&&(a+="\u2011")}return a?{kind:O.TEXT,text:a,rPrXml:n,startOffset:t,endOffset:t+a.length}:null}function cn(e,t){let r=e.getAttribute("w:author")||"",n="",a=V(e,S,"delText");for(let i of a)n+=i.textContent||"";let o=V(e,S,"r");for(let i of o){let s=V(i,S,"delText");for(let l of s)n+=l.textContent||""}return n?{kind:O.DELETION,text:n,rPrXml:"",startOffset:t,endOffset:t,author:r,nodeXml:K(e)}:null}function wr(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"),N=x!==null,v;if(N&&P!=="restart"){let y=c.get(p);y?(y.cell.rowSpan++,v={gridRow:u,gridCol:p,rowSpan:0,colSpan:b,tcNode:d,blocks:[],tcPrXml:hr(w),isMergeOrigin:!1,isMergeContinuation:!0,mergeOrigin:y.cell}):v=ho(u,p,b,d,w)}else{let y=fn(d);if(v={gridRow:u,gridCol:p,rowSpan:1,colSpan:b,tcNode:d,blocks:y,tcPrXml:hr(w),isMergeOrigin:N&&P==="restart",isMergeContinuation:!1,getText:()=>y.map(E=>E.acceptedText).join(`
10
+ `)},N&&P==="restart")for(let E=0;E<b;E++)c.set(p+E,{originRow:u,cell:v});else for(let E=0;E<b;E++)c.delete(p+E)}for(let y=0;y<b;y++){let E=p+y;E<i&&(s[u][E]=v,l.set(`${u},${E}`,v))}p+=b}}return{rowCount:a,colCount:i,grid:s,cellMap:l,tblPrXml:wo(e),tblGridXml:bo(e),trPrList:Array.from(n).map(u=>xo(u))}}function ho(e,t,r,n,a){let o=fn(n);return{gridRow:e,gridCol:t,rowSpan:1,colSpan:r,tcNode:n,blocks:o,tcPrXml:hr(a),isMergeOrigin:!1,isMergeContinuation:!1,getText:()=>o.map(i=>i.acceptedText).join(`
11
+ `)}}function fn(e){return ue(e,S,"p").map(r=>{let{runModel:n,acceptedText:a,pPr:o}=gr(r);return{runModel:n,acceptedText:a,pPr:o}})}function hr(e){return e?K(e):"<w:tcPr/>"}function wo(e){let t=H(e,S,"tblPr");return t?K(t):"<w:tblPr/>"}function bo(e){let t=H(e,S,"tblGrid");return t?K(t):"<w:tblGrid/>"}function xo(e){let t=H(e,S,"trPr");return t?K(t):"<w:trPr/>"}var gn=ro(mn(),1);var pn=new gn.diff_match_patch;function No(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 vo(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 ct(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}=No(e,t),s=pn.diff_main(a,o);return n&&pn.diff_cleanupSemantic(s),vo(s,i)}function Mt(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=ct(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 To=/\s+xmlns:[^=]+="[^"]*"/g;function Lt(e,t){let r=Co(t),n=[],a=0;for(let o of e){if(o.kind!==O.TEXT&&o.kind!==O.HYPERLINK){n.push(o);continue}for(;a<r.length&&r[a]<=o.startOffset;)a++;let i=a,s=o.startOffset,l=!1;for(;i<r.length;){let c=r[i];if(c>=o.endOffset)break;c>s&&(l=!0,n.push({...o,text:o.text.slice(s-o.startOffset,c-o.startOffset),startOffset:s,endOffset:c}),s=c),i++}if(a=i,!l){n.push(o);continue}n.push({...o,text:o.text.slice(s-o.startOffset),startOffset:s,endOffset:o.endOffset})}return n}function _t(e,t,r){let{generateRedlines:n,author:a}=r,o=[],i=new Set,s=Ao(t),l=So(e),c=Io(s.nonInsertOps),u={containerStack:[],lastParagraphStartIndex:-1,currentParagraphPPrXml:"",currentParagraphPPrElement:null};for(let f of e){if(f.kind===O.CONTAINER_START){u.containerStack.push(f.containerId),o.push({...f});continue}if(f.kind===O.CONTAINER_END){u.containerStack.pop(),o.push({...f});continue}if(f.kind===O.PARAGRAPH_START){u.currentParagraphPPrXml=typeof f.pPrXml=="string"?f.pPrXml:"",u.currentParagraphPPrElement=f.pPrElement||null,o.push({...f}),u.lastParagraphStartIndex=o.length-1;continue}if(f.kind===O.BOOKMARK||f.kind===O.DELETION){o.push({...f});continue}let p=c(f.startOffset,f.endOffset),g=s.insertOpsByStartOffset.get(f.startOffset)||[];for(let d of g)i.has(d)||(i.add(d),yo({insertOp:d,splitModel:e,styleLookup:l,patchedModel:o,state:u,options:r,generateRedlines:n,author:a}));if(!p||p.type===ce.EQUAL){o.push({...f,containerContext:u.containerStack.length>0?u.containerStack[u.containerStack.length-1]:null});continue}p.type===ce.DELETE&&n&&o.push({...f,kind:O.DELETION,author:a,containerContext:u.containerStack.length>0?u.containerStack[u.containerStack.length-1]:null})}let m=e.length>0?Math.max(...e.map(f=>f.endOffset)):0;for(let f of s.sortedInsertOps){if(f.startOffset<m||i.has(f))continue;let p=e[e.length-1];o.push({kind:n?O.INSERTION:O.TEXT,text:f.text,rPrXml:p?.rPrXml||"",startOffset:f.startOffset,endOffset:f.startOffset+f.text.length,author:n?a:void 0})}return o}function yo(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=Po(n,t.startOffset,t.text);for(let m=0;m<c.length;m++){let f=Eo(c[m],i.numberingService,o),p=f.lineText;if(m>0){let g=dn(o);f.isListLine&&f.numId&&(g=i.numberingService.buildListPPr(f.numId,f.ilvl)),a.push({kind:O.PARAGRAPH_START,pPrXml:g,startOffset:t.startOffset,endOffset:t.startOffset,text:""}),o.currentParagraphPPrXml=g,o.currentParagraphPPrElement=null,o.lastParagraphStartIndex=a.length-1}else if(f.isListLine&&f.numId&&o.lastParagraphStartIndex>=0){let g=i.numberingService.buildListPPr(f.numId,f.ilvl);a[o.lastParagraphStartIndex].pPrXml=g,a[o.lastParagraphStartIndex].pPrElement=null,o.currentParagraphPPrXml=g,o.currentParagraphPPrElement=null,C(`[Patching] Converted current paragraph to list item: numId=${f.numId}, ilvl=${f.ilvl}`)}(p.length>0||m>0)&&a.push({kind:s?O.INSERTION:O.TEXT,text:p,rPrXml:u?.rPrXml||"",startOffset:t.startOffset,endOffset:t.startOffset+p.length,author:s?l:void 0,containerContext:o.containerStack.length>0?o.containerStack[o.containerStack.length-1]:null})}}function Eo(e,t,r){if(!t)return{lineText:e,isListLine:!1,numId:null,ilvl:0};let n=be(e,{allowZeroSpaceAfterMarker:!0});if(!n)return{lineText:e,isListLine:!1,numId:null,ilvl:0};let a=n[2].trim(),o=t.detectNumberingFormat(a),i=e.match(/^(\s*)/),s=i?i[1].length:0,l=s>=4?4:2,c=Math.floor(s/l),u=dn(r),m=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 dn(e){return e.currentParagraphPPrXml?e.currentParagraphPPrXml:e.currentParagraphPPrElement?(e.currentParagraphPPrXml=K(e.currentParagraphPPrElement).replace(To,""),e.currentParagraphPPrXml):""}function Po(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 So(e){let t=e.filter(a=>a.kind===O.TEXT),r=t.map(a=>a.startOffset),n=t.map(a=>a.endOffset);return{findRunBefore(a){let o=0,i=n.length-1,s=-1;for(;o<=i;){let l=o+i>>1;n[l]<=a?(s=l,o=l+1):i=l-1}return s>=0?t[s]:null},findRunAfter(a){let o=0,i=r.length-1,s=-1;for(;o<=i;){let l=o+i>>1;r[l]>=a?(s=l,i=l-1):o=l+1}return s>=0?t[s]:null}}}function Io(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 Co(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 Ao(e){let t=new Map,r=[],n=[];for(let a of e){if(a.type===ce.INSERT){t.has(a.startOffset)||t.set(a.startOffset,[]),t.get(a.startOffset).push(a),n.push(a);continue}r.push(a)}return r.sort((a,o)=>a.startOffset-o.startOffset||a.endOffset-o.endOffset),n.sort((a,o)=>a.startOffset-o.startOffset||a.endOffset-o.endOffset),{insertOpsByStartOffset:t,nonInsertOps:r,sortedInsertOps:n}}var xn="http://schemas.openxmlformats.org/wordprocessingml/2006/main",Ro="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Oo="http://schemas.microsoft.com/office/2006/xmlPackage",hn="http://schemas.openxmlformats.org/package/2006/relationships",ko='<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>',wn='<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/>';var Mo=`
13
+ <w:numbering xmlns:w="${xn}">
14
14
  <w:abstractNum w:abstractNumId="0">
15
15
  <w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText w:val="&#8226;"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr></w:lvl>
16
16
  </w:abstractNum>
@@ -19,23 +19,23 @@ var Ga=Object.create;var Kr=Object.defineProperty;var Va=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 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`
22
+ </w:numbering>`.trim();function Lo(e){return e?e.replace(/<\?xml[^>]*\?>/g,""):""}function Nn(e,t=!0){let r=t?` xmlns:r="${Ro}"`:"";return`<w:document xmlns:w="${xn}"${r}><w:body>${e}</w:body></w:document>`}function bn(e){return`
23
23
  <pkg:part pkg:name="/word/numbering.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml">
24
24
  <pkg:xmlData>
25
- ${Oo(e)}
25
+ ${Lo(e)}
26
26
  </pkg:xmlData>
27
- </pkg:part>`}function bn(e,t="",r=""){return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
28
- <pkg:package xmlns:pkg="${Ao}">
27
+ </pkg:part>`}function vn(e,t="",r=""){return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
28
+ <pkg:package xmlns:pkg="${Oo}">
29
29
  <pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml">
30
30
  <pkg:xmlData>
31
- <Relationships xmlns="${pn}">
32
- ${Ro}
31
+ <Relationships xmlns="${hn}">
32
+ ${ko}
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="${pn}">
38
+ <Relationships xmlns="${hn}">
39
39
  ${t}
40
40
  </Relationships>
41
41
  </pkg:xmlData>
@@ -45,7 +45,7 @@ var Ga=Object.create;var Kr=Object.defineProperty;var Va=Object.getOwnPropertyDe
45
45
  ${e}
46
46
  </pkg:xmlData>
47
47
  </pkg:part>
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`
48
+ </pkg:package>`}function Tn(e,t={}){let{includeNumbering:r=!1,numberingXml:n=null,appendTrailingParagraph:a=!0}=t,o=a?`${e}<w:p><w:pPr></w:pPr></w:p>`:e,i=Nn(o,!0),s="",l="";return n?(s=wn,l+=bn(n)):r&&(s=wn,l+=bn(Mo)),vn(i,s,l)}function yn(e){let t=Nn(e,!0);return vn(t)}var _o=/\s+xmlns:[^=]+="[^"]*"/g;function fe(e,t,r=[],n={}){let a=Bo(n),{author:o,generateRedlines:i}=a,s=[],l="",c=null,u=[];function m(){if(u.length>0||s.length===0){let f="";l?f=Be(l):c?(l=Be(K(c)),f=l):t&&(typeof t=="string"?f=t:f=K(t),f=Be(f)),s.push(`<w:p>${f}${u.join("")}</w:p>`),u=[]}}for(let f of e)switch(f.kind){case O.PARAGRAPH_START:(u.length>0||s.length>0)&&m(),l=f.pPrXml||"",c=f.pPrElement||null;break;case O.TEXT:u.push(En(f,r,a));break;case O.DELETION:i&&u.push(Fo(f,a));break;case O.INSERTION:i?u.push($o(f,r,a)):u.push(En(f,r,a));break;case O.BOOKMARK:case O.HYPERLINK:f.nodeXml&&u.push(Be(f.nodeXml));break;case O.CONTAINER_START:if(f.containerKind==="sdt")u.push(`<w:sdt>${f.propertiesXml}<w:sdtContent>`);else if(f.containerKind==="smartTag")u.push(`<w:smartTag ${f.propertiesXml}>`);else if(f.containerKind==="hyperlink"){let p=JSON.parse(f.propertiesXml),g=p.rId?` r:id="${p.rId}"`:"",d=p.anchor?` w:anchor="${p.anchor}"`:"";u.push(`<w:hyperlink${g}${d}>`)}break;case O.CONTAINER_END:f.containerKind==="sdt"?u.push("</w:sdtContent></w:sdt>"):f.containerKind==="smartTag"?u.push("</w:smartTag>"):f.containerKind==="hyperlink"&&u.push("</w:hyperlink>");break;default:Le("Unknown run kind:",f.kind)}return m(),s.join("")}function Bo(e){if(typeof e=="string")return{author:J(),generateRedlines:!0,font:e};let t=e&&typeof e=="object"?e:{};return{author:typeof t.author=="string"&&t.author.trim()?t.author.trim():J(),generateRedlines:t.generateRedlines??!0,font:t.font??null}}function En(e,t,r={}){let n=we(t,e.startOffset,e.endOffset),a=r?.font??null,o=e.rPrXml?Be(e.rPrXml):"";if(a&&(o=br(o,a)),n.length===0)return Ie(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(Ie(l.slice(s,m),o));let p=Pn(o,u.format);i.push(Ie(l.slice(m,f),p)),s=f}return s<l.length&&i.push(Ie(l.slice(s),o)),i.join("")}function Ie(e,t){return e?`<w:r>${t||""}<w:t xml:space="preserve">${oe(e)}</w:t></w:r>`:""}function Fo(e,t={}){let r=ee(t.author??J()),n=t.font??null,a=e.rPrXml?Be(e.rPrXml):"";return n&&(a=br(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 $o(e,t,r={}){let n=ee(r.author??J()),a=r.font??null,o=we(t,e.startOffset,e.endOffset),i="",s=e.rPrXml?Be(e.rPrXml):"";if(a&&(s=br(s,a)),o.length===0)i=Ie(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+=Ie(c.slice(l,f),s));let g=Pn(s,m.format);i+=Ie(c.slice(f,p),g),l=p}l<c.length&&(i+=Ie(c.slice(l),s))}return`<w:ins w:id="${n.id}" w:author="${oe(n.author)}" w:date="${n.date}">`+i+"</w:ins>"}function br(e,t){if(!t)return e;let r="";return e&&(r=e.replace(/<\/?w:rPr[^>]*>/g,"")),r.includes("<w:rFonts")?r=r.replace(/<w:rFonts[^>]*\/>/,`<w:rFonts w:ascii="${t}" w:hAnsi="${t}"/>`):r=`<w:rFonts w:ascii="${t}" w:hAnsi="${t}"/>`+r,`<w:rPr>${r}</w:rPr>`}function Pn(e,t){if(!t||Object.keys(t).length===0)return e;let r="";return e&&(r=e.replace(/<\/?w:rPr[^>]*>/g,"")),t.bold&&!r.includes("<w:b")&&(r="<w:b/>"+r),t.italic&&!r.includes("<w:i")&&(r="<w:i/>"+r),t.underline&&!r.includes("<w:u")&&(r='<w:u w:val="single"/>'+r),t.strikethrough&&!r.includes("<w:strike")&&(r="<w:strike/>"+r),`<w:rPr>${r}</w:rPr>`}function Ce(e,t={}){let r=Xo(t);return Tn(e,r)}function Xo(e){return typeof e=="boolean"?{includeNumbering:e}:!e||typeof e!="object"?{}:{includeNumbering:e.includeNumbering??!1,numberingXml:e.numberingXml??null,appendTrailingParagraph:e.appendTrailingParagraph??!0}}function Be(e){return e?e.replace(_o,""):""}var ut=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>
@@ -110,7 +110,7 @@ var Ga=Object.create;var Kr=Object.defineProperty;var Va=Object.getOwnPropertyDe
110
110
  <w:abstractNumId w:val="2"/>
111
111
  </w:num>
112
112
  ${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=`
113
+ </w:numbering>`}};function Fe(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,42 +123,42 @@ var Ga=Object.create;var Kr=Object.defineProperty;var Va=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(),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`
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),N=[{kind:r?O.INSERTION:O.TEXT,text:x,rPrXml:p?"<w:rPr><w:b/></w:rPr>":"",author:n,startOffset:0,endOffset:x.length}],v=fe(N,null,P,{author:n,generateRedlines:r});d+=`<w:tc><w:tcPr><w:tcW w:w="0" w:type="auto"/></w:tcPr>${v}</w:tc>`}u+=`<w:tr><w:trPr/>${d}</w:tr>`}let m=`<w:tbl>${i}${l}${u}</w:tbl>`;return a&&(m=`<w:ins w:id="${a.id}" w:author="${oe(a.author)}" w:date="${a.date}">${m}</w:ins>`),m}function Sn(e,t){let r=[],{headers:n,rows:a,hasHeader:o}=t,i=o?[n,...a]:a,s=Math.max(e.rowCount,i.length);for(let l=0;l<s;l++){if(l>=e.rowCount&&i[l]){r.push({type:"row_insert",gridRow:l,cells:i[l]});continue}if(l<e.rowCount&&!i[l]){r.push({type:"row_delete",gridRow:l});continue}let c=i[l];for(let u=0;u<e.colCount;u++){let m=e.grid[l]?.[u],f=c?.[u];m&&(m.isMergeContinuation||u>m.gridCol||f!==void 0&&m.getText()!==f&&r.push({type:"cell_modify",gridRow:l,gridCol:u,originalCell:m,newText:f}))}}return r}function In(e,t,r){let{generateRedlines:n,author:a}=r,o=Do(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=zo(p,g.newText,r):d=Wo(p.blocks),u+=Ho(p,d,r),m+=p.colSpan}let f=e.trPrList[l]||"<w:trPr/>";if(c&&n){let p=ee(a),g=`<w:del w:id="${p.id}" w:author="${oe(p.author)}" w:date="${p.date}"/>`;f.includes("</w:trPr>")?f=f.replace("</w:trPr>",`${g}</w:trPr>`):f=`<w:trPr>${g}</w:trPr>`}i+=`<w:tr>${f}${u}</w:tr>`}let s=o.rowInsertOperations;for(let l of s){let c="",u=n?ee(a):null;for(let f of l.cells){let{cleanText:p,formatHints:g}=ne(f),d=[{kind:n?O.INSERTION:O.TEXT,text:p,rPrXml:"",author:a,startOffset:0,endOffset:p.length}],w=fe(d,null,g,{author:a,generateRedlines:n});c+=`<w:tc><w:tcPr><w:tcW w:w="0" w:type="auto"/></w:tcPr>${w}</w:tc>`}let m="<w:trPr/>";n&&(m=`<w:trPr><w:ins w:id="${u.id}" w:author="${oe(u.author)}" w:date="${u.date}"/></w:trPr>`),i+=`<w:tr>${m}${c}</w:tr>`}return`
127
127
  <w:tbl>
128
128
  ${e.tblPrXml}
129
129
  ${e.tblGridXml}
130
130
  ${i}
131
131
  </w:tbl>
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,`
132
+ `}function Do(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 zo(e,t,r){let{generateRedlines:n,author:a}=r,{cleanText:o,formatHints:i}=ne(t),s=e.getText(),l=Mt(s,o),c=e.blocks[0]||{runModel:[],pPr:null},u=Lt(c.runModel,l),m=_t(u,l,{generateRedlines:n,author:a,formatHints:i});return fe(m,c.pPr,i,{author:a,generateRedlines:n})}function Wo(e){return e.map(t=>fe(t.runModel,t.pPr,[],{})).join("")}function Ho(e,t,r){let n=e.tcPrXml;return e.colSpan>1&&!n.includes("gridSpan")?n=n.replace("</w:tcPr>",`<w:gridSpan w:val="${e.colSpan}"/></w:tcPr>`):e.colSpan>1&&n==="<w:tcPr/>"&&(n=`<w:tcPr><w:gridSpan w:val="${e.colSpan}"/></w:tcPr>`),e.rowSpan>1&&e.isMergeOrigin&&!n.includes("vMerge")?n=n.replace("</w:tcPr>",'<w:vMerge w:val="restart"/></w:tcPr>'):e.rowSpan>1&&e.isMergeOrigin&&n==="<w:tcPr/>"&&(n='<w:tcPr><w:vMerge w:val="restart"/></w:tcPr>'),`<w:tc>${n}${t}</w:tc>`}function me(e){let t=e.split(`
133
+ `).map(i=>i.trim()).filter(i=>i.startsWith("|"));if(t.length===0)return{headers:[],rows:[],hasHeader:!1};let r=i=>{let s=i.replace(/\s+/g,"");return/^\|:?-{3,}:?(\|:?-{3,}:?)+\|?$/.test(s)},n=t.some(r),o=t.filter(i=>!r(i)).map(i=>i.split("|").slice(1,-1).map(s=>s.trim()));return n?{headers:o[0]||[],rows:o.slice(1),hasHeader:!0}:{headers:[],rows:o,hasHeader:!1}}async function Cn(e){let{cleanText:t,numberingContext:r,originalRunModel:n=[],originalText:a="",generateRedlines:o=!0,author:i="AI",font:s=null,numberingService:l}=e,c=jo(t),u=Uo(c),m=u.map(N=>N.raw),f=[],p=[];if(o){if(n&&n.length>0)p=n.filter(N=>N.kind==="text"||N.kind==="run").map(N=>({...N,kind:"deletion",author:i}));else if(a&&a.trim().length>0){let N=a.trim();p=[{kind:"deletion",text:N,author:i,startOffset:0,endOffset:N.length}]}}let g=xr(m);C(`[ListGen] Detected indentation step: ${g} spaces/chars`);let d=u.find(N=>N.marker)?.marker||"",{format:w}=l.detectNumberingFormat(d);C(`[ListGen] Detected primary marker: "${d}", format: ${w}`);for(let N=0;N<u.length;N++){let v=Go(u,N);if(v){let I=me(v.tableText);if(I.headers.length>0||I.rows.length>0){o&&f.length===0&&p.length>0&&f.push(fe(p,null,[],{author:i,generateRedlines:o,font:s})),f.push(Fe(I,{generateRedlines:o,author:i})),N=v.endIndex;continue}}let y=u[N],E=Vo(y,N,g,r,l,o,i,s,p);f.push(E.ooxml)}let h=l.generateNumberingXml(),P=f.join("")+"<w:p><w:pPr></w:pPr></w:p>";return C(`[ListGen] \u2705 Generated OOXML for ${f.length} list items, total length: ${P.length}`),C(`[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 xr(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 Uo(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 jo(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 C(`[ListGen] Normalized ${a} composite list markers (e.g., "- A." -> "A.").`),o.join(`
136
+ `)}function Go(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 Vo(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 Ko=new Set(["officeonline","officeweb","web"]);function Yo(e){return e?Ko.has(String(e).toLowerCase()):!1}function Zo(){return typeof process<"u"&&process?.env?.NODE_ENV==="production"}function Jo(){return new Promise(e=>setTimeout(e,0))}var $e=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 ut,this.font=t.font||null,this.platform=t.platform??ir(),this.isWebPlatform=t.isWebPlatform??Yo(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}=kt(t,{xmlDoc:o}),u=i?dr(i):null;C(`[Reconcile] Ingested ${s.length} runs, ${l.length} chars, numbering:`,u),await this.maybeYield(s.length,Math.max(l.length,r?.length||0));let{cleanText:m,formatHints:f}=ne(r);C(`[Reconcile] Preprocessed: ${f.length} format hints`),await this.maybeYield(s.length,Math.max(l.length,m.length));let p=an(m),g=At(m),d=p||g;if(!p&&g&&C("[Reconcile] List-target detected via loose marker parsing; bypassing no-op short-circuit for structural conversion."),l===m&&f.length===0&&!d)return C("[Reconcile] No changes detected"),{ooxml:t,isValid:!0,warnings:["No changes detected"]};let w=Math.max(l.length,m.length)<this.disableSemanticCleanupOverChars,h=Mt(l,m,{cleanupSemantic:w});w||C("[Reconcile] Skipping semantic diff cleanup for large web payload"),await this.maybeYield(s.length,Math.max(l.length,m.length));let b=s.filter(v=>v.kind===O.PARAGRAPH_START).length;if(C(`[Reconcile] isTargetList: ${d}, paragraphCount: ${b}`),d)return C("[Reconcile] \u{1F3AF} ENTERING LIST GENERATION PATH"),C(`[Reconcile] cleanText preview: ${m.substring(0,100)}...`),C(`[Reconcile] acceptedText preview: ${l.substring(0,100)}...`),this.executeListGeneration(m,u,s);C(`[Reconcile] Computed ${h.length} diff operations`);let x=Lt(s,h);C(`[Reconcile] Split into ${x.length} runs`);let P=_t(x,h,{generateRedlines:this.generateRedlines,author:this.author,formatHints:f,numberingService:this.numberingService});C(`[Reconcile] Patched model has ${P.length} runs`),await this.maybeYield(P.length,Math.max(l.length,m.length));let N=fe(P,c,f,{author:this.author,generateRedlines:this.generateRedlines});if(this.shouldRunValidation()){let v=this.validateBasic(N);v.isValid||a.push(...v.errors)}return{ooxml:N,isValid:a.length===0,warnings:a}}catch(o){return Z("[Reconcile] Pipeline error:",o),{ooxml:t,isValid:!1,warnings:[`Pipeline error: ${o.message}`]}}}validateBasic(t){let r=[];try{let n=`<root xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">${t}</root>`,o=B().parseFromString(n,"application/xml"),i=j(o);i&&r.push("Generated OOXML is not well-formed XML: "+i.textContent.substring(0,100)),t.includes("<w:p")||r.push("Generated OOXML missing paragraph element")}catch(n){r.push(`Validation error: ${n.message}`)}return{isValid:r.length===0,errors:r}}shouldRunValidation(){return this.validateOutput?this.validationMode==="always"?!0:this.validationMode==="never"?!1:!(this.isWebPlatform&&Zo()):!1}async maybeYield(t,r){this.enableEventLoopYielding&&(t<=this.yieldRunThreshold&&r<=this.yieldCharThreshold||await Jo())}wrapForInsertion(t,r={}){return Ce(t,r)}async executeListGeneration(t,r,n,a=""){return Cn({cleanText:t,numberingContext:r,originalRunModel:n,originalText:a,generateRedlines:this.generateRedlines,author:this.author,font:this.font,numberingService:this.numberingService})}detectIndentationStep(t){return xr(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:Fe(r,{generateRedlines:this.generateRedlines,author:this.author}),isValid:!0,warnings:[],includeNumbering:!1}}};function W(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===S&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function A(e,t){return typeof e.createElementNS=="function"?e.createElementNS(S,t):e.createElement(t)}function qo(e,t){let r=Array.from(e?.getElementsByTagNameNS?.(S,t)||[]);return r.length>0?r:Array.from(e?.getElementsByTagName?.("*")||[]).filter(n=>W(n,t))}function Nr(e){return["ins","del","moveFrom","moveTo","moveFromRangeStart","moveFromRangeEnd","moveToRangeStart","moveToRangeEnd","rPrChange","pPrChange","cellIns","cellDel"].some(r=>qo(e,r).length>0)}function Qo(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:Qo(e.oxml)}}var ft=["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 Ze(e,t){let r=ft.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=ft.indexOf(o.nodeName);if((i===-1?999:i)>n){e.insertBefore(t,o),a=!0;break}}a||e.appendChild(t)}function ei(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"),Ze(t,c);let u=A(e,"w:bCs");u.setAttribute("w:val",n==="add"?"1":"0"),Ze(t,u)}if(o){let c=A(e,"w:i");c.setAttribute("w:val",n==="add"?"1":"0"),Ze(t,c);let u=A(e,"w:iCs");u.setAttribute("w:val",n==="add"?"1":"0"),Ze(t,u)}if(i){let c=A(e,"w:u");c.setAttribute("w:val",n==="add"?"single":"none"),Ze(t,c)}if(s){let c=A(e,"w:strike");c.setAttribute("w:val",n==="add"?"1":"0"),Ze(t,c)}}function An(e,t,r){ei(e,t,r,"remove")}function xe(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 Rn="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function de(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===Rn&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function ti(e){return!e||e.nodeType!==1||e.namespaceURI!==Rn?!1:e.localName==="del"||e.localName==="moveFrom"}function On(e){let t=[],r=Array.from(e?.childNodes||[]).reverse();for(;r.length>0;){let n=r.pop();if(!n||n.nodeType!==1||ti(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 Ne(e){let t=new Set(["comment","footnote","endnote"]);return V(e,"*","p").filter(n=>{let a=n.parentNode;for(;a&&a.nodeName;){let o=String(a.localName||"").toLowerCase();if(t.has(o))return!1;a=a.parentNode}return!0})}function kn(e){let t=[],r=0;for(let n=0;n<e.length;n++){let a=e[n],o=On(a);for(let i of o){let s=$(i,"w:rPr");Array.from(i.childNodes||[]).forEach(l=>{if(de(l,"t")){let c=l.textContent||"";c.length>0&&(t.push({charStart:r,charEnd:r+c.length,textElement:l,runElement:i,paragraph:a,container:i.parentNode,rPr:s}),r+=c.length)}else(de(l,"br")||de(l,"cr")||de(l,"tab")||de(l,"noBreakHyphen"))&&(t.push({charStart:r,charEnd:r+1,textElement:l,runElement:i,paragraph:a,container:i.parentNode,rPr:s}),r+=1)})}r=_e(r,n,e.length)}return{textSpans:t,charOffset:r}}function ri(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=xe(i);o&&(o.bold&&!s.bold&&(s.bold=!0),o.italic&&!s.italic&&(s.italic=!0),o.underline&&!s.underline&&(s.underline=!0),o.strikethrough&&!s.strikethrough&&(s.strikethrough=!0)),s.hasFormatting=s.bold||s.italic||s.underline||s.strikethrough;let l=r;for(let c of Array.from(e.childNodes))if(de(c,"t")){let u=c.textContent||"";if(u.length>0){let m=l,f=l+u.length;n.push({charStart:m,charEnd:f,textElement:c,runElement:e,paragraph:t,rPr:i,format:{...s}}),s.hasFormatting&&a.push({start:m,end:f,format:{...s},run:e,rPr:i}),l=f}}return l}function Mn(e){let t=[],r=[],n=0,a=Ne(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=xe(s);l.hasFormatting&&C(`[OxmlEngine] Found paragraph-level formatting: ${JSON.stringify(l)}`);let c=On(i);for(let u of c)n=ri(u,i,n,r,t,l);n=_e(n,o,a.length)}return C(`[OxmlEngine] Extracted ${r.length} text spans, ${t.length} format hints`),{existingFormatHints:t,textSpans:r,paragraphs:a}}function Xe(e,t,r,n){let a=A(e,t==="ins"?"w:ins":"w:del"),o=ee(n);return a.setAttribute("w:id",String(o.id)),a.setAttribute("w:author",o.author),a.setAttribute("w:date",o.date),r&&a.appendChild(r),a}function Ln(e,t){return Array.from(e?.childNodes||[]).find(r=>r.nodeType===1&&(r.localName===t||r.nodeName===`w:${t}`))||null}function ni(e,t){let r=Ln(t,"pPr");return r?t.firstChild!==r&&t.insertBefore(r,t.firstChild||null):(r=A(e,"w:pPr"),t.insertBefore(r,t.firstChild||null)),r}function ai(e,t){let r=Ln(t,"rPr");return r?t.lastChild!==r&&t.appendChild(r):(r=A(e,"w:rPr"),t.appendChild(r)),r}function _n(e,t,r,n){let a=ni(e,t),o=ai(e,a);for(let l of Array.from(o.childNodes||[]))l.nodeType===1&&(l.localName==="ins"||l.localName==="del"||l.nodeName==="w:ins"||l.nodeName==="w:del")&&o.removeChild(l);let i=A(e,n==="ins"?"w:ins":"w:del"),s=ee(r);return i.setAttribute("w:id",String(s.id)),i.setAttribute("w:author",s.author),i.setAttribute("w:date",s.date),o.appendChild(i),i}function Bn(e,t,r){return _n(e,t,r,"ins")}function Ft(e,t,r){return _n(e,t,r,"del")}function De(e,t,r,n){let a=A(e,"w:r");if(r&&a.appendChild(r.cloneNode(!0)),!n)return Fn(e,a,t),a;let o=A(e,n?"w:delText":"w:t");return o.setAttribute("xml:space","preserve"),o.textContent=t,a.appendChild(o),a}function $t(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={...xe(r)};w.forEach(x=>{x.format&&Object.assign(h,x.format)});let b=w.length>0?Je(e,r,h,o,i):r?.cloneNode(!0)||null;c.push(vr(e,p,b,!1))}return c}function vr(e,t,r,n){let a=A(e,"w:r");if(r&&a.appendChild(r),!n)return Fn(e,a,t),a;let o=A(e,n?"w:delText":"w:t");return o.setAttribute("xml:space","preserve"),o.textContent=t,a.appendChild(o),a}function Fn(e,t,r){let a=String(r||"").split(/(\t|\n|\u2011)/);for(let o of a){if(!o)continue;if(o===" "){t.appendChild(A(e,"w:tab"));continue}if(o===`
138
+ `){t.appendChild(A(e,"w:br"));continue}if(o==="\u2011"){t.appendChild(A(e,"w:noBreakHyphen"));continue}let i=A(e,"w:t");/^\s|\s$/.test(o)&&i.setAttribute("xml:space","preserve"),i.textContent=o,t.appendChild(i)}}function Je(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&&oi(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=ft.indexOf(l),g=p===-1?999:p,d=!1;for(let w of Array.from(o.childNodes)){if(w.nodeType!==1)continue;let h=ft.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 Tr(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");Array.from((a||t).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 oi(e,t,r,n){Tr(e,t,r,null,n||t)}var ii="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function qe(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===ii&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function Xt(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=si(l),u=yr(c),m=u.trim();a.push({paragraph:i,spans:l,text:c,normalizedText:u,normalizedTrim:m,startOffset:o}),o+=u.length,o=_e(o,s,t.length)}),a}function $n(e,t){if(!t)return null;let r=yr(t),n=r.trim();if(!n)return null;for(let a of e)if(a.normalizedText===r)return a;for(let a of e)if(a.normalizedTrim===n)return a;return null}function Xn(e,t){let r=yr(t),n=r.trim(),a=null,o=0;for(let i of e)if(i.normalizedText===r)return a=i,{targetInfo:a,matchOffset:o};if(n.length>0){for(let i of e)if(i.normalizedTrim===n)return a=i,{targetInfo:a,matchOffset:o}}if(n.length>0){let s=e.map(l=>l.normalizedText).join(`
139
+ `).indexOf(n);if(s!==-1)for(let l of e){let c=l.startOffset,u=l.normalizedText.length;if(s>=c&&s<=c+u){a=l,o=s-c;break}}}if(!a&&e.length===1&&r.length>0){let i=e[0],s=i.normalizedTrim||"";if(s.length>0){let l=r.indexOf(s);l>=0&&(a=i,o=-l)}}return{targetInfo:a,matchOffset:o}}function Dn(e){let t=e;for(;t;){if(qe(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;qe(n,"t")?t+=r.textElement.textContent||"":qe(n,"tab")?t+=" ":qe(n,"br")||qe(n,"cr")?t+=`
140
+ `:qe(n,"noBreakHyphen")&&(t+="\u2011")}return t}function yr(e){return e?e.replace(/\r/g,`
141
+ `).replace(/\u00a0/g," "):""}function zn(e,t,r){let n=Array.from(new Set(r)).sort((s,l)=>s-l);if(n.length===0||t.length===0)return[...t];let a=[...t].sort((s,l)=>s.charStart-l.charStart||s.charEnd-l.charEnd),o=[],i=0;for(let s of a){for(;i<n.length&&n[i]<=s.charStart;)i++;let l=s;for(;i<n.length&&n[i]<l.charEnd;){let c=n[i],u=li(e,l,c);if(!u){i++;continue}o.push(u[0]),l=u[1],i++}o.push(l)}return o}function li(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=De(e,s,t.rPr,!1),u=De(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 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 Wn(e,t,r,n,a,o=!0){let i=!1,s=new Set;C(`[OxmlEngine] Surgical format removal: ${r.length} hints to process (using w:rPrChange)`);for(let l of r){let c=l.run;if(s.has(c)||(s.add(c),!c.parentNode))continue;C("[OxmlEngine] Processing run for surgical format removal, format:",l.format);let u=$(c,"w:rPr");u||(u=A(e,"w:rPr"),c.insertBefore(u,c.firstChild)),o&&Tr(e,u,a||J()),An(e,u,l.format),i=!0}return i?(C("[OxmlEngine] Surgical format removal completed successfully (Pure Format Mode)"),{oxml:n.serializeToString(e),hasChanges:!0}):(C("[OxmlEngine] No format changes were applied"),{oxml:n.serializeToString(e),hasChanges:!1})}function mi(e,t,r,n,a,o=!0){let i=!1,s=new Set;if(!t||t.length===0)return{oxml:n.serializeToString(e),hasChanges:!1};let l=[];for(let f of r)l.push(f.start,f.end);let u=zn(e,t,l).slice().sort((f,p)=>f.charStart-p.charStart||f.charEnd-p.charEnd),m=pi(r);for(let f of u){if(!f||!f.textElement||!ui(f.textElement,"t"))continue;let p=m(f.charStart,f.charEnd);if(p.length===0)continue;let g=sr(...p.map(R=>R.format)),d={bold:!!g.bold,italic:!!g.italic,underline:!!g.underline,strikethrough:!!g.strikethrough},w=f.format||xe(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 v=f.runElement,y=$(v,"w:rPr"),E=Je(e,y,d,a||J(),o),I=y;if(!I)v.insertBefore(E,v.firstChild);else{for(;I.firstChild;)I.removeChild(I.firstChild);Array.from(E.childNodes).forEach(R=>I.appendChild(R))}i=!0}return{oxml:n.serializeToString(e),hasChanges:i}}function Hn(e,t,r,n,a,o=!0,i=null){let s=fi(i),l=s.paragraphs||Ne(e),c=s.textSpans||[];if(s.textSpans||({textSpans:c}=kn(l)),!c||c.length===0)return Le("[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||Xt(e,l,c),{targetInfo:m,matchOffset:f}=Xn(u,t);if(!m||!m.spans||m.spans.length===0)return Le("[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 mi(e,g,d,n,a,o)}function pi(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 gi="http://schemas.microsoft.com/office/word/2010/wordml";function Un(e,t,r={}){let{targetParagraphId:n=null}=r,a=ue(e,S,"tbl");if(a.length===0)return{hasTableWrapper:!1,isTableCellParagraph:!1,paragraphs:[],paragraph:null,tableElement:null};let i=Ne(e).filter(l=>{let c=l.parentNode;for(;c;){if(W(c,"tc"))return!0;c=c.parentNode}return!1});C(`[OxmlEngine] Table wrapper detected: ${a.length} tables, ${i.length} paragraphs in cells`);let s=null;if(n){let l=String(n).toUpperCase();s=i.find(c=>{let u=hi(c);return u&&u.toUpperCase()===l})||null,s?C(`[OxmlEngine] Found target paragraph by paraId: "${n}"`):C(`[OxmlEngine] paraId "${n}" not found in wrapper, falling back to text match`)}if(t&&t.trim()){let l=t.trim();if(!s)for(let c of i){let u=ue(c,S,"t"),m="";for(let f of u)m+=f.textContent||"";if(m.trim()===l){s=c,C(`[OxmlEngine] Found target paragraph by text match: "${l.substring(0,30)}..."`);break}}}return{hasTableWrapper:!0,isTableCellParagraph:i.length>0,targetParagraph:s,paragraphs:i,paragraph:s||i[0]||null,tableElement:a[0]}}function mt(e,t,r){let n=Array.isArray(t)?t:[t],a="";for(let o of n){if(!o)continue;let i=r.serializeToString(o);i=i.replace(/\s+xmlns:w="[^"]*"/g,""),i=i.replace(/\s+xmlns:r="[^"]*"/g,""),i=i.replace(/\s+xmlns:wp="[^"]*"/g,""),a+=i}return C(`[OxmlEngine] Stripping table wrapper, serializing ${n.length} paragraphs`),C(`[OxmlEngine] Paragraph XML preview: ${a.substring(0,200)}...`),di(a)}function di(e){return yn(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 Er(e){return W(e,"t")?e.textContent||"":W(e,"br")||W(e,"cr")?`
142
+ `:W(e,"tab")?" ":W(e,"noBreakHyphen")?"\u2011":""}function Pr(e){return W(e,"t")||W(e,"br")||W(e,"cr")||W(e,"tab")||W(e,"noBreakHyphen")}function Gn(e){let t="",r=[];return e.forEach((n,a)=>{let o=n.parentNode;for(let i=n.firstChild;i;i=i.nextSibling)if(W(i,"r"))t+=jn(i,n,o,t.length,r).text;else if(W(i,"hyperlink"))for(let s=i.firstChild;s;s=s.nextSibling)W(s,"r")&&(t+=jn(s,n,o,t.length,r).text);t=Ve(t,a,e.length)}),{fullText:t,textSpans:r}}function jn(e,t,r,n,a){let o=$(e,"w:rPr"),i=n,s=[];for(let l=e.firstChild;l;l=l.nextSibling)if(W(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(Pr(l)){let c=Er(l);a.push({charStart:i,charEnd:i+1,textElement:l,runElement:e,paragraph:t,container:r,rPr:o}),i+=1,s.push(c)}return{text:s.join("")}}function Vn(e){let t=e.slice().sort((a,o)=>a.charStart-o.charStart||a.charEnd-o.charEnd),r=t.map(a=>a.charStart),n=t.map(a=>a.charEnd);return{spans:t,starts:r,ends:n}}function Dt(e,t,r,n){if(r<=t||e.spans.length===0)return;let a=Sr(e.ends,t);for(;a<e.spans.length;){let o=e.spans[a];if(o.charStart>=r)break;n(o),a++}}function Kn(e,t){if(e.spans.length===0)return null;let r=Sr(e.starts,t)-1;if(r<0)return null;let n=e.spans[r];return t>=n.charStart&&t<n.charEnd?n:null}function Yn(e,t){let r=wi(e.ends,t);return r<e.spans.length&&e.ends[r]===t?e.spans[r]:null}function Zn(e,t){let r=Sr(e.ends,t)-1;return r>=0?e.spans[r]:null}function Sr(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 wi(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 Ir(e){let t=[],r=0;for(let n of Array.from(e.childNodes||[])){if(W(n,"rPr")||!Pr(n))continue;let a=Er(n);a.length!==0&&(t.push({node:n,start:r,end:r+a.length,text:a}),r+=a.length)}return t}function pt(e){return e.length===0?0:e[e.length-1].end}function Qe(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(bi(e,i.node,m,a))}),o}function Cr(e,t,r){let n=A(e,"w:r");return r&&n.appendChild(r.cloneNode(!0)),t.forEach(a=>n.appendChild(a)),n}function gt(e,t,r,n,a){if(n.length===0)return null;let o=Cr(e,n,a);return t.insertBefore(o,r),o}function bi(e,t,r,n){if(n){let o=A(e,"w:delText");return o.setAttribute("xml:space","preserve"),o.textContent=r,o}if(W(t,"t")){let o=t.cloneNode(!1);return o.textContent=r,/^\s|\s$/.test(r)&&o.setAttribute("xml:space","preserve"),o}if(r===`
143
+ `&&(W(t,"br")||W(t,"cr"))||r===" "&&W(t,"tab")||r==="\u2011"&&W(t,"noBreakHyphen"))return t.cloneNode(!0);let a=A(e,"w:t");return a.setAttribute("xml:space","preserve"),a.textContent=r,a}function Jn(e,t,r,n,a,o,i){if(a.length===0)return!1;let s=t.rPr,l=xe(s),c={...l};if(a.forEach(v=>Object.assign(c,v.format)),!["bold","italic","underline","strikethrough"].some(v=>!!c[v]!==l[v]))return!1;let f=t.runElement.parentNode;if(!f)return!1;let p=t.textElement.textContent||"",g=t.charStart,d=r-g,w=n-g,h=p.substring(0,d),b=p.substring(d,w),x=p.substring(w);if(h.length>0){let v=De(e,h,s,!1);f.insertBefore(v,t.runElement)}let P=Je(e,s,c,o,i),N=vr(e,b,P,!1);if(f.insertBefore(N,t.runElement),x.length>0){let v=De(e,x,s,!1);f.insertBefore(v,t.runElement)}return f.removeChild(t.runElement),!0}function qn(e,t,r,n,a,o){let i=[];if(Dt(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=Ir(u);if(f.length===0)return;let p=1/0,g=-1/0;if(c.forEach(b=>{let x=f.find(v=>v.node===b.textElement);if(!x)return;let P=Math.max(0,r-b.charStart),N=Math.min(b.charEnd-b.charStart,n-b.charStart);N<=P||(p=Math.min(p,x.start+P),g=Math.max(g,x.start+N))}),!Number.isFinite(p)||g<=p)return;let d=Qe(e,f,0,p,!1),w=Qe(e,f,p,g,!0),h=Qe(e,f,g,pt(f),!1);if(gt(e,m,u,d,c[0].rPr),o&&w.length>0){let b=Cr(e,w,c[0].rPr),x=Xe(e,"del",b,a);m.insertBefore(x,u)}gt(e,m,u,h,c[0].rPr),m.removeChild(u),l=!0}),l}function Qn(e,t,r,n,a,o=[],i=0,s=!0,l=null){let c=Kn(t,r);if(!c&&r>0&&(c=Yn(t,r)),!c&&r>0&&(c=Zn(t,r)),!c&&t.spans.length>0&&(c=t.spans[t.spans.length-1]),!c)return l?(zt(e,l,null,n,null,a,o,i,s),!0):!1;let u=c.runElement.parentNode;if(!u)return l?(zt(e,l,null,n,c.rPr,a,o,i,s),!0):!1;let m=Ir(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:pt(m);if(p>0&&p<pt(m)){let d=Qe(e,m,0,p,!1),w=Qe(e,m,p,pt(m),!1);return gt(e,u,c.runElement,d,c.rPr),zt(e,u,c.runElement,n,c.rPr,a,o,i,s),gt(e,u,c.runElement,w,c.rPr),u.removeChild(c.runElement),!0}let g=r<=c.charStart?c.runElement:c.runElement.nextSibling;return zt(e,u,g,n,c.rPr,a,o,i,s),!0}function zt(e,t,r,n,a,o,i,s,l){let c=we(i,s,s+n.length);if(c.length===0){let m=De(e,n,a,!1);if(l){let f=Xe(e,"ins",m,o);t.insertBefore(f,r)}else t.insertBefore(m,r);return}let u=$t(e,n,a,c,s,o,l);if(l){let m=Xe(e,"ins",null,o);u.forEach(f=>m.appendChild(f)),t.insertBefore(m,r)}else u.forEach(m=>t.insertBefore(m,r))}function ea(e,t,r,n,a,o,i=!0,s=null){let l=s?[s]:Ne(e),{fullText:c,textSpans:u}=Gn(l),m=ct(c,r),f=Vn(u),p=0,g=0,d=!1;for(let[w,h]of m)if(w===0){let b=h.length,x=p,P=p+b;Dt(f,x,P,N=>{let v=Math.max(N.charStart,x),y=Math.min(N.charEnd,P),E=y-v,I=v-x,R=g+I,M=R+E,L=we(o,R,M);Jn(e,N,v,y,L,a,i)&&(d=!0)}),p+=b,g+=b}else if(w===-1)qn(e,f,p,p+h.length,a,i)&&(d=!0),p+=h.length;else if(w===1){let b=h.replace(/\n/g," ");b.trim().length>0&&Qn(e,f,p,b,a,o,g,i,l[0]||null)&&(d=!0),g+=h.length}return te({oxml:n.serializeToString(e),hasChanges:d})}function ta(e){let t=0;return{at(r){for(;t<e.length&&e[t].end<=r;)t++;let n=e[t];return n&&n.start<=r&&r<n.end?n:null}}}function xi(e){let t=new Map;return e.forEach(r=>{t.has(r.start)||t.set(r.start,[]),t.get(r.start).push(r)}),t}function ra(e,t){let r=e.documentElement,n=r.nodeName==="w:body"||r.nodeName.endsWith(":package"),a=Ne(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((E,I)=>{let R=i.length;Array.from(E.childNodes).forEach(Ee=>{i=vi(Ee,i,s,c,u,m,f),u.size>m.size&&f++}),i=Ve(i,I,a.length);let M=i.length,L=$(E,"w:pPr"),le=E.parentNode;le&&p.add(le),l.push({start:R,end:M,pPr:L,container:le||o})});let g=t;m.forEach((E,I)=>{let R=I.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");g=g.replace(new RegExp(R,"g"),E)}),g=Ni(i,g,u);let d=new Map;p.forEach(E=>{d.set(E,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(E=>E.start)),b=ta(l),x=ta(s),P=xi(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:E=>{let I=b.at(E);return I||(l.length>0?l[l.length-1]:{start:0,end:0,pPr:null,container:o||e})},getRunProperties:E=>{let I=x.at(E);return I?{rPr:I.rPr,wrapper:I.wrapper}:{rPr:null}},getPropertySpanLength:(E,I)=>{let R=x.at(E);return R?Math.min(R.end-E,I):1},isParagraphStart:E=>h.has(E)}}function Ni(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 vi(e,t,r,n,a,o,i){return e.nodeName==="w:r"?Ti(e,t,r,n,a,o,i):e.nodeName==="w:hyperlink"?yi(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 Ti(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 yi(e,t,r){let n=t;return Array.from(e.childNodes).forEach(a=>{if(a.nodeName!=="w:r")return;let o=$(a,"w:rPr");Se(a,"w:t").forEach(s=>{let l=s.textContent||"";l.length!==0&&(r.push({start:n.length,end:n.length+l.length,rPr:o,wrapper:e}),n+=l)})}),n}function aa(e,t,r,n,a,o,i=!0){let{paragraphs:s,paragraphMap:l,containerFragments:c,sentinelMapByStart:u,referenceMap:m,replacementContainers:f,getParagraphInfo:p,getRunProperties:g,getPropertySpanLength:d,isParagraphStart:w}=r,h=E=>{let I=A(e,"w:p");return E&&I.appendChild(E.cloneNode(!0)),I},b=p(0),x=h(b.pPr),P=c.get(b.container);P&&P.appendChild(x);let N=0,v=0,y=new WeakSet;for(let[E,I]of t){if(E===0||E===-1){let R=E===0?"equal":"delete",M=0;for(;M<I.length;){let L=N+M,le=g(L),Ee=d(L,I.length-M),he=I.substring(M,M+Ee);x=na(e,he,R,le.rPr,le.wrapper,L,x,c,u,m,f,p,h,a,o,v,i,y).currentParagraph,E===0&&(v+=Ee),M+=Ee}N+=I.length;continue}if(E===1){let R=N>0&&!w(N)?g(N-1):g(N);x=na(e,I,"insert",R.rPr,R.wrapper,N,x,c,u,m,f,p,h,a,o,v,i,y).currentParagraph,v+=I.length}}return s.forEach(E=>{E.parentNode&&E.parentNode.removeChild(E)}),c.forEach((E,I)=>{let M=f.get(I)||I;if(M.nodeType===9){let L=E.firstChild;if(L)for(M.appendChild(L);E.firstChild;)M.documentElement.appendChild(E.firstChild);return}M.appendChild(E)}),{oxml:n.serializeToString(e),hasChanges:!0}}function na(e,t,r,n,a,o,i,s,l,c,u,m,f,p,g=[],d=0,w=!0,h=new WeakSet){let b=o,x=d,P=i;return t.split(/([\n\uFFFC]|[\uE000-\uF8FF])/).forEach(v=>{let y=l.get(b)||[];if(y.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))}),v===`
145
+ `){let R=m(b+1),M=f(R.pPr);w&&r==="insert"?Bn(e,M,p):w&&r==="delete"&&Ft(e,M,p);let L=s.get(R.container);L&&(L.appendChild(M),P=M),b++,r!=="delete"&&x++;return}if(v==="\uFFFC"){let R=y.find(M=>!M.isCommentMarker)||y[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(v)){if(r!=="delete"){let R=c.get(v);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(v.length===0)return;let I=P;if(a){let R=a.cloneNode(!1);I=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=v,R.appendChild(M),w){let L=Xe(e,"del",R,p);I.appendChild(L)}}else{let R=we(g,x,x+v.length),M=$t(e,v,n,R,x,p,w);if(r==="insert"&&w){let L=Xe(e,"ins",null,p);M.forEach(le=>L.appendChild(le)),I.appendChild(L)}else M.forEach(L=>I.appendChild(L))}r!=="delete"&&(x+=v.length),b+=v.length}),{currentParagraph:P}}function Ar(e,t,r,n,a,o,i=!0){let s=ra(e,r);if(s.paragraphs.length===0)return te({oxml:n.serializeToString(e),hasChanges:!1});let l=ct(s.originalFullText,s.processedModifiedText);return te(aa(e,l,s,n,a,o,i))}function Ae(e,t){return te({oxml:e.serializeToString(t),hasChanges:!1})}function oa(e,t,r,n,a,o=!0){let i=ue(e,S,"tbl"),s=me(t),l=s.rows.length>0||s.headers.length>0;if(i.length===0||!l)return Ae(r,e);let c=i[0],u=wr(c),m=Sn(u,s);if(m.length===0)return Ae(r,e);let p=In(u,m,{generateRedlines:o,author:a}),g=`<root xmlns:w="${S}">${p}</root>`,w=(n||B()).parseFromString(g,"application/xml"),h=j(w);if(h)return Z("[OxmlEngine] Failed to parse reconciled table OOXML:",h.textContent),Ae(r,e);let b=Ot(w,S,"tbl");if(!b)return Z("[OxmlEngine] No table found in reconciled OOXML"),Ae(r,e);let x=e.importNode(b,!0);return c.parentNode.replaceChild(x,c),te({oxml:r.serializeToString(e),hasChanges:!0})}function ia(e,t,r,n,a,o){let i=me(t);if(!i||i.rows.length===0&&i.headers.length===0)return C("[OxmlEngine] Failed to parse table data from Markdown"),Ae(r,e);let s=Fe(i,{generateRedlines:o,author:a}),l=n||B(),c=l.parseFromString(`<root xmlns:w="${S}">${s}</root>`,"application/xml"),u=j(c);if(u)return Z("[OxmlEngine] Failed to parse generated table OOXML:",u.textContent),Ae(r,e);let m=H(c,S,"tbl");if(m||(m=H(c,S,"ins")),!m)return Z("[OxmlEngine] No table element found in generated OOXML"),Ae(r,e);let f=e,p=V(f,S,"p");if(p.length===0)return C("[OxmlEngine] No paragraphs found to replace"),Ae(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=>{Ft(f,h,a),V(h,S,"r").forEach(x=>{V(x,S,"t").forEach(y=>{let E=y.textContent||"";if(E.trim()){let I=A(f,"w:delText");I.textContent=E,y.parentNode.replaceChild(I,y)}});let N=A(f,"w:del"),v=ee(a);N.setAttribute("w:id",String(v.id)),N.setAttribute("w:author",v.author),N.setAttribute("w:date",v.date),x.parentNode.insertBefore(N,x),N.appendChild(x)})}):p.slice(1).forEach(h=>h.parentNode.removeChild(h)),d.insertBefore(w,g),o||d.removeChild(g),C("[OxmlEngine] Text-to-table transformation complete"),te({oxml:r.serializeToString(f),hasChanges:!0})}function ze(e,t){if(!e||!e.attributes)return"";for(let r of Array.from(e.attributes))if((r.localName||"").toLowerCase()===t.toLowerCase())return String(r.value||"");return String(e.getAttribute?.(`w:${t}`)||e.getAttribute?.(t)||"")}function ca(e){return typeof e=="string"?e.trim().toLowerCase():""}function Ei(e){return!!e&&e.nodeType===1}function Re(e,t){return Ei(e)&&e.namespaceURI===S&&String(e.localName||"").toLowerCase()===t.toLowerCase()}function re(e,t){return Array.from(e.getElementsByTagNameNS(S,t))}function Rr(e={}){if(e?.allAuthors===!0)return{valid:!0,allAuthors:!0,normalizedAuthor:""};let t=ca(e?.author);return t?{valid:!0,allAuthors:!1,normalizedAuthor:t}:{valid:!1,allAuthors:!1,normalizedAuthor:"",warning:"No author provided. Pass { author } or set { allAuthors: true }."}}function ie(e,t){if(t.allAuthors)return!0;let r=ca(ze(e,"author"));return!!r&&r===t.normalizedAuthor}function Or(e,t){let n=B().parseFromString(e,"application/xml"),a=j(n);return a?{xmlDoc:null,serializer:null,warning:`${t}: ${a.textContent||"parse error"}`}:{xmlDoc:n,serializer:Q(),warning:null}}function Y(e){return e?.parentNode?(e.parentNode.removeChild(e),!0):!1}function Wt(e){let t=e?.parentNode;if(!t)return!1;for(;e.firstChild;)t.insertBefore(e.firstChild,e);return t.removeChild(e),!0}function Ht(e){let t=e?.parentNode;return Re(t,"trPr")&&Re(t?.parentNode,"tr")}function kr(e){let t=e?.parentNode,r=t?.parentNode,n=r?.parentNode;return Re(t,"rPr")&&Re(r,"pPr")&&Re(n,"p")}function ua(e){return kr(e)?e.parentNode.parentNode.parentNode:null}function Pi(e){let t=e?.nextSibling||null;for(;t;){if(Re(t,"p"))return t;t=t.nextSibling}return null}function fa(e){if(!e?.parentNode)return!1;let t=Pi(e);if(!t)return Y(e);let r=Array.from(e.childNodes||[]).filter(a=>!Re(a,"pPr")),n=t.firstChild||null;for(let a of r)t.insertBefore(a,n);return Y(e)}function Mr(e,t={}){let r=[],n=Rr(t);if(!n.valid)return{oxml:e,hasChanges:!1,acceptedCount:0,warnings:[n.warning]};let a=Or(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(kr(c)){Y(c)&&(s+=1);continue}if(Ht(c)){Y(c)&&(s+=1);continue}Wt(c)&&(s+=1)}for(let c of re(o,"del")){if(!c.parentNode||!ie(c,n))continue;let u=ua(c);if(u){fa(u)&&(s+=1);continue}if(Ht(c)){let m=c.parentNode?.parentNode;Y(m)&&(s+=1);continue}Y(c)&&(s+=1)}for(let c of re(o,"moveFrom"))!c.parentNode||!ie(c,n)||Y(c)&&(s+=1);for(let c of re(o,"moveTo"))!c.parentNode||!ie(c,n)||Wt(c)&&(s+=1);s+=ma(o,n);let l=["rPrChange","pPrChange","tblPrChange","trPrChange","tcPrChange"];for(let c of l)for(let u of re(o,c))!u.parentNode||!ie(u,n)||Y(u)&&(s+=1);return{oxml:i.serializeToString(o),hasChanges:s>0,acceptedCount:s,warnings:r}}function sa(e,t){for(let r of Array.from(t.getElementsByTagNameNS(S,"delText"))){let n=A(e,"w:t"),a=r.getAttribute("xml:space");for(a&&n.setAttribute("xml:space",a);r.firstChild;)n.appendChild(r.firstChild);r.parentNode?.replaceChild(n,r)}}function Si(e,t){let r=e?.parentNode;if(!r)return!1;let n=t.endsWith("Change")?t.slice(0,-6):"";if(!n||String(r.localName||"").toLowerCase()!==n.toLowerCase()||r.namespaceURI!==S)return Y(e);let a=Array.from(e.childNodes||[]).find(i=>i.nodeType===1&&i.namespaceURI===S&&String(i.localName||"").toLowerCase()===n.toLowerCase());if(!a)return Y(e);let o=Array.from(a.childNodes||[]);for(;r.firstChild;)r.removeChild(r.firstChild);for(let i of o){let s=Ii(r.ownerDocument,i);r.appendChild(s)}return!0}function Ii(e,t){return e&&typeof e.importNode=="function"?e.importNode(t,!0):t.cloneNode(!0)}function la(e,t,r){let n=new Set;for(let a of re(e,t)){if(!ie(a,r))continue;let o=ze(a,"id");o&&n.add(o)}return n}function ma(e,t){let r=0,n=la(e,"moveFromRangeStart",t),a=la(e,"moveToRangeStart",t),o=[["moveFromRangeStart",n,!0],["moveFromRangeEnd",n,!1],["moveToRangeStart",a,!0],["moveToRangeEnd",a,!1]];for(let[i,s,l]of o)for(let c of re(e,i)){if(!c.parentNode)continue;let u=ze(c,"id");u&&(t.allAuthors||s.has(u)||l&&ie(c,t))&&Y(c)&&(r+=1)}return r}function Ci(e,t={}){let r=[],n=Rr(t);if(!n.valid)return{oxml:e,hasChanges:!1,rejectedCount:0,warnings:[n.warning]};let a=Or(e,"Failed to parse OOXML");if(!a.xmlDoc)return{oxml:e,hasChanges:!1,rejectedCount:0,warnings:[a.warning]};let{xmlDoc:o,serializer:i}=a,s=0;for(let c of re(o,"ins")){if(!c.parentNode||!ie(c,n))continue;let u=ua(c);if(u){fa(u)&&(s+=1);continue}if(Ht(c)){let m=c.parentNode?.parentNode;Y(m)&&(s+=1);continue}Y(c)&&(s+=1)}for(let c of re(o,"del"))if(!(!c.parentNode||!ie(c,n))){if(kr(c)){Y(c)&&(s+=1);continue}if(Ht(c)){Y(c)&&(s+=1);continue}sa(o,c),Wt(c)&&(s+=1)}for(let c of re(o,"moveFrom"))!c.parentNode||!ie(c,n)||(sa(o,c),Wt(c)&&(s+=1));for(let c of re(o,"moveTo"))!c.parentNode||!ie(c,n)||Y(c)&&(s+=1);s+=ma(o,n);let l=["rPrChange","pPrChange","tblPrChange","trPrChange","tcPrChange"];for(let c of l)for(let u of re(o,c))!u.parentNode||!ie(u,n)||Si(u,c)&&(s+=1);return{oxml:i.serializeToString(o),hasChanges:s>0,rejectedCount:s,warnings:r}}function Ai(e,t){let r=new Set,n=re(e,"comment");for(let a of n){if(!ie(a,t))continue;let o=ze(a,"id");o&&r.add(o)}return{targetIds:r,commentNodes:n}}function Ri(e,t){let r=0;for(let n of e){let a=ze(n,"id");!a||!t.has(a)||Y(n)&&(r+=1)}return r}function Oi(e){return Re(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 ki(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=ze(o,"id");if(!(!i||!t.has(i))){if(a==="commentReference"&&Oi(o.parentNode)){Y(o.parentNode)&&(r+=1);continue}Y(o)&&(r+=1)}}return r}function Mi(e,t={}){let r=[],n=Rr(t);if(!n.valid)return{oxml:e,hasChanges:!1,commentsRemoved:0,referencesRemoved:0,warnings:[n.warning]};let a=Or(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}=Ai(o,n);if(n.allAuthors)for(let m of["commentRangeStart","commentRangeEnd","commentReference"])for(let f of re(o,m)){let p=ze(f,"id");p&&s.add(p)}let c=Ri(l,s),u=ki(o,s);return{oxml:i.serializeToString(o),hasChanges:c>0||u>0,commentsRemoved:c,referencesRemoved:u,warnings:r}}async function Lr(e,t,r,n={}){let a=n.generateRedlines??!0,o=n.author||J(),i=B(),s=Q(),l=U=>{let X={...U};return X.status||(X.status=X.hasChanges?"ok":"no-op"),te(X)},c=()=>l({oxml:e,hasChanges:!1}),u;try{u=i.parseFromString(e,"text/xml")}catch(U){return Z("[OxmlEngine] Failed to parse OXML:",U),l({oxml:e,hasChanges:!1,status:"error",error:{code:"PARSE_ERROR",message:"Could not parse OOXML input."}})}let m=j(u);if(m)return Z("[OxmlEngine] XML parse error:",m.textContent),l({oxml:e,hasChanges:!1,status:"error",error:{code:"PARSE_ERROR",message:m.textContent||"Could not parse OOXML input."}});if(ur(u),Nr(u))if((n.existingRevisions||"reject-input")==="accept-all-first"){C("[OxmlEngine] Existing revisions detected; accepting all input revisions before redlining"),e=Mr(e,{allAuthors:!0}).oxml,u=i.parseFromString(e,"text/xml");let ge=j(u);if(ge)return Z("[OxmlEngine] XML parse error after accepting existing revisions:",ge.textContent),l({oxml:e,hasChanges:!1,status:"error",error:{code:"PARSE_ERROR",message:"Could not parse OOXML after accepting existing revisions."}});ur(u)}else return C("[OxmlEngine] Existing revisions detected; rejecting input per existingRevisions policy"),l({oxml:e,hasChanges:!1,status:"error",error:{code:"EXISTING_REVISIONS",message:'Input OOXML contains existing tracked changes. Pass existingRevisions: "accept-all-first" to normalize before redlining.'}});let f=Un(u,t,n);if(f.hasTableWrapper&&f.targetParagraph&&!n._isolatedTableCell){C("[OxmlEngine] Isolating table-cell paragraph before diff");let U=mt(u,f.targetParagraph,s);return Lr(U,t,r,{...n,_isolatedTableCell:!0})}let p=ga(r),{cleanText:g,formatHints:d}=ne(p),w=g.trim()!==t.trim(),h=d.length>0,{existingFormatHints:b,textSpans:x,paragraphs:P}=Mn(u),N=b.length>0,v=x.map(U=>Li(U)).join("");if(w&&typeof t=="string"&&t.trim()&&!t.includes(`
146
+ `)&&!v.includes(t.trim())&&!v.replace(/[\t\n\u2011]/g,"").includes(t.trim().replace(/[\t\n\u2011]/g,""))&&!pa(v).includes(pa(t)))return C("[OxmlEngine] Target text not found in OOXML"),l({oxml:e,hasChanges:!1,status:"error",error:{code:"TARGET_NOT_FOUND",message:"Original text was not found in the supplied OOXML."}});let y=null,E=()=>(y||(y=Xt(u,P,x)),y),I=(U=null)=>{let X=Hn(u,t,d,s,o,a,U);return X.useNativeApi?(C("[OxmlEngine] Format-only surgical fallback signal encountered; retrying with OOXML reconstruction fallback"),Ar(u,t,g,s,o,d,a)):X};C(`[OxmlEngine] Text changes: ${w}, New format hints: ${d.length}, Existing format hints: ${b.length}`);let R=!w&&!h&&N;if(!w&&!h&&!N)return C("[OxmlEngine] No text changes, no format hints, and no existing formatting detected"),c();if(R){C("[OxmlEngine] Format REMOVAL detected: applying surgical replacement in OOXML");let U=f,X=U.targetParagraph||null;if(!X){let Pt=$n(E(),t);Pt&&(X=Pt.paragraph)}let ge=b;X&&(ge=b.filter(Pt=>Dn(Pt.run)===X));let qr=Wn(u,x,ge,s,o,a);return U.hasTableWrapper&&X?l({oxml:mt(u,X,s),hasChanges:qr.hasChanges}):l(qr)}if(!w&&h){C(`[OxmlEngine] Format-only change detected: ${d.length} format hints`);let U=f,X={textSpans:x,paragraphs:P,paragraphInfos:E()};if(U.hasTableWrapper&&U.targetParagraph){C("[OxmlEngine] Table cell context: applying formatting to target paragraph only");let ge=I(X);return C("[OxmlEngine] Stripping table wrapper for table cell paragraph (format-only)"),l({oxml:mt(u,U.targetParagraph,s),hasChanges:ge.hasChanges})}return l(I(X))}let L=ue(u,S,"tbl").length>0,le=/^\|.+\|/.test(g.trim())&&g.includes(`
147
+ `),Ee=At(g),he=f;if(C(`[OxmlEngine] Mode: ${L?"SURGICAL":"RECONSTRUCTION"}, formatHints: ${d.length}, isMarkdownTable: ${le}, isTargetList: ${Ee}, isTableCellParagraph: ${he.isTableCellParagraph}`),le&&!L)return C("[OxmlEngine] Text-to-table transformation: generating new table from Markdown"),l(ia(u,g,s,i,o,a));if(L&&le)return l(oa(u,g,s,i,o,a));if(L){let U=he.hasTableWrapper&&he.targetParagraph?he.targetParagraph:null;U&&C("[OxmlEngine] Table cell edit: scoping surgical mode to target paragraph");let X=ea(u,t,g,s,o,d,a,U);return he.hasTableWrapper&&X.hasChanges&&he.targetParagraph?(C("[OxmlEngine] Stripping table wrapper for table cell paragraph (surgical mode)"),l({oxml:mt(u,he.targetParagraph,s),hasChanges:!0})):l(X)}if(Ee){C("[OxmlEngine] \u{1F3AF} Using reconciliation pipeline for list generation");let X=await new $e({author:o,generateRedlines:a}).execute(e,r,{xmlDoc:u});if(X.isValid&&X.ooxml&&X.ooxml!==e){C(`[OxmlEngine] Wrapping list OOXML with numbering definitions, includeNumbering=${X.includeNumbering}`);let ge=Ce(X.ooxml,{includeNumbering:X.includeNumbering??!0,numberingXml:X.numberingXml});return C(`[OxmlEngine] \u2705 Wrapped OOXML length: ${ge.length}`),l({oxml:ge,hasChanges:!0})}return c()}return l(Ar(u,t,g,s,o,d,a))}function pa(e){return String(e||"").replace(/[\t\n\u2011]/g," ").replace(/\s+/g," ").trim()}function Li(e){let t=e?.textElement,r=String(t?.localName||t?.nodeName||"").replace(/^.*:/,"");return r==="tab"?" ":r==="br"||r==="cr"?`
148
+ `:r==="noBreakHyphen"?"\u2011":t?.textContent||""}function ga(e){let t=e;return t=t.replace(/^(Here is the redline:|Here is the text:|Sure, I can help:|Here's the updated text:)\s*/i,""),t=t.replace(/\$\\text\{/g,"").replace(/\}\$/g,""),t=t.replace(/\$([^0-9\n]+?)\$/g,"$1"),t=t.replace(/\\r\\n/g,`
149
149
  `).replace(/\\n/g,`
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`
150
+ `),t}function ve(e){return St(e,"application/xml")}function We(e){return K(e)}function _r(e){return Array.from(e||[])}var se="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function Br(e,t){if(!e)return[];if(typeof e.getElementsByTagNameNS=="function"){let n=_r(e.getElementsByTagNameNS("*",t));if(n.length>0)return n}if(typeof e.getElementsByTagName!="function")return[];let r=_r(e.getElementsByTagName(`w:${t}`));return r.length>0?r:_r(e.getElementsByTagName(t))}function _i(e){return Br(e,"t").map(r=>r.textContent||"").join("")}function G(e){return e?_i(e):""}function Te(e){if(!e)return[];let t=Br(e,"body"),r=t.length>0?t[0]:e;return Br(r,"p")}function _(e){return String(e||"").replace(/\s+/g," ").trim()}function Xr(e){let t=String(e||"").trim();return/^\|.+\|/.test(t)&&t.includes(`
151
+ `)}function Dr(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 Bi(e){return e==null?"":String(e).replace(/^\s*\[P\d+(?:\.\d+)?\]\s*/i,"").trim()}function Fi(e){let t=String(e||""),r=t.match(/^\s*\[P(\d+)(?:\.\d+)?\]\s*/i);return r?{text:t.replace(/^\s*\[P\d+(?:\.\d+)?\]\s*/i,"").trim(),targetRef:Number.parseInt(r[1],10)}:{text:t.trim(),targetRef:null}}function da(e,t){return!Number.isInteger(t)||t<1?null:Te(e)[t-1]||null}function et(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 Ut(e,t){let r=Te(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 Fr(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=Te(e),o=String(t||"").trim();if(!o)return null;let i=Ut(e,o);if(i)return i;let s=_(o),l=a.find(p=>{let g=_(G(p));return g.length>10&&s.startsWith(g)});if(l)return n(`[Fuzzy] Prefix match (target starts with paragraph): "${G(l).trim().slice(0,60)}..."`),l;let c=a.find(p=>{let g=_(G(p));return g.length>15&&s.includes(g)});if(c)return n(`[Fuzzy] Contains match: "${G(c).trim().slice(0,60)}..."`),c;let u=0,m=null,f=new Set(s.toLowerCase().split(/\s+/).filter(p=>p.length>2));for(let p of a){let g=G(p).trim();if(!g)continue;let h=_(g).toLowerCase().split(/\s+/).filter(b=>b.length>2).filter(b=>f.has(b)).length/Math.max(f.size,1);h>u&&h>.5&&(u=h,m=p)}return m?(n(`[Fuzzy] Best word-overlap match (${(u*100).toFixed(0)}%): "${G(m).trim().slice(0,60)}..."`),m):null}function ha(e,t={}){let r=typeof t.onInfo=="function"?t.onInfo:()=>{},n=typeof t.onWarn=="function"?t.onWarn:()=>{},a=t.opType||"operation",o=String(t.targetText||"").trim(),i=Dr(t.targetRef);if(i){let s=da(e,i);if(s){if(o){let l=Ut(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=Fr(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=Ut(e,o);if(s)return{paragraph:s,resolvedBy:"strict_text"};let l=Fr(e,o,{onInfo:r});if(l)return{paragraph:l,resolvedBy:"fuzzy_text"}}throw o?new Error(`Target paragraph not found: "${o}"`):i?new Error(`Target paragraph reference not found: [P${i}]`):new Error('Operation target missing: provide "target" text or "targetRef" ([P#]).')}function wa(e){return!!et(e,"tbl")}function $i(e,t){let r=_(t);if(!r)return[];let n=Te(e),a=[];for(let o=0;o<n.length;o++){let i=n[o],s=G(i).trim();s&&_(s)===r&&a.push({paragraph:i,index:o+1,inTable:wa(i)})}return a}function Xi(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 Di(e){let t=Te(e),r=new Map;for(let n=0;n<t.length;n++){let a=t[n],o=G(a).trim();r.set(n+1,{text:o,normalizedText:_(o),inTable:wa(a)})}return r}function $r(e,t={}){let r=typeof t.onInfo=="function"?t.onInfo:()=>{},n=ha(e,t),a=Dr(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=$i(e,f),g=Xi(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 zi(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=$r(e,{targetRef:t,opType:a,targetRefSnapshot:o,onInfo:i,onWarn:s})?.paragraph;if(!l)return null;let c=$r(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 jt(e,t){if(!e||typeof e.getElementsByTagNameNS!="function")return null;let r=e.getElementsByTagNameNS(se,t);if(r.length>0)return r[0];let n=e.getElementsByTagNameNS("*",t);return n.length>0?n[0]:null}function ba(e){if(!e)return null;if(typeof e.getAttributeNS=="function"){let t=e.getAttributeNS(se,"val");if(t)return t}return e.getAttribute("w:val")||e.getAttribute("val")||null}function Wi(e){let t=String(e||"").trim();if(!/^\d+(?:\.\d+)+\.?$/.test(t))return null;let r=t.replace(/\.$/,"").split(".");return Math.max(0,r.length-1)}var xa=/^(?:(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|[ivxlcIVXLC]+\.|[-*+\u2022]))\s+/;function va(e){let t=String(e||"").trim(),r=0;for(;r<4&&xa.test(t);)t=t.replace(xa,"").trimStart(),r++;return t.trim()}function Ta(e){let t=String(e||"").split(/\r?\n/g),r=[],n=!1;for(let a of t){let o=a.trimEnd();if(!o.trim())continue;let i=o.match(/^(\s*)((?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|[ivxlcIVXLC]+\.|[-*+\u2022]))\s+(.*)$/);if(i){n=!0;let s=i[2],l=/^[-*+\u2022]$/.test(s)?"bullet":"numbered",c=Math.floor((i[1]||"").length/2);r.push({kind:"list",markerType:l,level:c,marker:s,outlineLevel:l==="numbered"?Wi(s):null,text:va(i[3])});continue}r.push({kind:"text",text:o.trim()})}return{items:r,hasListMarkers:n}}function Na(e,t,r){return`${" ".repeat(Math.max(0,e))}${t==="numbered"?"1.":"-"} ${String(r||"").trim()}`.trimEnd()}function dt(e,t){return _(e)===_(t)}function Gt(e,t,r){return Number.isInteger(e?.outlineLevel)?Math.max(0,e.outlineLevel):Math.max(0,t+((e?.level||0)-r))}function Hi(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"?dt(n.text,t):!1}function Ui(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 ji(e,t,r,n){let a=e[0],o=e.slice(1).filter(i=>i.kind==="list");if(a?.kind==="text"&&dt(a.text,t)&&o.length>0){let i=o[0].level;return o.map(s=>({ilvl:Gt(s,r,i),markerType:s.markerType||n,text:s.text}))}if(e.every(i=>i.kind==="list")){let i=e[0];if(!i||!dt(i.text,t))return null;let s=i.level;return e.slice(1).map(l=>({ilvl:Gt(l,r,s),markerType:l.markerType||n,text:l.text})).filter(l=>l.text)}return null}function ye(e){if(!e)return null;let t=jt(e,"pPr");if(!t)return null;let r=jt(t,"numPr");if(!r)return null;let n=jt(r,"numId");if(!n)return null;let a=ba(n);if(!a)return null;let o=jt(r,"ilvl"),i=ba(o),s=Number.parseInt(i||"0",10);return{numId:String(a),ilvl:Number.isFinite(s)?s:0}}function ya(e){let t=ye(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=ye(n[o-1]);if(!s||s.numId!==t.numId)break;o--}let i=a;for(;i<n.length-1;){let s=ye(n[i+1]);if(!s||s.numId!==t.numId)break;i++}return n.slice(o,i+1)}function Gi(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
+ `)||!ye(e))return null;let s=ya(e);if(!s||s.length===0)return null;let l=Ta(o);if(!l.hasListMarkers||l.items.length<2)return null;let c=_(r.currentParagraphText||G(e)),m=l.items.filter(y=>y.kind==="list")[0]?.markerType||"bullet",f=s.map(y=>({paragraph:y,list:ye(y),text:String(G(y)||"").trim()})),p=s.indexOf(e);if(p<0)return null;let g=Math.min(...f.map(y=>y.list?.ilvl??0)),d=f.map(y=>Na((y.list?.ilvl??0)-g,m,y.text)),w=null,h=l.items[0],b=l.items.slice(1).filter(y=>y.kind==="list");if(h?.kind==="text"&&dt(h.text,c)&&b.length>0){let y=Math.max(0,(f[p].list?.ilvl??0)-g),E=b[0].level;w=[{level:y,markerType:m,text:f[p].text},...b.map(I=>({level:Gt(I,y,E),markerType:I.markerType||m,text:I.text}))]}else if(l.items.every(y=>y.kind==="list")){let y=Math.max(0,(f[p].list?.ilvl??0)-g),E=l.items[0].level;w=l.items.map(I=>({level:Gt(I,y,E),markerType:I.markerType||m,text:I.text}))}else return a("[List] Multiline list edit did not match supported insertion/replace patterns; skipping list-block synthesis."),null;let x=w.map(y=>Na(y.level,y.markerType,y.text)),P=d.slice(0,p).concat(x).concat(d.slice(p+1)),N=d.join(`
153
+ `),v=P.join(`
154
+ `);return v===N?null:(n("[List] Expanded single-item list edit to contiguous list block for stable middle insertion."),{paragraphs:s,originalText:N,modifiedText:v})}function Vi(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=typeof r.onWarn=="function"?r.onWarn:()=>{},o=String(t||"");if(!o.includes(`
155
+ `))return null;let i=ye(e);if(!i)return null;let s=Ta(o);if(!s.hasListMarkers||s.items.length<2)return null;let l=_(r.currentParagraphText||G(e)),u=s.items.filter(p=>p.kind==="list")[0]?.markerType||"bullet",m=Math.max(0,i.ilvl),f=ji(s.items,l,m,u);return!f||f.length===0?(a("[List] Could not derive insertion-only entries from multiline list edit."),null):(Hi(s.items,l,m)&&(f=Ui(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 ht(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 zr(e){return!e||!Array.isArray(e.items)?!1:e.items.some(t=>t?.type==="numbered"||t?.type==="bullet")}function Wr(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 Ki(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=Zi(s,t,r),c=" ".repeat(i*4);a.push(`${c}${l} ${o.text||""}`.trimEnd())}return a.join(`
157
+ `)}function Yi(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 Zi(e,t,r){if(t==="bullet")return"-";switch(r){case"lowerAlpha":return`${Ea(e,!1)}.`;case"upperAlpha":return`${Ea(e,!0)}.`;case"lowerRoman":return`${Pa(e,!1)}.`;case"upperRoman":return`${Pa(e,!0)}.`;default:return`${e}.`}}function Ea(e,t=!1){let r=Math.max(1,Number(e)||1),n="";for(;r>0;)r-=1,n=String.fromCharCode(97+r%26)+n,r=Math.floor(r/26);return t?n.toUpperCase():n}function Pa(e,t=!1){let r=Math.max(1,Number(e)||1),n=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]],a="";for(let[o,i]of n)for(;r>=o;)a+=i,r-=o;return t?a:a.toLowerCase()}function Vt(e){let t=String(e||"");if(!t.trim()||t.includes(`
158
+ `))return null;let r=ht(t);if(!r||!zr(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"?Wr(a||"1."):"bullet";return{type:n.type,marker:a,numberingStyle:o,startAt:qi(a,o),contentText:String(n.text||"").trim(),normalizedContent:_(String(n.text||""))}}function Ji(e){let t=Vt(e);return t?String(t.contentText||"").trim():String(e||"").trim()}function qi(e,t){if(t!=="decimal")return null;let r=String(e||"").trim().match(/^(\d+)\.?$/);if(!r)return null;let n=Number.parseInt(r[1],10);return Number.isFinite(n)&&n>0?n:null}function Qi(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 es(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 ts(e,t){!e||!(e.explicitByNumberingKey instanceof Map)||t&&e.explicitByNumberingKey.delete(String(t))}function tt(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 rs(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=tt(l,"pPr");if(u||(u=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:pPr"),l.insertBefore(u,l.firstChild)),a){let g=tt(u,"pPrChange");g&&u.removeChild(g)}if(o){let g=tt(u,"listPr");g&&u.removeChild(g)}let m=tt(u,"numPr");m||(m=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:numPr"),u.appendChild(m));let f=tt(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=tt(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 ns(e){let r=B().parseFromString(String(e||""),"application/xml");return j(r)?null:Te(r)[0]||null}function as(e){return e?String(e).replace(/<w:p>\s*<w:pPr>\s*<\/w:pPr>\s*<\/w:p>\s*$/i,""):""}function os(e,t){for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return null}function rt(e,t){let r=os(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function Sa(e,t){e.setAttribute("w:val",String(t))}function is(e){let r=B().parseFromString(String(e||""),"application/xml");if(j(r))return null;let o=Te(r)[0]||null;if(!o)return null;let i=Array.from(o.getElementsByTagNameNS("*","numId"));for(let s of i){let l=rt(s,["w:val","val"]);if(l!=null)return String(l)}return null}function ss(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=rt(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=rt(m,["w:val","val"]),p=Array.from(u.getElementsByTagNameNS("*","lvlOverride")).find(d=>rt(d,["w:ilvl","ilvl"])===0)||null;p||(p=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:lvlOverride"),p.setAttribute("w:ilvl","0"),u.appendChild(p));let g=Array.from(p.getElementsByTagNameNS("*","startOverride"))[0]||null;if(g||(g=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:startOverride"),p.appendChild(g)),Sa(g,r),a&&f!=null){let w=Array.from(s.getElementsByTagNameNS("*","abstractNum")).find(h=>{let b=rt(h,["w:abstractNumId","abstractNumId"]);return b!=null&&b===f})||null;if(w){let h=Array.from(w.getElementsByTagNameNS("*","lvl")).find(x=>rt(x,["w:ilvl","ilvl"])===0)||null;h||(h=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:lvl"),h.setAttribute("w:ilvl","0"),w.appendChild(h));let b=Array.from(h.getElementsByTagNameNS("*","start"))[0]||null;b||(b=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:start"),h.insertBefore(b,h.firstChild)),Sa(b,r)}}return i.serializeToString(s)}function Hr(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=ns(t);if(!o)return null;let i=ye(o);if(i&&!a)return null;let s=ne(n).cleanText||n,l=Vt(n)||Vt(s);if(!l)return null;let c=Vt(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 Kt(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 $e({author:r,generateRedlines:n})).executeListGeneration(e.listInput,null,null,String(e.originalText||"")),i=o?.oxml||o?.ooxml||"",s=as(i),l=is(s),c=ss(o?.numberingXml||null,l,Number.isInteger(e?.startAt)?e.startAt:null,{setAbstractStartOverride:t.setAbstractStartOverride}),u=o?.isValid!==!1;return!s||!u?{hasChanges:!1,oxml:"",numberingXml:null,includeNumbering:!1,listStructuralFallbackApplied:!1,listStructuralFallbackKey:e.numberingKey||null,warnings:["Single-line list fallback produced no valid OOXML"]}:{hasChanges:!0,oxml:s,numberingXml:c,includeNumbering:!0,listStructuralFallbackApplied:!0,listStructuralFallbackKey:e.numberingKey||null,listStructuralFallbackStartAt:Number.isInteger(e?.startAt)?e.startAt:null,warnings:["Single-line list structural fallback applied"]}}var ls=new Set(["ins","del","rPrChange","pPrChange"]),cs=/^\d{4}-\d{2}-\d{2}T/;function Yt(e){return String(e?.localName||e?.nodeName||"").replace(/^.*:/,"")}function wt(e,t){return Array.from(e.getElementsByTagName("*")).filter(r=>Yt(r)===t)}function He(e,t){return e.getAttribute(`w:${t}`)||e.getAttribute(t)||""}function us(e){return e.getAttribute("xml:space")||e.getAttribute("space")||e.getAttributeNS?.("http://www.w3.org/XML/1998/namespace","space")||""}function fs(e){return Yt(e.parentNode)==="rPr"}function ms(e){let t=r=>{let n=St(r),a=n.getElementsByTagName("parsererror")[0];if(a)throw new Error(a.textContent||"XML parse error");return n};try{return{doc:t(e)}}catch{try{return{doc:t(`<w:root xmlns:w="${S}">${e}</w:root>`)}}catch(r){return{error:r?.message||"XML parse error"}}}}function ps(e){let t=[],r=(u,m,f)=>t.push({code:u,severity:m,message:f});if(typeof e!="string"||e.trim()==="")return r("PARSE_ERROR","error","Input is not a non-empty OOXML string."),{valid:!1,issues:t};let{doc:n,error:a}=ms(e);if(!n)return r("PARSE_ERROR","error",`OOXML does not parse as XML: ${a}`),{valid:!1,issues:t};let o=wt(n,"ins"),i=wt(n,"del"),s=o.concat(i);for(let u of s){let m=Array.from(u.getElementsByTagName("*")).filter(f=>f!==u&&["ins","del"].includes(Yt(f)));m.length>0&&r("NESTED_REVISION","error",`<${u.nodeName}> (w:id="${He(u,"id")}") contains nested <${m[0].nodeName}>.`)}for(let u of i)wt(u,"t").length>0&&r("DEL_CONTAINS_T","error",`<w:del> (w:id="${He(u,"id")}") contains <w:t>; deleted text must use <w:delText>.`);for(let u of s){let m=[];He(u,"id")||m.push("w:id"),He(u,"author")||m.push("w:author"),cs.test(He(u,"date"))||m.push("w:date"),m.length>0&&r("MISSING_REVISION_METADATA","error",`<${u.nodeName}> is missing or has malformed ${m.join(", ")}.`)}let l=new Set;for(let u of Array.from(n.getElementsByTagName("*"))){if(!ls.has(Yt(u)))continue;let m=He(u,"id");m&&(l.has(m)&&r("DUPLICATE_REVISION_ID","error",`Revision id ${m} appears more than once.`),l.add(m))}let c=wt(n,"t").concat(wt(n,"delText"));for(let u of c){let m=u.textContent||"";/^\s|\s$/.test(m)&&us(u)!=="preserve"&&r("MISSING_SPACE_PRESERVE","error",`<${u.nodeName}> has boundary whitespace without xml:space="preserve".`),m===""&&r("EMPTY_TEXT_ELEMENT","warning",`<${u.nodeName}> is empty.`)}for(let u of s){if(fs(u))continue;Array.from(u.childNodes||[]).some(f=>f.nodeType===1)||r("EMPTY_REVISION_WRAPPER","warning",`<${u.nodeName}> (w:id="${He(u,"id")}") wraps no content.`)}return{valid:!t.some(u=>u.severity==="error"),issues:t}}function Zt(e,t){return e?Array.from(e.childNodes||[]).filter(r=>r&&r.nodeType===1&&r.namespaceURI===se&&r.localName===t):[]}function gs(e){return String(e||"").replace(/\|/g,"\\|").replace(/\r?\n/g,"<br>")}function ds(e){let t=Zt(e,"tr"),r=t.map(a=>Zt(a,"tc").map(i=>{let s=Zt(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 hs(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=>gs(l)).join(" | ")} |`;return[i(n),i(a),...o.map(i)].join(`
160
+ `)}function ws(e){if(!Array.isArray(e)||e.length<2)return!1;let t=e.map(r=>_(r)).filter(Boolean);return t.length<2?!1:t.every(r=>r===t[0])}function Ia(e){let t=String(e||"").trim();return t?!!(/^and$/i.test(t)||/^\[.*\]$/.test(t)||/^\(.*\)$/.test(t)||/:\s*$/.test(t)||t.length<=90&&!/[.!?]$/.test(t)&&/[:\[\]()]/.test(t)||/^[\[(]/.test(t)):!1}function bs(e,t={}){let r=Number.isInteger(t?.maxScan)&&t.maxScan>0?t.maxScan:10,n=typeof t?.getParagraphText=="function"?t.getParagraphText:G;if(!e||!e.parentNode)return null;let a=[e],o=e.nextSibling,i=0;for(;o&&i<r;){i+=1;let s=o.nextSibling;if(o.nodeType!==1||o.namespaceURI!==se||o.localName!=="p"){o=s;continue}let l=String(n(o)||"").trim();if(!l){if(a.length>1)break;o=s;continue}if(!Ia(l))break;a.push(o),o=s}return a.length>1?a:null}function xs(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
+ `)||Xr(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||et(e,"tbl"),l=et(e,"tr"),c=et(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}=ds(s);if(f.length===0||g===0)return null;let d=p.indexOf(l),h=Zt(l,"tc").indexOf(c);if(d<0||h<0||h>=g)return null;f[d][h]=i[0];let b=ws(f[d]);b&&n("[Table] Symmetric row detected; mirroring inserted row values across columns.");for(let P=1;P<i.length;P++){let N=d+P,v=i[P];if(N<f.length&&!_(f[N][h]))if(b)for(let y=0;y<g;y++)_(f[N][y])||(f[N][y]=v);else f[N][h]=v;else{let y=new Array(g).fill("");if(b)for(let E=0;E<g;E++)y[E]=v;else y[h]=v;f.splice(Math.min(N,f.length),0,y)}}let x=hs(f,g);return x?(n("[Table] Synthesized full markdown table from multiline cell edit for table-scope reconciliation."),x):null}function nt(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 at(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 Ns(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=ve(e),m=Array.from(u.getElementsByTagNameNS("*","abstractNum")),f=Array.from(u.getElementsByTagNameNS("*","num"));for(let p of m){let g=nt(p,["w:abstractNumId","abstractNumId"]);g!=null&&o.add(g)}for(let p of f){let g=nt(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:at(l,a,n),nextAbstractNumId:at(c,o,n),usedNumIds:a,usedAbstractNumIds:o,minId:r,maxPreferred:n}}function vs(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=at(e.nextNumId,e.usedNumIds,e.maxPreferred),e.nextAbstractNumId=at(e.nextAbstractNumId,e.usedAbstractNumIds,e.maxPreferred),e)}function xt(e,t="num"){let r=vs(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=at(a+1,r.usedAbstractNumIds,r.maxPreferred)):(r.usedNumIds.add(a),r.nextNumId=at(a+1,r.usedNumIds,r.maxPreferred)),a)}function Ts(e){let t=xt(e,"num"),r=xt(e,"abstract");return t==null||r==null?null:{numId:t,abstractNumId:r}}function Ur(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:e.getElementsByTagName("parsererror").length>0}function Jt(e,t){return!!(e&&e.nodeType===1&&e.namespaceURI===se&&e.localName===t)}function Ca(e,t,r){if(!e||!t)return;let n=Array.from(e.childNodes||[]).filter(o=>o&&o.nodeType===1&&o.namespaceURI===se),a=null;r==="abstract"?a=n.find(o=>o.localName==="num"||o.localName==="numIdMacAtCleanup")||null:a=n.find(o=>o.localName==="numIdMacAtCleanup")||null,a?e.insertBefore(t,a):e.appendChild(t)}function ys(e,t){for(let r of t||[]){let n=e?.getAttribute?.(r);if(n!=null&&n!=="")return n}return null}function bt(e,t){let r=ys(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function Aa(e,t,r){e?.setAttribute?.(t,String(r))}function jr(e,t){e?.setAttribute?.("w:val",String(t))}function Es(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)jr(a,t)}}function Ps(e){for(let t of e||[]){let r=Array.from(t?.getElementsByTagNameNS?.("*","numId")||[]);for(let n of r){let a=bt(n,["w:val","val"]);if(a!=null)return String(a)}}return null}function Ss(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`
162
162
  <w:lvl w:ilvl="${l}">
163
163
  <w:start w:val="1"/>
164
164
  <w:numFmt w:val="decimal"/>
@@ -177,23 +177,23 @@ var Ga=Object.create;var Kr=Object.defineProperty;var Va=Object.getOwnPropertyDe
177
177
  <w:startOverride w:val="${o}"/>
178
178
  </w:lvlOverride>
179
179
  </w:num>
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(`
180
+ </w:numbering>`.trim()}function Is(e,t,r){let n=ve(e);if(Ur(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=bt(c,["w:abstractNumId","abstractNumId"]);if(u==null)continue;let m=xt(r,"abstract");m!=null&&(a.set(u,m),Aa(c,"w:abstractNumId",m))}let s=Array.from(n.getElementsByTagNameNS("*","num"));for(let c of s){let u=bt(c,["w:numId","numId"]);if(u==null)continue;let m=xt(r,"num");if(m==null)continue;o.set(u,m),Aa(c,"w:numId",m);let f=Array.from(c.getElementsByTagNameNS("*","abstractNumId"))[0]||null;if(f){let p=bt(f,["w:val","val"]);p!=null&&a.has(p)&&jr(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=bt(m,["w:val","val"]);f!=null&&o.has(f)&&jr(m,o.get(f))}}return{numberingXml:We(n),replacementNodes:l}}function Cs(e,t){let r=String(e||""),n=String(t||"");if(!n.trim())return r;if(!r.trim())return n;try{let a=ve(r),o=ve(n);if(Ur(a)||Ur(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=>Jt(u,"abstractNum")).map(u=>nt(u,["w:abstractNumId","abstractNumId"])).filter(u=>u!=null)),c=new Set(Array.from(i.childNodes||[]).filter(u=>Jt(u,"num")).map(u=>nt(u,["w:numId","numId"])).filter(u=>u!=null));for(let u of Array.from(s.childNodes||[])){if(!Jt(u,"abstractNum"))continue;let m=nt(u,["w:abstractNumId","abstractNumId"]);m==null||l.has(m)||(Ca(i,a.importNode(u,!0),"abstract"),l.add(m))}for(let u of Array.from(s.childNodes||[])){if(!Jt(u,"num"))continue;let m=nt(u,["w:numId","numId"]);m==null||c.has(m)||(Ca(i,a.importNode(u,!0),"num"),c.add(m))}return We(a)}catch{return r}}function As(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:!!j(e)}function Oa(e){let t=typeof e=="string"?e:String(e||"");if(!t.trim())return null;try{let n=B().parseFromString(t,"application/xml");return As(n)?null:n}catch{return null}}function ka(e){if(!e)return[];let t=Array.from(e.getElementsByTagNameNS(S,"p"));return t.length>0?t:Array.from(e.getElementsByTagNameNS("*","p")).filter(r=>r?.localName==="p")}function Gr(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 Oe(e,t){return Array.from(e?.getElementsByTagNameNS?.(S,t)||[])}function Nt(e,t){if(!e)return"";for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return""}function Ra(e,t,r){let n=e?.parentNode||null;for(;n&&n!==r;){if(n.nodeType===1&&n.namespaceURI===S&&n.localName===t)return!0;n=n.parentNode}return!1}function Rs(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 Os(e){let t=Gr(e,"rPr");if(!t)return{bold:!1,italic:!1};let r=Oe(t,"rStyle")[0]||null,n=Nt(r,["w:val","val"]).toLowerCase(),a=n.includes("strong")||n.includes("bold"),o=n.includes("italic")||n.includes("emphasis");return{bold:Oe(t,"b").length>0||a,italic:Oe(t,"i").length>0||o}}function Ma(e){let t=[],r=Array.from(e?.getElementsByTagNameNS?.(S,"r")||[]);for(let n of r){if(Ra(n,"del",e)||Ra(n,"moveFrom",e))continue;let a=Rs(n);a&&t.push({text:a,...Os(n)})}return t}function Vr(e){return String(e||"").replace(/\r/g,"").split(`
182
182
  `).map(r=>r.replace(/[ \t]+/g," ").trim()).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(`
183
+ `).trim()}function ks(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 Ms(e){let t=Gr(e,"pPr");if(!t)return null;let r=Oe(t,"pStyle")[0]||null,n=Nt(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=Oe(t,"outlineLvl")[0]||null,o=Nt(a,["w:val","val"]),i=Number.parseInt(o,10);return Number.isInteger(i)&&i>=0?Math.min(i+1,6):null}function Ls(e){let t=Gr(e,"pPr");if(!t)return null;let r=Oe(t,"numPr")[0]||null;if(!r)return null;let n=Oe(r,"ilvl")[0]||null,a=Oe(r,"numId")[0]||null,o=Number.parseInt(Nt(n,["w:val","val"]),10),i=Nt(a,["w:val","val"]);return{level:Number.isInteger(o)&&o>=0?o:0,marker:i==="1"?"-":"1."}}function _s(e){let t=Ma(e).map(r=>r.text).join("");return Vr(t)}function Bs(e){let r=Ma(e).map(i=>ks(i.text,i)).join(""),n=Vr(r);if(!n)return"";let a=Ms(e);if(a!=null)return`${"#".repeat(a)} ${n}`;let o=Ls(e);return o?`${" ".repeat(o.level)}${o.marker} ${n}`:n}function Fs(e){let t=Oa(e);if(!t)return"";let r=ka(t);return r.length===0?Vr(t.documentElement?.textContent||""):r.map(_s).join(`
184
184
 
185
- `).trim()}function Rs(e){let t=Ia(e);if(!t)return"";let r=Aa(t);return r.length===0?"":r.map(Is).join(`
185
+ `).trim()}function $s(e){let t=Oa(e);if(!t)return"";let r=ka(t);return r.length===0?"":r.map(Bs).join(`
186
186
 
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}">
187
+ `).trim()}function Kr(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}">
188
188
  <w:p>
189
189
  <w:r><w:t>${o}</w:t></w:r>
190
190
  </w:p>
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(`
191
+ </w:comment>`}function Yr(e){if(!e||e.length===0)return`<w:comments xmlns:w="${S}"></w:comments>`;let t=e.map(r=>Kr(r.id,r.author,r.content,r.date)).join(`
192
192
  `);return`<w:comments xmlns:w="${S}">
193
193
  ${t}
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(`
194
+ </w:comments>`}function qt(e){let t=Se(e,"w:r"),r=[],n="";for(let a of t){let o=n.length,i=Se(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 Xs(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 vt(e,t,r){let n=A(e,"w:r");t&&n.appendChild(t.cloneNode(!0));let a=A(e,"w:t");return a.setAttribute("xml:space","preserve"),a.textContent=r,n.appendChild(a),n}function La(e,t,r,n,a=null){let o=a||qt(t),i=Xs(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"),N=g.parentNode;return h&&N.insertBefore(vt(e,P,h),g),N.insertBefore(s,g),d.textContent=b,g.nextSibling?N.insertBefore(l,g.nextSibling):N.appendChild(l),N.insertBefore(c,l.nextSibling||null),x&&N.insertBefore(vt(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(vt(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(vt(e,h,w),f.nextSibling):f.parentNode.appendChild(vt(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 ot="http://schemas.microsoft.com/office/2006/xmlPackage",Tt="http://schemas.openxmlformats.org/package/2006/relationships";function _a(e,t){let r=B(),n=Q(),a=r.parseFromString(e,"text/xml"),o=j(a);if(o)return Z("[CommentEngine] Failed to parse package:",o.textContent),e;let i=a.documentElement,s=a.createElementNS(ot,"pkg:part");s.setAttribute("pkg:name","/word/comments.xml"),s.setAttribute("pkg:contentType","application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml");let l=a.createElementNS(ot,"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,ot,"part").find(f=>f.getAttribute("pkg:name")==="/word/_rels/document.xml.rels");if(m){let f=V(m,ot,"xmlData");if(f.length>0){let p=V(f[0],Tt,"Relationships");if(p.length>0){let g=p[0],d=V(g,Tt,"Relationship");if(!d.some(h=>h.getAttribute("Type")?.includes("comments"))){let h=0;d.forEach(x=>{let P=x.getAttribute("Id"),N=parseInt(P?.replace("rId","")||"0",10);N>h&&(h=N)});let b=a.createElementNS(Tt,"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(ot,"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(ot,"pkg:xmlData"),g=a.createElementNS(Tt,"Relationships"),d=a.createElementNS(Tt,"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 Ds(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 zs(e,t,r={}){let n=r?.author||J(),a=cr(),o=[],i=[];if(!t||t.length===0)return{oxml:e,commentsApplied:0,warnings:["No comments to inject"]};let s=B(),l=Q(),c=Ds(e,s,g=>`Failed to parse OXML: ${g}`);if(!c.xmlDoc)return Z("[CommentEngine] Parse failure:",c.warning),{oxml:e,commentsApplied:0,warnings:[c.warning]};let u=c.xmlDoc,m=Se(u,"w:p");C(`[CommentEngine] Found ${m.length} paragraphs, processing ${t.length} comment requests`);let f=new Map;for(let g of t){let d=g.paragraphIndex-1;if(d<0||d>=m.length){o.push(`Paragraph ${g.paragraphIndex} out of range (1-${m.length})`);continue}f.set(d,(f.get(d)||0)+1)}let p=new Map;for(let g of t){let d=g.paragraphIndex-1;if(d<0||d>=m.length)continue;let w=m[d],h=p.get(d);h||(h=qt(w),p.set(d,h));let b=lr(),x=La(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,qt(w)):p.delete(d)}return i.length===0?{oxml:e,commentsApplied:0,warnings:o}:{oxml:l.serializeToString(u),commentsXml:Yr(i),commentsApplied:i.length,warnings:o}}function Ws(e,t){return _a(e,t)}function ke(e){e?.parentNode&&e.parentNode.removeChild(e)}function Ba(e,t=["all"]){if(!e)return null;let r=e.cloneNode(!0);if(t.includes("all"))["w:b","w:i","w:u","w:strike","w:dstrike","w:color","w:sz","w:szCs","w:rFonts","w:highlight","w:vertAlign","w:spacing","w:w","w:kern","w:position"].forEach(a=>{r.querySelectorAll(`${a}, ${a.replace("w:","")}`).forEach(ke)});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(ke)})}return r.children.length>0?r:null}function Hs(e,t,r){if(!t||!e)return e;let n=ve(e),a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",o=n.getElementsByTagNameNS(a,"r"),i=n.getElementsByTagNameNS(a,"ins"),s=[...Array.from(o)];for(let l of i){let c=l.getElementsByTagNameNS(a,"r");s.push(...Array.from(c))}for(let l of s){let c=l.getElementsByTagNameNS(a,"t"),u=Array.from(c).map(m=>m.textContent).join("");if(u.includes(t)||u===t){let m=l.getElementsByTagNameNS(a,"rPr");if(m.length>0){let f=m[0],p=Ba(f,r);p?f.parentNode&&f.parentNode.replaceChild(p,f):ke(f)}}}return We(n)}var Us={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 js(e,t,r="yellow",n={}){let a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",o=Us[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(ke);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(ke),l.appendChild(f)}return l}function Gs(e,t,r="yellow",n={}){if(!t||!e)return e;let a=ve(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(ke);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(ke);let x=A(a,"w:t");x.setAttribute("xml:space","preserve"),x.textContent=g,h.appendChild(x);let P=h.getElementsByTagNameNS(o,"rPr"),N=P.length>0?P[0]:null,v=js(a,N,r,n);N?h.replaceChild(v,N):h.insertBefore(v,h.firstChild),w.appendChild(h)}if(d.length>0){let h=c.cloneNode(!0),b=h.getElementsByTagNameNS(o,"t");Array.from(b).forEach(ke);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 We(a)}var ae="http://schemas.openxmlformats.org/wordprocessingml/2006/main",Vs="http://schemas.openxmlformats.org/package/2006/content-types",Ks="http://schemas.openxmlformats.org/package/2006/relationships",$a="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",Xa="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",Da="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",za="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",Fa="word/document.xml",Qt="word/numbering.xml",yt="word/comments.xml",Ue="[Content_Types].xml",je="word/_rels/document.xml.rels";function Me(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 er(e){return!!e&&e.nodeType===1&&e.namespaceURI===ae&&e.localName==="sectPr"}function Jr(e){return e.getElementsByTagNameNS("*","body")[0]||null}function Wa(e){for(let t of Array.from(e.childNodes||[]))if(er(t))return t;return null}function Ys(e,t){let r=Wa(e);r?e.insertBefore(t,r):e.appendChild(t)}function Ha(e){let t=Jr(e);if(!t)return;let r=Wa(t);if(!r)return;let n=r.nextSibling;for(;n;){let a=n.nextSibling;n.nodeType===1&&t.insertBefore(n,r),n=a}}function Zs(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 Zr(e){return e.getAttribute("pkg:name")||e.getAttribute("name")||""}function Js(e){let t=B(),r=Q(),n=t.parseFromString(e,"application/xml"),a=Array.from(n.getElementsByTagNameNS("*","part")),o=a.find(f=>Zr(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&&!er(f)):[s],u=a.find(f=>Zr(f)==="/word/numbering.xml"),m=null;if(u){let f=u.getElementsByTagNameNS("*","xmlData")[0],p=f?Array.from(f.childNodes||[]).find(g=>g.nodeType===1):null;p&&(m=r.serializeToString(p))}return{replacementNodes:c,numberingXml:m,sourceType:"package"}}function qs(e){if(typeof e!="string"||!e.trim())throw new Error("Reconciliation engine returned no OOXML payload for this operation");if(e.includes("<pkg:package"))return Js(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&&!er(c)):Array.from(i.childNodes||[]).filter(c=>c.nodeType===1),numberingXml:null,sourceType:"document"}}let t=`<root xmlns:w="${ae}">${e}</root>`,n=B().parseFromString(t,"application/xml");return{replacementNodes:Array.from(n.documentElement.childNodes||[]).filter(o=>o.nodeType===1),numberingXml:null,sourceType:"fragment"}}function Ua(e,t,r){if(Array.from(e.getElementsByTagNameNS("*","Override")).some(i=>(i.getAttribute("PartName")||"").toLowerCase()===String(t).toLowerCase()))return!1;let o=e.createElementNS(Vs,"Override");return o.setAttribute("PartName",t),o.setAttribute("ContentType",r),e.documentElement.appendChild(o),!0}function ja(e,t,r){let n=e.getElementsByTagNameNS("*","Relationships")[0]||e.documentElement,a=Array.from(n.getElementsByTagNameNS("*","Relationship"));if(a.some(l=>(l.getAttribute("Type")||"")===t))return!1;let i=0;for(let l of a){let c=l.getAttribute("Id")||"",u=Number.parseInt(c.replace(/^rId/i,""),10);Number.isFinite(u)&&(i=Math.max(i,u))}let s=e.createElementNS(Ks,"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 Qs(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{},a=typeof r?.mergeNumberingXml=="function"?r.mergeNumberingXml:null,o=(Array.isArray(t)?t:[t]).filter(Boolean);if(o.length===0)return;let i=await pe(e,Qt),s=i||null;for(let f of o){if(!s){s=f;continue}s=a?a(s,f):f}n(i?"[Demo] Merging numbering.xml payload(s) into existing numbering definitions":"[Demo] Adding numbering.xml"),e.file(Qt,s);let l=B(),c=Q(),u=await pe(e,Ue);if(u){let f=l.parseFromString(u,"application/xml");Ua(f,"/word/numbering.xml",Xa)&&e.file(Ue,c.serializeToString(f))}let m=await pe(e,je);if(m){let f=l.parseFromString(m,"application/xml");ja(f,$a,"numbering.xml")&&e.file(je,c.serializeToString(f))}}async function el(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{};if(!t)return;let a=B(),o=Q(),i=await pe(e,yt);if(!i)n("[Demo] Adding comments.xml"),e.file(yt,t);else{let c=Me(i,"word/comments.xml (existing)"),u=Me(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(yt,o.serializeToString(c))}let s=await pe(e,Ue);if(s){let c=a.parseFromString(s,"application/xml");Ua(c,"/word/comments.xml",za)&&e.file(Ue,o.serializeToString(c))}let l=await pe(e,je);if(l){let c=a.parseFromString(l,"application/xml");ja(c,Da,"comments.xml")&&e.file(je,o.serializeToString(c))}}async function tl(e){let t=await pe(e,Fa);if(!t)throw new Error("Validation failed: missing word/document.xml");let r=Me(t,Fa);Ha(r);let n=Jr(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=>er(d.node)).map(d=>d.index);if(o.length>1)throw new Error("Validation failed: multiple body-level w:sectPr");if(o.length===1&&o[0]!==a.length-1)throw new Error("Validation failed: w:sectPr not last");let i=r.getElementsByTagNameNS(ae,"tc");for(let d of Array.from(i))for(let w of Array.from(d.childNodes||[]).filter(h=>h.nodeType===1))if(w.namespaceURI===ae&&w.localName==="p"&&Array.from(w.childNodes||[]).some(b=>b.nodeType===1&&b.namespaceURI===ae&&b.localName==="p"))throw new Error("Validation failed: nested w:p");let s=r.getElementsByTagNameNS(ae,"numPr").length>0,l=r.getElementsByTagNameNS(ae,"commentRangeStart").length>0||r.getElementsByTagNameNS(ae,"commentRangeEnd").length>0||r.getElementsByTagNameNS(ae,"commentReference").length>0,c=await pe(e,Qt),u=await pe(e,yt);if(c)Me(c,Qt);else if(s)throw new Error("Validation failed: numbering used but part missing");if(u)Me(u,yt);else if(l)throw new Error("Validation failed: comments used but part missing");let m=await pe(e,Ue);if(!m)throw new Error(`Validation failed: missing ${Ue}`);let f=Me(m,Ue),p=await pe(e,je);if(!p)throw new Error(`Validation failed: missing ${je}`);let g=Me(p,je);if(c){let d=Array.from(f.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/numbering.xml"&&(h.getAttribute("ContentType")||"")===Xa),w=Array.from(g.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===$a);if(!d)throw new Error("Validation failed: numbering CT override missing");if(!w)throw new Error("Validation failed: numbering rel missing")}if(u){let d=Array.from(f.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/comments.xml"&&(h.getAttribute("ContentType")||"")===za),w=Array.from(g.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===Da);if(!d)throw new Error("Validation failed: comments CT override missing");if(!w)throw new Error("Validation failed: comments rel missing")}}var it=Object.freeze({STRUCTURED_LIST_DIRECT:"structured_list_direct",EMPTY_FORMATTED_TEXT:"empty_formatted_text",EMPTY_HTML:"empty_html",BLOCK_HTML:"block_html",OOXML_ENGINE:"ooxml_engine"});function Va(e){return!e||typeof e!="string"?e||"":e.replace(/\\n/g,`
195
+ `).replace(/\\t/g," ").replace(/\\r/g,"\r")}function rl(e={}){let t=e.originalText||"",r=Va(e.newContent||""),n=ht(r)||{type:"text",items:[]};return r.includes(`
196
+ `)&&n.type!=="text"?{kind:it.STRUCTURED_LIST_DIRECT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!0,isOriginalEmpty:Ga(t),hasInlineFormatting:tr(r),hasBlockElements:rr(r),hasMarkdownTable:Et(r)}}:Ga(t)?tr(r)?{kind:it.EMPTY_FORMATTED_TEXT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!0,hasBlockElements:rr(r),hasMarkdownTable:Et(r)}}:{kind:it.EMPTY_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!1,hasBlockElements:rr(r),hasMarkdownTable:Et(r)}}:rr(r)?{kind:it.BLOCK_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:tr(r),hasBlockElements:!0,hasMarkdownTable:Et(r)}}:{kind:it.OOXML_ENGINE,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:tr(r),hasBlockElements:!1,hasMarkdownTable:Et(r)}}}function Ga(e){return!e||e.trim().length===0}function Et(e){if(!e||!e.includes("|"))return!1;let t=me(e);return t.rows.length>0||t.headers.length>0}function tr(e){return e?/(\*\*.+?\*\*|\*.+?\*|__.+?__|_.+?_|`.+?`|~~.+?~~|\+\+.+?\+\+)/.test(e):!1}function rr(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(`
197
197
 
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};
198
+ `);return t||r||n||a||o||i||s||l||c}function nl(e){if(!e||typeof e!="string")return null;let t=e.match(/\b(?:w14:paraId|w:paraId|paraId)="([^"]+)"/i);return t?t[1]:null}async function Ka(e,t,r,n={}){let a=await Lr(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 tp(e,t,r,n={}){let a=typeof e=="string"?e:"",o=typeof r=="string"?r:String(r||""),i;try{i=me(o)}catch{i={headers:[],rows:[]}}return(i?.headers?.length||0)>0||(i?.rows?.length||0)>0?{...await Ka(a,t||"",o,n),isMarkdownTable:!0,tableData:i}:{oxml:a,hasChanges:!1,isMarkdownTable:!1,warnings:["Could not parse Markdown table from input."]}}async function rp(e,t,r,n={}){let a=n.listFallbackAllowExistingList!==!1,o=Hr({oxml:e,originalText:t,modifiedText:r,allowExistingList:a}),i=n.preferListStructuralFallback!==!1,s=[];if(o&&i){let p=await Kt(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 Ka(e,t,r,n);if(!o)return{...l,warnings:[...Array.isArray(l?.warnings)?l.warnings:[],...s],listStructuralFallbackApplied:!1};if(i)return{...l,warnings:[...Array.isArray(l?.warnings)?l.warnings:[],...s],listStructuralFallbackApplied:!1};if(l?.hasChanges)return{...l,listStructuralFallbackApplied:!1};let c=await Kt(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{Ge as ContainerKind,on as ContentType,ce as DiffOp,S as NS_W,ut as NumberingService,$e as ReconciliationPipeline,it as RoutePlanKind,O as RunKind,se as WORD_MAIN_NS,Mr as acceptTrackedChangesInOoxml,Hs as applyFormattingRemovalToOoxml,Gs as applyHighlightToOoxml,Ka as applyRedlineToOxml,rp as applyRedlineToOxmlWithListFallback,Kr as buildCommentElement,Yr as buildCommentsPartXml,Ss as buildExplicitDecimalMultilevelNumberingXml,Ki as buildListMarkdown,rl as buildReconciliationPlan,Hr as buildSingleLineListStructuralFallbackPlan,Di as buildTargetReferenceSnapshot,ts as clearSingleLineListFallbackExplicitSequence,ya as collectContiguousListParagraphBlock,io as configureLogger,no as configureXmlProvider,Nr as containsTrackedChanges,Ns as createDynamicNumberingIdState,Mi as deleteCommentsByAuthorInOoxml,rs as enforceListBindingOnParagraphNodes,el as ensureCommentsArtifactsInZip,Qs as ensureNumberingArtifactsInZip,oe as escapeXml,Kt as executeSingleLineListStructuralFallback,Ps as extractFirstParagraphNumId,nl as extractParagraphIdFromOoxml,qs as extractReplacementNodesFromOoxml,et as findContainingWordElement,Fr as findParagraphByBestTextMatch,da as findParagraphByReference,Ut as findParagraphByStrictText,Fe as generateTableOoxml,Jr as getBodyElementFromDocument,J as getDefaultAuthor,Te as getDocumentParagraphNodes,Zr as getPackagePartName,ye as getParagraphListInfo,G as getParagraphText,ir as getPlatform,zr as hasListItems,Wr as inferNumberingStyleFromMarker,bs as inferTableReplacementParagraphBlock,kt as ingestOoxml,$s as ingestWordOoxmlToMarkdown,Fs as ingestWordOoxmlToPlainText,zs as injectCommentsIntoOoxml,Ws as injectCommentsIntoPackage,Ys as insertBodyElementBeforeSectPr,Ia as isLikelyStructuredTableSourceParagraph,Xr as isMarkdownTableText,Cs as mergeNumberingXmlBySchemaOrder,Ha as normalizeBodySectionOrderStandalone,Va as normalizeContentEscapesForRouting,Yi as normalizeListItemsWithLevels,_ as normalizeWhitespaceForTargeting,Es as overwriteParagraphNumIds,ht as parseMarkdownListContent,ve as parseOoxml,Dr as parseParagraphReference,Me as parseXmlStrictStandalone,Vi as planListInsertionOnlyEdit,ne as preprocessMarkdown,tp as reconcileMarkdownTableOoxml,es as recordSingleLineListFallbackExplicitSequence,Ci as rejectTrackedChangesInOoxml,Is as remapNumberingPayloadForDocument,Ba as removeFormattingFromRPr,xt as reserveNextNumberingId,Ts as reserveNextNumberingIdPair,zi as resolveParagraphRangeByRefs,Qi as resolveSingleLineListFallbackNumberingAction,ha as resolveTargetParagraph,$r as resolveTargetParagraphWithSnapshot,ga as sanitizeAiResponse,Zs as sanitizeNestedParagraphsInTables,We as serializeOoxml,fe as serializeToOoxml,so as setDefaultAuthor,lo as setPlatform,Fi as splitLeadingParagraphMarker,Bi as stripLeadingParagraphMarker,va as stripRedundantLeadingListMarkers,Ji as stripSingleLineListMarkerPrefix,Gi as synthesizeExpandedListScopeEdit,xs as synthesizeTableMarkdownFromMultilineCellEdit,tl as validateDocxPackage,ps as validateRedlineOoxml,Ce as wrapInDocumentFragment};
199
199
  //# sourceMappingURL=docx-redline-js.esm.min.js.map