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

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