@netless/window-manager 1.0.0-canary.24 → 1.0.0-canary.27

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 (83) hide show
  1. package/dist/App/AppContext.d.ts +1 -1
  2. package/dist/App/WhiteboardView.d.ts +6 -4
  3. package/dist/AppListener.d.ts +0 -2
  4. package/dist/BoxManager.d.ts +2 -1
  5. package/dist/BuiltinApps.d.ts +3 -0
  6. package/dist/Cursor/index.d.ts +3 -2
  7. package/dist/Helper.d.ts +3 -1
  8. package/dist/callback.d.ts +5 -0
  9. package/dist/constants.d.ts +0 -2
  10. package/dist/index.cjs.js +82 -12
  11. package/dist/index.d.ts +16 -9
  12. package/dist/index.es.js +1620 -704
  13. package/dist/index.umd.js +82 -12
  14. package/dist/src/App/AppContext.d.ts +78 -0
  15. package/dist/src/App/AppPageStateImpl.d.ts +21 -0
  16. package/dist/src/App/AppProxy.d.ts +98 -0
  17. package/dist/src/App/MagixEvent/index.d.ts +29 -0
  18. package/dist/src/App/Storage/StorageEvent.d.ts +8 -0
  19. package/dist/src/App/Storage/index.d.ts +39 -0
  20. package/dist/src/App/Storage/typings.d.ts +22 -0
  21. package/dist/src/App/Storage/utils.d.ts +5 -0
  22. package/dist/src/App/WhiteboardView.d.ts +27 -0
  23. package/dist/src/App/index.d.ts +4 -0
  24. package/dist/src/App/type.d.ts +21 -0
  25. package/dist/src/AppListener.d.ts +19 -0
  26. package/dist/src/AppManager.d.ts +107 -0
  27. package/dist/src/AttributesDelegate.d.ts +83 -0
  28. package/dist/src/BoxEmitter.d.ts +34 -0
  29. package/dist/src/BoxManager.d.ts +102 -0
  30. package/dist/src/BuiltinApps.d.ts +8 -0
  31. package/dist/src/Cursor/Cursor.d.ts +39 -0
  32. package/dist/src/Cursor/icons.d.ts +3 -0
  33. package/dist/src/Cursor/index.d.ts +46 -0
  34. package/dist/src/Helper.d.ts +19 -0
  35. package/dist/src/InternalEmitter.d.ts +38 -0
  36. package/dist/src/Page/PageController.d.ts +21 -0
  37. package/dist/src/Page/index.d.ts +3 -0
  38. package/dist/src/PageState.d.ts +9 -0
  39. package/dist/src/ReconnectRefresher.d.ts +24 -0
  40. package/dist/src/RedoUndo.d.ts +18 -0
  41. package/dist/src/Register/index.d.ts +28 -0
  42. package/dist/src/Register/loader.d.ts +4 -0
  43. package/dist/src/Register/storage.d.ts +8 -0
  44. package/dist/src/Utils/AppCreateQueue.d.ts +15 -0
  45. package/dist/src/Utils/Common.d.ts +23 -0
  46. package/dist/src/Utils/Reactive.d.ts +6 -0
  47. package/dist/src/Utils/RoomHacker.d.ts +3 -0
  48. package/dist/src/Utils/error.d.ts +27 -0
  49. package/dist/src/Utils/log.d.ts +1 -0
  50. package/dist/src/View/CameraSynchronizer.d.ts +17 -0
  51. package/dist/src/View/MainView.d.ts +59 -0
  52. package/dist/src/View/ViewManager.d.ts +13 -0
  53. package/dist/src/View/ViewSync.d.ts +24 -0
  54. package/dist/src/callback.d.ts +29 -0
  55. package/dist/src/constants.d.ts +51 -0
  56. package/dist/src/image.d.ts +19 -0
  57. package/dist/src/index.d.ts +267 -0
  58. package/dist/src/shim.d.ts +11 -0
  59. package/dist/src/typings.d.ts +88 -0
  60. package/dist/style.css +1 -1
  61. package/dist/typings.d.ts +6 -0
  62. package/docs/app-context.md +68 -26
  63. package/package.json +10 -5
  64. package/playwright.config.ts +28 -0
  65. package/pnpm-lock.yaml +516 -30
  66. package/src/App/AppContext.ts +14 -6
  67. package/src/App/AppProxy.ts +17 -7
  68. package/src/App/WhiteboardView.ts +23 -18
  69. package/src/AppListener.ts +1 -21
  70. package/src/AppManager.ts +2 -1
  71. package/src/BoxManager.ts +32 -24
  72. package/src/BuiltinApps.ts +5 -0
  73. package/src/Cursor/Cursor.ts +6 -2
  74. package/src/Cursor/index.ts +5 -5
  75. package/src/Helper.ts +23 -5
  76. package/src/View/CameraSynchronizer.ts +5 -9
  77. package/src/View/MainView.ts +3 -1
  78. package/src/callback.ts +1 -0
  79. package/src/constants.ts +0 -2
  80. package/src/index.ts +69 -45
  81. package/src/style.css +2 -45
  82. package/src/typings.ts +6 -0
  83. package/vite.config.js +5 -3
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ import pRetry from "p-retry";
2
2
  import { AppManager } from "./AppManager";
3
3
  import { appRegister } from "./Register";
4
4
  import { callbacks } from "./callback";
5
- import { checkVersion, setupWrapper } from "./Helper";
5
+ import { checkVersion, createInvisiblePlugin, setupWrapper } from "./Helper";
6
6
  import { createBoxManager } from "./BoxManager";
7
7
  import { CursorManager } from "./Cursor";
8
8
  import { DEFAULT_CONTAINER_RATIO, Events, INIT_DIR, ROOT_DIR } from "./constants";
@@ -10,7 +10,7 @@ import { emitter } from "./InternalEmitter";
10
10
  import { Fields } from "./AttributesDelegate";
11
11
  import { initDb } from "./Register/storage";
12
12
  import { InvisiblePlugin, isPlayer, isRoom, RoomPhase, ViewMode } from "white-web-sdk";
13
- import { isEqual, isNull, isObject, omit, isNumber } from "lodash";
13
+ import { isEqual, isNull, isObject, isNumber } from "lodash";
14
14
  import { log } from "./Utils/log";
15
15
  import { PageStateImpl } from "./PageState";
16
16
  import { ReconnectRefresher } from "./ReconnectRefresher";
@@ -27,6 +27,8 @@ import {
27
27
  putScenes,
28
28
  wait,
29
29
  } from "./Utils/Common";
30
+ import { boxEmitter } from "./BoxEmitter";
31
+ import { Val } from "value-enhancer";
30
32
  import type { TELE_BOX_STATE, BoxManager } from "./BoxManager";
31
33
  import * as Errors from "./Utils/error";
32
34
  import type { Apps, Position , ICamera, ISize } from "./AttributesDelegate";
@@ -37,15 +39,13 @@ import type {
37
39
  Room,
38
40
  InvisiblePluginContext,
39
41
  Camera,
40
- AnimationMode,
41
42
  CameraBound,
42
43
  Point,
43
- Rectangle,
44
44
  CameraState,
45
45
  Player,
46
46
  ImageInformation,
47
47
  SceneState,
48
- } from "white-web-sdk";
48
+ Rectangle} from "white-web-sdk";
49
49
  import type { AppListeners } from "./AppListener";
50
50
  import type { ApplianceIcons, NetlessApp, RegisterParams } from "./typings";
51
51
  import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
@@ -53,8 +53,6 @@ import type { AppProxy } from "./App";
53
53
  import type { PublicEvent } from "./callback";
54
54
  import type Emittery from "emittery";
55
55
  import type { PageController, AddPageParams, PageState } from "./Page";
56
- import { boxEmitter } from "./BoxEmitter";
57
- import { Val } from "value-enhancer";
58
56
 
59
57
  export type WindowMangerAttributes = {
60
58
  modelValue?: string;
@@ -142,6 +140,8 @@ export type MountParams = {
142
140
  collectorContainer?: HTMLElement;
143
141
  collectorStyles?: Partial<CSSStyleDeclaration>;
144
142
  overwriteStyles?: string;
143
+ containerStyle?: string;
144
+ stageStyle?: string;
145
145
  cursor?: boolean;
146
146
  debug?: boolean;
147
147
  disableCameraTransform?: boolean;
@@ -249,7 +249,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
249
249
  collectorStyles: params.collectorStyles,
250
250
  prefersColorScheme: params.prefersColorScheme,
251
251
  stageRatio: WindowManager.containerSizeRatio,
252
- highlightStage: params.highlightStage
252
+ containerStyle: params.containerStyle,
253
+ stageStyle: params.stageStyle,
253
254
  });
254
255
  manager.appManager?.setBoxManager(manager.boxManager);
255
256
  if (params.container) {
@@ -268,8 +269,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
268
269
  return manager;
269
270
  }
270
271
 
271
- private static async initManager(room: Room): Promise<WindowManager> {
272
- let manager = room.getInvisiblePlugin(WindowManager.kind) as WindowManager;
272
+ private static async initManager(room: Room): Promise<WindowManager | undefined> {
273
+ let manager = room.getInvisiblePlugin(WindowManager.kind) as WindowManager | undefined;
273
274
  if (!manager) {
274
275
  if (isRoom(room)) {
275
276
  if (room.isWritable === false) {
@@ -278,18 +279,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
278
279
  } catch (error) {
279
280
  throw new Error("[WindowManger]: room must be switched to be writable");
280
281
  }
281
- manager = (await room.createInvisiblePlugin(
282
- WindowManager,
283
- {}
284
- )) as WindowManager;
285
- manager.ensureAttributes();
282
+ manager = await createInvisiblePlugin(room);
283
+ manager?.ensureAttributes();
286
284
  await wait(500);
287
285
  await room.setWritable(false);
288
286
  } else {
289
- manager = (await room.createInvisiblePlugin(
290
- WindowManager,
291
- {}
292
- )) as WindowManager;
287
+ manager = await createInvisiblePlugin(room);
293
288
  }
294
289
  }
295
290
  }
@@ -298,12 +293,13 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
298
293
 
299
294
  private static initContainer(
300
295
  container: HTMLElement,
296
+ target: HTMLElement,
301
297
  overwriteStyles: string | undefined
302
298
  ) {
303
299
  if (!WindowManager.container) {
304
300
  WindowManager.container = container;
305
301
  }
306
- const { playground, mainViewElement } = setupWrapper(container);
302
+ const { playground, mainViewElement } = setupWrapper(container, target);
307
303
  WindowManager.playground = playground;
308
304
  if (overwriteStyles) {
309
305
  const style = document.createElement("style");
@@ -326,10 +322,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
326
322
  container.appendChild(WindowManager.container.firstChild);
327
323
  }
328
324
  } else {
329
- if (WindowManager.params) {
325
+ const teleboxContainer = this.boxManager?.teleBoxManager.$stage;
326
+ if (WindowManager.params && teleboxContainer) {
330
327
  const params = WindowManager.params;
331
328
  const mainViewElement = WindowManager.initContainer(
332
329
  container,
330
+ teleboxContainer,
333
331
  params.overwriteStyles
334
332
  );
335
333
  if (this.boxManager && WindowManager.playground) {
@@ -339,6 +337,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
339
337
  if (WindowManager.playground) {
340
338
  this.cursorManager?.setupWrapper(WindowManager.playground);
341
339
  }
340
+
342
341
  }
343
342
  }
344
343
  emitter.emit("updateManagerRect");
@@ -661,6 +660,22 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
661
660
  }
662
661
  }
663
662
 
663
+ public get baseCamera$() {
664
+ if (this.appManager) {
665
+ return this.appManager.mainViewProxy.camera$;
666
+ } else {
667
+ throw new Errors.AppManagerNotInitError();
668
+ }
669
+ }
670
+
671
+ public get baseSize$() {
672
+ if (this.appManager) {
673
+ return this.appManager.mainViewProxy.size$;
674
+ } else {
675
+ throw new Errors.AppManagerNotInitError();
676
+ }
677
+ }
678
+
664
679
  public get cameraState(): CameraState {
665
680
  if (this.appManager) {
666
681
  return this.appManager.mainViewProxy.cameraState;
@@ -767,30 +782,31 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
767
782
  return this.appManager?.closeApp(appId);
768
783
  }
769
784
 
770
- public moveCamera(
771
- camera: Partial<Camera> & { animationMode?: AnimationMode | undefined }
772
- ): void {
773
- const pureCamera = omit(camera, ["animationMode"]);
785
+ public moveCamera(camera: Partial<Camera> ): void {
774
786
  const mainViewCamera = { ...this.mainView.camera };
775
- if (isEqual({ ...mainViewCamera, ...pureCamera }, mainViewCamera)) return;
776
- this.mainView.moveCamera(camera);
777
- this.appManager?.dispatchInternalEvent(Events.MoveCamera, camera);
778
- setTimeout(() => {
779
- this.appManager?.mainViewProxy.storeCurrentCamera();
780
- }, 500);
781
- }
782
-
783
- public moveCameraToContain(
784
- rectangle: Rectangle &
785
- Readonly<{
786
- animationMode?: AnimationMode;
787
- }>
788
- ): void {
789
- this.mainView.moveCameraToContain(rectangle);
790
- this.appManager?.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
791
- setTimeout(() => {
792
- this.appManager?.mainViewProxy.storeCurrentCamera();
793
- }, 500);
787
+ const nextCamera = { ...mainViewCamera, ...camera };
788
+ if (isEqual(nextCamera, mainViewCamera)) return;
789
+ if (!this.appManager) return;
790
+ this.appManager.mainViewProxy.storeCamera({
791
+ id: this.appManager.uid,
792
+ ...nextCamera
793
+ });
794
+ }
795
+
796
+ public moveCameraToContain(rectangle: Rectangle): void {
797
+ if (!this.appManager) return;
798
+ const mainViewSize = this.appManager.mainViewProxy.size$.value;
799
+ if (mainViewSize) {
800
+ const wScale = mainViewSize.width / rectangle.width;
801
+ const hScale = mainViewSize.height / rectangle.height;
802
+ const nextScale = Math.min(wScale, hScale);
803
+ this.appManager.mainViewProxy.storeCamera({
804
+ id: this.appManager.uid,
805
+ scale: nextScale,
806
+ centerX: rectangle.originX,
807
+ centerY: rectangle.originY,
808
+ });
809
+ }
794
810
  }
795
811
 
796
812
  public convertToPointInWorld(point: Point): Point {
@@ -930,6 +946,14 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
930
946
  emitter.emit("containerSizeRatioUpdate", ratio);
931
947
  }
932
948
 
949
+ public setContainerStyle(style: string) {
950
+ this.boxManager?.teleBoxManager.setContainerStyle(style);
951
+ }
952
+
953
+ public setStageStyle(style: string) {
954
+ this.boxManager?.teleBoxManager.setStageStyle(style);
955
+ }
956
+
933
957
  public createPPTHandler() {
934
958
  return {
935
959
  onPageJumpTo: (_pptUUID: string, index: number) => {
@@ -981,5 +1005,5 @@ setupBuiltin();
981
1005
 
982
1006
  export * from "./typings";
983
1007
 
984
- export { BuiltinApps } from "./BuiltinApps";
1008
+ export { BuiltinApps, BuiltinAppsMap } from "./BuiltinApps";
985
1009
  export type { PublicEvent } from "./callback";
package/src/style.css CHANGED
@@ -7,48 +7,9 @@
7
7
  user-select: none;
8
8
  }
9
9
 
10
- .netless-window-manager-sizer {
11
- position: absolute;
12
- top: 0;
13
- left: 0;
14
- width: 100%;
15
- height: 100%;
16
- z-index: 1;
17
- overflow: hidden;
18
- display: flex;
19
- }
20
-
21
- .netless-window-manager-sizer-horizontal {
22
- flex-direction: column;
23
- }
24
-
25
- .netless-window-manager-sizer::before,
26
- .netless-window-manager-sizer::after {
27
- flex: 1;
28
- content: "";
29
- display: block;
30
- }
31
-
32
- .netless-window-manager-chess-sizer::before,
33
- .netless-window-manager-chess-sizer::after {
34
- background-image: linear-gradient(45deg, #b0b0b0 25%, transparent 25%),
35
- linear-gradient(-45deg, #b0b0b0 25%, transparent 25%),
36
- linear-gradient(45deg, transparent 75%, #b0b0b0 75%),
37
- linear-gradient(-45deg, transparent 75%, #b0b0b0 75%);
38
- background-color: #fff;
39
- background-size: 20px 20px;
40
- background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
41
- }
42
-
43
- .netless-window-manager-wrapper {
44
- position: relative;
45
- z-index: 1;
46
- width: 100%;
47
- height: 100%;
48
- overflow: hidden;
49
- }
50
10
 
51
11
  .netless-window-manager-main-view {
12
+ position: absolute;
52
13
  width: 100%;
53
14
  height: 100%;
54
15
  }
@@ -180,10 +141,6 @@
180
141
  }
181
142
 
182
143
  .window-manager-view-wrapper {
183
- width: 100%;
184
- height: 100%;
185
144
  position: absolute;
186
- left: 0;
187
- top: 0;
188
- z-index: 1;
145
+ z-index: 10;
189
146
  }
package/src/typings.ts CHANGED
@@ -30,6 +30,9 @@ export interface NetlessApp<Attributes = any, MagixEventPayloads = any, AppOptio
30
30
 
31
31
  /** App only single instance. */
32
32
  singleton?: boolean;
33
+
34
+ /** App box enableShadowDom. Default true */
35
+ enableShadowDOM?: boolean;
33
36
  };
34
37
  setup: (context: AppContext<Attributes, MagixEventPayloads, AppOptions>) => SetupResult;
35
38
  }
@@ -74,12 +77,15 @@ export type RegisterParams<AppOptions = any, SetupResult = any, Attributes = any
74
77
  addHooks?: (emitter: Emittery<RegisterEvents<SetupResult>>) => void;
75
78
  /** dynamic load app package name */
76
79
  name?: string;
80
+ contentStyles?: string;
77
81
  };
78
82
 
79
83
  export type AppListenerKeys = keyof AppEmitterEvent;
80
84
 
81
85
  export type ApplianceIcons = Partial<Record<ApplianceNames, string>>;
82
86
 
87
+ export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
88
+
83
89
  export type { AppContext } from "./App/AppContext";
84
90
  export type { WhiteBoardView } from "./App";
85
91
  export type { ReadonlyTeleBox, TeleBoxRect };
package/vite.config.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import path from "path";
2
+ import dts from 'vite-plugin-dts'
2
3
  import { defineConfig } from 'vitest/config'
3
4
  import { svelte } from "@sveltejs/vite-plugin-svelte";
4
5
  import { dependencies, peerDependencies, version, devDependencies } from "./package.json"
@@ -28,7 +29,8 @@ export default defineConfig(({ mode }) => {
28
29
  experimental: {
29
30
  useVitePreprocess: true,
30
31
  },
31
- })
32
+ }),
33
+ dts()
32
34
  ],
33
35
  build: {
34
36
  lib: {
@@ -45,7 +47,7 @@ export default defineConfig(({ mode }) => {
45
47
  ...peerDependencies,
46
48
  }),
47
49
  },
48
- minify: isProd,
50
+ minify: isProd
49
51
  },
50
52
  };
51
- });
53
+ })