'),l=r('
"));l.find("#lhs-margin").attr("id","".concat(this.id,"-lhs-margin"));var a=r("
'));a.eq(0).attr("id","".concat(this.id,"-editor-lhs")),a.find("#text-lhs").attr("id","".concat(this.id,"-lhs"));var c=r('
"));c.find("#mergely-canvas").attr("id","".concat(this.id,"-mergely-canvas")),c.find("#lhs-rhs-canvas").attr("id","".concat(this.id,"-lhs-").concat(this.id,"-rhs-canvas")),this.element.append(h),this.element.append(l),this.element.append(a),this.element.append(c);var d=r('
"));d.find("#rhs-margin").attr("id","".concat(this.id,"-rhs-margin")),"left"==this.settings.rhs_margin&&this.element.append(d);var g,f=r("
'));if(f.eq(0).attr("id","".concat(this.id,"-editor-rhs")),f.find("#text-rhs").attr("id","".concat(this.id,"-rhs")),this.element.append(f),"left"!=this.settings.rhs_margin&&this.element.append(d),this.settings.sidebar||this.element.find(".mergely-margin").css({display:"none"}),["lgpl-separate-notice","gpl-separate-notice","mpl-separate-notice","commercial"].indexOf(this.settings.license)<0){var p={lgpl:"GNU LGPL v3.0",gpl:"GNU GPL v3.0",mpl:"MPL 1.1"},u=p[this.settings.license];u||(u=p.lgpl);this.element.parent().height();var m=this.element.parent().width();this.element.find("#mergely-splash").css({position:"absolute",zIndex:"100",backgroundColor:"#fff",border:"1px solid black",height:"70px",width:"300px",left:(m-300)/2,padding:"10px 10px 0 10px",fontFamily:"arial",fontSize:"11px"}).append('
This software is a Combined Work using Mergely and is covered by the '+u+' license. For the full license, see http://www.mergely.com/license.
'),r("body").one("click",(function(){r("#mergely-splash").fadeOut(100,"linear",(function(){r("#mergely-splash").remove()}))}))}try{g=this.element.find("#".concat(this.id,"-rhs")).get(0)}catch(t){}if(g){var _;try{_=this.element.find("#".concat(this.id,"-lhs")).get(0)}catch(t){}if(_){var y=r('
').appendTo("body").css("border-top-color");this.current_diff_color=y;var v="#".concat(this.id," .CodeMirror-gutter-text { padding: 5px 0 0 0; }\n\t\t'#").concat(this.id," .CodeMirror-lines pre, #").concat(this.id," .CodeMirror-gutter-text pre { line-height: 18px; }\n\t\t'.CodeMirror-linewidget { overflow: hidden; };");this.settings.autoresize&&(v+="".concat(this.id," .CodeMirror-scroll { height: 100%; overflow: auto; }")),r('")).appendTo("head");var w=this;if(w.trace("init","binding event listeners"),this.editor=[],this.editor[this.id+"-lhs"]=n.fromTextArea(_,this.lhs_cmsettings),this.editor[this.id+"-rhs"]=n.fromTextArea(g,this.rhs_cmsettings),this.editor[this.id+"-lhs"].on("change",(function(){w.settings.autoupdate&&w._changing(w.id+"-lhs",w.id+"-rhs")})),this.editor[this.id+"-lhs"].on("scroll",(function(){w._scrolling(w.id+"-lhs")})),this.editor[this.id+"-rhs"].on("change",(function(){w.settings.autoupdate&&w._changing(w.id+"-lhs",w.id+"-rhs")})),this.editor[this.id+"-rhs"].on("scroll",(function(){w._scrolling(w.id+"-rhs")})),this.settings.autoresize){var b=null,x=function(t){w.settings.resize&&w.settings.resize(t),w.resize(),w.editor[w.id+"-lhs"].refresh(),w.editor[w.id+"-rhs"].refresh()};r(window).on("resize.mergely",(function(){b&&clearTimeout(b),b=setTimeout(x,w.settings.resize_timeout)})),x(!0)}this.editor[this.id+"-lhs"].on("gutterClick",function(t,e,i,s){C.call(this,"lhs",e,s)}.bind(this)),this.editor[this.id+"-rhs"].on("gutterClick",function(t,e,i,s){C.call(this,"rhs",e,s)}.bind(this)),this.settings.lhs&&(w.trace("init","setting lhs value"),this.settings.lhs(function(t){this._initializing=!0,delete this._current_diff,this.editor[this.id+"-lhs"].getDoc().setValue(t)}.bind(this))),this.settings.rhs&&(w.trace("init","setting rhs value"),this.settings.rhs(function(t){this._initializing=!0,delete this._current_diff,this.editor[this.id+"-rhs"].getDoc().setValue(t)}.bind(this))),this.element.one("updated",(function(){s._initializing=!1,w.settings.loaded&&w.settings.loaded()})),this.trace("init","bound"),this.editor[this.id+"-lhs"].focus()}else console.error("lhs textarea not defined - Mergely not initialized properly")}else console.error("rhs textarea not defined - Mergely not initialized properly");function C(t,e,i){var s,n;if(!(i.target&&r(i.target).closest(".merge-button").length>0))for(s=0;s
=(n=this.changes[s])[t+"-line-from"]&&e<=n[t+"-line-to"]){this._current_diff=s,setTimeout(function(){this.scrollToDiff()}.bind(this),10);break}}},d.prototype._scroll_to_change=function(t){if(t){var e=this.editor[this.id+"-lhs"],i=this.editor[this.id+"-rhs"];e.setCursor(Math.max(t["lhs-line-from"],0),0),i.setCursor(Math.max(t["rhs-line-from"],0),0),t["lhs-line-to"]>=0&&e.scrollIntoView({line:t["lhs-line-to"]}),e.focus()}},d.prototype._scrolling=function(t){var e=this.jQuery;if(!0!==this._skipscroll[t]){if(this.changes){var i=e(this.editor[t].getScrollerElement());null==this.midway&&(this.midway=(i.height()/2+i.offset().top).toFixed(2));var s=this.editor[t].coordsChar({left:0,top:this.midway}),r=i.scrollTop(),n=i.scrollLeft();this.trace("scroll","side",t),this.trace("scroll","midway",this.midway),this.trace("scroll","midline",s),this.trace("scroll","top_to",r),this.trace("scroll","left_to",n);var o=this.id+"-lhs",l=this.id+"-rhs";for(var a in this.editor)if(this.editor.hasOwnProperty(a)&&t!=a){for(var c=t.replace(this.id+"-",""),d=a.replace(this.id+"-",""),g=0,f=null,p=!1,u=0;u=m[c+"-line-from"]&&(f=m,s.line>=f[c+"-line-to"]&&(m.hasOwnProperty(c+"-y-start")&&m.hasOwnProperty(c+"-y-end")&&m.hasOwnProperty(d+"-y-start")&&m.hasOwnProperty(d+"-y-end")?g+=m[c+"-y-end"]-m[c+"-y-start"]-(m[d+"-y-end"]-m[d+"-y-start"]):p=!0))}var _=this.editor[a].getViewport(),y=!0;f&&(this.trace("scroll","last change before midline",f),s.line>=_.from&&s<=_.to&&(y=!1)),this.trace("scroll","scroll",y),y||p?(this.trace("scroll","scrolling other side",r-g),this._skipscroll[a]=!0,this.editor[a].scrollTo(n,r-g)):this.trace("scroll","not scrolling other side"),this.settings.autoupdate&&(h.start(),this._calculate_offsets(o,l,this.changes),this.trace("change","offsets time",h.stop()),this._markup_changes(o,l,this.changes),this.trace("change","markup time",h.stop()),this._draw_diff(o,l,this.changes),this.trace("change","draw time",h.stop())),this.trace("scroll","scrolled")}}}else this._skipscroll[t]=!1},d.prototype._changing=function(t,e){this.trace("change","changing-timeout",this.changed_timeout);var i=this;null!=this.changed_timeout&&clearTimeout(this.changed_timeout),this.changed_timeout=setTimeout((function(){h.start(),i._changed(t,e),i.trace("change","total time",h.stop())}),this.settings.change_timeout)},d.prototype._changed=function(t,e){this._clear(),this._diff(t,e)},d.prototype._clear=function(){var t,e,i,s,r,n,o=this,l=function(){for(h.start(),s=0,n=e.lineCount();s=e.from&&i["".concat(t,"-line-from")]<=e.to||i["".concat(t,"-line-to")]>=e.from&&i["".concat(t,"-line-to")]<=e.to||e.from>=i["".concat(t,"-line-from")]&&e.to<=i["".concat(t,"-line-to")]},d.prototype._set_top_offset=function(t){var e=this.editor[t].getScrollInfo().top;this.editor[t].scrollTo(null,0);var i=this.element.find(".CodeMirror-measure").first().offset().top-4;return!!i&&(this.editor[t].scrollTo(null,e),this.draw_top_offset=.5-i,!0)},d.prototype._calculate_offsets=function(t,e,i){var s=this.jQuery;if(null==this.em_height){if(!this._set_top_offset(t))return;this.em_height=this.editor[t].defaultTextHeight(),this.em_height||(console.warn("Failed to calculate offsets, using 18 by default"),this.em_height=18),this.draw_lhs_min=.5;var r=s("#"+t+"-"+e+"-canvas");if(r.length||console.error("failed to find canvas","#"+t+"-"+e+"-canvas"),!r.width())return void console.error("canvas width is 0");this.draw_mid_width=s("#"+t+"-"+e+"-canvas").width(),this.draw_rhs_max=this.draw_mid_width-.5,this.draw_lhs_width=5,this.draw_rhs_width=5,this.trace("calc","change offsets calculated",{top_offset:this.draw_top_offset,lhs_min:this.draw_lhs_min,rhs_max:this.draw_rhs_max,lhs_width:this.draw_lhs_width,rhs_width:this.draw_rhs_width})}for(var n=this.editor[t].charCoords({line:0}),o=this.editor[e].charCoords({line:0}),h=this._get_viewport_side(t),l=(this._get_viewport_side(e),0);l=0?a["lhs-line-from"]:0,b=a["lhs-line-to"]>=0?a["lhs-line-to"]:0,x=a["rhs-line-from"]>=0?a["rhs-line-from"]:0,C=a["rhs-line-to"]>=0?a["rhs-line-to"]:0;this.editor[t].getOption("lineWrapping")||this.editor[e].getOption("lineWrapping")?(p=this.editor[t].cursorCoords({line:w,ch:0},"page"),_=this.editor[t].getLineHandle(w),c={top:p.top,bottom:p.top+_.height},u=this.editor[t].cursorCoords({line:b,ch:0},"page"),m=this.editor[t].getLineHandle(b),d={top:u.top,bottom:u.top+m.height},p=this.editor[e].cursorCoords({line:x,ch:0},"page"),y=this.editor[e].getLineHandle(x),g={top:p.top,bottom:p.top+y.height},u=this.editor[e].cursorCoords({line:C,ch:0},"page"),v=this.editor[e].getLineHandle(C),f={top:u.top,bottom:u.top+v.height}):(c={top:n.top+w*this.em_height,bottom:n.bottom+w*this.em_height+2},d={top:n.top+b*this.em_height,bottom:n.bottom+b*this.em_height+2},g={top:o.top+x*this.em_height,bottom:o.bottom+x*this.em_height+2},f={top:o.top+C*this.em_height,bottom:o.bottom+C*this.em_height+2}),"a"==a.op?x>0&&(c.top=c.bottom,c.bottom+=this.em_height,d=c):"d"==a.op&&w>0&&(g.top=g.bottom,g.bottom+=this.em_height,f=g),a["lhs-y-start"]=this.draw_top_offset+c.top,"c"==a.op||"d"==a.op?a["lhs-y-end"]=this.draw_top_offset+d.bottom:a["lhs-y-end"]=this.draw_top_offset+d.top,a["rhs-y-start"]=this.draw_top_offset+g.top,"c"==a.op||"a"==a.op?a["rhs-y-end"]=this.draw_top_offset+f.bottom:a["rhs-y-end"]=this.draw_top_offset+f.top,this.trace("calc","change calculated",l,a)}else delete a["lhs-y-start"],delete a["lhs-y-end"],delete a["rhs-y-start"],delete a["rhs-y-end"]}return i},d.prototype._markup_changes=function(t,e,i){var s=this.jQuery;this.element.find(".merge-button").remove();var r=this,n=this.editor[t],o=this.editor[e],l=this._current_diff,a=this._get_viewport_side(t),d=this._get_viewport_side(e);h.start(),n.operation(function(){for(var t=0;t=0?e["lhs-line-from"]:0,h=e["lhs-line-to"]>=0?e["lhs-line-to"]:0,c=e["rhs-line-from"]>=0?e["rhs-line-from"]:0,d=(e["rhs-line-to"]>=0&&e["rhs-line-to"],["mergely","lhs",e.op,"cid-"+t]);if(n.addLineClass(s,"background","start"),n.addLineClass(h,"background","end"),e["lhs-line-from"]<0&&d.push("empty"),l==t&&(s!=h&&n.addLineClass(s,"background","current"),n.addLineClass(h,"background","current")),0==s&&0==h&&0==c)n.addLineClass(s,"background",d.join(" ")),n.addLineClass(s,"background","first");else for(var g=s;g<=h;++g)n.addLineClass(g,"background",d.join(" ")),n.addLineClass(g,"background",d.join(" "));if(!o.getOption("readOnly")){var f=r.merge_rhs_button.clone();f.button&&f.button({icons:{primary:"ui-icon-triangle-1-e"},text:!1}),f.addClass("merge-button"),f.attr("id","merge-rhs-"+t),n.setGutterMarker(s,"merge",f.get(0))}}}}.bind(this)),this.trace("change","markup lhs-editor time",h.stop()),o.operation(function(){for(var t=0;t=0?e["lhs-line-from"]:0,h=(e["lhs-line-to"]>=0&&e["lhs-line-to"],e["rhs-line-from"]>=0?e["rhs-line-from"]:0),a=e["rhs-line-to"]>=0?e["rhs-line-to"]:0,c=["mergely","rhs",e.op,"cid-"+t];if(o.addLineClass(h,"background","start"),o.addLineClass(a,"background","end"),e["rhs-line-from"]<0&&c.push("empty"),l==t&&(h!=a&&o.addLineClass(h,"background","current"),o.addLineClass(a,"background","current")),0==h&&0==a&&0==s)o.addLineClass(h,"background",c.join(" ")),o.addLineClass(h,"background","first");else for(var g=h;g<=a;++g)o.addLineClass(g,"background",c.join(" ")),o.addLineClass(g,"background",c.join(" "));if(!n.getOption("readOnly")){var f=r.merge_lhs_button.clone();f.button&&f.button({icons:{primary:"ui-icon-triangle-1-w"},text:!1}),f.addClass("merge-button"),f.attr("id","merge-lhs-"+t),o.setGutterMarker(h,"merge",f.get(0))}}}}.bind(this)),this.trace("change","markup rhs-editor time",h.stop());var g,f=[];for(M=0;this.settings.lcs&&M=0?p["lhs-line-from"]:0,m=p["lhs-line-to"]>=0?p["lhs-line-to"]:0,_=p["rhs-line-from"]>=0?p["rhs-line-from"]:0,y=p["rhs-line-to"]>=0?p["rhs-line-to"]:0;if("d"==p.op){var v=u,w=m;if(this._is_change_in_view("lhs",a,p)){var b=n.lineInfo(w);b&&f.push([n,{line:v,ch:0},{line:w,ch:b.text.length},{className:"mergely ch d lhs"}])}}else if("c"==p.op)for(P=u,g=_;P>=0&&P<=m||g>=0&&g<=y;++P,++g){var x,C;if(g>y)x=n.getLine(P),f.push([n,{line:P,ch:0},{line:P,ch:x.length},{className:"mergely ch d lhs"}]);else if(P>m)C=o.getLine(g),f.push([o,{line:g,ch:0},{line:g,ch:C.length},{className:"mergely ch a rhs"}]);else x=n.getLine(P),C=o.getLine(g),new c(x,C,{ignoreaccents:!!this.settings.ignoreaccents,ignorews:!!this.settings.ignorews}).diff((function(t,e){r._is_change_in_view("rhs",d,p)&&f.push([o,{line:g,ch:t},{line:g,ch:e},{className:"mergely ch a rhs"}])}),(function(t,e){r._is_change_in_view("lhs",a,p)&&f.push([n,{line:P,ch:t},{line:P,ch:e},{className:"mergely ch d lhs"}])}))}}this.trace("change","LCS marktext time",h.stop()),n.operation((function(){for(var t=0;t=L&&P<=T&&S.eq(P-L).addClass("mergely current");if(l==M&&"d"!==p.op)for(A=p["rhs-line-from"],k=p["rhs-line-to"]+1,P=A;P=E&&P<=V&&j.eq(P-E).addClass("mergely current")}this.trace("change","markup buttons time",h.stop())},d.prototype._merge_change=function(t,e,i){if(t){var s,r=this.CodeMirror,n={lhs:this.editor[this.id+"-lhs"],rhs:this.editor[this.id+"-rhs"]},o=t[e+"-line-from"],h=t[e+"-line-to"],l=t[i+"-line-from"],a=t[i+"-line-to"],c=n[e].getDoc(),d=n[i].getDoc(),g=o>=0?c.getLine(o).length+1:0,f=h>=0?c.getLine(h).length+1:0,p=a>=0?d.getLine(a).length+1:0,u=l>=0?d.getLine(l).length+1:0;"c"===t.op?(s=c.getRange(r.Pos(o,0),r.Pos(h,f)),d.replaceRange(s,r.Pos(l,0),r.Pos(a,p))):"lhs"===i&&"d"===t.op||"rhs"===i&&"a"===t.op?(o>0?(s=c.getRange(r.Pos(o,g),r.Pos(h,f)),l+=1):s=c.getRange(r.Pos(0,0),r.Pos(h+1,0)),d.replaceRange(s,r.Pos(l-1,0),r.Pos(a+1,0))):("rhs"===i&&"d"===t.op||"lhs"===i&&"a"===t.op)&&(o>0?(g=c.getLine(o-1).length+1,s=c.getRange(r.Pos(o-1,g),r.Pos(h,f))):s=c.getRange(r.Pos(0,0),r.Pos(h+1,0)),l<0&&(l=0),d.replaceRange(s,r.Pos(l,u))),this._scroll_to_change(t)}},d.prototype._draw_info=function(t,e){var i=this.jQuery,s=i(this.editor[t].getScrollerElement()).height()+17,r=i(this.editor[t].getScrollerElement()).children(":first-child").height(),n=document.getElementById(t+"-"+e+"-canvas");if(null==n)throw"Failed to find: "+t+"-"+e+"-canvas";var o=this.element.find("#"+this.id+"-lhs-margin"),h=this.element.find("#"+this.id+"-rhs-margin");return{visible_page_height:s,gutter_height:r,visible_page_ratio:s/r,margin_ratio:s/r,lhs_scroller:i(this.editor[t].getScrollerElement()),rhs_scroller:i(this.editor[e].getScrollerElement()),lhs_lines:this.editor[t].lineCount(),rhs_lines:this.editor[e].lineCount(),dcanvas:n,clhs:o,crhs:h,lhs_xyoffset:i(o).offset(),rhs_xyoffset:i(h).offset()}},d.prototype._draw_diff=function(t,e,i){var s=this.jQuery,r=this._draw_info(t,e),n=r.clhs.get(0),o=r.crhs.get(0),h=r.dcanvas.getContext("2d"),l=n.getContext("2d"),a=o.getContext("2d");this.trace("draw","visible_page_height",r.visible_page_height),this.trace("draw","gutter_height",r.gutter_height),this.trace("draw","visible_page_ratio",r.visible_page_ratio),this.trace("draw","lhs-scroller-top",r.lhs_scroller.scrollTop()),this.trace("draw","rhs-scroller-top",r.rhs_scroller.scrollTop()),s.each(this.element.find("canvas"),(function(){s(this).get(0).height=r.visible_page_height})),r.clhs.unbind("click"),r.crhs.unbind("click"),l.beginPath(),l.fillStyle=this.settings.bgcolor,l.strokeStyle="#888",l.fillRect(0,0,6.5,r.visible_page_height),l.strokeRect(0,0,6.5,r.visible_page_height),a.beginPath(),a.fillStyle=this.settings.bgcolor,a.strokeStyle="#888",a.fillRect(0,0,6.5,r.visible_page_height),a.strokeRect(0,0,6.5,r.visible_page_height);for(var c=this._get_viewport_side(t),d=this._get_viewport_side(e),g=0;g=0&&(arguments[0]=t+":",console.log([].slice.apply(arguments)))},t.exports=d},function(t,e){function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function s(t,e){for(var s=0;s