mirror of https://github.com/mindoc-org/mindoc.git
7 lines
33 KiB
JavaScript
7 lines
33 KiB
JavaScript
|
/**
|
||
|
* Copyright (c) 2016 by Jamie Peabody, http://www.mergely.com
|
||
|
* All rights reserved.
|
||
|
* Version: 3.4.3 2016-09-07
|
||
|
*/
|
||
|
"use strict";!function(a,b,c,d){var e={};e.Timer=function(){var a=this;a.start=function(){a.t0=(new Date).getTime()},a.stop=function(){var b=(new Date).getTime(),c=b-a.t0;return a.t0=b,c},a.start()},e.ChangeExpression=new RegExp(/(^(?![><\-])*\d+(?:,\d+)?)([acd])(\d+(?:,\d+)?)/),e.DiffParser=function(a){for(var b=[],c=0,d=a.split(/\n/),f=0;f<d.length;++f)if(0!=d[f].length){var g={},h=e.ChangeExpression.exec(d[f]);if(null!=h){var i=h[1].split(",");g["lhs-line-from"]=i[0]-1,1==i.length?g["lhs-line-to"]=i[0]-1:g["lhs-line-to"]=i[1]-1;var j=h[3].split(",");g["rhs-line-from"]=j[0]-1,1==j.length?g["rhs-line-to"]=j[0]-1:g["rhs-line-to"]=j[1]-1,g.op=h[2],b[c++]=g}}return b},e.sizeOf=function(a){var c,b=0;for(c in a)a.hasOwnProperty(c)&&b++;return b},e.LCS=function(a,b){this.x=a.replace(/[ ]{1}/g,"\n"),this.y=b.replace(/[ ]{1}/g,"\n")},c.extend(e.LCS.prototype,{clear:function(){this.ready=0},diff:function(a,b){for(var c=new e.diff(this.x,this.y,{ignorews:!1}),d=e.DiffParser(c.normal_form()),f=0,g=0,h=0;h<d.length;++h){var i=d[h];if("a"!=i.op){f=c.getLines("lhs").slice(0,i["lhs-line-from"]).join(" ").length,g=i["lhs-line-to"]+1;var j=c.getLines("lhs").slice(i["lhs-line-from"],g).join(" ");"d"==i.op?j+=" ":f>0&&"c"==i.op&&(f+=1),b(f,f+j.length)}if("d"!=i.op){f=c.getLines("rhs").slice(0,i["rhs-line-from"]).join(" ").length,g=i["rhs-line-to"]+1;var k=c.getLines("rhs").slice(i["rhs-line-from"],g).join(" ");"a"==i.op?k+=" ":f>0&&"c"==i.op&&(f+=1),a(f,f+k.length)}}}}),e.CodeifyText=function(a){this._max_code=0,this._diff_codes={},this.ctxs={},this.options={ignorews:!1},c.extend(this,a),this.lhs=a.lhs.split("\n"),this.rhs=a.rhs.split("\n")},c.extend(e.CodeifyText.prototype,{getCodes:function(a){if(!this.ctxs.hasOwnProperty(a)){var b=this._diff_ctx(this[a]);this.ctxs[a]=b,b.codes.length=Object.keys(b.codes).length}return this.ctxs[a].codes},getLines:function(a){return this.ctxs[a].lines},_diff_ctx:function(a){var b={i:0,codes:{},lines:a};return this._codeify(a,b),b},_codeify:function(a,b){for(var d=(this._max_code,0);d<a.length;++d){var e=a[d];this.options.ignorews&&(e=e.replace(/\s+/g,""));var f=this._diff_codes[e];void 0!=f?b.codes[d]=f:(this._max_code++,this._diff_codes[e]=this._max_code,b.codes[d]=this._max_code)}}}),e.diff=function(a,b,d){var f=c.extend({ignorews:!1},d);this.codeify=new e.CodeifyText({lhs:a,rhs:b,options:f});var g={codes:this.codeify.getCodes("lhs"),modified:{}},h={codes:this.codeify.getCodes("rhs"),modified:{}},j=(g.codes.length+h.codes.length+1,[]),k=[];this._lcs(g,0,g.codes.length,h,0,h.codes.length,k,j),this._optimize(g),this._optimize(h),this.items=this._create_diffs(g,h)},c.extend(e.diff.prototype,{changes:function(){return this.items},getLines:function(a){return this.codeify.getLines(a)},normal_form:function(){for(var a="",b=0;b<this.items.length;++b){var c=this.items[b],d="",e="",f="c";0==c.lhs_deleted_count&&c.rhs_inserted_count>0?f="a":c.lhs_deleted_count>0&&0==c.rhs_inserted_count&&(f="d"),d=1==c.lhs_deleted_count?c.lhs_start+1:0==c.lhs_deleted_count?c.lhs_start:c.lhs_start+1+","+(c.lhs_start+c.lhs_deleted_count),e=1==c.rhs_inserted_count?c.rhs_start+1:0==c.rhs_inserted_count?c.rhs_start:c.rhs_start+1+","+(c.rhs_start+c.rhs_inserted_count),a+=d+f+e+"\n";var g=this.getLines("lhs"),h=this.getLines("rhs");if(h&&g){var i;for(i=c.lhs_start;i<c.lhs_start+c.lhs_deleted_count;++i)a+="< "+g[i]+"\n";for(c.rhs_inserted_count&&c.lhs_deleted_count&&(a+="---\n"),i=c.rhs_start;i<c.rhs_start+c.rhs_inserted_count;++i)a+="> "+h[i]+"\n"}}return a},_lcs:function(a,b,c,d,e,f,g,h){for(;c>b&&f>e&&a.codes[b]==d.codes[e];)++b,++e;for(;c>b&&f>e&&a.codes[c-1]==d.codes[f-1];)--c,--f;if(b==c)for(;f>e;)d.modified[e++]=!0;else if(e==f)for(;c>b;)a.modified[b++]=!0;else{var i=this._sms(a,b,c,d,e,f,g,h);this._lcs(a,b,i.x,d,e,i.y,g,h),this._lcs(a,i.x,c,d,i.y,f,g,h)}},_sms:function(a,b,c,d,e,f,g,h){var i=a.codes.length+d.codes.length+1,j=b-e,k=c-f,l=c-b-(f-e),m=0!=(1&l),n=i-j,o=i-k,p=(c-b+f-e)/2+1;h[n+j+1]=b,g[o+k-1]=c;var r,s,t,u,q={x:0,y:0};for(r=0;p>=r;++r){for(s=j-r;j+r>=s;s+=2){for(s==j-r?t=h[n+s+1]:(t=h[n+s-1]+1,j+r>s&&h[n+s+1]>=t&&(t
|
||
|
this.trace("draw","cls.height",e.clhs.height()),this.trace("draw","lhs_scroller.scrollTop()",e.lhs_scroller.scrollTop()),this.trace("draw","gutter_height",e.gutter_height),this.trace("draw","visible_page_ratio",e.visible_page_ratio),this.trace("draw","lhs from",C,"lhs to",B),this.trace("draw","rhs from",E,"rhs to",D),i.fillRect(1.5,C,4.5,B),j.fillRect(1.5,E,4.5,D),e.clhs.click(function(a){var b=a.pageY-e.lhs_xyoffset.top-B/2,c=Math.max(0,b/f.height*e.lhs_scroller.get(0).scrollHeight);e.lhs_scroller.scrollTop(c)}),e.crhs.click(function(a){var b=a.pageY-e.rhs_xyoffset.top-D/2,c=Math.max(0,b/g.height*e.rhs_scroller.get(0).scrollHeight);e.rhs_scroller.scrollTop(c)})},trace:function(a){this.settings._debug.indexOf(a)>=0&&(arguments[0]=a+":",console.log([].slice.apply(arguments)))}}),c.pluginMaker=function(a){c.fn[a.prototype.name]=function(b){var f,d=c.makeArray(arguments),e=d.slice(1);return this.each(function(){var g=c.data(this,a.prototype.name);if(g){if("string"==typeof b)f=g[b].apply(g,e);else if(g.update)return g.update.apply(g,d)}else{new a(this,b)}}),void 0!=f?f:void 0}},c.pluginMaker(e.mergely)}(window,document,jQuery,CodeMirror);
|