dockview-core
Version:
Zero dependency layout manager supporting tabs, groups, grids and splitviews for vanilla TypeScript
7 lines • 311 kB
JavaScript
/**
* dockview-core
* @version 6.6.1
* @link https://github.com/mathuo/dockview
* @license MIT
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["dockview-core"]={})}(this,function(e){"use strict";class t{}class i extends t{constructor(e,t,i,s){super(),this.viewId=e,this.groupId=t,this.panelId=i,this.tabGroupId=s}}class s extends t{constructor(e,t){super(),this.viewId=e,this.paneId=t}}class o{constructor(){}static getInstance(){return o.INSTANCE}hasData(e){return e&&e===this.proto}clearData(e){this.hasData(e)&&(this.proto=void 0,this.data=void 0)}getData(e){if(this.hasData(e))return this.data}setData(e,t){t&&(this.data=e,this.proto=t)}}function n(){const e=o.getInstance();if(e.hasData(i.prototype))return e.getData(i.prototype)[0]}function r(){const e=o.getInstance();if(e.hasData(s.prototype))return e.getData(s.prototype)[0]}var a;o.INSTANCE=new o,e.DockviewDisposable=void 0,(a=e.DockviewDisposable||(e.DockviewDisposable={})).NONE={dispose:()=>{}},a.from=function(e){return{dispose:()=>{e()}}};class l{get isDisposed(){return this._isDisposed}constructor(...e){this._isDisposed=!1,this._disposables=new Set(e)}addDisposables(...e){e.forEach(e=>this._disposables.add(e))}removeDisposable(e){this._disposables.delete(e)}dispose(){this._isDisposed||(this._isDisposed=!0,this._disposables.forEach(e=>e.dispose()),this._disposables.clear())}}class h{constructor(){this._disposable=e.DockviewDisposable.NONE}set value(e){this._disposable&&this._disposable.dispose(),this._disposable=e}dispose(){this._disposable&&(this._disposable.dispose(),this._disposable=e.DockviewDisposable.NONE)}}e.DockviewEvent=void 0,(e.DockviewEvent||(e.DockviewEvent={})).any=(...e)=>t=>{const i=e.map(e=>e(t));return{dispose:()=>{i.forEach(e=>{e.dispose()})}}};class d{constructor(){this._defaultPrevented=!1}get defaultPrevented(){return this._defaultPrevented}preventDefault(){this._defaultPrevented=!0}}class p{constructor(){this._isAccepted=!1}get isAccepted(){return this._isAccepted}accept(){this._isAccepted=!0}}class c{static create(){var e;return new c(null!==(e=(new Error).stack)&&void 0!==e?e:"")}constructor(e){this.value=e}print(){console.warn("dockview: stacktrace",this.value)}}class u{constructor(e,t){this.callback=e,this.stacktrace=t}}class m{static setLeakageMonitorEnabled(e){e!==m.ENABLE_TRACKING&&m.MEMORY_LEAK_WATCHER.clear(),m.ENABLE_TRACKING=e}get value(){return this._last}constructor(e){this.options=e,this._listeners=[],this._disposed=!1,this._pauseTokens=new Set}get event(){return this._event||(this._event=e=>{var t;(null===(t=this.options)||void 0===t?void 0:t.replay)&&void 0!==this._last&&e(this._last);const i=new u(e,m.ENABLE_TRACKING?c.create():void 0);return this._listeners.push(i),{dispose:()=>{const e=this._listeners.indexOf(i);e>-1?this._listeners.splice(e,1):m.ENABLE_TRACKING}}},m.ENABLE_TRACKING&&m.MEMORY_LEAK_WATCHER.add(this._event,c.create())),this._event}fire(e){var t;if(!(this._pauseTokens.size>0)){(null===(t=this.options)||void 0===t?void 0:t.replay)&&(this._last=e);for(const t of this._listeners)t.callback(e)}}pause(){const t={};return this._pauseTokens.add(t),e.DockviewDisposable.from(()=>this._pauseTokens.delete(t))}dispose(){this._disposed||(this._disposed=!0,this._listeners.length>0&&(m.ENABLE_TRACKING&&queueMicrotask(()=>{var e;for(const t of this._listeners)console.warn("dockview: stacktrace",null===(e=t.stacktrace)||void 0===e?void 0:e.print())}),this._listeners=[]),m.ENABLE_TRACKING&&this._event&&m.MEMORY_LEAK_WATCHER.delete(this._event))}}function v(e,t,i,s){return e.addEventListener(t,i,s),{dispose:()=>{e.removeEventListener(t,i,s)}}}m.ENABLE_TRACKING=!1,m.MEMORY_LEAK_WATCHER=new class{constructor(){this.events=new Map}get size(){return this.events.size}add(e,t){this.events.set(e,t)}delete(e){this.events.delete(e)}clear(){this.events.clear()}};class g{constructor(){this._onFired=new m,this._currentFireCount=0,this._queued=!1,this.onEvent=e=>{const t=this._currentFireCount;return this._onFired.event(()=>{this._currentFireCount>t&&e()})}}fire(){this._currentFireCount++,this._queued||(this._queued=!0,queueMicrotask(()=>{this._queued=!1,this._onFired.fire()}))}dispose(){this._onFired.dispose()}}class _ extends l{constructor(e){super(),this._onDidChange=new m,this.onDidChange=this._onDidChange.event,this._value=null,this.addDisposables(this._onDidChange,f(e,e=>{const t=e.target.scrollWidth>e.target.clientWidth,i=e.target.scrollHeight>e.target.clientHeight;this._value={hasScrollX:t,hasScrollY:i},this._onDidChange.fire(this._value)}))}}function f(e,t){const i=new ResizeObserver(e=>{requestAnimationFrame(()=>{const i=e[0];t(i)})});return i.observe(e),{dispose:()=>{i.unobserve(e),i.disconnect()}}}const b=(e,...t)=>{for(const i of t)e.classList.contains(i)&&e.classList.remove(i)},w=(e,...t)=>{for(const i of t)e.classList.contains(i)||e.classList.add(i)},D=(e,t,i)=>{const s=e.classList.contains(t);i&&!s&&e.classList.add(t),!i&&s&&e.classList.remove(t)};function C(e,t){for(;e;){if(e===t)return!0;e=e.parentNode}return!1}function y(e){return new S(e)}class S extends l{constructor(e){super(),this._onDidFocus=new m,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new m,this.onDidBlur=this._onDidBlur.event,this.addDisposables(this._onDidFocus,this._onDidBlur);let t=C(document.activeElement,e),i=!1;const s=()=>{i=!1,t||(t=!0,this._onDidFocus.fire())},o=()=>{t&&(i=!0,window.setTimeout(()=>{i&&(i=!1,t=!1,this._onDidBlur.fire())},0))};this._refreshStateHandler=()=>{C(document.activeElement,e)!==t&&(t?o():s())},this.addDisposables(v(e,"focus",s,!0)),this.addDisposables(v(e,"blur",o,!0))}refreshState(){this._refreshStateHandler()}}const x="dv-quasiPreventDefault";function G(e){return e[x]}function P(e){const{left:t,top:i,width:s,height:o}=e.getBoundingClientRect();return{left:t+window.scrollX,top:i+window.scrollY,width:s,height:o}}function T(e=document){const t=function(e,t){const i=[];return function t(s){if(s.nodeType===Node.ELEMENT_NODE){e.includes(s.tagName)&&i.push(s),s.shadowRoot&&t(s.shadowRoot);for(const e of s.children)t(e)}}(t instanceof Document?t.documentElement:t),i}(["IFRAME","WEBVIEW"],e),i=new WeakMap;for(const e of t)i.set(e,e.style.pointerEvents),e.style.pointerEvents="none";return{release:()=>{var e;for(const s of t)s.style.pointerEvents=null!==(e=i.get(s))&&void 0!==e?e:"auto";t.splice(0,t.length)}}}class I{constructor(e){this.element=e,this._classNames=[]}setClassNames(e){for(const e of this._classNames)D(this.element,e,!1);this._classNames=e.split(" ").filter(e=>e.trim().length>0);for(const e of this._classNames)D(this.element,e,!0)}}function z(e,t){const i=P(e),s=P(t);return!(i.left<s.left)&&(!(i.left+i.width>s.left+s.width)&&(!(i.top<s.top)&&!(i.top+i.height>s.top+s.height)))}function A(e){let t=e;for(;t&&("auto"===t.style.zIndex||""===t.style.zIndex);)t=t.parentElement;return t}function E(e){if(0===e.length)throw new Error("Invalid tail call");return[e.slice(0,e.length-1),e[e.length-1]]}function O(e,t){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(e[i]!==t[i])return!1;return!0}function M(e,t){const i=e.indexOf(t);i>-1&&(e.splice(i,1),e.unshift(t))}function k(e,t){const i=e.indexOf(t);i>-1&&(e.splice(i,1),e.push(t))}function V(e,t){const i=e.findIndex(e=>e===t);return i>-1&&(e.splice(i,1),!0)}const L=(e,t,i)=>t>i?t:Math.min(i,Math.max(e,t)),N=()=>{let e=1;return{next:()=>(e++).toString()}},R=(e,t)=>{const i=[];if("number"!=typeof t&&(t=e,e=0),e<=t)for(let s=e;s<t;s++)i.push(s);else for(let s=e;s>t;s--)i.push(s);return i};class W{set size(e){this._size=e}get size(){return this._size}get cachedVisibleSize(){return this._cachedVisibleSize}get visible(){return void 0===this._cachedVisibleSize}get minimumSize(){return this.visible?this.view.minimumSize:0}get viewMinimumSize(){return this.view.minimumSize}get maximumSize(){return this.visible?this.view.maximumSize:0}get viewMaximumSize(){return this.view.maximumSize}get priority(){return this.view.priority}get snap(){return!!this.view.snap}set enabled(e){this.container.style.pointerEvents=e?"":"none"}constructor(e,t,i,s){this.container=e,this.view=t,this.disposable=s,this._cachedVisibleSize=void 0,"number"==typeof i?(this._size=i,this._cachedVisibleSize=void 0,e.classList.add("visible")):(this._size=0,this._cachedVisibleSize=i.cachedVisibleSize)}setVisible(e,t){var i;e!==this.visible&&(e?(this.size=L(null!==(i=this._cachedVisibleSize)&&void 0!==i?i:0,this.viewMinimumSize,this.viewMaximumSize),this._cachedVisibleSize=void 0):(this._cachedVisibleSize="number"==typeof t?t:this.size,this.size=0),this.container.classList.toggle("visible",e),this.view.setVisible&&this.view.setVisible(e))}dispose(){return this.disposable.dispose(),this.view}}var H,F,B,$;e.Orientation=void 0,(H=e.Orientation||(e.Orientation={})).HORIZONTAL="HORIZONTAL",H.VERTICAL="VERTICAL",e.SashState=void 0,(F=e.SashState||(e.SashState={}))[F.MAXIMUM=0]="MAXIMUM",F[F.MINIMUM=1]="MINIMUM",F[F.DISABLED=2]="DISABLED",F[F.ENABLED=3]="ENABLED",e.LayoutPriority=void 0,(B=e.LayoutPriority||(e.LayoutPriority={})).Low="low",B.High="high",B.Normal="normal",e.Sizing=void 0,($=e.Sizing||(e.Sizing={})).Distribute={type:"distribute"},$.Split=function(e){return{type:"split",index:e}},$.Invisible=function(e){return{type:"invisible",cachedVisibleSize:e}};class U{get contentSize(){return this._contentSize}get size(){return this._size}set size(e){this._size=e}get orthogonalSize(){return this._orthogonalSize}set orthogonalSize(e){this._orthogonalSize=e}get length(){return this.viewItems.length}get proportions(){return this._proportions?[...this._proportions]:void 0}get orientation(){return this._orientation}set orientation(t){this._orientation=t;const i=this.size;this.size=this.orthogonalSize,this.orthogonalSize=i,b(this.element,"dv-horizontal","dv-vertical"),this.element.classList.add(this.orientation==e.Orientation.HORIZONTAL?"dv-horizontal":"dv-vertical")}get minimumSize(){return this.viewItems.reduce((e,t)=>e+t.minimumSize,0)}get maximumSize(){return 0===this.length?Number.POSITIVE_INFINITY:this.viewItems.reduce((e,t)=>e+t.maximumSize,0)}get startSnappingEnabled(){return this._startSnappingEnabled}set startSnappingEnabled(e){this._startSnappingEnabled!==e&&(this._startSnappingEnabled=e,this.updateSashEnablement())}get endSnappingEnabled(){return this._endSnappingEnabled}set endSnappingEnabled(e){this._endSnappingEnabled!==e&&(this._endSnappingEnabled=e,this.updateSashEnablement())}get disabled(){return this._disabled}set disabled(e){this._disabled=e,D(this.element,"dv-splitview-disabled",e)}get margin(){return this._margin}set margin(e){this._margin=e,D(this.element,"dv-splitview-has-margin",0!==e)}constructor(t,i){var s,o;this.container=t,this.viewItems=[],this.sashes=[],this._size=0,this._orthogonalSize=0,this._contentSize=0,this._proportions=void 0,this._startSnappingEnabled=!0,this._endSnappingEnabled=!0,this._disabled=!1,this._margin=0,this._onDidSashEnd=new m,this.onDidSashEnd=this._onDidSashEnd.event,this._onDidAddView=new m,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new m,this.onDidRemoveView=this._onDidRemoveView.event,this.resize=(e,t,i=this.viewItems.map(e=>e.size),s,o,n=Number.NEGATIVE_INFINITY,r=Number.POSITIVE_INFINITY,a,l)=>{if(e<0||e>this.viewItems.length)return 0;const h=R(e,-1),d=R(e+1,this.viewItems.length);if(o)for(const e of o)M(h,e),M(d,e);if(s)for(const e of s)k(h,e),k(d,e);const p=h.map(e=>this.viewItems[e]),c=h.map(e=>i[e]),u=d.map(e=>this.viewItems[e]),m=d.map(e=>i[e]),v=h.reduce((e,t)=>e+this.viewItems[t].minimumSize-i[t],0),g=h.reduce((e,t)=>e+this.viewItems[t].maximumSize-i[t],0),_=0===d.length?Number.POSITIVE_INFINITY:d.reduce((e,t)=>e+i[t]-this.viewItems[t].minimumSize,0),f=0===d.length?Number.NEGATIVE_INFINITY:d.reduce((e,t)=>e+i[t]-this.viewItems[t].maximumSize,0),b=Math.max(v,f),w=Math.min(_,g);let D=!1;if(a){const e=this.viewItems[a.index],i=t>=a.limitDelta;D=i!==e.visible,e.setVisible(i,a.size)}if(!D&&l){const e=this.viewItems[l.index],i=t<l.limitDelta;D=i!==e.visible,e.setVisible(i,l.size)}if(D)return this.resize(e,t,i,s,o,n,r);let C=0,y=L(t,b,w);for(let e=0;e<p.length;e++){const t=p[e],i=L(c[e]+y,t.minimumSize,t.maximumSize),s=i-c[e];C+=s,y-=s,t.size=i}let S=C;for(let e=0;e<u.length;e++){const t=u[e],i=L(m[e]-S,t.minimumSize,t.maximumSize);S+=i-m[e],t.size=i}return t},this._orientation=null!==(s=i.orientation)&&void 0!==s?s:e.Orientation.VERTICAL,this.element=this.createContainer(),this.margin=null!==(o=i.margin)&&void 0!==o?o:0,this.proportionalLayout=void 0===i.proportionalLayout||!!i.proportionalLayout,this.viewContainer=this.createViewContainer(),this.sashContainer=this.createSashContainer(),this.element.appendChild(this.sashContainer),this.element.appendChild(this.viewContainer),this.container.appendChild(this.element),this.style(i.styles),i.descriptor&&(this._size=i.descriptor.size,i.descriptor.views.forEach((e,t)=>{const i=void 0===e.visible||e.visible?e.size:{type:"invisible",cachedVisibleSize:e.size},s=e.view;this.addView(s,i,t,!0)}),this._contentSize=this.viewItems.reduce((e,t)=>e+t.size,0),this.saveProportions())}style(e){"transparent"===(null==e?void 0:e.separatorBorder)?(b(this.element,"dv-separator-border"),this.element.style.removeProperty("--dv-separator-border")):(w(this.element,"dv-separator-border"),(null==e?void 0:e.separatorBorder)&&this.element.style.setProperty("--dv-separator-border",e.separatorBorder))}isViewVisible(e){if(e<0||e>=this.viewItems.length)throw new Error("Index out of bounds");return this.viewItems[e].visible}setViewVisible(e,t){if(e<0||e>=this.viewItems.length)throw new Error("Index out of bounds");const i=this.viewItems[e];i.setVisible(t,i.size),this.distributeEmptySpace(e),this.layoutViews(),this.saveProportions()}getViewSize(e){return e<0||e>=this.viewItems.length?-1:this.viewItems[e].size}resizeView(t,i){if(t<0||t>=this.viewItems.length)return;const s=R(this.viewItems.length).filter(e=>e!==t),o=[...s.filter(t=>this.viewItems[t].priority===e.LayoutPriority.Low),t],n=s.filter(t=>this.viewItems[t].priority===e.LayoutPriority.High),r=this.viewItems[t];i=Math.round(i),i=L(i,r.minimumSize,Math.min(r.maximumSize,this._size)),r.size=i,this.relayout(o,n)}getViews(){return this.viewItems.map(e=>e.view)}onDidChange(t,i){const s=this.viewItems.indexOf(t);if(s<0||s>=this.viewItems.length)return;i="number"==typeof i?i:t.size,i=L(i,t.minimumSize,t.maximumSize),t.size=i;const o=R(this.viewItems.length).filter(e=>e!==s),n=[...o.filter(t=>this.viewItems[t].priority===e.LayoutPriority.Low),s],r=o.filter(t=>this.viewItems[t].priority===e.LayoutPriority.High);this.relayout([...n,s],r)}addView(t,i={type:"distribute"},s=this.viewItems.length,o){const n=document.createElement("div");let r;n.className="dv-view",n.appendChild(t.element),r="number"==typeof i?i:"split"===i.type?this.getViewSize(i.index)/2:"invisible"===i.type?{cachedVisibleSize:i.cachedVisibleSize}:t.minimumSize;const a=t.onDidChange(e=>this.onDidChange(l,e.size)),l=new W(n,t,r,{dispose:()=>{a.dispose(),this.viewContainer.removeChild(n)}});if(s===this.viewItems.length?this.viewContainer.appendChild(n):this.viewContainer.insertBefore(n,this.viewContainer.children.item(s)),this.viewItems.splice(s,0,l),this.viewItems.length>1){const t=document.createElement("div");t.className="dv-sash";const i=i=>{for(const e of this.viewItems)e.enabled=!1;const s=T(),o=this._orientation===e.Orientation.HORIZONTAL?i.clientX:i.clientY,n=function(e,t){for(let i=0;i<e.length;i++)if(t(e[i]))return i;return-1}(this.sashes,e=>e.container===t),r=this.viewItems.map(e=>e.size);let a,l;const h=R(n,-1),d=R(n+1,this.viewItems.length),p=h.reduce((e,t)=>e+(this.viewItems[t].minimumSize-r[t]),0),c=h.reduce((e,t)=>e+(this.viewItems[t].viewMaximumSize-r[t]),0),u=0===d.length?Number.POSITIVE_INFINITY:d.reduce((e,t)=>e+(r[t]-this.viewItems[t].minimumSize),0),m=0===d.length?Number.NEGATIVE_INFINITY:d.reduce((e,t)=>e+(r[t]-this.viewItems[t].viewMaximumSize),0),v=Math.max(p,m),g=Math.min(u,c),_=this.findFirstSnapIndex(h),f=this.findFirstSnapIndex(d);if("number"==typeof _){const e=this.viewItems[_],t=Math.floor(e.viewMinimumSize/2);a={index:_,limitDelta:e.visible?v-t:v+t,size:e.size}}if("number"==typeof f){const e=this.viewItems[f],t=Math.floor(e.viewMinimumSize/2);l={index:f,limitDelta:e.visible?g+t:g-t,size:e.size}}const b=t=>{const i=(this._orientation===e.Orientation.HORIZONTAL?t.clientX:t.clientY)-o;this.resize(n,i,r,void 0,void 0,v,g,a,l),this.distributeEmptySpace(),this.layoutViews()},w=()=>{for(const e of this.viewItems)e.enabled=!0;s.release(),this.saveProportions(),document.removeEventListener("pointermove",b),document.removeEventListener("pointerup",w),document.removeEventListener("pointercancel",w),document.removeEventListener("contextmenu",w),this._onDidSashEnd.fire(void 0)};document.addEventListener("pointermove",b),document.addEventListener("pointerup",w),document.addEventListener("pointercancel",w),document.addEventListener("contextmenu",w)};t.addEventListener("pointerdown",i);const s={container:t,disposable:()=>{t.removeEventListener("pointerdown",i),this.sashContainer.removeChild(t)}};this.sashContainer.appendChild(t),this.sashes.push(s)}o||this.relayout([s]),o||"number"==typeof i||"distribute"!==i.type||this.distributeViewSizes(),this._onDidAddView.fire(t)}distributeViewSizes(){const t=[];let i=0;for(const e of this.viewItems)e.maximumSize-e.minimumSize>0&&(t.push(e),i+=e.size);const s=Math.floor(i/t.length);for(const e of t)e.size=L(s,e.minimumSize,e.maximumSize);const o=R(this.viewItems.length),n=o.filter(t=>this.viewItems[t].priority===e.LayoutPriority.Low),r=o.filter(t=>this.viewItems[t].priority===e.LayoutPriority.High);this.relayout(n,r)}removeView(e,t,i=!1){const s=this.viewItems.splice(e,1)[0];if(s.dispose(),this.viewItems.length>=1){const t=Math.max(e-1,0);this.sashes.splice(t,1)[0].disposable()}return i||this.relayout(),t&&"distribute"===t.type&&this.distributeViewSizes(),this._onDidRemoveView.fire(s.view),s.view}getViewCachedVisibleSize(e){if(e<0||e>=this.viewItems.length)throw new Error("Index out of bounds");return this.viewItems[e].cachedVisibleSize}moveView(t,i){const s=this.getViewCachedVisibleSize(t),o=void 0===s?this.getViewSize(t):e.Sizing.Invisible(s),n=this.removeView(t,void 0,!0);this.addView(n,o,i)}layout(t,i){const s=Math.max(this.size,this._contentSize);if(this.size=t,this.orthogonalSize=i,this.proportions){let e=0;for(let i=0;i<this.viewItems.length;i++){const s=this.viewItems[i],o=this.proportions[i];"number"==typeof o?e+=o:t-=s.size}for(let i=0;i<this.viewItems.length;i++){const s=this.viewItems[i],o=this.proportions[i];"number"==typeof o&&e>0&&(s.size=L(Math.round(o*t/e),s.minimumSize,s.maximumSize))}}else{const i=R(this.viewItems.length),o=i.filter(t=>this.viewItems[t].priority===e.LayoutPriority.Low),n=i.filter(t=>this.viewItems[t].priority===e.LayoutPriority.High);this.resize(this.viewItems.length-1,t-s,void 0,o,n)}this.distributeEmptySpace(),this.layoutViews()}relayout(e,t){const i=this.viewItems.reduce((e,t)=>e+t.size,0);this.resize(this.viewItems.length-1,this._size-i,void 0,e,t),this.distributeEmptySpace(),this.layoutViews(),this.saveProportions()}distributeEmptySpace(t){const i=this.viewItems.reduce((e,t)=>e+t.size,0);let s=this.size-i;const o=R(this.viewItems.length-1,-1),n=o.filter(t=>this.viewItems[t].priority===e.LayoutPriority.Low),r=o.filter(t=>this.viewItems[t].priority===e.LayoutPriority.High);for(const e of r)M(o,e);for(const e of n)k(o,e);"number"==typeof t&&k(o,t);for(let e=0;0!==s&&e<o.length;e++){const t=this.viewItems[o[e]],i=L(t.size+s,t.minimumSize,t.maximumSize);s-=i-t.size,t.size=i}}saveProportions(){this.proportionalLayout&&this._contentSize>0&&(this._proportions=this.viewItems.map(e=>e.visible?e.size/this._contentSize:void 0))}layoutViews(){if(this._contentSize=this.viewItems.reduce((e,t)=>e+t.size,0),this.updateSashEnablement(),0===this.viewItems.length)return;const t=this.viewItems.filter(e=>e.visible),i=Math.max(0,t.length-1),s=this.margin*i/Math.max(1,t.length);let o=0;const n=[],r=this.viewItems.reduce((e,t,i)=>{const s=t.visible?1:0;return 0===i?e.push(s):e.push(e[i-1]+s),e},[]);this.viewItems.forEach((t,a)=>{o+=this.viewItems[a].size,n.push(o);const l=t.visible?t.size-s:0,h=Math.max(0,r[a]-1),d=0===a||0===h?0:n[a-1]+h/i*s;if(a<this.viewItems.length-1){const i=t.visible?d+l-2+this.margin/2:d;this._orientation===e.Orientation.HORIZONTAL&&(this.sashes[a].container.style.left=`${i}px`,this.sashes[a].container.style.top="0px"),this._orientation===e.Orientation.VERTICAL&&(this.sashes[a].container.style.left="0px",this.sashes[a].container.style.top=`${i}px`)}this._orientation===e.Orientation.HORIZONTAL&&(t.container.style.width=`${l}px`,t.container.style.left=`${d}px`,t.container.style.top="",t.container.style.height=""),this._orientation===e.Orientation.VERTICAL&&(t.container.style.height=`${l}px`,t.container.style.top=`${d}px`,t.container.style.width="",t.container.style.left=""),t.view.layout(t.size-s,this._orthogonalSize)})}findFirstSnapIndex(e){for(const t of e){const e=this.viewItems[t];if(e.visible&&e.snap)return t}for(const t of e){const e=this.viewItems[t];if(e.visible&&e.maximumSize-e.minimumSize>0)return;if(!e.visible&&e.snap)return t}}updateSashEnablement(){let t=!1;const i=this.viewItems.map(e=>t=e.size-e.minimumSize>0||t);t=!1;const s=this.viewItems.map(e=>t=e.maximumSize-e.size>0||t),o=[...this.viewItems].reverse();t=!1;const n=o.map(e=>t=e.size-e.minimumSize>0||t).reverse();t=!1;const r=o.map(e=>t=e.maximumSize-e.size>0||t).reverse();let a=0;for(let t=0;t<this.sashes.length;t++){const o=this.sashes[t];a+=this.viewItems[t].size;const l=!(i[t]&&r[t+1]),h=!(s[t]&&n[t+1]);if(l&&h){const s=R(t,-1),r=R(t+1,this.viewItems.length),l=this.findFirstSnapIndex(s),h=this.findFirstSnapIndex(r),d="number"==typeof l&&!this.viewItems[l].visible,p="number"==typeof h&&!this.viewItems[h].visible;d&&n[t]&&(a>0||this.startSnappingEnabled)?this.updateSash(o,e.SashState.MINIMUM):p&&i[t]&&(a<this._contentSize||this.endSnappingEnabled)?this.updateSash(o,e.SashState.MAXIMUM):this.updateSash(o,e.SashState.DISABLED)}else l&&!h?this.updateSash(o,e.SashState.MINIMUM):!l&&h?this.updateSash(o,e.SashState.MAXIMUM):this.updateSash(o,e.SashState.ENABLED)}}updateSash(t,i){D(t.container,"dv-disabled",i===e.SashState.DISABLED),D(t.container,"dv-enabled",i===e.SashState.ENABLED),D(t.container,"dv-maximum",i===e.SashState.MAXIMUM),D(t.container,"dv-minimum",i===e.SashState.MINIMUM)}createViewContainer(){const e=document.createElement("div");return e.className="dv-view-container",e}createSashContainer(){const e=document.createElement("div");return e.className="dv-sash-container",e}createContainer(){const t=document.createElement("div"),i=this._orientation===e.Orientation.HORIZONTAL?"dv-horizontal":"dv-vertical";return t.className=`dv-split-view-container ${i}`,t}dispose(){this._onDidSashEnd.dispose(),this._onDidAddView.dispose(),this._onDidRemoveView.dispose();for(let e=0;e<this.element.children.length;e++)if(this.element.children.item(e)===this.element){this.element.removeChild(this.element);break}for(const e of this.viewItems)e.dispose();this.element.remove()}}const Y=(()=>{const e={orientation:void 0,descriptor:void 0,proportionalLayout:void 0,styles:void 0,margin:void 0,disableAutoResizing:void 0,className:void 0};return Object.keys(e)})();class X extends l{get onDidAddView(){return this.splitview.onDidAddView}get onDidRemoveView(){return this.splitview.onDidRemoveView}get minimumSize(){return this.splitview.minimumSize}get maximumSize(){return this.splitview.maximumSize}get orientation(){return this.splitview.orientation}get size(){return this.splitview.size}get orthogonalSize(){return this.splitview.orthogonalSize}constructor(t,i){var s;super(),this.paneItems=[],this.skipAnimation=!1,this._onDidChange=new m,this.onDidChange=this._onDidChange.event,this._orientation=null!==(s=i.orientation)&&void 0!==s?s:e.Orientation.VERTICAL,this.element=document.createElement("div"),this.element.className="dv-pane-container",t.appendChild(this.element),this.splitview=new U(this.element,{orientation:this._orientation,proportionalLayout:!1,descriptor:i.descriptor}),this.getPanes().forEach(e=>{const t=new l(e.onDidChangeExpansionState(()=>{this.setupAnimation(),this._onDidChange.fire(void 0)})),i={pane:e,disposable:{dispose:()=>{t.dispose()}}};this.paneItems.push(i),e.orthogonalSize=this.splitview.orthogonalSize}),this.addDisposables(this._onDidChange,this.splitview.onDidSashEnd(()=>{this._onDidChange.fire(void 0)}),this.splitview.onDidAddView(()=>{this._onDidChange.fire()}),this.splitview.onDidRemoveView(()=>{this._onDidChange.fire()}))}setViewVisible(e,t){this.splitview.setViewVisible(e,t)}addPane(e,t,i=this.splitview.length,s=!1){const o=e.onDidChangeExpansionState(()=>{this.setupAnimation(),this._onDidChange.fire(void 0)}),n={pane:e,disposable:{dispose:()=>{o.dispose()}}};this.paneItems.splice(i,0,n),e.orthogonalSize=this.splitview.orthogonalSize,this.splitview.addView(e,t,i,s)}getViewSize(e){return this.splitview.getViewSize(e)}getPanes(){return this.splitview.getViews()}removePane(e,t={skipDispose:!1}){const i=this.paneItems.splice(e,1)[0];return this.splitview.removeView(e),t.skipDispose||(i.disposable.dispose(),i.pane.dispose()),i}moveView(e,t){if(e===t)return;const i=this.removePane(e,{skipDispose:!0});this.skipAnimation=!0;try{this.addPane(i.pane,i.pane.size,t,!1)}finally{this.skipAnimation=!1}}layout(e,t){this.splitview.layout(e,t)}setupAnimation(){this.skipAnimation||(this.animationTimer&&(clearTimeout(this.animationTimer),this.animationTimer=void 0),w(this.element,"dv-animated"),this.animationTimer=setTimeout(()=>{this.animationTimer=void 0,b(this.element,"dv-animated")},200))}dispose(){super.dispose(),this.animationTimer&&(clearTimeout(this.animationTimer),this.animationTimer=void 0),this.paneItems.forEach(e=>{e.disposable.dispose(),e.pane.dispose()}),this.paneItems=[],this.splitview.dispose(),this.element.remove()}}class J{get minimumWidth(){return this.view.minimumWidth}get maximumWidth(){return this.view.maximumWidth}get minimumHeight(){return this.view.minimumHeight}get maximumHeight(){return this.view.maximumHeight}get priority(){return this.view.priority}get snap(){return this.view.snap}get minimumSize(){return this.orientation===e.Orientation.HORIZONTAL?this.minimumHeight:this.minimumWidth}get maximumSize(){return this.orientation===e.Orientation.HORIZONTAL?this.maximumHeight:this.maximumWidth}get minimumOrthogonalSize(){return this.orientation===e.Orientation.HORIZONTAL?this.minimumWidth:this.minimumHeight}get maximumOrthogonalSize(){return this.orientation===e.Orientation.HORIZONTAL?this.maximumWidth:this.maximumHeight}get orthogonalSize(){return this._orthogonalSize}get size(){return this._size}get element(){return this.view.element}get width(){return this.orientation===e.Orientation.HORIZONTAL?this.orthogonalSize:this.size}get height(){return this.orientation===e.Orientation.HORIZONTAL?this.size:this.orthogonalSize}constructor(t,i,s,o=0){this.view=t,this.orientation=i,this._onDidChange=new m,this.onDidChange=this._onDidChange.event,this._orthogonalSize=s,this._size=o,this._disposable=this.view.onDidChange(t=>{t?this._onDidChange.fire({size:this.orientation===e.Orientation.VERTICAL?t.width:t.height,orthogonalSize:this.orientation===e.Orientation.VERTICAL?t.height:t.width}):this._onDidChange.fire({})})}setVisible(e){this.view.setVisible&&this.view.setVisible(e)}layout(e,t){this._size=e,this._orthogonalSize=t,this.view.layout(this.width,this.height)}dispose(){this._onDidChange.dispose(),this._disposable.dispose()}}class j extends l{get width(){return this.orientation===e.Orientation.HORIZONTAL?this.size:this.orthogonalSize}get height(){return this.orientation===e.Orientation.HORIZONTAL?this.orthogonalSize:this.size}get minimumSize(){return 0===this.children.length?0:Math.max(...this.children.map((e,t)=>this.splitview.isViewVisible(t)?e.minimumOrthogonalSize:0))}get maximumSize(){return Math.min(...this.children.map((e,t)=>this.splitview.isViewVisible(t)?e.maximumOrthogonalSize:Number.POSITIVE_INFINITY))}get minimumOrthogonalSize(){return this.splitview.minimumSize}get maximumOrthogonalSize(){return this.splitview.maximumSize}get orthogonalSize(){return this._orthogonalSize}get size(){return this._size}get minimumWidth(){return this.orientation===e.Orientation.HORIZONTAL?this.minimumOrthogonalSize:this.minimumSize}get minimumHeight(){return this.orientation===e.Orientation.HORIZONTAL?this.minimumSize:this.minimumOrthogonalSize}get maximumWidth(){return this.orientation===e.Orientation.HORIZONTAL?this.maximumOrthogonalSize:this.maximumSize}get maximumHeight(){return this.orientation===e.Orientation.HORIZONTAL?this.maximumSize:this.maximumOrthogonalSize}get priority(){if(0===this.children.length)return e.LayoutPriority.Normal;const t=this.children.map(t=>void 0===t.priority?e.LayoutPriority.Normal:t.priority);return t.some(t=>t===e.LayoutPriority.High)?e.LayoutPriority.High:t.some(t=>t===e.LayoutPriority.Low)?e.LayoutPriority.Low:e.LayoutPriority.Normal}get disabled(){return this.splitview.disabled}set disabled(e){this.splitview.disabled=e}get margin(){return this.splitview.margin}set margin(e){this.splitview.margin=e,this.children.forEach(t=>{t instanceof j&&(t.margin=e)})}constructor(t,i,s,o,n,r,a,l){if(super(),this.orientation=t,this.proportionalLayout=i,this.styles=s,this._childrenDisposable=e.DockviewDisposable.NONE,this.children=[],this._onDidChange=new m,this.onDidChange=this._onDidChange.event,this._onDidVisibilityChange=new m,this.onDidVisibilityChange=this._onDidVisibilityChange.event,this._orthogonalSize=n,this._size=o,this.element=document.createElement("div"),this.element.className="dv-branch-node",l){const e={views:l.map(e=>({view:e.node,size:e.node.size,visible:!(e.node instanceof J&&void 0!==e.visible)||e.visible})),size:this.orthogonalSize};this.children=l.map(e=>e.node),this.splitview=new U(this.element,{orientation:this.orientation,descriptor:e,proportionalLayout:i,styles:s,margin:a})}else this.splitview=new U(this.element,{orientation:this.orientation,proportionalLayout:i,styles:s,margin:a}),this.splitview.layout(this.size,this.orthogonalSize);this.disabled=r,this.addDisposables(this._onDidChange,this._onDidVisibilityChange,this.splitview.onDidSashEnd(()=>{this._onDidChange.fire({})})),this.setupChildrenEvents()}setVisible(e){}isChildVisible(e){if(e<0||e>=this.children.length)throw new Error("Invalid index");return this.splitview.isViewVisible(e)}setChildVisible(e,t){if(e<0||e>=this.children.length)throw new Error("Invalid index");if(this.splitview.isViewVisible(e)===t)return;const i=0===this.splitview.contentSize;this.splitview.setViewVisible(e,t);const s=0===this.splitview.contentSize;(t&&i||!t&&s)&&this._onDidVisibilityChange.fire({visible:t})}moveChild(e,t){if(e===t)return;if(e<0||e>=this.children.length)throw new Error("Invalid from index");e<t&&t--,this.splitview.moveView(e,t);const i=this._removeChild(e);this._addChild(i,t)}getChildSize(e){if(e<0||e>=this.children.length)throw new Error("Invalid index");return this.splitview.getViewSize(e)}resizeChild(e,t){if(e<0||e>=this.children.length)throw new Error("Invalid index");this.splitview.resizeView(e,t)}layout(e,t){this._size=t,this._orthogonalSize=e,this.splitview.layout(t,e)}addChild(e,t,i,s){if(i<0||i>this.children.length)throw new Error("Invalid index");this.splitview.addView(e,t,i,s),this._addChild(e,i)}getChildCachedVisibleSize(e){if(e<0||e>=this.children.length)throw new Error("Invalid index");return this.splitview.getViewCachedVisibleSize(e)}removeChild(e,t){if(e<0||e>=this.children.length)throw new Error("Invalid index");return this.splitview.removeView(e,t),this._removeChild(e)}_addChild(e,t){this.children.splice(t,0,e),this.setupChildrenEvents()}_removeChild(e){const[t]=this.children.splice(e,1);return this.setupChildrenEvents(),t}setupChildrenEvents(){this._childrenDisposable.dispose(),this._childrenDisposable=new l(e.DockviewEvent.any(...this.children.map(e=>e.onDidChange))(e=>{this._onDidChange.fire({size:e.orthogonalSize})}),...this.children.map((t,i)=>t instanceof j?t.onDidVisibilityChange(({visible:e})=>{this.setChildVisible(i,e)}):e.DockviewDisposable.NONE))}dispose(){this._childrenDisposable.dispose(),this.splitview.dispose(),this.children.forEach(e=>e.dispose()),super.dispose()}}function Z(e,t){if(e instanceof J)return e;if(e instanceof j)return Z(e.children[t?e.children.length-1:0],t);throw new Error("invalid node")}function q(e,t,i){if(e instanceof j){const s=new j(e.orientation,e.proportionalLayout,e.styles,t,i,e.disabled,e.margin);for(let t=e.children.length-1;t>=0;t--){const i=e.children[t];s.addChild(q(i,i.size,i.orthogonalSize),i.size,0,!0)}return s}return new J(e.view,e.orientation,i)}function K(e,t,i){if(e instanceof j){const s=new j(oe(e.orientation),e.proportionalLayout,e.styles,t,i,e.disabled,e.margin);let o=0;for(let n=e.children.length-1;n>=0;n--){const r=e.children[n],a=r instanceof j?r.orthogonalSize:r.size;let l=0===e.size?0:Math.round(t*a/e.size);o+=l,0===n&&(l+=t-o),s.addChild(K(r,i,l),l,0,!0)}return s}return new J(e.view,oe(e.orientation),i)}function Q(e){const t=e.parentElement;if(!t)throw new Error("Invalid grid element");let i=t.firstElementChild,s=0;for(;i!==e&&i!==t.lastElementChild&&i;)i=i.nextElementSibling,s++;return s}function ee(e){const t=e.parentElement;if(!t)throw new Error("Invalid grid element");if(/\bdv-grid-view\b/.test(t.className))return[];const i=Q(t);return[...ee(t.parentElement.parentElement.parentElement),i]}function te(e,t,i){if(se(e,t)===ie(i)){const[e,s]=E(t);let o=s;return"right"!==i&&"bottom"!==i||(o+=1),[...e,o]}{const e="right"===i||"bottom"===i?1:0;return[...t,e]}}function ie(t){return"top"===t||"bottom"===t?e.Orientation.VERTICAL:e.Orientation.HORIZONTAL}function se(e,t){return t.length%2==0?oe(e):e}const oe=t=>t===e.Orientation.HORIZONTAL?e.Orientation.VERTICAL:e.Orientation.HORIZONTAL;function ne(e){return!!e.children}const re=(t,i)=>{const s=i===e.Orientation.VERTICAL?t.box.width:t.box.height;return ne(t)?{type:"branch",data:t.children.map(e=>re(e,oe(i))),size:s}:"number"==typeof t.cachedVisibleSize?{type:"leaf",data:t.view.toJSON(),size:t.cachedVisibleSize,visible:!1}:{type:"leaf",data:t.view.toJSON(),size:s}};class ae{get length(){return this._root?this._root.children.length:0}get orientation(){return this.root.orientation}set orientation(e){if(this.root.orientation===e)return;const{size:t,orthogonalSize:i}=this.root;this.root=K(this.root,i,t),this.root.layout(t,i)}get width(){return this.root.width}get height(){return this.root.height}get minimumWidth(){return this.root.minimumWidth}get minimumHeight(){return this.root.minimumHeight}get maximumWidth(){return this.root.maximumHeight}get maximumHeight(){return this.root.maximumHeight}get locked(){return this._locked}set locked(e){this._locked=e;const t=[this.root];for(;t.length>0;){const i=t.pop();i instanceof j&&(i.disabled=e,t.push(...i.children))}}get margin(){return this._margin}set margin(e){this._margin=e,this.root.margin=e}maximizedView(){var e;return null===(e=this._maximizedNode)||void 0===e?void 0:e.leaf.view}hasMaximizedView(){return void 0!==this._maximizedNode}maximizeView(e){var t;const i=ee(e.element),[s,o]=this.getNode(i);if(!(o instanceof J))return;if((null===(t=this._maximizedNode)||void 0===t?void 0:t.leaf)===o)return;this.hasMaximizedView()&&this.exitMaximizedView(),re(this.getView(),this.orientation);const n=[];!function e(t,i){for(let s=0;s<t.children.length;s++){const o=t.children[s];o instanceof J?o!==i&&(t.isChildVisible(s)?t.setChildVisible(s,!1):n.push(o)):e(o,i)}}(this.root,o),this._maximizedNode={leaf:o,hiddenOnMaximize:n},this._onDidMaximizedNodeChange.fire({view:o.view,isMaximized:!0})}exitMaximizedView(){if(!this._maximizedNode)return;const e=this._maximizedNode.hiddenOnMaximize;!function t(i){for(let s=i.children.length-1;s>=0;s--){const o=i.children[s];o instanceof J?e.includes(o)||i.setChildVisible(s,!0):t(o)}}(this.root);const t=this._maximizedNode.leaf;this._maximizedNode=void 0,this._onDidMaximizedNodeChange.fire({view:t.view,isMaximized:!1})}serialize(){const e=this.maximizedView();let t;e&&(t=ee(e.element));const i=this._onDidMaximizedNodeChange.pause();try{this.hasMaximizedView()&&this.exitMaximizedView();const i={root:re(this.getView(),this.orientation),width:this.width,height:this.height,orientation:this.orientation};return t&&(i.maximizedNode={location:t}),e&&this.maximizeView(e),i}finally{i.dispose()}}dispose(){this.disposable.dispose(),this._onDidChange.dispose(),this._onDidMaximizedNodeChange.dispose(),this._onDidViewVisibilityChange.dispose(),this.root.dispose(),this._maximizedNode=void 0,this.element.remove()}clear(){const e=this.root.orientation;this.root=new j(e,this.proportionalLayout,this.styles,this.root.size,this.root.orthogonalSize,this.locked,this.margin)}deserialize(t,i){const s=t.orientation,o=s===e.Orientation.VERTICAL?t.height:t.width;if(this._deserialize(t.root,s,i,o),this.layout(t.width,t.height),t.maximizedNode){const e=t.maximizedNode.location,[i,s]=this.getNode(e);if(!(s instanceof J))return;this.maximizeView(s.view)}}_deserialize(e,t,i,s){this.root=this._deserializeNode(e,t,i,s)}_deserializeNode(e,t,i,s){var o;let n;if("branch"===e.type){const o=e.data.map(s=>({node:this._deserializeNode(s,oe(t),i,e.size),visible:s.visible}));n=new j(t,this.proportionalLayout,this.styles,e.size,s,this.locked,this.margin,o)}else{const r=i.fromJSON(e);"boolean"==typeof e.visible&&(null===(o=r.setVisible)||void 0===o||o.call(r,e.visible)),n=new J(r,t,s,e.size)}return n}get root(){return this._root}set root(e){const t=this._root;t&&(t.dispose(),this._maximizedNode=void 0,this.element.removeChild(t.element)),this._root=e,this.element.appendChild(this._root.element),this.disposable.value=this._root.onDidChange(e=>{this._onDidChange.fire(e)})}normalize(){if(!this._root)return;if(1!==this._root.children.length)return;const e=this.root,t=e.children[0];if(t instanceof J)return;e.element.remove();const i=e.removeChild(0);e.dispose(),i.dispose(),this._root=q(t,t.size,t.orthogonalSize),this.element.appendChild(this._root.element),this.disposable.value=this._root.onDidChange(e=>{this._onDidChange.fire(e)})}insertOrthogonalSplitviewAtRoot(){if(!this._root)return;const t=this.root;if(t.element.remove(),this._root=new j(oe(t.orientation),this.proportionalLayout,this.styles,this.root.orthogonalSize,this.root.size,this.locked,this.margin),0===t.children.length);else if(1===t.children.length){const i=t.children[0];t.removeChild(0).dispose(),t.dispose(),this._root.addChild(K(i,i.orthogonalSize,i.size),e.Sizing.Distribute,0)}else this._root.addChild(t,e.Sizing.Distribute,0);this.element.appendChild(this._root.element),this.disposable.value=this._root.onDidChange(e=>{this._onDidChange.fire(e)})}next(e){return this.progmaticSelect(e)}previous(e){return this.progmaticSelect(e,!0)}getView(e){const t=e?this.getNode(e)[1]:this.root;return this._getViews(t,this.orientation)}_getViews(e,t,i){const s={height:e.height,width:e.width};if(e instanceof J)return{box:s,view:e.view,cachedVisibleSize:i};const o=[];for(let i=0;i<e.children.length;i++){const s=e.children[i],n=e.getChildCachedVisibleSize(i);o.push(this._getViews(s,oe(t),n))}return{box:s,children:o}}progmaticSelect(e,t=!1){const[i,s]=this.getNode(e);if(!(s instanceof J))throw new Error("invalid location");for(let s=i.length-1;s>-1;s--){const o=i[s],n=e[s]||0;if(t?n-1>-1:n+1<o.children.length)return Z(o.children[t?n-1:n+1],t)}return Z(this.root,t)}constructor(e,t,i,s,o){this.proportionalLayout=e,this.styles=t,this._locked=!1,this._margin=0,this._maximizedNode=void 0,this.disposable=new h,this._onDidChange=new m,this.onDidChange=this._onDidChange.event,this._onDidViewVisibilityChange=new m,this.onDidViewVisibilityChange=this._onDidViewVisibilityChange.event,this._onDidMaximizedNodeChange=new m,this.onDidMaximizedNodeChange=this._onDidMaximizedNodeChange.event,this.element=document.createElement("div"),this.element.className="dv-grid-view",this._locked=null!=s&&s,this._margin=null!=o?o:0,this.root=new j(i,e,t,0,0,this.locked,this.margin)}isViewVisible(e){const[t,i]=E(e),[,s]=this.getNode(t);if(!(s instanceof j))throw new Error("Invalid from location");return s.isChildVisible(i)}setViewVisible(e,t){this.hasMaximizedView()&&this.exitMaximizedView();const[i,s]=E(e),[,o]=this.getNode(i);if(!(o instanceof j))throw new Error("Invalid from location");this._onDidViewVisibilityChange.fire(),o.setChildVisible(s,t)}moveView(e,t,i){this.hasMaximizedView()&&this.exitMaximizedView();const[,s]=this.getNode(e);if(!(s instanceof j))throw new Error("Invalid location");s.moveChild(t,i)}addView(t,i,s){this.hasMaximizedView()&&this.exitMaximizedView();const[o,n]=E(s),[r,a]=this.getNode(o);if(a instanceof j){const e=new J(t,oe(a.orientation),a.orthogonalSize);a.addChild(e,i,n)}else{const[s,...l]=[...r].reverse(),[h,...d]=[...o].reverse();let p=0;const c=s.getChildCachedVisibleSize(h);"number"==typeof c&&(p=e.Sizing.Invisible(c));s.removeChild(h).dispose();const u=new j(a.orientation,this.proportionalLayout,this.styles,a.size,a.orthogonalSize,this.locked,this.margin);s.addChild(u,a.size,h);const m=new J(a.view,s.orientation,a.size);u.addChild(m,p,0),"number"!=typeof i&&"split"===i.type&&(i={type:"split",index:0});const v=new J(t,s.orientation,a.size);u.addChild(v,i,n)}}remove(e,t){const i=ee(e.element);return this.removeView(i,t)}removeView(t,i){this.hasMaximizedView()&&this.exitMaximizedView();const[s,o]=E(t),[n,r]=this.getNode(s);if(!(r instanceof j))throw new Error("Invalid location");const a=r.children[o];if(!(a instanceof J))throw new Error("Invalid location");if(r.removeChild(o,i),a.dispose(),1!==r.children.length)return a.view;const l=r.children[0];if(0===n.length)return l instanceof J||(r.removeChild(0,i),this.root=l),a.view;const[h,...d]=[...n].reverse(),[p,...c]=[...s].reverse(),u=r.isChildVisible(0);r.removeChild(0,i);const m=h.children.map((e,t)=>h.getChildSize(t));if(h.removeChild(p,i).dispose(),l instanceof j){m.splice(p,1,...l.children.map(e=>e.size));for(let e=0;e<l.children.length;e++){const t=l.children[e];h.addChild(t,t.size,p+e)}for(;l.children.length>0;)l.removeChild(0)}else{const t=new J(l.view,oe(l.orientation),l.size),i=u?l.orthogonalSize:e.Sizing.Invisible(l.orthogonalSize);h.addChild(t,i,p)}l.dispose();for(let e=0;e<m.length;e++)h.resizeChild(e,m[e]);return a.view}layout(t,i){const[s,o]=this.root.orientation===e.Orientation.HORIZONTAL?[i,t]:[t,i];this.root.layout(s,o)}getNode(e,t=this.root,i=[]){if(0===e.length)return[i,t];if(!(t instanceof j))throw new Error("Invalid location");const[s,...o]=e;if(s<0||s>=t.children.length)throw new Error("Invalid location");const n=t.children[s];return i.push(t),this.getNode(o,n,i)}}const le=(()=>{const e={disableAutoResizing:void 0,proportionalLayout:void 0,orientation:void 0,hideBorders:void 0,className:void 0};return Object.keys(e)})();class he extends l{get element(){return this._element}get disableResizing(){return this._disableResizing}set disableResizing(e){this._disableResizing=e}constructor(e,t=!1){super(),this._lastWidth=-1,this._lastHeight=-1,this._disableResizing=t,this._element=e,this.addDisposables(f(this._element,e=>{if(this.isDisposed)return;if(this.disableResizing)return;if(!this._element.offsetParent)return;if(!function(e){let t=e;for(;null==t?void 0:t.parentNode;){if(t.parentNode===document)return!0;t=t.parentNode instanceof DocumentFragment?t.parentNode.host:t.parentNode}return!1}(this._element))return;const t=Math.round(e.contentRect.width),i=Math.round(e.contentRect.height);t===this._lastWidth&&i===this._lastHeight||(this._lastWidth=t,this._lastHeight=i,this.layout(t,i))}))}}const de=N();function pe(e){switch(e){case"left":return"left";case"right":return"right";case"above":return"top";case"below":return"bottom";default:return"center"}}class ce extends he{get id(){return this._id}get size(){return this._groups.size}get groups(){return Array.from(this._groups.values()).map(e=>e.value)}get width(){return this.gridview.width}get height(){return this.gridview.height}get minimumHeight(){return this.gridview.minimumHeight}get maximumHeight(){return this.gridview.maximumHeight}get minimumWidth(){return this.gridview.minimumWidth}get maximumWidth(){return this.gridview.maximumWidth}get activeGroup(){return this._activeGroup}get locked(){return this.gridview.locked}set locked(e){this.gridview.locked=e}constructor(t,i){var s;super(document.createElement("div"),i.disableAutoResizing),this._id=de.next(),this._groups=new Map,this._onDidRemove=new m,this.onDidRemove=this._onDidRemove.event,this._onDidAdd=new m,this.onDidAdd=this._onDidAdd.event,this._onDidMaximizedChange=new m,this.onDidMaximizedChange=this._onDidMaximizedChange.event,this._onDidActiveChange=new m,this.onDidActiveChange=this._onDidActiveChange.event,this._bufferOnDidLayoutChange=new g,this.onDidLayoutChange=this._bufferOnDidLayoutChange.onEvent,this._onDidViewVisibilityChangeMicroTaskQueue=new g,this.onDidViewVisibilityChangeMicroTaskQueue=this._onDidViewVisibilityChangeMicroTaskQueue.onEvent,this.element.style.height="100%",this.element.style.width="100%",this._classNames=new I(this.element),this._classNames.setClassNames(null!==(s=i.className)&&void 0!==s?s:""),t.appendChild(this.element),this.gridview=new ae(!!i.proportionalLayout,i.styles,i.orientation,i.locked,i.margin),this.gridview.locked=!!i.locked,this.element.appendChild(this.gridview.element),this.layout(0,0,!0),this.addDisposables(this.gridview.onDidMaximizedNodeChange(e=>{this._onDidMaximizedChange.fire({panel:e.view,isMaximized:e.isMaximized})}),this.gridview.onDidViewVisibilityChange(()=>this._onDidViewVisibilityChangeMicroTaskQueue.fire()),this.onDidViewVisibilityChangeMicroTaskQueue(()=>{this.forceRelayout()}),e.DockviewDisposable.from(()=>{var e;null===(e=this.element.parentElement)||void 0===e||e.removeChild(this.element)}),this.gridview.onDidChange(()=>{this._bufferOnDidLayoutChange.fire()}),e.DockviewEvent.any(this.onDidAdd,this.onDidRemove,this.onDidActiveChange)(()=>{this._bufferOnDidLayoutChange.fire()}),this._onDidMaximizedChange,this._onDidViewVisibilityChangeMicroTaskQueue,this._bufferOnDidLayoutChange)}setVisible(e,t){this.gridview.setViewVisible(ee(e.element),t),this._bufferOnDidLayoutChange.fire()}isVisible(e){return this.gridview.isViewVisible(ee(e.element))}updateOptions(e){var t,i,s,o;e.proportionalLayout,e.orientation&&(this.gridview.orientation=e.orientation),"disableResizing"in e&&(this.disableResizing=null!==(t=e.disableAutoResizing)&&void 0!==t&&t),"locked"in e&&(this.locked=null!==(i=e.locked)&&void 0!==i&&i),"margin"in e&&(this.gridview.margin=null!==(s=e.margin)&&void 0!==s?s:0),"className"in e&&this._classNames.setClassNames(null!==(o=e.className)&&void 0!==o?o:"")}maximizeGroup(e){this.gridview.maximizeView(e),this.doSetGroupActive(e)}isMaximizedGroup(e){return this.gridview.maximizedView()===e}exitMaximizedGroup(){this.gridview.exitMaximizedView()}hasMaximizedGroup(){return this.gridview.hasMaximizedView()}doAddGroup(t,i=[0],s){this.gridview.addView(t,null!=s?s:e.Sizing.Distribute,i),this._onDidAdd.fire(t)}doRemoveGroup(t,i){if(!this._groups.has(t.id))throw new Error("invalid operation");const s=this._groups.get(t.id),o=this.gridview.remove(t,e.Sizing.Distribute);if(s&&!(null==i?void 0:i.skipDispose)&&(s.disposable.dispose(),s.value.dispose(),this._groups.delete(t.id),this._onDidRemove.fire(t)),!(null==i?void 0:i.skipActive)&&this._activeGroup===t){const e=Array.from(this._groups.values());this.doSetGroupActive(e.length>0?e[0].value:void 0)}return o}getPanel(e){var t;return null===(t=this._groups.get(e))||void 0===t?void 0:t.value}doSetGroupActive(e){this._activeGroup!==e&&(this._activeGroup&&this._activeGroup.setActive(!1),e&&e.setActive(!0),this._activeGroup=e,this._onDidActiveChange.fire(e))}removeGroup(e){this.doRemoveGroup(e)}moveToNext(e){var t;if(e||(e={}),!e.group){if(!this.activeGroup)return;e.group=this.activeGroup}const i=ee(e.group.element),s=null===(t=this.gridview.next(i))||void 0===t?void 0:t.view;this.doSetGroupActive(s)}moveToPrevious(e){var t;if(e||(e={}),!e.group){if(!this.activeGroup)return;e.group=this.activeGroup}const i=ee(e.group.element),s=null===(t=this.gridview.previous(i))||void 0===t?void 0:t.view;this.doSetGroupActive(s)}forceRelayout(){this.layout(this.width,this.height,!0)}layout(e,t,i){(i||e!==this.width||t!==this.height)&&(this.gridview.element.style.height=`${t}px`,this.gridview.element.style.width=`${e}px`,this.gridview.layout(e,t))}dispose(){this._onDidActiveChange.dispose(),this._onDidAdd.dispose(),this._onDidRemove.dispose();for(const e of this.groups)e.dispose();this.gridview.dispose(),super.dispose()}}class ue{get minimumSize(){return this.component.minimumSize}get maximumSize(){return this.component.maximumSize}get width(){return this.component.width}get height(){return this.component.height}get length(){return this.component.length}get orientation(){return this.component.orientation}get panels(){return this.component.panels}get onDidLayoutFromJSON(){return this.component.onDidLayoutFromJSON}get onDidLayoutChange(){return this.component.onDidLayoutChange}get onDidAddView(){return this.component.onDidAddView}get onDidRemoveView(){return this.component.onDidRemoveView}constructor(e){this.component=e}removePanel(e,t){this.component.removePanel(e,t)}focus(){this.component.focus()}getPanel(e){return this.component.getPanel(e)}layout(e,t){return this.component.layout(e,t)}addPanel(e){return this.component.addPanel(e)}movePanel(e,t){this.component.movePanel(e,t)}fromJSON(e){this.component.fromJSON(e)}toJSON(){return this.component.toJSON()}clear(){this.component.clear()}updateOptions(e){this.component.updateOptions(e)}dispose(){this.component.dispose()}}class me{get minimumSize(){return this.component.minimumSize}get maximumSize(){return this.component.maximumSize}get width(){return this.component.width}g