bwin 0.2.8 → 0.2.9-dev.4

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