UNPKG

@leonwerth/vue-diff

Version:

Vue diff

12 lines (11 loc) 33.5 kB
(function(I,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],g):(I=typeof globalThis<"u"?globalThis:I||self,g(I["vue-diff"]={},I.Vue))})(this,function(I,g){"use strict";var H=document.createElement("style");H.textContent=`@charset "UTF-8";.text-compare-page{overflow:hidden;height:100%}.text-compare-page .text-title{width:100%;height:50px;background:#1564bb;font-size:18px;font-weight:400;color:#fff;text-align:center;line-height:50px}.text-compare-page .text-compare{display:flex;padding:20px 0 20px 20px}.text-compare-page .text-compare .text-compare-article{width:100%;background:#ffffff;box-shadow:0 8px 18px #4b4a8c38;border-radius:8px;margin-right:20px}.text-compare-page .text-compare .text-compare-article .text-compare-top{width:100%;height:57px;border-bottom:1px solid #dcdcdc;line-height:57px;position:relative;font-size:18px;font-weight:400;color:#454545}.text-compare-page .text-compare .text-compare-article .text-compare-top .input-group{position:absolute;right:10px;user-select:none;cursor:pointer;font-size:16px;font-weight:400;color:#4d4d59}.text-compare-page .text-compare .text-compare-article .text-compare-top .input-group>input{padding-right:12px;margin-left:5px}.text-compare-page .text-compare .text-compare-article .text-compare-top .input-group>label{padding:0 10px;margin-top:5px}.text-compare-page .text-compare .text-compare-article .text-compare-bottom{width:100%;display:flex;padding-top:20px;padding-bottom:20px;padding-right:3%}.text-compare-page .text-compare .text-compare-article .text-compare-bottom .text-compare-left,.text-compare-page .text-compare .text-compare-article .text-compare-bottom .text-compare-right{width:calc(50% - 40px);overflow:auto;margin-left:3%;padding:0 0 0 13px;border:13px solid #eeeeee}.text-compare-page .text-compare .text-compare-article .text-compare-bottom .text-compare-left .text-compare-article1,.text-compare-page .text-compare .text-compare-article .text-compare-bottom .text-compare-right .text-compare-article1{background:#fff}.text-compare-page .text-compare .text-compare-diff{width:348px;background:#ffffff;box-shadow:0 8px 18px #4b4a8c38;border-radius:8px}.text-compare-page .text-compare .text-compare-diff .text-compare-top{height:57px;border-bottom:1px solid #dcdcdc;line-height:57px;padding-left:20px;font-size:18px;font-weight:400;color:#454545}.text-compare-page .text-compare .text-compare-diff .text-compare-bottom{padding:10px 20px;height:calc(100% - 57px)}.text-compare-page .text-compare .text-compare-diff .text-compare-bottom>.flex{background:#eeeeee;border-radius:4px;height:43px;width:100%;display:flex}.text-compare-page .text-compare .text-compare-diff .text-compare-bottom .group-title.active{background:#3e74ef}.text-compare-page .text-compare .text-compare-diff .text-compare-bottom .group-title.active>div{color:#fff!important}.text-compare-page .text-compare .text-compare-diff .text-compare-bottom .group-title{background:#eeeeee;width:25%;position:relative;display:flex;cursor:pointer}.text-compare-page .text-compare .text-compare-diff .text-compare-bottom .group-title div{width:100%;text-align:center;line-height:42px;font-size:14px;font-weight:400;color:#757575}.text-compare-page .text-compare .text-compare-diff .text-compare-bottom .group-title .line{height:43px;width:1px;background-color:#d2d2d2;position:absolute;right:0px}.text-compare-page .text-compare .text-compare-diff .card-group{overflow:auto;height:calc(100% - 74px)}.text-compare-page .text-compare .text-compare-diff .card-group .group-card-card{margin-top:10px;cursor:pointer}.text-compare-page .text-compare .text-compare-diff .card-group .group-card-card.active .group-card-title{background:#9ac685}.text-compare-page .text-compare .text-compare-diff .card-group .group-card-card.active .group-card-content{border:2px solid #9ac685}.text-compare-page .text-compare .text-compare-diff .card-group .group-card-card .group-card-title{height:50px;background:#bfbfbf;border-radius:4px 4px 0 0;font-size:16px;font-weight:400;color:#fff;line-height:50px;padding-left:10px}.text-compare-page .text-compare .text-compare-diff .card-group .group-card-card .group-card-content{padding:21px 23px;font-size:16px;font-weight:400;color:#6f6f6f;border:2px solid #bfbfbf;border-radius:0 0 4px 4px}.vue-diff-cell-removed{background-color:#ff00001a;display:inline-block}.vue-diff-cell-removed span.modified{background-color:#ff000026}.vue-diff-cell-removed code:before{content:"-"}.vue-diff-cell-added{background-color:#00ff801a;display:inline-block}.vue-diff-cell-added span.modified{background-color:#00ff8026}.vue-diff-cell-added code:before{content:"+"}.vue-diff-cell-disabled{background-color:#8080801a;display:inline-block}.vue-diff-cell-fold.lineNum{opacity:.8;font-size:.8em}.vue-diff-cell-fold.lineNum:before{content:">"}.vue-diff-cell-fold.code{text-align:center}.vue-diff-cell-fold.code:before{color:#999;content:"⋯⋯"} `,document.head.appendChild(H);var F={},V={get exports(){return F},set exports(d){F=d}};(function(d){var o=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},p=-1,u=1,f=0;o.Diff=function(e,t){return[e,t]},o.prototype.diff_main=function(e,t,r,a){typeof a>"u"&&(this.Diff_Timeout<=0?a=Number.MAX_VALUE:a=new Date().getTime()+this.Diff_Timeout*1e3);var i=a;if(e==null||t==null)throw new Error("Null input. (diff_main)");if(e==t)return e?[new o.Diff(f,e)]:[];typeof r>"u"&&(r=!0);var n=r,l=this.diff_commonPrefix(e,t),s=e.substring(0,l);e=e.substring(l),t=t.substring(l),l=this.diff_commonSuffix(e,t);var h=e.substring(e.length-l);e=e.substring(0,e.length-l),t=t.substring(0,t.length-l);var c=this.diff_compute_(e,t,n,i);return s&&c.unshift(new o.Diff(f,s)),h&&c.push(new o.Diff(f,h)),this.diff_cleanupMerge(c),c},o.prototype.diff_compute_=function(e,t,r,a){var i;if(!e)return[new o.Diff(u,t)];if(!t)return[new o.Diff(p,e)];var n=e.length>t.length?e:t,l=e.length>t.length?t:e,s=n.indexOf(l);if(s!=-1)return i=[new o.Diff(u,n.substring(0,s)),new o.Diff(f,l),new o.Diff(u,n.substring(s+l.length))],e.length>t.length&&(i[0][0]=i[2][0]=p),i;if(l.length==1)return[new o.Diff(p,e),new o.Diff(u,t)];var h=this.diff_halfMatch_(e,t);if(h){var c=h[0],m=h[1],v=h[2],w=h[3],_=h[4],b=this.diff_main(c,v,r,a),M=this.diff_main(m,w,r,a);return b.concat([new o.Diff(f,_)],M)}return r&&e.length>100&&t.length>100?this.diff_lineMode_(e,t,a):this.diff_bisect_(e,t,a)},o.prototype.diff_lineMode_=function(e,t,r){var a=this.diff_linesToChars_(e,t);e=a.chars1,t=a.chars2;var i=a.lineArray,n=this.diff_main(e,t,!1,r);this.diff_charsToLines_(n,i),this.diff_cleanupSemantic(n),n.push(new o.Diff(f,""));for(var l=0,s=0,h=0,c="",m="";l<n.length;){switch(n[l][0]){case u:h++,m+=n[l][1];break;case p:s++,c+=n[l][1];break;case f:if(s>=1&&h>=1){n.splice(l-s-h,s+h),l=l-s-h;for(var v=this.diff_main(c,m,!1,r),w=v.length-1;w>=0;w--)n.splice(l,0,v[w]);l=l+v.length}h=0,s=0,c="",m="";break}l++}return n.pop(),n},o.prototype.diff_bisect_=function(e,t,r){for(var a=e.length,i=t.length,n=Math.ceil((a+i)/2),l=n,s=2*n,h=new Array(s),c=new Array(s),m=0;m<s;m++)h[m]=-1,c[m]=-1;h[l+1]=0,c[l+1]=0;for(var v=a-i,w=v%2!=0,_=0,b=0,M=0,T=0,y=0;y<n&&!(new Date().getTime()>r);y++){for(var D=-y+_;D<=y-b;D+=2){var k=l+D,E;D==-y||D!=y&&h[k-1]<h[k+1]?E=h[k+1]:E=h[k-1]+1;for(var B=E-D;E<a&&B<i&&e.charAt(E)==t.charAt(B);)E++,B++;if(h[k]=E,E>a)b+=2;else if(B>i)_+=2;else if(w){var S=l+v-D;if(S>=0&&S<s&&c[S]!=-1){var A=a-c[S];if(E>=A)return this.diff_bisectSplit_(e,t,E,B,r)}}}for(var C=-y+M;C<=y-T;C+=2){var S=l+C,A;C==-y||C!=y&&c[S-1]<c[S+1]?A=c[S+1]:A=c[S-1]+1;for(var N=A-C;A<a&&N<i&&e.charAt(a-A-1)==t.charAt(i-N-1);)A++,N++;if(c[S]=A,A>a)T+=2;else if(N>i)M+=2;else if(!w){var k=l+v-C;if(k>=0&&k<s&&h[k]!=-1){var E=h[k],B=l+E-k;if(A=a-A,E>=A)return this.diff_bisectSplit_(e,t,E,B,r)}}}}return[new o.Diff(p,e),new o.Diff(u,t)]},o.prototype.diff_bisectSplit_=function(e,t,r,a,i){var n=e.substring(0,r),l=t.substring(0,a),s=e.substring(r),h=t.substring(a),c=this.diff_main(n,l,!1,i),m=this.diff_main(s,h,!1,i);return c.concat(m)},o.prototype.diff_linesToChars_=function(e,t){var r=[],a={};r[0]="";function i(h){for(var c="",m=0,v=-1,w=r.length;v<h.length-1;){v=h.indexOf(` `,m),v==-1&&(v=h.length-1);var _=h.substring(m,v+1);(a.hasOwnProperty?a.hasOwnProperty(_):a[_]!==void 0)?c+=String.fromCharCode(a[_]):(w==n&&(_=h.substring(m),v=h.length),c+=String.fromCharCode(w),a[_]=w,r[w++]=_),m=v+1}return c}var n=4e4,l=i(e);n=65535;var s=i(t);return{chars1:l,chars2:s,lineArray:r}},o.prototype.diff_charsToLines_=function(e,t){for(var r=0;r<e.length;r++){for(var a=e[r][1],i=[],n=0;n<a.length;n++)i[n]=t[a.charCodeAt(n)];e[r][1]=i.join("")}},o.prototype.diff_commonPrefix=function(e,t){if(!e||!t||e.charAt(0)!=t.charAt(0))return 0;for(var r=0,a=Math.min(e.length,t.length),i=a,n=0;r<i;)e.substring(n,i)==t.substring(n,i)?(r=i,n=r):a=i,i=Math.floor((a-r)/2+r);return i},o.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,a=Math.min(e.length,t.length),i=a,n=0;r<i;)e.substring(e.length-i,e.length-n)==t.substring(t.length-i,t.length-n)?(r=i,n=r):a=i,i=Math.floor((a-r)/2+r);return i},o.prototype.diff_commonOverlap_=function(e,t){var r=e.length,a=t.length;if(r==0||a==0)return 0;r>a?e=e.substring(r-a):r<a&&(t=t.substring(0,r));var i=Math.min(r,a);if(e==t)return i;for(var n=0,l=1;;){var s=e.substring(i-l),h=t.indexOf(s);if(h==-1)return n;l+=h,(h==0||e.substring(i-l)==t.substring(0,l))&&(n=l,l++)}},o.prototype.diff_halfMatch_=function(e,t){if(this.Diff_Timeout<=0)return null;var r=e.length>t.length?e:t,a=e.length>t.length?t:e;if(r.length<4||a.length*2<r.length)return null;var i=this;function n(b,M,T){for(var y=b.substring(T,T+Math.floor(b.length/4)),D=-1,k="",E,B,S,A;(D=M.indexOf(y,D+1))!=-1;){var C=i.diff_commonPrefix(b.substring(T),M.substring(D)),N=i.diff_commonSuffix(b.substring(0,T),M.substring(0,D));k.length<N+C&&(k=M.substring(D-N,D)+M.substring(D,D+C),E=b.substring(0,T-N),B=b.substring(T+C),S=M.substring(0,D-N),A=M.substring(D+C))}return k.length*2>=b.length?[E,B,S,A,k]:null}var l=n(r,a,Math.ceil(r.length/4)),s=n(r,a,Math.ceil(r.length/2)),h;if(!l&&!s)return null;s?l?h=l[4].length>s[4].length?l:s:h=s:h=l;var c,m,v,w;e.length>t.length?(c=h[0],m=h[1],v=h[2],w=h[3]):(v=h[0],w=h[1],c=h[2],m=h[3]);var _=h[4];return[c,m,v,w,_]},o.prototype.diff_cleanupSemantic=function(e){for(var t=!1,r=[],a=0,i=null,n=0,l=0,s=0,h=0,c=0;n<e.length;)e[n][0]==f?(r[a++]=n,l=h,s=c,h=0,c=0,i=e[n][1]):(e[n][0]==u?h+=e[n][1].length:c+=e[n][1].length,i&&i.length<=Math.max(l,s)&&i.length<=Math.max(h,c)&&(e.splice(r[a-1],0,new o.Diff(p,i)),e[r[a-1]+1][0]=u,a--,a--,n=a>0?r[a-1]:-1,l=0,s=0,h=0,c=0,i=null,t=!0)),n++;for(t&&this.diff_cleanupMerge(e),this.diff_cleanupSemanticLossless(e),n=1;n<e.length;){if(e[n-1][0]==p&&e[n][0]==u){var m=e[n-1][1],v=e[n][1],w=this.diff_commonOverlap_(m,v),_=this.diff_commonOverlap_(v,m);w>=_?(w>=m.length/2||w>=v.length/2)&&(e.splice(n,0,new o.Diff(f,v.substring(0,w))),e[n-1][1]=m.substring(0,m.length-w),e[n+1][1]=v.substring(w),n++):(_>=m.length/2||_>=v.length/2)&&(e.splice(n,0,new o.Diff(f,m.substring(0,_))),e[n-1][0]=u,e[n-1][1]=v.substring(0,v.length-_),e[n+1][0]=p,e[n+1][1]=m.substring(_),n++),n++}n++}},o.prototype.diff_cleanupSemanticLossless=function(e){function t(_,b){if(!_||!b)return 6;var M=_.charAt(_.length-1),T=b.charAt(0),y=M.match(o.nonAlphaNumericRegex_),D=T.match(o.nonAlphaNumericRegex_),k=y&&M.match(o.whitespaceRegex_),E=D&&T.match(o.whitespaceRegex_),B=k&&M.match(o.linebreakRegex_),S=E&&T.match(o.linebreakRegex_),A=B&&_.match(o.blanklineEndRegex_),C=S&&b.match(o.blanklineStartRegex_);return A||C?5:B||S?4:y&&!k&&E?3:k||E?2:y||D?1:0}for(var r=1;r<e.length-1;){if(e[r-1][0]==f&&e[r+1][0]==f){var a=e[r-1][1],i=e[r][1],n=e[r+1][1],l=this.diff_commonSuffix(a,i);if(l){var s=i.substring(i.length-l);a=a.substring(0,a.length-l),i=s+i.substring(0,i.length-l),n=s+n}for(var h=a,c=i,m=n,v=t(a,i)+t(i,n);i.charAt(0)===n.charAt(0);){a+=i.charAt(0),i=i.substring(1)+n.charAt(0),n=n.substring(1);var w=t(a,i)+t(i,n);w>=v&&(v=w,h=a,c=i,m=n)}e[r-1][1]!=h&&(h?e[r-1][1]=h:(e.splice(r-1,1),r--),e[r][1]=c,m?e[r+1][1]=m:(e.splice(r+1,1),r--))}r++}},o.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/,o.whitespaceRegex_=/\s/,o.linebreakRegex_=/[\r\n]/,o.blanklineEndRegex_=/\n\r?\n$/,o.blanklineStartRegex_=/^\r?\n\r?\n/,o.prototype.diff_cleanupEfficiency=function(e){for(var t=!1,r=[],a=0,i=null,n=0,l=!1,s=!1,h=!1,c=!1;n<e.length;)e[n][0]==f?(e[n][1].length<this.Diff_EditCost&&(h||c)?(r[a++]=n,l=h,s=c,i=e[n][1]):(a=0,i=null),h=c=!1):(e[n][0]==p?c=!0:h=!0,i&&(l&&s&&h&&c||i.length<this.Diff_EditCost/2&&l+s+h+c==3)&&(e.splice(r[a-1],0,new o.Diff(p,i)),e[r[a-1]+1][0]=u,a--,i=null,l&&s?(h=c=!0,a=0):(a--,n=a>0?r[a-1]:-1,h=c=!1),t=!0)),n++;t&&this.diff_cleanupMerge(e)},o.prototype.diff_cleanupMerge=function(e){e.push(new o.Diff(f,""));for(var t=0,r=0,a=0,i="",n="",l;t<e.length;)switch(e[t][0]){case u:a++,n+=e[t][1],t++;break;case p:r++,i+=e[t][1],t++;break;case f:r+a>1?(r!==0&&a!==0&&(l=this.diff_commonPrefix(n,i),l!==0&&(t-r-a>0&&e[t-r-a-1][0]==f?e[t-r-a-1][1]+=n.substring(0,l):(e.splice(0,0,new o.Diff(f,n.substring(0,l))),t++),n=n.substring(l),i=i.substring(l)),l=this.diff_commonSuffix(n,i),l!==0&&(e[t][1]=n.substring(n.length-l)+e[t][1],n=n.substring(0,n.length-l),i=i.substring(0,i.length-l))),t-=r+a,e.splice(t,r+a),i.length&&(e.splice(t,0,new o.Diff(p,i)),t++),n.length&&(e.splice(t,0,new o.Diff(u,n)),t++),t++):t!==0&&e[t-1][0]==f?(e[t-1][1]+=e[t][1],e.splice(t,1)):t++,a=0,r=0,i="",n="";break}e[e.length-1][1]===""&&e.pop();var s=!1;for(t=1;t<e.length-1;)e[t-1][0]==f&&e[t+1][0]==f&&(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)},o.prototype.diff_xIndex=function(e,t){var r=0,a=0,i=0,n=0,l;for(l=0;l<e.length&&(e[l][0]!==u&&(r+=e[l][1].length),e[l][0]!==p&&(a+=e[l][1].length),!(r>t));l++)i=r,n=a;return e.length!=l&&e[l][0]===p?n:n+(t-i)},o.prototype.diff_prettyHtml=function(e){for(var t=[],r=/&/g,a=/</g,i=/>/g,n=/\n/g,l=0;l<e.length;l++){var s=e[l][0],h=e[l][1],c=h.replace(r,"&amp;").replace(a,"&lt;").replace(i,"&gt;").replace(n,"&para;<br>");switch(s){case u:t[l]='<ins style="background:#e6ffe6;">'+c+"</ins>";break;case p:t[l]='<del style="background:#ffe6e6;">'+c+"</del>";break;case f:t[l]="<span>"+c+"</span>";break}}return t.join("")},o.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("")},o.prototype.diff_text2=function(e){for(var t=[],r=0;r<e.length;r++)e[r][0]!==p&&(t[r]=e[r][1]);return t.join("")},o.prototype.diff_levenshtein=function(e){for(var t=0,r=0,a=0,i=0;i<e.length;i++){var n=e[i][0],l=e[i][1];switch(n){case u:r+=l.length;break;case p:a+=l.length;break;case f:t+=Math.max(r,a),r=0,a=0;break}}return t+=Math.max(r,a),t},o.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 p:t[r]="-"+e[r][1].length;break;case f:t[r]="="+e[r][1].length;break}return t.join(" ").replace(/%20/g," ")},o.prototype.diff_fromDelta=function(e,t){for(var r=[],a=0,i=0,n=t.split(/\t/g),l=0;l<n.length;l++){var s=n[l].substring(1);switch(n[l].charAt(0)){case"+":try{r[a++]=new o.Diff(u,decodeURI(s))}catch{throw new Error("Illegal escape in diff_fromDelta: "+s)}break;case"-":case"=":var h=parseInt(s,10);if(isNaN(h)||h<0)throw new Error("Invalid number in diff_fromDelta: "+s);var c=e.substring(i,i+=h);n[l].charAt(0)=="="?r[a++]=new o.Diff(f,c):r[a++]=new o.Diff(p,c);break;default:if(n[l])throw new Error("Invalid diff operation in diff_fromDelta: "+n[l])}}if(i!=e.length)throw new Error("Delta length ("+i+") does not equal source text length ("+e.length+").");return r},o.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},o.prototype.match_bitap_=function(e,t,r){if(t.length>this.Match_MaxBits)throw new Error("Pattern too long for this browser.");var a=this.match_alphabet_(t),i=this;function n(E,B){var S=E/t.length,A=Math.abs(r-B);return i.Match_Distance?S+A/i.Match_Distance:A?1:S}var l=this.Match_Threshold,s=e.indexOf(t,r);s!=-1&&(l=Math.min(n(0,s),l),s=e.lastIndexOf(t,r+t.length),s!=-1&&(l=Math.min(n(0,s),l)));var h=1<<t.length-1;s=-1;for(var c,m,v=t.length+e.length,w,_=0;_<t.length;_++){for(c=0,m=v;c<m;)n(_,r+m)<=l?c=m:v=m,m=Math.floor((v-c)/2+c);v=m;var b=Math.max(1,r-m+1),M=Math.min(r+m,e.length)+t.length,T=Array(M+2);T[M+1]=(1<<_)-1;for(var y=M;y>=b;y--){var D=a[e.charAt(y-1)];if(_===0?T[y]=(T[y+1]<<1|1)&D:T[y]=(T[y+1]<<1|1)&D|((w[y+1]|w[y])<<1|1)|w[y+1],T[y]&h){var k=n(_,y-1);if(k<=l)if(l=k,s=y-1,s>r)b=Math.max(1,2*r-s);else break}}if(n(_+1,r)>l)break;w=T}return s},o.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},o.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),a=0;t.indexOf(r)!=t.lastIndexOf(r)&&r.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin;)a+=this.Patch_Margin,r=t.substring(e.start2-a,e.start2+e.length1+a);a+=this.Patch_Margin;var i=t.substring(e.start2-a,e.start2);i&&e.diffs.unshift(new o.Diff(f,i));var n=t.substring(e.start2+e.length1,e.start2+e.length1+a);n&&e.diffs.push(new o.Diff(f,n)),e.start1-=i.length,e.start2-=i.length,e.length1+=i.length+n.length,e.length2+=i.length+n.length}},o.prototype.patch_make=function(e,t,r){var a,i;if(typeof e=="string"&&typeof t=="string"&&typeof r>"u")a=e,i=this.diff_main(a,t,!0),i.length>2&&(this.diff_cleanupSemantic(i),this.diff_cleanupEfficiency(i));else if(e&&typeof e=="object"&&typeof t>"u"&&typeof r>"u")i=e,a=this.diff_text1(i);else if(typeof e=="string"&&t&&typeof t=="object"&&typeof r>"u")a=e,i=t;else if(typeof e=="string"&&typeof t=="string"&&r&&typeof r=="object")a=e,i=r;else throw new Error("Unknown call format to patch_make.");if(i.length===0)return[];for(var n=[],l=new o.patch_obj,s=0,h=0,c=0,m=a,v=a,w=0;w<i.length;w++){var _=i[w][0],b=i[w][1];switch(!s&&_!==f&&(l.start1=h,l.start2=c),_){case u:l.diffs[s++]=i[w],l.length2+=b.length,v=v.substring(0,c)+b+v.substring(c);break;case p:l.length1+=b.length,l.diffs[s++]=i[w],v=v.substring(0,c)+v.substring(c+b.length);break;case f:b.length<=2*this.Patch_Margin&&s&&i.length!=w+1?(l.diffs[s++]=i[w],l.length1+=b.length,l.length2+=b.length):b.length>=2*this.Patch_Margin&&s&&(this.patch_addContext_(l,m),n.push(l),l=new o.patch_obj,s=0,m=v,h=c);break}_!==u&&(h+=b.length),_!==p&&(c+=b.length)}return s&&(this.patch_addContext_(l,m),n.push(l)),n},o.prototype.patch_deepCopy=function(e){for(var t=[],r=0;r<e.length;r++){var a=e[r],i=new o.patch_obj;i.diffs=[];for(var n=0;n<a.diffs.length;n++)i.diffs[n]=new o.Diff(a.diffs[n][0],a.diffs[n][1]);i.start1=a.start1,i.start2=a.start2,i.length1=a.length1,i.length2=a.length2,t[r]=i}return t},o.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 a=0,i=[],n=0;n<e.length;n++){var l=e[n].start2+a,s=this.diff_text1(e[n].diffs),h,c=-1;if(s.length>this.Match_MaxBits?(h=this.match_main(t,s.substring(0,this.Match_MaxBits),l),h!=-1&&(c=this.match_main(t,s.substring(s.length-this.Match_MaxBits),l+s.length-this.Match_MaxBits),(c==-1||h>=c)&&(h=-1))):h=this.match_main(t,s,l),h==-1)i[n]=!1,a-=e[n].length2-e[n].length1;else{i[n]=!0,a=h-l;var m;if(c==-1?m=t.substring(h,h+s.length):m=t.substring(h,c+this.Match_MaxBits),s==m)t=t.substring(0,h)+this.diff_text2(e[n].diffs)+t.substring(h+s.length);else{var v=this.diff_main(s,m,!1);if(s.length>this.Match_MaxBits&&this.diff_levenshtein(v)/s.length>this.Patch_DeleteThreshold)i[n]=!1;else{this.diff_cleanupSemanticLossless(v);for(var w=0,_,b=0;b<e[n].diffs.length;b++){var M=e[n].diffs[b];M[0]!==f&&(_=this.diff_xIndex(v,w)),M[0]===u?t=t.substring(0,h+_)+M[1]+t.substring(h+_):M[0]===p&&(t=t.substring(0,h+_)+t.substring(h+this.diff_xIndex(v,w+M[1].length))),M[0]!==p&&(w+=M[1].length)}}}}}return t=t.substring(r.length,t.length-r.length),[t,i]},o.prototype.patch_addPadding=function(e){for(var t=this.Patch_Margin,r="",a=1;a<=t;a++)r+=String.fromCharCode(a);for(var a=0;a<e.length;a++)e[a].start1+=t,e[a].start2+=t;var i=e[0],n=i.diffs;if(n.length==0||n[0][0]!=f)n.unshift(new o.Diff(f,r)),i.start1-=t,i.start2-=t,i.length1+=t,i.length2+=t;else if(t>n[0][1].length){var l=t-n[0][1].length;n[0][1]=r.substring(n[0][1].length)+n[0][1],i.start1-=l,i.start2-=l,i.length1+=l,i.length2+=l}if(i=e[e.length-1],n=i.diffs,n.length==0||n[n.length-1][0]!=f)n.push(new o.Diff(f,r)),i.length1+=t,i.length2+=t;else if(t>n[n.length-1][1].length){var l=t-n[n.length-1][1].length;n[n.length-1][1]+=r.substring(0,l),i.length1+=l,i.length2+=l}return r},o.prototype.patch_splitMax=function(e){for(var t=this.Match_MaxBits,r=0;r<e.length;r++)if(!(e[r].length1<=t)){var a=e[r];e.splice(r--,1);for(var i=a.start1,n=a.start2,l="";a.diffs.length!==0;){var s=new o.patch_obj,h=!0;for(s.start1=i-l.length,s.start2=n-l.length,l!==""&&(s.length1=s.length2=l.length,s.diffs.push(new o.Diff(f,l)));a.diffs.length!==0&&s.length1<t-this.Patch_Margin;){var c=a.diffs[0][0],m=a.diffs[0][1];c===u?(s.length2+=m.length,n+=m.length,s.diffs.push(a.diffs.shift()),h=!1):c===p&&s.diffs.length==1&&s.diffs[0][0]==f&&m.length>2*t?(s.length1+=m.length,i+=m.length,h=!1,s.diffs.push(new o.Diff(c,m)),a.diffs.shift()):(m=m.substring(0,t-s.length1-this.Patch_Margin),s.length1+=m.length,i+=m.length,c===f?(s.length2+=m.length,n+=m.length):h=!1,s.diffs.push(new o.Diff(c,m)),m==a.diffs[0][1]?a.diffs.shift():a.diffs[0][1]=a.diffs[0][1].substring(m.length))}l=this.diff_text2(s.diffs),l=l.substring(l.length-this.Patch_Margin);var v=this.diff_text1(a.diffs).substring(0,this.Patch_Margin);v!==""&&(s.length1+=v.length,s.length2+=v.length,s.diffs.length!==0&&s.diffs[s.diffs.length-1][0]===f?s.diffs[s.diffs.length-1][1]+=v:s.diffs.push(new o.Diff(f,v))),h||e.splice(++r,0,s)}}},o.prototype.patch_toText=function(e){for(var t=[],r=0;r<e.length;r++)t[r]=e[r];return t.join("")},o.prototype.patch_fromText=function(e){var t=[];if(!e)return t;for(var r=e.split(` `),a=0,i=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;a<r.length;){var n=r[a].match(i);if(!n)throw new Error("Invalid patch string: "+r[a]);var l=new o.patch_obj;for(t.push(l),l.start1=parseInt(n[1],10),n[2]===""?(l.start1--,l.length1=1):n[2]=="0"?l.length1=0:(l.start1--,l.length1=parseInt(n[2],10)),l.start2=parseInt(n[3],10),n[4]===""?(l.start2--,l.length2=1):n[4]=="0"?l.length2=0:(l.start2--,l.length2=parseInt(n[4],10)),a++;a<r.length;){var s=r[a].charAt(0);try{var h=decodeURI(r[a].substring(1))}catch{throw new Error("Illegal escape in patch_fromText: "+h)}if(s=="-")l.diffs.push(new o.Diff(p,h));else if(s=="+")l.diffs.push(new o.Diff(u,h));else if(s==" ")l.diffs.push(new o.Diff(f,h));else{if(s=="@")break;if(s!=="")throw new Error('Invalid patch mode "'+s+'" in: '+h)}a++}}return t},o.patch_obj=function(){this.diffs=[],this.start1=null,this.start2=null,this.length1=0,this.length2=0},o.patch_obj.prototype.toString=function(){var 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+` @@ `],a,i=0;i<this.diffs.length;i++){switch(this.diffs[i][0]){case u:a="+";break;case p:a="-";break;case f:a=" ";break}r[i+1]=a+encodeURI(this.diffs[i][1])+` `}return r.join("").replace(/%20/g," ")},d.exports=o,d.exports.diff_match_patch=o,d.exports.DIFF_DELETE=p,d.exports.DIFF_INSERT=u,d.exports.DIFF_EQUAL=f})(V);var x=(d=>(d[d.removed=-1]="removed",d[d.equal=0]="equal",d[d.added=1]="added",d[d.disabled=2]="disabled",d))(x||{});const L=d=>x[d]?x[d]:"disabled",z=d=>{const o=[],p={prev:0,current:0};return d.map(u=>{const f=u[0][1].replace(/\n$/,"").split(` `),e=u[1][1].replace(/\n$/,"").split(` `),t=Math.max(f.length,e.length);for(let r=0;r<t;r++){const a=L(u[0][0])!=="disabled"&&typeof f[r]<"u",i=L(u[1][0])!=="disabled"&&typeof e[r]<"u";a&&(p.prev=p.prev+1),i&&(p.current=p.current+1);const n=!!(L(u[0][0]).match(/added|removed/)&&L(u[1][0]).match(/added|removed/));o.push([{type:a?L(u[0][0]):"disabled",lineNum:a?p.prev:void 0,value:a?f[r]:void 0,chkWords:n},{type:i?L(u[1][0]):"disabled",lineNum:i?p.current:void 0,value:i?e[r]:void 0,chkWords:n}])}}),o},$=d=>{const o=[];let p=0;return d.map(u=>{const f=u[0][1].replace(/\n$/,"").split(` `),e=u[1][1].replace(/\n$/,"").split(` `);f.map(t=>{L(u[0][0])==="removed"&&o.push([{type:L(u[0][0]),lineNum:void 0,value:t}])}),e.map(t=>{L(u[1][0])!=="disabled"&&(p=p+1,o.push([{type:L(u[1][0]),lineNum:p,value:t}]))})}),o},O=(d,o,p)=>{function u(e,t){const r=new F.diff_match_patch,a=r.diff_linesToChars_(e,t),i=a.chars1,n=a.chars2,l=a.lineArray,s=r.diff_main(i,n,!1);return r.diff_charsToLines_(s,l),s}const f=u(o,p).reduce((e,t)=>{const r=L(t[0]);if(r==="equal"&&e.push([t]),r==="removed"&&e.push([t]),r==="added"){const a=e.length&&e[e.length-1][0]?e[e.length-1][0]:null;a&&L(a[0])==="removed"?e[e.length-1].push(t):e.push([t])}return e},[]);return f.map(e=>{if(e.length>1)return;const t=L(e[0][0]);t==="added"?e.unshift([2,""]):t==="removed"?e.push([2,""]):t==="equal"&&e.push([...e[0]])}),d==="split"?z(f):d==="unified"?$(f):[]};function U(){const d=g.ref({width:1920,height:1080});function o(){d.value={width:window.innerWidth,height:window.innerHeight}}return g.onMounted(()=>{window.addEventListener("resize",o)}),g.onBeforeUnmount(()=>{window.removeEventListener("resize",o)}),d}function j(){let o=16;const p="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),u=[];let f;for(o=o||p.length,f=0;f<32;f++)u[f]=p[0|Math.random()*o];return u.join("")}const P={changeStrToHtml(d){let o=d.replace(/\&para\;\<br\>/g,` `).replace(/\&gt\;/g,">").replace(/\&lt\;/g,"<").replace(/\&amp\;/g,"&");return o.substring(6,o.length-7)},diff_prettyHtml(d){for(var o=[],p=/&/g,u=/</g,f=/>/g,e=/\n/g,t=0;t<d.length;t++){d[t][0];var r=d[t][1],a=r.replace(p,"&amp;").replace(u,"&lt;").replace(f,"&gt;").replace(e,"&para;<br>");o[t]=a}return o.join("")},concatHTMLWithoutColor(d,o){var p=new F.diff_match_patch,u=p.diff_main(d,o);let f="";return u.forEach(e=>{f+=e[1]}),f},concatHTML(d,o){var p=new F.diff_match_patch,u=p.diff_main(d,o);p.diff_cleanupSemantic(u);var f=p.diff_prettyHtml(u);return this.changeStrToHtml(f)},diffScreens(d,o,p){if(!d&&!o){console.log("没有获取到要对比的字符串",d,o);return}const u=new F.diff_match_patch,f=u.diff_main(d,o);return u.diff_cleanupSemantic(f),f.filter(t=>L(t[0])!=="removed").map((t,r)=>t[1]).join("")},compareHTML(d,o){const p=O("split",d,o);let u=[],f="",e="";p.forEach((r,a)=>{let i=r[0],n=`pos${a}`;if(!i.chkWords)f+=`<span>${i.value}</span>`;else{let c=P.diffScreens(r[1].value,i.value,n);f+=`<span>${c}</span>`}let l=r[0];if(!l.chkWords)e+=`<span>${l.value}</span>`;else{let c=P.diffScreens(l.value,r[1].value,n);e+=`<span>${c}</span>`}let s=r[0],h=r[1];if(s.type!==h.type){const c=this.computeTypes(r,a,n);u=u.concat(c)}});const t=this.uniqText(u);return{newHTML1:f,newHTML2:e,Diffs:t}},uniqText(d){let o=[];d.forEach(t=>{let r=JSON.stringify(t);o.includes(r)||o.push(r)});let p=[];o.forEach(t=>{p.push(JSON.parse(t))});let u=p.filter(t=>t.type==="add"),f=p.filter(t=>t.type==="remove"),e=p.filter(t=>t.type==="edit");return{Diffs:p,DiffsCount:[{name:"全部",value:p.length,key:"all",cards:p},{name:"删除",value:f.length,key:"remove",cards:f},{name:"新增",value:u.length,key:"add",cards:u},{name:"修改",value:e.length,key:"edit",cards:e}]}},computeTypes(d,o,p){const u=[],f=this.getDiffArr(d[0].value,d[1].value),e=t=>{let r=t;if(t.includes(">")&&t.includes("<")){let a=t.match(/\>(.*?)\</g),i=a==null?void 0:a.map(n=>n.replace(/[\> \<]/g,""));r=i==null?void 0:i.join("")}return r};return f.forEach((t,r)=>{const a=j();let i=!1;t[0]===1&&(f[r-1]&&f[r-1][0]===-1&&(i=!0,u.push({name:"修改",type:"edit",id:o,key:p,uid:a,last:e(f[r-1][1]),next:e(t[1])})),i||u.push({name:"新增",type:"add",id:o,key:p,uid:a,last:"",next:e(t[1])})),t[0]===-1&&(f[r+1]&&f[r+1][0]===1&&(i=!0,u.push({name:"修改",type:"edit",id:o,key:p,uid:a,last:e(t[1]),next:e(f[r+1][1])})),i||u.push({name:"删除",type:"remove",id:o,key:p,uid:a,last:"",next:e(t[1])}))}),u},doingDate(d){const o=d.filter(f=>f.last||f.next),p=[],u=[];return o.forEach(f=>{p.includes(f.last+f.next+f.type)||(p.push(f.last+f.next+f.type),u.push(f))}),u},getDiffArr(d,o){var p=new F.diff_match_patch,u=p.diff_main(d,o);return u}},le="",W={class:"text-compare-page"},J={class:"text-compare-article"},Q={class:"text-compare-top"},G={class:"input-group"},X=g.createElementVNode("label",{for:"同步滚动"},"同步滚动",-1),Z=g.createElementVNode("label",{for:"文档对调"},"文档对调",-1),K={class:"text-compare-article1"},Y=["innerHTML"],q={class:"text-compare-article1"},ee=["innerHTML"],te=g.defineComponent({props:{html1:String,html2:String,isTitle:Boolean,notFilterTag:Array,similarity:Number},setup(d){const o=d,{html1:p,html2:u,isTitle:f,similarity:e=100,notFilterTag:t=[]}=o;let r=g.ref(),a=g.ref(),i=g.ref(!1),n=g.ref([]);g.ref("all");let l=g.ref([{name:"全部",value:0,key:"all",cards:[]},{name:"删除",value:0,key:"remove",cards:[]},{name:"新增",value:0,key:"add",cards:[]},{name:"修改",value:0,key:"edit",cards:[]}]);g.ref("");let s=_=>{i.value=_.target.checked};const h=g.ref(!1),c=_=>{h.value=_};let m=_=>{let b=document.querySelector(".text-compare-left"),M=document.querySelector(".text-compare-right");_.target.checked&&(M.scrollTop=b.scrollTop,M.scrollLeft=b.scrollLeft),b.addEventListener("scroll",()=>{_.target.checked&&(h.value||(M.scrollTop=b.scrollTop,M.scrollLeft=b.scrollLeft))}),M.addEventListener("scroll",()=>{_.target.checked&&h.value&&(b.scrollTop=M.scrollTop,b.scrollLeft=M.scrollLeft)})},v=U(),w=g.ref();return g.watch(v,_=>{w.value=_.height-50}),g.onMounted(()=>{if(!p||!u){console.log("请传递正确 html 节点");return}console.time("对比计算");let{newHTML1:_,newHTML2:b,Diffs:M}=P.compareHTML(p,u);console.timeEnd("对比计算"),r.value=_,a.value=b,e>50&&(n.value=M.Diffs,l.value=M.DiffsCount),g.nextTick(()=>{w.value=document.body.clientHeight-50})}),(_,b)=>(g.openBlock(),g.createElementBlock("div",W,[g.createElementVNode("div",{class:"text-compare",style:g.normalizeStyle({height:g.unref(w)+"px"})},[g.createElementVNode("div",J,[g.createElementVNode("div",Q,[g.createElementVNode("div",G,[g.createElementVNode("input",{id:"同步滚动",type:"checkbox",name:"同步滚动",onChange:b[0]||(b[0]=(...M)=>g.unref(m)&&g.unref(m)(...M))},null,32),X,g.createElementVNode("input",{id:"文档对调",type:"checkbox",name:"文档对调",onChange:b[1]||(b[1]=(...M)=>g.unref(s)&&g.unref(s)(...M))},null,32),Z])]),g.createElementVNode("div",{class:"text-compare-bottom",style:g.normalizeStyle({height:g.unref(w)-97+"px"})},[g.createElementVNode("div",{class:"text-compare-left",onMouseover:b[2]||(b[2]=M=>c(!1))},[g.createElementVNode("div",K,[g.createElementVNode("div",{innerHTML:g.unref(i)?g.unref(a):g.unref(r)},null,8,Y)])],32),g.createElementVNode("div",{class:"text-compare-right",onMouseover:b[3]||(b[3]=M=>c(!0))},[g.createElementVNode("div",q,[g.createElementVNode("div",{innerHTML:g.unref(i)?g.unref(r):g.unref(a)},null,8,ee)])],32)],4)])],4)]))}}),re=["innerHTML"],ne=g.defineComponent({props:{html1:String,html2:String},setup(d){const o=d,{html1:p,html2:u}=o;let f=g.ref("");return g.onMounted(()=>{if(!p||!u){console.log("请传递正确 html 节点");return}f.value=P.concatHTMLWithoutColor(p,u)}),(e,t)=>(g.openBlock(),g.createElementBlock("div",{id:"currentTextId",innerHTML:g.unref(f),class:"p-4 rounded-lg border-2 border-gray-500 text-gray-300"},null,8,re))}}),oe="",ae={key:0,class:"diff-page-c"},R=g.defineComponent({props:{screen:String,html1:String,html2:String,title:Boolean,notFilterTag:Array,similarity:Number},setup(d,{expose:o}){const p=d;let u=g.ref(p.html1),f=g.ref(p.html2),e=g.ref(p.title),t=g.ref(p.notFilterTag),r=g.ref(p.similarity),a=g.ref(""),i=g.ref(p.screen),n=g.ref(!0);return g.onMounted(()=>{if(n.value=!0,!u.value||!f.value){console.log("请传递正确 html 节点");return}a.value=P.concatHTML(u.value,f.value),g.nextTick(()=>{let l=document.getElementById("currentTextId");l.contentEditable=!0})}),g.onUnmounted(()=>{n.value=!1}),o(P),(l,s)=>g.unref(n)?(g.openBlock(),g.createElementBlock("div",ae,[g.withDirectives(g.createVNode(ne,{html1:g.unref(u),html2:g.unref(f)},null,8,["html1","html2"]),[[g.vShow,g.unref(i)==="1"]]),g.withDirectives(g.createVNode(te,{html1:g.unref(u),html2:g.unref(f),isTitle:g.unref(e),similarity:g.unref(r),notFilterTag:g.unref(t)},null,8,["html1","html2","isTitle","similarity","notFilterTag"]),[[g.vShow,g.unref(i)==="2"]])])):g.createCommentVNode("",!0)}}),ie={install:(d,o={})=>{d.component("DiffPage",R)}};I.DiffPage=R,I.default=ie,Object.defineProperties(I,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});