@netless/window-manager 0.4.0-canary.4 → 0.4.0-canary.8

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 (56) hide show
  1. package/dist/App/Storage/StorageEvent.d.ts +8 -0
  2. package/dist/App/Storage/index.d.ts +26 -0
  3. package/dist/App/Storage/typings.d.ts +21 -0
  4. package/dist/App/Storage/utils.d.ts +5 -0
  5. package/dist/AppContext.d.ts +2 -0
  6. package/dist/AppListener.d.ts +0 -1
  7. package/dist/AppManager.d.ts +4 -5
  8. package/dist/AppProxy.d.ts +2 -3
  9. package/dist/Base/Context.d.ts +0 -1
  10. package/dist/BoxManager.d.ts +2 -1
  11. package/dist/BuiltinApps.d.ts +6 -0
  12. package/dist/ContainerResizeObserver.d.ts +10 -0
  13. package/dist/Helper.d.ts +6 -0
  14. package/dist/Utils/Common.d.ts +3 -1
  15. package/dist/Utils/Reactive.d.ts +1 -1
  16. package/dist/{MainView.d.ts → View/MainView.d.ts} +2 -4
  17. package/dist/View/ViewManager.d.ts +13 -0
  18. package/dist/constants.d.ts +0 -5
  19. package/dist/index.d.ts +3 -9
  20. package/dist/index.es.js +1 -1
  21. package/dist/index.es.js.map +1 -1
  22. package/dist/index.umd.js +1 -1
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/style.css +1 -1
  25. package/dist/typings.d.ts +1 -0
  26. package/package.json +3 -3
  27. package/src/App/Storage/StorageEvent.ts +21 -0
  28. package/src/App/Storage/index.ts +243 -0
  29. package/src/App/Storage/typings.ts +21 -0
  30. package/src/App/Storage/utils.ts +17 -0
  31. package/src/AppContext.ts +9 -1
  32. package/src/AppListener.ts +0 -8
  33. package/src/AppManager.ts +32 -26
  34. package/src/AppProxy.ts +14 -36
  35. package/src/Base/Context.ts +0 -4
  36. package/src/BoxManager.ts +9 -7
  37. package/src/BuiltinApps.ts +24 -0
  38. package/src/ContainerResizeObserver.ts +62 -0
  39. package/src/Helper.ts +30 -0
  40. package/src/ReconnectRefresher.ts +0 -1
  41. package/src/Utils/Common.ts +35 -13
  42. package/src/Utils/Reactive.ts +9 -3
  43. package/src/{MainView.ts → View/MainView.ts} +7 -25
  44. package/src/View/ViewManager.ts +53 -0
  45. package/src/constants.ts +0 -2
  46. package/src/index.ts +17 -70
  47. package/src/shim.d.ts +4 -0
  48. package/src/style.css +6 -0
  49. package/src/typings.ts +1 -0
  50. package/vite.config.js +4 -1
  51. package/dist/Utils/CameraStore.d.ts +0 -15
  52. package/dist/ViewManager.d.ts +0 -29
  53. package/dist/sdk.d.ts +0 -14
  54. package/src/Utils/CameraStore.ts +0 -72
  55. package/src/sdk.ts +0 -39
  56. package/src/viewManager.ts +0 -177
package/src/AppProxy.ts CHANGED
@@ -2,16 +2,15 @@ import Emittery from "emittery";
2
2
  import { AppAttributes, AppEvents, Events } from "./constants";
3
3
  import { AppContext } from "./AppContext";
4
4
  import { appRegister } from "./Register";
5
- import { autorun, ViewVisionMode } from "white-web-sdk";
6
- import { callbacks, emitter } from "./index";
5
+ import { autorun } from "white-web-sdk";
6
+ import { emitter } from "./index";
7
7
  import { Fields } from "./AttributesDelegate";
8
8
  import { get } from "lodash";
9
9
  import { log } from "./Utils/log";
10
10
  import {
11
- notifyMainViewModeChange,
12
11
  setScenePath,
13
12
  setViewFocusScenePath,
14
- setViewMode,
13
+ getScenePath
15
14
  } from "./Utils/Common";
16
15
  import type {
17
16
  AppEmitterEvent,
@@ -37,7 +36,6 @@ export class AppProxy extends Base {
37
36
  private boxManager = this.manager.boxManager;
38
37
  private appProxies = this.manager.appProxies;
39
38
  private viewManager = this.manager.viewManager;
40
- private cameraStore = this.manager.cameraStore;
41
39
  private kind: string;
42
40
  public isAddApp: boolean;
43
41
  private status: "normal" | "destroyed" = "normal";
@@ -98,17 +96,25 @@ export class AppProxy extends Base {
98
96
 
99
97
  public getFullScenePath(): string | undefined {
100
98
  if (this.scenePath) {
101
- return get(this.appAttributes, [Fields.FullPath], this.scenePath);
99
+ return get(this.appAttributes, [Fields.FullPath], this.getFullScenePathFromScenes());
102
100
  }
103
101
  }
104
102
 
103
+ private getFullScenePathFromScenes() {
104
+ const sceneIndex = get(this.appAttributes, ["state", "SceneIndex"], 0);
105
+ const fullPath = getScenePath(this.manager.room, this.scenePath, sceneIndex);
106
+ if (fullPath) {
107
+ this.setFullPath(fullPath);
108
+ }
109
+ return fullPath;
110
+ }
111
+
105
112
  public setFullPath(path: string) {
106
113
  this.manager.safeUpdateAttributes(["apps", this.id, Fields.FullPath], path);
107
114
  }
108
115
 
109
116
  public async baseInsertApp(
110
117
  skipUpdate = false,
111
- focus?: boolean
112
118
  ): Promise<{ appId: string; app: NetlessApp }> {
113
119
  const params = this.params;
114
120
  if (!params.kind) {
@@ -122,9 +128,6 @@ export class AppProxy extends Base {
122
128
  throw new Error(`[WindowManager]: app load failed ${params.kind} ${params.src}`);
123
129
  }
124
130
  this.context.updateManagerRect();
125
- if (focus) {
126
- this.focusApp();
127
- }
128
131
  return {
129
132
  appId: this.id,
130
133
  app: appImpl,
@@ -133,7 +136,6 @@ export class AppProxy extends Base {
133
136
 
134
137
  private focusApp() {
135
138
  this.focusBox();
136
- this.context.switchAppToWriter(this.id);
137
139
  this.store.setMainViewFocusPath(this.manager.mainView);
138
140
  }
139
141
 
@@ -205,9 +207,6 @@ export class AppProxy extends Base {
205
207
 
206
208
  private afterSetupApp(boxInitState: AppInitState | undefined): void {
207
209
  if (boxInitState) {
208
- if (boxInitState.focus && this.scenePath) {
209
- this.context.switchAppToWriter(this.id);
210
- }
211
210
  if (!boxInitState?.x || !boxInitState.y) {
212
211
  this.boxManager?.setBoxInitState(this.id);
213
212
  }
@@ -226,29 +225,10 @@ export class AppProxy extends Base {
226
225
  await this.destroy(true, false, true);
227
226
  const params = this.params;
228
227
  const appProxy = new AppProxy(params, this.manager, this.id, this.isAddApp);
229
- await appProxy.baseInsertApp(true, this.store.focus === this.id);
228
+ await appProxy.baseInsertApp(true);
230
229
  this.boxManager?.updateBoxState(currentAppState);
231
230
  }
232
231
 
233
- public switchToWritable() {
234
- appRegister.notifyApp(this.kind, "focus", { appId: this.id });
235
- this.cameraStore.switchView(this.id, this.view, () => {
236
- if (this.view) {
237
- if (this.view.mode === ViewVisionMode.Writable) return;
238
- try {
239
- if (this.manager.mainView.mode === ViewVisionMode.Writable) {
240
- this.store.setMainViewFocusPath(this.manager.mainView);
241
- notifyMainViewModeChange(callbacks, ViewVisionMode.Freedom);
242
- setViewMode(this.manager.mainView, ViewVisionMode.Freedom);
243
- }
244
- setViewMode(this.view, ViewVisionMode.Writable);
245
- } catch (error) {
246
- log("switch view failed", error);
247
- }
248
- }
249
- });
250
- }
251
-
252
232
  public getAppInitState = (id: string) => {
253
233
  const attrs = this.store.getAppState(id);
254
234
  if (!attrs) return;
@@ -364,7 +344,6 @@ export class AppProxy extends Base {
364
344
 
365
345
  private async createView(): Promise<View> {
366
346
  const view = await this.viewManager.createView(this.id);
367
- this.cameraStore.register(this.id, view);
368
347
  this.setViewFocusScenePath();
369
348
  return view;
370
349
  }
@@ -388,7 +367,6 @@ export class AppProxy extends Base {
388
367
  this.store.cleanAppAttributes(this.id);
389
368
  }
390
369
  this.appProxies.delete(this.id);
391
- this.cameraStore.unregister(this.id, this.view);
392
370
 
393
371
  this.viewManager.destroyView(this.id);
394
372
  this.manager.appStatus.delete(this.id);
@@ -33,10 +33,6 @@ export class Context {
33
33
  public blurFocusBox() {
34
34
  this.manager.boxManager?.blurAllBox();
35
35
  }
36
-
37
- public switchAppToWriter(id: string) {
38
- this.manager.viewManager.switchAppToWriter(id);
39
- }
40
36
  }
41
37
 
42
38
  let context: Context;
package/src/BoxManager.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AppAttributes, DEFAULT_COLLECTOR_STYLE, Events, MIN_HEIGHT, MIN_WIDTH } from "./constants";
1
+ import { AppAttributes, Events, MIN_HEIGHT, MIN_WIDTH } from "./constants";
2
2
  import { debounce, maxBy } from "lodash";
3
3
  import {
4
4
  TELE_BOX_MANAGER_EVENT,
@@ -6,7 +6,7 @@ import {
6
6
  TeleBoxCollector,
7
7
  TeleBoxManager,
8
8
  } from "@netless/telebox-insider";
9
- import { WindowManager } from "./index";
9
+ import { emitter, WindowManager } from "./index";
10
10
  import type { AddAppOptions, AppInitState, EmitterType, CallbacksType } from "./index";
11
11
  import type {
12
12
  TeleBoxManagerUpdateConfig,
@@ -145,6 +145,11 @@ export class BoxManager {
145
145
  this.teleBoxManager.events.on("z_index", box => {
146
146
  this.context.updateAppState(box.id, AppAttributes.ZIndex, box.zIndex);
147
147
  });
148
+ emitter.on("playgroundSizeChange", this.playgroundSizeChangeListener);
149
+ }
150
+
151
+ private playgroundSizeChangeListener = () => {
152
+ this.updateManagerRect();
148
153
  }
149
154
 
150
155
  private get mainView() {
@@ -251,12 +256,8 @@ export class BoxManager {
251
256
  }
252
257
 
253
258
  public setCollectorContainer(container: HTMLElement) {
254
- const styles = {
255
- ...DEFAULT_COLLECTOR_STYLE,
256
- ...this.createTeleBoxManagerConfig?.collectorStyles,
257
- };
258
259
  const collector = new TeleBoxCollector({
259
- styles
260
+ styles: this.createTeleBoxManagerConfig?.collectorStyles,
260
261
  }).mount(container);
261
262
  this.teleBoxManager.setCollector(collector);
262
263
  }
@@ -391,6 +392,7 @@ export class BoxManager {
391
392
  }
392
393
 
393
394
  public destroy() {
395
+ emitter.off("playgroundSizeChange", this.playgroundSizeChangeListener);
394
396
  this.teleBoxManager.destroy();
395
397
  }
396
398
  }
@@ -0,0 +1,24 @@
1
+ import AppDocsViewer from "@netless/app-docs-viewer";
2
+ import AppMediaPlayer, { setOptions } from "@netless/app-media-player";
3
+ import { WindowManager } from "./index";
4
+ import "@netless/app-docs-viewer/dist/style.css";
5
+
6
+ export const setupBuiltin = () => {
7
+ if (WindowManager.debug) {
8
+ setOptions({ verbose: true });
9
+ }
10
+
11
+ WindowManager.register({
12
+ kind: AppDocsViewer.kind,
13
+ src: AppDocsViewer,
14
+ });
15
+ WindowManager.register({
16
+ kind: AppMediaPlayer.kind,
17
+ src: AppMediaPlayer,
18
+ });
19
+ };
20
+
21
+ export const BuiltinApps = {
22
+ DocsViewer: AppDocsViewer.kind as string,
23
+ MediaPlayer: AppMediaPlayer.kind as string,
24
+ };
@@ -0,0 +1,62 @@
1
+ import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
2
+ import { WindowManager } from "./index";
3
+ import type { EmitterType} from "./index";
4
+
5
+ const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
6
+
7
+ export class ContainerResizeObserver {
8
+ private containerResizeObserver?: ResizeObserver;
9
+
10
+ constructor(private emitter: EmitterType) {}
11
+
12
+ public static create(
13
+ container: HTMLElement,
14
+ sizer: HTMLElement,
15
+ wrapper: HTMLDivElement,
16
+ emitter: EmitterType,
17
+ ) {
18
+ const containerResizeObserver = new ContainerResizeObserver(emitter);
19
+ containerResizeObserver.observePlaygroundSize(container, sizer, wrapper);
20
+ return containerResizeObserver;
21
+ }
22
+
23
+ public observePlaygroundSize(
24
+ container: HTMLElement,
25
+ sizer: HTMLElement,
26
+ wrapper: HTMLDivElement
27
+ ) {
28
+ this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
29
+
30
+ this.containerResizeObserver = new ResizeObserver(entries => {
31
+ const containerRect = entries[0]?.contentRect;
32
+ if (containerRect) {
33
+ this.updateSizer(containerRect, sizer, wrapper);
34
+ this.emitter.emit("playgroundSizeChange", containerRect)
35
+ }
36
+ });
37
+
38
+ this.containerResizeObserver.observe(container);
39
+ }
40
+
41
+ private updateSizer(
42
+ { width, height }: DOMRectReadOnly,
43
+ sizer: HTMLElement,
44
+ wrapper: HTMLDivElement
45
+ ) {
46
+ if (width && height) {
47
+ if (height / width > WindowManager.containerSizeRatio) {
48
+ height = width * WindowManager.containerSizeRatio;
49
+ sizer.classList.toggle("netless-window-manager-sizer-horizontal", true);
50
+ } else {
51
+ width = height / WindowManager.containerSizeRatio;
52
+ sizer.classList.toggle("netless-window-manager-sizer-horizontal", false);
53
+ }
54
+ wrapper.style.width = `${width}px`;
55
+ wrapper.style.height = `${height}px`;
56
+ }
57
+ }
58
+
59
+ public disconnect() {
60
+ this.containerResizeObserver?.disconnect();
61
+ }
62
+ }
package/src/Helper.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { WindowManager } from "./index";
2
+
3
+ export const setupWrapper = (
4
+ root: HTMLElement
5
+ ): {
6
+ playground: HTMLDivElement;
7
+ wrapper: HTMLDivElement;
8
+ sizer: HTMLDivElement;
9
+ mainViewElement: HTMLDivElement;
10
+ } => {
11
+ const playground = document.createElement("div");
12
+ playground.className = "netless-window-manager-playground";
13
+
14
+ const sizer = document.createElement("div");
15
+ sizer.className = "netless-window-manager-sizer";
16
+
17
+ const wrapper = document.createElement("div");
18
+ wrapper.className = "netless-window-manager-wrapper";
19
+
20
+ const mainViewElement = document.createElement("div");
21
+ mainViewElement.className = "netless-window-manager-main-view";
22
+
23
+ playground.appendChild(sizer);
24
+ sizer.appendChild(wrapper);
25
+ wrapper.appendChild(mainViewElement);
26
+ root.appendChild(playground);
27
+ WindowManager.wrapper = wrapper;
28
+
29
+ return { playground, wrapper, sizer, mainViewElement };
30
+ };
@@ -1,5 +1,4 @@
1
1
  import { debounce, isFunction } from "lodash";
2
- import { emitter } from "./index";
3
2
  import { log } from "./Utils/log";
4
3
  import { RoomPhase } from "white-web-sdk";
5
4
  import type { Room } from "white-web-sdk";
@@ -1,7 +1,7 @@
1
- import { appRegister } from '../Register';
2
- import { debounce } from 'lodash';
3
- import { emitter } from '../index';
4
- import { v4 } from 'uuid';
1
+ import { appRegister } from "../Register";
2
+ import { debounce } from "lodash";
3
+ import { emitter } from "../index";
4
+ import { v4 } from "uuid";
5
5
  import type { PublicEvent } from "../index";
6
6
  import type { Displayer, ViewVisionMode, Room, View } from "white-web-sdk";
7
7
  import type Emittery from "emittery";
@@ -26,7 +26,21 @@ export const setScenePath = (room: Room | undefined, scenePath: string) => {
26
26
  room.setScenePath(scenePath);
27
27
  }
28
28
  }
29
- }
29
+ };
30
+
31
+ export const getScenePath = (
32
+ room: Room | undefined,
33
+ dir: string | undefined,
34
+ index: number
35
+ ): string | undefined => {
36
+ if (room && dir) {
37
+ const scenes = entireScenes(room);
38
+ const scene = scenes[dir]?.[index];
39
+ if (scene) {
40
+ return `${dir}/${scene.name}`;
41
+ }
42
+ }
43
+ };
30
44
 
31
45
  export const setViewMode = (view: View, mode: ViewVisionMode) => {
32
46
  if (!(view as any).didRelease && view.mode !== mode) {
@@ -44,7 +58,7 @@ export const emitError = (error: Error) => {
44
58
 
45
59
  export const addEmitterOnceListener = (event: any, listener: any) => {
46
60
  emitter.once(event).then(listener);
47
- }
61
+ };
48
62
 
49
63
  export const notifyMainViewModeChange = debounce(
50
64
  (callbacks: Emittery<PublicEvent>, mode: ViewVisionMode) => {
@@ -53,9 +67,10 @@ export const notifyMainViewModeChange = debounce(
53
67
  200
54
68
  );
55
69
 
56
- export const makeValidScenePath = (displayer: Displayer, scenePath: string) => {
57
- const scenes = displayer.entireScenes()[scenePath];
58
- const firstSceneName = scenes[0].name;
70
+ export const makeValidScenePath = (displayer: Displayer, scenePath: string, index = 0) => {
71
+ const scenes = entireScenes(displayer)[scenePath];
72
+ if (!scenes) return;
73
+ const firstSceneName = scenes[index].name;
59
74
  if (scenePath === "/") {
60
75
  return `/${firstSceneName}`;
61
76
  } else {
@@ -63,9 +78,13 @@ export const makeValidScenePath = (displayer: Displayer, scenePath: string) => {
63
78
  }
64
79
  };
65
80
 
81
+ export const entireScenes = (displayer: Displayer) => {
82
+ return displayer.entireScenes();
83
+ };
84
+
66
85
  export const isValidScenePath = (scenePath: string) => {
67
86
  return scenePath.startsWith("/");
68
- }
87
+ };
69
88
 
70
89
  export const ensureValidScenePath = (scenePath: string) => {
71
90
  if (scenePath.endsWith("/")) {
@@ -73,11 +92,14 @@ export const ensureValidScenePath = (scenePath: string) => {
73
92
  } else {
74
93
  return scenePath;
75
94
  }
76
- }
95
+ };
77
96
 
78
97
  export const getVersionNumber = (version: string) => {
79
- const versionString = version.split(".").map(s => s.padStart(2, "0")).join("");
98
+ const versionString = version
99
+ .split(".")
100
+ .map(s => s.padStart(2, "0"))
101
+ .join("");
80
102
  return parseInt(versionString);
81
103
  };
82
104
 
83
- export const wait = (time: number) => new Promise((resolve) => setTimeout(resolve, time));
105
+ export const wait = (time: number) => new Promise(resolve => setTimeout(resolve, time));
@@ -1,5 +1,6 @@
1
1
  import { listenUpdated, unlistenUpdated, reaction, UpdateEventKind } from "white-web-sdk";
2
2
  import type { AkkoObjectUpdatedProperty , AkkoObjectUpdatedListener } from "white-web-sdk";
3
+ import { isObject } from "lodash";
3
4
 
4
5
  // 兼容 13 和 14 版本 SDK
5
6
  export const onObjectByEvent = (event: UpdateEventKind) => {
@@ -30,7 +31,8 @@ export const onObjectByEvent = (event: UpdateEventKind) => {
30
31
 
31
32
  export const safeListenPropsUpdated = <T>(
32
33
  getProps: () => T,
33
- callback: AkkoObjectUpdatedListener<T>
34
+ callback: AkkoObjectUpdatedListener<T>,
35
+ onDestroyed?: (props: unknown) => void
34
36
  ) => {
35
37
  let disposeListenUpdated: (() => void) | null = null;
36
38
  const disposeReaction = reaction(
@@ -41,8 +43,12 @@ export const safeListenPropsUpdated = <T>(
41
43
  disposeListenUpdated = null;
42
44
  }
43
45
  const props = getProps();
44
- disposeListenUpdated = () => unlistenUpdated(props, callback);
45
- listenUpdated(props, callback);
46
+ if (isObject(props)) {
47
+ disposeListenUpdated = () => unlistenUpdated(props, callback);
48
+ listenUpdated(props, callback);
49
+ } else {
50
+ onDestroyed?.(props);
51
+ }
46
52
  },
47
53
  { fireImmediately: true }
48
54
  );
@@ -1,17 +1,16 @@
1
- import { AnimationMode, reaction, ViewVisionMode } from "white-web-sdk";
2
- import { Base } from "./Base";
3
- import { callbacks, emitter } from "./index";
1
+ import { AnimationMode, reaction } from "white-web-sdk";
2
+ import { Base } from "../Base";
3
+ import { callbacks, emitter } from "../index";
4
4
  import { createView } from "./ViewManager";
5
5
  import { debounce, isEmpty, isEqual } from "lodash";
6
- import { Fields } from "./AttributesDelegate";
7
- import { notifyMainViewModeChange, setViewFocusScenePath, setViewMode } from "./Utils/Common";
6
+ import { Fields } from "../AttributesDelegate";
7
+ import { setViewFocusScenePath } from "../Utils/Common";
8
8
  import { SideEffectManager } from "side-effect-manager";
9
9
  import type { Camera, Size, View } from "white-web-sdk";
10
- import type { AppManager } from "./AppManager";
10
+ import type { AppManager } from "../AppManager";
11
11
 
12
12
  export class MainViewProxy extends Base {
13
13
  private scale?: number;
14
- private cameraStore = this.manager.cameraStore;
15
14
  private started = false;
16
15
  private mainViewIsAddListener = false;
17
16
  private mainView: View;
@@ -23,7 +22,6 @@ export class MainViewProxy extends Base {
23
22
  super(manager);
24
23
  this.mainView = this.createMainView();
25
24
  this.moveCameraSizeByAttributes();
26
- this.cameraStore.register(this.viewId, this.mainView);
27
25
  emitter.once("mainViewMounted").then(() => {
28
26
  setTimeout(() => {
29
27
  this.start();
@@ -34,7 +32,7 @@ export class MainViewProxy extends Base {
34
32
  });
35
33
  const playgroundSizeChangeListener = () => {
36
34
  this.sizeChangeHandler(this.mainViewSize);
37
- }
35
+ };
38
36
  this.sideEffectManager.add(() => {
39
37
  emitter.on("playgroundSizeChange", playgroundSizeChangeListener);
40
38
  return () => emitter.off("playgroundSizeChange", playgroundSizeChangeListener);
@@ -103,9 +101,6 @@ export class MainViewProxy extends Base {
103
101
  if (mainViewScenePath) {
104
102
  setViewFocusScenePath(mainView, mainViewScenePath);
105
103
  }
106
- if (!this.store.focus) {
107
- this.switchViewModeToWriter();
108
- }
109
104
  return mainView;
110
105
  }
111
106
 
@@ -138,7 +133,6 @@ export class MainViewProxy extends Base {
138
133
 
139
134
  public async mainViewClickHandler(): Promise<void> {
140
135
  if (!this.manager.canOperate) return;
141
- if (this.view.mode === ViewVisionMode.Writable) return;
142
136
  this.store.cleanFocus();
143
137
  this.context.blurFocusBox();
144
138
  }
@@ -163,17 +157,6 @@ export class MainViewProxy extends Base {
163
157
  callbacks.emit("cameraStateChange", this.cameraState);
164
158
  };
165
159
 
166
- public switchViewModeToWriter(): void {
167
- if (!this.manager.canOperate) return;
168
- if (this.view) {
169
- if (this.view.mode === ViewVisionMode.Writable) return;
170
- this.cameraStore.switchView(this.viewId, this.mainView, () => {
171
- notifyMainViewModeChange(callbacks, ViewVisionMode.Writable);
172
- setViewMode(this.view, ViewVisionMode.Writable);
173
- });
174
- }
175
- }
176
-
177
160
  public moveCameraToContian(size: Size): void {
178
161
  if (!isEmpty(size)) {
179
162
  this.view.moveCameraToContain({
@@ -210,7 +193,6 @@ export class MainViewProxy extends Base {
210
193
 
211
194
  public destroy() {
212
195
  this.stop();
213
- this.cameraStore.unregister(this.viewId, this.mainView);
214
196
  this.sideEffectManager.flushAll();
215
197
  }
216
198
  }
@@ -0,0 +1,53 @@
1
+ import type { View , Displayer} from "white-web-sdk";
2
+
3
+ export class ViewManager {
4
+ public views: Map<string, View> = new Map();
5
+
6
+ constructor(private displayer: Displayer) {}
7
+
8
+ public createView(id: string): View {
9
+ const view = createView(this.displayer);
10
+ this.views.set(id, view);
11
+ return view;
12
+ }
13
+
14
+ public getView(id: string): View | undefined {
15
+ return this.views.get(id);
16
+ }
17
+
18
+ public destroyView(id: string): void {
19
+ const view = this.views.get(id);
20
+ if (view) {
21
+ view.release();
22
+ this.views.delete(id);
23
+ }
24
+ }
25
+
26
+ public setViewScenePath(id: string, scenePath: string): void {
27
+ const view = this.views.get(id);
28
+ if (view) {
29
+ view.focusScenePath = scenePath;
30
+ }
31
+ }
32
+
33
+ public destroy() {
34
+ this.views.forEach(view => {
35
+ view.release();
36
+ });
37
+ this.views.clear();
38
+ }
39
+ }
40
+
41
+
42
+ export const createView = (displayer: Displayer): View => {
43
+ const view = displayer.views.createView();
44
+ setDefaultCameraBound(view);
45
+ return view;
46
+ };
47
+
48
+ export const setDefaultCameraBound = (view: View) => {
49
+ view.setCameraBound({
50
+ maxContentMode: () => 10,
51
+ minContentMode: () => 0.1,
52
+ });
53
+ };
package/src/constants.ts CHANGED
@@ -44,6 +44,4 @@ export const MIN_HEIGHT = 340 / 720;
44
44
 
45
45
  export const SET_SCENEPATH_DELAY = 100; // 设置 scenePath 的延迟事件
46
46
 
47
- export const DEFAULT_COLLECTOR_STYLE = { right: "10px", bottom: "15px", position: "absolute" };
48
-
49
47
  export const DEFAULT_CONTAINER_RATIO = 9 / 16;