bwin 0.2.6 → 0.2.9-dev.3

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