bwin 0.2.0 → 0.2.2
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/README.md +2 -2
- package/dist/bwin.js +54 -53
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Binary Window
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A lightweight window-tiling JavaScript library for the browser, featuring resizable panes, drag-and-drop, and more.
|
|
4
4
|
|
|
5
|
-
[
|
|
5
|
+
[Documentation](https://bhjsdev.github.io/bwin-docs/)
|
package/dist/bwin.js
CHANGED
|
@@ -21,15 +21,15 @@ function z(e = 2, t = 3) {
|
|
|
21
21
|
}
|
|
22
22
|
return s;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function b(e, t) {
|
|
25
25
|
for (; t.firstChild; )
|
|
26
26
|
e.append(t.firstChild);
|
|
27
27
|
}
|
|
28
28
|
function H(e, t) {
|
|
29
29
|
const i = document.createElement("div");
|
|
30
|
-
|
|
30
|
+
b(i, e), b(e, t), b(t, i);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function C(e) {
|
|
33
33
|
if (typeof e == "number" && !isNaN(e))
|
|
34
34
|
return e;
|
|
35
35
|
if (typeof e == "string") {
|
|
@@ -65,7 +65,7 @@ function G(e) {
|
|
|
65
65
|
const t = document.createElement("template");
|
|
66
66
|
return t.innerHTML = e.trim(), t.content;
|
|
67
67
|
}
|
|
68
|
-
function
|
|
68
|
+
function m(e) {
|
|
69
69
|
if (e == null || e === "")
|
|
70
70
|
return null;
|
|
71
71
|
if (typeof e == "string")
|
|
@@ -121,8 +121,8 @@ function X(e, { clientX: t, clientY: i }) {
|
|
|
121
121
|
const n = e.getBoundingClientRect(), { width: s, height: o } = n, h = t - n.left, l = i - n.top;
|
|
122
122
|
if (h < 0 || h > s || l < 0 || l > o)
|
|
123
123
|
return r.Outside;
|
|
124
|
-
const a = 0.3,
|
|
125
|
-
return h < s * (0.5 - a / 2) && l >
|
|
124
|
+
const a = 0.3, d = _({ width: s, height: o, x: h }), c = U({ width: s, height: o, x: h }), g = k({ width: s, height: o, y: l }), u = Y({ width: s, height: o, y: l });
|
|
125
|
+
return h < s * (0.5 - a / 2) && l > d && l < c ? r.Left : h > s * (0.5 + a / 2) && l < d && l > c ? r.Right : l < o * (0.5 - a / 2) && h > g && h < u ? r.Top : l > o * (0.5 + a / 2) && h < g && h > u ? r.Bottom : h > s * (0.5 - a / 2) && h < s * (0.5 + a / 2) && l > o * (0.5 - a / 2) && l < o * (0.5 + a / 2) ? r.Center : r.Unknown;
|
|
126
126
|
}
|
|
127
127
|
const q = 100, j = 100, w = {
|
|
128
128
|
left: 0,
|
|
@@ -143,12 +143,12 @@ class p {
|
|
|
143
143
|
minHeight: h = w.minHeight,
|
|
144
144
|
domNode: l = null,
|
|
145
145
|
store: a = {},
|
|
146
|
-
position:
|
|
147
|
-
id:
|
|
146
|
+
position: d,
|
|
147
|
+
id: c
|
|
148
148
|
} = w) {
|
|
149
|
-
if (this.id =
|
|
149
|
+
if (this.id = c ?? z(), !d)
|
|
150
150
|
throw new Error("[bwin] Sash position is required");
|
|
151
|
-
this.position =
|
|
151
|
+
this.position = d, this.domNode = l, this._top = i, this._left = t, this._width = n, this._height = s, this.children = [], this.minWidth = o, this.minHeight = h, this.store = a;
|
|
152
152
|
}
|
|
153
153
|
walk(t) {
|
|
154
154
|
this.children.forEach((i) => i.walk(t)), t(this);
|
|
@@ -282,10 +282,10 @@ class p {
|
|
|
282
282
|
this._width = t;
|
|
283
283
|
const [n, s, o, h] = this.getChildren();
|
|
284
284
|
if (h && s) {
|
|
285
|
-
const l = h.width + s.width, a = i * (h.width / l),
|
|
286
|
-
let
|
|
287
|
-
const
|
|
288
|
-
|
|
285
|
+
const l = h.width + s.width, a = i * (h.width / l), d = l + i;
|
|
286
|
+
let c = h.width + a, g = d - c, u = s.left + a;
|
|
287
|
+
const E = h.calcMinWidth(), y = s.calcMinWidth();
|
|
288
|
+
i < 0 && (c < E && g > y ? (c = h.width, g = d - c, u = h.left + c) : g < y && c > E && (g = s.width, c = d - g, u = h.left + c)), h.width = c, s.width = g, s.left = u;
|
|
289
289
|
}
|
|
290
290
|
n && o && (n.width += i, o.width += i);
|
|
291
291
|
}
|
|
@@ -297,10 +297,13 @@ class p {
|
|
|
297
297
|
this._height = t;
|
|
298
298
|
const [n, s, o, h] = this.getChildren();
|
|
299
299
|
if (n && o) {
|
|
300
|
-
const l = n.height + o.height, a = i * (n.height / l),
|
|
301
|
-
let
|
|
302
|
-
|
|
303
|
-
|
|
300
|
+
const l = n.height + o.height, a = i * (n.height / l), d = l + i;
|
|
301
|
+
let c = n.height + a, g = d - c, u = o.top + a;
|
|
302
|
+
if (i < 0) {
|
|
303
|
+
const E = n.calcMinHeight(), y = o.calcMinHeight();
|
|
304
|
+
c < E && g > y ? (c = n.height, g = d - c, u = n.top + c) : g < y && c > E && (g = o.height, c = d - g, u = n.top + c);
|
|
305
|
+
}
|
|
306
|
+
n.height = c, o.height = g, o.top = u;
|
|
304
307
|
}
|
|
305
308
|
h && s && (h.height += i, s.height += i);
|
|
306
309
|
}
|
|
@@ -319,13 +322,13 @@ class A {
|
|
|
319
322
|
minHeight: h,
|
|
320
323
|
position: l,
|
|
321
324
|
size: a,
|
|
322
|
-
...
|
|
325
|
+
...d
|
|
323
326
|
}) {
|
|
324
327
|
f(this, "left");
|
|
325
328
|
f(this, "top");
|
|
326
329
|
f(this, "width");
|
|
327
330
|
f(this, "height");
|
|
328
|
-
this.parentRect = t, this.children = i, this.siblingConfigNode = n, this.id = s, this.minWidth = o, this.minHeight = h, this.position = this.getPosition(l), this.size = this.getSize(a), this.nonCoreData =
|
|
331
|
+
this.parentRect = t, this.children = i, this.siblingConfigNode = n, this.id = s, this.minWidth = o, this.minHeight = h, this.position = this.getPosition(l), this.size = this.getSize(a), this.nonCoreData = d, this.setBounds();
|
|
329
332
|
}
|
|
330
333
|
getPosition(t) {
|
|
331
334
|
if (!this.siblingConfigNode)
|
|
@@ -339,7 +342,7 @@ class A {
|
|
|
339
342
|
}
|
|
340
343
|
getSize(t) {
|
|
341
344
|
if (!this.siblingConfigNode)
|
|
342
|
-
return
|
|
345
|
+
return C(t);
|
|
343
346
|
if (!t) {
|
|
344
347
|
if (this.siblingConfigNode.size < 1)
|
|
345
348
|
return 1 - this.siblingConfigNode.size;
|
|
@@ -348,7 +351,7 @@ class A {
|
|
|
348
351
|
if (this.siblingConfigNode.position === r.Top || this.siblingConfigNode.position === r.Bottom)
|
|
349
352
|
return this.parentRect.height - this.siblingConfigNode.height;
|
|
350
353
|
}
|
|
351
|
-
const i =
|
|
354
|
+
const i = C(t);
|
|
352
355
|
if (i < 1) {
|
|
353
356
|
if (i + this.siblingConfigNode.size !== 1)
|
|
354
357
|
throw new Error("[bwin] Sum of sibling sizes is not equal to 1");
|
|
@@ -398,7 +401,7 @@ class A {
|
|
|
398
401
|
children: t
|
|
399
402
|
};
|
|
400
403
|
if (typeof t == "string" || typeof t == "number") {
|
|
401
|
-
const i =
|
|
404
|
+
const i = C(t);
|
|
402
405
|
if (isNaN(i))
|
|
403
406
|
throw new Error(`[bwin] Invalid size value: ${i}`);
|
|
404
407
|
return {
|
|
@@ -492,7 +495,7 @@ function J(e) {
|
|
|
492
495
|
return t.style.top = `${e.top}px`, t.style.left = `${e.left}px`, t.style.width = `${e.width}px`, t.style.height = `${e.height}px`, t.setAttribute("position", e.position), t;
|
|
493
496
|
}
|
|
494
497
|
function Q(e, { size: t }) {
|
|
495
|
-
const i =
|
|
498
|
+
const i = C(t);
|
|
496
499
|
let n = e.width / 2;
|
|
497
500
|
i && (i < 1 ? n = e.width * i : n = i);
|
|
498
501
|
const s = new p({
|
|
@@ -508,10 +511,10 @@ function Q(e, { size: t }) {
|
|
|
508
511
|
height: e.height,
|
|
509
512
|
position: r.Right
|
|
510
513
|
}), h = M(o);
|
|
511
|
-
return o.domNode = h,
|
|
514
|
+
return o.domNode = h, b(h, e.domNode), e.addChild(s), e.addChild(o), s;
|
|
512
515
|
}
|
|
513
516
|
function Z(e, { size: t }) {
|
|
514
|
-
const i =
|
|
517
|
+
const i = C(t);
|
|
515
518
|
let n = e.width / 2;
|
|
516
519
|
i && (i < 1 ? n = e.width * i : n = i);
|
|
517
520
|
const s = new p({
|
|
@@ -527,10 +530,10 @@ function Z(e, { size: t }) {
|
|
|
527
530
|
height: e.height,
|
|
528
531
|
position: r.Right
|
|
529
532
|
}), h = M(s);
|
|
530
|
-
return s.domNode = h,
|
|
533
|
+
return s.domNode = h, b(h, e.domNode), e.addChild(s), e.addChild(o), o;
|
|
531
534
|
}
|
|
532
535
|
function tt(e, { size: t }) {
|
|
533
|
-
const i =
|
|
536
|
+
const i = C(t);
|
|
534
537
|
let n = e.height / 2;
|
|
535
538
|
i && (i < 1 ? n = e.height * i : n = i);
|
|
536
539
|
const s = new p({
|
|
@@ -546,10 +549,10 @@ function tt(e, { size: t }) {
|
|
|
546
549
|
height: e.height - n,
|
|
547
550
|
position: r.Bottom
|
|
548
551
|
}), h = M(o);
|
|
549
|
-
return o.domNode = h,
|
|
552
|
+
return o.domNode = h, b(h, e.domNode), e.addChild(s), e.addChild(o), s;
|
|
550
553
|
}
|
|
551
554
|
function et(e, { size: t }) {
|
|
552
|
-
const i =
|
|
555
|
+
const i = C(t);
|
|
553
556
|
let n = e.height / 2;
|
|
554
557
|
i && (i < 1 ? n = e.height * i : n = i);
|
|
555
558
|
const s = new p({
|
|
@@ -565,7 +568,7 @@ function et(e, { size: t }) {
|
|
|
565
568
|
height: n,
|
|
566
569
|
position: r.Bottom
|
|
567
570
|
}), h = M(s);
|
|
568
|
-
return s.domNode = h,
|
|
571
|
+
return s.domNode = h, b(h, e.domNode), e.addChild(s), e.addChild(o), o;
|
|
569
572
|
}
|
|
570
573
|
function it(e, { position: t, size: i, minWidth: n, minHeight: s }) {
|
|
571
574
|
if (t === r.Left)
|
|
@@ -584,7 +587,7 @@ const nt = {
|
|
|
584
587
|
},
|
|
585
588
|
// Intended to be overridden
|
|
586
589
|
onPaneCreate(e, t) {
|
|
587
|
-
t.store.content && e.append(
|
|
590
|
+
t.store.content && e.append(m(t.store.content)), this != null && this.debug && (e.style.backgroundColor = W(), e.innerHTML = "", e.append(v(e)));
|
|
588
591
|
},
|
|
589
592
|
updatePane(e) {
|
|
590
593
|
return J(e);
|
|
@@ -699,15 +702,13 @@ const st = {
|
|
|
699
702
|
if (!this.isResizeStarted || !this.activeMuntinSash) return;
|
|
700
703
|
const [t, i, n, s] = this.activeMuntinSash.getChildren(), o = this.activeMuntinSash.isLeftRightSplit(), h = this.activeMuntinSash.isTopBottomSplit();
|
|
701
704
|
if (o && s && i) {
|
|
702
|
-
const l = e.pageX - this.lastX, a = s.width + l,
|
|
703
|
-
if (
|
|
704
|
-
|
|
705
|
-
s.width = a, i.width = c, i.left = i.left + l, this.update(), this.lastX = e.pageX;
|
|
705
|
+
const l = e.pageX - this.lastX, a = s.width + l, d = i.width - l;
|
|
706
|
+
if (l > 0 && d <= i.calcMinWidth() || l < 0 && a <= s.calcMinWidth()) return;
|
|
707
|
+
s.width = a, i.width = d, i.left = i.left + l, this.update(), this.lastX = e.pageX;
|
|
706
708
|
} else if (h && t && n) {
|
|
707
|
-
const l = e.pageY - this.lastY, a = t.height + l,
|
|
708
|
-
if (
|
|
709
|
-
|
|
710
|
-
t.height = a, n.height = c, n.top = n.top + l, this.update(), this.lastY = e.pageY;
|
|
709
|
+
const l = e.pageY - this.lastY, a = t.height + l, d = n.height - l;
|
|
710
|
+
if (l > 0 && d <= n.calcMinHeight() || l < 0 && a <= t.calcMinHeight()) return;
|
|
711
|
+
t.height = a, n.height = d, n.top = n.top + l, this.update(), this.lastY = e.pageY;
|
|
711
712
|
}
|
|
712
713
|
}), document.addEventListener("mouseup", () => {
|
|
713
714
|
this.isResizeStarted = !1, this.activeMuntinSash = null, this.revertResizeStyles();
|
|
@@ -787,7 +788,7 @@ const dt = {
|
|
|
787
788
|
onClick: (e, t) => {
|
|
788
789
|
const i = t.sillElement;
|
|
789
790
|
if (!i) throw new Error("[bwin] Sill element not found when minimizing");
|
|
790
|
-
const n =
|
|
791
|
+
const n = m('<button class="bw-minimized-glass" />');
|
|
791
792
|
i.append(n);
|
|
792
793
|
const s = e.target.closest("bw-pane"), o = e.target.closest("bw-glass"), h = s.getAttribute("sash-id"), l = s.getAttribute("position");
|
|
793
794
|
n.bwGlassElement = o, n.bwOriginalPosition = l, n.bwOriginalBoundingRect = P(s), t.removePane(h);
|
|
@@ -804,12 +805,12 @@ function ut(e, t) {
|
|
|
804
805
|
const i = e.left + e.width, n = e.top + e.height, s = t.left + t.width, o = t.top + t.height;
|
|
805
806
|
if (e.left >= s || t.left >= i || e.top >= o || t.top >= n)
|
|
806
807
|
return null;
|
|
807
|
-
const h = Math.max(e.left, t.left), l = Math.max(e.top, t.top), a = Math.min(i, s),
|
|
808
|
+
const h = Math.max(e.left, t.left), l = Math.max(e.top, t.top), a = Math.min(i, s), d = Math.min(n, o);
|
|
808
809
|
return {
|
|
809
810
|
left: h,
|
|
810
811
|
top: l,
|
|
811
812
|
width: a - h,
|
|
812
|
-
height:
|
|
813
|
+
height: d - l
|
|
813
814
|
};
|
|
814
815
|
}
|
|
815
816
|
const ft = [ct, gt, dt], pt = {
|
|
@@ -826,17 +827,17 @@ const ft = [ct, gt, dt], pt = {
|
|
|
826
827
|
l > i && (i = l, n = s);
|
|
827
828
|
}
|
|
828
829
|
}), n) {
|
|
829
|
-
const s = e.bwOriginalPosition, o = P(n);
|
|
830
|
-
let
|
|
830
|
+
const s = e.bwOriginalPosition, o = P(n), h = n.getAttribute("sash-id"), l = this.rootSash.getById(h);
|
|
831
|
+
let a = 0;
|
|
831
832
|
if (s === r.Left || s === r.Right)
|
|
832
|
-
|
|
833
|
+
a = o.width - t.width < l.minWidth ? o.width / 2 : t.width;
|
|
833
834
|
else if (s === r.Top || s === r.Bottom)
|
|
834
|
-
|
|
835
|
+
a = o.height - t.height < l.minHeight ? o.height / 2 : t.height;
|
|
835
836
|
else
|
|
836
837
|
throw new Error("[bwin] Invalid position when restoring glass");
|
|
837
838
|
this.addPane(n.getAttribute("sash-id"), {
|
|
838
839
|
position: s,
|
|
839
|
-
size:
|
|
840
|
+
size: a
|
|
840
841
|
}).domNode.append(e.bwGlassElement);
|
|
841
842
|
}
|
|
842
843
|
},
|
|
@@ -894,16 +895,16 @@ class x {
|
|
|
894
895
|
t.append(this.createTabs());
|
|
895
896
|
else if (this.title) {
|
|
896
897
|
const s = document.createElement("bw-glass-title");
|
|
897
|
-
s.append(
|
|
898
|
+
s.append(m(this.title)), t.append(s);
|
|
898
899
|
}
|
|
899
900
|
t.setAttribute("can-drag", this.draggable), t.append(this.createActions());
|
|
900
|
-
const i = document.createElement("bw-glass-content"), n =
|
|
901
|
+
const i = document.createElement("bw-glass-content"), n = m(this.content);
|
|
901
902
|
n && i.append(n), this.domNode = document.createElement("bw-glass"), this.domNode.append(t, i);
|
|
902
903
|
}
|
|
903
904
|
createTabs() {
|
|
904
905
|
const t = document.createElement("bw-glass-tab-container");
|
|
905
906
|
for (const i of this.tabs) {
|
|
906
|
-
const n = (i == null ? void 0 : i.label) ?? i, s =
|
|
907
|
+
const n = (i == null ? void 0 : i.label) ?? i, s = m(`<button class="bw-glass-tab">${n}</button>`);
|
|
907
908
|
t.append(s);
|
|
908
909
|
}
|
|
909
910
|
return t;
|
|
@@ -911,7 +912,7 @@ class x {
|
|
|
911
912
|
createActions() {
|
|
912
913
|
const t = document.createElement("bw-glass-action-container"), i = this.actions === void 0 ? ft : Array.isArray(this.actions) ? this.actions : [];
|
|
913
914
|
for (const n of i) {
|
|
914
|
-
const s = (n == null ? void 0 : n.label) ?? n, o = n.className ? `bw-glass-action ${n.className}` : "bw-glass-action", h =
|
|
915
|
+
const s = (n == null ? void 0 : n.label) ?? n, o = n.className ? `bw-glass-action ${n.className}` : "bw-glass-action", h = m(`<button class="${o}">${s}</button>`);
|
|
915
916
|
typeof n.onClick == "function" && h.addEventListener("click", (l) => {
|
|
916
917
|
n.onClick(l, this.binaryWindow);
|
|
917
918
|
}), t.append(h);
|
|
@@ -979,7 +980,7 @@ class bt extends T {
|
|
|
979
980
|
}
|
|
980
981
|
frame() {
|
|
981
982
|
super.frame(...arguments);
|
|
982
|
-
const i =
|
|
983
|
+
const i = m("<bw-sill />");
|
|
983
984
|
this.windowElement.append(i), this.sillElement = i;
|
|
984
985
|
}
|
|
985
986
|
enableFeatures() {
|