@netless/window-manager 1.0.13-test.4 → 1.0.13-test.6
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 +1 -0
- package/dist/index.js +14 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/AppListener.ts +1 -1
- package/src/AppManager.ts +3 -3
- package/src/ContainerResizeObserver.ts +4 -0
- package/src/Utils/RoomHacker.ts +1 -1
- package/src/Utils/log.ts +2 -2
- package/src/View/MainView.ts +8 -5
- package/src/index.ts +22 -2
package/package.json
CHANGED
package/src/AppListener.ts
CHANGED
|
@@ -47,7 +47,7 @@ export class AppListeners {
|
|
|
47
47
|
break;
|
|
48
48
|
}
|
|
49
49
|
case Events.SetMainViewScenePath: {
|
|
50
|
-
console.log("[window-manager] mainMagixEventListener "
|
|
50
|
+
console.log("[window-manager] mainMagixEventListener " + JSON.stringify(data.payload));
|
|
51
51
|
this.setMainViewScenePathHandler(data.payload);
|
|
52
52
|
break;
|
|
53
53
|
}
|
package/src/AppManager.ts
CHANGED
|
@@ -159,7 +159,7 @@ export class AppManager {
|
|
|
159
159
|
sceneName = this.callbacksNode?.scenes[nextIndex];
|
|
160
160
|
}
|
|
161
161
|
if (sceneName) {
|
|
162
|
-
console.log("[window-manager] onRemoveScenes setMainViewScenePath"
|
|
162
|
+
console.log("[window-manager] onRemoveScenes setMainViewScenePath" + `${ROOT_DIR}${sceneName}`);
|
|
163
163
|
this.setMainViewScenePath(`${ROOT_DIR}${sceneName}`);
|
|
164
164
|
}
|
|
165
165
|
await this.setMainViewSceneIndex(nextIndex);
|
|
@@ -713,8 +713,8 @@ export class AppManager {
|
|
|
713
713
|
callbacks.emit("onMainViewMounted", mainView);
|
|
714
714
|
const hasRoot = this.hasRoot(mainView.divElement);
|
|
715
715
|
const rect = this.getRectByDivElement(mainView.divElement);
|
|
716
|
-
console.log("[window-manager] bindMainView hasRoot"
|
|
717
|
-
window.outerHeight
|
|
716
|
+
console.log("[window-manager] bindMainView hasRoot" + hasRoot + JSON.stringify(rect) +
|
|
717
|
+
window.outerHeight + window.outerWidth,
|
|
718
718
|
window.visualViewport?.width ?? "null", window.visualViewport?.height ?? "null",
|
|
719
719
|
window.visualViewport?.offsetLeft ?? "null", window.visualViewport?.offsetTop ?? "null",
|
|
720
720
|
);
|
|
@@ -28,18 +28,21 @@ export class ContainerResizeObserver {
|
|
|
28
28
|
sizer: HTMLElement,
|
|
29
29
|
wrapper: HTMLDivElement
|
|
30
30
|
) {
|
|
31
|
+
console.log(`[window-manager] observePlaygroundSize ${container.getBoundingClientRect(), sizer.getBoundingClientRect(), wrapper.getBoundingClientRect()}`);
|
|
31
32
|
this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
|
|
32
33
|
|
|
33
34
|
this.containerResizeObserver = new ResizeObserver(entries => {
|
|
34
35
|
const containerRect = entries[0]?.contentRect;
|
|
35
36
|
if (containerRect) {
|
|
36
37
|
this.updateSizer(containerRect, sizer, wrapper);
|
|
38
|
+
console.log(`[window-manager] containerResizeObserver ${JSON.stringify(containerRect)}`);
|
|
37
39
|
this.emitter.emit("playgroundSizeChange", containerRect);
|
|
38
40
|
}
|
|
39
41
|
});
|
|
40
42
|
|
|
41
43
|
this.disposer = this.emitter.on("containerSizeRatioUpdate", () => {
|
|
42
44
|
const containerRect = container.getBoundingClientRect();
|
|
45
|
+
console.log(`[window-manager] containerSizeRatioUpdate ${JSON.stringify(containerRect)}`);
|
|
43
46
|
this.updateSizer(containerRect, sizer, wrapper);
|
|
44
47
|
this.emitter.emit("playgroundSizeChange", containerRect);
|
|
45
48
|
});
|
|
@@ -62,6 +65,7 @@ export class ContainerResizeObserver {
|
|
|
62
65
|
}
|
|
63
66
|
wrapper.style.width = `${width}px`;
|
|
64
67
|
wrapper.style.height = `${height}px`;
|
|
68
|
+
console.log(`[window-manager] updateSizer ${JSON.stringify({ width, height })}`);
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
|
package/src/Utils/RoomHacker.ts
CHANGED
|
@@ -37,7 +37,7 @@ export const replaceRoomFunction = (room: Room | Player, manager: WindowManager)
|
|
|
37
37
|
room.scalePptToFit = (...args) => {
|
|
38
38
|
_scalePptToFit.call(room, ...args);
|
|
39
39
|
if (manager.appManager?.mainViewProxy) {
|
|
40
|
-
console.log("[window-manager] scalePptToFit "
|
|
40
|
+
console.log("[window-manager] scalePptToFit " + JSON.stringify(args));
|
|
41
41
|
manager.appManager.mainViewProxy.setCameraAndSize();
|
|
42
42
|
}
|
|
43
43
|
};
|
package/src/Utils/log.ts
CHANGED
|
@@ -26,7 +26,7 @@ export class LocalConsole {
|
|
|
26
26
|
if (args === null) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
console.log(`[window-manager][${this.name}]
|
|
29
|
+
console.log(`[window-manager][${this.name}]: ${args.join(", ")}`);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
log(...args: unknown[]): void {
|
|
@@ -39,6 +39,6 @@ export class LocalConsole {
|
|
|
39
39
|
this.flushTimer = setTimeout(() => this.flush(), ms);
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
console.log(`[window-manager][${this.name}]
|
|
42
|
+
console.log(`[window-manager][${this.name}]: ${args.join(", ")}`);
|
|
43
43
|
}
|
|
44
44
|
}
|
package/src/View/MainView.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { AppManager } from "../AppManager";
|
|
|
11
11
|
import { Events } from "../constants";
|
|
12
12
|
import { LocalConsole } from "../Utils/log";
|
|
13
13
|
|
|
14
|
+
(window as any).___local_log = (window as any).___local_log || new Set();
|
|
14
15
|
export class MainViewProxy {
|
|
15
16
|
/** Refresh the view's camera in an interval of 1.5s. */
|
|
16
17
|
public polling = false;
|
|
@@ -36,8 +37,9 @@ export class MainViewProxy {
|
|
|
36
37
|
this.startListenWritableChange();
|
|
37
38
|
});
|
|
38
39
|
const playgroundSizeChangeListener = () => {
|
|
39
|
-
// console.log("[window-manager] playgroundSizeChangeListener ", JSON.stringify(this.mainViewSize), JSON.stringify(this.mainViewCamera));
|
|
40
40
|
this.playgroundSizeChangeListenerLocalConsole.log(
|
|
41
|
+
JSON.stringify(this.mainView.camera),
|
|
42
|
+
JSON.stringify(this.mainView.size),
|
|
41
43
|
JSON.stringify(this.mainViewSize),
|
|
42
44
|
JSON.stringify(this.mainViewCamera),
|
|
43
45
|
window.outerHeight, window.outerWidth,
|
|
@@ -108,7 +110,7 @@ export class MainViewProxy {
|
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
public start() {
|
|
111
|
-
console.log("[window-manager] start "
|
|
113
|
+
console.log("[window-manager] start " + JSON.stringify(this.mainViewSize));
|
|
112
114
|
this.sizeChangeHandler(this.mainViewSize);
|
|
113
115
|
if (this.started) return;
|
|
114
116
|
this.addCameraListener();
|
|
@@ -132,7 +134,7 @@ export class MainViewProxy {
|
|
|
132
134
|
() => this.mainViewCamera,
|
|
133
135
|
camera => {
|
|
134
136
|
if (camera && camera.id !== this.manager.uid) {
|
|
135
|
-
console.log("[window-manager] cameraReaction "
|
|
137
|
+
console.log("[window-manager] cameraReaction " + JSON.stringify(camera) + JSON.stringify(this.mainViewSize));
|
|
136
138
|
this.moveCameraToContian(this.mainViewSize);
|
|
137
139
|
this.moveCamera(camera);
|
|
138
140
|
}
|
|
@@ -143,16 +145,17 @@ export class MainViewProxy {
|
|
|
143
145
|
|
|
144
146
|
public sizeChangeHandler = debounce((size: Size) => {
|
|
145
147
|
if (size) {
|
|
146
|
-
console.log("[window-manager] sizeChangeHandler current size and camera", JSON.stringify(size), JSON.stringify(this.mainViewCamera));
|
|
147
148
|
this.moveCameraToContian(size);
|
|
148
149
|
this.moveCamera(this.mainViewCamera);
|
|
150
|
+
console.log("[window-manager] sizeChangeHandler current size and camera" + JSON.stringify(size) + JSON.stringify(this.mainViewCamera) +
|
|
151
|
+
JSON.stringify(this.mainView.camera) + JSON.stringify(this.mainView.size));
|
|
149
152
|
}
|
|
150
153
|
this.ensureMainViewSize();
|
|
151
154
|
}, 30);
|
|
152
155
|
|
|
153
156
|
public onUpdateContainerSizeRatio = () => {
|
|
154
157
|
const size = this.store.getMainViewSize();
|
|
155
|
-
console.log("[window-manager] onUpdateContainerSizeRatio "
|
|
158
|
+
console.log("[window-manager] onUpdateContainerSizeRatio " + JSON.stringify(size));
|
|
156
159
|
this.sizeChangeHandler(size);
|
|
157
160
|
};
|
|
158
161
|
|
package/src/index.ts
CHANGED
|
@@ -255,10 +255,12 @@ export class WindowManager
|
|
|
255
255
|
(window as any).NETLESS_DEPS = __APP_DEPENDENCIES__;
|
|
256
256
|
this.visibleStateListener();
|
|
257
257
|
document.addEventListener("visibilitychange", this.visibleStateListener);
|
|
258
|
+
this.emitter.on('mainViewScenePathChange', this.onMainViewScenePathChangeHandler)
|
|
258
259
|
}
|
|
259
260
|
|
|
261
|
+
|
|
260
262
|
private visibleStateListener = () => {
|
|
261
|
-
console.log("[window-manager] visibleStateListener isVisible:"
|
|
263
|
+
console.log("[window-manager] visibleStateListener isVisible:" + !document.hidden);
|
|
262
264
|
}
|
|
263
265
|
|
|
264
266
|
public static onCreate(manager: WindowManager) {
|
|
@@ -392,10 +394,26 @@ export class WindowManager
|
|
|
392
394
|
console.warn("[WindowManager]: indexedDB open failed");
|
|
393
395
|
console.log(error);
|
|
394
396
|
}
|
|
397
|
+
manager.emitter.on('mainViewScenePathChange', manager.onMainViewScenePathChangeHandler)
|
|
395
398
|
return manager;
|
|
396
399
|
}
|
|
397
400
|
|
|
398
|
-
|
|
401
|
+
public onMainViewScenePathChangeHandler = (scenePath: string) => {
|
|
402
|
+
const mainViewElement = this.mainView.divElement;
|
|
403
|
+
if (mainViewElement) {
|
|
404
|
+
const backgroundImage = mainViewElement.querySelector('.background img');
|
|
405
|
+
if (backgroundImage) {
|
|
406
|
+
// todo 获取到 back ground image 的 rect情况以及css情况是否可见
|
|
407
|
+
const backgroundImageRect = backgroundImage?.getBoundingClientRect();
|
|
408
|
+
const backgroundImageCSS = window.getComputedStyle(backgroundImage);
|
|
409
|
+
const backgroundImageVisible = backgroundImageRect?.width > 0 && backgroundImageRect?.height > 0 && backgroundImageCSS.display !== 'none';
|
|
410
|
+
console.log("[window-manager] backgroundImageVisible" + backgroundImageVisible);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
console.log("[window-manager] onMainViewScenePathChange" + scenePath + 'backgroundImageVisible is not found');
|
|
414
|
+
}
|
|
415
|
+
console.log("[window-manager] onMainViewScenePathChange" + scenePath + 'mainViewElement is not found');
|
|
416
|
+
}
|
|
399
417
|
|
|
400
418
|
private static initManager(room: Room): Promise<WindowManager | undefined> {
|
|
401
419
|
return createInvisiblePlugin(room);
|
|
@@ -1029,6 +1047,7 @@ export class WindowManager
|
|
|
1029
1047
|
animationMode?: AnimationMode;
|
|
1030
1048
|
}>
|
|
1031
1049
|
): void {
|
|
1050
|
+
console.log("[window-manager] moveCameraToContain" + JSON.stringify(rectangle));
|
|
1032
1051
|
this.mainView.moveCameraToContain(rectangle);
|
|
1033
1052
|
setTimeout(() => {
|
|
1034
1053
|
this.appManager?.mainViewProxy.setCameraAndSize();
|
|
@@ -1065,6 +1084,7 @@ export class WindowManager
|
|
|
1065
1084
|
}
|
|
1066
1085
|
WindowManager.params = undefined;
|
|
1067
1086
|
document.removeEventListener("visibilitychange", this.visibleStateListener);
|
|
1087
|
+
this.emitter.off('mainViewScenePathChange', this.onMainViewScenePathChangeHandler);
|
|
1068
1088
|
this._iframeBridge?.destroy();
|
|
1069
1089
|
this._iframeBridge = undefined;
|
|
1070
1090
|
log("Destroyed");
|