diff-online/lib/mergely.min.js

1 line
48 KiB
JavaScript
Raw Normal View History

2022-12-23 00:22:58 +03:00
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("jQuery"),require("CodeMirror")):"function"==typeof define&&define.amd?define("mergely",["jQuery","CodeMirror"],e):"object"==typeof exports?exports.mergely=e(require("jQuery"),require("CodeMirror")):t.mergely=e(t.jQuery,t.CodeMirror)}(window,(function(t,e){return function(t){var e={};function i(s){if(e[s])return e[s].exports;var r=e[s]={i:s,l:!1,exports:{}};return t[s].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,s){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:s})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(s,r,function(e){return t[e]}.bind(null,r));return s},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=3)}([function(t,e){function i(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=i.ignorews,n=void 0!==r&&r,o=i.ignoreaccents,h=void 0!==o&&o,l=i.ignorecase,a=void 0!==l&&l;this.codeify=new s(t,e,{ignorews:n,ignoreaccents:h,ignorecase:a});var c={codes:this.codeify.getCodes("lhs"),modified:{}},d={codes:this.codeify.getCodes("rhs"),modified:{}},g=[],f=[];this._lcs(c,0,c.codes.length,d,0,d.codes.length,f,g),this._optimize(c),this._optimize(d),this.items=this._create_diffs(c,d)}function s(t,e,i){this._max_code=0,this._diff_codes={},this.ctxs={},this.options=i,this.lhs="string"==typeof t?t.split("\n"):t,this.rhs="string"==typeof e?e.split("\n"):e}i.prototype.changes=function(){return this.items},i.prototype.getLines=function(t){return this.codeify.getLines(t)},i.prototype.normal_form=function(){for(var t="",e=0;e<this.items.length;++e){var i=this.items[e],s="c";0==i.lhs_deleted_count&&i.rhs_inserted_count>0?s="a":i.lhs_deleted_count>0&&0==i.rhs_inserted_count&&(s="d"),t+=(1==i.lhs_deleted_count?i.lhs_start+1:0==i.lhs_deleted_count?i.lhs_start:i.lhs_start+1+","+(i.lhs_start+i.lhs_deleted_count))+s+(1==i.rhs_inserted_count?i.rhs_start+1:0==i.rhs_inserted_count?i.rhs_start:i.rhs_start+1+","+(i.rhs_start+i.rhs_inserted_count))+"\n";var r=this.getLines("lhs"),n=this.getLines("rhs");if(n&&r){var o=void 0;for(o=i.lhs_start;o<i.lhs_start+i.lhs_deleted_count;++o)t+="< "+r[o]+"\n";for(i.rhs_inserted_count&&i.lhs_deleted_count&&(t+="---\n"),o=i.rhs_start;o<i.rhs_start+i.rhs_inserted_count;++o)t+="> "+n[o]+"\n"}}return t},i.prototype._lcs=function(t,e,i,s,r,n,o,h){for(;e<i&&r<n&&t.codes[e]==s.codes[r];)++e,++r;for(;e<i&&r<n&&t.codes[i-1]==s.codes[n-1];)--i,--n;if(e==i)for(;r<n;)s.modified[r++]=!0;else if(r==n)for(;e<i;)t.modified[e++]=!0;else{var l=this._sms(t,e,i,s,r,n,o,h);this._lcs(t,e,l.x,s,r,l.y,o,h),this._lcs(t,l.x,i,s,l.y,n,o,h)}},i.prototype._sms=function(t,e,i,s,r,n,o,h){var l=t.codes.length+s.codes.length+1,a=e-r,c=i-n,d=0!=(1&i-e-(n-r)),g=l-a,f=l-c,p=(i-e+n-r)/2+1;h[g+a+1]=e,o[f+c-1]=i;for(var u,m,_={x:0,y:0},y=0;y<=p;++y){for(var v=a-y;v<=a+y;v+=2){for(v==a-y?u=h[g+v+1]:(u=h[g+v-1]+1,v<a+y&&h[g+v+1]>=u&&(u=h[g+v+1])),m=u-v;u<i&&m<n&&t.codes[u]==s.codes[m];)u++,m++;if(h[g+v]=u,d&&c-y<v&&v<c+y&&o[f+v]<=h[g+v])return _.x=h[g+v],_.y=h[g+v]-v,_}for(k=c-y;k<=c+y;k+=2){for(k==c+y?u=o[f+k-1]:(u=o[f+k+1]-1,k>c-y&&o[f+k-1]<u&&(u=o[f+k-1])),m=u-k;u>e&&m>r&&t.codes[u-1]==s.codes[m-1];)u--,m--;if(o[f+k]=u,!d&&a-y<=k&&k<=a+y&&o[f+k]<=h[g+k])return _.x=h[g+k],_.y=h[g+k]-k,_}}throw"the algorithm should never come here."},i.prototype._optimize=function(t){for(var e=0,i=0;e<t.codes.length;){for(;e<t.codes.length&&(null==t.modified[e]||0==t.modified[e]);)e++;for(i=e;i<t.codes.length&&1==t.modified[i];)i++;i<t.codes.length&&t.codes[e]==t.codes[i]?(t.modified[e]=!1,t.modified[i]=!0):