@netless/window-manager 1.0.0-canary.26 → 1.0.0-canary.27

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 (73) hide show
  1. package/dist/App/WhiteboardView.d.ts +3 -1
  2. package/dist/BoxManager.d.ts +2 -4
  3. package/dist/BuiltinApps.d.ts +3 -0
  4. package/dist/Helper.d.ts +1 -1
  5. package/dist/callback.d.ts +5 -0
  6. package/dist/index.cjs.js +82 -12
  7. package/dist/index.d.ts +5 -1
  8. package/dist/index.es.js +1531 -657
  9. package/dist/index.umd.js +82 -12
  10. package/dist/src/App/AppContext.d.ts +78 -0
  11. package/dist/src/App/AppPageStateImpl.d.ts +21 -0
  12. package/dist/src/App/AppProxy.d.ts +98 -0
  13. package/dist/src/App/MagixEvent/index.d.ts +29 -0
  14. package/dist/src/App/Storage/StorageEvent.d.ts +8 -0
  15. package/dist/src/App/Storage/index.d.ts +39 -0
  16. package/dist/src/App/Storage/typings.d.ts +22 -0
  17. package/dist/src/App/Storage/utils.d.ts +5 -0
  18. package/dist/src/App/WhiteboardView.d.ts +27 -0
  19. package/dist/src/App/index.d.ts +4 -0
  20. package/dist/src/App/type.d.ts +21 -0
  21. package/dist/src/AppListener.d.ts +19 -0
  22. package/dist/src/AppManager.d.ts +107 -0
  23. package/dist/src/AttributesDelegate.d.ts +83 -0
  24. package/dist/src/BoxEmitter.d.ts +34 -0
  25. package/dist/src/BoxManager.d.ts +102 -0
  26. package/dist/src/BuiltinApps.d.ts +8 -0
  27. package/dist/src/Cursor/Cursor.d.ts +39 -0
  28. package/dist/src/Cursor/icons.d.ts +3 -0
  29. package/dist/src/Cursor/index.d.ts +46 -0
  30. package/dist/src/Helper.d.ts +19 -0
  31. package/dist/src/InternalEmitter.d.ts +38 -0
  32. package/dist/src/Page/PageController.d.ts +21 -0
  33. package/dist/src/Page/index.d.ts +3 -0
  34. package/dist/src/PageState.d.ts +9 -0
  35. package/dist/src/ReconnectRefresher.d.ts +24 -0
  36. package/dist/src/RedoUndo.d.ts +18 -0
  37. package/dist/src/Register/index.d.ts +28 -0
  38. package/dist/src/Register/loader.d.ts +4 -0
  39. package/dist/src/Register/storage.d.ts +8 -0
  40. package/dist/src/Utils/AppCreateQueue.d.ts +15 -0
  41. package/dist/src/Utils/Common.d.ts +23 -0
  42. package/dist/src/Utils/Reactive.d.ts +6 -0
  43. package/dist/src/Utils/RoomHacker.d.ts +3 -0
  44. package/dist/src/Utils/error.d.ts +27 -0
  45. package/dist/src/Utils/log.d.ts +1 -0
  46. package/dist/src/View/CameraSynchronizer.d.ts +17 -0
  47. package/dist/src/View/MainView.d.ts +59 -0
  48. package/dist/src/View/ViewManager.d.ts +13 -0
  49. package/dist/src/View/ViewSync.d.ts +24 -0
  50. package/dist/src/callback.d.ts +29 -0
  51. package/dist/src/constants.d.ts +51 -0
  52. package/dist/src/image.d.ts +19 -0
  53. package/dist/src/index.d.ts +267 -0
  54. package/dist/src/shim.d.ts +11 -0
  55. package/dist/src/typings.d.ts +88 -0
  56. package/dist/style.css +1 -1
  57. package/dist/typings.d.ts +6 -0
  58. package/docs/app-context.md +2 -2
  59. package/package.json +9 -4
  60. package/playwright.config.ts +28 -0
  61. package/pnpm-lock.yaml +514 -21
  62. package/src/App/AppContext.ts +2 -2
  63. package/src/App/AppProxy.ts +13 -7
  64. package/src/App/WhiteboardView.ts +19 -14
  65. package/src/BoxManager.ts +32 -36
  66. package/src/BuiltinApps.ts +5 -0
  67. package/src/Helper.ts +3 -2
  68. package/src/View/CameraSynchronizer.ts +3 -7
  69. package/src/callback.ts +1 -0
  70. package/src/index.ts +18 -5
  71. package/src/style.css +3 -41
  72. package/src/typings.ts +6 -0
  73. package/vite.config.js +5 -3
package/dist/index.es.js CHANGED
@@ -24,7 +24,7 @@ import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reactio
24
24
  import { v4 } from "uuid";
25
25
  import { genUID, SideEffectManager } from "side-effect-manager";
26
26
  import { Val, combine, ValManager, withReadonlyValueEnhancer, withValueEnhancer, derive } from "value-enhancer";
27
- import { ResizeObserver as ResizeObserver$2 } from "@juggle/resize-observer";
27
+ import { ResizeObserver as ResizeObserver$3 } from "@juggle/resize-observer";
28
28
  import p$1 from "video.js";
29
29
  var Events = /* @__PURE__ */ ((Events2) => {
30
30
  Events2["AppMove"] = "AppMove";
@@ -931,17 +931,25 @@ class WhiteBoardView {
931
931
  return this.appProxy.removeSceneByIndex(needRemoveIndex);
932
932
  };
933
933
  const pageState$ = new Val(appProxy.pageState);
934
+ const baseRect$ = new Val(appProxy.size$.value);
935
+ const pickCamera = (camera) => pick(camera, ["centerX", "centerY", "scale"]);
936
+ const camera$ = new Val(pickCamera(this.view.camera));
937
+ this.baseRect$ = baseRect$;
934
938
  this.pageState$ = pageState$;
935
- this.appProxy.sideEffectManager.add(() => appProxy.appEmitter.on("pageStateChange", (pageState) => {
936
- pageState$.setValue(pageState);
937
- }));
938
- const camera$ = new Val(pick(this.view.camera, ["centerX", "centerY", "scale"]));
939
939
  this.baseCamera$ = camera$;
940
- this.appProxy.sideEffectManager.add(() => appProxy.camera$.subscribe((camera) => {
941
- if (camera) {
942
- camera$.setValue(pick(camera, ["centerX", "centerY", "scale"]));
943
- }
944
- }));
940
+ this.appProxy.sideEffectManager.add(() => [
941
+ appProxy.appEmitter.on("pageStateChange", (pageState) => pageState$.setValue(pageState)),
942
+ appProxy.camera$.subscribe((camera) => {
943
+ if (camera) {
944
+ camera$.setValue(pickCamera(camera));
945
+ }
946
+ }),
947
+ appProxy.size$.subscribe((size2) => {
948
+ if (size2) {
949
+ baseRect$.setValue(pick(size2, ["width", "height"]));
950
+ }
951
+ })
952
+ ]);
945
953
  view.disableCameraTransform = true;
946
954
  }
947
955
  get pageState() {
@@ -959,12 +967,12 @@ const log = (...args) => {
959
967
  console.log(`[WindowManager]:`, ...args);
960
968
  }
961
969
  };
962
- const setupWrapper = (root) => {
970
+ const setupWrapper = (root, target) => {
963
971
  const playground = document.createElement("div");
964
972
  playground.className = "netless-window-manager-playground";
965
973
  const mainViewElement = document.createElement("div");
966
974
  mainViewElement.className = "netless-window-manager-main-view";
967
- playground.appendChild(mainViewElement);
975
+ target.appendChild(mainViewElement);
968
976
  root.appendChild(playground);
969
977
  return { playground, mainViewElement };
970
978
  };
@@ -1033,7 +1041,6 @@ class AppContext {
1033
1041
  }
1034
1042
  };
1035
1043
  this.createWhiteBoardView = (params) => {
1036
- var _a;
1037
1044
  if (this.whiteBoardView) {
1038
1045
  return this.whiteBoardView;
1039
1046
  }
@@ -1049,7 +1056,7 @@ class AppContext {
1049
1056
  const viewWrapper = document.createElement("div");
1050
1057
  this._viewWrapper = viewWrapper;
1051
1058
  viewWrapper.className = "window-manager-view-wrapper";
1052
- (_a = this.box.$content.parentElement) == null ? void 0 : _a.appendChild(viewWrapper);
1059
+ this.box.$main.appendChild(viewWrapper);
1053
1060
  view.divElement = viewWrapper;
1054
1061
  this.appProxy.fireMemberStateChange();
1055
1062
  if (this.isAddApp) {
@@ -1057,7 +1064,7 @@ class AppContext {
1057
1064
  }
1058
1065
  this.whiteBoardView = new WhiteBoardView(view, this, this.appProxy, this.ensurePageSize);
1059
1066
  this.appProxy.sideEffectManager.add(() => [
1060
- this.box._contentStageRect$.subscribe((rect) => {
1067
+ this.box._stageRect$.subscribe((rect) => {
1061
1068
  viewWrapper.style.left = `${rect.x}px`;
1062
1069
  viewWrapper.style.top = `${rect.y}px`;
1063
1070
  viewWrapper.style.width = `${rect.width}px`;
@@ -1238,13 +1245,9 @@ class CameraSynchronizer {
1238
1245
  this.remoteCamera = camera;
1239
1246
  this.remoteSize = size2;
1240
1247
  if (this.remoteSize && this.rect) {
1241
- let scale2;
1242
- if (size2.width < size2.height) {
1243
- scale2 = this.rect.width / size2.width;
1244
- } else {
1245
- scale2 = this.rect.height / size2.height;
1246
- }
1247
- const nextScale = camera.scale * scale2;
1248
+ const wScale = this.rect.width / size2.width;
1249
+ const hScale = this.rect.height / size2.height;
1250
+ const nextScale = camera.scale * Math.min(wScale, hScale);
1248
1251
  const config = {
1249
1252
  scale: nextScale,
1250
1253
  animationMode: AnimationMode.Continuous
@@ -1768,10 +1771,10 @@ class AppProxy {
1768
1771
  });
1769
1772
  this.camera$.setValue(toJS(this.appAttributes.camera));
1770
1773
  }
1771
- if (!this.size$.value && box.contentStageRect) {
1772
- const initialRect = this.computedInitialRect(box.contentStageRect);
1773
- const width = (initialRect == null ? void 0 : initialRect.width) || box.contentStageRect.width;
1774
- const height = (initialRect == null ? void 0 : initialRect.height) || box.contentStageRect.height;
1774
+ if (!this.size$.value && box.stageRect) {
1775
+ const initialRect = this.computedInitialRect(box.stageRect);
1776
+ const width = (initialRect == null ? void 0 : initialRect.width) || box.stageRect.width;
1777
+ const height = (initialRect == null ? void 0 : initialRect.height) || box.stageRect.height;
1775
1778
  this.storeSize({
1776
1779
  id: this.uid,
1777
1780
  width,
@@ -1784,7 +1787,7 @@ class AppProxy {
1784
1787
  view$: this.view$,
1785
1788
  camera$: this.camera$,
1786
1789
  size$: this.size$,
1787
- stageRect$: box._contentStageRect$,
1790
+ stageRect$: box._stageRect$,
1788
1791
  storeCamera: this.storeCamera,
1789
1792
  storeSize: this.storeSize
1790
1793
  });
@@ -1912,6 +1915,10 @@ class AppProxy {
1912
1915
  canOperate: this.manager.canOperate,
1913
1916
  smartPosition: this.isAddApp
1914
1917
  });
1918
+ const registerParams = appRegister.registered.get(this.kind);
1919
+ if (registerParams == null ? void 0 : registerParams.contentStyles) {
1920
+ box == null ? void 0 : box.mountUserStyles(registerParams.contentStyles);
1921
+ }
1915
1922
  this.box$.setValue(box);
1916
1923
  if (this.isAddApp && this.box) {
1917
1924
  this.store.updateAppState(appId, AppAttributes.ZIndex, this.box.zIndex);
@@ -2094,6 +2101,7 @@ class AppProxy {
2094
2101
  this.status = "destroyed";
2095
2102
  try {
2096
2103
  await appRegister.notifyApp(this.kind, "destroy", { appId: this.id });
2104
+ callbacks$1.emit("appClose", { appId: this.id, kind: this.kind, error });
2097
2105
  await this.appEmitter.emit("destroy", { error });
2098
2106
  } catch (error2) {
2099
2107
  console.error("[WindowManager]: notifyApp error", error2.message, error2.stack);
@@ -2699,7 +2707,7 @@ class AppManager {
2699
2707
  }
2700
2708
  };
2701
2709
  this.closeAll = async () => {
2702
- for (const [_2, appProxy] of this.appProxies.entries()) {
2710
+ for (const [_, appProxy] of this.appProxies.entries()) {
2703
2711
  await appProxy.destroy(true, false, true);
2704
2712
  }
2705
2713
  };
@@ -3312,7 +3320,7 @@ var startLoop = function() {
3312
3320
  if (!isProcessing)
3313
3321
  onNextFrame(processFrame);
3314
3322
  };
3315
- var clamp$1 = function(min, max) {
3323
+ var clamp$2 = function(min, max) {
3316
3324
  return function(v2) {
3317
3325
  return Math.max(Math.min(v2, max), min);
3318
3326
  };
@@ -3330,7 +3338,7 @@ var number = {
3330
3338
  return v2;
3331
3339
  }
3332
3340
  };
3333
- var alpha = __assign(__assign({}, number), { transform: clamp$1(0, 1) });
3341
+ var alpha = __assign(__assign({}, number), { transform: clamp$2(0, 1) });
3334
3342
  var scale = __assign(__assign({}, number), { default: 1 });
3335
3343
  var createUnitType = function(unit) {
3336
3344
  return {
@@ -3354,7 +3362,7 @@ var progressPercentage = __assign(__assign({}, percent), { parse: function(v2) {
3354
3362
  var getValueFromFunctionString = function(value) {
3355
3363
  return value.substring(value.indexOf("(") + 1, value.lastIndexOf(")"));
3356
3364
  };
3357
- var clampRgbUnit = clamp$1(0, 255);
3365
+ var clampRgbUnit = clamp$2(0, 255);
3358
3366
  var isRgba = function(v2) {
3359
3367
  return v2.red !== void 0;
3360
3368
  };
@@ -3993,190 +4001,422 @@ var shallowequal = function shallowEqual(objA, objB, compare, compareContext) {
3993
4001
  }
3994
4002
  return true;
3995
4003
  };
3996
- var e$2 = Object.defineProperty, t$3 = Object.defineProperties, i$1 = Object.getOwnPropertyDescriptors, s$2 = Object.getOwnPropertySymbols, a$1 = Object.prototype.hasOwnProperty, n$3 = Object.prototype.propertyIsEnumerable, o$2 = (t2, i2, s2) => i2 in t2 ? e$2(t2, i2, { enumerable: true, configurable: true, writable: true, value: s2 }) : t2[i2] = s2, r$4 = (e2, t2) => {
3997
- for (var i2 in t2 || (t2 = {}))
3998
- a$1.call(t2, i2) && o$2(e2, i2, t2[i2]);
3999
- if (s$2)
4000
- for (var i2 of s$2(t2))
4001
- n$3.call(t2, i2) && o$2(e2, i2, t2[i2]);
4002
- return e2;
4003
- };
4004
- var v$3, w$2, C$3, y$2, E$3, z$2, _, B$2, N$3, S$3;
4005
- (w$2 = v$3 || (v$3 = {})).Light = "light", w$2.Dark = "dark", w$2.Auto = "auto", (y$2 = C$3 || (C$3 = {})).Normal = "normal", y$2.Minimized = "minimized", y$2.Maximized = "maximized", (z$2 = E$3 || (E$3 = {})).DarkMode = "dark_mode", z$2.PrefersColorScheme = "prefers_color_scheme", z$2.Close = "close", z$2.Focus = "focus", z$2.Blur = "blur", z$2.IntrinsicMove = "intrinsic_move", z$2.IntrinsicResize = "intrinsic_resize", z$2.ZIndex = "z_index", z$2.State = "state", z$2.Minimized = "minimized", z$2.Maximized = "maximized", z$2.Readonly = "readonly", z$2.Destroyed = "destroyed", (B$2 = _ || (_ = {})).Close = "close", B$2.Maximize = "maximize", B$2.Minimize = "minimize", (S$3 = N$3 || (N$3 = {})).North = "n", S$3.South = "s", S$3.West = "w", S$3.East = "e", S$3.NorthWest = "nw", S$3.NorthEast = "ne", S$3.SouthEast = "se", S$3.SouthWest = "sw";
4006
- function I$3(e2, t2, i2) {
4007
- return Math.min(Math.max(e2, t2), i2);
4008
- }
4009
- function k$1(e2) {
4010
- e2.stopPropagation(), e2.cancelable && e2.preventDefault();
4011
- }
4012
- function R$3(e2) {
4013
- return e2.touches ? e2.touches[0] : e2;
4014
- }
4015
- let D$2 = 1;
4016
- function L$3() {
4017
- return "New Box " + D$2++;
4004
+ var shadowStyles = /* @__PURE__ */ (() => '.telebox-quarantine {\n all: initial;\n position: relative;\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n}\n\n.telebox-body-wrap {\n color: #191919;\n color: var(--tele-box-color, #191919);\n flex: 1;\n width: 100%;\n overflow: hidden;\n display: flex;\n justify-content: center;\n align-items: center;\n position: relative;\n}\n\n.telebox-content {\n width: 100%;\n height: 100%;\n position: relative;\n background-color: #f9f9f9;\n background-color: var(--tele-manager-container-background, #f9f9f9);\n}\n\n.telebox-box-stage {\n position: absolute;\n z-index: 1;\n overflow: hidden;\n background-color: #fff;\n background-color: var(--tele-manager-stage-background, #fff);\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.08);\n box-shadow: var(--tele-manager-stage-shadow, 0px 0px 16px rgba(0, 0, 0, 0.08));\n}\n\n.telebox-footer-wrap {\n flex-shrink: 0;\n display: flex;\n flex-direction: column;\n}\n\n.telebox-footer-wrap::before {\n content: "";\n display: block;\n flex: 1;\n}\n\n.telebox-color-scheme-dark {\n color-scheme: dark;\n}\n\n.telebox-color-scheme-dark .telebox-body-wrap {\n color: #e9e9e9;\n color: var(--tele-box-color-dark, #e9e9e9);\n}\n\n.telebox-color-scheme-dark .telebox-content {\n background-color: #25282e;\n background-color: var(--tele-manager-container-background-dark, #25282e);\n}\n\n.telebox-color-scheme-dark .telebox-box-stage {\n background-color: #272a30;\n background-color: var(--tele-manager-stage-background-dark, #272a30);\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.24);\n box-shadow: var(--tele-manager-stage-shadow-dark, 0px 0px 16px rgba(0, 0, 0, 0.24));\n}')();
4005
+ var TELE_BOX_COLOR_SCHEME = /* @__PURE__ */ ((TELE_BOX_COLOR_SCHEME2) => {
4006
+ TELE_BOX_COLOR_SCHEME2["Light"] = "light";
4007
+ TELE_BOX_COLOR_SCHEME2["Dark"] = "dark";
4008
+ TELE_BOX_COLOR_SCHEME2["Auto"] = "auto";
4009
+ return TELE_BOX_COLOR_SCHEME2;
4010
+ })(TELE_BOX_COLOR_SCHEME || {});
4011
+ var TELE_BOX_STATE = /* @__PURE__ */ ((TELE_BOX_STATE2) => {
4012
+ TELE_BOX_STATE2["Normal"] = "normal";
4013
+ TELE_BOX_STATE2["Minimized"] = "minimized";
4014
+ TELE_BOX_STATE2["Maximized"] = "maximized";
4015
+ return TELE_BOX_STATE2;
4016
+ })(TELE_BOX_STATE || {});
4017
+ var TELE_BOX_EVENT = /* @__PURE__ */ ((TELE_BOX_EVENT2) => {
4018
+ TELE_BOX_EVENT2["DarkMode"] = "dark_mode";
4019
+ TELE_BOX_EVENT2["PrefersColorScheme"] = "prefers_color_scheme";
4020
+ TELE_BOX_EVENT2["Close"] = "close";
4021
+ TELE_BOX_EVENT2["Focus"] = "focus";
4022
+ TELE_BOX_EVENT2["Blur"] = "blur";
4023
+ TELE_BOX_EVENT2["IntrinsicMove"] = "intrinsic_move";
4024
+ TELE_BOX_EVENT2["IntrinsicResize"] = "intrinsic_resize";
4025
+ TELE_BOX_EVENT2["ZIndex"] = "z_index";
4026
+ TELE_BOX_EVENT2["State"] = "state";
4027
+ TELE_BOX_EVENT2["Minimized"] = "minimized";
4028
+ TELE_BOX_EVENT2["Maximized"] = "maximized";
4029
+ TELE_BOX_EVENT2["Readonly"] = "readonly";
4030
+ TELE_BOX_EVENT2["Destroyed"] = "destroyed";
4031
+ return TELE_BOX_EVENT2;
4032
+ })(TELE_BOX_EVENT || {});
4033
+ var TELE_BOX_DELEGATE_EVENT = /* @__PURE__ */ ((TELE_BOX_DELEGATE_EVENT2) => {
4034
+ TELE_BOX_DELEGATE_EVENT2["Close"] = "close";
4035
+ TELE_BOX_DELEGATE_EVENT2["Maximize"] = "maximize";
4036
+ TELE_BOX_DELEGATE_EVENT2["Minimize"] = "minimize";
4037
+ return TELE_BOX_DELEGATE_EVENT2;
4038
+ })(TELE_BOX_DELEGATE_EVENT || {});
4039
+ var TELE_BOX_RESIZE_HANDLE = /* @__PURE__ */ ((TELE_BOX_RESIZE_HANDLE2) => {
4040
+ TELE_BOX_RESIZE_HANDLE2["North"] = "n";
4041
+ TELE_BOX_RESIZE_HANDLE2["South"] = "s";
4042
+ TELE_BOX_RESIZE_HANDLE2["West"] = "w";
4043
+ TELE_BOX_RESIZE_HANDLE2["East"] = "e";
4044
+ TELE_BOX_RESIZE_HANDLE2["NorthWest"] = "nw";
4045
+ TELE_BOX_RESIZE_HANDLE2["NorthEast"] = "ne";
4046
+ TELE_BOX_RESIZE_HANDLE2["SouthEast"] = "se";
4047
+ TELE_BOX_RESIZE_HANDLE2["SouthWest"] = "sw";
4048
+ return TELE_BOX_RESIZE_HANDLE2;
4049
+ })(TELE_BOX_RESIZE_HANDLE || {});
4050
+ const TeleBoxDragHandleType = "dh";
4051
+ function clamp$1(value, min, max) {
4052
+ return Math.min(Math.max(value, min), max);
4018
4053
  }
4019
- function T$3(e2) {
4020
- return Boolean(e2);
4054
+ function preventEvent$1(ev) {
4055
+ ev.stopPropagation();
4056
+ if (ev.cancelable) {
4057
+ ev.preventDefault();
4058
+ }
4021
4059
  }
4022
- function V$3(e2) {
4023
- return !e2;
4060
+ let defaultBoxCount = 1;
4061
+ function getBoxDefaultName() {
4062
+ return `New Box ${defaultBoxCount++}`;
4024
4063
  }
4025
- class H$3 {
4026
- constructor({ readonly$: e2, state$: t2, title$: i2, buttons: s2, onEvent: a2, onDragStart: n2, namespace: o2 = "telebox" }) {
4027
- this.sideEffect = new SideEffectManager(), this.lastTitleBarClick = { timestamp: 0, clientX: -100, clientY: -100 }, this.handleTitleBarClick = (e3) => {
4028
- var t3;
4029
- if (this.readonly$.value)
4030
- return;
4031
- if (e3.button !== 0)
4032
- return;
4033
- if ((t3 = e3.target.dataset) == null ? void 0 : t3.teleTitleBarNoDblClick)
4064
+ class DefaultTitleBar {
4065
+ constructor({
4066
+ readonly$,
4067
+ state$,
4068
+ title$,
4069
+ buttons,
4070
+ onEvent,
4071
+ onDragStart,
4072
+ namespace = "telebox"
4073
+ }) {
4074
+ this.sideEffect = new SideEffectManager();
4075
+ this.lastTitleBarClick = {
4076
+ timestamp: 0,
4077
+ clientX: -100,
4078
+ clientY: -100
4079
+ };
4080
+ this.handleTitleBarClick = (ev) => {
4081
+ var _a;
4082
+ if (!ev.isPrimary || this.readonly$.value) {
4034
4083
  return;
4035
- k$1(e3);
4036
- const i3 = Date.now();
4037
- i3 - this.lastTitleBarClick.timestamp <= 500 ? Math.abs(e3.clientX - this.lastTitleBarClick.clientX) <= 5 && Math.abs(e3.clientY - this.lastTitleBarClick.clientY) <= 5 && this.onEvent && this.onEvent({ type: _.Maximize }) : this.onDragStart && this.onDragStart(e3), this.lastTitleBarClick.timestamp = i3, this.lastTitleBarClick.clientX = e3.clientX, this.lastTitleBarClick.clientY = e3.clientY;
4038
- }, this.lastTitleBarTouch = { timestamp: 0, clientX: -100, clientY: -100 }, this.handleTitleBarTouch = (e3) => {
4039
- var t3;
4040
- if (this.readonly$.value)
4084
+ }
4085
+ if (ev.button !== 0) {
4041
4086
  return;
4042
- if ((t3 = e3.target.dataset) == null ? void 0 : t3.teleTitleBarNoDblClick)
4087
+ }
4088
+ if ((_a = ev.target.dataset) == null ? void 0 : _a.teleTitleBarNoDblClick) {
4043
4089
  return;
4044
- k$1(e3);
4045
- const i3 = Date.now(), { clientX: s3 = this.lastTitleBarTouch.clientX + 100, clientY: a3 = this.lastTitleBarTouch.clientY + 100 } = e3.touches[0] || {};
4046
- i3 - this.lastTitleBarTouch.timestamp <= 500 ? Math.abs(s3 - this.lastTitleBarTouch.clientX) <= 10 && Math.abs(a3 - this.lastTitleBarTouch.clientY) <= 10 && this.onEvent && this.onEvent({ type: _.Maximize }) : this.onDragStart && this.onDragStart(e3), this.lastTitleBarTouch.timestamp = i3, this.lastTitleBarTouch.clientX = s3, this.lastTitleBarTouch.clientY = a3;
4047
- }, this.readonly$ = e2, this.state$ = t2, this.title$ = i2, this.onEvent = a2, this.onDragStart = n2, this.namespace = o2, this.buttons = s2 || [{ type: _.Minimize, iconClassName: this.wrapClassName("titlebar-icon-minimize") }, { type: _.Maximize, iconClassName: this.wrapClassName("titlebar-icon-maximize"), isActive: (e3) => e3 === C$3.Maximized }, { type: _.Close, iconClassName: this.wrapClassName("titlebar-icon-close") }], this.$dragArea = this.renderDragArea();
4090
+ }
4091
+ preventEvent$1(ev);
4092
+ const now = Date.now();
4093
+ if (now - this.lastTitleBarClick.timestamp <= 500) {
4094
+ if (Math.abs(ev.clientX - this.lastTitleBarClick.clientX) <= 5 && Math.abs(ev.clientY - this.lastTitleBarClick.clientY) <= 5) {
4095
+ if (this.onEvent) {
4096
+ this.onEvent({ type: TELE_BOX_DELEGATE_EVENT.Maximize });
4097
+ }
4098
+ }
4099
+ } else if (this.onDragStart) {
4100
+ this.onDragStart(ev);
4101
+ }
4102
+ this.lastTitleBarClick.timestamp = now;
4103
+ this.lastTitleBarClick.clientX = ev.clientX;
4104
+ this.lastTitleBarClick.clientY = ev.clientY;
4105
+ };
4106
+ this.readonly$ = readonly$;
4107
+ this.state$ = state$;
4108
+ this.title$ = title$;
4109
+ this.onEvent = onEvent;
4110
+ this.onDragStart = onDragStart;
4111
+ this.namespace = namespace;
4112
+ this.buttons = buttons || [
4113
+ {
4114
+ type: TELE_BOX_DELEGATE_EVENT.Minimize,
4115
+ iconClassName: this.wrapClassName("titlebar-icon-minimize")
4116
+ },
4117
+ {
4118
+ type: TELE_BOX_DELEGATE_EVENT.Maximize,
4119
+ iconClassName: this.wrapClassName("titlebar-icon-maximize"),
4120
+ isActive: (state) => state === TELE_BOX_STATE.Maximized
4121
+ },
4122
+ {
4123
+ type: TELE_BOX_DELEGATE_EVENT.Close,
4124
+ iconClassName: this.wrapClassName("titlebar-icon-close")
4125
+ }
4126
+ ];
4127
+ this.$dragArea = this.renderDragArea();
4048
4128
  }
4049
4129
  render() {
4050
4130
  if (!this.$titleBar) {
4051
- this.$titleBar = document.createElement("div"), this.$titleBar.className = this.wrapClassName("titlebar");
4052
- const e2 = document.createElement("div");
4053
- e2.className = this.wrapClassName("title-area"), e2.dataset.teleBoxHandle = "dh";
4054
- const t2 = document.createElement("h1");
4055
- t2.className = this.wrapClassName("title"), t2.dataset.teleBoxHandle = "dh", e2.appendChild(t2), e2.appendChild(this.$dragArea);
4056
- const i2 = document.createElement("div");
4057
- i2.className = this.wrapClassName("titlebar-btns"), this.buttons.forEach(({ iconClassName: e3 }, t3) => {
4058
- const s2 = String(t3), a2 = document.createElement("button");
4059
- a2.className = `${this.wrapClassName("titlebar-btn")} ${e3}`, a2.dataset.teleTitleBarBtnIndex = s2, a2.dataset.teleTitleBarNoDblClick = "true", i2.appendChild(a2);
4060
- }), this.sideEffect.addDisposer(this.title$.subscribe((e3) => {
4061
- t2.textContent = e3, t2.title = e3;
4062
- }), "render-title"), this.sideEffect.addDisposer(this.state$.subscribe((e3) => {
4063
- this.buttons.forEach((t3, s2) => {
4064
- var a2;
4065
- t3.isActive && ((a2 = i2.children[s2]) == null || a2.classList.toggle("is-active", t3.isActive(e3)));
4131
+ this.$titleBar = document.createElement("div");
4132
+ this.$titleBar.className = this.wrapClassName("titlebar");
4133
+ const $titleArea = document.createElement("div");
4134
+ $titleArea.className = this.wrapClassName("title-area");
4135
+ $titleArea.dataset.teleBoxHandle = TeleBoxDragHandleType;
4136
+ const $title = document.createElement("h1");
4137
+ $title.className = this.wrapClassName("title");
4138
+ $title.dataset.teleBoxHandle = TeleBoxDragHandleType;
4139
+ $titleArea.appendChild($title);
4140
+ $titleArea.appendChild(this.$dragArea);
4141
+ const $buttonsContainer = document.createElement("div");
4142
+ $buttonsContainer.className = this.wrapClassName("titlebar-btns");
4143
+ this.buttons.forEach(({ iconClassName }, i2) => {
4144
+ const teleTitleBarBtnIndex = String(i2);
4145
+ const $btn = document.createElement("button");
4146
+ $btn.className = `${this.wrapClassName("titlebar-btn")} ${iconClassName}`;
4147
+ $btn.dataset.teleTitleBarBtnIndex = teleTitleBarBtnIndex;
4148
+ $btn.dataset.teleTitleBarNoDblClick = "true";
4149
+ $buttonsContainer.appendChild($btn);
4150
+ });
4151
+ this.sideEffect.addDisposer(this.title$.subscribe((title) => {
4152
+ $title.textContent = title;
4153
+ $title.title = title;
4154
+ }), "render-title");
4155
+ this.sideEffect.addDisposer(this.state$.subscribe((state) => {
4156
+ this.buttons.forEach((btn, i2) => {
4157
+ var _a;
4158
+ if (btn.isActive) {
4159
+ (_a = $buttonsContainer.children[i2]) == null ? void 0 : _a.classList.toggle("is-active", btn.isActive(state));
4160
+ }
4066
4161
  });
4067
- }), "render-state-btns"), this.sideEffect.addEventListener(i2, "click", (e3) => {
4068
- var t3;
4069
- if (this.readonly$.value)
4162
+ }), "render-state-btns");
4163
+ this.sideEffect.addEventListener($buttonsContainer, "pointerup", (ev) => {
4164
+ var _a;
4165
+ if (!ev.isPrimary || this.readonly$.value) {
4070
4166
  return;
4071
- const i3 = e3.target, s2 = Number((t3 = i3.dataset) == null ? void 0 : t3.teleTitleBarBtnIndex);
4072
- if (!Number.isNaN(s2) && s2 < this.buttons.length) {
4073
- k$1(e3);
4074
- const t4 = this.buttons[s2];
4075
- this.onEvent && this.onEvent({ type: t4.type, value: t4.value });
4076
4167
  }
4077
- }, {}, "render-btns-container-click"), this.$titleBar.appendChild(e2), this.$titleBar.appendChild(i2);
4168
+ const target = ev.target;
4169
+ const teleTitleBarBtnIndex = Number((_a = target.dataset) == null ? void 0 : _a.teleTitleBarBtnIndex);
4170
+ if (!Number.isNaN(teleTitleBarBtnIndex) && teleTitleBarBtnIndex < this.buttons.length) {
4171
+ preventEvent$1(ev);
4172
+ const btn = this.buttons[teleTitleBarBtnIndex];
4173
+ if (this.onEvent) {
4174
+ this.onEvent({
4175
+ type: btn.type,
4176
+ value: btn.value
4177
+ });
4178
+ }
4179
+ }
4180
+ }, {}, "render-btns-container-click");
4181
+ this.$titleBar.appendChild($titleArea);
4182
+ this.$titleBar.appendChild($buttonsContainer);
4078
4183
  }
4079
4184
  return this.$titleBar;
4080
4185
  }
4081
4186
  renderDragArea() {
4082
- const e2 = document.createElement("div");
4083
- return e2.className = this.wrapClassName("drag-area"), e2.dataset.teleBoxHandle = "dh", this.sideEffect.addEventListener(e2, "mousedown", this.handleTitleBarClick), this.sideEffect.addEventListener(e2, "touchstart", this.handleTitleBarTouch, { passive: true }), e2;
4187
+ const $dragArea = document.createElement("div");
4188
+ $dragArea.className = this.wrapClassName("drag-area");
4189
+ $dragArea.dataset.teleBoxHandle = TeleBoxDragHandleType;
4190
+ this.sideEffect.addEventListener($dragArea, "pointerdown", this.handleTitleBarClick);
4191
+ return $dragArea;
4084
4192
  }
4085
4193
  dragHandle() {
4086
4194
  return this.$titleBar;
4087
4195
  }
4088
- wrapClassName(e2) {
4089
- return `${this.namespace}-${e2}`;
4196
+ wrapClassName(className) {
4197
+ return `${this.namespace}-${className}`;
4090
4198
  }
4091
4199
  destroy() {
4092
- this.sideEffect.flushAll(), this.$titleBar && (this.$titleBar = void 0, this.onDragStart = void 0, this.onEvent = void 0);
4093
- }
4094
- }
4095
- class A$2 {
4096
- constructor({ namespace: e2, rootRect$: t2, ratio$: i2, highlightStage$: s2, root$: a2 }) {
4097
- this._sideEffect = new SideEffectManager(), this.namespace = e2, this.highlightStage$ = s2, this.stageRect$ = combine([t2, i2], ([e3, t3]) => {
4098
- if (t3 <= 0 || e3.width <= 0 || e3.height <= 0)
4099
- return e3;
4100
- const i3 = e3.width * t3;
4101
- if (i3 === e3.height)
4102
- return e3;
4103
- if (i3 < e3.height)
4104
- return { x: 0, y: (e3.height - i3) / 2, width: e3.width, height: i3 };
4105
- const s3 = e3.height / t3;
4106
- return { x: (e3.width - s3) / 2, y: 0, width: s3, height: e3.height };
4107
- }, { compare: shallowequal }), this._sideEffect.addDisposer(combine([a2, s2]).subscribe(([e3, t3]) => {
4108
- var i3;
4109
- e3 && t3 ? e3.appendChild(this.render()) : ((i3 = this.$boxStage) == null ? void 0 : i3.parentNode) && this.$boxStage.remove();
4110
- }));
4200
+ this.sideEffect.flushAll();
4201
+ if (this.$titleBar) {
4202
+ this.$titleBar = void 0;
4203
+ this.onDragStart = void 0;
4204
+ this.onEvent = void 0;
4205
+ }
4111
4206
  }
4112
- render() {
4113
- if (this.$boxStage)
4114
- return this.$boxStage;
4115
- const e2 = document.createElement("div");
4116
- e2.className = this.wrapClassName("box-stage-container");
4117
- const t2 = document.createElement("div");
4118
- t2.className = this.wrapClassName("box-stage-mask");
4119
- const i2 = document.createElement("div");
4120
- i2.className = this.wrapClassName("box-stage-mask");
4121
- const s2 = document.createElement("div");
4122
- s2.className = this.wrapClassName("box-stage-frame");
4123
- const [a2, n2, o2, r2] = ["M0 8V0h8v2H2v6H0Z", "M8 8V0H0v2h6v6h2Z", "M0 0v8h8V6H2V0H0Z", "M8 0v8H0V6h6V0h2Z"].map((e3, t3) => {
4124
- const i3 = document.createElementNS("http://www.w3.org/2000/svg", "svg");
4125
- i3.setAttribute("viewBox", "0 0 8 8"), i3.setAttribute("class", `${this.wrapClassName("box-stage-frame-corner")} is-${t3}`);
4126
- const s3 = document.createElementNS("http://www.w3.org/2000/svg", "path");
4127
- return s3.setAttribute("d", e3), s3.setAttribute("fill", "#3381FF"), i3.appendChild(s3), i3;
4128
- });
4129
- return s2.appendChild(a2), s2.appendChild(o2), s2.appendChild(n2), s2.appendChild(r2), e2.appendChild(t2), e2.appendChild(s2), e2.appendChild(i2), this._sideEffect.addDisposer(this.highlightStage$.subscribe((t3) => {
4130
- e2.classList.toggle("is-active", t3);
4131
- })), this._sideEffect.addDisposer(combine([this.highlightStage$, this.stageRect$]).subscribe(([s3, a3]) => {
4132
- s3 && (a3.x > 0 ? (e2.style.flexDirection = "row", t2.style.width = `${a3.x}px`, t2.style.height = "", i2.style.width = `${a3.x}px`, i2.style.height = "") : a3.y > 0 && (e2.style.flexDirection = "column", t2.style.width = "", t2.style.height = `${a3.y}px`, i2.style.width = "", i2.style.height = `${a3.y}px`));
4133
- })), this.$boxStage = e2, e2;
4207
+ }
4208
+ function calcStageRect([rootRect, ratio]) {
4209
+ if (ratio <= 0 || rootRect.width <= 0 || rootRect.height <= 0) {
4210
+ return rootRect;
4134
4211
  }
4135
- destroy() {
4136
- this._sideEffect.flushAll();
4212
+ const preferredHeight = rootRect.width * ratio;
4213
+ if (preferredHeight === rootRect.height) {
4214
+ return rootRect;
4137
4215
  }
4138
- wrapClassName(e2) {
4139
- return `${this.namespace}-${e2}`;
4140
- }
4141
- }
4142
- const W$3 = window.ResizeObserver || ResizeObserver$2;
4143
- class Y$3 {
4144
- constructor({ id: e2 = genUID(), title: t2 = L$3(), namespace: i2 = "telebox", visible: s2 = true, width: a2 = 0.5, height: n2 = 0.5, minWidth: o2 = 0, minHeight: r2 = 0, x: l2 = 0.1, y: $ = 0.1, resizable: b2 = true, draggable: v2 = true, ratio: w2 = -1, focus: y2 = false, zIndex: z2 = 100, stageRatio: _2 = null, titleBar: B2, content: N2, stage: S2, footer: M2, styles: k2, highlightStage: R2 = null, darkMode$: D2, fence$: T2, minimized$: V2, maximized$: W2, readonly$: Y2, root$: X2, rootRect$: P2, managerStageRect$: O2, managerStageRatio$: j2, collectorRect$: Z2, managerHighlightStage$: F2 }) {
4145
- this.events = new Emittery(), this._delegateEvents = new Emittery(), this.handleTrackStart = (e3) => {
4146
- var t3;
4147
- return (t3 = this._handleTrackStart) == null ? void 0 : t3.call(this, e3);
4148
- }, this._sideEffect = new SideEffectManager(), this.id = e2, this.namespace = i2;
4149
- const G2 = new ValManager();
4150
- this._sideEffect.addDisposer(() => G2.destroy());
4151
- const J2 = new Val(t2), q2 = new Val(s2), Q2 = new Val(b2), K2 = new Val(v2), U2 = new Val(w2), ee2 = new Val(z2), te2 = new Val(y2), ie2 = new Val(N2), se2 = new Val(S2), ae2 = new Val(M2), ne2 = new Val(k2), oe2 = combine([V2, W2], ([e3, t3]) => e3 ? C$3.Minimized : t3 ? C$3.Maximized : C$3.Normal), re2 = new Val({ width: I$3(o2, 0, 1), height: I$3(r2, 0, 1) }, { compare: shallowequal }), he2 = combine([re2, O2], ([e3, t3]) => ({ width: e3.width * t3.width, height: e3.height * t3.height }), { compare: shallowequal }), le2 = new Val({ width: a2, height: n2 }, { compare: shallowequal });
4152
- this._sideEffect.addDisposer(re2.reaction((e3, t3) => {
4153
- le2.setValue({ width: Math.max(a2, e3.width), height: Math.max(n2, e3.height) }, t3);
4216
+ if (preferredHeight < rootRect.height) {
4217
+ return {
4218
+ x: 0,
4219
+ y: (rootRect.height - preferredHeight) / 2,
4220
+ width: rootRect.width,
4221
+ height: preferredHeight
4222
+ };
4223
+ }
4224
+ const preferredWidth = rootRect.height / ratio;
4225
+ return {
4226
+ x: (rootRect.width - preferredWidth) / 2,
4227
+ y: 0,
4228
+ width: preferredWidth,
4229
+ height: rootRect.height
4230
+ };
4231
+ }
4232
+ const ResizeObserver$1$1 = window.ResizeObserver || ResizeObserver$3;
4233
+ class TeleBox {
4234
+ constructor({
4235
+ id: id2 = genUID(),
4236
+ title = getBoxDefaultName(),
4237
+ namespace = "telebox",
4238
+ visible = true,
4239
+ width = 0.5,
4240
+ height = 0.5,
4241
+ minWidth = 0,
4242
+ minHeight = 0,
4243
+ x: x2 = 0.1,
4244
+ y: y2 = 0.1,
4245
+ resizable = true,
4246
+ draggable = true,
4247
+ boxRatio = -1,
4248
+ focus = false,
4249
+ zIndex = 100,
4250
+ stageRatio = null,
4251
+ enableShadowDOM = true,
4252
+ titleBar,
4253
+ content,
4254
+ stage,
4255
+ footer,
4256
+ styles: styles2,
4257
+ userStyles,
4258
+ bodyStyle = null,
4259
+ stageStyle = null,
4260
+ darkMode$,
4261
+ fence$,
4262
+ minimized$,
4263
+ maximized$,
4264
+ readonly$,
4265
+ root,
4266
+ rootRect$,
4267
+ managerStageRect$,
4268
+ managerStageRatio$,
4269
+ defaultBoxBodyStyle$,
4270
+ defaultBoxStageStyle$,
4271
+ collectorRect$
4272
+ }) {
4273
+ this.events = new Emittery();
4274
+ this._delegateEvents = new Emittery();
4275
+ this.handleTrackStart = (ev) => {
4276
+ var _a;
4277
+ return (_a = this._handleTrackStart) == null ? void 0 : _a.call(this, ev);
4278
+ };
4279
+ this._sideEffect = new SideEffectManager();
4280
+ this.id = id2;
4281
+ this.namespace = namespace;
4282
+ this.enableShadowDOM = enableShadowDOM;
4283
+ const valManager = new ValManager();
4284
+ this._sideEffect.addDisposer(() => valManager.destroy());
4285
+ const title$ = new Val(title);
4286
+ const visible$ = new Val(visible);
4287
+ const resizable$ = new Val(resizable);
4288
+ const draggable$ = new Val(draggable);
4289
+ const boxRatio$ = new Val(boxRatio);
4290
+ const zIndex$ = new Val(zIndex);
4291
+ const focus$ = new Val(focus);
4292
+ const state$ = combine([minimized$, maximized$], ([minimized, maximized]) => minimized ? TELE_BOX_STATE.Minimized : maximized ? TELE_BOX_STATE.Maximized : TELE_BOX_STATE.Normal);
4293
+ const minSize$ = new Val({
4294
+ width: clamp$1(minWidth, 0, 1),
4295
+ height: clamp$1(minHeight, 0, 1)
4296
+ }, { compare: shallowequal });
4297
+ const pxMinSize$ = combine([minSize$, managerStageRect$], ([minSize, managerStageRect]) => ({
4298
+ width: minSize.width * managerStageRect.width,
4299
+ height: minSize.height * managerStageRect.height
4300
+ }), { compare: shallowequal });
4301
+ const intrinsicSize$ = new Val({ width, height }, { compare: shallowequal });
4302
+ this._sideEffect.addDisposer(minSize$.reaction((minSize, skipUpdate) => {
4303
+ intrinsicSize$.setValue({
4304
+ width: Math.max(width, minSize.width),
4305
+ height: Math.max(height, minSize.height)
4306
+ }, skipUpdate);
4307
+ }));
4308
+ const intrinsicCoord$ = new Val({ x: x2, y: y2 }, { compare: shallowequal });
4309
+ const pxIntrinsicSize$ = combine([intrinsicSize$, managerStageRect$], ([size2, managerStageRect]) => ({
4310
+ width: managerStageRect.width * size2.width,
4311
+ height: managerStageRect.height * size2.height
4312
+ }), { compare: shallowequal });
4313
+ const pxIntrinsicCoord$ = combine([intrinsicCoord$, managerStageRect$], ([intrinsicCoord, managerStageRect]) => ({
4314
+ x: intrinsicCoord.x * managerStageRect.width,
4315
+ y: intrinsicCoord.y * managerStageRect.height
4316
+ }), { compare: shallowequal });
4317
+ const bodyStyle$ = new Val(bodyStyle);
4318
+ const stageStyle$ = new Val(stageStyle);
4319
+ const contentRoot$ = new Val(null);
4320
+ const bodyRect$ = new Val(managerStageRect$.value, {
4321
+ compare: shallowequal
4322
+ });
4323
+ const stageRatio$ = new Val(stageRatio);
4324
+ const finalStageRatio$ = combine([stageRatio$, managerStageRatio$], ([stageRatio2, managerStageRatio]) => stageRatio2 != null ? stageRatio2 : managerStageRatio);
4325
+ const stageRect$ = combine([bodyRect$, finalStageRatio$], calcStageRect, { compare: shallowequal });
4326
+ const propsValConfig = {
4327
+ darkMode: darkMode$,
4328
+ fence: fence$,
4329
+ minimized: minimized$,
4330
+ maximized: maximized$,
4331
+ readonly: readonly$,
4332
+ rootRect: rootRect$,
4333
+ managerStageRect: managerStageRect$,
4334
+ defaultBoxBodyStyle: defaultBoxBodyStyle$,
4335
+ defaultBoxStageStyle: defaultBoxStageStyle$,
4336
+ collectorRect: collectorRect$
4337
+ };
4338
+ withReadonlyValueEnhancer(this, propsValConfig);
4339
+ const myReadonlyValConfig = {
4340
+ zIndex: zIndex$,
4341
+ focus: focus$,
4342
+ state: state$,
4343
+ minSize: minSize$,
4344
+ pxMinSize: pxMinSize$,
4345
+ intrinsicSize: intrinsicSize$,
4346
+ intrinsicCoord: intrinsicCoord$,
4347
+ pxIntrinsicSize: pxIntrinsicSize$,
4348
+ pxIntrinsicCoord: pxIntrinsicCoord$,
4349
+ bodyRect: bodyRect$,
4350
+ stageRect: stageRect$
4351
+ };
4352
+ withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
4353
+ const valConfig = {
4354
+ title: title$,
4355
+ visible: visible$,
4356
+ resizable: resizable$,
4357
+ draggable: draggable$,
4358
+ boxRatio: boxRatio$,
4359
+ stageRatio: stageRatio$,
4360
+ bodyStyle: bodyStyle$,
4361
+ stageStyle: stageStyle$
4362
+ };
4363
+ withValueEnhancer(this, valConfig, valManager);
4364
+ this.titleBar = titleBar || new DefaultTitleBar({
4365
+ readonly$,
4366
+ state$,
4367
+ title$,
4368
+ namespace: this.namespace,
4369
+ onDragStart: (event) => {
4370
+ var _a;
4371
+ return (_a = this._handleTrackStart) == null ? void 0 : _a.call(this, event);
4372
+ },
4373
+ onEvent: (event) => this._delegateEvents.emit(event.type)
4374
+ });
4375
+ this._sideEffect.addDisposer(boxRatio$.subscribe((boxRatio2) => {
4376
+ if (boxRatio2 > 0) {
4377
+ this.transform(pxIntrinsicCoord$.value.x, pxIntrinsicCoord$.value.y, pxIntrinsicSize$.value.width, pxIntrinsicSize$.value.height);
4378
+ }
4379
+ }));
4380
+ this._sideEffect.addDisposer(fence$.subscribe((fence) => {
4381
+ if (fence) {
4382
+ this.move(pxIntrinsicCoord$.value.x, pxIntrinsicCoord$.value.y);
4383
+ }
4154
4384
  }));
4155
- const de2 = new Val({ x: l2, y: $ }, { compare: shallowequal }), ce2 = combine([le2, O2], ([e3, t3]) => ({ width: t3.width * e3.width, height: t3.height * e3.height }), { compare: shallowequal }), me2 = combine([de2, O2], ([e3, t3]) => ({ x: e3.x * t3.width + t3.x, y: e3.y * t3.height + t3.y }), { compare: shallowequal }), ue2 = new Val(R2), ge2 = combine([ue2, F2], ([e3, t3]) => e3 != null ? e3 : t3), pe2 = new Val(null), xe2 = new Val(P2.value, { compare: shallowequal }), fe2 = new Val(_2), $e2 = new A$2({ namespace: i2, root$: pe2, rootRect$: xe2, ratio$: combine([fe2, j2], ([e3, t3]) => e3 != null ? e3 : t3), highlightStage$: ge2 });
4156
- this._sideEffect.addDisposer(() => $e2.destroy());
4157
- withReadonlyValueEnhancer(this, { darkMode: D2, fence: T2, minimized: V2, maximized: W2, readonly: Y2, rootRect: P2, managerStageRect: O2, collectorRect: Z2 });
4158
- const be2 = { zIndex: ee2, focus: te2, $userContent: ie2, $userStage: se2, $userFooter: ae2, $userStyles: ne2, state: oe2, minSize: re2, pxMinSize: he2, intrinsicSize: le2, intrinsicCoord: de2, pxIntrinsicSize: ce2, pxIntrinsicCoord: me2, highlightStage: ge2, boxHighlightStage: ue2, contentRect: xe2, contentStageRect: $e2.stageRect$ };
4159
- withReadonlyValueEnhancer(this, be2, G2);
4160
- withValueEnhancer(this, { title: J2, visible: q2, resizable: Q2, draggable: K2, ratio: U2, stageRatio: fe2 }, G2), this.titleBar = B2 || new H$3({ readonly$: Y2, state$: oe2, title$: J2, namespace: this.namespace, onDragStart: (e3) => {
4161
- var t3;
4162
- return (t3 = this._handleTrackStart) == null ? void 0 : t3.call(this, e3);
4163
- }, onEvent: (e3) => this._delegateEvents.emit(e3.type) }), this._sideEffect.addDisposer(U2.subscribe((e3) => {
4164
- e3 > 0 && this.transform(me2.value.x, me2.value.y, ce2.value.width, ce2.value.height, true);
4165
- })), this._sideEffect.addDisposer(T2.subscribe((e3) => {
4166
- e3 && this.move(me2.value.x, me2.value.y, true);
4167
- })), this.$box = this.render(), pe2.setValue(this.$content.parentElement);
4168
- const ve2 = (e3, t3) => {
4169
- this._sideEffect.addDisposer(e3.reaction((e4, i3) => {
4170
- i3 || this.events.emit(t3, e4);
4385
+ this.$box = this._render();
4386
+ contentRoot$.setValue(this.$content.parentElement);
4387
+ content && this.mountContent(content);
4388
+ stage && this.mountStage(stage);
4389
+ footer && this.mountFooter(footer);
4390
+ styles2 && this.mountStyles(styles2);
4391
+ userStyles && this.mountUserStyles(userStyles);
4392
+ root.appendChild(this.$box);
4393
+ const watchValEvent = (val, event) => {
4394
+ this._sideEffect.addDisposer(val.reaction((v2, skipUpdate) => {
4395
+ if (!skipUpdate) {
4396
+ this.events.emit(event, v2);
4397
+ }
4171
4398
  }));
4172
4399
  };
4173
- ve2(D2, E$3.DarkMode), ve2(Y2, E$3.Readonly), ve2(ee2, E$3.ZIndex), ve2(V2, E$3.Minimized), ve2(W2, E$3.Maximized), ve2(oe2, E$3.State), ve2(le2, E$3.IntrinsicResize), ve2(de2, E$3.IntrinsicMove), this._sideEffect.addDisposer([q2.reaction((e3, t3) => {
4174
- t3 || e3 || this.events.emit(E$3.Close);
4175
- }), te2.reaction((e3, t3) => {
4176
- t3 || this.events.emit(e3 ? E$3.Focus : E$3.Blur);
4177
- }), X2.subscribe((e3) => {
4178
- e3 ? e3.appendChild(this.$box) : this.$box.parentNode && this.$box.remove();
4179
- })]);
4400
+ watchValEvent(darkMode$, TELE_BOX_EVENT.DarkMode);
4401
+ watchValEvent(readonly$, TELE_BOX_EVENT.Readonly);
4402
+ watchValEvent(zIndex$, TELE_BOX_EVENT.ZIndex);
4403
+ watchValEvent(minimized$, TELE_BOX_EVENT.Minimized);
4404
+ watchValEvent(maximized$, TELE_BOX_EVENT.Maximized);
4405
+ watchValEvent(state$, TELE_BOX_EVENT.State);
4406
+ watchValEvent(intrinsicSize$, TELE_BOX_EVENT.IntrinsicResize);
4407
+ watchValEvent(intrinsicCoord$, TELE_BOX_EVENT.IntrinsicMove);
4408
+ this._sideEffect.addDisposer([
4409
+ visible$.reaction((visible2, skipUpdate) => {
4410
+ if (!skipUpdate && !visible2) {
4411
+ this.events.emit(TELE_BOX_EVENT.Close);
4412
+ }
4413
+ }),
4414
+ focus$.reaction((focus2, skipUpdate) => {
4415
+ if (!skipUpdate) {
4416
+ this.events.emit(focus2 ? TELE_BOX_EVENT.Focus : TELE_BOX_EVENT.Blur);
4417
+ }
4418
+ })
4419
+ ]);
4180
4420
  }
4181
4421
  get minWidth() {
4182
4422
  return this._minSize$.value.width;
@@ -4184,14 +4424,17 @@ class Y$3 {
4184
4424
  get minHeight() {
4185
4425
  return this._minSize$.value.height;
4186
4426
  }
4187
- setMinWidth(e2, t2 = false) {
4188
- this._minSize$.setValue({ width: e2, height: this.minHeight }, t2);
4427
+ setMinWidth(minWidth, skipUpdate = false) {
4428
+ this._minSize$.setValue({ width: minWidth, height: this.minHeight }, skipUpdate);
4189
4429
  }
4190
- setMinHeight(e2, t2 = false) {
4191
- this._minSize$.setValue({ width: this.minWidth, height: e2 }, t2);
4430
+ setMinHeight(minHeight, skipUpdate = false) {
4431
+ this._minSize$.setValue({ width: this.minWidth, height: minHeight }, skipUpdate);
4192
4432
  }
4193
- resize(e2, t2, i2 = false) {
4194
- this._intrinsicSize$.setValue({ width: Math.max(e2, this.minWidth), height: Math.max(t2, this.minHeight) }, i2);
4433
+ resize(width, height, skipUpdate = false) {
4434
+ this._intrinsicSize$.setValue({
4435
+ width: Math.max(width, this.minWidth),
4436
+ height: Math.max(height, this.minHeight)
4437
+ }, skipUpdate);
4195
4438
  }
4196
4439
  get intrinsicX() {
4197
4440
  return this._intrinsicCoord$.value.x;
@@ -4205,388 +4448,853 @@ class Y$3 {
4205
4448
  get intrinsicHeight() {
4206
4449
  return this._intrinsicSize$.value.height;
4207
4450
  }
4208
- move(e2, t2, i2 = false) {
4209
- let s2, a2;
4210
- const n2 = this.managerStageRect, o2 = this.pxIntrinsicSize;
4211
- if (this.fence)
4212
- s2 = I$3(e2, n2.x, n2.x + n2.width - o2.width), a2 = I$3(t2, n2.y, n2.y + n2.height - o2.height);
4213
- else {
4214
- const i3 = this.rootRect;
4215
- s2 = I$3(e2, 0 - o2.width + 20, 0 + i3.width - 20), a2 = I$3(t2, 0, 0 + i3.height - 20);
4216
- }
4217
- this._intrinsicCoord$.setValue({ x: (s2 - n2.x) / n2.width, y: (a2 - n2.y) / n2.height }, i2);
4218
- }
4219
- transform(e2, t2, i2, s2, a2 = false) {
4220
- const n2 = this.managerStageRect, o2 = this.rootRect;
4221
- if (i2 = Math.max(i2, this.pxMinSize.width), s2 = Math.max(s2, this.pxMinSize.height), this.ratio > 0) {
4222
- const e3 = this.ratio * i2;
4223
- t2 !== this.pxIntrinsicCoord.y && (t2 -= e3 - s2), s2 = e3;
4224
- }
4225
- t2 < o2.y && (t2 = o2.y, s2 = this.pxIntrinsicSize.height), this.move(e2, t2, a2), this._intrinsicSize$.setValue({ width: i2 / n2.width, height: s2 / n2.height }, a2);
4226
- }
4227
- mountContent(e2) {
4228
- this._$userContent$.setValue(e2);
4451
+ move(x2, y2, skipUpdate = false) {
4452
+ let safeX;
4453
+ let safeY;
4454
+ const managerStageRect = this.managerStageRect;
4455
+ const pxIntrinsicSize = this.pxIntrinsicSize;
4456
+ if (this.fence) {
4457
+ safeX = clamp$1(x2, 0, managerStageRect.width - pxIntrinsicSize.width);
4458
+ safeY = clamp$1(y2, 0, managerStageRect.height - pxIntrinsicSize.height);
4459
+ } else {
4460
+ safeX = clamp$1(x2, -(pxIntrinsicSize.width - 120), 0 + managerStageRect.width - 20);
4461
+ safeY = clamp$1(y2, 0, 0 + managerStageRect.height - 20);
4462
+ }
4463
+ this._intrinsicCoord$.setValue({
4464
+ x: safeX / managerStageRect.width,
4465
+ y: safeY / managerStageRect.height
4466
+ }, skipUpdate);
4467
+ }
4468
+ transform(x2, y2, width, height, skipUpdate = false) {
4469
+ const managerStageRect = this.managerStageRect;
4470
+ width = Math.max(width, this.pxMinSize.width);
4471
+ height = Math.max(height, this.pxMinSize.height);
4472
+ if (this.boxRatio > 0) {
4473
+ const newHeight = this.boxRatio * width;
4474
+ if (y2 !== this.pxIntrinsicCoord.y) {
4475
+ y2 -= newHeight - height;
4476
+ }
4477
+ height = newHeight;
4478
+ }
4479
+ if (y2 < 0) {
4480
+ y2 = 0;
4481
+ height = this.pxIntrinsicSize.height;
4482
+ }
4483
+ this.move(x2, y2, skipUpdate);
4484
+ this._intrinsicSize$.setValue({
4485
+ width: width / managerStageRect.width,
4486
+ height: height / managerStageRect.height
4487
+ }, skipUpdate);
4488
+ }
4489
+ mountContent(content) {
4490
+ var _a;
4491
+ (_a = this.$authorContent) == null ? void 0 : _a.remove();
4492
+ this.$authorContent = content;
4493
+ this.$content.appendChild(content);
4229
4494
  }
4230
4495
  unmountContent() {
4231
- this._$userContent$.setValue(void 0);
4496
+ if (this.$authorContent) {
4497
+ this.$authorContent.remove();
4498
+ this.$authorContent = void 0;
4499
+ }
4232
4500
  }
4233
- mountStage(e2) {
4234
- this._$userStage$.setValue(e2);
4501
+ mountStage(stage) {
4502
+ var _a;
4503
+ (_a = this.$authorStage) == null ? void 0 : _a.remove();
4504
+ this.$authorStage = stage;
4505
+ if (!this.$stage) {
4506
+ this.$stage = this._renderStage();
4507
+ }
4508
+ this.$stage.appendChild(stage);
4509
+ if (!this.$stage.parentElement) {
4510
+ this.$body.appendChild(this.$stage);
4511
+ }
4235
4512
  }
4236
4513
  unmountStage() {
4237
- this._$userStage$.setValue(void 0);
4514
+ var _a;
4515
+ if (this.$authorStage) {
4516
+ this.$authorStage.remove();
4517
+ this.$authorStage = void 0;
4518
+ }
4519
+ (_a = this.$stage) == null ? void 0 : _a.remove();
4238
4520
  }
4239
- mountFooter(e2) {
4240
- this._$userFooter$.setValue(e2);
4521
+ mountFooter(footer) {
4522
+ var _a;
4523
+ (_a = this.$authorFooter) == null ? void 0 : _a.remove();
4524
+ this.$authorFooter = footer;
4525
+ this.$footer.appendChild(footer);
4241
4526
  }
4242
4527
  unmountFooter() {
4243
- this._$userFooter$.setValue(void 0);
4244
- }
4245
- getUserStyles() {
4246
- return this.$userStyles;
4528
+ if (this.$authorFooter) {
4529
+ this.$authorFooter.remove();
4530
+ this.$authorFooter = void 0;
4531
+ }
4247
4532
  }
4248
- mountStyles(e2) {
4249
- let t2;
4250
- typeof e2 == "string" ? (t2 = document.createElement("style"), t2.textContent = e2) : t2 = e2, this._$userStyles$.setValue(t2);
4533
+ mountStyles(styles2) {
4534
+ this.$styles.textContent = styles2;
4251
4535
  }
4252
4536
  unmountStyles() {
4253
- this._$userStyles$.setValue(void 0);
4537
+ this.$styles.textContent = "";
4254
4538
  }
4255
- setHighlightStage(e2) {
4256
- this._boxHighlightStage$.setValue(e2);
4539
+ mountUserStyles(styles2) {
4540
+ this.$userStyles.textContent = styles2;
4257
4541
  }
4258
- render() {
4259
- if (this.$box)
4542
+ unmountUserStyles() {
4543
+ this.$userStyles.textContent = "";
4544
+ }
4545
+ _render() {
4546
+ if (this.$box) {
4260
4547
  return this.$box;
4261
- this.$box = document.createElement("div"), this.$box.classList.add(this.wrapClassName("box"));
4262
- const e2 = (e3, t3, i3, s3 = T$3) => this._sideEffect.add(() => {
4263
- const a3 = this.wrapClassName(i3);
4264
- return t3.subscribe((t4) => {
4265
- e3.classList.toggle(a3, s3(t4));
4548
+ }
4549
+ const bindBoxStates = (el, disposerID) => {
4550
+ return this._sideEffect.addDisposer([
4551
+ this._readonly$.subscribe((readonly) => el.classList.toggle(this.wrapClassName("readonly"), readonly)),
4552
+ this._draggable$.subscribe((draggable) => el.classList.toggle(this.wrapClassName("no-drag"), !draggable)),
4553
+ this._resizable$.subscribe((resizable) => el.classList.toggle(this.wrapClassName("no-resize"), !resizable)),
4554
+ this._focus$.subscribe((focus) => el.classList.toggle(this.wrapClassName("blur"), !focus)),
4555
+ this._darkMode$.subscribe((darkMode) => {
4556
+ el.classList.toggle(this.wrapClassName("color-scheme-dark"), darkMode);
4557
+ el.classList.toggle(this.wrapClassName("color-scheme-light"), !darkMode);
4558
+ })
4559
+ ], disposerID);
4560
+ };
4561
+ this.$box = document.createElement("div");
4562
+ this.$box.classList.add(this.wrapClassName("box"));
4563
+ bindBoxStates(this.$box, "bind-box-state");
4564
+ this._sideEffect.add(() => {
4565
+ const minimizedClassName = this.wrapClassName("minimized");
4566
+ const maximizedClassName = this.wrapClassName("maximized");
4567
+ const MAXIMIZED_TIMER_ID = "box-maximized-timer";
4568
+ return this._state$.subscribe((state) => {
4569
+ this.$box.classList.toggle(minimizedClassName, state === TELE_BOX_STATE.Minimized);
4570
+ if (state === TELE_BOX_STATE.Maximized) {
4571
+ this._sideEffect.flush(MAXIMIZED_TIMER_ID);
4572
+ this.$box.classList.toggle(maximizedClassName, true);
4573
+ } else {
4574
+ this._sideEffect.setTimeout(() => {
4575
+ this.$box.classList.toggle(maximizedClassName, false);
4576
+ }, 0, MAXIMIZED_TIMER_ID);
4577
+ }
4266
4578
  });
4267
4579
  });
4268
- e2(this.$box, this._readonly$, "readonly"), e2(this.$box, this._draggable$, "no-drag", V$3), e2(this.$box, this._resizable$, "no-resize", V$3), e2(this.$box, this._focus$, "blur", V$3), e2(this.$box, this._darkMode$, "color-scheme-dark"), e2(this.$box, this._darkMode$, "color-scheme-light", V$3), this._sideEffect.add(() => {
4269
- const e3 = this.wrapClassName("minimized"), t3 = this.wrapClassName("maximized"), i3 = "box-maximized-timer";
4270
- return this._state$.subscribe((s3) => {
4271
- this.$box.classList.toggle(e3, s3 === C$3.Minimized), s3 === C$3.Maximized ? (this._sideEffect.flush(i3), this.$box.classList.toggle(t3, true)) : this._sideEffect.setTimeout(() => {
4272
- this.$box.classList.toggle(t3, false);
4273
- }, 0, i3);
4274
- });
4275
- }), this._sideEffect.addDisposer(this._visible$.subscribe((e3) => {
4276
- this.$box.style.display = e3 ? "block" : "none";
4277
- })), this._sideEffect.addDisposer(this._zIndex$.subscribe((e3) => {
4278
- this.$box.style.zIndex = String(e3);
4279
- })), this.$box.dataset.teleBoxID = this.id;
4280
- const t2 = index(this.$box), i2 = combine([this._maximized$, this._minimized$, this._pxIntrinsicSize$, this._pxIntrinsicCoord$, this._collectorRect$], ([e3, t3, i3, s3, a3]) => {
4281
- const n3 = e3 ? { x: 0, y: 0, width: "100%", height: "100%", scaleX: 1, scaleY: 1 } : { x: s3.x, y: s3.y, width: i3.width + "px", height: i3.height + "px", scaleX: 1, scaleY: 1 };
4282
- if (t3 && a3) {
4283
- const { width: t4, height: s4 } = e3 ? this.rootRect : i3;
4284
- n3.x = a3.x - t4 / 2 + a3.width / 2, n3.y = a3.y - s4 / 2 + a3.height / 2, n3.scaleX = a3.width / t4, n3.scaleY = a3.height / s4;
4285
- }
4286
- return n3;
4287
- }, { compare: shallowequal }), s2 = i2.value;
4288
- this.$box.style.width = s2.width, this.$box.style.height = s2.height, this.$box.style.transform = `translate(${s2.x - 10}px,${s2.y - 10}px)`, this._sideEffect.addDisposer(i2.subscribe((e3) => {
4289
- t2.set(e3);
4580
+ this._sideEffect.addDisposer(this._visible$.subscribe((visible) => {
4581
+ this.$box.style.display = visible ? "block" : "none";
4290
4582
  }));
4291
- const a2 = document.createElement("div");
4292
- a2.className = this.wrapClassName("box-main"), this.$box.appendChild(a2);
4293
- const n2 = document.createElement("div");
4294
- n2.className = this.wrapClassName("titlebar-wrap"), n2.appendChild(this.titleBar.render()), this.$titleBar = n2;
4295
- const o2 = document.createElement("div");
4296
- o2.className = this.wrapClassName("content-wrap");
4297
- const r2 = document.createElement("div");
4298
- r2.className = this.wrapClassName("content") + " tele-fancy-scrollbar", this.$content = r2;
4299
- const h = () => {
4300
- const e3 = r2.getBoundingClientRect();
4301
- this._contentRect$.setValue({ x: 0, y: 0, width: e3.width, height: e3.height });
4583
+ this._sideEffect.addDisposer(this._zIndex$.subscribe((zIndex) => {
4584
+ this.$box.style.zIndex = String(zIndex);
4585
+ }));
4586
+ this.$box.dataset.teleBoxID = this.id;
4587
+ const boxStyler = index(this.$box);
4588
+ const boxStyles$ = combine([
4589
+ this._maximized$,
4590
+ this._minimized$,
4591
+ this._pxIntrinsicSize$,
4592
+ this._pxIntrinsicCoord$,
4593
+ this._collectorRect$,
4594
+ this._rootRect$,
4595
+ this._managerStageRect$
4596
+ ], ([
4597
+ maximized,
4598
+ minimized,
4599
+ pxIntrinsicSize,
4600
+ pxIntrinsicCoord,
4601
+ collectorRect,
4602
+ rootRect,
4603
+ managerStageRect
4604
+ ]) => {
4605
+ const styles2 = maximized ? {
4606
+ x: -managerStageRect.x,
4607
+ y: -managerStageRect.y,
4608
+ width: rootRect.width,
4609
+ height: rootRect.height,
4610
+ scaleX: 1,
4611
+ scaleY: 1
4612
+ } : {
4613
+ x: pxIntrinsicCoord.x,
4614
+ y: pxIntrinsicCoord.y,
4615
+ width: pxIntrinsicSize.width,
4616
+ height: pxIntrinsicSize.height,
4617
+ scaleX: 1,
4618
+ scaleY: 1
4619
+ };
4620
+ if (minimized && collectorRect) {
4621
+ const { width: boxWidth, height: boxHeight } = maximized ? this.rootRect : pxIntrinsicSize;
4622
+ styles2.x = collectorRect.x - boxWidth / 2 + collectorRect.width / 2 - managerStageRect.x;
4623
+ styles2.y = collectorRect.y - boxHeight / 2 + collectorRect.height / 2 - managerStageRect.y;
4624
+ styles2.scaleX = collectorRect.width / boxWidth;
4625
+ styles2.scaleY = collectorRect.height / boxHeight;
4626
+ }
4627
+ return styles2;
4628
+ }, { compare: shallowequal });
4629
+ const boxStyles = boxStyles$.value;
4630
+ this.$box.style.width = boxStyles.width + "px";
4631
+ this.$box.style.height = boxStyles.height + "px";
4632
+ this.$box.style.transform = `translate(${boxStyles.x - 10}px,${boxStyles.y - 10}px)`;
4633
+ this._sideEffect.addDisposer(boxStyles$.subscribe((styles2) => {
4634
+ boxStyler.set(styles2);
4635
+ }));
4636
+ const $boxMain = document.createElement("div");
4637
+ $boxMain.className = this.wrapClassName("box-main");
4638
+ this.$box.appendChild($boxMain);
4639
+ const $titleBar = document.createElement("div");
4640
+ $titleBar.className = this.wrapClassName("titlebar-wrap");
4641
+ $titleBar.appendChild(this.titleBar.render());
4642
+ this.$titleBar = $titleBar;
4643
+ const $body = document.createElement("div");
4644
+ $body.className = this.wrapClassName("body-wrap");
4645
+ this.$body = $body;
4646
+ const $styles = document.createElement("style");
4647
+ this.$styles = $styles;
4648
+ $body.appendChild($styles);
4649
+ const $userStyles = document.createElement("style");
4650
+ this.$userStyles = $userStyles;
4651
+ $body.appendChild($userStyles);
4652
+ const $content = document.createElement("div");
4653
+ $content.className = this.wrapClassName("content") + " tele-fancy-scrollbar";
4654
+ this.$content = $content;
4655
+ this._sideEffect.addDisposer(combine([this._bodyStyle$, this._defaultBoxBodyStyle$], ([bodyStyle, defaultBoxBodyStyle]) => bodyStyle != null ? bodyStyle : defaultBoxBodyStyle).subscribe((style2) => $content.style.cssText = style2 || ""));
4656
+ $body.appendChild($content);
4657
+ const $footer = document.createElement("div");
4658
+ $footer.className = this.wrapClassName("footer-wrap");
4659
+ this.$footer = $footer;
4660
+ $boxMain.appendChild($titleBar);
4661
+ const $main = document.createElement("div");
4662
+ $main.className = this.wrapClassName("main");
4663
+ this.$main = $main;
4664
+ $boxMain.appendChild($main);
4665
+ const $quarantineOuter = document.createElement("div");
4666
+ $quarantineOuter.className = this.wrapClassName("quarantine-outer");
4667
+ $main.appendChild($quarantineOuter);
4668
+ const $quarantine = document.createElement("div");
4669
+ $quarantine.className = this.wrapClassName("quarantine");
4670
+ $quarantine.appendChild($body);
4671
+ $quarantine.appendChild($footer);
4672
+ if (this.enableShadowDOM) {
4673
+ bindBoxStates($quarantine, "bind-quarantine-state");
4674
+ const $shadowStyle = document.createElement("style");
4675
+ $shadowStyle.textContent = shadowStyles;
4676
+ $quarantine.insertBefore($shadowStyle, $quarantine.firstChild);
4677
+ const shadow = $quarantineOuter.attachShadow({ mode: "open" });
4678
+ shadow.appendChild($quarantine);
4679
+ } else {
4680
+ $quarantineOuter.appendChild($quarantine);
4681
+ }
4682
+ this._renderResizeHandlers();
4683
+ const updateBodyRect = () => {
4684
+ const rect = $body.getBoundingClientRect();
4685
+ this._bodyRect$.setValue({
4686
+ x: 0,
4687
+ y: 0,
4688
+ width: rect.width,
4689
+ height: rect.height
4690
+ });
4302
4691
  };
4303
4692
  this._sideEffect.add(() => {
4304
- const e3 = new W$3(() => {
4305
- this.minimized || h();
4306
- });
4307
- return e3.observe(r2), () => e3.disconnect();
4308
- }), this._sideEffect.addDisposer(this._minimized$.reaction((e3) => {
4309
- e3 || this._sideEffect.setTimeout(h, 400, "minimized-content-rect-fix");
4310
- })), this._sideEffect.add(() => {
4311
- let e3;
4312
- return this._$userStyles$.subscribe((t3) => {
4313
- e3 && e3.remove(), e3 = t3, t3 && o2.appendChild(t3);
4314
- });
4315
- }), this._sideEffect.add(() => {
4316
- let e3;
4317
- return this._$userContent$.subscribe((t3) => {
4318
- e3 && e3.remove(), e3 = t3, t3 && r2.appendChild(t3);
4319
- });
4320
- }), this._sideEffect.add(() => {
4321
- let e3;
4322
- return this._$userStage$.subscribe((t3) => {
4323
- var i3;
4324
- if (e3 && e3.remove(), e3 = t3, t3) {
4325
- if (!this.$stage) {
4326
- const e4 = document.createElement("div");
4327
- this.$stage = e4, e4.className = this.wrapClassName("content-stage"), this._sideEffect.addDisposer(this._contentStageRect$.subscribe((t4) => {
4328
- e4.style.top = t4.y + "px", e4.style.left = t4.x + "px", e4.style.width = t4.width + "px", e4.style.height = t4.height + "px";
4329
- }), "content-stage-rect"), r2.appendChild(e4);
4330
- }
4331
- this.$stage.parentElement || r2.appendChild(this.$stage), this.$stage.appendChild(t3);
4332
- } else
4333
- ((i3 = this.$stage) == null ? void 0 : i3.parentElement) && this.$stage.remove();
4334
- });
4335
- }), o2.appendChild(r2);
4336
- const c = document.createElement("div");
4337
- return c.className = this.wrapClassName("footer-wrap"), this.$footer = c, this._sideEffect.add(() => {
4338
- let e3;
4339
- return this._$userFooter$.subscribe((t3) => {
4340
- e3 && e3.remove(), e3 = t3, t3 && c.appendChild(t3);
4693
+ const observer = new ResizeObserver$1$1(() => {
4694
+ if (!this.minimized) {
4695
+ updateBodyRect();
4696
+ }
4341
4697
  });
4342
- }), a2.appendChild(n2), a2.appendChild(o2), a2.appendChild(c), this._renderResizeHandlers(), this.$box;
4698
+ observer.observe($body);
4699
+ return () => observer.disconnect();
4700
+ });
4701
+ this._sideEffect.addDisposer(this._minimized$.reaction((minimized) => {
4702
+ if (!minimized) {
4703
+ this._sideEffect.setTimeout(updateBodyRect, 400, "minimized-content-rect-fix");
4704
+ }
4705
+ }));
4706
+ return this.$box;
4707
+ }
4708
+ _renderStage() {
4709
+ const $stage = document.createElement("div");
4710
+ $stage.className = this.wrapClassName("box-stage");
4711
+ const updateStageRect = (stageRect) => {
4712
+ $stage.style.top = stageRect.y + "px";
4713
+ $stage.style.left = stageRect.x + "px";
4714
+ $stage.style.width = stageRect.width + "px";
4715
+ $stage.style.height = stageRect.height + "px";
4716
+ };
4717
+ this._sideEffect.addDisposer([
4718
+ combine([this._stageStyle$, this._defaultBoxStageStyle$], ([stageStyle, defaultBoxStageStyle]) => stageStyle != null ? stageStyle : defaultBoxStageStyle).subscribe((styles2) => {
4719
+ $stage.style.cssText = styles2 || "";
4720
+ updateStageRect(this._stageRect$.value);
4721
+ }),
4722
+ this._stageRect$.subscribe(updateStageRect)
4723
+ ], "box-stage-styles");
4724
+ return $stage;
4343
4725
  }
4344
4726
  _renderResizeHandlers() {
4345
- const e2 = document.createElement("div");
4346
- e2.className = this.wrapClassName("resize-handles"), Object.values(N$3).forEach((t3) => {
4347
- const i3 = document.createElement("div");
4348
- i3.className = this.wrapClassName(t3) + " " + this.wrapClassName("resize-handle"), i3.dataset.teleBoxHandle = t3, e2.appendChild(i3);
4349
- }), this.$box.appendChild(e2);
4350
- const t2 = "handle-tracking-listener", i2 = this.wrapClassName("transforming");
4351
- let s2, a2, n2 = 0, o2 = 0, r2 = 0, h = 0, l2 = 0, d2 = 0;
4352
- const c = (e3) => {
4353
- if (this.state !== C$3.Normal)
4727
+ const $resizeHandles = document.createElement("div");
4728
+ $resizeHandles.className = this.wrapClassName("resize-handles");
4729
+ Object.values(TELE_BOX_RESIZE_HANDLE).forEach((handleType) => {
4730
+ const $handle = document.createElement("div");
4731
+ $handle.className = this.wrapClassName(handleType) + " " + this.wrapClassName("resize-handle");
4732
+ $handle.dataset.teleBoxHandle = handleType;
4733
+ $resizeHandles.appendChild($handle);
4734
+ });
4735
+ this.$box.appendChild($resizeHandles);
4736
+ const TRACKING_DISPOSER_ID = "handle-tracking-listener";
4737
+ const transformingClassName = this.wrapClassName("transforming");
4738
+ let $trackMask;
4739
+ let trackStartX = 0;
4740
+ let trackStartY = 0;
4741
+ let trackStartWidth = 0;
4742
+ let trackStartHeight = 0;
4743
+ let trackStartPageX = 0;
4744
+ let trackStartPageY = 0;
4745
+ let trackingHandle;
4746
+ const handleTracking = (ev) => {
4747
+ if (!ev.isPrimary || this.state !== TELE_BOX_STATE.Normal) {
4354
4748
  return;
4355
- k$1(e3);
4356
- let { pageX: t3, pageY: i3 } = R$3(e3);
4357
- i3 < this.rootRect.y && (i3 = this.rootRect.y);
4358
- const s3 = t3 - l2, c2 = i3 - d2;
4359
- let { x: m3, y: u3 } = this.pxIntrinsicCoord, { width: g2, height: p2 } = this.pxIntrinsicSize;
4360
- switch (a2) {
4361
- case N$3.North:
4362
- u3 = o2 + c2, p2 = h - c2;
4749
+ }
4750
+ preventEvent$1(ev);
4751
+ let { pageX, pageY } = ev;
4752
+ if (pageY < 0) {
4753
+ pageY = 0;
4754
+ }
4755
+ const offsetX = pageX - trackStartPageX;
4756
+ const offsetY = pageY - trackStartPageY;
4757
+ let { x: newX, y: newY } = this.pxIntrinsicCoord;
4758
+ let { width: newWidth, height: newHeight } = this.pxIntrinsicSize;
4759
+ switch (trackingHandle) {
4760
+ case TELE_BOX_RESIZE_HANDLE.North: {
4761
+ newY = trackStartY + offsetY;
4762
+ newHeight = trackStartHeight - offsetY;
4363
4763
  break;
4364
- case N$3.South:
4365
- p2 = h + c2;
4764
+ }
4765
+ case TELE_BOX_RESIZE_HANDLE.South: {
4766
+ newHeight = trackStartHeight + offsetY;
4366
4767
  break;
4367
- case N$3.West:
4368
- m3 = n2 + s3, g2 = r2 - s3;
4768
+ }
4769
+ case TELE_BOX_RESIZE_HANDLE.West: {
4770
+ newX = trackStartX + offsetX;
4771
+ newWidth = trackStartWidth - offsetX;
4369
4772
  break;
4370
- case N$3.East:
4371
- g2 = r2 + s3;
4773
+ }
4774
+ case TELE_BOX_RESIZE_HANDLE.East: {
4775
+ newWidth = trackStartWidth + offsetX;
4372
4776
  break;
4373
- case N$3.NorthWest:
4374
- m3 = n2 + s3, u3 = o2 + c2, g2 = r2 - s3, p2 = h - c2;
4777
+ }
4778
+ case TELE_BOX_RESIZE_HANDLE.NorthWest: {
4779
+ newX = trackStartX + offsetX;
4780
+ newY = trackStartY + offsetY;
4781
+ newWidth = trackStartWidth - offsetX;
4782
+ newHeight = trackStartHeight - offsetY;
4375
4783
  break;
4376
- case N$3.NorthEast:
4377
- u3 = o2 + c2, g2 = r2 + s3, p2 = h - c2;
4784
+ }
4785
+ case TELE_BOX_RESIZE_HANDLE.NorthEast: {
4786
+ newY = trackStartY + offsetY;
4787
+ newWidth = trackStartWidth + offsetX;
4788
+ newHeight = trackStartHeight - offsetY;
4378
4789
  break;
4379
- case N$3.SouthEast:
4380
- g2 = r2 + s3, p2 = h + c2;
4790
+ }
4791
+ case TELE_BOX_RESIZE_HANDLE.SouthEast: {
4792
+ newWidth = trackStartWidth + offsetX;
4793
+ newHeight = trackStartHeight + offsetY;
4381
4794
  break;
4382
- case N$3.SouthWest:
4383
- m3 = n2 + s3, g2 = r2 - s3, p2 = h + c2;
4795
+ }
4796
+ case TELE_BOX_RESIZE_HANDLE.SouthWest: {
4797
+ newX = trackStartX + offsetX;
4798
+ newWidth = trackStartWidth - offsetX;
4799
+ newHeight = trackStartHeight + offsetY;
4384
4800
  break;
4385
- default:
4386
- return void this.move(n2 + s3, o2 + c2);
4387
- }
4388
- this.transform(m3, u3, g2, p2);
4389
- }, m2 = (e3) => {
4390
- a2 = void 0, s2 && (k$1(e3), this.$box.classList.toggle(i2, false), this._sideEffect.flush(t2), s2.remove());
4391
- }, u2 = (e3) => {
4392
- var u3;
4393
- if (this.readonly)
4801
+ }
4802
+ default: {
4803
+ this.move(trackStartX + offsetX, trackStartY + offsetY);
4804
+ return;
4805
+ }
4806
+ }
4807
+ this.transform(newX, newY, newWidth, newHeight);
4808
+ };
4809
+ const handleTrackEnd = (ev) => {
4810
+ if (!ev.isPrimary) {
4394
4811
  return;
4395
- if (e3.button != null && e3.button !== 0)
4812
+ }
4813
+ trackingHandle = void 0;
4814
+ if (!$trackMask) {
4396
4815
  return;
4397
- if (!this.draggable || a2 || this.state !== C$3.Normal)
4816
+ }
4817
+ preventEvent$1(ev);
4818
+ this.$box.classList.toggle(transformingClassName, false);
4819
+ this._sideEffect.flush(TRACKING_DISPOSER_ID);
4820
+ $trackMask.remove();
4821
+ };
4822
+ const handleTrackStart = (ev) => {
4823
+ var _a;
4824
+ if (!ev.isPrimary || this.readonly) {
4825
+ return;
4826
+ }
4827
+ if (ev.button != null && ev.button !== 0) {
4828
+ return;
4829
+ }
4830
+ if (!this.draggable || trackingHandle || this.state !== TELE_BOX_STATE.Normal) {
4398
4831
  return;
4399
- const g2 = e3.target;
4400
- if ((u3 = g2.dataset) == null ? void 0 : u3.teleBoxHandle) {
4401
- k$1(e3), { x: n2, y: o2 } = this.pxIntrinsicCoord, { width: r2, height: h } = this.pxIntrinsicSize, { pageX: l2, pageY: d2 } = R$3(e3), a2 = g2.dataset.teleBoxHandle, s2 || (s2 = document.createElement("div"));
4402
- const u4 = a2 ? this.wrapClassName(`cursor-${a2}`) : "";
4403
- s2.className = this.wrapClassName("track-mask" + (u4 ? ` ${u4}` : "")), this.$box.appendChild(s2), this.$box.classList.add(i2), this._sideEffect.add(() => (window.addEventListener("mousemove", c), window.addEventListener("touchmove", c, { passive: false }), window.addEventListener("mouseup", m2), window.addEventListener("touchend", m2, { passive: false }), window.addEventListener("touchcancel", m2, { passive: false }), () => {
4404
- window.removeEventListener("mousemove", c), window.removeEventListener("touchmove", c), window.removeEventListener("mouseup", m2), window.removeEventListener("touchend", m2), window.removeEventListener("touchcancel", m2);
4405
- }), t2);
4832
+ }
4833
+ const target = ev.target;
4834
+ if ((_a = target.dataset) == null ? void 0 : _a.teleBoxHandle) {
4835
+ preventEvent$1(ev);
4836
+ ({ x: trackStartX, y: trackStartY } = this.pxIntrinsicCoord);
4837
+ ({ width: trackStartWidth, height: trackStartHeight } = this.pxIntrinsicSize);
4838
+ ({ pageX: trackStartPageX, pageY: trackStartPageY } = ev);
4839
+ trackingHandle = target.dataset.teleBoxHandle;
4840
+ if (!$trackMask) {
4841
+ $trackMask = document.createElement("div");
4842
+ }
4843
+ const cursor = trackingHandle ? this.wrapClassName(`cursor-${trackingHandle}`) : "";
4844
+ $trackMask.className = this.wrapClassName(`track-mask${cursor ? ` ${cursor}` : ""}`);
4845
+ this.$box.appendChild($trackMask);
4846
+ this.$box.classList.add(transformingClassName);
4847
+ this._sideEffect.add(() => {
4848
+ window.addEventListener("pointermove", handleTracking, {
4849
+ passive: false
4850
+ });
4851
+ window.addEventListener("pointerup", handleTrackEnd, {
4852
+ passive: false
4853
+ });
4854
+ window.addEventListener("pointercancel", handleTrackEnd, {
4855
+ passive: false
4856
+ });
4857
+ return () => {
4858
+ window.removeEventListener("pointermove", handleTracking);
4859
+ window.removeEventListener("pointerup", handleTrackEnd);
4860
+ window.removeEventListener("pointercancel", handleTrackEnd);
4861
+ };
4862
+ }, TRACKING_DISPOSER_ID);
4406
4863
  }
4407
4864
  };
4408
- this._handleTrackStart = u2, this._sideEffect.addEventListener(e2, "mousedown", u2, {}, "box-resizeHandles-mousedown"), this._sideEffect.addEventListener(e2, "touchstart", u2, { passive: false }, "box-resizeHandles-touchstart");
4865
+ this._handleTrackStart = handleTrackStart;
4866
+ this._sideEffect.addEventListener($resizeHandles, "pointerdown", handleTrackStart, {}, "box-resizeHandles-pointerdown");
4409
4867
  }
4410
4868
  async destroy() {
4411
- this.$box.remove(), this._sideEffect.flushAll(), this._sideEffect.flushAll(), await this.events.emit(E$3.Destroyed), this.events.clearListeners(), this._delegateEvents.clearListeners();
4412
- }
4413
- wrapClassName(e2) {
4414
- return `${this.namespace}-${e2}`;
4415
- }
4416
- }
4417
- var X$3, P$3;
4418
- class O$3 {
4419
- constructor({ minimized$: e2, readonly$: t2, darkMode$: i2, namespace: s2 = "telebox", styles: a2 = {}, root$: n2 }) {
4420
- this._sideEffect = new SideEffectManager(), this.namespace = s2;
4421
- const o2 = new ValManager();
4422
- this._sideEffect.addDisposer(() => o2.destroy());
4423
- const r2 = new Val(void 0), h = derive(e2), l2 = new Val(a2), d2 = new Val(document.createElement("button"));
4424
- withValueEnhancer(this, { styles: l2, $collector: d2 }, o2);
4425
- withReadonlyValueEnhancer(this, { root: n2 });
4426
- withReadonlyValueEnhancer(this, { rect: r2, visible: h }, o2), d2.value.className = this.wrapClassName("collector"), d2.value.style.backgroundImage = "url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxOCAxNiI+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxwYXRoIHN0cm9rZT0iIzdCODhBMCIgc3Ryb2tlLXdpZHRoPSIxLjQiIGQ9Ik0uNyAxLjJoMTYuNnYxMy42SC43eiIgLz4KICAgICAgICA8cGF0aCBmaWxsPSIjN0I4OEEwIiBkPSJNNCA1LjVoNnYxLjRINHpNNCA5LjVoMTB2MS40SDR6IiAvPgogICAgPC9nPgo8L3N2Zz4K')", this._sideEffect.addDisposer(d2.subscribe((s3) => {
4427
- this._sideEffect.addEventListener(s3, "click", () => {
4428
- t2.value || e2.setValue(false);
4429
- }, {}, "telebox-collector-click"), this._sideEffect.addDisposer([h.subscribe((e3) => {
4430
- s3.classList.toggle(this.wrapClassName("collector-visible"), e3);
4431
- }), t2.subscribe((e3) => {
4432
- s3.classList.toggle(this.wrapClassName("collector-readonly"), e3);
4433
- }), i2.subscribe((e3) => {
4434
- s3.classList.toggle(this.wrapClassName("color-scheme-dark"), e3), s3.classList.toggle(this.wrapClassName("color-scheme-light"), !e3);
4435
- }), l2.subscribe((e3) => {
4436
- Object.keys(e3).forEach((t3) => {
4437
- const i3 = e3[t3];
4438
- i3 != null && (s3.style[t3] = i3);
4439
- });
4440
- }), n2.subscribe((e3) => {
4441
- e3 && e3.appendChild(s3);
4442
- }), combine([e2, n2]).subscribe(([e3, t3]) => {
4443
- if (e3 && t3) {
4444
- const { x: e4, y: i3, width: a3, height: n3 } = s3.getBoundingClientRect(), o3 = t3.getBoundingClientRect();
4445
- r2.setValue({ x: e4 - o3.x, y: i3 - o3.y, width: a3, height: n3 });
4446
- }
4447
- })], "telebox-collector-el");
4869
+ this.$box.remove();
4870
+ this._sideEffect.flushAll();
4871
+ this._sideEffect.flushAll();
4872
+ await this.events.emit(TELE_BOX_EVENT.Destroyed);
4873
+ this.events.clearListeners();
4874
+ this._delegateEvents.clearListeners();
4875
+ }
4876
+ wrapClassName(className) {
4877
+ return `${this.namespace}-${className}`;
4878
+ }
4879
+ }
4880
+ var collectorSVG = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxOCAxNiI+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxwYXRoIHN0cm9rZT0iIzdCODhBMCIgc3Ryb2tlLXdpZHRoPSIxLjQiIGQ9Ik0uNyAxLjJoMTYuNnYxMy42SC43eiIgLz4KICAgICAgICA8cGF0aCBmaWxsPSIjN0I4OEEwIiBkPSJNNCA1LjVoNnYxLjRINHpNNCA5LjVoMTB2MS40SDR6IiAvPgogICAgPC9nPgo8L3N2Zz4K";
4881
+ class TeleBoxCollector {
4882
+ constructor({
4883
+ minimized$,
4884
+ readonly$,
4885
+ darkMode$,
4886
+ namespace = "telebox",
4887
+ styles: styles2 = {},
4888
+ root$
4889
+ }) {
4890
+ this._sideEffect = new SideEffectManager();
4891
+ this.namespace = namespace;
4892
+ const valManager = new ValManager();
4893
+ this._sideEffect.addDisposer(() => valManager.destroy());
4894
+ const rect$ = new Val(void 0);
4895
+ const visible$ = derive(minimized$);
4896
+ const styles$ = new Val(styles2);
4897
+ const el$ = new Val(document.createElement("button"));
4898
+ const valConfig = {
4899
+ styles: styles$,
4900
+ $collector: el$
4901
+ };
4902
+ withValueEnhancer(this, valConfig, valManager);
4903
+ const propsValConfig = {
4904
+ root: root$
4905
+ };
4906
+ withReadonlyValueEnhancer(this, propsValConfig);
4907
+ const myReadonlyValConfig = {
4908
+ rect: rect$,
4909
+ visible: visible$
4910
+ };
4911
+ withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
4912
+ el$.value.className = this.wrapClassName("collector");
4913
+ el$.value.style.backgroundImage = `url('${collectorSVG}')`;
4914
+ this._sideEffect.addDisposer(el$.subscribe(($collector) => {
4915
+ this._sideEffect.addEventListener($collector, "pointerup", (ev) => {
4916
+ if (ev.isPrimary && !readonly$.value) {
4917
+ minimized$.setValue(false);
4918
+ }
4919
+ }, {}, "telebox-collector-click");
4920
+ this._sideEffect.addDisposer([
4921
+ visible$.subscribe((visible) => {
4922
+ $collector.classList.toggle(this.wrapClassName("collector-visible"), visible);
4923
+ }),
4924
+ readonly$.subscribe((readonly) => {
4925
+ $collector.classList.toggle(this.wrapClassName("collector-readonly"), readonly);
4926
+ }),
4927
+ darkMode$.subscribe((darkMode) => {
4928
+ $collector.classList.toggle(this.wrapClassName("color-scheme-dark"), darkMode);
4929
+ $collector.classList.toggle(this.wrapClassName("color-scheme-light"), !darkMode);
4930
+ }),
4931
+ styles$.subscribe((styles22) => {
4932
+ Object.keys(styles22).forEach((key) => {
4933
+ const value = styles22[key];
4934
+ if (value != null) {
4935
+ $collector.style[key] = value;
4936
+ }
4937
+ });
4938
+ }),
4939
+ root$.subscribe((root) => {
4940
+ if (root) {
4941
+ root.appendChild($collector);
4942
+ }
4943
+ }),
4944
+ combine([minimized$, root$]).subscribe(([minimized, root]) => {
4945
+ if (minimized && root) {
4946
+ const { x: x2, y: y2, width, height } = $collector.getBoundingClientRect();
4947
+ const rootRect = root.getBoundingClientRect();
4948
+ rect$.setValue({
4949
+ x: x2 - rootRect.x,
4950
+ y: y2 - rootRect.y,
4951
+ width,
4952
+ height
4953
+ });
4954
+ }
4955
+ })
4956
+ ], "telebox-collector-el");
4448
4957
  }));
4449
4958
  }
4450
4959
  destroy() {
4451
4960
  this._sideEffect.flushAll();
4452
4961
  }
4453
- wrapClassName(e2) {
4454
- return `${this.namespace}-${e2}`;
4962
+ wrapClassName(className) {
4963
+ return `${this.namespace}-${className}`;
4455
4964
  }
4456
4965
  }
4457
- (P$3 = X$3 || (X$3 = {})).Focused = "focused", P$3.Blurred = "blurred", P$3.Created = "created", P$3.Removed = "removed", P$3.State = "state", P$3.Maximized = "maximized", P$3.Minimized = "minimized", P$3.IntrinsicMove = "intrinsic_move", P$3.IntrinsicResize = "intrinsic_resize", P$3.ZIndex = "z_index", P$3.PrefersColorScheme = "prefers_color_scheme", P$3.DarkMode = "dark_mode";
4458
- class j$1 extends H$3 {
4459
- constructor(e2) {
4460
- super(e2), this.boxes$ = e2.boxes$, this.rootRect$ = e2.rootRect$, this.darkMode$ = e2.darkMode$, this.sideEffect.addDisposer(e2.root$.subscribe((e3) => {
4461
- var t2;
4462
- e3 ? e3.appendChild(this.render()) : ((t2 = this.$titleBar) == null ? void 0 : t2.parentNode) && this.$titleBar.remove();
4463
- }));
4966
+ var TELE_BOX_MANAGER_EVENT = /* @__PURE__ */ ((TELE_BOX_MANAGER_EVENT2) => {
4967
+ TELE_BOX_MANAGER_EVENT2["Focused"] = "focused";
4968
+ TELE_BOX_MANAGER_EVENT2["Blurred"] = "blurred";
4969
+ TELE_BOX_MANAGER_EVENT2["Created"] = "created";
4970
+ TELE_BOX_MANAGER_EVENT2["Removed"] = "removed";
4971
+ TELE_BOX_MANAGER_EVENT2["State"] = "state";
4972
+ TELE_BOX_MANAGER_EVENT2["Maximized"] = "maximized";
4973
+ TELE_BOX_MANAGER_EVENT2["Minimized"] = "minimized";
4974
+ TELE_BOX_MANAGER_EVENT2["IntrinsicMove"] = "intrinsic_move";
4975
+ TELE_BOX_MANAGER_EVENT2["IntrinsicResize"] = "intrinsic_resize";
4976
+ TELE_BOX_MANAGER_EVENT2["ZIndex"] = "z_index";
4977
+ TELE_BOX_MANAGER_EVENT2["PrefersColorScheme"] = "prefers_color_scheme";
4978
+ TELE_BOX_MANAGER_EVENT2["DarkMode"] = "dark_mode";
4979
+ return TELE_BOX_MANAGER_EVENT2;
4980
+ })(TELE_BOX_MANAGER_EVENT || {});
4981
+ class MaxTitleBar extends DefaultTitleBar {
4982
+ constructor(config) {
4983
+ super(config);
4984
+ this.boxes$ = config.boxes$;
4985
+ this.rootRect$ = config.rootRect$;
4986
+ this.darkMode$ = config.darkMode$;
4987
+ config.root.appendChild(this.render());
4464
4988
  }
4465
- focusBox(e2) {
4466
- var t2;
4467
- if (!this.focusedBox || this.focusedBox !== e2) {
4468
- if (this.$titles && this.state$.value === C$3.Maximized) {
4469
- const { children: i2 } = this.$titles.firstElementChild;
4470
- for (let s2 = i2.length - 1; s2 >= 0; s2 -= 1) {
4471
- const a2 = i2[s2], n2 = (t2 = a2.dataset) == null ? void 0 : t2.teleBoxID;
4472
- n2 && (e2 && n2 === e2.id ? a2.classList.toggle(this.wrapClassName("titles-tab-focus"), true) : this.focusedBox && n2 === this.focusedBox.id && a2.classList.toggle(this.wrapClassName("titles-tab-focus"), false));
4989
+ focusBox(box) {
4990
+ var _a;
4991
+ if (this.focusedBox && this.focusedBox === box) {
4992
+ return;
4993
+ }
4994
+ if (this.$titles && this.state$.value === TELE_BOX_STATE.Maximized) {
4995
+ const { children: children2 } = this.$titles.firstElementChild;
4996
+ for (let i2 = children2.length - 1; i2 >= 0; i2 -= 1) {
4997
+ const $tab = children2[i2];
4998
+ const id2 = (_a = $tab.dataset) == null ? void 0 : _a.teleBoxID;
4999
+ if (id2) {
5000
+ if (box && id2 === box.id) {
5001
+ $tab.classList.toggle(this.wrapClassName("titles-tab-focus"), true);
5002
+ } else if (this.focusedBox && id2 === this.focusedBox.id) {
5003
+ $tab.classList.toggle(this.wrapClassName("titles-tab-focus"), false);
5004
+ }
4473
5005
  }
4474
5006
  }
4475
- this.focusedBox = e2;
4476
5007
  }
5008
+ this.focusedBox = box;
4477
5009
  }
4478
5010
  render() {
4479
- if (this.$titleBar)
5011
+ if (this.$titleBar) {
4480
5012
  return this.$titleBar;
4481
- const e2 = super.render();
4482
- e2.classList.add(this.wrapClassName("max-titlebar")), this.sideEffect.addDisposer([this.state$.subscribe((t3) => {
4483
- e2.classList.toggle(this.wrapClassName("max-titlebar-maximized"), t3 === C$3.Maximized);
4484
- }), this.readonly$.subscribe((t3) => {
4485
- e2.classList.toggle(this.wrapClassName("readonly"), t3);
4486
- }), this.darkMode$.subscribe((t3) => {
4487
- e2.classList.toggle(this.wrapClassName("color-scheme-dark"), t3), e2.classList.toggle(this.wrapClassName("color-scheme-light"), !t3);
4488
- }), combine([this.state$, this.boxes$]).subscribe(([t3, i2]) => {
4489
- t3 === C$3.Maximized && (e2.classList.toggle(this.wrapClassName("max-titlebar-single-title"), i2.length === 1), i2.length !== 1 && e2.replaceChild(this.renderTitles(), e2.firstElementChild));
4490
- })], "max-render");
4491
- const t2 = document.createElement("div");
4492
- return t2.classList.add(this.wrapClassName("titles-area")), e2.insertBefore(t2, e2.firstElementChild), e2;
5013
+ }
5014
+ const $titleBar = super.render();
5015
+ $titleBar.classList.add(this.wrapClassName("max-titlebar"));
5016
+ this.sideEffect.addDisposer([
5017
+ this.state$.subscribe((state) => {
5018
+ $titleBar.classList.toggle(this.wrapClassName("max-titlebar-maximized"), state === TELE_BOX_STATE.Maximized);
5019
+ }),
5020
+ this.readonly$.subscribe((readonly) => {
5021
+ $titleBar.classList.toggle(this.wrapClassName("readonly"), readonly);
5022
+ }),
5023
+ combine([this.state$, this.boxes$]).subscribe(([state, titles]) => {
5024
+ if (state === TELE_BOX_STATE.Maximized) {
5025
+ $titleBar.classList.toggle(this.wrapClassName("max-titlebar-single-title"), titles.length === 1);
5026
+ if (titles.length !== 1) {
5027
+ $titleBar.replaceChild(this.renderTitles(), $titleBar.firstElementChild);
5028
+ }
5029
+ }
5030
+ })
5031
+ ], "max-render");
5032
+ const $titlesArea = document.createElement("div");
5033
+ $titlesArea.classList.add(this.wrapClassName("titles-area"));
5034
+ $titleBar.insertBefore($titlesArea, $titleBar.firstElementChild);
5035
+ return $titleBar;
4493
5036
  }
4494
5037
  destroy() {
4495
- super.destroy(), this.$titles = void 0, this.focusedBox = void 0;
5038
+ super.destroy();
5039
+ this.$titles = void 0;
5040
+ this.focusedBox = void 0;
4496
5041
  }
4497
5042
  renderTitles() {
4498
- this.$titles = document.createElement("div"), this.$titles.className = this.wrapClassName("titles"), this.sideEffect.addEventListener(this.$titles, "wheel", (e3) => {
4499
- e3.currentTarget.scrollBy({ left: e3.deltaY > 0 ? 250 : -250, behavior: "smooth" });
5043
+ this.$titles = document.createElement("div");
5044
+ this.$titles.className = this.wrapClassName("titles");
5045
+ this.sideEffect.addEventListener(this.$titles, "wheel", (ev) => {
5046
+ ev.currentTarget.scrollBy({
5047
+ left: ev.deltaY > 0 ? 250 : -250,
5048
+ behavior: "smooth"
5049
+ });
4500
5050
  }, { passive: false }, "max-render-wheel-titles");
4501
- const e2 = document.createElement("div");
4502
- e2.className = this.wrapClassName("titles-content"), this.$titles.appendChild(e2);
4503
- const t2 = this.boxes$.value.map((t3) => {
4504
- const i2 = document.createElement("button");
4505
- return i2.className = this.wrapClassName("titles-tab"), i2.textContent = t3.title, i2.dataset.teleBoxID = t3.id, i2.dataset.teleTitleBarNoDblClick = "true", this.focusedBox && t3.id === this.focusedBox.id && i2.classList.add(this.wrapClassName("titles-tab-focus")), e2.appendChild(i2), t3._title$.reaction((e3) => i2.textContent = e3);
5051
+ const $content = document.createElement("div");
5052
+ $content.className = this.wrapClassName("titles-content");
5053
+ this.$titles.appendChild($content);
5054
+ const disposers = this.boxes$.value.map((box) => {
5055
+ const $tab = document.createElement("button");
5056
+ $tab.className = this.wrapClassName("titles-tab");
5057
+ $tab.textContent = box.title;
5058
+ $tab.dataset.teleBoxID = box.id;
5059
+ $tab.dataset.teleTitleBarNoDblClick = "true";
5060
+ if (this.focusedBox && box.id === this.focusedBox.id) {
5061
+ $tab.classList.add(this.wrapClassName("titles-tab-focus"));
5062
+ }
5063
+ $content.appendChild($tab);
5064
+ return box._title$.reaction((title) => $tab.textContent = title);
4506
5065
  });
4507
- return this.sideEffect.addDisposer(() => t2.forEach((e3) => e3()), "max-render-tab-titles"), this.$titles;
5066
+ this.sideEffect.addDisposer(() => disposers.forEach((disposer) => disposer()), "max-render-tab-titles");
5067
+ return this.$titles;
4508
5068
  }
4509
5069
  }
4510
- const Z$3 = window.ResizeObserver || ResizeObserver$2;
4511
- class F$3 {
4512
- constructor({ root: e2 = null, prefersColorScheme: t2 = v$3.Light, minimized: i2 = false, maximized: s2 = false, fence: a2 = false, collector: n2, namespace: o2 = "telebox", readonly: r2 = false, stageRatio: l2 = -1, highlightStage: m2 = true } = {}) {
4513
- this.events = new Emittery(), this._sideEffect = new SideEffectManager(), this.namespace = o2;
4514
- const b2 = new ValManager();
4515
- this._sideEffect.addDisposer(() => b2.destroy());
4516
- const w2 = new Val(e2), y2 = new Val(r2), z2 = new Val(i2), B2 = new Val(s2), N2 = new Val(a2), S2 = new Val(l2), M2 = new Val(m2), I2 = new Val({ x: 0, y: 0, width: window.innerWidth, height: window.innerHeight }, { compare: shallowequal });
4517
- this._sideEffect.addDisposer(w2.subscribe((e3) => {
5070
+ const ResizeObserver$2 = window.ResizeObserver || ResizeObserver$3;
5071
+ class TeleBoxManager {
5072
+ constructor({
5073
+ root = null,
5074
+ prefersColorScheme = TELE_BOX_COLOR_SCHEME.Light,
5075
+ minimized = false,
5076
+ maximized = false,
5077
+ fence = true,
5078
+ collector,
5079
+ namespace = "telebox",
5080
+ readonly = false,
5081
+ stageRatio = -1,
5082
+ containerStyle = "",
5083
+ stageStyle = "",
5084
+ defaultBoxBodyStyle = null,
5085
+ defaultBoxStageStyle = null
5086
+ } = {}) {
5087
+ this.events = new Emittery();
5088
+ this._sideEffect = new SideEffectManager();
5089
+ this.namespace = namespace;
5090
+ const valManager = new ValManager();
5091
+ this._sideEffect.addDisposer(() => valManager.destroy());
5092
+ const root$ = new Val(root);
5093
+ const readonly$ = new Val(readonly);
5094
+ const minimized$ = new Val(minimized);
5095
+ const maximized$ = new Val(maximized);
5096
+ const fence$ = new Val(fence);
5097
+ const containerStyle$ = new Val(containerStyle);
5098
+ const stageStyle$ = new Val(stageStyle);
5099
+ const stageRatio$ = new Val(stageRatio);
5100
+ const defaultBoxBodyStyle$ = new Val(defaultBoxBodyStyle);
5101
+ const defaultBoxStageStyle$ = new Val(defaultBoxStageStyle);
5102
+ const rootRect$ = new Val({
5103
+ x: 0,
5104
+ y: 0,
5105
+ width: window.innerWidth,
5106
+ height: window.innerHeight
5107
+ }, { compare: shallowequal });
5108
+ this._sideEffect.addDisposer(root$.subscribe((root2) => {
4518
5109
  this._sideEffect.add(() => {
4519
- if (!e3)
4520
- return () => {
4521
- };
4522
- const t3 = new Z$3(() => {
4523
- const t4 = e3.getBoundingClientRect();
4524
- I2.setValue({ x: 0, y: 0, width: t4.width, height: t4.height });
5110
+ if (!root2) {
5111
+ return () => void 0;
5112
+ }
5113
+ const observer = new ResizeObserver$2(() => {
5114
+ const rect = root2.getBoundingClientRect();
5115
+ rootRect$.setValue({
5116
+ x: 0,
5117
+ y: 0,
5118
+ width: rect.width,
5119
+ height: rect.height
5120
+ });
4525
5121
  });
4526
- return t3.observe(e3), () => t3.disconnect();
5122
+ observer.observe(root2);
5123
+ return () => observer.disconnect();
4527
5124
  }, "calc-root-rect");
4528
- })), this.boxes$ = new Val([]), this.topBox$ = new Val(void 0), this._sideEffect.addDisposer(this.boxes$.subscribe((e3) => {
4529
- if (e3.length > 0) {
4530
- const t3 = e3.reduce((e4, t4) => e4.zIndex > t4.zIndex ? e4 : t4);
4531
- this.topBox$.setValue(t3);
4532
- } else
4533
- this.topBox$.setValue(void 0);
4534
5125
  }));
4535
- const k2 = window.matchMedia("(prefers-color-scheme: dark)"), R2 = new Val(false);
4536
- k2 && (R2.setValue(k2.matches), this._sideEffect.add(() => {
4537
- const e3 = (e4) => {
4538
- R2.setValue(e4.matches);
4539
- };
4540
- return k2.addEventListener("change", e3), () => k2.removeEventListener("change", e3);
5126
+ const stageRect$ = combine([rootRect$, stageRatio$], calcStageRect, {
5127
+ compare: shallowequal
5128
+ });
5129
+ this.boxes$ = new Val([]);
5130
+ this.topBox$ = new Val(void 0);
5131
+ this._sideEffect.addDisposer(this.boxes$.subscribe((boxes) => {
5132
+ if (boxes.length > 0) {
5133
+ const topBox = boxes.reduce((topBox2, box) => topBox2.zIndex > box.zIndex ? topBox2 : box);
5134
+ this.topBox$.setValue(topBox);
5135
+ } else {
5136
+ this.topBox$.setValue(void 0);
5137
+ }
4541
5138
  }));
4542
- const D2 = new Val(t2);
4543
- this._sideEffect.addDisposer(D2.reaction((e3, t3) => {
4544
- t3 || this.events.emit(X$3.PrefersColorScheme, e3);
5139
+ const prefersDarkMatch = window.matchMedia("(prefers-color-scheme: dark)");
5140
+ const prefersDark$ = new Val(false);
5141
+ if (prefersDarkMatch) {
5142
+ prefersDark$.setValue(prefersDarkMatch.matches);
5143
+ this._sideEffect.add(() => {
5144
+ const handler = (evt) => {
5145
+ prefersDark$.setValue(evt.matches);
5146
+ };
5147
+ prefersDarkMatch.addEventListener("change", handler);
5148
+ return () => prefersDarkMatch.removeEventListener("change", handler);
5149
+ });
5150
+ }
5151
+ const prefersColorScheme$ = new Val(prefersColorScheme);
5152
+ this._sideEffect.addDisposer(prefersColorScheme$.reaction((prefersColorScheme2, skipUpdate) => {
5153
+ if (!skipUpdate) {
5154
+ this.events.emit(TELE_BOX_MANAGER_EVENT.PrefersColorScheme, prefersColorScheme2);
5155
+ }
4545
5156
  }));
4546
- const L2 = combine([R2, D2], ([e3, t3]) => t3 === "auto" ? e3 : t3 === "dark"), T2 = combine([z2, B2], ([e3, t3]) => e3 ? C$3.Minimized : t3 ? C$3.Maximized : C$3.Normal);
4547
- this.collector = n2 != null ? n2 : new O$3({ minimized$: z2, readonly$: y2, darkMode$: L2, namespace: o2, root$: w2 });
4548
- const V2 = new A$2({ namespace: o2, rootRect$: I2, ratio$: S2, root$: w2, highlightStage$: combine([M2, B2, z2], ([e3, t3, i3]) => e3 && (i3 || !t3)) });
4549
- this._sideEffect.addDisposer(() => V2.destroy());
4550
- const H2 = { darkMode: L2, state: T2, root: w2, rootRect: I2, stageRect: V2.stageRect$ };
4551
- withReadonlyValueEnhancer(this, H2, b2);
4552
- withValueEnhancer(this, { prefersColorScheme: D2, readonly: y2, fence: N2, minimized: z2, maximized: B2, stageRatio: S2, highlightStage: M2 }, b2);
4553
- const W2 = this.wrapClassName("titlebar-icon-close"), Y2 = (e3) => {
4554
- var t3;
4555
- if (y2.value)
5157
+ const darkMode$ = combine([prefersDark$, prefersColorScheme$], ([prefersDark, prefersColorScheme2]) => prefersColorScheme2 === "auto" ? prefersDark : prefersColorScheme2 === "dark");
5158
+ const state$ = combine([minimized$, maximized$], ([minimized2, maximized2]) => minimized2 ? TELE_BOX_STATE.Minimized : maximized2 ? TELE_BOX_STATE.Maximized : TELE_BOX_STATE.Normal);
5159
+ this.collector = collector != null ? collector : new TeleBoxCollector({
5160
+ minimized$,
5161
+ readonly$,
5162
+ darkMode$,
5163
+ namespace,
5164
+ root$
5165
+ });
5166
+ const readonlyValConfig = {
5167
+ darkMode: darkMode$,
5168
+ state: state$,
5169
+ root: root$,
5170
+ rootRect: rootRect$,
5171
+ stageRect: stageRect$
5172
+ };
5173
+ withReadonlyValueEnhancer(this, readonlyValConfig, valManager);
5174
+ const valConfig = {
5175
+ prefersColorScheme: prefersColorScheme$,
5176
+ readonly: readonly$,
5177
+ fence: fence$,
5178
+ minimized: minimized$,
5179
+ maximized: maximized$,
5180
+ stageRatio: stageRatio$,
5181
+ containerStyle: containerStyle$,
5182
+ stageStyle: stageStyle$,
5183
+ defaultBoxBodyStyle: defaultBoxBodyStyle$,
5184
+ defaultBoxStageStyle: defaultBoxStageStyle$
5185
+ };
5186
+ withValueEnhancer(this, valConfig, valManager);
5187
+ const closeBtnClassName = this.wrapClassName("titlebar-icon-close");
5188
+ const checkFocusBox = (ev) => {
5189
+ var _a;
5190
+ if (!ev.isPrimary || readonly$.value) {
5191
+ return;
5192
+ }
5193
+ const target = ev.target;
5194
+ if (!target.tagName) {
4556
5195
  return;
4557
- const i3 = e3.target;
4558
- if (i3.tagName)
4559
- for (let s3 = i3; s3; s3 = s3.parentElement) {
4560
- if (s3.classList && s3.classList.contains(W2))
5196
+ }
5197
+ for (let el = target; el; el = el.parentElement) {
5198
+ if (el.classList && el.classList.contains(closeBtnClassName)) {
5199
+ return;
5200
+ }
5201
+ const id2 = (_a = el.dataset) == null ? void 0 : _a.teleBoxID;
5202
+ if (id2) {
5203
+ const box = this.getBox(id2);
5204
+ if (box) {
5205
+ this.focusBox(box);
5206
+ this.makeBoxTop(box);
4561
5207
  return;
4562
- const e4 = (t3 = s3.dataset) == null ? void 0 : t3.teleBoxID;
4563
- if (e4) {
4564
- const t4 = this.getBox(e4);
4565
- if (t4)
4566
- return this.focusBox(t4), void this.makeBoxTop(t4);
4567
5208
  }
4568
5209
  }
5210
+ }
4569
5211
  };
4570
- this._sideEffect.addEventListener(window, "mousedown", Y2, true), this._sideEffect.addEventListener(window, "touchstart", Y2, true), this.titleBar = new j$1({ namespace: this.namespace, title$: derive(this.topBox$, (e3) => (e3 == null ? void 0 : e3.title) || ""), boxes$: this.boxes$, darkMode$: L2, readonly$: y2, state$: T2, root$: w2, rootRect$: I2, onEvent: (e3) => {
4571
- switch (e3.type) {
4572
- case _.Maximize:
4573
- B2.setValue(!B2.value);
4574
- break;
4575
- case _.Minimize:
4576
- z2.setValue(true);
4577
- break;
4578
- case E$3.Close:
4579
- this.removeTopBox(), this.focusTopBox();
4580
- }
4581
- } }), this._sideEffect.addDisposer([T2.reaction((e3, t3) => {
4582
- t3 || this.events.emit(X$3.State, e3);
4583
- }), B2.reaction((e3, t3) => {
4584
- t3 || this.events.emit(X$3.Maximized, e3);
4585
- }), z2.reaction((e3, t3) => {
4586
- t3 || this.events.emit(X$3.Minimized, e3);
4587
- }), L2.reaction((e3, t3) => {
4588
- t3 || this.events.emit(X$3.DarkMode, e3);
4589
- })]);
5212
+ this._sideEffect.addEventListener(window, "pointerdown", checkFocusBox, true);
5213
+ this.$container = document.createElement("div");
5214
+ this.$container.className = this.wrapClassName("manager-container");
5215
+ this.$stage = document.createElement("div");
5216
+ this.$stage.className = this.wrapClassName("manager-stage");
5217
+ this.$container.appendChild(this.$stage);
5218
+ this._sideEffect.addDisposer([
5219
+ darkMode$.subscribe((darkMode) => {
5220
+ this.$container.classList.toggle(this.wrapClassName("color-scheme-dark"), darkMode);
5221
+ this.$container.classList.toggle(this.wrapClassName("color-scheme-light"), !darkMode);
5222
+ }),
5223
+ maximized$.subscribe((maximized2) => {
5224
+ this.$container.classList.toggle("is-maximized", maximized2);
5225
+ }),
5226
+ minimized$.subscribe((minimized2) => {
5227
+ this.$container.classList.toggle("is-minimized", minimized2);
5228
+ }),
5229
+ containerStyle$.subscribe((containerStyle2) => {
5230
+ this.$container.style.cssText = containerStyle2;
5231
+ }),
5232
+ stageStyle$.subscribe((stageStyle2) => {
5233
+ this.$stage.style.cssText = stageStyle2;
5234
+ this.$stage.style.width = stageRect$.value.width + "px";
5235
+ this.$stage.style.height = stageRect$.value.height + "px";
5236
+ }),
5237
+ stageRect$.subscribe((stageRect) => {
5238
+ this.$stage.style.width = stageRect.width + "px";
5239
+ this.$stage.style.height = stageRect.height + "px";
5240
+ }),
5241
+ root$.subscribe((root2) => {
5242
+ if (root2) {
5243
+ root2.appendChild(this.$container);
5244
+ } else if (this.$container.parentElement) {
5245
+ this.$container.remove();
5246
+ }
5247
+ })
5248
+ ]);
5249
+ this.titleBar = new MaxTitleBar({
5250
+ namespace: this.namespace,
5251
+ title$: derive(this.topBox$, (topBox) => (topBox == null ? void 0 : topBox.title) || ""),
5252
+ boxes$: this.boxes$,
5253
+ darkMode$,
5254
+ readonly$,
5255
+ state$,
5256
+ rootRect$,
5257
+ root: this.$container,
5258
+ onEvent: (event) => {
5259
+ switch (event.type) {
5260
+ case TELE_BOX_DELEGATE_EVENT.Maximize: {
5261
+ maximized$.setValue(!maximized$.value);
5262
+ break;
5263
+ }
5264
+ case TELE_BOX_DELEGATE_EVENT.Minimize: {
5265
+ minimized$.setValue(true);
5266
+ break;
5267
+ }
5268
+ case TELE_BOX_EVENT.Close: {
5269
+ this.removeTopBox();
5270
+ this.focusTopBox();
5271
+ break;
5272
+ }
5273
+ }
5274
+ }
5275
+ });
5276
+ this._sideEffect.addDisposer([
5277
+ state$.reaction((state, skipUpdate) => {
5278
+ if (!skipUpdate) {
5279
+ this.events.emit(TELE_BOX_MANAGER_EVENT.State, state);
5280
+ }
5281
+ }),
5282
+ maximized$.reaction((maximized2, skipUpdate) => {
5283
+ if (!skipUpdate) {
5284
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Maximized, maximized2);
5285
+ }
5286
+ }),
5287
+ minimized$.reaction((minimized2, skipUpdate) => {
5288
+ if (!skipUpdate) {
5289
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Minimized, minimized2);
5290
+ }
5291
+ }),
5292
+ darkMode$.reaction((darkMode, skipUpdate) => {
5293
+ if (!skipUpdate) {
5294
+ this.events.emit(TELE_BOX_MANAGER_EVENT.DarkMode, darkMode);
5295
+ }
5296
+ })
5297
+ ]);
4590
5298
  }
4591
5299
  get boxes() {
4592
5300
  return this.boxes$.value;
@@ -4594,143 +5302,300 @@ class F$3 {
4594
5302
  get topBox() {
4595
5303
  return this.topBox$.value;
4596
5304
  }
4597
- setState(e2, t2 = false) {
4598
- switch (e2) {
4599
- case C$3.Maximized:
4600
- this.setMinimized(false, t2), this.setMaximized(true, t2);
5305
+ setState(state, skipUpdate = false) {
5306
+ switch (state) {
5307
+ case TELE_BOX_STATE.Maximized: {
5308
+ this.setMinimized(false, skipUpdate);
5309
+ this.setMaximized(true, skipUpdate);
5310
+ break;
5311
+ }
5312
+ case TELE_BOX_STATE.Minimized: {
5313
+ this.setMinimized(true, skipUpdate);
5314
+ this.setMaximized(false, skipUpdate);
4601
5315
  break;
4602
- case C$3.Minimized:
4603
- this.setMinimized(true, t2), this.setMaximized(false, t2);
5316
+ }
5317
+ default: {
5318
+ this.setMinimized(false, skipUpdate);
5319
+ this.setMaximized(false, skipUpdate);
4604
5320
  break;
4605
- default:
4606
- this.setMinimized(false, t2), this.setMaximized(false, t2);
5321
+ }
4607
5322
  }
4608
5323
  return this;
4609
5324
  }
4610
- create(e2 = {}, s2 = true) {
4611
- const a2 = new Y$3((n2 = r$4(r$4({ zIndex: this.topBox ? this.topBox.zIndex + 1 : 100 }, e2), s2 ? this.smartPosition(e2) : {}), o2 = { namespace: this.namespace, root$: this._root$, darkMode$: this._darkMode$, maximized$: this._maximized$, minimized$: this._minimized$, fence$: this._fence$, rootRect$: this._rootRect$, managerStageRect$: this._stageRect$, managerStageRatio$: this._stageRatio$, readonly$: this._readonly$, collectorRect$: this.collector._rect$, managerHighlightStage$: this._highlightStage$ }, t$3(n2, i$1(o2))));
4612
- var n2, o2;
4613
- return a2.focus && (this.focusBox(a2), s2 && this.makeBoxTop(a2)), this.boxes$.setValue([...this.boxes, a2]), this._sideEffect.addDisposer([a2._delegateEvents.on(_.Maximize, () => {
4614
- this.setMaximized(!this.maximized);
4615
- }), a2._delegateEvents.on(_.Minimize, () => {
4616
- this.setMinimized(true);
4617
- }), a2._delegateEvents.on(_.Close, () => {
4618
- this.remove(a2), this.focusTopBox();
4619
- }), a2._intrinsicCoord$.reaction((e3, t2) => {
4620
- t2 || this.events.emit(X$3.IntrinsicMove, a2);
4621
- }), a2._intrinsicSize$.reaction((e3, t2) => {
4622
- t2 || this.events.emit(X$3.IntrinsicResize, a2);
4623
- }), a2._zIndex$.reaction((e3, t2) => {
4624
- if (this.boxes.length > 0) {
4625
- const e4 = this.boxes.reduce((e5, t3) => e5.zIndex > t3.zIndex ? e5 : t3);
4626
- this.topBox$.setValue(e4);
4627
- }
4628
- t2 || this.events.emit(X$3.ZIndex, a2);
4629
- })]), this.events.emit(X$3.Created, a2), a2;
4630
- }
4631
- query(e2) {
4632
- return e2 ? this.boxes.filter(this.teleBoxMatcher(e2)) : [...this.boxes];
4633
- }
4634
- queryOne(e2) {
4635
- return e2 ? this.boxes.find(this.teleBoxMatcher(e2)) : this.boxes[0];
4636
- }
4637
- update(e2, t2, i2 = false) {
4638
- const s2 = this.boxes.find((t3) => t3.id === e2);
4639
- if (s2)
4640
- return this.updateBox(s2, t2, i2);
5325
+ create(config = {}, smartPosition = true) {
5326
+ const box = new TeleBox(__spreadProps(__spreadValues(__spreadValues({
5327
+ zIndex: this.topBox ? this.topBox.zIndex + 1 : 100
5328
+ }, config), smartPosition ? this.smartPosition(config) : {}), {
5329
+ namespace: this.namespace,
5330
+ root: this.$stage,
5331
+ darkMode$: this._darkMode$,
5332
+ maximized$: this._maximized$,
5333
+ minimized$: this._minimized$,
5334
+ fence$: this._fence$,
5335
+ rootRect$: this._rootRect$,
5336
+ managerStageRect$: this._stageRect$,
5337
+ managerStageRatio$: this._stageRatio$,
5338
+ readonly$: this._readonly$,
5339
+ collectorRect$: this.collector._rect$,
5340
+ defaultBoxBodyStyle$: this._defaultBoxBodyStyle$,
5341
+ defaultBoxStageStyle$: this._defaultBoxStageStyle$
5342
+ }));
5343
+ if (box.focus) {
5344
+ this.focusBox(box);
5345
+ if (smartPosition) {
5346
+ this.makeBoxTop(box);
5347
+ }
5348
+ }
5349
+ this.boxes$.setValue([...this.boxes, box]);
5350
+ this._sideEffect.addDisposer([
5351
+ box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Maximize, () => {
5352
+ this.setMaximized(!this.maximized);
5353
+ }),
5354
+ box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Minimize, () => {
5355
+ this.setMinimized(true);
5356
+ }),
5357
+ box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Close, () => {
5358
+ this.remove(box);
5359
+ this.focusTopBox();
5360
+ }),
5361
+ box._intrinsicCoord$.reaction((_, skipUpdate) => {
5362
+ if (!skipUpdate) {
5363
+ this.events.emit(TELE_BOX_MANAGER_EVENT.IntrinsicMove, box);
5364
+ }
5365
+ }),
5366
+ box._intrinsicSize$.reaction((_, skipUpdate) => {
5367
+ if (!skipUpdate) {
5368
+ this.events.emit(TELE_BOX_MANAGER_EVENT.IntrinsicResize, box);
5369
+ }
5370
+ }),
5371
+ box._zIndex$.reaction((_, skipUpdate) => {
5372
+ if (this.boxes.length > 0) {
5373
+ const topBox = this.boxes.reduce((topBox2, box2) => topBox2.zIndex > box2.zIndex ? topBox2 : box2);
5374
+ this.topBox$.setValue(topBox);
5375
+ }
5376
+ if (!skipUpdate) {
5377
+ this.events.emit(TELE_BOX_MANAGER_EVENT.ZIndex, box);
5378
+ }
5379
+ })
5380
+ ]);
5381
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Created, box);
5382
+ return box;
5383
+ }
5384
+ query(config) {
5385
+ return config ? this.boxes.filter(this.teleBoxMatcher(config)) : [...this.boxes];
5386
+ }
5387
+ queryOne(config) {
5388
+ return config ? this.boxes.find(this.teleBoxMatcher(config)) : this.boxes[0];
4641
5389
  }
4642
- updateAll(e2, t2 = false) {
4643
- this.boxes.forEach((i2) => {
4644
- this.updateBox(i2, e2, t2);
5390
+ update(boxID, config, skipUpdate = false) {
5391
+ const box = this.boxes.find((box2) => box2.id === boxID);
5392
+ if (box) {
5393
+ return this.updateBox(box, config, skipUpdate);
5394
+ }
5395
+ }
5396
+ updateAll(config, skipUpdate = false) {
5397
+ this.boxes.forEach((box) => {
5398
+ this.updateBox(box, config, skipUpdate);
4645
5399
  });
4646
5400
  }
4647
- remove(e2, t2 = false) {
4648
- const i2 = this.getBoxIndex(e2);
4649
- if (i2 >= 0) {
4650
- const e3 = this.boxes.slice(), s2 = e3.splice(i2, 1);
4651
- return this.boxes$.setValue(e3), s2.forEach((e4) => e4.destroy()), t2 || (this.boxes.length <= 0 && (this.setMaximized(false), this.setMinimized(false)), this.events.emit(X$3.Removed, s2)), s2[0];
5401
+ remove(boxOrID, skipUpdate = false) {
5402
+ const index2 = this.getBoxIndex(boxOrID);
5403
+ if (index2 >= 0) {
5404
+ const boxes = this.boxes.slice();
5405
+ const deletedBoxes = boxes.splice(index2, 1);
5406
+ this.boxes$.setValue(boxes);
5407
+ deletedBoxes.forEach((box) => box.destroy());
5408
+ if (!skipUpdate) {
5409
+ if (this.boxes.length <= 0) {
5410
+ this.setMaximized(false);
5411
+ this.setMinimized(false);
5412
+ }
5413
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Removed, deletedBoxes);
5414
+ }
5415
+ return deletedBoxes[0];
4652
5416
  }
5417
+ return;
4653
5418
  }
4654
5419
  removeTopBox() {
4655
- if (this.topBox)
5420
+ if (this.topBox) {
4656
5421
  return this.remove(this.topBox);
5422
+ }
5423
+ return;
4657
5424
  }
4658
- removeAll(e2 = false) {
4659
- const t2 = this.boxes$.value;
4660
- return this.boxes$.setValue([]), t2.forEach((e3) => e3.destroy()), e2 || (this.boxes.length <= 0 && (this.setMaximized(false), this.setMinimized(false)), this.events.emit(X$3.Removed, t2)), t2;
5425
+ removeAll(skipUpdate = false) {
5426
+ const deletedBoxes = this.boxes$.value;
5427
+ this.boxes$.setValue([]);
5428
+ deletedBoxes.forEach((box) => box.destroy());
5429
+ if (!skipUpdate) {
5430
+ if (this.boxes.length <= 0) {
5431
+ this.setMaximized(false);
5432
+ this.setMinimized(false);
5433
+ }
5434
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Removed, deletedBoxes);
5435
+ }
5436
+ return deletedBoxes;
4661
5437
  }
4662
- mount(e2) {
4663
- this._root$.setValue(e2);
5438
+ mount(root) {
5439
+ this._root$.setValue(root);
4664
5440
  }
4665
5441
  unmount() {
4666
5442
  this._root$.setValue(null);
4667
5443
  }
4668
- destroy(e2 = false) {
4669
- this.events.clearListeners(), this._sideEffect.flushAll(), this.removeAll(e2), this.collector.destroy(), this.titleBar.destroy();
5444
+ destroy(skipUpdate = false) {
5445
+ this.events.clearListeners();
5446
+ this._sideEffect.flushAll();
5447
+ this.removeAll(skipUpdate);
5448
+ this.collector.destroy();
5449
+ this.titleBar.destroy();
4670
5450
  }
4671
- wrapClassName(e2) {
4672
- return `${this.namespace}-${e2}`;
5451
+ wrapClassName(className) {
5452
+ return `${this.namespace}-${className}`;
4673
5453
  }
4674
- focusBox(e2, t2 = false) {
4675
- const i2 = this.getBox(e2);
4676
- i2 && (this.boxes.forEach((e3) => {
4677
- if (i2 === e3) {
4678
- let e4 = false;
4679
- i2.focus || (e4 = true, i2._focus$.setValue(true, t2)), e4 && !t2 && this.events.emit(X$3.Focused, i2);
4680
- } else
4681
- e3.focus && this.blurBox(e3, t2);
4682
- }), this.titleBar.focusBox(i2));
5454
+ focusBox(boxOrID, skipUpdate = false) {
5455
+ const targetBox = this.getBox(boxOrID);
5456
+ if (targetBox) {
5457
+ this.boxes.forEach((box) => {
5458
+ if (targetBox === box) {
5459
+ let focusChanged = false;
5460
+ if (!targetBox.focus) {
5461
+ focusChanged = true;
5462
+ targetBox._focus$.setValue(true, skipUpdate);
5463
+ }
5464
+ if (focusChanged && !skipUpdate) {
5465
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Focused, targetBox);
5466
+ }
5467
+ } else if (box.focus) {
5468
+ this.blurBox(box, skipUpdate);
5469
+ }
5470
+ });
5471
+ this.titleBar.focusBox(targetBox);
5472
+ }
4683
5473
  }
4684
5474
  focusTopBox() {
4685
- if (this.topBox && !this.topBox.focus)
5475
+ if (this.topBox && !this.topBox.focus) {
4686
5476
  return this.focusBox(this.topBox);
5477
+ }
4687
5478
  }
4688
- blurBox(e2, t2 = false) {
4689
- const i2 = this.getBox(e2);
4690
- i2 && (i2.focus && (i2._focus$.setValue(false, t2), t2 || this.events.emit(X$3.Blurred, i2)), this.titleBar.focusedBox === i2 && this.titleBar.focusBox());
4691
- }
4692
- blurAll(e2 = false) {
4693
- this.boxes.forEach((t2) => {
4694
- t2.focus && (t2._focus$.setValue(false, e2), e2 || this.events.emit(X$3.Blurred, t2));
4695
- }), this.titleBar.focusedBox && this.titleBar.focusBox();
4696
- }
4697
- teleBoxMatcher(e2) {
4698
- const t2 = Object.keys(e2);
4699
- return (i2) => t2.every((t3) => e2[t3] === i2[t3]);
4700
- }
4701
- updateBox(e2, t2, i2 = false) {
4702
- var s2, a2, n2, o2, r2, h;
4703
- t2.x == null && t2.y == null || e2._intrinsicCoord$.setValue({ x: (s2 = t2.x) != null ? s2 : e2.intrinsicX, y: (a2 = t2.y) != null ? a2 : e2.intrinsicY }, i2), t2.width == null && t2.height == null || e2._intrinsicSize$.setValue({ width: (n2 = t2.width) != null ? n2 : e2.intrinsicWidth, height: (o2 = t2.height) != null ? o2 : e2.intrinsicHeight }, i2), t2.title != null && e2._title$.setValue(t2.title), t2.visible != null && e2._visible$.setValue(t2.visible, i2), t2.resizable != null && e2._resizable$.setValue(t2.resizable, i2), t2.draggable != null && e2._draggable$.setValue(t2.draggable, i2), t2.ratio != null && e2._ratio$.setValue(t2.ratio, i2), t2.zIndex != null && e2._zIndex$.setValue(t2.zIndex, i2), t2.stageRatio !== void 0 && e2.setStageRatio(t2.stageRatio, i2), t2.content != null && e2.mountContent(t2.content), t2.footer != null && e2.mountFooter(t2.footer), t2.minHeight == null && t2.minWidth == null || e2._minSize$.setValue({ width: (r2 = t2.minWidth) != null ? r2 : e2.minWidth, height: (h = t2.minHeight) != null ? h : e2.minHeight }, i2);
5479
+ blurBox(boxOrID, skipUpdate = false) {
5480
+ const targetBox = this.getBox(boxOrID);
5481
+ if (targetBox) {
5482
+ if (targetBox.focus) {
5483
+ targetBox._focus$.setValue(false, skipUpdate);
5484
+ if (!skipUpdate) {
5485
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Blurred, targetBox);
5486
+ }
5487
+ }
5488
+ if (this.titleBar.focusedBox === targetBox) {
5489
+ this.titleBar.focusBox();
5490
+ }
5491
+ }
4704
5492
  }
4705
- smartPosition(e2) {
4706
- let { x: t2, y: i2 } = e2;
4707
- const { width: s2 = 0.5, height: a2 = 0.5 } = e2, n2 = this.stageRect, o2 = this.topBox;
4708
- if (t2 == null) {
4709
- let e3 = n2.x + 20;
4710
- if (o2) {
4711
- const t3 = o2.pxIntrinsicCoord.x + 20;
4712
- t3 + s2 * n2.width <= n2.x + n2.width && (e3 = t3);
5493
+ blurAll(skipUpdate = false) {
5494
+ this.boxes.forEach((box) => {
5495
+ if (box.focus) {
5496
+ box._focus$.setValue(false, skipUpdate);
5497
+ if (!skipUpdate) {
5498
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Blurred, box);
5499
+ }
4713
5500
  }
4714
- t2 = (e3 - n2.x) / n2.width;
5501
+ });
5502
+ if (this.titleBar.focusedBox) {
5503
+ this.titleBar.focusBox();
5504
+ }
5505
+ }
5506
+ teleBoxMatcher(config) {
5507
+ const keys = Object.keys(config);
5508
+ return (box) => keys.every((key) => config[key] === box[key]);
5509
+ }
5510
+ updateBox(box, config, skipUpdate = false) {
5511
+ var _a, _b, _c, _d, _e, _f;
5512
+ if (config.x != null || config.y != null) {
5513
+ box._intrinsicCoord$.setValue({
5514
+ x: (_a = config.x) != null ? _a : box.intrinsicX,
5515
+ y: (_b = config.y) != null ? _b : box.intrinsicY
5516
+ }, skipUpdate);
5517
+ }
5518
+ if (config.width != null || config.height != null) {
5519
+ box._intrinsicSize$.setValue({
5520
+ width: (_c = config.width) != null ? _c : box.intrinsicWidth,
5521
+ height: (_d = config.height) != null ? _d : box.intrinsicHeight
5522
+ }, skipUpdate);
5523
+ }
5524
+ if (config.title != null) {
5525
+ box._title$.setValue(config.title);
5526
+ }
5527
+ if (config.visible != null) {
5528
+ box._visible$.setValue(config.visible, skipUpdate);
5529
+ }
5530
+ if (config.resizable != null) {
5531
+ box._resizable$.setValue(config.resizable, skipUpdate);
5532
+ }
5533
+ if (config.draggable != null) {
5534
+ box._draggable$.setValue(config.draggable, skipUpdate);
5535
+ }
5536
+ if (config.boxRatio != null) {
5537
+ box._boxRatio$.setValue(config.boxRatio, skipUpdate);
5538
+ }
5539
+ if (config.zIndex != null) {
5540
+ box._zIndex$.setValue(config.zIndex, skipUpdate);
5541
+ }
5542
+ if (config.stageRatio !== void 0) {
5543
+ box.setStageRatio(config.stageRatio, skipUpdate);
5544
+ }
5545
+ if (config.content != null) {
5546
+ box.mountContent(config.content);
5547
+ }
5548
+ if (config.footer != null) {
5549
+ box.mountFooter(config.footer);
5550
+ }
5551
+ if (config.minHeight != null || config.minWidth != null) {
5552
+ box._minSize$.setValue({
5553
+ width: (_e = config.minWidth) != null ? _e : box.minWidth,
5554
+ height: (_f = config.minHeight) != null ? _f : box.minHeight
5555
+ }, skipUpdate);
5556
+ }
5557
+ }
5558
+ smartPosition(rect) {
5559
+ let { x: x2, y: y2 } = rect;
5560
+ const { width = 0.5, height = 0.5 } = rect;
5561
+ const stageRect = this.stageRect;
5562
+ const topBox = this.topBox;
5563
+ if (x2 == null) {
5564
+ let pxX = 20;
5565
+ if (topBox) {
5566
+ const pxPreferredX = topBox.pxIntrinsicCoord.x + 20;
5567
+ const pxIntrinsicWidth = width * stageRect.width;
5568
+ if (pxPreferredX + pxIntrinsicWidth <= stageRect.width) {
5569
+ pxX = pxPreferredX;
5570
+ }
5571
+ }
5572
+ x2 = pxX / stageRect.width;
4715
5573
  }
4716
- if (i2 == null) {
4717
- let e3 = n2.y + 20;
4718
- if (o2) {
4719
- const t3 = o2.pxIntrinsicCoord.y + 20;
4720
- t3 + a2 * n2.height <= n2.y + n2.height && (e3 = t3);
5574
+ if (y2 == null) {
5575
+ let pxY = 20;
5576
+ if (topBox) {
5577
+ const pxPreferredY = topBox.pxIntrinsicCoord.y + 20;
5578
+ const pxIntrinsicHeight = height * stageRect.height;
5579
+ if (pxPreferredY + pxIntrinsicHeight <= stageRect.height) {
5580
+ pxY = pxPreferredY;
5581
+ }
4721
5582
  }
4722
- i2 = (e3 - n2.y) / n2.height;
5583
+ y2 = pxY / stageRect.height;
4723
5584
  }
4724
- return { x: t2, y: i2, width: s2, height: a2 };
5585
+ return { x: x2, y: y2, width, height };
4725
5586
  }
4726
- makeBoxTop(e2, t2 = false) {
4727
- this.topBox && e2 !== this.topBox && e2._zIndex$.setValue(this.topBox.zIndex + 1, t2);
5587
+ makeBoxTop(box, skipUpdate = false) {
5588
+ if (this.topBox) {
5589
+ if (box !== this.topBox) {
5590
+ box._zIndex$.setValue(this.topBox.zIndex + 1, skipUpdate);
5591
+ }
5592
+ }
4728
5593
  }
4729
- getBoxIndex(e2) {
4730
- return typeof e2 == "string" ? this.boxes.findIndex((t2) => t2.id === e2) : this.boxes.findIndex((t2) => t2 === e2);
5594
+ getBoxIndex(boxOrID) {
5595
+ return typeof boxOrID === "string" ? this.boxes.findIndex((box) => box.id === boxOrID) : this.boxes.findIndex((box) => box === boxOrID);
4731
5596
  }
4732
- getBox(e2) {
4733
- return typeof e2 == "string" ? this.boxes.find((t2) => t2.id === e2) : e2;
5597
+ getBox(boxOrID) {
5598
+ return typeof boxOrID === "string" ? this.boxes.find((box) => box.id === boxOrID) : boxOrID;
4734
5599
  }
4735
5600
  }
4736
5601
  const createBoxManager = (manager, callbacks2, emitter2, boxEmitter2, options) => {
@@ -4761,15 +5626,6 @@ const createBoxManager = (manager, callbacks2, emitter2, boxEmitter2, options) =
4761
5626
  class BoxManager {
4762
5627
  constructor(context, createTeleBoxManagerConfig) {
4763
5628
  this.context = context;
4764
- this.mainViewElement$ = new Val(void 0);
4765
- this.updateStyle = (element2, rect) => {
4766
- if (!element2)
4767
- return;
4768
- element2.style.width = rect.width + "px";
4769
- element2.style.height = rect.height + "px";
4770
- element2.style.left = rect.x + "px";
4771
- element2.style.top = rect.y + "px";
4772
- };
4773
5629
  this.sideEffectManager = new SideEffectManager();
4774
5630
  const { emitter: emitter2, callbacks: callbacks2, boxEmitter: boxEmitter2 } = context;
4775
5631
  this.teleBoxManager = this.setupBoxManager(createTeleBoxManagerConfig);
@@ -4837,14 +5693,6 @@ class BoxManager {
4837
5693
  this.teleBoxManager.events.on("z_index", (box) => {
4838
5694
  this.context.updateAppState(box.id, AppAttributes.ZIndex, box.zIndex);
4839
5695
  }),
4840
- this.teleBoxManager._stageRect$.subscribe((stage) => {
4841
- this.updateStyle(this.mainViewElement$.value, stage);
4842
- emitter2.emit("playgroundSizeChange", stage);
4843
- this.context.notifyContainerRectUpdate(stage);
4844
- }),
4845
- emitter2.on("writableChange", (isWritable) => {
4846
- this.teleBoxManager.setHighlightStage(isWritable);
4847
- }),
4848
5696
  emitter2.on("containerSizeRatioUpdate", (ratio) => {
4849
5697
  this.teleBoxManager._stageRatio$.setValue(ratio);
4850
5698
  })
@@ -4881,7 +5729,7 @@ class BoxManager {
4881
5729
  var _a, _b, _c;
4882
5730
  if (!this.teleBoxManager)
4883
5731
  return;
4884
- let { minwidth = MIN_WIDTH, minheight = MIN_HEIGHT } = (_a = params.app.config) != null ? _a : {};
5732
+ let { minwidth = MIN_WIDTH, minheight = MIN_HEIGHT, enableShadowDOM = true } = (_a = params.app.config) != null ? _a : {};
4885
5733
  const { width, height } = (_b = params.app.config) != null ? _b : {};
4886
5734
  const title = ((_c = params.options) == null ? void 0 : _c.title) || params.appId;
4887
5735
  const rect = this.teleBoxManager.rootRect;
@@ -4897,7 +5745,8 @@ class BoxManager {
4897
5745
  minHeight: minheight,
4898
5746
  width,
4899
5747
  height,
4900
- id: params.appId
5748
+ id: params.appId,
5749
+ enableShadowDOM
4901
5750
  };
4902
5751
  const box = this.teleBoxManager.create(createBoxConfig, params.smartPosition);
4903
5752
  this.context.emitter.emit(`${params.appId}${Events.WindowCreated}`);
@@ -4909,10 +5758,15 @@ class BoxManager {
4909
5758
  stageRatio: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.stageRatio,
4910
5759
  root,
4911
5760
  fence: false,
4912
- prefersColorScheme: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.prefersColorScheme,
4913
- highlightStage: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.highlightStage
5761
+ prefersColorScheme: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.prefersColorScheme
4914
5762
  };
4915
- const manager = new F$3(initManagerState);
5763
+ if (createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.containerStyle) {
5764
+ initManagerState.containerStyle = createTeleBoxManagerConfig.containerStyle;
5765
+ }
5766
+ if (createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.stageStyle) {
5767
+ initManagerState.stageStyle = createTeleBoxManagerConfig.stageStyle;
5768
+ }
5769
+ const manager = new TeleBoxManager(initManagerState);
4916
5770
  if (this.teleBoxManager) {
4917
5771
  this.teleBoxManager.destroy();
4918
5772
  }
@@ -4944,18 +5798,19 @@ class BoxManager {
4944
5798
  return this.teleBoxManager.topBox;
4945
5799
  }
4946
5800
  updateBoxState(state) {
4947
- var _a, _b, _c, _d;
4948
5801
  if (!state)
4949
5802
  return;
4950
5803
  const box = this.getBox(state.id);
4951
5804
  if (box) {
4952
- this.teleBoxManager.update(box.id, {
4953
- x: (_a = state.position) == null ? void 0 : _a.x,
4954
- y: (_b = state.position) == null ? void 0 : _b.y,
4955
- width: ((_c = state.size) == null ? void 0 : _c.width) || 0.5,
4956
- height: ((_d = state.size) == null ? void 0 : _d.height) || 0.5,
4957
- zIndex: state.zIndex
4958
- }, true);
5805
+ if (state.size) {
5806
+ box._intrinsicSize$.setValue(state.size, true);
5807
+ }
5808
+ if (state.position) {
5809
+ box._intrinsicCoord$.setValue(state.position, true);
5810
+ }
5811
+ if (state.zIndex) {
5812
+ box._zIndex$.setValue(state.zIndex, true);
5813
+ }
4959
5814
  setTimeout(() => {
4960
5815
  if (state.focus) {
4961
5816
  this.teleBoxManager.focusBox(box.id, true);
@@ -4971,13 +5826,19 @@ class BoxManager {
4971
5826
  }
4972
5827
  }
4973
5828
  moveBox({ appId, x: x2, y: y2 }) {
4974
- this.teleBoxManager.update(appId, { x: x2, y: y2 }, true);
5829
+ const box = this.getBox(appId);
5830
+ if (box) {
5831
+ box._intrinsicCoord$.setValue({ x: x2, y: y2 }, true);
5832
+ }
4975
5833
  }
4976
5834
  focusBox({ appId }, skipUpdate = true) {
4977
5835
  this.teleBoxManager.focusBox(appId, skipUpdate);
4978
5836
  }
4979
5837
  resizeBox({ appId, width, height, skipUpdate }) {
4980
- this.teleBoxManager.update(appId, { width, height }, skipUpdate);
5838
+ const box = this.getBox(appId);
5839
+ if (box) {
5840
+ box._intrinsicSize$.setValue({ width, height }, skipUpdate);
5841
+ }
4981
5842
  }
4982
5843
  setBoxMinSize(params) {
4983
5844
  this.teleBoxManager.update(params.appId, {
@@ -15654,6 +16515,10 @@ const BuiltinApps = {
15654
16515
  DocsViewer: NetlessAppDocsViewer.kind,
15655
16516
  MediaPlayer: K.kind
15656
16517
  };
16518
+ const BuiltinAppsMap = {
16519
+ [BuiltinApps.DocsViewer]: NetlessAppDocsViewer,
16520
+ [BuiltinApps.MediaPlayer]: K
16521
+ };
15657
16522
  var videoJs = "";
15658
16523
  var style$1 = "";
15659
16524
  var style = "";
@@ -15661,15 +16526,15 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
15661
16526
  const _WindowManager = class extends InvisiblePlugin {
15662
16527
  constructor(context) {
15663
16528
  super(context);
15664
- this.version = "1.0.0-canary.26";
15665
- this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.18", "emittery": "^0.11.0", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^1.1.0", "uuid": "^7.0.3", "value-enhancer": "^1.3.0", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
16529
+ this.version = "1.0.0-canary.27";
16530
+ this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.25", "emittery": "^0.11.0", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^1.1.0", "uuid": "^7.0.3", "value-enhancer": "^1.3.0", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@playwright/test": "^1.23.0", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/node": "^18.0.0", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vite-plugin-dts": "^1.2.0", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
15666
16531
  this.emitter = callbacks$1;
15667
16532
  this.viewMode = ViewMode.Broadcaster;
15668
16533
  this.viewMode$ = new Val(ViewMode.Broadcaster);
15669
16534
  this.isReplay = isPlayer(this.displayer);
15670
16535
  this.containerSizeRatio = _WindowManager.containerSizeRatio;
15671
16536
  _WindowManager.displayer = context.displayer;
15672
- window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.18", "emittery": "^0.11.0", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^1.1.0", "uuid": "^7.0.3", "value-enhancer": "^1.3.0", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
16537
+ window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.25", "emittery": "^0.11.0", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^1.1.0", "uuid": "^7.0.3", "value-enhancer": "^1.3.0", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@playwright/test": "^1.23.0", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/node": "^18.0.0", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vite-plugin-dts": "^1.2.0", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
15673
16538
  }
15674
16539
  static async mount(params) {
15675
16540
  var _a;
@@ -15724,7 +16589,8 @@ const _WindowManager = class extends InvisiblePlugin {
15724
16589
  collectorStyles: params.collectorStyles,
15725
16590
  prefersColorScheme: params.prefersColorScheme,
15726
16591
  stageRatio: _WindowManager.containerSizeRatio,
15727
- highlightStage: params.highlightStage
16592
+ containerStyle: params.containerStyle,
16593
+ stageStyle: params.stageStyle
15728
16594
  });
15729
16595
  (_a = manager.appManager) == null ? void 0 : _a.setBoxManager(manager.boxManager);
15730
16596
  if (params.container) {
@@ -15762,11 +16628,11 @@ const _WindowManager = class extends InvisiblePlugin {
15762
16628
  }
15763
16629
  return manager;
15764
16630
  }
15765
- static initContainer(container, overwriteStyles) {
16631
+ static initContainer(container, target, overwriteStyles) {
15766
16632
  if (!_WindowManager.container) {
15767
16633
  _WindowManager.container = container;
15768
16634
  }
15769
- const { playground, mainViewElement } = setupWrapper(container);
16635
+ const { playground, mainViewElement } = setupWrapper(container, target);
15770
16636
  _WindowManager.playground = playground;
15771
16637
  if (overwriteStyles) {
15772
16638
  const style2 = document.createElement("style");
@@ -15779,7 +16645,7 @@ const _WindowManager = class extends InvisiblePlugin {
15779
16645
  return appRegister.registered;
15780
16646
  }
15781
16647
  bindContainer(container) {
15782
- var _a, _b, _c, _d, _e;
16648
+ var _a, _b, _c, _d, _e, _f;
15783
16649
  if (isRoom(this.displayer) && this.room.phase !== RoomPhase.Connected) {
15784
16650
  throw new BindContainerRoomPhaseInvalidError();
15785
16651
  }
@@ -15788,24 +16654,24 @@ const _WindowManager = class extends InvisiblePlugin {
15788
16654
  container.appendChild(_WindowManager.container.firstChild);
15789
16655
  }
15790
16656
  } else {
15791
- if (_WindowManager.params) {
16657
+ const teleboxContainer = (_a = this.boxManager) == null ? void 0 : _a.teleBoxManager.$stage;
16658
+ if (_WindowManager.params && teleboxContainer) {
15792
16659
  const params = _WindowManager.params;
15793
- const mainViewElement = _WindowManager.initContainer(container, params.overwriteStyles);
16660
+ const mainViewElement = _WindowManager.initContainer(container, teleboxContainer, params.overwriteStyles);
15794
16661
  if (this.boxManager && _WindowManager.playground) {
15795
16662
  this.boxManager.setRoot(_WindowManager.playground);
15796
- this.boxManager.mainViewElement$.setValue(mainViewElement);
15797
16663
  }
15798
16664
  this.bindMainView(mainViewElement, params.disableCameraTransform);
15799
16665
  if (_WindowManager.playground) {
15800
- (_a = this.cursorManager) == null ? void 0 : _a.setupWrapper(_WindowManager.playground);
16666
+ (_b = this.cursorManager) == null ? void 0 : _b.setupWrapper(_WindowManager.playground);
15801
16667
  }
15802
16668
  }
15803
16669
  }
15804
16670
  emitter.emit("updateManagerRect");
15805
- (_b = this.appManager) == null ? void 0 : _b.refresh();
15806
- (_c = this.appManager) == null ? void 0 : _c.resetMaximized();
15807
- (_d = this.appManager) == null ? void 0 : _d.resetMinimized();
15808
- (_e = this.appManager) == null ? void 0 : _e.displayerWritableListener(!this.room.isWritable);
16671
+ (_c = this.appManager) == null ? void 0 : _c.refresh();
16672
+ (_d = this.appManager) == null ? void 0 : _d.resetMaximized();
16673
+ (_e = this.appManager) == null ? void 0 : _e.resetMinimized();
16674
+ (_f = this.appManager) == null ? void 0 : _f.displayerWritableListener(!this.room.isWritable);
15809
16675
  _WindowManager.container = container;
15810
16676
  }
15811
16677
  bindCollectorContainer(container) {
@@ -16321,6 +17187,14 @@ const _WindowManager = class extends InvisiblePlugin {
16321
17187
  this.containerSizeRatio = ratio;
16322
17188
  emitter.emit("containerSizeRatioUpdate", ratio);
16323
17189
  }
17190
+ setContainerStyle(style2) {
17191
+ var _a;
17192
+ (_a = this.boxManager) == null ? void 0 : _a.teleBoxManager.setContainerStyle(style2);
17193
+ }
17194
+ setStageStyle(style2) {
17195
+ var _a;
17196
+ (_a = this.boxManager) == null ? void 0 : _a.teleBoxManager.setStageStyle(style2);
17197
+ }
16324
17198
  createPPTHandler() {
16325
17199
  return {
16326
17200
  onPageJumpTo: (_pptUUID, index2) => {
@@ -16375,4 +17249,4 @@ WindowManager.debug = false;
16375
17249
  WindowManager.containerSizeRatio = DEFAULT_CONTAINER_RATIO;
16376
17250
  WindowManager.isCreated = false;
16377
17251
  setupBuiltin();
16378
- export { AppCreateError, AppManagerNotInitError, AppNotRegisterError, BindContainerRoomPhaseInvalidError, BoxManagerNotFoundError, BoxNotCreatedError, BuiltinApps, InvalidScenePath, ParamsInvalidError, WhiteWebSDKInvalidError, WindowManager, calculateNextIndex, reconnectRefresher };
17252
+ export { AppCreateError, AppManagerNotInitError, AppNotRegisterError, BindContainerRoomPhaseInvalidError, BoxManagerNotFoundError, BoxNotCreatedError, BuiltinApps, BuiltinAppsMap, InvalidScenePath, ParamsInvalidError, WhiteWebSDKInvalidError, WindowManager, calculateNextIndex, reconnectRefresher };