@netless/window-manager 0.3.18 → 0.4.0-canary.11
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/CHANGELOG.md +6 -0
- package/README.md +4 -43
- package/dist/App/MagixEvent/index.d.ts +28 -0
- package/dist/App/Storage/StorageEvent.d.ts +8 -0
- package/dist/App/Storage/index.d.ts +38 -0
- package/dist/App/Storage/typings.d.ts +21 -0
- package/dist/App/Storage/utils.d.ts +5 -0
- package/dist/AppContext.d.ts +42 -17
- package/dist/AppListener.d.ts +2 -2
- package/dist/AppManager.d.ts +18 -14
- package/dist/AppProxy.d.ts +5 -3
- package/dist/AttributesDelegate.d.ts +19 -11
- package/dist/Base/Context.d.ts +0 -1
- package/dist/Base/index.d.ts +1 -2
- package/dist/BoxManager.d.ts +24 -7
- package/dist/BuiltinApps.d.ts +6 -0
- package/dist/ContainerResizeObserver.d.ts +10 -0
- package/dist/Cursor/Cursor.d.ts +2 -3
- package/dist/Cursor/index.d.ts +9 -5
- package/dist/Helper.d.ts +6 -0
- package/dist/ReconnectRefresher.d.ts +9 -3
- package/dist/Utils/Common.d.ts +3 -1
- package/dist/Utils/Reactive.d.ts +1 -1
- package/dist/Utils/RoomHacker.d.ts +2 -2
- package/dist/Utils/error.d.ts +3 -0
- package/dist/{MainView.d.ts → View/MainView.d.ts} +3 -4
- package/dist/View/ViewManager.d.ts +13 -0
- package/dist/constants.d.ts +3 -7
- package/dist/index.d.ts +25 -27
- package/dist/index.es.js +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/typings.d.ts +3 -2
- package/docs/api.md +17 -0
- package/docs/migrate.md +42 -0
- package/package.json +6 -4
- package/src/App/MagixEvent/index.ts +66 -0
- package/src/App/Storage/StorageEvent.ts +21 -0
- package/src/App/Storage/index.ts +284 -0
- package/src/App/Storage/typings.ts +21 -0
- package/src/App/Storage/utils.ts +17 -0
- package/src/AppContext.ts +61 -21
- package/src/AppListener.ts +15 -11
- package/src/AppManager.ts +141 -95
- package/src/AppProxy.ts +49 -52
- package/src/AttributesDelegate.ts +76 -49
- package/src/Base/Context.ts +2 -6
- package/src/Base/index.ts +2 -2
- package/src/BoxManager.ts +89 -31
- package/src/BuiltinApps.ts +24 -0
- package/src/ContainerResizeObserver.ts +62 -0
- package/src/Cursor/Cursor.ts +35 -39
- package/src/Cursor/index.ts +79 -43
- package/src/Helper.ts +30 -0
- package/src/ReconnectRefresher.ts +25 -10
- package/src/Utils/Common.ts +35 -13
- package/src/Utils/Reactive.ts +9 -3
- package/src/Utils/RoomHacker.ts +20 -5
- package/src/Utils/error.ts +6 -1
- package/src/{MainView.ts → View/MainView.ts} +19 -27
- package/src/View/ViewManager.ts +53 -0
- package/src/constants.ts +2 -3
- package/src/index.ts +144 -171
- package/src/shim.d.ts +4 -0
- package/src/style.css +7 -1
- package/src/typings.ts +3 -2
- package/vite.config.js +4 -1
- package/dist/Utils/CameraStore.d.ts +0 -15
- package/dist/ViewManager.d.ts +0 -29
- package/dist/sdk.d.ts +0 -14
- package/src/Utils/CameraStore.ts +0 -72
- package/src/sdk.ts +0 -39
- package/src/viewManager.ts +0 -177
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,8 +1,12 @@
|
|
1
|
-
import { isFunction } from
|
2
|
-
import {
|
1
|
+
import { debounce, isFunction } from "lodash";
|
2
|
+
import { log } from "./Utils/log";
|
3
|
+
import { RoomPhase } from "white-web-sdk";
|
3
4
|
import type { Room } from "white-web-sdk";
|
4
|
-
import type {
|
5
|
-
|
5
|
+
import type { EmitterType } from "./index";
|
6
|
+
|
7
|
+
export type ReconnectRefresherContext = {
|
8
|
+
emitter: EmitterType;
|
9
|
+
};
|
6
10
|
|
7
11
|
// 白板重连之后会刷新所有的对象,导致 listener 失效, 所以这里在重连之后重新对所有对象进行监听
|
8
12
|
export class ReconnectRefresher {
|
@@ -11,20 +15,27 @@ export class ReconnectRefresher {
|
|
11
15
|
private reactors: Map<string, any> = new Map();
|
12
16
|
private disposers: Map<string, any> = new Map();
|
13
17
|
|
14
|
-
constructor(
|
18
|
+
constructor(private ctx: ReconnectRefresherContext) {}
|
19
|
+
|
20
|
+
public setRoom(room: Room | undefined) {
|
15
21
|
this.room = room;
|
16
22
|
this.phase = room?.phase;
|
23
|
+
room?.callbacks.off("onPhaseChanged", this.onPhaseChanged);
|
17
24
|
room?.callbacks.on("onPhaseChanged", this.onPhaseChanged);
|
18
25
|
}
|
19
26
|
|
27
|
+
public setContext(ctx: ReconnectRefresherContext) {
|
28
|
+
this.ctx = ctx;
|
29
|
+
}
|
30
|
+
|
20
31
|
private onPhaseChanged = (phase: RoomPhase) => {
|
21
32
|
if (phase === RoomPhase.Connected && this.phase === RoomPhase.Reconnecting) {
|
22
33
|
this.onReconnected();
|
23
34
|
}
|
24
35
|
this.phase = phase;
|
25
|
-
}
|
36
|
+
};
|
26
37
|
|
27
|
-
private onReconnected = () => {
|
38
|
+
private onReconnected = debounce(() => {
|
28
39
|
log("onReconnected refresh reactors");
|
29
40
|
this.releaseDisposers();
|
30
41
|
this.reactors.forEach((func, id) => {
|
@@ -32,15 +43,15 @@ export class ReconnectRefresher {
|
|
32
43
|
this.disposers.set(id, func());
|
33
44
|
}
|
34
45
|
});
|
35
|
-
this.
|
36
|
-
}
|
46
|
+
this.ctx.emitter.emit("onReconnected", undefined);
|
47
|
+
}, 3000);
|
37
48
|
|
38
49
|
private releaseDisposers() {
|
39
50
|
this.disposers.forEach(disposer => {
|
40
51
|
if (isFunction(disposer)) {
|
41
52
|
disposer();
|
42
53
|
}
|
43
|
-
})
|
54
|
+
});
|
44
55
|
this.disposers.clear();
|
45
56
|
}
|
46
57
|
|
@@ -64,6 +75,10 @@ export class ReconnectRefresher {
|
|
64
75
|
}
|
65
76
|
}
|
66
77
|
|
78
|
+
public hasReactor(id: string) {
|
79
|
+
return this.reactors.has(id);
|
80
|
+
}
|
81
|
+
|
67
82
|
public destroy() {
|
68
83
|
this.room?.callbacks.off("onPhaseChanged", this.onPhaseChanged);
|
69
84
|
this.releaseDisposers();
|
package/src/Utils/Common.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { appRegister } from
|
2
|
-
import { debounce } from
|
3
|
-
import { emitter } from
|
4
|
-
import { v4 } from
|
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 =
|
58
|
-
|
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
|
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(
|
105
|
+
export const wait = (time: number) => new Promise(resolve => setTimeout(resolve, time));
|
package/src/Utils/Reactive.ts
CHANGED
@@ -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
|
-
|
45
|
-
|
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
|
);
|
package/src/Utils/RoomHacker.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import { emitter } from
|
2
|
-
import { isPlayer } from
|
1
|
+
import { emitter } from "../index";
|
2
|
+
import { isPlayer } from "white-web-sdk";
|
3
|
+
import type { WindowManager } from '../index';
|
3
4
|
import type { Camera, Room , Player , PlayerSeekingResult } from "white-web-sdk";
|
4
|
-
import type { AppManager } from "../AppManager";
|
5
5
|
|
6
6
|
// 修改多窗口状态下一些失效的方法实现到 manager 的 mainview 上, 降低迁移成本
|
7
|
-
export const replaceRoomFunction = (room: Room, manager:
|
7
|
+
export const replaceRoomFunction = (room: Room, manager: WindowManager) => {
|
8
8
|
if (isPlayer(room)) {
|
9
9
|
const player = room as unknown as Player;
|
10
10
|
const originSeek = player.seekToProgressTime;
|
@@ -29,13 +29,28 @@ export const replaceRoomFunction = (room: Room, manager: AppManager) => {
|
|
29
29
|
},
|
30
30
|
});
|
31
31
|
|
32
|
+
Object.defineProperty(room, "canUndoSteps", {
|
33
|
+
get() {
|
34
|
+
return manager.mainView.canUndoSteps;
|
35
|
+
}
|
36
|
+
});
|
37
|
+
|
38
|
+
Object.defineProperty(room, "canRedoSteps", {
|
39
|
+
get() {
|
40
|
+
return manager.mainView.canRedoSteps;
|
41
|
+
}
|
42
|
+
});
|
43
|
+
|
32
44
|
room.moveCamera = (camera: Camera) => manager.mainView.moveCamera(camera);
|
33
|
-
room.moveCameraToContain = (...args) => manager.
|
45
|
+
room.moveCameraToContain = (...args) => manager.moveCameraToContain(...args);
|
34
46
|
room.convertToPointInWorld = (...args) => manager.mainView.convertToPointInWorld(...args);
|
35
47
|
room.setCameraBound = (...args) => manager.mainView.setCameraBound(...args);
|
36
48
|
room.scenePreview = (...args) => manager.mainView.scenePreview(...args);
|
37
49
|
room.fillSceneSnapshot = (...args) => manager.mainView.fillSceneSnapshot(...args);
|
38
50
|
room.generateScreenshot = (...args) => manager.mainView.generateScreenshot(...args);
|
51
|
+
room.setMemberState = (...args) => manager.mainView.setMemberState(...args);
|
52
|
+
room.redo = () => manager.mainView.redo();
|
53
|
+
room.undo = () => manager.mainView.undo();
|
39
54
|
}
|
40
55
|
|
41
56
|
};
|
package/src/Utils/error.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
export class AppCreateError extends Error {
|
2
3
|
override message = "[WindowManager]: app duplicate exists and cannot be created again";
|
3
4
|
}
|
@@ -28,4 +29,8 @@ export class BoxNotCreatedError extends Error {
|
|
28
29
|
|
29
30
|
export class InvalidScenePath extends Error {
|
30
31
|
override message = `[WindowManager]: ScenePath should start with "/"`;
|
31
|
-
}
|
32
|
+
}
|
33
|
+
|
34
|
+
export class BoxManagerNotFoundError extends Error {
|
35
|
+
override message = "[WindowManager]: boxManager not found";
|
36
|
+
}
|
@@ -1,27 +1,29 @@
|
|
1
|
-
import { AnimationMode, reaction
|
2
|
-
import { Base } from "
|
3
|
-
import { callbacks, emitter } from "
|
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 "
|
7
|
-
import {
|
6
|
+
import { Fields } from "../AttributesDelegate";
|
7
|
+
import { setViewFocusScenePath } from "../Utils/Common";
|
8
|
+
import { SideEffectManager } from "side-effect-manager";
|
8
9
|
import type { Camera, Size, View } from "white-web-sdk";
|
9
|
-
import type { AppManager } from "
|
10
|
+
import type { AppManager } from "../AppManager";
|
10
11
|
|
11
12
|
export class MainViewProxy extends Base {
|
12
13
|
private scale?: number;
|
13
|
-
private cameraStore = this.manager.cameraStore;
|
14
14
|
private started = false;
|
15
15
|
private mainViewIsAddListener = false;
|
16
16
|
private mainView: View;
|
17
17
|
private viewId = "mainView";
|
18
18
|
|
19
|
+
private sideEffectManager = new SideEffectManager();
|
20
|
+
|
19
21
|
constructor(manager: AppManager) {
|
20
22
|
super(manager);
|
21
23
|
this.mainView = this.createMainView();
|
22
24
|
this.moveCameraSizeByAttributes();
|
23
|
-
this.cameraStore.register(this.viewId, this.mainView);
|
24
25
|
emitter.once("mainViewMounted").then(() => {
|
26
|
+
this.addMainViewListener();
|
25
27
|
setTimeout(() => {
|
26
28
|
this.start();
|
27
29
|
if (!this.mainViewCamera || !this.mainViewSize) {
|
@@ -29,8 +31,12 @@ export class MainViewProxy extends Base {
|
|
29
31
|
}
|
30
32
|
}, 200); // 等待 mainView 挂载完毕再进行监听,否则会触发不必要的 onSizeUpdated
|
31
33
|
});
|
32
|
-
|
34
|
+
const playgroundSizeChangeListener = () => {
|
33
35
|
this.sizeChangeHandler(this.mainViewSize);
|
36
|
+
};
|
37
|
+
this.sideEffectManager.add(() => {
|
38
|
+
emitter.on("playgroundSizeChange", playgroundSizeChangeListener);
|
39
|
+
return () => emitter.off("playgroundSizeChange", playgroundSizeChangeListener);
|
34
40
|
});
|
35
41
|
}
|
36
42
|
|
@@ -75,7 +81,7 @@ export class MainViewProxy extends Base {
|
|
75
81
|
);
|
76
82
|
};
|
77
83
|
|
78
|
-
private sizeChangeHandler =
|
84
|
+
private sizeChangeHandler = debounce((size: Size) => {
|
79
85
|
if (size) {
|
80
86
|
this.moveCameraToContian(size);
|
81
87
|
this.moveCamera(this.mainViewCamera);
|
@@ -96,15 +102,12 @@ export class MainViewProxy extends Base {
|
|
96
102
|
if (mainViewScenePath) {
|
97
103
|
setViewFocusScenePath(mainView, mainViewScenePath);
|
98
104
|
}
|
99
|
-
if (!this.store.focus) {
|
100
|
-
this.switchViewModeToWriter();
|
101
|
-
}
|
102
105
|
return mainView;
|
103
106
|
}
|
104
107
|
|
105
108
|
private onCameraUpdatedByDevice = (camera: Camera) => {
|
106
109
|
this.store.setMainViewCamera({ ...camera, id: this.context.uid });
|
107
|
-
if (!isEqual(this.mainViewSize, {...this.mainView.size, id: this.context.uid})) {
|
110
|
+
if (!isEqual(this.mainViewSize, { ...this.mainView.size, id: this.context.uid })) {
|
108
111
|
this.setMainViewSize(this.view.size);
|
109
112
|
}
|
110
113
|
};
|
@@ -131,7 +134,6 @@ export class MainViewProxy extends Base {
|
|
131
134
|
|
132
135
|
public async mainViewClickHandler(): Promise<void> {
|
133
136
|
if (!this.manager.canOperate) return;
|
134
|
-
if (this.view.mode === ViewVisionMode.Writable) return;
|
135
137
|
this.store.cleanFocus();
|
136
138
|
this.context.blurFocusBox();
|
137
139
|
}
|
@@ -156,17 +158,6 @@ export class MainViewProxy extends Base {
|
|
156
158
|
callbacks.emit("cameraStateChange", this.cameraState);
|
157
159
|
};
|
158
160
|
|
159
|
-
public switchViewModeToWriter(): void {
|
160
|
-
if (!this.manager.canOperate) return;
|
161
|
-
if (this.view) {
|
162
|
-
if (this.view.mode === ViewVisionMode.Writable) return;
|
163
|
-
this.cameraStore.switchView(this.viewId, this.mainView, () => {
|
164
|
-
notifyMainViewModeChange(callbacks, ViewVisionMode.Writable);
|
165
|
-
setViewMode(this.view, ViewVisionMode.Writable);
|
166
|
-
});
|
167
|
-
}
|
168
|
-
}
|
169
|
-
|
170
161
|
public moveCameraToContian(size: Size): void {
|
171
162
|
if (!isEmpty(size)) {
|
172
163
|
this.view.moveCameraToContain({
|
@@ -195,6 +186,7 @@ export class MainViewProxy extends Base {
|
|
195
186
|
}
|
196
187
|
|
197
188
|
public stop() {
|
189
|
+
this.removeMainViewListener();
|
198
190
|
this.removeCameraListener();
|
199
191
|
this.manager.refresher?.remove(Fields.MainViewCamera);
|
200
192
|
this.manager.refresher?.remove(Fields.MainViewSize);
|
@@ -203,6 +195,6 @@ export class MainViewProxy extends Base {
|
|
203
195
|
|
204
196
|
public destroy() {
|
205
197
|
this.stop();
|
206
|
-
this.
|
198
|
+
this.sideEffectManager.flushAll();
|
207
199
|
}
|
208
200
|
}
|
@@ -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
@@ -10,6 +10,7 @@ export enum Events {
|
|
10
10
|
SetMainViewScenePath = "SetMainViewScenePath",
|
11
11
|
SetMainViewSceneIndex = "SetMainViewSceneIndex",
|
12
12
|
SwitchViewsToFreedom = "SwitchViewsToFreedom",
|
13
|
+
MoveCameraToContain = "MoveCameraToContain"
|
13
14
|
}
|
14
15
|
|
15
16
|
export const MagixEventName = "__WindowManger";
|
@@ -36,13 +37,11 @@ export enum CursorState {
|
|
36
37
|
Normal = "normal",
|
37
38
|
}
|
38
39
|
|
39
|
-
export const REQUIRE_VERSION = "2.
|
40
|
+
export const REQUIRE_VERSION = "2.16.0";
|
40
41
|
|
41
42
|
export const MIN_WIDTH = 340 / 720;
|
42
43
|
export const MIN_HEIGHT = 340 / 720;
|
43
44
|
|
44
45
|
export const SET_SCENEPATH_DELAY = 100; // 设置 scenePath 的延迟事件
|
45
46
|
|
46
|
-
export const DEFAULT_COLLECTOR_STYLE = { right: "10px", bottom: "15px", position: "absolute" };
|
47
|
-
|
48
47
|
export const DEFAULT_CONTAINER_RATIO = 9 / 16;
|