(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 p(b,c,a){function f(a,e,c){if(a.text){var d=k?0:a.text.length-1,g=k?a.text.length:-1;if(a.text.length>u)return null;for(null!=c&&(d=c+h);d!=g;d+=h)if(c=a.text.charAt(d),q.test(c)&&b.getTokenTypeAt(l(e,d+1))==p){var m=r[c];if(">"==m.charAt(1)==k)s.push(c);else{if(s.pop()!=m.charAt(0))return{pos:d,
match:!1};if(!s.length)return{pos:d,match:!0}}}}}var d=b.state.matchBrackets,u=d&&d.maxScanLineLength||1E4,e=d&&d.maxScanLines||100,d=b.getLineHandle(c.line),g=c.ch-1,m=0<=g&&r[d.text.charAt(g)]||r[d.text.charAt(++g)];if(!m)return null;var k=">"==m.charAt(1),h=k?1:-1;if(a&&k!=(g==c.ch))return null;var p=b.getTokenTypeAt(l(c.line,g+1)),s=[d.text.charAt(g)],q=/[(){}[\]]/;a=c.line;for(var n,e=k?Math.min(a+e,b.lineCount()):Math.max(-1,a-e);a!=e&&!(n=a==c.line?f(d,a,g):f(b.getLineHandle(a),a));a+=h);return{from:l(c.line,
g),to:n&&l(a,n.pos),match:n&&n.match,forward:k}}function q(b,c){for(var a=b.state.matchBrackets.maxHighlightLineLength||1E3,f=[],d=b.listSelections(),h=0;h<d.length;h++){var e=d[h].empty()&&p(b,d[h].head);if(e&&b.getLine(e.from.line).length<=a&&e.to&&b.getLine(e.to.line).length<=a){var g=e.match?"CodeMirror-matchingbracket":"CodeMirror-nonmatchingbracket";f.push(b.markText(e.from,l(e.from.line,e.from.ch+1),{className:g}));e.to&&f.push(b.markText(e.to,l(e.to.line,e.to.ch+1),{className:g}))}}if(f.length)if(v&&
b.state.focused&&b.display.input.focus(),a=function(){b.operation(function(){for(var a=0;a<f.length;a++)f[a].clear()})},c)setTimeout(a,800);else return a}function t(b){b.operation(function(){h&&(h(),h=null);h=q(b,!1)})}var v=/MSIE \d/.test(navigator.userAgent)&&(null==document.documentMode||8>document.documentMode),l=f.Pos,r={"(":")>",")":"(<","[":"]>","]":"[<","{":"}>","}":"{<"},h=null;f.defineOption("matchBrackets",!1,function(b,c,a){a&&a!=f.Init&&b.off("cursorActivity",t);c&&(b.state.matchBrackets=
"object"==typeof c?c:{},b.on("cursorActivity",t))});f.defineExtension("matchBrackets",function(){q(this,!0)});f.defineExtension("findMatchingBracket",function(b,c){return p(this,b,c)})});
