react-bwin 0.1.1 → 0.1.2

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.
@@ -75,7 +75,7 @@ declare global {
75
75
  enableFeatures(): void
76
76
  }
77
77
 
78
- type WindowProps = ConfigRoot
78
+ type WindowProps = Omit<ConfigRoot, 'children'> & { panes: ConfigNode[] }
79
79
  }
80
80
 
81
81
  export {
@@ -4,7 +4,7 @@ function X(e = 0.7, t = 128) {
4
4
  const i = 256 - t, n = Math.floor(Math.random() * i + t), s = Math.floor(Math.random() * i + t), o = Math.floor(Math.random() * i + t), h = Math.max(0.5, Math.random() * e);
5
5
  return `rgba(${n}, ${s}, ${o}, ${h})`;
6
6
  }
7
- function P(e = 2, t = 3) {
7
+ function D(e = 2, t = 3) {
8
8
  if (e < 0 || t < 0)
9
9
  throw new Error("Parameters must be non-negative numbers");
10
10
  const i = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", n = "0123456789";
@@ -120,8 +120,8 @@ function it(e, { clientX: t, clientY: i }) {
120
120
  const n = e.getBoundingClientRect(), { width: s, height: o } = n, h = t - n.left, a = i - n.top;
121
121
  if (h < 0 || h > s || a < 0 || a > o)
122
122
  return r.Outside;
123
- const l = 0.3, c = J({ width: s, height: o, x: h }), d = tt({ width: s, height: o, x: h }), p = Q({ width: s, height: o, y: a }), u = et({ width: s, height: o, y: a });
124
- return h < s * (0.5 - l / 2) && a > c && a < d ? r.Left : h > s * (0.5 + l / 2) && a < c && a > d ? r.Right : a < o * (0.5 - l / 2) && h > p && h < u ? r.Top : a > o * (0.5 + l / 2) && h < p && h > u ? r.Bottom : h > s * (0.5 - l / 2) && h < s * (0.5 + l / 2) && a > o * (0.5 - l / 2) && a < o * (0.5 + l / 2) ? r.Center : r.Unknown;
123
+ const d = 0.3, l = J({ width: s, height: o, x: h }), c = tt({ width: s, height: o, x: h }), p = Q({ width: s, height: o, y: a }), u = et({ width: s, height: o, y: a });
124
+ return h < s * (0.5 - d / 2) && a > l && a < c ? r.Left : h > s * (0.5 + d / 2) && a < l && a > c ? r.Right : a < o * (0.5 - d / 2) && h > p && h < u ? r.Top : a > o * (0.5 + d / 2) && h < p && h > u ? r.Bottom : h > s * (0.5 - d / 2) && h < s * (0.5 + d / 2) && a > o * (0.5 - d / 2) && a < o * (0.5 + d / 2) ? r.Center : r.Unknown;
125
125
  }
126
126
  const nt = 100, st = 100, E = {
127
127
  left: 0,
@@ -141,13 +141,13 @@ class m {
141
141
  minWidth: o = E.minWidth,
142
142
  minHeight: h = E.minHeight,
143
143
  domNode: a = null,
144
- store: l = {},
145
- position: c,
146
- id: d
144
+ store: d = {},
145
+ position: l,
146
+ id: c
147
147
  } = E) {
148
- if (this.id = d ?? P(), !c)
148
+ if (this.id = c ?? D(), !l)
149
149
  throw new Error("[bwin] Sash position is required");
150
- this.position = c, this.domNode = a, this._top = i, this._left = t, this._width = n, this._height = s, this.children = [], this.minWidth = o, this.minHeight = h, this.store = l;
150
+ this.position = l, this.domNode = a, this._top = i, this._left = t, this._width = n, this._height = s, this.children = [], this.minWidth = o, this.minHeight = h, this.store = d;
151
151
  }
152
152
  walk(t) {
153
153
  this.children.forEach((i) => i.walk(t)), t(this);
@@ -281,10 +281,10 @@ class m {
281
281
  this._width = t;
282
282
  const [n, s, o, h] = this.getChildren();
283
283
  if (h && s) {
284
- const a = h.width + s.width, l = i * (h.width / a), c = a + i;
285
- let d = h.width + l, p = c - d, u = s.left + l;
284
+ const a = h.width + s.width, d = i * (h.width / a), l = a + i;
285
+ let c = h.width + d, p = l - c, u = s.left + d;
286
286
  const f = h.calcMinWidth(), w = s.calcMinWidth();
287
- d < f && p > w ? (d = f, p = c - d, u = h.left + d) : p < w && d > f && (p = w, d = c - p, u = h.left + d), h.width = d, s.width = p, s.left = u;
287
+ c < f && p > w ? (c = f, p = l - c, u = h.left + c) : p < w && c > f && (p = w, c = l - p, u = h.left + c), h.width = c, s.width = p, s.left = u;
288
288
  }
289
289
  n && o && (n.width += i, o.width += i);
290
290
  }
@@ -296,10 +296,10 @@ class m {
296
296
  this._height = t;
297
297
  const [n, s, o, h] = this.getChildren();
298
298
  if (n && o) {
299
- const a = n.height + o.height, l = i * (n.height / a), c = a + i;
300
- let d = n.height + l, p = c - d, u = o.top + l;
299
+ const a = n.height + o.height, d = i * (n.height / a), l = a + i;
300
+ let c = n.height + d, p = l - c, u = o.top + d;
301
301
  const f = n.calcMinHeight(), w = o.calcMinHeight();
302
- d < f && p > w ? (d = f, p = c - d, u = n.top + d) : p < w && d > f && (p = w, d = c - p, u = n.top + d), n.height = d, o.height = p, o.top = u;
302
+ c < f && p > w ? (c = f, p = l - c, u = n.top + c) : p < w && c > f && (p = w, c = l - p, u = n.top + c), n.height = c, o.height = p, o.top = u;
303
303
  }
304
304
  h && s && (h.height += i, s.height += i);
305
305
  }
@@ -308,7 +308,7 @@ const B = {
308
308
  size: "50%",
309
309
  position: r.Left
310
310
  };
311
- class x {
311
+ class P {
312
312
  constructor({
313
313
  parentRect: t,
314
314
  children: i,
@@ -317,10 +317,10 @@ class x {
317
317
  minWidth: o,
318
318
  minHeight: h,
319
319
  position: a,
320
- size: l,
321
- ...c
320
+ size: d,
321
+ ...l
322
322
  }) {
323
- b(this, "left"), b(this, "top"), b(this, "width"), b(this, "height"), this.parentRect = t, this.children = i, this.siblingConfigNode = n, this.id = s, this.minWidth = o, this.minHeight = h, this.position = this.getPosition(a), this.size = this.getSize(l), this.nonCoreData = c, this.setBounds();
323
+ b(this, "left"), b(this, "top"), b(this, "width"), b(this, "height"), this.parentRect = t, this.children = i, this.siblingConfigNode = n, this.id = s, this.minWidth = o, this.minHeight = h, this.position = this.getPosition(a), this.size = this.getSize(d), this.nonCoreData = l, this.setBounds();
324
324
  }
325
325
  getPosition(t) {
326
326
  if (!this.siblingConfigNode)
@@ -406,7 +406,7 @@ class x {
406
406
  }
407
407
  }
408
408
  createPrimaryConfigNode({ size: t, position: i, children: n, id: s, minWidth: o, minHeight: h, ...a }) {
409
- return new x({
409
+ return new P({
410
410
  parentRect: this,
411
411
  size: t ?? B.size,
412
412
  position: i ?? B.position,
@@ -417,13 +417,13 @@ class x {
417
417
  ...a
418
418
  });
419
419
  }
420
- createSecondaryConfigNode({ size: t, position: i, children: n, id: s, minWidth: o, minHeight: h, ...a }, l) {
421
- return new x({
420
+ createSecondaryConfigNode({ size: t, position: i, children: n, id: s, minWidth: o, minHeight: h, ...a }, d) {
421
+ return new P({
422
422
  parentRect: this,
423
423
  size: t,
424
424
  position: i,
425
425
  children: n,
426
- siblingConfigNode: l,
426
+ siblingConfigNode: d,
427
427
  id: s,
428
428
  minWidth: o,
429
429
  minHeight: h,
@@ -445,22 +445,22 @@ class x {
445
445
  )), s && o && (t.children.push(s.buildSashTree()), t.children.push(o.buildSashTree())), t;
446
446
  }
447
447
  }
448
- const D = {
448
+ const x = {
449
449
  width: 333,
450
450
  height: 333
451
451
  }, $ = {
452
452
  fitContainer: !1
453
453
  };
454
- class ot extends x {
454
+ class ot extends P {
455
455
  constructor({
456
456
  id: t,
457
457
  children: i,
458
- width: n = D.width,
459
- height: s = D.height,
458
+ width: n = x.width,
459
+ height: s = x.height,
460
460
  fitContainer: o = $.fitContainer,
461
461
  ...h
462
462
  } = {
463
- ...D,
463
+ ...x,
464
464
  ...$
465
465
  }) {
466
466
  super({
@@ -600,7 +600,7 @@ const ut = {
600
600
  const n = this.rootSash.getById(e);
601
601
  if (!n) throw new Error("[bwin] Parent sash not found when adding pane");
602
602
  const s = pt(n, { position: t, size: i });
603
- return n.id = P(), this.update(), s;
603
+ return n.id = D(), this.update(), s;
604
604
  },
605
605
  /**
606
606
  * Remove a pane
@@ -611,7 +611,7 @@ const ut = {
611
611
  const t = this.rootSash.getDescendantParentById(e);
612
612
  if (!t) throw new Error("[bwin] Parent sash not found when removing pane");
613
613
  const i = t.getChildSiblingById(e);
614
- t.id = P(), i.children.length === 0 ? (t.domNode = i.domNode, t.domNode.setAttribute("sash-id", t.id), t.children = []) : (t.children = i.children, i.position === r.Left ? i.width = t.width : i.position === r.Right ? (i.width = t.width, i.left = t.left) : i.position === r.Top ? i.height = t.height : i.position === r.Bottom && (i.height = t.height, i.top = t.top)), this.update();
614
+ t.id = D(), i.children.length === 0 ? (t.domNode = i.domNode, t.domNode.setAttribute("sash-id", t.id), t.children = []) : (t.children = i.children, i.position === r.Left ? i.width = t.width : i.position === r.Right ? (i.width = t.width, i.left = t.left) : i.position === r.Top ? i.height = t.height : i.position === r.Bottom && (i.height = t.height, i.top = t.top)), this.update();
615
615
  }
616
616
  };
617
617
  function T(e) {
@@ -691,15 +691,15 @@ const gt = {
691
691
  if (!this.isResizeStarted || !this.activeMuntinSash) return;
692
692
  const [t, i, n, s] = this.activeMuntinSash.getChildren(), o = this.activeMuntinSash.isLeftRightSplit(), h = this.activeMuntinSash.isTopBottomSplit();
693
693
  if (o && s && i) {
694
- const a = e.pageX - this.lastX, l = s.width + a, c = i.width - a;
695
- if (l <= s.calcMinWidth() || c <= i.calcMinWidth())
694
+ const a = e.pageX - this.lastX, d = s.width + a, l = i.width - a;
695
+ if (d <= s.calcMinWidth() || l <= i.calcMinWidth())
696
696
  return;
697
- s.width = l, i.width = c, i.left = i.left + a, this.update(), this.lastX = e.pageX;
697
+ s.width = d, i.width = l, i.left = i.left + a, this.update(), this.lastX = e.pageX;
698
698
  } else if (h && t && n) {
699
- const a = e.pageY - this.lastY, l = t.height + a, c = n.height - a;
700
- if (l <= t.calcMinHeight() || c <= n.calcMinHeight())
699
+ const a = e.pageY - this.lastY, d = t.height + a, l = n.height - a;
700
+ if (d <= t.calcMinHeight() || l <= n.calcMinHeight())
701
701
  return;
702
- t.height = l, n.height = c, n.top = n.top + a, this.update(), this.lastY = e.pageY;
702
+ t.height = d, n.height = l, n.top = n.top + a, this.update(), this.lastY = e.pageY;
703
703
  }
704
704
  }), document.addEventListener("mouseup", () => {
705
705
  this.isResizeStarted = !1, this.activeMuntinSash = null, this.revertResizeStyles();
@@ -794,12 +794,12 @@ function zt(e, t) {
794
794
  const i = e.left + e.width, n = e.top + e.height, s = t.left + t.width, o = t.top + t.height;
795
795
  if (e.left >= s || t.left >= i || e.top >= o || t.top >= n)
796
796
  return null;
797
- const h = Math.max(e.left, t.left), a = Math.max(e.top, t.top), l = Math.min(i, s), c = Math.min(n, o);
797
+ const h = Math.max(e.left, t.left), a = Math.max(e.top, t.top), d = Math.min(i, s), l = Math.min(n, o);
798
798
  return {
799
799
  left: h,
800
800
  top: a,
801
- width: l - h,
802
- height: c - a
801
+ width: d - h,
802
+ height: l - a
803
803
  };
804
804
  }
805
805
  const I = [vt, Nt, Et], Ct = {
@@ -1011,10 +1011,10 @@ class O extends H {
1011
1011
  O.assemble(St, At, Ct);
1012
1012
  const y = 4;
1013
1013
  function Mt({ sash: e }) {
1014
- var d;
1014
+ var c;
1015
1015
  const t = M(), i = e.leftChild, n = e.topChild;
1016
- let s, o, h, a, l, c;
1017
- return i ? (s = y, o = e.height - y, h = e.top + y / 2, a = e.left + i.width - y / 2, l = !0) : n && (s = e.width - y, o = y, h = e.top + n.height - y / 2, a = e.left + y / 2, c = !0), L(() => {
1016
+ let s, o, h, a, d, l;
1017
+ return i ? (s = y, o = e.height - y, h = e.top + y / 2, a = e.left + i.width - y / 2, d = !0) : n && (s = e.width - y, o = y, h = e.top + n.height - y / 2, a = e.left + y / 2, l = !0), L(() => {
1018
1018
  e.domNode = t.current;
1019
1019
  }, []), /* @__PURE__ */ g.createElement(
1020
1020
  "bw-muntin",
@@ -1026,9 +1026,9 @@ function Mt({ sash: e }) {
1026
1026
  top: h,
1027
1027
  left: a
1028
1028
  },
1029
- vertical: l,
1030
- horizontal: c,
1031
- resizable: ((d = e.store) == null ? void 0 : d.resizable) === !1 ? "false" : "true",
1029
+ vertical: d,
1030
+ horizontal: l,
1031
+ resizable: ((c = e.store) == null ? void 0 : c.resizable) === !1 ? "false" : "true",
1032
1032
  ref: t
1033
1033
  }
1034
1034
  );
@@ -1037,17 +1037,17 @@ function Rt({
1037
1037
  sash: e,
1038
1038
  bwin: t
1039
1039
  }) {
1040
- var d, p, u, f, w;
1041
- const i = M(), { left: n, top: s, width: o, height: h, id: a, position: l } = e;
1040
+ var c, p, u, f, w;
1041
+ const i = M(), { left: n, top: s, width: o, height: h, id: a, position: d } = e;
1042
1042
  L(() => {
1043
1043
  e.domNode = i.current;
1044
1044
  }, []);
1045
- const c = ((d = e.store) == null ? void 0 : d.actions) === void 0 ? I : Array.isArray(e.store.actions) ? e.store.actions : [];
1045
+ const l = ((c = e.store) == null ? void 0 : c.actions) === void 0 ? I : Array.isArray(e.store.actions) ? e.store.actions : [];
1046
1046
  return /* @__PURE__ */ g.createElement(
1047
1047
  "bw-pane",
1048
1048
  {
1049
1049
  "sash-id": a,
1050
- position: l,
1050
+ position: d,
1051
1051
  style: { left: n, top: s, width: o, height: h },
1052
1052
  "can-drop": ((p = e.store) == null ? void 0 : p.droppable) === !1 ? "false" : "true",
1053
1053
  ref: i
@@ -1058,7 +1058,7 @@ function Rt({
1058
1058
  "can-drag": ((u = e.store) == null ? void 0 : u.draggable) === !1 ? "false" : "true"
1059
1059
  },
1060
1060
  ((f = e.store) == null ? void 0 : f.title) && /* @__PURE__ */ g.createElement("bw-glass-title", null, e.store.title),
1061
- c.length > 0 && /* @__PURE__ */ g.createElement("bw-glass-action-container", null, c.map((A, k) => {
1061
+ l.length > 0 && /* @__PURE__ */ g.createElement("bw-glass-action-container", null, l.map((A, k) => {
1062
1062
  const F = A.className ? `bw-glass-action ${A.className}` : "bw-glass-action";
1063
1063
  return /* @__PURE__ */ g.createElement(
1064
1064
  "button",
@@ -1073,26 +1073,26 @@ function Rt({
1073
1073
  ), /* @__PURE__ */ g.createElement("bw-glass-content", null, (w = e.store) == null ? void 0 : w.content))
1074
1074
  );
1075
1075
  }
1076
- function Dt(e) {
1077
- const t = M(), i = M(), n = new O(e), s = [], o = [];
1078
- return n.rootSash.walk((h) => {
1079
- h.children.length > 0 ? s.push(h) : o.push(h);
1076
+ function xt(e) {
1077
+ const t = M(), i = M(), { panes: n, ...s } = e, o = { children: n, ...s }, h = new O(o), a = [], d = [];
1078
+ return h.rootSash.walk((l) => {
1079
+ l.children.length > 0 ? a.push(l) : d.push(l);
1080
1080
  }), L(() => {
1081
- const h = t.current;
1082
- h != null && h.parentElement && (n.windowElement = h, n.containerElement = h.parentElement, n.sillElement = i.current, n.enableFeatures());
1081
+ const l = t.current;
1082
+ l != null && l.parentElement && (h.windowElement = l, h.containerElement = l.parentElement, h.sillElement = i.current, h.enableFeatures());
1083
1083
  }, []), /* @__PURE__ */ g.createElement(
1084
1084
  "bw-window",
1085
1085
  {
1086
- "sash-id": n.rootSash.id,
1087
- style: { width: n.rootSash.width, height: n.rootSash.height },
1086
+ "sash-id": h.rootSash.id,
1087
+ style: { width: h.rootSash.width, height: h.rootSash.height },
1088
1088
  ref: t
1089
1089
  },
1090
- o.map((h) => /* @__PURE__ */ g.createElement(Rt, { key: h.id, sash: h, bwin: n })),
1091
- s.map((h) => /* @__PURE__ */ g.createElement(Mt, { key: h.id, sash: h })),
1090
+ d.map((l) => /* @__PURE__ */ g.createElement(Rt, { key: l.id, sash: l, bwin: h })),
1091
+ a.map((l) => /* @__PURE__ */ g.createElement(Mt, { key: l.id, sash: l })),
1092
1092
  /* @__PURE__ */ g.createElement("bw-sill", { ref: i })
1093
1093
  );
1094
1094
  }
1095
1095
  export {
1096
1096
  I as BUILTIN_ACTIONS,
1097
- Dt as Window
1097
+ xt as Window
1098
1098
  };
@@ -1,8 +1,8 @@
1
- (function(y,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],p):(y=typeof globalThis<"u"?globalThis:y||self,p(y.ReactBinaryWindow={},y.React))})(this,function(y,p){"use strict";var I=Object.defineProperty,k=(e,t,i)=>t in e?I(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,b=(e,t,i)=>k(e,typeof t!="symbol"?t+"":t,i);function F(e=.7,t=128){const i=256-t,n=Math.floor(Math.random()*i+t),s=Math.floor(Math.random()*i+t),o=Math.floor(Math.random()*i+t),h=Math.max(.5,Math.random()*e);return`rgba(${n}, ${s}, ${o}, ${h})`}function D(e=2,t=3){if(e<0||t<0)throw new Error("Parameters must be non-negative numbers");const i="ABCDEFGHIJKLMNOPQRSTUVWXYZ",n="0123456789";let s="";for(let o=0;o<e;o++){const h=Math.floor(Math.random()*i.length);s+=i[h]}s+="-";for(let o=0;o<t;o++){const h=Math.floor(Math.random()*n.length);s+=n[h]}return s}function N(e,t){for(;t.firstChild;)e.append(t.firstChild)}function _(e,t){const i=document.createElement("div");N(i,e),N(e,t),N(t,i)}function z(e){if(typeof e=="number"&&!isNaN(e))return e;if(typeof e=="string"){const t=e.trim();if(t.endsWith("%")){const i=t.slice(0,-1);if(!i)return NaN;const n=Number(i);return isNaN(n)?NaN:n/100}if(t.endsWith("px")){const i=t.slice(0,-2);if(!i)return NaN;const n=Number(i);return isNaN(n)?NaN:n}return Number(t)}return NaN}function q(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)&&Object.getPrototypeOf(e)===Object.prototype}function U(e,t){for(const i in t){if(Object.hasOwn(e,i))throw new Error(`Key "${i}" already exists in target object`);e[i]=t[i]}return e}function j(e){const t=document.createElement("template");return t.innerHTML=e.trim(),t.content}function C(e){if(e==null||e==="")return null;if(typeof e=="string")try{const t=j(e);return t.childNodes.length===1?t.firstChild:t}catch{return document.createTextNode(e)}return e instanceof Node?e:document.createTextNode(String(e))}function M(e){const t=parseFloat(e.style.left)||0,i=parseFloat(e.style.top)||0,n=parseFloat(e.style.width)||0,s=parseFloat(e.style.height)||0;return{left:t,top:i,width:n,height:s}}const r={Top:"top",Right:"right",Bottom:"bottom",Left:"left",Center:"center",Root:"root",Unknown:"unknown",Outside:"outside"};function X(e){switch(e){case r.Top:return r.Bottom;case r.Right:return r.Left;case r.Bottom:return r.Top;case r.Left:return r.Right;default:throw new Error(`[bwin] Invalid position: ${e}`)}}function Y({width:e,height:t,x:i}){return t/e*i}function K({width:e,height:t,y:i}){return e/t*i}function V({width:e,height:t,x:i}){return t-t/e*i}function Z({width:e,height:t,y:i}){return e-e/t*i}function J(e,{clientX:t,clientY:i}){const n=e.getBoundingClientRect(),{width:s,height:o}=n,h=t-n.left,a=i-n.top;if(h<0||h>s||a<0||a>o)return r.Outside;const l=.3,c=Y({width:s,height:o,x:h}),d=V({width:s,height:o,x:h}),u=K({width:s,height:o,y:a}),g=Z({width:s,height:o,y:a});return h<s*(.5-l/2)&&a>c&&a<d?r.Left:h>s*(.5+l/2)&&a<c&&a>d?r.Right:a<o*(.5-l/2)&&h>u&&h<g?r.Top:a>o*(.5+l/2)&&h<u&&h>g?r.Bottom:h>s*(.5-l/2)&&h<s*(.5+l/2)&&a>o*(.5-l/2)&&a<o*(.5+l/2)?r.Center:r.Unknown}const Q=100,tt=100,E={left:0,top:0,width:150,height:150,minWidth:Q,minHeight:tt};class f{constructor({left:t=E.left,top:i=E.top,width:n=E.width,height:s=E.height,minWidth:o=E.minWidth,minHeight:h=E.minHeight,domNode:a=null,store:l={},position:c,id:d}=E){if(this.id=d??D(),!c)throw new Error("[bwin] Sash position is required");this.position=c,this.domNode=a,this._top=i,this._left=t,this._width=n,this._height=s,this.children=[],this.minWidth=o,this.minHeight=h,this.store=l}walk(t){this.children.forEach(i=>i.walk(t)),t(this)}isLeaf(){return this.children.length===0}isSplit(){return this.children.length>0}isLeftRightSplit(){return this.children.some(t=>t.position===r.Left||t.position===r.Right)}isTopBottomSplit(){return this.children.some(t=>t.position===r.Top||t.position===r.Bottom)}get leftChild(){return this.children.find(t=>t.position===r.Left)}get rightChild(){return this.children.find(t=>t.position===r.Right)}get topChild(){return this.children.find(t=>t.position===r.Top)}get bottomChild(){return this.children.find(t=>t.position===r.Bottom)}getChildren(){let t=null,i=null,n=null,s=null;for(const o of this.children)o.position===r.Left?t=o:o.position===r.Right?i=o:o.position===r.Top?n=o:o.position===r.Bottom&&(s=o);return[n,i,s,t]}getAllLeafDescendants(){const t=[];return this.walk(i=>{i.children.length===0&&t.push(i)}),t}calcMinWidth(){if(this.isLeaf())return this.minWidth;const[t,i,n,s]=this.getChildren();if(s&&i){const o=s.calcMinWidth()+i.calcMinWidth();return Math.max(this.minWidth,o)}if(t&&n){const o=Math.max(t.calcMinWidth(),n.calcMinWidth());return Math.max(this.minWidth,o)}}calcMinHeight(){if(this.isLeaf())return this.minHeight;const[t,i,n,s]=this.getChildren();if(s&&i){const o=Math.max(s.calcMinHeight(),i.calcMinHeight());return Math.max(this.minHeight,o)}if(t&&n){const o=t.calcMinHeight()+n.calcMinHeight();return Math.max(this.minHeight,o)}}getById(t){if(this.id===t)return this;for(const i of this.children){const n=i.getById(t);if(n)return n}return null}getAllIds(){const t=[this.id];for(const i of this.children)t.push(...i.getAllIds());return t}addChild(t){if(this.children.length>=2)throw new Error("[bwin] Maximum 2 children allowed");this.children.push(t)}getDescendantParentById(t){for(const i of this.children){if(i.id===t)return this;const n=i.getDescendantParentById(t);if(n)return n}return null}getChildSiblingById(t){return this.children.find(i=>i.id!==t)}get top(){return this._top}set top(t){const i=t-this._top;this._top=t;const[n,s,o,h]=this.getChildren();n&&o&&(n.top+=i,o.top+=i),h&&s&&(h.top+=i,s.top+=i)}get left(){return this._left}set left(t){const i=t-this._left;this._left=t;const[n,s,o,h]=this.getChildren();h&&s&&(h.left+=i,s.left+=i),n&&o&&(n.left+=i,o.left+=i)}get width(){return this._width}set width(t){const i=t-this._width;this._width=t;const[n,s,o,h]=this.getChildren();if(h&&s){const a=h.width+s.width,l=i*(h.width/a),c=a+i;let d=h.width+l,u=c-d,g=s.left+l;const w=h.calcMinWidth(),m=s.calcMinWidth();d<w&&u>m?(d=w,u=c-d,g=h.left+d):u<m&&d>w&&(u=m,d=c-u,g=h.left+d),h.width=d,s.width=u,s.left=g}n&&o&&(n.width+=i,o.width+=i)}get height(){return this._height}set height(t){const i=t-this._height;this._height=t;const[n,s,o,h]=this.getChildren();if(n&&o){const a=n.height+o.height,l=i*(n.height/a),c=a+i;let d=n.height+l,u=c-d,g=o.top+l;const w=n.calcMinHeight(),m=o.calcMinHeight();d<w&&u>m?(d=w,u=c-d,g=n.top+d):u<m&&d>w&&(u=m,d=c-u,g=n.top+d),n.height=d,o.height=u,o.top=g}h&&s&&(h.height+=i,s.height+=i)}}const L={size:"50%",position:r.Left};class x{constructor({parentRect:t,children:i,siblingConfigNode:n,id:s,minWidth:o,minHeight:h,position:a,size:l,...c}){b(this,"left"),b(this,"top"),b(this,"width"),b(this,"height"),this.parentRect=t,this.children=i,this.siblingConfigNode=n,this.id=s,this.minWidth=o,this.minHeight=h,this.position=this.getPosition(a),this.size=this.getSize(l),this.nonCoreData=c,this.setBounds()}getPosition(t){if(!this.siblingConfigNode)return t;const i=X(this.siblingConfigNode.position);if(!t)return i;if(t!==i)throw new Error("[bwin] Sibling position and current position are not opposite");return t}getSize(t){if(!this.siblingConfigNode)return z(t);if(!t){if(this.siblingConfigNode.size<1)return 1-this.siblingConfigNode.size;if(this.siblingConfigNode.position===r.Left||this.siblingConfigNode.position===r.Right)return this.parentRect.width-this.siblingConfigNode.width;if(this.siblingConfigNode.position===r.Top||this.siblingConfigNode.position===r.Bottom)return this.parentRect.height-this.siblingConfigNode.height}const i=z(t);if(i<1){if(i+this.siblingConfigNode.size!==1)throw new Error("[bwin] Sum of sibling sizes is not equal to 1")}else{if((this.position===r.Left||this.position===r.Right)&&i+this.siblingConfigNode.size!==this.parentRect.width)throw new Error("[bwin] Sum of sibling sizes is not equal to parent width");if((this.position===r.Top||this.position===r.Bottom)&&i+this.siblingConfigNode.size!==this.parentRect.height)throw new Error("[bwin] Sum of sibling sizes is not equal to parent height")}return i}setBounds(){if(this.position===r.Root)this.left=0,this.top=0,this.width=this.parentRect.width,this.height=this.parentRect.height;else if(this.position===r.Left){const t=this.size<1?this.parentRect.width*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top,this.width=t,this.height=this.parentRect.height}else if(this.position===r.Right){const t=this.size<1?this.parentRect.width*this.size:this.size;this.left=this.parentRect.left+this.parentRect.width-t,this.top=this.parentRect.top,this.width=t,this.height=this.parentRect.height}else if(this.position===r.Top){const t=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=t}else if(this.position===r.Bottom){const t=this.size<1?this.parentRect.height*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top+this.parentRect.height-t,this.width=this.parentRect.width,this.height=t}}createSash(){return new f({left:this.left,top:this.top,width:this.width,height:this.height,position:this.position,id:this.id,minWidth:this.minWidth,minHeight:this.minHeight,store:this.nonCoreData})}normConfig(t){if(q(t))return t;if(Array.isArray(t))return{children:t};if(typeof t=="string"||typeof t=="number"){const i=z(t);if(isNaN(i))throw new Error(`[bwin] Invalid size value: ${i}`);return{size:t}}else{if(t==null)return{};throw new Error(`[bwin] Invalid config value: ${t}`)}}createPrimaryConfigNode({size:t,position:i,children:n,id:s,minWidth:o,minHeight:h,...a}){return new x({parentRect:this,size:t??L.size,position:i??L.position,children:n,id:s,minWidth:o,minHeight:h,...a})}createSecondaryConfigNode({size:t,position:i,children:n,id:s,minWidth:o,minHeight:h,...a},l){return new x({parentRect:this,size:t,position:i,children:n,siblingConfigNode:l,id:s,minWidth:o,minHeight:h,...a})}buildSashTree(){const t=this.createSash();if(!Array.isArray(this.children)||this.children.length===0)return t;const i=this.normConfig(this.children[0]),n=this.normConfig(this.children.at(1));let s,o;return!i.size&&!i.position&&n?(n.position||(n.position=r.Right),s=this.createPrimaryConfigNode(n),o=this.createSecondaryConfigNode(i,s)):(s=this.createPrimaryConfigNode(i),o=this.createSecondaryConfigNode(n,s)),s&&o&&(t.children.push(s.buildSashTree()),t.children.push(o.buildSashTree())),t}}const R={width:333,height:333},$={fitContainer:!1};class et extends x{constructor({id:t,children:i,width:n=R.width,height:s=R.height,fitContainer:o=$.fitContainer,...h}={...R,...$}){super({id:t,children:i,size:NaN,position:r.Root,parentRect:{width:n,height:s},...h}),this.fitContainer=o}}class it extends f{constructor(t=E){super({...t,position:r.Root}),Object.assign(this,$)}}function S(e){const 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 nt(e){const 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 st(e,{size:t}){const i=z(t);let n=e.width/2;i&&(i<1?n=e.width*i:n=i);const s=new f({top:e.top,left:e.left,width:n,height:e.height,position:r.Left}),o=new f({top:e.top,left:e.left+s.width,width:e.width-n,height:e.height,position:r.Right}),h=S(o);return o.domNode=h,N(h,e.domNode),e.addChild(s),e.addChild(o),s}function ot(e,{size:t}){const i=z(t);let n=e.width/2;i&&(i<1?n=e.width*i:n=i);const s=new f({left:e.left,top:e.top,width:e.width-n,height:e.height,position:r.Left}),o=new f({left:e.left+s.width,top:e.top,width:n,height:e.height,position:r.Right}),h=S(s);return s.domNode=h,N(h,e.domNode),e.addChild(s),e.addChild(o),o}function ht(e,{size:t}){const i=z(t);let n=e.height/2;i&&(i<1?n=e.height*i:n=i);const s=new f({left:e.left,top:e.top,width:e.width,height:n,position:r.Top}),o=new f({left:e.left,top:e.top+s.height,width:e.width,height:e.height-n,position:r.Bottom}),h=S(o);return o.domNode=h,N(h,e.domNode),e.addChild(s),e.addChild(o),s}function rt(e,{size:t}){const i=z(t);let n=e.height/2;i&&(i<1?n=e.height*i:n=i);const s=new f({top:e.top,left:e.left,width:e.width,height:e.height-n,position:r.Top}),o=new f({top:e.top+s.height,left:e.left,width:e.width,height:n,position:r.Bottom}),h=S(s);return s.domNode=h,N(h,e.domNode),e.addChild(s),e.addChild(o),o}function at(e,{position:t,size:i,minWidth:n,minHeight:s}){if(t===r.Left)return st(e,{size:i});if(t===r.Right)return ot(e,{size:i});if(t===r.Top)return ht(e,{size:i});if(t===r.Bottom)return rt(e,{size:i})}const lt={createPane(e){const t=S(e);return e.store.droppable===!1&&t.setAttribute("can-drop","false"),t},onPaneCreate(e,t){t.store.content&&e.append(C(t.store.content)),this!=null&&this.debug&&(e.style.backgroundColor=F(),e.innerHTML="",e.append(T(e)))},updatePane(e){return nt(e)},onPaneUpdate(e,t){this!=null&&this.debug&&(e.innerHTML="",e.append(T(e)))},addPane(e,{position:t,size:i}){if(!t)throw new Error("[bwin] Position is required when adding pane");const n=this.rootSash.getById(e);if(!n)throw new Error("[bwin] Parent sash not found when adding pane");const s=at(n,{position:t,size:i});return n.id=D(),this.update(),s},removePane(e){const t=this.rootSash.getDescendantParentById(e);if(!t)throw new Error("[bwin] Parent sash not found when removing pane");const i=t.getChildSiblingById(e);t.id=D(),i.children.length===0?(t.domNode=i.domNode,t.domNode.setAttribute("sash-id",t.id),t.children=[]):(t.children=i.children,i.position===r.Left?i.width=t.width:i.position===r.Right?(i.width=t.width,i.left=t.left):i.position===r.Top?i.height=t.height:i.position===r.Bottom&&(i.height=t.height,i.top=t.top)),this.update()}};function T(e){const t=document.createElement("pre");t.style.fontSize="10px";const i=`
1
+ (function(y,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],p):(y=typeof globalThis<"u"?globalThis:y||self,p(y.ReactBinaryWindow={},y.React))})(this,function(y,p){"use strict";var I=Object.defineProperty,k=(e,t,i)=>t in e?I(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,b=(e,t,i)=>k(e,typeof t!="symbol"?t+"":t,i);function F(e=.7,t=128){const i=256-t,n=Math.floor(Math.random()*i+t),s=Math.floor(Math.random()*i+t),o=Math.floor(Math.random()*i+t),h=Math.max(.5,Math.random()*e);return`rgba(${n}, ${s}, ${o}, ${h})`}function D(e=2,t=3){if(e<0||t<0)throw new Error("Parameters must be non-negative numbers");const i="ABCDEFGHIJKLMNOPQRSTUVWXYZ",n="0123456789";let s="";for(let o=0;o<e;o++){const h=Math.floor(Math.random()*i.length);s+=i[h]}s+="-";for(let o=0;o<t;o++){const h=Math.floor(Math.random()*n.length);s+=n[h]}return s}function N(e,t){for(;t.firstChild;)e.append(t.firstChild)}function _(e,t){const i=document.createElement("div");N(i,e),N(e,t),N(t,i)}function z(e){if(typeof e=="number"&&!isNaN(e))return e;if(typeof e=="string"){const t=e.trim();if(t.endsWith("%")){const i=t.slice(0,-1);if(!i)return NaN;const n=Number(i);return isNaN(n)?NaN:n/100}if(t.endsWith("px")){const i=t.slice(0,-2);if(!i)return NaN;const n=Number(i);return isNaN(n)?NaN:n}return Number(t)}return NaN}function q(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)&&Object.getPrototypeOf(e)===Object.prototype}function U(e,t){for(const i in t){if(Object.hasOwn(e,i))throw new Error(`Key "${i}" already exists in target object`);e[i]=t[i]}return e}function j(e){const t=document.createElement("template");return t.innerHTML=e.trim(),t.content}function C(e){if(e==null||e==="")return null;if(typeof e=="string")try{const t=j(e);return t.childNodes.length===1?t.firstChild:t}catch{return document.createTextNode(e)}return e instanceof Node?e:document.createTextNode(String(e))}function M(e){const t=parseFloat(e.style.left)||0,i=parseFloat(e.style.top)||0,n=parseFloat(e.style.width)||0,s=parseFloat(e.style.height)||0;return{left:t,top:i,width:n,height:s}}const r={Top:"top",Right:"right",Bottom:"bottom",Left:"left",Center:"center",Root:"root",Unknown:"unknown",Outside:"outside"};function X(e){switch(e){case r.Top:return r.Bottom;case r.Right:return r.Left;case r.Bottom:return r.Top;case r.Left:return r.Right;default:throw new Error(`[bwin] Invalid position: ${e}`)}}function Y({width:e,height:t,x:i}){return t/e*i}function K({width:e,height:t,y:i}){return e/t*i}function V({width:e,height:t,x:i}){return t-t/e*i}function Z({width:e,height:t,y:i}){return e-e/t*i}function J(e,{clientX:t,clientY:i}){const n=e.getBoundingClientRect(),{width:s,height:o}=n,h=t-n.left,a=i-n.top;if(h<0||h>s||a<0||a>o)return r.Outside;const d=.3,l=Y({width:s,height:o,x:h}),c=V({width:s,height:o,x:h}),u=K({width:s,height:o,y:a}),g=Z({width:s,height:o,y:a});return h<s*(.5-d/2)&&a>l&&a<c?r.Left:h>s*(.5+d/2)&&a<l&&a>c?r.Right:a<o*(.5-d/2)&&h>u&&h<g?r.Top:a>o*(.5+d/2)&&h<u&&h>g?r.Bottom:h>s*(.5-d/2)&&h<s*(.5+d/2)&&a>o*(.5-d/2)&&a<o*(.5+d/2)?r.Center:r.Unknown}const Q=100,tt=100,E={left:0,top:0,width:150,height:150,minWidth:Q,minHeight:tt};class f{constructor({left:t=E.left,top:i=E.top,width:n=E.width,height:s=E.height,minWidth:o=E.minWidth,minHeight:h=E.minHeight,domNode:a=null,store:d={},position:l,id:c}=E){if(this.id=c??D(),!l)throw new Error("[bwin] Sash position is required");this.position=l,this.domNode=a,this._top=i,this._left=t,this._width=n,this._height=s,this.children=[],this.minWidth=o,this.minHeight=h,this.store=d}walk(t){this.children.forEach(i=>i.walk(t)),t(this)}isLeaf(){return this.children.length===0}isSplit(){return this.children.length>0}isLeftRightSplit(){return this.children.some(t=>t.position===r.Left||t.position===r.Right)}isTopBottomSplit(){return this.children.some(t=>t.position===r.Top||t.position===r.Bottom)}get leftChild(){return this.children.find(t=>t.position===r.Left)}get rightChild(){return this.children.find(t=>t.position===r.Right)}get topChild(){return this.children.find(t=>t.position===r.Top)}get bottomChild(){return this.children.find(t=>t.position===r.Bottom)}getChildren(){let t=null,i=null,n=null,s=null;for(const o of this.children)o.position===r.Left?t=o:o.position===r.Right?i=o:o.position===r.Top?n=o:o.position===r.Bottom&&(s=o);return[n,i,s,t]}getAllLeafDescendants(){const t=[];return this.walk(i=>{i.children.length===0&&t.push(i)}),t}calcMinWidth(){if(this.isLeaf())return this.minWidth;const[t,i,n,s]=this.getChildren();if(s&&i){const o=s.calcMinWidth()+i.calcMinWidth();return Math.max(this.minWidth,o)}if(t&&n){const o=Math.max(t.calcMinWidth(),n.calcMinWidth());return Math.max(this.minWidth,o)}}calcMinHeight(){if(this.isLeaf())return this.minHeight;const[t,i,n,s]=this.getChildren();if(s&&i){const o=Math.max(s.calcMinHeight(),i.calcMinHeight());return Math.max(this.minHeight,o)}if(t&&n){const o=t.calcMinHeight()+n.calcMinHeight();return Math.max(this.minHeight,o)}}getById(t){if(this.id===t)return this;for(const i of this.children){const n=i.getById(t);if(n)return n}return null}getAllIds(){const t=[this.id];for(const i of this.children)t.push(...i.getAllIds());return t}addChild(t){if(this.children.length>=2)throw new Error("[bwin] Maximum 2 children allowed");this.children.push(t)}getDescendantParentById(t){for(const i of this.children){if(i.id===t)return this;const n=i.getDescendantParentById(t);if(n)return n}return null}getChildSiblingById(t){return this.children.find(i=>i.id!==t)}get top(){return this._top}set top(t){const i=t-this._top;this._top=t;const[n,s,o,h]=this.getChildren();n&&o&&(n.top+=i,o.top+=i),h&&s&&(h.top+=i,s.top+=i)}get left(){return this._left}set left(t){const i=t-this._left;this._left=t;const[n,s,o,h]=this.getChildren();h&&s&&(h.left+=i,s.left+=i),n&&o&&(n.left+=i,o.left+=i)}get width(){return this._width}set width(t){const i=t-this._width;this._width=t;const[n,s,o,h]=this.getChildren();if(h&&s){const a=h.width+s.width,d=i*(h.width/a),l=a+i;let c=h.width+d,u=l-c,g=s.left+d;const w=h.calcMinWidth(),m=s.calcMinWidth();c<w&&u>m?(c=w,u=l-c,g=h.left+c):u<m&&c>w&&(u=m,c=l-u,g=h.left+c),h.width=c,s.width=u,s.left=g}n&&o&&(n.width+=i,o.width+=i)}get height(){return this._height}set height(t){const i=t-this._height;this._height=t;const[n,s,o,h]=this.getChildren();if(n&&o){const a=n.height+o.height,d=i*(n.height/a),l=a+i;let c=n.height+d,u=l-c,g=o.top+d;const w=n.calcMinHeight(),m=o.calcMinHeight();c<w&&u>m?(c=w,u=l-c,g=n.top+c):u<m&&c>w&&(u=m,c=l-u,g=n.top+c),n.height=c,o.height=u,o.top=g}h&&s&&(h.height+=i,s.height+=i)}}const L={size:"50%",position:r.Left};class P{constructor({parentRect:t,children:i,siblingConfigNode:n,id:s,minWidth:o,minHeight:h,position:a,size:d,...l}){b(this,"left"),b(this,"top"),b(this,"width"),b(this,"height"),this.parentRect=t,this.children=i,this.siblingConfigNode=n,this.id=s,this.minWidth=o,this.minHeight=h,this.position=this.getPosition(a),this.size=this.getSize(d),this.nonCoreData=l,this.setBounds()}getPosition(t){if(!this.siblingConfigNode)return t;const i=X(this.siblingConfigNode.position);if(!t)return i;if(t!==i)throw new Error("[bwin] Sibling position and current position are not opposite");return t}getSize(t){if(!this.siblingConfigNode)return z(t);if(!t){if(this.siblingConfigNode.size<1)return 1-this.siblingConfigNode.size;if(this.siblingConfigNode.position===r.Left||this.siblingConfigNode.position===r.Right)return this.parentRect.width-this.siblingConfigNode.width;if(this.siblingConfigNode.position===r.Top||this.siblingConfigNode.position===r.Bottom)return this.parentRect.height-this.siblingConfigNode.height}const i=z(t);if(i<1){if(i+this.siblingConfigNode.size!==1)throw new Error("[bwin] Sum of sibling sizes is not equal to 1")}else{if((this.position===r.Left||this.position===r.Right)&&i+this.siblingConfigNode.size!==this.parentRect.width)throw new Error("[bwin] Sum of sibling sizes is not equal to parent width");if((this.position===r.Top||this.position===r.Bottom)&&i+this.siblingConfigNode.size!==this.parentRect.height)throw new Error("[bwin] Sum of sibling sizes is not equal to parent height")}return i}setBounds(){if(this.position===r.Root)this.left=0,this.top=0,this.width=this.parentRect.width,this.height=this.parentRect.height;else if(this.position===r.Left){const t=this.size<1?this.parentRect.width*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top,this.width=t,this.height=this.parentRect.height}else if(this.position===r.Right){const t=this.size<1?this.parentRect.width*this.size:this.size;this.left=this.parentRect.left+this.parentRect.width-t,this.top=this.parentRect.top,this.width=t,this.height=this.parentRect.height}else if(this.position===r.Top){const t=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=t}else if(this.position===r.Bottom){const t=this.size<1?this.parentRect.height*this.size:this.size;this.left=this.parentRect.left,this.top=this.parentRect.top+this.parentRect.height-t,this.width=this.parentRect.width,this.height=t}}createSash(){return new f({left:this.left,top:this.top,width:this.width,height:this.height,position:this.position,id:this.id,minWidth:this.minWidth,minHeight:this.minHeight,store:this.nonCoreData})}normConfig(t){if(q(t))return t;if(Array.isArray(t))return{children:t};if(typeof t=="string"||typeof t=="number"){const i=z(t);if(isNaN(i))throw new Error(`[bwin] Invalid size value: ${i}`);return{size:t}}else{if(t==null)return{};throw new Error(`[bwin] Invalid config value: ${t}`)}}createPrimaryConfigNode({size:t,position:i,children:n,id:s,minWidth:o,minHeight:h,...a}){return new P({parentRect:this,size:t??L.size,position:i??L.position,children:n,id:s,minWidth:o,minHeight:h,...a})}createSecondaryConfigNode({size:t,position:i,children:n,id:s,minWidth:o,minHeight:h,...a},d){return new P({parentRect:this,size:t,position:i,children:n,siblingConfigNode:d,id:s,minWidth:o,minHeight:h,...a})}buildSashTree(){const t=this.createSash();if(!Array.isArray(this.children)||this.children.length===0)return t;const i=this.normConfig(this.children[0]),n=this.normConfig(this.children.at(1));let s,o;return!i.size&&!i.position&&n?(n.position||(n.position=r.Right),s=this.createPrimaryConfigNode(n),o=this.createSecondaryConfigNode(i,s)):(s=this.createPrimaryConfigNode(i),o=this.createSecondaryConfigNode(n,s)),s&&o&&(t.children.push(s.buildSashTree()),t.children.push(o.buildSashTree())),t}}const R={width:333,height:333},$={fitContainer:!1};class et extends P{constructor({id:t,children:i,width:n=R.width,height:s=R.height,fitContainer:o=$.fitContainer,...h}={...R,...$}){super({id:t,children:i,size:NaN,position:r.Root,parentRect:{width:n,height:s},...h}),this.fitContainer=o}}class it extends f{constructor(t=E){super({...t,position:r.Root}),Object.assign(this,$)}}function S(e){const 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 nt(e){const 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 st(e,{size:t}){const i=z(t);let n=e.width/2;i&&(i<1?n=e.width*i:n=i);const s=new f({top:e.top,left:e.left,width:n,height:e.height,position:r.Left}),o=new f({top:e.top,left:e.left+s.width,width:e.width-n,height:e.height,position:r.Right}),h=S(o);return o.domNode=h,N(h,e.domNode),e.addChild(s),e.addChild(o),s}function ot(e,{size:t}){const i=z(t);let n=e.width/2;i&&(i<1?n=e.width*i:n=i);const s=new f({left:e.left,top:e.top,width:e.width-n,height:e.height,position:r.Left}),o=new f({left:e.left+s.width,top:e.top,width:n,height:e.height,position:r.Right}),h=S(s);return s.domNode=h,N(h,e.domNode),e.addChild(s),e.addChild(o),o}function ht(e,{size:t}){const i=z(t);let n=e.height/2;i&&(i<1?n=e.height*i:n=i);const s=new f({left:e.left,top:e.top,width:e.width,height:n,position:r.Top}),o=new f({left:e.left,top:e.top+s.height,width:e.width,height:e.height-n,position:r.Bottom}),h=S(o);return o.domNode=h,N(h,e.domNode),e.addChild(s),e.addChild(o),s}function rt(e,{size:t}){const i=z(t);let n=e.height/2;i&&(i<1?n=e.height*i:n=i);const s=new f({top:e.top,left:e.left,width:e.width,height:e.height-n,position:r.Top}),o=new f({top:e.top+s.height,left:e.left,width:e.width,height:n,position:r.Bottom}),h=S(s);return s.domNode=h,N(h,e.domNode),e.addChild(s),e.addChild(o),o}function at(e,{position:t,size:i,minWidth:n,minHeight:s}){if(t===r.Left)return st(e,{size:i});if(t===r.Right)return ot(e,{size:i});if(t===r.Top)return ht(e,{size:i});if(t===r.Bottom)return rt(e,{size:i})}const lt={createPane(e){const t=S(e);return e.store.droppable===!1&&t.setAttribute("can-drop","false"),t},onPaneCreate(e,t){t.store.content&&e.append(C(t.store.content)),this!=null&&this.debug&&(e.style.backgroundColor=F(),e.innerHTML="",e.append(T(e)))},updatePane(e){return nt(e)},onPaneUpdate(e,t){this!=null&&this.debug&&(e.innerHTML="",e.append(T(e)))},addPane(e,{position:t,size:i}){if(!t)throw new Error("[bwin] Position is required when adding pane");const n=this.rootSash.getById(e);if(!n)throw new Error("[bwin] Parent sash not found when adding pane");const s=at(n,{position:t,size:i});return n.id=D(),this.update(),s},removePane(e){const t=this.rootSash.getDescendantParentById(e);if(!t)throw new Error("[bwin] Parent sash not found when removing pane");const i=t.getChildSiblingById(e);t.id=D(),i.children.length===0?(t.domNode=i.domNode,t.domNode.setAttribute("sash-id",t.id),t.children=[]):(t.children=i.children,i.position===r.Left?i.width=t.width:i.position===r.Right?(i.width=t.width,i.left=t.left):i.position===r.Top?i.height=t.height:i.position===r.Bottom&&(i.height=t.height,i.top=t.top)),this.update()}};function T(e){const t=document.createElement("pre");t.style.fontSize="10px";const i=`
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
- `;return t.innerHTML=i.trim(),t}const dt={createWindow(){const e=document.createElement("bw-window");return e.style.width=`${this.rootSash.width}px`,e.style.height=`${this.rootSash.height}px`,e.setAttribute("sash-id",this.rootSash.id),e},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`;const e=this.rootSash.getAllIds(),t=[];this.windowElement.querySelectorAll("[sash-id]").forEach(i=>{const n=i.getAttribute("sash-id");t.push(n),e.includes(n)||i.remove()}),this.rootSash.walk(i=>{i.children.length>0?t.includes(i.id)?(this.updateMuntin(i),this.onMuntinUpdate(i.domNode,i)):(i.domNode=this.createMuntin(i),this.windowElement.append(i.domNode)):t.includes(i.id)?(this.updatePane(i),this.onPaneUpdate(i.domNode,i)):(i.domNode||(i.domNode=this.createPane(i)),this.windowElement.prepend(i.domNode))})}},ct={muntinSize:4,createMuntin(e){const t=document.createElement("bw-muntin"),i=e.leftChild,n=e.topChild;return i?(t.style.width=`${this.muntinSize}px`,t.style.height=`${e.height}px`,t.style.top=`${e.top}px`,t.style.left=`${e.left+i.width-this.muntinSize/2}px`,t.setAttribute("vertical","")):n&&(t.style.width=`${e.width}px`,t.style.height=`${this.muntinSize}px`,t.style.top=`${e.top+n.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){const t=e.domNode,i=e.leftChild,n=e.topChild;i?(t.style.height=`${e.height}px`,t.style.top=`${e.top}px`,t.style.left=`${e.left+i.width-this.muntinSize/2}px`):n&&(t.style.width=`${e.width}px`,t.style.top=`${e.top+n.height-this.muntinSize/2}px`,t.style.left=`${e.left}px`)},onMuntinUpdate(e,t){}},pt={fitContainer:!1,enableFitContainer(){new ResizeObserver(e=>{for(const t of e)t.target===this.containerElement&&this.fitContainer&&(this.rootSash.width=t.contentRect.width,this.rootSash.height=t.contentRect.height,this.update())}).observe(this.containerElement)}},ut={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;const 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;const[t,i,n,s]=this.activeMuntinSash.getChildren(),o=this.activeMuntinSash.isLeftRightSplit(),h=this.activeMuntinSash.isTopBottomSplit();if(o&&s&&i){const a=e.pageX-this.lastX,l=s.width+a,c=i.width-a;if(l<=s.calcMinWidth()||c<=i.calcMinWidth())return;s.width=l,i.width=c,i.left=i.left+a,this.update(),this.lastX=e.pageX}else if(h&&t&&n){const a=e.pageY-this.lastY,l=t.height+a,c=n.height-a;if(l<=t.calcMinHeight()||c<=n.calcMinHeight())return;t.height=l,n.height=c,n.top=n.top+a,this.update(),this.lastY=e.pageY}}),document.addEventListener("mouseup",()=>{this.isResizeStarted=!1,this.activeMuntinSash=null,this.revertResizeStyles()})}},gt={activeDropPaneEl:null,onPaneDrop(e,t){},enableDrop(){this.windowElement.addEventListener("dragover",e=>{e.preventDefault();const 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;const i=J(t,e);t.setAttribute("drop-area",i)}),this.windowElement.addEventListener("dragleave",e=>{e.currentTarget.contains(e.relatedTarget)&&e.currentTarget!==e.relatedTarget||this.activeDropPaneEl&&(this.activeDropPaneEl.removeAttribute("drop-area"),this.activeDropPaneEl=null)}),this.windowElement.addEventListener("drop",e=>{if(!this.activeDropPaneEl||this.activeDropPaneEl.getAttribute("can-drop")==="false")return;const t=this.activeDropPaneEl.getAttribute("sash-id"),i=this.rootSash.getById(t);this.onPaneDrop(e,i),typeof i.store.onDrop=="function"&&i.store.onDrop(e,i),this.activeDropPaneEl.removeAttribute("drop-area"),this.activeDropPaneEl=null})}},ft=!1;class W{constructor(t){b(this,"windowElement",null),b(this,"containerElement",null),b(this,"debug",ft);let i=null;t instanceof it?(i=t,this.rootSash=t):(i=new et(t),this.rootSash=i.buildSashTree()),this.fitContainer=i.fitContainer}frame(t){this.containerElement=t,this.windowElement=this.createWindow(),this.glaze(),this.containerElement.append(this.windowElement)}enableFeatures(){this.enableResize(),this.enableDrop(),this.fitContainer&&this.enableFitContainer()}mount(t){this.frame(t),this.enableFeatures()}static assemble(...t){t.forEach(i=>{U(this.prototype,i)})}}W.assemble(dt,ct,lt,pt,gt,ut);function H(e){if(e.tagName==="BW-PANE")return e.getAttribute("sash-id");const t=e.closest("bw-pane");if(!t)throw new Error("[bwin] Pane element not found");return t.getAttribute("sash-id")}const wt={label:"",className:"bw-glass-action--close",onClick:(e,t)=>{const i=H(e.target);t.removePane(i)}},mt={label:"",className:"bw-glass-action--minimize",onClick:(e,t)=>{const i=t.sillElement;if(!i)throw new Error("[bwin] Sill element not found when minimizing");const n=C('<button class="bw-minimized-glass" />');i.append(n);const s=e.target.closest("bw-pane"),o=e.target.closest("bw-glass"),h=s.getAttribute("sash-id"),a=s.getAttribute("position");n.bwGlassElement=o,n.bwOriginalPosition=a,n.bwOriginalBoundingRect=M(s),t.removePane(h)}},bt={label:"",className:"bw-glass-action--maximize",onClick:e=>{const 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=M(t),t.style.left="0",t.style.top="0",t.style.width="100%",t.style.height="100%")}};function yt(e,t){const i=e.left+e.width,n=e.top+e.height,s=t.left+t.width,o=t.top+t.height;if(e.left>=s||t.left>=i||e.top>=o||t.top>=n)return null;const h=Math.max(e.left,t.left),a=Math.max(e.top,t.top),l=Math.min(i,s),c=Math.min(n,o);return{left:h,top:a,width:l-h,height:c-a}}const B=[mt,bt,wt],Et={enableActions(){this.handleMinimizedGlassClick(),this.observeActionButtons()},restoreGlass(e){const t=e.bwOriginalBoundingRect;let i=0,n=null;if(this.windowElement.querySelectorAll("bw-pane").forEach(s=>{const o=M(s),h=yt(t,o);if(h){const a=h.width*h.height;a>i&&(i=a,n=s)}}),n){const s=e.bwOriginalPosition,o=M(n);let h=0;if(s===r.Left||s===r.Right)h=t.width>=o.width?o.width/2:t.width;else if(s===r.Top||s===r.Bottom)h=t.height>=o.height?o.height/2:t.height;else throw new Error("[bwin] Invalid position when restoring glass");this.addPane(n.getAttribute("sash-id"),{position:s,size:h}).domNode.append(e.bwGlassElement)}},handleMinimizedGlassClick(){this.sillElement.addEventListener("click",e=>{if(!e.target.matches(".bw-minimized-glass"))return;const 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){const t=this.windowElement.querySelector(e);t&&t.setAttribute("disabled","")}else this.windowElement.querySelectorAll(e).forEach(t=>{t.removeAttribute("disabled")})},observeActionButtons(){this.updateDisabledStateOfActionButtons(),new MutationObserver(e=>{e.forEach(t=>{t.type==="childList"&&this.updateDisabledStateOfActionButtons()})}).observe(this.windowElement,{childList:!0})}},A={title:null,content:null,tabs:[],actions:void 0,draggable:!0};class G{constructor({title:t=A.title,content:i=A.content,tabs:n=A.tabs,actions:s=A.actions,draggable:o=A.draggable,sash:h,binaryWindow:a}){b(this,"domNode"),this.title=t,this.content=i,this.tabs=n,this.actions=s,this.sash=h,this.draggable=o,this.binaryWindow=a,this.build()}build(){const t=document.createElement("bw-glass-header");if(Array.isArray(this.tabs)&&this.tabs.length>0)t.append(this.createTabs());else if(this.title){const s=document.createElement("bw-glass-title");s.append(C(this.title)),t.append(s)}t.setAttribute("can-drag",this.draggable),t.append(this.createActions());const i=document.createElement("bw-glass-content"),n=C(this.content);n&&i.append(n),this.domNode=document.createElement("bw-glass"),this.domNode.append(t,i)}createTabs(){const t=document.createElement("bw-glass-tab-container");for(const i of this.tabs){const n=(i==null?void 0:i.label)??i,s=C(`<button class="bw-glass-tab">${n}</button>`);t.append(s)}return t}createActions(){const t=document.createElement("bw-glass-action-container"),i=this.actions===void 0?B:Array.isArray(this.actions)?this.actions:[];for(const n of i){const s=(n==null?void 0:n.label)??n,o=n.className?`bw-glass-action ${n.className}`:"bw-glass-action",h=C(`<button class="${o}">${s}</button>`);typeof n.onClick=="function"&&h.addEventListener("click",a=>{n.onClick(a,this.binaryWindow)}),t.append(h)}return t}get contentElement(){return this.domNode.querySelector("bw-glass-content")}get headerElement(){return this.domNode.querySelector("bw-glass-header")}}const vt={activeDragGlassEl:null,activeDragGlassPaneCanDrop:!1,onPaneDrop(e,t){if(!this.activeDragGlassEl)return;const i=this.activeDropPaneEl.getAttribute("drop-area");if(i==="center"){const n=this.activeDragGlassEl.closest("bw-pane"),s=this.activeDropPaneEl.getAttribute("can-drop")!=="false";_(n,this.activeDropPaneEl),n.setAttribute("can-drop",s);return}else{const n=H(this.activeDragGlassEl);this.addPane(t.id,{position:i}).domNode.append(this.activeDragGlassEl),this.removePane(n)}},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}const t=e.target.closest("bw-glass");t.setAttribute("draggable",!0),this.activeDragGlassEl=t}),document.addEventListener("mouseup",()=>{this.activeDragGlassEl&&(this.activeDragGlassEl.removeAttribute("draggable"),this.activeDragGlassEl=null)}),this.windowElement.addEventListener("dragstart",e=>{if(!(e.target instanceof HTMLElement)||!e.target.matches("bw-glass")||!this.activeDragGlassEl)return;e.dataTransfer.effectAllowed="move";const 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),this.activeDragGlassEl=null)})}},Nt={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)}};class O extends W{constructor(){super(...arguments),b(this,"sillElement",null)}frame(){super.frame(...arguments);const t=C("<bw-sill />");this.windowElement.append(t),this.sillElement=t}enableFeatures(){super.enableFeatures(),this.enableDrag(),this.enableActions()}onPaneCreate(t,i){const n=new G({...i.store,sash:i,binaryWindow:this});t.innerHTML="",t.append(n.domNode),this.debug&&n.contentElement.prepend(`${i.id}`)}onPaneUpdate(){}addGlass(t,i,n){const s=this.addPane(t,{position:i}),o=new G({...n,sash:s,binaryWindow:this});s.domNode.append(o.domNode)}removeGlass(t,i){if(i)this.removePane(t);else{const n=this.rootSash.getById(t);if(!n)throw new Error("[bwin] Pane not found when removing glass");const s=n.domNode.querySelector("bw-glass");s&&s.remove()}}}O.assemble(vt,Nt,Et);const v=4;function zt({sash:e}){var d;const t=p.useRef(),i=e.leftChild,n=e.topChild;let s,o,h,a,l,c;return i?(s=v,o=e.height-v,h=e.top+v/2,a=e.left+i.width-v/2,l=!0):n&&(s=e.width-v,o=v,h=e.top+n.height-v/2,a=e.left+v/2,c=!0),p.useEffect(()=>{e.domNode=t.current},[]),p.createElement("bw-muntin",{"sash-id":e.id,style:{width:s,height:o,top:h,left:a},vertical:l,horizontal:c,resizable:((d=e.store)==null?void 0:d.resizable)===!1?"false":"true",ref:t})}function Ct({sash:e,bwin:t}){var d,u,g,w,m;const i=p.useRef(),{left:n,top:s,width:o,height:h,id:a,position:l}=e;p.useEffect(()=>{e.domNode=i.current},[]);const c=((d=e.store)==null?void 0:d.actions)===void 0?B:Array.isArray(e.store.actions)?e.store.actions:[];return p.createElement("bw-pane",{"sash-id":a,position:l,style:{left:n,top:s,width:o,height:h},"can-drop":((u=e.store)==null?void 0:u.droppable)===!1?"false":"true",ref:i},p.createElement("bw-glass",null,p.createElement("bw-glass-header",{"can-drag":((g=e.store)==null?void 0:g.draggable)===!1?"false":"true"},((w=e.store)==null?void 0:w.title)&&p.createElement("bw-glass-title",null,e.store.title),c.length>0&&p.createElement("bw-glass-action-container",null,c.map((P,At)=>{const Mt=P.className?`bw-glass-action ${P.className}`:"bw-glass-action";return p.createElement("button",{className:Mt,key:At,onClick:xt=>P.onClick(xt,t)},P.label)}))),p.createElement("bw-glass-content",null,(m=e.store)==null?void 0:m.content)))}function St(e){const t=p.useRef(),i=p.useRef(),n=new O(e),s=[],o=[];return n.rootSash.walk(h=>{h.children.length>0?s.push(h):o.push(h)}),p.useEffect(()=>{const h=t.current;h!=null&&h.parentElement&&(n.windowElement=h,n.containerElement=h.parentElement,n.sillElement=i.current,n.enableFeatures())},[]),p.createElement("bw-window",{"sash-id":n.rootSash.id,style:{width:n.rootSash.width,height:n.rootSash.height},ref:t},o.map(h=>p.createElement(Ct,{key:h.id,sash:h,bwin:n})),s.map(h=>p.createElement(zt,{key:h.id,sash:h})),p.createElement("bw-sill",{ref:i}))}y.BUILTIN_ACTIONS=B,y.Window=St,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
8
+ `;return t.innerHTML=i.trim(),t}const dt={createWindow(){const e=document.createElement("bw-window");return e.style.width=`${this.rootSash.width}px`,e.style.height=`${this.rootSash.height}px`,e.setAttribute("sash-id",this.rootSash.id),e},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`;const e=this.rootSash.getAllIds(),t=[];this.windowElement.querySelectorAll("[sash-id]").forEach(i=>{const n=i.getAttribute("sash-id");t.push(n),e.includes(n)||i.remove()}),this.rootSash.walk(i=>{i.children.length>0?t.includes(i.id)?(this.updateMuntin(i),this.onMuntinUpdate(i.domNode,i)):(i.domNode=this.createMuntin(i),this.windowElement.append(i.domNode)):t.includes(i.id)?(this.updatePane(i),this.onPaneUpdate(i.domNode,i)):(i.domNode||(i.domNode=this.createPane(i)),this.windowElement.prepend(i.domNode))})}},ct={muntinSize:4,createMuntin(e){const t=document.createElement("bw-muntin"),i=e.leftChild,n=e.topChild;return i?(t.style.width=`${this.muntinSize}px`,t.style.height=`${e.height}px`,t.style.top=`${e.top}px`,t.style.left=`${e.left+i.width-this.muntinSize/2}px`,t.setAttribute("vertical","")):n&&(t.style.width=`${e.width}px`,t.style.height=`${this.muntinSize}px`,t.style.top=`${e.top+n.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){const t=e.domNode,i=e.leftChild,n=e.topChild;i?(t.style.height=`${e.height}px`,t.style.top=`${e.top}px`,t.style.left=`${e.left+i.width-this.muntinSize/2}px`):n&&(t.style.width=`${e.width}px`,t.style.top=`${e.top+n.height-this.muntinSize/2}px`,t.style.left=`${e.left}px`)},onMuntinUpdate(e,t){}},pt={fitContainer:!1,enableFitContainer(){new ResizeObserver(e=>{for(const t of e)t.target===this.containerElement&&this.fitContainer&&(this.rootSash.width=t.contentRect.width,this.rootSash.height=t.contentRect.height,this.update())}).observe(this.containerElement)}},ut={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;const 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;const[t,i,n,s]=this.activeMuntinSash.getChildren(),o=this.activeMuntinSash.isLeftRightSplit(),h=this.activeMuntinSash.isTopBottomSplit();if(o&&s&&i){const a=e.pageX-this.lastX,d=s.width+a,l=i.width-a;if(d<=s.calcMinWidth()||l<=i.calcMinWidth())return;s.width=d,i.width=l,i.left=i.left+a,this.update(),this.lastX=e.pageX}else if(h&&t&&n){const a=e.pageY-this.lastY,d=t.height+a,l=n.height-a;if(d<=t.calcMinHeight()||l<=n.calcMinHeight())return;t.height=d,n.height=l,n.top=n.top+a,this.update(),this.lastY=e.pageY}}),document.addEventListener("mouseup",()=>{this.isResizeStarted=!1,this.activeMuntinSash=null,this.revertResizeStyles()})}},gt={activeDropPaneEl:null,onPaneDrop(e,t){},enableDrop(){this.windowElement.addEventListener("dragover",e=>{e.preventDefault();const 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;const i=J(t,e);t.setAttribute("drop-area",i)}),this.windowElement.addEventListener("dragleave",e=>{e.currentTarget.contains(e.relatedTarget)&&e.currentTarget!==e.relatedTarget||this.activeDropPaneEl&&(this.activeDropPaneEl.removeAttribute("drop-area"),this.activeDropPaneEl=null)}),this.windowElement.addEventListener("drop",e=>{if(!this.activeDropPaneEl||this.activeDropPaneEl.getAttribute("can-drop")==="false")return;const t=this.activeDropPaneEl.getAttribute("sash-id"),i=this.rootSash.getById(t);this.onPaneDrop(e,i),typeof i.store.onDrop=="function"&&i.store.onDrop(e,i),this.activeDropPaneEl.removeAttribute("drop-area"),this.activeDropPaneEl=null})}},ft=!1;class W{constructor(t){b(this,"windowElement",null),b(this,"containerElement",null),b(this,"debug",ft);let i=null;t instanceof it?(i=t,this.rootSash=t):(i=new et(t),this.rootSash=i.buildSashTree()),this.fitContainer=i.fitContainer}frame(t){this.containerElement=t,this.windowElement=this.createWindow(),this.glaze(),this.containerElement.append(this.windowElement)}enableFeatures(){this.enableResize(),this.enableDrop(),this.fitContainer&&this.enableFitContainer()}mount(t){this.frame(t),this.enableFeatures()}static assemble(...t){t.forEach(i=>{U(this.prototype,i)})}}W.assemble(dt,ct,lt,pt,gt,ut);function H(e){if(e.tagName==="BW-PANE")return e.getAttribute("sash-id");const t=e.closest("bw-pane");if(!t)throw new Error("[bwin] Pane element not found");return t.getAttribute("sash-id")}const wt={label:"",className:"bw-glass-action--close",onClick:(e,t)=>{const i=H(e.target);t.removePane(i)}},mt={label:"",className:"bw-glass-action--minimize",onClick:(e,t)=>{const i=t.sillElement;if(!i)throw new Error("[bwin] Sill element not found when minimizing");const n=C('<button class="bw-minimized-glass" />');i.append(n);const s=e.target.closest("bw-pane"),o=e.target.closest("bw-glass"),h=s.getAttribute("sash-id"),a=s.getAttribute("position");n.bwGlassElement=o,n.bwOriginalPosition=a,n.bwOriginalBoundingRect=M(s),t.removePane(h)}},bt={label:"",className:"bw-glass-action--maximize",onClick:e=>{const 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=M(t),t.style.left="0",t.style.top="0",t.style.width="100%",t.style.height="100%")}};function yt(e,t){const i=e.left+e.width,n=e.top+e.height,s=t.left+t.width,o=t.top+t.height;if(e.left>=s||t.left>=i||e.top>=o||t.top>=n)return null;const h=Math.max(e.left,t.left),a=Math.max(e.top,t.top),d=Math.min(i,s),l=Math.min(n,o);return{left:h,top:a,width:d-h,height:l-a}}const B=[mt,bt,wt],Et={enableActions(){this.handleMinimizedGlassClick(),this.observeActionButtons()},restoreGlass(e){const t=e.bwOriginalBoundingRect;let i=0,n=null;if(this.windowElement.querySelectorAll("bw-pane").forEach(s=>{const o=M(s),h=yt(t,o);if(h){const a=h.width*h.height;a>i&&(i=a,n=s)}}),n){const s=e.bwOriginalPosition,o=M(n);let h=0;if(s===r.Left||s===r.Right)h=t.width>=o.width?o.width/2:t.width;else if(s===r.Top||s===r.Bottom)h=t.height>=o.height?o.height/2:t.height;else throw new Error("[bwin] Invalid position when restoring glass");this.addPane(n.getAttribute("sash-id"),{position:s,size:h}).domNode.append(e.bwGlassElement)}},handleMinimizedGlassClick(){this.sillElement.addEventListener("click",e=>{if(!e.target.matches(".bw-minimized-glass"))return;const 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){const t=this.windowElement.querySelector(e);t&&t.setAttribute("disabled","")}else this.windowElement.querySelectorAll(e).forEach(t=>{t.removeAttribute("disabled")})},observeActionButtons(){this.updateDisabledStateOfActionButtons(),new MutationObserver(e=>{e.forEach(t=>{t.type==="childList"&&this.updateDisabledStateOfActionButtons()})}).observe(this.windowElement,{childList:!0})}},A={title:null,content:null,tabs:[],actions:void 0,draggable:!0};class G{constructor({title:t=A.title,content:i=A.content,tabs:n=A.tabs,actions:s=A.actions,draggable:o=A.draggable,sash:h,binaryWindow:a}){b(this,"domNode"),this.title=t,this.content=i,this.tabs=n,this.actions=s,this.sash=h,this.draggable=o,this.binaryWindow=a,this.build()}build(){const t=document.createElement("bw-glass-header");if(Array.isArray(this.tabs)&&this.tabs.length>0)t.append(this.createTabs());else if(this.title){const s=document.createElement("bw-glass-title");s.append(C(this.title)),t.append(s)}t.setAttribute("can-drag",this.draggable),t.append(this.createActions());const i=document.createElement("bw-glass-content"),n=C(this.content);n&&i.append(n),this.domNode=document.createElement("bw-glass"),this.domNode.append(t,i)}createTabs(){const t=document.createElement("bw-glass-tab-container");for(const i of this.tabs){const n=(i==null?void 0:i.label)??i,s=C(`<button class="bw-glass-tab">${n}</button>`);t.append(s)}return t}createActions(){const t=document.createElement("bw-glass-action-container"),i=this.actions===void 0?B:Array.isArray(this.actions)?this.actions:[];for(const n of i){const s=(n==null?void 0:n.label)??n,o=n.className?`bw-glass-action ${n.className}`:"bw-glass-action",h=C(`<button class="${o}">${s}</button>`);typeof n.onClick=="function"&&h.addEventListener("click",a=>{n.onClick(a,this.binaryWindow)}),t.append(h)}return t}get contentElement(){return this.domNode.querySelector("bw-glass-content")}get headerElement(){return this.domNode.querySelector("bw-glass-header")}}const vt={activeDragGlassEl:null,activeDragGlassPaneCanDrop:!1,onPaneDrop(e,t){if(!this.activeDragGlassEl)return;const i=this.activeDropPaneEl.getAttribute("drop-area");if(i==="center"){const n=this.activeDragGlassEl.closest("bw-pane"),s=this.activeDropPaneEl.getAttribute("can-drop")!=="false";_(n,this.activeDropPaneEl),n.setAttribute("can-drop",s);return}else{const n=H(this.activeDragGlassEl);this.addPane(t.id,{position:i}).domNode.append(this.activeDragGlassEl),this.removePane(n)}},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}const t=e.target.closest("bw-glass");t.setAttribute("draggable",!0),this.activeDragGlassEl=t}),document.addEventListener("mouseup",()=>{this.activeDragGlassEl&&(this.activeDragGlassEl.removeAttribute("draggable"),this.activeDragGlassEl=null)}),this.windowElement.addEventListener("dragstart",e=>{if(!(e.target instanceof HTMLElement)||!e.target.matches("bw-glass")||!this.activeDragGlassEl)return;e.dataTransfer.effectAllowed="move";const 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),this.activeDragGlassEl=null)})}},Nt={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)}};class O extends W{constructor(){super(...arguments),b(this,"sillElement",null)}frame(){super.frame(...arguments);const t=C("<bw-sill />");this.windowElement.append(t),this.sillElement=t}enableFeatures(){super.enableFeatures(),this.enableDrag(),this.enableActions()}onPaneCreate(t,i){const n=new G({...i.store,sash:i,binaryWindow:this});t.innerHTML="",t.append(n.domNode),this.debug&&n.contentElement.prepend(`${i.id}`)}onPaneUpdate(){}addGlass(t,i,n){const s=this.addPane(t,{position:i}),o=new G({...n,sash:s,binaryWindow:this});s.domNode.append(o.domNode)}removeGlass(t,i){if(i)this.removePane(t);else{const n=this.rootSash.getById(t);if(!n)throw new Error("[bwin] Pane not found when removing glass");const s=n.domNode.querySelector("bw-glass");s&&s.remove()}}}O.assemble(vt,Nt,Et);const v=4;function zt({sash:e}){var c;const t=p.useRef(),i=e.leftChild,n=e.topChild;let s,o,h,a,d,l;return i?(s=v,o=e.height-v,h=e.top+v/2,a=e.left+i.width-v/2,d=!0):n&&(s=e.width-v,o=v,h=e.top+n.height-v/2,a=e.left+v/2,l=!0),p.useEffect(()=>{e.domNode=t.current},[]),p.createElement("bw-muntin",{"sash-id":e.id,style:{width:s,height:o,top:h,left:a},vertical:d,horizontal:l,resizable:((c=e.store)==null?void 0:c.resizable)===!1?"false":"true",ref:t})}function Ct({sash:e,bwin:t}){var c,u,g,w,m;const i=p.useRef(),{left:n,top:s,width:o,height:h,id:a,position:d}=e;p.useEffect(()=>{e.domNode=i.current},[]);const l=((c=e.store)==null?void 0:c.actions)===void 0?B:Array.isArray(e.store.actions)?e.store.actions:[];return p.createElement("bw-pane",{"sash-id":a,position:d,style:{left:n,top:s,width:o,height:h},"can-drop":((u=e.store)==null?void 0:u.droppable)===!1?"false":"true",ref:i},p.createElement("bw-glass",null,p.createElement("bw-glass-header",{"can-drag":((g=e.store)==null?void 0:g.draggable)===!1?"false":"true"},((w=e.store)==null?void 0:w.title)&&p.createElement("bw-glass-title",null,e.store.title),l.length>0&&p.createElement("bw-glass-action-container",null,l.map((x,At)=>{const Mt=x.className?`bw-glass-action ${x.className}`:"bw-glass-action";return p.createElement("button",{className:Mt,key:At,onClick:Pt=>x.onClick(Pt,t)},x.label)}))),p.createElement("bw-glass-content",null,(m=e.store)==null?void 0:m.content)))}function St(e){const t=p.useRef(),i=p.useRef(),{panes:n,...s}=e,o={children:n,...s},h=new O(o),a=[],d=[];return h.rootSash.walk(l=>{l.children.length>0?a.push(l):d.push(l)}),p.useEffect(()=>{const l=t.current;l!=null&&l.parentElement&&(h.windowElement=l,h.containerElement=l.parentElement,h.sillElement=i.current,h.enableFeatures())},[]),p.createElement("bw-window",{"sash-id":h.rootSash.id,style:{width:h.rootSash.width,height:h.rootSash.height},ref:t},d.map(l=>p.createElement(Ct,{key:l.id,sash:l,bwin:h})),a.map(l=>p.createElement(zt,{key:l.id,sash:l})),p.createElement("bw-sill",{ref:i}))}y.BUILTIN_ACTIONS=B,y.Window=St,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
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.1.1",
4
+ "version": "0.1.2",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",