'use strict';(function(b){"object"==typeof exports&&"object"==typeof module?b(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],b):b(CodeMirror)})(function(b){function e(a,f){function c(a){clearTimeout(d.doRedraw);d.doRedraw=setTimeout(function(){d.redraw()},a)}this.cm=a;this.options=f;this.buttonHeight=f.scrollButtonHeight||a.getOption("scrollButtonHeight");this.annotations=[];this.doRedraw=this.doUpdate=null;this.div=a.getWrapperElement().appendChild(document.createElement("div"));
this.div.style.cssText="position: absolute; right: 0; top: 0; z-index: 7; pointer-events: none";this.computeScale();var d=this;a.on("refresh",this.resizeHandler=function(){clearTimeout(d.doUpdate);d.doUpdate=setTimeout(function(){d.computeScale()&&c(20)},100)});a.on("markerAdded",this.resizeHandler);a.on("markerCleared",this.resizeHandler);if(!1!==f.listenForChanges)a.on("change",this.changeHandler=function(){c(250)})}b.defineExtension("annotateScrollbar",function(a){"string"==typeof a&&(a={className:a});
return new e(this,a)});b.defineOption("scrollButtonHeight",0);e.prototype.computeScale=function(){var a=this.cm,a=(a.getWrapperElement().clientHeight-a.display.barHeight-2*this.buttonHeight)/a.getScrollerElement().scrollHeight;if(a!=this.hScale)return this.hScale=a,!0};e.prototype.update=function(a){this.annotations=a;this.redraw()};e.prototype.redraw=function(a){function f(a,b){m!=a.line&&(m=a.line,k=c.getLineHandle(m));return k.widgets&&k.widgets.length||e&&k.height>t?c.charCoords(a,"local")[b?
"top":"bottom"]:c.heightAtLine(k,"local")+(b?0:k.height)}!1!==a&&this.computeScale();var c=this.cm;a=this.hScale;var d=document.createDocumentFragment(),b=this.annotations,e=c.getOption("lineWrapping"),t=e&&1.5*c.defaultTextHeight(),m=null,k=null,r=c.lastLine();if(c.display.barWidth)for(var g=0,n;g<b.length;g++){var h=b[g];if(!(h.to.line>r)){for(var p=n||f(h.from,!0)*a,l=f(h.to,!1)*a;g<b.length-1&&!(b[g+1].to.line>r);){n=f(b[g+1].from,!0)*a;if(n>l+.9)break;h=b[++g];l=f(h.to,!1)*a}if(l!=p){var l=Math.max(l-
p,3),q=d.appendChild(document.createElement("div"));q.style.cssText="position: absolute; right: 0px; width: "+Math.max(c.display.barWidth-1,2)+"px; top: "+(p+this.buttonHeight)+"px; height: "+l+"px";q.className=this.options.className;h.id&&q.setAttribute("annotation-id",h.id)}}}this.div.textContent="";this.div.appendChild(d)};e.prototype.clear=function(){this.cm.off("refresh",this.resizeHandler);this.cm.off("markerAdded",this.resizeHandler);this.cm.off("markerCleared",this.resizeHandler);this.changeHandler&&
this.cm.off("change",this.changeHandler);this.div.parentNode.removeChild(this.div)}});
