n8n-nodes-adeu 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,22 @@
1
- 'use strict';var n8nWorkflow=require('n8n-workflow');var vi=Object.create;var Ct=Object.defineProperty;var bi=Object.getOwnPropertyDescriptor;var xi=Object.getOwnPropertyNames;var Ni=Object.getPrototypeOf,ki=Object.prototype.hasOwnProperty;var y=(t,e)=>Ct(t,"name",{value:e,configurable:true});var _n=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Ei=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of xi(e))!ki.call(t,s)&&s!==n&&Ct(t,s,{get:()=>e[s],enumerable:!(r=bi(e,s))||r.enumerable});return t};var mn=(t,e,n)=>(n=t!=null?vi(Ni(t)):{},Ei(Ct(n,"default",{value:t,enumerable:true}),t));var En=_n((Pa,kn)=>{kn.exports={createRequire:y(function(){return function(){return {}}},"createRequire")};});var Wn=_n(($a,We)=>{var O=y(function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32;},"diff_match_patch"),H=-1,Q=1,z=0;O.Diff=function(t,e){return [t,e]};O.prototype.diff_main=function(t,e,n,r){typeof r>"u"&&(this.Diff_Timeout<=0?r=Number.MAX_VALUE:r=new Date().getTime()+this.Diff_Timeout*1e3);var s=r;if(t==null||e==null)throw new Error("Null input. (diff_main)");if(t==e)return t?[new O.Diff(z,t)]:[];typeof n>"u"&&(n=true);var i=n,o=this.diff_commonPrefix(t,e),l=t.substring(0,o);t=t.substring(o),e=e.substring(o),o=this.diff_commonSuffix(t,e);var a=t.substring(t.length-o);t=t.substring(0,t.length-o),e=e.substring(0,e.length-o);var u=this.diff_compute_(t,e,i,s);return l&&u.unshift(new O.Diff(z,l)),a&&u.push(new O.Diff(z,a)),this.diff_cleanupMerge(u),u};O.prototype.diff_compute_=function(t,e,n,r){var s;if(!t)return [new O.Diff(Q,e)];if(!e)return [new O.Diff(H,t)];var i=t.length>e.length?t:e,o=t.length>e.length?e:t,l=i.indexOf(o);if(l!=-1)return s=[new O.Diff(Q,i.substring(0,l)),new O.Diff(z,o),new O.Diff(Q,i.substring(l+o.length))],t.length>e.length&&(s[0][0]=s[2][0]=H),s;if(o.length==1)return [new O.Diff(H,t),new O.Diff(Q,e)];var a=this.diff_halfMatch_(t,e);if(a){var u=a[0],c=a[1],d=a[2],f=a[3],h=a[4],p=this.diff_main(u,d,n,r),_=this.diff_main(c,f,n,r);return p.concat([new O.Diff(z,h)],_)}return n&&t.length>100&&e.length>100?this.diff_lineMode_(t,e,r):this.diff_bisect_(t,e,r)};O.prototype.diff_lineMode_=function(t,e,n){var r=this.diff_linesToChars_(t,e);t=r.chars1,e=r.chars2;var s=r.lineArray,i=this.diff_main(t,e,false,n);this.diff_charsToLines_(i,s),this.diff_cleanupSemantic(i),i.push(new O.Diff(z,""));for(var o=0,l=0,a=0,u="",c="";o<i.length;){switch(i[o][0]){case Q:a++,c+=i[o][1];break;case H:l++,u+=i[o][1];break;case z:if(l>=1&&a>=1){i.splice(o-l-a,l+a),o=o-l-a;for(var d=this.diff_main(u,c,false,n),f=d.length-1;f>=0;f--)i.splice(o,0,d[f]);o=o+d.length;}a=0,l=0,u="",c="";break}o++;}return i.pop(),i};O.prototype.diff_bisect_=function(t,e,n){for(var r=t.length,s=e.length,i=Math.ceil((r+s)/2),o=i,l=2*i,a=new Array(l),u=new Array(l),c=0;c<l;c++)a[c]=-1,u[c]=-1;a[o+1]=0,u[o+1]=0;for(var d=r-s,f=d%2!=0,h=0,p=0,_=0,g=0,w=0;w<i&&!(new Date().getTime()>n);w++){for(var k=-w+h;k<=w-p;k+=2){var b=o+k,m;k==-w||k!=w&&a[b-1]<a[b+1]?m=a[b+1]:m=a[b-1]+1;for(var v=m-k;m<r&&v<s&&t.charAt(m)==e.charAt(v);)m++,v++;if(a[b]=m,m>r)p+=2;else if(v>s)h+=2;else if(f){var N=o+d-k;if(N>=0&&N<l&&u[N]!=-1){var A=r-u[N];if(m>=A)return this.diff_bisectSplit_(t,e,m,v,n)}}}for(var C=-w+_;C<=w-g;C+=2){var N=o+C,A;C==-w||C!=w&&u[N-1]<u[N+1]?A=u[N+1]:A=u[N-1]+1;for(var x=A-C;A<r&&x<s&&t.charAt(r-A-1)==e.charAt(s-x-1);)A++,x++;if(u[N]=A,A>r)g+=2;else if(x>s)_+=2;else if(!f){var b=o+d-C;if(b>=0&&b<l&&a[b]!=-1){var m=a[b],v=o+m-b;if(A=r-A,m>=A)return this.diff_bisectSplit_(t,e,m,v,n)}}}}return [new O.Diff(H,t),new O.Diff(Q,e)]};O.prototype.diff_bisectSplit_=function(t,e,n,r,s){var i=t.substring(0,n),o=e.substring(0,r),l=t.substring(n),a=e.substring(r),u=this.diff_main(i,o,false,s),c=this.diff_main(l,a,false,s);return u.concat(c)};O.prototype.diff_linesToChars_=function(t,e){var n=[],r={};n[0]="";function s(a){for(var u="",c=0,d=-1,f=n.length;d<a.length-1;){d=a.indexOf(`
2
- `,c),d==-1&&(d=a.length-1);var h=a.substring(c,d+1);(r.hasOwnProperty?r.hasOwnProperty(h):r[h]!==void 0)?u+=String.fromCharCode(r[h]):(f==i&&(h=a.substring(c),d=a.length),u+=String.fromCharCode(f),r[h]=f,n[f++]=h),c=d+1;}return u}y(s,"diff_linesToCharsMunge_");var i=4e4,o=s(t);i=65535;var l=s(e);return {chars1:o,chars2:l,lineArray:n}};O.prototype.diff_charsToLines_=function(t,e){for(var n=0;n<t.length;n++){for(var r=t[n][1],s=[],i=0;i<r.length;i++)s[i]=e[r.charCodeAt(i)];t[n][1]=s.join("");}};O.prototype.diff_commonPrefix=function(t,e){if(!t||!e||t.charAt(0)!=e.charAt(0))return 0;for(var n=0,r=Math.min(t.length,e.length),s=r,i=0;n<s;)t.substring(i,s)==e.substring(i,s)?(n=s,i=n):r=s,s=Math.floor((r-n)/2+n);return s};O.prototype.diff_commonSuffix=function(t,e){if(!t||!e||t.charAt(t.length-1)!=e.charAt(e.length-1))return 0;for(var n=0,r=Math.min(t.length,e.length),s=r,i=0;n<s;)t.substring(t.length-s,t.length-i)==e.substring(e.length-s,e.length-i)?(n=s,i=n):r=s,s=Math.floor((r-n)/2+n);return s};O.prototype.diff_commonOverlap_=function(t,e){var n=t.length,r=e.length;if(n==0||r==0)return 0;n>r?t=t.substring(n-r):n<r&&(e=e.substring(0,n));var s=Math.min(n,r);if(t==e)return s;for(var i=0,o=1;;){var l=t.substring(s-o),a=e.indexOf(l);if(a==-1)return i;o+=a,(a==0||t.substring(s-o)==e.substring(0,o))&&(i=o,o++);}};O.prototype.diff_halfMatch_=function(t,e){if(this.Diff_Timeout<=0)return null;var n=t.length>e.length?t:e,r=t.length>e.length?e:t;if(n.length<4||r.length*2<n.length)return null;var s=this;function i(p,_,g){for(var w=p.substring(g,g+Math.floor(p.length/4)),k=-1,b="",m,v,N,A;(k=_.indexOf(w,k+1))!=-1;){var C=s.diff_commonPrefix(p.substring(g),_.substring(k)),x=s.diff_commonSuffix(p.substring(0,g),_.substring(0,k));b.length<x+C&&(b=_.substring(k-x,k)+_.substring(k,k+C),m=p.substring(0,g-x),v=p.substring(g+C),N=_.substring(0,k-x),A=_.substring(k+C));}return b.length*2>=p.length?[m,v,N,A,b]:null}y(i,"diff_halfMatchI_");var o=i(n,r,Math.ceil(n.length/4)),l=i(n,r,Math.ceil(n.length/2)),a;if(!o&&!l)return null;l?o?a=o[4].length>l[4].length?o:l:a=l:a=o;var u,c,d,f;t.length>e.length?(u=a[0],c=a[1],d=a[2],f=a[3]):(d=a[0],f=a[1],u=a[2],c=a[3]);var h=a[4];return [u,c,d,f,h]};O.prototype.diff_cleanupSemantic=function(t){for(var e=false,n=[],r=0,s=null,i=0,o=0,l=0,a=0,u=0;i<t.length;)t[i][0]==z?(n[r++]=i,o=a,l=u,a=0,u=0,s=t[i][1]):(t[i][0]==Q?a+=t[i][1].length:u+=t[i][1].length,s&&s.length<=Math.max(o,l)&&s.length<=Math.max(a,u)&&(t.splice(n[r-1],0,new O.Diff(H,s)),t[n[r-1]+1][0]=Q,r--,r--,i=r>0?n[r-1]:-1,o=0,l=0,a=0,u=0,s=null,e=true)),i++;for(e&&this.diff_cleanupMerge(t),this.diff_cleanupSemanticLossless(t),i=1;i<t.length;){if(t[i-1][0]==H&&t[i][0]==Q){var c=t[i-1][1],d=t[i][1],f=this.diff_commonOverlap_(c,d),h=this.diff_commonOverlap_(d,c);f>=h?(f>=c.length/2||f>=d.length/2)&&(t.splice(i,0,new O.Diff(z,d.substring(0,f))),t[i-1][1]=c.substring(0,c.length-f),t[i+1][1]=d.substring(f),i++):(h>=c.length/2||h>=d.length/2)&&(t.splice(i,0,new O.Diff(z,c.substring(0,h))),t[i-1][0]=Q,t[i-1][1]=d.substring(0,d.length-h),t[i+1][0]=H,t[i+1][1]=c.substring(h),i++),i++;}i++;}};O.prototype.diff_cleanupSemanticLossless=function(t){function e(h,p){if(!h||!p)return 6;var _=h.charAt(h.length-1),g=p.charAt(0),w=_.match(O.nonAlphaNumericRegex_),k=g.match(O.nonAlphaNumericRegex_),b=w&&_.match(O.whitespaceRegex_),m=k&&g.match(O.whitespaceRegex_),v=b&&_.match(O.linebreakRegex_),N=m&&g.match(O.linebreakRegex_),A=v&&h.match(O.blanklineEndRegex_),C=N&&p.match(O.blanklineStartRegex_);return A||C?5:v||N?4:w&&!b&&m?3:b||m?2:w||k?1:0}y(e,"diff_cleanupSemanticScore_");for(var n=1;n<t.length-1;){if(t[n-1][0]==z&&t[n+1][0]==z){var r=t[n-1][1],s=t[n][1],i=t[n+1][1],o=this.diff_commonSuffix(r,s);if(o){var l=s.substring(s.length-o);r=r.substring(0,r.length-o),s=l+s.substring(0,s.length-o),i=l+i;}for(var a=r,u=s,c=i,d=e(r,s)+e(s,i);s.charAt(0)===i.charAt(0);){r+=s.charAt(0),s=s.substring(1)+i.charAt(0),i=i.substring(1);var f=e(r,s)+e(s,i);f>=d&&(d=f,a=r,u=s,c=i);}t[n-1][1]!=a&&(a?t[n-1][1]=a:(t.splice(n-1,1),n--),t[n][1]=u,c?t[n+1][1]=c:(t.splice(n+1,1),n--));}n++;}};O.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/;O.whitespaceRegex_=/\s/;O.linebreakRegex_=/[\r\n]/;O.blanklineEndRegex_=/\n\r?\n$/;O.blanklineStartRegex_=/^\r?\n\r?\n/;O.prototype.diff_cleanupEfficiency=function(t){for(var e=false,n=[],r=0,s=null,i=0,o=false,l=false,a=false,u=false;i<t.length;)t[i][0]==z?(t[i][1].length<this.Diff_EditCost&&(a||u)?(n[r++]=i,o=a,l=u,s=t[i][1]):(r=0,s=null),a=u=false):(t[i][0]==H?u=true:a=true,s&&(o&&l&&a&&u||s.length<this.Diff_EditCost/2&&o+l+a+u==3)&&(t.splice(n[r-1],0,new O.Diff(H,s)),t[n[r-1]+1][0]=Q,r--,s=null,o&&l?(a=u=true,r=0):(r--,i=r>0?n[r-1]:-1,a=u=false),e=true)),i++;e&&this.diff_cleanupMerge(t);};O.prototype.diff_cleanupMerge=function(t){t.push(new O.Diff(z,""));for(var e=0,n=0,r=0,s="",i="",o;e<t.length;)switch(t[e][0]){case Q:r++,i+=t[e][1],e++;break;case H:n++,s+=t[e][1],e++;break;case z:n+r>1?(n!==0&&r!==0&&(o=this.diff_commonPrefix(i,s),o!==0&&(e-n-r>0&&t[e-n-r-1][0]==z?t[e-n-r-1][1]+=i.substring(0,o):(t.splice(0,0,new O.Diff(z,i.substring(0,o))),e++),i=i.substring(o),s=s.substring(o)),o=this.diff_commonSuffix(i,s),o!==0&&(t[e][1]=i.substring(i.length-o)+t[e][1],i=i.substring(0,i.length-o),s=s.substring(0,s.length-o))),e-=n+r,t.splice(e,n+r),s.length&&(t.splice(e,0,new O.Diff(H,s)),e++),i.length&&(t.splice(e,0,new O.Diff(Q,i)),e++),e++):e!==0&&t[e-1][0]==z?(t[e-1][1]+=t[e][1],t.splice(e,1)):e++,r=0,n=0,s="",i="";break}t[t.length-1][1]===""&&t.pop();var l=false;for(e=1;e<t.length-1;)t[e-1][0]==z&&t[e+1][0]==z&&(t[e][1].substring(t[e][1].length-t[e-1][1].length)==t[e-1][1]?(t[e][1]=t[e-1][1]+t[e][1].substring(0,t[e][1].length-t[e-1][1].length),t[e+1][1]=t[e-1][1]+t[e+1][1],t.splice(e-1,1),l=true):t[e][1].substring(0,t[e+1][1].length)==t[e+1][1]&&(t[e-1][1]+=t[e+1][1],t[e][1]=t[e][1].substring(t[e+1][1].length)+t[e+1][1],t.splice(e+1,1),l=true)),e++;l&&this.diff_cleanupMerge(t);};O.prototype.diff_xIndex=function(t,e){var n=0,r=0,s=0,i=0,o;for(o=0;o<t.length&&(t[o][0]!==Q&&(n+=t[o][1].length),t[o][0]!==H&&(r+=t[o][1].length),!(n>e));o++)s=n,i=r;return t.length!=o&&t[o][0]===H?i:i+(e-s)};O.prototype.diff_prettyHtml=function(t){for(var e=[],n=/&/g,r=/</g,s=/>/g,i=/\n/g,o=0;o<t.length;o++){var l=t[o][0],a=t[o][1],u=a.replace(n,"&amp;").replace(r,"&lt;").replace(s,"&gt;").replace(i,"&para;<br>");switch(l){case Q:e[o]='<ins style="background:#e6ffe6;">'+u+"</ins>";break;case H:e[o]='<del style="background:#ffe6e6;">'+u+"</del>";break;case z:e[o]="<span>"+u+"</span>";break}}return e.join("")};O.prototype.diff_text1=function(t){for(var e=[],n=0;n<t.length;n++)t[n][0]!==Q&&(e[n]=t[n][1]);return e.join("")};O.prototype.diff_text2=function(t){for(var e=[],n=0;n<t.length;n++)t[n][0]!==H&&(e[n]=t[n][1]);return e.join("")};O.prototype.diff_levenshtein=function(t){for(var e=0,n=0,r=0,s=0;s<t.length;s++){var i=t[s][0],o=t[s][1];switch(i){case Q:n+=o.length;break;case H:r+=o.length;break;case z:e+=Math.max(n,r),n=0,r=0;break}}return e+=Math.max(n,r),e};O.prototype.diff_toDelta=function(t){for(var e=[],n=0;n<t.length;n++)switch(t[n][0]){case Q:e[n]="+"+encodeURI(t[n][1]);break;case H:e[n]="-"+t[n][1].length;break;case z:e[n]="="+t[n][1].length;break}return e.join(" ").replace(/%20/g," ")};O.prototype.diff_fromDelta=function(t,e){for(var n=[],r=0,s=0,i=e.split(/\t/g),o=0;o<i.length;o++){var l=i[o].substring(1);switch(i[o].charAt(0)){case "+":try{n[r++]=new O.Diff(Q,decodeURI(l));}catch{throw new Error("Illegal escape in diff_fromDelta: "+l)}break;case "-":case "=":var a=parseInt(l,10);if(isNaN(a)||a<0)throw new Error("Invalid number in diff_fromDelta: "+l);var u=t.substring(s,s+=a);i[o].charAt(0)=="="?n[r++]=new O.Diff(z,u):n[r++]=new O.Diff(H,u);break;default:if(i[o])throw new Error("Invalid diff operation in diff_fromDelta: "+i[o])}}if(s!=t.length)throw new Error("Delta length ("+s+") does not equal source text length ("+t.length+").");return n};O.prototype.match_main=function(t,e,n){if(t==null||e==null||n==null)throw new Error("Null input. (match_main)");return n=Math.max(0,Math.min(n,t.length)),t==e?0:t.length?t.substring(n,n+e.length)==e?n:this.match_bitap_(t,e,n):-1};O.prototype.match_bitap_=function(t,e,n){if(e.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var r=this.match_alphabet_(e),s=this;function i(m,v){var N=m/e.length,A=Math.abs(n-v);return s.Match_Distance?N+A/s.Match_Distance:A?1:N}y(i,"match_bitapScore_");var o=this.Match_Threshold,l=t.indexOf(e,n);l!=-1&&(o=Math.min(i(0,l),o),l=t.lastIndexOf(e,n+e.length),l!=-1&&(o=Math.min(i(0,l),o)));var a=1<<e.length-1;l=-1;for(var u,c,d=e.length+t.length,f,h=0;h<e.length;h++){for(u=0,c=d;u<c;)i(h,n+c)<=o?u=c:d=c,c=Math.floor((d-u)/2+u);d=c;var p=Math.max(1,n-c+1),_=Math.min(n+c,t.length)+e.length,g=Array(_+2);g[_+1]=(1<<h)-1;for(var w=_;w>=p;w--){var k=r[t.charAt(w-1)];if(h===0?g[w]=(g[w+1]<<1|1)&k:g[w]=(g[w+1]<<1|1)&k|((f[w+1]|f[w])<<1|1)|f[w+1],g[w]&a){var b=i(h,w-1);if(b<=o)if(o=b,l=w-1,l>n)p=Math.max(1,2*n-l);else break}}if(i(h+1,n)>o)break;f=g;}return l};O.prototype.match_alphabet_=function(t){for(var e={},n=0;n<t.length;n++)e[t.charAt(n)]=0;for(var n=0;n<t.length;n++)e[t.charAt(n)]|=1<<t.length-n-1;return e};O.prototype.patch_addContext_=function(t,e){if(e.length!=0){if(t.start2===null)throw Error("patch not initialized");for(var n=e.substring(t.start2,t.start2+t.length1),r=0;e.indexOf(n)!=e.lastIndexOf(n)&&n.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)r+=this.Patch_Margin,n=e.substring(t.start2-r,t.start2+t.length1+r);r+=this.Patch_Margin;var s=e.substring(t.start2-r,t.start2);s&&t.diffs.unshift(new O.Diff(z,s));var i=e.substring(t.start2+t.length1,t.start2+t.length1+r);i&&t.diffs.push(new O.Diff(z,i)),t.start1-=s.length,t.start2-=s.length,t.length1+=s.length+i.length,t.length2+=s.length+i.length;}};O.prototype.patch_make=function(t,e,n){var r,s;if(typeof t=="string"&&typeof e=="string"&&typeof n>"u")r=t,s=this.diff_main(r,e,true),s.length>2&&(this.diff_cleanupSemantic(s),this.diff_cleanupEfficiency(s));else if(t&&typeof t=="object"&&typeof e>"u"&&typeof n>"u")s=t,r=this.diff_text1(s);else if(typeof t=="string"&&e&&typeof e=="object"&&typeof n>"u")r=t,s=e;else if(typeof t=="string"&&typeof e=="string"&&n&&typeof n=="object")r=t,s=n;else throw new Error("Unknown call format to patch_make.");if(s.length===0)return [];for(var i=[],o=new O.patch_obj,l=0,a=0,u=0,c=r,d=r,f=0;f<s.length;f++){var h=s[f][0],p=s[f][1];switch(!l&&h!==z&&(o.start1=a,o.start2=u),h){case Q:o.diffs[l++]=s[f],o.length2+=p.length,d=d.substring(0,u)+p+d.substring(u);break;case H:o.length1+=p.length,o.diffs[l++]=s[f],d=d.substring(0,u)+d.substring(u+p.length);break;case z:p.length<=2*this.Patch_Margin&&l&&s.length!=f+1?(o.diffs[l++]=s[f],o.length1+=p.length,o.length2+=p.length):p.length>=2*this.Patch_Margin&&l&&(this.patch_addContext_(o,c),i.push(o),o=new O.patch_obj,l=0,c=d,a=u);break}h!==Q&&(a+=p.length),h!==H&&(u+=p.length);}return l&&(this.patch_addContext_(o,c),i.push(o)),i};O.prototype.patch_deepCopy=function(t){for(var e=[],n=0;n<t.length;n++){var r=t[n],s=new O.patch_obj;s.diffs=[];for(var i=0;i<r.diffs.length;i++)s.diffs[i]=new O.Diff(r.diffs[i][0],r.diffs[i][1]);s.start1=r.start1,s.start2=r.start2,s.length1=r.length1,s.length2=r.length2,e[n]=s;}return e};O.prototype.patch_apply=function(t,e){if(t.length==0)return [e,[]];t=this.patch_deepCopy(t);var n=this.patch_addPadding(t);e=n+e+n,this.patch_splitMax(t);for(var r=0,s=[],i=0;i<t.length;i++){var o=t[i].start2+r,l=this.diff_text1(t[i].diffs),a,u=-1;if(l.length>this.Match_MaxBits?(a=this.match_main(e,l.substring(0,this.Match_MaxBits),o),a!=-1&&(u=this.match_main(e,l.substring(l.length-this.Match_MaxBits),o+l.length-this.Match_MaxBits),(u==-1||a>=u)&&(a=-1))):a=this.match_main(e,l,o),a==-1)s[i]=false,r-=t[i].length2-t[i].length1;else {s[i]=true,r=a-o;var c;if(u==-1?c=e.substring(a,a+l.length):c=e.substring(a,u+this.Match_MaxBits),l==c)e=e.substring(0,a)+this.diff_text2(t[i].diffs)+e.substring(a+l.length);else {var d=this.diff_main(l,c,false);if(l.length>this.Match_MaxBits&&this.diff_levenshtein(d)/l.length>this.Patch_DeleteThreshold)s[i]=false;else {this.diff_cleanupSemanticLossless(d);for(var f=0,h,p=0;p<t[i].diffs.length;p++){var _=t[i].diffs[p];_[0]!==z&&(h=this.diff_xIndex(d,f)),_[0]===Q?e=e.substring(0,a+h)+_[1]+e.substring(a+h):_[0]===H&&(e=e.substring(0,a+h)+e.substring(a+this.diff_xIndex(d,f+_[1].length))),_[0]!==H&&(f+=_[1].length);}}}}}return e=e.substring(n.length,e.length-n.length),[e,s]};O.prototype.patch_addPadding=function(t){for(var e=this.Patch_Margin,n="",r=1;r<=e;r++)n+=String.fromCharCode(r);for(var r=0;r<t.length;r++)t[r].start1+=e,t[r].start2+=e;var s=t[0],i=s.diffs;if(i.length==0||i[0][0]!=z)i.unshift(new O.Diff(z,n)),s.start1-=e,s.start2-=e,s.length1+=e,s.length2+=e;else if(e>i[0][1].length){var o=e-i[0][1].length;i[0][1]=n.substring(i[0][1].length)+i[0][1],s.start1-=o,s.start2-=o,s.length1+=o,s.length2+=o;}if(s=t[t.length-1],i=s.diffs,i.length==0||i[i.length-1][0]!=z)i.push(new O.Diff(z,n)),s.length1+=e,s.length2+=e;else if(e>i[i.length-1][1].length){var o=e-i[i.length-1][1].length;i[i.length-1][1]+=n.substring(0,o),s.length1+=o,s.length2+=o;}return n};O.prototype.patch_splitMax=function(t){for(var e=this.Match_MaxBits,n=0;n<t.length;n++)if(!(t[n].length1<=e)){var r=t[n];t.splice(n--,1);for(var s=r.start1,i=r.start2,o="";r.diffs.length!==0;){var l=new O.patch_obj,a=true;for(l.start1=s-o.length,l.start2=i-o.length,o!==""&&(l.length1=l.length2=o.length,l.diffs.push(new O.Diff(z,o)));r.diffs.length!==0&&l.length1<e-this.Patch_Margin;){var u=r.diffs[0][0],c=r.diffs[0][1];u===Q?(l.length2+=c.length,i+=c.length,l.diffs.push(r.diffs.shift()),a=false):u===H&&l.diffs.length==1&&l.diffs[0][0]==z&&c.length>2*e?(l.length1+=c.length,s+=c.length,a=false,l.diffs.push(new O.Diff(u,c)),r.diffs.shift()):(c=c.substring(0,e-l.length1-this.Patch_Margin),l.length1+=c.length,s+=c.length,u===z?(l.length2+=c.length,i+=c.length):a=false,l.diffs.push(new O.Diff(u,c)),c==r.diffs[0][1]?r.diffs.shift():r.diffs[0][1]=r.diffs[0][1].substring(c.length));}o=this.diff_text2(l.diffs),o=o.substring(o.length-this.Patch_Margin);var d=this.diff_text1(r.diffs).substring(0,this.Patch_Margin);d!==""&&(l.length1+=d.length,l.length2+=d.length,l.diffs.length!==0&&l.diffs[l.diffs.length-1][0]===z?l.diffs[l.diffs.length-1][1]+=d:l.diffs.push(new O.Diff(z,d))),a||t.splice(++n,0,l);}}};O.prototype.patch_toText=function(t){for(var e=[],n=0;n<t.length;n++)e[n]=t[n];return e.join("")};O.prototype.patch_fromText=function(t){var e=[];if(!t)return e;for(var n=t.split(`
3
- `),r=0,s=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;r<n.length;){var i=n[r].match(s);if(!i)throw new Error("Invalid patch string: "+n[r]);var o=new O.patch_obj;for(e.push(o),o.start1=parseInt(i[1],10),i[2]===""?(o.start1--,o.length1=1):i[2]=="0"?o.length1=0:(o.start1--,o.length1=parseInt(i[2],10)),o.start2=parseInt(i[3],10),i[4]===""?(o.start2--,o.length2=1):i[4]=="0"?o.length2=0:(o.start2--,o.length2=parseInt(i[4],10)),r++;r<n.length;){var l=n[r].charAt(0);try{var a=decodeURI(n[r].substring(1));}catch{throw new Error("Illegal escape in patch_fromText: "+a)}if(l=="-")o.diffs.push(new O.Diff(H,a));else if(l=="+")o.diffs.push(new O.Diff(Q,a));else if(l==" ")o.diffs.push(new O.Diff(z,a));else {if(l=="@")break;if(l!=="")throw new Error('Invalid patch mode "'+l+'" in: '+a)}r++;}}return e};O.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0;};O.patch_obj.prototype.toString=function(){var t,e;this.length1===0?t=this.start1+",0":this.length1==1?t=this.start1+1:t=this.start1+1+","+this.length1,this.length2===0?e=this.start2+",0":this.length2==1?e=this.start2+1:e=this.start2+1+","+this.length2;for(var n=["@@ -"+t+" +"+e+` @@
1
+ 'use strict';var n8nWorkflow=require('n8n-workflow');var ki=Object.create;var Ct=Object.defineProperty;var Ei=Object.getOwnPropertyDescriptor;var Ai=Object.getOwnPropertyNames;var Ci=Object.getPrototypeOf,Pi=Object.prototype.hasOwnProperty;var y=(t,e)=>Ct(t,"name",{value:e,configurable:true});var wn=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Ti=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ai(e))!Pi.call(t,s)&&s!==n&&Ct(t,s,{get:()=>e[s],enumerable:!(r=Ei(e,s))||r.enumerable});return t};var Pt=(t,e,n)=>(n=t!=null?ki(Ci(t)):{},Ti(Ct(n,"default",{value:t,enumerable:true}),t));var Cn=wn((Ra,An)=>{An.exports={createRequire:y(function(){return function(){return {}}},"createRequire")};});var Lt=wn((Wa,ze)=>{var O=y(function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32;},"diff_match_patch"),H=-1,Q=1,z=0;O.Diff=function(t,e){return [t,e]};O.prototype.diff_main=function(t,e,n,r){typeof r>"u"&&(this.Diff_Timeout<=0?r=Number.MAX_VALUE:r=new Date().getTime()+this.Diff_Timeout*1e3);var s=r;if(t==null||e==null)throw new Error("Null input. (diff_main)");if(t==e)return t?[new O.Diff(z,t)]:[];typeof n>"u"&&(n=true);var i=n,o=this.diff_commonPrefix(t,e),a=t.substring(0,o);t=t.substring(o),e=e.substring(o),o=this.diff_commonSuffix(t,e);var l=t.substring(t.length-o);t=t.substring(0,t.length-o),e=e.substring(0,e.length-o);var u=this.diff_compute_(t,e,i,s);return a&&u.unshift(new O.Diff(z,a)),l&&u.push(new O.Diff(z,l)),this.diff_cleanupMerge(u),u};O.prototype.diff_compute_=function(t,e,n,r){var s;if(!t)return [new O.Diff(Q,e)];if(!e)return [new O.Diff(H,t)];var i=t.length>e.length?t:e,o=t.length>e.length?e:t,a=i.indexOf(o);if(a!=-1)return s=[new O.Diff(Q,i.substring(0,a)),new O.Diff(z,o),new O.Diff(Q,i.substring(a+o.length))],t.length>e.length&&(s[0][0]=s[2][0]=H),s;if(o.length==1)return [new O.Diff(H,t),new O.Diff(Q,e)];var l=this.diff_halfMatch_(t,e);if(l){var u=l[0],c=l[1],d=l[2],f=l[3],h=l[4],_=this.diff_main(u,d,n,r),p=this.diff_main(c,f,n,r);return _.concat([new O.Diff(z,h)],p)}return n&&t.length>100&&e.length>100?this.diff_lineMode_(t,e,r):this.diff_bisect_(t,e,r)};O.prototype.diff_lineMode_=function(t,e,n){var r=this.diff_linesToChars_(t,e);t=r.chars1,e=r.chars2;var s=r.lineArray,i=this.diff_main(t,e,false,n);this.diff_charsToLines_(i,s),this.diff_cleanupSemantic(i),i.push(new O.Diff(z,""));for(var o=0,a=0,l=0,u="",c="";o<i.length;){switch(i[o][0]){case Q:l++,c+=i[o][1];break;case H:a++,u+=i[o][1];break;case z:if(a>=1&&l>=1){i.splice(o-a-l,a+l),o=o-a-l;for(var d=this.diff_main(u,c,false,n),f=d.length-1;f>=0;f--)i.splice(o,0,d[f]);o=o+d.length;}l=0,a=0,u="",c="";break}o++;}return i.pop(),i};O.prototype.diff_bisect_=function(t,e,n){for(var r=t.length,s=e.length,i=Math.ceil((r+s)/2),o=i,a=2*i,l=new Array(a),u=new Array(a),c=0;c<a;c++)l[c]=-1,u[c]=-1;l[o+1]=0,u[o+1]=0;for(var d=r-s,f=d%2!=0,h=0,_=0,p=0,m=0,w=0;w<i&&!(new Date().getTime()>n);w++){for(var k=-w+h;k<=w-_;k+=2){var b=o+k,g;k==-w||k!=w&&l[b-1]<l[b+1]?g=l[b+1]:g=l[b-1]+1;for(var v=g-k;g<r&&v<s&&t.charAt(g)==e.charAt(v);)g++,v++;if(l[b]=g,g>r)_+=2;else if(v>s)h+=2;else if(f){var x=o+d-k;if(x>=0&&x<a&&u[x]!=-1){var E=r-u[x];if(g>=E)return this.diff_bisectSplit_(t,e,g,v,n)}}}for(var C=-w+p;C<=w-m;C+=2){var x=o+C,E;C==-w||C!=w&&u[x-1]<u[x+1]?E=u[x+1]:E=u[x-1]+1;for(var A=E-C;E<r&&A<s&&t.charAt(r-E-1)==e.charAt(s-A-1);)E++,A++;if(u[x]=E,E>r)m+=2;else if(A>s)p+=2;else if(!f){var b=o+d-C;if(b>=0&&b<a&&l[b]!=-1){var g=l[b],v=o+g-b;if(E=r-E,g>=E)return this.diff_bisectSplit_(t,e,g,v,n)}}}}return [new O.Diff(H,t),new O.Diff(Q,e)]};O.prototype.diff_bisectSplit_=function(t,e,n,r,s){var i=t.substring(0,n),o=e.substring(0,r),a=t.substring(n),l=e.substring(r),u=this.diff_main(i,o,false,s),c=this.diff_main(a,l,false,s);return u.concat(c)};O.prototype.diff_linesToChars_=function(t,e){var n=[],r={};n[0]="";function s(l){for(var u="",c=0,d=-1,f=n.length;d<l.length-1;){d=l.indexOf(`
2
+ `,c),d==-1&&(d=l.length-1);var h=l.substring(c,d+1);(r.hasOwnProperty?r.hasOwnProperty(h):r[h]!==void 0)?u+=String.fromCharCode(r[h]):(f==i&&(h=l.substring(c),d=l.length),u+=String.fromCharCode(f),r[h]=f,n[f++]=h),c=d+1;}return u}y(s,"diff_linesToCharsMunge_");var i=4e4,o=s(t);i=65535;var a=s(e);return {chars1:o,chars2:a,lineArray:n}};O.prototype.diff_charsToLines_=function(t,e){for(var n=0;n<t.length;n++){for(var r=t[n][1],s=[],i=0;i<r.length;i++)s[i]=e[r.charCodeAt(i)];t[n][1]=s.join("");}};O.prototype.diff_commonPrefix=function(t,e){if(!t||!e||t.charAt(0)!=e.charAt(0))return 0;for(var n=0,r=Math.min(t.length,e.length),s=r,i=0;n<s;)t.substring(i,s)==e.substring(i,s)?(n=s,i=n):r=s,s=Math.floor((r-n)/2+n);return s};O.prototype.diff_commonSuffix=function(t,e){if(!t||!e||t.charAt(t.length-1)!=e.charAt(e.length-1))return 0;for(var n=0,r=Math.min(t.length,e.length),s=r,i=0;n<s;)t.substring(t.length-s,t.length-i)==e.substring(e.length-s,e.length-i)?(n=s,i=n):r=s,s=Math.floor((r-n)/2+n);return s};O.prototype.diff_commonOverlap_=function(t,e){var n=t.length,r=e.length;if(n==0||r==0)return 0;n>r?t=t.substring(n-r):n<r&&(e=e.substring(0,n));var s=Math.min(n,r);if(t==e)return s;for(var i=0,o=1;;){var a=t.substring(s-o),l=e.indexOf(a);if(l==-1)return i;o+=l,(l==0||t.substring(s-o)==e.substring(0,o))&&(i=o,o++);}};O.prototype.diff_halfMatch_=function(t,e){if(this.Diff_Timeout<=0)return null;var n=t.length>e.length?t:e,r=t.length>e.length?e:t;if(n.length<4||r.length*2<n.length)return null;var s=this;function i(_,p,m){for(var w=_.substring(m,m+Math.floor(_.length/4)),k=-1,b="",g,v,x,E;(k=p.indexOf(w,k+1))!=-1;){var C=s.diff_commonPrefix(_.substring(m),p.substring(k)),A=s.diff_commonSuffix(_.substring(0,m),p.substring(0,k));b.length<A+C&&(b=p.substring(k-A,k)+p.substring(k,k+C),g=_.substring(0,m-A),v=_.substring(m+C),x=p.substring(0,k-A),E=p.substring(k+C));}return b.length*2>=_.length?[g,v,x,E,b]:null}y(i,"diff_halfMatchI_");var o=i(n,r,Math.ceil(n.length/4)),a=i(n,r,Math.ceil(n.length/2)),l;if(!o&&!a)return null;a?o?l=o[4].length>a[4].length?o:a:l=a:l=o;var u,c,d,f;t.length>e.length?(u=l[0],c=l[1],d=l[2],f=l[3]):(d=l[0],f=l[1],u=l[2],c=l[3]);var h=l[4];return [u,c,d,f,h]};O.prototype.diff_cleanupSemantic=function(t){for(var e=false,n=[],r=0,s=null,i=0,o=0,a=0,l=0,u=0;i<t.length;)t[i][0]==z?(n[r++]=i,o=l,a=u,l=0,u=0,s=t[i][1]):(t[i][0]==Q?l+=t[i][1].length:u+=t[i][1].length,s&&s.length<=Math.max(o,a)&&s.length<=Math.max(l,u)&&(t.splice(n[r-1],0,new O.Diff(H,s)),t[n[r-1]+1][0]=Q,r--,r--,i=r>0?n[r-1]:-1,o=0,a=0,l=0,u=0,s=null,e=true)),i++;for(e&&this.diff_cleanupMerge(t),this.diff_cleanupSemanticLossless(t),i=1;i<t.length;){if(t[i-1][0]==H&&t[i][0]==Q){var c=t[i-1][1],d=t[i][1],f=this.diff_commonOverlap_(c,d),h=this.diff_commonOverlap_(d,c);f>=h?(f>=c.length/2||f>=d.length/2)&&(t.splice(i,0,new O.Diff(z,d.substring(0,f))),t[i-1][1]=c.substring(0,c.length-f),t[i+1][1]=d.substring(f),i++):(h>=c.length/2||h>=d.length/2)&&(t.splice(i,0,new O.Diff(z,c.substring(0,h))),t[i-1][0]=Q,t[i-1][1]=d.substring(0,d.length-h),t[i+1][0]=H,t[i+1][1]=c.substring(h),i++),i++;}i++;}};O.prototype.diff_cleanupSemanticLossless=function(t){function e(h,_){if(!h||!_)return 6;var p=h.charAt(h.length-1),m=_.charAt(0),w=p.match(O.nonAlphaNumericRegex_),k=m.match(O.nonAlphaNumericRegex_),b=w&&p.match(O.whitespaceRegex_),g=k&&m.match(O.whitespaceRegex_),v=b&&p.match(O.linebreakRegex_),x=g&&m.match(O.linebreakRegex_),E=v&&h.match(O.blanklineEndRegex_),C=x&&_.match(O.blanklineStartRegex_);return E||C?5:v||x?4:w&&!b&&g?3:b||g?2:w||k?1:0}y(e,"diff_cleanupSemanticScore_");for(var n=1;n<t.length-1;){if(t[n-1][0]==z&&t[n+1][0]==z){var r=t[n-1][1],s=t[n][1],i=t[n+1][1],o=this.diff_commonSuffix(r,s);if(o){var a=s.substring(s.length-o);r=r.substring(0,r.length-o),s=a+s.substring(0,s.length-o),i=a+i;}for(var l=r,u=s,c=i,d=e(r,s)+e(s,i);s.charAt(0)===i.charAt(0);){r+=s.charAt(0),s=s.substring(1)+i.charAt(0),i=i.substring(1);var f=e(r,s)+e(s,i);f>=d&&(d=f,l=r,u=s,c=i);}t[n-1][1]!=l&&(l?t[n-1][1]=l:(t.splice(n-1,1),n--),t[n][1]=u,c?t[n+1][1]=c:(t.splice(n+1,1),n--));}n++;}};O.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/;O.whitespaceRegex_=/\s/;O.linebreakRegex_=/[\r\n]/;O.blanklineEndRegex_=/\n\r?\n$/;O.blanklineStartRegex_=/^\r?\n\r?\n/;O.prototype.diff_cleanupEfficiency=function(t){for(var e=false,n=[],r=0,s=null,i=0,o=false,a=false,l=false,u=false;i<t.length;)t[i][0]==z?(t[i][1].length<this.Diff_EditCost&&(l||u)?(n[r++]=i,o=l,a=u,s=t[i][1]):(r=0,s=null),l=u=false):(t[i][0]==H?u=true:l=true,s&&(o&&a&&l&&u||s.length<this.Diff_EditCost/2&&o+a+l+u==3)&&(t.splice(n[r-1],0,new O.Diff(H,s)),t[n[r-1]+1][0]=Q,r--,s=null,o&&a?(l=u=true,r=0):(r--,i=r>0?n[r-1]:-1,l=u=false),e=true)),i++;e&&this.diff_cleanupMerge(t);};O.prototype.diff_cleanupMerge=function(t){t.push(new O.Diff(z,""));for(var e=0,n=0,r=0,s="",i="",o;e<t.length;)switch(t[e][0]){case Q:r++,i+=t[e][1],e++;break;case H:n++,s+=t[e][1],e++;break;case z:n+r>1?(n!==0&&r!==0&&(o=this.diff_commonPrefix(i,s),o!==0&&(e-n-r>0&&t[e-n-r-1][0]==z?t[e-n-r-1][1]+=i.substring(0,o):(t.splice(0,0,new O.Diff(z,i.substring(0,o))),e++),i=i.substring(o),s=s.substring(o)),o=this.diff_commonSuffix(i,s),o!==0&&(t[e][1]=i.substring(i.length-o)+t[e][1],i=i.substring(0,i.length-o),s=s.substring(0,s.length-o))),e-=n+r,t.splice(e,n+r),s.length&&(t.splice(e,0,new O.Diff(H,s)),e++),i.length&&(t.splice(e,0,new O.Diff(Q,i)),e++),e++):e!==0&&t[e-1][0]==z?(t[e-1][1]+=t[e][1],t.splice(e,1)):e++,r=0,n=0,s="",i="";break}t[t.length-1][1]===""&&t.pop();var a=false;for(e=1;e<t.length-1;)t[e-1][0]==z&&t[e+1][0]==z&&(t[e][1].substring(t[e][1].length-t[e-1][1].length)==t[e-1][1]?(t[e][1]=t[e-1][1]+t[e][1].substring(0,t[e][1].length-t[e-1][1].length),t[e+1][1]=t[e-1][1]+t[e+1][1],t.splice(e-1,1),a=true):t[e][1].substring(0,t[e+1][1].length)==t[e+1][1]&&(t[e-1][1]+=t[e+1][1],t[e][1]=t[e][1].substring(t[e+1][1].length)+t[e+1][1],t.splice(e+1,1),a=true)),e++;a&&this.diff_cleanupMerge(t);};O.prototype.diff_xIndex=function(t,e){var n=0,r=0,s=0,i=0,o;for(o=0;o<t.length&&(t[o][0]!==Q&&(n+=t[o][1].length),t[o][0]!==H&&(r+=t[o][1].length),!(n>e));o++)s=n,i=r;return t.length!=o&&t[o][0]===H?i:i+(e-s)};O.prototype.diff_prettyHtml=function(t){for(var e=[],n=/&/g,r=/</g,s=/>/g,i=/\n/g,o=0;o<t.length;o++){var a=t[o][0],l=t[o][1],u=l.replace(n,"&amp;").replace(r,"&lt;").replace(s,"&gt;").replace(i,"&para;<br>");switch(a){case Q:e[o]='<ins style="background:#e6ffe6;">'+u+"</ins>";break;case H:e[o]='<del style="background:#ffe6e6;">'+u+"</del>";break;case z:e[o]="<span>"+u+"</span>";break}}return e.join("")};O.prototype.diff_text1=function(t){for(var e=[],n=0;n<t.length;n++)t[n][0]!==Q&&(e[n]=t[n][1]);return e.join("")};O.prototype.diff_text2=function(t){for(var e=[],n=0;n<t.length;n++)t[n][0]!==H&&(e[n]=t[n][1]);return e.join("")};O.prototype.diff_levenshtein=function(t){for(var e=0,n=0,r=0,s=0;s<t.length;s++){var i=t[s][0],o=t[s][1];switch(i){case Q:n+=o.length;break;case H:r+=o.length;break;case z:e+=Math.max(n,r),n=0,r=0;break}}return e+=Math.max(n,r),e};O.prototype.diff_toDelta=function(t){for(var e=[],n=0;n<t.length;n++)switch(t[n][0]){case Q:e[n]="+"+encodeURI(t[n][1]);break;case H:e[n]="-"+t[n][1].length;break;case z:e[n]="="+t[n][1].length;break}return e.join(" ").replace(/%20/g," ")};O.prototype.diff_fromDelta=function(t,e){for(var n=[],r=0,s=0,i=e.split(/\t/g),o=0;o<i.length;o++){var a=i[o].substring(1);switch(i[o].charAt(0)){case "+":try{n[r++]=new O.Diff(Q,decodeURI(a));}catch{throw new Error("Illegal escape in diff_fromDelta: "+a)}break;case "-":case "=":var l=parseInt(a,10);if(isNaN(l)||l<0)throw new Error("Invalid number in diff_fromDelta: "+a);var u=t.substring(s,s+=l);i[o].charAt(0)=="="?n[r++]=new O.Diff(z,u):n[r++]=new O.Diff(H,u);break;default:if(i[o])throw new Error("Invalid diff operation in diff_fromDelta: "+i[o])}}if(s!=t.length)throw new Error("Delta length ("+s+") does not equal source text length ("+t.length+").");return n};O.prototype.match_main=function(t,e,n){if(t==null||e==null||n==null)throw new Error("Null input. (match_main)");return n=Math.max(0,Math.min(n,t.length)),t==e?0:t.length?t.substring(n,n+e.length)==e?n:this.match_bitap_(t,e,n):-1};O.prototype.match_bitap_=function(t,e,n){if(e.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var r=this.match_alphabet_(e),s=this;function i(g,v){var x=g/e.length,E=Math.abs(n-v);return s.Match_Distance?x+E/s.Match_Distance:E?1:x}y(i,"match_bitapScore_");var o=this.Match_Threshold,a=t.indexOf(e,n);a!=-1&&(o=Math.min(i(0,a),o),a=t.lastIndexOf(e,n+e.length),a!=-1&&(o=Math.min(i(0,a),o)));var l=1<<e.length-1;a=-1;for(var u,c,d=e.length+t.length,f,h=0;h<e.length;h++){for(u=0,c=d;u<c;)i(h,n+c)<=o?u=c:d=c,c=Math.floor((d-u)/2+u);d=c;var _=Math.max(1,n-c+1),p=Math.min(n+c,t.length)+e.length,m=Array(p+2);m[p+1]=(1<<h)-1;for(var w=p;w>=_;w--){var k=r[t.charAt(w-1)];if(h===0?m[w]=(m[w+1]<<1|1)&k:m[w]=(m[w+1]<<1|1)&k|((f[w+1]|f[w])<<1|1)|f[w+1],m[w]&l){var b=i(h,w-1);if(b<=o)if(o=b,a=w-1,a>n)_=Math.max(1,2*n-a);else break}}if(i(h+1,n)>o)break;f=m;}return a};O.prototype.match_alphabet_=function(t){for(var e={},n=0;n<t.length;n++)e[t.charAt(n)]=0;for(var n=0;n<t.length;n++)e[t.charAt(n)]|=1<<t.length-n-1;return e};O.prototype.patch_addContext_=function(t,e){if(e.length!=0){if(t.start2===null)throw Error("patch not initialized");for(var n=e.substring(t.start2,t.start2+t.length1),r=0;e.indexOf(n)!=e.lastIndexOf(n)&&n.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)r+=this.Patch_Margin,n=e.substring(t.start2-r,t.start2+t.length1+r);r+=this.Patch_Margin;var s=e.substring(t.start2-r,t.start2);s&&t.diffs.unshift(new O.Diff(z,s));var i=e.substring(t.start2+t.length1,t.start2+t.length1+r);i&&t.diffs.push(new O.Diff(z,i)),t.start1-=s.length,t.start2-=s.length,t.length1+=s.length+i.length,t.length2+=s.length+i.length;}};O.prototype.patch_make=function(t,e,n){var r,s;if(typeof t=="string"&&typeof e=="string"&&typeof n>"u")r=t,s=this.diff_main(r,e,true),s.length>2&&(this.diff_cleanupSemantic(s),this.diff_cleanupEfficiency(s));else if(t&&typeof t=="object"&&typeof e>"u"&&typeof n>"u")s=t,r=this.diff_text1(s);else if(typeof t=="string"&&e&&typeof e=="object"&&typeof n>"u")r=t,s=e;else if(typeof t=="string"&&typeof e=="string"&&n&&typeof n=="object")r=t,s=n;else throw new Error("Unknown call format to patch_make.");if(s.length===0)return [];for(var i=[],o=new O.patch_obj,a=0,l=0,u=0,c=r,d=r,f=0;f<s.length;f++){var h=s[f][0],_=s[f][1];switch(!a&&h!==z&&(o.start1=l,o.start2=u),h){case Q:o.diffs[a++]=s[f],o.length2+=_.length,d=d.substring(0,u)+_+d.substring(u);break;case H:o.length1+=_.length,o.diffs[a++]=s[f],d=d.substring(0,u)+d.substring(u+_.length);break;case z:_.length<=2*this.Patch_Margin&&a&&s.length!=f+1?(o.diffs[a++]=s[f],o.length1+=_.length,o.length2+=_.length):_.length>=2*this.Patch_Margin&&a&&(this.patch_addContext_(o,c),i.push(o),o=new O.patch_obj,a=0,c=d,l=u);break}h!==Q&&(l+=_.length),h!==H&&(u+=_.length);}return a&&(this.patch_addContext_(o,c),i.push(o)),i};O.prototype.patch_deepCopy=function(t){for(var e=[],n=0;n<t.length;n++){var r=t[n],s=new O.patch_obj;s.diffs=[];for(var i=0;i<r.diffs.length;i++)s.diffs[i]=new O.Diff(r.diffs[i][0],r.diffs[i][1]);s.start1=r.start1,s.start2=r.start2,s.length1=r.length1,s.length2=r.length2,e[n]=s;}return e};O.prototype.patch_apply=function(t,e){if(t.length==0)return [e,[]];t=this.patch_deepCopy(t);var n=this.patch_addPadding(t);e=n+e+n,this.patch_splitMax(t);for(var r=0,s=[],i=0;i<t.length;i++){var o=t[i].start2+r,a=this.diff_text1(t[i].diffs),l,u=-1;if(a.length>this.Match_MaxBits?(l=this.match_main(e,a.substring(0,this.Match_MaxBits),o),l!=-1&&(u=this.match_main(e,a.substring(a.length-this.Match_MaxBits),o+a.length-this.Match_MaxBits),(u==-1||l>=u)&&(l=-1))):l=this.match_main(e,a,o),l==-1)s[i]=false,r-=t[i].length2-t[i].length1;else {s[i]=true,r=l-o;var c;if(u==-1?c=e.substring(l,l+a.length):c=e.substring(l,u+this.Match_MaxBits),a==c)e=e.substring(0,l)+this.diff_text2(t[i].diffs)+e.substring(l+a.length);else {var d=this.diff_main(a,c,false);if(a.length>this.Match_MaxBits&&this.diff_levenshtein(d)/a.length>this.Patch_DeleteThreshold)s[i]=false;else {this.diff_cleanupSemanticLossless(d);for(var f=0,h,_=0;_<t[i].diffs.length;_++){var p=t[i].diffs[_];p[0]!==z&&(h=this.diff_xIndex(d,f)),p[0]===Q?e=e.substring(0,l+h)+p[1]+e.substring(l+h):p[0]===H&&(e=e.substring(0,l+h)+e.substring(l+this.diff_xIndex(d,f+p[1].length))),p[0]!==H&&(f+=p[1].length);}}}}}return e=e.substring(n.length,e.length-n.length),[e,s]};O.prototype.patch_addPadding=function(t){for(var e=this.Patch_Margin,n="",r=1;r<=e;r++)n+=String.fromCharCode(r);for(var r=0;r<t.length;r++)t[r].start1+=e,t[r].start2+=e;var s=t[0],i=s.diffs;if(i.length==0||i[0][0]!=z)i.unshift(new O.Diff(z,n)),s.start1-=e,s.start2-=e,s.length1+=e,s.length2+=e;else if(e>i[0][1].length){var o=e-i[0][1].length;i[0][1]=n.substring(i[0][1].length)+i[0][1],s.start1-=o,s.start2-=o,s.length1+=o,s.length2+=o;}if(s=t[t.length-1],i=s.diffs,i.length==0||i[i.length-1][0]!=z)i.push(new O.Diff(z,n)),s.length1+=e,s.length2+=e;else if(e>i[i.length-1][1].length){var o=e-i[i.length-1][1].length;i[i.length-1][1]+=n.substring(0,o),s.length1+=o,s.length2+=o;}return n};O.prototype.patch_splitMax=function(t){for(var e=this.Match_MaxBits,n=0;n<t.length;n++)if(!(t[n].length1<=e)){var r=t[n];t.splice(n--,1);for(var s=r.start1,i=r.start2,o="";r.diffs.length!==0;){var a=new O.patch_obj,l=true;for(a.start1=s-o.length,a.start2=i-o.length,o!==""&&(a.length1=a.length2=o.length,a.diffs.push(new O.Diff(z,o)));r.diffs.length!==0&&a.length1<e-this.Patch_Margin;){var u=r.diffs[0][0],c=r.diffs[0][1];u===Q?(a.length2+=c.length,i+=c.length,a.diffs.push(r.diffs.shift()),l=false):u===H&&a.diffs.length==1&&a.diffs[0][0]==z&&c.length>2*e?(a.length1+=c.length,s+=c.length,l=false,a.diffs.push(new O.Diff(u,c)),r.diffs.shift()):(c=c.substring(0,e-a.length1-this.Patch_Margin),a.length1+=c.length,s+=c.length,u===z?(a.length2+=c.length,i+=c.length):l=false,a.diffs.push(new O.Diff(u,c)),c==r.diffs[0][1]?r.diffs.shift():r.diffs[0][1]=r.diffs[0][1].substring(c.length));}o=this.diff_text2(a.diffs),o=o.substring(o.length-this.Patch_Margin);var d=this.diff_text1(r.diffs).substring(0,this.Patch_Margin);d!==""&&(a.length1+=d.length,a.length2+=d.length,a.diffs.length!==0&&a.diffs[a.diffs.length-1][0]===z?a.diffs[a.diffs.length-1][1]+=d:a.diffs.push(new O.Diff(z,d))),l||t.splice(++n,0,a);}}};O.prototype.patch_toText=function(t){for(var e=[],n=0;n<t.length;n++)e[n]=t[n];return e.join("")};O.prototype.patch_fromText=function(t){var e=[];if(!t)return e;for(var n=t.split(`
3
+ `),r=0,s=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;r<n.length;){var i=n[r].match(s);if(!i)throw new Error("Invalid patch string: "+n[r]);var o=new O.patch_obj;for(e.push(o),o.start1=parseInt(i[1],10),i[2]===""?(o.start1--,o.length1=1):i[2]=="0"?o.length1=0:(o.start1--,o.length1=parseInt(i[2],10)),o.start2=parseInt(i[3],10),i[4]===""?(o.start2--,o.length2=1):i[4]=="0"?o.length2=0:(o.start2--,o.length2=parseInt(i[4],10)),r++;r<n.length;){var a=n[r].charAt(0);try{var l=decodeURI(n[r].substring(1));}catch{throw new Error("Illegal escape in patch_fromText: "+l)}if(a=="-")o.diffs.push(new O.Diff(H,l));else if(a=="+")o.diffs.push(new O.Diff(Q,l));else if(a==" ")o.diffs.push(new O.Diff(z,l));else {if(a=="@")break;if(a!=="")throw new Error('Invalid patch mode "'+a+'" in: '+l)}r++;}}return e};O.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0;};O.patch_obj.prototype.toString=function(){var t,e;this.length1===0?t=this.start1+",0":this.length1==1?t=this.start1+1:t=this.start1+1+","+this.length1,this.length2===0?e=this.start2+",0":this.length2==1?e=this.start2+1:e=this.start2+1+","+this.length2;for(var n=["@@ -"+t+" +"+e+` @@
4
4
  `],r,s=0;s<this.diffs.length;s++){switch(this.diffs[s][0]){case Q:r="+";break;case H:r="-";break;case z:r=" ";break}n[s+1]=r+encodeURI(this.diffs[s][1])+`
5
- `;}return n.join("").replace(/%20/g," ")};We.exports=O;We.exports.diff_match_patch=O;We.exports.DIFF_DELETE=H;We.exports.DIFF_INSERT=Q;We.exports.DIFF_EQUAL=z;});var $e="application/vnd.openxmlformats-officedocument.wordprocessingml.document";function gn(t,e){return e.split(".").reduce((n,r)=>{if(n&&typeof n=="object")return n[r]},t)}y(gn,"getNestedProperty");async function Ai(t,e){let n=this.getInputData()[t];if(!n.binary||!n.binary[e])throw new n8nWorkflow.NodeOperationError(this.getNode(),`No binary data found on property "${e}"`,{description:"Verify that the upstream node produced binary data and that the property name matches.",itemIndex:t});let r=n.binary[e],s=await this.helpers.getBinaryDataBuffer(t,e),i=r.fileName??"document.docx";return {buffer:s,fileName:i}}y(Ai,"getDocxBuffer");async function le(t,e){if(e.mode==="fromInput")return Ai.call(this,t,e.binaryPropertyName);let{sourceNodeName:n,binaryPropertyName:r}=e,s="sourceBinaryId"in e?e.sourceBinaryId:void 0;if(s&&s.trim()!=="")try{let d=await this.helpers.getBinaryStream(s);return {buffer:await this.helpers.binaryToBuffer(d),fileName:"document.docx"}}catch(d){throw new n8nWorkflow.NodeApiError(this.getNode(),{message:d.message},{message:`Failed to load document from Binary ID '${s}'.`,description:`The binary with ID '${s}' could not be loaded. This usually means the binary has expired, been garbage-collected, or the ID is incorrect.`,itemIndex:t})}if(!n||n.trim()==="")throw new n8nWorkflow.NodeApiError(this.getNode(),{message:"Source Node Name is empty"},{message:"Source Node Name is required when Document Source is 'From Another Node'.",description:"Set 'Source Node Name' to the exact name of the node in this workflow whose output holds the .docx binary (e.g. the trigger node). Node names are case-sensitive and must match the node label in the canvas exactly.",itemIndex:t});let i=n.replace(/'/g,"\\'"),o=`{{ $('${i}').first().binary.${r} }}`,l;try{l=this.evaluateExpression(o,t);}catch(d){throw new n8nWorkflow.NodeApiError(this.getNode(),{message:d.message},{message:`Failed to resolve binary from source node '${n}'.`,description:`Could not evaluate '${o}'. Verify the source node name is exactly correct (case-sensitive, including spaces and punctuation). Underlying error: ${d.message}`,itemIndex:t})}if(l==null||typeof l!="object"){let d=`{{ $('${i}').first().json }}`,f;try{f=this.evaluateExpression(d,t);}catch{f=void 0;}if(f==null)throw new n8nWorkflow.NodeApiError(this.getNode(),{message:"Source node produced no output"},{message:`Source node '${n}' has no output.`,description:`The expression '${o}' resolved to undefined and the node appears not to have executed in this run. Verify that '${n}' is upstream of this Adeu node, that its name matches exactly (case-sensitive), and that it has run successfully.`,itemIndex:t});let h="";try{let p=this.evaluateExpression(`{{ Object.keys($('${i}').first().binary || {}) }}`,t);Array.isArray(p)&&p.length>0?h=` Available binary properties on '${n}': `+p.map(_=>`'${_}'`).join(", ")+".":Array.isArray(p)&&p.length===0&&(h=` Source node '${n}' has no binary properties at all.`);}catch{}throw new n8nWorkflow.NodeApiError(this.getNode(),{message:"Binary property not found"},{message:`Source node '${n}' has no binary on property '${r}'.`,description:`The expression '${o}' resolved to undefined.${h} Update 'Binary Property Name' to match an existing property, or change the source node so it outputs the .docx on the expected property.`,itemIndex:t})}let a=l,u;try{if(a.id){let d=await this.helpers.getBinaryStream(a.id);u=await this.helpers.binaryToBuffer(d);}else if(a.data)u=Buffer.from(a.data,"base64");else throw new Error("Resolved binary metadata has neither an 'id' nor 'data' field.")}catch(d){throw new n8nWorkflow.NodeApiError(this.getNode(),{message:d.message},{message:`Failed to read binary content from source node '${n}'.`,description:`The binary metadata was found on property '${r}', but its contents could not be loaded. Underlying error: ${d.message}`,itemIndex:t})}let c=a.fileName??"document.docx";return {buffer:u,fileName:c}}y(le,"getDocxBufferFromSource");function ct(t,e){let n=t.lastIndexOf(".");return `${n===-1?t:t.substring(0,n)}_${e}.docx`}y(ct,"buildOutputFileName");var Ci={strict:"strict",exact:"strict",single:"strict",first:"first","first-occurrence":"first","first-only":"first",all:"all",global:"all",bulk:"all",alloccurrences:"all","all-occurrences":"all",every:"all"};function Pi(t){if(!(t===null||typeof t!="object"||Array.isArray(t))&&((!("type"in t)||t.type===void 0||t.type===null)&&("cells"in t?t.type="insert_row":"text"in t&&"target_id"in t?t.type="reply":"target_text"in t&&"new_text"in t&&(t.type="modify")),"match_mode"in t)){let e=t.match_mode;if(typeof e!="string")delete t.match_mode;else {let n=Ci[e.trim().toLowerCase()];n===void 0?delete t.match_mode:t.match_mode=n;}}}y(Pi,"coerceChangeItemInPlace");function wn(t){return t.map(e=>{let n=e;if(typeof e=="string")try{let r=JSON.parse(e);n=r!==null&&typeof r=="object"?r:e;}catch{n=e;}return n!==null&&typeof n=="object"&&!Array.isArray(n)&&Pi(n),n})}y(wn,"coerceChangesArray");function yn(t,e,n){if(t==null||t==="")throw new n8nWorkflow.NodeOperationError(this.getNode(),`Parameter "${n}" is empty`,{description:`Provide a JSON value for "${n}".`,itemIndex:e});if(typeof t=="object")return t;let r=t.trim();r.startsWith("```")&&(r=r.replace(/^```[a-zA-Z]*\n?/,""),r=r.replace(/\n?```$/,"")),r=r.trim();try{return JSON.parse(r)}catch(s){throw new n8nWorkflow.NodeOperationError(this.getNode(),`Parameter "${n}" is not valid JSON`,{description:s.message,itemIndex:e})}}y(yn,"parseJsonParameter");function vn(t,e){let n=t.message??"Unknown error",r=t.name??"",s=t.errors,i=Array.isArray(s)?s.join(`
6
- `):n,o=i.toLowerCase();if(r==="BatchValidationError"){let l="Batch validation failed.",a=`Review the listed failures:
7
- `+i;return o.includes("target text not found")?(l="An edit could not be applied: target text not found.",a="Verify the exact `target_text` string \u2014 including punctuation and whitespace \u2014 against the document. Check the individual failures:\n"+i):o.includes("ambiguous match")?(l="An edit matched multiple locations in the document.",a="Provide more surrounding context in `target_text` to uniquely identify the location:\n"+i):o.includes("read-only")||o.includes("readonly")?(l="An edit targeted a read-only structural element.",a=`Cross-references, footnotes, hyperlinks, and the Structural Appendix cannot be modified via text replacement:
8
- `+i):o.includes("comment range from another author")?(l="A match_mode='all' edit would sweep through another author's comment range.",a=`Bulk replacements are blocked from running through foreign comment ranges. Target the commented text deliberately with match_mode 'strict' or 'first', or scope the edit outside of it:
9
- `+i):o.includes("another author")||o.includes("nested")?(l="An edit overlaps with a pending tracked change by another author.",a=`Accept or reject the conflicting change first, or scope your edit outside of it:
10
- `+i):o.includes("control character")?(l="An edit contains invalid XML control characters.",a=`Remove non-printable control characters from your edit string before submitting:
11
- `+i):o.includes("criticmarkup tags")&&(l="Do not manually include CriticMarkup tags in new_text.",a="The engine applies tracked change tags automatically. Pass clean replacement text in `new_text`:\n"+i),new n8nWorkflow.NodeApiError(this.getNode(),{message:i,errors:s},{message:l,description:a,itemIndex:e})}return o.includes("invalid docx")||o.includes("missing word/document.xml")?new n8nWorkflow.NodeApiError(this.getNode(),{message:n},{message:"The document could not be opened.",description:"Verify the input binary is a valid .docx file (not .doc, .pdf, or another format).",itemIndex:e}):new n8nWorkflow.NodeApiError(this.getNode(),{message:n},{message:"Adeu engine error.",description:n,itemIndex:e})}y(vn,"mapAdeuErrorToNodeApiError");function Ti(t){if(!t||typeof t!="object")return false;let e=t;return typeof e.id=="string"&&typeof e.fileName=="string"&&typeof e.mimeType=="string"}y(Ti,"isStashedBinaryEntry");var xn=[{displayName:"Static Data Key",name:"staticDataKey",type:"string",default:"adeu_last_redlined",required:true,placeholder:"e.g. adeu_last_redlined",description:"Key in workflow global static data to read the stashed binary metadata from (string). When the Apply Edits operation runs as an AI Agent tool, n8n's tool wrapper strips the binary from its output before any downstream node can see it. To work around that, Apply Edits writes the binary's storage id into workflow static data under 'adeu_last_redlined'. This operation reads that entry back, fetches the original buffer via getBinaryStream, and attaches a fresh IBinaryData onto the outgoing item. Leave the default unless you've customized the stash key on the Apply Edits side.",displayOptions:{show:{resource:["document"],operation:["hydrateToolOutput"]}}},{displayName:"Output Binary Property",name:"outputBinaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property on the outgoing item that will hold the hydrated .docx (string, e.g. 'data'). Downstream nodes (e.g. Write Binary File, Gmail send) should be configured to read from this property name.",displayOptions:{show:{resource:["document"],operation:["hydrateToolOutput"]}}},{displayName:"On Missing",name:"onMissing",type:"options",default:"emit_empty",description:"What to do when no stashed binary entry is found under the configured key. 'Emit Empty' is the typical AI Agent path: emits an item with json.hydrated=false and no binary, so a downstream If node can gate any write step on whether the LLM actually called Apply Edits this turn. 'Throw' is for deterministic pipelines where the stash MUST be present and a missing entry indicates a workflow bug.",options:[{name:"Emit Empty",value:"emit_empty",description:"Emit a single item with JSON.hydrated=false and no binary. Downstream If on JSON.hydrated gates the write."},{name:"Throw",value:"throw",description:"Throw a NodeOperationError. Use when a missing stash indicates a workflow bug."}],displayOptions:{show:{resource:["document"],operation:["hydrateToolOutput"]}}},{displayName:"Clear After Read",name:"clearAfterRead",type:"boolean",default:true,description:"Whether to delete the static data entry after a successful hydration so it does not leak across workflow runs. Set false if you want to inspect or re-read the entry from a later node in the same run.",displayOptions:{show:{resource:["document"],operation:["hydrateToolOutput"]}}},{displayName:"Output Path Template",name:"outputPathTemplate",type:"string",default:"",placeholder:"e.g. C:\\Users\\Uzair\\.n8n-files\\{baseName}_{timestamp}.docx",description:"Optional template to compute the final write path on disk, returned on the output JSON as 'outputPath'. If set, you can configure downstream Write nodes to simply read '{{ $json.outputPath }}' with zero escaping risks. Supports these placeholders: '{baseName}' (filename with extension stripped), '{timestamp}' (current ISO 8601 timestamp with colons and dots replaced by dashes for Windows file compatibility), '{fileName}' (the stashed filename including extension), and '{ext}' (e.g., '.docx').",displayOptions:{show:{resource:["document"],operation:["hydrateToolOutput"]}}}];async function Nn(t){let e=this.getNodeParameter("staticDataKey",t),n=this.getNodeParameter("outputBinaryPropertyName",t),r=this.getNodeParameter("onMissing",t),s=this.getNodeParameter("clearAfterRead",t),i=this.getWorkflowStaticData("global"),o=i[e];if(!Ti(o)){if(r==="throw")throw new n8nWorkflow.NodeOperationError(this.getNode(),`No stashed binary found under static data key "${e}".`,{description:"The Apply Edits operation writes a stash entry into workflow static data only when it runs as an AI Agent tool and produces a binary. Verify that Apply Edits was actually called by the agent this turn, that it ran successfully, and that the key matches the one used on the writing side.",itemIndex:t});return [{json:{hydrated:false},pairedItem:{item:t}}]}let{id:l,fileName:a,mimeType:u}=o,c;try{let _=await this.helpers.getBinaryStream(l);c=await this.helpers.binaryToBuffer(_);}catch(_){throw new n8nWorkflow.NodeOperationError(this.getNode(),`Failed to load stashed binary (id=${l}) from external storage.`,{description:`The stash entry under "${e}" points at binary id "${l}", but the underlying data could not be loaded. This usually means the binary has been garbage-collected (n8n's execution data retention may be too short) or external storage is unavailable. Underlying error: ${_.message}`,itemIndex:t})}let d=u||$e,f=await this.helpers.prepareBinaryData(c,a,d);s&&delete i[e];let h=this.getNodeParameter("outputPathTemplate",t,""),p;if(h.trim()!==""){let _=a.replace(/\.docx$/i,""),g=a.match(/\.docx$/i)?.[0]??".docx",w=new Date().toISOString().replace(/[:.]/g,"-").replace(/Z$/,"");p=h.replaceAll("{baseName}",_).replaceAll("{timestamp}",w).replaceAll("{fileName}",a).replaceAll("{ext}",g);}return [{json:{hydrated:true,fileName:a,sourceBinaryId:l,mimeType:d,...p!==void 0?{outputPath:p}:{}},binary:{[n]:f},pairedItem:{item:t}}]}y(Nn,"executeHydrateToolOutput");var In=mn(En());var Si=(0, In.createRequire)("/"),Fe,Ii,$i;try{Fe=Si("worker_threads"),Ii=Fe.Worker,$i=Fe.isMarkedAsUntransferable;}catch{}var G=Uint8Array,ie=Uint16Array,Bt=Int32Array,dt=new G([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ft=new G([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Ot=new G([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),$n=y(function(t,e){for(var n=new ie(31),r=0;r<31;++r)n[r]=e+=1<<t[r-1];for(var s=new Bt(n[30]),r=1;r<30;++r)for(var i=n[r];i<n[r+1];++i)s[i]=i-n[r]<<5|r;return {b:n,r:s}},"freb"),Fe=$n(dt,2),On=Fe.b,Dt=Fe.r;On[28]=258,Dt[258]=28;var Dn=$n(ft,0),Oi=Dn.b,An=Dn.r,Mt=new ie(32768);for(q=0;q<32768;++q)ge=(q&43690)>>1|(q&21845)<<1,ge=(ge&52428)>>2|(ge&13107)<<2,ge=(ge&61680)>>4|(ge&3855)<<4,Mt[q]=((ge&65280)>>8|(ge&255)<<8)>>1;var ge,q,fe=y((function(t,e,n){for(var r=t.length,s=0,i=new ie(e);s<r;++s)t[s]&&++i[t[s]-1];var o=new ie(e);for(s=1;s<e;++s)o[s]=o[s-1]+i[s-1]<<1;var l;if(n){l=new ie(1<<e);var a=15-e;for(s=0;s<r;++s)if(t[s])for(var u=s<<4|t[s],c=e-t[s],d=o[t[s]-1]++<<c,f=d|(1<<c)-1;d<=f;++d)l[Mt[d]>>a]=u;}else for(l=new ie(r),s=0;s<r;++s)t[s]&&(l[s]=Mt[o[t[s]-1]++]>>15-t[s]);return l}),"hMap"),be=new G(288);for(q=0;q<144;++q)be[q]=8;var q;for(q=144;q<256;++q)be[q]=9;var q;for(q=256;q<280;++q)be[q]=7;var q;for(q=280;q<288;++q)be[q]=8;var q,Ke=new G(32);for(q=0;q<32;++q)Ke[q]=5;var q,Di=fe(be,9,0),Mi=fe(be,9,1),Ri=fe(Ke,5,0),ji=fe(Ke,5,1),Tt=y(function(t){for(var e=t[0],n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},"max"),ce=y(function(t,e,n){var r=e/8|0;return (t[r]|t[r+1]<<8)>>(e&7)&n},"bits"),St=y(function(t,e){var n=e/8|0;return (t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},"bits16"),Wt=y(function(t){return (t+7)/8|0},"shft"),et=y(function(t,e,n){return (e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new G(t.subarray(e,n))},"slc");var Fi=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],ee=y(function(t,e,n){var r=new Error(e||Fi[t]);if(r.code=t,Error.captureStackTrace&&Error.captureStackTrace(r,ee),!n)throw r;return r},"err"),Bi=y(function(t,e,n,r){var s=t.length,i=r?r.length:0;if(!s||e.f&&!e.l)return n||new G(0);var o=!n,l=o||e.i!=2,a=e.i;o&&(n=new G(s*3));var u=y(function(Ye){var Ge=n.length;if(Ye>Ge){var je=new G(Math.max(Ge*2,Ye));je.set(n),n=je;}},"cbuf"),c=e.f||0,d=e.p||0,f=e.b||0,h=e.l,p=e.d,_=e.m,g=e.n,w=s*8;do{if(!h){c=ce(t,d,1);var k=ce(t,d+1,3);if(d+=3,k)if(k==1)h=Mi,p=ji,_=9,g=5;else if(k==2){var N=ce(t,d,31)+257,A=ce(t,d+10,15)+4,C=N+ce(t,d+5,31)+1;d+=14;for(var x=new G(C),E=new G(19),T=0;T<A;++T)E[Ot[T]]=ce(t,d+T*3,7);d+=A*3;for(var D=Tt(E),P=(1<<D)-1,R=fe(E,D,1),T=0;T<C;){var $=R[ce(t,d,P)];d+=$&15;var b=$>>4;if(b<16)x[T++]=b;else {var S=0,j=0;for(b==16?(j=3+ce(t,d,3),d+=2,S=x[T-1]):b==17?(j=3+ce(t,d,7),d+=3):b==18&&(j=11+ce(t,d,127),d+=7);j--;)x[T++]=S;}}var F=x.subarray(0,N),B=x.subarray(N);_=Tt(F),g=Tt(B),h=fe(F,_,1),p=fe(B,g,1);}else ee(1);else {var b=Wt(d)+4,m=t[b-4]|t[b-3]<<8,v=b+m;if(v>s){a&&ee(0);break}l&&u(f+m),n.set(t.subarray(b,v),f),e.b=f+=m,e.p=d=v*8,e.f=c;continue}if(d>w){a&&ee(0);break}}l&&u(f+131072);for(var L=(1<<_)-1,U=(1<<g)-1,Y=d;;Y=d){var S=h[St(t,d)&L],X=S>>4;if(d+=S&15,d>w){a&&ee(0);break}if(S||ee(2),X<256)n[f++]=X;else if(X==256){Y=d,h=null;break}else {var J=X-254;if(X>264){var T=X-257,W=dt[T];J=ce(t,d,(1<<W)-1)+On[T],d+=W;}var te=p[St(t,d)&U],ue=te>>4;te||ee(3),d+=te&15;var B=Oi[ue];if(ue>3){var W=ft[ue];B+=St(t,d)&(1<<W)-1,d+=W;}if(d>w){a&&ee(0);break}l&&u(f+131072);var _e=f+J;if(f<B){var at=i-B,lt=Math.min(B,_e);for(at+f<0&&ee(3);f<lt;++f)n[f]=r[at+f];}for(;f<_e;++f)n[f]=n[f-B];}}e.l=h,e.p=Y,e.b=f,e.f=c,h&&(c=1,e.m=_,e.d=p,e.n=g);}while(!c);return f!=n.length&&o?et(n,0,f):n.subarray(0,f)},"inflt"),we=y(function(t,e,n){n<<=e&7;var r=e/8|0;t[r]|=n,t[r+1]|=n>>8;},"wbits"),Ve=y(function(t,e,n){n<<=e&7;var r=e/8|0;t[r]|=n,t[r+1]|=n>>8,t[r+2]|=n>>16;},"wbits16"),It=y(function(t,e){for(var n=[],r=0;r<t.length;++r)t[r]&&n.push({s:r,f:t[r]});var s=n.length,i=n.slice();if(!s)return {t:Rn,l:0};if(s==1){var o=new G(n[0].s+1);return o[n[0].s]=1,{t:o,l:1}}n.sort(function(v,N){return v.f-N.f}),n.push({s:-1,f:25001});var l=n[0],a=n[1],u=0,c=1,d=2;for(n[0]={s:-1,f:l.f+a.f,l,r:a};c!=s-1;)l=n[n[u].f<n[d].f?u++:d++],a=n[u!=c&&n[u].f<n[d].f?u++:d++],n[c++]={s:-1,f:l.f+a.f,l,r:a};for(var f=i[0].s,r=1;r<s;++r)i[r].s>f&&(f=i[r].s);var h=new ie(f+1),p=Rt(n[c-1],h,0);if(p>e){var r=0,_=0,g=p-e,w=1<<g;for(i.sort(function(N,A){return h[A.s]-h[N.s]||N.f-A.f});r<s;++r){var k=i[r].s;if(h[k]>e)_+=w-(1<<p-h[k]),h[k]=e;else break}for(_>>=g;_>0;){var b=i[r].s;h[b]<e?_-=1<<e-h[b]++-1:++r;}for(;r>=0&&_;--r){var m=i[r].s;h[m]==e&&(--h[m],++_);}p=e;}return {t:new G(h),l:p}},"hTree"),Rt=y(function(t,e,n){return t.s==-1?Math.max(Rt(t.l,e,n+1),Rt(t.r,e,n+1)):e[t.s]=n},"ln"),Cn=y(function(t){for(var e=t.length;e&&!t[--e];);for(var n=new ie(++e),r=0,s=t[0],i=1,o=y(function(a){n[r++]=a;},"w"),l=1;l<=e;++l)if(t[l]==s&&l!=e)++i;else {if(!s&&i>2){for(;i>138;i-=138)o(32754);i>2&&(o(i>10?i-11<<5|28690:i-3<<5|12305),i=0);}else if(i>3){for(o(s),--i;i>6;i-=6)o(8304);i>2&&(o(i-3<<5|8208),i=0);}for(;i--;)o(s);i=1,s=t[l];}return {c:n.subarray(0,r),n:e}},"lc"),Ze=y(function(t,e){for(var n=0,r=0;r<e.length;++r)n+=t[r]*e[r];return n},"clen"),Mn=y(function(t,e,n){var r=n.length,s=Wt(e+2);t[s]=r&255,t[s+1]=r>>8,t[s+2]=t[s]^255,t[s+3]=t[s+1]^255;for(var i=0;i<r;++i)t[s+i+4]=n[i];return (s+4+r)*8},"wfblk"),Pn=y(function(t,e,n,r,s,i,o,l,a,u,c){we(e,c++,n),++s[256];for(var d=It(s,15),f=d.t,h=d.l,p=It(i,15),_=p.t,g=p.l,w=Cn(f),k=w.c,b=w.n,m=Cn(_),v=m.c,N=m.n,A=new ie(19),C=0;C<k.length;++C)++A[k[C]&31];for(var C=0;C<v.length;++C)++A[v[C]&31];for(var x=It(A,7),E=x.t,T=x.l,D=19;D>4&&!E[Ot[D-1]];--D);var P=u+5<<3,R=Ze(s,be)+Ze(i,Ke)+o,$=Ze(s,f)+Ze(i,_)+o+14+3*D+Ze(A,E)+2*A[16]+3*A[17]+7*A[18];if(a>=0&&P<=R&&P<=$)return Mn(e,c,t.subarray(a,a+u));var S,j,F,B;if(we(e,c,1+($<R)),c+=2,$<R){S=fe(f,h,0),j=f,F=fe(_,g,0),B=_;var L=fe(E,T,0);we(e,c,b-257),we(e,c+5,N-1),we(e,c+10,D-4),c+=14;for(var C=0;C<D;++C)we(e,c+3*C,E[Ot[C]]);c+=3*D;for(var U=[k,v],Y=0;Y<2;++Y)for(var X=U[Y],C=0;C<X.length;++C){var J=X[C]&31;we(e,c,L[J]),c+=E[J],J>15&&(we(e,c,X[C]>>5&127),c+=X[C]>>12);}}else S=Di,j=be,F=Ri,B=Ke;for(var C=0;C<l;++C){var W=r[C];if(W>255){var J=W>>18&31;Ve(e,c,S[J+257]),c+=j[J+257],J>7&&(we(e,c,W>>23&31),c+=dt[J]);var te=W&31;Ve(e,c,F[te]),c+=B[te],te>3&&(Ve(e,c,W>>5&8191),c+=ft[te]);}else Ve(e,c,S[W]),c+=j[W];}return Ve(e,c,S[256]),c+j[256]},"wblk"),Wi=new Bt([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Rn=new G(0),zi=y(function(t,e,n,r,s,i){var o=i.z||t.length,l=new G(r+o+5*(1+Math.ceil(o/7e3))+s),a=l.subarray(r,l.length-s),u=i.l,c=(i.r||0)&7;if(e){c&&(a[0]=i.r>>3);for(var d=Wi[e-1],f=d>>13,h=d&8191,p=(1<<n)-1,_=i.p||new ie(32768),g=i.h||new ie(p+1),w=Math.ceil(n/3),k=2*w,b=y(function(At){return (t[At]^t[At+1]<<w^t[At+2]<<k)&p},"hsh"),m=new Bt(25e3),v=new ie(288),N=new ie(32),A=0,C=0,x=i.i||0,E=0,T=i.w||0,D=0;x+2<o;++x){var P=b(x),R=x&32767,$=g[P];if(_[R]=$,g[P]=R,T<=x){var S=o-x;if((A>7e3||E>24576)&&(S>423||!u)){c=Pn(t,a,0,m,v,N,C,E,D,x-D,c),E=A=C=0,D=x;for(var j=0;j<286;++j)v[j]=0;for(var j=0;j<30;++j)N[j]=0;}var F=2,B=0,L=h,U=R-$&32767;if(S>2&&P==b(x-U))for(var Y=Math.min(f,S)-1,X=Math.min(32767,x),J=Math.min(258,S);U<=X&&--L&&R!=$;){if(t[x+F]==t[x+F-U]){for(var W=0;W<J&&t[x+W]==t[x+W-U];++W);if(W>F){if(F=W,B=U,W>Y)break;for(var te=Math.min(U,W-2),ue=0,j=0;j<te;++j){var _e=x-U+j&32767,at=_[_e],lt=_e-at&32767;lt>ue&&(ue=lt,$=_e);}}}R=$,$=_[R],U+=R-$&32767;}if(B){m[E++]=268435456|Dt[F]<<18|An[B];var Ye=Dt[F]&31,Ge=An[B]&31;C+=dt[Ye]+ft[Ge],++v[257+Ye],++N[Ge],T=x+F,++A;}else m[E++]=t[x],++v[t[x]];}}for(x=Math.max(x,T);x<o;++x)m[E++]=t[x],++v[t[x]];c=Pn(t,a,u,m,v,N,C,E,D,x-D,c),u||(i.r=c&7|a[c/8|0]<<3,c-=7,i.h=g,i.p=_,i.i=x,i.w=T);}else {for(var x=i.w||0;x<o+u;x+=65535){var je=x+65535;je>=o&&(a[c/8|0]=u,je=o),c=Mn(a,c+1,t.subarray(x,je));}i.i=o;}return et(l,0,r+Wt(c)+s)},"dflt"),Li=(function(){for(var t=new Int32Array(256),e=0;e<256;++e){for(var n=e,r=9;--r;)n=(n&1&&-306674912)^n>>>1;t[e]=n;}return t})(),Ui=y(function(){var t=-1;return {p:y(function(e){for(var n=t,r=0;r<e.length;++r)n=Li[n&255^e[r]]^n>>>8;t=n;},"p"),d:y(function(){return ~t},"d")}},"crc");var qi=y(function(t,e,n,r,s){if(!s&&(s={l:1},e.dictionary)){var i=e.dictionary.subarray(-32768),o=new G(i.length+t.length);o.set(i),o.set(t,i.length),t=o,s.w=i.length;}return zi(t,e.level==null?6:e.level,e.mem==null?s.l?Math.ceil(Math.max(8,Math.min(13,Math.log(t.length)))*1.5):20:12+e.mem,n,r,s)},"dopt"),jn=y(function(t,e){var n={};for(var r in t)n[r]=t[r];for(var r in e)n[r]=e[r];return n},"mrg");var de=y(function(t,e){return t[e]|t[e+1]<<8},"b2"),oe=y(function(t,e){return (t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0},"b4"),$t=y(function(t,e){return oe(t,e)+oe(t,e+4)*4294967296},"b8"),K=y(function(t,e,n){for(;n;++e)t[e]=n,n>>>=8;},"wbytes");function Ji(t,e){return qi(t,e||{},0,0)}y(Ji,"deflateSync");function Hi(t,e){return Bi(t,{i:2},e&&e.out,e&&e.dictionary)}y(Hi,"inflateSync");var Fn=y(function(t,e,n,r){for(var s in t){var i=t[s],o=e+s,l=r;Array.isArray(i)&&(l=jn(r,i[1]),i=i[0]),ArrayBuffer.isView(i)?n[o]=[i,l]:(n[o+="/"]=[new G(0),l],Fn(i,o,n,r));}},"fltn"),Tn=typeof TextEncoder<"u"&&new TextEncoder,jt=typeof TextDecoder<"u"&&new TextDecoder,Xi=0;try{jt.decode(Rn,{stream:!0}),Xi=1;}catch{}var Qi=y(function(t){for(var e="",n=0;;){var r=t[n++],s=(r>127)+(r>223)+(r>239);if(n+s>t.length)return {s:e,r:et(t,n-1)};s?s==3?(r=((r&15)<<18|(t[n++]&63)<<12|(t[n++]&63)<<6|t[n++]&63)-65536,e+=String.fromCharCode(55296|r>>10,56320|r&1023)):s&1?e+=String.fromCharCode((r&31)<<6|t[n++]&63):e+=String.fromCharCode((r&15)<<12|(t[n++]&63)<<6|t[n++]&63):e+=String.fromCharCode(r);}},"dutf8");function ut(t,e){if(e){for(var n=new G(t.length),r=0;r<t.length;++r)n[r]=t.charCodeAt(r);return n}if(Tn)return Tn.encode(t);for(var s=t.length,i=new G(t.length+(t.length>>1)),o=0,l=y(function(c){i[o++]=c;},"w"),r=0;r<s;++r){if(o+5>i.length){var a=new G(o+8+(s-r<<1));a.set(i),i=a;}var u=t.charCodeAt(r);u<128||e?l(u):u<2048?(l(192|u>>6),l(128|u&63)):u>55295&&u<57344?(u=65536+(u&1047552)|t.charCodeAt(++r)&1023,l(240|u>>18),l(128|u>>12&63),l(128|u>>6&63),l(128|u&63)):(l(224|u>>12),l(128|u>>6&63),l(128|u&63));}return et(i,0,o)}y(ut,"strToU8");function Oe(t,e){if(e){for(var n="",r=0;r<t.length;r+=16384)n+=String.fromCharCode.apply(null,t.subarray(r,r+16384));return n}else {if(jt)return jt.decode(t);var s=Qi(t),i=s.s,n=s.r;return n.length&&ee(8),i}}y(Oe,"strFromU8");var Yi=y(function(t,e){return e+30+de(t,e+26)+de(t,e+28)},"slzh"),Gi=y(function(t,e,n){var r=de(t,e+28),s=de(t,e+30),i=Oe(t.subarray(e+46,e+46+r),!(de(t,e+8)&2048)),o=e+46+r,l=Vi(t,o,s,n,oe(t,e+20),oe(t,e+24),oe(t,e+42)),a=l[0],u=l[1],c=l[2];return [de(t,e+10),a,u,i,o+s+de(t,e+32),c]},"zh"),Vi=y(function(t,e,n,r,s,i,o){var l=s==4294967295,a=i==4294967295,u=o==4294967295,c=e+n,d=l+a+u;if(r&&d){for(;e+4<c;e+=4+de(t,e+2))if(de(t,e)==1)return [l?$t(t,e+4+8*a):s,a?$t(t,e+4):i,u?$t(t,e+4+8*(a+l)):o,1];r<2&&ee(13);}return [s,i,o,0]},"z64hs"),Ft=y(function(t){var e=0;if(t)for(var n in t){var r=t[n].length;r>65535&&ee(9),e+=r+4;}return e},"exfl"),Sn=y(function(t,e,n,r,s,i,o,l){var a=r.length,u=n.extra,c=l&&l.length,d=Ft(u);K(t,e,o!=null?33639248:67324752),e+=4,o!=null&&(t[e++]=20,t[e++]=n.os),t[e]=20,e+=2,t[e++]=n.flag<<1|(i<0&&8),t[e++]=s&&8,t[e++]=n.compression&255,t[e++]=n.compression>>8;var f=new Date(n.mtime==null?Date.now():n.mtime),h=f.getFullYear()-1980;if((h<0||h>119)&&ee(10),K(t,e,h<<25|f.getMonth()+1<<21|f.getDate()<<16|f.getHours()<<11|f.getMinutes()<<5|f.getSeconds()>>1),e+=4,i!=-1&&(K(t,e,n.crc),K(t,e+4,i<0?-i-2:i),K(t,e+8,n.size)),K(t,e+12,a),K(t,e+14,d),e+=16,o!=null&&(K(t,e,c),K(t,e+6,n.attrs),K(t,e+10,o),e+=14),t.set(r,e),e+=a,d)for(var p in u){var _=u[p],g=_.length;K(t,e,+p),K(t,e+2,g),t.set(_,e+4),e+=4+g;}return c&&(t.set(l,e),e+=c),e},"wzh"),Zi=y(function(t,e,n,r,s){K(t,e,101010256),K(t,e+8,n),K(t,e+10,n),K(t,e+12,r),K(t,e+16,s);},"wzf");function Bn(t,e){e||(e={});var n={},r=[];Fn(t,"",n,e);var s=0,i=0;for(var o in n){var l=n[o],a=l[0],u=l[1],c=u.level==0?0:8,d=ut(o),f=d.length,h=u.comment,p=h&&ut(h),_=p&&p.length,g=Ft(u.extra);f>65535&&ee(11);var w=c?Ji(a,u):a,k=w.length,b=Ui();b.p(a),r.push(jn(u,{size:a.length,crc:b.d(),c:w,f:d,m:p,u:f!=o.length||p&&h.length!=_,o:s,compression:c})),s+=30+f+g+k,i+=76+2*(f+g)+(_||0)+k;}for(var m=new G(i+22),v=s,N=i-s,A=0;A<r.length;++A){var d=r[A];Sn(m,d.o,d,d.f,d.u,d.c.length);var C=30+d.f.length+Ft(d.extra);m.set(d.c,d.o+C),Sn(m,s,d,d.f,d.u,d.c.length,d.o,d.m),s+=16+C+(d.m?d.m.length:0);}return Zi(m,s,r.length,N,v),m}y(Bn,"zipSync");function Be(t,e){for(var n={},r=t.length-22;oe(t,r)!=101010256;--r)(!r||t.length-r>65558)&&ee(13);var s=de(t,r+8);if(!s)return {};var i=oe(t,r+16),o=oe(t,r-20)==117853008;if(o){var l=oe(t,r-12);o=oe(t,l)==101075792,o&&(s=oe(t,l+32),i=oe(t,l+48));}for(var a=e&&e.filter,u=0;u<s;++u){var c=Gi(t,i,o),d=c[0],f=c[1],h=c[2],p=c[3],_=c[4],g=c[5],w=Yi(t,g);i=_,(!a||a({name:p,size:f,originalSize:h,compression:d}))&&(d?d==8?n[p]=Hi(t.subarray(w,w+f),{out:new G(h)}):ee(14,"unknown compression type "+d):n[p]=et(t,w,w+f));}return n}y(Be,"unzipSync");var dn=mn(Wn());var Me=1,tn=3,nn=4,lr=8,rn=9,cr=class{static{y(this,"FastNode");}nodeType=0;parentNode=null;ownerDocument=null;get firstChild(){return null}get lastChild(){return null}get nextSibling(){let t=this.parentNode;if(!t)return null;let e=t.childNodes,n=e.indexOf(this);return n>=0&&n+1<e.length?e[n+1]:null}get previousSibling(){let t=this.parentNode;if(!t)return null;let e=t.childNodes,n=e.indexOf(this);return n>0?e[n-1]:null}},it=class ur extends cr{static{y(this,"_FastText");}constructor(e){super(),this.data=e;}data;nodeType=tn;get nodeName(){return "#text"}get nodeValue(){return this.data}set nodeValue(e){this.data=e;}get textContent(){return this.data}set textContent(e){this.data=e,this.ownerDocument&&this.ownerDocument._inc++;}cloneNode(e){let n=new ur(this.data);return n.ownerDocument=this.ownerDocument,n}toString(){return bt(this)}},dr=class fr extends it{static{y(this,"_FastComment");}nodeType=lr;cloneNode(e){let n=new fr(this.data);return n.ownerDocument=this.ownerDocument,n}},Ki=class hr extends it{static{y(this,"_FastCData");}nodeType=nn;cloneNode(e){let n=new hr(this.data);return n.ownerDocument=this.ownerDocument,n}},pr=class extends cr{static{y(this,"FastParent");}childNodes=[];get firstChild(){return this.childNodes.length?this.childNodes[0]:null}get lastChild(){return this.childNodes.length?this.childNodes[this.childNodes.length-1]:null}hasChildNodes(){return this.childNodes.length>0}bump(){let t=this.nodeType===rn?this:this.ownerDocument;t&&t._inc++;}appendChild(t){return t.parentNode&&t.parentNode.removeChild(t),this.childNodes.push(t),t.parentNode=this,this.bump(),t}insertBefore(t,e){if(!e)return this.appendChild(t);if(this.childNodes.indexOf(e)<0)throw new Error("insertBefore: reference node not a child");t.parentNode&&t.parentNode.removeChild(t);let r=this.childNodes.indexOf(e);return this.childNodes.splice(r,0,t),t.parentNode=this,this.bump(),t}removeChild(t){let e=this.childNodes.indexOf(t);if(e<0)throw new Error("removeChild: node is not a child");return this.childNodes.splice(e,1),t.parentNode=null,this.bump(),t}replaceChild(t,e){if(this.childNodes.indexOf(e)<0)throw new Error("replaceChild: node is not a child");t.parentNode&&t.parentNode.removeChild(t);let r=this.childNodes.indexOf(e);return this.childNodes[r]=t,t.parentNode=this,e.parentNode=null,this.bump(),e}getElementsByTagName(t){let e=[],n=t==="*",r=[];for(let s=this.childNodes.length-1;s>=0;s--)r.push(this.childNodes[s]);for(;r.length;){let s=r.pop();if(s.nodeType===Me){let i=s;(n||i.tagName===t)&&e.push(i);for(let o=i.childNodes.length-1;o>=0;o--)r.push(i.childNodes[o]);}}return e}},_r=class mr extends pr{static{y(this,"_FastElement");}constructor(e){super(),this.tagName=e;}tagName;nodeType=Me;attrs=[];get nodeName(){return this.tagName}get localName(){let e=this.tagName.indexOf(":");return e<0?this.tagName:this.tagName.slice(e+1)}get prefix(){let e=this.tagName.indexOf(":");return e<0?null:this.tagName.slice(0,e)}get nodeValue(){return null}get attributes(){let e=this.attrs.map(([n,r])=>({nodeType:2,name:n,value:r,nodeName:n,nodeValue:r,localName:n.indexOf(":")<0?n:n.slice(n.indexOf(":")+1),prefix:n.indexOf(":")<0?null:n.slice(0,n.indexOf(":")),ownerElement:this}));return e.item=n=>e[n]??null,e}toString(){return bt(this)}getAttribute(e){let n=this.attrs;for(let r=0;r<n.length;r++)if(n[r][0]===e)return n[r][1];return null}hasAttribute(e){return this.getAttribute(e)!==null}setAttribute(e,n){let r=this.attrs;for(let s=0;s<r.length;s++)if(r[s][0]===e){r[s][1]=String(n),this.ownerDocument&&this.ownerDocument._inc++;return}r.push([e,String(n)]),this.ownerDocument&&this.ownerDocument._inc++;}removeAttribute(e){let n=this.attrs;for(let r=0;r<n.length;r++)if(n[r][0]===e){n.splice(r,1),this.ownerDocument&&this.ownerDocument._inc++;return}}get textContent(){let e="",n=[];for(let r=this.childNodes.length-1;r>=0;r--)n.push(this.childNodes[r]);for(;n.length;){let r=n.pop();if(r.nodeType===tn||r.nodeType===nn)e+=r.data;else if(r.nodeType===Me){let s=r;for(let i=s.childNodes.length-1;i>=0;i--)n.push(s.childNodes[i]);}}return e}set textContent(e){for(let n of this.childNodes)n.parentNode=null;if(this.childNodes.length=0,e!==""&&e!==null&&e!==void 0){let n=new it(String(e));n.ownerDocument=this.ownerDocument,n.parentNode=this,this.childNodes.push(n);}this.ownerDocument&&this.ownerDocument._inc++;}cloneNode(e=false){let n=new mr(this.tagName);if(n.ownerDocument=this.ownerDocument,this.attrs.length&&(n.attrs=this.attrs.map(([r,s])=>[r,s])),e)for(let r of this.childNodes){let s=r.cloneNode(true);s.parentNode=n,n.childNodes.push(s);}return n}},es=class extends pr{static{y(this,"FastDocument");}nodeType=rn;_inc=1;documentElement=null;get nodeName(){return "#document"}createElement(t){let e=new _r(t);return e.ownerDocument=this,e}createElementNS(t,e){return this.createElement(e)}createTextNode(t){let e=new it(String(t));return e.ownerDocument=this,e}createComment(t){let e=new dr(String(t));return e.ownerDocument=this,e}toString(){return bt(this)}appendChild(t){let e=super.appendChild(t);return t.nodeType===Me&&(this.documentElement=t),e}replaceChild(t,e){let n=super.replaceChild(t,e);return e===this.documentElement&&t.nodeType===Me&&(this.documentElement=t),n}},ts=/&(?:amp|lt|gt|quot|apos|#x?[0-9a-fA-F]+);/g;function gr(t){return t.indexOf("&")<0?t:t.replace(ts,e=>{switch(e){case "&amp;":return "&";case "&lt;":return "<";case "&gt;":return ">";case "&quot;":return '"';case "&apos;":return "'";default:{let n=e.slice(2,-1),r=n[0]==="x"||n[0]==="X"?parseInt(n.slice(1),16):parseInt(n,10);return Number.isFinite(r)?String.fromCodePoint(r):e}}})}y(gr,"decodeEntities");function Xt(t){return t.indexOf("\r")<0?t:t.replace(/\r\n?/g,`
12
- `)}y(Xt,"normalizeLineEnds");function ns(t){let e=Xt(t),n=/[\n\t]/.test(e)?e.replace(/[\n\t]/g," "):e;return gr(n)}y(ns,"normalizeAttrValue");var zt=new Set([32,9,10,13]);function rs(t){t.charCodeAt(0)===65279&&(t=t.slice(1));let e=new es,n=e,r=0,s=t.length,i=false;for(;r<s;){let o=t.indexOf("<",r);if(o<0){if(n!==e)throw new Error("Unexpected end of XML");if(/\S/.test(t.slice(r)))throw new Error("Content after document root");break}if(o>r&&n!==e){let d=t.slice(r,o),f=new it(gr(Xt(d)));f.ownerDocument=e,f.parentNode=n,n.childNodes.push(f);}else if(o>r&&/\S/.test(t.slice(r,o)))throw new Error("Text content outside document root");r=o+1;let l=t.charCodeAt(r);if(l===47){let d=t.indexOf(">",r);if(d<0)throw new Error("Unterminated close tag");let f=t.slice(r+1,d).trim();if(n.nodeType!==Me||n.tagName!==f)throw new Error(`Mismatched close tag </${f}>`);n=n.parentNode??e,r=d+1;continue}if(l===63){let d=t.indexOf("?>",r);if(d<0)throw new Error("Unterminated processing instruction");r=d+2;continue}if(l===33){if(t.startsWith("!--",r)){let f=t.indexOf("-->",r+3);if(f<0)throw new Error("Unterminated comment");let h=new dr(t.slice(r+3,f));h.ownerDocument=e,n!==e&&(h.parentNode=n,n.childNodes.push(h)),r=f+3;continue}if(t.startsWith("![CDATA[",r)){let f=t.indexOf("]]>",r+8);if(f<0)throw new Error("Unterminated CDATA section");if(n!==e){let h=new Ki(Xt(t.slice(r+8,f)));h.ownerDocument=e,h.parentNode=n,n.childNodes.push(h);}r=f+3;continue}let d=t.indexOf(">",r);if(d<0)throw new Error("Unterminated declaration");r=d+1;continue}let a=r;for(;a<s;){let d=t.charCodeAt(a);if(zt.has(d)||d===62||d===47)break;a++;}if(a===r)throw new Error(`Invalid tag at offset ${o}`);let u=new _r(t.slice(r,a));if(u.ownerDocument=e,n===e){if(i)throw new Error("Multiple document roots");i=true,e.childNodes.push(u),u.parentNode=e,e.documentElement=u;}else u.parentNode=n,n.childNodes.push(u);r=a;let c=false;for(;r<s;){let d=t.charCodeAt(r);if(d===62){r++;break}if(d===47){if(t.charCodeAt(r+1)!==62)throw new Error("Malformed self-close");c=true,r+=2;break}if(zt.has(d)){r++;continue}let f=t.indexOf("=",r);if(f<0)throw new Error("Malformed attribute");let h=t.slice(r,f).trim(),p=f+1;for(;p<s&&zt.has(t.charCodeAt(p));)p++;let _=t.charCodeAt(p);if(_!==34&&_!==39)throw new Error("Unquoted attribute value");let g=t.indexOf(String.fromCharCode(_),p+1);if(g<0)throw new Error("Unterminated attribute value");u.attrs.push([h,ns(t.slice(p+1,g))]),r=g+1;}c||(n=u);}if(n!==e)throw new Error("Unclosed element at end of document");if(!e.documentElement)throw new Error("Empty XML document");return e}y(rs,"parseFastXml");function is(t){return /[&<>\r]/.test(t)?t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\r/g,"&#13;"):t}y(is,"escText");function ss(t){return /[&<>"\t\n\r]/.test(t)?t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/\t/g,"&#9;").replace(/\n/g,"&#10;").replace(/\r/g,"&#13;"):t}y(ss,"escAttr");function bt(t){let e=[],n=y(r=>{switch(r.nodeType){case Me:{let s=r;e.push("<",s.tagName);for(let i=0;i<s.attrs.length;i++){let[o,l]=s.attrs[i];e.push(" ",o,'="',ss(l),'"');}if(s.childNodes.length===0)e.push("/>");else {e.push(">");for(let i of s.childNodes)n(i);e.push("</",s.tagName,">");}break}case tn:e.push(is(r.data));break;case nn:e.push("<![CDATA[",r.data,"]]>");break;case lr:e.push("<!--",r.data,"-->");break;case rn:for(let s of r.childNodes)n(s);break}},"write");return n(t),e.join("")}y(bt,"serializeFastXml");function M(t,e){for(let n=0;n<t.childNodes.length;n++){let r=t.childNodes[n];if(r.nodeType===1&&r.tagName===e)return r}return null}y(M,"findChild");function wr(t,e){let n=[];for(let r=0;r<t.childNodes.length;r++){let s=t.childNodes[r];s.nodeType===1&&s.tagName===e&&n.push(s);}return n}y(wr,"findChildren");function I(t,e){return Array.from(t.getElementsByTagName(e))}y(I,"findAllDescendants");function qe(t){return t.startsWith("\uFEFF")&&(t=t.slice(1)),rs(t)}y(qe,"parseXml");function zn(t){let e=bt(t),r=/<([a-zA-Z0-9_:]+)(\s+[^>]+?)(>|\/>)/.exec(e);if(r&&!r[1].startsWith("?")){let s=r.index,i=e.substring(0,s);if(!i.includes("<")||i.trim().startsWith("<?xml")&&(i.match(/</g)||[]).length===1){let l=r[0],a=`<${r[1]}`,u=r[2],c=r[3],d=/([a-zA-Z0-9_:]+)\s*=\s*(["'])(.*?)\2/g,f=[],h;for(;(h=d.exec(u))!==null;)f.push(h[0].trim());f.sort((_,g)=>{let w=_.split("=")[0].trim(),k=g.split("=")[0].trim(),b=w.startsWith("xmlns"),m=k.startsWith("xmlns");return b&&!m?-1:!b&&m?1:w<k?-1:w>k?1:0});let p=f.length>0?`${a} ${f.join(" ")}${c}`:`${a}${c}`;e=e.substring(0,s)+p+e.substring(s+l.length);}}return e}y(zn,"serializeXml");var Qt="__adeu_wp_index_cache",yr="__adeu_clean_inc";function xt(t){return typeof t._inc=="number"?t._inc:null}y(xt,"docInc");function tt(t){let e=xt(t);e!==null&&(t[yr]=e);}y(tt,"markPartClean");function sn(t){let e=xt(t);return e!==null&&t[yr]===e}y(sn,"isPartClean");function os(t){let e=new Map,n=t.documentElement;if(!n)return e;let r=0;n.nodeType===1&&n.tagName==="w:p"&&e.set(n,r++);let s=[n],i=[0];for(;s.length;){let o=s.length-1,l=s[o].childNodes;if(!l||i[o]>=l.length){s.pop(),i.pop();continue}let a=l[i[o]++];a.nodeType===1&&(a.tagName==="w:p"&&e.set(a,r++),s.push(a),i.push(0));}return e}y(os,"buildWpIndexMap");function as(t,e){let n=xt(t),r=t[Qt];(!r||n===null||r.inc!==n||!r.map.has(e))&&(r={inc:n??NaN,map:os(t)},t[Qt]=r);let s=r.map.get(e);return s===void 0?-1:s}y(as,"wpDocumentOrderIndex");function ls(t){let e=t[Qt],n=xt(t);e&&n!==null&&(e.inc=n);}y(ls,"resyncAfterOwnAttributeMutation");function vr(t,e){let n=t.getElementsByTagName("w:p")[0],r=n?n.getAttribute("w14:paraId"):null;if(!r&&e){let s=t.ownerDocument,i=sn(s);n||(n=s.createElement("w:p"),t.appendChild(n));let o=as(s,n),l=2166136261,a=`fallback-paraId-${o}`;for(let u=0;u<a.length;u++)l^=a.charCodeAt(u),l+=(l<<1)+(l<<4)+(l<<7)+(l<<8)+(l<<24);r=(l>>>0).toString(16).toUpperCase().padStart(8,"0"),n.setAttribute("w14:paraId",r),ls(s),i&&tt(s);}return {paraId:r,firstP:n}}y(vr,"resolve_cell_anchor");var mt=class{static{y(this,"Relationship");}constructor(t,e,n,r){this.id=t,this.type=e,this.target=n,this.isExternal=r;}id;type;target;isExternal},br=class{static{y(this,"Part");}constructor(t,e,n,r){this.partname=t,this.blob=e,this.contentType=r,this._element=n;}partname;blob;contentType;rels=new Map;_element;package;addRelationship(t,e,n,r=false){if(this.rels.set(t,new mt(t,e,n,r)),this.partname.endsWith(".rels")){let s=this._element.ownerDocument;if(s){let i=s.createElementNS("http://schemas.openxmlformats.org/package/2006/relationships","Relationship");i.setAttribute("Id",t),i.setAttribute("Type",e),i.setAttribute("Target",n),r&&i.setAttribute("TargetMode","External"),this._element.appendChild(i);}}}},cs=class{static{y(this,"DocxPackage");}constructor(t){this.unzipped=t;}unzipped;parts=[];mainDocumentPart;getPartByPath(t){let e=t.startsWith("/")?t.substring(1):t;return this.parts.find(n=>n.partname===e||n.partname==="/"+e)}nextPartname(t){let e=1;for(;;){let n=t.replace("%d",e===1?"":e.toString());if(!this.getPartByPath(n))return n;e++;}}addPart(t,e,n){let r=qe(n),s=new br(t,n,r.documentElement,e);s.package=this,this.parts.push(s);let i=this.getPartByPath("[Content_Types].xml");if(i){let o=i._element.ownerDocument;if(o){let l=o.createElement("Override");l.setAttribute("PartName",t),l.setAttribute("ContentType",e),i._element.appendChild(l);}}return s}getOrCreateRelsPart(t){let e=t.split("/"),n=e.pop(),r=e.join("/")+"/_rels/"+n+".rels",s=this.getPartByPath(r);return s||(s=this.addPart(r,"application/vnd.openxmlformats-package.relationships+xml",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
13
- <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>`)),s}},pe=class xr{static{y(this,"_DocumentObject");}constructor(e,n){this.pkg=e,this.part=n;}pkg;part;settings={oddAndEvenPagesHeaderFooter:false};sections=[];get element(){return M(this.part._element,"w:body")||this.part._element}static async load(e,n){let r=e instanceof Uint8Array?e:new Uint8Array(e),s=Be(r),i=new cs(s),o=s["[Content_Types].xml"],l={};if(o){let p=qe(Oe(o)),_=I(p.documentElement,"Override");for(let g of _)l[g.getAttribute("PartName")||""]=g.getAttribute("ContentType")||"";}let a=n?.onPart,u=Math.max(1,n?.partTickEvery??200),c=0;if(a)for(let p of Object.keys(s))(p.endsWith(".xml")||p.endsWith(".rels"))&&c++;let d=0;for(let[p,_]of Object.entries(s))if(p.endsWith(".xml")||p.endsWith(".rels")){let g=Oe(_),w=qe(g);tt(w);let k=l["/"+p]||"application/xml",b=new br("/"+p,g,w.documentElement,k);b.package=i,i.parts.push(b),d++,a&&d%u===0&&await a(d,c);}a&&c>0&&await a(c,c);let f=i.getPartByPath("word/document.xml");if(!f)throw new Error("Invalid DOCX: Missing word/document.xml");i.mainDocumentPart=f;let h=i.getPartByPath("word/_rels/document.xml.rels");if(h){let p=I(h._element,"Relationship");for(let _ of p){let g=_.getAttribute("Id"),w=_.getAttribute("Target"),k=_.getAttribute("Type"),b=_.getAttribute("TargetMode");g&&w&&k&&f.rels.set(g,new mt(g,k,w,b==="External"));}}return new xr(i,f)}relateTo(e,n){let r=1;for(;this.part.rels.has(`rId${r}`);)r++;let s=`rId${r}`,i=e.partname.split("/").pop();this.part.rels.set(s,new mt(s,n,i,false)),this.pkg.getOrCreateRelsPart(this.part.partname).addRelationship(s,n,i,false);}relateToExternal(e,n){let r=1;for(;this.part.rels.has(`rId${r}`);)r++;let s=`rId${r}`;return this.part.rels.set(s,new mt(s,n,e,true)),this.pkg.getOrCreateRelsPart(this.part.partname).addRelationship(s,n,e,true),s}async save(){for(let e of this.pkg.parts){let n=zn(e._element.ownerDocument||e._element);n.includes("w16du:")&&!n.includes("xmlns:w16du=")&&(e._element.setAttribute("xmlns:w16du","http://schemas.microsoft.com/office/word/2023/wordml/word16du"),n=zn(e._element.ownerDocument||e._element)),n.startsWith("<?xml")||(n=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
14
- `+n),this.pkg.unzipped[e.partname.substring(1)]=ut(n),e.blob=n;let r=e._element.ownerDocument;r&&tt(r);}return Buffer.from(Bn(this.pkg.unzipped))}},re=class{static{y(this,"Paragraph");}constructor(t,e){this._element=t,this._parent=e;}_element;_parent;get text(){let t="",e=this._element.getElementsByTagName("w:t");for(let n=0;n<e.length;n++)t+=e[n].textContent||"";return t}},Ae=class{static{y(this,"Run");}constructor(t,e){this._element=t,this._parent=e;}_element;_parent},us=class{static{y(this,"Cell");}constructor(t,e){this._element=t,this._parent=e;}_element;_parent},ds=class{static{y(this,"Row");}constructor(t,e){this._element=t,this._parent=e;let n=this._element.getElementsByTagName("w:tc");for(let r=0;r<n.length;r++)this.cells.push(new us(n[r],this));}_element;_parent;cells=[]},Te=class{static{y(this,"Table");}constructor(t,e){this._element=t,this._parent=e;let n=this._element.getElementsByTagName("w:tr");for(let r=0;r<n.length;r++)this.rows.push(new ds(n[r],this));}_element;_parent;rows=[]},Ln=class{static{y(this,"NotesPart");}constructor(t,e){this.part=t,this.note_type=e,this._element=t._element;}part;note_type;_element},fs=class{static{y(this,"FootnoteItem");}constructor(t,e,n){this._element=t,this._parent=e,this.note_type=n,this.id=t.getAttribute("w:id")||"",this.part=e.part;}_element;_parent;note_type;id;part},ne={w:"http://schemas.openxmlformats.org/wordprocessingml/2006/main",w14:"http://schemas.microsoft.com/office/word/2010/wordml",w15:"http://schemas.microsoft.com/office/word/2012/wordml",w16cid:"http://schemas.microsoft.com/office/word/2016/wordml/cid",w16cex:"http://schemas.microsoft.com/office/word/2018/wordml/cex",mc:"http://schemas.openxmlformats.org/markup-compatibility/2006"},se={COMMENTS:"application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",EXTENDED:"application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",IDS:"application/vnd.openxmlformats-officedocument.wordprocessingml.commentsIds+xml",EXTENSIBLE:"application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml"},xe={COMMENTS:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",EXTENDED:"http://schemas.microsoft.com/office/2011/relationships/commentsExtended",IDS:"http://schemas.microsoft.com/office/2016/09/relationships/commentsIds",EXTENSIBLE:"http://schemas.microsoft.com/office/2018/08/relationships/commentsExtensible"},nt=class{static{y(this,"CommentsManager");}constructor(t){this.doc=t;}doc;_commentsPart=null;_extendedPart=null;_idsPart=null;_extensiblePart=null;_nextId=null;get commentsPart(){return this._commentsPart||(this._commentsPart=this._getOrCreateCommentsPart(),this._ensureNamespaces()),this._commentsPart}get extendedPart(){return this._extendedPart||(this._extendedPart=this._getOrCreateExtendedPart()),this._extendedPart}get idsPart(){return this._idsPart||(this._idsPart=this._getOrCreateIdsPart()),this._idsPart}get extensiblePart(){return this._extensiblePart||(this._extensiblePart=this._getOrCreateExtensiblePart()),this._extensiblePart}get nextId(){return this._nextId===null&&(this._nextId=this._getNextCommentId()),this._nextId}set nextId(t){this._nextId=t;}_getExistingPartByType(t){return this.doc.pkg.parts.find(e=>e.contentType===t)||null}_linkPart(t,e){for(let n of this.doc.part.rels.values())if(!n.isExternal&&n.target===t.partname.split("/").pop())return t;return this.doc.relateTo(t,e),t}_getOrCreateCommentsPart(){let t=this._getExistingPartByType(se.COMMENTS);if(t)return this._linkPart(t,xe.COMMENTS);let e=this.doc.pkg.nextPartname("/word/comments%d.xml"),n=`<w:comments xmlns:w="${ne.w}" xmlns:w14="${ne.w14}" xmlns:w15="${ne.w15}" xmlns:w16cid="${ne.w16cid}" xmlns:w16cex="${ne.w16cex}" xmlns:mc="${ne.mc}" mc:Ignorable="w14 w15 w16cid w16cex"></w:comments>`;return t=this.doc.pkg.addPart(e,se.COMMENTS,n),this.doc.relateTo(t,xe.COMMENTS),t}_getOrCreateExtendedPart(){let t=this._getExistingPartByType(se.EXTENDED);if(t)return this._linkPart(t,xe.EXTENDED);let e=this.doc.pkg.nextPartname("/word/commentsExtended%d.xml"),n=`<w15:commentsEx xmlns:w15="${ne.w15}"></w15:commentsEx>`;return t=this.doc.pkg.addPart(e,se.EXTENDED,n),this.doc.relateTo(t,xe.EXTENDED),t}_getOrCreateIdsPart(){let t=this._getExistingPartByType(se.IDS);if(t)return this._linkPart(t,xe.IDS);let e=this.doc.pkg.nextPartname("/word/commentsIds%d.xml"),n=`<w16cid:commentsIds xmlns:w16cid="${ne.w16cid}"></w16cid:commentsIds>`;return t=this.doc.pkg.addPart(e,se.IDS,n),this.doc.relateTo(t,xe.IDS),t}_getOrCreateExtensiblePart(){let t=this._getExistingPartByType(se.EXTENSIBLE);if(t)return this._linkPart(t,xe.EXTENSIBLE);let e=this.doc.pkg.nextPartname("/word/commentsExtensible%d.xml"),n=`<w16cex:commentsExtensible xmlns:w16cex="${ne.w16cex}"></w16cex:commentsExtensible>`;return t=this.doc.pkg.addPart(e,se.EXTENSIBLE,n),this.doc.relateTo(t,xe.EXTENSIBLE),t}_ensureNamespaces(){let t=this._commentsPart?._element;if(!t)return;let e=[["xmlns:w",ne.w],["xmlns:w14",ne.w14],["xmlns:w15",ne.w15],["xmlns:w16cid",ne.w16cid],["xmlns:w16cex",ne.w16cex],["xmlns:mc",ne.mc]];for(let[n,r]of e)t.getAttribute(n)||t.setAttribute(n,r);}_getNextCommentId(){let t=[0],e=this._getExistingPartByType(se.COMMENTS);if(e){let n=I(e._element,"w:comment");for(let r of n){let s=r.getAttribute("w:id");s&&t.push(parseInt(s,10)||0);}}return Math.max(...t)+1}_generateHexId(){return Math.floor(Math.random()*4294967295).toString(16).toUpperCase().padStart(8,"0")}_getInitials(t){return t?t.split(" ").filter(Boolean).map(e=>e[0]).join("").toUpperCase():""}_findParaIdForComment(t){if(!this._commentsPart)return null;for(let e of I(this._commentsPart._element,"w:comment"))if(e.getAttribute("w:id")===t)for(let n of I(e,"w:p")){let r=n.getAttribute("w14:paraId");if(r)return r}return null}_findThreadRootParaId(t){let e=this._findParaIdForComment(t),n=this._getExistingPartByType(se.EXTENDED);if(!e||!n)return e;for(let r=0;r<n._element.childNodes.length;r++){let s=n._element.childNodes[r];if(s.nodeType===1&&s.getAttribute("w15:paraId")===e){let i=s.getAttribute("w15:paraIdParent");if(i)return i}}return e}addComment(t,e,n=null){let r=this.nextId.toString();this.nextId++;let s=new Date().toISOString().replace(/\.\d{3}Z$/,"Z"),i=this.commentsPart._element.ownerDocument,o=i.createElement("w:comment");o.setAttribute("w:id",r),o.setAttribute("w:author",t),o.setAttribute("w:date",s);let l=this._getInitials(t);l&&o.setAttribute("w:initials",l);let a=this._getExistingPartByType(se.EXTENDED);n&&!a&&o.setAttribute("w15:p",n);let u=this._generateHexId(),c=this._generateHexId(),d=i.createElement("w:p");d.setAttribute("w14:paraId",u),d.setAttribute("w14:textId","77777777"),d.setAttribute("w:rsidR",c),d.setAttribute("w:rsidRDefault",c),d.setAttribute("w:rsidP",c);let f=i.createElement("w:pPr"),h=i.createElement("w:pStyle");h.setAttribute("w:val","CommentText"),f.appendChild(h),d.appendChild(f);let p=i.createElement("w:r"),_=i.createElement("w:rPr"),g=i.createElement("w:rStyle");g.setAttribute("w:val","CommentReference"),_.appendChild(g),p.appendChild(_),p.appendChild(i.createElement("w:annotationRef")),d.appendChild(p);let w=i.createElement("w:r"),k=i.createElement("w:t");if(k.textContent=e,w.appendChild(k),d.appendChild(w),o.appendChild(d),this.commentsPart._element.appendChild(o),this.extendedPart){let b=n?this._findThreadRootParaId(n):null,v=this.extendedPart._element.ownerDocument.createElement("w15:commentEx");v.setAttribute("w15:paraId",u),b&&v.setAttribute("w15:paraIdParent",b),v.setAttribute("w15:done","0"),this.extendedPart._element.appendChild(v);}if(this.idsPart){let m=this.idsPart._element.ownerDocument.createElement("w16cid:commentId");m.setAttribute("w16cid:paraId",u),m.setAttribute("w16cid:durableId",this._generateHexId()),this.idsPart._element.appendChild(m);}if(this.extensiblePart){let b=null;for(let m=0;m<this.idsPart._element.childNodes.length;m++){let v=this.idsPart._element.childNodes[m];if(v.nodeType===1&&v.getAttribute("w16cid:paraId")===u){b=v.getAttribute("w16cid:durableId");break}}if(b){let v=this.extensiblePart._element.ownerDocument.createElement("w16cex:commentExtensible");v.setAttribute("w16cex:durableId",b),v.setAttribute("w16cex:dateUtc",s),this.extensiblePart._element.appendChild(v);}}return r}deleteComment(t){if(!this.commentsPart)return;let e=null;for(let r of I(this.commentsPart._element,"w:comment"))if(r.getAttribute("w:id")===t){e=r;break}if(!e)return;let n=null;for(let r of I(e,"w:p")){let s=r.getAttribute("w14:paraId");if(s){n=s;break}}if(n){let r=[];if(this.extendedPart)for(let i=0;i<this.extendedPart._element.childNodes.length;i++){let o=this.extendedPart._element.childNodes[i];if(o.nodeType===1&&o.getAttribute("w15:paraIdParent")===n){let l=o.getAttribute("w15:paraId");if(l){for(let a of I(this.commentsPart._element,"w:comment"))for(let u of I(a,"w:p"))if(u.getAttribute("w14:paraId")===l){let c=a.getAttribute("w:id");c&&r.push(c);break}}}}for(let i of r)this.deleteComment(i);let s=null;if(this.idsPart){let i=[];for(let o=0;o<this.idsPart._element.childNodes.length;o++){let l=this.idsPart._element.childNodes[o];l.nodeType===1&&l.getAttribute("w16cid:paraId")===n&&(s=l.getAttribute("w16cid:durableId"),i.push(l));}i.forEach(o=>this.idsPart._element.removeChild(o));}if(this.extendedPart){let i=[];for(let o=0;o<this.extendedPart._element.childNodes.length;o++){let l=this.extendedPart._element.childNodes[o];l.nodeType===1&&l.getAttribute("w15:paraId")===n&&i.push(l);}i.forEach(o=>this.extendedPart._element.removeChild(o));}if(s&&this.extensiblePart){let i=[];for(let o=0;o<this.extensiblePart._element.childNodes.length;o++){let l=this.extensiblePart._element.childNodes[o];l.nodeType===1&&l.getAttribute("w16cex:durableId")===s&&i.push(l);}i.forEach(o=>this.extensiblePart._element.removeChild(o));}}e.parentNode&&e.parentNode.removeChild(e);}};function Xe(t){({part:t.mainDocumentPart,relateTo:y(()=>{},"relateTo")});let r={},s=t.parts.find(a=>a.contentType===se.COMMENTS);if(!s)return r;let i={},o=I(s._element,"w:comment");for(let a of o){let u=a.getAttribute("w:id");if(!u)continue;let c=a.getAttribute("w:author")||"Unknown",d=a.getAttribute("w:date")||"",f=false,h=a.getAttribute("w15:done");(h==="1"||h==="true"||h==="on")&&(f=true);let p=a.getAttribute("w15:p")||null,_=I(a,"w:p");for(let k of _){let b=k.getAttribute("w14:paraId");b&&(i[b]=u);}let g=[];for(let k of _){let b=I(k,"w:t");for(let m of b)m.textContent&&g.push(m.textContent);g.push(`
15
- `);}let w=g.join("").trim();r[u]={author:c,text:w,date:d,resolved:f,parent_id:p};}let l=t.parts.find(a=>a.contentType===se.EXTENDED);if(l){let a=l._element.childNodes;for(let u=0;u<a.length;u++){let c=a[u];if(c.nodeType!==1)continue;let d=c.getAttribute("w15:paraId"),f=c.getAttribute("w15:paraIdParent"),h=c.getAttribute("w15:done");if(d){let p=i[d];if(p&&r[p]){if(f){let _=i[f];_&&(r[p].parent_id=_);}(h==="1"||h==="true"||h==="on")&&(r[p].resolved=true);}}}}return r}y(Xe,"extract_comments_data");var Lt=500,ze=200,hs=["{++","++}","{--","--}","{==","==}","{>>","<<}"];function Nr(t){if(!t||!t.includes("{")&&!t.includes("}"))return t;for(let e of hs)if(t.includes(e)){let n=e.startsWith("{")?"{ "+e.slice(1):e.slice(0,-1)+" }";t=t.split(e).join(n);}return t}y(Nr,"escape_critic_tokens");function he(t,e){if(t==null||t.length<=e)return t;let n=Math.max(1,Math.floor(e*2/3)),r=Math.max(1,e-n),s=t.length-n-r;return `${t.slice(0,n)}\u2026 [${s.toLocaleString("en-US")} chars omitted] \u2026${t.slice(-r)}`}y(he,"truncate_middle");var on=2e3,Ce=class extends Error{static{y(this,"RegexTimeoutError");}pattern;constructor(t){super(`Regular expression exceeded the ${on/1e3}s matching time budget (catastrophic backtracking). Simplify the pattern \u2014 nested quantifiers like (a+)+ are the usual cause \u2014 or use a literal target instead.`),this.name="RegexTimeoutError",this.pattern=t;}};function kr(t){let e=false,n=false,r=[];for(let s=0;s<t.length;s++){let i=t[s];if(n){n=false;continue}if(i==="\\"){n=true;continue}if(e){i==="]"&&(e=false);continue}if(i==="["){e=true;continue}if(i==="("){r.push({hasInnerQuantifierOrPipe:false});continue}if(i===")"){if(r.length>0){let o=r.pop(),l=t.substring(s+1),a=l.match(/^(\*|\+|\{\d+\,\s*\}|\?)/),u=a?a[1]:"",c=u==="*"||u==="+"||/^\{\d+\,\s*\}/.test(l);if(c&&o.hasInnerQuantifierOrPipe)return true;r.length>0&&(o.hasInnerQuantifierOrPipe||c)&&(r[r.length-1].hasInnerQuantifierOrPipe=true);}continue}r.length>0&&(i==="|"||i==="*"||i==="+"||/^\{\d+\,\s*\}/.test(t.substring(s)))&&(r[r.length-1].hasInnerQuantifierOrPipe=true);}return false}y(kr,"hasCatastrophicBacktrackingRisk");function ps(t,e,n=""){if(kr(t))throw new Ce(t);let r=n.includes("g")?n:n+"g",s=new RegExp(t,r),i=Date.now(),o=[],l;for(;(l=s.exec(e))!==null;){if(Date.now()-i>on)throw new Ce(t);o.push({start:l.index,end:l.index+l[0].length}),l.index===s.lastIndex&&s.lastIndex++;}return o}y(ps,"userFindAllMatches");function _s(t,e,n=""){if(kr(t))throw new Ce(t);let r=new RegExp(t,n.replace("g","")),s=Date.now(),i=r.exec(e);if(Date.now()-s>on)throw new Ce(t);return i?{start:i.index,end:i.index+i[0].length}:null}y(_s,"userSearch");var ms="w:p",Er="w:r",an="w:t",gs="w:delText",ws="w:tab",ys="w:br",vs="w:cr",ln="w:rPr",bs="w:rPrChange",xs="w:commentReference",Ns="w:footnoteReference",ks="w:endnoteReference",Es="w:fldChar",As="w:fldCharType",Cs="w:instrText",Ps="w:ins",Ts="w:del",Ne="w:id",Ut="w:author",qt="w:date",Ss="w:commentRangeStart",Is="w:commentRangeEnd",$s="w:hyperlink",Os="r:id",Ds="w:fldSimple",Ms="w:instr",Rs="w:bookmarkStart",js="w:name",Ar="w:sdt",Fs="w:smartTag",Cr="w:sdtContent",Pr="w:b",Bs="w:i",ae="w:val",Tr="w:pPr",Sr="w:pStyle",Ir="w:outlineLvl",Ws="w:numPr",zs="w:numId",Ls="w:ilvl",Yt="w:drawing",Gt="w:object",Vt="w:pict",Us="wp:docPr",qs="v:imagedata",Js="o:title",Hs="w:txbxContent",Xs="mc:AlternateContent",Qs="mc:Choice",Ys="mc:Fallback",Un=300;function qn(t){let e=[];for(let r of I(t,Hs))for(let s of I(r,an))s.textContent&&e.push(s.textContent);let n=e.join(" ").split(/\s+/).filter(Boolean).join(" ");return n.length>Un&&(n=n.slice(0,Un).trimEnd()+"\u2026"),n}y(qn,"_textbox_text");function*Jn(t){let e=t.tagName;if(e===Yt||e===Gt){let n=I(t,Us)[0]||null,r="",s="0";n&&(r=n.getAttribute("descr")||n.getAttribute("title")||"",s=n.getAttribute("id")||"0");let i=qn(t);i&&(r=r?`Text box (${r}): ${i}`:`Text box: ${i}`),yield {type:"image",id:s,date:r};}else if(e===Vt){let n=I(t,qs)[0]||null,r=n&&n.getAttribute(Js)||"",s=qn(t);s&&(r=r?`Text box (${r}): ${s}`:`Text box: ${s}`),(s||n)&&(yield {type:"image",id:"vml",date:r});}}y(Jn,"_graphic_marker_events");var Gs=/Heading[ ]?([1-6])(?![0-9])/;function Vs(t){let e=t,n=new Set;for(;e&&!n.has(e);){if(n.add(e),e.package)return e.package;if(e.pkg)return e.pkg;if(e.part&&(e.part.package||e.part.pkg))return e.part.package||e.part.pkg;e=e._parent||e.part||null;}return null}y(Vs,"_resolve_package");function st(t){let e=t.package||t.pkg||(t.part?t.part.pkg:null);if(e&&e._adeu_style_cache)return e._adeu_style_cache;let n={},r=null,s={},i=e?.getPartByPath("word/styles.xml");if(!i){let u=[n,null];return e&&(e._adeu_style_cache=u),u}let o=I(i._element,"w:style");for(let u of o){let c=u.getAttribute("w:styleId");if(!c)continue;let d=u.getAttribute("w:type"),f=u.getAttribute("w:default")==="1"||u.getAttribute("w:default")==="true";d==="paragraph"&&f&&(r=c);let h=M(u,"w:name"),p=h?h.getAttribute("w:val"):c;p&&typeof p=="string"&&(p.toLowerCase().startsWith("heading")?p=p.replace(/^heading/i,"Heading"):p.toLowerCase()==="title"&&(p="Title"));let _=M(u,"w:basedOn"),g=_?_.getAttribute("w:val"):null,w=null,k=null,b=null,m=M(u,"w:pPr");if(m){let A=M(m,"w:outlineLvl");if(A){let x=A.getAttribute("w:val");x&&/^\d+$/.test(x)&&(w=parseInt(x,10));}let C=M(m,"w:numPr");if(C){let x=M(C,"w:numId");if(x){let T=x.getAttribute("w:val");T&&T!=="0"&&(k=T);}let E=M(C,"w:ilvl");if(E){let T=E.getAttribute("w:val");T&&/^\d+$/.test(T)&&(b=parseInt(T,10));}}}let v=null,N=M(u,"w:rPr");if(N){let A=M(N,"w:b");if(A){let C=A.getAttribute("w:val");v=C!=="0"&&C!=="false"&&C!=="off";}}s[c]={name:p,based_on:g,outline_level:w,bold:v,num_id:k,num_ilvl:b};}let l=y((u,c)=>{if(n[u])return n[u];if(c.has(u)||!s[u])return {name:u,outline_level:null,bold:false,num_id:null,num_ilvl:null};c.add(u);let d=s[u],f=d.based_on,h=d.outline_level,p=d.bold!==null?d.bold:false,_=d.num_id,g=d.num_ilvl;if(f){let k=l(f,c);h===null&&(h=k.outline_level),d.bold===null&&(p=k.bold),_===null&&(_=k.num_id??null),g===null&&(g=k.num_ilvl??null);}let w={name:d.name,outline_level:h,bold:p,num_id:_,num_ilvl:g};return n[u]=w,w},"resolve_style");for(let u in s)l(u,new Set);let a=[n,r];return e&&(e._adeu_style_cache=a),a}y(st,"_get_style_cache");function Zs(t){let e=Vs(t);if(!e)return {};if(e._adeu_numbering_cache)return e._adeu_numbering_cache;let n={},r=null;try{let s=(e.parts||[]).find(i=>String(i.partname).endsWith("/numbering.xml"));s&&(r=s._element);}catch{r=null;}if(r){let s={};for(let i of I(r,"w:abstractNum")){let o=i.getAttribute("w:abstractNumId");if(o===null)continue;let l={};for(let a of I(i,"w:lvl")){let u=a.getAttribute("w:ilvl"),c=M(a,"w:numFmt");if(u!==null&&/^-?\d+$/.test(u)&&c){let d=c.getAttribute("w:val");d&&(l[parseInt(u,10)]=d);}}s[o]=l;}for(let i of I(r,"w:num")){let o=i.getAttribute("w:numId"),l=M(i,"w:abstractNumId");if(o===null||!l)continue;let a=l.getAttribute("w:val");a!==null&&s[a]!==void 0&&(n[o]=s[a]);}}return e._adeu_numbering_cache=n,n}y(Zs,"_get_numbering_cache");function Ks(t,e,n){let r=null;if(e!=null){let s=Zs(t)[e];if(s&&Object.keys(s).length>0&&(r=s[n]!==void 0?s[n]:null,r===null)){for(let i=n;i>=0;i--)if(s[i]!==void 0){r=s[i];break}}}return r!==null&&r!=="bullet"?"1. ":"* "}y(Ks,"get_list_marker");function $r(t){if(!t)return null;let e=t.match(Gs);return e?parseInt(e[1],10):null}y($r,"_detect_heading_level_from_name");function cn(t,e,n){e||([e,n]=st(t._parent.part||t._parent));let r=M(t._element,Tr);if(r){let l=M(r,Ir);if(l){let a=l.getAttribute(ae);if(a&&/^\d+$/.test(a)){let u=parseInt(a,10);if(u>=0&&u<=8)return true}}}let s=n;if(r){let l=M(r,Sr);l&&(s=l.getAttribute(ae)||n);}let i=s&&e?e[s]:null;if(i&&i.outline_level!==null&&i.outline_level>=0&&i.outline_level<=8)return true;let o=i?i.name:s;return o&&typeof o=="string"&&o.toLowerCase().startsWith("heading")&&(o=o.replace(/^heading/i,"Heading")),!!(o?.startsWith("Heading")||o==="Title"||o&&o!=="Normal"&&$r(o)!==null)}y(cn,"is_native_heading");function Se(t,e,n){e||([e,n]=st(t._parent.part||t._parent));let r=M(t._element,Tr);if(r){let c=M(r,Ir);if(c){let d=c.getAttribute(ae);if(d&&/^\d+$/.test(d)){let f=parseInt(d,10);if(f>=0&&f<=8)return "#".repeat(f+1)+" "}}}let s=n;if(r){let c=M(r,Sr);c&&(s=c.getAttribute(ae)||n);}let i=s&&e?e[s]:null;if(i&&i.outline_level!==null&&i.outline_level>=0&&i.outline_level<=8)return "#".repeat(i.outline_level+1)+" ";let o=i?i.name:s;if(o&&typeof o=="string"&&o.toLowerCase().startsWith("heading")&&(o=o.replace(/^heading/i,"Heading")),o?.startsWith("Heading")){let c=o.replace("Heading","").trim();if(/^\d+$/.test(c))return "#".repeat(parseInt(c,10))+" "}if(o==="Title")return "# ";let l=null,a=null,u=false;if(r){let c=M(r,Ws);if(c){let d=M(c,zs);if(d){let f=d.getAttribute(ae);if(f==="0")u=true;else if(f){l=f;let h=M(c,Ls);if(h){let p=h.getAttribute(ae);p!==null&&/^\d+$/.test(p)&&(a=parseInt(p,10));}}}}}if(l===null&&!u&&i){let c=i.num_id;c&&(l=c,a===null&&(a=i.num_ilvl!==void 0?i.num_ilvl:null));}if(l!==null){let c=a!==null?a:0,d=Ks(t._parent?t._parent.part||t._parent:null,l,c);return " ".repeat(c)+d}if(o&&o!=="Normal"){let c=$r(o);if(c!==null)return "#".repeat(c)+" "}if(!o||o==="Normal"){let c=false,d=t._element;for(;d;){if(d.tagName==="w:tc"){c=true;break}d=d.parentNode;}if(c)return "";let f=t.text.trim();if(f&&f.length<100&&f===f.toUpperCase()){let h=false;if(i?.bold)h=true;else {let p=I(t._element,Er);for(let _ of p)if(I(_,an).map(k=>k.textContent||"").join("").trim()){let k=M(_,ln);if(k){let b=M(k,Pr);b&&b.getAttribute(ae)!=="0"&&b.getAttribute(ae)!=="false"&&(h=true);}break}}if(h)return "## "}}return ""}y(Se,"get_paragraph_prefix");function Or(t,e,n){let r=Se(t,e,n);if(!r)return false;let s=r.trimEnd();return s.length>0&&s==="#".repeat(s.length)}y(Or,"is_heading_paragraph");function Dr(t,e=null){let n="",r="",s=M(t._element,ln),i=false,o=false;if(s){let l=M(s,Pr);l&&l.getAttribute(ae)!=="0"&&l.getAttribute(ae)!=="false"&&(i=true);let a=M(s,Bs);a&&a.getAttribute(ae)!=="0"&&a.getAttribute(ae)!=="false"&&(o=true);}if(e===null){let l=t._parent;e=l instanceof re?cn(l):false;}return i&&!e&&(n+="**",r="**"+r),o&&(n+="_",r="_"+r),[n,r]}y(Dr,"get_run_style_markers");function Mr(t){let e=t.trim();if(!e)return ["","",t];let n=t.length-t.trimStart().length;return [t.substring(0,n),t.substring(n,n+e.length),t.substring(n+e.length)]}y(Mr,"split_boundary_whitespace");function Rr(t){let e=[],n=[],r=new Set;for(let[i,o]of t){let l=Object.entries(i),a=Object.entries(o);if(l.length===0&&a.length===0){n.length>0&&(e.push(n),n=[]);continue}let u=[];for(let[c,d]of l)r.has(c)||u.push([c,d&&d.author||"Unknown"]);for(let[c,d]of a)r.has(c)||u.push([c,d&&d.author||"Unknown"]);for(let[c,d]of u)r.add(c),n.length>0&&n[n.length-1][1]!==d&&(e.push(n),n=[]),n.push([c,d]);}n.length>0&&e.push(n);let s={};for(let i of e)if(!(i.length<2))for(let[o]of i)s[o]=i.filter(([l])=>l!==o).map(([l])=>`Chg:${l}`).join(", ");return s}y(Rr,"compute_change_pair_map");function eo(t,e,n){if(!e&&!n)return t;if(!t)return "";let r=y(i=>{let[o,l,a]=Mr(i);return l?`${o}${e}${l}${n}${a}`:i},"wrap");return t.includes(`
5
+ `;}return n.join("").replace(/%20/g," ")};ze.exports=O;ze.exports.diff_match_patch=O;ze.exports.DIFF_DELETE=H;ze.exports.DIFF_INSERT=Q;ze.exports.DIFF_EQUAL=z;});var $e="application/vnd.openxmlformats-officedocument.wordprocessingml.document";function yn(t,e){return e.split(".").reduce((n,r)=>{if(n&&typeof n=="object")return n[r]},t)}y(yn,"getNestedProperty");async function Si(t,e){let n=this.getInputData()[t];if(!n.binary||!n.binary[e])throw new n8nWorkflow.NodeOperationError(this.getNode(),`No binary data found on property "${e}"`,{description:"Verify that the upstream node produced binary data and that the property name matches.",itemIndex:t});let r=n.binary[e],s=await this.helpers.getBinaryDataBuffer(t,e),i=r.fileName??"document.docx";return {buffer:s,fileName:i}}y(Si,"getDocxBuffer");async function le(t,e){if(e.mode==="fromInput")return Si.call(this,t,e.binaryPropertyName);let{sourceNodeName:n,binaryPropertyName:r}=e,s="sourceBinaryId"in e?e.sourceBinaryId:void 0;if(s&&s.trim()!=="")try{let d=await this.helpers.getBinaryStream(s);return {buffer:await this.helpers.binaryToBuffer(d),fileName:"document.docx"}}catch(d){throw new n8nWorkflow.NodeApiError(this.getNode(),{message:d.message},{message:`Failed to load document from Binary ID '${s}'.`,description:`The binary with ID '${s}' could not be loaded. This usually means the binary has expired, been garbage-collected, or the ID is incorrect.`,itemIndex:t})}if(!n||n.trim()==="")throw new n8nWorkflow.NodeApiError(this.getNode(),{message:"Source Node Name is empty"},{message:"Source Node Name is required when Document Source is 'From Another Node'.",description:"Set 'Source Node Name' to the exact name of the node in this workflow whose output holds the .docx binary (e.g. the trigger node). Node names are case-sensitive and must match the node label in the canvas exactly.",itemIndex:t});let i=n.replace(/'/g,"\\'"),o=`{{ $('${i}').first().binary.${r} }}`,a;try{a=this.evaluateExpression(o,t);}catch(d){throw new n8nWorkflow.NodeApiError(this.getNode(),{message:d.message},{message:`Failed to resolve binary from source node '${n}'.`,description:`Could not evaluate '${o}'. Verify the source node name is exactly correct (case-sensitive, including spaces and punctuation). Underlying error: ${d.message}`,itemIndex:t})}if(a==null||typeof a!="object"){let d=`{{ $('${i}').first().json }}`,f;try{f=this.evaluateExpression(d,t);}catch{f=void 0;}if(f==null)throw new n8nWorkflow.NodeApiError(this.getNode(),{message:"Source node produced no output"},{message:`Source node '${n}' has no output.`,description:`The expression '${o}' resolved to undefined and the node appears not to have executed in this run. Verify that '${n}' is upstream of this Adeu node, that its name matches exactly (case-sensitive), and that it has run successfully.`,itemIndex:t});let h="";try{let _=this.evaluateExpression(`{{ Object.keys($('${i}').first().binary || {}) }}`,t);Array.isArray(_)&&_.length>0?h=` Available binary properties on '${n}': `+_.map(p=>`'${p}'`).join(", ")+".":Array.isArray(_)&&_.length===0&&(h=` Source node '${n}' has no binary properties at all.`);}catch{}throw new n8nWorkflow.NodeApiError(this.getNode(),{message:"Binary property not found"},{message:`Source node '${n}' has no binary on property '${r}'.`,description:`The expression '${o}' resolved to undefined.${h} Update 'Binary Property Name' to match an existing property, or change the source node so it outputs the .docx on the expected property.`,itemIndex:t})}let l=a,u;try{if(l.id){let d=await this.helpers.getBinaryStream(l.id);u=await this.helpers.binaryToBuffer(d);}else if(l.data)u=Buffer.from(l.data,"base64");else throw new Error("Resolved binary metadata has neither an 'id' nor 'data' field.")}catch(d){throw new n8nWorkflow.NodeApiError(this.getNode(),{message:d.message},{message:`Failed to read binary content from source node '${n}'.`,description:`The binary metadata was found on property '${r}', but its contents could not be loaded. Underlying error: ${d.message}`,itemIndex:t})}let c=l.fileName??"document.docx";return {buffer:u,fileName:c}}y(le,"getDocxBufferFromSource");function ct(t,e){let n=t.lastIndexOf(".");return `${n===-1?t:t.substring(0,n)}_${e}.docx`}y(ct,"buildOutputFileName");var Ii={strict:"strict",exact:"strict",single:"strict",first:"first","first-occurrence":"first","first-only":"first",all:"all",global:"all",bulk:"all",alloccurrences:"all","all-occurrences":"all",every:"all"};function $i(t){if(!(t===null||typeof t!="object"||Array.isArray(t))&&((!("type"in t)||t.type===void 0||t.type===null)&&("cells"in t?t.type="insert_row":"text"in t&&"target_id"in t?t.type="reply":"target_text"in t&&"new_text"in t&&(t.type="modify")),"match_mode"in t)){let e=t.match_mode;if(typeof e!="string")delete t.match_mode;else {let n=Ii[e.trim().toLowerCase()];n===void 0?delete t.match_mode:t.match_mode=n;}}}y($i,"coerceChangeItemInPlace");function vn(t){return t.map(e=>{let n=e;if(typeof e=="string")try{let r=JSON.parse(e);n=r!==null&&typeof r=="object"?r:e;}catch{n=e;}return n!==null&&typeof n=="object"&&!Array.isArray(n)&&$i(n),n})}y(vn,"coerceChangesArray");function bn(t,e,n){if(t==null||t==="")throw new n8nWorkflow.NodeOperationError(this.getNode(),`Parameter "${n}" is empty`,{description:`Provide a JSON value for "${n}".`,itemIndex:e});if(typeof t=="object")return t;let r=t.trim();r.startsWith("```")&&(r=r.replace(/^```[a-zA-Z]*\n?/,""),r=r.replace(/\n?```$/,"")),r=r.trim();try{return JSON.parse(r)}catch(s){throw new n8nWorkflow.NodeOperationError(this.getNode(),`Parameter "${n}" is not valid JSON`,{description:s.message,itemIndex:e})}}y(bn,"parseJsonParameter");function xn(t,e){let n=t.message??"Unknown error",r=t.name??"",s=t.errors,i=Array.isArray(s)?s.join(`
6
+ `):n,o=i.toLowerCase();if(r==="BatchValidationError"){let a="Batch validation failed.",l=`Review the listed failures:
7
+ `+i;return o.includes("target text not found")?(a="An edit could not be applied: target text not found.",l="Verify the exact `target_text` string \u2014 including punctuation and whitespace \u2014 against the document. Check the individual failures:\n"+i):o.includes("ambiguous match")?(a="An edit matched multiple locations in the document.",l="Provide more surrounding context in `target_text` to uniquely identify the location:\n"+i):o.includes("read-only")||o.includes("readonly")?(a="An edit targeted a read-only structural element.",l=`Cross-references, footnotes, hyperlinks, and the Structural Appendix cannot be modified via text replacement:
8
+ `+i):o.includes("comment range from another author")?(a="A match_mode='all' edit would sweep through another author's comment range.",l=`Bulk replacements are blocked from running through foreign comment ranges. Target the commented text deliberately with match_mode 'strict' or 'first', or scope the edit outside of it:
9
+ `+i):o.includes("another author")||o.includes("nested")?(a="An edit overlaps with a pending tracked change by another author.",l=`Accept or reject the conflicting change first, or scope your edit outside of it:
10
+ `+i):o.includes("control character")?(a="An edit contains invalid XML control characters.",l=`Remove non-printable control characters from your edit string before submitting:
11
+ `+i):o.includes("criticmarkup tags")&&(a="Do not manually include CriticMarkup tags in new_text.",l="The engine applies tracked change tags automatically. Pass clean replacement text in `new_text`:\n"+i),new n8nWorkflow.NodeApiError(this.getNode(),{message:i,errors:s},{message:a,description:l,itemIndex:e})}return o.includes("invalid docx")||o.includes("missing word/document.xml")?new n8nWorkflow.NodeApiError(this.getNode(),{message:n},{message:"The document could not be opened.",description:"Verify the input binary is a valid .docx file (not .doc, .pdf, or another format).",itemIndex:e}):new n8nWorkflow.NodeApiError(this.getNode(),{message:n},{message:"Adeu engine error.",description:n,itemIndex:e})}y(xn,"mapAdeuErrorToNodeApiError");function Oi(t){if(!t||typeof t!="object")return false;let e=t;return typeof e.id=="string"&&typeof e.fileName=="string"&&typeof e.mimeType=="string"}y(Oi,"isStashedBinaryEntry");var kn=[{displayName:"Static Data Key",name:"staticDataKey",type:"string",default:"adeu_last_redlined",required:true,placeholder:"e.g. adeu_last_redlined",description:"Key in workflow global static data to read the stashed binary metadata from (string). When the Apply Edits operation runs as an AI Agent tool, n8n's tool wrapper strips the binary from its output before any downstream node can see it. To work around that, Apply Edits writes the binary's storage id into workflow static data under 'adeu_last_redlined'. This operation reads that entry back, fetches the original buffer via getBinaryStream, and attaches a fresh IBinaryData onto the outgoing item. Leave the default unless you've customized the stash key on the Apply Edits side.",displayOptions:{show:{resource:["document"],operation:["hydrateToolOutput"]}}},{displayName:"Output Binary Property",name:"outputBinaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property on the outgoing item that will hold the hydrated .docx (string, e.g. 'data'). Downstream nodes (e.g. Write Binary File, Gmail send) should be configured to read from this property name.",displayOptions:{show:{resource:["document"],operation:["hydrateToolOutput"]}}},{displayName:"On Missing",name:"onMissing",type:"options",default:"emit_empty",description:"What to do when no stashed binary entry is found under the configured key. 'Emit Empty' is the typical AI Agent path: emits an item with json.hydrated=false and no binary, so a downstream If node can gate any write step on whether the LLM actually called Apply Edits this turn. 'Throw' is for deterministic pipelines where the stash MUST be present and a missing entry indicates a workflow bug.",options:[{name:"Emit Empty",value:"emit_empty",description:"Emit a single item with JSON.hydrated=false and no binary. Downstream If on JSON.hydrated gates the write."},{name:"Throw",value:"throw",description:"Throw a NodeOperationError. Use when a missing stash indicates a workflow bug."}],displayOptions:{show:{resource:["document"],operation:["hydrateToolOutput"]}}},{displayName:"Clear After Read",name:"clearAfterRead",type:"boolean",default:true,description:"Whether to delete the static data entry after a successful hydration so it does not leak across workflow runs. Set false if you want to inspect or re-read the entry from a later node in the same run.",displayOptions:{show:{resource:["document"],operation:["hydrateToolOutput"]}}},{displayName:"Output Path Template",name:"outputPathTemplate",type:"string",default:"",placeholder:"e.g. C:\\Users\\Uzair\\.n8n-files\\{baseName}_{timestamp}.docx",description:"Optional template to compute the final write path on disk, returned on the output JSON as 'outputPath'. If set, you can configure downstream Write nodes to simply read '{{ $json.outputPath }}' with zero escaping risks. Supports these placeholders: '{baseName}' (filename with extension stripped), '{timestamp}' (current ISO 8601 timestamp with colons and dots replaced by dashes for Windows file compatibility), '{fileName}' (the stashed filename including extension), and '{ext}' (e.g., '.docx').",displayOptions:{show:{resource:["document"],operation:["hydrateToolOutput"]}}}];async function En(t){let e=this.getNodeParameter("staticDataKey",t),n=this.getNodeParameter("outputBinaryPropertyName",t),r=this.getNodeParameter("onMissing",t),s=this.getNodeParameter("clearAfterRead",t),i=this.getWorkflowStaticData("global"),o=i[e];if(!Oi(o)){if(r==="throw")throw new n8nWorkflow.NodeOperationError(this.getNode(),`No stashed binary found under static data key "${e}".`,{description:"The Apply Edits operation writes a stash entry into workflow static data only when it runs as an AI Agent tool and produces a binary. Verify that Apply Edits was actually called by the agent this turn, that it ran successfully, and that the key matches the one used on the writing side.",itemIndex:t});return [{json:{hydrated:false},pairedItem:{item:t}}]}let{id:a,fileName:l,mimeType:u}=o,c;try{let p=await this.helpers.getBinaryStream(a);c=await this.helpers.binaryToBuffer(p);}catch(p){throw new n8nWorkflow.NodeOperationError(this.getNode(),`Failed to load stashed binary (id=${a}) from external storage.`,{description:`The stash entry under "${e}" points at binary id "${a}", but the underlying data could not be loaded. This usually means the binary has been garbage-collected (n8n's execution data retention may be too short) or external storage is unavailable. Underlying error: ${p.message}`,itemIndex:t})}let d=u||$e,f=await this.helpers.prepareBinaryData(c,l,d);s&&delete i[e];let h=this.getNodeParameter("outputPathTemplate",t,""),_;if(h.trim()!==""){let p=l.replace(/\.docx$/i,""),m=l.match(/\.docx$/i)?.[0]??".docx",w=new Date().toISOString().replace(/[:.]/g,"-").replace(/Z$/,"");_=h.replaceAll("{baseName}",p).replaceAll("{timestamp}",w).replaceAll("{fileName}",l).replaceAll("{ext}",m);}return [{json:{hydrated:true,fileName:l,sourceBinaryId:a,mimeType:d,..._!==void 0?{outputPath:_}:{}},binary:{[n]:f},pairedItem:{item:t}}]}y(En,"executeHydrateToolOutput");var On=Pt(Cn());var Di=(0, On.createRequire)("/"),Be,Mi,Ri;try{Be=Di("worker_threads"),Mi=Be.Worker,Ri=Be.isMarkedAsUntransferable;}catch{}var G=Uint8Array,se=Uint16Array,Wt=Int32Array,dt=new G([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ft=new G([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Dt=new G([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Dn=y(function(t,e){for(var n=new se(31),r=0;r<31;++r)n[r]=e+=1<<t[r-1];for(var s=new Wt(n[30]),r=1;r<30;++r)for(var i=n[r];i<n[r+1];++i)s[i]=i-n[r]<<5|r;return {b:n,r:s}},"freb"),Be=Dn(dt,2),Mn=Be.b,Mt=Be.r;Mn[28]=258,Mt[258]=28;var Rn=Dn(ft,0),ji=Rn.b,Pn=Rn.r,Rt=new se(32768);for(q=0;q<32768;++q)ge=(q&43690)>>1|(q&21845)<<1,ge=(ge&52428)>>2|(ge&13107)<<2,ge=(ge&61680)>>4|(ge&3855)<<4,Rt[q]=((ge&65280)>>8|(ge&255)<<8)>>1;var ge,q,fe=y((function(t,e,n){for(var r=t.length,s=0,i=new se(e);s<r;++s)t[s]&&++i[t[s]-1];var o=new se(e);for(s=1;s<e;++s)o[s]=o[s-1]+i[s-1]<<1;var a;if(n){a=new se(1<<e);var l=15-e;for(s=0;s<r;++s)if(t[s])for(var u=s<<4|t[s],c=e-t[s],d=o[t[s]-1]++<<c,f=d|(1<<c)-1;d<=f;++d)a[Rt[d]>>l]=u;}else for(a=new se(r),s=0;s<r;++s)t[s]&&(a[s]=Rt[o[t[s]-1]++]>>15-t[s]);return a}),"hMap"),be=new G(288);for(q=0;q<144;++q)be[q]=8;var q;for(q=144;q<256;++q)be[q]=9;var q;for(q=256;q<280;++q)be[q]=7;var q;for(q=280;q<288;++q)be[q]=8;var q,Ke=new G(32);for(q=0;q<32;++q)Ke[q]=5;var q,Fi=fe(be,9,0),Bi=fe(be,9,1),Wi=fe(Ke,5,0),zi=fe(Ke,5,1),St=y(function(t){for(var e=t[0],n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},"max"),ce=y(function(t,e,n){var r=e/8|0;return (t[r]|t[r+1]<<8)>>(e&7)&n},"bits"),It=y(function(t,e){var n=e/8|0;return (t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},"bits16"),zt=y(function(t){return (t+7)/8|0},"shft"),et=y(function(t,e,n){return (e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new G(t.subarray(e,n))},"slc");var Li=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],ee=y(function(t,e,n){var r=new Error(e||Li[t]);if(r.code=t,Error.captureStackTrace&&Error.captureStackTrace(r,ee),!n)throw r;return r},"err"),Ui=y(function(t,e,n,r){var s=t.length,i=r?r.length:0;if(!s||e.f&&!e.l)return n||new G(0);var o=!n,a=o||e.i!=2,l=e.i;o&&(n=new G(s*3));var u=y(function(Ye){var Ge=n.length;if(Ye>Ge){var Fe=new G(Math.max(Ge*2,Ye));Fe.set(n),n=Fe;}},"cbuf"),c=e.f||0,d=e.p||0,f=e.b||0,h=e.l,_=e.d,p=e.m,m=e.n,w=s*8;do{if(!h){c=ce(t,d,1);var k=ce(t,d+1,3);if(d+=3,k)if(k==1)h=Bi,_=zi,p=9,m=5;else if(k==2){var x=ce(t,d,31)+257,E=ce(t,d+10,15)+4,C=x+ce(t,d+5,31)+1;d+=14;for(var A=new G(C),N=new G(19),P=0;P<E;++P)N[Dt[P]]=ce(t,d+P*3,7);d+=E*3;for(var D=St(N),T=(1<<D)-1,F=fe(N,D,1),P=0;P<C;){var I=F[ce(t,d,T)];d+=I&15;var b=I>>4;if(b<16)A[P++]=b;else {var S=0,R=0;for(b==16?(R=3+ce(t,d,3),d+=2,S=A[P-1]):b==17?(R=3+ce(t,d,7),d+=3):b==18&&(R=11+ce(t,d,127),d+=7);R--;)A[P++]=S;}}var j=A.subarray(0,x),B=A.subarray(x);p=St(j),m=St(B),h=fe(j,p,1),_=fe(B,m,1);}else ee(1);else {var b=zt(d)+4,g=t[b-4]|t[b-3]<<8,v=b+g;if(v>s){l&&ee(0);break}a&&u(f+g),n.set(t.subarray(b,v),f),e.b=f+=g,e.p=d=v*8,e.f=c;continue}if(d>w){l&&ee(0);break}}a&&u(f+131072);for(var L=(1<<p)-1,U=(1<<m)-1,Y=d;;Y=d){var S=h[It(t,d)&L],X=S>>4;if(d+=S&15,d>w){l&&ee(0);break}if(S||ee(2),X<256)n[f++]=X;else if(X==256){Y=d,h=null;break}else {var J=X-254;if(X>264){var P=X-257,W=dt[P];J=ce(t,d,(1<<W)-1)+Mn[P],d+=W;}var te=_[It(t,d)&U],ue=te>>4;te||ee(3),d+=te&15;var B=ji[ue];if(ue>3){var W=ft[ue];B+=It(t,d)&(1<<W)-1,d+=W;}if(d>w){l&&ee(0);break}a&&u(f+131072);var _e=f+J;if(f<B){var at=i-B,lt=Math.min(B,_e);for(at+f<0&&ee(3);f<lt;++f)n[f]=r[at+f];}for(;f<_e;++f)n[f]=n[f-B];}}e.l=h,e.p=Y,e.b=f,e.f=c,h&&(c=1,e.m=p,e.d=_,e.n=m);}while(!c);return f!=n.length&&o?et(n,0,f):n.subarray(0,f)},"inflt"),we=y(function(t,e,n){n<<=e&7;var r=e/8|0;t[r]|=n,t[r+1]|=n>>8;},"wbits"),Ve=y(function(t,e,n){n<<=e&7;var r=e/8|0;t[r]|=n,t[r+1]|=n>>8,t[r+2]|=n>>16;},"wbits16"),$t=y(function(t,e){for(var n=[],r=0;r<t.length;++r)t[r]&&n.push({s:r,f:t[r]});var s=n.length,i=n.slice();if(!s)return {t:Fn,l:0};if(s==1){var o=new G(n[0].s+1);return o[n[0].s]=1,{t:o,l:1}}n.sort(function(v,x){return v.f-x.f}),n.push({s:-1,f:25001});var a=n[0],l=n[1],u=0,c=1,d=2;for(n[0]={s:-1,f:a.f+l.f,l:a,r:l};c!=s-1;)a=n[n[u].f<n[d].f?u++:d++],l=n[u!=c&&n[u].f<n[d].f?u++:d++],n[c++]={s:-1,f:a.f+l.f,l:a,r:l};for(var f=i[0].s,r=1;r<s;++r)i[r].s>f&&(f=i[r].s);var h=new se(f+1),_=jt(n[c-1],h,0);if(_>e){var r=0,p=0,m=_-e,w=1<<m;for(i.sort(function(x,E){return h[E.s]-h[x.s]||x.f-E.f});r<s;++r){var k=i[r].s;if(h[k]>e)p+=w-(1<<_-h[k]),h[k]=e;else break}for(p>>=m;p>0;){var b=i[r].s;h[b]<e?p-=1<<e-h[b]++-1:++r;}for(;r>=0&&p;--r){var g=i[r].s;h[g]==e&&(--h[g],++p);}_=e;}return {t:new G(h),l:_}},"hTree"),jt=y(function(t,e,n){return t.s==-1?Math.max(jt(t.l,e,n+1),jt(t.r,e,n+1)):e[t.s]=n},"ln"),Tn=y(function(t){for(var e=t.length;e&&!t[--e];);for(var n=new se(++e),r=0,s=t[0],i=1,o=y(function(l){n[r++]=l;},"w"),a=1;a<=e;++a)if(t[a]==s&&a!=e)++i;else {if(!s&&i>2){for(;i>138;i-=138)o(32754);i>2&&(o(i>10?i-11<<5|28690:i-3<<5|12305),i=0);}else if(i>3){for(o(s),--i;i>6;i-=6)o(8304);i>2&&(o(i-3<<5|8208),i=0);}for(;i--;)o(s);i=1,s=t[a];}return {c:n.subarray(0,r),n:e}},"lc"),Ze=y(function(t,e){for(var n=0,r=0;r<e.length;++r)n+=t[r]*e[r];return n},"clen"),jn=y(function(t,e,n){var r=n.length,s=zt(e+2);t[s]=r&255,t[s+1]=r>>8,t[s+2]=t[s]^255,t[s+3]=t[s+1]^255;for(var i=0;i<r;++i)t[s+i+4]=n[i];return (s+4+r)*8},"wfblk"),Sn=y(function(t,e,n,r,s,i,o,a,l,u,c){we(e,c++,n),++s[256];for(var d=$t(s,15),f=d.t,h=d.l,_=$t(i,15),p=_.t,m=_.l,w=Tn(f),k=w.c,b=w.n,g=Tn(p),v=g.c,x=g.n,E=new se(19),C=0;C<k.length;++C)++E[k[C]&31];for(var C=0;C<v.length;++C)++E[v[C]&31];for(var A=$t(E,7),N=A.t,P=A.l,D=19;D>4&&!N[Dt[D-1]];--D);var T=u+5<<3,F=Ze(s,be)+Ze(i,Ke)+o,I=Ze(s,f)+Ze(i,p)+o+14+3*D+Ze(E,N)+2*E[16]+3*E[17]+7*E[18];if(l>=0&&T<=F&&T<=I)return jn(e,c,t.subarray(l,l+u));var S,R,j,B;if(we(e,c,1+(I<F)),c+=2,I<F){S=fe(f,h,0),R=f,j=fe(p,m,0),B=p;var L=fe(N,P,0);we(e,c,b-257),we(e,c+5,x-1),we(e,c+10,D-4),c+=14;for(var C=0;C<D;++C)we(e,c+3*C,N[Dt[C]]);c+=3*D;for(var U=[k,v],Y=0;Y<2;++Y)for(var X=U[Y],C=0;C<X.length;++C){var J=X[C]&31;we(e,c,L[J]),c+=N[J],J>15&&(we(e,c,X[C]>>5&127),c+=X[C]>>12);}}else S=Fi,R=be,j=Wi,B=Ke;for(var C=0;C<a;++C){var W=r[C];if(W>255){var J=W>>18&31;Ve(e,c,S[J+257]),c+=R[J+257],J>7&&(we(e,c,W>>23&31),c+=dt[J]);var te=W&31;Ve(e,c,j[te]),c+=B[te],te>3&&(Ve(e,c,W>>5&8191),c+=ft[te]);}else Ve(e,c,S[W]),c+=R[W];}return Ve(e,c,S[256]),c+R[256]},"wblk"),qi=new Wt([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Fn=new G(0),Ji=y(function(t,e,n,r,s,i){var o=i.z||t.length,a=new G(r+o+5*(1+Math.ceil(o/7e3))+s),l=a.subarray(r,a.length-s),u=i.l,c=(i.r||0)&7;if(e){c&&(l[0]=i.r>>3);for(var d=qi[e-1],f=d>>13,h=d&8191,_=(1<<n)-1,p=i.p||new se(32768),m=i.h||new se(_+1),w=Math.ceil(n/3),k=2*w,b=y(function(At){return (t[At]^t[At+1]<<w^t[At+2]<<k)&_},"hsh"),g=new Wt(25e3),v=new se(288),x=new se(32),E=0,C=0,A=i.i||0,N=0,P=i.w||0,D=0;A+2<o;++A){var T=b(A),F=A&32767,I=m[T];if(p[F]=I,m[T]=F,P<=A){var S=o-A;if((E>7e3||N>24576)&&(S>423||!u)){c=Sn(t,l,0,g,v,x,C,N,D,A-D,c),N=E=C=0,D=A;for(var R=0;R<286;++R)v[R]=0;for(var R=0;R<30;++R)x[R]=0;}var j=2,B=0,L=h,U=F-I&32767;if(S>2&&T==b(A-U))for(var Y=Math.min(f,S)-1,X=Math.min(32767,A),J=Math.min(258,S);U<=X&&--L&&F!=I;){if(t[A+j]==t[A+j-U]){for(var W=0;W<J&&t[A+W]==t[A+W-U];++W);if(W>j){if(j=W,B=U,W>Y)break;for(var te=Math.min(U,W-2),ue=0,R=0;R<te;++R){var _e=A-U+R&32767,at=p[_e],lt=_e-at&32767;lt>ue&&(ue=lt,I=_e);}}}F=I,I=p[F],U+=F-I&32767;}if(B){g[N++]=268435456|Mt[j]<<18|Pn[B];var Ye=Mt[j]&31,Ge=Pn[B]&31;C+=dt[Ye]+ft[Ge],++v[257+Ye],++x[Ge],P=A+j,++E;}else g[N++]=t[A],++v[t[A]];}}for(A=Math.max(A,P);A<o;++A)g[N++]=t[A],++v[t[A]];c=Sn(t,l,u,g,v,x,C,N,D,A-D,c),u||(i.r=c&7|l[c/8|0]<<3,c-=7,i.h=m,i.p=p,i.i=A,i.w=P);}else {for(var A=i.w||0;A<o+u;A+=65535){var Fe=A+65535;Fe>=o&&(l[c/8|0]=u,Fe=o),c=jn(l,c+1,t.subarray(A,Fe));}i.i=o;}return et(a,0,r+zt(c)+s)},"dflt"),Hi=(function(){for(var t=new Int32Array(256),e=0;e<256;++e){for(var n=e,r=9;--r;)n=(n&1&&-306674912)^n>>>1;t[e]=n;}return t})(),Xi=y(function(){var t=-1;return {p:y(function(e){for(var n=t,r=0;r<e.length;++r)n=Hi[n&255^e[r]]^n>>>8;t=n;},"p"),d:y(function(){return ~t},"d")}},"crc");var Qi=y(function(t,e,n,r,s){if(!s&&(s={l:1},e.dictionary)){var i=e.dictionary.subarray(-32768),o=new G(i.length+t.length);o.set(i),o.set(t,i.length),t=o,s.w=i.length;}return Ji(t,e.level==null?6:e.level,e.mem==null?s.l?Math.ceil(Math.max(8,Math.min(13,Math.log(t.length)))*1.5):20:12+e.mem,n,r,s)},"dopt"),Bn=y(function(t,e){var n={};for(var r in t)n[r]=t[r];for(var r in e)n[r]=e[r];return n},"mrg");var de=y(function(t,e){return t[e]|t[e+1]<<8},"b2"),oe=y(function(t,e){return (t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0},"b4"),Ot=y(function(t,e){return oe(t,e)+oe(t,e+4)*4294967296},"b8"),K=y(function(t,e,n){for(;n;++e)t[e]=n,n>>>=8;},"wbytes");function Yi(t,e){return Qi(t,e||{},0,0)}y(Yi,"deflateSync");function Gi(t,e){return Ui(t,{i:2},e&&e.out,e&&e.dictionary)}y(Gi,"inflateSync");var Wn=y(function(t,e,n,r){for(var s in t){var i=t[s],o=e+s,a=r;Array.isArray(i)&&(a=Bn(r,i[1]),i=i[0]),ArrayBuffer.isView(i)?n[o]=[i,a]:(n[o+="/"]=[new G(0),a],Wn(i,o,n,r));}},"fltn"),In=typeof TextEncoder<"u"&&new TextEncoder,Ft=typeof TextDecoder<"u"&&new TextDecoder,Vi=0;try{Ft.decode(Fn,{stream:!0}),Vi=1;}catch{}var Zi=y(function(t){for(var e="",n=0;;){var r=t[n++],s=(r>127)+(r>223)+(r>239);if(n+s>t.length)return {s:e,r:et(t,n-1)};s?s==3?(r=((r&15)<<18|(t[n++]&63)<<12|(t[n++]&63)<<6|t[n++]&63)-65536,e+=String.fromCharCode(55296|r>>10,56320|r&1023)):s&1?e+=String.fromCharCode((r&31)<<6|t[n++]&63):e+=String.fromCharCode((r&15)<<12|(t[n++]&63)<<6|t[n++]&63):e+=String.fromCharCode(r);}},"dutf8");function ut(t,e){if(e){for(var n=new G(t.length),r=0;r<t.length;++r)n[r]=t.charCodeAt(r);return n}if(In)return In.encode(t);for(var s=t.length,i=new G(t.length+(t.length>>1)),o=0,a=y(function(c){i[o++]=c;},"w"),r=0;r<s;++r){if(o+5>i.length){var l=new G(o+8+(s-r<<1));l.set(i),i=l;}var u=t.charCodeAt(r);u<128||e?a(u):u<2048?(a(192|u>>6),a(128|u&63)):u>55295&&u<57344?(u=65536+(u&1047552)|t.charCodeAt(++r)&1023,a(240|u>>18),a(128|u>>12&63),a(128|u>>6&63),a(128|u&63)):(a(224|u>>12),a(128|u>>6&63),a(128|u&63));}return et(i,0,o)}y(ut,"strToU8");function Oe(t,e){if(e){for(var n="",r=0;r<t.length;r+=16384)n+=String.fromCharCode.apply(null,t.subarray(r,r+16384));return n}else {if(Ft)return Ft.decode(t);var s=Zi(t),i=s.s,n=s.r;return n.length&&ee(8),i}}y(Oe,"strFromU8");var Ki=y(function(t,e){return e+30+de(t,e+26)+de(t,e+28)},"slzh"),es=y(function(t,e,n){var r=de(t,e+28),s=de(t,e+30),i=Oe(t.subarray(e+46,e+46+r),!(de(t,e+8)&2048)),o=e+46+r,a=ts(t,o,s,n,oe(t,e+20),oe(t,e+24),oe(t,e+42)),l=a[0],u=a[1],c=a[2];return [de(t,e+10),l,u,i,o+s+de(t,e+32),c]},"zh"),ts=y(function(t,e,n,r,s,i,o){var a=s==4294967295,l=i==4294967295,u=o==4294967295,c=e+n,d=a+l+u;if(r&&d){for(;e+4<c;e+=4+de(t,e+2))if(de(t,e)==1)return [a?Ot(t,e+4+8*l):s,l?Ot(t,e+4):i,u?Ot(t,e+4+8*(l+a)):o,1];r<2&&ee(13);}return [s,i,o,0]},"z64hs"),Bt=y(function(t){var e=0;if(t)for(var n in t){var r=t[n].length;r>65535&&ee(9),e+=r+4;}return e},"exfl"),$n=y(function(t,e,n,r,s,i,o,a){var l=r.length,u=n.extra,c=a&&a.length,d=Bt(u);K(t,e,o!=null?33639248:67324752),e+=4,o!=null&&(t[e++]=20,t[e++]=n.os),t[e]=20,e+=2,t[e++]=n.flag<<1|(i<0&&8),t[e++]=s&&8,t[e++]=n.compression&255,t[e++]=n.compression>>8;var f=new Date(n.mtime==null?Date.now():n.mtime),h=f.getFullYear()-1980;if((h<0||h>119)&&ee(10),K(t,e,h<<25|f.getMonth()+1<<21|f.getDate()<<16|f.getHours()<<11|f.getMinutes()<<5|f.getSeconds()>>1),e+=4,i!=-1&&(K(t,e,n.crc),K(t,e+4,i<0?-i-2:i),K(t,e+8,n.size)),K(t,e+12,l),K(t,e+14,d),e+=16,o!=null&&(K(t,e,c),K(t,e+6,n.attrs),K(t,e+10,o),e+=14),t.set(r,e),e+=l,d)for(var _ in u){var p=u[_],m=p.length;K(t,e,+_),K(t,e+2,m),t.set(p,e+4),e+=4+m;}return c&&(t.set(a,e),e+=c),e},"wzh"),ns=y(function(t,e,n,r,s){K(t,e,101010256),K(t,e+8,n),K(t,e+10,n),K(t,e+12,r),K(t,e+16,s);},"wzf");function zn(t,e){e||(e={});var n={},r=[];Wn(t,"",n,e);var s=0,i=0;for(var o in n){var a=n[o],l=a[0],u=a[1],c=u.level==0?0:8,d=ut(o),f=d.length,h=u.comment,_=h&&ut(h),p=_&&_.length,m=Bt(u.extra);f>65535&&ee(11);var w=c?Yi(l,u):l,k=w.length,b=Xi();b.p(l),r.push(Bn(u,{size:l.length,crc:b.d(),c:w,f:d,m:_,u:f!=o.length||_&&h.length!=p,o:s,compression:c})),s+=30+f+m+k,i+=76+2*(f+m)+(p||0)+k;}for(var g=new G(i+22),v=s,x=i-s,E=0;E<r.length;++E){var d=r[E];$n(g,d.o,d,d.f,d.u,d.c.length);var C=30+d.f.length+Bt(d.extra);g.set(d.c,d.o+C),$n(g,s,d,d.f,d.u,d.c.length,d.o,d.m),s+=16+C+(d.m?d.m.length:0);}return ns(g,s,r.length,x,v),g}y(zn,"zipSync");function We(t,e){for(var n={},r=t.length-22;oe(t,r)!=101010256;--r)(!r||t.length-r>65558)&&ee(13);var s=de(t,r+8);if(!s)return {};var i=oe(t,r+16),o=oe(t,r-20)==117853008;if(o){var a=oe(t,r-12);o=oe(t,a)==101075792,o&&(s=oe(t,a+32),i=oe(t,a+48));}for(var l=e&&e.filter,u=0;u<s;++u){var c=es(t,i,o),d=c[0],f=c[1],h=c[2],_=c[3],p=c[4],m=c[5],w=Ki(t,m);i=p,(!l||l({name:_,size:f,originalSize:h,compression:d}))&&(d?d==8?n[_]=Gi(t.subarray(w,w+f),{out:new G(h)}):ee(14,"unknown compression type "+d):n[_]=et(t,w,w+f));}return n}y(We,"unzipSync");var Ar=Pt(Lt());var pn=Pt(Lt());var Me=1,sn=3,on=4,ur=8,an=9,dr=class{static{y(this,"FastNode");}nodeType=0;parentNode=null;ownerDocument=null;get firstChild(){return null}get lastChild(){return null}get nextSibling(){let t=this.parentNode;if(!t)return null;let e=t.childNodes,n=e.indexOf(this);return n>=0&&n+1<e.length?e[n+1]:null}get previousSibling(){let t=this.parentNode;if(!t)return null;let e=t.childNodes,n=e.indexOf(this);return n>0?e[n-1]:null}},it=class fr extends dr{static{y(this,"_FastText");}constructor(e){super(),this.data=e;}data;nodeType=sn;get nodeName(){return "#text"}get nodeValue(){return this.data}set nodeValue(e){this.data=e;}get textContent(){return this.data}set textContent(e){this.data=e,this.ownerDocument&&this.ownerDocument._inc++;}cloneNode(e){let n=new fr(this.data);return n.ownerDocument=this.ownerDocument,n}toString(){return bt(this)}},hr=class pr extends it{static{y(this,"_FastComment");}nodeType=ur;cloneNode(e){let n=new pr(this.data);return n.ownerDocument=this.ownerDocument,n}},rs=class _r extends it{static{y(this,"_FastCData");}nodeType=on;cloneNode(e){let n=new _r(this.data);return n.ownerDocument=this.ownerDocument,n}},mr=class extends dr{static{y(this,"FastParent");}childNodes=[];get firstChild(){return this.childNodes.length?this.childNodes[0]:null}get lastChild(){return this.childNodes.length?this.childNodes[this.childNodes.length-1]:null}hasChildNodes(){return this.childNodes.length>0}bump(){let t=this.nodeType===an?this:this.ownerDocument;t&&t._inc++;}appendChild(t){return t.parentNode&&t.parentNode.removeChild(t),this.childNodes.push(t),t.parentNode=this,this.bump(),t}insertBefore(t,e){if(!e)return this.appendChild(t);if(this.childNodes.indexOf(e)<0)throw new Error("insertBefore: reference node not a child");t.parentNode&&t.parentNode.removeChild(t);let r=this.childNodes.indexOf(e);return this.childNodes.splice(r,0,t),t.parentNode=this,this.bump(),t}removeChild(t){let e=this.childNodes.indexOf(t);if(e<0)throw new Error("removeChild: node is not a child");return this.childNodes.splice(e,1),t.parentNode=null,this.bump(),t}replaceChild(t,e){if(this.childNodes.indexOf(e)<0)throw new Error("replaceChild: node is not a child");t.parentNode&&t.parentNode.removeChild(t);let r=this.childNodes.indexOf(e);return this.childNodes[r]=t,t.parentNode=this,e.parentNode=null,this.bump(),e}getElementsByTagName(t){let e=[],n=t==="*",r=[];for(let s=this.childNodes.length-1;s>=0;s--)r.push(this.childNodes[s]);for(;r.length;){let s=r.pop();if(s.nodeType===Me){let i=s;(n||i.tagName===t)&&e.push(i);for(let o=i.childNodes.length-1;o>=0;o--)r.push(i.childNodes[o]);}}return e}},gr=class wr extends mr{static{y(this,"_FastElement");}constructor(e){super(),this.tagName=e;}tagName;nodeType=Me;attrs=[];get nodeName(){return this.tagName}get localName(){let e=this.tagName.indexOf(":");return e<0?this.tagName:this.tagName.slice(e+1)}get prefix(){let e=this.tagName.indexOf(":");return e<0?null:this.tagName.slice(0,e)}get nodeValue(){return null}get attributes(){let e=this.attrs.map(([n,r])=>({nodeType:2,name:n,value:r,nodeName:n,nodeValue:r,localName:n.indexOf(":")<0?n:n.slice(n.indexOf(":")+1),prefix:n.indexOf(":")<0?null:n.slice(0,n.indexOf(":")),ownerElement:this}));return e.item=n=>e[n]??null,e}toString(){return bt(this)}getAttribute(e){let n=this.attrs;for(let r=0;r<n.length;r++)if(n[r][0]===e)return n[r][1];return null}hasAttribute(e){return this.getAttribute(e)!==null}setAttribute(e,n){let r=this.attrs;for(let s=0;s<r.length;s++)if(r[s][0]===e){r[s][1]=String(n),this.ownerDocument&&this.ownerDocument._inc++;return}r.push([e,String(n)]),this.ownerDocument&&this.ownerDocument._inc++;}removeAttribute(e){let n=this.attrs;for(let r=0;r<n.length;r++)if(n[r][0]===e){n.splice(r,1),this.ownerDocument&&this.ownerDocument._inc++;return}}get textContent(){let e="",n=[];for(let r=this.childNodes.length-1;r>=0;r--)n.push(this.childNodes[r]);for(;n.length;){let r=n.pop();if(r.nodeType===sn||r.nodeType===on)e+=r.data;else if(r.nodeType===Me){let s=r;for(let i=s.childNodes.length-1;i>=0;i--)n.push(s.childNodes[i]);}}return e}set textContent(e){for(let n of this.childNodes)n.parentNode=null;if(this.childNodes.length=0,e!==""&&e!==null&&e!==void 0){let n=new it(String(e));n.ownerDocument=this.ownerDocument,n.parentNode=this,this.childNodes.push(n);}this.ownerDocument&&this.ownerDocument._inc++;}cloneNode(e=false){let n=new wr(this.tagName);if(n.ownerDocument=this.ownerDocument,this.attrs.length&&(n.attrs=this.attrs.map(([r,s])=>[r,s])),e)for(let r of this.childNodes){let s=r.cloneNode(true);s.parentNode=n,n.childNodes.push(s);}return n}},is=class extends mr{static{y(this,"FastDocument");}nodeType=an;_inc=1;documentElement=null;get nodeName(){return "#document"}createElement(t){let e=new gr(t);return e.ownerDocument=this,e}createElementNS(t,e){return this.createElement(e)}createTextNode(t){let e=new it(String(t));return e.ownerDocument=this,e}createComment(t){let e=new hr(String(t));return e.ownerDocument=this,e}toString(){return bt(this)}appendChild(t){let e=super.appendChild(t);return t.nodeType===Me&&(this.documentElement=t),e}replaceChild(t,e){let n=super.replaceChild(t,e);return e===this.documentElement&&t.nodeType===Me&&(this.documentElement=t),n}},ss=/&(?:amp|lt|gt|quot|apos|#x?[0-9a-fA-F]+);/g;function yr(t){return t.indexOf("&")<0?t:t.replace(ss,e=>{switch(e){case "&amp;":return "&";case "&lt;":return "<";case "&gt;":return ">";case "&quot;":return '"';case "&apos;":return "'";default:{let n=e.slice(2,-1),r=n[0]==="x"||n[0]==="X"?parseInt(n.slice(1),16):parseInt(n,10);return Number.isFinite(r)?String.fromCodePoint(r):e}}})}y(yr,"decodeEntities");function Yt(t){return t.indexOf("\r")<0?t:t.replace(/\r\n?/g,`
12
+ `)}y(Yt,"normalizeLineEnds");function os(t){let e=Yt(t),n=/[\n\t]/.test(e)?e.replace(/[\n\t]/g," "):e;return yr(n)}y(os,"normalizeAttrValue");var Ut=new Set([32,9,10,13]);function as(t){t.charCodeAt(0)===65279&&(t=t.slice(1));let e=new is,n=e,r=0,s=t.length,i=false;for(;r<s;){let o=t.indexOf("<",r);if(o<0){if(n!==e)throw new Error("Unexpected end of XML");if(/\S/.test(t.slice(r)))throw new Error("Content after document root");break}if(o>r&&n!==e){let d=t.slice(r,o),f=new it(yr(Yt(d)));f.ownerDocument=e,f.parentNode=n,n.childNodes.push(f);}else if(o>r&&/\S/.test(t.slice(r,o)))throw new Error("Text content outside document root");r=o+1;let a=t.charCodeAt(r);if(a===47){let d=t.indexOf(">",r);if(d<0)throw new Error("Unterminated close tag");let f=t.slice(r+1,d).trim();if(n.nodeType!==Me||n.tagName!==f)throw new Error(`Mismatched close tag </${f}>`);n=n.parentNode??e,r=d+1;continue}if(a===63){let d=t.indexOf("?>",r);if(d<0)throw new Error("Unterminated processing instruction");r=d+2;continue}if(a===33){if(t.startsWith("!--",r)){let f=t.indexOf("-->",r+3);if(f<0)throw new Error("Unterminated comment");let h=new hr(t.slice(r+3,f));h.ownerDocument=e,n!==e&&(h.parentNode=n,n.childNodes.push(h)),r=f+3;continue}if(t.startsWith("![CDATA[",r)){let f=t.indexOf("]]>",r+8);if(f<0)throw new Error("Unterminated CDATA section");if(n!==e){let h=new rs(Yt(t.slice(r+8,f)));h.ownerDocument=e,h.parentNode=n,n.childNodes.push(h);}r=f+3;continue}let d=t.indexOf(">",r);if(d<0)throw new Error("Unterminated declaration");r=d+1;continue}let l=r;for(;l<s;){let d=t.charCodeAt(l);if(Ut.has(d)||d===62||d===47)break;l++;}if(l===r)throw new Error(`Invalid tag at offset ${o}`);let u=new gr(t.slice(r,l));if(u.ownerDocument=e,n===e){if(i)throw new Error("Multiple document roots");i=true,e.childNodes.push(u),u.parentNode=e,e.documentElement=u;}else u.parentNode=n,n.childNodes.push(u);r=l;let c=false;for(;r<s;){let d=t.charCodeAt(r);if(d===62){r++;break}if(d===47){if(t.charCodeAt(r+1)!==62)throw new Error("Malformed self-close");c=true,r+=2;break}if(Ut.has(d)){r++;continue}let f=t.indexOf("=",r);if(f<0)throw new Error("Malformed attribute");let h=t.slice(r,f).trim(),_=f+1;for(;_<s&&Ut.has(t.charCodeAt(_));)_++;let p=t.charCodeAt(_);if(p!==34&&p!==39)throw new Error("Unquoted attribute value");let m=t.indexOf(String.fromCharCode(p),_+1);if(m<0)throw new Error("Unterminated attribute value");u.attrs.push([h,os(t.slice(_+1,m))]),r=m+1;}c||(n=u);}if(n!==e)throw new Error("Unclosed element at end of document");if(!e.documentElement)throw new Error("Empty XML document");return e}y(as,"parseFastXml");function ls(t){return /[&<>\r]/.test(t)?t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\r/g,"&#13;"):t}y(ls,"escText");function cs(t){return /[&<>"\t\n\r]/.test(t)?t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/\t/g,"&#9;").replace(/\n/g,"&#10;").replace(/\r/g,"&#13;"):t}y(cs,"escAttr");function bt(t){let e=[],n=y(r=>{switch(r.nodeType){case Me:{let s=r;e.push("<",s.tagName);for(let i=0;i<s.attrs.length;i++){let[o,a]=s.attrs[i];e.push(" ",o,'="',cs(a),'"');}if(s.childNodes.length===0)e.push("/>");else {e.push(">");for(let i of s.childNodes)n(i);e.push("</",s.tagName,">");}break}case sn:e.push(ls(r.data));break;case on:e.push("<![CDATA[",r.data,"]]>");break;case ur:e.push("<!--",r.data,"-->");break;case an:for(let s of r.childNodes)n(s);break}},"write");return n(t),e.join("")}y(bt,"serializeFastXml");function M(t,e){for(let n=0;n<t.childNodes.length;n++){let r=t.childNodes[n];if(r.nodeType===1&&r.tagName===e)return r}return null}y(M,"findChild");function vr(t,e){let n=[];for(let r=0;r<t.childNodes.length;r++){let s=t.childNodes[r];s.nodeType===1&&s.tagName===e&&n.push(s);}return n}y(vr,"findChildren");function $(t,e){return Array.from(t.getElementsByTagName(e))}y($,"findAllDescendants");function Je(t){return t.startsWith("\uFEFF")&&(t=t.slice(1)),as(t)}y(Je,"parseXml");function Ln(t){let e=bt(t),r=/<([a-zA-Z0-9_:]+)(\s+[^>]+?)(>|\/>)/.exec(e);if(r&&!r[1].startsWith("?")){let s=r.index,i=e.substring(0,s);if(!i.includes("<")||i.trim().startsWith("<?xml")&&(i.match(/</g)||[]).length===1){let a=r[0],l=`<${r[1]}`,u=r[2],c=r[3],d=/([a-zA-Z0-9_:]+)\s*=\s*(["'])(.*?)\2/g,f=[],h;for(;(h=d.exec(u))!==null;)f.push(h[0].trim());f.sort((p,m)=>{let w=p.split("=")[0].trim(),k=m.split("=")[0].trim(),b=w.startsWith("xmlns"),g=k.startsWith("xmlns");return b&&!g?-1:!b&&g?1:w<k?-1:w>k?1:0});let _=f.length>0?`${l} ${f.join(" ")}${c}`:`${l}${c}`;e=e.substring(0,s)+_+e.substring(s+a.length);}}return e}y(Ln,"serializeXml");var Gt="__adeu_wp_index_cache",br="__adeu_clean_inc";function xt(t){return typeof t._inc=="number"?t._inc:null}y(xt,"docInc");function tt(t){let e=xt(t);e!==null&&(t[br]=e);}y(tt,"markPartClean");function ln(t){let e=xt(t);return e!==null&&t[br]===e}y(ln,"isPartClean");function us(t){let e=new Map,n=t.documentElement;if(!n)return e;let r=0;n.nodeType===1&&n.tagName==="w:p"&&e.set(n,r++);let s=[n],i=[0];for(;s.length;){let o=s.length-1,a=s[o].childNodes;if(!a||i[o]>=a.length){s.pop(),i.pop();continue}let l=a[i[o]++];l.nodeType===1&&(l.tagName==="w:p"&&e.set(l,r++),s.push(l),i.push(0));}return e}y(us,"buildWpIndexMap");function ds(t,e){let n=xt(t),r=t[Gt];(!r||n===null||r.inc!==n||!r.map.has(e))&&(r={inc:n??NaN,map:us(t)},t[Gt]=r);let s=r.map.get(e);return s===void 0?-1:s}y(ds,"wpDocumentOrderIndex");function fs(t){let e=t[Gt],n=xt(t);e&&n!==null&&(e.inc=n);}y(fs,"resyncAfterOwnAttributeMutation");function xr(t,e){let n=t.getElementsByTagName("w:p")[0],r=n?n.getAttribute("w14:paraId"):null;if(!r&&e){let s=t.ownerDocument,i=ln(s);n||(n=s.createElement("w:p"),t.appendChild(n));let o=ds(s,n),a=2166136261,l=`fallback-paraId-${o}`;for(let u=0;u<l.length;u++)a^=l.charCodeAt(u),a+=(a<<1)+(a<<4)+(a<<7)+(a<<8)+(a<<24);r=(a>>>0).toString(16).toUpperCase().padStart(8,"0"),n.setAttribute("w14:paraId",r),fs(s),i&&tt(s);}return {paraId:r,firstP:n}}y(xr,"resolve_cell_anchor");var mt=class{static{y(this,"Relationship");}constructor(t,e,n,r){this.id=t,this.type=e,this.target=n,this.isExternal=r;}id;type;target;isExternal},Nr=class{static{y(this,"Part");}constructor(t,e,n,r){this.partname=t,this.blob=e,this.contentType=r,this._element=n;}partname;blob;contentType;rels=new Map;_element;package;addRelationship(t,e,n,r=false){if(this.rels.set(t,new mt(t,e,n,r)),this.partname.endsWith(".rels")){let s=this._element.ownerDocument;if(s){let i=s.createElementNS("http://schemas.openxmlformats.org/package/2006/relationships","Relationship");i.setAttribute("Id",t),i.setAttribute("Type",e),i.setAttribute("Target",n),r&&i.setAttribute("TargetMode","External"),this._element.appendChild(i);}}}},hs=class{static{y(this,"DocxPackage");}constructor(t){this.unzipped=t;}unzipped;parts=[];mainDocumentPart;getPartByPath(t){let e=t.startsWith("/")?t.substring(1):t;return this.parts.find(n=>n.partname===e||n.partname==="/"+e)}nextPartname(t){let e=1;for(;;){let n=t.replace("%d",e===1?"":e.toString());if(!this.getPartByPath(n))return n;e++;}}addPart(t,e,n){let r=Je(n),s=new Nr(t,n,r.documentElement,e);s.package=this,this.parts.push(s);let i=this.getPartByPath("[Content_Types].xml");if(i){let o=i._element.ownerDocument;if(o){let a=o.createElement("Override");a.setAttribute("PartName",t),a.setAttribute("ContentType",e),i._element.appendChild(a);}}return s}getOrCreateRelsPart(t){let e=t.split("/"),n=e.pop(),r=e.join("/")+"/_rels/"+n+".rels",s=this.getPartByPath(r);return s||(s=this.addPart(r,"application/vnd.openxmlformats-package.relationships+xml",`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
13
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>`)),s}},pe=class kr{static{y(this,"_DocumentObject");}constructor(e,n){this.pkg=e,this.part=n;}pkg;part;settings={oddAndEvenPagesHeaderFooter:false};sections=[];get element(){return M(this.part._element,"w:body")||this.part._element}static async load(e,n){let r=e instanceof Uint8Array?e:new Uint8Array(e),s=We(r),i=new hs(s),o=s["[Content_Types].xml"],a={};if(o){let _=Je(Oe(o)),p=$(_.documentElement,"Override");for(let m of p)a[m.getAttribute("PartName")||""]=m.getAttribute("ContentType")||"";}let l=n?.onPart,u=Math.max(1,n?.partTickEvery??200),c=0;if(l)for(let _ of Object.keys(s))(_.endsWith(".xml")||_.endsWith(".rels"))&&c++;let d=0;for(let[_,p]of Object.entries(s))if(_.endsWith(".xml")||_.endsWith(".rels")){let m=Oe(p),w=Je(m);tt(w);let k=a["/"+_]||"application/xml",b=new Nr("/"+_,m,w.documentElement,k);b.package=i,i.parts.push(b),d++,l&&d%u===0&&await l(d,c);}l&&c>0&&await l(c,c);let f=i.getPartByPath("word/document.xml");if(!f)throw new Error("Invalid DOCX: Missing word/document.xml");i.mainDocumentPart=f;let h=i.getPartByPath("word/_rels/document.xml.rels");if(h){let _=$(h._element,"Relationship");for(let p of _){let m=p.getAttribute("Id"),w=p.getAttribute("Target"),k=p.getAttribute("Type"),b=p.getAttribute("TargetMode");m&&w&&k&&f.rels.set(m,new mt(m,k,w,b==="External"));}}return new kr(i,f)}relateTo(e,n){let r=1;for(;this.part.rels.has(`rId${r}`);)r++;let s=`rId${r}`,i=e.partname.split("/").pop();this.part.rels.set(s,new mt(s,n,i,false)),this.pkg.getOrCreateRelsPart(this.part.partname).addRelationship(s,n,i,false);}relateToExternal(e,n){let r=1;for(;this.part.rels.has(`rId${r}`);)r++;let s=`rId${r}`;return this.part.rels.set(s,new mt(s,n,e,true)),this.pkg.getOrCreateRelsPart(this.part.partname).addRelationship(s,n,e,true),s}async save(){for(let e of this.pkg.parts){let n=Ln(e._element.ownerDocument||e._element);n.includes("w16du:")&&!n.includes("xmlns:w16du=")&&(e._element.setAttribute("xmlns:w16du","http://schemas.microsoft.com/office/word/2023/wordml/word16du"),n=Ln(e._element.ownerDocument||e._element)),n.startsWith("<?xml")||(n=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
14
+ `+n),this.pkg.unzipped[e.partname.substring(1)]=ut(n),e.blob=n;let r=e._element.ownerDocument;r&&tt(r);}return Buffer.from(zn(this.pkg.unzipped))}},re=class{static{y(this,"Paragraph");}constructor(t,e){this._element=t,this._parent=e;}_element;_parent;get text(){let t="",e=this._element.getElementsByTagName("w:t");for(let n=0;n<e.length;n++)t+=e[n].textContent||"";return t}},Ae=class{static{y(this,"Run");}constructor(t,e){this._element=t,this._parent=e;}_element;_parent},ps=class{static{y(this,"Cell");}constructor(t,e){this._element=t,this._parent=e;}_element;_parent},_s=class{static{y(this,"Row");}constructor(t,e){this._element=t,this._parent=e;let n=this._element.getElementsByTagName("w:tc");for(let r=0;r<n.length;r++)this.cells.push(new ps(n[r],this));}_element;_parent;cells=[]},Te=class{static{y(this,"Table");}constructor(t,e){this._element=t,this._parent=e;let n=this._element.getElementsByTagName("w:tr");for(let r=0;r<n.length;r++)this.rows.push(new _s(n[r],this));}_element;_parent;rows=[]},Un=class{static{y(this,"NotesPart");}constructor(t,e){this.part=t,this.note_type=e,this._element=t._element;}part;note_type;_element},ms=class{static{y(this,"FootnoteItem");}constructor(t,e,n){this._element=t,this._parent=e,this.note_type=n,this.id=t.getAttribute("w:id")||"",this.part=e.part;}_element;_parent;note_type;id;part},ne={w:"http://schemas.openxmlformats.org/wordprocessingml/2006/main",w14:"http://schemas.microsoft.com/office/word/2010/wordml",w15:"http://schemas.microsoft.com/office/word/2012/wordml",w16cid:"http://schemas.microsoft.com/office/word/2016/wordml/cid",w16cex:"http://schemas.microsoft.com/office/word/2018/wordml/cex",mc:"http://schemas.openxmlformats.org/markup-compatibility/2006"},ie={COMMENTS:"application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",EXTENDED:"application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",IDS:"application/vnd.openxmlformats-officedocument.wordprocessingml.commentsIds+xml",EXTENSIBLE:"application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml"},xe={COMMENTS:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",EXTENDED:"http://schemas.microsoft.com/office/2011/relationships/commentsExtended",IDS:"http://schemas.microsoft.com/office/2016/09/relationships/commentsIds",EXTENSIBLE:"http://schemas.microsoft.com/office/2018/08/relationships/commentsExtensible"},Er=class extends Error{static{y(this,"CommentThreadingError");}constructor(t){super(t),this.name="CommentThreadingError";}},nt=class{static{y(this,"CommentsManager");}constructor(t){this.doc=t;}doc;_commentsPart=null;_extendedPart=null;_idsPart=null;_extensiblePart=null;_nextId=null;get commentsPart(){return this._commentsPart||(this._commentsPart=this._getOrCreateCommentsPart(),this._ensureNamespaces()),this._commentsPart}get extendedPart(){return this._extendedPart||(this._extendedPart=this._getOrCreateExtendedPart()),this._extendedPart}get idsPart(){return this._idsPart||(this._idsPart=this._getOrCreateIdsPart()),this._idsPart}get extensiblePart(){return this._extensiblePart||(this._extensiblePart=this._getOrCreateExtensiblePart()),this._extensiblePart}get nextId(){return this._nextId===null&&(this._nextId=this._getNextCommentId()),this._nextId}set nextId(t){this._nextId=t;}_getExistingPartByType(t){return this.doc.pkg.parts.find(e=>e.contentType===t)||null}_linkPart(t,e){for(let n of this.doc.part.rels.values())if(!n.isExternal&&n.target===t.partname.split("/").pop())return t;return this.doc.relateTo(t,e),t}_getOrCreateCommentsPart(){let t=this._getExistingPartByType(ie.COMMENTS);if(t)return this._linkPart(t,xe.COMMENTS);let e=this.doc.pkg.nextPartname("/word/comments%d.xml"),n=`<w:comments xmlns:w="${ne.w}" xmlns:w14="${ne.w14}" xmlns:w15="${ne.w15}" xmlns:w16cid="${ne.w16cid}" xmlns:w16cex="${ne.w16cex}" xmlns:mc="${ne.mc}" mc:Ignorable="w14 w15 w16cid w16cex"></w:comments>`;return t=this.doc.pkg.addPart(e,ie.COMMENTS,n),this.doc.relateTo(t,xe.COMMENTS),t}_getOrCreateExtendedPart(){let t=this._getExistingPartByType(ie.EXTENDED);if(t)return this._linkPart(t,xe.EXTENDED);let e=this.doc.pkg.nextPartname("/word/commentsExtended%d.xml"),n=`<w15:commentsEx xmlns:w15="${ne.w15}"></w15:commentsEx>`;return t=this.doc.pkg.addPart(e,ie.EXTENDED,n),this.doc.relateTo(t,xe.EXTENDED),t}_getOrCreateIdsPart(){let t=this._getExistingPartByType(ie.IDS);if(t)return this._linkPart(t,xe.IDS);let e=this.doc.pkg.nextPartname("/word/commentsIds%d.xml"),n=`<w16cid:commentsIds xmlns:w16cid="${ne.w16cid}"></w16cid:commentsIds>`;return t=this.doc.pkg.addPart(e,ie.IDS,n),this.doc.relateTo(t,xe.IDS),t}_getOrCreateExtensiblePart(){let t=this._getExistingPartByType(ie.EXTENSIBLE);if(t)return this._linkPart(t,xe.EXTENSIBLE);let e=this.doc.pkg.nextPartname("/word/commentsExtensible%d.xml"),n=`<w16cex:commentsExtensible xmlns:w16cex="${ne.w16cex}"></w16cex:commentsExtensible>`;return t=this.doc.pkg.addPart(e,ie.EXTENSIBLE,n),this.doc.relateTo(t,xe.EXTENSIBLE),t}_ensureNamespaces(){let t=this._commentsPart?._element;if(!t)return;let e=[["xmlns:w",ne.w],["xmlns:w14",ne.w14],["xmlns:w15",ne.w15],["xmlns:w16cid",ne.w16cid],["xmlns:w16cex",ne.w16cex],["xmlns:mc",ne.mc]];for(let[n,r]of e)t.getAttribute(n)||t.setAttribute(n,r);}_getNextCommentId(){let t=[0],e=this._getExistingPartByType(ie.COMMENTS);if(e){let n=$(e._element,"w:comment");for(let r of n){let s=r.getAttribute("w:id");s&&t.push(parseInt(s,10)||0);}}return Math.max(...t)+1}_generateHexId(){return Math.floor(Math.random()*4294967295).toString(16).toUpperCase().padStart(8,"0")}_generateDurableId(){return Math.floor(Math.random()*2147483648).toString(16).toUpperCase().padStart(8,"0")}_getInitials(t){return t?t.split(" ").filter(Boolean).map(e=>e[0]).join("").toUpperCase():""}_hasCommentsPart(){return this._commentsPart!==null||this._getExistingPartByType(ie.COMMENTS)!==null}_findParaIdForComment(t){if(!this._hasCommentsPart())return null;for(let e of $(this.commentsPart._element,"w:comment"))if(e.getAttribute("w:id")===t)for(let n of $(e,"w:p")){let r=n.getAttribute("w14:paraId");if(r)return r}return null}_findThreadRootParaId(t){let e=this._findParaIdForComment(t),n=this._getExistingPartByType(ie.EXTENDED);if(!e||!n)return e;for(let r=0;r<n._element.childNodes.length;r++){let s=n._element.childNodes[r];if(s.nodeType===1&&s.getAttribute("w15:paraId")===e){let i=s.getAttribute("w15:paraIdParent");if(i)return i}}return e}_adoptIntoModernComments(t){if(!this._hasCommentsPart())return null;let e=null;for(let i of $(this.commentsPart._element,"w:comment"))if(i.getAttribute("w:id")===t){e=i;break}if(!e)return null;let n=$(e,"w:p");if(n.length===0)return null;let r=null;for(let i of n){let o=i.getAttribute("w14:paraId");if(o){r=o;break}}r||(r=this._generateHexId(),n[0].setAttribute("w14:paraId",r));let s=y((i,o)=>{for(let a=0;a<i._element.childNodes.length;a++){let l=i._element.childNodes[a];if(l.nodeType===1&&l.getAttribute(o)===r)return true}return false},"hasChild");if(!s(this.extendedPart,"w15:paraId")){let o=this.extendedPart._element.ownerDocument.createElement("w15:commentEx");o.setAttribute("w15:paraId",r),o.setAttribute("w15:done","0"),this.extendedPart._element.appendChild(o);}if(!s(this.idsPart,"w16cid:paraId")){let o=this.idsPart._element.ownerDocument.createElement("w16cid:commentId");o.setAttribute("w16cid:paraId",r),o.setAttribute("w16cid:durableId",this._generateDurableId()),this.idsPart._element.appendChild(o);}return r}resolveThreadParentParaId(t){let e=this._findThreadRootParaId(t),n=this._adoptIntoModernComments(t);return e??n}addComment(t,e,n=null){let r=this._getExistingPartByType(ie.EXTENDED)!==null,s=null;if(n!=null&&(s=this.resolveThreadParentParaId(n),!s))throw new Er(`Cannot thread a reply onto comment Com:${n}: the comment has no resolvable paragraph identity (w14:paraId) in word/comments.xml, so Word would render the reply as a separate top-level comment instead of a reply. Refusing to create an unthreaded comment.`);let i=this.nextId.toString();this.nextId++;let o=new Date().toISOString().replace(/\.\d{3}Z$/,"Z"),a=this.commentsPart._element.ownerDocument,l=a.createElement("w:comment");l.setAttribute("w:id",i),l.setAttribute("w:author",t),l.setAttribute("w:date",o);let u=this._getInitials(t);u&&l.setAttribute("w:initials",u),n&&!r&&l.setAttribute("w15:p",n);let c=this._generateHexId(),d=this._generateHexId(),f=a.createElement("w:p");f.setAttribute("w14:paraId",c),f.setAttribute("w14:textId","77777777"),f.setAttribute("w:rsidR",d),f.setAttribute("w:rsidRDefault",d),f.setAttribute("w:rsidP",d);let h=a.createElement("w:pPr"),_=a.createElement("w:pStyle");_.setAttribute("w:val","CommentText"),h.appendChild(_),f.appendChild(h);let p=a.createElement("w:r"),m=a.createElement("w:rPr"),w=a.createElement("w:rStyle");w.setAttribute("w:val","CommentReference"),m.appendChild(w),p.appendChild(m),p.appendChild(a.createElement("w:annotationRef")),f.appendChild(p);let k=a.createElement("w:r"),b=a.createElement("w:t");if(b.textContent=e,k.appendChild(b),f.appendChild(k),l.appendChild(f),this.commentsPart._element.appendChild(l),this.extendedPart){let v=this.extendedPart._element.ownerDocument.createElement("w15:commentEx");v.setAttribute("w15:paraId",c),s&&v.setAttribute("w15:paraIdParent",s),v.setAttribute("w15:done","0"),this.extendedPart._element.appendChild(v);}if(this.idsPart){let v=this.idsPart._element.ownerDocument.createElement("w16cid:commentId");v.setAttribute("w16cid:paraId",c),v.setAttribute("w16cid:durableId",this._generateDurableId()),this.idsPart._element.appendChild(v);}if(this.extensiblePart){let g=null;for(let v=0;v<this.idsPart._element.childNodes.length;v++){let x=this.idsPart._element.childNodes[v];if(x.nodeType===1&&x.getAttribute("w16cid:paraId")===c){g=x.getAttribute("w16cid:durableId");break}}if(g){let x=this.extensiblePart._element.ownerDocument.createElement("w16cex:commentExtensible");x.setAttribute("w16cex:durableId",g),x.setAttribute("w16cex:dateUtc",o),this.extensiblePart._element.appendChild(x);}}return i}deleteComment(t){if(!this.commentsPart)return;let e=null;for(let r of $(this.commentsPart._element,"w:comment"))if(r.getAttribute("w:id")===t){e=r;break}if(!e)return;let n=null;for(let r of $(e,"w:p")){let s=r.getAttribute("w14:paraId");if(s){n=s;break}}if(n){let r=[];if(this.extendedPart)for(let i=0;i<this.extendedPart._element.childNodes.length;i++){let o=this.extendedPart._element.childNodes[i];if(o.nodeType===1&&o.getAttribute("w15:paraIdParent")===n){let a=o.getAttribute("w15:paraId");if(a){for(let l of $(this.commentsPart._element,"w:comment"))for(let u of $(l,"w:p"))if(u.getAttribute("w14:paraId")===a){let c=l.getAttribute("w:id");c&&r.push(c);break}}}}for(let i of r)this.deleteComment(i);let s=null;if(this.idsPart){let i=[];for(let o=0;o<this.idsPart._element.childNodes.length;o++){let a=this.idsPart._element.childNodes[o];a.nodeType===1&&a.getAttribute("w16cid:paraId")===n&&(s=a.getAttribute("w16cid:durableId"),i.push(a));}i.forEach(o=>this.idsPart._element.removeChild(o));}if(this.extendedPart){let i=[];for(let o=0;o<this.extendedPart._element.childNodes.length;o++){let a=this.extendedPart._element.childNodes[o];a.nodeType===1&&a.getAttribute("w15:paraId")===n&&i.push(a);}i.forEach(o=>this.extendedPart._element.removeChild(o));}if(s&&this.extensiblePart){let i=[];for(let o=0;o<this.extensiblePart._element.childNodes.length;o++){let a=this.extensiblePart._element.childNodes[o];a.nodeType===1&&a.getAttribute("w16cex:durableId")===s&&i.push(a);}i.forEach(o=>this.extensiblePart._element.removeChild(o));}}e.parentNode&&e.parentNode.removeChild(e);}};function Re(t){({part:t.mainDocumentPart,relateTo:y(()=>{},"relateTo")});let r={},s=t.parts.find(l=>l.contentType===ie.COMMENTS);if(!s)return r;let i={},o=$(s._element,"w:comment");for(let l of o){let u=l.getAttribute("w:id");if(!u)continue;let c=l.getAttribute("w:author")||"Unknown",d=l.getAttribute("w:date")||"",f=false,h=l.getAttribute("w15:done");(h==="1"||h==="true"||h==="on")&&(f=true);let _=l.getAttribute("w15:p")||null,p=$(l,"w:p");for(let k of p){let b=k.getAttribute("w14:paraId");b&&(i[b]=u);}let m=[];for(let k of p){let b=$(k,"w:t");for(let g of b)g.textContent&&m.push(g.textContent);m.push(`
15
+ `);}let w=m.join("").trim();r[u]={author:c,text:w,date:d,resolved:f,parent_id:_};}let a=t.parts.find(l=>l.contentType===ie.EXTENDED);if(a){let l=a._element.childNodes;for(let u=0;u<l.length;u++){let c=l[u];if(c.nodeType!==1)continue;let d=c.getAttribute("w15:paraId"),f=c.getAttribute("w15:paraIdParent"),h=c.getAttribute("w15:done");if(d){let _=i[d];if(_&&r[_]){if(f){let p=i[f];p&&(r[_].parent_id=p);}(h==="1"||h==="true"||h==="on")&&(r[_].resolved=true);}}}}return r}y(Re,"extract_comments_data");var qt=500,Le=200,gs=["{++","++}","{--","--}","{==","==}","{>>","<<}"];function Cr(t){if(!t||!t.includes("{")&&!t.includes("}"))return t;for(let e of gs)if(t.includes(e)){let n=e.startsWith("{")?"{ "+e.slice(1):e.slice(0,-1)+" }";t=t.split(e).join(n);}return t}y(Cr,"escape_critic_tokens");function he(t,e){if(t==null||t.length<=e)return t;let n=Math.max(1,Math.floor(e*2/3)),r=Math.max(1,e-n),s=t.length-n-r;return `${t.slice(0,n)}\u2026 [${s.toLocaleString("en-US")} chars omitted] \u2026${t.slice(-r)}`}y(he,"truncate_middle");var ws={"\u201C":'"',"\u201D":'"',"\u2018":"'","\u2019":"'"},ys=/[\u201c\u201d\u2018\u2019]/g;function qn(t){return t&&t.replace(ys,e=>ws[e])}y(qn,"normalize_smart_quotes");function Vt(t){return !!t&&/[\u201c\u201d\u2018\u2019]/.test(t)}y(Vt,"has_smart_quotes");function vs(t,e){if(!t||!e||!Vt(t))return e;let n=qn(t),r=qn(e);if(n===r)return t;let i=new Ar.diff_match_patch().diff_main(n,r),o=[],a=0,l=0;for(let[u,c]of i)u===0?(o.push(t.substr(a,c.length)),a+=c.length,l+=c.length):u===-1?a+=c.length:(o.push(e.substr(l,c.length)),l+=c.length);return o.join("")}y(vs,"restore_document_typography");function bs(t,e,n){return !n||!t||!Vt(t)||Vt(e||"")?n:vs(t,n)}y(bs,"restore_matched_typography");var cn=2e3,Ce=class extends Error{static{y(this,"RegexTimeoutError");}pattern;constructor(t){super(`Regular expression exceeded the ${cn/1e3}s matching time budget (catastrophic backtracking). Simplify the pattern \u2014 nested quantifiers like (a+)+ are the usual cause \u2014 or use a literal target instead.`),this.name="RegexTimeoutError",this.pattern=t;}};function Pr(t){let e=false,n=false,r=[];for(let s=0;s<t.length;s++){let i=t[s];if(n){n=false;continue}if(i==="\\"){n=true;continue}if(e){i==="]"&&(e=false);continue}if(i==="["){e=true;continue}if(i==="("){r.push({hasInnerQuantifierOrPipe:false});continue}if(i===")"){if(r.length>0){let o=r.pop(),a=t.substring(s+1),l=a.match(/^(\*|\+|\{\d+\,\s*\}|\?)/),u=l?l[1]:"",c=u==="*"||u==="+"||/^\{\d+\,\s*\}/.test(a);if(c&&o.hasInnerQuantifierOrPipe)return true;r.length>0&&(o.hasInnerQuantifierOrPipe||c)&&(r[r.length-1].hasInnerQuantifierOrPipe=true);}continue}r.length>0&&(i==="|"||i==="*"||i==="+"||/^\{\d+\,\s*\}/.test(t.substring(s)))&&(r[r.length-1].hasInnerQuantifierOrPipe=true);}return false}y(Pr,"hasCatastrophicBacktrackingRisk");function xs(t,e,n=""){if(Pr(t))throw new Ce(t);let r=n.includes("g")?n:n+"g",s=new RegExp(t,r),i=Date.now(),o=[],a;for(;(a=s.exec(e))!==null;){if(Date.now()-i>cn)throw new Ce(t);o.push({start:a.index,end:a.index+a[0].length}),a.index===s.lastIndex&&s.lastIndex++;}return o}y(xs,"userFindAllMatches");function Ns(t,e,n=""){if(Pr(t))throw new Ce(t);let r=new RegExp(t,n.replace("g","")),s=Date.now(),i=r.exec(e);if(Date.now()-s>cn)throw new Ce(t);return i?{start:i.index,end:i.index+i[0].length}:null}y(Ns,"userSearch");var ks="w:p",Tr="w:r",un="w:t",Es="w:delText",As="w:tab",Cs="w:br",Ps="w:cr",dn="w:rPr",Ts="w:rPrChange",Ss="w:commentReference",Is="w:footnoteReference",$s="w:endnoteReference",Os="w:fldChar",Ds="w:fldCharType",Ms="w:instrText",Rs="w:ins",js="w:del",Ne="w:id",Jt="w:author",Ht="w:date",Fs="w:commentRangeStart",Bs="w:commentRangeEnd",Ws="w:hyperlink",zs="r:id",Ls="w:fldSimple",Us="w:instr",qs="w:bookmarkStart",Js="w:name",Sr="w:sdt",Hs="w:smartTag",Ir="w:sdtContent",$r="w:b",Xs="w:i",ae="w:val",Or="w:pPr",Dr="w:pStyle",Mr="w:outlineLvl",Qs="w:numPr",Ys="w:numId",Gs="w:ilvl",Zt="w:drawing",Kt="w:object",en="w:pict",Vs="wp:docPr",Zs="v:imagedata",Ks="o:title",eo="w:txbxContent",to="mc:AlternateContent",no="mc:Choice",ro="mc:Fallback",Jn=300;function Hn(t){let e=[];for(let r of $(t,eo))for(let s of $(r,un))s.textContent&&e.push(s.textContent);let n=e.join(" ").split(/\s+/).filter(Boolean).join(" ");return n.length>Jn&&(n=n.slice(0,Jn).trimEnd()+"\u2026"),n}y(Hn,"_textbox_text");function*Xn(t){let e=t.tagName;if(e===Zt||e===Kt){let n=$(t,Vs)[0]||null,r="",s="0";n&&(r=n.getAttribute("descr")||n.getAttribute("title")||"",s=n.getAttribute("id")||"0");let i=Hn(t);i&&(r=r?`Text box (${r}): ${i}`:`Text box: ${i}`),yield {type:"image",id:s,date:r};}else if(e===en){let n=$(t,Zs)[0]||null,r=n&&n.getAttribute(Ks)||"",s=Hn(t);s&&(r=r?`Text box (${r}): ${s}`:`Text box: ${s}`),(s||n)&&(yield {type:"image",id:"vml",date:r});}}y(Xn,"_graphic_marker_events");var io=/Heading[ ]?([1-6])(?![0-9])/;function so(t){let e=t,n=new Set;for(;e&&!n.has(e);){if(n.add(e),e.package)return e.package;if(e.pkg)return e.pkg;if(e.part&&(e.part.package||e.part.pkg))return e.part.package||e.part.pkg;e=e._parent||e.part||null;}return null}y(so,"_resolve_package");function st(t){let e=t.package||t.pkg||(t.part?t.part.pkg:null);if(e&&e._adeu_style_cache)return e._adeu_style_cache;let n={},r=null,s={},i=e?.getPartByPath("word/styles.xml");if(!i){let u=[n,null];return e&&(e._adeu_style_cache=u),u}let o=$(i._element,"w:style");for(let u of o){let c=u.getAttribute("w:styleId");if(!c)continue;let d=u.getAttribute("w:type"),f=u.getAttribute("w:default")==="1"||u.getAttribute("w:default")==="true";d==="paragraph"&&f&&(r=c);let h=M(u,"w:name"),_=h?h.getAttribute("w:val"):c;_&&typeof _=="string"&&(_.toLowerCase().startsWith("heading")?_=_.replace(/^heading/i,"Heading"):_.toLowerCase()==="title"&&(_="Title"));let p=M(u,"w:basedOn"),m=p?p.getAttribute("w:val"):null,w=null,k=null,b=null,g=M(u,"w:pPr");if(g){let E=M(g,"w:outlineLvl");if(E){let A=E.getAttribute("w:val");A&&/^\d+$/.test(A)&&(w=parseInt(A,10));}let C=M(g,"w:numPr");if(C){let A=M(C,"w:numId");if(A){let P=A.getAttribute("w:val");P&&P!=="0"&&(k=P);}let N=M(C,"w:ilvl");if(N){let P=N.getAttribute("w:val");P&&/^\d+$/.test(P)&&(b=parseInt(P,10));}}}let v=null,x=M(u,"w:rPr");if(x){let E=M(x,"w:b");if(E){let C=E.getAttribute("w:val");v=C!=="0"&&C!=="false"&&C!=="off";}}s[c]={name:_,based_on:m,outline_level:w,bold:v,num_id:k,num_ilvl:b};}let a=y((u,c)=>{if(n[u])return n[u];if(c.has(u)||!s[u])return {name:u,outline_level:null,bold:false,num_id:null,num_ilvl:null};c.add(u);let d=s[u],f=d.based_on,h=d.outline_level,_=d.bold!==null?d.bold:false,p=d.num_id,m=d.num_ilvl;if(f){let k=a(f,c);h===null&&(h=k.outline_level),d.bold===null&&(_=k.bold),p===null&&(p=k.num_id??null),m===null&&(m=k.num_ilvl??null);}let w={name:d.name,outline_level:h,bold:_,num_id:p,num_ilvl:m};return n[u]=w,w},"resolve_style");for(let u in s)a(u,new Set);let l=[n,r];return e&&(e._adeu_style_cache=l),l}y(st,"_get_style_cache");function oo(t){let e=so(t);if(!e)return {};if(e._adeu_numbering_cache)return e._adeu_numbering_cache;let n={},r=null;try{let s=(e.parts||[]).find(i=>String(i.partname).endsWith("/numbering.xml"));s&&(r=s._element);}catch{r=null;}if(r){let s={};for(let i of $(r,"w:abstractNum")){let o=i.getAttribute("w:abstractNumId");if(o===null)continue;let a={};for(let l of $(i,"w:lvl")){let u=l.getAttribute("w:ilvl"),c=M(l,"w:numFmt");if(u!==null&&/^-?\d+$/.test(u)&&c){let d=c.getAttribute("w:val");d&&(a[parseInt(u,10)]=d);}}s[o]=a;}for(let i of $(r,"w:num")){let o=i.getAttribute("w:numId"),a=M(i,"w:abstractNumId");if(o===null||!a)continue;let l=a.getAttribute("w:val");l!==null&&s[l]!==void 0&&(n[o]=s[l]);}}return e._adeu_numbering_cache=n,n}y(oo,"_get_numbering_cache");function ao(t,e,n){let r=null;if(e!=null){let s=oo(t)[e];if(s&&Object.keys(s).length>0&&(r=s[n]!==void 0?s[n]:null,r===null)){for(let i=n;i>=0;i--)if(s[i]!==void 0){r=s[i];break}}}return r!==null&&r!=="bullet"?"1. ":"* "}y(ao,"get_list_marker");function Rr(t){if(!t)return null;let e=t.match(io);return e?parseInt(e[1],10):null}y(Rr,"_detect_heading_level_from_name");function fn(t,e,n){e||([e,n]=st(t._parent.part||t._parent));let r=M(t._element,Or);if(r){let a=M(r,Mr);if(a){let l=a.getAttribute(ae);if(l&&/^\d+$/.test(l)){let u=parseInt(l,10);if(u>=0&&u<=8)return true}}}let s=n;if(r){let a=M(r,Dr);a&&(s=a.getAttribute(ae)||n);}let i=s&&e?e[s]:null;if(i&&i.outline_level!==null&&i.outline_level>=0&&i.outline_level<=8)return true;let o=i?i.name:s;return o&&typeof o=="string"&&o.toLowerCase().startsWith("heading")&&(o=o.replace(/^heading/i,"Heading")),!!(o?.startsWith("Heading")||o==="Title"||o&&o!=="Normal"&&Rr(o)!==null)}y(fn,"is_native_heading");function Se(t,e,n){e||([e,n]=st(t._parent.part||t._parent));let r=M(t._element,Or);if(r){let c=M(r,Mr);if(c){let d=c.getAttribute(ae);if(d&&/^\d+$/.test(d)){let f=parseInt(d,10);if(f>=0&&f<=8)return "#".repeat(f+1)+" "}}}let s=n;if(r){let c=M(r,Dr);c&&(s=c.getAttribute(ae)||n);}let i=s&&e?e[s]:null;if(i&&i.outline_level!==null&&i.outline_level>=0&&i.outline_level<=8)return "#".repeat(i.outline_level+1)+" ";let o=i?i.name:s;if(o&&typeof o=="string"&&o.toLowerCase().startsWith("heading")&&(o=o.replace(/^heading/i,"Heading")),o?.startsWith("Heading")){let c=o.replace("Heading","").trim();if(/^\d+$/.test(c))return "#".repeat(parseInt(c,10))+" "}if(o==="Title")return "# ";let a=null,l=null,u=false;if(r){let c=M(r,Qs);if(c){let d=M(c,Ys);if(d){let f=d.getAttribute(ae);if(f==="0")u=true;else if(f){a=f;let h=M(c,Gs);if(h){let _=h.getAttribute(ae);_!==null&&/^\d+$/.test(_)&&(l=parseInt(_,10));}}}}}if(a===null&&!u&&i){let c=i.num_id;c&&(a=c,l===null&&(l=i.num_ilvl!==void 0?i.num_ilvl:null));}if(a!==null){let c=l!==null?l:0,d=ao(t._parent?t._parent.part||t._parent:null,a,c);return " ".repeat(c)+d}if(o&&o!=="Normal"){let c=Rr(o);if(c!==null)return "#".repeat(c)+" "}if(!o||o==="Normal"){let c=false,d=t._element;for(;d;){if(d.tagName==="w:tc"){c=true;break}d=d.parentNode;}if(c)return "";let f=t.text.trim();if(f&&f.length<100&&f===f.toUpperCase()){let h=false;if(i?.bold)h=true;else {let _=$(t._element,Tr);for(let p of _)if($(p,un).map(k=>k.textContent||"").join("").trim()){let k=M(p,dn);if(k){let b=M(k,$r);b&&b.getAttribute(ae)!=="0"&&b.getAttribute(ae)!=="false"&&(h=true);}break}}if(h)return "## "}}return ""}y(Se,"get_paragraph_prefix");function jr(t,e,n){let r=Se(t,e,n);if(!r)return false;let s=r.trimEnd();return s.length>0&&s==="#".repeat(s.length)}y(jr,"is_heading_paragraph");function Fr(t,e=null){let n="",r="",s=M(t._element,dn),i=false,o=false;if(s){let a=M(s,$r);a&&a.getAttribute(ae)!=="0"&&a.getAttribute(ae)!=="false"&&(i=true);let l=M(s,Xs);l&&l.getAttribute(ae)!=="0"&&l.getAttribute(ae)!=="false"&&(o=true);}if(e===null){let a=t._parent;e=a instanceof re?fn(a):false;}return i&&!e&&(n+="**",r="**"+r),o&&(n+="_",r="_"+r),[n,r]}y(Fr,"get_run_style_markers");function Br(t){let e=t.trim();if(!e)return ["","",t];let n=t.length-t.trimStart().length;return [t.substring(0,n),t.substring(n,n+e.length),t.substring(n+e.length)]}y(Br,"split_boundary_whitespace");function Wr(t){let e=[],n=[],r=new Set;for(let[i,o]of t){let a=Object.entries(i),l=Object.entries(o);if(a.length===0&&l.length===0){n.length>0&&(e.push(n),n=[]);continue}let u=[];for(let[c,d]of a)r.has(c)||u.push([c,d&&d.author||"Unknown"]);for(let[c,d]of l)r.has(c)||u.push([c,d&&d.author||"Unknown"]);for(let[c,d]of u)r.add(c),n.length>0&&n[n.length-1][1]!==d&&(e.push(n),n=[]),n.push([c,d]);}n.length>0&&e.push(n);let s={};for(let i of e)if(!(i.length<2))for(let[o]of i)s[o]=i.filter(([a])=>a!==o).map(([a])=>`Chg:${a}`).join(", ");return s}y(Wr,"compute_change_pair_map");function lo(t,e,n){if(!e&&!n)return t;if(!t)return "";let r=y(i=>{let[o,a,l]=Br(i);return a?`${o}${e}${a}${n}${l}`:i},"wrap");return t.includes(`
16
16
  `)?t.split(`
17
17
  `).map(i=>i?r(i):"").join(`
18
- `):r(t)}y(eo,"apply_formatting_to_segments");function De(t){let e="";for(let n=0;n<t._element.childNodes.length;n++){let r=t._element.childNodes[n];if(r.nodeType===1)if(r.tagName===an||r.tagName===gs){let s=r.textContent||"";e+=s.replace(/\t/g," ");}else r.tagName===ws?e+=" ":(r.tagName===ys||r.tagName===vs)&&(e+=`
19
- `);}return e}y(De,"get_run_text");function*Ie(t){let e=t._element||t.element||t;if(t.constructor.name==="NotesPart"){let n=t.note_type==="fn"?"w:footnote":"w:endnote",r=I(e,n);for(let s of r){if(s.getAttribute("w:type")==="separator"||s.getAttribute("w:type")==="continuationSeparator")continue;let i=s.getAttribute("w:id");i!==null&&/^\s*[-+]?\d+\s*$/.test(i)&&parseInt(i,10)<=0||(yield new fs(s,t,t.note_type));}return}yield*jr(e,t);}y(Ie,"iter_block_items");function*jr(t,e){for(let n=0;n<t.childNodes.length;n++){let r=t.childNodes[n];if(r.nodeType===1){if(r.tagName===ms)yield new re(r,e);else if(r.tagName==="w:tbl")yield new Te(r,e);else if(r.tagName===Ar){let s=M(r,Cr);s&&(yield*jr(s,e));}}}}y(jr,"_iter_block_children");function*to(t){for(let[e]of un(t))yield e;}y(to,"iter_document_parts");function*un(t){let e=t.pkg.parts.filter(i=>i.contentType==="application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml");for(let i of e)yield [i,"header"];yield [t,"body"];let n=t.pkg.parts.filter(i=>i.contentType==="application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml");for(let i of n)yield [i,"footer"];let r=t.pkg.getPartByPath("word/footnotes.xml"),s=t.pkg.getPartByPath("word/endnotes.xml");r&&(yield [new Ln(r,"fn"),"footnotes"]),s&&(yield [new Ln(s,"en"),"endnotes"]);}y(un,"iter_document_parts_with_kind");function no(t){if(!t)return false;let e=t.toUpperCase().trim().split(/\s+/);return e.length>0&&(e[0]==="PAGE"||e[0]==="NUMPAGES")}y(no,"_is_page_instr");function Fr(t){return t?t.part?t.part:t.pkg&&t.pkg.mainDocumentPart?t.pkg.mainDocumentPart:t._parent?Fr(t._parent):null:null}y(Fr,"_get_part");function*Nt(t){let e=false,n="",r=false;function*s(o){let l=null,a=M(o,ln);if(a){let u=M(a,bs);u&&(l=u.getAttribute(Ne),yield {type:"fmt_start",id:l,author:u.getAttribute(Ut)||void 0,date:u.getAttribute(qt)||void 0});}for(let u=0;u<o.childNodes.length;u++){let c=o.childNodes[u];if(c.nodeType!==1)continue;let d=c.tagName;if(d===Yt||d===Gt||d===Vt)yield*Jn(c);else if(d===Xs){let f=null;for(let h of [Qs,Ys]){for(let p of wr(c,h))if(f=M(p,Yt)||M(p,Gt)||M(p,Vt),f)break;if(f)break}f&&(yield*Jn(f));}else if(d===xs){let f=c.getAttribute(Ne);f&&(yield {type:"ref",id:f});}else if(d===Ns){let f=c.getAttribute(Ne);f&&(yield {type:"footnote",id:f});}else if(d===ks){let f=c.getAttribute(Ne);f&&(yield {type:"endnote",id:f});}else if(d===Es){let f=c.getAttribute(As);if(f==="begin")e=true,n="";else if(f==="separate")if(no(n))r=true;else {let h=n.trim().split(/\s+/);h.length>1&&h[0]==="REF"&&(yield {type:"xref_start",id:h[1]});}else if(f==="end"){if(!r){let h=n.trim().split(/\s+/);h.length>1&&h[0]==="REF"&&(yield {type:"xref_end",id:h[1]});}e=false,n="",r=false;}}else d===Cs&&e&&!r&&(n+=c.textContent||"");}r||(yield new Ae(o,t)),l!==null&&(yield {type:"fmt_end",id:l});}y(s,"process_run_element");function*i(o){for(let l=0;l<o.childNodes.length;l++){let a=o.childNodes[l];if(a.nodeType!==1)continue;let u=a.tagName;if(u===Er)yield*s(a);else if(u===Ps){let c=a.getAttribute(Ne);yield {type:"ins_start",id:c,author:a.getAttribute(Ut)||void 0,date:a.getAttribute(qt)||void 0},yield*i(a),yield {type:"ins_end",id:c};}else if(u===Ts){let c=a.getAttribute(Ne);yield {type:"del_start",id:c,author:a.getAttribute(Ut)||void 0,date:a.getAttribute(qt)||void 0},yield*i(a),yield {type:"del_end",id:c};}else if(u===Ss)yield {type:"start",id:a.getAttribute(Ne)};else if(u===Is)yield {type:"end",id:a.getAttribute(Ne)};else if(u===$s){let c=a.getAttribute(Os)||a.getAttribute("id"),d="",f=Fr(t._parent);if(c&&f){let h=f.rels.get(c);h&&h.isExternal&&(d=h.target);}d&&(yield {type:"hyperlink_start",id:c,date:d}),yield*i(a),d&&(yield {type:"hyperlink_end",id:c,date:d});}else if(u===Ds){let d=(a.getAttribute(Ms)||"").trim().split(/\s+/),f=d.length>1&&d[0]==="REF"?d[1]:"";f&&(yield {type:"xref_start",id:f}),yield*i(a),f&&(yield {type:"xref_end",id:f});}else if(u===Rs){let c=a.getAttribute(js);c&&(!c.startsWith("_")||c.startsWith("_Ref"))&&(yield {type:"bookmark",id:c});}else (u===Ar||u===Fs||u===Cr)&&(yield*i(a));}}y(i,"traverse_node"),yield*i(t._element);}y(Nt,"iter_paragraph_content");var ro=new Set(["**","__","*","_"]),ke=class{static{y(this,"DocumentMapper");}doc;clean_view;original_view;comments_map;full_text="";spans=[];appendix_start_index=-1;part_ranges=[];_current_part_index=0;_text_chunks=[];_plain_projection=null;constructor(t,e=false,n=false){this.doc=t,this.clean_view=e,this.original_view=n,this.comments_map=Xe(t.pkg),this._build_map();}_build_map(){let t=0;this.spans=[],this._text_chunks=[],this.full_text="",this._plain_projection=null,this.part_ranges=[],this._current_part_index=0;let e=0;for(let[n,r]of un(this.doc)){this._current_part_index=e;let s=t;t=this._map_blocks(n,t),this.part_ranges.push([s,t,r]),this.spans.length>0&&this.spans[this.spans.length-1].text!==`
18
+ `):r(t)}y(lo,"apply_formatting_to_segments");function De(t){let e="";for(let n=0;n<t._element.childNodes.length;n++){let r=t._element.childNodes[n];if(r.nodeType===1)if(r.tagName===un||r.tagName===Es){let s=r.textContent||"";e+=s.replace(/\t/g," ");}else r.tagName===As?e+=" ":(r.tagName===Cs||r.tagName===Ps)&&(e+=`
19
+ `);}return e}y(De,"get_run_text");function*Ie(t){let e=t._element||t.element||t;if(t.constructor.name==="NotesPart"){let n=t.note_type==="fn"?"w:footnote":"w:endnote",r=$(e,n);for(let s of r){if(s.getAttribute("w:type")==="separator"||s.getAttribute("w:type")==="continuationSeparator")continue;let i=s.getAttribute("w:id");i!==null&&/^\s*[-+]?\d+\s*$/.test(i)&&parseInt(i,10)<=0||(yield new ms(s,t,t.note_type));}return}yield*zr(e,t);}y(Ie,"iter_block_items");function*zr(t,e){for(let n=0;n<t.childNodes.length;n++){let r=t.childNodes[n];if(r.nodeType===1){if(r.tagName===ks)yield new re(r,e);else if(r.tagName==="w:tbl")yield new Te(r,e);else if(r.tagName===Sr){let s=M(r,Ir);s&&(yield*zr(s,e));}}}}y(zr,"_iter_block_children");function*co(t){for(let[e]of hn(t))yield e;}y(co,"iter_document_parts");function*hn(t){let e=t.pkg.parts.filter(i=>i.contentType==="application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml");for(let i of e)yield [i,"header"];yield [t,"body"];let n=t.pkg.parts.filter(i=>i.contentType==="application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml");for(let i of n)yield [i,"footer"];let r=t.pkg.getPartByPath("word/footnotes.xml"),s=t.pkg.getPartByPath("word/endnotes.xml");r&&(yield [new Un(r,"fn"),"footnotes"]),s&&(yield [new Un(s,"en"),"endnotes"]);}y(hn,"iter_document_parts_with_kind");function uo(t){if(!t)return false;let e=t.toUpperCase().trim().split(/\s+/);return e.length>0&&(e[0]==="PAGE"||e[0]==="NUMPAGES")}y(uo,"_is_page_instr");function Lr(t){return t?t.part?t.part:t.pkg&&t.pkg.mainDocumentPart?t.pkg.mainDocumentPart:t._parent?Lr(t._parent):null:null}y(Lr,"_get_part");function*Nt(t){let e=false,n="",r=false;function*s(o){let a=null,l=M(o,dn);if(l){let u=M(l,Ts);u&&(a=u.getAttribute(Ne),yield {type:"fmt_start",id:a,author:u.getAttribute(Jt)||void 0,date:u.getAttribute(Ht)||void 0});}for(let u=0;u<o.childNodes.length;u++){let c=o.childNodes[u];if(c.nodeType!==1)continue;let d=c.tagName;if(d===Zt||d===Kt||d===en)yield*Xn(c);else if(d===to){let f=null;for(let h of [no,ro]){for(let _ of vr(c,h))if(f=M(_,Zt)||M(_,Kt)||M(_,en),f)break;if(f)break}f&&(yield*Xn(f));}else if(d===Ss){let f=c.getAttribute(Ne);f&&(yield {type:"ref",id:f});}else if(d===Is){let f=c.getAttribute(Ne);f&&(yield {type:"footnote",id:f});}else if(d===$s){let f=c.getAttribute(Ne);f&&(yield {type:"endnote",id:f});}else if(d===Os){let f=c.getAttribute(Ds);if(f==="begin")e=true,n="";else if(f==="separate")if(uo(n))r=true;else {let h=n.trim().split(/\s+/);h.length>1&&h[0]==="REF"&&(yield {type:"xref_start",id:h[1]});}else if(f==="end"){if(!r){let h=n.trim().split(/\s+/);h.length>1&&h[0]==="REF"&&(yield {type:"xref_end",id:h[1]});}e=false,n="",r=false;}}else d===Ms&&e&&!r&&(n+=c.textContent||"");}r||(yield new Ae(o,t)),a!==null&&(yield {type:"fmt_end",id:a});}y(s,"process_run_element");function*i(o){for(let a=0;a<o.childNodes.length;a++){let l=o.childNodes[a];if(l.nodeType!==1)continue;let u=l.tagName;if(u===Tr)yield*s(l);else if(u===Rs){let c=l.getAttribute(Ne);yield {type:"ins_start",id:c,author:l.getAttribute(Jt)||void 0,date:l.getAttribute(Ht)||void 0},yield*i(l),yield {type:"ins_end",id:c};}else if(u===js){let c=l.getAttribute(Ne);yield {type:"del_start",id:c,author:l.getAttribute(Jt)||void 0,date:l.getAttribute(Ht)||void 0},yield*i(l),yield {type:"del_end",id:c};}else if(u===Fs)yield {type:"start",id:l.getAttribute(Ne)};else if(u===Bs)yield {type:"end",id:l.getAttribute(Ne)};else if(u===Ws){let c=l.getAttribute(zs)||l.getAttribute("id"),d="",f=Lr(t._parent);if(c&&f){let h=f.rels.get(c);h&&h.isExternal&&(d=h.target);}d&&(yield {type:"hyperlink_start",id:c,date:d}),yield*i(l),d&&(yield {type:"hyperlink_end",id:c,date:d});}else if(u===Ls){let d=(l.getAttribute(Us)||"").trim().split(/\s+/),f=d.length>1&&d[0]==="REF"?d[1]:"";f&&(yield {type:"xref_start",id:f}),yield*i(l),f&&(yield {type:"xref_end",id:f});}else if(u===qs){let c=l.getAttribute(Js);c&&(!c.startsWith("_")||c.startsWith("_Ref"))&&(yield {type:"bookmark",id:c});}else (u===Sr||u===Hs||u===Ir)&&(yield*i(l));}}y(i,"traverse_node"),yield*i(t._element);}y(Nt,"iter_paragraph_content");var fo=new Set(["**","__","*","_"]),ke=class{static{y(this,"DocumentMapper");}doc;clean_view;original_view;comments_map;full_text="";spans=[];appendix_start_index=-1;part_ranges=[];_current_part_index=0;_text_chunks=[];_plain_projection=null;constructor(t,e=false,n=false){this.doc=t,this.clean_view=e,this.original_view=n,this.comments_map=Re(t.pkg),this._build_map();}_build_map(){let t=0;this.spans=[],this._text_chunks=[],this.full_text="",this._plain_projection=null,this.part_ranges=[],this._current_part_index=0;let e=0;for(let[n,r]of hn(this.doc)){this._current_part_index=e;let s=t;t=this._map_blocks(n,t),this.part_ranges.push([s,t,r]),this.spans.length>0&&this.spans[this.spans.length-1].text!==`
20
20
 
21
21
  `&&(this._add_virtual_text(`
22
22
 
@@ -25,24 +25,24 @@
25
25
  `;)this.spans.pop(),this._text_chunks.pop();this.full_text=this._text_chunks.join(""),this.appendix_start_index=-1;}_nonempty_part_ranges(){let t=[];for(let e=0;e<this.part_ranges.length;e++){let[n,r,s]=this.part_ranges[e];r>n&&t.push([e,n,r,s]);}return t}part_kind_of(t){return t>=0&&t<this.part_ranges.length?this.part_ranges[t][2]:null}part_kind_at(t){for(let[,e,n,r]of this._nonempty_part_ranges())if(e<=t&&t<=n)return r;return null}part_boundary_at(t){let e=this._nonempty_part_ranges();for(let n=1;n<e.length;n++){let[r,,s]=e[n-1],[i,o]=e[n];if(s<t&&t<=o)return [r,i]}return null}_map_blocks(t,e){let n=e,r=t.constructor.name,s=t.part||t,[i,o]=st(s);if(r==="NotesPart"){let c=`---
26
26
  ${t.note_type==="fn"?"## Footnotes":"## Endnotes"}`;this._add_virtual_text(c,n,null),n+=c.length,this._add_virtual_text(`
27
27
 
28
- `,n,null),n+=2;}let l=true,a=null;for(let u of Ie(t))if(u.constructor.name==="FootnoteItem")n=this._map_blocks(u,n);else if(u instanceof re){if(!l){let f=a instanceof re?a:null;this._add_virtual_text(`
28
+ `,n,null),n+=2;}let a=true,l=null;for(let u of Ie(t))if(u.constructor.name==="FootnoteItem")n=this._map_blocks(u,n);else if(u instanceof re){if(!a){let f=l instanceof re?l:null;this._add_virtual_text(`
29
29
 
30
- `,n,f),n+=2;}let d=Se(u,i,o);l&&r==="FootnoteItem"&&(d=`[^${t.note_type}-${t.id}]: `+d),d&&(this._add_virtual_text(d,n,u),n+=d.length),n=this._map_paragraph_content(u,n,i,o),l=false,a=u;}else if(u instanceof Te){if(!l){let d=a instanceof re?a:null;this._add_virtual_text(`
30
+ `,n,f),n+=2;}let d=Se(u,i,o);a&&r==="FootnoteItem"&&(d=`[^${t.note_type}-${t.id}]: `+d),d&&(this._add_virtual_text(d,n,u),n+=d.length),n=this._map_paragraph_content(u,n,i,o),a=false,l=u;}else if(u instanceof Te){if(!a){let d=l instanceof re?l:null;this._add_virtual_text(`
31
31
 
32
- `,n,d),n+=2;}n=this._map_table(u,n),l=false,a=u;}return n}_map_table(t,e){let n=e,r=0;for(let s of t.rows){let i=s._element,o=M(i,"w:trPr"),l=o?M(o,"w:ins"):null,a=o?M(o,"w:del"):null;if(this.clean_view&&a||this.original_view&&l)continue;r>0&&(this._add_virtual_text(`
33
- `,n,null),n+=1),l&&!this.clean_view&&!this.original_view?(this._add_virtual_text("{++ ",n,null),n+=4):a&&!this.clean_view&&!this.original_view&&(this._add_virtual_text("{-- ",n,null),n+=4);let u=new Set,c=0;for(let d of s.cells){if(u.has(d))continue;u.add(d),c>0&&(this._add_virtual_text(" | ",n,null),n+=3);let f=n;if(n=this._map_blocks(d,n),!this.clean_view&&!this.original_view){let{paraId:h,firstP:p}=vr(d._element,n===f);if(h&&p){let _=new re(p,d);this._add_virtual_text("",n,_),n>f&&(this._add_virtual_text(" ",n,_),n+=1);let w=`{#cell:${h}}`;this._add_virtual_text(w,n,_),n+=w.length;}}c+=1;}if(l&&!this.clean_view&&!this.original_view){let d=` ++}{>>[Chg:${l.getAttribute("w:id")} insert] ${l.getAttribute("w:author")||"Unknown"}<<}`;this._add_virtual_text(d,n,null),n+=d.length;}else if(a&&!this.clean_view&&!this.original_view){let d=` --}{>>[Chg:${a.getAttribute("w:id")} delete] ${a.getAttribute("w:author")||"Unknown"}<<}`;this._add_virtual_text(d,n,null),n+=d.length;}if(r+=1,r===1){let d=new Set,f=0;for(let h of s.cells)d.has(h)||(d.add(h),f+=1);if(f>0){let h=Array(f).fill("---").join(" | ");this._add_virtual_text(`
34
- `,n,null),n+=1,this._add_virtual_text(h,n,null),n+=h.length;}}}return n}_strip_markdown_formatting(t){let e=t;return e=e.replace(/^#+\s*/gm,""),e=e.replace(/\*\*(\w[\w\s]*\w|\w{2,})\*\*/g,"$1"),e=e.replace(/__(\w[\w\s]*\w|\w{2,})__/g,"$1"),e=e.replace(/(?<!\w)_(\w[\w\s]*\w|\w{2,})_(?!\w)/g,"$1"),e=e.replace(/(?<!\w)\*(\w[\w\s]*\w|\w{2,})\*(?!\w)/g,"$1"),e}_map_paragraph_content(t,e,n,r){let s=e,i={start:s,end:s,text:"",run:null,paragraph:t,part_index:this._current_part_index};this.spans.push(i);let o=new Set,l={},a={},u={},c=[],d=["",""],f=["",""],h=null,p=[],_=y(()=>{if(p.length===0)return;let[m,v]=d;m&&(this._add_virtual_text(m,s,t),s+=m.length);for(let[N,A,C,x,E,T,D]of p){if(N==="virtual")this._add_virtual_text(A,s,t,h);else {let P={start:s,end:s+A.length,text:A,run:C,paragraph:t,ins_id:E||void 0,del_id:T||void 0,hyperlink_id:h||void 0,comment_ids:D.length>0?D:void 0,part_index:this._current_part_index,run_offset:x};this.spans.push(P),this._text_chunks.push(A);}s+=A.length;}v&&(this._add_virtual_text(v,s,t),s+=v.length),p=[];},"flush_pending_runs"),g=Array.from(Nt(t)),w=Or(t,n,r),k=cn(t,n,r),b=w;for(let m=0;m<g.length;m++){let v=g[m];if(v instanceof Ae){let[N,A]=Dr(v,k),C=[],x=De(v);if(b){if(x===""||/^\s*$/.test(x))continue;b=false;}let E=0,T=y($=>{let[S,j,F]=Mr($);if(!j){C.push(["real",$,v,E]),E+=$.length;return}S&&(C.push(["real",S,v,E]),E+=S.length),N&&C.push(["virtual",N,null,0]),C.push(["real",j,v,E]),E+=j.length,A&&C.push(["virtual",A,null,0]),F&&(C.push(["real",F,v,E]),E+=F.length);},"append_wrapped");if(x.includes(`
35
- `)&&(N||A)){let $=x.split(`
36
- `);for(let S=0;S<$.length;S++)S>0&&(C.push(["real",`
37
- `,v,E]),E+=1),$[S]&&T($[S]);}else (N||A)&&x?T(x):(N&&C.push(["virtual",N,null,0]),x&&C.push(["real",x,v,0]),A&&C.push(["virtual",A,null,0]));this.clean_view&&Object.keys(a).length>0,this.original_view&&Object.keys(l).length>0;let D=C.map($=>$[1]).join(""),P=Object.keys(l).pop()||null,R=Object.keys(a).pop()||null;if(D&&!(this.clean_view&&R)&&!(this.original_view&&P)){let $=this.clean_view||this.original_view?["",""]:this._get_wrappers(P,R,o,u),S=[N,A];if(p.length>0&&$[0]===d[0]&&$[1]===d[1]){let j=false;S[0]===f[0]&&S[1]===f[1]&&f[0]!==""&&p[p.length-1][0]==="virtual"&&p[p.length-1][1]===f[1]&&(p.pop(),j=true);let F=Array.from(o);for(let[B,L,U,Y]of C){if(j&&B==="virtual"&&L===S[0]){j=false;continue}p.push([B,L,U,Y,P,R,F]);}f=S;}else {_(),d=$,f=S;let j=Array.from(o);for(let[F,B,L,U]of C)p.push([F,B,L,U,P,R,j]);}}if(!this.clean_view&&!this.original_view){(Object.keys(l).length>0||Object.keys(a).length>0||o.size>0||Object.keys(u).length>0)&&c.push([{...l},{...a},new Set(o),{...u}]);let S=false;if(P!==null||R!==null||Object.keys(u).length>0||o.size>0){let F=m+1,B=false,L=Object.keys(l).length,U=Object.keys(a).length,Y=Object.keys(u).length,X=new Set(o);for(;F<g.length;){let J=g[F];if(J instanceof Ae){if(!De(J)){F++;continue}(L>0||U>0||Y>0||X.size>0)&&(B=true);break}else {let W=J;W.type==="ins_start"?L++:W.type==="ins_end"?L=Math.max(0,L-1):W.type==="del_start"?U++:W.type==="del_end"?U=Math.max(0,U-1):W.type==="fmt_start"?Y++:W.type==="fmt_end"?Y=Math.max(0,Y-1):W.type==="start"?X.add(W.id):W.type==="end"&&X.delete(W.id);}F++;}B&&(S=true);}if(!S&&c.length>0){let F=this._build_merged_meta_block(c);if(F){_(),d=["",""],f=["",""];let B=`{>>${F}<<}`;this._add_virtual_text(B,s,t),s+=B.length;}c=[];}}}else {let N=v;if(b=false,_(),d=["",""],f=["",""],N.type==="start")o.add(N.id);else if(N.type==="end")o.delete(N.id);else if(N.type==="ins_start")l[N.id]=N;else if(N.type==="ins_end")delete l[N.id];else if(N.type==="del_start")a[N.id]=N;else if(N.type==="del_end")delete a[N.id];else if(N.type==="fmt_start")u[N.id]=N;else if(N.type==="fmt_end")delete u[N.id];else if(N.type==="image"){if(!(this.clean_view&&Object.keys(a).length>0||this.original_view&&Object.keys(l).length>0)){let x=`![${(N.date||"image").replace(/\]/g,")").replace(/\n/g," ")}](docx-image:${N.id})`;this._add_virtual_text(x,s,t,null,true),s+=x.length;}}else if(N.type==="footnote"||N.type==="endnote"){_(),d=["",""],f=["",""];let C=`[^${N.type==="footnote"?"fn":"en"}-${N.id}]`;this._add_virtual_text(C,s,t),s+=C.length;}else if(N.type==="hyperlink_start")_(),d=["",""],f=["",""],this._add_virtual_text("[",s,t,N.id),s+=1,h=N.id;else if(N.type==="hyperlink_end"){_(),d=["",""],f=["",""];let A=`](${N.date})`;this._add_virtual_text(A,s,t,N.id),s+=A.length,h=null;}else if(N.type==="xref_start")_(),d=["",""],f=["",""],this._add_virtual_text("[~",s,t),s+=2;else if(N.type==="xref_end"){_(),d=["",""],f=["",""];let A=`~](#${N.id})`;this._add_virtual_text(A,s,t),s+=A.length;}else if(N.type==="bookmark"){_(),d=["",""],f=["",""];let A=`{#${N.id}}`;this._add_virtual_text(A,s,t),s+=A.length;}}}if(_(),c.length>0){let m=this._build_merged_meta_block(c);if(m){let v=`{>>${m}<<}`;this._add_virtual_text(v,s,t),s+=v.length;}}return s}_get_wrappers(t,e,n,r){return e?["{--","--}"]:t?["{++","++}"]:n.size>0||Object.keys(r).length>0?["{==","==}"]:["",""]}_build_merged_meta_block(t){let e=[],n=[],r=new Set,s=Rr(t),i=y(o=>s[o]?` (pairs with ${s[o]})`:"","pairSuffix");for(let[o,l,a,u]of t){for(let[d,f]of Object.entries(o)){let h=`Chg:${d}`;if(!r.has(h)){let p=f.author||"Unknown";e.push(`[${h} insert] ${p}${i(d)}`),r.add(h);}}for(let[d,f]of Object.entries(l)){let h=`Chg:${d}`;if(!r.has(h)){let p=f.author||"Unknown";e.push(`[${h} delete] ${p}${i(d)}`),r.add(h);}}for(let[d,f]of Object.entries(u)){let h=`Chg:${d}`;if(!r.has(h)){let p=f.author||"Unknown";e.push(`[${h} format] ${p}`),r.add(h);}}let c=Array.from(a).sort();for(let d of c){if(!this.comments_map[d])continue;let f=`Com:${d}`;if(!r.has(f)){let h=this.comments_map[d],p=`[${f}] ${h.author}`;h.date&&(p+=` @ ${h.date}`),h.resolved&&(p+="(RESOLVED)"),n.push(`${p}: ${Nr(h.text)}`),r.add(f);}}}return [...e,...n].join(`
38
- `)}_add_virtual_text(t,e,n,r=null,s=false){let i={start:e,end:e+t.length,text:t,run:null,paragraph:n,hyperlink_id:r||void 0,part_index:this._current_part_index,is_image_marker:s||void 0};this.spans.push(i),this._text_chunks.push(t);}_replace_smart_quotes(t){return t.replace(/“/g,'"').replace(/”/g,'"').replace(/‘/g,"'").replace(/’/g,"'")}_make_fuzzy_regex(t){t=this._strip_markdown_formatting(t),t=this._replace_smart_quotes(t);let e=[],n=/(\[_+\])|(\s+)|(['"])|([.,;:\/\-\[\](){}+=$?*!|#^<>\\%&@~`_])/g,r=0,s,i=y(l=>l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"escapeRegExp");for(;(s=n.exec(t))!==null;){let l=t.substring(r,s.index);l&&e.push(i(l));let a=s[1],u=s[2],c=s[3],d=s[4];a?e.push("\\[_+\\]"):u?(e.push("(?:\\*\\*|__|\\*|_)?"),e.push("\\s+"),e.push("(?:\\*\\*|__|\\*|_)?")):c?c==="'"?e.push("[\u2018\u2019']"):e.push('["\u201C\u201D]'):d&&(e.push("(?:\\*\\*|__|\\*|_)?"),e.push(i(d)),e.push("(?:\\*\\*|__|\\*|_)?")),r=n.lastIndex;}let o=t.substring(r);return o&&e.push(i(o)),e.join("")}_get_plain_projection(){if(this._plain_projection===null){let t=[],e=[];for(let n of this.spans)if(!(n.run===null&&n.paragraph!==null&&ro.has(n.text))){t.push(n.text);for(let r=n.start;r<n.end;r++)e.push(r);}this._plain_projection=[t.join(""),e];}return this._plain_projection}_find_plain_projection_matches(t){let[e,n]=this._get_plain_projection();if(e.length===this.full_text.length)return [];let r=this._replace_smart_quotes(this._strip_markdown_formatting(t));if(!r)return [];let s=this._replace_smart_quotes(e),i=[],o=0;for(;;){let l=s.indexOf(r,o);if(l===-1)break;let a=l+r.length,u=n[l],c=n[a-1]+1;i.push([u,c-u]),o=a;}return i}range_is_virtual_only(t,e){let n=t+e,r=this.spans.filter(s=>s.end>t&&s.start<n);return r.some(s=>s.run!==null)?false:!r.some(s=>s.run===null&&s.text.startsWith("{#"))}drop_virtual_only_matches(t){return t.filter(([e,n])=>!this.range_is_virtual_only(e,n))}find_match_index(t,e=false){if(e){try{let a=_s(t,this.full_text);if(a&&!this.range_is_virtual_only(a.start,a.end-a.start))return [a.start,a.end-a.start]}catch(a){if(a instanceof Ce)throw a}return [-1,0]}let n=0;for(;;){let a=this.full_text.indexOf(t,n);if(a===-1)break;if(!this.range_is_virtual_only(a,t.length))return [a,t.length];n=a+1;}let r=this._replace_smart_quotes(this.full_text),s=this._replace_smart_quotes(t),i=r.indexOf(s);if(i!==-1)return [i,t.length];let o=this._strip_markdown_formatting(t);if(this.full_text.includes(o))return i=this.full_text.indexOf(o),[i,o.length];let l=this._find_plain_projection_matches(t);if(l.length>0)return l[0];try{let a=new RegExp(this._make_fuzzy_regex(t),"g");for(let u of this.full_text.matchAll(a))if(!this.range_is_virtual_only(u.index,u[0].length))return [u.index,u[0].length]}catch{}return [-1,0]}find_all_match_indices(t,e=false){if(!t)return [];if(e){try{let a=ps(t,this.full_text);if(a.length>0)return a.map(u=>[u.start,u.end-u.start])}catch(a){if(a instanceof Ce)throw a}return []}let n=y((a,u)=>{let c=[];if(!u)return c;let d=0;for(;;){let f=a.indexOf(u,d);if(f===-1)break;c.push([f,u.length]),d=f+u.length;}return c},"findAllLiteral"),r=n(this.full_text,t);if(r.length>0)return r;let s=this._replace_smart_quotes(this.full_text),i=this._replace_smart_quotes(t);if(r=n(s,i),r.length>0)return r;let o=this._strip_markdown_formatting(t);if(r=n(this.full_text,o),r.length>0)return r;let l=this._find_plain_projection_matches(t);if(l.length>0)return l;try{let a=new RegExp(this._make_fuzzy_regex(t),"g"),u=[...this.full_text.matchAll(a)];if(u.length>0)return u.map(c=>[c.index,c[0].length])}catch{}return []}find_target_runs(t){let[e,n]=this.find_match_index(t);return e===-1?[]:this._resolve_runs_at_range(e,e+n)}find_target_runs_by_index(t,e,n=true){return this._resolve_runs_at_range(t,t+e,n)}get_virtual_spans_in_range(t,e){let n=t+e;return this.spans.filter(r=>r.run===null&&r.text===`
32
+ `,n,d),n+=2;}n=this._map_table(u,n),a=false,l=u;}return n}_map_table(t,e){let n=e,r=0;for(let s of t.rows){let i=s._element,o=M(i,"w:trPr"),a=o?M(o,"w:ins"):null,l=o?M(o,"w:del"):null;if(this.clean_view&&l||this.original_view&&a)continue;r>0&&(this._add_virtual_text(`
33
+ `,n,null),n+=1),a&&!this.clean_view&&!this.original_view?(this._add_virtual_text("{++ ",n,null),n+=4):l&&!this.clean_view&&!this.original_view&&(this._add_virtual_text("{-- ",n,null),n+=4);let u=new Set,c=0;for(let d of s.cells){if(u.has(d))continue;u.add(d),c>0&&(this._add_virtual_text(" | ",n,null),n+=3);let f=n;if(n=this._map_blocks(d,n),!this.clean_view&&!this.original_view){let{paraId:h,firstP:_}=xr(d._element,n===f);if(h&&_){let p=new re(_,d);this._add_virtual_text("",n,p),n>f&&(this._add_virtual_text(" ",n,p),n+=1);let w=`{#cell:${h}}`;this._add_virtual_text(w,n,p),n+=w.length;}}c+=1;}if(a&&!this.clean_view&&!this.original_view){let d=` ++}{>>[Chg:${a.getAttribute("w:id")} insert] ${a.getAttribute("w:author")||"Unknown"}<<}`;this._add_virtual_text(d,n,null),n+=d.length;}else if(l&&!this.clean_view&&!this.original_view){let d=` --}{>>[Chg:${l.getAttribute("w:id")} delete] ${l.getAttribute("w:author")||"Unknown"}<<}`;this._add_virtual_text(d,n,null),n+=d.length;}if(r+=1,r===1){let d=new Set,f=0;for(let h of s.cells)d.has(h)||(d.add(h),f+=1);if(f>0){let h=Array(f).fill("---").join(" | ");this._add_virtual_text(`
34
+ `,n,null),n+=1,this._add_virtual_text(h,n,null),n+=h.length;}}}return n}_strip_markdown_formatting(t){let e=t;return e=e.replace(/^#+\s*/gm,""),e=e.replace(/\*\*(\w[\w\s]*\w|\w{2,})\*\*/g,"$1"),e=e.replace(/__(\w[\w\s]*\w|\w{2,})__/g,"$1"),e=e.replace(/(?<!\w)_(\w[\w\s]*\w|\w{2,})_(?!\w)/g,"$1"),e=e.replace(/(?<!\w)\*(\w[\w\s]*\w|\w{2,})\*(?!\w)/g,"$1"),e}_map_paragraph_content(t,e,n,r){let s=e,i={start:s,end:s,text:"",run:null,paragraph:t,part_index:this._current_part_index};this.spans.push(i);let o=new Set,a={},l={},u={},c=[],d=["",""],f=["",""],h=null,_=[],p=y(()=>{if(_.length===0)return;let[g,v]=d;g&&(this._add_virtual_text(g,s,t),s+=g.length);for(let[x,E,C,A,N,P,D]of _){if(x==="virtual")this._add_virtual_text(E,s,t,h);else {let T={start:s,end:s+E.length,text:E,run:C,paragraph:t,ins_id:N||void 0,del_id:P||void 0,hyperlink_id:h||void 0,comment_ids:D.length>0?D:void 0,part_index:this._current_part_index,run_offset:A};this.spans.push(T),this._text_chunks.push(E);}s+=E.length;}v&&(this._add_virtual_text(v,s,t),s+=v.length),_=[];},"flush_pending_runs"),m=Array.from(Nt(t)),w=jr(t,n,r),k=fn(t,n,r),b=w;for(let g=0;g<m.length;g++){let v=m[g];if(v instanceof Ae){let[x,E]=Fr(v,k),C=[],A=De(v);if(b){if(A===""||/^\s*$/.test(A))continue;b=false;}let N=0,P=y(I=>{let[S,R,j]=Br(I);if(!R){C.push(["real",I,v,N]),N+=I.length;return}S&&(C.push(["real",S,v,N]),N+=S.length),x&&C.push(["virtual",x,null,0]),C.push(["real",R,v,N]),N+=R.length,E&&C.push(["virtual",E,null,0]),j&&(C.push(["real",j,v,N]),N+=j.length);},"append_wrapped");if(A.includes(`
35
+ `)&&(x||E)){let I=A.split(`
36
+ `);for(let S=0;S<I.length;S++)S>0&&(C.push(["real",`
37
+ `,v,N]),N+=1),I[S]&&P(I[S]);}else (x||E)&&A?P(A):(x&&C.push(["virtual",x,null,0]),A&&C.push(["real",A,v,0]),E&&C.push(["virtual",E,null,0]));this.clean_view&&Object.keys(l).length>0,this.original_view&&Object.keys(a).length>0;let D=C.map(I=>I[1]).join(""),T=Object.keys(a).pop()||null,F=Object.keys(l).pop()||null;if(D&&!(this.clean_view&&F)&&!(this.original_view&&T)){let I=this.clean_view||this.original_view?["",""]:this._get_wrappers(T,F,o,u),S=[x,E];if(_.length>0&&I[0]===d[0]&&I[1]===d[1]){let R=false;S[0]===f[0]&&S[1]===f[1]&&f[0]!==""&&_[_.length-1][0]==="virtual"&&_[_.length-1][1]===f[1]&&(_.pop(),R=true);let j=Array.from(o);for(let[B,L,U,Y]of C){if(R&&B==="virtual"&&L===S[0]){R=false;continue}_.push([B,L,U,Y,T,F,j]);}f=S;}else {p(),d=I,f=S;let R=Array.from(o);for(let[j,B,L,U]of C)_.push([j,B,L,U,T,F,R]);}}if(!this.clean_view&&!this.original_view){(Object.keys(a).length>0||Object.keys(l).length>0||o.size>0||Object.keys(u).length>0)&&c.push([{...a},{...l},new Set(o),{...u}]);let S=false;if(T!==null||F!==null||Object.keys(u).length>0||o.size>0){let j=g+1,B=false,L=Object.keys(a).length,U=Object.keys(l).length,Y=Object.keys(u).length,X=new Set(o);for(;j<m.length;){let J=m[j];if(J instanceof Ae){if(!De(J)){j++;continue}(L>0||U>0||Y>0||X.size>0)&&(B=true);break}else {let W=J;W.type==="ins_start"?L++:W.type==="ins_end"?L=Math.max(0,L-1):W.type==="del_start"?U++:W.type==="del_end"?U=Math.max(0,U-1):W.type==="fmt_start"?Y++:W.type==="fmt_end"?Y=Math.max(0,Y-1):W.type==="start"?X.add(W.id):W.type==="end"&&X.delete(W.id);}j++;}B&&(S=true);}if(!S&&c.length>0){let j=this._build_merged_meta_block(c);if(j){p(),d=["",""],f=["",""];let B=`{>>${j}<<}`;this._add_virtual_text(B,s,t),s+=B.length;}c=[];}}}else {let x=v;if(b=false,p(),d=["",""],f=["",""],x.type==="start")o.add(x.id);else if(x.type==="end")o.delete(x.id);else if(x.type==="ins_start")a[x.id]=x;else if(x.type==="ins_end")delete a[x.id];else if(x.type==="del_start")l[x.id]=x;else if(x.type==="del_end")delete l[x.id];else if(x.type==="fmt_start")u[x.id]=x;else if(x.type==="fmt_end")delete u[x.id];else if(x.type==="image"){if(!(this.clean_view&&Object.keys(l).length>0||this.original_view&&Object.keys(a).length>0)){let A=`![${(x.date||"image").replace(/\]/g,")").replace(/\n/g," ")}](docx-image:${x.id})`;this._add_virtual_text(A,s,t,null,true),s+=A.length;}}else if(x.type==="footnote"||x.type==="endnote"){p(),d=["",""],f=["",""];let C=`[^${x.type==="footnote"?"fn":"en"}-${x.id}]`;this._add_virtual_text(C,s,t),s+=C.length;}else if(x.type==="hyperlink_start")p(),d=["",""],f=["",""],this._add_virtual_text("[",s,t,x.id),s+=1,h=x.id;else if(x.type==="hyperlink_end"){p(),d=["",""],f=["",""];let E=`](${x.date})`;this._add_virtual_text(E,s,t,x.id),s+=E.length,h=null;}else if(x.type==="xref_start")p(),d=["",""],f=["",""],this._add_virtual_text("[~",s,t),s+=2;else if(x.type==="xref_end"){p(),d=["",""],f=["",""];let E=`~](#${x.id})`;this._add_virtual_text(E,s,t),s+=E.length;}else if(x.type==="bookmark"){p(),d=["",""],f=["",""];let E=`{#${x.id}}`;this._add_virtual_text(E,s,t),s+=E.length;}}}if(p(),c.length>0){let g=this._build_merged_meta_block(c);if(g){let v=`{>>${g}<<}`;this._add_virtual_text(v,s,t),s+=v.length;}}return s}_get_wrappers(t,e,n,r){return e?["{--","--}"]:t?["{++","++}"]:n.size>0||Object.keys(r).length>0?["{==","==}"]:["",""]}_build_merged_meta_block(t){let e=[],n=[],r=new Set,s=Wr(t),i=y(o=>s[o]?` (pairs with ${s[o]})`:"","pairSuffix");for(let[o,a,l,u]of t){for(let[d,f]of Object.entries(o)){let h=`Chg:${d}`;if(!r.has(h)){let _=f.author||"Unknown";e.push(`[${h} insert] ${_}${i(d)}`),r.add(h);}}for(let[d,f]of Object.entries(a)){let h=`Chg:${d}`;if(!r.has(h)){let _=f.author||"Unknown";e.push(`[${h} delete] ${_}${i(d)}`),r.add(h);}}for(let[d,f]of Object.entries(u)){let h=`Chg:${d}`;if(!r.has(h)){let _=f.author||"Unknown";e.push(`[${h} format] ${_}`),r.add(h);}}let c=Array.from(l).sort();for(let d of c){if(!this.comments_map[d])continue;let f=`Com:${d}`;if(!r.has(f)){let h=this.comments_map[d],_=`[${f}] ${h.author}`;h.date&&(_+=` @ ${h.date}`),h.resolved&&(_+="(RESOLVED)"),n.push(`${_}: ${Cr(h.text)}`),r.add(f);}}}return [...e,...n].join(`
38
+ `)}_add_virtual_text(t,e,n,r=null,s=false){let i={start:e,end:e+t.length,text:t,run:null,paragraph:n,hyperlink_id:r||void 0,part_index:this._current_part_index,is_image_marker:s||void 0};this.spans.push(i),this._text_chunks.push(t);}_replace_smart_quotes(t){return t.replace(/“/g,'"').replace(/”/g,'"').replace(/‘/g,"'").replace(/’/g,"'")}_make_fuzzy_regex(t){t=this._strip_markdown_formatting(t),t=this._replace_smart_quotes(t);let e=[],n=/(\[_+\])|(\s+)|(['"])|([.,;:\/\-\[\](){}+=$?*!|#^<>\\%&@~`_])/g,r=0,s,i=y(a=>a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"escapeRegExp");for(;(s=n.exec(t))!==null;){let a=t.substring(r,s.index);a&&e.push(i(a));let l=s[1],u=s[2],c=s[3],d=s[4];l?e.push("\\[_+\\]"):u?(e.push("(?:\\*\\*|__|\\*|_)?"),e.push("\\s+"),e.push("(?:\\*\\*|__|\\*|_)?")):c?c==="'"?e.push("[\u2018\u2019']"):e.push('["\u201C\u201D]'):d&&(e.push("(?:\\*\\*|__|\\*|_)?"),e.push(i(d)),e.push("(?:\\*\\*|__|\\*|_)?")),r=n.lastIndex;}let o=t.substring(r);return o&&e.push(i(o)),e.join("")}_get_plain_projection(){if(this._plain_projection===null){let t=[],e=[];for(let n of this.spans)if(!(n.run===null&&n.paragraph!==null&&fo.has(n.text))){t.push(n.text);for(let r=n.start;r<n.end;r++)e.push(r);}this._plain_projection=[t.join(""),e];}return this._plain_projection}_find_plain_projection_matches(t){let[e,n]=this._get_plain_projection();if(e.length===this.full_text.length)return [];let r=this._replace_smart_quotes(this._strip_markdown_formatting(t));if(!r)return [];let s=this._replace_smart_quotes(e),i=[],o=0;for(;;){let a=s.indexOf(r,o);if(a===-1)break;let l=a+r.length,u=n[a],c=n[l-1]+1;i.push([u,c-u]),o=l;}return i}range_is_virtual_only(t,e){let n=t+e,r=this.spans.filter(s=>s.end>t&&s.start<n);return r.some(s=>s.run!==null)?false:!r.some(s=>s.run===null&&s.text.startsWith("{#"))}drop_virtual_only_matches(t){return t.filter(([e,n])=>!this.range_is_virtual_only(e,n))}find_match_index(t,e=false){if(e){try{let l=Ns(t,this.full_text);if(l&&!this.range_is_virtual_only(l.start,l.end-l.start))return [l.start,l.end-l.start]}catch(l){if(l instanceof Ce)throw l}return [-1,0]}let n=0;for(;;){let l=this.full_text.indexOf(t,n);if(l===-1)break;if(!this.range_is_virtual_only(l,t.length))return [l,t.length];n=l+1;}let r=this._replace_smart_quotes(this.full_text),s=this._replace_smart_quotes(t),i=r.indexOf(s);if(i!==-1)return [i,t.length];let o=this._strip_markdown_formatting(t);if(this.full_text.includes(o))return i=this.full_text.indexOf(o),[i,o.length];let a=this._find_plain_projection_matches(t);if(a.length>0)return a[0];try{let l=new RegExp(this._make_fuzzy_regex(t),"g");for(let u of this.full_text.matchAll(l))if(!this.range_is_virtual_only(u.index,u[0].length))return [u.index,u[0].length]}catch{}return [-1,0]}find_all_match_indices(t,e=false){if(!t)return [];if(e){try{let l=xs(t,this.full_text);if(l.length>0)return l.map(u=>[u.start,u.end-u.start])}catch(l){if(l instanceof Ce)throw l}return []}let n=y((l,u)=>{let c=[];if(!u)return c;let d=0;for(;;){let f=l.indexOf(u,d);if(f===-1)break;c.push([f,u.length]),d=f+u.length;}return c},"findAllLiteral"),r=n(this.full_text,t);if(r.length>0)return r;let s=this._replace_smart_quotes(this.full_text),i=this._replace_smart_quotes(t);if(r=n(s,i),r.length>0)return r;let o=this._strip_markdown_formatting(t);if(r=n(this.full_text,o),r.length>0)return r;let a=this._find_plain_projection_matches(t);if(a.length>0)return a;try{let l=new RegExp(this._make_fuzzy_regex(t),"g"),u=[...this.full_text.matchAll(l)];if(u.length>0)return u.map(c=>[c.index,c[0].length])}catch{}return []}find_target_runs(t){let[e,n]=this.find_match_index(t);return e===-1?[]:this._resolve_runs_at_range(e,e+n)}find_target_runs_by_index(t,e,n=true){return this._resolve_runs_at_range(t,t+e,n)}get_virtual_spans_in_range(t,e){let n=t+e;return this.spans.filter(r=>r.run===null&&r.text===`
39
39
 
40
- `&&r.start>=t&&r.end<=n)}_resolve_runs_at_range(t,e,n=true){let r=this.spans.filter(g=>g.end>t&&g.start<e);if(r.length===0)return [];let s=r.filter(g=>g.run!==null);if(s.length===0)return [];let i=[];for(let g of s)i.some(w=>w===g.run)||i.push(g.run);let o=false,l=s[0],a=0,u=Math.max(t,l.start)-l.start+(l.run_offset||0);if(u>0){let g=i[0],[,w]=this._split_run_at_index(g,u);for(let k=0;k<i.length;k++)i[k]===g&&(i[k]=w);o=true,a=u;}let c=s[s.length-1],d=l.run===c.run,f=i[i.length-1],p=Math.min(c.end,e)-c.start+(c.run_offset||0);d&&a>0&&(p-=a);let _=De(f);if(p>0&&p<_.length){let[g]=this._split_run_at_index(f,p);i[i.length-1]=g,o=true;}return o&&n&&this._build_map(),i}get_insertion_anchor(t,e=true){let n=this.spans.filter(i=>i.end===t);if(n.length>0){for(let i=n.length-1;i>=0;i--)if(n[i].run)return [n[i].run,n[i].paragraph];for(let i=n.length-1;i>=0;i--){let o=n[i].paragraph;if(o){for(let l=this.spans.length-1;l>=0;l--){let a=this.spans[l];if(a.end<=t&&a.run!==null&&a.paragraph!==null&&a.paragraph._element===o._element)return [a.run,a.paragraph]}return [null,o]}}}let r=this.spans.filter(i=>i.start<t&&t<i.end);if(r.length>0){let i=r[0];if(i.run===null)return i.paragraph===null?this.get_insertion_anchor(i.end,e):[null,i.paragraph];{let o=t-i.start+(i.run_offset||0),[l]=this._split_run_at_index(i.run,o);return e&&this._build_map(),[l,i.paragraph]}}if(t===0&&this.spans.length>0){for(let i of this.spans)if(i.run)return [i.run,i.paragraph];for(let i of this.spans)if(i.paragraph)return [null,i.paragraph];return [null,null]}let s=this.spans.filter(i=>i.end<t);if(s.length>0){for(let i=s.length-1;i>=0;i--)if(s[i].run)return [s[i].run,s[i].paragraph];for(let i=s.length-1;i>=0;i--)if(s[i].paragraph)return [null,s[i].paragraph]}return [null,null]}_split_run_at_index(t,e){let n=De(t),r=n.substring(0,e),s=n.substring(e);this._set_run_text_elements(t._element,r);let i=t._element.cloneNode(true);this._set_run_text_elements(i,s),t._element.parentNode&&t._element.parentNode.insertBefore(i,t._element.nextSibling);let o=new Ae(i,t._parent);return [t,o]}_set_run_text_elements(t,e){let n=[];for(let s=0;s<t.childNodes.length;s++){let i=t.childNodes[s];i.nodeType===1&&["w:t","w:delText","w:br","w:cr","w:tab"].includes(i.tagName)&&n.push(i);}for(let s of n)t.removeChild(s);let r=t.ownerDocument;if(r){let s=r.createElement("w:t");s.textContent=e,e.trim()!==e&&s.setAttribute("xml:space","preserve"),t.appendChild(s);}}get_context_at_range(t,e){let n=this.spans.filter(r=>r.run&&r.end>t&&r.start<e);return n.length>0?n[0]:null}};function Hn(t){let e=0,n=0,r=t.length,s=y(i=>/[a-zA-Z0-9]/.test(i),"isAlnum");for(;n<r;){if(t[n]==="_"){let i=false;(n>0&&t[n-1]==="_"||n<r-1&&t[n+1]==="_")&&(i=true);let o=false;n>0&&s(t[n-1])&&n<r-1&&s(t[n+1])&&(o=true),!i&&!o&&e++;}n++;}return e}y(Hn,"_count_standalone_underscores");function Ue(t,e){if(!t||!e)return [0,0];let n=y(u=>/\s/.test(u),"isSpace"),r=0,s=Math.min(t.length,e.length);for(;r<s&&t[r]===e[r];)r++;if(r<t.length&&r<e.length)for(;r>0;){let u=!n(t[r-1])&&!n(t[r]),c=!n(e[r-1])&&!n(e[r]);if(u||c)r--;else break}for(;r>0;){if(r<t.length){let _=t.substring(r-1,r+1);if(_==="**"||_==="__"){r--;continue}}let u=t.substring(0,r),c=(u.match(/\*\*/g)||[]).length,d=(u.match(/__/g)||[]).length,f=Hn(u);if(c%2!==0){r=u.lastIndexOf("**");continue}if(d%2!==0){r=u.lastIndexOf("__");continue}if(f%2!==0){let _=u.length-1,g=y(w=>/[a-zA-Z0-9]/.test(w),"isAlnum");for(;_>=0;){if(u[_]==="_"&&(_===0||u[_-1]!=="_")&&(_===u.length-1||u[_+1]!=="_")&&!(_>0&&g(u[_-1])&&_<u.length-1&&g(u[_+1]))){r=_;break}_--;}continue}let h=r,p=false;for(;h>0;){let _=t[h-1];if(_==="#"){for(r=h-1;r>0&&t[r-1]!==`
41
- `;)r--;p=true;break}if(_===`
42
- `)break;h--;}if(!p)break}let i=0,o=t.length-r,l=e.length-r,a=Math.min(o,l);for(;i<a&&t[t.length-1-i]===e[e.length-1-i];)i++;if(i>0)for(;i>0;){let u=false;i<t.length&&(u=!n(t[t.length-1-i])&&!n(t[t.length-i]));let c=false;if(i<e.length&&(c=!n(e[e.length-1-i])&&!n(e[e.length-i])),u||c)i--;else break}for(;i>0;){let u=t.length-i;if(u>0){let p=t.substring(u-1,u+1);if(p==="**"||p==="__"){i--;continue}}let c=t.substring(t.length-i),d=(c.match(/\*\*/g)||[]).length,f=(c.match(/__/g)||[]).length,h=Hn(c);if(d%2!==0){i-=c.indexOf("**")+2;continue}if(f%2!==0){i-=c.indexOf("__")+2;continue}if(h%2!==0){let p=0,_=y(g=>/[a-zA-Z0-9]/.test(g),"isAlnum");for(;p<c.length;){if(c[p]==="_"&&(p===0||c[p-1]!=="_")&&(p===c.length-1||c[p+1]!=="_")&&!(p>0&&_(c[p-1])&&p<c.length-1&&_(c[p+1]))){i-=p+1;break}p++;}continue}break}i>0&&/^\s+$/.test(t.substring(t.length-i))&&(i=0);for(let u of ["**","__","_"]){let c=u.length,d=t.substring(r,t.length-i),f=e.substring(r,e.length-i);d.startsWith(u)&&f.startsWith(u)&&d.endsWith(u)&&f.endsWith(u)&&d.length>=2*c&&f.length>=2*c&&(r+=c,i+=c);}return [r,i]}y(Ue,"trim_common_context");function io(t,e){let n=[],r={},s=/(\s+|[\p{L}\p{N}_]+|[^\p{L}\p{N}_\s])/gu,i=y(o=>{let l=o.split(s).filter(Boolean),a="";for(let u of l)if(u in r)a+=String.fromCharCode(r[u]);else {let c=n.length;r[u]=c,n.push(u),a+=String.fromCharCode(c);}return a},"encode_text");return [i(t),i(e),n]}y(io,"_words_to_chars");function wt(t,e){let n=new dn.default.diff_match_patch;n.Diff_Timeout=2;let[r,s,i]=io(t,e),o=n.diff_main(r,s,false);n.diff_cleanupSemantic(o);for(let c=0;c<o.length;c++){let d=o[c][1],f="";for(let h=0;h<d.length;h++)f+=i[d.charCodeAt(h)];o[c][1]=f;}let l=[],a=0,u=null;for(let[c,d]of o)if(c===0){if(u){let[f,h]=u;l.push({type:"modify",target_text:h,new_text:"",comment:"Diff: Text deleted",_match_start_index:f}),u=null;}a+=d.length;}else if(c===-1)u=[a,d],a+=d.length;else if(c===1)if(u){let[f,h]=u;l.push({type:"modify",target_text:h,new_text:d,comment:"Diff: Replacement",_match_start_index:f}),u=null;}else l.push({type:"modify",target_text:"",new_text:d,comment:"Diff: Text inserted",_match_start_index:a});if(u){let[c,d]=u;l.push({type:"modify",target_text:d,new_text:"",comment:"Diff: Text deleted",_match_start_index:c});}return l}y(wt,"generate_edits_from_text");function Br(t,e){let n=t.length,r=e.length,s=[];for(let h=0;h<=n;h++)s.push(new Int32Array(r+1));for(let h=n-1;h>=0;h--)for(let p=r-1;p>=0;p--)s[h][p]=t[h]===e[p]?s[h+1][p+1]+1:Math.max(s[h+1][p],s[h][p+1]);let i=[],o=0,l=0,a=0,u=0,c=0,d=0,f=y(()=>{if(c===0&&d===0)return;let h=c>0&&d>0?"replace":c>0?"delete":"insert";i.push([h,a,a+c,u,u+d]),c=0,d=0;},"flushPending");for(;o<n||l<r;)if(o<n&&l<r&&t[o]===e[l]){f();let h=o,p=l;for(;o<n&&l<r&&t[o]===e[l];)o++,l++;i.push(["equal",h,o,p,l]);}else c===0&&d===0&&(a=o,u=l),l<r&&(o===n||s[o][l+1]>=s[o+1][l])?(d++,l++):(c++,o++);return f(),i}y(Br,"_sequence_opcodes");function ht(t){let e=t.split(`
43
- `);return e.length>0&&e.every(n=>n.includes(" | "))}y(ht,"_is_table_blob");function so(t,e){let n=t.split(`
40
+ `&&r.start>=t&&r.end<=n)}_resolve_runs_at_range(t,e,n=true){let r=this.spans.filter(m=>m.end>t&&m.start<e);if(r.length===0)return [];let s=r.filter(m=>m.run!==null);if(s.length===0)return [];let i=[];for(let m of s)i.some(w=>w===m.run)||i.push(m.run);let o=false,a=s[0],l=0,u=Math.max(t,a.start)-a.start+(a.run_offset||0);if(u>0){let m=i[0],[,w]=this._split_run_at_index(m,u);for(let k=0;k<i.length;k++)i[k]===m&&(i[k]=w);o=true,l=u;}let c=s[s.length-1],d=a.run===c.run,f=i[i.length-1],_=Math.min(c.end,e)-c.start+(c.run_offset||0);d&&l>0&&(_-=l);let p=De(f);if(_>0&&_<p.length){let[m]=this._split_run_at_index(f,_);i[i.length-1]=m,o=true;}return o&&n&&this._build_map(),i}get_insertion_anchor(t,e=true){let n=this.spans.filter(i=>i.end===t);if(n.length>0){for(let i=n.length-1;i>=0;i--)if(n[i].run)return [n[i].run,n[i].paragraph];for(let i=n.length-1;i>=0;i--){let o=n[i].paragraph;if(o){for(let a=this.spans.length-1;a>=0;a--){let l=this.spans[a];if(l.end<=t&&l.run!==null&&l.paragraph!==null&&l.paragraph._element===o._element)return [l.run,l.paragraph]}return [null,o]}}}let r=this.spans.filter(i=>i.start<t&&t<i.end);if(r.length>0){let i=r[0];if(i.run===null)return i.paragraph===null?this.get_insertion_anchor(i.end,e):[null,i.paragraph];{let o=t-i.start+(i.run_offset||0),[a]=this._split_run_at_index(i.run,o);return e&&this._build_map(),[a,i.paragraph]}}if(t===0&&this.spans.length>0){for(let i of this.spans)if(i.run)return [i.run,i.paragraph];for(let i of this.spans)if(i.paragraph)return [null,i.paragraph];return [null,null]}let s=this.spans.filter(i=>i.end<t);if(s.length>0){for(let i=s.length-1;i>=0;i--)if(s[i].run)return [s[i].run,s[i].paragraph];for(let i=s.length-1;i>=0;i--)if(s[i].paragraph)return [null,s[i].paragraph]}return [null,null]}_split_run_at_index(t,e){let n=De(t),r=n.substring(0,e),s=n.substring(e);this._set_run_text_elements(t._element,r);let i=t._element.cloneNode(true);this._set_run_text_elements(i,s),t._element.parentNode&&t._element.parentNode.insertBefore(i,t._element.nextSibling);let o=new Ae(i,t._parent);return [t,o]}_set_run_text_elements(t,e){let n=[];for(let s=0;s<t.childNodes.length;s++){let i=t.childNodes[s];i.nodeType===1&&["w:t","w:delText","w:br","w:cr","w:tab"].includes(i.tagName)&&n.push(i);}for(let s of n)t.removeChild(s);let r=t.ownerDocument;if(r){let s=r.createElement("w:t");s.textContent=e,e.trim()!==e&&s.setAttribute("xml:space","preserve"),t.appendChild(s);}}get_context_at_range(t,e){let n=this.spans.filter(r=>r.run&&r.end>t&&r.start<e);return n.length>0?n[0]:null}};function Qn(t){let e=0,n=0,r=t.length,s=y(i=>/[a-zA-Z0-9]/.test(i),"isAlnum");for(;n<r;){if(t[n]==="_"){let i=false;(n>0&&t[n-1]==="_"||n<r-1&&t[n+1]==="_")&&(i=true);let o=false;n>0&&s(t[n-1])&&n<r-1&&s(t[n+1])&&(o=true),!i&&!o&&e++;}n++;}return e}y(Qn,"_count_standalone_underscores");function qe(t,e){if(!t||!e)return [0,0];let n=y(u=>/\s/.test(u),"isSpace"),r=0,s=Math.min(t.length,e.length);for(;r<s&&t[r]===e[r];)r++;if(r<t.length&&r<e.length)for(;r>0;){let u=!n(t[r-1])&&!n(t[r]),c=!n(e[r-1])&&!n(e[r]);if(u||c)r--;else break}for(;r>0;){if(r<t.length){let p=t.substring(r-1,r+1);if(p==="**"||p==="__"){r--;continue}}let u=t.substring(0,r),c=(u.match(/\*\*/g)||[]).length,d=(u.match(/__/g)||[]).length,f=Qn(u);if(c%2!==0){r=u.lastIndexOf("**");continue}if(d%2!==0){r=u.lastIndexOf("__");continue}if(f%2!==0){let p=u.length-1,m=y(w=>/[a-zA-Z0-9]/.test(w),"isAlnum");for(;p>=0;){if(u[p]==="_"&&(p===0||u[p-1]!=="_")&&(p===u.length-1||u[p+1]!=="_")&&!(p>0&&m(u[p-1])&&p<u.length-1&&m(u[p+1]))){r=p;break}p--;}continue}let h=r,_=false;for(;h>0;){let p=t[h-1];if(p==="#"){for(r=h-1;r>0&&t[r-1]!==`
41
+ `;)r--;_=true;break}if(p===`
42
+ `)break;h--;}if(!_)break}let i=0,o=t.length-r,a=e.length-r,l=Math.min(o,a);for(;i<l&&t[t.length-1-i]===e[e.length-1-i];)i++;if(i>0)for(;i>0;){let u=false;i<t.length&&(u=!n(t[t.length-1-i])&&!n(t[t.length-i]));let c=false;if(i<e.length&&(c=!n(e[e.length-1-i])&&!n(e[e.length-i])),u||c)i--;else break}for(;i>0;){let u=t.length-i;if(u>0){let _=t.substring(u-1,u+1);if(_==="**"||_==="__"){i--;continue}}let c=t.substring(t.length-i),d=(c.match(/\*\*/g)||[]).length,f=(c.match(/__/g)||[]).length,h=Qn(c);if(d%2!==0){i-=c.indexOf("**")+2;continue}if(f%2!==0){i-=c.indexOf("__")+2;continue}if(h%2!==0){let _=0,p=y(m=>/[a-zA-Z0-9]/.test(m),"isAlnum");for(;_<c.length;){if(c[_]==="_"&&(_===0||c[_-1]!=="_")&&(_===c.length-1||c[_+1]!=="_")&&!(_>0&&p(c[_-1])&&_<c.length-1&&p(c[_+1]))){i-=_+1;break}_++;}continue}break}i>0&&/^\s+$/.test(t.substring(t.length-i))&&(i=0);for(let u of ["**","__","_"]){let c=u.length,d=t.substring(r,t.length-i),f=e.substring(r,e.length-i);d.startsWith(u)&&f.startsWith(u)&&d.endsWith(u)&&f.endsWith(u)&&d.length>=2*c&&f.length>=2*c&&(r+=c,i+=c);}return [r,i]}y(qe,"trim_common_context");function ho(t,e){let n=[],r={},s=/(\s+|[\p{L}\p{N}_]+|[^\p{L}\p{N}_\s])/gu,i=y(o=>{let a=o.split(s).filter(Boolean),l="";for(let u of a)if(u in r)l+=String.fromCharCode(r[u]);else {let c=n.length;r[u]=c,n.push(u),l+=String.fromCharCode(c);}return l},"encode_text");return [i(t),i(e),n]}y(ho,"_words_to_chars");function wt(t,e){let n=new pn.default.diff_match_patch;n.Diff_Timeout=2;let[r,s,i]=ho(t,e),o=n.diff_main(r,s,false);n.diff_cleanupSemantic(o);for(let c=0;c<o.length;c++){let d=o[c][1],f="";for(let h=0;h<d.length;h++)f+=i[d.charCodeAt(h)];o[c][1]=f;}let a=[],l=0,u=null;for(let[c,d]of o)if(c===0){if(u){let[f,h]=u;a.push({type:"modify",target_text:h,new_text:"",comment:"Diff: Text deleted",_match_start_index:f}),u=null;}l+=d.length;}else if(c===-1)u=[l,d],l+=d.length;else if(c===1)if(u){let[f,h]=u;a.push({type:"modify",target_text:h,new_text:d,comment:"Diff: Replacement",_match_start_index:f}),u=null;}else a.push({type:"modify",target_text:"",new_text:d,comment:"Diff: Text inserted",_match_start_index:l});if(u){let[c,d]=u;a.push({type:"modify",target_text:d,new_text:"",comment:"Diff: Text deleted",_match_start_index:c});}return a}y(wt,"generate_edits_from_text");function Ur(t,e){let n=t.length,r=e.length,s=[];for(let h=0;h<=n;h++)s.push(new Int32Array(r+1));for(let h=n-1;h>=0;h--)for(let _=r-1;_>=0;_--)s[h][_]=t[h]===e[_]?s[h+1][_+1]+1:Math.max(s[h+1][_],s[h][_+1]);let i=[],o=0,a=0,l=0,u=0,c=0,d=0,f=y(()=>{if(c===0&&d===0)return;let h=c>0&&d>0?"replace":c>0?"delete":"insert";i.push([h,l,l+c,u,u+d]),c=0,d=0;},"flushPending");for(;o<n||a<r;)if(o<n&&a<r&&t[o]===e[a]){f();let h=o,_=a;for(;o<n&&a<r&&t[o]===e[a];)o++,a++;i.push(["equal",h,o,_,a]);}else c===0&&d===0&&(l=o,u=a),a<r&&(o===n||s[o][a+1]>=s[o+1][a])?(d++,a++):(c++,o++);return f(),i}y(Ur,"_sequence_opcodes");function ht(t){let e=t.split(`
43
+ `);return e.length>0&&e.every(n=>n.includes(" | "))}y(ht,"_is_table_blob");function po(t,e){let n=t.split(`
44
44
  `),r=e.split(`
45
- `);if(n.length!==r.length)return null;let s=[];for(let i=0;i<n.length;i++)n[i]!==r[i]&&s.push({type:"modify",target_text:n[i],new_text:r[i],comment:"Diff: Table row modified",_is_table_edit:true});return s}y(so,"_table_blob_row_edits");function oo(t){let e=[];for(let n of t){let r=n.target_text||"",s=n.new_text||"",i=n._match_start_index;if(i==null||!r.includes(`
45
+ `);if(n.length!==r.length)return null;let s=[];for(let i=0;i<n.length;i++)n[i]!==r[i]&&s.push({type:"modify",target_text:n[i],new_text:r[i],comment:"Diff: Table row modified",_is_table_edit:true});return s}y(po,"_table_blob_row_edits");function _o(t){let e=[];for(let n of t){let r=n.target_text||"",s=n.new_text||"",i=n._match_start_index;if(i==null||!r.includes(`
46
46
 
47
47
  `)||r.split(`
48
48
 
@@ -50,106 +50,106 @@ ${t.note_type==="fn"?"## Footnotes":"## Endnotes"}`;this._add_virtual_text(c,n,n
50
50
 
51
51
  `).length-1){e.push(n);continue}let o=r.split(`
52
52
 
53
- `);if(o.length<2||!o[0].trim()||!o[o.length-1].trim()){e.push(n);continue}let l=i;for(let a of o.slice(0,-1))e.push({type:"modify",target_text:a+`
53
+ `);if(o.length<2||!o[0].trim()||!o[o.length-1].trim()){e.push(n);continue}let a=i;for(let l of o.slice(0,-1))e.push({type:"modify",target_text:l+`
54
54
 
55
- `,new_text:"",comment:n.comment||"Diff: Text deleted",_match_start_index:l}),l+=a.length+2;e.push({type:"modify",target_text:o[o.length-1],new_text:s,comment:n.comment,_match_start_index:l});}return e}y(oo,"_split_cross_paragraph_hunks");function Jt(t,e){let n=t.trimEnd(),r=t.slice(n.length);e=e.trimEnd()+r;let i=t.split(`
55
+ `,new_text:"",comment:n.comment||"Diff: Text deleted",_match_start_index:a}),a+=l.length+2;e.push({type:"modify",target_text:o[o.length-1],new_text:s,comment:n.comment,_match_start_index:a});}return e}y(_o,"_split_cross_paragraph_hunks");function Xt(t,e){let n=t.trimEnd(),r=t.slice(n.length);e=e.trimEnd()+r;let i=t.split(`
56
56
 
57
57
  `),o=e.split(`
58
58
 
59
- `),l=[],a=0;for(let d of i)l.push(a),a+=d.length+2;let u=Br(i,o),c=[];for(let[d,f,h,p,_]of u){if(d==="equal")continue;let g=f<l.length?l[f]:t.length;if(d==="delete")if(h<i.length){let w=g;for(let k=f;k<h;k++){let b=i[k]+`
59
+ `),a=[],l=0;for(let d of i)a.push(l),l+=d.length+2;let u=Ur(i,o),c=[];for(let[d,f,h,_,p]of u){if(d==="equal")continue;let m=f<a.length?a[f]:t.length;if(d==="delete")if(h<i.length){let w=m;for(let k=f;k<h;k++){let b=i[k]+`
60
60
 
61
61
  `;c.push({type:"modify",target_text:b,new_text:"",comment:"Diff: Text deleted",_match_start_index:w}),w+=b.length;}}else {let w=i.slice(f,h).join(`
62
62
 
63
- `),k=g;f>0&&(w=`
63
+ `),k=m;f>0&&(w=`
64
64
 
65
- `+w,k-=2),c.push({type:"modify",target_text:w,new_text:"",comment:"Diff: Text deleted",_match_start_index:k});}else if(d==="insert"){let w=o.slice(p,_).join(`
65
+ `+w,k-=2),c.push({type:"modify",target_text:w,new_text:"",comment:"Diff: Text deleted",_match_start_index:k});}else if(d==="insert"){let w=o.slice(_,p).join(`
66
66
 
67
67
  `);f<i.length?w=w+`
68
68
 
69
69
  `:w=`
70
70
 
71
- `+w,c.push({type:"modify",target_text:"",new_text:w,comment:"Diff: Text inserted",_match_start_index:g});}else if(d==="replace"){if(h-f===_-p&&Array.from({length:h-f}).some((m,v)=>ht(i[f+v])||ht(o[p+v]))){for(let m=0;m<h-f;m++){let v=i[f+m],N=o[p+m];if(v===N)continue;let A=l[f+m],C=ht(v)&&ht(N)?so(v,N):null;if(C!==null){c.push(...C);continue}let x=wt(v,N);for(let E of x)E._match_start_index=(E._match_start_index||0)+A,c.push(E);}continue}let w=i.slice(f,h).join(`
71
+ `+w,c.push({type:"modify",target_text:"",new_text:w,comment:"Diff: Text inserted",_match_start_index:m});}else if(d==="replace"){if(h-f===p-_&&Array.from({length:h-f}).some((g,v)=>ht(i[f+v])||ht(o[_+v]))){for(let g=0;g<h-f;g++){let v=i[f+g],x=o[_+g];if(v===x)continue;let E=a[f+g],C=ht(v)&&ht(x)?po(v,x):null;if(C!==null){c.push(...C);continue}let A=wt(v,x);for(let N of A)N._match_start_index=(N._match_start_index||0)+E,c.push(N);}continue}let w=i.slice(f,h).join(`
72
72
 
73
- `),k=o.slice(p,_).join(`
73
+ `),k=o.slice(_,p).join(`
74
74
 
75
- `),b=wt(w,k);for(let m of b)m._match_start_index=(m._match_start_index||0)+g,c.push(m);}}return oo(c)}y(Jt,"generate_edits_via_paragraph_alignment");var gt=/!\[[^\]]*\]\(docx-image:[^)]*\)/g;function Xn(t,e){let n=y(s=>s.replace(gt,"").replace(/\s+/g," ").trim(),"_normalized"),r=[];for(let s of t){let i=((s.target_text||"").match(gt)||[]).sort(),o=((s.new_text||"").match(gt)||[]).sort();if(JSON.stringify(i)===JSON.stringify(o)){r.push(s);continue}n(s.target_text||"")===n(s.new_text||"")?e.push("An inline image was added or removed between the documents. Images cannot be transferred by text edits \u2014 the image-only difference was skipped; apply it manually in Word."):e.push("A text change overlapping an added/removed inline image was skipped \u2014 images cannot be transferred by text edits. Apply that section manually in Word.");}return r}y(Xn,"_drop_image_marker_hunks");function Qn(t,e,n){let r=[];for(let o of e.matchAll(gt))r.push([o.index,o.index+o[0].length]);if(r.length===0)return t;let s=[],i=false;for(let o of t){let l=o._match_start_index;if(l==null){s.push(o);continue}let a=l+(o.target_text||"").length;if(!r.some(([c,d])=>c<a&&l<d&&!(l<=c&&d<=a))){s.push(o);continue}i||(n.push("An image's alternative text differs between the documents. Image markers (![alt](docx-image:N)) are read-only projections, so this difference cannot be expressed as a text edit \u2014 it was skipped; update the image or its alt text manually in Word."),i=true);}return s}y(Qn,"_drop_marker_interior_hunks");function Yn(t,e){for(let n of e.rows)if(t.substring(n.start,n.end)!==n.cells.join(" | "))return false;return true}y(Yn,"_rows_are_plain");var Zt="";function ao(t,e){let n=t.map(i=>i.cells.join(Zt)),r=e.map(i=>i.cells.join(Zt)),s=Br(n,r);for(let[i,o,l,a,u]of s)if(i==="insert"||i==="delete"||i==="replace"&&l-o!==u-a)return s;return null}y(ao,"_table_row_opcodes");function lo(t,e,n,r){let s=t.rows,i=e.rows,o=s.map(p=>p.cells.join(Zt)),l=y(p=>p.cells.join(" | "),"row_text");new Set(o).size!==o.length&&r.push("A table contains rows with identical text; the generated row operations anchor by row text and may be rejected as ambiguous at apply time. If that happens, apply the row changes with explicit insert_row/delete_row edits.");let a=new Set,u={};for(let[p,_,g,w,k]of n)if(p==="delete")for(let b=_;b<g;b++)a.add(b);else if(p==="replace"){let b=Math.min(g-_,k-w);for(let m=_+b;m<g;m++)a.add(m);for(let m=0;m<b;m++)u[_+m]=l(i[w+m]);}let c=[];for(let p=0;p<s.length;p++)a.has(p)||c.push(p);let d=y(p=>u[p]!==void 0?u[p]:l(s[p]),"anchor_text"),f=y((p,_)=>{let g=[],w=c.filter(b=>b<_),k=c.filter(b=>b>=_);if(w.length>0){let b=w[w.length-1],m=d(b);for(let v of [...p].reverse())g.push({type:"insert_row",target_text:m,position:"below",cells:[...v.cells],_match_start_index:s[b].start});}else if(k.length>0){let b=k[0],m=d(b);for(let v of p)g.push({type:"insert_row",target_text:m,position:"above",cells:[...v.cells],_match_start_index:s[b].start});}else r.push("A table gained rows but no original row survives to anchor them; these row insertions were skipped \u2014 add them with explicit insert_row operations.");return g},"insert_ops"),h=[];for(let[p,_,g,w,k]of n)if(p!=="equal")if(p==="replace"){let b=Math.min(g-_,k-w);for(let v=0;v<b;v++){let N=l(s[_+v]),A=l(i[w+v]);N!==A&&h.push({type:"modify",target_text:N,new_text:A,comment:"Diff: Table row modified",_is_table_edit:true});}for(let v=_+b;v<g;v++)h.push({type:"delete_row",target_text:l(s[v]),_match_start_index:s[v].start});let m=i.slice(w+b,k);m.length>0&&h.push(...f(m,g));}else if(p==="delete")for(let b=_;b<g;b++)h.push({type:"delete_row",target_text:l(s[b]),_match_start_index:s[b].start});else p==="insert"&&h.push(...f(i.slice(w,k),_));return h}y(lo,"_row_ops_for_table");function Wr(t,e,n,r){let s=[],i=[],o=e.part_ranges.filter(([_,g])=>g>_).map(([,,_])=>_),l=r.part_ranges.filter(([_,g])=>g>_).map(([,,_])=>_);if(JSON.stringify(o)!==JSON.stringify(l))return s.push(`The documents have different part layouts (${o.join(" + ")||"none"} vs ${l.join(" + ")||"none"}); comparing flattened text instead. Header/footer additions or removals cannot be expressed as text edits.`),{edits:[...Qn(Xn(Jt(t,n),s),t,s)],warnings:s};let a=e.part_ranges.filter(([_,g])=>g>_).map(([_,g])=>[_,g]),u=r.part_ranges.filter(([_,g])=>g>_).map(([_,g])=>[_,g]);for(let _=0;_<a.length;_++){let[g,w]=a[_],[k,b]=u[_],m=e.tables.filter(x=>g<=x.start&&x.end<=w),v=r.tables.filter(x=>k<=x.start&&x.end<=b),N=m.length===v.length&&m.every(x=>Yn(t,x))&&v.every(x=>Yn(n,x));if(m.length!==v.length&&s.push(`A ${o[_]} part has ${m.length} table(s) in the original but ${v.length} in the modified document; its tables were compared as plain text. Adding or removing whole tables is not supported via diff/apply.`),!N){let x=Jt(t.substring(g,w),n.substring(k,b));for(let E of x)E._match_start_index=(E._match_start_index||0)+g;i.push(...x);continue}let A=[[g,g],...m.map(x=>[x.start,x.end]),[w,w]],C=[[k,k],...v.map(x=>[x.start,x.end]),[b,b]];for(let x=0;x<A.length-1;x++){let E=A[x][1],T=A[x+1][0],D=C[x][1],P=C[x+1][0],R=Jt(t.substring(E,T),n.substring(D,P));for(let $ of R)$._match_start_index=($._match_start_index||0)+E;if(i.push(...R),x<m.length){let $=m[x],S=v[x],j=ao($.rows,S.rows);if(j!==null)i.push(...lo($,S,j,s));else for(let F=0;F<$.rows.length;F++){let B=$.rows[F].cells.join(" | "),L=S.rows[F].cells.join(" | ");B!==L&&i.push({type:"modify",target_text:B,new_text:L,comment:"Diff: Table row modified",_is_table_edit:true});}}}}let c=y((_,g)=>{let w=0,k=0;for(;;){let b=_.indexOf(g,k);if(b===-1)break;w++,k=b+g.length;}return w},"countOccurrences"),d=false;for(let _ of i)(_.type==="insert_row"||_.type==="delete_row"||_._is_table_edit)&&!d&&_.target_text&&c(t,_.target_text)>1&&(s.push(`The row anchor "${_.target_text.substring(0,60)}" appears more than once in the document. Applying this diff from its JSON output may be rejected as ambiguous \u2014 make the anchor rows unique, or apply the row changes with explicit insert_row/delete_row edits.`),d=true);let f=i.filter(_=>_.type==="modify"),h=new Set(Qn(Xn(f,s),t,s));return {edits:i.filter(_=>_.type!=="modify"||h.has(_)),warnings:s}}y(Wr,"generate_structured_edits");function zr(t,e){let n=y(c=>{let d=new Map;try{let f=Be(c);for(let[h,p]of Object.entries(f)){if(!h.startsWith("word/media/"))continue;let _=2166136261,g=3421674724;for(let w=0;w<p.length;w++)_=Math.imul(_^p[w],16777619)>>>0,g=Math.imul(g^p[p.length-1-w],16777619)>>>0;d.set(h,`${p.length}:${_.toString(16)}:${g.toString(16)}`);}}catch{return new Map}return d},"media_hashes"),r=n(t),s=n(e),i=[],o=[],l=[];for(let[c,d]of r)s.has(c)?s.get(c)!==d&&i.push(c):l.push(c);for(let c of s.keys())r.has(c)||o.push(c);if(i.sort(),o.sort(),l.sort(),i.length+o.length+l.length===0)return [];let a=[];i.length&&a.push(`${i.length} changed`),o.length&&a.push(`${o.length} added`),l.length&&a.push(`${l.length} removed`);let u=[...i,...o,...l].slice(0,5).join(", ");return [`The documents' embedded media differ (${a.join(", ")}: ${u}). This diff compares TEXT only \u2014 an empty edit list does not mean the documents are visually identical. Image changes must be applied manually in Word.`]}y(zr,"collect_media_difference_warnings");function Lr(t,e,n=3){let r=new dn.default.diff_match_patch;r.Diff_Timeout=2;let s=r.diff_linesToChars_(t,e),i=r.diff_main(s.chars1,s.chars2,false);r.diff_charsToLines_(i,s.lineArray);let o=[];o.push("--- Original"),o.push("+++ Modified");let l=0;for(;l<i.length;){for(;l<i.length&&i[l][0]===0;)l++;if(l>=i.length)break;let a=l,u=[];a>0&&i[a-1][0]===0&&(u=i[a-1][1].replace(/\n$/,"").split(`
76
- `).slice(-n));let c=[];for(c.push(...u.map(f=>` ${f}`));l<i.length;){let[f,h]=i[l],p=h.replace(/\n$/,"").split(`
77
- `);if(f===0){if(p.length>n*2)break;c.push(...p.map(_=>` ${_}`));}else {let _=f===-1?"-":"+";c.push(...p.map(g=>`${_}${g}`));}l++;}let d=[];l<i.length&&i[l][0]===0&&(d=i[l][1].replace(/\n$/,"").split(`
75
+ `),b=wt(w,k);for(let g of b)g._match_start_index=(g._match_start_index||0)+m,c.push(g);}}return _o(c)}y(Xt,"generate_edits_via_paragraph_alignment");var gt=/!\[[^\]]*\]\(docx-image:[^)]*\)/g;function Yn(t,e){let n=y(s=>s.replace(gt,"").replace(/\s+/g," ").trim(),"_normalized"),r=[];for(let s of t){let i=((s.target_text||"").match(gt)||[]).sort(),o=((s.new_text||"").match(gt)||[]).sort();if(JSON.stringify(i)===JSON.stringify(o)){r.push(s);continue}n(s.target_text||"")===n(s.new_text||"")?e.push("An inline image was added or removed between the documents. Images cannot be transferred by text edits \u2014 the image-only difference was skipped; apply it manually in Word."):e.push("A text change overlapping an added/removed inline image was skipped \u2014 images cannot be transferred by text edits. Apply that section manually in Word.");}return r}y(Yn,"_drop_image_marker_hunks");function Gn(t,e,n){let r=[];for(let o of e.matchAll(gt))r.push([o.index,o.index+o[0].length]);if(r.length===0)return t;let s=[],i=false;for(let o of t){let a=o._match_start_index;if(a==null){s.push(o);continue}let l=a+(o.target_text||"").length;if(!r.some(([c,d])=>c<l&&a<d&&!(a<=c&&d<=l))){s.push(o);continue}i||(n.push("An image's alternative text differs between the documents. Image markers (![alt](docx-image:N)) are read-only projections, so this difference cannot be expressed as a text edit \u2014 it was skipped; update the image or its alt text manually in Word."),i=true);}return s}y(Gn,"_drop_marker_interior_hunks");function Vn(t,e){for(let n of e.rows)if(t.substring(n.start,n.end)!==n.cells.join(" | "))return false;return true}y(Vn,"_rows_are_plain");var tn="";function mo(t,e){let n=t.map(i=>i.cells.join(tn)),r=e.map(i=>i.cells.join(tn)),s=Ur(n,r);for(let[i,o,a,l,u]of s)if(i==="insert"||i==="delete"||i==="replace"&&a-o!==u-l)return s;return null}y(mo,"_table_row_opcodes");function go(t,e,n,r){let s=t.rows,i=e.rows,o=s.map(_=>_.cells.join(tn)),a=y(_=>_.cells.join(" | "),"row_text");new Set(o).size!==o.length&&r.push("A table contains rows with identical text; the generated row operations anchor by row text and may be rejected as ambiguous at apply time. If that happens, apply the row changes with explicit insert_row/delete_row edits.");let l=new Set,u={};for(let[_,p,m,w,k]of n)if(_==="delete")for(let b=p;b<m;b++)l.add(b);else if(_==="replace"){let b=Math.min(m-p,k-w);for(let g=p+b;g<m;g++)l.add(g);for(let g=0;g<b;g++)u[p+g]=a(i[w+g]);}let c=[];for(let _=0;_<s.length;_++)l.has(_)||c.push(_);let d=y(_=>u[_]!==void 0?u[_]:a(s[_]),"anchor_text"),f=y((_,p)=>{let m=[],w=c.filter(b=>b<p),k=c.filter(b=>b>=p);if(w.length>0){let b=w[w.length-1],g=d(b);for(let v of [..._].reverse())m.push({type:"insert_row",target_text:g,position:"below",cells:[...v.cells],_match_start_index:s[b].start});}else if(k.length>0){let b=k[0],g=d(b);for(let v of _)m.push({type:"insert_row",target_text:g,position:"above",cells:[...v.cells],_match_start_index:s[b].start});}else r.push("A table gained rows but no original row survives to anchor them; these row insertions were skipped \u2014 add them with explicit insert_row operations.");return m},"insert_ops"),h=[];for(let[_,p,m,w,k]of n)if(_!=="equal")if(_==="replace"){let b=Math.min(m-p,k-w);for(let v=0;v<b;v++){let x=a(s[p+v]),E=a(i[w+v]);x!==E&&h.push({type:"modify",target_text:x,new_text:E,comment:"Diff: Table row modified",_is_table_edit:true});}for(let v=p+b;v<m;v++)h.push({type:"delete_row",target_text:a(s[v]),_match_start_index:s[v].start});let g=i.slice(w+b,k);g.length>0&&h.push(...f(g,m));}else if(_==="delete")for(let b=p;b<m;b++)h.push({type:"delete_row",target_text:a(s[b]),_match_start_index:s[b].start});else _==="insert"&&h.push(...f(i.slice(w,k),p));return h}y(go,"_row_ops_for_table");function qr(t,e,n,r){let s=[],i=[],o=e.part_ranges.filter(([p,m])=>m>p).map(([,,p])=>p),a=r.part_ranges.filter(([p,m])=>m>p).map(([,,p])=>p);if(JSON.stringify(o)!==JSON.stringify(a))return s.push(`The documents have different part layouts (${o.join(" + ")||"none"} vs ${a.join(" + ")||"none"}); comparing flattened text instead. Header/footer additions or removals cannot be expressed as text edits.`),{edits:[...Gn(Yn(Xt(t,n),s),t,s)],warnings:s};let l=e.part_ranges.filter(([p,m])=>m>p).map(([p,m])=>[p,m]),u=r.part_ranges.filter(([p,m])=>m>p).map(([p,m])=>[p,m]);for(let p=0;p<l.length;p++){let[m,w]=l[p],[k,b]=u[p],g=e.tables.filter(A=>m<=A.start&&A.end<=w),v=r.tables.filter(A=>k<=A.start&&A.end<=b),x=g.length===v.length&&g.every(A=>Vn(t,A))&&v.every(A=>Vn(n,A));if(g.length!==v.length&&s.push(`A ${o[p]} part has ${g.length} table(s) in the original but ${v.length} in the modified document; its tables were compared as plain text. Adding or removing whole tables is not supported via diff/apply.`),!x){let A=Xt(t.substring(m,w),n.substring(k,b));for(let N of A)N._match_start_index=(N._match_start_index||0)+m;i.push(...A);continue}let E=[[m,m],...g.map(A=>[A.start,A.end]),[w,w]],C=[[k,k],...v.map(A=>[A.start,A.end]),[b,b]];for(let A=0;A<E.length-1;A++){let N=E[A][1],P=E[A+1][0],D=C[A][1],T=C[A+1][0],F=Xt(t.substring(N,P),n.substring(D,T));for(let I of F)I._match_start_index=(I._match_start_index||0)+N;if(i.push(...F),A<g.length){let I=g[A],S=v[A],R=mo(I.rows,S.rows);if(R!==null)i.push(...go(I,S,R,s));else for(let j=0;j<I.rows.length;j++){let B=I.rows[j].cells.join(" | "),L=S.rows[j].cells.join(" | ");B!==L&&i.push({type:"modify",target_text:B,new_text:L,comment:"Diff: Table row modified",_is_table_edit:true});}}}}let c=y((p,m)=>{let w=0,k=0;for(;;){let b=p.indexOf(m,k);if(b===-1)break;w++,k=b+m.length;}return w},"countOccurrences"),d=false;for(let p of i)(p.type==="insert_row"||p.type==="delete_row"||p._is_table_edit)&&!d&&p.target_text&&c(t,p.target_text)>1&&(s.push(`The row anchor "${p.target_text.substring(0,60)}" appears more than once in the document. Applying this diff from its JSON output may be rejected as ambiguous \u2014 make the anchor rows unique, or apply the row changes with explicit insert_row/delete_row edits.`),d=true);let f=i.filter(p=>p.type==="modify"),h=new Set(Gn(Yn(f,s),t,s));return {edits:i.filter(p=>p.type!=="modify"||h.has(p)),warnings:s}}y(qr,"generate_structured_edits");function Jr(t,e){let n=y(c=>{let d=new Map;try{let f=We(c);for(let[h,_]of Object.entries(f)){if(!h.startsWith("word/media/"))continue;let p=2166136261,m=3421674724;for(let w=0;w<_.length;w++)p=Math.imul(p^_[w],16777619)>>>0,m=Math.imul(m^_[_.length-1-w],16777619)>>>0;d.set(h,`${_.length}:${p.toString(16)}:${m.toString(16)}`);}}catch{return new Map}return d},"media_hashes"),r=n(t),s=n(e),i=[],o=[],a=[];for(let[c,d]of r)s.has(c)?s.get(c)!==d&&i.push(c):a.push(c);for(let c of s.keys())r.has(c)||o.push(c);if(i.sort(),o.sort(),a.sort(),i.length+o.length+a.length===0)return [];let l=[];i.length&&l.push(`${i.length} changed`),o.length&&l.push(`${o.length} added`),a.length&&l.push(`${a.length} removed`);let u=[...i,...o,...a].slice(0,5).join(", ");return [`The documents' embedded media differ (${l.join(", ")}: ${u}). This diff compares TEXT only \u2014 an empty edit list does not mean the documents are visually identical. Image changes must be applied manually in Word.`]}y(Jr,"collect_media_difference_warnings");function Hr(t,e,n=3){let r=new pn.default.diff_match_patch;r.Diff_Timeout=2;let s=r.diff_linesToChars_(t,e),i=r.diff_main(s.chars1,s.chars2,false);r.diff_charsToLines_(i,s.lineArray);let o=[];o.push("--- Original"),o.push("+++ Modified");let a=0;for(;a<i.length;){for(;a<i.length&&i[a][0]===0;)a++;if(a>=i.length)break;let l=a,u=[];l>0&&i[l-1][0]===0&&(u=i[l-1][1].replace(/\n$/,"").split(`
76
+ `).slice(-n));let c=[];for(c.push(...u.map(f=>` ${f}`));a<i.length;){let[f,h]=i[a],_=h.replace(/\n$/,"").split(`
77
+ `);if(f===0){if(_.length>n*2)break;c.push(..._.map(p=>` ${p}`));}else {let p=f===-1?"-":"+";c.push(..._.map(m=>`${p}${m}`));}a++;}let d=[];a<i.length&&i[a][0]===0&&(d=i[a][1].replace(/\n$/,"").split(`
78
78
  `).slice(0,n)),c.push(...d.map(f=>` ${f}`)),o.push("@@ ... @@"),o.push(...c);}return o.length===2?"":o.join(`
79
- `)}y(Lr,"create_unified_diff");var yt=/\{\+\+|\{--|\{==|\{>>|\+\+\}|--\}|==\}|<<\}/g,co={"{++":"++}","{--":"--}","{==":"==}","{>>":"<<}"};function Gn(t){if(!t)return true;if(/\{[=+\-><]?$/.test(t)||/^[=+\-><]?\}/.test(t))return false;let e=[];yt.lastIndex=0;let n;for(;(n=yt.exec(t))!==null;){let r=n[0];if(r.startsWith("{"))e.push(r);else if(e.length===0||co[e.pop()]!==r)return false}return e.length===0}y(Gn,"_critic_payload_atomic");function Ur(t,e,n,r){let s=true;for(;s;){s=false;for(let i of [t,e]){let o=i.length-r;yt.lastIndex=0;let l;for(;(l=yt.exec(i))!==null;){let a=l.index,u=l.index+l[0].length;if(n>a&&n<u&&(n=a,s=true),o>a&&o<u){r=i.length-u,s=true;break}}}}return [Math.max(0,n),Math.max(0,r)]}y(Ur,"_clamp_trim_outside_critic_tokens");function uo(t,e){let[n,r]=Ue(t,e);return [n,r]=Ur(t,e,n,r),[t.substring(n,t.length-r),e.substring(n,e.length-r)]}y(uo,"_word_patch_displays");function fo(t,e){let n=[],r=0;for(;r<t.length;){let s=t[r].target_text||"",i=t[r].new_text||"",o=t[r]._match_start_index||0,l=r+1;for(;;){let[a,u]=uo(s,i);if(Gn(a)&&Gn(u)||l>=t.length)break;let c=t[l],d=c._match_start_index||0,f=o+s.length,h=d>=f?e.substring(f,d):"";s=s+h+(c.target_text||""),i=i+h+(c.new_text||""),l++;}l>r+1?n.push({...t[r],target_text:s,new_text:i,_match_start_index:o}):n.push(t[r]),r=l;}return n}y(fo,"_merge_critic_split_hunks");function qr(t,e,n="Original",r="Modified"){let s=fo(wt(t,e),t),i=[`--- ${n}`,`+++ ${r}`,""],o=40;for(let l of s){let a=l._match_start_index||0,u=l.target_text||"",c=l.new_text||"",[d,f]=Ue(u,c);[d,f]=Ur(u,c,d,f);let h=u.length-f,p=c.length-f,_=u.substring(d,h),g=c.substring(d,p),w=a+d,k=w+_.length,b=Math.max(0,w-o),m=t.substring(b,w);b>0&&(m="..."+m);let v=Math.min(t.length,k+o),N=t.substring(k,v);v<t.length&&(N=N+"..."),m=m.replace(/\n/g," ").replace(/\r/g,""),N=N.replace(/\n/g," ").replace(/\r/g,""),i.push("@@ Word Patch @@"),i.push(` ${m}`),_&&i.push(`- ${_}`),g&&i.push(`+ ${g}`),i.push(` ${N}`),i.push("");}return i.join(`
80
- `)}y(qr,"create_word_patch_diff");var Vn=19e3,ho="<!-- READONLY_BOUNDARY_START -->",Zn={"{++":"++}","{--":"--}","{==":"==}","{>>":"<<}"},po=/\bChg:(\d+)\b/g;function Je(t){if(!t)return ["",""];let e=t.indexOf(ho);if(e===-1)return [t,""];let n=t.lastIndexOf(`
81
- `,e)+1,r=t.substring(0,n).trimEnd(),s=t.substring(n);return [r,s]}y(Je,"split_structural_appendix");function He(t,e=""){if(!t){let u=e?e.trim():"";return {pages:[{page:1,total_pages:1,has_next:false,has_prev:false,tracked_change_count:Kn(u),page_content:u}],total_pages:1,body_pages:[""],body_page_offsets:[0]}}let n=_o(t),[r,s]=wo(n),i;if(e&&e.trim()){let a=e.trim();i=r.map(u=>u?`${u}
79
+ `)}y(Hr,"create_unified_diff");var yt=/\{\+\+|\{--|\{==|\{>>|\+\+\}|--\}|==\}|<<\}/g,wo={"{++":"++}","{--":"--}","{==":"==}","{>>":"<<}"};function Zn(t){if(!t)return true;if(/\{[=+\-><]?$/.test(t)||/^[=+\-><]?\}/.test(t))return false;let e=[];yt.lastIndex=0;let n;for(;(n=yt.exec(t))!==null;){let r=n[0];if(r.startsWith("{"))e.push(r);else if(e.length===0||wo[e.pop()]!==r)return false}return e.length===0}y(Zn,"_critic_payload_atomic");function Xr(t,e,n,r){let s=true;for(;s;){s=false;for(let i of [t,e]){let o=i.length-r;yt.lastIndex=0;let a;for(;(a=yt.exec(i))!==null;){let l=a.index,u=a.index+a[0].length;if(n>l&&n<u&&(n=l,s=true),o>l&&o<u){r=i.length-u,s=true;break}}}}return [Math.max(0,n),Math.max(0,r)]}y(Xr,"_clamp_trim_outside_critic_tokens");function yo(t,e){let[n,r]=qe(t,e);return [n,r]=Xr(t,e,n,r),[t.substring(n,t.length-r),e.substring(n,e.length-r)]}y(yo,"_word_patch_displays");function vo(t,e){let n=[],r=0;for(;r<t.length;){let s=t[r].target_text||"",i=t[r].new_text||"",o=t[r]._match_start_index||0,a=r+1;for(;;){let[l,u]=yo(s,i);if(Zn(l)&&Zn(u)||a>=t.length)break;let c=t[a],d=c._match_start_index||0,f=o+s.length,h=d>=f?e.substring(f,d):"";s=s+h+(c.target_text||""),i=i+h+(c.new_text||""),a++;}a>r+1?n.push({...t[r],target_text:s,new_text:i,_match_start_index:o}):n.push(t[r]),r=a;}return n}y(vo,"_merge_critic_split_hunks");function Qr(t,e,n="Original",r="Modified"){let s=vo(wt(t,e),t),i=[`--- ${n}`,`+++ ${r}`,""],o=40;for(let a of s){let l=a._match_start_index||0,u=a.target_text||"",c=a.new_text||"",[d,f]=qe(u,c);[d,f]=Xr(u,c,d,f);let h=u.length-f,_=c.length-f,p=u.substring(d,h),m=c.substring(d,_),w=l+d,k=w+p.length,b=Math.max(0,w-o),g=t.substring(b,w);b>0&&(g="..."+g);let v=Math.min(t.length,k+o),x=t.substring(k,v);v<t.length&&(x=x+"..."),g=g.replace(/\n/g," ").replace(/\r/g,""),x=x.replace(/\n/g," ").replace(/\r/g,""),i.push("@@ Word Patch @@"),i.push(` ${g}`),p&&i.push(`- ${p}`),m&&i.push(`+ ${m}`),i.push(` ${x}`),i.push("");}return i.join(`
80
+ `)}y(Qr,"create_word_patch_diff");var Kn=19e3,bo="<!-- READONLY_BOUNDARY_START -->",er={"{++":"++}","{--":"--}","{==":"==}","{>>":"<<}"},xo=/\bChg:(\d+)\b/g;function He(t){if(!t)return ["",""];let e=t.indexOf(bo);if(e===-1)return [t,""];let n=t.lastIndexOf(`
81
+ `,e)+1,r=t.substring(0,n).trimEnd(),s=t.substring(n);return [r,s]}y(He,"split_structural_appendix");function Xe(t,e=""){if(!t){let u=e?e.trim():"";return {pages:[{page:1,total_pages:1,has_next:false,has_prev:false,tracked_change_count:tr(u),page_content:u}],total_pages:1,body_pages:[""],body_page_offsets:[0]}}let n=No(t),[r,s]=Ao(n),i;if(e&&e.trim()){let l=e.trim();i=r.map(u=>u?`${u}
82
82
 
83
- ${a}`:a);}else i=[...r];let o=i.length;return {pages:i.map((a,u)=>({page:u+1,total_pages:o,has_next:u+1<o,has_prev:u+1>1,tracked_change_count:Kn(a),page_content:a})),total_pages:o,body_pages:r,body_page_offsets:s}}y(He,"paginate");function _o(t){let e=mo(t);return go(e)}y(_o,"_tokenize_into_atomic_blocks");function mo(t){let e={"++}":0,"--}":0,"==}":0,"<<}":0},n=[],r=0,s=0,i=t.length;for(;s<i;){let o=false;for(let[a,u]of Object.entries(Zn))if(t.startsWith(a,s)){e[u]++,s+=a.length,o=true;break}if(o)continue;let l=false;for(let a of Object.values(Zn))if(t.startsWith(a,s)){e[a]>0&&e[a]--,s+=a.length,l=true;break}if(!l){if(t[s]===`
83
+ ${l}`:l);}else i=[...r];let o=i.length;return {pages:i.map((l,u)=>({page:u+1,total_pages:o,has_next:u+1<o,has_prev:u+1>1,tracked_change_count:tr(l),page_content:l})),total_pages:o,body_pages:r,body_page_offsets:s}}y(Xe,"paginate");function No(t){let e=ko(t);return Eo(e)}y(No,"_tokenize_into_atomic_blocks");function ko(t){let e={"++}":0,"--}":0,"==}":0,"<<}":0},n=[],r=0,s=0,i=t.length;for(;s<i;){let o=false;for(let[l,u]of Object.entries(er))if(t.startsWith(l,s)){e[u]++,s+=l.length,o=true;break}if(o)continue;let a=false;for(let l of Object.values(er))if(t.startsWith(l,s)){e[l]>0&&e[l]--,s+=l.length,a=true;break}if(!a){if(t[s]===`
84
84
  `&&s+1<i&&t[s+1]===`
85
- `&&Object.values(e).every(a=>a===0)){let a=t.substring(r,s);a&&n.push([a,r]);let u=s;for(;u<i&&t[u]===`
86
- `;)u++;s=u,r=s;continue}s++;}}if(r<i){let o=t.substring(r,i);o&&n.push([o,r]);}return n}y(mo,"_split_on_safe_paragraph_breaks");function go(t){if(!t.length)return t;let e=[],n=0;for(;n<t.length;){let[r,s]=t[n],i=r.trimStart();if(!(i.startsWith("## Footnotes")||i.startsWith("## Endnotes"))){e.push([r,s]),n++;continue}let l=r,a=n+1;for(;a<t.length;){let[u]=t[a],c=u.trimStart();if(c.startsWith("[^fn-")||c.startsWith("[^en-"))l=`${l}
85
+ `&&Object.values(e).every(l=>l===0)){let l=t.substring(r,s);l&&n.push([l,r]);let u=s;for(;u<i&&t[u]===`
86
+ `;)u++;s=u,r=s;continue}s++;}}if(r<i){let o=t.substring(r,i);o&&n.push([o,r]);}return n}y(ko,"_split_on_safe_paragraph_breaks");function Eo(t){if(!t.length)return t;let e=[],n=0;for(;n<t.length;){let[r,s]=t[n],i=r.trimStart();if(!(i.startsWith("## Footnotes")||i.startsWith("## Endnotes"))){e.push([r,s]),n++;continue}let a=r,l=n+1;for(;l<t.length;){let[u]=t[l],c=u.trimStart();if(c.startsWith("[^fn-")||c.startsWith("[^en-"))a=`${a}
87
87
 
88
- ${u}`,a++;else break}e.push([l,s]),n=a;}return e}y(go,"_merge_footnote_sections");function wo(t){if(!t.length)return [[""],[0]];let e=[],n=[],r=[],s=0,i=-1,o=y(()=>{r.length>0&&(e.push(r.join(`
88
+ ${u}`,l++;else break}e.push([a,s]),n=l;}return e}y(Eo,"_merge_footnote_sections");function Ao(t){if(!t.length)return [[""],[0]];let e=[],n=[],r=[],s=0,i=-1,o=y(()=>{r.length>0&&(e.push(r.join(`
89
89
 
90
- `)),n.push(i)),r=[],s=0,i=-1;},"flush_current");for(let[l,a]of t){let u=l.length,c=u+(r.length>0?2:0);if(r.length>0&&s+c>Vn&&o(),r.length===0&&u>Vn){e.push(l),n.push(a);continue}r.length===0&&(i=a),r.push(l),s+=s>0?c:u;}return o(),e.length?[e,n]:[[""],[0]]}y(wo,"_assemble_pages");function Kn(t){let e=[...t.matchAll(po)];return new Set(e.map(r=>r[1])).size}y(Kn,"_count_tracked_changes");var yo=5,er=50;function vo(t,e,n,r){let s=r.length;if(s<2)throw new Error(`format_ambiguity_error requires at least 2 matches, got ${s}`);let i=r.slice(0,yo),o=s-i.length,l=[`- Edit ${t} Failed: Ambiguous match. Target text appears ${s} times. First ${i.length} occurrences:`];for(let a=0;a<i.length;a++){let[u,c]=i[a],d=Math.max(0,u-er),f=Math.min(n.length,c+er),h=n.substring(d,u).replace(/\n/g," "),p=n.substring(c,f).replace(/\n/g," "),_=n.substring(u,c).replace(/\n/g," ");_.length>50&&(_=_.substring(0,25)+"..."+_.substring(_.length-20));let g=d>0?"...":"",w=f<n.length?"...":"";l.push(` ${a+1}. "${g}${h}[${_}]${p}${w}"`);}return o>0&&l.push(` ... and ${o} more occurrence(s) not shown.`),l.push(" To resolve, re-send this edit using ONE of these strategies:"),l.push(' 1. RECOMMENDED: Provide more surrounding context in your target_text to uniquely identify a single location (keep the default "match_mode": "strict").'),l.push(` 2. Set "match_mode": "all" to modify ALL ${s} occurrences \u2014 only after verifying from the occurrence list above that EVERY occurrence should change.`),l.push(' 3. Set "match_mode": "first" to modify only the FIRST occurrence \u2014 only after verifying the first occurrence above is the one you intend to change.'),l.join(`
91
- `)}y(vo,"format_ambiguity_error");var ye=30;function ve(t){let e=t.nextSibling;for(;e;){if(e.nodeType===1)return e;e=e.nextSibling;}return null}y(ve,"getNextElement");function Ee(t){let e=t.previousSibling;for(;e;){if(e.nodeType===1)return e;e=e.previousSibling;}return null}y(Ee,"getPreviousElement");function Le(t,e){e.parentNode&&e.parentNode.insertBefore(t,e.nextSibling);}y(Le,"insertAfter");function bo(t){let e=[...t.pkg.parts],n={...t.pkg.unzipped},r=new Map,s=new Map,i=new Set;for(let o of e){if(r.set(o,new Map(o.rels)),!o._element)continue;let l=o._element.ownerDocument;l&&sn(l)&&typeof o.blob=="string"?i.add(o):s.set(o,o._element.cloneNode(true));}return {parts:e,unzipped:n,rels:r,elements:s,blobRestores:i}}y(bo,"takeSnapshot");function xo(t,e){t.pkg.parts=[...e.parts];for(let n of Object.keys(t.pkg.unzipped))delete t.pkg.unzipped[n];for(let[n,r]of Object.entries(e.unzipped))t.pkg.unzipped[n]=r;for(let n of e.parts){if(n.rels=new Map(e.rels.get(n)),e.blobRestores&&e.blobRestores.has(n)){let s=qe(n.blob);tt(s),n._element=s.documentElement;continue}let r=e.elements.get(n);if(r&&n._element){let s=n._element.ownerDocument;s&&s.documentElement&&s.replaceChild(r,s.documentElement),n._element=r;}}}y(xo,"restoreSnapshot");function No(t,e){if(!t||!e)return [t,e];let n=t.match(/^(#+)\s+/),r=e.match(/^(#+)\s+/);if(n&&r&&n[1]===r[1]){let s=n[1],i=t.substring(s.length).trimStart(),o=e.substring(s.length).trimStart();return [i,o]}return [t,e]}y(No,"stripMatchingHeadingHashes");var pt=class extends Error{static{y(this,"BatchValidationError");}errors;constructor(t){super(`Batch validation failed:
90
+ `)),n.push(i)),r=[],s=0,i=-1;},"flush_current");for(let[a,l]of t){let u=a.length,c=u+(r.length>0?2:0);if(r.length>0&&s+c>Kn&&o(),r.length===0&&u>Kn){e.push(a),n.push(l);continue}r.length===0&&(i=l),r.push(a),s+=s>0?c:u;}return o(),e.length?[e,n]:[[""],[0]]}y(Ao,"_assemble_pages");function tr(t){let e=[...t.matchAll(xo)];return new Set(e.map(r=>r[1])).size}y(tr,"_count_tracked_changes");var Co=5,nr=50;function Po(t,e,n,r){let s=r.length;if(s<2)throw new Error(`format_ambiguity_error requires at least 2 matches, got ${s}`);let i=r.slice(0,Co),o=s-i.length,a=[`- Edit ${t} Failed: Ambiguous match. Target text appears ${s} times. First ${i.length} occurrences:`];for(let l=0;l<i.length;l++){let[u,c]=i[l],d=Math.max(0,u-nr),f=Math.min(n.length,c+nr),h=n.substring(d,u).replace(/\n/g," "),_=n.substring(c,f).replace(/\n/g," "),p=n.substring(u,c).replace(/\n/g," ");p.length>50&&(p=p.substring(0,25)+"..."+p.substring(p.length-20));let m=d>0?"...":"",w=f<n.length?"...":"";a.push(` ${l+1}. "${m}${h}[${p}]${_}${w}"`);}return o>0&&a.push(` ... and ${o} more occurrence(s) not shown.`),a.push(" To resolve, re-send this edit using ONE of these strategies:"),a.push(' 1. RECOMMENDED: Provide more surrounding context in your target_text to uniquely identify a single location (keep the default "match_mode": "strict").'),a.push(` 2. Set "match_mode": "all" to modify ALL ${s} occurrences \u2014 only after verifying from the occurrence list above that EVERY occurrence should change.`),a.push(' 3. Set "match_mode": "first" to modify only the FIRST occurrence \u2014 only after verifying the first occurrence above is the one you intend to change.'),a.join(`
91
+ `)}y(Po,"format_ambiguity_error");var ye=30;function ve(t){let e=t.nextSibling;for(;e;){if(e.nodeType===1)return e;e=e.nextSibling;}return null}y(ve,"getNextElement");function Ee(t){let e=t.previousSibling;for(;e;){if(e.nodeType===1)return e;e=e.previousSibling;}return null}y(Ee,"getPreviousElement");function Ue(t,e){e.parentNode&&e.parentNode.insertBefore(t,e.nextSibling);}y(Ue,"insertAfter");function To(t){let e=[...t.pkg.parts],n={...t.pkg.unzipped},r=new Map,s=new Map,i=new Set;for(let o of e){if(r.set(o,new Map(o.rels)),!o._element)continue;let a=o._element.ownerDocument;a&&ln(a)&&typeof o.blob=="string"?i.add(o):s.set(o,o._element.cloneNode(true));}return {parts:e,unzipped:n,rels:r,elements:s,blobRestores:i}}y(To,"takeSnapshot");function So(t,e){t.pkg.parts=[...e.parts];for(let n of Object.keys(t.pkg.unzipped))delete t.pkg.unzipped[n];for(let[n,r]of Object.entries(e.unzipped))t.pkg.unzipped[n]=r;for(let n of e.parts){if(n.rels=new Map(e.rels.get(n)),e.blobRestores&&e.blobRestores.has(n)){let s=Je(n.blob);tt(s),n._element=s.documentElement;continue}let r=e.elements.get(n);if(r&&n._element){let s=n._element.ownerDocument;s&&s.documentElement&&s.replaceChild(r,s.documentElement),n._element=r;}}}y(So,"restoreSnapshot");function Io(t,e){if(!t||!e)return [t,e];let n=t.match(/^(#+)\s+/),r=e.match(/^(#+)\s+/);if(n&&r&&n[1]===r[1]){let s=n[1],i=t.substring(s.length).trimStart(),o=e.substring(s.length).trimStart();return [i,o]}return [t,e]}y(Io,"stripMatchingHeadingHashes");var pt=class extends Error{static{y(this,"BatchValidationError");}errors;constructor(t){super(`Batch validation failed:
92
92
  `+t.join(`
93
- `)),this.name="BatchValidationError",this.errors=t;}};function tr(t){return `
94
- Note: ${t} earlier edit(s) in this batch validated against the intermediate document state; because this batch failed, it was rolled back and nothing was saved. Batches apply sequentially \u2014 each edit must target the document text as it reads AFTER the preceding edits (e.g. target the replacement text an earlier edit introduced, not the original wording).`}y(tr,"sequential_context_hint");var ko=/[\x00-\x08\x0b\x0c\x0e-\x1f]/g,Eo={"w:sectPr":new Set(["w:headerReference","w:footerReference"])},Kt=["w:ins","w:del"],en=["w:pPrChange","w:rPrChange","w:sectPrChange"],nr=[...Kt,...en];function Ao(t){if(!t)return null;let e=t.match(ko);return e?Array.from(new Set(e.map(r=>`0x${r.charCodeAt(0).toString(16).padStart(2,"0")}`))).sort().join(", "):null}y(Ao,"describe_illegal_control_chars");function Co(t,e=0){let n=[];for(let r=0;r<t.length;r++){let s=t[r],i=s.target_text||"",o=s.new_text||"",l=[["target_text",i],["new_text",o]];s.comment&&l.push(["comment",s.comment]),(s.cells||[]).forEach((a,u)=>{l.push([`cells[${u}]`,a||""]);});for(let[a,u]of l){let c=Ao(u);c&&n.push(`- Edit ${r+1+e} Failed: \`${a}\` contains control character(s) (${c}) that cannot be stored in a DOCX. Remove them and re-submit.`);}if((o.includes("{++")||o.includes("{--")||o.includes("{>>")||o.includes("{=="))&&n.push(`- Edit ${r+1+e} Failed: Do not manually write CriticMarkup tags ({++, {--, {>>, {==) in \`new_text\`. The engine handles redlining automatically. To add a comment, use the \`comment\` parameter.`),i.includes("[^")||o.includes("[^")){let a=(i.match(/\[\^(?:fn|en)-[^\]]+\]/g)||[]).sort(),u=(o.match(/\[\^(?:fn|en)-[^\]]+\]/g)||[]).sort();JSON.stringify(a)!==JSON.stringify(u)&&(u.length>a.length||u.some(c=>u.filter(d=>d===c).length>a.filter(d=>d===c).length)?n.push(`- Edit ${r+1+e} Failed: Cannot insert footnote/endnote markers via text replace. Markers like \`[^fn-N]\` are read-only projections. Use Word's References menu.`):n.push(`- Edit ${r+1+e} Failed: Cannot delete footnote/endnote references via text replace. The marker corresponds to a structural XML element.`));}if(i.includes("](")||o.includes("](")){let a=(i.match(/\[(?!~)[^\]]+\]\([^)]+\)/g)||[]).sort(),u=(o.match(/\[(?!~)[^\]]+\]\([^)]+\)/g)||[]).sort();a.length!==u.length?u.length>a.length?n.push(`- Edit ${r+1+e} Failed: Cannot insert hyperlinks via text replace. Inserting new hyperlinks is not supported; insert the display text instead (editing the text or URL of an existing link IS supported).`):n.push(`- Edit ${r+1+e} Failed: Cannot delete hyperlinks via text replace. The marker corresponds to a structural XML element.`):a.length>1&&JSON.stringify(a)!==JSON.stringify(u)&&n.push(`- Edit ${r+1+e} Failed: Can only edit or retarget one hyperlink per text replacement. Please split into multiple edits.`);}if(i.includes("[~")||o.includes("[~")){let a=i.match(/\[~[^~]+~\]\(#[^\)]+\)/g)||[],u=o.match(/\[~[^~]+~\]\(#[^\)]+\)/g)||[];a.length!==u.length?u.length>a.length?n.push(`- Edit ${r+1+e} Failed: Cannot insert cross-references via text replace. Markers are read-only projections.`):n.push(`- Edit ${r+1+e} Failed: Cannot delete cross-references via text replace. The marker corresponds to a structural XML element.`):JSON.stringify(a)!==JSON.stringify(u)&&n.push(`- Edit ${r+1+e} Failed: Modifying or retargeting cross-reference markers is disallowed to prevent dependency corruption.`);}if(i.includes("docx-image:")||o.includes("docx-image:")){let a=(i.match(/!\[[^\]]*\]\(docx-image:[^)]*\)/g)||[]).sort(),u=(o.match(/!\[[^\]]*\]\(docx-image:[^)]*\)/g)||[]).sort();JSON.stringify(a)!==JSON.stringify(u)&&n.push(`- Edit ${r+1+e} Failed: image markers (![alt](docx-image:N)) are read-only projections of embedded images. They cannot be inserted, altered, or removed via text replacement \u2014 edit the text around the image instead.`);}if(i.includes("{#")||o.includes("{#")){let a=i.match(/\{#[^\}]+\}/g)||[],u=o.match(/\{#[^\}]+\}/g)||[];for(let c of u)if(u.filter(d=>d===c).length>a.filter(d=>d===c).length){n.push(`- Edit ${r+1+e} Failed: Cannot modify or insert internal anchor markers (\`{#...}\`). These represent structural XML bookmarks.`);break}}if(s.type==="modify"&&o){let a=o.split(/[\r\n]+/);for(let u of a){let c=u.trimStart();if(c.startsWith("#######")){let d=c.length-c.replace(/^#+/,"").length;if(c.substring(d).startsWith(" ")||c.substring(d)===""){n.push(`- Edit ${r+1+e} Failed: Heading level ${d} is not supported (maximum is 6).`);break}}}}(i.includes("READONLY_BOUNDARY_START")||o.includes("READONLY_BOUNDARY_START")||i.includes("# Document Structure (Read-Only)")||o.includes("# Document Structure (Read-Only)")||i.includes("Document Structure (Read-Only)")||o.includes("Document Structure (Read-Only)"))&&n.push(`- Edit ${r+1+e} Failed: Modification targets the read-only boundary (Structural Appendix). This section cannot be edited.`);}return n}y(Co,"validate_edit_strings");var fn=class V{static{y(this,"_RedlineEngine");}doc;author;timestamp;current_id;mapper;comments_manager;clean_mapper=null;original_mapper=null;skipped_details=[];_revisionIndex=null;constructor(e,n="Adeu AI (TS)"){this.doc=e,this.author=n,this.timestamp=new Date().toISOString().replace(/\.\d{3}Z$/,"Z");let r="http://schemas.microsoft.com/office/word/2023/wordml/word16du";for(let s of this.doc.pkg.parts)if(s===this.doc.part&&!s._element.hasAttribute("xmlns:w16du")){let i=s._element.ownerDocument,o=sn(i);s._element.setAttribute("xmlns:w16du",r),o&&tt(i);}this.current_id=this._scan_existing_ids(),this.mapper=new ke(this.doc),this.comments_manager=new nt(this.doc);}_check_punctuation_warning(e){return !e||e.length>20||e.includes(" ")?null:e.includes("_")||e.includes("-")?`Warning: target_text '${e}' contains tokenization-splitting punctuation ('_' or '-'). This can trigger mid-word splits in the diff engine. Consider using a longer plain-prose anchor.`:null}_single_commented_sub_edit(e,n,r,s,i,o){let l,a,u,c;if(e===n)l=e,a=n,u=r,c="COMMENT_ONLY";else {let[f,h]=Ue(e,n);l=e.slice(f,e.length-h),a=n.slice(f,n.length-h),u=r+f,!l&&a?c="INSERTION":l&&!a?c="DELETION":c="MODIFICATION";}let d={type:"modify",target_text:l,new_text:a,comment:s};return d._resolved_start_idx=u,d._match_start_index=u,d._active_mapper_ref=o,d._internal_op=c,i&&(d._is_table_edit=true),[d]}_word_diff_sub_edits(e,n,r,s=null,i=false,o=null){if(s!=null)return this._single_commented_sub_edit(e,n,r,s,i,o);let l=[];try{l=wt(e,n);}catch{l=[];}let a=y(d=>{let f=d.trim();return f.length>0&&/^[*_]+$/.test(f)},"_marker_only");if(l=l.filter(d=>!((!d.target_text||a(d.target_text))&&(!d.new_text||a(d.new_text))&&(d.target_text||d.new_text))),!l||l.length===0){let d={type:"modify",target_text:e,new_text:n,comment:s};return d._resolved_start_idx=r,d._match_start_index=r,d._active_mapper_ref=o,i&&(d._is_table_edit=true),e===n?d._internal_op="COMMENT_ONLY":!e&&n?d._internal_op="INSERTION":e&&!n?d._internal_op="DELETION":e&&n?d._internal_op="MODIFICATION":d._internal_op="COMMENT_ONLY",[d]}let u=[],c=false;for(let d of l){let f=r+(d._match_start_index||0),h=s!==null&&!c;h&&(c=true);let p={type:"modify",target_text:d.target_text,new_text:d.new_text,comment:h?s:null};p._resolved_start_idx=f,p._match_start_index=f,p._active_mapper_ref=o,i&&(p._is_table_edit=true);let _=d.target_text,g=d.new_text;!_&&g?p._internal_op="INSERTION":_&&!g?p._internal_op="DELETION":_&&g?p._internal_op="MODIFICATION":p._internal_op="COMMENT_ONLY",u.push(p);}return u}_nearest_match_hint(e,n){if(!e)return "";let r=e;if(n&&(r=r.replace(/^\^/,"").replace(/\$$/,""),r=r.replace(/^\\s\*/,"").replace(/\\s\*$/,""),r=r.replace(/\\([.^$*+?()[\]{}|\\/])/g,"$1")),r=r.trim(),(!r||r===e)&&!n)return "";let s=this.mapper.full_text.indexOf(r);if(s!==-1){let i=Math.max(0,s-15),o=Math.min(this.mapper.full_text.length,s+r.length+15),l=this.mapper.full_text.substring(i,o).replace(/\n/g," ");return `
95
- Did you mean the literal "${r}"? It appears in the document (\u2026${l}\u2026). If you used a regex, drop the ^/$ anchors \u2014 they match the start/end of the entire document, not a line.`}return ""}static _PREVIEW_WRAPPER_PAIRS=[["{--","--}"],["{++","++}"],["{==","==}"],["{>>","<<}"]];static _tidy_preview_context(e,n){e=e.replace(/\{>>[\s\S]*?<<\}/g,"");for(let[r,s]of V._PREVIEW_WRAPPER_PAIRS)if(n==="before"){let i=0,o=0,l=0;for(;l<e.length;)e.startsWith(r,l)?(i+=1,l+=r.length):e.startsWith(s,l)?(i===0?o=l+s.length:i-=1,l+=s.length):l+=1;e=e.substring(o);}else {let i=[],o=0;for(;o<e.length;)e.startsWith(r,o)?(i.push(o),o+=r.length):e.startsWith(s,o)?(i.length>0&&i.pop(),o+=s.length):o+=1;i.length>0&&(e=e.substring(0,i[0]));}return n==="before"?e=e.replace(/^[-+=<>]{0,2}\}/,""):e=e.replace(/\{[-+=<>]{0,2}$/,""),e}_capture_preview_context(e){if(e.type!=="modify")return;let n=e._resolved_start_idx;if(n==null)return;let s=(e._active_mapper_ref||this.mapper).full_text;if(!s)return;let i=(e.target_text||"").length,o=s.substring(Math.max(0,n-ye),n),l=s.substring(n+i,n+i+ye);e._preview_context=[V._tidy_preview_context(o,"before"),V._tidy_preview_context(l,"after")];}_capture_parent_preview_context(e){if(!e||e.type!=="modify"||e._preview_context||!e._preview_span)return;let[n,r]=e._preview_span,i=(e._preview_mapper_ref||this.mapper).full_text;if(!i)return;let o=i.substring(Math.max(0,n-ye),n),l=i.substring(n+r,n+r+ye);e._preview_context=[V._tidy_preview_context(o,"before"),V._tidy_preview_context(l,"after")];}_build_full_match_preview(e){let[n,r]=e._preview_context,s=e._preview_matched_text||"",i=e._preview_new_text!==void 0&&e._preview_new_text!==null?e._preview_new_text:e.new_text||"",[o,l]=this._parse_markdown_style(s),[a,u]=this._parse_markdown_style(i);l&&l.startsWith("Heading")&&(n=n+s.substring(0,s.length-o.length),s=o),u&&u.startsWith("Heading")&&(i=a);let[c,d]=Ue(s,i),f=s.substring(c,s.length-d),h=i.substring(c,i.length-d);n=n+s.substring(0,c),d&&(r=s.substring(s.length-d)+r),f=he(f,ze),h=he(h,ze);let p;if(!f&&!h){let g=he(s,ze),w=g?`{==${g}==}`:"";p=`${n.substring(0,n.length-s.length)}${w}${r}`;}else {let g=f?`{--${f}--}`:"",w=h?`{++${h}++}`:"";p=`${n}${g}${w}${r}`;}let _=p;return _=_.replace(/\{>>[\s\S]*?<<\}/g,""),_=_.replace(/\{--[\s\S]*?--\}/g,""),_=_.replace(/\{\+\+([\s\S]*?)\+\+\}/g,"$1"),[p,_]}static _report_new_text(e){return e&&e.type==="insert_row"&&Array.isArray(e.cells)?e.cells.join(" | "):e&&e.new_text||""}_build_postapply_previews(e){let n=new Set((e._minted_change_ids||[]).map(w=>String(w))),r=new Set((e._minted_comment_ids||[]).map(w=>String(w)));if(n.size===0&&r.size===0)return null;let s=this.mapper;s.full_text||s._build_map();let i=s.full_text;if(!i)return null;let o=[];for(let w of s.spans)(w.ins_id&&n.has(String(w.ins_id))||w.del_id&&n.has(String(w.del_id))||r.size>0&&w.comment_ids&&w.comment_ids.some(b=>r.has(String(b))))&&o.push([w.start,w.end]);if(o.length===0)return null;let l=/\{>>[\s\S]*?<<\}/g,a=[],u;for(;(u=l.exec(i))!==null;)a.push([u.index,u.index+u[0].length]);let c=i,d=y(w=>w,"to_visible");if(a.length>0){let w=[],k=0;for(let[b,m]of a)w.push(i.substring(k,b)),k=m;w.push(i.substring(k)),c=w.join(""),d=y(b=>{let m=0;for(let[v,N]of a)if(b>=N)m+=N-v;else if(b>v){m+=b-v;break}else break;return b-m},"to_visible");}o.sort((w,k)=>w[0]-k[0]);let f=[];for(let[w,k]of o){let b=d(w),m=d(k),v=Math.max(0,b-ye),N=Math.min(c.length,m+ye),A=f.length>0?f[f.length-1]:null;A&&v<=A[1]?A[1]=Math.max(A[1],N):f.push([v,N]);}let h=[];for(let[w,k]of f){let b=c.substring(w,k);b=V._tidy_preview_context(b,"before"),b=V._tidy_preview_context(b,"after"),h.push(b);}let p=h.join(`
93
+ `)),this.name="BatchValidationError",this.errors=t;}};function rr(t){return `
94
+ Note: ${t} earlier edit(s) in this batch validated against the intermediate document state; because this batch failed, it was rolled back and nothing was saved. Batches apply sequentially \u2014 each edit must target the document text as it reads AFTER the preceding edits (e.g. target the replacement text an earlier edit introduced, not the original wording).`}y(rr,"sequential_context_hint");var $o=/[\x00-\x08\x0b\x0c\x0e-\x1f]/g,Oo={"w:sectPr":new Set(["w:headerReference","w:footerReference"])},nn=["w:ins","w:del"],rn=["w:pPrChange","w:rPrChange","w:sectPrChange"],ir=[...nn,...rn];function Do(t){if(!t)return null;let e=t.match($o);return e?Array.from(new Set(e.map(r=>`0x${r.charCodeAt(0).toString(16).padStart(2,"0")}`))).sort().join(", "):null}y(Do,"describe_illegal_control_chars");function Mo(t,e=0){let n=[];for(let r=0;r<t.length;r++){let s=t[r],i=s.target_text||"",o=s.new_text||"",a=[["target_text",i],["new_text",o]];s.comment&&a.push(["comment",s.comment]),(s.cells||[]).forEach((l,u)=>{a.push([`cells[${u}]`,l||""]);});for(let[l,u]of a){let c=Do(u);c&&n.push(`- Edit ${r+1+e} Failed: \`${l}\` contains control character(s) (${c}) that cannot be stored in a DOCX. Remove them and re-submit.`);}if((o.includes("{++")||o.includes("{--")||o.includes("{>>")||o.includes("{=="))&&n.push(`- Edit ${r+1+e} Failed: Do not manually write CriticMarkup tags ({++, {--, {>>, {==) in \`new_text\`. The engine handles redlining automatically. To add a comment, use the \`comment\` parameter.`),i.includes("[^")||o.includes("[^")){let l=(i.match(/\[\^(?:fn|en)-[^\]]+\]/g)||[]).sort(),u=(o.match(/\[\^(?:fn|en)-[^\]]+\]/g)||[]).sort();JSON.stringify(l)!==JSON.stringify(u)&&(u.length>l.length||u.some(c=>u.filter(d=>d===c).length>l.filter(d=>d===c).length)?n.push(`- Edit ${r+1+e} Failed: Cannot insert footnote/endnote markers via text replace. Markers like \`[^fn-N]\` are read-only projections. Use Word's References menu.`):n.push(`- Edit ${r+1+e} Failed: Cannot delete footnote/endnote references via text replace. The marker corresponds to a structural XML element.`));}if(i.includes("](")||o.includes("](")){let l=(i.match(/\[(?!~)[^\]]+\]\([^)]+\)/g)||[]).sort(),u=(o.match(/\[(?!~)[^\]]+\]\([^)]+\)/g)||[]).sort();l.length!==u.length?u.length>l.length?n.push(`- Edit ${r+1+e} Failed: Cannot insert hyperlinks via text replace. Inserting new hyperlinks is not supported; insert the display text instead (editing the text or URL of an existing link IS supported).`):n.push(`- Edit ${r+1+e} Failed: Cannot delete hyperlinks via text replace. The marker corresponds to a structural XML element.`):l.length>1&&JSON.stringify(l)!==JSON.stringify(u)&&n.push(`- Edit ${r+1+e} Failed: Can only edit or retarget one hyperlink per text replacement. Please split into multiple edits.`);}if(i.includes("[~")||o.includes("[~")){let l=i.match(/\[~[^~]+~\]\(#[^\)]+\)/g)||[],u=o.match(/\[~[^~]+~\]\(#[^\)]+\)/g)||[];l.length!==u.length?u.length>l.length?n.push(`- Edit ${r+1+e} Failed: Cannot insert cross-references via text replace. Markers are read-only projections.`):n.push(`- Edit ${r+1+e} Failed: Cannot delete cross-references via text replace. The marker corresponds to a structural XML element.`):JSON.stringify(l)!==JSON.stringify(u)&&n.push(`- Edit ${r+1+e} Failed: Modifying or retargeting cross-reference markers is disallowed to prevent dependency corruption.`);}if(i.includes("docx-image:")||o.includes("docx-image:")){let l=(i.match(/!\[[^\]]*\]\(docx-image:[^)]*\)/g)||[]).sort(),u=(o.match(/!\[[^\]]*\]\(docx-image:[^)]*\)/g)||[]).sort();JSON.stringify(l)!==JSON.stringify(u)&&n.push(`- Edit ${r+1+e} Failed: image markers (![alt](docx-image:N)) are read-only projections of embedded images. They cannot be inserted, altered, or removed via text replacement \u2014 edit the text around the image instead.`);}if(i.includes("{#")||o.includes("{#")){let l=i.match(/\{#[^\}]+\}/g)||[],u=o.match(/\{#[^\}]+\}/g)||[];for(let c of u)if(u.filter(d=>d===c).length>l.filter(d=>d===c).length){n.push(`- Edit ${r+1+e} Failed: Cannot modify or insert internal anchor markers (\`{#...}\`). These represent structural XML bookmarks.`);break}}if(s.type==="modify"&&o){let l=o.split(/[\r\n]+/);for(let u of l){let c=u.trimStart();if(c.startsWith("#######")){let d=c.length-c.replace(/^#+/,"").length;if(c.substring(d).startsWith(" ")||c.substring(d)===""){n.push(`- Edit ${r+1+e} Failed: Heading level ${d} is not supported (maximum is 6).`);break}}}}(i.includes("READONLY_BOUNDARY_START")||o.includes("READONLY_BOUNDARY_START")||i.includes("# Document Structure (Read-Only)")||o.includes("# Document Structure (Read-Only)")||i.includes("Document Structure (Read-Only)")||o.includes("Document Structure (Read-Only)"))&&n.push(`- Edit ${r+1+e} Failed: Modification targets the read-only boundary (Structural Appendix). This section cannot be edited.`);}return n}y(Mo,"validate_edit_strings");var _n=class V{static{y(this,"_RedlineEngine");}doc;author;timestamp;current_id;mapper;comments_manager;clean_mapper=null;original_mapper=null;skipped_details=[];removed_comment_notes=[];_revisionIndex=null;constructor(e,n="Adeu AI (TS)"){this.doc=e,this.author=n,this.timestamp=new Date().toISOString().replace(/\.\d{3}Z$/,"Z");let r="http://schemas.microsoft.com/office/word/2023/wordml/word16du";for(let s of this.doc.pkg.parts)if(s===this.doc.part&&!s._element.hasAttribute("xmlns:w16du")){let i=s._element.ownerDocument,o=ln(i);s._element.setAttribute("xmlns:w16du",r),o&&tt(i);}this.current_id=this._scan_existing_ids(),this.mapper=new ke(this.doc),this.comments_manager=new nt(this.doc);}_check_punctuation_warning(e){return !e||e.length>20||e.includes(" ")?null:e.includes("_")||e.includes("-")?`Warning: target_text '${e}' contains tokenization-splitting punctuation ('_' or '-'). This can trigger mid-word splits in the diff engine. Consider using a longer plain-prose anchor.`:null}_single_commented_sub_edit(e,n,r,s,i,o){let a,l,u,c;if(e===n)a=e,l=n,u=r,c="COMMENT_ONLY";else {let[f,h]=qe(e,n);a=e.slice(f,e.length-h),l=n.slice(f,n.length-h),u=r+f,!a&&l?c="INSERTION":a&&!l?c="DELETION":c="MODIFICATION";}let d={type:"modify",target_text:a,new_text:l,comment:s};return d._resolved_start_idx=u,d._match_start_index=u,d._active_mapper_ref=o,d._internal_op=c,i&&(d._is_table_edit=true),[d]}_word_diff_sub_edits(e,n,r,s=null,i=false,o=null){if(s!=null)return this._single_commented_sub_edit(e,n,r,s,i,o);let a=[];try{a=wt(e,n);}catch{a=[];}let l=y(d=>{let f=d.trim();return f.length>0&&/^[*_]+$/.test(f)},"_marker_only");if(a=a.filter(d=>!((!d.target_text||l(d.target_text))&&(!d.new_text||l(d.new_text))&&(d.target_text||d.new_text))),!a||a.length===0){let d={type:"modify",target_text:e,new_text:n,comment:s};return d._resolved_start_idx=r,d._match_start_index=r,d._active_mapper_ref=o,i&&(d._is_table_edit=true),e===n?d._internal_op="COMMENT_ONLY":!e&&n?d._internal_op="INSERTION":e&&!n?d._internal_op="DELETION":e&&n?d._internal_op="MODIFICATION":d._internal_op="COMMENT_ONLY",[d]}let u=[],c=false;for(let d of a){let f=r+(d._match_start_index||0),h=s!==null&&!c;h&&(c=true);let _={type:"modify",target_text:d.target_text,new_text:d.new_text,comment:h?s:null};_._resolved_start_idx=f,_._match_start_index=f,_._active_mapper_ref=o,i&&(_._is_table_edit=true);let p=d.target_text,m=d.new_text;!p&&m?_._internal_op="INSERTION":p&&!m?_._internal_op="DELETION":p&&m?_._internal_op="MODIFICATION":_._internal_op="COMMENT_ONLY",u.push(_);}return u}_nearest_match_hint(e,n){if(!e)return "";let r=e;if(n&&(r=r.replace(/^\^/,"").replace(/\$$/,""),r=r.replace(/^\\s\*/,"").replace(/\\s\*$/,""),r=r.replace(/\\([.^$*+?()[\]{}|\\/])/g,"$1")),r=r.trim(),(!r||r===e)&&!n)return "";let s=this.mapper.full_text.indexOf(r);if(s!==-1){let i=Math.max(0,s-15),o=Math.min(this.mapper.full_text.length,s+r.length+15),a=this.mapper.full_text.substring(i,o).replace(/\n/g," ");return `
95
+ Did you mean the literal "${r}"? It appears in the document (\u2026${a}\u2026). If you used a regex, drop the ^/$ anchors \u2014 they match the start/end of the entire document, not a line.`}return ""}static _PREVIEW_WRAPPER_PAIRS=[["{--","--}"],["{++","++}"],["{==","==}"],["{>>","<<}"]];static _tidy_preview_context(e,n){e=e.replace(/\{>>[\s\S]*?<<\}/g,"");for(let[r,s]of V._PREVIEW_WRAPPER_PAIRS)if(n==="before"){let i=0,o=0,a=0;for(;a<e.length;)e.startsWith(r,a)?(i+=1,a+=r.length):e.startsWith(s,a)?(i===0?o=a+s.length:i-=1,a+=s.length):a+=1;e=e.substring(o);}else {let i=[],o=0;for(;o<e.length;)e.startsWith(r,o)?(i.push(o),o+=r.length):e.startsWith(s,o)?(i.length>0&&i.pop(),o+=s.length):o+=1;i.length>0&&(e=e.substring(0,i[0]));}return n==="before"?e=e.replace(/^[-+=<>]{0,2}\}/,""):e=e.replace(/\{[-+=<>]{0,2}$/,""),e}_capture_preview_context(e){if(e.type!=="modify")return;let n=e._resolved_start_idx;if(n==null)return;let s=(e._active_mapper_ref||this.mapper).full_text;if(!s)return;let i=(e.target_text||"").length,o=s.substring(Math.max(0,n-ye),n),a=s.substring(n+i,n+i+ye);e._preview_context=[V._tidy_preview_context(o,"before"),V._tidy_preview_context(a,"after")];}_capture_parent_preview_context(e){if(!e||e.type!=="modify"||e._preview_context||!e._preview_span)return;let[n,r]=e._preview_span,i=(e._preview_mapper_ref||this.mapper).full_text;if(!i)return;let o=i.substring(Math.max(0,n-ye),n),a=i.substring(n+r,n+r+ye);e._preview_context=[V._tidy_preview_context(o,"before"),V._tidy_preview_context(a,"after")];}_build_full_match_preview(e){let[n,r]=e._preview_context,s=e._preview_matched_text||"",i=e._preview_new_text!==void 0&&e._preview_new_text!==null?e._preview_new_text:e.new_text||"",[o,a]=this._parse_markdown_style(s),[l,u]=this._parse_markdown_style(i);a&&a.startsWith("Heading")&&(n=n+s.substring(0,s.length-o.length),s=o),u&&u.startsWith("Heading")&&(i=l);let[c,d]=qe(s,i),f=s.substring(c,s.length-d),h=i.substring(c,i.length-d);n=n+s.substring(0,c),d&&(r=s.substring(s.length-d)+r),f=he(f,Le),h=he(h,Le);let _;if(!f&&!h){let m=he(s,Le),w=m?`{==${m}==}`:"";_=`${n.substring(0,n.length-s.length)}${w}${r}`;}else {let m=f?`{--${f}--}`:"",w=h?`{++${h}++}`:"";_=`${n}${m}${w}${r}`;}let p=_;return p=p.replace(/\{>>[\s\S]*?<<\}/g,""),p=p.replace(/\{--[\s\S]*?--\}/g,""),p=p.replace(/\{\+\+([\s\S]*?)\+\+\}/g,"$1"),[_,p]}static _report_new_text(e){return e&&e.type==="insert_row"&&Array.isArray(e.cells)?e.cells.join(" | "):e&&e.new_text||""}_build_postapply_previews(e){let n=new Set((e._minted_change_ids||[]).map(w=>String(w))),r=new Set((e._minted_comment_ids||[]).map(w=>String(w)));if(n.size===0&&r.size===0)return null;let s=this.mapper;s.full_text||s._build_map();let i=s.full_text;if(!i)return null;let o=[];for(let w of s.spans)(w.ins_id&&n.has(String(w.ins_id))||w.del_id&&n.has(String(w.del_id))||r.size>0&&w.comment_ids&&w.comment_ids.some(b=>r.has(String(b))))&&o.push([w.start,w.end]);if(o.length===0)return null;let a=/\{>>[\s\S]*?<<\}/g,l=[],u;for(;(u=a.exec(i))!==null;)l.push([u.index,u.index+u[0].length]);let c=i,d=y(w=>w,"to_visible");if(l.length>0){let w=[],k=0;for(let[b,g]of l)w.push(i.substring(k,b)),k=g;w.push(i.substring(k)),c=w.join(""),d=y(b=>{let g=0;for(let[v,x]of l)if(b>=x)g+=x-v;else if(b>v){g+=b-v;break}else break;return b-g},"to_visible");}o.sort((w,k)=>w[0]-k[0]);let f=[];for(let[w,k]of o){let b=d(w),g=d(k),v=Math.max(0,b-ye),x=Math.min(c.length,g+ye),E=f.length>0?f[f.length-1]:null;E&&v<=E[1]?E[1]=Math.max(E[1],x):f.push([v,x]);}let h=[];for(let[w,k]of f){let b=c.substring(w,k);b=V._tidy_preview_context(b,"before"),b=V._tidy_preview_context(b,"after"),h.push(b);}let _=h.join(`
96
96
  \u2026
97
- `),_=p;_=_.replace(/\{>>[\s\S]*?<<\}/g,""),_=_.replace(/\{--[\s\S]*?--\}/g,""),_=_.replace(/\{\+\+([\s\S]*?)\+\+\}/g,"$1"),_=_.replace(/\{==([\s\S]*?)==\}/g,"$1");let g=ze*2+4*ye;return [he(p,g),he(_,g)]}_build_edit_context_previews(e){if(e.type!=="modify")return [null,null];let n=this._build_postapply_previews(e);if(n)return n;if(e._preview_span&&e._preview_context)return this._build_full_match_preview(e);e._resolved_proxy_edit&&(e=e._resolved_proxy_edit);let r=e._resolved_start_idx;if(r==null)return [null,null];let s=e.target_text||"",i=e.new_text||"",[o,l]=this._parse_markdown_style(s);if(l&&l.startsWith("Heading")){let b=s.length-o.length;r+=b,s=o;}let[a,u]=this._parse_markdown_style(i);u&&u.startsWith("Heading")&&(i=a);let c=s.length,d,f;if(e._preview_context)[d,f]=e._preview_context;else {let m=(e._active_mapper_ref||this.mapper).full_text;if(!m)return [null,null];d=V._tidy_preview_context(m.substring(Math.max(0,r-ye),r),"before"),f=V._tidy_preview_context(m.substring(r+c,r+c+ye),"after");}let h=he(s,ze),p=he(i,ze),_=h?`{--${h}--}`:"",g=p?`{++${p}++}`:"",w=`${d}${_}${g}${f}`,k=w;return k=k.replace(/\{>>.*?<<\}/gs,""),k=k.replace(/\{--.*?--\}/gs,""),k=k.replace(/\{\+\+(.*?)\+\+\}/gs,"$1"),[w,k]}_scan_existing_ids(){let e=0;for(let n of ["w:ins","w:del","w:pPrChange"]){let r=I(this.doc.element,n);for(let s of r){let i=parseInt(s.getAttribute("w:id")||"0",10);!isNaN(i)&&i>e&&(e=i);}}return e}_get_heading_path_and_page(e,n,r){let s=1;for(let u=0;u<r.length&&e>=r[u];u++)s=u+1;let o=n.substring(0,e).split(`
98
- `),l=[],a=999;for(let u=o.length-1;u>=0;u--){let d=o[u].match(/^(#{1,6})\s+(.*)/);if(d){let f=d[1].length;if(f<a){let h=d[2].replace(/\*\*|__|[*_]/g,"").replace(/\{#[^}]+\}/g,"").trim();if(h.length>80&&(h=h.substring(0,80)+"..."),l.unshift(h),a=f,f===1)break}}}return [l.join(" > "),s]}accept_all_revisions(){let e=[this.doc.element];for(let a of this.doc.pkg.parts)a!==this.doc.part&&a.contentType.includes("wordprocessingml")&&a.contentType.endsWith("+xml")&&e.push(a._element);let n=0,r=0,s=0;for(let a of e){n+=I(a,"w:ins").length,r+=I(a,"w:del").length;for(let u of ["w:rPrChange","w:pPrChange","w:sectPrChange"])s+=I(a,u).length;}let i=this._existing_comment_ids().length;for(let a of e){let u=I(a,"w:ins");for(let f of u){this._clean_wrapping_comments(f);let h=f.parentNode;if(h){if(h.tagName==="w:trPr"){h.removeChild(f);continue}for(;f.firstChild;)h.insertBefore(f.firstChild,f);h.removeChild(f);}}let c=I(a,"w:p");for(let f of c){let h=M(f,"w:pPr");if(h){let p=M(h,"w:rPr"),_=p?M(p,"w:del"):null;if(p&&_){let g=false;for(let w of ["w:t","w:tab","w:br"]){for(let k of I(f,w)){if(w==="w:t"&&!k.textContent)continue;let b=false,m=k.parentNode;for(;m&&m!==f;){if(m.tagName==="w:del"){b=true;break}m=m.parentNode;}if(!b){g=true;break}}if(g)break}g?p.removeChild(_):(this._clean_wrapping_comments(f),this._delete_comments_in_element(f),f.parentNode&&f.parentNode.removeChild(f));}}}let d=I(a,"w:del");for(let f of d){this._clean_wrapping_comments(f),this._delete_comments_in_element(f);let h=f.parentNode;if(h)if(h.tagName==="w:trPr"){let p=h.parentNode;p&&p.parentNode&&p.parentNode.removeChild(p);}else h.removeChild(f);}for(let f of I(a,"w:pPrChange"))f.parentNode?.removeChild(f);}for(let a of e){for(let c of ["w:commentRangeStart","w:commentRangeEnd"])for(let d of I(a,c))d.parentNode?.removeChild(d);let u=I(a,"w:commentReference");for(let c of u){let d=c.parentNode;d&&((d.tagName==="w:r"||d.tagName.endsWith(":r"))&&Array.from(d.childNodes).filter(h=>h.nodeType===1&&h.tagName!=="w:rPr"&&h.tagName!=="rPr").length<=1?d.parentNode?.removeChild(d):d.removeChild(c));}}let o=this.doc.pkg,l=new Set;for(let a of o.parts)if(a.partname.toLowerCase().includes("comments")){l.add(a.partname);let u=a.partname.startsWith("/")?a.partname:"/"+a.partname,c=a.partname.startsWith("/")?a.partname.substring(1):a.partname;l.add(u),l.add(c);}if(l.size>0){for(let u of o.parts)if(u.partname.endsWith(".rels")){let c=I(u._element,"Relationship"),d=[];for(let f of c)if((f.getAttribute("Target")||"").toLowerCase().includes("comments")){d.push(f);let p=u.partname.replace("/_rels/","/").replace(".rels",""),_=o.getPartByPath(p);if(_){let g=f.getAttribute("Id");g&&_.rels.delete(g);}}for(let f of d)f.parentNode?.removeChild(f);}let a=o.getPartByPath("[Content_Types].xml");if(a){let u=I(a._element,"Override"),c=[];for(let d of u){let f=d.getAttribute("PartName")||"";(l.has(f)||f.toLowerCase().includes("comments"))&&c.push(d);}for(let d of c)d.parentNode?.removeChild(d);}o.parts=o.parts.filter(u=>!u.partname.toLowerCase().includes("comments"));for(let u of Object.keys(o.unzipped))u.toLowerCase().includes("comments")&&delete o.unzipped[u];}return {accepted_insertions:n,accepted_deletions:r,accepted_formatting:s,removed_comments:i}}reject_all_revisions(){let e=[this.doc.element];for(let n of this.doc.pkg.parts)n!==this.doc.part&&n.contentType.includes("wordprocessingml")&&n.contentType.endsWith("+xml")&&e.push(n._element);for(let n of e){for(let o of I(n,"w:pPrChange"))this._revert_ppr_change(o);let r=I(n,"w:ins");for(let o of r){let l=o.parentNode;if(l)if(this._clean_wrapping_comments(o),this._delete_comments_in_element(o),l.tagName==="w:trPr"){let a=l.parentNode;a&&a.parentNode&&a.parentNode.removeChild(a);}else l.removeChild(o);}let s=I(n,"w:p");for(let o of s){let l=M(o,"w:pPr");if(l){let a=M(l,"w:rPr"),u=a?M(a,"w:del"):null;a&&u&&a.removeChild(u);}}let i=I(n,"w:del");for(let o of i){let l=o.parentNode;if(!l)continue;if(l.tagName==="w:trPr"){l.removeChild(o);continue}let a=Array.from(o.getElementsByTagName("w:delText"));for(let u of a){let c=o.ownerDocument.createElement("w:t");c.textContent=u.textContent,u.hasAttribute("xml:space")&&c.setAttribute("xml:space","preserve"),u.parentNode?.replaceChild(c,u);}for(;o.firstChild;)l.insertBefore(o.firstChild,o);l.removeChild(o);}}}_revert_ppr_change(e){let n=e.parentNode;if(!n||n.tagName!=="w:pPr")return;let r=n.parentNode;if(!r)return;let s=M(e,"w:pPr");if(s){let i=s.cloneNode(true);Array.from(i.childNodes).some(l=>l.nodeType===1)?r.replaceChild(i,n):r.removeChild(n);}else r.removeChild(n);}_revert_props_change(e){let n=e.parentNode;if(!n)return;let r=Array.from(e.childNodes).find(i=>i.nodeType===1);n.removeChild(e);let s=Eo[n.tagName];for(let i of Array.from(n.childNodes)){if(i.nodeType!==1)continue;let o=i;o.tagName==="w:rPr"&&(M(o,"w:ins")||M(o,"w:del"))||s?.has(o.tagName)||n.removeChild(i);}if(r)for(let i of Array.from(r.childNodes))i.nodeType===1&&n.appendChild(i.cloneNode(true));}_getNextId(){return this.current_id++,this.current_id.toString()}_create_track_change_tag(e,n="",r=null){let i=this.doc.part._element.ownerDocument.createElement(e),o=r!==null?r:this._getNextId();return i.setAttribute("w:id",o),i.setAttribute("w:author",n||this.author),i.setAttribute("w:date",this.timestamp),i.setAttribute("w16du:dateUtc",this.timestamp),i}_set_text_content(e,n){e.textContent=n,n.trim()!==n&&e.setAttribute("xml:space","preserve");}_comment_anchor_in_main_story(e){let n=e;for(;n.parentNode&&n.parentNode.nodeType===1;)n=n.parentNode;return n.tagName==="w:document"}_skip_comment_outside_main_story(e,n){if(this._comment_anchor_in_main_story(e))return false;let r=e;for(;r.parentNode&&r.parentNode.nodeType===1;)r=r.parentNode;let s={"w:ftr":"footer","w:hdr":"header","w:footnotes":"footnote","w:endnotes":"endnote"}[r.tagName]||"non-body",i=`- Warning: the comment "${n.substring(0,60)}" was NOT attached: Word does not support comments inside a ${s} part, and writing one produces a document other applications cannot open. The tracked change itself was applied.`;return this.skipped_details.push(i),true}_attach_comment(e,n,r,s){if(!s||!e||!n||!r||this._skip_comment_outside_main_story(e,s))return;let i=this.comments_manager.addComment(this.author,s),o=e.ownerDocument,l=o.createElement("w:commentRangeStart");l.setAttribute("w:id",i);let a=o.createElement("w:commentRangeEnd");a.setAttribute("w:id",i);let u=o.createElement("w:r"),c=o.createElement("w:rPr"),d=o.createElement("w:rStyle");d.setAttribute("w:val","CommentReference"),c.appendChild(d),u.appendChild(c);let f=o.createElement("w:commentReference");f.setAttribute("w:id",i),u.appendChild(f),e.insertBefore(l,n);let h=r.nextSibling;h?(e.insertBefore(a,h),e.insertBefore(u,a.nextSibling)):(e.appendChild(a),e.appendChild(u));}_attach_comment_spanning(e,n,r,s,i){if(!i||!e||!r||this._skip_comment_outside_main_story(e,i)||this._skip_comment_outside_main_story(r,i))return;let o=this.comments_manager.addComment(this.author,i),l=e.ownerDocument,a=r.ownerDocument,u=l.createElement("w:commentRangeStart");u.setAttribute("w:id",o);let c=a.createElement("w:commentRangeEnd");c.setAttribute("w:id",o);let d=a.createElement("w:r"),f=a.createElement("w:rPr"),h=a.createElement("w:rStyle");h.setAttribute("w:val","CommentReference"),f.appendChild(h),d.appendChild(f);let p=a.createElement("w:commentReference");p.setAttribute("w:id",o),d.appendChild(p),e.insertBefore(u,n);let _=s.nextSibling;_?(r.insertBefore(c,_),r.insertBefore(d,c.nextSibling)):(r.appendChild(c),r.appendChild(d));}_clone_pPr_scrubbing_headings(e){let n=e.cloneNode(true),r=M(n,"w:pStyle");if(r){let i=r.getAttribute("w:val");i&&(i.startsWith("Heading")||i==="Title"||i.replace(/\s+/g,"").startsWith("Heading"))&&n.removeChild(r);}let s=M(n,"w:outlineLvl");return s&&n.removeChild(s),n}_track_insert_multiline(e,n,r,s,i=null,o=false,l=false){if(!e)return {first_node:null,last_p:null,last_ins:null,used_block_mode:false};let a=this.doc.part._element.ownerDocument,u=e.split(/[\r\n]+/),c=null;if(r!==null)c=r._element;else if(n!==null){let P=n._element;for(;P&&P.tagName!=="w:p";)P=P.parentNode;c=P;}let d=[],f=new Set(["w:r","w:ins","w:del"]),h=i&&i.parentNode?i:null,p=n!==null&&n._element.parentNode?n._element:null,_=h??p,g=l&&h===null&&p!==null;if(c!==null&&_!==null){let P=_;for(;P&&P.parentNode!==c;)if(P=P.parentNode,P===c){P=null;break}if(P){let R=g?P:P.nextSibling;for(;R;)R.nodeType===1&&f.has(R.tagName)&&d.push(R),R=R.nextSibling;}}else if(c!==null&&l){let P=c.firstChild;for(;P;)P.nodeType===1&&f.has(P.tagName)&&d.push(P),P=P.nextSibling;}for(;u.length>1&&u[u.length-1]===""&&d.length===0;)u.pop();if(u.length===0)return {first_node:null,last_p:null,last_ins:null,used_block_mode:false};let[w,k]=this._parse_markdown_style(u[0]),m=k!==null&&c!==null,v=null,N=null;m||(N=this._build_tracked_ins_for_line((w===u[0],u[0]),n,s,a,o),v=N);let A=m?u:u.slice(1);if(A.length===0)return {first_node:v,last_p:null,last_ins:N,used_block_mode:false};if(!c)return {first_node:v,last_p:null,last_ins:N,used_block_mode:false};let C=c.parentNode;if(!C)return {first_node:v,last_p:null,last_ins:N,used_block_mode:false};let x=y((P,R)=>{C.insertBefore(P,R.nextSibling);},"insertAfterEl"),E=null,T=null,D=c;for(let P=0;P<A.length;P++){let R=A[P],[$,S]=this._parse_markdown_style(R),j=a.createElement("w:p");if(S)this._set_paragraph_style(j,S);else {let Y=M(c,"w:pPr");Y&&j.appendChild(this._clone_pPr_scrubbing_headings(Y));}let F=M(j,"w:pPr");F||(F=a.createElement("w:pPr"),j.insertBefore(F,j.firstChild));let B=M(F,"w:rPr");B||(B=a.createElement("w:rPr"),F.appendChild(B));let L=this._create_track_change_tag("w:ins","",s);B.appendChild(L);let U=this._build_tracked_ins_for_line($,n,s,a,o);U&&j.appendChild(U),x(j,D),D=j,E=j,T=U,v||(v=j);}if(!m&&E&&d.length>0)for(let P of d)P.parentNode?.removeChild(P),E.appendChild(P);return {first_node:v,last_p:E,last_ins:T,used_block_mode:m}}_build_tracked_ins_for_line(e,n,r,s,i=false){if(!e&&e!=="")return null;let o=this._create_track_change_tag("w:ins","",r),l=this._parse_inline_markdown(e);if(l.length===0)return null;for(let[a,u]of l){let c=s.createElement("w:r");if(n&&n._element){let f=M(n._element,"w:rPr");if(f){let h=f.cloneNode(true),p=["w:vanish","w:strike","w:dstrike","w:i","w:iCs"];i&&p.push("w:b","w:bCs");for(let _ of p){let g=M(h,_);g&&h.removeChild(g);}c.appendChild(h);}}this._apply_run_props(c,u,false);let d=s.createElement("w:t");this._set_text_content(d,a),c.appendChild(d),o.appendChild(c);}return o}_parse_markdown_style(e){let n=e.trimStart();if(n.startsWith("#")){let s=0,i=n;for(;i.startsWith("#");)s++,i=i.substring(1);if(i.startsWith(" "))return [i.trim(),`Heading ${s}`]}if(n.startsWith("* ")||n.startsWith("- "))return [n.substring(2).trim(),"List Paragraph"];let r=n.match(/^1\.\s+/);return r?[n.substring(r[0].length).trim(),"List Number"]:[e,null]}_edit_declares_emphasis(e){for(let n of [e?.target_text,e?.new_text]){if(!n||!n.includes("**")&&!n.includes("_"))continue;if(this._parse_inline_markdown(n).some(([,s])=>s&&Object.keys(s).length>0))return true}return false}_parse_inline_markdown(e,n={}){if(!e)return [];let r=/(\*\*.*?\*\*)|(_.*?_)/,s=e.match(r);if(!s)return [[e,n]];let i=s.index,o=s[0],l=i+o.length,a=o.startsWith("**"),u=a?o.substring(2,o.length-2):o.substring(1,o.length-1),c=e.substring(0,i),d=e.substring(l),f=[];c&&f.push([c,n]);let h={...n};return a?h.bold=true:h.italic=true,f.push(...this._parse_inline_markdown(u,h)),f.push(...this._parse_inline_markdown(d,n)),f}_apply_run_props(e,n,r=false){if(!n){if(!r)return;n={};}let s=M(e,"w:rPr");if(!s&&(n.bold||n.italic||r)&&(s=e.ownerDocument.createElement("w:rPr"),e.appendChild(s)),s){let i=e.ownerDocument;if(n.bold){let o=M(s,"w:b");o||(o=i.createElement("w:b"),s.appendChild(o)),o.setAttribute("w:val","1");}else if(r){let o=M(s,"w:b");o&&s.removeChild(o);}if(n.italic){let o=M(s,"w:i");o||(o=i.createElement("w:i"),s.appendChild(o)),o.setAttribute("w:val","1");}else if(r){let o=M(s,"w:i");o&&s.removeChild(o);}}}_set_paragraph_style(e,n,r=null){let s=e.ownerDocument,i=M(e,"w:pPr");i&&e.removeChild(i);let o=s.createElement("w:pPr"),l=s.createElement("w:pStyle"),a=n.replace(/\s+/g,"");if(l.setAttribute("w:val",a),o.appendChild(l),a==="ListParagraph"){let u=this._ensure_bullet_num_id();if(u){let c=s.createElement("w:numPr"),d=s.createElement("w:ilvl");d.setAttribute("w:val","0");let f=s.createElement("w:numId");f.setAttribute("w:val",u),c.appendChild(d),c.appendChild(f),o.appendChild(c);}}if(r!==null){let u=this._create_track_change_tag("w:pPrChange","",r),c=i?i.cloneNode(true):s.createElement("w:pPr"),d=M(c,"w:pPrChange");d&&c.removeChild(d),u.appendChild(c),o.appendChild(u);}e.insertBefore(o,e.firstChild);}static _NUMBERING_CT="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml";static _NUMBERING_RT="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";_ensure_bullet_num_id(){let e=this.doc.pkg,n="http://schemas.openxmlformats.org/wordprocessingml/2006/main",r='<w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText w:val="\uF0B7"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr><w:rPr><w:rFonts w:ascii="Symbol" w:hAnsi="Symbol" w:hint="default"/></w:rPr></w:lvl>',s=e.parts.find(E=>String(E.partname).replace(/^\//,"")==="word/numbering.xml");if(!s){let E=`<w:numbering xmlns:w="${n}"><w:abstractNum w:abstractNumId="0"><w:multiLevelType w:val="singleLevel"/>`+r+'</w:abstractNum><w:num w:numId="1"><w:abstractNumId w:val="0"/></w:num></w:numbering>';try{s=e.addPart("/word/numbering.xml",V._NUMBERING_CT,E),this.doc.relateTo(s,V._NUMBERING_RT);}catch{return null}return delete e._adeu_numbering_cache,"1"}let i=s._element,o=I(i,"w:abstractNum"),l=I(i,"w:num"),a=null;for(let E of o){let T=E.getAttribute("w:abstractNumId");if(T!==null){for(let D of I(E,"w:lvl")){if((D.getAttribute("w:ilvl")||"0")!=="0")continue;let P=M(D,"w:numFmt");P&&P.getAttribute("w:val")==="bullet"&&(a=T);break}if(a!==null)break}}let u=0;for(let E of l){let T=parseInt(E.getAttribute("w:numId")||"0",10);!isNaN(T)&&T>u&&(u=T);}let c=i.ownerDocument;if(a!==null){for(let D of l){let P=M(D,"w:abstractNumId");if(P&&P.getAttribute("w:val")===a){let R=D.getAttribute("w:numId");if(R&&R!=="0")return R}}let E=c.createElement("w:num");E.setAttribute("w:numId",String(u+1));let T=c.createElement("w:abstractNumId");return T.setAttribute("w:val",a),E.appendChild(T),i.appendChild(E),delete e._adeu_numbering_cache,String(u+1)}let d=-1;for(let E of o){let T=parseInt(E.getAttribute("w:abstractNumId")||"-1",10);!isNaN(T)&&T>d&&(d=T);}let f=c.createElement("w:abstractNum");f.setAttribute("w:abstractNumId",String(d+1));let h=c.createElement("w:multiLevelType");h.setAttribute("w:val","singleLevel"),f.appendChild(h);let p=c.createElement("w:lvl");p.setAttribute("w:ilvl","0");let _=c.createElement("w:start");_.setAttribute("w:val","1"),p.appendChild(_);let g=c.createElement("w:numFmt");g.setAttribute("w:val","bullet"),p.appendChild(g);let w=c.createElement("w:lvlText");w.setAttribute("w:val","\uF0B7"),p.appendChild(w);let k=c.createElement("w:lvlJc");k.setAttribute("w:val","left"),p.appendChild(k);let b=c.createElement("w:pPr"),m=c.createElement("w:ind");m.setAttribute("w:left","720"),m.setAttribute("w:hanging","360"),b.appendChild(m),p.appendChild(b);let v=c.createElement("w:rPr"),N=c.createElement("w:rFonts");N.setAttribute("w:ascii","Symbol"),N.setAttribute("w:hAnsi","Symbol"),N.setAttribute("w:hint","default"),v.appendChild(N),p.appendChild(v),f.appendChild(p);let A=l.find(E=>E.parentNode===i)||null;A?i.insertBefore(f,A):i.appendChild(f);let C=c.createElement("w:num");C.setAttribute("w:numId",String(u+1));let x=c.createElement("w:abstractNumId");return x.setAttribute("w:val",String(d+1)),C.appendChild(x),i.appendChild(C),delete e._adeu_numbering_cache,String(u+1)}_anchor_reply_comment(e,n){let r=this.doc.part._element.ownerDocument,s=I(this.doc.element,"w:commentRangeStart").filter(g=>g.getAttribute("w:id")===e);if(s.length===0)return;let i=s[0],o=r.createElement("w:commentRangeStart");o.setAttribute("w:id",n),Le(o,i);let l=I(this.doc.element,"w:commentRangeEnd").filter(g=>g.getAttribute("w:id")===e);if(l.length===0)return;let a=l[0],u=I(this.doc.element,"w:commentReference").filter(g=>g.getAttribute("w:id")===e),c=a;if(u.length>0){let g=u[0];g.parentNode&&g.parentNode.tagName==="w:r"&&(c=g.parentNode);}let d=r.createElement("w:commentRangeEnd");d.setAttribute("w:id",n),Le(d,c);let f=r.createElement("w:r"),h=r.createElement("w:rPr"),p=r.createElement("w:rStyle");p.setAttribute("w:val","CommentReference"),h.appendChild(p),f.appendChild(h);let _=r.createElement("w:commentReference");_.setAttribute("w:id",n),f.appendChild(_),Le(f,d);}_clean_wrapping_comments(e){let n=0,r=e;for(;;){let c=Ee(r);if(c&&(c.tagName==="w:ins"||c.tagName==="w:del"))r=c;else break}let s=e;for(;;){let c=ve(s);if(c&&(c.tagName==="w:ins"||c.tagName==="w:del"))s=c;else break}let i=[],o=Ee(r);for(;o;)if(o.tagName==="w:commentRangeStart")i.push(o),o=Ee(o);else if(o.tagName==="w:rPr"||o.tagName==="w:pPr")o=Ee(o);else break;let l=[],a=ve(s);for(;a;)if(a.tagName==="w:commentRangeEnd")l.push(a),a=ve(a);else if(a.tagName==="w:r"&&I(a,"w:commentReference").length>0)l.push(a),a=ve(a);else if(a.tagName==="w:commentReference")l.push(a),a=ve(a);else break;let u=new Set;for(let c of l)if(c.tagName==="w:commentRangeEnd"){let d=c.getAttribute("w:id");d&&u.add(d);}else {let d=I(c,"w:commentReference")[0];if(!d&&c.tagName==="w:commentReference"&&(d=c),d){let f=d.getAttribute("w:id");f&&u.add(f);}}for(let c of i){let d=c.getAttribute("w:id");if(d&&u.has(d)){this.comments_manager.deleteComment(d),n++,c.parentNode&&c.parentNode.removeChild(c);for(let f of l){let h=null;if(f.tagName==="w:commentRangeEnd")h=f.getAttribute("w:id");else {let p=I(f,"w:commentReference")[0];!p&&f.tagName==="w:commentReference"&&(p=f),p&&(h=p.getAttribute("w:id"));}h===d&&f.parentNode&&f.parentNode.removeChild(f);}}}return n}_delete_comments_in_element(e){let n=0,r=I(e,"w:commentReference");for(let s of r){let i=s.getAttribute("w:id");if(i){this.comments_manager.deleteComment(i),n++;for(let o of ["w:commentRangeStart","w:commentRangeEnd"]){let l=I(this.doc.element,o);for(let a of l)a.getAttribute("w:id")===i&&a.parentNode&&a.parentNode.removeChild(a);}}}return n}validate_edits(e,n=0){let r=[];this.mapper.full_text||this.mapper._build_map(),r.push(...Co(e,n));for(let s=0;s<e.length;s++){let i=e[s];if(typeof i!="object"||i===null){r.push(`- Edit ${s+1+n} Failed: Invalid change format. Expected a JSON object, but received a primitive ${typeof i}. Do not pass raw strings.`);continue}if(i._match_start_index!==void 0&&i._match_start_index!==null||i._resolved_start_idx!==void 0&&i._resolved_start_idx!==null)continue;if(i.target_text===void 0||i.target_text===null||!String(i.target_text).trim()){i.type==="insert_row"?r.push(`- Edit ${s+1+n} Failed: insert_row requires target_text (text inside an existing row to anchor on) and cells (the new row's cell values).`):i.type==="delete_row"?r.push(`- Edit ${s+1+n} Failed: delete_row requires target_text (text inside the row to delete).`):r.push(`- Edit ${s+1+n} Failed: target_text is empty. Pure insertions are expressed as a replacement: put the text immediately around the insertion point in target_text and repeat it (plus the new text) in new_text.`);continue}if(i.type==="modify"&&(i.new_text===void 0||i.new_text===null))if(i.comment&&String(i.comment).trim())i.new_text=i.target_text;else {r.push(`- Edit ${s+1+n} Failed: modify requires new_text (an empty string deletes the target; to attach a comment without changing the text, supply the comment and omit new_text).`);continue}let o=i.regex||false,l=i.match_mode||"strict";if(o)try{new RegExp(i.target_text);}catch(h){r.push(`- Edit ${s+1+n} Failed: target_text is not a valid regular expression (${h?.message??h}). Fix the pattern, or set "regex": false to match the text literally.`);continue}let a=this.mapper.drop_virtual_only_matches(this.mapper.find_all_match_indices(i.target_text,o)),u=this.mapper.full_text,c=this.mapper;a.length===0&&(this.clean_mapper||(this.clean_mapper=new ke(this.doc,true)),a=this.clean_mapper.drop_virtual_only_matches(this.clean_mapper.find_all_match_indices(i.target_text,o)),a.length>0&&(u=this.clean_mapper.full_text,c=this.clean_mapper)),u===this.mapper.full_text&&a.length>0&&(a=a.filter(([p,_])=>{let g=this.mapper.spans.filter(w=>w.run!==null&&w.end>p&&w.start<p+_);return g.length===0?true:g.some(w=>!w.del_id)}));let d=false,f=new Set;if(a.length===0){this.original_mapper||(this.original_mapper=new ke(this.doc,false,true));let h=this.original_mapper.drop_virtual_only_matches(this.original_mapper.find_all_match_indices(i.target_text,o));if(h.length>0){d=true;for(let[p,_]of h){let g=this.original_mapper.spans.filter(w=>w.end>p&&w.start<p+_);for(let w of g)if(w.run!==null){let k=w.run._element;for(;k;){if(k.nodeType===1&&k.tagName==="w:del"){let b=k.getAttribute("w:author");b&&f.add(b);break}k=k.parentNode;}}}}}if(a.length===0)if(d){let h=f.size>0?`by ${Array.from(f).sort().join(", ")}`:"by an existing revision";r.push(`- Edit ${s+1+n} Failed: Target text matches text inside a tracked deletion ${h}. Reject/accept that change first or target the active replacement text instead.`);}else {let h=this._nearest_match_hint(i.target_text,o);r.push(`- Edit ${s+1+n} Failed: Target text not found in document:
99
- "${he(i.target_text,Lt)}"${h}`);}else if(a.length>1&&l==="strict")if(i.target_text.includes("|"))a=a.slice(0,1);else {let h=a.map(([p,_])=>[p,p+_]);r.push(vo(s+1+n,i.target_text,u,h));}if(a.length===1){let[h,p]=a[0],_=u.substring(h,h+p),[g,w]=Ue(_,i.new_text||""),k=_.length-w,b=_.substring(g,k),m=(i.new_text||"").substring(g,(i.new_text||"").length-w),N=c.part_ranges.filter(x=>x[1]>x[0]).length>1?Array.from(new Set(c.spans.filter(x=>x.run!==null&&x.end>h&&x.start<h+p).map(x=>x.part_index))).sort((x,E)=>x-E):[];if(N.length>1){let x=N.map(E=>c.part_kind_of(E)||"?").join(" \u2192 ");r.push(`- Edit ${s+1+n} Failed: target_text spans a structural document-part boundary (${x}). Headers, body, footers and footnotes are separate Word parts \u2014 an edit cannot cross between them. Anchor the edit on text within a single part (split it into one edit per part if both sides must change).`);}let A=h+g,C=h+p-w;if(C>A&&c.spans.filter(E=>E.end>A&&E.start<C&&(E.run!==null||E.text.trim()!=="")).some(E=>E.is_image_marker)&&r.push(`- Edit ${s+1+n} Failed: the target overlaps a read-only image marker (![alt](docx-image:N)). Images cannot be edited or removed via text replacement \u2014 target the text around the image instead.`),i.comment&&(i.new_text||"")===(i.target_text||"")){let x=c.part_kind_at(h);x!==null&&x!=="body"&&r.push(`- Edit ${s+1+n} Failed: comments cannot be anchored inside a ${x} part \u2014 Word only supports comments in the main document body. Comment on the related body text instead.`);}if(V._introduces_table_row_text(c,h,p,b,m)&&r.push(`- Edit ${s+1+n} Failed: new_text introduces a pipe-delimited row line inside a table. Text replacement cannot create table rows \u2014 use the structured 'insert_row' operation instead (e.g. {"type": "insert_row", "target_text": "<anchor row text>", "cells": ["...", "..."]}).`),b.includes(`
97
+ `),p=_;p=p.replace(/\{>>[\s\S]*?<<\}/g,""),p=p.replace(/\{--[\s\S]*?--\}/g,""),p=p.replace(/\{\+\+([\s\S]*?)\+\+\}/g,"$1"),p=p.replace(/\{==([\s\S]*?)==\}/g,"$1");let m=Le*2+4*ye;return [he(_,m),he(p,m)]}_build_edit_context_previews(e){if(e.type!=="modify")return [null,null];let n=this._build_postapply_previews(e);if(n)return n;if(e._preview_span&&e._preview_context)return this._build_full_match_preview(e);e._resolved_proxy_edit&&(e=e._resolved_proxy_edit);let r=e._resolved_start_idx;if(r==null)return [null,null];let s=e.target_text||"",i=e.new_text||"",[o,a]=this._parse_markdown_style(s);if(a&&a.startsWith("Heading")){let b=s.length-o.length;r+=b,s=o;}let[l,u]=this._parse_markdown_style(i);u&&u.startsWith("Heading")&&(i=l);let c=s.length,d,f;if(e._preview_context)[d,f]=e._preview_context;else {let g=(e._active_mapper_ref||this.mapper).full_text;if(!g)return [null,null];d=V._tidy_preview_context(g.substring(Math.max(0,r-ye),r),"before"),f=V._tidy_preview_context(g.substring(r+c,r+c+ye),"after");}let h=he(s,Le),_=he(i,Le),p=h?`{--${h}--}`:"",m=_?`{++${_}++}`:"",w=`${d}${p}${m}${f}`,k=w;return k=k.replace(/\{>>.*?<<\}/gs,""),k=k.replace(/\{--.*?--\}/gs,""),k=k.replace(/\{\+\+(.*?)\+\+\}/gs,"$1"),[w,k]}_scan_existing_ids(){let e=0;for(let n of ["w:ins","w:del","w:pPrChange"]){let r=$(this.doc.element,n);for(let s of r){let i=parseInt(s.getAttribute("w:id")||"0",10);!isNaN(i)&&i>e&&(e=i);}}return e}_get_heading_path_and_page(e,n,r){let s=1;for(let u=0;u<r.length&&e>=r[u];u++)s=u+1;let o=n.substring(0,e).split(`
98
+ `),a=[],l=999;for(let u=o.length-1;u>=0;u--){let d=o[u].match(/^(#{1,6})\s+(.*)/);if(d){let f=d[1].length;if(f<l){let h=d[2].replace(/\*\*|__|[*_]/g,"").replace(/\{#[^}]+\}/g,"").trim();if(h.length>80&&(h=h.substring(0,80)+"..."),a.unshift(h),l=f,f===1)break}}}return [a.join(" > "),s]}accept_all_revisions(e=false){let n=[this.doc.element];for(let f of this.doc.pkg.parts)f!==this.doc.part&&f.contentType.includes("wordprocessingml")&&f.contentType.endsWith("+xml")&&n.push(f._element);let r=0,s=0,i=0;for(let f of n){r+=$(f,"w:ins").length,s+=$(f,"w:del").length;for(let h of ["w:rPrChange","w:pPrChange","w:sectPrChange"])i+=$(f,h).length;}let o=this._comment_authors(),a=new Set(Object.keys(o));this.removed_comment_notes=[];for(let f of n){let h=$(f,"w:ins");for(let m of h){this._clean_wrapping_comments(m);let w=m.parentNode;if(w){if(w.tagName==="w:trPr"){w.removeChild(m);continue}for(;m.firstChild;)w.insertBefore(m.firstChild,m);w.removeChild(m);}}let _=$(f,"w:p");for(let m of _){let w=M(m,"w:pPr");if(w){let k=M(w,"w:rPr"),b=k?M(k,"w:del"):null;if(k&&b){let g=false;for(let v of ["w:t","w:tab","w:br"]){for(let x of $(m,v)){if(v==="w:t"&&!x.textContent)continue;let E=false,C=x.parentNode;for(;C&&C!==m;){if(C.tagName==="w:del"){E=true;break}C=C.parentNode;}if(!E){g=true;break}}if(g)break}g||this._is_last_paragraph_in_cell(m)?k.removeChild(b):(this._clean_wrapping_comments(m),this._delete_comments_in_element(m),m.parentNode&&m.parentNode.removeChild(m));}}}let p=$(f,"w:del");for(let m of p){this._clean_wrapping_comments(m),this._delete_comments_in_element(m);let w=m.parentNode;if(w)if(w.tagName==="w:trPr"){let k=w.parentNode;k&&k.parentNode&&k.parentNode.removeChild(k);}else w.removeChild(m);}for(let m of $(f,"w:pPrChange"))m.parentNode?.removeChild(m);}if(e)for(let f of n){for(let _ of ["w:commentRangeStart","w:commentRangeEnd"])for(let p of $(f,_))p.parentNode?.removeChild(p);let h=$(f,"w:commentReference");for(let _ of h){let p=_.parentNode;p&&((p.tagName==="w:r"||p.tagName.endsWith(":r"))&&Array.from(p.childNodes).filter(w=>w.nodeType===1&&w.tagName!=="w:rPr"&&w.tagName!=="rPr").length<=1?p.parentNode?.removeChild(p):p.removeChild(_));}}let l=this.doc.pkg,u=new Set;for(let f of l.parts)if(e&&f.partname.toLowerCase().includes("comments")){u.add(f.partname);let h=f.partname.startsWith("/")?f.partname:"/"+f.partname,_=f.partname.startsWith("/")?f.partname.substring(1):f.partname;u.add(h),u.add(_);}if(u.size>0){for(let h of l.parts)if(h.partname.endsWith(".rels")){let _=$(h._element,"Relationship"),p=[];for(let m of _)if((m.getAttribute("Target")||"").toLowerCase().includes("comments")){p.push(m);let k=h.partname.replace("/_rels/","/").replace(".rels",""),b=l.getPartByPath(k);if(b){let g=m.getAttribute("Id");g&&b.rels.delete(g);}}for(let m of p)m.parentNode?.removeChild(m);}let f=l.getPartByPath("[Content_Types].xml");if(f){let h=$(f._element,"Override"),_=[];for(let p of h){let m=p.getAttribute("PartName")||"";(u.has(m)||m.toLowerCase().includes("comments"))&&_.push(p);}for(let p of _)p.parentNode?.removeChild(p);}l.parts=l.parts.filter(h=>!h.partname.toLowerCase().includes("comments"));for(let h of Object.keys(l.unzipped))h.toLowerCase().includes("comments")&&delete l.unzipped[h];}let c=new Set(this._existing_comment_ids()),d=Array.from(a).filter(f=>!c.has(f)).sort((f,h)=>{let _=/^\d+$/.test(f)?parseInt(f,10):0,p=/^\d+$/.test(h)?parseInt(h,10):0;return _-p||f.localeCompare(h)});return this.removed_comment_notes=d.map(f=>`Com:${f} (by ${o[f]??"Unknown"})`),{accepted_insertions:r,accepted_deletions:s,accepted_formatting:i,removed_comments:d.length}}reject_all_revisions(){let e=[this.doc.element];for(let n of this.doc.pkg.parts)n!==this.doc.part&&n.contentType.includes("wordprocessingml")&&n.contentType.endsWith("+xml")&&e.push(n._element);for(let n of e){for(let o of $(n,"w:pPrChange"))this._revert_ppr_change(o);let r=$(n,"w:ins");for(let o of r){let a=o.parentNode;if(a)if(this._clean_wrapping_comments(o),this._delete_comments_in_element(o),a.tagName==="w:trPr"){let l=a.parentNode;l&&l.parentNode&&l.parentNode.removeChild(l);}else a.removeChild(o);}let s=$(n,"w:p");for(let o of s){let a=M(o,"w:pPr");if(a){let l=M(a,"w:rPr"),u=l?M(l,"w:del"):null;l&&u&&l.removeChild(u);}}let i=$(n,"w:del");for(let o of i){let a=o.parentNode;if(!a)continue;if(a.tagName==="w:trPr"){a.removeChild(o);continue}let l=Array.from(o.getElementsByTagName("w:delText"));for(let u of l){let c=o.ownerDocument.createElement("w:t");c.textContent=u.textContent,u.hasAttribute("xml:space")&&c.setAttribute("xml:space","preserve"),u.parentNode?.replaceChild(c,u);}for(;o.firstChild;)a.insertBefore(o.firstChild,o);a.removeChild(o);}}}_revert_ppr_change(e){let n=e.parentNode;if(!n||n.tagName!=="w:pPr")return;let r=n.parentNode;if(!r)return;let s=M(e,"w:pPr");if(s){let i=s.cloneNode(true);Array.from(i.childNodes).some(a=>a.nodeType===1)?r.replaceChild(i,n):r.removeChild(n);}else r.removeChild(n);}_revert_props_change(e){let n=e.parentNode;if(!n)return;let r=Array.from(e.childNodes).find(i=>i.nodeType===1);n.removeChild(e);let s=Oo[n.tagName];for(let i of Array.from(n.childNodes)){if(i.nodeType!==1)continue;let o=i;o.tagName==="w:rPr"&&(M(o,"w:ins")||M(o,"w:del"))||s?.has(o.tagName)||n.removeChild(i);}if(r)for(let i of Array.from(r.childNodes))i.nodeType===1&&n.appendChild(i.cloneNode(true));}_getNextId(){return this.current_id++,this.current_id.toString()}_create_track_change_tag(e,n="",r=null){let i=this.doc.part._element.ownerDocument.createElement(e),o=r!==null?r:this._getNextId();return i.setAttribute("w:id",o),i.setAttribute("w:author",n||this.author),i.setAttribute("w:date",this.timestamp),i.setAttribute("w16du:dateUtc",this.timestamp),i}_set_text_content(e,n){e.textContent=n,n.trim()!==n&&e.setAttribute("xml:space","preserve");}_comment_anchor_in_main_story(e){let n=e;for(;n.parentNode&&n.parentNode.nodeType===1;)n=n.parentNode;return n.tagName==="w:document"}_skip_comment_outside_main_story(e,n){if(this._comment_anchor_in_main_story(e))return false;let r=e;for(;r.parentNode&&r.parentNode.nodeType===1;)r=r.parentNode;let s={"w:ftr":"footer","w:hdr":"header","w:footnotes":"footnote","w:endnotes":"endnote"}[r.tagName]||"non-body",i=`- Warning: the comment "${n.substring(0,60)}" was NOT attached: Word does not support comments inside a ${s} part, and writing one produces a document other applications cannot open. The tracked change itself was applied.`;return this.skipped_details.push(i),true}_attach_comment(e,n,r,s){if(!s||!e||!n||!r||this._skip_comment_outside_main_story(e,s))return;let i=this.comments_manager.addComment(this.author,s),o=e.ownerDocument,a=o.createElement("w:commentRangeStart");a.setAttribute("w:id",i);let l=o.createElement("w:commentRangeEnd");l.setAttribute("w:id",i);let u=o.createElement("w:r"),c=o.createElement("w:rPr"),d=o.createElement("w:rStyle");d.setAttribute("w:val","CommentReference"),c.appendChild(d),u.appendChild(c);let f=o.createElement("w:commentReference");f.setAttribute("w:id",i),u.appendChild(f),e.insertBefore(a,n);let h=r.nextSibling;h?(e.insertBefore(l,h),e.insertBefore(u,l.nextSibling)):(e.appendChild(l),e.appendChild(u));}_attach_comment_spanning(e,n,r,s,i){if(!i||!e||!r||this._skip_comment_outside_main_story(e,i)||this._skip_comment_outside_main_story(r,i))return;let o=this.comments_manager.addComment(this.author,i),a=e.ownerDocument,l=r.ownerDocument,u=a.createElement("w:commentRangeStart");u.setAttribute("w:id",o);let c=l.createElement("w:commentRangeEnd");c.setAttribute("w:id",o);let d=l.createElement("w:r"),f=l.createElement("w:rPr"),h=l.createElement("w:rStyle");h.setAttribute("w:val","CommentReference"),f.appendChild(h),d.appendChild(f);let _=l.createElement("w:commentReference");_.setAttribute("w:id",o),d.appendChild(_),e.insertBefore(u,n);let p=s.nextSibling;p?(r.insertBefore(c,p),r.insertBefore(d,c.nextSibling)):(r.appendChild(c),r.appendChild(d));}_clone_pPr_scrubbing_headings(e){let n=e.cloneNode(true),r=M(n,"w:pStyle");if(r){let i=r.getAttribute("w:val");i&&(i.startsWith("Heading")||i==="Title"||i.replace(/\s+/g,"").startsWith("Heading"))&&n.removeChild(r);}let s=M(n,"w:outlineLvl");return s&&n.removeChild(s),n}_track_insert_multiline(e,n,r,s,i=null,o=false,a=false){if(!e)return {first_node:null,last_p:null,last_ins:null,used_block_mode:false};let l=this.doc.part._element.ownerDocument,u=e.split(/[\r\n]+/),c=null;if(r!==null)c=r._element;else if(n!==null){let T=n._element;for(;T&&T.tagName!=="w:p";)T=T.parentNode;c=T;}let d=[],f=new Set(["w:r","w:ins","w:del"]),h=i&&i.parentNode?i:null,_=n!==null&&n._element.parentNode?n._element:null,p=h??_,m=a&&h===null&&_!==null;if(c!==null&&p!==null){let T=p;for(;T&&T.parentNode!==c;)if(T=T.parentNode,T===c){T=null;break}if(T){let F=m?T:T.nextSibling;for(;F;)F.nodeType===1&&f.has(F.tagName)&&d.push(F),F=F.nextSibling;}}else if(c!==null&&a){let T=c.firstChild;for(;T;)T.nodeType===1&&f.has(T.tagName)&&d.push(T),T=T.nextSibling;}for(;u.length>1&&u[u.length-1]===""&&d.length===0;)u.pop();if(u.length===0)return {first_node:null,last_p:null,last_ins:null,used_block_mode:false};let[w,k]=this._parse_markdown_style(u[0]),g=k!==null&&c!==null,v=null,x=null;g||(x=this._build_tracked_ins_for_line((w===u[0],u[0]),n,s,l,o),v=x);let E=g?u:u.slice(1);if(E.length===0)return {first_node:v,last_p:null,last_ins:x,used_block_mode:false};if(!c)return {first_node:v,last_p:null,last_ins:x,used_block_mode:false};let C=c.parentNode;if(!C)return {first_node:v,last_p:null,last_ins:x,used_block_mode:false};let A=y((T,F)=>{C.insertBefore(T,F.nextSibling);},"insertAfterEl"),N=null,P=null,D=c;for(let T=0;T<E.length;T++){let F=E[T],[I,S]=this._parse_markdown_style(F),R=l.createElement("w:p");if(S)this._set_paragraph_style(R,S);else {let Y=M(c,"w:pPr");Y&&R.appendChild(this._clone_pPr_scrubbing_headings(Y));}let j=M(R,"w:pPr");j||(j=l.createElement("w:pPr"),R.insertBefore(j,R.firstChild));let B=M(j,"w:rPr");B||(B=l.createElement("w:rPr"),j.appendChild(B));let L=this._create_track_change_tag("w:ins","",s);B.appendChild(L);let U=this._build_tracked_ins_for_line(I,n,s,l,o);U&&R.appendChild(U),A(R,D),D=R,N=R,P=U,v||(v=R);}if(!g&&N&&d.length>0)for(let T of d)T.parentNode?.removeChild(T),N.appendChild(T);return {first_node:v,last_p:N,last_ins:P,used_block_mode:g}}_build_tracked_ins_for_line(e,n,r,s,i=false){if(!e&&e!=="")return null;let o=this._create_track_change_tag("w:ins","",r),a=this._parse_inline_markdown(e);if(a.length===0)return null;for(let[l,u]of a){let c=s.createElement("w:r");if(n&&n._element){let f=M(n._element,"w:rPr");if(f){let h=f.cloneNode(true),_=["w:vanish","w:strike","w:dstrike","w:i","w:iCs"];i&&_.push("w:b","w:bCs");for(let p of _){let m=M(h,p);m&&h.removeChild(m);}c.appendChild(h);}}this._apply_run_props(c,u,false);let d=s.createElement("w:t");this._set_text_content(d,l),c.appendChild(d),o.appendChild(c);}return o}_parse_markdown_style(e){let n=e.trimStart();if(n.startsWith("#")){let s=0,i=n;for(;i.startsWith("#");)s++,i=i.substring(1);if(i.startsWith(" "))return [i.trim(),`Heading ${s}`]}if(n.startsWith("* ")||n.startsWith("- "))return [n.substring(2).trim(),"List Paragraph"];let r=n.match(/^1\.\s+/);return r?[n.substring(r[0].length).trim(),"List Number"]:[e,null]}_edit_declares_emphasis(e){for(let n of [e?.target_text,e?.new_text]){if(!n||!n.includes("**")&&!n.includes("_"))continue;if(this._parse_inline_markdown(n).some(([,s])=>s&&Object.keys(s).length>0))return true}return false}_parse_inline_markdown(e,n={}){if(!e)return [];let r=/(\*\*.*?\*\*)|(_.*?_)/,s=e.match(r);if(!s)return [[e,n]];let i=s.index,o=s[0],a=i+o.length,l=o.startsWith("**"),u=l?o.substring(2,o.length-2):o.substring(1,o.length-1),c=e.substring(0,i),d=e.substring(a),f=[];c&&f.push([c,n]);let h={...n};return l?h.bold=true:h.italic=true,f.push(...this._parse_inline_markdown(u,h)),f.push(...this._parse_inline_markdown(d,n)),f}_apply_run_props(e,n,r=false){if(!n){if(!r)return;n={};}let s=M(e,"w:rPr");if(!s&&(n.bold||n.italic||r)&&(s=e.ownerDocument.createElement("w:rPr"),e.appendChild(s)),s){let i=e.ownerDocument;if(n.bold){let o=M(s,"w:b");o||(o=i.createElement("w:b"),s.appendChild(o)),o.setAttribute("w:val","1");}else if(r){let o=M(s,"w:b");o&&s.removeChild(o);}if(n.italic){let o=M(s,"w:i");o||(o=i.createElement("w:i"),s.appendChild(o)),o.setAttribute("w:val","1");}else if(r){let o=M(s,"w:i");o&&s.removeChild(o);}}}_set_paragraph_style(e,n,r=null){let s=e.ownerDocument,i=M(e,"w:pPr");i&&e.removeChild(i);let o=s.createElement("w:pPr"),a=s.createElement("w:pStyle"),l=n.replace(/\s+/g,"");if(a.setAttribute("w:val",l),o.appendChild(a),l==="ListParagraph"){let u=this._ensure_bullet_num_id();if(u){let c=s.createElement("w:numPr"),d=s.createElement("w:ilvl");d.setAttribute("w:val","0");let f=s.createElement("w:numId");f.setAttribute("w:val",u),c.appendChild(d),c.appendChild(f),o.appendChild(c);}}if(r!==null){let u=this._create_track_change_tag("w:pPrChange","",r),c=i?i.cloneNode(true):s.createElement("w:pPr"),d=M(c,"w:pPrChange");d&&c.removeChild(d),u.appendChild(c),o.appendChild(u);}e.insertBefore(o,e.firstChild);}static _NUMBERING_CT="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml";static _NUMBERING_RT="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering";_ensure_bullet_num_id(){let e=this.doc.pkg,n="http://schemas.openxmlformats.org/wordprocessingml/2006/main",r='<w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText w:val="\uF0B7"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr><w:rPr><w:rFonts w:ascii="Symbol" w:hAnsi="Symbol" w:hint="default"/></w:rPr></w:lvl>',s=e.parts.find(N=>String(N.partname).replace(/^\//,"")==="word/numbering.xml");if(!s){let N=`<w:numbering xmlns:w="${n}"><w:abstractNum w:abstractNumId="0"><w:multiLevelType w:val="singleLevel"/>`+r+'</w:abstractNum><w:num w:numId="1"><w:abstractNumId w:val="0"/></w:num></w:numbering>';try{s=e.addPart("/word/numbering.xml",V._NUMBERING_CT,N),this.doc.relateTo(s,V._NUMBERING_RT);}catch{return null}return delete e._adeu_numbering_cache,"1"}let i=s._element,o=$(i,"w:abstractNum"),a=$(i,"w:num"),l=null;for(let N of o){let P=N.getAttribute("w:abstractNumId");if(P!==null){for(let D of $(N,"w:lvl")){if((D.getAttribute("w:ilvl")||"0")!=="0")continue;let T=M(D,"w:numFmt");T&&T.getAttribute("w:val")==="bullet"&&(l=P);break}if(l!==null)break}}let u=0;for(let N of a){let P=parseInt(N.getAttribute("w:numId")||"0",10);!isNaN(P)&&P>u&&(u=P);}let c=i.ownerDocument;if(l!==null){for(let D of a){let T=M(D,"w:abstractNumId");if(T&&T.getAttribute("w:val")===l){let F=D.getAttribute("w:numId");if(F&&F!=="0")return F}}let N=c.createElement("w:num");N.setAttribute("w:numId",String(u+1));let P=c.createElement("w:abstractNumId");return P.setAttribute("w:val",l),N.appendChild(P),i.appendChild(N),delete e._adeu_numbering_cache,String(u+1)}let d=-1;for(let N of o){let P=parseInt(N.getAttribute("w:abstractNumId")||"-1",10);!isNaN(P)&&P>d&&(d=P);}let f=c.createElement("w:abstractNum");f.setAttribute("w:abstractNumId",String(d+1));let h=c.createElement("w:multiLevelType");h.setAttribute("w:val","singleLevel"),f.appendChild(h);let _=c.createElement("w:lvl");_.setAttribute("w:ilvl","0");let p=c.createElement("w:start");p.setAttribute("w:val","1"),_.appendChild(p);let m=c.createElement("w:numFmt");m.setAttribute("w:val","bullet"),_.appendChild(m);let w=c.createElement("w:lvlText");w.setAttribute("w:val","\uF0B7"),_.appendChild(w);let k=c.createElement("w:lvlJc");k.setAttribute("w:val","left"),_.appendChild(k);let b=c.createElement("w:pPr"),g=c.createElement("w:ind");g.setAttribute("w:left","720"),g.setAttribute("w:hanging","360"),b.appendChild(g),_.appendChild(b);let v=c.createElement("w:rPr"),x=c.createElement("w:rFonts");x.setAttribute("w:ascii","Symbol"),x.setAttribute("w:hAnsi","Symbol"),x.setAttribute("w:hint","default"),v.appendChild(x),_.appendChild(v),f.appendChild(_);let E=a.find(N=>N.parentNode===i)||null;E?i.insertBefore(f,E):i.appendChild(f);let C=c.createElement("w:num");C.setAttribute("w:numId",String(u+1));let A=c.createElement("w:abstractNumId");return A.setAttribute("w:val",String(d+1)),C.appendChild(A),i.appendChild(C),delete e._adeu_numbering_cache,String(u+1)}_anchor_reply_comment(e,n){let r=this.doc.part._element.ownerDocument,s=$(this.doc.element,"w:commentRangeStart").filter(m=>m.getAttribute("w:id")===e);if(s.length===0)return;let i=s[0],o=r.createElement("w:commentRangeStart");o.setAttribute("w:id",n),Ue(o,i);let a=$(this.doc.element,"w:commentRangeEnd").filter(m=>m.getAttribute("w:id")===e);if(a.length===0)return;let l=a[0],u=$(this.doc.element,"w:commentReference").filter(m=>m.getAttribute("w:id")===e),c=l;if(u.length>0){let m=u[0];m.parentNode&&m.parentNode.tagName==="w:r"&&(c=m.parentNode);}let d=r.createElement("w:commentRangeEnd");d.setAttribute("w:id",n),Ue(d,c);let f=r.createElement("w:r"),h=r.createElement("w:rPr"),_=r.createElement("w:rStyle");_.setAttribute("w:val","CommentReference"),h.appendChild(_),f.appendChild(h);let p=r.createElement("w:commentReference");p.setAttribute("w:id",n),f.appendChild(p),Ue(f,d);}_clean_wrapping_comments(e){let n=0,r=e;for(;;){let c=Ee(r);if(c&&(c.tagName==="w:ins"||c.tagName==="w:del"))r=c;else break}let s=e;for(;;){let c=ve(s);if(c&&(c.tagName==="w:ins"||c.tagName==="w:del"))s=c;else break}let i=[],o=Ee(r);for(;o;)if(o.tagName==="w:commentRangeStart")i.push(o),o=Ee(o);else if(o.tagName==="w:rPr"||o.tagName==="w:pPr")o=Ee(o);else break;let a=[],l=ve(s);for(;l;)if(l.tagName==="w:commentRangeEnd")a.push(l),l=ve(l);else if(l.tagName==="w:r"&&$(l,"w:commentReference").length>0)a.push(l),l=ve(l);else if(l.tagName==="w:commentReference")a.push(l),l=ve(l);else break;let u=new Set;for(let c of a)if(c.tagName==="w:commentRangeEnd"){let d=c.getAttribute("w:id");d&&u.add(d);}else {let d=$(c,"w:commentReference")[0];if(!d&&c.tagName==="w:commentReference"&&(d=c),d){let f=d.getAttribute("w:id");f&&u.add(f);}}for(let c of i){let d=c.getAttribute("w:id");if(d&&u.has(d)){this.comments_manager.deleteComment(d),n++,c.parentNode&&c.parentNode.removeChild(c);for(let f of a){let h=null;if(f.tagName==="w:commentRangeEnd")h=f.getAttribute("w:id");else {let _=$(f,"w:commentReference")[0];!_&&f.tagName==="w:commentReference"&&(_=f),_&&(h=_.getAttribute("w:id"));}h===d&&f.parentNode&&f.parentNode.removeChild(f);}}}return n}_delete_comments_in_element(e){let n=0,r=$(e,"w:commentReference");for(let s of r){let i=s.getAttribute("w:id");if(i){this.comments_manager.deleteComment(i),n++;for(let o of ["w:commentRangeStart","w:commentRangeEnd"]){let a=$(this.doc.element,o);for(let l of a)l.getAttribute("w:id")===i&&l.parentNode&&l.parentNode.removeChild(l);}}}return n}validate_edits(e,n=0){let r=[];this.mapper.full_text||this.mapper._build_map(),r.push(...Mo(e,n));for(let s=0;s<e.length;s++){let i=e[s];if(typeof i!="object"||i===null){r.push(`- Edit ${s+1+n} Failed: Invalid change format. Expected a JSON object, but received a primitive ${typeof i}. Do not pass raw strings.`);continue}if(i._match_start_index!==void 0&&i._match_start_index!==null||i._resolved_start_idx!==void 0&&i._resolved_start_idx!==null)continue;if(i.target_text===void 0||i.target_text===null||!String(i.target_text).trim()){i.type==="insert_row"?r.push(`- Edit ${s+1+n} Failed: insert_row requires target_text (text inside an existing row to anchor on) and cells (the new row's cell values).`):i.type==="delete_row"?r.push(`- Edit ${s+1+n} Failed: delete_row requires target_text (text inside the row to delete).`):r.push(`- Edit ${s+1+n} Failed: target_text is empty. Pure insertions are expressed as a replacement: put the text immediately around the insertion point in target_text and repeat it (plus the new text) in new_text.`);continue}if(i.type==="modify"&&(i.new_text===void 0||i.new_text===null))if(i.comment&&String(i.comment).trim())i.new_text=i.target_text;else {r.push(`- Edit ${s+1+n} Failed: modify requires new_text (an empty string deletes the target; to attach a comment without changing the text, supply the comment and omit new_text).`);continue}let o=i.regex||false,a=i.match_mode||"strict";if(o)try{new RegExp(i.target_text);}catch(h){r.push(`- Edit ${s+1+n} Failed: target_text is not a valid regular expression (${h?.message??h}). Fix the pattern, or set "regex": false to match the text literally.`);continue}let l=this.mapper.drop_virtual_only_matches(this.mapper.find_all_match_indices(i.target_text,o)),u=this.mapper.full_text,c=this.mapper;l.length===0&&(this.clean_mapper||(this.clean_mapper=new ke(this.doc,true)),l=this.clean_mapper.drop_virtual_only_matches(this.clean_mapper.find_all_match_indices(i.target_text,o)),l.length>0&&(u=this.clean_mapper.full_text,c=this.clean_mapper)),u===this.mapper.full_text&&l.length>0&&(l=l.filter(([_,p])=>{let m=this.mapper.spans.filter(w=>w.run!==null&&w.end>_&&w.start<_+p);return m.length===0?true:m.some(w=>!w.del_id)}));let d=false,f=new Set;if(l.length===0){this.original_mapper||(this.original_mapper=new ke(this.doc,false,true));let h=this.original_mapper.drop_virtual_only_matches(this.original_mapper.find_all_match_indices(i.target_text,o));if(h.length>0){d=true;for(let[_,p]of h){let m=this.original_mapper.spans.filter(w=>w.end>_&&w.start<_+p);for(let w of m)if(w.run!==null){let k=w.run._element;for(;k;){if(k.nodeType===1&&k.tagName==="w:del"){let b=k.getAttribute("w:author");b&&f.add(b);break}k=k.parentNode;}}}}}if(l.length===0)if(d){let h=f.size>0?`by ${Array.from(f).sort().join(", ")}`:"by an existing revision";r.push(`- Edit ${s+1+n} Failed: Target text matches text inside a tracked deletion ${h}. Reject/accept that change first or target the active replacement text instead.`);}else {let h=this._nearest_match_hint(i.target_text,o);r.push(`- Edit ${s+1+n} Failed: Target text not found in document:
99
+ "${he(i.target_text,qt)}"${h}`);}else if(l.length>1&&a==="strict")if(i.target_text.includes("|"))l=l.slice(0,1);else {let h=l.map(([_,p])=>[_,_+p]);r.push(Po(s+1+n,i.target_text,u,h));}if(l.length===1){let[h,_]=l[0],p=u.substring(h,h+_),[m,w]=qe(p,i.new_text||""),k=p.length-w,b=p.substring(m,k),g=(i.new_text||"").substring(m,(i.new_text||"").length-w),x=c.part_ranges.filter(A=>A[1]>A[0]).length>1?Array.from(new Set(c.spans.filter(A=>A.run!==null&&A.end>h&&A.start<h+_).map(A=>A.part_index))).sort((A,N)=>A-N):[];if(x.length>1){let A=x.map(N=>c.part_kind_of(N)||"?").join(" \u2192 ");r.push(`- Edit ${s+1+n} Failed: target_text spans a structural document-part boundary (${A}). Headers, body, footers and footnotes are separate Word parts \u2014 an edit cannot cross between them. Anchor the edit on text within a single part (split it into one edit per part if both sides must change).`);}let E=h+m,C=h+_-w;if(C>E&&c.spans.filter(N=>N.end>E&&N.start<C&&(N.run!==null||N.text.trim()!=="")).some(N=>N.is_image_marker)&&r.push(`- Edit ${s+1+n} Failed: the target overlaps a read-only image marker (![alt](docx-image:N)). Images cannot be edited or removed via text replacement \u2014 target the text around the image instead.`),i.comment&&(i.new_text||"")===(i.target_text||"")){let A=c.part_kind_at(h);A!==null&&A!=="body"&&r.push(`- Edit ${s+1+n} Failed: comments cannot be anchored inside a ${A} part \u2014 Word only supports comments in the main document body. Comment on the related body text instead.`);}if(V._introduces_table_row_text(c,h,_,b,g)&&r.push(`- Edit ${s+1+n} Failed: new_text introduces a pipe-delimited row line inside a table. Text replacement cannot create table rows \u2014 use the structured 'insert_row' operation instead (e.g. {"type": "insert_row", "target_text": "<anchor row text>", "cells": ["...", "..."]}).`),b.includes(`
100
100
 
101
- `)&&!(_.split(`
101
+ `)&&!(p.split(`
102
102
 
103
103
  `).length===(i.new_text||"").split(`
104
104
 
105
- `).length))if(m.includes(`
105
+ `).length))if(g.includes(`
106
106
 
107
- `)){let E=_.split(`
107
+ `)){let N=p.split(`
108
108
 
109
- `);E.length>=2&&E[0].trim()!==""&&E[E.length-1].trim()!==""&&r.push(`- Edit ${s+1+n} Failed: target_text spans a paragraph boundary with body text on both sides. The paragraph break is a structural element, not literal text, so it cannot be replaced as a single span without corrupting the document. Split this into one edit per paragraph.`);}else {let E=b.split(`
109
+ `);N.length>=2&&N[0].trim()!==""&&N[N.length-1].trim()!==""&&r.push(`- Edit ${s+1+n} Failed: target_text spans a paragraph boundary with body text on both sides. The paragraph break is a structural element, not literal text, so it cannot be replaced as a single span without corrupting the document. Split this into one edit per paragraph.`);}else {let N=b.split(`
110
110
 
111
- `);E.length>=2&&E[0].trim()!==""&&E[E.length-1].trim()!==""&&r.push(`- Edit ${s+1+n} Failed: target_text spans a paragraph boundary with body text on both sides. The paragraph break is a structural element, not literal text, so it cannot be replaced as a single span without corrupting the document. Split this into one edit per paragraph.`);}}for(let[h,p]of a){let _=c.spans.filter(b=>b.end>h&&b.start<h+p),g=new Set,w=new Set,k=false;for(let b of _){if(b.run===null)continue;let m=false;if(b.ins_id){let v=I(this.doc.element,"w:ins").filter(N=>N.getAttribute("w:id")===b.ins_id);if(v.length>0){let N=v[0].getAttribute("w:author");N&&N!==this.author&&(g.add(N),m=true);}}m||(k=true);}for(let b of _)if(b.comment_ids)for(let m of b.comment_ids){let v=this.mapper.comments_map[m];v&&v.author&&v.author!==this.author&&w.add(v.author);}if(g.size>0&&!((l==="strict"||l==="first")&&!k)){r.push(`- Edit ${s+1+n} Failed: Modification targets an active insertion from another author (${Array.from(g).join(", ")}). Accept that change first or scope your edit outside of it.`);continue}w.size>0&&l==="all"&&r.push(`- Edit ${s+1+n} Failed: match_mode="all" would sweep through a comment range from another author (${Array.from(w).join(", ")}). Target the commented text deliberately with match_mode "strict" or "first", or scope your edit outside of it.`);}if((i.type==="insert_row"||i.type==="delete_row")&&a.length>0){let[h,p]=a[0],_=V._column_count_at(c,h,p);_===null?r.push(`- Edit ${s+1+n} Failed: ${i.type} target text was found, but it is not inside a table row. Anchor the operation on text that appears within the table.`):i.type==="insert_row"&&Array.isArray(i.cells)&&i.cells.length>_&&r.push(`- Edit ${s+1+n} Failed: insert_row provides ${i.cells.length} cells but the target table has ${_} column(s). The extra cell(s) would be dropped. Provide at most ${_} cells \u2014 rows given fewer cells are padded with empty ones.`);}}return r}static _introduces_table_row_text(e,n,r,s,i){if(!i.includes(`
111
+ `);N.length>=2&&N[0].trim()!==""&&N[N.length-1].trim()!==""&&r.push(`- Edit ${s+1+n} Failed: target_text spans a paragraph boundary with body text on both sides. The paragraph break is a structural element, not literal text, so it cannot be replaced as a single span without corrupting the document. Split this into one edit per paragraph.`);}}for(let[h,_]of l){let p=c.spans.filter(b=>b.end>h&&b.start<h+_),m=new Set,w=new Set,k=false;for(let b of p){if(b.run===null)continue;let g=false;if(b.ins_id){let v=$(this.doc.element,"w:ins").filter(x=>x.getAttribute("w:id")===b.ins_id);if(v.length>0){let x=v[0].getAttribute("w:author");x&&x!==this.author&&(m.add(x),g=true);}}g||(k=true);}for(let b of p)if(b.comment_ids)for(let g of b.comment_ids){let v=this.mapper.comments_map[g];v&&v.author&&v.author!==this.author&&w.add(v.author);}if(m.size>0&&!((a==="strict"||a==="first")&&!k)){r.push(`- Edit ${s+1+n} Failed: Modification targets an active insertion from another author (${Array.from(m).join(", ")}). Accept that change first or scope your edit outside of it.`);continue}w.size>0&&a==="all"&&r.push(`- Edit ${s+1+n} Failed: match_mode="all" would sweep through a comment range from another author (${Array.from(w).join(", ")}). Target the commented text deliberately with match_mode "strict" or "first", or scope your edit outside of it.`);}if((i.type==="insert_row"||i.type==="delete_row")&&l.length>0){let[h,_]=l[0],p=V._column_count_at(c,h,_);p===null?r.push(`- Edit ${s+1+n} Failed: ${i.type} target text was found, but it is not inside a table row. Anchor the operation on text that appears within the table.`):i.type==="insert_row"&&Array.isArray(i.cells)&&i.cells.length>p&&r.push(`- Edit ${s+1+n} Failed: insert_row provides ${i.cells.length} cells but the target table has ${p} column(s). The extra cell(s) would be dropped. Provide at most ${p} cells \u2014 rows given fewer cells are padded with empty ones.`);}}return r}static _introduces_table_row_text(e,n,r,s,i){if(!i.includes(`
112
112
  `)||!i.includes(" | "))return false;let o=i.split(`
113
- `).filter(a=>a.includes(" | ")).length,l=s.split(`
114
- `).filter(a=>a.includes(" | ")).length;return o<=l?false:V._column_count_at(e,n,Math.max(r,1))!==null}static _column_count_at(e,n,r){for(let s of e.spans){if(s.end<=n||s.start>=n+r)continue;let i=null;for(s.run!==null?i=s.run._element:s.paragraph!==null&&(i=s.paragraph._element);i;){if(i.nodeType===1&&i.tagName==="w:tr")return I(i,"w:tc").filter(o=>o.parentNode===i).length;i=i.parentNode;}}return null}validate_review_actions(e){let n=[],r=new Map,s=new Set;for(let i=0;i<e.length;i++){let o=e[i],l=o.type,a=o.target_id??"";if(l==="reply"){if(!String(o.text??"").trim()){n.push(`- Action ${i+1} Failed: reply text for ${a} is empty or whitespace-only. Word would show a blank comment bubble \u2014 provide the reply content in 'text'.`);continue}let u=a+"\0"+String(o.text).trim();s.has(u)&&n.push(`- Action ${i+1} Failed: duplicate reply \u2014 this batch already replies to ${a} with the same text. Remove the duplicate action.`),s.add(u);}else if(l==="accept"||l==="reject"){let u=r.get(a);if(u!==void 0){let[c,d]=u;d===l?n.push(`- Action ${i+1} Failed: duplicate action \u2014 Action ${c+1} in this batch already applies '${l}' to ${a}. A change can only be resolved once; remove the duplicate action.`):n.push(`- Action ${i+1} Failed: conflicting actions \u2014 Action ${c+1} in this batch applies '${d}' to ${a}, but this action applies '${l}'. Decide the outcome and keep exactly one of them.`);}else r.set(a,[i,l]);}}if(n.length>0)return n;for(let i=0;i<e.length;i++){let o=e[i],l=o.type;if(l==="reply"){let a=o.target_id.replace("Com:",""),u=false,c=this.doc.pkg.parts.find(d=>d.contentType==="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml");c&&(u=I(c._element,"w:comment").some(f=>f.getAttribute("w:id")===a)),u||n.push(this._action_not_found_error(o.target_id,"reply",`- Action ${i+1} Failed:`));}else if(l==="accept"||l==="reject"){let a=o.target_id.replace("Chg:",""),u=I(this.doc.element,"w:ins").filter(f=>f.getAttribute("w:id")===a),c=I(this.doc.element,"w:del").filter(f=>f.getAttribute("w:id")===a),d=I(this.doc.element,"w:pPrChange").filter(f=>f.getAttribute("w:id")===a);u.length===0&&c.length===0&&d.length===0&&n.push(this._action_not_found_error(o.target_id,l,`- Action ${i+1} Failed:`));}}return n}process_batch(e){return Array.isArray(e)&&(e=e.map(n=>{if(typeof n=="string")try{let r=JSON.parse(n);return r!==null&&typeof r=="object"?r:n}catch{return n}return n})),this._process_batch_internal(e)}_process_batch_internal(e){for(let w of e)if(w&&typeof w=="object"&&w.type==="modify"&&w.target_text&&w.new_text){let[k,b]=No(w.target_text,w.new_text);w.target_text=k,w.new_text=b;}this.skipped_details=[];let n=e.filter(w=>w!==null&&typeof w=="object"&&["accept","reject","reply"].includes(w.type)),r=e.filter(w=>w===null||typeof w!="object"||!["accept","reject","reply"].includes(w.type)),s=n.length>0?this.validate_review_actions(n):[];n.length>0&&s.length===0&&(s=this.validate_action_pairing(n));let o=r.length>0&&s.length>0?this.validate_edits(r):[],l=[...s,...o];if(l.length>0)throw new pt(l);let a=0,u=0,c=0;if(n.length>0){let w=this.apply_review_actions(n);if(a=w[0],u=w[1],c=w[2],u>0)throw new pt(this.skipped_details);a>0&&(this.mapper._build_map(),this.clean_mapper&&this.clean_mapper._build_map());}let[d]=Je(this.mapper.full_text),h=He(d,"").body_page_offsets,p=[],_=0,g=0;if(r.length>0){let w=y(b=>b._resolved_start_idx!==void 0&&b._resolved_start_idx!==null?b._resolved_start_idx:b._match_start_index!==void 0&&b._match_start_index!==null?b._match_start_index:null,"pinned_idx"),k=r.map((b,m)=>({edit:b,i:m})).sort((b,m)=>{let v=w(b.edit),N=w(m.edit);return v===null&&N===null?b.i-m.i:v===null?1:N===null?-1:N-v||b.i-m.i});{let b=bo(this.doc),m=this.current_id;try{let v=[],N=0;for(let{edit:A,i:C}of k){let x;try{x=this.validate_edits([A],C);}catch(E){if(!(E instanceof Ce))throw E;x=[`- Edit ${C+1} Failed: ${E.message}`];}if(x.length>0){if(N>0){let E=tr(N);x=x.map(T=>T+E);}v.push(...x);}else if(this.apply_edits([A],h),A._applied_status&&!A._any_sub_failure)N++,this.mapper=new ke(this.doc),this.clean_mapper=null;else {let E=A._error_msg||`- Edit ${C+1} Failed: Failed to apply edit.`;N>0&&(E+=tr(N)),v.push(E);break}}if(v.length>0)throw new pt(v)}catch(v){throw xo(this.doc,b),this.current_id=m,this.mapper=new ke(this.doc),this.comments_manager=new nt(this.doc),this.clean_mapper=null,v}_=r.filter(v=>v._applied_status&&!v._any_sub_failure).length,g=r.length-_;for(let v of r){let N=v._applied_status||false,A=v._error_msg||null,C=null,x=null,E=v._warning||null;if(N){let T=this._build_edit_context_previews(v);C=T[0],x=T[1];}else E=E||this._check_punctuation_warning(v.target_text||"");p.push({status:N?"applied":"failed",type:v.type||"modify",target_text:he(v.target_text||"",Lt),new_text:he(V._report_new_text(v),Lt),comment:v.comment??null,warning:E,error:A,critic_markup:C,clean_text:x,pages:v._pages||[],heading_path:v._heading_path||"",occurrences_modified:v._occurrences_modified||0,match_mode:v.match_mode||"strict"});}}}return {actions_applied:a,actions_skipped:u,actions_already_resolved:c,edits_applied:_,edits_skipped:g,occurrences_modified:p.reduce((w,k)=>w+(k.occurrences_modified||0),0),skipped_details:this.skipped_details,edits:p,engine:"node",version:"1.18.2"}}static _flag_surviving_python_backreference(e,n){let r=/\\(\d+)|\\g<(\d+)>/.exec(e.new_text||"");if(!r||!n.includes(r[0]))return;let s=0;try{let o=new RegExp(`(?:${e.target_text})|`).exec("");s=o?o.length-1:0;}catch{return}let i=parseInt(r[1]??r[2],10);i>0&&i<=s&&(e._warning=`new_text contains '${r[0]}', which JavaScript's replace does not expand \u2014 the literal text '${r[0]}' was written into the document. For a capture-group backreference use $${i} (\\N and \\g<N> are Python syntax). If you meant literal text, ignore this warning.`);}static _ids_needed(e){let n=e._internal_op;return n==null&&(!e.target_text&&e.new_text?n="INSERTION":e.target_text&&!e.new_text?n="DELETION":n="MODIFICATION"),n==="STYLE_ONLY"?[false,false]:(n==="STYLE_AND_TEXT"&&(e.target_text&&e.new_text?n="MODIFICATION":!e.target_text&&e.new_text?n="INSERTION":e.target_text&&!e.new_text?n="DELETION":n="COMMENT_ONLY"),[n==="DELETION"||n==="MODIFICATION",n==="INSERTION"||n==="MODIFICATION"])}apply_edits(e,n=[]){if(!n||n.length===0){let[c]=Je(this.mapper.full_text);n=He(c,"").body_page_offsets;}let i=[];for(let c of e){if(typeof c!="object"||c===null){continue}c._applied_status=false,c._error_msg=null,c._any_sub_failure=false,c._minted_change_ids=[],c._minted_comment_ids=[],c._reserved_del_id=null,c._reserved_ins_id=null,c._reserved_row_id=null;}for(let c of e)if(!(typeof c!="object"||c===null))if(c._resolved_start_idx!==void 0&&c._resolved_start_idx!==null||c._match_start_index!==void 0&&c._match_start_index!==null)(c._resolved_start_idx===void 0||c._resolved_start_idx===null)&&(c._resolved_start_idx=c._match_start_index),c._active_mapper_ref||(this.clean_mapper||(this.clean_mapper=new ke(this.doc,true)),c._active_mapper_ref=this.clean_mapper),i.push([c,c.new_text||null]);else if(c.type==="insert_row"||c.type==="delete_row"){let d=this.mapper.drop_virtual_only_matches(this.mapper.find_all_match_indices(c.target_text)),f=this.mapper;if(d.length===0&&(this.clean_mapper||(this.clean_mapper=new ke(this.doc,true)),d=this.clean_mapper.drop_virtual_only_matches(this.clean_mapper.find_all_match_indices(c.target_text)),f=this.clean_mapper),d.length>0){let h=c.match_mode||"strict",p=[],_=new Set;for(let g of d){let w=g[0],[k,b]=f.get_insertion_anchor(w,false),m=null;k?m=k._element:b&&(m=b._element);let v=m;for(;v&&v.tagName!=="w:tr";)v=v.parentNode;v&&(_.has(v)||(_.add(v),p.push(g)));}if(p.length>0){let g=p;if((h==="strict"||h==="first")&&(g=p.slice(0,1)),h==="all"||g.length>1)for(let w of g){let k={...c,_resolved_start_idx:w[0],_active_mapper_ref:f,_parent_edit_ref:c};i.push([k,null]);}else c._resolved_start_idx=g[0][0],c._active_mapper_ref=f,i.push([c,null]);}else {c._applied_status=false;let w=`- Failed to locate row target: '${(c.target_text||"").trim().substring(0,40)}...'`;this.skipped_details.push(w),c._error_msg=w;}}else {c._applied_status=false;let p=`- Failed to locate row target: '${(c.target_text||"").trim().substring(0,40)}...'`;this.skipped_details.push(p),c._error_msg=p;}}else {let d;try{d=this._pre_resolve_heuristic_edit(c);}catch(f){if(!(f instanceof Ce))throw f;c._applied_status=false;let h=`- Failed to apply edit targeting: '${(c.target_text||"").substring(0,40)}...' (${f.message})`;this.skipped_details.push(h),c._error_msg=h;continue}if(d)if(Array.isArray(d))for(let f of d)f._resolved_start_idx=f._match_start_index,f._parent_edit_ref=c,(c._resolved_start_idx===void 0||c._resolved_start_idx===null)&&(c._resolved_start_idx=f._resolved_start_idx),c._resolved_proxy_edit||(c._resolved_proxy_edit=f),i.push([f,f.new_text]);else d._resolved_start_idx=d._match_start_index,d._parent_edit_ref=c,c._resolved_start_idx=d._resolved_start_idx,c._resolved_proxy_edit=d,i.push([d,d.new_text]);else {c._applied_status=false;let p=`- Failed to apply edit targeting: '${(c.target_text||"insertion").trim().substring(0,40)}...'`;this.skipped_details.push(p),c._error_msg=p;}}i.sort((c,d)=>(d[0]._resolved_start_idx||0)-(c[0]._resolved_start_idx||0));{let c=[...i].sort((d,f)=>(d[0]._resolved_start_idx||0)-(f[0]._resolved_start_idx||0));for(let[d]of c){let f=d._parent_edit_ref||d;if(Array.isArray(f._minted_change_ids)||(f._minted_change_ids=[]),d.type==="insert_row"||d.type==="delete_row"){d._reserved_row_id==null&&(d._reserved_row_id=this._getNextId(),f._minted_change_ids.push(d._reserved_row_id));continue}if(d.type!=="modify")continue;let[h,p]=V._ids_needed(d);h&&d._reserved_del_id==null&&(d._reserved_del_id=this._getNextId(),f._minted_change_ids.push(d._reserved_del_id)),p&&d._reserved_ins_id==null&&(d._reserved_ins_id=this._getNextId(),f._minted_change_ids.push(d._reserved_ins_id));}}for(let[c]of i)this._capture_preview_context(c),c._parent_edit_ref&&this._capture_parent_preview_context(c._parent_edit_ref);let o=[],l=new Set;for(let[c,d]of i){let f=c._resolved_start_idx||0,h=c.type==="insert_row"?f:f+(c.target_text?c.target_text.length:0);if(o.some(([k,b])=>f<b&&h>k)){let m=`- Skipped overlapping edit targeting: '${(c.target_text||"insertion").trim().substring(0,40)}...'`;this.skipped_details.push(m),c._applied_status=false,c._error_msg=m,c._any_sub_failure=true;let v=c._parent_edit_ref;v&&(v._applied_status=false,v._error_msg=m,v._any_sub_failure=true);continue}let _=false,g=this.current_id,w=this.comments_manager.nextId;if(c.type==="modify"?_=this._apply_single_edit_indexed(c,d,false):(c.type==="insert_row"||c.type==="delete_row")&&(_=this._apply_table_edit(c,false)),_){let k=c._parent_edit_ref||c;Array.isArray(k._minted_change_ids)||(k._minted_change_ids=[]);for(let b=g+1;b<=this.current_id;b++)k._minted_change_ids.push(String(b));Array.isArray(k._minted_comment_ids)||(k._minted_comment_ids=[]);for(let b=w;b<this.comments_manager.nextId;b++)k._minted_comment_ids.push(String(b));}if(_){let k=c._split_group_id,b=k==null||!l.has(k);b&&k!==void 0&&k!==null&&l.add(k),o.push([f,h]),c._applied_status=true;let m=c._parent_edit_ref;if(m){m._applied_status=true,b&&(m._occurrences_modified=(m._occurrences_modified||0)+1);let[v,N]=this._get_heading_path_and_page(f,this.mapper.full_text,n),A=m._pages||[];A.includes(N)||A.unshift(N),m._pages=A,m._heading_path=v;}else {b&&(c._occurrences_modified=(c._occurrences_modified||0)+1);let[v,N]=this._get_heading_path_and_page(f,this.mapper.full_text,n),A=c._pages||[];A.includes(N)||A.unshift(N),c._pages=A,c._heading_path=v;}}else {let m=`- Failed to apply edit targeting: '${(c.target_text||"insertion").trim().substring(0,40)}...'`;this.skipped_details.push(m),c._applied_status=false,c._error_msg=m,c._any_sub_failure=true;let v=c._parent_edit_ref;v&&(v._any_sub_failure=true,v._applied_status||(v._applied_status=false,v._error_msg=m));}}let a=0,u=0;for(let c of e){if(typeof c!="object"||c===null){u++;continue}c._applied_status&&!c._any_sub_failure?a++:u++;}return [a,u]}_paragraph_has_visible_content(e){for(let n of ["w:t","w:tab","w:br"]){let r=I(e,n);for(let s of r){let i=false,o=s.parentNode;for(;o&&o!==e.parentNode;){if(o.tagName==="w:del"){i=true;break}o=o.parentNode;}if(!i){if(n==="w:t"&&!s.textContent)continue;return true}}}return false}_get_paired_nodes(e){let n=[],r=e.getAttribute("w:author"),s=new Set(["w:commentRangeStart","w:commentRangeEnd","w:commentReference","w:rPr","w:pPr"]),i=new Set,o=y(d=>{let f=d.getAttribute("w:id");f&&i.add(f);},"add_id");o(e);let l=y(d=>{let f=d;for(;f&&f.tagName!=="w:p";)f=f.parentNode;return f},"paragraph_of"),a=y(d=>{let f=M(d,"w:pPr"),h=f?M(f,"w:rPr"):null;return h?M(h,"w:ins"):null},"mark_of"),u=y(d=>{let f=a(d);if(!f||f.getAttribute("w:author")!==r)return false;let h=f.getAttribute("w:id");return h!==null&&i.has(h)},"boundary_is_ours"),c=y((d,f)=>{let h=l(d),p=f==="next"?d.nextSibling:d.previousSibling;for(;;){if(!p){if(!h)break;if(f==="next"){let g=ve(h);for(;g&&g.tagName!=="w:p";)g=ve(g);if(!g||!u(g))break;h=g,p=g.firstChild;}else {if(!u(h))break;let g=Ee(h);for(;g&&g.tagName!=="w:p";)g=Ee(g);if(!g)break;h=g,p=g.lastChild;}continue}if(p.nodeType!==1){p=f==="next"?p.nextSibling:p.previousSibling;continue}let _=p;if(s.has(_.tagName)){p=f==="next"?p.nextSibling:p.previousSibling;continue}if((_.tagName==="w:ins"||_.tagName==="w:del")&&_.getAttribute("w:author")===r){n.push(_),o(_),p=f==="next"?p.nextSibling:p.previousSibling;continue}break}},"walk");return c(e,"next"),c(e,"prev"),n}_resolution_group_ids(e){let n=[...I(this.doc.element,"w:ins"),...I(this.doc.element,"w:del")].filter(s=>s.getAttribute("w:id")===e),r=new Set;if(n.length===0)return I(this.doc.element,"w:pPrChange").some(i=>i.getAttribute("w:id")===e)&&r.add(e),r;r.add(e);for(let s of n)for(let i of this._get_paired_nodes(s)){let o=i.getAttribute("w:id");o&&r.add(o);}return r}validate_action_pairing(e){let n=[],r=new Map;for(let s=0;s<e.length;s++){let i=e[s];if(i.type!=="accept"&&i.type!=="reject")continue;let o=String(i.target_id??"");if(o.startsWith("Com:"))continue;let l=o.startsWith("Chg:")?o.slice(4):o,a=this._resolution_group_ids(l);if(a.size===0)continue;let u=null;for(let c of a){let d=r.get(c);if(d!==void 0&&d[1]!==i.type){u=d;break}}if(u!==null){let[c,d,f]=u;n.push(`- Action ${s+1} Failed: conflicting actions on one replacement \u2014 Action ${c+1} applies '${d}' to Chg:${f}, and Chg:${l} is part of the same change (a replacement's contiguous del+ins pair resolves as one unit, so '${d}' already decides both sides). Accepting one side and rejecting the other is contradictory \u2014 decide the outcome and submit exactly one action for the pair.`);continue}for(let c of a)r.has(c)||r.set(c,[s,i.type,l]);}return n}_buildRevisionIndex(e,n){let r=new Map;for(let u of nr)r.set(u,[]);let i=[this.doc.element],o=[0],l=[],a=[];for(;i.length;){let u=i.length-1,c=i[u].childNodes;if(!c||o[u]>=c.length){for(i.pop(),o.pop();a.length&&a[a.length-1]>i.length;)a.pop(),l.pop();continue}let d=c[o[u]++];if(d.nodeType!==1)continue;let f=r.get(d.tagName),h=null;f&&(h={el:d,id:d.getAttribute("w:id"),nested:[]},f.push(h));let p=d.tagName==="w:ins"||d.tagName==="w:del";if(h&&p)for(let _ of l)_.nested.push(h);i.push(d),o.push(0),h&&p&&(l.push(h),a.push(i.length));}return {doc:e,inc:n,byTag:r}}_getRevisionIndex(){let e=this.doc.element.ownerDocument,n=typeof e?._inc=="number"?e._inc:null,r=this._revisionIndex;if(r&&r.doc===e&&n!==null&&r.inc===n)return r;let s=this._buildRevisionIndex(e,n);return this._revisionIndex=s,s}_revisionsByTag(e){return this._getRevisionIndex().byTag.get(e)??[]}_existing_change_ids(){let e=new Set;for(let n of nr)for(let r of this._revisionsByTag(n))r.id&&e.add(r.id);return Array.from(e).sort((n,r)=>{let s=/^\d+$/.test(n)?parseInt(n,10):0,i=/^\d+$/.test(r)?parseInt(r,10):0;return s-i||n.localeCompare(r)})}_existing_comment_ids(){let e=[];try{e=Object.keys(Xe(this.doc.pkg));}catch{e=[];}return e.sort((n,r)=>{let s=/^\d+$/.test(n)?parseInt(n,10):0,i=/^\d+$/.test(r)?parseInt(r,10):0;return s-i||n.localeCompare(r)})}static _format_id_list(e,n,r=20){let s=e.slice(0,r),i=s.map(o=>`${n}${o}`).join(", ");return e.length>s.length&&(i+=`, \u2026 (+${e.length-s.length} more)`),i}_action_not_found_error(e,n,r="- Failed to apply action:"){let s=this._existing_change_ids(),i=this._existing_comment_ids(),o=e.startsWith("Chg:")||e.startsWith("Com:"),l=e.replace(/^(Chg:|Com:)/,""),a="Call `read_docx` on the document again to list the current change (Chg:) and comment (Com:) ids \u2014 ids shift between document states.";if(n==="reply"){let d=o?e:`Com:${l}`;if(s.includes(l))return `${r} reply on ${d} \u2014 Chg:${l} is a tracked-change id, not a comment. \`reply\` adds to an existing comment thread (Com:\u2026); to comment on a change instead, apply a modify with a \`comment\`. ${a}`;let f=i.length>0?`Comment ids in this document: ${V._format_id_list(i,"Com:")}. `:"This document has no comments to reply to. ";return `${r} reply on ${d} \u2014 no comment with that id exists. ${f}${a}`}let u=o?e:`Chg:${l}`;if(i.includes(l))return `${r} ${n} on ${u} \u2014 Com:${l} is a comment id, not a tracked change. accept/reject act on tracked changes (Chg:\u2026); to respond to a comment use \`reply\`. ${a}`;let c=s.length>0?`Tracked-change ids in this document: ${V._format_id_list(s,"Chg:")}. `:"This document has no tracked changes. ";return `${r} ${n} on ${u} \u2014 no tracked change with that id exists (it may already have been accepted or rejected, or the id is stale). ${c}${a}`}apply_review_actions(e){let n=0,r=0,s=0,i=new Map,o=e.map((l,a)=>({action:l,pos:a})).sort((l,a)=>{let u=l.action.type==="reply"?0:1,c=a.action.type==="reply"?0:1;return u!==c?u-c:l.pos-a.pos});for(let{action:l,pos:a}of o){let u=l.type;if(u==="reply"){let x=l.target_id.replace("Com:",""),E=this.comments_manager.addComment(this.author,l.text,x);this._anchor_reply_comment(x,E),n++;continue}let c=l.target_id.replace("Chg:",""),d=i.get(c);if(d!==void 0){if(d===u){s++,this.skipped_details.push(`- Note: Action ${a+1} ('${u}' on ${l.target_id}) had no additional effect \u2014 the change was already resolved together with its replacement pair by an earlier action in this batch. Counted as already_resolved, not applied.`);continue}this.skipped_details.push(`- Action ${a+1} Failed: contradictory action \u2014 '${u}' on ${l.target_id}, but the change was already resolved as '${d}' together with its replacement pair by an earlier action in this batch.`),r++;continue}let f=this._revisionsByTag("w:ins").filter(x=>x.id===c).map(x=>x.el),h=this._revisionsByTag("w:del").filter(x=>x.id===c).map(x=>x.el),p=[...f,...h],_=en.flatMap(x=>this._revisionsByTag(x).filter(E=>E.id===c).map(E=>E.el));if(p.length===0&&_.length===0){r++,this.skipped_details.push(this._action_not_found_error(l.target_id,u));continue}let g=Array.from(new Set([...p,..._].map(x=>x.getAttribute("w:author")||"Unknown"))).sort();if(g.length>1){r++,this.skipped_details.push(`- Failed to apply action: ${u} on Chg:${c} is ambiguous. The document contains ${p.length} tracked-change elements sharing w:id=${c} from different authors (${g.join(", ")}) \u2014 duplicate revision IDs produced outside this engine (e.g. by a document merge or copy-paste). Acting on this ID would resolve all of them at once. Resolve these changes individually in Word, or apply the intended outcome as an explicit text edit instead.`);continue}let w=new Set([c]);for(let x of p)for(let E of this._get_paired_nodes(x)){let T=E.getAttribute("w:id");T&&w.add(T);}let k=Kt.flatMap(x=>this._revisionsByTag(x)),b=-1;for(;b!==w.size;){b=w.size;for(let x of k)if(!(!x.id||!w.has(x.id)))for(let E of x.nested)E.id&&w.add(E.id);}let m=[];for(let x of Kt)for(let E of this._revisionsByTag(x))E.id&&w.has(E.id)&&m.push(E.el);let v=en.flatMap(x=>this._revisionsByTag(x).filter(E=>E.id!==null&&w.has(E.id)).map(E=>E.el)),N=new Set;for(let x of [...m,...v]){let E=x.getAttribute("w:id");E&&N.add(E);}let A=new Set(this._existing_comment_ids()),C=[];for(let x of m){let E=x.tagName==="w:ins",T=x.parentNode?x.parentNode.tagName:"",D=T==="w:trPr",P=E&&T==="w:rPr"&&!!x.parentNode?.parentNode&&x.parentNode.parentNode.tagName==="w:pPr";if(u==="accept")if(E)if(D)x.parentNode?.removeChild(x);else {for(;x.firstChild;)x.parentNode?.insertBefore(x.firstChild,x);x.parentNode?.removeChild(x);}else if(this._clean_wrapping_comments(x),this._delete_comments_in_element(x),D){let R=x.parentNode?.parentNode;R?.parentNode?.removeChild(R);}else x.parentNode?.removeChild(x);else if(u==="reject")if(E){if(P){let R=x.parentNode;x.parentNode?.removeChild(x),R=R?.parentNode,R=R?.parentNode,R&&R.tagName==="w:p"&&C.push(R);continue}if(this._clean_wrapping_comments(x),this._delete_comments_in_element(x),D){let R=x.parentNode?.parentNode;R?.parentNode?.removeChild(R);}else x.parentNode?.removeChild(x);}else if(D)x.parentNode?.removeChild(x);else {let R=Array.from(x.getElementsByTagName("w:delText"));for(let $ of R){let S=$.ownerDocument.createElement("w:t");S.textContent=$.textContent,$.hasAttribute("xml:space")&&S.setAttribute("xml:space","preserve"),$.parentNode?.replaceChild(S,$);}for(;x.firstChild;)x.parentNode?.insertBefore(x.firstChild,x);x.parentNode?.removeChild(x);}}for(let x of C.reverse()){if(!x.parentNode)continue;let E=Ee(x);for(;E&&E.tagName!=="w:p";)E=Ee(E);if(E){for(let T of Array.from(x.childNodes))T.nodeType===1&&T.tagName==="w:pPr"||E.appendChild(T);x.parentNode.removeChild(x);}}for(let x of v)u==="accept"?x.parentNode?.removeChild(x):x.tagName==="w:pPrChange"?this._revert_ppr_change(x):this._revert_props_change(x);for(let x of N)i.set(x,u);if(n++,A.size>0){let x=new Set(this._existing_comment_ids()),E=Array.from(A).filter(T=>!x.has(T));if(E.length>0){let T=E.sort((D,P)=>{let R=/^\d+$/.test(D)?parseInt(D,10):0,$=/^\d+$/.test(P)?parseInt(P,10):0;return R-$||D.localeCompare(P)}).map(D=>`Com:${D}`).join(", ");this.skipped_details.push(`- Note: ${u} on ${l.target_id} also removed comment ${T} (including any reply thread) because its anchor was inside the resolved change. This note is informational \u2014 the action itself succeeded.`);}}}return [n,r,s]}_apply_table_edit(e,n){let r=e._resolved_start_idx!==void 0&&e._resolved_start_idx!==null?e._resolved_start_idx:e._match_start_index||0,s=e._active_mapper_ref||this.mapper,[i,o]=s.get_insertion_anchor(r,n),l=null;if(i?l=i._element:o&&(l=o._element),!l)return false;let a=l;for(;a&&a.tagName!=="w:tr";)a=a.parentNode;if(!a)return false;let u=(e._reserved_row_id??null)!==null?String(e._reserved_row_id):null;if(e.type==="delete_row"){let c=M(a,"w:trPr");return c||(c=a.ownerDocument.createElement("w:trPr"),a.insertBefore(c,a.firstChild)),c.appendChild(this._create_track_change_tag("w:del","",u)),true}else if(e.type==="insert_row"){let c=a.ownerDocument.createElement("w:tr"),d=a.ownerDocument.createElement("w:trPr");c.appendChild(d),d.appendChild(this._create_track_change_tag("w:ins","",u));let f=I(a,"w:tc").filter(p=>p.parentNode===a).length,h=Array.isArray(e.cells)?[...e.cells]:[];if(f>0){for(;h.length<f;)h.push("");h=h.slice(0,f);}for(let p of h){let _=a.ownerDocument.createElement("w:tc"),g=a.ownerDocument.createElement("w:p"),w=a.ownerDocument.createElement("w:r"),k=a.ownerDocument.createElement("w:t");k.textContent=p,p.trim()!==p&&k.setAttribute("xml:space","preserve"),w.appendChild(k),g.appendChild(w),_.appendChild(g),c.appendChild(_);}return e.position==="above"?a.parentNode?.insertBefore(c,a):Le(c,a),true}return false}_pre_resolve_heuristic_edit(e){if(!e.target_text)return null;let n=e.regex||false,r=e.match_mode||"strict",s=this.mapper.drop_virtual_only_matches(this.mapper.find_all_match_indices(e.target_text,n)),i=false;if(s.length===0)if(this.clean_mapper||(this.clean_mapper=new ke(this.doc,true)),s=this.clean_mapper.drop_virtual_only_matches(this.clean_mapper.find_all_match_indices(e.target_text,n)),s.length>0)i=true;else return null;let o=i?this.clean_mapper:this.mapper,l=[];for(let[u,c]of s){let d=o.spans.filter(f=>f.run!==null&&f.end>u&&f.start<u+c);(d.length===0||d.some(f=>!f.del_id))&&l.push([u,c]);}if(l.length===0)return null;(r==="strict"||r==="first")&&(l=l.slice(0,1));let a=[];for(let[u,c]of l){let d=o.full_text.substring(u,u+c),f=e.new_text||"";if(/^\{#cell:[^}]+\}$/.test(d.trim())){let E=f;E=E.split(d.trim()).join("");let T=o.spans.find(D=>D.start<=u&&u<D.end&&D.paragraph!==null);if(T&&E){let D=o.spans.filter(P=>P.end<=u&&P.run!==null&&P.paragraph!==null&&P.paragraph._element===T.paragraph._element).map(P=>P.text).join("");if(D){for(let P of [D,D.replace(/\s+$/,"")])if(P&&E.startsWith(P)){E=E.substring(P.length).replace(/^\s+/,"");break}E&&!/\s$/.test(D)&&!/^\s/.test(E)&&(E=" "+E);}}E?a.push({type:"modify",target_text:"",new_text:E,comment:e.comment,_match_start_index:u,_internal_op:"INSERTION",_active_mapper_ref:o}):e.comment&&a.push({type:"modify",target_text:"",new_text:"",comment:e.comment,_match_start_index:u,_internal_op:"COMMENT_ONLY",_active_mapper_ref:o});continue}if(n&&f){try{f=d.replace(new RegExp(e.target_text),f);}catch{}V._flag_surviving_python_backreference(e,f);}e._preview_span||(e._preview_span=[u,c],e._preview_matched_text=d,e._preview_new_text=f,e._preview_mapper_ref=o);let[h,p]=this._parse_markdown_style(e.target_text),[_,g]=this._parse_markdown_style(f);if(p!==g){let[E]=this._parse_markdown_style(d),T=E,D=_,P=T===D?"STYLE_ONLY":"STYLE_AND_TEXT",R=d.indexOf(E),$=u+(R!==-1?R:0),S=g!==null?g:"Normal";a.push({type:"modify",target_text:T,new_text:D,comment:e.comment,_match_start_index:$,_internal_op:P,_new_style:S,_active_mapper_ref:o});continue}if(d===f||e.target_text===f){a.push({type:"modify",target_text:d,new_text:d,comment:e.comment,_match_start_index:u,_internal_op:"COMMENT_ONLY",_active_mapper_ref:o});continue}let w=false;if(o&&(w=o.spans.some(E=>E.text===" | "&&(E.run===null||E.run===void 0)&&E.start<u+c&&E.end>u)),w){let E=d.split("|"),T=f.split("|");if(E.length!==T.length)throw new pt([`Target text spans ${E.length} table cells, but replacement provides ${T.length}. To modify text without altering table structure (rows or columns), ensure the replacement contains the exact same number of '|' separators (e.g., replace with 'CellC | ' to empty the second cell).`]);if(E.length>1){let D=[],P=0,R=0;for(let $=0;$<E.length;$++)if(E[$].trim()!==T[$].trim()){R=$;break}for(let $=0;$<E.length;$++){let S=E[$],j=T[$],F=S.trim(),B=j.trim(),L=u+P+(F?S.indexOf(F):0),U=e.comment!==null&&e.comment!==void 0&&$===R;if(F!==B||U){let Y=this._word_diff_sub_edits(F,B,L,U?e.comment:null,true,o);for(let X of Y)X._original_target_text=e.target_text,X._split_group_id=u,D.push(X);}P+=S.length+1;}for(let $ of D)a.push($);continue}}let k=false;e.target_text&&(e.target_text.includes("**")||e.target_text.includes("_"))&&(k=true),f&&(f.includes("**")||f.includes("_"))&&(k=true);let b="",m="",v="",N=u;if(f.startsWith(d))b="INSERTION",v=f.substring(d.length),N=u+c;else {let[E,T]=Ue(d,f),D=d.length-T,P=f.length-T;m=d.substring(E,D),v=f.substring(E,P),N=u+E;}if(k){if(!m&&v)b="INSERTION";else if(m&&!v)b="DELETION";else if(m&&v)b="MODIFICATION";else {a.push({type:"modify",target_text:m,new_text:v,comment:e.comment,_match_start_index:N,_internal_op:"COMMENT_ONLY",_active_mapper_ref:o});continue}a.push({type:"modify",target_text:m,new_text:v,comment:e.comment,_resolved_start_idx:N,_match_start_index:N,_internal_op:b,_active_mapper_ref:o});continue}let A=d.split(`
113
+ `).filter(l=>l.includes(" | ")).length,a=s.split(`
114
+ `).filter(l=>l.includes(" | ")).length;return o<=a?false:V._column_count_at(e,n,Math.max(r,1))!==null}static _column_count_at(e,n,r){for(let s of e.spans){if(s.end<=n||s.start>=n+r)continue;let i=null;for(s.run!==null?i=s.run._element:s.paragraph!==null&&(i=s.paragraph._element);i;){if(i.nodeType===1&&i.tagName==="w:tr")return $(i,"w:tc").filter(o=>o.parentNode===i).length;i=i.parentNode;}}return null}validate_review_actions(e){let n=[],r=new Map,s=new Set;for(let i=0;i<e.length;i++){let o=e[i],a=o.type,l=o.target_id??"";if(a==="reply"){if(!String(o.text??"").trim()){n.push(`- Action ${i+1} Failed: reply text for ${l} is empty or whitespace-only. Word would show a blank comment bubble \u2014 provide the reply content in 'text'.`);continue}let u=l+"\0"+String(o.text).trim();s.has(u)&&n.push(`- Action ${i+1} Failed: duplicate reply \u2014 this batch already replies to ${l} with the same text. Remove the duplicate action.`),s.add(u);}else if(a==="accept"||a==="reject"){let u=r.get(l);if(u!==void 0){let[c,d]=u;d===a?n.push(`- Action ${i+1} Failed: duplicate action \u2014 Action ${c+1} in this batch already applies '${a}' to ${l}. A change can only be resolved once; remove the duplicate action.`):n.push(`- Action ${i+1} Failed: conflicting actions \u2014 Action ${c+1} in this batch applies '${d}' to ${l}, but this action applies '${a}'. Decide the outcome and keep exactly one of them.`);}else r.set(l,[i,a]);}}if(n.length>0)return n;for(let i=0;i<e.length;i++){let o=e[i],a=o.type;if(a==="reply"){let l=o.target_id.replace("Com:",""),u=false,c=this.doc.pkg.parts.find(d=>d.contentType==="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml");c&&(u=$(c._element,"w:comment").some(f=>f.getAttribute("w:id")===l)),u||n.push(this._action_not_found_error(o.target_id,"reply",`- Action ${i+1} Failed:`));}else if(a==="accept"||a==="reject"){let l=o.target_id.replace("Chg:",""),u=$(this.doc.element,"w:ins").filter(f=>f.getAttribute("w:id")===l),c=$(this.doc.element,"w:del").filter(f=>f.getAttribute("w:id")===l),d=$(this.doc.element,"w:pPrChange").filter(f=>f.getAttribute("w:id")===l);u.length===0&&c.length===0&&d.length===0&&n.push(this._action_not_found_error(o.target_id,a,`- Action ${i+1} Failed:`));}}return n}process_batch(e){return Array.isArray(e)&&(e=e.map(n=>{if(typeof n=="string")try{let r=JSON.parse(n);return r!==null&&typeof r=="object"?r:n}catch{return n}return n})),this._process_batch_internal(e)}_process_batch_internal(e){for(let w of e)if(w&&typeof w=="object"&&w.type==="modify"&&w.target_text&&w.new_text){let[k,b]=Io(w.target_text,w.new_text);w.target_text=k,w.new_text=b;}this.skipped_details=[];let n=e.filter(w=>w!==null&&typeof w=="object"&&["accept","reject","reply"].includes(w.type)),r=e.filter(w=>w===null||typeof w!="object"||!["accept","reject","reply"].includes(w.type)),s=n.length>0?this.validate_review_actions(n):[];n.length>0&&s.length===0&&(s=this.validate_action_pairing(n));let o=r.length>0&&s.length>0?this.validate_edits(r):[],a=[...s,...o];if(a.length>0)throw new pt(a);let l=0,u=0,c=0;if(n.length>0){let w=this.apply_review_actions(n);if(l=w[0],u=w[1],c=w[2],u>0)throw new pt(this.skipped_details);l>0&&(this.mapper._build_map(),this.clean_mapper&&this.clean_mapper._build_map());}let[d]=He(this.mapper.full_text),h=Xe(d,"").body_page_offsets,_=[],p=0,m=0;if(r.length>0){let w=y(b=>b._resolved_start_idx!==void 0&&b._resolved_start_idx!==null?b._resolved_start_idx:b._match_start_index!==void 0&&b._match_start_index!==null?b._match_start_index:null,"pinned_idx"),k=r.map((b,g)=>({edit:b,i:g})).sort((b,g)=>{let v=w(b.edit),x=w(g.edit);return v===null&&x===null?b.i-g.i:v===null?1:x===null?-1:x-v||b.i-g.i});{let b=To(this.doc),g=this.current_id;try{let v=[],x=0;for(let{edit:E,i:C}of k){let A;try{A=this.validate_edits([E],C);}catch(N){if(!(N instanceof Ce))throw N;A=[`- Edit ${C+1} Failed: ${N.message}`];}if(A.length>0){if(x>0){let N=rr(x);A=A.map(P=>P+N);}v.push(...A);}else if(this.apply_edits([E],h),E._applied_status&&!E._any_sub_failure)x++,this.mapper=new ke(this.doc),this.clean_mapper=null;else {let N=E._error_msg||`- Edit ${C+1} Failed: Failed to apply edit.`;x>0&&(N+=rr(x)),v.push(N);break}}if(v.length>0)throw new pt(v)}catch(v){throw So(this.doc,b),this.current_id=g,this.mapper=new ke(this.doc),this.comments_manager=new nt(this.doc),this.clean_mapper=null,v}p=r.filter(v=>v._applied_status&&!v._any_sub_failure).length,m=r.length-p;for(let v of r){let x=v._applied_status||false,E=v._error_msg||null,C=null,A=null,N=v._warning||null;if(x){let P=this._build_edit_context_previews(v);C=P[0],A=P[1];}else N=N||this._check_punctuation_warning(v.target_text||"");_.push({status:x?"applied":"failed",type:v.type||"modify",target_text:he(v.target_text||"",qt),new_text:he(V._report_new_text(v),qt),comment:v.comment??null,warning:N,error:E,critic_markup:C,clean_text:A,pages:v._pages||[],heading_path:v._heading_path||"",occurrences_modified:v._occurrences_modified||0,match_mode:v.match_mode||"strict"});}}}return {actions_applied:l,actions_skipped:u,actions_already_resolved:c,edits_applied:p,edits_skipped:m,occurrences_modified:_.reduce((w,k)=>w+(k.occurrences_modified||0),0),skipped_details:this.skipped_details,edits:_,engine:"node",version:"1.18.2"}}static _flag_surviving_python_backreference(e,n){let r=/\\(\d+)|\\g<(\d+)>/.exec(e.new_text||"");if(!r||!n.includes(r[0]))return;let s=0;try{let o=new RegExp(`(?:${e.target_text})|`).exec("");s=o?o.length-1:0;}catch{return}let i=parseInt(r[1]??r[2],10);i>0&&i<=s&&(e._warning=`new_text contains '${r[0]}', which JavaScript's replace does not expand \u2014 the literal text '${r[0]}' was written into the document. For a capture-group backreference use $${i} (\\N and \\g<N> are Python syntax). If you meant literal text, ignore this warning.`);}static _ids_needed(e){let n=e._internal_op;return n==null&&(!e.target_text&&e.new_text?n="INSERTION":e.target_text&&!e.new_text?n="DELETION":n="MODIFICATION"),n==="STYLE_ONLY"?[false,false]:(n==="STYLE_AND_TEXT"&&(e.target_text&&e.new_text?n="MODIFICATION":!e.target_text&&e.new_text?n="INSERTION":e.target_text&&!e.new_text?n="DELETION":n="COMMENT_ONLY"),[n==="DELETION"||n==="MODIFICATION",n==="INSERTION"||n==="MODIFICATION"])}apply_edits(e,n=[]){if(!n||n.length===0){let[c]=He(this.mapper.full_text);n=Xe(c,"").body_page_offsets;}let i=[];for(let c of e){if(typeof c!="object"||c===null){continue}c._applied_status=false,c._error_msg=null,c._any_sub_failure=false,c._minted_change_ids=[],c._minted_comment_ids=[],c._reserved_del_id=null,c._reserved_ins_id=null,c._reserved_row_id=null;}for(let c of e)if(!(typeof c!="object"||c===null))if(c._resolved_start_idx!==void 0&&c._resolved_start_idx!==null||c._match_start_index!==void 0&&c._match_start_index!==null)(c._resolved_start_idx===void 0||c._resolved_start_idx===null)&&(c._resolved_start_idx=c._match_start_index),c._active_mapper_ref||(this.clean_mapper||(this.clean_mapper=new ke(this.doc,true)),c._active_mapper_ref=this.clean_mapper),i.push([c,c.new_text||null]);else if(c.type==="insert_row"||c.type==="delete_row"){let d=this.mapper.drop_virtual_only_matches(this.mapper.find_all_match_indices(c.target_text)),f=this.mapper;if(d.length===0&&(this.clean_mapper||(this.clean_mapper=new ke(this.doc,true)),d=this.clean_mapper.drop_virtual_only_matches(this.clean_mapper.find_all_match_indices(c.target_text)),f=this.clean_mapper),d.length>0){let h=c.match_mode||"strict",_=[],p=new Set;for(let m of d){let w=m[0],[k,b]=f.get_insertion_anchor(w,false),g=null;k?g=k._element:b&&(g=b._element);let v=g;for(;v&&v.tagName!=="w:tr";)v=v.parentNode;v&&(p.has(v)||(p.add(v),_.push(m)));}if(_.length>0){let m=_;if((h==="strict"||h==="first")&&(m=_.slice(0,1)),h==="all"||m.length>1)for(let w of m){let k={...c,_resolved_start_idx:w[0],_active_mapper_ref:f,_parent_edit_ref:c};i.push([k,null]);}else c._resolved_start_idx=m[0][0],c._active_mapper_ref=f,i.push([c,null]);}else {c._applied_status=false;let w=`- Failed to locate row target: '${(c.target_text||"").trim().substring(0,40)}...'`;this.skipped_details.push(w),c._error_msg=w;}}else {c._applied_status=false;let _=`- Failed to locate row target: '${(c.target_text||"").trim().substring(0,40)}...'`;this.skipped_details.push(_),c._error_msg=_;}}else {let d;try{d=this._pre_resolve_heuristic_edit(c);}catch(f){if(!(f instanceof Ce))throw f;c._applied_status=false;let h=`- Failed to apply edit targeting: '${(c.target_text||"").substring(0,40)}...' (${f.message})`;this.skipped_details.push(h),c._error_msg=h;continue}if(d)if(Array.isArray(d))for(let f of d)f._resolved_start_idx=f._match_start_index,f._parent_edit_ref=c,(c._resolved_start_idx===void 0||c._resolved_start_idx===null)&&(c._resolved_start_idx=f._resolved_start_idx),c._resolved_proxy_edit||(c._resolved_proxy_edit=f),i.push([f,f.new_text]);else d._resolved_start_idx=d._match_start_index,d._parent_edit_ref=c,c._resolved_start_idx=d._resolved_start_idx,c._resolved_proxy_edit=d,i.push([d,d.new_text]);else {c._applied_status=false;let _=`- Failed to apply edit targeting: '${(c.target_text||"insertion").trim().substring(0,40)}...'`;this.skipped_details.push(_),c._error_msg=_;}}i.sort((c,d)=>(d[0]._resolved_start_idx||0)-(c[0]._resolved_start_idx||0));{let c=[...i].sort((d,f)=>(d[0]._resolved_start_idx||0)-(f[0]._resolved_start_idx||0));for(let[d]of c){let f=d._parent_edit_ref||d;if(Array.isArray(f._minted_change_ids)||(f._minted_change_ids=[]),d.type==="insert_row"||d.type==="delete_row"){d._reserved_row_id==null&&(d._reserved_row_id=this._getNextId(),f._minted_change_ids.push(d._reserved_row_id));continue}if(d.type!=="modify")continue;let[h,_]=V._ids_needed(d);h&&d._reserved_del_id==null&&(d._reserved_del_id=this._getNextId(),f._minted_change_ids.push(d._reserved_del_id)),_&&d._reserved_ins_id==null&&(d._reserved_ins_id=this._getNextId(),f._minted_change_ids.push(d._reserved_ins_id));}}for(let[c]of i)this._capture_preview_context(c),c._parent_edit_ref&&this._capture_parent_preview_context(c._parent_edit_ref);let o=[],a=new Set;for(let[c,d]of i){let f=c._resolved_start_idx||0,h=c.type==="insert_row"?f:f+(c.target_text?c.target_text.length:0);if(o.some(([k,b])=>f<b&&h>k)){let g=`- Skipped overlapping edit targeting: '${(c.target_text||"insertion").trim().substring(0,40)}...'`;this.skipped_details.push(g),c._applied_status=false,c._error_msg=g,c._any_sub_failure=true;let v=c._parent_edit_ref;v&&(v._applied_status=false,v._error_msg=g,v._any_sub_failure=true);continue}let p=false,m=this.current_id,w=this.comments_manager.nextId;if(c.type==="modify"?p=this._apply_single_edit_indexed(c,d,false):(c.type==="insert_row"||c.type==="delete_row")&&(p=this._apply_table_edit(c,false)),p){let k=c._parent_edit_ref||c;Array.isArray(k._minted_change_ids)||(k._minted_change_ids=[]);for(let b=m+1;b<=this.current_id;b++)k._minted_change_ids.push(String(b));Array.isArray(k._minted_comment_ids)||(k._minted_comment_ids=[]);for(let b=w;b<this.comments_manager.nextId;b++)k._minted_comment_ids.push(String(b));}if(p){let k=c._split_group_id,b=k==null||!a.has(k);b&&k!==void 0&&k!==null&&a.add(k),o.push([f,h]),c._applied_status=true;let g=c._parent_edit_ref;if(g){g._applied_status=true,b&&(g._occurrences_modified=(g._occurrences_modified||0)+1);let[v,x]=this._get_heading_path_and_page(f,this.mapper.full_text,n),E=g._pages||[];E.includes(x)||E.unshift(x),g._pages=E,g._heading_path=v;}else {b&&(c._occurrences_modified=(c._occurrences_modified||0)+1);let[v,x]=this._get_heading_path_and_page(f,this.mapper.full_text,n),E=c._pages||[];E.includes(x)||E.unshift(x),c._pages=E,c._heading_path=v;}}else {let g=`- Failed to apply edit targeting: '${(c.target_text||"insertion").trim().substring(0,40)}...'`;this.skipped_details.push(g),c._applied_status=false,c._error_msg=g,c._any_sub_failure=true;let v=c._parent_edit_ref;v&&(v._any_sub_failure=true,v._applied_status||(v._applied_status=false,v._error_msg=g));}}let l=0,u=0;for(let c of e){if(typeof c!="object"||c===null){u++;continue}c._applied_status&&!c._any_sub_failure?l++:u++;}return [l,u]}_paragraph_has_visible_content(e){for(let n of ["w:t","w:tab","w:br"]){let r=$(e,n);for(let s of r){let i=false,o=s.parentNode;for(;o&&o!==e.parentNode;){if(o.tagName==="w:del"){i=true;break}o=o.parentNode;}if(!i){if(n==="w:t"&&!s.textContent)continue;return true}}}return false}_is_last_paragraph_in_cell(e){let n=e.parentNode;for(;n&&n.tagName!=="w:tc";)n=n.parentNode;return n?$(n,"w:p").length<=1:false}_get_paired_nodes(e){let n=[],r=e.getAttribute("w:author"),s=new Set(["w:commentRangeStart","w:commentRangeEnd","w:commentReference","w:rPr","w:pPr"]),i=new Set,o=y(d=>{let f=d.getAttribute("w:id");f&&i.add(f);},"add_id");o(e);let a=y(d=>{let f=d;for(;f&&f.tagName!=="w:p";)f=f.parentNode;return f},"paragraph_of"),l=y(d=>{let f=M(d,"w:pPr"),h=f?M(f,"w:rPr"):null;return h?M(h,"w:ins"):null},"mark_of"),u=y(d=>{let f=l(d);if(!f||f.getAttribute("w:author")!==r)return false;let h=f.getAttribute("w:id");return h!==null&&i.has(h)},"boundary_is_ours"),c=y((d,f)=>{let h=a(d),_=f==="next"?d.nextSibling:d.previousSibling;for(;;){if(!_){if(!h)break;if(f==="next"){let m=ve(h);for(;m&&m.tagName!=="w:p";)m=ve(m);if(!m||!u(m))break;h=m,_=m.firstChild;}else {if(!u(h))break;let m=Ee(h);for(;m&&m.tagName!=="w:p";)m=Ee(m);if(!m)break;h=m,_=m.lastChild;}continue}if(_.nodeType!==1){_=f==="next"?_.nextSibling:_.previousSibling;continue}let p=_;if(s.has(p.tagName)){_=f==="next"?_.nextSibling:_.previousSibling;continue}if((p.tagName==="w:ins"||p.tagName==="w:del")&&p.getAttribute("w:author")===r){n.push(p),o(p),_=f==="next"?_.nextSibling:_.previousSibling;continue}break}},"walk");return c(e,"next"),c(e,"prev"),n}_resolution_group_ids(e){let n=[...$(this.doc.element,"w:ins"),...$(this.doc.element,"w:del")].filter(s=>s.getAttribute("w:id")===e),r=new Set;if(n.length===0)return $(this.doc.element,"w:pPrChange").some(i=>i.getAttribute("w:id")===e)&&r.add(e),r;r.add(e);for(let s of n)for(let i of this._get_paired_nodes(s)){let o=i.getAttribute("w:id");o&&r.add(o);}return r}validate_action_pairing(e){let n=[],r=new Map;for(let s=0;s<e.length;s++){let i=e[s];if(i.type!=="accept"&&i.type!=="reject")continue;let o=String(i.target_id??"");if(o.startsWith("Com:"))continue;let a=o.startsWith("Chg:")?o.slice(4):o,l=this._resolution_group_ids(a);if(l.size===0)continue;let u=null;for(let c of l){let d=r.get(c);if(d!==void 0&&d[1]!==i.type){u=d;break}}if(u!==null){let[c,d,f]=u;n.push(`- Action ${s+1} Failed: conflicting actions on one replacement \u2014 Action ${c+1} applies '${d}' to Chg:${f}, and Chg:${a} is part of the same change (a replacement's contiguous del+ins pair resolves as one unit, so '${d}' already decides both sides). Accepting one side and rejecting the other is contradictory \u2014 decide the outcome and submit exactly one action for the pair.`);continue}for(let c of l)r.has(c)||r.set(c,[s,i.type,a]);}return n}_buildRevisionIndex(e,n){let r=new Map;for(let u of ir)r.set(u,[]);let i=[this.doc.element],o=[0],a=[],l=[];for(;i.length;){let u=i.length-1,c=i[u].childNodes;if(!c||o[u]>=c.length){for(i.pop(),o.pop();l.length&&l[l.length-1]>i.length;)l.pop(),a.pop();continue}let d=c[o[u]++];if(d.nodeType!==1)continue;let f=r.get(d.tagName),h=null;f&&(h={el:d,id:d.getAttribute("w:id"),nested:[]},f.push(h));let _=d.tagName==="w:ins"||d.tagName==="w:del";if(h&&_)for(let p of a)p.nested.push(h);i.push(d),o.push(0),h&&_&&(a.push(h),l.push(i.length));}return {doc:e,inc:n,byTag:r}}_getRevisionIndex(){let e=this.doc.element.ownerDocument,n=typeof e?._inc=="number"?e._inc:null,r=this._revisionIndex;if(r&&r.doc===e&&n!==null&&r.inc===n)return r;let s=this._buildRevisionIndex(e,n);return this._revisionIndex=s,s}_revisionsByTag(e){return this._getRevisionIndex().byTag.get(e)??[]}_existing_change_ids(){let e=new Set;for(let n of ir)for(let r of this._revisionsByTag(n))r.id&&e.add(r.id);return Array.from(e).sort((n,r)=>{let s=/^\d+$/.test(n)?parseInt(n,10):0,i=/^\d+$/.test(r)?parseInt(r,10):0;return s-i||n.localeCompare(r)})}_existing_comment_ids(){let e=[];try{e=Object.keys(Re(this.doc.pkg));}catch{e=[];}return e.sort((n,r)=>{let s=/^\d+$/.test(n)?parseInt(n,10):0,i=/^\d+$/.test(r)?parseInt(r,10):0;return s-i||n.localeCompare(r)})}_comment_authors(){let e={};try{for(let[n,r]of Object.entries(Re(this.doc.pkg)))e[n]=r?.author||"Unknown";}catch{}return e}static _describe_removed_comments(e,n){let r=[...e].sort((i,o)=>{let a=/^\d+$/.test(i)?parseInt(i,10):0,l=/^\d+$/.test(o)?parseInt(o,10):0;return a-l||i.localeCompare(o)}),s=r.map(i=>n[i]?`Com:${i} (by ${n[i]})`:`Com:${i}`).join(", ");return `${r.length===1?"comment":"comments"} ${s}`}static _format_id_list(e,n,r=20){let s=e.slice(0,r),i=s.map(o=>`${n}${o}`).join(", ");return e.length>s.length&&(i+=`, \u2026 (+${e.length-s.length} more)`),i}_action_not_found_error(e,n,r="- Failed to apply action:"){let s=this._existing_change_ids(),i=this._existing_comment_ids(),o=e.startsWith("Chg:")||e.startsWith("Com:"),a=e.replace(/^(Chg:|Com:)/,""),l="Call `read_docx` on the document again to list the current change (Chg:) and comment (Com:) ids \u2014 ids shift between document states.";if(n==="reply"){let d=o?e:`Com:${a}`;if(s.includes(a))return `${r} reply on ${d} \u2014 Chg:${a} is a tracked-change id, not a comment. \`reply\` adds to an existing comment thread (Com:\u2026); to comment on a change instead, apply a modify with a \`comment\`. ${l}`;let f=i.length>0?`Comment ids in this document: ${V._format_id_list(i,"Com:")}. `:"This document has no comments to reply to. ";return `${r} reply on ${d} \u2014 no comment with that id exists. ${f}${l}`}let u=o?e:`Chg:${a}`;if(i.includes(a))return `${r} ${n} on ${u} \u2014 Com:${a} is a comment id, not a tracked change. accept/reject act on tracked changes (Chg:\u2026); to respond to a comment use \`reply\`. ${l}`;let c=s.length>0?`Tracked-change ids in this document: ${V._format_id_list(s,"Chg:")}. `:"This document has no tracked changes. ";return `${r} ${n} on ${u} \u2014 no tracked change with that id exists (it may already have been accepted or rejected, or the id is stale). ${c}${l}`}apply_review_actions(e){let n=0,r=0,s=0,i=new Map,o=e.map((a,l)=>({action:a,pos:l})).sort((a,l)=>{let u=a.action.type==="reply"?0:1,c=l.action.type==="reply"?0:1;return u!==c?u-c:a.pos-l.pos});for(let{action:a,pos:l}of o){let u=a.type;if(u==="reply"){let N=a.target_id.replace("Com:","");if(!this._existing_comment_ids().includes(N)){r++,this.skipped_details.push(this._action_not_found_error(a.target_id,"reply",`- Action ${l+1} Failed:`));continue}let P;try{P=this.comments_manager.addComment(this.author,a.text,N);}catch(D){if(D instanceof Er){r++,this.skipped_details.push(`- Action ${l+1} Failed: reply on ${a.target_id} \u2014 ${D.message}`);continue}throw D}this._anchor_reply_comment(N,P),n++;continue}let c=a.target_id.replace("Chg:",""),d=i.get(c);if(d!==void 0){if(d===u){s++,this.skipped_details.push(`- Note: Action ${l+1} ('${u}' on ${a.target_id}) had no additional effect \u2014 the change was already resolved together with its replacement pair by an earlier action in this batch. Counted as already_resolved, not applied.`);continue}this.skipped_details.push(`- Action ${l+1} Failed: contradictory action \u2014 '${u}' on ${a.target_id}, but the change was already resolved as '${d}' together with its replacement pair by an earlier action in this batch.`),r++;continue}let f=this._revisionsByTag("w:ins").filter(N=>N.id===c).map(N=>N.el),h=this._revisionsByTag("w:del").filter(N=>N.id===c).map(N=>N.el),_=[...f,...h],p=rn.flatMap(N=>this._revisionsByTag(N).filter(P=>P.id===c).map(P=>P.el));if(_.length===0&&p.length===0){r++,this.skipped_details.push(this._action_not_found_error(a.target_id,u));continue}let m=Array.from(new Set([..._,...p].map(N=>N.getAttribute("w:author")||"Unknown"))).sort();if(m.length>1){r++,this.skipped_details.push(`- Failed to apply action: ${u} on Chg:${c} is ambiguous. The document contains ${_.length} tracked-change elements sharing w:id=${c} from different authors (${m.join(", ")}) \u2014 duplicate revision IDs produced outside this engine (e.g. by a document merge or copy-paste). Acting on this ID would resolve all of them at once. Resolve these changes individually in Word, or apply the intended outcome as an explicit text edit instead.`);continue}let w=new Set([c]);for(let N of _)for(let P of this._get_paired_nodes(N)){let D=P.getAttribute("w:id");D&&w.add(D);}let k=nn.flatMap(N=>this._revisionsByTag(N)),b=-1;for(;b!==w.size;){b=w.size;for(let N of k)if(!(!N.id||!w.has(N.id)))for(let P of N.nested)P.id&&w.add(P.id);}let g=[];for(let N of nn)for(let P of this._revisionsByTag(N))P.id&&w.has(P.id)&&g.push(P.el);let v=rn.flatMap(N=>this._revisionsByTag(N).filter(P=>P.id!==null&&w.has(P.id)).map(P=>P.el)),x=new Set;for(let N of [...g,...v]){let P=N.getAttribute("w:id");P&&x.add(P);}let E=this._comment_authors(),C=new Set(Object.keys(E)),A=[];for(let N of g){let P=N.tagName==="w:ins",D=N.parentNode?N.parentNode.tagName:"",T=D==="w:trPr",F=P&&D==="w:rPr"&&!!N.parentNode?.parentNode&&N.parentNode.parentNode.tagName==="w:pPr";if(u==="accept")if(P)if(T)N.parentNode?.removeChild(N);else {for(;N.firstChild;)N.parentNode?.insertBefore(N.firstChild,N);N.parentNode?.removeChild(N);}else if(this._clean_wrapping_comments(N),this._delete_comments_in_element(N),T){let I=N.parentNode?.parentNode;I?.parentNode?.removeChild(I);}else N.parentNode?.removeChild(N);else if(u==="reject")if(P){if(F){let I=N.parentNode;N.parentNode?.removeChild(N),I=I?.parentNode,I=I?.parentNode,I&&I.tagName==="w:p"&&A.push(I);continue}if(this._clean_wrapping_comments(N),this._delete_comments_in_element(N),T){let I=N.parentNode?.parentNode;I?.parentNode?.removeChild(I);}else N.parentNode?.removeChild(N);}else if(T)N.parentNode?.removeChild(N);else {let I=Array.from(N.getElementsByTagName("w:delText"));for(let S of I){let R=S.ownerDocument.createElement("w:t");R.textContent=S.textContent,S.hasAttribute("xml:space")&&R.setAttribute("xml:space","preserve"),S.parentNode?.replaceChild(R,S);}for(;N.firstChild;)N.parentNode?.insertBefore(N.firstChild,N);N.parentNode?.removeChild(N);}}for(let N of A.reverse()){if(!N.parentNode)continue;let P=Ee(N);for(;P&&P.tagName!=="w:p";)P=Ee(P);if(P){for(let D of Array.from(N.childNodes))D.nodeType===1&&D.tagName==="w:pPr"||P.appendChild(D);N.parentNode.removeChild(N);}}for(let N of v)u==="accept"?N.parentNode?.removeChild(N):N.tagName==="w:pPrChange"?this._revert_ppr_change(N):this._revert_props_change(N);for(let N of x)i.set(N,u);if(n++,C.size>0){let N=new Set(this._existing_comment_ids()),P=Array.from(C).filter(D=>!N.has(D));P.length>0&&this.skipped_details.push(`- Note: ${u} on ${a.target_id} also removed ${V._describe_removed_comments(P,E)} (including any reply thread) because its anchor was inside the resolved change. This note is informational \u2014 the action itself succeeded.`);}}return [n,r,s]}_apply_table_edit(e,n){let r=e._resolved_start_idx!==void 0&&e._resolved_start_idx!==null?e._resolved_start_idx:e._match_start_index||0,s=e._active_mapper_ref||this.mapper,[i,o]=s.get_insertion_anchor(r,n),a=null;if(i?a=i._element:o&&(a=o._element),!a)return false;let l=a;for(;l&&l.tagName!=="w:tr";)l=l.parentNode;if(!l)return false;let u=(e._reserved_row_id??null)!==null?String(e._reserved_row_id):null;if(e.type==="delete_row"){let c=M(l,"w:trPr");return c||(c=l.ownerDocument.createElement("w:trPr"),l.insertBefore(c,l.firstChild)),c.appendChild(this._create_track_change_tag("w:del","",u)),true}else if(e.type==="insert_row"){let c=l.ownerDocument.createElement("w:tr"),d=l.ownerDocument.createElement("w:trPr");c.appendChild(d),d.appendChild(this._create_track_change_tag("w:ins","",u));let f=$(l,"w:tc").filter(_=>_.parentNode===l).length,h=Array.isArray(e.cells)?[...e.cells]:[];if(f>0){for(;h.length<f;)h.push("");h=h.slice(0,f);}for(let _ of h){let p=l.ownerDocument.createElement("w:tc"),m=l.ownerDocument.createElement("w:p"),w=l.ownerDocument.createElement("w:r"),k=l.ownerDocument.createElement("w:t");k.textContent=_,_.trim()!==_&&k.setAttribute("xml:space","preserve"),w.appendChild(k),m.appendChild(w),p.appendChild(m),c.appendChild(p);}return e.position==="above"?l.parentNode?.insertBefore(c,l):Ue(c,l),true}return false}_pre_resolve_heuristic_edit(e){if(!e.target_text)return null;let n=e.regex||false,r=e.match_mode||"strict",s=this.mapper.drop_virtual_only_matches(this.mapper.find_all_match_indices(e.target_text,n)),i=false;if(s.length===0)if(this.clean_mapper||(this.clean_mapper=new ke(this.doc,true)),s=this.clean_mapper.drop_virtual_only_matches(this.clean_mapper.find_all_match_indices(e.target_text,n)),s.length>0)i=true;else return null;let o=i?this.clean_mapper:this.mapper,a=[];for(let[u,c]of s){let d=o.spans.filter(f=>f.run!==null&&f.end>u&&f.start<u+c);(d.length===0||d.some(f=>!f.del_id))&&a.push([u,c]);}if(a.length===0)return null;(r==="strict"||r==="first")&&(a=a.slice(0,1));let l=[];for(let[u,c]of a){let d=o.full_text.substring(u,u+c),f=e.new_text||"";if(/^\{#cell:[^}]+\}$/.test(d.trim())){let N=f;N=N.split(d.trim()).join("");let P=o.spans.find(D=>D.start<=u&&u<D.end&&D.paragraph!==null);if(P&&N){let D=o.spans.filter(T=>T.end<=u&&T.run!==null&&T.paragraph!==null&&T.paragraph._element===P.paragraph._element).map(T=>T.text).join("");if(D){for(let T of [D,D.replace(/\s+$/,"")])if(T&&N.startsWith(T)){N=N.substring(T.length).replace(/^\s+/,"");break}N&&!/\s$/.test(D)&&!/^\s/.test(N)&&(N=" "+N);}}N?l.push({type:"modify",target_text:"",new_text:N,comment:e.comment,_match_start_index:u,_internal_op:"INSERTION",_active_mapper_ref:o}):e.comment&&l.push({type:"modify",target_text:"",new_text:"",comment:e.comment,_match_start_index:u,_internal_op:"COMMENT_ONLY",_active_mapper_ref:o});continue}if(n&&f){try{f=d.replace(new RegExp(e.target_text),f);}catch{}V._flag_surviving_python_backreference(e,f);}f=bs(d,e.target_text,f),e._preview_span||(e._preview_span=[u,c],e._preview_matched_text=d,e._preview_new_text=f,e._preview_mapper_ref=o);let[h,_]=this._parse_markdown_style(e.target_text),[p,m]=this._parse_markdown_style(f);if(_!==m){let[N]=this._parse_markdown_style(d),P=N,D=p,T=P===D?"STYLE_ONLY":"STYLE_AND_TEXT",F=d.indexOf(N),I=u+(F!==-1?F:0),S=m!==null?m:"Normal";l.push({type:"modify",target_text:P,new_text:D,comment:e.comment,_match_start_index:I,_internal_op:T,_new_style:S,_active_mapper_ref:o});continue}if(d===f||e.target_text===f){l.push({type:"modify",target_text:d,new_text:d,comment:e.comment,_match_start_index:u,_internal_op:"COMMENT_ONLY",_active_mapper_ref:o});continue}let w=false;if(o&&(w=o.spans.some(N=>N.text===" | "&&(N.run===null||N.run===void 0)&&N.start<u+c&&N.end>u)),w){let N=d.split("|"),P=f.split("|");if(N.length!==P.length)throw new pt([`Target text spans ${N.length} table cells, but replacement provides ${P.length}. To modify text without altering table structure (rows or columns), ensure the replacement contains the exact same number of '|' separators (e.g., replace with 'CellC | ' to empty the second cell).`]);if(N.length>1){let D=[],T=0,F=0;for(let I=0;I<N.length;I++)if(N[I].trim()!==P[I].trim()){F=I;break}for(let I=0;I<N.length;I++){let S=N[I],R=P[I],j=S.trim(),B=R.trim(),L=u+T+(j?S.indexOf(j):0),U=e.comment!==null&&e.comment!==void 0&&I===F;if(j!==B||U){let Y=this._word_diff_sub_edits(j,B,L,U?e.comment:null,true,o);for(let X of Y)X._original_target_text=e.target_text,X._split_group_id=u,D.push(X);}T+=S.length+1;}for(let I of D)l.push(I);continue}}let k=false;e.target_text&&(e.target_text.includes("**")||e.target_text.includes("_"))&&(k=true),f&&(f.includes("**")||f.includes("_"))&&(k=true);let b="",g="",v="",x=u;if(f.startsWith(d))b="INSERTION",v=f.substring(d.length),x=u+c;else {let[N,P]=qe(d,f),D=d.length-P,T=f.length-P;g=d.substring(N,D),v=f.substring(N,T),x=u+N;}if(k){if(!g&&v)b="INSERTION";else if(g&&!v)b="DELETION";else if(g&&v)b="MODIFICATION";else {l.push({type:"modify",target_text:g,new_text:v,comment:e.comment,_match_start_index:x,_internal_op:"COMMENT_ONLY",_active_mapper_ref:o});continue}l.push({type:"modify",target_text:g,new_text:v,comment:e.comment,_resolved_start_idx:x,_match_start_index:x,_internal_op:b,_active_mapper_ref:o});continue}let E=d.split(`
115
115
 
116
116
  `),C=f.split(`
117
117
 
118
118
  `);if(d.includes(`
119
119
 
120
- `)&&A.length===C.length){let E=[],T=u,D=false;for(let P=0;P<A.length;P++){let R=A[P],$=C[P];if(R!==$){let S=e.comment&&!D?e.comment:null,j=this._word_diff_sub_edits(R,$,T,S,false,o);j.some(F=>F.comment!==null&&F.comment!==void 0)&&(D=true);for(let F of j)F._split_group_id=u,E.push(F);}T+=R.length+2;}if(E.length>0){for(let P of E)a.push(P);continue}}if(!m&&v){a.push({type:"modify",target_text:"",new_text:v,comment:e.comment,_resolved_start_idx:N,_match_start_index:N,_internal_op:"INSERTION",_active_mapper_ref:o});continue}let x=this._word_diff_sub_edits(d,f,u,e.comment,false,o);for(let E of x)E._split_group_id=u,a.push(E);}return a.length===0?null:r==="all"||a.length>1?a:a[0]}_insert_and_split_ins(e,n,r,s=false){let i=e.parentNode;if(!i)return;let o=e.cloneNode(false),l=e.cloneNode(false),a=false;for(let u of Array.from(e.childNodes))e.removeChild(u),s&&u===n&&(a=true),a?l.appendChild(u):(o.appendChild(u),u===n&&(a=true));o.childNodes.length>0&&i.insertBefore(o,e),i.insertBefore(r,e),l.childNodes.length>0&&i.insertBefore(l,e),i.removeChild(e);}_apply_single_edit_indexed(e,n,r){let s=e._internal_op,i=e._active_mapper_ref||this.mapper,o=e._resolved_start_idx!==void 0&&e._resolved_start_idx!==null?e._resolved_start_idx:e._match_start_index||0,l=e.target_text?e.target_text.length:0;s==null&&(!e.target_text&&e.new_text?s="INSERTION":e.target_text&&!e.new_text?s="DELETION":s="MODIFICATION");let a=this._edit_declares_emphasis(e),u=null;if(s==="STYLE_ONLY"||s==="STYLE_AND_TEXT"){let[m,v]=i.get_insertion_anchor(o,r),N=null;if(v)N=v._element;else if(m){let A=m._element;for(;A&&A.tagName!=="w:p";)A=A.parentNode;N=A;}if(N&&e._new_style&&(s==="STYLE_ONLY"?this._set_paragraph_style(N,e._new_style,this._getNextId()):u=N),s==="STYLE_ONLY"){if(e.comment){let A=i.find_target_runs_by_index(o,l,r);if(A.length>0){let C=A[0]._element,x=A[A.length-1]._element,E=C;for(;E&&E.tagName!=="w:p";)E=E.parentNode;let T=x;for(;T&&T.tagName!=="w:p";)T=T.parentNode;if(E&&T){let D=y(($,S)=>{let j=$;for(;j.parentNode&&j.parentNode!==S;)j=j.parentNode;return j},"ascend_to_paragraph_child"),P=D(C,E),R=D(x,T);E===T?this._attach_comment(E,P,R,e.comment):this._attach_comment_spanning(E,P,T,R,e.comment);}}}return true}e.target_text&&e.new_text?s="MODIFICATION":!e.target_text&&e.new_text?s="INSERTION":e.target_text&&!e.new_text?s="DELETION":s="COMMENT_ONLY";}let c=["DELETION","MODIFICATION"].includes(s)?(e._reserved_del_id??null)!==null?String(e._reserved_del_id):this._getNextId():null,d=["INSERTION","MODIFICATION"].includes(s)?(e._reserved_ins_id??null)!==null?String(e._reserved_ins_id):this._getNextId():null;if(u&&e._new_style&&this._set_paragraph_style(u,e._new_style,d??c??this._getNextId()),s==="COMMENT_ONLY"){let m=i.find_target_runs_by_index(o,l,r);if(m.length===0)return false;if(!e.comment)return true;let v=m[0]._element,N=m[m.length-1]._element,A=v;for(;A&&A.tagName!=="w:p";)A=A.parentNode;let C=N;for(;C&&C.tagName!=="w:p";)C=C.parentNode;if(!A||!C)return false;let x=y((D,P)=>{let R=D;for(;R.parentNode&&R.parentNode!==P;)R=R.parentNode;return R},"ascend_to_paragraph_child"),E=x(v,A),T=x(N,C);return A===C?this._attach_comment(A,E,T,e.comment):this._attach_comment_spanning(A,E,C,T,e.comment),true}if(s==="INSERTION"){let m=e.new_text||"",v=null,N=typeof i.part_boundary_at=="function"?i.part_boundary_at(o):null,A=!e.target_text&&(e._parent_edit_ref===void 0||e._parent_edit_ref===null);if(N!==null&&A){let[$,S]=N,j=i.part_kind_of($),F=i.part_kind_of(S);if(j==="body"&&F!=="body"){let B=i.spans.filter(L=>L.run!==null&&L.part_index===$);B.length>0&&(v=B[B.length-1]);}}let C,x;if(v!==null?(C=v.run,x=v.paragraph,m.startsWith(`
121
- `)||(m=`
120
+ `)&&E.length===C.length){let N=[],P=u,D=false;for(let T=0;T<E.length;T++){let F=E[T],I=C[T];if(F!==I){let S=e.comment&&!D?e.comment:null,R=this._word_diff_sub_edits(F,I,P,S,false,o);R.some(j=>j.comment!==null&&j.comment!==void 0)&&(D=true);for(let j of R)j._split_group_id=u,N.push(j);}P+=F.length+2;}if(N.length>0){for(let T of N)l.push(T);continue}}if(!g&&v){l.push({type:"modify",target_text:"",new_text:v,comment:e.comment,_resolved_start_idx:x,_match_start_index:x,_internal_op:"INSERTION",_active_mapper_ref:o});continue}let A=this._word_diff_sub_edits(d,f,u,e.comment,false,o);for(let N of A)N._split_group_id=u,l.push(N);}return l.length===0?null:r==="all"||l.length>1?l:l[0]}_insert_and_split_ins(e,n,r,s=false){let i=e.parentNode;if(!i)return;let o=e.cloneNode(false),a=e.cloneNode(false),l=false;for(let u of Array.from(e.childNodes))e.removeChild(u),s&&u===n&&(l=true),l?a.appendChild(u):(o.appendChild(u),u===n&&(l=true));o.childNodes.length>0&&i.insertBefore(o,e),i.insertBefore(r,e),a.childNodes.length>0&&i.insertBefore(a,e),i.removeChild(e);}_apply_single_edit_indexed(e,n,r){let s=e._internal_op,i=e._active_mapper_ref||this.mapper,o=e._resolved_start_idx!==void 0&&e._resolved_start_idx!==null?e._resolved_start_idx:e._match_start_index||0,a=e.target_text?e.target_text.length:0;s==null&&(!e.target_text&&e.new_text?s="INSERTION":e.target_text&&!e.new_text?s="DELETION":s="MODIFICATION");let l=this._edit_declares_emphasis(e),u=null;if(s==="STYLE_ONLY"||s==="STYLE_AND_TEXT"){let[g,v]=i.get_insertion_anchor(o,r),x=null;if(v)x=v._element;else if(g){let E=g._element;for(;E&&E.tagName!=="w:p";)E=E.parentNode;x=E;}if(x&&e._new_style&&(s==="STYLE_ONLY"?this._set_paragraph_style(x,e._new_style,this._getNextId()):u=x),s==="STYLE_ONLY"){if(e.comment){let E=i.find_target_runs_by_index(o,a,r);if(E.length>0){let C=E[0]._element,A=E[E.length-1]._element,N=C;for(;N&&N.tagName!=="w:p";)N=N.parentNode;let P=A;for(;P&&P.tagName!=="w:p";)P=P.parentNode;if(N&&P){let D=y((I,S)=>{let R=I;for(;R.parentNode&&R.parentNode!==S;)R=R.parentNode;return R},"ascend_to_paragraph_child"),T=D(C,N),F=D(A,P);N===P?this._attach_comment(N,T,F,e.comment):this._attach_comment_spanning(N,T,P,F,e.comment);}}}return true}e.target_text&&e.new_text?s="MODIFICATION":!e.target_text&&e.new_text?s="INSERTION":e.target_text&&!e.new_text?s="DELETION":s="COMMENT_ONLY";}let c=["DELETION","MODIFICATION"].includes(s)?(e._reserved_del_id??null)!==null?String(e._reserved_del_id):this._getNextId():null,d=["INSERTION","MODIFICATION"].includes(s)?(e._reserved_ins_id??null)!==null?String(e._reserved_ins_id):this._getNextId():null;if(u&&e._new_style&&this._set_paragraph_style(u,e._new_style,d??c??this._getNextId()),s==="COMMENT_ONLY"){let g=i.find_target_runs_by_index(o,a,r);if(g.length===0)return false;if(!e.comment)return true;let v=g[0]._element,x=g[g.length-1]._element,E=v;for(;E&&E.tagName!=="w:p";)E=E.parentNode;let C=x;for(;C&&C.tagName!=="w:p";)C=C.parentNode;if(!E||!C)return false;let A=y((D,T)=>{let F=D;for(;F.parentNode&&F.parentNode!==T;)F=F.parentNode;return F},"ascend_to_paragraph_child"),N=A(v,E),P=A(x,C);return E===C?this._attach_comment(E,N,P,e.comment):this._attach_comment_spanning(E,N,C,P,e.comment),true}if(s==="INSERTION"){let g=e.new_text||"",v=null,x=typeof i.part_boundary_at=="function"?i.part_boundary_at(o):null,E=!e.target_text&&(e._parent_edit_ref===void 0||e._parent_edit_ref===null);if(x!==null&&E){let[I,S]=x,R=i.part_kind_of(I),j=i.part_kind_of(S);if(R==="body"&&j!=="body"){let B=i.spans.filter(L=>L.run!==null&&L.part_index===I);B.length>0&&(v=B[B.length-1]);}}let C,A;if(v!==null?(C=v.run,A=v.paragraph,g.startsWith(`
121
+ `)||(g=`
122
122
 
123
- `+m)):[C,x]=i.get_insertion_anchor(o,r),!C&&!x||V._introduces_table_row_text(i,o,1,"",m))return false;let E=m,T=v===null&&/\n\s*$/.test(E),D=null;{let $=i.spans.filter(S=>S.paragraph!==null&&S.start===o);$.length>0&&$[0].paragraph&&(D=$[0].paragraph._element);}if(T&&D&&D.parentNode){let $=D.parentNode,S=this.doc.part._element.ownerDocument,j=E.split(/[\r\n]+/).filter(U=>U!==""),F=null,B=null,L=null;for(let U of j){let[Y,X]=this._parse_markdown_style(U),J=S.createElement("w:p");if(X)this._set_paragraph_style(J,X);else {let _e=M(D,"w:pPr");_e&&J.appendChild(this._clone_pPr_scrubbing_headings(_e));}let W=M(J,"w:pPr");W||(W=S.createElement("w:pPr"),J.insertBefore(W,J.firstChild));let te=M(W,"w:rPr");te||(te=S.createElement("w:rPr"),W.appendChild(te)),te.appendChild(this._create_track_change_tag("w:ins","",d));let ue=this._build_tracked_ins_for_line(Y,C,d,S,a);ue&&J.appendChild(ue),$.insertBefore(J,D),F||(F=J),B=J,L=ue;}if(F){if(e.comment&&B&&L){let U=y((X,J)=>{let W=X;for(;W.parentNode&&W.parentNode!==J;)W=W.parentNode;return W},"ascend"),Y=I(F,"w:ins")[0]||F;this._attach_comment_spanning(F,U(Y,F),B,U(L,B),e.comment);}return true}}let P=this._track_insert_multiline(m,C,x,d,null,a,o===0);if(!P.first_node)return false;if(P.first_node.tagName==="w:ins"){if(C){let $=C._element,S=$.parentNode;S&&S.tagName==="w:del"&&($=S,S=$.parentNode);let j=o===0;S&&S.tagName==="w:ins"?this._insert_and_split_ins(S,$,P.first_node,j):j&&S?S.insertBefore(P.first_node,$):Le(P.first_node,$);}else if(x){let $=x._element,S=$.firstChild;for(;S&&S.tagName==="w:pPr";)S=S.nextSibling;$.insertBefore(P.first_node,S);}}if(e.comment){let $=y((S,j)=>{let F=S;for(;F.parentNode&&F.parentNode!==j;)F=F.parentNode;return F},"ascend_to_paragraph_child");if(P.last_p&&P.last_ins){let S=P.first_node;for(;S&&S.tagName!=="w:p";)S=S.parentNode;if(S){let j=P.first_node;P.first_node.tagName==="w:p"&&(j=I(P.first_node,"w:ins")[0]||P.first_node);let F=$(j,S),B=$(P.last_ins,P.last_p);this._attach_comment_spanning(S,F,P.last_p,B,e.comment);}}else {let S=P.first_node;for(;S&&S.tagName!=="w:p";)S=S.parentNode;if(S){let j=P.first_node;P.first_node.tagName==="w:p"&&(j=I(P.first_node,"w:ins")[0]||P.first_node);let F=$(j,S);this._attach_comment(S,F,F,e.comment);}}}return true}if((s==="DELETION"||s==="MODIFICATION")&&l&&i.part_ranges.filter(m=>m[1]>m[0]).length>1){let m=new Set;for(let v of i.spans)v.run!==null&&v.end>o&&v.start<o+l&&m.add(v.part_index);if(m.size>1)return false}let f=i.find_target_runs_by_index(o,l,r),h=i.get_virtual_spans_in_range(o,l);if(f.length===0&&h.length===0)return false;let p=new Set;for(let m of f){let v=m._element.parentNode;for(;v&&v.tagName!=="w:p";)v=v.parentNode;v&&p.add(v);}let _=null,g=null;for(let m of f){let v=this._create_track_change_tag("w:del","",c),N=m._element.cloneNode(true);Array.from(N.getElementsByTagName("w:t")).forEach(C=>{let x=N.ownerDocument.createElement("w:delText");x.textContent=C.textContent,C.hasAttribute("xml:space")&&x.setAttribute("xml:space","preserve"),N.replaceChild(x,C);}),v.appendChild(N),m._element.parentNode?.replaceChild(v,m._element),_===null&&(_=v),g=v;}let w=null,k=null,b=null;if(s==="MODIFICATION"&&e.new_text&&g){let m=g;for(;m&&m.tagName!=="w:p";)m=m.parentNode;let v=m?new re(m,null):null,N=f.length>0?f[f.length-1]:null,A=this._track_insert_multiline(e.new_text,N,v,d,g,a);if(A.first_node){if(A.first_node.tagName==="w:ins"){let x=g.parentNode;x&&x.tagName==="w:ins"?this._insert_and_split_ins(x,g,A.first_node):Le(A.first_node,g),w=A.first_node;}else w=A.last_ins;k=A.last_p,b=A.last_ins;}}if(s==="DELETION"||s==="MODIFICATION"){if(s==="MODIFICATION"&&f.length===0&&h.length>0&&e.new_text){let m=h[0];if(m.paragraph){let v=m.paragraph._element,N=I(v,"w:r"),A=N.length>0?new Ae(N[N.length-1],m.paragraph):null,C=this._track_insert_multiline(e.new_text,A,m.paragraph,d,null,a);C.first_node&&v.appendChild(C.first_node);}}for(let m of [...h].reverse())if(m.paragraph){let v=m.paragraph._element,N=ve(v);for(;N&&N.tagName!=="w:p";)N=ve(N);if(N&&N.tagName==="w:p"){let A=!this._paragraph_has_visible_content(v),C=M(v,"w:pPr");if(A){let T=M(N,"w:pPr"),D=T?T.cloneNode(true):v.ownerDocument.createElement("w:pPr");if(C){let P=M(C,"w:sectPr");P&&!M(D,"w:sectPr")&&D.appendChild(P.cloneNode(true)),v.removeChild(C);}v.insertBefore(D,v.firstChild),C=D;}C||(C=v.ownerDocument.createElement("w:pPr"),v.insertBefore(C,v.firstChild));let x=M(C,"w:rPr");if(x||(x=v.ownerDocument.createElement("w:rPr"),C.appendChild(x)),!M(x,"w:del")){let T=this._create_track_change_tag("w:del");x.appendChild(T);}let E=Array.from(N.childNodes);for(let T of E)T.nodeType===1&&T.tagName==="w:pPr"||v.appendChild(T);N.parentNode&&N.parentNode.removeChild(N);}}}if(e.comment&&_!==null){let m,v;if(k&&b)m=b,v=k;else {let E=w!==null?w:g;for(m=E,v=E;v&&v.tagName!=="w:p";)v=v.parentNode;}let N=_;for(;N&&N.tagName!=="w:p";)N=N.parentNode;if(!N||!v)return true;let A=y((E,T)=>{let D=E;for(;D.parentNode&&D.parentNode!==T;)D=D.parentNode;return D},"ascend_to_paragraph_child"),C=A(_,N),x=A(m,v);N===v?this._attach_comment(N,C,x,e.comment):this._attach_comment_spanning(N,C,v,x,e.comment);}for(let m of p)if(!this._paragraph_has_visible_content(m)){let N=M(m,"w:pPr");N||(N=m.ownerDocument.createElement("w:pPr"),m.insertBefore(N,m.firstChild));let A=M(N,"w:rPr");if(A||(A=m.ownerDocument.createElement("w:rPr"),N.appendChild(A)),!M(A,"w:del")){let C=this._create_track_change_tag("w:del");A.appendChild(C);}}return true}};function Z(t,e){let n=[],r=t.getElementsByTagName("*");for(let s=0;s<r.length;s++){let i=r[s].tagName;(i===e||i.endsWith(":"+e))&&n.push(r[s]);}return n}y(Z,"findDescendantsByLocalName");function Po(t){let e=0;function n(o,l){let a=o?o.toString():"",u=l?l.toString():"";return a===u}y(n,"areRunsIdentical");function r(o){let l=["w:t","w:tab","w:br","w:cr","w:delText","w:rPr"];for(let a=0;a<o.childNodes.length;a++){let u=o.childNodes[a];if(u.nodeType===1){let c=u.tagName;if(!l.includes(c))return true}}return false}y(r,"hasSpecialContent");function s(o){let l=Array.from(o.childNodes).filter(u=>u.nodeType===1),a=0;for(;a<l.length-1;){let u=l[a],c=l[a+1];if(u.tagName==="w:r"&&c.tagName==="w:r"&&!r(u)&&!r(c)){let d=M(u,"w:rPr"),f=M(c,"w:rPr");if(n(d,f)){let h=null;for(let _=0;_<u.childNodes.length;_++){let g=u.childNodes[_];g.nodeType===1&&(g.tagName==="w:t"||g.tagName==="w:delText")&&(h=g);}let p=Array.from(c.childNodes).filter(_=>_.nodeType===1);for(let _ of p)if(_.tagName!=="w:rPr")if((_.tagName==="w:t"||_.tagName==="w:delText")&&h&&h.tagName===_.tagName){let g=h.textContent||"",w=_.textContent||"",k=g+w;h.textContent=k,k.trim()!==k&&h.setAttribute("xml:space","preserve");}else u.appendChild(_),(_.tagName==="w:t"||_.tagName==="w:delText")&&(h=_);o.removeChild(c),l.splice(a+1,1),e++;continue}}["w:ins","w:del","w:hyperlink","w:sdt","w:smartTag","w:fldSimple","w:sdtContent"].includes(u.tagName)&&s(u),a++;}if(l.length>0){let u=l[l.length-1];["w:ins","w:del","w:hyperlink","w:sdt","w:smartTag","w:fldSimple","w:sdtContent"].includes(u.tagName)&&s(u);}}y(s,"coalesceContainer");let i=I(t.element,"w:p");for(let o of i)s(o);return e?[`Adjacent identical runs coalesced: ${e}`]:[]}y(Po,"coalesce_runs");function To(t){let e=0,n=["w:rsidR","w:rsidRPr","w:rsidRDefault","w:rsidP","w:rsidDel","w:rsidSect","w:rsidTr"],r=t.element.getElementsByTagName("*");for(let i=0;i<r.length;i++)for(let o of n)r[i].hasAttribute(o)&&(r[i].removeAttribute(o),e++);let s=I(t.element,"w:rsids");for(let i of s)i.parentNode&&(i.parentNode.removeChild(i),e++);return e?[`rsid attributes: ${e} removed`]:[]}y(To,"strip_rsid");function So(t){let e=0,n=["w14:paraId","w14:textId"],r=t.element.getElementsByTagName("*");for(let s=0;s<r.length;s++)for(let i of n)r[s].hasAttribute(i)&&(r[s].removeAttribute(i),e++);return e?[`Paragraph/text IDs: ${e} removed`]:[]}y(So,"strip_para_ids");function Io(t){let e=I(t.element,"w:proofErr");return e.forEach(n=>n.parentNode?.removeChild(n)),e.length?[`Spell check markers: ${e.length} removed`]:[]}y(Io,"strip_proof_errors");function $o(t){let e=0;for(let n of ["w:rPr","w:pPr"]){let r=I(t.element,n);for(let s of r)(s.childNodes.length===0||s.childNodes.length===1&&s.childNodes[0].nodeType===3&&!s.childNodes[0].textContent?.trim())&&(s.parentNode?.removeChild(s),e++);}return e?[`Empty property elements: ${e} removed`]:[]}y($o,"strip_empty_properties");function Oo(t){let e=0,n=I(t.element,"w:rPr");for(let r of n)if(M(r,"w:vanish")||M(r,"w:webHidden")){let s=r.parentNode;s&&s.tagName==="w:r"&&s.parentNode&&(s.parentNode.removeChild(s),e++);}return e?[`Hidden text runs: ${e} removed`]:[]}y(Oo,"strip_hidden_text");function rr(t){let e=I(t.element,"w:ins").length,n=I(t.element,"w:del").length,r=I(t.element,"w:rPrChange").length+I(t.element,"w:pPrChange").length+I(t.element,"w:sectPrChange").length;return [e,n,r]}y(rr,"count_tracked_changes");function Do(t){let e=new Set;for(let n of ["w:ins","w:del","w:rPrChange","w:pPrChange","w:sectPrChange"])for(let r of I(t.element,n)){let s=r.getAttribute("w:author");s&&e.add(s);}return e}y(Do,"get_track_change_authors");function ir(t){let e=[],n=I(t,"w:t");for(let s of n)s.textContent&&e.push(s.textContent);let r=I(t,"w:delText");for(let s of r)s.textContent&&e.push(s.textContent);return e.join("")}y(ir,"_getElementText");function Pe(t,e=60){let n=t.replace(/\n/g," ").trim();return n.length<=e?n:n.substring(0,e-3)+"..."}y(Pe,"_truncate");function sr(t){let e=t.parentNode;if(e&&e.tagName==="w:rPr"){let n=e.parentNode;if(n&&n.tagName==="w:pPr")return "(paragraph mark)"}return e&&e.tagName==="w:trPr"?"(table row)":"(no visible text)"}y(sr,"_describe_textless_revision");function Mo(t){let e=[],n=I(t.element,"w:ins"),r=I(t.element,"w:del");for(let o of n){let l=ir(o).trim();l?e.push(` Accepted insertion: "${Pe(l,60)}"`):e.push(` Accepted insertion: ${sr(o)}`);}for(let o of r){let l=ir(o).trim();l?e.push(` Accepted deletion of: "${Pe(l,60)}"`):e.push(` Accepted deletion of: ${sr(o)}`);}new fn(t).accept_all_revisions();for(let o of ["w:rPrChange","w:pPrChange","w:sectPrChange"])for(let l of I(t.element,o))l.parentNode?.removeChild(l);let i=n.length+r.length;return i?[`Tracked changes auto-accepted: ${i}`].concat(e):[]}y(Mo,"accept_all_tracked_changes");function _t(t){let e=Xe(t.pkg),n=[],r=0,s=0;for(let[i,o]of Object.entries(e))o.resolved?s++:r++,n.push({id:i,...o});return {total:n.length,open:r,resolved:s,comments:n}}y(_t,"get_comments_summary");function Ro(t){let e=Xe(t.pkg),n=Object.keys(e);if(n.length===0)return [];let r=[],s=new nt(t);for(let[a,u]of Object.entries(e)){let c=u.resolved?"[Resolved]":"[Open]";r.push(` ${c} "${Pe(u.text||"",60)}" (${u.author||"Unknown"})`),s.deleteComment(a);}for(let a of ["w:commentRangeStart","w:commentRangeEnd"])for(let u of I(t.element,a))u.parentNode?.removeChild(u);let i=I(t.element,"w:commentReference");for(let a of i){let u=a.parentNode;u&&((u.tagName==="w:r"||u.tagName.endsWith(":r"))&&Array.from(u.childNodes).filter(d=>d.nodeType===1&&d.tagName!=="w:rPr"&&d.tagName!=="rPr").length<=1?u.parentNode?.removeChild(u):u.removeChild(a));}let o=Object.values(e).filter(a=>a.resolved).length,l=Object.values(e).filter(a=>!a.resolved).length;return [`Comments removed: ${n.length} (${o} resolved, ${l} open)`].concat(r)}y(Ro,"remove_all_comments");function jo(t){let e=t.pkg,n=new Set;for(let s of e.parts)if(s.partname.toLowerCase().includes("comments")){n.add(s.partname);let i=s.partname.startsWith("/")?s.partname:"/"+s.partname,o=s.partname.startsWith("/")?s.partname.substring(1):s.partname;n.add(i),n.add(o);}if(n.size===0)return;for(let s of e.parts)if(s.partname.endsWith(".rels")){let i=I(s._element,"Relationship"),o=[];for(let l of i)if((l.getAttribute("Target")||"").toLowerCase().includes("comments")){o.push(l);let u=s.partname.replace("/_rels/","/").replace(".rels",""),c=e.getPartByPath(u);if(c){let d=l.getAttribute("Id");d&&c.rels.delete(d);}}for(let l of o)l.parentNode?.removeChild(l);}let r=e.getPartByPath("[Content_Types].xml");if(r){let s=I(r._element,"Override"),i=[];for(let o of s){let l=o.getAttribute("PartName")||"";(n.has(l)||l.toLowerCase().includes("comments"))&&i.push(o);}for(let o of i)o.parentNode?.removeChild(o);}e.parts=e.parts.filter(s=>!s.partname.toLowerCase().includes("comments"));for(let s of Object.keys(e.unzipped))s.toLowerCase().includes("comments")&&delete e.unzipped[s];}y(jo,"eject_comment_parts");function Fo(t,e){let n=new nt(t);if(!n.commentsPart)return [];let r=new Set,s=I(n.commentsPart._element,"w:comment");for(let i of s){let o=i.getAttribute("w:author");if(o&&(r.add(o),i.setAttribute("w:author",e)),i.hasAttribute("w:initials")){let l=e.split(" ").filter(Boolean).map(a=>a[0]).join("").toUpperCase();i.setAttribute("w:initials",l);}}return r.size?[`Comment authors replaced: ${Array.from(r).sort().join(", ")} \u2192 "${e}"`]:[]}y(Fo,"replace_comment_authors");function Bo(t,e){let n=new Set;for(let r of ["w:ins","w:del","w:rPrChange","w:pPrChange"])for(let s of I(t.element,r)){let i=s.getAttribute("w:author");i&&(n.add(i),s.setAttribute("w:author",e));}return n.size?[`Track change authors replaced: ${Array.from(n).sort().join(", ")} \u2192 "${e}"`]:[]}y(Bo,"replace_change_authors");function Wo(t){let e=0,n="2025-01-01T00:00:00Z";for(let r of ["w:ins","w:del","w:rPrChange","w:pPrChange"])for(let s of I(t.element,r))s.hasAttribute("w:date")&&(s.setAttribute("w:date",n),e++);return e?[`Track change timestamps: ${e} normalized`]:[]}y(Wo,"normalize_change_dates");function zo(t){let e=0,n="2025-01-01T00:00:00Z";for(let r of t.pkg.parts)if(r.contentType.includes("comments")){for(let s of I(r._element,"w:comment"))s.hasAttribute("w:date")&&(s.setAttribute("w:date",n),e++);for(let s of I(r._element,"w16cex:commentExtensible"))s.hasAttribute("w16cex:dateUtc")&&(s.setAttribute("w16cex:dateUtc",n),e++);}return e?[`Comment timestamps: ${e} normalized`]:[]}y(zo,"normalize_comment_dates");function Lo(t){let e=[],n=t.pkg.getPartByPath("docProps/core.xml");if(n){Z(n._element,"creator").forEach(u=>{u.textContent&&(e.push(`Author: ${u.textContent}`),u.textContent="");}),Z(n._element,"lastModifiedBy").forEach(u=>{u.textContent&&(e.push(`Last modified by: ${u.textContent}`),u.textContent="");}),Z(n._element,"title").forEach(u=>{u.textContent&&e.push(`Title kept (review manually): "${u.textContent}"`);});let l=[["category","Category"],["keywords","Keywords"],["subject","Subject"],["contentStatus","Content status"],["description","Description/comments"],["identifier","Identifier"],["language","Language"],["version","Version"]];for(let[u,c]of l)Z(n._element,u).forEach(d=>{d.textContent&&(e.push(`${c}: ${d.textContent}`),d.textContent="");});Z(n._element,"revision").forEach(u=>{u.textContent&&parseInt(u.textContent)>1&&(e.push(`Revision count: ${u.textContent} \u2192 1`),u.textContent="1");});}let r=t.pkg.getPartByPath("docProps/app.xml");if(r){let s=r._element,i=["TotalTime","Words","Characters","Paragraphs","Lines","CharactersWithSpaces"];for(let l of i)Z(s,l).forEach(a=>{a.textContent&&a.textContent!=="0"&&(l==="TotalTime"&&e.push(`Total editing time: ${a.textContent} minutes`),a.textContent="0");});let o=["Template","Manager","Company"];for(let l of o)Z(s,l).forEach(a=>{a.textContent&&(e.push(`${l}: ${a.textContent}`),a.textContent="");});}return e.length?["Metadata scrubbed:",...e.map(s=>` ${s}`)]:[]}y(Lo,"scrub_doc_properties");function Uo(t){let e=false,n="1970-01-01T00:00:00Z",r=t.pkg.getPartByPath("docProps/core.xml");if(r)for(let s of ["created","modified","lastPrinted"])Z(r._element,s).forEach(i=>{i.textContent&&i.textContent!==n&&(i.textContent=n,e=true);});return e?["Timestamps normalized to epoch"]:[]}y(Uo,"scrub_timestamps");function Jr(t,e,n){let r=t.pkg,s=y(o=>o.startsWith("/")?o.substring(1):o,"normalized");for(let o of r.parts){if(!o.partname.endsWith(".rels"))continue;let l=[];for(let a of I(o._element,"Relationship")){let u=a.getAttribute("Target")||"";if(n(u)){l.push(a);let c=o.partname.replace("/_rels/","/").replace(".rels",""),d=r.getPartByPath(c);if(d){let f=a.getAttribute("Id");f&&d.rels.delete(f);}}}l.forEach(a=>a.parentNode?.removeChild(a));}let i=r.getPartByPath("[Content_Types].xml");if(i){let o=[];for(let l of I(i._element,"Override")){let a=l.getAttribute("PartName")||"";e(s(a))&&o.push(l);}o.forEach(l=>l.parentNode?.removeChild(l));}r.parts=r.parts.filter(o=>!e(s(o.partname)));for(let o of Object.keys(r.unzipped))e(s(o))&&delete r.unzipped[o];}y(Jr,"ejectPackageMembers");function qo(t){let e=y(s=>s.startsWith("customXml/"),"isCustomXml"),n=t.pkg.parts.filter(s=>e(s.partname.startsWith("/")?s.partname.substring(1):s.partname)),r=Object.keys(t.pkg.unzipped).filter(e);if(n.length===0&&r.length===0)return [];Jr(t,e,s=>s.includes("customXml"));for(let s of I(t.element,"w:sdtPr"))wr(s,"w:dataBinding").forEach(i=>s.removeChild(i));return [`Custom XML parts: ${Math.max(n.length,r.length)} removed`]}y(qo,"strip_custom_xml");var Ht="docProps/custom.xml";function Jo(t){let e=t.pkg.getPartByPath(Ht),n=Object.keys(t.pkg.unzipped).includes(Ht);if(!e&&!n)return [];let r=[];if(e)for(let i of Z(e._element,"property")){let o=i.getAttribute("name")||"(unnamed)",l=(i.textContent||"").trim();r.push(` Custom property removed: ${o} = "${Pe(l,60)}"`);}return Jr(t,i=>i===Ht,i=>i.includes("docProps/custom.xml")),[`Custom document properties: ${Math.max(r.length,1)} removed (docProps/custom.xml)`].concat(r)}y(Jo,"strip_custom_properties");function Ho(t){let e=t.pkg.getPartByPath("word/settings.xml");if(!e)return [];let n=[],r=false;for(let i of Z(e._element,"docVars")){for(let o of Array.from(i.childNodes)){let l=o,a=l.tagName||"";(a==="docVar"||a.endsWith(":docVar"))&&n.push(l.getAttribute("w:name")||l.getAttribute("name")||"(unnamed)");}i.parentNode?.removeChild(i),r=true;}for(let i of Z(e._element,"docVar"))n.push(i.getAttribute("w:name")||i.getAttribute("name")||"(unnamed)"),i.parentNode?.removeChild(i),r=true;if(!r)return [];let s=Array.from(new Set(n)).sort().join(", ")||"(unnamed)";return [`Document variables: ${n.length} removed (${s})`]}y(Ho,"strip_document_variables");function Xo(t){let e=0;for(let n of Z(t.element,"docPr")){let r=n.getAttribute("descr");if(r){let s=r.length<10,i=r.includes(".")&&r.length<60;(s||i)&&(n.removeAttribute("descr"),e++);}}return e?[`Image alt text: ${e} auto-generated descriptions removed`]:[]}y(Xo,"strip_image_alt_text");function Qo(t){let e=[],n=new Set;for(let r of t.pkg.parts){let s=String(r.partname),i;if(s.startsWith("/word/header"))i="header";else if(s.startsWith("/word/footer"))i="footer";else if(s==="/word/document.xml")i="body";else continue;let o;try{o=Z(r._element,"textpath");}catch{continue}for(let l of o){let a=(l.getAttribute("string")||"").trim(),u=`${i}${a}`;if(n.has(u))continue;n.add(u);let c=a?`"${Pe(a,60)}"`:"(no text)";e.push(`Watermark-like text object in ${i}: ${c} \u2014 NOT removed. It remains in the document package and may render in other applications; review and remove it in Word if it must not reach the counterparty.`);}}return e}y(Qo,"detect_watermarks");function Yo(t){let e=["sharepoint.com","onedrive.com",".internal","intranet","localhost","10.","192.168.","172.16."],n=[],r=t.pkg.getOrCreateRelsPart(t.part.partname);for(let s of I(r._element,"Relationship"))if(s.getAttribute("TargetMode")==="External"){let i=s.getAttribute("Target")||"";for(let o of e)if(i.toLowerCase().includes(o.toLowerCase())){n.push(`Hyperlink targets internal URL: ${Pe(i,80)}`);break}}return n}y(Yo,"audit_hyperlinks");function Go(t,e,n=2){if(t===e)return 0;if(Math.abs(t.length-e.length)>n)return n+1;if(t.length===0)return e.length<=n?e.length:n+1;if(e.length===0)return t.length<=n?t.length:n+1;if(t.length>e.length){let s=t;t=e,e=s;}let r=Array.from({length:t.length+1},(s,i)=>i);for(let s=1;s<=e.length;s++){let i=[s],o=s;for(let l=1;l<=t.length;l++){let a=t[l-1]===e[s-1]?0:1,u=Math.min(r[l]+1,i[l-1]+1,r[l-1]+a);i.push(u),u<o&&(o=u);}if(o>n)return n+1;r=i;}return r[t.length]<=n?r[t.length]:n+1}y(Go,"boundedLevenshtein");function Vo(t){let e="",n=I(t._element,"w:r");for(let r of n)e+=De(new Ae(r,t));return e}y(Vo,"_get_paragraph_text");var hn="[A-Z][A-Za-z0-9\\s\\-&'\u2019]{1,60}",Zo=new RegExp(`^(?:[\\d.\\-()a-zA-Z]+\\s*)?["\u201C](${hn})["\u201D]`,"d"),Ko=new RegExp(`(?<=[.;:!?])\\s+(?:[\\d.\\-()a-zA-Z]+\\s+)?["\u201C](${hn})["\u201D]`,"dg"),ea=new RegExp(`\\([^)]*?["\u201C](${hn})["\u201D][^)]*?\\)`,"dg");function ta(t){let e=[],n=Zo.exec(t);n&&n.indices&&n.indices[1]&&e.push([n.indices[1][0],n[1].trim()]);for(let i of t.matchAll(Ko)){let o=i.indices;o&&o[1]&&e.push([o[1][0],i[1].trim()]);}for(let i of t.matchAll(ea)){let o=i.indices;o&&o[1]&&e.push([o[1][0],i[1].trim()]);}let r=[],s=new Set;e.sort((i,o)=>i[0]-o[0]);for(let[i,o]of e)s.has(i)||(s.add(i),r.push(o));return r}y(ta,"extract_terms_from_paragraph");function na(t,e){let n={},r=new Set,s={},i=[];for(let _ of Ie(t)){if(!(_ instanceof re))continue;let g=Vo(_).trim();if(!g)continue;for(let b of ta(g))n[b]?r.add(b):n[b]={count:0};let w=g.length>60?g.substring(0,60)+"...":g,k=I(_._element,"*");for(let b of k){if(b.tagName==="w:bookmarkStart"){let v=b.getAttribute("w:name");v&&(!v.startsWith("_")||v.startsWith("_Ref"))&&(s[v]||(s[v]={anchored_to:w,referenced_from:[]}));}let m=null;if(b.tagName==="w:fldSimple"){let N=(b.getAttribute("w:instr")||"").trim().split(/\s+/);N.length>1&&N[0]==="REF"&&(m=N[1]);}else if(b.tagName==="w:instrText"){let N=(b.textContent||"").trim().split(/\s+/);N.length>1&&N[0]==="REF"&&(m=N[1]);}m&&i.push([m,w]);}}for(let[_,g]of i)s[_]&&s[_].referenced_from.push(g);let o=[],l=Object.keys(n);if(l.length>0){let _=l.sort((b,m)=>m.length-b.length),g=y(b=>b.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"escapeRegExp"),w=_.map(g).join("|"),k=new RegExp(`(?<!["\u201C])\\b(${w})\\b(?![\u201D"])`,"g");for(let b of e.matchAll(k)){let m=b[1];n[m]&&n[m].count++;}for(let b of l)n[b].count===0&&(delete n[b],r.has(b)||o.push(`[Warning] Unused Definition: '${b}' is defined but never used.`));}for(let _ of r)o.push(`[Error] Duplicate Definition: '${_}' is defined multiple times.`);let a=new Set(["The","This","That","Such","A","An","Any","All","Some","No","Every","Each","As","In","Of","For","To","On","By","With"]),u=/\b[A-Z][a-zA-Z]*(?:\s+[A-Z][a-zA-Z]*)*\b/g,c=new Set(e.match(u)||[]),d=new Set(Object.keys(n)),f={};for(let _ of d){let g=_[0].toLowerCase();f[g]||(f[g]=[]),f[g].push(_);}let h={};for(let _ of c){let g=_.trim(),w=g.split(/\s+/);for(;w.length>0;){let m=w[0],v=m.charAt(0).toUpperCase()+m.slice(1).toLowerCase();if(a.has(v))w.shift();else break}if(g=w.join(" "),g.length<4||d.has(g))continue;let k=g[0].toLowerCase(),b=f[k]||[];if(g.length>5)for(let[m,v]of Object.entries(f))m!==k&&(b=b.concat(v));for(let m of b){if(Math.abs(g.length-m.length)>2||g===m+"s"||g===m+"es"||m===g+"s"||m===g+"es")continue;let v=Go(g,m,2);v===0||v>2||m.length<=5&&(v>1||g[0].toLowerCase()!==m[0].toLowerCase())||(h[m]||(h[m]=[]),h[m].includes(g)||h[m].push(g));}}for(let[_,g]of Object.entries(h)){g.sort();let w=g.map(k=>`'${k}'`).join(", ");o.push(`[Info] Possible Typos for '${_}': Found ${w}`);}function p(_){return _.startsWith("[Error]")?0:_.startsWith("[Warning]")?1:2}return y(p,"diag_sort_key"),o.sort((_,g)=>{let w=p(_),k=p(g);return w!==k?w-k:_.localeCompare(g)}),[n,o,s]}y(na,"extract_all_domain_metadata");function ra(t){let e=[],n=t.pkg.getPartByPath("word/settings.xml");if(!n)return e;let r=y(o=>{if(!o.hasAttribute("w:val"))return true;let l=(o.getAttribute("w:val")||"").toLowerCase();return l!=="0"&&l!=="false"&&l!=="off"},"isTruthy"),s=Z(n._element,"removePersonalInformation");s.length>0&&r(s[0])&&e.push("[Warning] Privacy flag `removePersonalInformation` is enabled in word/settings.xml. Microsoft Word will strip the `w:author`, `w:initials`, and `w:date` attributes from every tracked change and comment the next time this document is opened and saved. Edits made by this agent will lose attribution, breaking audit trails and any multi-turn workflow that relies on identifying prior edits.");let i=Z(n._element,"removeDateAndTime");return i.length>0&&r(i[0])&&e.push("[Warning] Privacy flag `removeDateAndTime` is enabled in word/settings.xml. Microsoft Word will strip the `w:date` attribute from every tracked change and comment the next time this document is opened and saved. Timestamps on this agent's edits will be lost on the next Word save."),e}y(ra,"extract_document_settings_warnings");function ia(t,e){let[n,r,s]=na(t,e),i=ra(t),o=[`
123
+ `+g)):[C,A]=i.get_insertion_anchor(o,r),!C&&!A||V._introduces_table_row_text(i,o,1,"",g))return false;let N=g,P=v===null&&/\n\s*$/.test(N),D=null;{let I=i.spans.filter(S=>S.paragraph!==null&&S.start===o);I.length>0&&I[0].paragraph&&(D=I[0].paragraph._element);}if(P&&D&&D.parentNode){let I=D.parentNode,S=this.doc.part._element.ownerDocument,R=N.split(/[\r\n]+/).filter(U=>U!==""),j=null,B=null,L=null;for(let U of R){let[Y,X]=this._parse_markdown_style(U),J=S.createElement("w:p");if(X)this._set_paragraph_style(J,X);else {let _e=M(D,"w:pPr");_e&&J.appendChild(this._clone_pPr_scrubbing_headings(_e));}let W=M(J,"w:pPr");W||(W=S.createElement("w:pPr"),J.insertBefore(W,J.firstChild));let te=M(W,"w:rPr");te||(te=S.createElement("w:rPr"),W.appendChild(te)),te.appendChild(this._create_track_change_tag("w:ins","",d));let ue=this._build_tracked_ins_for_line(Y,C,d,S,l);ue&&J.appendChild(ue),I.insertBefore(J,D),j||(j=J),B=J,L=ue;}if(j){if(e.comment&&B&&L){let U=y((X,J)=>{let W=X;for(;W.parentNode&&W.parentNode!==J;)W=W.parentNode;return W},"ascend"),Y=$(j,"w:ins")[0]||j;this._attach_comment_spanning(j,U(Y,j),B,U(L,B),e.comment);}return true}}let T=this._track_insert_multiline(g,C,A,d,null,l,o===0);if(!T.first_node)return false;if(T.first_node.tagName==="w:ins"){if(C){let I=C._element,S=I.parentNode;S&&S.tagName==="w:del"&&(I=S,S=I.parentNode);let R=o===0;S&&S.tagName==="w:ins"?this._insert_and_split_ins(S,I,T.first_node,R):R&&S?S.insertBefore(T.first_node,I):Ue(T.first_node,I);}else if(A){let I=A._element,S=I.firstChild;for(;S&&S.tagName==="w:pPr";)S=S.nextSibling;I.insertBefore(T.first_node,S);}}if(e.comment){let I=y((S,R)=>{let j=S;for(;j.parentNode&&j.parentNode!==R;)j=j.parentNode;return j},"ascend_to_paragraph_child");if(T.last_p&&T.last_ins){let S=T.first_node;for(;S&&S.tagName!=="w:p";)S=S.parentNode;if(S){let R=T.first_node;T.first_node.tagName==="w:p"&&(R=$(T.first_node,"w:ins")[0]||T.first_node);let j=I(R,S),B=I(T.last_ins,T.last_p);this._attach_comment_spanning(S,j,T.last_p,B,e.comment);}}else {let S=T.first_node;for(;S&&S.tagName!=="w:p";)S=S.parentNode;if(S){let R=T.first_node;T.first_node.tagName==="w:p"&&(R=$(T.first_node,"w:ins")[0]||T.first_node);let j=I(R,S);this._attach_comment(S,j,j,e.comment);}}}return true}if((s==="DELETION"||s==="MODIFICATION")&&a&&i.part_ranges.filter(g=>g[1]>g[0]).length>1){let g=new Set;for(let v of i.spans)v.run!==null&&v.end>o&&v.start<o+a&&g.add(v.part_index);if(g.size>1)return false}let f=i.find_target_runs_by_index(o,a,r),h=i.get_virtual_spans_in_range(o,a);if(f.length===0&&h.length===0)return false;let _=new Set;for(let g of f){let v=g._element.parentNode;for(;v&&v.tagName!=="w:p";)v=v.parentNode;v&&_.add(v);}let p=null,m=null;for(let g of f){let v=this._create_track_change_tag("w:del","",c),x=g._element.cloneNode(true);Array.from(x.getElementsByTagName("w:t")).forEach(C=>{let A=x.ownerDocument.createElement("w:delText");A.textContent=C.textContent,C.hasAttribute("xml:space")&&A.setAttribute("xml:space","preserve"),x.replaceChild(A,C);}),v.appendChild(x),g._element.parentNode?.replaceChild(v,g._element),p===null&&(p=v),m=v;}let w=null,k=null,b=null;if(s==="MODIFICATION"&&e.new_text&&m){let g=m;for(;g&&g.tagName!=="w:p";)g=g.parentNode;let v=g?new re(g,null):null,x=f.length>0?f[f.length-1]:null,E=this._track_insert_multiline(e.new_text,x,v,d,m,l);if(E.first_node){if(E.first_node.tagName==="w:ins"){let A=m.parentNode;A&&A.tagName==="w:ins"?this._insert_and_split_ins(A,m,E.first_node):Ue(E.first_node,m),w=E.first_node;}else w=E.last_ins;k=E.last_p,b=E.last_ins;}}if(s==="DELETION"||s==="MODIFICATION"){if(s==="MODIFICATION"&&f.length===0&&h.length>0&&e.new_text){let g=h[0];if(g.paragraph){let v=g.paragraph._element,x=$(v,"w:r"),E=x.length>0?new Ae(x[x.length-1],g.paragraph):null,C=this._track_insert_multiline(e.new_text,E,g.paragraph,d,null,l);C.first_node&&v.appendChild(C.first_node);}}for(let g of [...h].reverse())if(g.paragraph){let v=g.paragraph._element,x=ve(v);for(;x&&x.tagName!=="w:p";)x=ve(x);if(x&&x.tagName==="w:p"){let E=!this._paragraph_has_visible_content(v),C=M(v,"w:pPr");if(E){let P=M(x,"w:pPr"),D=P?P.cloneNode(true):v.ownerDocument.createElement("w:pPr");if(C){let T=M(C,"w:sectPr");T&&!M(D,"w:sectPr")&&D.appendChild(T.cloneNode(true)),v.removeChild(C);}v.insertBefore(D,v.firstChild),C=D;}C||(C=v.ownerDocument.createElement("w:pPr"),v.insertBefore(C,v.firstChild));let A=M(C,"w:rPr");if(A||(A=v.ownerDocument.createElement("w:rPr"),C.appendChild(A)),!M(A,"w:del")){let P=this._create_track_change_tag("w:del");A.appendChild(P);}let N=Array.from(x.childNodes);for(let P of N)P.nodeType===1&&P.tagName==="w:pPr"||v.appendChild(P);x.parentNode&&x.parentNode.removeChild(x);}}}if(e.comment&&p!==null){let g,v;if(k&&b)g=b,v=k;else {let N=w!==null?w:m;for(g=N,v=N;v&&v.tagName!=="w:p";)v=v.parentNode;}let x=p;for(;x&&x.tagName!=="w:p";)x=x.parentNode;if(!x||!v)return true;let E=y((N,P)=>{let D=N;for(;D.parentNode&&D.parentNode!==P;)D=D.parentNode;return D},"ascend_to_paragraph_child"),C=E(p,x),A=E(g,v);x===v?this._attach_comment(x,C,A,e.comment):this._attach_comment_spanning(x,C,v,A,e.comment);}for(let g of _)if(!this._paragraph_has_visible_content(g)){let x=M(g,"w:pPr");x||(x=g.ownerDocument.createElement("w:pPr"),g.insertBefore(x,g.firstChild));let E=M(x,"w:rPr");if(E||(E=g.ownerDocument.createElement("w:rPr"),x.appendChild(E)),!M(E,"w:del")){let C=this._create_track_change_tag("w:del");E.appendChild(C);}}return true}};function Z(t,e){let n=[],r=t.getElementsByTagName("*");for(let s=0;s<r.length;s++){let i=r[s].tagName;(i===e||i.endsWith(":"+e))&&n.push(r[s]);}return n}y(Z,"findDescendantsByLocalName");function Ro(t){let e=0;function n(o,a){let l=o?o.toString():"",u=a?a.toString():"";return l===u}y(n,"areRunsIdentical");function r(o){let a=["w:t","w:tab","w:br","w:cr","w:delText","w:rPr"];for(let l=0;l<o.childNodes.length;l++){let u=o.childNodes[l];if(u.nodeType===1){let c=u.tagName;if(!a.includes(c))return true}}return false}y(r,"hasSpecialContent");function s(o){let a=Array.from(o.childNodes).filter(u=>u.nodeType===1),l=0;for(;l<a.length-1;){let u=a[l],c=a[l+1];if(u.tagName==="w:r"&&c.tagName==="w:r"&&!r(u)&&!r(c)){let d=M(u,"w:rPr"),f=M(c,"w:rPr");if(n(d,f)){let h=null;for(let p=0;p<u.childNodes.length;p++){let m=u.childNodes[p];m.nodeType===1&&(m.tagName==="w:t"||m.tagName==="w:delText")&&(h=m);}let _=Array.from(c.childNodes).filter(p=>p.nodeType===1);for(let p of _)if(p.tagName!=="w:rPr")if((p.tagName==="w:t"||p.tagName==="w:delText")&&h&&h.tagName===p.tagName){let m=h.textContent||"",w=p.textContent||"",k=m+w;h.textContent=k,k.trim()!==k&&h.setAttribute("xml:space","preserve");}else u.appendChild(p),(p.tagName==="w:t"||p.tagName==="w:delText")&&(h=p);o.removeChild(c),a.splice(l+1,1),e++;continue}}["w:ins","w:del","w:hyperlink","w:sdt","w:smartTag","w:fldSimple","w:sdtContent"].includes(u.tagName)&&s(u),l++;}if(a.length>0){let u=a[a.length-1];["w:ins","w:del","w:hyperlink","w:sdt","w:smartTag","w:fldSimple","w:sdtContent"].includes(u.tagName)&&s(u);}}y(s,"coalesceContainer");let i=$(t.element,"w:p");for(let o of i)s(o);return e?[`Adjacent identical runs coalesced: ${e}`]:[]}y(Ro,"coalesce_runs");function jo(t){let e=0,n=["w:rsidR","w:rsidRPr","w:rsidRDefault","w:rsidP","w:rsidDel","w:rsidSect","w:rsidTr"],r=t.element.getElementsByTagName("*");for(let i=0;i<r.length;i++)for(let o of n)r[i].hasAttribute(o)&&(r[i].removeAttribute(o),e++);let s=$(t.element,"w:rsids");for(let i of s)i.parentNode&&(i.parentNode.removeChild(i),e++);return e?[`rsid attributes: ${e} removed`]:[]}y(jo,"strip_rsid");function Fo(t){let e=0,n=["w14:paraId","w14:textId"],r=t.element.getElementsByTagName("*");for(let s=0;s<r.length;s++)for(let i of n)r[s].hasAttribute(i)&&(r[s].removeAttribute(i),e++);return e?[`Paragraph/text IDs: ${e} removed`]:[]}y(Fo,"strip_para_ids");function Bo(t){let e=$(t.element,"w:proofErr");return e.forEach(n=>n.parentNode?.removeChild(n)),e.length?[`Spell check markers: ${e.length} removed`]:[]}y(Bo,"strip_proof_errors");function Wo(t){let e=0;for(let n of ["w:rPr","w:pPr"]){let r=$(t.element,n);for(let s of r)(s.childNodes.length===0||s.childNodes.length===1&&s.childNodes[0].nodeType===3&&!s.childNodes[0].textContent?.trim())&&(s.parentNode?.removeChild(s),e++);}return e?[`Empty property elements: ${e} removed`]:[]}y(Wo,"strip_empty_properties");function zo(t){let e=0,n=$(t.element,"w:rPr");for(let r of n)if(M(r,"w:vanish")||M(r,"w:webHidden")){let s=r.parentNode;s&&s.tagName==="w:r"&&s.parentNode&&(s.parentNode.removeChild(s),e++);}return e?[`Hidden text runs: ${e} removed`]:[]}y(zo,"strip_hidden_text");function sr(t){let e=$(t.element,"w:ins").length,n=$(t.element,"w:del").length,r=$(t.element,"w:rPrChange").length+$(t.element,"w:pPrChange").length+$(t.element,"w:sectPrChange").length;return [e,n,r]}y(sr,"count_tracked_changes");function Lo(t){let e=new Set;for(let n of ["w:ins","w:del","w:rPrChange","w:pPrChange","w:sectPrChange"])for(let r of $(t.element,n)){let s=r.getAttribute("w:author");s&&e.add(s);}return e}y(Lo,"get_track_change_authors");function or(t){let e=[],n=$(t,"w:t");for(let s of n)s.textContent&&e.push(s.textContent);let r=$(t,"w:delText");for(let s of r)s.textContent&&e.push(s.textContent);return e.join("")}y(or,"_getElementText");function Pe(t,e=60){let n=t.replace(/\n/g," ").trim();return n.length<=e?n:n.substring(0,e-3)+"..."}y(Pe,"_truncate");function ar(t){let e=t.parentNode;if(e&&e.tagName==="w:rPr"){let n=e.parentNode;if(n&&n.tagName==="w:pPr")return "(paragraph mark)"}return e&&e.tagName==="w:trPr"?"(table row)":"(no visible text)"}y(ar,"_describe_textless_revision");function Uo(t){let e=[],n=$(t.element,"w:ins"),r=$(t.element,"w:del");for(let o of n){let a=or(o).trim();a?e.push(` Accepted insertion: "${Pe(a,60)}"`):e.push(` Accepted insertion: ${ar(o)}`);}for(let o of r){let a=or(o).trim();a?e.push(` Accepted deletion of: "${Pe(a,60)}"`):e.push(` Accepted deletion of: ${ar(o)}`);}new _n(t).accept_all_revisions();for(let o of ["w:rPrChange","w:pPrChange","w:sectPrChange"])for(let a of $(t.element,o))a.parentNode?.removeChild(a);let i=n.length+r.length;return i?[`Tracked changes auto-accepted: ${i}`].concat(e):[]}y(Uo,"accept_all_tracked_changes");function _t(t){let e=Re(t.pkg),n=[],r=0,s=0;for(let[i,o]of Object.entries(e))o.resolved?s++:r++,n.push({id:i,...o});return {total:n.length,open:r,resolved:s,comments:n}}y(_t,"get_comments_summary");function qo(t){let e=Re(t.pkg),n=Object.keys(e);if(n.length===0)return [];let r=[],s=new nt(t);for(let[l,u]of Object.entries(e)){let c=u.resolved?"[Resolved]":"[Open]";r.push(` ${c} "${Pe(u.text||"",60)}" (${u.author||"Unknown"})`),s.deleteComment(l);}for(let l of ["w:commentRangeStart","w:commentRangeEnd"])for(let u of $(t.element,l))u.parentNode?.removeChild(u);let i=$(t.element,"w:commentReference");for(let l of i){let u=l.parentNode;u&&((u.tagName==="w:r"||u.tagName.endsWith(":r"))&&Array.from(u.childNodes).filter(d=>d.nodeType===1&&d.tagName!=="w:rPr"&&d.tagName!=="rPr").length<=1?u.parentNode?.removeChild(u):u.removeChild(l));}let o=Object.values(e).filter(l=>l.resolved).length,a=Object.values(e).filter(l=>!l.resolved).length;return [`Comments removed: ${n.length} (${o} resolved, ${a} open)`].concat(r)}y(qo,"remove_all_comments");function Jo(t){let e=t.pkg,n=new Set;for(let s of e.parts)if(s.partname.toLowerCase().includes("comments")){n.add(s.partname);let i=s.partname.startsWith("/")?s.partname:"/"+s.partname,o=s.partname.startsWith("/")?s.partname.substring(1):s.partname;n.add(i),n.add(o);}if(n.size===0)return;for(let s of e.parts)if(s.partname.endsWith(".rels")){let i=$(s._element,"Relationship"),o=[];for(let a of i)if((a.getAttribute("Target")||"").toLowerCase().includes("comments")){o.push(a);let u=s.partname.replace("/_rels/","/").replace(".rels",""),c=e.getPartByPath(u);if(c){let d=a.getAttribute("Id");d&&c.rels.delete(d);}}for(let a of o)a.parentNode?.removeChild(a);}let r=e.getPartByPath("[Content_Types].xml");if(r){let s=$(r._element,"Override"),i=[];for(let o of s){let a=o.getAttribute("PartName")||"";(n.has(a)||a.toLowerCase().includes("comments"))&&i.push(o);}for(let o of i)o.parentNode?.removeChild(o);}e.parts=e.parts.filter(s=>!s.partname.toLowerCase().includes("comments"));for(let s of Object.keys(e.unzipped))s.toLowerCase().includes("comments")&&delete e.unzipped[s];}y(Jo,"eject_comment_parts");function Ho(t,e){let n=new nt(t);if(!n.commentsPart)return [];let r=new Set,s=$(n.commentsPart._element,"w:comment");for(let i of s){let o=i.getAttribute("w:author");if(o&&(r.add(o),i.setAttribute("w:author",e)),i.hasAttribute("w:initials")){let a=e.split(" ").filter(Boolean).map(l=>l[0]).join("").toUpperCase();i.setAttribute("w:initials",a);}}return r.size?[`Comment authors replaced: ${Array.from(r).sort().join(", ")} \u2192 "${e}"`]:[]}y(Ho,"replace_comment_authors");function Xo(t,e){let n=new Set;for(let r of ["w:ins","w:del","w:rPrChange","w:pPrChange"])for(let s of $(t.element,r)){let i=s.getAttribute("w:author");i&&(n.add(i),s.setAttribute("w:author",e));}return n.size?[`Track change authors replaced: ${Array.from(n).sort().join(", ")} \u2192 "${e}"`]:[]}y(Xo,"replace_change_authors");function Qo(t){let e=0,n="2025-01-01T00:00:00Z";for(let r of ["w:ins","w:del","w:rPrChange","w:pPrChange"])for(let s of $(t.element,r))s.hasAttribute("w:date")&&(s.setAttribute("w:date",n),e++);return e?[`Track change timestamps: ${e} normalized`]:[]}y(Qo,"normalize_change_dates");function Yo(t){let e=0,n="2025-01-01T00:00:00Z";for(let r of t.pkg.parts)if(r.contentType.includes("comments")){for(let s of $(r._element,"w:comment"))s.hasAttribute("w:date")&&(s.setAttribute("w:date",n),e++);for(let s of $(r._element,"w16cex:commentExtensible"))s.hasAttribute("w16cex:dateUtc")&&(s.setAttribute("w16cex:dateUtc",n),e++);}return e?[`Comment timestamps: ${e} normalized`]:[]}y(Yo,"normalize_comment_dates");function Go(t){let e=[],n=t.pkg.getPartByPath("docProps/core.xml");if(n){Z(n._element,"creator").forEach(u=>{u.textContent&&(e.push(`Author: ${u.textContent}`),u.textContent="");}),Z(n._element,"lastModifiedBy").forEach(u=>{u.textContent&&(e.push(`Last modified by: ${u.textContent}`),u.textContent="");}),Z(n._element,"title").forEach(u=>{u.textContent&&e.push(`Title kept (review manually): "${u.textContent}"`);});let a=[["category","Category"],["keywords","Keywords"],["subject","Subject"],["contentStatus","Content status"],["description","Description/comments"],["identifier","Identifier"],["language","Language"],["version","Version"]];for(let[u,c]of a)Z(n._element,u).forEach(d=>{d.textContent&&(e.push(`${c}: ${d.textContent}`),d.textContent="");});Z(n._element,"revision").forEach(u=>{u.textContent&&parseInt(u.textContent)>1&&(e.push(`Revision count: ${u.textContent} \u2192 1`),u.textContent="1");});}let r=t.pkg.getPartByPath("docProps/app.xml");if(r){let s=r._element,i=["TotalTime","Words","Characters","Paragraphs","Lines","CharactersWithSpaces"];for(let a of i)Z(s,a).forEach(l=>{l.textContent&&l.textContent!=="0"&&(a==="TotalTime"&&e.push(`Total editing time: ${l.textContent} minutes`),l.textContent="0");});let o=["Template","Manager","Company"];for(let a of o)Z(s,a).forEach(l=>{l.textContent&&(e.push(`${a}: ${l.textContent}`),l.textContent="");});}return e.length?["Metadata scrubbed:",...e.map(s=>` ${s}`)]:[]}y(Go,"scrub_doc_properties");function Vo(t){let e=false,n="1970-01-01T00:00:00Z",r=t.pkg.getPartByPath("docProps/core.xml");if(r)for(let s of ["created","modified","lastPrinted"])Z(r._element,s).forEach(i=>{i.textContent&&i.textContent!==n&&(i.textContent=n,e=true);});return e?["Timestamps normalized to epoch"]:[]}y(Vo,"scrub_timestamps");function Yr(t,e,n){let r=t.pkg,s=y(o=>o.startsWith("/")?o.substring(1):o,"normalized");for(let o of r.parts){if(!o.partname.endsWith(".rels"))continue;let a=[];for(let l of $(o._element,"Relationship")){let u=l.getAttribute("Target")||"";if(n(u)){a.push(l);let c=o.partname.replace("/_rels/","/").replace(".rels",""),d=r.getPartByPath(c);if(d){let f=l.getAttribute("Id");f&&d.rels.delete(f);}}}a.forEach(l=>l.parentNode?.removeChild(l));}let i=r.getPartByPath("[Content_Types].xml");if(i){let o=[];for(let a of $(i._element,"Override")){let l=a.getAttribute("PartName")||"";e(s(l))&&o.push(a);}o.forEach(a=>a.parentNode?.removeChild(a));}r.parts=r.parts.filter(o=>!e(s(o.partname)));for(let o of Object.keys(r.unzipped))e(s(o))&&delete r.unzipped[o];}y(Yr,"ejectPackageMembers");function Zo(t){let e=y(s=>s.startsWith("customXml/"),"isCustomXml"),n=t.pkg.parts.filter(s=>e(s.partname.startsWith("/")?s.partname.substring(1):s.partname)),r=Object.keys(t.pkg.unzipped).filter(e);if(n.length===0&&r.length===0)return [];Yr(t,e,s=>s.includes("customXml"));for(let s of $(t.element,"w:sdtPr"))vr(s,"w:dataBinding").forEach(i=>s.removeChild(i));return [`Custom XML parts: ${Math.max(n.length,r.length)} removed`]}y(Zo,"strip_custom_xml");var Qt="docProps/custom.xml";function Ko(t){let e=t.pkg.getPartByPath(Qt),n=Object.keys(t.pkg.unzipped).includes(Qt);if(!e&&!n)return [];let r=[];if(e)for(let i of Z(e._element,"property")){let o=i.getAttribute("name")||"(unnamed)",a=(i.textContent||"").trim();r.push(` Custom property removed: ${o} = "${Pe(a,60)}"`);}return Yr(t,i=>i===Qt,i=>i.includes("docProps/custom.xml")),[`Custom document properties: ${Math.max(r.length,1)} removed (docProps/custom.xml)`].concat(r)}y(Ko,"strip_custom_properties");function ea(t){let e=t.pkg.getPartByPath("word/settings.xml");if(!e)return [];let n=[],r=false;for(let i of Z(e._element,"docVars")){for(let o of Array.from(i.childNodes)){let a=o,l=a.tagName||"";(l==="docVar"||l.endsWith(":docVar"))&&n.push(a.getAttribute("w:name")||a.getAttribute("name")||"(unnamed)");}i.parentNode?.removeChild(i),r=true;}for(let i of Z(e._element,"docVar"))n.push(i.getAttribute("w:name")||i.getAttribute("name")||"(unnamed)"),i.parentNode?.removeChild(i),r=true;if(!r)return [];let s=Array.from(new Set(n)).sort().join(", ")||"(unnamed)";return [`Document variables: ${n.length} removed (${s})`]}y(ea,"strip_document_variables");function ta(t){let e=0;for(let n of Z(t.element,"docPr")){let r=n.getAttribute("descr");if(r){let s=r.length<10,i=r.includes(".")&&r.length<60;(s||i)&&(n.removeAttribute("descr"),e++);}}return e?[`Image alt text: ${e} auto-generated descriptions removed`]:[]}y(ta,"strip_image_alt_text");function na(t){let e=[],n=new Set;for(let r of t.pkg.parts){let s=String(r.partname),i;if(s.startsWith("/word/header"))i="header";else if(s.startsWith("/word/footer"))i="footer";else if(s==="/word/document.xml")i="body";else continue;let o;try{o=Z(r._element,"textpath");}catch{continue}for(let a of o){let l=(a.getAttribute("string")||"").trim(),u=`${i}${l}`;if(n.has(u))continue;n.add(u);let c=l?`"${Pe(l,60)}"`:"(no text)";e.push(`Watermark-like text object in ${i}: ${c} \u2014 NOT removed. It remains in the document package and may render in other applications; review and remove it in Word if it must not reach the counterparty.`);}}return e}y(na,"detect_watermarks");function ra(t){let e=["sharepoint.com","onedrive.com",".internal","intranet","localhost","10.","192.168.","172.16."],n=[],r=t.pkg.getOrCreateRelsPart(t.part.partname);for(let s of $(r._element,"Relationship"))if(s.getAttribute("TargetMode")==="External"){let i=s.getAttribute("Target")||"";for(let o of e)if(i.toLowerCase().includes(o.toLowerCase())){n.push(`Hyperlink targets internal URL: ${Pe(i,80)}`);break}}return n}y(ra,"audit_hyperlinks");function ia(t,e,n=2){if(t===e)return 0;if(Math.abs(t.length-e.length)>n)return n+1;if(t.length===0)return e.length<=n?e.length:n+1;if(e.length===0)return t.length<=n?t.length:n+1;if(t.length>e.length){let s=t;t=e,e=s;}let r=Array.from({length:t.length+1},(s,i)=>i);for(let s=1;s<=e.length;s++){let i=[s],o=s;for(let a=1;a<=t.length;a++){let l=t[a-1]===e[s-1]?0:1,u=Math.min(r[a]+1,i[a-1]+1,r[a-1]+l);i.push(u),u<o&&(o=u);}if(o>n)return n+1;r=i;}return r[t.length]<=n?r[t.length]:n+1}y(ia,"boundedLevenshtein");function sa(t){let e="",n=$(t._element,"w:r");for(let r of n)e+=De(new Ae(r,t));return e}y(sa,"_get_paragraph_text");var mn="[A-Z][A-Za-z0-9\\s\\-&'\u2019]{1,60}",oa=new RegExp(`^(?:[\\d.\\-()a-zA-Z]+\\s*)?["\u201C](${mn})["\u201D]`,"d"),aa=new RegExp(`(?<=[.;:!?])\\s+(?:[\\d.\\-()a-zA-Z]+\\s+)?["\u201C](${mn})["\u201D]`,"dg"),la=new RegExp(`\\([^)]*?["\u201C](${mn})["\u201D][^)]*?\\)`,"dg");function ca(t){let e=[],n=oa.exec(t);n&&n.indices&&n.indices[1]&&e.push([n.indices[1][0],n[1].trim()]);for(let i of t.matchAll(aa)){let o=i.indices;o&&o[1]&&e.push([o[1][0],i[1].trim()]);}for(let i of t.matchAll(la)){let o=i.indices;o&&o[1]&&e.push([o[1][0],i[1].trim()]);}let r=[],s=new Set;e.sort((i,o)=>i[0]-o[0]);for(let[i,o]of e)s.has(i)||(s.add(i),r.push(o));return r}y(ca,"extract_terms_from_paragraph");function ua(t,e){let n={},r=new Set,s={},i=[];for(let p of Ie(t)){if(!(p instanceof re))continue;let m=sa(p).trim();if(!m)continue;for(let b of ca(m))n[b]?r.add(b):n[b]={count:0};let w=m.length>60?m.substring(0,60)+"...":m,k=$(p._element,"*");for(let b of k){if(b.tagName==="w:bookmarkStart"){let v=b.getAttribute("w:name");v&&(!v.startsWith("_")||v.startsWith("_Ref"))&&(s[v]||(s[v]={anchored_to:w,referenced_from:[]}));}let g=null;if(b.tagName==="w:fldSimple"){let x=(b.getAttribute("w:instr")||"").trim().split(/\s+/);x.length>1&&x[0]==="REF"&&(g=x[1]);}else if(b.tagName==="w:instrText"){let x=(b.textContent||"").trim().split(/\s+/);x.length>1&&x[0]==="REF"&&(g=x[1]);}g&&i.push([g,w]);}}for(let[p,m]of i)s[p]&&s[p].referenced_from.push(m);let o=[],a=Object.keys(n);if(a.length>0){let p=a.sort((b,g)=>g.length-b.length),m=y(b=>b.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"escapeRegExp"),w=p.map(m).join("|"),k=new RegExp(`(?<!["\u201C])\\b(${w})\\b(?![\u201D"])`,"g");for(let b of e.matchAll(k)){let g=b[1];n[g]&&n[g].count++;}for(let b of a)n[b].count===0&&(delete n[b],r.has(b)||o.push(`[Warning] Unused Definition: '${b}' is defined but never used.`));}for(let p of r)o.push(`[Error] Duplicate Definition: '${p}' is defined multiple times.`);let l=new Set(["The","This","That","Such","A","An","Any","All","Some","No","Every","Each","As","In","Of","For","To","On","By","With"]),u=/\b[A-Z][a-zA-Z]*(?:\s+[A-Z][a-zA-Z]*)*\b/g,c=new Set(e.match(u)||[]),d=new Set(Object.keys(n)),f={};for(let p of d){let m=p[0].toLowerCase();f[m]||(f[m]=[]),f[m].push(p);}let h={};for(let p of c){let m=p.trim(),w=m.split(/\s+/);for(;w.length>0;){let g=w[0],v=g.charAt(0).toUpperCase()+g.slice(1).toLowerCase();if(l.has(v))w.shift();else break}if(m=w.join(" "),m.length<4||d.has(m))continue;let k=m[0].toLowerCase(),b=f[k]||[];if(m.length>5)for(let[g,v]of Object.entries(f))g!==k&&(b=b.concat(v));for(let g of b){if(Math.abs(m.length-g.length)>2||m===g+"s"||m===g+"es"||g===m+"s"||g===m+"es")continue;let v=ia(m,g,2);v===0||v>2||g.length<=5&&(v>1||m[0].toLowerCase()!==g[0].toLowerCase())||(h[g]||(h[g]=[]),h[g].includes(m)||h[g].push(m));}}for(let[p,m]of Object.entries(h)){m.sort();let w=m.map(k=>`'${k}'`).join(", ");o.push(`[Info] Possible Typos for '${p}': Found ${w}`);}function _(p){return p.startsWith("[Error]")?0:p.startsWith("[Warning]")?1:2}return y(_,"diag_sort_key"),o.sort((p,m)=>{let w=_(p),k=_(m);return w!==k?w-k:p.localeCompare(m)}),[n,o,s]}y(ua,"extract_all_domain_metadata");function da(t){let e=[],n=t.pkg.getPartByPath("word/settings.xml");if(!n)return e;let r=y(o=>{if(!o.hasAttribute("w:val"))return true;let a=(o.getAttribute("w:val")||"").toLowerCase();return a!=="0"&&a!=="false"&&a!=="off"},"isTruthy"),s=Z(n._element,"removePersonalInformation");s.length>0&&r(s[0])&&e.push("[Warning] Privacy flag `removePersonalInformation` is enabled in word/settings.xml. Microsoft Word will strip the `w:author`, `w:initials`, and `w:date` attributes from every tracked change and comment the next time this document is opened and saved. Edits made by this agent will lose attribution, breaking audit trails and any multi-turn workflow that relies on identifying prior edits.");let i=Z(n._element,"removeDateAndTime");return i.length>0&&r(i[0])&&e.push("[Warning] Privacy flag `removeDateAndTime` is enabled in word/settings.xml. Microsoft Word will strip the `w:date` attribute from every tracked change and comment the next time this document is opened and saved. Timestamps on this agent's edits will be lost on the next Word save."),e}y(da,"extract_document_settings_warnings");function fa(t,e){let[n,r,s]=ua(t,e),i=da(t),o=[`
124
124
 
125
- ---`,"","<!-- READONLY_BOUNDARY_START -->","# Document Structure (Read-Only)","The content below is metadata describing the document's reference structure. Do not include this section in any tracked changes or edits \u2014 it is for your context only and will be discarded on write."],l=false;if(i.length>0){l=true,o.push(`
126
- ## Document Settings`);for(let a of i)o.push(`- ${a}`);}if(Object.keys(n).length>0){l=true,o.push(`
127
- ## Defined Terms`);for(let[a,u]of Object.entries(n))o.push(`- "${a}" \u2014 used ${u.count} time${u.count===1?"":"s"}.`);}if(r.length>0){l=true,o.push(`
128
- ## Semantic Diagnostics`);for(let a of r)o.push(`- ${a}`);}if(Object.keys(s).length>0){l=true,o.push(`
129
- ## Named Anchors`);for(let[a,u]of Object.entries(s)){o.push(`- ${a} \u2192 Anchored to: "${u.anchored_to}"`);for(let c of u.referenced_from)o.push(` - Referenced from: "${c}"`);}}return l?o.join(`
130
- `):""}y(ia,"build_structural_appendix");async function Re(t,e=false,n=true){let r=await pe.load(t);return Qe(r,e,n)}y(Re,"extractTextFromBuffer");function Qe(t,e=false,n=true,r=false,s=false){let i=Xe(t.pkg),o=[],l=new Map,a=s?{part_ranges:[],tables:[]}:null,u=0;for(let[d,f]of un(t)){let h=o.length>0?u+2:u,p=pn(d,i,e,h,r?l:void 0,a?a.tables:void 0);p&&(o.length>0&&(u+=2),o.push(p),a&&a.part_ranges.push([u,u+p.length,f]),u+=p.length);}let c=o.join(`
125
+ ---`,"","<!-- READONLY_BOUNDARY_START -->","# Document Structure (Read-Only)","The content below is metadata describing the document's reference structure. Do not include this section in any tracked changes or edits \u2014 it is for your context only and will be discarded on write."],a=false;if(i.length>0){a=true,o.push(`
126
+ ## Document Settings`);for(let l of i)o.push(`- ${l}`);}if(Object.keys(n).length>0){a=true,o.push(`
127
+ ## Defined Terms`);for(let[l,u]of Object.entries(n))o.push(`- "${l}" \u2014 used ${u.count} time${u.count===1?"":"s"}.`);}if(r.length>0){a=true,o.push(`
128
+ ## Semantic Diagnostics`);for(let l of r)o.push(`- ${l}`);}if(Object.keys(s).length>0){a=true,o.push(`
129
+ ## Named Anchors`);for(let[l,u]of Object.entries(s)){o.push(`- ${l} \u2192 Anchored to: "${u.anchored_to}"`);for(let c of u.referenced_from)o.push(` - Referenced from: "${c}"`);}}return a?o.join(`
130
+ `):""}y(fa,"build_structural_appendix");async function je(t,e=false,n=true){let r=await pe.load(t);return Qe(r,e,n)}y(je,"extractTextFromBuffer");function Qe(t,e=false,n=true,r=false,s=false){let i=Re(t.pkg),o=[],a=new Map,l=s?{part_ranges:[],tables:[]}:null,u=0;for(let[d,f]of hn(t)){let h=o.length>0?u+2:u,_=gn(d,i,e,h,r?a:void 0,l?l.tables:void 0);_&&(o.length>0&&(u+=2),o.push(_),l&&l.part_ranges.push([u,u+_.length,f]),u+=_.length);}let c=o.join(`
131
131
 
132
- `);if(n){let d=ia(t,c);d&&(c+=d);}return r?{text:c,paragraph_offsets:l}:a?{text:c,structure:a}:c}y(Qe,"_extractTextFromDoc");function pn(t,e,n,r,s,i){let o=t.part||t,[l,a]=st(o),u=[],c=r,d=true,f=true;if(t.constructor&&t.constructor.name==="NotesPart"){let p=`---
133
- ${t.note_type==="fn"?"## Footnotes":"## Endnotes"}`;u.push(p),c+=p.length,d=false;}for(let h of Ie(t)){d||(c+=2);let p=c;if(h.constructor.name==="FootnoteItem"){let _=pn(h,e,n,p,s);_?(u.push(_),c=p+_.length,d=false):d||(c-=2);}else if(h instanceof re){let _=Se(h,l,a);f&&t.constructor.name==="FootnoteItem"&&(_=`[^${t.note_type}-${t.id}]: `+_);let g=ot(h,e,n,l,a),w=_+g;u.push(w),s&&s.set(h._element,[p,w.length]),c=p+w.length,f=false,d=false;}else if(h instanceof Te){let _=i?{start:p,end:p,rows:[]}:null,g=kt(h,e,n,p,s,_);g?(u.push(g),c=p+g.length,d=false,_&&i&&(_.end=p+g.length,i.push(_))):d||(c-=2),f=false;}}return u.join(`
132
+ `);if(n){let d=fa(t,c);d&&(c+=d);}return r?{text:c,paragraph_offsets:a}:l?{text:c,structure:l}:c}y(Qe,"_extractTextFromDoc");function gn(t,e,n,r,s,i){let o=t.part||t,[a,l]=st(o),u=[],c=r,d=true,f=true;if(t.constructor&&t.constructor.name==="NotesPart"){let _=`---
133
+ ${t.note_type==="fn"?"## Footnotes":"## Endnotes"}`;u.push(_),c+=_.length,d=false;}for(let h of Ie(t)){d||(c+=2);let _=c;if(h.constructor.name==="FootnoteItem"){let p=gn(h,e,n,_,s);p?(u.push(p),c=_+p.length,d=false):d||(c-=2);}else if(h instanceof re){let p=Se(h,a,l);f&&t.constructor.name==="FootnoteItem"&&(p=`[^${t.note_type}-${t.id}]: `+p);let m=ot(h,e,n,a,l),w=p+m;u.push(w),s&&s.set(h._element,[_,w.length]),c=_+w.length,f=false,d=false;}else if(h instanceof Te){let p=i?{start:_,end:_,rows:[]}:null,m=kt(h,e,n,_,s,p);m?(u.push(m),c=_+m.length,d=false,p&&i&&(p.end=_+m.length,i.push(p))):d||(c-=2),f=false;}}return u.join(`
134
134
 
135
- `)}y(pn,"_extract_blocks");function kt(t,e,n,r,s,i){let o=[],l=0,a=r;for(let u of t.rows){let c=[],d=new Set,f=M(u._element,"w:trPr"),h=f?M(f,"w:ins"):null,p=f?M(f,"w:del"):null;if(n&&p)continue;let _=a+(l>0?1:0),w=_+(!n&&h||!n&&p?4:0),k=true;for(let m of u.cells){if(d.has(m))continue;d.add(m),k||(w+=3);let v=pn(m,e,n,w,s);if(!n){let{paraId:N}=vr(m._element,!v||v.trim()==="");if(N){let C=`${v?" ":""}{#cell:${N}}`;v=v+C;}}c.push(v),w+=v.length,k=false;}let b=c.join(" | ");if(n||(h?b=`{++ ${b} ++}{>>[Chg:${h.getAttribute("w:id")} insert] ${h.getAttribute("w:author")||"Unknown"}<<}`:p&&(b=`{-- ${b} --}{>>[Chg:${p.getAttribute("w:id")} delete] ${p.getAttribute("w:author")||"Unknown"}<<}`)),o.push(b),a=_+b.length,i&&i.rows.push({start:_,end:a,cells:[...c]}),l++,l===1){let m=c.length;if(m>0){let v=Array(m).fill("---").join(" | ");o.push(v),a+=1+v.length;}}}return o.join(`
136
- `)}y(kt,"extract_table");function ot(t,e,n,r,s){let i=[],o={},l={},a=new Set,u={},c=[],d="",f=["",""],h=["",""],p=Array.from(Nt(t)),_=Or(t,r,s),g=cn(t,r,s),w=_;for(let k=0;k<p.length;k++){let b=p[k];if(b instanceof Ae){let[m,v]=Dr(b,g),N=De(b);if(n&&Object.keys(l).length>0)continue;if(w){if(!N||!N.trim())continue;w=false;}let A=eo(N,m,v);if(A){let C=n?["",""]:sa(o,l,a,u),x=[m,v];if(d&&C[0]===f[0]&&C[1]===f[1]){let E=x[0].replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),T=x[0]!==""||x[1]!==""?A.match(new RegExp("^(\\s*)"+E)):null;x[0]===h[0]&&x[1]===h[1]&&h[0]!==""&&d.endsWith(h[1])&&T!==null?d=d.slice(0,-h[1].length)+T[1]+A.slice(T[0].length):d+=A,h=x;}else d&&i.push(`${f[0]}${d}${f[1]}`),d=A,f=C,h=x;if(!n){(Object.keys(o).length>0||Object.keys(l).length>0||a.size>0||Object.keys(u).length>0)&&c.push([{...o},{...l},new Set(a),{...u}]);let T=false;if(Object.keys(o).length>0||Object.keys(l).length>0||Object.keys(u).length>0||a.size>0){let P=k+1,R=false,$=Object.keys(o).length,S=Object.keys(l).length,j=Object.keys(u).length,F=new Set(a);for(;P<p.length;){let B=p[P];if(B instanceof Ae){if(!De(B)){P++;continue}($>0||S>0||j>0||F.size>0)&&(R=true);break}else {let L=B;L.type==="ins_start"?$++:L.type==="ins_end"?$=Math.max(0,$-1):L.type==="del_start"?S++:L.type==="del_end"?S=Math.max(0,S-1):L.type==="fmt_start"?j++:L.type==="fmt_end"?j=Math.max(0,j-1):L.type==="start"?F.add(L.id):L.type==="end"&&F.delete(L.id);}P++;}R&&(T=true);}if(!T&&c.length>0){let P=or(c,e);P&&(d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),i.push(`{>>${P}<<}`)),c.length=0;}}}}else {let m=b;if(w=false,["ins_start","ins_end","del_start","del_end","fmt_start","fmt_end"].includes(m.type)||d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),m.type==="start")a.add(m.id);else if(m.type==="end")a.delete(m.id);else if(m.type==="ins_start")o[m.id]=m;else if(m.type==="ins_end")delete o[m.id];else if(m.type==="del_start")l[m.id]=m;else if(m.type==="del_end")delete l[m.id];else if(m.type==="fmt_start")u[m.id]=m;else if(m.type==="fmt_end")delete u[m.id];else if(m.type==="image"){if(!(n&&Object.keys(l).length>0)){let v=(m.date||"image").replace(/\]/g,")").replace(/\n/g," ");i.push(`![${v}](docx-image:${m.id})`);}}else m.type==="footnote"||m.type==="endnote"?(d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),i.push(`[^${m.type==="footnote"?"fn":"en"}-${m.id}]`)):m.type==="hyperlink_start"?(d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),i.push("[")):m.type==="hyperlink_end"?(d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),i.push(`](${m.date})`)):m.type==="xref_start"?(d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),i.push("[~")):m.type==="xref_end"?(d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),i.push(`~](#${m.id})`)):m.type==="bookmark"&&(d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),i.push(`{#${m.id}}`));}}if(d&&i.push(`${f[0]}${d}${f[1]}`),c.length>0){let k=or(c,e);k&&i.push(`{>>${k}<<}`);}return i.join("")}y(ot,"build_paragraph_text");function sa(t,e,n,r){return Object.keys(e).length>0?["{--","--}"]:Object.keys(t).length>0?["{++","++}"]:n.size>0||Object.keys(r).length>0?["{==","==}"]:["",""]}y(sa,"_get_wrappers");function or(t,e){let n=[],r=[],s=new Set,i=Rr(t),o=y(a=>i[a]?` (pairs with ${i[a]})`:"","pairSuffix");for(let[a,u,c,d]of t){let f=y(function(_){if(!e[_])return;let g=`Com:${_}`;if(s.has(g))return;let w=e[_],k=`[${g}] ${w.author}`;if(w.date&&(k+=` @ ${w.date}`),w.resolved&&(k+="(RESOLVED)"),r.push(`${k}: ${Nr(w.text)}`),s.add(g),h[_]){let b=h[_].sort((m,v)=>(e[m]?.date||"").localeCompare(e[v]?.date||""));for(let m of b)f(m);}},"render_comment2");for(let[_,g]of Object.entries(a)){let w=`Chg:${_}`;s.has(w)||(n.push(`[${w} insert] ${g.author||"Unknown"}${o(_)}`),s.add(w));}for(let[_,g]of Object.entries(u)){let w=`Chg:${_}`;s.has(w)||(n.push(`[${w} delete] ${g.author||"Unknown"}${o(_)}`),s.add(w));}for(let[_,g]of Object.entries(d)){let w=`Chg:${_}`;s.has(w)||(n.push(`[${w} format] ${g.author||"Unknown"}`),s.add(w));}let h={};for(let[_,g]of Object.entries(e)){let w=g.parent_id;w&&(h[w]||(h[w]=[]),h[w].push(_));}let p=Array.from(c).sort();for(let _ of p)f(_);}return [...n,...r].join(`
137
- `)}y(or,"_build_merged_meta_block");var Hr=/^(#{1,6}) /,Xr=3;function Qr(t,e,n,r,s=null){if(n.length!==r.length)throw new Error("body_pages and body_page_offsets length mismatch");if(s)return ha(t,e,r,s);let i=Xe(t.pkg),o=aa(t,i),l=[];for(let u=0;u<o.length;u++){let c=o[u];c.is_paragraph&&rt(c.item)&&ua(c.item,i)&&l.push(u);}if(l.length===0)return [];let a=[];for(let u=0;u<l.length;u++){let c=l[u],d=o[c],f=d.item,h=vt(f),p=Kr(f,i),_=Et(f),g=da(o,l,u,h),w=o.slice(c+1,g),k=oa(o,c+1,g),b=fa(w),m=ri(d.start_offset,r);a.push({level:h,text:p,page:m,style:_,has_table:k,footnote_ids:b});}return a}y(Qr,"extract_outline");function oa(t,e,n){for(let r=e;r<n;r++){let s=t[r];if(s.is_paragraph&&rt(s.item))return false;if(s.is_table)return true}return false}y(oa,"_direct_has_table");function aa(t,e){let n=Array.from(to(t)),r=0,s=null;for(let a of n){if(a===t){s=a;break}let u=Vr(a,e);u&&(r>0&&(r+=2),r+=u.length);}s?r>0&&(r+=2):(s=t,r=0);let i=[],o=r,l=true;for(let a of Ie(s))if(a instanceof re){let u=Se(a),c=ot(a,e,false),d=(u+c).length;l||(o+=2),i.push({item:a,is_paragraph:true,is_table:false,start_offset:o,projected_length:d}),o+=d,l=false;}else if(a instanceof Te){let u=kt(a,e,false,0),c=u?u.length:0;l||(o+=2);let d=o;i.push({item:a,is_paragraph:false,is_table:true,start_offset:d,projected_length:c}),Gr(a,d,i,e),o+=c,l=false;}return i}y(aa,"_walk_doc_body");function Yr(t,e,n,r){let s=e._element,i=n,o=0;for(let l of t.rows){if(o>0)if(o===1){let c=t.rows[0],d=new Set,f=0;for(let p of c.cells)d.has(p)||(d.add(p),f+=1);let h=f>0?Array(f).fill("---").join(" | ").length:0;i+=1+h+1;}else i+=1;let a=new Set,u=0;for(let c of l.cells){if(a.has(c))continue;a.add(c),u>0&&(i+=3);let[d,f]=la(c,s,i,r);if(f)return d;i=d,u++;}o++;}return n}y(Yr,"_compute_inner_block_offset");function la(t,e,n,r){let s=n,i=true;for(let o of Ie(t)){if(i||(s+=2),o instanceof re){if(o._element===e)return [s,true];let l=Se(o),a=ot(o,r,false);s+=(l+a).length;}else if(o instanceof Te){let l=Yr(o,new re(e,null),s,r);if(l!==s&&ca(e,o._element))return [l,true];let a=kt(o,r,false,0);s+=a?a.length:0;}i=false;}return [s,false]}y(la,"_walk_cell_for_offset");function ca(t,e){let n=t.parentNode;for(;n;){if(n===e)return true;n=n.parentNode;}return false}y(ca,"_element_is_descendant");function Gr(t,e,n,r){let s=new Set;for(let i of t.rows)for(let o of i.cells)if(!s.has(o)){s.add(o);for(let l of Ie(o))if(l instanceof re){let a=rt(l)?Yr(t,l,e,r):e;n.push({item:l,is_paragraph:true,is_table:false,start_offset:a,projected_length:0});}else l instanceof Te&&(n.push({item:l,is_paragraph:false,is_table:true,start_offset:e,projected_length:0}),Gr(l,e,n,r));}}y(Gr,"_record_table_inner_blocks_lite");function Vr(t,e){let n=[],r=t.constructor.name;if(r==="NotesPart"){let i=t.note_type==="fn"?"## Footnotes":"## Endnotes";n.push(`---
138
- ${i}`);}let s=true;for(let i of Ie(t))if(i.constructor.name==="FootnoteItem"){let o=Vr(i,e);o&&n.push(o);}else if(i instanceof re){let o=Se(i);s&&r==="FootnoteItem"&&(o=`[^${t.note_type}-${t.id}]: ${o}`);let l=ot(i,e,false);n.push(o+l),s=false;}else if(i instanceof Te){let o=kt(i,e,false,0);o&&n.push(o),s=false;}return n.join(`
135
+ `)}y(gn,"_extract_blocks");function kt(t,e,n,r,s,i){let o=[],a=0,l=r;for(let u of t.rows){let c=[],d=new Set,f=M(u._element,"w:trPr"),h=f?M(f,"w:ins"):null,_=f?M(f,"w:del"):null;if(n&&_)continue;let p=l+(a>0?1:0),w=p+(!n&&h||!n&&_?4:0),k=true;for(let g of u.cells){if(d.has(g))continue;d.add(g),k||(w+=3);let v=gn(g,e,n,w,s);if(!n){let{paraId:x}=xr(g._element,!v||v.trim()==="");if(x){let C=`${v?" ":""}{#cell:${x}}`;v=v+C;}}c.push(v),w+=v.length,k=false;}let b=c.join(" | ");if(n||(h?b=`{++ ${b} ++}{>>[Chg:${h.getAttribute("w:id")} insert] ${h.getAttribute("w:author")||"Unknown"}<<}`:_&&(b=`{-- ${b} --}{>>[Chg:${_.getAttribute("w:id")} delete] ${_.getAttribute("w:author")||"Unknown"}<<}`)),o.push(b),l=p+b.length,i&&i.rows.push({start:p,end:l,cells:[...c]}),a++,a===1){let g=c.length;if(g>0){let v=Array(g).fill("---").join(" | ");o.push(v),l+=1+v.length;}}}return o.join(`
136
+ `)}y(kt,"extract_table");function ot(t,e,n,r,s){let i=[],o={},a={},l=new Set,u={},c=[],d="",f=["",""],h=["",""],_=Array.from(Nt(t)),p=jr(t,r,s),m=fn(t,r,s),w=p;for(let k=0;k<_.length;k++){let b=_[k];if(b instanceof Ae){let[g,v]=Fr(b,m),x=De(b);if(n&&Object.keys(a).length>0)continue;if(w){if(!x||!x.trim())continue;w=false;}let E=lo(x,g,v);if(E){let C=n?["",""]:ha(o,a,l,u),A=[g,v];if(d&&C[0]===f[0]&&C[1]===f[1]){let N=A[0].replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),P=A[0]!==""||A[1]!==""?E.match(new RegExp("^(\\s*)"+N)):null;A[0]===h[0]&&A[1]===h[1]&&h[0]!==""&&d.endsWith(h[1])&&P!==null?d=d.slice(0,-h[1].length)+P[1]+E.slice(P[0].length):d+=E,h=A;}else d&&i.push(`${f[0]}${d}${f[1]}`),d=E,f=C,h=A;if(!n){(Object.keys(o).length>0||Object.keys(a).length>0||l.size>0||Object.keys(u).length>0)&&c.push([{...o},{...a},new Set(l),{...u}]);let P=false;if(Object.keys(o).length>0||Object.keys(a).length>0||Object.keys(u).length>0||l.size>0){let T=k+1,F=false,I=Object.keys(o).length,S=Object.keys(a).length,R=Object.keys(u).length,j=new Set(l);for(;T<_.length;){let B=_[T];if(B instanceof Ae){if(!De(B)){T++;continue}(I>0||S>0||R>0||j.size>0)&&(F=true);break}else {let L=B;L.type==="ins_start"?I++:L.type==="ins_end"?I=Math.max(0,I-1):L.type==="del_start"?S++:L.type==="del_end"?S=Math.max(0,S-1):L.type==="fmt_start"?R++:L.type==="fmt_end"?R=Math.max(0,R-1):L.type==="start"?j.add(L.id):L.type==="end"&&j.delete(L.id);}T++;}F&&(P=true);}if(!P&&c.length>0){let T=lr(c,e);T&&(d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),i.push(`{>>${T}<<}`)),c.length=0;}}}}else {let g=b;if(w=false,["ins_start","ins_end","del_start","del_end","fmt_start","fmt_end"].includes(g.type)||d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),g.type==="start")l.add(g.id);else if(g.type==="end")l.delete(g.id);else if(g.type==="ins_start")o[g.id]=g;else if(g.type==="ins_end")delete o[g.id];else if(g.type==="del_start")a[g.id]=g;else if(g.type==="del_end")delete a[g.id];else if(g.type==="fmt_start")u[g.id]=g;else if(g.type==="fmt_end")delete u[g.id];else if(g.type==="image"){if(!(n&&Object.keys(a).length>0)){let v=(g.date||"image").replace(/\]/g,")").replace(/\n/g," ");i.push(`![${v}](docx-image:${g.id})`);}}else g.type==="footnote"||g.type==="endnote"?(d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),i.push(`[^${g.type==="footnote"?"fn":"en"}-${g.id}]`)):g.type==="hyperlink_start"?(d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),i.push("[")):g.type==="hyperlink_end"?(d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),i.push(`](${g.date})`)):g.type==="xref_start"?(d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),i.push("[~")):g.type==="xref_end"?(d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),i.push(`~](#${g.id})`)):g.type==="bookmark"&&(d&&(i.push(`${f[0]}${d}${f[1]}`),d="",f=["",""],h=["",""]),i.push(`{#${g.id}}`));}}if(d&&i.push(`${f[0]}${d}${f[1]}`),c.length>0){let k=lr(c,e);k&&i.push(`{>>${k}<<}`);}return i.join("")}y(ot,"build_paragraph_text");function ha(t,e,n,r){return Object.keys(e).length>0?["{--","--}"]:Object.keys(t).length>0?["{++","++}"]:n.size>0||Object.keys(r).length>0?["{==","==}"]:["",""]}y(ha,"_get_wrappers");function lr(t,e){let n=[],r=[],s=new Set,i=Wr(t),o=y(l=>i[l]?` (pairs with ${i[l]})`:"","pairSuffix");for(let[l,u,c,d]of t){let f=y(function(p){if(!e[p])return;let m=`Com:${p}`;if(s.has(m))return;let w=e[p],k=`[${m}] ${w.author}`;if(w.date&&(k+=` @ ${w.date}`),w.resolved&&(k+="(RESOLVED)"),r.push(`${k}: ${Cr(w.text)}`),s.add(m),h[p]){let b=h[p].sort((g,v)=>(e[g]?.date||"").localeCompare(e[v]?.date||""));for(let g of b)f(g);}},"render_comment2");for(let[p,m]of Object.entries(l)){let w=`Chg:${p}`;s.has(w)||(n.push(`[${w} insert] ${m.author||"Unknown"}${o(p)}`),s.add(w));}for(let[p,m]of Object.entries(u)){let w=`Chg:${p}`;s.has(w)||(n.push(`[${w} delete] ${m.author||"Unknown"}${o(p)}`),s.add(w));}for(let[p,m]of Object.entries(d)){let w=`Chg:${p}`;s.has(w)||(n.push(`[${w} format] ${m.author||"Unknown"}`),s.add(w));}let h={};for(let[p,m]of Object.entries(e)){let w=m.parent_id;w&&(h[w]||(h[w]=[]),h[w].push(p));}let _=Array.from(c).sort();for(let p of _)f(p);}return [...n,...r].join(`
137
+ `)}y(lr,"_build_merged_meta_block");var Gr=/^(#{1,6}) /,Vr=3;function Zr(t,e,n,r,s=null){if(n.length!==r.length)throw new Error("body_pages and body_page_offsets length mismatch");if(s)return ba(t,e,r,s);let i=Re(t.pkg),o=_a(t,i),a=[];for(let u=0;u<o.length;u++){let c=o[u];c.is_paragraph&&rt(c.item)&&wa(c.item,i)&&a.push(u);}if(a.length===0)return [];let l=[];for(let u=0;u<a.length;u++){let c=a[u],d=o[c],f=d.item,h=vt(f),_=ri(f,i),p=Et(f),m=ya(o,a,u,h),w=o.slice(c+1,m),k=pa(o,c+1,m),b=va(w),g=ai(d.start_offset,r);l.push({level:h,text:_,page:g,style:p,has_table:k,footnote_ids:b});}return l}y(Zr,"extract_outline");function pa(t,e,n){for(let r=e;r<n;r++){let s=t[r];if(s.is_paragraph&&rt(s.item))return false;if(s.is_table)return true}return false}y(pa,"_direct_has_table");function _a(t,e){let n=Array.from(co(t)),r=0,s=null;for(let l of n){if(l===t){s=l;break}let u=ti(l,e);u&&(r>0&&(r+=2),r+=u.length);}s?r>0&&(r+=2):(s=t,r=0);let i=[],o=r,a=true;for(let l of Ie(s))if(l instanceof re){let u=Se(l),c=ot(l,e,false),d=(u+c).length;a||(o+=2),i.push({item:l,is_paragraph:true,is_table:false,start_offset:o,projected_length:d}),o+=d,a=false;}else if(l instanceof Te){let u=kt(l,e,false,0),c=u?u.length:0;a||(o+=2);let d=o;i.push({item:l,is_paragraph:false,is_table:true,start_offset:d,projected_length:c}),ei(l,d,i,e),o+=c,a=false;}return i}y(_a,"_walk_doc_body");function Kr(t,e,n,r){let s=e._element,i=n,o=0;for(let a of t.rows){if(o>0)if(o===1){let c=t.rows[0],d=new Set,f=0;for(let _ of c.cells)d.has(_)||(d.add(_),f+=1);let h=f>0?Array(f).fill("---").join(" | ").length:0;i+=1+h+1;}else i+=1;let l=new Set,u=0;for(let c of a.cells){if(l.has(c))continue;l.add(c),u>0&&(i+=3);let[d,f]=ma(c,s,i,r);if(f)return d;i=d,u++;}o++;}return n}y(Kr,"_compute_inner_block_offset");function ma(t,e,n,r){let s=n,i=true;for(let o of Ie(t)){if(i||(s+=2),o instanceof re){if(o._element===e)return [s,true];let a=Se(o),l=ot(o,r,false);s+=(a+l).length;}else if(o instanceof Te){let a=Kr(o,new re(e,null),s,r);if(a!==s&&ga(e,o._element))return [a,true];let l=kt(o,r,false,0);s+=l?l.length:0;}i=false;}return [s,false]}y(ma,"_walk_cell_for_offset");function ga(t,e){let n=t.parentNode;for(;n;){if(n===e)return true;n=n.parentNode;}return false}y(ga,"_element_is_descendant");function ei(t,e,n,r){let s=new Set;for(let i of t.rows)for(let o of i.cells)if(!s.has(o)){s.add(o);for(let a of Ie(o))if(a instanceof re){let l=rt(a)?Kr(t,a,e,r):e;n.push({item:a,is_paragraph:true,is_table:false,start_offset:l,projected_length:0});}else a instanceof Te&&(n.push({item:a,is_paragraph:false,is_table:true,start_offset:e,projected_length:0}),ei(a,e,n,r));}}y(ei,"_record_table_inner_blocks_lite");function ti(t,e){let n=[],r=t.constructor.name;if(r==="NotesPart"){let i=t.note_type==="fn"?"## Footnotes":"## Endnotes";n.push(`---
138
+ ${i}`);}let s=true;for(let i of Ie(t))if(i.constructor.name==="FootnoteItem"){let o=ti(i,e);o&&n.push(o);}else if(i instanceof re){let o=Se(i);s&&r==="FootnoteItem"&&(o=`[^${t.note_type}-${t.id}]: ${o}`);let a=ot(i,e,false);n.push(o+a),s=false;}else if(i instanceof Te){let o=kt(i,e,false,0);o&&n.push(o),s=false;}return n.join(`
139
139
 
140
- `)}y(Vr,"_project_part");function rt(t){return Hr.test(Se(t))}y(rt,"_is_heading");function ua(t,e){let n=Kr(t,e);return Zr(n)?Et(t)!=="(heuristic)"?true:(n.match(/\w+/g)||[]).length>=Xr:false}y(ua,"_heading_passes_quality_filter");function Zr(t){if(!t)return false;let e=t.replace(/\{#[^}]+\}/g,"");return /\w/.test(e)}y(Zr,"_heading_text_has_words");function vt(t){let e=Hr.exec(Se(t));return e?Math.min(e[1].length,6):1}y(vt,"_heading_level");var ar=200;function Kr(t,e){let n=ot(t,e,false),r=ti(n);return r=r.replace(/\n+/g," "),r=ni(r),ei(r.trim())}y(Kr,"_heading_text");function ei(t){return t.length<=ar?t:t.substring(0,ar)+"\u2026"}y(ei,"_truncate_outline_text");function ti(t){return t?(t=t.replace(/\{--[\s\S]*?--\}/g,""),t=t.replace(/\{>>[\s\S]*?<<\}/g,""),t=t.replace(/\{\+\+([\s\S]*?)\+\+\}/g,"$1"),t=t.replace(/\{==([\s\S]*?)==\}/g,"$1"),t):""}y(ti,"_strip_critic_markup");function ni(t){if(!t)return "";let e=[];return t=t.replace(/\{#[^}]+\}|_{3,}/g,n=>(e.push(n),`\0${e.length-1}\0`)),t=t.replace(/\*\*(.+?)\*\*/g,"$1"),t=t.replace(/__(.+?)__/g,"$1"),t=t.replace(/(?<!\w)_(\S(?:.*?\S)?)_(?!\w)/g,"$1"),t=t.replace(/\x00(\d+)\x00/g,(n,r)=>e[Number(r)]),t}y(ni,"_strip_inline_formatting");function Et(t){let[e,n]=st(t._parent.part||t._parent),r=M(t._element,"w:pPr"),s=n;if(r){let u=M(r,"w:pStyle");u&&(s=u.getAttribute("w:val")||n);}let i=null,o=false;if(r){let u=M(r,"w:outlineLvl");u&&/^\d+$/.test(u.getAttribute("w:val")||"")&&(i=parseInt(u.getAttribute("w:val"),10));}i===null&&s&&e&&e[s]&&(i=e[s].outline_level,o=true);let a=s&&e&&e[s]?e[s].name:s;return a&&typeof a=="string"&&(a.toLowerCase().startsWith("heading")?a=a.replace(/^heading/i,"Heading"):a.toLowerCase()==="title"&&(a="Title")),o&&i!==null&&(a&&(a.startsWith("Heading")||a==="Title")||(i=null)),i!==null&&i>=0&&i<=8?a&&(a.startsWith("Heading")||a==="Title")?a:"(outline_level)":a&&(a.startsWith("Heading")||a==="Title")||a&&/Heading[ ]?([1-6])(?![0-9])/.test(a)?a:"(heuristic)"}y(Et,"_determine_heading_style");function da(t,e,n,r){for(let s=n+1;s<e.length;s++){let i=e[s];if(vt(t[i].item)<=r)return i}return t.length}y(da,"_find_owned_end");function fa(t){let e=new Set,n=[];for(let r of t)if(r.is_paragraph)for(let s of Nt(r.item)){if(!("type"in s))continue;let i="";if(s.type==="footnote")i=`fn-${s.id}`;else if(s.type==="endnote")i=`en-${s.id}`;else continue;e.has(i)||(e.add(i),n.push(i));}return n}y(fa,"_collect_footnote_ids");function ri(t,e){if(!e||e.length===0)return 1;let n=1;for(let r=0;r<e.length&&t>=e[r];r++)n=r+1;return n}y(ri,"_offset_to_page");function ha(t,e,n,r){let s=[],i=new Set;function o(u){for(let c of Ie(u))if(c.constructor.name==="FootnoteItem")o(c);else if(c instanceof re)s.push(["p",c]);else if(c instanceof Te){s.push(["t",c]);for(let f of c.rows)for(let h of f.cells)i.has(h._element)||(i.add(h._element),o(h));}}y(o,"walk"),o(t);let l=[];for(let u=0;u<s.length;u++){let[c,d]=s[u];if(c!=="p")continue;let f=false;r instanceof Map?f=r.has(d._element):f=d._element in r,f&&rt(d)&&pa(d,e,r)&&l.push(u);}if(l.length===0)return [];let a=[];for(let u=0;u<l.length;u++){let c=l[u],d=s[c][1],f=vt(d),h=ii(d,e,r),p=Et(d),_=c;for(let v=u+1;v<l.length;v++){let N=l[v],A=s[N][1];if(vt(A)<=f){_=N;break}}_===c&&(_=s.length);let g=s.slice(c+1,_),w=false;for(let[v,N]of g){if(v==="p"&&rt(N))break;if(v==="t"){w=true;break}}let k=_a(g),b;r instanceof Map?b=r.get(d._element):b=r[d._element];let m=1;if(b!==void 0){let[v]=b;m=ri(v,n);}a.push({level:f,text:h,page:m,style:p,has_table:w,footnote_ids:k});}return a}y(ha,"_extract_outline_fast");function pa(t,e,n){let r=ii(t,e,n);return Zr(r)?Et(t)!=="(heuristic)"?true:(r.match(/\w+/g)||[]).length>=Xr:false}y(pa,"_heading_passes_quality_filter_fast");function ii(t,e,n){let r;if(n instanceof Map?r=n.get(t._element):r=n[t._element],r===void 0)return "";let[s,i]=r,o=e.substring(s,s+i),l=ti(o);return l=l.replace(/\n+/g," "),l=ni(l),l=l.replace(/^#+\s+/,""),ei(l.trim())}y(ii,"_heading_text_fast");function _a(t){let e=new Set,n=[];for(let[r,s]of t)if(r==="p")for(let i of Nt(s)){if(!("type"in i))continue;let o="";if(i.type==="footnote")o=`fn-${i.id}`;else if(i.type==="endnote")o=`en-${i.id}`;else continue;e.has(o)||(e.add(o),n.push(o));}return n}y(_a,"_collect_footnote_ids_fast");var ma=class{static{y(this,"SanitizeReport");}filename;mode;author;tracked_changes_found=0;tracked_changes_accepted=0;tracked_changes_kept=0;change_lines=[];comments_removed=0;comments_kept=0;removed_comment_lines=[];kept_comment_lines=[];metadata_lines=[];structural_lines=[];warnings=[];status="clean";blocked_reason=null;constructor(t,e="full",n=null){this.filename=t,this.mode=e,this.author=n;}add_transform_lines(t){for(let e of t){let n=e.toLowerCase();n.includes("tracked change")||n.includes("insertion")||n.includes("deletion")||n.includes("accepted")?this.change_lines.push(e):n.includes("author")||n.includes("template")||n.includes("company")||n.includes("manager")||n.includes("metadata")||n.includes("timestamp")||n.includes("custom xml")||n.includes("custom propert")||n.includes("identifier")||n.includes("document variable")||n.includes("language")||n.includes("version")||n.includes("last modified by")||n.includes("revision count")||n.includes("last printed")||n.includes("description/comments")?this.metadata_lines.push(e):n.includes("comment")||n.includes("[open]")||n.includes("[resolved]")?n.includes("kept")||n.includes("visible")?this.kept_comment_lines.push(e):this.removed_comment_lines.push(e):n.includes("hyperlink")||n.includes("warning")?this.warnings.push(e):this.structural_lines.push(e);}}render(){let t="\u2550".repeat(50),e=[t,`Finalization Report: ${this.filename}`],n=[];if(this.mode==="keep-markup"&&n.push("--keep-markup"),this.author&&n.push(`--author "${this.author}"`),this.tracked_changes_accepted>0&&n.push("--accept-all"),n.length>0&&e.push(`Options: ${n.join(" ")}`),e.push(t),this.status==="blocked")return e.push(""),e.push(`BLOCKED: ${this.blocked_reason}`),e.push(t),e.join(`
140
+ `)}y(ti,"_project_part");function rt(t){return Gr.test(Se(t))}y(rt,"_is_heading");function wa(t,e){let n=ri(t,e);return ni(n)?Et(t)!=="(heuristic)"?true:(n.match(/\w+/g)||[]).length>=Vr:false}y(wa,"_heading_passes_quality_filter");function ni(t){if(!t)return false;let e=t.replace(/\{#[^}]+\}/g,"");return /\w/.test(e)}y(ni,"_heading_text_has_words");function vt(t){let e=Gr.exec(Se(t));return e?Math.min(e[1].length,6):1}y(vt,"_heading_level");var cr=200;function ri(t,e){let n=ot(t,e,false),r=si(n);return r=r.replace(/\n+/g," "),r=oi(r),ii(r.trim())}y(ri,"_heading_text");function ii(t){return t.length<=cr?t:t.substring(0,cr)+"\u2026"}y(ii,"_truncate_outline_text");function si(t){return t?(t=t.replace(/\{--[\s\S]*?--\}/g,""),t=t.replace(/\{>>[\s\S]*?<<\}/g,""),t=t.replace(/\{\+\+([\s\S]*?)\+\+\}/g,"$1"),t=t.replace(/\{==([\s\S]*?)==\}/g,"$1"),t):""}y(si,"_strip_critic_markup");function oi(t){if(!t)return "";let e=[];return t=t.replace(/\{#[^}]+\}|_{3,}/g,n=>(e.push(n),`\0${e.length-1}\0`)),t=t.replace(/\*\*(.+?)\*\*/g,"$1"),t=t.replace(/__(.+?)__/g,"$1"),t=t.replace(/(?<!\w)_(\S(?:.*?\S)?)_(?!\w)/g,"$1"),t=t.replace(/\x00(\d+)\x00/g,(n,r)=>e[Number(r)]),t}y(oi,"_strip_inline_formatting");function Et(t){let[e,n]=st(t._parent.part||t._parent),r=M(t._element,"w:pPr"),s=n;if(r){let u=M(r,"w:pStyle");u&&(s=u.getAttribute("w:val")||n);}let i=null,o=false;if(r){let u=M(r,"w:outlineLvl");u&&/^\d+$/.test(u.getAttribute("w:val")||"")&&(i=parseInt(u.getAttribute("w:val"),10));}i===null&&s&&e&&e[s]&&(i=e[s].outline_level,o=true);let l=s&&e&&e[s]?e[s].name:s;return l&&typeof l=="string"&&(l.toLowerCase().startsWith("heading")?l=l.replace(/^heading/i,"Heading"):l.toLowerCase()==="title"&&(l="Title")),o&&i!==null&&(l&&(l.startsWith("Heading")||l==="Title")||(i=null)),i!==null&&i>=0&&i<=8?l&&(l.startsWith("Heading")||l==="Title")?l:"(outline_level)":l&&(l.startsWith("Heading")||l==="Title")||l&&/Heading[ ]?([1-6])(?![0-9])/.test(l)?l:"(heuristic)"}y(Et,"_determine_heading_style");function ya(t,e,n,r){for(let s=n+1;s<e.length;s++){let i=e[s];if(vt(t[i].item)<=r)return i}return t.length}y(ya,"_find_owned_end");function va(t){let e=new Set,n=[];for(let r of t)if(r.is_paragraph)for(let s of Nt(r.item)){if(!("type"in s))continue;let i="";if(s.type==="footnote")i=`fn-${s.id}`;else if(s.type==="endnote")i=`en-${s.id}`;else continue;e.has(i)||(e.add(i),n.push(i));}return n}y(va,"_collect_footnote_ids");function ai(t,e){if(!e||e.length===0)return 1;let n=1;for(let r=0;r<e.length&&t>=e[r];r++)n=r+1;return n}y(ai,"_offset_to_page");function ba(t,e,n,r){let s=[],i=new Set;function o(u){for(let c of Ie(u))if(c.constructor.name==="FootnoteItem")o(c);else if(c instanceof re)s.push(["p",c]);else if(c instanceof Te){s.push(["t",c]);for(let f of c.rows)for(let h of f.cells)i.has(h._element)||(i.add(h._element),o(h));}}y(o,"walk"),o(t);let a=[];for(let u=0;u<s.length;u++){let[c,d]=s[u];if(c!=="p")continue;let f=false;r instanceof Map?f=r.has(d._element):f=d._element in r,f&&rt(d)&&xa(d,e,r)&&a.push(u);}if(a.length===0)return [];let l=[];for(let u=0;u<a.length;u++){let c=a[u],d=s[c][1],f=vt(d),h=li(d,e,r),_=Et(d),p=c;for(let v=u+1;v<a.length;v++){let x=a[v],E=s[x][1];if(vt(E)<=f){p=x;break}}p===c&&(p=s.length);let m=s.slice(c+1,p),w=false;for(let[v,x]of m){if(v==="p"&&rt(x))break;if(v==="t"){w=true;break}}let k=Na(m),b;r instanceof Map?b=r.get(d._element):b=r[d._element];let g=1;if(b!==void 0){let[v]=b;g=ai(v,n);}l.push({level:f,text:h,page:g,style:_,has_table:w,footnote_ids:k});}return l}y(ba,"_extract_outline_fast");function xa(t,e,n){let r=li(t,e,n);return ni(r)?Et(t)!=="(heuristic)"?true:(r.match(/\w+/g)||[]).length>=Vr:false}y(xa,"_heading_passes_quality_filter_fast");function li(t,e,n){let r;if(n instanceof Map?r=n.get(t._element):r=n[t._element],r===void 0)return "";let[s,i]=r,o=e.substring(s,s+i),a=si(o);return a=a.replace(/\n+/g," "),a=oi(a),a=a.replace(/^#+\s+/,""),ii(a.trim())}y(li,"_heading_text_fast");function Na(t){let e=new Set,n=[];for(let[r,s]of t)if(r==="p")for(let i of Nt(s)){if(!("type"in i))continue;let o="";if(i.type==="footnote")o=`fn-${i.id}`;else if(i.type==="endnote")o=`en-${i.id}`;else continue;e.has(o)||(e.add(o),n.push(o));}return n}y(Na,"_collect_footnote_ids_fast");var ka=class{static{y(this,"SanitizeReport");}filename;mode;author;tracked_changes_found=0;tracked_changes_accepted=0;tracked_changes_kept=0;change_lines=[];comments_removed=0;comments_kept=0;removed_comment_lines=[];kept_comment_lines=[];metadata_lines=[];structural_lines=[];warnings=[];status="clean";blocked_reason=null;constructor(t,e="full",n=null){this.filename=t,this.mode=e,this.author=n;}add_transform_lines(t){for(let e of t){let n=e.toLowerCase();n.includes("tracked change")||n.includes("insertion")||n.includes("deletion")||n.includes("accepted")?this.change_lines.push(e):n.includes("author")||n.includes("template")||n.includes("company")||n.includes("manager")||n.includes("metadata")||n.includes("timestamp")||n.includes("custom xml")||n.includes("custom propert")||n.includes("identifier")||n.includes("document variable")||n.includes("language")||n.includes("version")||n.includes("last modified by")||n.includes("revision count")||n.includes("last printed")||n.includes("description/comments")?this.metadata_lines.push(e):n.includes("comment")||n.includes("[open]")||n.includes("[resolved]")?n.includes("kept")||n.includes("visible")?this.kept_comment_lines.push(e):this.removed_comment_lines.push(e):n.includes("hyperlink")||n.includes("warning")?this.warnings.push(e):this.structural_lines.push(e);}}render(){let t="\u2550".repeat(50),e=[t,`Finalization Report: ${this.filename}`],n=[];if(this.mode==="keep-markup"&&n.push("--keep-markup"),this.author&&n.push(`--author "${this.author}"`),this.tracked_changes_accepted>0&&n.push("--accept-all"),n.length>0&&e.push(`Options: ${n.join(" ")}`),e.push(t),this.status==="blocked")return e.push(""),e.push(`BLOCKED: ${this.blocked_reason}`),e.push(t),e.join(`
141
141
  `);if(this.mode==="keep-markup"&&(this.tracked_changes_kept>0||this.comments_kept>0)){if(e.push(""),e.push("VISIBLE TO COUNTERPARTY"),this.tracked_changes_kept>0&&e.push(` Tracked changes: ${this.tracked_changes_kept}`),this.comments_kept>0){e.push(` Open comments: ${this.comments_kept}`);for(let r of this.kept_comment_lines)e.push(` ${r}`);}this.author&&e.push(` Author on all markup: "${this.author}"`);}if(this.change_lines.length>0){e.push(""),e.push("TRACKED CHANGES");for(let r of this.change_lines)e.push(` ${r}`);}if(this.removed_comment_lines.length>0){e.push(""),e.push("COMMENTS (stripped)");for(let r of this.removed_comment_lines)e.push(` ${r}`);}if(this.metadata_lines.length>0){e.push(""),e.push("METADATA");for(let r of this.metadata_lines)e.push(` ${r}`);}if(this.structural_lines.length>0){e.push(""),e.push("STRUCTURAL & PROTECTION");for(let r of this.structural_lines)e.push(` ${r}`);}if(this.warnings.length>0){e.push(""),e.push("WARNINGS");for(let r of this.warnings)e.push(` \u26A0 ${r}`);}return e.push(""),e.push(t),this.warnings.length>0?e.push(`Result: CLEAN WITH WARNINGS (${this.warnings.length} warning${this.warnings.length>1?"s":""})`):this.mode==="keep-markup"?e.push("Result: CLEAN"):e.push(`Result: CLEAN (${this.tracked_changes_found} changes resolved, ${this.comments_removed} comments removed)`),e.push(t),e.join(`
142
- `)}};async function si(t,e){let n=new ma(e.filename,e.sanitize_mode||"full",e.author||null);if(e.sanitize_mode==="full"){let i=rr(t),o=i[0]+i[1]+i[2];if(n.tracked_changes_found=o,o>0&&!e.accept_all)return n.status="blocked",n.blocked_reason=`Document contains ${o} unresolved tracked changes (${i[0]} insertions, ${i[1]} deletions, ${i[2]} formatting). Review in Word first, set accept_all=true, or set sanitize_mode='keep-markup'.`,{reportText:n.render()};if(o>0){let a=Do(t);a.size>1&&n.warnings.push(`Multiple authors detected in tracked changes: ${Array.from(a).sort().join(", ")}. Review per-change list before sending.`);let u=_t(t);n.add_transform_lines(Mo(t)),n.tracked_changes_accepted=o;let c=new Set(_t(t).comments.map(f=>f.id)),d=u.comments.filter(f=>!c.has(f.id));if(d.length>0){n.comments_removed+=d.length,n.removed_comment_lines.push(`Comments removed: ${d.length} (anchored to auto-accepted tracked changes)`);for(let f of d){let h=f.resolved?"[Resolved]":"[Open]";n.removed_comment_lines.push(` ${h} "${Pe(f.text||"",60)}" (${f.author||"Unknown"})`);}}}let l=_t(t);n.comments_removed+=l.total,n.add_transform_lines(Ro(t)),jo(t);}else if(e.sanitize_mode==="keep-markup"){let i=rr(t);n.tracked_changes_found=i[0]+i[1]+i[2],n.tracked_changes_kept=n.tracked_changes_found;let o=_t(t);n.comments_kept=o.open;for(let l of o.comments)l.resolved||n.kept_comment_lines.push(`"${Pe(l.text||"",60)}" (${l.author||"Unknown"})`);e.author&&(n.add_transform_lines(Fo(t,e.author)),n.add_transform_lines(Bo(t,e.author)));}n.add_transform_lines(To(t)),n.add_transform_lines(So(t)),n.add_transform_lines(Io(t)),n.add_transform_lines($o(t)),n.add_transform_lines(Oo(t)),n.add_transform_lines(Po(t)),n.add_transform_lines(Lo(t)),n.add_transform_lines(Uo(t)),n.add_transform_lines(qo(t)),n.add_transform_lines(Jo(t)),n.add_transform_lines(Ho(t)),n.add_transform_lines(Xo(t));let r=Yo(t);for(let i of r)n.warnings.push(i);for(let i of Qo(t))n.warnings.push(i);if(n.add_transform_lines(Wo(t)),n.add_transform_lines(zo(t)),e.protection_mode==="read_only"||e.protection_mode==="encrypt"){e.protection_mode==="encrypt"&&n.warnings.push("Encryption mode (AES compound wrappers) is strictly unsupported in the zero-dependency Node engine. Falling back to native Word Read-Only lock.");let i=t.pkg.getPartByPath("word/settings.xml");if(i){let o=i._element.ownerDocument,l=Z(i._element,"documentProtection")[0];l||(l=o.createElement("w:documentProtection"),i._element.appendChild(l)),l.setAttribute("w:edit","readOnly"),l.setAttribute("w:enforcement","1"),n.structural_lines.push("Document locked (Read-Only enforcement injected into settings.xml)");}}e.export_pdf&&n.warnings.push("PDF export requires the Python/Word COM environment and is skipped in this zero-dependency Node agent.");for(let i of t.pkg.parts)if((i===t.part||i.contentType.includes("wordprocessingml")&&i.contentType.endsWith("+xml"))&&i._element.hasAttribute("xmlns:w16du")){let o=false;if(Array.from(i._element.attributes||[]).some(l=>l.name.startsWith("w16du:")&&l.name!=="xmlns:w16du")&&(o=true),!o){let l=I(i._element,"*");for(let a of l)if(a.tagName.startsWith("w16du:")||Array.from(a.attributes||[]).some(u=>u.name.startsWith("w16du:"))){o=true;break}}o||i._element.removeAttribute("xmlns:w16du");}n.warnings.length>0&&(n.status="clean_with_warnings");let s=await t.save();return wa(s),{reportText:n.render(),outBuffer:s}}y(si,"finalize_document");var ga=[["creator","author (dc:creator)"],["lastModifiedBy","last modified by (cp:lastModifiedBy)"],["identifier","identifier (dc:identifier)"],["description","description (dc:description)"],["keywords","keywords (cp:keywords)"],["category","category (cp:category)"],["subject","subject (dc:subject)"],["contentStatus","content status (cp:contentStatus)"],["language","language (dc:language)"],["version","version (cp:version)"]];function wa(t){let e=Be(new Uint8Array(t)),n=Object.keys(e),r=[];if(n.includes("docProps/custom.xml")&&r.push("docProps/custom.xml (custom document properties) is still in the package"),n.some(s=>s.startsWith("customXml/"))&&r.push("customXml/* parts are still in the package"),n.includes("docProps/core.xml")){let s=qe(Oe(e["docProps/core.xml"]));for(let[i,o]of ga)for(let l of Z(s.documentElement,i))(l.textContent||"").trim()&&r.push(`core property ${o} still contains a value`);}if(n.includes("word/settings.xml")){let s=qe(Oe(e["word/settings.xml"]));Z(s.documentElement,"docVar").length>0&&r.push("word/settings.xml still contains document variables (w:docVar)");}if(r.length>0)throw new Error(`Sanitize integrity check failed \u2014 the saved package still contains metadata this run claims to remove:
142
+ `)}};async function ci(t,e){let n=new ka(e.filename,e.sanitize_mode||"full",e.author||null);if(e.sanitize_mode==="full"){let i=sr(t),o=i[0]+i[1]+i[2];if(n.tracked_changes_found=o,o>0&&!e.accept_all)return n.status="blocked",n.blocked_reason=`Document contains ${o} unresolved tracked changes (${i[0]} insertions, ${i[1]} deletions, ${i[2]} formatting). Review in Word first, set accept_all=true, or set sanitize_mode='keep-markup'.`,{reportText:n.render()};if(o>0){let l=Lo(t);l.size>1&&n.warnings.push(`Multiple authors detected in tracked changes: ${Array.from(l).sort().join(", ")}. Review per-change list before sending.`);let u=_t(t);n.add_transform_lines(Uo(t)),n.tracked_changes_accepted=o;let c=new Set(_t(t).comments.map(f=>f.id)),d=u.comments.filter(f=>!c.has(f.id));if(d.length>0){n.comments_removed+=d.length,n.removed_comment_lines.push(`Comments removed: ${d.length} (anchored to auto-accepted tracked changes)`);for(let f of d){let h=f.resolved?"[Resolved]":"[Open]";n.removed_comment_lines.push(` ${h} "${Pe(f.text||"",60)}" (${f.author||"Unknown"})`);}}}let a=_t(t);n.comments_removed+=a.total,n.add_transform_lines(qo(t)),Jo(t);}else if(e.sanitize_mode==="keep-markup"){let i=sr(t);n.tracked_changes_found=i[0]+i[1]+i[2],n.tracked_changes_kept=n.tracked_changes_found;let o=_t(t);n.comments_kept=o.open;for(let a of o.comments)a.resolved||n.kept_comment_lines.push(`"${Pe(a.text||"",60)}" (${a.author||"Unknown"})`);e.author&&(n.add_transform_lines(Ho(t,e.author)),n.add_transform_lines(Xo(t,e.author)));}n.add_transform_lines(jo(t)),n.add_transform_lines(Fo(t)),n.add_transform_lines(Bo(t)),n.add_transform_lines(Wo(t)),n.add_transform_lines(zo(t)),n.add_transform_lines(Ro(t)),n.add_transform_lines(Go(t)),n.add_transform_lines(Vo(t)),n.add_transform_lines(Zo(t)),n.add_transform_lines(Ko(t)),n.add_transform_lines(ea(t)),n.add_transform_lines(ta(t));let r=ra(t);for(let i of r)n.warnings.push(i);for(let i of na(t))n.warnings.push(i);if(n.add_transform_lines(Qo(t)),n.add_transform_lines(Yo(t)),e.protection_mode==="read_only"||e.protection_mode==="encrypt"){e.protection_mode==="encrypt"&&n.warnings.push("Encryption mode (AES compound wrappers) is strictly unsupported in the zero-dependency Node engine. Falling back to native Word Read-Only lock.");let i=t.pkg.getPartByPath("word/settings.xml");if(i){let o=i._element.ownerDocument,a=Z(i._element,"documentProtection")[0];a||(a=o.createElement("w:documentProtection"),i._element.appendChild(a)),a.setAttribute("w:edit","readOnly"),a.setAttribute("w:enforcement","1"),n.structural_lines.push("Document locked (Read-Only enforcement injected into settings.xml)");}}e.export_pdf&&n.warnings.push("PDF export requires the Python/Word COM environment and is skipped in this zero-dependency Node agent.");for(let i of t.pkg.parts)if((i===t.part||i.contentType.includes("wordprocessingml")&&i.contentType.endsWith("+xml"))&&i._element.hasAttribute("xmlns:w16du")){let o=false;if(Array.from(i._element.attributes||[]).some(a=>a.name.startsWith("w16du:")&&a.name!=="xmlns:w16du")&&(o=true),!o){let a=$(i._element,"*");for(let l of a)if(l.tagName.startsWith("w16du:")||Array.from(l.attributes||[]).some(u=>u.name.startsWith("w16du:"))){o=true;break}}o||i._element.removeAttribute("xmlns:w16du");}n.warnings.length>0&&(n.status="clean_with_warnings");let s=await t.save();return Aa(s),{reportText:n.render(),outBuffer:s}}y(ci,"finalize_document");var Ea=[["creator","author (dc:creator)"],["lastModifiedBy","last modified by (cp:lastModifiedBy)"],["identifier","identifier (dc:identifier)"],["description","description (dc:description)"],["keywords","keywords (cp:keywords)"],["category","category (cp:category)"],["subject","subject (dc:subject)"],["contentStatus","content status (cp:contentStatus)"],["language","language (dc:language)"],["version","version (cp:version)"]];function Aa(t){let e=We(new Uint8Array(t)),n=Object.keys(e),r=[];if(n.includes("docProps/custom.xml")&&r.push("docProps/custom.xml (custom document properties) is still in the package"),n.some(s=>s.startsWith("customXml/"))&&r.push("customXml/* parts are still in the package"),n.includes("docProps/core.xml")){let s=Je(Oe(e["docProps/core.xml"]));for(let[i,o]of Ea)for(let a of Z(s.documentElement,i))(a.textContent||"").trim()&&r.push(`core property ${o} still contains a value`);}if(n.includes("word/settings.xml")){let s=Je(Oe(e["word/settings.xml"]));Z(s.documentElement,"docVar").length>0&&r.push("word/settings.xml still contains document variables (w:docVar)");}if(r.length>0)throw new Error(`Sanitize integrity check failed \u2014 the saved package still contains metadata this run claims to remove:
143
143
  - `+r.join(`
144
144
  - `)+`
145
- Refusing to report a clean document.`)}y(wa,"verifySanitizedPackage");var oi=[{displayName:"Input Binary Property",name:"binaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property holding the .docx file (string, e.g. 'data'). In 'From Connected Input' mode this reads from the current item; in 'From Another Node' mode this specifies which property on the source node's output to read. Must be a valid .docx (not .doc, .pdf, or another format).",displayOptions:{show:{resource:["document"],operation:["extractMarkdown"]}}},{displayName:"Clean View",name:"cleanView",type:"boolean",default:false,description:"Whether to project the document as if all pending tracked changes were accepted (simulates Accept All). When false (default), all tracked changes are surfaced inline as CriticMarkup ({++ins++}, {--del--}, {>>comment<<}) so an AI can review and resolve them. Use false to review counterparty edits; use true to generate net-new redlines against a clean baseline.",displayOptions:{show:{resource:["document"],operation:["extractMarkdown"]}}},{displayName:"Include Appendix",name:"includeAppendix",type:"boolean",default:true,description:"Whether to include the Structural Appendix (defined terms, cross-reference anchors, and potential typos) at the end of the projection. True by default for rich LLM context.",displayOptions:{show:{resource:["document"],operation:["extractMarkdown"]}}},{displayName:"Page",name:"page",type:"number",default:0,typeOptions:{minValue:0},description:"Optional 1-based page number to return only one page of the projected document (integer, default 0). When 0 (default), the full Markdown body plus the Structural Appendix is returned in the 'markdown' field and pagination metadata is omitted. When >= 1, only that page is returned in the 'markdown' field and the JSON output includes pagination metadata: page, total_pages, has_next, has_prev, tracked_change_count. Pages are ~19,000-character chunks of the projected body with the Structural Appendix appended to each page. Use the extractOutline operation first to discover how many pages exist and what each page contains. If the requested page exceeds total_pages, an error is thrown.",displayOptions:{show:{resource:["document"],operation:["extractMarkdown"]}}}];async function ai(t){let e=this.getNodeParameter("binaryPropertyName",t),n=this.getNodeParameter("cleanView",t),r=this.getNodeParameter("includeAppendix",t,true),s=this.getNodeParameter("page",t,0),o=this.getNodeParameter("documentSource",t,"fromInput")==="fromNode"?{mode:"fromNode",sourceNodeName:this.getNodeParameter("sourceNodeName",t,""),binaryPropertyName:e,sourceBinaryId:this.getNodeParameter("sourceBinaryId",t,"")}:{mode:"fromInput",binaryPropertyName:e},{buffer:l,fileName:a}=await le.call(this,t,o),u=await Re(l,n,r);if(!s||s===0)return [{json:{fileName:a,cleanView:n,markdown:u},pairedItem:{item:t}}];let[c,d]=Je(u),f=He(c,d);if(s>f.total_pages)throw new n8nWorkflow.NodeOperationError(this.getNode(),`Requested page ${s} exceeds total_pages (${f.total_pages}). Call extractOutline to discover the page count first.`,{itemIndex:t});let h=f.pages[s-1];return [{json:{fileName:a,cleanView:n,markdown:h.page_content,page:h.page,total_pages:h.total_pages,has_next:h.has_next,has_prev:h.has_prev,tracked_change_count:h.tracked_change_count},pairedItem:{item:t}}]}y(ai,"executeExtractMarkdown");var li=[{displayName:"Input Binary Property",name:"binaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property holding the .docx file (string, e.g. 'data'). In 'From Connected Input' mode this reads from the current item; in 'From Another Node' mode this specifies which property on the source node's output to read. Must be a valid .docx.",displayOptions:{show:{resource:["document"],operation:["extractOutline"]}}}];async function ci(t){let e=this.getNodeParameter("binaryPropertyName",t),r=this.getNodeParameter("documentSource",t,"fromInput")==="fromNode"?{mode:"fromNode",sourceNodeName:this.getNodeParameter("sourceNodeName",t,""),binaryPropertyName:e,sourceBinaryId:this.getNodeParameter("sourceBinaryId",t,"")}:{mode:"fromInput",binaryPropertyName:e},{buffer:s,fileName:i}=await le.call(this,t,r),o=await pe.load(s),l=Qe(o,false,true,true),[a]=Je(l.text),u=He(a,""),c=Qr(o,a,u.body_pages,u.body_page_offsets,l.paragraph_offsets);return [{json:{fileName:i,total_pages:u.total_pages,outline:c.map(d=>({level:d.level,text:d.text,page:d.page,style:d.style,has_table:d.has_table,footnote_ids:d.footnote_ids}))},pairedItem:{item:t}}]}y(ci,"executeExtractOutline");var ui=[{displayName:"Reasoning",name:"reasoning",type:"string",default:"",typeOptions:{rows:2},description:"Why these edits are being made. State your reasoning BEFORE the changes \u2014 what you intend to change and why \u2014 then produce the Changes (JSON) array. This field is captured for auditability and is NOT forwarded into the redline engine; its only purpose is to make the AI reason first, which improves edit quality. Safe to leave empty in deterministic (non-AI) pipelines.",displayOptions:{show:{resource:["document"],operation:["applyEdits"]}}},{displayName:"Input Binary Property",name:"binaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property holding the .docx file (string, e.g. 'data'). In 'From Connected Input' mode this reads from the current item; in 'From Another Node' mode this specifies which property on the source node's output to read. The file must be a valid .docx.",displayOptions:{show:{resource:["document"],operation:["applyEdits"]}}},{displayName:"Output Binary Property",name:"outputBinaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property on the outgoing item that will hold the redlined .docx file (string, e.g. 'data'). If equal to the input property name, the original binary is overwritten on the outgoing item.",displayOptions:{show:{resource:["document"],operation:["applyEdits"]}}},{displayName:"Author",name:"author",type:"string",default:"Adeu AI",placeholder:"e.g. AI Reviewer",description:"Author name attached to all tracked changes and comments produced by this operation (string, e.g. 'AI Reviewer'). Shows up in Word's review pane as the author of every redline and comment created in this batch.",displayOptions:{show:{resource:["document"],operation:["applyEdits"]}}},{displayName:"Edits Source",name:"editsSource",type:"options",noDataExpression:true,default:"fromInputJson",description:"Where to read the list of DocumentChange objects from. Use 'Define Below' to read the array from the Changes (JSON) field on this node \u2014 this is the typical AI Agent path, since the LLM generates the array as a tool call argument that lands on that field via $fromAI(). Use 'From Input JSON' to read the array from a property on the upstream item's JSON, for deterministic pipelines where a non-AI node (HTTP Request, Code, etc.) has pre-populated it.",options:[{name:"Define Below",value:"defineBelow",description:"Read the array from the Changes (JSON) field on this node. Use for AI Agent workflows \u2014 the LLM populates that field via $fromAI() as a tool call argument."},{name:"From Input JSON",value:"fromInputJson",description:"Read the array from a property on the upstream item's JSON. Use for deterministic pipelines where a non-AI node has pre-populated the changes array."}],displayOptions:{show:{resource:["document"],operation:["applyEdits"]}}},{displayName:"JSON Path on Input Item",name:"editsJsonPath",type:"string",default:"changes",required:true,placeholder:"e.g. data.changes",description:"Property path on the input item JSON whose value is the array of DocumentChange objects (string, dot-notation supported, e.g. 'changes' or 'data.changes'). Must resolve to an array; throws an error otherwise.",displayOptions:{show:{resource:["document"],operation:["applyEdits"],editsSource:["fromInputJson"]}}},{displayName:"Changes (JSON)",name:"editsJson",type:"string",default:`[
145
+ Refusing to report a clean document.`)}y(Aa,"verifySanitizedPackage");var ui=[{displayName:"Input Binary Property",name:"binaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property holding the .docx file (string, e.g. 'data'). In 'From Connected Input' mode this reads from the current item; in 'From Another Node' mode this specifies which property on the source node's output to read. Must be a valid .docx (not .doc, .pdf, or another format).",displayOptions:{show:{resource:["document"],operation:["extractMarkdown"]}}},{displayName:"Clean View",name:"cleanView",type:"boolean",default:false,description:"Whether to project the document as if all pending tracked changes were accepted (simulates Accept All). When false (default), all tracked changes are surfaced inline as CriticMarkup ({++ins++}, {--del--}, {>>comment<<}) so an AI can review and resolve them. Use false to review counterparty edits; use true to generate net-new redlines against a clean baseline.",displayOptions:{show:{resource:["document"],operation:["extractMarkdown"]}}},{displayName:"Include Appendix",name:"includeAppendix",type:"boolean",default:true,description:"Whether to include the Structural Appendix (defined terms, cross-reference anchors, and potential typos) at the end of the projection. True by default for rich LLM context.",displayOptions:{show:{resource:["document"],operation:["extractMarkdown"]}}},{displayName:"Page",name:"page",type:"number",default:0,typeOptions:{minValue:0},description:"Optional 1-based page number to return only one page of the projected document (integer, default 0). When 0 (default), the full Markdown body plus the Structural Appendix is returned in the 'markdown' field and pagination metadata is omitted. When >= 1, only that page is returned in the 'markdown' field and the JSON output includes pagination metadata: page, total_pages, has_next, has_prev, tracked_change_count. Pages are ~19,000-character chunks of the projected body with the Structural Appendix appended to each page. Use the extractOutline operation first to discover how many pages exist and what each page contains. If the requested page exceeds total_pages, an error is thrown.",displayOptions:{show:{resource:["document"],operation:["extractMarkdown"]}}}];async function di(t){let e=this.getNodeParameter("binaryPropertyName",t),n=this.getNodeParameter("cleanView",t),r=this.getNodeParameter("includeAppendix",t,true),s=this.getNodeParameter("page",t,0),o=this.getNodeParameter("documentSource",t,"fromInput")==="fromNode"?{mode:"fromNode",sourceNodeName:this.getNodeParameter("sourceNodeName",t,""),binaryPropertyName:e,sourceBinaryId:this.getNodeParameter("sourceBinaryId",t,"")}:{mode:"fromInput",binaryPropertyName:e},{buffer:a,fileName:l}=await le.call(this,t,o),u=await je(a,n,r);if(!s||s===0)return [{json:{fileName:l,cleanView:n,markdown:u},pairedItem:{item:t}}];let[c,d]=He(u),f=Xe(c,d);if(s>f.total_pages)throw new n8nWorkflow.NodeOperationError(this.getNode(),`Requested page ${s} exceeds total_pages (${f.total_pages}). Call extractOutline to discover the page count first.`,{itemIndex:t});let h=f.pages[s-1];return [{json:{fileName:l,cleanView:n,markdown:h.page_content,page:h.page,total_pages:h.total_pages,has_next:h.has_next,has_prev:h.has_prev,tracked_change_count:h.tracked_change_count},pairedItem:{item:t}}]}y(di,"executeExtractMarkdown");var fi=[{displayName:"Input Binary Property",name:"binaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property holding the .docx file (string, e.g. 'data'). In 'From Connected Input' mode this reads from the current item; in 'From Another Node' mode this specifies which property on the source node's output to read. Must be a valid .docx.",displayOptions:{show:{resource:["document"],operation:["extractOutline"]}}}];async function hi(t){let e=this.getNodeParameter("binaryPropertyName",t),r=this.getNodeParameter("documentSource",t,"fromInput")==="fromNode"?{mode:"fromNode",sourceNodeName:this.getNodeParameter("sourceNodeName",t,""),binaryPropertyName:e,sourceBinaryId:this.getNodeParameter("sourceBinaryId",t,"")}:{mode:"fromInput",binaryPropertyName:e},{buffer:s,fileName:i}=await le.call(this,t,r),o=await pe.load(s),a=Qe(o,false,true,true),[l]=He(a.text),u=Xe(l,""),c=Zr(o,l,u.body_pages,u.body_page_offsets,a.paragraph_offsets);return [{json:{fileName:i,total_pages:u.total_pages,outline:c.map(d=>({level:d.level,text:d.text,page:d.page,style:d.style,has_table:d.has_table,footnote_ids:d.footnote_ids}))},pairedItem:{item:t}}]}y(hi,"executeExtractOutline");var pi=[{displayName:"Reasoning",name:"reasoning",type:"string",default:"",typeOptions:{rows:2},description:"Why these edits are being made. State your reasoning BEFORE the changes \u2014 what you intend to change and why \u2014 then produce the Changes (JSON) array. This field is captured for auditability and is NOT forwarded into the redline engine; its only purpose is to make the AI reason first, which improves edit quality. Safe to leave empty in deterministic (non-AI) pipelines.",displayOptions:{show:{resource:["document"],operation:["applyEdits"]}}},{displayName:"Input Binary Property",name:"binaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property holding the .docx file (string, e.g. 'data'). In 'From Connected Input' mode this reads from the current item; in 'From Another Node' mode this specifies which property on the source node's output to read. The file must be a valid .docx.",displayOptions:{show:{resource:["document"],operation:["applyEdits"]}}},{displayName:"Output Binary Property",name:"outputBinaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property on the outgoing item that will hold the redlined .docx file (string, e.g. 'data'). If equal to the input property name, the original binary is overwritten on the outgoing item.",displayOptions:{show:{resource:["document"],operation:["applyEdits"]}}},{displayName:"Author",name:"author",type:"string",default:"Adeu AI",placeholder:"e.g. AI Reviewer",description:"Author name attached to all tracked changes and comments produced by this operation (string, e.g. 'AI Reviewer'). Shows up in Word's review pane as the author of every redline and comment created in this batch.",displayOptions:{show:{resource:["document"],operation:["applyEdits"]}}},{displayName:"Edits Source",name:"editsSource",type:"options",noDataExpression:true,default:"fromInputJson",description:"Where to read the list of DocumentChange objects from. Use 'Define Below' to read the array from the Changes (JSON) field on this node \u2014 this is the typical AI Agent path, since the LLM generates the array as a tool call argument that lands on that field via $fromAI(). Use 'From Input JSON' to read the array from a property on the upstream item's JSON, for deterministic pipelines where a non-AI node (HTTP Request, Code, etc.) has pre-populated it.",options:[{name:"Define Below",value:"defineBelow",description:"Read the array from the Changes (JSON) field on this node. Use for AI Agent workflows \u2014 the LLM populates that field via $fromAI() as a tool call argument."},{name:"From Input JSON",value:"fromInputJson",description:"Read the array from a property on the upstream item's JSON. Use for deterministic pipelines where a non-AI node has pre-populated the changes array."}],displayOptions:{show:{resource:["document"],operation:["applyEdits"]}}},{displayName:"JSON Path on Input Item",name:"editsJsonPath",type:"string",default:"changes",required:true,placeholder:"e.g. data.changes",description:"Property path on the input item JSON whose value is the array of DocumentChange objects (string, dot-notation supported, e.g. 'changes' or 'data.changes'). Must resolve to an array; throws an error otherwise.",displayOptions:{show:{resource:["document"],operation:["applyEdits"],editsSource:["fromInputJson"]}}},{displayName:"Changes (JSON)",name:"editsJson",type:"string",default:`[
146
146
  {
147
147
  "type": "modify",
148
148
  "target_text": "State of New York",
149
149
  "new_text": "State of Delaware",
150
150
  "comment": "Standardizing governing law."
151
151
  }
152
- ]`,required:true,description:`JSON-encoded string containing an array of DocumentChange objects. Each object has a 'type' field discriminator and type-specific fields. type='modify': requires target_text (string, copied EXACTLY from the source including punctuation, spacing, and case) and new_text (string); optional comment (string). Optional match_mode (one of 'strict' | 'first' | 'all', default 'strict'): 'strict' fails on ambiguous matches; 'first' silently anchors to the first occurrence; 'all' applies the same replacement to every occurrence in linear document order. Optional regex (boolean, default false): when true, target_text is interpreted as an ES2022 RegExp pattern and new_text may reference capture groups via $1, $2, etc. Combine with match_mode='all' for global regex replacements. Never include CriticMarkup tags like {++ ++} or {-- --} in new_text \u2014 the engine applies tracking automatically. Never target text already inside another author's pending tracked change. type='accept': requires target_id (string like 'Chg:12' from the Markdown projection); optional comment. type='reject': requires target_id (string like 'Chg:12'); optional comment. type='reply': requires target_id (string like 'Com:45') and text (string). type='insert_row': requires target_text (string anchoring a table cell), position ('above' or 'below'), and cells (array of strings, one per column). type='delete_row': requires target_text (string anchoring the row to delete). The whole batch is validated atomically: if any single edit fails (target text not found, ambiguous match under match_mode='strict', read-only target, overlapping another author's change), the entire batch is rejected and the document is left untouched. Example: '[{"type":"modify","target_text":"within thirty (30) days","new_text":"within forty-five (45) days","comment":"Per playbook.","match_mode":"all"}]'. Markdown code fences (\`\`\`json ... \`\`\`) wrapping the value are stripped automatically.`,typeOptions:{rows:10},displayOptions:{show:{resource:["document"],operation:["applyEdits"],editsSource:["defineBelow"]}}},{displayName:"Return Markdown Output",name:"returnMarkdown",type:"boolean",default:true,description:"Whether to auto-extract the post-edit document as Markdown (with CriticMarkup) and include it in the outgoing JSON under the 'markdown' field. Useful for feeding the updated state back into a downstream AI Agent for review or further edits. Adds extraction overhead per call.",displayOptions:{show:{resource:["document"],operation:["applyEdits"]}}}];async function di(t){let e=this.getNodeParameter("binaryPropertyName",t),n=this.getNodeParameter("outputBinaryPropertyName",t),r=this.getNodeParameter("author",t),s=this.getNodeParameter("editsSource",t),i=this.getNodeParameter("returnMarkdown",t),o=this.getNodeParameter("reasoning",t,""),l;if(s==="fromInputJson"){let N=this.getNodeParameter("editsJsonPath",t),A=this.getInputData()[t].json;if(l=gn(A,N),l===void 0)throw new Error(`No property "${N}" found on the input item JSON. Verify the upstream node produced it, or switch "Edits Source" to "Define Below".`)}else {let N=this.getNodeParameter("editsJson",t);l=yn.call(this,N,t,"Changes (JSON)");}if(!Array.isArray(l))throw new Error("Changes must be an array of DocumentChange objects.");l=wn(l);let u=this.getNodeParameter("documentSource",t,"fromInput")==="fromNode"?{mode:"fromNode",sourceNodeName:this.getNodeParameter("sourceNodeName",t,""),binaryPropertyName:e,sourceBinaryId:this.getNodeParameter("sourceBinaryId",t,"")}:{mode:"fromInput",binaryPropertyName:e},{buffer:c,fileName:d}=await le.call(this,t,u),f=await pe.load(c),p=new fn(f,r).process_batch(l),_=this.getInputData()[t].binary??{},g=await f.save(),w=ct(d,"redlined"),k=await this.helpers.prepareBinaryData(g,w,$e),b=typeof this.isToolExecution=="function"&&this.isToolExecution(),m;if(b&&k.id){let N=this.getWorkflowStaticData("global");N.adeu_last_redlined={id:k.id,fileName:w,mimeType:$e,timestamp:Date.now()},m=k.id;}let v;return i&&(v=await Re(g,false)),[{json:{fileName:w,author:r,stats:p,...o!==""?{reasoning:o}:{},...v!==void 0?{markdown:v}:{},...m!==void 0?{redlinedBinaryId:m}:{}},binary:{..._,[n]:k},pairedItem:{item:t}}]}y(di,"executeApplyEdits");var fi=[{displayName:"Original Document Source",name:"originalDocumentSource",type:"options",default:"fromInput",description:"Where to read the original (baseline) .docx file from. 'From Connected Input' reads from the current item; 'From Another Node' reads from a named upstream node \u2014 required when this node is called as an AI Agent tool.",options:[{name:"From Connected Input",value:"fromInput"},{name:"From Another Node",value:"fromNode"}],displayOptions:{show:{resource:["document"],operation:["generateDiff"]}}},{displayName:"Original Source Node Name",name:"originalSourceNodeName",type:"string",default:"",required:true,placeholder:"e.g. Download Original",description:"Exact name of the node whose output binary holds the original (baseline) .docx (string, case-sensitive). Must match the node label in the canvas exactly.",displayOptions:{show:{resource:["document"],operation:["generateDiff"],originalDocumentSource:["fromNode"]}}},{displayName:"Original Binary Property",name:"originalBinaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property holding the original (baseline) .docx file (string, e.g. 'data'). In 'From Connected Input' mode this reads from the current item; in 'From Another Node' mode this specifies which property on the source node's output to read.",displayOptions:{show:{resource:["document"],operation:["generateDiff"]}}},{displayName:"Modified Document Source",name:"modifiedDocumentSource",type:"options",default:"fromInput",description:"Where to read the modified (compared-to) .docx file from. 'From Connected Input' reads from the current item; 'From Another Node' reads from a named upstream node \u2014 required when this node is called as an AI Agent tool.",options:[{name:"From Connected Input",value:"fromInput"},{name:"From Another Node",value:"fromNode"}],displayOptions:{show:{resource:["document"],operation:["generateDiff"]}}},{displayName:"Modified Source Node Name",name:"modifiedSourceNodeName",type:"string",default:"",required:true,placeholder:"e.g. Apply Edits",description:"Exact name of the node whose output binary holds the modified (compared-to) .docx (string, case-sensitive). Must match the node label in the canvas exactly.",displayOptions:{show:{resource:["document"],operation:["generateDiff"],modifiedDocumentSource:["fromNode"]}}},{displayName:"Modified Binary Property",name:"modifiedBinaryPropertyName",type:"string",default:"data2",required:true,placeholder:"e.g. data2",description:"Name of the binary property holding the modified (compared-to) .docx file (string, e.g. 'data2'). In 'From Connected Input' mode this reads from the current item and must be different from the original property; in 'From Another Node' mode this specifies which property on the source node's output to read.",displayOptions:{show:{resource:["document"],operation:["generateDiff"]}}},{displayName:"Clean View",name:"cleanView",type:"boolean",default:true,description:"Whether to compare the Accept All clean view of both documents. When true (default, recommended), diffs reflect the final content as if all tracked changes were accepted. When false, diffs the raw CriticMarkup-projected text including pending change markers \u2014 useful for auditing tracked-change differences themselves.",displayOptions:{show:{resource:["document"],operation:["generateDiff"]}}},{displayName:"Diff Format",name:"diffFormat",type:"options",default:"wordPatch",description:"Format of the output diff. 'Word Patch' (default) produces an Adeu @@ Word Patch @@ text string showing sub-word modifications. 'Unified' produces a standard Git-style unified diff string. 'Structured Changes' produces a JSON array of DocumentChange objects suitable for feeding directly into Apply Edits.",options:[{name:"Word Patch",value:"wordPatch",description:"Adeu @@ Word Patch @@ sub-word text diff format"},{name:"Unified Diff",value:"unified",description:"Standard Git-style unified text diff format"},{name:"Structured Changes (JSON)",value:"structuredChanges",description:"JSON array of DocumentChange objects that transform original into modified"}],displayOptions:{show:{resource:["document"],operation:["generateDiff"]}}}];async function hi(t){let e=this.getNodeParameter("originalBinaryPropertyName",t),n=this.getNodeParameter("modifiedBinaryPropertyName",t),r=this.getNodeParameter("cleanView",t),s=this.getNodeParameter("diffFormat",t,"wordPatch"),i=this.getNodeParameter("originalDocumentSource",t,"fromInput"),o=this.getNodeParameter("modifiedDocumentSource",t,"fromInput"),l=i==="fromNode"?{mode:"fromNode",sourceNodeName:this.getNodeParameter("originalSourceNodeName",t,""),binaryPropertyName:e}:{mode:"fromInput",binaryPropertyName:e},a=o==="fromNode"?{mode:"fromNode",sourceNodeName:this.getNodeParameter("modifiedSourceNodeName",t,""),binaryPropertyName:n}:{mode:"fromInput",binaryPropertyName:n},{buffer:u,fileName:c}=await le.call(this,t,l),{buffer:d,fileName:f}=await le.call(this,t,a),h=zr(new Uint8Array(u),new Uint8Array(d));if(s==="structuredChanges"){let w=await pe.load(u),k=await pe.load(d),b=Qe(w,r,false,false,true),m=Qe(k,r,false,false,true),{edits:v,warnings:N}=Wr(b.text,b.structure,m.text,m.structure),A=[...h,...N];return [{json:{originalFileName:c,modifiedFileName:f,cleanView:r,diffFormat:s,changes:v,...A.length>0?{warnings:A}:{}},pairedItem:{item:t}}]}let p=await Re(u,r,false),_=await Re(d,r,false),g=s==="unified"?Lr(p,_):qr(p,_,c,f);return h.length>0&&(g=h.map(k=>`\u26A0\uFE0F ${k}`).join(`
152
+ ]`,required:true,description:`JSON-encoded string containing an array of DocumentChange objects. Each object has a 'type' field discriminator and type-specific fields. type='modify': requires target_text (string, copied EXACTLY from the source including punctuation, spacing, and case) and new_text (string); optional comment (string). Optional match_mode (one of 'strict' | 'first' | 'all', default 'strict'): 'strict' fails on ambiguous matches; 'first' silently anchors to the first occurrence; 'all' applies the same replacement to every occurrence in linear document order. Optional regex (boolean, default false): when true, target_text is interpreted as an ES2022 RegExp pattern and new_text may reference capture groups via $1, $2, etc. Combine with match_mode='all' for global regex replacements. Never include CriticMarkup tags like {++ ++} or {-- --} in new_text \u2014 the engine applies tracking automatically. Never target text already inside another author's pending tracked change. type='accept': requires target_id (string like 'Chg:12' from the Markdown projection); optional comment. type='reject': requires target_id (string like 'Chg:12'); optional comment. type='reply': requires target_id (string like 'Com:45') and text (string). type='insert_row': requires target_text (string anchoring a table cell), position ('above' or 'below'), and cells (array of strings, one per column). type='delete_row': requires target_text (string anchoring the row to delete). The whole batch is validated atomically: if any single edit fails (target text not found, ambiguous match under match_mode='strict', read-only target, overlapping another author's change), the entire batch is rejected and the document is left untouched. Example: '[{"type":"modify","target_text":"within thirty (30) days","new_text":"within forty-five (45) days","comment":"Per playbook.","match_mode":"all"}]'. Markdown code fences (\`\`\`json ... \`\`\`) wrapping the value are stripped automatically.`,typeOptions:{rows:10},displayOptions:{show:{resource:["document"],operation:["applyEdits"],editsSource:["defineBelow"]}}},{displayName:"Return Markdown Output",name:"returnMarkdown",type:"boolean",default:true,description:"Whether to auto-extract the post-edit document as Markdown (with CriticMarkup) and include it in the outgoing JSON under the 'markdown' field. Useful for feeding the updated state back into a downstream AI Agent for review or further edits. Adds extraction overhead per call.",displayOptions:{show:{resource:["document"],operation:["applyEdits"]}}}];async function _i(t){let e=this.getNodeParameter("binaryPropertyName",t),n=this.getNodeParameter("outputBinaryPropertyName",t),r=this.getNodeParameter("author",t),s=this.getNodeParameter("editsSource",t),i=this.getNodeParameter("returnMarkdown",t),o=this.getNodeParameter("reasoning",t,""),a;if(s==="fromInputJson"){let x=this.getNodeParameter("editsJsonPath",t),E=this.getInputData()[t].json;if(a=yn(E,x),a===void 0)throw new Error(`No property "${x}" found on the input item JSON. Verify the upstream node produced it, or switch "Edits Source" to "Define Below".`)}else {let x=this.getNodeParameter("editsJson",t);a=bn.call(this,x,t,"Changes (JSON)");}if(!Array.isArray(a))throw new Error("Changes must be an array of DocumentChange objects.");a=vn(a);let u=this.getNodeParameter("documentSource",t,"fromInput")==="fromNode"?{mode:"fromNode",sourceNodeName:this.getNodeParameter("sourceNodeName",t,""),binaryPropertyName:e,sourceBinaryId:this.getNodeParameter("sourceBinaryId",t,"")}:{mode:"fromInput",binaryPropertyName:e},{buffer:c,fileName:d}=await le.call(this,t,u),f=await pe.load(c),_=new _n(f,r).process_batch(a),p=this.getInputData()[t].binary??{},m=await f.save(),w=ct(d,"redlined"),k=await this.helpers.prepareBinaryData(m,w,$e),b=typeof this.isToolExecution=="function"&&this.isToolExecution(),g;if(b&&k.id){let x=this.getWorkflowStaticData("global");x.adeu_last_redlined={id:k.id,fileName:w,mimeType:$e,timestamp:Date.now()},g=k.id;}let v;return i&&(v=await je(m,false)),[{json:{fileName:w,author:r,stats:_,...o!==""?{reasoning:o}:{},...v!==void 0?{markdown:v}:{},...g!==void 0?{redlinedBinaryId:g}:{}},binary:{...p,[n]:k},pairedItem:{item:t}}]}y(_i,"executeApplyEdits");var mi=[{displayName:"Original Document Source",name:"originalDocumentSource",type:"options",default:"fromInput",description:"Where to read the original (baseline) .docx file from. 'From Connected Input' reads from the current item; 'From Another Node' reads from a named upstream node \u2014 required when this node is called as an AI Agent tool.",options:[{name:"From Connected Input",value:"fromInput"},{name:"From Another Node",value:"fromNode"}],displayOptions:{show:{resource:["document"],operation:["generateDiff"]}}},{displayName:"Original Source Node Name",name:"originalSourceNodeName",type:"string",default:"",required:true,placeholder:"e.g. Download Original",description:"Exact name of the node whose output binary holds the original (baseline) .docx (string, case-sensitive). Must match the node label in the canvas exactly.",displayOptions:{show:{resource:["document"],operation:["generateDiff"],originalDocumentSource:["fromNode"]}}},{displayName:"Original Binary Property",name:"originalBinaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property holding the original (baseline) .docx file (string, e.g. 'data'). In 'From Connected Input' mode this reads from the current item; in 'From Another Node' mode this specifies which property on the source node's output to read.",displayOptions:{show:{resource:["document"],operation:["generateDiff"]}}},{displayName:"Modified Document Source",name:"modifiedDocumentSource",type:"options",default:"fromInput",description:"Where to read the modified (compared-to) .docx file from. 'From Connected Input' reads from the current item; 'From Another Node' reads from a named upstream node \u2014 required when this node is called as an AI Agent tool.",options:[{name:"From Connected Input",value:"fromInput"},{name:"From Another Node",value:"fromNode"}],displayOptions:{show:{resource:["document"],operation:["generateDiff"]}}},{displayName:"Modified Source Node Name",name:"modifiedSourceNodeName",type:"string",default:"",required:true,placeholder:"e.g. Apply Edits",description:"Exact name of the node whose output binary holds the modified (compared-to) .docx (string, case-sensitive). Must match the node label in the canvas exactly.",displayOptions:{show:{resource:["document"],operation:["generateDiff"],modifiedDocumentSource:["fromNode"]}}},{displayName:"Modified Binary Property",name:"modifiedBinaryPropertyName",type:"string",default:"data2",required:true,placeholder:"e.g. data2",description:"Name of the binary property holding the modified (compared-to) .docx file (string, e.g. 'data2'). In 'From Connected Input' mode this reads from the current item and must be different from the original property; in 'From Another Node' mode this specifies which property on the source node's output to read.",displayOptions:{show:{resource:["document"],operation:["generateDiff"]}}},{displayName:"Clean View",name:"cleanView",type:"boolean",default:true,description:"Whether to compare the Accept All clean view of both documents. When true (default, recommended), diffs reflect the final content as if all tracked changes were accepted. When false, diffs the raw CriticMarkup-projected text including pending change markers \u2014 useful for auditing tracked-change differences themselves.",displayOptions:{show:{resource:["document"],operation:["generateDiff"]}}},{displayName:"Diff Format",name:"diffFormat",type:"options",default:"wordPatch",description:"Format of the output diff. 'Word Patch' (default) produces an Adeu @@ Word Patch @@ text string showing sub-word modifications. 'Unified' produces a standard Git-style unified diff string. 'Structured Changes' produces a JSON array of DocumentChange objects suitable for feeding directly into Apply Edits.",options:[{name:"Word Patch",value:"wordPatch",description:"Adeu @@ Word Patch @@ sub-word text diff format"},{name:"Unified Diff",value:"unified",description:"Standard Git-style unified text diff format"},{name:"Structured Changes (JSON)",value:"structuredChanges",description:"JSON array of DocumentChange objects that transform original into modified"}],displayOptions:{show:{resource:["document"],operation:["generateDiff"]}}}];async function gi(t){let e=this.getNodeParameter("originalBinaryPropertyName",t),n=this.getNodeParameter("modifiedBinaryPropertyName",t),r=this.getNodeParameter("cleanView",t),s=this.getNodeParameter("diffFormat",t,"wordPatch"),i=this.getNodeParameter("originalDocumentSource",t,"fromInput"),o=this.getNodeParameter("modifiedDocumentSource",t,"fromInput"),a=i==="fromNode"?{mode:"fromNode",sourceNodeName:this.getNodeParameter("originalSourceNodeName",t,""),binaryPropertyName:e}:{mode:"fromInput",binaryPropertyName:e},l=o==="fromNode"?{mode:"fromNode",sourceNodeName:this.getNodeParameter("modifiedSourceNodeName",t,""),binaryPropertyName:n}:{mode:"fromInput",binaryPropertyName:n},{buffer:u,fileName:c}=await le.call(this,t,a),{buffer:d,fileName:f}=await le.call(this,t,l),h=Jr(new Uint8Array(u),new Uint8Array(d));if(s==="structuredChanges"){let w=await pe.load(u),k=await pe.load(d),b=Qe(w,r,false,false,true),g=Qe(k,r,false,false,true),{edits:v,warnings:x}=qr(b.text,b.structure,g.text,g.structure),E=[...h,...x];return [{json:{originalFileName:c,modifiedFileName:f,cleanView:r,diffFormat:s,changes:v,...E.length>0?{warnings:E}:{}},pairedItem:{item:t}}]}let _=await je(u,r,false),p=await je(d,r,false),m=s==="unified"?Hr(_,p):Qr(_,p,c,f);return h.length>0&&(m=h.map(k=>`\u26A0\uFE0F ${k}`).join(`
153
153
  `)+`
154
154
 
155
- `+g),[{json:{originalFileName:c,modifiedFileName:f,cleanView:r,diffFormat:s,diff:g,...h.length>0?{warnings:h}:{}},pairedItem:{item:t}}]}y(hi,"executeGenerateDiff");var pi=[{displayName:"Reasoning",name:"reasoning",type:"string",default:"",typeOptions:{rows:2},description:"Why the document is being finalized now \u2014 e.g. what state it's in and why it's ready for distribution. State your reasoning BEFORE choosing the sanitize mode and options. This field is captured for auditability and is NOT forwarded into the finalize engine; its only purpose is to make the AI reason first. Safe to leave empty in deterministic (non-AI) pipelines.",displayOptions:{show:{resource:["document"],operation:["finalizeDocument"]}}},{displayName:"Input Binary Property",name:"binaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property holding the .docx file (string, e.g. 'data'). In 'From Connected Input' mode this reads from the current item; in 'From Another Node' mode this specifies which property on the source node's output to read. The file must be a valid .docx.",displayOptions:{show:{resource:["document"],operation:["finalizeDocument"]}}},{displayName:"Output Binary Property",name:"outputBinaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property on the outgoing item that will hold the finalized .docx file (string, e.g. 'data'). If equal to the input property name, the original binary is overwritten on the outgoing item.",displayOptions:{show:{resource:["document"],operation:["finalizeDocument"]}}},{displayName:"Sanitize Mode",name:"sanitizeMode",type:"options",default:"full",description:"How aggressively to sanitize the document before distribution. One of: 'baseline' (minimal metadata cleanup only), 'full' (strip metadata AND require all tracked changes resolved or auto-accepted), 'keep-markup' (strip metadata but preserve visible tracked changes and comments, optionally with author rewrite).",options:[{name:"Baseline",value:"baseline",description:"Minimal sanitization: strip RSID attributes, paragraph IDs, and proof errors only. Leaves tracked changes, comments, authors, and other metadata untouched."},{name:"Full",value:"full",description:"Strip metadata (authors, RSIDs, paragraph IDs, proof errors) and require all tracked changes and comments to be resolved. If pending tracked changes exist and 'Accept All Tracked Changes' is false, the operation is blocked and an error is thrown."},{name:"Keep Markup",value:"keep-markup",description:"Strip metadata but preserve all visible tracked changes and comments. Use 'Author Override' to rewrite the author name on every preserved redline and comment (e.g. replace 'AI Reviewer' with your firm name)."}],displayOptions:{show:{resource:["document"],operation:["finalizeDocument"]}}},{displayName:"Accept All Tracked Changes",name:"acceptAll",type:"boolean",default:false,description:"Whether to auto-accept all pending tracked changes before sanitization. Only applies when Sanitize Mode is 'full'. When false (default), the operation throws an error if any pending tracked changes exist, forcing the caller to resolve them first. If multiple distinct authors are detected in pending changes, a warning is included in the report to alert you of potential silent smuggles.",displayOptions:{show:{resource:["document"],operation:["finalizeDocument"],sanitizeMode:["full"]}}},{displayName:"Author Override",name:"authorOverride",type:"string",default:"",placeholder:"e.g. My Firm",description:"Only applies when Sanitize Mode is 'keep-markup'. Optional string. When set, replaces the author name on every preserved tracked change and comment with this value (e.g. 'My Law Firm'). Leave empty to keep original authors intact.",displayOptions:{show:{resource:["document"],operation:["finalizeDocument"],sanitizeMode:["keep-markup"]}}},{displayName:"Protection Mode",name:"protectionMode",type:"options",default:"none",description:"Optionally lock the finalized document. 'none' (default) leaves the document unlocked. 'read_only' injects a native Word read-only enforcement flag into settings.xml \u2014 Word users see a read-only banner and cannot edit without explicitly unlocking. AES encryption is not supported in this engine.",options:[{name:"None",value:"none"},{name:"Read Only",value:"read_only"}],displayOptions:{show:{resource:["document"],operation:["finalizeDocument"]}}}];async function _i(t){let e=this.getNodeParameter("binaryPropertyName",t),n=this.getNodeParameter("outputBinaryPropertyName",t),r=this.getNodeParameter("sanitizeMode",t),s=false;r==="full"&&(s=this.getNodeParameter("acceptAll",t));let i=null;if(r==="keep-markup"){let b=this.getNodeParameter("authorOverride",t);i=b.trim()===""?null:b;}let l=this.getNodeParameter("protectionMode",t)==="read_only"?"read_only":null,a=this.getNodeParameter("reasoning",t,""),c=this.getNodeParameter("documentSource",t,"fromInput")==="fromNode"?{mode:"fromNode",sourceNodeName:this.getNodeParameter("sourceNodeName",t,""),binaryPropertyName:e,sourceBinaryId:this.getNodeParameter("sourceBinaryId",t,"")}:{mode:"fromInput",binaryPropertyName:e},{buffer:d,fileName:f}=await le.call(this,t,c),h=await pe.load(d),{reportText:p,outBuffer:_}=await si(h,{filename:f,sanitize_mode:r,accept_all:s,protection_mode:l,author:i});if(!_)throw new Error(p);let g=ct(f,"finalized"),w=await this.helpers.prepareBinaryData(_,g,$e),k=this.getInputData()[t].binary??{};return [{json:{fileName:g,sanitizeMode:r,report:p,...a!==""?{reasoning:a}:{}},binary:{...k,[n]:w},pairedItem:{item:t}}]}y(_i,"executeFinalizeDocument");var mi=[{displayName:"Operation",name:"operation",type:"options",noDataExpression:true,displayOptions:{show:{resource:["document"]}},options:[{name:"Apply Edits",value:"applyEdits",action:"Apply tracked changes to document",description:"Apply a JSON array of DocumentChange objects (modify, accept, reject, reply, insert_row, delete_row) as native Word tracked changes and comments. modify edits support match_mode ('strict'|'first'|'all') and regex (boolean) for targeted multi-occurrence writes. The whole batch is pre-validated atomically: if any single edit is invalid, the entire batch is rejected with a per-edit error report and the document is left untouched."},{name:"Extract Markdown",value:"extractMarkdown",action:"Extract markdown from document",description:"Project the .docx into LLM-friendly Markdown with CriticMarkup ({++ins++}, {--del--}, {>>comment<<}) plus a Semantic Appendix listing defined terms, cross-references, and potential typos. Each tracked change is tagged with a stable ID (Chg:N, Com:N) for use in Apply Edits. Supports an optional Page parameter to fetch only one page of a large document (paired with Extract Outline for navigation)."},{name:"Extract Outline",value:"extractOutline",action:"Extract a structural outline of the document",description:"Return a token-cheap structural map of the .docx: a JSON array of headings with their level (1-6), text, page number, paragraph style, whether the section directly contains a table, and any footnote/endnote IDs scoped to that section. Also returns total_pages. Use this as a navigation primitive for large documents \u2014 call it first to discover structure, then call Extract Markdown with a specific Page to drill into the relevant section."},{name:"Finalize",value:"finalizeDocument",action:"Sanitize metadata and lock the document for distribution",description:"Strip author names, internal IDs, RSIDs, and proof errors; optionally auto-accept all pending tracked changes; optionally lock the document read-only. Use before sending to counterparties or signers."},{name:"Generate Diff",value:"generateDiff",action:"Generate diff between documents",description:"Produce a sub-word level @@ Word Patch @@ diff between two .docx files. Reads the document text via the same Markdown projection used by Extract Markdown, so the diff respects CriticMarkup and Clean View settings."},{name:"Hydrate Tool Output",value:"hydrateToolOutput",action:"Hydrate a redlined binary stashed by Apply Edits as a tool",description:"Read a binary's storage id from workflow static data (where Apply Edits stashes it when run as an AI Agent tool) and re-attach the binary to a main-flow item. Necessary because n8n's AI Agent tool wrapper strips binaries from tool outputs, so the redlined .docx produced by an apply_edits tool call cannot reach downstream nodes directly. Place this node downstream of the AI Agent on the main connection, then route its output into Write Binary File, Gmail (attachment), Slack (file upload), etc."}],default:"extractMarkdown"},{displayName:"Document Source",name:"documentSource",type:"options",default:"fromInput",description:"Where to read the .docx file from. 'From Connected Input' reads the binary on the current input item \u2014 use this in deterministic pipelines (e.g. Gmail Trigger \u2192 Adeu \u2192 Gmail Reply). 'From Another Node' fetches the binary from a named upstream node by name \u2014 use this when the Adeu node is called as an AI Agent tool, since the Agent cannot pass binary data through JSON arguments.",options:[{name:"From Connected Input",value:"fromInput",description:"Read the binary from the current item's binary attachment. Default behavior for deterministic workflows."},{name:"From Another Node",value:"fromNode",description:"Read the binary from a named upstream node. Required when this node is used as an AI Agent tool."}],displayOptions:{show:{resource:["document"],operation:["applyEdits","extractMarkdown","extractOutline","finalizeDocument"]}}},{displayName:"Source Node Name",name:"sourceNodeName",type:"string",default:"",required:true,placeholder:"e.g. Gmail Trigger",description:"Exact name of the node in this workflow whose output binary holds the .docx file (string, case-sensitive). Must match the node's label in the canvas exactly, including spaces and punctuation. The referenced node must have already executed in this run and produced binary output on the property named in 'Input Binary Property'.",displayOptions:{show:{resource:["document"],operation:["applyEdits","extractMarkdown","extractOutline","finalizeDocument"],documentSource:["fromNode"]}}},{displayName:"Source Binary ID",name:"sourceBinaryId",type:"string",default:"",placeholder:"e.g. filesystem-v2:...",description:"Optional. When set (such as by an AI Agent during a multi-turn conversation), the node will load the document directly from this binary storage ID instead of reading from the source node. Leave empty on the first call to default to the baseline source node.",displayOptions:{show:{resource:["document"],operation:["applyEdits","extractMarkdown","extractOutline","finalizeDocument"],documentSource:["fromNode"]}}},...oi,...li,...ui,...fi,...pi,...xn];var yi=class{static{y(this,"Adeu");}description={displayName:"Adeu",name:"adeu",icon:{light:"file:adeu.svg",dark:"file:adeu-dark.svg"},group:["transform"],version:1,subtitle:'={{$parameter["operation"]}}',description:"Operate on Microsoft Word (.docx) files: extract LLM-friendly Markdown with CriticMarkup, navigate large documents via a structural outline, apply tracked changes and comments, generate sub-word diffs, and sanitize/finalize documents. Five operations on the Document resource: (1) Extract Markdown \u2014 project a .docx into Markdown plus a Semantic Appendix; toggle Clean View to simulate Accept All; pass an optional Page number to fetch only one page of a large document. (2) Extract Outline \u2014 return a token-cheap structural map (headings with level, page number, paragraph style, has_table, footnote IDs) plus total_pages. Pair with Extract Markdown to navigate large documents. (3) Apply Edits \u2014 apply a JSON array of DocumentChange objects as native Word tracked changes; modify edits support match_mode ('strict'|'first'|'all') and regex (boolean); the entire batch is pre-validated atomically and rejected if any single edit is invalid. (4) Generate Diff \u2014 produce a @@ Word Patch @@ sub-word level diff between two .docx files. (5) Finalize Document \u2014 strip metadata, optionally accept all pending markup, and optionally lock the file read-only. DocumentChange schema (used by Apply Edits): each object has a 'type' field discriminator. type='modify' requires target_text (string, copied EXACTLY from the source including punctuation, spacing, and case) and new_text (string); optional comment (string); optional match_mode ('strict'|'first'|'all', default 'strict'); optional regex (boolean, default false \u2014 when true, target_text is an ES2022 RegExp pattern and new_text may reference $1, $2 capture groups). type='accept' or type='reject' requires target_id (string like 'Chg:12' from the Markdown projection); optional 'comment'. type='reply' requires target_id (string like 'Com:45') and text (string). type='insert_row' requires target_text (string), position ('above' or 'below'), and cells (array of strings). type='delete_row' requires target_text (string). Never wrap new_text in CriticMarkup tags like {++ ++} or {-- --}; the engine applies tracking automatically. Never target text already wrapped in another author's pending tracked change; accept or reject their change first by target_id. Binary handling for AI Agents: this tool cannot receive .docx files through JSON arguments because JSON cannot carry binary data. To process a document, set 'Document Source' to 'From Another Node' and 'Source Node Name' to the exact name of the workflow node that produced the .docx binary (typically the trigger node, e.g. 'Gmail Trigger', 'When clicking Test workflow', or an HTTP Request node configured to download a file). Node names are case-sensitive and must match the canvas label exactly. For the Generate Diff operation, set both 'Original Source Node Name' and 'Modified Source Node Name' independently.",defaults:{name:"Adeu"},usableAsTool:true,inputs:[n8nWorkflow.NodeConnectionTypes.Main],outputs:[n8nWorkflow.NodeConnectionTypes.Main],credentials:[],properties:[{displayName:"Resource",name:"resource",type:"options",noDataExpression:true,options:[{name:"Document",value:"document"}],default:"document"},...mi]};async execute(){let e=this.getInputData(),n=[],r=this.getNodeParameter("resource",0),s=this.getNodeParameter("operation",0);for(let i=0;i<e.length;i++)try{let o;if(r==="document")switch(s){case "extractMarkdown":o=await ai.call(this,i);break;case "extractOutline":o=await ci.call(this,i);break;case "applyEdits":o=await di.call(this,i);break;case "generateDiff":o=await hi.call(this,i);break;case "finalizeDocument":o=await _i.call(this,i);break;case "hydrateToolOutput":o=await Nn.call(this,i);break;default:throw new n8nWorkflow.NodeOperationError(this.getNode(),`Unsupported operation: ${s}`,{itemIndex:i})}else throw new n8nWorkflow.NodeOperationError(this.getNode(),`Unsupported resource: ${r}`,{itemIndex:i});n.push(...o);}catch(o){if(this.continueOnFail()){n.push({json:{error:o.message},pairedItem:{item:i}});continue}let l=o;throw l.name==="NodeOperationError"||l.name==="NodeApiError"?l:vn.call(this,l,i)}return [n]}};exports.Adeu=yi;
155
+ `+m),[{json:{originalFileName:c,modifiedFileName:f,cleanView:r,diffFormat:s,diff:m,...h.length>0?{warnings:h}:{}},pairedItem:{item:t}}]}y(gi,"executeGenerateDiff");var wi=[{displayName:"Reasoning",name:"reasoning",type:"string",default:"",typeOptions:{rows:2},description:"Why the document is being finalized now \u2014 e.g. what state it's in and why it's ready for distribution. State your reasoning BEFORE choosing the sanitize mode and options. This field is captured for auditability and is NOT forwarded into the finalize engine; its only purpose is to make the AI reason first. Safe to leave empty in deterministic (non-AI) pipelines.",displayOptions:{show:{resource:["document"],operation:["finalizeDocument"]}}},{displayName:"Input Binary Property",name:"binaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property holding the .docx file (string, e.g. 'data'). In 'From Connected Input' mode this reads from the current item; in 'From Another Node' mode this specifies which property on the source node's output to read. The file must be a valid .docx.",displayOptions:{show:{resource:["document"],operation:["finalizeDocument"]}}},{displayName:"Output Binary Property",name:"outputBinaryPropertyName",type:"string",default:"data",required:true,placeholder:"e.g. data",description:"Name of the binary property on the outgoing item that will hold the finalized .docx file (string, e.g. 'data'). If equal to the input property name, the original binary is overwritten on the outgoing item.",displayOptions:{show:{resource:["document"],operation:["finalizeDocument"]}}},{displayName:"Sanitize Mode",name:"sanitizeMode",type:"options",default:"full",description:"How aggressively to sanitize the document before distribution. One of: 'baseline' (minimal metadata cleanup only), 'full' (strip metadata AND require all tracked changes resolved or auto-accepted), 'keep-markup' (strip metadata but preserve visible tracked changes and comments, optionally with author rewrite).",options:[{name:"Baseline",value:"baseline",description:"Minimal sanitization: strip RSID attributes, paragraph IDs, and proof errors only. Leaves tracked changes, comments, authors, and other metadata untouched."},{name:"Full",value:"full",description:"Strip metadata (authors, RSIDs, paragraph IDs, proof errors) and require all tracked changes and comments to be resolved. If pending tracked changes exist and 'Accept All Tracked Changes' is false, the operation is blocked and an error is thrown."},{name:"Keep Markup",value:"keep-markup",description:"Strip metadata but preserve all visible tracked changes and comments. Use 'Author Override' to rewrite the author name on every preserved redline and comment (e.g. replace 'AI Reviewer' with your firm name)."}],displayOptions:{show:{resource:["document"],operation:["finalizeDocument"]}}},{displayName:"Accept All Tracked Changes",name:"acceptAll",type:"boolean",default:false,description:"Whether to auto-accept all pending tracked changes before sanitization. Only applies when Sanitize Mode is 'full'. When false (default), the operation throws an error if any pending tracked changes exist, forcing the caller to resolve them first. If multiple distinct authors are detected in pending changes, a warning is included in the report to alert you of potential silent smuggles.",displayOptions:{show:{resource:["document"],operation:["finalizeDocument"],sanitizeMode:["full"]}}},{displayName:"Author Override",name:"authorOverride",type:"string",default:"",placeholder:"e.g. My Firm",description:"Only applies when Sanitize Mode is 'keep-markup'. Optional string. When set, replaces the author name on every preserved tracked change and comment with this value (e.g. 'My Law Firm'). Leave empty to keep original authors intact.",displayOptions:{show:{resource:["document"],operation:["finalizeDocument"],sanitizeMode:["keep-markup"]}}},{displayName:"Protection Mode",name:"protectionMode",type:"options",default:"none",description:"Optionally lock the finalized document. 'none' (default) leaves the document unlocked. 'read_only' injects a native Word read-only enforcement flag into settings.xml \u2014 Word users see a read-only banner and cannot edit without explicitly unlocking. AES encryption is not supported in this engine.",options:[{name:"None",value:"none"},{name:"Read Only",value:"read_only"}],displayOptions:{show:{resource:["document"],operation:["finalizeDocument"]}}}];async function yi(t){let e=this.getNodeParameter("binaryPropertyName",t),n=this.getNodeParameter("outputBinaryPropertyName",t),r=this.getNodeParameter("sanitizeMode",t),s=false;r==="full"&&(s=this.getNodeParameter("acceptAll",t));let i=null;if(r==="keep-markup"){let b=this.getNodeParameter("authorOverride",t);i=b.trim()===""?null:b;}let a=this.getNodeParameter("protectionMode",t)==="read_only"?"read_only":null,l=this.getNodeParameter("reasoning",t,""),c=this.getNodeParameter("documentSource",t,"fromInput")==="fromNode"?{mode:"fromNode",sourceNodeName:this.getNodeParameter("sourceNodeName",t,""),binaryPropertyName:e,sourceBinaryId:this.getNodeParameter("sourceBinaryId",t,"")}:{mode:"fromInput",binaryPropertyName:e},{buffer:d,fileName:f}=await le.call(this,t,c),h=await pe.load(d),{reportText:_,outBuffer:p}=await ci(h,{filename:f,sanitize_mode:r,accept_all:s,protection_mode:a,author:i});if(!p)throw new Error(_);let m=ct(f,"finalized"),w=await this.helpers.prepareBinaryData(p,m,$e),k=this.getInputData()[t].binary??{};return [{json:{fileName:m,sanitizeMode:r,report:_,...l!==""?{reasoning:l}:{}},binary:{...k,[n]:w},pairedItem:{item:t}}]}y(yi,"executeFinalizeDocument");var vi=[{displayName:"Operation",name:"operation",type:"options",noDataExpression:true,displayOptions:{show:{resource:["document"]}},options:[{name:"Apply Edits",value:"applyEdits",action:"Apply tracked changes to document",description:"Apply a JSON array of DocumentChange objects (modify, accept, reject, reply, insert_row, delete_row) as native Word tracked changes and comments. modify edits support match_mode ('strict'|'first'|'all') and regex (boolean) for targeted multi-occurrence writes. The whole batch is pre-validated atomically: if any single edit is invalid, the entire batch is rejected with a per-edit error report and the document is left untouched."},{name:"Extract Markdown",value:"extractMarkdown",action:"Extract markdown from document",description:"Project the .docx into LLM-friendly Markdown with CriticMarkup ({++ins++}, {--del--}, {>>comment<<}) plus a Semantic Appendix listing defined terms, cross-references, and potential typos. Each tracked change is tagged with a stable ID (Chg:N, Com:N) for use in Apply Edits. Supports an optional Page parameter to fetch only one page of a large document (paired with Extract Outline for navigation)."},{name:"Extract Outline",value:"extractOutline",action:"Extract a structural outline of the document",description:"Return a token-cheap structural map of the .docx: a JSON array of headings with their level (1-6), text, page number, paragraph style, whether the section directly contains a table, and any footnote/endnote IDs scoped to that section. Also returns total_pages. Use this as a navigation primitive for large documents \u2014 call it first to discover structure, then call Extract Markdown with a specific Page to drill into the relevant section."},{name:"Finalize",value:"finalizeDocument",action:"Sanitize metadata and lock the document for distribution",description:"Strip author names, internal IDs, RSIDs, and proof errors; optionally auto-accept all pending tracked changes; optionally lock the document read-only. Use before sending to counterparties or signers."},{name:"Generate Diff",value:"generateDiff",action:"Generate diff between documents",description:"Produce a sub-word level @@ Word Patch @@ diff between two .docx files. Reads the document text via the same Markdown projection used by Extract Markdown, so the diff respects CriticMarkup and Clean View settings."},{name:"Hydrate Tool Output",value:"hydrateToolOutput",action:"Hydrate a redlined binary stashed by Apply Edits as a tool",description:"Read a binary's storage id from workflow static data (where Apply Edits stashes it when run as an AI Agent tool) and re-attach the binary to a main-flow item. Necessary because n8n's AI Agent tool wrapper strips binaries from tool outputs, so the redlined .docx produced by an apply_edits tool call cannot reach downstream nodes directly. Place this node downstream of the AI Agent on the main connection, then route its output into Write Binary File, Gmail (attachment), Slack (file upload), etc."}],default:"extractMarkdown"},{displayName:"Document Source",name:"documentSource",type:"options",default:"fromInput",description:"Where to read the .docx file from. 'From Connected Input' reads the binary on the current input item \u2014 use this in deterministic pipelines (e.g. Gmail Trigger \u2192 Adeu \u2192 Gmail Reply). 'From Another Node' fetches the binary from a named upstream node by name \u2014 use this when the Adeu node is called as an AI Agent tool, since the Agent cannot pass binary data through JSON arguments.",options:[{name:"From Connected Input",value:"fromInput",description:"Read the binary from the current item's binary attachment. Default behavior for deterministic workflows."},{name:"From Another Node",value:"fromNode",description:"Read the binary from a named upstream node. Required when this node is used as an AI Agent tool."}],displayOptions:{show:{resource:["document"],operation:["applyEdits","extractMarkdown","extractOutline","finalizeDocument"]}}},{displayName:"Source Node Name",name:"sourceNodeName",type:"string",default:"",required:true,placeholder:"e.g. Gmail Trigger",description:"Exact name of the node in this workflow whose output binary holds the .docx file (string, case-sensitive). Must match the node's label in the canvas exactly, including spaces and punctuation. The referenced node must have already executed in this run and produced binary output on the property named in 'Input Binary Property'.",displayOptions:{show:{resource:["document"],operation:["applyEdits","extractMarkdown","extractOutline","finalizeDocument"],documentSource:["fromNode"]}}},{displayName:"Source Binary ID",name:"sourceBinaryId",type:"string",default:"",placeholder:"e.g. filesystem-v2:...",description:"Optional. When set (such as by an AI Agent during a multi-turn conversation), the node will load the document directly from this binary storage ID instead of reading from the source node. Leave empty on the first call to default to the baseline source node.",displayOptions:{show:{resource:["document"],operation:["applyEdits","extractMarkdown","extractOutline","finalizeDocument"],documentSource:["fromNode"]}}},...ui,...fi,...pi,...mi,...wi,...kn];var Ni=class{static{y(this,"Adeu");}description={displayName:"Adeu",name:"adeu",icon:{light:"file:adeu.svg",dark:"file:adeu-dark.svg"},group:["transform"],version:1,subtitle:'={{$parameter["operation"]}}',description:"Operate on Microsoft Word (.docx) files: extract LLM-friendly Markdown with CriticMarkup, navigate large documents via a structural outline, apply tracked changes and comments, generate sub-word diffs, and sanitize/finalize documents. Five operations on the Document resource: (1) Extract Markdown \u2014 project a .docx into Markdown plus a Semantic Appendix; toggle Clean View to simulate Accept All; pass an optional Page number to fetch only one page of a large document. (2) Extract Outline \u2014 return a token-cheap structural map (headings with level, page number, paragraph style, has_table, footnote IDs) plus total_pages. Pair with Extract Markdown to navigate large documents. (3) Apply Edits \u2014 apply a JSON array of DocumentChange objects as native Word tracked changes; modify edits support match_mode ('strict'|'first'|'all') and regex (boolean); the entire batch is pre-validated atomically and rejected if any single edit is invalid. (4) Generate Diff \u2014 produce a @@ Word Patch @@ sub-word level diff between two .docx files. (5) Finalize Document \u2014 strip metadata, optionally accept all pending markup, and optionally lock the file read-only. DocumentChange schema (used by Apply Edits): each object has a 'type' field discriminator. type='modify' requires target_text (string, copied EXACTLY from the source including punctuation, spacing, and case) and new_text (string); optional comment (string); optional match_mode ('strict'|'first'|'all', default 'strict'); optional regex (boolean, default false \u2014 when true, target_text is an ES2022 RegExp pattern and new_text may reference $1, $2 capture groups). type='accept' or type='reject' requires target_id (string like 'Chg:12' from the Markdown projection); optional 'comment'. type='reply' requires target_id (string like 'Com:45') and text (string). type='insert_row' requires target_text (string), position ('above' or 'below'), and cells (array of strings). type='delete_row' requires target_text (string). Never wrap new_text in CriticMarkup tags like {++ ++} or {-- --}; the engine applies tracking automatically. Never target text already wrapped in another author's pending tracked change; accept or reject their change first by target_id. Binary handling for AI Agents: this tool cannot receive .docx files through JSON arguments because JSON cannot carry binary data. To process a document, set 'Document Source' to 'From Another Node' and 'Source Node Name' to the exact name of the workflow node that produced the .docx binary (typically the trigger node, e.g. 'Gmail Trigger', 'When clicking Test workflow', or an HTTP Request node configured to download a file). Node names are case-sensitive and must match the canvas label exactly. For the Generate Diff operation, set both 'Original Source Node Name' and 'Modified Source Node Name' independently.",defaults:{name:"Adeu"},usableAsTool:true,inputs:[n8nWorkflow.NodeConnectionTypes.Main],outputs:[n8nWorkflow.NodeConnectionTypes.Main],credentials:[],properties:[{displayName:"Resource",name:"resource",type:"options",noDataExpression:true,options:[{name:"Document",value:"document"}],default:"document"},...vi]};async execute(){let e=this.getInputData(),n=[],r=this.getNodeParameter("resource",0),s=this.getNodeParameter("operation",0);for(let i=0;i<e.length;i++)try{let o;if(r==="document")switch(s){case "extractMarkdown":o=await di.call(this,i);break;case "extractOutline":o=await hi.call(this,i);break;case "applyEdits":o=await _i.call(this,i);break;case "generateDiff":o=await gi.call(this,i);break;case "finalizeDocument":o=await yi.call(this,i);break;case "hydrateToolOutput":o=await En.call(this,i);break;default:throw new n8nWorkflow.NodeOperationError(this.getNode(),`Unsupported operation: ${s}`,{itemIndex:i})}else throw new n8nWorkflow.NodeOperationError(this.getNode(),`Unsupported resource: ${r}`,{itemIndex:i});n.push(...o);}catch(o){if(this.continueOnFail()){n.push({json:{error:o.message},pairedItem:{item:i}});continue}let a=o;throw a.name==="NodeOperationError"||a.name==="NodeApiError"?a:xn.call(this,a,i)}return [n]}};exports.Adeu=Ni;