'use strict';(function(g){"object"==typeof exports&&"object"==typeof module?g(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],g):g(CodeMirror)})(function(g){function f(b,a,c,d){this.cm=b;this.node=a;this.options=c;this.height=d;this.cleared=!1}function k(b){var a=b.getWrapperElement(),c=window.getComputedStyle?window.getComputedStyle(a):a.currentStyle,d=parseInt(c.height),e=b.state.panels={setHeight:a.style.height,heightLeft:d,panels:0,wrapper:document.createElement("div")};
a.parentNode.insertBefore(e.wrapper,a);c=b.hasFocus();e.wrapper.appendChild(a);c&&b.focus();b._setSize=b.setSize;null!=d&&(b.setSize=function(a,c){if(null==c)return this._setSize(a,c);e.setHeight=c;if("number"!=typeof c){var f=/^(\d+\.?\d*)px$/.exec(c);f?c=Number(f[1]):(e.wrapper.style.height=c,c=e.wrapper.offsetHeight,e.wrapper.style.height="")}b._setSize(a,e.heightLeft+=c-d);d=c})}function h(b,a){for(a=a.nextSibling;a;a=a.nextSibling)if(a==b.getWrapperElement())return!0;return!1}g.defineExtension("addPanel",
function(b,a){a=a||{};this.state.panels||k(this);var c=this.state.panels,d=c.wrapper,e=this.getWrapperElement(),g=a.replace instanceof f&&!a.replace.cleared;a.after instanceof f&&!a.after.cleared?d.insertBefore(b,a.before.node.nextSibling):a.before instanceof f&&!a.before.cleared?d.insertBefore(b,a.before.node):g?(d.insertBefore(b,a.replace.node),c.panels++,a.replace.clear()):"bottom"==a.position?d.appendChild(b):"before-bottom"==a.position?d.insertBefore(b,e.nextSibling):"after-top"==a.position?
d.insertBefore(b,e):d.insertBefore(b,d.firstChild);d=a&&a.height||b.offsetHeight;this._setSize(null,c.heightLeft-=d);g||c.panels++;a.stable&&h(this,b)&&this.scrollTo(null,this.getScrollInfo().top+d);return new f(this,b,a,d)});f.prototype.clear=function(){if(!this.cleared){this.cleared=!0;var b=this.cm.state.panels;this.cm._setSize(null,b.heightLeft+=this.height);this.options.stable&&h(this.cm,this.node)&&this.cm.scrollTo(null,this.cm.getScrollInfo().top-this.height);b.wrapper.removeChild(this.node);
if(0==--b.panels){b=this.cm;var a=b.state.panels;b.state.panels=null;var c=b.getWrapperElement();a.wrapper.parentNode.replaceChild(c,a.wrapper);c.style.height=a.setHeight;b.setSize=b._setSize;b.setSize()}}};f.prototype.changed=function(b){b=null==b?this.node.offsetHeight:b;this.cm._setSize(null,this.cm.state.panels.heightLeft-=b-this.height);this.height=b}});
