@netless/window-manager 1.0.0-canary.25 → 1.0.0-canary.28

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 (71) hide show
  1. package/dist/index.cjs.js +93 -12
  2. package/dist/index.es.js +1585 -698
  3. package/dist/index.umd.js +93 -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 +6 -4
  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 -2
  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 -2
  46. package/dist/src/image.d.ts +19 -0
  47. package/dist/{index.d.ts → src/index.d.ts} +16 -12
  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 +18 -7
  57. package/src/App/WhiteboardView.ts +23 -18
  58. package/src/AppListener.ts +1 -21
  59. package/src/AppManager.ts +2 -1
  60. package/src/BoxManager.ts +32 -36
  61. package/src/BuiltinApps.ts +5 -0
  62. package/src/Helper.ts +3 -2
  63. package/src/Utils/Common.ts +3 -0
  64. package/src/View/CameraSynchronizer.ts +5 -9
  65. package/src/View/MainView.ts +3 -1
  66. package/src/callback.ts +1 -0
  67. package/src/constants.ts +0 -2
  68. package/src/index.ts +62 -34
  69. package/src/style.css +3 -41
  70. package/src/typings.ts +6 -0
  71. package/vite.config.js +5 -3
package/dist/index.es.js CHANGED
@@ -19,12 +19,12 @@ var __spreadValues = (a2, b2) => {
19
19
  var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2));
20
20
  import pRetry from "p-retry";
21
21
  import Emittery from "emittery";
22
- import { debounce, isEqual, omit, isObject, has, get, size as size$1, mapValues, noop as noop$1, pick, isBoolean, isNumber, throttle, omitBy, isUndefined, isInteger, orderBy, isEmpty, isFunction, isNull } from "lodash";
22
+ import { debounce, isObject, has, get, size as size$1, mapValues, noop as noop$1, pick, isBoolean, isNumber, throttle, isEqual, omitBy, isUndefined, isInteger, orderBy, isEmpty, omit, isFunction, isNull } from "lodash";
23
23
  import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, WhiteVersion, autorun, toJS, listenDisposed, unlistenDisposed, AnimationMode, ViewMode, isPlayer, isRoom, ApplianceNames, RoomPhase, InvisiblePlugin } from "white-web-sdk";
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";
@@ -38,8 +38,6 @@ var Events = /* @__PURE__ */ ((Events2) => {
38
38
  Events2["SetMainViewSceneIndex"] = "SetMainViewSceneIndex";
39
39
  Events2["SetAppFocusIndex"] = "SetAppFocusIndex";
40
40
  Events2["SwitchViewsToFreedom"] = "SwitchViewsToFreedom";
41
- Events2["MoveCamera"] = "MoveCamera";
42
- Events2["MoveCameraToContain"] = "MoveCameraToContain";
43
41
  Events2["CursorMove"] = "CursorMove";
44
42
  Events2["RootDirRemoved"] = "RootDirRemoved";
45
43
  Events2["Refresh"] = "Refresh";
@@ -354,6 +352,9 @@ const genAppId = async (kind2) => {
354
352
  return `${kind2}-${v4().replace("-", "").slice(0, 8)}`;
355
353
  };
356
354
  const setViewFocusScenePath = (view, focusScenePath) => {
355
+ if (view.didRelease) {
356
+ return;
357
+ }
357
358
  if (view.focusScenePath !== focusScenePath) {
358
359
  view.focusScenePath = focusScenePath;
359
360
  return view;
@@ -473,14 +474,6 @@ class AppListeners {
473
474
  this.setMainViewScenePathHandler(data.payload);
474
475
  break;
475
476
  }
476
- case Events.MoveCamera: {
477
- this.moveCameraHandler(data.payload);
478
- break;
479
- }
480
- case Events.MoveCameraToContain: {
481
- this.moveCameraToContainHandler(data.payload);
482
- break;
483
- }
484
477
  case Events.CursorMove: {
485
478
  this.cursorMoveHandler(data.payload);
486
479
  break;
@@ -520,14 +513,6 @@ class AppListeners {
520
513
  setViewFocusScenePath(this.manager.mainView, nextScenePath);
521
514
  callbacks$1.emit("mainViewScenePathChange", nextScenePath);
522
515
  };
523
- this.moveCameraHandler = (payload) => {
524
- if (isEqual(omit(payload, ["animationMode"]), __spreadValues({}, this.manager.mainView.camera)))
525
- return;
526
- this.manager.mainView.moveCamera(payload);
527
- };
528
- this.moveCameraToContainHandler = (payload) => {
529
- this.manager.mainView.moveCameraToContain(payload);
530
- };
531
516
  this.cursorMoveHandler = (payload) => {
532
517
  emitter.emit("cursorMove", payload);
533
518
  };
@@ -949,17 +934,25 @@ class WhiteBoardView {
949
934
  return this.appProxy.removeSceneByIndex(needRemoveIndex);
950
935
  };
951
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$;
952
941
  this.pageState$ = pageState$;
953
- this.appProxy.sideEffectManager.add(() => appProxy.appEmitter.on("pageStateChange", (pageState) => {
954
- pageState$.setValue(pageState);
955
- }));
956
- const camera$ = new Val(pick(this.view.camera, ["centerX", "centerY"]));
957
- this.camera$ = camera$;
958
- this.appProxy.sideEffectManager.add(() => appProxy.camera$.subscribe((camera) => {
959
- if (camera) {
960
- camera$.setValue(pick(camera, ["centerX", "centerY"]));
961
- }
962
- }));
942
+ this.baseCamera$ = camera$;
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
+ ]);
963
956
  view.disableCameraTransform = true;
964
957
  }
965
958
  get pageState() {
@@ -968,7 +961,7 @@ class WhiteBoardView {
968
961
  moveCamera(camera) {
969
962
  this.appProxy.moveCamera(camera);
970
963
  }
971
- setRect(rect) {
964
+ setBaseRect(rect) {
972
965
  this.appProxy.updateSize(rect.width, rect.height);
973
966
  }
974
967
  }
@@ -977,12 +970,12 @@ const log = (...args) => {
977
970
  console.log(`[WindowManager]:`, ...args);
978
971
  }
979
972
  };
980
- const setupWrapper = (root) => {
973
+ const setupWrapper = (root, target) => {
981
974
  const playground = document.createElement("div");
982
975
  playground.className = "netless-window-manager-playground";
983
976
  const mainViewElement = document.createElement("div");
984
977
  mainViewElement.className = "netless-window-manager-main-view";
985
- playground.appendChild(mainViewElement);
978
+ target.appendChild(mainViewElement);
986
979
  root.appendChild(playground);
987
980
  return { playground, mainViewElement };
988
981
  };
@@ -1051,7 +1044,6 @@ class AppContext {
1051
1044
  }
1052
1045
  };
1053
1046
  this.createWhiteBoardView = (params) => {
1054
- var _a;
1055
1047
  if (this.whiteBoardView) {
1056
1048
  return this.whiteBoardView;
1057
1049
  }
@@ -1067,7 +1059,7 @@ class AppContext {
1067
1059
  const viewWrapper = document.createElement("div");
1068
1060
  this._viewWrapper = viewWrapper;
1069
1061
  viewWrapper.className = "window-manager-view-wrapper";
1070
- (_a = this.box.$content.parentElement) == null ? void 0 : _a.appendChild(viewWrapper);
1062
+ this.box.$main.appendChild(viewWrapper);
1071
1063
  view.divElement = viewWrapper;
1072
1064
  this.appProxy.fireMemberStateChange();
1073
1065
  if (this.isAddApp) {
@@ -1075,7 +1067,7 @@ class AppContext {
1075
1067
  }
1076
1068
  this.whiteBoardView = new WhiteBoardView(view, this, this.appProxy, this.ensurePageSize);
1077
1069
  this.appProxy.sideEffectManager.add(() => [
1078
- this.box._contentStageRect$.subscribe((rect) => {
1070
+ this.box._stageRect$.subscribe((rect) => {
1079
1071
  viewWrapper.style.left = `${rect.x}px`;
1080
1072
  viewWrapper.style.top = `${rect.y}px`;
1081
1073
  viewWrapper.style.width = `${rect.width}px`;
@@ -1256,16 +1248,12 @@ class CameraSynchronizer {
1256
1248
  this.remoteCamera = camera;
1257
1249
  this.remoteSize = size2;
1258
1250
  if (this.remoteSize && this.rect) {
1259
- let scale2;
1260
- if (size2.width < size2.height) {
1261
- scale2 = this.rect.width / size2.width;
1262
- } else {
1263
- scale2 = this.rect.height / size2.height;
1264
- }
1265
- 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);
1266
1254
  const config = {
1267
1255
  scale: nextScale,
1268
- animationMode: AnimationMode.Immediately
1256
+ animationMode: AnimationMode.Continuous
1269
1257
  };
1270
1258
  if (camera.centerX !== null) {
1271
1259
  config.centerX = camera.centerX;
@@ -1289,7 +1277,7 @@ class CameraSynchronizer {
1289
1277
  const nextScale = this.remoteCamera.scale * scale2;
1290
1278
  (_a = this.view) == null ? void 0 : _a.moveCamera({
1291
1279
  scale: nextScale,
1292
- animationMode: AnimationMode.Immediately
1280
+ animationMode: AnimationMode.Continuous
1293
1281
  });
1294
1282
  }
1295
1283
  }
@@ -1786,10 +1774,10 @@ class AppProxy {
1786
1774
  });
1787
1775
  this.camera$.setValue(toJS(this.appAttributes.camera));
1788
1776
  }
1789
- if (!this.size$.value && box.contentStageRect) {
1790
- const initialRect = this.computedInitialRect(box.contentStageRect);
1791
- const width = (initialRect == null ? void 0 : initialRect.width) || box.contentStageRect.width;
1792
- 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;
1793
1781
  this.storeSize({
1794
1782
  id: this.uid,
1795
1783
  width,
@@ -1802,7 +1790,7 @@ class AppProxy {
1802
1790
  view$: this.view$,
1803
1791
  camera$: this.camera$,
1804
1792
  size$: this.size$,
1805
- stageRect$: box._contentStageRect$,
1793
+ stageRect$: box._stageRect$,
1806
1794
  storeCamera: this.storeCamera,
1807
1795
  storeSize: this.storeSize
1808
1796
  });
@@ -1930,9 +1918,17 @@ class AppProxy {
1930
1918
  canOperate: this.manager.canOperate,
1931
1919
  smartPosition: this.isAddApp
1932
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
+ }
1933
1925
  this.box$.setValue(box);
1934
1926
  if (this.isAddApp && this.box) {
1935
1927
  this.store.updateAppState(appId, AppAttributes.ZIndex, this.box.zIndex);
1928
+ this.store.updateAppState(appId, AppAttributes.Size, {
1929
+ width: this.box.intrinsicWidth,
1930
+ height: this.box.intrinsicHeight
1931
+ });
1936
1932
  this.boxManager.focusBox({ appId }, false);
1937
1933
  }
1938
1934
  } catch (error) {
@@ -2053,6 +2049,8 @@ class AppProxy {
2053
2049
  }
2054
2050
  }
2055
2051
  setViewFocusScenePath() {
2052
+ if (this.status === "destroyed")
2053
+ return;
2056
2054
  const fullPath = this.getFullScenePath();
2057
2055
  if (fullPath && this.view) {
2058
2056
  setViewFocusScenePath(this.view, fullPath);
@@ -2108,6 +2106,7 @@ class AppProxy {
2108
2106
  this.status = "destroyed";
2109
2107
  try {
2110
2108
  await appRegister.notifyApp(this.kind, "destroy", { appId: this.id });
2109
+ callbacks$1.emit("appClose", { appId: this.id, kind: this.kind, error });
2111
2110
  await this.appEmitter.emit("destroy", { error });
2112
2111
  } catch (error2) {
2113
2112
  console.error("[WindowManager]: notifyApp error", error2.message, error2.stack);
@@ -2357,12 +2356,14 @@ class MainViewProxy {
2357
2356
  rebind() {
2358
2357
  const divElement = this.mainView.divElement;
2359
2358
  const disableCameraTransform = this.mainView.disableCameraTransform;
2359
+ const camera = __spreadValues({}, this.mainView.camera);
2360
2360
  this.stop();
2361
2361
  releaseView(this.mainView);
2362
2362
  this.removeMainViewListener();
2363
2363
  this.mainView = this.createMainView();
2364
2364
  this.mainView.disableCameraTransform = disableCameraTransform;
2365
2365
  this.mainView.divElement = divElement;
2366
+ this.mainView.moveCamera(__spreadProps(__spreadValues({}, camera), { animationMode: AnimationMode.Immediately }));
2366
2367
  this.addMainViewListener();
2367
2368
  this.start();
2368
2369
  }
@@ -2634,8 +2635,7 @@ class AppManager {
2634
2635
  this.dispatchInternalEvent(Events.AppBoxStateChange, payload);
2635
2636
  };
2636
2637
  this.addAppsChangeListener = () => {
2637
- var _a;
2638
- (_a = this.refresher) == null ? void 0 : _a.add("apps", () => {
2638
+ this.refresher.add("apps", () => {
2639
2639
  return safeListenPropsUpdated(() => this.attributes.apps, () => {
2640
2640
  this.attributesUpdateCallback(this.attributes.apps);
2641
2641
  });
@@ -2712,7 +2712,7 @@ class AppManager {
2712
2712
  }
2713
2713
  };
2714
2714
  this.closeAll = async () => {
2715
- for (const [_2, appProxy] of this.appProxies.entries()) {
2715
+ for (const [_, appProxy] of this.appProxies.entries()) {
2716
2716
  await appProxy.destroy(true, false, true);
2717
2717
  }
2718
2718
  };
@@ -3128,6 +3128,7 @@ class AppManager {
3128
3128
  }
3129
3129
  }
3130
3130
  async onReconnected() {
3131
+ this.attributesUpdateCallback(this.attributes.apps);
3131
3132
  const appProxies = Array.from(this.appProxies.values());
3132
3133
  const reconnected = appProxies.map((appProxy) => {
3133
3134
  return appProxy.onReconnected();
@@ -3324,7 +3325,7 @@ var startLoop = function() {
3324
3325
  if (!isProcessing)
3325
3326
  onNextFrame(processFrame);
3326
3327
  };
3327
- var clamp$1 = function(min, max) {
3328
+ var clamp$2 = function(min, max) {
3328
3329
  return function(v2) {
3329
3330
  return Math.max(Math.min(v2, max), min);
3330
3331
  };
@@ -3342,7 +3343,7 @@ var number = {
3342
3343
  return v2;
3343
3344
  }
3344
3345
  };
3345
- var alpha = __assign(__assign({}, number), { transform: clamp$1(0, 1) });
3346
+ var alpha = __assign(__assign({}, number), { transform: clamp$2(0, 1) });
3346
3347
  var scale = __assign(__assign({}, number), { default: 1 });
3347
3348
  var createUnitType = function(unit) {
3348
3349
  return {
@@ -3366,7 +3367,7 @@ var progressPercentage = __assign(__assign({}, percent), { parse: function(v2) {
3366
3367
  var getValueFromFunctionString = function(value) {
3367
3368
  return value.substring(value.indexOf("(") + 1, value.lastIndexOf(")"));
3368
3369
  };
3369
- var clampRgbUnit = clamp$1(0, 255);
3370
+ var clampRgbUnit = clamp$2(0, 255);
3370
3371
  var isRgba = function(v2) {
3371
3372
  return v2.red !== void 0;
3372
3373
  };
@@ -4005,190 +4006,423 @@ var shallowequal = function shallowEqual(objA, objB, compare, compareContext) {
4005
4006
  }
4006
4007
  return true;
4007
4008
  };
4008
- 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) => {
4009
- for (var i2 in t2 || (t2 = {}))
4010
- a$1.call(t2, i2) && o$2(e2, i2, t2[i2]);
4011
- if (s$2)
4012
- for (var i2 of s$2(t2))
4013
- n$3.call(t2, i2) && o$2(e2, i2, t2[i2]);
4014
- return e2;
4015
- };
4016
- var v$3, w$2, C$3, y$2, E$3, z$2, _, B$2, N$3, S$3;
4017
- (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";
4018
- function I$3(e2, t2, i2) {
4019
- return Math.min(Math.max(e2, t2), i2);
4020
- }
4021
- function k$1(e2) {
4022
- e2.stopPropagation(), e2.cancelable && e2.preventDefault();
4023
- }
4024
- function R$3(e2) {
4025
- return e2.touches ? e2.touches[0] : e2;
4026
- }
4027
- let D$2 = 1;
4028
- function L$3() {
4029
- return "New Box " + D$2++;
4009
+ var shadowStyles = /* @__PURE__ */ (() => '.telebox-quarantine {\n all: initial;\n position: relative;\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n}\n\n.telebox-body-wrap {\n color: #191919;\n color: var(--tele-box-color, #191919);\n flex: 1;\n width: 100%;\n overflow: hidden;\n display: flex;\n justify-content: center;\n align-items: center;\n position: relative;\n}\n\n.telebox-content {\n width: 100%;\n height: 100%;\n position: relative;\n background-color: #f9f9f9;\n background-color: var(--tele-manager-container-background, #f9f9f9);\n}\n\n.telebox-box-stage {\n position: absolute;\n z-index: 1;\n overflow: hidden;\n background-color: #fff;\n background-color: var(--tele-manager-stage-background, #fff);\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.08);\n box-shadow: var(--tele-manager-stage-shadow, 0px 0px 16px rgba(0, 0, 0, 0.08));\n}\n\n.telebox-footer-wrap {\n flex-shrink: 0;\n display: flex;\n flex-direction: column;\n 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\n.telebox-footer-wrap::before {\n content: "";\n display: block;\n flex: 1;\n}\n\n.telebox-color-scheme-dark {\n color-scheme: dark;\n}\n\n.telebox-color-scheme-dark .telebox-body-wrap {\n color: #e9e9e9;\n color: var(--tele-box-color-dark, #e9e9e9);\n}\n\n.telebox-color-scheme-dark .telebox-content {\n background-color: #25282e;\n background-color: var(--tele-manager-container-background-dark, #25282e);\n}\n\n.telebox-color-scheme-dark .telebox-box-stage {\n background-color: #272a30;\n background-color: var(--tele-manager-stage-background-dark, #272a30);\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.24);\n box-shadow: var(--tele-manager-stage-shadow-dark, 0px 0px 16px rgba(0, 0, 0, 0.24));\n}\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);
4030
4058
  }
4031
- function T$3(e2) {
4032
- return Boolean(e2);
4059
+ function preventEvent$1(ev) {
4060
+ ev.stopPropagation();
4061
+ if (ev.cancelable) {
4062
+ ev.preventDefault();
4063
+ }
4033
4064
  }
4034
- function V$3(e2) {
4035
- return !e2;
4065
+ let defaultBoxCount = 1;
4066
+ function getBoxDefaultName() {
4067
+ return `New Box ${defaultBoxCount++}`;
4036
4068
  }
4037
- class H$3 {
4038
- constructor({ readonly$: e2, state$: t2, title$: i2, buttons: s2, onEvent: a2, onDragStart: n2, namespace: o2 = "telebox" }) {
4039
- this.sideEffect = new SideEffectManager(), this.lastTitleBarClick = { timestamp: 0, clientX: -100, clientY: -100 }, this.handleTitleBarClick = (e3) => {
4040
- var t3;
4041
- if (this.readonly$.value)
4042
- return;
4043
- if (e3.button !== 0)
4044
- return;
4045
- 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) {
4046
4088
  return;
4047
- k$1(e3);
4048
- const i3 = Date.now();
4049
- 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;
4050
- }, this.lastTitleBarTouch = { timestamp: 0, clientX: -100, clientY: -100 }, this.handleTitleBarTouch = (e3) => {
4051
- var t3;
4052
- if (this.readonly$.value)
4089
+ }
4090
+ if (ev.button !== 0) {
4053
4091
  return;
4054
- if ((t3 = e3.target.dataset) == null ? void 0 : t3.teleTitleBarNoDblClick)
4092
+ }
4093
+ if ((_a = ev.target.dataset) == null ? void 0 : _a.teleTitleBarNoDblClick) {
4055
4094
  return;
4056
- k$1(e3);
4057
- const i3 = Date.now(), { clientX: s3 = this.lastTitleBarTouch.clientX + 100, clientY: a3 = this.lastTitleBarTouch.clientY + 100 } = e3.touches[0] || {};
4058
- 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;
4059
- }, 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();
4060
4133
  }
4061
4134
  render() {
4062
4135
  if (!this.$titleBar) {
4063
- this.$titleBar = document.createElement("div"), this.$titleBar.className = this.wrapClassName("titlebar");
4064
- const e2 = document.createElement("div");
4065
- e2.className = this.wrapClassName("title-area"), e2.dataset.teleBoxHandle = "dh";
4066
- const t2 = document.createElement("h1");
4067
- t2.className = this.wrapClassName("title"), t2.dataset.teleBoxHandle = "dh", e2.appendChild(t2), e2.appendChild(this.$dragArea);
4068
- const i2 = document.createElement("div");
4069
- i2.className = this.wrapClassName("titlebar-btns"), this.buttons.forEach(({ iconClassName: e3 }, t3) => {
4070
- const s2 = String(t3), a2 = document.createElement("button");
4071
- a2.className = `${this.wrapClassName("titlebar-btn")} ${e3}`, a2.dataset.teleTitleBarBtnIndex = s2, a2.dataset.teleTitleBarNoDblClick = "true", i2.appendChild(a2);
4072
- }), this.sideEffect.addDisposer(this.title$.subscribe((e3) => {
4073
- t2.textContent = e3, t2.title = e3;
4074
- }), "render-title"), this.sideEffect.addDisposer(this.state$.subscribe((e3) => {
4075
- this.buttons.forEach((t3, s2) => {
4076
- var a2;
4077
- 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
+ }
4078
4166
  });
4079
- }), "render-state-btns"), this.sideEffect.addEventListener(i2, "click", (e3) => {
4080
- var t3;
4081
- 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) {
4082
4171
  return;
4083
- const i3 = e3.target, s2 = Number((t3 = i3.dataset) == null ? void 0 : t3.teleTitleBarBtnIndex);
4084
- if (!Number.isNaN(s2) && s2 < this.buttons.length) {
4085
- k$1(e3);
4086
- const t4 = this.buttons[s2];
4087
- this.onEvent && this.onEvent({ type: t4.type, value: t4.value });
4088
4172
  }
4089
- }, {}, "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);
4090
4188
  }
4091
4189
  return this.$titleBar;
4092
4190
  }
4093
4191
  renderDragArea() {
4094
- const e2 = document.createElement("div");
4095
- 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;
4096
4197
  }
4097
4198
  dragHandle() {
4098
4199
  return this.$titleBar;
4099
4200
  }
4100
- wrapClassName(e2) {
4101
- return `${this.namespace}-${e2}`;
4201
+ wrapClassName(className) {
4202
+ return `${this.namespace}-${className}`;
4102
4203
  }
4103
4204
  destroy() {
4104
- this.sideEffect.flushAll(), this.$titleBar && (this.$titleBar = void 0, this.onDragStart = void 0, this.onEvent = void 0);
4105
- }
4106
- }
4107
- class A$2 {
4108
- constructor({ namespace: e2, rootRect$: t2, ratio$: i2, highlightStage$: s2, root$: a2 }) {
4109
- this._sideEffect = new SideEffectManager(), this.namespace = e2, this.highlightStage$ = s2, this.stageRect$ = combine([t2, i2], ([e3, t3]) => {
4110
- if (t3 <= 0 || e3.width <= 0 || e3.height <= 0)
4111
- return e3;
4112
- const i3 = e3.width * t3;
4113
- if (i3 === e3.height)
4114
- return e3;
4115
- if (i3 < e3.height)
4116
- return { x: 0, y: (e3.height - i3) / 2, width: e3.width, height: i3 };
4117
- const s3 = e3.height / t3;
4118
- return { x: (e3.width - s3) / 2, y: 0, width: s3, height: e3.height };
4119
- }, { compare: shallowequal }), this._sideEffect.addDisposer(combine([a2, s2]).subscribe(([e3, t3]) => {
4120
- var i3;
4121
- e3 && t3 ? e3.appendChild(this.render()) : ((i3 = this.$boxStage) == null ? void 0 : i3.parentNode) && this.$boxStage.remove();
4122
- }));
4205
+ this.sideEffect.flushAll();
4206
+ if (this.$titleBar) {
4207
+ this.$titleBar = void 0;
4208
+ this.onDragStart = void 0;
4209
+ this.onEvent = void 0;
4210
+ }
4123
4211
  }
4124
- render() {
4125
- if (this.$boxStage)
4126
- return this.$boxStage;
4127
- const e2 = document.createElement("div");
4128
- e2.className = this.wrapClassName("box-stage-container");
4129
- const t2 = document.createElement("div");
4130
- t2.className = this.wrapClassName("box-stage-mask");
4131
- const i2 = document.createElement("div");
4132
- i2.className = this.wrapClassName("box-stage-mask");
4133
- const s2 = document.createElement("div");
4134
- s2.className = this.wrapClassName("box-stage-frame");
4135
- const [a2, n2, o2, r2] = ["M0 8V0h8v2H2v6H0Z", "M8 8V0H0v2h6v6h2Z", "M0 0v8h8V6H2V0H0Z", "M8 0v8H0V6h6V0h2Z"].map((e3, t3) => {
4136
- const i3 = document.createElementNS("http://www.w3.org/2000/svg", "svg");
4137
- i3.setAttribute("viewBox", "0 0 8 8"), i3.setAttribute("class", `${this.wrapClassName("box-stage-frame-corner")} is-${t3}`);
4138
- const s3 = document.createElementNS("http://www.w3.org/2000/svg", "path");
4139
- return s3.setAttribute("d", e3), s3.setAttribute("fill", "#3381FF"), i3.appendChild(s3), i3;
4140
- });
4141
- 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) => {
4142
- e2.classList.toggle("is-active", t3);
4143
- })), this._sideEffect.addDisposer(combine([this.highlightStage$, this.stageRect$]).subscribe(([s3, a3]) => {
4144
- 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`));
4145
- })), this.$boxStage = e2, e2;
4212
+ }
4213
+ function calcStageRect([rootRect, ratio]) {
4214
+ if (ratio <= 0 || rootRect.width <= 0 || rootRect.height <= 0) {
4215
+ return rootRect;
4146
4216
  }
4147
- destroy() {
4148
- this._sideEffect.flushAll();
4217
+ const preferredHeight = rootRect.width * ratio;
4218
+ if (preferredHeight === rootRect.height) {
4219
+ return rootRect;
4149
4220
  }
4150
- wrapClassName(e2) {
4151
- return `${this.namespace}-${e2}`;
4152
- }
4153
- }
4154
- const W$3 = window.ResizeObserver || ResizeObserver$2;
4155
- class Y$3 {
4156
- 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 }) {
4157
- this.events = new Emittery(), this._delegateEvents = new Emittery(), this.handleTrackStart = (e3) => {
4158
- var t3;
4159
- return (t3 = this._handleTrackStart) == null ? void 0 : t3.call(this, e3);
4160
- }, this._sideEffect = new SideEffectManager(), this.id = e2, this.namespace = i2;
4161
- const G2 = new ValManager();
4162
- this._sideEffect.addDisposer(() => G2.destroy());
4163
- 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 });
4164
- this._sideEffect.addDisposer(re2.reaction((e3, t3) => {
4165
- 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
+ }
4166
4385
  }));
4167
- 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 });
4168
- this._sideEffect.addDisposer(() => $e2.destroy());
4169
- withReadonlyValueEnhancer(this, { darkMode: D2, fence: T2, minimized: V2, maximized: W2, readonly: Y2, rootRect: P2, managerStageRect: O2, collectorRect: Z2 });
4170
- 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$ };
4171
- withReadonlyValueEnhancer(this, be2, G2);
4172
- 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) => {
4173
- var t3;
4174
- return (t3 = this._handleTrackStart) == null ? void 0 : t3.call(this, e3);
4175
- }, onEvent: (e3) => this._delegateEvents.emit(e3.type) }), this._sideEffect.addDisposer(U2.subscribe((e3) => {
4176
- e3 > 0 && this.transform(me2.value.x, me2.value.y, ce2.value.width, ce2.value.height, true);
4177
- })), this._sideEffect.addDisposer(T2.subscribe((e3) => {
4178
- e3 && this.move(me2.value.x, me2.value.y, true);
4179
- })), this.$box = this.render(), pe2.setValue(this.$content.parentElement);
4180
- const ve2 = (e3, t3) => {
4181
- this._sideEffect.addDisposer(e3.reaction((e4, i3) => {
4182
- i3 || this.events.emit(t3, e4);
4386
+ this._sideEffect.addDisposer(fence$.subscribe((fence) => {
4387
+ if (fence) {
4388
+ this.move(pxIntrinsicCoord$.value.x, pxIntrinsicCoord$.value.y);
4389
+ }
4390
+ }));
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
+ }
4183
4404
  }));
4184
4405
  };
4185
- 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) => {
4186
- t3 || e3 || this.events.emit(E$3.Close);
4187
- }), te2.reaction((e3, t3) => {
4188
- t3 || this.events.emit(e3 ? E$3.Focus : E$3.Blur);
4189
- }), X2.subscribe((e3) => {
4190
- e3 ? e3.appendChild(this.$box) : this.$box.parentNode && this.$box.remove();
4191
- })]);
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
+ ]);
4192
4426
  }
4193
4427
  get minWidth() {
4194
4428
  return this._minSize$.value.width;
@@ -4196,14 +4430,17 @@ class Y$3 {
4196
4430
  get minHeight() {
4197
4431
  return this._minSize$.value.height;
4198
4432
  }
4199
- setMinWidth(e2, t2 = false) {
4200
- this._minSize$.setValue({ width: e2, height: this.minHeight }, t2);
4433
+ setMinWidth(minWidth, skipUpdate = false) {
4434
+ this._minSize$.setValue({ width: minWidth, height: this.minHeight }, skipUpdate);
4201
4435
  }
4202
- setMinHeight(e2, t2 = false) {
4203
- this._minSize$.setValue({ width: this.minWidth, height: e2 }, t2);
4436
+ setMinHeight(minHeight, skipUpdate = false) {
4437
+ this._minSize$.setValue({ width: this.minWidth, height: minHeight }, skipUpdate);
4204
4438
  }
4205
- resize(e2, t2, i2 = false) {
4206
- 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);
4207
4444
  }
4208
4445
  get intrinsicX() {
4209
4446
  return this._intrinsicCoord$.value.x;
@@ -4217,388 +4454,853 @@ class Y$3 {
4217
4454
  get intrinsicHeight() {
4218
4455
  return this._intrinsicSize$.value.height;
4219
4456
  }
4220
- move(e2, t2, i2 = false) {
4221
- let s2, a2;
4222
- const n2 = this.managerStageRect, o2 = this.pxIntrinsicSize;
4223
- if (this.fence)
4224
- s2 = I$3(e2, n2.x, n2.x + n2.width - o2.width), a2 = I$3(t2, n2.y, n2.y + n2.height - o2.height);
4225
- else {
4226
- const i3 = this.rootRect;
4227
- s2 = I$3(e2, 0 - o2.width + 20, 0 + i3.width - 20), a2 = I$3(t2, 0, 0 + i3.height - 20);
4228
- }
4229
- this._intrinsicCoord$.setValue({ x: (s2 - n2.x) / n2.width, y: (a2 - n2.y) / n2.height }, i2);
4230
- }
4231
- transform(e2, t2, i2, s2, a2 = false) {
4232
- const n2 = this.managerStageRect, o2 = this.rootRect;
4233
- if (i2 = Math.max(i2, this.pxMinSize.width), s2 = Math.max(s2, this.pxMinSize.height), this.ratio > 0) {
4234
- const e3 = this.ratio * i2;
4235
- t2 !== this.pxIntrinsicCoord.y && (t2 -= e3 - s2), s2 = e3;
4236
- }
4237
- 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);
4238
- }
4239
- mountContent(e2) {
4240
- 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);
4241
4500
  }
4242
4501
  unmountContent() {
4243
- this._$userContent$.setValue(void 0);
4502
+ if (this.$authorContent) {
4503
+ this.$authorContent.remove();
4504
+ this.$authorContent = void 0;
4505
+ }
4244
4506
  }
4245
- mountStage(e2) {
4246
- 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
+ }
4247
4518
  }
4248
4519
  unmountStage() {
4249
- 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();
4250
4526
  }
4251
- mountFooter(e2) {
4252
- 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);
4253
4532
  }
4254
4533
  unmountFooter() {
4255
- this._$userFooter$.setValue(void 0);
4256
- }
4257
- getUserStyles() {
4258
- return this.$userStyles;
4534
+ if (this.$authorFooter) {
4535
+ this.$authorFooter.remove();
4536
+ this.$authorFooter = void 0;
4537
+ }
4259
4538
  }
4260
- mountStyles(e2) {
4261
- let t2;
4262
- typeof e2 == "string" ? (t2 = document.createElement("style"), t2.textContent = e2) : t2 = e2, this._$userStyles$.setValue(t2);
4539
+ mountStyles(styles2) {
4540
+ this.$styles.textContent = styles2;
4263
4541
  }
4264
4542
  unmountStyles() {
4265
- this._$userStyles$.setValue(void 0);
4543
+ this.$styles.textContent = "";
4266
4544
  }
4267
- setHighlightStage(e2) {
4268
- this._boxHighlightStage$.setValue(e2);
4545
+ mountUserStyles(styles2) {
4546
+ this.$userStyles.textContent = styles2;
4269
4547
  }
4270
- render() {
4271
- if (this.$box)
4548
+ unmountUserStyles() {
4549
+ this.$userStyles.textContent = "";
4550
+ }
4551
+ _render() {
4552
+ if (this.$box) {
4272
4553
  return this.$box;
4273
- this.$box = document.createElement("div"), this.$box.classList.add(this.wrapClassName("box"));
4274
- const e2 = (e3, t3, i3, s3 = T$3) => this._sideEffect.add(() => {
4275
- const a3 = this.wrapClassName(i3);
4276
- return t3.subscribe((t4) => {
4277
- 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
+ }
4278
4584
  });
4279
4585
  });
4280
- 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(() => {
4281
- const e3 = this.wrapClassName("minimized"), t3 = this.wrapClassName("maximized"), i3 = "box-maximized-timer";
4282
- return this._state$.subscribe((s3) => {
4283
- 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(() => {
4284
- this.$box.classList.toggle(t3, false);
4285
- }, 0, i3);
4286
- });
4287
- }), this._sideEffect.addDisposer(this._visible$.subscribe((e3) => {
4288
- this.$box.style.display = e3 ? "block" : "none";
4289
- })), this._sideEffect.addDisposer(this._zIndex$.subscribe((e3) => {
4290
- this.$box.style.zIndex = String(e3);
4291
- })), this.$box.dataset.teleBoxID = this.id;
4292
- const t2 = index(this.$box), i2 = combine([this._maximized$, this._minimized$, this._pxIntrinsicSize$, this._pxIntrinsicCoord$, this._collectorRect$], ([e3, t3, i3, s3, a3]) => {
4293
- 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 };
4294
- if (t3 && a3) {
4295
- const { width: t4, height: s4 } = e3 ? this.rootRect : i3;
4296
- 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;
4297
- }
4298
- return n3;
4299
- }, { compare: shallowequal }), s2 = i2.value;
4300
- 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) => {
4301
- 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);
4302
4641
  }));
4303
- const a2 = document.createElement("div");
4304
- a2.className = this.wrapClassName("box-main"), this.$box.appendChild(a2);
4305
- const n2 = document.createElement("div");
4306
- n2.className = this.wrapClassName("titlebar-wrap"), n2.appendChild(this.titleBar.render()), this.$titleBar = n2;
4307
- const o2 = document.createElement("div");
4308
- o2.className = this.wrapClassName("content-wrap");
4309
- const r2 = document.createElement("div");
4310
- r2.className = this.wrapClassName("content") + " tele-fancy-scrollbar", this.$content = r2;
4311
- const h = () => {
4312
- const e3 = r2.getBoundingClientRect();
4313
- 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
+ });
4314
4697
  };
4315
4698
  this._sideEffect.add(() => {
4316
- const e3 = new W$3(() => {
4317
- this.minimized || h();
4318
- });
4319
- return e3.observe(r2), () => e3.disconnect();
4320
- }), this._sideEffect.addDisposer(this._minimized$.reaction((e3) => {
4321
- e3 || this._sideEffect.setTimeout(h, 400, "minimized-content-rect-fix");
4322
- })), this._sideEffect.add(() => {
4323
- let e3;
4324
- return this._$userStyles$.subscribe((t3) => {
4325
- e3 && e3.remove(), e3 = t3, t3 && o2.appendChild(t3);
4326
- });
4327
- }), this._sideEffect.add(() => {
4328
- let e3;
4329
- return this._$userContent$.subscribe((t3) => {
4330
- e3 && e3.remove(), e3 = t3, t3 && r2.appendChild(t3);
4331
- });
4332
- }), this._sideEffect.add(() => {
4333
- let e3;
4334
- return this._$userStage$.subscribe((t3) => {
4335
- var i3;
4336
- if (e3 && e3.remove(), e3 = t3, t3) {
4337
- if (!this.$stage) {
4338
- const e4 = document.createElement("div");
4339
- this.$stage = e4, e4.className = this.wrapClassName("content-stage"), this._sideEffect.addDisposer(this._contentStageRect$.subscribe((t4) => {
4340
- e4.style.top = t4.y + "px", e4.style.left = t4.x + "px", e4.style.width = t4.width + "px", e4.style.height = t4.height + "px";
4341
- }), "content-stage-rect"), r2.appendChild(e4);
4342
- }
4343
- this.$stage.parentElement || r2.appendChild(this.$stage), this.$stage.appendChild(t3);
4344
- } else
4345
- ((i3 = this.$stage) == null ? void 0 : i3.parentElement) && this.$stage.remove();
4346
- });
4347
- }), o2.appendChild(r2);
4348
- const c = document.createElement("div");
4349
- return c.className = this.wrapClassName("footer-wrap"), this.$footer = c, this._sideEffect.add(() => {
4350
- let e3;
4351
- return this._$userFooter$.subscribe((t3) => {
4352
- e3 && e3.remove(), e3 = t3, t3 && c.appendChild(t3);
4699
+ const observer = new ResizeObserver$1$1(() => {
4700
+ if (!this.minimized) {
4701
+ updateBodyRect();
4702
+ }
4353
4703
  });
4354
- }), 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;
4355
4731
  }
4356
4732
  _renderResizeHandlers() {
4357
- const e2 = document.createElement("div");
4358
- e2.className = this.wrapClassName("resize-handles"), Object.values(N$3).forEach((t3) => {
4359
- const i3 = document.createElement("div");
4360
- i3.className = this.wrapClassName(t3) + " " + this.wrapClassName("resize-handle"), i3.dataset.teleBoxHandle = t3, e2.appendChild(i3);
4361
- }), this.$box.appendChild(e2);
4362
- const t2 = "handle-tracking-listener", i2 = this.wrapClassName("transforming");
4363
- let s2, a2, n2 = 0, o2 = 0, r2 = 0, h = 0, l2 = 0, d2 = 0;
4364
- const c = (e3) => {
4365
- 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) {
4366
4754
  return;
4367
- k$1(e3);
4368
- let { pageX: t3, pageY: i3 } = R$3(e3);
4369
- i3 < this.rootRect.y && (i3 = this.rootRect.y);
4370
- const s3 = t3 - l2, c2 = i3 - d2;
4371
- let { x: m3, y: u3 } = this.pxIntrinsicCoord, { width: g2, height: p2 } = this.pxIntrinsicSize;
4372
- switch (a2) {
4373
- case N$3.North:
4374
- 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;
4375
4769
  break;
4376
- case N$3.South:
4377
- p2 = h + c2;
4770
+ }
4771
+ case TELE_BOX_RESIZE_HANDLE.South: {
4772
+ newHeight = trackStartHeight + offsetY;
4378
4773
  break;
4379
- case N$3.West:
4380
- m3 = n2 + s3, g2 = r2 - s3;
4774
+ }
4775
+ case TELE_BOX_RESIZE_HANDLE.West: {
4776
+ newX = trackStartX + offsetX;
4777
+ newWidth = trackStartWidth - offsetX;
4381
4778
  break;
4382
- case N$3.East:
4383
- g2 = r2 + s3;
4779
+ }
4780
+ case TELE_BOX_RESIZE_HANDLE.East: {
4781
+ newWidth = trackStartWidth + offsetX;
4384
4782
  break;
4385
- case N$3.NorthWest:
4386
- 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;
4387
4789
  break;
4388
- case N$3.NorthEast:
4389
- 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;
4390
4795
  break;
4391
- case N$3.SouthEast:
4392
- g2 = r2 + s3, p2 = h + c2;
4796
+ }
4797
+ case TELE_BOX_RESIZE_HANDLE.SouthEast: {
4798
+ newWidth = trackStartWidth + offsetX;
4799
+ newHeight = trackStartHeight + offsetY;
4393
4800
  break;
4394
- case N$3.SouthWest:
4395
- 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;
4396
4806
  break;
4397
- default:
4398
- return void this.move(n2 + s3, o2 + c2);
4399
- }
4400
- this.transform(m3, u3, g2, p2);
4401
- }, m2 = (e3) => {
4402
- a2 = void 0, s2 && (k$1(e3), this.$box.classList.toggle(i2, false), this._sideEffect.flush(t2), s2.remove());
4403
- }, u2 = (e3) => {
4404
- var u3;
4405
- 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) {
4817
+ return;
4818
+ }
4819
+ trackingHandle = void 0;
4820
+ if (!$trackMask) {
4821
+ return;
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) {
4406
4831
  return;
4407
- if (e3.button != null && e3.button !== 0)
4832
+ }
4833
+ if (ev.button != null && ev.button !== 0) {
4408
4834
  return;
4409
- if (!this.draggable || a2 || this.state !== C$3.Normal)
4835
+ }
4836
+ if (!this.draggable || trackingHandle || this.state !== TELE_BOX_STATE.Normal) {
4410
4837
  return;
4411
- const g2 = e3.target;
4412
- if ((u3 = g2.dataset) == null ? void 0 : u3.teleBoxHandle) {
4413
- 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"));
4414
- const u4 = a2 ? this.wrapClassName(`cursor-${a2}`) : "";
4415
- 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 }), () => {
4416
- window.removeEventListener("mousemove", c), window.removeEventListener("touchmove", c), window.removeEventListener("mouseup", m2), window.removeEventListener("touchend", m2), window.removeEventListener("touchcancel", m2);
4417
- }), t2);
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);
4418
4869
  }
4419
4870
  };
4420
- 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");
4421
4873
  }
4422
4874
  async destroy() {
4423
- this.$box.remove(), this._sideEffect.flushAll(), this._sideEffect.flushAll(), await this.events.emit(E$3.Destroyed), this.events.clearListeners(), this._delegateEvents.clearListeners();
4424
- }
4425
- wrapClassName(e2) {
4426
- return `${this.namespace}-${e2}`;
4427
- }
4428
- }
4429
- var X$3, P$3;
4430
- class O$3 {
4431
- constructor({ minimized$: e2, readonly$: t2, darkMode$: i2, namespace: s2 = "telebox", styles: a2 = {}, root$: n2 }) {
4432
- this._sideEffect = new SideEffectManager(), this.namespace = s2;
4433
- const o2 = new ValManager();
4434
- this._sideEffect.addDisposer(() => o2.destroy());
4435
- const r2 = new Val(void 0), h = derive(e2), l2 = new Val(a2), d2 = new Val(document.createElement("button"));
4436
- withValueEnhancer(this, { styles: l2, $collector: d2 }, o2);
4437
- withReadonlyValueEnhancer(this, { root: n2 });
4438
- 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) => {
4439
- this._sideEffect.addEventListener(s3, "click", () => {
4440
- t2.value || e2.setValue(false);
4441
- }, {}, "telebox-collector-click"), this._sideEffect.addDisposer([h.subscribe((e3) => {
4442
- s3.classList.toggle(this.wrapClassName("collector-visible"), e3);
4443
- }), t2.subscribe((e3) => {
4444
- s3.classList.toggle(this.wrapClassName("collector-readonly"), e3);
4445
- }), i2.subscribe((e3) => {
4446
- s3.classList.toggle(this.wrapClassName("color-scheme-dark"), e3), s3.classList.toggle(this.wrapClassName("color-scheme-light"), !e3);
4447
- }), l2.subscribe((e3) => {
4448
- Object.keys(e3).forEach((t3) => {
4449
- const i3 = e3[t3];
4450
- i3 != null && (s3.style[t3] = i3);
4451
- });
4452
- }), n2.subscribe((e3) => {
4453
- e3 && e3.appendChild(s3);
4454
- }), combine([e2, n2]).subscribe(([e3, t3]) => {
4455
- if (e3 && t3) {
4456
- const { x: e4, y: i3, width: a3, height: n3 } = s3.getBoundingClientRect(), o3 = t3.getBoundingClientRect();
4457
- r2.setValue({ x: e4 - o3.x, y: i3 - o3.y, width: a3, height: n3 });
4458
- }
4459
- })], "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");
4460
4963
  }));
4461
4964
  }
4462
4965
  destroy() {
4463
4966
  this._sideEffect.flushAll();
4464
4967
  }
4465
- wrapClassName(e2) {
4466
- return `${this.namespace}-${e2}`;
4968
+ wrapClassName(className) {
4969
+ return `${this.namespace}-${className}`;
4467
4970
  }
4468
4971
  }
4469
- (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";
4470
- class j$1 extends H$3 {
4471
- constructor(e2) {
4472
- super(e2), this.boxes$ = e2.boxes$, this.rootRect$ = e2.rootRect$, this.darkMode$ = e2.darkMode$, this.sideEffect.addDisposer(e2.root$.subscribe((e3) => {
4473
- var t2;
4474
- e3 ? e3.appendChild(this.render()) : ((t2 = this.$titleBar) == null ? void 0 : t2.parentNode) && this.$titleBar.remove();
4475
- }));
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());
4476
4994
  }
4477
- focusBox(e2) {
4478
- var t2;
4479
- if (!this.focusedBox || this.focusedBox !== e2) {
4480
- if (this.$titles && this.state$.value === C$3.Maximized) {
4481
- const { children: i2 } = this.$titles.firstElementChild;
4482
- for (let s2 = i2.length - 1; s2 >= 0; s2 -= 1) {
4483
- const a2 = i2[s2], n2 = (t2 = a2.dataset) == null ? void 0 : t2.teleBoxID;
4484
- 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
+ }
4485
5011
  }
4486
5012
  }
4487
- this.focusedBox = e2;
4488
5013
  }
5014
+ this.focusedBox = box;
4489
5015
  }
4490
5016
  render() {
4491
- if (this.$titleBar)
5017
+ if (this.$titleBar) {
4492
5018
  return this.$titleBar;
4493
- const e2 = super.render();
4494
- e2.classList.add(this.wrapClassName("max-titlebar")), this.sideEffect.addDisposer([this.state$.subscribe((t3) => {
4495
- e2.classList.toggle(this.wrapClassName("max-titlebar-maximized"), t3 === C$3.Maximized);
4496
- }), this.readonly$.subscribe((t3) => {
4497
- e2.classList.toggle(this.wrapClassName("readonly"), t3);
4498
- }), this.darkMode$.subscribe((t3) => {
4499
- e2.classList.toggle(this.wrapClassName("color-scheme-dark"), t3), e2.classList.toggle(this.wrapClassName("color-scheme-light"), !t3);
4500
- }), combine([this.state$, this.boxes$]).subscribe(([t3, i2]) => {
4501
- 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));
4502
- })], "max-render");
4503
- const t2 = document.createElement("div");
4504
- 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;
4505
5042
  }
4506
5043
  destroy() {
4507
- super.destroy(), this.$titles = void 0, this.focusedBox = void 0;
5044
+ super.destroy();
5045
+ this.$titles = void 0;
5046
+ this.focusedBox = void 0;
4508
5047
  }
4509
5048
  renderTitles() {
4510
- this.$titles = document.createElement("div"), this.$titles.className = this.wrapClassName("titles"), this.sideEffect.addEventListener(this.$titles, "wheel", (e3) => {
4511
- 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
+ });
4512
5056
  }, { passive: false }, "max-render-wheel-titles");
4513
- const e2 = document.createElement("div");
4514
- e2.className = this.wrapClassName("titles-content"), this.$titles.appendChild(e2);
4515
- const t2 = this.boxes$.value.map((t3) => {
4516
- const i2 = document.createElement("button");
4517
- 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);
4518
5071
  });
4519
- 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;
4520
5074
  }
4521
5075
  }
4522
- const Z$3 = window.ResizeObserver || ResizeObserver$2;
4523
- class F$3 {
4524
- 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 } = {}) {
4525
- this.events = new Emittery(), this._sideEffect = new SideEffectManager(), this.namespace = o2;
4526
- const b2 = new ValManager();
4527
- this._sideEffect.addDisposer(() => b2.destroy());
4528
- 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 });
4529
- 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) => {
4530
5115
  this._sideEffect.add(() => {
4531
- if (!e3)
4532
- return () => {
4533
- };
4534
- const t3 = new Z$3(() => {
4535
- const t4 = e3.getBoundingClientRect();
4536
- 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
+ });
4537
5127
  });
4538
- return t3.observe(e3), () => t3.disconnect();
5128
+ observer.observe(root2);
5129
+ return () => observer.disconnect();
4539
5130
  }, "calc-root-rect");
4540
- })), this.boxes$ = new Val([]), this.topBox$ = new Val(void 0), this._sideEffect.addDisposer(this.boxes$.subscribe((e3) => {
4541
- if (e3.length > 0) {
4542
- const t3 = e3.reduce((e4, t4) => e4.zIndex > t4.zIndex ? e4 : t4);
4543
- this.topBox$.setValue(t3);
4544
- } else
4545
- this.topBox$.setValue(void 0);
4546
5131
  }));
4547
- const k2 = window.matchMedia("(prefers-color-scheme: dark)"), R2 = new Val(false);
4548
- k2 && (R2.setValue(k2.matches), this._sideEffect.add(() => {
4549
- const e3 = (e4) => {
4550
- R2.setValue(e4.matches);
4551
- };
4552
- 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
+ }
4553
5144
  }));
4554
- const D2 = new Val(t2);
4555
- this._sideEffect.addDisposer(D2.reaction((e3, t3) => {
4556
- 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
+ }
4557
5162
  }));
4558
- 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);
4559
- this.collector = n2 != null ? n2 : new O$3({ minimized$: z2, readonly$: y2, darkMode$: L2, namespace: o2, root$: w2 });
4560
- const V2 = new A$2({ namespace: o2, rootRect$: I2, ratio$: S2, root$: w2, highlightStage$: combine([M2, B2, z2], ([e3, t3, i3]) => e3 && (i3 || !t3)) });
4561
- this._sideEffect.addDisposer(() => V2.destroy());
4562
- const H2 = { darkMode: L2, state: T2, root: w2, rootRect: I2, stageRect: V2.stageRect$ };
4563
- withReadonlyValueEnhancer(this, H2, b2);
4564
- withValueEnhancer(this, { prefersColorScheme: D2, readonly: y2, fence: N2, minimized: z2, maximized: B2, stageRatio: S2, highlightStage: M2 }, b2);
4565
- const W2 = this.wrapClassName("titlebar-icon-close"), Y2 = (e3) => {
4566
- var t3;
4567
- 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) {
4568
5197
  return;
4569
- const i3 = e3.target;
4570
- if (i3.tagName)
4571
- for (let s3 = i3; s3; s3 = s3.parentElement) {
4572
- if (s3.classList && s3.classList.contains(W2))
5198
+ }
5199
+ const target = ev.target;
5200
+ if (!target.tagName) {
5201
+ return;
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);
4573
5213
  return;
4574
- const e4 = (t3 = s3.dataset) == null ? void 0 : t3.teleBoxID;
4575
- if (e4) {
4576
- const t4 = this.getBox(e4);
4577
- if (t4)
4578
- return this.focusBox(t4), void this.makeBoxTop(t4);
4579
5214
  }
4580
5215
  }
5216
+ }
4581
5217
  };
4582
- 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) => {
4583
- switch (e3.type) {
4584
- case _.Maximize:
4585
- B2.setValue(!B2.value);
4586
- break;
4587
- case _.Minimize:
4588
- z2.setValue(true);
4589
- break;
4590
- case E$3.Close:
4591
- this.removeTopBox(), this.focusTopBox();
4592
- }
4593
- } }), this._sideEffect.addDisposer([T2.reaction((e3, t3) => {
4594
- t3 || this.events.emit(X$3.State, e3);
4595
- }), B2.reaction((e3, t3) => {
4596
- t3 || this.events.emit(X$3.Maximized, e3);
4597
- }), z2.reaction((e3, t3) => {
4598
- t3 || this.events.emit(X$3.Minimized, e3);
4599
- }), L2.reaction((e3, t3) => {
4600
- t3 || this.events.emit(X$3.DarkMode, e3);
4601
- })]);
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
+ ]);
4602
5304
  }
4603
5305
  get boxes() {
4604
5306
  return this.boxes$.value;
@@ -4606,143 +5308,300 @@ class F$3 {
4606
5308
  get topBox() {
4607
5309
  return this.topBox$.value;
4608
5310
  }
4609
- setState(e2, t2 = false) {
4610
- switch (e2) {
4611
- case C$3.Maximized:
4612
- 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);
4613
5316
  break;
4614
- case C$3.Minimized:
4615
- 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);
4616
5321
  break;
4617
- default:
4618
- this.setMinimized(false, t2), this.setMaximized(false, t2);
5322
+ }
5323
+ default: {
5324
+ this.setMinimized(false, skipUpdate);
5325
+ this.setMaximized(false, skipUpdate);
5326
+ break;
5327
+ }
4619
5328
  }
4620
5329
  return this;
4621
5330
  }
4622
- create(e2 = {}, s2 = true) {
4623
- 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))));
4624
- var n2, o2;
4625
- return a2.focus && (this.focusBox(a2), s2 && this.makeBoxTop(a2)), this.boxes$.setValue([...this.boxes, a2]), this._sideEffect.addDisposer([a2._delegateEvents.on(_.Maximize, () => {
4626
- this.setMaximized(!this.maximized);
4627
- }), a2._delegateEvents.on(_.Minimize, () => {
4628
- this.setMinimized(true);
4629
- }), a2._delegateEvents.on(_.Close, () => {
4630
- this.remove(a2), this.focusTopBox();
4631
- }), a2._intrinsicCoord$.reaction((e3, t2) => {
4632
- t2 || this.events.emit(X$3.IntrinsicMove, a2);
4633
- }), a2._intrinsicSize$.reaction((e3, t2) => {
4634
- t2 || this.events.emit(X$3.IntrinsicResize, a2);
4635
- }), a2._zIndex$.reaction((e3, t2) => {
4636
- if (this.boxes.length > 0) {
4637
- const e4 = this.boxes.reduce((e5, t3) => e5.zIndex > t3.zIndex ? e5 : t3);
4638
- this.topBox$.setValue(e4);
4639
- }
4640
- t2 || this.events.emit(X$3.ZIndex, a2);
4641
- })]), this.events.emit(X$3.Created, a2), a2;
4642
- }
4643
- query(e2) {
4644
- return e2 ? this.boxes.filter(this.teleBoxMatcher(e2)) : [...this.boxes];
4645
- }
4646
- queryOne(e2) {
4647
- return e2 ? this.boxes.find(this.teleBoxMatcher(e2)) : this.boxes[0];
4648
- }
4649
- update(e2, t2, i2 = false) {
4650
- const s2 = this.boxes.find((t3) => t3.id === e2);
4651
- if (s2)
4652
- 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];
5392
+ }
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
+ }
4653
5401
  }
4654
- updateAll(e2, t2 = false) {
4655
- this.boxes.forEach((i2) => {
4656
- this.updateBox(i2, e2, t2);
5402
+ updateAll(config, skipUpdate = false) {
5403
+ this.boxes.forEach((box) => {
5404
+ this.updateBox(box, config, skipUpdate);
4657
5405
  });
4658
5406
  }
4659
- remove(e2, t2 = false) {
4660
- const i2 = this.getBoxIndex(e2);
4661
- if (i2 >= 0) {
4662
- const e3 = this.boxes.slice(), s2 = e3.splice(i2, 1);
4663
- 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];
4664
5422
  }
5423
+ return;
4665
5424
  }
4666
5425
  removeTopBox() {
4667
- if (this.topBox)
5426
+ if (this.topBox) {
4668
5427
  return this.remove(this.topBox);
5428
+ }
5429
+ return;
4669
5430
  }
4670
- removeAll(e2 = false) {
4671
- const t2 = this.boxes$.value;
4672
- 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;
4673
5443
  }
4674
- mount(e2) {
4675
- this._root$.setValue(e2);
5444
+ mount(root) {
5445
+ this._root$.setValue(root);
4676
5446
  }
4677
5447
  unmount() {
4678
5448
  this._root$.setValue(null);
4679
5449
  }
4680
- destroy(e2 = false) {
4681
- 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();
4682
5456
  }
4683
- wrapClassName(e2) {
4684
- return `${this.namespace}-${e2}`;
5457
+ wrapClassName(className) {
5458
+ return `${this.namespace}-${className}`;
4685
5459
  }
4686
- focusBox(e2, t2 = false) {
4687
- const i2 = this.getBox(e2);
4688
- i2 && (this.boxes.forEach((e3) => {
4689
- if (i2 === e3) {
4690
- let e4 = false;
4691
- i2.focus || (e4 = true, i2._focus$.setValue(true, t2)), e4 && !t2 && this.events.emit(X$3.Focused, i2);
4692
- } else
4693
- e3.focus && this.blurBox(e3, t2);
4694
- }), 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
+ }
4695
5479
  }
4696
5480
  focusTopBox() {
4697
- if (this.topBox && !this.topBox.focus)
5481
+ if (this.topBox && !this.topBox.focus) {
4698
5482
  return this.focusBox(this.topBox);
5483
+ }
4699
5484
  }
4700
- blurBox(e2, t2 = false) {
4701
- const i2 = this.getBox(e2);
4702
- i2 && (i2.focus && (i2._focus$.setValue(false, t2), t2 || this.events.emit(X$3.Blurred, i2)), this.titleBar.focusedBox === i2 && this.titleBar.focusBox());
4703
- }
4704
- blurAll(e2 = false) {
4705
- this.boxes.forEach((t2) => {
4706
- t2.focus && (t2._focus$.setValue(false, e2), e2 || this.events.emit(X$3.Blurred, t2));
4707
- }), this.titleBar.focusedBox && this.titleBar.focusBox();
4708
- }
4709
- teleBoxMatcher(e2) {
4710
- const t2 = Object.keys(e2);
4711
- return (i2) => t2.every((t3) => e2[t3] === i2[t3]);
4712
- }
4713
- updateBox(e2, t2, i2 = false) {
4714
- var s2, a2, n2, o2, r2, h;
4715
- 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
+ }
4716
5498
  }
4717
- smartPosition(e2) {
4718
- let { x: t2, y: i2 } = e2;
4719
- const { width: s2 = 0.5, height: a2 = 0.5 } = e2, n2 = this.stageRect, o2 = this.topBox;
4720
- if (t2 == null) {
4721
- let e3 = n2.x + 20;
4722
- if (o2) {
4723
- const t3 = o2.pxIntrinsicCoord.x + 20;
4724
- 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
+ }
5506
+ }
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
+ }
4725
5577
  }
4726
- t2 = (e3 - n2.x) / n2.width;
5578
+ x2 = pxX / stageRect.width;
4727
5579
  }
4728
- if (i2 == null) {
4729
- let e3 = n2.y + 20;
4730
- if (o2) {
4731
- const t3 = o2.pxIntrinsicCoord.y + 20;
4732
- 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
+ }
4733
5588
  }
4734
- i2 = (e3 - n2.y) / n2.height;
5589
+ y2 = pxY / stageRect.height;
4735
5590
  }
4736
- return { x: t2, y: i2, width: s2, height: a2 };
5591
+ return { x: x2, y: y2, width, height };
4737
5592
  }
4738
- makeBoxTop(e2, t2 = false) {
4739
- 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
+ }
4740
5599
  }
4741
- getBoxIndex(e2) {
4742
- 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);
4743
5602
  }
4744
- getBox(e2) {
4745
- 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;
4746
5605
  }
4747
5606
  }
4748
5607
  const createBoxManager = (manager, callbacks2, emitter2, boxEmitter2, options) => {
@@ -4773,15 +5632,6 @@ const createBoxManager = (manager, callbacks2, emitter2, boxEmitter2, options) =
4773
5632
  class BoxManager {
4774
5633
  constructor(context, createTeleBoxManagerConfig) {
4775
5634
  this.context = context;
4776
- this.mainViewElement$ = new Val(void 0);
4777
- this.updateStyle = (element2, rect) => {
4778
- if (!element2)
4779
- return;
4780
- element2.style.width = rect.width + "px";
4781
- element2.style.height = rect.height + "px";
4782
- element2.style.left = rect.x + "px";
4783
- element2.style.top = rect.y + "px";
4784
- };
4785
5635
  this.sideEffectManager = new SideEffectManager();
4786
5636
  const { emitter: emitter2, callbacks: callbacks2, boxEmitter: boxEmitter2 } = context;
4787
5637
  this.teleBoxManager = this.setupBoxManager(createTeleBoxManagerConfig);
@@ -4849,14 +5699,6 @@ class BoxManager {
4849
5699
  this.teleBoxManager.events.on("z_index", (box) => {
4850
5700
  this.context.updateAppState(box.id, AppAttributes.ZIndex, box.zIndex);
4851
5701
  }),
4852
- this.teleBoxManager._stageRect$.subscribe((stage) => {
4853
- this.updateStyle(this.mainViewElement$.value, stage);
4854
- emitter2.emit("playgroundSizeChange", stage);
4855
- this.context.notifyContainerRectUpdate(stage);
4856
- }),
4857
- emitter2.on("writableChange", (isWritable) => {
4858
- this.teleBoxManager.setHighlightStage(isWritable);
4859
- }),
4860
5702
  emitter2.on("containerSizeRatioUpdate", (ratio) => {
4861
5703
  this.teleBoxManager._stageRatio$.setValue(ratio);
4862
5704
  })
@@ -4893,7 +5735,7 @@ class BoxManager {
4893
5735
  var _a, _b, _c;
4894
5736
  if (!this.teleBoxManager)
4895
5737
  return;
4896
- 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 : {};
4897
5739
  const { width, height } = (_b = params.app.config) != null ? _b : {};
4898
5740
  const title = ((_c = params.options) == null ? void 0 : _c.title) || params.appId;
4899
5741
  const rect = this.teleBoxManager.rootRect;
@@ -4909,7 +5751,8 @@ class BoxManager {
4909
5751
  minHeight: minheight,
4910
5752
  width,
4911
5753
  height,
4912
- id: params.appId
5754
+ id: params.appId,
5755
+ enableShadowDOM
4913
5756
  };
4914
5757
  const box = this.teleBoxManager.create(createBoxConfig, params.smartPosition);
4915
5758
  this.context.emitter.emit(`${params.appId}${Events.WindowCreated}`);
@@ -4921,10 +5764,15 @@ class BoxManager {
4921
5764
  stageRatio: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.stageRatio,
4922
5765
  root,
4923
5766
  fence: false,
4924
- prefersColorScheme: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.prefersColorScheme,
4925
- highlightStage: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.highlightStage
5767
+ prefersColorScheme: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.prefersColorScheme
4926
5768
  };
4927
- 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);
4928
5776
  if (this.teleBoxManager) {
4929
5777
  this.teleBoxManager.destroy();
4930
5778
  }
@@ -4956,18 +5804,19 @@ class BoxManager {
4956
5804
  return this.teleBoxManager.topBox;
4957
5805
  }
4958
5806
  updateBoxState(state) {
4959
- var _a, _b, _c, _d;
4960
5807
  if (!state)
4961
5808
  return;
4962
5809
  const box = this.getBox(state.id);
4963
5810
  if (box) {
4964
- this.teleBoxManager.update(box.id, {
4965
- x: (_a = state.position) == null ? void 0 : _a.x,
4966
- y: (_b = state.position) == null ? void 0 : _b.y,
4967
- width: ((_c = state.size) == null ? void 0 : _c.width) || 0.5,
4968
- height: ((_d = state.size) == null ? void 0 : _d.height) || 0.5,
4969
- zIndex: state.zIndex
4970
- }, 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
+ }
4971
5820
  setTimeout(() => {
4972
5821
  if (state.focus) {
4973
5822
  this.teleBoxManager.focusBox(box.id, true);
@@ -4983,13 +5832,19 @@ class BoxManager {
4983
5832
  }
4984
5833
  }
4985
5834
  moveBox({ appId, x: x2, y: y2 }) {
4986
- 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
+ }
4987
5839
  }
4988
5840
  focusBox({ appId }, skipUpdate = true) {
4989
5841
  this.teleBoxManager.focusBox(appId, skipUpdate);
4990
5842
  }
4991
5843
  resizeBox({ appId, width, height, skipUpdate }) {
4992
- this.teleBoxManager.update(appId, { width, height }, skipUpdate);
5844
+ const box = this.getBox(appId);
5845
+ if (box) {
5846
+ box._intrinsicSize$.setValue({ width, height }, skipUpdate);
5847
+ }
4993
5848
  }
4994
5849
  setBoxMinSize(params) {
4995
5850
  this.teleBoxManager.update(params.appId, {
@@ -15666,6 +16521,10 @@ const BuiltinApps = {
15666
16521
  DocsViewer: NetlessAppDocsViewer.kind,
15667
16522
  MediaPlayer: K.kind
15668
16523
  };
16524
+ const BuiltinAppsMap = {
16525
+ [BuiltinApps.DocsViewer]: NetlessAppDocsViewer,
16526
+ [BuiltinApps.MediaPlayer]: K
16527
+ };
15669
16528
  var videoJs = "";
15670
16529
  var style$1 = "";
15671
16530
  var style = "";
@@ -15673,15 +16532,15 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
15673
16532
  const _WindowManager = class extends InvisiblePlugin {
15674
16533
  constructor(context) {
15675
16534
  super(context);
15676
- this.version = "1.0.0-canary.25";
15677
- 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.28";
16536
+ this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.26", "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" } };
15678
16537
  this.emitter = callbacks$1;
15679
16538
  this.viewMode = ViewMode.Broadcaster;
15680
16539
  this.viewMode$ = new Val(ViewMode.Broadcaster);
15681
16540
  this.isReplay = isPlayer(this.displayer);
15682
16541
  this.containerSizeRatio = _WindowManager.containerSizeRatio;
15683
16542
  _WindowManager.displayer = context.displayer;
15684
- 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.26", "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" } };
15685
16544
  }
15686
16545
  static async mount(params) {
15687
16546
  var _a;
@@ -15736,7 +16595,8 @@ const _WindowManager = class extends InvisiblePlugin {
15736
16595
  collectorStyles: params.collectorStyles,
15737
16596
  prefersColorScheme: params.prefersColorScheme,
15738
16597
  stageRatio: _WindowManager.containerSizeRatio,
15739
- highlightStage: params.highlightStage
16598
+ containerStyle: params.containerStyle,
16599
+ stageStyle: params.stageStyle
15740
16600
  });
15741
16601
  (_a = manager.appManager) == null ? void 0 : _a.setBoxManager(manager.boxManager);
15742
16602
  if (params.container) {
@@ -15774,11 +16634,11 @@ const _WindowManager = class extends InvisiblePlugin {
15774
16634
  }
15775
16635
  return manager;
15776
16636
  }
15777
- static initContainer(container, overwriteStyles) {
16637
+ static initContainer(container, target, overwriteStyles) {
15778
16638
  if (!_WindowManager.container) {
15779
16639
  _WindowManager.container = container;
15780
16640
  }
15781
- const { playground, mainViewElement } = setupWrapper(container);
16641
+ const { playground, mainViewElement } = setupWrapper(container, target);
15782
16642
  _WindowManager.playground = playground;
15783
16643
  if (overwriteStyles) {
15784
16644
  const style2 = document.createElement("style");
@@ -15791,7 +16651,7 @@ const _WindowManager = class extends InvisiblePlugin {
15791
16651
  return appRegister.registered;
15792
16652
  }
15793
16653
  bindContainer(container) {
15794
- var _a, _b, _c, _d, _e;
16654
+ var _a, _b, _c, _d, _e, _f;
15795
16655
  if (isRoom(this.displayer) && this.room.phase !== RoomPhase.Connected) {
15796
16656
  throw new BindContainerRoomPhaseInvalidError();
15797
16657
  }
@@ -15800,24 +16660,24 @@ const _WindowManager = class extends InvisiblePlugin {
15800
16660
  container.appendChild(_WindowManager.container.firstChild);
15801
16661
  }
15802
16662
  } else {
15803
- if (_WindowManager.params) {
16663
+ const teleboxContainer = (_a = this.boxManager) == null ? void 0 : _a.teleBoxManager.$stage;
16664
+ if (_WindowManager.params && teleboxContainer) {
15804
16665
  const params = _WindowManager.params;
15805
- const mainViewElement = _WindowManager.initContainer(container, params.overwriteStyles);
16666
+ const mainViewElement = _WindowManager.initContainer(container, teleboxContainer, params.overwriteStyles);
15806
16667
  if (this.boxManager && _WindowManager.playground) {
15807
16668
  this.boxManager.setRoot(_WindowManager.playground);
15808
- this.boxManager.mainViewElement$.setValue(mainViewElement);
15809
16669
  }
15810
16670
  this.bindMainView(mainViewElement, params.disableCameraTransform);
15811
16671
  if (_WindowManager.playground) {
15812
- (_a = this.cursorManager) == null ? void 0 : _a.setupWrapper(_WindowManager.playground);
16672
+ (_b = this.cursorManager) == null ? void 0 : _b.setupWrapper(_WindowManager.playground);
15813
16673
  }
15814
16674
  }
15815
16675
  }
15816
16676
  emitter.emit("updateManagerRect");
15817
- (_b = this.appManager) == null ? void 0 : _b.refresh();
15818
- (_c = this.appManager) == null ? void 0 : _c.resetMaximized();
15819
- (_d = this.appManager) == null ? void 0 : _d.resetMinimized();
15820
- (_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);
15821
16681
  _WindowManager.container = container;
15822
16682
  }
15823
16683
  bindCollectorContainer(container) {
@@ -16076,6 +16936,20 @@ const _WindowManager = class extends InvisiblePlugin {
16076
16936
  throw new AppManagerNotInitError();
16077
16937
  }
16078
16938
  }
16939
+ get baseCamera$() {
16940
+ if (this.appManager) {
16941
+ return this.appManager.mainViewProxy.camera$;
16942
+ } else {
16943
+ throw new AppManagerNotInitError();
16944
+ }
16945
+ }
16946
+ get baseSize$() {
16947
+ if (this.appManager) {
16948
+ return this.appManager.mainViewProxy.size$;
16949
+ } else {
16950
+ throw new AppManagerNotInitError();
16951
+ }
16952
+ }
16079
16953
  get cameraState() {
16080
16954
  if (this.appManager) {
16081
16955
  return this.appManager.mainViewProxy.cameraState;
@@ -16169,26 +17043,31 @@ const _WindowManager = class extends InvisiblePlugin {
16169
17043
  return (_a = this.appManager) == null ? void 0 : _a.closeApp(appId);
16170
17044
  }
16171
17045
  moveCamera(camera) {
16172
- var _a;
16173
- const pureCamera = omit(camera, ["animationMode"]);
16174
17046
  const mainViewCamera = __spreadValues({}, this.mainView.camera);
16175
- if (isEqual(__spreadValues(__spreadValues({}, mainViewCamera), pureCamera), mainViewCamera))
17047
+ const nextCamera = __spreadValues(__spreadValues({}, mainViewCamera), camera);
17048
+ if (isEqual(nextCamera, mainViewCamera))
16176
17049
  return;
16177
- this.mainView.moveCamera(camera);
16178
- (_a = this.appManager) == null ? void 0 : _a.dispatchInternalEvent(Events.MoveCamera, camera);
16179
- setTimeout(() => {
16180
- var _a2;
16181
- (_a2 = this.appManager) == null ? void 0 : _a2.mainViewProxy.storeCurrentCamera();
16182
- }, 500);
17050
+ if (!this.appManager)
17051
+ return;
17052
+ this.appManager.mainViewProxy.storeCamera(__spreadValues({
17053
+ id: this.appManager.uid
17054
+ }, nextCamera));
16183
17055
  }
16184
17056
  moveCameraToContain(rectangle) {
16185
- var _a;
16186
- this.mainView.moveCameraToContain(rectangle);
16187
- (_a = this.appManager) == null ? void 0 : _a.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
16188
- setTimeout(() => {
16189
- var _a2;
16190
- (_a2 = this.appManager) == null ? void 0 : _a2.mainViewProxy.storeCurrentCamera();
16191
- }, 500);
17057
+ if (!this.appManager)
17058
+ return;
17059
+ const mainViewSize = this.appManager.mainViewProxy.size$.value;
17060
+ if (mainViewSize) {
17061
+ const wScale = mainViewSize.width / rectangle.width;
17062
+ const hScale = mainViewSize.height / rectangle.height;
17063
+ const nextScale = Math.min(wScale, hScale);
17064
+ this.appManager.mainViewProxy.storeCamera({
17065
+ id: this.appManager.uid,
17066
+ scale: nextScale,
17067
+ centerX: rectangle.originX,
17068
+ centerY: rectangle.originY
17069
+ });
17070
+ }
16192
17071
  }
16193
17072
  convertToPointInWorld(point) {
16194
17073
  return this.mainView.convertToPointInWorld(point);
@@ -16314,6 +17193,14 @@ const _WindowManager = class extends InvisiblePlugin {
16314
17193
  this.containerSizeRatio = ratio;
16315
17194
  emitter.emit("containerSizeRatioUpdate", ratio);
16316
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
+ }
16317
17204
  createPPTHandler() {
16318
17205
  return {
16319
17206
  onPageJumpTo: (_pptUUID, index2) => {
@@ -16368,4 +17255,4 @@ WindowManager.debug = false;
16368
17255
  WindowManager.containerSizeRatio = DEFAULT_CONTAINER_RATIO;
16369
17256
  WindowManager.isCreated = false;
16370
17257
  setupBuiltin();
16371
- 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 };