@netless/window-manager 0.4.24 → 0.4.25
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 +4 -0
- package/__mocks__/white-web-sdk.ts +41 -0
- package/dist/ContainerResizeObserver.d.ts +2 -1
- package/dist/InternalEmitter.d.ts +1 -0
- package/dist/View/MainView.d.ts +2 -1
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +30 -6
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +10 -10
- package/dist/index.umd.js.map +1 -1
- package/docs/advanced.md +12 -4
- package/docs/api.md +9 -0
- package/package.json +5 -9
- package/pnpm-lock.yaml +793 -2690
- package/src/ContainerResizeObserver.ts +12 -1
- package/src/InternalEmitter.ts +1 -0
- package/src/View/MainView.ts +13 -3
- package/src/index.ts +10 -1
- package/vite.config.js +9 -1
@@ -1,11 +1,14 @@
|
|
1
1
|
import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
|
2
|
+
import { isFunction } from "lodash";
|
2
3
|
import { WindowManager } from "./index";
|
3
4
|
import type { EmitterType } from "./InternalEmitter";
|
5
|
+
import type { UnsubscribeFn } from "emittery";
|
4
6
|
|
5
7
|
const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
|
6
8
|
|
7
9
|
export class ContainerResizeObserver {
|
8
10
|
private containerResizeObserver?: ResizeObserver;
|
11
|
+
private disposer?: UnsubscribeFn;
|
9
12
|
|
10
13
|
constructor(private emitter: EmitterType) {}
|
11
14
|
|
@@ -35,10 +38,14 @@ export class ContainerResizeObserver {
|
|
35
38
|
}
|
36
39
|
});
|
37
40
|
|
41
|
+
this.disposer = this.emitter.on("containerSizeRatioUpdate", () => {
|
42
|
+
this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
|
43
|
+
});
|
44
|
+
|
38
45
|
this.containerResizeObserver.observe(container);
|
39
46
|
}
|
40
47
|
|
41
|
-
|
48
|
+
public updateSizer(
|
42
49
|
{ width, height }: DOMRectReadOnly,
|
43
50
|
sizer: HTMLElement,
|
44
51
|
wrapper: HTMLDivElement
|
@@ -58,5 +65,9 @@ export class ContainerResizeObserver {
|
|
58
65
|
|
59
66
|
public disconnect() {
|
60
67
|
this.containerResizeObserver?.disconnect();
|
68
|
+
if (isFunction(this.disposer)) {
|
69
|
+
this.disposer();
|
70
|
+
this.disposer = undefined;
|
71
|
+
}
|
61
72
|
}
|
62
73
|
}
|
package/src/InternalEmitter.ts
CHANGED
package/src/View/MainView.ts
CHANGED
@@ -32,8 +32,10 @@ export class MainViewProxy {
|
|
32
32
|
this.sizeChangeHandler(this.mainViewSize);
|
33
33
|
};
|
34
34
|
this.sideEffectManager.add(() => {
|
35
|
-
emitter.on("playgroundSizeChange", playgroundSizeChangeListener);
|
36
|
-
|
35
|
+
return emitter.on("playgroundSizeChange", playgroundSizeChangeListener);
|
36
|
+
});
|
37
|
+
this.sideEffectManager.add(() => {
|
38
|
+
return emitter.on("containerSizeRatioUpdate", this.onUpdateContainerSizeRatio);
|
37
39
|
});
|
38
40
|
}
|
39
41
|
|
@@ -98,13 +100,21 @@ export class MainViewProxy {
|
|
98
100
|
);
|
99
101
|
};
|
100
102
|
|
101
|
-
|
103
|
+
public sizeChangeHandler = debounce((size: Size) => {
|
102
104
|
if (size) {
|
103
105
|
this.moveCameraToContian(size);
|
104
106
|
this.moveCamera(this.mainViewCamera);
|
105
107
|
}
|
106
108
|
}, 30);
|
107
109
|
|
110
|
+
public onUpdateContainerSizeRatio = () => {
|
111
|
+
const size = this.store.getMainViewSize();
|
112
|
+
this.sizeChangeHandler(size);
|
113
|
+
if (size.id === this.manager.uid) {
|
114
|
+
this.setCameraAndSize();
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
108
118
|
public get view(): View {
|
109
119
|
return this.mainView;
|
110
120
|
}
|
package/src/index.ts
CHANGED
@@ -11,7 +11,7 @@ import { emitter } from "./InternalEmitter";
|
|
11
11
|
import { Fields } from "./AttributesDelegate";
|
12
12
|
import { initDb } from "./Register/storage";
|
13
13
|
import { InvisiblePlugin, isPlayer, isRoom, RoomPhase, ViewMode } from "white-web-sdk";
|
14
|
-
import { isEqual, isNull, isObject, omit } from "lodash";
|
14
|
+
import { isEqual, isNull, isObject, omit, isNumber } from "lodash";
|
15
15
|
import { log } from "./Utils/log";
|
16
16
|
import { PageStateImpl } from "./PageState";
|
17
17
|
import { ReconnectRefresher } from "./ReconnectRefresher";
|
@@ -893,6 +893,15 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
893
893
|
this.appManager?.refresher?.refresh();
|
894
894
|
}
|
895
895
|
|
896
|
+
public setContainerSizeRatio(ratio: number) {
|
897
|
+
if (!isNumber(ratio)) {
|
898
|
+
throw new Error(`[WindowManager]: updateContainerSizeRatio error, ratio must be a number. but got ${ratio}`);
|
899
|
+
}
|
900
|
+
WindowManager.containerSizeRatio = ratio;
|
901
|
+
this.containerSizeRatio = ratio;
|
902
|
+
emitter.emit("containerSizeRatioUpdate", ratio);
|
903
|
+
}
|
904
|
+
|
896
905
|
private isDynamicPPT(scenes: SceneDefinition[]) {
|
897
906
|
const sceneSrc = scenes[0]?.ppt?.src;
|
898
907
|
return sceneSrc?.startsWith("pptx://");
|
package/vite.config.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import path from "path";
|
2
|
-
import { defineConfig } from
|
2
|
+
import { defineConfig } from 'vitest/config'
|
3
3
|
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
4
4
|
import { dependencies, peerDependencies, version, devDependencies } from "./package.json"
|
5
5
|
import { omit } from "lodash";
|
@@ -8,6 +8,14 @@ export default defineConfig(({ mode }) => {
|
|
8
8
|
const isProd = mode === "production";
|
9
9
|
|
10
10
|
return {
|
11
|
+
test: {
|
12
|
+
environment: "jsdom",
|
13
|
+
deps: {
|
14
|
+
inline: [
|
15
|
+
"@juggle/resize-observer"
|
16
|
+
]
|
17
|
+
}
|
18
|
+
},
|
11
19
|
define: {
|
12
20
|
__APP_VERSION__: JSON.stringify(version),
|
13
21
|
__APP_DEPENDENCIES__: JSON.stringify({
|