n8n-nodes-adeu 2.1.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
'use strict';var n8nWorkflow=require('n8n-workflow');var
|
|
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,"&").replace(r,"<").replace(s,">").replace(i,"¶<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
|
|
4
|
-
`],r,s=0;s<this.diffs.length;s++){switch(this.diffs[s][0]){case Q:r="+";break;case
|
|
5
|
-
`;}return n.join("").replace(/%20/g," ")};
|
|
6
|
-
`):n,o=i.toLowerCase();if(r==="BatchValidationError"){let
|
|
7
|
-
`+i;return o.includes("target text not found")?(
|
|
8
|
-
`+i):o.includes("comment range from another author")?(
|
|
9
|
-
`+i):o.includes("another author")||o.includes("nested")?(
|
|
10
|
-
`+i):o.includes("control character")?(
|
|
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 "&":return "&";case "<":return "<";case ">":return ">";case """:return '"';case "'":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
|
-
`)}
|
|
13
|
-
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>`)),s}},pe=class
|
|
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(`
|
|
1
|
+
'use strict';var n8nWorkflow=require('n8n-workflow');var $i=Object.create;var It=Object.defineProperty;var Di=Object.getOwnPropertyDescriptor;var Oi=Object.getOwnPropertyNames;var Mi=Object.getPrototypeOf,Ri=Object.prototype.hasOwnProperty;var w=(t,e)=>It(t,"name",{value:e,configurable:true});var kn=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var ji=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Oi(e))!Ri.call(t,s)&&s!==n&&It(t,s,{get:()=>e[s],enumerable:!(r=Di(e,s))||r.enumerable});return t};var St=(t,e,n)=>(n=t!=null?$i(Mi(t)):{},ji(It(n,"default",{value:t,enumerable:true}),t));var Dn=kn((Ha,$n)=>{$n.exports={createRequire:w(function(){return function(){return {}}},"createRequire")};});var Ht=kn((Ga,ze)=>{var O=w(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"),X=-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(X,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]=X),s;if(o.length==1)return [new O.Diff(X,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 X: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,y=0;y<i&&!(new Date().getTime()>n);y++){for(var k=-y+h;k<=y-_;k+=2){var b=o+k,g;k==-y||k!=y&&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 N=o+d-k;if(N>=0&&N<a&&u[N]!=-1){var E=r-u[N];if(g>=E)return this.diff_bisectSplit_(t,e,g,v,n)}}}for(var C=-y+p;C<=y-m;C+=2){var N=o+C,E;C==-y||C!=y&&u[N-1]<u[N+1]?E=u[N+1]:E=u[N-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[N]=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(X,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}w(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 y=_.substring(m,m+Math.floor(_.length/4)),k=-1,b="",g,v,N,E;(k=p.indexOf(y,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),N=p.substring(0,k-A),E=p.substring(k+C));}return b.length*2>=_.length?[g,v,N,E,b]:null}w(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(X,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]==X&&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]=X,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),y=p.match(O.nonAlphaNumericRegex_),k=m.match(O.nonAlphaNumericRegex_),b=y&&p.match(O.whitespaceRegex_),g=k&&m.match(O.whitespaceRegex_),v=b&&p.match(O.linebreakRegex_),N=g&&m.match(O.linebreakRegex_),E=v&&h.match(O.blanklineEndRegex_),C=N&&_.match(O.blanklineStartRegex_);return E||C?5:v||N?4:y&&!b&&g?3:b||g?2:y||k?1:0}w(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]==X?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(X,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 X: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(X,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]!==X&&(r+=t[o][1].length),!(n>e));o++)s=n,i=r;return t.length!=o&&t[o][0]===X?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,"&").replace(r,"<").replace(s,">").replace(i,"¶<br>");switch(a){case Q:e[o]='<ins style="background:#e6ffe6;">'+u+"</ins>";break;case X: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]!==X&&(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 X: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 X: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(X,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 N=g/e.length,E=Math.abs(n-v);return s.Match_Distance?N+E/s.Match_Distance:E?1:N}w(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 y=p;y>=_;y--){var k=r[t.charAt(y-1)];if(h===0?m[y]=(m[y+1]<<1|1)&k:m[y]=(m[y+1]<<1|1)&k|((f[y+1]|f[y])<<1|1)|f[y+1],m[y]&l){var b=i(h,y-1);if(b<=o)if(o=b,a=y-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 X: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!==X&&(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]===X&&(e=e.substring(0,l+h)+e.substring(l+this.diff_xIndex(d,f+p[1].length))),p[0]!==X&&(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===X&&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(X,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
|
+
`],r,s=0;s<this.diffs.length;s++){switch(this.diffs[s][0]){case Q:r="+";break;case X:r="-";break;case z:r=" ";break}n[s+1]=r+encodeURI(this.diffs[s][1])+`
|
|
5
|
+
`;}return n.join("").replace(/%20/g," ")};ze.exports=O;ze.exports.diff_match_patch=O;ze.exports.DIFF_DELETE=X;ze.exports.DIFF_INSERT=Q;ze.exports.DIFF_EQUAL=z;});var $e="application/vnd.openxmlformats-officedocument.wordprocessingml.document";function En(t,e){return e.split(".").reduce((n,r)=>{if(n&&typeof n=="object")return n[r]},t)}w(En,"getNestedProperty");async function Bi(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}}w(Bi,"getDocxBuffer");async function le(t,e){if(e.mode==="fromInput")return Bi.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}}w(le,"getDocxBufferFromSource");function ct(t,e){let n=t.lastIndexOf(".");return `${n===-1?t:t.substring(0,n)}_${e}.docx`}w(ct,"buildOutputFileName");var Fi={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 Wi(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=Fi[e.trim().toLowerCase()];n===void 0?delete t.match_mode:t.match_mode=n;}}}w(Wi,"coerceChangeItemInPlace");function An(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)&&Wi(n),n})}w(An,"coerceChangesArray");function Cn(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})}}w(Cn,"parseJsonParameter");function Pn(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})}w(Pn,"mapAdeuErrorToNodeApiError");function zi(t){if(!t||typeof t!="object")return false;let e=t;return typeof e.id=="string"&&typeof e.fileName=="string"&&typeof e.mimeType=="string"}w(zi,"isStashedBinaryEntry");var In=[{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 Sn(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(!zi(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",y=new Date().toISOString().replace(/[:.]/g,"-").replace(/Z$/,"");_=h.replaceAll("{baseName}",p).replaceAll("{timestamp}",y).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}}]}w(Sn,"executeHydrateToolOutput");var Fn=St(Dn());var Li=(0, Fn.createRequire)("/"),Fe,Ui,qi;try{Fe=Li("worker_threads"),Ui=Fe.Worker,qi=Fe.isMarkedAsUntransferable;}catch{}var Y=Uint8Array,se=Uint16Array,Ut=Int32Array,dt=new Y([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 Y([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]),jt=new Y([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Wn=w(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 Ut(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=Wn(dt,2),zn=Fe.b,Bt=Fe.r;zn[28]=258,Bt[258]=28;var Ln=Wn(ft,0),Hi=Ln.b,On=Ln.r,Ft=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,Ft[q]=((ge&65280)>>8|(ge&255)<<8)>>1;var ge,q,he=w((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[Ft[d]>>l]=u;}else for(a=new se(r),s=0;s<r;++s)t[s]&&(a[s]=Ft[o[t[s]-1]++]>>15-t[s]);return a}),"hMap"),be=new Y(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,et=new Y(32);for(q=0;q<32;++q)et[q]=5;var q,Xi=he(be,9,0),Ji=he(be,9,1),Qi=he(et,5,0),Gi=he(et,5,1),Dt=w(function(t){for(var e=t[0],n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},"max"),ce=w(function(t,e,n){var r=e/8|0;return (t[r]|t[r+1]<<8)>>(e&7)&n},"bits"),Ot=w(function(t,e){var n=e/8|0;return (t[n]|t[n+1]<<8|t[n+2]<<16)>>(e&7)},"bits16"),qt=w(function(t){return (t+7)/8|0},"shft"),tt=w(function(t,e,n){return (e==null||e<0)&&(e=0),(n==null||n>t.length)&&(n=t.length),new Y(t.subarray(e,n))},"slc");var Yi=["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"],te=w(function(t,e,n){var r=new Error(e||Yi[t]);if(r.code=t,Error.captureStackTrace&&Error.captureStackTrace(r,te),!n)throw r;return r},"err"),Vi=w(function(t,e,n,r){var s=t.length,i=r?r.length:0;if(!s||e.f&&!e.l)return n||new Y(0);var o=!n,a=o||e.i!=2,l=e.i;o&&(n=new Y(s*3));var u=w(function(Ye){var Ve=n.length;if(Ye>Ve){var Be=new Y(Math.max(Ve*2,Ye));Be.set(n),n=Be;}},"cbuf"),c=e.f||0,d=e.p||0,f=e.b||0,h=e.l,_=e.d,p=e.m,m=e.n,y=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=Ji,_=Gi,p=9,m=5;else if(k==2){var N=ce(t,d,31)+257,E=ce(t,d+10,15)+4,C=N+ce(t,d+5,31)+1;d+=14;for(var A=new Y(C),x=new Y(19),P=0;P<E;++P)x[jt[P]]=ce(t,d+P*3,7);d+=E*3;for(var S=Dt(x),T=(1<<S)-1,B=he(x,S,1),P=0;P<C;){var D=B[ce(t,d,T)];d+=D&15;var b=D>>4;if(b<16)A[P++]=b;else {var I=0,R=0;for(b==16?(R=3+ce(t,d,3),d+=2,I=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++]=I;}}var j=A.subarray(0,N),F=A.subarray(N);p=Dt(j),m=Dt(F),h=he(j,p,1),_=he(F,m,1);}else te(1);else {var b=qt(d)+4,g=t[b-4]|t[b-3]<<8,v=b+g;if(v>s){l&&te(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>y){l&&te(0);break}}a&&u(f+131072);for(var L=(1<<p)-1,U=(1<<m)-1,G=d;;G=d){var I=h[Ot(t,d)&L],J=I>>4;if(d+=I&15,d>y){l&&te(0);break}if(I||te(2),J<256)n[f++]=J;else if(J==256){G=d,h=null;break}else {var H=J-254;if(J>264){var P=J-257,W=dt[P];H=ce(t,d,(1<<W)-1)+zn[P],d+=W;}var ne=_[Ot(t,d)&U],de=ne>>4;ne||te(3),d+=ne&15;var F=Hi[de];if(de>3){var W=ft[de];F+=Ot(t,d)&(1<<W)-1,d+=W;}if(d>y){l&&te(0);break}a&&u(f+131072);var _e=f+H;if(f<F){var at=i-F,lt=Math.min(F,_e);for(at+f<0&&te(3);f<lt;++f)n[f]=r[at+f];}for(;f<_e;++f)n[f]=n[f-F];}}e.l=h,e.p=G,e.b=f,e.f=c,h&&(c=1,e.m=p,e.d=_,e.n=m);}while(!c);return f!=n.length&&o?tt(n,0,f):n.subarray(0,f)},"inflt"),we=w(function(t,e,n){n<<=e&7;var r=e/8|0;t[r]|=n,t[r+1]|=n>>8;},"wbits"),Ze=w(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"),Mt=w(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:qn,l:0};if(s==1){var o=new Y(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 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),_=Wt(n[c-1],h,0);if(_>e){var r=0,p=0,m=_-e,y=1<<m;for(i.sort(function(N,E){return h[E.s]-h[N.s]||N.f-E.f});r<s;++r){var k=i[r].s;if(h[k]>e)p+=y-(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 Y(h),l:_}},"hTree"),Wt=w(function(t,e,n){return t.s==-1?Math.max(Wt(t.l,e,n+1),Wt(t.r,e,n+1)):e[t.s]=n},"ln"),Mn=w(function(t){for(var e=t.length;e&&!t[--e];);for(var n=new se(++e),r=0,s=t[0],i=1,o=w(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"),Ke=w(function(t,e){for(var n=0,r=0;r<e.length;++r)n+=t[r]*e[r];return n},"clen"),Un=w(function(t,e,n){var r=n.length,s=qt(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"),Rn=w(function(t,e,n,r,s,i,o,a,l,u,c){we(e,c++,n),++s[256];for(var d=Mt(s,15),f=d.t,h=d.l,_=Mt(i,15),p=_.t,m=_.l,y=Mn(f),k=y.c,b=y.n,g=Mn(p),v=g.c,N=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=Mt(E,7),x=A.t,P=A.l,S=19;S>4&&!x[jt[S-1]];--S);var T=u+5<<3,B=Ke(s,be)+Ke(i,et)+o,D=Ke(s,f)+Ke(i,p)+o+14+3*S+Ke(E,x)+2*E[16]+3*E[17]+7*E[18];if(l>=0&&T<=B&&T<=D)return Un(e,c,t.subarray(l,l+u));var I,R,j,F;if(we(e,c,1+(D<B)),c+=2,D<B){I=he(f,h,0),R=f,j=he(p,m,0),F=p;var L=he(x,P,0);we(e,c,b-257),we(e,c+5,N-1),we(e,c+10,S-4),c+=14;for(var C=0;C<S;++C)we(e,c+3*C,x[jt[C]]);c+=3*S;for(var U=[k,v],G=0;G<2;++G)for(var J=U[G],C=0;C<J.length;++C){var H=J[C]&31;we(e,c,L[H]),c+=x[H],H>15&&(we(e,c,J[C]>>5&127),c+=J[C]>>12);}}else I=Xi,R=be,j=Qi,F=et;for(var C=0;C<a;++C){var W=r[C];if(W>255){var H=W>>18&31;Ze(e,c,I[H+257]),c+=R[H+257],H>7&&(we(e,c,W>>23&31),c+=dt[H]);var ne=W&31;Ze(e,c,j[ne]),c+=F[ne],ne>3&&(Ze(e,c,W>>5&8191),c+=ft[ne]);}else Ze(e,c,I[W]),c+=R[W];}return Ze(e,c,I[256]),c+R[256]},"wblk"),Zi=new Ut([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),qn=new Y(0),Ki=w(function(t,e,n,r,s,i){var o=i.z||t.length,a=new Y(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=Zi[e-1],f=d>>13,h=d&8191,_=(1<<n)-1,p=i.p||new se(32768),m=i.h||new se(_+1),y=Math.ceil(n/3),k=2*y,b=w(function(Tt){return (t[Tt]^t[Tt+1]<<y^t[Tt+2]<<k)&_},"hsh"),g=new Ut(25e3),v=new se(288),N=new se(32),E=0,C=0,A=i.i||0,x=0,P=i.w||0,S=0;A+2<o;++A){var T=b(A),B=A&32767,D=m[T];if(p[B]=D,m[T]=B,P<=A){var I=o-A;if((E>7e3||x>24576)&&(I>423||!u)){c=Rn(t,l,0,g,v,N,C,x,S,A-S,c),x=E=C=0,S=A;for(var R=0;R<286;++R)v[R]=0;for(var R=0;R<30;++R)N[R]=0;}var j=2,F=0,L=h,U=B-D&32767;if(I>2&&T==b(A-U))for(var G=Math.min(f,I)-1,J=Math.min(32767,A),H=Math.min(258,I);U<=J&&--L&&B!=D;){if(t[A+j]==t[A+j-U]){for(var W=0;W<H&&t[A+W]==t[A+W-U];++W);if(W>j){if(j=W,F=U,W>G)break;for(var ne=Math.min(U,W-2),de=0,R=0;R<ne;++R){var _e=A-U+R&32767,at=p[_e],lt=_e-at&32767;lt>de&&(de=lt,D=_e);}}}B=D,D=p[B],U+=B-D&32767;}if(F){g[x++]=268435456|Bt[j]<<18|On[F];var Ye=Bt[j]&31,Ve=On[F]&31;C+=dt[Ye]+ft[Ve],++v[257+Ye],++N[Ve],P=A+j,++E;}else g[x++]=t[A],++v[t[A]];}}for(A=Math.max(A,P);A<o;++A)g[x++]=t[A],++v[t[A]];c=Rn(t,l,u,g,v,N,C,x,S,A-S,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 Be=A+65535;Be>=o&&(l[c/8|0]=u,Be=o),c=Un(l,c+1,t.subarray(A,Be));}i.i=o;}return tt(a,0,r+qt(c)+s)},"dflt"),es=(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})(),ts=w(function(){var t=-1;return {p:w(function(e){for(var n=t,r=0;r<e.length;++r)n=es[n&255^e[r]]^n>>>8;t=n;},"p"),d:w(function(){return ~t},"d")}},"crc");var ns=w(function(t,e,n,r,s){if(!s&&(s={l:1},e.dictionary)){var i=e.dictionary.subarray(-32768),o=new Y(i.length+t.length);o.set(i),o.set(t,i.length),t=o,s.w=i.length;}return Ki(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"),Hn=w(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 fe=w(function(t,e){return t[e]|t[e+1]<<8},"b2"),oe=w(function(t,e){return (t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0},"b4"),Rt=w(function(t,e){return oe(t,e)+oe(t,e+4)*4294967296},"b8"),ee=w(function(t,e,n){for(;n;++e)t[e]=n,n>>>=8;},"wbytes");function rs(t,e){return ns(t,e||{},0,0)}w(rs,"deflateSync");function is(t,e){return Vi(t,{i:2},e&&e.out,e&&e.dictionary)}w(is,"inflateSync");var Xn=w(function(t,e,n,r){for(var s in t){var i=t[s],o=e+s,a=r;Array.isArray(i)&&(a=Hn(r,i[1]),i=i[0]),ArrayBuffer.isView(i)?n[o]=[i,a]:(n[o+="/"]=[new Y(0),a],Xn(i,o,n,r));}},"fltn"),jn=typeof TextEncoder<"u"&&new TextEncoder,zt=typeof TextDecoder<"u"&&new TextDecoder,ss=0;try{zt.decode(qn,{stream:!0}),ss=1;}catch{}var os=w(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:tt(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 Y(t.length),r=0;r<t.length;++r)n[r]=t.charCodeAt(r);return n}if(jn)return jn.encode(t);for(var s=t.length,i=new Y(t.length+(t.length>>1)),o=0,a=w(function(c){i[o++]=c;},"w"),r=0;r<s;++r){if(o+5>i.length){var l=new Y(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 tt(i,0,o)}w(ut,"strToU8");function De(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(zt)return zt.decode(t);var s=os(t),i=s.s,n=s.r;return n.length&&te(8),i}}w(De,"strFromU8");var as=w(function(t,e){return e+30+fe(t,e+26)+fe(t,e+28)},"slzh"),ls=w(function(t,e,n){var r=fe(t,e+28),s=fe(t,e+30),i=De(t.subarray(e+46,e+46+r),!(fe(t,e+8)&2048)),o=e+46+r,a=cs(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 [fe(t,e+10),l,u,i,o+s+fe(t,e+32),c]},"zh"),cs=w(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+fe(t,e+2))if(fe(t,e)==1)return [a?Rt(t,e+4+8*l):s,l?Rt(t,e+4):i,u?Rt(t,e+4+8*(l+a)):o,1];r<2&&te(13);}return [s,i,o,0]},"z64hs"),Lt=w(function(t){var e=0;if(t)for(var n in t){var r=t[n].length;r>65535&&te(9),e+=r+4;}return e},"exfl"),Bn=w(function(t,e,n,r,s,i,o,a){var l=r.length,u=n.extra,c=a&&a.length,d=Lt(u);ee(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)&&te(10),ee(t,e,h<<25|f.getMonth()+1<<21|f.getDate()<<16|f.getHours()<<11|f.getMinutes()<<5|f.getSeconds()>>1),e+=4,i!=-1&&(ee(t,e,n.crc),ee(t,e+4,i<0?-i-2:i),ee(t,e+8,n.size)),ee(t,e+12,l),ee(t,e+14,d),e+=16,o!=null&&(ee(t,e,c),ee(t,e+6,n.attrs),ee(t,e+10,o),e+=14),t.set(r,e),e+=l,d)for(var _ in u){var p=u[_],m=p.length;ee(t,e,+_),ee(t,e+2,m),t.set(p,e+4),e+=4+m;}return c&&(t.set(a,e),e+=c),e},"wzh"),us=w(function(t,e,n,r,s){ee(t,e,101010256),ee(t,e+8,n),ee(t,e+10,n),ee(t,e+12,r),ee(t,e+16,s);},"wzf");function Jn(t,e){e||(e={});var n={},r=[];Xn(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=Lt(u.extra);f>65535&&te(11);var y=c?rs(l,u):l,k=y.length,b=ts();b.p(l),r.push(Hn(u,{size:l.length,crc:b.d(),c:y,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 Y(i+22),v=s,N=i-s,E=0;E<r.length;++E){var d=r[E];Bn(g,d.o,d,d.f,d.u,d.c.length);var C=30+d.f.length+Lt(d.extra);g.set(d.c,d.o+C),Bn(g,s,d,d.f,d.u,d.c.length,d.o,d.m),s+=16+C+(d.m?d.m.length:0);}return us(g,s,r.length,N,v),g}w(Jn,"zipSync");function We(t,e){for(var n={},r=t.length-22;oe(t,r)!=101010256;--r)(!r||t.length-r>65558)&&te(13);var s=fe(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=ls(t,i,o),d=c[0],f=c[1],h=c[2],_=c[3],p=c[4],m=c[5],y=as(t,m);i=p,(!l||l({name:_,size:f,originalSize:h,compression:d}))&&(d?d==8?n[_]=is(t.subarray(y,y+f),{out:new Y(h)}):te(14,"unknown compression type "+d):n[_]=tt(t,y,y+f));}return n}w(We,"unzipSync");var Or=St(Ht());var vn=St(Ht());var Me=1,un=3,dn=4,wr=8,fn=9,yr=class{static{w(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}},st=class vr extends yr{static{w(this,"_FastText");}constructor(e){super(),this.data=e;}data;nodeType=un;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 vr(this.data);return n.ownerDocument=this.ownerDocument,n}toString(){return Nt(this)}},br=class xr extends st{static{w(this,"_FastComment");}nodeType=wr;cloneNode(e){let n=new xr(this.data);return n.ownerDocument=this.ownerDocument,n}},ds=class Nr extends st{static{w(this,"_FastCData");}nodeType=dn;cloneNode(e){let n=new Nr(this.data);return n.ownerDocument=this.ownerDocument,n}},kr=class extends yr{static{w(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===fn?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}},Er=class Ar extends kr{static{w(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 Nt(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===un||r.nodeType===dn)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 st(String(e));n.ownerDocument=this.ownerDocument,n.parentNode=this,this.childNodes.push(n);}this.ownerDocument&&this.ownerDocument._inc++;}cloneNode(e=false){let n=new Ar(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}},fs=class extends kr{static{w(this,"FastDocument");}nodeType=fn;_inc=1;documentElement=null;get nodeName(){return "#document"}createElement(t){let e=new Er(t);return e.ownerDocument=this,e}createElementNS(t,e){return this.createElement(e)}createTextNode(t){let e=new st(String(t));return e.ownerDocument=this,e}createComment(t){let e=new br(String(t));return e.ownerDocument=this,e}toString(){return Nt(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}},hs=/&(?:amp|lt|gt|quot|apos|#x?[0-9a-fA-F]+);/g;function Cr(t){return t.indexOf("&")<0?t:t.replace(hs,e=>{switch(e){case "&":return "&";case "<":return "<";case ">":return ">";case """:return '"';case "'":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}}})}w(Cr,"decodeEntities");function Kt(t){return t.indexOf("\r")<0?t:t.replace(/\r\n?/g,`
|
|
12
|
+
`)}w(Kt,"normalizeLineEnds");function ps(t){let e=Kt(t),n=/[\n\t]/.test(e)?e.replace(/[\n\t]/g," "):e;return Cr(n)}w(ps,"normalizeAttrValue");var Xt=new Set([32,9,10,13]);function _s(t){t.charCodeAt(0)===65279&&(t=t.slice(1));let e=new fs,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 st(Cr(Kt(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 br(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 ds(Kt(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(Xt.has(d)||d===62||d===47)break;l++;}if(l===r)throw new Error(`Invalid tag at offset ${o}`);let u=new Er(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(Xt.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&&Xt.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,ps(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}w(_s,"parseFastXml");function ms(t){return /[&<>\r]/.test(t)?t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\r/g," "):t}w(ms,"escText");function gs(t){return /[&<>"\t\n\r]/.test(t)?t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/\t/g,"	").replace(/\n/g," ").replace(/\r/g," "):t}w(gs,"escAttr");function Nt(t){let e=[],n=w(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,'="',gs(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 un:e.push(ms(r.data));break;case dn:e.push("<![CDATA[",r.data,"]]>");break;case wr:e.push("<!--",r.data,"-->");break;case fn:for(let s of r.childNodes)n(s);break}},"write");return n(t),e.join("")}w(Nt,"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}w(M,"findChild");function Pr(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}w(Pr,"findChildren");function $(t,e){return Array.from(t.getElementsByTagName(e))}w($,"findAllDescendants");function He(t){return t.startsWith("\uFEFF")&&(t=t.slice(1)),_s(t)}w(He,"parseXml");function Qn(t){let e=Nt(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 y=p.split("=")[0].trim(),k=m.split("=")[0].trim(),b=y.startsWith("xmlns"),g=k.startsWith("xmlns");return b&&!g?-1:!b&&g?1:y<k?-1:y>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}w(Qn,"serializeXml");var yt=1,hn=2147483647;function pn(t){return ((t&hn)>>>0||yt).toString(16).toUpperCase().padStart(8,"0")}w(pn,"toLongHexNumber");function ht(){let t=hn-yt+1;return pn(yt+Math.floor(Math.random()*t))}w(ht,"generateLongHexNumber");function Gn(t){if(!/^[0-9A-Fa-f]{1,8}$/.test(t))return false;let e=parseInt(t,16);return e>=yt&&e<=hn}w(Gn,"isWordReadableLongHexNumber");var en="__adeu_wp_index_cache",Tr="__adeu_clean_inc";function kt(t){return typeof t._inc=="number"?t._inc:null}w(kt,"docInc");function nt(t){let e=kt(t);e!==null&&(t[Tr]=e);}w(nt,"markPartClean");function _n(t){let e=kt(t);return e!==null&&t[Tr]===e}w(_n,"isPartClean");function ws(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}w(ws,"buildWpIndexMap");function ys(t,e){let n=kt(t),r=t[en];(!r||n===null||r.inc!==n||!r.map.has(e))&&(r={inc:n??NaN,map:ws(t)},t[en]=r);let s=r.map.get(e);return s===void 0?-1:s}w(ys,"wpDocumentOrderIndex");function vs(t){let e=t[en],n=kt(t);e&&n!==null&&(e.inc=n);}w(vs,"resyncAfterOwnAttributeMutation");function Ir(t,e){let n=t.getElementsByTagName("w:p")[0],r=n?n.getAttribute("w14:paraId"):null;if(!r&&e){let s=t.ownerDocument,i=_n(s);n||(n=s.createElement("w:p"),t.appendChild(n));let o=ys(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=pn(a),n.setAttribute("w14:paraId",r),vs(s),i&&nt(s);}return {paraId:r,firstP:n}}w(Ir,"resolve_cell_anchor");var gt=class{static{w(this,"Relationship");}constructor(t,e,n,r){this.id=t,this.type=e,this.target=n,this.isExternal=r;}id;type;target;isExternal},Sr=class{static{w(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 gt(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);}}}},bs=class{static{w(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=He(n),s=new Sr(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 $r{static{w(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 bs(s),o=s["[Content_Types].xml"],a={};if(o){let _=He(De(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=De(p),y=He(m);nt(y);let k=a["/"+_]||"application/xml",b=new Sr("/"+_,m,y.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"),y=p.getAttribute("Target"),k=p.getAttribute("Type"),b=p.getAttribute("TargetMode");m&&y&&k&&f.rels.set(m,new gt(m,k,y,b==="External"));}}return new $r(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 gt(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 gt(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=Qn(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=Qn(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&&nt(r);}return Buffer.from(Jn(this.pkg.unzipped))}},ie=class{static{w(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{w(this,"Run");}constructor(t,e){this._element=t,this._parent=e;}_element;_parent},xs=class{static{w(this,"Cell");}constructor(t,e){this._element=t,this._parent=e;}_element;_parent},Ns=class{static{w(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 xs(n[r],this));}_element;_parent;cells=[]},Te=class{static{w(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 Ns(n[r],this));}_element;_parent;rows=[]},Yn=class{static{w(this,"NotesPart");}constructor(t,e){this.part=t,this.note_type=e,this._element=t._element;}part;note_type;_element},ks=class{static{w(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},re={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"},Z={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"},Vn=["w14:paraId","w15:paraId","w15:paraIdParent","w16cid:paraId"],Zn=["w16cid:durableId","w16cex:durableId"],Es=["w14:textId","w:rsidR","w:rsidRPr","w:rsidRDefault","w:rsidP","w:rsidDel","w:rsidTr"],Dr=class extends Error{static{w(this,"CommentThreadingError");}constructor(t){super(t),this.name="CommentThreadingError";}};function*tn(t){yield t;for(let e=0;e<t.childNodes.length;e++){let n=t.childNodes[e];n.nodeType===1&&(yield*tn(n));}}w(tn,"walkElements");var rt=class{static{w(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(Z.COMMENTS);if(t)return this._linkPart(t,xe.COMMENTS);let e=this.doc.pkg.nextPartname("/word/comments%d.xml"),n=`<w:comments xmlns:w="${re.w}" xmlns:w14="${re.w14}" xmlns:w15="${re.w15}" xmlns:w16cid="${re.w16cid}" xmlns:w16cex="${re.w16cex}" xmlns:mc="${re.mc}" mc:Ignorable="w14 w15 w16cid w16cex"></w:comments>`;return t=this.doc.pkg.addPart(e,Z.COMMENTS,n),this.doc.relateTo(t,xe.COMMENTS),t}_getOrCreateExtendedPart(){let t=this._getExistingPartByType(Z.EXTENDED);if(t)return this._linkPart(t,xe.EXTENDED);let e=this.doc.pkg.nextPartname("/word/commentsExtended%d.xml"),n=`<w15:commentsEx xmlns:w15="${re.w15}"></w15:commentsEx>`;return t=this.doc.pkg.addPart(e,Z.EXTENDED,n),this.doc.relateTo(t,xe.EXTENDED),t}_getOrCreateIdsPart(){let t=this._getExistingPartByType(Z.IDS);if(t)return this._linkPart(t,xe.IDS);let e=this.doc.pkg.nextPartname("/word/commentsIds%d.xml"),n=`<w16cid:commentsIds xmlns:w16cid="${re.w16cid}"></w16cid:commentsIds>`;return t=this.doc.pkg.addPart(e,Z.IDS,n),this.doc.relateTo(t,xe.IDS),t}_getOrCreateExtensiblePart(){let t=this._getExistingPartByType(Z.EXTENSIBLE);if(t)return this._linkPart(t,xe.EXTENSIBLE);let e=this.doc.pkg.nextPartname("/word/commentsExtensible%d.xml"),n=`<w16cex:commentsExtensible xmlns:w16cex="${re.w16cex}"></w16cex:commentsExtensible>`;return t=this.doc.pkg.addPart(e,Z.EXTENSIBLE,n),this.doc.relateTo(t,xe.EXTENSIBLE),t}_ensureNamespaces(){let t=this._commentsPart?._element;if(!t)return;let e=[["xmlns:w",re.w],["xmlns:w14",re.w14],["xmlns:w15",re.w15],["xmlns:w16cid",re.w16cid],["xmlns:w16cex",re.w16cex],["xmlns:mc",re.mc]];for(let[n,r]of e)t.getAttribute(n)||t.setAttribute(n,r);}_getNextCommentId(){let t=[0],e=this._getExistingPartByType(Z.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 ht()}_generateDurableId(){return ht()}_getInitials(t){return t?t.split(" ").filter(Boolean).map(e=>e[0]).join("").toUpperCase():""}_hasCommentsPart(){return this._commentsPart!==null||this._getExistingPartByType(Z.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(Z.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}_existingCommentPartElements(){let t=[];for(let e of [Z.COMMENTS,Z.EXTENDED,Z.IDS,Z.EXTENSIBLE]){let n=this._getExistingPartByType(e);n&&t.push(n._element);}return t}_freeLongHexNumber(t,e){let n=parseInt(t,16),r=Number.isNaN(n)?ht():pn(n);for(;e.has(r);)r=ht();return r}_repairInheritedLongHexNumbers(){let t=this._existingCommentPartElements();if(t.length===0)return;let e=w(s=>{let i=new Set,o=[];for(let l of t)for(let u of tn(l))for(let c of s){let d=u.getAttribute(c);d&&(Gn(d)?i.add(d.toUpperCase()):o.includes(d)||o.push(d));}let a=new Map;for(let l of o){let u=this._freeLongHexNumber(l,i);i.add(u),a.set(l,u);}return a},"remapFor"),n=e(Vn),r=e(Zn);for(let s of t)for(let i of tn(s)){for(let o of Vn){let a=n.get(i.getAttribute(o)??"");a&&i.setAttribute(o,a);}for(let o of Zn){let a=r.get(i.getAttribute(o)??"");a&&i.setAttribute(o,a);}for(let o of Es){let a=i.getAttribute(o);a&&!Gn(a)&&i.setAttribute(o,this._freeLongHexNumber(a,new Set));}}}_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=w((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){this._repairInheritedLongHexNumbers();let e=this._findThreadRootParaId(t),n=this._adoptIntoModernComments(t);return e??n}addComment(t,e,n=null){this._repairInheritedLongHexNumbers();let r=this._getExistingPartByType(Z.EXTENDED)!==null,s=null;if(n!=null&&(s=this.resolveThreadParentParaId(n),!s))throw new Dr(`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"),y=a.createElement("w:rStyle");y.setAttribute("w:val","CommentReference"),m.appendChild(y),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 N=this.idsPart._element.childNodes[v];if(N.nodeType===1&&N.getAttribute("w16cid:paraId")===c){g=N.getAttribute("w16cid:durableId");break}}if(g){let N=this.extensiblePart._element.ownerDocument.createElement("w16cex:commentExtensible");N.setAttribute("w16cex:durableId",g),N.setAttribute("w16cex:dateUtc",o),this.extensiblePart._element.appendChild(N);}}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:w(()=>{},"relateTo")});let r={},s=t.parts.find(l=>l.contentType===Z.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 y=m.join("").trim();r[u]={author:c,text:y,date:d,resolved:f,parent_id:_};}let a=t.parts.find(l=>l.contentType===Z.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}w(Re,"extract_comments_data");var Jt=500,Le=200,As=["{++","++}","{--","--}","{==","==}","{>>","<<}"];function Mr(t){if(!t||!t.includes("{")&&!t.includes("}"))return t;for(let e of As)if(t.includes(e)){let n=e.startsWith("{")?"{ "+e.slice(1):e.slice(0,-1)+" }";t=t.split(e).join(n);}return t}w(Mr,"escape_critic_tokens");function ue(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)}`}w(ue,"truncate_middle");var Cs={"\u201C":'"',"\u201D":'"',"\u2018":"'","\u2019":"'"},Ps=/[\u201c\u201d\u2018\u2019]/g;function Kn(t){return t&&t.replace(Ps,e=>Cs[e])}w(Kn,"normalize_smart_quotes");function nn(t){return !!t&&/[\u201c\u201d\u2018\u2019]/.test(t)}w(nn,"has_smart_quotes");function Ts(t,e){if(!t||!e||!nn(t))return e;let n=Kn(t),r=Kn(e);if(n===r)return t;let i=new Or.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("")}w(Ts,"restore_document_typography");function Is(t,e,n){return !n||!t||!nn(t)||nn(e||"")?n:Ts(t,n)}w(Is,"restore_matched_typography");var mn=2e3,Ce=class extends Error{static{w(this,"RegexTimeoutError");}pattern;constructor(t){super(`Regular expression exceeded the ${mn/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 Rr(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}w(Rr,"hasCatastrophicBacktrackingRisk");function Ss(t,e,n=""){if(Rr(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>mn)throw new Ce(t);o.push({start:a.index,end:a.index+a[0].length}),a.index===s.lastIndex&&s.lastIndex++;}return o}w(Ss,"userFindAllMatches");function $s(t,e,n=""){if(Rr(t))throw new Ce(t);let r=new RegExp(t,n.replace("g","")),s=Date.now(),i=r.exec(e);if(Date.now()-s>mn)throw new Ce(t);return i?{start:i.index,end:i.index+i[0].length}:null}w($s,"userSearch");var Ds="w:p",jr="w:r",gn="w:t",Os="w:delText",Ms="w:tab",Rs="w:br",js="w:cr",wn="w:rPr",Bs="w:rPrChange",Fs="w:commentReference",Ws="w:footnoteReference",zs="w:endnoteReference",Ls="w:fldChar",Us="w:fldCharType",qs="w:instrText",Hs="w:ins",Xs="w:del",Ne="w:id",Qt="w:author",Gt="w:date",Js="w:commentRangeStart",Qs="w:commentRangeEnd",Gs="w:hyperlink",Ys="r:id",Vs="w:fldSimple",Zs="w:instr",Ks="w:bookmarkStart",eo="w:name",Br="w:sdt",to="w:smartTag",Fr="w:sdtContent",Wr="w:b",no="w:i",ae="w:val",zr="w:pPr",Lr="w:pStyle",Ur="w:outlineLvl",ro="w:numPr",io="w:numId",so="w:ilvl",rn="w:drawing",sn="w:object",on="w:pict",oo="wp:docPr",ao="v:imagedata",lo="o:title",co="w:txbxContent",uo="mc:AlternateContent",fo="mc:Choice",ho="mc:Fallback",er=300;function tr(t){let e=[];for(let r of $(t,co))for(let s of $(r,gn))s.textContent&&e.push(s.textContent);let n=e.join(" ").split(/\s+/).filter(Boolean).join(" ");return n.length>er&&(n=n.slice(0,er).trimEnd()+"\u2026"),n}w(tr,"_textbox_text");function*nr(t){let e=t.tagName;if(e===rn||e===sn){let n=$(t,oo)[0]||null,r="",s="0";n&&(r=n.getAttribute("descr")||n.getAttribute("title")||"",s=n.getAttribute("id")||"0");let i=tr(t);i&&(r=r?`Text box (${r}): ${i}`:`Text box: ${i}`),yield {type:"image",id:s,date:r};}else if(e===on){let n=$(t,ao)[0]||null,r=n&&n.getAttribute(lo)||"",s=tr(t);s&&(r=r?`Text box (${r}): ${s}`:`Text box: ${s}`),(s||n)&&(yield {type:"image",id:"vml",date:r});}}w(nr,"_graphic_marker_events");var po=/Heading[ ]?([1-6])(?![0-9])/;function _o(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}w(_o,"_resolve_package");function Qe(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,y=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)&&(y=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 x=M(C,"w:ilvl");if(x){let P=x.getAttribute("w:val");P&&/^\d+$/.test(P)&&(b=parseInt(P,10));}}}let v=null,N=M(u,"w:rPr");if(N){let E=M(N,"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:y,bold:v,num_id:k,num_ilvl:b};}let a=w((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 y={name:d.name,outline_level:h,bold:_,num_id:p,num_ilvl:m};return n[u]=y,y},"resolve_style");for(let u in s)a(u,new Set);let l=[n,r];return e&&(e._adeu_style_cache=l),l}w(Qe,"_get_style_cache");function mo(t){let e=_o(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}w(mo,"_get_numbering_cache");function go(t,e,n){let r=null;if(e!=null){let s=mo(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. ":"* "}w(go,"get_list_marker");function qr(t){if(!t)return null;let e=t.match(po);return e?parseInt(e[1],10):null}w(qr,"_detect_heading_level_from_name");function Et(t,e,n){e||([e,n]=Qe(t._parent.part||t._parent));let r=M(t._element,zr);if(r){let a=M(r,Ur);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,Lr);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"&&qr(o)!==null)}w(Et,"is_native_heading");function Ie(t,e,n){e||([e,n]=Qe(t._parent.part||t._parent));let r=M(t._element,zr);if(r){let c=M(r,Ur);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,Lr);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,ro);if(c){let d=M(c,io);if(d){let f=d.getAttribute(ae);if(f==="0")u=true;else if(f){a=f;let h=M(c,so);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=go(t._parent?t._parent.part||t._parent:null,a,c);return " ".repeat(c)+d}if(o&&o!=="Normal"){let c=qr(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,jr);for(let p of _)if($(p,gn).map(k=>k.textContent||"").join("").trim()){let k=M(p,wn);if(k){let b=M(k,Wr);b&&b.getAttribute(ae)!=="0"&&b.getAttribute(ae)!=="false"&&(h=true);}break}}if(h)return "## "}}return ""}w(Ie,"get_paragraph_prefix");function Hr(t,e,n){let r=Ie(t,e,n);if(!r)return false;let s=r.trimEnd();return s.length>0&&s==="#".repeat(s.length)}w(Hr,"is_heading_paragraph");function Xr(t,e=null){let n="",r="",s=M(t._element,wn),i=false,o=false;if(s){let a=M(s,Wr);a&&a.getAttribute(ae)!=="0"&&a.getAttribute(ae)!=="false"&&(i=true);let l=M(s,no);l&&l.getAttribute(ae)!=="0"&&l.getAttribute(ae)!=="false"&&(o=true);}if(e===null){let a=t._parent;e=a instanceof ie?Et(a):false;}return i&&!e&&(n+="**",r="**"+r),o&&(n+="_",r="_"+r),[n,r]}w(Xr,"get_run_style_markers");function Jr(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)]}w(Jr,"split_boundary_whitespace");function Qr(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}w(Qr,"compute_change_pair_map");function wo(t,e,n){if(!e&&!n)return t;if(!t)return "";let r=w(i=>{let[o,a,l]=Jr(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)}
|
|
19
|
-
`);}return e}
|
|
18
|
+
`):r(t)}w(wo,"apply_formatting_to_segments");function Oe(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===gn||r.tagName===Os){let s=r.textContent||"";e+=s.replace(/\t/g," ");}else r.tagName===Ms?e+=" ":(r.tagName===Rs||r.tagName===js)&&(e+=`
|
|
19
|
+
`);}return e}w(Oe,"get_run_text");function*Se(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 ks(s,t,t.note_type));}return}yield*Gr(e,t);}w(Se,"iter_block_items");function*Gr(t,e){for(let n=0;n<t.childNodes.length;n++){let r=t.childNodes[n];if(r.nodeType===1){if(r.tagName===Ds)yield new ie(r,e);else if(r.tagName==="w:tbl")yield new Te(r,e);else if(r.tagName===Br){let s=M(r,Fr);s&&(yield*Gr(s,e));}}}}w(Gr,"_iter_block_children");function*yo(t){for(let[e]of yn(t))yield e;}w(yo,"iter_document_parts");function*yn(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 Yn(r,"fn"),"footnotes"]),s&&(yield [new Yn(s,"en"),"endnotes"]);}w(yn,"iter_document_parts_with_kind");function vo(t){if(!t)return false;let e=t.toUpperCase().trim().split(/\s+/);return e.length>0&&(e[0]==="PAGE"||e[0]==="NUMPAGES")}w(vo,"_is_page_instr");function Yr(t){return t?t.part?t.part:t.pkg&&t.pkg.mainDocumentPart?t.pkg.mainDocumentPart:t._parent?Yr(t._parent):null:null}w(Yr,"_get_part");function*At(t){let e=false,n="",r=false;function*s(o){let a=null,l=M(o,wn);if(l){let u=M(l,Bs);u&&(a=u.getAttribute(Ne),yield {type:"fmt_start",id:a,author:u.getAttribute(Qt)||void 0,date:u.getAttribute(Gt)||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===rn||d===sn||d===on)yield*nr(c);else if(d===uo){let f=null;for(let h of [fo,ho]){for(let _ of Pr(c,h))if(f=M(_,rn)||M(_,sn)||M(_,on),f)break;if(f)break}f&&(yield*nr(f));}else if(d===Fs){let f=c.getAttribute(Ne);f&&(yield {type:"ref",id:f});}else if(d===Ws){let f=c.getAttribute(Ne);f&&(yield {type:"footnote",id:f});}else if(d===zs){let f=c.getAttribute(Ne);f&&(yield {type:"endnote",id:f});}else if(d===Ls){let f=c.getAttribute(Us);if(f==="begin")e=true,n="";else if(f==="separate")if(vo(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===qs&&e&&!r&&(n+=c.textContent||"");}r||(yield new Ae(o,t)),a!==null&&(yield {type:"fmt_end",id:a});}w(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===jr)yield*s(l);else if(u===Hs){let c=l.getAttribute(Ne);yield {type:"ins_start",id:c,author:l.getAttribute(Qt)||void 0,date:l.getAttribute(Gt)||void 0},yield*i(l),yield {type:"ins_end",id:c};}else if(u===Xs){let c=l.getAttribute(Ne);yield {type:"del_start",id:c,author:l.getAttribute(Qt)||void 0,date:l.getAttribute(Gt)||void 0},yield*i(l),yield {type:"del_end",id:c};}else if(u===Js)yield {type:"start",id:l.getAttribute(Ne)};else if(u===Qs)yield {type:"end",id:l.getAttribute(Ne)};else if(u===Gs){let c=l.getAttribute(Ys)||l.getAttribute("id"),d="",f=Yr(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===Vs){let d=(l.getAttribute(Zs)||"").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===Ks){let c=l.getAttribute(eo);c&&(!c.startsWith("_")||c.startsWith("_Ref"))&&(yield {type:"bookmark",id:c});}else (u===Br||u===to||u===Fr)&&(yield*i(l));}}w(i,"traverse_node"),yield*i(t._element);}w(At,"iter_paragraph_content");var bo=new Set(["**","__","*","_"]),ke=class{static{w(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 yn(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
|
|
|
23
23
|
`,t,null),t+=2),e++;}for(;this.spans.length>0&&this.spans[this.spans.length-1].text===`
|
|
24
24
|
|
|
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]=
|
|
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]=Qe(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
|
|
28
|
+
`,n,null),n+=2;}let a=true,l=null;for(let u of Se(t))if(u.constructor.name==="FootnoteItem")n=this._map_blocks(u,n);else if(u instanceof ie){if(!a){let f=l instanceof ie?l:null;this._add_virtual_text(`
|
|
29
29
|
|
|
30
|
-
`,n,f),n+=2;}let d=
|
|
30
|
+
`,n,f),n+=2;}let d=Ie(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 ie?l:null;this._add_virtual_text(`
|
|
31
31
|
|
|
32
|
-
`,n,d),n+=2;}n=this._map_table(u,n),
|
|
33
|
-
`,n,null),n+=1),
|
|
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,
|
|
35
|
-
`)&&(N||
|
|
36
|
-
`);for(let
|
|
37
|
-
`,v,
|
|
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=
|
|
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:_}=Ir(d._element,n===f);if(h&&_){let p=new ie(_,d);this._add_virtual_text("",n,p),n>f&&(this._add_virtual_text(" ",n,p),n+=1);let y=`{#cell:${h}}`;this._add_virtual_text(y,n,p),n+=y.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=w(()=>{if(_.length===0)return;let[g,v]=d;g&&(this._add_virtual_text(g,s,t),s+=g.length);for(let[N,E,C,A,x,P,S]of _){if(N==="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:x||void 0,del_id:P||void 0,hyperlink_id:h||void 0,comment_ids:S.length>0?S: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(At(t)),y=Hr(t,n,r),k=Et(t,n,r),b=y;for(let g=0;g<m.length;g++){let v=m[g];if(v instanceof Ae){let[N,E]=Xr(v,k),C=[],A=Oe(v);if(b){if(A===""||/^\s*$/.test(A))continue;b=false;}let x=0,P=w(D=>{let[I,R,j]=Jr(D);if(!R){C.push(["real",D,v,x]),x+=D.length;return}I&&(C.push(["real",I,v,x]),x+=I.length),N&&C.push(["virtual",N,null,0]),C.push(["real",R,v,x]),x+=R.length,E&&C.push(["virtual",E,null,0]),j&&(C.push(["real",j,v,x]),x+=j.length);},"append_wrapped");if(A.includes(`
|
|
35
|
+
`)&&(N||E)){let D=A.split(`
|
|
36
|
+
`);for(let I=0;I<D.length;I++)I>0&&(C.push(["real",`
|
|
37
|
+
`,v,x]),x+=1),D[I]&&P(D[I]);}else (N||E)&&A?P(A):(N&&C.push(["virtual",N,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 S=C.map(D=>D[1]).join(""),T=Object.keys(a).pop()||null,B=Object.keys(l).pop()||null;if(S&&!(this.clean_view&&B)&&!(this.original_view&&T)){let D=this.clean_view||this.original_view?["",""]:this._get_wrappers(T,B,o,u),I=[N,E];if(_.length>0&&D[0]===d[0]&&D[1]===d[1]){let R=false;I[0]===f[0]&&I[1]===f[1]&&f[0]!==""&&_[_.length-1][0]==="virtual"&&_[_.length-1][1]===f[1]&&(_.pop(),R=true);let j=Array.from(o);for(let[F,L,U,G]of C){if(R&&F==="virtual"&&L===I[0]){R=false;continue}_.push([F,L,U,G,T,B,j]);}f=I;}else {p(),d=D,f=I;let R=Array.from(o);for(let[j,F,L,U]of C)_.push([j,F,L,U,T,B,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 I=false;if(T!==null||B!==null||Object.keys(u).length>0||o.size>0){let j=g+1,F=false,L=Object.keys(a).length,U=Object.keys(l).length,G=Object.keys(u).length,J=new Set(o);for(;j<m.length;){let H=m[j];if(H instanceof Ae){if(!Oe(H)){j++;continue}(L>0||U>0||G>0||J.size>0)&&(F=true);break}else {let W=H;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"?G++:W.type==="fmt_end"?G=Math.max(0,G-1):W.type==="start"?J.add(W.id):W.type==="end"&&J.delete(W.id);}j++;}F&&(I=true);}if(!I&&c.length>0){let j=this._build_merged_meta_block(c);if(j){p(),d=["",""],f=["",""];let F=`{>>${j}<<}`;this._add_virtual_text(F,s,t),s+=F.length;}c=[];}}}else {let N=v;if(b=false,p(),d=["",""],f=["",""],N.type==="start")o.add(N.id);else if(N.type==="end")o.delete(N.id);else if(N.type==="ins_start")a[N.id]=N;else if(N.type==="ins_end")delete a[N.id];else if(N.type==="del_start")l[N.id]=N;else if(N.type==="del_end")delete l[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(l).length>0||this.original_view&&Object.keys(a).length>0)){let A=`![${(N.date||"image").replace(/\]/g,")").replace(/\n/g," ")}](docx-image:${N.id})`;this._add_virtual_text(A,s,t,null,true),s+=A.length;}}else if(N.type==="footnote"||N.type==="endnote"){p(),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")p(),d=["",""],f=["",""],this._add_virtual_text("[",s,t,N.id),s+=1,h=N.id;else if(N.type==="hyperlink_end"){p(),d=["",""],f=["",""];let E=`](${N.date})`;this._add_virtual_text(E,s,t,N.id),s+=E.length,h=null;}else if(N.type==="xref_start")p(),d=["",""],f=["",""],this._add_virtual_text("[~",s,t),s+=2;else if(N.type==="xref_end"){p(),d=["",""],f=["",""];let E=`~](#${N.id})`;this._add_virtual_text(E,s,t),s+=E.length;}else if(N.type==="bookmark"){p(),d=["",""],f=["",""];let E=`{#${N.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=Qr(t),i=w(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(`${_}: ${Mr(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=w(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&&bo.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=$s(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=Ss(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=w((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(
|
|
41
|
-
`;)r--;
|
|
42
|
-
`)break;h--;}if(!
|
|
43
|
-
`);return e.length>0&&e.every(n=>n.includes(" | "))}
|
|
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(y=>y===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],[,y]=this._split_run_at_index(m,u);for(let k=0;k<i.length;k++)i[k]===m&&(i[k]=y);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=Oe(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=Oe(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 rr(t){let e=0,n=0,r=t.length,s=w(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}w(rr,"_count_standalone_underscores");function qe(t,e){if(!t||!e)return [0,0];let n=w(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=rr(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=w(y=>/[a-zA-Z0-9]/.test(y),"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=rr(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=w(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]}w(qe,"trim_common_context");function xo(t,e){let n=[],r={},s=/(\s+|[\p{L}\p{N}_]+|[^\p{L}\p{N}_\s])/gu,i=w(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]}w(xo,"_words_to_chars");function vt(t,e){let n=new vn.default.diff_match_patch;n.Diff_Timeout=2;let[r,s,i]=xo(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}w(vt,"generate_edits_from_text");function Vr(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=w(()=>{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}w(Vr,"_sequence_opcodes");function pt(t){let e=t.split(`
|
|
43
|
+
`);return e.length>0&&e.every(n=>n.includes(" | "))}w(pt,"_is_table_blob");function No(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}
|
|
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}w(No,"_table_blob_row_edits");function ko(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,107 @@ ${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
|
|
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:
|
|
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}w(ko,"_split_cross_paragraph_hunks");function Yt(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
|
-
`),
|
|
59
|
+
`),a=[],l=0;for(let d of i)a.push(l),l+=d.length+2;let u=Vr(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 y=m;for(let k=f;k<h;k++){let b=i[k]+`
|
|
60
60
|
|
|
61
|
-
`;c.push({type:"modify",target_text:b,new_text:"",comment:"Diff: Text deleted",_match_start_index:
|
|
61
|
+
`;c.push({type:"modify",target_text:b,new_text:"",comment:"Diff: Text deleted",_match_start_index:y}),y+=b.length;}}else {let y=i.slice(f,h).join(`
|
|
62
62
|
|
|
63
|
-
`),k=
|
|
63
|
+
`),k=m;f>0&&(y=`
|
|
64
64
|
|
|
65
|
-
`+
|
|
65
|
+
`+y,k-=2),c.push({type:"modify",target_text:y,new_text:"",comment:"Diff: Text deleted",_match_start_index:k});}else if(d==="insert"){let y=o.slice(_,p).join(`
|
|
66
66
|
|
|
67
|
-
`);f<i.length?
|
|
67
|
+
`);f<i.length?y=y+`
|
|
68
68
|
|
|
69
|
-
`:
|
|
69
|
+
`:y=`
|
|
70
70
|
|
|
71
|
-
`+
|
|
71
|
+
`+y,c.push({type:"modify",target_text:"",new_text:y,comment:"Diff: Text inserted",_match_start_index:m});}else if(d==="replace"){if(h-f===p-_&&Array.from({length:h-f}).some((g,v)=>pt(i[f+v])||pt(o[_+v]))){for(let g=0;g<h-f;g++){let v=i[f+g],N=o[_+g];if(v===N)continue;let E=a[f+g],C=pt(v)&&pt(N)?No(v,N):null;if(C!==null){c.push(...C);continue}let A=vt(v,N);for(let x of A)x._match_start_index=(x._match_start_index||0)+E,c.push(x);}continue}let y=i.slice(f,h).join(`
|
|
72
72
|
|
|
73
|
-
`),k=o.slice(p
|
|
73
|
+
`),k=o.slice(_,p).join(`
|
|
74
74
|
|
|
75
|
-
`),b=
|
|
76
|
-
`).slice(-n));let c=[];for(c.push(...u.map(f=>` ${f}`));
|
|
77
|
-
`);if(f===0){if(
|
|
75
|
+
`),b=vt(y,k);for(let g of b)g._match_start_index=(g._match_start_index||0)+m,c.push(g);}}return ko(c)}w(Yt,"generate_edits_via_paragraph_alignment");var wt=/!\[[^\]]*\]\(docx-image:[^)]*\)/g;function ir(t,e){let n=w(s=>s.replace(wt,"").replace(/\s+/g," ").trim(),"_normalized"),r=[];for(let s of t){let i=((s.target_text||"").match(wt)||[]).sort(),o=((s.new_text||"").match(wt)||[]).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}w(ir,"_drop_image_marker_hunks");function sr(t,e,n){let r=[];for(let o of e.matchAll(wt))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 () 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}w(sr,"_drop_marker_interior_hunks");function or(t,e){for(let n of e.rows)if(t.substring(n.start,n.end)!==n.cells.join(" | "))return false;return true}w(or,"_rows_are_plain");var an="";function Eo(t,e){let n=t.map(i=>i.cells.join(an)),r=e.map(i=>i.cells.join(an)),s=Vr(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}w(Eo,"_table_row_opcodes");function Ao(t,e,n,r){let s=t.rows,i=e.rows,o=s.map(_=>_.cells.join(an)),a=w(_=>_.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,y,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-y);for(let g=p+b;g<m;g++)l.add(g);for(let g=0;g<b;g++)u[p+g]=a(i[y+g]);}let c=[];for(let _=0;_<s.length;_++)l.has(_)||c.push(_);let d=w(_=>u[_]!==void 0?u[_]:a(s[_]),"anchor_text"),f=w((_,p)=>{let m=[],y=c.filter(b=>b<p),k=c.filter(b=>b>=p);if(y.length>0){let b=y[y.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,y,k]of n)if(_!=="equal")if(_==="replace"){let b=Math.min(m-p,k-y);for(let v=0;v<b;v++){let N=a(s[p+v]),E=a(i[y+v]);N!==E&&h.push({type:"modify",target_text:N,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(y+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(y,k),p));return h}w(Ao,"_row_ops_for_table");function Zr(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:[...sr(ir(Yt(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,y]=l[p],[k,b]=u[p],g=e.tables.filter(A=>m<=A.start&&A.end<=y),v=r.tables.filter(A=>k<=A.start&&A.end<=b),N=g.length===v.length&&g.every(A=>or(t,A))&&v.every(A=>or(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.`),!N){let A=Yt(t.substring(m,y),n.substring(k,b));for(let x of A)x._match_start_index=(x._match_start_index||0)+m;i.push(...A);continue}let E=[[m,m],...g.map(A=>[A.start,A.end]),[y,y]],C=[[k,k],...v.map(A=>[A.start,A.end]),[b,b]];for(let A=0;A<E.length-1;A++){let x=E[A][1],P=E[A+1][0],S=C[A][1],T=C[A+1][0],B=Yt(t.substring(x,P),n.substring(S,T));for(let D of B)D._match_start_index=(D._match_start_index||0)+x;if(i.push(...B),A<g.length){let D=g[A],I=v[A],R=Eo(D.rows,I.rows);if(R!==null)i.push(...Ao(D,I,R,s));else for(let j=0;j<D.rows.length;j++){let F=D.rows[j].cells.join(" | "),L=I.rows[j].cells.join(" | ");F!==L&&i.push({type:"modify",target_text:F,new_text:L,comment:"Diff: Table row modified",_is_table_edit:true});}}}}let c=w((p,m)=>{let y=0,k=0;for(;;){let b=p.indexOf(m,k);if(b===-1)break;y++,k=b+m.length;}return y},"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(sr(ir(f,s),t,s));return {edits:i.filter(p=>p.type!=="modify"||h.has(p)),warnings:s}}w(Zr,"generate_structured_edits");function Kr(t,e){let n=w(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 y=0;y<_.length;y++)p=Math.imul(p^_[y],16777619)>>>0,m=Math.imul(m^_[_.length-1-y],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.`]}w(Kr,"collect_media_difference_warnings");function ei(t,e,n=3){let r=new vn.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
|
-
`)}
|
|
80
|
-
`)}
|
|
81
|
-
`,e)+1,r=t.substring(0,n).trimEnd(),s=t.substring(n);return [r,s]}
|
|
79
|
+
`)}w(ei,"create_unified_diff");var bt=/\{\+\+|\{--|\{==|\{>>|\+\+\}|--\}|==\}|<<\}/g,Co={"{++":"++}","{--":"--}","{==":"==}","{>>":"<<}"};function ar(t){if(!t)return true;if(/\{[=+\-><]?$/.test(t)||/^[=+\-><]?\}/.test(t))return false;let e=[];bt.lastIndex=0;let n;for(;(n=bt.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}w(ar,"_critic_payload_atomic");function ti(t,e,n,r){let s=true;for(;s;){s=false;for(let i of [t,e]){let o=i.length-r;bt.lastIndex=0;let a;for(;(a=bt.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)]}w(ti,"_clamp_trim_outside_critic_tokens");function Po(t,e){let[n,r]=qe(t,e);return [n,r]=ti(t,e,n,r),[t.substring(n,t.length-r),e.substring(n,e.length-r)]}w(Po,"_word_patch_displays");function To(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]=Po(s,i);if(ar(l)&&ar(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}w(To,"_merge_critic_split_hunks");function ni(t,e,n="Original",r="Modified"){let s=To(vt(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]=ti(u,c,d,f);let h=u.length-f,_=c.length-f,p=u.substring(d,h),m=c.substring(d,_),y=l+d,k=y+p.length,b=Math.max(0,y-o),g=t.substring(b,y);b>0&&(g="..."+g);let v=Math.min(t.length,k+o),N=t.substring(k,v);v<t.length&&(N=N+"..."),g=g.replace(/\n/g," ").replace(/\r/g,""),N=N.replace(/\n/g," ").replace(/\r/g,""),i.push("@@ Word Patch @@"),i.push(` ${g}`),p&&i.push(`- ${p}`),m&&i.push(`+ ${m}`),i.push(` ${N}`),i.push("");}return i.join(`
|
|
80
|
+
`)}w(ni,"create_word_patch_diff");var lr=19e3,Io="<!-- READONLY_BOUNDARY_START -->",cr={"{++":"++}","{--":"--}","{==":"==}","{>>":"<<}"},So=/\bChg:(\d+)\b/g;function Xe(t){if(!t)return ["",""];let e=t.indexOf(Io);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]}w(Xe,"split_structural_appendix");function Je(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:ur(u),page_content:u}],total_pages:1,body_pages:[""],body_page_offsets:[0]}}let n=$o(t),[r,s]=Mo(n),i;if(e&&e.trim()){let l=e.trim();i=r.map(u=>u?`${u}
|
|
82
82
|
|
|
83
|
-
${
|
|
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:ur(l),page_content:l})),total_pages:o,body_pages:r,body_page_offsets:s}}w(Je,"paginate");function $o(t){let e=Do(t);return Oo(e)}w($o,"_tokenize_into_atomic_blocks");function Do(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(cr))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(cr))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(
|
|
86
|
-
`;)u++;s=u,r=s;continue}s++;}}if(r<i){let o=t.substring(r,i);o&&n.push([o,r]);}return n}
|
|
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}w(Do,"_split_on_safe_paragraph_breaks");function Oo(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}`,
|
|
88
|
+
${u}`,l++;else break}e.push([a,s]),n=l;}return e}w(Oo,"_merge_footnote_sections");function Mo(t){if(!t.length)return [[""],[0]];let e=[],n=[],r=[],s=0,i=-1,o=w(()=>{r.length>0&&(e.push(r.join(`
|
|
89
89
|
|
|
90
|
-
`)),n.push(i)),r=[],s=0,i=-1;},"flush_current");for(let[l
|
|
91
|
-
`)}
|
|
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>lr&&o(),r.length===0&&u>lr){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]]}w(Mo,"_assemble_pages");function ur(t){let e=[...t.matchAll(So)];return new Set(e.map(r=>r[1])).size}w(ur,"_count_tracked_changes");var Ro=5,dr=50;function jo(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,Ro),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-dr),f=Math.min(n.length,c+dr),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?"...":"",y=f<n.length?"...":"";a.push(` ${l+1}. "${m}${h}[${p}]${_}${y}"`);}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
|
+
`)}w(jo,"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}w(ve,"getNextElement");function Ee(t){let e=t.previousSibling;for(;e;){if(e.nodeType===1)return e;e=e.previousSibling;}return null}w(Ee,"getPreviousElement");function Ue(t,e){e.parentNode&&e.parentNode.insertBefore(t,e.nextSibling);}w(Ue,"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 a=o._element.ownerDocument;a&&_n(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}}w(Bo,"takeSnapshot");function Fo(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=He(n.blob);nt(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;}}}w(Fo,"restoreSnapshot");function Wo(t,e){if(!t||!e)return [t,e];if(e.includes(`
|
|
92
|
+
`))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]}w(Wo,"stripMatchingHeadingHashes");var _t=class extends Error{static{w(this,"BatchValidationError");}errors;constructor(t){super(`Batch validation failed:
|
|
92
93
|
`+t.join(`
|
|
93
|
-
`)),this.name="BatchValidationError",this.errors=t;}};function
|
|
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).`}
|
|
95
|
-
Did you mean the literal "${r}"? It appears in the document (\u2026${
|
|
94
|
+
`)),this.name="BatchValidationError",this.errors=t;}};function fr(t){return `
|
|
95
|
+
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).`}w(fr,"sequential_context_hint");var zo=/[\x00-\x08\x0b\x0c\x0e-\x1f]/g,Lo={"w:sectPr":new Set(["w:headerReference","w:footerReference"])},ln=["w:ins","w:del"],cn=["w:pPrChange","w:rPrChange","w:sectPrChange"],Vt=[...ln,...cn];function Uo(t){if(!t)return null;let e=t.match(zo);return e?Array.from(new Set(e.map(r=>`0x${r.charCodeAt(0).toString(16).padStart(2,"0")}`))).sort().join(", "):null}w(Uo,"describe_illegal_control_chars");function qo(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=Uo(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 () 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}w(qo,"validate_edit_strings");var bn=class V{static{w(this,"_RedlineEngine");}doc;author;timestamp;current_id;mapper;comments_manager;clean_mapper=null;original_mapper=null;skipped_details=[];removed_comment_notes=[];rollback_verified=true;_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=_n(i);s._element.setAttribute("xmlns:w16du",r),o&&nt(i);}this.current_id=this._scan_existing_ids(),this.mapper=new ke(this.doc),this.comments_manager=new rt(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=vt(e,n);}catch{a=[];}let l=w(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 `
|
|
96
|
+
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=ue(f,Le),h=ue(h,Le);let _;if(!f&&!h){let m=ue(s,Le),y=m?`{==${m}==}`:"";_=`${n.substring(0,n.length-s.length)}${y}${r}`;}else {let m=f?`{--${f}--}`:"",y=h?`{++${h}++}`:"";_=`${n}${m}${y}${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(y=>String(y))),r=new Set((e._minted_comment_ids||[]).map(y=>String(y)));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 y of s.spans)(y.ins_id&&n.has(String(y.ins_id))||y.del_id&&n.has(String(y.del_id))||r.size>0&&y.comment_ids&&y.comment_ids.some(b=>r.has(String(b))))&&o.push([y.start,y.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=w(y=>y,"to_visible");if(l.length>0){let y=[],k=0;for(let[b,g]of l)y.push(i.substring(k,b)),k=g;y.push(i.substring(k)),c=y.join(""),d=w(b=>{let g=0;for(let[v,N]of l)if(b>=N)g+=N-v;else if(b>v){g+=b-v;break}else break;return b-g},"to_visible");}o.sort((y,k)=>y[0]-k[0]);let f=[];for(let[y,k]of o){let b=d(y),g=d(k),v=Math.max(0,b-ye),N=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],N):f.push([v,N]);}let h=[];for(let[y,k]of f){let b=c.substring(y,k);b=V._tidy_preview_context(b,"before"),b=V._tidy_preview_context(b,"after"),h.push(b);}let _=h.join(`
|
|
96
97
|
\u2026
|
|
97
|
-
`),_=p
|
|
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||this._is_last_paragraph_in_cell(f)?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
|
-
"${
|
|
98
|
+
`),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 [ue(_,m),ue(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=ue(s,Le),_=ue(i,Le),p=h?`{--${h}--}`:"",m=_?`{++${_}++}`:"",y=`${d}${p}${m}${f}`,k=y;return k=k.replace(/\{>>.*?<<\}/gs,""),k=k.replace(/\{--.*?--\}/gs,""),k=k.replace(/\{\+\+(.*?)\+\+\}/gs,"$1"),[y,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(`
|
|
99
|
+
`),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 y=m.parentNode;if(y){if(y.tagName==="w:trPr"){y.removeChild(m);continue}for(;m.firstChild;)y.insertBefore(m.firstChild,m);y.removeChild(m);}}let _=$(f,"w:p");for(let m of _){let y=M(m,"w:pPr");if(y){let k=M(y,"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 N of $(m,v)){if(v==="w:t"&&!N.textContent)continue;let E=false,C=N.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 y=m.parentNode;if(y)if(y.tagName==="w:trPr"){let k=y.parentNode;k&&k.parentNode&&k.parentNode.removeChild(k);}else y.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(y=>y.nodeType===1&&y.tagName!=="w:rPr"&&y.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=Lo[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));}_is_native_heading_element(e){try{let n=this.doc.part||this.doc,[r,s]=Qe(n);return Et({_element:e},r,s)}catch{return false}}_clone_pPr_scrubbing_headings(e,n=null){let r=e.cloneNode(true),s=M(r,"w:pStyle");if(s){let o=s.getAttribute("w:val");o&&(o.startsWith("Heading")||o==="Title"||o.replace(/\s+/g,"").startsWith("Heading")||n!==null&&this._is_native_heading_element(n))&&r.removeChild(s);}let i=M(r,"w:outlineLvl");return i&&r.removeChild(i),r}_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 B=m?T:T.nextSibling;for(;B;)B.nodeType===1&&f.has(B.tagName)&&d.push(B),B=B.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[y,k]=this._parse_markdown_style(u[0]),g=k!==null&&c!==null,v=null,N=null;g||(N=this._build_tracked_ins_for_line((y===u[0],u[0]),n,s,l,o),v=N);let E=g?u:u.slice(1);if(E.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 A=w((T,B)=>{C.insertBefore(T,B.nextSibling);},"insertAfterEl"),x=null,P=null,S=c;for(let T=0;T<E.length;T++){let B=E[T],[D,I]=this._parse_markdown_style(B),R=l.createElement("w:p");if(I)this._set_paragraph_style(R,I);else {let G=M(c,"w:pPr");G&&R.appendChild(this._clone_pPr_scrubbing_headings(G,c));}let j=M(R,"w:pPr");j||(j=l.createElement("w:pPr"),R.insertBefore(j,R.firstChild));let F=M(j,"w:rPr");F||(F=l.createElement("w:rPr"),j.appendChild(F));let L=this._create_track_change_tag("w:ins","",s);F.appendChild(L);let U=this._build_tracked_ins_for_line(D,n,s,l,o);U&&R.appendChild(U),A(R,S),S=R,x=R,P=U,v||(v=R);}if(!g&&x&&d.length>0)for(let T of d)T.parentNode?.removeChild(T),x.appendChild(T);return {first_node:v,last_p:x,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(x=>String(x.partname).replace(/^\//,"")==="word/numbering.xml");if(!s){let x=`<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,x),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 x of o){let P=x.getAttribute("w:abstractNumId");if(P!==null){for(let S of $(x,"w:lvl")){if((S.getAttribute("w:ilvl")||"0")!=="0")continue;let T=M(S,"w:numFmt");T&&T.getAttribute("w:val")==="bullet"&&(l=P);break}if(l!==null)break}}let u=0;for(let x of a){let P=parseInt(x.getAttribute("w:numId")||"0",10);!isNaN(P)&&P>u&&(u=P);}let c=i.ownerDocument;if(l!==null){for(let S of a){let T=M(S,"w:abstractNumId");if(T&&T.getAttribute("w:val")===l){let B=S.getAttribute("w:numId");if(B&&B!=="0")return B}}let x=c.createElement("w:num");x.setAttribute("w:numId",String(u+1));let P=c.createElement("w:abstractNumId");return P.setAttribute("w:val",l),x.appendChild(P),i.appendChild(x),delete e._adeu_numbering_cache,String(u+1)}let d=-1;for(let x of o){let P=parseInt(x.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 y=c.createElement("w:lvlText");y.setAttribute("w:val","\uF0B7"),_.appendChild(y);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"),N=c.createElement("w:rFonts");N.setAttribute("w:ascii","Symbol"),N.setAttribute("w:hAnsi","Symbol"),N.setAttribute("w:hint","default"),v.appendChild(N),_.appendChild(v),f.appendChild(_);let E=a.find(x=>x.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(...qo(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(y=>y.run!==null&&y.end>_&&y.start<_+p);return m.length===0?true:m.some(y=>!y.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(y=>y.end>_&&y.start<_+p);for(let y of m)if(y.run!==null){let k=y.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:
|
|
100
|
+
"${ue(i.target_text,Jt)}"${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(jo(s+1+n,i.target_text,u,h));}if(l.length===1){let[h,_]=l[0],p=u.substring(h,h+_),[m,y]=qe(p,i.new_text||""),k=p.length-y,b=p.substring(m,k),g=(i.new_text||"").substring(m,(i.new_text||"").length-y),N=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,x)=>A-x):[];if(N.length>1){let A=N.map(x=>c.part_kind_of(x)||"?").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+_-y;if(C>E&&c.spans.filter(x=>x.end>E&&x.start<C&&(x.run!==null||x.text.trim()!=="")).some(x=>x.is_image_marker)&&r.push(`- Edit ${s+1+n} Failed: the target overlaps a read-only image marker (). 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
101
|
|
|
101
|
-
`)&&!(
|
|
102
|
+
`)&&!(p.split(`
|
|
102
103
|
|
|
103
104
|
`).length===(i.new_text||"").split(`
|
|
104
105
|
|
|
105
|
-
`).length))if(
|
|
106
|
+
`).length))if(g.includes(`
|
|
106
107
|
|
|
107
|
-
`)){let
|
|
108
|
+
`)){let x=p.split(`
|
|
108
109
|
|
|
109
|
-
`);
|
|
110
|
+
`);x.length>=2&&x[0].trim()!==""&&x[x.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 x=b.split(`
|
|
110
111
|
|
|
111
|
-
`);
|
|
112
|
+
`);x.length>=2&&x[0].trim()!==""&&x[x.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,y=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(N=>N.getAttribute("w:id")===b.ins_id);if(v.length>0){let N=v[0].getAttribute("w:author");N&&N!==this.author&&(m.add(N),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&&y.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}y.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(y).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
113
|
`)||!i.includes(" | "))return false;let o=i.split(`
|
|
113
|
-
`).filter(
|
|
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}_is_last_paragraph_in_cell(e){let n=e.parentNode;for(;n&&n.tagName!=="w:tc";)n=n.parentNode;return n?I(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 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(`
|
|
114
|
+
`).filter(l=>l.includes(" | ")).length,a=s.split(`
|
|
115
|
+
`).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)}_batch_fingerprint(){let e=0,n=new Set;for(let r of Vt)for(let s of this._revisionsByTag(r))e++,s.id&&n.add(s.id);return [e,[...n].sort().join(","),this._existing_comment_ids().join(",")].join("|")}_restore_batch_snapshot(e,n){e&&(Fo(this.doc,e),this.current_id=n,this.mapper=new ke(this.doc),this.comments_manager=new rt(this.doc),this.clean_mapper=null,this._revisionIndex=null);}_verify_rollback(e){if(e!==null)try{this.rollback_verified=this._batch_fingerprint()===e;}catch{this.rollback_verified=false;}}_process_batch_internal(e){this.rollback_verified=true;for(let v of e)if(v&&typeof v=="object"&&v.type==="modify"&&v.target_text&&v.new_text){let[N,E]=Wo(v.target_text,v.new_text);v.target_text=N,v.new_text=E;}this.skipped_details=[];let n=e.filter(v=>v!==null&&typeof v=="object"&&["accept","reject","reply"].includes(v.type)),r=e.filter(v=>v===null||typeof v!="object"||!["accept","reject","reply"].includes(v.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 _t(a);let l=0,u=0,c=0,f=n.length>0||r.length>0?Bo(this.doc):null,h=n.length>0?this._batch_fingerprint():null,_=this.current_id;if(n.length>0){try{let v=this.apply_review_actions(n);if(l=v[0],u=v[1],c=v[2],u>0)throw new _t(this.skipped_details)}catch(v){throw this._restore_batch_snapshot(f,_),this._verify_rollback(h),v}l>0&&(this.mapper._build_map(),this.clean_mapper&&this.clean_mapper._build_map());}let[p]=Xe(this.mapper.full_text),y=Je(p,"").body_page_offsets,k=[],b=0,g=0;if(r.length>0){let v=w(E=>E._resolved_start_idx!==void 0&&E._resolved_start_idx!==null?E._resolved_start_idx:E._match_start_index!==void 0&&E._match_start_index!==null?E._match_start_index:null,"pinned_idx"),N=r.map((E,C)=>({edit:E,i:C})).sort((E,C)=>{let A=v(E.edit),x=v(C.edit);return A===null&&x===null?E.i-C.i:A===null?1:x===null?-1:x-A||E.i-C.i});{try{let E=[],C=0;for(let{edit:A,i:x}of N){let P;try{P=this.validate_edits([A],x);}catch(S){if(!(S instanceof Ce))throw S;P=[`- Edit ${x+1} Failed: ${S.message}`];}if(P.length>0){if(C>0){let S=fr(C);P=P.map(T=>T+S);}E.push(...P);}else if(this.apply_edits([A],y),A._applied_status&&!A._any_sub_failure)C++,this.mapper=new ke(this.doc),this.clean_mapper=null;else {let S=A._error_msg||`- Edit ${x+1} Failed: Failed to apply edit.`;C>0&&(S+=fr(C)),E.push(S);break}}if(E.length>0)throw new _t(E)}catch(E){throw this._restore_batch_snapshot(f,_),this._verify_rollback(h),E}b=r.filter(E=>E._applied_status&&!E._any_sub_failure).length,g=r.length-b;for(let E of r){let C=E._applied_status||false,A=E._error_msg||null,x=null,P=null,S=E._warning||null;if(C){let T=this._build_edit_context_previews(E);x=T[0],P=T[1];}else S=S||this._check_punctuation_warning(E.target_text||"");k.push({status:C?"applied":"failed",type:E.type||"modify",target_text:ue(E.target_text||"",Jt),new_text:ue(V._report_new_text(E),Jt),comment:E.comment??null,warning:S,error:A,critic_markup:x,clean_text:P,pages:E._pages||[],heading_path:E._heading_path||"",occurrences_modified:E._occurrences_modified||0,match_mode:E.match_mode||"strict"});}}}if(b>0)try{this._warn_stranded_comment_anchors(_);}catch{}return {actions_applied:l,actions_skipped:u,actions_already_resolved:c,edits_applied:b,edits_skipped:g,occurrences_modified:k.reduce((v,N)=>v+(N.occurrences_modified||0),0),skipped_details:this.skipped_details,edits:k,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]=Xe(this.mapper.full_text);n=Je(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 y=m[0],[k,b]=f.get_insertion_anchor(y,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 y of m){let k={...c,_resolved_start_idx:y[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 y=`- Failed to locate row target: '${(c.target_text||"").trim().substring(0,40)}...'`;this.skipped_details.push(y),c._error_msg=y;}}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,y=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=y;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,N]=this._get_heading_path_and_page(f,this.mapper.full_text,n),E=g._pages||[];E.includes(N)||E.unshift(N),g._pages=E,g._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),E=c._pages||[];E.includes(N)||E.unshift(N),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=w(d=>{let f=d.getAttribute("w:id");f&&i.add(f);},"add_id");o(e);let a=w(d=>{let f=d;for(;f&&f.tagName!=="w:p";)f=f.parentNode;return f},"paragraph_of"),l=w(d=>{let f=M(d,"w:pPr"),h=f?M(f,"w:rPr"):null;return h?M(h,"w:ins"):null},"mark_of"),u=w(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=w((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 Vt)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 Vt)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)})}_warn_stranded_comment_anchors(e){let n;try{n=$(this.doc.element,"w:commentRangeStart");}catch{return}if(n.length===0)return;let r=w(l=>{let u=new Map,c=0,d=w(f=>{u.set(f,c++);for(let h=f.firstChild;h;h=h.nextSibling)h.nodeType===1&&d(h);},"walk");return d(l),u},"order"),s=w(l=>{let u=l.parentNode;for(;u&&u.nodeType===1;){if(u.tagName==="w:p")return u;u=u.parentNode;}return null},"paragraphOf"),i=w((l,u)=>{let c=l.parentNode;for(;c&&c.nodeType===1&&c!==u;){if(c.tagName==="w:del")return true;c=c.parentNode;}return false},"hasDeletedAncestorWithin"),o=null,a=[];for(let l of n){let u=l.getAttribute("w:id");if(!u)continue;let c=s(l);if(!c)continue;let d=$(c,"w:commentRangeEnd").find(b=>b.getAttribute("w:id")===u);if(!d)continue;let f=r(c),h=f.get(l),_=f.get(d);if(h===void 0||_===void 0||_<h)continue;let p="";for(let b of $(c,"w:t")){let g=f.get(b);g===void 0||g<h||g>_||i(b,c)||(p+=b.textContent||"");}if(!p.trim())continue;let m=false,y=false,k=false;for(let b of $(c,"w:del")){let g=f.get(b);if(g===void 0)continue;let v=g<h?"before":g>_?"after":null;if(!v||!$(b,"w:delText").some(C=>(C.textContent||"").trim()))continue;v==="before"?m=true:y=true;let E=b.getAttribute("w:id")||"";/^\d+$/.test(E)&&parseInt(E,10)>e&&(k=true);}m&&y&&k&&(o===null&&(o=this._comment_authors()),a.push([u,p.trim()]));}for(let[l,u]of a){let c=o?.[l],d=c?`comment Com:${l} (by ${c})`:`comment Com:${l}`;this.skipped_details.push(`- Warning: this batch deleted text on both sides of ${d} but left its anchored text "${ue(u,60)}" in place, so once the changes are accepted that text stands alone in its sentence. If you kept it to preserve the comment's anchor, re-read the sentence; if you meant to remove the clause, extend one edit over the anchored text too. The edits themselves were applied.`);}}_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 x=a.target_id.replace("Com:","");if(!this._existing_comment_ids().includes(x)){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,x);}catch(S){if(S instanceof Dr){r++,this.skipped_details.push(`- Action ${l+1} Failed: reply on ${a.target_id} \u2014 ${S.message}`);continue}throw S}this._anchor_reply_comment(x,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(x=>x.id===c).map(x=>x.el),h=this._revisionsByTag("w:del").filter(x=>x.id===c).map(x=>x.el),_=[...f,...h],p=cn.flatMap(x=>this._revisionsByTag(x).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(x=>x.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 y=new Set([c]);for(let x of _)for(let P of this._get_paired_nodes(x)){let S=P.getAttribute("w:id");S&&y.add(S);}let k=ln.flatMap(x=>this._revisionsByTag(x)),b=-1;for(;b!==y.size;){b=y.size;for(let x of k)if(!(!x.id||!y.has(x.id)))for(let P of x.nested)P.id&&y.add(P.id);}let g=[];for(let x of ln)for(let P of this._revisionsByTag(x))P.id&&y.has(P.id)&&g.push(P.el);let v=cn.flatMap(x=>this._revisionsByTag(x).filter(P=>P.id!==null&&y.has(P.id)).map(P=>P.el)),N=new Set;for(let x of [...g,...v]){let P=x.getAttribute("w:id");P&&N.add(P);}let E=this._comment_authors(),C=new Set(Object.keys(E)),A=[];for(let x of g){let P=x.tagName==="w:ins",S=x.parentNode?x.parentNode.tagName:"",T=S==="w:trPr",B=P&&S==="w:rPr"&&!!x.parentNode?.parentNode&&x.parentNode.parentNode.tagName==="w:pPr";if(u==="accept")if(P)if(T)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),T){let D=x.parentNode?.parentNode;D?.parentNode?.removeChild(D);}else x.parentNode?.removeChild(x);else if(u==="reject")if(P){if(B){let D=x.parentNode;x.parentNode?.removeChild(x),D=D?.parentNode,D=D?.parentNode,D&&D.tagName==="w:p"&&A.push(D);continue}if(this._clean_wrapping_comments(x),this._delete_comments_in_element(x),T){let D=x.parentNode?.parentNode;D?.parentNode?.removeChild(D);}else x.parentNode?.removeChild(x);}else if(T)x.parentNode?.removeChild(x);else {let D=Array.from(x.getElementsByTagName("w:delText"));for(let I of D){let R=I.ownerDocument.createElement("w:t");R.textContent=I.textContent,I.hasAttribute("xml:space")&&R.setAttribute("xml:space","preserve"),I.parentNode?.replaceChild(R,I);}for(;x.firstChild;)x.parentNode?.insertBefore(x.firstChild,x);x.parentNode?.removeChild(x);}}for(let x of A.reverse()){if(!x.parentNode)continue;let P=Ee(x);for(;P&&P.tagName!=="w:p";)P=Ee(P);if(P){for(let S of Array.from(x.childNodes))S.nodeType===1&&S.tagName==="w:pPr"||P.appendChild(S);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++,C.size>0){let x=new Set(this._existing_comment_ids()),P=Array.from(C).filter(S=>!x.has(S));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"),y=l.ownerDocument.createElement("w:r"),k=l.ownerDocument.createElement("w:t");k.textContent=_,_.trim()!==_&&k.setAttribute("xml:space","preserve"),y.appendChild(k),m.appendChild(y),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 x=f;x=x.split(d.trim()).join("");let P=o.spans.find(S=>S.start<=u&&u<S.end&&S.paragraph!==null);if(P&&x){let S=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(S){for(let T of [S,S.replace(/\s+$/,"")])if(T&&x.startsWith(T)){x=x.substring(T.length).replace(/^\s+/,"");break}x&&!/\s$/.test(S)&&!/^\s/.test(x)&&(x=" "+x);}}x?l.push({type:"modify",target_text:"",new_text:x,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=Is(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[x]=this._parse_markdown_style(d),P=x,S=p,T=P===S?"STYLE_ONLY":"STYLE_AND_TEXT",B=d.indexOf(x),D=u+(B!==-1?B:0),I=m!==null?m:"Normal";l.push({type:"modify",target_text:P,new_text:S,comment:e.comment,_match_start_index:D,_internal_op:T,_new_style:I,_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 y=false;if(o&&(y=o.spans.some(x=>x.text===" | "&&(x.run===null||x.run===void 0)&&x.start<u+c&&x.end>u)),y){let x=d.split("|"),P=f.split("|");if(x.length!==P.length)throw new _t([`Target text spans ${x.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(x.length>1){let S=[],T=0,B=0;for(let D=0;D<x.length;D++)if(x[D].trim()!==P[D].trim()){B=D;break}for(let D=0;D<x.length;D++){let I=x[D],R=P[D],j=I.trim(),F=R.trim(),L=u+T+(j?I.indexOf(j):0),U=e.comment!==null&&e.comment!==void 0&&D===B;if(j!==F||U){let G=this._word_diff_sub_edits(j,F,L,U?e.comment:null,true,o);for(let J of G)J._original_target_text=e.target_text,J._split_group_id=u,S.push(J);}T+=I.length+1;}for(let D of S)l.push(D);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="",N=u;if(f.startsWith(d))b="INSERTION",v=f.substring(d.length),N=u+c;else {let[x,P]=qe(d,f),S=d.length-P,T=f.length-P;g=d.substring(x,S),v=f.substring(x,T),N=u+x;}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:N,_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:N,_match_start_index:N,_internal_op:b,_active_mapper_ref:o});continue}let E=d.split(`
|
|
115
116
|
|
|
116
117
|
`),C=f.split(`
|
|
117
118
|
|
|
118
119
|
`);if(d.includes(`
|
|
119
120
|
|
|
120
|
-
`)&&
|
|
121
|
-
`)||(
|
|
121
|
+
`)&&E.length===C.length){let x=[],P=u,S=false;for(let T=0;T<E.length;T++){let B=E[T],D=C[T];if(B!==D){let I=e.comment&&!S?e.comment:null,R=this._word_diff_sub_edits(B,D,P,I,false,o);R.some(j=>j.comment!==null&&j.comment!==void 0)&&(S=true);for(let j of R)j._split_group_id=u,x.push(j);}P+=B.length+2;}if(x.length>0){for(let T of x)l.push(T);continue}}if(!g&&v){l.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 A=this._word_diff_sub_edits(d,f,u,e.comment,false,o);for(let x of A)x._split_group_id=u,l.push(x);}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),N=null;if(v)N=v._element;else if(g){let E=g._element;for(;E&&E.tagName!=="w:p";)E=E.parentNode;N=E;}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 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,x=C;for(;x&&x.tagName!=="w:p";)x=x.parentNode;let P=A;for(;P&&P.tagName!=="w:p";)P=P.parentNode;if(x&&P){let S=w((D,I)=>{let R=D;for(;R.parentNode&&R.parentNode!==I;)R=R.parentNode;return R},"ascend_to_paragraph_child"),T=S(C,x),B=S(A,P);x===P?this._attach_comment(x,T,B,e.comment):this._attach_comment_spanning(x,T,P,B,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,N=g[g.length-1]._element,E=v;for(;E&&E.tagName!=="w:p";)E=E.parentNode;let C=N;for(;C&&C.tagName!=="w:p";)C=C.parentNode;if(!E||!C)return false;let A=w((S,T)=>{let B=S;for(;B.parentNode&&B.parentNode!==T;)B=B.parentNode;return B},"ascend_to_paragraph_child"),x=A(v,E),P=A(N,C);return E===C?this._attach_comment(E,x,P,e.comment):this._attach_comment_spanning(E,x,C,P,e.comment),true}if(s==="INSERTION"){let g=e.new_text||"",v=null,N=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(N!==null&&E){let[D,I]=N,R=i.part_kind_of(D),j=i.part_kind_of(I);if(R==="body"&&j!=="body"){let F=i.spans.filter(L=>L.run!==null&&L.part_index===D);F.length>0&&(v=F[F.length-1]);}}let C,A;if(v!==null?(C=v.run,A=v.paragraph,g.startsWith(`
|
|
122
|
+
`)||(g=`
|
|
122
123
|
|
|
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=[`
|
|
124
|
+
`+g)):[C,A]=i.get_insertion_anchor(o,r),!C&&!A||V._introduces_table_row_text(i,o,1,"",g))return false;let x=g,P=v===null&&/\n\s*$/.test(x),S=null;{let D=i.spans.filter(I=>I.paragraph!==null&&I.start===o);D.length>0&&D[0].paragraph&&(S=D[0].paragraph._element);}if(P&&S&&S.parentNode){let D=S.parentNode,I=this.doc.part._element.ownerDocument,R=x.split(/[\r\n]+/).filter(U=>U!==""),j=null,F=null,L=null;for(let U of R){let[G,J]=this._parse_markdown_style(U),H=I.createElement("w:p");if(J)this._set_paragraph_style(H,J);else {let _e=M(S,"w:pPr");_e&&H.appendChild(this._clone_pPr_scrubbing_headings(_e,S));}let W=M(H,"w:pPr");W||(W=I.createElement("w:pPr"),H.insertBefore(W,H.firstChild));let ne=M(W,"w:rPr");ne||(ne=I.createElement("w:rPr"),W.appendChild(ne)),ne.appendChild(this._create_track_change_tag("w:ins","",d));let de=this._build_tracked_ins_for_line(G,C,d,I,l);de&&H.appendChild(de),D.insertBefore(H,S),j||(j=H),F=H,L=de;}if(j){if(e.comment&&F&&L){let U=w((J,H)=>{let W=J;for(;W.parentNode&&W.parentNode!==H;)W=W.parentNode;return W},"ascend"),G=$(j,"w:ins")[0]||j;this._attach_comment_spanning(j,U(G,j),F,U(L,F),e.comment);}return true}}let T=this._track_insert_multiline(g,C,A,d,null,l,o===0||C===null&&A!==null);if(!T.first_node)return false;if(T.first_node.tagName==="w:ins"){if(C){let D=C._element,I=D.parentNode;I&&I.tagName==="w:del"&&(D=I,I=D.parentNode);let R=o===0;I&&I.tagName==="w:ins"?this._insert_and_split_ins(I,D,T.first_node,R):R&&I?I.insertBefore(T.first_node,D):Ue(T.first_node,D);}else if(A){let D=A._element,I=D.firstChild;for(;I&&I.tagName==="w:pPr";)I=I.nextSibling;D.insertBefore(T.first_node,I);}}if(e.comment){let D=w((I,R)=>{let j=I;for(;j.parentNode&&j.parentNode!==R;)j=j.parentNode;return j},"ascend_to_paragraph_child");if(T.last_p&&T.last_ins){let I=T.first_node;for(;I&&I.tagName!=="w:p";)I=I.parentNode;if(I){let R=T.first_node;T.first_node.tagName==="w:p"&&(R=$(T.first_node,"w:ins")[0]||T.first_node);let j=D(R,I),F=D(T.last_ins,T.last_p);this._attach_comment_spanning(I,j,T.last_p,F,e.comment);}}else {let I=T.first_node;for(;I&&I.tagName!=="w:p";)I=I.parentNode;if(I){let R=T.first_node;T.first_node.tagName==="w:p"&&(R=$(T.first_node,"w:ins")[0]||T.first_node);let j=D(R,I);this._attach_comment(I,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),N=g._element.cloneNode(true);Array.from(N.getElementsByTagName("w:t")).forEach(C=>{let A=N.ownerDocument.createElement("w:delText");A.textContent=C.textContent,C.hasAttribute("xml:space")&&A.setAttribute("xml:space","preserve"),N.replaceChild(A,C);}),v.appendChild(N),g._element.parentNode?.replaceChild(v,g._element),p===null&&(p=v),m=v;}let y=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 ie(g,null):null,N=f.length>0?f[f.length-1]:null,E=this._track_insert_multiline(e.new_text,N,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),y=E.first_node;}else y=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,N=$(v,"w:r"),E=N.length>0?new Ae(N[N.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,N=ve(v);for(;N&&N.tagName!=="w:p";)N=ve(N);if(N&&N.tagName==="w:p"){let E=!this._paragraph_has_visible_content(v),C=M(v,"w:pPr");if(E){let P=M(N,"w:pPr"),S=P?P.cloneNode(true):v.ownerDocument.createElement("w:pPr");if(C){let T=M(C,"w:sectPr");T&&!M(S,"w:sectPr")&&S.appendChild(T.cloneNode(true)),v.removeChild(C);}v.insertBefore(S,v.firstChild),C=S;}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 x=Array.from(N.childNodes);for(let P of x)P.nodeType===1&&P.tagName==="w:pPr"||v.appendChild(P);N.parentNode&&N.parentNode.removeChild(N);}}}if(e.comment&&p!==null){let g,v;if(k&&b)g=b,v=k;else {let x=y!==null?y:m;for(g=x,v=x;v&&v.tagName!=="w:p";)v=v.parentNode;}let N=p;for(;N&&N.tagName!=="w:p";)N=N.parentNode;if(!N||!v)return true;let E=w((x,P)=>{let S=x;for(;S.parentNode&&S.parentNode!==P;)S=S.parentNode;return S},"ascend_to_paragraph_child"),C=E(p,N),A=E(g,v);N===v?this._attach_comment(N,C,A,e.comment):this._attach_comment_spanning(N,C,v,A,e.comment);}for(let g of _)if(!this._paragraph_has_visible_content(g)){let N=M(g,"w:pPr");N||(N=g.ownerDocument.createElement("w:pPr"),g.insertBefore(N,g.firstChild));let E=M(N,"w:rPr");if(E||(E=g.ownerDocument.createElement("w:rPr"),N.appendChild(E)),!M(E,"w:del")){let C=this._create_track_change_tag("w:del");E.appendChild(C);}}return true}};function K(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}w(K,"findDescendantsByLocalName");function Ho(t){let e=0;function n(o,a){let l=o?o.toString():"",u=a?a.toString():"";return l===u}w(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}w(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||"",y=p.textContent||"",k=m+y;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);}}w(s,"coalesceContainer");let i=$(t.element,"w:p");for(let o of i)s(o);return e?[`Adjacent identical runs coalesced: ${e}`]:[]}w(Ho,"coalesce_runs");function Xo(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`]:[]}w(Xo,"strip_rsid");function Jo(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`]:[]}w(Jo,"strip_para_ids");function Qo(t){let e=$(t.element,"w:proofErr");return e.forEach(n=>n.parentNode?.removeChild(n)),e.length?[`Spell check markers: ${e.length} removed`]:[]}w(Qo,"strip_proof_errors");function Go(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`]:[]}w(Go,"strip_empty_properties");function Yo(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`]:[]}w(Yo,"strip_hidden_text");function hr(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]}w(hr,"count_tracked_changes");function Vo(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}w(Vo,"get_track_change_authors");function pr(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("")}w(pr,"_getElementText");function Pe(t,e=60){let n=t.replace(/\n/g," ").trim();return n.length<=e?n:n.substring(0,e-3)+"..."}w(Pe,"_truncate");function _r(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)"}w(_r,"_describe_textless_revision");function Zo(t){let e=[],n=$(t.element,"w:ins"),r=$(t.element,"w:del");for(let o of n){let a=pr(o).trim();a?e.push(` Accepted insertion: "${Pe(a,60)}"`):e.push(` Accepted insertion: ${_r(o)}`);}for(let o of r){let a=pr(o).trim();a?e.push(` Accepted deletion of: "${Pe(a,60)}"`):e.push(` Accepted deletion of: ${_r(o)}`);}new bn(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):[]}w(Zo,"accept_all_tracked_changes");function mt(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}}w(mt,"get_comments_summary");function Ko(t){let e=Re(t.pkg),n=Object.keys(e);if(n.length===0)return [];let r=[],s=new rt(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)}w(Ko,"remove_all_comments");function ea(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];}w(ea,"eject_comment_parts");function ta(t,e){let n=new rt(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}"`]:[]}w(ta,"replace_comment_authors");function na(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}"`]:[]}w(na,"replace_change_authors");function ra(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`]:[]}w(ra,"normalize_change_dates");function ia(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`]:[]}w(ia,"normalize_comment_dates");function sa(t){let e=[],n=t.pkg.getPartByPath("docProps/core.xml");if(n){K(n._element,"creator").forEach(u=>{u.textContent&&(e.push(`Author: ${u.textContent}`),u.textContent="");}),K(n._element,"lastModifiedBy").forEach(u=>{u.textContent&&(e.push(`Last modified by: ${u.textContent}`),u.textContent="");}),K(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)K(n._element,u).forEach(d=>{d.textContent&&(e.push(`${c}: ${d.textContent}`),d.textContent="");});K(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)K(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)K(s,a).forEach(l=>{l.textContent&&(e.push(`${a}: ${l.textContent}`),l.textContent="");});}return e.length?["Metadata scrubbed:",...e.map(s=>` ${s}`)]:[]}w(sa,"scrub_doc_properties");function oa(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"])K(r._element,s).forEach(i=>{i.textContent&&i.textContent!==n&&(i.textContent=n,e=true);});return e?["Timestamps normalized to epoch"]:[]}w(oa,"scrub_timestamps");function ri(t,e,n){let r=t.pkg,s=w(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];}w(ri,"ejectPackageMembers");function aa(t){let e=w(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 [];ri(t,e,s=>s.includes("customXml"));for(let s of $(t.element,"w:sdtPr"))Pr(s,"w:dataBinding").forEach(i=>s.removeChild(i));return [`Custom XML parts: ${Math.max(n.length,r.length)} removed`]}w(aa,"strip_custom_xml");var Zt="docProps/custom.xml";function la(t){let e=t.pkg.getPartByPath(Zt),n=Object.keys(t.pkg.unzipped).includes(Zt);if(!e&&!n)return [];let r=[];if(e)for(let i of K(e._element,"property")){let o=i.getAttribute("name")||"(unnamed)",a=(i.textContent||"").trim();r.push(` Custom property removed: ${o} = "${Pe(a,60)}"`);}return ri(t,i=>i===Zt,i=>i.includes("docProps/custom.xml")),[`Custom document properties: ${Math.max(r.length,1)} removed (docProps/custom.xml)`].concat(r)}w(la,"strip_custom_properties");function ca(t){let e=t.pkg.getPartByPath("word/settings.xml");if(!e)return [];let n=[],r=false;for(let i of K(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 K(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})`]}w(ca,"strip_document_variables");function ua(t){let e=0;for(let n of K(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`]:[]}w(ua,"strip_image_alt_text");function da(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=K(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}w(da,"detect_watermarks");function fa(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}w(fa,"audit_hyperlinks");function ha(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}w(ha,"boundedLevenshtein");function pa(t){let e="",n=$(t._element,"w:r");for(let r of n)e+=Oe(new Ae(r,t));return e}w(pa,"_get_paragraph_text");var xn="[A-Z][A-Za-z0-9\\s\\-&'\u2019]{1,60}",_a=new RegExp(`^(?:[\\d.\\-()a-zA-Z]+\\s*)?["\u201C](${xn})["\u201D]`,"d"),ma=new RegExp(`(?<=[.;:!?])\\s+(?:[\\d.\\-()a-zA-Z]+\\s+)?["\u201C](${xn})["\u201D]`,"dg"),ga=new RegExp(`\\([^)]*?["\u201C](${xn})["\u201D][^)]*?\\)`,"dg");function wa(t){let e=[],n=_a.exec(t);n&&n.indices&&n.indices[1]&&e.push([n.indices[1][0],n[1].trim()]);for(let i of t.matchAll(ma)){let o=i.indices;o&&o[1]&&e.push([o[1][0],i[1].trim()]);}for(let i of t.matchAll(ga)){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}w(wa,"extract_terms_from_paragraph");function ya(t,e){let n={},r=new Set,s={},i=[];for(let p of Se(t)){if(!(p instanceof ie))continue;let m=pa(p).trim();if(!m)continue;for(let b of wa(m))n[b]?r.add(b):n[b]={count:0};let y=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:y,referenced_from:[]}));}let g=null;if(b.tagName==="w:fldSimple"){let N=(b.getAttribute("w:instr")||"").trim().split(/\s+/);N.length>1&&N[0]==="REF"&&(g=N[1]);}else if(b.tagName==="w:instrText"){let N=(b.textContent||"").trim().split(/\s+/);N.length>1&&N[0]==="REF"&&(g=N[1]);}g&&i.push([g,y]);}}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=w(b=>b.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"escapeRegExp"),y=p.map(m).join("|"),k=new RegExp(`(?<!["\u201C])\\b(${y})\\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(),y=m.split(/\s+/);for(;y.length>0;){let g=y[0],v=g.charAt(0).toUpperCase()+g.slice(1).toLowerCase();if(l.has(v))y.shift();else break}if(m=y.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=ha(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 y=m.map(k=>`'${k}'`).join(", ");o.push(`[Info] Possible Typos for '${p}': Found ${y}`);}function _(p){return p.startsWith("[Error]")?0:p.startsWith("[Warning]")?1:2}return w(_,"diag_sort_key"),o.sort((p,m)=>{let y=_(p),k=_(m);return y!==k?y-k:p.localeCompare(m)}),[n,o,s]}w(ya,"extract_all_domain_metadata");function va(t){let e=[],n=t.pkg.getPartByPath("word/settings.xml");if(!n)return e;let r=w(o=>{if(!o.hasAttribute("w:val"))return true;let a=(o.getAttribute("w:val")||"").toLowerCase();return a!=="0"&&a!=="false"&&a!=="off"},"isTruthy"),s=K(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=K(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}w(va,"extract_document_settings_warnings");function ba(t,e){let[n,r,s]=ya(t,e),i=va(t),o=[`
|
|
124
125
|
|
|
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."],
|
|
126
|
-
## Document Settings`);for(let
|
|
127
|
-
## Defined Terms`);for(let[
|
|
128
|
-
## Semantic Diagnostics`);for(let
|
|
129
|
-
## Named Anchors`);for(let[
|
|
130
|
-
`):""}
|
|
126
|
+
---`,"","<!-- 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(`
|
|
127
|
+
## Document Settings`);for(let l of i)o.push(`- ${l}`);}if(Object.keys(n).length>0){a=true,o.push(`
|
|
128
|
+
## 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(`
|
|
129
|
+
## Semantic Diagnostics`);for(let l of r)o.push(`- ${l}`);}if(Object.keys(s).length>0){a=true,o.push(`
|
|
130
|
+
## 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(`
|
|
131
|
+
`):""}w(ba,"build_structural_appendix");async function je(t,e=false,n=true){let r=await pe.load(t);return Ge(r,e,n)}w(je,"extractTextFromBuffer");function Ge(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 yn(t)){let h=o.length>0?u+2:u,_=Nn(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
132
|
|
|
132
|
-
`);if(n){let d=
|
|
133
|
-
${t.note_type==="fn"?"## Footnotes":"## Endnotes"}`;u.push(
|
|
133
|
+
`);if(n){let d=ba(t,c);d&&(c+=d);}return r?{text:c,paragraph_offsets:a}:l?{text:c,structure:l}:c}w(Ge,"_extractTextFromDoc");function Nn(t,e,n,r,s,i){let o=t.part||t,[a,l]=Qe(o),u=[],c=r,d=true,f=true;if(t.constructor&&t.constructor.name==="NotesPart"){let _=`---
|
|
134
|
+
${t.note_type==="fn"?"## Footnotes":"## Endnotes"}`;u.push(_),c+=_.length,d=false;}for(let h of Se(t)){d||(c+=2);let _=c;if(h.constructor.name==="FootnoteItem"){let p=Nn(h,e,n,_,s);p?(u.push(p),c=_+p.length,d=false):d||(c-=2);}else if(h instanceof ie){let p=Ie(h,a,l);f&&t.constructor.name==="FootnoteItem"&&(p=`[^${t.note_type}-${t.id}]: `+p);let m=ot(h,e,n,a,l),y=p+m;u.push(y),s&&s.set(h._element,[_,y.length]),c=_+y.length,f=false,d=false;}else if(h instanceof Te){let p=i?{start:_,end:_,rows:[]}:null,m=Ct(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
135
|
|
|
135
|
-
`)}
|
|
136
|
-
`)}
|
|
137
|
-
`)}
|
|
138
|
-
${i}`);}let s=true;for(let i of
|
|
136
|
+
`)}w(Nn,"_extract_blocks");function Ct(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),y=p+(!n&&h||!n&&_?4:0),k=true;for(let g of u.cells){if(d.has(g))continue;d.add(g),k||(y+=3);let v=Nn(g,e,n,y,s);if(!n){let{paraId:N}=Ir(g._element,!v||v.trim()==="");if(N){let C=`${v?" ":""}{#cell:${N}}`;v=v+C;}}c.push(v),y+=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(`
|
|
137
|
+
`)}w(Ct,"extract_table");function ot(t,e,n,r,s){let i=[],o={},a={},l=new Set,u={},c=[],d="",f=["",""],h=["",""],_=Array.from(At(t)),p=Hr(t,r,s),m=Et(t,r,s),y=p;for(let k=0;k<_.length;k++){let b=_[k];if(b instanceof Ae){let[g,v]=Xr(b,m),N=Oe(b);if(n&&Object.keys(a).length>0)continue;if(y){if(!N||!N.trim())continue;y=false;}let E=wo(N,g,v);if(E){let C=n?["",""]:xa(o,a,l,u),A=[g,v];if(d&&C[0]===f[0]&&C[1]===f[1]){let x=A[0].replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),P=A[0]!==""||A[1]!==""?E.match(new RegExp("^(\\s*)"+x)):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,B=false,D=Object.keys(o).length,I=Object.keys(a).length,R=Object.keys(u).length,j=new Set(l);for(;T<_.length;){let F=_[T];if(F instanceof Ae){if(!Oe(F)){T++;continue}(D>0||I>0||R>0||j.size>0)&&(B=true);break}else {let L=F;L.type==="ins_start"?D++:L.type==="ins_end"?D=Math.max(0,D-1):L.type==="del_start"?I++:L.type==="del_end"?I=Math.max(0,I-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++;}B&&(P=true);}if(!P&&c.length>0){let T=mr(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(y=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(``);}}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=mr(c,e);k&&i.push(`{>>${k}<<}`);}return i.join("")}w(ot,"build_paragraph_text");function xa(t,e,n,r){return Object.keys(e).length>0?["{--","--}"]:Object.keys(t).length>0?["{++","++}"]:n.size>0||Object.keys(r).length>0?["{==","==}"]:["",""]}w(xa,"_get_wrappers");function mr(t,e){let n=[],r=[],s=new Set,i=Qr(t),o=w(l=>i[l]?` (pairs with ${i[l]})`:"","pairSuffix");for(let[l,u,c,d]of t){let f=w(function(p){if(!e[p])return;let m=`Com:${p}`;if(s.has(m))return;let y=e[p],k=`[${m}] ${y.author}`;if(y.date&&(k+=` @ ${y.date}`),y.resolved&&(k+="(RESOLVED)"),r.push(`${k}: ${Mr(y.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 y=`Chg:${p}`;s.has(y)||(n.push(`[${y} insert] ${m.author||"Unknown"}${o(p)}`),s.add(y));}for(let[p,m]of Object.entries(u)){let y=`Chg:${p}`;s.has(y)||(n.push(`[${y} delete] ${m.author||"Unknown"}${o(p)}`),s.add(y));}for(let[p,m]of Object.entries(d)){let y=`Chg:${p}`;s.has(y)||(n.push(`[${y} format] ${m.author||"Unknown"}`),s.add(y));}let h={};for(let[p,m]of Object.entries(e)){let y=m.parent_id;y&&(h[y]||(h[y]=[]),h[y].push(p));}let _=Array.from(c).sort();for(let p of _)f(p);}return [...n,...r].join(`
|
|
138
|
+
`)}w(mr,"_build_merged_meta_block");var ii=/^(#{1,6}) /,si=3;function oi(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 Ia(t,e,r,s);let i=Re(t.pkg),o=ka(t,i),a=[];for(let u=0;u<o.length;u++){let c=o[u];c.is_paragraph&&it(c.item)&&Ca(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=xt(f),_=di(f,i),p=Pt(f),m=Pa(o,a,u,h),y=o.slice(c+1,m),k=Na(o,c+1,m),b=Ta(y),g=_i(d.start_offset,r);l.push({level:h,text:_,page:g,style:p,has_table:k,footnote_ids:b});}return l}w(oi,"extract_outline");function Na(t,e,n){for(let r=e;r<n;r++){let s=t[r];if(s.is_paragraph&&it(s.item))return false;if(s.is_table)return true}return false}w(Na,"_direct_has_table");function ka(t,e){let n=Array.from(yo(t)),r=0,s=null;for(let l of n){if(l===t){s=l;break}let u=ci(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 Se(s))if(l instanceof ie){let u=Ie(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=Ct(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}),li(l,d,i,e),o+=c,a=false;}return i}w(ka,"_walk_doc_body");function ai(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]=Ea(c,s,i,r);if(f)return d;i=d,u++;}o++;}return n}w(ai,"_compute_inner_block_offset");function Ea(t,e,n,r){let s=n,i=true;for(let o of Se(t)){if(i||(s+=2),o instanceof ie){if(o._element===e)return [s,true];let a=Ie(o),l=ot(o,r,false);s+=(a+l).length;}else if(o instanceof Te){let a=ai(o,new ie(e,null),s,r);if(a!==s&&Aa(e,o._element))return [a,true];let l=Ct(o,r,false,0);s+=l?l.length:0;}i=false;}return [s,false]}w(Ea,"_walk_cell_for_offset");function Aa(t,e){let n=t.parentNode;for(;n;){if(n===e)return true;n=n.parentNode;}return false}w(Aa,"_element_is_descendant");function li(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 Se(o))if(a instanceof ie){let l=it(a)?ai(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}),li(a,e,n,r));}}w(li,"_record_table_inner_blocks_lite");function ci(t,e){let n=[],r=t.constructor.name;if(r==="NotesPart"){let i=t.note_type==="fn"?"## Footnotes":"## Endnotes";n.push(`---
|
|
139
|
+
${i}`);}let s=true;for(let i of Se(t))if(i.constructor.name==="FootnoteItem"){let o=ci(i,e);o&&n.push(o);}else if(i instanceof ie){let o=Ie(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=Ct(i,e,false,0);o&&n.push(o),s=false;}return n.join(`
|
|
139
140
|
|
|
140
|
-
`)}
|
|
141
|
+
`)}w(ci,"_project_part");function it(t){return ii.test(Ie(t))}w(it,"_is_heading");function Ca(t,e){let n=di(t,e);return ui(n)?Pt(t)!=="(heuristic)"?true:(n.match(/\w+/g)||[]).length>=si:false}w(Ca,"_heading_passes_quality_filter");function ui(t){if(!t)return false;let e=t.replace(/\{#[^}]+\}/g,"");return /\w/.test(e)}w(ui,"_heading_text_has_words");function xt(t){let e=ii.exec(Ie(t));return e?Math.min(e[1].length,6):1}w(xt,"_heading_level");var gr=200;function di(t,e){let n=ot(t,e,false),r=hi(n);return r=r.replace(/\n+/g," "),r=pi(r),fi(r.trim())}w(di,"_heading_text");function fi(t){return t.length<=gr?t:t.substring(0,gr)+"\u2026"}w(fi,"_truncate_outline_text");function hi(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):""}w(hi,"_strip_critic_markup");function pi(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}w(pi,"_strip_inline_formatting");function Pt(t){let[e,n]=Qe(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)"}w(Pt,"_determine_heading_style");function Pa(t,e,n,r){for(let s=n+1;s<e.length;s++){let i=e[s];if(xt(t[i].item)<=r)return i}return t.length}w(Pa,"_find_owned_end");function Ta(t){let e=new Set,n=[];for(let r of t)if(r.is_paragraph)for(let s of At(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}w(Ta,"_collect_footnote_ids");function _i(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}w(_i,"_offset_to_page");function Ia(t,e,n,r){let s=[],i=new Set;function o(u){for(let c of Se(u))if(c.constructor.name==="FootnoteItem")o(c);else if(c instanceof ie)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));}}w(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&&it(d)&&Sa(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=xt(d),h=mi(d,e,r),_=Pt(d),p=c;for(let v=u+1;v<a.length;v++){let N=a[v],E=s[N][1];if(xt(E)<=f){p=N;break}}p===c&&(p=s.length);let m=s.slice(c+1,p),y=false;for(let[v,N]of m){if(v==="p"&&it(N))break;if(v==="t"){y=true;break}}let k=$a(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=_i(v,n);}l.push({level:f,text:h,page:g,style:_,has_table:y,footnote_ids:k});}return l}w(Ia,"_extract_outline_fast");function Sa(t,e,n){let r=mi(t,e,n);return ui(r)?Pt(t)!=="(heuristic)"?true:(r.match(/\w+/g)||[]).length>=si:false}w(Sa,"_heading_passes_quality_filter_fast");function mi(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=hi(o);return a=a.replace(/\n+/g," "),a=pi(a),a=a.replace(/^#+\s+/,""),fi(a.trim())}w(mi,"_heading_text_fast");function $a(t){let e=new Set,n=[];for(let[r,s]of t)if(r==="p")for(let i of At(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}w($a,"_collect_footnote_ids_fast");var Da=class{static{w(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
142
|
`);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
|
|
143
|
+
`)}};async function gi(t,e){let n=new Da(e.filename,e.sanitize_mode||"full",e.author||null);if(e.sanitize_mode==="full"){let i=hr(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=Vo(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=mt(t);n.add_transform_lines(Zo(t)),n.tracked_changes_accepted=o;let c=new Set(mt(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=mt(t);n.comments_removed+=a.total,n.add_transform_lines(Ko(t)),ea(t);}else if(e.sanitize_mode==="keep-markup"){let i=hr(t);n.tracked_changes_found=i[0]+i[1]+i[2],n.tracked_changes_kept=n.tracked_changes_found;let o=mt(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(ta(t,e.author)),n.add_transform_lines(na(t,e.author)));}n.add_transform_lines(Xo(t)),n.add_transform_lines(Jo(t)),n.add_transform_lines(Qo(t)),n.add_transform_lines(Go(t)),n.add_transform_lines(Yo(t)),n.add_transform_lines(Ho(t)),n.add_transform_lines(sa(t)),n.add_transform_lines(oa(t)),n.add_transform_lines(aa(t)),n.add_transform_lines(la(t)),n.add_transform_lines(ca(t)),n.add_transform_lines(ua(t));let r=fa(t);for(let i of r)n.warnings.push(i);for(let i of da(t))n.warnings.push(i);if(n.add_transform_lines(ra(t)),n.add_transform_lines(ia(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=K(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 Ma(s),{reportText:n.render(),outBuffer:s}}w(gi,"finalize_document");var Oa=[["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 Ma(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=He(De(e["docProps/core.xml"]));for(let[i,o]of Oa)for(let a of K(s.documentElement,i))(a.textContent||"").trim()&&r.push(`core property ${o} still contains a value`);}if(n.includes("word/settings.xml")){let s=He(De(e["word/settings.xml"]));K(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
144
|
- `+r.join(`
|
|
144
145
|
- `)+`
|
|
145
|
-
Refusing to report a clean document.`)}
|
|
146
|
+
Refusing to report a clean document.`)}w(Ma,"verifySanitizedPackage");var wi=[{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 yi(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]=Xe(u),f=Je(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}}]}w(yi,"executeExtractMarkdown");var vi=[{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 bi(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=Ge(o,false,true,true),[l]=Xe(a.text),u=Je(l,""),c=oi(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}}]}w(bi,"executeExtractOutline");var xi=[{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
147
|
{
|
|
147
148
|
"type": "modify",
|
|
148
149
|
"target_text": "State of New York",
|
|
149
150
|
"new_text": "State of Delaware",
|
|
150
151
|
"comment": "Standardizing governing law."
|
|
151
152
|
}
|
|
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
|
|
153
|
+
]`,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 Ni(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 N=this.getNodeParameter("editsJsonPath",t),E=this.getInputData()[t].json;if(a=En(E,N),a===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);a=Cn.call(this,N,t,"Changes (JSON)");}if(!Array.isArray(a))throw new Error("Changes must be an array of DocumentChange objects.");a=An(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 bn(f,r).process_batch(a),p=this.getInputData()[t].binary??{},m=await f.save(),y=ct(d,"redlined"),k=await this.helpers.prepareBinaryData(m,y,$e),b=typeof this.isToolExecution=="function"&&this.isToolExecution(),g;if(b&&k.id){let N=this.getWorkflowStaticData("global");N.adeu_last_redlined={id:k.id,fileName:y,mimeType:$e,timestamp:Date.now()},g=k.id;}let v;return i&&(v=await je(m,false)),[{json:{fileName:y,author:r,stats:_,...o!==""?{reasoning:o}:{},...v!==void 0?{markdown:v}:{},...g!==void 0?{redlinedBinaryId:g}:{}},binary:{...p,[n]:k},pairedItem:{item:t}}]}w(Ni,"executeApplyEdits");var ki=[{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 Ei(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=Kr(new Uint8Array(u),new Uint8Array(d));if(s==="structuredChanges"){let y=await pe.load(u),k=await pe.load(d),b=Ge(y,r,false,false,true),g=Ge(k,r,false,false,true),{edits:v,warnings:N}=Zr(b.text,b.structure,g.text,g.structure),E=[...h,...N];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"?ei(_,p):ni(_,p,c,f);return h.length>0&&(m=h.map(k=>`\u26A0\uFE0F ${k}`).join(`
|
|
153
154
|
`)+`
|
|
154
155
|
|
|
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;
|
|
156
|
+
`+m),[{json:{originalFileName:c,modifiedFileName:f,cleanView:r,diffFormat:s,diff:m,...h.length>0?{warnings:h}:{}},pairedItem:{item:t}}]}w(Ei,"executeGenerateDiff");var Ai=[{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 Ci(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 gi(h,{filename:f,sanitize_mode:r,accept_all:s,protection_mode:a,author:i});if(!p)throw new Error(_);let m=ct(f,"finalized"),y=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]:y},pairedItem:{item:t}}]}w(Ci,"executeFinalizeDocument");var Pi=[{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"]}}},...wi,...vi,...xi,...ki,...Ai,...In];var Si=class{static{w(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"},...Pi]};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 yi.call(this,i);break;case "extractOutline":o=await bi.call(this,i);break;case "applyEdits":o=await Ni.call(this,i);break;case "generateDiff":o=await Ei.call(this,i);break;case "finalizeDocument":o=await Ci.call(this,i);break;case "hydrateToolOutput":o=await Sn.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:Pn.call(this,a,i)}return [n]}};exports.Adeu=Si;
|