@netless/window-manager 1.0.0-canary.35 → 1.0.0-canary.36
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.cjs.js +8 -8
- package/dist/index.es.js +168 -70
- package/dist/index.umd.js +8 -8
- package/dist/src/AppListener.d.ts +2 -0
- package/dist/src/BoxManager.d.ts +4 -1
- package/dist/src/callback.d.ts +3 -0
- package/dist/src/constants.d.ts +3 -1
- package/dist/src/index.d.ts +15 -5
- package/package.json +1 -1
- package/src/AppListener.ts +26 -1
- package/src/BoxManager.ts +16 -1
- package/src/View/MainView.ts +10 -0
- package/src/callback.ts +4 -1
- package/src/constants.ts +2 -0
- package/src/index.ts +84 -19
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,
|
35
|
-
import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, toJS, WhiteVersion, autorun, listenDisposed, unlistenDisposed,
|
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,61 @@ 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
|
+
this.remoteSize = size2;
|
499
|
+
const needMoveCamera = !isEqual(pick(this.rect, ["width", "height"]), pick(size2, ["width", "height"]));
|
500
|
+
if (this.rect && this.remoteCamera && needMoveCamera) {
|
501
|
+
const scale2 = this.rect.width / size2.width;
|
502
|
+
const nextScale = this.remoteCamera.scale * scale2;
|
503
|
+
this.moveCamera({
|
504
|
+
scale: nextScale
|
505
|
+
});
|
506
|
+
}
|
507
|
+
}
|
508
|
+
onLocalCameraUpdate(camera) {
|
509
|
+
this.saveCamera(camera);
|
510
|
+
this.remoteCamera = camera;
|
511
|
+
}
|
512
|
+
moveCamera(camera) {
|
513
|
+
var _a;
|
514
|
+
(_a = this.view) == null ? void 0 : _a.moveCamera(__spreadProps(__spreadValues({}, camera), { animationMode: AnimationMode.Immediately }));
|
515
|
+
}
|
516
|
+
}
|
517
|
+
const computedMinScale = (remoteSize, currentSize) => {
|
518
|
+
const wScale = currentSize.width / remoteSize.width;
|
519
|
+
const hScale = currentSize.height / remoteSize.height;
|
520
|
+
return Math.min(wScale, hScale);
|
521
|
+
};
|
465
522
|
class AppListeners {
|
466
523
|
constructor(manager) {
|
467
524
|
this.manager = manager;
|
@@ -510,6 +567,14 @@ class AppListeners {
|
|
510
567
|
this.manager.attributesUpdateCallback(this.manager.attributes.apps);
|
511
568
|
break;
|
512
569
|
}
|
570
|
+
case Events.MoveCamera: {
|
571
|
+
this.moveCameraHandler(data.payload);
|
572
|
+
break;
|
573
|
+
}
|
574
|
+
case Events.MoveCameraToContain: {
|
575
|
+
this.moveCameraToContainHandler(data.payload);
|
576
|
+
break;
|
577
|
+
}
|
513
578
|
}
|
514
579
|
}
|
515
580
|
};
|
@@ -553,6 +618,21 @@ class AppListeners {
|
|
553
618
|
}
|
554
619
|
}
|
555
620
|
};
|
621
|
+
this.moveCameraHandler = (payload) => {
|
622
|
+
var _a;
|
623
|
+
const cameraPayload = payload;
|
624
|
+
if (payload.scale) {
|
625
|
+
const remoteSize = this.manager.mainViewProxy.size$.value;
|
626
|
+
const currentSize = (_a = this.manager.boxManager) == null ? void 0 : _a.stageRect;
|
627
|
+
if (remoteSize && currentSize) {
|
628
|
+
cameraPayload.scale = payload.scale * computedMinScale(remoteSize, currentSize);
|
629
|
+
}
|
630
|
+
}
|
631
|
+
this.manager.mainView.moveCamera(cameraPayload);
|
632
|
+
};
|
633
|
+
this.moveCameraToContainHandler = (payload) => {
|
634
|
+
this.manager.mainView.moveCameraToContain(payload);
|
635
|
+
};
|
556
636
|
}
|
557
637
|
get boxManager() {
|
558
638
|
return this.manager.boxManager;
|
@@ -1258,61 +1338,6 @@ class AppPageStateImpl {
|
|
1258
1338
|
(_a = this.sceneNode) == null ? void 0 : _a.dispose();
|
1259
1339
|
}
|
1260
1340
|
}
|
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
1341
|
class ViewSync {
|
1317
1342
|
constructor(context) {
|
1318
1343
|
this.context = context;
|
@@ -2322,6 +2347,16 @@ class MainViewProxy {
|
|
2322
2347
|
}
|
2323
2348
|
}
|
2324
2349
|
}));
|
2350
|
+
this.camera$.reaction((camera) => {
|
2351
|
+
if (camera) {
|
2352
|
+
callbacks.emit("baseCameraChange", camera);
|
2353
|
+
}
|
2354
|
+
});
|
2355
|
+
this.size$.reaction((size2) => {
|
2356
|
+
if (size2) {
|
2357
|
+
callbacks.emit("baseSizeChange", size2);
|
2358
|
+
}
|
2359
|
+
});
|
2325
2360
|
}
|
2326
2361
|
ensureCameraAndSize() {
|
2327
2362
|
var _a;
|
@@ -5840,6 +5875,15 @@ class BoxManager {
|
|
5840
5875
|
if (createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.fullscreen) {
|
5841
5876
|
initManagerState.fullscreen = createTeleBoxManagerConfig.fullscreen;
|
5842
5877
|
}
|
5878
|
+
if ((createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.defaultBoxBodyStyle) !== void 0) {
|
5879
|
+
initManagerState.defaultBoxBodyStyle = createTeleBoxManagerConfig.defaultBoxBodyStyle;
|
5880
|
+
}
|
5881
|
+
if ((createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.defaultBoxStageStyle) !== void 0) {
|
5882
|
+
initManagerState.defaultBoxStageStyle = createTeleBoxManagerConfig.defaultBoxStageStyle;
|
5883
|
+
}
|
5884
|
+
if (createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.theme) {
|
5885
|
+
initManagerState.theme = createTeleBoxManagerConfig.theme;
|
5886
|
+
}
|
5843
5887
|
const manager = new TeleBoxManager(initManagerState);
|
5844
5888
|
if (this.teleBoxManager) {
|
5845
5889
|
this.teleBoxManager.destroy();
|
@@ -12848,7 +12892,7 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
|
|
12848
12892
|
const _WindowManager = class extends InvisiblePlugin {
|
12849
12893
|
constructor(context) {
|
12850
12894
|
super(context);
|
12851
|
-
this.version = "1.0.0-canary.
|
12895
|
+
this.version = "1.0.0-canary.36";
|
12852
12896
|
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
12897
|
this.emitter = callbacks;
|
12854
12898
|
this.viewMode = ViewMode.Broadcaster;
|
@@ -13368,30 +13412,84 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
13368
13412
|
return (_a = this.appManager) == null ? void 0 : _a.closeApp(appId);
|
13369
13413
|
}
|
13370
13414
|
moveCamera(camera) {
|
13415
|
+
var _a;
|
13371
13416
|
const mainViewCamera = __spreadValues({}, this.mainView.camera);
|
13372
13417
|
const nextCamera = __spreadValues(__spreadValues({}, mainViewCamera), camera);
|
13373
13418
|
if (isEqual(nextCamera, mainViewCamera))
|
13374
13419
|
return;
|
13375
13420
|
if (!this.appManager)
|
13376
13421
|
return;
|
13377
|
-
|
13378
|
-
|
13379
|
-
|
13422
|
+
if (camera.animationMode === AnimationMode.Immediately) {
|
13423
|
+
this.appManager.mainViewProxy.storeCamera(__spreadValues({
|
13424
|
+
id: this.appManager.uid
|
13425
|
+
}, nextCamera));
|
13426
|
+
} else {
|
13427
|
+
const remoteCamera = this.appManager.mainViewProxy.size$.value;
|
13428
|
+
const currentSize = (_a = this.boxManager) == null ? void 0 : _a.stageRect;
|
13429
|
+
let nextScale;
|
13430
|
+
if (camera.scale && remoteCamera && currentSize) {
|
13431
|
+
nextScale = camera.scale * computedMinScale(remoteCamera, currentSize);
|
13432
|
+
}
|
13433
|
+
if (nextScale) {
|
13434
|
+
this.mainView.moveCamera(__spreadProps(__spreadValues({}, camera), {
|
13435
|
+
scale: nextScale
|
13436
|
+
}));
|
13437
|
+
} else {
|
13438
|
+
this.mainView.moveCamera(camera);
|
13439
|
+
}
|
13440
|
+
this.appManager.dispatchInternalEvent(Events.MoveCamera, camera);
|
13441
|
+
setTimeout(() => {
|
13442
|
+
if (!this.appManager)
|
13443
|
+
return;
|
13444
|
+
this.appManager.mainViewProxy.storeCamera(__spreadValues({
|
13445
|
+
id: this.appManager.uid
|
13446
|
+
}, nextCamera));
|
13447
|
+
}, 200);
|
13448
|
+
}
|
13380
13449
|
}
|
13381
13450
|
moveCameraToContain(rectangle) {
|
13382
13451
|
if (!this.appManager)
|
13383
13452
|
return;
|
13384
|
-
const
|
13385
|
-
if (
|
13386
|
-
|
13387
|
-
|
13388
|
-
|
13389
|
-
|
13453
|
+
const camera = {};
|
13454
|
+
if (isNumber$2(rectangle.originX)) {
|
13455
|
+
camera.centerX = rectangle.originX;
|
13456
|
+
}
|
13457
|
+
if (isNumber$2(rectangle.originY)) {
|
13458
|
+
camera.centerY = rectangle.originY;
|
13459
|
+
}
|
13460
|
+
if (rectangle.animationMode === AnimationMode.Immediately) {
|
13461
|
+
this.appManager.mainViewProxy.storeSize({
|
13390
13462
|
id: this.appManager.uid,
|
13391
|
-
|
13392
|
-
|
13393
|
-
centerY: rectangle.originY
|
13463
|
+
width: rectangle.width,
|
13464
|
+
height: rectangle.height
|
13394
13465
|
});
|
13466
|
+
this.mainView.moveCameraToContain(rectangle);
|
13467
|
+
if (!isEmpty$2(camera) && this.appManager.mainViewProxy.camera$.value) {
|
13468
|
+
this.appManager.mainViewProxy.storeCamera(__spreadProps(__spreadValues({}, this.appManager.mainViewProxy.camera$.value), {
|
13469
|
+
id: this.appManager.uid,
|
13470
|
+
centerX: this.mainView.camera.centerX,
|
13471
|
+
centerY: this.mainView.camera.centerY
|
13472
|
+
}));
|
13473
|
+
}
|
13474
|
+
} else {
|
13475
|
+
this.appManager.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
|
13476
|
+
this.mainView.moveCameraToContain(rectangle);
|
13477
|
+
setTimeout(() => {
|
13478
|
+
if (!this.appManager)
|
13479
|
+
return;
|
13480
|
+
this.appManager.mainViewProxy.storeSize({
|
13481
|
+
id: this.appManager.uid,
|
13482
|
+
width: rectangle.width,
|
13483
|
+
height: rectangle.height
|
13484
|
+
});
|
13485
|
+
if (!isEmpty$2(camera) && this.appManager.mainViewProxy.camera$.value) {
|
13486
|
+
this.appManager.mainViewProxy.storeCamera(__spreadProps(__spreadValues({}, this.appManager.mainViewProxy.camera$.value), {
|
13487
|
+
id: this.appManager.uid,
|
13488
|
+
centerX: this.mainView.camera.centerX,
|
13489
|
+
centerY: this.mainView.camera.centerY
|
13490
|
+
}));
|
13491
|
+
}
|
13492
|
+
}, 200);
|
13395
13493
|
}
|
13396
13494
|
}
|
13397
13495
|
convertToPointInWorld(point) {
|