bwin 0.2.3 → 0.2.4

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 +226 -214
  2. package/package.json +1 -1
package/dist/bwin.js CHANGED
@@ -1,35 +1,35 @@
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);
1
+ var B = Object.defineProperty;
2
+ var $ = (e, t, i) => t in e ? B(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
3
+ var f = (e, t, i) => $(e, typeof t != "symbol" ? t + "" : t, i);
4
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);
6
- return `rgba(${n}, ${s}, ${o}, ${h})`;
5
+ const i = 256 - t, n = Math.floor(Math.random() * i + t), o = Math.floor(Math.random() * i + t), s = Math.floor(Math.random() * i + t), h = Math.max(0.5, Math.random() * e);
6
+ return `rgba(${n}, ${o}, ${s}, ${h})`;
7
7
  }
8
- function z(e = 2, t = 3) {
8
+ function C(e = 2, t = 3) {
9
9
  if (e < 0 || t < 0)
10
10
  throw new Error("Parameters must be non-negative numbers");
11
11
  const i = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", n = "0123456789";
12
- let s = "";
13
- for (let o = 0; o < e; o++) {
12
+ let o = "";
13
+ for (let s = 0; s < e; s++) {
14
14
  const h = Math.floor(Math.random() * i.length);
15
- s += i[h];
15
+ o += i[h];
16
16
  }
17
- s += "-";
18
- for (let o = 0; o < t; o++) {
17
+ o += "-";
18
+ for (let s = 0; s < t; s++) {
19
19
  const h = Math.floor(Math.random() * n.length);
20
- s += n[h];
20
+ o += n[h];
21
21
  }
22
- return s;
22
+ return o;
23
23
  }
24
- function b(e, t) {
24
+ function R(e, t) {
25
25
  for (; t.firstChild; )
26
26
  e.append(t.firstChild);
27
27
  }
28
28
  function H(e, t) {
29
29
  const i = document.createElement("div");
30
- b(i, e), b(e, t), b(t, i);
30
+ R(i, e), R(e, t), R(t, i);
31
31
  }
32
- function C(e) {
32
+ function b(e) {
33
33
  if (typeof e == "number" && !isNaN(e))
34
34
  return e;
35
35
  if (typeof e == "string") {
@@ -53,7 +53,7 @@ function C(e) {
53
53
  function I(e) {
54
54
  return e !== null && typeof e == "object" && !Array.isArray(e) && Object.getPrototypeOf(e) === Object.prototype;
55
55
  }
56
- function O(e, t) {
56
+ function P(e, t) {
57
57
  for (const i in t) {
58
58
  if (Object.hasOwn(e, i))
59
59
  throw new Error(`Key "${i}" already exists in target object`);
@@ -61,7 +61,7 @@ function O(e, t) {
61
61
  }
62
62
  return e;
63
63
  }
64
- function G(e) {
64
+ function O(e) {
65
65
  const t = document.createElement("template");
66
66
  return t.innerHTML = e.trim(), t.content;
67
67
  }
@@ -70,16 +70,16 @@ function m(e) {
70
70
  return null;
71
71
  if (typeof e == "string")
72
72
  try {
73
- const t = G(e);
73
+ const t = O(e);
74
74
  return t.childNodes.length === 1 ? t.firstChild : t;
75
75
  } catch {
76
76
  return document.createTextNode(e);
77
77
  }
78
78
  return e instanceof Node ? e : document.createTextNode(String(e));
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(e) {
81
+ const t = parseFloat(e.style.left) || 0, i = parseFloat(e.style.top) || 0, n = parseFloat(e.style.width) || 0, o = parseFloat(e.style.height) || 0;
82
+ return { left: t, top: i, width: n, height: o };
83
83
  }
84
84
  const r = {
85
85
  Top: "top",
@@ -91,7 +91,7 @@ const r = {
91
91
  Unknown: "unknown",
92
92
  Outside: "outside"
93
93
  };
94
- function F(e) {
94
+ function G(e) {
95
95
  switch (e) {
96
96
  case r.Top:
97
97
  return r.Bottom;
@@ -105,50 +105,50 @@ function F(e) {
105
105
  throw new Error(`[bwin] Invalid position: ${e}`);
106
106
  }
107
107
  }
108
- function _({ width: e, height: t, x: i }) {
108
+ function F({ width: e, height: t, x: i }) {
109
109
  return t / e * i;
110
110
  }
111
- function k({ width: e, height: t, y: i }) {
111
+ function _({ width: e, height: t, y: i }) {
112
112
  return e / t * i;
113
113
  }
114
- function U({ width: e, height: t, x: i }) {
114
+ function k({ width: e, height: t, x: i }) {
115
115
  return t - t / e * i;
116
116
  }
117
- function Y({ width: e, height: t, y: i }) {
117
+ function U({ width: e, height: t, y: i }) {
118
118
  return e - e / t * i;
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;
122
- if (h < 0 || h > s || l < 0 || l > o)
120
+ function Y(e, { clientX: t, clientY: i }) {
121
+ const n = e.getBoundingClientRect(), { width: o, height: s } = n, h = t - n.left, l = i - n.top;
122
+ if (h < 0 || h > o || l < 0 || l > s)
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 });
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;
124
+ const d = 0.3, a = F({ width: o, height: s, x: h }), c = k({ width: o, height: s, x: h }), p = _({ width: o, height: s, y: l }), u = U({ width: o, height: s, y: l });
125
+ return h < o * (0.5 - d / 2) && l > a && l < c ? r.Left : h > o * (0.5 + d / 2) && l < a && l > c ? r.Right : l < s * (0.5 - d / 2) && h > p && h < u ? r.Top : l > s * (0.5 + d / 2) && h < p && h > u ? r.Bottom : h > o * (0.5 - d / 2) && h < o * (0.5 + d / 2) && l > s * (0.5 - d / 2) && l < s * (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
139
  top: i = w.top,
140
140
  width: n = w.width,
141
- height: s = w.height,
142
- minWidth: o = w.minWidth,
141
+ height: o = w.height,
142
+ minWidth: s = w.minWidth,
143
143
  minHeight: h = w.minHeight,
144
144
  domNode: l = null,
145
145
  store: d = {},
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 = i, this._left = t, this._width = n, this._height = o, this.children = [], this.minWidth = s, this.minHeight = h, this.store = d;
152
152
  }
153
153
  walk(t) {
154
154
  this.children.forEach((i) => i.walk(t)), t(this);
@@ -183,10 +183,10 @@ 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;
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];
186
+ let t = null, i = null, n = null, o = null;
187
+ for (const s of this.children)
188
+ s.position === r.Left ? t = s : s.position === r.Right ? i = s : s.position === r.Top ? n = s : s.position === r.Bottom && (o = s);
189
+ return [n, i, o, t];
190
190
  }
191
191
  getAllLeafDescendants() {
192
192
  const t = [];
@@ -197,27 +197,27 @@ class g {
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();
203
- return Math.max(this.minWidth, o);
200
+ const [t, i, n, o] = this.getChildren();
201
+ if (o && i) {
202
+ const s = o.calcMinWidth() + i.calcMinWidth();
203
+ return Math.max(this.minWidth, s);
204
204
  }
205
205
  if (t && n) {
206
- const o = Math.max(t.calcMinWidth(), n.calcMinWidth());
207
- return Math.max(this.minWidth, o);
206
+ const s = Math.max(t.calcMinWidth(), n.calcMinWidth());
207
+ return Math.max(this.minWidth, s);
208
208
  }
209
209
  }
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());
216
- return Math.max(this.minHeight, o);
213
+ const [t, i, n, o] = this.getChildren();
214
+ if (o && i) {
215
+ const s = Math.max(o.calcMinHeight(), i.calcMinHeight());
216
+ return Math.max(this.minHeight, s);
217
217
  }
218
218
  if (t && n) {
219
- const o = t.calcMinHeight() + n.calcMinHeight();
220
- return Math.max(this.minHeight, o);
219
+ const s = t.calcMinHeight() + n.calcMinHeight();
220
+ return Math.max(this.minHeight, s);
221
221
  }
222
222
  }
223
223
  // Get self or descendant by id
@@ -262,8 +262,8 @@ class g {
262
262
  set top(t) {
263
263
  const i = t - this._top;
264
264
  this._top = t;
265
- const [n, s, o, h] = this.getChildren();
266
- n && o && (n.top += i, o.top += i), h && s && (h.top += i, s.top += i);
265
+ const [n, o, s, h] = this.getChildren();
266
+ n && s && (n.top += i, s.top += i), h && o && (h.top += i, o.top += i);
267
267
  }
268
268
  get left() {
269
269
  return this._left;
@@ -271,8 +271,8 @@ class g {
271
271
  set left(t) {
272
272
  const i = t - this._left;
273
273
  this._left = t;
274
- const [n, s, o, h] = this.getChildren();
275
- h && s && (h.left += i, s.left += i), n && o && (n.left += i, o.left += i);
274
+ const [n, o, s, h] = this.getChildren();
275
+ h && o && (h.left += i, o.left += i), n && s && (n.left += i, s.left += i);
276
276
  }
277
277
  get width() {
278
278
  return this._width;
@@ -280,14 +280,14 @@ class g {
280
280
  set width(t) {
281
281
  const i = t - this._width;
282
282
  this._width = t;
283
- const [n, s, o, h] = this.getChildren();
284
- if (h && s) {
285
- const l = h.width + s.width, d = i * (h.width / l), a = l + i;
286
- 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;
283
+ const [n, o, s, h] = this.getChildren();
284
+ if (h && o) {
285
+ const l = h.width + o.width, d = i * (h.width / l), a = l + i;
286
+ let c = h.width + d, p = a - c, u = o.left + d;
287
+ const E = h.calcMinWidth(), y = o.calcMinWidth();
288
+ i < 0 && (c < E && p > y ? (c = h.width, p = a - c, u = h.left + c) : p < y && c > E && (p = o.width, c = a - p, u = h.left + c)), h.width = c, o.width = p, o.left = u;
289
289
  }
290
- n && o && (n.width += i, o.width += i);
290
+ n && s && (n.width += i, s.width += i);
291
291
  }
292
292
  get height() {
293
293
  return this._height;
@@ -295,30 +295,30 @@ class g {
295
295
  set height(t) {
296
296
  const i = t - this._height;
297
297
  this._height = t;
298
- const [n, s, o, h] = this.getChildren();
299
- if (n && o) {
300
- const l = n.height + o.height, d = i * (n.height / l), a = l + i;
301
- let c = n.height + d, p = a - c, u = o.top + d;
298
+ const [n, o, s, h] = this.getChildren();
299
+ if (n && s) {
300
+ const l = n.height + s.height, d = i * (n.height / l), a = l + i;
301
+ let c = n.height + d, p = a - c, u = s.top + d;
302
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);
303
+ const E = n.calcMinHeight(), y = s.calcMinHeight();
304
+ c < E && p > y ? (c = n.height, p = a - c, u = n.top + c) : p < y && c > E && (p = s.height, c = a - p, u = n.top + c);
305
305
  }
306
- n.height = c, o.height = p, o.top = u;
306
+ n.height = c, s.height = p, s.top = u;
307
307
  }
308
- h && s && (h.height += i, s.height += i);
308
+ h && o && (h.height += i, o.height += i);
309
309
  }
310
310
  }
311
- const v = {
311
+ const S = {
312
312
  size: "50%",
313
313
  position: r.Left
314
314
  };
315
- class R {
315
+ class A {
316
316
  constructor({
317
317
  parentRect: t,
318
318
  children: i,
319
319
  siblingConfigNode: n,
320
- id: s,
321
- minWidth: o,
320
+ id: o,
321
+ minWidth: s,
322
322
  minHeight: h,
323
323
  position: l,
324
324
  size: d,
@@ -328,12 +328,12 @@ class R {
328
328
  f(this, "top");
329
329
  f(this, "width");
330
330
  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();
331
+ this.parentRect = t, this.children = i, this.siblingConfigNode = n, this.id = o, this.minWidth = s, this.minHeight = h, this.position = this.getPosition(l), this.size = this.getSize(d), this.nonCoreData = a, this.setBounds();
332
332
  }
333
333
  getPosition(t) {
334
334
  if (!this.siblingConfigNode)
335
335
  return t;
336
- const i = F(this.siblingConfigNode.position);
336
+ const i = G(this.siblingConfigNode.position);
337
337
  if (!t)
338
338
  return i;
339
339
  if (t !== i)
@@ -342,7 +342,7 @@ class R {
342
342
  }
343
343
  getSize(t) {
344
344
  if (!this.siblingConfigNode)
345
- return C(t);
345
+ return b(t);
346
346
  if (!t) {
347
347
  if (this.siblingConfigNode.size < 1)
348
348
  return 1 - this.siblingConfigNode.size;
@@ -351,7 +351,7 @@ class R {
351
351
  if (this.siblingConfigNode.position === r.Top || this.siblingConfigNode.position === r.Bottom)
352
352
  return this.parentRect.height - this.siblingConfigNode.height;
353
353
  }
354
- const i = C(t);
354
+ const i = b(t);
355
355
  if (i < 1) {
356
356
  if (i + this.siblingConfigNode.size !== 1)
357
357
  throw new Error("[bwin] Sum of sibling sizes is not equal to 1");
@@ -401,7 +401,7 @@ class R {
401
401
  children: t
402
402
  };
403
403
  if (typeof t == "string" || typeof t == "number") {
404
- const i = C(t);
404
+ const i = b(t);
405
405
  if (isNaN(i))
406
406
  throw new Error(`[bwin] Invalid size value: ${i}`);
407
407
  return {
@@ -413,27 +413,27 @@ class R {
413
413
  throw new Error(`[bwin] Invalid config value: ${t}`);
414
414
  }
415
415
  }
416
- createPrimaryConfigNode({ size: t, position: i, children: n, id: s, minWidth: o, minHeight: h, ...l }) {
417
- return new R({
416
+ createPrimaryConfigNode({ size: t, position: i, children: n, id: o, minWidth: s, minHeight: h, ...l }) {
417
+ return new A({
418
418
  parentRect: this,
419
- size: t ?? v.size,
420
- position: i ?? v.position,
419
+ size: t ?? S.size,
420
+ position: i ?? S.position,
421
421
  children: n,
422
- id: s,
423
- minWidth: o,
422
+ id: o,
423
+ minWidth: s,
424
424
  minHeight: h,
425
425
  ...l
426
426
  });
427
427
  }
428
- createSecondaryConfigNode({ size: t, position: i, children: n, id: s, minWidth: o, minHeight: h, ...l }, d) {
429
- return new R({
428
+ createSecondaryConfigNode({ size: t, position: i, children: n, id: o, minWidth: s, minHeight: h, ...l }, d) {
429
+ return new A({
430
430
  parentRect: this,
431
431
  size: t,
432
432
  position: i,
433
433
  children: n,
434
434
  siblingConfigNode: d,
435
- id: s,
436
- minWidth: o,
435
+ id: o,
436
+ minWidth: s,
437
437
  minHeight: h,
438
438
  ...l
439
439
  });
@@ -443,32 +443,32 @@ class R {
443
443
  if (!Array.isArray(this.children) || this.children.length === 0)
444
444
  return t;
445
445
  const i = this.normConfig(this.children[0]), n = this.normConfig(this.children.at(1));
446
- let s, o;
447
- return !i.size && !i.position && n ? (n.position || (n.position = r.Right), s = this.createPrimaryConfigNode(n), o = this.createSecondaryConfigNode(
446
+ let o, s;
447
+ return !i.size && !i.position && n ? (n.position || (n.position = r.Right), o = this.createPrimaryConfigNode(n), s = this.createSecondaryConfigNode(
448
448
  i,
449
- s
450
- )) : (s = this.createPrimaryConfigNode(i), o = this.createSecondaryConfigNode(
449
+ o
450
+ )) : (o = this.createPrimaryConfigNode(i), s = this.createSecondaryConfigNode(
451
451
  n,
452
- s
453
- )), s && o && (t.children.push(s.buildSashTree()), t.children.push(o.buildSashTree())), t;
452
+ o
453
+ )), o && s && (t.children.push(o.buildSashTree()), t.children.push(s.buildSashTree())), t;
454
454
  }
455
455
  }
456
- const S = {
456
+ const z = {
457
457
  width: 333,
458
458
  height: 333
459
459
  }, D = {
460
460
  fitContainer: !1
461
461
  };
462
- class K extends R {
462
+ class j extends A {
463
463
  constructor({
464
464
  id: t,
465
465
  children: i,
466
- width: n = S.width,
467
- height: s = S.height,
468
- fitContainer: o = D.fitContainer,
466
+ width: n = z.width,
467
+ height: o = z.height,
468
+ fitContainer: s = D.fitContainer,
469
469
  ...h
470
470
  } = {
471
- ...S,
471
+ ...z,
472
472
  ...D
473
473
  }) {
474
474
  super({
@@ -476,17 +476,17 @@ class K extends R {
476
476
  children: i,
477
477
  size: NaN,
478
478
  position: r.Root,
479
- parentRect: { width: n, height: s },
479
+ parentRect: { width: n, height: o },
480
480
  ...h
481
- }), this.fitContainer = o;
481
+ }), this.fitContainer = s;
482
482
  }
483
483
  }
484
- class V extends g {
484
+ class K extends g {
485
485
  constructor(t = w) {
486
486
  super({ ...t, position: r.Root }), Object.assign(this, D);
487
487
  }
488
488
  }
489
- function M(e) {
489
+ function V(e) {
490
490
  const t = document.createElement("bw-pane");
491
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
492
  }
@@ -494,107 +494,119 @@ function J(e) {
494
494
  const t = e.domNode;
495
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
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);
497
+ function Q(e, { size: t, id: i }) {
498
+ const n = b(t);
499
+ let o = e.width / 2;
500
+ n && (n < 1 ? o = e.width * n : o = n);
501
501
  const s = new g({
502
+ id: i,
502
503
  top: e.top,
503
504
  left: e.left,
504
- width: n,
505
+ width: o,
505
506
  height: e.height,
506
507
  position: r.Left
507
- }), o = new g({
508
+ }), h = new g({
509
+ id: e.id,
508
510
  top: e.top,
509
511
  left: e.left + s.width,
510
- width: e.width - n,
512
+ width: e.width - o,
511
513
  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;
514
+ position: r.Right,
515
+ domNode: e.domNode
516
+ });
517
+ return e.addChild(s), e.addChild(h), e.domNode = null, e.id = C(), s;
515
518
  }
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);
519
+ function Z(e, { size: t, id: i }) {
520
+ const n = b(t);
521
+ let o = e.width / 2;
522
+ n && (n < 1 ? o = e.width * n : o = n);
520
523
  const s = new g({
524
+ id: e.id,
521
525
  left: e.left,
522
526
  top: e.top,
523
- width: e.width - n,
527
+ width: e.width - o,
524
528
  height: e.height,
525
- position: r.Left
526
- }), o = new g({
529
+ position: r.Left,
530
+ domNode: e.domNode
531
+ }), h = new g({
532
+ id: i,
527
533
  left: e.left + s.width,
528
534
  top: e.top,
529
- width: n,
535
+ width: o,
530
536
  height: e.height,
531
537
  position: r.Right
532
- }), h = M(s);
533
- return s.domNode = h, b(h, e.domNode), e.addChild(s), e.addChild(o), o;
538
+ });
539
+ return e.addChild(s), e.addChild(h), e.domNode = null, e.id = C(), h;
534
540
  }
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);
541
+ function tt(e, { size: t, id: i }) {
542
+ const n = b(t);
543
+ let o = e.height / 2;
544
+ n && (n < 1 ? o = e.height * n : o = n);
539
545
  const s = new g({
546
+ id: i,
540
547
  left: e.left,
541
548
  top: e.top,
542
549
  width: e.width,
543
- height: n,
550
+ height: o,
544
551
  position: r.Top
545
- }), o = new g({
552
+ }), h = new g({
553
+ id: e.id,
546
554
  left: e.left,
547
555
  top: e.top + s.height,
548
556
  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;
557
+ height: e.height - o,
558
+ position: r.Bottom,
559
+ domNode: e.domNode
560
+ });
561
+ return e.addChild(s), e.addChild(h), e.domNode = null, e.id = C(), s;
553
562
  }
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);
563
+ function et(e, { size: t, id: i }) {
564
+ const n = b(t);
565
+ let o = e.height / 2;
566
+ n && (n < 1 ? o = e.height * n : o = n);
558
567
  const s = new g({
568
+ id: e.id,
559
569
  top: e.top,
560
570
  left: e.left,
561
571
  width: e.width,
562
- height: e.height - n,
563
- position: r.Top
564
- }), o = new g({
572
+ height: e.height - o,
573
+ position: r.Top,
574
+ domNode: e.domNode
575
+ }), h = new g({
576
+ id: i,
565
577
  top: e.top + s.height,
566
578
  left: e.left,
567
579
  width: e.width,
568
- height: n,
580
+ height: o,
569
581
  position: r.Bottom
570
- }), h = M(s);
571
- return s.domNode = h, b(h, e.domNode), e.addChild(s), e.addChild(o), o;
582
+ });
583
+ return e.addChild(s), e.addChild(h), e.domNode = null, e.id = C(), h;
572
584
  }
573
- function it(e, { position: t, size: i, minWidth: n, minHeight: s }) {
585
+ function it(e, { position: t, size: i, id: n, minWidth: o, minHeight: s }) {
574
586
  if (t === r.Left)
575
- return Q(e, { size: i });
587
+ return Q(e, { size: i, id: n });
576
588
  if (t === r.Right)
577
- return Z(e, { size: i });
589
+ return Z(e, { size: i, id: n });
578
590
  if (t === r.Top)
579
- return tt(e, { size: i });
591
+ return tt(e, { size: i, id: n });
580
592
  if (t === r.Bottom)
581
- return et(e, { size: i });
593
+ return et(e, { size: i, id: n });
582
594
  }
583
595
  const nt = {
584
596
  createPane(e) {
585
- const t = M(e);
597
+ const t = V(e);
586
598
  return e.store.droppable === !1 && t.setAttribute("can-drop", "false"), t;
587
599
  },
588
600
  // Intended to be overridden
589
601
  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)));
602
+ t.store.content && e.append(m(t.store.content)), this != null && this.debug && (e.style.backgroundColor = W(), e.innerHTML = "", e.append(v(e)));
591
603
  },
592
604
  updatePane(e) {
593
605
  return J(e);
594
606
  },
595
607
  // Intended to be overridden
596
608
  onPaneUpdate(e, t) {
597
- this != null && this.debug && (e.innerHTML = "", e.append(x(e)));
609
+ this != null && this.debug && (e.innerHTML = "", e.append(v(e)));
598
610
  },
599
611
  /**
600
612
  * Add a pane into the target pane. The two panes become next to each other
@@ -603,12 +615,12 @@ const nt = {
603
615
  * @param {'top'|'right'|'bottom'|'left'} position - The position of the new pane relative to the target pane
604
616
  * @returns {Sash} - The newly created sash
605
617
  */
606
- addPane(e, { position: t, size: i }) {
618
+ addPane(e, { position: t, size: i, id: n }) {
607
619
  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;
620
+ const o = this.rootSash.getById(e);
621
+ if (!o) throw new Error("[bwin] Parent sash not found when adding pane");
622
+ const s = it(o, { position: t, size: i, id: n });
623
+ return this.update(), s;
612
624
  },
613
625
  /**
614
626
  * Remove a pane
@@ -619,10 +631,10 @@ const nt = {
619
631
  const t = this.rootSash.getDescendantParentById(e);
620
632
  if (!t) throw new Error("[bwin] Parent sash not found when removing pane");
621
633
  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();
634
+ i.children.length === 0 ? (t.id = i.id, t.domNode = i.domNode, t.domNode.setAttribute("sash-id", i.id), t.children = []) : (t.id = C(), 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();
623
635
  }
624
636
  };
625
- function x(e) {
637
+ function v(e) {
626
638
  const t = document.createElement("pre");
627
639
  t.style.fontSize = "10px";
628
640
  const i = `
@@ -635,7 +647,7 @@ height: ${e.style.height}
635
647
  `;
636
648
  return t.innerHTML = i.trim(), t;
637
649
  }
638
- const st = {
650
+ const ot = {
639
651
  createWindow() {
640
652
  const e = document.createElement("bw-window");
641
653
  return e.style.width = `${this.rootSash.width}px`, e.style.height = `${this.rootSash.height}px`, e.setAttribute("root-sash-id", this.rootSash.id), e;
@@ -656,7 +668,7 @@ const st = {
656
668
  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));
657
669
  });
658
670
  }
659
- }, ot = {
671
+ }, st = {
660
672
  muntinSize: 4,
661
673
  createMuntin(e) {
662
674
  const t = document.createElement("bw-muntin"), i = e.leftChild, n = e.topChild;
@@ -700,11 +712,11 @@ const st = {
700
712
  this.activeMuntinSash = this.rootSash.getById(t), this.activeMuntinSash && (this.isResizeStarted = !0, this.lastX = e.pageX, this.lastY = e.pageY, this.applyResizeStyles());
701
713
  }), document.addEventListener("mousemove", (e) => {
702
714
  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;
715
+ const [t, i, n, o] = this.activeMuntinSash.getChildren(), s = this.activeMuntinSash.isLeftRightSplit(), h = this.activeMuntinSash.isTopBottomSplit();
716
+ if (s && o && i) {
717
+ const l = e.pageX - this.lastX, d = o.width + l, a = i.width - l;
718
+ if (l > 0 && a <= i.calcMinWidth() || l < 0 && d <= o.calcMinWidth()) return;
719
+ o.width = d, i.width = a, i.left = i.left + l, this.update(), this.lastX = e.pageX;
708
720
  } else if (h && t && n) {
709
721
  const l = e.pageY - this.lastY, d = t.height + l, a = n.height - l;
710
722
  if (l > 0 && a <= n.calcMinHeight() || l < 0 && d <= t.calcMinHeight()) return;
@@ -724,7 +736,7 @@ const st = {
724
736
  e.preventDefault();
725
737
  const t = e.target.matches("bw-pane") ? e.target : e.target.closest("bw-pane");
726
738
  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);
739
+ const i = Y(t, e);
728
740
  t.setAttribute("drop-area", i);
729
741
  }), this.windowElement.addEventListener("dragleave", (e) => {
730
742
  e.currentTarget.contains(e.relatedTarget) && e.currentTarget !== e.relatedTarget || this.activeDropPaneEl && (this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = null);
@@ -735,13 +747,13 @@ const st = {
735
747
  });
736
748
  }
737
749
  }, dt = !1;
738
- class L {
750
+ class T {
739
751
  constructor(t) {
740
752
  f(this, "windowElement", null);
741
753
  f(this, "containerElement", null);
742
754
  f(this, "debug", dt);
743
755
  let i = null;
744
- t instanceof V ? (i = t, this.rootSash = t) : (i = new K(t), this.rootSash = i.buildSashTree()), this.fitContainer = i.fitContainer;
756
+ t instanceof K ? (i = t, this.rootSash = t) : (i = new j(t), this.rootSash = i.buildSashTree()), this.fitContainer = i.fitContainer;
745
757
  }
746
758
  frame(t) {
747
759
  this.containerElement = t, this.windowElement = this.createWindow(), this.glaze(), this.containerElement.append(this.windowElement);
@@ -755,19 +767,19 @@ class L {
755
767
  }
756
768
  static assemble(...t) {
757
769
  t.forEach((i) => {
758
- O(this.prototype, i);
770
+ P(this.prototype, i);
759
771
  });
760
772
  }
761
773
  }
762
- L.assemble(
763
- st,
774
+ T.assemble(
764
775
  ot,
776
+ st,
765
777
  nt,
766
778
  ht,
767
779
  lt,
768
780
  rt
769
781
  );
770
- function B(e) {
782
+ function L(e) {
771
783
  if (e.tagName === "BW-PANE")
772
784
  return e.getAttribute("sash-id");
773
785
  const t = e.closest("bw-pane");
@@ -779,7 +791,7 @@ const at = {
779
791
  label: "",
780
792
  className: "bw-glass-action--close",
781
793
  onClick: (e, t) => {
782
- const i = B(e.target);
794
+ const i = L(e.target);
783
795
  t.removePane(i);
784
796
  }
785
797
  }, ct = {
@@ -790,22 +802,22 @@ const at = {
790
802
  if (!i) throw new Error("[bwin] Sill element not found when minimizing");
791
803
  const n = m('<button class="bw-minimized-glass" />');
792
804
  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);
805
+ const o = e.target.closest("bw-pane"), s = e.target.closest("bw-glass"), h = o.getAttribute("sash-id"), l = o.getAttribute("position");
806
+ n.bwGlassElement = s, n.bwOriginalPosition = l, n.bwOriginalBoundingRect = M(o), t.removePane(h);
795
807
  }
796
808
  }, pt = {
797
809
  label: "",
798
810
  className: "bw-glass-action--maximize",
799
811
  onClick: (e) => {
800
812
  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%");
813
+ 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
814
  }
803
815
  };
804
816
  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)
817
+ const i = e.left + e.width, n = e.top + e.height, o = t.left + t.width, s = t.top + t.height;
818
+ if (e.left >= o || t.left >= i || e.top >= s || t.top >= n)
807
819
  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);
820
+ const h = Math.max(e.left, t.left), l = Math.max(e.top, t.top), d = Math.min(i, o), a = Math.min(n, s);
809
821
  return {
810
822
  left: h,
811
823
  top: l,
@@ -820,23 +832,23 @@ const ft = [ct, pt, at], gt = {
820
832
  restoreGlass(e) {
821
833
  const t = e.bwOriginalBoundingRect;
822
834
  let i = 0, n = null;
823
- if (this.windowElement.querySelectorAll("bw-pane").forEach((s) => {
824
- const o = A(s), h = ut(t, o);
835
+ if (this.windowElement.querySelectorAll("bw-pane").forEach((o) => {
836
+ const s = M(o), h = ut(t, s);
825
837
  if (h) {
826
838
  const l = h.width * h.height;
827
- l > i && (i = l, n = s);
839
+ l > i && (i = l, n = o);
828
840
  }
829
841
  }), n) {
830
- const s = e.bwOriginalPosition, o = A(n), h = n.getAttribute("sash-id"), l = this.rootSash.getById(h);
842
+ const o = e.bwOriginalPosition, s = M(n), h = n.getAttribute("sash-id"), l = this.rootSash.getById(h);
831
843
  let d = 0;
832
- if (s === r.Left || s === r.Right)
833
- d = o.width - t.width < l.minWidth ? o.width / 2 : t.width;
834
- else if (s === r.Top || s === r.Bottom)
835
- d = o.height - t.height < l.minHeight ? o.height / 2 : t.height;
844
+ if (o === r.Left || o === r.Right)
845
+ d = s.width - t.width < l.minWidth ? s.width / 2 : t.width;
846
+ else if (o === r.Top || o === r.Bottom)
847
+ d = s.height - t.height < l.minHeight ? s.height / 2 : t.height;
836
848
  else
837
849
  throw new Error("[bwin] Invalid position when restoring glass");
838
850
  this.addPane(n.getAttribute("sash-id"), {
839
- position: s,
851
+ position: o,
840
852
  size: d
841
853
  }).domNode.append(e.bwGlassElement);
842
854
  }
@@ -876,26 +888,26 @@ const ft = [ct, pt, at], gt = {
876
888
  actions: void 0,
877
889
  draggable: !0
878
890
  };
879
- class T {
891
+ class x {
880
892
  constructor({
881
893
  title: t = N.title,
882
894
  content: i = N.content,
883
895
  tabs: n = N.tabs,
884
- actions: s = N.actions,
885
- draggable: o = N.draggable,
896
+ actions: o = N.actions,
897
+ draggable: s = N.draggable,
886
898
  sash: h,
887
899
  binaryWindow: l
888
900
  }) {
889
901
  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();
902
+ this.title = t, this.content = i, this.tabs = n, this.actions = o, this.sash = h, this.draggable = s, this.binaryWindow = l, this.build();
891
903
  }
892
904
  build() {
893
905
  const t = document.createElement("bw-glass-header");
894
906
  if (Array.isArray(this.tabs) && this.tabs.length > 0)
895
907
  t.append(this.createTabs());
896
908
  else if (this.title) {
897
- const s = document.createElement("bw-glass-title");
898
- s.append(m(this.title)), t.append(s);
909
+ const o = document.createElement("bw-glass-title");
910
+ o.append(m(this.title)), t.append(o);
899
911
  }
900
912
  t.setAttribute("can-drag", this.draggable), t.append(this.createActions());
901
913
  const i = document.createElement("bw-glass-content"), n = m(this.content);
@@ -904,15 +916,15 @@ class T {
904
916
  createTabs() {
905
917
  const t = document.createElement("bw-glass-tab-container");
906
918
  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>`);
908
- t.append(s);
919
+ const n = (i == null ? void 0 : i.label) ?? i, o = m(`<button class="bw-glass-tab">${n}</button>`);
920
+ t.append(o);
909
921
  }
910
922
  return t;
911
923
  }
912
924
  createActions() {
913
925
  const t = document.createElement("bw-glass-action-container"), i = this.actions === void 0 ? ft : Array.isArray(this.actions) ? this.actions : [];
914
926
  for (const n of i) {
915
- 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>`);
927
+ const o = (n == null ? void 0 : n.label) ?? n, s = n.className ? `bw-glass-action ${n.className}` : "bw-glass-action", h = m(`<button class="${s}">${o}</button>`);
916
928
  typeof n.onClick == "function" && h.addEventListener("click", (l) => {
917
929
  n.onClick(l, this.binaryWindow);
918
930
  }), t.append(h);
@@ -933,11 +945,11 @@ const wt = {
933
945
  if (!this.activeDragGlassEl) return;
934
946
  const i = this.activeDropPaneEl.getAttribute("drop-area");
935
947
  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);
948
+ const n = this.activeDragGlassEl.closest("bw-pane"), o = this.activeDropPaneEl.getAttribute("can-drop") !== "false";
949
+ H(n, this.activeDropPaneEl), n.setAttribute("can-drop", o);
938
950
  return;
939
951
  } else {
940
- const n = B(this.activeDragGlassEl);
952
+ const n = L(this.activeDragGlassEl);
941
953
  this.addPane(t.id, { position: i }).domNode.append(this.activeDragGlassEl), this.removePane(n);
942
954
  }
943
955
  },
@@ -973,7 +985,7 @@ const wt = {
973
985
  this.trimMuntin(e);
974
986
  }
975
987
  };
976
- class bt extends L {
988
+ class bt extends T {
977
989
  constructor() {
978
990
  super(...arguments);
979
991
  f(this, "sillElement", null);
@@ -987,8 +999,8 @@ class bt extends L {
987
999
  super.enableFeatures(), this.enableDrag(), this.enableActions();
988
1000
  }
989
1001
  onPaneCreate(i, n) {
990
- const s = new T({ ...n.store, sash: n, binaryWindow: this });
991
- i.innerHTML = "", i.append(s.domNode), this.debug && s.contentElement.prepend(`${n.id}`);
1002
+ const o = new x({ ...n.store, sash: n, binaryWindow: this });
1003
+ i.innerHTML = "", i.append(o.domNode), this.debug && o.contentElement.prepend(`${n.id}`);
992
1004
  }
993
1005
  onPaneUpdate() {
994
1006
  }
@@ -1000,17 +1012,17 @@ class bt extends L {
1000
1012
  * @returns {Sash} - The newly created Sash
1001
1013
  */
1002
1014
  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;
1015
+ const { position: o, size: s, id: h, ...l } = n, d = super.addPane(i, { position: o, size: s, id: h }), a = new x({ ...l, sash: d, binaryWindow: this });
1016
+ return d.domNode.append(a.domNode), d;
1005
1017
  }
1006
1018
  }
1007
1019
  bt.assemble(wt, mt, gt);
1008
1020
  export {
1009
1021
  ft as BUILTIN_ACTIONS,
1010
1022
  bt as BinaryWindow,
1011
- K as ConfigRoot,
1012
- L as Frame,
1023
+ j as ConfigRoot,
1024
+ T as Frame,
1013
1025
  r as Position,
1014
1026
  g as Sash,
1015
- V as SashConfig
1027
+ K as SashConfig
1016
1028
  };
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.4",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/bhjsdev/bwin.git"