bwin 0.2.6 → 0.2.8

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.
Files changed (2) hide show
  1. package/dist/bwin.js +80 -65
  2. package/package.json +1 -1
package/dist/bwin.js CHANGED
@@ -21,13 +21,13 @@ function C(i = 2, t = 3) {
21
21
  }
22
22
  return s;
23
23
  }
24
- function R(i, t) {
24
+ function S(i, t) {
25
25
  for (; t.firstChild; )
26
26
  i.append(t.firstChild);
27
27
  }
28
28
  function W(i, t) {
29
29
  const e = document.createElement("div");
30
- R(e, i), R(i, t), R(t, e);
30
+ S(e, i), S(i, t), S(t, e);
31
31
  }
32
32
  function b(i) {
33
33
  if (typeof i == "number" && !isNaN(i))
@@ -117,21 +117,23 @@ function k({ width: i, height: t, x: e }) {
117
117
  function U({ width: i, height: t, y: e }) {
118
118
  return i - i / t * e;
119
119
  }
120
- function Y(i, { clientX: t, clientY: e }) {
120
+ function q(i, { clientX: t, clientY: e }) {
121
121
  const n = i.getBoundingClientRect(), { width: s, height: o } = n, h = t - n.left, l = e - n.top;
122
122
  if (h < 0 || h > s || l < 0 || l > o)
123
123
  return r.Outside;
124
- const d = 0.3, a = F({ width: s, height: o, x: h }), c = k({ width: s, height: o, x: h }), p = _({ width: s, height: o, y: l }), u = U({ width: s, height: o, y: l });
125
- return h < s * (0.5 - d / 2) && l > a && l < c ? r.Left : h > s * (0.5 + d / 2) && l < a && l > c ? r.Right : l < o * (0.5 - d / 2) && h > p && h < u ? r.Top : l > o * (0.5 + d / 2) && h < p && h > u ? r.Bottom : h > s * (0.5 - d / 2) && h < s * (0.5 + d / 2) && l > o * (0.5 - d / 2) && l < o * (0.5 + d / 2) ? r.Center : r.Unknown;
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
126
  }
127
- const q = 100, X = 100, w = {
127
+ const Y = 100, X = 100, w = {
128
128
  left: 0,
129
129
  top: 0,
130
130
  width: 150,
131
131
  height: 150,
132
132
  // Initial min values, real min width/height is calculated based on children
133
- minWidth: q,
134
- minHeight: X
133
+ minWidth: Y,
134
+ minHeight: X,
135
+ // `classic` | `natural`, `natural` means only one child is updating its size
136
+ resizeStrategy: "classic"
135
137
  };
136
138
  class g {
137
139
  constructor({
@@ -141,14 +143,16 @@ class g {
141
143
  height: s = w.height,
142
144
  minWidth: o = w.minWidth,
143
145
  minHeight: h = w.minHeight,
144
- domNode: l = null,
145
- store: d = {},
146
- position: a,
147
- id: c
146
+ resizeStrategy: l = w.resizeStrategy,
147
+ parent: d = null,
148
+ domNode: c = null,
149
+ store: a = {},
150
+ position: p,
151
+ id: u
148
152
  } = w) {
149
- if (this.id = c ?? C(), !a)
153
+ if (this.id = u ?? C(), !p)
150
154
  throw new Error("[bwin] Sash position is required");
151
- this.position = a, this.domNode = l, this._top = e, this._left = t, this._width = n, this._height = s, this.children = [], this.minWidth = o, this.minHeight = h, this.store = d;
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;
152
156
  }
153
157
  walk(t) {
154
158
  this.children.forEach((e) => e.walk(t)), t(this);
@@ -289,10 +293,13 @@ class g {
289
293
  this._width = t;
290
294
  const [n, s, o, h] = this.getChildren();
291
295
  if (h && s) {
292
- const l = h.width + s.width, d = e * (h.width / l), a = l + e;
293
- let c = h.width + d, p = a - c, u = s.left + d;
294
- const E = h.calcMinWidth(), y = s.calcMinWidth();
295
- e < 0 && (c < E && p > y ? (c = h.width, p = a - c, u = h.left + c) : p < y && c > E && (p = s.width, c = a - p, u = h.left + c)), h.width = c, s.width = p, s.left = u;
296
+ 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;
296
303
  }
297
304
  n && o && (n.width += e, o.width += e);
298
305
  }
@@ -304,13 +311,13 @@ class g {
304
311
  this._height = t;
305
312
  const [n, s, o, h] = this.getChildren();
306
313
  if (n && o) {
307
- const l = n.height + o.height, d = e * (n.height / l), a = l + e;
308
- let c = n.height + d, p = a - c, u = o.top + d;
309
- if (e < 0) {
310
- const E = n.calcMinHeight(), y = o.calcMinHeight();
311
- c < E && p > y ? (c = n.height, p = a - c, u = n.top + c) : p < y && c > E && (p = o.height, c = a - p, u = n.top + c);
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);
312
319
  }
313
- n.height = c, o.height = p, o.top = u;
320
+ n.height = a, o.height = p, o.top = u;
314
321
  }
315
322
  h && s && (h.height += e, s.height += e);
316
323
  }
@@ -319,7 +326,7 @@ const v = {
319
326
  size: "50%",
320
327
  position: r.Left
321
328
  };
322
- class A {
329
+ class z {
323
330
  constructor({
324
331
  parentRect: t,
325
332
  children: e,
@@ -329,13 +336,14 @@ class A {
329
336
  minHeight: h,
330
337
  position: l,
331
338
  size: d,
339
+ resizeStrategy: c,
332
340
  ...a
333
341
  }) {
334
342
  f(this, "left");
335
343
  f(this, "top");
336
344
  f(this, "width");
337
345
  f(this, "height");
338
- this.parentRect = t, this.children = e, this.siblingConfigNode = n, this.id = s, this.minWidth = o, this.minHeight = h, this.position = this.getPosition(l), this.size = this.getSize(d), this.nonCoreData = a, this.setBounds();
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();
339
347
  }
340
348
  getPosition(t) {
341
349
  if (!this.siblingConfigNode)
@@ -387,7 +395,7 @@ class A {
387
395
  this.left = this.parentRect.left, this.top = this.parentRect.top + this.parentRect.height - t, this.width = this.parentRect.width, this.height = t;
388
396
  }
389
397
  }
390
- createSash() {
398
+ createSash({ resizeStrategy: t } = {}) {
391
399
  return new g({
392
400
  left: this.left,
393
401
  top: this.top,
@@ -397,6 +405,7 @@ class A {
397
405
  id: this.id,
398
406
  minWidth: this.minWidth,
399
407
  minHeight: this.minHeight,
408
+ resizeStrategy: t || this.resizeStrategy,
400
409
  store: this.nonCoreData
401
410
  });
402
411
  }
@@ -421,7 +430,7 @@ class A {
421
430
  }
422
431
  }
423
432
  createPrimaryConfigNode({ size: t, position: e, children: n, id: s, minWidth: o, minHeight: h, ...l }) {
424
- return new A({
433
+ return new z({
425
434
  parentRect: this,
426
435
  size: t ?? v.size,
427
436
  position: e ?? v.position,
@@ -433,7 +442,7 @@ class A {
433
442
  });
434
443
  }
435
444
  createSecondaryConfigNode({ size: t, position: e, children: n, id: s, minWidth: o, minHeight: h, ...l }, d) {
436
- return new A({
445
+ return new z({
437
446
  parentRect: this,
438
447
  size: t,
439
448
  position: e,
@@ -445,37 +454,41 @@ class A {
445
454
  ...l
446
455
  });
447
456
  }
448
- buildSashTree() {
449
- const t = this.createSash();
457
+ buildSashTree({ resizeStrategy: t } = {}) {
458
+ const e = this.createSash({ resizeStrategy: t });
450
459
  if (!Array.isArray(this.children) || this.children.length === 0)
451
- return t;
452
- const e = this.normConfig(this.children[0]), n = this.normConfig(this.children.at(1));
453
- let s, o;
454
- return !e.size && !e.position && n ? (n.position || (n.position = r.Right), s = this.createPrimaryConfigNode(n), o = this.createSecondaryConfigNode(
455
- e,
456
- s
457
- )) : (s = this.createPrimaryConfigNode(e), o = this.createSecondaryConfigNode(
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(
458
464
  n,
459
- s
460
- )), s && o && (t.children.push(s.buildSashTree()), t.children.push(o.buildSashTree())), t;
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;
461
474
  }
462
475
  }
463
- const S = {
476
+ const R = {
464
477
  width: 333,
465
478
  height: 333
466
479
  }, D = {
467
480
  fitContainer: !1
468
481
  };
469
- class j extends A {
482
+ class j extends z {
470
483
  constructor({
471
484
  id: t,
472
485
  children: e,
473
- width: n = S.width,
474
- height: s = S.height,
486
+ width: n = R.width,
487
+ height: s = R.height,
475
488
  fitContainer: o = D.fitContainer,
476
489
  ...h
477
490
  } = {
478
- ...S,
491
+ ...R,
479
492
  ...D
480
493
  }) {
481
494
  super({
@@ -599,7 +612,7 @@ function et(i, { position: t, size: e, id: n, minWidth: s, minHeight: o }) {
599
612
  if (t === r.Bottom)
600
613
  return it(i, { size: e, id: n });
601
614
  }
602
- function z(i) {
615
+ function A(i) {
603
616
  if (i.tagName === "BW-PANE")
604
617
  return i.getAttribute("sash-id");
605
618
  const t = i.closest("bw-pane");
@@ -649,7 +662,7 @@ const nt = {
649
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();
650
663
  },
651
664
  swapPanes(i, t) {
652
- const e = z(i), n = z(t), s = i.getAttribute("can-drop") !== "false", o = t.getAttribute("can-drop") !== "false";
665
+ const e = A(i), n = A(t), s = i.getAttribute("can-drop") !== "false", o = t.getAttribute("can-drop") !== "false";
653
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);
654
667
  }
655
668
  };
@@ -708,8 +721,10 @@ const st = {
708
721
  },
709
722
  enableFitContainer() {
710
723
  new ResizeObserver((t) => {
711
- for (const e of t)
712
- e.target === this.containerElement && this.fitContainer && this.fit();
724
+ requestAnimationFrame(() => {
725
+ for (const e of t)
726
+ e.target === this.containerElement && this.fitContainer && this.fit();
727
+ });
713
728
  }).observe(this.containerElement);
714
729
  }
715
730
  }, rt = {
@@ -733,13 +748,13 @@ const st = {
733
748
  if (!this.isResizeStarted || !this.activeMuntinSash) return;
734
749
  const [t, e, n, s] = this.activeMuntinSash.getChildren(), o = this.activeMuntinSash.isLeftRightSplit(), h = this.activeMuntinSash.isTopBottomSplit();
735
750
  if (o && s && e) {
736
- const l = i.pageX - this.lastX, d = s.width + l, a = e.width - l;
737
- if (l > 0 && a <= e.calcMinWidth() || l < 0 && d <= s.calcMinWidth()) return;
738
- s.width = d, e.width = a, e.left = e.left + l, this.update(), this.lastX = i.pageX;
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;
739
754
  } else if (h && t && n) {
740
- const l = i.pageY - this.lastY, d = t.height + l, a = n.height - l;
741
- if (l > 0 && a <= n.calcMinHeight() || l < 0 && d <= t.calcMinHeight()) return;
742
- t.height = d, n.height = a, n.top = n.top + l, this.update(), this.lastY = i.pageY;
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;
743
758
  }
744
759
  }), document.addEventListener("mouseup", () => {
745
760
  this.isResizeStarted = !1, this.activeMuntinSash = null, this.revertResizeStyles();
@@ -755,7 +770,7 @@ const st = {
755
770
  i.preventDefault();
756
771
  const t = i.target.matches("bw-pane") ? i.target : i.target.closest("bw-pane");
757
772
  if (!t || (t !== this.activeDropPaneEl && (this.activeDropPaneEl && this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = t), t.getAttribute("can-drop") === "false")) return;
758
- const e = Y(t, i);
773
+ const e = q(t, i);
759
774
  t.setAttribute("drop-area", e);
760
775
  }), this.windowElement.addEventListener("dragleave", (i) => {
761
776
  i.currentTarget.contains(i.relatedTarget) && i.currentTarget !== i.relatedTarget || this.activeDropPaneEl && (this.activeDropPaneEl.removeAttribute("drop-area"), this.activeDropPaneEl = null);
@@ -772,7 +787,7 @@ class B {
772
787
  f(this, "containerElement", null);
773
788
  f(this, "debug", dt);
774
789
  let e = null;
775
- t instanceof K ? (e = t, this.rootSash = t) : (e = new j(t), this.rootSash = e.buildSashTree()), this.fitContainer = e.fitContainer;
790
+ t instanceof K ? (e = t, this.rootSash = t) : (e = new j(t), this.rootSash = e.buildSashTree({ resizeStrategy: e.resizeStrategy })), this.fitContainer = e.fitContainer;
776
791
  }
777
792
  frame(t) {
778
793
  this.containerElement = t, this.windowElement = this.createWindow(), this.glaze(), this.containerElement.append(this.windowElement);
@@ -802,7 +817,7 @@ const at = {
802
817
  label: "",
803
818
  className: "bw-glass-action--close",
804
819
  onClick: (i, t) => {
805
- const e = z(i.target);
820
+ const e = A(i.target);
806
821
  t.removePane(e);
807
822
  }
808
823
  }, ct = {
@@ -828,12 +843,12 @@ function ut(i, t) {
828
843
  const e = i.left + i.width, n = i.top + i.height, s = t.left + t.width, o = t.top + t.height;
829
844
  if (i.left >= s || t.left >= e || i.top >= o || t.top >= n)
830
845
  return null;
831
- const h = Math.max(i.left, t.left), l = Math.max(i.top, t.top), d = Math.min(e, s), a = Math.min(n, o);
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);
832
847
  return {
833
848
  left: h,
834
849
  top: l,
835
850
  width: d - h,
836
- height: a - l
851
+ height: c - l
837
852
  };
838
853
  }
839
854
  const ft = [ct, pt, at], gt = {
@@ -858,9 +873,9 @@ const ft = [ct, pt, at], gt = {
858
873
  d = o.height - t.height < l.minHeight ? o.height / 2 : t.height;
859
874
  else
860
875
  throw new Error("[bwin] Invalid position when restoring glass");
861
- const a = i.bwOriginalSashId;
876
+ const c = i.bwOriginalSashId;
862
877
  this.addPane(n.getAttribute("sash-id"), {
863
- id: a,
878
+ id: c,
864
879
  position: s,
865
880
  size: d
866
881
  }).domNode.append(i.bwGlassElement);
@@ -966,7 +981,7 @@ const wt = {
966
981
  this.swapPanes(n, this.activeDropPaneEl);
967
982
  return;
968
983
  } else {
969
- const n = z(this.activeDragGlassEl);
984
+ const n = A(this.activeDragGlassEl);
970
985
  this.removePane(n), this.addPane(t.id, { position: e, id: n }).domNode.append(this.activeDragGlassEl);
971
986
  }
972
987
  },
@@ -1029,8 +1044,8 @@ class bt extends B {
1029
1044
  * @returns {Sash} - The newly created Sash
1030
1045
  */
1031
1046
  addPane(e, n) {
1032
- const { position: s, size: o, id: h, ...l } = n, d = super.addPane(e, { position: s, size: o, id: h }), a = new T({ ...l, sash: d, binaryWindow: this });
1033
- return d.domNode.append(a.domNode), d;
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;
1034
1049
  }
1035
1050
  removePane(e) {
1036
1051
  if (this.windowElement.querySelector(`[sash-id="${e}"]`)) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "bwin",
3
3
  "description": "A tiling window manager for web browsers",
4
4
  "type": "module",
5
- "version": "0.2.6",
5
+ "version": "0.2.8",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/bhjsdev/bwin.git"