'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 m(a,b){for(var c=a.findMarks(k(b,0),k(b+1,0)),d=0;d<c.length;++d)if(c[d].__isFold&&c[d].find().from.line==b)return c[d]}function n(a){if("string"==typeof a){var b=document.createElement("div");b.className=
a+" CodeMirror-guttermarker-subtle";return b}return a.cloneNode(!0)}function h(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(m(a,e))c=n(d.indicatorFolded);else{var f=k(e,0);(f=g&&g(a,f))&&f.to.line-f.from.line>=h&&(c=n(d.indicatorOpen))}a.setGutterMarker(b,d.gutter,c);++e})}function l(a){var b=a.getViewport(),c=a.state.foldGutter;c&&(a.operation(function(){h(a,b.from,b.to)}),c.from=b.from,c.to=b.to)}
function p(a,b,c){var d=a.state.foldGutter;d&&(d=d.options,c==d.gutter&&((c=m(a,b))?c.clear():a.foldCode(k(b,0),d.rangeFinder)))}function g(a){var b=a.state.foldGutter;if(b){var c=b.options;b.from=b.to=0;clearTimeout(b.changeUpdate);b.changeUpdate=setTimeout(function(){l(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?l(a):
a.operation(function(){c.from<b.from&&(h(a,c.from,b.from),b.from=c.from);c.to>b.to&&(h(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&&h(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",p),a.off("change",g),a.off("viewportChange",q),a.off("fold",f),a.off("unfold",f),a.off("swapDoc",g));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),l(a),a.on("gutterClick",p),a.on("change",g),a.on("viewportChange",q),a.on("fold",f),a.on("unfold",f),a.on("swapDoc",g))});var k=e.Pos});
