bwin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/bwin.css +1 -0
- package/dist/bwin.js +929 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Bhjs Dev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/bwin.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:root{--bw-font-family: system-ui;--bw-font-size: 14px;--bw-drop-area-bg-color: hsl(0, 0%, 0%, .05);--bw-glass-header-height: 30px;--bw-glass-header-padding: 0 4px;--bw-glass-header-bg-color: hsl(0, 0%, 97%);--bw-glass-clearance: 2px;--bw-glass-border-color: hsl(0, 0%, 10%);--bw-glass-border-color-disabled: hsl(0, 0%, 80%);--bw-glass-bg-color-disabled: hsl(0, 0%, 100%)}.body--bw-resize-x{-webkit-user-select:none;user-select:none;cursor:ew-resize}.body--bw-resize-y{-webkit-user-select:none;user-select:none;cursor:ns-resize}bw-window{position:absolute;display:block;box-sizing:border-box}bw-pane{position:absolute;overflow:auto;box-sizing:border-box;background-color:#f2f2f2}bw-pane[drop-area]:before{content:"";position:absolute;background-color:var(--bw-drop-area-bg-color)}bw-pane[drop-area=top]:before{top:0;left:0;right:0;height:50%}bw-pane[drop-area=right]:before{top:0;right:0;bottom:0;width:50%}bw-pane[drop-area=bottom]:before{bottom:0;left:0;right:0;height:50%}bw-pane[drop-area=left]:before{top:0;left:0;bottom:0;width:50%}bw-pane[drop-area=center]:before{top:0;left:0;right:0;bottom:0}bw-muntin{box-sizing:border-box;position:absolute;background-color:#fff}bw-muntin[horizontal]{cursor:ns-resize}bw-muntin[vertical]{cursor:ew-resize}bw-muntin[resizable=false]{cursor:auto}bw-window:has(bw-glass) bw-pane{background-color:transparent}bw-window:has(bw-glass) bw-pane[drop-area]:before{z-index:1}bw-window:has(bw-glass) bw-pane[drop-area=top]:before{top:var(--bw-glass-clearance);left:var(--bw-glass-clearance);right:var(--bw-glass-clearance);height:50%}bw-window:has(bw-glass) bw-pane[drop-area=right]:before{top:var(--bw-glass-clearance);right:var(--bw-glass-clearance);bottom:var(--bw-glass-clearance);width:50%}bw-window:has(bw-glass) bw-pane[drop-area=bottom]:before{bottom:var(--bw-glass-clearance);left:var(--bw-glass-clearance);right:var(--bw-glass-clearance);height:50%}bw-window:has(bw-glass) bw-pane[drop-area=left]:before{top:var(--bw-glass-clearance);left:var(--bw-glass-clearance);bottom:var(--bw-glass-clearance);width:50%}bw-window:has(bw-glass) bw-pane[drop-area=center]:before{inset:var(--bw-glass-clearance)}bw-window:has(bw-glass) bw-muntin{background-color:transparent}bw-glass{font-family:var(--bw-font-family);font-size:var(--bw-font-size);box-sizing:border-box;position:absolute;inset:var(--bw-glass-clearance);border:1px solid var(--bw-glass-border-color);background-color:#fff;display:flex;flex-direction:column}bw-glass[draggable=true]:active{cursor:move;opacity:.3}bw-glass-header{box-sizing:border-box;display:flex;align-items:center;padding:var(--bw-glass-header-padding);flex-basis:var(--bw-glass-header-height);border-bottom:1px solid var(--bw-glass-border-color);background-color:var(--bw-glass-header-bg-color)}bw-glass-tab-container{align-self:flex-end;display:flex;gap:4px}.bw-glass-tab{font-family:var(--bw-font-family);border:1px solid var(--bw-glass-border-color);border-bottom:none;cursor:pointer}.bw-glass-tab:hover{background-color:#fff}.bw-glass-tab:active{transform:translateY(1px)}bw-glass-action-container{margin-left:auto;display:flex;gap:2px}.bw-glass-action{font-family:var(--bw-font-family);border:1px solid var(--bw-glass-border-color);cursor:pointer}.bw-glass-action:hover{background-color:#fff}.bw-glass-action:active{transform:scale(.95)}.bw-glass-action--close:before{content:"✕"}.bw-glass-action--close:disabled{border:1px solid var(--bw-glass-border-color-disabled);background-color:var(--bw-glass-bg-color-disabled);cursor:not-allowed}.bw-glass-action--close:disabled:hover{background-color:var(--bw-glass-bg-color-disabled)}.bw-glass-action--close:disabled:active{transform:scale(1)}bw-glass-content{display:block;box-sizing:border-box;overflow:auto;flex-grow:1}
|
package/dist/bwin.js
ADDED
|
@@ -0,0 +1,929 @@
|
|
|
1
|
+
var $ = Object.defineProperty;
|
|
2
|
+
var B = (e, t, i) => t in e ? $(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
|
|
3
|
+
var p = (e, t, i) => B(e, typeof t != "symbol" ? t + "" : t, i);
|
|
4
|
+
function W(e = 0.7, t = 128) {
|
|
5
|
+
const i = 256 - t, n = Math.floor(Math.random() * i + t), o = Math.floor(Math.random() * i + t), s = Math.floor(Math.random() * i + t), r = Math.max(0.5, Math.random() * e);
|
|
6
|
+
return `rgba(${n}, ${o}, ${s}, ${r})`;
|
|
7
|
+
}
|
|
8
|
+
function R(e = 2, t = 3) {
|
|
9
|
+
if (e < 0 || t < 0)
|
|
10
|
+
throw new Error("Parameters must be non-negative numbers");
|
|
11
|
+
const i = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", n = "0123456789";
|
|
12
|
+
let o = "";
|
|
13
|
+
for (let s = 0; s < e; s++) {
|
|
14
|
+
const r = Math.floor(Math.random() * i.length);
|
|
15
|
+
o += i[r];
|
|
16
|
+
}
|
|
17
|
+
o += "-";
|
|
18
|
+
for (let s = 0; s < t; s++) {
|
|
19
|
+
const r = Math.floor(Math.random() * n.length);
|
|
20
|
+
o += n[r];
|
|
21
|
+
}
|
|
22
|
+
return o;
|
|
23
|
+
}
|
|
24
|
+
function C(e, t) {
|
|
25
|
+
for (; t.firstChild; )
|
|
26
|
+
e.append(t.firstChild);
|
|
27
|
+
}
|
|
28
|
+
function H(e, t) {
|
|
29
|
+
const i = document.createElement("div");
|
|
30
|
+
C(i, e), C(e, t), C(t, i);
|
|
31
|
+
}
|
|
32
|
+
function P(e) {
|
|
33
|
+
if (typeof e == "number" && !isNaN(e))
|
|
34
|
+
return e;
|
|
35
|
+
if (typeof e == "string") {
|
|
36
|
+
const t = e.trim();
|
|
37
|
+
if (t.endsWith("%")) {
|
|
38
|
+
const i = t.slice(0, -1);
|
|
39
|
+
if (!i) return NaN;
|
|
40
|
+
const n = Number(i);
|
|
41
|
+
return isNaN(n) ? NaN : n / 100;
|
|
42
|
+
}
|
|
43
|
+
if (t.endsWith("px")) {
|
|
44
|
+
const i = t.slice(0, -2);
|
|
45
|
+
if (!i) return NaN;
|
|
46
|
+
const n = Number(i);
|
|
47
|
+
return isNaN(n) ? NaN : n;
|
|
48
|
+
}
|
|
49
|
+
return Number(t);
|
|
50
|
+
}
|
|
51
|
+
return NaN;
|
|
52
|
+
}
|
|
53
|
+
function I(e) {
|
|
54
|
+
return e !== null && typeof e == "object" && !Array.isArray(e) && Object.getPrototypeOf(e) === Object.prototype;
|
|
55
|
+
}
|
|
56
|
+
function O(e, t) {
|
|
57
|
+
for (const i in t) {
|
|
58
|
+
if (Object.hasOwn(e, i))
|
|
59
|
+
throw new Error(`Key "${i}" already exists in target object`);
|
|
60
|
+
e[i] = t[i];
|
|
61
|
+
}
|
|
62
|
+
return e;
|
|
63
|
+
}
|
|
64
|
+
function G(e) {
|
|
65
|
+
const t = document.createElement("template");
|
|
66
|
+
return t.innerHTML = e.trim(), t.content;
|
|
67
|
+
}
|
|
68
|
+
function E(e) {
|
|
69
|
+
if (e == null || e === "")
|
|
70
|
+
return null;
|
|
71
|
+
if (typeof e == "string")
|
|
72
|
+
try {
|
|
73
|
+
const t = G(e);
|
|
74
|
+
return t.childNodes.length === 1 ? t.firstChild : t;
|
|
75
|
+
} catch {
|
|
76
|
+
return document.createTextNode(e);
|
|
77
|
+
}
|
|
78
|
+
return e instanceof Node ? e : document.createTextNode(String(e));
|
|
79
|
+
}
|
|
80
|
+
const h = {
|
|
81
|
+
Top: "top",
|
|
82
|
+
Right: "right",
|
|
83
|
+
Bottom: "bottom",
|
|
84
|
+
Left: "left",
|
|
85
|
+
Center: "center",
|
|
86
|
+
Root: "root",
|
|
87
|
+
Unknown: "unknown",
|
|
88
|
+
Outside: "outside"
|
|
89
|
+
};
|
|
90
|
+
function _(e) {
|
|
91
|
+
switch (e) {
|
|
92
|
+
case h.Top:
|
|
93
|
+
return h.Bottom;
|
|
94
|
+
case h.Right:
|
|
95
|
+
return h.Left;
|
|
96
|
+
case h.Bottom:
|
|
97
|
+
return h.Top;
|
|
98
|
+
case h.Left:
|
|
99
|
+
return h.Right;
|
|
100
|
+
default:
|
|
101
|
+
throw new Error(`[bwin] Invalid position: ${e}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function F({ width: e, height: t, x: i }) {
|
|
105
|
+
return t / e * i;
|
|
106
|
+
}
|
|
107
|
+
function U({ width: e, height: t, y: i }) {
|
|
108
|
+
return e / t * i;
|
|
109
|
+
}
|
|
110
|
+
function Y({ width: e, height: t, x: i }) {
|
|
111
|
+
return t - t / e * i;
|
|
112
|
+
}
|
|
113
|
+
function X({ width: e, height: t, y: i }) {
|
|
114
|
+
return e - e / t * i;
|
|
115
|
+
}
|
|
116
|
+
function k(e, { clientX: t, clientY: i }) {
|
|
117
|
+
const n = e.getBoundingClientRect(), { width: o, height: s } = n, r = t - n.left, l = i - n.top;
|
|
118
|
+
if (r < 0 || r > o || l < 0 || l > s)
|
|
119
|
+
return h.Outside;
|
|
120
|
+
const d = 0.3, c = F({ width: o, height: s, x: r }), a = Y({ width: o, height: s, x: r }), f = U({ width: o, height: s, y: l }), u = X({ width: o, height: s, y: l });
|
|
121
|
+
return r < o * (0.5 - d / 2) && l > c && l < a ? h.Left : r > o * (0.5 + d / 2) && l < c && l > a ? h.Right : l < s * (0.5 - d / 2) && r > f && r < u ? h.Top : l > s * (0.5 + d / 2) && r < f && r > u ? h.Bottom : r > o * (0.5 - d / 2) && r < o * (0.5 + d / 2) && l > s * (0.5 - d / 2) && l < s * (0.5 + d / 2) ? h.Center : h.Unknown;
|
|
122
|
+
}
|
|
123
|
+
const w = {
|
|
124
|
+
top: 0,
|
|
125
|
+
left: 0,
|
|
126
|
+
width: 100,
|
|
127
|
+
height: 100,
|
|
128
|
+
// Initial min values, real min width/height is calculated based on children
|
|
129
|
+
minWidth: 20,
|
|
130
|
+
minHeight: 20
|
|
131
|
+
};
|
|
132
|
+
class g {
|
|
133
|
+
constructor({
|
|
134
|
+
top: t = w.top,
|
|
135
|
+
left: i = w.left,
|
|
136
|
+
width: n = w.width,
|
|
137
|
+
height: o = w.height,
|
|
138
|
+
minWidth: s = w.minWidth,
|
|
139
|
+
minHeight: r = w.minHeight,
|
|
140
|
+
domNode: l = null,
|
|
141
|
+
store: d = {},
|
|
142
|
+
position: c,
|
|
143
|
+
id: a
|
|
144
|
+
} = w) {
|
|
145
|
+
if (this.id = a ?? R(), !c)
|
|
146
|
+
throw new Error("[bwin] Sash position is required");
|
|
147
|
+
this.position = c, this.domNode = l, this._top = t, this._left = i, this._width = n, this._height = o, this.children = [], this.minWidth = s, this.minHeight = r, this.store = d;
|
|
148
|
+
}
|
|
149
|
+
walk(t) {
|
|
150
|
+
this.children.forEach((i) => i.walk(t)), t(this);
|
|
151
|
+
}
|
|
152
|
+
isLeaf() {
|
|
153
|
+
return this.children.length === 0;
|
|
154
|
+
}
|
|
155
|
+
// A sash that doesn't split is a leaf, in UI it's a pane
|
|
156
|
+
isSplit() {
|
|
157
|
+
return this.children.length > 0;
|
|
158
|
+
}
|
|
159
|
+
isLeftRightSplit() {
|
|
160
|
+
return this.children.some(
|
|
161
|
+
(t) => t.position === h.Left || t.position === h.Right
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
isTopBottomSplit() {
|
|
165
|
+
return this.children.some(
|
|
166
|
+
(t) => t.position === h.Top || t.position === h.Bottom
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
get leftChild() {
|
|
170
|
+
return this.children.find((t) => t.position === h.Left);
|
|
171
|
+
}
|
|
172
|
+
get rightChild() {
|
|
173
|
+
return this.children.find((t) => t.position === h.Right);
|
|
174
|
+
}
|
|
175
|
+
get topChild() {
|
|
176
|
+
return this.children.find((t) => t.position === h.Top);
|
|
177
|
+
}
|
|
178
|
+
get bottomChild() {
|
|
179
|
+
return this.children.find((t) => t.position === h.Bottom);
|
|
180
|
+
}
|
|
181
|
+
getChildren() {
|
|
182
|
+
let t = null, i = null, n = null, o = null;
|
|
183
|
+
for (const s of this.children)
|
|
184
|
+
s.position === h.Left ? t = s : s.position === h.Right ? i = s : s.position === h.Top ? n = s : s.position === h.Bottom && (o = s);
|
|
185
|
+
return [n, i, o, t];
|
|
186
|
+
}
|
|
187
|
+
getAllLeafDescendants() {
|
|
188
|
+
const t = [];
|
|
189
|
+
return this.walk((i) => {
|
|
190
|
+
i.children.length === 0 && t.push(i);
|
|
191
|
+
}), t;
|
|
192
|
+
}
|
|
193
|
+
calcMinWidth() {
|
|
194
|
+
if (this.isLeaf())
|
|
195
|
+
return this.minWidth;
|
|
196
|
+
const [t, i, n, o] = this.getChildren();
|
|
197
|
+
if (o && i) {
|
|
198
|
+
const s = o.calcMinWidth() + i.calcMinWidth();
|
|
199
|
+
return Math.max(this.minWidth, s);
|
|
200
|
+
}
|
|
201
|
+
if (t && n) {
|
|
202
|
+
const s = Math.max(t.calcMinWidth(), n.calcMinWidth());
|
|
203
|
+
return Math.max(this.minWidth, s);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
calcMinHeight() {
|
|
207
|
+
if (this.isLeaf())
|
|
208
|
+
return this.minHeight;
|
|
209
|
+
const [t, i, n, o] = this.getChildren();
|
|
210
|
+
if (o && i) {
|
|
211
|
+
const s = Math.max(o.calcMinHeight(), i.calcMinHeight());
|
|
212
|
+
return Math.max(this.minHeight, s);
|
|
213
|
+
}
|
|
214
|
+
if (t && n) {
|
|
215
|
+
const s = t.calcMinHeight() + n.calcMinHeight();
|
|
216
|
+
return Math.max(this.minHeight, s);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// Get self or descendant by id
|
|
220
|
+
getById(t) {
|
|
221
|
+
if (this.id === t)
|
|
222
|
+
return this;
|
|
223
|
+
for (const i of this.children) {
|
|
224
|
+
const n = i.getById(t);
|
|
225
|
+
if (n)
|
|
226
|
+
return n;
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
// Get all ids of self and descendants
|
|
231
|
+
getAllIds() {
|
|
232
|
+
const t = [this.id];
|
|
233
|
+
for (const i of this.children)
|
|
234
|
+
t.push(...i.getAllIds());
|
|
235
|
+
return t;
|
|
236
|
+
}
|
|
237
|
+
addChild(t) {
|
|
238
|
+
if (this.children.length >= 2)
|
|
239
|
+
throw new Error("[bwin] Maximum 2 children allowed");
|
|
240
|
+
this.children.push(t);
|
|
241
|
+
}
|
|
242
|
+
getDescendantParentById(t) {
|
|
243
|
+
for (const i of this.children) {
|
|
244
|
+
if (i.id === t)
|
|
245
|
+
return this;
|
|
246
|
+
const n = i.getDescendantParentById(t);
|
|
247
|
+
if (n)
|
|
248
|
+
return n;
|
|
249
|
+
}
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
getChildSiblingById(t) {
|
|
253
|
+
return this.children.find((i) => i.id !== t);
|
|
254
|
+
}
|
|
255
|
+
get top() {
|
|
256
|
+
return this._top;
|
|
257
|
+
}
|
|
258
|
+
set top(t) {
|
|
259
|
+
const i = t - this._top;
|
|
260
|
+
this._top = t;
|
|
261
|
+
const [n, o, s, r] = this.getChildren();
|
|
262
|
+
n && s && (n.top += i, s.top += i), r && o && (r.top += i, o.top += i);
|
|
263
|
+
}
|
|
264
|
+
get left() {
|
|
265
|
+
return this._left;
|
|
266
|
+
}
|
|
267
|
+
set left(t) {
|
|
268
|
+
const i = t - this._left;
|
|
269
|
+
this._left = t;
|
|
270
|
+
const [n, o, s, r] = this.getChildren();
|
|
271
|
+
r && o && (r.left += i, o.left += i), n && s && (n.left += i, s.left += i);
|
|
272
|
+
}
|
|
273
|
+
get width() {
|
|
274
|
+
return this._width;
|
|
275
|
+
}
|
|
276
|
+
set width(t) {
|
|
277
|
+
const i = t - this._width;
|
|
278
|
+
this._width = t;
|
|
279
|
+
const [n, o, s, r] = this.getChildren();
|
|
280
|
+
if (r && o) {
|
|
281
|
+
const l = r.width + o.width, d = i * (r.width / l), c = l + i;
|
|
282
|
+
let a = r.width + d, f = c - a, u = o.left + d;
|
|
283
|
+
const m = r.calcMinWidth(), b = o.calcMinWidth();
|
|
284
|
+
a < m && f > b ? (a = m, f = c - a, u = r.left + a) : f < b && a > m && (f = b, a = c - f, u = r.left + a), r.width = a, o.width = f, o.left = u;
|
|
285
|
+
}
|
|
286
|
+
n && s && (n.width += i, s.width += i);
|
|
287
|
+
}
|
|
288
|
+
get height() {
|
|
289
|
+
return this._height;
|
|
290
|
+
}
|
|
291
|
+
set height(t) {
|
|
292
|
+
const i = t - this._height;
|
|
293
|
+
this._height = t;
|
|
294
|
+
const [n, o, s, r] = this.getChildren();
|
|
295
|
+
if (n && s) {
|
|
296
|
+
const l = n.height + s.height, d = i * (n.height / l), c = l + i;
|
|
297
|
+
let a = n.height + d, f = c - a, u = s.top + d;
|
|
298
|
+
const m = n.calcMinHeight(), b = s.calcMinHeight();
|
|
299
|
+
a < m && f > b ? (a = m, f = c - a, u = n.top + a) : f < b && a > m && (f = b, a = c - f, u = n.top + a), n.height = a, s.height = f, s.top = u;
|
|
300
|
+
}
|
|
301
|
+
r && o && (r.height += i, o.height += i);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const A = {
|
|
305
|
+
size: "50%",
|
|
306
|
+
position: h.Left
|
|
307
|
+
};
|
|
308
|
+
class M {
|
|
309
|
+
constructor({
|
|
310
|
+
parentRect: t,
|
|
311
|
+
children: i,
|
|
312
|
+
siblingConfigNode: n,
|
|
313
|
+
id: o,
|
|
314
|
+
minWidth: s,
|
|
315
|
+
minHeight: r,
|
|
316
|
+
position: l,
|
|
317
|
+
size: d,
|
|
318
|
+
...c
|
|
319
|
+
}) {
|
|
320
|
+
p(this, "left");
|
|
321
|
+
p(this, "top");
|
|
322
|
+
p(this, "width");
|
|
323
|
+
p(this, "height");
|
|
324
|
+
this.parentRect = t, this.children = i, this.siblingConfigNode = n, this.id = o, this.minWidth = s, this.minHeight = r, this.position = this.getPosition(l), this.size = this.getSize(d), this.nonCoreData = c, this.setBounds();
|
|
325
|
+
}
|
|
326
|
+
getPosition(t) {
|
|
327
|
+
if (!this.siblingConfigNode)
|
|
328
|
+
return t;
|
|
329
|
+
const i = _(this.siblingConfigNode.position);
|
|
330
|
+
if (!t)
|
|
331
|
+
return i;
|
|
332
|
+
if (t !== i)
|
|
333
|
+
throw new Error("[bwin] Sibling position and current position are not opposite");
|
|
334
|
+
return t;
|
|
335
|
+
}
|
|
336
|
+
getSize(t) {
|
|
337
|
+
if (!this.siblingConfigNode)
|
|
338
|
+
return P(t);
|
|
339
|
+
if (!t) {
|
|
340
|
+
if (this.siblingConfigNode.size < 1)
|
|
341
|
+
return 1 - this.siblingConfigNode.size;
|
|
342
|
+
if (this.siblingConfigNode.position === h.Left || this.siblingConfigNode.position === h.Right)
|
|
343
|
+
return this.parentRect.width - this.siblingConfigNode.width;
|
|
344
|
+
if (this.siblingConfigNode.position === h.Top || this.siblingConfigNode.position === h.Bottom)
|
|
345
|
+
return this.parentRect.height - this.siblingConfigNode.height;
|
|
346
|
+
}
|
|
347
|
+
const i = P(t);
|
|
348
|
+
if (i < 1) {
|
|
349
|
+
if (i + this.siblingConfigNode.size !== 1)
|
|
350
|
+
throw new Error("[bwin] Sum of sibling sizes is not equal to 1");
|
|
351
|
+
} else {
|
|
352
|
+
if ((this.position === h.Left || this.position === h.Right) && i + this.siblingConfigNode.size !== this.parentRect.width)
|
|
353
|
+
throw new Error("[bwin] Sum of sibling sizes is not equal to parent width");
|
|
354
|
+
if ((this.position === h.Top || this.position === h.Bottom) && i + this.siblingConfigNode.size !== this.parentRect.height)
|
|
355
|
+
throw new Error("[bwin] Sum of sibling sizes is not equal to parent height");
|
|
356
|
+
}
|
|
357
|
+
return i;
|
|
358
|
+
}
|
|
359
|
+
setBounds() {
|
|
360
|
+
if (this.position === h.Root)
|
|
361
|
+
this.left = 0, this.top = 0, this.width = this.parentRect.width, this.height = this.parentRect.height;
|
|
362
|
+
else if (this.position === h.Left) {
|
|
363
|
+
const t = this.size < 1 ? this.parentRect.width * this.size : this.size;
|
|
364
|
+
this.left = this.parentRect.left, this.top = this.parentRect.top, this.width = t, this.height = this.parentRect.height;
|
|
365
|
+
} else if (this.position === h.Right) {
|
|
366
|
+
const t = this.size < 1 ? this.parentRect.width * this.size : this.size;
|
|
367
|
+
this.left = this.parentRect.left + this.parentRect.width - t, this.top = this.parentRect.top, this.width = t, this.height = this.parentRect.height;
|
|
368
|
+
} else if (this.position === h.Top) {
|
|
369
|
+
const t = this.size < 1 ? this.parentRect.height * this.size : this.size;
|
|
370
|
+
this.left = this.parentRect.left, this.top = this.parentRect.top, this.width = this.parentRect.width, this.height = t;
|
|
371
|
+
} else if (this.position === h.Bottom) {
|
|
372
|
+
const t = this.size < 1 ? this.parentRect.height * this.size : this.size;
|
|
373
|
+
this.left = this.parentRect.left, this.top = this.parentRect.top + this.parentRect.height - t, this.width = this.parentRect.width, this.height = t;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
createSash() {
|
|
377
|
+
return new g({
|
|
378
|
+
left: this.left,
|
|
379
|
+
top: this.top,
|
|
380
|
+
width: this.width,
|
|
381
|
+
height: this.height,
|
|
382
|
+
position: this.position,
|
|
383
|
+
id: this.id,
|
|
384
|
+
minWidth: this.minWidth,
|
|
385
|
+
minHeight: this.minHeight,
|
|
386
|
+
store: this.nonCoreData
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
normConfig(t) {
|
|
390
|
+
if (I(t))
|
|
391
|
+
return t;
|
|
392
|
+
if (Array.isArray(t))
|
|
393
|
+
return {
|
|
394
|
+
children: t
|
|
395
|
+
};
|
|
396
|
+
if (typeof t == "string" || typeof t == "number") {
|
|
397
|
+
const i = P(t);
|
|
398
|
+
if (isNaN(i))
|
|
399
|
+
throw new Error(`[bwin] Invalid size value: ${i}`);
|
|
400
|
+
return {
|
|
401
|
+
size: t
|
|
402
|
+
};
|
|
403
|
+
} else {
|
|
404
|
+
if (t == null)
|
|
405
|
+
return {};
|
|
406
|
+
throw new Error(`[bwin] Invalid config value: ${t}`);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
createPrimaryConfigNode({ size: t, position: i, children: n, id: o, minWidth: s, minHeight: r, ...l }) {
|
|
410
|
+
return new M({
|
|
411
|
+
parentRect: this,
|
|
412
|
+
size: t ?? A.size,
|
|
413
|
+
position: i ?? A.position,
|
|
414
|
+
children: n,
|
|
415
|
+
id: o,
|
|
416
|
+
minWidth: s,
|
|
417
|
+
minHeight: r,
|
|
418
|
+
...l
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
createSecondaryConfigNode({ size: t, position: i, children: n, id: o, minWidth: s, minHeight: r, ...l }, d) {
|
|
422
|
+
return new M({
|
|
423
|
+
parentRect: this,
|
|
424
|
+
size: t,
|
|
425
|
+
position: i,
|
|
426
|
+
children: n,
|
|
427
|
+
siblingConfigNode: d,
|
|
428
|
+
id: o,
|
|
429
|
+
minWidth: s,
|
|
430
|
+
minHeight: r,
|
|
431
|
+
...l
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
buildSashTree() {
|
|
435
|
+
const t = this.createSash();
|
|
436
|
+
if (!Array.isArray(this.children) || this.children.length === 0)
|
|
437
|
+
return t;
|
|
438
|
+
const i = this.normConfig(this.children[0]), n = this.normConfig(this.children.at(1));
|
|
439
|
+
let o, s;
|
|
440
|
+
return !i.size && !i.position && n ? (n.position || (n.position = h.Right), o = this.createPrimaryConfigNode(n), s = this.createSecondaryConfigNode(
|
|
441
|
+
i,
|
|
442
|
+
o
|
|
443
|
+
)) : (o = this.createPrimaryConfigNode(i), s = this.createSecondaryConfigNode(
|
|
444
|
+
n,
|
|
445
|
+
o
|
|
446
|
+
)), o && s && (t.children.push(o.buildSashTree()), t.children.push(s.buildSashTree())), t;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
const v = {
|
|
450
|
+
width: 333,
|
|
451
|
+
height: 333
|
|
452
|
+
}, D = {
|
|
453
|
+
fitContainer: !1
|
|
454
|
+
};
|
|
455
|
+
class q extends M {
|
|
456
|
+
constructor({
|
|
457
|
+
id: t,
|
|
458
|
+
children: i,
|
|
459
|
+
width: n = v.width,
|
|
460
|
+
height: o = v.height,
|
|
461
|
+
fitContainer: s = D.fitContainer,
|
|
462
|
+
...r
|
|
463
|
+
} = {
|
|
464
|
+
...v,
|
|
465
|
+
...D
|
|
466
|
+
}) {
|
|
467
|
+
super({
|
|
468
|
+
id: t,
|
|
469
|
+
children: i,
|
|
470
|
+
size: NaN,
|
|
471
|
+
position: h.Root,
|
|
472
|
+
parentRect: { width: n, height: o },
|
|
473
|
+
...r
|
|
474
|
+
}), this.fitContainer = s;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
class j extends g {
|
|
478
|
+
constructor(t = w) {
|
|
479
|
+
super({ ...t, position: h.Root }), Object.assign(this, D);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
const K = {
|
|
483
|
+
createPane(e) {
|
|
484
|
+
const t = N(e);
|
|
485
|
+
return e.store.droppable === !1 && t.setAttribute("can-drop", "false"), t;
|
|
486
|
+
},
|
|
487
|
+
// Intended to be overridden
|
|
488
|
+
onPaneCreate(e, t) {
|
|
489
|
+
t.store.content && e.append(E(t.store.content)), this != null && this.debug && (e.style.backgroundColor = W(), e.innerHTML = "", e.append(S(e)));
|
|
490
|
+
},
|
|
491
|
+
updatePane(e) {
|
|
492
|
+
return V(e);
|
|
493
|
+
},
|
|
494
|
+
// Intended to be overridden
|
|
495
|
+
onPaneUpdate(e, t) {
|
|
496
|
+
this != null && this.debug && (e.innerHTML = "", e.append(S(e)));
|
|
497
|
+
},
|
|
498
|
+
/**
|
|
499
|
+
* Add a pane into the target pane. The two panes become next to each other
|
|
500
|
+
*
|
|
501
|
+
* @param {string} targetPaneSashId - The Sash ID of the target pane that the new pane moves into
|
|
502
|
+
* @param {'top'|'right'|'bottom'|'left'} position - The position of the new pane relative to the target pane
|
|
503
|
+
* @returns {Sash} - The newly created sash
|
|
504
|
+
*/
|
|
505
|
+
addPane(e, t) {
|
|
506
|
+
if (!t) throw new Error("[bwin] Position is required when adding pane");
|
|
507
|
+
const i = this.rootSash.getById(e);
|
|
508
|
+
if (!i) throw new Error("[bwin] Parent sash not found when adding pane");
|
|
509
|
+
const n = et(i, t);
|
|
510
|
+
return i.id = R(), this.update(), n;
|
|
511
|
+
},
|
|
512
|
+
/**
|
|
513
|
+
* Remove a pane
|
|
514
|
+
*
|
|
515
|
+
* @param {string} sashId - The Sash ID of the pane to be removed
|
|
516
|
+
*/
|
|
517
|
+
removePane(e) {
|
|
518
|
+
const t = this.rootSash.getDescendantParentById(e);
|
|
519
|
+
if (!t) throw new Error("[bwin] Can not remove root pane");
|
|
520
|
+
const i = t.getChildSiblingById(e);
|
|
521
|
+
t.id = R(), i.children.length === 0 ? (t.domNode = i.domNode, t.domNode.setAttribute("sash-id", t.id), t.children = []) : (t.children = i.children, i.position === h.Left ? i.width = t.width : i.position === h.Right ? (i.width = t.width, i.left = t.left) : i.position === h.Top ? i.height = t.height : i.position === h.Bottom && (i.height = t.height, i.top = t.top)), this.update();
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
function N(e) {
|
|
525
|
+
const t = document.createElement("bw-pane");
|
|
526
|
+
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;
|
|
527
|
+
}
|
|
528
|
+
function V(e) {
|
|
529
|
+
const t = e.domNode;
|
|
530
|
+
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;
|
|
531
|
+
}
|
|
532
|
+
function J(e) {
|
|
533
|
+
const t = new g({
|
|
534
|
+
top: e.top,
|
|
535
|
+
left: e.left,
|
|
536
|
+
width: e.width / 2,
|
|
537
|
+
height: e.height,
|
|
538
|
+
position: h.Left
|
|
539
|
+
}), i = new g({
|
|
540
|
+
top: e.top,
|
|
541
|
+
left: e.left + t.width,
|
|
542
|
+
width: e.width / 2,
|
|
543
|
+
height: e.height,
|
|
544
|
+
position: h.Right
|
|
545
|
+
}), n = N(i);
|
|
546
|
+
return i.domNode = n, C(n, e.domNode), e.addChild(t), e.addChild(i), t;
|
|
547
|
+
}
|
|
548
|
+
function Q(e) {
|
|
549
|
+
const t = new g({
|
|
550
|
+
top: e.top,
|
|
551
|
+
left: e.left,
|
|
552
|
+
width: e.width / 2,
|
|
553
|
+
height: e.height,
|
|
554
|
+
position: h.Left
|
|
555
|
+
}), i = N(t);
|
|
556
|
+
t.domNode = i, C(i, e.domNode);
|
|
557
|
+
const n = new g({
|
|
558
|
+
top: e.top,
|
|
559
|
+
left: e.left + t.width,
|
|
560
|
+
width: e.width / 2,
|
|
561
|
+
height: e.height,
|
|
562
|
+
position: h.Right
|
|
563
|
+
});
|
|
564
|
+
return e.addChild(t), e.addChild(n), n;
|
|
565
|
+
}
|
|
566
|
+
function Z(e) {
|
|
567
|
+
const t = new g({
|
|
568
|
+
top: e.top,
|
|
569
|
+
left: e.left,
|
|
570
|
+
width: e.width,
|
|
571
|
+
height: e.height / 2,
|
|
572
|
+
position: h.Top
|
|
573
|
+
}), i = new g({
|
|
574
|
+
top: e.top + t.height,
|
|
575
|
+
left: e.left,
|
|
576
|
+
width: e.width,
|
|
577
|
+
height: e.height / 2,
|
|
578
|
+
position: h.Bottom
|
|
579
|
+
}), n = N(i);
|
|
580
|
+
return i.domNode = n, C(n, e.domNode), e.addChild(t), e.addChild(i), t;
|
|
581
|
+
}
|
|
582
|
+
function tt(e) {
|
|
583
|
+
const t = new g({
|
|
584
|
+
top: e.top,
|
|
585
|
+
left: e.left,
|
|
586
|
+
width: e.width,
|
|
587
|
+
height: e.height / 2,
|
|
588
|
+
position: h.Top
|
|
589
|
+
}), i = N(t);
|
|
590
|
+
t.domNode = i, C(i, e.domNode);
|
|
591
|
+
const n = new g({
|
|
592
|
+
top: e.top + t.height,
|
|
593
|
+
left: e.left,
|
|
594
|
+
width: e.width,
|
|
595
|
+
height: e.height / 2,
|
|
596
|
+
position: h.Bottom
|
|
597
|
+
});
|
|
598
|
+
return e.addChild(t), e.addChild(n), n;
|
|
599
|
+
}
|
|
600
|
+
function et(e, t) {
|
|
601
|
+
if (t === h.Left)
|
|
602
|
+
return J(e);
|
|
603
|
+
if (t === h.Right)
|
|
604
|
+
return Q(e);
|
|
605
|
+
if (t === h.Top)
|
|
606
|
+
return Z(e);
|
|
607
|
+
if (t === h.Bottom)
|
|
608
|
+
return tt(e);
|
|
609
|
+
}
|
|
610
|
+
function S(e) {
|
|
611
|
+
const t = document.createElement("pre");
|
|
612
|
+
t.style.fontSize = "10px";
|
|
613
|
+
const i = `
|
|
614
|
+
id: ${e.getAttribute("sash-id")}
|
|
615
|
+
top: ${e.style.top}
|
|
616
|
+
left: ${e.style.left}
|
|
617
|
+
width: ${e.style.width}
|
|
618
|
+
height: ${e.style.height}
|
|
619
|
+
position: ${e.getAttribute("position")}
|
|
620
|
+
`;
|
|
621
|
+
return t.innerHTML = i.trim(), t;
|
|
622
|
+
}
|
|
623
|
+
const it = {
|
|
624
|
+
create() {
|
|
625
|
+
const e = document.createElement("bw-window");
|
|
626
|
+
e.style.width = `${this.rootSash.width}px`, e.style.height = `${this.rootSash.height}px`, e.setAttribute("sash-id", this.rootSash.id), this.rootSash.walk((t) => {
|
|
627
|
+
let i = null;
|
|
628
|
+
t.children.length > 0 ? (i = this.createMuntin(t), this.onMuntinCreate(i, t), e.append(i)) : (i = this.createPane(t), this.onPaneCreate(i, t), e.prepend(i)), t.domNode = i;
|
|
629
|
+
}), this.windowElement = e, this.containerElement.append(this.windowElement);
|
|
630
|
+
},
|
|
631
|
+
update() {
|
|
632
|
+
this.windowElement.style.width = `${this.rootSash.width}px`, this.windowElement.style.height = `${this.rootSash.height}px`;
|
|
633
|
+
const e = this.rootSash.getAllIds(), t = [];
|
|
634
|
+
this.windowElement.querySelectorAll("[sash-id]").forEach((i) => {
|
|
635
|
+
const n = i.getAttribute("sash-id");
|
|
636
|
+
t.push(n), e.includes(n) || i.remove();
|
|
637
|
+
}), this.rootSash.walk((i) => {
|
|
638
|
+
i.children.length > 0 ? t.includes(i.id) ? (this.updateMuntin(i), this.onMuntinUpdate(i.domNode, i)) : (i.domNode = this.createMuntin(i), this.windowElement.append(i.domNode)) : t.includes(i.id) ? (this.updatePane(i), this.onPaneUpdate(i.domNode, i)) : (i.domNode || (i.domNode = this.createPane(i)), this.windowElement.prepend(i.domNode));
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
}, nt = {
|
|
642
|
+
muntinSize: 4,
|
|
643
|
+
createMuntin(e) {
|
|
644
|
+
const t = document.createElement("bw-muntin"), i = e.leftChild, n = e.topChild;
|
|
645
|
+
return i ? (t.style.width = `${this.muntinSize}px`, t.style.height = `${e.height}px`, t.style.top = `${e.top}px`, t.style.left = `${e.left + i.width - this.muntinSize / 2}px`, t.setAttribute("vertical", "")) : n && (t.style.width = `${e.width}px`, t.style.height = `${this.muntinSize}px`, t.style.top = `${e.top + n.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;
|
|
646
|
+
},
|
|
647
|
+
onMuntinCreate(e, t) {
|
|
648
|
+
},
|
|
649
|
+
updateMuntin(e) {
|
|
650
|
+
const t = e.domNode, i = e.leftChild, n = e.topChild;
|
|
651
|
+
i ? (t.style.height = `${e.height}px`, t.style.top = `${e.top}px`, t.style.left = `${e.left + i.width - this.muntinSize / 2}px`) : n && (t.style.width = `${e.width}px`, t.style.top = `${e.top + n.height - this.muntinSize / 2}px`, t.style.left = `${e.left}px`);
|
|
652
|
+
},
|
|
653
|
+
onMuntinUpdate(e, t) {
|
|
654
|
+
}
|
|
655
|
+
}, ot = {
|
|
656
|
+
fitContainer: !1,
|
|
657
|
+
enableFitContainer() {
|
|
658
|
+
new ResizeObserver((t) => {
|
|
659
|
+
for (const i of t)
|
|
660
|
+
i.target === this.containerElement && this.fitContainer && (this.rootSash.width = i.contentRect.width, this.rootSash.height = i.contentRect.height, this.update());
|
|
661
|
+
}).observe(this.containerElement);
|
|
662
|
+
}
|
|
663
|
+
}, st = {
|
|
664
|
+
activeMuntinSash: null,
|
|
665
|
+
isResizeStarted: !1,
|
|
666
|
+
isDropStarted: !1,
|
|
667
|
+
lastX: 0,
|
|
668
|
+
lastY: 0,
|
|
669
|
+
applyResizeStyles() {
|
|
670
|
+
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");
|
|
671
|
+
},
|
|
672
|
+
revertResizeStyles() {
|
|
673
|
+
document.body.classList.remove("body--bw-resize-x"), document.body.classList.remove("body--bw-resize-y");
|
|
674
|
+
},
|
|
675
|
+
enableResize() {
|
|
676
|
+
document.addEventListener("mousedown", (e) => {
|
|
677
|
+
if (e.target.tagName !== "BW-MUNTIN" || e.target.getAttribute("resizable") === "false") return;
|
|
678
|
+
const t = e.target.getAttribute("sash-id");
|
|
679
|
+
this.activeMuntinSash = this.rootSash.getById(t), this.activeMuntinSash && (this.isResizeStarted = !0, this.lastX = e.pageX, this.lastY = e.pageY, this.applyResizeStyles());
|
|
680
|
+
}), document.addEventListener("mousemove", (e) => {
|
|
681
|
+
if (!this.isResizeStarted || !this.activeMuntinSash) return;
|
|
682
|
+
const [t, i, n, o] = this.activeMuntinSash.getChildren(), s = this.activeMuntinSash.isLeftRightSplit(), r = this.activeMuntinSash.isTopBottomSplit();
|
|
683
|
+
if (s && o && i) {
|
|
684
|
+
const l = e.pageX - this.lastX, d = o.width + l, c = i.width - l;
|
|
685
|
+
if (d <= o.calcMinWidth() || c <= i.calcMinWidth())
|
|
686
|
+
return;
|
|
687
|
+
o.width = d, i.width = c, i.left = i.left + l, this.update(), this.lastX = e.pageX;
|
|
688
|
+
} else if (r && t && n) {
|
|
689
|
+
const l = e.pageY - this.lastY, d = t.height + l, c = n.height - l;
|
|
690
|
+
if (d <= t.calcMinHeight() || c <= n.calcMinHeight())
|
|
691
|
+
return;
|
|
692
|
+
t.height = d, n.height = c, n.top = n.top + l, this.update(), this.lastY = e.pageY;
|
|
693
|
+
}
|
|
694
|
+
}), document.addEventListener("mouseup", () => {
|
|
695
|
+
this.isResizeStarted = !1, this.activeMuntinSash = null, this.revertResizeStyles();
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
}, ht = {
|
|
699
|
+
activeDropPaneEl: null,
|
|
700
|
+
// Intended to be overridden in `BinaryWindow` class
|
|
701
|
+
onPaneDrop(e, t) {
|
|
702
|
+
},
|
|
703
|
+
enableDrop() {
|
|
704
|
+
this.windowElement.addEventListener("dragover", (e) => {
|
|
705
|
+
e.preventDefault();
|
|
706
|
+
const t = e.target.matches("bw-pane") ? e.target : e.target.closest("bw-pane");
|
|
707
|
+
if (!t || (t !== this.activeDropPaneEl && (this.activeDropPaneEl && this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = t), t.getAttribute("can-drop") === "false")) return;
|
|
708
|
+
const i = k(t, e);
|
|
709
|
+
t.setAttribute("drop-area", i);
|
|
710
|
+
}), this.windowElement.addEventListener("dragleave", (e) => {
|
|
711
|
+
e.currentTarget.contains(e.relatedTarget) && e.currentTarget !== e.relatedTarget || this.activeDropPaneEl && (this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = null);
|
|
712
|
+
}), this.windowElement.addEventListener("drop", (e) => {
|
|
713
|
+
if (!this.activeDropPaneEl || this.activeDropPaneEl.getAttribute("can-drop") === "false") return;
|
|
714
|
+
const t = this.activeDropPaneEl.getAttribute("sash-id"), i = this.rootSash.getById(t);
|
|
715
|
+
this.onPaneDrop(e, i), typeof i.store.onDrop == "function" && i.store.onDrop(e, i), this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = null;
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
class L {
|
|
720
|
+
constructor(t) {
|
|
721
|
+
p(this, "windowElement", null);
|
|
722
|
+
p(this, "containerElement", null);
|
|
723
|
+
p(this, "debug", !1);
|
|
724
|
+
let i = null;
|
|
725
|
+
t instanceof j ? (i = t, this.rootSash = t) : (i = new q(t), this.rootSash = i.buildSashTree()), this.fitContainer = i.fitContainer;
|
|
726
|
+
}
|
|
727
|
+
mount(t) {
|
|
728
|
+
this.containerElement = t, this.create(), this.enableResize(), this.enableDrop(), this.fitContainer && this.enableFitContainer();
|
|
729
|
+
}
|
|
730
|
+
static assemble(...t) {
|
|
731
|
+
t.forEach((i) => {
|
|
732
|
+
O(this.prototype, i);
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
L.assemble(
|
|
737
|
+
it,
|
|
738
|
+
nt,
|
|
739
|
+
K,
|
|
740
|
+
ot,
|
|
741
|
+
ht,
|
|
742
|
+
st
|
|
743
|
+
);
|
|
744
|
+
function x(e) {
|
|
745
|
+
if (e.tagName === "BW-PANE")
|
|
746
|
+
return e.getAttribute("sash-id");
|
|
747
|
+
const t = e.closest("bw-pane");
|
|
748
|
+
if (!t)
|
|
749
|
+
throw new Error("[bwin] Pane element not found");
|
|
750
|
+
return t.getAttribute("sash-id");
|
|
751
|
+
}
|
|
752
|
+
const T = "bw-glass-action--close", rt = [
|
|
753
|
+
{
|
|
754
|
+
label: "",
|
|
755
|
+
className: T,
|
|
756
|
+
onClick: (e, t) => {
|
|
757
|
+
const i = x(e.target);
|
|
758
|
+
t.binaryWindow.removePane(i);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
], y = {
|
|
762
|
+
title: null,
|
|
763
|
+
content: null,
|
|
764
|
+
tabs: [],
|
|
765
|
+
actions: void 0,
|
|
766
|
+
draggable: !0
|
|
767
|
+
};
|
|
768
|
+
class z {
|
|
769
|
+
constructor({
|
|
770
|
+
title: t = y.title,
|
|
771
|
+
content: i = y.content,
|
|
772
|
+
tabs: n = y.tabs,
|
|
773
|
+
actions: o = y.actions,
|
|
774
|
+
draggable: s = y.draggable,
|
|
775
|
+
sash: r,
|
|
776
|
+
binaryWindow: l
|
|
777
|
+
}) {
|
|
778
|
+
p(this, "domNode");
|
|
779
|
+
this.title = t, this.content = i, this.tabs = n, this.actions = o, this.sash = r, this.draggable = s, this.binaryWindow = l, this.build();
|
|
780
|
+
}
|
|
781
|
+
build() {
|
|
782
|
+
const t = document.createElement("bw-glass-header");
|
|
783
|
+
if (Array.isArray(this.tabs) && this.tabs.length > 0)
|
|
784
|
+
t.append(this.createTabs());
|
|
785
|
+
else if (this.title) {
|
|
786
|
+
const o = document.createElement("bw-glass-title");
|
|
787
|
+
o.append(E(this.title)), t.append(o);
|
|
788
|
+
}
|
|
789
|
+
t.setAttribute("can-drag", this.draggable), t.append(this.createActions());
|
|
790
|
+
const i = document.createElement("bw-glass-content"), n = E(this.content);
|
|
791
|
+
n && i.append(n), this.domNode = document.createElement("bw-glass"), this.domNode.append(t, i);
|
|
792
|
+
}
|
|
793
|
+
createTabs() {
|
|
794
|
+
const t = document.createElement("bw-glass-tab-container");
|
|
795
|
+
for (const i of this.tabs) {
|
|
796
|
+
const n = (i == null ? void 0 : i.label) ?? i, o = E(`<button class="bw-glass-tab">${n}</button>`);
|
|
797
|
+
t.append(o);
|
|
798
|
+
}
|
|
799
|
+
return t;
|
|
800
|
+
}
|
|
801
|
+
createActions() {
|
|
802
|
+
const t = document.createElement("bw-glass-action-container"), i = this.actions === void 0 ? rt : Array.isArray(this.actions) ? this.actions : [];
|
|
803
|
+
for (const n of i) {
|
|
804
|
+
const o = (n == null ? void 0 : n.label) ?? n, s = n.className ? `bw-glass-action ${n.className}` : "bw-glass-action", r = E(`<button class="${s}">${o}</button>`);
|
|
805
|
+
typeof n.onClick == "function" && r.addEventListener("click", (l) => {
|
|
806
|
+
n.onClick(l, this);
|
|
807
|
+
}), t.append(r);
|
|
808
|
+
}
|
|
809
|
+
return t;
|
|
810
|
+
}
|
|
811
|
+
get contentElement() {
|
|
812
|
+
return this.domNode.querySelector("bw-glass-content");
|
|
813
|
+
}
|
|
814
|
+
get headerElement() {
|
|
815
|
+
return this.domNode.querySelector("bw-glass-header");
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
const lt = {
|
|
819
|
+
enableObservers() {
|
|
820
|
+
this.observeCloseButtons();
|
|
821
|
+
},
|
|
822
|
+
observeCloseButtons() {
|
|
823
|
+
const e = `.${T}`;
|
|
824
|
+
new MutationObserver((i) => {
|
|
825
|
+
i.forEach((n) => {
|
|
826
|
+
if (n.type === "childList")
|
|
827
|
+
if (this.windowElement.querySelectorAll("bw-pane").length === 1) {
|
|
828
|
+
const s = this.windowElement.querySelector(e);
|
|
829
|
+
s && s.setAttribute("disabled", "");
|
|
830
|
+
} else
|
|
831
|
+
this.windowElement.querySelectorAll(e).forEach((s) => {
|
|
832
|
+
s.removeAttribute("disabled");
|
|
833
|
+
});
|
|
834
|
+
});
|
|
835
|
+
}).observe(this.windowElement, {
|
|
836
|
+
childList: !0
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
}, dt = {
|
|
840
|
+
activeDragGlassEl: null,
|
|
841
|
+
// Stores original `can-drop` attribute value of pane element
|
|
842
|
+
activeDragGlassPaneCanDrop: !1,
|
|
843
|
+
onPaneDrop(e, t) {
|
|
844
|
+
if (!this.activeDragGlassEl) return;
|
|
845
|
+
const i = this.activeDropPaneEl.getAttribute("drop-area");
|
|
846
|
+
if (i === "center") {
|
|
847
|
+
const n = this.activeDragGlassEl.closest("bw-pane"), o = this.activeDropPaneEl.getAttribute("can-drop") !== "false";
|
|
848
|
+
H(n, this.activeDropPaneEl), n.setAttribute("can-drop", o);
|
|
849
|
+
return;
|
|
850
|
+
} else {
|
|
851
|
+
const n = x(this.activeDragGlassEl);
|
|
852
|
+
this.addPane(t.id, i).domNode.append(this.activeDragGlassEl), this.removePane(n);
|
|
853
|
+
}
|
|
854
|
+
},
|
|
855
|
+
enableDrag() {
|
|
856
|
+
document.addEventListener("mousedown", (e) => {
|
|
857
|
+
if (!e.target.matches("bw-glass-header") || e.target.getAttribute("can-drag") === "false") return;
|
|
858
|
+
const i = e.target.closest("bw-glass");
|
|
859
|
+
i.setAttribute("draggable", !0), this.activeDragGlassEl = i;
|
|
860
|
+
}), document.addEventListener("mouseup", () => {
|
|
861
|
+
this.activeDragGlassEl && (this.activeDragGlassEl.removeAttribute("draggable"), this.activeDragGlassEl = null);
|
|
862
|
+
}), document.addEventListener("dragstart", (e) => {
|
|
863
|
+
if (!e.target.matches("bw-glass") || !this.activeDragGlassEl) return;
|
|
864
|
+
e.dataTransfer.effectAllowed = "move";
|
|
865
|
+
const t = this.activeDragGlassEl.closest("bw-pane");
|
|
866
|
+
this.activeDragGlassPaneCanDrop = t.getAttribute("can-drop") !== "false", t.setAttribute("can-drop", !1);
|
|
867
|
+
}), document.addEventListener("dragend", () => {
|
|
868
|
+
this.activeDragGlassEl && (this.activeDragGlassEl.removeAttribute("draggable"), this.activeDragGlassEl.closest("bw-pane").setAttribute("can-drop", this.activeDragGlassPaneCanDrop), this.activeDragGlassEl = null);
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
class at extends L {
|
|
873
|
+
mount(t) {
|
|
874
|
+
super.mount(t), this.enableObservers(), this.enableDrag();
|
|
875
|
+
}
|
|
876
|
+
onPaneCreate(t, i) {
|
|
877
|
+
const n = new z({ ...i.store, sash: i, binaryWindow: this });
|
|
878
|
+
t.innerHTML = "", t.append(n.domNode), this.debug && n.contentElement.prepend(`${i.id}`);
|
|
879
|
+
}
|
|
880
|
+
onPaneUpdate() {
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* Add glass into the target pane.
|
|
884
|
+
*
|
|
885
|
+
* @param {string} paneSashId - The Sash ID of the pane that the glass moves into
|
|
886
|
+
* @param {'top'|'right'|'bottom'|'left'} position - The position of the glass relative to the target pane
|
|
887
|
+
* @param {Object} glassProps - The glass properties
|
|
888
|
+
*
|
|
889
|
+
*/
|
|
890
|
+
addGlass(t, i, n) {
|
|
891
|
+
const o = this.addPane(t, i), s = new z({ ...n, sash: o, binaryWindow: this });
|
|
892
|
+
o.domNode.append(s.domNode);
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* Remove glass from or together with the pane
|
|
896
|
+
*
|
|
897
|
+
* @param {string} paneSashId - The Sash ID of the pane that contains the glass
|
|
898
|
+
* @param {boolean} removePane - Whether to remove the pane together
|
|
899
|
+
*/
|
|
900
|
+
removeGlass(t, i) {
|
|
901
|
+
if (i)
|
|
902
|
+
this.removePane(t);
|
|
903
|
+
else {
|
|
904
|
+
const n = this.rootSash.getById(t);
|
|
905
|
+
if (!n) throw new Error("[bwin] Pane not found when removing glass");
|
|
906
|
+
const o = n.domNode.querySelector("bw-glass");
|
|
907
|
+
o && o.remove();
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
trimMuntin(t) {
|
|
911
|
+
t.hasAttribute("vertical") ? (t.style.top = `${parseFloat(t.style.top) + this.muntinSize / 2}px`, t.style.height = `${parseFloat(t.style.height) - this.muntinSize}px`) : t.hasAttribute("horizontal") && (t.style.left = `${parseFloat(t.style.left) + this.muntinSize / 2}px`, t.style.width = `${parseFloat(t.style.width) - this.muntinSize}px`);
|
|
912
|
+
}
|
|
913
|
+
onMuntinCreate(t) {
|
|
914
|
+
this.trimMuntin(t);
|
|
915
|
+
}
|
|
916
|
+
onMuntinUpdate(t) {
|
|
917
|
+
this.trimMuntin(t);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
at.assemble(lt, dt);
|
|
921
|
+
export {
|
|
922
|
+
rt as BUILTIN_ACTIONS,
|
|
923
|
+
at as BinaryWindow,
|
|
924
|
+
q as ConfigRoot,
|
|
925
|
+
L as Frame,
|
|
926
|
+
h as Position,
|
|
927
|
+
g as Sash,
|
|
928
|
+
j as SashConfig
|
|
929
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bwin",
|
|
3
|
+
"description": "A tiling window manager for web browsers",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/bhjsdev/bwin.git"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"ui",
|
|
12
|
+
"drag",
|
|
13
|
+
"drop",
|
|
14
|
+
"resize",
|
|
15
|
+
"window-manager",
|
|
16
|
+
"tiling-window-manager"
|
|
17
|
+
],
|
|
18
|
+
"author": "Bhjs Dev <bhjsdev@gmail.com>",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"bugs": "https://github.com/bhjsdev/bwin/issues",
|
|
21
|
+
"homepage": "https://github.com/bhjsdev/bwin#readme",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"main": "./dist/bwin.js",
|
|
26
|
+
"module": "./dist/bwin.js",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./dist/bwin.js"
|
|
30
|
+
},
|
|
31
|
+
"./bwin.css": "./dist/bwin.css"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"dev": "vite",
|
|
35
|
+
"build": "vite build",
|
|
36
|
+
"preview": "vite preview",
|
|
37
|
+
"test": "vitest"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"jsdom": "^25.0.1",
|
|
41
|
+
"prettier": "^3.3.3",
|
|
42
|
+
"prettier-plugin-brace-style": "^0.7.0",
|
|
43
|
+
"vite": "^5.4.11",
|
|
44
|
+
"vitest": "^2.1.4"
|
|
45
|
+
}
|
|
46
|
+
}
|