bwin 0.2.3 → 0.2.5

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.
Files changed (2) hide show
  1. package/dist/bwin.js +406 -381
  2. package/package.json +1 -1
package/dist/bwin.js CHANGED
@@ -1,18 +1,18 @@
1
- var $ = Object.defineProperty;
2
- var P = (e, t, i) => t in e ? $(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
3
- var f = (e, t, i) => P(e, typeof t != "symbol" ? t + "" : t, i);
4
- function W(e = 0.7, t = 128) {
5
- 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);
1
+ var L = Object.defineProperty;
2
+ var $ = (i, t, e) => t in i ? L(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
+ var f = (i, t, e) => $(i, typeof t != "symbol" ? t + "" : t, e);
4
+ function I(i = 0.7, t = 128) {
5
+ const e = 256 - t, n = Math.floor(Math.random() * e + t), s = Math.floor(Math.random() * e + t), o = Math.floor(Math.random() * e + t), h = Math.max(0.5, Math.random() * i);
6
6
  return `rgba(${n}, ${s}, ${o}, ${h})`;
7
7
  }
8
- function z(e = 2, t = 3) {
9
- if (e < 0 || t < 0)
8
+ function C(i = 2, t = 3) {
9
+ if (i < 0 || t < 0)
10
10
  throw new Error("Parameters must be non-negative numbers");
11
- const i = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", n = "0123456789";
11
+ const e = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", n = "0123456789";
12
12
  let s = "";
13
- for (let o = 0; o < e; o++) {
14
- const h = Math.floor(Math.random() * i.length);
15
- s += i[h];
13
+ for (let o = 0; o < i; o++) {
14
+ const h = Math.floor(Math.random() * e.length);
15
+ s += e[h];
16
16
  }
17
17
  s += "-";
18
18
  for (let o = 0; o < t; o++) {
@@ -21,65 +21,65 @@ function z(e = 2, t = 3) {
21
21
  }
22
22
  return s;
23
23
  }
24
- function b(e, t) {
24
+ function z(i, t) {
25
25
  for (; t.firstChild; )
26
- e.append(t.firstChild);
26
+ i.append(t.firstChild);
27
27
  }
28
- function H(e, t) {
29
- const i = document.createElement("div");
30
- b(i, e), b(e, t), b(t, i);
28
+ function W(i, t) {
29
+ const e = document.createElement("div");
30
+ z(e, i), z(i, t), z(t, e);
31
31
  }
32
- function C(e) {
33
- if (typeof e == "number" && !isNaN(e))
34
- return e;
35
- if (typeof e == "string") {
36
- const t = e.trim();
32
+ function b(i) {
33
+ if (typeof i == "number" && !isNaN(i))
34
+ return i;
35
+ if (typeof i == "string") {
36
+ const t = i.trim();
37
37
  if (t.endsWith("%")) {
38
- const i = t.slice(0, -1);
39
- if (!i) return NaN;
40
- const n = Number(i);
38
+ const e = t.slice(0, -1);
39
+ if (!e) return NaN;
40
+ const n = Number(e);
41
41
  return isNaN(n) ? NaN : n / 100;
42
42
  }
43
43
  if (t.endsWith("px")) {
44
- const i = t.slice(0, -2);
45
- if (!i) return NaN;
46
- const n = Number(i);
44
+ const e = t.slice(0, -2);
45
+ if (!e) return NaN;
46
+ const n = Number(e);
47
47
  return isNaN(n) ? NaN : n;
48
48
  }
49
49
  return Number(t);
50
50
  }
51
51
  return NaN;
52
52
  }
53
- function I(e) {
54
- return e !== null && typeof e == "object" && !Array.isArray(e) && Object.getPrototypeOf(e) === Object.prototype;
53
+ function H(i) {
54
+ return i !== null && typeof i == "object" && !Array.isArray(i) && Object.getPrototypeOf(i) === Object.prototype;
55
55
  }
56
- function O(e, t) {
57
- for (const i in t) {
58
- if (Object.hasOwn(e, i))
59
- throw new Error(`Key "${i}" already exists in target object`);
60
- e[i] = t[i];
56
+ function O(i, t) {
57
+ for (const e in t) {
58
+ if (Object.hasOwn(i, e))
59
+ throw new Error(`Key "${e}" already exists in target object`);
60
+ i[e] = t[e];
61
61
  }
62
- return e;
62
+ return i;
63
63
  }
64
- function G(e) {
64
+ function P(i) {
65
65
  const t = document.createElement("template");
66
- return t.innerHTML = e.trim(), t.content;
66
+ return t.innerHTML = i.trim(), t.content;
67
67
  }
68
- function m(e) {
69
- if (e == null || e === "")
68
+ function m(i) {
69
+ if (i == null || i === "")
70
70
  return null;
71
- if (typeof e == "string")
71
+ if (typeof i == "string")
72
72
  try {
73
- const t = G(e);
73
+ const t = P(i);
74
74
  return t.childNodes.length === 1 ? t.firstChild : t;
75
75
  } catch {
76
- return document.createTextNode(e);
76
+ return document.createTextNode(i);
77
77
  }
78
- return e instanceof Node ? e : document.createTextNode(String(e));
78
+ return i instanceof Node ? i : document.createTextNode(String(i));
79
79
  }
80
- function A(e) {
81
- 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;
82
- return { left: t, top: i, width: n, height: s };
80
+ function M(i) {
81
+ const t = parseFloat(i.style.left) || 0, e = parseFloat(i.style.top) || 0, n = parseFloat(i.style.width) || 0, s = parseFloat(i.style.height) || 0;
82
+ return { left: t, top: e, width: n, height: s };
83
83
  }
84
84
  const r = {
85
85
  Top: "top",
@@ -91,8 +91,8 @@ const r = {
91
91
  Unknown: "unknown",
92
92
  Outside: "outside"
93
93
  };
94
- function F(e) {
95
- switch (e) {
94
+ function G(i) {
95
+ switch (i) {
96
96
  case r.Top:
97
97
  return r.Bottom;
98
98
  case r.Right:
@@ -102,41 +102,41 @@ function F(e) {
102
102
  case r.Left:
103
103
  return r.Right;
104
104
  default:
105
- throw new Error(`[bwin] Invalid position: ${e}`);
105
+ throw new Error(`[bwin] Invalid position: ${i}`);
106
106
  }
107
107
  }
108
- function _({ width: e, height: t, x: i }) {
109
- return t / e * i;
108
+ function F({ width: i, height: t, x: e }) {
109
+ return t / i * e;
110
110
  }
111
- function k({ width: e, height: t, y: i }) {
112
- return e / t * i;
111
+ function _({ width: i, height: t, y: e }) {
112
+ return i / t * e;
113
113
  }
114
- function U({ width: e, height: t, x: i }) {
115
- return t - t / e * i;
114
+ function k({ width: i, height: t, x: e }) {
115
+ return t - t / i * e;
116
116
  }
117
- function Y({ width: e, height: t, y: i }) {
118
- return e - e / t * i;
117
+ function U({ width: i, height: t, y: e }) {
118
+ return i - i / t * e;
119
119
  }
120
- function X(e, { clientX: t, clientY: i }) {
121
- const n = e.getBoundingClientRect(), { width: s, height: o } = n, h = t - n.left, l = i - n.top;
120
+ function Y(i, { clientX: t, clientY: e }) {
121
+ const n = i.getBoundingClientRect(), { width: s, height: o } = n, h = t - n.left, l = e - n.top;
122
122
  if (h < 0 || h > s || l < 0 || l > o)
123
123
  return r.Outside;
124
- const d = 0.3, a = _({ width: s, height: o, x: h }), c = U({ width: s, height: o, x: h }), p = k({ width: s, height: o, y: l }), u = Y({ width: s, height: o, y: l });
124
+ const d = 0.3, a = F({ width: s, height: o, x: h }), c = k({ width: s, height: o, x: h }), p = _({ width: s, height: o, y: l }), u = U({ width: s, height: o, y: l });
125
125
  return h < s * (0.5 - d / 2) && l > a && l < c ? r.Left : h > s * (0.5 + d / 2) && l < a && l > c ? r.Right : l < o * (0.5 - d / 2) && h > p && h < u ? r.Top : l > o * (0.5 + d / 2) && h < p && h > u ? r.Bottom : h > s * (0.5 - d / 2) && h < s * (0.5 + d / 2) && l > o * (0.5 - d / 2) && l < o * (0.5 + d / 2) ? r.Center : r.Unknown;
126
126
  }
127
- const q = 100, j = 100, w = {
127
+ const X = 100, q = 100, w = {
128
128
  left: 0,
129
129
  top: 0,
130
130
  width: 150,
131
131
  height: 150,
132
132
  // Initial min values, real min width/height is calculated based on children
133
- minWidth: q,
134
- minHeight: j
133
+ minWidth: X,
134
+ minHeight: q
135
135
  };
136
136
  class g {
137
137
  constructor({
138
138
  left: t = w.left,
139
- top: i = w.top,
139
+ top: e = w.top,
140
140
  width: n = w.width,
141
141
  height: s = w.height,
142
142
  minWidth: o = w.minWidth,
@@ -146,12 +146,12 @@ class g {
146
146
  position: a,
147
147
  id: c
148
148
  } = w) {
149
- if (this.id = c ?? z(), !a)
149
+ if (this.id = c ?? C(), !a)
150
150
  throw new Error("[bwin] Sash position is required");
151
- this.position = a, this.domNode = l, this._top = i, this._left = t, this._width = n, this._height = s, this.children = [], this.minWidth = o, this.minHeight = h, this.store = d;
151
+ this.position = a, this.domNode = l, this._top = e, this._left = t, this._width = n, this._height = s, this.children = [], this.minWidth = o, this.minHeight = h, this.store = d;
152
152
  }
153
153
  walk(t) {
154
- this.children.forEach((i) => i.walk(t)), t(this);
154
+ this.children.forEach((e) => e.walk(t)), t(this);
155
155
  }
156
156
  isLeaf() {
157
157
  return this.children.length === 0;
@@ -183,23 +183,23 @@ class g {
183
183
  return this.children.find((t) => t.position === r.Bottom);
184
184
  }
185
185
  getChildren() {
186
- let t = null, i = null, n = null, s = null;
186
+ let t = null, e = null, n = null, s = null;
187
187
  for (const o of this.children)
188
- o.position === r.Left ? t = o : o.position === r.Right ? i = o : o.position === r.Top ? n = o : o.position === r.Bottom && (s = o);
189
- return [n, i, s, t];
188
+ o.position === r.Left ? t = o : o.position === r.Right ? e = o : o.position === r.Top ? n = o : o.position === r.Bottom && (s = o);
189
+ return [n, e, s, t];
190
190
  }
191
191
  getAllLeafDescendants() {
192
192
  const t = [];
193
- return this.walk((i) => {
194
- i.children.length === 0 && t.push(i);
193
+ return this.walk((e) => {
194
+ e.children.length === 0 && t.push(e);
195
195
  }), t;
196
196
  }
197
197
  calcMinWidth() {
198
198
  if (this.isLeaf())
199
199
  return this.minWidth;
200
- const [t, i, n, s] = this.getChildren();
201
- if (s && i) {
202
- const o = s.calcMinWidth() + i.calcMinWidth();
200
+ const [t, e, n, s] = this.getChildren();
201
+ if (s && e) {
202
+ const o = s.calcMinWidth() + e.calcMinWidth();
203
203
  return Math.max(this.minWidth, o);
204
204
  }
205
205
  if (t && n) {
@@ -210,9 +210,9 @@ class g {
210
210
  calcMinHeight() {
211
211
  if (this.isLeaf())
212
212
  return this.minHeight;
213
- const [t, i, n, s] = this.getChildren();
214
- if (s && i) {
215
- const o = Math.max(s.calcMinHeight(), i.calcMinHeight());
213
+ const [t, e, n, s] = this.getChildren();
214
+ if (s && e) {
215
+ const o = Math.max(s.calcMinHeight(), e.calcMinHeight());
216
216
  return Math.max(this.minHeight, o);
217
217
  }
218
218
  if (t && n) {
@@ -224,18 +224,25 @@ class g {
224
224
  getById(t) {
225
225
  if (this.id === t)
226
226
  return this;
227
- for (const i of this.children) {
228
- const n = i.getById(t);
227
+ for (const e of this.children) {
228
+ const n = e.getById(t);
229
229
  if (n)
230
230
  return n;
231
231
  }
232
232
  return null;
233
233
  }
234
+ swapIds(t, e) {
235
+ const n = this.getById(t), s = this.getById(e);
236
+ if (!n || !s)
237
+ throw new Error("[bwin] Sash not found when swapping IDs");
238
+ const o = n.id;
239
+ n.id = s.id, s.id = o;
240
+ }
234
241
  // Get all ids of self and descendants
235
242
  getAllIds() {
236
243
  const t = [this.id];
237
- for (const i of this.children)
238
- t.push(...i.getAllIds());
244
+ for (const e of this.children)
245
+ t.push(...e.getAllIds());
239
246
  return t;
240
247
  }
241
248
  addChild(t) {
@@ -244,78 +251,78 @@ class g {
244
251
  this.children.push(t);
245
252
  }
246
253
  getDescendantParentById(t) {
247
- for (const i of this.children) {
248
- if (i.id === t)
254
+ for (const e of this.children) {
255
+ if (e.id === t)
249
256
  return this;
250
- const n = i.getDescendantParentById(t);
257
+ const n = e.getDescendantParentById(t);
251
258
  if (n)
252
259
  return n;
253
260
  }
254
261
  return null;
255
262
  }
256
263
  getChildSiblingById(t) {
257
- return this.children.find((i) => i.id !== t);
264
+ return this.children.find((e) => e.id !== t);
258
265
  }
259
266
  get top() {
260
267
  return this._top;
261
268
  }
262
269
  set top(t) {
263
- const i = t - this._top;
270
+ const e = t - this._top;
264
271
  this._top = t;
265
272
  const [n, s, o, h] = this.getChildren();
266
- n && o && (n.top += i, o.top += i), h && s && (h.top += i, s.top += i);
273
+ n && o && (n.top += e, o.top += e), h && s && (h.top += e, s.top += e);
267
274
  }
268
275
  get left() {
269
276
  return this._left;
270
277
  }
271
278
  set left(t) {
272
- const i = t - this._left;
279
+ const e = t - this._left;
273
280
  this._left = t;
274
281
  const [n, s, o, h] = this.getChildren();
275
- h && s && (h.left += i, s.left += i), n && o && (n.left += i, o.left += i);
282
+ h && s && (h.left += e, s.left += e), n && o && (n.left += e, o.left += e);
276
283
  }
277
284
  get width() {
278
285
  return this._width;
279
286
  }
280
287
  set width(t) {
281
- const i = t - this._width;
288
+ const e = t - this._width;
282
289
  this._width = t;
283
290
  const [n, s, o, h] = this.getChildren();
284
291
  if (h && s) {
285
- const l = h.width + s.width, d = i * (h.width / l), a = l + i;
292
+ const l = h.width + s.width, d = e * (h.width / l), a = l + e;
286
293
  let c = h.width + d, p = a - c, u = s.left + d;
287
- const E = h.calcMinWidth(), y = s.calcMinWidth();
288
- i < 0 && (c < E && p > y ? (c = h.width, p = a - c, u = h.left + c) : p < y && c > E && (p = s.width, c = a - p, u = h.left + c)), h.width = c, s.width = p, s.left = u;
294
+ const y = h.calcMinWidth(), E = s.calcMinWidth();
295
+ e < 0 && (c < y && p > E ? (c = h.width, p = a - c, u = h.left + c) : p < E && c > y && (p = s.width, c = a - p, u = h.left + c)), h.width = c, s.width = p, s.left = u;
289
296
  }
290
- n && o && (n.width += i, o.width += i);
297
+ n && o && (n.width += e, o.width += e);
291
298
  }
292
299
  get height() {
293
300
  return this._height;
294
301
  }
295
302
  set height(t) {
296
- const i = t - this._height;
303
+ const e = t - this._height;
297
304
  this._height = t;
298
305
  const [n, s, o, h] = this.getChildren();
299
306
  if (n && o) {
300
- const l = n.height + o.height, d = i * (n.height / l), a = l + i;
307
+ const l = n.height + o.height, d = e * (n.height / l), a = l + e;
301
308
  let c = n.height + d, p = a - c, u = o.top + d;
302
- if (i < 0) {
303
- const E = n.calcMinHeight(), y = o.calcMinHeight();
304
- c < E && p > y ? (c = n.height, p = a - c, u = n.top + c) : p < y && c > E && (p = o.height, c = a - p, u = n.top + c);
309
+ if (e < 0) {
310
+ const y = n.calcMinHeight(), E = o.calcMinHeight();
311
+ c < y && p > E ? (c = n.height, p = a - c, u = n.top + c) : p < E && c > y && (p = o.height, c = a - p, u = n.top + c);
305
312
  }
306
313
  n.height = c, o.height = p, o.top = u;
307
314
  }
308
- h && s && (h.height += i, s.height += i);
315
+ h && s && (h.height += e, s.height += e);
309
316
  }
310
317
  }
311
318
  const v = {
312
319
  size: "50%",
313
320
  position: r.Left
314
321
  };
315
- class R {
322
+ class A {
316
323
  constructor({
317
324
  parentRect: t,
318
- children: i,
325
+ children: e,
319
326
  siblingConfigNode: n,
320
327
  id: s,
321
328
  minWidth: o,
@@ -328,21 +335,21 @@ class R {
328
335
  f(this, "top");
329
336
  f(this, "width");
330
337
  f(this, "height");
331
- this.parentRect = t, this.children = i, this.siblingConfigNode = n, this.id = s, this.minWidth = o, this.minHeight = h, this.position = this.getPosition(l), this.size = this.getSize(d), this.nonCoreData = a, this.setBounds();
338
+ this.parentRect = t, this.children = e, this.siblingConfigNode = n, this.id = s, this.minWidth = o, this.minHeight = h, this.position = this.getPosition(l), this.size = this.getSize(d), this.nonCoreData = a, this.setBounds();
332
339
  }
333
340
  getPosition(t) {
334
341
  if (!this.siblingConfigNode)
335
342
  return t;
336
- const i = F(this.siblingConfigNode.position);
343
+ const e = G(this.siblingConfigNode.position);
337
344
  if (!t)
338
- return i;
339
- if (t !== i)
345
+ return e;
346
+ if (t !== e)
340
347
  throw new Error("[bwin] Sibling position and current position are not opposite");
341
348
  return t;
342
349
  }
343
350
  getSize(t) {
344
351
  if (!this.siblingConfigNode)
345
- return C(t);
352
+ return b(t);
346
353
  if (!t) {
347
354
  if (this.siblingConfigNode.size < 1)
348
355
  return 1 - this.siblingConfigNode.size;
@@ -351,17 +358,17 @@ class R {
351
358
  if (this.siblingConfigNode.position === r.Top || this.siblingConfigNode.position === r.Bottom)
352
359
  return this.parentRect.height - this.siblingConfigNode.height;
353
360
  }
354
- const i = C(t);
355
- if (i < 1) {
356
- if (i + this.siblingConfigNode.size !== 1)
361
+ const e = b(t);
362
+ if (e < 1) {
363
+ if (e + this.siblingConfigNode.size !== 1)
357
364
  throw new Error("[bwin] Sum of sibling sizes is not equal to 1");
358
365
  } else {
359
- if ((this.position === r.Left || this.position === r.Right) && i + this.siblingConfigNode.size !== this.parentRect.width)
366
+ if ((this.position === r.Left || this.position === r.Right) && e + this.siblingConfigNode.size !== this.parentRect.width)
360
367
  throw new Error("[bwin] Sum of sibling sizes is not equal to parent width");
361
- if ((this.position === r.Top || this.position === r.Bottom) && i + this.siblingConfigNode.size !== this.parentRect.height)
368
+ if ((this.position === r.Top || this.position === r.Bottom) && e + this.siblingConfigNode.size !== this.parentRect.height)
362
369
  throw new Error("[bwin] Sum of sibling sizes is not equal to parent height");
363
370
  }
364
- return i;
371
+ return e;
365
372
  }
366
373
  setBounds() {
367
374
  if (this.position === r.Root)
@@ -394,16 +401,16 @@ class R {
394
401
  });
395
402
  }
396
403
  normConfig(t) {
397
- if (I(t))
404
+ if (H(t))
398
405
  return t;
399
406
  if (Array.isArray(t))
400
407
  return {
401
408
  children: t
402
409
  };
403
410
  if (typeof t == "string" || typeof t == "number") {
404
- const i = C(t);
405
- if (isNaN(i))
406
- throw new Error(`[bwin] Invalid size value: ${i}`);
411
+ const e = b(t);
412
+ if (isNaN(e))
413
+ throw new Error(`[bwin] Invalid size value: ${e}`);
407
414
  return {
408
415
  size: t
409
416
  };
@@ -413,11 +420,11 @@ class R {
413
420
  throw new Error(`[bwin] Invalid config value: ${t}`);
414
421
  }
415
422
  }
416
- createPrimaryConfigNode({ size: t, position: i, children: n, id: s, minWidth: o, minHeight: h, ...l }) {
417
- return new R({
423
+ createPrimaryConfigNode({ size: t, position: e, children: n, id: s, minWidth: o, minHeight: h, ...l }) {
424
+ return new A({
418
425
  parentRect: this,
419
426
  size: t ?? v.size,
420
- position: i ?? v.position,
427
+ position: e ?? v.position,
421
428
  children: n,
422
429
  id: s,
423
430
  minWidth: o,
@@ -425,11 +432,11 @@ class R {
425
432
  ...l
426
433
  });
427
434
  }
428
- createSecondaryConfigNode({ size: t, position: i, children: n, id: s, minWidth: o, minHeight: h, ...l }, d) {
429
- return new R({
435
+ createSecondaryConfigNode({ size: t, position: e, children: n, id: s, minWidth: o, minHeight: h, ...l }, d) {
436
+ return new A({
430
437
  parentRect: this,
431
438
  size: t,
432
- position: i,
439
+ position: e,
433
440
  children: n,
434
441
  siblingConfigNode: d,
435
442
  id: s,
@@ -442,38 +449,38 @@ class R {
442
449
  const t = this.createSash();
443
450
  if (!Array.isArray(this.children) || this.children.length === 0)
444
451
  return t;
445
- const i = this.normConfig(this.children[0]), n = this.normConfig(this.children.at(1));
452
+ const e = this.normConfig(this.children[0]), n = this.normConfig(this.children.at(1));
446
453
  let s, o;
447
- return !i.size && !i.position && n ? (n.position || (n.position = r.Right), s = this.createPrimaryConfigNode(n), o = this.createSecondaryConfigNode(
448
- i,
454
+ return !e.size && !e.position && n ? (n.position || (n.position = r.Right), s = this.createPrimaryConfigNode(n), o = this.createSecondaryConfigNode(
455
+ e,
449
456
  s
450
- )) : (s = this.createPrimaryConfigNode(i), o = this.createSecondaryConfigNode(
457
+ )) : (s = this.createPrimaryConfigNode(e), o = this.createSecondaryConfigNode(
451
458
  n,
452
459
  s
453
460
  )), s && o && (t.children.push(s.buildSashTree()), t.children.push(o.buildSashTree())), t;
454
461
  }
455
462
  }
456
- const S = {
463
+ const D = {
457
464
  width: 333,
458
465
  height: 333
459
- }, D = {
466
+ }, S = {
460
467
  fitContainer: !1
461
468
  };
462
- class K extends R {
469
+ class j extends A {
463
470
  constructor({
464
471
  id: t,
465
- children: i,
466
- width: n = S.width,
467
- height: s = S.height,
468
- fitContainer: o = D.fitContainer,
472
+ children: e,
473
+ width: n = D.width,
474
+ height: s = D.height,
475
+ fitContainer: o = S.fitContainer,
469
476
  ...h
470
477
  } = {
471
- ...S,
472
- ...D
478
+ ...D,
479
+ ...S
473
480
  }) {
474
481
  super({
475
482
  id: t,
476
- children: i,
483
+ children: e,
477
484
  size: NaN,
478
485
  position: r.Root,
479
486
  parentRect: { width: n, height: s },
@@ -481,120 +488,140 @@ class K extends R {
481
488
  }), this.fitContainer = o;
482
489
  }
483
490
  }
484
- class V extends g {
491
+ class K extends g {
485
492
  constructor(t = w) {
486
- super({ ...t, position: r.Root }), Object.assign(this, D);
493
+ super({ ...t, position: r.Root }), Object.assign(this, S);
487
494
  }
488
495
  }
489
- function M(e) {
496
+ function V(i) {
490
497
  const t = document.createElement("bw-pane");
491
- 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;
492
- }
493
- function J(e) {
494
- const t = e.domNode;
495
- 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;
496
- }
497
- function Q(e, { size: t }) {
498
- const i = C(t);
499
- let n = e.width / 2;
500
- i && (i < 1 ? n = e.width * i : n = i);
501
- const s = new g({
502
- top: e.top,
503
- left: e.left,
504
- width: n,
505
- height: e.height,
506
- position: r.Left
507
- }), o = new g({
508
- top: e.top,
509
- left: e.left + s.width,
510
- width: e.width - n,
511
- height: e.height,
512
- position: r.Right
513
- }), h = M(o);
514
- return o.domNode = h, b(h, e.domNode), e.addChild(s), e.addChild(o), s;
515
- }
516
- function Z(e, { size: t }) {
517
- const i = C(t);
518
- let n = e.width / 2;
519
- i && (i < 1 ? n = e.width * i : n = i);
520
- const s = new g({
521
- left: e.left,
522
- top: e.top,
523
- width: e.width - n,
524
- height: e.height,
498
+ return t.style.top = `${i.top}px`, t.style.left = `${i.left}px`, t.style.width = `${i.width}px`, t.style.height = `${i.height}px`, t.setAttribute("sash-id", i.id), t.setAttribute("position", i.position), t;
499
+ }
500
+ function J(i) {
501
+ const t = i.domNode;
502
+ return t.style.top = `${i.top}px`, t.style.left = `${i.left}px`, t.style.width = `${i.width}px`, t.style.height = `${i.height}px`, t.setAttribute("position", i.position), t;
503
+ }
504
+ function Q(i, { size: t, id: e }) {
505
+ const n = b(t);
506
+ let s = i.width / 2;
507
+ n && (n < 1 ? s = i.width * n : s = n);
508
+ const o = new g({
509
+ id: e,
510
+ top: i.top,
511
+ left: i.left,
512
+ width: s,
513
+ height: i.height,
525
514
  position: r.Left
526
- }), o = new g({
527
- left: e.left + s.width,
528
- top: e.top,
529
- width: n,
530
- height: e.height,
515
+ }), h = new g({
516
+ id: i.id,
517
+ top: i.top,
518
+ left: i.left + o.width,
519
+ width: i.width - s,
520
+ height: i.height,
521
+ position: r.Right,
522
+ domNode: i.domNode
523
+ });
524
+ return i.addChild(o), i.addChild(h), i.domNode = null, i.id = C(), o;
525
+ }
526
+ function Z(i, { size: t, id: e }) {
527
+ const n = b(t);
528
+ let s = i.width / 2;
529
+ n && (n < 1 ? s = i.width * n : s = n);
530
+ const o = new g({
531
+ id: i.id,
532
+ left: i.left,
533
+ top: i.top,
534
+ width: i.width - s,
535
+ height: i.height,
536
+ position: r.Left,
537
+ domNode: i.domNode
538
+ }), h = new g({
539
+ id: e,
540
+ left: i.left + o.width,
541
+ top: i.top,
542
+ width: s,
543
+ height: i.height,
531
544
  position: r.Right
532
- }), h = M(s);
533
- return s.domNode = h, b(h, e.domNode), e.addChild(s), e.addChild(o), o;
534
- }
535
- function tt(e, { size: t }) {
536
- const i = C(t);
537
- let n = e.height / 2;
538
- i && (i < 1 ? n = e.height * i : n = i);
539
- const s = new g({
540
- left: e.left,
541
- top: e.top,
542
- width: e.width,
543
- height: n,
544
- position: r.Top
545
- }), o = new g({
546
- left: e.left,
547
- top: e.top + s.height,
548
- width: e.width,
549
- height: e.height - n,
550
- position: r.Bottom
551
- }), h = M(o);
552
- return o.domNode = h, b(h, e.domNode), e.addChild(s), e.addChild(o), s;
553
- }
554
- function et(e, { size: t }) {
555
- const i = C(t);
556
- let n = e.height / 2;
557
- i && (i < 1 ? n = e.height * i : n = i);
558
- const s = new g({
559
- top: e.top,
560
- left: e.left,
561
- width: e.width,
562
- height: e.height - n,
545
+ });
546
+ return i.addChild(o), i.addChild(h), i.domNode = null, i.id = C(), h;
547
+ }
548
+ function tt(i, { size: t, id: e }) {
549
+ const n = b(t);
550
+ let s = i.height / 2;
551
+ n && (n < 1 ? s = i.height * n : s = n);
552
+ const o = new g({
553
+ id: e,
554
+ left: i.left,
555
+ top: i.top,
556
+ width: i.width,
557
+ height: s,
563
558
  position: r.Top
564
- }), o = new g({
565
- top: e.top + s.height,
566
- left: e.left,
567
- width: e.width,
568
- height: n,
559
+ }), h = new g({
560
+ id: i.id,
561
+ left: i.left,
562
+ top: i.top + o.height,
563
+ width: i.width,
564
+ height: i.height - s,
565
+ position: r.Bottom,
566
+ domNode: i.domNode
567
+ });
568
+ return i.addChild(o), i.addChild(h), i.domNode = null, i.id = C(), o;
569
+ }
570
+ function it(i, { size: t, id: e }) {
571
+ const n = b(t);
572
+ let s = i.height / 2;
573
+ n && (n < 1 ? s = i.height * n : s = n);
574
+ const o = new g({
575
+ id: i.id,
576
+ top: i.top,
577
+ left: i.left,
578
+ width: i.width,
579
+ height: i.height - s,
580
+ position: r.Top,
581
+ domNode: i.domNode
582
+ }), h = new g({
583
+ id: e,
584
+ top: i.top + o.height,
585
+ left: i.left,
586
+ width: i.width,
587
+ height: s,
569
588
  position: r.Bottom
570
- }), h = M(s);
571
- return s.domNode = h, b(h, e.domNode), e.addChild(s), e.addChild(o), o;
589
+ });
590
+ return i.addChild(o), i.addChild(h), i.domNode = null, i.id = C(), h;
572
591
  }
573
- function it(e, { position: t, size: i, minWidth: n, minHeight: s }) {
592
+ function et(i, { position: t, size: e, id: n, minWidth: s, minHeight: o }) {
574
593
  if (t === r.Left)
575
- return Q(e, { size: i });
594
+ return Q(i, { size: e, id: n });
576
595
  if (t === r.Right)
577
- return Z(e, { size: i });
596
+ return Z(i, { size: e, id: n });
578
597
  if (t === r.Top)
579
- return tt(e, { size: i });
598
+ return tt(i, { size: e, id: n });
580
599
  if (t === r.Bottom)
581
- return et(e, { size: i });
600
+ return it(i, { size: e, id: n });
601
+ }
602
+ function R(i) {
603
+ if (i.tagName === "BW-PANE")
604
+ return i.getAttribute("sash-id");
605
+ const t = i.closest("bw-pane");
606
+ if (!t)
607
+ throw new Error("[bwin] Pane element not found");
608
+ return t.getAttribute("sash-id");
582
609
  }
583
610
  const nt = {
584
- createPane(e) {
585
- const t = M(e);
586
- return e.store.droppable === !1 && t.setAttribute("can-drop", "false"), t;
611
+ createPane(i) {
612
+ const t = V(i);
613
+ return i.store.droppable === !1 && t.setAttribute("can-drop", "false"), t;
587
614
  },
588
615
  // Intended to be overridden
589
- onPaneCreate(e, t) {
590
- t.store.content && e.append(m(t.store.content)), this != null && this.debug && (e.style.backgroundColor = W(), e.innerHTML = "", e.append(x(e)));
616
+ onPaneCreate(i, t) {
617
+ t.store.content && i.append(m(t.store.content)), this != null && this.debug && (i.style.backgroundColor = I(), i.innerHTML = "", i.append(x(i)));
591
618
  },
592
- updatePane(e) {
593
- return J(e);
619
+ updatePane(i) {
620
+ return J(i);
594
621
  },
595
622
  // Intended to be overridden
596
- onPaneUpdate(e, t) {
597
- this != null && this.debug && (e.innerHTML = "", e.append(x(e)));
623
+ onPaneUpdate(i, t) {
624
+ this != null && this.debug && (i.innerHTML = "", i.append(x(i)));
598
625
  },
599
626
  /**
600
627
  * Add a pane into the target pane. The two panes become next to each other
@@ -603,72 +630,76 @@ const nt = {
603
630
  * @param {'top'|'right'|'bottom'|'left'} position - The position of the new pane relative to the target pane
604
631
  * @returns {Sash} - The newly created sash
605
632
  */
606
- addPane(e, { position: t, size: i }) {
633
+ addPane(i, { position: t, size: e, id: n }) {
607
634
  if (!t) throw new Error("[bwin] Position is required when adding pane");
608
- const n = this.rootSash.getById(e);
609
- if (!n) throw new Error("[bwin] Parent sash not found when adding pane");
610
- const s = it(n, { position: t, size: i });
611
- return n.id = z(), this.update(), s;
635
+ const s = this.rootSash.getById(i);
636
+ if (!s) throw new Error("[bwin] Parent sash not found when adding pane");
637
+ const o = et(s, { position: t, size: e, id: n });
638
+ return this.update(), o;
612
639
  },
613
640
  /**
614
641
  * Remove a pane
615
642
  *
616
643
  * @param {string} sashId - The Sash ID of the pane to be removed
617
644
  */
618
- removePane(e) {
619
- const t = this.rootSash.getDescendantParentById(e);
645
+ removePane(i) {
646
+ const t = this.rootSash.getDescendantParentById(i);
620
647
  if (!t) throw new Error("[bwin] Parent sash not found when removing pane");
621
- const i = t.getChildSiblingById(e);
622
- i.children.length === 0 ? (t.id = i.id, t.domNode = i.domNode, t.domNode.setAttribute("sash-id", i.id), t.children = []) : (t.id = z(), 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();
648
+ const e = t.getChildSiblingById(i);
649
+ e.children.length === 0 ? (t.id = e.id, t.domNode = e.domNode, t.domNode.setAttribute("sash-id", e.id), t.children = []) : (t.id = C(), t.children = e.children, e.position === r.Left ? e.width = t.width : e.position === r.Right ? (e.width = t.width, e.left = t.left) : e.position === r.Top ? e.height = t.height : e.position === r.Bottom && (e.height = t.height, e.top = t.top)), this.update();
650
+ },
651
+ swapPanes(i, t) {
652
+ const e = R(i), n = R(t), s = i.getAttribute("can-drop") !== "false", o = t.getAttribute("can-drop") !== "false";
653
+ this.rootSash.swapIds(e, n), W(i, this.activeDropPaneEl), i.setAttribute("sash-id", n), t.setAttribute("sash-id", e), i.setAttribute("can-drop", o), t.setAttribute("can-drop", s);
623
654
  }
624
655
  };
625
- function x(e) {
656
+ function x(i) {
626
657
  const t = document.createElement("pre");
627
658
  t.style.fontSize = "10px";
628
- const i = `
629
- ${e.getAttribute("sash-id")}
630
- ${e.getAttribute("position")}
631
- top: ${e.style.top}
632
- left: ${e.style.left}
633
- width: ${e.style.width}
634
- height: ${e.style.height}
659
+ const e = `
660
+ ${i.getAttribute("sash-id")}
661
+ ${i.getAttribute("position")}
662
+ top: ${i.style.top}
663
+ left: ${i.style.left}
664
+ width: ${i.style.width}
665
+ height: ${i.style.height}
635
666
  `;
636
- return t.innerHTML = i.trim(), t;
667
+ return t.innerHTML = e.trim(), t;
637
668
  }
638
669
  const st = {
639
670
  createWindow() {
640
- const e = document.createElement("bw-window");
641
- return e.style.width = `${this.rootSash.width}px`, e.style.height = `${this.rootSash.height}px`, e.setAttribute("root-sash-id", this.rootSash.id), e;
671
+ const i = document.createElement("bw-window");
672
+ return i.style.width = `${this.rootSash.width}px`, i.style.height = `${this.rootSash.height}px`, i.setAttribute("root-sash-id", this.rootSash.id), i;
642
673
  },
643
674
  glaze() {
644
- this.rootSash.walk((e) => {
675
+ this.rootSash.walk((i) => {
645
676
  let t = null;
646
- 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;
677
+ i.children.length > 0 ? (t = this.createMuntin(i), this.onMuntinCreate(t, i), this.windowElement.append(t)) : (t = this.createPane(i), this.onPaneCreate(t, i), this.windowElement.prepend(t)), i.domNode = t;
647
678
  });
648
679
  },
649
680
  update() {
650
681
  this.windowElement.style.width = `${this.rootSash.width}px`, this.windowElement.style.height = `${this.rootSash.height}px`;
651
- const e = this.rootSash.getAllIds(), t = [];
652
- this.windowElement.querySelectorAll("[sash-id]").forEach((i) => {
653
- const n = i.getAttribute("sash-id");
654
- t.push(n), e.includes(n) || i.remove();
655
- }), this.rootSash.walk((i) => {
656
- 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));
682
+ const i = this.rootSash.getAllIds(), t = [];
683
+ this.windowElement.querySelectorAll("[sash-id]").forEach((e) => {
684
+ const n = e.getAttribute("sash-id");
685
+ t.push(n), i.includes(n) || e.remove();
686
+ }), this.rootSash.walk((e) => {
687
+ 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 || (e.domNode = this.createPane(e)), this.windowElement.prepend(e.domNode));
657
688
  });
658
689
  }
659
690
  }, ot = {
660
691
  muntinSize: 4,
661
- createMuntin(e) {
662
- const t = document.createElement("bw-muntin"), i = e.leftChild, n = e.topChild;
663
- 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;
692
+ createMuntin(i) {
693
+ const t = document.createElement("bw-muntin"), e = i.leftChild, n = i.topChild;
694
+ return e ? (t.style.width = `${this.muntinSize}px`, t.style.height = `${i.height}px`, t.style.top = `${i.top}px`, t.style.left = `${i.left + e.width - this.muntinSize / 2}px`, t.setAttribute("vertical", "")) : n && (t.style.width = `${i.width}px`, t.style.height = `${this.muntinSize}px`, t.style.top = `${i.top + n.height - this.muntinSize / 2}px`, t.style.left = `${i.left}px`, t.setAttribute("horizontal", "")), t.setAttribute("sash-id", i.id), i.store.resizable === !1 && t.setAttribute("resizable", "false"), t;
664
695
  },
665
- onMuntinCreate(e, t) {
696
+ onMuntinCreate(i, t) {
666
697
  },
667
- updateMuntin(e) {
668
- const t = e.domNode, i = e.leftChild, n = e.topChild;
669
- 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`);
698
+ updateMuntin(i) {
699
+ const t = i.domNode, e = i.leftChild, n = i.topChild;
700
+ e ? (t.style.height = `${i.height}px`, t.style.top = `${i.top}px`, t.style.left = `${i.left + e.width - this.muntinSize / 2}px`) : n && (t.style.width = `${i.width}px`, t.style.top = `${i.top + n.height - this.muntinSize / 2}px`, t.style.left = `${i.left}px`);
670
701
  },
671
- onMuntinUpdate(e, t) {
702
+ onMuntinUpdate(i, t) {
672
703
  }
673
704
  }, ht = {
674
705
  fitContainer: !1,
@@ -677,8 +708,8 @@ const st = {
677
708
  },
678
709
  enableFitContainer() {
679
710
  new ResizeObserver((t) => {
680
- for (const i of t)
681
- i.target === this.containerElement && this.fitContainer && this.fit();
711
+ for (const e of t)
712
+ e.target === this.containerElement && this.fitContainer && this.fit();
682
713
  }).observe(this.containerElement);
683
714
  }
684
715
  }, rt = {
@@ -694,21 +725,21 @@ const st = {
694
725
  document.body.classList.remove("body--bw-resize-x"), document.body.classList.remove("body--bw-resize-y");
695
726
  },
696
727
  enableResize() {
697
- document.addEventListener("mousedown", (e) => {
698
- if (e.target.tagName !== "BW-MUNTIN" || e.target.getAttribute("resizable") === "false") return;
699
- const t = e.target.getAttribute("sash-id");
700
- this.activeMuntinSash = this.rootSash.getById(t), this.activeMuntinSash && (this.isResizeStarted = !0, this.lastX = e.pageX, this.lastY = e.pageY, this.applyResizeStyles());
701
- }), document.addEventListener("mousemove", (e) => {
728
+ document.addEventListener("mousedown", (i) => {
729
+ if (i.target.tagName !== "BW-MUNTIN" || i.target.getAttribute("resizable") === "false") return;
730
+ const t = i.target.getAttribute("sash-id");
731
+ this.activeMuntinSash = this.rootSash.getById(t), this.activeMuntinSash && (this.isResizeStarted = !0, this.lastX = i.pageX, this.lastY = i.pageY, this.applyResizeStyles());
732
+ }), document.addEventListener("mousemove", (i) => {
702
733
  if (!this.isResizeStarted || !this.activeMuntinSash) return;
703
- const [t, i, n, s] = this.activeMuntinSash.getChildren(), o = this.activeMuntinSash.isLeftRightSplit(), h = this.activeMuntinSash.isTopBottomSplit();
704
- if (o && s && i) {
705
- const l = e.pageX - this.lastX, d = s.width + l, a = i.width - l;
706
- if (l > 0 && a <= i.calcMinWidth() || l < 0 && d <= s.calcMinWidth()) return;
707
- s.width = d, i.width = a, i.left = i.left + l, this.update(), this.lastX = e.pageX;
734
+ const [t, e, n, s] = this.activeMuntinSash.getChildren(), o = this.activeMuntinSash.isLeftRightSplit(), h = this.activeMuntinSash.isTopBottomSplit();
735
+ if (o && s && e) {
736
+ const l = i.pageX - this.lastX, d = s.width + l, a = e.width - l;
737
+ if (l > 0 && a <= e.calcMinWidth() || l < 0 && d <= s.calcMinWidth()) return;
738
+ s.width = d, e.width = a, e.left = e.left + l, this.update(), this.lastX = i.pageX;
708
739
  } else if (h && t && n) {
709
- const l = e.pageY - this.lastY, d = t.height + l, a = n.height - l;
740
+ const l = i.pageY - this.lastY, d = t.height + l, a = n.height - l;
710
741
  if (l > 0 && a <= n.calcMinHeight() || l < 0 && d <= t.calcMinHeight()) return;
711
- t.height = d, n.height = a, n.top = n.top + l, this.update(), this.lastY = e.pageY;
742
+ t.height = d, n.height = a, n.top = n.top + l, this.update(), this.lastY = i.pageY;
712
743
  }
713
744
  }), document.addEventListener("mouseup", () => {
714
745
  this.isResizeStarted = !1, this.activeMuntinSash = null, this.revertResizeStyles();
@@ -717,31 +748,31 @@ const st = {
717
748
  }, lt = {
718
749
  activeDropPaneEl: null,
719
750
  // Intended to be overridden in `BinaryWindow` class
720
- onPaneDrop(e, t) {
751
+ onPaneDrop(i, t) {
721
752
  },
722
753
  enableDrop() {
723
- this.windowElement.addEventListener("dragover", (e) => {
724
- e.preventDefault();
725
- const t = e.target.matches("bw-pane") ? e.target : e.target.closest("bw-pane");
754
+ this.windowElement.addEventListener("dragover", (i) => {
755
+ i.preventDefault();
756
+ const t = i.target.matches("bw-pane") ? i.target : i.target.closest("bw-pane");
726
757
  if (!t || (t !== this.activeDropPaneEl && (this.activeDropPaneEl && this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = t), t.getAttribute("can-drop") === "false")) return;
727
- const i = X(t, e);
728
- t.setAttribute("drop-area", i);
729
- }), this.windowElement.addEventListener("dragleave", (e) => {
730
- e.currentTarget.contains(e.relatedTarget) && e.currentTarget !== e.relatedTarget || this.activeDropPaneEl && (this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = null);
731
- }), this.windowElement.addEventListener("drop", (e) => {
758
+ const e = Y(t, i);
759
+ t.setAttribute("drop-area", e);
760
+ }), this.windowElement.addEventListener("dragleave", (i) => {
761
+ i.currentTarget.contains(i.relatedTarget) && i.currentTarget !== i.relatedTarget || this.activeDropPaneEl && (this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = null);
762
+ }), this.windowElement.addEventListener("drop", (i) => {
732
763
  if (!this.activeDropPaneEl || this.activeDropPaneEl.getAttribute("can-drop") === "false") return;
733
- const t = this.activeDropPaneEl.getAttribute("sash-id"), i = this.rootSash.getById(t);
734
- this.onPaneDrop(e, i), typeof i.store.onDrop == "function" && i.store.onDrop(e, i), this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = null;
764
+ const t = this.activeDropPaneEl.getAttribute("sash-id"), e = this.rootSash.getById(t);
765
+ this.onPaneDrop(i, e), typeof e.store.onDrop == "function" && e.store.onDrop(i, e), this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = null;
735
766
  });
736
767
  }
737
768
  }, dt = !1;
738
- class L {
769
+ class B {
739
770
  constructor(t) {
740
771
  f(this, "windowElement", null);
741
772
  f(this, "containerElement", null);
742
773
  f(this, "debug", dt);
743
- let i = null;
744
- t instanceof V ? (i = t, this.rootSash = t) : (i = new K(t), this.rootSash = i.buildSashTree()), this.fitContainer = i.fitContainer;
774
+ let e = null;
775
+ t instanceof K ? (e = t, this.rootSash = t) : (e = new j(t), this.rootSash = e.buildSashTree()), this.fitContainer = e.fitContainer;
745
776
  }
746
777
  frame(t) {
747
778
  this.containerElement = t, this.windowElement = this.createWindow(), this.glaze(), this.containerElement.append(this.windowElement);
@@ -754,12 +785,12 @@ class L {
754
785
  this.frame(t), this.enableFeatures();
755
786
  }
756
787
  static assemble(...t) {
757
- t.forEach((i) => {
758
- O(this.prototype, i);
788
+ t.forEach((e) => {
789
+ O(this.prototype, e);
759
790
  });
760
791
  }
761
792
  }
762
- L.assemble(
793
+ B.assemble(
763
794
  st,
764
795
  ot,
765
796
  nt,
@@ -767,45 +798,37 @@ L.assemble(
767
798
  lt,
768
799
  rt
769
800
  );
770
- function B(e) {
771
- if (e.tagName === "BW-PANE")
772
- return e.getAttribute("sash-id");
773
- const t = e.closest("bw-pane");
774
- if (!t)
775
- throw new Error("[bwin] Pane element not found");
776
- return t.getAttribute("sash-id");
777
- }
778
801
  const at = {
779
802
  label: "",
780
803
  className: "bw-glass-action--close",
781
- onClick: (e, t) => {
782
- const i = B(e.target);
783
- t.removePane(i);
804
+ onClick: (i, t) => {
805
+ const e = R(i.target);
806
+ t.removePane(e);
784
807
  }
785
808
  }, ct = {
786
809
  label: "",
787
810
  className: "bw-glass-action--minimize",
788
- onClick: (e, t) => {
789
- const i = t.sillElement;
790
- if (!i) throw new Error("[bwin] Sill element not found when minimizing");
811
+ onClick: (i, t) => {
812
+ const e = t.sillElement;
813
+ if (!e) throw new Error("[bwin] Sill element not found when minimizing");
791
814
  const n = m('<button class="bw-minimized-glass" />');
792
- i.append(n);
793
- const s = e.target.closest("bw-pane"), o = e.target.closest("bw-glass"), h = s.getAttribute("sash-id"), l = s.getAttribute("position");
794
- n.bwGlassElement = o, n.bwOriginalPosition = l, n.bwOriginalBoundingRect = A(s), t.removePane(h);
815
+ e.append(n);
816
+ const s = i.target.closest("bw-pane"), o = i.target.closest("bw-glass"), h = s.getAttribute("sash-id"), l = s.getAttribute("position");
817
+ n.bwGlassElement = o, n.bwOriginalPosition = l, n.bwOriginalBoundingRect = M(s), n.bwOriginalSashId = h, t.removePane(h);
795
818
  }
796
819
  }, pt = {
797
820
  label: "",
798
821
  className: "bw-glass-action--maximize",
799
- onClick: (e) => {
800
- const t = e.target.closest("bw-pane");
801
- 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 = A(t), t.style.left = "0", t.style.top = "0", t.style.width = "100%", t.style.height = "100%");
822
+ onClick: (i) => {
823
+ const t = i.target.closest("bw-pane");
824
+ 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%");
802
825
  }
803
826
  };
804
- function ut(e, t) {
805
- const i = e.left + e.width, n = e.top + e.height, s = t.left + t.width, o = t.top + t.height;
806
- if (e.left >= s || t.left >= i || e.top >= o || t.top >= n)
827
+ function ut(i, t) {
828
+ const e = i.left + i.width, n = i.top + i.height, s = t.left + t.width, o = t.top + t.height;
829
+ if (i.left >= s || t.left >= e || i.top >= o || t.top >= n)
807
830
  return null;
808
- const h = Math.max(e.left, t.left), l = Math.max(e.top, t.top), d = Math.min(i, s), a = Math.min(n, o);
831
+ const h = Math.max(i.left, t.left), l = Math.max(i.top, t.top), d = Math.min(e, s), a = Math.min(n, o);
809
832
  return {
810
833
  left: h,
811
834
  top: l,
@@ -817,17 +840,17 @@ const ft = [ct, pt, at], gt = {
817
840
  enableActions() {
818
841
  this.handleMinimizedGlassClick(), this.observeActionButtons();
819
842
  },
820
- restoreGlass(e) {
821
- const t = e.bwOriginalBoundingRect;
822
- let i = 0, n = null;
843
+ restoreGlass(i) {
844
+ const t = i.bwOriginalBoundingRect;
845
+ let e = 0, n = null;
823
846
  if (this.windowElement.querySelectorAll("bw-pane").forEach((s) => {
824
- const o = A(s), h = ut(t, o);
847
+ const o = M(s), h = ut(t, o);
825
848
  if (h) {
826
849
  const l = h.width * h.height;
827
- l > i && (i = l, n = s);
850
+ l > e && (e = l, n = s);
828
851
  }
829
852
  }), n) {
830
- const s = e.bwOriginalPosition, o = A(n), h = n.getAttribute("sash-id"), l = this.rootSash.getById(h);
853
+ const s = i.bwOriginalPosition, o = M(n), h = n.getAttribute("sash-id"), l = this.rootSash.getById(h);
831
854
  let d = 0;
832
855
  if (s === r.Left || s === r.Right)
833
856
  d = o.width - t.width < l.minWidth ? o.width / 2 : t.width;
@@ -835,35 +858,37 @@ const ft = [ct, pt, at], gt = {
835
858
  d = o.height - t.height < l.minHeight ? o.height / 2 : t.height;
836
859
  else
837
860
  throw new Error("[bwin] Invalid position when restoring glass");
861
+ const a = i.bwOriginalSashId;
838
862
  this.addPane(n.getAttribute("sash-id"), {
863
+ id: a,
839
864
  position: s,
840
865
  size: d
841
- }).domNode.append(e.bwGlassElement);
866
+ }).domNode.append(i.bwGlassElement);
842
867
  }
843
868
  },
844
869
  handleMinimizedGlassClick() {
845
- this.sillElement.addEventListener("click", (e) => {
846
- if (!e.target.matches(".bw-minimized-glass")) return;
847
- const t = e.target;
870
+ this.sillElement.addEventListener("click", (i) => {
871
+ if (!i.target.matches(".bw-minimized-glass")) return;
872
+ const t = i.target;
848
873
  this.restoreGlass(t), t.remove();
849
874
  });
850
875
  },
851
876
  updateDisabledStateOfActionButtons() {
852
877
  this.updateDisabledState(".bw-glass-action--close"), this.updateDisabledState(".bw-glass-action--minimize"), this.updateDisabledState(".bw-glass-action--maximize");
853
878
  },
854
- updateDisabledState(e) {
879
+ updateDisabledState(i) {
855
880
  if (this.windowElement.querySelectorAll("bw-pane").length === 1) {
856
- const i = this.windowElement.querySelector(e);
857
- i && i.setAttribute("disabled", "");
881
+ const e = this.windowElement.querySelector(i);
882
+ e && e.setAttribute("disabled", "");
858
883
  } else
859
- this.windowElement.querySelectorAll(e).forEach((i) => {
860
- i.removeAttribute("disabled");
884
+ this.windowElement.querySelectorAll(i).forEach((e) => {
885
+ e.removeAttribute("disabled");
861
886
  });
862
887
  },
863
888
  observeActionButtons() {
864
889
  this.updateDisabledStateOfActionButtons(), new MutationObserver((t) => {
865
- t.forEach((i) => {
866
- i.type === "childList" && this.updateDisabledStateOfActionButtons();
890
+ t.forEach((e) => {
891
+ e.type === "childList" && this.updateDisabledStateOfActionButtons();
867
892
  });
868
893
  }).observe(this.windowElement, {
869
894
  childList: !0
@@ -879,7 +904,7 @@ const ft = [ct, pt, at], gt = {
879
904
  class T {
880
905
  constructor({
881
906
  title: t = N.title,
882
- content: i = N.content,
907
+ content: e = N.content,
883
908
  tabs: n = N.tabs,
884
909
  actions: s = N.actions,
885
910
  draggable: o = N.draggable,
@@ -887,7 +912,7 @@ class T {
887
912
  binaryWindow: l
888
913
  }) {
889
914
  f(this, "domNode");
890
- this.title = t, this.content = i, this.tabs = n, this.actions = s, this.sash = h, this.draggable = o, this.binaryWindow = l, this.build();
915
+ this.title = t, this.content = e, this.tabs = n, this.actions = s, this.sash = h, this.draggable = o, this.binaryWindow = l, this.build();
891
916
  }
892
917
  build() {
893
918
  const t = document.createElement("bw-glass-header");
@@ -898,20 +923,20 @@ class T {
898
923
  s.append(m(this.title)), t.append(s);
899
924
  }
900
925
  t.setAttribute("can-drag", this.draggable), t.append(this.createActions());
901
- const i = document.createElement("bw-glass-content"), n = m(this.content);
902
- n && i.append(n), this.domNode = document.createElement("bw-glass"), this.domNode.append(t, i);
926
+ const e = document.createElement("bw-glass-content"), n = m(this.content);
927
+ n && e.append(n), this.domNode = document.createElement("bw-glass"), this.domNode.append(t, e);
903
928
  }
904
929
  createTabs() {
905
930
  const t = document.createElement("bw-glass-tab-container");
906
- for (const i of this.tabs) {
907
- const n = (i == null ? void 0 : i.label) ?? i, s = m(`<button class="bw-glass-tab">${n}</button>`);
931
+ for (const e of this.tabs) {
932
+ const n = (e == null ? void 0 : e.label) ?? e, s = m(`<button class="bw-glass-tab">${n}</button>`);
908
933
  t.append(s);
909
934
  }
910
935
  return t;
911
936
  }
912
937
  createActions() {
913
- const t = document.createElement("bw-glass-action-container"), i = this.actions === void 0 ? ft : Array.isArray(this.actions) ? this.actions : [];
914
- for (const n of i) {
938
+ const t = document.createElement("bw-glass-action-container"), e = this.actions === void 0 ? ft : Array.isArray(this.actions) ? this.actions : [];
939
+ for (const n of e) {
915
940
  const s = (n == null ? void 0 : n.label) ?? n, o = n.className ? `bw-glass-action ${n.className}` : "bw-glass-action", h = m(`<button class="${o}">${s}</button>`);
916
941
  typeof n.onClick == "function" && h.addEventListener("click", (l) => {
917
942
  n.onClick(l, this.binaryWindow);
@@ -929,33 +954,33 @@ class T {
929
954
  const wt = {
930
955
  activeDragGlassEl: null,
931
956
  activeDragGlassPaneCanDrop: !1,
932
- onPaneDrop(e, t) {
957
+ onPaneDrop(i, t) {
933
958
  if (!this.activeDragGlassEl) return;
934
- const i = this.activeDropPaneEl.getAttribute("drop-area");
935
- if (i === "center") {
936
- const n = this.activeDragGlassEl.closest("bw-pane"), s = this.activeDropPaneEl.getAttribute("can-drop") !== "false";
937
- H(n, this.activeDropPaneEl), n.setAttribute("can-drop", s);
959
+ const e = this.activeDropPaneEl.getAttribute("drop-area");
960
+ if (e === "center") {
961
+ const n = this.activeDragGlassEl.closest("bw-pane");
962
+ this.swapPanes(n, this.activeDropPaneEl);
938
963
  return;
939
964
  } else {
940
- const n = B(this.activeDragGlassEl);
941
- this.addPane(t.id, { position: i }).domNode.append(this.activeDragGlassEl), this.removePane(n);
965
+ const n = R(this.activeDragGlassEl);
966
+ this.removePane(n), this.addPane(t.id, { position: e, id: n }).domNode.append(this.activeDragGlassEl);
942
967
  }
943
968
  },
944
969
  enableDrag() {
945
- document.addEventListener("mousedown", (e) => {
946
- if (e.button !== 0 || !e.target.matches("bw-glass-header")) return;
947
- if (e.target.getAttribute("can-drag") === "false") {
948
- e.preventDefault();
970
+ document.addEventListener("mousedown", (i) => {
971
+ if (i.button !== 0 || !i.target.matches("bw-glass-header")) return;
972
+ if (i.target.getAttribute("can-drag") === "false") {
973
+ i.preventDefault();
949
974
  return;
950
975
  }
951
- const i = e.target.closest("bw-glass");
952
- i.setAttribute("draggable", !0), this.activeDragGlassEl = i;
976
+ const e = i.target.closest("bw-glass");
977
+ e.setAttribute("draggable", !0), this.activeDragGlassEl = e;
953
978
  }), document.addEventListener("mouseup", () => {
954
979
  this.activeDragGlassEl && (this.activeDragGlassEl.removeAttribute("draggable"), this.activeDragGlassEl = null);
955
- }), this.windowElement.addEventListener("dragstart", (e) => {
956
- if (!(e.target instanceof HTMLElement) || !e.target.matches("bw-glass") || !this.activeDragGlassEl)
980
+ }), this.windowElement.addEventListener("dragstart", (i) => {
981
+ if (!(i.target instanceof HTMLElement) || !i.target.matches("bw-glass") || !this.activeDragGlassEl)
957
982
  return;
958
- e.dataTransfer.effectAllowed = "move";
983
+ i.dataTransfer.effectAllowed = "move";
959
984
  const t = this.activeDragGlassEl.closest("bw-pane");
960
985
  this.activeDragGlassPaneCanDrop = t.getAttribute("can-drop") !== "false", t.setAttribute("can-drop", !1);
961
986
  }), this.windowElement.addEventListener("dragend", () => {
@@ -963,32 +988,32 @@ const wt = {
963
988
  });
964
989
  }
965
990
  }, mt = {
966
- trimMuntin(e) {
967
- 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`);
991
+ trimMuntin(i) {
992
+ i.hasAttribute("vertical") ? (i.style.top = `${parseFloat(i.style.top) + this.muntinSize / 2}px`, i.style.height = `${parseFloat(i.style.height) - this.muntinSize}px`) : i.hasAttribute("horizontal") && (i.style.left = `${parseFloat(i.style.left) + this.muntinSize / 2}px`, i.style.width = `${parseFloat(i.style.width) - this.muntinSize}px`);
968
993
  },
969
- onMuntinCreate(e) {
970
- this.trimMuntin(e);
994
+ onMuntinCreate(i) {
995
+ this.trimMuntin(i);
971
996
  },
972
- onMuntinUpdate(e) {
973
- this.trimMuntin(e);
997
+ onMuntinUpdate(i) {
998
+ this.trimMuntin(i);
974
999
  }
975
1000
  };
976
- class bt extends L {
1001
+ class bt extends B {
977
1002
  constructor() {
978
1003
  super(...arguments);
979
1004
  f(this, "sillElement", null);
980
1005
  }
981
1006
  frame() {
982
1007
  super.frame(...arguments);
983
- const i = m("<bw-sill />");
984
- this.windowElement.append(i), this.sillElement = i;
1008
+ const e = m("<bw-sill />");
1009
+ this.windowElement.append(e), this.sillElement = e;
985
1010
  }
986
1011
  enableFeatures() {
987
1012
  super.enableFeatures(), this.enableDrag(), this.enableActions();
988
1013
  }
989
- onPaneCreate(i, n) {
1014
+ onPaneCreate(e, n) {
990
1015
  const s = new T({ ...n.store, sash: n, binaryWindow: this });
991
- i.innerHTML = "", i.append(s.domNode), this.debug && s.contentElement.prepend(`${n.id}`);
1016
+ e.innerHTML = "", e.append(s.domNode), this.debug && s.contentElement.prepend(`${n.id}`);
992
1017
  }
993
1018
  onPaneUpdate() {
994
1019
  }
@@ -999,18 +1024,18 @@ class bt extends L {
999
1024
  * @param {Object} props - The pane and glass properties grouped together
1000
1025
  * @returns {Sash} - The newly created Sash
1001
1026
  */
1002
- addPane(i, n) {
1003
- const { position: s, size: o, ...h } = n, l = super.addPane(i, { position: s, size: o }), d = new T({ ...h, sash: l, binaryWindow: this });
1004
- return l.domNode.append(d.domNode), l;
1027
+ addPane(e, n) {
1028
+ const { position: s, size: o, id: h, ...l } = n, d = super.addPane(e, { position: s, size: o, id: h }), a = new T({ ...l, sash: d, binaryWindow: this });
1029
+ return d.domNode.append(a.domNode), d;
1005
1030
  }
1006
1031
  }
1007
1032
  bt.assemble(wt, mt, gt);
1008
1033
  export {
1009
1034
  ft as BUILTIN_ACTIONS,
1010
1035
  bt as BinaryWindow,
1011
- K as ConfigRoot,
1012
- L as Frame,
1036
+ j as ConfigRoot,
1037
+ B as Frame,
1013
1038
  r as Position,
1014
1039
  g as Sash,
1015
- V as SashConfig
1040
+ K as SashConfig
1016
1041
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "bwin",
3
3
  "description": "A tiling window manager for web browsers",
4
4
  "type": "module",
5
- "version": "0.2.3",
5
+ "version": "0.2.5",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/bhjsdev/bwin.git"