1 line
285 KiB
JavaScript
1 line
285 KiB
JavaScript
|
|
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Vditor=t():e.Vditor=t()}(this,(function(){return(()=>{var e={173:e=>{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},n=-1;t.Diff=function(e,t){return[e,t]},t.prototype.diff_main=function(e,n,r,i){void 0===i&&(i=this.Diff_Timeout<=0?Number.MAX_VALUE:(new Date).getTime()+1e3*this.Diff_Timeout);var o=i;if(null==e||null==n)throw new Error("Null input. (diff_main)");if(e==n)return e?[new t.Diff(0,e)]:[];void 0===r&&(r=!0);var a=r,s=this.diff_commonPrefix(e,n),l=e.substring(0,s);e=e.substring(s),n=n.substring(s),s=this.diff_commonSuffix(e,n);var c=e.substring(e.length-s);e=e.substring(0,e.length-s),n=n.substring(0,n.length-s);var d=this.diff_compute_(e,n,a,o);return l&&d.unshift(new t.Diff(0,l)),c&&d.push(new t.Diff(0,c)),this.diff_cleanupMerge(d),d},t.prototype.diff_compute_=function(e,r,i,o){var a;if(!e)return[new t.Diff(1,r)];if(!r)return[new t.Diff(n,e)];var s=e.length>r.length?e:r,l=e.length>r.length?r:e,c=s.indexOf(l);if(-1!=c)return a=[new t.Diff(1,s.substring(0,c)),new t.Diff(0,l),new t.Diff(1,s.substring(c+l.length))],e.length>r.length&&(a[0][0]=a[2][0]=n),a;if(1==l.length)return[new t.Diff(n,e),new t.Diff(1,r)];var d=this.diff_halfMatch_(e,r);if(d){var u=d[0],p=d[1],m=d[2],f=d[3],h=d[4],v=this.diff_main(u,m,i,o),g=this.diff_main(p,f,i,o);return v.concat([new t.Diff(0,h)],g)}return i&&e.length>100&&r.length>100?this.diff_lineMode_(e,r,o):this.diff_bisect_(e,r,o)},t.prototype.diff_lineMode_=function(e,r,i){var o=this.diff_linesToChars_(e,r);e=o.chars1,r=o.chars2;var a=o.lineArray,s=this.diff_main(e,r,!1,i);this.diff_charsToLines_(s,a),this.diff_cleanupSemantic(s),s.push(new t.Diff(0,""));for(var l=0,c=0,d=0,u="",p="";l<s.length;){switch(s[l][0]){case 1:d++,p+=s[l][1];break;case n:c++,u+=s[l][1];break;case 0:if(c>=1&&d>=1){s.splice(l-c-d,c+d),l=l-c-d;for(var m=this.diff_main(u,p,!1,i),f=m.length-1;f>=0;f--)s.splice(l,0,m[f]);l+=m.length}d=0,c=0,u="",p=""}l++}return s.pop(),s},t.prototype.diff_bisect_=function(e,r,i){for(var o=e.length,a=r.length,s=Math.ceil((o+a)/2),l=s,c=2*s,d=new Array(c),u=new Array(c),p=0;p<c;p++)d[p]=-1,u[p]=-1;d[l+1]=0,u[l+1]=0;for(var m=o-a,f=m%2!=0,h=0,v=0,g=0,b=0,y=0;y<s&&!((new Date).getTime()>i);y++){for(var w=-y+h;w<=y-v;w+=2){for(var E=l+w,k=(M=w==-y||w!=y&&d[E-1]<d[E+1]?d[E+1]:d[E-1]+1)-w;M<o&&k<a&&e.charAt(M)==r.charAt(k);)M++,k++;if(d[E]=M,M>o)v+=2;else if(k>a)h+=2;else if(f){if((T=l+m-w)>=0&&T<c&&-1!=u[T])if(M>=(L=o-u[T]))return this.diff_bisectSplit_(e,r,M,k,i)}}for(var S=-y+g;S<=y-b;S+=2){for(var L,T=l+S,C=(L=S==-y||S!=y&&u[T-1]<u[T+1]?u[T+1]:u[T-1]+1)-S;L<o&&C<a&&e.charAt(o-L-1)==r.charAt(a-C-1);)L++,C++;if(u[T]=L,L>o)b+=2;else if(C>a)g+=2;else if(!f){if((E=l+m-S)>=0&&E<c&&-1!=d[E]){var M;k=l+(M=d[E])-E;if(M>=(L=o-L))return this.diff_bisectSplit_(e,r,M,k,i)}}}}return[new t.Diff(n,e),new t.Diff(1,r)]},t.prototype.diff_bisectSplit_=function(e,t,n,r,i){var o=e.substring(0,n),a=t.substring(0,r),s=e.substring(n),l=t.substring(r),c=this.diff_main(o,a,!1,i),d=this.diff_main(s,l,!1,i);return c.concat(d)},t.prototype.diff_linesToChars_=function(e,t){var n=[],r={};function i(e){for(var t="",i=0,a=-1,s=n.length;a<e.length-1;){-1==(a=e.indexOf("\n",i))&&(a=e.length-1);var l=e.substring(i,a+1);(r.hasOwnProperty?r.hasOwnProperty(l):void 0!==r[l])?t+=String.fromCharCode(r[l]):(s==o&&(l=e.substring(i),a=e.length),t+=String.fromCharCode(s),r[l]=s,n[s++]=l),i=a+1}return t}n[0]="";var o=4e4,a=i(e);return o=65535,{chars1:a,chars2:i(t),lineArray:n}},t.prototype.diff_charsToLines_=function(e,t){for(var n=0;n<e.length;n++){for(var r=e[n][1],i=[],o=0;o<r.length;o++)i[o]=t[r.charCodeAt(o)];e[n][1]=i.join("")}},t.prototype.diff_commonPrefix=function(e,t){if(!e||!t||e.charAt(0)!=t.charAt(0))return 0;for(var n=0,r=Math.min(e.length,t.length),i=r,o=0;n<i;)e.substring(o,i)==t.substring(o,i)?o=n=i:r=i,i=Math.floor((r-n)
|