@netless/window-manager 0.4.0-canary.1 → 0.4.0-canary.13

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 (64) hide show
  1. package/dist/App/MagixEvent/index.d.ts +29 -0
  2. package/dist/App/Storage/StorageEvent.d.ts +8 -0
  3. package/dist/App/Storage/index.d.ts +38 -0
  4. package/dist/App/Storage/typings.d.ts +21 -0
  5. package/dist/App/Storage/utils.d.ts +5 -0
  6. package/dist/AppContext.d.ts +40 -16
  7. package/dist/AppListener.d.ts +0 -1
  8. package/dist/AppManager.d.ts +8 -7
  9. package/dist/AppProxy.d.ts +3 -3
  10. package/dist/Base/Context.d.ts +0 -1
  11. package/dist/BoxManager.d.ts +1 -0
  12. package/dist/BuiltinApps.d.ts +6 -0
  13. package/dist/ContainerResizeObserver.d.ts +10 -0
  14. package/dist/Cursor/Cursor.d.ts +2 -3
  15. package/dist/Cursor/index.d.ts +7 -4
  16. package/dist/Helper.d.ts +6 -0
  17. package/dist/ReconnectRefresher.d.ts +5 -2
  18. package/dist/Utils/Common.d.ts +3 -1
  19. package/dist/Utils/Reactive.d.ts +1 -1
  20. package/dist/{MainView.d.ts → View/MainView.d.ts} +2 -4
  21. package/dist/View/ViewManager.d.ts +13 -0
  22. package/dist/constants.d.ts +1 -6
  23. package/dist/index.d.ts +14 -13
  24. package/dist/index.es.js +1 -1
  25. package/dist/index.es.js.map +1 -1
  26. package/dist/index.umd.js +1 -1
  27. package/dist/index.umd.js.map +1 -1
  28. package/dist/style.css +1 -1
  29. package/dist/typings.d.ts +3 -2
  30. package/package.json +6 -5
  31. package/src/App/MagixEvent/index.ts +68 -0
  32. package/src/App/Storage/StorageEvent.ts +21 -0
  33. package/src/App/Storage/index.ts +284 -0
  34. package/src/App/Storage/typings.ts +21 -0
  35. package/src/App/Storage/utils.ts +17 -0
  36. package/src/AppContext.ts +65 -20
  37. package/src/AppListener.ts +1 -8
  38. package/src/AppManager.ts +68 -35
  39. package/src/AppProxy.ts +37 -46
  40. package/src/Base/Context.ts +0 -4
  41. package/src/BoxManager.ts +9 -7
  42. package/src/BuiltinApps.ts +24 -0
  43. package/src/ContainerResizeObserver.ts +62 -0
  44. package/src/Cursor/Cursor.ts +23 -34
  45. package/src/Cursor/index.ts +70 -41
  46. package/src/Helper.ts +30 -0
  47. package/src/ReconnectRefresher.ts +13 -5
  48. package/src/Utils/Common.ts +35 -13
  49. package/src/Utils/Reactive.ts +9 -3
  50. package/src/Utils/RoomHacker.ts +16 -0
  51. package/src/{MainView.ts → View/MainView.ts} +9 -25
  52. package/src/View/ViewManager.ts +53 -0
  53. package/src/constants.ts +1 -3
  54. package/src/index.ts +47 -86
  55. package/src/shim.d.ts +4 -0
  56. package/src/style.css +6 -0
  57. package/src/typings.ts +3 -2
  58. package/vite.config.js +4 -1
  59. package/dist/Utils/CameraStore.d.ts +0 -15
  60. package/dist/ViewManager.d.ts +0 -29
  61. package/dist/sdk.d.ts +0 -14
  62. package/src/Utils/CameraStore.ts +0 -72
  63. package/src/sdk.ts +0 -39
  64. package/src/viewManager.ts +0 -177
@@ -1,17 +1,16 @@
1
- import { AnimationMode, reaction, ViewVisionMode } from "white-web-sdk";
2
- import { Base } from "./Base";
3
- import { callbacks, emitter } from "./index";
1
+ import { AnimationMode, reaction } from "white-web-sdk";
2
+ import { Base } from "../Base";
3
+ import { callbacks, emitter } from "../index";
4
4
  import { createView } from "./ViewManager";
5
5
  import { debounce, isEmpty, isEqual } from "lodash";
6
- import { Fields } from "./AttributesDelegate";
7
- import { notifyMainViewModeChange, setViewFocusScenePath, setViewMode } from "./Utils/Common";
6
+ import { Fields } from "../AttributesDelegate";
7
+ import { setViewFocusScenePath } from "../Utils/Common";
8
8
  import { SideEffectManager } from "side-effect-manager";
9
9
  import type { Camera, Size, View } from "white-web-sdk";
10
- import type { AppManager } from "./AppManager";
10
+ import type { AppManager } from "../AppManager";
11
11
 
12
12
  export class MainViewProxy extends Base {
13
13
  private scale?: number;
14
- private cameraStore = this.manager.cameraStore;
15
14
  private started = false;
16
15
  private mainViewIsAddListener = false;
17
16
  private mainView: View;
@@ -23,8 +22,8 @@ export class MainViewProxy extends Base {
23
22
  super(manager);
24
23
  this.mainView = this.createMainView();
25
24
  this.moveCameraSizeByAttributes();
26
- this.cameraStore.register(this.viewId, this.mainView);
27
25
  emitter.once("mainViewMounted").then(() => {
26
+ this.addMainViewListener();
28
27
  setTimeout(() => {
29
28
  this.start();
30
29
  if (!this.mainViewCamera || !this.mainViewSize) {
@@ -34,7 +33,7 @@ export class MainViewProxy extends Base {
34
33
  });
35
34
  const playgroundSizeChangeListener = () => {
36
35
  this.sizeChangeHandler(this.mainViewSize);
37
- }
36
+ };
38
37
  this.sideEffectManager.add(() => {
39
38
  emitter.on("playgroundSizeChange", playgroundSizeChangeListener);
40
39
  return () => emitter.off("playgroundSizeChange", playgroundSizeChangeListener);
@@ -103,9 +102,6 @@ export class MainViewProxy extends Base {
103
102
  if (mainViewScenePath) {
104
103
  setViewFocusScenePath(mainView, mainViewScenePath);
105
104
  }
106
- if (!this.store.focus) {
107
- this.switchViewModeToWriter();
108
- }
109
105
  return mainView;
110
106
  }
111
107
 
@@ -138,7 +134,6 @@ export class MainViewProxy extends Base {
138
134
 
139
135
  public async mainViewClickHandler(): Promise<void> {
140
136
  if (!this.manager.canOperate) return;
141
- if (this.view.mode === ViewVisionMode.Writable) return;
142
137
  this.store.cleanFocus();
143
138
  this.context.blurFocusBox();
144
139
  }
@@ -163,17 +158,6 @@ export class MainViewProxy extends Base {
163
158
  callbacks.emit("cameraStateChange", this.cameraState);
164
159
  };
165
160
 
166
- public switchViewModeToWriter(): void {
167
- if (!this.manager.canOperate) return;
168
- if (this.view) {
169
- if (this.view.mode === ViewVisionMode.Writable) return;
170
- this.cameraStore.switchView(this.viewId, this.mainView, () => {
171
- notifyMainViewModeChange(callbacks, ViewVisionMode.Writable);
172
- setViewMode(this.view, ViewVisionMode.Writable);
173
- });
174
- }
175
- }
176
-
177
161
  public moveCameraToContian(size: Size): void {
178
162
  if (!isEmpty(size)) {
179
163
  this.view.moveCameraToContain({
@@ -202,6 +186,7 @@ export class MainViewProxy extends Base {
202
186
  }
203
187
 
204
188
  public stop() {
189
+ this.removeMainViewListener();
205
190
  this.removeCameraListener();
206
191
  this.manager.refresher?.remove(Fields.MainViewCamera);
207
192
  this.manager.refresher?.remove(Fields.MainViewSize);
@@ -210,7 +195,6 @@ export class MainViewProxy extends Base {
210
195
 
211
196
  public destroy() {
212
197
  this.stop();
213
- this.cameraStore.unregister(this.viewId, this.mainView);
214
198
  this.sideEffectManager.flushAll();
215
199
  }
216
200
  }
@@ -0,0 +1,53 @@
1
+ import type { View , Displayer} from "white-web-sdk";
2
+
3
+ export class ViewManager {
4
+ public views: Map<string, View> = new Map();
5
+
6
+ constructor(private displayer: Displayer) {}
7
+
8
+ public createView(id: string): View {
9
+ const view = createView(this.displayer);
10
+ this.views.set(id, view);
11
+ return view;
12
+ }
13
+
14
+ public getView(id: string): View | undefined {
15
+ return this.views.get(id);
16
+ }
17
+
18
+ public destroyView(id: string): void {
19
+ const view = this.views.get(id);
20
+ if (view) {
21
+ view.release();
22
+ this.views.delete(id);
23
+ }
24
+ }
25
+
26
+ public setViewScenePath(id: string, scenePath: string): void {
27
+ const view = this.views.get(id);
28
+ if (view) {
29
+ view.focusScenePath = scenePath;
30
+ }
31
+ }
32
+
33
+ public destroy() {
34
+ this.views.forEach(view => {
35
+ view.release();
36
+ });
37
+ this.views.clear();
38
+ }
39
+ }
40
+
41
+
42
+ export const createView = (displayer: Displayer): View => {
43
+ const view = displayer.views.createView();
44
+ setDefaultCameraBound(view);
45
+ return view;
46
+ };
47
+
48
+ export const setDefaultCameraBound = (view: View) => {
49
+ view.setCameraBound({
50
+ maxContentMode: () => 10,
51
+ minContentMode: () => 0.1,
52
+ });
53
+ };
package/src/constants.ts CHANGED
@@ -37,13 +37,11 @@ export enum CursorState {
37
37
  Normal = "normal",
38
38
  }
39
39
 
40
- export const REQUIRE_VERSION = "2.13.16";
40
+ export const REQUIRE_VERSION = "2.16.0";
41
41
 
42
42
  export const MIN_WIDTH = 340 / 720;
43
43
  export const MIN_HEIGHT = 340 / 720;
44
44
 
45
45
  export const SET_SCENEPATH_DELAY = 100; // 设置 scenePath 的延迟事件
46
46
 
47
- export const DEFAULT_COLLECTOR_STYLE = { right: "10px", bottom: "15px", position: "absolute" };
48
-
49
47
  export const DEFAULT_CONTAINER_RATIO = 9 / 16;
package/src/index.ts CHANGED
@@ -1,9 +1,8 @@
1
- import AppDocsViewer from "@netless/app-docs-viewer";
2
- import AppMediaPlayer, { setOptions } from "@netless/app-media-player";
3
1
  import Emittery from "emittery";
4
2
  import pRetry from "p-retry";
5
3
  import { AppManager } from "./AppManager";
6
4
  import { appRegister } from "./Register";
5
+ import { ContainerResizeObserver } from "./ContainerResizeObserver";
7
6
  import { createBoxManager } from "./BoxManager";
8
7
  import { CursorManager } from "./Cursor";
9
8
  import { DEFAULT_CONTAINER_RATIO, Events, REQUIRE_VERSION } from "./constants";
@@ -11,9 +10,10 @@ import { Fields } from "./AttributesDelegate";
11
10
  import { initDb } from "./Register/storage";
12
11
  import { isNull, isObject } from "lodash";
13
12
  import { log } from "./Utils/log";
13
+ import { ReconnectRefresher } from "./ReconnectRefresher";
14
14
  import { replaceRoomFunction } from "./Utils/RoomHacker";
15
- import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
16
- import { setupWrapper } from "./ViewManager";
15
+ import { setupBuiltin } from "./BuiltinApps";
16
+ import { setupWrapper } from "./Helper";
17
17
  import "./style.css";
18
18
  import "@netless/telebox-insider/dist/style.css";
19
19
  import {
@@ -59,8 +59,6 @@ import type { NetlessApp, RegisterParams } from "./typings";
59
59
  import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
60
60
  import type { AppProxy } from "./AppProxy";
61
61
 
62
- const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
63
-
64
62
  export type WindowMangerAttributes = {
65
63
  modelValue?: string;
66
64
  boxState: TELE_BOX_STATE;
@@ -81,14 +79,14 @@ export type AddAppOptions = {
81
79
 
82
80
  export type setAppOptions = AddAppOptions & { appOptions?: any };
83
81
 
84
- export type AddAppParams = {
82
+ export type AddAppParams<TAttributes = any> = {
85
83
  kind: string;
86
84
  // app 地址(本地 app 不需要传)
87
85
  src?: string;
88
86
  // 窗口配置
89
87
  options?: AddAppOptions;
90
88
  // 初始化 attributes
91
- attributes?: any;
89
+ attributes?: TAttributes;
92
90
  };
93
91
 
94
92
  export type BaseInsertParams = {
@@ -139,6 +137,7 @@ export type EmitterEvent = {
139
137
  observerIdChange: number;
140
138
  boxStateChange: string;
141
139
  playgroundSizeChange: DOMRect;
140
+ onReconnected: void;
142
141
  };
143
142
 
144
143
  export type EmitterType = Emittery<EmitterEvent>;
@@ -150,6 +149,9 @@ export type PublicEvent = {
150
149
  darkModeChange: boolean;
151
150
  prefersColorSchemeChange: TeleBoxColorScheme;
152
151
  cameraStateChange: CameraState;
152
+ mainViewScenePathChange: string;
153
+ mainViewSceneIndexChange: number;
154
+ focusedChange: string | undefined;
153
155
  };
154
156
 
155
157
  export type MountParams = {
@@ -171,6 +173,8 @@ export type MountParams = {
171
173
  export type CallbacksType = Emittery<PublicEvent>;
172
174
  export const callbacks: CallbacksType = new Emittery();
173
175
 
176
+ export const reconnectRefresher = new ReconnectRefresher({ emitter });
177
+
174
178
  export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
175
179
  public static kind = "WindowManager";
176
180
  public static displayer: Displayer;
@@ -181,7 +185,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
181
185
  public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
182
186
  private static isCreated = false;
183
187
 
184
- public version = "0.4.0-canary.1";
188
+ public version = __APP_VERSION__;
185
189
 
186
190
  public appListeners?: AppListeners;
187
191
 
@@ -195,6 +199,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
195
199
  private boxManager?: BoxManager;
196
200
  private static params?: MountParams;
197
201
 
202
+ private containerResizeObserver?: ContainerResizeObserver;
203
+
198
204
  constructor(context: InvisiblePluginContext) {
199
205
  super(context);
200
206
  WindowManager.displayer = context.displayer;
@@ -214,15 +220,16 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
214
220
  if (room.phase !== RoomPhase.Connected) {
215
221
  throw new Error("[WindowManager]: Room only Connected can be mount");
216
222
  }
223
+ if (room.phase === RoomPhase.Connected && room.isWritable) {
224
+ // redo undo 需要设置这个属性
225
+ room.disableSerialization = false;
226
+ }
217
227
  }
218
228
  if (WindowManager.isCreated) {
219
229
  throw new Error("[WindowManager]: Already created cannot be created again");
220
230
  }
221
231
  let manager = await this.initManager(room);
222
232
  this.debug = Boolean(debug);
223
- if (this.debug) {
224
- setOptions({ verbose: true });
225
- }
226
233
  log("Already insert room", manager);
227
234
 
228
235
  if (isRoom(this.displayer)) {
@@ -254,7 +261,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
254
261
  }
255
262
 
256
263
  if (params.container) {
257
- manager.bindContainer(params.container, params.collectorContainer);
264
+ manager.bindContainer(params.container);
258
265
  }
259
266
 
260
267
  replaceRoomFunction(room, manager);
@@ -316,12 +323,17 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
316
323
  style.textContent = overwriteStyles;
317
324
  playground.appendChild(style);
318
325
  }
319
- manager.observePlaygroundSize(playground, sizer, wrapper);
326
+ manager.containerResizeObserver = ContainerResizeObserver.create(
327
+ playground,
328
+ sizer,
329
+ wrapper,
330
+ emitter
331
+ );
320
332
  WindowManager.wrapper = wrapper;
321
333
  return mainViewElement;
322
334
  }
323
335
 
324
- public bindContainer(container: HTMLElement, collectorContainer?: HTMLElement) {
336
+ public bindContainer(container: HTMLElement) {
325
337
  if (WindowManager.isCreated && WindowManager.container) {
326
338
  if (WindowManager.container.firstChild) {
327
339
  container.appendChild(WindowManager.container.firstChild);
@@ -336,7 +348,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
336
348
  params.overwriteStyles
337
349
  );
338
350
  const boxManager = createBoxManager(this, callbacks, emitter, {
339
- collectorContainer: collectorContainer,
351
+ collectorContainer: params.collectorContainer,
340
352
  collectorStyles: params.collectorStyles,
341
353
  prefersColorScheme: params.prefersColorScheme,
342
354
  });
@@ -355,6 +367,16 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
355
367
  WindowManager.container = container;
356
368
  }
357
369
 
370
+ public bindCollectorContainer(container: HTMLElement) {
371
+ if (WindowManager.isCreated && this.boxManager) {
372
+ this.boxManager.setCollectorContainer(container);
373
+ } else {
374
+ if (WindowManager.params) {
375
+ WindowManager.params.collectorContainer = container;
376
+ }
377
+ }
378
+ }
379
+
358
380
  /**
359
381
  * 注册插件
360
382
  */
@@ -364,21 +386,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
364
386
  return appRegister.register(params);
365
387
  }
366
388
 
367
- public static setCollectorContainer(container: HTMLElement) {
368
- const manager = this.displayer.getInvisiblePlugin(this.kind) as WindowManager;
369
- if (this.isCreated && manager) {
370
- manager.boxManager?.setCollectorContainer(container);
371
- } else {
372
- if (this.params) {
373
- this.params.collectorContainer = container;
374
- }
375
- }
376
- }
377
-
378
389
  /**
379
390
  * 创建一个 app 至白板
380
391
  */
381
- public async addApp(params: AddAppParams): Promise<string | undefined> {
392
+ public async addApp<T = any>(params: AddAppParams<T>): Promise<string | undefined> {
382
393
  if (this.appManager) {
383
394
  if (!params.kind || typeof params.kind !== "string") {
384
395
  throw new ParamsInvalidError();
@@ -475,10 +486,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
475
486
  * 设置所有 app 的 readonly 模式
476
487
  */
477
488
  public setReadonly(readonly: boolean): void {
478
- if (this.room?.isWritable) {
479
- this.readonly = readonly;
480
- this.appManager?.boxManager?.setReadonly(readonly);
481
- }
489
+ this.readonly = readonly;
490
+ this.boxManager?.setReadonly(readonly);
482
491
  }
483
492
 
484
493
  /**
@@ -558,6 +567,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
558
567
  }
559
568
  }
560
569
 
570
+ public get focused(): string | undefined {
571
+ return this.attributes.focus;
572
+ }
573
+
561
574
  /**
562
575
  * 查询所有的 App
563
576
  */
@@ -698,62 +711,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
698
711
  }
699
712
  }
700
713
  }
701
-
702
- private containerResizeObserver?: ResizeObserver;
703
-
704
- private observePlaygroundSize(
705
- container: HTMLElement,
706
- sizer: HTMLElement,
707
- wrapper: HTMLDivElement
708
- ) {
709
- this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
710
-
711
- this.containerResizeObserver = new ResizeObserver(entries => {
712
- const containerRect = entries[0]?.contentRect;
713
- if (containerRect) {
714
- this.updateSizer(containerRect, sizer, wrapper);
715
- this.cursorManager?.updateContainerRect();
716
- this.boxManager?.updateManagerRect();
717
- emitter.emit("playgroundSizeChange", containerRect);
718
- }
719
- });
720
-
721
- this.containerResizeObserver.observe(container);
722
- }
723
-
724
- private updateSizer(
725
- { width, height }: DOMRectReadOnly,
726
- sizer: HTMLElement,
727
- wrapper: HTMLDivElement
728
- ) {
729
- if (width && height) {
730
- if (height / width > WindowManager.containerSizeRatio) {
731
- height = width * WindowManager.containerSizeRatio;
732
- sizer.classList.toggle("netless-window-manager-sizer-horizontal", true);
733
- } else {
734
- width = height / WindowManager.containerSizeRatio;
735
- sizer.classList.toggle("netless-window-manager-sizer-horizontal", false);
736
- }
737
- wrapper.style.width = `${width}px`;
738
- wrapper.style.height = `${height}px`;
739
- }
740
- }
741
714
  }
742
715
 
743
- WindowManager.register({
744
- kind: AppDocsViewer.kind,
745
- src: AppDocsViewer,
746
- });
747
- WindowManager.register({
748
- kind: AppMediaPlayer.kind,
749
- src: AppMediaPlayer,
750
- });
751
-
752
- export const BuiltinApps = {
753
- DocsViewer: AppDocsViewer.kind as string,
754
- MediaPlayer: AppMediaPlayer.kind as string,
755
- };
716
+ setupBuiltin();
756
717
 
757
718
  export * from "./typings";
758
719
 
759
- export { WhiteWindowSDK } from "./sdk";
720
+ export { BuiltinApps } from "./BuiltinApps";
package/src/shim.d.ts CHANGED
@@ -4,3 +4,7 @@ declare module "*.svelte" {
4
4
  const app: SvelteComponent;
5
5
  export default app;
6
6
  }
7
+
8
+ declare global {
9
+ const __APP_VERSION__: string;
10
+ }
package/src/style.css CHANGED
@@ -167,3 +167,9 @@
167
167
  display: flex;
168
168
  justify-content: center;
169
169
  }
170
+
171
+ .telebox-collector {
172
+ position: absolute;
173
+ right: 10px;
174
+ bottom: 15px;
175
+ }
package/src/typings.ts CHANGED
@@ -12,7 +12,7 @@ import type {
12
12
  import type { AppContext } from "./AppContext";
13
13
  import type { ReadonlyTeleBox, TeleBoxRect } from "@netless/telebox-insider";
14
14
 
15
- export interface NetlessApp<Attributes = any, SetupResult = any, AppOptions = any> {
15
+ export interface NetlessApp<Attributes = any, MagixEventPayloads = any, AppOptions = any, SetupResult = any> {
16
16
  kind: string;
17
17
  config?: {
18
18
  /** Box width relative to whiteboard. 0~1. Default 0.5. */
@@ -28,7 +28,7 @@ export interface NetlessApp<Attributes = any, SetupResult = any, AppOptions = an
28
28
  /** App only single instance. */
29
29
  singleton?: boolean;
30
30
  };
31
- setup: (context: AppContext<Attributes, AppOptions>) => SetupResult;
31
+ setup: (context: AppContext<Attributes, MagixEventPayloads, AppOptions>) => SetupResult;
32
32
  }
33
33
 
34
34
  export type AppEmitterEvent<T = any> = {
@@ -76,3 +76,4 @@ export type AppListenerKeys = keyof AppEmitterEvent;
76
76
  export type { AppContext } from "./AppContext";
77
77
  export type { ReadonlyTeleBox, TeleBoxRect };
78
78
  export type { SceneState, SceneDefinition, View, AnimationMode, Displayer, Room, Player };
79
+ export type { Storage, StorageStateChangedEvent, StorageStateChangedListener } from "./App/Storage";
package/vite.config.js CHANGED
@@ -1,13 +1,16 @@
1
1
  import path from "path";
2
2
  import { defineConfig } from "vite";
3
3
  import { svelte } from "@sveltejs/vite-plugin-svelte";
4
- import { dependencies ,peerDependencies } from "./package.json"
4
+ import { dependencies ,peerDependencies, version } from "./package.json"
5
5
 
6
6
 
7
7
  export default defineConfig(({ mode }) => {
8
8
  const isProd = mode === "production";
9
9
 
10
10
  return {
11
+ define: {
12
+ __APP_VERSION__: JSON.stringify(version),
13
+ },
11
14
  plugins: [
12
15
  svelte({
13
16
  emitCss: false,
@@ -1,15 +0,0 @@
1
- import type { Camera, View } from "white-web-sdk";
2
- export declare class CameraStore {
3
- private cameras;
4
- private listeners;
5
- setCamera(id: string, camera: Camera): void;
6
- getCamera(id: string): Camera | undefined;
7
- deleteCamera(id: string): void;
8
- recoverCamera(id: string, view?: View): void;
9
- register(id: string, view: View): void;
10
- unregister(id: string, view?: View): void;
11
- private onListener;
12
- private offListener;
13
- switchView(id: string, view: View | undefined, callback: () => void): Promise<void>;
14
- private getOrCreateListener;
15
- }
@@ -1,29 +0,0 @@
1
- import { Base } from "./Base";
2
- import type { View, Displayer } from "white-web-sdk";
3
- import type { AppManager } from "./AppManager";
4
- export declare class ViewManager extends Base {
5
- private views;
6
- private timer?;
7
- private appTimer?;
8
- private mainViewProxy;
9
- private displayer;
10
- constructor(manager: AppManager);
11
- get currentScenePath(): string;
12
- get mainView(): View;
13
- createView(appId: string): View;
14
- destroyView(appId: string): void;
15
- private releaseView;
16
- getView(appId: string): View | undefined;
17
- switchMainViewToWriter(): Promise<boolean> | undefined;
18
- freedomAllViews(): void;
19
- switchAppToWriter(id: string): void;
20
- destroy(): void;
21
- }
22
- export declare const createView: (displayer: Displayer) => View;
23
- export declare const setDefaultCameraBound: (view: View) => void;
24
- export declare const setupWrapper: (root: HTMLElement) => {
25
- playground: HTMLDivElement;
26
- wrapper: HTMLDivElement;
27
- sizer: HTMLDivElement;
28
- mainViewElement: HTMLDivElement;
29
- };
package/dist/sdk.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { WindowManager } from './index';
2
- import type { MountParams } from "./index";
3
- import type { WhiteWebSdkConfiguration, JoinRoomParams } from "white-web-sdk";
4
- declare type WhiteWindowSDKConfiguration = Omit<WhiteWebSdkConfiguration, "useMobXState">;
5
- declare type WindowJoinRoomParams = {
6
- joinRoomParams: Omit<JoinRoomParams, "useMultiViews" | "disableMagixEventDispatchLimit">;
7
- mountParams: Omit<MountParams, "room">;
8
- };
9
- export declare class WhiteWindowSDK {
10
- private sdk;
11
- constructor(params: WhiteWindowSDKConfiguration);
12
- mount(params: WindowJoinRoomParams): Promise<WindowManager>;
13
- }
14
- export {};
@@ -1,72 +0,0 @@
1
- import { AnimationMode } from "white-web-sdk";
2
- import type { Camera, View } from "white-web-sdk";
3
-
4
- export class CameraStore {
5
- private cameras: Map<string, Camera> = new Map();
6
- private listeners: Map<string, any> = new Map();
7
-
8
- public setCamera(id: string, camera: Camera) {
9
- this.cameras.set(id, camera);
10
- }
11
-
12
- public getCamera(id: string) {
13
- return this.cameras.get(id);
14
- }
15
-
16
- public deleteCamera(id: string) {
17
- this.cameras.delete(id);
18
- }
19
-
20
- public recoverCamera(id: string, view?: View) {
21
- const camera = this.cameras.get(id);
22
- if (camera && view) {
23
- view.moveCamera({
24
- ...camera,
25
- animationMode: AnimationMode.Immediately,
26
- });
27
- }
28
- }
29
-
30
- public register(id: string, view: View) {
31
- this.onListener(id, view);
32
- this.setCamera(id, view.camera);
33
- }
34
-
35
- public unregister(id: string, view?: View) {
36
- if (view) {
37
- this.offListener(id, view);
38
- }
39
- this.listeners.delete(id);
40
- this.deleteCamera(id);
41
- }
42
-
43
- private onListener = (id: string, view: View) => {
44
- view.callbacks.on("onCameraUpdated", this.getOrCreateListener(id));
45
- };
46
-
47
- private offListener = (id: string, view: View) => {
48
- view.callbacks.off("onCameraUpdated", this.getOrCreateListener(id));
49
- };
50
-
51
- public async switchView(id: string, view: View | undefined, callback: () => void) {
52
- if (view) {
53
- this.offListener(id, view);
54
- await callback();
55
- this.recoverCamera(id, view);
56
- this.onListener(id, view);
57
- }
58
- }
59
-
60
- private getOrCreateListener(id: string) {
61
- let listener = this.listeners.get(id);
62
- if (listener) {
63
- return listener;
64
- } else {
65
- listener = (camera: Camera) => {
66
- this.setCamera(id, camera);
67
- };
68
- this.listeners.set(id, listener);
69
- return listener;
70
- }
71
- }
72
- }
package/src/sdk.ts DELETED
@@ -1,39 +0,0 @@
1
- import { isBoolean } from 'lodash';
2
- import { WhiteWebSdk } from 'white-web-sdk';
3
- import { WindowManager } from './index';
4
- import type { MountParams } from "./index";
5
- import type { WhiteWebSdkConfiguration, JoinRoomParams } from "white-web-sdk";
6
-
7
-
8
-
9
- type WhiteWindowSDKConfiguration = Omit<WhiteWebSdkConfiguration, "useMobXState">
10
- type WindowJoinRoomParams = {
11
- joinRoomParams: Omit<JoinRoomParams, "useMultiViews" | "disableMagixEventDispatchLimit">,
12
- mountParams: Omit<MountParams, "room">,
13
- }
14
-
15
- export class WhiteWindowSDK {
16
- private sdk: WhiteWebSdk;
17
-
18
- constructor(params: WhiteWindowSDKConfiguration) {
19
- this.sdk = new WhiteWebSdk({ ...params, useMobXState: true });
20
- }
21
-
22
- public async mount(params: WindowJoinRoomParams): Promise<WindowManager> {
23
- const invisiblePlugins = params.joinRoomParams.invisiblePlugins || [];
24
- const room = await this.sdk.joinRoom({
25
- ...params.joinRoomParams,
26
- useMultiViews: true,
27
- invisiblePlugins: [...invisiblePlugins, WindowManager],
28
- disableMagixEventDispatchLimit: true,
29
- });
30
- const manager = await WindowManager.mount({
31
- room,
32
- ...params.mountParams
33
- });
34
- if (isBoolean(params.joinRoomParams.disableCameraTransform)) {
35
- manager.mainView.disableCameraTransform = params.joinRoomParams.disableCameraTransform;
36
- }
37
- return manager;
38
- }
39
- }