@ansonlai/docx-redline-js 0.4.0 → 0.5.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 (100) hide show
  1. package/AGENTS.md +589 -287
  2. package/ARCHITECTURE.md +215 -9
  3. package/CHANGELOG.md +319 -0
  4. package/README.md +604 -360
  5. package/adapters/config.js +45 -43
  6. package/bin/docx-redline.js +3 -0
  7. package/core/list-targeting.js +101 -110
  8. package/core/paragraph-targeting.js +501 -61
  9. package/core/paragraph-text.js +209 -0
  10. package/core/revision-cloning.js +38 -0
  11. package/core/types.js +64 -10
  12. package/core/word-xml.js +43 -15
  13. package/dist/docx-redline-js.esm.js +2849 -466
  14. package/dist/docx-redline-js.esm.js.map +4 -4
  15. package/dist/docx-redline-js.esm.min.js +87 -76
  16. package/dist/docx-redline-js.esm.min.js.map +4 -4
  17. package/docs/TESTING.md +342 -23
  18. package/docs/plans/2026-09-05-structural-revisions-and-fidelity-oracles.md +1669 -0
  19. package/docs/plans/completed/2026-09-01-performance-and-complexity-reduction.md +669 -0
  20. package/docs/plans/completed/2026-09-03-agent-friendly-document-workflows.md +427 -0
  21. package/docs/plans/completed/2026-09-04-comment-anchor-and-cli-reliability.md +519 -0
  22. package/docs/plans/completed/PERFORMANCE-CONSOLIDATION.md +69 -0
  23. package/docs/plans/completed/structural-revision-capability-matrix.md +115 -0
  24. package/docs/schemas/document-operations.schema.json +109 -0
  25. package/docs/test-comparison-dashboard.html +4250 -7
  26. package/engine/formatting-removal.js +11 -2
  27. package/engine/oxml-engine.js +491 -336
  28. package/engine/reconstruction-mode.js +15 -14
  29. package/engine/reconstruction-writer.js +247 -142
  30. package/engine/route-selection.js +35 -0
  31. package/engine/rpr-helpers.js +334 -35
  32. package/engine/run-builders.js +239 -196
  33. package/engine/surgical-diff-application.js +222 -37
  34. package/engine/surgical-mode.js +134 -6
  35. package/engine/surgical-spans.js +52 -1
  36. package/engine/table-cell-context.js +3 -6
  37. package/engine/table-mode.js +1 -1
  38. package/index.d.ts +234 -6
  39. package/index.js +24 -1
  40. package/node/cli.js +317 -0
  41. package/node/docx-document.js +302 -0
  42. package/node/index.d.ts +31 -0
  43. package/node/index.js +2 -0
  44. package/node/zip-archive.js +52 -0
  45. package/orchestration/list-markdown.js +10 -16
  46. package/orchestration/list-parsing.js +7 -12
  47. package/orchestration/list-structural-fallback.js +21 -10
  48. package/package.json +24 -3
  49. package/pipeline/content-analysis.js +12 -17
  50. package/pipeline/ingestion-export.js +3 -31
  51. package/pipeline/ingestion-paragraph.js +10 -5
  52. package/pipeline/list-generation.js +150 -55
  53. package/pipeline/list-markers.js +70 -3
  54. package/pipeline/serialization.js +4 -2
  55. package/pipeline/structured-content.js +160 -0
  56. package/scripts/apply_changes.mjs +27 -0
  57. package/scripts/benchmark-operation-session.mjs +137 -0
  58. package/scripts/benchmark-targeting-browser.html +74 -0
  59. package/scripts/benchmark-targeting-hot-paths.mjs +67 -0
  60. package/scripts/benchmark-test-runner.mjs +59 -0
  61. package/scripts/build-test-dashboard.mjs +23 -0
  62. package/scripts/export-lane1-fixtures.mjs +380 -0
  63. package/scripts/export-reredline-stress-fixtures.mjs +317 -0
  64. package/scripts/export-validation-fixtures.mjs +1 -1
  65. package/scripts/extract_text.mjs +7 -0
  66. package/scripts/generate-paragraph-boundary-fixtures.ps1 +215 -0
  67. package/scripts/generate-test-dashboard.mjs +362 -11
  68. package/scripts/lib/word-coverage-catalogue.mjs +6 -2
  69. package/scripts/profile-route-selection.mjs +19 -0
  70. package/scripts/render-agenda-multilevel.mjs +0 -5
  71. package/scripts/render-multilevel-cases.mjs +0 -1
  72. package/scripts/run-tests.mjs +107 -35
  73. package/scripts/word-com-corpus-suite.ps1 +3 -0
  74. package/scripts/word-com-differential.ps1 +64 -4
  75. package/scripts/word-com-suite.ps1 +3 -0
  76. package/services/batch-operation-orchestrator.js +494 -0
  77. package/services/capture-engine.js +226 -0
  78. package/services/comment-builders.js +23 -6
  79. package/services/comment-engine.js +108 -47
  80. package/services/comment-locator.js +187 -82
  81. package/services/comment-replies.js +95 -0
  82. package/services/document-inspection.js +258 -0
  83. package/services/document-operation-applier.js +372 -0
  84. package/services/document-operation-contract.js +323 -0
  85. package/services/document-operation-mutations.js +1733 -0
  86. package/services/document-operation-session.js +258 -0
  87. package/services/numbering-service.js +14 -5
  88. package/services/operation-heuristics.js +173 -0
  89. package/services/operation-preflight.js +366 -0
  90. package/services/receipt-collector.js +288 -0
  91. package/services/revision-comment-management.js +37 -5
  92. package/services/revision-token.js +290 -0
  93. package/services/standalone-docx-plumbing.js +123 -8
  94. package/services/standalone-operation-runner.d.ts +296 -0
  95. package/services/standalone-operation-runner.js +10 -1455
  96. package/services/table-reconciliation.js +15 -6
  97. package/docs/VALIDATION.md +0 -183
  98. package/docs/WORD-MANUAL-REVIEW.md +0 -138
  99. package/docs/plans/2026-09-01-performance-and-complexity-reduction.md +0 -210
  100. /package/docs/plans/{2026-08-30-reliability-testing-improvements.md → completed/2026-08-30-reliability-testing-improvements.md} +0 -0
@@ -1,16 +1,16 @@
1
- var Aa=Object.create;var bn=Object.defineProperty;var Ra=Object.getOwnPropertyDescriptor;var Ca=Object.getOwnPropertyNames;var Oa=Object.getPrototypeOf,ka=Object.prototype.hasOwnProperty;var Ma=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}};var La=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ca(t))!ka.call(e,o)&&o!==r&&bn(e,o,{get:()=>t[o],enumerable:!(n=Ra(t,o))||n.enumerable});return e};var xn=(e,t,r)=>(r=e!=null?Aa(Oa(e)):{},La(t||!e||!e.__esModule?bn(r,"default",{value:e,enumerable:!0}):r,e));var _r=Ma((yc,ot)=>{var T=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32},W=-1,U=1,B=0;T.Diff=function(e,t){return[e,t]};T.prototype.diff_main=function(e,t,r,n){typeof n>"u"&&(this.Diff_Timeout<=0?n=Number.MAX_VALUE:n=new Date().getTime()+this.Diff_Timeout*1e3);var o=n;if(e==null||t==null)throw new Error("Null input. (diff_main)");if(e==t)return e?[new T.Diff(B,e)]:[];typeof r>"u"&&(r=!0);var a=r,i=this.diff_commonPrefix(e,t),s=e.substring(0,i);e=e.substring(i),t=t.substring(i),i=this.diff_commonSuffix(e,t);var l=e.substring(e.length-i);e=e.substring(0,e.length-i),t=t.substring(0,t.length-i);var c=this.diff_compute_(e,t,a,o);return s&&c.unshift(new T.Diff(B,s)),l&&c.push(new T.Diff(B,l)),this.diff_cleanupMerge(c),c};T.prototype.diff_compute_=function(e,t,r,n){var o;if(!e)return[new T.Diff(U,t)];if(!t)return[new T.Diff(W,e)];var a=e.length>t.length?e:t,i=e.length>t.length?t:e,s=a.indexOf(i);if(s!=-1)return o=[new T.Diff(U,a.substring(0,s)),new T.Diff(B,i),new T.Diff(U,a.substring(s+i.length))],e.length>t.length&&(o[0][0]=o[2][0]=W),o;if(i.length==1)return[new T.Diff(W,e),new T.Diff(U,t)];var l=this.diff_halfMatch_(e,t);if(l){var c=l[0],u=l[1],f=l[2],m=l[3],p=l[4],d=this.diff_main(c,f,r,n),g=this.diff_main(u,m,r,n);return d.concat([new T.Diff(B,p)],g)}return r&&e.length>100&&t.length>100?this.diff_lineMode_(e,t,n):this.diff_bisect_(e,t,n)};T.prototype.diff_lineMode_=function(e,t,r){var n=this.diff_linesToChars_(e,t);e=n.chars1,t=n.chars2;var o=n.lineArray,a=this.diff_main(e,t,!1,r);this.diff_charsToLines_(a,o),this.diff_cleanupSemantic(a),a.push(new T.Diff(B,""));for(var i=0,s=0,l=0,c="",u="";i<a.length;){switch(a[i][0]){case U:l++,u+=a[i][1];break;case W:s++,c+=a[i][1];break;case B:if(s>=1&&l>=1){a.splice(i-s-l,s+l),i=i-s-l;for(var f=this.diff_main(c,u,!1,r),m=f.length-1;m>=0;m--)a.splice(i,0,f[m]);i=i+f.length}l=0,s=0,c="",u="";break}i++}return a.pop(),a};T.prototype.diff_bisect_=function(e,t,r){for(var n=e.length,o=t.length,a=Math.ceil((n+o)/2),i=a,s=2*a,l=new Array(s),c=new Array(s),u=0;u<s;u++)l[u]=-1,c[u]=-1;l[i+1]=0,c[i+1]=0;for(var f=n-o,m=f%2!=0,p=0,d=0,g=0,h=0,w=0;w<a&&!(new Date().getTime()>r);w++){for(var b=-w+p;b<=w-d;b+=2){var v=i+b,E;b==-w||b!=w&&l[v-1]<l[v+1]?E=l[v+1]:E=l[v-1]+1;for(var P=E-b;E<n&&P<o&&e.charAt(E)==t.charAt(P);)E++,P++;if(l[v]=E,E>n)d+=2;else if(P>o)p+=2;else if(m){var x=i+f-b;if(x>=0&&x<s&&c[x]!=-1){var N=n-c[x];if(E>=N)return this.diff_bisectSplit_(e,t,E,P,r)}}}for(var A=-w+g;A<=w-h;A+=2){var x=i+A,N;A==-w||A!=w&&c[x-1]<c[x+1]?N=c[x+1]:N=c[x-1]+1;for(var k=N-A;N<n&&k<o&&e.charAt(n-N-1)==t.charAt(o-k-1);)N++,k++;if(c[x]=N,N>n)h+=2;else if(k>o)g+=2;else if(!m){var v=i+f-A;if(v>=0&&v<s&&l[v]!=-1){var E=l[v],P=i+E-v;if(N=n-N,E>=N)return this.diff_bisectSplit_(e,t,E,P,r)}}}}return[new T.Diff(W,e),new T.Diff(U,t)]};T.prototype.diff_bisectSplit_=function(e,t,r,n,o){var a=e.substring(0,r),i=t.substring(0,n),s=e.substring(r),l=t.substring(n),c=this.diff_main(a,i,!1,o),u=this.diff_main(s,l,!1,o);return c.concat(u)};T.prototype.diff_linesToChars_=function(e,t){var r=[],n={};r[0]="";function o(l){for(var c="",u=0,f=-1,m=r.length;f<l.length-1;){f=l.indexOf(`
2
- `,u),f==-1&&(f=l.length-1);var p=l.substring(u,f+1);(n.hasOwnProperty?n.hasOwnProperty(p):n[p]!==void 0)?c+=String.fromCharCode(n[p]):(m==a&&(p=l.substring(u),f=l.length),c+=String.fromCharCode(m),n[p]=m,r[m++]=p),u=f+1}return c}var a=4e4,i=o(e);a=65535;var s=o(t);return{chars1:i,chars2:s,lineArray:r}};T.prototype.diff_charsToLines_=function(e,t){for(var r=0;r<e.length;r++){for(var n=e[r][1],o=[],a=0;a<n.length;a++)o[a]=t[n.charCodeAt(a)];e[r][1]=o.join("")}};T.prototype.diff_commonPrefix=function(e,t){if(!e||!t||e.charAt(0)!=t.charAt(0))return 0;for(var r=0,n=Math.min(e.length,t.length),o=n,a=0;r<o;)e.substring(a,o)==t.substring(a,o)?(r=o,a=r):n=o,o=Math.floor((n-r)/2+r);return o};T.prototype.diff_commonSuffix=function(e,t){if(!e||!t||e.charAt(e.length-1)!=t.charAt(t.length-1))return 0;for(var r=0,n=Math.min(e.length,t.length),o=n,a=0;r<o;)e.substring(e.length-o,e.length-a)==t.substring(t.length-o,t.length-a)?(r=o,a=r):n=o,o=Math.floor((n-r)/2+r);return o};T.prototype.diff_commonOverlap_=function(e,t){var r=e.length,n=t.length;if(r==0||n==0)return 0;r>n?e=e.substring(r-n):r<n&&(t=t.substring(0,r));var o=Math.min(r,n);if(e==t)return o;for(var a=0,i=1;;){var s=e.substring(o-i),l=t.indexOf(s);if(l==-1)return a;i+=l,(l==0||e.substring(o-i)==t.substring(0,i))&&(a=i,i++)}};T.prototype.diff_halfMatch_=function(e,t){if(this.Diff_Timeout<=0)return null;var r=e.length>t.length?e:t,n=e.length>t.length?t:e;if(r.length<4||n.length*2<r.length)return null;var o=this;function a(d,g,h){for(var w=d.substring(h,h+Math.floor(d.length/4)),b=-1,v="",E,P,x,N;(b=g.indexOf(w,b+1))!=-1;){var A=o.diff_commonPrefix(d.substring(h),g.substring(b)),k=o.diff_commonSuffix(d.substring(0,h),g.substring(0,b));v.length<k+A&&(v=g.substring(b-k,b)+g.substring(b,b+A),E=d.substring(0,h-k),P=d.substring(h+A),x=g.substring(0,b-k),N=g.substring(b+A))}return v.length*2>=d.length?[E,P,x,N,v]:null}var i=a(r,n,Math.ceil(r.length/4)),s=a(r,n,Math.ceil(r.length/2)),l;if(!i&&!s)return null;s?i?l=i[4].length>s[4].length?i:s:l=s:l=i;var c,u,f,m;e.length>t.length?(c=l[0],u=l[1],f=l[2],m=l[3]):(f=l[0],m=l[1],c=l[2],u=l[3]);var p=l[4];return[c,u,f,m,p]};T.prototype.diff_cleanupSemantic=function(e){for(var t=!1,r=[],n=0,o=null,a=0,i=0,s=0,l=0,c=0;a<e.length;)e[a][0]==B?(r[n++]=a,i=l,s=c,l=0,c=0,o=e[a][1]):(e[a][0]==U?l+=e[a][1].length:c+=e[a][1].length,o&&o.length<=Math.max(i,s)&&o.length<=Math.max(l,c)&&(e.splice(r[n-1],0,new T.Diff(W,o)),e[r[n-1]+1][0]=U,n--,n--,a=n>0?r[n-1]:-1,i=0,s=0,l=0,c=0,o=null,t=!0)),a++;for(t&&this.diff_cleanupMerge(e),this.diff_cleanupSemanticLossless(e),a=1;a<e.length;){if(e[a-1][0]==W&&e[a][0]==U){var u=e[a-1][1],f=e[a][1],m=this.diff_commonOverlap_(u,f),p=this.diff_commonOverlap_(f,u);m>=p?(m>=u.length/2||m>=f.length/2)&&(e.splice(a,0,new T.Diff(B,f.substring(0,m))),e[a-1][1]=u.substring(0,u.length-m),e[a+1][1]=f.substring(m),a++):(p>=u.length/2||p>=f.length/2)&&(e.splice(a,0,new T.Diff(B,u.substring(0,p))),e[a-1][0]=U,e[a-1][1]=f.substring(0,f.length-p),e[a+1][0]=W,e[a+1][1]=u.substring(p),a++),a++}a++}};T.prototype.diff_cleanupSemanticLossless=function(e){function t(p,d){if(!p||!d)return 6;var g=p.charAt(p.length-1),h=d.charAt(0),w=g.match(T.nonAlphaNumericRegex_),b=h.match(T.nonAlphaNumericRegex_),v=w&&g.match(T.whitespaceRegex_),E=b&&h.match(T.whitespaceRegex_),P=v&&g.match(T.linebreakRegex_),x=E&&h.match(T.linebreakRegex_),N=P&&p.match(T.blanklineEndRegex_),A=x&&d.match(T.blanklineStartRegex_);return N||A?5:P||x?4:w&&!v&&E?3:v||E?2:w||b?1:0}for(var r=1;r<e.length-1;){if(e[r-1][0]==B&&e[r+1][0]==B){var n=e[r-1][1],o=e[r][1],a=e[r+1][1],i=this.diff_commonSuffix(n,o);if(i){var s=o.substring(o.length-i);n=n.substring(0,n.length-i),o=s+o.substring(0,o.length-i),a=s+a}for(var l=n,c=o,u=a,f=t(n,o)+t(o,a);o.charAt(0)===a.charAt(0);){n+=o.charAt(0),o=o.substring(1)+a.charAt(0),a=a.substring(1);var m=t(n,o)+t(o,a);m>=f&&(f=m,l=n,c=o,u=a)}e[r-1][1]!=l&&(l?e[r-1][1]=l:(e.splice(r-1,1),r--),e[r][1]=c,u?e[r+1][1]=u:(e.splice(r+1,1),r--))}r++}};T.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/;T.whitespaceRegex_=/\s/;T.linebreakRegex_=/[\r\n]/;T.blanklineEndRegex_=/\n\r?\n$/;T.blanklineStartRegex_=/^\r?\n\r?\n/;T.prototype.diff_cleanupEfficiency=function(e){for(var t=!1,r=[],n=0,o=null,a=0,i=!1,s=!1,l=!1,c=!1;a<e.length;)e[a][0]==B?(e[a][1].length<this.Diff_EditCost&&(l||c)?(r[n++]=a,i=l,s=c,o=e[a][1]):(n=0,o=null),l=c=!1):(e[a][0]==W?c=!0:l=!0,o&&(i&&s&&l&&c||o.length<this.Diff_EditCost/2&&i+s+l+c==3)&&(e.splice(r[n-1],0,new T.Diff(W,o)),e[r[n-1]+1][0]=U,n--,o=null,i&&s?(l=c=!0,n=0):(n--,a=n>0?r[n-1]:-1,l=c=!1),t=!0)),a++;t&&this.diff_cleanupMerge(e)};T.prototype.diff_cleanupMerge=function(e){e.push(new T.Diff(B,""));for(var t=0,r=0,n=0,o="",a="",i;t<e.length;)switch(e[t][0]){case U:n++,a+=e[t][1],t++;break;case W:r++,o+=e[t][1],t++;break;case B:r+n>1?(r!==0&&n!==0&&(i=this.diff_commonPrefix(a,o),i!==0&&(t-r-n>0&&e[t-r-n-1][0]==B?e[t-r-n-1][1]+=a.substring(0,i):(e.splice(0,0,new T.Diff(B,a.substring(0,i))),t++),a=a.substring(i),o=o.substring(i)),i=this.diff_commonSuffix(a,o),i!==0&&(e[t][1]=a.substring(a.length-i)+e[t][1],a=a.substring(0,a.length-i),o=o.substring(0,o.length-i))),t-=r+n,e.splice(t,r+n),o.length&&(e.splice(t,0,new T.Diff(W,o)),t++),a.length&&(e.splice(t,0,new T.Diff(U,a)),t++),t++):t!==0&&e[t-1][0]==B?(e[t-1][1]+=e[t][1],e.splice(t,1)):t++,n=0,r=0,o="",a="";break}e[e.length-1][1]===""&&e.pop();var s=!1;for(t=1;t<e.length-1;)e[t-1][0]==B&&e[t+1][0]==B&&(e[t][1].substring(e[t][1].length-e[t-1][1].length)==e[t-1][1]?(e[t][1]=e[t-1][1]+e[t][1].substring(0,e[t][1].length-e[t-1][1].length),e[t+1][1]=e[t-1][1]+e[t+1][1],e.splice(t-1,1),s=!0):e[t][1].substring(0,e[t+1][1].length)==e[t+1][1]&&(e[t-1][1]+=e[t+1][1],e[t][1]=e[t][1].substring(e[t+1][1].length)+e[t+1][1],e.splice(t+1,1),s=!0)),t++;s&&this.diff_cleanupMerge(e)};T.prototype.diff_xIndex=function(e,t){var r=0,n=0,o=0,a=0,i;for(i=0;i<e.length&&(e[i][0]!==U&&(r+=e[i][1].length),e[i][0]!==W&&(n+=e[i][1].length),!(r>t));i++)o=r,a=n;return e.length!=i&&e[i][0]===W?a:a+(t-o)};T.prototype.diff_prettyHtml=function(e){for(var t=[],r=/&/g,n=/</g,o=/>/g,a=/\n/g,i=0;i<e.length;i++){var s=e[i][0],l=e[i][1],c=l.replace(r,"&amp;").replace(n,"&lt;").replace(o,"&gt;").replace(a,"&para;<br>");switch(s){case U:t[i]='<ins style="background:#e6ffe6;">'+c+"</ins>";break;case W:t[i]='<del style="background:#ffe6e6;">'+c+"</del>";break;case B:t[i]="<span>"+c+"</span>";break}}return t.join("")};T.prototype.diff_text1=function(e){for(var t=[],r=0;r<e.length;r++)e[r][0]!==U&&(t[r]=e[r][1]);return t.join("")};T.prototype.diff_text2=function(e){for(var t=[],r=0;r<e.length;r++)e[r][0]!==W&&(t[r]=e[r][1]);return t.join("")};T.prototype.diff_levenshtein=function(e){for(var t=0,r=0,n=0,o=0;o<e.length;o++){var a=e[o][0],i=e[o][1];switch(a){case U:r+=i.length;break;case W:n+=i.length;break;case B:t+=Math.max(r,n),r=0,n=0;break}}return t+=Math.max(r,n),t};T.prototype.diff_toDelta=function(e){for(var t=[],r=0;r<e.length;r++)switch(e[r][0]){case U:t[r]="+"+encodeURI(e[r][1]);break;case W:t[r]="-"+e[r][1].length;break;case B:t[r]="="+e[r][1].length;break}return t.join(" ").replace(/%20/g," ")};T.prototype.diff_fromDelta=function(e,t){for(var r=[],n=0,o=0,a=t.split(/\t/g),i=0;i<a.length;i++){var s=a[i].substring(1);switch(a[i].charAt(0)){case"+":try{r[n++]=new T.Diff(U,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(o,o+=l);a[i].charAt(0)=="="?r[n++]=new T.Diff(B,c):r[n++]=new T.Diff(W,c);break;default:if(a[i])throw new Error("Invalid diff operation in diff_fromDelta: "+a[i])}}if(o!=e.length)throw new Error("Delta length ("+o+") does not equal source text length ("+e.length+").");return r};T.prototype.match_main=function(e,t,r){if(e==null||t==null||r==null)throw new Error("Null input. (match_main)");return r=Math.max(0,Math.min(r,e.length)),e==t?0:e.length?e.substring(r,r+t.length)==t?r:this.match_bitap_(e,t,r):-1};T.prototype.match_bitap_=function(e,t,r){if(t.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var n=this.match_alphabet_(t),o=this;function a(E,P){var x=E/t.length,N=Math.abs(r-P);return o.Match_Distance?x+N/o.Match_Distance:N?1:x}var i=this.Match_Threshold,s=e.indexOf(t,r);s!=-1&&(i=Math.min(a(0,s),i),s=e.lastIndexOf(t,r+t.length),s!=-1&&(i=Math.min(a(0,s),i)));var l=1<<t.length-1;s=-1;for(var c,u,f=t.length+e.length,m,p=0;p<t.length;p++){for(c=0,u=f;c<u;)a(p,r+u)<=i?c=u:f=u,u=Math.floor((f-c)/2+c);f=u;var d=Math.max(1,r-u+1),g=Math.min(r+u,e.length)+t.length,h=Array(g+2);h[g+1]=(1<<p)-1;for(var w=g;w>=d;w--){var b=n[e.charAt(w-1)];if(p===0?h[w]=(h[w+1]<<1|1)&b:h[w]=(h[w+1]<<1|1)&b|((m[w+1]|m[w])<<1|1)|m[w+1],h[w]&l){var v=a(p,w-1);if(v<=i)if(i=v,s=w-1,s>r)d=Math.max(1,2*r-s);else break}}if(a(p+1,r)>i)break;m=h}return s};T.prototype.match_alphabet_=function(e){for(var t={},r=0;r<e.length;r++)t[e.charAt(r)]=0;for(var r=0;r<e.length;r++)t[e.charAt(r)]|=1<<e.length-r-1;return t};T.prototype.patch_addContext_=function(e,t){if(t.length!=0){if(e.start2===null)throw Error("patch not initialized");for(var r=t.substring(e.start2,e.start2+e.length1),n=0;t.indexOf(r)!=t.lastIndexOf(r)&&r.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)n+=this.Patch_Margin,r=t.substring(e.start2-n,e.start2+e.length1+n);n+=this.Patch_Margin;var o=t.substring(e.start2-n,e.start2);o&&e.diffs.unshift(new T.Diff(B,o));var a=t.substring(e.start2+e.length1,e.start2+e.length1+n);a&&e.diffs.push(new T.Diff(B,a)),e.start1-=o.length,e.start2-=o.length,e.length1+=o.length+a.length,e.length2+=o.length+a.length}};T.prototype.patch_make=function(e,t,r){var n,o;if(typeof e=="string"&&typeof t=="string"&&typeof r>"u")n=e,o=this.diff_main(n,t,!0),o.length>2&&(this.diff_cleanupSemantic(o),this.diff_cleanupEfficiency(o));else if(e&&typeof e=="object"&&typeof t>"u"&&typeof r>"u")o=e,n=this.diff_text1(o);else if(typeof e=="string"&&t&&typeof t=="object"&&typeof r>"u")n=e,o=t;else if(typeof e=="string"&&typeof t=="string"&&r&&typeof r=="object")n=e,o=r;else throw new Error("Unknown call format to patch_make.");if(o.length===0)return[];for(var a=[],i=new T.patch_obj,s=0,l=0,c=0,u=n,f=n,m=0;m<o.length;m++){var p=o[m][0],d=o[m][1];switch(!s&&p!==B&&(i.start1=l,i.start2=c),p){case U:i.diffs[s++]=o[m],i.length2+=d.length,f=f.substring(0,c)+d+f.substring(c);break;case W:i.length1+=d.length,i.diffs[s++]=o[m],f=f.substring(0,c)+f.substring(c+d.length);break;case B:d.length<=2*this.Patch_Margin&&s&&o.length!=m+1?(i.diffs[s++]=o[m],i.length1+=d.length,i.length2+=d.length):d.length>=2*this.Patch_Margin&&s&&(this.patch_addContext_(i,u),a.push(i),i=new T.patch_obj,s=0,u=f,l=c);break}p!==U&&(l+=d.length),p!==W&&(c+=d.length)}return s&&(this.patch_addContext_(i,u),a.push(i)),a};T.prototype.patch_deepCopy=function(e){for(var t=[],r=0;r<e.length;r++){var n=e[r],o=new T.patch_obj;o.diffs=[];for(var a=0;a<n.diffs.length;a++)o.diffs[a]=new T.Diff(n.diffs[a][0],n.diffs[a][1]);o.start1=n.start1,o.start2=n.start2,o.length1=n.length1,o.length2=n.length2,t[r]=o}return t};T.prototype.patch_apply=function(e,t){if(e.length==0)return[t,[]];e=this.patch_deepCopy(e);var r=this.patch_addPadding(e);t=r+t+r,this.patch_splitMax(e);for(var n=0,o=[],a=0;a<e.length;a++){var i=e[a].start2+n,s=this.diff_text1(e[a].diffs),l,c=-1;if(s.length>this.Match_MaxBits?(l=this.match_main(t,s.substring(0,this.Match_MaxBits),i),l!=-1&&(c=this.match_main(t,s.substring(s.length-this.Match_MaxBits),i+s.length-this.Match_MaxBits),(c==-1||l>=c)&&(l=-1))):l=this.match_main(t,s,i),l==-1)o[a]=!1,n-=e[a].length2-e[a].length1;else{o[a]=!0,n=l-i;var u;if(c==-1?u=t.substring(l,l+s.length):u=t.substring(l,c+this.Match_MaxBits),s==u)t=t.substring(0,l)+this.diff_text2(e[a].diffs)+t.substring(l+s.length);else{var f=this.diff_main(s,u,!1);if(s.length>this.Match_MaxBits&&this.diff_levenshtein(f)/s.length>this.Patch_DeleteThreshold)o[a]=!1;else{this.diff_cleanupSemanticLossless(f);for(var m=0,p,d=0;d<e[a].diffs.length;d++){var g=e[a].diffs[d];g[0]!==B&&(p=this.diff_xIndex(f,m)),g[0]===U?t=t.substring(0,l+p)+g[1]+t.substring(l+p):g[0]===W&&(t=t.substring(0,l+p)+t.substring(l+this.diff_xIndex(f,m+g[1].length))),g[0]!==W&&(m+=g[1].length)}}}}}return t=t.substring(r.length,t.length-r.length),[t,o]};T.prototype.patch_addPadding=function(e){for(var t=this.Patch_Margin,r="",n=1;n<=t;n++)r+=String.fromCharCode(n);for(var n=0;n<e.length;n++)e[n].start1+=t,e[n].start2+=t;var o=e[0],a=o.diffs;if(a.length==0||a[0][0]!=B)a.unshift(new T.Diff(B,r)),o.start1-=t,o.start2-=t,o.length1+=t,o.length2+=t;else if(t>a[0][1].length){var i=t-a[0][1].length;a[0][1]=r.substring(a[0][1].length)+a[0][1],o.start1-=i,o.start2-=i,o.length1+=i,o.length2+=i}if(o=e[e.length-1],a=o.diffs,a.length==0||a[a.length-1][0]!=B)a.push(new T.Diff(B,r)),o.length1+=t,o.length2+=t;else if(t>a[a.length-1][1].length){var i=t-a[a.length-1][1].length;a[a.length-1][1]+=r.substring(0,i),o.length1+=i,o.length2+=i}return r};T.prototype.patch_splitMax=function(e){for(var t=this.Match_MaxBits,r=0;r<e.length;r++)if(!(e[r].length1<=t)){var n=e[r];e.splice(r--,1);for(var o=n.start1,a=n.start2,i="";n.diffs.length!==0;){var s=new T.patch_obj,l=!0;for(s.start1=o-i.length,s.start2=a-i.length,i!==""&&(s.length1=s.length2=i.length,s.diffs.push(new T.Diff(B,i)));n.diffs.length!==0&&s.length1<t-this.Patch_Margin;){var c=n.diffs[0][0],u=n.diffs[0][1];c===U?(s.length2+=u.length,a+=u.length,s.diffs.push(n.diffs.shift()),l=!1):c===W&&s.diffs.length==1&&s.diffs[0][0]==B&&u.length>2*t?(s.length1+=u.length,o+=u.length,l=!1,s.diffs.push(new T.Diff(c,u)),n.diffs.shift()):(u=u.substring(0,t-s.length1-this.Patch_Margin),s.length1+=u.length,o+=u.length,c===B?(s.length2+=u.length,a+=u.length):l=!1,s.diffs.push(new T.Diff(c,u)),u==n.diffs[0][1]?n.diffs.shift():n.diffs[0][1]=n.diffs[0][1].substring(u.length))}i=this.diff_text2(s.diffs),i=i.substring(i.length-this.Patch_Margin);var f=this.diff_text1(n.diffs).substring(0,this.Patch_Margin);f!==""&&(s.length1+=f.length,s.length2+=f.length,s.diffs.length!==0&&s.diffs[s.diffs.length-1][0]===B?s.diffs[s.diffs.length-1][1]+=f:s.diffs.push(new T.Diff(B,f))),l||e.splice(++r,0,s)}}};T.prototype.patch_toText=function(e){for(var t=[],r=0;r<e.length;r++)t[r]=e[r];return t.join("")};T.prototype.patch_fromText=function(e){var t=[];if(!e)return t;for(var r=e.split(`
3
- `),n=0,o=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;n<r.length;){var a=r[n].match(o);if(!a)throw new Error("Invalid patch string: "+r[n]);var i=new T.patch_obj;for(t.push(i),i.start1=parseInt(a[1],10),a[2]===""?(i.start1--,i.length1=1):a[2]=="0"?i.length1=0:(i.start1--,i.length1=parseInt(a[2],10)),i.start2=parseInt(a[3],10),a[4]===""?(i.start2--,i.length2=1):a[4]=="0"?i.length2=0:(i.start2--,i.length2=parseInt(a[4],10)),n++;n<r.length;){var s=r[n].charAt(0);try{var l=decodeURI(r[n].substring(1))}catch{throw new Error("Illegal escape in patch_fromText: "+l)}if(s=="-")i.diffs.push(new T.Diff(W,l));else if(s=="+")i.diffs.push(new T.Diff(U,l));else if(s==" ")i.diffs.push(new T.Diff(B,l));else{if(s=="@")break;if(s!=="")throw new Error('Invalid patch mode "'+s+'" in: '+l)}n++}}return t};T.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0};T.patch_obj.prototype.toString=function(){var e,t;this.length1===0?e=this.start1+",0":this.length1==1?e=this.start1+1:e=this.start1+1+","+this.length1,this.length2===0?t=this.start2+",0":this.length2==1?t=this.start2+1:t=this.start2+1+","+this.length2;for(var r=["@@ -"+e+" +"+t+` @@
4
- `],n,o=0;o<this.diffs.length;o++){switch(this.diffs[o][0]){case U:n="+";break;case W:n="-";break;case B:n=" ";break}r[o+1]=n+encodeURI(this.diffs[o][1])+`
5
- `}return r.join("").replace(/%20/g," ")};ot.exports=T;ot.exports.diff_match_patch=T;ot.exports.DIFF_DELETE=W;ot.exports.DIFF_INSERT=U;ot.exports.DIFF_EQUAL=B});var Xt=console,Nr=Object.freeze({silent:0,error:1,warn:2,info:3}),_a=typeof process<"u"&&process?.env?.NODE_ENV==="production"?"warn":"info",vr=_a;function Ba(e){let t=String(e||"").toLowerCase();return Object.prototype.hasOwnProperty.call(Nr,t)?t:vr}function Tr(e){return Nr[vr]>=Nr[e]}function Fa(e,t={}){Xt=e||console,t.level&&(vr=Ba(t.level))}function I(...e){Tr("info")&&(Xt.log||(()=>{}))(...e)}function Se(...e){Tr("warn")&&(Xt.warn||(()=>{}))(...e)}function G(...e){Tr("error")&&(Xt.error||(()=>{}))(...e)}var bt=globalThis.DOMParser,xt=globalThis.XMLSerializer;function $a(e={}){e.DOMParser&&(bt=e.DOMParser),e.XMLSerializer&&(xt=e.XMLSerializer)}function Xa(e={}){if(!bt&&globalThis.DOMParser&&(bt=globalThis.DOMParser),!bt)throw new Error("DOMParser is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new bt(e)}function ae(){if(!xt&&globalThis.XMLSerializer&&(xt=globalThis.XMLSerializer),!xt)throw new Error("XMLSerializer is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new xt}function Nn(e,t="text/xml"){let r=D(e,t);if(r.error){let n=new Error(r.error.message);throw n.code=r.error.code,n}return r.doc}function Da(e){return e?.documentElement?String(e.documentElement.localName||e.documentElement.nodeName).toLowerCase()==="parsererror"?e.documentElement:e.getElementsByTagName?.("parsererror")?.[0]||null:null}function D(e,t="application/xml"){let r=[];if(typeof e!="string"||e.trim()==="")return{doc:null,error:{code:"PARSE_ERROR",message:"Input is not a non-empty XML string."},warnings:r};let n=(o,a)=>{let i=String(a||"XML parser diagnostic.");o==="fatalError"?G("[XmlAdapter] XML fatal parse error:",i):(r.push(i),Se(`[XmlAdapter] XML ${o||"warning"}:`,i))};try{let a=Xa({onError:n}).parseFromString(e,t),i=Da(a);if(!a?.documentElement||i){let s=i?.textContent||"Could not parse XML input.";return G("[XmlAdapter] XML parse error:",s),{doc:null,error:{code:"PARSE_ERROR",message:s},warnings:r}}return{doc:a,error:null,warnings:r}}catch(o){let a=o?.message||String(o||"Could not parse XML input.");return G("[XmlAdapter] XML parse error:",a),{doc:null,error:{code:"PARSE_ERROR",message:a},warnings:r}}}function Q(e){return ae().serializeToString(e)}var vn="Author",Tn="Unknown";function za(e){vn=typeof e=="string"&&e.trim()?e.trim():"Author"}function re(){return vn}function Wa(e){Tn=typeof e=="string"&&e.trim()?e.trim():"Unknown"}function Er(){return Tn}var Ua=[{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 le(e){if(!e)return{cleanText:"",formatHints:[]};let t=[],r="",n=[];for(let s of Ua){let l,c=s.regex.source||s.regex.toString().replace(/^\/|\/[gimuy]*$/g,""),u="g"+(s.regex.ignoreCase?"i":""),f=new RegExp(c,u);for(;(l=f.exec(e))!==null;)n.push({start:l.index,end:l.index+l[0].length,fullMatch:l[0],innerText:s.isEscaped?Ha(l[1]):l[1],format:s.format}),l.index===f.lastIndex&&f.lastIndex++}n.sort((s,l)=>s.start-l.start||l.end-s.end);let o=[],a=0;for(let s of n)s.start>=a&&(o.push(s),a=s.end);let i=0;for(let s of o){r+=e.slice(i,s.start);let l=le(s.innerText),c=r.length;r+=l.cleanText;let u=r.length;t.push({start:c,end:u,format:s.format});for(let f of l.formatHints)t.push({start:c+f.start,end:c+f.end,format:f.format});i=s.end}return r+=e.slice(i),{cleanText:r,formatHints:t}}function Ie(e,t,r){return e.filter(n=>n.start<r&&n.end>t)}function yr(...e){let t={};for(let r of e)r&&Object.assign(t,r);return t}function Ha(e){return e?e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#039;/g,"'"):""}var Dt=String.raw`(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|\d+\.|[ivxlcIVXLC]+\.|[-*\u2022])`,En=new RegExp(`^(\\s*)((?:${Dt})\\s+)`),yn=new RegExp(`^(\\s*)((?:${Dt})\\s*)`),ja=new RegExp(`^(\\s*)((?:${Dt})\\s+)`,"m"),Ga=new RegExp(`^(\\s*)((?:${Dt})\\s*)`,"m");function Pr(e){return typeof e!="string"?!1:e.includes(`
6
- `)&&ja.test(e)}function Nt(e){return typeof e!="string"?!1:e.includes(`
7
- `)&&Ga.test(e.trim())}function Ae(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?yn:En;return e.match(n)}function _e(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?yn:En;return e.replace(n,"")}var y="http://schemas.openxmlformats.org/wordprocessingml/2006/main";var we=Object.freeze({EQUAL:"equal",DELETE:"delete",INSERT:"insert"}),_=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"}),et=Object.freeze({SDT:"sdt",SMART_TAG:"smartTag",CUSTOM_XML:"customXml",FIELD_COMPLEX:"fldComplex"}),In=Object.freeze({PARAGRAPH:"paragraph",BULLET_LIST:"bullet_list",NUMBERED_LIST:"numbered_list",TABLE:"table"}),z=Object.freeze({DECIMAL:"decimal",LOWER_ALPHA:"lowerLetter",UPPER_ALPHA:"upperLetter",LOWER_ROMAN:"lowerRoman",UPPER_ROMAN:"upperRoman",BULLET:"bullet",OUTLINE:"outline"}),ne=Object.freeze({PERIOD:"period",PAREN_RIGHT:"parenRight",PAREN_BOTH:"parenBoth",NONE:"none"});function pe(e){return e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;"):""}var Sr=1e3,Pn=2147483647,Sn=1e4,Va=new Set(["ins","del","moveFrom","moveTo","rPrChange","pPrChange","cellIns","cellDel","comment"]),An=new WeakMap;function Ka(e){if(!e||e.nodeType!==1)return!1;let t=String(e.localName||e.nodeName||"").replace(/^.*:/,"");return Va.has(t)?!e.namespaceURI||e.namespaceURI===y||String(e.nodeName||"").startsWith("w:"):!1}function Ya(e){let t=e?.getAttributeNS?.(y,"id")||e?.getAttribute?.("w:id")||e?.getAttribute?.("id"),r=Number.parseInt(String(t??""),10);return Number.isInteger(r)&&r>=0?r:null}var he=class{constructor(t=Sr){this.startValue=Number.isInteger(t)&&t>=0?t:Sr,this.nextId=this.startValue,this.occupiedIds=new Set}seed(t){let r=-1,n=Array.from(t?.getElementsByTagName?.("*")||[]);t?.nodeType===1&&n.unshift(t);for(let a of n){if(!Ka(a))continue;let i=Ya(a);i!=null&&(this.occupiedIds.add(i),r=Math.max(r,i))}let o=Pn-Sn;return this.nextId=r>=o?this.startValue:Math.max(this.nextId,r+1),this.advanceToAvailableId(),this.nextId}advanceToAvailableId(){let t=Pn-Sn;for(this.nextId>=t&&(this.nextId=this.startValue);this.occupiedIds.has(this.nextId);)this.nextId+=1,this.nextId>=t&&(this.nextId=this.startValue)}next(){this.advanceToAvailableId();let t=this.nextId;return this.occupiedIds.add(t),this.nextId+=1,t}},zt=new he;function Wt(e,t){let r=e?.nodeType===9?e:e?.ownerDocument;return r&&t instanceof he&&An.set(r,t),t}function Ut(e){let t=e?.nodeType===9?e:e?.ownerDocument;return t&&An.get(t)||null}function Rn(e,t=Sr){let r=new he(t);return r.seed(e),Wt(e,r),r}function Cn(){return zt.next()}function Ir(e=new Date){return e.toISOString()}function ie(e,t=null){let r=typeof e=="string"&&e.trim()?e.trim():re();return{id:(t instanceof he?t:Ut(t)||zt).next(),author:r,date:Ir()}}function vt(e,t=zt){let r=t instanceof he?t:zt,n=r.seed(e);return Wt(e,r),n}function On(e,t){return e<t-1}function tt(e,t,r){return On(t,r)?e+`
8
- `:e}function Ue(e,t,r){return On(t,r)?e+1:e}function rt(e,t){return!e||typeof e.getElementsByTagName!="function"?[]:Array.from(e.getElementsByTagName(t))}function V(e,t){if(!e||typeof e.getElementsByTagName!="function")return null;let r=e.getElementsByTagName(t);return r.length>0?r[0]:null}function J(e,t,r){return!e||typeof e.getElementsByTagNameNS!="function"?[]:Array.from(e.getElementsByTagNameNS(t,r))}function H(e,t,r){if(!e||typeof e.getElementsByTagNameNS!="function")return null;let n=e.getElementsByTagNameNS(t,r);return n.length>0?n[0]:null}function ce(e,t,r,n=`w:${r}`){let o=J(e,t,r);return o.length>0?o:rt(e,n)}function be(e,t,r,n=`w:${r}`){let o=H(e,t,r);return o||V(e,n)}function K(e){return V(e,"parsererror")}function Ar(e){return Array.from(e?.childNodes||[])}function kn(e){return Array.from(e.attributes).map(t=>`${t.name}="${t.value}"`).join(" ")}function Rr(e,t,r=""){return!e||e.namespaceURI!==t?!1:r?e.localName===r:!0}var Cr=0;function Ht(e,t={}){let r=[],n="",o=t.xmlDoc||null;if(!e&&!o)return{runModel:r,acceptedText:n,pPr:null};try{let a=o?{doc:o,error:null}:D(e,"application/xml"),i=a.doc;if(a.error||!i)return G("OOXML parse error:",a.error?.message),{runModel:r,acceptedText:n,pPr:null,error:a.error};let s=K(i);if(s)return G("OOXML parse error:",s.textContent),{runModel:r,acceptedText:n,pPr:null};let l=J(i,y,"p");return l.length===0?(Se("No paragraphs found in OOXML"),{runModel:r,acceptedText:n,pPr:null}):Ln(l,{includeParagraphBoundaries:!0})}catch(a){return G("Error ingesting OOXML:",a),{runModel:r,acceptedText:n,pPr:null}}}function Or(e){return e?Ln([e],{includeParagraphBoundaries:!1}):{runModel:[],acceptedText:"",pPr:null}}function kr(e){let t=H(e,y,"pPr");if(!t)return null;let r=H(t,y,"numPr");if(!r)return null;let n=H(r,y,"numId"),o=H(r,y,"ilvl");if(!n)return null;let a=n.getAttribute("w:val"),i=a==="1"?"bullet":a==="2"?"numbered":"unknown";return{numId:a,ilvl:parseInt(o?.getAttribute("w:val")||"0",10),type:i}}function Ln(e,t={}){let r=t.includeParagraphBoundaries??!0,n=[],o="",a=0,i=null;for(let s=0;s<e.length;s++){let l=e[s],c=H(l,y,"pPr");s===0&&(i=c),n.push({kind:_.PARAGRAPH_START,pPrElement:c||null,startOffset:a,endOffset:a,text:""});let u=nt(l,a,n);o+=u.text,a=o.length,r&&(o=tt(o,s,e.length),a=Ue(a,s,e.length))}return{runModel:n,acceptedText:o,pPr:i}}function nt(e,t,r){let n=t,o="",a=Za(r);for(let i of Ar(e)){if(Rr(i,y,"pPr")||Rr(i,y,"proofErr"))continue;let s=a.get(i.localName);if(!s)continue;let l=s(i,n);n=l.offset,o+=l.text}return{offset:n,text:o}}function Za(e){let t=new Map;t.set("sdt",(r,n)=>{let o=`sdt_${Cr++}`,a=H(r,y,"sdtPr"),i=H(r,y,"sdtContent");e.push({kind:_.CONTAINER_START,containerKind:et.SDT,containerId:o,propertiesXml:a?Q(a):"",startOffset:n,endOffset:n,text:""});let s=i?nt(i,n,e):{offset:n,text:""};return e.push({kind:_.CONTAINER_END,containerKind:et.SDT,containerId:o,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("smartTag",(r,n)=>{let o=`smartTag_${Cr++}`;e.push({kind:_.CONTAINER_START,containerKind:et.SMART_TAG,containerId:o,propertiesXml:kn(r),startOffset:n,endOffset:n,text:""});let a=nt(r,n,e);return e.push({kind:_.CONTAINER_END,containerKind:et.SMART_TAG,containerId:o,startOffset:a.offset,endOffset:a.offset,text:""}),a}),t.set("del",(r,n)=>{let o=Mn(r,n);return o&&e.push(o),{offset:n,text:""}}),t.set("moveFrom",(r,n)=>{let o=Mn(r,n);return o&&e.push(o),{offset:n,text:""}}),t.set("moveTo",(r,n)=>nt(r,n,e));for(let r of["moveFromRangeStart","moveFromRangeEnd","moveToRangeStart","moveToRangeEnd"])t.set(r,(n,o)=>(e.push({kind:_.BOOKMARK,nodeXml:Q(n),startOffset:o,endOffset:o,text:""}),{offset:o,text:""}));return t.set("bookmarkStart",(r,n)=>(e.push({kind:_.BOOKMARK,nodeXml:Q(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("bookmarkEnd",(r,n)=>(e.push({kind:_.BOOKMARK,nodeXml:Q(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("ins",(r,n)=>nt(r,n,e)),t.set("hyperlink",(r,n)=>{let o=`hyperlink_${Cr++}`,a=r.getAttribute("r:id")||"",i=r.getAttribute("w:anchor")||"";e.push({kind:_.CONTAINER_START,containerKind:"hyperlink",containerId:o,propertiesXml:JSON.stringify({rId:a,anchor:i}),startOffset:n,endOffset:n,text:""});let s=nt(r,n,e);return e.push({kind:_.CONTAINER_END,containerKind:"hyperlink",containerId:o,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("r",(r,n)=>{let o=Ja(r,n);return!o||!o.text?{offset:n,text:""}:(e.push(o),{offset:n+o.text.length,text:o.text})}),t}function Ja(e,t){let r=be(e,y,"rPr"),n=r?Q(r):"",o="";for(let a of Ar(e)){let i=a.nodeName;i.endsWith(":t")||i==="t"?o+=a.textContent||"":i.endsWith(":br")||i==="br"||i.endsWith(":cr")||i==="cr"?o+=`
9
- `:i.endsWith(":tab")||i==="tab"?o+=" ":(i.endsWith(":noBreakHyphen")||i==="noBreakHyphen")&&(o+="\u2011")}return o?{kind:_.TEXT,text:o,rPrXml:n,startOffset:t,endOffset:t+o.length}:null}function Mn(e,t){let r=e.getAttribute("w:author")||"",n="",o=J(e,y,"delText");for(let i of o)n+=i.textContent||"";let a=J(e,y,"r");for(let i of a){let s=J(i,y,"delText");for(let l of s)n+=l.textContent||""}return n?{kind:_.DELETION,text:n,rPrXml:"",startOffset:t,endOffset:t,author:r,nodeXml:Q(e)}:null}function Lr(e){let t=H(e,y,"tblGrid"),r=t?J(t,y,"gridCol"):[],n=ce(e,y,"tr"),o=n.length,a=n.reduce((u,f)=>{let m=ce(f,y,"tc");return Math.max(u,m.length)},0),i=r.length||a,s=Array.from({length:o},()=>Array.from({length:i},()=>null)),l=new Map,c=new Map;for(let u=0;u<n.length;u++){let f=n[u],m=ce(f,y,"tc"),p=0;for(let d=0;d<m.length;d++){let g=m[d],h=H(g,y,"tcPr");for(;p<i&&s[u][p]!==null;)p++;if(p>=i)break;let w=h?H(h,y,"gridSpan")||V(h,"w:gridSpan"):null,b=parseInt(w?.getAttribute("w:val")||"1",10),v=h?H(h,y,"vMerge")||V(h,"w:vMerge"):null,E=v?.getAttribute("w:val"),P=v!==null,x;if(P&&E!=="restart"){let N=c.get(p);N?(N.cell.rowSpan++,x={gridRow:u,gridCol:p,rowSpan:0,colSpan:b,tcNode:g,blocks:[],tcPrXml:Mr(h),isMergeOrigin:!1,isMergeContinuation:!0,mergeOrigin:N.cell}):x=Qa(u,p,b,g,h)}else{let N=_n(g);if(x={gridRow:u,gridCol:p,rowSpan:1,colSpan:b,tcNode:g,blocks:N,tcPrXml:Mr(h),isMergeOrigin:P&&E==="restart",isMergeContinuation:!1,getText:()=>N.map(A=>A.acceptedText).join(`
10
- `)},P&&E==="restart")for(let A=0;A<b;A++)c.set(p+A,{originRow:u,cell:x});else for(let A=0;A<b;A++)c.delete(p+A)}for(let N=0;N<b;N++){let A=p+N;A<i&&(s[u][A]=x,l.set(`${u},${A}`,x))}p+=b}}return{rowCount:o,colCount:i,grid:s,cellMap:l,tblPrXml:qa(e),tblGridXml:ei(e),trPrList:Array.from(n).map(u=>ti(u))}}function Qa(e,t,r,n,o){let a=_n(n);return{gridRow:e,gridCol:t,rowSpan:1,colSpan:r,tcNode:n,blocks:a,tcPrXml:Mr(o),isMergeOrigin:!1,isMergeContinuation:!1,getText:()=>a.map(i=>i.acceptedText).join(`
11
- `)}}function _n(e){return ce(e,y,"p").map(r=>{let{runModel:n,acceptedText:o,pPr:a}=Or(r);return{runModel:n,acceptedText:o,pPr:a}})}function Mr(e){return e?Q(e):"<w:tcPr/>"}function qa(e){let t=H(e,y,"tblPr");return t?Q(t):"<w:tblPr/>"}function ei(e){let t=H(e,y,"tblGrid");return t?Q(t):"<w:tblGrid/>"}function ti(e){let t=H(e,y,"trPr");return t?Q(t):"<w:trPr/>"}var $n=xn(_r(),1);var ri=65536,jt=262144,Gt=1,Vt=55296-Gt,ni=8192,oi=Vt+ni,Br=class extends Error{constructor(t=jt){super(`Word diff exceeds the safe limit of ${t} unique tokens.`),this.name="DiffTokenLimitError",this.code="DIFF_TOKEN_LIMIT",this.limit=t}};function Xn(e){return e?.code==="DIFF_TOKEN_LIMIT"}function ai(e={}){let t=e.diffTimeoutSeconds??0;if(!Number.isFinite(t)||t<0)throw new TypeError("diffTimeoutSeconds must be a finite non-negative number.");let r=new $n.diff_match_patch;return r.Diff_Timeout=t,r}function Bn(e){let t=[],r=e.match(/^\s+/);r&&t.push(r[0]);let n=/(\S+)(\s*)/g;n.lastIndex=r?.[0].length||0;let o;for(;(o=n.exec(e))!==null;)o[1]&&t.push(o[1]),o[2]&&t.push(o[2]);return t}function ii(e,t,r={}){let n=[],o=new Map,a=r.maxTokens??jt;if(!Number.isInteger(a)||a<1||a>jt)throw new RangeError(`maxTokens must be an integer from 1 to ${jt}.`);function i(f){let m="",p=[];for(let d of f){let g=o.get(d);if(g===void 0){if(n.length>=a)throw new Br(a);g=n.length,n.push(d),o.set(d,g)}p.push(g),m+=String.fromCodePoint(ri+g)}return{chars:m,tokenIds:p}}let s=Bn(e),l=Bn(t),c=i(s),u=i(l);return{chars1:c.chars,chars2:u.chars,wordArray:n,tokenIds1:c.tokenIds,tokenIds2:u.tokenIds}}function si(e){let t=e<Vt?Gt+e:57344+(e-Vt);return String.fromCharCode(t)}function li(e){if(e>=Gt&&e<55296)return e-Gt;if(e>=57344&&e<=65535)return Vt+e-57344;throw new RangeError(`BMP diff token U+${e.toString(16).toUpperCase()} has no mapping.`)}function Fn(e){let t="";for(let r of e)t+=si(r);return t}function ci(e,t){return e.map(([r,n])=>{let o=[];for(let a=0;a<n.length;a++){let i=li(n.charCodeAt(a));if(i>=t.length)throw new RangeError(`BMP diff token ${i} has no mapping.`);o.push(t[i])}return[r,o.join("")]})}function ui(e,t,r){let n=0,o=Math.min(e.length,t.length);for(;n<o&&e[n]===t[n];)n++;let a=0;for(;a<o-n&&e[e.length-1-a]===t[t.length-1-a];)a++;let i=u=>u.map(f=>r[f]).join(""),s=[];n&&s.push([0,i(e.slice(0,n))]);let l=e.slice(n,e.length-a),c=t.slice(n,t.length-a);return l.length&&s.push([-1,i(l)]),c.length&&s.push([1,i(c)]),a&&s.push([0,i(e.slice(e.length-a))]),s}function Tt(e,t,r={}){if(e===t)return[[0,e]];if(!e)return[[1,t]];if(!t)return[[-1,e]];let{cleanupSemantic:n=!0}=r,{wordArray:o,tokenIds1:a,tokenIds2:i}=ii(e,t,r);if(o.length>oi)return ui(a,i,o);let s=ai(r),l=s.diff_main(Fn(a),Fn(i));return n&&s.diff_cleanupSemantic(l),ci(l,o)}function Kt(e,t,r={}){if(e===t)return[{type:we.EQUAL,startOffset:0,endOffset:e.length,text:e}];if(!e)return[{type:we.INSERT,startOffset:0,endOffset:0,text:t}];if(!t)return[{type:we.DELETE,startOffset:0,endOffset:e.length,text:e}];let n=Tt(e,t,r),o=[],a=0;for(let[i,s]of n)i===0?(o.push({type:we.EQUAL,startOffset:a,endOffset:a+s.length,text:s}),a+=s.length):i===-1?(o.push({type:we.DELETE,startOffset:a,endOffset:a+s.length,text:s}),a+=s.length):i===1&&o.push({type:we.INSERT,startOffset:a,endOffset:a,text:s});return o}var fi=/\s+xmlns:[^=]+="[^"]*"/g;function Yt(e,t){let r=wi(t),n=[],o=0;for(let a of e){if(a.kind!==_.TEXT&&a.kind!==_.HYPERLINK){n.push(a);continue}for(;o<r.length&&r[o]<=a.startOffset;)o++;let i=o,s=a.startOffset,l=!1;for(;i<r.length;){let c=r[i];if(c>=a.endOffset)break;c>s&&(l=!0,n.push({...a,text:a.text.slice(s-a.startOffset,c-a.startOffset),startOffset:s,endOffset:c}),s=c),i++}if(o=i,!l){n.push(a);continue}n.push({...a,text:a.text.slice(s-a.startOffset),startOffset:s,endOffset:a.endOffset})}return n}function Zt(e,t,r){let{generateRedlines:n,author:o}=r,a=[],i=new Set,s=bi(t),l=gi(e),c=hi(s.nonInsertOps),u={containerStack:[],lastParagraphStartIndex:-1,currentParagraphPPrXml:"",currentParagraphPPrElement:null};for(let m of e){if(m.kind===_.CONTAINER_START){u.containerStack.push(m.containerId),a.push({...m});continue}if(m.kind===_.CONTAINER_END){u.containerStack.pop(),a.push({...m});continue}if(m.kind===_.PARAGRAPH_START){u.currentParagraphPPrXml=typeof m.pPrXml=="string"?m.pPrXml:"",u.currentParagraphPPrElement=m.pPrElement||null,a.push({...m}),u.lastParagraphStartIndex=a.length-1;continue}if(m.kind===_.BOOKMARK||m.kind===_.DELETION){a.push({...m});continue}let p=c(m.startOffset,m.endOffset),d=s.insertOpsByStartOffset.get(m.startOffset)||[];for(let g of d)i.has(g)||(i.add(g),mi({insertOp:g,splitModel:e,styleLookup:l,patchedModel:a,state:u,options:r,generateRedlines:n,author:o}));if(!p||p.type===we.EQUAL){a.push({...m,containerContext:u.containerStack.length>0?u.containerStack[u.containerStack.length-1]:null});continue}p.type===we.DELETE&&n&&a.push({...m,kind:_.DELETION,author:o,containerContext:u.containerStack.length>0?u.containerStack[u.containerStack.length-1]:null})}let f=e.length>0?Math.max(...e.map(m=>m.endOffset)):0;for(let m of s.sortedInsertOps){if(m.startOffset<f||i.has(m))continue;let p=e[e.length-1];a.push({kind:n?_.INSERTION:_.TEXT,text:m.text,rPrXml:p?.rPrXml||"",startOffset:m.startOffset,endOffset:m.startOffset+m.text.length,author:n?o:void 0})}return a}function mi(e){let{insertOp:t,styleLookup:r,patchedModel:n,state:o,options:a,generateRedlines:i,author:s}=e,l=t.text.split(`
12
- `),c=di(r,t.startOffset,t.text);for(let u=0;u<l.length;u++){let f=pi(l[u],a.numberingService,o),m=f.lineText;if(u>0){let p=Dn(o);f.isListLine&&f.numId&&(p=a.numberingService.buildListPPr(f.numId,f.ilvl)),n.push({kind:_.PARAGRAPH_START,pPrXml:p,startOffset:t.startOffset,endOffset:t.startOffset,text:""}),o.currentParagraphPPrXml=p,o.currentParagraphPPrElement=null,o.lastParagraphStartIndex=n.length-1}else if(f.isListLine&&f.numId&&o.lastParagraphStartIndex>=0){let p=a.numberingService.buildListPPr(f.numId,f.ilvl);n[o.lastParagraphStartIndex].pPrXml=p,n[o.lastParagraphStartIndex].pPrElement=null,o.currentParagraphPPrXml=p,o.currentParagraphPPrElement=null,I(`[Patching] Converted current paragraph to list item: numId=${f.numId}, ilvl=${f.ilvl}`)}(m.length>0||u>0)&&n.push({kind:i?_.INSERTION:_.TEXT,text:m,rPrXml:c?.rPrXml||"",startOffset:t.startOffset,endOffset:t.startOffset+m.length,author:i?s:void 0,containerContext:o.containerStack.length>0?o.containerStack[o.containerStack.length-1]:null})}}function pi(e,t,r){if(!t)return{lineText:e,isListLine:!1,numId:null,ilvl:0};let n=Ae(e,{allowZeroSpaceAfterMarker:!0});if(!n)return{lineText:e,isListLine:!1,numId:null,ilvl:0};let o=n[2].trim(),a=t.detectNumberingFormat(o),i=e.match(/^(\s*)/),s=i?i[1].length:0,l=s>=4?4:2,c=Math.floor(s/l),u=Dn(r),f=_e(e,{allowZeroSpaceAfterMarker:!0}),m=u.match(/w:numId w:val="(\d+)"/),p=u.match(/w:ilvl w:val="(\d+)"/),d=m?m[1]:null,g=p?parseInt(p[1],10):0,h=t.getOrCreateNumId({type:a.format},{numId:d,type:"unknown"}),w=a.format==="outline"?Math.min(8,a.depth):Math.min(8,c+g);return{lineText:f,isListLine:!0,numId:h,ilvl:w}}function Dn(e){return e.currentParagraphPPrXml?e.currentParagraphPPrXml:e.currentParagraphPPrElement?(e.currentParagraphPPrXml=Q(e.currentParagraphPPrElement).replace(fi,""),e.currentParagraphPPrXml):""}function di(e,t,r){let n=e.findRunBefore(t),o=e.findRunAfter(t);return!n&&!o?null:n?o?r&&r.endsWith(" ")?o:(r&&r.startsWith(" "),n):n:o}function gi(e){let t=e.filter(o=>o.kind===_.TEXT),r=t.map(o=>o.startOffset),n=t.map(o=>o.endOffset);return{findRunBefore(o){let a=0,i=n.length-1,s=-1;for(;a<=i;){let l=a+i>>1;n[l]<=o?(s=l,a=l+1):i=l-1}return s>=0?t[s]:null},findRunAfter(o){let a=0,i=r.length-1,s=-1;for(;a<=i;){let l=a+i>>1;r[l]>=o?(s=l,i=l-1):a=l+1}return s>=0?t[s]:null}}}function hi(e){let t=0;return(r,n)=>{for(;t<e.length&&e[t].endOffset<=r;)t++;let o=e[t];return o&&o.startOffset<=r&&o.endOffset>=n?o:null}}function wi(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 bi(e){let t=new Map,r=[],n=[];for(let o of e){if(o.type===we.INSERT){t.has(o.startOffset)||t.set(o.startOffset,[]),t.get(o.startOffset).push(o),n.push(o);continue}r.push(o)}return r.sort((o,a)=>o.startOffset-a.startOffset||o.endOffset-a.endOffset),n.sort((o,a)=>o.startOffset-a.startOffset||o.endOffset-a.endOffset),{insertOpsByStartOffset:t,nonInsertOps:r,sortedInsertOps:n}}var Hn="http://schemas.openxmlformats.org/wordprocessingml/2006/main",xi="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Ni="http://schemas.microsoft.com/office/2006/xmlPackage",zn="http://schemas.openxmlformats.org/package/2006/relationships",vi='<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>',Wn='<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/>';var Ti=`
13
- <w:numbering xmlns:w="${Hn}">
1
+ var za=Object.create;var xo=Object.defineProperty;var Wa=Object.getOwnPropertyDescriptor;var Ua=Object.getOwnPropertyNames;var ja=Object.getPrototypeOf,Ha=Object.prototype.hasOwnProperty;var Va=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}};var Ga=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ua(t))!Ha.call(e,o)&&o!==r&&xo(e,o,{get:()=>t[o],enumerable:!(n=Wa(t,o))||n.enumerable});return e};var No=(e,t,r)=>(r=e!=null?za(ja(e)):{},Ga(t||!e||!e.__esModule?xo(r,"default",{value:e,enumerable:!0}):r,e));var yn=Va((sf,It)=>{var A=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},K=-1,q=1,D=0;A.Diff=function(e,t){return[e,t]};A.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 o=n;if(e==null||t==null)throw new Error("Null input. (diff_main)");if(e==t)return e?[new A.Diff(D,e)]:[];typeof r>"u"&&(r=!0);var i=r,a=this.diff_commonPrefix(e,t),s=e.substring(0,a);e=e.substring(a),t=t.substring(a),a=this.diff_commonSuffix(e,t);var l=e.substring(e.length-a);e=e.substring(0,e.length-a),t=t.substring(0,t.length-a);var u=this.diff_compute_(e,t,i,o);return s&&u.unshift(new A.Diff(D,s)),l&&u.push(new A.Diff(D,l)),this.diff_cleanupMerge(u),u};A.prototype.diff_compute_=function(e,t,r,n){var o;if(!e)return[new A.Diff(q,t)];if(!t)return[new A.Diff(K,e)];var i=e.length>t.length?e:t,a=e.length>t.length?t:e,s=i.indexOf(a);if(s!=-1)return o=[new A.Diff(q,i.substring(0,s)),new A.Diff(D,a),new A.Diff(q,i.substring(s+a.length))],e.length>t.length&&(o[0][0]=o[2][0]=K),o;if(a.length==1)return[new A.Diff(K,e),new A.Diff(q,t)];var l=this.diff_halfMatch_(e,t);if(l){var u=l[0],c=l[1],f=l[2],m=l[3],d=l[4],p=this.diff_main(u,f,r,n),b=this.diff_main(c,m,r,n);return p.concat([new A.Diff(D,d)],b)}return r&&e.length>100&&t.length>100?this.diff_lineMode_(e,t,n):this.diff_bisect_(e,t,n)};A.prototype.diff_lineMode_=function(e,t,r){var n=this.diff_linesToChars_(e,t);e=n.chars1,t=n.chars2;var o=n.lineArray,i=this.diff_main(e,t,!1,r);this.diff_charsToLines_(i,o),this.diff_cleanupSemantic(i),i.push(new A.Diff(D,""));for(var a=0,s=0,l=0,u="",c="";a<i.length;){switch(i[a][0]){case q:l++,c+=i[a][1];break;case K:s++,u+=i[a][1];break;case D:if(s>=1&&l>=1){i.splice(a-s-l,s+l),a=a-s-l;for(var f=this.diff_main(u,c,!1,r),m=f.length-1;m>=0;m--)i.splice(a,0,f[m]);a=a+f.length}l=0,s=0,u="",c="";break}a++}return i.pop(),i};A.prototype.diff_bisect_=function(e,t,r){for(var n=e.length,o=t.length,i=Math.ceil((n+o)/2),a=i,s=2*i,l=new Array(s),u=new Array(s),c=0;c<s;c++)l[c]=-1,u[c]=-1;l[a+1]=0,u[a+1]=0;for(var f=n-o,m=f%2!=0,d=0,p=0,b=0,w=0,g=0;g<i&&!(new Date().getTime()>r);g++){for(var h=-g+d;h<=g-p;h+=2){var x=a+h,v;h==-g||h!=g&&l[x-1]<l[x+1]?v=l[x+1]:v=l[x-1]+1;for(var T=v-h;v<n&&T<o&&e.charAt(v)==t.charAt(T);)v++,T++;if(l[x]=v,v>n)p+=2;else if(T>o)d+=2;else if(m){var y=a+f-h;if(y>=0&&y<s&&u[y]!=-1){var N=n-u[y];if(v>=N)return this.diff_bisectSplit_(e,t,v,T,r)}}}for(var E=-g+b;E<=g-w;E+=2){var y=a+E,N;E==-g||E!=g&&u[y-1]<u[y+1]?N=u[y+1]:N=u[y-1]+1;for(var P=N-E;N<n&&P<o&&e.charAt(n-N-1)==t.charAt(o-P-1);)N++,P++;if(u[y]=N,N>n)w+=2;else if(P>o)b+=2;else if(!m){var x=a+f-E;if(x>=0&&x<s&&l[x]!=-1){var v=l[x],T=a+v-x;if(N=n-N,v>=N)return this.diff_bisectSplit_(e,t,v,T,r)}}}}return[new A.Diff(K,e),new A.Diff(q,t)]};A.prototype.diff_bisectSplit_=function(e,t,r,n,o){var i=e.substring(0,r),a=t.substring(0,n),s=e.substring(r),l=t.substring(n),u=this.diff_main(i,a,!1,o),c=this.diff_main(s,l,!1,o);return u.concat(c)};A.prototype.diff_linesToChars_=function(e,t){var r=[],n={};r[0]="";function o(l){for(var u="",c=0,f=-1,m=r.length;f<l.length-1;){f=l.indexOf(`
2
+ `,c),f==-1&&(f=l.length-1);var d=l.substring(c,f+1);(n.hasOwnProperty?n.hasOwnProperty(d):n[d]!==void 0)?u+=String.fromCharCode(n[d]):(m==i&&(d=l.substring(c),f=l.length),u+=String.fromCharCode(m),n[d]=m,r[m++]=d),c=f+1}return u}var i=4e4,a=o(e);i=65535;var s=o(t);return{chars1:a,chars2:s,lineArray:r}};A.prototype.diff_charsToLines_=function(e,t){for(var r=0;r<e.length;r++){for(var n=e[r][1],o=[],i=0;i<n.length;i++)o[i]=t[n.charCodeAt(i)];e[r][1]=o.join("")}};A.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),o=n,i=0;r<o;)e.substring(i,o)==t.substring(i,o)?(r=o,i=r):n=o,o=Math.floor((n-r)/2+r);return o};A.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),o=n,i=0;r<o;)e.substring(e.length-o,e.length-i)==t.substring(t.length-o,t.length-i)?(r=o,i=r):n=o,o=Math.floor((n-r)/2+r);return o};A.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 o=Math.min(r,n);if(e==t)return o;for(var i=0,a=1;;){var s=e.substring(o-a),l=t.indexOf(s);if(l==-1)return i;a+=l,(l==0||e.substring(o-a)==t.substring(0,a))&&(i=a,a++)}};A.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 o=this;function i(p,b,w){for(var g=p.substring(w,w+Math.floor(p.length/4)),h=-1,x="",v,T,y,N;(h=b.indexOf(g,h+1))!=-1;){var E=o.diff_commonPrefix(p.substring(w),b.substring(h)),P=o.diff_commonSuffix(p.substring(0,w),b.substring(0,h));x.length<P+E&&(x=b.substring(h-P,h)+b.substring(h,h+E),v=p.substring(0,w-P),T=p.substring(w+E),y=b.substring(0,h-P),N=b.substring(h+E))}return x.length*2>=p.length?[v,T,y,N,x]:null}var a=i(r,n,Math.ceil(r.length/4)),s=i(r,n,Math.ceil(r.length/2)),l;if(!a&&!s)return null;s?a?l=a[4].length>s[4].length?a:s:l=s:l=a;var u,c,f,m;e.length>t.length?(u=l[0],c=l[1],f=l[2],m=l[3]):(f=l[0],m=l[1],u=l[2],c=l[3]);var d=l[4];return[u,c,f,m,d]};A.prototype.diff_cleanupSemantic=function(e){for(var t=!1,r=[],n=0,o=null,i=0,a=0,s=0,l=0,u=0;i<e.length;)e[i][0]==D?(r[n++]=i,a=l,s=u,l=0,u=0,o=e[i][1]):(e[i][0]==q?l+=e[i][1].length:u+=e[i][1].length,o&&o.length<=Math.max(a,s)&&o.length<=Math.max(l,u)&&(e.splice(r[n-1],0,new A.Diff(K,o)),e[r[n-1]+1][0]=q,n--,n--,i=n>0?r[n-1]:-1,a=0,s=0,l=0,u=0,o=null,t=!0)),i++;for(t&&this.diff_cleanupMerge(e),this.diff_cleanupSemanticLossless(e),i=1;i<e.length;){if(e[i-1][0]==K&&e[i][0]==q){var c=e[i-1][1],f=e[i][1],m=this.diff_commonOverlap_(c,f),d=this.diff_commonOverlap_(f,c);m>=d?(m>=c.length/2||m>=f.length/2)&&(e.splice(i,0,new A.Diff(D,f.substring(0,m))),e[i-1][1]=c.substring(0,c.length-m),e[i+1][1]=f.substring(m),i++):(d>=c.length/2||d>=f.length/2)&&(e.splice(i,0,new A.Diff(D,c.substring(0,d))),e[i-1][0]=q,e[i-1][1]=f.substring(0,f.length-d),e[i+1][0]=K,e[i+1][1]=c.substring(d),i++),i++}i++}};A.prototype.diff_cleanupSemanticLossless=function(e){function t(d,p){if(!d||!p)return 6;var b=d.charAt(d.length-1),w=p.charAt(0),g=b.match(A.nonAlphaNumericRegex_),h=w.match(A.nonAlphaNumericRegex_),x=g&&b.match(A.whitespaceRegex_),v=h&&w.match(A.whitespaceRegex_),T=x&&b.match(A.linebreakRegex_),y=v&&w.match(A.linebreakRegex_),N=T&&d.match(A.blanklineEndRegex_),E=y&&p.match(A.blanklineStartRegex_);return N||E?5:T||y?4:g&&!x&&v?3:x||v?2:g||h?1:0}for(var r=1;r<e.length-1;){if(e[r-1][0]==D&&e[r+1][0]==D){var n=e[r-1][1],o=e[r][1],i=e[r+1][1],a=this.diff_commonSuffix(n,o);if(a){var s=o.substring(o.length-a);n=n.substring(0,n.length-a),o=s+o.substring(0,o.length-a),i=s+i}for(var l=n,u=o,c=i,f=t(n,o)+t(o,i);o.charAt(0)===i.charAt(0);){n+=o.charAt(0),o=o.substring(1)+i.charAt(0),i=i.substring(1);var m=t(n,o)+t(o,i);m>=f&&(f=m,l=n,u=o,c=i)}e[r-1][1]!=l&&(l?e[r-1][1]=l:(e.splice(r-1,1),r--),e[r][1]=u,c?e[r+1][1]=c:(e.splice(r+1,1),r--))}r++}};A.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/;A.whitespaceRegex_=/\s/;A.linebreakRegex_=/[\r\n]/;A.blanklineEndRegex_=/\n\r?\n$/;A.blanklineStartRegex_=/^\r?\n\r?\n/;A.prototype.diff_cleanupEfficiency=function(e){for(var t=!1,r=[],n=0,o=null,i=0,a=!1,s=!1,l=!1,u=!1;i<e.length;)e[i][0]==D?(e[i][1].length<this.Diff_EditCost&&(l||u)?(r[n++]=i,a=l,s=u,o=e[i][1]):(n=0,o=null),l=u=!1):(e[i][0]==K?u=!0:l=!0,o&&(a&&s&&l&&u||o.length<this.Diff_EditCost/2&&a+s+l+u==3)&&(e.splice(r[n-1],0,new A.Diff(K,o)),e[r[n-1]+1][0]=q,n--,o=null,a&&s?(l=u=!0,n=0):(n--,i=n>0?r[n-1]:-1,l=u=!1),t=!0)),i++;t&&this.diff_cleanupMerge(e)};A.prototype.diff_cleanupMerge=function(e){e.push(new A.Diff(D,""));for(var t=0,r=0,n=0,o="",i="",a;t<e.length;)switch(e[t][0]){case q:n++,i+=e[t][1],t++;break;case K:r++,o+=e[t][1],t++;break;case D:r+n>1?(r!==0&&n!==0&&(a=this.diff_commonPrefix(i,o),a!==0&&(t-r-n>0&&e[t-r-n-1][0]==D?e[t-r-n-1][1]+=i.substring(0,a):(e.splice(0,0,new A.Diff(D,i.substring(0,a))),t++),i=i.substring(a),o=o.substring(a)),a=this.diff_commonSuffix(i,o),a!==0&&(e[t][1]=i.substring(i.length-a)+e[t][1],i=i.substring(0,i.length-a),o=o.substring(0,o.length-a))),t-=r+n,e.splice(t,r+n),o.length&&(e.splice(t,0,new A.Diff(K,o)),t++),i.length&&(e.splice(t,0,new A.Diff(q,i)),t++),t++):t!==0&&e[t-1][0]==D?(e[t-1][1]+=e[t][1],e.splice(t,1)):t++,n=0,r=0,o="",i="";break}e[e.length-1][1]===""&&e.pop();var s=!1;for(t=1;t<e.length-1;)e[t-1][0]==D&&e[t+1][0]==D&&(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)};A.prototype.diff_xIndex=function(e,t){var r=0,n=0,o=0,i=0,a;for(a=0;a<e.length&&(e[a][0]!==q&&(r+=e[a][1].length),e[a][0]!==K&&(n+=e[a][1].length),!(r>t));a++)o=r,i=n;return e.length!=a&&e[a][0]===K?i:i+(t-o)};A.prototype.diff_prettyHtml=function(e){for(var t=[],r=/&/g,n=/</g,o=/>/g,i=/\n/g,a=0;a<e.length;a++){var s=e[a][0],l=e[a][1],u=l.replace(r,"&amp;").replace(n,"&lt;").replace(o,"&gt;").replace(i,"&para;<br>");switch(s){case q:t[a]='<ins style="background:#e6ffe6;">'+u+"</ins>";break;case K:t[a]='<del style="background:#ffe6e6;">'+u+"</del>";break;case D:t[a]="<span>"+u+"</span>";break}}return t.join("")};A.prototype.diff_text1=function(e){for(var t=[],r=0;r<e.length;r++)e[r][0]!==q&&(t[r]=e[r][1]);return t.join("")};A.prototype.diff_text2=function(e){for(var t=[],r=0;r<e.length;r++)e[r][0]!==K&&(t[r]=e[r][1]);return t.join("")};A.prototype.diff_levenshtein=function(e){for(var t=0,r=0,n=0,o=0;o<e.length;o++){var i=e[o][0],a=e[o][1];switch(i){case q:r+=a.length;break;case K:n+=a.length;break;case D:t+=Math.max(r,n),r=0,n=0;break}}return t+=Math.max(r,n),t};A.prototype.diff_toDelta=function(e){for(var t=[],r=0;r<e.length;r++)switch(e[r][0]){case q:t[r]="+"+encodeURI(e[r][1]);break;case K:t[r]="-"+e[r][1].length;break;case D:t[r]="="+e[r][1].length;break}return t.join(" ").replace(/%20/g," ")};A.prototype.diff_fromDelta=function(e,t){for(var r=[],n=0,o=0,i=t.split(/\t/g),a=0;a<i.length;a++){var s=i[a].substring(1);switch(i[a].charAt(0)){case"+":try{r[n++]=new A.Diff(q,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 u=e.substring(o,o+=l);i[a].charAt(0)=="="?r[n++]=new A.Diff(D,u):r[n++]=new A.Diff(K,u);break;default:if(i[a])throw new Error("Invalid diff operation in diff_fromDelta: "+i[a])}}if(o!=e.length)throw new Error("Delta length ("+o+") does not equal source text length ("+e.length+").");return r};A.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};A.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),o=this;function i(v,T){var y=v/t.length,N=Math.abs(r-T);return o.Match_Distance?y+N/o.Match_Distance:N?1:y}var a=this.Match_Threshold,s=e.indexOf(t,r);s!=-1&&(a=Math.min(i(0,s),a),s=e.lastIndexOf(t,r+t.length),s!=-1&&(a=Math.min(i(0,s),a)));var l=1<<t.length-1;s=-1;for(var u,c,f=t.length+e.length,m,d=0;d<t.length;d++){for(u=0,c=f;u<c;)i(d,r+c)<=a?u=c:f=c,c=Math.floor((f-u)/2+u);f=c;var p=Math.max(1,r-c+1),b=Math.min(r+c,e.length)+t.length,w=Array(b+2);w[b+1]=(1<<d)-1;for(var g=b;g>=p;g--){var h=n[e.charAt(g-1)];if(d===0?w[g]=(w[g+1]<<1|1)&h:w[g]=(w[g+1]<<1|1)&h|((m[g+1]|m[g])<<1|1)|m[g+1],w[g]&l){var x=i(d,g-1);if(x<=a)if(a=x,s=g-1,s>r)p=Math.max(1,2*r-s);else break}}if(i(d+1,r)>a)break;m=w}return s};A.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};A.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 o=t.substring(e.start2-n,e.start2);o&&e.diffs.unshift(new A.Diff(D,o));var i=t.substring(e.start2+e.length1,e.start2+e.length1+n);i&&e.diffs.push(new A.Diff(D,i)),e.start1-=o.length,e.start2-=o.length,e.length1+=o.length+i.length,e.length2+=o.length+i.length}};A.prototype.patch_make=function(e,t,r){var n,o;if(typeof e=="string"&&typeof t=="string"&&typeof r>"u")n=e,o=this.diff_main(n,t,!0),o.length>2&&(this.diff_cleanupSemantic(o),this.diff_cleanupEfficiency(o));else if(e&&typeof e=="object"&&typeof t>"u"&&typeof r>"u")o=e,n=this.diff_text1(o);else if(typeof e=="string"&&t&&typeof t=="object"&&typeof r>"u")n=e,o=t;else if(typeof e=="string"&&typeof t=="string"&&r&&typeof r=="object")n=e,o=r;else throw new Error("Unknown call format to patch_make.");if(o.length===0)return[];for(var i=[],a=new A.patch_obj,s=0,l=0,u=0,c=n,f=n,m=0;m<o.length;m++){var d=o[m][0],p=o[m][1];switch(!s&&d!==D&&(a.start1=l,a.start2=u),d){case q:a.diffs[s++]=o[m],a.length2+=p.length,f=f.substring(0,u)+p+f.substring(u);break;case K:a.length1+=p.length,a.diffs[s++]=o[m],f=f.substring(0,u)+f.substring(u+p.length);break;case D:p.length<=2*this.Patch_Margin&&s&&o.length!=m+1?(a.diffs[s++]=o[m],a.length1+=p.length,a.length2+=p.length):p.length>=2*this.Patch_Margin&&s&&(this.patch_addContext_(a,c),i.push(a),a=new A.patch_obj,s=0,c=f,l=u);break}d!==q&&(l+=p.length),d!==K&&(u+=p.length)}return s&&(this.patch_addContext_(a,c),i.push(a)),i};A.prototype.patch_deepCopy=function(e){for(var t=[],r=0;r<e.length;r++){var n=e[r],o=new A.patch_obj;o.diffs=[];for(var i=0;i<n.diffs.length;i++)o.diffs[i]=new A.Diff(n.diffs[i][0],n.diffs[i][1]);o.start1=n.start1,o.start2=n.start2,o.length1=n.length1,o.length2=n.length2,t[r]=o}return t};A.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,o=[],i=0;i<e.length;i++){var a=e[i].start2+n,s=this.diff_text1(e[i].diffs),l,u=-1;if(s.length>this.Match_MaxBits?(l=this.match_main(t,s.substring(0,this.Match_MaxBits),a),l!=-1&&(u=this.match_main(t,s.substring(s.length-this.Match_MaxBits),a+s.length-this.Match_MaxBits),(u==-1||l>=u)&&(l=-1))):l=this.match_main(t,s,a),l==-1)o[i]=!1,n-=e[i].length2-e[i].length1;else{o[i]=!0,n=l-a;var c;if(u==-1?c=t.substring(l,l+s.length):c=t.substring(l,u+this.Match_MaxBits),s==c)t=t.substring(0,l)+this.diff_text2(e[i].diffs)+t.substring(l+s.length);else{var f=this.diff_main(s,c,!1);if(s.length>this.Match_MaxBits&&this.diff_levenshtein(f)/s.length>this.Patch_DeleteThreshold)o[i]=!1;else{this.diff_cleanupSemanticLossless(f);for(var m=0,d,p=0;p<e[i].diffs.length;p++){var b=e[i].diffs[p];b[0]!==D&&(d=this.diff_xIndex(f,m)),b[0]===q?t=t.substring(0,l+d)+b[1]+t.substring(l+d):b[0]===K&&(t=t.substring(0,l+d)+t.substring(l+this.diff_xIndex(f,m+b[1].length))),b[0]!==K&&(m+=b[1].length)}}}}}return t=t.substring(r.length,t.length-r.length),[t,o]};A.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 o=e[0],i=o.diffs;if(i.length==0||i[0][0]!=D)i.unshift(new A.Diff(D,r)),o.start1-=t,o.start2-=t,o.length1+=t,o.length2+=t;else if(t>i[0][1].length){var a=t-i[0][1].length;i[0][1]=r.substring(i[0][1].length)+i[0][1],o.start1-=a,o.start2-=a,o.length1+=a,o.length2+=a}if(o=e[e.length-1],i=o.diffs,i.length==0||i[i.length-1][0]!=D)i.push(new A.Diff(D,r)),o.length1+=t,o.length2+=t;else if(t>i[i.length-1][1].length){var a=t-i[i.length-1][1].length;i[i.length-1][1]+=r.substring(0,a),o.length1+=a,o.length2+=a}return r};A.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 o=n.start1,i=n.start2,a="";n.diffs.length!==0;){var s=new A.patch_obj,l=!0;for(s.start1=o-a.length,s.start2=i-a.length,a!==""&&(s.length1=s.length2=a.length,s.diffs.push(new A.Diff(D,a)));n.diffs.length!==0&&s.length1<t-this.Patch_Margin;){var u=n.diffs[0][0],c=n.diffs[0][1];u===q?(s.length2+=c.length,i+=c.length,s.diffs.push(n.diffs.shift()),l=!1):u===K&&s.diffs.length==1&&s.diffs[0][0]==D&&c.length>2*t?(s.length1+=c.length,o+=c.length,l=!1,s.diffs.push(new A.Diff(u,c)),n.diffs.shift()):(c=c.substring(0,t-s.length1-this.Patch_Margin),s.length1+=c.length,o+=c.length,u===D?(s.length2+=c.length,i+=c.length):l=!1,s.diffs.push(new A.Diff(u,c)),c==n.diffs[0][1]?n.diffs.shift():n.diffs[0][1]=n.diffs[0][1].substring(c.length))}a=this.diff_text2(s.diffs),a=a.substring(a.length-this.Patch_Margin);var f=this.diff_text1(n.diffs).substring(0,this.Patch_Margin);f!==""&&(s.length1+=f.length,s.length2+=f.length,s.diffs.length!==0&&s.diffs[s.diffs.length-1][0]===D?s.diffs[s.diffs.length-1][1]+=f:s.diffs.push(new A.Diff(D,f))),l||e.splice(++r,0,s)}}};A.prototype.patch_toText=function(e){for(var t=[],r=0;r<e.length;r++)t[r]=e[r];return t.join("")};A.prototype.patch_fromText=function(e){var t=[];if(!e)return t;for(var r=e.split(`
3
+ `),n=0,o=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;n<r.length;){var i=r[n].match(o);if(!i)throw new Error("Invalid patch string: "+r[n]);var a=new A.patch_obj;for(t.push(a),a.start1=parseInt(i[1],10),i[2]===""?(a.start1--,a.length1=1):i[2]=="0"?a.length1=0:(a.start1--,a.length1=parseInt(i[2],10)),a.start2=parseInt(i[3],10),i[4]===""?(a.start2--,a.length2=1):i[4]=="0"?a.length2=0:(a.start2--,a.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=="-")a.diffs.push(new A.Diff(K,l));else if(s=="+")a.diffs.push(new A.Diff(q,l));else if(s==" ")a.diffs.push(new A.Diff(D,l));else{if(s=="@")break;if(s!=="")throw new Error('Invalid patch mode "'+s+'" in: '+l)}n++}}return t};A.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0};A.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,o=0;o<this.diffs.length;o++){switch(this.diffs[o][0]){case q:n="+";break;case K:n="-";break;case D:n=" ";break}r[o+1]=n+encodeURI(this.diffs[o][1])+`
5
+ `}return r.join("").replace(/%20/g," ")};It.exports=A;It.exports.diff_match_patch=A;It.exports.DIFF_DELETE=K;It.exports.DIFF_INSERT=q;It.exports.DIFF_EQUAL=D});var yr=console,cn=Object.freeze({silent:0,error:1,warn:2,info:3}),Ka=typeof process<"u"&&process?.env?.NODE_ENV==="production"?"warn":"info",un=Ka;function Ya(e){let t=String(e||"").toLowerCase();return Object.prototype.hasOwnProperty.call(cn,t)?t:un}function fn(e){return cn[un]>=cn[e]}function Ja(e,t={}){yr=e||console,t.level&&(un=Ya(t.level))}function k(...e){fn("info")&&(yr.log||(()=>{}))(...e)}function Le(...e){fn("warn")&&(yr.warn||(()=>{}))(...e)}function te(...e){fn("error")&&(yr.error||(()=>{}))(...e)}var Ht=globalThis.DOMParser,Vt=globalThis.XMLSerializer;function qa(e={}){e.DOMParser&&(Ht=e.DOMParser),e.XMLSerializer&&(Vt=e.XMLSerializer)}function Za(e={}){if(!Ht&&globalThis.DOMParser&&(Ht=globalThis.DOMParser),!Ht)throw new Error("DOMParser is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new Ht(e)}function fe(){if(!Vt&&globalThis.XMLSerializer&&(Vt=globalThis.XMLSerializer),!Vt)throw new Error("XMLSerializer is not configured. Call configureXmlProvider({ DOMParser, XMLSerializer }) first.");return new Vt}function vo(e,t="text/xml"){let r=W(e,t);if(r.error){let n=new Error(r.error.message);throw n.code=r.error.code,n}return r.doc}function Qa(e){return e?.documentElement?String(e.documentElement.localName||e.documentElement.nodeName).toLowerCase()==="parsererror"?e.documentElement:e.getElementsByTagName?.("parsererror")?.[0]||null:null}function W(e,t="application/xml"){let r=[];if(typeof e!="string"||e.trim()==="")return{doc:null,error:{code:"PARSE_ERROR",message:"Input is not a non-empty XML string."},warnings:r};let n=(o,i)=>{let a=String(i||"XML parser diagnostic.");o==="fatalError"?te("[XmlAdapter] XML fatal parse error:",a):(r.push(a),Le(`[XmlAdapter] XML ${o||"warning"}:`,a))};try{let i=Za({onError:n}).parseFromString(e,t),a=Qa(i);if(!i?.documentElement||a){let s=a?.textContent||"Could not parse XML input.";return te("[XmlAdapter] XML parse error:",s),{doc:null,error:{code:"PARSE_ERROR",message:s},warnings:r}}return{doc:i,error:null,warnings:r}}catch(o){let i=o?.message||String(o||"Could not parse XML input.");return te("[XmlAdapter] XML parse error:",i),{doc:null,error:{code:"PARSE_ERROR",message:i},warnings:r}}}function oe(e){return fe().serializeToString(e)}var yo=()=>typeof process<"u"&&process.env?.DOCX_REDLINE_AUTHOR||"AI Redliner",To=yo(),So="Unknown";function es(e){To=typeof e=="string"&&e.trim()?e.trim():yo()}function me(){return To}function ts(e){So=typeof e=="string"&&e.trim()?e.trim():"Unknown"}function mn(){return So}var rs=[{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 Ee(e){if(!e)return{cleanText:"",formatHints:[]};let t=[],r="",n=[];for(let s of rs){let l,u=s.regex.source||s.regex.toString().replace(/^\/|\/[gimuy]*$/g,""),c="g"+(s.regex.ignoreCase?"i":""),f=new RegExp(u,c);for(;(l=f.exec(e))!==null;)n.push({start:l.index,end:l.index+l[0].length,fullMatch:l[0],innerText:s.isEscaped?ns(l[1]):l[1],format:s.format}),l.index===f.lastIndex&&f.lastIndex++}n.sort((s,l)=>s.start-l.start||l.end-s.end);let o=[],i=0;for(let s of n)s.start>=i&&(o.push(s),i=s.end);let a=0;for(let s of o){r+=e.slice(a,s.start);let l=Ee(s.innerText),u=r.length;r+=l.cleanText;let c=r.length;t.push({start:u,end:c,format:s.format});for(let f of l.formatHints)t.push({start:u+f.start,end:u+f.end,format:f.format});a=s.end}return r+=e.slice(a),{cleanText:r,formatHints:t}}function Ve(e,t,r){return e.filter(n=>n.start<r&&n.end>t)}function dn(...e){let t={};for(let r of e)r&&Object.assign(t,r);return t}function ns(e){return e?e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#039;/g,"'"):""}var Tr=String.raw`(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|\d+\.|[ivxlcIVXLC]+\.|[-*+\u2022])`,Eo=new RegExp(`^(\\s*)((?:${Tr})\\s+)`),Io=new RegExp(`^(\\s*)((?:${Tr})\\s*)`),os=new RegExp(`^(\\s*)((?:${Tr})\\s+)`,"m"),is=new RegExp(`^(\\s*)((?:${Tr})\\s*)`,"m");function pn(e){return typeof e!="string"?!1:e.includes(`
6
+ `)&&os.test(e)}function Gt(e){return typeof e!="string"?!1:e.includes(`
7
+ `)&&is.test(e.trim())}function Be(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?Io:Eo;return e.match(n)}function We(e,t={}){let{allowZeroSpaceAfterMarker:r=!1}=t,n=r?Io:Eo;return e.replace(n,"")}function Ao(e){return/^[-*+\u2022]$/.test(String(e||"").trim())?"bullet":"numbered"}function Kt(e){let t=String(e||"").trim();return Ao(t)==="bullet"?"bullet":/^\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 as(e){let t=String(e||"").trim();return/^\d+(?:\.\d+)+\.?$/.test(t)?Math.max(0,t.replace(/\.$/,"").split(".").length-1):null}function Yt(e,t={}){let r=Be(String(e||""),t);if(!r)return null;let n=r[2].trim(),o=(r[1]||"").length,i=Math.max(1,Number(t.indentSpaces)||2),a=Ao(n);return{line:String(e||""),text:We(String(e||""),t),marker:n,indent:o,level:Math.min(8,Math.floor(o/i)),markerType:a,listType:a,numberingStyle:Kt(n),outlineLevel:a==="numbered"?as(n):null}}var S="http://schemas.openxmlformats.org/wordprocessingml/2006/main";var Oe=Object.freeze({EQUAL:"equal",DELETE:"delete",INSERT:"insert"}),B=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"}),Nt=Object.freeze({SDT:"sdt",SMART_TAG:"smartTag",CUSTOM_XML:"customXml",FIELD_COMPLEX:"fldComplex"}),Co=Object.freeze({PARAGRAPH:"paragraph",BULLET_LIST:"bullet_list",NUMBERED_LIST:"numbered_list",TABLE:"table"}),V=Object.freeze({DECIMAL:"decimal",LOWER_ALPHA:"lowerLetter",UPPER_ALPHA:"upperLetter",LOWER_ROMAN:"lowerRoman",UPPER_ROMAN:"upperRoman",BULLET:"bullet",OUTLINE:"outline"}),he=Object.freeze({PERIOD:"period",PAREN_RIGHT:"parenRight",PAREN_BOTH:"parenBoth",NONE:"none"});function we(e){return e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;"):""}var gn=1e3,Po=2147483647,Ro=1e4,ss=new Set(["ins","del","moveFrom","moveTo","rPrChange","pPrChange","cellIns","cellDel","comment"]),Oo=new WeakMap;function ls(e){if(!e||e.nodeType!==1)return!1;let t=String(e.localName||e.nodeName||"").replace(/^.*:/,"");return ss.has(t)?!e.namespaceURI||e.namespaceURI===S||String(e.nodeName||"").startsWith("w:"):!1}function cs(e){let t=e?.getAttributeNS?.(S,"id")||e?.getAttribute?.("w:id")||e?.getAttribute?.("id"),r=Number.parseInt(String(t??""),10);return Number.isInteger(r)&&r>=0?r:null}var Ne=class{constructor(t=gn){this.startValue=Number.isInteger(t)&&t>=0?t:gn,this.nextId=this.startValue,this.occupiedIds=new Set}seed(t){let r=-1,n=t?.nodeType===9?t.documentElement:t,o=n||null;for(;o;){if(ls(o)){let a=cs(o);a!=null&&(this.occupiedIds.add(a),r=Math.max(r,a))}if(o.firstChild){o=o.firstChild;continue}for(;o&&o!==n&&!o.nextSibling;)o=o.parentNode;o=o&&o!==n?o.nextSibling:null}let i=Po-Ro;return this.nextId=r>=i?this.startValue:Math.max(this.nextId,r+1),this.advanceToAvailableId(),this.nextId}advanceToAvailableId(){let t=Po-Ro;for(this.nextId>=t&&(this.nextId=this.startValue);this.occupiedIds.has(this.nextId);)this.nextId+=1,this.nextId>=t&&(this.nextId=this.startValue)}next(){this.advanceToAvailableId();let t=this.nextId;return this.occupiedIds.add(t),this.nextId+=1,t}},Jt=new Ne;function Sr(e,t){let r=e?.nodeType===9?e:e?.ownerDocument;return r&&t instanceof Ne&&Oo.set(r,t),t}function st(e){let t=e?.nodeType===9?e:e?.ownerDocument;return t&&Oo.get(t)||null}function vt(e,t=gn){let r=new Ne(t);return r.seed(e),Sr(e,r),r}function ko(){return Jt.next()}function Er(e=new Date){return e.toISOString()}function ie(e,t=null,r=null){let n=typeof e=="string"&&e.trim()?e.trim():me(),o=t instanceof Ne?t:st(t)||Jt,i=o.next();return o._receiptCollector&&o._receiptCollector.recordRevision(i,r||"structural"),{id:i,author:n,date:Er()}}function Ir(e,t=null){let r=typeof e=="string"&&e.trim()?e.trim():me(),n=t instanceof Ne?t:st(t)||Jt,o=Er(),i=n.next(),a=n.next();return n._receiptCollector&&(n._receiptCollector.recordRevision(i,"del"),n._receiptCollector.recordRevision(a,"ins")),{deletionId:i,insertionId:a,author:r,date:o}}function yt(e,t=Jt){let r=t instanceof Ne?t:Jt,n=r.seed(e);return Sr(e,r),n}function Mo(e,t){return e<t-1}function Tt(e,t,r){return Mo(t,r)?e+`
8
+ `:e}function lt(e,t,r){return Mo(t,r)?e+1:e}function qt(e,t){return!e||typeof e.getElementsByTagName!="function"?[]:Array.from(e.getElementsByTagName(t))}function ae(e,t){if(!e||typeof e.getElementsByTagName!="function")return null;let r=e.getElementsByTagName(t);return r.length>0?r[0]:null}function se(e,t,r){return!e||typeof e.getElementsByTagNameNS!="function"?[]:Array.from(e.getElementsByTagNameNS(t,r))}function re(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 ve(e,t,r,n=`w:${r}`){let o=se(e,t,r);return o.length>0?o:qt(e,n)}function be(e,t,r,n=`w:${r}`){let o=re(e,t,r);return o||ae(e,n)}function ne(e){return ae(e,"parsererror")}function hn(e){return Array.from(e?.childNodes||[])}function _o(e){return Array.from(e.attributes).map(t=>`${t.name}="${t.value}"`).join(" ")}function wn(e,t,r=""){return!e||e.namespaceURI!==t?!1:r?e.localName===r:!0}var bn=0;function Et(e,t={}){let r=[],n="",o=t.xmlDoc||null;if(!e&&!o)return{runModel:r,acceptedText:n,pPr:null};try{let i=o?{doc:o,error:null}:W(e,"application/xml"),a=i.doc;if(i.error||!a)return te("OOXML parse error:",i.error?.message),{runModel:r,acceptedText:n,pPr:null,error:i.error};let s=ne(a);if(s)return te("OOXML parse error:",s.textContent),{runModel:r,acceptedText:n,pPr:null};let l=se(a,S,"p");return l.length===0?(Le("No paragraphs found in OOXML"),{runModel:r,acceptedText:n,pPr:null}):Bo(l,{includeParagraphBoundaries:!0})}catch(i){return te("Error ingesting OOXML:",i),{runModel:r,acceptedText:n,pPr:null}}}function xn(e){return e?Bo([e],{includeParagraphBoundaries:!1}):{runModel:[],acceptedText:"",pPr:null}}function Zt(e){let t=re(e,S,"pPr");if(!t)return null;let r=re(t,S,"numPr");if(!r)return null;let n=re(r,S,"numId"),o=re(r,S,"ilvl");if(!n)return null;let i=n.getAttribute("w:val");if(!/^\d+$/.test(i)||Number.parseInt(i,10)===0)return null;let a=i==="1"?"bullet":i==="2"?"numbered":"unknown";return{numId:i,ilvl:parseInt(o?.getAttribute("w:val")||"0",10),type:a}}function Bo(e,t={}){let r=t.includeParagraphBoundaries??!0,n=[],o="",i=0,a=null;for(let s=0;s<e.length;s++){let l=e[s],u=re(l,S,"pPr");s===0&&(a=u),n.push({kind:B.PARAGRAPH_START,pPrElement:u||null,startOffset:i,endOffset:i,text:""});let c=St(l,i,n);o+=c.text,i=o.length,r&&(o=Tt(o,s,e.length),i=lt(i,s,e.length))}return{runModel:n,acceptedText:o,pPr:a}}function St(e,t,r){let n=t,o="",i=us(r);for(let a of hn(e)){if(wn(a,S,"pPr")||wn(a,S,"proofErr"))continue;let s=i.get(a.localName);if(!s)continue;let l=s(a,n);n=l.offset,o+=l.text}return{offset:n,text:o}}function us(e){let t=new Map;t.set("sdt",(r,n)=>{let o=`sdt_${bn++}`,i=re(r,S,"sdtPr"),a=re(r,S,"sdtContent");e.push({kind:B.CONTAINER_START,containerKind:Nt.SDT,containerId:o,propertiesXml:i?oe(i):"",startOffset:n,endOffset:n,text:""});let s=a?St(a,n,e):{offset:n,text:""};return e.push({kind:B.CONTAINER_END,containerKind:Nt.SDT,containerId:o,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("smartTag",(r,n)=>{let o=`smartTag_${bn++}`;e.push({kind:B.CONTAINER_START,containerKind:Nt.SMART_TAG,containerId:o,propertiesXml:_o(r),startOffset:n,endOffset:n,text:""});let i=St(r,n,e);return e.push({kind:B.CONTAINER_END,containerKind:Nt.SMART_TAG,containerId:o,startOffset:i.offset,endOffset:i.offset,text:""}),i}),t.set("del",(r,n)=>{let o=Lo(r,n);return o&&e.push(o),{offset:n,text:""}}),t.set("moveFrom",(r,n)=>{let o=Lo(r,n);return o&&e.push(o),{offset:n,text:""}}),t.set("moveTo",(r,n)=>St(r,n,e));for(let r of["moveFromRangeStart","moveFromRangeEnd","moveToRangeStart","moveToRangeEnd"])t.set(r,(n,o)=>(e.push({kind:B.BOOKMARK,nodeXml:oe(n),startOffset:o,endOffset:o,text:""}),{offset:o,text:""}));return t.set("bookmarkStart",(r,n)=>(e.push({kind:B.BOOKMARK,nodeXml:oe(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("bookmarkEnd",(r,n)=>(e.push({kind:B.BOOKMARK,nodeXml:oe(r),startOffset:n,endOffset:n,text:""}),{offset:n,text:""})),t.set("ins",(r,n)=>St(r,n,e)),t.set("hyperlink",(r,n)=>{let o=`hyperlink_${bn++}`,i=r.getAttribute("r:id")||"",a=r.getAttribute("w:anchor")||"";e.push({kind:B.CONTAINER_START,containerKind:"hyperlink",containerId:o,propertiesXml:JSON.stringify({rId:i,anchor:a}),startOffset:n,endOffset:n,text:""});let s=St(r,n,e);return e.push({kind:B.CONTAINER_END,containerKind:"hyperlink",containerId:o,startOffset:s.offset,endOffset:s.offset,text:""}),s}),t.set("r",(r,n)=>{let o=fs(r,n);return!o||!o.text?{offset:n,text:""}:(e.push(o),{offset:n+o.text.length,text:o.text})}),t}function fs(e,t){let r=be(e,S,"rPr"),n=r?oe(r):"",o="";for(let i of hn(e)){let a=i.nodeName;a.endsWith(":t")||a==="t"?o+=i.textContent||"":a.endsWith(":br")||a==="br"||a.endsWith(":cr")||a==="cr"?o+=`
9
+ `:a.endsWith(":tab")||a==="tab"?o+=" ":a.endsWith(":noBreakHyphen")||a==="noBreakHyphen"?o+="\u2011":(a.endsWith(":softHyphen")||a==="softHyphen")&&(o+="\xAD")}return o?{kind:B.TEXT,text:o,rPrXml:n,startOffset:t,endOffset:t+o.length}:null}function Lo(e,t){let r=e.getAttribute("w:author")||"",n="",o=se(e,S,"delText");for(let a of o)n+=a.textContent||"";let i=se(e,S,"r");for(let a of i){let s=se(a,S,"delText");for(let l of s)n+=l.textContent||""}return n?{kind:B.DELETION,text:n,rPrXml:"",startOffset:t,endOffset:t,author:r,nodeXml:oe(e)}:null}function vn(e){let t=re(e,S,"tblGrid"),r=t?se(t,S,"gridCol"):[],n=ve(e,S,"tr"),o=n.length,i=n.reduce((c,f)=>{let m=ve(f,S,"tc");return Math.max(c,m.length)},0),a=r.length||i,s=Array.from({length:o},()=>Array.from({length:a},()=>null)),l=new Map,u=new Map;for(let c=0;c<n.length;c++){let f=n[c],m=ve(f,S,"tc"),d=0;for(let p=0;p<m.length;p++){let b=m[p],w=re(b,S,"tcPr");for(;d<a&&s[c][d]!==null;)d++;if(d>=a)break;let g=w?re(w,S,"gridSpan")||ae(w,"w:gridSpan"):null,h=parseInt(g?.getAttribute("w:val")||"1",10),x=w?re(w,S,"vMerge")||ae(w,"w:vMerge"):null,v=x?.getAttribute("w:val"),T=x!==null,y;if(T&&v!=="restart"){let N=u.get(d);N?(N.cell.rowSpan++,y={gridRow:c,gridCol:d,rowSpan:0,colSpan:h,tcNode:b,blocks:[],tcPrXml:Nn(w),isMergeOrigin:!1,isMergeContinuation:!0,mergeOrigin:N.cell}):y=ms(c,d,h,b,w)}else{let N=Fo(b);if(y={gridRow:c,gridCol:d,rowSpan:1,colSpan:h,tcNode:b,blocks:N,tcPrXml:Nn(w),isMergeOrigin:T&&v==="restart",isMergeContinuation:!1,getText:()=>N.map(E=>E.acceptedText).join(`
10
+ `)},T&&v==="restart")for(let E=0;E<h;E++)u.set(d+E,{originRow:c,cell:y});else for(let E=0;E<h;E++)u.delete(d+E)}for(let N=0;N<h;N++){let E=d+N;E<a&&(s[c][E]=y,l.set(`${c},${E}`,y))}d+=h}}return{rowCount:o,colCount:a,grid:s,cellMap:l,tblPrXml:ds(e),tblGridXml:ps(e),trPrList:Array.from(n).map(c=>gs(c))}}function ms(e,t,r,n,o){let i=Fo(n);return{gridRow:e,gridCol:t,rowSpan:1,colSpan:r,tcNode:n,blocks:i,tcPrXml:Nn(o),isMergeOrigin:!1,isMergeContinuation:!1,getText:()=>i.map(a=>a.acceptedText).join(`
11
+ `)}}function Fo(e){return ve(e,S,"p").map(r=>{let{runModel:n,acceptedText:o,pPr:i}=xn(r);return{runModel:n,acceptedText:o,pPr:i}})}function Nn(e){return e?oe(e):"<w:tcPr/>"}function ds(e){let t=re(e,S,"tblPr");return t?oe(t):"<w:tblPr/>"}function ps(e){let t=re(e,S,"tblGrid");return t?oe(t):"<w:tblGrid/>"}function gs(e){let t=re(e,S,"trPr");return t?oe(t):"<w:trPr/>"}var Do=No(yn(),1);var hs=65536,Ar=262144,Pr=1,Rr=55296-Pr,ws=8192,bs=Rr+ws,Tn=class extends Error{constructor(t=Ar){super(`Word diff exceeds the safe limit of ${t} unique tokens.`),this.name="DiffTokenLimitError",this.code="DIFF_TOKEN_LIMIT",this.limit=t}};function zo(e){return e?.code==="DIFF_TOKEN_LIMIT"}function xs(e={}){let t=e.diffTimeoutSeconds??0;if(!Number.isFinite(t)||t<0)throw new TypeError("diffTimeoutSeconds must be a finite non-negative number.");let r=new Do.diff_match_patch;return r.Diff_Timeout=t,r}function $o(e){let t=[],r=e.match(/^\s+/);r&&t.push(r[0]);let n=/(\S+)(\s*)/g;n.lastIndex=r?.[0].length||0;let o;for(;(o=n.exec(e))!==null;)o[1]&&t.push(o[1]),o[2]&&t.push(o[2]);return t}function Ns(e,t,r={}){let n=[],o=new Map,i=r.maxTokens??Ar;if(!Number.isInteger(i)||i<1||i>Ar)throw new RangeError(`maxTokens must be an integer from 1 to ${Ar}.`);function a(f){let m="",d=[];for(let p of f){let b=o.get(p);if(b===void 0){if(n.length>=i)throw new Tn(i);b=n.length,n.push(p),o.set(p,b)}d.push(b),m+=String.fromCodePoint(hs+b)}return{chars:m,tokenIds:d}}let s=$o(e),l=$o(t),u=a(s),c=a(l);return{chars1:u.chars,chars2:c.chars,wordArray:n,tokenIds1:u.tokenIds,tokenIds2:c.tokenIds}}function vs(e){let t=e<Rr?Pr+e:57344+(e-Rr);return String.fromCharCode(t)}function ys(e){if(e>=Pr&&e<55296)return e-Pr;if(e>=57344&&e<=65535)return Rr+e-57344;throw new RangeError(`BMP diff token U+${e.toString(16).toUpperCase()} has no mapping.`)}function Xo(e){let t="";for(let r of e)t+=vs(r);return t}function Ts(e,t){return e.map(([r,n])=>{let o=[];for(let i=0;i<n.length;i++){let a=ys(n.charCodeAt(i));if(a>=t.length)throw new RangeError(`BMP diff token ${a} has no mapping.`);o.push(t[a])}return[r,o.join("")]})}function Ss(e,t,r){let n=0,o=Math.min(e.length,t.length);for(;n<o&&e[n]===t[n];)n++;let i=0;for(;i<o-n&&e[e.length-1-i]===t[t.length-1-i];)i++;let a=c=>c.map(f=>r[f]).join(""),s=[];n&&s.push([0,a(e.slice(0,n))]);let l=e.slice(n,e.length-i),u=t.slice(n,t.length-i);return l.length&&s.push([-1,a(l)]),u.length&&s.push([1,a(u)]),i&&s.push([0,a(e.slice(e.length-i))]),s}function Qt(e,t,r={}){if(e===t)return[[0,e]];if(!e)return[[1,t]];if(!t)return[[-1,e]];let{cleanupSemantic:n=!0}=r,{wordArray:o,tokenIds1:i,tokenIds2:a}=Ns(e,t,r);if(o.length>bs)return Ss(i,a,o);let s=xs(r),l=s.diff_main(Xo(i),Xo(a));return n&&s.diff_cleanupSemantic(l),Ts(l,o)}function Cr(e,t,r={}){if(e===t)return[{type:Oe.EQUAL,startOffset:0,endOffset:e.length,text:e}];if(!e)return[{type:Oe.INSERT,startOffset:0,endOffset:0,text:t}];if(!t)return[{type:Oe.DELETE,startOffset:0,endOffset:e.length,text:e}];let n=Qt(e,t,r),o=[],i=0;for(let[a,s]of n)a===0?(o.push({type:Oe.EQUAL,startOffset:i,endOffset:i+s.length,text:s}),i+=s.length):a===-1?(o.push({type:Oe.DELETE,startOffset:i,endOffset:i+s.length,text:s}),i+=s.length):a===1&&o.push({type:Oe.INSERT,startOffset:i,endOffset:i,text:s});return o}var Es=/\s+xmlns:[^=]+="[^"]*"/g;function Or(e,t){let r=Os(t),n=[],o=0;for(let i of e){if(i.kind!==B.TEXT&&i.kind!==B.HYPERLINK){n.push(i);continue}for(;o<r.length&&r[o]<=i.startOffset;)o++;let a=o,s=i.startOffset,l=!1;for(;a<r.length;){let u=r[a];if(u>=i.endOffset)break;u>s&&(l=!0,n.push({...i,text:i.text.slice(s-i.startOffset,u-i.startOffset),startOffset:s,endOffset:u}),s=u),a++}if(o=a,!l){n.push(i);continue}n.push({...i,text:i.text.slice(s-i.startOffset),startOffset:s,endOffset:i.endOffset})}return n}function kr(e,t,r){let{generateRedlines:n,author:o}=r,i=[],a=new Set,s=ks(t),l=Rs(e),u=Cs(s.nonInsertOps),c={containerStack:[],lastParagraphStartIndex:-1,currentParagraphPPrXml:"",currentParagraphPPrElement:null};for(let m of e){if(m.kind===B.CONTAINER_START){c.containerStack.push(m.containerId),i.push({...m});continue}if(m.kind===B.CONTAINER_END){c.containerStack.pop(),i.push({...m});continue}if(m.kind===B.PARAGRAPH_START){c.currentParagraphPPrXml=typeof m.pPrXml=="string"?m.pPrXml:"",c.currentParagraphPPrElement=m.pPrElement||null,i.push({...m}),c.lastParagraphStartIndex=i.length-1;continue}if(m.kind===B.BOOKMARK||m.kind===B.DELETION){i.push({...m});continue}let d=u(m.startOffset,m.endOffset),p=s.insertOpsByStartOffset.get(m.startOffset)||[];for(let b of p)a.has(b)||(a.add(b),Is({insertOp:b,splitModel:e,styleLookup:l,patchedModel:i,state:c,options:r,generateRedlines:n,author:o}));if(!d||d.type===Oe.EQUAL){i.push({...m,containerContext:c.containerStack.length>0?c.containerStack[c.containerStack.length-1]:null});continue}d.type===Oe.DELETE&&n&&i.push({...m,kind:B.DELETION,author:o,containerContext:c.containerStack.length>0?c.containerStack[c.containerStack.length-1]:null})}let f=e.length>0?Math.max(...e.map(m=>m.endOffset)):0;for(let m of s.sortedInsertOps){if(m.startOffset<f||a.has(m))continue;let d=e[e.length-1];i.push({kind:n?B.INSERTION:B.TEXT,text:m.text,rPrXml:d?.rPrXml||"",startOffset:m.startOffset,endOffset:m.startOffset+m.text.length,author:n?o:void 0})}return i}function Is(e){let{insertOp:t,styleLookup:r,patchedModel:n,state:o,options:i,generateRedlines:a,author:s}=e,l=t.text.split(`
12
+ `),u=Ps(r,t.startOffset,t.text);for(let c=0;c<l.length;c++){let f=As(l[c],i.numberingService,o),m=f.lineText;if(c>0){let d=Wo(o);f.isListLine&&f.numId&&(d=i.numberingService.buildListPPr(f.numId,f.ilvl)),n.push({kind:B.PARAGRAPH_START,pPrXml:d,startOffset:t.startOffset,endOffset:t.startOffset,text:""}),o.currentParagraphPPrXml=d,o.currentParagraphPPrElement=null,o.lastParagraphStartIndex=n.length-1}else if(f.isListLine&&f.numId&&o.lastParagraphStartIndex>=0){let d=i.numberingService.buildListPPr(f.numId,f.ilvl);n[o.lastParagraphStartIndex].pPrXml=d,n[o.lastParagraphStartIndex].pPrElement=null,o.currentParagraphPPrXml=d,o.currentParagraphPPrElement=null,k(`[Patching] Converted current paragraph to list item: numId=${f.numId}, ilvl=${f.ilvl}`)}(m.length>0||c>0)&&n.push({kind:a?B.INSERTION:B.TEXT,text:m,rPrXml:u?.rPrXml||"",startOffset:t.startOffset,endOffset:t.startOffset+m.length,author:a?s:void 0,containerContext:o.containerStack.length>0?o.containerStack[o.containerStack.length-1]:null})}}function As(e,t,r){if(!t)return{lineText:e,isListLine:!1,numId:null,ilvl:0};let n=Be(e,{allowZeroSpaceAfterMarker:!0});if(!n)return{lineText:e,isListLine:!1,numId:null,ilvl:0};let o=n[2].trim(),i=t.detectNumberingFormat(o),a=e.match(/^(\s*)/),s=a?a[1].length:0,l=s>=4?4:2,u=Math.floor(s/l),c=Wo(r),f=We(e,{allowZeroSpaceAfterMarker:!0}),m=c.match(/w:numId w:val="(\d+)"/),d=c.match(/w:ilvl w:val="(\d+)"/),p=m?m[1]:null,b=d?parseInt(d[1],10):0,w=t.getOrCreateNumId({type:i.format},{numId:p,type:"unknown"}),g=i.format==="outline"?Math.min(8,i.depth):Math.min(8,u+b);return{lineText:f,isListLine:!0,numId:w,ilvl:g}}function Wo(e){return e.currentParagraphPPrXml?e.currentParagraphPPrXml:e.currentParagraphPPrElement?(e.currentParagraphPPrXml=oe(e.currentParagraphPPrElement).replace(Es,""),e.currentParagraphPPrXml):""}function Ps(e,t,r){let n=e.findRunBefore(t),o=e.findRunAfter(t);return!n&&!o?null:n?o?r&&r.endsWith(" ")?o:(r&&r.startsWith(" "),n):n:o}function Rs(e){let t=e.filter(o=>o.kind===B.TEXT),r=t.map(o=>o.startOffset),n=t.map(o=>o.endOffset);return{findRunBefore(o){let i=0,a=n.length-1,s=-1;for(;i<=a;){let l=i+a>>1;n[l]<=o?(s=l,i=l+1):a=l-1}return s>=0?t[s]:null},findRunAfter(o){let i=0,a=r.length-1,s=-1;for(;i<=a;){let l=i+a>>1;r[l]>=o?(s=l,a=l-1):i=l+1}return s>=0?t[s]:null}}}function Cs(e){let t=0;return(r,n)=>{for(;t<e.length&&e[t].endOffset<=r;)t++;let o=e[t];return o&&o.startOffset<=r&&o.endOffset>=n?o:null}}function Os(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 ks(e){let t=new Map,r=[],n=[];for(let o of e){if(o.type===Oe.INSERT){t.has(o.startOffset)||t.set(o.startOffset,[]),t.get(o.startOffset).push(o),n.push(o);continue}r.push(o)}return r.sort((o,i)=>o.startOffset-i.startOffset||o.endOffset-i.endOffset),n.sort((o,i)=>o.startOffset-i.startOffset||o.endOffset-i.endOffset),{insertOpsByStartOffset:t,nonInsertOps:r,sortedInsertOps:n}}var Vo="http://schemas.openxmlformats.org/wordprocessingml/2006/main",Ms="http://schemas.openxmlformats.org/officeDocument/2006/relationships",_s="http://schemas.microsoft.com/office/2006/xmlPackage",Uo="http://schemas.openxmlformats.org/package/2006/relationships",Ls='<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>',jo='<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/>';var Bs=`
13
+ <w:numbering xmlns:w="${Vo}">
14
14
  <w:abstractNum w:abstractNumId="0">
15
15
  <w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="bullet"/><w:lvlText w:val="&#8226;"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr></w:lvl>
16
16
  </w:abstractNum>
@@ -19,23 +19,23 @@ var Aa=Object.create;var bn=Object.defineProperty;var Ra=Object.getOwnPropertyDe
19
19
  </w:abstractNum>
20
20
  <w:num w:numId="1"><w:abstractNumId w:val="0"/></w:num>
21
21
  <w:num w:numId="2"><w:abstractNumId w:val="1"/></w:num>
22
- </w:numbering>`.trim();function Ei(e){return e?e.replace(/<\?xml[^>]*\?>/g,""):""}function jn(e,t=!0){let r=t?` xmlns:r="${xi}"`:"";return`<w:document xmlns:w="${Hn}"${r}><w:body>${e}</w:body></w:document>`}function Un(e){return`
22
+ </w:numbering>`.trim();function Fs(e){return e?e.replace(/<\?xml[^>]*\?>/g,""):""}function Go(e,t=!0){let r=t?` xmlns:r="${Ms}"`:"";return`<w:document xmlns:w="${Vo}"${r}><w:body>${e}</w:body></w:document>`}function Ho(e){return`
23
23
  <pkg:part pkg:name="/word/numbering.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml">
24
24
  <pkg:xmlData>
25
- ${Ei(e)}
25
+ ${Fs(e)}
26
26
  </pkg:xmlData>
27
- </pkg:part>`}function Gn(e,t="",r=""){return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
28
- <pkg:package xmlns:pkg="${Ni}">
27
+ </pkg:part>`}function Ko(e,t="",r=""){return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
28
+ <pkg:package xmlns:pkg="${_s}">
29
29
  <pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml">
30
30
  <pkg:xmlData>
31
- <Relationships xmlns="${zn}">
32
- ${vi}
31
+ <Relationships xmlns="${Uo}">
32
+ ${Ls}
33
33
  </Relationships>
34
34
  </pkg:xmlData>
35
35
  </pkg:part>
36
36
  <pkg:part pkg:name="/word/_rels/document.xml.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml">
37
37
  <pkg:xmlData>
38
- <Relationships xmlns="${zn}">
38
+ <Relationships xmlns="${Uo}">
39
39
  ${t}
40
40
  </Relationships>
41
41
  </pkg:xmlData>
@@ -45,7 +45,7 @@ var Aa=Object.create;var bn=Object.defineProperty;var Ra=Object.getOwnPropertyDe
45
45
  ${e}
46
46
  </pkg:xmlData>
47
47
  </pkg:part>
48
- </pkg:package>`}function Vn(e,t={}){let{includeNumbering:r=!1,numberingXml:n=null,appendTrailingParagraph:o=!0}=t,a=o?`${e}<w:p><w:pPr></w:pPr></w:p>`:e,i=jn(a,!0),s="",l="";return n?(s=Wn,l+=Un(n)):r&&(s=Wn,l+=Un(Ti)),Gn(i,s,l)}function Kn(e){let t=jn(e,!0);return Gn(t)}var yi=/\s+xmlns:[^=]+="[^"]*"/g;function xe(e,t,r=[],n={}){let o=Pi(n),{generateRedlines:a}=o,i=[],s="",l=null,c=[];function u(){if(c.length>0||i.length===0){let f="";s?f=He(s):l?(s=He(Q(l)),f=s):t&&(typeof t=="string"?f=t:f=Q(t),f=He(f)),i.push(`<w:p>${f}${c.join("")}</w:p>`),c=[]}}for(let f of e)switch(f.kind){case _.PARAGRAPH_START:(c.length>0||i.length>0)&&u(),s=f.pPrXml||"",l=f.pPrElement||null;break;case _.TEXT:c.push(Yn(f,r,o));break;case _.DELETION:a&&c.push(Si(f,o));break;case _.INSERTION:a?c.push(Ii(f,r,o)):c.push(Yn(f,r,o));break;case _.BOOKMARK:case _.HYPERLINK:f.nodeXml&&c.push(He(f.nodeXml));break;case _.CONTAINER_START:if(f.containerKind==="sdt")c.push(`<w:sdt>${f.propertiesXml}<w:sdtContent>`);else if(f.containerKind==="smartTag")c.push(`<w:smartTag ${f.propertiesXml}>`);else if(f.containerKind==="hyperlink"){let m=JSON.parse(f.propertiesXml),p=m.rId?` r:id="${m.rId}"`:"",d=m.anchor?` w:anchor="${m.anchor}"`:"";c.push(`<w:hyperlink${p}${d}>`)}break;case _.CONTAINER_END:f.containerKind==="sdt"?c.push("</w:sdtContent></w:sdt>"):f.containerKind==="smartTag"?c.push("</w:smartTag>"):f.containerKind==="hyperlink"&&c.push("</w:hyperlink>");break;default:Se("Unknown run kind:",f.kind)}return u(),i.join("")}function Pi(e){if(typeof e=="string")return{author:re(),generateRedlines:!0,font:e,revisionIdAllocator:null};let t=e&&typeof e=="object"?e:{};return{author:typeof t.author=="string"&&t.author.trim()?t.author.trim():re(),generateRedlines:t.generateRedlines??!0,font:t.font??null,revisionIdAllocator:t.revisionIdAllocator??null}}function Yn(e,t,r={}){let n=Ie(t,e.startOffset,e.endOffset),o=r?.font??null,a=e.rPrXml?He(e.rPrXml):"";if(o&&(a=Fr(a,o)),n.length===0)return Be(e.text,a);let i=[],s=0,l=e.text,c=e.startOffset;for(let u of n){let f=Math.max(0,u.start-c),m=Math.min(l.length,u.end-c);f>s&&i.push(Be(l.slice(s,f),a));let p=Zn(a,u.format);i.push(Be(l.slice(f,m),p)),s=m}return s<l.length&&i.push(Be(l.slice(s),a)),i.join("")}function Be(e,t){return e?`<w:r>${t||""}<w:t xml:space="preserve">${pe(e)}</w:t></w:r>`:""}function Si(e,t={}){let r=ie(t.author??re(),t.revisionIdAllocator),n=t.font??null,o=e.rPrXml?He(e.rPrXml):"";return n&&(o=Fr(o,n)),`<w:del w:id="${r.id}" w:author="${pe(r.author)}" w:date="${r.date}"><w:r>${o}<w:delText xml:space="preserve">${pe(e.text)}</w:delText></w:r></w:del>`}function Ii(e,t,r={}){let n=ie(r.author??re(),r.revisionIdAllocator),o=r.font??null,a=Ie(t,e.startOffset,e.endOffset),i="",s=e.rPrXml?He(e.rPrXml):"";if(o&&(s=Fr(s,o)),a.length===0)i=Be(e.text,s);else{let l=0,c=e.text,u=e.startOffset;for(let f of a){let m=Math.max(0,f.start-u),p=Math.min(c.length,f.end-u);m>l&&(i+=Be(c.slice(l,m),s));let d=Zn(s,f.format);i+=Be(c.slice(m,p),d),l=p}l<c.length&&(i+=Be(c.slice(l),s))}return`<w:ins w:id="${n.id}" w:author="${pe(n.author)}" w:date="${n.date}">`+i+"</w:ins>"}function Fr(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 Zn(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 Fe(e,t={}){let r=Ai(t);return Vn(e,r)}function Ai(e){return typeof e=="boolean"?{includeNumbering:e}:!e||typeof e!="object"?{}:{includeNumbering:e.includeNumbering??!1,numberingXml:e.numberingXml??null,appendTrailingParagraph:e.appendTrailingParagraph??!0}}function He(e){return e?e.replace(yi,""):""}var Et=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||z.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===z.OUTLINE)return"3";if(n===z.DECIMAL)return"2";if(n===z.BULLET)return"1";if((r?parseInt(r.ilvl||"0"):0)===0&&n!==z.DECIMAL&&n!==z.BULLET){let a=`custom_${n}`;if(this.contextMap.has(a))return this.contextMap.get(a);let i=String(this.nextNumId++);return this.customConfigs.push({numId:i,levels:[{format:n,suffix:t.suffix||ne.PERIOD}]}),this.contextMap.set(a,i),i}return"2"}detectNumberingFormat(t){let r=(t||"").trim();if(!r)return{format:z.BULLET,suffix:ne.NONE,depth:0};if(/^[-*•]$/.test(r))return{format:z.BULLET,suffix:ne.NONE,depth:0};let n=r.match(/^(\d+(?:\.\d+)+)\.?$/);if(n){let o=n[1].split(".").length-1;return{format:z.OUTLINE,suffix:ne.PERIOD,depth:o}}return/^\([a-z]\)$/.test(r)?{format:z.LOWER_ALPHA,suffix:ne.PAREN_BOTH,depth:0}:/^\([ivxlc]+\)$/i.test(r)?{format:r===r.toLowerCase()?z.LOWER_ROMAN:z.UPPER_ROMAN,suffix:ne.PAREN_BOTH,depth:0}:/^\(\d+\)$/.test(r)?{format:z.DECIMAL,suffix:ne.PAREN_BOTH,depth:0}:/^\d+\.$/.test(r)?{format:z.DECIMAL,suffix:ne.PERIOD,depth:0}:/^[a-z]\.$/.test(r)?{format:z.LOWER_ALPHA,suffix:ne.PERIOD,depth:0}:/^[A-Z]\.$/.test(r)?{format:z.UPPER_ALPHA,suffix:ne.PERIOD,depth:0}:/^[ivxlc]+\.$/i.test(r)?{format:r===r.toLowerCase()?z.LOWER_ROMAN:z.UPPER_ROMAN,suffix:ne.PERIOD,depth:0}:/^\d+/.test(r)?{format:z.DECIMAL,suffix:ne.PERIOD,depth:0}:{format:z.BULLET,suffix:ne.NONE,depth:0}}formatToOoxmlNumFmt(t){return{[z.DECIMAL]:"decimal",[z.LOWER_ALPHA]:"lowerLetter",[z.UPPER_ALPHA]:"upperLetter",[z.LOWER_ROMAN]:"lowerRoman",[z.UPPER_ROMAN]:"upperRoman",[z.BULLET]:"bullet",[z.OUTLINE]:"decimal"}[t]||"decimal"}suffixToOoxmlLevelText(t,r,n=0){if(t===z.BULLET)return"\u2022";let o=`%${n+1}`;if(t===z.OUTLINE)return Array(n+1).fill(0).map((a,i)=>`%${i+1}`).join(".")+".";switch(r){case ne.PERIOD:return`${o}.`;case ne.PAREN_RIGHT:return`${o})`;case ne.PAREN_BOTH:return`(${o})`;default:return o}}buildListPPr(t,r,n={}){return`
48
+ </pkg:package>`}function Yo(e,t={}){let{includeNumbering:r=!1,numberingXml:n=null,appendTrailingParagraph:o=!0}=t,i=o?`${e}<w:p><w:pPr></w:pPr></w:p>`:e,a=Go(i,!0),s="",l="";return n?(s=jo,l+=Ho(n)):r&&(s=jo,l+=Ho(Bs)),Ko(a,s,l)}function Jo(e){let t=Go(e,!0);return Ko(t)}var $s=/\s+xmlns:[^=]+="[^"]*"/g;function Fe(e,t,r=[],n={}){let o=Xs(n),{generateRedlines:i}=o,a=[],s="",l=null,u=[];function c(){if(u.length>0||a.length===0){let f="";s?f=ct(s):l?(s=ct(oe(l)),f=s):t&&(typeof t=="string"?f=t:f=oe(t),f=ct(f)),a.push(`<w:p>${f}${u.join("")}</w:p>`),u=[]}}for(let f of e)switch(f.kind){case B.PARAGRAPH_START:(u.length>0||a.length>0)&&c(),s=f.pPrXml||"",l=f.pPrElement||null;break;case B.TEXT:u.push(qo(f,r,o));break;case B.DELETION:i&&u.push(Ds(f,o));break;case B.INSERTION:i?u.push(zs(f,r,o)):u.push(qo(f,r,o));break;case B.BOOKMARK:case B.HYPERLINK:f.nodeXml&&u.push(ct(f.nodeXml));break;case B.CONTAINER_START:if(f.containerKind==="sdt")u.push(`<w:sdt>${f.propertiesXml}<w:sdtContent>`);else if(f.containerKind==="smartTag")u.push(`<w:smartTag ${f.propertiesXml}>`);else if(f.containerKind==="hyperlink"){let m=JSON.parse(f.propertiesXml),d=m.rId?` r:id="${m.rId}"`:"",p=m.anchor?` w:anchor="${m.anchor}"`:"";u.push(`<w:hyperlink${d}${p}>`)}break;case B.CONTAINER_END:f.containerKind==="sdt"?u.push("</w:sdtContent></w:sdt>"):f.containerKind==="smartTag"?u.push("</w:smartTag>"):f.containerKind==="hyperlink"&&u.push("</w:hyperlink>");break;default:Le("Unknown run kind:",f.kind)}return c(),a.join("")}function Xs(e){if(typeof e=="string")return{author:me(),generateRedlines:!0,font:e,revisionIdAllocator:null};let t=e&&typeof e=="object"?e:{};return{author:typeof t.author=="string"&&t.author.trim()?t.author.trim():me(),generateRedlines:t.generateRedlines??!0,font:t.font??null,revisionIdAllocator:t.revisionIdAllocator??null}}function qo(e,t,r={}){let n=Ve(t,e.startOffset,e.endOffset),o=r?.font??null,i=e.rPrXml?ct(e.rPrXml):"";if(o&&(i=Sn(i,o)),n.length===0)return Qe(e.text,i);let a=[],s=0,l=e.text,u=e.startOffset;for(let c of n){let f=Math.max(0,c.start-u),m=Math.min(l.length,c.end-u);f>s&&a.push(Qe(l.slice(s,f),i));let d=Zo(i,c.format);a.push(Qe(l.slice(f,m),d)),s=m}return s<l.length&&a.push(Qe(l.slice(s),i)),a.join("")}function Qe(e,t){return e?`<w:r>${t||""}<w:t xml:space="preserve">${we(e)}</w:t></w:r>`:""}function Ds(e,t={}){let r=ie(t.author??me(),t.revisionIdAllocator,"del"),n=t.font??null,o=e.rPrXml?ct(e.rPrXml):"";return n&&(o=Sn(o,n)),`<w:del w:id="${r.id}" w:author="${we(r.author)}" w:date="${r.date}"><w:r>${o}<w:delText xml:space="preserve">${we(e.text)}</w:delText></w:r></w:del>`}function zs(e,t,r={}){let n=ie(r.author??me(),r.revisionIdAllocator,"ins"),o=r.font??null,i=Ve(t,e.startOffset,e.endOffset),a="",s=e.rPrXml?ct(e.rPrXml):"";if(o&&(s=Sn(s,o)),i.length===0)a=Qe(e.text,s);else{let l=0,u=e.text,c=e.startOffset;for(let f of i){let m=Math.max(0,f.start-c),d=Math.min(u.length,f.end-c);m>l&&(a+=Qe(u.slice(l,m),s));let p=Zo(s,f.format);a+=Qe(u.slice(m,d),p),l=d}l<u.length&&(a+=Qe(u.slice(l),s))}return`<w:ins w:id="${n.id}" w:author="${we(n.author)}" w:date="${n.date}">`+a+"</w:ins>"}function Sn(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 Zo(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 et(e,t={}){let r=Ws(t);return Yo(e,r)}function Ws(e){return typeof e=="boolean"?{includeNumbering:e}:!e||typeof e!="object"?{}:{includeNumbering:e.includeNumbering??!1,numberingXml:e.numberingXml??null,appendTrailingParagraph:e.appendTrailingParagraph??!0}}function ct(e){return e?e.replace($s,""):""}function En(e){let t=String(e??"");return/^\d+$/.test(t)&&Number.parseInt(t,10)>0}var Ge=class{constructor(){this.contextMap=new Map,this.nextNumId=1e3,this.customConfigs=[]}registerExistingNumId(t,r){En(r)&&this.contextMap.set(t,String(r))}getOrCreateNumId(t,r=null){let n=t.type||V.BULLET;if(r&&En(r.numId)&&(r.type===n||r.type==="unknown"))return r.numId;if(this.contextMap.has(n)){let i=this.contextMap.get(n);if(En(i))return i;this.contextMap.delete(n)}if(n===V.OUTLINE)return"3";if(n===V.DECIMAL)return"2";if(n===V.BULLET)return"1";if((r?parseInt(r.ilvl||"0"):0)===0&&n!==V.DECIMAL&&n!==V.BULLET){let i=`custom_${n}`;if(this.contextMap.has(i))return this.contextMap.get(i);let a=String(this.nextNumId++);return this.customConfigs.push({numId:a,levels:[{format:n,suffix:t.suffix||he.PERIOD}]}),this.contextMap.set(i,a),a}return"2"}detectNumberingFormat(t){let r=(t||"").trim();if(!r)return{format:V.BULLET,suffix:he.NONE,depth:0};if(/^[-*•]$/.test(r))return{format:V.BULLET,suffix:he.NONE,depth:0};let n=r.match(/^(\d+(?:\.\d+)+)\.?$/);if(n){let o=n[1].split(".").length-1;return{format:V.OUTLINE,suffix:he.PERIOD,depth:o}}return/^\([a-z]\)$/.test(r)?{format:V.LOWER_ALPHA,suffix:he.PAREN_BOTH,depth:0}:/^\([ivxlc]+\)$/i.test(r)?{format:r===r.toLowerCase()?V.LOWER_ROMAN:V.UPPER_ROMAN,suffix:he.PAREN_BOTH,depth:0}:/^\(\d+\)$/.test(r)?{format:V.DECIMAL,suffix:he.PAREN_BOTH,depth:0}:/^\d+\.$/.test(r)?{format:V.DECIMAL,suffix:he.PERIOD,depth:0}:/^[a-z]\.$/.test(r)?{format:V.LOWER_ALPHA,suffix:he.PERIOD,depth:0}:/^[A-Z]\.$/.test(r)?{format:V.UPPER_ALPHA,suffix:he.PERIOD,depth:0}:/^[ivxlc]+\.$/i.test(r)?{format:r===r.toLowerCase()?V.LOWER_ROMAN:V.UPPER_ROMAN,suffix:he.PERIOD,depth:0}:/^\d+/.test(r)?{format:V.DECIMAL,suffix:he.PERIOD,depth:0}:{format:V.BULLET,suffix:he.NONE,depth:0}}formatToOoxmlNumFmt(t){return{[V.DECIMAL]:"decimal",[V.LOWER_ALPHA]:"lowerLetter",[V.UPPER_ALPHA]:"upperLetter",[V.LOWER_ROMAN]:"lowerRoman",[V.UPPER_ROMAN]:"upperRoman",[V.BULLET]:"bullet",[V.OUTLINE]:"decimal"}[t]||"decimal"}suffixToOoxmlLevelText(t,r,n=0){if(t===V.BULLET)return"\u2022";let o=`%${n+1}`;if(t===V.OUTLINE)return Array(n+1).fill(0).map((i,a)=>`%${a+1}`).join(".")+".";switch(r){case he.PERIOD:return`${o}.`;case he.PAREN_RIGHT:return`${o})`;case he.PAREN_BOTH:return`(${o})`;default:return o}}buildListPPr(t,r,n={}){return`
49
49
  <w:pPr>${n.includeListParagraphStyle===!0?`
50
50
  <w:pStyle w:val="ListParagraph"/>`:""}
51
51
  <w:numPr>
@@ -72,7 +72,7 @@ var Aa=Object.create;var bn=Object.defineProperty;var Ra=Object.getOwnPropertyDe
72
72
  <w:lvl w:ilvl="2"><w:start w:val="1"/><w:numFmt w:val="lowerRoman"/><w:lvlText w:val="(%3)"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="2160" w:hanging="360"/></w:pPr></w:lvl>
73
73
  <w:lvl w:ilvl="3"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="(%4)"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="2880" w:hanging="360"/></w:pPr></w:lvl>
74
74
  <w:lvl w:ilvl="4"><w:start w:val="1"/><w:numFmt w:val="lowerLetter"/><w:lvlText w:val="%5."/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="3600" w:hanging="360"/></w:pPr></w:lvl>
75
- </w:abstractNum>`,a=`
75
+ </w:abstractNum>`,i=`
76
76
  <w:abstractNum w:abstractNumId="2">
77
77
  <w:multiLevelType w:val="multilevel"/>
78
78
  <w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1."/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr></w:lvl>
@@ -80,8 +80,8 @@ var Aa=Object.create;var bn=Object.defineProperty;var Ra=Object.getOwnPropertyDe
80
80
  <w:lvl w:ilvl="2"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1.%2.%3"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="2160" w:hanging="360"/></w:pPr></w:lvl>
81
81
  <w:lvl w:ilvl="3"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1.%2.%3.%4"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="2880" w:hanging="360"/></w:pPr></w:lvl>
82
82
  <w:lvl w:ilvl="4"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1.%2.%3.%4.%5"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="3600" w:hanging="360"/></w:pPr></w:lvl>
83
- </w:abstractNum>`,i="",s="";return r.forEach((l,c)=>{let u=10+c;i+=`
84
- <w:abstractNum w:abstractNumId="${u}">
83
+ </w:abstractNum>`,a="",s="";return r.forEach((l,u)=>{let c=10+u;a+=`
84
+ <w:abstractNum w:abstractNumId="${c}">
85
85
  <w:multiLevelType w:val="multilevel"/>
86
86
  ${l.levels.map((f,m)=>`
87
87
  <w:lvl w:ilvl="${m}">
@@ -93,13 +93,13 @@ var Aa=Object.create;var bn=Object.defineProperty;var Ra=Object.getOwnPropertyDe
93
93
  </w:lvl>`).join("")}
94
94
  </w:abstractNum>`,s+=`
95
95
  <w:num w:numId="${l.numId}">
96
- <w:abstractNumId w:val="${u}"/>
96
+ <w:abstractNumId w:val="${c}"/>
97
97
  </w:num>`}),`
98
98
  <w:numbering xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
99
99
  ${n}
100
100
  ${o}
101
- ${a}
102
101
  ${i}
102
+ ${a}
103
103
  <w:num w:numId="1">
104
104
  <w:abstractNumId w:val="0"/>
105
105
  </w:num>
@@ -110,7 +110,7 @@ var Aa=Object.create;var bn=Object.defineProperty;var Ra=Object.getOwnPropertyDe
110
110
  <w:abstractNumId w:val="2"/>
111
111
  </w:num>
112
112
  ${s}
113
- </w:numbering>`}};function je(e,t={}){let{generateRedlines:r=!1,author:n="AI",revisionIdAllocator:o=null}=t,a=r?ie(n,o):null,i=e.headers?.length||e.rows?.[0]?.length||1,s=`
113
+ </w:numbering>`}};function ut(e,t={}){let{generateRedlines:r=!1,author:n="AI",revisionIdAllocator:o=null,trackAsBlock:i=!1}=t,a=r&&i?ie(n,o):null,s=e.headers?.length||e.rows?.[0]?.length||1,l=`
114
114
  <w:tblPr>
115
115
  <w:tblW w:w="5000" w:type="pct"/>
116
116
  <w:tblBorders>
@@ -123,78 +123,89 @@ var Aa=Object.create;var bn=Object.defineProperty;var Ra=Object.getOwnPropertyDe
123
123
  </w:tblBorders>
124
124
  <w:tblLook w:val="04A0" w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="1"/>
125
125
  </w:tblPr>
126
- `.trim(),c=`<w:tblGrid>${Array(i).fill("<w:gridCol/>").join("")}</w:tblGrid>`,u=e.hasHeader?[e.headers,...e.rows]:e.rows,f="";for(let p=0;p<u.length;p++){let d=e.hasHeader&&p===0,g=u[p]||[],h="";for(let b=0;b<i;b++){let v=g[b]||"",{cleanText:E,formatHints:P}=le(v),x=[{kind:r?_.INSERTION:_.TEXT,text:E,rPrXml:d?"<w:rPr><w:b/></w:rPr>":"",author:n,startOffset:0,endOffset:E.length}],N=xe(x,null,P,{author:n,generateRedlines:r,revisionIdAllocator:o});h+=`<w:tc><w:tcPr><w:tcW w:w="0" w:type="auto"/></w:tcPr>${N}</w:tc>`}f+=`<w:tr><w:trPr/>${h}</w:tr>`}let m=`<w:tbl>${s}${c}${f}</w:tbl>`;return a&&(m=`<w:ins w:id="${a.id}" w:author="${pe(a.author)}" w:date="${a.date}">${m}</w:ins>`),m}function Jn(e,t){let r=[],{headers:n,rows:o,hasHeader:a}=t,i=a?[n,...o]:o,s=Math.max(e.rowCount,i.length);for(let l=0;l<s;l++){if(l>=e.rowCount&&i[l]){r.push({type:"row_insert",gridRow:l,cells:i[l]});continue}if(l<e.rowCount&&!i[l]){r.push({type:"row_delete",gridRow:l});continue}let c=i[l];for(let u=0;u<e.colCount;u++){let f=e.grid[l]?.[u],m=c?.[u];f&&(f.isMergeContinuation||u>f.gridCol||m!==void 0&&f.getText()!==m&&r.push({type:"cell_modify",gridRow:l,gridCol:u,originalCell:f,newText:m}))}}return r}function Qn(e,t,r){let{generateRedlines:n,author:o,revisionIdAllocator:a=null}=r,i=Ri(t),s="";for(let c=0;c<e.rowCount;c++){let u=i.rowDeleteByRow.get(c)||null;if(u&&!n)continue;let f="",m=0;for(;m<e.colCount;){let d=e.grid[c][m];if(!d){m++;continue}if(d.isMergeContinuation){m++;continue}let g=i.cellModifyByCoordinate.get(`${c}:${m}`)||null,h;g?h=Ci(d,g.newText,r):h=Oi(d.blocks),f+=ki(d,h,r),m+=d.colSpan}let p=e.trPrList[c]||"<w:trPr/>";if(u&&n){let d=ie(o,a),g=`<w:del w:id="${d.id}" w:author="${pe(d.author)}" w:date="${d.date}"/>`;p.includes("</w:trPr>")?p=p.replace("</w:trPr>",`${g}</w:trPr>`):p=`<w:trPr>${g}</w:trPr>`}s+=`<w:tr>${p}${f}</w:tr>`}let l=i.rowInsertOperations;for(let c of l){let u="",f=n?ie(o,a):null;for(let p of c.cells){let{cleanText:d,formatHints:g}=le(p),h=[{kind:n?_.INSERTION:_.TEXT,text:d,rPrXml:"",author:o,startOffset:0,endOffset:d.length}],w=xe(h,null,g,{author:o,generateRedlines:n,revisionIdAllocator:a});u+=`<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="${pe(f.author)}" w:date="${f.date}"/></w:trPr>`),s+=`<w:tr>${m}${u}</w:tr>`}return`
126
+ `.trim(),c=`<w:tblGrid>${Array(s).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 b=e.hasHeader&&p===0,w=f[p]||[],g="";for(let x=0;x<s;x++){let v=w[x]||"",{cleanText:T,formatHints:y}=Ee(v),N=[{kind:r&&!i?B.INSERTION:B.TEXT,text:T,rPrXml:b?"<w:rPr><w:b/></w:rPr>":"",author:n,startOffset:0,endOffset:T.length}],E=Fe(N,null,y,{author:n,generateRedlines:r,revisionIdAllocator:o});g+=`<w:tc><w:tcPr><w:tcW w:w="0" w:type="auto"/></w:tcPr>${E}</w:tc>`}m+=`<w:tr>${b?"<w:trPr><w:tblHeader/><w:cantSplit/></w:trPr>":"<w:trPr><w:cantSplit/></w:trPr>"}${g}</w:tr>`}let d=`<w:tbl>${l}${c}${m}</w:tbl>`;return a&&(d=`<w:ins w:id="${a.id}" w:author="${we(a.author)}" w:date="${a.date}">${d}</w:ins>`),d}function Qo(e,t){let r=[],{headers:n,rows:o,hasHeader:i}=t,a=i?[n,...o]:o,s=Math.max(e.rowCount,a.length);for(let l=0;l<s;l++){if(l>=e.rowCount&&a[l]){r.push({type:"row_insert",gridRow:l,cells:a[l]});continue}if(l<e.rowCount&&!a[l]){r.push({type:"row_delete",gridRow:l});continue}let u=a[l];for(let c=0;c<e.colCount;c++){let f=e.grid[l]?.[c],m=u?.[c];f&&(f.isMergeContinuation||c>f.gridCol||m!==void 0&&f.getText()!==m&&r.push({type:"cell_modify",gridRow:l,gridCol:c,originalCell:f,newText:m}))}}return r}function ei(e,t,r){let{generateRedlines:n,author:o,revisionIdAllocator:i=null}=r,a=Us(t),s="";for(let u=0;u<e.rowCount;u++){let c=a.rowDeleteByRow.get(u)||null;if(c&&!n)continue;let f="",m=0;for(;m<e.colCount;){let p=e.grid[u][m];if(!p){m++;continue}if(p.isMergeContinuation){m++;continue}let b=a.cellModifyByCoordinate.get(`${u}:${m}`)||null,w;b?w=js(p,b.newText,r):w=Hs(p.blocks),f+=Vs(p,w,r),m+=p.colSpan}let d=e.trPrList[u]||"<w:trPr/>";if(c&&n){let p=ie(o,i),b=`<w:del w:id="${p.id}" w:author="${we(p.author)}" w:date="${p.date}"/>`;d.includes("</w:trPr>")?d=d.replace("</w:trPr>",`${b}</w:trPr>`):d=`<w:trPr>${b}</w:trPr>`}s+=`<w:tr>${d}${f}</w:tr>`}let l=a.rowInsertOperations;for(let u of l){let c="",f=n?ie(o,i):null;for(let d of u.cells){let{cleanText:p,formatHints:b}=Ee(d),w=[{kind:n?B.INSERTION:B.TEXT,text:p,rPrXml:"",author:o,startOffset:0,endOffset:p.length}],g=Fe(w,null,b,{author:o,generateRedlines:n,revisionIdAllocator:i});c+=`<w:tc><w:tcPr><w:tcW w:w="0" w:type="auto"/></w:tcPr>${g}</w:tc>`}let m="<w:trPr/>";n&&(m=`<w:trPr><w:ins w:id="${f.id}" w:author="${we(f.author)}" w:date="${f.date}"/></w:trPr>`),s+=`<w:tr>${m}${c}</w:tr>`}return`
127
127
  <w:tbl>
128
128
  ${e.tblPrXml}
129
129
  ${e.tblGridXml}
130
130
  ${s}
131
131
  </w:tbl>
132
- `}function Ri(e){let t=new Map,r=new Map,n=[];for(let o of e)o.type==="row_delete"?t.set(o.gridRow,o):o.type==="cell_modify"?r.set(`${o.gridRow}:${o.gridCol}`,o):o.type==="row_insert"&&n.push(o);return n.sort((o,a)=>o.gridRow-a.gridRow),{rowDeleteByRow:t,cellModifyByCoordinate:r,rowInsertOperations:n}}function Ci(e,t,r){let{generateRedlines:n,author:o,revisionIdAllocator:a=null}=r,{cleanText:i,formatHints:s}=le(t),l=e.getText(),c=Kt(l,i),u=e.blocks[0]||{runModel:[],pPr:null},f=Yt(u.runModel,c),m=Zt(f,c,{generateRedlines:n,author:o,formatHints:s});return xe(m,u.pPr,s,{author:o,generateRedlines:n,revisionIdAllocator:a})}function Oi(e){return e.map(t=>xe(t.runModel,t.pPr,[],{})).join("")}function ki(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 Ne(e){let t=e.split(`
133
- `).map(i=>i.trim()).filter(i=>i.startsWith("|"));if(t.length===0)return{headers:[],rows:[],hasHeader:!1};let r=i=>{let s=i.replace(/\s+/g,"");return/^\|:?-{3,}:?(\|:?-{3,}:?)+\|?$/.test(s)},n=t.some(r),a=t.filter(i=>!r(i)).map(i=>i.split("|").slice(1,-1).map(s=>s.trim()));return n?{headers:a[0]||[],rows:a.slice(1),hasHeader:!0}:{headers:[],rows:a,hasHeader:!1}}async function qn(e){let{cleanText:t,numberingContext:r,originalRunModel:n=[],originalText:o="",generateRedlines:a=!0,author:i="AI",font:s=null,revisionIdAllocator:l=null,numberingService:c}=e,u=Li(t),f=Mi(u),m=f.map(x=>x.raw),p=[],d=[];if(a){if(n&&n.length>0)d=n.filter(x=>x.kind==="text"||x.kind==="run").map(x=>({...x,kind:"deletion",author:i}));else if(o&&o.trim().length>0){let x=o.trim();d=[{kind:"deletion",text:x,author:i,startOffset:0,endOffset:x.length}]}}let g=$r(m);I(`[ListGen] Detected indentation step: ${g} spaces/chars`);let h=f.find(x=>x.marker)?.marker||"",{format:w}=c.detectNumberingFormat(h);I(`[ListGen] Detected primary marker: "${h}", format: ${w}`);for(let x=0;x<f.length;x++){let N=_i(f,x);if(N){let C=Ne(N.tableText);if(C.headers.length>0||C.rows.length>0){a&&p.length===0&&d.length>0&&p.push(xe(d,null,[],{author:i,generateRedlines:a,font:s,revisionIdAllocator:l})),p.push(je(C,{generateRedlines:a,author:i,revisionIdAllocator:l})),x=N.endIndex;continue}}let A=f[x],k=Bi(A,x,g,r,c,a,i,s,l,d);p.push(k.ooxml)}let b=c.generateNumberingXml(),P=p.join("")+"<w:p><w:pPr></w:pPr></w:p>";return I(`[ListGen] \u2705 Generated OOXML for ${p.length} list items, total length: ${P.length}`),I(`[ListGen] First 200 chars: ${P.substring(0,200)}...`),{ooxml:P,isValid:!0,warnings:["Paragraph expanded to list fragment"],type:"fragment",includeNumbering:!0,numberingXml:b}}function $r(e){let t=e.map(n=>n.match(/^(\s*)/)[0].length).filter(n=>n>0).sort((n,o)=>n-o);if(t.length===0)return 2;let r=t[0];for(let n=1;n<t.length;n++){let o=t[n]-t[n-1];o>0&&o<r&&(r=o)}return r||2}function Mi(e){return e.split(`
134
- `).filter(t=>t.trim().length>0).map(t=>{let r=Ae(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 Li(e){let t=String(e||"").split(`
135
- `),r=t.map((i,s)=>({line:i,index:s})).filter(i=>i.line.trim().length>0);if(r.length<2)return e;let n=[],o=0;for(let{line:i,index:s}of r){let l=Ae(i);if(!l)return e;let c=_e(i),u=Ae(c);if(!u)return e;let f=(l[2]||"").trim(),m=(u[2]||"").trim();if(!f||!m||f===m)return e;let d=`${l[1]||""}${c.trimStart()}`;n.push({index:s,rewritten:d}),o++}if(o<2)return e;let a=t.slice();for(let i of n)a[i.index]=i.rewritten;return I(`[ListGen] Normalized ${o} composite list markers (e.g., "- A." -> "A.").`),a.join(`
136
- `)}function _i(e,t){let r=e[t],n=e[t+1];if(!r?.isTableLine||!n?.isTableLine||!n?.isTableSeparator)return null;let o=[],a=t;for(;a<e.length&&e[a].isTableLine;)o.push(e[a].raw),a++;return{tableText:o.join(`
137
- `),endIndex:a-1}}function Bi(e,t,r,n,o,a,i,s,l,c){let u="",f="";if(e.headerMatch){let g=Math.min(e.headerMatch[1].length,9),h=Math.min(g-1,8),w=[32,28,26,24,22,20,20,20,20],b=w[g-1]||w[w.length-1];f=e.headerMatch[2].trim(),u=`<w:pPr><w:pStyle w:val="Heading${g}"/><w:outlineLvl w:val="${h}"/><w:rPr><w:b/><w:sz w:val="${b}"/><w:szCs w:val="${b}"/></w:rPr></w:pPr>`}else if(e.marker){let g=o.detectNumberingFormat(e.marker),h=r>0?Math.floor(e.indentSize/r):0,w=n?.ilvl||0,b=g.format==="outline"?Math.min(8,g.depth):Math.min(8,h+w);f=_e(e.raw);let v=o.getOrCreateNumId({type:g.format},n);u=o.buildListPPr(v,b)}else f=e.raw;let{cleanText:m,formatHints:p}=le(f),d=[];return t===0&&c.length>0&&d.push(...c),d.push({kind:a?"insertion":"run",text:m,author:i,startOffset:0,endOffset:m.length}),{ooxml:xe(d,u,p,{author:i,generateRedlines:a,font:s,revisionIdAllocator:l})}}var Fi=new Set(["officeonline","officeweb","web"]);function $i(e){return e?Fi.has(String(e).toLowerCase()):!1}function Xi(){return typeof process<"u"&&process?.env?.NODE_ENV==="production"}function Di(){return new Promise(e=>setTimeout(e,0))}var Ge=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 Et,this.font=t.font||null,this.revisionIdAllocator=t.revisionIdAllocator||null,this.platform=t.platform??Er(),this.isWebPlatform=t.isWebPlatform??$i(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 o=[];try{let a=n.xmlDoc?{doc:n.xmlDoc,error:null,warnings:[]}:D(t,"application/xml");if(a.error||!a.doc)return{ooxml:t,isValid:!1,status:"error",error:a.error,warnings:a.warnings||[]};o.push(...a.warnings||[]);let i=a.doc,s=H(i,"*","p"),{runModel:l,acceptedText:c,pPr:u}=Ht(t,{xmlDoc:i}),f=s?kr(s):null;I(`[Reconcile] Ingested ${l.length} runs, ${c.length} chars, numbering:`,f),await this.maybeYield(l.length,Math.max(c.length,r?.length||0));let{cleanText:m,formatHints:p}=le(r);I(`[Reconcile] Preprocessed: ${p.length} format hints`),await this.maybeYield(l.length,Math.max(c.length,m.length));let d=Pr(m),g=Nt(m),h=d||g;if(!d&&g&&I("[Reconcile] List-target detected via loose marker parsing; bypassing no-op short-circuit for structural conversion."),c===m&&p.length===0&&!h)return I("[Reconcile] No changes detected"),{ooxml:t,isValid:!0,warnings:["No changes detected"]};let w=Math.max(c.length,m.length)<this.disableSemanticCleanupOverChars,b=Kt(c,m,{cleanupSemantic:w});w||I("[Reconcile] Skipping semantic diff cleanup for large web payload"),await this.maybeYield(l.length,Math.max(c.length,m.length));let v=l.filter(k=>k.kind===_.PARAGRAPH_START).length,E=Pr(c)||Nt(c),P=h&&E&&v>1&&c!==m;if(I(`[Reconcile] isTargetList: ${h}, paragraphCount: ${v}`),P)I("[Reconcile] Existing marked list edit detected; using run-aware patching to preserve formatting and paragraph boundaries.");else if(h)return I("[Reconcile] \u{1F3AF} ENTERING LIST GENERATION PATH"),I(`[Reconcile] cleanText preview: ${m.substring(0,100)}...`),I(`[Reconcile] acceptedText preview: ${c.substring(0,100)}...`),this.executeListGeneration(m,f,l);I(`[Reconcile] Computed ${b.length} diff operations`);let x=Yt(l,b);I(`[Reconcile] Split into ${x.length} runs`);let N=Zt(x,b,{generateRedlines:this.generateRedlines,author:this.author,formatHints:p,numberingService:this.numberingService});I(`[Reconcile] Patched model has ${N.length} runs`),await this.maybeYield(N.length,Math.max(c.length,m.length));let A=xe(N,u,p,{author:this.author,generateRedlines:this.generateRedlines,revisionIdAllocator:this.revisionIdAllocator});if(this.shouldRunValidation()){let k=this.validateBasic(A);k.isValid||o.push(...k.errors)}return{ooxml:A,isValid:o.length===0,warnings:o}}catch(a){return G("[Reconcile] Pipeline error:",a),{ooxml:t,isValid:!1,warnings:[`Pipeline error: ${a.message}`],error:a?.code?{code:a.code,message:a.message}:void 0}}}validateBasic(t){let r=[];try{let n=`<root xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">${t}</root>`,o=D(n,"application/xml"),a=o.doc;if(o.error||!a)return r.push("Generated OOXML is not well-formed XML: "+(o.error?.message||"parse error")),{isValid:!1,errors:r};let i=K(a);i&&r.push("Generated OOXML is not well-formed XML: "+i.textContent.substring(0,100)),t.includes("<w:p")||r.push("Generated OOXML missing paragraph element")}catch(n){r.push(`Validation error: ${n.message}`)}return{isValid:r.length===0,errors:r}}shouldRunValidation(){return this.validateOutput?this.validationMode==="always"?!0:this.validationMode==="never"?!1:!(this.isWebPlatform&&Xi()):!1}async maybeYield(t,r){this.enableEventLoopYielding&&(t<=this.yieldRunThreshold&&r<=this.yieldCharThreshold||await Di())}wrapForInsertion(t,r={}){return Fe(t,r)}async executeListGeneration(t,r,n,o=""){return qn({cleanText:t,numberingContext:r,originalRunModel:n,originalText:o,generateRedlines:this.generateRedlines,author:this.author,font:this.font,revisionIdAllocator:this.revisionIdAllocator,numberingService:this.numberingService})}detectIndentationStep(t){return $r(t)}executeTableGeneration(t){let r=Ne(t);return r.rows.length===0&&r.headers.length===0?{ooxml:"",isValid:!1,warnings:["Could not parse Markdown table"]}:{ooxml:je(r,{generateRedlines:this.generateRedlines,author:this.author,revisionIdAllocator:this.revisionIdAllocator}),isValid:!0,warnings:[],includeNumbering:!1}}};function R(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===y&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function S(e,t){return typeof e.createElementNS=="function"?e.createElementNS(y,t):e.createElement(t)}function zi(e,t){let r=Array.from(e?.getElementsByTagNameNS?.(y,t)||[]);return r.length>0?r:Array.from(e?.getElementsByTagName?.("*")||[]).filter(n=>R(n,t))}function Xr(e){return["ins","del","moveFrom","moveTo","moveFromRangeStart","moveFromRangeEnd","moveToRangeStart","moveToRangeEnd","rPrChange","pPrChange","cellIns","cellDel"].some(r=>zi(e,r).length>0)}function Wi(e){let t=String(e||"").trim();return/^<\?xml\b[^>]*>\s*<pkg:package\b/i.test(t)||/^<pkg:package\b/i.test(t)?"package":/^<\?xml\b[^>]*>\s*<(?:w:)?document\b/i.test(t)||/^<(?:w:)?document\b/i.test(t)?"document":"fragment"}function oe(e){return!e||typeof e!="object"||e.sourceType||typeof e.oxml!="string"?e:{...e,sourceType:Wi(e.oxml)}}var yt=["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 at(e,t){let r=yt.indexOf(t.nodeName),n=r===-1?999:r,o=!1;for(let a of Array.from(e.childNodes)){if(a.nodeType!==1)continue;let i=yt.indexOf(a.nodeName);if((i===-1?999:i)>n){e.insertBefore(t,a),o=!0;break}}o||e.appendChild(t)}function Ui(e,t,r,n){if(!t||!r)return;let o=!!r.bold,a=!!r.italic,i=!!r.underline,s=!!r.strikethrough,l=new Set;if(o&&(l.add("w:b"),l.add("w:bCs")),a&&(l.add("w:i"),l.add("w:iCs")),i&&l.add("w:u"),s&&l.add("w:strike"),l.size>0){let c=[];for(let u of Array.from(t.childNodes))l.has(u.nodeName)&&c.push(u);for(let u of c)t.removeChild(u)}if(o){let c=S(e,"w:b");c.setAttribute("w:val",n==="add"?"1":"0"),at(t,c);let u=S(e,"w:bCs");u.setAttribute("w:val",n==="add"?"1":"0"),at(t,u)}if(a){let c=S(e,"w:i");c.setAttribute("w:val",n==="add"?"1":"0"),at(t,c);let u=S(e,"w:iCs");u.setAttribute("w:val",n==="add"?"1":"0"),at(t,u)}if(i){let c=S(e,"w:u");c.setAttribute("w:val",n==="add"?"single":"none"),at(t,c)}if(s){let c=S(e,"w:strike");c.setAttribute("w:val",n==="add"?"1":"0"),at(t,c)}}function eo(e,t,r){Ui(e,t,r,"remove")}function Re(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=Jt(r,!1)),r.nodeName==="w:i"&&(t.italic=Jt(r,!1)),r.nodeName==="w:u"&&(t.underline=Jt(r,!0)),r.nodeName==="w:strike"&&(t.strikethrough=Jt(r,!1)),r.nodeName==="w:rStyle"){let n=r.getAttribute("w:val");if(n){let o=n.toLowerCase();(o.includes("bold")||o.includes("strong"))&&(t.bold=!0),(o.includes("italic")||o.includes("emphasis"))&&(t.italic=!0),o.includes("underline")&&(t.underline=!0)}}return t.hasFormatting=t.bold||t.italic||t.underline||t.strikethrough,t}function Jt(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 to="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function ye(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===to&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function Hi(e){return!e||e.nodeType!==1||e.namespaceURI!==to?!1:e.localName==="del"||e.localName==="moveFrom"}function ro(e){let t=[],r=Array.from(e?.childNodes||[]).reverse();for(;r.length>0;){let n=r.pop();if(!n||n.nodeType!==1||Hi(n))continue;if(ye(n,"r")){t.push(n);continue}let o=Array.from(n.childNodes||[]);for(let a=o.length-1;a>=0;a-=1)r.push(o[a])}return t}function Pe(e){let t=new Set(["comment","footnote","endnote"]);return J(e,"*","p").filter(n=>{let o=n.parentNode;for(;o&&o.nodeName;){let a=String(o.localName||"").toLowerCase();if(t.has(a))return!1;o=o.parentNode}return!0})}function no(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e[n],a=ro(o);for(let i of a){let s=V(i,"w:rPr");Array.from(i.childNodes||[]).forEach(l=>{if(ye(l,"t")){let c=l.textContent||"";c.length>0&&(t.push({charStart:r,charEnd:r+c.length,textElement:l,runElement:i,paragraph:o,container:i.parentNode,rPr:s}),r+=c.length)}else(ye(l,"br")||ye(l,"cr")||ye(l,"tab")||ye(l,"noBreakHyphen"))&&(t.push({charStart:r,charEnd:r+1,textElement:l,runElement:i,paragraph:o,container:i.parentNode,rPr:s}),r+=1)})}r=Ue(r,n,e.length)}return{textSpans:t,charOffset:r}}function ji(e,t,r,n,o,a=null){let i=null;for(let c of Array.from(e.childNodes))if(ye(c,"rPr")){i=c;break}let s=Re(i);a&&(a.bold&&!s.bold&&(s.bold=!0),a.italic&&!s.italic&&(s.italic=!0),a.underline&&!s.underline&&(s.underline=!0),a.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(ye(c,"t")){let u=c.textContent||"";if(u.length>0){let f=l,m=l+u.length;n.push({charStart:f,charEnd:m,textElement:c,runElement:e,paragraph:t,rPr:i,format:{...s}}),s.hasFormatting&&o.push({start:f,end:m,format:{...s},run:e,rPr:i}),l=m}}return l}function oo(e){let t=[],r=[],n=0,o=Pe(e);for(let a=0;a<o.length;a++){let i=o[a],s=null;for(let u of Array.from(i.childNodes))if(ye(u,"pPr")){for(let f of Array.from(u.childNodes))if(ye(f,"rPr")){s=f;break}break}let l=Re(s);l.hasFormatting&&I(`[OxmlEngine] Found paragraph-level formatting: ${JSON.stringify(l)}`);let c=ro(i);for(let u of c)n=ji(u,i,n,r,t,l);n=Ue(n,a,o.length)}return I(`[OxmlEngine] Extracted ${r.length} text spans, ${t.length} format hints`),{existingFormatHints:t,textSpans:r,paragraphs:o}}function Ve(e,t,r,n){let o=S(e,t==="ins"?"w:ins":"w:del"),a=ie(n,e);return o.setAttribute("w:id",String(a.id)),o.setAttribute("w:author",a.author),o.setAttribute("w:date",a.date),r&&o.appendChild(r),o}function ao(e,t){return Array.from(e?.childNodes||[]).find(r=>r.nodeType===1&&(r.localName===t||r.nodeName===`w:${t}`))||null}function Gi(e,t){let r=ao(t,"pPr");return r?t.firstChild!==r&&t.insertBefore(r,t.firstChild||null):(r=S(e,"w:pPr"),t.insertBefore(r,t.firstChild||null)),r}function Vi(e,t){let r=ao(t,"rPr");return r?t.lastChild!==r&&t.appendChild(r):(r=S(e,"w:rPr"),t.appendChild(r)),r}function io(e,t,r,n){let o=Gi(e,t),a=Vi(e,o);for(let l of Array.from(a.childNodes||[]))l.nodeType===1&&(l.localName==="ins"||l.localName==="del"||l.nodeName==="w:ins"||l.nodeName==="w:del")&&a.removeChild(l);let i=S(e,n==="ins"?"w:ins":"w:del"),s=ie(r,e);return i.setAttribute("w:id",String(s.id)),i.setAttribute("w:author",s.author),i.setAttribute("w:date",s.date),a.appendChild(i),i}function so(e,t,r){return io(e,t,r,"ins")}function Qt(e,t,r){return io(e,t,r,"del")}function Ke(e,t,r,n){let o=S(e,"w:r");if(r&&o.appendChild(r.cloneNode(!0)),!n)return lo(e,o,t),o;let a=S(e,n?"w:delText":"w:t");return a.setAttribute("xml:space","preserve"),a.textContent=t,o.appendChild(a),o}function qt(e,t,r,n,o,a,i){if(!t)return[];let s=new Set([0,t.length]);for(let u of n){let f=Math.max(0,u.start-o),m=Math.min(t.length,u.end-o);f>=0&&f<t.length&&s.add(f),m>0&&m<=t.length&&s.add(m)}let l=Array.from(s).sort((u,f)=>u-f),c=[];for(let u=0;u<l.length-1;u++){let f=l[u],m=l[u+1],p=t.slice(f,m);if(!p)continue;let d=o+f,g=o+m,h=n.filter(v=>v.start<=d&&v.end>=g),w={...Re(r)};h.forEach(v=>{v.format&&Object.assign(w,v.format)});let b=h.length>0?it(e,r,w,a,i):r?.cloneNode(!0)||null;c.push(Dr(e,p,b,!1))}return c}function Dr(e,t,r,n){let o=S(e,"w:r");if(r&&o.appendChild(r),!n)return lo(e,o,t),o;let a=S(e,n?"w:delText":"w:t");return a.setAttribute("xml:space","preserve"),a.textContent=t,o.appendChild(a),o}function lo(e,t,r){let o=String(r||"").split(/(\t|\n|\u2011)/);for(let a of o){if(!a)continue;if(a===" "){t.appendChild(S(e,"w:tab"));continue}if(a===`
138
- `){t.appendChild(S(e,"w:br"));continue}if(a==="\u2011"){t.appendChild(S(e,"w:noBreakHyphen"));continue}let i=S(e,"w:t");/^\s|\s$/.test(a)&&i.setAttribute("xml:space","preserve"),i.textContent=a,t.appendChild(i)}}function it(e,t,r,n,o){let a=S(e,"w:rPr");t&&Array.from(t.childNodes).forEach(l=>{["w:b","w:bCs","w:i","w:iCs","w:u","w:strike","w:rPrChange"].includes(l.nodeName)||a.appendChild(l.cloneNode(!0))});let i=r||{bold:!1,italic:!1,underline:!1,strikethrough:!1};n&&o&&Ki(e,a,n,t);let s=(l,c,u=null,f="0")=>{let m=S(e,l);c?u&&m.setAttribute("w:val",u):f&&m.setAttribute("w:val",f);let p=yt.indexOf(l),d=p===-1?999:p,g=!1;for(let h of Array.from(a.childNodes)){if(h.nodeType!==1)continue;let w=yt.indexOf(h.nodeName);if((w===-1?999:w)>d){a.insertBefore(m,h),g=!0;break}}g||a.appendChild(m)};return s("w:b",!!i.bold,"1","0"),s("w:bCs",!!i.bold,"1","0"),s("w:i",!!i.italic,"1","0"),s("w:iCs",!!i.italic,"1","0"),s("w:u",!!i.underline,"single","none"),s("w:strike",!!i.strikethrough,"1","0"),a}function zr(e,t,r,n,o){let a=S(e,"w:rPrChange"),i=ie(r,e);a.setAttribute("w:id",String(i.id)),a.setAttribute("w:author",i.author),a.setAttribute("w:date",n||i.date);let s=S(e,"w:rPr");Array.from((o||t).childNodes).forEach(u=>{u.nodeName!=="w:rPrChange"&&s.appendChild(u.cloneNode(!0))}),a.appendChild(s);let c=V(t,"w:rPrChange");return c&&t.removeChild(c),t.appendChild(a),a}function Ki(e,t,r,n){zr(e,t,r,null,n||t)}var Yi="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function st(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===Yi&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function er(e,t,r){let n=new Map;for(let i of r)!i||!i.paragraph||(n.has(i.paragraph)||n.set(i.paragraph,[]),n.get(i.paragraph).push(i));let o=[],a=0;return t.forEach((i,s)=>{let l=(n.get(i)||[]).slice().sort((m,p)=>m.charStart-p.charStart),c=Zi(l),u=Wr(c),f=u.trim();o.push({paragraph:i,spans:l,text:c,normalizedText:u,normalizedTrim:f,startOffset:a}),a+=u.length,a=Ue(a,s,t.length)}),o}function co(e,t){if(!t)return null;let r=Wr(t),n=r.trim();if(!n)return null;for(let o of e)if(o.normalizedText===r)return o;for(let o of e)if(o.normalizedTrim===n)return o;return null}function uo(e,t){let r=Wr(t),n=r.trim(),o=null,a=0;for(let i of e)if(i.normalizedText===r)return o=i,{targetInfo:o,matchOffset:a};if(n.length>0){for(let i of e)if(i.normalizedTrim===n)return o=i,{targetInfo:o,matchOffset:a}}if(n.length>0){let s=e.map(l=>l.normalizedText).join(`
139
- `).indexOf(n);if(s!==-1)for(let l of e){let c=l.startOffset,u=l.normalizedText.length;if(s>=c&&s<=c+u){o=l,a=s-c;break}}}if(!o&&e.length===1&&r.length>0){let i=e[0],s=i.normalizedTrim||"";if(s.length>0){let l=r.indexOf(s);l>=0&&(o=i,a=-l)}}return{targetInfo:o,matchOffset:a}}function fo(e){let t=e;for(;t;){if(st(t,"p"))return t;t=t.parentNode}return null}function Zi(e){if(!e||e.length===0)return"";let t="";for(let r of e){if(!r||!r.textElement)continue;let n=r.textElement;st(n,"t")?t+=r.textElement.textContent||"":st(n,"tab")?t+=" ":st(n,"br")||st(n,"cr")?t+=`
140
- `:st(n,"noBreakHyphen")&&(t+="\u2011")}return t}function Wr(e){return e?e.replace(/\r/g,`
141
- `).replace(/\u00a0/g," "):""}function mo(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 o=[...t].sort((s,l)=>s.charStart-l.charStart||s.charEnd-l.charEnd),a=[],i=0;for(let s of o){for(;i<n.length&&n[i]<=s.charStart;)i++;let l=s;for(;i<n.length&&n[i]<l.charEnd;){let c=n[i],u=Ji(e,l,c);if(!u){i++;continue}a.push(u[0]),l=u[1],i++}a.push(l)}return a}function Ji(e,t,r){let n=t.runElement,o=n.parentNode;if(!o)return null;let a=t.textElement.textContent||"",i=r-t.charStart,s=a.substring(0,i),l=a.substring(i);if(s.length===0||l.length===0)return null;let c=Ke(e,s,t.rPr,!1),u=Ke(e,l,t.rPr,!1);o.insertBefore(c,n),o.insertBefore(u,n),o.removeChild(n);let f=c.getElementsByTagName("w:t")[0],m=u.getElementsByTagName("w:t")[0];return[{...t,charEnd:r,textElement:f,runElement:c},{...t,charStart:r,textElement:m,runElement:u}]}var Qi="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function qi(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===Qi&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function es(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 po(e,t,r,n,o,a=!0){let i=!1,s=new Set;I(`[OxmlEngine] Surgical format removal: ${r.length} hints to process (using w:rPrChange)`);for(let l of r){let c=l.run;if(s.has(c)||(s.add(c),!c.parentNode))continue;I("[OxmlEngine] Processing run for surgical format removal, format:",l.format);let u=V(c,"w:rPr");u||(u=S(e,"w:rPr"),c.insertBefore(u,c.firstChild)),a&&zr(e,u,o||re()),eo(e,u,l.format),i=!0}return i?(I("[OxmlEngine] Surgical format removal completed successfully (Pure Format Mode)"),{oxml:n.serializeToString(e),hasChanges:!0}):(I("[OxmlEngine] No format changes were applied"),{oxml:n.serializeToString(e),hasChanges:!1})}function ts(e,t,r,n,o,a=!0){let i=!1,s=new Set;if(!t||t.length===0)return{oxml:n.serializeToString(e),hasChanges:!1};let l=[];for(let m of r)l.push(m.start,m.end);let u=mo(e,t,l).slice().sort((m,p)=>m.charStart-p.charStart||m.charEnd-p.charEnd),f=rs(r);for(let m of u){if(!m||!m.textElement||!qi(m.textElement,"t"))continue;let p=f(m.charStart,m.charEnd);if(p.length===0)continue;let d=yr(...p.map(C=>C.format)),g={bold:!!d.bold,italic:!!d.italic,underline:!!d.underline,strikethrough:!!d.strikethrough},h=m.format||Re(m.rPr),w={bold:!!h.bold,italic:!!h.italic,underline:!!h.underline,strikethrough:!!h.strikethrough};if(!["bold","italic","underline","strikethrough"].some(C=>g[C]!==w[C])||s.has(m.runElement)||(s.add(m.runElement),!(m.textElement.textContent||""))||!m.runElement.parentNode)continue;let x=m.runElement,N=V(x,"w:rPr"),A=it(e,N,g,o||re(),a),k=N;if(!k)x.insertBefore(A,x.firstChild);else{for(;k.firstChild;)k.removeChild(k.firstChild);Array.from(A.childNodes).forEach(C=>k.appendChild(C))}i=!0}return{oxml:n.serializeToString(e),hasChanges:i}}function go(e,t,r,n,o,a=!0,i=null){let s=es(i),l=s.paragraphs||Pe(e),c=s.textSpans||[];if(s.textSpans||({textSpans:c}=no(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 u=s.paragraphInfos||er(e,l,c),{targetInfo:f,matchOffset:m}=uo(u,t);if(!f||!f.spans||f.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=f.spans[0].charStart,d=f.spans.map(h=>({...h,charStart:h.charStart-p,charEnd:h.charEnd-p})),g=r.map(h=>({...h,start:h.start+m,end:h.end+m}));return ts(e,d,g,n,o,a)}function rs(e){let t=(e||[]).slice().sort((o,a)=>o.start-a.start||o.end-a.end),r=[],n=0;return(o,a)=>{for(;n<t.length&&t[n].start<a;)r.push(t[n]),n++;for(let i=r.length-1;i>=0;i--)r[i].end<=o&&r.splice(i,1);return r.filter(i=>i.start<a&&i.end>o)}}var ns="http://schemas.microsoft.com/office/word/2010/wordml";function ho(e,t,r={}){let{targetParagraphId:n=null}=r,o=ce(e,y,"tbl");if(o.length===0)return{hasTableWrapper:!1,isTableCellParagraph:!1,paragraphs:[],paragraph:null,tableElement:null};let i=Pe(e).filter(l=>{let c=l.parentNode;for(;c;){if(R(c,"tc"))return!0;c=c.parentNode}return!1});I(`[OxmlEngine] Table wrapper detected: ${o.length} tables, ${i.length} paragraphs in cells`);let s=null;if(n){let l=String(n).toUpperCase();s=i.find(c=>{let u=as(c);return u&&u.toUpperCase()===l})||null,s?I(`[OxmlEngine] Found target paragraph by paraId: "${n}"`):I(`[OxmlEngine] paraId "${n}" not found in wrapper, falling back to text match`)}if(t&&t.trim()){let l=t.trim();if(!s)for(let c of i){let u=ce(c,y,"t"),f="";for(let m of u)f+=m.textContent||"";if(f.trim()===l){s=c,I(`[OxmlEngine] Found target paragraph by text match: "${l.substring(0,30)}..."`);break}}}return{hasTableWrapper:!0,isTableCellParagraph:i.length>0,targetParagraph:s,paragraphs:i,paragraph:s||i[0]||null,tableElement:o[0]}}function Pt(e,t,r){let n=Array.isArray(t)?t:[t],o="";for(let a of n){if(!a)continue;let i=r.serializeToString(a);i=i.replace(/\s+xmlns:w="[^"]*"/g,""),i=i.replace(/\s+xmlns:r="[^"]*"/g,""),i=i.replace(/\s+xmlns:wp="[^"]*"/g,""),o+=i}return I(`[OxmlEngine] Stripping table wrapper, serializing ${n.length} paragraphs`),I(`[OxmlEngine] Paragraph XML preview: ${o.substring(0,200)}...`),os(o)}function os(e){return Kn(e)}function as(e){if(!e)return null;let t=typeof e.getAttributeNS=="function"?e.getAttributeNS(ns,"paraId"):null;return t||e.getAttribute("w14:paraId")||e.getAttribute("w:paraId")||e.getAttribute("paraId")||null}function Ur(e){return R(e,"t")?e.textContent||"":R(e,"br")||R(e,"cr")?`
142
- `:R(e,"tab")?" ":R(e,"noBreakHyphen")?"\u2011":""}function Hr(e){return R(e,"t")||R(e,"br")||R(e,"cr")||R(e,"tab")||R(e,"noBreakHyphen")}function bo(e){let t="",r=[];return e.forEach((n,o)=>{let a=n.parentNode;for(let i=n.firstChild;i;i=i.nextSibling)if(R(i,"r"))t+=wo(i,n,a,t.length,r).text;else if(R(i,"hyperlink"))for(let s=i.firstChild;s;s=s.nextSibling)R(s,"r")&&(t+=wo(s,n,a,t.length,r).text);t=tt(t,o,e.length)}),{fullText:t,textSpans:r}}function wo(e,t,r,n,o){let a=V(e,"w:rPr"),i=n,s=[];for(let l=e.firstChild;l;l=l.nextSibling)if(R(l,"t")){let c=l.textContent||"";if(c.length===0)continue;o.push({charStart:i,charEnd:i+c.length,textElement:l,runElement:e,paragraph:t,container:r,rPr:a}),i+=c.length,s.push(c)}else if(Hr(l)){let c=Ur(l);o.push({charStart:i,charEnd:i+1,textElement:l,runElement:e,paragraph:t,container:r,rPr:a}),i+=1,s.push(c)}return{text:s.join("")}}function xo(e){let t=e.slice().sort((o,a)=>o.charStart-a.charStart||o.charEnd-a.charEnd),r=t.map(o=>o.charStart),n=t.map(o=>o.charEnd);return{spans:t,starts:r,ends:n}}function tr(e,t,r,n){if(r<=t||e.spans.length===0)return;let o=jr(e.ends,t);for(;o<e.spans.length;){let a=e.spans[o];if(a.charStart>=r)break;n(a),o++}}function No(e,t){if(e.spans.length===0)return null;let r=jr(e.starts,t)-1;if(r<0)return null;let n=e.spans[r];return t>=n.charStart&&t<n.charEnd?n:null}function vo(e,t){let r=is(e.ends,t);return r<e.spans.length&&e.ends[r]===t?e.spans[r]:null}function To(e,t){let r=jr(e.ends,t)-1;return r>=0?e.spans[r]:null}function jr(e,t){let r=0,n=e.length;for(;r<n;){let o=r+n>>1;e[o]<=t?r=o+1:n=o}return r}function is(e,t){let r=0,n=e.length;for(;r<n;){let o=r+n>>1;e[o]<t?r=o+1:n=o}return r}function Gr(e){let t=[],r=0;for(let n of Array.from(e.childNodes||[])){if(R(n,"rPr")||!Hr(n))continue;let o=Ur(n);o.length!==0&&(t.push({node:n,start:r,end:r+o.length,text:o}),r+=o.length)}return t}function St(e){return e.length===0?0:e[e.length-1].end}function lt(e,t,r,n,o){let a=[];return n<=r||t.forEach(i=>{let s=Math.max(r,i.start),l=Math.min(n,i.end);if(l<=s)return;let c=s-i.start,u=l-i.start,f=i.text.slice(c,u);a.push(ss(e,i.node,f,o))}),a}function Vr(e,t,r){let n=S(e,"w:r");return r&&n.appendChild(r.cloneNode(!0)),t.forEach(o=>n.appendChild(o)),n}function It(e,t,r,n,o){if(n.length===0)return null;let a=Vr(e,n,o);return t.insertBefore(a,r),a}function ss(e,t,r,n){if(n){let a=S(e,"w:delText");return a.setAttribute("xml:space","preserve"),a.textContent=r,a}if(R(t,"t")){let a=t.cloneNode(!1);return a.textContent=r,/^\s|\s$/.test(r)&&a.setAttribute("xml:space","preserve"),a}if(r===`
143
- `&&(R(t,"br")||R(t,"cr"))||r===" "&&R(t,"tab")||r==="\u2011"&&R(t,"noBreakHyphen"))return t.cloneNode(!0);let o=S(e,"w:t");return o.setAttribute("xml:space","preserve"),o.textContent=r,o}function Eo(e,t,r,n,o,a,i){if(o.length===0)return!1;let s=t.rPr,l=Re(s),c={...l};if(o.forEach(x=>Object.assign(c,x.format)),!["bold","italic","underline","strikethrough"].some(x=>!!c[x]!==l[x]))return!1;let m=t.runElement.parentNode;if(!m)return!1;let p=t.textElement.textContent||"",d=t.charStart,g=r-d,h=n-d,w=p.substring(0,g),b=p.substring(g,h),v=p.substring(h);if(w.length>0){let x=Ke(e,w,s,!1);m.insertBefore(x,t.runElement)}let E=it(e,s,c,a,i),P=Dr(e,b,E,!1);if(m.insertBefore(P,t.runElement),v.length>0){let x=Ke(e,v,s,!1);m.insertBefore(x,t.runElement)}return m.removeChild(t.runElement),!0}function yo(e,t,r,n,o,a){let i=[];if(tr(t,r,n,c=>{i.push(c)}),i.length===0)return!1;let s=new Map;i.forEach(c=>{c.runElement?.parentNode&&(s.has(c.runElement)||s.set(c.runElement,[]),s.get(c.runElement).push(c))});let l=!1;return s.forEach((c,u)=>{let f=u.parentNode;if(!f)return;let m=Gr(u);if(m.length===0)return;let p=1/0,d=-1/0;if(c.forEach(b=>{let v=m.find(x=>x.node===b.textElement);if(!v)return;let E=Math.max(0,r-b.charStart),P=Math.min(b.charEnd-b.charStart,n-b.charStart);P<=E||(p=Math.min(p,v.start+E),d=Math.max(d,v.start+P))}),!Number.isFinite(p)||d<=p)return;let g=lt(e,m,0,p,!1),h=lt(e,m,p,d,!0),w=lt(e,m,d,St(m),!1);if(It(e,f,u,g,c[0].rPr),a&&h.length>0){let b=Vr(e,h,c[0].rPr),v=Ve(e,"del",b,o);f.insertBefore(v,u)}It(e,f,u,w,c[0].rPr),f.removeChild(u),l=!0}),l}function Po(e,t,r,n,o,a=[],i=0,s=!0,l=null){let c=No(t,r);if(!c&&r>0&&(c=vo(t,r)),!c&&r>0&&(c=To(t,r)),!c&&t.spans.length>0&&(c=t.spans[t.spans.length-1]),!c)return l?(rr(e,l,null,n,null,o,a,i,s),!0):!1;let u=c.runElement.parentNode;if(!u)return l?(rr(e,l,null,n,c.rPr,o,a,i,s),!0):!1;let f=Gr(c.runElement),m=f.find(g=>g.node===c.textElement),p=m?m.start+Math.max(0,Math.min(r-c.charStart,c.charEnd-c.charStart)):r<=c.charStart?0:St(f);if(p>0&&p<St(f)){let g=lt(e,f,0,p,!1),h=lt(e,f,p,St(f),!1);return It(e,u,c.runElement,g,c.rPr),rr(e,u,c.runElement,n,c.rPr,o,a,i,s),It(e,u,c.runElement,h,c.rPr),u.removeChild(c.runElement),!0}let d=r<=c.charStart?c.runElement:c.runElement.nextSibling;return rr(e,u,d,n,c.rPr,o,a,i,s),!0}function rr(e,t,r,n,o,a,i,s,l){let c=Ie(i,s,s+n.length);if(c.length===0){let f=Ke(e,n,o,!1);if(l){let m=Ve(e,"ins",f,a);t.insertBefore(m,r)}else t.insertBefore(f,r);return}let u=qt(e,n,o,c,s,a,l);if(l){let f=Ve(e,"ins",null,a);u.forEach(m=>f.appendChild(m)),t.insertBefore(f,r)}else u.forEach(f=>t.insertBefore(f,r))}function So(e,t,r,n,o,a,i=!0,s=null,l={}){let c=s?[s]:Pe(e),{fullText:u,textSpans:f}=bo(c),m=Tt(u,r,l),p=xo(f),d=0,g=0,h=!1;for(let[w,b]of m)if(w===0){let v=b.length,E=d,P=d+v;tr(p,E,P,x=>{let N=Math.max(x.charStart,E),A=Math.min(x.charEnd,P),k=A-N,C=N-E,O=g+C,L=O+k,F=Ie(a,O,L);Eo(e,x,N,A,F,o,i)&&(h=!0)}),d+=v,g+=v}else if(w===-1)yo(e,p,d,d+b.length,o,i)&&(h=!0),d+=b.length;else if(w===1){let v=b.replace(/\n/g," ");v.trim().length>0&&Po(e,p,d,v,o,a,g,i,c[0]||null)&&(h=!0),g+=b.length}return oe({oxml:n.serializeToString(e),hasChanges:h})}var Ao=xn(_r(),1);var Ro=new Ao.diff_match_patch;function Co(e){return String(e?.localName||e?.nodeName||"").replace(/^.*:/,"")}function ls(e,t){return e?.getAttributeNS?.(y,t)||e?.getAttribute?.(`w:${t}`)||e?.getAttribute?.(t)||""}function Io(e){let t=0;return{at(r){if(t>0&&(!e[t]||r<e[t].start)){let o=0,a=t-1;for(;o<=a;){let i=Math.floor((o+a)/2);e[i].end<=r?o=i+1:a=i-1}t=o}for(;t<e.length&&e[t].end<=r;)t++;let n=e[t];return n&&n.start<=r&&r<n.end?n:null}}}function cs(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 Oo(e,t,r=null){let n=e.documentElement,o=R(n,"body")||Co(n)==="package",a=r||Pe(e),i=be(e,y,"body");!i&&o&&(i=n);let s="",l=[],c=[],u=[],f=new Map,m=new Map,p=new Set,d={nextCharCode:57344},g=new Set;a.forEach((O,L)=>{let F=s.length;Array.from(O.childNodes).forEach(me=>{s=ds(me,s,l,u,f,m,d,p)}),s=tt(s,L,a.length);let Z=s.length,ee=be(O,y,"pPr"),j=O.parentNode;j&&g.add(j),c.push({start:F,end:Z,pPr:ee,container:j||i})});let h="";for(let O=0;O<s.length;O++){let L=s[O];h+=p.has(L)?`
144
- `:L}let w=ms(h,t,u);w=fs(h,s,w,p),m.forEach((O,L)=>{let F=L.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");w=w.replace(new RegExp(F,"g"),O)}),w=ps(s,w,f);let b=new Map;g.forEach(O=>{b.set(O,e.createDocumentFragment())}),i&&!b.has(i)&&b.set(i,e.createDocumentFragment()),b.has(e)||b.set(e,e.createDocumentFragment());let v=new Map,E=new Set(c.map(O=>O.start)),P=Io(c),x=Io(l),N=cs(u);return{paragraphs:a,body:i||e,paragraphMap:c,paragraphStarts:E,propertyMap:l,sentinelMap:u,sentinelMapByStart:N,referenceMap:f,tokenToCharMap:m,containerFragments:b,replacementContainers:v,originalFullText:s,processedModifiedText:w,getParagraphInfo:O=>{let L=P.at(O);return L||(c.length>0?c[c.length-1]:{start:0,end:0,pPr:null,container:i||e})},getRunProperties:O=>{let L=x.at(O);return L?{rPr:L.rPr,wrapper:L.wrapper}:{rPr:null}},getPropertySpanLength:(O,L)=>{let F=x.at(O);return F?Math.min(F.end-O,L):1},isParagraphStart:O=>E.has(O)}}function ko(e,t){let r=Pe(e);if(r.length===0)return[];let n=Mo(t),o=r.map(us);if(!n){let i=o.findIndex(s=>s==="");return i>=0?[r[i]]:null}if(r.length===1&&o[0]==="")return r;let a=[i=>i,i=>i.trim(),i=>i.replace(/\s+/g," ").trim()];for(let i of a){let s=i(n);for(let l=0;l<r.length;l++){let c="";for(let u=l;u<r.length;u++)if(c+=(u===l?"":`
145
- `)+o[u],i(c)===s)return r.slice(l,u+1)}}return null}function Mo(e){return String(e??"").replace(/\r\n?/g,`
146
- `).replace(/\u00a0/g," ")}function us(e){let t="",r=n=>{for(let o of Array.from(n?.childNodes||[]))o.nodeType===1&&(R(o,"pPr")||R(o,"del")||R(o,"moveFrom")||(R(o,"t")?t+=o.textContent||"":R(o,"tab")?t+=" ":R(o,"br")||R(o,"cr")?t+=`
147
- `:R(o,"noBreakHyphen")?t+="\u2011":r(o)))};return r(e),Mo(t)}function fs(e,t,r,n){if(n.size===0)return r;let o=Ro.diff_main(e,r),a=0,i="";for(let[s,l]of o)if(s===0){for(let c=0;c<l.length;c++){let u=t[a+c];i+=n.has(u)?u:l[c]}a+=l.length}else s===-1?a+=l.length:i+=l;return i}function ms(e,t,r){let n=new Map;if(r.forEach(f=>{f.zeroWidth&&n.set(f.start,f)}),n.size===0)return t;let o="",a=0,i=new Map;for(let f=0;f<e.length;f++){let m=n.get(f);if(m){i.has(a)||i.set(a,[]),i.get(a).push({char:e[f],affinity:m.affinity||"right",emitted:!1});continue}o+=e[f],a++}let s=Ro.diff_main(o,t),l=0,c="",u=(f,m)=>{let p=i.get(f)||[];for(let d of p)d.emitted||m&&d.affinity!==m||(c+=d.char,d.emitted=!0)};for(let[f,m]of s){if(f===1){u(l,"left"),c+=m;continue}for(let p=0;p<m.length;p++)u(l),f===0&&(c+=m[p]),l++}return u(l),c}function ps(e,t,r){let n=t;for(let o of r.keys()){if(n.includes(o))continue;let a=e.indexOf(o);if(a<0)continue;let i=e.slice(0,a),s=e.slice(a+o.length);if(i&&n.startsWith(i)){n=`${n.slice(0,i.length)}${o}${n.slice(i.length)}`;continue}if(s&&n.endsWith(s)){let l=n.length-s.length;n=`${n.slice(0,l)}${o}${n.slice(l)}`}}return n}function ds(e,t,r,n,o,a,i,s){return R(e,"r")?gs(e,t,r,n,o,a,i,s):R(e,"hyperlink")?hs(e,t,r):R(e,"sdt")||R(e,"oMath")||Co(e)==="oMath"||R(e,"bookmarkStart")||R(e,"bookmarkEnd")?(n.push({start:t.length,node:e}),t+"\uFFFC"):((R(e,"commentRangeStart")||R(e,"commentRangeEnd"))&&n.push({start:t.length,node:e,isCommentMarker:!0}),t)}function gs(e,t,r,n,o,a,i,s){let l=t,c=be(e,y,"rPr");return Array.from(e.childNodes).forEach(u=>{if(R(u,"t")){let f=u.textContent||"";f.length>0&&(r.push({start:l.length,end:l.length+f.length,rPr:c}),l+=f)}else if(R(u,"br")||R(u,"cr")){let f=String.fromCharCode(i.nextCharCode++);o.set(f,u),s.add(f),l+=f,r.push({start:l.length-1,end:l.length,rPr:c})}else if(R(u,"tab"))l+=" ",r.push({start:l.length-1,end:l.length,rPr:c});else if(R(u,"noBreakHyphen"))l+="\u2011",r.push({start:l.length-1,end:l.length,rPr:c});else if(["drawing","pict","object","fldChar","instrText","sym"].some(f=>R(u,f))){let f=be(u,y,"txbxContent"),m=R(u,"pict")&&!!f,p=R(u,"fldChar")||R(u,"instrText"),d=R(u,"fldChar")?u.getAttributeNS?.(y,"fldCharType")||u.getAttribute("w:fldCharType")||u.getAttribute("fldCharType"):null;n.push({start:l.length,node:u,wrapInRun:!0,rPr:c,zeroWidth:p,affinity:d==="end"?"left":"right",isTextBox:m,originalContainer:m?f:void 0}),l+="\uFFFC",r.push({start:l.length-1,end:l.length,rPr:c})}else if(R(u,"footnoteReference")||R(u,"endnoteReference")){let f=ls(u,"id");if(f){let p=`{{__${R(u,"footnoteReference")?"FN":"EN"}_${f}__}}`,d=String.fromCharCode(i.nextCharCode++);o.set(d,u),a.set(p,d),l+=d,r.push({start:l.length-1,end:l.length,rPr:c})}}else R(u,"commentReference")&&n.push({start:l.length,node:u,isCommentMarker:!0})}),l}function hs(e,t,r){let n=t;return Array.from(e.childNodes).forEach(o=>{if(!R(o,"r"))return;let a=be(o,y,"rPr");ce(o,y,"t").forEach(s=>{let l=s.textContent||"";l.length!==0&&(r.push({start:n.length,end:n.length+l.length,rPr:a,wrapper:e}),n+=l)})}),n}function _o(e,t,r,n,o,a,i=!0){let{paragraphs:s,containerFragments:l,sentinelMapByStart:c,referenceMap:u,replacementContainers:f,getParagraphInfo:m,getRunProperties:p,getPropertySpanLength:d,isParagraphStart:g}=r,h=F=>{let Z=S(e,"w:p");return F&&Z.appendChild(F.cloneNode(!0)),Z},w=m(0),b=h(w.pPr),v=l.get(w.container);v&&v.appendChild(b);let E=0,P=0,x=null,N=new WeakSet;for(let[F,Z]of t){if(F===0||F===-1){let ee=F===0?"equal":"delete";F===0?x=null:x===null&&(x=E);let j=0;for(;j<Z.length;){let me=E+j,De=p(me),Ft=d(me,Z.length-j),qe=Z.substring(j,j+Ft);b=Lo(e,qe,ee,De.rPr,De.wrapper,me,b,l,c,u,f,m,h,o,a,P,i,N).currentParagraph,F===0&&(P+=Ft),j+=Ft}E+=Z.length;continue}if(F===1){let ee=x!==null?x:E>0&&!g(E)?E-1:E,j=p(ee);b=Lo(e,Z,"insert",j.rPr,j.wrapper,E,b,l,c,u,f,m,h,o,a,P,i,N).currentParagraph,P+=Z.length,x=null}}let A=new Set(s),k=new Map;s.forEach(F=>{let Z=F.parentNode;if(!Z||k.has(Z))return;let ee=F.nextSibling;for(;ee&&A.has(ee);)ee=ee.nextSibling;k.set(Z,ee)}),s.forEach(F=>{F.parentNode&&F.parentNode.removeChild(F)});let C=!1,O="";return l.forEach((F,Z)=>{let ee=f.get(Z),j=ee||Z;if(j.nodeType===9){C=!0,F.childNodes.length===1?j.appendChild(F.firstChild):O=Array.from(F.childNodes).map(De=>n.serializeToString(De)).join("");return}let me=ee?null:k.get(Z);me&&me.parentNode===j?j.insertBefore(F,me):j.appendChild(F)}),{oxml:C&&O?O:n.serializeToString(e),hasChanges:!0}}function Lo(e,t,r,n,o,a,i,s,l,c,u,f,m,p,d=[],g=0,h=!0,w=new WeakSet){let b=a,v=g,E=i;return t.split(/([\n\uFFFC]|[\uE000-\uF8FF])/).forEach(x=>{let N=l.get(b)||[];if(N.filter(C=>C.isCommentMarker&&!w.has(C.node)).forEach(C=>{if(w.add(C.node),R(C.node,"commentReference")){let O=S(e,"w:r");O.appendChild(C.node.cloneNode(!0)),E.appendChild(O)}else E.appendChild(C.node.cloneNode(!0))}),x===`
148
- `){let C=f(b+1),O=m(C.pPr);h&&r==="insert"?so(e,E,p):h&&r==="delete"&&Qt(e,E,p);let L=s.get(C.container);L&&(L.appendChild(O),E=O),b++,r!=="delete"&&v++;return}if(x==="\uFFFC"){let C=N.find(O=>!O.isCommentMarker)||N[0];if(C){let O=C.node.cloneNode(!0);if(C.isTextBox&&C.originalContainer){let L=be(O,y,"txbxContent");if(L){for(;L.firstChild;)L.removeChild(L.firstChild);u.set(C.originalContainer,L)}}if(C.wrapInRun){let L=S(e,"w:r");C.rPr&&L.appendChild(C.rPr.cloneNode(!0)),L.appendChild(O),E.appendChild(L)}else E.appendChild(O)}b++,r!=="delete"&&v++;return}if(c.has(x)){if(r!=="delete"){let C=c.get(x);if(C){let O=C.cloneNode(!0),L=S(e,"w:r");n&&L.appendChild(n.cloneNode(!0)),L.appendChild(O),E.appendChild(L)}}b++,r!=="delete"&&v++;return}if(x.length===0)return;let k=E;if(o){let C=o.cloneNode(!1);k=C,E.appendChild(C)}if(r==="delete"){let C=S(e,"w:r");n&&C.appendChild(n.cloneNode(!0));let O=S(e,"w:delText");if(O.setAttribute("xml:space","preserve"),O.textContent=x,C.appendChild(O),h){let L=Ve(e,"del",C,p);k.appendChild(L)}}else{let C=Ie(d,v,v+x.length),O=qt(e,x,n,C,v,p,h);if(r==="insert"&&h){let L=Ve(e,"ins",null,p);O.forEach(F=>L.appendChild(F)),k.appendChild(L)}else O.forEach(L=>k.appendChild(L))}r!=="delete"&&(v+=x.length),b+=x.length}),{currentParagraph:E}}function Kr(e,t,r,n,o,a,i=!0,s={}){let l=ko(e,t);if(l===null)return oe({oxml:n.serializeToString(e),hasChanges:!1,status:"error",error:{code:"PARTIAL_TARGET",message:"Original text did not identify a complete contiguous paragraph range for reconstruction."}});let c=Oo(e,r,l);if(c.paragraphs.length===0)return oe({oxml:n.serializeToString(e),hasChanges:!1});let u=Tt(c.originalFullText,c.processedModifiedText,s);return oe(_o(e,u,c,n,o,a,i))}function ve(e,t){return oe({oxml:e.serializeToString(t),hasChanges:!1})}function Bo(e,t,r,n,o,a=!0){let i=ce(e,y,"tbl"),s=Ne(t),l=s.rows.length>0||s.headers.length>0;if(i.length===0||!l)return ve(r,e);let c=i[0],u=Lr(c),f=Jn(u,s);if(f.length===0)return ve(r,e);let m={generateRedlines:a,author:o,revisionIdAllocator:Ut(e)},p=Qn(u,f,m),d=`<root xmlns:w="${y}">${p}</root>`,g=D(d,"application/xml").doc;if(!g)return ve(r,e);let h=K(g);if(h)return G("[OxmlEngine] Failed to parse reconciled table OOXML:",h.textContent),ve(r,e);let w=be(g,y,"tbl");if(!w)return G("[OxmlEngine] No table found in reconciled OOXML"),ve(r,e);let b=e.importNode(w,!0);return c.parentNode.replaceChild(b,c),oe({oxml:r.serializeToString(e),hasChanges:!0})}function Fo(e,t,r,n,o,a){let i=Ut(e),s=Ne(t);if(!s||s.rows.length===0&&s.headers.length===0)return I("[OxmlEngine] Failed to parse table data from Markdown"),ve(r,e);let l=je(s,{generateRedlines:a,author:o,revisionIdAllocator:i}),c=D(`<root xmlns:w="${y}">${l}</root>`,"application/xml").doc;if(!c)return ve(r,e);let u=K(c);if(u)return G("[OxmlEngine] Failed to parse generated table OOXML:",u.textContent),ve(r,e);let f=H(c,y,"tbl");if(f||(f=H(c,y,"ins")),!f)return G("[OxmlEngine] No table element found in generated OOXML"),ve(r,e);let m=e,p=J(m,y,"p");if(p.length===0)return I("[OxmlEngine] No paragraphs found to replace"),ve(r,m);let d=p[0],g=d.parentNode;if(g&&g.nodeType===9){let w=D(`<w:document xmlns:w="${y}"><w:body/></w:document>`,"application/xml").doc;if(!w)return ve(r,m);let b=H(w,y,"body");p.forEach(v=>b.appendChild(w.importNode(v,!0))),m=w,Wt(m,i),p=J(m,y,"p"),d=p[0],g=d.parentNode}let h=m.importNode(f,!0);return a?p.forEach(w=>{Qt(m,w,o),J(w,y,"r").forEach(v=>{J(v,y,"t").forEach(N=>{let A=N.textContent||"";if(A.trim()){let k=S(m,"w:delText");k.textContent=A,N.parentNode.replaceChild(k,N)}});let P=S(m,"w:del"),x=ie(o,m);P.setAttribute("w:id",String(x.id)),P.setAttribute("w:author",x.author),P.setAttribute("w:date",x.date),v.parentNode.insertBefore(P,v),P.appendChild(v)})}):p.slice(1).forEach(w=>w.parentNode.removeChild(w)),g.insertBefore(h,d),a||g.removeChild(d),I("[OxmlEngine] Text-to-table transformation complete"),oe({oxml:r.serializeToString(m),hasChanges:!0})}function Ye(e,t){if(!e||!e.attributes)return"";for(let r of Array.from(e.attributes))if((r.localName||"").toLowerCase()===t.toLowerCase())return String(r.value||"");return String(e.getAttribute?.(`w:${t}`)||e.getAttribute?.(t)||"")}function Do(e){return typeof e=="string"?e.trim().toLowerCase():""}function ws(e){return!!e&&e.nodeType===1}function $e(e,t){return ws(e)&&e.namespaceURI===y&&String(e.localName||"").toLowerCase()===t.toLowerCase()}function se(e,t){return Array.from(e.getElementsByTagNameNS(y,t))}function Yr(e={}){if(e?.allAuthors===!0)return{valid:!0,allAuthors:!0,normalizedAuthor:""};let t=Do(e?.author);return t?{valid:!0,allAuthors:!1,normalizedAuthor:t}:{valid:!1,allAuthors:!1,normalizedAuthor:"",warning:"No author provided. Pass { author } or set { allAuthors: true }."}}function de(e,t){if(t.allAuthors)return!0;let r=Do(Ye(e,"author"));return!!r&&r===t.normalizedAuthor}function Zr(e,t){let r=D(e,"application/xml"),n=r.doc?K(r.doc):null;if(r.error||n){let o=r.error?.message||n?.textContent||"parse error";return{xmlDoc:null,serializer:null,warning:`${t}: ${o}`,warnings:r.warnings,error:{code:"PARSE_ERROR",message:o}}}return{xmlDoc:r.doc,serializer:ae(),warning:null,warnings:r.warnings,error:null}}function q(e){return e?.parentNode?(e.parentNode.removeChild(e),!0):!1}function nr(e){let t=e?.parentNode;if(!t)return!1;for(;e.firstChild;)t.insertBefore(e.firstChild,e);return t.removeChild(e),!0}function or(e){let t=e?.parentNode;return $e(t,"trPr")&&$e(t?.parentNode,"tr")}function Jr(e){let t=e?.parentNode,r=t?.parentNode,n=r?.parentNode;return $e(t,"rPr")&&$e(r,"pPr")&&$e(n,"p")}function zo(e){return Jr(e)?e.parentNode.parentNode.parentNode:null}function bs(e){let t=e?.nextSibling||null;for(;t;){if($e(t,"p"))return t;t=t.nextSibling}return null}function Wo(e){if(!e?.parentNode)return!1;let t=bs(e);if(!t)return q(e);let r=Array.from(e.childNodes||[]).filter(o=>!$e(o,"pPr")),n=t.firstChild||null;for(let o of r)t.insertBefore(o,n);return q(e)}function Qr(e,t={}){let r=[],n=Yr(t);if(!n.valid)return{oxml:e,hasChanges:!1,acceptedCount:0,warnings:[n.warning]};let o=Zr(e,"Failed to parse OOXML");if(!o.xmlDoc)return{oxml:e,hasChanges:!1,acceptedCount:0,status:"error",error:o.error,warnings:[...o.warnings||[],o.warning]};let{xmlDoc:a,serializer:i}=o;r.push(...o.warnings||[]);let s=0;for(let c of se(a,"ins"))if(!(!c.parentNode||!de(c,n))){if(Jr(c)){q(c)&&(s+=1);continue}if(or(c)){q(c)&&(s+=1);continue}nr(c)&&(s+=1)}for(let c of se(a,"del")){if(!c.parentNode||!de(c,n))continue;let u=zo(c);if(u){Wo(u)&&(s+=1);continue}if(or(c)){let f=c.parentNode?.parentNode;q(f)&&(s+=1);continue}q(c)&&(s+=1)}for(let c of se(a,"moveFrom"))!c.parentNode||!de(c,n)||q(c)&&(s+=1);for(let c of se(a,"moveTo"))!c.parentNode||!de(c,n)||nr(c)&&(s+=1);s+=Uo(a,n);let l=["rPrChange","pPrChange","tblPrChange","trPrChange","tcPrChange"];for(let c of l)for(let u of se(a,c))!u.parentNode||!de(u,n)||q(u)&&(s+=1);return{oxml:i.serializeToString(a),hasChanges:s>0,acceptedCount:s,warnings:r}}function $o(e,t){for(let r of Array.from(t.getElementsByTagNameNS(y,"delText"))){let n=S(e,"w:t"),o=r.getAttribute("xml:space");for(o&&n.setAttribute("xml:space",o);r.firstChild;)n.appendChild(r.firstChild);r.parentNode?.replaceChild(n,r)}}function xs(e,t){let r=e?.parentNode;if(!r)return!1;let n=t.endsWith("Change")?t.slice(0,-6):"";if(!n||String(r.localName||"").toLowerCase()!==n.toLowerCase()||r.namespaceURI!==y)return q(e);let o=Array.from(e.childNodes||[]).find(i=>i.nodeType===1&&i.namespaceURI===y&&String(i.localName||"").toLowerCase()===n.toLowerCase());if(!o)return q(e);let a=Array.from(o.childNodes||[]);for(;r.firstChild;)r.removeChild(r.firstChild);for(let i of a){let s=Ns(r.ownerDocument,i);r.appendChild(s)}return!0}function Ns(e,t){return e&&typeof e.importNode=="function"?e.importNode(t,!0):t.cloneNode(!0)}function Xo(e,t,r){let n=new Set;for(let o of se(e,t)){if(!de(o,r))continue;let a=Ye(o,"id");a&&n.add(a)}return n}function Uo(e,t){let r=0,n=Xo(e,"moveFromRangeStart",t),o=Xo(e,"moveToRangeStart",t),a=[["moveFromRangeStart",n,!0],["moveFromRangeEnd",n,!1],["moveToRangeStart",o,!0],["moveToRangeEnd",o,!1]];for(let[i,s,l]of a)for(let c of se(e,i)){if(!c.parentNode)continue;let u=Ye(c,"id");u&&(t.allAuthors||s.has(u)||l&&de(c,t))&&q(c)&&(r+=1)}return r}function vs(e,t={}){let r=[],n=Yr(t);if(!n.valid)return{oxml:e,hasChanges:!1,rejectedCount:0,warnings:[n.warning]};let o=Zr(e,"Failed to parse OOXML");if(!o.xmlDoc)return{oxml:e,hasChanges:!1,rejectedCount:0,status:"error",error:o.error,warnings:[...o.warnings||[],o.warning]};let{xmlDoc:a,serializer:i}=o;r.push(...o.warnings||[]);let s=0;for(let c of se(a,"ins")){if(!c.parentNode||!de(c,n))continue;let u=zo(c);if(u){Wo(u)&&(s+=1);continue}if(or(c)){let f=c.parentNode?.parentNode;q(f)&&(s+=1);continue}q(c)&&(s+=1)}for(let c of se(a,"del"))if(!(!c.parentNode||!de(c,n))){if(Jr(c)){q(c)&&(s+=1);continue}if(or(c)){q(c)&&(s+=1);continue}$o(a,c),nr(c)&&(s+=1)}for(let c of se(a,"moveFrom"))!c.parentNode||!de(c,n)||($o(a,c),nr(c)&&(s+=1));for(let c of se(a,"moveTo"))!c.parentNode||!de(c,n)||q(c)&&(s+=1);s+=Uo(a,n);let l=["rPrChange","pPrChange","tblPrChange","trPrChange","tcPrChange"];for(let c of l)for(let u of se(a,c))!u.parentNode||!de(u,n)||xs(u,c)&&(s+=1);return{oxml:i.serializeToString(a),hasChanges:s>0,rejectedCount:s,warnings:r}}function Ts(e,t){let r=new Set,n=se(e,"comment");for(let o of n){if(!de(o,t))continue;let a=Ye(o,"id");a&&r.add(a)}return{targetIds:r,commentNodes:n}}function Es(e,t){let r=0;for(let n of e){let o=Ye(n,"id");!o||!t.has(o)||q(n)&&(r+=1)}return r}function ys(e){return $e(e,"r")?Array.from(e.childNodes||[]).filter(r=>{if(r.nodeType===3)return String(r.nodeValue||"").trim().length>0;if(r.nodeType!==1)return!1;if(r.namespaceURI!==y)return!0;let n=String(r.localName||"").toLowerCase();return n!=="rpr"&&n!=="commentreference"}).length===0:!1}function Ps(e,t){let r=0,n=["commentRangeStart","commentRangeEnd","commentReference"];for(let o of n)for(let a of se(e,o)){if(!a.parentNode)continue;let i=Ye(a,"id");if(!(!i||!t.has(i))){if(o==="commentReference"&&ys(a.parentNode)){q(a.parentNode)&&(r+=1);continue}q(a)&&(r+=1)}}return r}function Ss(e,t={}){let r=[],n=Yr(t);if(!n.valid)return{oxml:e,hasChanges:!1,commentsRemoved:0,referencesRemoved:0,warnings:[n.warning]};let o=Zr(e,"Failed to parse OOXML");if(!o.xmlDoc)return{oxml:e,hasChanges:!1,commentsRemoved:0,referencesRemoved:0,status:"error",error:o.error,warnings:[...o.warnings||[],o.warning]};let{xmlDoc:a,serializer:i}=o;r.push(...o.warnings||[]);let{targetIds:s,commentNodes:l}=Ts(a,n);if(n.allAuthors)for(let f of["commentRangeStart","commentRangeEnd","commentReference"])for(let m of se(a,f)){let p=Ye(m,"id");p&&s.add(p)}let c=Es(l,s),u=Ps(a,s);return{oxml:i.serializeToString(a),hasChanges:c>0||u>0,commentsRemoved:c,referencesRemoved:u,warnings:r}}async function qr(e,t,r,n={}){let o=e,a=e;t=typeof t=="string"?t:String(t??""),r=typeof r=="string"?r:String(r??"");let i=n.generateRedlines??!0,s=n.author||re(),l=ae(),c=[],u=[],f=!1,m=n.existingRevisions==="accept-all-first-keep-normalized",p=X=>{let M={...X};f&&M.hasChanges===!1&&M.status!=="error"&&(m?(M.oxml=a,M.hasChanges=!0,M.warnings=[...Array.isArray(M.warnings)?M.warnings:[],"Existing revisions were accepted before redlining."]):M.oxml=o);let te=[...c,...u,...Array.isArray(M.warnings)?M.warnings:[]];return te.length>0&&(M.warnings=[...new Set(te)]),M.status||(M.status=M.hasChanges?"ok":"no-op"),oe(M)},d=()=>p(f&&m?{oxml:a,hasChanges:!0,warnings:["Existing revisions were accepted before redlining."]}:{oxml:o,hasChanges:!1}),g=D(o,"text/xml");c=g.warnings;let h=g.doc,w=h?K(h):null;if(g.error||w){let X=g.error?.message||w?.textContent||"Could not parse OOXML input.";return G("[OxmlEngine] XML parse error:",X),p({oxml:o,hasChanges:!1,status:"error",error:{code:"PARSE_ERROR",message:X}})}let b=n?._revisionIdAllocator instanceof he?n._revisionIdAllocator:new he;if(vt(h,b),Xr(h)){let X=n.existingRevisions||"reject-input";if(X==="accept-all-first"||X==="accept-all-first-keep-normalized"){I("[OxmlEngine] Existing revisions detected; accepting all input revisions before redlining");let M=Qr(o,{allAuthors:!0});if(M.status==="error")return p(M);a=M.oxml,f=!0;let te=D(a,"text/xml");c.push(...te.warnings),h=te.doc;let Ee=h?K(h):null;if(te.error||Ee){let We=te.error?.message||Ee?.textContent||"Could not parse OOXML after accepting existing revisions.";return G("[OxmlEngine] XML parse error after accepting existing revisions:",We),p({oxml:o,hasChanges:!1,status:"error",error:{code:"PARSE_ERROR",message:We}})}vt(h,b)}else return I("[OxmlEngine] Existing revisions detected; rejecting input per existingRevisions policy"),p({oxml:o,hasChanges:!1,status:"error",error:{code:"EXISTING_REVISIONS",message:'Input OOXML contains existing tracked changes. Pass existingRevisions: "accept-all-first" to normalize before redlining.'}})}let v=ho(h,t,n);if(v.hasTableWrapper&&v.targetParagraph&&!n._isolatedTableCell){I("[OxmlEngine] Isolating table-cell paragraph before diff");let X=Pt(h,v.targetParagraph,l),M=await qr(X,t,r,{...n,_isolatedTableCell:!0});return!M.hasChanges&&M.status==="no-op"?d():M}let E=n.sanitizeInput===!0?en(r):r;E!==r&&u.push("Input was sanitized; pass sanitizeInput: false to disable.");let{cleanText:P,formatHints:x}=le(E),N=P.trim()!==t.trim(),A=x.length>0,{existingFormatHints:k,textSpans:C,paragraphs:O}=oo(h),L=k.length>0,F=C.map(X=>Ho(X)).join(""),Z=t.includes(`
149
- `)||t.includes("\r")?t.split(/\r?\n/).map(ar).filter(Boolean).every(X=>O.some(M=>{let te=C.filter(Ee=>Ee.paragraph===M).map(Ho).join("");return ar(te).includes(X)})):F.includes(t.trim())||F.replace(/[\t\n\u2011]/g,"").includes(t.trim().replace(/[\t\n\u2011]/g,""))||ar(F).includes(ar(t));if(N&&typeof t=="string"&&t.trim()&&!Z)return I("[OxmlEngine] Target text not found in OOXML"),p({oxml:o,hasChanges:!1,status:"error",error:{code:"TARGET_NOT_FOUND",message:"Original text was not found in the supplied OOXML."}});let ee=null,j=()=>(ee||(ee=er(h,O,C)),ee),me=(X=null)=>{let M=go(h,t,x,l,s,i,X);return M.useNativeApi?(I("[OxmlEngine] Format-only surgical fallback signal encountered; retrying with OOXML reconstruction fallback"),Kr(h,t,P,l,s,x,i)):M};I(`[OxmlEngine] Text changes: ${N}, New format hints: ${x.length}, Existing format hints: ${k.length}`);let De=n.removeFormatting===!0&&!N&&!A&&L;if(!N&&!A&&!L)return I("[OxmlEngine] No text changes, no format hints, and no existing formatting detected"),d();if(!N&&!A&&L&&!De)return I("[OxmlEngine] No text or explicit formatting changes; preserving existing formatting"),d();if(De){I("[OxmlEngine] Format REMOVAL detected: applying surgical replacement in OOXML");let X=v,M=X.targetParagraph||null;if(!M){let We=co(j(),t);We&&(M=We.paragraph)}let te=k;M&&(te=k.filter(We=>fo(We.run)===M));let Ee=po(h,C,te,l,s,i);return X.hasTableWrapper&&M?p({oxml:Pt(h,M,l),hasChanges:Ee.hasChanges}):p(Ee)}if(!N&&A){I(`[OxmlEngine] Format-only change detected: ${x.length} format hints`);let X=v,M={textSpans:C,paragraphs:O,paragraphInfos:j()};if(X.hasTableWrapper&&X.targetParagraph){I("[OxmlEngine] Table cell context: applying formatting to target paragraph only");let te=me(M);return I("[OxmlEngine] Stripping table wrapper for table cell paragraph (format-only)"),p({oxml:Pt(h,X.targetParagraph,l),hasChanges:te.hasChanges})}return p(me(M))}let qe=ce(h,y,"tbl").length>0,$t=/^\|.+\|/.test(P.trim())&&P.includes(`
150
- `),wn=Nt(P),ze=v;I(`[OxmlEngine] Mode: ${qe?"SURGICAL":"RECONSTRUCTION"}, formatHints: ${x.length}, isMarkdownTable: ${$t}, isTargetList: ${wn}, isTableCellParagraph: ${ze.isTableCellParagraph}`);try{if($t&&!qe)return I("[OxmlEngine] Text-to-table transformation: generating new table from Markdown"),p(Fo(h,P,l,null,s,i));if(qe&&$t)return p(Bo(h,P,l,null,s,i));if(qe){let X=ze.hasTableWrapper&&ze.targetParagraph?ze.targetParagraph:null;X&&I("[OxmlEngine] Table cell edit: scoping surgical mode to target paragraph");let M=So(h,t,P,l,s,x,i,X);return ze.hasTableWrapper&&M.hasChanges&&ze.targetParagraph?(I("[OxmlEngine] Stripping table wrapper for table cell paragraph (surgical mode)"),p({oxml:Pt(h,ze.targetParagraph,l),hasChanges:!0})):p(M)}if(wn){I("[OxmlEngine] \u{1F3AF} Using reconciliation pipeline for list generation");let M=await new Ge({author:s,generateRedlines:i,revisionIdAllocator:b}).execute(a,E,{xmlDoc:h});if(M.error?.code==="DIFF_TOKEN_LIMIT")return p({oxml:o,hasChanges:!1,status:"error",error:M.error});if(M.isValid&&M.ooxml&&M.ooxml!==a){let te=M.includeNumbering===!0;I(`[OxmlEngine] Wrapping list OOXML with numbering definitions, includeNumbering=${te}`);let Ee=Fe(M.ooxml,{includeNumbering:te,numberingXml:M.numberingXml});return I(`[OxmlEngine] \u2705 Wrapped OOXML length: ${Ee.length}`),p({oxml:Ee,hasChanges:!0})}return d()}return p(Kr(h,t,P,l,s,x,i))}catch(X){if(Xn(X))return p({oxml:o,hasChanges:!1,status:"error",error:{code:X.code,message:X.message}});throw X}}function ar(e){return String(e||"").replace(/[\t\n\u2011]/g," ").replace(/\s+/g," ").trim()}function Ho(e){let t=e?.textElement,r=String(t?.localName||t?.nodeName||"").replace(/^.*:/,"");return r==="tab"?" ":r==="br"||r==="cr"?`
151
- `:r==="noBreakHyphen"?"\u2011":t?.textContent||""}function en(e){return String(e??"").replace(/^(?:Here is the redline:|Here is the text:|Sure, I can help:|Here's the updated text:)[ \t]*\r?\n/i,"")}function Ce(e){return D(e,"application/xml").doc}function Ze(e){return Q(e)}function ir(e){return Array.from(e||[])}function sr(e){let t=new Error(e);return t.code="TARGET_NOT_FOUND",t}var ge="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function jo(e,t){if(!e)return[];if(typeof e.getElementsByTagNameNS=="function"){let n=ir(e.getElementsByTagNameNS("*",t));if(n.length>0)return n}if(typeof e.getElementsByTagName!="function")return[];let r=ir(e.getElementsByTagName(`w:${t}`));return r.length>0?r:ir(e.getElementsByTagName(t))}function Is(e){let t="",r=n=>{for(let o of ir(n?.childNodes)){if(o?.nodeType!==1)continue;let a=String(o.localName||o.nodeName||"").replace(/^.*:/,"");a==="t"?t+=o.textContent||"":a==="tab"?t+=" ":r(o)}};return r(e),t}function Y(e){return e?Is(e):""}function Oe(e){if(!e)return[];let t=jo(e,"body"),r=t.length>0?t[0]:e;return jo(r,"p")}function $(e){return String(e||"").replace(/\s+/g," ").trim()}function nn(e){let t=String(e||"").trim();return/^\|.+\|/.test(t)&&t.includes(`
152
- `)}function on(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 As(e){return e==null?"":String(e).replace(/^\s*\[P\d+(?:\.\d+)?\]\s*/i,"").trim()}function Rs(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 Go(e,t){return!Number.isInteger(t)||t<1?null:Oe(e)[t-1]||null}function ct(e,t,r=ge){let n=e;for(;n;){if(n.nodeType===1&&n.namespaceURI===r&&n.localName===t)return n;n=n.parentNode}return null}function lr(e,t){let r=Oe(e),n=String(t||"").trim();if(!n)return null;let o=r.find(i=>Y(i).trim()===n);if(o)return o;let a=$(n);return r.find(i=>$(Y(i))===a)||null}function tn(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},o=Oe(e),a=String(t||"").trim();if(!a)return null;let i=lr(e,a);if(i)return i;let s=$(a),l=o.find(p=>{let d=$(Y(p));return d.length>10&&s.startsWith(d)});if(l)return n(`[Fuzzy] Prefix match (target starts with paragraph): "${Y(l).trim().slice(0,60)}..."`),l;let c=o.find(p=>{let d=$(Y(p));return d.length>15&&s.includes(d)});if(c)return n(`[Fuzzy] Contains match: "${Y(c).trim().slice(0,60)}..."`),c;let u=0,f=null,m=new Set(s.toLowerCase().split(/\s+/).filter(p=>p.length>2));for(let p of o){let d=Y(p).trim();if(!d)continue;let w=$(d).toLowerCase().split(/\s+/).filter(b=>b.length>2).filter(b=>m.has(b)).length/Math.max(m.size,1);w>u&&w>.5&&(u=w,f=p)}return f?(n(`[Fuzzy] Best word-overlap match (${(u*100).toFixed(0)}%): "${Y(f).trim().slice(0,60)}..."`),f):null}function Vo(e,t={}){let r=typeof t.onInfo=="function"?t.onInfo:()=>{},n=typeof t.onWarn=="function"?t.onWarn:()=>{},o=t.opType||"operation",a=String(t.targetText||"").trim(),i=on(t.targetRef);if(i){let s=Go(e,i);if(s){if(a){let l=lr(e,a),c=Y(s).trim(),u=$(c),f=$(a),m=u!==f;if(m&&l&&l!==s)return r(`[Target] [P${i}] drifted for ${o}; using strict text rematch.`),{paragraph:l,resolvedBy:"strict_text_after_ref_drift"};if(m){let p=tn(e,a,{onInfo:r});if(p&&p!==s)return r(`[Target] [P${i}] drifted for ${o}; using fuzzy text rematch.`),{paragraph:p,resolvedBy:"fuzzy_text_after_ref_drift"};r(`[Target] Using [P${i}] fallback for ${o}; target text drifted.`)}else l&&l!==s&&r(`[Target] [P${i}] disambiguated duplicate target text for ${o}.`)}else r(`[Target] Using [P${i}] fallback for ${o}.`);return{paragraph:s,resolvedBy:"ref"}}n(`[WARN] Target reference [P${i}] not found; falling back to text matching for ${o}.`)}if(a){let s=lr(e,a);if(s)return{paragraph:s,resolvedBy:"strict_text"};let l=tn(e,a,{onInfo:r});if(l)return{paragraph:l,resolvedBy:"fuzzy_text"}}throw sr(a?`Target paragraph not found: "${a}"`:i?`Target paragraph reference not found: [P${i}]`:'Operation target missing: provide "target" text or "targetRef" ([P#]).')}function Ko(e){return!!ct(e,"tbl")}function Cs(e,t){let r=$(t);if(!r)return[];let n=Oe(e),o=[];for(let a=0;a<n.length;a++){let i=n[a],s=Y(i).trim();s&&$(s)===r&&o.push({paragraph:i,index:a+1,inTable:Ko(i)})}return o}function Os(e,t,r=null){if(!Array.isArray(e)||e.length===0)return null;let n=e.slice();if(typeof r=="boolean"){let o=n.filter(a=>a.inTable===r);o.length>0&&(n=o)}return Number.isInteger(t)&&t>0&&n.sort((o,a)=>Math.abs(o.index-t)-Math.abs(a.index-t)),n[0]||null}function ks(e){let t=Oe(e),r=new Map;for(let n=0;n<t.length;n++){let o=t[n],a=Y(o).trim();r.set(n+1,{text:a,normalizedText:$(a),inTable:Ko(o)})}return r}function rn(e,t={}){let r=typeof t.onInfo=="function"?t.onInfo:()=>{},n=Vo(e,t),o=on(t.targetRef);if(!o||n?.resolvedBy!=="ref")return n;let a=t.targetRefSnapshot instanceof Map&&t.targetRefSnapshot.get(o)||null;if(!a)return n;let i=String(t.targetText||"").trim(),s=i||a.text||"",l=$(s);if(!l||$(Y(n.paragraph))===l)return n;let u=[];if(i&&u.push(i),a.text){let m=$(a.text);m&&!u.some(p=>$(p)===m)&&u.push(a.text)}let f=null;for(let m of u){let p=Cs(e,m),d=Os(p,o,a.inTable);if(d&&(f||(f=d),d.paragraph!==n.paragraph)){f=d;break}}if(f&&f.paragraph!==n.paragraph){let m=t.opType||"operation";return r(`[Target] [P${o}] appears stale after prior edits; using strict text rematch for ${m}.`),{paragraph:f.paragraph,resolvedBy:"strict_text_after_ref_drift"}}throw sr(`Target paragraph [P${o}] no longer matches its batch-start anchor.`)}function Ms(e,t,r,n={}){if(!e||!t||!r)return null;let o=n?.opType||"redline",a=n?.targetRefSnapshot||null,i=typeof n?.onInfo=="function"?n.onInfo:()=>{},s=typeof n?.onWarn=="function"?n.onWarn:()=>{},l=rn(e,{targetRef:t,opType:o,targetRefSnapshot:a,onInfo:i,onWarn:s})?.paragraph;if(!l)return null;let c=rn(e,{targetRef:r,opType:o,targetRefSnapshot:a,onInfo:i,onWarn:s})?.paragraph;if(!c)return null;let u=Array.from(e.getElementsByTagNameNS("*","p")),f=u.indexOf(l),m=u.indexOf(c);if(f<0||m<f)return null;let p=u.slice(f,m+1);if(p.length===0)return null;let d=p[0]?.parentNode||null;return!d||!p.every(g=>g&&g.parentNode===d)?null:p}function cr(e,t){if(!e||typeof e.getElementsByTagNameNS!="function")return null;let r=e.getElementsByTagNameNS(ge,t);if(r.length>0)return r[0];let n=e.getElementsByTagNameNS("*",t);return n.length>0?n[0]:null}function Yo(e){if(!e)return null;if(typeof e.getAttributeNS=="function"){let t=e.getAttributeNS(ge,"val");if(t)return t}return e.getAttribute("w:val")||e.getAttribute("val")||null}function Ls(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 Zo=/^(?:(?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|[ivxlcIVXLC]+\.|[-*+\u2022]))\s+/;function Qo(e){let t=String(e||"").trim(),r=0;for(;r<4&&Zo.test(t);)t=t.replace(Zo,"").trimStart(),r++;return t.trim()}function qo(e){let t=String(e||"").split(/\r?\n/g),r=[],n=!1;for(let o of t){let a=o.trimEnd();if(!a.trim())continue;let i=a.match(/^(\s*)((?:\d+(?:\.\d+)*\.?|\((?:\d+|[a-zA-Z]|[ivxlcIVXLC]+)\)|[a-zA-Z]\.|[ivxlcIVXLC]+\.|[-*+\u2022]))\s+(.*)$/);if(i){n=!0;let s=i[2],l=/^[-*+\u2022]$/.test(s)?"bullet":"numbered",c=Math.floor((i[1]||"").length/2);r.push({kind:"list",markerType:l,level:c,marker:s,outlineLevel:l==="numbered"?Ls(s):null,text:Qo(i[3])});continue}r.push({kind:"text",text:a.trim()})}return{items:r,hasListMarkers:n}}function Jo(e,t,r){return`${" ".repeat(Math.max(0,e))}${t==="numbered"?"1.":"-"} ${String(r||"").trim()}`.trimEnd()}function At(e,t){return $(e)===$(t)}function ur(e,t,r){return Number.isInteger(e?.outlineLevel)?Math.max(0,e.outlineLevel):Math.max(0,t+((e?.level||0)-r))}function _s(e,t,r){if(!Array.isArray(e)||e.length<2||!Number.isInteger(r)||r<1)return!1;let n=e[0],o=e.slice(1).filter(a=>a.kind==="list");if(o.length===0||o.some(a=>a.markerType!=="bullet")||o.some(a=>Number.isInteger(a.outlineLevel)))return!1;if(n?.kind==="text")return At(n.text,t);if(n?.kind==="list"&&n.markerType==="numbered"){let a=n.level||0;return o.some(s=>(s.level||0)>a)?!1:At(n.text,t)}return!1}function Bs(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 Fs(e,t,r,n){let o=e[0],a=e.slice(1).filter(i=>i.kind==="list");if(o?.kind==="text"&&At(o.text,t)&&a.length>0){let i=a[0].level;return a.map(s=>({ilvl:ur(s,r,i),markerType:s.markerType||n,text:s.text}))}if(e.every(i=>i.kind==="list")){let i=e[0];if(!i||!At(i.text,t))return null;let s=i.level;return e.slice(1).map(l=>({ilvl:ur(l,r,s),markerType:l.markerType||n,text:l.text})).filter(l=>l.text)}return null}function ke(e){if(!e)return null;let t=cr(e,"pPr");if(!t)return null;let r=cr(t,"numPr");if(!r)return null;let n=cr(r,"numId");if(!n)return null;let o=Yo(n);if(!o)return null;let a=cr(r,"ilvl"),i=Yo(a),s=Number.parseInt(i||"0",10);return{numId:String(o),ilvl:Number.isFinite(s)?s:0}}function ea(e){let t=ke(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===ge&&s.localName==="p"),o=n.indexOf(e);if(o<0)return null;let a=o;for(;a>0;){let s=ke(n[a-1]);if(!s||s.numId!==t.numId)break;a--}let i=o;for(;i<n.length-1;){let s=ke(n[i+1]);if(!s||s.numId!==t.numId)break;i++}return n.slice(a,i+1)}function $s(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},o=typeof r.onWarn=="function"?r.onWarn:()=>{},a=String(t||"");if(!a.includes(`
153
- `)||!ke(e))return null;let s=ea(e);if(!s||s.length===0)return null;let l=qo(a);if(!l.hasListMarkers||l.items.length<2)return null;let c=$(r.currentParagraphText||Y(e)),f=l.items.filter(N=>N.kind==="list")[0]?.markerType||"bullet",m=s.map(N=>({paragraph:N,list:ke(N),text:String(Y(N)||"").trim()})),p=s.indexOf(e);if(p<0)return null;let d=Math.min(...m.map(N=>N.list?.ilvl??0)),g=m.map(N=>Jo((N.list?.ilvl??0)-d,f,N.text)),h=null,w=l.items[0],b=l.items.slice(1).filter(N=>N.kind==="list");if(w?.kind==="text"&&At(w.text,c)&&b.length>0){let N=Math.max(0,(m[p].list?.ilvl??0)-d),A=b[0].level;h=[{level:N,markerType:f,text:m[p].text},...b.map(k=>({level:ur(k,N,A),markerType:k.markerType||f,text:k.text}))]}else if(l.items.every(N=>N.kind==="list")){let N=Math.max(0,(m[p].list?.ilvl??0)-d),A=l.items[0].level;h=l.items.map(k=>({level:ur(k,N,A),markerType:k.markerType||f,text:k.text}))}else return o("[List] Multiline list edit did not match supported insertion/replace patterns; skipping list-block synthesis."),null;let v=h.map(N=>Jo(N.level,N.markerType,N.text)),E=g.slice(0,p).concat(v).concat(g.slice(p+1)),P=g.join(`
154
- `),x=E.join(`
155
- `);return x===P?null:(n("[List] Expanded single-item list edit to contiguous list block for stable middle insertion."),{paragraphs:s,originalText:P,modifiedText:x})}function Xs(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},o=typeof r.onWarn=="function"?r.onWarn:()=>{},a=String(t||"");if(!a.includes(`
156
- `))return null;let i=ke(e);if(!i)return null;let s=qo(a);if(!s.hasListMarkers||s.items.length<2)return null;let l=$(r.currentParagraphText||Y(e)),u=s.items.filter(p=>p.kind==="list")[0]?.markerType||"bullet",f=Math.max(0,i.ilvl),m=Fs(s.items,l,f,u);return!m||m.length===0?(o("[List] Could not derive insertion-only entries from multiline list edit."),null):(_s(s.items,l,f)&&(m=Bs(m,f),n("[List] Promoted bullet insertion to child depth for nested numbered-list intent.")),n("[List] Planned insertion-only list redline entries (no block rewrite)."),{targetParagraph:e,numId:i.numId,entries:m})}function Rt(e){if(!e)return null;let t=String(e).trim();if(!t)return null;let r=t.split(`
157
- `),n=[];for(let i of r){if(!i.trim())continue;let s=Ae(i,{allowZeroSpaceAfterMarker:!1});if(s){let l=s[1]||"",c=s[2].trim(),u=_e(i,{allowZeroSpaceAfterMarker:!1}).trim(),f=Math.floor(l.length/2),m=/^[-*+\u2022]$/.test(c);n.push({type:m?"bullet":"numbered",level:f,text:u,marker:c});continue}n.push({type:"text",level:0,text:i.trim()})}if(n.length===0)return null;let o=n.some(i=>i.type==="numbered"),a=n.some(i=>i.type==="bullet");return{type:o?"numbered":a?"bullet":"text",items:n}}function an(e){return!e||!Array.isArray(e.items)?!1:e.items.some(t=>t?.type==="numbered"||t?.type==="bullet")}function sn(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 Ds(e,t,r){let n=new Map,o=[];for(let a of e){let i=Math.max(0,Number(a?.level)||0);for(let u of Array.from(n.keys()))u>i&&n.delete(u);let s=(n.get(i)||0)+1;n.set(i,s);let l=Ws(s,t,r),c=" ".repeat(i*4);o.push(`${c}${l} ${a.text||""}`.trimEnd())}return o.join(`
158
- `)}function zs(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(o=>{let a=String(o??""),i=a.match(/^(\s*)/),s=i?i[1].length:0,l=Math.floor(s/r),c=a.trim(),u=null,f=c.match(n);return f&&(u=f[1].trim()||null,c=c.replace(n,"")),{text:c.trim(),level:l,removedMarker:u}})}function Ws(e,t,r){if(t==="bullet")return"-";switch(r){case"lowerAlpha":return`${ta(e,!1)}.`;case"upperAlpha":return`${ta(e,!0)}.`;case"lowerRoman":return`${ra(e,!1)}.`;case"upperRoman":return`${ra(e,!0)}.`;default:return`${e}.`}}function ta(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 ra(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"]],o="";for(let[a,i]of n)for(;r>=a;)o+=i,r-=a;return t?o:o.toLowerCase()}function fr(e){let t=String(e||"");if(!t.trim()||t.includes(`
159
- `))return null;let r=Rt(t);if(!r||!an(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 o=String(n.marker||"").trim(),a=n.type==="numbered"?sn(o||"1."):"bullet";return{type:n.type,marker:o,numberingStyle:a,startAt:Hs(o,a),contentText:String(n.text||"").trim(),normalizedContent:$(String(n.text||""))}}function Us(e){let t=fr(e);return t?String(t.contentText||"").trim():String(e||"").trim()}function Hs(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 js(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 o=t?.explicitByNumberingKey;if(!(o instanceof Map))return{type:"explicitIsolated",numberingKey:r,startAt:n,numId:null};let a=o.get(r)||null;return a&&a.numId!=null&&Number.isInteger(a.nextStartAt)&&a.nextStartAt===n?{type:"explicitReuse",numberingKey:r,startAt:n,numId:String(a.numId)}:{type:"explicitStartNew",numberingKey:r,startAt:n,numId:null}}function Gs(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 Vs(e,t){!e||!(e.explicitByNumberingKey instanceof Map)||t&&e.explicitByNumberingKey.delete(String(t))}function ut(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 Ks(e,t={}){let r=t?.numId;if(r==null)return 0;let n=Number.isInteger(t?.ilvl)?Math.max(0,t.ilvl):0,o=t?.clearParagraphPropertyChanges!==!1,a=t?.removeListPropertyNode!==!1,i=(Array.isArray(e)?e:[]).filter(l=>l&&l.nodeType===1&&l.localName==="p"),s=0;for(let l of i){let c=l.ownerDocument;if(!c)continue;let u=ut(l,"pPr");if(u||(u=S(c,"w:pPr"),l.insertBefore(u,l.firstChild)),o){let d=ut(u,"pPrChange");d&&u.removeChild(d)}if(a){let d=ut(u,"listPr");d&&u.removeChild(d)}let f=ut(u,"numPr");f||(f=S(c,"w:numPr"),u.appendChild(f));let m=ut(f,"ilvl");m||(m=S(c,"w:ilvl"),f.appendChild(m)),m.setAttribute("w:val",String(n));let p=ut(f,"numId");p||(p=S(c,"w:numId"),f.appendChild(p)),p.setAttribute("w:val",String(r)),s++}return s}function Ys(e){let t=D(e,"application/xml").doc;return!t||K(t)?null:Oe(t)[0]||null}function Zs(e){return e?String(e).replace(/<w:p>\s*<w:pPr>\s*<\/w:pPr>\s*<\/w:p>\s*$/i,""):""}function Js(e,t){for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return null}function ft(e,t){let r=Js(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function na(e,t){e.setAttribute("w:val",String(t))}function Qs(e){let t=D(e,"application/xml").doc;if(!t||K(t))return null;let o=Oe(t)[0]||null;if(!o)return null;let a=Array.from(o.getElementsByTagNameNS("*","numId"));for(let i of a){let s=ft(i,["w:val","val"]);if(s!=null)return String(s)}return null}function qs(e,t,r,n={}){if(!e||!t||!Number.isInteger(r)||r<1)return e;let o=n.setAbstractStartOverride!==!1,a=ae(),i=D(e,"application/xml").doc;if(!i||K(i))return e;let c=Array.from(i.getElementsByTagNameNS("*","num")).find(d=>{let g=ft(d,["w:numId","numId"]);return g!=null&&String(g)===String(t)});if(!c)return e;let u=Array.from(c.getElementsByTagNameNS("*","abstractNumId"))[0]||null,f=ft(u,["w:val","val"]),m=Array.from(c.getElementsByTagNameNS("*","lvlOverride")).find(d=>ft(d,["w:ilvl","ilvl"])===0)||null;m||(m=S(i,"w:lvlOverride"),m.setAttribute("w:ilvl","0"),c.appendChild(m));let p=Array.from(m.getElementsByTagNameNS("*","startOverride"))[0]||null;if(p||(p=S(i,"w:startOverride"),m.appendChild(p)),na(p,r),o&&f!=null){let g=Array.from(i.getElementsByTagNameNS("*","abstractNum")).find(h=>{let w=ft(h,["w:abstractNumId","abstractNumId"]);return w!=null&&w===f})||null;if(g){let h=Array.from(g.getElementsByTagNameNS("*","lvl")).find(b=>ft(b,["w:ilvl","ilvl"])===0)||null;h||(h=S(i,"w:lvl"),h.setAttribute("w:ilvl","0"),g.appendChild(h));let w=Array.from(h.getElementsByTagNameNS("*","start"))[0]||null;w||(w=S(i,"w:start"),h.insertBefore(w,h.firstChild)),na(w,r)}}return a.serializeToString(i)}function ln(e={}){let t=String(e.oxml||""),r=String(e.originalText||""),n=String(e.modifiedText||""),o=e.allowExistingList===!0;if(!t.trim()||!n.trim())return null;let a=Ys(t);if(!a)return null;let i=ke(a);if(i&&!o)return null;let s=le(n).cleanText||n,l=fr(n)||fr(s);if(!l)return null;let c=fr(r),u=$(r)===$(s),f=!!c&&c.type===l.type&&c.normalizedContent===l.normalizedContent;return!u&&!f?null:{listInput:`${l.marker} ${l.contentText}`.trim(),numberingKey:`${l.type}:${l.numberingStyle}:single`,originalText:r,wasListParagraph:!!i,startAt:l.startAt}}async function mr(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,a=await(t.pipeline||new Ge({author:r,generateRedlines:n})).executeListGeneration(e.listInput,null,null,String(e.originalText||"")),i=a?.oxml||a?.ooxml||"",s=Zs(i),l=Qs(s),c=qs(a?.numberingXml||null,l,Number.isInteger(e?.startAt)?e.startAt:null,{setAbstractStartOverride:t.setAbstractStartOverride}),u=a?.isValid!==!1;return!s||!u?{hasChanges:!1,oxml:"",numberingXml:null,includeNumbering:!1,listStructuralFallbackApplied:!1,listStructuralFallbackKey:e.numberingKey||null,warnings:["Single-line list fallback produced no valid OOXML"]}:{hasChanges:!0,oxml:s,numberingXml:c,includeNumbering:!0,listStructuralFallbackApplied:!0,listStructuralFallbackKey:e.numberingKey||null,listStructuralFallbackStartAt:Number.isInteger(e?.startAt)?e.startAt:null,warnings:["Single-line list structural fallback applied"]}}var el=new Set(["ins","del","rPrChange","pPrChange"]),tl=/^\d{4}-\d{2}-\d{2}T/;function mt(e){return String(e?.localName||e?.nodeName||"").replace(/^.*:/,"")}function Je(e,t){return Array.from(e.getElementsByTagName("*")).filter(r=>mt(r)===t)}function Qe(e,t){return e.getAttribute(`w:${t}`)||e.getAttribute(t)||""}function rl(e){return e.getAttribute("xml:space")||e.getAttribute("space")||e.getAttributeNS?.("http://www.w3.org/XML/1998/namespace","space")||""}function nl(e){return mt(e.parentNode)==="rPr"}function ol(e){let t=r=>{let n=Nn(r),o=n.getElementsByTagName("parsererror")[0];if(o)throw new Error(o.textContent||"XML parse error");return n};try{return{doc:t(e)}}catch{try{return{doc:t(`<w:root xmlns:w="${y}">${e}</w:root>`)}}catch(r){return{error:r?.message||"XML parse error"}}}}function al(e){let t=[],r=(u,f,m)=>t.push({code:u,severity:f,message:m});if(typeof e!="string"||e.trim()==="")return r("PARSE_ERROR","error","Input is not a non-empty OOXML string."),{valid:!1,issues:t};let{doc:n,error:o}=ol(e);if(!n)return r("PARSE_ERROR","error",`OOXML does not parse as XML: ${o}`),{valid:!1,issues:t};let a=Je(n,"ins"),i=Je(n,"del"),s=a.concat(i);for(let u of Je(n,"p")){let f=Array.from(u.getElementsByTagName("*")).find(m=>m!==u&&mt(m)==="p");f&&r("NESTED_PARAGRAPH","error",`<${u.nodeName}> contains nested <${f.nodeName}>.`)}for(let u of Je(n,"body")){let f=Array.from(u.childNodes||[]).filter(p=>p.nodeType===1),m=f.map((p,d)=>mt(p)==="sectPr"?d:-1).filter(p=>p>=0);m.length>1?r("MULTIPLE_BODY_SECTPR","error","<w:body> contains multiple direct <w:sectPr> elements."):m.length===1&&m[0]!==f.length-1&&r("SECTPR_NOT_LAST","error","<w:sectPr> is not the last element child of <w:body>.")}for(let u of s){let f=Array.from(u.getElementsByTagName("*")).filter(m=>m!==u&&["ins","del"].includes(mt(m)));f.length>0&&r("NESTED_REVISION","error",`<${u.nodeName}> (w:id="${Qe(u,"id")}") contains nested <${f[0].nodeName}>.`)}for(let u of i)Je(u,"t").length>0&&r("DEL_CONTAINS_T","error",`<w:del> (w:id="${Qe(u,"id")}") contains <w:t>; deleted text must use <w:delText>.`);for(let u of s){let f=[];Qe(u,"id")||f.push("w:id"),Qe(u,"author")||f.push("w:author"),tl.test(Qe(u,"date"))||f.push("w:date"),f.length>0&&r("MISSING_REVISION_METADATA","error",`<${u.nodeName}> is missing or has malformed ${f.join(", ")}.`)}let l=new Set;for(let u of Array.from(n.getElementsByTagName("*"))){if(!el.has(mt(u)))continue;let f=Qe(u,"id");f&&(l.has(f)&&r("DUPLICATE_REVISION_ID","error",`Revision id ${f} appears more than once.`),l.add(f))}let c=Je(n,"t").concat(Je(n,"delText"));for(let u of c){let f=u.textContent||"";/^\s|\s$/.test(f)&&rl(u)!=="preserve"&&r("MISSING_SPACE_PRESERVE","error",`<${u.nodeName}> has boundary whitespace without xml:space="preserve".`),f===""&&r("EMPTY_TEXT_ELEMENT","warning",`<${u.nodeName}> is empty.`)}for(let u of s){if(nl(u))continue;Array.from(u.childNodes||[]).some(m=>m.nodeType===1)||r("EMPTY_REVISION_WRAPPER","warning",`<${u.nodeName}> (w:id="${Qe(u,"id")}") wraps no content.`)}return{valid:!t.some(u=>u.severity==="error"),issues:t}}function pr(e,t){return e?Array.from(e.childNodes||[]).filter(r=>r&&r.nodeType===1&&r.namespaceURI===ge&&r.localName===t):[]}function il(e){return String(e||"").replace(/\|/g,"\\|").replace(/\r?\n/g,"<br>")}function sl(e){let t=pr(e,"tr"),r=t.map(o=>pr(o,"tc").map(i=>{let s=pr(i,"p");return s.length===0?$(Y(i)):s.map(c=>$(Y(c))).filter(Boolean).join(`
160
- `)})),n=r.reduce((o,a)=>Math.max(o,a.length),0);return r.forEach(o=>{for(;o.length<n;)o.push("")}),{matrix:r,rowElements:t,columnCount:n}}function ll(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],o=new Array(t).fill("---"),a=r.slice(1),i=s=>`| ${s.map(l=>il(l)).join(" | ")} |`;return[i(n),i(o),...a.map(i)].join(`
161
- `)}function cl(e){if(!Array.isArray(e)||e.length<2)return!1;let t=e.map(r=>$(r)).filter(Boolean);return t.length<2?!1:t.every(r=>r===t[0])}function oa(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 ul(e,t={}){let r=Number.isInteger(t?.maxScan)&&t.maxScan>0?t.maxScan:10,n=typeof t?.getParagraphText=="function"?t.getParagraphText:Y;if(!e||!e.parentNode)return null;let o=[e],a=e.nextSibling,i=0;for(;a&&i<r;){i+=1;let s=a.nextSibling;if(a.nodeType!==1||a.namespaceURI!==ge||a.localName!=="p"){a=s;continue}let l=String(n(a)||"").trim();if(!l){if(o.length>1)break;a=s;continue}if(!oa(l))break;o.push(a),a=s}return o.length>1?o:null}function fl(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},o=typeof r.onWarn=="function"?r.onWarn:()=>{},a=String(t||"");if(!a.includes(`
162
- `)||nn(a))return null;let i=a.split(/\r?\n/g).map(E=>E.trim()).filter(Boolean);if(i.length<2)return null;let s=r.tableElement||ct(e,"tbl"),l=ct(e,"tr"),c=ct(e,"tc");if(!s||!l||!c)return null;let u=$(r.currentParagraphText||Y(e)),f=$(i[0]);if(u&&f&&f!==u)return o("[Table] Multiline cell text did not anchor to original cell text; skipping table-row synthesis heuristic."),null;let{matrix:m,rowElements:p,columnCount:d}=sl(s);if(m.length===0||d===0)return null;let g=p.indexOf(l),w=pr(l,"tc").indexOf(c);if(g<0||w<0||w>=d)return null;m[g][w]=i[0];let b=cl(m[g]);b&&n("[Table] Symmetric row detected; mirroring inserted row values across columns.");for(let E=1;E<i.length;E++){let P=g+E,x=i[E];if(P<m.length&&!$(m[P][w]))if(b)for(let N=0;N<d;N++)$(m[P][N])||(m[P][N]=x);else m[P][w]=x;else{let N=new Array(d).fill("");if(b)for(let A=0;A<d;A++)N[A]=x;else N[w]=x;m.splice(Math.min(P,m.length),0,N)}}let v=ll(m,d);return v?(n("[Table] Synthesized full markdown table from multiline cell edit for table-scope reconciliation."),v):null}function pt(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 o=Number.parseInt(String(n),10);if(Number.isFinite(o))return o}return null}function dt(e,t,r=null){let n=Number.isInteger(e)&&e>0?e:1,o=t instanceof Set?t:new Set;for(;o.has(n);)n+=1;if(Number.isInteger(r)&&r>0&&n>r){for(let a=1;a<=r;a+=1)if(!o.has(a))return a}return n}function ml(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,o=new Set,a=new Set;if(String(e||"").trim())try{let u=Ce(e),f=Array.from(u.getElementsByTagNameNS("*","abstractNum")),m=Array.from(u.getElementsByTagNameNS("*","num"));for(let p of f){let d=pt(p,["w:abstractNumId","abstractNumId"]);d!=null&&a.add(d)}for(let p of m){let d=pt(p,["w:numId","numId"]);d!=null&&o.add(d)}}catch{}let i=o.size>0?Math.max(...o):0,s=a.size>0?Math.max(...a):0,l=Math.max(r,i+1),c=Math.max(r,s+1);return{nextNumId:dt(l,o,n),nextAbstractNumId:dt(c,a,n),usedNumIds:o,usedAbstractNumIds:a,minId:r,maxPreferred:n}}function pl(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=dt(e.nextNumId,e.usedNumIds,e.maxPreferred),e.nextAbstractNumId=dt(e.nextAbstractNumId,e.usedAbstractNumIds,e.maxPreferred),e)}function Ot(e,t="num"){let r=pl(e);if(!r)return null;let n=t==="abstract",o=n?r.nextAbstractNumId:r.nextNumId;return!Number.isInteger(o)||o<1?null:(n?(r.usedAbstractNumIds.add(o),r.nextAbstractNumId=dt(o+1,r.usedAbstractNumIds,r.maxPreferred)):(r.usedNumIds.add(o),r.nextNumId=dt(o+1,r.usedNumIds,r.maxPreferred)),o)}function dl(e){let t=Ot(e,"num"),r=Ot(e,"abstract");return t==null||r==null?null:{numId:t,abstractNumId:r}}function cn(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:e.getElementsByTagName("parsererror").length>0}function dr(e,t){return!!(e&&e.nodeType===1&&e.namespaceURI===ge&&e.localName===t)}function aa(e,t,r){if(!e||!t)return;let n=Array.from(e.childNodes||[]).filter(a=>a&&a.nodeType===1&&a.namespaceURI===ge),o=null;r==="abstract"?o=n.find(a=>a.localName==="num"||a.localName==="numIdMacAtCleanup")||null:o=n.find(a=>a.localName==="numIdMacAtCleanup")||null,o?e.insertBefore(t,o):e.appendChild(t)}function gl(e,t){for(let r of t||[]){let n=e?.getAttribute?.(r);if(n!=null&&n!=="")return n}return null}function Ct(e,t){let r=gl(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function ia(e,t,r){e?.setAttribute?.(t,String(r))}function un(e,t){e?.setAttribute?.("w:val",String(t))}function hl(e,t){if(!(!Array.isArray(e)||t==null))for(let r of e){let n=Array.from(r?.getElementsByTagNameNS?.("*","numId")||[]);for(let o of n)un(o,t)}}function wl(e){for(let t of e||[]){let r=Array.from(t?.getElementsByTagNameNS?.("*","numId")||[]);for(let n of r){let o=Ct(n,["w:val","val"]);if(o!=null)return String(o)}}return null}function bl(e,t,r){let n=String(e),o=String(t),a=Number.isInteger(r)&&r>0?r:1,i=Array.from({length:9},(s,l)=>{let c=Array.from({length:l+1},(f,m)=>`%${m+1}`).join(".")+".",u=720*(l+1);return`
132
+ `}function Us(e){let t=new Map,r=new Map,n=[];for(let o of e)o.type==="row_delete"?t.set(o.gridRow,o):o.type==="cell_modify"?r.set(`${o.gridRow}:${o.gridCol}`,o):o.type==="row_insert"&&n.push(o);return n.sort((o,i)=>o.gridRow-i.gridRow),{rowDeleteByRow:t,cellModifyByCoordinate:r,rowInsertOperations:n}}function js(e,t,r){let{generateRedlines:n,author:o,revisionIdAllocator:i=null}=r,{cleanText:a,formatHints:s}=Ee(t),l=e.getText(),u=Cr(l,a),c=e.blocks[0]||{runModel:[],pPr:null},f=Or(c.runModel,u),m=kr(f,u,{generateRedlines:n,author:o,formatHints:s});return Fe(m,c.pPr,s,{author:o,generateRedlines:n,revisionIdAllocator:i})}function Hs(e){return e.map(t=>Fe(t.runModel,t.pPr,[],{})).join("")}function Vs(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 $e(e){let t=e.split(`
133
+ `).map(a=>a.trim()).filter(a=>a.startsWith("|"));if(t.length===0)return{headers:[],rows:[],hasHeader:!1};let r=a=>{let s=a.replace(/\s+/g,"");return/^\|:?-{3,}:?(\|:?-{3,}:?)+\|?$/.test(s)},n=t.some(r),i=t.filter(a=>!r(a)).map(a=>a.split("|").slice(1,-1).map(s=>s.trim()));return n?{headers:i[0]||[],rows:i.slice(1),hasHeader:!0}:{headers:[],rows:i,hasHeader:!1}}function I(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===S&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function C(e,t){return typeof e.createElementNS=="function"?e.createElementNS(S,t):e.createElement(t)}function ti(e,t){let r=Array.from(e?.getElementsByTagNameNS?.(S,t)||[]);return r.length>0?r:Array.from(e?.getElementsByTagName?.("*")||[]).filter(n=>I(n,t))}var ri=["ins","del","moveFrom","moveTo","moveFromRangeStart","moveFromRangeEnd","moveToRangeStart","moveToRangeEnd","rPrChange","pPrChange","tblPrChange","trPrChange","tcPrChange","cellIns","cellDel"];function Mr(e){return ri.some(t=>ti(e,t).length>0)}function In(e){if(!e)return[];let t=new Set;for(let r of ri)for(let n of ti(e,r)){let o=n.getAttribute?.("w:author")||n.getAttribute?.("author")||(typeof n.getAttributeNS=="function"?n.getAttributeNS(S,"author"):null);o&&typeof o=="string"&&o.trim()&&t.add(o.trim())}return[...t].sort()}function Gs(e){let t=String(e||"").trim();return/^<\?xml\b[^>]*>\s*<pkg:package\b/i.test(t)||/^<pkg:package\b/i.test(t)?"package":/^<\?xml\b[^>]*>\s*<(?:w:)?document\b/i.test(t)||/^<(?:w:)?document\b/i.test(t)?"document":"fragment"}function de(e){return!e||typeof e!="object"||e.sourceType||typeof e.oxml!="string"?e:{...e,sourceType:Gs(e.oxml)}}async function At(e){let{cleanText:t,numberingContext:r,originalRunModel:n=[],originalText:o="",generateRedlines:i=!0,author:a="AI",font:s=null,revisionIdAllocator:l=null,numberingService:u}=e,c=Ys(t),f=Ks(c),m=f.map(N=>N.raw),d=[],p=Zs(n),b=ni(n,p),w=ni(n,p,["rFonts","kern","position","rtl","cs","lang"]),g=[];if(i){if(n&&n.length>0)g=n.filter(N=>N.kind==="text"||N.kind==="run").map(N=>({...N,kind:"deletion",author:a}));else if(o&&o.trim().length>0){let N=o.trim();g=[{kind:"deletion",text:N,author:a,startOffset:0,endOffset:N.length}]}}if(i&&g.length>0){let N=oi(p,"del",a,l),E=Fe(g,N,[],{author:a,generateRedlines:i,revisionIdAllocator:l});d.push(E)}let h=An(m);k(`[ListGen] Detected indentation step: ${h} spaces/chars`);let x=f.find(N=>N.marker)?.marker||"",{format:v}=u.detectNumberingFormat(x);k(`[ListGen] Detected primary marker: "${x}", format: ${v}`);for(let N=0;N<f.length;N++){let E=Js(f,N);if(E){let L=$e(E.tableText);if(L.headers.length>0||L.rows.length>0){d.push(ut(L,{generateRedlines:i,author:a,revisionIdAllocator:l,trackAsBlock:!0})),N=E.endIndex;continue}}let P=f[N],$=qs(P,h,r,u,i,a,s,l,b,w);d.push($.ooxml)}let T=u.generateNumberingXml(),y=d.join("");return k(`[ListGen] \u2705 Generated OOXML for ${d.length} paragraphs, total length: ${y.length}`),k(`[ListGen] First 200 chars: ${y.substring(0,200)}...`),{ooxml:y,isValid:!0,warnings:["Paragraph expanded to list fragment"],type:"fragment",includeNumbering:!0,numberingXml:T}}function An(e){let t=e.map(n=>n.match(/^(\s*)/)[0].length).filter(n=>n>0).sort((n,o)=>n-o);if(t.length===0)return 2;let r=t[0];for(let n=1;n<t.length;n++){let o=t[n]-t[n-1];o>0&&o<r&&(r=o)}return r||2}function Ks(e){return e.split(`
134
+ `).filter(t=>t.trim().length>0).map(t=>{let r=Be(t),n=t.match(/^\s*(#{1,9})\s+(.*)/);return{raw:t,marker:r?r[2].trim():"",headerMatch:n,indentSize:t.match(/^(\s*)/)?.[1].length||0,isTableLine:/^\s*\|/.test(t),isTableSeparator:/^\s*\|?[\s:-]*-[-\s|:]*\|?\s*$/.test(t)}})}function Ys(e){let t=String(e||"").split(`
135
+ `),r=t.map((a,s)=>({line:a,index:s})).filter(a=>a.line.trim().length>0);if(r.length<2)return e;let n=[],o=0;for(let{line:a,index:s}of r){let l=Be(a);if(!l)return e;let u=We(a),c=Be(u);if(!c)return e;let f=(l[2]||"").trim(),m=(c[2]||"").trim();if(!f||!m||f===m)return e;let p=`${l[1]||""}${u.trimStart()}`;n.push({index:s,rewritten:p}),o++}if(o<2)return e;let i=t.slice();for(let a of n)i[a.index]=a.rewritten;return k(`[ListGen] Normalized ${o} composite list markers (e.g., "- A." -> "A.").`),i.join(`
136
+ `)}function Js(e,t){let r=e[t],n=e[t+1];if(!r?.isTableLine||!n?.isTableLine||!n?.isTableSeparator)return null;let o=[],i=t;for(;i<e.length&&e[i].isTableLine;)o.push(e[i].raw),i++;return{tableText:o.join(`
137
+ `),endIndex:i-1}}function qs(e,t,r,n,o,i,a,s,l,u){let c="",f="",m=l;if(e.headerMatch){let w=Math.min(e.headerMatch[1].length,9),g=Math.min(w-1,8),h=[32,28,26,24,22,20,20,20,20],x=h[w-1]||h[h.length-1];f=e.headerMatch[2].trim(),c=`<w:pPr><w:pStyle w:val="Heading${w}"/><w:outlineLvl w:val="${g}"/><w:rPr><w:b/><w:sz w:val="${x}"/><w:szCs w:val="${x}"/></w:rPr></w:pPr>`,m=Qs(u,`<w:rPr><w:b/><w:sz w:val="${x}"/><w:szCs w:val="${x}"/></w:rPr>`)}else if(e.marker){let w=n.detectNumberingFormat(e.marker),g=t>0?Math.floor(e.indentSize/t):0,h=r?.ilvl||0,x=w.format==="outline"?Math.min(8,w.depth):Math.min(8,g+h);f=We(e.raw);let v=n.getOrCreateNumId({type:w.format},r);c=n.buildListPPr(v,x)}else f=e.raw;o&&(c=oi(c||"<w:pPr/>","ins",i,s));let{cleanText:d,formatHints:p}=Ee(f),b=[];return b.push({kind:o?"insertion":"run",text:d,rPrXml:m,author:i,startOffset:0,endOffset:d.length}),{ooxml:Fe(b,c,p,{author:i,generateRedlines:o,font:a,revisionIdAllocator:s})}}function Zs(e){let t=(e||[]).find(r=>r.kind===B.PARAGRAPH_START);return t?.pPrElement||t?.pPrXml||null}function ni(e,t,r=["rFonts","kern","position","sz","szCs","rtl","cs","lang"]){let n=(e||[]).filter(i=>(i.kind===B.TEXT||i.kind==="text")&&i.rPrXml).map(i=>i.rPrXml);t&&n.push(typeof t=="string"?t:oe(t));let o=[];for(let i of r){let a=null;for(let s of n)if(a=String(s||"").match(new RegExp(`<w:${i}\\b[^>]*(?:\\/>|>[\\s\\S]*?<\\/w:${i}>)`)),a)break;a&&o.push(a[0])}return o.length>0?`<w:rPr>${o.join("")}</w:rPr>`:""}function Qs(...e){let t=e.map(r=>String(r||"").replace(/^\s*<w:rPr[^>]*>|<\/w:rPr>\s*$/g,"")).filter(Boolean).join("");return t?`<w:rPr>${t}</w:rPr>`:""}function oi(e,t,r,n){let o=ie(r,n),i,a;if(e?.nodeType===1)i=e.cloneNode(!0),a=i.ownerDocument;else{let u=typeof e=="string"&&e.trim()?e:"<w:pPr/>",c=W(`<w:root xmlns:w="${S}">${u}</w:root>`);if(!c.doc)throw new Error(c.error?.message||"Could not parse paragraph properties for list revision");a=c.doc,i=Array.from(a.documentElement.childNodes||[]).find(f=>f.nodeType===1&&f.localName==="pPr")}if(!i||!a)throw new Error("List paragraph properties are unavailable");let s=Array.from(i.childNodes||[]).find(u=>u.nodeType===1&&u.localName==="rPr");s||(s=C(a,"w:rPr"),i.appendChild(s));let l=C(a,t==="del"?"w:del":"w:ins");return l.setAttribute("w:id",String(o.id)),l.setAttribute("w:author",o.author),l.setAttribute("w:date",o.date),s.appendChild(l),oe(i)}var el=new Set(["officeonline","officeweb","web"]);function tl(e){return e?el.has(String(e).toLowerCase()):!1}function rl(){return typeof process<"u"&&process?.env?.NODE_ENV==="production"}function nl(){return new Promise(e=>setTimeout(e,0))}var er=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 Ge,this.font=t.font||null,this.revisionIdAllocator=t.revisionIdAllocator||null,this.platform=t.platform??mn(),this.isWebPlatform=t.isWebPlatform??tl(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 o=[];try{let i=n.xmlDoc?{doc:n.xmlDoc,error:null,warnings:[]}:W(t,"application/xml");if(i.error||!i.doc)return{ooxml:t,isValid:!1,status:"error",error:i.error,warnings:i.warnings||[]};o.push(...i.warnings||[]);let a=i.doc,s=re(a,"*","p"),{runModel:l,acceptedText:u,pPr:c}=Et(t,{xmlDoc:a}),f=s?Zt(s):null;k(`[Reconcile] Ingested ${l.length} runs, ${u.length} chars, numbering:`,f),await this.maybeYield(l.length,Math.max(u.length,r?.length||0));let{cleanText:m,formatHints:d}=Ee(r);k(`[Reconcile] Preprocessed: ${d.length} format hints`),await this.maybeYield(l.length,Math.max(u.length,m.length));let p=pn(m),b=Gt(m),w=p||b;if(!p&&b&&k("[Reconcile] List-target detected via loose marker parsing; bypassing no-op short-circuit for structural conversion."),u===m&&d.length===0&&!w)return k("[Reconcile] No changes detected"),{ooxml:t,isValid:!0,warnings:["No changes detected"]};let g=Math.max(u.length,m.length)<this.disableSemanticCleanupOverChars,h=Cr(u,m,{cleanupSemantic:g});g||k("[Reconcile] Skipping semantic diff cleanup for large web payload"),await this.maybeYield(l.length,Math.max(u.length,m.length));let x=l.filter(P=>P.kind===B.PARAGRAPH_START).length,v=pn(u)||Gt(u),T=w&&v&&x>1&&u!==m;if(k(`[Reconcile] isTargetList: ${w}, paragraphCount: ${x}`),T)k("[Reconcile] Existing marked list edit detected; using run-aware patching to preserve formatting and paragraph boundaries.");else if(w)return k("[Reconcile] \u{1F3AF} ENTERING LIST GENERATION PATH"),k(`[Reconcile] cleanText preview: ${m.substring(0,100)}...`),k(`[Reconcile] acceptedText preview: ${u.substring(0,100)}...`),this.executeListGeneration(m,f,l);k(`[Reconcile] Computed ${h.length} diff operations`);let y=Or(l,h);k(`[Reconcile] Split into ${y.length} runs`);let N=kr(y,h,{generateRedlines:this.generateRedlines,author:this.author,formatHints:d,numberingService:this.numberingService});k(`[Reconcile] Patched model has ${N.length} runs`),await this.maybeYield(N.length,Math.max(u.length,m.length));let E=Fe(N,c,d,{author:this.author,generateRedlines:this.generateRedlines,revisionIdAllocator:this.revisionIdAllocator});if(this.shouldRunValidation()){let P=this.validateBasic(E);P.isValid||o.push(...P.errors)}return{ooxml:E,isValid:o.length===0,warnings:o}}catch(i){return te("[Reconcile] Pipeline error:",i),{ooxml:t,isValid:!1,warnings:[`Pipeline error: ${i.message}`],error:i?.code?{code:i.code,message:i.message}:void 0}}}validateBasic(t){let r=[];try{let n=`<root xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">${t}</root>`,o=W(n,"application/xml"),i=o.doc;if(o.error||!i)return r.push("Generated OOXML is not well-formed XML: "+(o.error?.message||"parse error")),{isValid:!1,errors:r};let a=ne(i);a&&r.push("Generated OOXML is not well-formed XML: "+a.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&&rl()):!1}async maybeYield(t,r){this.enableEventLoopYielding&&(t<=this.yieldRunThreshold&&r<=this.yieldCharThreshold||await nl())}wrapForInsertion(t,r={}){return et(t,r)}async executeListGeneration(t,r,n,o=""){return At({cleanText:t,numberingContext:r,originalRunModel:n,originalText:o,generateRedlines:this.generateRedlines,author:this.author,font:this.font,revisionIdAllocator:this.revisionIdAllocator,numberingService:this.numberingService})}detectIndentationStep(t){return An(t)}executeTableGeneration(t){let r=$e(t);return r.rows.length===0&&r.headers.length===0?{ooxml:"",isValid:!1,warnings:["Could not parse Markdown table"]}:{ooxml:ut(r,{generateRedlines:this.generateRedlines,author:this.author,revisionIdAllocator:this.revisionIdAllocator}),isValid:!0,warnings:[],includeNumbering:!1}}};var ii=/^\s*\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)+\|?\s*$/;function ai(e){return!e||e.trim().length===0}function si(e){let t=String(e||"").trim();return t.startsWith("|")&&t.endsWith("|")}function ol(e){return String(e||"").trim().split("|").slice(1,-1).map(t=>t.trim())}function Pn(e){return ai(e)?"blank":/^\s*#{1,9}\s+\S/.test(e)?"heading":si(e)?"table":Be(e)?"list":"paragraph"}function _r(e){let r=(typeof e=="string"?e.replace(/\r\n?/g,`
138
+ `):String(e??"")).split(`
139
+ `),n=[],o=[],i=0;for(;i<r.length;){if(ai(r[i])){i++;continue}let l=Pn(r[i]),u=i+1;if(l==="heading"){let m=r[i].match(/^\s*(#{1,9})\s+(.+?)\s*$/);n.push({type:"heading",level:m[1].length,text:m[2],markdown:r[i].trim()}),i++;continue}if(l==="table"){let m=[];for(;i<r.length&&si(r[i]);)m.push(r[i].trim()),i++;let d=m.length>1&&ii.test(m[1]),p=m.filter(b=>!ii.test(b)).map(b=>ol(b).length);d||o.push({severity:"error",code:"TABLE_SEPARATOR_REQUIRED",line:u,message:"Markdown tables require a separator row immediately after the header (for example | --- | --- |)."}),p.length<2?o.push({severity:"error",code:"TABLE_DATA_ROW_REQUIRED",line:u,message:"Markdown tables require a header and at least one data row."}):new Set(p).size>1&&o.push({severity:"error",code:"TABLE_COLUMN_COUNT_MISMATCH",line:u,message:`Markdown table rows have inconsistent column counts: ${p.join(", ")}.`}),n.push({type:"table",columns:p[0]||0,rows:Math.max(0,p.length-1),hasHeader:d,markdown:m.join(`
140
+ `)});continue}if(l==="list"){let m=[];for(;i<r.length&&Pn(r[i])==="list";)m.push(r[i].trimEnd()),i++;n.push({type:"list",items:m.length,markdown:m.join(`
141
+ `)});continue}let c=[];for(;i<r.length&&Pn(r[i])==="paragraph";)c.push(r[i].trim()),i++;let f=c.join(" ").trim();n.push({type:"paragraph",text:f,markdown:f})}let a={heading:0,paragraph:0,list:0,table:0};for(let l of n)a[l.type]=(a[l.type]||0)+1;let s=n.map(l=>l.markdown).join(`
142
+
143
+ `);return{valid:o.every(l=>l.severity!=="error"),normalizedMarkdown:s,blocks:n,issues:o,counts:a,requiresStructuredContent:n.length>1||n.some(l=>l.type==="heading"||l.type==="table"||l.type==="list"&&l.items>1)}}function il(e,t,r={}){let n=_r(t);return{...n,operation:n.valid?{type:"replace",target:e,modified:n.normalizedMarkdown,structuredContent:!0,...r.author?{author:r.author}:{},...typeof r.generateRedlines=="boolean"?{generateRedlines:r.generateRedlines}:{},...r.existingRevisions?{existingRevisions:r.existingRevisions}:{}}:null}}var tr=["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","w:rPrChange"];function Pt(e,t){let r=tr.indexOf(t.nodeName),n=r===-1?999:r,o=!1;for(let i of Array.from(e.childNodes)){if(i.nodeType!==1)continue;let a=tr.indexOf(i.nodeName);if((a===-1?999:a)>n){e.insertBefore(t,i),o=!0;break}}o||e.appendChild(t)}function al(e,t,r,n){if(!t||!r)return;let o=!!r.bold,i=!!r.italic,a=!!r.underline,s=!!r.strikethrough,l=new Set;if(o&&(l.add("w:b"),l.add("w:bCs")),i&&(l.add("w:i"),l.add("w:iCs")),a&&l.add("w:u"),s&&l.add("w:strike"),l.size>0){let u=[];for(let c of Array.from(t.childNodes))l.has(c.nodeName)&&u.push(c);for(let c of u)t.removeChild(c)}if(o){let u=C(e,"w:b");u.setAttribute("w:val",n==="add"?"1":"0"),Pt(t,u);let c=C(e,"w:bCs");c.setAttribute("w:val",n==="add"?"1":"0"),Pt(t,c)}if(i){let u=C(e,"w:i");u.setAttribute("w:val",n==="add"?"1":"0"),Pt(t,u);let c=C(e,"w:iCs");c.setAttribute("w:val",n==="add"?"1":"0"),Pt(t,c)}if(a){let u=C(e,"w:u");u.setAttribute("w:val",n==="add"?"single":"none"),Pt(t,u)}if(s){let u=C(e,"w:strike");u.setAttribute("w:val",n==="add"?"1":"0"),Pt(t,u)}}function li(e,t,r){al(e,t,r,"remove")}function Ke(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=Lr(r,!1)),r.nodeName==="w:i"&&(t.italic=Lr(r,!1)),r.nodeName==="w:u"&&(t.underline=Lr(r,!0)),r.nodeName==="w:strike"&&(t.strikethrough=Lr(r,!1)),r.nodeName==="w:rStyle"){let n=r.getAttribute("w:val");if(n){let o=n.toLowerCase();(o.includes("bold")||o.includes("strong"))&&(t.bold=!0),(o.includes("italic")||o.includes("emphasis"))&&(t.italic=!0),o.includes("underline")&&(t.underline=!0)}}return t.hasFormatting=t.bold||t.italic||t.underline||t.strikethrough,t}function Lr(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 ci="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function Ue(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 sl(e){return!e||e.nodeType!==1||e.namespaceURI!==ci?!1:e.localName==="del"||e.localName==="moveFrom"}function ui(e){let t=[],r=Array.from(e?.childNodes||[]).reverse();for(;r.length>0;){let n=r.pop();if(!n||n.nodeType!==1||sl(n))continue;if(Ue(n,"r")){t.push(n);continue}let o=Array.from(n.childNodes||[]);for(let i=o.length-1;i>=0;i-=1)r.push(o[i])}return t}function ke(e){let t=new Set(["comment","footnote","endnote"]);return se(e,"*","p").filter(n=>{let o=n.parentNode;for(;o&&o.nodeName;){let i=String(o.localName||"").toLowerCase();if(t.has(i))return!1;o=o.parentNode}return!0})}function fi(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e[n],i=ui(o);for(let a of i){let s=ae(a,"w:rPr");Array.from(a.childNodes||[]).forEach(l=>{if(Ue(l,"t")){let u=l.textContent||"";u.length>0&&(t.push({charStart:r,charEnd:r+u.length,textElement:l,runElement:a,paragraph:o,container:a.parentNode,rPr:s}),r+=u.length)}else(Ue(l,"br")||Ue(l,"cr")||Ue(l,"tab")||Ue(l,"noBreakHyphen"))&&(t.push({charStart:r,charEnd:r+1,textElement:l,runElement:a,paragraph:o,container:a.parentNode,rPr:s}),r+=1)})}r=lt(r,n,e.length)}return{textSpans:t,charOffset:r}}function ll(e,t,r,n,o,i=null){let a=null;for(let u of Array.from(e.childNodes))if(Ue(u,"rPr")){a=u;break}let s=Ke(a);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 u of Array.from(e.childNodes))if(Ue(u,"t")){let c=u.textContent||"";if(c.length>0){let f=l,m=l+c.length;n.push({charStart:f,charEnd:m,textElement:u,runElement:e,paragraph:t,rPr:a,format:{...s}}),s.hasFormatting&&o.push({start:f,end:m,format:{...s},run:e,rPr:a}),l=m}}return l}function mi(e){let t=[],r=[],n=0,o=ke(e);for(let i=0;i<o.length;i++){let a=o[i],s=null;for(let c of Array.from(a.childNodes))if(Ue(c,"pPr")){for(let f of Array.from(c.childNodes))if(Ue(f,"rPr")){s=f;break}break}let l=Ke(s);l.hasFormatting&&k(`[OxmlEngine] Found paragraph-level formatting: ${JSON.stringify(l)}`);let u=ui(a);for(let c of u)n=ll(c,a,n,r,t,l);n=lt(n,i,o.length)}return k(`[OxmlEngine] Extracted ${r.length} text spans, ${t.length} format hints`),{existingFormatHints:t,textSpans:r,paragraphs:o}}function ft(e,t,r,n,o=null){let i=C(e,t==="ins"?"w:ins":"w:del"),a=o||ie(n,e,t==="ins"?"ins":"del");return i.setAttribute("w:id",String(a.id)),i.setAttribute("w:author",a.author),i.setAttribute("w:date",a.date),r&&i.appendChild(r),i}function di(e,t){return Array.from(e?.childNodes||[]).find(r=>r.nodeType===1&&(r.localName===t||r.nodeName===`w:${t}`))||null}function cl(e,t){let r=di(t,"pPr");return r?t.firstChild!==r&&t.insertBefore(r,t.firstChild||null):(r=C(e,"w:pPr"),t.insertBefore(r,t.firstChild||null)),r}function ul(e,t){let r=di(t,"rPr");return r?t.lastChild!==r&&t.appendChild(r):(r=C(e,"w:rPr"),t.appendChild(r)),r}function pi(e,t,r,n,o=null){let i=cl(e,t),a=ul(e,i);for(let u of Array.from(a.childNodes||[]))u.nodeType===1&&(u.localName==="ins"||u.localName==="del"||u.nodeName==="w:ins"||u.nodeName==="w:del")&&a.removeChild(u);let s=C(e,n==="ins"?"w:ins":"w:del"),l=o||ie(r,e,n==="ins"?"ins":"del");return s.setAttribute("w:id",String(l.id)),s.setAttribute("w:author",l.author),s.setAttribute("w:date",l.date),a.appendChild(s),s}function gi(e,t,r,n=null){return pi(e,t,r,"ins",n)}function rr(e,t,r,n=null){return pi(e,t,r,"del",n)}function tt(e,t,r,n){let o=C(e,"w:r");if(r&&o.appendChild(r.cloneNode(!0)),!n)return hi(e,o,t),o;let i=C(e,n?"w:delText":"w:t");return i.setAttribute("xml:space","preserve"),i.textContent=t,o.appendChild(i),o}function Br(e,t,r,n,o,i,a){if(!t)return[];let s=new Set([0,t.length]);for(let c of n){let f=Math.max(0,c.start-o),m=Math.min(t.length,c.end-o);f>=0&&f<t.length&&s.add(f),m>0&&m<=t.length&&s.add(m)}let l=Array.from(s).sort((c,f)=>c-f),u=[];for(let c=0;c<l.length-1;c++){let f=l[c],m=l[c+1],d=t.slice(f,m);if(!d)continue;let p=o+f,b=o+m,w=n.filter(x=>x.start<=p&&x.end>=b),g={...Ke(r)};w.forEach(x=>{x.format&&Object.assign(g,x.format)});let h=w.length>0?Rt(e,r,g,i,a):r?.cloneNode(!0)||null;u.push(Rn(e,d,h,!1))}return u}function Rn(e,t,r,n){let o=C(e,"w:r");if(r&&o.appendChild(r),!n)return hi(e,o,t),o;let i=C(e,n?"w:delText":"w:t");return i.setAttribute("xml:space","preserve"),i.textContent=t,o.appendChild(i),o}function hi(e,t,r){let o=String(r||"").split(/(\t|\n|\u2011)/);for(let i of o){if(!i)continue;if(i===" "){t.appendChild(C(e,"w:tab"));continue}if(i===`
144
+ `){t.appendChild(C(e,"w:br"));continue}if(i==="\u2011"){t.appendChild(C(e,"w:noBreakHyphen"));continue}let a=C(e,"w:t");/^\s|\s$/.test(i)&&a.setAttribute("xml:space","preserve"),a.textContent=i,t.appendChild(a)}}function Rt(e,t,r,n,o){let i=C(e,"w:rPr");t&&Array.from(t.childNodes).forEach(l=>{["w:b","w:bCs","w:i","w:iCs","w:u","w:strike","w:rPrChange"].includes(l.nodeName)||i.appendChild(l.cloneNode(!0))});let a=r||{bold:!1,italic:!1,underline:!1,strikethrough:!1};n&&o&&fl(e,i,n,t);let s=(l,u,c=null,f="0")=>{let m=C(e,l);u?c&&m.setAttribute("w:val",c):f&&m.setAttribute("w:val",f);let d=tr.indexOf(l),p=d===-1?999:d,b=!1;for(let w of Array.from(i.childNodes)){if(w.nodeType!==1)continue;let g=tr.indexOf(w.nodeName);if((g===-1?999:g)>p){i.insertBefore(m,w),b=!0;break}}b||i.appendChild(m)};return s("w:b",!!a.bold,"1","0"),s("w:bCs",!!a.bold,"1","0"),s("w:i",!!a.italic,"1","0"),s("w:iCs",!!a.italic,"1","0"),s("w:u",!!a.underline,"single","none"),s("w:strike",!!a.strikethrough,"1","0"),i}function Cn(e,t,r,n,o){let i=C(e,"w:rPrChange"),a=ie(r,e,"rPrChange");i.setAttribute("w:id",String(a.id)),i.setAttribute("w:author",a.author),i.setAttribute("w:date",n||a.date);let s=C(e,"w:rPr");Array.from((o||t).childNodes).forEach(c=>{c.nodeName!=="w:rPrChange"&&s.appendChild(c.cloneNode(!0))}),i.appendChild(s);let u=ae(t,"w:rPrChange");return u&&t.removeChild(u),t.appendChild(i),i}function fl(e,t,r,n){Cn(e,t,r,null,n||t)}var ml="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function Ct(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===ml&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function Fr(e,t,r){let n=new Map;for(let a of r)!a||!a.paragraph||(n.has(a.paragraph)||n.set(a.paragraph,[]),n.get(a.paragraph).push(a));let o=[],i=0;return t.forEach((a,s)=>{let l=(n.get(a)||[]).slice().sort((m,d)=>m.charStart-d.charStart),u=dl(l),c=On(u),f=c.trim();o.push({paragraph:a,spans:l,text:u,normalizedText:c,normalizedTrim:f,startOffset:i}),i+=c.length,i=lt(i,s,t.length)}),o}function wi(e,t){if(!t)return null;let r=On(t),n=r.trim();if(!n)return null;for(let o of e)if(o.normalizedText===r)return o;for(let o of e)if(o.normalizedTrim===n)return o;return null}function bi(e,t){let r=On(t),n=r.trim(),o=null,i=0;for(let a of e)if(a.normalizedText===r)return o=a,{targetInfo:o,matchOffset:i};if(n.length>0){for(let a of e)if(a.normalizedTrim===n)return o=a,{targetInfo:o,matchOffset:i}}if(n.length>0){let s=e.map(l=>l.normalizedText).join(`
145
+ `).indexOf(n);if(s!==-1)for(let l of e){let u=l.startOffset,c=l.normalizedText.length;if(s>=u&&s<=u+c){o=l,i=s-u;break}}}if(!o&&e.length===1&&r.length>0){let a=e[0],s=a.normalizedTrim||"";if(s.length>0){let l=r.indexOf(s);l>=0&&(o=a,i=-l)}}return{targetInfo:o,matchOffset:i}}function xi(e){let t=e;for(;t;){if(Ct(t,"p"))return t;t=t.parentNode}return null}function dl(e){if(!e||e.length===0)return"";let t="";for(let r of e){if(!r||!r.textElement)continue;let n=r.textElement;Ct(n,"t")?t+=r.textElement.textContent||"":Ct(n,"tab")?t+=" ":Ct(n,"br")||Ct(n,"cr")?t+=`
146
+ `:Ct(n,"noBreakHyphen")&&(t+="\u2011")}return t}function On(e){return e?e.replace(/\r/g,`
147
+ `).replace(/\u00a0/g," "):""}function Ni(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 o=[...t].sort((s,l)=>s.charStart-l.charStart||s.charEnd-l.charEnd),i=[],a=0;for(let s of o){for(;a<n.length&&n[a]<=s.charStart;)a++;let l=s;for(;a<n.length&&n[a]<l.charEnd;){let u=n[a],c=pl(e,l,u);if(!c){a++;continue}i.push(c[0]),l=c[1],a++}i.push(l)}return i}function pl(e,t,r){let n=t.runElement,o=n.parentNode;if(!o)return null;let i=t.textElement.textContent||"",a=r-t.charStart,s=i.substring(0,a),l=i.substring(a);if(s.length===0||l.length===0)return null;let u=tt(e,s,t.rPr,!1),c=tt(e,l,t.rPr,!1);o.insertBefore(u,n),o.insertBefore(c,n),o.removeChild(n);let f=u.getElementsByTagName("w:t")[0],m=c.getElementsByTagName("w:t")[0];return[{...t,charEnd:r,textElement:f,runElement:u},{...t,charStart:r,textElement:m,runElement:c}]}var gl="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function hl(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===gl&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function wl(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 vi(e,t,r,n,o,i=!0){let a=!1,s=new Set;k(`[OxmlEngine] Surgical format removal: ${r.length} hints to process (using w:rPrChange)`);for(let l of r){let u=l.run;if(s.has(u)||(s.add(u),!u.parentNode))continue;k("[OxmlEngine] Processing run for surgical format removal, format:",l.format);let c=ae(u,"w:rPr");c||(c=C(e,"w:rPr"),u.insertBefore(c,u.firstChild)),i&&Cn(e,c,o||me()),li(e,c,l.format),a=!0}return a?(k("[OxmlEngine] Surgical format removal completed successfully (Pure Format Mode)"),{oxml:n.serializeToString(e),hasChanges:!0}):(k("[OxmlEngine] No format changes were applied"),{oxml:n.serializeToString(e),hasChanges:!1})}function bl(e,t,r,n,o,i=!0){let a=!1,s=new Set;if(!t||t.length===0)return{oxml:n.serializeToString(e),hasChanges:!1};let l=[];for(let m of r)l.push(m.start,m.end);let c=Ni(e,t,l).slice().sort((m,d)=>m.charStart-d.charStart||m.charEnd-d.charEnd),f=xl(r);for(let m of c){if(!m||!m.textElement||!hl(m.textElement,"t"))continue;let d=f(m.charStart,m.charEnd);if(d.length===0)continue;let p=dn(...d.map($=>$.format)),b={bold:!!p.bold,italic:!!p.italic,underline:!!p.underline,strikethrough:!!p.strikethrough},w=m.format||Ke(m.rPr),g={bold:!!w.bold,italic:!!w.italic,underline:!!w.underline,strikethrough:!!w.strikethrough};if(!["bold","italic","underline","strikethrough"].some($=>b[$]!==g[$])||s.has(m.runElement)||(s.add(m.runElement),!(m.textElement.textContent||""))||!m.runElement.parentNode)continue;let y=m.runElement,N=ae(y,"w:rPr"),E=Rt(e,N,b,o||me(),i),P=N;if(!P)y.insertBefore(E,y.firstChild);else{for(;P.firstChild;)P.removeChild(P.firstChild);Array.from(E.childNodes).forEach($=>P.appendChild($))}a=!0}return{oxml:n.serializeToString(e),hasChanges:a}}function yi(e,t,r,n,o,i=!0,a=null){let s=wl(a),l=s.paragraphs||ke(e),u=s.textSpans||[];if(s.textSpans||({textSpans:u}=fi(l)),!u||u.length===0)return Le("[OxmlEngine] No spans available for surgical format-only change; requesting caller fallback strategy"),{hasChanges:!0,useNativeApi:!0,formatHints:r,originalText:t};if(!r||r.length===0)return{oxml:n.serializeToString(e),hasChanges:!1};let c=s.paragraphInfos||Fr(e,l,u),{targetInfo:f,matchOffset:m}=bi(c,t);if(!f||!f.spans||f.spans.length===0)return Le("[OxmlEngine] Unable to pinpoint target paragraph for surgical format-only change; requesting caller fallback strategy"),{hasChanges:!0,useNativeApi:!0,formatHints:r,originalText:t};let d=f.spans[0].charStart,p=f.spans.map(w=>({...w,charStart:w.charStart-d,charEnd:w.charEnd-d})),b=r.map(w=>({...w,start:w.start+m,end:w.end+m}));return bl(e,p,b,n,o,i)}function xl(e){let t=(e||[]).slice().sort((o,i)=>o.start-i.start||o.end-i.end),r=[],n=0;return(o,i)=>{for(;n<t.length&&t[n].start<i;)r.push(t[n]),n++;for(let a=r.length-1;a>=0;a--)r[a].end<=o&&r.splice(a,1);return r.filter(a=>a.start<i&&a.end>o)}}function $r(e){return String(e?.localName||e?.nodeName||"").replace(/^.*:/,"")}function mt(e,t=null,r="accepted"){let n=r==="current"?"accepted":r,o=e;for(;o&&o!==t;){let i=$r(o);if(n==="accepted"&&(i==="del"||i==="moveFrom")||n==="rejected"&&(i==="ins"||i==="moveTo"))return!1;o=o.parentNode}return!0}function dt(e,t={}){let r=t.revisionView==="current"?"accepted":t.revisionView||"accepted",n=t.boundary||null;if(!mt(e,n,r))return"";let o="",i=a=>{for(let s of Array.from(a?.childNodes||[])){if(s?.nodeType!==1||s.namespaceURI&&s.namespaceURI!==S||!mt(s,n,r))continue;let l=$r(s);l==="t"||l==="delText"&&r==="rejected"?o+=s.textContent||"":l==="tab"?o+=" ":l==="br"||l==="cr"?o+=`
148
+ `:l==="noBreakHyphen"?o+="\u2011":l==="softHyphen"?o+="\xAD":i(s)}};return i(e),o}var rt=(e,t)=>e?.getAttribute?.(`w:${t}`)||e?.getAttribute?.(t)||"";function Xr(e,t={}){if(!e)return[];let r=[];function n(f,m,d){for(let p of Array.from(f?.childNodes||[])){if(p?.nodeType!==1||p.namespaceURI&&p.namespaceURI!==S)continue;let b=$r(p);if(b==="pPr"||b==="rPr")continue;let w=m;b==="ins"?w={kind:"insertion",author:rt(p,"author")||void 0,revisionId:rt(p,"id")||void 0}:b==="del"?w={kind:"deletion",author:rt(p,"author")||void 0,revisionId:rt(p,"id")||void 0}:b==="moveFrom"?w={kind:"move_from",author:rt(p,"author")||void 0,revisionId:rt(p,"id")||void 0}:b==="moveTo"&&(w={kind:"move_to",author:rt(p,"author")||void 0,revisionId:rt(p,"id")||void 0});let g=d;b==="r"&&(g=p);let h=null,x=w?w.kind:"baseline",v=w?.author,T=w?.revisionId;b==="t"?h=p.textContent||"":b==="delText"?(h=p.textContent||"",w||(x="deletion")):b==="tab"?h=" ":b==="br"||b==="cr"?h=`
149
+ `:b==="noBreakHyphen"?h="\u2011":b==="softHyphen"&&(h="\xAD"),h!==null?h.length>0&&r.push({text:h,kind:x,author:v,revisionId:T,carrier:g||p,carrierContainer:(g||p)?.parentNode||null}):n(p,w,g)}}let o=$r(e)==="r"?e:null;if(n(e,null,o),r.length===0)return[];let i=t.mergeRuns!==!1,a=[],s=null;for(let f of r){if(!s){s={...f};continue}let m=s.kind===f.kind,d=s.author===f.author,p=s.revisionId===f.revisionId,b=s.carrier===f.carrier,w=i&&s.carrierContainer===f.carrierContainer;m&&d&&p&&(b||w)?s.text+=f.text:(a.push(s),s={...f})}s&&a.push(s);let l=0,u=0,c=[];for(let f of a){let m=f.kind!=="deletion"&&f.kind!=="move_from",d=f.kind!=="insertion"&&f.kind!=="move_to",p=m?l:null,b=d?u:null;m&&(l+=f.text.length),d&&(u+=f.text.length);let w={text:f.text,kind:f.kind,acceptedStart:p,rejectedStart:b};f.author!==void 0&&(w.author=f.author),f.revisionId!==void 0&&(w.revisionId=f.revisionId),c.push(w)}return c}function ye(e,t={}){if(!e)return"";let r=t.revisionView==="current"?"accepted":t.revisionView||"accepted",n=Xr(e,t);return r==="rejected"?n.filter(o=>o.rejectedStart!==null).map(o=>o.text).join(""):n.filter(o=>o.acceptedStart!==null).map(o=>o.text).join("")}var Nl="http://schemas.microsoft.com/office/word/2010/wordml";function Ti(e,t,r={}){let{targetParagraphId:n=null}=r,o=ve(e,S,"tbl");if(o.length===0)return{hasTableWrapper:!1,isTableCellParagraph:!1,paragraphs:[],paragraph:null,tableElement:null};let a=ke(e).filter(l=>{let u=l.parentNode;for(;u;){if(I(u,"tc"))return!0;u=u.parentNode}return!1});k(`[OxmlEngine] Table wrapper detected: ${o.length} tables, ${a.length} paragraphs in cells`);let s=null;if(n){let l=String(n).toUpperCase();s=a.find(u=>{let c=yl(u);return c&&c.toUpperCase()===l})||null,s?k(`[OxmlEngine] Found target paragraph by paraId: "${n}"`):k(`[OxmlEngine] paraId "${n}" not found in wrapper, falling back to text match`)}if(t&&t.trim()){let l=t.trim();if(!s){for(let u of a)if(ye(u).trim()===l){s=u,k(`[OxmlEngine] Found target paragraph by text match: "${l.substring(0,30)}..."`);break}}}return{hasTableWrapper:!0,isTableCellParagraph:a.length>0,targetParagraph:s,paragraphs:a,paragraph:s||a[0]||null,tableElement:o[0]}}function nr(e,t,r){let n=Array.isArray(t)?t:[t],o="";for(let i of n){if(!i)continue;let a=r.serializeToString(i);a=a.replace(/\s+xmlns:w="[^"]*"/g,""),a=a.replace(/\s+xmlns:r="[^"]*"/g,""),a=a.replace(/\s+xmlns:wp="[^"]*"/g,""),o+=a}return k(`[OxmlEngine] Stripping table wrapper, serializing ${n.length} paragraphs`),k(`[OxmlEngine] Paragraph XML preview: ${o.substring(0,200)}...`),vl(o)}function vl(e){return Jo(e)}function yl(e){if(!e)return null;let t=typeof e.getAttributeNS=="function"?e.getAttributeNS(Nl,"paraId"):null;return t||e.getAttribute("w14:paraId")||e.getAttribute("w:paraId")||e.getAttribute("paraId")||null}function kn(e){return I(e,"t")?e.textContent||"":I(e,"br")||I(e,"cr")?`
150
+ `:I(e,"tab")?" ":I(e,"noBreakHyphen")?"\u2011":I(e,"softHyphen")?"\xAD":""}function Mn(e){return I(e,"t")||I(e,"br")||I(e,"cr")||I(e,"tab")||I(e,"noBreakHyphen")||I(e,"softHyphen")}function Si(e){let t="",r=[];return e.forEach((n,o)=>{let i=n.parentNode;for(let a=n.firstChild;a;a=a.nextSibling)if(I(a,"r"))t+=or(a,n,i,t.length,r).text;else if(I(a,"hyperlink"))for(let s=a.firstChild;s;s=s.nextSibling)I(s,"r")&&(t+=or(s,n,i,t.length,r).text);else if(I(a,"ins"))for(let s=a.firstChild;s;s=s.nextSibling)I(s,"r")&&(t+=or(s,n,i,t.length,r).text);else if(I(a,"sdt")){let s=Array.from(a.childNodes||[]).find(l=>I(l,"sdtContent"));if(s)for(let l=s.firstChild;l;l=l.nextSibling)I(l,"r")&&(t+=or(l,n,i,t.length,r).text)}else if(I(a,"smartTag"))for(let s=a.firstChild;s;s=s.nextSibling)I(s,"r")&&(t+=or(s,n,i,t.length,r).text);t=Tt(t,o,e.length)}),{fullText:t,textSpans:r}}function or(e,t,r,n,o){let i=ae(e,"w:rPr"),a=n,s=[];for(let l=e.firstChild;l;l=l.nextSibling)if(I(l,"t")){let u=l.textContent||"";if(u.length===0)continue;o.push({charStart:a,charEnd:a+u.length,textElement:l,runElement:e,paragraph:t,container:r,rPr:i}),a+=u.length,s.push(u)}else if(Mn(l)){let u=kn(l);o.push({charStart:a,charEnd:a+1,textElement:l,runElement:e,paragraph:t,container:r,rPr:i}),a+=1,s.push(u)}return{text:s.join("")}}function Ei(e){let t=e.slice().sort((o,i)=>o.charStart-i.charStart||o.charEnd-i.charEnd),r=t.map(o=>o.charStart),n=t.map(o=>o.charEnd);return{spans:t,starts:r,ends:n}}function ir(e,t,r,n){if(r<=t||e.spans.length===0)return;let o=Fn(e.ends,t);for(;o<e.spans.length;){let i=e.spans[o];if(i.charStart>=r)break;n(i),o++}}function _n(e,t){if(e.spans.length===0)return null;let r=Fn(e.starts,t)-1;if(r<0)return null;let n=e.spans[r];return t>=n.charStart&&t<n.charEnd?n:null}function Ln(e,t){let r=Tl(e.ends,t);return r<e.spans.length&&e.ends[r]===t?e.spans[r]:null}function Bn(e,t){let r=Fn(e.ends,t)-1;return r>=0?e.spans[r]:null}function Fn(e,t){let r=0,n=e.length;for(;r<n;){let o=r+n>>1;e[o]<=t?r=o+1:n=o}return r}function Tl(e,t){let r=0,n=e.length;for(;r<n;){let o=r+n>>1;e[o]<t?r=o+1:n=o}return r}function Ii(e,t,r=null){if(!e||!e.spans||e.spans.length===0)return{leftSpan:null,rightSpan:null,containingSpan:null,isInterior:!1,fallbackParagraph:r};let n=_n(e,t),o=n!==null&&t>n.charStart&&t<n.charEnd,i=Ln(e,t)||(t>0?Bn(e,t):null),a=e.spans.find(s=>s.charStart===t)||(t===0?e.spans[0]:null);return{leftSpan:i,rightSpan:a,containingSpan:n,isInterior:o,fallbackParagraph:r}}function Dr(e){let t=[],r=0;for(let n of Array.from(e.childNodes||[])){if(I(n,"rPr")||!Mn(n))continue;let o=kn(n);o.length!==0&&(t.push({node:n,start:r,end:r+o.length,text:o}),r+=o.length)}return t}function nt(e){return e.length===0?0:e[e.length-1].end}function ot(e,t,r,n,o){let i=[];return n<=r||t.forEach(a=>{let s=Math.max(r,a.start),l=Math.min(n,a.end);if(l<=s)return;let u=s-a.start,c=l-a.start,f=a.text.slice(u,c);i.push(Sl(e,a.node,f,o))}),i}function $n(e,t,r){let n=C(e,"w:r");return r&&n.appendChild(r.cloneNode(!0)),t.forEach(o=>n.appendChild(o)),n}function pt(e,t,r,n,o){if(n.length===0)return null;let i=$n(e,n,o);return t.insertBefore(i,r),i}function Sl(e,t,r,n){if(n){let i=C(e,"w:delText");return i.setAttribute("xml:space","preserve"),i.textContent=r,i}if(I(t,"t")){let i=t.cloneNode(!1);return i.textContent=r,/^\s|\s$/.test(r)&&i.setAttribute("xml:space","preserve"),i}if(r===`
151
+ `&&(I(t,"br")||I(t,"cr"))||r===" "&&I(t,"tab")||r==="\u2011"&&I(t,"noBreakHyphen"))return t.cloneNode(!0);let o=C(e,"w:t");return o.setAttribute("xml:space","preserve"),o.textContent=r,o}function Ai(e,t,r,n,o,i,a){if(o.length===0)return!1;let s=t.rPr,l=Ke(s),u={...l};if(o.forEach(y=>Object.assign(u,y.format)),!["bold","italic","underline","strikethrough"].some(y=>!!u[y]!==l[y]))return!1;let m=t.runElement.parentNode;if(!m)return!1;let d=t.textElement.textContent||"",p=t.charStart,b=r-p,w=n-p,g=d.substring(0,b),h=d.substring(b,w),x=d.substring(w);if(g.length>0){let y=tt(e,g,s,!1);m.insertBefore(y,t.runElement)}let v=Rt(e,s,u,i,a),T=Rn(e,h,v,!1);if(m.insertBefore(T,t.runElement),x.length>0){let y=tt(e,x,s,!1);m.insertBefore(y,t.runElement)}return m.removeChild(t.runElement),!0}function Pi(e,t,r,n,o,i,a=null){let s=[];if(ir(t,r,n,f=>{s.push(f)}),s.length===0)return!1;let l=new Map;s.forEach(f=>{f.runElement?.parentNode&&(l.has(f.runElement)||l.set(f.runElement,[]),l.get(f.runElement).push(f))});let u=!1,c=!1;return l.forEach((f,m)=>{let d=m.parentNode;if(!d)return;let p=Dr(m);if(p.length===0)return;let b=1/0,w=-1/0;if(f.forEach(v=>{let T=p.find(E=>E.node===v.textElement);if(!T)return;let y=Math.max(0,r-v.charStart),N=Math.min(v.charEnd-v.charStart,n-v.charStart);N<=y||(b=Math.min(b,T.start+y),w=Math.max(w,T.start+N))}),!Number.isFinite(b)||w<=b)return;let g=ot(e,p,0,b,!1),h=ot(e,p,b,w,!0),x=ot(e,p,w,nt(p),!1);if(pt(e,d,m,g,f[0].rPr),i&&h.length>0){let v=$n(e,h,f[0].rPr),T=a?c?{...a,id:ie(o,e).id}:a:null;c=!0;let y=ft(e,"del",v,o,T);d.insertBefore(y,m)}pt(e,d,m,x,f[0].rPr),d.removeChild(m),u=!0}),u}function Xn(e,t,r,n,o,i=[],a=0,s=!0,l=null,u=null,c=null){if(!c){let h=_n(t,r);if(!h&&r>0&&(h=Ln(t,r)),!h&&r>0&&(h=Bn(t,r)),!h&&t.spans.length>0&&(h=t.spans[t.spans.length-1]),!h)return l?(Ot(e,l,null,n,null,o,i,a,s,u),!0):!1;let x=h.runElement.parentNode;if(!x)return l?(Ot(e,l,null,n,h.rPr,o,i,a,s,u),!0):!1;let v=Dr(h.runElement),T=v.find(E=>E.node===h.textElement),y=T?T.start+Math.max(0,Math.min(r-h.charStart,h.charEnd-h.charStart)):r<=h.charStart?0:nt(v);if(y>0&&y<nt(v)){let E=ot(e,v,0,y,!1),P=ot(e,v,y,nt(v),!1);return pt(e,x,h.runElement,E,h.rPr),Ot(e,x,h.runElement,n,h.rPr,o,i,a,s,u),pt(e,x,h.runElement,P,h.rPr),x.removeChild(h.runElement),!0}let N=r<=h.charStart?h.runElement:h.runElement.nextSibling;return Ot(e,x,N,n,h.rPr,o,i,a,s,u),!0}let f=Ii(t,r,l),m=f.leftSpan&&I(f.leftSpan.runElement?.parentNode,"hyperlink"),d=f.rightSpan&&I(f.rightSpan.runElement?.parentNode,"hyperlink"),p=f.containingSpan&&I(f.containingSpan.runElement?.parentNode,"hyperlink");if(c.hyperlink==="outside"){if(f.isInterior&&p)return{error:{code:"UNSUPPORTED_INSERTION_AFFINITY",message:"Cannot place insertion outside hyperlink from strictly interior position."}}}else if(c.hyperlink==="inside"&&!m&&!d&&!p)return{error:{code:"UNSUPPORTED_INSERTION_AFFINITY",message:"Cannot place insertion inside hyperlink when no hyperlink is present at boundary."}};let b=null;if(c.formatting==="none"?b=null:c.formatting==="right"?b=f.rightSpan?.rPr||null:c.formatting==="left"?b=f.leftSpan?.rPr||null:b=(f.containingSpan||f.leftSpan||f.rightSpan)?.rPr||null,f.isInterior){let h=f.containingSpan,x=h.runElement.parentNode||l;if(!x)return!1;let v=Dr(h.runElement),T=v.find(N=>N.node===h.textElement),y=T?T.start+Math.max(0,Math.min(r-h.charStart,h.charEnd-h.charStart)):r<=h.charStart?0:nt(v);if(y>0&&y<nt(v)){let N=ot(e,v,0,y,!1),E=ot(e,v,y,nt(v),!1);return pt(e,x,h.runElement,N,h.rPr),Ot(e,x,h.runElement,n,b,o,i,a,s,u),pt(e,x,h.runElement,E,h.rPr),x.removeChild(h.runElement),!0}}let w=null,g=null;if(c.hyperlink==="outside"){if(d){let h=f.rightSpan.runElement.parentNode;w=h.parentNode||l,g=h}else if(m){let h=f.leftSpan.runElement.parentNode;w=h.parentNode||l,g=h.nextSibling}}else c.hyperlink==="inside"&&(d?(w=f.rightSpan.runElement.parentNode,g=f.rightSpan.runElement):m&&(w=f.leftSpan.runElement.parentNode,g=f.leftSpan.runElement.nextSibling));if(w||(f.rightSpan?(w=f.rightSpan.runElement.parentNode||l,g=f.rightSpan.runElement):f.leftSpan?(w=f.leftSpan.runElement.parentNode||l,g=f.leftSpan.runElement.nextSibling):(w=l,g=null)),c.bookmark&&w&&(c.bookmark==="outside"?(g&&I(g.previousSibling,"bookmarkStart")&&(g=g.previousSibling),f.leftSpan&&I(f.leftSpan.runElement.nextSibling,"bookmarkEnd")&&(g=f.leftSpan.runElement.nextSibling.nextSibling)):c.bookmark==="inside"&&(g&&I(g,"bookmarkStart")&&(g=g.nextSibling),f.leftSpan&&I(f.leftSpan.runElement.nextSibling,"bookmarkEnd")&&(g=f.leftSpan.runElement.nextSibling))),c.comment&&w)if(c.comment==="outside"){if(g&&I(g.previousSibling,"commentRangeStart")&&(g=g.previousSibling),f.leftSpan&&I(f.leftSpan.runElement.nextSibling,"commentRangeEnd")){let h=f.leftSpan.runElement.nextSibling.nextSibling;h&&(I(h,"commentReference")||I(h,"r"))&&Array.from(h.childNodes||[]).some(v=>I(v,"commentReference"))&&(h=h.nextSibling),g=h}}else c.comment==="inside"&&(g&&I(g,"commentRangeStart")&&(g=g.nextSibling),f.leftSpan&&I(f.leftSpan.runElement.nextSibling,"commentRangeEnd")&&(g=f.leftSpan.runElement.nextSibling));if(s&&c.revision==="coalesce_same_author"){let h=null,x=null;if(f.leftSpan&&I(f.leftSpan.runElement.parentNode,"ins")){let v=f.leftSpan.runElement.parentNode;(v.getAttribute("w:author")||v.getAttributeNS(S,"author"))===o&&(h=v,x=f.leftSpan.runElement.nextSibling)}else if(f.rightSpan&&I(f.rightSpan.runElement.parentNode,"ins")){let v=f.rightSpan.runElement.parentNode;(v.getAttribute("w:author")||v.getAttributeNS(S,"author"))===o&&(h=v,x=f.rightSpan.runElement)}if(h){let v=tt(e,n,b,!1);return h.insertBefore(v,x),!0}}return Ot(e,w,g,n,b,o,i,a,s,u),!0}function Ot(e,t,r,n,o,i,a,s,l,u=null){let c=Ve(a,s,s+n.length);if(c.length===0){let m=tt(e,n,o,!1);if(l){let d=ft(e,"ins",m,i,u);t.insertBefore(d,r)}else t.insertBefore(m,r);return}let f=Br(e,n,o,c,s,i,l);if(l){let m=ft(e,"ins",null,i,u);f.forEach(d=>m.appendChild(d)),t.insertBefore(m,r)}else f.forEach(m=>t.insertBefore(m,r))}function El(e,t,r){let n=[];if(ir(e,t,r,m=>n.push(m)),n.length===0)return{safe:!1};let o=n[0].runElement,i=o?.parentNode;if(!i)return{safe:!1};if(!n.every(m=>m.runElement?.parentNode===i))return{safe:!1,structuralBoundary:!0};let s=i.localName||i.nodeName.replace(/^.*:/,"");if(["hyperlink","sdt","ins","del","moveFrom","moveTo"].includes(s))return{safe:!1,structuralBoundary:!0};let l=new Set(["hyperlink","fldSimple","sdt","commentRangeStart","commentRangeEnd","commentReference","bookmarkStart","bookmarkEnd","moveFrom","moveTo","ins","del"]);for(let m of n){let d=m.runElement;for(let p of Array.from(d.childNodes||[]))if(p.nodeType===1){let b=p.localName||p.nodeName.replace(/^.*:/,"");if(l.has(b)||b==="fldChar")return{safe:!1,structuralBoundary:!0}}}let u=n[n.length-1].runElement,c=o;for(;c&&c!==u;){if(c!==o){let m=c.localName||c.nodeName.replace(/^.*:/,"");if(l.has(m))return{safe:!1,structuralBoundary:!0}}c=c.nextSibling}function f(m){if(!m||m.nodeType!==1)return!1;let d=m.localName||m.nodeName.replace(/^.*:/,"");if(l.has(d)||d==="fldChar")return!0;for(let p of Array.from(m.childNodes||[]))if(p.nodeType===1&&f(p))return!0;return!1}return f(o.previousSibling)||f(u.nextSibling)?{safe:!1,structuralBoundary:!0}:{safe:!0}}function Ri(e,t,r,n,o,i,a=!0,s=null,l={},u={}){let c=s?[s]:ke(e),{fullText:f,textSpans:m}=Si(c),d=Qt(f,r,l),p=Ei(m),b=u.pairReplacements===!0,w=[],g=0,h=0,x=!1;for(let v=0;v<d.length;v++){let[T,y]=d[v];if(T===0){let N=y.length,E=g,P=g+N;ir(p,E,P,$=>{let L=Math.max($.charStart,E),z=Math.min($.charEnd,P),j=z-L,O=L-E,H=h+O,R=H+j,_=Ve(i,H,R);Ai(e,$,L,z,_,o,a)&&(x=!0)}),g+=N,h+=N}else if(T===-1){let N=v+1<d.length&&d[v+1][0]===1,E=!1,P=null,$=null;if(b&&a&&N&&d[v+1][1].replace(/\n/g," ").trim().length>0){let j=El(p,g,g+y.length);if(j.safe){let O=Ir(o,e);P={id:O.deletionId,author:O.author,date:O.date},$={id:O.insertionId,author:O.author,date:O.date},E=!0}else j.structuralBoundary&&w.push("PAIRING_SKIPPED_STRUCTURAL_BOUNDARY")}if(Pi(e,p,g,g+y.length,o,a,P)&&(x=!0),g+=y.length,E){v++;let[,L]=d[v],z=L.replace(/\n/g," ");if(z.trim().length>0){let j=Xn(e,p,g,z,o,i,h,a,c[0]||null,$,u?.insertionAffinity||null);if(j&&typeof j=="object"&&j.error)return de({oxml:n.serializeToString(e),hasChanges:!1,status:"error",error:j.error});j===!0&&(x=!0)}h+=L.length}}else if(T===1){let N=y.replace(/\n/g," ");if(N.trim().length>0){let E=Xn(e,p,g,N,o,i,h,a,c[0]||null,null,u?.insertionAffinity||null);if(E&&typeof E=="object"&&E.error)return de({oxml:n.serializeToString(e),hasChanges:!1,status:"error",error:E.error});E===!0&&(x=!0)}h+=y.length}}return de({oxml:n.serializeToString(e),hasChanges:x,...w.length>0?{warnings:[...new Set(w)]}:{}})}var Oi=No(yn(),1);var ki=new Oi.diff_match_patch;function Mi(e){return String(e?.localName||e?.nodeName||"").replace(/^.*:/,"")}function Il(e,t){return e?.getAttributeNS?.(S,t)||e?.getAttribute?.(`w:${t}`)||e?.getAttribute?.(t)||""}function Ci(e){let t=0;return{at(r){if(t>0&&(!e[t]||r<e[t].start)){let o=0,i=t-1;for(;o<=i;){let a=Math.floor((o+i)/2);e[a].end<=r?o=a+1:i=a-1}t=o}for(;t<e.length&&e[t].end<=r;)t++;let n=e[t];return n&&n.start<=r&&r<n.end?n:null}}}function Al(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 _i(e,t,r=null){let n=e.documentElement,o=I(n,"body")||Mi(n)==="package",i=r||ke(e),a=be(e,S,"body");!a&&o&&(a=n);let s="",l=[],u=[],c=[],f=new Map,m=new Map,d=new Set,p={nextCharCode:57344},b=new Set;i.forEach((L,z)=>{let j=s.length;Array.from(L.childNodes).forEach(_=>{s=kl(_,s,l,c,f,m,p,d)}),s=Tt(s,z,i.length);let O=s.length,H=be(L,S,"pPr"),R=L.parentNode;R&&b.add(R),u.push({start:j,end:O,pPr:H,container:R||a})});let w="";for(let L=0;L<s.length;L++){let z=s[L];w+=d.has(z)?`
152
+ `:z}let g=Cl(w,t,c);g=Rl(w,s,g,d),m.forEach((L,z)=>{let j=z.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");g=g.replace(new RegExp(j,"g"),L)}),g=Ol(s,g,f);let h=new Map;b.forEach(L=>{h.set(L,e.createDocumentFragment())}),a&&!h.has(a)&&h.set(a,e.createDocumentFragment()),h.has(e)||h.set(e,e.createDocumentFragment());let x=new Map,v=new Set(u.map(L=>L.start)),T=Ci(u),y=Ci(l),N=Al(c);return{paragraphs:i,body:a||e,paragraphMap:u,paragraphStarts:v,propertyMap:l,sentinelMap:c,sentinelMapByStart:N,referenceMap:f,tokenToCharMap:m,containerFragments:h,replacementContainers:x,originalFullText:s,processedModifiedText:g,getParagraphInfo:L=>{let z=T.at(L);return z||(u.length>0?u[u.length-1]:{start:0,end:0,pPr:null,container:a||e})},getRunProperties:L=>{let z=y.at(L);return z?{rPr:z.rPr,wrapper:z.wrapper}:{rPr:null}},getPropertySpanLength:(L,z)=>{let j=y.at(L);return j?Math.min(j.end-L,z):1},isParagraphStart:L=>v.has(L)}}function Li(e,t){let r=ke(e);if(r.length===0)return[];let n=Bi(t),o=r.map(Pl);if(!n){let a=o.findIndex(s=>s==="");return a>=0?[r[a]]:null}if(r.length===1&&o[0]==="")return r;let i=[a=>a,a=>a.trim(),a=>a.replace(/\s+/g," ").trim()];for(let a of i){let s=a(n);for(let l=0;l<r.length;l++){let u="";for(let c=l;c<r.length;c++)if(u+=(c===l?"":`
153
+ `)+o[c],a(u)===s)return r.slice(l,c+1)}}return null}function Bi(e){return String(e??"").replace(/\r\n?/g,`
154
+ `).replace(/\u00a0/g," ")}function Pl(e){let t="",r=n=>{for(let o of Array.from(n?.childNodes||[]))o.nodeType===1&&(I(o,"pPr")||I(o,"del")||I(o,"moveFrom")||(I(o,"t")?t+=o.textContent||"":I(o,"tab")?t+=" ":I(o,"br")||I(o,"cr")?t+=`
155
+ `:I(o,"noBreakHyphen")?t+="\u2011":r(o)))};return r(e),Bi(t)}function Rl(e,t,r,n){if(n.size===0)return r;let o=ki.diff_main(e,r),i=0,a="";for(let[s,l]of o)if(s===0){for(let u=0;u<l.length;u++){let c=t[i+u];a+=n.has(c)?c:l[u]}i+=l.length}else s===-1?i+=l.length:a+=l;return a}function Cl(e,t,r){let n=new Map;if(r.forEach(f=>{f.zeroWidth&&n.set(f.start,f)}),n.size===0)return t;let o="",i=0,a=new Map;for(let f=0;f<e.length;f++){let m=n.get(f);if(m){a.has(i)||a.set(i,[]),a.get(i).push({char:e[f],affinity:m.affinity||"right",emitted:!1});continue}o+=e[f],i++}let s=ki.diff_main(o,t),l=0,u="",c=(f,m)=>{let d=a.get(f)||[];for(let p of d)p.emitted||m&&p.affinity!==m||(u+=p.char,p.emitted=!0)};for(let[f,m]of s){if(f===1){c(l,"left"),u+=m;continue}for(let d=0;d<m.length;d++)c(l),f===0&&(u+=m[d]),l++}return c(l),u}function Ol(e,t,r){let n=t;for(let o of r.keys()){if(n.includes(o))continue;let i=e.indexOf(o);if(i<0)continue;let a=e.slice(0,i),s=e.slice(i+o.length);if(a&&n.startsWith(a)){n=`${n.slice(0,a.length)}${o}${n.slice(a.length)}`;continue}if(s&&n.endsWith(s)){let l=n.length-s.length;n=`${n.slice(0,l)}${o}${n.slice(l)}`}}return n}function kl(e,t,r,n,o,i,a,s){return I(e,"r")?Ml(e,t,r,n,o,i,a,s):I(e,"hyperlink")?_l(e,t,r):I(e,"sdt")||I(e,"oMath")||Mi(e)==="oMath"||I(e,"bookmarkStart")||I(e,"bookmarkEnd")?(n.push({start:t.length,node:e}),t+"\uFFFC"):((I(e,"commentRangeStart")||I(e,"commentRangeEnd"))&&n.push({start:t.length,node:e,isCommentMarker:!0}),t)}function Ml(e,t,r,n,o,i,a,s){let l=t,u=be(e,S,"rPr");return Array.from(e.childNodes).forEach(c=>{if(I(c,"t")){let f=c.textContent||"";f.length>0&&(r.push({start:l.length,end:l.length+f.length,rPr:u}),l+=f)}else if(I(c,"br")||I(c,"cr")){let f=String.fromCharCode(a.nextCharCode++);o.set(f,c),s.add(f),l+=f,r.push({start:l.length-1,end:l.length,rPr:u})}else if(I(c,"tab"))l+=" ",r.push({start:l.length-1,end:l.length,rPr:u});else if(I(c,"noBreakHyphen"))l+="\u2011",r.push({start:l.length-1,end:l.length,rPr:u});else if(["drawing","pict","object","fldChar","instrText","sym"].some(f=>I(c,f))){let f=be(c,S,"txbxContent"),m=I(c,"pict")&&!!f,d=I(c,"fldChar")||I(c,"instrText"),p=I(c,"fldChar")?c.getAttributeNS?.(S,"fldCharType")||c.getAttribute("w:fldCharType")||c.getAttribute("fldCharType"):null;n.push({start:l.length,node:c,wrapInRun:!0,rPr:u,zeroWidth:d,affinity:p==="end"?"left":"right",isTextBox:m,originalContainer:m?f:void 0}),l+="\uFFFC",r.push({start:l.length-1,end:l.length,rPr:u})}else if(I(c,"footnoteReference")||I(c,"endnoteReference")){let f=Il(c,"id");if(f){let d=`{{__${I(c,"footnoteReference")?"FN":"EN"}_${f}__}}`,p=String.fromCharCode(a.nextCharCode++);o.set(p,c),i.set(d,p),l+=p,r.push({start:l.length-1,end:l.length,rPr:u})}}else I(c,"commentReference")&&n.push({start:l.length,node:c,isCommentMarker:!0})}),l}function _l(e,t,r){let n=t;return Array.from(e.childNodes).forEach(o=>{if(!I(o,"r"))return;let i=be(o,S,"rPr");ve(o,S,"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 $i(e,t,r,n,o,i,a=!0,s={}){let{paragraphs:l,containerFragments:u,sentinelMapByStart:c,referenceMap:f,replacementContainers:m,getParagraphInfo:d,getRunProperties:p,getPropertySpanLength:b,isParagraphStart:w}=r,g=R=>{let _=C(e,"w:p");if(R){let F=R.cloneNode(!0),Z=be(F,S,"sectPr");Z&&F.removeChild(Z),_.appendChild(F)}return _},h=d(0),x=g(h.pPr),v=u.get(h.container);v&&v.appendChild(x);let T=0,y=0,N=s?.pairReplacements===!0,E=null,P=null,$=new WeakSet;for(let R=0;R<t.length;R++){let[_,F]=t[R];if(_===0||_===-1){let Z=_===0?"equal":"delete";if(_===0)E=null,P=null;else if(E===null){E=T;let Q=!1;for(let ee=R+1;ee<t.length;ee++){if(t[ee][0]===1){Q=!0;break}if(t[ee][0]===0)break}N&&a&&Q&&(P=Ir(o,e))}let G=0;for(;G<F.length;){let Q=T+G,ee=p(Q),ze=b(Q,F.length-G),Nr=F.substring(G,G+ze);x=Fi(e,Nr,Z,ee.rPr,ee.wrapper,Q,x,u,c,f,m,d,g,o,i,y,a,$,P).currentParagraph,_===0&&(y+=ze),G+=ze}T+=F.length;continue}if(_===1){let Z=E!==null?E:T>0&&!w(T)?T-1:T,G=p(Z);x=Fi(e,F,"insert",G.rPr,G.wrapper,T,x,u,c,f,m,d,g,o,i,y,a,$,P,E!==null).currentParagraph,y+=F.length,E=null,P=null}}a&&u.forEach(R=>{Array.from(R.childNodes).forEach(_=>{if(I(_,"p")){let F=Array.from(_.getElementsByTagNameNS(S,"t")).length>0,Z=Array.from(_.getElementsByTagNameNS(S,"delText")).length>0;l.length===1&&!F&&(Z||r.originalFullText.trim()!=="")&&rr(e,_,o)}})}),u.forEach(R=>{let _=Array.from(R.childNodes).filter(F=>I(F,"p"));if(_.length>1){let F=_[0],Z=_[_.length-1],G=be(F,S,"pPr"),Q=G?be(G,S,"sectPr"):null;if(Q){G.removeChild(Q);let ee=be(Z,S,"pPr");ee||(ee=C(e,"w:pPr"),Z.insertBefore(ee,Z.firstChild||null)),ee.appendChild(Q)}}});let L=new Set(l),z=new Map;l.forEach(R=>{let _=R.parentNode;if(!_||z.has(_))return;let F=R.nextSibling;for(;F&&L.has(F);)F=F.nextSibling;z.set(_,F)}),l.forEach(R=>{R.parentNode&&R.parentNode.removeChild(R)});let j=!1,O="";return u.forEach((R,_)=>{let F=m.get(_),Z=F||_;if(Z.nodeType===9){j=!0,R.childNodes.length===1?Z.appendChild(R.firstChild):O=Array.from(R.childNodes).map(Q=>n.serializeToString(Q)).join("");return}let G=F?null:z.get(_);G&&G.parentNode===Z?Z.insertBefore(R,G):Z.appendChild(R)}),{oxml:j&&O?O:n.serializeToString(e),hasChanges:!0}}function Fi(e,t,r,n,o,i,a,s,l,u,c,f,m,d,p=[],b=0,w=!0,g=new WeakSet,h=null,x=!1){let v=i,T=b,y=a,N=[];return t.split(/([\n\uFFFC]|[\uE000-\uF8FF])/).forEach(P=>{let $=l.get(v)||[],L=$.filter(O=>O.isCommentMarker&&!g.has(O.node)),z=x?new Set(L.filter(O=>I(O.node,"commentRangeEnd")).map(O=>O.node.getAttributeNS?.(S,"id")||O.node.getAttribute?.("w:id")||O.node.getAttribute?.("id"))):new Set;if(L.forEach(O=>{g.add(O.node);let H=O.node.getAttributeNS?.(S,"id")||O.node.getAttribute?.("w:id")||O.node.getAttribute?.("id");if(x&&z.has(H)&&(I(O.node,"commentRangeEnd")||I(O.node,"commentReference"))){N.push(O.node);return}if(I(O.node,"commentReference")){let R=C(e,"w:r");R.appendChild(O.node.cloneNode(!0)),y.appendChild(R)}else y.appendChild(O.node.cloneNode(!0))}),P===`
156
+ `){let O=f(v+1),H=m(O.pPr);w&&r==="insert"?gi(e,y,d):w&&r==="delete"&&rr(e,y,d);let R=s.get(O.container);R&&(R.appendChild(H),y=H),v++,r!=="delete"&&T++;return}if(P==="\uFFFC"){let O=$.find(H=>!H.isCommentMarker)||$[0];if(O){let H=O.node.cloneNode(!0);if(O.isTextBox&&O.originalContainer){let R=be(H,S,"txbxContent");if(R){for(;R.firstChild;)R.removeChild(R.firstChild);c.set(O.originalContainer,R)}}if(O.wrapInRun){let R=C(e,"w:r");O.rPr&&R.appendChild(O.rPr.cloneNode(!0)),R.appendChild(H),y.appendChild(R)}else y.appendChild(H)}v++,r!=="delete"&&T++;return}if(u.has(P)){if(r!=="delete"){let O=u.get(P);if(O){let H=O.cloneNode(!0),R=C(e,"w:r");n&&R.appendChild(n.cloneNode(!0)),R.appendChild(H),y.appendChild(R)}}v++,r!=="delete"&&T++;return}if(P.length===0)return;let j=y;if(o){let O=o.cloneNode(!1);j=O,y.appendChild(O)}if(r==="delete"){let O=C(e,"w:r");n&&O.appendChild(n.cloneNode(!0));let H=C(e,"w:delText");if(H.setAttribute("xml:space","preserve"),H.textContent=P,O.appendChild(H),w){let R=null;if(h){let F=h.usedDeletionId?ie(d,e,"del").id:h.deletionId;h.usedDeletionId=!0,R={id:F,author:h.author,date:h.date}}let _=ft(e,"del",O,d,R);j.appendChild(_)}}else{let O=Ve(p,T,T+P.length),H=Br(e,P,n,O,T,d,w);if(r==="insert"&&w){let R=null;if(h){let F=h.usedInsertionId?ie(d,e,"ins").id:h.insertionId;h.usedInsertionId=!0,R={id:F,author:h.author,date:h.date}}let _=ft(e,"ins",null,d,R);H.forEach(F=>_.appendChild(F)),j.appendChild(_)}else H.forEach(R=>j.appendChild(R))}r!=="delete"&&(T+=P.length),v+=P.length}),N.forEach(P=>{if(I(P,"commentReference")){let $=C(e,"w:r");$.appendChild(P.cloneNode(!0)),y.appendChild($)}else y.appendChild(P.cloneNode(!0))}),{currentParagraph:y}}function Dn(e,t,r,n,o,i,a=!0,s={},l={}){let u=Li(e,t);if(u===null)return de({oxml:n.serializeToString(e),hasChanges:!1,status:"error",error:{code:"PARTIAL_TARGET",message:"Original text did not identify a complete contiguous paragraph range for reconstruction."}});let c=_i(e,r,u);if(c.paragraphs.length===0)return de({oxml:n.serializeToString(e),hasChanges:!1});let f=Qt(c.originalFullText,c.processedModifiedText,s);return de($i(e,f,c,n,o,i,a,l))}function Xe(e,t){return de({oxml:e.serializeToString(t),hasChanges:!1})}function Xi(e,t,r,n,o,i=!0){let a=ve(e,S,"tbl"),s=$e(t),l=s.rows.length>0||s.headers.length>0;if(a.length===0||!l)return Xe(r,e);let u=a[0],c=vn(u),f=Qo(c,s);if(f.length===0)return Xe(r,e);let m={generateRedlines:i,author:o,revisionIdAllocator:st(e)},d=ei(c,f,m),p=`<root xmlns:w="${S}">${d}</root>`,b=W(p,"application/xml").doc;if(!b)return Xe(r,e);let w=ne(b);if(w)return te("[OxmlEngine] Failed to parse reconciled table OOXML:",w.textContent),Xe(r,e);let g=be(b,S,"tbl");if(!g)return te("[OxmlEngine] No table found in reconciled OOXML"),Xe(r,e);let h=e.importNode(g,!0);return u.parentNode.replaceChild(h,u),de({oxml:r.serializeToString(e),hasChanges:!0})}function Di(e,t,r,n,o,i){let a=st(e),s=$e(t);if(!s||s.rows.length===0&&s.headers.length===0)return k("[OxmlEngine] Failed to parse table data from Markdown"),Xe(r,e);let l=ut(s,{generateRedlines:i,author:o,revisionIdAllocator:a}),u=W(`<root xmlns:w="${S}">${l}</root>`,"application/xml").doc;if(!u)return Xe(r,e);let c=ne(u);if(c)return te("[OxmlEngine] Failed to parse generated table OOXML:",c.textContent),Xe(r,e);let f=re(u,S,"tbl");if(f||(f=re(u,S,"ins")),!f)return te("[OxmlEngine] No table element found in generated OOXML"),Xe(r,e);let m=e,d=se(m,S,"p");if(d.length===0)return k("[OxmlEngine] No paragraphs found to replace"),Xe(r,m);let p=d[0],b=p.parentNode;if(b&&b.nodeType===9){let g=W(`<w:document xmlns:w="${S}"><w:body/></w:document>`,"application/xml").doc;if(!g)return Xe(r,m);let h=re(g,S,"body");d.forEach(x=>h.appendChild(g.importNode(x,!0))),m=g,Sr(m,a),d=se(m,S,"p"),p=d[0],b=p.parentNode}let w=m.importNode(f,!0);return i?d.forEach(g=>{rr(m,g,o),se(g,S,"r").forEach(x=>{se(x,S,"t").forEach(N=>{let E=N.textContent||"";if(E.trim()){let P=C(m,"w:delText");P.textContent=E,N.parentNode.replaceChild(P,N)}});let T=C(m,"w:del"),y=ie(o,m,"del");T.setAttribute("w:id",String(y.id)),T.setAttribute("w:author",y.author),T.setAttribute("w:date",y.date),x.parentNode.insertBefore(T,x),T.appendChild(x)})}):d.slice(1).forEach(g=>g.parentNode.removeChild(g)),b.insertBefore(w,p),i||b.removeChild(p),k("[OxmlEngine] Text-to-table transformation complete"),de({oxml:r.serializeToString(m),hasChanges:!0})}function gt(e,t){if(!e||!e.attributes)return"";for(let r of Array.from(e.attributes))if((r.localName||"").toLowerCase()===t.toLowerCase())return String(r.value||"");return String(e.getAttribute?.(`w:${t}`)||e.getAttribute?.(t)||"")}function Ui(e){return typeof e=="string"?e.trim().toLowerCase():""}function Ll(e){return!!e&&e.nodeType===1}function je(e,t){return Ll(e)&&e.namespaceURI===S&&String(e.localName||"").toLowerCase()===t.toLowerCase()}function xe(e,t){return Array.from(e.getElementsByTagNameNS(S,t))}function zn(e={}){if(e?.allAuthors===!0)return{valid:!0,allAuthors:!0,normalizedAuthor:""};let t=Ui(e?.author);return t?{valid:!0,allAuthors:!1,normalizedAuthor:t}:{valid:!1,allAuthors:!1,normalizedAuthor:"",warning:"No author provided. Pass { author } or set { allAuthors: true }."}}function Pe(e,t){if(t.allAuthors)return!0;let r=Ui(gt(e,"author"));return!!r&&r===t.normalizedAuthor}function Wn(e,t){let r=typeof e=="string"?e.replace(/^\uFEFF/,"").trim():"",n=!1,o=W(r,"application/xml");if(o.error&&(o.error.message.includes("HierarchyRequestError")||o.error.message.includes("Only one element"))){let a=`<w:body xmlns:w="${S}">${r}</w:body>`,s=W(a,"application/xml");s.error||(o=s,n=!0)}let i=o.doc?ne(o.doc):null;if(o.error||i){let a=o.error?.message||i?.textContent||"parse error";return{xmlDoc:null,serializer:null,isFragmentWrapped:!1,warning:`${t}: ${a}`,warnings:o.warnings,error:{code:"PARSE_ERROR",message:a}}}return{xmlDoc:o.doc,serializer:fe(),isFragmentWrapped:n,warning:null,warnings:o.warnings,error:null}}function ue(e){return e?.parentNode?(e.parentNode.removeChild(e),!0):!1}function zr(e){let t=e?.parentNode;if(!t)return!1;for(;e.firstChild;)t.insertBefore(e.firstChild,e);return t.removeChild(e),!0}function Wr(e){let t=e?.parentNode;return je(t,"trPr")&&je(t?.parentNode,"tr")}function Un(e){let t=e?.parentNode,r=t?.parentNode,n=r?.parentNode;return je(t,"rPr")&&je(r,"pPr")&&je(n,"p")}function ji(e){return Un(e)?e.parentNode.parentNode.parentNode:null}function Bl(e){let t=e?.nextSibling||null;for(;t;){if(je(t,"p"))return t;t=t.nextSibling}return null}function Hi(e){if(!e?.parentNode)return!1;let t=Bl(e);if(!t)return je(e.parentNode,"tc")&&xe(e.parentNode,"p").length<=1?!1:ue(e);let r=Array.from(e.childNodes||[]).filter(o=>!je(o,"pPr")),n=t.firstChild||null;je(n,"pPr")&&(n=n.nextSibling||null);for(let o of r)t.insertBefore(o,n);return ue(e)}function jn(e,t={}){let r=[],n=zn(t);if(!n.valid)return{oxml:e,hasChanges:!1,acceptedCount:0,warnings:[n.warning]};let o=Wn(e,"Failed to parse OOXML");if(!o.xmlDoc)return{oxml:e,hasChanges:!1,acceptedCount:0,status:"error",error:o.error,warnings:[...o.warnings||[],o.warning]};let{xmlDoc:i,serializer:a}=o;r.push(...o.warnings||[]);let s=0;for(let c of xe(i,"ins"))if(!(!c.parentNode||!Pe(c,n))){if(Un(c)){ue(c)&&(s+=1);continue}if(Wr(c)){ue(c)&&(s+=1);continue}zr(c)&&(s+=1)}for(let c of xe(i,"del")){if(!c.parentNode||!Pe(c,n))continue;let f=ji(c);if(f){Hi(f)&&(s+=1);continue}if(Wr(c)){let m=c.parentNode?.parentNode;ue(m)&&(s+=1);continue}ue(c)&&(s+=1)}for(let c of xe(i,"moveFrom"))!c.parentNode||!Pe(c,n)||ue(c)&&(s+=1);for(let c of xe(i,"moveTo"))!c.parentNode||!Pe(c,n)||zr(c)&&(s+=1);s+=Vi(i,n);let l=["rPrChange","pPrChange","tblPrChange","trPrChange","tcPrChange"];for(let c of l)for(let f of xe(i,c))!f.parentNode||!Pe(f,n)||ue(f)&&(s+=1);return{oxml:o.isFragmentWrapped?Array.from(i.documentElement.childNodes).map(c=>a.serializeToString(c)).join(""):a.serializeToString(i),hasChanges:s>0,acceptedCount:s,warnings:r}}function zi(e,t){for(let r of Array.from(t.getElementsByTagNameNS(S,"delText"))){let n=C(e,"w:t"),o=r.getAttribute("xml:space");for(o&&n.setAttribute("xml:space",o);r.firstChild;)n.appendChild(r.firstChild);r.parentNode?.replaceChild(n,r)}}function Fl(e,t){let r=e?.parentNode;if(!r)return!1;let n=t.endsWith("Change")?t.slice(0,-6):"";if(!n||String(r.localName||"").toLowerCase()!==n.toLowerCase()||r.namespaceURI!==S)return ue(e);let o=Array.from(e.childNodes||[]).find(a=>a.nodeType===1&&a.namespaceURI===S&&String(a.localName||"").toLowerCase()===n.toLowerCase());if(!o)return ue(e);let i=Array.from(o.childNodes||[]);for(;r.firstChild;)r.removeChild(r.firstChild);for(let a of i){let s=$l(r.ownerDocument,a);r.appendChild(s)}return!0}function $l(e,t){return e&&typeof e.importNode=="function"?e.importNode(t,!0):t.cloneNode(!0)}function Wi(e,t,r){let n=new Set;for(let o of xe(e,t)){if(!Pe(o,r))continue;let i=gt(o,"id");i&&n.add(i)}return n}function Vi(e,t){let r=0,n=Wi(e,"moveFromRangeStart",t),o=Wi(e,"moveToRangeStart",t),i=[["moveFromRangeStart",n,!0],["moveFromRangeEnd",n,!1],["moveToRangeStart",o,!0],["moveToRangeEnd",o,!1]];for(let[a,s,l]of i)for(let u of xe(e,a)){if(!u.parentNode)continue;let c=gt(u,"id");c&&(t.allAuthors||s.has(c)||l&&Pe(u,t))&&ue(u)&&(r+=1)}return r}function Hn(e,t={}){let r=[],n=zn(t);if(!n.valid)return{oxml:e,hasChanges:!1,rejectedCount:0,warnings:[n.warning]};let o=Wn(e,"Failed to parse OOXML");if(!o.xmlDoc)return{oxml:e,hasChanges:!1,rejectedCount:0,status:"error",error:o.error,warnings:[...o.warnings||[],o.warning]};let{xmlDoc:i,serializer:a}=o;r.push(...o.warnings||[]);let s=0;for(let c of xe(i,"ins")){if(!c.parentNode||!Pe(c,n))continue;let f=ji(c);if(f){Hi(f)&&(s+=1);continue}if(Wr(c)){let m=c.parentNode?.parentNode;ue(m)&&(s+=1);continue}ue(c)&&(s+=1)}for(let c of xe(i,"del"))if(!(!c.parentNode||!Pe(c,n))){if(Un(c)){ue(c)&&(s+=1);continue}if(Wr(c)){ue(c)&&(s+=1);continue}zi(i,c),zr(c)&&(s+=1)}for(let c of xe(i,"moveFrom"))!c.parentNode||!Pe(c,n)||(zi(i,c),zr(c)&&(s+=1));for(let c of xe(i,"moveTo"))!c.parentNode||!Pe(c,n)||ue(c)&&(s+=1);s+=Vi(i,n);let l=["rPrChange","pPrChange","tblPrChange","trPrChange","tcPrChange"];for(let c of l)for(let f of xe(i,c))!f.parentNode||!Pe(f,n)||Fl(f,c)&&(s+=1);return{oxml:o.isFragmentWrapped?Array.from(i.documentElement.childNodes).map(c=>a.serializeToString(c)).join(""):a.serializeToString(i),hasChanges:s>0,rejectedCount:s,warnings:r}}function Xl(e,t){let r=new Set,n=xe(e,"comment");for(let o of n){if(!Pe(o,t))continue;let i=gt(o,"id");i&&r.add(i)}return{targetIds:r,commentNodes:n}}function Dl(e,t){let r=0;for(let n of e){let o=gt(n,"id");!o||!t.has(o)||ue(n)&&(r+=1)}return r}function zl(e){return je(e,"r")?Array.from(e.childNodes||[]).filter(r=>{if(r.nodeType===3)return String(r.nodeValue||"").trim().length>0;if(r.nodeType!==1)return!1;if(r.namespaceURI!==S)return!0;let n=String(r.localName||"").toLowerCase();return n!=="rpr"&&n!=="commentreference"}).length===0:!1}function Wl(e,t){let r=0,n=["commentRangeStart","commentRangeEnd","commentReference"];for(let o of n)for(let i of xe(e,o)){if(!i.parentNode)continue;let a=gt(i,"id");if(!(!a||!t.has(a))){if(o==="commentReference"&&zl(i.parentNode)){ue(i.parentNode)&&(r+=1);continue}ue(i)&&(r+=1)}}return r}function Ul(e,t={}){let r=[],n=zn(t);if(!n.valid)return{oxml:e,hasChanges:!1,commentsRemoved:0,referencesRemoved:0,warnings:[n.warning]};let o=Wn(e,"Failed to parse OOXML");if(!o.xmlDoc)return{oxml:e,hasChanges:!1,commentsRemoved:0,referencesRemoved:0,status:"error",error:o.error,warnings:[...o.warnings||[],o.warning]};let{xmlDoc:i,serializer:a}=o;r.push(...o.warnings||[]);let{targetIds:s,commentNodes:l}=Xl(i,n);if(n.allAuthors)for(let f of["commentRangeStart","commentRangeEnd","commentReference"])for(let m of xe(i,f)){let d=gt(m,"id");d&&s.add(d)}let u=Dl(l,s),c=Wl(i,s);return{oxml:a.serializeToString(i),hasChanges:u>0||c>0,commentsRemoved:u,referencesRemoved:c,warnings:r}}var jl=Object.freeze({formatOnly:Object.freeze({paragraphs:!0,formatting:!0,tables:"scoped",hyperlinks:"preserved",fields:"preserved",comments:"preserved"}),surgical:Object.freeze({paragraphs:!0,tables:"cell-scoped",hyperlinks:"preserved",fields:"preserved",comments:"preserved",notes:"preserved"}),reconstruction:Object.freeze({paragraphs:!0,hyperlinks:"sentinel-preserved",fields:"sentinel-preserved",comments:"marker-preserved",notes:"reference-preserved"}),table:Object.freeze({tables:!0,paragraphs:!0,formatting:"cell-dependent",numbering:!1}),listDirect:Object.freeze({lists:!0,numbering:!0,paragraphs:"single-source expansion",tables:"embedded-markdown blocks",formatting:"markdown hints"}),listCompatibilityPipeline:Object.freeze({lists:!0,numbering:!0,paragraphs:"multi-source patching",compatibility:!0})});function Ye(e,t,r={}){let n=e?._routeInstrumentation?.onRoute;typeof n=="function"&&n(Object.freeze({route:t,capabilities:jl[t]||null,...r}))}function Hl(e){let t=new Set;for(let r of["commentRangeStart","commentRangeEnd","commentReference"])for(let n of ve(e,S,r)){let o=n.getAttribute?.("w:id")||n.getAttribute?.("id");o!==""&&t.add(o)}return[...t].sort((r,n)=>Number(r)-Number(n)||r.localeCompare(n))}async function Vn(e,t,r,n={}){let o=e,i=e;t=typeof t=="string"?t:String(t??""),r=typeof r=="string"?r:String(r??"");let a=n.generateRedlines??!0,s=n.author||me(),l=fe(),u=[],c=[],f=!1,m=n.existingRevisions||"merge-same-author",d=m==="accept-all-first-keep-normalized",p=X=>{let M={...X};f&&M.hasChanges===!1&&M.status!=="error"&&(m==="merge-same-author"?(M.oxml=i,M.hasChanges=!0,M.warnings=[...Array.isArray(M.warnings)?M.warnings:[],"Previous revisions by the same author were reverted to baseline."]):d?(M.oxml=i,M.hasChanges=!0,M.warnings=[...Array.isArray(M.warnings)?M.warnings:[],"Existing revisions were accepted before redlining."]):M.oxml=o);let J=[...u,...c,...Array.isArray(M.warnings)?M.warnings:[]];return J.length>0&&(M.warnings=[...new Set(J)]),M.status||(M.status=M.hasChanges?"ok":"no-op"),de(M)},b=()=>p(f&&d?{oxml:i,hasChanges:!0,warnings:["Existing revisions were accepted before redlining."]}:{oxml:o,hasChanges:!1}),w=W(o,"text/xml");u=w.warnings;let g=w.doc,h=g?ne(g):null;if(w.error||h){let X=w.error?.message||h?.textContent||"Could not parse OOXML input.";return te("[OxmlEngine] XML parse error:",X),p({oxml:o,hasChanges:!1,status:"error",error:{code:"PARSE_ERROR",message:X}})}let x=n?._revisionIdAllocator instanceof Ne?n._revisionIdAllocator:new Ne;if(yt(g,x),Mr(g))if(m==="merge-same-author"){let X=In(g),M=String(s||"").trim().toLowerCase();if(X.length>0&&X.every(ce=>ce.trim().toLowerCase()===M)){let ce=Hl(g);if(ce.length>0)return p({oxml:o,hasChanges:!1,status:"error",error:{code:"COMMENTED_CONTENT_MERGE",message:"Refusing to merge existing revisions in commented content because reverting the prior revisions could remove or orphan comment anchors.",commentIds:ce}});k("[OxmlEngine] Existing revisions from same author detected; rejecting previous changes to merge against baseline");let Ae=Hn(o,{author:s});if(Ae.status==="error")return p(Ae);i=Ae.oxml,f=!0;let jt=W(i,"text/xml");u.push(...jt.warnings),g=jt.doc;let wo=g?ne(g):null;if(jt.error||wo){let vr=jt.error?.message||wo?.textContent||"Could not parse OOXML after rejecting same-author revisions.";return te("[OxmlEngine] XML parse error after rejecting same-author revisions:",vr),p({oxml:o,hasChanges:!1,status:"error",error:{code:"PARSE_ERROR",message:vr}})}if(Mr(g))return p({oxml:o,hasChanges:!1,status:"error",error:{code:"UNSAFE_REVISION_NESTING",message:"Existing same-author revisions could not be completely restored to baseline; refusing to layer new revisions over unsupported revision markup."}});yt(g,x);let bo=g.documentElement&&String(g.documentElement.localName||"").toLowerCase()==="p"?[g.documentElement]:ke(g);t=bo.length>0?bo.map(vr=>ye(vr)).join(`
157
+ `):""}else return k("[OxmlEngine] Existing revisions detected from another/unattributed author; refusing per merge-same-author policy"),p({oxml:o,hasChanges:!1,status:"error",error:{code:"EXISTING_REVISIONS",message:`Input OOXML contains tracked changes from another author (${X.length?X.join(", "):"unattributed"}). Pass existingRevisions: "accept-all-first" or resolve revisions first.`}})}else if(m==="accept-all-first"||m==="accept-all-first-keep-normalized"){k("[OxmlEngine] Existing revisions detected; accepting all input revisions before redlining");let X=jn(o,{allAuthors:!0});if(X.status==="error")return p(X);i=X.oxml,f=!0;let M=W(i,"text/xml");u.push(...M.warnings),g=M.doc;let J=g?ne(g):null;if(M.error||J){let ce=M.error?.message||J?.textContent||"Could not parse OOXML after accepting existing revisions.";return te("[OxmlEngine] XML parse error after accepting existing revisions:",ce),p({oxml:o,hasChanges:!1,status:"error",error:{code:"PARSE_ERROR",message:ce}})}yt(g,x)}else return k("[OxmlEngine] Existing revisions detected; rejecting input per existingRevisions policy"),p({oxml:o,hasChanges:!1,status:"error",error:{code:"EXISTING_REVISIONS",message:'Input OOXML contains existing tracked changes and existingRevisions is "reject-input".'}});let v=Ti(g,t,n);if(v.hasTableWrapper&&v.targetParagraph&&!n._isolatedTableCell){k("[OxmlEngine] Isolating table-cell paragraph before diff");let X=nr(g,v.targetParagraph,l),M=await Vn(X,t,r,{...n,_isolatedTableCell:!0});return!M.hasChanges&&M.status==="no-op"?b():M}let T=n.sanitizeInput===!0?Gn(r):r;T!==r&&c.push("Input was sanitized; pass sanitizeInput: false to disable.");let y=null;if(n.structuredContent!==!1)if(y=_r(T),y.valid)y.requiresStructuredContent&&(T=y.normalizedMarkdown);else{if(n.explicitStructuredContent===!0){let X=y.issues.map(M=>`${M.code}: ${M.message}`).join(" ");return p({oxml:o,hasChanges:!1,status:"error",error:{code:"STRUCTURED_CONTENT_INVALID",message:X},warnings:y.issues.map(M=>M.message)})}y=null}let{cleanText:N,formatHints:E}=Ee(T),P=N.trim()!==t.trim(),$=E.length>0,{existingFormatHints:L,textSpans:z,paragraphs:j}=mi(g),O=L.length>0,H=z.map(X=>Gi(X)).join(""),R=t.includes(`
158
+ `)||t.includes("\r")?t.split(/\r?\n/).map(Ur).filter(Boolean).every(X=>j.some(M=>{let J=z.filter(ce=>ce.paragraph===M).map(Gi).join("");return Ur(J).includes(X)})):H.includes(t.trim())||H.replace(/[\t\n\u2011]/g,"").includes(t.trim().replace(/[\t\n\u2011]/g,""))||Ur(H).includes(Ur(t));if(P&&typeof t=="string"&&t.trim()&&!R)return k("[OxmlEngine] Target text not found in OOXML"),p({oxml:o,hasChanges:!1,status:"error",error:{code:"TARGET_NOT_FOUND",message:"Original text was not found in the supplied OOXML."}});let _=null,F=()=>(_||(_=Fr(g,j,z)),_),Z=(X=null)=>{let M=yi(g,t,E,l,s,a,X);return M.useNativeApi?(k("[OxmlEngine] Format-only surgical fallback signal encountered; retrying with OOXML reconstruction fallback"),Dn(g,t,N,l,s,E,a)):M};k(`[OxmlEngine] Text changes: ${P}, New format hints: ${E.length}, Existing format hints: ${L.length}`);let G=n.removeFormatting===!0&&!P&&!$&&O;if(!P&&!$&&!O)return Ye(n,"noChange"),k("[OxmlEngine] No text changes, no format hints, and no existing formatting detected"),b();if(!P&&!$&&O&&!G)return k("[OxmlEngine] No text or explicit formatting changes; preserving existing formatting"),b();if(G){Ye(n,"formatOnly",{removeFormatting:!0}),k("[OxmlEngine] Format REMOVAL detected: applying surgical replacement in OOXML");let X=v,M=X.targetParagraph||null;if(!M){let Ae=wi(F(),t);Ae&&(M=Ae.paragraph)}let J=L;M&&(J=L.filter(Ae=>xi(Ae.run)===M));let ce=vi(g,z,J,l,s,a);return X.hasTableWrapper&&M?p({oxml:nr(g,M,l),hasChanges:ce.hasChanges}):p(ce)}if(!P&&$){Ye(n,"formatOnly",{removeFormatting:!1}),k(`[OxmlEngine] Format-only change detected: ${E.length} format hints`);let X=v,M={textSpans:z,paragraphs:j,paragraphInfos:F()};if(X.hasTableWrapper&&X.targetParagraph){k("[OxmlEngine] Table cell context: applying formatting to target paragraph only");let J=Z(M);return k("[OxmlEngine] Stripping table wrapper for table cell paragraph (format-only)"),p({oxml:nr(g,X.targetParagraph,l),hasChanges:J.hasChanges})}return p(Z(M))}let ee=ve(g,S,"tbl").length>0,ze=/^\|.+\|/.test(N.trim())&&N.includes(`
159
+ `),Nr=Gt(N),ho=n.structuredContent!==!1&&y?.requiresStructuredContent===!0,at=v;k(`[OxmlEngine] Mode: ${ee?"SURGICAL":"RECONSTRUCTION"}, formatHints: ${E.length}, isMarkdownTable: ${ze}, isTargetList: ${Nr}, isTableCellParagraph: ${at.isTableCellParagraph}`);try{if(ze&&!ee)return Ye(n,"table",{transformation:"text-to-table"}),k("[OxmlEngine] Text-to-table transformation: generating new table from Markdown"),p(Di(g,N,l,null,s,a));if(ee&&ze)return Ye(n,"table",{transformation:"table-reconciliation"}),p(Xi(g,N,l,null,s,a));if(ee){Ye(n,"surgical",{tableScoped:!0});let X=at.hasTableWrapper&&at.targetParagraph?at.targetParagraph:null;X&&k("[OxmlEngine] Table cell edit: scoping surgical mode to target paragraph");let M=Ri(g,t,N,l,s,E,a,X,{},n);return at.hasTableWrapper&&M.hasChanges&&at.targetParagraph?(k("[OxmlEngine] Stripping table wrapper for table cell paragraph (surgical mode)"),p({oxml:nr(g,at.targetParagraph,l),hasChanges:!0})):p(M)}if(Nr||ho){let X=ve(g,S,"p"),M=X.length===1;Ye(n,M?"listDirect":"listCompatibilityPipeline",{sourceParagraphCount:X.length}),k(`[OxmlEngine] \u{1F3AF} Using ${M?"direct list generation":"compatibility pipeline"} for list reconciliation`);let J;if(M){let ce=Et(i,{xmlDoc:g}),Ae=Zt(X[0]);J=await At({cleanText:N,numberingContext:Ae,originalRunModel:ce.runModel,originalText:ce.acceptedText,generateRedlines:a,author:s,font:n.font||null,revisionIdAllocator:x,numberingService:new Ge})}else J=await new er({author:s,generateRedlines:a,revisionIdAllocator:x}).execute(i,T,{xmlDoc:g});if(J.error?.code==="DIFF_TOKEN_LIMIT")return p({oxml:o,hasChanges:!1,status:"error",error:J.error});if(J.isValid&&J.ooxml&&J.ooxml!==i){let ce=J.includeNumbering===!0;k(`[OxmlEngine] Wrapping list OOXML with numbering definitions, includeNumbering=${ce}`);let Ae=et(J.ooxml,{includeNumbering:ce,numberingXml:J.numberingXml});return k(`[OxmlEngine] \u2705 Wrapped OOXML length: ${Ae.length}`),p({oxml:Ae,hasChanges:!0,...Array.isArray(J.warnings)?{warnings:J.warnings}:{}})}return b()}return Ye(n,"reconstruction"),p(Dn(g,t,N,l,s,E,a,{},n))}catch(X){if(zo(X))return p({oxml:o,hasChanges:!1,status:"error",error:{code:X.code,message:X.message}});throw X}}function Ur(e){return String(e||"").replace(/[\t\n\u2011]/g," ").replace(/\s+/g," ").trim()}function Gi(e){let t=e?.textElement,r=String(t?.localName||t?.nodeName||"").replace(/^.*:/,"");return r==="tab"?" ":r==="br"||r==="cr"?`
160
+ `:r==="noBreakHyphen"?"\u2011":t?.textContent||""}function Gn(e){return String(e??"").replace(/^(?:Here is the redline:|Here is the text:|Sure, I can help:|Here's the updated text:)[ \t]*\r?\n/i,"")}function Je(e){return W(e,"application/xml").doc}function ht(e){return oe(e)}function jr(e){return Array.from(e||[])}function ar(e){let t=new Error(e);return t.code="TARGET_NOT_FOUND",t}function Re(e,t,r=null){let n=new Error(t);return n.code=e,Array.isArray(r)&&(n.candidates=r),n}var Ce="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function Ki(e,t){if(!e)return[];if(typeof e.getElementsByTagNameNS=="function"){let n=jr(e.getElementsByTagNameNS("*",t));if(n.length>0)return n}if(typeof e.getElementsByTagName!="function")return[];let r=jr(e.getElementsByTagName(`w:${t}`));return r.length>0?r:jr(e.getElementsByTagName(t))}function le(e){return e?ye(e):""}function Te(e){if(!e)return[];let t=Ki(e,"body"),r=t.length>0?t[0]:e;return Ki(r,"p")}function wt(e){return e&&jr(e.attributes).find(r=>String(r?.localName||r?.name||"").replace(/^.*:/,"")==="paraId")?.value||null}function kt(e,t={}){if(!e)return null;let r=t.revisionView==="rejected"?"rejected":"accepted",n=typeof t.text=="string"?t.text:ye(e,{revisionView:r}),o=Number.isInteger(t.index)?t.index:Te(e.ownerDocument||e).indexOf(e)+1,i=t.paragraphId===void 0?wt(e):t.paragraphId,a=typeof t.inTable=="boolean"?t.inTable:sr(e),l=`${i||""}${o}${a?"table":"body"}${r==="rejected"?"rejected":""}${n}`,u=2166136261;for(let c=0;c<l.length;c++)u^=l.charCodeAt(c),u=Math.imul(u,16777619)>>>0;return`fnv1a32:${u.toString(16).padStart(8,"0")}`}function Yi(e,t={}){let r=t.revisionView==="rejected"?"rejected":"accepted",n=Te(e),o=[],i=new Map,a=new Map,s=new Map;for(let l=0;l<n.length;l++){let u=n[l],c=ye(u,{revisionView:r}),f=wt(u),m=sr(u),d=U(c),p=Object.freeze({paragraph:u,index:l+1,paragraphId:f,text:c,normalizedText:d,revisionView:r,fingerprint:kt(u,{text:c,index:l+1,paragraphId:f,inTable:m,revisionView:r}),inTable:m});o.push(p),i.set(u,p),f&&!a.has(f)&&a.set(f,p),d&&(s.has(d)||s.set(d,[]),s.get(d).push(p))}for(let[l,u]of s)s.set(l,Object.freeze(u));return Object.freeze({revisionView:r,entries:Object.freeze(o),byParagraph:i,byId:a,byNormalizedText:s})}function U(e){return String(e||"").replace(/\s+/g," ").trim()}function Jn(e){let t=String(e||"").trim();return/^\|.+\|/.test(t)&&t.includes(`
161
+ `)}function qn(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 Vl(e){return e==null?"":String(e).replace(/^\s*\[P\d+(?:\.\d+)?\]\s*/i,"").trim()}function Gl(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 Ji(e,t,r=null){return!Number.isInteger(t)||t<1?null:r?.entries?r.entries[t-1]?.paragraph||null:Te(e)[t-1]||null}function Mt(e,t,r=Ce){let n=e;for(;n;){if(n.nodeType===1&&n.namespaceURI===r&&n.localName===t)return n;n=n.parentNode}return null}function Hr(e,t,r={}){let n=r.paragraphMetadataIndex||null,o=n?.entries||null,i=o?null:Te(e),a=String(t||"").trim();if(!a)return null;let s=o?o.find(u=>u.text.trim()===a)?.paragraph:i.find(u=>le(u).trim()===a);if(s)return s;let l=U(a);return n?.byNormalizedText?n.byNormalizedText.get(l)?.[0]?.paragraph||null:i.find(u=>U(le(u))===l)||null}function Kn(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},o=r.paragraphMetadataIndex||null,i=o?.entries||null,a=i?null:Te(e),s=String(t||"").trim();if(!s)return null;let l=Hr(e,s,{paragraphMetadataIndex:o});if(l)return l;let u=U(s),c=i?i.find(w=>w.normalizedText.length>10&&u.startsWith(w.normalizedText))?.paragraph||null:a.find(w=>{let g=U(le(w));return g.length>10&&u.startsWith(g)});if(c)return n(`[Fuzzy] Prefix match (target starts with paragraph): "${le(c).trim().slice(0,60)}..."`),c;let f=i?i.find(w=>w.normalizedText.length>15&&u.includes(w.normalizedText))?.paragraph||null:a.find(w=>{let g=U(le(w));return g.length>15&&u.includes(g)});if(f)return n(`[Fuzzy] Contains match: "${le(f).trim().slice(0,60)}..."`),f;let m=0,d=null,p=new Set(u.toLowerCase().split(/\s+/).filter(w=>w.length>2)),b=i?.length??a.length;for(let w=0;w<b;w++){let g=i?.[w]?.paragraph??a[w],h=(i?.[w]?.text??le(g)).trim();if(!h)continue;let T=U(h).toLowerCase().split(/\s+/).filter(y=>y.length>2).filter(y=>p.has(y)).length/Math.max(p.size,1);T>m&&T>.5&&(m=T,d=g)}return d?(n(`[Fuzzy] Best word-overlap match (${(m*100).toFixed(0)}%): "${le(d).trim().slice(0,60)}..."`),d):null}function qi(e,t={}){let r=typeof t.onInfo=="function"?t.onInfo:()=>{},n=typeof t.onWarn=="function"?t.onWarn:()=>{},o=t.opType||"operation",i=t.targetDescriptor&&typeof t.targetDescriptor=="object"?t.targetDescriptor:null,a=i?.revisionView==="rejected"?"rejected":"accepted",s=String(i?.exactText??i?.text??t.targetText??"").trim(),l=qn(i?.index??i?.paragraphIndex??t.targetRef),u=t.strictAmbiguity===!0,c=t.paragraphMetadataIndex||null;if(c&&c.revisionView!==a?c=t.metadataIndices?.[a]||Yi(e,{revisionView:a}):c||(c=Yi(e,{revisionView:a})),i?.paragraphId){let m=Yl(e,i.paragraphId,c);if(!m)throw Re("TARGET_NOT_FOUND",`Target paragraphId not found: "${i.paragraphId}".`);let d=c?.byParagraph?.get(m)||null,p=d?.index??Te(e).indexOf(m)+1,b=d?.fingerprint||kt(m,{revisionView:a}),w=d?.inTable??sr(m),g=d?.normalizedText||U(ye(m,{revisionView:a}));if(l!=null&&l!==p)throw Re("TARGET_INDEX_MISMATCH",`Target paragraphId "${i.paragraphId}" (index ${p}) does not match requested index ${l}.`,d?[He(d)]:null);if(i.fingerprint&&i.fingerprint!==b)throw Re("TARGET_FINGERPRINT_MISMATCH",`Target paragraphId "${i.paragraphId}" no longer matches its source fingerprint.`,d?[He(d)]:null);if(typeof i.inTable=="boolean"&&i.inTable!==w)throw Re("TARGET_CONTEXT_MISMATCH",`Target paragraphId "${i.paragraphId}" does not match the requested table context.`,d?[He(d)]:null);if(s&&g!==U(s))throw Re("TARGET_TEXT_MISMATCH",`Target paragraphId "${i.paragraphId}" no longer matches the supplied text.`,d?[He(d)]:null);if(i.occurrence!=null){let x=Vr(e,s||g,c),v=x.findIndex(T=>T.paragraph===m)+1;if(v===0||v!==i.occurrence)throw Re("TARGET_OCCURRENCE_MISMATCH",`Target paragraphId "${i.paragraphId}" matches occurrence ${v}, not requested occurrence ${i.occurrence}.`,x.map(He))}return{paragraph:m,resolvedBy:"paragraph_id"}}let f=[];if(s){let m=Vr(e,s,c);if(f=Kl(m,i),i?.fingerprint&&m.length>0&&f.length===0)throw Re("TARGET_FINGERPRINT_MISMATCH","Target text matched, but no paragraph matched the supplied source fingerprint.",m.map(He));if(typeof i?.inTable=="boolean"&&m.length>0&&f.length===0)throw Re("TARGET_CONTEXT_MISMATCH","Target text matched, but no paragraph matched the requested table context.",m.map(He));if(i?.occurrence){let d=f[i.occurrence-1]||null;if(!d)throw Re("TARGET_NOT_FOUND",`Target occurrence ${i.occurrence} was not found.`,f.map(He));return{paragraph:d.paragraph,resolvedBy:"occurrence"}}if(u){if(l){let d=f.find(p=>p.index===l)||null;if(d)return{paragraph:d.paragraph,resolvedBy:"ref"};if(i?.fingerprint&&f.length>0)throw Re("TARGET_FINGERPRINT_MISMATCH",`Target fingerprint does not match paragraph reference [P${l}].`,f.map(He));if(f.length===1)return{paragraph:f[0].paragraph,resolvedBy:"strict_text_after_ref_drift"}}if(f.length>1)throw Re("AMBIGUOUS_TARGET",`Target text matched ${f.length} paragraphs; provide paragraphId, index, occurrence, or fingerprint.`,f.map(He));if(f.length===0)throw ar(`Target paragraph not found: "${s}"`)}if(!l&&f.length===1)return{paragraph:f[0].paragraph,resolvedBy:i?.fingerprint?"fingerprint":"strict_text"}}if(l){let m=Ji(e,l,c);if(m){let d=c?.byParagraph?.get(m)||null;if(i?.fingerprint&&i.fingerprint!==d?.fingerprint)throw Re("TARGET_FINGERPRINT_MISMATCH",`Target fingerprint does not match paragraph reference [P${l}].`);if(typeof i?.inTable=="boolean"&&i.inTable!==d?.inTable)throw Re("TARGET_CONTEXT_MISMATCH",`Target paragraph reference [P${l}] does not match requested table context.`);if(s){let p=Hr(e,s,{paragraphMetadataIndex:c}),b=(d?.text||ye(m,{revisionView:a})).trim(),w=U(b),g=U(s),h=w!==g;if(h&&p&&p!==m)return r(`[Target] [P${l}] drifted for ${o}; using strict text rematch.`),{paragraph:p,resolvedBy:"strict_text_after_ref_drift"};if(h){let x=Kn(e,s,{onInfo:r,paragraphMetadataIndex:c});if(x&&x!==m)return r(`[Target] [P${l}] drifted for ${o}; using fuzzy text rematch.`),{paragraph:x,resolvedBy:"fuzzy_text_after_ref_drift"};r(`[Target] Using [P${l}] fallback for ${o}; target text drifted.`)}else p&&p!==m&&r(`[Target] [P${l}] disambiguated duplicate target text for ${o}.`)}else r(`[Target] Using [P${l}] fallback for ${o}.`);return{paragraph:m,resolvedBy:"ref"}}n(`[WARN] Target reference [P${l}] not found; falling back to text matching for ${o}.`)}if(s&&!u){let m=Hr(e,s,{paragraphMetadataIndex:c});if(m){let p=f.length;if(p>1){let b=`AMBIGUOUS_TARGET_HEURISTIC_USED: Target text matched ${p} paragraphs; permissive resolution chose candidate 1. Migrate to strict targeting (e.g. strictTargets: true with paragraphId, index, occurrence, or fingerprint) before v1.0.0.`;return n(b),{paragraph:m,resolvedBy:"strict_text",warnings:[b]}}return{paragraph:m,resolvedBy:"strict_text"}}let d=Kn(e,s,{onInfo:r,paragraphMetadataIndex:c});if(d)return{paragraph:d,resolvedBy:"fuzzy_text"}}throw ar(s?`Target paragraph not found: "${s}"`:l?`Target paragraph reference not found: [P${l}]`:'Operation target missing: provide "target" text or "targetRef" ([P#]).')}function sr(e){return!!Mt(e,"tbl")}function Vr(e,t,r=null){let n=U(t);if(!n)return[];let o=r?.byNormalizedText?r:r?.paragraphMetadataIndex||null,i=r?.revisionView||o?.revisionView||"accepted";if(o?.byNormalizedText&&o.revisionView===i)return Array.from(o.byNormalizedText.get(n)||[]);let a=Te(e),s=[];for(let l=0;l<a.length;l++){let u=a[l],c=ye(u,{revisionView:i}).trim();c&&U(c)===n&&s.push({paragraph:u,index:l+1,inTable:sr(u),paragraphId:wt(u),fingerprint:kt(u,{text:c,index:l+1,revisionView:i}),text:c,revisionView:i})}return s}function He(e){return{index:e.index,paragraphId:e.paragraphId||null,text:e.text,inTable:e.inTable,fingerprint:e.fingerprint,revisionView:e.revisionView||"accepted"}}function Kl(e,t){let r=e.slice();return t?.paragraphId&&(r=r.filter(n=>n.paragraphId===t.paragraphId)),typeof t?.inTable=="boolean"&&(r=r.filter(n=>n.inTable===t.inTable)),t?.fingerprint&&(r=r.filter(n=>n.fingerprint===t.fingerprint)),r}function Yl(e,t,r=null){return t?r?.byId?r.byId.get(t)?.paragraph||null:Te(e).find(n=>wt(n)===t)||null:null}function Jl(e,t,r=null){if(!Array.isArray(e)||e.length===0)return null;let n=e.slice();if(typeof r=="boolean"){let o=n.filter(i=>i.inTable===r);o.length>0&&(n=o)}return Number.isInteger(t)&&t>0&&n.sort((o,i)=>Math.abs(o.index-t)-Math.abs(i.index-t)),n[0]||null}function ql(e,t=null){let r=t?.entries||null,n=r?null:Te(e),o=new Map,i=r?.length??n.length;for(let a=0;a<i;a++){let s=r?.[a]?.paragraph??n[a],l=(r?.[a]?.text??le(s)).trim();o.set(a+1,{text:l,normalizedText:r?.[a]?.normalizedText??U(l),inTable:r?.[a]?.inTable??sr(s)})}return o}function Yn(e,t={}){let r=typeof t.onInfo=="function"?t.onInfo:()=>{},n=qi(e,t),o=qn(t.targetRef);if(!o||n?.resolvedBy!=="ref")return n;let i=t.targetRefSnapshot instanceof Map&&t.targetRefSnapshot.get(o)||null;if(!i)return n;let a=String(t.targetText||"").trim(),s=a||i.text||"",l=U(s);if(!l||(t.paragraphMetadataIndex?.byParagraph?.get(n.paragraph)?.normalizedText||U(le(n.paragraph)))===l)return n;let c=[];if(a&&c.push(a),i.text){let m=U(i.text);m&&!c.some(d=>U(d)===m)&&c.push(i.text)}let f=null;for(let m of c){let d=Vr(e,m,t.paragraphMetadataIndex||null),p=Jl(d,o,i.inTable);if(p&&(f||(f=p),p.paragraph!==n.paragraph)){f=p;break}}if(f&&f.paragraph!==n.paragraph){let m=t.opType||"operation";return r(`[Target] [P${o}] appears stale after prior edits; using strict text rematch for ${m}.`),{paragraph:f.paragraph,resolvedBy:"strict_text_after_ref_drift"}}throw ar(`Target paragraph [P${o}] no longer matches its batch-start anchor.`)}function Zl(e,t,r,n={}){if(!e||!t||!r)return null;let o=n?.opType||"redline",i=n?.targetRefSnapshot||null,a=typeof n?.onInfo=="function"?n.onInfo:()=>{},s=typeof n?.onWarn=="function"?n.onWarn:()=>{},l=Yn(e,{targetRef:t,opType:o,targetRefSnapshot:i,onInfo:a,onWarn:s})?.paragraph;if(!l)return null;let u=Yn(e,{targetRef:r,opType:o,targetRefSnapshot:i,onInfo:a,onWarn:s})?.paragraph;if(!u)return null;let c=Array.from(e.getElementsByTagNameNS("*","p")),f=c.indexOf(l),m=c.indexOf(u);if(f<0||m<f)return null;let d=c.slice(f,m+1);if(d.length===0)return null;let p=d[0]?.parentNode||null;return!p||!d.every(b=>b&&b.parentNode===p)?null:d}function Gr(e,t){if(!e||typeof e.getElementsByTagNameNS!="function")return null;let r=e.getElementsByTagNameNS(Ce,t);if(r.length>0)return r[0];let n=e.getElementsByTagNameNS("*",t);return n.length>0?n[0]:null}function Zi(e){if(!e)return null;if(typeof e.getAttributeNS=="function"){let t=e.getAttributeNS(Ce,"val");if(t)return t}return e.getAttribute("w:val")||e.getAttribute("val")||null}function ea(e){let t=String(e||"").trim(),r=0;for(;r<4;){let n=We(t);if(n===t)break;t=n.trimStart(),r++}return t.trim()}function ta(e){let t=String(e||"").split(/\r?\n/g),r=[],n=!1;for(let o of t){let i=o.trimEnd();if(!i.trim())continue;let a=Yt(i,{indentSpaces:2});if(a){n=!0,r.push({kind:"list",markerType:a.markerType,level:a.level,marker:a.marker,outlineLevel:a.outlineLevel,text:ea(a.text)});continue}r.push({kind:"text",text:i.trim()})}return{items:r,hasListMarkers:n}}function Qi(e,t,r){return`${" ".repeat(Math.max(0,e))}${t==="numbered"?"1.":"-"} ${String(r||"").trim()}`.trimEnd()}function lr(e,t){return U(e)===U(t)}function Kr(e,t,r){return Number.isInteger(e?.outlineLevel)?Math.max(0,e.outlineLevel):Math.max(0,t+((e?.level||0)-r))}function Ql(e,t,r){if(!Array.isArray(e)||e.length<2||!Number.isInteger(r)||r<0)return!1;let n=e[0],o=e.slice(1).filter(i=>i.kind==="list");if(o.length===0||o.some(i=>i.markerType!=="bullet")||o.some(i=>Number.isInteger(i.outlineLevel)))return!1;if(n?.kind==="text")return lr(n.text,t);if(n?.kind==="list"&&n.markerType==="numbered"){let i=n.level||0;return o.some(s=>(s.level||0)>i)?!1:lr(n.text,t)}return!1}function ec(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 tc(e,t,r,n){let o=e[0],i=e.slice(1).filter(a=>a.kind==="list");if(o?.kind==="text"&&lr(o.text,t)&&i.length>0){let a=i[0].level;return i.map(s=>({ilvl:Kr(s,r,a),markerType:s.markerType||n,text:s.text}))}if(e.every(a=>a.kind==="list")){let a=e[0];if(!a||!lr(a.text,t))return null;let s=a.level;return e.slice(1).map(l=>({ilvl:Kr(l,r,s),markerType:l.markerType||n,text:l.text})).filter(l=>l.text)}return null}function qe(e){if(!e)return null;let t=Gr(e,"pPr");if(!t)return null;let r=Gr(t,"numPr");if(!r)return null;let n=Gr(r,"numId");if(!n)return null;let o=Zi(n);if(!o||o==="0")return null;let i=Gr(r,"ilvl"),a=Zi(i),s=Number.parseInt(a||"0",10);return{numId:String(o),ilvl:Number.isFinite(s)?s:0}}function ra(e){let t=qe(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===Ce&&s.localName==="p"),o=n.indexOf(e);if(o<0)return null;let i=o;for(;i>0;){let s=qe(n[i-1]);if(!s||s.numId!==t.numId)break;i--}let a=o;for(;a<n.length-1;){let s=qe(n[a+1]);if(!s||s.numId!==t.numId)break;a++}return n.slice(i,a+1)}function rc(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},o=typeof r.onWarn=="function"?r.onWarn:()=>{},i=String(t||"");if(!i.includes(`
162
+ `)||!qe(e))return null;let s=ra(e);if(!s||s.length===0)return null;let l=ta(i);if(!l.hasListMarkers||l.items.length<2)return null;let u=U(r.currentParagraphText||le(e)),f=l.items.filter(N=>N.kind==="list")[0]?.markerType||"bullet",m=s.map(N=>({paragraph:N,list:qe(N),text:String(le(N)||"").trim()})),d=s.indexOf(e);if(d<0)return null;let p=Math.min(...m.map(N=>N.list?.ilvl??0)),b=m.map(N=>Qi((N.list?.ilvl??0)-p,f,N.text)),w=null,g=l.items[0],h=l.items.slice(1).filter(N=>N.kind==="list");if(g?.kind==="text"&&lr(g.text,u)&&h.length>0){let N=Math.max(0,(m[d].list?.ilvl??0)-p),E=h[0].level;w=[{level:N,markerType:f,text:m[d].text},...h.map(P=>({level:Kr(P,N,E),markerType:P.markerType||f,text:P.text}))]}else if(l.items.every(N=>N.kind==="list")){let N=Math.max(0,(m[d].list?.ilvl??0)-p),E=l.items[0].level;w=l.items.map(P=>({level:Kr(P,N,E),markerType:P.markerType||f,text:P.text}))}else return o("[List] Multiline list edit did not match supported insertion/replace patterns; skipping list-block synthesis."),null;let x=w.map(N=>Qi(N.level,N.markerType,N.text)),v=b.slice(0,d).concat(x).concat(b.slice(d+1)),T=b.join(`
163
+ `),y=v.join(`
164
+ `);return y===T?null:(n("[List] Expanded single-item list edit to contiguous list block for stable middle insertion."),{paragraphs:s,originalText:T,modifiedText:y})}function nc(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},o=typeof r.onWarn=="function"?r.onWarn:()=>{},i=String(t||"");if(!i.includes(`
165
+ `))return null;let a=qe(e);if(!a)return null;let s=ta(i);if(!s.hasListMarkers||s.items.length<2)return null;let l=U(r.currentParagraphText||le(e)),c=s.items.filter(d=>d.kind==="list")[0]?.markerType||"bullet",f=Math.max(0,a.ilvl),m=tc(s.items,l,f,c);return!m||m.length===0?(o("[List] Could not derive insertion-only entries from multiline list edit."),null):(Ql(s.items,l,f)&&(m=ec(m,f),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:a.numId,entries:m})}function cr(e){if(!e)return null;let t=String(e).trim();if(!t)return null;let r=t.split(`
166
+ `),n=[];for(let a of r){if(!a.trim())continue;let s=Yt(a,{allowZeroSpaceAfterMarker:!1,indentSpaces:2});if(s){n.push({type:s.markerType,level:s.level,text:s.text.trim(),marker:s.marker});continue}n.push({type:"text",level:0,text:a.trim()})}if(n.length===0)return null;let o=n.some(a=>a.type==="numbered"),i=n.some(a=>a.type==="bullet");return{type:o?"numbered":i?"bullet":"text",items:n}}function Zn(e){return!e||!Array.isArray(e.items)?!1:e.items.some(t=>t?.type==="numbered"||t?.type==="bullet")}function oc(e,t,r){let n=new Map,o=[];for(let i of e){let a=Math.max(0,Number(i?.level)||0);for(let c of Array.from(n.keys()))c>a&&n.delete(c);let s=(n.get(a)||0)+1;n.set(a,s);let l=ac(s,t,r),u=" ".repeat(a*4);o.push(`${u}${l} ${i.text||""}`.trimEnd())}return o.join(`
167
+ `)}function ic(e,t={}){let r=Math.max(1,Number(t.indentSpaces)||4);return(e||[]).map(n=>{let o=String(n??""),i=o.match(/^(\s*)/),a=i?i[1].length:0,s=Math.floor(a/r),l=o.trim(),u=null,c=Be(l,{allowZeroSpaceAfterMarker:!0});return c&&(u=c[2].trim()||null,l=We(l,{allowZeroSpaceAfterMarker:!0})),{text:l.trim(),level:s,removedMarker:u}})}function ac(e,t,r){if(t==="bullet")return"-";switch(r){case"lowerAlpha":return`${na(e,!1)}.`;case"upperAlpha":return`${na(e,!0)}.`;case"lowerRoman":return`${oa(e,!1)}.`;case"upperRoman":return`${oa(e,!0)}.`;default:return`${e}.`}}function na(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 oa(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"]],o="";for(let[i,a]of n)for(;r>=i;)o+=a,r-=i;return t?o:o.toLowerCase()}function Yr(e){let t=String(e||"");if(!t.trim()||t.includes(`
168
+ `))return null;let r=cr(t);if(!r||!Zn(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 o=String(n.marker||"").trim(),i=n.type==="numbered"?Kt(o||"1."):"bullet";return{type:n.type,marker:o,numberingStyle:i,startAt:lc(o,i),contentText:String(n.text||"").trim(),normalizedContent:U(String(n.text||""))}}function sc(e){let t=Yr(e);return t?String(t.contentText||"").trim():String(e||"").trim()}function lc(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 cc(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 o=t?.explicitByNumberingKey;if(!(o instanceof Map))return{type:"explicitIsolated",numberingKey:r,startAt:n,numId:null};let i=o.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 uc(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 fc(e,t){!e||!(e.explicitByNumberingKey instanceof Map)||t&&e.explicitByNumberingKey.delete(String(t))}function _t(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 mc(e,t={}){let r=t?.numId;if(r==null)return 0;let n=Number.isInteger(t?.ilvl)?Math.max(0,t.ilvl):0,o=t?.clearParagraphPropertyChanges!==!1,i=t?.removeListPropertyNode!==!1,a=(Array.isArray(e)?e:[]).filter(l=>l&&l.nodeType===1&&l.localName==="p"),s=0;for(let l of a){let u=l.ownerDocument;if(!u)continue;let c=_t(l,"pPr");if(c||(c=C(u,"w:pPr"),l.insertBefore(c,l.firstChild)),o){let p=_t(c,"pPrChange");p&&c.removeChild(p)}if(i){let p=_t(c,"listPr");p&&c.removeChild(p)}let f=_t(c,"numPr");f||(f=C(u,"w:numPr"),c.appendChild(f));let m=_t(f,"ilvl");m||(m=C(u,"w:ilvl"),f.appendChild(m)),m.setAttribute("w:val",String(n));let d=_t(f,"numId");d||(d=C(u,"w:numId"),f.appendChild(d)),d.setAttribute("w:val",String(r)),s++}return s}function dc(e){let t=W(e,"application/xml").doc;return!t||ne(t)?null:Te(t)[0]||null}function pc(e){return e?String(e).replace(/<w:p>\s*<w:pPr>\s*<\/w:pPr>\s*<\/w:p>\s*$/i,""):""}function gc(e,t){for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return null}function Lt(e,t){let r=gc(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function ia(e,t){e.setAttribute("w:val",String(t))}function hc(e){let t=W(e,"application/xml").doc;if(!t||ne(t))return null;let o=Te(t)[0]||null;if(!o)return null;let i=Array.from(o.getElementsByTagNameNS("*","numId"));for(let a of i){let s=Lt(a,["w:val","val"]);if(s!=null)return String(s)}return null}function wc(e,t,r,n={}){if(!e||!t||!Number.isInteger(r)||r<1)return e;let o=n.setAbstractStartOverride!==!1,i=fe(),a=W(e,"application/xml").doc;if(!a||ne(a))return e;let u=Array.from(a.getElementsByTagNameNS("*","num")).find(p=>{let b=Lt(p,["w:numId","numId"]);return b!=null&&String(b)===String(t)});if(!u)return e;let c=Array.from(u.getElementsByTagNameNS("*","abstractNumId"))[0]||null,f=Lt(c,["w:val","val"]),m=Array.from(u.getElementsByTagNameNS("*","lvlOverride")).find(p=>Lt(p,["w:ilvl","ilvl"])===0)||null;m||(m=C(a,"w:lvlOverride"),m.setAttribute("w:ilvl","0"),u.appendChild(m));let d=Array.from(m.getElementsByTagNameNS("*","startOverride"))[0]||null;if(d||(d=C(a,"w:startOverride"),m.appendChild(d)),ia(d,r),o&&f!=null){let b=Array.from(a.getElementsByTagNameNS("*","abstractNum")).find(w=>{let g=Lt(w,["w:abstractNumId","abstractNumId"]);return g!=null&&g===f})||null;if(b){let w=Array.from(b.getElementsByTagNameNS("*","lvl")).find(h=>Lt(h,["w:ilvl","ilvl"])===0)||null;w||(w=C(a,"w:lvl"),w.setAttribute("w:ilvl","0"),b.appendChild(w));let g=Array.from(w.getElementsByTagNameNS("*","start"))[0]||null;g||(g=C(a,"w:start"),w.insertBefore(g,w.firstChild)),ia(g,r)}}return i.serializeToString(a)}function Qn(e={}){let t=String(e.oxml||""),r=String(e.originalText||""),n=String(e.modifiedText||""),o=e.allowExistingList===!0;if(!t.trim()||!n.trim())return null;let i=dc(t);if(!i)return null;let a=qe(i);if(a&&!o)return null;let s=Ee(n).cleanText||n,l=Yr(n)||Yr(s);if(!l)return null;let u=Yr(r),c=U(r)===U(s),f=!!u&&u.type===l.type&&u.normalizedContent===l.normalizedContent;return!c&&!f?null:{listInput:`${l.marker} ${l.contentText}`.trim(),numberingKey:`${l.type}:${l.numberingStyle}:single`,originalText:r,wasListParagraph:!!a,startAt:l.startAt}}async function Jr(e,t={}){if(!e||!e.listInput)return{hasChanges:!1,oxml:"",numberingXml:null,includeNumbering:!1,listStructuralFallbackApplied:!1,listStructuralFallbackKey:null,warnings:["Single-line list fallback plan missing"]};let r=t.author||"AI",n=t.generateRedlines??!0,o=t.pipeline?await t.pipeline.executeListGeneration(e.listInput,null,null,String(e.originalText||"")):await At({cleanText:e.listInput,numberingContext:null,originalRunModel:[],originalText:String(e.originalText||""),generateRedlines:n,author:r,revisionIdAllocator:t.revisionIdAllocator||null,numberingService:new Ge}),i=o?.oxml||o?.ooxml||"",a=pc(i),s=hc(a),l=wc(o?.numberingXml||null,s,Number.isInteger(e?.startAt)?e.startAt:null,{setAbstractStartOverride:t.setAbstractStartOverride}),u=o?.isValid!==!1;return!a||!u?{hasChanges:!1,oxml:"",numberingXml:null,includeNumbering:!1,listStructuralFallbackApplied:!1,listStructuralFallbackKey:e.numberingKey||null,warnings:["Single-line list fallback produced no valid OOXML"]}:{hasChanges:!0,oxml:a,numberingXml:l,includeNumbering:!0,listStructuralFallbackApplied:!0,listStructuralFallbackKey:e.numberingKey||null,listStructuralFallbackStartAt:Number.isInteger(e?.startAt)?e.startAt:null,warnings:["Single-line list structural fallback applied"]}}var bc=new Set(["ins","del","rPrChange","pPrChange"]),xc=/^\d{4}-\d{2}-\d{2}T/;function Bt(e){return String(e?.localName||e?.nodeName||"").replace(/^.*:/,"")}function bt(e,t){return Array.from(e.getElementsByTagName("*")).filter(r=>Bt(r)===t)}function xt(e,t){return e.getAttribute(`w:${t}`)||e.getAttribute(t)||""}function Nc(e){return e.getAttribute("xml:space")||e.getAttribute("space")||e.getAttributeNS?.("http://www.w3.org/XML/1998/namespace","space")||""}function vc(e){return Bt(e.parentNode)==="rPr"}function yc(e){let t=r=>{let n=vo(r),o=n.getElementsByTagName("parsererror")[0];if(o)throw new Error(o.textContent||"XML parse error");return n};try{return{doc:t(e)}}catch{try{return{doc:t(`<w:root xmlns:w="${S}">${e}</w:root>`)}}catch(r){return{error:r?.message||"XML parse error"}}}}function Tc(e){let t=[],r=(c,f,m)=>t.push({code:c,severity:f,message:m});if(typeof e!="string"||e.trim()==="")return r("PARSE_ERROR","error","Input is not a non-empty OOXML string."),{valid:!1,issues:t};let{doc:n,error:o}=yc(e);if(!n)return r("PARSE_ERROR","error",`OOXML does not parse as XML: ${o}`),{valid:!1,issues:t};let i=bt(n,"ins"),a=bt(n,"del"),s=i.concat(a);for(let c of bt(n,"p")){let f=Array.from(c.getElementsByTagName("*")).find(m=>m!==c&&Bt(m)==="p");f&&r("NESTED_PARAGRAPH","error",`<${c.nodeName}> contains nested <${f.nodeName}>.`)}for(let c of bt(n,"body")){let f=Array.from(c.childNodes||[]).filter(d=>d.nodeType===1),m=f.map((d,p)=>Bt(d)==="sectPr"?p:-1).filter(d=>d>=0);m.length>1?r("MULTIPLE_BODY_SECTPR","error","<w:body> contains multiple direct <w:sectPr> elements."):m.length===1&&m[0]!==f.length-1&&r("SECTPR_NOT_LAST","error","<w:sectPr> is not the last element child of <w:body>.")}for(let c of s){let f=Array.from(c.getElementsByTagName("*")).filter(m=>m!==c&&["ins","del"].includes(Bt(m)));f.length>0&&r("NESTED_REVISION","error",`<${c.nodeName}> (w:id="${xt(c,"id")}") contains nested <${f[0].nodeName}>.`)}for(let c of a)bt(c,"t").length>0&&r("DEL_CONTAINS_T","error",`<w:del> (w:id="${xt(c,"id")}") contains <w:t>; deleted text must use <w:delText>.`);for(let c of s){let f=[];xt(c,"id")||f.push("w:id"),xt(c,"author")||f.push("w:author"),xc.test(xt(c,"date"))||f.push("w:date"),f.length>0&&r("MISSING_REVISION_METADATA","error",`<${c.nodeName}> is missing or has malformed ${f.join(", ")}.`)}let l=new Set;for(let c of Array.from(n.getElementsByTagName("*"))){if(!bc.has(Bt(c)))continue;let f=xt(c,"id");f&&(l.has(f)&&r("DUPLICATE_REVISION_ID","error",`Revision id ${f} appears more than once.`),l.add(f))}let u=bt(n,"t").concat(bt(n,"delText"));for(let c of u){let f=c.textContent||"";/^\s|\s$/.test(f)&&Nc(c)!=="preserve"&&r("MISSING_SPACE_PRESERVE","error",`<${c.nodeName}> has boundary whitespace without xml:space="preserve".`),f===""&&r("EMPTY_TEXT_ELEMENT","warning",`<${c.nodeName}> is empty.`)}for(let c of s){if(vc(c))continue;Array.from(c.childNodes||[]).some(m=>m.nodeType===1)||r("EMPTY_REVISION_WRAPPER","warning",`<${c.nodeName}> (w:id="${xt(c,"id")}") wraps no content.`)}return{valid:!t.some(c=>c.severity==="error"),issues:t}}function qr(e,t){return e?Array.from(e.childNodes||[]).filter(r=>r&&r.nodeType===1&&r.namespaceURI===Ce&&r.localName===t):[]}function Sc(e){return String(e||"").replace(/\|/g,"\\|").replace(/\r?\n/g,"<br>")}function Ec(e){let t=qr(e,"tr"),r=t.map(o=>qr(o,"tc").map(a=>{let s=qr(a,"p");return s.length===0?U(le(a)):s.map(u=>U(le(u))).filter(Boolean).join(`
169
+ `)})),n=r.reduce((o,i)=>Math.max(o,i.length),0);return r.forEach(o=>{for(;o.length<n;)o.push("")}),{matrix:r,rowElements:t,columnCount:n}}function Ic(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],o=new Array(t).fill("---"),i=r.slice(1),a=s=>`| ${s.map(l=>Sc(l)).join(" | ")} |`;return[a(n),a(o),...i.map(a)].join(`
170
+ `)}function Ac(e){if(!Array.isArray(e)||e.length<2)return!1;let t=e.map(r=>U(r)).filter(Boolean);return t.length<2?!1:t.every(r=>r===t[0])}function aa(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 Pc(e,t={}){let r=Number.isInteger(t?.maxScan)&&t.maxScan>0?t.maxScan:10,n=typeof t?.getParagraphText=="function"?t.getParagraphText:le;if(!e||!e.parentNode)return null;let o=[e],i=e.nextSibling,a=0;for(;i&&a<r;){a+=1;let s=i.nextSibling;if(i.nodeType!==1||i.namespaceURI!==Ce||i.localName!=="p"){i=s;continue}let l=String(n(i)||"").trim();if(!l){if(o.length>1)break;i=s;continue}if(!aa(l))break;o.push(i),i=s}return o.length>1?o:null}function Rc(e,t,r={}){let n=typeof r.onInfo=="function"?r.onInfo:()=>{},o=typeof r.onWarn=="function"?r.onWarn:()=>{},i=String(t||"");if(!i.includes(`
171
+ `)||Jn(i))return null;let a=i.split(/\r?\n/g).map(v=>v.trim()).filter(Boolean);if(a.length<2)return null;let s=r.tableElement||Mt(e,"tbl"),l=Mt(e,"tr"),u=Mt(e,"tc");if(!s||!l||!u)return null;let c=U(r.currentParagraphText||le(e)),f=U(a[0]);if(c&&f&&f!==c)return o("[Table] Multiline cell text did not anchor to original cell text; skipping table-row synthesis heuristic."),null;let{matrix:m,rowElements:d,columnCount:p}=Ec(s);if(m.length===0||p===0)return null;let b=d.indexOf(l),g=qr(l,"tc").indexOf(u);if(b<0||g<0||g>=p)return null;m[b][g]=a[0];let h=Ac(m[b]);h&&n("[Table] Symmetric row detected; mirroring inserted row values across columns.");for(let v=1;v<a.length;v++){let T=b+v,y=a[v];if(T<m.length&&!U(m[T][g]))if(h)for(let N=0;N<p;N++)U(m[T][N])||(m[T][N]=y);else m[T][g]=y;else{let N=new Array(p).fill("");if(h)for(let E=0;E<p;E++)N[E]=y;else N[g]=y;m.splice(Math.min(T,m.length),0,N)}}let x=Ic(m,p);return x?(n("[Table] Synthesized full markdown table from multiline cell edit for table-scope reconciliation."),x):null}function Ft(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 o=Number.parseInt(String(n),10);if(Number.isFinite(o))return o}return null}function $t(e,t,r=null){let n=Number.isInteger(e)&&e>0?e:1,o=t instanceof Set?t:new Set;for(;o.has(n);)n+=1;if(Number.isInteger(r)&&r>0&&n>r){for(let i=1;i<=r;i+=1)if(!o.has(i))return i}return n}function Cc(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,o=new Set,i=new Set;if(String(e||"").trim())try{let c=Je(e),f=Array.from(c.getElementsByTagNameNS("*","abstractNum")),m=Array.from(c.getElementsByTagNameNS("*","num"));for(let d of f){let p=Ft(d,["w:abstractNumId","abstractNumId"]);p!=null&&i.add(p)}for(let d of m){let p=Ft(d,["w:numId","numId"]);p!=null&&o.add(p)}}catch{}let a=o.size>0?Math.max(...o):0,s=i.size>0?Math.max(...i):0,l=Math.max(r,a+1),u=Math.max(r,s+1);return{nextNumId:$t(l,o,n),nextAbstractNumId:$t(u,i,n),usedNumIds:o,usedAbstractNumIds:i,minId:r,maxPreferred:n}}function Oc(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=$t(e.nextNumId,e.usedNumIds,e.maxPreferred),e.nextAbstractNumId=$t(e.nextAbstractNumId,e.usedAbstractNumIds,e.maxPreferred),e)}function fr(e,t="num"){let r=Oc(e);if(!r)return null;let n=t==="abstract",o=n?r.nextAbstractNumId:r.nextNumId;return!Number.isInteger(o)||o<1?null:(n?(r.usedAbstractNumIds.add(o),r.nextAbstractNumId=$t(o+1,r.usedAbstractNumIds,r.maxPreferred)):(r.usedNumIds.add(o),r.nextNumId=$t(o+1,r.usedNumIds,r.maxPreferred)),o)}function kc(e){let t=fr(e,"num"),r=fr(e,"abstract");return t==null||r==null?null:{numId:t,abstractNumId:r}}function eo(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:e.getElementsByTagName("parsererror").length>0}function Zr(e,t){return!!(e&&e.nodeType===1&&e.namespaceURI===Ce&&e.localName===t)}function sa(e,t,r){if(!e||!t)return;let n=Array.from(e.childNodes||[]).filter(i=>i&&i.nodeType===1&&i.namespaceURI===Ce),o=null;r==="abstract"?o=n.find(i=>i.localName==="num"||i.localName==="numIdMacAtCleanup")||null:o=n.find(i=>i.localName==="numIdMacAtCleanup")||null,o?e.insertBefore(t,o):e.appendChild(t)}function Mc(e,t){for(let r of t||[]){let n=e?.getAttribute?.(r);if(n!=null&&n!=="")return n}return null}function ur(e,t){let r=Mc(e,t),n=Number.parseInt(String(r||""),10);return Number.isFinite(n)?n:null}function la(e,t,r){e?.setAttribute?.(t,String(r))}function to(e,t){e?.setAttribute?.("w:val",String(t))}function _c(e,t){if(!(!Array.isArray(e)||t==null))for(let r of e){let n=Array.from(r?.getElementsByTagNameNS?.("*","numId")||[]);for(let o of n)to(o,t)}}function Lc(e){for(let t of e||[]){let r=Array.from(t?.getElementsByTagNameNS?.("*","numId")||[]);for(let n of r){let o=ur(n,["w:val","val"]);if(o!=null)return String(o)}}return null}function Bc(e,t,r){let n=String(e),o=String(t),i=Number.isInteger(r)&&r>0?r:1,a=Array.from({length:9},(s,l)=>{let u=Array.from({length:l+1},(f,m)=>`%${m+1}`).join(".")+".",c=720*(l+1);return`
163
172
  <w:lvl w:ilvl="${l}">
164
173
  <w:start w:val="1"/>
165
174
  <w:numFmt w:val="decimal"/>
166
- <w:lvlText w:val="${c}"/>
175
+ <w:lvlText w:val="${u}"/>
167
176
  <w:lvlJc w:val="left"/>
168
- <w:pPr><w:ind w:left="${u}" w:hanging="360"/></w:pPr>
177
+ <w:pPr><w:ind w:left="${c}" w:hanging="360"/></w:pPr>
169
178
  </w:lvl>`}).join("");return`
170
- <w:numbering xmlns:w="${ge}">
179
+ <w:numbering xmlns:w="${Ce}">
171
180
  <w:abstractNum w:abstractNumId="${o}">
172
181
  <w:multiLevelType w:val="multilevel"/>
173
- ${i}
182
+ ${a}
174
183
  </w:abstractNum>
175
184
  <w:num w:numId="${n}">
176
185
  <w:abstractNumId w:val="${o}"/>
177
186
  <w:lvlOverride w:ilvl="0">
178
- <w:startOverride w:val="${a}"/>
187
+ <w:startOverride w:val="${i}"/>
179
188
  </w:lvlOverride>
180
189
  </w:num>
181
- </w:numbering>`.trim()}function xl(e,t,r){let n=Ce(e);if(cn(n))return{numberingXml:String(e||""),replacementNodes:Array.isArray(t)?t.map(c=>c?.cloneNode?c.cloneNode(!0):c):[]};let o=new Map,a=new Map,i=Array.from(n.getElementsByTagNameNS("*","abstractNum"));for(let c of i){let u=Ct(c,["w:abstractNumId","abstractNumId"]);if(u==null)continue;let f=Ot(r,"abstract");f!=null&&(o.set(u,f),ia(c,"w:abstractNumId",f))}let s=Array.from(n.getElementsByTagNameNS("*","num"));for(let c of s){let u=Ct(c,["w:numId","numId"]);if(u==null)continue;let f=Ot(r,"num");if(f==null)continue;a.set(u,f),ia(c,"w:numId",f);let m=Array.from(c.getElementsByTagNameNS("*","abstractNumId"))[0]||null;if(m){let p=Ct(m,["w:val","val"]);p!=null&&o.has(p)&&un(m,o.get(p))}}let l=Array.isArray(t)?t.map(c=>c?.cloneNode?c.cloneNode(!0):c):[];for(let c of l){let u=Array.from(c?.getElementsByTagNameNS?.("*","numId")||[]);for(let f of u){let m=Ct(f,["w:val","val"]);m!=null&&a.has(m)&&un(f,a.get(m))}}return{numberingXml:Ze(n),replacementNodes:l}}function Nl(e,t){let r=String(e||""),n=String(t||"");if(!n.trim())return r;if(!r.trim())return n;try{let o=Ce(r),a=Ce(n);if(cn(o)||cn(a))return r;let i=o.documentElement,s=a.documentElement;if(!i||!s)return r;let l=new Set(Array.from(i.childNodes||[]).filter(u=>dr(u,"abstractNum")).map(u=>pt(u,["w:abstractNumId","abstractNumId"])).filter(u=>u!=null)),c=new Set(Array.from(i.childNodes||[]).filter(u=>dr(u,"num")).map(u=>pt(u,["w:numId","numId"])).filter(u=>u!=null));for(let u of Array.from(s.childNodes||[])){if(!dr(u,"abstractNum"))continue;let f=pt(u,["w:abstractNumId","abstractNumId"]);f==null||l.has(f)||(aa(i,o.importNode(u,!0),"abstract"),l.add(f))}for(let u of Array.from(s.childNodes||[])){if(!dr(u,"num"))continue;let f=pt(u,["w:numId","numId"]);f==null||c.has(f)||(aa(i,o.importNode(u,!0),"num"),c.add(f))}return Ze(o)}catch{return r}}function vl(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:!!K(e)}function la(e){let t=D(e,"application/xml");return t.error||vl(t.doc)?{...t,doc:null}:t}function ca(e){if(!e)return[];let t=Array.from(e.getElementsByTagNameNS(y,"p"));return t.length>0?t:Array.from(e.getElementsByTagNameNS("*","p")).filter(r=>r?.localName==="p")}function fn(e,t){let r=Array.from(e?.childNodes||[]);for(let n of r)if(n?.nodeType===1&&n.namespaceURI===y&&n.localName===t)return n;return null}function Xe(e,t){return Array.from(e?.getElementsByTagNameNS?.(y,t)||[])}function kt(e,t){if(!e)return"";for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return""}function sa(e,t,r){let n=e?.parentNode||null;for(;n&&n!==r;){if(n.nodeType===1&&n.namespaceURI===y&&n.localName===t)return!0;n=n.parentNode}return!1}function Tl(e){let t="";for(let r of Array.from(e?.childNodes||[]))!r||r.nodeType!==1||r.namespaceURI!==y||(r.localName==="t"?t+=r.textContent||"":r.localName==="tab"?t+=" ":r.localName==="br"||r.localName==="cr"?t+=`
182
- `:r.localName==="noBreakHyphen"&&(t+="\u2011"));return t}function El(e){let t=fn(e,"rPr");if(!t)return{bold:!1,italic:!1};let r=Xe(t,"rStyle")[0]||null,n=kt(r,["w:val","val"]).toLowerCase(),o=n.includes("strong")||n.includes("bold"),a=n.includes("italic")||n.includes("emphasis");return{bold:Xe(t,"b").length>0||o,italic:Xe(t,"i").length>0||a}}function ua(e){let t=[],r=Array.from(e?.getElementsByTagNameNS?.(y,"r")||[]);for(let n of r){if(sa(n,"del",e)||sa(n,"moveFrom",e))continue;let o=Tl(n);o&&t.push({text:o,...El(n)})}return t}function mn(e){return String(e||"").replace(/\r/g,"").split(`
190
+ </w:numbering>`.trim()}function Fc(e,t,r){let n=Je(e);if(eo(n))return{numberingXml:String(e||""),replacementNodes:Array.isArray(t)?t.map(u=>u?.cloneNode?u.cloneNode(!0):u):[]};let o=new Map,i=new Map,a=Array.from(n.getElementsByTagNameNS("*","abstractNum"));for(let u of a){let c=ur(u,["w:abstractNumId","abstractNumId"]);if(c==null)continue;let f=fr(r,"abstract");f!=null&&(o.set(c,f),la(u,"w:abstractNumId",f))}let s=Array.from(n.getElementsByTagNameNS("*","num"));for(let u of s){let c=ur(u,["w:numId","numId"]);if(c==null)continue;let f=fr(r,"num");if(f==null)continue;i.set(c,f),la(u,"w:numId",f);let m=Array.from(u.getElementsByTagNameNS("*","abstractNumId"))[0]||null;if(m){let d=ur(m,["w:val","val"]);d!=null&&o.has(d)&&to(m,o.get(d))}}let l=Array.isArray(t)?t.map(u=>u?.cloneNode?u.cloneNode(!0):u):[];for(let u of l){let c=Array.from(u?.getElementsByTagNameNS?.("*","numId")||[]);for(let f of c){let m=ur(f,["w:val","val"]);m!=null&&i.has(m)&&to(f,i.get(m))}}return{numberingXml:ht(n),replacementNodes:l}}function $c(e,t){let r=String(e||""),n=String(t||"");if(!n.trim())return r;if(!r.trim())return n;try{let o=Je(r),i=Je(n);if(eo(o)||eo(i))return r;let a=o.documentElement,s=i.documentElement;if(!a||!s)return r;let l=new Set(Array.from(a.childNodes||[]).filter(c=>Zr(c,"abstractNum")).map(c=>Ft(c,["w:abstractNumId","abstractNumId"])).filter(c=>c!=null)),u=new Set(Array.from(a.childNodes||[]).filter(c=>Zr(c,"num")).map(c=>Ft(c,["w:numId","numId"])).filter(c=>c!=null));for(let c of Array.from(s.childNodes||[])){if(!Zr(c,"abstractNum"))continue;let f=Ft(c,["w:abstractNumId","abstractNumId"]);f==null||l.has(f)||(sa(a,o.importNode(c,!0),"abstract"),l.add(f))}for(let c of Array.from(s.childNodes||[])){if(!Zr(c,"num"))continue;let f=Ft(c,["w:numId","numId"]);f==null||u.has(f)||(sa(a,o.importNode(c,!0),"num"),u.add(f))}return ht(o)}catch{return r}}function Xc(e){return!e||!e.documentElement||e.documentElement.localName==="parsererror"?!0:!!ne(e)}function ca(e){let t=W(e,"application/xml");return t.error||Xc(t.doc)?{...t,doc:null}:t}function ua(e){if(!e)return[];let t=Array.from(e.getElementsByTagNameNS(S,"p"));return t.length>0?t:Array.from(e.getElementsByTagNameNS("*","p")).filter(r=>r?.localName==="p")}function ro(e,t){let r=Array.from(e?.childNodes||[]);for(let n of r)if(n?.nodeType===1&&n.namespaceURI===S&&n.localName===t)return n;return null}function it(e,t){return Array.from(e?.getElementsByTagNameNS?.(S,t)||[])}function mr(e,t){if(!e)return"";for(let r of t){let n=e.getAttribute(r);if(n!=null&&n!=="")return n}return""}function Dc(e){let t=ro(e,"rPr");if(!t)return{bold:!1,italic:!1};let r=it(t,"rStyle")[0]||null,n=mr(r,["w:val","val"]).toLowerCase(),o=n.includes("strong")||n.includes("bold"),i=n.includes("italic")||n.includes("emphasis");return{bold:it(t,"b").length>0||o,italic:it(t,"i").length>0||i}}function fa(e){let t=[],r=Array.from(e?.getElementsByTagNameNS?.(S,"r")||[]);for(let n of r){if(!mt(n,e,"accepted"))continue;let o=dt(n,{boundary:e,revisionView:"accepted"});o&&t.push({text:o,...Dc(n)})}return t}function no(e){return String(e||"").replace(/\r/g,"").split(`
183
191
  `).map(r=>r.replace(/[ \t]+/g," ").trim()).join(`
184
- `).trim()}function yl(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 o=n[1]||"",a=n[2]||"",i=n[3]||"";if(!a.trim())return r;let s=a;return t.bold&&t.italic?s=`***${a}***`:t.bold?s=`**${a}**`:t.italic&&(s=`*${a}*`),`${o}${s}${i}`}function Pl(e){let t=fn(e,"pPr");if(!t)return null;let r=Xe(t,"pStyle")[0]||null,n=kt(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 o=Xe(t,"outlineLvl")[0]||null,a=kt(o,["w:val","val"]),i=Number.parseInt(a,10);return Number.isInteger(i)&&i>=0?Math.min(i+1,6):null}function Sl(e){let t=fn(e,"pPr");if(!t)return null;let r=Xe(t,"numPr")[0]||null;if(!r)return null;let n=Xe(r,"ilvl")[0]||null,o=Xe(r,"numId")[0]||null,a=Number.parseInt(kt(n,["w:val","val"]),10),i=kt(o,["w:val","val"]);return{level:Number.isInteger(a)&&a>=0?a:0,marker:i==="1"?"-":"1."}}function Il(e){let t=ua(e).map(r=>r.text).join("");return mn(t)}function Al(e){let r=ua(e).map(i=>yl(i.text,i)).join(""),n=mn(r);if(!n)return"";let o=Pl(e);if(o!=null)return`${"#".repeat(o)} ${n}`;let a=Sl(e);return a?`${" ".repeat(a.level)}${a.marker} ${n}`:n}function Rl(e){return fa(e).text}function fa(e){let t=la(e);if(!t.doc)return{text:"",status:"error",error:t.error,warnings:t.warnings};let r=t.doc,n=ca(r);return n.length===0?{text:mn(r.documentElement?.textContent||""),status:"ok",warnings:t.warnings}:{text:n.map(Il).join(`
192
+ `).trim()}function zc(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 o=n[1]||"",i=n[2]||"",a=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}*`),`${o}${s}${a}`}function Wc(e){let t=ro(e,"pPr");if(!t)return null;let r=it(t,"pStyle")[0]||null,n=mr(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 o=it(t,"outlineLvl")[0]||null,i=mr(o,["w:val","val"]),a=Number.parseInt(i,10);return Number.isInteger(a)&&a>=0?Math.min(a+1,6):null}function Uc(e){let t=ro(e,"pPr");if(!t)return null;let r=it(t,"numPr")[0]||null;if(!r)return null;let n=it(r,"ilvl")[0]||null,o=it(r,"numId")[0]||null,i=Number.parseInt(mr(n,["w:val","val"]),10),a=mr(o,["w:val","val"]);return{level:Number.isInteger(i)&&i>=0?i:0,marker:a==="1"?"-":"1."}}function jc(e){let t=fa(e).map(r=>r.text).join("");return no(t)}function Hc(e){let r=fa(e).map(a=>zc(a.text,a)).join(""),n=no(r);if(!n)return"";let o=Wc(e);if(o!=null)return`${"#".repeat(o)} ${n}`;let i=Uc(e);return i?`${" ".repeat(i.level)}${i.marker} ${n}`:n}function Vc(e){return ma(e).text}function ma(e){let t=ca(e);if(!t.doc)return{text:"",status:"error",error:t.error,warnings:t.warnings};let r=t.doc,n=ua(r);return n.length===0?{text:no(r.documentElement?.textContent||""),status:"ok",warnings:t.warnings}:{text:n.map(jc).join(`
185
193
 
186
- `).trim(),status:"ok",warnings:t.warnings}}function Cl(e){return ma(e).text}function ma(e){let t=la(e);if(!t.doc)return{text:"",status:"error",error:t.error,warnings:t.warnings};let r=t.doc,n=ca(r);return n.length===0?{text:"",status:"ok",warnings:t.warnings}:{text:n.map(Al).join(`
194
+ `).trim(),status:"ok",warnings:t.warnings}}function Gc(e){return da(e).text}function da(e){let t=ca(e);if(!t.doc)return{text:"",status:"error",error:t.error,warnings:t.warnings};let r=t.doc,n=ua(r);return n.length===0?{text:"",status:"ok",warnings:t.warnings}:{text:n.map(Hc).join(`
187
195
 
188
- `).trim(),status:"ok",warnings:t.warnings}}function pn(e,t,r,n){let o=t.split(" ").map(s=>s[0]).join("").toUpperCase()||"AI",a=pe(r),i=pe(t);return`<w:comment w:id="${e}" w:author="${i}" w:date="${n}" w:initials="${o}">
189
- <w:p>
196
+ `).trim(),status:"ok",warnings:t.warnings}}var Xt=new TextEncoder;function pa(e){if(typeof e!="string")throw new TypeError(`Entry name must be a string, got ${typeof e}`);let t=e.replace(/\\/g,"/");for(t=t.replace(/^\/+/,"");t.startsWith("./");)t=t.slice(2);if(t=t.replace(/\/+/g,"/"),!t)throw new Error(`Invalid empty entry name: "${e}"`);return t}function oo({scope:e,entries:t=[]}){if(typeof e!="string"||!e)throw new TypeError("Revision token scope must be a non-empty string.");let r=Xt.encode("docx-redline-revision-token\0"),n=1,o=Xt.encode(e),i=[],a=new Set,s=Array.isArray(t)?t:t instanceof Map?Array.from(t.entries()):Object.entries(t||{});for(let m of s){if(!m)continue;let d=Array.isArray(m)?m[0]:m.name,p=Array.isArray(m)?m[1]:m.payload??m.bytes;if(d==null)continue;let b=pa(String(d));if(a.has(b))throw new Error(`Duplicate normalized entry path detected: "${b}"`);a.add(b);let w;typeof p=="string"?w=Xt.encode(p):p instanceof Uint8Array?w=p:p&&typeof p.length=="number"?w=new Uint8Array(p):w=new Uint8Array(0),i.push({name:b,nameBytes:Xt.encode(b),payloadBytes:w})}i.sort((m,d)=>m.name<d.name?-1:m.name>d.name?1:0);let l=r.length+4+4+o.length+4;for(let m of i)l+=4+m.nameBytes.length+4+m.payloadBytes.length;let u=new Uint8Array(l),c=new DataView(u.buffer,u.byteOffset,u.byteLength),f=0;u.set(r,f),f+=r.length,c.setUint32(f,n,!1),f+=4,c.setUint32(f,o.length,!1),f+=4,u.set(o,f),f+=o.length,c.setUint32(f,i.length,!1),f+=4;for(let m of i)c.setUint32(f,m.nameBytes.length,!1),f+=4,u.set(m.nameBytes,f),f+=m.nameBytes.length,c.setUint32(f,m.payloadBytes.length,!1),f+=4,u.set(m.payloadBytes,f),f+=m.payloadBytes.length;return{framing:u,scope:e,version:n,coveredParts:i.map(m=>m.name)}}async function ga({scope:e,entries:t=[],digestFn:r=null}){let{framing:n,coveredParts:o,version:i}=oo({scope:e,entries:t}),a="";if(typeof r=="function")a=await r(n);else if(typeof globalThis.crypto?.subtle?.digest=="function"){let s=await globalThis.crypto.subtle.digest("SHA-256",n),l=new Uint8Array(s);a=Array.from(l).map(u=>u.toString(16).padStart(2,"0")).join("")}else throw new Error("No crypto provider available for SHA-256 revision token computation.");return{algorithm:"sha256",version:i,scope:e,value:a,coveredParts:o}}function io({scope:e,entries:t=[],digestFn:r}){if(typeof r!="function")throw new TypeError("computeRevisionTokenSync requires a synchronous digestFn.");let{framing:n,coveredParts:o,version:i}=oo({scope:e,entries:t}),a=r(n);return{algorithm:"sha256",version:i,scope:e,value:a,coveredParts:o}}function Qr(e){let t=[];if(e?.documentXml&&t.push({name:"word/document.xml",payload:e.documentXml}),e?.commentsXml&&t.push({name:"word/comments.xml",payload:e.commentsXml}),e?.commentsExtendedXml&&t.push({name:"word/commentsExtended.xml",payload:e.commentsExtendedXml}),e?.numberingXml&&t.push({name:"word/numbering.xml",payload:e.numberingXml}),e?.stylesXml&&t.push({name:"word/styles.xml",payload:e.stylesXml}),e?.parts instanceof Map)for(let[r,n]of e.parts.entries())t.push({name:r,payload:n});else if(e?.additionalParts&&typeof e.additionalParts=="object")for(let[r,n]of Object.entries(e.additionalParts))t.push({name:r,payload:n});return t}async function Kc(e,t={}){let r=Qr(e);return ga({scope:"document-parts",entries:r,digestFn:t.digestFn})}function Yc(e){return!e||typeof e!="object"?{valid:!1,error:{code:"INVALID_REVISION_TOKEN",message:"Revision token must be an object."}}:e.algorithm!=="sha256"?{valid:!1,error:{code:"INVALID_REVISION_TOKEN",message:`Unsupported revision token algorithm: "${e.algorithm}". Expected "sha256".`}}:e.version!==1?{valid:!1,error:{code:"INVALID_REVISION_TOKEN",message:`Unsupported revision token version: "${e.version}". Expected 1.`}}:e.scope!=="document-parts"&&e.scope!=="package"?{valid:!1,error:{code:"INVALID_REVISION_TOKEN",message:`Unsupported revision token scope: "${e.scope}". Expected "document-parts" or "package".`}}:typeof e.value!="string"||!/^[0-9a-f]{64}$/i.test(e.value.trim())?{valid:!1,error:{code:"INVALID_REVISION_TOKEN",message:"Revision token value must be a 64-character hex string."}}:{valid:!0}}function Jc(e,t){if(typeof e!="string"||typeof t!="string")return!1;let r=e.trim().toLowerCase(),n=t.trim().toLowerCase();if(r.length!==n.length)return!1;let o=Xt.encode(r),i=Xt.encode(n),a=0;for(let s=0;s<o.length;s++)a|=o[s]^i[s];return a===0}var Y=(e,t)=>e?.getAttribute?.(`w:${t}`)||e?.getAttribute?.(t)||"",De=(e,t)=>Array.from(e?.getElementsByTagNameNS?.(S,t)||[]),pe=(e,t)=>De(e,t)[0]||null;function qc(e,t){let r=e?.parentNode;for(;r;){if(r.localName===t&&(!r.namespaceURI||r.namespaceURI===S))return!0;r=r.parentNode}return!1}function en(e,t,r=!1){if(!e)return r?{error:{code:"MISSING_PART",message:`Missing ${t}.`}}:{doc:null};let n=W(e,"application/xml");return!n.doc||n.error?{error:{code:"PARSE_ERROR",message:`Could not parse ${t}: ${n.error?.message||"invalid XML"}`}}:{doc:n.doc,warnings:n.warnings||[]}}function Zc(e){let t=pe(pe(e,"pPr"),"numPr");if(!t)return null;let r=Y(pe(t,"numId"),"val");return!r||r==="0"?null:{numId:r,level:Number.parseInt(Y(pe(t,"ilvl"),"val")||"0",10)||0}}function Qc(e){let t=new Map;for(let n of De(e,"abstractNum")){let o=new Map;for(let i of De(n,"lvl")){let a=Number.parseInt(Y(i,"ilvl")||"0",10)||0;o.set(a,{start:Number.parseInt(Y(pe(i,"start"),"val")||"1",10)||1,format:Y(pe(i,"numFmt"),"val")||"decimal",text:Y(pe(i,"lvlText"),"val")||`%${a+1}.`})}t.set(Y(n,"abstractNumId"),o)}let r=new Map;for(let n of De(e,"num")){let o=Y(pe(n,"abstractNumId"),"val"),i=new Map(t.get(o)||[]);for(let a of De(n,"lvlOverride")){let s=Number.parseInt(Y(a,"ilvl")||"0",10)||0,l=pe(a,"lvl"),u={...i.get(s)||{start:1,format:"decimal",text:`%${s+1}.`}};l&&(u.start=Number.parseInt(Y(pe(l,"start"),"val")||String(u.start),10)||u.start,u.format=Y(pe(l,"numFmt"),"val")||u.format,u.text=Y(pe(l,"lvlText"),"val")||u.text);let c=pe(a,"startOverride");c&&(u.start=Number.parseInt(Y(c,"val")||String(u.start),10)||u.start),i.set(s,u)}r.set(Y(n,"numId"),i)}return r}function ha(e,t){let r=Math.max(1,e),n="";for(;r>0;)r-=1,n=String.fromCharCode(97+r%26)+n,r=Math.floor(r/26);return t?n.toUpperCase():n}function wa(e){let t=[[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"]],r=e,n="";for(let[o,i]of t)for(;r>=o;)n+=i,r-=o;return n}function eu(e,t){return t==="lowerLetter"?ha(e,!1):t==="upperLetter"?ha(e,!0):t==="lowerRoman"?wa(e).toLowerCase():t==="upperRoman"?wa(e):String(e)}function tu(e){let t=e?Qc(e):new Map,r=new Map;return n=>{if(!n?.numId)return null;let o=t.get(String(n.numId));if(!o)return{...n,label:null,format:null};let i=r.get(n.numId)||[],a=o.get(n.level)||{start:1,format:"decimal",text:`%${n.level+1}.`};i[n.level]=i[n.level]==null?a.start:i[n.level]+1,i.length=n.level+1,r.set(n.numId,i);let s=a.text.replace(/%([1-9])/g,(l,u)=>{let c=Number(u)-1,f=o.get(c)||a;return eu(i[c]??f.start,f.format)});return{...n,label:s,format:a.format}}}function ru(e){let t=pe(e,"pPr"),n=Y(pe(t,"pStyle"),"val").match(/^heading\s*([1-9])$/i);if(n)return Math.min(Number(n[1]),6);let o=Number.parseInt(Y(pe(t,"outlineLvl"),"val"),10);return Number.isInteger(o)?Math.min(o+1,6):null}function nu(e,t){let r=[];for(let[s,l]of[["footnoteReference","footnote"],["endnoteReference","endnote"],["commentReference","comment"]])for(let u of De(e,s))r.push({type:l,id:Y(u,"id")||null});let n=e.parentNode;for(;n&&n.localName!=="tc";)n=n.parentNode;let o=n?.parentNode;for(;o&&o.localName!=="tr";)o=o.parentNode;let i=o?.parentNode;for(;i&&i.localName!=="tbl";)i=i.parentNode;let a=e.ownerDocument;return{references:r,table:i?{tableIndex:Array.from(a.getElementsByTagNameNS(S,"tbl")).indexOf(i)+1,rowIndex:Array.from(i.getElementsByTagNameNS(S,"tr")).indexOf(o)+1,cellIndex:Array.from(o.getElementsByTagNameNS(S,"tc")).indexOf(n)+1}:null,empty:t.length===0}}function ou(e){let t=new Set;for(let r of["ins","del","moveFrom","moveTo","rPrChange","pPrChange"])for(let n of De(e,r))Y(n,"author")&&t.add(Y(n,"author"));return[...t].sort()}function iu(e){let t=new Map;for(let r of De(e,"comment")){let n=De(r,"p");t.set(Y(r,"id"),{id:Y(r,"id"),author:Y(r,"author")||null,date:Y(r,"date")||null,text:n.map(o=>ye(o)).join(`
197
+ `),paraId:n[0]?.getAttribute?.("w14:paraId")||n[0]?.getAttribute?.("paraId")||null})}return t}function au(e,t){if(!t)return;let r=new Map([...e.values()].filter(n=>n.paraId).map(n=>[n.paraId.toUpperCase(),n]));for(let n of Array.from(t.getElementsByTagNameNS("*","commentEx"))){let o=n.getAttribute("w15:paraId")||n.getAttribute("paraId")||"",i=n.getAttribute("w15:paraIdParent")||n.getAttribute("paraIdParent")||"",a=r.get(o.toUpperCase());a&&(a.done=(n.getAttribute("w15:done")||n.getAttribute("done"))==="1",i&&(a.parentParaId=i,a.parentCommentId=r.get(i.toUpperCase())?.id||null))}}function su(e,t){let r=new Map,n=new Map,o=null,i=s=>{for(let l of r.values())l.text+=s},a=s=>{for(let l of Array.from(s?.childNodes||[])){if(l?.nodeType!==1)continue;let u=l.localName;if(!(t==="accepted"&&(u==="del"||u==="moveFrom")||t==="rejected"&&(u==="ins"||u==="moveTo")))if(u==="commentRangeStart")r.set(Y(l,"id"),{text:""});else if(u==="commentRangeEnd"){let c=Y(l,"id");r.has(c)&&(n.set(c,r.get(c).text),r.delete(c))}else u==="r"?i(dt(l,{revisionView:t,boundary:o})):a(l)}};return e.forEach((s,l)=>{o=s,a(s),l<e.length-1&&r.size&&i(`
198
+ `)}),n}function lu(e,t={}){let r=en(e?.documentXml,"word/document.xml",!0);if(r.error)return{status:"error",error:r.error,paragraphs:[],comments:[],warnings:[]};let n=en(e?.commentsXml,"word/comments.xml"),o=en(e?.commentsExtendedXml,"word/commentsExtended.xml"),i=en(e?.numberingXml,"word/numbering.xml"),a=[...r.warnings||[]];n.error&&a.push(n.error.message),o.error&&a.push(o.error.message),i.error&&a.push(i.error.message);let s=iu(n.doc);au(s,o.doc);let l=tu(i.doc),u=null,c=Te(r.doc),f=su(c,t.revisionView||"accepted"),m=c.map((g,h)=>{let x=ye(g,{revisionView:t.revisionView||"accepted"}),v=ru(g);v&&(u={level:v,text:x});let T=[...new Set([...De(g,"commentRangeStart"),...De(g,"commentReference")].map(H=>Y(H,"id")).filter(Boolean))],y=ou(g),N=l(Zc(g)),E=Y(pe(pe(g,"pPr"),"pStyle"),"val")||null,P=nu(g,x),$=h+1,L=N?.label&&N.format!=="bullet"?N.label:null,z=u?.text||null,j=[L,z,x.slice(0,t.excerptLength||120)].filter(Boolean).join(" \u2014 "),O=Xr(g);return{index:$,ref:`P${$}`,paragraphId:wt(g),fingerprint:kt(g),text:x,exactText:x,excerpt:x.slice(0,t.excerptLength||120),humanReference:j,inTable:qc(g,"tc"),table:P.table,styleId:E,headingLevel:v,nearestHeading:u,list:N,structuralReferences:P.references,hasRevisions:y.length>0,revisionAuthors:y,commentIds:T,segments:O}});for(let g of m)for(let h of g.commentIds){let x=s.get(h)||{id:h,author:null,date:null,text:""};x.paragraphIndex??(x.paragraphIndex=g.index),x.targetRef??(x.targetRef=g.ref),x.anchoredText??(x.anchoredText=f.get(h)||g.text),s.set(h,x)}if(t.revisedOnly&&(m=m.filter(g=>g.hasRevisions)),t.inTable!=null&&(m=m.filter(g=>g.inTable===!!t.inTable)),t.skipEmpty&&(m=m.filter(g=>g.text.length>0)),t.search){let g=String(t.search).toLowerCase();m=m.filter(h=>h.text.toLowerCase().includes(g))}if(Array.isArray(t.indexes)){let g=new Set(t.indexes);m=m.filter(h=>g.has(h.index))}if(t.range){let g=Number(t.range.start??t.range[0]),h=Number(t.range.end??t.range[1]);m=m.filter(x=>x.index>=g&&x.index<=h)}let d=[...new Set(m.flatMap(g=>g.revisionAuthors))].sort(),p=Qr(e),b=p.map(g=>g.name).sort(),w=null;return typeof t.digestFn=="function"&&(w=io({scope:"document-parts",entries:p,digestFn:t.digestFn})),{status:"ok",revisionToken:w,coveredParts:b,paragraphs:m,comments:[...s.values()],revisionAuthors:d,commentAuthors:[...new Set([...s.values()].map(g=>g.author).filter(Boolean))].sort(),counts:{paragraphs:m.length,comments:s.size,revisedParagraphs:m.filter(g=>g.hasRevisions).length},warnings:a}}var tn="http://schemas.microsoft.com/office/word/2010/wordml",Ze="http://schemas.microsoft.com/office/word/2012/wordml";function ao(e){let t=Number.parseInt(String(e),10);return(Number.isFinite(t)?1879048192+(t>>>0)>>>0:1879048192).toString(16).toUpperCase().padStart(8,"0").slice(-8)}function dr(e,t,r,n,o=ao(e)){let i=t.split(" ").map(l=>l[0]).join("").toUpperCase()||"AI",a=we(r),s=we(t);return`<w:comment w:id="${e}" w:author="${s}" w:date="${n}" w:initials="${i}">
199
+ <w:p w14:paraId="${we(o)}" xmlns:w14="${tn}">
190
200
  <w:r><w:t>${a}</w:t></w:r>
191
201
  </w:p>
192
- </w:comment>`}function dn(e){if(!e||e.length===0)return`<w:comments xmlns:w="${y}"></w:comments>`;let t=e.map(r=>pn(r.id,r.author,r.content,r.date)).join(`
193
- `);return`<w:comments xmlns:w="${y}">
202
+ </w:comment>`}function so(e){if(!e||e.length===0)return`<w:comments xmlns:w="${S}"></w:comments>`;let t=e.map(r=>dr(r.id,r.author,r.content,r.date,r.paraId)).join(`
203
+ `);return`<w:comments xmlns:w="${S}">
194
204
  ${t}
195
- </w:comments>`}function gr(e){let t=rt(e,"w:r"),r=[],n="";for(let o of t){let a=n.length,i=rt(o,"w:t");for(let s of i)n+=s.textContent||"";r.push({run:o,start:a,end:n.length})}return{fullText:n,runOffsets:r}}function Ol(e,t){let r=e.fullText.indexOf(t);if(r===-1)return{found:!1};let n=r+t.length,o=null,a=null,i=0,s=0;for(let{run:l,start:c,end:u}of e.runOffsets)r>=c&&r<u&&(o=l,i=r-c),n>c&&n<=u&&(a=l,s=n-c);return{found:!0,startRun:o,startOffset:i,endRun:a,endOffset:s}}function Mt(e,t,r){let n=S(e,"w:r");t&&n.appendChild(t.cloneNode(!0));let o=S(e,"w:t");return o.setAttribute("xml:space","preserve"),o.textContent=r,n.appendChild(o),n}function pa(e,t,r,n,o=null){let a=o||gr(t),i=Ol(a,r);if(!i.found||!i.startRun)return!1;let s=S(e,"w:commentRangeStart");s.setAttribute("w:id",String(n));let l=S(e,"w:commentRangeEnd");l.setAttribute("w:id",String(n));let c=S(e,"w:r"),u=S(e,"w:commentReference");if(u.setAttribute("w:id",String(n)),c.appendChild(u),i.startRun===i.endRun){let d=i.startRun,g=V(d,"w:t");if(!g)return d.parentNode.insertBefore(s,d),d.nextSibling?(d.parentNode.insertBefore(l,d.nextSibling),l.parentNode.insertBefore(c,l.nextSibling)):(d.parentNode.appendChild(l),d.parentNode.appendChild(c)),!0;let h=g.textContent||"",w=h.substring(0,i.startOffset),b=h.substring(i.startOffset,i.endOffset),v=h.substring(i.endOffset),E=V(d,"w:rPr"),P=d.parentNode;return w&&P.insertBefore(Mt(e,E,w),d),P.insertBefore(s,d),g.textContent=b,d.nextSibling?P.insertBefore(l,d.nextSibling):P.appendChild(l),P.insertBefore(c,l.nextSibling||null),v&&P.insertBefore(Mt(e,E,v),c.nextSibling||null),!0}let f=V(i.startRun,"w:t");if(f&&i.startOffset>0){let d=f.textContent||"",g=d.substring(0,i.startOffset),h=d.substring(i.startOffset);if(g){let w=V(i.startRun,"w:rPr");i.startRun.parentNode.insertBefore(Mt(e,w,g),i.startRun)}f.textContent=h}i.startRun.parentNode.insertBefore(s,i.startRun);let m=i.endRun||i.startRun,p=V(m,"w:t");if(p&&i.endOffset<(p.textContent||"").length){let d=p.textContent||"",g=d.substring(0,i.endOffset),h=d.substring(i.endOffset);if(p.textContent=g,h){let w=V(m,"w:rPr");m.nextSibling?m.parentNode.insertBefore(Mt(e,w,h),m.nextSibling):m.parentNode.appendChild(Mt(e,w,h))}}return m.nextSibling?(m.parentNode.insertBefore(l,m.nextSibling),l.parentNode.insertBefore(c,l.nextSibling)):(m.parentNode.appendChild(l),m.parentNode.appendChild(c)),!0}var gt="http://schemas.microsoft.com/office/2006/xmlPackage",Lt="http://schemas.openxmlformats.org/package/2006/relationships";function da(e,t){let r=ae(),n=D(e,"text/xml"),o=n.doc,a=o?K(o):null;if(n.error||a)return G("[CommentEngine] Failed to parse package:",n.error?.message||a?.textContent),e;let i=o.documentElement,s=o.createElementNS(gt,"pkg:part");s.setAttribute("pkg:name","/word/comments.xml"),s.setAttribute("pkg:contentType","application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml");let l=o.createElementNS(gt,"pkg:xmlData"),c=D(t,"text/xml").doc;if(!c)return e;l.appendChild(o.importNode(c.documentElement,!0)),s.appendChild(l),i.appendChild(s);let f=J(i,gt,"part").find(m=>m.getAttribute("pkg:name")==="/word/_rels/document.xml.rels");if(f){let m=J(f,gt,"xmlData");if(m.length>0){let p=J(m[0],Lt,"Relationships");if(p.length>0){let d=p[0],g=J(d,Lt,"Relationship");if(!g.some(w=>w.getAttribute("Type")?.includes("comments"))){let w=0;g.forEach(v=>{let E=v.getAttribute("Id"),P=parseInt(E?.replace("rId","")||"0",10);P>w&&(w=P)});let b=o.createElementNS(Lt,"Relationship");b.setAttribute("Id",`rId${w+1}`),b.setAttribute("Type","http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"),b.setAttribute("Target","comments.xml"),d.appendChild(b)}}}}else{let m=o.createElementNS(gt,"pkg:part");m.setAttribute("pkg:name","/word/_rels/document.xml.rels"),m.setAttribute("pkg:contentType","application/vnd.openxmlformats-package.relationships+xml");let p=o.createElementNS(gt,"pkg:xmlData"),d=o.createElementNS(Lt,"Relationships"),g=o.createElementNS(Lt,"Relationship");g.setAttribute("Id","rId1"),g.setAttribute("Type","http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"),g.setAttribute("Target","comments.xml"),d.appendChild(g),p.appendChild(d),m.appendChild(p),i.appendChild(m)}return r.serializeToString(o)}function kl(e,t){let r=D(e,"text/xml"),n=r.doc?K(r.doc):null;if(r.error||n){let o=r.error?.message||n?.textContent||"parse error";return{xmlDoc:null,warning:t(o),warnings:r.warnings,error:{code:"PARSE_ERROR",message:o}}}return{xmlDoc:r.doc,warning:null,warnings:r.warnings,error:null}}function Ml(e,t,r={}){let n=r?.author||re(),o=Ir(),a=[],i=[];if(!t||t.length===0)return{oxml:e,hasChanges:!1,commentsApplied:0,warnings:["No comments to inject"]};let s=ae(),l=kl(e,p=>`Failed to parse OXML: ${p}`);if(a.push(...l.warnings||[]),!l.xmlDoc)return G("[CommentEngine] Parse failure:",l.warning),{oxml:e,hasChanges:!1,commentsApplied:0,status:"error",error:l.error,warnings:[...a,l.warning]};let c=l.xmlDoc,u=rt(c,"w:p");I(`[CommentEngine] Found ${u.length} paragraphs, processing ${t.length} comment requests`);let f=new Map;for(let p of t){let d=p.paragraphIndex-1;if(d<0||d>=u.length){a.push(`Paragraph ${p.paragraphIndex} out of range (1-${u.length})`);continue}f.set(d,(f.get(d)||0)+1)}let m=new Map;for(let p of t){let d=p.paragraphIndex-1;if(d<0||d>=u.length)continue;let g=u[d],h=m.get(d);h||(h=gr(g),m.set(d,h));let w=Cn(),b=pa(c,g,p.textToFind,w,h),v=(f.get(d)||1)-1;if(f.set(d,v),!b){a.push(`Could not find "${p.textToFind.substring(0,30)}..." in paragraph ${p.paragraphIndex}`),v===0&&m.delete(d);continue}i.push({id:w,content:p.commentContent,author:n,date:o}),v>0?m.set(d,gr(g)):m.delete(d)}return i.length===0?{oxml:e,hasChanges:!1,commentsApplied:0,warnings:a}:{oxml:s.serializeToString(c),hasChanges:!0,commentsXml:dn(i),commentsApplied:i.length,warnings:a}}function Ll(e,t){return da(e,t)}function ht(e){e?.parentNode&&e.parentNode.removeChild(e)}function ga(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(o=>{r.querySelectorAll(`${o}, ${o.replace("w:","")}`).forEach(ht)});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(o=>{let a=n[o];a&&r.querySelectorAll(`${a}, ${a.replace("w:","")}`).forEach(ht)})}return r.children.length>0?r:null}function _l(e,t,r){if(!t||!e)return e;let n=Ce(e);if(!n)return e;let o="http://schemas.openxmlformats.org/wordprocessingml/2006/main",a=n.getElementsByTagNameNS(o,"r"),i=n.getElementsByTagNameNS(o,"ins"),s=[...Array.from(a)];for(let l of i){let c=l.getElementsByTagNameNS(o,"r");s.push(...Array.from(c))}for(let l of s){let c=l.getElementsByTagNameNS(o,"t"),u=Array.from(c).map(f=>f.textContent).join("");if(u.includes(t)||u===t){let f=l.getElementsByTagNameNS(o,"rPr");if(f.length>0){let m=f[0],p=ga(m,r);p?m.parentNode&&m.parentNode.replaceChild(p,m):ht(m)}}}return Ze(n)}var Bl={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 Fl(e,t,r="yellow",n={}){let o="http://schemas.openxmlformats.org/wordprocessingml/2006/main",a=Bl[r.toLowerCase()]||"yellow",i=n?.generateRedlines??!1,s=n?.author||re(),l=t;l?l=t.cloneNode(!0):l=S(e,"w:rPr");let c=null;i&&(c=S(e,"w:rPr"),Array.from(l.childNodes).forEach(m=>{m.nodeName!=="w:rPrChange"&&c.appendChild(m.cloneNode(!0))}));let u=l.getElementsByTagNameNS(o,"highlight");Array.from(u).forEach(ht);let f=S(e,"w:highlight");if(f.setAttributeNS(o,"w:val",a),l.appendChild(f),i&&c){let m=S(e,"w:rPrChange"),p=ie(s,e);m.setAttribute("w:id",String(p.id)),m.setAttribute("w:author",p.author),m.setAttribute("w:date",p.date),m.appendChild(c);let d=l.getElementsByTagNameNS(o,"rPrChange");Array.from(d).forEach(ht),l.appendChild(m)}return l}function $l(e,t,r="yellow",n={}){if(!t||!e)return e;let o=Ce(e);if(!o)return e;n?._revisionIdAllocator instanceof he?vt(o,n._revisionIdAllocator):Rn(o);let a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",i=c=>{let u=c.getElementsByTagNameNS(a,"t");return Array.from(u).map(f=>f.textContent).join("")},s=Array.from(o.getElementsByTagNameNS(a,"r")),l=(c,u,f)=>{let m=c.cloneNode(!0),p=m.getElementsByTagNameNS(a,"t");Array.from(p).forEach(ht);let d=S(o,"w:t");if(d.setAttribute("xml:space","preserve"),d.textContent=u,m.appendChild(d),f){let g=m.getElementsByTagNameNS(a,"rPr"),h=g.length>0?g[0]:null,w=Fl(o,h,r,n);h?m.replaceChild(w,h):m.insertBefore(w,m.firstChild)}return m};for(let c of s){let u=i(c);if(!u)continue;let f=[],m=0;for(;m<=u.length-t.length;){let h=u.indexOf(t,m);if(h===-1)break;f.push(h),m=h+t.length}if(f.length===0)continue;let p=c.parentNode;if(!p){console.warn("[Highlight] Run parent is null; skipping. Likely already processed.");continue}let d=o.createDocumentFragment(),g=0;for(let h of f)h>g&&d.appendChild(l(c,u.slice(g,h),!1)),d.appendChild(l(c,u.slice(h,h+t.length),!0)),g=h+t.length;g<u.length&&d.appendChild(l(c,u.slice(g),!1)),p.replaceChild(d,c)}return Ze(o)}var ue="http://schemas.openxmlformats.org/wordprocessingml/2006/main",Xl="http://schemas.openxmlformats.org/package/2006/content-types",Dl="http://schemas.openxmlformats.org/package/2006/relationships",wa="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",ba="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",xa="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",Na="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",ha="word/document.xml",hr="word/numbering.xml",_t="word/comments.xml",Me="[Content_Types].xml",Le="word/_rels/document.xml.rels";function fe(e,t="xml"){let r=D(e,"application/xml");if(r.error||!r.doc){let n=new Error(`[XML parse error] ${t}: ${r.error?.message||"Unknown"}`);throw n.code="PARSE_ERROR",n}return r.doc}function wr(e){return!!e&&e.nodeType===1&&e.namespaceURI===ue&&e.localName==="sectPr"}function hn(e){return e.getElementsByTagNameNS("*","body")[0]||null}function va(e){for(let t of Array.from(e.childNodes||[]))if(wr(t))return t;return null}function zl(e,t){let r=va(e);r?e.insertBefore(t,r):e.appendChild(t)}function Ta(e){let t=hn(e);if(!t)return;let r=va(t);if(!r)return;let n=r.nextSibling;for(;n;){let o=n.nextSibling;n.nodeType===1&&t.insertBefore(n,r),n=o}}function Wl(e,t={}){let r=typeof t?.onInfo=="function"?t.onInfo:()=>{},n=e.getElementsByTagNameNS(ue,"tc"),o=0;for(let a of Array.from(n)){let i=Array.from(a.childNodes||[]).filter(s=>s.nodeType===1&&s.namespaceURI===ue&&s.localName==="p");for(let s of i){let l=Array.from(s.childNodes||[]).filter(c=>c.nodeType===1&&c.namespaceURI===ue&&c.localName==="p");for(let c of l)a.insertBefore(c,s),o+=1}}return o>0&&r(`[Sanitize] Fixed ${o} nested w:p element(s) in table cells`),o}function gn(e){return e.getAttribute("pkg:name")||e.getAttribute("name")||""}function Ul(e){let t=ae(),r=fe(e,"package OOXML"),n=Array.from(r.getElementsByTagNameNS("*","part")),o=n.find(f=>gn(f)==="/word/document.xml");if(!o)throw new Error("Package output missing /word/document.xml part");let a=o.getElementsByTagNameNS("*","xmlData")[0];if(!a)throw new Error("Package document part missing pkg:xmlData");let i=Array.from(a.childNodes||[]).find(f=>f.nodeType===1);if(!i)throw new Error("Package document part missing XML payload");let s=i.getElementsByTagNameNS("*","body")[0],l=s?Array.from(s.childNodes||[]).filter(f=>f.nodeType===1&&!wr(f)):[i],c=n.find(f=>gn(f)==="/word/numbering.xml"),u=null;if(c){let f=c.getElementsByTagNameNS("*","xmlData")[0],m=f?Array.from(f.childNodes||[]).find(p=>p.nodeType===1):null;m&&(u=t.serializeToString(m))}return{replacementNodes:l,numberingXml:u,sourceType:"package"}}function Hl(e){if(typeof e!="string"||!e.trim())return{replacementNodes:[],numberingXml:null,sourceType:"fragment",status:"error",error:{code:"PARSE_ERROR",message:"Reconciliation engine returned no OOXML payload for this operation"}};try{if(e.includes("<pkg:package"))return Ul(e);if(e.includes("<w:document")){let o=fe(e,"document OOXML"),a=o.getElementsByTagNameNS("*","body")[0];return{replacementNodes:a?Array.from(a.childNodes||[]).filter(s=>s.nodeType===1&&!wr(s)):Array.from(o.childNodes||[]).filter(s=>s.nodeType===1),numberingXml:null,sourceType:"document"}}let t=`<root xmlns:w="${ue}">${e}</root>`,r=fe(t,"OOXML fragment");return{replacementNodes:Array.from(r.documentElement.childNodes||[]).filter(o=>o.nodeType===1),numberingXml:null,sourceType:"fragment"}}catch(t){return{replacementNodes:[],numberingXml:null,sourceType:"fragment",status:"error",error:{code:"PARSE_ERROR",message:t?.message||"Could not parse OOXML payload."}}}}function Ea(e,t,r){if(Array.from(e.getElementsByTagNameNS("*","Override")).some(i=>(i.getAttribute("PartName")||"").toLowerCase()===String(t).toLowerCase()))return!1;let a=e.createElementNS(Xl,"Override");return a.setAttribute("PartName",t),a.setAttribute("ContentType",r),e.documentElement.appendChild(a),!0}function ya(e,t,r){let n=e.getElementsByTagNameNS("*","Relationships")[0]||e.documentElement,o=Array.from(n.getElementsByTagNameNS("*","Relationship"));if(o.some(l=>(l.getAttribute("Type")||"")===t))return!1;let i=0;for(let l of o){let c=l.getAttribute("Id")||"",u=Number.parseInt(c.replace(/^rId/i,""),10);Number.isFinite(u)&&(i=Math.max(i,u))}let s=e.createElementNS(Dl,"Relationship");return s.setAttribute("Id",`rId${i+1}`),s.setAttribute("Type",t),s.setAttribute("Target",r),n.appendChild(s),!0}async function Te(e,t){let r=e.file(t);return r?r.async("string"):null}async function jl(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{},o=typeof r?.mergeNumberingXml=="function"?r.mergeNumberingXml:null,a=(Array.isArray(t)?t:[t]).filter(Boolean);if(a.length===0)return;let i=await Te(e,hr),s=i||null;for(let f of a){if(!s){s=f;continue}s=o?o(s,f):f}n(i?"[Demo] Merging numbering.xml payload(s) into existing numbering definitions":"[Demo] Adding numbering.xml"),e.file(hr,s);let l=ae(),c=await Te(e,Me);if(c){let f=fe(c,Me);Ea(f,"/word/numbering.xml",ba)&&e.file(Me,l.serializeToString(f))}let u=await Te(e,Le);if(u){let f=fe(u,Le);ya(f,wa,"numbering.xml")&&e.file(Le,l.serializeToString(f))}}async function Gl(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{};if(!t)return;let o=ae(),a=await Te(e,_t);if(!a)n("[Demo] Adding comments.xml"),e.file(_t,t);else{let l=fe(a,"word/comments.xml (existing)"),c=fe(t,"word/comments.xml (incoming)"),u=l.documentElement,f=new Set(Array.from(u.getElementsByTagNameNS(ue,"comment")).map(m=>m.getAttribute("w:id")||m.getAttribute("id")).filter(Boolean));for(let m of Array.from(c.documentElement.getElementsByTagNameNS(ue,"comment"))){let p=m.getAttribute("w:id")||m.getAttribute("id");if(p&&f.has(p))throw new Error(`Duplicate comment id: ${p}`);u.appendChild(l.importNode(m,!0))}e.file(_t,o.serializeToString(l))}let i=await Te(e,Me);if(i){let l=fe(i,Me);Ea(l,"/word/comments.xml",Na)&&e.file(Me,o.serializeToString(l))}let s=await Te(e,Le);if(s){let l=fe(s,Le);ya(l,xa,"comments.xml")&&e.file(Le,o.serializeToString(l))}}async function Vl(e){let t=await Te(e,ha);if(!t)throw new Error("Validation failed: missing word/document.xml");let r=fe(t,ha);Ta(r);let n=hn(r);if(!n)throw new Error("Validation failed: word/document.xml has no w:body");let o=Array.from(n.childNodes||[]).filter(g=>g.nodeType===1),a=o.map((g,h)=>({node:g,index:h})).filter(g=>wr(g.node)).map(g=>g.index);if(a.length>1)throw new Error("Validation failed: multiple body-level w:sectPr");if(a.length===1&&a[0]!==o.length-1)throw new Error("Validation failed: w:sectPr not last");let i=r.getElementsByTagNameNS(ue,"tc");for(let g of Array.from(i))for(let h of Array.from(g.childNodes||[]).filter(w=>w.nodeType===1))if(h.namespaceURI===ue&&h.localName==="p"&&Array.from(h.childNodes||[]).some(b=>b.nodeType===1&&b.namespaceURI===ue&&b.localName==="p"))throw new Error("Validation failed: nested w:p");let s=r.getElementsByTagNameNS(ue,"numPr").length>0,l=r.getElementsByTagNameNS(ue,"commentRangeStart").length>0||r.getElementsByTagNameNS(ue,"commentRangeEnd").length>0||r.getElementsByTagNameNS(ue,"commentReference").length>0,c=await Te(e,hr),u=await Te(e,_t);if(c)fe(c,hr);else if(s)throw new Error("Validation failed: numbering used but part missing");if(u)fe(u,_t);else if(l)throw new Error("Validation failed: comments used but part missing");let f=await Te(e,Me);if(!f)throw new Error(`Validation failed: missing ${Me}`);let m=fe(f,Me),p=await Te(e,Le);if(!p)throw new Error(`Validation failed: missing ${Le}`);let d=fe(p,Le);if(c){let g=Array.from(m.getElementsByTagNameNS("*","Override")).some(w=>(w.getAttribute("PartName")||"").toLowerCase()==="/word/numbering.xml"&&(w.getAttribute("ContentType")||"")===ba),h=Array.from(d.getElementsByTagNameNS("*","Relationship")).some(w=>(w.getAttribute("Type")||"")===wa);if(!g)throw new Error("Validation failed: numbering CT override missing");if(!h)throw new Error("Validation failed: numbering rel missing")}if(u){let g=Array.from(m.getElementsByTagNameNS("*","Override")).some(w=>(w.getAttribute("PartName")||"").toLowerCase()==="/word/comments.xml"&&(w.getAttribute("ContentType")||"")===Na),h=Array.from(d.getElementsByTagNameNS("*","Relationship")).some(w=>(w.getAttribute("Type")||"")===xa);if(!g)throw new Error("Validation failed: comments CT override missing");if(!h)throw new Error("Validation failed: comments rel missing")}}var wt=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 Sa(e){return!e||typeof e!="string"?e||"":e.replace(/\\n/g,`
196
- `).replace(/\\t/g," ").replace(/\\r/g,"\r")}function Kl(e={}){let t=e.originalText||"",r=Sa(e.newContent||""),n=Rt(r)||{type:"text",items:[]};return r.includes(`
197
- `)&&n.type!=="text"?{kind:wt.STRUCTURED_LIST_DIRECT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!0,isOriginalEmpty:Pa(t),hasInlineFormatting:br(r),hasBlockElements:xr(r),hasMarkdownTable:Bt(r)}}:Pa(t)?br(r)?{kind:wt.EMPTY_FORMATTED_TEXT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!0,hasBlockElements:xr(r),hasMarkdownTable:Bt(r)}}:{kind:wt.EMPTY_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!1,hasBlockElements:xr(r),hasMarkdownTable:Bt(r)}}:xr(r)?{kind:wt.BLOCK_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:br(r),hasBlockElements:!0,hasMarkdownTable:Bt(r)}}:{kind:wt.OOXML_ENGINE,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:br(r),hasBlockElements:!1,hasMarkdownTable:Bt(r)}}}function Pa(e){return!e||e.trim().length===0}function Bt(e){if(!e||!e.includes("|"))return!1;let t=Ne(e);return t.rows.length>0||t.headers.length>0}function br(e){return e?/(\*\*.+?\*\*|\*.+?\*|__.+?__|_.+?_|`.+?`|~~.+?~~|\+\+.+?\+\+)/.test(e):!1}function xr(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),o=/^[\s]*[A-Za-z]\.\s+/m.test(e),a=/^[\s]*[ivxlcIVXLC]+\.\s+/m.test(e),i=/^[\s]*\([a-z]\)\s+/m.test(e),s=/\|.*\|.*\n/.test(e),l=/^#{1,9}\s/m.test(e),c=e.includes(`
205
+ </w:comments>`}function ba(e){let t=(e||[]).map(r=>{let n=r.paraIdParent?` w15:paraIdParent="${we(r.paraIdParent)}"`:"";return`<w15:commentEx w15:paraId="${we(r.paraId)}"${n} w15:done="${r.done?"1":"0"}"/>`}).join("");return`<w15:commentsEx xmlns:w15="${Ze}">${t}</w15:commentsEx>`}function Dt(e,t=null){if(!e)return e;let r=e.nodeType===9?e:e.ownerDocument,n=t instanceof Ne?t:st(r)||vt(r),o=[e,...Array.from(e.getElementsByTagName?.("*")||[])];for(let i of o){if(!I(i,"rPrChange"))continue;let a=String(n.next());typeof i.setAttributeNS=="function"?i.setAttributeNS(S,"w:id",a):i.setAttribute("w:id",a)}return e}function rn(e,t={}){let r=t.revisionView==="current"?"accepted":t.revisionView||"accepted",n=qt(e,"w:r"),o=[],i="";for(let a of n){if(!mt(a,e,r))continue;let s=i.length,l=dt(a,{revisionView:r,boundary:e});i+=l,o.push({run:a,start:s,end:i.length})}return{fullText:i,runOffsets:o}}function xa(e,t){if(!t)return[];let r=[],n=e.indexOf(t);for(;n!==-1;)r.push({start:n,end:n+t.length}),n=e.indexOf(t,n+1);return r}function Na(e){return String(e).replace(/[ \u00a0]/g," ")}function gr(e,t,r=[]){return{code:e,message:t,...r.length>0?{candidates:r}:{}}}function va(e,t,r){let n=null,o=null,i=0,a=0;for(let{run:s,start:l,end:u}of e.runOffsets)t.start>=l&&t.start<u&&(n=s,i=t.start-l),t.end>l&&t.end<=u&&(o=s,a=t.end-l);return!n||!o?null:{found:!0,resolvedBy:r,...t,startRun:n,startOffset:i,endRun:o,endOffset:a}}function ya(e,t,r=null){let n=e?.parentNode;for(;n&&n.nodeType===1&&n!==r&&(n.localName||n.nodeName.replace(/^.*:/,""))!=="p";){let o=n.localName||n.nodeName.replace(/^.*:/,"");if(t.includes(o))return{node:n,tag:o};n=n.parentNode}return null}function Ta(e,t){if(!t||!t.found)return t;let r=e.runOffsets.filter(n=>n.end>t.start&&n.start<t.end).map(n=>n.run);for(let n of r){if(ya(n,["del"]))return{found:!1,error:gr("UNSAFE_REVISION_NESTING","Refusing to attach comment to pending deletion.",[t])};if(ya(n,["moveFrom","moveTo"]))return{found:!1,error:gr("UNSAFE_REVISION_NESTING","Refusing to comment on move revision until move lifecycle is designed.",[t])}}return t}function lo(e,t){let r=String(t??""),n=xa(e.fullText,r);if(n.length>1)return{found:!1,error:gr("AMBIGUOUS_ANCHOR",`Anchor text matched ${n.length} locations in the target paragraph.`,n)};if(n.length===1){let s=va(e,n[0],"exact_anchor");if(s)return Ta(e,s)}let o=Na(r),i=Na(e.fullText),a=xa(i,o);if(a.length>1)return{found:!1,error:gr("AMBIGUOUS_ANCHOR",`Space-equivalent anchor text matched ${a.length} locations in the target paragraph.`,a)};if(a.length===1){let s=va(e,a[0],"space_equivalent_anchor");if(s)return Ta(e,s)}return{found:!1,error:gr("ANCHOR_NOT_FOUND",`Could not find anchor text in the target paragraph: "${r}".`)}}function pr(e,t,r,n,o=!1){let i=C(e,"w:r");if(t){let s=t.cloneNode(!0);o||Dt(s,n),i.appendChild(s)}let a=C(e,"w:t");return a.setAttribute("xml:space","preserve"),a.textContent=r,i.appendChild(a),i}function Sa(e,t,r,n,o=null,i=null,a=null){let s=o||rn(t),l=a||lo(s,r);if(!l.found||!l.startRun)return!1;let u=C(e,"w:commentRangeStart");u.setAttribute("w:id",String(n));let c=C(e,"w:commentRangeEnd");c.setAttribute("w:id",String(n));let f=C(e,"w:r"),m=C(e,"w:commentReference");if(m.setAttribute("w:id",String(n)),f.appendChild(m),l.startRun===l.endRun){let w=l.startRun,g=ae(w,"w:t");if(!g)return w.parentNode.insertBefore(u,w),w.nextSibling?(w.parentNode.insertBefore(c,w.nextSibling),c.parentNode.insertBefore(f,c.nextSibling)):(w.parentNode.appendChild(c),w.parentNode.appendChild(f)),!0;let h=g.textContent||"",x=h.substring(0,l.startOffset),v=h.substring(l.startOffset,l.endOffset),T=h.substring(l.endOffset),y=ae(w,"w:rPr"),N=w.parentNode;return x&&(N.insertBefore(pr(e,y,x,i,!0),w),Dt(y,i)),N.insertBefore(u,w),g.textContent=v,w.nextSibling?N.insertBefore(c,w.nextSibling):N.appendChild(c),N.insertBefore(f,c.nextSibling||null),T&&N.insertBefore(pr(e,y,T,i),f.nextSibling||null),!0}let d=ae(l.startRun,"w:t");if(d&&l.startOffset>0){let w=d.textContent||"",g=w.substring(0,l.startOffset),h=w.substring(l.startOffset);if(g){let x=ae(l.startRun,"w:rPr");l.startRun.parentNode.insertBefore(pr(e,x,g,i,!0),l.startRun),Dt(x,i)}d.textContent=h}l.startRun.parentNode.insertBefore(u,l.startRun);let p=l.endRun||l.startRun,b=ae(p,"w:t");if(b&&l.endOffset<(b.textContent||"").length){let w=b.textContent||"",g=w.substring(0,l.endOffset),h=w.substring(l.endOffset);if(b.textContent=g,h){let x=ae(p,"w:rPr");p.nextSibling?p.parentNode.insertBefore(pr(e,x,h,i),p.nextSibling):p.parentNode.appendChild(pr(e,x,h,i))}}return p.nextSibling?(p.parentNode.insertBefore(c,p.nextSibling),c.parentNode.insertBefore(f,c.nextSibling)):(p.parentNode.appendChild(c),p.parentNode.appendChild(f)),!0}var zt="http://schemas.microsoft.com/office/2006/xmlPackage",hr="http://schemas.openxmlformats.org/package/2006/relationships";function Ea(e,t){let r=fe(),n=W(e,"text/xml"),o=n.doc,i=o?ne(o):null;if(n.error||i)return te("[CommentEngine] Failed to parse package:",n.error?.message||i?.textContent),e;let a=o.documentElement,s=o.createElementNS(zt,"pkg:part");s.setAttribute("pkg:name","/word/comments.xml"),s.setAttribute("pkg:contentType","application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml");let l=o.createElementNS(zt,"pkg:xmlData"),u=W(t,"text/xml").doc;if(!u)return e;l.appendChild(o.importNode(u.documentElement,!0)),s.appendChild(l),a.appendChild(s);let f=se(a,zt,"part").find(m=>m.getAttribute("pkg:name")==="/word/_rels/document.xml.rels");if(f){let m=se(f,zt,"xmlData");if(m.length>0){let d=se(m[0],hr,"Relationships");if(d.length>0){let p=d[0],b=se(p,hr,"Relationship");if(!b.some(g=>g.getAttribute("Type")?.includes("comments"))){let g=0;b.forEach(x=>{let v=x.getAttribute("Id"),T=parseInt(v?.replace("rId","")||"0",10);T>g&&(g=T)});let h=o.createElementNS(hr,"Relationship");h.setAttribute("Id",`rId${g+1}`),h.setAttribute("Type","http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"),h.setAttribute("Target","comments.xml"),p.appendChild(h)}}}}else{let m=o.createElementNS(zt,"pkg:part");m.setAttribute("pkg:name","/word/_rels/document.xml.rels"),m.setAttribute("pkg:contentType","application/vnd.openxmlformats-package.relationships+xml");let d=o.createElementNS(zt,"pkg:xmlData"),p=o.createElementNS(hr,"Relationships"),b=o.createElementNS(hr,"Relationship");b.setAttribute("Id","rId1"),b.setAttribute("Type","http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"),b.setAttribute("Target","comments.xml"),p.appendChild(b),d.appendChild(p),m.appendChild(d),a.appendChild(m)}return r.serializeToString(o)}function cu(e,t){let r=W(e,"text/xml"),n=r.doc?ne(r.doc):null;if(r.error||n){let o=r.error?.message||n?.textContent||"parse error";return{xmlDoc:null,warning:t(o),warnings:r.warnings,error:{code:"PARSE_ERROR",message:o}}}return{xmlDoc:r.doc,warning:null,warnings:r.warnings,error:null}}function uu(e,t,r={}){let n=r?.author||me(),o=Er(),i=[],a=[],s=[],l=[];if(!t||t.length===0)return{oxml:e,hasChanges:!1,commentsApplied:0,warnings:["No comments to inject"]};let u=fe(),c=cu(e,w=>`Failed to parse OXML: ${w}`);if(i.push(...c.warnings||[]),!c.xmlDoc)return te("[CommentEngine] Parse failure:",c.warning),{oxml:e,hasChanges:!1,commentsApplied:0,status:"error",error:c.error,warnings:[...i,c.warning]};let f=c.xmlDoc,m=vt(f),d=qt(f,"w:p");k(`[CommentEngine] Found ${d.length} paragraphs, processing ${t.length} comment requests`);let p=new Map;for(let w of t){let g=w.paragraphIndex-1;if(g<0||g>=d.length){let h=`Paragraph ${w.paragraphIndex} out of range (1-${d.length})`;i.push(h),l.push({code:"TARGET_NOT_FOUND",message:h,paragraphIndex:w.paragraphIndex});continue}p.set(g,(p.get(g)||0)+1)}let b=new Map;for(let[w,g]of t.entries()){let h=g.paragraphIndex-1;if(h<0||h>=d.length)continue;let x=d[h],v=b.get(h);v||(v=rn(x),b.set(h,v));let T=String(g.textToFind??""),y=lo(v,T),N=(p.get(h)||1)-1;if(p.set(h,N),!y.found){let $={...y.error,requestIndex:w+1,paragraphIndex:g.paragraphIndex};l.push($),i.push($.message),N===0&&b.delete(h);continue}let E=typeof r.commentIdAllocator=="function"?r.commentIdAllocator():ko();if(!Sa(f,x,T,E,v,m,y)){let $={code:"ANCHOR_INSERTION_FAILED",message:`Resolved comment anchor could not be inserted in paragraph ${g.paragraphIndex}.`,requestIndex:w+1,paragraphIndex:g.paragraphIndex};l.push($),i.push($.message),N===0&&b.delete(h);continue}a.push({id:E,content:g.commentContent,author:n,date:o}),s.push({requestIndex:w+1,paragraphIndex:g.paragraphIndex,text:T,resolvedBy:y.resolvedBy,start:y.start,end:y.end}),N>0?b.set(h,rn(x)):b.delete(h)}return a.length===0?{oxml:e,hasChanges:!1,commentsApplied:0,warnings:i,resolvedAnchors:s,...l.length>0?{status:"error",error:l[0],errors:l}:{}}:{oxml:u.serializeToString(f),hasChanges:!0,commentsXml:so(a),commentsApplied:a.length,placedComments:a,warnings:i,resolvedAnchors:s,...l.length>0?{status:"error",error:l[0],errors:l}:{}}}function fu(e,t){return Ea(e,t)}var Ia="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function wr(e,t,r){return e?.getAttribute?.(t)||e?.getAttribute?.(r)||""}function nn(e,t){let r=W(e,"application/xml");return!r.doc||r.error?{error:{code:"PARSE_ERROR",message:`Could not parse ${t}: ${r.error?.message||"invalid XML"}`}}:{doc:r.doc}}function mu(e,t){let r=new Set;for(let n of Array.from(e?.getElementsByTagNameNS("*","p")||[])){let o=wr(n,"w14:paraId","paraId");o&&r.add(o.toUpperCase())}for(let n of Array.from(t?.getElementsByTagNameNS("*","commentEx")||[])){let o=wr(n,"w15:paraId","paraId");o&&r.add(o.toUpperCase())}return r}function Aa(e,t){let r=ao(e),n=Number.parseInt(r,16)>>>0;for(;t.has(r);)n=n+1>>>0,r=n.toString(16).toUpperCase().padStart(8,"0");return t.add(r),r}function du({commentsXml:e,commentsExtendedXml:t=null,parentCommentId:r,commentId:n,commentContent:o,author:i,date:a=new Date().toISOString()}){if(!e)return{status:"error",error:{code:"COMMENTS_PART_MISSING",message:"A comment reply requires an existing word/comments.xml part."}};let s=nn(e,"word/comments.xml");if(s.error)return{status:"error",error:s.error};let l=s.doc,u=Array.from(l.getElementsByTagNameNS("*","comment")).find(v=>wr(v,"w:id","id")===String(r));if(!u)return{status:"error",error:{code:"PARENT_COMMENT_NOT_FOUND",message:`Parent comment '${r}' was not found.`}};let c=null;if(t){let v=nn(t,"word/commentsExtended.xml");if(v.error)return{status:"error",error:v.error};c=v.doc}let f=mu(l,c),m=Array.from(u.getElementsByTagNameNS(Ia,"p"))[0]||Array.from(u.getElementsByTagNameNS("*","p"))[0];if(!m)return{status:"error",error:{code:"PARENT_COMMENT_INVALID",message:`Parent comment '${r}' has no paragraph.`}};let d=wr(m,"w14:paraId","paraId");d?d=d.toUpperCase():(d=Aa(r,f),m.setAttributeNS(tn,"w14:paraId",d));let p=Aa(n,f),b=nn(`<w:comments xmlns:w="${Ia}" xmlns:w14="${tn}">${dr(n,i,o,a,p)}</w:comments>`,"reply comment");l.documentElement.appendChild(l.importNode(b.doc.documentElement.firstChild,!0)),c||(c=nn(ba([]),"word/commentsExtended.xml").doc);let w=c.documentElement;if(!Array.from(w.getElementsByTagNameNS("*","commentEx")).some(v=>wr(v,"w15:paraId","paraId").toUpperCase()===d)){let v=c.createElementNS(Ze,"w15:commentEx");v.setAttributeNS(Ze,"w15:paraId",d),v.setAttributeNS(Ze,"w15:done","0"),w.appendChild(v)}let h=c.createElementNS(Ze,"w15:commentEx");h.setAttributeNS(Ze,"w15:paraId",p),h.setAttributeNS(Ze,"w15:paraIdParent",d),h.setAttributeNS(Ze,"w15:done","0"),w.appendChild(h);let x=fe();return{status:"ok",hasChanges:!0,commentsXml:x.serializeToString(l),commentsExtendedXml:x.serializeToString(c),commentsXmlMode:"replace",commentsExtendedXmlMode:"replace",commentId:n,parentCommentId:String(r),paraId:p,parentParaId:d}}function Wt(e){e?.parentNode&&e.parentNode.removeChild(e)}function Pa(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(o=>{r.querySelectorAll(`${o}, ${o.replace("w:","")}`).forEach(Wt)});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(o=>{let i=n[o];i&&r.querySelectorAll(`${i}, ${i.replace("w:","")}`).forEach(Wt)})}return r.children.length>0?r:null}function pu(e,t,r){if(!t||!e)return e;let n=Je(e);if(!n)return e;let o="http://schemas.openxmlformats.org/wordprocessingml/2006/main",i=n.getElementsByTagNameNS(o,"r"),a=n.getElementsByTagNameNS(o,"ins"),s=[...Array.from(i)];for(let l of a){let u=l.getElementsByTagNameNS(o,"r");s.push(...Array.from(u))}for(let l of s){let u=l.getElementsByTagNameNS(o,"t"),c=Array.from(u).map(f=>f.textContent).join("");if(c.includes(t)||c===t){let f=l.getElementsByTagNameNS(o,"rPr");if(f.length>0){let m=f[0],d=Pa(m,r);d?m.parentNode&&m.parentNode.replaceChild(d,m):Wt(m)}}}return ht(n)}var gu={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 hu(e,t,r="yellow",n={}){let o="http://schemas.openxmlformats.org/wordprocessingml/2006/main",i=gu[r.toLowerCase()]||"yellow",a=n?.generateRedlines??!1,s=n?.author||me(),l=t;l?l=t.cloneNode(!0):l=C(e,"w:rPr");let u=null;a&&(u=C(e,"w:rPr"),Array.from(l.childNodes).forEach(m=>{m.nodeName!=="w:rPrChange"&&u.appendChild(m.cloneNode(!0))}));let c=l.getElementsByTagNameNS(o,"highlight");Array.from(c).forEach(Wt);let f=C(e,"w:highlight");if(f.setAttributeNS(o,"w:val",i),l.appendChild(f),a&&u){let m=C(e,"w:rPrChange"),d=ie(s,e);m.setAttribute("w:id",String(d.id)),m.setAttribute("w:author",d.author),m.setAttribute("w:date",d.date),m.appendChild(u);let p=l.getElementsByTagNameNS(o,"rPrChange");Array.from(p).forEach(Wt),l.appendChild(m)}return l}function wu(e,t,r="yellow",n={}){if(!t||!e)return e;let o=Je(e);if(!o)return e;let i;n?._revisionIdAllocator instanceof Ne?(i=n._revisionIdAllocator,yt(o,i)):i=vt(o);let a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",s=f=>{let m=f.getElementsByTagNameNS(a,"t");return Array.from(m).map(d=>d.textContent).join("")},l=Array.from(o.getElementsByTagNameNS(a,"r")),u=new WeakSet,c=(f,m,d)=>{let p=f.cloneNode(!0);u.has(f)?Dt(p,i):u.add(f);let b=p.getElementsByTagNameNS(a,"t");Array.from(b).forEach(Wt);let w=C(o,"w:t");if(w.setAttribute("xml:space","preserve"),w.textContent=m,p.appendChild(w),d){let g=p.getElementsByTagNameNS(a,"rPr"),h=g.length>0?g[0]:null,x=hu(o,h,r,n);h?p.replaceChild(x,h):p.insertBefore(x,p.firstChild)}return p};for(let f of l){let m=s(f);if(!m)continue;let d=[],p=0;for(;p<=m.length-t.length;){let h=m.indexOf(t,p);if(h===-1)break;d.push(h),p=h+t.length}if(d.length===0)continue;let b=f.parentNode;if(!b){console.warn("[Highlight] Run parent is null; skipping. Likely already processed.");continue}let w=o.createDocumentFragment(),g=0;for(let h of d)h>g&&w.appendChild(c(f,m.slice(g,h),!1)),w.appendChild(c(f,m.slice(h,h+t.length),!0)),g=h+t.length;g<m.length&&w.appendChild(c(f,m.slice(g),!1)),b.replaceChild(w,f)}return ht(o)}var Se="http://schemas.openxmlformats.org/wordprocessingml/2006/main",bu="http://schemas.openxmlformats.org/package/2006/content-types",xu="http://schemas.openxmlformats.org/package/2006/relationships",Ca="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",Oa="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",ka="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",Ma="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",_a="http://schemas.microsoft.com/office/2011/relationships/commentsExtended",La="application/vnd.ms-word.commentsExtended+xml",Ra="word/document.xml",on="word/numbering.xml",br="word/comments.xml",co="word/commentsExtended.xml",Me="[Content_Types].xml",_e="word/_rels/document.xml.rels";function ge(e,t="xml"){let r=W(e,"application/xml");if(r.error||!r.doc){let n=new Error(`[XML parse error] ${t}: ${r.error?.message||"Unknown"}`);throw n.code="PARSE_ERROR",n}return r.doc}function an(e){return!!e&&e.nodeType===1&&e.namespaceURI===Se&&e.localName==="sectPr"}function fo(e){return e.getElementsByTagNameNS("*","body")[0]||null}function Ba(e){for(let t of Array.from(e.childNodes||[]))if(an(t))return t;return null}function Nu(e,t){let r=Ba(e);r?e.insertBefore(t,r):e.appendChild(t)}function Fa(e){let t=fo(e);if(!t)return;let r=Ba(t);if(!r)return;let n=r.nextSibling;for(;n;){let o=n.nextSibling;n.nodeType===1&&t.insertBefore(n,r),n=o}}function vu(e,t={}){let r=typeof t?.onInfo=="function"?t.onInfo:()=>{},n=e.getElementsByTagNameNS(Se,"tc"),o=0;for(let i of Array.from(n)){let a=Array.from(i.childNodes||[]).filter(s=>s.nodeType===1&&s.namespaceURI===Se&&s.localName==="p");for(let s of a){let l=Array.from(s.childNodes||[]).filter(u=>u.nodeType===1&&u.namespaceURI===Se&&u.localName==="p");for(let u of l)i.insertBefore(u,s),o+=1}}return o>0&&r(`[Sanitize] Fixed ${o} nested w:p element(s) in table cells`),o}function uo(e){return e.getAttribute("pkg:name")||e.getAttribute("name")||""}function yu(e){let t=fe(),r=ge(e,"package OOXML"),n=Array.from(r.getElementsByTagNameNS("*","part")),o=n.find(f=>uo(f)==="/word/document.xml");if(!o)throw new Error("Package output missing /word/document.xml part");let i=o.getElementsByTagNameNS("*","xmlData")[0];if(!i)throw new Error("Package document part missing pkg:xmlData");let a=Array.from(i.childNodes||[]).find(f=>f.nodeType===1);if(!a)throw new Error("Package document part missing XML payload");let s=a.getElementsByTagNameNS("*","body")[0],l=s?Array.from(s.childNodes||[]).filter(f=>f.nodeType===1&&!an(f)):[a],u=n.find(f=>uo(f)==="/word/numbering.xml"),c=null;if(u){let f=u.getElementsByTagNameNS("*","xmlData")[0],m=f?Array.from(f.childNodes||[]).find(d=>d.nodeType===1):null;m&&(c=t.serializeToString(m))}return{replacementNodes:l,numberingXml:c,sourceType:"package"}}function Tu(e){if(typeof e!="string"||!e.trim())return{replacementNodes:[],numberingXml:null,sourceType:"fragment",status:"error",error:{code:"PARSE_ERROR",message:"Reconciliation engine returned no OOXML payload for this operation"}};try{if(e.includes("<pkg:package"))return yu(e);if(e.includes("<w:document")){let o=ge(e,"document OOXML"),i=o.getElementsByTagNameNS("*","body")[0];return{replacementNodes:i?Array.from(i.childNodes||[]).filter(s=>s.nodeType===1&&!an(s)):Array.from(o.childNodes||[]).filter(s=>s.nodeType===1),numberingXml:null,sourceType:"document"}}let t=`<root xmlns:w="${Se}">${e}</root>`,r=ge(t,"OOXML fragment");return{replacementNodes:Array.from(r.documentElement.childNodes||[]).filter(o=>o.nodeType===1),numberingXml:null,sourceType:"fragment"}}catch(t){return{replacementNodes:[],numberingXml:null,sourceType:"fragment",status:"error",error:{code:"PARSE_ERROR",message:t?.message||"Could not parse OOXML payload."}}}}function mo(e,t,r){let o=Array.from(e.getElementsByTagNameNS("*","Override")).find(a=>(a.getAttribute("PartName")||"").toLowerCase()===String(t).toLowerCase());if(o)return(o.getAttribute("ContentType")||"")===r?!1:(o.setAttribute("ContentType",r),!0);let i=e.createElementNS(bu,"Override");return i.setAttribute("PartName",t),i.setAttribute("ContentType",r),e.documentElement.appendChild(i),!0}function po(e,t,r,n={}){let o=e.getElementsByTagNameNS("*","Relationships")[0]||e.documentElement,i=Array.from(o.getElementsByTagNameNS("*","Relationship"));if(i.some(c=>(c.getAttribute("Type")||"")===t))return!1;let s=0;for(let c of i){let f=c.getAttribute("Id")||"",m=Number.parseInt(f.replace(/^rId/i,""),10);Number.isFinite(m)&&(s=Math.max(s,m))}let l=`rId${s+1}`,u=e.createElementNS(xu,"Relationship");return u.setAttribute("Id",l),u.setAttribute("Type",t),u.setAttribute("Target",r),o.appendChild(u),n?._receiptCollector?n._receiptCollector.recordRelationship(l):n?._documentOperationSession?.receiptCollector&&n._documentOperationSession.receiptCollector.recordRelationship(l),!0}async function Ie(e,t){let r=e.file(t);return r?r.async("string"):null}async function Su(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{},o=typeof r?.mergeNumberingXml=="function"?r.mergeNumberingXml:null,i=typeof r?.onWarn=="function"?r.onWarn:Le,a=(Array.isArray(t)?t:[t]).filter(Boolean);if(a.length===0)return;let s=await Ie(e,on);s&&!o&&i("[Deprecation] Replacing an existing numbering.xml without mergeNumberingXml is deprecated and will throw in the next major version.");let l=s||null;for(let m of a){if(!l){l=m;continue}l=o?o(l,m):m}n(s?"[Demo] Merging numbering.xml payload(s) into existing numbering definitions":"[Demo] Adding numbering.xml"),e.file(on,l);let u=fe(),c=await Ie(e,Me);if(c){let m=ge(c,Me);mo(m,"/word/numbering.xml",Oa)&&e.file(Me,u.serializeToString(m))}let f=await Ie(e,_e);if(f){let m=ge(f,_e);po(m,Ca,"numbering.xml",r)&&e.file(_e,u.serializeToString(m))}}async function Eu(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{};if(!t)return;let o=fe(),i=await Ie(e,br);if(!i||r.replaceExisting===!0)n("[Demo] Adding comments.xml"),e.file(br,t);else{let l=ge(i,"word/comments.xml (existing)"),u=ge(t,"word/comments.xml (incoming)"),c=l.documentElement,f=new Set(Array.from(c.getElementsByTagNameNS(Se,"comment")).map(m=>m.getAttribute("w:id")||m.getAttribute("id")).filter(Boolean));for(let m of Array.from(u.documentElement.getElementsByTagNameNS(Se,"comment"))){let d=m.getAttribute("w:id")||m.getAttribute("id");if(d&&f.has(d))throw new Error(`Duplicate comment id: ${d}`);c.appendChild(l.importNode(m,!0))}e.file(br,o.serializeToString(l))}let a=await Ie(e,Me);if(a){let l=ge(a,Me);mo(l,"/word/comments.xml",Ma)&&e.file(Me,o.serializeToString(l))}let s=await Ie(e,_e);if(s){let l=ge(s,_e);po(l,ka,"comments.xml",r)&&e.file(_e,o.serializeToString(l))}}async function Iu(e,t,r={}){if(!t)return;ge(t,"word/commentsExtended.xml"),e.file(co,t);let n=fe(),o=await Ie(e,Me);if(o){let a=ge(o,Me);mo(a,"/word/commentsExtended.xml",La)&&e.file(Me,n.serializeToString(a))}let i=await Ie(e,_e);if(i){let a=ge(i,_e);po(a,_a,"commentsExtended.xml",r)&&e.file(_e,n.serializeToString(a))}}async function Au(e){let t=await Ie(e,Ra);if(!t)throw new Error("Validation failed: missing word/document.xml");let r=ge(t,Ra);Fa(r);let n=fo(r);if(!n)throw new Error("Validation failed: word/document.xml has no w:body");let o=Array.from(n.childNodes||[]).filter(w=>w.nodeType===1),i=o.map((w,g)=>({node:w,index:g})).filter(w=>an(w.node)).map(w=>w.index);if(i.length>1)throw new Error("Validation failed: multiple body-level w:sectPr");if(i.length===1&&i[0]!==o.length-1)throw new Error("Validation failed: w:sectPr not last");let a=r.getElementsByTagNameNS(Se,"tc");for(let w of Array.from(a))for(let g of Array.from(w.childNodes||[]).filter(h=>h.nodeType===1))if(g.namespaceURI===Se&&g.localName==="p"&&Array.from(g.childNodes||[]).some(x=>x.nodeType===1&&x.namespaceURI===Se&&x.localName==="p"))throw new Error("Validation failed: nested w:p");let s=r.getElementsByTagNameNS(Se,"numPr").length>0,l=r.getElementsByTagNameNS(Se,"commentRangeStart").length>0||r.getElementsByTagNameNS(Se,"commentRangeEnd").length>0||r.getElementsByTagNameNS(Se,"commentReference").length>0,u=await Ie(e,on),c=await Ie(e,br),f=await Ie(e,co);if(f&&!c)throw new Error("Validation failed: commentsExtended part exists but comments part is missing");if(u)ge(u,on);else if(s)throw new Error("Validation failed: numbering used but part missing");if(c){let w=ge(c,br),g=(R,_)=>Array.from(R.getElementsByTagNameNS(Se,_)).map(F=>F.getAttribute("w:id")||F.getAttribute("id")).filter(F=>F!==""),h=new Set(g(r,"commentRangeStart")),x=new Set(g(r,"commentRangeEnd")),v=new Set(g(r,"commentReference")),T=g(w,"comment"),y=new Set(T),N=R=>Array.from(R).sort((_,F)=>Number(_)-Number(F)||_.localeCompare(F)),E=(R,_)=>N(new Set(Array.from(R).filter(F=>!_.has(F)))),P=N(new Set(T.filter((R,_)=>T.indexOf(R)!==_)));if(P.length>0)throw new Error(`Validation failed: duplicate comment definitions for id(s): ${P.join(", ")}`);let $=E(h,x),L=E(x,h);if($.length>0||L.length>0){let R=[];throw $.length>0&&R.push(`start without end: ${$.join(", ")}`),L.length>0&&R.push(`end without start: ${L.join(", ")}`),new Error(`Validation failed: unbalanced comment range marker(s) (${R.join("; ")})`)}let z=E(new Set([...h,...x]),v);if(z.length>0)throw new Error(`Validation failed: comment range has no reference for id(s): ${z.join(", ")}`);let j=E(new Set([...h,...x,...v]),y);if(j.length>0)throw new Error(`Validation failed: comment usage has no definition for id(s): ${j.join(", ")}`);let O=new Set;if(f){let R=ge(f,co),_=new Map;for(let G of Array.from(w.getElementsByTagNameNS("*","comment"))){let Q=G.getAttribute("w:id")||G.getAttribute("id"),ee=Array.from(G.getElementsByTagNameNS("*","p"))[0],ze=ee?.getAttribute("w14:paraId")||ee?.getAttribute("paraId");ze&&_.set(ze.toUpperCase(),Q)}let F=new Set(_.keys()),Z=new Set;for(let G of Array.from(R.getElementsByTagNameNS("*","commentEx"))){let Q=G.getAttribute("w15:paraId")||G.getAttribute("paraId"),ee=G.getAttribute("w15:paraIdParent")||G.getAttribute("paraIdParent");if(!Q||!F.has(Q.toUpperCase()))throw new Error(`Validation failed: commentsExtended entry has no matching comment paragraph: ${Q||"(missing)"}`);if(Z.has(Q.toUpperCase()))throw new Error(`Validation failed: duplicate commentsExtended entry for paraId: ${Q}`);if(Z.add(Q.toUpperCase()),ee){if(!F.has(ee.toUpperCase()))throw new Error(`Validation failed: commentsExtended parent paragraph was not found: ${ee}`);O.add(_.get(Q.toUpperCase()))}}}let H=E(new Set([...y].filter(R=>!O.has(R))),v);if(H.length>0)throw new Error(`Validation failed: comment definition has no document reference for id(s): ${H.join(", ")}`)}else if(l)throw new Error("Validation failed: comments used but part missing");let m=await Ie(e,Me);if(!m)throw new Error(`Validation failed: missing ${Me}`);let d=ge(m,Me),p=await Ie(e,_e);if(!p)throw new Error(`Validation failed: missing ${_e}`);let b=ge(p,_e);if(u){let w=Array.from(d.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/numbering.xml"&&(h.getAttribute("ContentType")||"")===Oa),g=Array.from(b.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===Ca);if(!w)throw new Error("Validation failed: numbering CT override missing");if(!g)throw new Error("Validation failed: numbering rel missing")}if(c){let w=Array.from(d.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/comments.xml"&&(h.getAttribute("ContentType")||"")===Ma),g=Array.from(b.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===ka);if(!w)throw new Error("Validation failed: comments CT override missing");if(!g)throw new Error("Validation failed: comments rel missing")}if(f){let w=Array.from(d.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/commentsextended.xml"&&(h.getAttribute("ContentType")||"")===La),g=Array.from(b.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===_a);if(!w)throw new Error("Validation failed: commentsExtended CT override missing");if(!g)throw new Error("Validation failed: commentsExtended rel missing")}}var Ut=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 Xa(e){return!e||typeof e!="string"?e||"":e.replace(/\\n/g,`
206
+ `).replace(/\\t/g," ").replace(/\\r/g,"\r")}function Pu(e={}){let t=e.originalText||"",r=Xa(e.newContent||""),n=cr(r)||{type:"text",items:[]};return r.includes(`
207
+ `)&&n.type!=="text"?{kind:Ut.STRUCTURED_LIST_DIRECT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!0,isOriginalEmpty:$a(t),hasInlineFormatting:sn(r),hasBlockElements:ln(r),hasMarkdownTable:xr(r)}}:$a(t)?sn(r)?{kind:Ut.EMPTY_FORMATTED_TEXT,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!0,hasBlockElements:ln(r),hasMarkdownTable:xr(r)}}:{kind:Ut.EMPTY_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!0,hasInlineFormatting:!1,hasBlockElements:ln(r),hasMarkdownTable:xr(r)}}:ln(r)?{kind:Ut.BLOCK_HTML,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:sn(r),hasBlockElements:!0,hasMarkdownTable:xr(r)}}:{kind:Ut.OOXML_ENGINE,normalizedContent:r,parsedListData:n,flags:{hasStructuredListContent:!1,isOriginalEmpty:!1,hasInlineFormatting:sn(r),hasBlockElements:!1,hasMarkdownTable:xr(r)}}}function $a(e){return!e||e.trim().length===0}function xr(e){if(!e||!e.includes("|"))return!1;let t=$e(e);return t.rows.length>0||t.headers.length>0}function sn(e){return e?/(\*\*.+?\*\*|\*.+?\*|__.+?__|_.+?_|`.+?`|~~.+?~~|\+\+.+?\+\+)/.test(e):!1}function ln(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),o=/^[\s]*[A-Za-z]\.\s+/m.test(e),i=/^[\s]*[ivxlcIVXLC]+\.\s+/m.test(e),a=/^[\s]*\([a-z]\)\s+/m.test(e),s=/\|.*\|.*\n/.test(e),l=/^#{1,9}\s/m.test(e),u=e.includes(`
198
208
 
199
- `);return t||r||n||o||a||i||s||l||c}function Yl(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 Ia(e,t,r,n={}){let o=await qr(e,t,r,n);if(o?.useNativeApi&&typeof o?.oxml!="string"){let a=Array.isArray(o?.warnings)?o.warnings:[];return oe({...o,oxml:e,hasChanges:!1,warnings:[...a,"Standalone mode cannot execute native Word API fallback for this operation."]})}return o}async function Wp(e,t,r,n={}){let o=typeof e=="string"?e:"",a=typeof r=="string"?r:String(r||""),i;try{i=Ne(a)}catch{i={headers:[],rows:[]}}return(i?.headers?.length||0)>0||(i?.rows?.length||0)>0?{...await Ia(o,t||"",a,n),isMarkdownTable:!0,tableData:i}:{oxml:o,hasChanges:!1,isMarkdownTable:!1,warnings:["Could not parse Markdown table from input."]}}async function Up(e,t,r,n={}){let o=n.listFallbackAllowExistingList!==!1,a=n.sanitizeInput===!0?en(r):r,i=a!==r?["Input was sanitized; pass sanitizeInput: false to disable."]:[],s=ln({oxml:e,originalText:t,modifiedText:a,allowExistingList:o}),l=n.preferListStructuralFallback!==!1,c=[];if(s&&l){let g=await mr(s,{author:n.author,generateRedlines:n.generateRedlines,pipeline:n.listFallbackPipeline});if(g?.hasChanges&&g?.oxml){let h=Fe(g.oxml,{includeNumbering:g.includeNumbering??!0,numberingXml:g.numberingXml}),w=Array.isArray(g?.warnings)?g.warnings:[];return oe({oxml:h,hasChanges:!0,warnings:[...i,...w],listStructuralFallbackApplied:!0,listStructuralFallbackKey:g.listStructuralFallbackKey||null,listStructuralFallbackNumberingXml:g.numberingXml||null})}c=Array.isArray(g?.warnings)?g.warnings:[]}let u=await Ia(e,t,r,n);if(!s)return{...u,warnings:[...Array.isArray(u?.warnings)?u.warnings:[],...c],listStructuralFallbackApplied:!1};if(l)return{...u,warnings:[...Array.isArray(u?.warnings)?u.warnings:[],...c],listStructuralFallbackApplied:!1};if(u?.hasChanges)return{...u,listStructuralFallbackApplied:!1};let f=await mr(s,{author:n.author,generateRedlines:n.generateRedlines,pipeline:n.listFallbackPipeline});if(!f?.hasChanges||!f?.oxml){let g=Array.isArray(u?.warnings)?u.warnings:[],h=Array.isArray(f?.warnings)?f.warnings:[];return{...u,warnings:[...g,...h],listStructuralFallbackApplied:!1}}let m=Fe(f.oxml,{includeNumbering:f.includeNumbering??!0,numberingXml:f.numberingXml}),p=Array.isArray(u?.warnings)?u.warnings:[],d=Array.isArray(f?.warnings)?f.warnings:[];return oe({...u,oxml:m,hasChanges:!0,warnings:[...p,...c,...d],listStructuralFallbackApplied:!0,listStructuralFallbackKey:f.listStructuralFallbackKey||null,listStructuralFallbackNumberingXml:f.numberingXml||null})}export{et as ContainerKind,In as ContentType,we as DiffOp,y as NS_W,Et as NumberingService,Ge as ReconciliationPipeline,wt as RoutePlanKind,_ as RunKind,ge as WORD_MAIN_NS,Qr as acceptTrackedChangesInOoxml,_l as applyFormattingRemovalToOoxml,$l as applyHighlightToOoxml,Ia as applyRedlineToOxml,Up as applyRedlineToOxmlWithListFallback,pn as buildCommentElement,dn as buildCommentsPartXml,bl as buildExplicitDecimalMultilevelNumberingXml,Ds as buildListMarkdown,Kl as buildReconciliationPlan,ln as buildSingleLineListStructuralFallbackPlan,ks as buildTargetReferenceSnapshot,Vs as clearSingleLineListFallbackExplicitSequence,ea as collectContiguousListParagraphBlock,Fa as configureLogger,$a as configureXmlProvider,Xr as containsTrackedChanges,ml as createDynamicNumberingIdState,Ss as deleteCommentsByAuthorInOoxml,Ks as enforceListBindingOnParagraphNodes,Gl as ensureCommentsArtifactsInZip,jl as ensureNumberingArtifactsInZip,pe as escapeXml,mr as executeSingleLineListStructuralFallback,wl as extractFirstParagraphNumId,Yl as extractParagraphIdFromOoxml,Hl as extractReplacementNodesFromOoxml,ct as findContainingWordElement,tn as findParagraphByBestTextMatch,Go as findParagraphByReference,lr as findParagraphByStrictText,je as generateTableOoxml,hn as getBodyElementFromDocument,re as getDefaultAuthor,Oe as getDocumentParagraphNodes,gn as getPackagePartName,ke as getParagraphListInfo,Y as getParagraphText,Er as getPlatform,an as hasListItems,sn as inferNumberingStyleFromMarker,ul as inferTableReplacementParagraphBlock,Ht as ingestOoxml,Cl as ingestWordOoxmlToMarkdown,ma as ingestWordOoxmlToMarkdownResult,Rl as ingestWordOoxmlToPlainText,fa as ingestWordOoxmlToPlainTextResult,Ml as injectCommentsIntoOoxml,Ll as injectCommentsIntoPackage,zl as insertBodyElementBeforeSectPr,oa as isLikelyStructuredTableSourceParagraph,nn as isMarkdownTableText,Nl as mergeNumberingXmlBySchemaOrder,Ta as normalizeBodySectionOrderStandalone,Sa as normalizeContentEscapesForRouting,zs as normalizeListItemsWithLevels,$ as normalizeWhitespaceForTargeting,hl as overwriteParagraphNumIds,Rt as parseMarkdownListContent,Ce as parseOoxml,D as parseOoxmlSafe,on as parseParagraphReference,Xs as planListInsertionOnlyEdit,le as preprocessMarkdown,Wp as reconcileMarkdownTableOoxml,Gs as recordSingleLineListFallbackExplicitSequence,vs as rejectTrackedChangesInOoxml,xl as remapNumberingPayloadForDocument,ga as removeFormattingFromRPr,Ot as reserveNextNumberingId,dl as reserveNextNumberingIdPair,Ms as resolveParagraphRangeByRefs,js as resolveSingleLineListFallbackNumberingAction,Vo as resolveTargetParagraph,rn as resolveTargetParagraphWithSnapshot,en as sanitizeAiResponse,Wl as sanitizeNestedParagraphsInTables,Ze as serializeOoxml,xe as serializeToOoxml,za as setDefaultAuthor,Wa as setPlatform,Rs as splitLeadingParagraphMarker,As as stripLeadingParagraphMarker,Qo as stripRedundantLeadingListMarkers,Us as stripSingleLineListMarkerPrefix,$s as synthesizeExpandedListScopeEdit,fl as synthesizeTableMarkdownFromMultilineCellEdit,Vl as validateDocxPackage,al as validateRedlineOoxml,Fe as wrapInDocumentFragment};
209
+ `);return t||r||n||o||i||a||s||l||u}function Ru(e){if(!e||typeof e!="string")return null;let t=e.match(/\b(?:w14:paraId|w:paraId|paraId)="([^"]+)"/i);return t?t[1]:null}var go=class{constructor(){this.receipts=[],this.activeReceipt=null}beginOperation(t,r=null,n=null){this.activeReceipt={operationIndex:typeof t=="number"?t:1,...r?{operationId:String(r)}:{},attemptedDisposition:"applied",finalDisposition:"applied",committed:!0,...n?{authorUsed:String(n)}:{},revisionItems:[],commentIds:[],numberingIds:[],relationshipIds:[],affectedTargets:[],warnings:[]}}recordRevision(t,r="structural",n="word/document.xml"){if(!this.activeReceipt||t==null)return;let o=String(t);this.activeReceipt.revisionItems.some(i=>i.id===o&&i.kind===r&&i.partName===n)||this.activeReceipt.revisionItems.push({id:o,kind:r,partName:n})}recordComment(t,r="word/comments.xml"){if(!this.activeReceipt||t==null)return;let n=String(t);this.activeReceipt.commentIds.includes(n)||this.activeReceipt.commentIds.push(n)}recordNumbering(t,r="word/numbering.xml"){if(!this.activeReceipt||t==null)return;let n=String(t);this.activeReceipt.numberingIds.includes(n)||this.activeReceipt.numberingIds.push(n)}recordRelationship(t,r="word/_rels/document.xml.rels"){if(!this.activeReceipt||t==null)return;let n=String(t);this.activeReceipt.relationshipIds.includes(n)||this.activeReceipt.relationshipIds.push(n)}recordAffectedTarget(t){!this.activeReceipt||!t||this.activeReceipt.affectedTargets.push(JSON.parse(JSON.stringify(t)))}recordWarning(t){!this.activeReceipt||!t||this.activeReceipt.warnings.push(String(t))}commitOperation(t="applied"){if(!this.activeReceipt)return null;this.activeReceipt.attemptedDisposition=t,this.activeReceipt.finalDisposition=t,this.activeReceipt.committed=t==="applied";let r=JSON.parse(JSON.stringify(this.activeReceipt));return this.receipts.push(r),this.activeReceipt=null,r}abortOperation(t="refused"){if(!this.activeReceipt)return null;this.activeReceipt.attemptedDisposition=t,this.activeReceipt.finalDisposition=t,this.activeReceipt.committed=!1;let r=JSON.parse(JSON.stringify(this.activeReceipt));return this.activeReceipt=null,r}createSavepoint(){return{receipts:JSON.parse(JSON.stringify(this.receipts)),activeReceipt:this.activeReceipt?JSON.parse(JSON.stringify(this.activeReceipt)):null}}restoreSavepoint(t){t&&(this.receipts=Array.isArray(t.receipts)?JSON.parse(JSON.stringify(t.receipts)):[],this.activeReceipt=t.activeReceipt?JSON.parse(JSON.stringify(t.activeReceipt)):null)}clear(){this.receipts=[],this.activeReceipt=null}markRolledBack(){for(let t of this.receipts)t.attemptedDisposition==="applied"&&(t.finalDisposition="rolled_back",t.committed=!1);this.activeReceipt=null}getReceipts(){return JSON.parse(JSON.stringify(this.receipts))}getCurrentReceipt(){return this.activeReceipt?JSON.parse(JSON.stringify(this.activeReceipt)):null}};function Cu(e,t=null,r=null,n="not_attempted"){return{operationIndex:typeof e=="number"?e:1,...t?{operationId:String(t)}:{},attemptedDisposition:n,finalDisposition:n,committed:!1,...r?{authorUsed:String(r)}:{},revisionItems:[],commentIds:[],numberingIds:[],relationshipIds:[],affectedTargets:[],warnings:[]}}function Ou(e,t){if(!Array.isArray(t)||t.length===0)return{valid:!0};let r=t.filter(l=>l&&l.committed===!0&&l.finalDisposition==="applied");if(r.length===0)return{valid:!0};let n=new Set;if(e?.documentXml&&typeof e.documentXml=="string"){let l=/<(?:w:)?(?:ins|del|rPrChange|pPrChange|moveFrom|moveTo)\b[^>]*?\b(?:w:)?id="([^"]+)"/g,u;for(;(u=l.exec(e.documentXml))!==null;)n.add(u[1])}let o=new Set;if(e?.commentsXml&&typeof e.commentsXml=="string"){let l=/<(?:w:)?comment\b[^>]*?\b(?:w:)?id="([^"]+)"/g,u;for(;(u=l.exec(e.commentsXml))!==null;)o.add(u[1])}let i=new Set,a=[e?.numberingXml,...e?.numberingXmlParts||[]].filter(Boolean).join(`
210
+ `);if(a){let l=/<(?:w:)?num\b[^>]*?\b(?:w:)?numId="([^"]+)"/g,u;for(;(u=l.exec(a))!==null;)i.add(u[1])}if(e?.documentXml&&typeof e.documentXml=="string"){let l=/<(?:w:)?numId\b[^>]*?\b(?:w:)?val="([^"]+)"/g,u;for(;(u=l.exec(e.documentXml))!==null;)i.add(u[1])}let s=new Set;if(e?.relationshipsXml&&typeof e.relationshipsXml=="string"){let l=/<Relationship\b[^>]*?\bId="([^"]+)"/g,u;for(;(u=l.exec(e.relationshipsXml))!==null;)s.add(u[1])}for(let l of r){if(Array.isArray(l.revisionItems)){for(let u of l.revisionItems)if(u.partName==="word/document.xml"&&!n.has(String(u.id)))return{valid:!1,error:{code:"RECEIPT_RECONCILIATION_FAILED",message:`Committed revision id '${u.id}' (kind: ${u.kind}) was not found in word/document.xml.`}}}if(Array.isArray(l.commentIds)){for(let u of l.commentIds)if(!o.has(String(u)))return{valid:!1,error:{code:"RECEIPT_RECONCILIATION_FAILED",message:`Committed comment id '${u}' was not found in word/comments.xml.`}}}if(Array.isArray(l.numberingIds)){for(let u of l.numberingIds)if(!i.has(String(u)))return{valid:!1,error:{code:"RECEIPT_RECONCILIATION_FAILED",message:`Committed numbering id '${u}' was not found in numbering parts or document.`}}}if(e?.relationshipsXml&&Array.isArray(l.relationshipIds)){for(let u of l.relationshipIds)if(!s.has(String(u)))return{valid:!1,error:{code:"RECEIPT_RECONCILIATION_FAILED",message:`Committed relationship id '${u}' was not found in document.xml.rels.`}}}}return{valid:!0}}async function Da(e,t,r,n={}){let o=await Vn(e,t,r,n);if(o?.useNativeApi&&typeof o?.oxml!="string"){let i=Array.isArray(o?.warnings)?o.warnings:[];return de({...o,oxml:e,hasChanges:!1,warnings:[...i,"Standalone mode cannot execute native Word API fallback for this operation."]})}return o}async function gh(e,t,r,n={}){let o=typeof e=="string"?e:"",i=typeof r=="string"?r:String(r||""),a;try{a=$e(i)}catch{a={headers:[],rows:[]}}return(a?.headers?.length||0)>0||(a?.rows?.length||0)>0?{...await Da(o,t||"",i,n),isMarkdownTable:!0,tableData:a}:{oxml:o,hasChanges:!1,isMarkdownTable:!1,warnings:["Could not parse Markdown table from input."]}}async function hh(e,t,r,n={}){let o=n.listFallbackAllowExistingList!==!1,i=n.sanitizeInput===!0?Gn(r):r,a=i!==r?["Input was sanitized; pass sanitizeInput: false to disable."]:[],s=Qn({oxml:e,originalText:t,modifiedText:i,allowExistingList:o}),l=n.preferListStructuralFallback!==!1,u=[];if(s&&l){let b=await Jr(s,{author:n.author,generateRedlines:n.generateRedlines,pipeline:n.listFallbackPipeline});if(b?.hasChanges&&b?.oxml){let w=et(b.oxml,{includeNumbering:b.includeNumbering??!0,numberingXml:b.numberingXml}),g=Array.isArray(b?.warnings)?b.warnings:[];return de({oxml:w,hasChanges:!0,warnings:[...a,...g],listStructuralFallbackApplied:!0,listStructuralFallbackKey:b.listStructuralFallbackKey||null,listStructuralFallbackNumberingXml:b.numberingXml||null})}u=Array.isArray(b?.warnings)?b.warnings:[]}let c=await Da(e,t,r,n);if(!s)return{...c,warnings:[...Array.isArray(c?.warnings)?c.warnings:[],...u],listStructuralFallbackApplied:!1};if(l)return{...c,warnings:[...Array.isArray(c?.warnings)?c.warnings:[],...u],listStructuralFallbackApplied:!1};if(c?.hasChanges)return{...c,listStructuralFallbackApplied:!1};let f=await Jr(s,{author:n.author,generateRedlines:n.generateRedlines,pipeline:n.listFallbackPipeline});if(!f?.hasChanges||!f?.oxml){let b=Array.isArray(c?.warnings)?c.warnings:[],w=Array.isArray(f?.warnings)?f.warnings:[];return{...c,warnings:[...b,...w],listStructuralFallbackApplied:!1}}let m=et(f.oxml,{includeNumbering:f.includeNumbering??!0,numberingXml:f.numberingXml}),d=Array.isArray(c?.warnings)?c.warnings:[],p=Array.isArray(f?.warnings)?f.warnings:[];return de({...c,oxml:m,hasChanges:!0,warnings:[...d,...u,...p],listStructuralFallbackApplied:!0,listStructuralFallbackKey:f.listStructuralFallbackKey||null,listStructuralFallbackNumberingXml:f.numberingXml||null})}export{Nt as ContainerKind,Co as ContentType,Oe as DiffOp,S as NS_W,Ge as NumberingService,go as ReceiptCollector,er as ReconciliationPipeline,Ut as RoutePlanKind,B as RunKind,Ce as WORD_MAIN_NS,jn as acceptTrackedChangesInOoxml,_r as analyzeStructuredContent,du as applyCommentReplyToParts,pu as applyFormattingRemovalToOoxml,wu as applyHighlightToOoxml,Da as applyRedlineToOxml,hh as applyRedlineToOxmlWithListFallback,Jc as areRevisionTokensEqual,dr as buildCommentElement,so as buildCommentsPartXml,Bc as buildExplicitDecimalMultilevelNumberingXml,oc as buildListMarkdown,Pu as buildReconciliationPlan,oo as buildRevisionTokenFraming,Qn as buildSingleLineListStructuralFallbackPlan,ql as buildTargetReferenceSnapshot,fc as clearSingleLineListFallbackExplicitSequence,ra as collectContiguousListParagraphBlock,Kc as computeDocumentPartsRevisionToken,ga as computeRevisionToken,io as computeRevisionTokenSync,Ja as configureLogger,qa as configureXmlProvider,Mr as containsTrackedChanges,Cc as createDynamicNumberingIdState,Cu as createEmptyReceipt,kt as createParagraphFingerprint,Ul as deleteCommentsByAuthorInOoxml,mc as enforceListBindingOnParagraphNodes,Eu as ensureCommentsArtifactsInZip,Iu as ensureCommentsExtendedArtifactsInZip,Su as ensureNumberingArtifactsInZip,we as escapeXml,Jr as executeSingleLineListStructuralFallback,ye as extractCanonicalParagraphText,Qr as extractDocumentPartsEntries,Lc as extractFirstParagraphNumId,Ru as extractParagraphIdFromOoxml,Xr as extractParagraphRevisionSegments,Tu as extractReplacementNodesFromOoxml,Mt as findContainingWordElement,Kn as findParagraphByBestTextMatch,Ji as findParagraphByReference,Hr as findParagraphByStrictText,Vr as findStrictTargetCandidates,ut as generateTableOoxml,fo as getBodyElementFromDocument,me as getDefaultAuthor,Te as getDocumentParagraphNodes,uo as getPackagePartName,wt as getParagraphId,qe as getParagraphListInfo,le as getParagraphText,mn as getPlatform,In as getTrackedChangeAuthors,Zn as hasListItems,Kt as inferNumberingStyleFromMarker,Pc as inferTableReplacementParagraphBlock,Et as ingestOoxml,Gc as ingestWordOoxmlToMarkdown,da as ingestWordOoxmlToMarkdownResult,Vc as ingestWordOoxmlToPlainText,ma as ingestWordOoxmlToPlainTextResult,uu as injectCommentsIntoOoxml,fu as injectCommentsIntoPackage,Nu as insertBodyElementBeforeSectPr,lu as inspectDocumentParts,aa as isLikelyStructuredTableSourceParagraph,Jn as isMarkdownTableText,mt as isNodeVisibleInRevisionView,$c as mergeNumberingXmlBySchemaOrder,Fa as normalizeBodySectionOrderStandalone,Xa as normalizeContentEscapesForRouting,ic as normalizeListItemsWithLevels,pa as normalizeOpcEntryName,U as normalizeWhitespaceForTargeting,_c as overwriteParagraphNumIds,cr as parseMarkdownListContent,Je as parseOoxml,W as parseOoxmlSafe,qn as parseParagraphReference,nc as planListInsertionOnlyEdit,il as planStructuredReplacement,Ee as preprocessMarkdown,dt as readCanonicalRunText,gh as reconcileMarkdownTableOoxml,Ou as reconcileReceiptsAgainstOutput,uc as recordSingleLineListFallbackExplicitSequence,Hn as rejectTrackedChangesInOoxml,Fc as remapNumberingPayloadForDocument,Pa as removeFormattingFromRPr,fr as reserveNextNumberingId,kc as reserveNextNumberingIdPair,Zl as resolveParagraphRangeByRefs,cc as resolveSingleLineListFallbackNumberingAction,qi as resolveTargetParagraph,Yn as resolveTargetParagraphWithSnapshot,Gn as sanitizeAiResponse,vu as sanitizeNestedParagraphsInTables,ht as serializeOoxml,Fe as serializeToOoxml,es as setDefaultAuthor,ts as setPlatform,Gl as splitLeadingParagraphMarker,Vl as stripLeadingParagraphMarker,ea as stripRedundantLeadingListMarkers,sc as stripSingleLineListMarkerPrefix,rc as synthesizeExpandedListScopeEdit,Rc as synthesizeTableMarkdownFromMultilineCellEdit,Au as validateDocxPackage,Tc as validateRedlineOoxml,Yc as validateRevisionToken,et as wrapInDocumentFragment};
200
211
  //# sourceMappingURL=docx-redline-js.esm.min.js.map