UNPKG

dockview-core

Version:

Zero dependency layout manager supporting tabs, grids and splitviews

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