@ansonlai/docx-redline-js 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/AGENTS.md +176 -0
  2. package/ARCHITECTURE.md +121 -0
  3. package/LICENSE +21 -0
  4. package/README.md +177 -0
  5. package/adapters/config.js +43 -0
  6. package/adapters/logger.js +89 -0
  7. package/adapters/xml-adapter.js +74 -0
  8. package/core/list-targeting.js +398 -0
  9. package/core/ooxml-identifiers.js +15 -0
  10. package/core/paragraph-offset-policy.js +50 -0
  11. package/core/paragraph-targeting.js +501 -0
  12. package/core/table-targeting.js +233 -0
  13. package/core/types.js +204 -0
  14. package/core/xml-query.js +99 -0
  15. package/dist/docx-redline-js.esm.js +8801 -0
  16. package/dist/docx-redline-js.esm.js.map +7 -0
  17. package/dist/docx-redline-js.esm.min.js +195 -0
  18. package/dist/docx-redline-js.esm.min.js.map +7 -0
  19. package/engine/format-application.js +358 -0
  20. package/engine/format-extraction.js +232 -0
  21. package/engine/format-paragraph-targeting.js +208 -0
  22. package/engine/format-span-application.js +178 -0
  23. package/engine/formatting-removal.js +330 -0
  24. package/engine/oxml-engine.js +279 -0
  25. package/engine/reconstruction-mapper.js +270 -0
  26. package/engine/reconstruction-mode.js +38 -0
  27. package/engine/reconstruction-writer.js +276 -0
  28. package/engine/rpr-helpers.js +194 -0
  29. package/engine/run-builders.js +235 -0
  30. package/engine/surgical-mode.js +520 -0
  31. package/engine/table-cell-context.js +151 -0
  32. package/engine/table-mode.js +172 -0
  33. package/index.js +308 -0
  34. package/orchestration/list-markdown.js +141 -0
  35. package/orchestration/list-parsing.js +73 -0
  36. package/orchestration/list-structural-fallback.js +530 -0
  37. package/orchestration/redline-operation-converter.js +141 -0
  38. package/orchestration/route-plan.js +160 -0
  39. package/package.json +76 -0
  40. package/pipeline/content-analysis.js +107 -0
  41. package/pipeline/diff-engine.js +204 -0
  42. package/pipeline/ingestion-export.js +255 -0
  43. package/pipeline/ingestion-paragraph.js +351 -0
  44. package/pipeline/ingestion-table.js +169 -0
  45. package/pipeline/ingestion-xml.js +39 -0
  46. package/pipeline/ingestion.js +8 -0
  47. package/pipeline/list-generation.js +280 -0
  48. package/pipeline/list-markers.js +77 -0
  49. package/pipeline/markdown-processor.js +160 -0
  50. package/pipeline/patching.js +408 -0
  51. package/pipeline/pipeline.js +326 -0
  52. package/pipeline/serialization.js +395 -0
  53. package/services/browser-demo-prompt-context.js +345 -0
  54. package/services/comment-builders.js +60 -0
  55. package/services/comment-engine.js +248 -0
  56. package/services/comment-locator.js +197 -0
  57. package/services/comment-package.js +113 -0
  58. package/services/numbering-helpers.js +416 -0
  59. package/services/numbering-service.js +290 -0
  60. package/services/package-builder.js +147 -0
  61. package/services/standalone-docx-plumbing.js +443 -0
  62. package/services/standalone-operation-runner.js +1169 -0
  63. package/services/table-reconciliation.js +344 -0
  64. package/standalone.js +5 -0
@@ -0,0 +1,195 @@
1
+ var Jn=Object.create;var wr=Object.defineProperty;var qn=Object.getOwnPropertyDescriptor;var Qn=Object.getOwnPropertyNames;var ea=Object.getPrototypeOf,ta=Object.prototype.hasOwnProperty;var ra=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var na=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Qn(t))!ta.call(e,a)&&a!==r&&wr(e,a,{get:()=>t[a],enumerable:!(n=qn(t,a))||n.enumerable});return e};var aa=(e,t,r)=>(r=e!=null?Jn(ea(e)):{},na(t||!e||!e.__esModule?wr(r,"default",{value:e,enumerable:!0}):r,e));var Rr=ra((vs,Be)=>{var y=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32},$=-1,F=1,O=0;y.Diff=function(e,t){return[e,t]};y.prototype.diff_main=function(e,t,r,n){typeof n>"u"&&(this.Diff_Timeout<=0?n=Number.MAX_VALUE:n=new Date().getTime()+this.Diff_Timeout*1e3);var a=n;if(e==null||t==null)throw new Error("Null input. (diff_main)");if(e==t)return e?[new y.Diff(O,e)]:[];typeof r>"u"&&(r=!0);var i=r,o=this.diff_commonPrefix(e,t),s=e.substring(0,o);e=e.substring(o),t=t.substring(o),o=this.diff_commonSuffix(e,t);var l=e.substring(e.length-o);e=e.substring(0,e.length-o),t=t.substring(0,t.length-o);var c=this.diff_compute_(e,t,i,a);return s&&c.unshift(new y.Diff(O,s)),l&&c.push(new y.Diff(O,l)),this.diff_cleanupMerge(c),c};y.prototype.diff_compute_=function(e,t,r,n){var a;if(!e)return[new y.Diff(F,t)];if(!t)return[new y.Diff($,e)];var i=e.length>t.length?e:t,o=e.length>t.length?t:e,s=i.indexOf(o);if(s!=-1)return a=[new y.Diff(F,i.substring(0,s)),new y.Diff(O,o),new y.Diff(F,i.substring(s+o.length))],e.length>t.length&&(a[0][0]=a[2][0]=$),a;if(o.length==1)return[new y.Diff($,e),new y.Diff(F,t)];var l=this.diff_halfMatch_(e,t);if(l){var c=l[0],f=l[1],m=l[2],u=l[3],p=l[4],g=this.diff_main(c,m,r,n),d=this.diff_main(f,u,r,n);return g.concat([new y.Diff(O,p)],d)}return r&&e.length>100&&t.length>100?this.diff_lineMode_(e,t,n):this.diff_bisect_(e,t,n)};y.prototype.diff_lineMode_=function(e,t,r){var n=this.diff_linesToChars_(e,t);e=n.chars1,t=n.chars2;var a=n.lineArray,i=this.diff_main(e,t,!1,r);this.diff_charsToLines_(i,a),this.diff_cleanupSemantic(i),i.push(new y.Diff(O,""));for(var o=0,s=0,l=0,c="",f="";o<i.length;){switch(i[o][0]){case F:l++,f+=i[o][1];break;case $:s++,c+=i[o][1];break;case O:if(s>=1&&l>=1){i.splice(o-s-l,s+l),o=o-s-l;for(var m=this.diff_main(c,f,!1,r),u=m.length-1;u>=0;u--)i.splice(o,0,m[u]);o=o+m.length}l=0,s=0,c="",f="";break}o++}return i.pop(),i};y.prototype.diff_bisect_=function(e,t,r){for(var n=e.length,a=t.length,i=Math.ceil((n+a)/2),o=i,s=2*i,l=new Array(s),c=new Array(s),f=0;f<s;f++)l[f]=-1,c[f]=-1;l[o+1]=0,c[o+1]=0;for(var m=n-a,u=m%2!=0,p=0,g=0,d=0,w=0,h=0;h<i&&!(new Date().getTime()>r);h++){for(var x=-h+p;x<=h-g;x+=2){var v=o+x,T;x==-h||x!=h&&l[v-1]<l[v+1]?T=l[v+1]:T=l[v-1]+1;for(var N=T-x;T<n&&N<a&&e.charAt(T)==t.charAt(N);)T++,N++;if(l[v]=T,T>n)g+=2;else if(N>a)p+=2;else if(u){var E=o+m-x;if(E>=0&&E<s&&c[E]!=-1){var b=n-c[E];if(T>=b)return this.diff_bisectSplit_(e,t,T,N,r)}}}for(var S=-h+d;S<=h-w;S+=2){var E=o+S,b;S==-h||S!=h&&c[E-1]<c[E+1]?b=c[E+1]:b=c[E-1]+1;for(var P=b-S;b<n&&P<a&&e.charAt(n-b-1)==t.charAt(a-P-1);)b++,P++;if(c[E]=b,b>n)w+=2;else if(P>a)d+=2;else if(!u){var v=o+m-S;if(v>=0&&v<s&&l[v]!=-1){var T=l[v],N=o+T-v;if(b=n-b,T>=b)return this.diff_bisectSplit_(e,t,T,N,r)}}}}return[new y.Diff($,e),new y.Diff(F,t)]};y.prototype.diff_bisectSplit_=function(e,t,r,n,a){var i=e.substring(0,r),o=t.substring(0,n),s=e.substring(r),l=t.substring(n),c=this.diff_main(i,o,!1,a),f=this.diff_main(s,l,!1,a);return c.concat(f)};y.prototype.diff_linesToChars_=function(e,t){var r=[],n={};r[0]="";function a(l){for(var c="",f=0,m=-1,u=r.length;m<l.length-1;){m=l.indexOf(`
2
+ `,f),m==-1&&(m=l.length-1);var p=l.substring(f,m+1);(n.hasOwnProperty?n.hasOwnProperty(p):n[p]!==void 0)?c+=String.fromCharCode(n[p]):(u==i&&(p=l.substring(f),m=l.length),c+=String.fromCharCode(u),n[p]=u,r[u++]=p),f=m+1}return c}var i=4e4,o=a(e);i=65535;var s=a(t);return{chars1:o,chars2:s,lineArray:r}};y.prototype.diff_charsToLines_=function(e,t){for(var r=0;r<e.length;r++){for(var n=e[r][1],a=[],i=0;i<n.length;i++)a[i]=t[n.charCodeAt(i)];e[r][1]=a.join("")}};y.prototype.diff_commonPrefix=function(e,t){if(!e||!t||e.charAt(0)!=t.charAt(0))return 0;for(var r=0,n=Math.min(e.length,t.length),a=n,i=0;r<a;)e.substring(i,a)==t.substring(i,a)?(r=a,i=r):n=a,a=Math.floor((n-r)/2+r);return a};y.prototype.diff_commonSuffix=function(e,t){if(!e||!t||e.charAt(e.length-1)!=t.charAt(t.length-1))return 0;for(var r=0,n=Math.min(e.length,t.length),a=n,i=0;r<a;)e.substring(e.length-a,e.length-i)==t.substring(t.length-a,t.length-i)?(r=a,i=r):n=a,a=Math.floor((n-r)/2+r);return a};y.prototype.diff_commonOverlap_=function(e,t){var r=e.length,n=t.length;if(r==0||n==0)return 0;r>n?e=e.substring(r-n):r<n&&(t=t.substring(0,r));var a=Math.min(r,n);if(e==t)return a;for(var i=0,o=1;;){var s=e.substring(a-o),l=t.indexOf(s);if(l==-1)return i;o+=l,(l==0||e.substring(a-o)==t.substring(0,o))&&(i=o,o++)}};y.prototype.diff_halfMatch_=function(e,t){if(this.Diff_Timeout<=0)return null;var r=e.length>t.length?e:t,n=e.length>t.length?t:e;if(r.length<4||n.length*2<r.length)return null;var a=this;function i(g,d,w){for(var h=g.substring(w,w+Math.floor(g.length/4)),x=-1,v="",T,N,E,b;(x=d.indexOf(h,x+1))!=-1;){var S=a.diff_commonPrefix(g.substring(w),d.substring(x)),P=a.diff_commonSuffix(g.substring(0,w),d.substring(0,x));v.length<P+S&&(v=d.substring(x-P,x)+d.substring(x,x+S),T=g.substring(0,w-P),N=g.substring(w+S),E=d.substring(0,x-P),b=d.substring(x+S))}return v.length*2>=g.length?[T,N,E,b,v]:null}var o=i(r,n,Math.ceil(r.length/4)),s=i(r,n,Math.ceil(r.length/2)),l;if(!o&&!s)return null;s?o?l=o[4].length>s[4].length?o:s:l=s:l=o;var c,f,m,u;e.length>t.length?(c=l[0],f=l[1],m=l[2],u=l[3]):(m=l[0],u=l[1],c=l[2],f=l[3]);var p=l[4];return[c,f,m,u,p]};y.prototype.diff_cleanupSemantic=function(e){for(var t=!1,r=[],n=0,a=null,i=0,o=0,s=0,l=0,c=0;i<e.length;)e[i][0]==O?(r[n++]=i,o=l,s=c,l=0,c=0,a=e[i][1]):(e[i][0]==F?l+=e[i][1].length:c+=e[i][1].length,a&&a.length<=Math.max(o,s)&&a.length<=Math.max(l,c)&&(e.splice(r[n-1],0,new y.Diff($,a)),e[r[n-1]+1][0]=F,n--,n--,i=n>0?r[n-1]:-1,o=0,s=0,l=0,c=0,a=null,t=!0)),i++;for(t&&this.diff_cleanupMerge(e),this.diff_cleanupSemanticLossless(e),i=1;i<e.length;){if(e[i-1][0]==$&&e[i][0]==F){var f=e[i-1][1],m=e[i][1],u=this.diff_commonOverlap_(f,m),p=this.diff_commonOverlap_(m,f);u>=p?(u>=f.length/2||u>=m.length/2)&&(e.splice(i,0,new y.Diff(O,m.substring(0,u))),e[i-1][1]=f.substring(0,f.length-u),e[i+1][1]=m.substring(u),i++):(p>=f.length/2||p>=m.length/2)&&(e.splice(i,0,new y.Diff(O,f.substring(0,p))),e[i-1][0]=F,e[i-1][1]=m.substring(0,m.length-p),e[i+1][0]=$,e[i+1][1]=f.substring(p),i++),i++}i++}};y.prototype.diff_cleanupSemanticLossless=function(e){function t(p,g){if(!p||!g)return 6;var d=p.charAt(p.length-1),w=g.charAt(0),h=d.match(y.nonAlphaNumericRegex_),x=w.match(y.nonAlphaNumericRegex_),v=h&&d.match(y.whitespaceRegex_),T=x&&w.match(y.whitespaceRegex_),N=v&&d.match(y.linebreakRegex_),E=T&&w.match(y.linebreakRegex_),b=N&&p.match(y.blanklineEndRegex_),S=E&&g.match(y.blanklineStartRegex_);return b||S?5:N||E?4:h&&!v&&T?3:v||T?2:h||x?1:0}for(var r=1;r<e.length-1;){if(e[r-1][0]==O&&e[r+1][0]==O){var n=e[r-1][1],a=e[r][1],i=e[r+1][1],o=this.diff_commonSuffix(n,a);if(o){var s=a.substring(a.length-o);n=n.substring(0,n.length-o),a=s+a.substring(0,a.length-o),i=s+i}for(var l=n,c=a,f=i,m=t(n,a)+t(a,i);a.charAt(0)===i.charAt(0);){n+=a.charAt(0),a=a.substring(1)+i.charAt(0),i=i.substring(1);var u=t(n,a)+t(a,i);u>=m&&(m=u,l=n,c=a,f=i)}e[r-1][1]!=l&&(l?e[r-1][1]=l:(e.splice(r-1,1),r--),e[r][1]=c,f?e[r+1][1]=f:(e.splice(r+1,1),r--))}r++}};y.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/;y.whitespaceRegex_=/\s/;y.linebreakRegex_=/[\r\n]/;y.blanklineEndRegex_=/\n\r?\n$/;y.blanklineStartRegex_=/^\r?\n\r?\n/;y.prototype.diff_cleanupEfficiency=function(e){for(var t=!1,r=[],n=0,a=null,i=0,o=!1,s=!1,l=!1,c=!1;i<e.length;)e[i][0]==O?(e[i][1].length<this.Diff_EditCost&&(l||c)?(r[n++]=i,o=l,s=c,a=e[i][1]):(n=0,a=null),l=c=!1):(e[i][0]==$?c=!0:l=!0,a&&(o&&s&&l&&c||a.length<this.Diff_EditCost/2&&o+s+l+c==3)&&(e.splice(r[n-1],0,new y.Diff($,a)),e[r[n-1]+1][0]=F,n--,a=null,o&&s?(l=c=!0,n=0):(n--,i=n>0?r[n-1]:-1,l=c=!1),t=!0)),i++;t&&this.diff_cleanupMerge(e)};y.prototype.diff_cleanupMerge=function(e){e.push(new y.Diff(O,""));for(var t=0,r=0,n=0,a="",i="",o;t<e.length;)switch(e[t][0]){case F:n++,i+=e[t][1],t++;break;case $:r++,a+=e[t][1],t++;break;case O:r+n>1?(r!==0&&n!==0&&(o=this.diff_commonPrefix(i,a),o!==0&&(t-r-n>0&&e[t-r-n-1][0]==O?e[t-r-n-1][1]+=i.substring(0,o):(e.splice(0,0,new y.Diff(O,i.substring(0,o))),t++),i=i.substring(o),a=a.substring(o)),o=this.diff_commonSuffix(i,a),o!==0&&(e[t][1]=i.substring(i.length-o)+e[t][1],i=i.substring(0,i.length-o),a=a.substring(0,a.length-o))),t-=r+n,e.splice(t,r+n),a.length&&(e.splice(t,0,new y.Diff($,a)),t++),i.length&&(e.splice(t,0,new y.Diff(F,i)),t++),t++):t!==0&&e[t-1][0]==O?(e[t-1][1]+=e[t][1],e.splice(t,1)):t++,n=0,r=0,a="",i="";break}e[e.length-1][1]===""&&e.pop();var s=!1;for(t=1;t<e.length-1;)e[t-1][0]==O&&e[t+1][0]==O&&(e[t][1].substring(e[t][1].length-e[t-1][1].length)==e[t-1][1]?(e[t][1]=e[t-1][1]+e[t][1].substring(0,e[t][1].length-e[t-1][1].length),e[t+1][1]=e[t-1][1]+e[t+1][1],e.splice(t-1,1),s=!0):e[t][1].substring(0,e[t+1][1].length)==e[t+1][1]&&(e[t-1][1]+=e[t+1][1],e[t][1]=e[t][1].substring(e[t+1][1].length)+e[t+1][1],e.splice(t+1,1),s=!0)),t++;s&&this.diff_cleanupMerge(e)};y.prototype.diff_xIndex=function(e,t){var r=0,n=0,a=0,i=0,o;for(o=0;o<e.length&&(e[o][0]!==F&&(r+=e[o][1].length),e[o][0]!==$&&(n+=e[o][1].length),!(r>t));o++)a=r,i=n;return e.length!=o&&e[o][0]===$?i:i+(t-a)};y.prototype.diff_prettyHtml=function(e){for(var t=[],r=/&/g,n=/</g,a=/>/g,i=/\n/g,o=0;o<e.length;o++){var s=e[o][0],l=e[o][1],c=l.replace(r,"&amp;").replace(n,"&lt;").replace(a,"&gt;").replace(i,"&para;<br>");switch(s){case F:t[o]='<ins style="background:#e6ffe6;">'+c+"</ins>";break;case $:t[o]='<del style="background:#ffe6e6;">'+c+"</del>";break;case O:t[o]="<span>"+c+"</span>";break}}return t.join("")};y.prototype.diff_text1=function(e){for(var t=[],r=0;r<e.length;r++)e[r][0]!==F&&(t[r]=e[r][1]);return t.join("")};y.prototype.diff_text2=function(e){for(var t=[],r=0;r<e.length;r++)e[r][0]!==$&&(t[r]=e[r][1]);return t.join("")};y.prototype.diff_levenshtein=function(e){for(var t=0,r=0,n=0,a=0;a<e.length;a++){var i=e[a][0],o=e[a][1];switch(i){case F:r+=o.length;break;case $:n+=o.length;break;case O:t+=Math.max(r,n),r=0,n=0;break}}return t+=Math.max(r,n),t};y.prototype.diff_toDelta=function(e){for(var t=[],r=0;r<e.length;r++)switch(e[r][0]){case F:t[r]="+"+encodeURI(e[r][1]);break;case $:t[r]="-"+e[r][1].length;break;case O:t[r]="="+e[r][1].length;break}return t.join(" ").replace(/%20/g," ")};y.prototype.diff_fromDelta=function(e,t){for(var r=[],n=0,a=0,i=t.split(/\t/g),o=0;o<i.length;o++){var s=i[o].substring(1);switch(i[o].charAt(0)){case"+":try{r[n++]=new y.Diff(F,decodeURI(s))}catch{throw new Error("Illegal escape in diff_fromDelta: "+s)}break;case"-":case"=":var l=parseInt(s,10);if(isNaN(l)||l<0)throw new Error("Invalid number in diff_fromDelta: "+s);var c=e.substring(a,a+=l);i[o].charAt(0)=="="?r[n++]=new y.Diff(O,c):r[n++]=new y.Diff($,c);break;default:if(i[o])throw new Error("Invalid diff operation in diff_fromDelta: "+i[o])}}if(a!=e.length)throw new Error("Delta length ("+a+") does not equal source text length ("+e.length+").");return r};y.prototype.match_main=function(e,t,r){if(e==null||t==null||r==null)throw new Error("Null input. (match_main)");return r=Math.max(0,Math.min(r,e.length)),e==t?0:e.length?e.substring(r,r+t.length)==t?r:this.match_bitap_(e,t,r):-1};y.prototype.match_bitap_=function(e,t,r){if(t.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var n=this.match_alphabet_(t),a=this;function i(T,N){var E=T/t.length,b=Math.abs(r-N);return a.Match_Distance?E+b/a.Match_Distance:b?1:E}var o=this.Match_Threshold,s=e.indexOf(t,r);s!=-1&&(o=Math.min(i(0,s),o),s=e.lastIndexOf(t,r+t.length),s!=-1&&(o=Math.min(i(0,s),o)));var l=1<<t.length-1;s=-1;for(var c,f,m=t.length+e.length,u,p=0;p<t.length;p++){for(c=0,f=m;c<f;)i(p,r+f)<=o?c=f:m=f,f=Math.floor((m-c)/2+c);m=f;var g=Math.max(1,r-f+1),d=Math.min(r+f,e.length)+t.length,w=Array(d+2);w[d+1]=(1<<p)-1;for(var h=d;h>=g;h--){var x=n[e.charAt(h-1)];if(p===0?w[h]=(w[h+1]<<1|1)&x:w[h]=(w[h+1]<<1|1)&x|((u[h+1]|u[h])<<1|1)|u[h+1],w[h]&l){var v=i(p,h-1);if(v<=o)if(o=v,s=h-1,s>r)g=Math.max(1,2*r-s);else break}}if(i(p+1,r)>o)break;u=w}return s};y.prototype.match_alphabet_=function(e){for(var t={},r=0;r<e.length;r++)t[e.charAt(r)]=0;for(var r=0;r<e.length;r++)t[e.charAt(r)]|=1<<e.length-r-1;return t};y.prototype.patch_addContext_=function(e,t){if(t.length!=0){if(e.start2===null)throw Error("patch not initialized");for(var r=t.substring(e.start2,e.start2+e.length1),n=0;t.indexOf(r)!=t.lastIndexOf(r)&&r.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)n+=this.Patch_Margin,r=t.substring(e.start2-n,e.start2+e.length1+n);n+=this.Patch_Margin;var a=t.substring(e.start2-n,e.start2);a&&e.diffs.unshift(new y.Diff(O,a));var i=t.substring(e.start2+e.length1,e.start2+e.length1+n);i&&e.diffs.push(new y.Diff(O,i)),e.start1-=a.length,e.start2-=a.length,e.length1+=a.length+i.length,e.length2+=a.length+i.length}};y.prototype.patch_make=function(e,t,r){var n,a;if(typeof e=="string"&&typeof t=="string"&&typeof r>"u")n=e,a=this.diff_main(n,t,!0),a.length>2&&(this.diff_cleanupSemantic(a),this.diff_cleanupEfficiency(a));else if(e&&typeof e=="object"&&typeof t>"u"&&typeof r>"u")a=e,n=this.diff_text1(a);else if(typeof e=="string"&&t&&typeof t=="object"&&typeof r>"u")n=e,a=t;else if(typeof e=="string"&&typeof t=="string"&&r&&typeof r=="object")n=e,a=r;else throw new Error("Unknown call format to patch_make.");if(a.length===0)return[];for(var i=[],o=new y.patch_obj,s=0,l=0,c=0,f=n,m=n,u=0;u<a.length;u++){var p=a[u][0],g=a[u][1];switch(!s&&p!==O&&(o.start1=l,o.start2=c),p){case F:o.diffs[s++]=a[u],o.length2+=g.length,m=m.substring(0,c)+g+m.substring(c);break;case $:o.length1+=g.length,o.diffs[s++]=a[u],m=m.substring(0,c)+m.substring(c+g.length);break;case O:g.length<=2*this.Patch_Margin&&s&&a.length!=u+1?(o.diffs[s++]=a[u],o.length1+=g.length,o.length2+=g.length):g.length>=2*this.Patch_Margin&&s&&(this.patch_addContext_(o,f),i.push(o),o=new y.patch_obj,s=0,f=m,l=c);break}p!==F&&(l+=g.length),p!==$&&(c+=g.length)}return s&&(this.patch_addContext_(o,f),i.push(o)),i};y.prototype.patch_deepCopy=function(e){for(var t=[],r=0;r<e.length;r++){var n=e[r],a=new y.patch_obj;a.diffs=[];for(var i=0;i<n.diffs.length;i++)a.diffs[i]=new y.Diff(n.diffs[i][0],n.diffs[i][1]);a.start1=n.start1,a.start2=n.start2,a.length1=n.length1,a.length2=n.length2,t[r]=a}return t};y.prototype.patch_apply=function(e,t){if(e.length==0)return[t,[]];e=this.patch_deepCopy(e);var r=this.patch_addPadding(e);t=r+t+r,this.patch_splitMax(e);for(var n=0,a=[],i=0;i<e.length;i++){var o=e[i].start2+n,s=this.diff_text1(e[i].diffs),l,c=-1;if(s.length>this.Match_MaxBits?(l=this.match_main(t,s.substring(0,this.Match_MaxBits),o),l!=-1&&(c=this.match_main(t,s.substring(s.length-this.Match_MaxBits),o+s.length-this.Match_MaxBits),(c==-1||l>=c)&&(l=-1))):l=this.match_main(t,s,o),l==-1)a[i]=!1,n-=e[i].length2-e[i].length1;else{a[i]=!0,n=l-o;var f;if(c==-1?f=t.substring(l,l+s.length):f=t.substring(l,c+this.Match_MaxBits),s==f)t=t.substring(0,l)+this.diff_text2(e[i].diffs)+t.substring(l+s.length);else{var m=this.diff_main(s,f,!1);if(s.length>this.Match_MaxBits&&this.diff_levenshtein(m)/s.length>this.Patch_DeleteThreshold)a[i]=!1;else{this.diff_cleanupSemanticLossless(m);for(var u=0,p,g=0;g<e[i].diffs.length;g++){var d=e[i].diffs[g];d[0]!==O&&(p=this.diff_xIndex(m,u)),d[0]===F?t=t.substring(0,l+p)+d[1]+t.substring(l+p):d[0]===$&&(t=t.substring(0,l+p)+t.substring(l+this.diff_xIndex(m,u+d[1].length))),d[0]!==$&&(u+=d[1].length)}}}}}return t=t.substring(r.length,t.length-r.length),[t,a]};y.prototype.patch_addPadding=function(e){for(var t=this.Patch_Margin,r="",n=1;n<=t;n++)r+=String.fromCharCode(n);for(var n=0;n<e.length;n++)e[n].start1+=t,e[n].start2+=t;var a=e[0],i=a.diffs;if(i.length==0||i[0][0]!=O)i.unshift(new y.Diff(O,r)),a.start1-=t,a.start2-=t,a.length1+=t,a.length2+=t;else if(t>i[0][1].length){var o=t-i[0][1].length;i[0][1]=r.substring(i[0][1].length)+i[0][1],a.start1-=o,a.start2-=o,a.length1+=o,a.length2+=o}if(a=e[e.length-1],i=a.diffs,i.length==0||i[i.length-1][0]!=O)i.push(new y.Diff(O,r)),a.length1+=t,a.length2+=t;else if(t>i[i.length-1][1].length){var o=t-i[i.length-1][1].length;i[i.length-1][1]+=r.substring(0,o),a.length1+=o,a.length2+=o}return r};y.prototype.patch_splitMax=function(e){for(var t=this.Match_MaxBits,r=0;r<e.length;r++)if(!(e[r].length1<=t)){var n=e[r];e.splice(r--,1);for(var a=n.start1,i=n.start2,o="";n.diffs.length!==0;){var s=new y.patch_obj,l=!0;for(s.start1=a-o.length,s.start2=i-o.length,o!==""&&(s.length1=s.length2=o.length,s.diffs.push(new y.Diff(O,o)));n.diffs.length!==0&&s.length1<t-this.Patch_Margin;){var c=n.diffs[0][0],f=n.diffs[0][1];c===F?(s.length2+=f.length,i+=f.length,s.diffs.push(n.diffs.shift()),l=!1):c===$&&s.diffs.length==1&&s.diffs[0][0]==O&&f.length>2*t?(s.length1+=f.length,a+=f.length,l=!1,s.diffs.push(new y.Diff(c,f)),n.diffs.shift()):(f=f.substring(0,t-s.length1-this.Patch_Margin),s.length1+=f.length,a+=f.length,c===O?(s.length2+=f.length,i+=f.length):l=!1,s.diffs.push(new y.Diff(c,f)),f==n.diffs[0][1]?n.diffs.shift():n.diffs[0][1]=n.diffs[0][1].substring(f.length))}o=this.diff_text2(s.diffs),o=o.substring(o.length-this.Patch_Margin);var m=this.diff_text1(n.diffs).substring(0,this.Patch_Margin);m!==""&&(s.length1+=m.length,s.length2+=m.length,s.diffs.length!==0&&s.diffs[s.diffs.length-1][0]===O?s.diffs[s.diffs.length-1][1]+=m:s.diffs.push(new y.Diff(O,m))),l||e.splice(++r,0,s)}}};y.prototype.patch_toText=function(e){for(var t=[],r=0;r<e.length;r++)t[r]=e[r];return t.join("")};y.prototype.patch_fromText=function(e){var t=[];if(!e)return t;for(var r=e.split(`
3
+ `),n=0,a=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;n<r.length;){var i=r[n].match(a);if(!i)throw new Error("Invalid patch string: "+r[n]);var o=new y.patch_obj;for(t.push(o),o.start1=parseInt(i[1],10),i[2]===""?(o.start1--,o.length1=1):i[2]=="0"?o.length1=0:(o.start1--,o.length1=parseInt(i[2],10)),o.start2=parseInt(i[3],10),i[4]===""?(o.start2--,o.length2=1):i[4]=="0"?o.length2=0:(o.start2--,o.length2=parseInt(i[4],10)),n++;n<r.length;){var s=r[n].charAt(0);try{var l=decodeURI(r[n].substring(1))}catch{throw new Error("Illegal escape in patch_fromText: "+l)}if(s=="-")o.diffs.push(new y.Diff($,l));else if(s=="+")o.diffs.push(new y.Diff(F,l));else if(s==" ")o.diffs.push(new y.Diff(O,l));else{if(s=="@")break;if(s!=="")throw new Error('Invalid patch mode "'+s+'" in: '+l)}n++}}return t};y.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0};y.patch_obj.prototype.toString=function(){var e,t;this.length1===0?e=this.start1+",0":this.length1==1?e=this.start1+1:e=this.start1+1+","+this.length1,this.length2===0?t=this.start2+",0":this.length2==1?t=this.start2+1:t=this.start2+1+","+this.length2;for(var r=["@@ -"+e+" +"+t+` @@
4
+ `],n,a=0;a<this.diffs.length;a++){switch(this.diffs[a][0]){case F:n="+";break;case $:n="-";break;case O:n=" ";break}r[a+1]=n+encodeURI(this.diffs[a][1])+`
5
+ `}return r.join("").replace(/%20/g," ")};Be.exports=y;Be.exports.diff_match_patch=y;Be.exports.DIFF_DELETE=$;Be.exports.DIFF_INSERT=F;Be.exports.DIFF_EQUAL=O});var Ke=globalThis.DOMParser,Ve=globalThis.XMLSerializer;function ia(e={}){e.DOMParser&&(Ke=e.DOMParser),e.XMLSerializer&&(Ve=e.XMLSerializer)}function B(){if(!Ke&&globalThis.DOMParser&&(Ke=globalThis.DOMParser),!Ke)throw new Error("DOMParser is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new Ke}function J(){if(!Ve&&globalThis.XMLSerializer&&(Ve=globalThis.XMLSerializer),!Ve)throw new Error("XMLSerializer is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new Ve}function br(e,t="text/xml"){return B().parseFromString(e,t)}function j(e){return J().serializeToString(e)}var ft=console,Mt=Object.freeze({silent:0,error:1,warn:2,info:3}),oa=typeof process<"u"&&process?.env?.NODE_ENV==="production"?"warn":"info",Lt=oa;function sa(e){let t=String(e||"").toLowerCase();return Object.prototype.hasOwnProperty.call(Mt,t)?t:Lt}function _t(e){return Mt[Lt]>=Mt[e]}function la(e,t={}){ft=e||console,t.level&&(Lt=sa(t.level))}function A(...e){_t("info")&&(ft.log||(()=>{}))(...e)}function Se(...e){_t("warn")&&(ft.warn||(()=>{}))(...e)}function K(...e){_t("error")&&(ft.error||(()=>{}))(...e)}var xr="Author",Nr="Unknown";function ca(e){xr=typeof e=="string"&&e.trim()?e.trim():"Author"}function G(){return xr}function ua(e){Nr=typeof e=="string"&&e.trim()?e.trim():"Unknown"}function Bt(){return Nr}var fa=[{regex:/<b>(.+?)<\/b>/i,format:{bold:!0}},{regex:/<strong>(.+?)<\/strong>/i,format:{bold:!0}},{regex:/<i>(.+?)<\/i>/i,format:{italic:!0}},{regex:/<em>(.+?)<\/em>/i,format:{italic:!0}},{regex:/<u>(.+?)<\/u>/i,format:{underline:!0}},{regex:/<s>(.+?)<\/s>/i,format:{strikethrough:!0}},{regex:/<strike>(.+?)<\/strike>/i,format:{strikethrough:!0}},{regex:/<del>(.+?)<\/del>/i,format:{strikethrough:!0}},{regex:/&lt;b&gt;(.+?)&lt;\/b&gt;/i,format:{bold:!0},isEscaped:!0},{regex:/&lt;strong&gt;(.+?)&lt;\/strong&gt;/i,format:{bold:!0},isEscaped:!0},{regex:/&lt;i&gt;(.+?)&lt;\/i&gt;/i,format:{italic:!0},isEscaped:!0},{regex:/&lt;em&gt;(.+?)&lt;\/em&gt;/i,format:{italic:!0},isEscaped:!0},{regex:/&lt;u&gt;(.+?)&lt;\/u&gt;/i,format:{underline:!0},isEscaped:!0},{regex:/&lt;s&gt;(.+?)&lt;\/s&gt;/i,format:{strikethrough:!0},isEscaped:!0},{regex:/\*\*\*(.+?)\*\*\*/,format:{bold:!0,italic:!0}},{regex:/\*\*\+\+(.+?)\+\+\*\*/,format:{bold:!0,underline:!0}},{regex:/\*\*(.+?)\*\*/,format:{bold:!0}},{regex:/__(.+?)__/,format:{bold:!0}},{regex:/\+\+(.+?)\+\+/,format:{underline:!0}},{regex:/~~(.+?)~~/,format:{strikethrough:!0}},{regex:/~(.+?)~/,format:{strikethrough:!0}},{regex:/\*(?!\*)(.+?)\*(?!\*)/,format:{italic:!0}},{regex:/_(?!_)(.+?)_(?!_)/,format:{italic:!0}}];function q(e){if(!e)return{cleanText:"",formatHints:[]};let t=[],r="",n=[];for(let s of fa){let l,c=s.regex.source||s.regex.toString().replace(/^\/|\/[gimuy]*$/g,""),f="g"+(s.regex.ignoreCase?"i":""),m=new RegExp(c,f);for(;(l=m.exec(e))!==null;)n.push({start:l.index,end:l.index+l[0].length,fullMatch:l[0],innerText:s.isEscaped?ma(l[1]):l[1],format:s.format}),l.index===m.lastIndex&&m.lastIndex++}n.sort((s,l)=>s.start-l.start||l.end-s.end);let a=[],i=0;for(let s of n)s.start>=i&&(a.push(s),i=s.end);let o=0;for(let s of a){r+=e.slice(o,s.start);let l=q(s.innerText),c=r.length;r+=l.cleanText;let f=r.length;t.push({start:c,end:f,format:s.format});for(let m of l.formatHints)t.push({start:c+m.start,end:c+m.end,format:m.format});o=s.end}return r+=e.slice(o),{cleanText:r,formatHints:t}}function he(e,t,r){return e.filter(n=>n.start<r&&n.end>t)}function $t(...e){let t={};for(let r of e)r&&Object.assign(t,r);return t}function ma(e){return e?e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#039;/g,"'"):""}var mt=String.raw`(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|\d+\.|[ivxlcIVXLC]+\.|[-*\u2022])`,vr=new RegExp(`^(\\s*)((?:${mt})\\s+)`),Tr=new RegExp(`^(\\s*)((?:${mt})\\s*)`),pa=new RegExp(`^(\\s*)((?:${mt})\\s+)`,"m"),ga=new RegExp(`^(\\s*)((?:${mt})\\s*)`,"m");function yr(e){return typeof e!="string"?!1:e.includes(`
6
+ `)&&pa.test(e)}function pt(e){return typeof e!="string"?!1:e.includes(`
7
+ `)&&ga.test(e.trim())}function ue(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?Tr:vr;return e.match(n)}function we(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?Tr:vr;return e.replace(n,"")}var I="http://schemas.openxmlformats.org/wordprocessingml/2006/main";var re=Object.freeze({EQUAL:"equal",DELETE:"delete",INSERT:"insert"}),C=Object.freeze({TEXT:"run",DELETION:"deletion",INSERTION:"insertion",HYPERLINK:"hyperlink",BOOKMARK:"bookmark",FIELD:"field",CONTAINER_START:"container_start",CONTAINER_END:"container_end",PARAGRAPH_START:"paragraph_start"}),Le=Object.freeze({SDT:"sdt",SMART_TAG:"smartTag",CUSTOM_XML:"customXml",FIELD_COMPLEX:"fldComplex"}),Er=Object.freeze({PARAGRAPH:"paragraph",BULLET_LIST:"bullet_list",NUMBERED_LIST:"numbered_list",TABLE:"table"}),_=Object.freeze({DECIMAL:"decimal",LOWER_ALPHA:"lowerLetter",UPPER_ALPHA:"upperLetter",LOWER_ROMAN:"lowerRoman",UPPER_ROMAN:"upperRoman",BULLET:"bullet",OUTLINE:"outline"}),V=Object.freeze({PERIOD:"period",PAREN_RIGHT:"parenRight",PAREN_BOTH:"parenBoth",NONE:"none"});function ee(e){return e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;"):""}var da=1e3;function be(){return da++}function ae(e=new Date){return e.toISOString()}function fe(e){let t=typeof e=="string"&&e.trim()?e.trim():G();return{id:be(),author:t,date:ae()}}var Pr=`
8
+ `,ha=Pr.length;function Sr(e,t){return e<t-1}function _e(e,t,r){return Sr(t,r)?e+Pr:e}function Ie(e,t,r){return Sr(t,r)?e+ha:e}function Y(e,t){return!e||typeof e.getElementsByTagName!="function"?[]:Array.from(e.getElementsByTagName(t))}function M(e,t){if(!e||typeof e.getElementsByTagName!="function")return null;let r=e.getElementsByTagName(t);return r.length>0?r[0]:null}function z(e,t,r){return!e||typeof e.getElementsByTagNameNS!="function"?[]:Array.from(e.getElementsByTagNameNS(t,r))}function D(e,t,r){if(!e||typeof e.getElementsByTagNameNS!="function")return null;let n=e.getElementsByTagNameNS(t,r);return n.length>0?n[0]:null}function Ir(e,t,r,n=`w:${r}`){let a=z(e,t,r);return a.length>0?a:Y(e,n)}function Ar(e,t,r,n=`w:${r}`){let a=D(e,t,r);return a||M(e,n)}function U(e){return M(e,"parsererror")}function Ft(e){return Array.from(e?.childNodes||[])}function kr(e){return Array.from(e.attributes).map(t=>`${t.name}="${t.value}"`).join(" ")}function Xt(e,t,r=""){return!e||e.namespaceURI!==t?!1:r?e.localName===r:!0}var Dt=0;function gt(e,t={}){let r=[],n="",a=t.xmlDoc||null;if(!e&&!a)return{runModel:r,acceptedText:n,pPr:null};try{let i=a||B().parseFromString(e,"application/xml"),o=U(i);if(o)return K("OOXML parse error:",o.textContent),{runModel:r,acceptedText:n,pPr:null};let s=z(i,I,"p");return s.length===0?(Se("No paragraphs found in OOXML"),{runModel:r,acceptedText:n,pPr:null}):Cr(s,{includeParagraphBoundaries:!0})}catch(i){return K("Error ingesting OOXML:",i),{runModel:r,acceptedText:n,pPr:null}}}function zt(e){return e?Cr([e],{includeParagraphBoundaries:!1}):{runModel:[],acceptedText:"",pPr:null}}function Wt(e){let t=D(e,I,"pPr");if(!t)return null;let r=D(t,I,"numPr");if(!r)return null;let n=D(r,I,"numId"),a=D(r,I,"ilvl");if(!n)return null;let i=n.getAttribute("w:val"),o=i==="1"?"bullet":i==="2"?"numbered":"unknown";return{numId:i,ilvl:parseInt(a?.getAttribute("w:val")||"0",10),type:o}}function Cr(e,t={}){let r=t.includeParagraphBoundaries??!0,n=[],a="",i=0,o=null;for(let s=0;s<e.length;s++){let l=e[s],c=D(l,I,"pPr");s===0&&(o=c),n.push({kind:C.PARAGRAPH_START,pPrElement:c||null,startOffset:i,endOffset:i,text:""});let f=Ze(l,i,n);a+=f.text,i=a.length,r&&(a=_e(a,s,e.length),i=Ie(i,s,e.length))}return{runModel:n,acceptedText:a,pPr:o}}function Ze(e,t,r){let n=t,a="",i=wa(r);for(let o of Ft(e)){if(Xt(o,I,"pPr")||Xt(o,I,"proofErr"))continue;let s=i.get(o.localName);if(!s)continue;let l=s(o,n);n=l.offset,a+=l.text}return{offset:n,text:a}}function wa(e){let t=new Map;return t.set("sdt",(r,n)=>{let a=`sdt_${Dt++}`,i=D(r,I,"sdtPr"),o=D(r,I,"sdtContent");e.push({kind:C.CONTAINER_START,containerKind:Le.SDT,containerId:a,propertiesXml:i?j(i):"",startOffset:n,endOffset:n,text:""});let s=o?Ze(o,n,e):{offset:n,text:""};return e.push({kind:C.CONTAINER_END,containerKind:Le.SDT,containerId:a,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("smartTag",(r,n)=>{let a=`smartTag_${Dt++}`;e.push({kind:C.CONTAINER_START,containerKind:Le.SMART_TAG,containerId:a,propertiesXml:kr(r),startOffset:n,endOffset:n,text:""});let i=Ze(r,n,e);return e.push({kind:C.CONTAINER_END,containerKind:Le.SMART_TAG,containerId:a,startOffset:i.offset,endOffset:i.offset,text:""}),i}),t.set("del",(r,n)=>{let a=xa(r,n);return a&&e.push(a),{offset:n,text:""}}),t.set("bookmarkStart",(r,n)=>(e.push({kind:C.BOOKMARK,nodeXml:j(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("bookmarkEnd",(r,n)=>(e.push({kind:C.BOOKMARK,nodeXml:j(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("ins",(r,n)=>Ze(r,n,e)),t.set("hyperlink",(r,n)=>{let a=`hyperlink_${Dt++}`,i=r.getAttribute("r:id")||"",o=r.getAttribute("w:anchor")||"";e.push({kind:C.CONTAINER_START,containerKind:"hyperlink",containerId:a,propertiesXml:JSON.stringify({rId:i,anchor:o}),startOffset:n,endOffset:n,text:""});let s=Ze(r,n,e);return e.push({kind:C.CONTAINER_END,containerKind:"hyperlink",containerId:a,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("r",(r,n)=>{let a=ba(r,n);return!a||!a.text?{offset:n,text:""}:(e.push(a),{offset:n+a.text.length,text:a.text})}),t}function ba(e,t){let r=Ar(e,I,"rPr"),n=r?j(r):"",a="";for(let i of Ft(e)){let o=i.nodeName;o.endsWith(":t")||o==="t"?a+=i.textContent||"":o.endsWith(":br")||o==="br"||o.endsWith(":cr")||o==="cr"?a+=`
9
+ `:o.endsWith(":tab")||o==="tab"?a+=" ":(o.endsWith(":noBreakHyphen")||o==="noBreakHyphen")&&(a+="\u2011")}return a?{kind:C.TEXT,text:a,rPrXml:n,startOffset:t,endOffset:t+a.length}:null}function xa(e,t){let r=e.getAttribute("w:author")||"",n="",a=z(e,I,"delText");for(let o of a)n+=o.textContent||"";let i=z(e,I,"r");for(let o of i){let s=z(o,I,"delText");for(let l of s)n+=l.textContent||""}return n?{kind:C.DELETION,text:n,rPrXml:"",startOffset:t,endOffset:t,author:r,nodeXml:j(e)}:null}function Ut(e){let t=D(e,I,"tblGrid"),n=(t?z(t,I,"gridCol"):[]).length,a=z(e,I,"tr"),i=a.length,o=Array.from({length:i},()=>Array.from({length:n},()=>null)),s=new Map,l=new Map;for(let c=0;c<a.length;c++){let f=a[c],m=z(f,I,"tc"),u=0;for(let p=0;p<m.length;p++){let g=m[p],d=D(g,I,"tcPr");for(;u<n&&o[c][u]!==null;)u++;if(u>=n)break;let w=d?D(d,I,"gridSpan")||M(d,"w:gridSpan"):null,h=parseInt(w?.getAttribute("w:val")||"1",10),x=d?D(d,I,"vMerge")||M(d,"w:vMerge"):null,v=x?.getAttribute("w:val"),T=x!==null,N;if(T&&v!=="restart"){let E=l.get(u);E?(E.cell.rowSpan++,N={gridRow:c,gridCol:u,rowSpan:0,colSpan:h,tcNode:g,blocks:[],tcPrXml:Ht(d),isMergeOrigin:!1,isMergeContinuation:!0,mergeOrigin:E.cell}):N=Na(c,u,h,g,d)}else{let E=Or(g);if(N={gridRow:c,gridCol:u,rowSpan:1,colSpan:h,tcNode:g,blocks:E,tcPrXml:Ht(d),isMergeOrigin:T&&v==="restart",isMergeContinuation:!1,getText:()=>E.map(b=>b.acceptedText).join(`
10
+ `)},T&&v==="restart")for(let b=0;b<h;b++)l.set(u+b,{originRow:c,cell:N});else for(let b=0;b<h;b++)l.delete(u+b)}for(let E=0;E<h;E++){let b=u+E;b<n&&(o[c][b]=N,s.set(`${c},${b}`,N))}u+=h}}return{rowCount:i,colCount:n,grid:o,cellMap:s,tblPrXml:va(e),tblGridXml:Ta(e),trPrList:Array.from(a).map(c=>ya(c))}}function Na(e,t,r,n,a){let i=Or(n);return{gridRow:e,gridCol:t,rowSpan:1,colSpan:r,tcNode:n,blocks:i,tcPrXml:Ht(a),isMergeOrigin:!1,isMergeContinuation:!1,getText:()=>i.map(o=>o.acceptedText).join(`
11
+ `)}}function Or(e){return Ir(e,I,"p").map(r=>{let{runModel:n,acceptedText:a,pPr:i}=zt(r);return{runModel:n,acceptedText:a,pPr:i}})}function Ht(e){return e?j(e):"<w:tcPr/>"}function va(e){let t=D(e,I,"tblPr");return t?j(t):"<w:tblPr/>"}function Ta(e){let t=D(e,I,"tblGrid");return t?j(t):"<w:tblGrid/>"}function ya(e){let t=D(e,I,"trPr");return t?j(t):"<w:trPr/>"}var Lr=aa(Rr(),1);var Mr=new Lr.diff_match_patch;function Ea(e,t){let r=[],n=new Map;function a(l){let c=[],f=/(\S+)(\s*)/g,m;for(;(m=f.exec(l))!==null;)m[1]&&c.push(m[1]),m[2]&&c.push(m[2]);return c}function i(l){let c="";for(let f of l)if(n.has(f))c+=String.fromCharCode(n.get(f));else{let m=r.length;r.push(f),n.set(f,m),c+=String.fromCharCode(m)}return c}let o=a(e),s=a(t);return{chars1:i(o),chars2:i(s),wordArray:r}}function Pa(e,t){let r=[];for(let[n,a]of e){let i=[];for(let o=0;o<a.length;o++){let s=a.charCodeAt(o);s<t.length&&i.push(t[s])}r.push([n,i.join("")])}return r}function Ye(e,t,r={}){if(e===t)return[[0,e]];if(!e)return[[1,t]];if(!t)return[[-1,e]];let{cleanupSemantic:n=!0}=r,{chars1:a,chars2:i,wordArray:o}=Ea(e,t),s=Mr.diff_main(a,i);return n&&Mr.diff_cleanupSemantic(s),Pa(s,o)}function dt(e,t,r={}){if(e===t)return[{type:re.EQUAL,startOffset:0,endOffset:e.length,text:e}];if(!e)return[{type:re.INSERT,startOffset:0,endOffset:0,text:t}];if(!t)return[{type:re.DELETE,startOffset:0,endOffset:e.length,text:e}];let n=Ye(e,t,r),a=[],i=0;for(let[o,s]of n)o===0?(a.push({type:re.EQUAL,startOffset:i,endOffset:i+s.length,text:s}),i+=s.length):o===-1?(a.push({type:re.DELETE,startOffset:i,endOffset:i+s.length,text:s}),i+=s.length):o===1&&a.push({type:re.INSERT,startOffset:i,endOffset:i,text:s});return a}var Sa=/\s+xmlns:[^=]+="[^"]*"/g;function ht(e,t){let r=Ra(t),n=[],a=0;for(let i of e){if(i.kind!==C.TEXT&&i.kind!==C.HYPERLINK){n.push(i);continue}for(;a<r.length&&r[a]<=i.startOffset;)a++;let o=a,s=i.startOffset,l=!1;for(;o<r.length;){let c=r[o];if(c>=i.endOffset)break;c>s&&(l=!0,n.push({...i,text:i.text.slice(s-i.startOffset,c-i.startOffset),startOffset:s,endOffset:c}),s=c),o++}if(a=o,!l){n.push(i);continue}n.push({...i,text:i.text.slice(s-i.startOffset),startOffset:s,endOffset:i.endOffset})}return n}function wt(e,t,r){let{generateRedlines:n,author:a}=r,i=[],o=new Set,s=Ma(t),l=Ca(e),c=Oa(s.nonInsertOps),f={containerStack:[],lastParagraphStartIndex:-1,currentParagraphPPrXml:"",currentParagraphPPrElement:null};for(let u of e){if(u.kind===C.CONTAINER_START){f.containerStack.push(u.containerId),i.push({...u});continue}if(u.kind===C.CONTAINER_END){f.containerStack.pop(),i.push({...u});continue}if(u.kind===C.PARAGRAPH_START){f.currentParagraphPPrXml=typeof u.pPrXml=="string"?u.pPrXml:"",f.currentParagraphPPrElement=u.pPrElement||null,i.push({...u}),f.lastParagraphStartIndex=i.length-1;continue}if(u.kind===C.BOOKMARK||u.kind===C.DELETION){i.push({...u});continue}let p=c(u.startOffset,u.endOffset),g=s.insertOpsByStartOffset.get(u.startOffset)||[];for(let d of g)o.has(d)||(o.add(d),Ia({insertOp:d,splitModel:e,styleLookup:l,patchedModel:i,state:f,options:r,generateRedlines:n,author:a}));if(!p||p.type===re.EQUAL){i.push({...u,containerContext:f.containerStack.length>0?f.containerStack[f.containerStack.length-1]:null});continue}p.type===re.DELETE&&n&&i.push({...u,kind:C.DELETION,author:a,containerContext:f.containerStack.length>0?f.containerStack[f.containerStack.length-1]:null})}let m=e.length>0?Math.max(...e.map(u=>u.endOffset)):0;for(let u of s.sortedInsertOps){if(u.startOffset<m||o.has(u))continue;let p=e[e.length-1];i.push({kind:n?C.INSERTION:C.TEXT,text:u.text,rPrXml:p?.rPrXml||"",startOffset:u.startOffset,endOffset:u.startOffset+u.text.length,author:n?a:void 0})}return i}function Ia(e){let{insertOp:t,splitModel:r,styleLookup:n,patchedModel:a,state:i,options:o,generateRedlines:s,author:l}=e,c=t.text.split(`
12
+ `),f=ka(n,t.startOffset,t.text);for(let m=0;m<c.length;m++){let u=Aa(c[m],o.numberingService,i),p=u.lineText;if(m>0){let g=_r(i);u.isListLine&&u.numId&&(g=o.numberingService.buildListPPr(u.numId,u.ilvl)),a.push({kind:C.PARAGRAPH_START,pPrXml:g,startOffset:t.startOffset,endOffset:t.startOffset,text:""}),i.currentParagraphPPrXml=g,i.currentParagraphPPrElement=null,i.lastParagraphStartIndex=a.length-1}else if(u.isListLine&&u.numId&&i.lastParagraphStartIndex>=0){let g=o.numberingService.buildListPPr(u.numId,u.ilvl);a[i.lastParagraphStartIndex].pPrXml=g,a[i.lastParagraphStartIndex].pPrElement=null,i.currentParagraphPPrXml=g,i.currentParagraphPPrElement=null,A(`[Patching] Converted current paragraph to list item: numId=${u.numId}, ilvl=${u.ilvl}`)}(p.length>0||m>0)&&a.push({kind:s?C.INSERTION:C.TEXT,text:p,rPrXml:f?.rPrXml||"",startOffset:t.startOffset,endOffset:t.startOffset+p.length,author:s?l:void 0,containerContext:i.containerStack.length>0?i.containerStack[i.containerStack.length-1]:null})}}function Aa(e,t,r){if(!t)return{lineText:e,isListLine:!1,numId:null,ilvl:0};let n=ue(e,{allowZeroSpaceAfterMarker:!0});if(!n)return{lineText:e,isListLine:!1,numId:null,ilvl:0};let a=n[2].trim(),i=t.detectNumberingFormat(a),o=e.match(/^(\s*)/),s=o?o[1].length:0,l=s>=4?4:2,c=Math.floor(s/l),f=_r(r),m=we(e,{allowZeroSpaceAfterMarker:!0}),u=f.match(/w:numId w:val="(\d+)"/),p=f.match(/w:ilvl w:val="(\d+)"/),g=u?u[1]:null,d=p?parseInt(p[1],10):0,w=t.getOrCreateNumId({type:i.format},{numId:g,type:"unknown"}),h=i.format==="outline"?Math.min(8,i.depth):Math.min(8,c+d);return{lineText:m,isListLine:!0,numId:w,ilvl:h}}function _r(e){return e.currentParagraphPPrXml?e.currentParagraphPPrXml:e.currentParagraphPPrElement?(e.currentParagraphPPrXml=j(e.currentParagraphPPrElement).replace(Sa,""),e.currentParagraphPPrXml):""}function ka(e,t,r){let n=e.findRunBefore(t),a=e.findRunAfter(t);return!n&&!a?null:n?a?r&&r.endsWith(" ")?a:(r&&r.startsWith(" "),n):n:a}function Ca(e){let t=e.filter(a=>a.kind===C.TEXT),r=t.map(a=>a.startOffset),n=t.map(a=>a.endOffset);return{findRunBefore(a){let i=0,o=n.length-1,s=-1;for(;i<=o;){let l=i+o>>1;n[l]<=a?(s=l,i=l+1):o=l-1}return s>=0?t[s]:null},findRunAfter(a){let i=0,o=r.length-1,s=-1;for(;i<=o;){let l=i+o>>1;r[l]>=a?(s=l,o=l-1):i=l+1}return s>=0?t[s]:null}}}function Oa(e){let t=0;return(r,n)=>{for(;t<e.length&&e[t].endOffset<=r;)t++;let a=e[t];return a&&a.startOffset<=r&&a.endOffset>=n?a:null}}function Ra(e){let t=new Set;for(let r of e)t.add(r.startOffset),t.add(r.endOffset);return Array.from(t).sort((r,n)=>r-n)}function Ma(e){let t=new Map,r=[],n=[];for(let a of e){if(a.type===re.INSERT){t.has(a.startOffset)||t.set(a.startOffset,[]),t.get(a.startOffset).push(a),n.push(a);continue}r.push(a)}return r.sort((a,i)=>a.startOffset-i.startOffset||a.endOffset-i.endOffset),n.sort((a,i)=>a.startOffset-i.startOffset||a.endOffset-i.endOffset),{insertOpsByStartOffset:t,nonInsertOps:r,sortedInsertOps:n}}var Xr="http://schemas.openxmlformats.org/wordprocessingml/2006/main",La="http://schemas.openxmlformats.org/officeDocument/2006/relationships",_a="http://schemas.microsoft.com/office/2006/xmlPackage",Br="http://schemas.openxmlformats.org/package/2006/relationships",Ba='<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>',$r='<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/>';var $a=`
13
+ <w:numbering xmlns:w="${Xr}">
14
+ <w:abstractNum w:abstractNumId="0">
15
+ <w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText w:val="&#8226;"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr></w:lvl>
16
+ </w:abstractNum>
17
+ <w:abstractNum w:abstractNumId="1">
18
+ <w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1."/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr></w:lvl>
19
+ </w:abstractNum>
20
+ <w:num w:numId="1"><w:abstractNumId w:val="0"/></w:num>
21
+ <w:num w:numId="2"><w:abstractNumId w:val="1"/></w:num>
22
+ </w:numbering>`.trim();function Fa(e){return e?e.replace(/<\?xml[^>]*\?>/g,""):""}function Dr(e,t=!0){let r=t?` xmlns:r="${La}"`:"";return`<w:document xmlns:w="${Xr}"${r}><w:body>${e}</w:body></w:document>`}function Fr(e){return`
23
+ <pkg:part pkg:name="/word/numbering.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml">
24
+ <pkg:xmlData>
25
+ ${Fa(e)}
26
+ </pkg:xmlData>
27
+ </pkg:part>`}function zr(e,t="",r=""){return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
28
+ <pkg:package xmlns:pkg="${_a}">
29
+ <pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml">
30
+ <pkg:xmlData>
31
+ <Relationships xmlns="${Br}">
32
+ ${Ba}
33
+ </Relationships>
34
+ </pkg:xmlData>
35
+ </pkg:part>
36
+ <pkg:part pkg:name="/word/_rels/document.xml.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml">
37
+ <pkg:xmlData>
38
+ <Relationships xmlns="${Br}">
39
+ ${t}
40
+ </Relationships>
41
+ </pkg:xmlData>
42
+ </pkg:part>${r}
43
+ <pkg:part pkg:name="/word/document.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
44
+ <pkg:xmlData>
45
+ ${e}
46
+ </pkg:xmlData>
47
+ </pkg:part>
48
+ </pkg:package>`}function Wr(e,t={}){let{includeNumbering:r=!1,numberingXml:n=null,appendTrailingParagraph:a=!0}=t,i=a?`${e}<w:p><w:pPr></w:pPr></w:p>`:e,o=Dr(i,!0),s="",l="";return n?(s=$r,l+=Fr(n)):r&&(s=$r,l+=Fr($a)),zr(o,s,l)}function Hr(e){let t=Dr(e,!0);return zr(t)}var Xa=/\s+xmlns:[^=]+="[^"]*"/g;function ie(e,t,r=[],n={}){let a=Da(n),{author:i,generateRedlines:o}=a,s=[],l="",c=null,f=[];function m(){if(f.length>0||s.length===0){let u="";l?u=Ae(l):c?(l=Ae(j(c)),u=l):t&&(typeof t=="string"?u=t:u=j(t),u=Ae(u)),s.push(`<w:p>${u}${f.join("")}</w:p>`),f=[]}}for(let u of e)switch(u.kind){case C.PARAGRAPH_START:(f.length>0||s.length>0)&&m(),l=u.pPrXml||"",c=u.pPrElement||null;break;case C.TEXT:f.push(Ur(u,r,a));break;case C.DELETION:o&&f.push(za(u,a));break;case C.INSERTION:o?f.push(Wa(u,r,a)):f.push(Ur(u,r,a));break;case C.BOOKMARK:case C.HYPERLINK:u.nodeXml&&f.push(Ae(u.nodeXml));break;case C.CONTAINER_START:if(u.containerKind==="sdt")f.push(`<w:sdt>${u.propertiesXml}<w:sdtContent>`);else if(u.containerKind==="smartTag")f.push(`<w:smartTag ${u.propertiesXml}>`);else if(u.containerKind==="hyperlink"){let p=JSON.parse(u.propertiesXml),g=p.rId?` r:id="${p.rId}"`:"",d=p.anchor?` w:anchor="${p.anchor}"`:"";f.push(`<w:hyperlink${g}${d}>`)}break;case C.CONTAINER_END:u.containerKind==="sdt"?f.push("</w:sdtContent></w:sdt>"):u.containerKind==="smartTag"?f.push("</w:smartTag>"):u.containerKind==="hyperlink"&&f.push("</w:hyperlink>");break;default:Se("Unknown run kind:",u.kind)}return m(),s.join("")}function Da(e){if(typeof e=="string")return{author:G(),generateRedlines:!0,font:e};let t=e&&typeof e=="object"?e:{};return{author:typeof t.author=="string"&&t.author.trim()?t.author.trim():G(),generateRedlines:t.generateRedlines??!0,font:t.font??null}}function Ur(e,t,r={}){let n=he(t,e.startOffset,e.endOffset),a=r?.font??null,i=e.rPrXml?Ae(e.rPrXml):"";if(a&&(i=jt(i,a)),n.length===0)return xe(e.text,i);let o=[],s=0,l=e.text,c=e.startOffset;for(let f of n){let m=Math.max(0,f.start-c),u=Math.min(l.length,f.end-c);m>s&&o.push(xe(l.slice(s,m),i));let p=jr(i,f.format);o.push(xe(l.slice(m,u),p)),s=u}return s<l.length&&o.push(xe(l.slice(s),i)),o.join("")}function xe(e,t){return e?`<w:r>${t||""}<w:t xml:space="preserve">${ee(e)}</w:t></w:r>`:""}function za(e,t={}){let r=fe(t.author??G()),n=t.font??null,a=e.rPrXml?Ae(e.rPrXml):"";return n&&(a=jt(a,n)),`<w:del w:id="${r.id}" w:author="${ee(r.author)}" w:date="${r.date}"><w:r>${a}<w:delText xml:space="preserve">${ee(e.text)}</w:delText></w:r></w:del>`}function Wa(e,t,r={}){let n=fe(r.author??G()),a=r.font??null,i=he(t,e.startOffset,e.endOffset),o="",s=e.rPrXml?Ae(e.rPrXml):"";if(a&&(s=jt(s,a)),i.length===0)o=xe(e.text,s);else{let l=0,c=e.text,f=e.startOffset;for(let m of i){let u=Math.max(0,m.start-f),p=Math.min(c.length,m.end-f);u>l&&(o+=xe(c.slice(l,u),s));let g=jr(s,m.format);o+=xe(c.slice(u,p),g),l=p}l<c.length&&(o+=xe(c.slice(l),s))}return`<w:ins w:id="${n.id}" w:author="${ee(n.author)}" w:date="${n.date}">`+o+"</w:ins>"}function jt(e,t){if(!t)return e;let r="";return e&&(r=e.replace(/<\/?w:rPr[^>]*>/g,"")),r.includes("<w:rFonts")?r=r.replace(/<w:rFonts[^>]*\/>/,`<w:rFonts w:ascii="${t}" w:hAnsi="${t}"/>`):r=`<w:rFonts w:ascii="${t}" w:hAnsi="${t}"/>`+r,`<w:rPr>${r}</w:rPr>`}function jr(e,t){if(!t||Object.keys(t).length===0)return e;let r="";return e&&(r=e.replace(/<\/?w:rPr[^>]*>/g,"")),t.bold&&!r.includes("<w:b")&&(r="<w:b/>"+r),t.italic&&!r.includes("<w:i")&&(r="<w:i/>"+r),t.underline&&!r.includes("<w:u")&&(r='<w:u w:val="single"/>'+r),t.strikethrough&&!r.includes("<w:strike")&&(r="<w:strike/>"+r),`<w:rPr>${r}</w:rPr>`}function Ne(e,t={}){let r=Ha(t);return Wr(e,r)}function Ha(e){return typeof e=="boolean"?{includeNumbering:e}:!e||typeof e!="object"?{}:{includeNumbering:e.includeNumbering??!1,numberingXml:e.numberingXml??null,appendTrailingParagraph:e.appendTrailingParagraph??!0}}function Ae(e){return e?e.replace(Xa,""):""}var Je=class{constructor(){this.contextMap=new Map,this.nextNumId=1e3,this.customConfigs=[]}registerExistingNumId(t,r){this.contextMap.set(t,r)}getOrCreateNumId(t,r=null){let n=t.type||_.BULLET;if(r&&r.numId&&(r.type===n||r.type==="unknown"))return r.numId;if(this.contextMap.has(n))return this.contextMap.get(n);if(n===_.OUTLINE)return"3";if(n===_.DECIMAL)return"2";if(n===_.BULLET)return"1";if((r?parseInt(r.ilvl||"0"):0)===0&&n!==_.DECIMAL&&n!==_.BULLET){let i=`custom_${n}`;if(this.contextMap.has(i))return this.contextMap.get(i);let o=String(this.nextNumId++);return this.customConfigs.push({numId:o,levels:[{format:n,suffix:t.suffix||V.PERIOD}]}),this.contextMap.set(i,o),o}return"2"}detectNumberingFormat(t){let r=(t||"").trim();if(!r)return{format:_.BULLET,suffix:V.NONE,depth:0};if(/^[-*•]$/.test(r))return{format:_.BULLET,suffix:V.NONE,depth:0};let n=r.match(/^(\d+(?:\.\d+)+)\.?$/);if(n){let a=n[1].split(".").length-1;return{format:_.OUTLINE,suffix:V.PERIOD,depth:a}}return/^\([a-z]\)$/.test(r)?{format:_.LOWER_ALPHA,suffix:V.PAREN_BOTH,depth:0}:/^\([ivxlc]+\)$/i.test(r)?{format:r===r.toLowerCase()?_.LOWER_ROMAN:_.UPPER_ROMAN,suffix:V.PAREN_BOTH,depth:0}:/^\(\d+\)$/.test(r)?{format:_.DECIMAL,suffix:V.PAREN_BOTH,depth:0}:/^\d+\.$/.test(r)?{format:_.DECIMAL,suffix:V.PERIOD,depth:0}:/^[a-z]\.$/.test(r)?{format:_.LOWER_ALPHA,suffix:V.PERIOD,depth:0}:/^[A-Z]\.$/.test(r)?{format:_.UPPER_ALPHA,suffix:V.PERIOD,depth:0}:/^[ivxlc]+\.$/i.test(r)?{format:r===r.toLowerCase()?_.LOWER_ROMAN:_.UPPER_ROMAN,suffix:V.PERIOD,depth:0}:/^\d+/.test(r)?{format:_.DECIMAL,suffix:V.PERIOD,depth:0}:{format:_.BULLET,suffix:V.NONE,depth:0}}formatToOoxmlNumFmt(t){return{[_.DECIMAL]:"decimal",[_.LOWER_ALPHA]:"lowerLetter",[_.UPPER_ALPHA]:"upperLetter",[_.LOWER_ROMAN]:"lowerRoman",[_.UPPER_ROMAN]:"upperRoman",[_.BULLET]:"bullet",[_.OUTLINE]:"decimal"}[t]||"decimal"}suffixToOoxmlLevelText(t,r,n=0){if(t===_.BULLET)return"\u2022";let a=`%${n+1}`;if(t===_.OUTLINE)return Array(n+1).fill(0).map((i,o)=>`%${o+1}`).join(".")+".";switch(r){case V.PERIOD:return`${a}.`;case V.PAREN_RIGHT:return`${a})`;case V.PAREN_BOTH:return`(${a})`;default:return a}}buildListPPr(t,r,n={}){return`
49
+ <w:pPr>${n.includeListParagraphStyle===!0?`
50
+ <w:pStyle w:val="ListParagraph"/>`:""}
51
+ <w:numPr>
52
+ <w:ilvl w:val="${r}"/>
53
+ <w:numId w:val="${t}"/>
54
+ </w:numPr>
55
+ </w:pPr>
56
+ `}generateNumberingXml(t=[]){let r=[...this.customConfigs,...t],n=`
57
+ <w:abstractNum w:abstractNumId="0">
58
+ <w:multiLevelType w:val="hybridMultilevel"/>
59
+ ${[0,1,2,3,4,5,6,7,8].map(l=>`
60
+ <w:lvl w:ilvl="${l}">
61
+ <w:start w:val="1"/>
62
+ <w:numFmt w:val="${l%3===0?"bullet":l%3===1?"circle":"square"}"/>
63
+ <w:lvlText w:val="${l%3===0?"\u2022":l%3===1?"\u25CB":"\u25A0"}"/>
64
+ <w:lvlJc w:val="left"/>
65
+ <w:pPr><w:ind w:left="${720*(l+1)}" w:hanging="360"/></w:pPr>
66
+ </w:lvl>`).join("")}
67
+ </w:abstractNum>`,a=`
68
+ <w:abstractNum w:abstractNumId="1">
69
+ <w:multiLevelType w:val="multilevel"/>
70
+ <w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1."/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr></w:lvl>
71
+ <w:lvl w:ilvl="1"><w:start w:val="1"/><w:numFmt w:val="lowerLetter"/><w:lvlText w:val="(%2)"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="1440" w:hanging="360"/></w:pPr></w:lvl>
72
+ <w:lvl w:ilvl="2"><w:start w:val="1"/><w:numFmt w:val="lowerRoman"/><w:lvlText w:val="(%3)"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="2160" w:hanging="360"/></w:pPr></w:lvl>
73
+ <w:lvl w:ilvl="3"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="(%4)"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="2880" w:hanging="360"/></w:pPr></w:lvl>
74
+ <w:lvl w:ilvl="4"><w:start w:val="1"/><w:numFmt w:val="lowerLetter"/><w:lvlText w:val="%5."/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="3600" w:hanging="360"/></w:pPr></w:lvl>
75
+ </w:abstractNum>`,i=`
76
+ <w:abstractNum w:abstractNumId="2">
77
+ <w:multiLevelType w:val="multilevel"/>
78
+ <w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1."/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr></w:lvl>
79
+ <w:lvl w:ilvl="1"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1.%2"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="1440" w:hanging="360"/></w:pPr></w:lvl>
80
+ <w:lvl w:ilvl="2"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1.%2.%3"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="2160" w:hanging="360"/></w:pPr></w:lvl>
81
+ <w:lvl w:ilvl="3"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1.%2.%3.%4"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="2880" w:hanging="360"/></w:pPr></w:lvl>
82
+ <w:lvl w:ilvl="4"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1.%2.%3.%4.%5"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="3600" w:hanging="360"/></w:pPr></w:lvl>
83
+ </w:abstractNum>`,o="",s="";return r.forEach((l,c)=>{let f=10+c;o+=`
84
+ <w:abstractNum w:abstractNumId="${f}">
85
+ <w:multiLevelType w:val="multilevel"/>
86
+ ${l.levels.map((m,u)=>`
87
+ <w:lvl w:ilvl="${u}">
88
+ <w:start w:val="1"/>
89
+ <w:numFmt w:val="${this.formatToOoxmlNumFmt(m.format)}"/>
90
+ <w:lvlText w:val="${this.suffixToOoxmlLevelText(m.format,m.suffix,u)}"/>
91
+ <w:lvlJc w:val="left"/>
92
+ <w:pPr><w:ind w:left="${720*(u+1)}" w:hanging="360"/></w:pPr>
93
+ </w:lvl>`).join("")}
94
+ </w:abstractNum>`,s+=`
95
+ <w:num w:numId="${l.numId}">
96
+ <w:abstractNumId w:val="${f}"/>
97
+ </w:num>`}),`
98
+ <w:numbering xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
99
+ ${n}
100
+ ${a}
101
+ ${i}
102
+ ${o}
103
+ <w:num w:numId="1">
104
+ <w:abstractNumId w:val="0"/>
105
+ </w:num>
106
+ <w:num w:numId="2">
107
+ <w:abstractNumId w:val="1"/>
108
+ </w:num>
109
+ <w:num w:numId="3">
110
+ <w:abstractNumId w:val="2"/>
111
+ </w:num>
112
+ ${s}
113
+ </w:numbering>`}};function ke(e,t={}){let{generateRedlines:r=!1,author:n="AI"}=t,a=ae(),i=r?be():null,o=e.headers?.length||e.rows?.[0]?.length||1,s=`
114
+ <w:tblPr>
115
+ <w:tblW w:w="5000" w:type="pct"/>
116
+ <w:tblBorders>
117
+ <w:top w:val="single" w:sz="4" w:space="0" w:color="auto"/>
118
+ <w:left w:val="single" w:sz="4" w:space="0" w:color="auto"/>
119
+ <w:bottom w:val="single" w:sz="4" w:space="0" w:color="auto"/>
120
+ <w:right w:val="single" w:sz="4" w:space="0" w:color="auto"/>
121
+ <w:insideH w:val="single" w:sz="4" w:space="0" w:color="auto"/>
122
+ <w:insideV w:val="single" w:sz="4" w:space="0" w:color="auto"/>
123
+ </w:tblBorders>
124
+ <w:tblLook w:val="04A0" w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="1"/>
125
+ </w:tblPr>
126
+ `.trim(),c=`<w:tblGrid>${Array(o).fill("<w:gridCol/>").join("")}</w:tblGrid>`,f=e.hasHeader?[e.headers,...e.rows]:e.rows,m="";for(let p=0;p<f.length;p++){let g=e.hasHeader&&p===0,d=f[p]||[],w="";for(let x=0;x<o;x++){let v=d[x]||"",{cleanText:T,formatHints:N}=q(v),E=[{kind:r?C.INSERTION:C.TEXT,text:T,rPrXml:g?"<w:rPr><w:b/></w:rPr>":"",author:n,startOffset:0,endOffset:T.length}],b=ie(E,null,N,{author:n,generateRedlines:r});w+=`<w:tc><w:tcPr><w:tcW w:w="0" w:type="auto"/></w:tcPr>${b}</w:tc>`}m+=`<w:tr><w:trPr/>${w}</w:tr>`}let u=`<w:tbl>${s}${c}${m}</w:tbl>`;return r&&i&&(u=`<w:ins w:id="${i}" w:author="${ee(n)}" w:date="${a}">${u}</w:ins>`),u}function Gr(e,t){let r=[],{headers:n,rows:a,hasHeader:i}=t,o=i?[n,...a]:a,s=Math.max(e.rowCount,o.length);for(let l=0;l<s;l++){if(l>=e.rowCount&&o[l]){r.push({type:"row_insert",gridRow:l,cells:o[l]});continue}if(l<e.rowCount&&!o[l]){r.push({type:"row_delete",gridRow:l});continue}let c=o[l];for(let f=0;f<e.colCount;f++){let m=e.grid[l]?.[f],u=c?.[f];m&&(m.isMergeContinuation||f>m.gridCol||u!==void 0&&m.getText()!==u&&r.push({type:"cell_modify",gridRow:l,gridCol:f,originalCell:m,newText:u}))}}return r}function Kr(e,t,r){let{generateRedlines:n,author:a}=r,i=Ua(t),o="";for(let l=0;l<e.rowCount;l++){let c=i.rowDeleteByRow.get(l)||null;if(c&&!n)continue;let f="",m=0;for(;m<e.colCount;){let p=e.grid[l][m];if(!p){m++;continue}if(p.isMergeContinuation){m++;continue}let g=i.cellModifyByCoordinate.get(`${l}:${m}`)||null,d;g?d=ja(p,g.newText,r):d=Ga(p.blocks),f+=Ka(p,d,r),m+=p.colSpan}let u=e.trPrList[l]||"<w:trPr/>";if(c&&n){let p=fe(a),g=`<w:del w:id="${p.id}" w:author="${ee(p.author)}" w:date="${p.date}"/>`;u.includes("</w:trPr>")?u=u.replace("</w:trPr>",`${g}</w:trPr>`):u=`<w:trPr>${g}</w:trPr>`}o+=`<w:tr>${u}${f}</w:tr>`}let s=i.rowInsertOperations;for(let l of s){let c="",f=n?fe(a):null;for(let u of l.cells){let{cleanText:p,formatHints:g}=q(u),d=[{kind:n?C.INSERTION:C.TEXT,text:p,rPrXml:"",author:a,startOffset:0,endOffset:p.length}],w=ie(d,null,g,{author:a,generateRedlines:n});c+=`<w:tc><w:tcPr><w:tcW w:w="0" w:type="auto"/></w:tcPr>${w}</w:tc>`}let m="<w:trPr/>";n&&(m=`<w:trPr><w:ins w:id="${f.id}" w:author="${ee(f.author)}" w:date="${f.date}"/></w:trPr>`),o+=`<w:tr>${m}${c}</w:tr>`}return`
127
+ <w:tbl>
128
+ ${e.tblPrXml}
129
+ ${e.tblGridXml}
130
+ ${o}
131
+ </w:tbl>
132
+ `}function Ua(e){let t=new Map,r=new Map,n=[];for(let a of e)a.type==="row_delete"?t.set(a.gridRow,a):a.type==="cell_modify"?r.set(`${a.gridRow}:${a.gridCol}`,a):a.type==="row_insert"&&n.push(a);return n.sort((a,i)=>a.gridRow-i.gridRow),{rowDeleteByRow:t,cellModifyByCoordinate:r,rowInsertOperations:n}}function ja(e,t,r){let{generateRedlines:n,author:a}=r,{cleanText:i,formatHints:o}=q(t),s=e.getText(),l=dt(s,i),c=e.blocks[0]||{runModel:[],pPr:null},f=ht(c.runModel,l),m=wt(f,l,{generateRedlines:n,author:a,formatHints:o});return ie(m,c.pPr,o,{author:a,generateRedlines:n})}function Ga(e){return e.map(t=>ie(t.runModel,t.pPr,[],{})).join("")}function Ka(e,t,r){let n=e.tcPrXml;return e.colSpan>1&&!n.includes("gridSpan")?n=n.replace("</w:tcPr>",`<w:gridSpan w:val="${e.colSpan}"/></w:tcPr>`):e.colSpan>1&&n==="<w:tcPr/>"&&(n=`<w:tcPr><w:gridSpan w:val="${e.colSpan}"/></w:tcPr>`),e.rowSpan>1&&e.isMergeOrigin&&!n.includes("vMerge")?n=n.replace("</w:tcPr>",'<w:vMerge w:val="restart"/></w:tcPr>'):e.rowSpan>1&&e.isMergeOrigin&&n==="<w:tcPr/>"&&(n='<w:tcPr><w:vMerge w:val="restart"/></w:tcPr>'),`<w:tc>${n}${t}</w:tc>`}function oe(e){let t=e.split(`
133
+ `).map(o=>o.trim()).filter(o=>o.startsWith("|"));if(t.length===0)return{headers:[],rows:[],hasHeader:!1};let r=o=>{let s=o.replace(/\s+/g,"");return/^\|:?-{3,}:?(\|:?-{3,}:?)+\|?$/.test(s)},n=t.some(r),i=t.filter(o=>!r(o)).map(o=>o.split("|").slice(1,-1).map(s=>s.trim()));return n?{headers:i[0]||[],rows:i.slice(1),hasHeader:!0}:{headers:[],rows:i,hasHeader:!1}}async function Vr(e){let{cleanText:t,numberingContext:r,originalRunModel:n=[],originalText:a="",generateRedlines:i=!0,author:o="AI",font:s=null,numberingService:l}=e,c=Za(t),f=Va(c),m=f.map(N=>N.raw),u=[],p=[];if(i){if(n&&n.length>0)p=n.filter(N=>N.kind==="text"||N.kind==="run").map(N=>({...N,kind:"deletion",author:o}));else if(a&&a.trim().length>0){let N=a.trim();p=[{kind:"deletion",text:N,author:o,startOffset:0,endOffset:N.length}]}}let g=Gt(m);A(`[ListGen] Detected indentation step: ${g} spaces/chars`);let d=f.find(N=>N.marker)?.marker||"",{format:w}=l.detectNumberingFormat(d);A(`[ListGen] Detected primary marker: "${d}", format: ${w}`);for(let N=0;N<f.length;N++){let E=Ya(f,N);if(E){let P=oe(E.tableText);if(P.headers.length>0||P.rows.length>0){i&&u.length===0&&p.length>0&&u.push(ie(p,null,[],{author:o,generateRedlines:i,font:s})),u.push(ke(P,{generateRedlines:i,author:o})),N=E.endIndex;continue}}let b=f[N],S=Ja(b,N,g,r,l,i,o,s,p);u.push(S.ooxml)}let h=l.generateNumberingXml(),T=u.join("")+"<w:p><w:pPr></w:pPr></w:p>";return A(`[ListGen] \u2705 Generated OOXML for ${u.length} list items, total length: ${T.length}`),A(`[ListGen] First 200 chars: ${T.substring(0,200)}...`),{ooxml:T,isValid:!0,warnings:["Paragraph expanded to list fragment"],type:"fragment",includeNumbering:!0,numberingXml:h}}function Gt(e){let t=e.map(n=>n.match(/^(\s*)/)[0].length).filter(n=>n>0).sort((n,a)=>n-a);if(t.length===0)return 2;let r=t[0];for(let n=1;n<t.length;n++){let a=t[n]-t[n-1];a>0&&a<r&&(r=a)}return r||2}function Va(e){return e.split(`
134
+ `).filter(t=>t.trim().length>0).map(t=>{let r=ue(t),n=t.match(/^\s*(#{1,9})\s+(.*)/);return{raw:t,marker:r?r[2].trim():"",headerMatch:n,indentSize:t.match(/^(\s*)/)?.[1].length||0,isTableLine:/^\s*\|/.test(t),isTableSeparator:/^\s*\|?[\s:-]*-[-\s|:]*\|?\s*$/.test(t)}})}function Za(e){let t=String(e||"").split(`
135
+ `),r=t.map((o,s)=>({line:o,index:s})).filter(o=>o.line.trim().length>0);if(r.length<2)return e;let n=[],a=0;for(let{line:o,index:s}of r){let l=ue(o);if(!l)return e;let c=we(o),f=ue(c);if(!f)return e;let m=(l[2]||"").trim(),u=(f[2]||"").trim();if(!m||!u||m===u)return e;let g=`${l[1]||""}${c.trimStart()}`;n.push({index:s,rewritten:g}),a++}if(a<2)return e;let i=t.slice();for(let o of n)i[o.index]=o.rewritten;return A(`[ListGen] Normalized ${a} composite list markers (e.g., "- A." -> "A.").`),i.join(`
136
+ `)}function Ya(e,t){let r=e[t],n=e[t+1];if(!r?.isTableLine||!n?.isTableLine||!n?.isTableSeparator)return null;let a=[],i=t;for(;i<e.length&&e[i].isTableLine;)a.push(e[i].raw),i++;return{tableText:a.join(`
137
+ `),endIndex:i-1}}function Ja(e,t,r,n,a,i,o,s,l){let c="",f="";if(e.headerMatch){let g=Math.min(e.headerMatch[1].length,9),d=Math.min(g-1,8),w=[32,28,26,24,22,20,20,20,20],h=w[g-1]||w[w.length-1];f=e.headerMatch[2].trim(),c=`<w:pPr><w:pStyle w:val="Heading${g}"/><w:outlineLvl w:val="${d}"/><w:rPr><w:b/><w:sz w:val="${h}"/><w:szCs w:val="${h}"/></w:rPr></w:pPr>`}else if(e.marker){let g=a.detectNumberingFormat(e.marker),d=r>0?Math.floor(e.indentSize/r):0,w=n?.ilvl||0,h=g.format==="outline"?Math.min(8,g.depth):Math.min(8,d+w);f=we(e.raw);let x=a.getOrCreateNumId({type:g.format},n);c=a.buildListPPr(x,h)}else f=e.raw;let{cleanText:m,formatHints:u}=q(f),p=[];return t===0&&l.length>0&&p.push(...l),p.push({kind:i?"insertion":"run",text:m,author:o,startOffset:0,endOffset:m.length}),{ooxml:ie(p,c,u,{author:o,generateRedlines:i,font:s})}}var qa=new Set(["officeonline","officeweb","web"]);function Qa(e){return e?qa.has(String(e).toLowerCase()):!1}function ei(){return typeof process<"u"&&process?.env?.NODE_ENV==="production"}function ti(){return new Promise(e=>setTimeout(e,0))}var Ce=class{constructor(t={}){this.generateRedlines=t.generateRedlines??!0,this.author=t.author??"AI",this.validateOutput=t.validateOutput??!0,this.validationMode=t.validationMode??"auto",this.numberingService=t.numberingService||new Je,this.font=t.font||null,this.platform=t.platform??Bt(),this.isWebPlatform=t.isWebPlatform??Qa(this.platform),this.enableEventLoopYielding=t.enableEventLoopYielding??this.isWebPlatform,this.yieldRunThreshold=t.yieldRunThreshold??50,this.yieldCharThreshold=t.yieldCharThreshold??5e3,this.disableSemanticCleanupOverChars=t.disableSemanticCleanupOverChars??(this.isWebPlatform?8e3:Number.POSITIVE_INFINITY)}async execute(t,r,n={}){let a=[];try{let i=n.xmlDoc||B().parseFromString(t,"application/xml"),o=D(i,"*","p"),{runModel:s,acceptedText:l,pPr:c}=gt(t,{xmlDoc:i}),f=o?Wt(o):null;A(`[Reconcile] Ingested ${s.length} runs, ${l.length} chars, numbering:`,f),await this.maybeYield(s.length,Math.max(l.length,r?.length||0));let{cleanText:m,formatHints:u}=q(r);A(`[Reconcile] Preprocessed: ${u.length} format hints`),await this.maybeYield(s.length,Math.max(l.length,m.length));let p=yr(m),g=pt(m),d=p||g;if(!p&&g&&A("[Reconcile] List-target detected via loose marker parsing; bypassing no-op short-circuit for structural conversion."),l===m&&u.length===0&&!d)return A("[Reconcile] No changes detected"),{ooxml:t,isValid:!0,warnings:["No changes detected"]};let w=Math.max(l.length,m.length)<this.disableSemanticCleanupOverChars,h=dt(l,m,{cleanupSemantic:w});w||A("[Reconcile] Skipping semantic diff cleanup for large web payload"),await this.maybeYield(s.length,Math.max(l.length,m.length));let x=s.filter(E=>E.kind===C.PARAGRAPH_START).length;if(A(`[Reconcile] isTargetList: ${d}, paragraphCount: ${x}`),d)return A("[Reconcile] \u{1F3AF} ENTERING LIST GENERATION PATH"),A(`[Reconcile] cleanText preview: ${m.substring(0,100)}...`),A(`[Reconcile] acceptedText preview: ${l.substring(0,100)}...`),this.executeListGeneration(m,f,s);A(`[Reconcile] Computed ${h.length} diff operations`);let v=ht(s,h);A(`[Reconcile] Split into ${v.length} runs`);let T=wt(v,h,{generateRedlines:this.generateRedlines,author:this.author,formatHints:u,numberingService:this.numberingService});A(`[Reconcile] Patched model has ${T.length} runs`),await this.maybeYield(T.length,Math.max(l.length,m.length));let N=ie(T,c,u,{author:this.author,generateRedlines:this.generateRedlines});if(this.shouldRunValidation()){let E=this.validateBasic(N);E.isValid||a.push(...E.errors)}return{ooxml:N,isValid:a.length===0,warnings:a}}catch(i){return K("[Reconcile] Pipeline error:",i),{ooxml:t,isValid:!1,warnings:[`Pipeline error: ${i.message}`]}}}validateBasic(t){let r=[];try{let n=`<root xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">${t}</root>`,i=B().parseFromString(n,"application/xml"),o=U(i);o&&r.push("Generated OOXML is not well-formed XML: "+o.textContent.substring(0,100)),t.includes("<w:p")||r.push("Generated OOXML missing paragraph element")}catch(n){r.push(`Validation error: ${n.message}`)}return{isValid:r.length===0,errors:r}}shouldRunValidation(){return this.validateOutput?this.validationMode==="always"?!0:this.validationMode==="never"?!1:!(this.isWebPlatform&&ei()):!1}async maybeYield(t,r){this.enableEventLoopYielding&&(t<=this.yieldRunThreshold&&r<=this.yieldCharThreshold||await ti())}wrapForInsertion(t,r={}){return Ne(t,r)}async executeListGeneration(t,r,n,a=""){return Vr({cleanText:t,numberingContext:r,originalRunModel:n,originalText:a,generateRedlines:this.generateRedlines,author:this.author,font:this.font,numberingService:this.numberingService})}detectIndentationStep(t){return Gt(t)}executeTableGeneration(t){let r=oe(t);return r.rows.length===0&&r.headers.length===0?{ooxml:"",isValid:!1,warnings:["Could not parse Markdown table"]}:{ooxml:ke(r,{generateRedlines:this.generateRedlines,author:this.author}),isValid:!0,warnings:[],includeNumbering:!1}}};var qe=["w:rStyle","w:rFonts","w:b","w:bCs","w:i","w:iCs","w:caps","w:smallCaps","w:strike","w:dstrike","w:outline","w:shadow","w:emboss","w:imprint","w:noProof","w:snapToGrid","w:vanish","w:webHidden","w:color","w:spacing","w:w","w:kern","w:position","w:sz","w:szCs","w:highlight","w:u","w:effect","w:bdr","w:shd","w:fitText","w:vertAlign","w:rtl","w:cs","w:em","w:lang","w:eastAsianLayout","w:specVanish","w:oMath"];function $e(e,t){let r=qe.indexOf(t.nodeName),n=r===-1?999:r,a=!1;for(let i of Array.from(e.childNodes)){if(i.nodeType!==1)continue;let o=qe.indexOf(i.nodeName);if((o===-1?999:o)>n){e.insertBefore(t,i),a=!0;break}}a||e.appendChild(t)}function ri(e,t,r,n){if(!t||!r)return;let a=!!r.bold,i=!!r.italic,o=!!r.underline,s=!!r.strikethrough,l=new Set;if(a&&(l.add("w:b"),l.add("w:bCs")),i&&(l.add("w:i"),l.add("w:iCs")),o&&l.add("w:u"),s&&l.add("w:strike"),l.size>0){let c=[];for(let f of Array.from(t.childNodes))l.has(f.nodeName)&&c.push(f);for(let f of c)t.removeChild(f)}if(a){let c=e.createElement("w:b");c.setAttribute("w:val",n==="add"?"1":"0"),$e(t,c);let f=e.createElement("w:bCs");f.setAttribute("w:val",n==="add"?"1":"0"),$e(t,f)}if(i){let c=e.createElement("w:i");c.setAttribute("w:val",n==="add"?"1":"0"),$e(t,c);let f=e.createElement("w:iCs");f.setAttribute("w:val",n==="add"?"1":"0"),$e(t,f)}if(o){let c=e.createElement("w:u");c.setAttribute("w:val",n==="add"?"single":"none"),$e(t,c)}if(s){let c=e.createElement("w:strike");c.setAttribute("w:val",n==="add"?"1":"0"),$e(t,c)}}function Zr(e,t,r){ri(e,t,r,"remove")}function Qe(e){let t={bold:!1,italic:!1,underline:!1,strikethrough:!1,hasFormatting:!1};if(!e)return t;for(let r of Array.from(e.childNodes))if(r.nodeName==="w:b"&&(t.bold=bt(r,!1)),r.nodeName==="w:i"&&(t.italic=bt(r,!1)),r.nodeName==="w:u"&&(t.underline=bt(r,!0)),r.nodeName==="w:strike"&&(t.strikethrough=bt(r,!1)),r.nodeName==="w:rStyle"){let n=r.getAttribute("w:val");if(n){let a=n.toLowerCase();(a.includes("bold")||a.includes("strong"))&&(t.bold=!0),(a.includes("italic")||a.includes("emphasis"))&&(t.italic=!0),a.includes("underline")&&(t.underline=!0)}}return t.hasFormatting=t.bold||t.italic||t.underline||t.strikethrough,t}function bt(e,t){let n=(e.getAttribute("w:val")||e.getAttribute("val")||"").toLowerCase();return n?t?n!=="none"&&n!=="0"&&n!=="false"&&n!=="off":n!=="0"&&n!=="false"&&n!=="off":!0}var Yr="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function ce(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===Yr&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function ni(e){return!e||e.nodeType!==1||e.namespaceURI!==Yr?!1:e.localName==="del"||e.localName==="moveFrom"}function Jr(e){let t=[],r=Array.from(e?.childNodes||[]).reverse();for(;r.length>0;){let n=r.pop();if(!n||n.nodeType!==1||ni(n))continue;if(ce(n,"r")){t.push(n);continue}let a=Array.from(n.childNodes||[]);for(let i=a.length-1;i>=0;i-=1)r.push(a[i])}return t}function me(e){let t=new Set(["comment","footnote","endnote"]);return z(e,"*","p").filter(n=>{let a=n.parentNode;for(;a&&a.nodeName;){let i=String(a.localName||"").toLowerCase();if(t.has(i))return!1;a=a.parentNode}return!0})}function qr(e){let t=[],r=0;for(let n=0;n<e.length;n++){let a=e[n],i=Jr(a);for(let o of i){let s=M(o,"w:rPr");Array.from(o.childNodes||[]).forEach(l=>{if(ce(l,"t")){let c=l.textContent||"";c.length>0&&(t.push({charStart:r,charEnd:r+c.length,textElement:l,runElement:o,paragraph:a,container:o.parentNode,rPr:s}),r+=c.length)}else(ce(l,"br")||ce(l,"cr")||ce(l,"tab")||ce(l,"noBreakHyphen"))&&(t.push({charStart:r,charEnd:r+1,textElement:l,runElement:o,paragraph:a,container:o.parentNode,rPr:s}),r+=1)})}r=Ie(r,n,e.length)}return{textSpans:t,charOffset:r}}function ai(e,t,r,n,a,i=null){let o=null;for(let c of Array.from(e.childNodes))if(ce(c,"rPr")){o=c;break}let s=Qe(o);i&&(i.bold&&!s.bold&&(s.bold=!0),i.italic&&!s.italic&&(s.italic=!0),i.underline&&!s.underline&&(s.underline=!0),i.strikethrough&&!s.strikethrough&&(s.strikethrough=!0)),s.hasFormatting=s.bold||s.italic||s.underline||s.strikethrough;let l=r;for(let c of Array.from(e.childNodes))if(ce(c,"t")){let f=c.textContent||"";if(f.length>0){let m=l,u=l+f.length;n.push({charStart:m,charEnd:u,textElement:c,runElement:e,paragraph:t,rPr:o,format:{...s}}),s.hasFormatting&&a.push({start:m,end:u,format:{...s},run:e,rPr:o}),l=u}}return l}function Qr(e){let t=[],r=[],n=0,a=me(e);for(let i=0;i<a.length;i++){let o=a[i],s=null;for(let f of Array.from(o.childNodes))if(ce(f,"pPr")){for(let m of Array.from(f.childNodes))if(ce(m,"rPr")){s=m;break}break}let l=Qe(s);l.hasFormatting&&A(`[OxmlEngine] Found paragraph-level formatting: ${JSON.stringify(l)}`);let c=Jr(o);for(let f of c)n=ai(f,o,n,r,t,l);n=Ie(n,i,a.length)}return A(`[OxmlEngine] Extracted ${r.length} text spans, ${t.length} format hints`),{existingFormatHints:t,textSpans:r,paragraphs:a}}function ve(e,t,r,n){let a=e.createElement(t==="ins"?"w:ins":"w:del"),i=fe(n);return a.setAttribute("w:id",String(i.id)),a.setAttribute("w:author",i.author),a.setAttribute("w:date",i.date),r&&a.appendChild(r),a}function se(e,t,r,n){let a=e.createElement("w:r");r&&a.appendChild(r.cloneNode(!0));let i=e.createElement(n?"w:delText":"w:t");return i.setAttribute("xml:space","preserve"),i.textContent=t,a.appendChild(i),a}function xt(e,t,r,n,a,i,o){if(!t)return[];let s=new Set([0,t.length]);for(let f of n){let m=Math.max(0,f.start-a),u=Math.min(t.length,f.end-a);m>=0&&m<t.length&&s.add(m),u>0&&u<=t.length&&s.add(u)}let l=Array.from(s).sort((f,m)=>f-m),c=[];for(let f=0;f<l.length-1;f++){let m=l[f],u=l[f+1],p=t.slice(m,u);if(!p)continue;let g=a+m,d=a+u,w=n.filter(v=>v.start<=g&&v.end>=d),h={};w.forEach(v=>{v.format&&Object.assign(h,v.format)});let x=Fe(e,r,h,i,o);c.push(Kt(e,p,x,!1))}return c}function Kt(e,t,r,n){let a=e.createElement("w:r");r&&a.appendChild(r);let i=e.createElement(n?"w:delText":"w:t");return i.setAttribute("xml:space","preserve"),i.textContent=t,a.appendChild(i),a}function Fe(e,t,r,n,a){let i=e.createElement("w:rPr");t&&Array.from(t.childNodes).forEach(l=>{["w:b","w:bCs","w:i","w:iCs","w:u","w:strike","w:rPrChange"].includes(l.nodeName)||i.appendChild(l.cloneNode(!0))});let o=r||{bold:!1,italic:!1,underline:!1,strikethrough:!1};n&&a&&ii(e,i,n,t);let s=(l,c,f=null,m="0")=>{let u=e.createElement(l);c?f&&u.setAttribute("w:val",f):m&&u.setAttribute("w:val",m);let p=qe.indexOf(l),g=p===-1?999:p,d=!1;for(let w of Array.from(i.childNodes)){if(w.nodeType!==1)continue;let h=qe.indexOf(w.nodeName);if((h===-1?999:h)>g){i.insertBefore(u,w),d=!0;break}}d||i.appendChild(u)};return s("w:b",!!o.bold,"1","0"),s("w:bCs",!!o.bold,"1","0"),s("w:i",!!o.italic,"1","0"),s("w:iCs",!!o.italic,"1","0"),s("w:u",!!o.underline,"single","none"),s("w:strike",!!o.strikethrough,"1","0"),i}function Vt(e,t,r,n,a){let i=e.createElement("w:rPrChange");i.setAttribute("w:id",String(fe(r).id)),i.setAttribute("w:author",r),i.setAttribute("w:date",n);let o=e.createElement("w:rPr"),s=a||t;Array.from(s.childNodes).forEach(c=>{c.nodeName!=="w:rPrChange"&&o.appendChild(c.cloneNode(!0))}),i.appendChild(o);let l=M(t,"w:rPrChange");return l&&t.removeChild(l),t.appendChild(i),i}function ii(e,t,r,n){Vt(e,t,r,ae(),n||t)}var oi="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function Xe(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===oi&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function Nt(e,t,r){let n=new Map;for(let o of r)!o||!o.paragraph||(n.has(o.paragraph)||n.set(o.paragraph,[]),n.get(o.paragraph).push(o));let a=[],i=0;return t.forEach((o,s)=>{let l=(n.get(o)||[]).slice().sort((u,p)=>u.charStart-p.charStart),c=si(l),f=Zt(c),m=f.trim();a.push({paragraph:o,spans:l,text:c,normalizedText:f,normalizedTrim:m,startOffset:i}),i+=f.length,i=Ie(i,s,t.length)}),a}function en(e,t){if(!t)return null;let r=Zt(t),n=r.trim();if(!n)return null;for(let a of e)if(a.normalizedText===r)return a;for(let a of e)if(a.normalizedTrim===n)return a;return null}function tn(e,t){let r=Zt(t),n=r.trim(),a=null,i=0;for(let o of e)if(o.normalizedText===r)return a=o,{targetInfo:a,matchOffset:i};if(n.length>0){for(let o of e)if(o.normalizedTrim===n)return a=o,{targetInfo:a,matchOffset:i}}if(n.length>0){let s=e.map(l=>l.normalizedText).join(`
138
+ `).indexOf(n);if(s!==-1)for(let l of e){let c=l.startOffset,f=l.normalizedText.length;if(s>=c&&s<=c+f){a=l,i=s-c;break}}}if(!a&&e.length===1&&r.length>0){let o=e[0],s=o.normalizedTrim||"";if(s.length>0){let l=r.indexOf(s);l>=0&&(a=o,i=-l)}}return{targetInfo:a,matchOffset:i}}function rn(e){let t=e;for(;t;){if(Xe(t,"p"))return t;t=t.parentNode}return null}function si(e){if(!e||e.length===0)return"";let t="";for(let r of e){if(!r||!r.textElement)continue;let n=r.textElement;Xe(n,"t")?t+=r.textElement.textContent||"":Xe(n,"tab")?t+=" ":Xe(n,"br")||Xe(n,"cr")?t+=`
139
+ `:Xe(n,"noBreakHyphen")&&(t+="\u2011")}return t}function Zt(e){return e?e.replace(/\r/g,`
140
+ `).replace(/\u00a0/g," "):""}function nn(e,t,r){let n=Array.from(new Set(r)).sort((s,l)=>s-l);if(n.length===0||t.length===0)return[...t];let a=[...t].sort((s,l)=>s.charStart-l.charStart||s.charEnd-l.charEnd),i=[],o=0;for(let s of a){for(;o<n.length&&n[o]<=s.charStart;)o++;let l=s;for(;o<n.length&&n[o]<l.charEnd;){let c=n[o],f=li(e,l,c);if(!f){o++;continue}i.push(f[0]),l=f[1],o++}i.push(l)}return i}function li(e,t,r){let n=t.runElement,a=n.parentNode;if(!a)return null;let i=t.textElement.textContent||"",o=r-t.charStart,s=i.substring(0,o),l=i.substring(o);if(s.length===0||l.length===0)return null;let c=se(e,s,t.rPr,!1),f=se(e,l,t.rPr,!1);a.insertBefore(c,n),a.insertBefore(f,n),a.removeChild(n);let m=c.getElementsByTagName("w:t")[0],u=f.getElementsByTagName("w:t")[0];return[{...t,charEnd:r,textElement:m,runElement:c},{...t,charStart:r,textElement:u,runElement:f}]}var ci="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function ui(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===ci&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function fi(e){return Array.isArray(e)?{textSpans:e,paragraphs:null,paragraphInfos:null}:!e||typeof e!="object"?{textSpans:null,paragraphs:null,paragraphInfos:null}:{textSpans:Array.isArray(e.textSpans)?e.textSpans:null,paragraphs:Array.isArray(e.paragraphs)?e.paragraphs:null,paragraphInfos:Array.isArray(e.paragraphInfos)?e.paragraphInfos:null}}function an(e,t,r,n,a,i=!0){let o=!1,s=new Set,l=ae();A(`[OxmlEngine] Surgical format removal: ${r.length} hints to process (using w:rPrChange)`);for(let c of r){let f=c.run;if(s.has(f)||(s.add(f),!f.parentNode))continue;A("[OxmlEngine] Processing run for surgical format removal, format:",c.format);let m=M(f,"w:rPr");m||(m=e.createElement("w:rPr"),f.insertBefore(m,f.firstChild)),i&&Vt(e,m,a||G(),l),Zr(e,m,c.format),o=!0}return o?(A("[OxmlEngine] Surgical format removal completed successfully (Pure Format Mode)"),{oxml:n.serializeToString(e),hasChanges:!0}):(A("[OxmlEngine] No format changes were applied"),{oxml:n.serializeToString(e),hasChanges:!1})}function mi(e,t,r,n,a,i=!0){let o=!1,s=new Set;if(!t||t.length===0)return{oxml:n.serializeToString(e),hasChanges:!1};let l=[];for(let u of r)l.push(u.start,u.end);let f=nn(e,t,l).slice().sort((u,p)=>u.charStart-p.charStart||u.charEnd-p.charEnd),m=pi(r);for(let u of f){if(!u||!u.textElement||!ui(u.textElement,"t"))continue;let p=m(u.charStart,u.charEnd);if(p.length===0)continue;let g=$t(...p.map(k=>k.format)),d={bold:!!g.bold,italic:!!g.italic,underline:!!g.underline,strikethrough:!!g.strikethrough},w=u.format||Qe(u.rPr),h={bold:!!w.bold,italic:!!w.italic,underline:!!w.underline,strikethrough:!!w.strikethrough};if(!["bold","italic","underline","strikethrough"].some(k=>d[k]!==h[k])||s.has(u.runElement)||(s.add(u.runElement),!(u.textElement.textContent||""))||!u.runElement.parentNode)continue;let E=u.runElement,b=M(E,"w:rPr"),S=Fe(e,b,d,a||G(),i),P=b;if(!P)E.insertBefore(S,E.firstChild);else{for(;P.firstChild;)P.removeChild(P.firstChild);Array.from(S.childNodes).forEach(k=>P.appendChild(k))}o=!0}return{oxml:n.serializeToString(e),hasChanges:o}}function on(e,t,r,n,a,i=!0,o=null){let s=fi(o),l=s.paragraphs||me(e),c=s.textSpans||[];if(s.textSpans||({textSpans:c}=qr(l)),!c||c.length===0)return Se("[OxmlEngine] No spans available for surgical format-only change; requesting caller fallback strategy"),{hasChanges:!0,useNativeApi:!0,formatHints:r,originalText:t};if(!r||r.length===0)return{oxml:n.serializeToString(e),hasChanges:!1};let f=s.paragraphInfos||Nt(e,l,c),{targetInfo:m,matchOffset:u}=tn(f,t);if(!m||!m.spans||m.spans.length===0)return Se("[OxmlEngine] Unable to pinpoint target paragraph for surgical format-only change; requesting caller fallback strategy"),{hasChanges:!0,useNativeApi:!0,formatHints:r,originalText:t};let p=m.spans[0].charStart,g=m.spans.map(w=>({...w,charStart:w.charStart-p,charEnd:w.charEnd-p})),d=r.map(w=>({...w,start:w.start+u,end:w.end+u}));return mi(e,g,d,n,a,i)}function pi(e){let t=(e||[]).slice().sort((a,i)=>a.start-i.start||a.end-i.end),r=[],n=0;return(a,i)=>{for(;n<t.length&&t[n].start<i;)r.push(t[n]),n++;for(let o=r.length-1;o>=0;o--)r[o].end<=a&&r.splice(o,1);return r.filter(o=>o.start<i&&o.end>a)}}var gi="http://schemas.microsoft.com/office/word/2010/wordml";function sn(e,t,r={}){let{targetParagraphId:n=null}=r,a=Y(e,"w:tbl");if(a.length===0)return{hasTableWrapper:!1,isTableCellParagraph:!1,paragraphs:[],paragraph:null,tableElement:null};let o=me(e).filter(l=>{let c=l.parentNode;for(;c;){if(c.nodeName==="w:tc")return!0;c=c.parentNode}return!1});A(`[OxmlEngine] Table wrapper detected: ${a.length} tables, ${o.length} paragraphs in cells`);let s=null;if(n){let l=String(n).toUpperCase();s=o.find(c=>{let f=hi(c);return f&&f.toUpperCase()===l})||null,s?A(`[OxmlEngine] Found target paragraph by paraId: "${n}"`):A(`[OxmlEngine] paraId "${n}" not found in wrapper, falling back to text match`)}if(t&&t.trim()){let l=t.trim();if(!s)for(let c of o){let f=Y(c,"w:t"),m="";for(let u of f)m+=u.textContent||"";if(m.trim()===l){s=c,A(`[OxmlEngine] Found target paragraph by text match: "${l.substring(0,30)}..."`);break}}}return{hasTableWrapper:!0,isTableCellParagraph:o.length>0,targetParagraph:s,paragraphs:o,paragraph:s||o[0]||null,tableElement:a[0]}}function et(e,t,r){let n=Array.isArray(t)?t:[t],a="";for(let i of n){if(!i)continue;let o=r.serializeToString(i);o=o.replace(/\s+xmlns:w="[^"]*"/g,""),o=o.replace(/\s+xmlns:r="[^"]*"/g,""),o=o.replace(/\s+xmlns:wp="[^"]*"/g,""),a+=o}return A(`[OxmlEngine] Stripping table wrapper, serializing ${n.length} paragraphs`),A(`[OxmlEngine] Paragraph XML preview: ${a.substring(0,200)}...`),di(a)}function di(e){return Hr(e)}function hi(e){if(!e)return null;let t=typeof e.getAttributeNS=="function"?e.getAttributeNS(gi,"paraId"):null;return t||e.getAttribute("w14:paraId")||e.getAttribute("w:paraId")||e.getAttribute("paraId")||null}function cn(e,t,r,n,a,i,o=!0,s=null){let l="",c=[],f=s?[s]:me(e);f.forEach((w,h)=>{let x=w.parentNode;for(let v=w.firstChild;v;v=v.nextSibling)if(v.nodeName==="w:r"){let T=ln(v,w,x,l.length,c);l+=T.text}else if(v.nodeName==="w:hyperlink"){for(let T=v.firstChild;T;T=T.nextSibling)if(T.nodeName==="w:r"){let N=ln(T,w,x,l.length,c);l+=N.text}}l=_e(l,h,f.length)});let m=Ye(l,r),u=Ni(c),p=0,g=0,d=new Set;for(let[w,h]of m)if(w===0){let x=h.length,v=p,T=p+x;un(u,v,T,N=>{let E=Math.max(N.charStart,v),b=Math.min(N.charEnd,T),S=b-E,P=E-v,k=g+P,R=k+S,ne=he(i,k,R);wi(e,N,E,b,ne,a,o)}),p+=x,g+=x}else if(w===-1)bi(e,u,p,p+h.length,d,a,o),p+=h.length;else if(w===1){let x=h.replace(/\n/g," ");x.trim().length>0&&xi(e,u,p,x,d,a,i,g,o),g+=h.length}return{oxml:n.serializeToString(e),hasChanges:!0}}function wi(e,t,r,n,a,i,o){let s={};a.length>0&&a.forEach(b=>Object.assign(s,b.format));let l=t.rPr,c=b=>{if(!l)return!1;for(let S=l.firstChild;S;S=S.nextSibling)if(S.nodeName===b)return!0;return!1},f={bold:c("w:b"),italic:c("w:i"),underline:c("w:u"),strikethrough:c("w:strike")};if(!["bold","italic","underline","strikethrough"].some(b=>!!s[b]!==f[b]))return;let p=t.runElement.parentNode;if(!p)return;let g=t.textElement.textContent||"",d=t.charStart,w=r-d,h=n-d,x=g.substring(0,w),v=g.substring(w,h),T=g.substring(h);if(x.length>0){let b=se(e,x,l,!1);p.insertBefore(b,t.runElement)}let N=Fe(e,l,s,i,o),E=Kt(e,v,N,!1);if(p.insertBefore(E,t.runElement),T.length>0){let b=se(e,T,l,!1);p.insertBefore(b,t.runElement)}p.removeChild(t.runElement)}function ln(e,t,r,n,a){let i=M(e,"w:rPr"),o=n,s=[];for(let l=e.firstChild;l;l=l.nextSibling)if(l.nodeName==="w:t"){let c=l.textContent||"";c.length>0&&(a.push({charStart:o,charEnd:o+c.length,textElement:l,runElement:e,paragraph:t,container:r,rPr:i}),o+=c.length,s.push(c))}else l.nodeName==="w:br"||l.nodeName==="w:cr"?(a.push({charStart:o,charEnd:o+1,textElement:l,runElement:e,paragraph:t,container:r,rPr:i}),o+=1,s.push(`
141
+ `)):l.nodeName==="w:tab"?(a.push({charStart:o,charEnd:o+1,textElement:l,runElement:e,paragraph:t,container:r,rPr:i}),o+=1,s.push(" ")):l.nodeName==="w:noBreakHyphen"&&(a.push({charStart:o,charEnd:o+1,textElement:l,runElement:e,paragraph:t,container:r,rPr:i}),o+=1,s.push("\u2011"));return{nextOffset:o,text:s.join("")}}function bi(e,t,r,n,a,i,o){un(t,r,n,s=>{if(a.has(s.textElement))return;let l=Math.max(0,r-s.charStart),c=Math.min(s.charEnd-s.charStart,n-s.charStart),f=s.textElement.textContent||"",m=f.substring(0,l),u=f.substring(l,c),p=f.substring(c);if(u.length===0)return;let g=s.runElement.parentNode;if(g){if(m.length===0&&p.length===0){let d=se(e,u,s.rPr,!0);if(o){let w=ve(e,"del",d,i);g.insertBefore(w,s.runElement)}g.removeChild(s.runElement)}else{let d=s.runElement;if(m.length>0){let h=se(e,m,s.rPr,!1);g.insertBefore(h,d)}let w=se(e,u,s.rPr,!0);if(o){let h=ve(e,"del",w,i);g.insertBefore(h,d)}if(p.length>0){let h=se(e,p,s.rPr,!1);g.insertBefore(h,d),s.runElement=h,s.textElement=M(h,"w:t")||M(h,"t")}g.removeChild(d)}a.add(s.textElement)}})}function xi(e,t,r,n,a,i,o=[],s=0,l=!0){let c=Ti(t,r);if(!c&&r>0&&(c=yi(t,r)),!c&&r>0&&(c=Ei(t,r)),!c&&t.spans.length>0&&(c=t.spans[t.spans.length-1]),c){let f=he(o,s,s+n.length),m=c.rPr,u=c.runElement.parentNode;if(u){let p=r===c.charStart?c.runElement:c.runElement.nextSibling;if(f.length===0){let g=se(e,n,m,!1);if(l){let d=ve(e,"ins",g,i);u.insertBefore(d,p)}else u.insertBefore(g,p)}else{let g=xt(e,n,m,f,s,i,l);if(l){let d=ve(e,"ins",null,i);g.forEach(w=>d.appendChild(w)),u.insertBefore(d,p)}else g.forEach(d=>u.insertBefore(d,p))}}}}function Ni(e){let t=e.slice().sort((a,i)=>a.charStart-i.charStart||a.charEnd-i.charEnd),r=t.map(a=>a.charStart),n=t.map(a=>a.charEnd);return{spans:t,starts:r,ends:n}}function Yt(e,t){let r=0,n=e.length;for(;r<n;){let a=r+n>>1;e[a]<=t?r=a+1:n=a}return r}function vi(e,t){let r=0,n=e.length;for(;r<n;){let a=r+n>>1;e[a]<t?r=a+1:n=a}return r}function un(e,t,r,n){if(r<=t||e.spans.length===0)return;let a=Yt(e.ends,t);for(;a<e.spans.length;){let i=e.spans[a];if(i.charStart>=r)break;n(i),a++}}function Ti(e,t){if(e.spans.length===0)return null;let r=Yt(e.starts,t)-1;if(r<0)return null;let n=e.spans[r];return t>=n.charStart&&t<n.charEnd?n:null}function yi(e,t){let r=vi(e.ends,t);return r<e.spans.length&&e.ends[r]===t?e.spans[r]:null}function Ei(e,t){let r=Yt(e.ends,t)-1;return r>=0?e.spans[r]:null}function fn(e){let t=0;return{at(r){for(;t<e.length&&e[t].end<=r;)t++;let n=e[t];return n&&n.start<=r&&r<n.end?n:null}}}function Pi(e){let t=new Map;return e.forEach(r=>{t.has(r.start)||t.set(r.start,[]),t.get(r.start).push(r)}),t}function mn(e,t){let r=e.documentElement,n=r.nodeName==="w:body"||r.nodeName.endsWith(":package"),a=me(e),i=M(e,"w:body");!i&&n&&(i=r);let o="",s=[],l=[],c=[],f=new Map,m=new Map,u=57344,p=new Set;a.forEach((S,P)=>{let k=o.length;Array.from(S.childNodes).forEach(H=>{o=Si(H,o,s,c,f,m,u),f.size>m.size&&u++}),o=_e(o,P,a.length);let R=o.length,ne=M(S,"w:pPr"),Z=S.parentNode;Z&&p.add(Z),l.push({start:k,end:R,pPr:ne,container:Z||i})});let g=t;m.forEach((S,P)=>{let k=P.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");g=g.replace(new RegExp(k,"g"),S)});let d=new Map;p.forEach(S=>{d.set(S,e.createDocumentFragment())}),i&&!d.has(i)&&d.set(i,e.createDocumentFragment()),d.has(e)||d.set(e,e.createDocumentFragment());let w=new Map,h=new Set(l.map(S=>S.start)),x=fn(l),v=fn(s),T=Pi(c);return{paragraphs:a,body:i||e,paragraphMap:l,paragraphStarts:h,propertyMap:s,sentinelMap:c,sentinelMapByStart:T,referenceMap:f,tokenToCharMap:m,containerFragments:d,replacementContainers:w,originalFullText:o,processedModifiedText:g,getParagraphInfo:S=>{let P=x.at(S);return P||(l.length>0?l[l.length-1]:{start:0,end:0,pPr:null,container:i||e})},getRunProperties:S=>{let P=v.at(S);return P?{rPr:P.rPr,wrapper:P.wrapper}:{rPr:null}},getPropertySpanLength:(S,P)=>{let k=v.at(S);return k?Math.min(k.end-S,P):1},isParagraphStart:S=>h.has(S)}}function Si(e,t,r,n,a,i,o){return e.nodeName==="w:r"?Ii(e,t,r,n,a,i,o):e.nodeName==="w:hyperlink"?Ai(e,t,r):["w:sdt","w:oMath","m:oMath","w:bookmarkStart","w:bookmarkEnd"].includes(e.nodeName)?(n.push({start:t.length,node:e}),t+"\uFFFC"):(["w:commentRangeStart","w:commentRangeEnd"].includes(e.nodeName)&&n.push({start:t.length,node:e,isCommentMarker:!0}),t)}function Ii(e,t,r,n,a,i,o){let s=t,l=M(e,"w:rPr");return Array.from(e.childNodes).forEach(c=>{if(c.nodeName==="w:t"){let f=c.textContent||"";f.length>0&&(r.push({start:s.length,end:s.length+f.length,rPr:l}),s+=f)}else if(c.nodeName==="w:br"||c.nodeName==="w:cr")s+=`
142
+ `,r.push({start:s.length-1,end:s.length,rPr:l});else if(c.nodeName==="w:tab")s+=" ",r.push({start:s.length-1,end:s.length,rPr:l});else if(c.nodeName==="w:noBreakHyphen")s+="\u2011",r.push({start:s.length-1,end:s.length,rPr:l});else if(["w:drawing","w:pict","w:object","w:fldChar","w:instrText","w:sym"].includes(c.nodeName)){let f=M(c,"w:txbxContent"),m=c.nodeName==="w:pict"&&!!f;n.push({start:s.length,node:c,isTextBox:m,originalContainer:m?f:void 0}),s+="\uFFFC",r.push({start:s.length-1,end:s.length,rPr:l})}else if(c.nodeName==="w:footnoteReference"||c.nodeName==="w:endnoteReference"){let f=c.getAttribute("w:id");if(f){let u=`{{__${c.nodeName==="w:footnoteReference"?"FN":"EN"}_${f}__}}`,p=String.fromCharCode(o);a.set(p,c),i.set(u,p),s+=p,r.push({start:s.length-1,end:s.length,rPr:l})}}else c.nodeName==="w:commentReference"&&n.push({start:s.length,node:c,isCommentMarker:!0})}),s}function Ai(e,t,r){let n=t;return Array.from(e.childNodes).forEach(a=>{if(a.nodeName!=="w:r")return;let i=M(a,"w:rPr");Y(a,"w:t").forEach(s=>{let l=s.textContent||"";l.length!==0&&(r.push({start:n.length,end:n.length+l.length,rPr:i,wrapper:e}),n+=l)})}),n}function gn(e,t,r,n,a,i,o=!0){let{paragraphs:s,paragraphMap:l,containerFragments:c,sentinelMapByStart:f,referenceMap:m,replacementContainers:u,getParagraphInfo:p,getRunProperties:g,getPropertySpanLength:d,isParagraphStart:w}=r,h=b=>{let S=e.createElement("w:p");return b&&S.appendChild(b.cloneNode(!0)),S},x=p(0),v=h(x.pPr),T=c.get(x.container);T&&T.appendChild(v);let N=0,E=0;for(let[b,S]of t){if(b===0||b===-1){let P=b===0?"equal":"delete",k=0;for(;k<S.length;){let R=N+k,ne=g(R),Z=d(R,S.length-k),H=S.substring(k,k+Z);pn(e,H,P,ne.rPr,ne.wrapper,R,v,c,f,m,u,p,h,a,i,E,o),b===0&&(E+=Z),k+=Z}N+=S.length;continue}if(b===1){let P=N>0&&!w(N)?g(N-1):g(N);pn(e,S,"insert",P.rPr,P.wrapper,N,v,c,f,m,u,p,h,a,i,E,o),E+=S.length}}return s.forEach(b=>{b.parentNode&&b.parentNode.removeChild(b)}),c.forEach((b,S)=>{let k=u.get(S)||S;if(k.nodeType===9){let R=b.firstChild;if(R)for(k.appendChild(R);b.firstChild;)k.documentElement.appendChild(b.firstChild);return}k.appendChild(b)}),{oxml:n.serializeToString(e),hasChanges:!0}}function pn(e,t,r,n,a,i,o,s,l,c,f,m,u,p,g=[],d=0,w=!0){let h=i,x=d,v=o;t.split(/([\n\uFFFC]|[\uE000-\uF8FF])/).forEach(N=>{let E=l.get(h)||[];if(E.filter(P=>P.isCommentMarker).forEach(P=>{if(P.node.nodeName==="w:commentReference"){let k=e.createElement("w:r");k.appendChild(P.node.cloneNode(!0)),v.appendChild(k)}else v.appendChild(P.node.cloneNode(!0))}),N===`
143
+ `){if(r!=="delete"){let P=m(h),k=u(P.pPr),R=s.get(P.container);R&&(R.appendChild(k),v=k)}h++,r!=="delete"&&x++;return}if(N==="\uFFFC"){let P=E.find(k=>!k.isCommentMarker)||E[0];if(P){let k=P.node.cloneNode(!0);if(P.isTextBox&&P.originalContainer){let R=M(k,"w:txbxContent");if(R){for(;R.firstChild;)R.removeChild(R.firstChild);f.set(P.originalContainer,R)}}v.appendChild(k)}h++,r!=="delete"&&x++;return}if(c.has(N)){if(r!=="delete"){let P=c.get(N);if(P){let k=P.cloneNode(!0),R=e.createElement("w:r");n&&R.appendChild(n.cloneNode(!0)),R.appendChild(k),v.appendChild(R)}}h++,r!=="delete"&&x++;return}if(N.length===0)return;let S=v;if(a){let P=a.cloneNode(!1);S=P,v.appendChild(P)}if(r==="delete"){let P=e.createElement("w:r");n&&P.appendChild(n.cloneNode(!0));let k=e.createElement("w:delText");if(k.setAttribute("xml:space","preserve"),k.textContent=N,P.appendChild(k),w){let R=ve(e,"del",P,p);S.appendChild(R)}}else{let P=he(g,x,x+N.length),k=xt(e,N,n,P,x,p,w);if(r==="insert"&&w){let R=ve(e,"ins",null,p);k.forEach(ne=>R.appendChild(ne)),S.appendChild(R)}else k.forEach(R=>S.appendChild(R))}r!=="delete"&&(x+=N.length),h+=N.length})}function Jt(e,t,r,n,a,i,o=!0){let s=mn(e,r);if(s.paragraphs.length===0)return{oxml:n.serializeToString(e),hasChanges:!1};let l=Ye(s.originalFullText,s.processedModifiedText);return gn(e,l,s,n,a,i,o)}function Te(e,t){return{oxml:e.serializeToString(t),hasChanges:!1}}function dn(e,t,r,n,a,i=!0){let o=Y(e,"w:tbl"),s=oe(t),l=s.rows.length>0||s.headers.length>0;if(o.length===0||!l)return Te(r,e);let c=o[0],f=Ut(c),m=Gr(f,s);if(m.length===0)return Te(r,e);let p=Kr(f,m,{generateRedlines:i,author:a}),g=`<root xmlns:w="${I}">${p}</root>`,w=(n||B()).parseFromString(g,"application/xml"),h=U(w);if(h)return K("[OxmlEngine] Failed to parse reconciled table OOXML:",h.textContent),Te(r,e);let x=M(w,"w:tbl");if(!x)return K("[OxmlEngine] No table found in reconciled OOXML"),Te(r,e);let v=e.importNode(x,!0);return c.parentNode.replaceChild(v,c),{oxml:r.serializeToString(e),hasChanges:!0}}function hn(e,t,r,n,a,i){let o=oe(t);if(!o||o.rows.length===0&&o.headers.length===0)return A("[OxmlEngine] Failed to parse table data from Markdown"),Te(r,e);let s=ke(o,{generateRedlines:i,author:a}),l=n||B(),c=l.parseFromString(`<root xmlns:w="${I}">${s}</root>`,"application/xml"),f=U(c);if(f)return K("[OxmlEngine] Failed to parse generated table OOXML:",f.textContent),Te(r,e);let m=D(c,I,"tbl");if(m||(m=D(c,I,"ins")),!m)return K("[OxmlEngine] No table element found in generated OOXML"),Te(r,e);let u=e,p=z(u,I,"p");if(p.length===0)return A("[OxmlEngine] No paragraphs found to replace"),Te(r,u);let g=p[0],d=g.parentNode;if(d&&d.nodeType===9){let h=l.parseFromString(`<w:document xmlns:w="${I}"><w:body/></w:document>`,"application/xml"),x=D(h,I,"body");p.forEach(v=>x.appendChild(h.importNode(v,!0))),u=h,p=z(u,I,"p"),g=p[0],d=g.parentNode}let w=u.importNode(m,!0);if(i){let h=ae();p.forEach(x=>{z(x,I,"r").forEach(T=>{z(T,I,"t").forEach(b=>{let S=b.textContent||"";if(S.trim()){let P=u.createElementNS(I,"w:delText");P.textContent=S,b.parentNode.replaceChild(P,b)}});let E=u.createElementNS(I,"w:del");E.setAttribute("w:id",String(be())),E.setAttribute("w:author",a),E.setAttribute("w:date",h),T.parentNode.insertBefore(E,T),E.appendChild(T)})})}else p.slice(1).forEach(h=>h.parentNode.removeChild(h));return d.insertBefore(w,g),i||d.removeChild(g),A("[OxmlEngine] Text-to-table transformation complete"),{oxml:r.serializeToString(u),hasChanges:!0}}async function qt(e,t,r,n={}){let a=n.generateRedlines??!0,i=n.author||G(),o=B(),s=J(),l=()=>({oxml:e,hasChanges:!1}),c;try{c=o.parseFromString(e,"text/xml")}catch(H){return K("[OxmlEngine] Failed to parse OXML:",H),l()}let f=U(c);if(f)return K("[OxmlEngine] XML parse error:",f.textContent),l();let m=sn(c,t,n);if(m.hasTableWrapper&&m.targetParagraph&&!n._isolatedTableCell){A("[OxmlEngine] Isolating table-cell paragraph before diff");let H=et(c,m.targetParagraph,s);return qt(H,t,r,{...n,_isolatedTableCell:!0})}let u=wn(r),{cleanText:p,formatHints:g}=q(u),d=p.trim()!==t.trim(),w=g.length>0,{existingFormatHints:h,textSpans:x,paragraphs:v}=Qr(c),T=h.length>0,N=null,E=()=>(N||(N=Nt(c,v,x)),N),b=(H=null)=>{let X=on(c,t,g,s,i,a,H);return X.useNativeApi?(A("[OxmlEngine] Format-only surgical fallback signal encountered; retrying with OOXML reconstruction fallback"),Jt(c,t,p,s,i,g,a)):X};A(`[OxmlEngine] Text changes: ${d}, New format hints: ${g.length}, Existing format hints: ${h.length}`);let S=!d&&!w&&T;if(!d&&!w&&!T)return A("[OxmlEngine] No text changes, no format hints, and no existing formatting detected"),l();if(S){A("[OxmlEngine] Format REMOVAL detected: applying surgical replacement in OOXML");let H=m,X=H.targetParagraph||null;if(!X){let ut=en(E(),t);ut&&(X=ut.paragraph)}let Pe=h;X&&(Pe=h.filter(ut=>rn(ut.run)===X));let hr=an(c,x,Pe,s,i,a);return H.hasTableWrapper&&X?{oxml:et(c,X,s),hasChanges:hr.hasChanges}:hr}if(!d&&w){A(`[OxmlEngine] Format-only change detected: ${g.length} format hints`);let H=m,X={textSpans:x,paragraphs:v,paragraphInfos:E()};if(H.hasTableWrapper&&H.targetParagraph){A("[OxmlEngine] Table cell context: applying formatting to target paragraph only");let Pe=b(X);return A("[OxmlEngine] Stripping table wrapper for table cell paragraph (format-only)"),{oxml:et(c,H.targetParagraph,s),hasChanges:Pe.hasChanges}}return b(X)}let k=Y(c,"w:tbl").length>0,R=/^\|.+\|/.test(p.trim())&&p.includes(`
144
+ `),ne=pt(p),Z=m;if(A(`[OxmlEngine] Mode: ${k?"SURGICAL":"RECONSTRUCTION"}, formatHints: ${g.length}, isMarkdownTable: ${R}, isTargetList: ${ne}, isTableCellParagraph: ${Z.isTableCellParagraph}`),R&&!k)return A("[OxmlEngine] Text-to-table transformation: generating new table from Markdown"),hn(c,p,s,o,i,a);if(k&&R)return dn(c,p,s,o,i,a);if(k){let H=Z.hasTableWrapper&&Z.targetParagraph?Z.targetParagraph:null;H&&A("[OxmlEngine] Table cell edit: scoping surgical mode to target paragraph");let X=cn(c,t,p,s,i,g,a,H);return Z.hasTableWrapper&&X.hasChanges&&Z.targetParagraph?(A("[OxmlEngine] Stripping table wrapper for table cell paragraph (surgical mode)"),{oxml:et(c,Z.targetParagraph,s),hasChanges:!0}):X}if(ne){A("[OxmlEngine] \u{1F3AF} Using reconciliation pipeline for list generation");let X=await new Ce({author:i,generateRedlines:a}).execute(e,r,{xmlDoc:c});if(X.isValid&&X.ooxml&&X.ooxml!==e){A(`[OxmlEngine] Wrapping list OOXML with numbering definitions, includeNumbering=${X.includeNumbering}`);let Pe=Ne(X.ooxml,{includeNumbering:X.includeNumbering??!0,numberingXml:X.numberingXml});return A(`[OxmlEngine] \u2705 Wrapped OOXML length: ${Pe.length}`),{oxml:Pe,hasChanges:!0}}return l()}return Jt(c,t,p,s,i,g,a)}function wn(e){let t=e;return t=t.replace(/^(Here is the redline:|Here is the text:|Sure, I can help:|Here's the updated text:)\s*/i,""),t=t.replace(/\$\\text\{/g,"").replace(/\}\$/g,""),t=t.replace(/\$([^0-9\n]+?)\$/g,"$1"),t=t.replace(/\\r\\n/g,`
145
+ `).replace(/\\n/g,`
146
+ `),t}function pe(e){return br(e,"application/xml")}function Oe(e){return j(e)}function Qt(e){return Array.from(e||[])}var te="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function er(e,t){if(!e)return[];if(typeof e.getElementsByTagNameNS=="function"){let n=Qt(e.getElementsByTagNameNS("*",t));if(n.length>0)return n}if(typeof e.getElementsByTagName!="function")return[];let r=Qt(e.getElementsByTagName(`w:${t}`));return r.length>0?r:Qt(e.getElementsByTagName(t))}function ki(e){return er(e,"t").map(r=>r.textContent||"").join("")}function W(e){return e?ki(e):""}function ge(e){if(!e)return[];let t=er(e,"body"),r=t.length>0?t[0]:e;return er(r,"p")}function L(e){return String(e||"").replace(/\s+/g," ").trim()}function nr(e){let t=String(e||"").trim();return/^\|.+\|/.test(t)&&t.includes(`
147
+ `)}function ar(e){if(e==null)return null;if(typeof e=="number"&&Number.isInteger(e)&&e>0)return e;let t=String(e).trim();if(!t)return null;let r=t.match(/^\[?P(\d+)(?:\.\d+)?\]?$/i);if(r)return Number.parseInt(r[1],10);let n=t.match(/^(\d+)$/);return n?Number.parseInt(n[1],10):null}function Ci(e){return e==null?"":String(e).replace(/^\s*\[P\d+(?:\.\d+)?\]\s*/i,"").trim()}function Oi(e){let t=String(e||""),r=t.match(/^\s*\[P(\d+)(?:\.\d+)?\]\s*/i);return r?{text:t.replace(/^\s*\[P\d+(?:\.\d+)?\]\s*/i,"").trim(),targetRef:Number.parseInt(r[1],10)}:{text:t.trim(),targetRef:null}}function bn(e,t){return!Number.isInteger(t)||t<1?null:ge(e)[t-1]||null}function De(e,t,r=te){let n=e;for(;n;){if(n.nodeType===1&&n.namespaceURI===r&&n.localName===t)return n;n=n.parentNode}return null}function vt(e,t){let r=ge(e),n=String(t||"").trim();if(!n)return null;let a=r.find(o=>W(o).trim()===n);if(a)return a;let i=L(n);return r.find(o=>L(W(o))===i)||null}function tr(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=ge(e),i=String(t||"").trim();if(!i)return null;let o=vt(e,i);if(o)return o;let s=L(i),l=a.find(p=>{let g=L(W(p));return g.length>10&&s.startsWith(g)});if(l)return n(`[Fuzzy] Prefix match (target starts with paragraph): "${W(l).trim().slice(0,60)}..."`),l;let c=a.find(p=>{let g=L(W(p));return g.length>15&&s.includes(g)});if(c)return n(`[Fuzzy] Contains match: "${W(c).trim().slice(0,60)}..."`),c;let f=0,m=null,u=new Set(s.toLowerCase().split(/\s+/).filter(p=>p.length>2));for(let p of a){let g=W(p).trim();if(!g)continue;let h=L(g).toLowerCase().split(/\s+/).filter(x=>x.length>2).filter(x=>u.has(x)).length/Math.max(u.size,1);h>f&&h>.5&&(f=h,m=p)}return m?(n(`[Fuzzy] Best word-overlap match (${(f*100).toFixed(0)}%): "${W(m).trim().slice(0,60)}..."`),m):null}function xn(e,t={}){let r=typeof t.onInfo=="function"?t.onInfo:()=>{},n=typeof t.onWarn=="function"?t.onWarn:()=>{},a=t.opType||"operation",i=String(t.targetText||"").trim(),o=ar(t.targetRef);if(o){let s=bn(e,o);if(s){if(i){let l=vt(e,i),c=W(s).trim(),f=L(c),m=L(i),u=f!==m;if(u&&l&&l!==s)return r(`[Target] [P${o}] drifted for ${a}; using strict text rematch.`),{paragraph:l,resolvedBy:"strict_text_after_ref_drift"};if(u){let p=tr(e,i,{onInfo:r});if(p&&p!==s)return r(`[Target] [P${o}] drifted for ${a}; using fuzzy text rematch.`),{paragraph:p,resolvedBy:"fuzzy_text_after_ref_drift"};r(`[Target] Using [P${o}] fallback for ${a}; target text drifted.`)}else l&&l!==s&&r(`[Target] [P${o}] disambiguated duplicate target text for ${a}.`)}else r(`[Target] Using [P${o}] fallback for ${a}.`);return{paragraph:s,resolvedBy:"ref"}}n(`[WARN] Target reference [P${o}] not found; falling back to text matching for ${a}.`)}if(i){let s=vt(e,i);if(s)return{paragraph:s,resolvedBy:"strict_text"};let l=tr(e,i,{onInfo:r});if(l)return{paragraph:l,resolvedBy:"fuzzy_text"}}throw i?new Error(`Target paragraph not found: "${i}"`):o?new Error(`Target paragraph reference not found: [P${o}]`):new Error('Operation target missing: provide "target" text or "targetRef" ([P#]).')}function Nn(e){return!!De(e,"tbl")}function Ri(e,t){let r=L(t);if(!r)return[];let n=ge(e),a=[];for(let i=0;i<n.length;i++){let o=n[i],s=W(o).trim();s&&L(s)===r&&a.push({paragraph:o,index:i+1,inTable:Nn(o)})}return a}function Mi(e,t,r=null){if(!Array.isArray(e)||e.length===0)return null;let n=e.slice();if(typeof r=="boolean"){let a=n.filter(i=>i.inTable===r);a.length>0&&(n=a)}return Number.isInteger(t)&&t>0&&n.sort((a,i)=>Math.abs(a.index-t)-Math.abs(i.index-t)),n[0]||null}function Li(e){let t=ge(e),r=new Map;for(let n=0;n<t.length;n++){let a=t[n],i=W(a).trim();r.set(n+1,{text:i,normalizedText:L(i),inTable:Nn(a)})}return r}function rr(e,t={}){let r=typeof t.onInfo=="function"?t.onInfo:()=>{},n=xn(e,t),a=ar(t.targetRef);if(!a||n?.resolvedBy!=="ref")return n;let i=t.targetRefSnapshot instanceof Map&&t.targetRefSnapshot.get(a)||null;if(!i)return n;let o=String(t.targetText||"").trim(),s=o||i.text||"",l=L(s);if(!l||L(W(n.paragraph))===l)return n;let f=[];if(o&&f.push(o),i.text){let u=L(i.text);u&&!f.some(p=>L(p)===u)&&f.push(i.text)}let m=null;for(let u of f){let p=Ri(e,u),g=Mi(p,a,i.inTable);if(g&&(m||(m=g),g.paragraph!==n.paragraph)){m=g;break}}if(m&&m.paragraph!==n.paragraph){let u=t.opType||"operation";return r(`[Target] [P${a}] appears stale after prior edits; using strict text rematch for ${u}.`),{paragraph:m.paragraph,resolvedBy:"strict_text_after_ref_drift"}}return n}function _i(e,t,r,n={}){if(!e||!t||!r)return null;let a=n?.opType||"redline",i=n?.targetRefSnapshot||null,o=typeof n?.onInfo=="function"?n.onInfo:()=>{},s=typeof n?.onWarn=="function"?n.onWarn:()=>{},l=rr(e,{targetRef:t,opType:a,targetRefSnapshot:i,onInfo:o,onWarn:s})?.paragraph;if(!l)return null;let c=rr(e,{targetRef:r,opType:a,targetRefSnapshot:i,onInfo:o,onWarn:s})?.paragraph;if(!c)return null;let f=Array.from(e.getElementsByTagNameNS("*","p")),m=f.indexOf(l),u=f.indexOf(c);if(m<0||u<m)return null;let p=f.slice(m,u+1);if(p.length===0)return null;let g=p[0]?.parentNode||null;return!g||!p.every(d=>d&&d.parentNode===g)?null:p}function Tt(e,t){if(!e||typeof e.getElementsByTagNameNS!="function")return null;let r=e.getElementsByTagNameNS(te,t);if(r.length>0)return r[0];let n=e.getElementsByTagNameNS("*",t);return n.length>0?n[0]:null}function vn(e){if(!e)return null;if(typeof e.getAttributeNS=="function"){let t=e.getAttributeNS(te,"val");if(t)return t}return e.getAttribute("w:val")||e.getAttribute("val")||null}function Bi(e){let t=String(e||"").trim();if(!/^\d+(?:\.\d+)+\.?$/.test(t))return null;let r=t.replace(/\.$/,"").split(".");return Math.max(0,r.length-1)}var Tn=/^(?:(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|[ivxlcIVXLC]+\.|[-*+\u2022]))\s+/;function En(e){let t=String(e||"").trim(),r=0;for(;r<4&&Tn.test(t);)t=t.replace(Tn,"").trimStart(),r++;return t.trim()}function Pn(e){let t=String(e||"").split(/\r?\n/g),r=[],n=!1;for(let a of t){let i=a.trimEnd();if(!i.trim())continue;let o=i.match(/^(\s*)((?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|[ivxlcIVXLC]+\.|[-*+\u2022]))\s+(.*)$/);if(o){n=!0;let s=o[2],l=/^[-*+\u2022]$/.test(s)?"bullet":"numbered",c=Math.floor((o[1]||"").length/2);r.push({kind:"list",markerType:l,level:c,marker:s,outlineLevel:l==="numbered"?Bi(s):null,text:En(o[3])});continue}r.push({kind:"text",text:i.trim()})}return{items:r,hasListMarkers:n}}function yn(e,t,r){return`${" ".repeat(Math.max(0,e))}${t==="numbered"?"1.":"-"} ${String(r||"").trim()}`.trimEnd()}function tt(e,t){return L(e)===L(t)}function yt(e,t,r){return Number.isInteger(e?.outlineLevel)?Math.max(0,e.outlineLevel):Math.max(0,t+((e?.level||0)-r))}function $i(e,t,r){if(!Array.isArray(e)||e.length<2||!Number.isInteger(r)||r<1)return!1;let n=e[0],a=e.slice(1).filter(i=>i.kind==="list");return a.length===0||a.some(i=>i.markerType!=="bullet")||a.some(i=>Number.isInteger(i.outlineLevel))?!1:n?.kind==="text"||n?.kind==="list"&&n.markerType==="numbered"?tt(n.text,t):!1}function Fi(e,t){return e.map(r=>{let n=Math.max(0,(r.ilvl||0)-t);return{...r,ilvl:Math.min(8,t+1+n)}})}function Xi(e,t,r,n){let a=e[0],i=e.slice(1).filter(o=>o.kind==="list");if(a?.kind==="text"&&tt(a.text,t)&&i.length>0){let o=i[0].level;return i.map(s=>({ilvl:yt(s,r,o),markerType:s.markerType||n,text:s.text}))}if(e.every(o=>o.kind==="list")){let o=e[0];if(!o||!tt(o.text,t))return null;let s=o.level;return e.slice(1).map(l=>({ilvl:yt(l,r,s),markerType:l.markerType||n,text:l.text})).filter(l=>l.text)}return null}function de(e){if(!e)return null;let t=Tt(e,"pPr");if(!t)return null;let r=Tt(t,"numPr");if(!r)return null;let n=Tt(r,"numId");if(!n)return null;let a=vn(n);if(!a)return null;let i=Tt(r,"ilvl"),o=vn(i),s=Number.parseInt(o||"0",10);return{numId:String(a),ilvl:Number.isFinite(s)?s:0}}function Sn(e){let t=de(e);if(!t)return null;let r=e.parentNode;if(!r)return null;let n=Array.from(r.childNodes||[]).filter(s=>s&&s.nodeType===1&&s.namespaceURI===te&&s.localName==="p"),a=n.indexOf(e);if(a<0)return null;let i=a;for(;i>0;){let s=de(n[i-1]);if(!s||s.numId!==t.numId)break;i--}let o=a;for(;o<n.length-1;){let s=de(n[o+1]);if(!s||s.numId!==t.numId)break;o++}return n.slice(i,o+1)}function Di(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=typeof r.onWarn=="function"?r.onWarn:()=>{},i=String(t||"");if(!i.includes(`
148
+ `)||!de(e))return null;let s=Sn(e);if(!s||s.length===0)return null;let l=Pn(i);if(!l.hasListMarkers||l.items.length<2)return null;let c=L(r.currentParagraphText||W(e)),m=l.items.filter(b=>b.kind==="list")[0]?.markerType||"bullet",u=s.map(b=>({paragraph:b,list:de(b),text:String(W(b)||"").trim()})),p=s.indexOf(e);if(p<0)return null;let g=Math.min(...u.map(b=>b.list?.ilvl??0)),d=u.map(b=>yn((b.list?.ilvl??0)-g,m,b.text)),w=null,h=l.items[0],x=l.items.slice(1).filter(b=>b.kind==="list");if(h?.kind==="text"&&tt(h.text,c)&&x.length>0){let b=Math.max(0,(u[p].list?.ilvl??0)-g),S=x[0].level;w=[{level:b,markerType:m,text:u[p].text},...x.map(P=>({level:yt(P,b,S),markerType:P.markerType||m,text:P.text}))]}else if(l.items.every(b=>b.kind==="list")){let b=Math.max(0,(u[p].list?.ilvl??0)-g),S=l.items[0].level;w=l.items.map(P=>({level:yt(P,b,S),markerType:P.markerType||m,text:P.text}))}else return a("[List] Multiline list edit did not match supported insertion/replace patterns; skipping list-block synthesis."),null;let v=w.map(b=>yn(b.level,b.markerType,b.text)),T=d.slice(0,p).concat(v).concat(d.slice(p+1)),N=d.join(`
149
+ `),E=T.join(`
150
+ `);return E===N?null:(n("[List] Expanded single-item list edit to contiguous list block for stable middle insertion."),{paragraphs:s,originalText:N,modifiedText:E})}function zi(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=typeof r.onWarn=="function"?r.onWarn:()=>{},i=String(t||"");if(!i.includes(`
151
+ `))return null;let o=de(e);if(!o)return null;let s=Pn(i);if(!s.hasListMarkers||s.items.length<2)return null;let l=L(r.currentParagraphText||W(e)),f=s.items.filter(p=>p.kind==="list")[0]?.markerType||"bullet",m=Math.max(0,o.ilvl),u=Xi(s.items,l,m,f);return!u||u.length===0?(a("[List] Could not derive insertion-only entries from multiline list edit."),null):($i(s.items,l,m)&&(u=Fi(u,m),n("[List] Promoted bullet insertion to child depth for nested numbered-list intent.")),n("[List] Planned insertion-only list redline entries (no block rewrite)."),{targetParagraph:e,numId:o.numId,entries:u})}function rt(e){if(!e)return null;let t=String(e).trim();if(!t)return null;let r=t.split(`
152
+ `),n=[];for(let o of r){if(!o.trim())continue;let s=ue(o,{allowZeroSpaceAfterMarker:!1});if(s){let l=s[1]||"",c=s[2].trim(),f=we(o,{allowZeroSpaceAfterMarker:!1}).trim(),m=Math.floor(l.length/2),u=/^[-*+\u2022]$/.test(c);n.push({type:u?"bullet":"numbered",level:m,text:f,marker:c});continue}n.push({type:"text",level:0,text:o.trim()})}if(n.length===0)return null;let a=n.some(o=>o.type==="numbered"),i=n.some(o=>o.type==="bullet");return{type:a?"numbered":i?"bullet":"text",items:n}}function ir(e){return!e||!Array.isArray(e.items)?!1:e.items.some(t=>t?.type==="numbered"||t?.type==="bullet")}function or(e){let t=(e||"").trim();return!t||/^\d+(?:\.\d+)*\.?$/.test(t)||/^\(\d+\)$/.test(t)?"decimal":/^[ivxlcdm]+\.$/.test(t)?"lowerRoman":/^[IVXLCDM]{2,}\.$/.test(t)?"upperRoman":/^[a-z]\.$/.test(t)?"lowerAlpha":/^[A-Z]\.$/.test(t)?"upperAlpha":"decimal"}function Wi(e,t,r){let n=new Map,a=[];for(let i of e){let o=Math.max(0,Number(i?.level)||0);for(let f of Array.from(n.keys()))f>o&&n.delete(f);let s=(n.get(o)||0)+1;n.set(o,s);let l=Ui(s,t,r),c=" ".repeat(o*4);a.push(`${c}${l} ${i.text||""}`.trimEnd())}return a.join(`
153
+ `)}function Hi(e,t={}){let r=Math.max(1,Number(t.indentSpaces)||4),n=/^((?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|\d+\.|[ivxlcIVXLC]+\.|[-*•])\s*)/;return(e||[]).map(a=>{let i=String(a??""),o=i.match(/^(\s*)/),s=o?o[1].length:0,l=Math.floor(s/r),c=i.trim(),f=null,m=c.match(n);return m&&(f=m[1].trim()||null,c=c.replace(n,"")),{text:c.trim(),level:l,removedMarker:f}})}function Ui(e,t,r){if(t==="bullet")return"-";switch(r){case"lowerAlpha":return`${In(e,!1)}.`;case"upperAlpha":return`${In(e,!0)}.`;case"lowerRoman":return`${An(e,!1)}.`;case"upperRoman":return`${An(e,!0)}.`;case"decimal":default:return`${e}.`}}function In(e,t=!1){let r=Math.max(1,Number(e)||1),n="";for(;r>0;)r-=1,n=String.fromCharCode(97+r%26)+n,r=Math.floor(r/26);return t?n.toUpperCase():n}function An(e,t=!1){let r=Math.max(1,Number(e)||1),n=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]],a="";for(let[i,o]of n)for(;r>=i;)a+=o,r-=i;return t?a:a.toLowerCase()}function Et(e){let t=String(e||"");if(!t.trim()||t.includes(`
154
+ `))return null;let r=rt(t);if(!r||!ir(r)||!Array.isArray(r.items)||r.items.length!==1)return null;let n=r.items[0];if(!n||n.type!=="numbered"&&n.type!=="bullet")return null;let a=String(n.marker||"").trim(),i=n.type==="numbered"?or(a||"1."):"bullet";return{type:n.type,marker:a,numberingStyle:i,startAt:Gi(a,i),contentText:String(n.text||"").trim(),normalizedContent:L(String(n.text||""))}}function ji(e){let t=Et(e);return t?String(t.contentText||"").trim():String(e||"").trim()}function Gi(e,t){if(t!=="decimal")return null;let r=String(e||"").trim().match(/^(\d+)\.?$/);if(!r)return null;let n=Number.parseInt(r[1],10);return Number.isFinite(n)&&n>0?n:null}function Ki(e,t=null){let r=e?.numberingKey?String(e.numberingKey):null,n=Number.isInteger(e?.startAt)&&e.startAt>0?e.startAt:null;if(!r)return{type:"none",numberingKey:null,startAt:n,numId:null};if(n==null)return{type:"sharedByStyle",numberingKey:r,startAt:null,numId:null};let a=t?.explicitByNumberingKey;if(!(a instanceof Map))return{type:"explicitIsolated",numberingKey:r,startAt:n,numId:null};let i=a.get(r)||null;return i&&i.numId!=null&&Number.isInteger(i.nextStartAt)&&i.nextStartAt===n?{type:"explicitReuse",numberingKey:r,startAt:n,numId:String(i.numId)}:{type:"explicitStartNew",numberingKey:r,startAt:n,numId:null}}function Vi(e,t,r,n){!e||!(e.explicitByNumberingKey instanceof Map)||!t||r==null||!Number.isInteger(n)||n<1||e.explicitByNumberingKey.set(String(t),{numId:String(r),nextStartAt:n+1})}function Zi(e,t){!e||!(e.explicitByNumberingKey instanceof Map)||t&&e.explicitByNumberingKey.delete(String(t))}function ze(e,t){return e&&Array.from(e.childNodes||[]).find(r=>r&&r.nodeType===1&&r.namespaceURI==="http://schemas.openxmlformats.org/wordprocessingml/2006/main"&&r.localName===t)||null}function Yi(e,t={}){let r=t?.numId;if(r==null)return 0;let n=Number.isInteger(t?.ilvl)?Math.max(0,t.ilvl):0,a=t?.clearParagraphPropertyChanges!==!1,i=t?.removeListPropertyNode!==!1,o=(Array.isArray(e)?e:[]).filter(l=>l&&l.nodeType===1&&l.localName==="p"),s=0;for(let l of o){let c=l.ownerDocument;if(!c)continue;let f=ze(l,"pPr");if(f||(f=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:pPr"),l.insertBefore(f,l.firstChild)),a){let g=ze(f,"pPrChange");g&&f.removeChild(g)}if(i){let g=ze(f,"listPr");g&&f.removeChild(g)}let m=ze(f,"numPr");m||(m=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:numPr"),f.appendChild(m));let u=ze(m,"ilvl");u||(u=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:ilvl"),m.appendChild(u)),u.setAttribute("w:val",String(n));let p=ze(m,"numId");p||(p=c.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:numId"),m.appendChild(p)),p.setAttribute("w:val",String(r)),s++}return s}function Ji(e){let r=B().parseFromString(String(e||""),"application/xml");return U(r)?null:ge(r)[0]||null}function qi(e){return e?String(e).replace(/<w:p>\s*<w:pPr>\s*<\/w:pPr>\s*<\/w:p>\s*$/i,""):""}function Qi(e,t){for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return null}function We(e,t){let r=Qi(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function kn(e,t){e.setAttribute("w:val",String(t))}function eo(e){let r=B().parseFromString(String(e||""),"application/xml");if(U(r))return null;let i=ge(r)[0]||null;if(!i)return null;let o=Array.from(i.getElementsByTagNameNS("*","numId"));for(let s of o){let l=We(s,["w:val","val"]);if(l!=null)return String(l)}return null}function to(e,t,r,n={}){if(!e||!t||!Number.isInteger(r)||r<1)return e;let a=n.setAbstractStartOverride!==!1,i=B(),o=J(),s=i.parseFromString(String(e||""),"application/xml");if(U(s))return e;let f=Array.from(s.getElementsByTagNameNS("*","num")).find(d=>{let w=We(d,["w:numId","numId"]);return w!=null&&String(w)===String(t)});if(!f)return e;let m=Array.from(f.getElementsByTagNameNS("*","abstractNumId"))[0]||null,u=We(m,["w:val","val"]),p=Array.from(f.getElementsByTagNameNS("*","lvlOverride")).find(d=>We(d,["w:ilvl","ilvl"])===0)||null;p||(p=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:lvlOverride"),p.setAttribute("w:ilvl","0"),f.appendChild(p));let g=Array.from(p.getElementsByTagNameNS("*","startOverride"))[0]||null;if(g||(g=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:startOverride"),p.appendChild(g)),kn(g,r),a&&u!=null){let w=Array.from(s.getElementsByTagNameNS("*","abstractNum")).find(h=>{let x=We(h,["w:abstractNumId","abstractNumId"]);return x!=null&&x===u})||null;if(w){let h=Array.from(w.getElementsByTagNameNS("*","lvl")).find(v=>We(v,["w:ilvl","ilvl"])===0)||null;h||(h=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:lvl"),h.setAttribute("w:ilvl","0"),w.appendChild(h));let x=Array.from(h.getElementsByTagNameNS("*","start"))[0]||null;x||(x=s.createElementNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main","w:start"),h.insertBefore(x,h.firstChild)),kn(x,r)}}return o.serializeToString(s)}function sr(e={}){let t=String(e.oxml||""),r=String(e.originalText||""),n=String(e.modifiedText||""),a=e.allowExistingList===!0;if(!t.trim()||!n.trim())return null;let i=Ji(t);if(!i)return null;let o=de(i);if(o&&!a)return null;let s=q(n).cleanText||n,l=Et(n)||Et(s);if(!l)return null;let c=Et(r),f=L(r)===L(s),m=!!c&&c.type===l.type&&c.normalizedContent===l.normalizedContent;return!f&&!m?null:{listInput:`${l.marker} ${l.contentText}`.trim(),numberingKey:`${l.type}:${l.numberingStyle}:single`,originalText:r,wasListParagraph:!!o,startAt:l.startAt}}async function Pt(e,t={}){if(!e||!e.listInput)return{hasChanges:!1,oxml:"",numberingXml:null,includeNumbering:!1,listStructuralFallbackApplied:!1,listStructuralFallbackKey:null,warnings:["Single-line list fallback plan missing"]};let r=t.author||"AI",n=t.generateRedlines??!0,i=await(t.pipeline||new Ce({author:r,generateRedlines:n})).executeListGeneration(e.listInput,null,null,String(e.originalText||"")),o=i?.oxml||i?.ooxml||"",s=qi(o),l=eo(s),c=to(i?.numberingXml||null,l,Number.isInteger(e?.startAt)?e.startAt:null,{setAbstractStartOverride:t.setAbstractStartOverride}),f=i?.isValid!==!1;return!s||!f?{hasChanges:!1,oxml:"",numberingXml:null,includeNumbering:!1,listStructuralFallbackApplied:!1,listStructuralFallbackKey:e.numberingKey||null,warnings:["Single-line list fallback produced no valid OOXML"]}:{hasChanges:!0,oxml:s,numberingXml:c,includeNumbering:!0,listStructuralFallbackApplied:!0,listStructuralFallbackKey:e.numberingKey||null,listStructuralFallbackStartAt:Number.isInteger(e?.startAt)?e.startAt:null,warnings:["Single-line list structural fallback applied"]}}function St(e,t){return e?Array.from(e.childNodes||[]).filter(r=>r&&r.nodeType===1&&r.namespaceURI===te&&r.localName===t):[]}function ro(e){return String(e||"").replace(/\|/g,"\\|").replace(/\r?\n/g,"<br>")}function no(e){let t=St(e,"tr"),r=t.map(a=>St(a,"tc").map(o=>{let s=St(o,"p");return s.length===0?L(W(o)):s.map(c=>L(W(c))).filter(Boolean).join(`
155
+ `)})),n=r.reduce((a,i)=>Math.max(a,i.length),0);return r.forEach(a=>{for(;a.length<n;)a.push("")}),{matrix:r,rowElements:t,columnCount:n}}function ao(e,t){if(!Array.isArray(e)||e.length===0||t<=0)return null;let r=e.map(s=>{let l=Array.isArray(s)?s.slice(0,t):[];for(;l.length<t;)l.push("");return l}),n=r[0],a=new Array(t).fill("---"),i=r.slice(1),o=s=>`| ${s.map(l=>ro(l)).join(" | ")} |`;return[o(n),o(a),...i.map(o)].join(`
156
+ `)}function io(e){if(!Array.isArray(e)||e.length<2)return!1;let t=e.map(r=>L(r)).filter(Boolean);return t.length<2?!1:t.every(r=>r===t[0])}function Cn(e){let t=String(e||"").trim();return t?!!(/^and$/i.test(t)||/^\[.*\]$/.test(t)||/^\(.*\)$/.test(t)||/:\s*$/.test(t)||t.length<=90&&!/[.!?]$/.test(t)&&/[:\[\]()]/.test(t)||/^[\[(]/.test(t)):!1}function oo(e,t={}){let r=Number.isInteger(t?.maxScan)&&t.maxScan>0?t.maxScan:10,n=typeof t?.getParagraphText=="function"?t.getParagraphText:W;if(!e||!e.parentNode)return null;let a=[e],i=e.nextSibling,o=0;for(;i&&o<r;){o+=1;let s=i.nextSibling;if(i.nodeType!==1||i.namespaceURI!==te||i.localName!=="p"){i=s;continue}let l=String(n(i)||"").trim();if(!l){if(a.length>1)break;i=s;continue}if(!Cn(l))break;a.push(i),i=s}return a.length>1?a:null}function so(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},a=typeof r.onWarn=="function"?r.onWarn:()=>{},i=String(t||"");if(!i.includes(`
157
+ `)||nr(i))return null;let o=i.split(/\r?\n/g).map(T=>T.trim()).filter(Boolean);if(o.length<2)return null;let s=r.tableElement||De(e,"tbl"),l=De(e,"tr"),c=De(e,"tc");if(!s||!l||!c)return null;let f=L(r.currentParagraphText||W(e)),m=L(o[0]);if(f&&m&&m!==f)return a("[Table] Multiline cell text did not anchor to original cell text; skipping table-row synthesis heuristic."),null;let{matrix:u,rowElements:p,columnCount:g}=no(s);if(u.length===0||g===0)return null;let d=p.indexOf(l),h=St(l,"tc").indexOf(c);if(d<0||h<0||h>=g)return null;u[d][h]=o[0];let x=io(u[d]);x&&n("[Table] Symmetric row detected; mirroring inserted row values across columns.");for(let T=1;T<o.length;T++){let N=d+T,E=o[T];if(N<u.length&&!L(u[N][h]))if(x)for(let b=0;b<g;b++)L(u[N][b])||(u[N][b]=E);else u[N][h]=E;else{let b=new Array(g).fill("");if(x)for(let S=0;S<g;S++)b[S]=E;else b[h]=E;u.splice(Math.min(N,u.length),0,b)}}let v=ao(u,g);return v?(n("[Table] Synthesized full markdown table from multiline cell edit for table-scope reconciliation."),v):null}function He(e,t){if(!e||!Array.isArray(t))return null;for(let r of t){let n=e.getAttribute(r);if(n==null||n==="")continue;let a=Number.parseInt(String(n),10);if(Number.isFinite(a))return a}return null}function Ue(e,t,r=null){let n=Number.isInteger(e)&&e>0?e:1,a=t instanceof Set?t:new Set;for(;a.has(n);)n+=1;if(Number.isInteger(r)&&r>0&&n>r){for(let i=1;i<=r;i+=1)if(!a.has(i))return i}return n}function lo(e,t={}){let r=Number.isInteger(t?.minId)&&t.minId>0?t.minId:1,n=Number.isInteger(t?.maxPreferred)&&t.maxPreferred>=r?t.maxPreferred:32767,a=new Set,i=new Set;if(String(e||"").trim())try{let f=pe(e),m=Array.from(f.getElementsByTagNameNS("*","abstractNum")),u=Array.from(f.getElementsByTagNameNS("*","num"));for(let p of m){let g=He(p,["w:abstractNumId","abstractNumId"]);g!=null&&i.add(g)}for(let p of u){let g=He(p,["w:numId","numId"]);g!=null&&a.add(g)}}catch{}let o=a.size>0?Math.max(...a):0,s=i.size>0?Math.max(...i):0,l=Math.max(r,o+1),c=Math.max(r,s+1);return{nextNumId:Ue(l,a,n),nextAbstractNumId:Ue(c,i,n),usedNumIds:a,usedAbstractNumIds:i,minId:r,maxPreferred:n}}function co(e){return!e||typeof e!="object"?null:(e.usedNumIds instanceof Set||(e.usedNumIds=new Set),e.usedAbstractNumIds instanceof Set||(e.usedAbstractNumIds=new Set),(!Number.isInteger(e.minId)||e.minId<1)&&(e.minId=1),(!Number.isInteger(e.maxPreferred)||e.maxPreferred<e.minId)&&(e.maxPreferred=32767),(!Number.isInteger(e.nextNumId)||e.nextNumId<e.minId)&&(e.nextNumId=e.minId),(!Number.isInteger(e.nextAbstractNumId)||e.nextAbstractNumId<e.minId)&&(e.nextAbstractNumId=e.minId),e.nextNumId=Ue(e.nextNumId,e.usedNumIds,e.maxPreferred),e.nextAbstractNumId=Ue(e.nextAbstractNumId,e.usedAbstractNumIds,e.maxPreferred),e)}function at(e,t="num"){let r=co(e);if(!r)return null;let n=t==="abstract",a=n?r.nextAbstractNumId:r.nextNumId;return!Number.isInteger(a)||a<1?null:(n?(r.usedAbstractNumIds.add(a),r.nextAbstractNumId=Ue(a+1,r.usedAbstractNumIds,r.maxPreferred)):(r.usedNumIds.add(a),r.nextNumId=Ue(a+1,r.usedNumIds,r.maxPreferred)),a)}function uo(e){let t=at(e,"num"),r=at(e,"abstract");return t==null||r==null?null:{numId:t,abstractNumId:r}}function lr(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:e.getElementsByTagName("parsererror").length>0}function It(e,t){return!!(e&&e.nodeType===1&&e.namespaceURI===te&&e.localName===t)}function On(e,t,r){if(!e||!t)return;let n=Array.from(e.childNodes||[]).filter(i=>i&&i.nodeType===1&&i.namespaceURI===te),a=null;r==="abstract"?a=n.find(i=>i.localName==="num"||i.localName==="numIdMacAtCleanup")||null:a=n.find(i=>i.localName==="numIdMacAtCleanup")||null,a?e.insertBefore(t,a):e.appendChild(t)}function fo(e,t){for(let r of t||[]){let n=e?.getAttribute?.(r);if(n!=null&&n!=="")return n}return null}function nt(e,t){let r=fo(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function Rn(e,t,r){e?.setAttribute?.(t,String(r))}function cr(e,t){e?.setAttribute?.("w:val",String(t))}function mo(e,t){if(!(!Array.isArray(e)||t==null))for(let r of e){let n=Array.from(r?.getElementsByTagNameNS?.("*","numId")||[]);for(let a of n)cr(a,t)}}function po(e){for(let t of e||[]){let r=Array.from(t?.getElementsByTagNameNS?.("*","numId")||[]);for(let n of r){let a=nt(n,["w:val","val"]);if(a!=null)return String(a)}}return null}function go(e,t,r){let n=String(e),a=String(t),i=Number.isInteger(r)&&r>0?r:1,o=Array.from({length:9},(s,l)=>{let c=Array.from({length:l+1},(m,u)=>`%${u+1}`).join(".")+".",f=720*(l+1);return`
158
+ <w:lvl w:ilvl="${l}">
159
+ <w:start w:val="1"/>
160
+ <w:numFmt w:val="decimal"/>
161
+ <w:lvlText w:val="${c}"/>
162
+ <w:lvlJc w:val="left"/>
163
+ <w:pPr><w:ind w:left="${f}" w:hanging="360"/></w:pPr>
164
+ </w:lvl>`}).join("");return`
165
+ <w:numbering xmlns:w="${te}">
166
+ <w:abstractNum w:abstractNumId="${a}">
167
+ <w:multiLevelType w:val="multilevel"/>
168
+ ${o}
169
+ </w:abstractNum>
170
+ <w:num w:numId="${n}">
171
+ <w:abstractNumId w:val="${a}"/>
172
+ <w:lvlOverride w:ilvl="0">
173
+ <w:startOverride w:val="${i}"/>
174
+ </w:lvlOverride>
175
+ </w:num>
176
+ </w:numbering>`.trim()}function ho(e,t,r){let n=pe(e);if(lr(n))return{numberingXml:String(e||""),replacementNodes:Array.isArray(t)?t.map(c=>c?.cloneNode?c.cloneNode(!0):c):[]};let a=new Map,i=new Map,o=Array.from(n.getElementsByTagNameNS("*","abstractNum"));for(let c of o){let f=nt(c,["w:abstractNumId","abstractNumId"]);if(f==null)continue;let m=at(r,"abstract");m!=null&&(a.set(f,m),Rn(c,"w:abstractNumId",m))}let s=Array.from(n.getElementsByTagNameNS("*","num"));for(let c of s){let f=nt(c,["w:numId","numId"]);if(f==null)continue;let m=at(r,"num");if(m==null)continue;i.set(f,m),Rn(c,"w:numId",m);let u=Array.from(c.getElementsByTagNameNS("*","abstractNumId"))[0]||null;if(u){let p=nt(u,["w:val","val"]);p!=null&&a.has(p)&&cr(u,a.get(p))}}let l=Array.isArray(t)?t.map(c=>c?.cloneNode?c.cloneNode(!0):c):[];for(let c of l){let f=Array.from(c?.getElementsByTagNameNS?.("*","numId")||[]);for(let m of f){let u=nt(m,["w:val","val"]);u!=null&&i.has(u)&&cr(m,i.get(u))}}return{numberingXml:Oe(n),replacementNodes:l}}function wo(e,t){let r=String(e||""),n=String(t||"");if(!n.trim())return r;if(!r.trim())return n;try{let a=pe(r),i=pe(n);if(lr(a)||lr(i))return r;let o=a.documentElement,s=i.documentElement;if(!o||!s)return r;let l=new Set(Array.from(o.childNodes||[]).filter(f=>It(f,"abstractNum")).map(f=>He(f,["w:abstractNumId","abstractNumId"])).filter(f=>f!=null)),c=new Set(Array.from(o.childNodes||[]).filter(f=>It(f,"num")).map(f=>He(f,["w:numId","numId"])).filter(f=>f!=null));for(let f of Array.from(s.childNodes||[])){if(!It(f,"abstractNum"))continue;let m=He(f,["w:abstractNumId","abstractNumId"]);m==null||l.has(m)||(On(o,a.importNode(f,!0),"abstract"),l.add(m))}for(let f of Array.from(s.childNodes||[])){if(!It(f,"num"))continue;let m=He(f,["w:numId","numId"]);m==null||c.has(m)||(On(o,a.importNode(f,!0),"num"),c.add(m))}return Oe(a)}catch{return r}}function bo(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:!!U(e)}function Mn(e){let t=typeof e=="string"?e:String(e||"");if(!t.trim())return null;try{let n=B().parseFromString(t,"application/xml");return bo(n)?null:n}catch{return null}}function Ln(e){if(!e)return[];let t=Array.from(e.getElementsByTagNameNS(I,"p"));return t.length>0?t:Array.from(e.getElementsByTagNameNS("*","p")).filter(r=>r?.localName==="p")}function ur(e,t){let r=Array.from(e?.childNodes||[]);for(let n of r)if(n?.nodeType===1&&n.namespaceURI===I&&n.localName===t)return n;return null}function ye(e,t){return Array.from(e?.getElementsByTagNameNS?.(I,t)||[])}function it(e,t){if(!e)return"";for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return""}function xo(e,t,r){let n=e?.parentNode||null;for(;n&&n!==r;){if(n.nodeType===1&&n.namespaceURI===I&&n.localName===t)return!0;n=n.parentNode}return!1}function No(e){let t="";for(let r of Array.from(e?.childNodes||[]))!r||r.nodeType!==1||r.namespaceURI!==I||(r.localName==="t"?t+=r.textContent||"":r.localName==="tab"?t+=" ":r.localName==="br"||r.localName==="cr"?t+=`
177
+ `:r.localName==="noBreakHyphen"&&(t+="\u2011"));return t}function vo(e){let t=ur(e,"rPr");if(!t)return{bold:!1,italic:!1};let r=ye(t,"rStyle")[0]||null,n=it(r,["w:val","val"]).toLowerCase(),a=n.includes("strong")||n.includes("bold"),i=n.includes("italic")||n.includes("emphasis");return{bold:ye(t,"b").length>0||a,italic:ye(t,"i").length>0||i}}function _n(e){let t=[],r=Array.from(e?.getElementsByTagNameNS?.(I,"r")||[]);for(let n of r){if(xo(n,"del",e))continue;let a=No(n);a&&t.push({text:a,...vo(n)})}return t}function fr(e){return String(e||"").replace(/\r/g,"").split(`
178
+ `).map(r=>r.replace(/[ \t]+/g," ").trim()).join(`
179
+ `).trim()}function To(e,t){let r=String(e||"");if(!r)return"";if(!t?.bold&&!t?.italic)return r;let n=r.match(/^(\s*)([\s\S]*?)(\s*)$/);if(!n)return r;let a=n[1]||"",i=n[2]||"",o=n[3]||"";if(!i.trim())return r;let s=i;return t.bold&&t.italic?s=`***${i}***`:t.bold?s=`**${i}**`:t.italic&&(s=`*${i}*`),`${a}${s}${o}`}function yo(e){let t=ur(e,"pPr");if(!t)return null;let r=ye(t,"pStyle")[0]||null,n=it(r,["w:val","val"]);if(n){let s=n.match(/^heading\s*([1-9])$/i);if(s){let l=Number.parseInt(s[1],10);if(Number.isInteger(l))return Math.min(Math.max(l,1),6)}}let a=ye(t,"outlineLvl")[0]||null,i=it(a,["w:val","val"]),o=Number.parseInt(i,10);return Number.isInteger(o)&&o>=0?Math.min(o+1,6):null}function Eo(e){let t=ur(e,"pPr");if(!t)return null;let r=ye(t,"numPr")[0]||null;if(!r)return null;let n=ye(r,"ilvl")[0]||null,a=ye(r,"numId")[0]||null,i=Number.parseInt(it(n,["w:val","val"]),10),o=it(a,["w:val","val"]);return{level:Number.isInteger(i)&&i>=0?i:0,marker:o==="1"?"-":"1."}}function Po(e){let t=_n(e).map(r=>r.text).join("");return fr(t)}function So(e){let r=_n(e).map(o=>To(o.text,o)).join(""),n=fr(r);if(!n)return"";let a=yo(e);if(a!=null)return`${"#".repeat(a)} ${n}`;let i=Eo(e);return i?`${" ".repeat(i.level)}${i.marker} ${n}`:n}function Io(e){let t=Mn(e);if(!t)return"";let r=Ln(t);return r.length===0?fr(t.documentElement?.textContent||""):r.map(Po).join(`
180
+
181
+ `).trim()}function Ao(e){let t=Mn(e);if(!t)return"";let r=Ln(t);return r.length===0?"":r.map(So).join(`
182
+
183
+ `).trim()}function mr(e,t,r,n){let a=t.split(" ").map(s=>s[0]).join("").toUpperCase()||"AI",i=ee(r),o=ee(t);return`<w:comment w:id="${e}" w:author="${o}" w:date="${n}" w:initials="${a}">
184
+ <w:p>
185
+ <w:r><w:t>${i}</w:t></w:r>
186
+ </w:p>
187
+ </w:comment>`}function pr(e){if(!e||e.length===0)return`<w:comments xmlns:w="${I}"></w:comments>`;let t=e.map(r=>mr(r.id,r.author,r.content,r.date)).join(`
188
+ `);return`<w:comments xmlns:w="${I}">
189
+ ${t}
190
+ </w:comments>`}function At(e){let t=Y(e,"w:r"),r=[],n="";for(let a of t){let i=n.length,o=Y(a,"w:t");for(let s of o)n+=s.textContent||"";r.push({run:a,start:i,end:n.length})}return{fullText:n,runOffsets:r}}function ko(e,t){let r=e.fullText.indexOf(t);if(r===-1)return{found:!1};let n=r+t.length,a=null,i=null,o=0,s=0;for(let{run:l,start:c,end:f}of e.runOffsets)r>=c&&r<f&&(a=l,o=r-c),n>c&&n<=f&&(i=l,s=n-c);return{found:!0,startRun:a,startOffset:o,endRun:i,endOffset:s}}function ot(e,t,r){let n=e.createElementNS(I,"w:r");t&&n.appendChild(t.cloneNode(!0));let a=e.createElementNS(I,"w:t");return a.setAttribute("xml:space","preserve"),a.textContent=r,n.appendChild(a),n}function Bn(e,t,r,n,a=null){let i=a||At(t),o=ko(i,r);if(!o.found||!o.startRun)return!1;let s=e.createElementNS(I,"w:commentRangeStart");s.setAttribute("w:id",String(n));let l=e.createElementNS(I,"w:commentRangeEnd");l.setAttribute("w:id",String(n));let c=e.createElementNS(I,"w:r"),f=e.createElementNS(I,"w:commentReference");if(f.setAttribute("w:id",String(n)),c.appendChild(f),o.startRun===o.endRun){let g=o.startRun,d=M(g,"w:t");if(!d)return g.parentNode.insertBefore(s,g),g.nextSibling?(g.parentNode.insertBefore(l,g.nextSibling),l.parentNode.insertBefore(c,l.nextSibling)):(g.parentNode.appendChild(l),g.parentNode.appendChild(c)),!0;let w=d.textContent||"",h=w.substring(0,o.startOffset),x=w.substring(o.startOffset,o.endOffset),v=w.substring(o.endOffset),T=M(g,"w:rPr"),N=g.parentNode;return h&&N.insertBefore(ot(e,T,h),g),N.insertBefore(s,g),d.textContent=x,g.nextSibling?N.insertBefore(l,g.nextSibling):N.appendChild(l),N.insertBefore(c,l.nextSibling||null),v&&N.insertBefore(ot(e,T,v),c.nextSibling||null),!0}let m=M(o.startRun,"w:t");if(m&&o.startOffset>0){let g=m.textContent||"",d=g.substring(0,o.startOffset),w=g.substring(o.startOffset);if(d){let h=M(o.startRun,"w:rPr");o.startRun.parentNode.insertBefore(ot(e,h,d),o.startRun)}m.textContent=w}o.startRun.parentNode.insertBefore(s,o.startRun);let u=o.endRun||o.startRun,p=M(u,"w:t");if(p&&o.endOffset<(p.textContent||"").length){let g=p.textContent||"",d=g.substring(0,o.endOffset),w=g.substring(o.endOffset);if(p.textContent=d,w){let h=M(u,"w:rPr");u.nextSibling?u.parentNode.insertBefore(ot(e,h,w),u.nextSibling):u.parentNode.appendChild(ot(e,h,w))}}return u.nextSibling?(u.parentNode.insertBefore(l,u.nextSibling),l.parentNode.insertBefore(c,l.nextSibling)):(u.parentNode.appendChild(l),u.parentNode.appendChild(c)),!0}var je="http://schemas.microsoft.com/office/2006/xmlPackage",st="http://schemas.openxmlformats.org/package/2006/relationships";function $n(e,t){let r=B(),n=J(),a=r.parseFromString(e,"text/xml"),i=U(a);if(i)return K("[CommentEngine] Failed to parse package:",i.textContent),e;let o=a.documentElement,s=a.createElementNS(je,"pkg:part");s.setAttribute("pkg:name","/word/comments.xml"),s.setAttribute("pkg:contentType","application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml");let l=a.createElementNS(je,"pkg:xmlData"),c=r.parseFromString(t,"text/xml");l.appendChild(a.importNode(c.documentElement,!0)),s.appendChild(l),o.appendChild(s);let m=z(o,je,"part").find(u=>u.getAttribute("pkg:name")==="/word/_rels/document.xml.rels");if(m){let u=z(m,je,"xmlData");if(u.length>0){let p=z(u[0],st,"Relationships");if(p.length>0){let g=p[0],d=z(g,st,"Relationship");if(!d.some(h=>h.getAttribute("Type")?.includes("comments"))){let h=0;d.forEach(v=>{let T=v.getAttribute("Id"),N=parseInt(T?.replace("rId","")||"0",10);N>h&&(h=N)});let x=a.createElementNS(st,"Relationship");x.setAttribute("Id",`rId${h+1}`),x.setAttribute("Type","http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"),x.setAttribute("Target","comments.xml"),g.appendChild(x)}}}}else{let u=a.createElementNS(je,"pkg:part");u.setAttribute("pkg:name","/word/_rels/document.xml.rels"),u.setAttribute("pkg:contentType","application/vnd.openxmlformats-package.relationships+xml");let p=a.createElementNS(je,"pkg:xmlData"),g=a.createElementNS(st,"Relationships"),d=a.createElementNS(st,"Relationship");d.setAttribute("Id","rId1"),d.setAttribute("Type","http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"),d.setAttribute("Target","comments.xml"),g.appendChild(d),p.appendChild(g),u.appendChild(p),o.appendChild(u)}return n.serializeToString(a)}function Co(e,t,r){try{let n=t.parseFromString(e,"text/xml"),a=U(n);return a?{xmlDoc:null,warning:r(a.textContent||"parse error")}:{xmlDoc:n,warning:null}}catch(n){return{xmlDoc:null,warning:r(n.message)}}}function Oo(e,t,r={}){let n=r?.author||G(),a=ae(),i=[],o=[];if(!t||t.length===0)return{oxml:e,commentsApplied:0,warnings:["No comments to inject"]};let s=B(),l=J(),c=Co(e,s,g=>`Failed to parse OXML: ${g}`);if(!c.xmlDoc)return K("[CommentEngine] Parse failure:",c.warning),{oxml:e,commentsApplied:0,warnings:[c.warning]};let f=c.xmlDoc,m=Y(f,"w:p");A(`[CommentEngine] Found ${m.length} paragraphs, processing ${t.length} comment requests`);let u=new Map;for(let g of t){let d=g.paragraphIndex-1;if(d<0||d>=m.length){i.push(`Paragraph ${g.paragraphIndex} out of range (1-${m.length})`);continue}u.set(d,(u.get(d)||0)+1)}let p=new Map;for(let g of t){let d=g.paragraphIndex-1;if(d<0||d>=m.length)continue;let w=m[d],h=p.get(d);h||(h=At(w),p.set(d,h));let x=be(),v=Bn(f,w,g.textToFind,x,h),T=(u.get(d)||1)-1;if(u.set(d,T),!v){i.push(`Could not find "${g.textToFind.substring(0,30)}..." in paragraph ${g.paragraphIndex}`),T===0&&p.delete(d);continue}o.push({id:x,content:g.commentContent,author:n,date:a}),T>0?p.set(d,At(w)):p.delete(d)}return o.length===0?{oxml:e,commentsApplied:0,warnings:i}:{oxml:l.serializeToString(f),commentsXml:pr(o),commentsApplied:o.length,warnings:i}}function Ro(e,t){return $n(e,t)}function Fn(e,t=["all"]){if(!e)return null;let r=e.cloneNode(!0);if(t.includes("all"))["w:b","w:i","w:u","w:strike","w:dstrike","w:color","w:sz","w:szCs","w:rFonts","w:highlight","w:vertAlign","w:spacing","w:w","w:kern","w:position"].forEach(a=>{r.querySelectorAll(`${a}, ${a.replace("w:","")}`).forEach(o=>o.remove())});else{let n={bold:"w:b",italic:"w:i",underline:"w:u",strikethrough:"w:strike",doubleStrike:"w:dstrike",color:"w:color",highlight:"w:highlight",fontSize:"w:sz",fontSizeCs:"w:szCs",fontFamily:"w:rFonts",superscript:"w:vertAlign",subscript:"w:vertAlign"};t.forEach(a=>{let i=n[a];i&&r.querySelectorAll(`${i}, ${i.replace("w:","")}`).forEach(s=>s.remove())})}return r.children.length>0?r:null}function Mo(e,t,r){if(!t||!e)return e;let n=pe(e),a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",i=n.getElementsByTagNameNS(a,"r"),o=n.getElementsByTagNameNS(a,"ins"),s=[...Array.from(i)];for(let l of o){let c=l.getElementsByTagNameNS(a,"r");s.push(...Array.from(c))}for(let l of s){let c=l.getElementsByTagNameNS(a,"t"),f=Array.from(c).map(m=>m.textContent).join("");if(f.includes(t)||f===t){let m=l.getElementsByTagNameNS(a,"rPr");if(m.length>0){let u=m[0],p=Fn(u,r);p?u.parentNode&&u.parentNode.replaceChild(p,u):u.remove()}}}return Oe(n)}var Lo={yellow:"yellow",green:"green",cyan:"cyan",magenta:"magenta",blue:"blue",red:"red",darkblue:"darkBlue",darkcyan:"darkCyan",darkgreen:"darkGreen",darkmagenta:"darkMagenta",darkred:"darkRed",darkyellow:"darkYellow",gray25:"lightGray",gray50:"darkGray",black:"black",white:"white"};function _o(e,t,r="yellow",n={}){let a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",i=Lo[r.toLowerCase()]||"yellow",o=n?.generateRedlines??!1,s=n?.author||G(),l=t;l?l=t.cloneNode(!0):l=e.createElementNS(a,"w:rPr");let c=null;o&&(c=e.createElementNS(a,"w:rPr"),Array.from(l.childNodes).forEach(u=>{u.nodeName!=="w:rPrChange"&&c.appendChild(u.cloneNode(!0))}));let f=l.getElementsByTagNameNS(a,"highlight");Array.from(f).forEach(u=>u.remove());let m=e.createElementNS(a,"w:highlight");if(m.setAttributeNS(a,"w:val",i),l.appendChild(m),o&&c){let u=e.createElementNS(a,"w:rPrChange");u.setAttributeNS(a,"w:id",Math.floor(Math.random()*9999999).toString()),u.setAttributeNS(a,"w:author",s),u.setAttributeNS(a,"w:date",new Date().toISOString()),u.appendChild(c);let p=l.getElementsByTagNameNS(a,"rPrChange");Array.from(p).forEach(g=>g.remove()),l.appendChild(u)}return l}function Bo(e,t,r="yellow",n={}){if(!t||!e)return e;let a=pe(e),i="http://schemas.openxmlformats.org/wordprocessingml/2006/main",o=l=>{let c=l.getElementsByTagNameNS(i,"t");return Array.from(c).map(f=>f.textContent).join("")},s=Array.from(a.getElementsByTagNameNS(i,"r"));for(let l=0;l<s.length;l++){let c=s[l],f=o(c);if(!f)continue;let m=f.indexOf(t);if(m===-1)continue;let u=c.parentNode;if(!u){console.warn("[Highlight] Run parent is null; skipping. Likely already processed.");continue}let p=f.substring(0,m),g=f.substring(m,m+t.length),d=f.substring(m+t.length),w=a.createDocumentFragment();if(p.length>0){let h=c.cloneNode(!0),x=h.getElementsByTagNameNS(i,"t");Array.from(x).forEach(T=>T.remove());let v=a.createElementNS(i,"w:t");v.setAttribute("xml:space","preserve"),v.textContent=p,h.appendChild(v),w.appendChild(h)}if(g.length>0){let h=c.cloneNode(!0),x=h.getElementsByTagNameNS(i,"t");Array.from(x).forEach(b=>b.remove());let v=a.createElementNS(i,"w:t");v.setAttribute("xml:space","preserve"),v.textContent=g,h.appendChild(v);let T=h.getElementsByTagNameNS(i,"rPr"),N=T.length>0?T[0]:null,E=_o(a,N,r,n);N?h.replaceChild(E,N):h.insertBefore(E,h.firstChild),w.appendChild(h)}if(d.length>0){let h=c.cloneNode(!0),x=h.getElementsByTagNameNS(i,"t");Array.from(x).forEach(T=>T.remove());let v=a.createElementNS(i,"w:t");v.setAttribute("xml:space","preserve"),v.textContent=d,h.appendChild(v),w.appendChild(h)}u.replaceChild(w,c)}return Oe(a)}var Q="http://schemas.openxmlformats.org/wordprocessingml/2006/main",$o="http://schemas.openxmlformats.org/package/2006/content-types",Fo="http://schemas.openxmlformats.org/package/2006/relationships",Dn="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",zn="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",Wn="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",Hn="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",Xn="word/document.xml",kt="word/numbering.xml",lt="word/comments.xml",Re="[Content_Types].xml",Me="word/_rels/document.xml.rels";function Ee(e,t="xml"){let n=B().parseFromString(e,"application/xml"),a=n.getElementsByTagName("parsererror")[0];if(a)throw new Error(`[XML parse error] ${t}: ${a.textContent||"Unknown"}`);return n}function Ct(e){return!!e&&e.nodeType===1&&e.namespaceURI===Q&&e.localName==="sectPr"}function dr(e){return e.getElementsByTagNameNS("*","body")[0]||null}function Un(e){for(let t of Array.from(e.childNodes||[]))if(Ct(t))return t;return null}function Xo(e,t){let r=Un(e);r?e.insertBefore(t,r):e.appendChild(t)}function jn(e){let t=dr(e);if(!t)return;let r=Un(t);if(!r)return;let n=r.nextSibling;for(;n;){let a=n.nextSibling;n.nodeType===1&&t.insertBefore(n,r),n=a}}function Do(e,t={}){let r=typeof t?.onInfo=="function"?t.onInfo:()=>{},n=e.getElementsByTagNameNS(Q,"tc"),a=0;for(let i of Array.from(n)){let o=Array.from(i.childNodes||[]).filter(s=>s.nodeType===1&&s.namespaceURI===Q&&s.localName==="p");for(let s of o){let l=Array.from(s.childNodes||[]).filter(c=>c.nodeType===1&&c.namespaceURI===Q&&c.localName==="p");for(let c of l)i.insertBefore(c,s),a+=1}}return a>0&&r(`[Sanitize] Fixed ${a} nested w:p element(s) in table cells`),a}function gr(e){return e.getAttribute("pkg:name")||e.getAttribute("name")||""}function zo(e){let t=B(),r=J(),n=t.parseFromString(e,"application/xml"),a=Array.from(n.getElementsByTagNameNS("*","part")),i=a.find(u=>gr(u)==="/word/document.xml");if(!i)throw new Error("Package output missing /word/document.xml part");let o=i.getElementsByTagNameNS("*","xmlData")[0];if(!o)throw new Error("Package document part missing pkg:xmlData");let s=Array.from(o.childNodes||[]).find(u=>u.nodeType===1);if(!s)throw new Error("Package document part missing XML payload");let l=s.getElementsByTagNameNS("*","body")[0],c=l?Array.from(l.childNodes||[]).filter(u=>u.nodeType===1&&!Ct(u)):[s],f=a.find(u=>gr(u)==="/word/numbering.xml"),m=null;if(f){let u=f.getElementsByTagNameNS("*","xmlData")[0],p=u?Array.from(u.childNodes||[]).find(g=>g.nodeType===1):null;p&&(m=r.serializeToString(p))}return{replacementNodes:c,numberingXml:m,sourceType:"package"}}function Wo(e){if(typeof e!="string"||!e.trim())throw new Error("Reconciliation engine returned no OOXML payload for this operation");if(e.includes("<pkg:package"))return zo(e);if(e.includes("<w:document")){let o=B().parseFromString(e,"application/xml"),s=o.getElementsByTagNameNS("*","body")[0];return{replacementNodes:s?Array.from(s.childNodes||[]).filter(c=>c.nodeType===1&&!Ct(c)):Array.from(o.childNodes||[]).filter(c=>c.nodeType===1),numberingXml:null,sourceType:"document"}}let t=`<root xmlns:w="${Q}">${e}</root>`,n=B().parseFromString(t,"application/xml");return{replacementNodes:Array.from(n.documentElement.childNodes||[]).filter(i=>i.nodeType===1),numberingXml:null,sourceType:"fragment"}}function Gn(e,t,r){if(Array.from(e.getElementsByTagNameNS("*","Override")).some(o=>(o.getAttribute("PartName")||"").toLowerCase()===String(t).toLowerCase()))return!1;let i=e.createElementNS($o,"Override");return i.setAttribute("PartName",t),i.setAttribute("ContentType",r),e.documentElement.appendChild(i),!0}function Kn(e,t,r){let n=e.getElementsByTagNameNS("*","Relationships")[0]||e.documentElement,a=Array.from(n.getElementsByTagNameNS("*","Relationship"));if(a.some(l=>(l.getAttribute("Type")||"")===t))return!1;let o=0;for(let l of a){let c=l.getAttribute("Id")||"",f=Number.parseInt(c.replace(/^rId/i,""),10);Number.isFinite(f)&&(o=Math.max(o,f))}let s=e.createElementNS(Fo,"Relationship");return s.setAttribute("Id",`rId${o+1}`),s.setAttribute("Type",t),s.setAttribute("Target",r),n.appendChild(s),!0}async function le(e,t){let r=e.file(t);return r?r.async("string"):null}async function Ho(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{},a=typeof r?.mergeNumberingXml=="function"?r.mergeNumberingXml:null,i=(Array.isArray(t)?t:[t]).filter(Boolean);if(i.length===0)return;let o=await le(e,kt),s=o||null;for(let u of i){if(!s){s=u;continue}s=a?a(s,u):u}n(o?"[Demo] Merging numbering.xml payload(s) into existing numbering definitions":"[Demo] Adding numbering.xml"),e.file(kt,s);let l=B(),c=J(),f=await le(e,Re);if(f){let u=l.parseFromString(f,"application/xml");Gn(u,"/word/numbering.xml",zn)&&e.file(Re,c.serializeToString(u))}let m=await le(e,Me);if(m){let u=l.parseFromString(m,"application/xml");Kn(u,Dn,"numbering.xml")&&e.file(Me,c.serializeToString(u))}}async function Uo(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{};if(!t)return;let a=B(),i=J(),o=await le(e,lt);if(!o)n("[Demo] Adding comments.xml"),e.file(lt,t);else{let c=Ee(o,"word/comments.xml (existing)"),f=Ee(t,"word/comments.xml (incoming)"),m=c.documentElement,u=new Set(Array.from(m.getElementsByTagNameNS(Q,"comment")).map(p=>p.getAttribute("w:id")||p.getAttribute("id")).filter(Boolean));for(let p of Array.from(f.documentElement.getElementsByTagNameNS(Q,"comment"))){let g=p.getAttribute("w:id")||p.getAttribute("id");if(g&&u.has(g))throw new Error(`Duplicate comment id: ${g}`);m.appendChild(c.importNode(p,!0))}e.file(lt,i.serializeToString(c))}let s=await le(e,Re);if(s){let c=a.parseFromString(s,"application/xml");Gn(c,"/word/comments.xml",Hn)&&e.file(Re,i.serializeToString(c))}let l=await le(e,Me);if(l){let c=a.parseFromString(l,"application/xml");Kn(c,Wn,"comments.xml")&&e.file(Me,i.serializeToString(c))}}async function jo(e){let t=await le(e,Xn);if(!t)throw new Error("Validation failed: missing word/document.xml");let r=Ee(t,Xn);jn(r);let n=dr(r);if(!n)throw new Error("Validation failed: word/document.xml has no w:body");let a=Array.from(n.childNodes||[]).filter(d=>d.nodeType===1),i=a.map((d,w)=>({node:d,index:w})).filter(d=>Ct(d.node)).map(d=>d.index);if(i.length>1)throw new Error("Validation failed: multiple body-level w:sectPr");if(i.length===1&&i[0]!==a.length-1)throw new Error("Validation failed: w:sectPr not last");let o=r.getElementsByTagNameNS(Q,"tc");for(let d of Array.from(o))for(let w of Array.from(d.childNodes||[]).filter(h=>h.nodeType===1))if(w.namespaceURI===Q&&w.localName==="p"&&Array.from(w.childNodes||[]).some(x=>x.nodeType===1&&x.namespaceURI===Q&&x.localName==="p"))throw new Error("Validation failed: nested w:p");let s=r.getElementsByTagNameNS(Q,"numPr").length>0,l=r.getElementsByTagNameNS(Q,"commentRangeStart").length>0||r.getElementsByTagNameNS(Q,"commentRangeEnd").length>0||r.getElementsByTagNameNS(Q,"commentReference").length>0,c=await le(e,kt),f=await le(e,lt);if(c)Ee(c,kt);else if(s)throw new Error("Validation failed: numbering used but part missing");if(f)Ee(f,lt);else if(l)throw new Error("Validation failed: comments used but part missing");let m=await le(e,Re);if(!m)throw new Error(`Validation failed: missing ${Re}`);let u=Ee(m,Re),p=await le(e,Me);if(!p)throw new Error(`Validation failed: missing ${Me}`);let g=Ee(p,Me);if(c){let d=Array.from(u.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/numbering.xml"&&(h.getAttribute("ContentType")||"")===zn),w=Array.from(g.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===Dn);if(!d)throw new Error("Validation failed: numbering CT override missing");if(!w)throw new Error("Validation failed: numbering rel missing")}if(f){let d=Array.from(u.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/comments.xml"&&(h.getAttribute("ContentType")||"")===Hn),w=Array.from(g.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===Wn);if(!d)throw new Error("Validation failed: comments CT override missing");if(!w)throw new Error("Validation failed: comments rel missing")}}var Ge=Object.freeze({STRUCTURED_LIST_DIRECT:"structured_list_direct",EMPTY_FORMATTED_TEXT:"empty_formatted_text",EMPTY_HTML:"empty_html",BLOCK_HTML:"block_html",OOXML_ENGINE:"ooxml_engine"});function Zn(e){return!e||typeof e!="string"?e||"":e.replace(/\\n/g,`
191
+ `).replace(/\\t/g," ").replace(/\\r/g,"\r")}function Go(e={}){let t=e.originalText||"",r=Zn(e.newContent||""),n=rt(r)||{type:"text",items:[]};return r.includes(`
192
+ `)&&n.type!=="text"?{kind:Ge.STRUCTURED_LIST_DIRECT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!0,isOriginalEmpty:Vn(t),hasInlineFormatting:Ot(r),hasBlockElements:Rt(r),hasMarkdownTable:ct(r)}}:Vn(t)?Ot(r)?{kind:Ge.EMPTY_FORMATTED_TEXT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!0,hasBlockElements:Rt(r),hasMarkdownTable:ct(r)}}:{kind:Ge.EMPTY_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!1,hasBlockElements:Rt(r),hasMarkdownTable:ct(r)}}:Rt(r)?{kind:Ge.BLOCK_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:Ot(r),hasBlockElements:!0,hasMarkdownTable:ct(r)}}:{kind:Ge.OOXML_ENGINE,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:Ot(r),hasBlockElements:!1,hasMarkdownTable:ct(r)}}}function Vn(e){return!e||e.trim().length===0}function ct(e){if(!e||!e.includes("|"))return!1;let t=oe(e);return t.rows.length>0||t.headers.length>0}function Ot(e){return e?/(\*\*.+?\*\*|\*.+?\*|__.+?__|_.+?_|`.+?`|~~.+?~~|\+\+.+?\+\+)/.test(e):!1}function Rt(e){if(!e)return!1;let t=/^[\s]*[-*+]\s+/m.test(e),r=/^[\s]*\d+\.\s+/m.test(e),n=/^[\s]*\d+\.\d+(?:\.\d+)*\.?\s+/m.test(e),a=/^[\s]*[A-Za-z]\.\s+/m.test(e),i=/^[\s]*[ivxlcIVXLC]+\.\s+/m.test(e),o=/^[\s]*\([a-z]\)\s+/m.test(e),s=/\|.*\|.*\n/.test(e),l=/^#{1,9}\s/m.test(e),c=e.includes(`
193
+
194
+ `);return t||r||n||a||i||o||s||l||c}function Ko(e){if(!e||typeof e!="string")return null;let t=e.match(/\b(?:w14:paraId|w:paraId|paraId)="([^"]+)"/i);return t?t[1]:null}async function Yn(e,t,r,n={}){let a=await qt(e,t,r,n);if(a?.useNativeApi&&typeof a?.oxml!="string"){let i=Array.isArray(a?.warnings)?a.warnings:[];return{...a,oxml:e,hasChanges:!1,warnings:[...i,"Standalone mode cannot execute native Word API fallback for this operation."]}}return a}async function cf(e,t,r,n={}){let a=typeof e=="string"?e:"",i=typeof r=="string"?r:String(r||""),o;try{o=oe(i)}catch{o={headers:[],rows:[]}}return(o?.headers?.length||0)>0||(o?.rows?.length||0)>0?{...await Yn(a,t||"",i,n),isMarkdownTable:!0,tableData:o}:{oxml:a,hasChanges:!1,isMarkdownTable:!1,warnings:["Could not parse Markdown table from input."]}}async function uf(e,t,r,n={}){let a=n.listFallbackAllowExistingList!==!1,i=sr({oxml:e,originalText:t,modifiedText:r,allowExistingList:a}),o=n.preferListStructuralFallback!==!1,s=[];if(i&&o){let p=await Pt(i,{author:n.author,generateRedlines:n.generateRedlines,pipeline:n.listFallbackPipeline});if(p?.hasChanges&&p?.oxml){let g=Ne(p.oxml,{includeNumbering:p.includeNumbering??!0,numberingXml:p.numberingXml}),d=Array.isArray(p?.warnings)?p.warnings:[];return{oxml:g,hasChanges:!0,warnings:d,listStructuralFallbackApplied:!0,listStructuralFallbackKey:p.listStructuralFallbackKey||null,listStructuralFallbackNumberingXml:p.numberingXml||null}}s=Array.isArray(p?.warnings)?p.warnings:[]}let l=await Yn(e,t,r,n);if(!i)return{...l,warnings:[...Array.isArray(l?.warnings)?l.warnings:[],...s],listStructuralFallbackApplied:!1};if(o)return{...l,warnings:[...Array.isArray(l?.warnings)?l.warnings:[],...s],listStructuralFallbackApplied:!1};if(l?.hasChanges)return{...l,listStructuralFallbackApplied:!1};let c=await Pt(i,{author:n.author,generateRedlines:n.generateRedlines,pipeline:n.listFallbackPipeline});if(!c?.hasChanges||!c?.oxml){let p=Array.isArray(l?.warnings)?l.warnings:[],g=Array.isArray(c?.warnings)?c.warnings:[];return{...l,warnings:[...p,...g],listStructuralFallbackApplied:!1}}let f=Ne(c.oxml,{includeNumbering:c.includeNumbering??!0,numberingXml:c.numberingXml}),m=Array.isArray(l?.warnings)?l.warnings:[],u=Array.isArray(c?.warnings)?c.warnings:[];return{...l,oxml:f,hasChanges:!0,warnings:[...m,...s,...u],listStructuralFallbackApplied:!0,listStructuralFallbackKey:c.listStructuralFallbackKey||null,listStructuralFallbackNumberingXml:c.numberingXml||null}}export{Le as ContainerKind,Er as ContentType,re as DiffOp,I as NS_W,Je as NumberingService,Ce as ReconciliationPipeline,Ge as RoutePlanKind,C as RunKind,te as WORD_MAIN_NS,Mo as applyFormattingRemovalToOoxml,Bo as applyHighlightToOoxml,Yn as applyRedlineToOxml,uf as applyRedlineToOxmlWithListFallback,mr as buildCommentElement,pr as buildCommentsPartXml,go as buildExplicitDecimalMultilevelNumberingXml,Wi as buildListMarkdown,Go as buildReconciliationPlan,sr as buildSingleLineListStructuralFallbackPlan,Li as buildTargetReferenceSnapshot,Zi as clearSingleLineListFallbackExplicitSequence,Sn as collectContiguousListParagraphBlock,la as configureLogger,ia as configureXmlProvider,lo as createDynamicNumberingIdState,Yi as enforceListBindingOnParagraphNodes,Uo as ensureCommentsArtifactsInZip,Ho as ensureNumberingArtifactsInZip,ee as escapeXml,Pt as executeSingleLineListStructuralFallback,po as extractFirstParagraphNumId,Ko as extractParagraphIdFromOoxml,Wo as extractReplacementNodesFromOoxml,De as findContainingWordElement,tr as findParagraphByBestTextMatch,bn as findParagraphByReference,vt as findParagraphByStrictText,ke as generateTableOoxml,dr as getBodyElementFromDocument,G as getDefaultAuthor,ge as getDocumentParagraphNodes,gr as getPackagePartName,de as getParagraphListInfo,W as getParagraphText,Bt as getPlatform,ir as hasListItems,or as inferNumberingStyleFromMarker,oo as inferTableReplacementParagraphBlock,gt as ingestOoxml,Ao as ingestWordOoxmlToMarkdown,Io as ingestWordOoxmlToPlainText,Oo as injectCommentsIntoOoxml,Ro as injectCommentsIntoPackage,Xo as insertBodyElementBeforeSectPr,Cn as isLikelyStructuredTableSourceParagraph,nr as isMarkdownTableText,wo as mergeNumberingXmlBySchemaOrder,jn as normalizeBodySectionOrderStandalone,Zn as normalizeContentEscapesForRouting,Hi as normalizeListItemsWithLevels,L as normalizeWhitespaceForTargeting,mo as overwriteParagraphNumIds,rt as parseMarkdownListContent,pe as parseOoxml,ar as parseParagraphReference,Ee as parseXmlStrictStandalone,zi as planListInsertionOnlyEdit,q as preprocessMarkdown,cf as reconcileMarkdownTableOoxml,Vi as recordSingleLineListFallbackExplicitSequence,ho as remapNumberingPayloadForDocument,Fn as removeFormattingFromRPr,at as reserveNextNumberingId,uo as reserveNextNumberingIdPair,_i as resolveParagraphRangeByRefs,Ki as resolveSingleLineListFallbackNumberingAction,xn as resolveTargetParagraph,rr as resolveTargetParagraphWithSnapshot,wn as sanitizeAiResponse,Do as sanitizeNestedParagraphsInTables,Oe as serializeOoxml,ie as serializeToOoxml,ca as setDefaultAuthor,ua as setPlatform,Oi as splitLeadingParagraphMarker,Ci as stripLeadingParagraphMarker,En as stripRedundantLeadingListMarkers,ji as stripSingleLineListMarkerPrefix,Di as synthesizeExpandedListScopeEdit,so as synthesizeTableMarkdownFromMultilineCellEdit,jo as validateDocxPackage,Ne as wrapInDocumentFragment};
195
+ //# sourceMappingURL=docx-redline-js.esm.min.js.map