react-bwin 0.3.5 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`),require(`react-dom`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`react-dom`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ReactBinaryWindow={},e.React,e.ReactDOM))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var s=o(t),l=0,u=s.length,d;l<u;l++)d=s[l],!c.call(e,d)&&d!==n&&i(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=a(t,d))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:r(s(e)),l(t||!e||!e.__esModule?i(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);function u(e=.7,t=128){let n=256-t;return`rgba(${Math.floor(Math.random()*n+t)}, ${Math.floor(Math.random()*n+t)}, ${Math.floor(Math.random()*n+t)}, ${Math.max(.5,Math.random()*e)})`}function d(e=2,t=3){if(e<0||t<0)throw Error(`Parameters must be non-negative numbers`);let n=``;for(let t=0;t<e;t++){let e=Math.floor(Math.random()*26);n+=`ABCDEFGHIJKLMNOPQRSTUVWXYZ`[e]}n+=`-`;for(let e=0;e<t;e++){let e=Math.floor(Math.random()*10);n+=`0123456789`[e]}return n}function f(e,t){for(;t.firstChild;)e.append(t.firstChild)}function p(e,t){let n=document.createElement(`div`);f(n,e),f(e,t),f(t,n)}function m(e){if(typeof e==`number`&&!isNaN(e))return e;if(typeof e==`string`){let t=e.trim();if(t.endsWith(`%`)){let e=t.slice(0,-1);if(!e)return NaN;let n=Number(e);return isNaN(n)?NaN:n/100}if(t.endsWith(`px`)){let e=t.slice(0,-2);if(!e)return NaN;let n=Number(e);return isNaN(n)?NaN:n}return Number(t)}return NaN}function h(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getPrototypeOf(e)===Object.prototype}function g(e,t){for(let n in t){if(Object.hasOwn(e,n))throw Error(`Key "${n}" already exists in target object`);e[n]=t[n]}return e}function _(e){let t=document.createElement(`template`);return t.innerHTML=e.trim(),t.content}function v(e){if(e==null||e===``)return null;if(typeof e==`string`)try{let t=_(e);return t.childNodes.length===1?t.firstChild:t}catch{return document.createTextNode(e)}return e instanceof Node?e:document.createTextNode(String(e))}function y(e){return{left:parseFloat(e.style.left)||0,top:parseFloat(e.style.top)||0,width:parseFloat(e.style.width)||0,height:parseFloat(e.style.height)||0}}var b={Top:`top`,Right:`right`,Bottom:`bottom`,Left:`left`,Center:`center`,Root:`root`,Unknown:`unknown`,Outside:`outside`};function ee(e){switch(e){case b.Top:return b.Bottom;case b.Right:return b.Left;case b.Bottom:return b.Top;case b.Left:return b.Right;default:throw Error(`[bwin] Invalid position: ${e}`)}}function te({width:e,height:t,x:n}){return t/e*n}function ne({width:e,height:t,y:n}){return e/t*n}function x({width:e,height:t,x:n}){return t-t/e*n}function S({width:e,height:t,y:n}){return e-e/t*n}function C(e,{clientX:t,clientY:n}){let r=e.getBoundingClientRect(),{width:i,height:a}=r,o=t-r.left,s=n-r.top;if(o<0||o>i||s<0||s>a)return b.Outside;let c=.3,l=te({width:i,height:a,x:o}),u=x({width:i,height:a,x:o}),d=ne({width:i,height:a,y:s}),f=S({width:i,height:a,y:s});return o<i*(.5-c/2)&&s>l&&s<u?b.Left:o>i*.65&&s<l&&s>u?b.Right:s<a*(.5-c/2)&&o>d&&o<f?b.Top:s>a*.65&&o<d&&o>f?b.Bottom:o>i*(.5-c/2)&&o<i*.65&&s>a*(.5-c/2)&&s<a*.65?b.Center:b.Unknown}var w={left:0,top:0,width:150,height:150,minWidth:100,minHeight:100,resizeStrategy:`classic`},T=class{constructor({left:e=w.left,top:t=w.top,width:n=w.width,height:r=w.height,minWidth:i=w.minWidth,minHeight:a=w.minHeight,resizeStrategy:o=w.resizeStrategy,parent:s=null,domNode:c=null,store:l={},position:u,id:f}=w){if(this.id=f??d(),!u)throw Error(`[bwin] Sash position is required`);this.position=u,this.domNode=c,this.parent=s,this._top=t,this._left=e,this._width=n,this._height=r,this.children=[],this.minWidth=i,this.minHeight=a,this.resizeStrategy=o,this.store=l}walk(e){this.children.forEach(t=>t.walk(e)),e(this)}isLeaf(){return this.children.length===0}isSplit(){return this.children.length>0}isLeftRightSplit(){return this.children.some(e=>e.position===b.Left||e.position===b.Right)}isTopBottomSplit(){return this.children.some(e=>e.position===b.Top||e.position===b.Bottom)}get leftChild(){return this.children.find(e=>e.position===b.Left)}get rightChild(){return this.children.find(e=>e.position===b.Right)}get topChild(){return this.children.find(e=>e.position===b.Top)}get bottomChild(){return this.children.find(e=>e.position===b.Bottom)}getChildren(){let e=null,t=null,n=null,r=null;for(let i of this.children)i.position===b.Left?e=i:i.position===b.Right?t=i:i.position===b.Top?n=i:i.position===b.Bottom&&(r=i);return[n,t,r,e]}getAllLeafDescendants(){let e=[];return this.walk(t=>{t.children.length===0&&e.push(t)}),e}calcMinWidth(){if(this.isLeaf())return this.minWidth;let[e,t,n,r]=this.getChildren();if(r&&t){let e=r.calcMinWidth()+t.calcMinWidth();return Math.max(this.minWidth,e)}if(e&&n){let t=Math.max(e.calcMinWidth(),n.calcMinWidth());return Math.max(this.minWidth,t)}}calcMinHeight(){if(this.isLeaf())return this.minHeight;let[e,t,n,r]=this.getChildren();if(r&&t){let e=Math.max(r.calcMinHeight(),t.calcMinHeight());return Math.max(this.minHeight,e)}if(e&&n){let t=e.calcMinHeight()+n.calcMinHeight();return Math.max(this.minHeight,t)}}getById(e){if(this.id===e)return this;for(let t of this.children){let n=t.getById(e);if(n)return n}return null}swapIds(e,t){let n=this.getById(e),r=this.getById(t);if(!n||!r)throw Error(`[bwin] Sash not found when swapping IDs`);let i=n.id;n.id=r.id,r.id=i}getAllIds(){let e=[this.id];for(let t of this.children)e.push(...t.getAllIds());return e}addChild(e){if(this.children.length>=2)throw Error(`[bwin] Maximum 2 children allowed`);this.children.push(e)}getDescendantParentById(e){for(let t of this.children){if(t.id===e)return this;let n=t.getDescendantParentById(e);if(n)return n}return null}getChildSiblingById(e){return this.children.find(t=>t.id!==e)}get top(){return this._top}set top(e){let t=e-this._top;this._top=e;let[n,r,i,a]=this.getChildren();n&&i&&(n.top+=t,i.top+=t),a&&r&&(a.top+=t,r.top+=t)}get left(){return this._left}set left(e){let t=e-this._left;this._left=e;let[n,r,i,a]=this.getChildren();a&&r&&(a.left+=t,r.left+=t),n&&i&&(n.left+=t,i.left+=t)}get width(){return this._width}set width(e){let t=e-this._width;this._width=e;let[n,r,i,a]=this.getChildren();if(a&&r){let e=a.width+r.width,n=t*(a.width/e),i=e+t,o,s,c;if(this.resizeStrategy===`natural`&&this.position===b.Left?(o=a.width,s=r.width+t,c=r.left):this.resizeStrategy===`natural`&&this.position===b.Right?(o=a.width+t,s=r.width,c=a.left+o):(o=a.width+n,s=i-o,c=r.left+n),t<0){let e=a.calcMinWidth(),t=r.calcMinWidth();o<e&&s>t?(o=a.width,s=i-o,c=a.left+o):s<t&&o>e&&(s=r.width,o=i-s,c=a.left+o)}a.width=o,r.width=s,r.left=c}n&&i&&(n.width+=t,i.width+=t)}get height(){return this._height}set height(e){let t=e-this._height;this._height=e;let[n,r,i,a]=this.getChildren();if(n&&i){let e=n.height+i.height,r=t*(n.height/e),a=e+t,o,s,c;if(this.resizeStrategy===`natural`&&this.position===b.Top?(o=n.height,s=i.height+t,c=i.top):this.resizeStrategy===`natural`&&this.position===b.Bottom?(o=n.height+t,s=i.height,c=n.top+o):(o=n.height+r,s=a-o,c=i.top+r),t<0){let e=n.calcMinHeight(),t=i.calcMinHeight();o<e&&s>t?(o=n.height,s=a-o,c=n.top+o):s<t&&o>e&&(s=i.height,o=a-s,c=n.top+o)}n.height=o,i.height=s,i.top=c}a&&r&&(a.height+=t,r.height+=t)}},E={size:`50%`,position:b.Left},re=class e{left;top;width;height;constructor({parentRect:e,children:t,siblingConfigNode:n,id:r,minWidth:i,minHeight:a,position:o,size:s,resizeStrategy:c,...l}){this.parentRect=e,this.children=t,this.siblingConfigNode=n,this.id=r,this.minWidth=i,this.minHeight=a,this.position=this.getPosition(o),this.size=this.getSize(s),this.resizeStrategy=c,this.nonCoreData=l,this.setBounds()}getPosition(e){if(!this.siblingConfigNode)return e;let t=ee(this.siblingConfigNode.position);if(!e)return t;if(e!==t)throw Error(`[bwin] Sibling position and current position are not opposite`);return e}getSize(e){if(!this.siblingConfigNode)return m(e);if(!e){if(this.siblingConfigNode.size<1)return 1-this.siblingConfigNode.size;if(this.siblingConfigNode.position===b.Left||this.siblingConfigNode.position===b.Right)return this.parentRect.width-this.siblingConfigNode.width;if(this.siblingConfigNode.position===b.Top||this.siblingConfigNode.position===b.Bottom)return this.parentRect.height-this.siblingConfigNode.height}let t=m(e);if(t<1){if(t+this.siblingConfigNode.size!==1)throw Error(`[bwin] Sum of sibling sizes is not equal to 1`)}else{if((this.position===b.Left||this.position===b.Right)&&t+this.siblingConfigNode.size!==this.parentRect.width)throw Error(`[bwin] Sum of sibling sizes is not equal to parent width`);if((this.position===b.Top||this.position===b.Bottom)&&t+this.siblingConfigNode.size!==this.parentRect.height)throw Error(`[bwin] Sum of sibling sizes is not equal to parent height`)}return t}setBounds(){if(this.position===b.Root)this.left=0,this.top=0,this.width=this.parentRect.width,this.height=this.parentRect.height;else if(this.position===b.Left){let e=this.size<1?this.parentRect.width*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top,this.width=e,this.height=this.parentRect.height}else if(this.position===b.Right){let e=this.size<1?this.parentRect.width*this.size:this.size;this.left=this.parentRect.left+this.parentRect.width-e,this.top=this.parentRect.top,this.width=e,this.height=this.parentRect.height}else if(this.position===b.Top){let e=this.size<1?this.parentRect.height*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top,this.width=this.parentRect.width,this.height=e}else if(this.position===b.Bottom){let e=this.size<1?this.parentRect.height*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top+this.parentRect.height-e,this.width=this.parentRect.width,this.height=e}}createSash({resizeStrategy:e}={}){return new T({left:this.left,top:this.top,width:this.width,height:this.height,position:this.position,id:this.id,minWidth:this.minWidth,minHeight:this.minHeight,resizeStrategy:e||this.resizeStrategy,store:this.nonCoreData})}normConfig(e){if(h(e))return e;if(Array.isArray(e))return{children:e};if(typeof e==`string`||typeof e==`number`){let t=m(e);if(isNaN(t))throw Error(`[bwin] Invalid size value: ${t}`);return{size:e}}else if(e==null)return{};else throw Error(`[bwin] Invalid config value: ${e}`)}createPrimaryConfigNode({size:t,position:n,children:r,id:i,minWidth:a,minHeight:o,...s}){return new e({parentRect:this,size:t??E.size,position:n??E.position,children:r,id:i,minWidth:a,minHeight:o,...s})}createSecondaryConfigNode({size:t,position:n,children:r,id:i,minWidth:a,minHeight:o,...s},c){return new e({parentRect:this,size:t,position:n,children:r,siblingConfigNode:c,id:i,minWidth:a,minHeight:o,...s})}buildSashTree({resizeStrategy:e}={}){let t=this.createSash({resizeStrategy:e});if(!Array.isArray(this.children)||this.children.length===0)return t;let n=this.normConfig(this.children[0]),r=this.normConfig(this.children.at(1)),i,a;if(!n.size&&!n.position&&r?(r.position||=b.Right,i=this.createPrimaryConfigNode(r),a=this.createSecondaryConfigNode(n,i)):(i=this.createPrimaryConfigNode(n),a=this.createSecondaryConfigNode(r,i)),i&&a){let n=i.buildSashTree({resizeStrategy:e}),r=a.buildSashTree({resizeStrategy:e});n.parent=t,r.parent=t,t.children.push(n),t.children.push(r)}return t}},D={width:333,height:333},O={fitContainer:!1,theme:``},ie=class extends re{constructor({id:e,children:t,width:n=D.width,height:r=D.height,fitContainer:i=O.fitContainer,theme:a=O.theme,...o}={...D,...O}){super({id:e,children:t,size:NaN,position:b.Root,parentRect:{width:n,height:r},...o}),this.fitContainer=i,this.theme=a}},k=class extends T{constructor(e=w){super({...e,position:b.Root}),Object.assign(this,O)}};function A(e){let t=document.createElement(`bw-pane`);return t.style.top=`${e.top}px`,t.style.left=`${e.left}px`,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.setAttribute(`sash-id`,e.id),t.setAttribute(`position`,e.position),t}function j(e){let t=e.domNode;return t.style.top=`${e.top}px`,t.style.left=`${e.left}px`,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.setAttribute(`position`,e.position),t}function M(e,{size:t,id:n}){let r=m(t),i=e.width/2;r&&(i=r<1?e.width*r:r);let a=new T({id:n,top:e.top,left:e.left,width:i,height:e.height,position:b.Left}),o=new T({id:e.id,top:e.top,left:e.left+a.width,width:e.width-i,height:e.height,position:b.Right,domNode:e.domNode});return e.addChild(a),e.addChild(o),e.domNode=null,e.id=d(),a}function N(e,{size:t,id:n}){let r=m(t),i=e.width/2;r&&(i=r<1?e.width*r:r);let a=new T({id:e.id,left:e.left,top:e.top,width:e.width-i,height:e.height,position:b.Left,domNode:e.domNode}),o=new T({id:n,left:e.left+a.width,top:e.top,width:i,height:e.height,position:b.Right});return e.addChild(a),e.addChild(o),e.domNode=null,e.id=d(),o}function P(e,{size:t,id:n}){let r=m(t),i=e.height/2;r&&(i=r<1?e.height*r:r);let a=new T({id:n,left:e.left,top:e.top,width:e.width,height:i,position:b.Top}),o=new T({id:e.id,left:e.left,top:e.top+a.height,width:e.width,height:e.height-i,position:b.Bottom,domNode:e.domNode});return e.addChild(a),e.addChild(o),e.domNode=null,e.id=d(),a}function F(e,{size:t,id:n}){let r=m(t),i=e.height/2;r&&(i=r<1?e.height*r:r);let a=new T({id:e.id,top:e.top,left:e.left,width:e.width,height:e.height-i,position:b.Top,domNode:e.domNode}),o=new T({id:n,top:e.top+a.height,left:e.left,width:e.width,height:i,position:b.Bottom});return e.addChild(a),e.addChild(o),e.domNode=null,e.id=d(),o}function I(e,{position:t,size:n,id:r,minWidth:i,minHeight:a}){if(t===b.Left)return M(e,{size:n,id:r});if(t===b.Right)return N(e,{size:n,id:r});if(t===b.Top)return P(e,{size:n,id:r});if(t===b.Bottom)return F(e,{size:n,id:r})}function L(e){if(e.tagName===`BW-PANE`)return e.getAttribute(`sash-id`);let t=e.closest(`bw-pane`);if(!t)throw Error(`[bwin] Pane element not found`);return t.getAttribute(`sash-id`)}var R={createPane(e){let t=A(e);return e.store.droppable===!1&&t.setAttribute(`can-drop`,`false`),t},onPaneCreate(e,t){t.store.content&&e.append(v(t.store.content)),this?.debug&&(e.style.backgroundColor=u(),e.innerHTML=``,e.append(z(e)))},updatePane(e){return j(e)},onPaneUpdate(e,t){this?.debug&&(e.innerHTML=``,e.append(z(e)))},addPane(e,{position:t,size:n,id:r}){if(!t)throw Error(`[bwin] Position is required when adding pane`);let i=this.rootSash.getById(e);if(!i)throw Error(`[bwin] Parent sash not found when adding pane`);let a=I(i,{position:t,size:n,id:r});return this.update(),a},removePane(e){let t=this.rootSash.getDescendantParentById(e);if(!t)throw Error(`[bwin] Parent sash not found when removing pane`);let n=t.getChildSiblingById(e);n.children.length===0?(t.id=n.id,t.domNode=n.domNode,t.domNode.setAttribute(`sash-id`,n.id),t.children=[]):(t.id=d(),t.children=n.children,n.position===b.Left?n.width=t.width:n.position===b.Right?(n.width=t.width,n.left=t.left):n.position===b.Top?n.height=t.height:n.position===b.Bottom&&(n.height=t.height,n.top=t.top)),this.update()},swapPanes(e,t){let n=L(e),r=L(t),i=e.getAttribute(`can-drop`)!==`false`,a=t.getAttribute(`can-drop`)!==`false`;this.rootSash.swapIds(n,r),p(e,this.activeDropPaneEl),e.setAttribute(`sash-id`,r),t.setAttribute(`sash-id`,n),e.setAttribute(`can-drop`,a),t.setAttribute(`can-drop`,i)}};function z(e){let t=document.createElement(`pre`);return t.style.fontSize=`10px`,t.innerHTML=`
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react"),require("react-dom")):typeof define==`function`&&define.amd?define([`exports`,`react`,`react-dom`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ReactBinaryWindow={},e.React,e.ReactDOM))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var s=o(t),l=0,u=s.length,d;l<u;l++)d=s[l],!c.call(e,d)&&d!==n&&i(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=a(t,d))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:r(s(e)),l(t||!e||!e.__esModule?i(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);function u(e=.7,t=128){let n=256-t;return`rgba(${Math.floor(Math.random()*n+t)}, ${Math.floor(Math.random()*n+t)}, ${Math.floor(Math.random()*n+t)}, ${Math.max(.5,Math.random()*e)})`}function d(e=2,t=3){if(e<0||t<0)throw Error(`Parameters must be non-negative numbers`);let n=``;for(let t=0;t<e;t++){let e=Math.floor(Math.random()*26);n+=`ABCDEFGHIJKLMNOPQRSTUVWXYZ`[e]}n+=`-`;for(let e=0;e<t;e++){let e=Math.floor(Math.random()*10);n+=`0123456789`[e]}return n}function f(e,t){for(;t.firstChild;)e.append(t.firstChild)}function p(e,t){let n=document.createElement(`div`);f(n,e),f(e,t),f(t,n)}function m(e){if(typeof e==`number`&&!isNaN(e))return e;if(typeof e==`string`){let t=e.trim();if(t.endsWith(`%`)){let e=t.slice(0,-1);if(!e)return NaN;let n=Number(e);return isNaN(n)?NaN:n/100}if(t.endsWith(`px`)){let e=t.slice(0,-2);if(!e)return NaN;let n=Number(e);return isNaN(n)?NaN:n}return Number(t)}return NaN}function h(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getPrototypeOf(e)===Object.prototype}function ee(e,t){for(let n in t){if(Object.hasOwn(e,n))throw Error(`Key "${n}" already exists in target object`);e[n]=t[n]}return e}function te(e){let t=document.createElement(`template`);return t.innerHTML=e.trim(),t.content}function g(e){if(e==null||e===``)return null;if(typeof e==`string`)try{let t=te(e);return t.childNodes.length===1?t.firstChild:t}catch{return document.createTextNode(e)}return e instanceof Node?e:document.createTextNode(String(e))}function ne(e){let t=document.createDocumentFragment();return t.append(...e.childNodes),t}function _(e){return{left:parseFloat(e.style.left)||0,top:parseFloat(e.style.top)||0,width:parseFloat(e.style.width)||0,height:parseFloat(e.style.height)||0}}var v={Top:`top`,Right:`right`,Bottom:`bottom`,Left:`left`,Center:`center`,Root:`root`,Unknown:`unknown`,Outside:`outside`};function re(e){switch(e){case v.Top:return v.Bottom;case v.Right:return v.Left;case v.Bottom:return v.Top;case v.Left:return v.Right;default:throw Error(`[bwin] Invalid position: ${e}`)}}function y({width:e,height:t,x:n}){return t/e*n}function ie({width:e,height:t,y:n}){return e/t*n}function ae({width:e,height:t,x:n}){return t-t/e*n}function oe({width:e,height:t,y:n}){return e-e/t*n}function se(e,{clientX:t,clientY:n}){let r=e.getBoundingClientRect(),{width:i,height:a}=r,o=t-r.left,s=n-r.top;if(o<0||o>i||s<0||s>a)return v.Outside;let c=.3,l=y({width:i,height:a,x:o}),u=ae({width:i,height:a,x:o}),d=ie({width:i,height:a,y:s}),f=oe({width:i,height:a,y:s});return o<i*(.5-c/2)&&s>l&&s<u?v.Left:o>i*.65&&s<l&&s>u?v.Right:s<a*(.5-c/2)&&o>d&&o<f?v.Top:s>a*.65&&o<d&&o>f?v.Bottom:o>i*(.5-c/2)&&o<i*.65&&s>a*(.5-c/2)&&s<a*.65?v.Center:v.Unknown}var b={left:0,top:0,width:150,height:150,minWidth:100,minHeight:100,resizeStrategy:`classic`},x=class{constructor({left:e=b.left,top:t=b.top,width:n=b.width,height:r=b.height,minWidth:i=b.minWidth,minHeight:a=b.minHeight,resizeStrategy:o=b.resizeStrategy,parent:s=null,domNode:c=null,store:l={},position:u,id:f}=b){if(this.id=f??d(),!u)throw Error(`[bwin] Sash position is required`);this.position=u,this.domNode=c,this.parent=s,this._top=t,this._left=e,this._width=n,this._height=r,this.children=[],this.minWidth=i,this.minHeight=a,this.resizeStrategy=o,this.store=l}walk(e){this.children.forEach(t=>t.walk(e)),e(this)}isLeaf(){return this.children.length===0}isSplit(){return this.children.length>0}isLeftRightSplit(){return this.children.some(e=>e.position===v.Left||e.position===v.Right)}isTopBottomSplit(){return this.children.some(e=>e.position===v.Top||e.position===v.Bottom)}get leftChild(){return this.children.find(e=>e.position===v.Left)}get rightChild(){return this.children.find(e=>e.position===v.Right)}get topChild(){return this.children.find(e=>e.position===v.Top)}get bottomChild(){return this.children.find(e=>e.position===v.Bottom)}getChildren(){let e=null,t=null,n=null,r=null;for(let i of this.children)i.position===v.Left?e=i:i.position===v.Right?t=i:i.position===v.Top?n=i:i.position===v.Bottom&&(r=i);return[n,t,r,e]}getAllLeafDescendants(){let e=[];return this.walk(t=>{t.children.length===0&&e.push(t)}),e}calcMinWidth(){if(this.isLeaf())return this.minWidth;let[e,t,n,r]=this.getChildren();if(r&&t){let e=r.calcMinWidth()+t.calcMinWidth();return Math.max(this.minWidth,e)}if(e&&n){let t=Math.max(e.calcMinWidth(),n.calcMinWidth());return Math.max(this.minWidth,t)}}calcMinHeight(){if(this.isLeaf())return this.minHeight;let[e,t,n,r]=this.getChildren();if(r&&t){let e=Math.max(r.calcMinHeight(),t.calcMinHeight());return Math.max(this.minHeight,e)}if(e&&n){let t=e.calcMinHeight()+n.calcMinHeight();return Math.max(this.minHeight,t)}}getById(e){if(this.id===e)return this;for(let t of this.children){let n=t.getById(e);if(n)return n}return null}swapIds(e,t){let n=this.getById(e),r=this.getById(t);if(!n||!r)throw Error(`[bwin] Sash not found when swapping IDs`);let i=n.id;n.id=r.id,r.id=i}getAllIds(){let e=[this.id];for(let t of this.children)e.push(...t.getAllIds());return e}addChild(e){if(this.children.length>=2)throw Error(`[bwin] Maximum 2 children allowed`);e.parent=this,this.children.push(e)}getDescendantParentById(e){for(let t of this.children){if(t.id===e)return this;let n=t.getDescendantParentById(e);if(n)return n}return null}getChildSiblingById(e){return this.children.find(t=>t.id!==e)}getLargestLeaf(){return this.getAllLeafDescendants().reduce((e,t)=>t.width*t.height>e.width*e.height?t:e)}getRelativeSize(){return this.parent?this.position===v.Left||this.position===v.Right?this.width/this.parent.width:this.height/this.parent.height:1}get top(){return this._top}set top(e){let t=e-this._top;this._top=e;let[n,r,i,a]=this.getChildren();n&&i&&(n.top+=t,i.top+=t),a&&r&&(a.top+=t,r.top+=t)}get left(){return this._left}set left(e){let t=e-this._left;this._left=e;let[n,r,i,a]=this.getChildren();a&&r&&(a.left+=t,r.left+=t),n&&i&&(n.left+=t,i.left+=t)}get width(){return this._width}set width(e){let t=e-this._width;this._width=e;let[n,r,i,a]=this.getChildren();if(a&&r){let e=a.width+r.width,n=t*(a.width/e),i=e+t,o,s,c;if(this.resizeStrategy===`natural`&&this.position===v.Left?(o=a.width,s=r.width+t,c=r.left):this.resizeStrategy===`natural`&&this.position===v.Right?(o=a.width+t,s=r.width,c=a.left+o):(o=a.width+n,s=i-o,c=r.left+n),t<0){let e=a.calcMinWidth(),t=r.calcMinWidth();o<e&&s>t?(o=a.width,s=i-o,c=a.left+o):s<t&&o>e&&(s=r.width,o=i-s,c=a.left+o)}a.width=o,r.width=s,r.left=c}n&&i&&(n.width+=t,i.width+=t)}get height(){return this._height}set height(e){let t=e-this._height;this._height=e;let[n,r,i,a]=this.getChildren();if(n&&i){let e=n.height+i.height,r=t*(n.height/e),a=e+t,o,s,c;if(this.resizeStrategy===`natural`&&this.position===v.Top?(o=n.height,s=i.height+t,c=i.top):this.resizeStrategy===`natural`&&this.position===v.Bottom?(o=n.height+t,s=i.height,c=n.top+o):(o=n.height+r,s=a-o,c=i.top+r),t<0){let e=n.calcMinHeight(),t=i.calcMinHeight();o<e&&s>t?(o=n.height,s=a-o,c=n.top+o):s<t&&o>e&&(s=i.height,o=a-s,c=n.top+o)}n.height=o,i.height=s,i.top=c}a&&r&&(a.height+=t,r.height+=t)}},S={size:`50%`,position:v.Left},ce=class e{left;top;width;height;constructor({parentRect:e,children:t,siblingConfigNode:n,id:r,minWidth:i,minHeight:a,position:o,size:s,resizeStrategy:c,...l}){this.parentRect=e,this.children=t,this.siblingConfigNode=n,this.id=r,this.minWidth=i,this.minHeight=a,this.position=this.getPosition(o),this.size=this.getSize(s),this.resizeStrategy=c,this.nonCoreData=l,this.setBounds()}getPosition(e){if(!this.siblingConfigNode)return e;let t=re(this.siblingConfigNode.position);if(!e)return t;if(e!==t)throw Error(`[bwin] Sibling position and current position are not opposite`);return e}getSize(e){if(!this.siblingConfigNode)return m(e);if(!e){if(this.siblingConfigNode.size<1)return 1-this.siblingConfigNode.size;if(this.siblingConfigNode.position===v.Left||this.siblingConfigNode.position===v.Right)return this.parentRect.width-this.siblingConfigNode.width;if(this.siblingConfigNode.position===v.Top||this.siblingConfigNode.position===v.Bottom)return this.parentRect.height-this.siblingConfigNode.height}let t=m(e);if(t<1){if(t+this.siblingConfigNode.size!==1)throw Error(`[bwin] Sum of sibling sizes is not equal to 1`)}else{if((this.position===v.Left||this.position===v.Right)&&t+this.siblingConfigNode.size!==this.parentRect.width)throw Error(`[bwin] Sum of sibling sizes is not equal to parent width`);if((this.position===v.Top||this.position===v.Bottom)&&t+this.siblingConfigNode.size!==this.parentRect.height)throw Error(`[bwin] Sum of sibling sizes is not equal to parent height`)}return t}setBounds(){if(this.position===v.Root)this.left=0,this.top=0,this.width=this.parentRect.width,this.height=this.parentRect.height;else if(this.position===v.Left){let e=this.size<1?this.parentRect.width*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top,this.width=e,this.height=this.parentRect.height}else if(this.position===v.Right){let e=this.size<1?this.parentRect.width*this.size:this.size;this.left=this.parentRect.left+this.parentRect.width-e,this.top=this.parentRect.top,this.width=e,this.height=this.parentRect.height}else if(this.position===v.Top){let e=this.size<1?this.parentRect.height*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top,this.width=this.parentRect.width,this.height=e}else if(this.position===v.Bottom){let e=this.size<1?this.parentRect.height*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top+this.parentRect.height-e,this.width=this.parentRect.width,this.height=e}}createSash({resizeStrategy:e}={}){return new x({left:this.left,top:this.top,width:this.width,height:this.height,position:this.position,id:this.id,minWidth:this.minWidth,minHeight:this.minHeight,resizeStrategy:e||this.resizeStrategy,store:this.nonCoreData})}normConfig(e){if(h(e))return e;if(Array.isArray(e))return{children:e};if(typeof e==`string`||typeof e==`number`){let t=m(e);if(isNaN(t))throw Error(`[bwin] Invalid size value: ${t}`);return{size:e}}else if(e==null)return{};else throw Error(`[bwin] Invalid config value: ${e}`)}createPrimaryConfigNode({size:t,position:n,children:r,id:i,minWidth:a,minHeight:o,...s}){return new e({parentRect:this,size:t??S.size,position:n??S.position,children:r,id:i,minWidth:a,minHeight:o,...s})}createSecondaryConfigNode({size:t,position:n,children:r,id:i,minWidth:a,minHeight:o,...s},c){return new e({parentRect:this,size:t,position:n,children:r,siblingConfigNode:c,id:i,minWidth:a,minHeight:o,...s})}buildSashTree({resizeStrategy:e}={}){let t=this.createSash({resizeStrategy:e});if(!Array.isArray(this.children)||this.children.length===0)return t;let n=this.normConfig(this.children[0]),r=this.normConfig(this.children.at(1)),i,a;if(!n.size&&!n.position&&r?(r.position||=v.Right,i=this.createPrimaryConfigNode(r),a=this.createSecondaryConfigNode(n,i)):(i=this.createPrimaryConfigNode(n),a=this.createSecondaryConfigNode(r,i)),i&&a){let n=i.buildSashTree({resizeStrategy:e}),r=a.buildSashTree({resizeStrategy:e});n.parent=t,r.parent=t,t.children.push(n),t.children.push(r)}return t}},C={width:333,height:333},w={fitContainer:!1,theme:``},le=class extends ce{constructor({id:e,children:t,width:n=C.width,height:r=C.height,fitContainer:i=w.fitContainer,theme:a=w.theme,...o}={...C,...w}){super({id:e,children:t,size:NaN,position:v.Root,parentRect:{width:n,height:r},...o}),this.fitContainer=i,this.theme=a}},ue=class extends x{constructor(e=b){super({...e,position:v.Root}),Object.assign(this,w)}};function de(e){let t=document.createElement(`bw-pane`);return t.style.top=`${e.top}px`,t.style.left=`${e.left}px`,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.setAttribute(`sash-id`,e.id),t.setAttribute(`position`,e.position),t}function fe(e){let t=e.domNode;return t.style.top=`${e.top}px`,t.style.left=`${e.left}px`,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.setAttribute(`position`,e.position),t}function pe(e,{size:t,id:n}){let r=m(t),i=e.width/2;r&&(i=r<1?e.width*r:r);let a=new x({id:n,top:e.top,left:e.left,width:i,height:e.height,position:v.Left}),o=new x({id:e.id,top:e.top,left:e.left+a.width,width:e.width-i,height:e.height,position:v.Right,domNode:e.domNode});return e.addChild(a),e.addChild(o),e.domNode=null,e.id=d(),a}function me(e,{size:t,id:n}){let r=m(t),i=e.width/2;r&&(i=r<1?e.width*r:r);let a=new x({id:e.id,left:e.left,top:e.top,width:e.width-i,height:e.height,position:v.Left,domNode:e.domNode}),o=new x({id:n,left:e.left+a.width,top:e.top,width:i,height:e.height,position:v.Right});return e.addChild(a),e.addChild(o),e.domNode=null,e.id=d(),o}function he(e,{size:t,id:n}){let r=m(t),i=e.height/2;r&&(i=r<1?e.height*r:r);let a=new x({id:n,left:e.left,top:e.top,width:e.width,height:i,position:v.Top}),o=new x({id:e.id,left:e.left,top:e.top+a.height,width:e.width,height:e.height-i,position:v.Bottom,domNode:e.domNode});return e.addChild(a),e.addChild(o),e.domNode=null,e.id=d(),a}function ge(e,{size:t,id:n}){let r=m(t),i=e.height/2;r&&(i=r<1?e.height*r:r);let a=new x({id:e.id,top:e.top,left:e.left,width:e.width,height:e.height-i,position:v.Top,domNode:e.domNode}),o=new x({id:n,top:e.top+a.height,left:e.left,width:e.width,height:i,position:v.Bottom});return e.addChild(a),e.addChild(o),e.domNode=null,e.id=d(),o}function _e(e,{position:t,size:n,id:r,minWidth:i,minHeight:a}){if(t===v.Left)return pe(e,{size:n,id:r});if(t===v.Right)return me(e,{size:n,id:r});if(t===v.Top)return he(e,{size:n,id:r});if(t===v.Bottom)return ge(e,{size:n,id:r})}function T(e){if(e.tagName===`BW-PANE`)return e.getAttribute(`sash-id`);let t=e.closest(`bw-pane`);if(!t)throw Error(`[bwin] Pane element not found`);return t.getAttribute(`sash-id`)}var ve={createPane(e){let t=de(e);return e.store.droppable===!1&&t.setAttribute(`can-drop`,`false`),t},onPaneCreate(e,t){t.store.content&&e.append(g(t.store.content)),this?.debug&&(e.style.backgroundColor=u(),e.innerHTML=``,e.append(E(e)))},updatePane(e){return fe(e)},onPaneUpdate(e,t){this?.debug&&(e.innerHTML=``,e.append(E(e)))},addPane(e,{position:t,size:n,id:r}){if(!t)throw Error(`[bwin] Position is required when adding pane`);let i=this.rootSash.getById(e);if(!i)throw Error(`[bwin] Parent sash not found when adding pane`);let a=_e(i,{position:t,size:n,id:r});return this.update(),a},removePane(e){let t=this.rootSash.getDescendantParentById(e);if(!t)throw Error(`[bwin] Parent sash not found when removing pane`);let n=t.getChildSiblingById(e);n.children.length===0?(t.id=n.id,t.domNode=n.domNode,t.domNode.setAttribute(`sash-id`,n.id),t.children=[]):(t.id=d(),t.children=n.children,t.children.forEach(e=>e.parent=t),n.position===v.Left?n.width=t.width:n.position===v.Right?(n.width=t.width,n.left=t.left):n.position===v.Top?n.height=t.height:n.position===v.Bottom&&(n.height=t.height,n.top=t.top)),this.update()},swapPanes(e,t){let n=T(e),r=T(t),i=e.getAttribute(`can-drop`)!==`false`,a=t.getAttribute(`can-drop`)!==`false`;this.rootSash.swapIds(n,r),p(e,this.activeDropPaneEl),e.setAttribute(`sash-id`,r),t.setAttribute(`sash-id`,n),e.setAttribute(`can-drop`,a),t.setAttribute(`can-drop`,i)}};function E(e){let t=document.createElement(`pre`);return t.style.fontSize=`10px`,t.innerHTML=`
2
2
  ${e.getAttribute(`sash-id`)}
3
3
  ${e.getAttribute(`position`)}
4
4
  top: ${e.style.top}
5
5
  left: ${e.style.left}
6
6
  width: ${e.style.width}
7
7
  height: ${e.style.height}
8
- `.trim(),t}var B={createWindow({theme:e}={}){let t=document.createElement(`bw-window`);return t.style.width=`${this.rootSash.width}px`,t.style.height=`${this.rootSash.height}px`,t.setAttribute(`root-sash-id`,this.rootSash.id),e&&t.setAttribute(`theme`,e),t},glaze(){this.rootSash.walk(e=>{let t=null;e.children.length>0?(t=this.createMuntin(e),this.onMuntinCreate(t,e),this.windowElement.append(t)):(t=this.createPane(e),this.onPaneCreate(t,e),this.windowElement.prepend(t)),e.domNode=t})},update(){this.windowElement.style.width=`${this.rootSash.width}px`,this.windowElement.style.height=`${this.rootSash.height}px`;let e=this.rootSash.getAllIds(),t=[];this.windowElement.querySelectorAll(`[sash-id]`).forEach(n=>{let r=n.getAttribute(`sash-id`);t.push(r),e.includes(r)||n.remove()}),this.rootSash.walk(e=>{e.children.length>0?t.includes(e.id)?(this.updateMuntin(e),this.onMuntinUpdate(e.domNode,e)):(e.domNode=this.createMuntin(e),this.windowElement.append(e.domNode)):t.includes(e.id)?(this.updatePane(e),this.onPaneUpdate(e.domNode,e)):(e.domNode||=this.createPane(e),this.windowElement.prepend(e.domNode))})}},V={muntinSize:4,createMuntin(e){let t=document.createElement(`bw-muntin`),n=e.leftChild,r=e.topChild;return n?(t.style.width=`${this.muntinSize}px`,t.style.height=`${e.height}px`,t.style.top=`${e.top}px`,t.style.left=`${e.left+n.width-this.muntinSize/2}px`,t.setAttribute(`vertical`,``)):r&&(t.style.width=`${e.width}px`,t.style.height=`${this.muntinSize}px`,t.style.top=`${e.top+r.height-this.muntinSize/2}px`,t.style.left=`${e.left}px`,t.setAttribute(`horizontal`,``)),t.setAttribute(`sash-id`,e.id),e.store.resizable===!1&&t.setAttribute(`resizable`,`false`),t},onMuntinCreate(e,t){},updateMuntin(e){let t=e.domNode,n=e.leftChild,r=e.topChild;n?(t.style.height=`${e.height}px`,t.style.top=`${e.top}px`,t.style.left=`${e.left+n.width-this.muntinSize/2}px`):r&&(t.style.width=`${e.width}px`,t.style.top=`${e.top+r.height-this.muntinSize/2}px`,t.style.left=`${e.left}px`)},onMuntinUpdate(e,t){}},H={fitContainer:!1,fit(){this.rootSash.width=this.containerElement.clientWidth,this.rootSash.height=this.containerElement.clientHeight,this.update()},enableFitContainer(){new ResizeObserver(e=>{requestAnimationFrame(()=>{for(let t of e)t.target===this.containerElement&&this.fitContainer&&this.fit()})}).observe(this.containerElement)}},U={activeMuntinSash:null,isResizeStarted:!1,isDropStarted:!1,lastX:0,lastY:0,applyResizeStyles(){this.activeMuntinSash.domNode.hasAttribute(`vertical`)?document.body.classList.add(`body--bw-resize-x`):this.activeMuntinSash.domNode.hasAttribute(`horizontal`)&&document.body.classList.add(`body--bw-resize-y`)},revertResizeStyles(){document.body.classList.remove(`body--bw-resize-x`),document.body.classList.remove(`body--bw-resize-y`)},enableResize(){document.addEventListener(`mousedown`,e=>{if(e.target.tagName!==`BW-MUNTIN`||e.target.getAttribute(`resizable`)===`false`)return;let t=e.target.getAttribute(`sash-id`);this.activeMuntinSash=this.rootSash.getById(t),this.activeMuntinSash&&(this.isResizeStarted=!0,this.lastX=e.pageX,this.lastY=e.pageY,this.applyResizeStyles())}),document.addEventListener(`mousemove`,e=>{if(!this.isResizeStarted||!this.activeMuntinSash)return;let[t,n,r,i]=this.activeMuntinSash.getChildren(),a=this.activeMuntinSash.isLeftRightSplit(),o=this.activeMuntinSash.isTopBottomSplit();if(a&&i&&n){let t=e.pageX-this.lastX,r=i.width+t,a=n.width-t;if(t>0&&a<=n.calcMinWidth()||t<0&&r<=i.calcMinWidth())return;i.width=r,n.width=a,n.left+=t,this.update(),this.lastX=e.pageX}else if(o&&t&&r){let n=e.pageY-this.lastY,i=t.height+n,a=r.height-n;if(n>0&&a<=r.calcMinHeight()||n<0&&i<=t.calcMinHeight())return;t.height=i,r.height=a,r.top+=n,this.update(),this.lastY=e.pageY}}),document.addEventListener(`mouseup`,()=>{this.isResizeStarted=!1,this.activeMuntinSash=null,this.revertResizeStyles()})}},ae={activeDropPaneEl:null,onPaneDrop(e,t){},enableDrop(){this.windowElement.addEventListener(`dragover`,e=>{e.preventDefault();let t=e.target.matches(`bw-pane`)?e.target:e.target.closest(`bw-pane`);if(!t||(t!==this.activeDropPaneEl&&(this.activeDropPaneEl&&this.activeDropPaneEl.removeAttribute(`drop-area`),this.activeDropPaneEl=t),t.getAttribute(`can-drop`)===`false`))return;let n=C(t,e);t.setAttribute(`drop-area`,n)}),this.windowElement.addEventListener(`dragleave`,e=>{e.currentTarget.contains(e.relatedTarget)&&e.currentTarget!==e.relatedTarget||(this.activeDropPaneEl&&=(this.activeDropPaneEl.removeAttribute(`drop-area`),null))}),this.windowElement.addEventListener(`drop`,e=>{if(!this.activeDropPaneEl||this.activeDropPaneEl.getAttribute(`can-drop`)===`false`)return;let t=this.activeDropPaneEl.getAttribute(`sash-id`),n=this.rootSash.getById(t);this.onPaneDrop(e,n),typeof n.store.onDrop==`function`&&n.store.onDrop(e,n),this.activeDropPaneEl.removeAttribute(`drop-area`),this.activeDropPaneEl=null})}},W=!1,G=class{windowElement=null;containerElement=null;debug=W;constructor(e){let t=null;e instanceof k?(t=e,this.rootSash=e):(t=new ie(e),this.rootSash=t.buildSashTree({resizeStrategy:t.resizeStrategy})),this.fitContainer=t.fitContainer,this.theme=t.theme}frame(e){this.containerElement=e,this.windowElement=this.createWindow({theme:this.theme}),this.glaze(),this.containerElement.append(this.windowElement)}enableFeatures(){this.enableResize(),this.enableDrop(),this.fitContainer&&this.enableFitContainer()}mount(e){this.frame(e),this.enableFeatures()}static assemble(...e){e.forEach(e=>{g(this.prototype,e)})}};G.assemble(B,V,R,H,ae,U);var K={label:``,className:`bw-glass-action--close`,onClick:(e,t)=>{let n=L(e.target);t.removePane(n)}},q={label:``,className:`bw-glass-action--minimize`,onClick:(e,t)=>{let n=t.sillElement;if(!n)throw Error(`[bwin] Sill element not found when minimizing`);let r=v(`<button class="bw-minimized-glass" />`);n.append(r);let i=e.target.closest(`bw-pane`),a=e.target.closest(`bw-glass`),o=i.getAttribute(`sash-id`),s=i.getAttribute(`position`);r.bwGlassElement=a,r.bwOriginalPosition=s,r.bwOriginalBoundingRect=y(i),r.bwOriginalSashId=o,t.removePane(o)}},J={label:``,className:`bw-glass-action--maximize`,onClick:e=>{let t=e.target.closest(`bw-pane`);t.hasAttribute(`maximized`)?(t.removeAttribute(`maximized`),t.style.left=`${t.bwOriginalBoundingRect.left}px`,t.style.top=`${t.bwOriginalBoundingRect.top}px`,t.style.width=`${t.bwOriginalBoundingRect.width}px`,t.style.height=`${t.bwOriginalBoundingRect.height}px`):(t.setAttribute(`maximized`,``),t.bwOriginalBoundingRect=y(t),t.style.left=`0`,t.style.top=`0`,t.style.width=`100%`,t.style.height=`100%`)}};function oe(e,t){let n=e.left+e.width,r=e.top+e.height,i=t.left+t.width,a=t.top+t.height;if(e.left>=i||t.left>=n||e.top>=a||t.top>=r)return null;let o=Math.max(e.left,t.left),s=Math.max(e.top,t.top),c=Math.min(n,i),l=Math.min(r,a);return{left:o,top:s,width:c-o,height:l-s}}var Y=[q,J,K],se={enableActions(){this.handleMinimizedGlassClick(),this.observeActionButtons()},restoreGlass(e){let t=e.bwOriginalBoundingRect,n=0,r=null;if(this.windowElement.querySelectorAll(`bw-pane`).forEach(e=>{let i=oe(t,y(e));if(i){let t=i.width*i.height;t>n&&(n=t,r=e)}}),r){let n=e.bwOriginalPosition,i=y(r),a=r.getAttribute(`sash-id`),o=this.rootSash.getById(a),s=0;if(n===b.Left||n===b.Right)s=i.width-t.width<o.minWidth?i.width/2:t.width;else if(n===b.Top||n===b.Bottom)s=i.height-t.height<o.minHeight?i.height/2:t.height;else throw Error(`[bwin] Invalid position when restoring glass`);let c=e.bwOriginalSashId;this.addPane(r.getAttribute(`sash-id`),{id:c,position:n,size:s}).domNode.append(e.bwGlassElement)}},handleMinimizedGlassClick(){this.sillElement.addEventListener(`click`,e=>{if(!e.target.matches(`.bw-minimized-glass`))return;let t=e.target;this.restoreGlass(t),t.remove()})},updateDisabledStateOfActionButtons(){this.updateDisabledState(`.bw-glass-action--close`),this.updateDisabledState(`.bw-glass-action--minimize`),this.updateDisabledState(`.bw-glass-action--maximize`)},updateDisabledState(e){if(this.windowElement.querySelectorAll(`bw-pane`).length===1){let t=this.windowElement.querySelector(e);t&&t.setAttribute(`disabled`,``)}else this.windowElement.querySelectorAll(e).forEach(e=>{e.removeAttribute(`disabled`)})},getMinimizedGlassElementBySashId(e){let t=this.windowElement.querySelectorAll(`.bw-minimized-glass`);return Array.from(t).find(t=>t.bwOriginalSashId===e)},observeActionButtons(){this.updateDisabledStateOfActionButtons(),new MutationObserver(e=>{e.forEach(e=>{e.type===`childList`&&this.updateDisabledStateOfActionButtons()})}).observe(this.windowElement,{childList:!0})}},X={title:null,content:null,tabs:[],actions:void 0,draggable:!0},Z=class{domNode;constructor({title:e=X.title,content:t=X.content,tabs:n=X.tabs,actions:r=X.actions,draggable:i=X.draggable,sash:a,binaryWindow:o}){this.title=e,this.content=t,this.tabs=n,this.actions=r,this.sash=a,this.draggable=i,this.binaryWindow=o,this.build()}build(){let e=document.createElement(`bw-glass-header`);if(Array.isArray(this.tabs)&&this.tabs.length>0)e.append(this.createTabs());else if(this.title){let t=document.createElement(`bw-glass-title`);t.append(v(this.title)),e.append(t)}e.setAttribute(`can-drag`,this.draggable),e.append(this.createActions());let t=document.createElement(`bw-glass-content`),n=v(this.content);n&&t.append(n),this.domNode=document.createElement(`bw-glass`),this.domNode.append(e,t)}createTabs(){let e=document.createElement(`bw-glass-tab-container`);for(let t of this.tabs){let n=v(`<button class="bw-glass-tab">${t?.label??t}</button>`);e.append(n)}return e}createActions(){let e=document.createElement(`bw-glass-action-container`),t=this.actions===void 0?Y:Array.isArray(this.actions)?this.actions:[];for(let n of t){let t=n?.label??n,r=v(`<button class="${n.className?`bw-glass-action ${n.className}`:`bw-glass-action`}">${t}</button>`);typeof n.onClick==`function`&&r.addEventListener(`click`,e=>{n.onClick(e,this.binaryWindow)}),e.append(r)}return e}get contentElement(){return this.domNode.querySelector(`bw-glass-content`)}get headerElement(){return this.domNode.querySelector(`bw-glass-header`)}},ce={activeDragGlassEl:null,activeDragGlassPaneCanDrop:!1,onPaneDrop(e,t){if(!this.activeDragGlassEl)return;let n=this.activeDropPaneEl.getAttribute(`drop-area`);if(n===`center`){let e=this.activeDragGlassEl.closest(`bw-pane`);this.swapPanes(e,this.activeDropPaneEl);return}else{let e=L(this.activeDragGlassEl);this.removePane(e),this.addPane(t.id,{position:n,id:e}).domNode.append(this.activeDragGlassEl)}},enableDrag(){document.addEventListener(`mousedown`,e=>{if(e.button!==0||!e.target.matches(`bw-glass-header`))return;if(e.target.getAttribute(`can-drag`)===`false`){e.preventDefault();return}let t=e.target.closest(`bw-glass`);t.setAttribute(`draggable`,!0),this.activeDragGlassEl=t}),document.addEventListener(`mouseup`,()=>{this.activeDragGlassEl&&=(this.activeDragGlassEl.removeAttribute(`draggable`),null)}),this.windowElement.addEventListener(`dragstart`,e=>{if(!(e.target instanceof HTMLElement)||!e.target.matches(`bw-glass`)||!this.activeDragGlassEl)return;e.dataTransfer.effectAllowed=`move`;let t=this.activeDragGlassEl.closest(`bw-pane`);this.activeDragGlassPaneCanDrop=t.getAttribute(`can-drop`)!==`false`,t.setAttribute(`can-drop`,!1)}),this.windowElement.addEventListener(`dragend`,()=>{this.activeDragGlassEl&&=(this.activeDragGlassEl.removeAttribute(`draggable`),this.activeDragGlassEl.closest(`bw-pane`).setAttribute(`can-drop`,this.activeDragGlassPaneCanDrop),null)})}},le={trimMuntin(e){e.hasAttribute(`vertical`)?(e.style.top=`${parseFloat(e.style.top)+this.muntinSize/2}px`,e.style.height=`${parseFloat(e.style.height)-this.muntinSize}px`):e.hasAttribute(`horizontal`)&&(e.style.left=`${parseFloat(e.style.left)+this.muntinSize/2}px`,e.style.width=`${parseFloat(e.style.width)-this.muntinSize}px`)},onMuntinCreate(e){this.trimMuntin(e)},onMuntinUpdate(e){this.trimMuntin(e)}},Q=class extends G{sillElement=null;frame(){super.frame(...arguments);let e=v(`<bw-sill />`);this.windowElement.append(e),this.sillElement=e}enableFeatures(){super.enableFeatures(),this.enableDrag(),this.enableActions()}onPaneCreate(e,t){let n=new Z({...t.store,sash:t,binaryWindow:this});e.innerHTML=``,e.append(n.domNode),this.debug&&n.contentElement.prepend(`${t.id}`)}onPaneUpdate(){}addPane(e,t){let{position:n,size:r,id:i,...a}=t,o=super.addPane(e,{position:n,size:r,id:i}),s=new Z({...a,sash:o,binaryWindow:this});return o.domNode.append(s.domNode),o}setTheme(e){if(!e){this.theme=``,this.windowElement.removeAttribute(`theme`);return}this.theme=e,this.windowElement.setAttribute(`theme`,e)}removePane(e){if(this.windowElement.querySelector(`[sash-id="${e}"]`)){super.removePane(e);return}let t=this.getMinimizedGlassElementBySashId(e);t&&t.remove()}};Q.assemble(ce,le,se);var $=4;function ue({sash:e}){let n=(0,t.useRef)(),r=e.leftChild,i=e.topChild,a,o,s,c,l,u;return r?(a=$,o=e.height-$,s=e.top+$/2,c=e.left+r.width-$/2,l=!0):i&&(a=e.width-$,o=$,s=e.top+i.height-$/2,c=e.left+$/2,u=!0),(0,t.useEffect)(()=>{e.domNode=n.current},[]),t.default.createElement(`bw-muntin`,{"sash-id":e.id,style:{width:a,height:o,top:s,left:c},vertical:l,horizontal:u,resizable:e.store?.resizable===!1?`false`:`true`,ref:n})}function de({sash:e,bwin:n}){let r=(0,t.useRef)(),{left:i,top:a,width:o,height:s,id:c,position:l}=e;(0,t.useEffect)(()=>{e.domNode=r.current},[]);let u=e.store?.actions===void 0?Y:Array.isArray(e.store.actions)?e.store.actions:[];return t.default.createElement(`bw-pane`,{"sash-id":c,position:l,style:{left:i,top:a,width:o,height:s},"can-drop":e.store?.droppable===!1?`false`:`true`,ref:r},t.default.createElement(`bw-glass`,null,t.default.createElement(`bw-glass-header`,{"can-drag":e.store?.draggable===!1?`false`:`true`},e.store?.title&&t.default.createElement(`bw-glass-title`,null,e.store.title),u.length>0&&t.default.createElement(`bw-glass-action-container`,null,u.map((e,r)=>{let i=e.className?`bw-glass-action ${e.className}`:`bw-glass-action`;return t.default.createElement(`button`,{className:i,key:r,onClick:t=>e.onClick(t,n)},e.label)}))),t.default.createElement(`bw-glass-content`,null,e.store?.content)))}var fe=(0,t.forwardRef)((e,r)=>{let i=(0,t.useRef)(),a=(0,t.useRef)(),[o,s]=(0,t.useState)(),{panes:c,...l}=e,u=new Q({...l,children:c}),d=[],f=[];u.rootSash.walk(e=>{e.children.length>0?d.push(e):f.push(e)}),(0,t.useEffect)(()=>{let e=i.current;e?.parentElement&&(u.windowElement=e,u.containerElement=e.parentElement,u.sillElement=a.current,u.enableFeatures())},[]),(0,t.useImperativeHandle)(r,()=>({fit:u.fit.bind(u),removePane:u.removePane.bind(u),setTheme:u.setTheme.bind(u),addPane:h}),[]);let p=t.default.createElement(`bw-window`,{"root-sash-id":u.rootSash.id,theme:u.theme||void 0,style:{width:u.rootSash.width,height:u.rootSash.height},ref:i},f.map(e=>t.default.createElement(de,{key:e.id,sash:e,bwin:u})),d.map(e=>t.default.createElement(ue,{key:e.id,sash:e})),t.default.createElement(`bw-sill`,{ref:a})),m=(0,t.useMemo)(()=>p,[]);function h(e,t){let{content:n,...r}=t,i=u.addPane(e,r),a=document.querySelector(`bw-pane[sash-id="${i.id}"] bw-glass-content`);s(e=>[...e||[],{node:n,container:a}])}return t.default.createElement(t.default.Fragment,null,m,o?.map(e=>(0,n.createPortal)(e.node,e.container)))});e.BUILTIN_ACTIONS=Y,e.Window=fe,e.version=`0.3.5`});
8
+ `.trim(),t}var ye={createWindow({theme:e}={}){let t=document.createElement(`bw-window`);return t.style.width=`${this.rootSash.width}px`,t.style.height=`${this.rootSash.height}px`,t.setAttribute(`root-sash-id`,this.rootSash.id),e&&t.setAttribute(`theme`,e),t},glaze(){this.rootSash.walk(e=>{let t=null;e.children.length>0?(t=this.createMuntin(e),this.onMuntinCreate(t,e),this.windowElement.append(t)):(t=this.createPane(e),this.onPaneCreate(t,e),this.windowElement.prepend(t)),e.domNode=t})},update(){this.windowElement.style.width=`${this.rootSash.width}px`,this.windowElement.style.height=`${this.rootSash.height}px`;let e=this.rootSash.getAllIds(),t=[];this.windowElement.querySelectorAll(`[sash-id]`).forEach(n=>{let r=n.getAttribute(`sash-id`);t.push(r),e.includes(r)||n.remove()}),this.rootSash.walk(e=>{e.children.length>0?t.includes(e.id)?(this.updateMuntin(e),this.onMuntinUpdate(e.domNode,e)):(e.domNode=this.createMuntin(e),this.windowElement.append(e.domNode)):t.includes(e.id)?(this.updatePane(e),this.onPaneUpdate(e.domNode,e)):(e.domNode||=this.createPane(e),this.windowElement.prepend(e.domNode))})}},be={muntinSize:4,createMuntin(e){let t=document.createElement(`bw-muntin`),n=e.leftChild,r=e.topChild;return n?(t.style.width=`${this.muntinSize}px`,t.style.height=`${e.height}px`,t.style.top=`${e.top}px`,t.style.left=`${e.left+n.width-this.muntinSize/2}px`,t.setAttribute(`vertical`,``)):r&&(t.style.width=`${e.width}px`,t.style.height=`${this.muntinSize}px`,t.style.top=`${e.top+r.height-this.muntinSize/2}px`,t.style.left=`${e.left}px`,t.setAttribute(`horizontal`,``)),t.setAttribute(`sash-id`,e.id),e.store.resizable===!1&&t.setAttribute(`resizable`,`false`),t},onMuntinCreate(e,t){},updateMuntin(e){let t=e.domNode,n=e.leftChild,r=e.topChild;n?(t.style.height=`${e.height}px`,t.style.top=`${e.top}px`,t.style.left=`${e.left+n.width-this.muntinSize/2}px`):r&&(t.style.width=`${e.width}px`,t.style.top=`${e.top+r.height-this.muntinSize/2}px`,t.style.left=`${e.left}px`)},onMuntinUpdate(e,t){}},D={fitContainer:!1,fit(){this.rootSash.width=this.containerElement.clientWidth,this.rootSash.height=this.containerElement.clientHeight,this.update()},enableFitContainer(){new ResizeObserver(e=>{requestAnimationFrame(()=>{for(let t of e)t.target===this.containerElement&&this.fitContainer&&this.fit()})}).observe(this.containerElement)}},O={activeMuntinSash:null,isResizeStarted:!1,isDropStarted:!1,lastX:0,lastY:0,applyResizeStyles(){this.activeMuntinSash.domNode.hasAttribute(`vertical`)?document.body.classList.add(`body--bw-resize-x`):this.activeMuntinSash.domNode.hasAttribute(`horizontal`)&&document.body.classList.add(`body--bw-resize-y`)},revertResizeStyles(){document.body.classList.remove(`body--bw-resize-x`),document.body.classList.remove(`body--bw-resize-y`)},enableResize(){document.addEventListener(`mousedown`,e=>{if(e.target.tagName!==`BW-MUNTIN`||e.target.getAttribute(`resizable`)===`false`)return;let t=e.target.getAttribute(`sash-id`);this.activeMuntinSash=this.rootSash.getById(t),this.activeMuntinSash&&(this.isResizeStarted=!0,this.lastX=e.pageX,this.lastY=e.pageY,this.applyResizeStyles())}),document.addEventListener(`mousemove`,e=>{if(!this.isResizeStarted||!this.activeMuntinSash)return;let[t,n,r,i]=this.activeMuntinSash.getChildren(),a=this.activeMuntinSash.isLeftRightSplit(),o=this.activeMuntinSash.isTopBottomSplit();if(a&&i&&n){let t=e.pageX-this.lastX,r=i.width+t,a=n.width-t;if(t>0&&a<=n.calcMinWidth()||t<0&&r<=i.calcMinWidth())return;i.width=r,n.width=a,n.left+=t,this.update(),this.lastX=e.pageX}else if(o&&t&&r){let n=e.pageY-this.lastY,i=t.height+n,a=r.height-n;if(n>0&&a<=r.calcMinHeight()||n<0&&i<=t.calcMinHeight())return;t.height=i,r.height=a,r.top+=n,this.update(),this.lastY=e.pageY}}),document.addEventListener(`mouseup`,()=>{this.isResizeStarted=!1,this.activeMuntinSash=null,this.revertResizeStyles()})}},k={activeDropPaneEl:null,onPaneDrop(e,t){},enableDrop(){this.windowElement.addEventListener(`dragover`,e=>{e.preventDefault();let t=e.target.matches(`bw-pane`)?e.target:e.target.closest(`bw-pane`);if(!t||(t!==this.activeDropPaneEl&&(this.activeDropPaneEl&&this.activeDropPaneEl.removeAttribute(`drop-area`),this.activeDropPaneEl=t),t.getAttribute(`can-drop`)===`false`))return;let n=se(t,e);t.setAttribute(`drop-area`,n)}),this.windowElement.addEventListener(`dragleave`,e=>{e.currentTarget.contains(e.relatedTarget)&&e.currentTarget!==e.relatedTarget||(this.activeDropPaneEl&&=(this.activeDropPaneEl.removeAttribute(`drop-area`),null))}),this.windowElement.addEventListener(`drop`,e=>{if(!this.activeDropPaneEl||this.activeDropPaneEl.getAttribute(`can-drop`)===`false`)return;let t=this.activeDropPaneEl.getAttribute(`sash-id`),n=this.rootSash.getById(t);this.onPaneDrop(e,n),typeof n.store.onDrop==`function`&&n.store.onDrop(e,n),this.activeDropPaneEl.removeAttribute(`drop-area`),this.activeDropPaneEl=null})}},A=!1,j=class{windowElement=null;containerElement=null;debug=A;constructor(e){let t=null;e instanceof ue?(t=e,this.rootSash=e):(t=new le(e),this.rootSash=t.buildSashTree({resizeStrategy:t.resizeStrategy})),this.fitContainer=t.fitContainer}frame(e){this.containerElement=e,this.windowElement=this.createWindow({theme:this.theme}),this.glaze(),this.containerElement.append(this.windowElement)}enableFeatures(){this.enableResize(),this.enableDrop(),this.fitContainer&&this.enableFitContainer()}mount(e){this.frame(e),this.enableFeatures()}static assemble(...e){e.forEach(e=>{ee(this.prototype,e)})}};j.assemble(ye,be,ve,D,k,O);function M(e,t){let n=e.left+e.width,r=e.top+e.height,i=t.left+t.width,a=t.top+t.height;if(e.left>=i||t.left>=n||e.top>=a||t.top>=r)return null;let o=Math.max(e.left,t.left),s=Math.max(e.top,t.top),c=Math.min(n,i),l=Math.min(r,a);return{left:o,top:s,width:c-o,height:l-s}}var N={enableGlassActions(){this.handleMinimizedGlassClick(),this.observeActionButtons()},restoreGlass(e){let t=e.bwOriginalBoundingRect,n=0,r=null;if(this.windowElement.querySelectorAll(`bw-pane`).forEach(e=>{let i=M(t,_(e));if(i){let t=i.width*i.height;t>n&&(n=t,r=e)}}),r){let n=e.bwOriginalPosition,i=_(r),a=r.getAttribute(`sash-id`),o=this.rootSash.getById(a),s=0;if(n===v.Left||n===v.Right)s=i.width-t.width<o.minWidth?i.width/2:t.width;else if(n===v.Top||n===v.Bottom)s=i.height-t.height<o.minHeight?i.height/2:t.height;else throw Error(`[bwin] Invalid position when restoring glass`);let c=e.bwOriginalSashId;this.addPane(r.getAttribute(`sash-id`),{id:c,position:n,size:s}).domNode.append(e.bwGlassElement)}},handleMinimizedGlassClick(){this.sillElement.addEventListener(`click`,e=>{if(!e.target.matches(`.bw-minimized-glass`))return;let t=e.target;this.restoreGlass(t),t.remove()})},updateDisabledStateOfActionButtons(){this.updateDisabledState(`.bw-glass-action--close`),this.updateDisabledState(`.bw-glass-action--minimize`),this.updateDisabledState(`.bw-glass-action--maximize`),this.updateDisabledState(`.bw-glass-action--detach`)},updateDisabledState(e){if(this.windowElement.querySelectorAll(`bw-pane`).length===1){let t=this.windowElement.querySelector(e);t&&t.setAttribute(`disabled`,``)}else this.windowElement.querySelectorAll(e).forEach(e=>{e.removeAttribute(`disabled`)})},getMinimizedGlassElementBySashId(e){let t=this.windowElement.querySelectorAll(`.bw-minimized-glass`);return Array.from(t).find(t=>t.bwOriginalSashId===e)},observeActionButtons(){this.updateDisabledStateOfActionButtons(),new MutationObserver(e=>{e.forEach(e=>{e.type===`childList`&&this.updateDisabledStateOfActionButtons()})}).observe(this.windowElement,{childList:!0})}},P=null,F=!1,xe={onPaneDrop(e,t){if(!P)return;let n=this.activeDropPaneEl.getAttribute(`drop-area`);if(n===`center`){let e=P.closest(`bw-pane`);this.swapPanes(e,this.activeDropPaneEl);return}else{let e=T(P);this.removePane(e),this.addPane(t.id,{position:n,id:e}).domNode.replaceChildren(P)}},enableGlassDrag(){document.addEventListener(`mousedown`,e=>{if(e.button!==0||!e.target.matches(`bw-glass-header`))return;if(e.target.getAttribute(`can-drag`)===`false`){e.preventDefault();return}let t=e.target.closest(`bw-glass`);t.setAttribute(`draggable`,!0),P=t}),document.addEventListener(`mouseup`,()=>{P&&=(P.removeAttribute(`draggable`),null)}),this.windowElement.addEventListener(`dragstart`,e=>{if(!(e.target instanceof HTMLElement)||!e.target.matches(`bw-glass`)||!P)return;e.dataTransfer.effectAllowed=`move`;let t=P.closest(`bw-pane`);F=t.getAttribute(`can-drop`)!==`false`,t.setAttribute(`can-drop`,!1)}),this.windowElement.addEventListener(`dragend`,()=>{P&&=(P.removeAttribute(`draggable`),P.closest(`bw-pane`).setAttribute(`can-drop`,F),null)})}},I={label:``,className:`bw-glass-action--close`,onClick:(e,t)=>{let n=T(e.target);t.removePane(n)}},L={label:``,className:`bw-glass-action--minimize`,onClick:(e,t)=>{let n=t.sillElement;if(!n)throw Error(`[bwin] Sill element not found when minimizing`);let r=g(`<button class="bw-minimized-glass" />`);n.append(r);let i=e.target.closest(`bw-pane`),a=e.target.closest(`bw-glass`),o=i.getAttribute(`sash-id`),s=i.getAttribute(`position`);r.bwGlassElement=a,r.bwOriginalPosition=s,r.bwOriginalBoundingRect=_(i),r.bwOriginalSashId=o,t.removePane(o)}},Se={label:``,className:`bw-glass-action--maximize`,onClick:e=>{let t=e.target.closest(`bw-pane`);t.hasAttribute(`maximized`)?(t.removeAttribute(`maximized`),t.style.left=`${t.bwOriginalBoundingRect.left}px`,t.style.top=`${t.bwOriginalBoundingRect.top}px`,t.style.width=`${t.bwOriginalBoundingRect.width}px`,t.style.height=`${t.bwOriginalBoundingRect.height}px`):(t.setAttribute(`maximized`,``),t.bwOriginalBoundingRect=_(t),t.style.left=`0`,t.style.top=`0`,t.style.width=`100%`,t.style.height=`100%`)}},R=15,z={label:``,className:`bw-glass-action--detach`,onClick:(e,t)=>{if(!t.addDetachedGlass)throw Error(`[bwin] Failed to detach glass from pane`);let n=e.target.closest(`bw-pane`),r=n.querySelector(`bw-glass-content`),i=n.querySelector(`bw-glass-title`),a=t.windowElement.getBoundingClientRect(),o=a.width-R*2,s=a.height-R*2,c=t.addDetachedGlass({position:`center`,width:o,height:s}),l=n.getAttribute(`sash-id`),u=t.rootSash.getById(l),d=u.parent.getChildSiblingById(l).id;c.domNode.bwOriginalSiblingSashId=d,c.domNode.bwOriginalPosition=n.getAttribute(`position`),c.domNode.bwOriginalRelativeSize=u.getRelativeSize(),c.contentElement.replaceWith(r),i&&c.titleElement.replaceWith(i),t.removePane(l)}},B=[L,z,I],V=class{domNode;constructor({title:e=null,content:t=null,tabs:n=[],actions:r=B,draggable:i=!0,sash:a=null,binaryWindow:o}){this.title=e,this.content=t,this.tabs=n,this.actions=r,this.sash=a,this.draggable=i,this.binaryWindow=o,this.build()}build(){let e=document.createElement(`bw-glass-header`);if(Array.isArray(this.tabs)&&this.tabs.length>0)e.append(this.createTabs());else{let t=document.createElement(`bw-glass-title`);this.title&&t.append(g(this.title)),e.append(t)}e.setAttribute(`can-drag`,this.draggable),e.append(this.createActions());let t=document.createElement(`bw-glass-content`),n=g(this.content);n&&t.append(n),this.domNode=document.createElement(`bw-glass`),this.domNode.append(e,t)}createTabs(){let e=document.createElement(`bw-glass-tab-container`);for(let t of this.tabs){let n=g(`<button class="bw-glass-tab">${t?.label??t}</button>`);e.append(n)}return e}createActions(){let e=document.createElement(`bw-glass-action-container`),t=Array.isArray(this.actions)?this.actions:[];for(let n of t){let t=n?.label??n,r=g(`<button class="${n.className?`bw-glass-action ${n.className}`:`bw-glass-action`}">${t}</button>`);typeof n.onClick==`function`&&r.addEventListener(`click`,e=>{n.onClick(e,this.binaryWindow)}),e.append(r)}return e}get contentElement(){return this.domNode.querySelector(`bw-glass-content`)}get headerElement(){return this.domNode.querySelector(`bw-glass-header`)}get titleElement(){return this.domNode.querySelector(`bw-glass-title`)}},Ce=[L,Se,z,I],we={enableGlassFeature(){this.enableGlassActions(),this.enableGlassDrag()},...N,...xe},Te={trimMuntin(e){e.hasAttribute(`vertical`)?(e.style.top=`${parseFloat(e.style.top)+this.muntinSize/2}px`,e.style.height=`${parseFloat(e.style.height)-this.muntinSize}px`):e.hasAttribute(`horizontal`)&&(e.style.left=`${parseFloat(e.style.left)+this.muntinSize/2}px`,e.style.width=`${parseFloat(e.style.width)-this.muntinSize}px`)},onMuntinCreate(e){this.trimMuntin(e)},onMuntinUpdate(e){this.trimMuntin(e)}},H=[`n`,`s`,`e`,`w`,`ne`,`nw`,`se`,`sw`];function Ee(){return H.map(e=>{let t=document.createElement(`bw-glass-resize-handle`);return t.setAttribute(`resize-dir`,e),t})}function De({position:e,offset:t,offsetX:n,offsetY:r,width:i,height:a}){let o=n??t,s=r??t;switch(e){case`top-left`:return{top:`${s}px`,left:`${o}px`,right:`auto`,bottom:`auto`};case`top-right`:return{top:`${s}px`,right:`${o}px`,left:`auto`,bottom:`auto`};case`bottom-left`:return{bottom:`${s}px`,left:`${o}px`,right:`auto`,top:`auto`};case`bottom-right`:return{bottom:`${s}px`,right:`${o}px`,left:`auto`,top:`auto`};case`center`:return{top:`calc(50% - ${a/2}px + ${s}px)`,left:`calc(50% - ${i/2}px + ${o}px)`,right:`auto`,bottom:`auto`};default:throw Error(`Position "${e}" is not supported for detached glass.`)}}var U=new class{constructor(){this.glasses=[],this.topZIndex=1}addGlassByElement(e){this.glasses.push(e)}getActiveGlass(){return this.glasses.find(e=>e.hasAttribute(`active`))??null}bringToFront(e){e.hasAttribute(`active`)||(this.topZIndex+=1,e.style.zIndex=this.topZIndex,e.parentElement?.querySelectorAll(`:scope > bw-glass[detached][active]`).forEach(t=>t!==e&&t.removeAttribute(`active`)),e.setAttribute(`active`,``))}removeGlassById(e){let t=this.glasses.findIndex(t=>t.id===e);if(t!==-1){let[e]=this.glasses.splice(t,1);return e}return null}},W=[{label:``,className:`bw-glass-action--minimize`,onClick:(e,t)=>{let n=t.sillElement;if(!n)throw Error(`[bwin] Sill element not found when minimizing`);let r=g(`<button class="bw-minimized-detached-glass" />`);n.append(r);let i=e.target.closest(`bw-glass[detached]`);if(!i)throw Error(`[bwin] Detached Glass element not found when minimizing`);r.bwDetachedGlassElement=i,i.style.display=`none`}},{label:``,className:`bw-glass-action--attach`,onClick:(e,t)=>{let n=e.target.closest(`bw-glass[detached]`),r=n.bwOriginalPosition,i=n.bwOriginalSiblingSashId,a=n.bwOriginalRelativeSize,o=t.rootSash.getById(i),s=i,c=r,l=a;if(!o){let e=t.rootSash.getLargestLeaf();s=e.id,c=e.width>e.height?`right`:`bottom`,l=.5}let u=n.querySelector(`bw-glass-content`);t.addPane(s,{position:c,size:l,content:ne(u),title:n.querySelector(`bw-glass-title`)?.textContent||``}),t.removeDetachedGlass(n.id)}},{label:``,className:`bw-glass-action--close`,onClick:e=>{let t=e.target.closest(`bw-glass[detached]`);t&&(U.removeGlassById(t.id),t.remove())}}],Oe=class extends V{constructor(e){let{position:t,width:n=222,height:r=222,offset:i=0,offsetX:a,offsetY:o,id:s,actions:c=W,...l}=e;super({...l,actions:c}),this.domNode.setAttribute(`id`,s||d()+`-F`),this.domNode.setAttribute(`detached`,``),this.domNode.style.position=`absolute`,this.domNode.style.width=`${n}px`,this.domNode.style.height=`${r}px`;let{top:u,left:f,right:p,bottom:m}=De({position:t,offset:i,offsetX:a,offsetY:o,width:n,height:r});this.domNode.style.top=u,this.domNode.style.left=f,this.domNode.style.right=p,this.domNode.style.bottom=m}},ke=200,Ae=200,G=25;function je(e,{width:t,height:n}){let r=U.getActiveGlass();if(!r)return{position:`center`};let i=e.getBoundingClientRect(),a=r.getBoundingClientRect(),o=a.left-i.left+G,s=a.top-i.top+G;return o+t>i.width&&(o=G),s+n>i.height&&(s=G),{position:`top-left`,offsetX:o,offsetY:s}}var Me={addDetachedGlass(e={}){let t=e.width??ke,n=e.height??Ae,{position:r,offsetX:i,offsetY:a}=e.position?{}:je(this.windowElement,{width:t,height:n}),o=new Oe({actions:this.actions[1],binaryWindow:this,position:r,offsetX:i,offsetY:a,...e,width:t,height:n});return this.windowElement.append(o.domNode),U.addGlassByElement(o.domNode),U.bringToFront(o.domNode),o},removeDetachedGlass(e){let t=U.removeGlassById(e);return t?.remove(),t}},Ne={enableDetachedGlassActivate(){this.windowElement.addEventListener(`pointerdown`,e=>{if(e.button!==0)return;let t=e.target.closest?.(`bw-glass[detached]`);t&&U.bringToFront(t)})}},Pe={enableDetachedGlassMove(){let e=null,t=0,n=0,r=0,i=0;this.windowElement.addEventListener(`pointerdown`,a=>{if(a.button!==0)return;let o=a.target.closest(`bw-glass-header`);if(!o||a.target.closest(`button`)||o.getAttribute(`can-drag`)===`false`)return;let s=o.closest(`bw-glass[detached]`);if(!s)return;a.preventDefault(),o.setPointerCapture(a.pointerId),e=s,t=a.pageX,n=a.pageY;let c=this.windowElement.getBoundingClientRect(),l=s.getBoundingClientRect();r=l.left-c.left,i=l.top-c.top}),this.windowElement.addEventListener(`pointermove`,a=>{if(!e)return;let o=r+(a.pageX-t),s=i+(a.pageY-n);e.style.right=`auto`,e.style.bottom=`auto`,e.style.left=`${o}px`,e.style.top=`${s}px`}),this.windowElement.addEventListener(`pointerup`,t=>{e&&=(t.target.hasPointerCapture?.(t.pointerId)&&t.target.releasePointerCapture(t.pointerId),null)})}},K=null,q=0,J=0,Fe={enableDetachedGlassDrag(){document.addEventListener(`mousedown`,e=>{if(e.button!==0)return;let t=e.target.closest(`bw-glass-header`);if(!t||e.target.closest(`button`)||t.getAttribute(`can-drag`)===`false`)return;let n=t.closest(`bw-glass[detached]`);n&&(n.setAttribute(`draggable`,!0),K=n)}),document.addEventListener(`mouseup`,()=>{K&&=(K.removeAttribute(`draggable`),null)}),this.windowElement.addEventListener(`dragstart`,e=>{if(!K)return;e.dataTransfer.effectAllowed=`move`;let t=K.getBoundingClientRect();q=e.clientX-t.left,J=e.clientY-t.top}),this.windowElement.addEventListener(`dragend`,e=>{if(!K)return;let t=this.windowElement.getBoundingClientRect(),n=e.clientX-t.left-q,r=e.clientY-t.top-J;K.style.right=`auto`,K.style.bottom=`auto`,K.style.left=`${n}px`,K.style.top=`${r}px`,K.removeAttribute(`draggable`),K=null})}},Y=100,X=60;function Ie(e){return!!e.querySelector(`:scope > bw-glass-resize-handle`)}function Le(e){Ie(e)||e.append(...Ee())}function Z(e){e.querySelectorAll(`:scope > bw-glass-resize-handle`).forEach(e=>e.remove())}var Re={enableDetachedGlassResize(){let e=null,t=``,n=0,r=0,i=null;this.windowElement.addEventListener(`pointerover`,e=>{let t=e.target.closest?.(`bw-glass[detached]`);t&&Le(t)}),this.windowElement.addEventListener(`pointerout`,t=>{let n=t.target.closest?.(`bw-glass[detached]`);n&&t.relatedTarget?.closest?.(`bw-glass[detached]`)!==n&&n!==e&&Z(n)}),this.windowElement.addEventListener(`pointerdown`,a=>{if(a.button!==0||a.target.tagName!==`BW-GLASS-RESIZE-HANDLE`)return;let o=a.target.closest(`bw-glass[detached]`);if(!o)return;a.preventDefault(),a.target.setPointerCapture(a.pointerId),e=o,t=a.target.getAttribute(`resize-dir`),n=a.pageX,r=a.pageY;let s=this.windowElement.getBoundingClientRect(),c=o.getBoundingClientRect();i={left:c.left-s.left,top:c.top-s.top,width:c.width,height:c.height}}),this.windowElement.addEventListener(`pointermove`,a=>{if(!e)return;let o=t,s=a.pageX-n,c=a.pageY-r,l=i,{left:u,top:d,width:f,height:p}=l;o.includes(`e`)?f=Math.max(Y,l.width+s):o.includes(`w`)&&(f=Math.max(Y,l.width-s),u=l.left+(l.width-f)),o.includes(`s`)?p=Math.max(X,l.height+c):o.includes(`n`)&&(p=Math.max(X,l.height-c),d=l.top+(l.height-p)),e.style.right=`auto`,e.style.bottom=`auto`,e.style.left=`${u}px`,e.style.top=`${d}px`,e.style.width=`${f}px`,e.style.height=`${p}px`}),this.windowElement.addEventListener(`pointerup`,n=>{if(!e)return;n.target.hasPointerCapture?.(n.pointerId)&&n.target.releasePointerCapture(n.pointerId);let r=e;e=null,t=``,i=null,r.matches(`:hover`)||Z(r)})}},ze={handleMinimizedDetachedGlassClick(){this.sillElement.addEventListener(`click`,e=>{let t=e.target;if(!t.matches(`.bw-minimized-detached-glass`))return;let n=t.bwDetachedGlassElement;n&&(n.style.display=``,t.remove(),U.bringToFront(n))})}},Be={enableDetachedGlassFeatures(){this.enableDetachedGlassActivate(),this.enableDetachedGlassResize(),this.enableDetachedGlassMove(),this.handleMinimizedDetachedGlassClick()},...Me,...Ne,...Pe,...Fe,...Re,...ze},Q=class e extends j{sillElement=null;constructor(t){super(t),this.theme=t.theme||``,this.actions=e.normActions(t.actions)}frame(){super.frame(...arguments);let e=g(`<bw-sill />`);this.windowElement.append(e),this.sillElement=e}enableFeatures(){super.enableFeatures(),this.enableGlassFeature(),this.enableDetachedGlassFeatures()}onPaneCreate(e,t){let n=this.actions[0],r=new V({actions:n,...t.store,sash:t,binaryWindow:this});e.innerHTML=``,e.append(r.domNode),this.debug&&r.contentElement.prepend(`${t.id}`)}onPaneUpdate(){}addPane(e,t){let{position:n,size:r,id:i,...a}=t,o=super.addPane(e,{position:n,size:r,id:i}),s=new V({...a,sash:o,binaryWindow:this});return o.domNode.append(s.domNode),o}setTheme(e){if(!e){this.theme=``,this.windowElement.removeAttribute(`theme`);return}this.theme=e,this.windowElement.setAttribute(`theme`,e)}removePane(e){if(this.windowElement.querySelector(`[sash-id="${e}"]`)){super.removePane(e);return}let t=this.getMinimizedGlassElementBySashId(e);t&&t.remove()}static normActions(e){if(e===void 0)return[B,W];if(!e||!Array.isArray(e)||e.length===0)return[[],[]];if(e.length===1&&Array.isArray(e[0]))return[e[0],W];if(!e.some(Array.isArray))return[e,W];if(e.length>=2&&!Array.isArray(e[0])&&Array.isArray(e[1]))return[[],e[1]];if(e.length>=2&&Array.isArray(e[0])&&!Array.isArray(e[1]))return[e[0],[]];if(e.length>=2&&Array.isArray(e[0])&&Array.isArray(e[1]))return e;throw Error(`[bwin] Invalid actions format`)}};Q.assemble(we,Be,Te);var $=4;function Ve({sash:e}){let n=(0,t.useRef)(),r=e.leftChild,i=e.topChild,a,o,s,c,l,u;return r?(a=$,o=e.height-$,s=e.top+$/2,c=e.left+r.width-$/2,l=!0):i&&(a=e.width-$,o=$,s=e.top+i.height-$/2,c=e.left+$/2,u=!0),(0,t.useEffect)(()=>{e.domNode=n.current},[]),t.default.createElement(`bw-muntin`,{"sash-id":e.id,style:{width:a,height:o,top:s,left:c},vertical:l,horizontal:u,resizable:e.store?.resizable===!1?`false`:`true`,ref:n})}function He({sash:e,bwin:n}){let r=(0,t.useRef)(),{left:i,top:a,width:o,height:s,id:c,position:l}=e;(0,t.useEffect)(()=>{e.domNode=r.current},[]);let u=e.store?.actions===void 0?n.actions[0]:Array.isArray(e.store.actions)?e.store.actions:[];return t.default.createElement(`bw-pane`,{"sash-id":c,position:l,style:{left:i,top:a,width:o,height:s},"can-drop":e.store?.droppable===!1?`false`:`true`,ref:r},t.default.createElement(`bw-glass`,null,t.default.createElement(`bw-glass-header`,{"can-drag":e.store?.draggable===!1?`false`:`true`},t.default.createElement(`bw-glass-title`,null,e.store?.title),u.length>0&&t.default.createElement(`bw-glass-action-container`,null,u.map((e,r)=>{let i=e.className?`bw-glass-action ${e.className}`:`bw-glass-action`;return t.default.createElement(`button`,{className:i,key:r,onClick:t=>e.onClick(t,n)},e.label)}))),t.default.createElement(`bw-glass-content`,null,e.store?.content)))}var Ue=(0,t.forwardRef)((e,r)=>{let i=(0,t.useRef)(),a=(0,t.useRef)(),[o,s]=(0,t.useState)(),{panes:c,...l}=e,u=new Q({...l,children:c}),d=[],f=[];u.rootSash.walk(e=>{e.children.length>0?d.push(e):f.push(e)}),(0,t.useEffect)(()=>{let e=i.current;e?.parentElement&&(u.windowElement=e,u.containerElement=e.parentElement,u.sillElement=a.current,u.enableFeatures())},[]),(0,t.useImperativeHandle)(r,()=>({fit:u.fit.bind(u),removePane:u.removePane.bind(u),setTheme:u.setTheme.bind(u),addPane:h}),[]);let p=t.default.createElement(`bw-window`,{"root-sash-id":u.rootSash.id,theme:u.theme||void 0,style:{width:u.rootSash.width,height:u.rootSash.height},ref:i},f.map(e=>t.default.createElement(He,{key:e.id,sash:e,bwin:u})),d.map(e=>t.default.createElement(Ve,{key:e.id,sash:e})),t.default.createElement(`bw-sill`,{ref:a})),m=(0,t.useMemo)(()=>p,[]);function h(e,t){let{content:n,...r}=t,i=u.addPane(e,r),a=document.querySelector(`bw-pane[sash-id="${i.id}"] bw-glass-content`);s(e=>[...e||[],{node:n,container:a}])}return t.default.createElement(t.default.Fragment,null,m,o?.map(e=>(0,n.createPortal)(e.node,e.container)))});e.BUILTIN_ACTIONS=Ce,e.DEFAULT_DETACHED_GLASS_ACTIONS=W,e.DEFAULT_GLASS_ACTIONS=B,e.Window=Ue,e.version=`0.4.1`});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-bwin",
3
3
  "description": "A tiling window manager in React based on Binary Window library",
4
- "version": "0.3.5",
4
+ "version": "0.4.1",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -41,7 +41,7 @@
41
41
  "@types/react": "^16.14.62",
42
42
  "@types/react-dom": "^16.9.24",
43
43
  "@vitejs/plugin-react": "^6.0.2",
44
- "bwin": "0.3.3",
44
+ "bwin": "0.4.2",
45
45
  "picocolors": "^1.1.1",
46
46
  "prettier": "^3.4.1",
47
47
  "react": "^16.14.0",