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

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