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

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.d.ts CHANGED
@@ -5,9 +5,10 @@ import { ReconnectRefresher } from "./ReconnectRefresher";
5
5
  import "video.js/dist/video-js.css";
6
6
  import "./style.css";
7
7
  import "@netless/telebox-insider/dist/style.css";
8
+ import { Val } from "value-enhancer";
8
9
  import type { TELE_BOX_STATE } from "./BoxManager";
9
10
  import type { Apps, Position, ICamera, ISize } from "./AttributesDelegate";
10
- import type { Displayer, SceneDefinition, View, Room, InvisiblePluginContext, Camera, AnimationMode, CameraBound, Point, Rectangle, CameraState, Player, ImageInformation, SceneState } from "white-web-sdk";
11
+ import type { Displayer, SceneDefinition, View, Room, InvisiblePluginContext, Camera, CameraBound, Point, CameraState, Player, ImageInformation, SceneState, Rectangle } from "white-web-sdk";
11
12
  import type { AppListeners } from "./AppListener";
12
13
  import type { ApplianceIcons, NetlessApp, RegisterParams } from "./typings";
13
14
  import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
@@ -15,7 +16,6 @@ import type { AppProxy } from "./App";
15
16
  import type { PublicEvent } from "./callback";
16
17
  import type Emittery from "emittery";
17
18
  import type { PageController, AddPageParams, PageState } from "./Page";
18
- import { Val } from "value-enhancer";
19
19
  export declare type WindowMangerAttributes = {
20
20
  modelValue?: string;
21
21
  boxState: TELE_BOX_STATE;
@@ -190,6 +190,13 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
190
190
  setMinimized(minimized: boolean): void;
191
191
  get mainView(): View;
192
192
  get camera(): Camera;
193
+ get baseCamera$(): Val<{
194
+ id: string;
195
+ centerX: number | null;
196
+ centerY: number | null;
197
+ scale: number;
198
+ } | undefined, any>;
199
+ get baseSize$(): Val<ISize | undefined, any>;
193
200
  get cameraState(): CameraState;
194
201
  get apps(): Apps | undefined;
195
202
  get boxState(): TeleBoxState | undefined;
@@ -217,12 +224,8 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
217
224
  * 关闭 APP
218
225
  */
219
226
  closeApp(appId: string): Promise<void>;
220
- moveCamera(camera: Partial<Camera> & {
221
- animationMode?: AnimationMode | undefined;
222
- }): void;
223
- moveCameraToContain(rectangle: Rectangle & Readonly<{
224
- animationMode?: AnimationMode;
225
- }>): void;
227
+ moveCamera(camera: Partial<Camera>): void;
228
+ moveCameraToContain(rectangle: Rectangle): void;
226
229
  convertToPointInWorld(point: Point): Point;
227
230
  setCameraBound(cameraBound: CameraBound): void;
228
231
  onDestroy(): void;
package/dist/index.es.js CHANGED
@@ -19,7 +19,7 @@ var __spreadValues = (a2, b2) => {
19
19
  var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2));
20
20
  import pRetry from "p-retry";
21
21
  import Emittery from "emittery";
22
- import { debounce, isEqual, omit, isObject, has, get, size as size$1, mapValues, noop as noop$1, pick, isBoolean, isNumber, throttle, omitBy, isUndefined, isInteger, orderBy, isEmpty, isFunction, isNull } from "lodash";
22
+ import { debounce, isObject, has, get, size as size$1, mapValues, noop as noop$1, pick, isBoolean, isNumber, throttle, isEqual, omitBy, isUndefined, isInteger, orderBy, isEmpty, omit, isFunction, isNull } from "lodash";
23
23
  import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, WhiteVersion, autorun, toJS, listenDisposed, unlistenDisposed, AnimationMode, ViewMode, isPlayer, isRoom, ApplianceNames, RoomPhase, InvisiblePlugin } from "white-web-sdk";
24
24
  import { v4 } from "uuid";
25
25
  import { genUID, SideEffectManager } from "side-effect-manager";
@@ -38,8 +38,6 @@ var Events = /* @__PURE__ */ ((Events2) => {
38
38
  Events2["SetMainViewSceneIndex"] = "SetMainViewSceneIndex";
39
39
  Events2["SetAppFocusIndex"] = "SetAppFocusIndex";
40
40
  Events2["SwitchViewsToFreedom"] = "SwitchViewsToFreedom";
41
- Events2["MoveCamera"] = "MoveCamera";
42
- Events2["MoveCameraToContain"] = "MoveCameraToContain";
43
41
  Events2["CursorMove"] = "CursorMove";
44
42
  Events2["RootDirRemoved"] = "RootDirRemoved";
45
43
  Events2["Refresh"] = "Refresh";
@@ -473,14 +471,6 @@ class AppListeners {
473
471
  this.setMainViewScenePathHandler(data.payload);
474
472
  break;
475
473
  }
476
- case Events.MoveCamera: {
477
- this.moveCameraHandler(data.payload);
478
- break;
479
- }
480
- case Events.MoveCameraToContain: {
481
- this.moveCameraToContainHandler(data.payload);
482
- break;
483
- }
484
474
  case Events.CursorMove: {
485
475
  this.cursorMoveHandler(data.payload);
486
476
  break;
@@ -520,14 +510,6 @@ class AppListeners {
520
510
  setViewFocusScenePath(this.manager.mainView, nextScenePath);
521
511
  callbacks$1.emit("mainViewScenePathChange", nextScenePath);
522
512
  };
523
- this.moveCameraHandler = (payload) => {
524
- if (isEqual(omit(payload, ["animationMode"]), __spreadValues({}, this.manager.mainView.camera)))
525
- return;
526
- this.manager.mainView.moveCamera(payload);
527
- };
528
- this.moveCameraToContainHandler = (payload) => {
529
- this.manager.mainView.moveCameraToContain(payload);
530
- };
531
513
  this.cursorMoveHandler = (payload) => {
532
514
  emitter.emit("cursorMove", payload);
533
515
  };
@@ -953,11 +935,11 @@ class WhiteBoardView {
953
935
  this.appProxy.sideEffectManager.add(() => appProxy.appEmitter.on("pageStateChange", (pageState) => {
954
936
  pageState$.setValue(pageState);
955
937
  }));
956
- const camera$ = new Val(pick(this.view.camera, ["centerX", "centerY"]));
957
- this.camera$ = camera$;
938
+ const camera$ = new Val(pick(this.view.camera, ["centerX", "centerY", "scale"]));
939
+ this.baseCamera$ = camera$;
958
940
  this.appProxy.sideEffectManager.add(() => appProxy.camera$.subscribe((camera) => {
959
941
  if (camera) {
960
- camera$.setValue(pick(camera, ["centerX", "centerY"]));
942
+ camera$.setValue(pick(camera, ["centerX", "centerY", "scale"]));
961
943
  }
962
944
  }));
963
945
  view.disableCameraTransform = true;
@@ -968,7 +950,7 @@ class WhiteBoardView {
968
950
  moveCamera(camera) {
969
951
  this.appProxy.moveCamera(camera);
970
952
  }
971
- setRect(rect) {
953
+ setBaseRect(rect) {
972
954
  this.appProxy.updateSize(rect.width, rect.height);
973
955
  }
974
956
  }
@@ -1265,7 +1247,7 @@ class CameraSynchronizer {
1265
1247
  const nextScale = camera.scale * scale2;
1266
1248
  const config = {
1267
1249
  scale: nextScale,
1268
- animationMode: AnimationMode.Immediately
1250
+ animationMode: AnimationMode.Continuous
1269
1251
  };
1270
1252
  if (camera.centerX !== null) {
1271
1253
  config.centerX = camera.centerX;
@@ -1289,7 +1271,7 @@ class CameraSynchronizer {
1289
1271
  const nextScale = this.remoteCamera.scale * scale2;
1290
1272
  (_a = this.view) == null ? void 0 : _a.moveCamera({
1291
1273
  scale: nextScale,
1292
- animationMode: AnimationMode.Immediately
1274
+ animationMode: AnimationMode.Continuous
1293
1275
  });
1294
1276
  }
1295
1277
  }
@@ -1933,6 +1915,10 @@ class AppProxy {
1933
1915
  this.box$.setValue(box);
1934
1916
  if (this.isAddApp && this.box) {
1935
1917
  this.store.updateAppState(appId, AppAttributes.ZIndex, this.box.zIndex);
1918
+ this.store.updateAppState(appId, AppAttributes.Size, {
1919
+ width: this.box.intrinsicWidth,
1920
+ height: this.box.intrinsicHeight
1921
+ });
1936
1922
  this.boxManager.focusBox({ appId }, false);
1937
1923
  }
1938
1924
  } catch (error) {
@@ -2357,12 +2343,14 @@ class MainViewProxy {
2357
2343
  rebind() {
2358
2344
  const divElement = this.mainView.divElement;
2359
2345
  const disableCameraTransform = this.mainView.disableCameraTransform;
2346
+ const camera = __spreadValues({}, this.mainView.camera);
2360
2347
  this.stop();
2361
2348
  releaseView(this.mainView);
2362
2349
  this.removeMainViewListener();
2363
2350
  this.mainView = this.createMainView();
2364
2351
  this.mainView.disableCameraTransform = disableCameraTransform;
2365
2352
  this.mainView.divElement = divElement;
2353
+ this.mainView.moveCamera(__spreadProps(__spreadValues({}, camera), { animationMode: AnimationMode.Immediately }));
2366
2354
  this.addMainViewListener();
2367
2355
  this.start();
2368
2356
  }
@@ -2634,8 +2622,7 @@ class AppManager {
2634
2622
  this.dispatchInternalEvent(Events.AppBoxStateChange, payload);
2635
2623
  };
2636
2624
  this.addAppsChangeListener = () => {
2637
- var _a;
2638
- (_a = this.refresher) == null ? void 0 : _a.add("apps", () => {
2625
+ this.refresher.add("apps", () => {
2639
2626
  return safeListenPropsUpdated(() => this.attributes.apps, () => {
2640
2627
  this.attributesUpdateCallback(this.attributes.apps);
2641
2628
  });
@@ -3128,6 +3115,7 @@ class AppManager {
3128
3115
  }
3129
3116
  }
3130
3117
  async onReconnected() {
3118
+ this.attributesUpdateCallback(this.attributes.apps);
3131
3119
  const appProxies = Array.from(this.appProxies.values());
3132
3120
  const reconnected = appProxies.map((appProxy) => {
3133
3121
  return appProxy.onReconnected();
@@ -15673,7 +15661,7 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
15673
15661
  const _WindowManager = class extends InvisiblePlugin {
15674
15662
  constructor(context) {
15675
15663
  super(context);
15676
- this.version = "1.0.0-canary.25";
15664
+ this.version = "1.0.0-canary.26";
15677
15665
  this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.18", "emittery": "^0.11.0", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^1.1.0", "uuid": "^7.0.3", "value-enhancer": "^1.3.0", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
15678
15666
  this.emitter = callbacks$1;
15679
15667
  this.viewMode = ViewMode.Broadcaster;
@@ -16076,6 +16064,20 @@ const _WindowManager = class extends InvisiblePlugin {
16076
16064
  throw new AppManagerNotInitError();
16077
16065
  }
16078
16066
  }
16067
+ get baseCamera$() {
16068
+ if (this.appManager) {
16069
+ return this.appManager.mainViewProxy.camera$;
16070
+ } else {
16071
+ throw new AppManagerNotInitError();
16072
+ }
16073
+ }
16074
+ get baseSize$() {
16075
+ if (this.appManager) {
16076
+ return this.appManager.mainViewProxy.size$;
16077
+ } else {
16078
+ throw new AppManagerNotInitError();
16079
+ }
16080
+ }
16079
16081
  get cameraState() {
16080
16082
  if (this.appManager) {
16081
16083
  return this.appManager.mainViewProxy.cameraState;
@@ -16169,26 +16171,31 @@ const _WindowManager = class extends InvisiblePlugin {
16169
16171
  return (_a = this.appManager) == null ? void 0 : _a.closeApp(appId);
16170
16172
  }
16171
16173
  moveCamera(camera) {
16172
- var _a;
16173
- const pureCamera = omit(camera, ["animationMode"]);
16174
16174
  const mainViewCamera = __spreadValues({}, this.mainView.camera);
16175
- if (isEqual(__spreadValues(__spreadValues({}, mainViewCamera), pureCamera), mainViewCamera))
16175
+ const nextCamera = __spreadValues(__spreadValues({}, mainViewCamera), camera);
16176
+ if (isEqual(nextCamera, mainViewCamera))
16176
16177
  return;
16177
- this.mainView.moveCamera(camera);
16178
- (_a = this.appManager) == null ? void 0 : _a.dispatchInternalEvent(Events.MoveCamera, camera);
16179
- setTimeout(() => {
16180
- var _a2;
16181
- (_a2 = this.appManager) == null ? void 0 : _a2.mainViewProxy.storeCurrentCamera();
16182
- }, 500);
16178
+ if (!this.appManager)
16179
+ return;
16180
+ this.appManager.mainViewProxy.storeCamera(__spreadValues({
16181
+ id: this.appManager.uid
16182
+ }, nextCamera));
16183
16183
  }
16184
16184
  moveCameraToContain(rectangle) {
16185
- var _a;
16186
- this.mainView.moveCameraToContain(rectangle);
16187
- (_a = this.appManager) == null ? void 0 : _a.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
16188
- setTimeout(() => {
16189
- var _a2;
16190
- (_a2 = this.appManager) == null ? void 0 : _a2.mainViewProxy.storeCurrentCamera();
16191
- }, 500);
16185
+ if (!this.appManager)
16186
+ return;
16187
+ const mainViewSize = this.appManager.mainViewProxy.size$.value;
16188
+ if (mainViewSize) {
16189
+ const wScale = mainViewSize.width / rectangle.width;
16190
+ const hScale = mainViewSize.height / rectangle.height;
16191
+ const nextScale = Math.min(wScale, hScale);
16192
+ this.appManager.mainViewProxy.storeCamera({
16193
+ id: this.appManager.uid,
16194
+ scale: nextScale,
16195
+ centerX: rectangle.originX,
16196
+ centerY: rectangle.originY
16197
+ });
16198
+ }
16192
16199
  }
16193
16200
  convertToPointInWorld(point) {
16194
16201
  return this.mainView.convertToPointInWorld(point);