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