react-bwin 0.3.5-dev.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import e, { forwardRef as t, useEffect as n, useImperativeHandle as r, useMemo as i, useRef as a, useState as o } from "react";
2
2
  import { createPortal as s } from "react-dom";
3
- //#region node_modules/.pnpm/bwin@0.3.3/node_modules/bwin/dist/bwin.js
3
+ //#region node_modules/.pnpm/bwin@0.4.1/node_modules/bwin/dist/bwin.js
4
4
  function c(e = .7, t = 128) {
5
5
  let n = 256 - t;
6
6
  return `rgba(${Math.floor(Math.random() * n + t)}, ${Math.floor(Math.random() * n + t)}, ${Math.floor(Math.random() * n + t)}, ${Math.max(.5, Math.random() * e)})`;
@@ -71,6 +71,10 @@ function g(e) {
71
71
  return e instanceof Node ? e : document.createTextNode(String(e));
72
72
  }
73
73
  function _(e) {
74
+ let t = document.createDocumentFragment();
75
+ return t.append(...e.childNodes), t;
76
+ }
77
+ function v(e) {
74
78
  return {
75
79
  left: parseFloat(e.style.left) || 0,
76
80
  top: parseFloat(e.style.top) || 0,
@@ -78,7 +82,7 @@ function _(e) {
78
82
  height: parseFloat(e.style.height) || 0
79
83
  };
80
84
  }
81
- var v = {
85
+ var y = {
82
86
  Top: "top",
83
87
  Right: "right",
84
88
  Bottom: "bottom",
@@ -88,50 +92,50 @@ var v = {
88
92
  Unknown: "unknown",
89
93
  Outside: "outside"
90
94
  };
91
- function y(e) {
95
+ function b(e) {
92
96
  switch (e) {
93
- case v.Top: return v.Bottom;
94
- case v.Right: return v.Left;
95
- case v.Bottom: return v.Top;
96
- case v.Left: return v.Right;
97
+ case y.Top: return y.Bottom;
98
+ case y.Right: return y.Left;
99
+ case y.Bottom: return y.Top;
100
+ case y.Left: return y.Right;
97
101
  default: throw Error(`[bwin] Invalid position: ${e}`);
98
102
  }
99
103
  }
100
- function b({ width: e, height: t, x: n }) {
104
+ function x({ width: e, height: t, x: n }) {
101
105
  return t / e * n;
102
106
  }
103
- function x({ width: e, height: t, y: n }) {
107
+ function ee({ width: e, height: t, y: n }) {
104
108
  return e / t * n;
105
109
  }
106
- function ee({ width: e, height: t, x: n }) {
110
+ function te({ width: e, height: t, x: n }) {
107
111
  return t - t / e * n;
108
112
  }
109
- function te({ width: e, height: t, y: n }) {
113
+ function ne({ width: e, height: t, y: n }) {
110
114
  return e - e / t * n;
111
115
  }
112
- function ne(e, { clientX: t, clientY: n }) {
116
+ function S(e, { clientX: t, clientY: n }) {
113
117
  let r = e.getBoundingClientRect(), { width: i, height: a } = r, o = t - r.left, s = n - r.top;
114
- if (o < 0 || o > i || s < 0 || s > a) return v.Outside;
115
- let c = .3, l = b({
118
+ if (o < 0 || o > i || s < 0 || s > a) return y.Outside;
119
+ let c = .3, l = x({
116
120
  width: i,
117
121
  height: a,
118
122
  x: o
119
- }), u = ee({
123
+ }), u = te({
120
124
  width: i,
121
125
  height: a,
122
126
  x: o
123
- }), d = x({
127
+ }), d = ee({
124
128
  width: i,
125
129
  height: a,
126
130
  y: s
127
- }), f = te({
131
+ }), f = ne({
128
132
  width: i,
129
133
  height: a,
130
134
  y: s
131
135
  });
132
- return o < i * (.5 - c / 2) && s > l && s < u ? v.Left : o > i * .65 && s < l && s > u ? v.Right : s < a * (.5 - c / 2) && o > d && o < f ? v.Top : s > a * .65 && o < d && o > f ? v.Bottom : o > i * (.5 - c / 2) && o < i * .65 && s > a * (.5 - c / 2) && s < a * .65 ? v.Center : v.Unknown;
136
+ return o < i * (.5 - c / 2) && s > l && s < u ? y.Left : o > i * .65 && s < l && s > u ? y.Right : s < a * (.5 - c / 2) && o > d && o < f ? y.Top : s > a * .65 && o < d && o > f ? y.Bottom : o > i * (.5 - c / 2) && o < i * .65 && s > a * (.5 - c / 2) && s < a * .65 ? y.Center : y.Unknown;
133
137
  }
134
- var S = {
138
+ var C = {
135
139
  left: 0,
136
140
  top: 0,
137
141
  width: 150,
@@ -139,8 +143,8 @@ var S = {
139
143
  minWidth: 100,
140
144
  minHeight: 100,
141
145
  resizeStrategy: "classic"
142
- }, C = class {
143
- constructor({ left: e = S.left, top: t = S.top, width: n = S.width, height: r = S.height, minWidth: i = S.minWidth, minHeight: a = S.minHeight, resizeStrategy: o = S.resizeStrategy, parent: s = null, domNode: c = null, store: u = {}, position: d, id: f } = S) {
146
+ }, w = class {
147
+ constructor({ left: e = C.left, top: t = C.top, width: n = C.width, height: r = C.height, minWidth: i = C.minWidth, minHeight: a = C.minHeight, resizeStrategy: o = C.resizeStrategy, parent: s = null, domNode: c = null, store: u = {}, position: d, id: f } = C) {
144
148
  if (this.id = f ?? l(), !d) throw Error("[bwin] Sash position is required");
145
149
  this.position = d, this.domNode = c, this.parent = s, this._top = t, this._left = e, this._width = n, this._height = r, this.children = [], this.minWidth = i, this.minHeight = a, this.resizeStrategy = o, this.store = u;
146
150
  }
@@ -154,26 +158,26 @@ var S = {
154
158
  return this.children.length > 0;
155
159
  }
156
160
  isLeftRightSplit() {
157
- return this.children.some((e) => e.position === v.Left || e.position === v.Right);
161
+ return this.children.some((e) => e.position === y.Left || e.position === y.Right);
158
162
  }
159
163
  isTopBottomSplit() {
160
- return this.children.some((e) => e.position === v.Top || e.position === v.Bottom);
164
+ return this.children.some((e) => e.position === y.Top || e.position === y.Bottom);
161
165
  }
162
166
  get leftChild() {
163
- return this.children.find((e) => e.position === v.Left);
167
+ return this.children.find((e) => e.position === y.Left);
164
168
  }
165
169
  get rightChild() {
166
- return this.children.find((e) => e.position === v.Right);
170
+ return this.children.find((e) => e.position === y.Right);
167
171
  }
168
172
  get topChild() {
169
- return this.children.find((e) => e.position === v.Top);
173
+ return this.children.find((e) => e.position === y.Top);
170
174
  }
171
175
  get bottomChild() {
172
- return this.children.find((e) => e.position === v.Bottom);
176
+ return this.children.find((e) => e.position === y.Bottom);
173
177
  }
174
178
  getChildren() {
175
179
  let e = null, t = null, n = null, r = null;
176
- for (let i of this.children) i.position === v.Left ? e = i : i.position === v.Right ? t = i : i.position === v.Top ? n = i : i.position === v.Bottom && (r = i);
180
+ for (let i of this.children) i.position === y.Left ? e = i : i.position === y.Right ? t = i : i.position === y.Top ? n = i : i.position === y.Bottom && (r = i);
177
181
  return [
178
182
  n,
179
183
  t,
@@ -232,7 +236,7 @@ var S = {
232
236
  }
233
237
  addChild(e) {
234
238
  if (this.children.length >= 2) throw Error("[bwin] Maximum 2 children allowed");
235
- this.children.push(e);
239
+ e.parent = this, this.children.push(e);
236
240
  }
237
241
  getDescendantParentById(e) {
238
242
  for (let t of this.children) {
@@ -245,6 +249,12 @@ var S = {
245
249
  getChildSiblingById(e) {
246
250
  return this.children.find((t) => t.id !== e);
247
251
  }
252
+ getLargestLeaf() {
253
+ return this.getAllLeafDescendants().reduce((e, t) => t.width * t.height > e.width * e.height ? t : e);
254
+ }
255
+ getRelativeSize() {
256
+ return this.parent ? this.position === y.Left || this.position === y.Right ? this.width / this.parent.width : this.height / this.parent.height : 1;
257
+ }
248
258
  get top() {
249
259
  return this._top;
250
260
  }
@@ -272,7 +282,7 @@ var S = {
272
282
  let [n, r, i, a] = this.getChildren();
273
283
  if (a && r) {
274
284
  let e = a.width + r.width, n = t * (a.width / e), i = e + t, o, s, c;
275
- if (this.resizeStrategy === "natural" && this.position === v.Left ? (o = a.width, s = r.width + t, c = r.left) : this.resizeStrategy === "natural" && this.position === v.Right ? (o = a.width + t, s = r.width, c = a.left + o) : (o = a.width + n, s = i - o, c = r.left + n), t < 0) {
285
+ if (this.resizeStrategy === "natural" && this.position === y.Left ? (o = a.width, s = r.width + t, c = r.left) : this.resizeStrategy === "natural" && this.position === y.Right ? (o = a.width + t, s = r.width, c = a.left + o) : (o = a.width + n, s = i - o, c = r.left + n), t < 0) {
276
286
  let e = a.calcMinWidth(), t = r.calcMinWidth();
277
287
  o < e && s > t ? (o = a.width, s = i - o, c = a.left + o) : s < t && o > e && (s = r.width, o = i - s, c = a.left + o);
278
288
  }
@@ -289,7 +299,7 @@ var S = {
289
299
  let [n, r, i, a] = this.getChildren();
290
300
  if (n && i) {
291
301
  let e = n.height + i.height, r = t * (n.height / e), a = e + t, o, s, c;
292
- if (this.resizeStrategy === "natural" && this.position === v.Top ? (o = n.height, s = i.height + t, c = i.top) : this.resizeStrategy === "natural" && this.position === v.Bottom ? (o = n.height + t, s = i.height, c = n.top + o) : (o = n.height + r, s = a - o, c = i.top + r), t < 0) {
302
+ if (this.resizeStrategy === "natural" && this.position === y.Top ? (o = n.height, s = i.height + t, c = i.top) : this.resizeStrategy === "natural" && this.position === y.Bottom ? (o = n.height + t, s = i.height, c = n.top + o) : (o = n.height + r, s = a - o, c = i.top + r), t < 0) {
293
303
  let e = n.calcMinHeight(), t = i.calcMinHeight();
294
304
  o < e && s > t ? (o = n.height, s = a - o, c = n.top + o) : s < t && o > e && (s = i.height, o = a - s, c = n.top + o);
295
305
  }
@@ -297,10 +307,10 @@ var S = {
297
307
  }
298
308
  a && r && (a.height += t, r.height += t);
299
309
  }
300
- }, w = {
310
+ }, T = {
301
311
  size: "50%",
302
- position: v.Left
303
- }, T = class e {
312
+ position: y.Left
313
+ }, re = class e {
304
314
  left;
305
315
  top;
306
316
  width;
@@ -310,7 +320,7 @@ var S = {
310
320
  }
311
321
  getPosition(e) {
312
322
  if (!this.siblingConfigNode) return e;
313
- let t = y(this.siblingConfigNode.position);
323
+ let t = b(this.siblingConfigNode.position);
314
324
  if (!e) return t;
315
325
  if (e !== t) throw Error("[bwin] Sibling position and current position are not opposite");
316
326
  return e;
@@ -319,36 +329,36 @@ var S = {
319
329
  if (!this.siblingConfigNode) return f(e);
320
330
  if (!e) {
321
331
  if (this.siblingConfigNode.size < 1) return 1 - this.siblingConfigNode.size;
322
- if (this.siblingConfigNode.position === v.Left || this.siblingConfigNode.position === v.Right) return this.parentRect.width - this.siblingConfigNode.width;
323
- if (this.siblingConfigNode.position === v.Top || this.siblingConfigNode.position === v.Bottom) return this.parentRect.height - this.siblingConfigNode.height;
332
+ if (this.siblingConfigNode.position === y.Left || this.siblingConfigNode.position === y.Right) return this.parentRect.width - this.siblingConfigNode.width;
333
+ if (this.siblingConfigNode.position === y.Top || this.siblingConfigNode.position === y.Bottom) return this.parentRect.height - this.siblingConfigNode.height;
324
334
  }
325
335
  let t = f(e);
326
336
  if (t < 1) {
327
337
  if (t + this.siblingConfigNode.size !== 1) throw Error("[bwin] Sum of sibling sizes is not equal to 1");
328
338
  } else {
329
- if ((this.position === v.Left || this.position === v.Right) && t + this.siblingConfigNode.size !== this.parentRect.width) throw Error("[bwin] Sum of sibling sizes is not equal to parent width");
330
- if ((this.position === v.Top || this.position === v.Bottom) && t + this.siblingConfigNode.size !== this.parentRect.height) throw Error("[bwin] Sum of sibling sizes is not equal to parent height");
339
+ if ((this.position === y.Left || this.position === y.Right) && t + this.siblingConfigNode.size !== this.parentRect.width) throw Error("[bwin] Sum of sibling sizes is not equal to parent width");
340
+ if ((this.position === y.Top || this.position === y.Bottom) && t + this.siblingConfigNode.size !== this.parentRect.height) throw Error("[bwin] Sum of sibling sizes is not equal to parent height");
331
341
  }
332
342
  return t;
333
343
  }
334
344
  setBounds() {
335
- if (this.position === v.Root) this.left = 0, this.top = 0, this.width = this.parentRect.width, this.height = this.parentRect.height;
336
- else if (this.position === v.Left) {
345
+ if (this.position === y.Root) this.left = 0, this.top = 0, this.width = this.parentRect.width, this.height = this.parentRect.height;
346
+ else if (this.position === y.Left) {
337
347
  let e = this.size < 1 ? this.parentRect.width * this.size : this.size;
338
348
  this.left = this.parentRect.left, this.top = this.parentRect.top, this.width = e, this.height = this.parentRect.height;
339
- } else if (this.position === v.Right) {
349
+ } else if (this.position === y.Right) {
340
350
  let e = this.size < 1 ? this.parentRect.width * this.size : this.size;
341
351
  this.left = this.parentRect.left + this.parentRect.width - e, this.top = this.parentRect.top, this.width = e, this.height = this.parentRect.height;
342
- } else if (this.position === v.Top) {
352
+ } else if (this.position === y.Top) {
343
353
  let e = this.size < 1 ? this.parentRect.height * this.size : this.size;
344
354
  this.left = this.parentRect.left, this.top = this.parentRect.top, this.width = this.parentRect.width, this.height = e;
345
- } else if (this.position === v.Bottom) {
355
+ } else if (this.position === y.Bottom) {
346
356
  let e = this.size < 1 ? this.parentRect.height * this.size : this.size;
347
357
  this.left = this.parentRect.left, this.top = this.parentRect.top + this.parentRect.height - e, this.width = this.parentRect.width, this.height = e;
348
358
  }
349
359
  }
350
360
  createSash({ resizeStrategy: e } = {}) {
351
- return new C({
361
+ return new w({
352
362
  left: this.left,
353
363
  top: this.top,
354
364
  width: this.width,
@@ -374,8 +384,8 @@ var S = {
374
384
  createPrimaryConfigNode({ size: t, position: n, children: r, id: i, minWidth: a, minHeight: o, ...s }) {
375
385
  return new e({
376
386
  parentRect: this,
377
- size: t ?? w.size,
378
- position: n ?? w.position,
387
+ size: t ?? T.size,
388
+ position: n ?? T.position,
379
389
  children: r,
380
390
  id: i,
381
391
  minWidth: a,
@@ -400,7 +410,7 @@ var S = {
400
410
  let t = this.createSash({ resizeStrategy: e });
401
411
  if (!Array.isArray(this.children) || this.children.length === 0) return t;
402
412
  let n = this.normConfig(this.children[0]), r = this.normConfig(this.children.at(1)), i, a;
403
- if (!n.size && !n.position && r ? (r.position ||= v.Right, i = this.createPrimaryConfigNode(r), a = this.createSecondaryConfigNode(n, i)) : (i = this.createPrimaryConfigNode(n), a = this.createSecondaryConfigNode(r, i)), i && a) {
413
+ if (!n.size && !n.position && r ? (r.position ||= y.Right, i = this.createPrimaryConfigNode(r), a = this.createSecondaryConfigNode(n, i)) : (i = this.createPrimaryConfigNode(n), a = this.createSecondaryConfigNode(r, i)), i && a) {
404
414
  let n = i.buildSashTree({ resizeStrategy: e }), r = a.buildSashTree({ resizeStrategy: e });
405
415
  n.parent = t, r.parent = t, t.children.push(n), t.children.push(r);
406
416
  }
@@ -412,7 +422,7 @@ var S = {
412
422
  }, D = {
413
423
  fitContainer: !1,
414
424
  theme: ""
415
- }, O = class extends T {
425
+ }, ie = class extends re {
416
426
  constructor({ id: e, children: t, width: n = E.width, height: r = E.height, fitContainer: i = D.fitContainer, theme: a = D.theme, ...o } = {
417
427
  ...E,
418
428
  ...D
@@ -421,7 +431,7 @@ var S = {
421
431
  id: e,
422
432
  children: t,
423
433
  size: NaN,
424
- position: v.Root,
434
+ position: y.Root,
425
435
  parentRect: {
426
436
  width: n,
427
437
  height: r
@@ -429,149 +439,149 @@ var S = {
429
439
  ...o
430
440
  }), this.fitContainer = i, this.theme = a;
431
441
  }
432
- }, re = class extends C {
433
- constructor(e = S) {
442
+ }, ae = class extends w {
443
+ constructor(e = C) {
434
444
  super({
435
445
  ...e,
436
- position: v.Root
446
+ position: y.Root
437
447
  }), Object.assign(this, D);
438
448
  }
439
449
  };
440
- function ie(e) {
450
+ function oe(e) {
441
451
  let t = document.createElement("bw-pane");
442
452
  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;
443
453
  }
444
- function k(e) {
454
+ function se(e) {
445
455
  let t = e.domNode;
446
456
  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;
447
457
  }
448
- function A(e, { size: t, id: n }) {
458
+ function ce(e, { size: t, id: n }) {
449
459
  let r = f(t), i = e.width / 2;
450
460
  r && (i = r < 1 ? e.width * r : r);
451
- let a = new C({
461
+ let a = new w({
452
462
  id: n,
453
463
  top: e.top,
454
464
  left: e.left,
455
465
  width: i,
456
466
  height: e.height,
457
- position: v.Left
458
- }), o = new C({
467
+ position: y.Left
468
+ }), o = new w({
459
469
  id: e.id,
460
470
  top: e.top,
461
471
  left: e.left + a.width,
462
472
  width: e.width - i,
463
473
  height: e.height,
464
- position: v.Right,
474
+ position: y.Right,
465
475
  domNode: e.domNode
466
476
  });
467
477
  return e.addChild(a), e.addChild(o), e.domNode = null, e.id = l(), a;
468
478
  }
469
- function j(e, { size: t, id: n }) {
479
+ function O(e, { size: t, id: n }) {
470
480
  let r = f(t), i = e.width / 2;
471
481
  r && (i = r < 1 ? e.width * r : r);
472
- let a = new C({
482
+ let a = new w({
473
483
  id: e.id,
474
484
  left: e.left,
475
485
  top: e.top,
476
486
  width: e.width - i,
477
487
  height: e.height,
478
- position: v.Left,
488
+ position: y.Left,
479
489
  domNode: e.domNode
480
- }), o = new C({
490
+ }), o = new w({
481
491
  id: n,
482
492
  left: e.left + a.width,
483
493
  top: e.top,
484
494
  width: i,
485
495
  height: e.height,
486
- position: v.Right
496
+ position: y.Right
487
497
  });
488
498
  return e.addChild(a), e.addChild(o), e.domNode = null, e.id = l(), o;
489
499
  }
490
- function M(e, { size: t, id: n }) {
500
+ function k(e, { size: t, id: n }) {
491
501
  let r = f(t), i = e.height / 2;
492
502
  r && (i = r < 1 ? e.height * r : r);
493
- let a = new C({
503
+ let a = new w({
494
504
  id: n,
495
505
  left: e.left,
496
506
  top: e.top,
497
507
  width: e.width,
498
508
  height: i,
499
- position: v.Top
500
- }), o = new C({
509
+ position: y.Top
510
+ }), o = new w({
501
511
  id: e.id,
502
512
  left: e.left,
503
513
  top: e.top + a.height,
504
514
  width: e.width,
505
515
  height: e.height - i,
506
- position: v.Bottom,
516
+ position: y.Bottom,
507
517
  domNode: e.domNode
508
518
  });
509
519
  return e.addChild(a), e.addChild(o), e.domNode = null, e.id = l(), a;
510
520
  }
511
- function N(e, { size: t, id: n }) {
521
+ function le(e, { size: t, id: n }) {
512
522
  let r = f(t), i = e.height / 2;
513
523
  r && (i = r < 1 ? e.height * r : r);
514
- let a = new C({
524
+ let a = new w({
515
525
  id: e.id,
516
526
  top: e.top,
517
527
  left: e.left,
518
528
  width: e.width,
519
529
  height: e.height - i,
520
- position: v.Top,
530
+ position: y.Top,
521
531
  domNode: e.domNode
522
- }), o = new C({
532
+ }), o = new w({
523
533
  id: n,
524
534
  top: e.top + a.height,
525
535
  left: e.left,
526
536
  width: e.width,
527
537
  height: i,
528
- position: v.Bottom
538
+ position: y.Bottom
529
539
  });
530
540
  return e.addChild(a), e.addChild(o), e.domNode = null, e.id = l(), o;
531
541
  }
532
- function P(e, { position: t, size: n, id: r, minWidth: i, minHeight: a }) {
533
- if (t === v.Left) return A(e, {
542
+ function ue(e, { position: t, size: n, id: r, minWidth: i, minHeight: a }) {
543
+ if (t === y.Left) return ce(e, {
534
544
  size: n,
535
545
  id: r
536
546
  });
537
- if (t === v.Right) return j(e, {
547
+ if (t === y.Right) return O(e, {
538
548
  size: n,
539
549
  id: r
540
550
  });
541
- if (t === v.Top) return M(e, {
551
+ if (t === y.Top) return k(e, {
542
552
  size: n,
543
553
  id: r
544
554
  });
545
- if (t === v.Bottom) return N(e, {
555
+ if (t === y.Bottom) return le(e, {
546
556
  size: n,
547
557
  id: r
548
558
  });
549
559
  }
550
- function F(e) {
560
+ function A(e) {
551
561
  if (e.tagName === "BW-PANE") return e.getAttribute("sash-id");
552
562
  let t = e.closest("bw-pane");
553
563
  if (!t) throw Error("[bwin] Pane element not found");
554
564
  return t.getAttribute("sash-id");
555
565
  }
556
- var I = {
566
+ var de = {
557
567
  createPane(e) {
558
- let t = ie(e);
568
+ let t = oe(e);
559
569
  return e.store.droppable === !1 && t.setAttribute("can-drop", "false"), t;
560
570
  },
561
571
  onPaneCreate(e, t) {
562
- t.store.content && e.append(g(t.store.content)), this?.debug && (e.style.backgroundColor = c(), e.innerHTML = "", e.append(L(e)));
572
+ t.store.content && e.append(g(t.store.content)), this?.debug && (e.style.backgroundColor = c(), e.innerHTML = "", e.append(j(e)));
563
573
  },
564
574
  updatePane(e) {
565
- return k(e);
575
+ return se(e);
566
576
  },
567
577
  onPaneUpdate(e, t) {
568
- this?.debug && (e.innerHTML = "", e.append(L(e)));
578
+ this?.debug && (e.innerHTML = "", e.append(j(e)));
569
579
  },
570
580
  addPane(e, { position: t, size: n, id: r }) {
571
581
  if (!t) throw Error("[bwin] Position is required when adding pane");
572
582
  let i = this.rootSash.getById(e);
573
583
  if (!i) throw Error("[bwin] Parent sash not found when adding pane");
574
- let a = P(i, {
584
+ let a = ue(i, {
575
585
  position: t,
576
586
  size: n,
577
587
  id: r
@@ -582,14 +592,14 @@ var I = {
582
592
  let t = this.rootSash.getDescendantParentById(e);
583
593
  if (!t) throw Error("[bwin] Parent sash not found when removing pane");
584
594
  let n = t.getChildSiblingById(e);
585
- n.children.length === 0 ? (t.id = n.id, t.domNode = n.domNode, t.domNode.setAttribute("sash-id", n.id), t.children = []) : (t.id = l(), t.children = n.children, n.position === v.Left ? n.width = t.width : n.position === v.Right ? (n.width = t.width, n.left = t.left) : n.position === v.Top ? n.height = t.height : n.position === v.Bottom && (n.height = t.height, n.top = t.top)), this.update();
595
+ n.children.length === 0 ? (t.id = n.id, t.domNode = n.domNode, t.domNode.setAttribute("sash-id", n.id), t.children = []) : (t.id = l(), t.children = n.children, t.children.forEach((e) => e.parent = t), n.position === y.Left ? n.width = t.width : n.position === y.Right ? (n.width = t.width, n.left = t.left) : n.position === y.Top ? n.height = t.height : n.position === y.Bottom && (n.height = t.height, n.top = t.top)), this.update();
586
596
  },
587
597
  swapPanes(e, t) {
588
- let n = F(e), r = F(t), i = e.getAttribute("can-drop") !== "false", a = t.getAttribute("can-drop") !== "false";
598
+ let n = A(e), r = A(t), i = e.getAttribute("can-drop") !== "false", a = t.getAttribute("can-drop") !== "false";
589
599
  this.rootSash.swapIds(n, r), d(e, this.activeDropPaneEl), e.setAttribute("sash-id", r), t.setAttribute("sash-id", n), e.setAttribute("can-drop", a), t.setAttribute("can-drop", i);
590
600
  }
591
601
  };
592
- function L(e) {
602
+ function j(e) {
593
603
  let t = document.createElement("pre");
594
604
  return t.style.fontSize = "10px", t.innerHTML = `
595
605
  ${e.getAttribute("sash-id")}
@@ -600,7 +610,7 @@ width: ${e.style.width}
600
610
  height: ${e.style.height}
601
611
  `.trim(), t;
602
612
  }
603
- var R = {
613
+ var fe = {
604
614
  createWindow({ theme: e } = {}) {
605
615
  let t = document.createElement("bw-window");
606
616
  return t.style.width = `${this.rootSash.width}px`, t.style.height = `${this.rootSash.height}px`, t.setAttribute("root-sash-id", this.rootSash.id), e && t.setAttribute("theme", e), t;
@@ -621,7 +631,7 @@ var R = {
621
631
  e.children.length > 0 ? t.includes(e.id) ? (this.updateMuntin(e), this.onMuntinUpdate(e.domNode, e)) : (e.domNode = this.createMuntin(e), this.windowElement.append(e.domNode)) : t.includes(e.id) ? (this.updatePane(e), this.onPaneUpdate(e.domNode, e)) : (e.domNode ||= this.createPane(e), this.windowElement.prepend(e.domNode));
622
632
  });
623
633
  }
624
- }, z = {
634
+ }, pe = {
625
635
  muntinSize: 4,
626
636
  createMuntin(e) {
627
637
  let t = document.createElement("bw-muntin"), n = e.leftChild, r = e.topChild;
@@ -633,7 +643,7 @@ var R = {
633
643
  n ? (t.style.height = `${e.height}px`, t.style.top = `${e.top}px`, t.style.left = `${e.left + n.width - this.muntinSize / 2}px`) : r && (t.style.width = `${e.width}px`, t.style.top = `${e.top + r.height - this.muntinSize / 2}px`, t.style.left = `${e.left}px`);
634
644
  },
635
645
  onMuntinUpdate(e, t) {}
636
- }, B = {
646
+ }, me = {
637
647
  fitContainer: !1,
638
648
  fit() {
639
649
  this.rootSash.width = this.containerElement.clientWidth, this.rootSash.height = this.containerElement.clientHeight, this.update();
@@ -645,7 +655,7 @@ var R = {
645
655
  });
646
656
  }).observe(this.containerElement);
647
657
  }
648
- }, V = {
658
+ }, he = {
649
659
  activeMuntinSash: null,
650
660
  isResizeStarted: !1,
651
661
  isDropStarted: !1,
@@ -678,7 +688,7 @@ var R = {
678
688
  this.isResizeStarted = !1, this.activeMuntinSash = null, this.revertResizeStyles();
679
689
  });
680
690
  }
681
- }, H = {
691
+ }, ge = {
682
692
  activeDropPaneEl: null,
683
693
  onPaneDrop(e, t) {},
684
694
  enableDrop() {
@@ -686,7 +696,7 @@ var R = {
686
696
  e.preventDefault();
687
697
  let t = e.target.matches("bw-pane") ? e.target : e.target.closest("bw-pane");
688
698
  if (!t || (t !== this.activeDropPaneEl && (this.activeDropPaneEl && this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = t), t.getAttribute("can-drop") === "false")) return;
689
- let n = ne(t, e);
699
+ let n = S(t, e);
690
700
  t.setAttribute("drop-area", n);
691
701
  }), this.windowElement.addEventListener("dragleave", (e) => {
692
702
  e.currentTarget.contains(e.relatedTarget) && e.currentTarget !== e.relatedTarget || (this.activeDropPaneEl &&= (this.activeDropPaneEl.removeAttribute("drop-area"), null));
@@ -696,13 +706,13 @@ var R = {
696
706
  this.onPaneDrop(e, n), typeof n.store.onDrop == "function" && n.store.onDrop(e, n), this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = null;
697
707
  });
698
708
  }
699
- }, U = !1, W = class {
709
+ }, _e = !1, M = class {
700
710
  windowElement = null;
701
711
  containerElement = null;
702
- debug = U;
712
+ debug = _e;
703
713
  constructor(e) {
704
714
  let t = null;
705
- e instanceof re ? (t = e, this.rootSash = e) : (t = new O(e), this.rootSash = t.buildSashTree({ resizeStrategy: t.resizeStrategy })), this.fitContainer = t.fitContainer, this.theme = t.theme;
715
+ e instanceof ae ? (t = e, this.rootSash = e) : (t = new ie(e), this.rootSash = t.buildSashTree({ resizeStrategy: t.resizeStrategy })), this.fitContainer = t.fitContainer;
706
716
  }
707
717
  frame(e) {
708
718
  this.containerElement = e, this.windowElement = this.createWindow({ theme: this.theme }), this.glaze(), this.containerElement.append(this.windowElement);
@@ -719,34 +729,8 @@ var R = {
719
729
  });
720
730
  }
721
731
  };
722
- W.assemble(R, z, I, B, H, V);
723
- var G = {
724
- label: "",
725
- className: "bw-glass-action--close",
726
- onClick: (e, t) => {
727
- let n = F(e.target);
728
- t.removePane(n);
729
- }
730
- }, K = {
731
- label: "",
732
- className: "bw-glass-action--minimize",
733
- onClick: (e, t) => {
734
- let n = t.sillElement;
735
- if (!n) throw Error("[bwin] Sill element not found when minimizing");
736
- let r = g("<button class=\"bw-minimized-glass\" />");
737
- n.append(r);
738
- let i = e.target.closest("bw-pane"), a = e.target.closest("bw-glass"), o = i.getAttribute("sash-id"), s = i.getAttribute("position");
739
- r.bwGlassElement = a, r.bwOriginalPosition = s, r.bwOriginalBoundingRect = _(i), r.bwOriginalSashId = o, t.removePane(o);
740
- }
741
- }, q = {
742
- label: "",
743
- className: "bw-glass-action--maximize",
744
- onClick: (e) => {
745
- let t = e.target.closest("bw-pane");
746
- t.hasAttribute("maximized") ? (t.removeAttribute("maximized"), t.style.left = `${t.bwOriginalBoundingRect.left}px`, t.style.top = `${t.bwOriginalBoundingRect.top}px`, t.style.width = `${t.bwOriginalBoundingRect.width}px`, t.style.height = `${t.bwOriginalBoundingRect.height}px`) : (t.setAttribute("maximized", ""), t.bwOriginalBoundingRect = _(t), t.style.left = "0", t.style.top = "0", t.style.width = "100%", t.style.height = "100%");
747
- }
748
- };
749
- function J(e, t) {
732
+ M.assemble(fe, pe, de, me, ge, he);
733
+ function N(e, t) {
750
734
  let n = e.left + e.width, r = e.top + e.height, i = t.left + t.width, a = t.top + t.height;
751
735
  if (e.left >= i || t.left >= n || e.top >= a || t.top >= r) return null;
752
736
  let o = Math.max(e.left, t.left), s = Math.max(e.top, t.top), c = Math.min(n, i), l = Math.min(r, a);
@@ -757,26 +741,22 @@ function J(e, t) {
757
741
  height: l - s
758
742
  };
759
743
  }
760
- var Y = [
761
- K,
762
- q,
763
- G
764
- ], ae = {
765
- enableActions() {
744
+ var P = {
745
+ enableGlassActions() {
766
746
  this.handleMinimizedGlassClick(), this.observeActionButtons();
767
747
  },
768
748
  restoreGlass(e) {
769
749
  let t = e.bwOriginalBoundingRect, n = 0, r = null;
770
750
  if (this.windowElement.querySelectorAll("bw-pane").forEach((e) => {
771
- let i = J(t, _(e));
751
+ let i = N(t, v(e));
772
752
  if (i) {
773
753
  let t = i.width * i.height;
774
754
  t > n && (n = t, r = e);
775
755
  }
776
756
  }), r) {
777
- let n = e.bwOriginalPosition, i = _(r), a = r.getAttribute("sash-id"), o = this.rootSash.getById(a), s = 0;
778
- if (n === v.Left || n === v.Right) s = i.width - t.width < o.minWidth ? i.width / 2 : t.width;
779
- else if (n === v.Top || n === v.Bottom) s = i.height - t.height < o.minHeight ? i.height / 2 : t.height;
757
+ let n = e.bwOriginalPosition, i = v(r), a = r.getAttribute("sash-id"), o = this.rootSash.getById(a), s = 0;
758
+ if (n === y.Left || n === y.Right) s = i.width - t.width < o.minWidth ? i.width / 2 : t.width;
759
+ else if (n === y.Top || n === y.Bottom) s = i.height - t.height < o.minHeight ? i.height / 2 : t.height;
780
760
  else throw Error("[bwin] Invalid position when restoring glass");
781
761
  let c = e.bwOriginalSashId;
782
762
  this.addPane(r.getAttribute("sash-id"), {
@@ -794,7 +774,7 @@ var Y = [
794
774
  });
795
775
  },
796
776
  updateDisabledStateOfActionButtons() {
797
- this.updateDisabledState(".bw-glass-action--close"), this.updateDisabledState(".bw-glass-action--minimize"), this.updateDisabledState(".bw-glass-action--maximize");
777
+ this.updateDisabledState(".bw-glass-action--close"), this.updateDisabledState(".bw-glass-action--minimize"), this.updateDisabledState(".bw-glass-action--maximize"), this.updateDisabledState(".bw-glass-action--detach");
798
778
  },
799
779
  updateDisabledState(e) {
800
780
  if (this.windowElement.querySelectorAll("bw-pane").length === 1) {
@@ -815,23 +795,94 @@ var Y = [
815
795
  });
816
796
  }).observe(this.windowElement, { childList: !0 });
817
797
  }
818
- }, X = {
819
- title: null,
820
- content: null,
821
- tabs: [],
822
- actions: void 0,
823
- draggable: !0
824
- }, Z = class {
798
+ }, F = null, I = !1, ve = {
799
+ onPaneDrop(e, t) {
800
+ if (!F) return;
801
+ let n = this.activeDropPaneEl.getAttribute("drop-area");
802
+ if (n === "center") {
803
+ let e = F.closest("bw-pane");
804
+ this.swapPanes(e, this.activeDropPaneEl);
805
+ return;
806
+ } else {
807
+ let e = A(F);
808
+ this.removePane(e), this.addPane(t.id, {
809
+ position: n,
810
+ id: e
811
+ }).domNode.append(F);
812
+ }
813
+ },
814
+ enableGlassDrag() {
815
+ document.addEventListener("mousedown", (e) => {
816
+ if (e.button !== 0 || !e.target.matches("bw-glass-header")) return;
817
+ if (e.target.getAttribute("can-drag") === "false") {
818
+ e.preventDefault();
819
+ return;
820
+ }
821
+ let t = e.target.closest("bw-glass");
822
+ t.setAttribute("draggable", !0), F = t;
823
+ }), document.addEventListener("mouseup", () => {
824
+ F &&= (F.removeAttribute("draggable"), null);
825
+ }), this.windowElement.addEventListener("dragstart", (e) => {
826
+ if (!(e.target instanceof HTMLElement) || !e.target.matches("bw-glass") || !F) return;
827
+ e.dataTransfer.effectAllowed = "move";
828
+ let t = F.closest("bw-pane");
829
+ I = t.getAttribute("can-drop") !== "false", t.setAttribute("can-drop", !1);
830
+ }), this.windowElement.addEventListener("dragend", () => {
831
+ F &&= (F.removeAttribute("draggable"), F.closest("bw-pane").setAttribute("can-drop", I), null);
832
+ });
833
+ }
834
+ }, L = {
835
+ label: "",
836
+ className: "bw-glass-action--close",
837
+ onClick: (e, t) => {
838
+ let n = A(e.target);
839
+ t.removePane(n);
840
+ }
841
+ }, R = {
842
+ label: "",
843
+ className: "bw-glass-action--minimize",
844
+ onClick: (e, t) => {
845
+ let n = t.sillElement;
846
+ if (!n) throw Error("[bwin] Sill element not found when minimizing");
847
+ let r = g("<button class=\"bw-minimized-glass\" />");
848
+ n.append(r);
849
+ let i = e.target.closest("bw-pane"), a = e.target.closest("bw-glass"), o = i.getAttribute("sash-id"), s = i.getAttribute("position");
850
+ r.bwGlassElement = a, r.bwOriginalPosition = s, r.bwOriginalBoundingRect = v(i), r.bwOriginalSashId = o, t.removePane(o);
851
+ }
852
+ }, ye = {
853
+ label: "",
854
+ className: "bw-glass-action--maximize",
855
+ onClick: (e) => {
856
+ let t = e.target.closest("bw-pane");
857
+ 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 = v(t), t.style.left = "0", t.style.top = "0", t.style.width = "100%", t.style.height = "100%");
858
+ }
859
+ }, z = 15, B = {
860
+ label: "",
861
+ className: "bw-glass-action--detach",
862
+ onClick: (e, t) => {
863
+ if (!t.addDetachedGlass) throw Error("[bwin] Failed to detach glass from pane");
864
+ let n = e.target.closest("bw-pane"), r = n.querySelector("bw-glass-content"), i = n.querySelector("bw-glass-title"), a = t.windowElement.getBoundingClientRect(), o = a.width - z * 2, s = a.height - z * 2, c = t.addDetachedGlass({
865
+ position: "center",
866
+ width: o,
867
+ height: s
868
+ }), l = n.getAttribute("sash-id"), u = t.rootSash.getById(l), d = u.parent.getChildSiblingById(l).id;
869
+ c.domNode.bwOriginalSiblingSashId = d, c.domNode.bwOriginalPosition = n.getAttribute("position"), c.domNode.bwOriginalRelativeSize = u.getRelativeSize(), c.contentElement.replaceWith(r), c.titleElement.replaceWith(i), t.removePane(l);
870
+ }
871
+ }, V = [
872
+ R,
873
+ B,
874
+ L
875
+ ], H = class {
825
876
  domNode;
826
- constructor({ title: e = X.title, content: t = X.content, tabs: n = X.tabs, actions: r = X.actions, draggable: i = X.draggable, sash: a, binaryWindow: o }) {
877
+ constructor({ title: e = null, content: t = null, tabs: n = [], actions: r = V, draggable: i = !0, sash: a = null, binaryWindow: o }) {
827
878
  this.title = e, this.content = t, this.tabs = n, this.actions = r, this.sash = a, this.draggable = i, this.binaryWindow = o, this.build();
828
879
  }
829
880
  build() {
830
881
  let e = document.createElement("bw-glass-header");
831
882
  if (Array.isArray(this.tabs) && this.tabs.length > 0) e.append(this.createTabs());
832
- else if (this.title) {
883
+ else {
833
884
  let t = document.createElement("bw-glass-title");
834
- t.append(g(this.title)), e.append(t);
885
+ this.title && t.append(g(this.title)), e.append(t);
835
886
  }
836
887
  e.setAttribute("can-drag", this.draggable), e.append(this.createActions());
837
888
  let t = document.createElement("bw-glass-content"), n = g(this.content);
@@ -846,7 +897,7 @@ var Y = [
846
897
  return e;
847
898
  }
848
899
  createActions() {
849
- let e = document.createElement("bw-glass-action-container"), t = this.actions === void 0 ? Y : Array.isArray(this.actions) ? this.actions : [];
900
+ let e = document.createElement("bw-glass-action-container"), t = Array.isArray(this.actions) ? this.actions : [];
850
901
  for (let n of t) {
851
902
  let t = n?.label ?? n, r = g(`<button class="${n.className ? `bw-glass-action ${n.className}` : "bw-glass-action"}">${t}</button>`);
852
903
  typeof n.onClick == "function" && r.addEventListener("click", (e) => {
@@ -861,45 +912,21 @@ var Y = [
861
912
  get headerElement() {
862
913
  return this.domNode.querySelector("bw-glass-header");
863
914
  }
864
- }, oe = {
865
- activeDragGlassEl: null,
866
- activeDragGlassPaneCanDrop: !1,
867
- onPaneDrop(e, t) {
868
- if (!this.activeDragGlassEl) return;
869
- let n = this.activeDropPaneEl.getAttribute("drop-area");
870
- if (n === "center") {
871
- let e = this.activeDragGlassEl.closest("bw-pane");
872
- this.swapPanes(e, this.activeDropPaneEl);
873
- return;
874
- } else {
875
- let e = F(this.activeDragGlassEl);
876
- this.removePane(e), this.addPane(t.id, {
877
- position: n,
878
- id: e
879
- }).domNode.append(this.activeDragGlassEl);
880
- }
915
+ get titleElement() {
916
+ return this.domNode.querySelector("bw-glass-title");
917
+ }
918
+ }, be = [
919
+ R,
920
+ ye,
921
+ B,
922
+ L
923
+ ], xe = {
924
+ enableGlassFeature() {
925
+ this.enableGlassActions(), this.enableGlassDrag();
881
926
  },
882
- enableDrag() {
883
- document.addEventListener("mousedown", (e) => {
884
- if (e.button !== 0 || !e.target.matches("bw-glass-header")) return;
885
- if (e.target.getAttribute("can-drag") === "false") {
886
- e.preventDefault();
887
- return;
888
- }
889
- let t = e.target.closest("bw-glass");
890
- t.setAttribute("draggable", !0), this.activeDragGlassEl = t;
891
- }), document.addEventListener("mouseup", () => {
892
- this.activeDragGlassEl &&= (this.activeDragGlassEl.removeAttribute("draggable"), null);
893
- }), this.windowElement.addEventListener("dragstart", (e) => {
894
- if (!(e.target instanceof HTMLElement) || !e.target.matches("bw-glass") || !this.activeDragGlassEl) return;
895
- e.dataTransfer.effectAllowed = "move";
896
- let t = this.activeDragGlassEl.closest("bw-pane");
897
- this.activeDragGlassPaneCanDrop = t.getAttribute("can-drop") !== "false", t.setAttribute("can-drop", !1);
898
- }), this.windowElement.addEventListener("dragend", () => {
899
- this.activeDragGlassEl &&= (this.activeDragGlassEl.removeAttribute("draggable"), this.activeDragGlassEl.closest("bw-pane").setAttribute("can-drop", this.activeDragGlassPaneCanDrop), null);
900
- });
901
- }
902
- }, se = {
927
+ ...P,
928
+ ...ve
929
+ }, Se = {
903
930
  trimMuntin(e) {
904
931
  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`);
905
932
  },
@@ -909,23 +936,289 @@ var Y = [
909
936
  onMuntinUpdate(e) {
910
937
  this.trimMuntin(e);
911
938
  }
912
- }, Q = class extends W {
939
+ }, Ce = [
940
+ "n",
941
+ "s",
942
+ "e",
943
+ "w",
944
+ "ne",
945
+ "nw",
946
+ "se",
947
+ "sw"
948
+ ];
949
+ function we() {
950
+ return Ce.map((e) => {
951
+ let t = document.createElement("bw-glass-resize-handle");
952
+ return t.setAttribute("resize-dir", e), t;
953
+ });
954
+ }
955
+ function Te({ position: e, offset: t, offsetX: n, offsetY: r, width: i, height: a }) {
956
+ let o = n ?? t, s = r ?? t;
957
+ switch (e) {
958
+ case "top-left": return {
959
+ top: `${s}px`,
960
+ left: `${o}px`,
961
+ right: "auto",
962
+ bottom: "auto"
963
+ };
964
+ case "top-right": return {
965
+ top: `${s}px`,
966
+ right: `${o}px`,
967
+ left: "auto",
968
+ bottom: "auto"
969
+ };
970
+ case "bottom-left": return {
971
+ bottom: `${s}px`,
972
+ left: `${o}px`,
973
+ right: "auto",
974
+ top: "auto"
975
+ };
976
+ case "bottom-right": return {
977
+ bottom: `${s}px`,
978
+ right: `${o}px`,
979
+ left: "auto",
980
+ top: "auto"
981
+ };
982
+ case "center": return {
983
+ top: `calc(50% - ${a / 2}px + ${s}px)`,
984
+ left: `calc(50% - ${i / 2}px + ${o}px)`,
985
+ right: "auto",
986
+ bottom: "auto"
987
+ };
988
+ default: throw Error(`Position "${e}" is not supported for detached glass.`);
989
+ }
990
+ }
991
+ var U = new class {
992
+ constructor() {
993
+ this.glasses = [], this.topZIndex = 1;
994
+ }
995
+ addGlassByElement(e) {
996
+ this.glasses.push(e);
997
+ }
998
+ getActiveGlass() {
999
+ return this.glasses.find((e) => e.hasAttribute("active")) ?? null;
1000
+ }
1001
+ bringToFront(e) {
1002
+ e.hasAttribute("active") || (this.topZIndex += 1, e.style.zIndex = this.topZIndex, e.parentElement?.querySelectorAll(":scope > bw-glass[detached][active]").forEach((t) => t !== e && t.removeAttribute("active")), e.setAttribute("active", ""));
1003
+ }
1004
+ removeGlassById(e) {
1005
+ let t = this.glasses.findIndex((t) => t.id === e);
1006
+ if (t !== -1) {
1007
+ let [e] = this.glasses.splice(t, 1);
1008
+ return e;
1009
+ }
1010
+ return null;
1011
+ }
1012
+ }(), W = [
1013
+ {
1014
+ label: "",
1015
+ className: "bw-glass-action--minimize",
1016
+ onClick: (e, t) => {
1017
+ let n = t.sillElement;
1018
+ if (!n) throw Error("[bwin] Sill element not found when minimizing");
1019
+ let r = g("<button class=\"bw-minimized-detached-glass\" />");
1020
+ n.append(r);
1021
+ let i = e.target.closest("bw-glass[detached]");
1022
+ if (!i) throw Error("[bwin] Detached Glass element not found when minimizing");
1023
+ r.bwDetachedGlassElement = i, i.style.display = "none";
1024
+ }
1025
+ },
1026
+ {
1027
+ label: "",
1028
+ className: "bw-glass-action--attach",
1029
+ onClick: (e, t) => {
1030
+ let n = e.target.closest("bw-glass[detached]"), r = n.bwOriginalPosition, i = n.bwOriginalSiblingSashId, a = n.bwOriginalRelativeSize, o = t.rootSash.getById(i), s = i, c = r, l = a;
1031
+ if (!o) {
1032
+ let e = t.rootSash.getLargestLeaf();
1033
+ s = e.id, c = e.width > e.height ? "right" : "bottom", l = .5;
1034
+ }
1035
+ let u = n.querySelector("bw-glass-content");
1036
+ t.addPane(s, {
1037
+ position: c,
1038
+ size: l,
1039
+ content: _(u),
1040
+ title: n.querySelector("bw-glass-title")?.textContent || ""
1041
+ }), t.removeDetachedGlass(n.id);
1042
+ }
1043
+ },
1044
+ {
1045
+ label: "",
1046
+ className: "bw-glass-action--close",
1047
+ onClick: (e) => {
1048
+ let t = e.target.closest("bw-glass[detached]");
1049
+ t && (U.removeGlassById(t.id), t.remove());
1050
+ }
1051
+ }
1052
+ ], Ee = class extends H {
1053
+ constructor(e) {
1054
+ let { position: t, width: n = 222, height: r = 222, offset: i = 0, offsetX: a, offsetY: o, id: s, actions: c = W, ...u } = e;
1055
+ super({
1056
+ ...u,
1057
+ actions: c
1058
+ }), this.domNode.setAttribute("id", s || l() + "-F"), this.domNode.setAttribute("detached", ""), this.domNode.style.position = "absolute", this.domNode.style.width = `${n}px`, this.domNode.style.height = `${r}px`;
1059
+ let { top: d, left: f, right: p, bottom: m } = Te({
1060
+ position: t,
1061
+ offset: i,
1062
+ offsetX: a,
1063
+ offsetY: o,
1064
+ width: n,
1065
+ height: r
1066
+ });
1067
+ this.domNode.style.top = d, this.domNode.style.left = f, this.domNode.style.right = p, this.domNode.style.bottom = m;
1068
+ }
1069
+ }, De = 200, Oe = 200, G = 25;
1070
+ function ke(e, { width: t, height: n }) {
1071
+ let r = U.getActiveGlass();
1072
+ if (!r) return { position: "center" };
1073
+ let i = e.getBoundingClientRect(), a = r.getBoundingClientRect(), o = a.left - i.left + G, s = a.top - i.top + G;
1074
+ return o + t > i.width && (o = G), s + n > i.height && (s = G), {
1075
+ position: "top-left",
1076
+ offsetX: o,
1077
+ offsetY: s
1078
+ };
1079
+ }
1080
+ var Ae = {
1081
+ addDetachedGlass(e = {}) {
1082
+ let t = e.width ?? De, n = e.height ?? Oe, { position: r, offsetX: i, offsetY: a } = e.position ? {} : ke(this.windowElement, {
1083
+ width: t,
1084
+ height: n
1085
+ }), o = new Ee({
1086
+ actions: this.actions[1],
1087
+ binaryWindow: this,
1088
+ position: r,
1089
+ offsetX: i,
1090
+ offsetY: a,
1091
+ ...e,
1092
+ width: t,
1093
+ height: n
1094
+ });
1095
+ return this.windowElement.append(o.domNode), U.addGlassByElement(o.domNode), U.bringToFront(o.domNode), o;
1096
+ },
1097
+ removeDetachedGlass(e) {
1098
+ let t = U.removeGlassById(e);
1099
+ return t?.remove(), t;
1100
+ }
1101
+ }, je = { enableDetachedGlassActivate() {
1102
+ this.windowElement.addEventListener("pointerdown", (e) => {
1103
+ if (e.button !== 0) return;
1104
+ let t = e.target.closest?.("bw-glass[detached]");
1105
+ t && U.bringToFront(t);
1106
+ });
1107
+ } }, Me = { enableDetachedGlassMove() {
1108
+ let e = null, t = 0, n = 0, r = 0, i = 0;
1109
+ this.windowElement.addEventListener("pointerdown", (a) => {
1110
+ if (a.button !== 0) return;
1111
+ let o = a.target.closest("bw-glass-header");
1112
+ if (!o || a.target.closest("button") || o.getAttribute("can-drag") === "false") return;
1113
+ let s = o.closest("bw-glass[detached]");
1114
+ if (!s) return;
1115
+ a.preventDefault(), o.setPointerCapture(a.pointerId), e = s, t = a.pageX, n = a.pageY;
1116
+ let c = this.windowElement.getBoundingClientRect(), l = s.getBoundingClientRect();
1117
+ r = l.left - c.left, i = l.top - c.top;
1118
+ }), this.windowElement.addEventListener("pointermove", (a) => {
1119
+ if (!e) return;
1120
+ let o = r + (a.pageX - t), s = i + (a.pageY - n);
1121
+ e.style.right = "auto", e.style.bottom = "auto", e.style.left = `${o}px`, e.style.top = `${s}px`;
1122
+ }), this.windowElement.addEventListener("pointerup", (t) => {
1123
+ e &&= (t.target.hasPointerCapture?.(t.pointerId) && t.target.releasePointerCapture(t.pointerId), null);
1124
+ });
1125
+ } }, K = null, q = 0, J = 0, Ne = { enableDetachedGlassDrag() {
1126
+ document.addEventListener("mousedown", (e) => {
1127
+ if (e.button !== 0) return;
1128
+ let t = e.target.closest("bw-glass-header");
1129
+ if (!t || e.target.closest("button") || t.getAttribute("can-drag") === "false") return;
1130
+ let n = t.closest("bw-glass[detached]");
1131
+ n && (n.setAttribute("draggable", !0), K = n);
1132
+ }), document.addEventListener("mouseup", () => {
1133
+ K &&= (K.removeAttribute("draggable"), null);
1134
+ }), this.windowElement.addEventListener("dragstart", (e) => {
1135
+ if (!K) return;
1136
+ e.dataTransfer.effectAllowed = "move";
1137
+ let t = K.getBoundingClientRect();
1138
+ q = e.clientX - t.left, J = e.clientY - t.top;
1139
+ }), this.windowElement.addEventListener("dragend", (e) => {
1140
+ if (!K) return;
1141
+ let t = this.windowElement.getBoundingClientRect(), n = e.clientX - t.left - q, r = e.clientY - t.top - J;
1142
+ K.style.right = "auto", K.style.bottom = "auto", K.style.left = `${n}px`, K.style.top = `${r}px`, K.removeAttribute("draggable"), K = null;
1143
+ });
1144
+ } }, Y = 100, X = 60;
1145
+ function Pe(e) {
1146
+ return !!e.querySelector(":scope > bw-glass-resize-handle");
1147
+ }
1148
+ function Fe(e) {
1149
+ Pe(e) || e.append(...we());
1150
+ }
1151
+ function Z(e) {
1152
+ e.querySelectorAll(":scope > bw-glass-resize-handle").forEach((e) => e.remove());
1153
+ }
1154
+ var Ie = { enableDetachedGlassResize() {
1155
+ let e = null, t = "", n = 0, r = 0, i = null;
1156
+ this.windowElement.addEventListener("pointerover", (e) => {
1157
+ let t = e.target.closest?.("bw-glass[detached]");
1158
+ t && Fe(t);
1159
+ }), this.windowElement.addEventListener("pointerout", (t) => {
1160
+ let n = t.target.closest?.("bw-glass[detached]");
1161
+ n && t.relatedTarget?.closest?.("bw-glass[detached]") !== n && n !== e && Z(n);
1162
+ }), this.windowElement.addEventListener("pointerdown", (a) => {
1163
+ if (a.button !== 0 || a.target.tagName !== "BW-GLASS-RESIZE-HANDLE") return;
1164
+ let o = a.target.closest("bw-glass[detached]");
1165
+ if (!o) return;
1166
+ a.preventDefault(), a.target.setPointerCapture(a.pointerId), e = o, t = a.target.getAttribute("resize-dir"), n = a.pageX, r = a.pageY;
1167
+ let s = this.windowElement.getBoundingClientRect(), c = o.getBoundingClientRect();
1168
+ i = {
1169
+ left: c.left - s.left,
1170
+ top: c.top - s.top,
1171
+ width: c.width,
1172
+ height: c.height
1173
+ };
1174
+ }), this.windowElement.addEventListener("pointermove", (a) => {
1175
+ if (!e) return;
1176
+ let o = t, s = a.pageX - n, c = a.pageY - r, l = i, { left: u, top: d, width: f, height: p } = l;
1177
+ o.includes("e") ? f = Math.max(Y, l.width + s) : o.includes("w") && (f = Math.max(Y, l.width - s), u = l.left + (l.width - f)), o.includes("s") ? p = Math.max(X, l.height + c) : o.includes("n") && (p = Math.max(X, l.height - c), d = l.top + (l.height - p)), e.style.right = "auto", e.style.bottom = "auto", e.style.left = `${u}px`, e.style.top = `${d}px`, e.style.width = `${f}px`, e.style.height = `${p}px`;
1178
+ }), this.windowElement.addEventListener("pointerup", (n) => {
1179
+ if (!e) return;
1180
+ n.target.hasPointerCapture?.(n.pointerId) && n.target.releasePointerCapture(n.pointerId);
1181
+ let r = e;
1182
+ e = null, t = "", i = null, r.matches(":hover") || Z(r);
1183
+ });
1184
+ } }, Le = { handleMinimizedDetachedGlassClick() {
1185
+ this.sillElement.addEventListener("click", (e) => {
1186
+ let t = e.target;
1187
+ if (!t.matches(".bw-minimized-detached-glass")) return;
1188
+ let n = t.bwDetachedGlassElement;
1189
+ n && (n.style.display = "", t.remove(), U.bringToFront(n));
1190
+ });
1191
+ } }, Re = {
1192
+ enableDetachedGlassFeatures() {
1193
+ this.enableDetachedGlassActivate(), this.enableDetachedGlassResize(), this.enableDetachedGlassMove(), this.handleMinimizedDetachedGlassClick();
1194
+ },
1195
+ ...Ae,
1196
+ ...je,
1197
+ ...Me,
1198
+ ...Ne,
1199
+ ...Ie,
1200
+ ...Le
1201
+ }, Q = class e extends M {
913
1202
  sillElement = null;
1203
+ constructor(t) {
1204
+ super(t), this.theme = t.theme || "", this.actions = e.normActions(t.actions);
1205
+ }
914
1206
  frame() {
915
1207
  super.frame(...arguments);
916
1208
  let e = g("<bw-sill />");
917
1209
  this.windowElement.append(e), this.sillElement = e;
918
1210
  }
919
1211
  enableFeatures() {
920
- super.enableFeatures(), this.enableDrag(), this.enableActions();
1212
+ super.enableFeatures(), this.enableGlassFeature(), this.enableDetachedGlassFeatures();
921
1213
  }
922
1214
  onPaneCreate(e, t) {
923
- let n = new Z({
1215
+ let n = this.actions[0], r = new H({
1216
+ actions: n,
924
1217
  ...t.store,
925
1218
  sash: t,
926
1219
  binaryWindow: this
927
1220
  });
928
- e.innerHTML = "", e.append(n.domNode), this.debug && n.contentElement.prepend(`${t.id}`);
1221
+ e.innerHTML = "", e.append(r.domNode), this.debug && r.contentElement.prepend(`${t.id}`);
929
1222
  }
930
1223
  onPaneUpdate() {}
931
1224
  addPane(e, t) {
@@ -933,7 +1226,7 @@ var Y = [
933
1226
  position: n,
934
1227
  size: r,
935
1228
  id: i
936
- }), s = new Z({
1229
+ }), s = new H({
937
1230
  ...a,
938
1231
  sash: o,
939
1232
  binaryWindow: this
@@ -955,12 +1248,22 @@ var Y = [
955
1248
  let t = this.getMinimizedGlassElementBySashId(e);
956
1249
  t && t.remove();
957
1250
  }
1251
+ static normActions(e) {
1252
+ if (e === void 0) return [V, W];
1253
+ if (!e || !Array.isArray(e) || e.length === 0) return [[], []];
1254
+ if (e.length === 1 && Array.isArray(e[0])) return [e[0], W];
1255
+ if (!e.some(Array.isArray)) return [e, W];
1256
+ if (e.length >= 2 && !Array.isArray(e[0]) && Array.isArray(e[1])) return [[], e[1]];
1257
+ if (e.length >= 2 && Array.isArray(e[0]) && !Array.isArray(e[1])) return [e[0], []];
1258
+ if (e.length >= 2 && Array.isArray(e[0]) && Array.isArray(e[1])) return e;
1259
+ throw Error("[bwin] Invalid actions format");
1260
+ }
958
1261
  };
959
- Q.assemble(oe, se, ae);
1262
+ Q.assemble(xe, Re, Se);
960
1263
  //#endregion
961
1264
  //#region src/Muntin.tsx
962
1265
  var $ = 4;
963
- function ce({ sash: t }) {
1266
+ function ze({ sash: t }) {
964
1267
  let r = a(), i = t.leftChild, o = t.topChild, s, c, l, u, d, f;
965
1268
  return i ? (s = $, c = t.height - $, l = t.top + $ / 2, u = t.left + i.width - $ / 2, d = !0) : o && (s = t.width - $, c = $, l = t.top + o.height - $ / 2, u = t.left + $ / 2, f = !0), n(() => {
966
1269
  t.domNode = r.current;
@@ -980,12 +1283,12 @@ function ce({ sash: t }) {
980
1283
  }
981
1284
  //#endregion
982
1285
  //#region src/Pane.tsx
983
- function le({ sash: t, bwin: r }) {
1286
+ function Be({ sash: t, bwin: r }) {
984
1287
  let i = a(), { left: o, top: s, width: c, height: l, id: u, position: d } = t;
985
1288
  n(() => {
986
1289
  t.domNode = i.current;
987
1290
  }, []);
988
- let f = t.store?.actions === void 0 ? Y : Array.isArray(t.store.actions) ? t.store.actions : [];
1291
+ let f = t.store?.actions === void 0 ? r.actions[0] : Array.isArray(t.store.actions) ? t.store.actions : [];
989
1292
  return /* @__PURE__ */ e.createElement("bw-pane", {
990
1293
  "sash-id": u,
991
1294
  position: d,
@@ -997,7 +1300,7 @@ function le({ sash: t, bwin: r }) {
997
1300
  },
998
1301
  "can-drop": t.store?.droppable === !1 ? "false" : "true",
999
1302
  ref: i
1000
- }, /* @__PURE__ */ e.createElement("bw-glass", null, /* @__PURE__ */ e.createElement("bw-glass-header", { "can-drag": t.store?.draggable === !1 ? "false" : "true" }, t.store?.title && /* @__PURE__ */ e.createElement("bw-glass-title", null, t.store.title), f.length > 0 && /* @__PURE__ */ e.createElement("bw-glass-action-container", null, f.map((t, n) => {
1303
+ }, /* @__PURE__ */ e.createElement("bw-glass", null, /* @__PURE__ */ e.createElement("bw-glass-header", { "can-drag": t.store?.draggable === !1 ? "false" : "true" }, /* @__PURE__ */ e.createElement("bw-glass-title", null, t.store?.title), f.length > 0 && /* @__PURE__ */ e.createElement("bw-glass-action-container", null, f.map((t, n) => {
1001
1304
  let i = t.className ? `bw-glass-action ${t.className}` : "bw-glass-action";
1002
1305
  return /* @__PURE__ */ e.createElement("button", {
1003
1306
  className: i,
@@ -1008,7 +1311,7 @@ function le({ sash: t, bwin: r }) {
1008
1311
  }
1009
1312
  //#endregion
1010
1313
  //#region src/Window.tsx
1011
- var ue = t((t, c) => {
1314
+ var Ve = t((t, c) => {
1012
1315
  let l = a(), u = a(), [d, f] = o(), { panes: p, ...m } = t, h = new Q({
1013
1316
  ...m,
1014
1317
  children: p
@@ -1032,11 +1335,11 @@ var ue = t((t, c) => {
1032
1335
  height: h.rootSash.height
1033
1336
  },
1034
1337
  ref: l
1035
- }, _.map((t) => /* @__PURE__ */ e.createElement(le, {
1338
+ }, _.map((t) => /* @__PURE__ */ e.createElement(Be, {
1036
1339
  key: t.id,
1037
1340
  sash: t,
1038
1341
  bwin: h
1039
- })), g.map((t) => /* @__PURE__ */ e.createElement(ce, {
1342
+ })), g.map((t) => /* @__PURE__ */ e.createElement(ze, {
1040
1343
  key: t.id,
1041
1344
  sash: t
1042
1345
  })), /* @__PURE__ */ e.createElement("bw-sill", { ref: u })), y = i(() => v, []);
@@ -1048,6 +1351,6 @@ var ue = t((t, c) => {
1048
1351
  }]);
1049
1352
  }
1050
1353
  return /* @__PURE__ */ e.createElement(e.Fragment, null, y, d?.map((e) => s(e.node, e.container)));
1051
- }), de = "0.3.5-dev.0";
1354
+ }), He = "0.4.0";
1052
1355
  //#endregion
1053
- export { Y as BUILTIN_ACTIONS, ue as Window, de as version };
1356
+ export { be as BUILTIN_ACTIONS, W as DEFAULT_DETACHED_GLASS_ACTIONS, V as DEFAULT_GLASS_ACTIONS, Ve as Window, He as version };