'use strict';(function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror"),require("./foldcode")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","./foldcode"],e):e(CodeMirror)})(function(e){function r(a){this.options=a;this.from=this.to=0}function l(a,b){for(var c=a.findMarksAt(k(b)),d=0;d<c.length;++d)if(c[d].__isFold&&c[d].find().from.line==b)return c[d]}function m(a){if("string"==typeof a){var b=document.createElement("div");b.className=
a+" CodeMirror-guttermarker-subtle";return b}return a.cloneNode(!0)}function g(a,b,c){var d=a.state.foldGutter.options,e=b,h=a.foldOption(d,"minFoldSize"),g=a.foldOption(d,"rangeFinder");a.eachLine(b,c,function(b){var c=null;if(l(a,e))c=m(d.indicatorFolded);else{var f=k(e,0);(f=g&&g(a,f))&&f.to.line-f.from.line>=h&&(c=m(d.indicatorOpen))}a.setGutterMarker(b,d.gutter,c);++e})}function h(a){var b=a.getViewport(),c=a.state.foldGutter;c&&(a.operation(function(){g(a,b.from,b.to)}),c.from=b.from,c.to=b.to)}
function n(a,b,c){var d=a.state.foldGutter;d&&(d=d.options,c==d.gutter&&((c=l(a,b))?c.clear():a.foldCode(k(b,0),d.rangeFinder)))}function p(a){var b=a.state.foldGutter;if(b){var c=b.options;b.from=b.to=0;clearTimeout(b.changeUpdate);b.changeUpdate=setTimeout(function(){h(a)},c.foldOnChangeTimeSpan||600)}}function q(a){var b=a.state.foldGutter;if(b){var c=b.options;clearTimeout(b.changeUpdate);b.changeUpdate=setTimeout(function(){var c=a.getViewport();b.from==b.to||20<c.from-b.to||20<b.from-c.to?h(a):
a.operation(function(){c.from<b.from&&(g(a,c.from,b.from),b.from=c.from);c.to>b.to&&(g(a,b.to,c.to),b.to=c.to)})},c.updateViewportTimeSpan||400)}}function f(a,b){var c=a.state.foldGutter;if(c){var d=b.line;d>=c.from&&d<c.to&&g(a,d,d+1)}}e.defineOption("foldGutter",!1,function(a,b,c){c&&c!=e.Init&&(a.clearGutter(a.state.foldGutter.options.gutter),a.state.foldGutter=null,a.off("gutterClick",n),a.off("change",p),a.off("viewportChange",q),a.off("fold",f),a.off("unfold",f),a.off("swapDoc",h));b&&(c=a.state,
!0===b&&(b={}),null==b.gutter&&(b.gutter="CodeMirror-foldgutter"),null==b.indicatorOpen&&(b.indicatorOpen="CodeMirror-foldgutter-open"),null==b.indicatorFolded&&(b.indicatorFolded="CodeMirror-foldgutter-folded"),c.foldGutter=new r(b),h(a),a.on("gutterClick",n),a.on("change",p),a.on("viewportChange",q),a.on("fold",f),a.on("unfold",f),a.on("swapDoc",h))});var k=e.Pos});
