@netless/window-manager 0.4.30 → 1.0.0-canary.0

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 (44) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/App/AppProxy.d.ts +0 -1
  3. package/dist/AppManager.d.ts +5 -1
  4. package/dist/BoxEmitter.d.ts +34 -0
  5. package/dist/BoxManager.d.ts +8 -6
  6. package/dist/Cursor/index.d.ts +3 -1
  7. package/dist/Helper.d.ts +0 -2
  8. package/dist/InternalEmitter.d.ts +2 -19
  9. package/dist/Utils/AppCreateQueue.d.ts +2 -3
  10. package/dist/View/CameraSynchronizer.d.ts +17 -0
  11. package/dist/View/MainView.d.ts +4 -5
  12. package/dist/index.cjs.js +21 -22
  13. package/dist/index.d.ts +2 -3
  14. package/dist/index.es.js +2283 -1898
  15. package/dist/index.umd.js +21 -22
  16. package/dist/style.css +1 -1
  17. package/dist/typings.d.ts +2 -1
  18. package/docs/api.md +1 -1
  19. package/docs/app-context.md +127 -36
  20. package/docs/develop-app.md +1 -1
  21. package/package.json +5 -4
  22. package/pnpm-lock.yaml +150 -133
  23. package/src/App/AppContext.ts +1 -1
  24. package/src/App/AppProxy.ts +2 -10
  25. package/src/AppManager.ts +67 -59
  26. package/src/BoxEmitter.ts +19 -0
  27. package/src/BoxManager.ts +99 -108
  28. package/src/Cursor/Cursor.ts +3 -3
  29. package/src/Cursor/index.ts +13 -7
  30. package/src/Helper.ts +2 -15
  31. package/src/InternalEmitter.ts +6 -8
  32. package/src/Utils/AppCreateQueue.ts +2 -3
  33. package/src/View/CameraSynchronizer.ts +67 -0
  34. package/src/View/MainView.ts +45 -53
  35. package/src/index.ts +33 -57
  36. package/src/typings.ts +3 -0
  37. package/vite.config.js +0 -1
  38. package/dist/ContainerResizeObserver.d.ts +0 -11
  39. package/dist/ScenePath/index.d.ts +0 -12
  40. package/dist/index.cjs.js.map +0 -1
  41. package/dist/index.es.js.map +0 -1
  42. package/dist/index.umd.js.map +0 -1
  43. package/src/ContainerResizeObserver.ts +0 -73
  44. package/src/ScenePath/index.ts +0 -47
@@ -1,73 +0,0 @@
1
- import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
2
- import { isFunction } from "lodash";
3
- import { WindowManager } from "./index";
4
- import type { EmitterType } from "./InternalEmitter";
5
- import type { UnsubscribeFn } from "emittery";
6
-
7
- const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
8
-
9
- export class ContainerResizeObserver {
10
- private containerResizeObserver?: ResizeObserver;
11
- private disposer?: UnsubscribeFn;
12
-
13
- constructor(private emitter: EmitterType) {}
14
-
15
- public static create(
16
- container: HTMLElement,
17
- sizer: HTMLElement,
18
- wrapper: HTMLDivElement,
19
- emitter: EmitterType
20
- ) {
21
- const containerResizeObserver = new ContainerResizeObserver(emitter);
22
- containerResizeObserver.observePlaygroundSize(container, sizer, wrapper);
23
- return containerResizeObserver;
24
- }
25
-
26
- public observePlaygroundSize(
27
- container: HTMLElement,
28
- sizer: HTMLElement,
29
- wrapper: HTMLDivElement
30
- ) {
31
- this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
32
-
33
- this.containerResizeObserver = new ResizeObserver(entries => {
34
- const containerRect = entries[0]?.contentRect;
35
- if (containerRect) {
36
- this.updateSizer(containerRect, sizer, wrapper);
37
- this.emitter.emit("playgroundSizeChange", containerRect);
38
- }
39
- });
40
-
41
- this.disposer = this.emitter.on("containerSizeRatioUpdate", () => {
42
- this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
43
- });
44
-
45
- this.containerResizeObserver.observe(container);
46
- }
47
-
48
- public updateSizer(
49
- { width, height }: DOMRectReadOnly,
50
- sizer: HTMLElement,
51
- wrapper: HTMLDivElement
52
- ) {
53
- if (width && height) {
54
- if (height / width > WindowManager.containerSizeRatio) {
55
- height = width * WindowManager.containerSizeRatio;
56
- sizer.classList.toggle("netless-window-manager-sizer-horizontal", true);
57
- } else {
58
- width = height / WindowManager.containerSizeRatio;
59
- sizer.classList.toggle("netless-window-manager-sizer-horizontal", false);
60
- }
61
- wrapper.style.width = `${width}px`;
62
- wrapper.style.height = `${height}px`;
63
- }
64
- }
65
-
66
- public disconnect() {
67
- this.containerResizeObserver?.disconnect();
68
- if (isFunction(this.disposer)) {
69
- this.disposer();
70
- this.disposer = undefined;
71
- }
72
- }
73
- }
@@ -1,47 +0,0 @@
1
- import type { ScenesCallbacks, ScenesCallbacksNode } from "white-web-sdk";
2
- import type { AppManager } from "../AppManager";
3
-
4
- export class ScenesCallbackManager {
5
-
6
- private nodes: Map<string, ScenesCallbacksNode> = new Map();
7
-
8
- constructor(private manager: AppManager) {}
9
-
10
- public createNode(path: string, callbacks?: Partial<ScenesCallbacks>): ScenesCallbacksNode | null {
11
- const node = this.manager.displayer.createScenesCallback(path, callbacks);
12
- if (node) {
13
- this.nodes.set(path, node);
14
- }
15
- return node;
16
- }
17
-
18
- public getScenes(path: string) {
19
- const node = this.nodes.get(path);
20
- return node?.scenes;
21
- }
22
-
23
- public getScenesOnce(path: string) {
24
- let node = this.nodes.get(path);
25
- if (!node) {
26
- const created = this.createNode(path);
27
- if (created) {
28
- node = created;
29
- }
30
- }
31
- const scenes = node?.scenes;
32
- this.removeNode(path);
33
- return scenes;
34
- }
35
-
36
- public removeNode(path: string) {
37
- const node = this.nodes.get(path);
38
- if (node) {
39
- node.dispose();
40
- this.nodes.delete(path);
41
- }
42
- }
43
-
44
- public destroy(): void {
45
- this.nodes.forEach(node => node.dispose());
46
- }
47
- }