@netless/window-manager 1.0.0-canary.2 → 1.0.0-canary.20

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 (47) hide show
  1. package/__mocks__/white-web-sdk.ts +10 -1
  2. package/dist/App/AppContext.d.ts +6 -6
  3. package/dist/App/AppProxy.d.ts +30 -5
  4. package/dist/App/{WhiteBoardView.d.ts → WhiteboardView.d.ts} +10 -1
  5. package/dist/App/index.d.ts +1 -1
  6. package/dist/AppManager.d.ts +5 -5
  7. package/dist/AttributesDelegate.d.ts +11 -16
  8. package/dist/BoxManager.d.ts +3 -3
  9. package/dist/InternalEmitter.d.ts +2 -0
  10. package/dist/Page/PageController.d.ts +1 -0
  11. package/dist/ReconnectRefresher.d.ts +1 -1
  12. package/dist/Utils/Common.d.ts +1 -0
  13. package/dist/Utils/Reactive.d.ts +2 -0
  14. package/dist/View/CameraSynchronizer.d.ts +9 -9
  15. package/dist/View/MainView.d.ts +18 -7
  16. package/dist/View/ViewSync.d.ts +24 -0
  17. package/dist/constants.d.ts +6 -1
  18. package/dist/index.cjs.js +12 -12
  19. package/dist/index.d.ts +19 -2
  20. package/dist/index.es.js +791 -380
  21. package/dist/index.umd.js +12 -12
  22. package/dist/style.css +1 -1
  23. package/docs/app-context.md +98 -64
  24. package/docs/develop-app.md +2 -5
  25. package/docs/mirgrate-to-1.0.md +28 -0
  26. package/package.json +3 -3
  27. package/pnpm-lock.yaml +9 -9
  28. package/src/App/AppContext.ts +30 -19
  29. package/src/App/AppProxy.ts +251 -39
  30. package/src/App/{WhiteBoardView.ts → WhiteboardView.ts} +38 -4
  31. package/src/App/index.ts +1 -1
  32. package/src/AppManager.ts +33 -30
  33. package/src/AttributesDelegate.ts +18 -18
  34. package/src/BoxManager.ts +20 -15
  35. package/src/InternalEmitter.ts +2 -0
  36. package/src/Page/PageController.ts +1 -0
  37. package/src/PageState.ts +1 -1
  38. package/src/ReconnectRefresher.ts +2 -1
  39. package/src/Utils/Common.ts +6 -0
  40. package/src/Utils/Reactive.ts +43 -26
  41. package/src/Utils/RoomHacker.ts +3 -0
  42. package/src/View/CameraSynchronizer.ts +43 -30
  43. package/src/View/MainView.ts +106 -81
  44. package/src/View/ViewSync.ts +116 -0
  45. package/src/constants.ts +5 -0
  46. package/src/index.ts +59 -15
  47. package/src/style.css +8 -0
package/dist/index.es.js CHANGED
@@ -19,11 +19,11 @@ 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, isNumber, pick, throttle, delay, isInteger, orderBy, isEmpty, isFunction, isNull } from "lodash";
23
- import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, WhiteVersion, autorun, toJS, listenDisposed, unlistenDisposed, AnimationMode, isPlayer, isRoom, ApplianceNames, RoomPhase, InvisiblePlugin, ViewMode } from "white-web-sdk";
22
+ import { debounce, isEqual, omit, isObject, has, get, size as size$1, mapValues, noop as noop$1, pick, isNumber, throttle, delay, isInteger, orderBy, isEmpty, isFunction, isNull } from "lodash";
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
- import { Val, ValManager, combine, withReadonlyValueEnhancer, withValueEnhancer, derive } from "value-enhancer";
26
+ import { Val, combine, ValManager, withReadonlyValueEnhancer, withValueEnhancer, derive } from "value-enhancer";
27
27
  import { ResizeObserver as ResizeObserver$2 } from "@juggle/resize-observer";
28
28
  import p$1 from "video.js";
29
29
  var Events = /* @__PURE__ */ ((Events2) => {
@@ -54,6 +54,11 @@ var AppAttributes = /* @__PURE__ */ ((AppAttributes2) => {
54
54
  AppAttributes2["Position"] = "position";
55
55
  AppAttributes2["SceneIndex"] = "SceneIndex";
56
56
  AppAttributes2["ZIndex"] = "zIndex";
57
+ AppAttributes2["Visible"] = "visible";
58
+ AppAttributes2["Ratio"] = "ratio";
59
+ AppAttributes2["StageRatio"] = "stageRatio";
60
+ AppAttributes2["Draggable"] = "draggable";
61
+ AppAttributes2["Resizable"] = "resizable";
57
62
  return AppAttributes2;
58
63
  })(AppAttributes || {});
59
64
  var AppEvents = /* @__PURE__ */ ((AppEvents2) => {
@@ -355,6 +360,11 @@ const setViewFocusScenePath = (view, focusScenePath) => {
355
360
  return view;
356
361
  }
357
362
  };
363
+ const releaseView = (view) => {
364
+ if (!view.didRelease) {
365
+ view.release();
366
+ }
367
+ };
358
368
  const setScenePath = (room, scenePath) => {
359
369
  if (room && room.isWritable) {
360
370
  if (room.state.sceneState.scenePath !== scenePath) {
@@ -651,6 +661,16 @@ const safeListenPropsUpdated = (getProps, callback, onDestroyed) => {
651
661
  };
652
662
  const onObjectRemoved = onObjectByEvent(UpdateEventKind.Removed);
653
663
  onObjectByEvent(UpdateEventKind.Inserted);
664
+ const createValSync = (expr, Val2, isAddApp) => {
665
+ let skipUpdate = false;
666
+ return reaction(expr, (val) => {
667
+ if (isAddApp && !skipUpdate) {
668
+ skipUpdate = true;
669
+ } else {
670
+ Val2.setValue(val);
671
+ }
672
+ }, { fireImmediately: true });
673
+ };
654
674
  const plainObjectKeys = Object.keys;
655
675
  function isRef(e2) {
656
676
  return Boolean(has(e2, "__isRef"));
@@ -893,9 +913,11 @@ class Storage {
893
913
  }
894
914
  }
895
915
  class WhiteBoardView {
896
- constructor(appContext, appProxy) {
916
+ constructor(view, appContext, appProxy, ensureSize) {
917
+ this.view = view;
897
918
  this.appContext = appContext;
898
919
  this.appProxy = appProxy;
920
+ this.ensureSize = ensureSize;
899
921
  this.nextPage = async () => {
900
922
  const nextIndex = this.pageState.index + 1;
901
923
  return this.jumpPage(nextIndex);
@@ -939,13 +961,27 @@ class WhiteBoardView {
939
961
  };
940
962
  const pageState$ = new Val(appProxy.pageState);
941
963
  this.pageState$ = pageState$;
942
- appProxy.appEmitter.on("pageStateChange", (pageState) => {
964
+ this.appProxy.sideEffectManager.add(() => appProxy.appEmitter.on("pageStateChange", (pageState) => {
943
965
  pageState$.setValue(pageState);
944
- });
966
+ }));
967
+ const camera$ = new Val(pick(this.view.camera, ["centerX", "centerY"]));
968
+ this.camera$ = camera$;
969
+ this.appProxy.sideEffectManager.add(() => appProxy.camera$.subscribe((camera) => {
970
+ if (camera) {
971
+ camera$.setValue(pick(camera, ["centerX", "centerY"]));
972
+ }
973
+ }));
974
+ view.disableCameraTransform = true;
945
975
  }
946
976
  get pageState() {
947
977
  return this.pageState$.value;
948
978
  }
979
+ moveCamera(camera) {
980
+ this.appProxy.moveCamera(camera);
981
+ }
982
+ setRect(rect) {
983
+ this.appProxy.updateSize(rect.width, rect.height);
984
+ }
949
985
  }
950
986
  const setupWrapper = (root) => {
951
987
  const playground = document.createElement("div");
@@ -978,9 +1014,8 @@ const serializeRoomMembers = (members) => {
978
1014
  });
979
1015
  };
980
1016
  class AppContext {
981
- constructor(manager, boxManager, appId, appProxy, appOptions) {
1017
+ constructor(manager, appId, appProxy, appOptions) {
982
1018
  this.manager = manager;
983
- this.boxManager = boxManager;
984
1019
  this.appId = appId;
985
1020
  this.appProxy = appProxy;
986
1021
  this.appOptions = appOptions;
@@ -1009,6 +1044,7 @@ class AppContext {
1009
1044
  }
1010
1045
  };
1011
1046
  this.createWhiteBoardView = (size2) => {
1047
+ var _a;
1012
1048
  if (this.whiteBoardView) {
1013
1049
  return this.whiteBoardView;
1014
1050
  }
@@ -1016,12 +1052,25 @@ class AppContext {
1016
1052
  if (!view) {
1017
1053
  view = this.appProxy.createAppDir();
1018
1054
  }
1019
- view.divElement = this.box.$content;
1020
- this.initPageSize(size2);
1021
- this.whiteBoardView = new WhiteBoardView(this, this.appProxy);
1055
+ const viewWrapper = document.createElement("div");
1056
+ this._viewWrapper = viewWrapper;
1057
+ viewWrapper.className = "window-manager-view-wrapper";
1058
+ (_a = this.box.$content.parentElement) == null ? void 0 : _a.appendChild(viewWrapper);
1059
+ view.divElement = viewWrapper;
1060
+ this.appProxy.fireMemberStateChange();
1061
+ if (this.isAddApp) {
1062
+ this.ensurePageSize(size2);
1063
+ }
1064
+ this.whiteBoardView = new WhiteBoardView(view, this, this.appProxy, this.ensurePageSize);
1065
+ this.appProxy.sideEffectManager.add(() => {
1066
+ return () => {
1067
+ this.whiteBoardView = void 0;
1068
+ };
1069
+ });
1022
1070
  return this.whiteBoardView;
1023
1071
  };
1024
- this.initPageSize = (size2) => {
1072
+ this.ensurePageSize = (size2) => {
1073
+ var _a;
1025
1074
  if (!isNumber(size2))
1026
1075
  return;
1027
1076
  if (!this.appProxy.scenePath)
@@ -1032,14 +1081,11 @@ class AppContext {
1032
1081
  throw Error(`[WindowManager]: size ${size2} muse be in range [1, ${MAX_PAGE_SIZE}]`);
1033
1082
  }
1034
1083
  const needInsert = size2 - this.appProxy.pageState.length;
1035
- const startPageNumber = this.appProxy.pageState.length;
1036
- const scenes = new Array(needInsert).fill({}).map((_2, index2) => {
1037
- return { name: `${startPageNumber + index2 + 1}` };
1038
- });
1039
- putScenes(this.room, this.appProxy.scenePath, scenes);
1084
+ const scenes = new Array(needInsert).fill({});
1085
+ (_a = this.room) == null ? void 0 : _a.putScenes(this.appProxy.scenePath, scenes);
1040
1086
  };
1041
1087
  this.getInitScenePath = () => {
1042
- return this.manager.getAppInitPath(this.appId);
1088
+ return this.appProxy.scenePath;
1043
1089
  };
1044
1090
  this.setAttributes = (attributes) => {
1045
1091
  this.manager.safeSetAttributes({ [this.appId]: attributes });
@@ -1083,14 +1129,17 @@ class AppContext {
1083
1129
  get displayer() {
1084
1130
  return this.manager.displayer;
1085
1131
  }
1132
+ get destroyed() {
1133
+ return this.appProxy.status === "destroyed";
1134
+ }
1086
1135
  get view() {
1087
1136
  return this.appProxy.view;
1088
1137
  }
1089
1138
  get isWritable() {
1090
- return this.manager.canOperate;
1139
+ return this.manager.canOperate && !this.destroyed;
1091
1140
  }
1092
1141
  get box() {
1093
- const box = this.boxManager.getBox(this.appId);
1142
+ const box = this.appProxy.box$.value;
1094
1143
  if (box) {
1095
1144
  return box;
1096
1145
  } else {
@@ -1172,6 +1221,160 @@ class AppPageStateImpl {
1172
1221
  (_a = this.sceneNode) == null ? void 0 : _a.dispose();
1173
1222
  }
1174
1223
  }
1224
+ class CameraSynchronizer {
1225
+ constructor(saveCamera) {
1226
+ this.saveCamera = saveCamera;
1227
+ this.setRect = debounce((rect) => {
1228
+ this.rect = rect;
1229
+ if (this.remoteCamera && this.remoteSize) {
1230
+ this.onRemoteUpdate(this.remoteCamera, this.remoteSize);
1231
+ }
1232
+ }, 10);
1233
+ this.onRemoteUpdate = throttle((camera, size2) => {
1234
+ this.remoteCamera = camera;
1235
+ this.remoteSize = size2;
1236
+ if (this.remoteSize && this.rect) {
1237
+ let scale2;
1238
+ if (size2.width < size2.height) {
1239
+ scale2 = this.rect.width / size2.width;
1240
+ } else {
1241
+ scale2 = this.rect.height / size2.height;
1242
+ }
1243
+ const nextScale = camera.scale * scale2;
1244
+ const moveCamera = () => {
1245
+ var _a;
1246
+ const config = {
1247
+ scale: nextScale,
1248
+ animationMode: AnimationMode.Immediately
1249
+ };
1250
+ if (camera.centerX !== null) {
1251
+ config.centerX = camera.centerX;
1252
+ }
1253
+ if (camera.centerY !== null) {
1254
+ config.centerY = camera.centerY;
1255
+ }
1256
+ (_a = this.view) == null ? void 0 : _a.moveCamera(config);
1257
+ };
1258
+ moveCamera();
1259
+ delay(moveCamera, 50);
1260
+ }
1261
+ }, 10);
1262
+ }
1263
+ setView(view) {
1264
+ this.view = view;
1265
+ }
1266
+ onRemoteSizeUpdate(size2) {
1267
+ this.remoteSize = size2;
1268
+ const needMoveCamera = !isEqual(pick(this.rect, ["width", "height"]), pick(size2, ["width", "height"]));
1269
+ if (this.rect && this.remoteCamera && needMoveCamera) {
1270
+ const scale2 = this.rect.width / size2.width;
1271
+ const nextScale = this.remoteCamera.scale * scale2;
1272
+ const moveCamera = () => {
1273
+ var _a;
1274
+ (_a = this.view) == null ? void 0 : _a.moveCamera({
1275
+ scale: nextScale,
1276
+ animationMode: AnimationMode.Immediately
1277
+ });
1278
+ };
1279
+ moveCamera();
1280
+ delay(moveCamera, 50);
1281
+ }
1282
+ }
1283
+ onLocalCameraUpdate(camera) {
1284
+ this.saveCamera(camera);
1285
+ this.remoteCamera = camera;
1286
+ }
1287
+ }
1288
+ class ViewSync {
1289
+ constructor(context) {
1290
+ this.context = context;
1291
+ this.sem = new SideEffectManager();
1292
+ this.bindView = (view) => {
1293
+ if (!view)
1294
+ return;
1295
+ this.synchronizer.setView(view);
1296
+ this.sem.flush("view");
1297
+ this.sem.add(() => {
1298
+ view.callbacks.on("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
1299
+ return () => view.callbacks.off("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
1300
+ }, "view");
1301
+ };
1302
+ this.onCameraUpdatedByDevice = (camera) => {
1303
+ if (!camera)
1304
+ return;
1305
+ this.synchronizer.onLocalCameraUpdate(Object.assign(camera, { id: this.context.uid }));
1306
+ const stage = this.context.stageRect$.value;
1307
+ if (stage) {
1308
+ const size2 = { width: stage.width, height: stage.height, id: this.context.uid };
1309
+ if (!isEqual(size2, this.context.size$.value)) {
1310
+ this.context.storeSize(size2);
1311
+ }
1312
+ }
1313
+ };
1314
+ this.synchronizer = new CameraSynchronizer((camera) => {
1315
+ this.context.camera$.setValue(camera, true);
1316
+ const notStoreCamera = this.context.viewMode$ && this.context.viewMode$.value === ViewMode.Freedom;
1317
+ if (notStoreCamera) {
1318
+ return;
1319
+ } else {
1320
+ this.context.storeCamera(camera);
1321
+ }
1322
+ });
1323
+ this.bindView(this.context.view$.value);
1324
+ this.sem.add(() => this.context.view$.subscribe((view) => {
1325
+ const currentCamera = this.context.camera$.value;
1326
+ if (currentCamera && this.context.size$.value) {
1327
+ view == null ? void 0 : view.moveCamera({
1328
+ scale: 1,
1329
+ animationMode: AnimationMode.Immediately
1330
+ });
1331
+ this.synchronizer.onRemoteUpdate(currentCamera, this.context.size$.value);
1332
+ }
1333
+ this.bindView(view);
1334
+ }));
1335
+ this.sem.add(() => this.context.camera$.subscribe((camera, skipUpdate) => {
1336
+ const size2 = this.context.size$.value;
1337
+ if (camera && size2 && !skipUpdate) {
1338
+ this.synchronizer.onRemoteUpdate(camera, size2);
1339
+ }
1340
+ }));
1341
+ this.sem.add(() => this.context.size$.subscribe((size2) => {
1342
+ if (size2) {
1343
+ this.synchronizer.onRemoteSizeUpdate(size2);
1344
+ }
1345
+ }));
1346
+ this.sem.add(() => this.context.stageRect$.reaction((rect) => {
1347
+ if (rect) {
1348
+ this.synchronizer.setRect(rect);
1349
+ }
1350
+ }));
1351
+ const camera$size$ = combine([this.context.camera$, this.context.size$]);
1352
+ camera$size$.reaction(([camera, size2]) => {
1353
+ if (camera && size2) {
1354
+ this.synchronizer.onRemoteUpdate(camera, size2);
1355
+ camera$size$.destroy();
1356
+ }
1357
+ });
1358
+ }
1359
+ destroy() {
1360
+ this.sem.flushAll();
1361
+ }
1362
+ }
1363
+ const boxEmitter = new Emittery();
1364
+ const calculateNextIndex = (index2, pageState) => {
1365
+ let nextIndex = 0;
1366
+ const maxIndex = pageState.length - 1;
1367
+ if (index2 === pageState.index) {
1368
+ if (index2 === maxIndex) {
1369
+ nextIndex = index2 - 1;
1370
+ } else {
1371
+ nextIndex = pageState.index + 1;
1372
+ }
1373
+ } else {
1374
+ nextIndex = pageState.index;
1375
+ }
1376
+ return nextIndex;
1377
+ };
1175
1378
  var Fields = /* @__PURE__ */ ((Fields2) => {
1176
1379
  Fields2["Apps"] = "apps";
1177
1380
  Fields2["Focus"] = "focus";
@@ -1185,6 +1388,8 @@ var Fields = /* @__PURE__ */ ((Fields2) => {
1185
1388
  Fields2["CursorState"] = "cursorState";
1186
1389
  Fields2["FullPath"] = "fullPath";
1187
1390
  Fields2["Registered"] = "registered";
1391
+ Fields2["Camera"] = "camera";
1392
+ Fields2["Size"] = "size";
1188
1393
  return Fields2;
1189
1394
  })(Fields || {});
1190
1395
  class AttributesDelegate {
@@ -1249,6 +1454,9 @@ class AttributesDelegate {
1249
1454
  this.context.safeUpdateAttributes(["apps", appId, "state", stateName], state);
1250
1455
  }
1251
1456
  }
1457
+ updateAppAttributes(appId, key, value) {
1458
+ this.context.safeUpdateAttributes(["apps", appId, key], value);
1459
+ }
1252
1460
  cleanAppAttributes(id2) {
1253
1461
  this.context.safeUpdateAttributes(["apps", id2], void 0);
1254
1462
  this.context.safeSetAttributes({ [id2]: void 0 });
@@ -1345,21 +1553,6 @@ const log = (...args) => {
1345
1553
  console.log(`[WindowManager]:`, ...args);
1346
1554
  }
1347
1555
  };
1348
- const calculateNextIndex = (index2, pageState) => {
1349
- let nextIndex = 0;
1350
- const maxIndex = pageState.length - 1;
1351
- if (index2 === pageState.index) {
1352
- if (index2 === maxIndex) {
1353
- nextIndex = index2 - 1;
1354
- } else {
1355
- nextIndex = pageState.index + 1;
1356
- }
1357
- } else {
1358
- nextIndex = pageState.index;
1359
- }
1360
- return nextIndex;
1361
- };
1362
- const boxEmitter = new Emittery();
1363
1556
  class AppProxy {
1364
1557
  constructor(params, manager, appId, isAddApp) {
1365
1558
  var _a;
@@ -1369,8 +1562,52 @@ class AppProxy {
1369
1562
  this.appProxies = this.manager.appProxies;
1370
1563
  this.viewManager = this.manager.viewManager;
1371
1564
  this.store = this.manager.store;
1565
+ this.uid = this.manager.uid;
1372
1566
  this.status = "normal";
1373
1567
  this.sideEffectManager = new SideEffectManager();
1568
+ this.valManager = new ValManager();
1569
+ this.fullPath$ = this.valManager.attach(new Val(void 0));
1570
+ this.camera$ = this.valManager.attach(new Val(void 0));
1571
+ this.size$ = this.valManager.attach(new Val(void 0));
1572
+ this.box$ = this.valManager.attach(new Val(void 0));
1573
+ this.view$ = this.valManager.attach(new Val(void 0));
1574
+ this.fireMemberStateChange = () => {
1575
+ if (this.manager.room) {
1576
+ this.onMemberStateChange(this.manager.room.state.memberState);
1577
+ }
1578
+ };
1579
+ this.onMemberStateChange = (memberState) => {
1580
+ var _a2, _b;
1581
+ const needPointerEventsNone = memberState.currentApplianceName === "clicker";
1582
+ if (needPointerEventsNone) {
1583
+ if ((_a2 = this.appContext) == null ? void 0 : _a2._viewWrapper) {
1584
+ this.appContext._viewWrapper.style.pointerEvents = "none";
1585
+ }
1586
+ } else {
1587
+ if ((_b = this.appContext) == null ? void 0 : _b._viewWrapper) {
1588
+ this.appContext._viewWrapper.style.pointerEvents = "auto";
1589
+ }
1590
+ }
1591
+ };
1592
+ this.computedInitialRect = (boxRect) => {
1593
+ var _a2;
1594
+ const managerRect = (_a2 = this.manager.boxManager) == null ? void 0 : _a2.stageRect;
1595
+ if (managerRect) {
1596
+ const { width, height } = managerRect;
1597
+ const boxRatio = boxRect.height / boxRect.width;
1598
+ if (height < 480) {
1599
+ return {
1600
+ width: 480 / boxRatio,
1601
+ height: 480
1602
+ };
1603
+ } else {
1604
+ return {
1605
+ width: width * 0.65,
1606
+ height: height * 0.65
1607
+ };
1608
+ }
1609
+ }
1610
+ };
1374
1611
  this.getAppInitState = (id2) => {
1375
1612
  var _a2, _b;
1376
1613
  const attrs = this.store.getAppState(id2);
@@ -1399,8 +1636,7 @@ class AppProxy {
1399
1636
  return payload;
1400
1637
  };
1401
1638
  this.appAttributesUpdateListener = (appId2) => {
1402
- var _a2, _b, _c;
1403
- (_a2 = this.manager.refresher) == null ? void 0 : _a2.add(appId2, () => {
1639
+ this.manager.refresher.add(appId2, () => {
1404
1640
  return autorun(() => {
1405
1641
  const attrs = this.manager.attributes[appId2];
1406
1642
  if (attrs) {
@@ -1408,23 +1644,23 @@ class AppProxy {
1408
1644
  }
1409
1645
  });
1410
1646
  });
1411
- (_b = this.manager.refresher) == null ? void 0 : _b.add(this.stateKey, () => {
1647
+ this.manager.refresher.add(this.stateKey, () => {
1412
1648
  return autorun(() => {
1413
- var _a3, _b2, _c2;
1414
- const appState = (_a3 = this.appAttributes) == null ? void 0 : _a3.state;
1415
- if ((appState == null ? void 0 : appState.zIndex) > 0 && appState.zIndex !== ((_b2 = this.box) == null ? void 0 : _b2.zIndex)) {
1416
- (_c2 = this.boxManager) == null ? void 0 : _c2.setZIndex(appId2, appState.zIndex);
1649
+ var _a2, _b, _c;
1650
+ const appState = (_a2 = this.appAttributes) == null ? void 0 : _a2.state;
1651
+ if ((appState == null ? void 0 : appState.zIndex) > 0 && appState.zIndex !== ((_b = this.box) == null ? void 0 : _b.zIndex)) {
1652
+ (_c = this.boxManager) == null ? void 0 : _c.setZIndex(appId2, appState.zIndex);
1417
1653
  }
1418
1654
  });
1419
1655
  });
1420
- (_c = this.manager.refresher) == null ? void 0 : _c.add(`${appId2}-fullPath`, () => {
1656
+ this.manager.refresher.add(`${appId2}-fullPath`, () => {
1421
1657
  return autorun(() => {
1422
- var _a3;
1423
- const fullPath = (_a3 = this.appAttributes) == null ? void 0 : _a3.fullPath;
1658
+ var _a2;
1659
+ const fullPath = (_a2 = this.appAttributes) == null ? void 0 : _a2.fullPath;
1424
1660
  this.setFocusScenePathHandler(fullPath);
1425
- if (this._prevFullPath !== fullPath) {
1661
+ if (this.fullPath$.value !== fullPath) {
1426
1662
  this.notifyPageStateChange();
1427
- this._prevFullPath = fullPath;
1663
+ this.fullPath$.setValue(fullPath);
1428
1664
  }
1429
1665
  });
1430
1666
  });
@@ -1440,6 +1676,58 @@ class AppProxy {
1440
1676
  this.appEmitter.emit("pageStateChange", this.pageState);
1441
1677
  }
1442
1678
  }, 50);
1679
+ this.storeCamera = (camera) => {
1680
+ this.store.updateAppAttributes(this.id, Fields.Camera, camera);
1681
+ };
1682
+ this.storeSize = (size2) => {
1683
+ this.store.updateAppAttributes(this.id, Fields.Size, size2);
1684
+ };
1685
+ this.updateSize = (width, height) => {
1686
+ const iSize = {
1687
+ id: this.manager.uid,
1688
+ width,
1689
+ height
1690
+ };
1691
+ this.store.updateAppAttributes(this.id, Fields.Size, iSize);
1692
+ this.size$.setValue(iSize);
1693
+ };
1694
+ this.moveCamera = (camera) => {
1695
+ if (!this.camera$.value) {
1696
+ return;
1697
+ }
1698
+ const nextCamera = __spreadProps(__spreadValues(__spreadValues({}, this.camera$.value), camera), { id: this.uid });
1699
+ this.storeCamera(nextCamera);
1700
+ this.camera$.setValue(nextCamera);
1701
+ };
1702
+ this.addCameraReaction = () => {
1703
+ this.sideEffectManager.add(() => this.manager.refresher.add(`${this.id}-camera`, () => reaction(() => {
1704
+ var _a2;
1705
+ return (_a2 = this.appAttributes) == null ? void 0 : _a2.camera;
1706
+ }, (camera) => {
1707
+ if (camera) {
1708
+ const rawCamera = toJS(camera);
1709
+ if (!isEqual(rawCamera, this.camera$.value)) {
1710
+ this.camera$.setValue(rawCamera);
1711
+ }
1712
+ }
1713
+ })), "camera");
1714
+ };
1715
+ this.addSizeReaction = () => {
1716
+ this.sideEffectManager.add(() => this.manager.refresher.add(`${this.id}-size`, () => reaction(() => {
1717
+ var _a2;
1718
+ return (_a2 = this.appAttributes) == null ? void 0 : _a2.size;
1719
+ }, (size2) => {
1720
+ if (size2) {
1721
+ const rawSize = toJS(size2);
1722
+ if (!isEqual(rawSize, this.size$.value)) {
1723
+ this.size$.setValue(rawSize);
1724
+ }
1725
+ }
1726
+ })), "size");
1727
+ };
1728
+ this.onFocus = () => {
1729
+ this.setScenePath();
1730
+ };
1443
1731
  this.kind = params.kind;
1444
1732
  this.id = appId;
1445
1733
  this.appScenePath = `/${this.id}-app-dir`;
@@ -1461,13 +1749,93 @@ class AppProxy {
1461
1749
  view: this.view,
1462
1750
  notifyPageStateChange: this.notifyPageStateChange
1463
1751
  });
1464
- this.sideEffectManager.add(() => {
1465
- return () => this._pageState.destroy();
1466
- });
1467
- this.sideEffectManager.add(() => {
1468
- return emitter.on("roomMembersChange", (members) => {
1469
- this.appEmitter.emit("roomMembersChange", members);
1470
- });
1752
+ this.sideEffectManager.add(() => () => this._pageState.destroy());
1753
+ this.sideEffectManager.add(() => emitter.on("roomMembersChange", (members) => {
1754
+ this.appEmitter.emit("roomMembersChange", members);
1755
+ }));
1756
+ this.camera$.setValue(toJS(this.appAttributes.camera));
1757
+ this.size$.setValue(toJS(this.appAttributes.size));
1758
+ this.addCameraReaction();
1759
+ this.addSizeReaction();
1760
+ this.sideEffectManager.add(() => combine([this.box$, this.view$]).subscribe(([box, view]) => {
1761
+ if (box && view) {
1762
+ if (!this.camera$.value) {
1763
+ this.storeCamera({
1764
+ centerX: null,
1765
+ centerY: null,
1766
+ scale: 1,
1767
+ id: this.uid
1768
+ });
1769
+ this.camera$.setValue(toJS(this.appAttributes.camera));
1770
+ }
1771
+ if (!this.size$.value && box.contentStageRect) {
1772
+ const initialRect = this.computedInitialRect(box.contentStageRect);
1773
+ const width = (initialRect == null ? void 0 : initialRect.width) || box.contentStageRect.width;
1774
+ const height = (initialRect == null ? void 0 : initialRect.height) || box.contentStageRect.height;
1775
+ this.storeSize({
1776
+ id: this.uid,
1777
+ width,
1778
+ height
1779
+ });
1780
+ this.size$.setValue(toJS(this.appAttributes.size));
1781
+ }
1782
+ this.viewSync = new ViewSync({
1783
+ uid: this.uid,
1784
+ view$: this.view$,
1785
+ camera$: this.camera$,
1786
+ size$: this.size$,
1787
+ stageRect$: box._contentStageRect$,
1788
+ storeCamera: this.storeCamera,
1789
+ storeSize: this.storeSize
1790
+ });
1791
+ this.sideEffectManager.add(() => () => {
1792
+ var _a2;
1793
+ return (_a2 = this.viewSync) == null ? void 0 : _a2.destroy();
1794
+ });
1795
+ }
1796
+ }));
1797
+ this.sideEffectManager.add(() => emitter.on("memberStateChange", this.onMemberStateChange));
1798
+ this.box$.subscribe((box) => {
1799
+ if (!box)
1800
+ return;
1801
+ this.sideEffectManager.add(() => [
1802
+ createValSync(() => {
1803
+ var _a2;
1804
+ return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.visible;
1805
+ }, box._visible$, this.isAddApp),
1806
+ createValSync(() => {
1807
+ var _a2;
1808
+ return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.ratio;
1809
+ }, box._ratio$, this.isAddApp),
1810
+ createValSync(() => {
1811
+ var _a2;
1812
+ return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.stageRatio;
1813
+ }, box._stageRatio$, this.isAddApp),
1814
+ createValSync(() => {
1815
+ var _a2;
1816
+ return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.draggable;
1817
+ }, box._draggable$, this.isAddApp),
1818
+ createValSync(() => {
1819
+ var _a2;
1820
+ return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.resizable;
1821
+ }, box._resizable$, this.isAddApp),
1822
+ box._visible$.subscribe((visible) => {
1823
+ this.store.updateAppState(this.id, AppAttributes.Visible, visible);
1824
+ }),
1825
+ box._ratio$.subscribe((ratio) => {
1826
+ this.store.updateAppState(this.id, AppAttributes.Ratio, ratio);
1827
+ }),
1828
+ box._stageRatio$.subscribe((stageRatio) => {
1829
+ this.store.updateAppState(this.id, AppAttributes.StageRatio, stageRatio);
1830
+ }),
1831
+ box._draggable$.subscribe((draggable) => {
1832
+ this.store.updateAppState(this.id, AppAttributes.Draggable, draggable);
1833
+ }),
1834
+ box._resizable$.subscribe((resizable) => {
1835
+ console.log("resizable change", resizable);
1836
+ this.store.updateAppState(this.id, AppAttributes.Resizable, resizable);
1837
+ })
1838
+ ]);
1471
1839
  });
1472
1840
  }
1473
1841
  createAppDir() {
@@ -1496,7 +1864,7 @@ class AppProxy {
1496
1864
  }
1497
1865
  }
1498
1866
  get view() {
1499
- return this.manager.viewManager.getView(this.id);
1867
+ return this.view$.value;
1500
1868
  }
1501
1869
  get viewIndex() {
1502
1870
  var _a;
@@ -1526,7 +1894,7 @@ class AppProxy {
1526
1894
  return fullPath;
1527
1895
  }
1528
1896
  setFullPath(path) {
1529
- this.manager.safeUpdateAttributes(["apps", this.id, Fields.FullPath], path);
1897
+ this.store.updateAppAttributes(this.id, Fields.FullPath, path);
1530
1898
  }
1531
1899
  async baseInsertApp(skipUpdate = false) {
1532
1900
  var _a;
@@ -1548,8 +1916,7 @@ class AppProxy {
1548
1916
  };
1549
1917
  }
1550
1918
  get box() {
1551
- var _a;
1552
- return (_a = this.boxManager) == null ? void 0 : _a.getBox(this.id);
1919
+ return this.box$.value;
1553
1920
  }
1554
1921
  async setupApp(appId, skipUpdate, app, options, appOptions) {
1555
1922
  var _a;
@@ -1557,7 +1924,7 @@ class AppProxy {
1557
1924
  if (!this.boxManager) {
1558
1925
  throw new BoxManagerNotFoundError();
1559
1926
  }
1560
- const context = new AppContext(this.manager, this.boxManager, appId, this, appOptions);
1927
+ const context = new AppContext(this.manager, appId, this, appOptions);
1561
1928
  this.appContext = context;
1562
1929
  try {
1563
1930
  emitter.once(`${appId}${Events.WindowCreated}`).then(async () => {
@@ -1577,13 +1944,14 @@ class AppProxy {
1577
1944
  this.fixMobileSize();
1578
1945
  }, SETUP_APP_DELAY);
1579
1946
  });
1580
- (_a = this.boxManager) == null ? void 0 : _a.createBox({
1947
+ const box = (_a = this.boxManager) == null ? void 0 : _a.createBox({
1581
1948
  appId,
1582
1949
  app,
1583
1950
  options,
1584
1951
  canOperate: this.manager.canOperate,
1585
1952
  smartPosition: this.isAddApp
1586
1953
  });
1954
+ this.box$.setValue(box);
1587
1955
  if (this.isAddApp && this.box) {
1588
1956
  this.store.updateAppState(appId, AppAttributes.ZIndex, this.box.zIndex);
1589
1957
  this.boxManager.focusBox({ appId }, false);
@@ -1597,12 +1965,14 @@ class AppProxy {
1597
1965
  var _a, _b;
1598
1966
  const box = (_a = this.boxManager) == null ? void 0 : _a.getBox(this.id);
1599
1967
  if (box) {
1600
- (_b = this.boxManager) == null ? void 0 : _b.resizeBox({
1601
- appId: this.id,
1602
- width: box.intrinsicWidth + 1e-3,
1603
- height: box.intrinsicHeight + 1e-3,
1604
- skipUpdate: true
1605
- });
1968
+ if (!box.minimized) {
1969
+ (_b = this.boxManager) == null ? void 0 : _b.resizeBox({
1970
+ appId: this.id,
1971
+ width: box.intrinsicWidth + 1e-3,
1972
+ height: box.intrinsicHeight + 1e-3,
1973
+ skipUpdate: true
1974
+ });
1975
+ }
1606
1976
  }
1607
1977
  }
1608
1978
  async onSeek(time2) {
@@ -1712,6 +2082,7 @@ class AppProxy {
1712
2082
  }
1713
2083
  createView() {
1714
2084
  const view = this.viewManager.createView(this.id);
2085
+ this.view$.setValue(view);
1715
2086
  this.setViewFocusScenePath();
1716
2087
  return view;
1717
2088
  }
@@ -1747,11 +2118,12 @@ class AppProxy {
1747
2118
  const fullPath = this._pageState.getFullPath(index2);
1748
2119
  if (fullPath) {
1749
2120
  this.setFullPath(fullPath);
2121
+ setScenePath(this.manager.room, fullPath);
1750
2122
  }
1751
2123
  }
1752
2124
  }
1753
2125
  async destroy(needCloseBox, cleanAttrs, skipUpdate, error) {
1754
- var _a, _b, _c, _d;
2126
+ var _a;
1755
2127
  if (this.status === "destroyed")
1756
2128
  return;
1757
2129
  this.status = "destroyed";
@@ -1762,6 +2134,7 @@ class AppProxy {
1762
2134
  console.error("[WindowManager]: notifyApp error", error2.message, error2.stack);
1763
2135
  }
1764
2136
  this.appEmitter.clearListeners();
2137
+ this.sideEffectManager.flushAll();
1765
2138
  emitter.emit(`destroy-${this.id}`, { error });
1766
2139
  if (needCloseBox) {
1767
2140
  (_a = this.boxManager) == null ? void 0 : _a.closeBox(this.id, skipUpdate);
@@ -1775,11 +2148,12 @@ class AppProxy {
1775
2148
  this.appProxies.delete(this.id);
1776
2149
  this.viewManager.destroyView(this.id);
1777
2150
  this.manager.appStatus.delete(this.id);
1778
- (_b = this.manager.refresher) == null ? void 0 : _b.remove(this.id);
1779
- (_c = this.manager.refresher) == null ? void 0 : _c.remove(this.stateKey);
1780
- (_d = this.manager.refresher) == null ? void 0 : _d.remove(`${this.id}-fullPath`);
1781
- this._prevFullPath = void 0;
1782
- this.sideEffectManager.flushAll();
2151
+ this.manager.refresher.remove(this.id);
2152
+ this.manager.refresher.remove(this.stateKey);
2153
+ this.manager.refresher.remove(`${this.id}-fullPath`);
2154
+ this.manager.refresher.remove(`${this.id}-camera`);
2155
+ this.manager.refresher.remove(`${this.id}-size`);
2156
+ this.valManager.destroy();
1783
2157
  }
1784
2158
  close() {
1785
2159
  return this.destroy(true, true, false);
@@ -1835,102 +2209,84 @@ const setDefaultCameraBound = (view) => {
1835
2209
  minContentMode: () => 0.1
1836
2210
  });
1837
2211
  };
1838
- class CameraSynchronizer {
1839
- constructor(saveCamera) {
1840
- this.saveCamera = saveCamera;
1841
- this.onRemoteUpdate = throttle((camera, size2) => {
1842
- this.remoteCamera = camera;
1843
- this.remoteSize = size2;
1844
- if (this.remoteSize && this.rect) {
1845
- let scale2;
1846
- if (size2.width < size2.height) {
1847
- scale2 = this.rect.width / size2.width;
1848
- } else {
1849
- scale2 = this.rect.height / size2.height;
1850
- }
1851
- const nextScale = camera.scale * scale2;
1852
- const moveCamera = () => {
1853
- var _a;
1854
- return (_a = this.view) == null ? void 0 : _a.moveCamera({
1855
- centerX: camera.centerX,
1856
- centerY: camera.centerY,
1857
- scale: nextScale,
1858
- animationMode: AnimationMode.Immediately
1859
- });
1860
- };
1861
- delay(moveCamera, 10);
1862
- }
1863
- }, 50);
1864
- }
1865
- setRect(rect) {
1866
- this.rect = rect;
1867
- if (this.remoteCamera && this.remoteSize) {
1868
- this.onRemoteUpdate(this.remoteCamera, this.remoteSize);
1869
- }
1870
- }
1871
- setView(view) {
1872
- this.view = view;
1873
- }
1874
- onLocalCameraUpdate(camera) {
1875
- this.saveCamera(camera);
1876
- }
1877
- onLocalSizeUpdate(size2) {
1878
- if (this.rect && this.view) {
1879
- const scale2 = this.rect.width / size2.width;
1880
- const nextScale = this.view.camera.scale * scale2;
1881
- this.view.moveCamera({
1882
- scale: nextScale,
1883
- animationMode: AnimationMode.Immediately
1884
- });
1885
- }
1886
- }
1887
- }
1888
2212
  class MainViewProxy {
1889
2213
  constructor(manager) {
1890
- var _a;
1891
2214
  this.manager = manager;
1892
2215
  this.started = false;
1893
2216
  this.mainViewIsAddListener = false;
1894
2217
  this.store = this.manager.store;
1895
2218
  this.sideEffectManager = new SideEffectManager();
1896
- this.startListenWritableChange = () => {
1897
- this.sideEffectManager.add(() => {
1898
- return emitter.on("writableChange", (isWritable) => {
1899
- if (isWritable) {
1900
- this.ensureCameraAndSize();
1901
- }
2219
+ this.camera$ = new Val(void 0);
2220
+ this.size$ = new Val(void 0);
2221
+ this.view$ = new Val(void 0);
2222
+ this.createViewSync = () => {
2223
+ var _a;
2224
+ if (this.manager.boxManager && !this.viewSync) {
2225
+ this.viewSync = new ViewSync({
2226
+ uid: this.manager.uid,
2227
+ view$: this.view$,
2228
+ camera$: this.camera$,
2229
+ size$: this.size$,
2230
+ stageRect$: (_a = this.manager.boxManager) == null ? void 0 : _a.stageRect$,
2231
+ viewMode$: this.manager.windowManger.viewMode$,
2232
+ storeCamera: this.storeCamera,
2233
+ storeSize: this.storeSize
1902
2234
  });
1903
- });
2235
+ }
2236
+ };
2237
+ this.startListenWritableChange = () => {
2238
+ this.sideEffectManager.add(() => emitter.on("writableChange", (isWritable) => {
2239
+ if (isWritable) {
2240
+ this.ensureCameraAndSize();
2241
+ }
2242
+ }));
1904
2243
  };
1905
2244
  this.addCameraReaction = () => {
1906
- var _a2;
1907
- (_a2 = this.manager.refresher) == null ? void 0 : _a2.add(Fields.MainViewCamera, this.cameraReaction);
2245
+ this.manager.refresher.add(Fields.MainViewCamera, this.cameraReaction);
2246
+ this.manager.refresher.add(Fields.MainViewSize, this.sizeReaction);
2247
+ };
2248
+ this.storeCurrentCamera = () => {
2249
+ const iCamera = this.view.camera;
2250
+ this.storeCamera(__spreadValues({
2251
+ id: this.manager.uid
2252
+ }, iCamera));
2253
+ };
2254
+ this.storeCurrentSize = () => {
2255
+ var _a;
2256
+ const rect = (_a = this.manager.boxManager) == null ? void 0 : _a.stageRect;
2257
+ if (rect) {
2258
+ this.storeSize({
2259
+ id: this.manager.uid,
2260
+ width: rect.width,
2261
+ height: rect.height
2262
+ });
2263
+ }
2264
+ };
2265
+ this.storeCamera = (camera) => {
2266
+ this.store.setMainViewCamera(camera);
2267
+ };
2268
+ this.storeSize = (size2) => {
2269
+ this.store.setMainViewSize(size2);
1908
2270
  };
1909
2271
  this.cameraReaction = () => {
1910
2272
  return reaction(() => this.mainViewCamera, (camera) => {
1911
- if (camera && camera.id !== this.manager.uid) {
1912
- this.synchronizer.onRemoteUpdate(camera, this.mainViewSize);
2273
+ if (camera) {
2274
+ const rawCamera = toJS(camera);
2275
+ if (!isEqual(rawCamera, this.camera$.value)) {
2276
+ this.camera$.setValue(rawCamera);
2277
+ }
1913
2278
  }
1914
2279
  }, { fireImmediately: true });
1915
2280
  };
1916
- this.sizeChangeHandler = debounce((size2) => {
1917
- if (size2) {
1918
- this.synchronizer.onLocalSizeUpdate(size2);
1919
- }
1920
- }, 30);
1921
- this.onUpdateContainerSizeRatio = () => {
1922
- const size2 = this.store.getMainViewSize();
1923
- this.sizeChangeHandler(size2);
1924
- if (size2.id === this.manager.uid) {
1925
- this.setCameraAndSize();
1926
- }
1927
- };
1928
- this.onCameraUpdatedByDevice = (camera) => {
1929
- this.synchronizer.onLocalCameraUpdate(camera);
1930
- const size2 = this.getStageSize();
1931
- if (size2 && !isEqual(size2, this.mainViewSize)) {
1932
- this.setMainViewSize(size2);
1933
- }
2281
+ this.sizeReaction = () => {
2282
+ return reaction(() => this.mainViewSize, (size2) => {
2283
+ if (size2) {
2284
+ const rawSize = toJS(size2);
2285
+ if (!isEqual(rawSize, this.size$.value)) {
2286
+ this.size$.setValue(rawSize);
2287
+ }
2288
+ }
2289
+ }, { fireImmediately: true });
1934
2290
  };
1935
2291
  this.mainViewClickListener = () => {
1936
2292
  this.mainViewClickHandler();
@@ -1941,40 +2297,43 @@ class MainViewProxy {
1941
2297
  this.onCameraOrSizeUpdated = () => {
1942
2298
  callbacks$1.emit("cameraStateChange", this.cameraState);
1943
2299
  };
1944
- this.synchronizer = new CameraSynchronizer((camera) => this.store.setMainViewCamera(__spreadProps(__spreadValues({}, camera), { id: this.manager.uid })));
1945
2300
  this.mainView = this.createMainView();
1946
- this.moveCameraSizeByAttributes();
1947
2301
  emitter.once("mainViewMounted").then(() => {
1948
2302
  this.addMainViewListener();
1949
2303
  this.start();
1950
2304
  this.ensureCameraAndSize();
1951
2305
  this.startListenWritableChange();
1952
2306
  });
1953
- this.sideEffectManager.add(() => {
1954
- return emitter.on("containerSizeRatioUpdate", this.onUpdateContainerSizeRatio);
1955
- });
1956
- this.sideEffectManager.add(() => {
1957
- return emitter.on("startReconnect", () => {
1958
- if (!this.mainView.didRelease) {
1959
- this.mainView.release();
2307
+ this.sideEffectManager.add(() => [
2308
+ emitter.on("startReconnect", () => {
2309
+ releaseView(this.mainView);
2310
+ })
2311
+ ]);
2312
+ this.createViewSync();
2313
+ this.sideEffectManager.add(() => emitter.on("focusedChange", ({ focused }) => {
2314
+ if (focused === void 0) {
2315
+ const scenePath = this.store.getMainViewScenePath();
2316
+ if (scenePath) {
2317
+ setScenePath(this.manager.room, scenePath);
1960
2318
  }
1961
- });
1962
- });
1963
- const rect = (_a = this.manager.boxManager) == null ? void 0 : _a.stageRect;
1964
- if (rect) {
1965
- this.synchronizer.setRect(rect);
1966
- }
1967
- this.sideEffectManager.add(() => {
1968
- return emitter.on("playgroundSizeChange", (rect2) => {
1969
- this.synchronizer.setRect(rect2);
1970
- this.synchronizer.onLocalSizeUpdate(rect2);
1971
- });
1972
- });
2319
+ }
2320
+ }));
1973
2321
  }
1974
2322
  ensureCameraAndSize() {
2323
+ var _a;
1975
2324
  if (!this.mainViewCamera || !this.mainViewSize) {
1976
2325
  this.manager.dispatchInternalEvent(Events.InitMainViewCamera);
1977
- this.setCameraAndSize();
2326
+ this.storeCamera(__spreadValues({
2327
+ id: this.manager.uid
2328
+ }, this.view.camera));
2329
+ const stageRect = (_a = this.manager.boxManager) == null ? void 0 : _a.stageRect;
2330
+ if (stageRect && !this.mainViewSize) {
2331
+ this.storeSize({
2332
+ id: this.manager.uid,
2333
+ width: stageRect.width,
2334
+ height: stageRect.height
2335
+ });
2336
+ }
1978
2337
  }
1979
2338
  }
1980
2339
  get mainViewCamera() {
@@ -1986,25 +2345,13 @@ class MainViewProxy {
1986
2345
  get didRelease() {
1987
2346
  return get(this.view, ["didRelease"]);
1988
2347
  }
1989
- moveCameraSizeByAttributes() {
1990
- this.synchronizer.onRemoteUpdate(this.mainViewCamera, this.mainViewSize);
1991
- }
1992
2348
  start() {
1993
2349
  if (this.started)
1994
2350
  return;
1995
- this.sizeChangeHandler(this.mainViewSize);
1996
2351
  this.addCameraListener();
1997
2352
  this.addCameraReaction();
1998
2353
  this.started = true;
1999
2354
  }
2000
- setCameraAndSize() {
2001
- const stageSize = this.getStageSize();
2002
- if (stageSize) {
2003
- const camera = __spreadProps(__spreadValues({}, this.mainView.camera), { id: this.manager.uid });
2004
- const size2 = __spreadProps(__spreadValues({}, stageSize), { id: this.manager.uid });
2005
- this.store.setMainViewCameraAndSize(camera, size2);
2006
- }
2007
- }
2008
2355
  get view() {
2009
2356
  return this.mainView;
2010
2357
  }
@@ -2017,7 +2364,7 @@ class MainViewProxy {
2017
2364
  if (mainViewScenePath) {
2018
2365
  setViewFocusScenePath(mainView, mainViewScenePath);
2019
2366
  }
2020
- this.synchronizer.setView(mainView);
2367
+ this.view$.setValue(mainView);
2021
2368
  return mainView;
2022
2369
  }
2023
2370
  onReconnect() {
@@ -2037,9 +2384,7 @@ class MainViewProxy {
2037
2384
  const divElement = this.mainView.divElement;
2038
2385
  const disableCameraTransform = this.mainView.disableCameraTransform;
2039
2386
  this.stop();
2040
- if (!this.didRelease) {
2041
- this.mainView.release();
2042
- }
2387
+ releaseView(this.mainView);
2043
2388
  this.removeMainViewListener();
2044
2389
  this.mainView = this.createMainView();
2045
2390
  this.mainView.disableCameraTransform = disableCameraTransform;
@@ -2047,13 +2392,6 @@ class MainViewProxy {
2047
2392
  this.addMainViewListener();
2048
2393
  this.start();
2049
2394
  }
2050
- getStageSize() {
2051
- var _a;
2052
- const stage = (_a = this.manager.boxManager) == null ? void 0 : _a.stageRect;
2053
- if (stage) {
2054
- return { width: stage.width, height: stage.height };
2055
- }
2056
- }
2057
2395
  addMainViewListener() {
2058
2396
  if (this.mainViewIsAddListener)
2059
2397
  return;
@@ -2078,23 +2416,23 @@ class MainViewProxy {
2078
2416
  (_a = this.manager.boxManager) == null ? void 0 : _a.blurAllBox();
2079
2417
  }
2080
2418
  addCameraListener() {
2081
- this.view.callbacks.on("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
2082
2419
  this.view.callbacks.on("onCameraUpdated", this.onCameraOrSizeUpdated);
2083
2420
  this.view.callbacks.on("onSizeUpdated", this.onCameraOrSizeUpdated);
2084
2421
  }
2085
2422
  removeCameraListener() {
2086
- this.view.callbacks.off("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
2087
2423
  this.view.callbacks.off("onCameraUpdated", this.onCameraOrSizeUpdated);
2088
2424
  this.view.callbacks.off("onSizeUpdated", this.onCameraOrSizeUpdated);
2089
2425
  }
2090
2426
  stop() {
2091
- var _a, _b;
2092
2427
  this.removeCameraListener();
2093
- (_a = this.manager.refresher) == null ? void 0 : _a.remove(Fields.MainViewCamera);
2094
- (_b = this.manager.refresher) == null ? void 0 : _b.remove(Fields.MainViewSize);
2428
+ this.manager.refresher.remove(Fields.MainViewCamera);
2429
+ this.manager.refresher.remove(Fields.MainViewSize);
2095
2430
  this.started = false;
2096
2431
  }
2097
2432
  destroy() {
2433
+ this.camera$.destroy();
2434
+ this.size$.destroy();
2435
+ this.view$.destroy();
2098
2436
  this.removeMainViewListener();
2099
2437
  this.stop();
2100
2438
  this.sideEffectManager.flushAll();
@@ -2169,6 +2507,8 @@ class AppManager {
2169
2507
  this.mainViewScenesLength = 0;
2170
2508
  this.callbacksNode = null;
2171
2509
  this.appCreateQueue = new AppCreateQueue();
2510
+ this.sceneIndex$ = new Val(void 0);
2511
+ this.focused$ = new Val(void 0);
2172
2512
  this.sideEffectManager = new SideEffectManager();
2173
2513
  this.sceneState = null;
2174
2514
  this.rootDirRemoving = false;
@@ -2188,7 +2528,7 @@ class AppManager {
2188
2528
  sceneName = (_b = this.callbacksNode) == null ? void 0 : _b.scenes[nextIndex];
2189
2529
  }
2190
2530
  if (sceneName) {
2191
- this.setMainViewScenePath(`${ROOT_DIR}${sceneName}`);
2531
+ await this.setMainViewScenePath(`${ROOT_DIR}${sceneName}`);
2192
2532
  }
2193
2533
  await this.setMainViewSceneIndex(nextIndex);
2194
2534
  } else {
@@ -2336,26 +2676,27 @@ class AppManager {
2336
2676
  });
2337
2677
  };
2338
2678
  this.onMainViewIndexChange = (index2) => {
2339
- if (index2 !== void 0 && this._prevSceneIndex !== index2) {
2679
+ if (index2 !== void 0 && this.sceneIndex$.value !== index2) {
2340
2680
  callbacks$1.emit("mainViewSceneIndexChange", index2);
2341
2681
  emitter.emit("changePageState");
2342
2682
  if (this.callbacksNode) {
2343
2683
  this.updateSceneState(this.callbacksNode);
2344
2684
  }
2345
- this._prevSceneIndex = index2;
2685
+ this.sceneIndex$.setValue(index2);
2346
2686
  }
2347
2687
  };
2348
2688
  this.onFocusChange = (focused) => {
2349
2689
  var _a;
2350
- if (this._prevFocused !== focused) {
2690
+ if (this.focused$.value !== focused) {
2351
2691
  callbacks$1.emit("focusedChange", focused);
2352
- emitter.emit("focusedChange", { focused, prev: this._prevFocused });
2353
- this._prevFocused = focused;
2692
+ emitter.emit("focusedChange", { focused, prev: this.focused$.value });
2693
+ this.focused$.setValue(focused);
2354
2694
  if (focused !== void 0) {
2355
2695
  (_a = this.boxManager) == null ? void 0 : _a.focusBox({ appId: focused });
2356
2696
  setTimeout(() => {
2357
2697
  const appProxy = this.appProxies.get(focused);
2358
2698
  if (appProxy) {
2699
+ appProxy.onFocus();
2359
2700
  appRegister.notifyApp(appProxy.kind, "focus", { appId: focused });
2360
2701
  }
2361
2702
  }, 0);
@@ -2419,11 +2760,14 @@ class AppManager {
2419
2760
  emitter.emit("roomMembersChange", this.members);
2420
2761
  }
2421
2762
  emitter.emit("observerIdChange", this.displayer.observerId);
2763
+ if (state.memberState) {
2764
+ emitter.emit("memberStateChange", toJS(state.memberState));
2765
+ }
2422
2766
  };
2423
2767
  this.displayerWritableListener = (isReadonly) => {
2424
2768
  var _a, _b;
2425
2769
  const isWritable = !isReadonly;
2426
- const isManualWritable = this.windowManger.readonly === void 0 || this.windowManger.readonly === false;
2770
+ const isManualWritable = this.windowManger.readonly === void 0 || !this.windowManger.readonly;
2427
2771
  if (this.windowManger.readonly === void 0) {
2428
2772
  (_a = this.boxManager) == null ? void 0 : _a.setReadonly(isReadonly);
2429
2773
  } else {
@@ -2432,13 +2776,10 @@ class AppManager {
2432
2776
  this.appProxies.forEach((appProxy) => {
2433
2777
  appProxy.emitAppIsWritableChange();
2434
2778
  });
2435
- if (isWritable === true) {
2436
- this.mainView.disableCameraTransform = false;
2779
+ if (isWritable) {
2437
2780
  if (this.room && this.room.disableSerialization === true) {
2438
2781
  this.room.disableSerialization = false;
2439
2782
  }
2440
- } else {
2441
- this.mainView.disableCameraTransform = true;
2442
2783
  }
2443
2784
  emitter.emit("writableChange", isWritable);
2444
2785
  };
@@ -2496,7 +2837,7 @@ class AppManager {
2496
2837
  });
2497
2838
  }
2498
2839
  async onRootDirRemoved(needClose = true) {
2499
- this.setMainViewScenePath(INIT_DIR);
2840
+ await this.setMainViewScenePath(INIT_DIR);
2500
2841
  this.createRootDirScenesCallback();
2501
2842
  for (const [id2, appProxy] of this.appProxies.entries()) {
2502
2843
  if (appProxy.view) {
@@ -2504,7 +2845,7 @@ class AppManager {
2504
2845
  }
2505
2846
  }
2506
2847
  this.mainViewProxy.rebind();
2507
- emitter.emit("rootDirRemoved");
2848
+ await emitter.emit("rootDirRemoved");
2508
2849
  this.updateRootDirRemoving(false);
2509
2850
  }
2510
2851
  get eventName() {
@@ -2543,7 +2884,7 @@ class AppManager {
2543
2884
  }
2544
2885
  }
2545
2886
  async onCreated() {
2546
- var _a, _b, _c, _d, _e, _f;
2887
+ var _a;
2547
2888
  await this.attributesUpdateCallback(this.attributes.apps);
2548
2889
  emitter.emit("updateManagerRect");
2549
2890
  boxEmitter.on("move", this.onBoxMove);
@@ -2553,32 +2894,32 @@ class AppManager {
2553
2894
  boxEmitter.on("boxStateChange", this.onBoxStateChange);
2554
2895
  this.addAppsChangeListener();
2555
2896
  this.addAppCloseListener();
2556
- (_a = this.refresher) == null ? void 0 : _a.add("maximized", () => {
2897
+ this.refresher.add("maximized", () => {
2557
2898
  return autorun(() => {
2558
2899
  var _a2;
2559
2900
  const maximized = this.attributes.maximized;
2560
2901
  (_a2 = this.boxManager) == null ? void 0 : _a2.setMaximized(Boolean(maximized));
2561
2902
  });
2562
2903
  });
2563
- (_b = this.refresher) == null ? void 0 : _b.add("minimized", () => {
2904
+ this.refresher.add("minimized", () => {
2564
2905
  return autorun(() => {
2565
2906
  const minimized = this.attributes.minimized;
2566
2907
  this.onMinimized(minimized);
2567
2908
  });
2568
2909
  });
2569
- (_c = this.refresher) == null ? void 0 : _c.add("mainViewIndex", () => {
2910
+ this.refresher.add("mainViewIndex", () => {
2570
2911
  return autorun(() => {
2571
2912
  const mainSceneIndex = get(this.attributes, "_mainSceneIndex");
2572
2913
  this.onMainViewIndexChange(mainSceneIndex);
2573
2914
  });
2574
2915
  });
2575
- (_d = this.refresher) == null ? void 0 : _d.add("focusedChange", () => {
2916
+ this.refresher.add("focusedChange", () => {
2576
2917
  return autorun(() => {
2577
2918
  const focused = get(this.attributes, "focus");
2578
2919
  this.onFocusChange(focused);
2579
2920
  });
2580
2921
  });
2581
- (_e = this.refresher) == null ? void 0 : _e.add("registeredChange", () => {
2922
+ this.refresher.add("registeredChange", () => {
2582
2923
  return autorun(() => {
2583
2924
  const registered = get(this.attributes, Fields.Registered);
2584
2925
  this.onRegisteredChange(registered);
@@ -2590,9 +2931,9 @@ class AppManager {
2590
2931
  return;
2591
2932
  this.resetScenePath(mainScenePath);
2592
2933
  }
2593
- this.displayerWritableListener(!((_f = this.room) == null ? void 0 : _f.isWritable));
2934
+ this.displayerWritableListener(!((_a = this.room) == null ? void 0 : _a.isWritable));
2594
2935
  this.displayer.callbacks.on("onEnableWriteNowChanged", this.displayerWritableListener);
2595
- this._prevFocused = this.attributes.focus;
2936
+ this.focused$.setValue(this.attributes.focus);
2596
2937
  this.sideEffectManager.add(() => {
2597
2938
  const redoUndo = new RedoUndo({
2598
2939
  mainView: () => this.mainViewProxy.view,
@@ -2643,6 +2984,7 @@ class AppManager {
2643
2984
  }
2644
2985
  setBoxManager(boxManager) {
2645
2986
  this.boxManager = boxManager;
2987
+ this.mainViewProxy.createViewSync();
2646
2988
  }
2647
2989
  resetMaximized() {
2648
2990
  var _a;
@@ -2841,8 +3183,8 @@ class AppManager {
2841
3183
  }
2842
3184
  callbacks$1.clearListeners();
2843
3185
  this.sideEffectManager.flushAll();
2844
- this._prevFocused = void 0;
2845
- this._prevSceneIndex = void 0;
3186
+ this.sceneIndex$.destroy();
3187
+ this.focused$.destroy();
2846
3188
  }
2847
3189
  }
2848
3190
  /*! *****************************************************************************
@@ -3687,16 +4029,16 @@ var shallowequal = function shallowEqual(objA, objB, compare, compareContext) {
3687
4029
  }
3688
4030
  return true;
3689
4031
  };
3690
- var e$2 = Object.defineProperty, t$3 = Object.defineProperties, i$1 = Object.getOwnPropertyDescriptors, s$2 = Object.getOwnPropertySymbols, a$1 = Object.prototype.hasOwnProperty, o$2 = Object.prototype.propertyIsEnumerable, r$4 = (t2, i2, s2) => i2 in t2 ? e$2(t2, i2, { enumerable: true, configurable: true, writable: true, value: s2 }) : t2[i2] = s2, n$3 = (e2, t2) => {
4032
+ 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) => {
3691
4033
  for (var i2 in t2 || (t2 = {}))
3692
- a$1.call(t2, i2) && r$4(e2, i2, t2[i2]);
4034
+ a$1.call(t2, i2) && o$2(e2, i2, t2[i2]);
3693
4035
  if (s$2)
3694
4036
  for (var i2 of s$2(t2))
3695
- o$2.call(t2, i2) && r$4(e2, i2, t2[i2]);
4037
+ n$3.call(t2, i2) && o$2(e2, i2, t2[i2]);
3696
4038
  return e2;
3697
4039
  };
3698
- var v$3, w$2, C$3, y$2, E$3, z$2, B$2, _, N$3, M$3;
3699
- (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 || (B$2 = {})).Close = "close", _.Maximize = "maximize", _.Minimize = "minimize", (M$3 = N$3 || (N$3 = {})).North = "n", M$3.South = "s", M$3.West = "w", M$3.East = "e", M$3.NorthWest = "nw", M$3.NorthEast = "ne", M$3.SouthEast = "se", M$3.SouthWest = "sw";
4040
+ var v$3, w$2, C$3, y$2, E$3, z$2, _, B$2, N$3, S$3;
4041
+ (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";
3700
4042
  function I$3(e2, t2, i2) {
3701
4043
  return Math.min(Math.max(e2, t2), i2);
3702
4044
  }
@@ -3717,7 +4059,7 @@ function V$3(e2) {
3717
4059
  return !e2;
3718
4060
  }
3719
4061
  class H$3 {
3720
- constructor({ readonly$: e2, state$: t2, title$: i2, buttons: s2, onEvent: a2, onDragStart: o2, namespace: r2 = "telebox" }) {
4062
+ constructor({ readonly$: e2, state$: t2, title$: i2, buttons: s2, onEvent: a2, onDragStart: n2, namespace: o2 = "telebox" }) {
3721
4063
  this.sideEffect = new SideEffectManager(), this.lastTitleBarClick = { timestamp: 0, clientX: -100, clientY: -100 }, this.handleTitleBarClick = (e3) => {
3722
4064
  var t3;
3723
4065
  if (this.readonly$.value)
@@ -3728,7 +4070,7 @@ class H$3 {
3728
4070
  return;
3729
4071
  k$1(e3);
3730
4072
  const i3 = Date.now();
3731
- 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: B$2.Maximize }) : this.onDragStart && this.onDragStart(e3), this.lastTitleBarClick.timestamp = i3, this.lastTitleBarClick.clientX = e3.clientX, this.lastTitleBarClick.clientY = e3.clientY;
4073
+ 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;
3732
4074
  }, this.lastTitleBarTouch = { timestamp: 0, clientX: -100, clientY: -100 }, this.handleTitleBarTouch = (e3) => {
3733
4075
  var t3;
3734
4076
  if (this.readonly$.value)
@@ -3737,8 +4079,8 @@ class H$3 {
3737
4079
  return;
3738
4080
  k$1(e3);
3739
4081
  const i3 = Date.now(), { clientX: s3 = this.lastTitleBarTouch.clientX + 100, clientY: a3 = this.lastTitleBarTouch.clientY + 100 } = e3.touches[0] || {};
3740
- i3 - this.lastTitleBarTouch.timestamp <= 500 ? Math.abs(s3 - this.lastTitleBarTouch.clientX) <= 10 && Math.abs(a3 - this.lastTitleBarTouch.clientY) <= 10 && this.onEvent && this.onEvent({ type: B$2.Maximize }) : this.onDragStart && this.onDragStart(e3), this.lastTitleBarTouch.timestamp = i3, this.lastTitleBarTouch.clientX = s3, this.lastTitleBarTouch.clientY = a3;
3741
- }, this.readonly$ = e2, this.state$ = t2, this.title$ = i2, this.onEvent = a2, this.onDragStart = o2, this.namespace = r2, this.buttons = s2 || [{ type: B$2.Minimize, iconClassName: this.wrapClassName("titlebar-icon-minimize") }, { type: B$2.Maximize, iconClassName: this.wrapClassName("titlebar-icon-maximize"), isActive: (e3) => e3 === C$3.Maximized }, { type: B$2.Close, iconClassName: this.wrapClassName("titlebar-icon-close") }], this.$dragArea = this.renderDragArea();
4082
+ 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;
4083
+ }, 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();
3742
4084
  }
3743
4085
  render() {
3744
4086
  if (!this.$titleBar) {
@@ -3814,13 +4156,13 @@ class A$2 {
3814
4156
  i2.className = this.wrapClassName("box-stage-mask");
3815
4157
  const s2 = document.createElement("div");
3816
4158
  s2.className = this.wrapClassName("box-stage-frame");
3817
- const [a2, o2, r2, n2] = ["M0 8V0h8v2H2v6H0Z", "M8 8V0H0v2h6v6h2Z", "M0 0v8h8V6H2V0H0Z", "M8 0v8H0V6h6V0h2Z"].map((e3, t3) => {
4159
+ const [a2, n2, o2, r2] = ["M0 8V0h8v2H2v6H0Z", "M8 8V0H0v2h6v6h2Z", "M0 0v8h8V6H2V0H0Z", "M8 0v8H0V6h6V0h2Z"].map((e3, t3) => {
3818
4160
  const i3 = document.createElementNS("http://www.w3.org/2000/svg", "svg");
3819
4161
  i3.setAttribute("viewBox", "0 0 8 8"), i3.setAttribute("class", `${this.wrapClassName("box-stage-frame-corner")} is-${t3}`);
3820
4162
  const s3 = document.createElementNS("http://www.w3.org/2000/svg", "path");
3821
4163
  return s3.setAttribute("d", e3), s3.setAttribute("fill", "#3381FF"), i3.appendChild(s3), i3;
3822
4164
  });
3823
- return s2.appendChild(a2), s2.appendChild(r2), s2.appendChild(o2), s2.appendChild(n2), e2.appendChild(t2), e2.appendChild(s2), e2.appendChild(i2), this._sideEffect.addDisposer(this.highlightStage$.subscribe((t3) => {
4165
+ 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) => {
3824
4166
  e2.classList.toggle("is-active", t3);
3825
4167
  })), this._sideEffect.addDisposer(combine([this.highlightStage$, this.stageRect$]).subscribe(([s3, a3]) => {
3826
4168
  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`));
@@ -3835,40 +4177,40 @@ class A$2 {
3835
4177
  }
3836
4178
  const W$3 = window.ResizeObserver || ResizeObserver$2;
3837
4179
  class Y$3 {
3838
- constructor({ id: e2 = genUID(), title: t2 = L$3(), namespace: i2 = "telebox", visible: s2 = true, width: a2 = 0.5, height: o2 = 0.5, minWidth: r2 = 0, minHeight: n2 = 0, x: l2 = 0.1, y: $ = 0.1, resizable: b2 = true, draggable: v2 = true, ratio: w2 = -1, focus: y2 = false, zIndex: z2 = 100, titleBar: B2, content: _2, footer: N2, styles: M2, highlightStage: S2 = null, darkMode$: k2, fence$: R2, minimized$: D2, maximized$: T2, readonly$: V2, root$: W2, rootRect$: Y2, managerStageRect$: X2, stageRatio$: P2, collectorRect$: O2, managerHighlightStage$: j2 }) {
4180
+ 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 }) {
3839
4181
  this.events = new Emittery(), this._delegateEvents = new Emittery(), this.handleTrackStart = (e3) => {
3840
4182
  var t3;
3841
4183
  return (t3 = this._handleTrackStart) == null ? void 0 : t3.call(this, e3);
3842
4184
  }, this._sideEffect = new SideEffectManager(), this.id = e2, this.namespace = i2;
3843
- const Z2 = new ValManager();
3844
- this._sideEffect.addDisposer(() => Z2.destroy());
3845
- const F2 = new Val(t2), G2 = new Val(s2), J2 = new Val(b2), q2 = new Val(v2), Q2 = new Val(w2), K2 = new Val(z2), U2 = new Val(y2), ee2 = new Val(_2), te2 = new Val(N2), ie2 = new Val(M2), se2 = combine([D2, T2], ([e3, t3]) => e3 ? C$3.Minimized : t3 ? C$3.Maximized : C$3.Normal), ae2 = new Val({ width: I$3(r2, 0, 1), height: I$3(n2, 0, 1) }, { compare: shallowequal }), oe2 = combine([ae2, X2], ([e3, t3]) => ({ width: e3.width * t3.width, height: e3.height * t3.height }), { compare: shallowequal }), re2 = new Val({ width: a2, height: o2 }, { compare: shallowequal });
3846
- this._sideEffect.addDisposer(ae2.reaction((e3, t3) => {
3847
- re2.setValue({ width: Math.max(a2, e3.width), height: Math.max(o2, e3.height) }, t3);
4185
+ const G2 = new ValManager();
4186
+ this._sideEffect.addDisposer(() => G2.destroy());
4187
+ 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 });
4188
+ this._sideEffect.addDisposer(re2.reaction((e3, t3) => {
4189
+ le2.setValue({ width: Math.max(a2, e3.width), height: Math.max(n2, e3.height) }, t3);
3848
4190
  }));
3849
- const ne2 = new Val({ x: l2, y: $ }, { compare: shallowequal }), he2 = combine([re2, X2], ([e3, t3]) => ({ width: t3.width * e3.width, height: t3.height * e3.height }), { compare: shallowequal }), le2 = combine([ne2, X2], ([e3, t3]) => ({ x: e3.x * t3.width + t3.x, y: e3.y * t3.height + t3.y }), { compare: shallowequal }), de2 = new Val(S2), ce2 = combine([T2, de2, j2], ([e3, t3, i3]) => t3 === null ? i3 && e3 : t3), me2 = new Val(null), ue2 = new Val(Y2.value, { compare: shallowequal }), xe2 = new A$2({ namespace: i2, root$: me2, rootRect$: ue2, ratio$: P2, highlightStage$: ce2 });
3850
- this._sideEffect.addDisposer(() => xe2.destroy());
3851
- withReadonlyValueEnhancer(this, { darkMode: k2, fence: R2, minimized: D2, maximized: T2, readonly: V2, rootRect: Y2, managerStageRect: X2, collectorRect: O2 });
3852
- const ge2 = { zIndex: K2, focus: U2, $userContent: ee2, $userFooter: te2, $userStyles: ie2, state: se2, minSize: ae2, pxMinSize: oe2, intrinsicSize: re2, intrinsicCoord: ne2, pxIntrinsicSize: he2, pxIntrinsicCoord: le2, highlightStage: ce2, boxHighlightStage: de2, contentRect: ue2, contentStageRect: xe2.stageRect$ };
3853
- withReadonlyValueEnhancer(this, ge2, Z2);
3854
- withValueEnhancer(this, { title: F2, visible: G2, resizable: J2, draggable: q2, ratio: Q2 }, Z2), this.titleBar = B2 || new H$3({ readonly$: V2, state$: se2, title$: F2, namespace: this.namespace, onDragStart: (e3) => {
4191
+ 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 });
4192
+ this._sideEffect.addDisposer(() => $e2.destroy());
4193
+ withReadonlyValueEnhancer(this, { darkMode: D2, fence: T2, minimized: V2, maximized: W2, readonly: Y2, rootRect: P2, managerStageRect: O2, collectorRect: Z2 });
4194
+ 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$ };
4195
+ withReadonlyValueEnhancer(this, be2, G2);
4196
+ 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) => {
3855
4197
  var t3;
3856
4198
  return (t3 = this._handleTrackStart) == null ? void 0 : t3.call(this, e3);
3857
- }, onEvent: (e3) => this._delegateEvents.emit(e3.type) }), this._sideEffect.addDisposer(Q2.subscribe((e3) => {
3858
- e3 > 0 && this.transform(le2.value.x, le2.value.y, he2.value.width, he2.value.height, true);
3859
- })), this._sideEffect.addDisposer(R2.subscribe((e3) => {
3860
- e3 && this.move(le2.value.x, le2.value.y, true);
3861
- })), this.$box = this.render(), me2.setValue(this.$content.parentElement);
3862
- const pe2 = (e3, t3) => {
4199
+ }, onEvent: (e3) => this._delegateEvents.emit(e3.type) }), this._sideEffect.addDisposer(U2.subscribe((e3) => {
4200
+ e3 > 0 && this.transform(me2.value.x, me2.value.y, ce2.value.width, ce2.value.height, true);
4201
+ })), this._sideEffect.addDisposer(T2.subscribe((e3) => {
4202
+ e3 && this.move(me2.value.x, me2.value.y, true);
4203
+ })), this.$box = this.render(), pe2.setValue(this.$content.parentElement);
4204
+ const ve2 = (e3, t3) => {
3863
4205
  this._sideEffect.addDisposer(e3.reaction((e4, i3) => {
3864
4206
  i3 || this.events.emit(t3, e4);
3865
4207
  }));
3866
4208
  };
3867
- pe2(k2, E$3.DarkMode), pe2(V2, E$3.Readonly), pe2(K2, E$3.ZIndex), pe2(D2, E$3.Minimized), pe2(T2, E$3.Maximized), pe2(se2, E$3.State), pe2(re2, E$3.IntrinsicResize), pe2(ne2, E$3.IntrinsicMove), this._sideEffect.addDisposer([G2.reaction((e3, t3) => {
4209
+ 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) => {
3868
4210
  t3 || e3 || this.events.emit(E$3.Close);
3869
- }), U2.reaction((e3, t3) => {
4211
+ }), te2.reaction((e3, t3) => {
3870
4212
  t3 || this.events.emit(e3 ? E$3.Focus : E$3.Blur);
3871
- }), W2.subscribe((e3) => {
4213
+ }), X2.subscribe((e3) => {
3872
4214
  e3 ? e3.appendChild(this.$box) : this.$box.parentNode && this.$box.remove();
3873
4215
  })]);
3874
4216
  }
@@ -3901,22 +4243,22 @@ class Y$3 {
3901
4243
  }
3902
4244
  move(e2, t2, i2 = false) {
3903
4245
  let s2, a2;
3904
- const o2 = this.managerStageRect, r2 = this.pxIntrinsicSize;
4246
+ const n2 = this.managerStageRect, o2 = this.pxIntrinsicSize;
3905
4247
  if (this.fence)
3906
- s2 = I$3(e2, o2.x, o2.x + o2.width - r2.width), a2 = I$3(t2, o2.y, o2.y + o2.height - r2.height);
4248
+ s2 = I$3(e2, n2.x, n2.x + n2.width - o2.width), a2 = I$3(t2, n2.y, n2.y + n2.height - o2.height);
3907
4249
  else {
3908
4250
  const i3 = this.rootRect;
3909
- s2 = I$3(e2, i3.x - r2.width + 20, i3.x + i3.width - 20), a2 = I$3(t2, i3.y, i3.y + i3.height - 20);
4251
+ s2 = I$3(e2, 0 - o2.width + 20, 0 + i3.width - 20), a2 = I$3(t2, 0, 0 + i3.height - 20);
3910
4252
  }
3911
- this._intrinsicCoord$.setValue({ x: (s2 - o2.x) / o2.width, y: (a2 - o2.y) / o2.height }, i2);
4253
+ this._intrinsicCoord$.setValue({ x: (s2 - n2.x) / n2.width, y: (a2 - n2.y) / n2.height }, i2);
3912
4254
  }
3913
4255
  transform(e2, t2, i2, s2, a2 = false) {
3914
- const o2 = this.managerStageRect, r2 = this.rootRect;
4256
+ const n2 = this.managerStageRect, o2 = this.rootRect;
3915
4257
  if (i2 = Math.max(i2, this.pxMinSize.width), s2 = Math.max(s2, this.pxMinSize.height), this.ratio > 0) {
3916
4258
  const e3 = this.ratio * i2;
3917
4259
  t2 !== this.pxIntrinsicCoord.y && (t2 -= e3 - s2), s2 = e3;
3918
4260
  }
3919
- t2 < r2.y && (t2 = r2.y, s2 = this.pxIntrinsicSize.height), this.move(e2, t2, a2), this._intrinsicSize$.setValue({ width: i2 / o2.width, height: s2 / o2.height }, a2);
4261
+ 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);
3920
4262
  }
3921
4263
  mountContent(e2) {
3922
4264
  this._$userContent$.setValue(e2);
@@ -3924,6 +4266,12 @@ class Y$3 {
3924
4266
  unmountContent() {
3925
4267
  this._$userContent$.setValue(void 0);
3926
4268
  }
4269
+ mountStage(e2) {
4270
+ this._$userStage$.setValue(e2);
4271
+ }
4272
+ unmountStage() {
4273
+ this._$userStage$.setValue(void 0);
4274
+ }
3927
4275
  mountFooter(e2) {
3928
4276
  this._$userFooter$.setValue(e2);
3929
4277
  }
@@ -3966,47 +4314,68 @@ class Y$3 {
3966
4314
  this.$box.style.zIndex = String(e3);
3967
4315
  })), this.$box.dataset.teleBoxID = this.id;
3968
4316
  const t2 = index(this.$box), i2 = combine([this._maximized$, this._minimized$, this._pxIntrinsicSize$, this._pxIntrinsicCoord$, this._collectorRect$], ([e3, t3, i3, s3, a3]) => {
3969
- const o3 = 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 };
4317
+ 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 };
3970
4318
  if (t3 && a3) {
3971
4319
  const { width: t4, height: s4 } = e3 ? this.rootRect : i3;
3972
- o3.x = a3.x - t4 / 2 + a3.width / 2, o3.y = a3.y - s4 / 2 + a3.height / 2, o3.scaleX = a3.width / t4, o3.scaleY = a3.height / s4;
4320
+ 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;
3973
4321
  }
3974
- return o3;
4322
+ return n3;
3975
4323
  }, { compare: shallowequal }), s2 = i2.value;
3976
4324
  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) => {
3977
4325
  t2.set(e3);
3978
4326
  }));
3979
4327
  const a2 = document.createElement("div");
3980
4328
  a2.className = this.wrapClassName("box-main"), this.$box.appendChild(a2);
4329
+ const n2 = document.createElement("div");
4330
+ n2.className = this.wrapClassName("titlebar-wrap"), n2.appendChild(this.titleBar.render()), this.$titleBar = n2;
3981
4331
  const o2 = document.createElement("div");
3982
- o2.className = this.wrapClassName("titlebar-wrap"), o2.appendChild(this.titleBar.render()), this.$titleBar = o2;
4332
+ o2.className = this.wrapClassName("content-wrap");
3983
4333
  const r2 = document.createElement("div");
3984
- r2.className = this.wrapClassName("content-wrap");
3985
- const n2 = document.createElement("div");
3986
- n2.className = this.wrapClassName("content") + " tele-fancy-scrollbar", this.$content = n2, this._sideEffect.add(() => {
4334
+ r2.className = this.wrapClassName("content") + " tele-fancy-scrollbar", this.$content = r2;
4335
+ const h = () => {
4336
+ const e3 = r2.getBoundingClientRect();
4337
+ this._contentRect$.setValue({ x: 0, y: 0, width: e3.width, height: e3.height });
4338
+ };
4339
+ this._sideEffect.add(() => {
3987
4340
  const e3 = new W$3(() => {
3988
- const e4 = n2.getBoundingClientRect();
3989
- this._contentRect$.setValue({ x: e4.x, y: e4.y, width: e4.width, height: e4.height });
4341
+ this.minimized || h();
3990
4342
  });
3991
- return e3.observe(n2), () => e3.disconnect();
3992
- }), this._sideEffect.add(() => {
4343
+ return e3.observe(r2), () => e3.disconnect();
4344
+ }), this._sideEffect.addDisposer(this._minimized$.reaction((e3) => {
4345
+ e3 || this._sideEffect.setTimeout(h, 400, "minimized-content-rect-fix");
4346
+ })), this._sideEffect.add(() => {
3993
4347
  let e3;
3994
4348
  return this._$userStyles$.subscribe((t3) => {
3995
- e3 && e3.remove(), e3 = t3, t3 && r2.appendChild(t3);
4349
+ e3 && e3.remove(), e3 = t3, t3 && o2.appendChild(t3);
3996
4350
  });
3997
4351
  }), this._sideEffect.add(() => {
3998
4352
  let e3;
3999
4353
  return this._$userContent$.subscribe((t3) => {
4000
- e3 && e3.remove(), e3 = t3, t3 && n2.appendChild(t3);
4354
+ e3 && e3.remove(), e3 = t3, t3 && r2.appendChild(t3);
4001
4355
  });
4002
- }), r2.appendChild(n2);
4003
- const h = document.createElement("div");
4004
- return h.className = this.wrapClassName("footer-wrap"), this.$footer = h, this._sideEffect.add(() => {
4356
+ }), this._sideEffect.add(() => {
4357
+ let e3;
4358
+ return this._$userStage$.subscribe((t3) => {
4359
+ var i3;
4360
+ if (e3 && e3.remove(), e3 = t3, t3) {
4361
+ if (!this.$stage) {
4362
+ const e4 = document.createElement("div");
4363
+ this.$stage = e4, e4.className = this.wrapClassName("content-stage"), this._sideEffect.addDisposer(this._contentStageRect$.subscribe((t4) => {
4364
+ e4.style.top = t4.y + "px", e4.style.left = t4.x + "px", e4.style.width = t4.width + "px", e4.style.height = t4.height + "px";
4365
+ }), "content-stage-rect"), r2.appendChild(e4);
4366
+ }
4367
+ this.$stage.parentElement || r2.appendChild(this.$stage), this.$stage.appendChild(t3);
4368
+ } else
4369
+ ((i3 = this.$stage) == null ? void 0 : i3.parentElement) && this.$stage.remove();
4370
+ });
4371
+ }), o2.appendChild(r2);
4372
+ const c = document.createElement("div");
4373
+ return c.className = this.wrapClassName("footer-wrap"), this.$footer = c, this._sideEffect.add(() => {
4005
4374
  let e3;
4006
4375
  return this._$userFooter$.subscribe((t3) => {
4007
- e3 && e3.remove(), e3 = t3, t3 && h.appendChild(t3);
4376
+ e3 && e3.remove(), e3 = t3, t3 && c.appendChild(t3);
4008
4377
  });
4009
- }), a2.appendChild(o2), a2.appendChild(r2), a2.appendChild(h), this._renderResizeHandlers(), this.$box;
4378
+ }), a2.appendChild(n2), a2.appendChild(o2), a2.appendChild(c), this._renderResizeHandlers(), this.$box;
4010
4379
  }
4011
4380
  _renderResizeHandlers() {
4012
4381
  const e2 = document.createElement("div");
@@ -4015,7 +4384,7 @@ class Y$3 {
4015
4384
  i3.className = this.wrapClassName(t3) + " " + this.wrapClassName("resize-handle"), i3.dataset.teleBoxHandle = t3, e2.appendChild(i3);
4016
4385
  }), this.$box.appendChild(e2);
4017
4386
  const t2 = "handle-tracking-listener", i2 = this.wrapClassName("transforming");
4018
- let s2, a2, o2 = 0, r2 = 0, n2 = 0, h = 0, l2 = 0, d2 = 0;
4387
+ let s2, a2, n2 = 0, o2 = 0, r2 = 0, h = 0, l2 = 0, d2 = 0;
4019
4388
  const c = (e3) => {
4020
4389
  if (this.state !== C$3.Normal)
4021
4390
  return;
@@ -4023,36 +4392,36 @@ class Y$3 {
4023
4392
  let { pageX: t3, pageY: i3 } = R$3(e3);
4024
4393
  i3 < this.rootRect.y && (i3 = this.rootRect.y);
4025
4394
  const s3 = t3 - l2, c2 = i3 - d2;
4026
- let { x: m3, y: u3 } = this.pxIntrinsicCoord, { width: x2, height: g2 } = this.pxIntrinsicSize;
4395
+ let { x: m3, y: u3 } = this.pxIntrinsicCoord, { width: g2, height: p2 } = this.pxIntrinsicSize;
4027
4396
  switch (a2) {
4028
4397
  case N$3.North:
4029
- u3 = r2 + c2, g2 = h - c2;
4398
+ u3 = o2 + c2, p2 = h - c2;
4030
4399
  break;
4031
4400
  case N$3.South:
4032
- g2 = h + c2;
4401
+ p2 = h + c2;
4033
4402
  break;
4034
4403
  case N$3.West:
4035
- m3 = o2 + s3, x2 = n2 - s3;
4404
+ m3 = n2 + s3, g2 = r2 - s3;
4036
4405
  break;
4037
4406
  case N$3.East:
4038
- x2 = n2 + s3;
4407
+ g2 = r2 + s3;
4039
4408
  break;
4040
4409
  case N$3.NorthWest:
4041
- m3 = o2 + s3, u3 = r2 + c2, x2 = n2 - s3, g2 = h - c2;
4410
+ m3 = n2 + s3, u3 = o2 + c2, g2 = r2 - s3, p2 = h - c2;
4042
4411
  break;
4043
4412
  case N$3.NorthEast:
4044
- u3 = r2 + c2, x2 = n2 + s3, g2 = h - c2;
4413
+ u3 = o2 + c2, g2 = r2 + s3, p2 = h - c2;
4045
4414
  break;
4046
4415
  case N$3.SouthEast:
4047
- x2 = n2 + s3, g2 = h + c2;
4416
+ g2 = r2 + s3, p2 = h + c2;
4048
4417
  break;
4049
4418
  case N$3.SouthWest:
4050
- m3 = o2 + s3, x2 = n2 - s3, g2 = h + c2;
4419
+ m3 = n2 + s3, g2 = r2 - s3, p2 = h + c2;
4051
4420
  break;
4052
4421
  default:
4053
- return void this.move(o2 + s3, r2 + c2);
4422
+ return void this.move(n2 + s3, o2 + c2);
4054
4423
  }
4055
- this.transform(m3, u3, x2, g2);
4424
+ this.transform(m3, u3, g2, p2);
4056
4425
  }, m2 = (e3) => {
4057
4426
  a2 = void 0, s2 && (k$1(e3), this.$box.classList.toggle(i2, false), this._sideEffect.flush(t2), s2.remove());
4058
4427
  }, u2 = (e3) => {
@@ -4063,9 +4432,9 @@ class Y$3 {
4063
4432
  return;
4064
4433
  if (!this.draggable || a2 || this.state !== C$3.Normal)
4065
4434
  return;
4066
- const x2 = e3.target;
4067
- if ((u3 = x2.dataset) == null ? void 0 : u3.teleBoxHandle) {
4068
- k$1(e3), { x: o2, y: r2 } = this.pxIntrinsicCoord, { width: n2, height: h } = this.pxIntrinsicSize, { pageX: l2, pageY: d2 } = R$3(e3), a2 = x2.dataset.teleBoxHandle, s2 || (s2 = document.createElement("div"));
4435
+ const g2 = e3.target;
4436
+ if ((u3 = g2.dataset) == null ? void 0 : u3.teleBoxHandle) {
4437
+ 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"));
4069
4438
  const u4 = a2 ? this.wrapClassName(`cursor-${a2}`) : "";
4070
4439
  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 }), () => {
4071
4440
  window.removeEventListener("mousemove", c), window.removeEventListener("touchmove", c), window.removeEventListener("mouseup", m2), window.removeEventListener("touchend", m2), window.removeEventListener("touchcancel", m2);
@@ -4083,33 +4452,33 @@ class Y$3 {
4083
4452
  }
4084
4453
  var X$3, P$3;
4085
4454
  class O$3 {
4086
- constructor({ minimized$: e2, readonly$: t2, darkMode$: i2, rootRect$: s2, namespace: a2 = "telebox", styles: o2 = {}, root$: r2 }) {
4087
- this._sideEffect = new SideEffectManager(), this.namespace = a2;
4088
- const n2 = new ValManager();
4089
- this._sideEffect.addDisposer(() => n2.destroy());
4090
- const h = new Val(void 0), l2 = derive(e2), d2 = new Val(o2), m2 = new Val(document.createElement("button"));
4091
- withValueEnhancer(this, { styles: d2, $collector: m2 }, n2);
4092
- withReadonlyValueEnhancer(this, { root: r2 });
4093
- withReadonlyValueEnhancer(this, { rect: h, visible: l2 }, n2), m2.value.className = this.wrapClassName("collector"), m2.value.style.backgroundImage = "url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxOCAxNiI+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxwYXRoIHN0cm9rZT0iIzdCODhBMCIgc3Ryb2tlLXdpZHRoPSIxLjQiIGQ9Ik0uNyAxLjJoMTYuNnYxMy42SC43eiIgLz4KICAgICAgICA8cGF0aCBmaWxsPSIjN0I4OEEwIiBkPSJNNCA1LjVoNnYxLjRINHpNNCA5LjVoMTB2MS40SDR6IiAvPgogICAgPC9nPgo8L3N2Zz4K')", this._sideEffect.addDisposer(m2.subscribe((a3) => {
4094
- this._sideEffect.addEventListener(a3, "click", () => {
4455
+ constructor({ minimized$: e2, readonly$: t2, darkMode$: i2, namespace: s2 = "telebox", styles: a2 = {}, root$: n2 }) {
4456
+ this._sideEffect = new SideEffectManager(), this.namespace = s2;
4457
+ const o2 = new ValManager();
4458
+ this._sideEffect.addDisposer(() => o2.destroy());
4459
+ const r2 = new Val(void 0), h = derive(e2), l2 = new Val(a2), d2 = new Val(document.createElement("button"));
4460
+ withValueEnhancer(this, { styles: l2, $collector: d2 }, o2);
4461
+ withReadonlyValueEnhancer(this, { root: n2 });
4462
+ 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) => {
4463
+ this._sideEffect.addEventListener(s3, "click", () => {
4095
4464
  t2.value || e2.setValue(false);
4096
- }, {}, "telebox-collector-click"), this._sideEffect.addDisposer([l2.subscribe((e3) => {
4097
- a3.classList.toggle(this.wrapClassName("collector-visible"), e3);
4465
+ }, {}, "telebox-collector-click"), this._sideEffect.addDisposer([h.subscribe((e3) => {
4466
+ s3.classList.toggle(this.wrapClassName("collector-visible"), e3);
4098
4467
  }), t2.subscribe((e3) => {
4099
- a3.classList.toggle(this.wrapClassName("collector-readonly"), e3);
4468
+ s3.classList.toggle(this.wrapClassName("collector-readonly"), e3);
4100
4469
  }), i2.subscribe((e3) => {
4101
- a3.classList.toggle(this.wrapClassName("color-scheme-dark"), e3), a3.classList.toggle(this.wrapClassName("color-scheme-light"), !e3);
4102
- }), d2.subscribe((e3) => {
4470
+ s3.classList.toggle(this.wrapClassName("color-scheme-dark"), e3), s3.classList.toggle(this.wrapClassName("color-scheme-light"), !e3);
4471
+ }), l2.subscribe((e3) => {
4103
4472
  Object.keys(e3).forEach((t3) => {
4104
4473
  const i3 = e3[t3];
4105
- i3 != null && (a3.style[t3] = i3);
4474
+ i3 != null && (s3.style[t3] = i3);
4106
4475
  });
4107
- }), r2.subscribe((e3) => {
4108
- e3 && e3.appendChild(a3);
4109
- }), combine([e2, s2, r2]).subscribe(([e3, t3, i3]) => {
4110
- if (e3 && i3) {
4111
- const { x: e4, y: i4, width: s3, height: o3 } = a3.getBoundingClientRect();
4112
- h.setValue({ x: e4 - t3.x, y: i4 - t3.y, width: s3, height: o3 });
4476
+ }), n2.subscribe((e3) => {
4477
+ e3 && e3.appendChild(s3);
4478
+ }), combine([e2, n2]).subscribe(([e3, t3]) => {
4479
+ if (e3 && t3) {
4480
+ const { x: e4, y: i3, width: a3, height: n3 } = s3.getBoundingClientRect(), o3 = t3.getBoundingClientRect();
4481
+ r2.setValue({ x: e4 - o3.x, y: i3 - o3.y, width: a3, height: n3 });
4113
4482
  }
4114
4483
  })], "telebox-collector-el");
4115
4484
  }));
@@ -4135,8 +4504,8 @@ class j$1 extends H$3 {
4135
4504
  if (this.$titles && this.state$.value === C$3.Maximized) {
4136
4505
  const { children: i2 } = this.$titles.firstElementChild;
4137
4506
  for (let s2 = i2.length - 1; s2 >= 0; s2 -= 1) {
4138
- const a2 = i2[s2], o2 = (t2 = a2.dataset) == null ? void 0 : t2.teleBoxID;
4139
- o2 && (e2 && o2 === e2.id ? a2.classList.toggle(this.wrapClassName("titles-tab-focus"), true) : this.focusedBox && o2 === this.focusedBox.id && a2.classList.toggle(this.wrapClassName("titles-tab-focus"), false));
4507
+ const a2 = i2[s2], n2 = (t2 = a2.dataset) == null ? void 0 : t2.teleBoxID;
4508
+ 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));
4140
4509
  }
4141
4510
  }
4142
4511
  this.focusedBox = e2;
@@ -4176,11 +4545,11 @@ class j$1 extends H$3 {
4176
4545
  }
4177
4546
  const Z$3 = window.ResizeObserver || ResizeObserver$2;
4178
4547
  class F$3 {
4179
- constructor({ root: e2 = null, prefersColorScheme: t2 = v$3.Light, minimized: i2 = false, maximized: s2 = false, fence: a2 = false, collector: o2, namespace: r2 = "telebox", readonly: n2 = false, stageRatio: l2 = -1, highlightStage: m2 = true } = {}) {
4180
- this.events = new Emittery(), this._sideEffect = new SideEffectManager(), this.namespace = r2;
4548
+ 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 } = {}) {
4549
+ this.events = new Emittery(), this._sideEffect = new SideEffectManager(), this.namespace = o2;
4181
4550
  const b2 = new ValManager();
4182
4551
  this._sideEffect.addDisposer(() => b2.destroy());
4183
- const w2 = new Val(e2), y2 = new Val(n2), z2 = new Val(i2), _2 = new Val(s2), N2 = new Val(a2), M2 = new Val(l2), S2 = new Val(m2), I2 = new Val({ x: 0, y: 0, width: window.innerWidth, height: window.innerHeight }, { compare: shallowequal });
4552
+ 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 });
4184
4553
  this._sideEffect.addDisposer(w2.subscribe((e3) => {
4185
4554
  this._sideEffect.add(() => {
4186
4555
  if (!e3)
@@ -4188,7 +4557,7 @@ class F$3 {
4188
4557
  };
4189
4558
  const t3 = new Z$3(() => {
4190
4559
  const t4 = e3.getBoundingClientRect();
4191
- I2.setValue({ x: t4.x, y: t4.y, width: t4.width, height: t4.height });
4560
+ I2.setValue({ x: 0, y: 0, width: t4.width, height: t4.height });
4192
4561
  });
4193
4562
  return t3.observe(e3), () => t3.disconnect();
4194
4563
  }, "calc-root-rect");
@@ -4210,13 +4579,13 @@ class F$3 {
4210
4579
  this._sideEffect.addDisposer(D2.reaction((e3, t3) => {
4211
4580
  t3 || this.events.emit(X$3.PrefersColorScheme, e3);
4212
4581
  }));
4213
- const L2 = combine([R2, D2], ([e3, t3]) => t3 === "auto" ? e3 : t3 === "dark"), T2 = combine([z2, _2], ([e3, t3]) => e3 ? C$3.Minimized : t3 ? C$3.Maximized : C$3.Normal);
4214
- this.collector = o2 != null ? o2 : new O$3({ minimized$: z2, readonly$: y2, darkMode$: L2, namespace: r2, root$: w2, rootRect$: I2 });
4215
- const V2 = new A$2({ namespace: r2, rootRect$: I2, ratio$: M2, root$: w2, highlightStage$: combine([S2, _2, z2], ([e3, t3, i3]) => e3 && (i3 || !t3)) });
4582
+ 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);
4583
+ this.collector = n2 != null ? n2 : new O$3({ minimized$: z2, readonly$: y2, darkMode$: L2, namespace: o2, root$: w2 });
4584
+ const V2 = new A$2({ namespace: o2, rootRect$: I2, ratio$: S2, root$: w2, highlightStage$: combine([M2, B2, z2], ([e3, t3, i3]) => e3 && (i3 || !t3)) });
4216
4585
  this._sideEffect.addDisposer(() => V2.destroy());
4217
4586
  const H2 = { darkMode: L2, state: T2, root: w2, rootRect: I2, stageRect: V2.stageRect$ };
4218
4587
  withReadonlyValueEnhancer(this, H2, b2);
4219
- withValueEnhancer(this, { prefersColorScheme: D2, readonly: y2, fence: N2, minimized: z2, maximized: _2, stageRatio: M2, highlightStage: S2 }, b2);
4588
+ withValueEnhancer(this, { prefersColorScheme: D2, readonly: y2, fence: N2, minimized: z2, maximized: B2, stageRatio: S2, highlightStage: M2 }, b2);
4220
4589
  const W2 = this.wrapClassName("titlebar-icon-close"), Y2 = (e3) => {
4221
4590
  var t3;
4222
4591
  if (y2.value)
@@ -4236,10 +4605,10 @@ class F$3 {
4236
4605
  };
4237
4606
  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) => {
4238
4607
  switch (e3.type) {
4239
- case B$2.Maximize:
4240
- _2.setValue(!_2.value);
4608
+ case _.Maximize:
4609
+ B2.setValue(!B2.value);
4241
4610
  break;
4242
- case B$2.Minimize:
4611
+ case _.Minimize:
4243
4612
  z2.setValue(true);
4244
4613
  break;
4245
4614
  case E$3.Close:
@@ -4247,7 +4616,7 @@ class F$3 {
4247
4616
  }
4248
4617
  } }), this._sideEffect.addDisposer([T2.reaction((e3, t3) => {
4249
4618
  t3 || this.events.emit(X$3.State, e3);
4250
- }), _2.reaction((e3, t3) => {
4619
+ }), B2.reaction((e3, t3) => {
4251
4620
  t3 || this.events.emit(X$3.Maximized, e3);
4252
4621
  }), z2.reaction((e3, t3) => {
4253
4622
  t3 || this.events.emit(X$3.Minimized, e3);
@@ -4275,13 +4644,13 @@ class F$3 {
4275
4644
  return this;
4276
4645
  }
4277
4646
  create(e2 = {}, s2 = true) {
4278
- const a2 = new Y$3((o2 = n$3(n$3({ zIndex: this.topBox ? this.topBox.zIndex + 1 : 100 }, e2), s2 ? this.smartPosition(e2) : {}), r2 = { namespace: this.namespace, root$: this._root$, darkMode$: this._darkMode$, maximized$: this._maximized$, minimized$: this._minimized$, fence$: this._fence$, rootRect$: this._rootRect$, managerStageRect$: this._stageRect$, stageRatio$: this._stageRatio$, readonly$: this._readonly$, collectorRect$: this.collector._rect$, managerHighlightStage$: this._highlightStage$ }, t$3(o2, i$1(r2))));
4279
- var o2, r2;
4280
- return a2.focus && (this.focusBox(a2), s2 && this.makeBoxTop(a2)), this.boxes$.setValue([...this.boxes, a2]), this._sideEffect.addDisposer([a2._delegateEvents.on(B$2.Maximize, () => {
4647
+ 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))));
4648
+ var n2, o2;
4649
+ return a2.focus && (this.focusBox(a2), s2 && this.makeBoxTop(a2)), this.boxes$.setValue([...this.boxes, a2]), this._sideEffect.addDisposer([a2._delegateEvents.on(_.Maximize, () => {
4281
4650
  this.setMaximized(!this.maximized);
4282
- }), a2._delegateEvents.on(B$2.Minimize, () => {
4651
+ }), a2._delegateEvents.on(_.Minimize, () => {
4283
4652
  this.setMinimized(true);
4284
- }), a2._delegateEvents.on(B$2.Close, () => {
4653
+ }), a2._delegateEvents.on(_.Close, () => {
4285
4654
  this.remove(a2), this.focusTopBox();
4286
4655
  }), a2._intrinsicCoord$.reaction((e3, t2) => {
4287
4656
  t2 || this.events.emit(X$3.IntrinsicMove, a2);
@@ -4366,27 +4735,27 @@ class F$3 {
4366
4735
  return (i2) => t2.every((t3) => e2[t3] === i2[t3]);
4367
4736
  }
4368
4737
  updateBox(e2, t2, i2 = false) {
4369
- var s2, a2, o2, r2, n2, h;
4370
- 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: (o2 = t2.width) != null ? o2 : e2.intrinsicWidth, height: (r2 = t2.height) != null ? r2 : 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.content != null && e2.mountContent(t2.content), t2.footer != null && e2.mountFooter(t2.footer), t2.minHeight == null && t2.minWidth == null || e2._minSize$.setValue({ width: (n2 = t2.minWidth) != null ? n2 : e2.minWidth, height: (h = t2.minHeight) != null ? h : e2.minHeight }, i2);
4738
+ var s2, a2, n2, o2, r2, h;
4739
+ 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);
4371
4740
  }
4372
4741
  smartPosition(e2) {
4373
4742
  let { x: t2, y: i2 } = e2;
4374
- const { width: s2 = 0.5, height: a2 = 0.5 } = e2, o2 = this.stageRect, r2 = this.topBox;
4743
+ const { width: s2 = 0.5, height: a2 = 0.5 } = e2, n2 = this.stageRect, o2 = this.topBox;
4375
4744
  if (t2 == null) {
4376
- let e3 = o2.x + 20;
4377
- if (r2) {
4378
- const t3 = r2.pxIntrinsicCoord.x + 20;
4379
- t3 + s2 * o2.width <= o2.x + o2.width && (e3 = t3);
4745
+ let e3 = n2.x + 20;
4746
+ if (o2) {
4747
+ const t3 = o2.pxIntrinsicCoord.x + 20;
4748
+ t3 + s2 * n2.width <= n2.x + n2.width && (e3 = t3);
4380
4749
  }
4381
- t2 = (e3 - o2.x) / o2.width;
4750
+ t2 = (e3 - n2.x) / n2.width;
4382
4751
  }
4383
4752
  if (i2 == null) {
4384
- let e3 = o2.y + 20;
4385
- if (r2) {
4386
- const t3 = r2.pxIntrinsicCoord.y + 20;
4387
- t3 + a2 * o2.height <= o2.y + o2.height && (e3 = t3);
4753
+ let e3 = n2.y + 20;
4754
+ if (o2) {
4755
+ const t3 = o2.pxIntrinsicCoord.y + 20;
4756
+ t3 + a2 * n2.height <= n2.y + n2.height && (e3 = t3);
4388
4757
  }
4389
- i2 = (e3 - o2.y) / o2.height;
4758
+ i2 = (e3 - n2.y) / n2.height;
4390
4759
  }
4391
4760
  return { x: t2, y: i2, width: s2, height: a2 };
4392
4761
  }
@@ -4403,7 +4772,6 @@ class F$3 {
4403
4772
  const createBoxManager = (manager, callbacks2, emitter2, boxEmitter2, options) => {
4404
4773
  return new BoxManager({
4405
4774
  safeSetAttributes: (attributes) => manager.safeSetAttributes(attributes),
4406
- getMainView: () => manager.mainView,
4407
4775
  updateAppState: (...args) => {
4408
4776
  var _a;
4409
4777
  return (_a = manager.appManager) == null ? void 0 : _a.store.updateAppState(...args);
@@ -4433,17 +4801,17 @@ class BoxManager {
4433
4801
  const { emitter: emitter2, callbacks: callbacks2, boxEmitter: boxEmitter2 } = context;
4434
4802
  this.teleBoxManager = this.setupBoxManager(createTeleBoxManagerConfig);
4435
4803
  this.sideEffectManager.add(() => [
4436
- this.teleBoxManager._state$.reaction((state) => {
4804
+ this.teleBoxManager.onValChanged("state", (state) => {
4437
4805
  callbacks2.emit("boxStateChange", state);
4438
4806
  emitter2.emit("boxStateChange", state);
4439
4807
  }),
4440
- this.teleBoxManager._darkMode$.reaction((darkMode) => {
4808
+ this.teleBoxManager.onValChanged("darkMode", (darkMode) => {
4441
4809
  callbacks2.emit("darkModeChange", darkMode);
4442
4810
  }),
4443
- this.teleBoxManager._prefersColorScheme$.reaction((colorScheme) => {
4811
+ this.teleBoxManager.onValChanged("prefersColorScheme", (colorScheme) => {
4444
4812
  callbacks2.emit("prefersColorSchemeChange", colorScheme);
4445
4813
  }),
4446
- this.teleBoxManager._minimized$.reaction((minimized, skipUpdate) => {
4814
+ this.teleBoxManager.onValChanged("minimized", (minimized, skipUpdate) => {
4447
4815
  if (skipUpdate) {
4448
4816
  return;
4449
4817
  }
@@ -4459,7 +4827,7 @@ class BoxManager {
4459
4827
  }
4460
4828
  }
4461
4829
  }),
4462
- this.teleBoxManager._maximized$.reaction((maximized, skipUpdate) => {
4830
+ this.teleBoxManager.onValChanged("maximized", (maximized, skipUpdate) => {
4463
4831
  if (skipUpdate) {
4464
4832
  return;
4465
4833
  }
@@ -4471,7 +4839,11 @@ class BoxManager {
4471
4839
  });
4472
4840
  }),
4473
4841
  this.teleBoxManager.events.on("intrinsic_move", debounce((box) => {
4474
- boxEmitter2.emit("move", { appId: box.id, x: box.intrinsicX, y: box.intrinsicY });
4842
+ boxEmitter2.emit("move", {
4843
+ appId: box.id,
4844
+ x: box.intrinsicX,
4845
+ y: box.intrinsicY
4846
+ });
4475
4847
  }, 50)),
4476
4848
  this.teleBoxManager.events.on("intrinsic_resize", debounce((box) => {
4477
4849
  boxEmitter2.emit("resize", {
@@ -4504,9 +4876,6 @@ class BoxManager {
4504
4876
  })
4505
4877
  ]);
4506
4878
  }
4507
- get mainView() {
4508
- return this.context.getMainView();
4509
- }
4510
4879
  get canOperate() {
4511
4880
  return this.context.canOperate();
4512
4881
  }
@@ -4531,6 +4900,9 @@ class BoxManager {
4531
4900
  get stageRect() {
4532
4901
  return this.teleBoxManager.stageRect;
4533
4902
  }
4903
+ get stageRect$() {
4904
+ return this.teleBoxManager._stageRect$;
4905
+ }
4534
4906
  createBox(params) {
4535
4907
  var _a, _b, _c;
4536
4908
  if (!this.teleBoxManager)
@@ -4553,8 +4925,9 @@ class BoxManager {
4553
4925
  height,
4554
4926
  id: params.appId
4555
4927
  };
4556
- this.teleBoxManager.create(createBoxConfig, params.smartPosition);
4928
+ const box = this.teleBoxManager.create(createBoxConfig, params.smartPosition);
4557
4929
  this.context.emitter.emit(`${params.appId}${Events.WindowCreated}`);
4930
+ return box;
4558
4931
  }
4559
4932
  setupBoxManager(createTeleBoxManagerConfig) {
4560
4933
  const root = WindowManager.playground;
@@ -4562,7 +4935,8 @@ class BoxManager {
4562
4935
  stageRatio: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.stageRatio,
4563
4936
  root,
4564
4937
  fence: false,
4565
- prefersColorScheme: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.prefersColorScheme
4938
+ prefersColorScheme: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.prefersColorScheme,
4939
+ highlightStage: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.highlightStage
4566
4940
  };
4567
4941
  const manager = new F$3(initManagerState);
4568
4942
  if (this.teleBoxManager) {
@@ -5629,7 +6003,7 @@ class ReconnectRefresher {
5629
6003
  };
5630
6004
  this.onReconnected = debounce(() => {
5631
6005
  this._onReconnected();
5632
- }, 3e3);
6006
+ }, 1e3);
5633
6007
  this._onReconnected = () => {
5634
6008
  log("onReconnected refresh reactors");
5635
6009
  this.releaseDisposers();
@@ -5677,6 +6051,7 @@ class ReconnectRefresher {
5677
6051
  this.reactors.set(id2, func);
5678
6052
  this.disposers.set(id2, func());
5679
6053
  }
6054
+ return () => this.remove(id2);
5680
6055
  }
5681
6056
  remove(id2) {
5682
6057
  if (this.reactors.has(id2)) {
@@ -5748,6 +6123,9 @@ const replaceRoomFunction = (room, manager) => {
5748
6123
  room.lockImage = (...args) => manager.lockImage(...args);
5749
6124
  room.lockImages = (...args) => manager.lockImages(...args);
5750
6125
  delegateRemoveScenes(room, manager);
6126
+ if (!room.dynamicPpt.slideStateAdapter.pptHandler) {
6127
+ room.dynamicPpt.slideStateAdapter.pptHandler = manager.createPPTHandler();
6128
+ }
5751
6129
  }
5752
6130
  };
5753
6131
  const delegateRemoveScenes = (room, manager) => {
@@ -15302,20 +15680,20 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
15302
15680
  const _WindowManager = class extends InvisiblePlugin {
15303
15681
  constructor(context) {
15304
15682
  super(context);
15305
- this.version = "1.0.0-canary.2";
15306
- this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.8", "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.2.1", "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" } };
15683
+ this.version = "1.0.0-canary.20";
15684
+ 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" } };
15307
15685
  this.emitter = callbacks$1;
15308
15686
  this.viewMode = ViewMode.Broadcaster;
15687
+ this.viewMode$ = new Val(ViewMode.Broadcaster);
15309
15688
  this.isReplay = isPlayer(this.displayer);
15310
15689
  this.containerSizeRatio = _WindowManager.containerSizeRatio;
15311
15690
  _WindowManager.displayer = context.displayer;
15312
- window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.8", "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.2.1", "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" } };
15691
+ 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" } };
15313
15692
  }
15314
15693
  static async mount(params) {
15315
15694
  var _a;
15316
15695
  const room = params.room;
15317
15696
  _WindowManager.container = params.container;
15318
- const containerSizeRatio = params.containerSizeRatio;
15319
15697
  const debug = params.debug;
15320
15698
  const cursor = params.cursor;
15321
15699
  _WindowManager.params = params;
@@ -15352,21 +15730,20 @@ const _WindowManager = class extends InvisiblePlugin {
15352
15730
  if (!manager) {
15353
15731
  throw new Error("[WindowManager]: create manager failed");
15354
15732
  }
15355
- if (containerSizeRatio) {
15356
- _WindowManager.containerSizeRatio = containerSizeRatio;
15733
+ if (params.containerSizeRatio) {
15734
+ _WindowManager.containerSizeRatio = params.containerSizeRatio;
15357
15735
  }
15736
+ manager.containerSizeRatio = _WindowManager.containerSizeRatio;
15358
15737
  await manager.ensureAttributes();
15359
15738
  manager.appManager = new AppManager(manager);
15360
15739
  manager._pageState = new PageStateImpl(manager.appManager);
15361
15740
  manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor), params.applianceIcons);
15362
- if (containerSizeRatio) {
15363
- manager.containerSizeRatio = containerSizeRatio;
15364
- }
15365
15741
  manager.boxManager = createBoxManager(manager, callbacks$1, emitter, boxEmitter, {
15366
15742
  collectorContainer: params.collectorContainer,
15367
15743
  collectorStyles: params.collectorStyles,
15368
15744
  prefersColorScheme: params.prefersColorScheme,
15369
- stageRatio: params.containerSizeRatio
15745
+ stageRatio: _WindowManager.containerSizeRatio,
15746
+ highlightStage: params.highlightStage
15370
15747
  });
15371
15748
  (_a = manager.appManager) == null ? void 0 : _a.setBoxManager(manager.boxManager);
15372
15749
  if (params.container) {
@@ -15586,6 +15963,17 @@ const _WindowManager = class extends InvisiblePlugin {
15586
15963
  return false;
15587
15964
  }
15588
15965
  }
15966
+ async jumpPage(index2) {
15967
+ if (!this.appManager) {
15968
+ return false;
15969
+ }
15970
+ if (index2 < 0 || index2 >= this.pageState.length) {
15971
+ console.warn(`[WindowManager]: index ${index2} out of range`);
15972
+ return false;
15973
+ }
15974
+ await this.appManager.setMainViewSceneIndex(index2);
15975
+ return true;
15976
+ }
15589
15977
  async addPage(params) {
15590
15978
  if (this.appManager) {
15591
15979
  const after = params == null ? void 0 : params.after;
@@ -15636,17 +16024,20 @@ const _WindowManager = class extends InvisiblePlugin {
15636
16024
  addEmitterOnceListener(`destroy-${kind2}`, listener);
15637
16025
  }
15638
16026
  setViewMode(mode) {
15639
- var _a, _b, _c;
16027
+ var _a;
16028
+ log("setViewMode", mode);
16029
+ const mainViewProxy = (_a = this.appManager) == null ? void 0 : _a.mainViewProxy;
15640
16030
  if (mode === ViewMode.Broadcaster) {
15641
16031
  if (this.canOperate) {
15642
- (_a = this.appManager) == null ? void 0 : _a.mainViewProxy.setCameraAndSize();
16032
+ mainViewProxy == null ? void 0 : mainViewProxy.storeCurrentCamera();
15643
16033
  }
15644
- (_b = this.appManager) == null ? void 0 : _b.mainViewProxy.start();
16034
+ mainViewProxy == null ? void 0 : mainViewProxy.start();
15645
16035
  }
15646
16036
  if (mode === ViewMode.Freedom) {
15647
- (_c = this.appManager) == null ? void 0 : _c.mainViewProxy.stop();
16037
+ mainViewProxy == null ? void 0 : mainViewProxy.stop();
15648
16038
  }
15649
16039
  this.viewMode = mode;
16040
+ this.viewMode$.setValue(mode);
15650
16041
  }
15651
16042
  setBoxState(boxState) {
15652
16043
  if (!this.canOperate)
@@ -15793,7 +16184,7 @@ const _WindowManager = class extends InvisiblePlugin {
15793
16184
  (_a = this.appManager) == null ? void 0 : _a.dispatchInternalEvent(Events.MoveCamera, camera);
15794
16185
  setTimeout(() => {
15795
16186
  var _a2;
15796
- (_a2 = this.appManager) == null ? void 0 : _a2.mainViewProxy.setCameraAndSize();
16187
+ (_a2 = this.appManager) == null ? void 0 : _a2.mainViewProxy.storeCurrentCamera();
15797
16188
  }, 500);
15798
16189
  }
15799
16190
  moveCameraToContain(rectangle) {
@@ -15802,7 +16193,7 @@ const _WindowManager = class extends InvisiblePlugin {
15802
16193
  (_a = this.appManager) == null ? void 0 : _a.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
15803
16194
  setTimeout(() => {
15804
16195
  var _a2;
15805
- (_a2 = this.appManager) == null ? void 0 : _a2.mainViewProxy.setCameraAndSize();
16196
+ (_a2 = this.appManager) == null ? void 0 : _a2.mainViewProxy.storeCurrentCamera();
15806
16197
  }, 500);
15807
16198
  }
15808
16199
  convertToPointInWorld(point) {
@@ -15914,12 +16305,12 @@ const _WindowManager = class extends InvisiblePlugin {
15914
16305
  (_a = this.appManager) == null ? void 0 : _a.dispatchInternalEvent(Events.Refresh);
15915
16306
  }
15916
16307
  _refresh() {
15917
- var _a, _b, _c;
16308
+ var _a, _b;
15918
16309
  (_a = this.appManager) == null ? void 0 : _a.mainViewProxy.rebind();
15919
16310
  if (_WindowManager.container) {
15920
16311
  this.bindContainer(_WindowManager.container);
15921
16312
  }
15922
- (_c = (_b = this.appManager) == null ? void 0 : _b.refresher) == null ? void 0 : _c.refresh();
16313
+ (_b = this.appManager) == null ? void 0 : _b.refresher.refresh();
15923
16314
  }
15924
16315
  setContainerSizeRatio(ratio) {
15925
16316
  if (!isNumber(ratio)) {
@@ -15929,6 +16320,26 @@ const _WindowManager = class extends InvisiblePlugin {
15929
16320
  this.containerSizeRatio = ratio;
15930
16321
  emitter.emit("containerSizeRatioUpdate", ratio);
15931
16322
  }
16323
+ createPPTHandler() {
16324
+ return {
16325
+ onPageJumpTo: (_pptUUID, index2) => {
16326
+ var _a, _b, _c, _d;
16327
+ (_d = (_c = (_b = (_a = this.appManager) == null ? void 0 : _a.focusApp) == null ? void 0 : _b.appContext) == null ? void 0 : _c.whiteBoardView) == null ? void 0 : _d.jumpPage(index2);
16328
+ },
16329
+ onPageToNext: () => {
16330
+ var _a, _b, _c, _d;
16331
+ if (this.focused) {
16332
+ (_d = (_c = (_b = (_a = this.appManager) == null ? void 0 : _a.focusApp) == null ? void 0 : _b.appContext) == null ? void 0 : _c.whiteBoardView) == null ? void 0 : _d.nextPage();
16333
+ }
16334
+ },
16335
+ onPageToPrev: () => {
16336
+ var _a, _b, _c, _d;
16337
+ if (this.focused) {
16338
+ (_d = (_c = (_b = (_a = this.appManager) == null ? void 0 : _a.focusApp) == null ? void 0 : _b.appContext) == null ? void 0 : _c.whiteBoardView) == null ? void 0 : _d.prevPage();
16339
+ }
16340
+ }
16341
+ };
16342
+ }
15932
16343
  isDynamicPPT(scenes) {
15933
16344
  var _a, _b;
15934
16345
  const sceneSrc = (_b = (_a = scenes[0]) == null ? void 0 : _a.ppt) == null ? void 0 : _b.src;