@netless/window-manager 1.0.0-canary.34 → 1.0.0-canary.37

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/src/callback.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import Emittery from "emittery";
2
2
  import type { TeleBoxColorScheme, TELE_BOX_STATE } from "@netless/telebox-insider";
3
- import type { CameraState, SceneState, ViewVisionMode } from "white-web-sdk";
3
+ import type { Camera, CameraState, SceneState, Size, ViewVisionMode } from "white-web-sdk";
4
4
  import type { LoadAppEvent } from "./Register";
5
5
  import type { PageState } from "./Page";
6
+ import { ICamera, ISize } from "./AttributesDelegate";
6
7
 
7
8
  export type PublicEvent = {
8
9
  mainViewModeChange: ViewVisionMode;
@@ -21,6 +22,8 @@ export type PublicEvent = {
21
22
  sceneStateChange: SceneState;
22
23
  pageStateChange: PageState;
23
24
  appClose: { appId: string; kind: string, error?: Error };
25
+ baseCameraChange: ICamera;
26
+ baseSizeChange: ISize;
24
27
  };
25
28
 
26
29
  export type CallbacksType = Emittery<PublicEvent>;
package/src/constants.ts CHANGED
@@ -15,6 +15,8 @@ export enum Events {
15
15
  Refresh = "Refresh",
16
16
  InitMainViewCamera = "InitMainViewCamera",
17
17
  InvokeAttributesUpdateCallback = "InvokeAttributesUpdateCallback",
18
+ MoveCamera = "MoveCamera",
19
+ MoveCameraToContain = "moveCameraToContain",
18
20
  }
19
21
 
20
22
  export const MagixEventName = "__WindowManger";
package/src/index.ts CHANGED
@@ -9,14 +9,13 @@ import { DEFAULT_CONTAINER_RATIO, Events, INIT_DIR, ROOT_DIR } from "./constants
9
9
  import { emitter } from "./InternalEmitter";
10
10
  import { Fields } from "./AttributesDelegate";
11
11
  import { initDb } from "./Register/storage";
12
- import { InvisiblePlugin, isPlayer, isRoom, RoomPhase, ViewMode } from "white-web-sdk";
13
- import { isEqual, isNull, isObject, isNumber } from "lodash";
12
+ import { AnimationMode, InvisiblePlugin, isPlayer, isRoom, RoomPhase, ViewMode } from "white-web-sdk";
13
+ import { isEqual, isNull, isObject, isNumber, isEmpty } from "lodash";
14
14
  import { log } from "./Utils/log";
15
15
  import { PageStateImpl } from "./PageState";
16
16
  import { ReconnectRefresher } from "./ReconnectRefresher";
17
17
  import { replaceRoomFunction } from "./Utils/RoomHacker";
18
18
  import { setupBuiltin } from "./BuiltinApps";
19
- import "video.js/dist/video-js.css";
20
19
  import "./style.css";
21
20
  import "@netless/telebox-insider/dist/style.css";
22
21
  import {
@@ -45,14 +44,17 @@ import type {
45
44
  Player,
46
45
  ImageInformation,
47
46
  SceneState,
48
- Rectangle} from "white-web-sdk";
47
+ Rectangle,
48
+ Size
49
+ } from "white-web-sdk";
49
50
  import type { AppListeners } from "./AppListener";
50
51
  import type { ApplianceIcons, NetlessApp, RegisterParams } from "./typings";
51
- import type { TeleBoxColorScheme, TeleBoxFullscreen, TeleBoxState } from "@netless/telebox-insider";
52
+ import type { TeleBoxColorScheme, TeleBoxFullscreen, TeleBoxManagerThemeConfig, TeleBoxState } from "@netless/telebox-insider";
52
53
  import type { AppProxy } from "./App";
53
54
  import type { PublicEvent } from "./callback";
54
55
  import type Emittery from "emittery";
55
56
  import type { PageController, AddPageParams, PageState } from "./Page";
57
+ import { computedMinScale } from "./View/CameraSynchronizer";
56
58
 
57
59
  export type WindowMangerAttributes = {
58
60
  modelValue?: string;
@@ -147,6 +149,12 @@ export type MountParams = {
147
149
  prefersColorScheme?: TeleBoxColorScheme;
148
150
  applianceIcons?: ApplianceIcons;
149
151
  fullscreen?: TeleBoxFullscreen;
152
+ /** Custom `style` attribute value for content area of all boxes. Can be overwritten by box. */
153
+ defaultBoxBodyStyle?: string | null;
154
+ /** Custom `style` attribute value for stage area of all boxes. Can be overwritten by box. */
155
+ defaultBoxStageStyle?: string | null;
156
+ /** Theme variable */
157
+ theme?: TeleBoxManagerThemeConfig;
150
158
  };
151
159
 
152
160
  export const reconnectRefresher = new ReconnectRefresher({ emitter });
@@ -791,30 +799,86 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
791
799
  return this.appManager?.closeApp(appId);
792
800
  }
793
801
 
794
- public moveCamera(camera: Partial<Camera> ): void {
802
+ public moveCamera(camera: Partial<Camera> & { animationMode?: AnimationMode } ): void {
795
803
  const mainViewCamera = { ...this.mainView.camera };
796
804
  const nextCamera = { ...mainViewCamera, ...camera };
797
805
  if (isEqual(nextCamera, mainViewCamera)) return;
798
806
  if (!this.appManager) return;
799
- this.appManager.mainViewProxy.storeCamera({
800
- id: this.appManager.uid,
801
- ...nextCamera
802
- });
807
+ if (camera.animationMode === AnimationMode.Immediately) {
808
+ this.appManager.mainViewProxy.storeCamera({
809
+ id: this.appManager.uid,
810
+ ...nextCamera
811
+ });
812
+ } else {
813
+ const remoteCamera = this.appManager.mainViewProxy.size$.value;
814
+ const currentSize = this.boxManager?.stageRect;
815
+ let nextScale;
816
+ if (camera.scale && remoteCamera && currentSize) {
817
+ nextScale = camera.scale * computedMinScale(remoteCamera, currentSize);
818
+ }
819
+ if (nextScale) {
820
+ this.mainView.moveCamera({
821
+ ...camera,
822
+ scale: nextScale,
823
+ });
824
+ } else {
825
+ this.mainView.moveCamera(camera);
826
+ }
827
+ this.appManager.dispatchInternalEvent(Events.MoveCamera, camera);
828
+ setTimeout(() => {
829
+ if (!this.appManager) return;
830
+ this.appManager.mainViewProxy.storeCamera({
831
+ id: this.appManager.uid,
832
+ ...nextCamera
833
+ });
834
+ }, 200);
835
+ }
803
836
  }
804
837
 
805
- public moveCameraToContain(rectangle: Rectangle): void {
838
+ public moveCameraToContain(rectangle: Rectangle & { animationMode?: AnimationMode }): void {
806
839
  if (!this.appManager) return;
807
- const mainViewSize = this.appManager.mainViewProxy.size$.value;
808
- if (mainViewSize) {
809
- const wScale = mainViewSize.width / rectangle.width;
810
- const hScale = mainViewSize.height / rectangle.height;
811
- const nextScale = Math.min(wScale, hScale);
812
- this.appManager.mainViewProxy.storeCamera({
840
+ const camera: Partial<Camera> = {};
841
+ if (isNumber(rectangle.originX)) {
842
+ camera.centerX = rectangle.originX;
843
+ }
844
+ if (isNumber(rectangle.originY)) {
845
+ camera.centerY = rectangle.originY;
846
+ }
847
+ if (rectangle.animationMode === AnimationMode.Immediately) {
848
+ this.appManager.mainViewProxy.storeSize({
813
849
  id: this.appManager.uid,
814
- scale: nextScale,
815
- centerX: rectangle.originX,
816
- centerY: rectangle.originY,
850
+ width: rectangle.width,
851
+ height: rectangle.height,
817
852
  });
853
+ this.mainView.moveCameraToContain(rectangle);
854
+ if (!isEmpty(camera) && this.appManager.mainViewProxy.camera$.value) {
855
+ this.appManager.mainViewProxy.storeCamera({
856
+ ...this.appManager.mainViewProxy.camera$.value,
857
+ id: this.appManager.uid,
858
+ centerX: this.mainView.camera.centerX,
859
+ centerY: this.mainView.camera.centerY
860
+ });
861
+ }
862
+ } else {
863
+ this.appManager.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
864
+ this.mainView.moveCameraToContain(rectangle);
865
+ setTimeout(() => {
866
+ if (!this.appManager) return;
867
+ this.appManager.mainViewProxy.storeSize({
868
+ id: this.appManager.uid,
869
+ width: rectangle.width,
870
+ height: rectangle.height,
871
+ });
872
+
873
+ if (!isEmpty(camera) && this.appManager.mainViewProxy.camera$.value) {
874
+ this.appManager.mainViewProxy.storeCamera({
875
+ ...this.appManager.mainViewProxy.camera$.value,
876
+ id: this.appManager.uid,
877
+ centerX: this.mainView.camera.centerX,
878
+ centerY: this.mainView.camera.centerY
879
+ });
880
+ }
881
+ }, 200);
818
882
  }
819
883
  }
820
884
 
@@ -967,6 +1031,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
967
1031
  this.boxManager?.teleBoxManager.setStageStyle(style);
968
1032
  }
969
1033
 
1034
+ public setBaseSize(size: Size) {
1035
+ this.appManager?.mainViewProxy.setMainViewSize(size);
1036
+ }
1037
+
970
1038
  public createPPTHandler() {
971
1039
  return {
972
1040
  onPageJumpTo: (_pptUUID: string, index: number) => {