@ansonlai/docx-redline-js 0.2.0 → 0.4.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.
- package/AGENTS.md +36 -10
- package/README.md +83 -6
- package/adapters/xml-adapter.js +73 -10
- package/core/list-targeting.js +3 -0
- package/core/paragraph-targeting.js +33 -7
- package/core/redline-validation.js +22 -0
- package/core/types.js +122 -27
- package/core/xml-query.js +3 -1
- package/dist/docx-redline-js.esm.js +1148 -572
- package/dist/docx-redline-js.esm.js.map +4 -4
- package/dist/docx-redline-js.esm.min.js +79 -78
- package/dist/docx-redline-js.esm.min.js.map +4 -4
- package/docs/TESTING.md +687 -0
- package/docs/VALIDATION.md +81 -2
- package/docs/WORD-MANUAL-REVIEW.md +138 -0
- package/docs/plans/2026-08-30-reliability-testing-improvements.md +488 -0
- package/docs/plans/2026-09-01-performance-and-complexity-reduction.md +210 -0
- package/docs/plans/{2026-03-01-release-0.1.4-design.md → completed/2026-03-01-release-0.1.4-design.md} +2 -0
- package/docs/plans/{2026-03-01-release-0.1.4.md → completed/2026-03-01-release-0.1.4.md} +5 -3
- package/docs/plans/{2026-05-31-architectural changes.md → completed/2026-05-31-architectural changes.md } +2 -0
- package/docs/plans/completed/2026-08-02-reliability-improvements.md +1155 -0
- package/docs/test-comparison-dashboard.html +95 -0
- package/docs/validation-reports/2026-08-30-phase-1-word-visual-preflight.md +22 -0
- package/docs/validation-reports/2026-08-30-phase-2-word-visual-preflight.md +24 -0
- package/docs/validation-reports/2026-08-30-phase-3-coverage.md +73 -0
- package/docs/validation-reports/2026-09-02-multilevel-bullets-visual-review.md +82 -0
- package/docs/validation-reports/2026-09-02-multimodal-visual-samples.md +114 -0
- package/docs/validation-reports/2026-09-02-visual-failures-preflight.md +79 -0
- package/engine/format-extraction.js +1 -1
- package/engine/formatting-removal.js +95 -104
- package/engine/oxml-engine.js +176 -83
- package/engine/reconstruction-mapper.js +276 -79
- package/engine/reconstruction-mode.js +20 -6
- package/engine/reconstruction-writer.js +117 -72
- package/engine/run-builders.js +17 -13
- package/engine/surgical-diff-application.js +7 -21
- package/engine/surgical-mode.js +3 -2
- package/engine/table-mode.js +27 -16
- package/index.d.ts +95 -3
- package/index.js +14 -13
- package/orchestration/list-structural-fallback.js +16 -39
- package/package.json +23 -5
- package/pipeline/diff-engine.js +174 -55
- package/pipeline/ingestion-export.js +39 -24
- package/pipeline/ingestion-paragraph.js +7 -5
- package/pipeline/list-generation.js +27 -18
- package/pipeline/patching.js +2 -3
- package/pipeline/pipeline.js +65 -36
- package/pipeline/serialization.js +13 -5
- package/scripts/build-test-dashboard.mjs +43 -0
- package/scripts/check-types.mjs +16 -24
- package/scripts/export-validation-fixtures.mjs +191 -45
- package/scripts/fetch-superdoc-corpus.mjs +61 -0
- package/scripts/generate-test-dashboard.mjs +199 -0
- package/scripts/inspect-visual-evidence.mjs +271 -0
- package/scripts/lib/minimal-zip.mjs +199 -18
- package/scripts/lib/word-coverage-catalogue.mjs +207 -0
- package/scripts/lib/word-coverage-metadata.mjs +93 -0
- package/scripts/lib/zip-reader.mjs +64 -0
- package/scripts/package-superdoc-word-fixtures.ps1 +64 -0
- package/scripts/prepare-corpus-word-visual-review.mjs +84 -0
- package/scripts/prepare-superdoc-word-corpus.mjs +284 -0
- package/scripts/prepare-word-review.mjs +77 -0
- package/scripts/prepare-word-visual-review.mjs +90 -0
- package/scripts/render-agenda-multilevel.mjs +70 -0
- package/scripts/render-case22.mjs +73 -0
- package/scripts/render-case40.ps1 +35 -0
- package/scripts/render-multilevel-bullet-images.py +58 -0
- package/scripts/render-multilevel-bullet-visual.ps1 +32 -0
- package/scripts/render-multilevel-cases.mjs +80 -0
- package/scripts/report-coverage-gaps.mjs +103 -0
- package/scripts/report-word-coverage.mjs +71 -0
- package/scripts/sample-multimodal-visual-check.mjs +221 -0
- package/scripts/test-multilevel-bullet-visual.mjs +187 -0
- package/scripts/word-com-corpus-suite.ps1 +43 -0
- package/scripts/word-com-corpus-visual-suite.ps1 +116 -0
- package/scripts/word-com-differential.ps1 +158 -16
- package/scripts/word-com-suite.ps1 +19 -0
- package/scripts/word-com-visual-suite.ps1 +132 -0
- package/services/comment-engine.js +51 -46
- package/services/comment-locator.js +0 -1
- package/services/comment-package.js +11 -10
- package/services/numbering-service.js +1 -1
- package/services/revision-comment-management.js +31 -10
- package/services/standalone-docx-plumbing.js +45 -34
- package/services/standalone-operation-runner.js +315 -75
- package/services/table-reconciliation.js +23 -11
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
`,u),m==-1&&(m=l.length-1);var p=l.substring(u,m+1);(n.hasOwnProperty?n.hasOwnProperty(p):n[p]!==void 0)?c+=String.fromCharCode(n[p]):(f==o&&(p=l.substring(u),m=l.length),c+=String.fromCharCode(f),n[p]=f,r[f++]=p),u=m+1}return c}var o=4e4,i=a(e);o=65535;var s=a(t);return{chars1:i,chars2:s,lineArray:r}};T.prototype.diff_charsToLines_=function(e,t){for(var r=0;r<e.length;r++){for(var n=e[r][1],a=[],o=0;o<n.length;o++)a[o]=t[n.charCodeAt(o)];e[r][1]=a.join("")}};T.prototype.diff_commonPrefix=function(e,t){if(!e||!t||e.charAt(0)!=t.charAt(0))return 0;for(var r=0,n=Math.min(e.length,t.length),a=n,o=0;r<a;)e.substring(o,a)==t.substring(o,a)?(r=a,o=r):n=a,a=Math.floor((n-r)/2+r);return a};T.prototype.diff_commonSuffix=function(e,t){if(!e||!t||e.charAt(e.length-1)!=t.charAt(t.length-1))return 0;for(var r=0,n=Math.min(e.length,t.length),a=n,o=0;r<a;)e.substring(e.length-a,e.length-o)==t.substring(t.length-a,t.length-o)?(r=a,o=r):n=a,a=Math.floor((n-r)/2+r);return a};T.prototype.diff_commonOverlap_=function(e,t){var r=e.length,n=t.length;if(r==0||n==0)return 0;r>n?e=e.substring(r-n):r<n&&(t=t.substring(0,r));var a=Math.min(r,n);if(e==t)return a;for(var o=0,i=1;;){var s=e.substring(a-i),l=t.indexOf(s);if(l==-1)return o;i+=l,(l==0||e.substring(a-i)==t.substring(0,i))&&(o=i,i++)}};T.prototype.diff_halfMatch_=function(e,t){if(this.Diff_Timeout<=0)return null;var r=e.length>t.length?e:t,n=e.length>t.length?t:e;if(r.length<4||n.length*2<r.length)return null;var a=this;function o(g,d,w){for(var h=g.substring(w,w+Math.floor(g.length/4)),b=-1,x="",E,v,P,N;(b=d.indexOf(h,b+1))!=-1;){var y=a.diff_commonPrefix(g.substring(w),d.substring(b)),I=a.diff_commonSuffix(g.substring(0,w),d.substring(0,b));x.length<I+y&&(x=d.substring(b-I,b)+d.substring(b,b+y),E=g.substring(0,w-I),v=g.substring(w+y),P=d.substring(0,b-I),N=d.substring(b+y))}return x.length*2>=g.length?[E,v,P,N,x]:null}var i=o(r,n,Math.ceil(r.length/4)),s=o(r,n,Math.ceil(r.length/2)),l;if(!i&&!s)return null;s?i?l=i[4].length>s[4].length?i:s:l=s:l=i;var c,u,m,f;e.length>t.length?(c=l[0],u=l[1],m=l[2],f=l[3]):(m=l[0],f=l[1],c=l[2],u=l[3]);var p=l[4];return[c,u,m,f,p]};T.prototype.diff_cleanupSemantic=function(e){for(var t=!1,r=[],n=0,a=null,o=0,i=0,s=0,l=0,c=0;o<e.length;)e[o][0]==k?(r[n++]=o,i=l,s=c,l=0,c=0,a=e[o][1]):(e[o][0]==W?l+=e[o][1].length:c+=e[o][1].length,a&&a.length<=Math.max(i,s)&&a.length<=Math.max(l,c)&&(e.splice(r[n-1],0,new T.Diff(D,a)),e[r[n-1]+1][0]=W,n--,n--,o=n>0?r[n-1]:-1,i=0,s=0,l=0,c=0,a=null,t=!0)),o++;for(t&&this.diff_cleanupMerge(e),this.diff_cleanupSemanticLossless(e),o=1;o<e.length;){if(e[o-1][0]==D&&e[o][0]==W){var u=e[o-1][1],m=e[o][1],f=this.diff_commonOverlap_(u,m),p=this.diff_commonOverlap_(m,u);f>=p?(f>=u.length/2||f>=m.length/2)&&(e.splice(o,0,new T.Diff(k,m.substring(0,f))),e[o-1][1]=u.substring(0,u.length-f),e[o+1][1]=m.substring(f),o++):(p>=u.length/2||p>=m.length/2)&&(e.splice(o,0,new T.Diff(k,u.substring(0,p))),e[o-1][0]=W,e[o-1][1]=m.substring(0,m.length-p),e[o+1][0]=D,e[o+1][1]=u.substring(p),o++),o++}o++}};T.prototype.diff_cleanupSemanticLossless=function(e){function t(p,g){if(!p||!g)return 6;var d=p.charAt(p.length-1),w=g.charAt(0),h=d.match(T.nonAlphaNumericRegex_),b=w.match(T.nonAlphaNumericRegex_),x=h&&d.match(T.whitespaceRegex_),E=b&&w.match(T.whitespaceRegex_),v=x&&d.match(T.linebreakRegex_),P=E&&w.match(T.linebreakRegex_),N=v&&p.match(T.blanklineEndRegex_),y=P&&g.match(T.blanklineStartRegex_);return N||y?5:v||P?4:h&&!x&&E?3:x||E?2:h||b?1:0}for(var r=1;r<e.length-1;){if(e[r-1][0]==k&&e[r+1][0]==k){var n=e[r-1][1],a=e[r][1],o=e[r+1][1],i=this.diff_commonSuffix(n,a);if(i){var s=a.substring(a.length-i);n=n.substring(0,n.length-i),a=s+a.substring(0,a.length-i),o=s+o}for(var l=n,c=a,u=o,m=t(n,a)+t(a,o);a.charAt(0)===o.charAt(0);){n+=a.charAt(0),a=a.substring(1)+o.charAt(0),o=o.substring(1);var f=t(n,a)+t(a,o);f>=m&&(m=f,l=n,c=a,u=o)}e[r-1][1]!=l&&(l?e[r-1][1]=l:(e.splice(r-1,1),r--),e[r][1]=c,u?e[r+1][1]=u:(e.splice(r+1,1),r--))}r++}};T.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/;T.whitespaceRegex_=/\s/;T.linebreakRegex_=/[\r\n]/;T.blanklineEndRegex_=/\n\r?\n$/;T.blanklineStartRegex_=/^\r?\n\r?\n/;T.prototype.diff_cleanupEfficiency=function(e){for(var t=!1,r=[],n=0,a=null,o=0,i=!1,s=!1,l=!1,c=!1;o<e.length;)e[o][0]==k?(e[o][1].length<this.Diff_EditCost&&(l||c)?(r[n++]=o,i=l,s=c,a=e[o][1]):(n=0,a=null),l=c=!1):(e[o][0]==D?c=!0:l=!0,a&&(i&&s&&l&&c||a.length<this.Diff_EditCost/2&&i+s+l+c==3)&&(e.splice(r[n-1],0,new T.Diff(D,a)),e[r[n-1]+1][0]=W,n--,a=null,i&&s?(l=c=!0,n=0):(n--,o=n>0?r[n-1]:-1,l=c=!1),t=!0)),o++;t&&this.diff_cleanupMerge(e)};T.prototype.diff_cleanupMerge=function(e){e.push(new T.Diff(k,""));for(var t=0,r=0,n=0,a="",o="",i;t<e.length;)switch(e[t][0]){case W:n++,o+=e[t][1],t++;break;case D:r++,a+=e[t][1],t++;break;case k:r+n>1?(r!==0&&n!==0&&(i=this.diff_commonPrefix(o,a),i!==0&&(t-r-n>0&&e[t-r-n-1][0]==k?e[t-r-n-1][1]+=o.substring(0,i):(e.splice(0,0,new T.Diff(k,o.substring(0,i))),t++),o=o.substring(i),a=a.substring(i)),i=this.diff_commonSuffix(o,a),i!==0&&(e[t][1]=o.substring(o.length-i)+e[t][1],o=o.substring(0,o.length-i),a=a.substring(0,a.length-i))),t-=r+n,e.splice(t,r+n),a.length&&(e.splice(t,0,new T.Diff(D,a)),t++),o.length&&(e.splice(t,0,new T.Diff(W,o)),t++),t++):t!==0&&e[t-1][0]==k?(e[t-1][1]+=e[t][1],e.splice(t,1)):t++,n=0,r=0,a="",o="";break}e[e.length-1][1]===""&&e.pop();var s=!1;for(t=1;t<e.length-1;)e[t-1][0]==k&&e[t+1][0]==k&&(e[t][1].substring(e[t][1].length-e[t-1][1].length)==e[t-1][1]?(e[t][1]=e[t-1][1]+e[t][1].substring(0,e[t][1].length-e[t-1][1].length),e[t+1][1]=e[t-1][1]+e[t+1][1],e.splice(t-1,1),s=!0):e[t][1].substring(0,e[t+1][1].length)==e[t+1][1]&&(e[t-1][1]+=e[t+1][1],e[t][1]=e[t][1].substring(e[t+1][1].length)+e[t+1][1],e.splice(t+1,1),s=!0)),t++;s&&this.diff_cleanupMerge(e)};T.prototype.diff_xIndex=function(e,t){var r=0,n=0,a=0,o=0,i;for(i=0;i<e.length&&(e[i][0]!==W&&(r+=e[i][1].length),e[i][0]!==D&&(n+=e[i][1].length),!(r>t));i++)a=r,o=n;return e.length!=i&&e[i][0]===D?o:o+(t-a)};T.prototype.diff_prettyHtml=function(e){for(var t=[],r=/&/g,n=/</g,a=/>/g,o=/\n/g,i=0;i<e.length;i++){var s=e[i][0],l=e[i][1],c=l.replace(r,"&").replace(n,"<").replace(a,">").replace(o,"¶<br>");switch(s){case W:t[i]='<ins style="background:#e6ffe6;">'+c+"</ins>";break;case D:t[i]='<del style="background:#ffe6e6;">'+c+"</del>";break;case k:t[i]="<span>"+c+"</span>";break}}return t.join("")};T.prototype.diff_text1=function(e){for(var t=[],r=0;r<e.length;r++)e[r][0]!==W&&(t[r]=e[r][1]);return t.join("")};T.prototype.diff_text2=function(e){for(var t=[],r=0;r<e.length;r++)e[r][0]!==D&&(t[r]=e[r][1]);return t.join("")};T.prototype.diff_levenshtein=function(e){for(var t=0,r=0,n=0,a=0;a<e.length;a++){var o=e[a][0],i=e[a][1];switch(o){case W:r+=i.length;break;case D:n+=i.length;break;case k:t+=Math.max(r,n),r=0,n=0;break}}return t+=Math.max(r,n),t};T.prototype.diff_toDelta=function(e){for(var t=[],r=0;r<e.length;r++)switch(e[r][0]){case W:t[r]="+"+encodeURI(e[r][1]);break;case D:t[r]="-"+e[r][1].length;break;case k:t[r]="="+e[r][1].length;break}return t.join(" ").replace(/%20/g," ")};T.prototype.diff_fromDelta=function(e,t){for(var r=[],n=0,a=0,o=t.split(/\t/g),i=0;i<o.length;i++){var s=o[i].substring(1);switch(o[i].charAt(0)){case"+":try{r[n++]=new T.Diff(W,decodeURI(s))}catch{throw new Error("Illegal escape in diff_fromDelta: "+s)}break;case"-":case"=":var l=parseInt(s,10);if(isNaN(l)||l<0)throw new Error("Invalid number in diff_fromDelta: "+s);var c=e.substring(a,a+=l);o[i].charAt(0)=="="?r[n++]=new T.Diff(k,c):r[n++]=new T.Diff(D,c);break;default:if(o[i])throw new Error("Invalid diff operation in diff_fromDelta: "+o[i])}}if(a!=e.length)throw new Error("Delta length ("+a+") does not equal source text length ("+e.length+").");return r};T.prototype.match_main=function(e,t,r){if(e==null||t==null||r==null)throw new Error("Null input. (match_main)");return r=Math.max(0,Math.min(r,e.length)),e==t?0:e.length?e.substring(r,r+t.length)==t?r:this.match_bitap_(e,t,r):-1};T.prototype.match_bitap_=function(e,t,r){if(t.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var n=this.match_alphabet_(t),a=this;function o(E,v){var P=E/t.length,N=Math.abs(r-v);return a.Match_Distance?P+N/a.Match_Distance:N?1:P}var i=this.Match_Threshold,s=e.indexOf(t,r);s!=-1&&(i=Math.min(o(0,s),i),s=e.lastIndexOf(t,r+t.length),s!=-1&&(i=Math.min(o(0,s),i)));var l=1<<t.length-1;s=-1;for(var c,u,m=t.length+e.length,f,p=0;p<t.length;p++){for(c=0,u=m;c<u;)o(p,r+u)<=i?c=u:m=u,u=Math.floor((m-c)/2+c);m=u;var g=Math.max(1,r-u+1),d=Math.min(r+u,e.length)+t.length,w=Array(d+2);w[d+1]=(1<<p)-1;for(var h=d;h>=g;h--){var b=n[e.charAt(h-1)];if(p===0?w[h]=(w[h+1]<<1|1)&b:w[h]=(w[h+1]<<1|1)&b|((f[h+1]|f[h])<<1|1)|f[h+1],w[h]&l){var x=o(p,h-1);if(x<=i)if(i=x,s=h-1,s>r)g=Math.max(1,2*r-s);else break}}if(o(p+1,r)>i)break;f=w}return s};T.prototype.match_alphabet_=function(e){for(var t={},r=0;r<e.length;r++)t[e.charAt(r)]=0;for(var r=0;r<e.length;r++)t[e.charAt(r)]|=1<<e.length-r-1;return t};T.prototype.patch_addContext_=function(e,t){if(t.length!=0){if(e.start2===null)throw Error("patch not initialized");for(var r=t.substring(e.start2,e.start2+e.length1),n=0;t.indexOf(r)!=t.lastIndexOf(r)&&r.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)n+=this.Patch_Margin,r=t.substring(e.start2-n,e.start2+e.length1+n);n+=this.Patch_Margin;var a=t.substring(e.start2-n,e.start2);a&&e.diffs.unshift(new T.Diff(k,a));var o=t.substring(e.start2+e.length1,e.start2+e.length1+n);o&&e.diffs.push(new T.Diff(k,o)),e.start1-=a.length,e.start2-=a.length,e.length1+=a.length+o.length,e.length2+=a.length+o.length}};T.prototype.patch_make=function(e,t,r){var n,a;if(typeof e=="string"&&typeof t=="string"&&typeof r>"u")n=e,a=this.diff_main(n,t,!0),a.length>2&&(this.diff_cleanupSemantic(a),this.diff_cleanupEfficiency(a));else if(e&&typeof e=="object"&&typeof t>"u"&&typeof r>"u")a=e,n=this.diff_text1(a);else if(typeof e=="string"&&t&&typeof t=="object"&&typeof r>"u")n=e,a=t;else if(typeof e=="string"&&typeof t=="string"&&r&&typeof r=="object")n=e,a=r;else throw new Error("Unknown call format to patch_make.");if(a.length===0)return[];for(var o=[],i=new T.patch_obj,s=0,l=0,c=0,u=n,m=n,f=0;f<a.length;f++){var p=a[f][0],g=a[f][1];switch(!s&&p!==k&&(i.start1=l,i.start2=c),p){case W:i.diffs[s++]=a[f],i.length2+=g.length,m=m.substring(0,c)+g+m.substring(c);break;case D:i.length1+=g.length,i.diffs[s++]=a[f],m=m.substring(0,c)+m.substring(c+g.length);break;case k:g.length<=2*this.Patch_Margin&&s&&a.length!=f+1?(i.diffs[s++]=a[f],i.length1+=g.length,i.length2+=g.length):g.length>=2*this.Patch_Margin&&s&&(this.patch_addContext_(i,u),o.push(i),i=new T.patch_obj,s=0,u=m,l=c);break}p!==W&&(l+=g.length),p!==D&&(c+=g.length)}return s&&(this.patch_addContext_(i,u),o.push(i)),o};T.prototype.patch_deepCopy=function(e){for(var t=[],r=0;r<e.length;r++){var n=e[r],a=new T.patch_obj;a.diffs=[];for(var o=0;o<n.diffs.length;o++)a.diffs[o]=new T.Diff(n.diffs[o][0],n.diffs[o][1]);a.start1=n.start1,a.start2=n.start2,a.length1=n.length1,a.length2=n.length2,t[r]=a}return t};T.prototype.patch_apply=function(e,t){if(e.length==0)return[t,[]];e=this.patch_deepCopy(e);var r=this.patch_addPadding(e);t=r+t+r,this.patch_splitMax(e);for(var n=0,a=[],o=0;o<e.length;o++){var i=e[o].start2+n,s=this.diff_text1(e[o].diffs),l,c=-1;if(s.length>this.Match_MaxBits?(l=this.match_main(t,s.substring(0,this.Match_MaxBits),i),l!=-1&&(c=this.match_main(t,s.substring(s.length-this.Match_MaxBits),i+s.length-this.Match_MaxBits),(c==-1||l>=c)&&(l=-1))):l=this.match_main(t,s,i),l==-1)a[o]=!1,n-=e[o].length2-e[o].length1;else{a[o]=!0,n=l-i;var u;if(c==-1?u=t.substring(l,l+s.length):u=t.substring(l,c+this.Match_MaxBits),s==u)t=t.substring(0,l)+this.diff_text2(e[o].diffs)+t.substring(l+s.length);else{var m=this.diff_main(s,u,!1);if(s.length>this.Match_MaxBits&&this.diff_levenshtein(m)/s.length>this.Patch_DeleteThreshold)a[o]=!1;else{this.diff_cleanupSemanticLossless(m);for(var f=0,p,g=0;g<e[o].diffs.length;g++){var d=e[o].diffs[g];d[0]!==k&&(p=this.diff_xIndex(m,f)),d[0]===W?t=t.substring(0,l+p)+d[1]+t.substring(l+p):d[0]===D&&(t=t.substring(0,l+p)+t.substring(l+this.diff_xIndex(m,f+d[1].length))),d[0]!==D&&(f+=d[1].length)}}}}}return t=t.substring(r.length,t.length-r.length),[t,a]};T.prototype.patch_addPadding=function(e){for(var t=this.Patch_Margin,r="",n=1;n<=t;n++)r+=String.fromCharCode(n);for(var n=0;n<e.length;n++)e[n].start1+=t,e[n].start2+=t;var a=e[0],o=a.diffs;if(o.length==0||o[0][0]!=k)o.unshift(new T.Diff(k,r)),a.start1-=t,a.start2-=t,a.length1+=t,a.length2+=t;else if(t>o[0][1].length){var i=t-o[0][1].length;o[0][1]=r.substring(o[0][1].length)+o[0][1],a.start1-=i,a.start2-=i,a.length1+=i,a.length2+=i}if(a=e[e.length-1],o=a.diffs,o.length==0||o[o.length-1][0]!=k)o.push(new T.Diff(k,r)),a.length1+=t,a.length2+=t;else if(t>o[o.length-1][1].length){var i=t-o[o.length-1][1].length;o[o.length-1][1]+=r.substring(0,i),a.length1+=i,a.length2+=i}return r};T.prototype.patch_splitMax=function(e){for(var t=this.Match_MaxBits,r=0;r<e.length;r++)if(!(e[r].length1<=t)){var n=e[r];e.splice(r--,1);for(var a=n.start1,o=n.start2,i="";n.diffs.length!==0;){var s=new T.patch_obj,l=!0;for(s.start1=a-i.length,s.start2=o-i.length,i!==""&&(s.length1=s.length2=i.length,s.diffs.push(new T.Diff(k,i)));n.diffs.length!==0&&s.length1<t-this.Patch_Margin;){var c=n.diffs[0][0],u=n.diffs[0][1];c===W?(s.length2+=u.length,o+=u.length,s.diffs.push(n.diffs.shift()),l=!1):c===D&&s.diffs.length==1&&s.diffs[0][0]==k&&u.length>2*t?(s.length1+=u.length,a+=u.length,l=!1,s.diffs.push(new T.Diff(c,u)),n.diffs.shift()):(u=u.substring(0,t-s.length1-this.Patch_Margin),s.length1+=u.length,a+=u.length,c===k?(s.length2+=u.length,o+=u.length):l=!1,s.diffs.push(new T.Diff(c,u)),u==n.diffs[0][1]?n.diffs.shift():n.diffs[0][1]=n.diffs[0][1].substring(u.length))}i=this.diff_text2(s.diffs),i=i.substring(i.length-this.Patch_Margin);var m=this.diff_text1(n.diffs).substring(0,this.Patch_Margin);m!==""&&(s.length1+=m.length,s.length2+=m.length,s.diffs.length!==0&&s.diffs[s.diffs.length-1][0]===k?s.diffs[s.diffs.length-1][1]+=m:s.diffs.push(new T.Diff(k,m))),l||e.splice(++r,0,s)}}};T.prototype.patch_toText=function(e){for(var t=[],r=0;r<e.length;r++)t[r]=e[r];return t.join("")};T.prototype.patch_fromText=function(e){var t=[];if(!e)return t;for(var r=e.split(`
|
|
3
|
-
`),n=0,
|
|
4
|
-
`],n,
|
|
5
|
-
`}return r.join("").replace(/%20/g," ")};
|
|
6
|
-
`)&&
|
|
7
|
-
`)&&
|
|
8
|
-
|
|
9
|
-
`:i.endsWith(":tab")||i==="tab"?
|
|
10
|
-
`)},
|
|
11
|
-
`)}}function
|
|
12
|
-
`),
|
|
13
|
-
<w:numbering xmlns:w="${
|
|
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,"&").replace(n,"<").replace(o,">").replace(a,"¶<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:/<b>(.+?)<\/b>/i,format:{bold:!0},isEscaped:!0},{regex:/<strong>(.+?)<\/strong>/i,format:{bold:!0},isEscaped:!0},{regex:/<i>(.+?)<\/i>/i,format:{italic:!0},isEscaped:!0},{regex:/<em>(.+?)<\/em>/i,format:{italic:!0},isEscaped:!0},{regex:/<u>(.+?)<\/u>/i,format:{underline:!0},isEscaped:!0},{regex:/<s>(.+?)<\/s>/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(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"):""}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}">
|
|
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="•"/><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 Ya=Object.create;var qr=Object.defineProperty;var Za=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
|
|
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`
|
|
23
23
|
<pkg:part pkg:name="/word/numbering.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml">
|
|
24
24
|
<pkg:xmlData>
|
|
25
|
-
${
|
|
25
|
+
${Ei(e)}
|
|
26
26
|
</pkg:xmlData>
|
|
27
|
-
</pkg:part>`}function
|
|
28
|
-
<pkg:package xmlns:pkg="${
|
|
27
|
+
</pkg:part>`}function Gn(e,t="",r=""){return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
28
|
+
<pkg:package xmlns:pkg="${Ni}">
|
|
29
29
|
<pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml">
|
|
30
30
|
<pkg:xmlData>
|
|
31
|
-
<Relationships xmlns="${
|
|
32
|
-
${
|
|
31
|
+
<Relationships xmlns="${zn}">
|
|
32
|
+
${vi}
|
|
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="${
|
|
38
|
+
<Relationships xmlns="${zn}">
|
|
39
39
|
${t}
|
|
40
40
|
</Relationships>
|
|
41
41
|
</pkg:xmlData>
|
|
@@ -45,7 +45,7 @@ var Ya=Object.create;var qr=Object.defineProperty;var Za=Object.getOwnPropertyDe
|
|
|
45
45
|
${e}
|
|
46
46
|
</pkg:xmlData>
|
|
47
47
|
</pkg:part>
|
|
48
|
-
</pkg:package>`}function
|
|
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`
|
|
49
49
|
<w:pPr>${n.includeListParagraphStyle===!0?`
|
|
50
50
|
<w:pStyle w:val="ListParagraph"/>`:""}
|
|
51
51
|
<w:numPr>
|
|
@@ -64,7 +64,7 @@ var Ya=Object.create;var qr=Object.defineProperty;var Za=Object.getOwnPropertyDe
|
|
|
64
64
|
<w:lvlJc w:val="left"/>
|
|
65
65
|
<w:pPr><w:ind w:left="${720*(l+1)}" w:hanging="360"/></w:pPr>
|
|
66
66
|
</w:lvl>`).join("")}
|
|
67
|
-
</w:abstractNum>`,
|
|
67
|
+
</w:abstractNum>`,o=`
|
|
68
68
|
<w:abstractNum w:abstractNumId="1">
|
|
69
69
|
<w:multiLevelType w:val="multilevel"/>
|
|
70
70
|
<w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1."/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr></w:lvl>
|
|
@@ -72,7 +72,7 @@ var Ya=Object.create;var qr=Object.defineProperty;var Za=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>`,
|
|
75
|
+
</w:abstractNum>`,a=`
|
|
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>
|
|
@@ -83,13 +83,13 @@ var Ya=Object.create;var qr=Object.defineProperty;var Za=Object.getOwnPropertyDe
|
|
|
83
83
|
</w:abstractNum>`,i="",s="";return r.forEach((l,c)=>{let u=10+c;i+=`
|
|
84
84
|
<w:abstractNum w:abstractNumId="${u}">
|
|
85
85
|
<w:multiLevelType w:val="multilevel"/>
|
|
86
|
-
${l.levels.map((m
|
|
87
|
-
<w:lvl w:ilvl="${
|
|
86
|
+
${l.levels.map((f,m)=>`
|
|
87
|
+
<w:lvl w:ilvl="${m}">
|
|
88
88
|
<w:start w:val="1"/>
|
|
89
|
-
<w:numFmt w:val="${this.formatToOoxmlNumFmt(
|
|
90
|
-
<w:lvlText w:val="${this.suffixToOoxmlLevelText(
|
|
89
|
+
<w:numFmt w:val="${this.formatToOoxmlNumFmt(f.format)}"/>
|
|
90
|
+
<w:lvlText w:val="${this.suffixToOoxmlLevelText(f.format,f.suffix,m)}"/>
|
|
91
91
|
<w:lvlJc w:val="left"/>
|
|
92
|
-
<w:pPr><w:ind w:left="${720*(
|
|
92
|
+
<w:pPr><w:ind w:left="${720*(m+1)}" w:hanging="360"/></w:pPr>
|
|
93
93
|
</w:lvl>`).join("")}
|
|
94
94
|
</w:abstractNum>`,s+=`
|
|
95
95
|
<w:num w:numId="${l.numId}">
|
|
@@ -97,8 +97,8 @@ var Ya=Object.create;var qr=Object.defineProperty;var Za=Object.getOwnPropertyDe
|
|
|
97
97
|
</w:num>`}),`
|
|
98
98
|
<w:numbering xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
|
99
99
|
${n}
|
|
100
|
-
${a}
|
|
101
100
|
${o}
|
|
101
|
+
${a}
|
|
102
102
|
${i}
|
|
103
103
|
<w:num w:numId="1">
|
|
104
104
|
<w:abstractNumId w:val="0"/>
|
|
@@ -110,7 +110,7 @@ var Ya=Object.create;var qr=Object.defineProperty;var Za=Object.getOwnPropertyDe
|
|
|
110
110
|
<w:abstractNumId w:val="2"/>
|
|
111
111
|
</w:num>
|
|
112
112
|
${s}
|
|
113
|
-
</w:numbering>`}};function
|
|
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=`
|
|
114
114
|
<w:tblPr>
|
|
115
115
|
<w:tblW w:w="5000" w:type="pct"/>
|
|
116
116
|
<w:tblBorders>
|
|
@@ -123,42 +123,43 @@ var Ya=Object.create;var qr=Object.defineProperty;var Za=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(),
|
|
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`
|
|
127
127
|
<w:tbl>
|
|
128
128
|
${e.tblPrXml}
|
|
129
129
|
${e.tblGridXml}
|
|
130
|
-
${
|
|
130
|
+
${s}
|
|
131
131
|
</w:tbl>
|
|
132
|
-
`}function
|
|
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),
|
|
134
|
-
`).filter(t=>t.trim().length>0).map(t=>{let r=
|
|
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=[],
|
|
136
|
-
`)}function
|
|
137
|
-
`),endIndex:o-1}}function Ko(e,t,r,n,a,o,i,s,l){let c="",u="";if(e.headerMatch){let g=Math.min(e.headerMatch[1].length,9),d=Math.min(g-1,8),w=[32,28,26,24,22,20,20,20,20],h=w[g-1]||w[w.length-1];u=e.headerMatch[2].trim(),c=`<w:pPr><w:pStyle w:val="Heading${g}"/><w:outlineLvl w:val="${d}"/><w:rPr><w:b/><w:sz w:val="${h}"/><w:szCs w:val="${h}"/></w:rPr></w:pPr>`}else if(e.marker){let g=a.detectNumberingFormat(e.marker),d=r>0?Math.floor(e.indentSize/r):0,w=n?.ilvl||0,h=g.format==="outline"?Math.min(8,g.depth):Math.min(8,d+w);u=Ee(e.raw);let b=a.getOrCreateNumId({type:g.format},n);c=a.buildListPPr(b,h)}else u=e.raw;let{cleanText:m,formatHints:f}=ne(u),p=[];return t===0&&l.length>0&&p.push(...l),p.push({kind:o?"insertion":"run",text:m,author:i,startOffset:0,endOffset:m.length}),{ooxml:fe(p,c,f,{author:i,generateRedlines:o,font:s})}}var Yo=new Set(["officeonline","officeweb","web"]);function Zo(e){return e?Yo.has(String(e).toLowerCase()):!1}function Jo(){return typeof process<"u"&&process?.env?.NODE_ENV==="production"}function qo(){return new Promise(e=>setTimeout(e,0))}var Be=class{constructor(t={}){this.generateRedlines=t.generateRedlines??!0,this.author=t.author??"AI",this.validateOutput=t.validateOutput??!0,this.validationMode=t.validationMode??"auto",this.numberingService=t.numberingService||new lt,this.font=t.font||null,this.platform=t.platform??or(),this.isWebPlatform=t.isWebPlatform??Zo(this.platform),this.enableEventLoopYielding=t.enableEventLoopYielding??this.isWebPlatform,this.yieldRunThreshold=t.yieldRunThreshold??50,this.yieldCharThreshold=t.yieldCharThreshold??5e3,this.disableSemanticCleanupOverChars=t.disableSemanticCleanupOverChars??(this.isWebPlatform?8e3:Number.POSITIVE_INFINITY)}async execute(t,r,n={}){let a=[];try{let o=n.xmlDoc||B().parseFromString(t,"application/xml"),i=H(o,"*","p"),{runModel:s,acceptedText:l,pPr:c}=Ot(t,{xmlDoc:o}),u=i?gr(i):null;C(`[Reconcile] Ingested ${s.length} runs, ${l.length} chars, numbering:`,u),await this.maybeYield(s.length,Math.max(l.length,r?.length||0));let{cleanText:m,formatHints:f}=ne(r);C(`[Reconcile] Preprocessed: ${f.length} format hints`),await this.maybeYield(s.length,Math.max(l.length,m.length));let p=nn(m),g=Ct(m),d=p||g;if(!p&&g&&C("[Reconcile] List-target detected via loose marker parsing; bypassing no-op short-circuit for structural conversion."),l===m&&f.length===0&&!d)return C("[Reconcile] No changes detected"),{ooxml:t,isValid:!0,warnings:["No changes detected"]};let w=Math.max(l.length,m.length)<this.disableSemanticCleanupOverChars,h=kt(l,m,{cleanupSemantic:w});w||C("[Reconcile] Skipping semantic diff cleanup for large web payload"),await this.maybeYield(s.length,Math.max(l.length,m.length));let b=s.filter(P=>P.kind===O.PARAGRAPH_START).length;if(C(`[Reconcile] isTargetList: ${d}, paragraphCount: ${b}`),d)return C("[Reconcile] \u{1F3AF} ENTERING LIST GENERATION PATH"),C(`[Reconcile] cleanText preview: ${m.substring(0,100)}...`),C(`[Reconcile] acceptedText preview: ${l.substring(0,100)}...`),this.executeListGeneration(m,u,s);C(`[Reconcile] Computed ${h.length} diff operations`);let x=Mt(s,h);C(`[Reconcile] Split into ${x.length} runs`);let E=Lt(x,h,{generateRedlines:this.generateRedlines,author:this.author,formatHints:f,numberingService:this.numberingService});C(`[Reconcile] Patched model has ${E.length} runs`),await this.maybeYield(E.length,Math.max(l.length,m.length));let v=fe(E,c,f,{author:this.author,generateRedlines:this.generateRedlines});if(this.shouldRunValidation()){let P=this.validateBasic(v);P.isValid||a.push(...P.errors)}return{ooxml:v,isValid:a.length===0,warnings:a}}catch(o){return Z("[Reconcile] Pipeline error:",o),{ooxml:t,isValid:!1,warnings:[`Pipeline error: ${o.message}`]}}}validateBasic(t){let r=[];try{let n=`<root xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">${t}</root>`,o=B().parseFromString(n,"application/xml"),i=j(o);i&&r.push("Generated OOXML is not well-formed XML: "+i.textContent.substring(0,100)),t.includes("<w:p")||r.push("Generated OOXML missing paragraph element")}catch(n){r.push(`Validation error: ${n.message}`)}return{isValid:r.length===0,errors:r}}shouldRunValidation(){return this.validateOutput?this.validationMode==="always"?!0:this.validationMode==="never"?!1:!(this.isWebPlatform&&Jo()):!1}async maybeYield(t,r){this.enableEventLoopYielding&&(t<=this.yieldRunThreshold&&r<=this.yieldCharThreshold||await qo())}wrapForInsertion(t,r={}){return Ie(t,r)}async executeListGeneration(t,r,n,a=""){return Cn({cleanText:t,numberingContext:r,originalRunModel:n,originalText:a,generateRedlines:this.generateRedlines,author:this.author,font:this.font,numberingService:this.numberingService})}detectIndentationStep(t){return br(t)}executeTableGeneration(t){let r=me(t);return r.rows.length===0&&r.headers.length===0?{ooxml:"",isValid:!1,warnings:["Could not parse Markdown table"]}:{ooxml:_e(r,{generateRedlines:this.generateRedlines,author:this.author}),isValid:!0,warnings:[],includeNumbering:!1}}};function z(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===S&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function A(e,t){return typeof e.createElementNS=="function"?e.createElementNS(S,t):e.createElement(t)}function Qo(e,t){let r=Array.from(e?.getElementsByTagNameNS?.(S,t)||[]);return r.length>0?r:Array.from(e?.getElementsByTagName?.("*")||[]).filter(n=>z(n,t))}function xr(e){return["ins","del","moveFrom","moveTo","moveFromRangeStart","moveFromRangeEnd","moveToRangeStart","moveToRangeEnd","rPrChange","pPrChange","cellIns","cellDel"].some(r=>Qo(e,r).length>0)}function ei(e){let t=String(e||"").trim();return/^<\?xml\b[^>]*>\s*<pkg:package\b/i.test(t)||/^<pkg:package\b/i.test(t)?"package":/^<\?xml\b[^>]*>\s*<(?:w:)?document\b/i.test(t)||/^<(?:w:)?document\b/i.test(t)?"document":"fragment"}function te(e){return!e||typeof e!="object"||e.sourceType||typeof e.oxml!="string"?e:{...e,sourceType:ei(e.oxml)}}var ct=["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 Ke(e,t){let r=ct.indexOf(t.nodeName),n=r===-1?999:r,a=!1;for(let o of Array.from(e.childNodes)){if(o.nodeType!==1)continue;let i=ct.indexOf(o.nodeName);if((i===-1?999:i)>n){e.insertBefore(t,o),a=!0;break}}a||e.appendChild(t)}function ti(e,t,r,n){if(!t||!r)return;let a=!!r.bold,o=!!r.italic,i=!!r.underline,s=!!r.strikethrough,l=new Set;if(a&&(l.add("w:b"),l.add("w:bCs")),o&&(l.add("w:i"),l.add("w:iCs")),i&&l.add("w:u"),s&&l.add("w:strike"),l.size>0){let c=[];for(let u of Array.from(t.childNodes))l.has(u.nodeName)&&c.push(u);for(let u of c)t.removeChild(u)}if(a){let c=A(e,"w:b");c.setAttribute("w:val",n==="add"?"1":"0"),Ke(t,c);let u=A(e,"w:bCs");u.setAttribute("w:val",n==="add"?"1":"0"),Ke(t,u)}if(o){let c=A(e,"w:i");c.setAttribute("w:val",n==="add"?"1":"0"),Ke(t,c);let u=A(e,"w:iCs");u.setAttribute("w:val",n==="add"?"1":"0"),Ke(t,u)}if(i){let c=A(e,"w:u");c.setAttribute("w:val",n==="add"?"single":"none"),Ke(t,c)}if(s){let c=A(e,"w:strike");c.setAttribute("w:val",n==="add"?"1":"0"),Ke(t,c)}}function An(e,t,r){ti(e,t,r,"remove")}function ut(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=_t(r,!1)),r.nodeName==="w:i"&&(t.italic=_t(r,!1)),r.nodeName==="w:u"&&(t.underline=_t(r,!0)),r.nodeName==="w:strike"&&(t.strikethrough=_t(r,!1)),r.nodeName==="w:rStyle"){let n=r.getAttribute("w:val");if(n){let a=n.toLowerCase();(a.includes("bold")||a.includes("strong"))&&(t.bold=!0),(a.includes("italic")||a.includes("emphasis"))&&(t.italic=!0),a.includes("underline")&&(t.underline=!0)}}return t.hasFormatting=t.bold||t.italic||t.underline||t.strikethrough,t}function _t(e,t){let n=(e.getAttribute("w:val")||e.getAttribute("val")||"").toLowerCase();return n?t?n!=="none"&&n!=="0"&&n!=="false"&&n!=="off":n!=="0"&&n!=="false"&&n!=="off":!0}var Rn="http://schemas.openxmlformats.org/wordprocessingml/2006/main";function de(e,t){if(!e||e.nodeType!==1)return!1;if(e.namespaceURI===Rn&&e.localName===t)return!0;let r=String(e.nodeName||"");return r===`w:${t}`||r===t}function ri(e){return!e||e.nodeType!==1||e.namespaceURI!==Rn?!1:e.localName==="del"||e.localName==="moveFrom"}function On(e){let t=[],r=Array.from(e?.childNodes||[]).reverse();for(;r.length>0;){let n=r.pop();if(!n||n.nodeType!==1||ri(n))continue;if(de(n,"r")){t.push(n);continue}let a=Array.from(n.childNodes||[]);for(let o=a.length-1;o>=0;o-=1)r.push(a[o])}return t}function xe(e){let t=new Set(["comment","footnote","endnote"]);return V(e,"*","p").filter(n=>{let a=n.parentNode;for(;a&&a.nodeName;){let o=String(a.localName||"").toLowerCase();if(t.has(o))return!1;a=a.parentNode}return!0})}function kn(e){let t=[],r=0;for(let n=0;n<e.length;n++){let a=e[n],o=On(a);for(let i of o){let s=$(i,"w:rPr");Array.from(i.childNodes||[]).forEach(l=>{if(de(l,"t")){let c=l.textContent||"";c.length>0&&(t.push({charStart:r,charEnd:r+c.length,textElement:l,runElement:i,paragraph:a,container:i.parentNode,rPr:s}),r+=c.length)}else(de(l,"br")||de(l,"cr")||de(l,"tab")||de(l,"noBreakHyphen"))&&(t.push({charStart:r,charEnd:r+1,textElement:l,runElement:i,paragraph:a,container:i.parentNode,rPr:s}),r+=1)})}r=Me(r,n,e.length)}return{textSpans:t,charOffset:r}}function ni(e,t,r,n,a,o=null){let i=null;for(let c of Array.from(e.childNodes))if(de(c,"rPr")){i=c;break}let s=ut(i);o&&(o.bold&&!s.bold&&(s.bold=!0),o.italic&&!s.italic&&(s.italic=!0),o.underline&&!s.underline&&(s.underline=!0),o.strikethrough&&!s.strikethrough&&(s.strikethrough=!0)),s.hasFormatting=s.bold||s.italic||s.underline||s.strikethrough;let l=r;for(let c of Array.from(e.childNodes))if(de(c,"t")){let u=c.textContent||"";if(u.length>0){let m=l,f=l+u.length;n.push({charStart:m,charEnd:f,textElement:c,runElement:e,paragraph:t,rPr:i,format:{...s}}),s.hasFormatting&&a.push({start:m,end:f,format:{...s},run:e,rPr:i}),l=f}}return l}function Mn(e){let t=[],r=[],n=0,a=xe(e);for(let o=0;o<a.length;o++){let i=a[o],s=null;for(let u of Array.from(i.childNodes))if(de(u,"pPr")){for(let m of Array.from(u.childNodes))if(de(m,"rPr")){s=m;break}break}let l=ut(s);l.hasFormatting&&C(`[OxmlEngine] Found paragraph-level formatting: ${JSON.stringify(l)}`);let c=On(i);for(let u of c)n=ni(u,i,n,r,t,l);n=Me(n,o,a.length)}return C(`[OxmlEngine] Extracted ${r.length} text spans, ${t.length} format hints`),{existingFormatHints:t,textSpans:r,paragraphs:a}}function Fe(e,t,r,n){let a=A(e,t==="ins"?"w:ins":"w:del"),o=ee(n);return a.setAttribute("w:id",String(o.id)),a.setAttribute("w:author",o.author),a.setAttribute("w:date",o.date),r&&a.appendChild(r),a}function Ln(e,t){return Array.from(e?.childNodes||[]).find(r=>r.nodeType===1&&(r.localName===t||r.nodeName===`w:${t}`))||null}function ai(e,t){let r=Ln(t,"pPr");return r?t.firstChild!==r&&t.insertBefore(r,t.firstChild||null):(r=A(e,"w:pPr"),t.insertBefore(r,t.firstChild||null)),r}function oi(e,t){let r=Ln(t,"rPr");return r?t.lastChild!==r&&t.appendChild(r):(r=A(e,"w:rPr"),t.appendChild(r)),r}function _n(e,t,r,n){let a=ai(e,t),o=oi(e,a);for(let l of Array.from(o.childNodes||[]))l.nodeType===1&&(l.localName==="ins"||l.localName==="del"||l.nodeName==="w:ins"||l.nodeName==="w:del")&&o.removeChild(l);let i=A(e,n==="ins"?"w:ins":"w:del"),s=ee(r);return i.setAttribute("w:id",String(s.id)),i.setAttribute("w:author",s.author),i.setAttribute("w:date",s.date),o.appendChild(i),i}function Bn(e,t,r){return _n(e,t,r,"ins")}function Bt(e,t,r){return _n(e,t,r,"del")}function $e(e,t,r,n){let a=A(e,"w:r");if(r&&a.appendChild(r.cloneNode(!0)),!n)return Fn(e,a,t),a;let o=A(e,n?"w:delText":"w:t");return o.setAttribute("xml:space","preserve"),o.textContent=t,a.appendChild(o),a}function Ft(e,t,r,n,a,o,i){if(!t)return[];let s=new Set([0,t.length]);for(let u of n){let m=Math.max(0,u.start-a),f=Math.min(t.length,u.end-a);m>=0&&m<t.length&&s.add(m),f>0&&f<=t.length&&s.add(f)}let l=Array.from(s).sort((u,m)=>u-m),c=[];for(let u=0;u<l.length-1;u++){let m=l[u],f=l[u+1],p=t.slice(m,f);if(!p)continue;let g=a+m,d=a+f,w=n.filter(x=>x.start<=g&&x.end>=d),h={};w.forEach(x=>{x.format&&Object.assign(h,x.format)});let b=Ye(e,r,h,o,i);c.push(Nr(e,p,b,!1))}return c}function Nr(e,t,r,n){let a=A(e,"w:r");if(r&&a.appendChild(r),!n)return Fn(e,a,t),a;let o=A(e,n?"w:delText":"w:t");return o.setAttribute("xml:space","preserve"),o.textContent=t,a.appendChild(o),a}function Fn(e,t,r){let a=String(r||"").split(/(\t|\n|\u2011)/);for(let o of a){if(!o)continue;if(o===" "){t.appendChild(A(e,"w:tab"));continue}if(o===`
|
|
138
|
-
`){t.appendChild(
|
|
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){
|
|
140
|
-
`:
|
|
141
|
-
`).replace(/\u00a0/g," "):""}function
|
|
142
|
-
`:
|
|
143
|
-
`&&(
|
|
144
|
-
|
|
145
|
-
`){let R=m(b+1),M=f(R.pPr);w&&r==="insert"?Bn(e,M,p):w&&r==="delete"&&Bt(e,M,p);let L=s.get(R.container);L&&(L.appendChild(M),E=M),b++,r!=="delete"&&x++;return}if(P==="\uFFFC"){let R=N.find(M=>!M.isCommentMarker)||N[0];if(R){let M=R.node.cloneNode(!0);if(R.isTextBox&&R.originalContainer){let L=$(M,"w:txbxContent");if(L){for(;L.firstChild;)L.removeChild(L.firstChild);u.set(R.originalContainer,L)}}E.appendChild(M)}b++,r!=="delete"&&x++;return}if(c.has(P)){if(r!=="delete"){let R=c.get(P);if(R){let M=R.cloneNode(!0),L=A(e,"w:r");n&&L.appendChild(n.cloneNode(!0)),L.appendChild(M),E.appendChild(L)}}b++,r!=="delete"&&x++;return}if(P.length===0)return;let I=E;if(a){let R=a.cloneNode(!1);I=R,E.appendChild(R)}if(r==="delete"){let R=A(e,"w:r");n&&R.appendChild(n.cloneNode(!0));let M=A(e,"w:delText");if(M.setAttribute("xml:space","preserve"),M.textContent=P,R.appendChild(M),w){let L=Fe(e,"del",R,p);I.appendChild(L)}}else{let R=we(g,x,x+P.length),M=Ft(e,P,n,R,x,p,w);if(r==="insert"&&w){let L=Fe(e,"ins",null,p);M.forEach(le=>L.appendChild(le)),I.appendChild(L)}else M.forEach(L=>I.appendChild(L))}r!=="delete"&&(x+=P.length),b+=P.length}),{currentParagraph:E}}function Cr(e,t,r,n,a,o,i=!0){let s=ra(e,r);if(s.paragraphs.length===0)return te({oxml:n.serializeToString(e),hasChanges:!1});let l=st(s.originalFullText,s.processedModifiedText);return te(aa(e,l,s,n,a,o,i))}function Ce(e,t){return te({oxml:e.serializeToString(t),hasChanges:!1})}function oa(e,t,r,n,a,o=!0){let i=ue(e,S,"tbl"),s=me(t),l=s.rows.length>0||s.headers.length>0;if(i.length===0||!l)return Ce(r,e);let c=i[0],u=hr(c),m=Sn(u,s);if(m.length===0)return Ce(r,e);let p=In(u,m,{generateRedlines:o,author:a}),g=`<root xmlns:w="${S}">${p}</root>`,w=(n||B()).parseFromString(g,"application/xml"),h=j(w);if(h)return Z("[OxmlEngine] Failed to parse reconciled table OOXML:",h.textContent),Ce(r,e);let b=Rt(w,S,"tbl");if(!b)return Z("[OxmlEngine] No table found in reconciled OOXML"),Ce(r,e);let x=e.importNode(b,!0);return c.parentNode.replaceChild(x,c),te({oxml:r.serializeToString(e),hasChanges:!0})}function ia(e,t,r,n,a,o){let i=me(t);if(!i||i.rows.length===0&&i.headers.length===0)return C("[OxmlEngine] Failed to parse table data from Markdown"),Ce(r,e);let s=_e(i,{generateRedlines:o,author:a}),l=n||B(),c=l.parseFromString(`<root xmlns:w="${S}">${s}</root>`,"application/xml"),u=j(c);if(u)return Z("[OxmlEngine] Failed to parse generated table OOXML:",u.textContent),Ce(r,e);let m=H(c,S,"tbl");if(m||(m=H(c,S,"ins")),!m)return Z("[OxmlEngine] No table element found in generated OOXML"),Ce(r,e);let f=e,p=V(f,S,"p");if(p.length===0)return C("[OxmlEngine] No paragraphs found to replace"),Ce(r,f);let g=p[0],d=g.parentNode;if(d&&d.nodeType===9){let h=l.parseFromString(`<w:document xmlns:w="${S}"><w:body/></w:document>`,"application/xml"),b=H(h,S,"body");p.forEach(x=>b.appendChild(h.importNode(x,!0))),f=h,p=V(f,S,"p"),g=p[0],d=g.parentNode}let w=f.importNode(m,!0);return o?p.forEach(h=>{Bt(f,h,a),V(h,S,"r").forEach(x=>{V(x,S,"t").forEach(N=>{let y=N.textContent||"";if(y.trim()){let I=A(f,"w:delText");I.textContent=y,N.parentNode.replaceChild(I,N)}});let v=A(f,"w:del"),P=ee(a);v.setAttribute("w:id",String(P.id)),v.setAttribute("w:author",P.author),v.setAttribute("w:date",P.date),x.parentNode.insertBefore(v,x),v.appendChild(x)})}):p.slice(1).forEach(h=>h.parentNode.removeChild(h)),d.insertBefore(w,g),o||d.removeChild(g),C("[OxmlEngine] Text-to-table transformation complete"),te({oxml:r.serializeToString(f),hasChanges:!0})}function Xe(e,t){if(!e||!e.attributes)return"";for(let r of Array.from(e.attributes))if((r.localName||"").toLowerCase()===t.toLowerCase())return String(r.value||"");return String(e.getAttribute?.(`w:${t}`)||e.getAttribute?.(t)||"")}function ca(e){return typeof e=="string"?e.trim().toLowerCase():""}function Pi(e){return!!e&&e.nodeType===1}function Ae(e,t){return Pi(e)&&e.namespaceURI===S&&String(e.localName||"").toLowerCase()===t.toLowerCase()}function re(e,t){return Array.from(e.getElementsByTagNameNS(S,t))}function Ar(e={}){if(e?.allAuthors===!0)return{valid:!0,allAuthors:!0,normalizedAuthor:""};let t=ca(e?.author);return t?{valid:!0,allAuthors:!1,normalizedAuthor:t}:{valid:!1,allAuthors:!1,normalizedAuthor:"",warning:"No author provided. Pass { author } or set { allAuthors: true }."}}function ie(e,t){if(t.allAuthors)return!0;let r=ca(Xe(e,"author"));return!!r&&r===t.normalizedAuthor}function Rr(e,t){let n=B().parseFromString(e,"application/xml"),a=j(n);return a?{xmlDoc:null,serializer:null,warning:`${t}: ${a.textContent||"parse error"}`}:{xmlDoc:n,serializer:Q(),warning:null}}function Y(e){return e?.parentNode?(e.parentNode.removeChild(e),!0):!1}function zt(e){let t=e?.parentNode;if(!t)return!1;for(;e.firstChild;)t.insertBefore(e.firstChild,e);return t.removeChild(e),!0}function Wt(e){let t=e?.parentNode;return Ae(t,"trPr")&&Ae(t?.parentNode,"tr")}function Or(e){let t=e?.parentNode,r=t?.parentNode,n=r?.parentNode;return Ae(t,"rPr")&&Ae(r,"pPr")&&Ae(n,"p")}function ua(e){return Or(e)?e.parentNode.parentNode.parentNode:null}function Si(e){let t=e?.nextSibling||null;for(;t;){if(Ae(t,"p"))return t;t=t.nextSibling}return null}function fa(e){if(!e?.parentNode)return!1;let t=Si(e);if(!t)return Y(e);let r=Array.from(e.childNodes||[]).filter(a=>!Ae(a,"pPr")),n=t.firstChild||null;for(let a of r)t.insertBefore(a,n);return Y(e)}function kr(e,t={}){let r=[],n=Ar(t);if(!n.valid)return{oxml:e,hasChanges:!1,acceptedCount:0,warnings:[n.warning]};let a=Rr(e,"Failed to parse OOXML");if(!a.xmlDoc)return{oxml:e,hasChanges:!1,acceptedCount:0,warnings:[a.warning]};let{xmlDoc:o,serializer:i}=a,s=0;for(let c of re(o,"ins"))if(!(!c.parentNode||!ie(c,n))){if(Or(c)){Y(c)&&(s+=1);continue}if(Wt(c)){Y(c)&&(s+=1);continue}zt(c)&&(s+=1)}for(let c of re(o,"del")){if(!c.parentNode||!ie(c,n))continue;let u=ua(c);if(u){fa(u)&&(s+=1);continue}if(Wt(c)){let m=c.parentNode?.parentNode;Y(m)&&(s+=1);continue}Y(c)&&(s+=1)}for(let c of re(o,"moveFrom"))!c.parentNode||!ie(c,n)||Y(c)&&(s+=1);for(let c of re(o,"moveTo"))!c.parentNode||!ie(c,n)||zt(c)&&(s+=1);s+=ma(o,n);let l=["rPrChange","pPrChange","tblPrChange","trPrChange","tcPrChange"];for(let c of l)for(let u of re(o,c))!u.parentNode||!ie(u,n)||Y(u)&&(s+=1);return{oxml:i.serializeToString(o),hasChanges:s>0,acceptedCount:s,warnings:r}}function sa(e,t){for(let r of Array.from(t.getElementsByTagNameNS(S,"delText"))){let n=A(e,"w:t"),a=r.getAttribute("xml:space");for(a&&n.setAttribute("xml:space",a);r.firstChild;)n.appendChild(r.firstChild);r.parentNode?.replaceChild(n,r)}}function Ii(e,t){let r=e?.parentNode;if(!r)return!1;let n=t.endsWith("Change")?t.slice(0,-6):"";if(!n||String(r.localName||"").toLowerCase()!==n.toLowerCase()||r.namespaceURI!==S)return Y(e);let a=Array.from(e.childNodes||[]).find(i=>i.nodeType===1&&i.namespaceURI===S&&String(i.localName||"").toLowerCase()===n.toLowerCase());if(!a)return Y(e);let o=Array.from(a.childNodes||[]);for(;r.firstChild;)r.removeChild(r.firstChild);for(let i of o){let s=Ci(r.ownerDocument,i);r.appendChild(s)}return!0}function Ci(e,t){return e&&typeof e.importNode=="function"?e.importNode(t,!0):t.cloneNode(!0)}function la(e,t,r){let n=new Set;for(let a of re(e,t)){if(!ie(a,r))continue;let o=Xe(a,"id");o&&n.add(o)}return n}function ma(e,t){let r=0,n=la(e,"moveFromRangeStart",t),a=la(e,"moveToRangeStart",t),o=[["moveFromRangeStart",n,!0],["moveFromRangeEnd",n,!1],["moveToRangeStart",a,!0],["moveToRangeEnd",a,!1]];for(let[i,s,l]of o)for(let c of re(e,i)){if(!c.parentNode)continue;let u=Xe(c,"id");u&&(t.allAuthors||s.has(u)||l&&ie(c,t))&&Y(c)&&(r+=1)}return r}function Ai(e,t={}){let r=[],n=Ar(t);if(!n.valid)return{oxml:e,hasChanges:!1,rejectedCount:0,warnings:[n.warning]};let a=Rr(e,"Failed to parse OOXML");if(!a.xmlDoc)return{oxml:e,hasChanges:!1,rejectedCount:0,warnings:[a.warning]};let{xmlDoc:o,serializer:i}=a,s=0;for(let c of re(o,"ins")){if(!c.parentNode||!ie(c,n))continue;let u=ua(c);if(u){fa(u)&&(s+=1);continue}if(Wt(c)){let m=c.parentNode?.parentNode;Y(m)&&(s+=1);continue}Y(c)&&(s+=1)}for(let c of re(o,"del"))if(!(!c.parentNode||!ie(c,n))){if(Or(c)){Y(c)&&(s+=1);continue}if(Wt(c)){Y(c)&&(s+=1);continue}sa(o,c),zt(c)&&(s+=1)}for(let c of re(o,"moveFrom"))!c.parentNode||!ie(c,n)||(sa(o,c),zt(c)&&(s+=1));for(let c of re(o,"moveTo"))!c.parentNode||!ie(c,n)||Y(c)&&(s+=1);s+=ma(o,n);let l=["rPrChange","pPrChange","tblPrChange","trPrChange","tcPrChange"];for(let c of l)for(let u of re(o,c))!u.parentNode||!ie(u,n)||Ii(u,c)&&(s+=1);return{oxml:i.serializeToString(o),hasChanges:s>0,rejectedCount:s,warnings:r}}function Ri(e,t){let r=new Set,n=re(e,"comment");for(let a of n){if(!ie(a,t))continue;let o=Xe(a,"id");o&&r.add(o)}return{targetIds:r,commentNodes:n}}function Oi(e,t){let r=0;for(let n of e){let a=Xe(n,"id");!a||!t.has(a)||Y(n)&&(r+=1)}return r}function ki(e){return Ae(e,"r")?Array.from(e.childNodes||[]).filter(r=>{if(r.nodeType===3)return String(r.nodeValue||"").trim().length>0;if(r.nodeType!==1)return!1;if(r.namespaceURI!==S)return!0;let n=String(r.localName||"").toLowerCase();return n!=="rpr"&&n!=="commentreference"}).length===0:!1}function Mi(e,t){let r=0,n=["commentRangeStart","commentRangeEnd","commentReference"];for(let a of n)for(let o of re(e,a)){if(!o.parentNode)continue;let i=Xe(o,"id");if(!(!i||!t.has(i))){if(a==="commentReference"&&ki(o.parentNode)){Y(o.parentNode)&&(r+=1);continue}Y(o)&&(r+=1)}}return r}function Li(e,t={}){let r=[],n=Ar(t);if(!n.valid)return{oxml:e,hasChanges:!1,commentsRemoved:0,referencesRemoved:0,warnings:[n.warning]};let a=Rr(e,"Failed to parse OOXML");if(!a.xmlDoc)return{oxml:e,hasChanges:!1,commentsRemoved:0,referencesRemoved:0,warnings:[a.warning]};let{xmlDoc:o,serializer:i}=a,{targetIds:s,commentNodes:l}=Ri(o,n);if(n.allAuthors)for(let m of["commentRangeStart","commentRangeEnd","commentReference"])for(let f of re(o,m)){let p=Xe(f,"id");p&&s.add(p)}let c=Oi(l,s),u=Mi(o,s);return{oxml:i.serializeToString(o),hasChanges:c>0||u>0,commentsRemoved:c,referencesRemoved:u,warnings:r}}async function Mr(e,t,r,n={}){let a=n.generateRedlines??!0,o=n.author||J(),i=B(),s=Q(),l=U=>{let X={...U};return X.status||(X.status=X.hasChanges?"ok":"no-op"),te(X)},c=()=>l({oxml:e,hasChanges:!1}),u;try{u=i.parseFromString(e,"text/xml")}catch(U){return Z("[OxmlEngine] Failed to parse OXML:",U),l({oxml:e,hasChanges:!1,status:"error",error:{code:"PARSE_ERROR",message:"Could not parse OOXML input."}})}let m=j(u);if(m)return Z("[OxmlEngine] XML parse error:",m.textContent),l({oxml:e,hasChanges:!1,status:"error",error:{code:"PARSE_ERROR",message:m.textContent||"Could not parse OOXML input."}});if(cr(u),xr(u))if((n.existingRevisions||"reject-input")==="accept-all-first"){C("[OxmlEngine] Existing revisions detected; accepting all input revisions before redlining"),e=kr(e,{allAuthors:!0}).oxml,u=i.parseFromString(e,"text/xml");let ge=j(u);if(ge)return Z("[OxmlEngine] XML parse error after accepting existing revisions:",ge.textContent),l({oxml:e,hasChanges:!1,status:"error",error:{code:"PARSE_ERROR",message:"Could not parse OOXML after accepting existing revisions."}});cr(u)}else return C("[OxmlEngine] Existing revisions detected; rejecting input per existingRevisions policy"),l({oxml:e,hasChanges:!1,status:"error",error:{code:"EXISTING_REVISIONS",message:'Input OOXML contains existing tracked changes. Pass existingRevisions: "accept-all-first" to normalize before redlining.'}});let f=Un(u,t,n);if(f.hasTableWrapper&&f.targetParagraph&&!n._isolatedTableCell){C("[OxmlEngine] Isolating table-cell paragraph before diff");let U=ft(u,f.targetParagraph,s);return Mr(U,t,r,{...n,_isolatedTableCell:!0})}let p=ga(r),{cleanText:g,formatHints:d}=ne(p),w=g.trim()!==t.trim(),h=d.length>0,{existingFormatHints:b,textSpans:x,paragraphs:E}=Mn(u),v=b.length>0,P=x.map(U=>_i(U)).join("");if(w&&typeof t=="string"&&t.trim()&&!t.includes(`
|
|
146
|
-
`)
|
|
147
|
-
|
|
148
|
-
`:r==="noBreakHyphen"?"\u2011":t?.textContent||""}function ga(e){let t=e;return t=t.replace(/^(Here is the redline:|Here is the text:|Sure, I can help:|Here's the updated text:)\s*/i,""),t=t.replace(/\$\\text\{/g,"").replace(/\}\$/g,""),t=t.replace(/\$([^0-9\n]+?)\$/g,"$1"),t=t.replace(/\\r\\n/g,`
|
|
149
|
-
`).replace(
|
|
150
|
-
`),t}
|
|
151
|
-
|
|
152
|
-
`)
|
|
153
|
-
`),
|
|
154
|
-
`)
|
|
155
|
-
`)
|
|
156
|
-
`)
|
|
157
|
-
`)
|
|
158
|
-
`)
|
|
159
|
-
`)
|
|
160
|
-
`)}
|
|
161
|
-
`)
|
|
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`
|
|
162
163
|
<w:lvl w:ilvl="${l}">
|
|
163
164
|
<w:start w:val="1"/>
|
|
164
165
|
<w:numFmt w:val="decimal"/>
|
|
@@ -166,34 +167,34 @@ var Ya=Object.create;var qr=Object.defineProperty;var Za=Object.getOwnPropertyDe
|
|
|
166
167
|
<w:lvlJc w:val="left"/>
|
|
167
168
|
<w:pPr><w:ind w:left="${u}" w:hanging="360"/></w:pPr>
|
|
168
169
|
</w:lvl>`}).join("");return`
|
|
169
|
-
<w:numbering xmlns:w="${
|
|
170
|
-
<w:abstractNum w:abstractNumId="${
|
|
170
|
+
<w:numbering xmlns:w="${ge}">
|
|
171
|
+
<w:abstractNum w:abstractNumId="${o}">
|
|
171
172
|
<w:multiLevelType w:val="multilevel"/>
|
|
172
173
|
${i}
|
|
173
174
|
</w:abstractNum>
|
|
174
175
|
<w:num w:numId="${n}">
|
|
175
|
-
<w:abstractNumId w:val="${
|
|
176
|
+
<w:abstractNumId w:val="${o}"/>
|
|
176
177
|
<w:lvlOverride w:ilvl="0">
|
|
177
|
-
<w:startOverride w:val="${
|
|
178
|
+
<w:startOverride w:val="${a}"/>
|
|
178
179
|
</w:lvlOverride>
|
|
179
180
|
</w:num>
|
|
180
|
-
</w:numbering>`.trim()}function
|
|
181
|
-
`:r.localName==="noBreakHyphen"&&(t+="\u2011"));return t}function
|
|
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(`
|
|
182
183
|
`).map(r=>r.replace(/[ \t]+/g," ").trim()).join(`
|
|
183
|
-
`).trim()}function
|
|
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(`
|
|
184
185
|
|
|
185
|
-
`).trim()}function
|
|
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(`
|
|
186
187
|
|
|
187
|
-
`).trim()}function
|
|
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}">
|
|
188
189
|
<w:p>
|
|
189
|
-
<w:r><w:t>${
|
|
190
|
+
<w:r><w:t>${a}</w:t></w:r>
|
|
190
191
|
</w:p>
|
|
191
|
-
</w:comment>`}function
|
|
192
|
-
`);return`<w:comments xmlns:w="${
|
|
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}">
|
|
193
194
|
${t}
|
|
194
|
-
</w:comments>`}function Jt(e){let t=Pe(e,"w:r"),r=[],n="";for(let a of t){let o=n.length,i=Pe(a,"w:t");for(let s of i)n+=s.textContent||"";r.push({run:a,start:o,end:n.length})}return{fullText:n,runOffsets:r}}function Ds(e,t){let r=e.fullText.indexOf(t);if(r===-1)return{found:!1};let n=r+t.length,a=null,o=null,i=0,s=0;for(let{run:l,start:c,end:u}of e.runOffsets)r>=c&&r<u&&(a=l,i=r-c),n>c&&n<=u&&(o=l,s=n-c);return{found:!0,startRun:a,startOffset:i,endRun:o,endOffset:s}}function Nt(e,t,r){let n=A(e,"w:r");t&&n.appendChild(t.cloneNode(!0));let a=A(e,"w:t");return a.setAttribute("xml:space","preserve"),a.textContent=r,n.appendChild(a),n}function La(e,t,r,n,a=null){let o=a||Jt(t),i=Ds(o,r);if(!i.found||!i.startRun)return!1;let s=A(e,"w:commentRangeStart");s.setAttribute("w:id",String(n));let l=A(e,"w:commentRangeEnd");l.setAttribute("w:id",String(n));let c=A(e,"w:r"),u=A(e,"w:commentReference");if(u.setAttribute("w:id",String(n)),c.appendChild(u),i.startRun===i.endRun){let g=i.startRun,d=$(g,"w:t");if(!d)return g.parentNode.insertBefore(s,g),g.nextSibling?(g.parentNode.insertBefore(l,g.nextSibling),l.parentNode.insertBefore(c,l.nextSibling)):(g.parentNode.appendChild(l),g.parentNode.appendChild(c)),!0;let w=d.textContent||"",h=w.substring(0,i.startOffset),b=w.substring(i.startOffset,i.endOffset),x=w.substring(i.endOffset),E=$(g,"w:rPr"),v=g.parentNode;return h&&v.insertBefore(Nt(e,E,h),g),v.insertBefore(s,g),d.textContent=b,g.nextSibling?v.insertBefore(l,g.nextSibling):v.appendChild(l),v.insertBefore(c,l.nextSibling||null),x&&v.insertBefore(Nt(e,E,x),c.nextSibling||null),!0}let m=$(i.startRun,"w:t");if(m&&i.startOffset>0){let g=m.textContent||"",d=g.substring(0,i.startOffset),w=g.substring(i.startOffset);if(d){let h=$(i.startRun,"w:rPr");i.startRun.parentNode.insertBefore(Nt(e,h,d),i.startRun)}m.textContent=w}i.startRun.parentNode.insertBefore(s,i.startRun);let f=i.endRun||i.startRun,p=$(f,"w:t");if(p&&i.endOffset<(p.textContent||"").length){let g=p.textContent||"",d=g.substring(0,i.endOffset),w=g.substring(i.endOffset);if(p.textContent=d,w){let h=$(f,"w:rPr");f.nextSibling?f.parentNode.insertBefore(Nt(e,h,w),f.nextSibling):f.parentNode.appendChild(Nt(e,h,w))}}return f.nextSibling?(f.parentNode.insertBefore(l,f.nextSibling),l.parentNode.insertBefore(c,l.nextSibling)):(f.parentNode.appendChild(l),f.parentNode.appendChild(c)),!0}var nt="http://schemas.microsoft.com/office/2006/xmlPackage",vt="http://schemas.openxmlformats.org/package/2006/relationships";function _a(e,t){let r=B(),n=Q(),a=r.parseFromString(e,"text/xml"),o=j(a);if(o)return Z("[CommentEngine] Failed to parse package:",o.textContent),e;let i=a.documentElement,s=a.createElementNS(nt,"pkg:part");s.setAttribute("pkg:name","/word/comments.xml"),s.setAttribute("pkg:contentType","application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml");let l=a.createElementNS(nt,"pkg:xmlData"),c=r.parseFromString(t,"text/xml");l.appendChild(a.importNode(c.documentElement,!0)),s.appendChild(l),i.appendChild(s);let m=V(i,nt,"part").find(f=>f.getAttribute("pkg:name")==="/word/_rels/document.xml.rels");if(m){let f=V(m,nt,"xmlData");if(f.length>0){let p=V(f[0],vt,"Relationships");if(p.length>0){let g=p[0],d=V(g,vt,"Relationship");if(!d.some(h=>h.getAttribute("Type")?.includes("comments"))){let h=0;d.forEach(x=>{let E=x.getAttribute("Id"),v=parseInt(E?.replace("rId","")||"0",10);v>h&&(h=v)});let b=a.createElementNS(vt,"Relationship");b.setAttribute("Id",`rId${h+1}`),b.setAttribute("Type","http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"),b.setAttribute("Target","comments.xml"),g.appendChild(b)}}}}else{let f=a.createElementNS(nt,"pkg:part");f.setAttribute("pkg:name","/word/_rels/document.xml.rels"),f.setAttribute("pkg:contentType","application/vnd.openxmlformats-package.relationships+xml");let p=a.createElementNS(nt,"pkg:xmlData"),g=a.createElementNS(vt,"Relationships"),d=a.createElementNS(vt,"Relationship");d.setAttribute("Id","rId1"),d.setAttribute("Type","http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"),d.setAttribute("Target","comments.xml"),g.appendChild(d),p.appendChild(g),f.appendChild(p),i.appendChild(f)}return n.serializeToString(a)}function zs(e,t,r){try{let n=t.parseFromString(e,"text/xml"),a=j(n);return a?{xmlDoc:null,warning:r(a.textContent||"parse error")}:{xmlDoc:n,warning:null}}catch(n){return{xmlDoc:null,warning:r(n.message)}}}function Ws(e,t,r={}){let n=r?.author||J(),a=lr(),o=[],i=[];if(!t||t.length===0)return{oxml:e,commentsApplied:0,warnings:["No comments to inject"]};let s=B(),l=Q(),c=zs(e,s,g=>`Failed to parse OXML: ${g}`);if(!c.xmlDoc)return Z("[CommentEngine] Parse failure:",c.warning),{oxml:e,commentsApplied:0,warnings:[c.warning]};let u=c.xmlDoc,m=Pe(u,"w:p");C(`[CommentEngine] Found ${m.length} paragraphs, processing ${t.length} comment requests`);let f=new Map;for(let g of t){let d=g.paragraphIndex-1;if(d<0||d>=m.length){o.push(`Paragraph ${g.paragraphIndex} out of range (1-${m.length})`);continue}f.set(d,(f.get(d)||0)+1)}let p=new Map;for(let g of t){let d=g.paragraphIndex-1;if(d<0||d>=m.length)continue;let w=m[d],h=p.get(d);h||(h=Jt(w),p.set(d,h));let b=sr(),x=La(u,w,g.textToFind,b,h),E=(f.get(d)||1)-1;if(f.set(d,E),!x){o.push(`Could not find "${g.textToFind.substring(0,30)}..." in paragraph ${g.paragraphIndex}`),E===0&&p.delete(d);continue}i.push({id:b,content:g.commentContent,author:n,date:a}),E>0?p.set(d,Jt(w)):p.delete(d)}return i.length===0?{oxml:e,commentsApplied:0,warnings:o}:{oxml:l.serializeToString(u),commentsXml:Kr(i),commentsApplied:i.length,warnings:o}}function Hs(e,t){return _a(e,t)}function Ba(e,t=["all"]){if(!e)return null;let r=e.cloneNode(!0);if(t.includes("all"))["w:b","w:i","w:u","w:strike","w:dstrike","w:color","w:sz","w:szCs","w:rFonts","w:highlight","w:vertAlign","w:spacing","w:w","w:kern","w:position"].forEach(a=>{r.querySelectorAll(`${a}, ${a.replace("w:","")}`).forEach(i=>i.remove())});else{let n={bold:"w:b",italic:"w:i",underline:"w:u",strikethrough:"w:strike",doubleStrike:"w:dstrike",color:"w:color",highlight:"w:highlight",fontSize:"w:sz",fontSizeCs:"w:szCs",fontFamily:"w:rFonts",superscript:"w:vertAlign",subscript:"w:vertAlign"};t.forEach(a=>{let o=n[a];o&&r.querySelectorAll(`${o}, ${o.replace("w:","")}`).forEach(s=>s.remove())})}return r.children.length>0?r:null}function Us(e,t,r){if(!t||!e)return e;let n=Ne(e),a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",o=n.getElementsByTagNameNS(a,"r"),i=n.getElementsByTagNameNS(a,"ins"),s=[...Array.from(o)];for(let l of i){let c=l.getElementsByTagNameNS(a,"r");s.push(...Array.from(c))}for(let l of s){let c=l.getElementsByTagNameNS(a,"t"),u=Array.from(c).map(m=>m.textContent).join("");if(u.includes(t)||u===t){let m=l.getElementsByTagNameNS(a,"rPr");if(m.length>0){let f=m[0],p=Ba(f,r);p?f.parentNode&&f.parentNode.replaceChild(p,f):f.remove()}}}return De(n)}var js={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 Gs(e,t,r="yellow",n={}){let a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",o=js[r.toLowerCase()]||"yellow",i=n?.generateRedlines??!1,s=n?.author||J(),l=t;l?l=t.cloneNode(!0):l=A(e,"w:rPr");let c=null;i&&(c=A(e,"w:rPr"),Array.from(l.childNodes).forEach(f=>{f.nodeName!=="w:rPrChange"&&c.appendChild(f.cloneNode(!0))}));let u=l.getElementsByTagNameNS(a,"highlight");Array.from(u).forEach(f=>f.remove());let m=A(e,"w:highlight");if(m.setAttributeNS(a,"w:val",o),l.appendChild(m),i&&c){let f=A(e,"w:rPrChange"),p=ee(s);f.setAttribute("w:id",String(p.id)),f.setAttribute("w:author",p.author),f.setAttribute("w:date",p.date),f.appendChild(c);let g=l.getElementsByTagNameNS(a,"rPrChange");Array.from(g).forEach(d=>d.remove()),l.appendChild(f)}return l}function Vs(e,t,r="yellow",n={}){if(!t||!e)return e;let a=Ne(e),o="http://schemas.openxmlformats.org/wordprocessingml/2006/main",i=l=>{let c=l.getElementsByTagNameNS(o,"t");return Array.from(c).map(u=>u.textContent).join("")},s=Array.from(a.getElementsByTagNameNS(o,"r"));for(let l=0;l<s.length;l++){let c=s[l],u=i(c);if(!u)continue;let m=u.indexOf(t);if(m===-1)continue;let f=c.parentNode;if(!f){console.warn("[Highlight] Run parent is null; skipping. Likely already processed.");continue}let p=u.substring(0,m),g=u.substring(m,m+t.length),d=u.substring(m+t.length),w=a.createDocumentFragment();if(p.length>0){let h=c.cloneNode(!0),b=h.getElementsByTagNameNS(o,"t");Array.from(b).forEach(E=>E.remove());let x=A(a,"w:t");x.setAttribute("xml:space","preserve"),x.textContent=p,h.appendChild(x),w.appendChild(h)}if(g.length>0){let h=c.cloneNode(!0),b=h.getElementsByTagNameNS(o,"t");Array.from(b).forEach(N=>N.remove());let x=A(a,"w:t");x.setAttribute("xml:space","preserve"),x.textContent=g,h.appendChild(x);let E=h.getElementsByTagNameNS(o,"rPr"),v=E.length>0?E[0]:null,P=Gs(a,v,r,n);v?h.replaceChild(P,v):h.insertBefore(P,h.firstChild),w.appendChild(h)}if(d.length>0){let h=c.cloneNode(!0),b=h.getElementsByTagNameNS(o,"t");Array.from(b).forEach(E=>E.remove());let x=A(a,"w:t");x.setAttribute("xml:space","preserve"),x.textContent=d,h.appendChild(x),w.appendChild(h)}f.replaceChild(w,c)}return De(a)}var ae="http://schemas.openxmlformats.org/wordprocessingml/2006/main",Ks="http://schemas.openxmlformats.org/package/2006/content-types",Ys="http://schemas.openxmlformats.org/package/2006/relationships",$a="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",Xa="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",Da="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",za="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",Fa="word/document.xml",qt="word/numbering.xml",Tt="word/comments.xml",We="[Content_Types].xml",He="word/_rels/document.xml.rels";function Oe(e,t="xml"){let n=B().parseFromString(e,"application/xml"),a=n.getElementsByTagName("parsererror")[0];if(a)throw new Error(`[XML parse error] ${t}: ${a.textContent||"Unknown"}`);return n}function Qt(e){return!!e&&e.nodeType===1&&e.namespaceURI===ae&&e.localName==="sectPr"}function Zr(e){return e.getElementsByTagNameNS("*","body")[0]||null}function Wa(e){for(let t of Array.from(e.childNodes||[]))if(Qt(t))return t;return null}function Zs(e,t){let r=Wa(e);r?e.insertBefore(t,r):e.appendChild(t)}function Ha(e){let t=Zr(e);if(!t)return;let r=Wa(t);if(!r)return;let n=r.nextSibling;for(;n;){let a=n.nextSibling;n.nodeType===1&&t.insertBefore(n,r),n=a}}function Js(e,t={}){let r=typeof t?.onInfo=="function"?t.onInfo:()=>{},n=e.getElementsByTagNameNS(ae,"tc"),a=0;for(let o of Array.from(n)){let i=Array.from(o.childNodes||[]).filter(s=>s.nodeType===1&&s.namespaceURI===ae&&s.localName==="p");for(let s of i){let l=Array.from(s.childNodes||[]).filter(c=>c.nodeType===1&&c.namespaceURI===ae&&c.localName==="p");for(let c of l)o.insertBefore(c,s),a+=1}}return a>0&&r(`[Sanitize] Fixed ${a} nested w:p element(s) in table cells`),a}function Yr(e){return e.getAttribute("pkg:name")||e.getAttribute("name")||""}function qs(e){let t=B(),r=Q(),n=t.parseFromString(e,"application/xml"),a=Array.from(n.getElementsByTagNameNS("*","part")),o=a.find(f=>Yr(f)==="/word/document.xml");if(!o)throw new Error("Package output missing /word/document.xml part");let i=o.getElementsByTagNameNS("*","xmlData")[0];if(!i)throw new Error("Package document part missing pkg:xmlData");let s=Array.from(i.childNodes||[]).find(f=>f.nodeType===1);if(!s)throw new Error("Package document part missing XML payload");let l=s.getElementsByTagNameNS("*","body")[0],c=l?Array.from(l.childNodes||[]).filter(f=>f.nodeType===1&&!Qt(f)):[s],u=a.find(f=>Yr(f)==="/word/numbering.xml"),m=null;if(u){let f=u.getElementsByTagNameNS("*","xmlData")[0],p=f?Array.from(f.childNodes||[]).find(g=>g.nodeType===1):null;p&&(m=r.serializeToString(p))}return{replacementNodes:c,numberingXml:m,sourceType:"package"}}function Qs(e){if(typeof e!="string"||!e.trim())throw new Error("Reconciliation engine returned no OOXML payload for this operation");if(e.includes("<pkg:package"))return qs(e);if(e.includes("<w:document")){let i=B().parseFromString(e,"application/xml"),s=i.getElementsByTagNameNS("*","body")[0];return{replacementNodes:s?Array.from(s.childNodes||[]).filter(c=>c.nodeType===1&&!Qt(c)):Array.from(i.childNodes||[]).filter(c=>c.nodeType===1),numberingXml:null,sourceType:"document"}}let t=`<root xmlns:w="${ae}">${e}</root>`,n=B().parseFromString(t,"application/xml");return{replacementNodes:Array.from(n.documentElement.childNodes||[]).filter(o=>o.nodeType===1),numberingXml:null,sourceType:"fragment"}}function Ua(e,t,r){if(Array.from(e.getElementsByTagNameNS("*","Override")).some(i=>(i.getAttribute("PartName")||"").toLowerCase()===String(t).toLowerCase()))return!1;let o=e.createElementNS(Ks,"Override");return o.setAttribute("PartName",t),o.setAttribute("ContentType",r),e.documentElement.appendChild(o),!0}function ja(e,t,r){let n=e.getElementsByTagNameNS("*","Relationships")[0]||e.documentElement,a=Array.from(n.getElementsByTagNameNS("*","Relationship"));if(a.some(l=>(l.getAttribute("Type")||"")===t))return!1;let i=0;for(let l of a){let c=l.getAttribute("Id")||"",u=Number.parseInt(c.replace(/^rId/i,""),10);Number.isFinite(u)&&(i=Math.max(i,u))}let s=e.createElementNS(Ys,"Relationship");return s.setAttribute("Id",`rId${i+1}`),s.setAttribute("Type",t),s.setAttribute("Target",r),n.appendChild(s),!0}async function pe(e,t){let r=e.file(t);return r?r.async("string"):null}async function el(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{},a=typeof r?.mergeNumberingXml=="function"?r.mergeNumberingXml:null,o=(Array.isArray(t)?t:[t]).filter(Boolean);if(o.length===0)return;let i=await pe(e,qt),s=i||null;for(let f of o){if(!s){s=f;continue}s=a?a(s,f):f}n(i?"[Demo] Merging numbering.xml payload(s) into existing numbering definitions":"[Demo] Adding numbering.xml"),e.file(qt,s);let l=B(),c=Q(),u=await pe(e,We);if(u){let f=l.parseFromString(u,"application/xml");Ua(f,"/word/numbering.xml",Xa)&&e.file(We,c.serializeToString(f))}let m=await pe(e,He);if(m){let f=l.parseFromString(m,"application/xml");ja(f,$a,"numbering.xml")&&e.file(He,c.serializeToString(f))}}async function tl(e,t,r={}){let n=typeof r?.onInfo=="function"?r.onInfo:()=>{};if(!t)return;let a=B(),o=Q(),i=await pe(e,Tt);if(!i)n("[Demo] Adding comments.xml"),e.file(Tt,t);else{let c=Oe(i,"word/comments.xml (existing)"),u=Oe(t,"word/comments.xml (incoming)"),m=c.documentElement,f=new Set(Array.from(m.getElementsByTagNameNS(ae,"comment")).map(p=>p.getAttribute("w:id")||p.getAttribute("id")).filter(Boolean));for(let p of Array.from(u.documentElement.getElementsByTagNameNS(ae,"comment"))){let g=p.getAttribute("w:id")||p.getAttribute("id");if(g&&f.has(g))throw new Error(`Duplicate comment id: ${g}`);m.appendChild(c.importNode(p,!0))}e.file(Tt,o.serializeToString(c))}let s=await pe(e,We);if(s){let c=a.parseFromString(s,"application/xml");Ua(c,"/word/comments.xml",za)&&e.file(We,o.serializeToString(c))}let l=await pe(e,He);if(l){let c=a.parseFromString(l,"application/xml");ja(c,Da,"comments.xml")&&e.file(He,o.serializeToString(c))}}async function rl(e){let t=await pe(e,Fa);if(!t)throw new Error("Validation failed: missing word/document.xml");let r=Oe(t,Fa);Ha(r);let n=Zr(r);if(!n)throw new Error("Validation failed: word/document.xml has no w:body");let a=Array.from(n.childNodes||[]).filter(d=>d.nodeType===1),o=a.map((d,w)=>({node:d,index:w})).filter(d=>Qt(d.node)).map(d=>d.index);if(o.length>1)throw new Error("Validation failed: multiple body-level w:sectPr");if(o.length===1&&o[0]!==a.length-1)throw new Error("Validation failed: w:sectPr not last");let i=r.getElementsByTagNameNS(ae,"tc");for(let d of Array.from(i))for(let w of Array.from(d.childNodes||[]).filter(h=>h.nodeType===1))if(w.namespaceURI===ae&&w.localName==="p"&&Array.from(w.childNodes||[]).some(b=>b.nodeType===1&&b.namespaceURI===ae&&b.localName==="p"))throw new Error("Validation failed: nested w:p");let s=r.getElementsByTagNameNS(ae,"numPr").length>0,l=r.getElementsByTagNameNS(ae,"commentRangeStart").length>0||r.getElementsByTagNameNS(ae,"commentRangeEnd").length>0||r.getElementsByTagNameNS(ae,"commentReference").length>0,c=await pe(e,qt),u=await pe(e,Tt);if(c)Oe(c,qt);else if(s)throw new Error("Validation failed: numbering used but part missing");if(u)Oe(u,Tt);else if(l)throw new Error("Validation failed: comments used but part missing");let m=await pe(e,We);if(!m)throw new Error(`Validation failed: missing ${We}`);let f=Oe(m,We),p=await pe(e,He);if(!p)throw new Error(`Validation failed: missing ${He}`);let g=Oe(p,He);if(c){let d=Array.from(f.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/numbering.xml"&&(h.getAttribute("ContentType")||"")===Xa),w=Array.from(g.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===$a);if(!d)throw new Error("Validation failed: numbering CT override missing");if(!w)throw new Error("Validation failed: numbering rel missing")}if(u){let d=Array.from(f.getElementsByTagNameNS("*","Override")).some(h=>(h.getAttribute("PartName")||"").toLowerCase()==="/word/comments.xml"&&(h.getAttribute("ContentType")||"")===za),w=Array.from(g.getElementsByTagNameNS("*","Relationship")).some(h=>(h.getAttribute("Type")||"")===Da);if(!d)throw new Error("Validation failed: comments CT override missing");if(!w)throw new Error("Validation failed: comments rel missing")}}var at=Object.freeze({STRUCTURED_LIST_DIRECT:"structured_list_direct",EMPTY_FORMATTED_TEXT:"empty_formatted_text",EMPTY_HTML:"empty_html",BLOCK_HTML:"block_html",OOXML_ENGINE:"ooxml_engine"});function Va(e){return!e||typeof e!="string"?e||"":e.replace(/\\n/g,`
|
|
195
|
-
`).replace(/\\t/g," ").replace(/\\r/g,"\r")}function
|
|
196
|
-
`)&&n.type!=="text"?{kind:
|
|
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(`
|
|
197
198
|
|
|
198
|
-
`);return t||r||n||a||
|
|
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};
|
|
199
200
|
//# sourceMappingURL=docx-redline-js.esm.min.js.map
|