'use strict';(function(f){"object"==typeof exports&&"object"==typeof module?f(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],f):f(CodeMirror)})(function(f){function v(a,b){function c(a){if(!d.parentNode)return f.off(document,"mousemove",c);d.style.top=Math.max(0,a.clientY-d.offsetHeight-5)+"px";d.style.left=a.clientX+5+"px"}var d=document.createElement("div");d.className="CodeMirror-lint-tooltip";d.appendChild(b.cloneNode(!0));document.body.appendChild(d);
f.on(document,"mousemove",c);c(a);null!=d.style.opacity&&(d.style.opacity=1);return d}function w(a){a.parentNode&&(null==a.style.opacity&&a.parentNode&&a.parentNode.removeChild(a),a.style.opacity=0,setTimeout(function(){a.parentNode&&a.parentNode.removeChild(a)},600))}function q(a,b,c){function d(){f.off(c,"mouseout",d);e&&(w(e),e=null)}var e=v(a,b),g=setInterval(function(){if(e)for(var a=c;;a=a.parentNode){a&&11==a.nodeType&&(a=a.host);if(a==document.body)return;if(!a){d();break}}if(!e)return clearInterval(g)},
400);f.on(c,"mouseout",d)}function x(a,b,c){this.marked=[];this.options=b;this.timeout=null;this.hasGutter=c;this.onMouseOver=function(b){var e=b.target||b.srcElement;if(/\bCodeMirror-lint-mark-/.test(e.className)){e=e.getBoundingClientRect();var c=a.findMarksAt(a.coordsChar({left:(e.left+e.right)/2,top:(e.top+e.bottom)/2},"client"));e=[];for(var d=0;d<c.length;++d){var f=c[d].__annotation;f&&e.push(f)}if(e.length){c=b.target||b.srcElement;d=document.createDocumentFragment();for(f=0;f<e.length;f++)d.appendChild(r(e[f]));
q(b,d,c)}}};this.waitingFor=0}function t(a){var b=a.state.lint;b.hasGutter&&a.clearGutter("CodeMirror-lint-markers");for(a=0;a<b.marked.length;++a)b.marked[a].clear();b.marked.length=0}function y(a,b,c,d){var e=document.createElement("div"),g=e;e.className="CodeMirror-lint-marker-"+b;c&&(g=e.appendChild(document.createElement("div")),g.className="CodeMirror-lint-marker-multiple");if(0!=d)f.on(g,"mouseover",function(b){q(b,a,g)});return e}function r(a){var b=a.severity;b||(b="error");var c=document.createElement("div");
c.className="CodeMirror-lint-message-"+b;"undefined"!=typeof a.messageHTML?c.innerHTML=a.messageHTML:c.appendChild(document.createTextNode(a.message));return c}function z(a,b,c){function d(){g=-1;a.off("change",d)}var e=a.state.lint,g=++e.waitingFor;a.on("change",d);b(a.getValue(),function(b,c){a.off("change",d);e.waitingFor==g&&(c&&b instanceof f&&(b=c),a.operation(function(){n(a,b)}))},c,a)}function k(a){var b=a.state.lint.options,c=b.options||b,d=b.getAnnotations||a.getHelper(f.Pos(0,0),"lint");
if(d)if(b.async||d.async)z(a,d,c);else{var e=d(a.getValue(),c,a);e&&(e.then?e.then(function(b){a.operation(function(){n(a,b)})}):a.operation(function(){n(a,e)}))}}function n(a,b){t(a);for(var c=a.state.lint,d=c.options,e=[],f=0;f<b.length;++f){var l=b[f],m=l.from.line;(e[m]||(e[m]=[])).push(l)}for(f=0;f<e.length;++f)if(l=e[f]){m=null;for(var n=c.hasGutter&&document.createDocumentFragment(),k=0;k<l.length;++k){var h=l[k],p=h.severity;p||(p="error");"error"!=m&&(m=p);d.formatAnnotation&&(h=d.formatAnnotation(h));
c.hasGutter&&n.appendChild(r(h));h.to&&c.marked.push(a.markText(h.from,h.to,{className:"CodeMirror-lint-mark-"+p,__annotation:h}))}c.hasGutter&&a.setGutterMarker(f,"CodeMirror-lint-markers",y(n,m,1<l.length,c.options.tooltips))}if(d.onUpdateLinting)d.onUpdateLinting(b,e,a)}function u(a){var b=a.state.lint;b&&(clearTimeout(b.timeout),b.timeout=setTimeout(function(){k(a)},b.options.delay||500))}f.defineOption("lint",!1,function(a,b,c){c&&c!=f.Init&&(t(a),!1!==a.state.lint.options.lintOnChange&&a.off("change",
u),f.off(a.getWrapperElement(),"mouseover",a.state.lint.onMouseOver),clearTimeout(a.state.lint.timeout),delete a.state.lint);if(b){var d=a.getOption("gutters");c=!1;for(var e=0;e<d.length;++e)"CodeMirror-lint-markers"==d[e]&&(c=!0);d=a.state;b instanceof Function?b={getAnnotations:b}:b&&!0!==b||(b={});c=d.lint=new x(a,b,c);if(!1!==c.options.lintOnChange)a.on("change",u);if(0!=c.options.tooltips&&"gutter"!=c.options.tooltips)f.on(a.getWrapperElement(),"mouseover",c.onMouseOver);k(a)}});f.defineExtension("performLint",
function(){this.state.lint&&k(this)})});
