@netless/window-manager 1.0.0-canary.35 → 1.0.0-canary.38

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.
package/dist/index.es.js CHANGED
@@ -31,8 +31,8 @@ var __objRest = (source2, exclude) => {
31
31
  };
32
32
  import pRetry from "p-retry";
33
33
  import Emittery from "emittery";
34
- import { debounce, isObject as isObject$2, has, get, size, mapValues, noop as noop$3, pick, isBoolean as isBoolean$2, isNumber as isNumber$2, throttle, isEqual, omitBy, isUndefined, isInteger, orderBy, isEmpty as isEmpty$2, omit, isFunction as isFunction$2, isNull } from "lodash";
35
- import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, toJS, WhiteVersion, autorun, listenDisposed, unlistenDisposed, AnimationMode, ViewMode, isPlayer, isRoom, ApplianceNames, RoomPhase, InvisiblePlugin } from "white-web-sdk";
34
+ import { debounce, throttle, isEqual, pick, isObject as isObject$2, has, get, size, mapValues, noop as noop$3, isBoolean as isBoolean$2, isNumber as isNumber$2, omitBy, isUndefined, isInteger, orderBy, isEmpty as isEmpty$2, omit, isFunction as isFunction$2, isNull } from "lodash";
35
+ import { ScenePathType, AnimationMode, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, toJS, WhiteVersion, autorun, listenDisposed, unlistenDisposed, ViewMode, isPlayer, isRoom, ApplianceNames, RoomPhase, InvisiblePlugin } from "white-web-sdk";
36
36
  import { v4 } from "uuid";
37
37
  import { genUID, SideEffectManager } from "side-effect-manager";
38
38
  import { Val as Val$1, combine as combine$1, ValManager, withReadonlyValueEnhancer as withReadonlyValueEnhancer$1, withValueEnhancer as withValueEnhancer$1, derive as derive$1 } from "value-enhancer";
@@ -54,6 +54,8 @@ var Events = /* @__PURE__ */ ((Events2) => {
54
54
  Events2["Refresh"] = "Refresh";
55
55
  Events2["InitMainViewCamera"] = "InitMainViewCamera";
56
56
  Events2["InvokeAttributesUpdateCallback"] = "InvokeAttributesUpdateCallback";
57
+ Events2["MoveCamera"] = "MoveCamera";
58
+ Events2["MoveCameraToContain"] = "moveCameraToContain";
57
59
  return Events2;
58
60
  })(Events || {});
59
61
  const MagixEventName = "__WindowManger";
@@ -462,6 +464,66 @@ const isRootDirPage = (scenePath) => {
462
464
  }, 0);
463
465
  return delimiterCount === 1;
464
466
  };
467
+ class CameraSynchronizer {
468
+ constructor(saveCamera) {
469
+ this.saveCamera = saveCamera;
470
+ this.setRect = (rect) => {
471
+ this.rect = rect;
472
+ if (this.remoteCamera && this.remoteSize) {
473
+ this.onRemoteUpdate(this.remoteCamera, this.remoteSize);
474
+ }
475
+ };
476
+ this.onRemoteUpdate = throttle((camera, size2) => {
477
+ this.remoteCamera = camera;
478
+ this.remoteSize = size2;
479
+ if (this.remoteSize && this.rect) {
480
+ const nextScale = camera.scale * computedMinScale(size2, this.rect);
481
+ const config = {
482
+ scale: nextScale
483
+ };
484
+ if (camera.centerX !== null) {
485
+ config.centerX = camera.centerX;
486
+ }
487
+ if (camera.centerY !== null) {
488
+ config.centerY = camera.centerY;
489
+ }
490
+ this.moveCamera(config);
491
+ }
492
+ }, 10);
493
+ }
494
+ setView(view) {
495
+ this.view = view;
496
+ }
497
+ onRemoteSizeUpdate(size2) {
498
+ var _a;
499
+ this.remoteSize = size2;
500
+ const needMoveCamera = !isEqual(pick(this.rect, ["width", "height"]), pick(size2, ["width", "height"]));
501
+ if (this.rect && this.remoteCamera && needMoveCamera) {
502
+ if (!this.view)
503
+ return;
504
+ const currentCamera = this.view.camera;
505
+ (_a = this.view) == null ? void 0 : _a.moveCameraToContain({
506
+ width: size2.width,
507
+ height: size2.height,
508
+ originX: currentCamera.centerX - size2.width / 2,
509
+ originY: currentCamera.centerY - size2.height / 2
510
+ });
511
+ }
512
+ }
513
+ onLocalCameraUpdate(camera) {
514
+ this.saveCamera(camera);
515
+ this.remoteCamera = camera;
516
+ }
517
+ moveCamera(camera) {
518
+ var _a;
519
+ (_a = this.view) == null ? void 0 : _a.moveCamera(__spreadProps(__spreadValues({}, camera), { animationMode: AnimationMode.Immediately }));
520
+ }
521
+ }
522
+ const computedMinScale = (remoteSize, currentSize) => {
523
+ const wScale = currentSize.width / remoteSize.width;
524
+ const hScale = currentSize.height / remoteSize.height;
525
+ return Math.min(wScale, hScale);
526
+ };
465
527
  class AppListeners {
466
528
  constructor(manager) {
467
529
  this.manager = manager;
@@ -510,6 +572,14 @@ class AppListeners {
510
572
  this.manager.attributesUpdateCallback(this.manager.attributes.apps);
511
573
  break;
512
574
  }
575
+ case Events.MoveCamera: {
576
+ this.moveCameraHandler(data.payload);
577
+ break;
578
+ }
579
+ case Events.MoveCameraToContain: {
580
+ this.moveCameraToContainHandler(data.payload);
581
+ break;
582
+ }
513
583
  }
514
584
  }
515
585
  };
@@ -553,6 +623,21 @@ class AppListeners {
553
623
  }
554
624
  }
555
625
  };
626
+ this.moveCameraHandler = (payload) => {
627
+ var _a;
628
+ const cameraPayload = payload;
629
+ if (payload.scale) {
630
+ const remoteSize = this.manager.mainViewProxy.size$.value;
631
+ const currentSize = (_a = this.manager.boxManager) == null ? void 0 : _a.stageRect;
632
+ if (remoteSize && currentSize) {
633
+ cameraPayload.scale = payload.scale * computedMinScale(remoteSize, currentSize);
634
+ }
635
+ }
636
+ this.manager.mainView.moveCamera(cameraPayload);
637
+ };
638
+ this.moveCameraToContainHandler = (payload) => {
639
+ this.manager.mainView.moveCameraToContain(payload);
640
+ };
556
641
  }
557
642
  get boxManager() {
558
643
  return this.manager.boxManager;
@@ -1258,61 +1343,6 @@ class AppPageStateImpl {
1258
1343
  (_a = this.sceneNode) == null ? void 0 : _a.dispose();
1259
1344
  }
1260
1345
  }
1261
- class CameraSynchronizer {
1262
- constructor(saveCamera) {
1263
- this.saveCamera = saveCamera;
1264
- this.setRect = (rect) => {
1265
- this.rect = rect;
1266
- if (this.remoteCamera && this.remoteSize) {
1267
- this.onRemoteUpdate(this.remoteCamera, this.remoteSize);
1268
- }
1269
- };
1270
- this.onRemoteUpdate = throttle((camera, size2) => {
1271
- this.remoteCamera = camera;
1272
- this.remoteSize = size2;
1273
- if (this.remoteSize && this.rect) {
1274
- const nextScale = camera.scale * computedMinScale(size2, this.rect);
1275
- const config = {
1276
- scale: nextScale
1277
- };
1278
- if (camera.centerX !== null) {
1279
- config.centerX = camera.centerX;
1280
- }
1281
- if (camera.centerY !== null) {
1282
- config.centerY = camera.centerY;
1283
- }
1284
- this.moveCamera(config);
1285
- }
1286
- }, 10);
1287
- }
1288
- setView(view) {
1289
- this.view = view;
1290
- }
1291
- onRemoteSizeUpdate(size2) {
1292
- this.remoteSize = size2;
1293
- const needMoveCamera = !isEqual(pick(this.rect, ["width", "height"]), pick(size2, ["width", "height"]));
1294
- if (this.rect && this.remoteCamera && needMoveCamera) {
1295
- const scale2 = this.rect.width / size2.width;
1296
- const nextScale = this.remoteCamera.scale * scale2;
1297
- this.moveCamera({
1298
- scale: nextScale
1299
- });
1300
- }
1301
- }
1302
- onLocalCameraUpdate(camera) {
1303
- this.saveCamera(camera);
1304
- this.remoteCamera = camera;
1305
- }
1306
- moveCamera(camera) {
1307
- var _a;
1308
- (_a = this.view) == null ? void 0 : _a.moveCamera(__spreadProps(__spreadValues({}, camera), { animationMode: AnimationMode.Immediately }));
1309
- }
1310
- }
1311
- const computedMinScale = (remoteSize, currentSize) => {
1312
- const wScale = currentSize.width / remoteSize.width;
1313
- const hScale = currentSize.height / remoteSize.height;
1314
- return Math.min(wScale, hScale);
1315
- };
1316
1346
  class ViewSync {
1317
1347
  constructor(context) {
1318
1348
  this.context = context;
@@ -2322,6 +2352,16 @@ class MainViewProxy {
2322
2352
  }
2323
2353
  }
2324
2354
  }));
2355
+ this.camera$.reaction((camera) => {
2356
+ if (camera) {
2357
+ callbacks.emit("baseCameraChange", camera);
2358
+ }
2359
+ });
2360
+ this.size$.reaction((size2) => {
2361
+ if (size2) {
2362
+ callbacks.emit("baseSizeChange", size2);
2363
+ }
2364
+ });
2325
2365
  }
2326
2366
  ensureCameraAndSize() {
2327
2367
  var _a;
@@ -2953,7 +2993,7 @@ class AppManager {
2953
2993
  if (appIds.length === 0) {
2954
2994
  this.appCreateQueue.emitReady();
2955
2995
  }
2956
- const appsWithCreatedAt = appIds.map((appId) => {
2996
+ let appsWithCreatedAt = appIds.map((appId) => {
2957
2997
  if (apps[appId].setup) {
2958
2998
  return {
2959
2999
  id: appId,
@@ -2963,6 +3003,14 @@ class AppManager {
2963
3003
  return {};
2964
3004
  }
2965
3005
  });
3006
+ if (this.isReplay) {
3007
+ appsWithCreatedAt = appIds.map((appId) => {
3008
+ return {
3009
+ id: appId,
3010
+ createdAt: apps[appId].createdAt
3011
+ };
3012
+ });
3013
+ }
2966
3014
  for (const { id } of orderBy(appsWithCreatedAt, "createdAt", "asc")) {
2967
3015
  if (id && !this.appProxies.has(id) && !this.appStatus.has(id)) {
2968
3016
  const app = apps[id];
@@ -5840,6 +5888,15 @@ class BoxManager {
5840
5888
  if (createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.fullscreen) {
5841
5889
  initManagerState.fullscreen = createTeleBoxManagerConfig.fullscreen;
5842
5890
  }
5891
+ if ((createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.defaultBoxBodyStyle) !== void 0) {
5892
+ initManagerState.defaultBoxBodyStyle = createTeleBoxManagerConfig.defaultBoxBodyStyle;
5893
+ }
5894
+ if ((createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.defaultBoxStageStyle) !== void 0) {
5895
+ initManagerState.defaultBoxStageStyle = createTeleBoxManagerConfig.defaultBoxStageStyle;
5896
+ }
5897
+ if (createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.theme) {
5898
+ initManagerState.theme = createTeleBoxManagerConfig.theme;
5899
+ }
5843
5900
  const manager = new TeleBoxManager(initManagerState);
5844
5901
  if (this.teleBoxManager) {
5845
5902
  this.teleBoxManager.destroy();
@@ -12848,7 +12905,7 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
12848
12905
  const _WindowManager = class extends InvisiblePlugin {
12849
12906
  constructor(context) {
12850
12907
  super(context);
12851
- this.version = "1.0.0-canary.35";
12908
+ this.version = "1.0.0-canary.38";
12852
12909
  this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.33", "emittery": "^0.11.0", "lodash": "^4.17.21", "p-retry": "^4.6.2", "side-effect-manager": "^1.1.1", "uuid": "^7.0.3", "value-enhancer": "^1.3.2" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.3.0", "@netless/app-plyr": "0.2.0", "@playwright/test": "^1.23.2", "@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.49", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.6", "@types/node": "^18.0.3", "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.2", "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.3", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vite-plugin-dts": "^1.2.1", "vitest": "^0.18.0", "white-web-sdk": "2.16.26" } };
12853
12910
  this.emitter = callbacks;
12854
12911
  this.viewMode = ViewMode.Broadcaster;
@@ -13368,30 +13425,39 @@ const _WindowManager = class extends InvisiblePlugin {
13368
13425
  return (_a = this.appManager) == null ? void 0 : _a.closeApp(appId);
13369
13426
  }
13370
13427
  moveCamera(camera) {
13428
+ var _a;
13371
13429
  const mainViewCamera = __spreadValues({}, this.mainView.camera);
13372
13430
  const nextCamera = __spreadValues(__spreadValues({}, mainViewCamera), camera);
13373
13431
  if (isEqual(nextCamera, mainViewCamera))
13374
13432
  return;
13375
13433
  if (!this.appManager)
13376
13434
  return;
13377
- this.appManager.mainViewProxy.storeCamera(__spreadValues({
13378
- id: this.appManager.uid
13379
- }, nextCamera));
13380
- }
13381
- moveCameraToContain(rectangle) {
13382
- if (!this.appManager)
13383
- return;
13384
- const mainViewSize = this.appManager.mainViewProxy.size$.value;
13385
- if (mainViewSize) {
13386
- const wScale = mainViewSize.width / rectangle.width;
13387
- const hScale = mainViewSize.height / rectangle.height;
13388
- const nextScale = Math.min(wScale, hScale);
13389
- this.appManager.mainViewProxy.storeCamera({
13390
- id: this.appManager.uid,
13391
- scale: nextScale,
13392
- centerX: rectangle.originX,
13393
- centerY: rectangle.originY
13394
- });
13435
+ if (camera.animationMode === AnimationMode.Immediately) {
13436
+ this.appManager.mainViewProxy.storeCamera(__spreadValues({
13437
+ id: this.appManager.uid
13438
+ }, nextCamera));
13439
+ } else {
13440
+ const remoteCamera = this.appManager.mainViewProxy.size$.value;
13441
+ const currentSize = (_a = this.boxManager) == null ? void 0 : _a.stageRect;
13442
+ let nextScale;
13443
+ if (camera.scale && remoteCamera && currentSize) {
13444
+ nextScale = camera.scale * computedMinScale(remoteCamera, currentSize);
13445
+ }
13446
+ if (nextScale) {
13447
+ this.mainView.moveCamera(__spreadProps(__spreadValues({}, camera), {
13448
+ scale: nextScale
13449
+ }));
13450
+ } else {
13451
+ this.mainView.moveCamera(camera);
13452
+ }
13453
+ this.appManager.dispatchInternalEvent(Events.MoveCamera, camera);
13454
+ setTimeout(() => {
13455
+ if (!this.appManager)
13456
+ return;
13457
+ this.appManager.mainViewProxy.storeCamera(__spreadValues({
13458
+ id: this.appManager.uid
13459
+ }, nextCamera));
13460
+ }, 200);
13395
13461
  }
13396
13462
  }
13397
13463
  convertToPointInWorld(point) {