@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,31 +1,29 @@
1
1
  import Emittery from "emittery";
2
+ import type { TeleBoxRect } from "@netless/telebox-insider";
2
3
  import type { AppInitState, CursorMovePayload } from "./index";
3
4
 
4
5
  export type RemoveSceneParams = {
5
- scenePath: string, index?: number
6
- }
6
+ scenePath: string;
7
+ index?: number;
8
+ };
7
9
 
8
10
  export type EmitterEvent = {
9
11
  onCreated: undefined;
10
12
  InitReplay: AppInitState;
11
- move: { appId: string; x: number; y: number };
12
- focus: { appId: string };
13
- close: { appId: string };
14
- resize: { appId: string; width: number; height: number; x?: number; y?: number };
15
13
  error: Error;
16
14
  seekStart: undefined;
17
15
  seek: number;
18
16
  mainViewMounted: undefined;
19
17
  observerIdChange: number;
20
18
  boxStateChange: string;
21
- playgroundSizeChange: DOMRect;
19
+ playgroundSizeChange: TeleBoxRect;
22
20
  startReconnect: undefined;
23
21
  onReconnected: undefined;
24
22
  removeScenes: RemoveSceneParams;
25
23
  cursorMove: CursorMovePayload;
26
24
  updateManagerRect: undefined;
27
25
  focusedChange: { focused: string | undefined; prev: string | undefined };
28
- rootDirRemoved: undefined; // 根目录整个被删除
26
+ rootDirRemoved: undefined; // 根目录整个被删除
29
27
  rootDirSceneRemoved: string; // 根目录下的场景被删除
30
28
  setReadonly: boolean;
31
29
  changePageState: undefined;
@@ -1,8 +1,7 @@
1
1
  import { callbacks } from "../callback";
2
2
  import { SETUP_APP_DELAY } from "../constants";
3
- import type { AppProxy } from "../App";
4
3
 
5
- export type Invoker = () => Promise<AppProxy | undefined>;
4
+ export type Invoker<T = any> = () => Promise<T | undefined>;
6
5
 
7
6
  export class AppCreateQueue {
8
7
  private list: Invoker[] = [];
@@ -16,7 +15,7 @@ export class AppCreateQueue {
16
15
  }, 50);
17
16
  }
18
17
 
19
- public push(item: Invoker) {
18
+ public push<T>(item: Invoker<T>) {
20
19
  this.list.push(item);
21
20
  this.invoke();
22
21
  if (this.timer === undefined && this.list.length > 0) {
@@ -0,0 +1,67 @@
1
+ import { AnimationMode } from "white-web-sdk";
2
+ import { delay, throttle } from "lodash";
3
+ import type { TeleBoxRect } from "@netless/telebox-insider";
4
+ import type { Camera, View, Size } from "white-web-sdk";
5
+ import type { MainViewSize } from "../AttributesDelegate";
6
+
7
+ export type SaveCamera = (camera: Camera) => void;
8
+
9
+ export class CameraSynchronizer {
10
+ protected remoteCamera?: Camera;
11
+ protected remoteSize?: MainViewSize;
12
+ protected rect?: TeleBoxRect;
13
+ protected view?: View;
14
+
15
+ constructor(protected saveCamera: SaveCamera) {}
16
+
17
+ public setRect(rect: TeleBoxRect) {
18
+ this.rect = rect;
19
+ if (this.remoteCamera && this.remoteSize) {
20
+ this.onRemoteUpdate(this.remoteCamera, this.remoteSize);
21
+ }
22
+ }
23
+
24
+ public setView(view: View) {
25
+ this.view = view;
26
+ }
27
+
28
+ // 远端 Camera 或者 size 更新
29
+ public onRemoteUpdate = throttle((camera: Camera, size: MainViewSize) => {
30
+ this.remoteCamera = camera;
31
+ this.remoteSize = size;
32
+ if (this.remoteSize && this.rect) {
33
+ let scale: number;
34
+ if (size.width < size.height) {
35
+ scale = this.rect.width / size.width;
36
+ } else {
37
+ scale = this.rect.height / size.height;
38
+ }
39
+ const nextScale = camera.scale * scale;
40
+ const moveCamera = () => this.view?.moveCamera({
41
+ centerX: camera.centerX,
42
+ centerY: camera.centerY,
43
+ scale: nextScale,
44
+ animationMode: AnimationMode.Immediately,
45
+ });
46
+ // TODO 直接调用 moveCamera 依然会出现 camera 错误的情况,这里暂时加一个 delay 保证 camera 是对的, 后续需要 SDK 进行修改
47
+ delay(moveCamera, 10);
48
+ }
49
+ }, 50);
50
+
51
+
52
+ public onLocalCameraUpdate(camera: Camera) {
53
+ this.saveCamera(camera);
54
+ }
55
+
56
+ // 本地 Size 更新, 先匹配 camera 到新的 size 然后再发送 camera 数据到远端
57
+ public onLocalSizeUpdate(size: Size) {
58
+ if (this.rect && this.view) {
59
+ const scale = this.rect.width / size.width;
60
+ const nextScale = this.view.camera.scale * scale;
61
+ this.view.moveCamera({
62
+ scale: nextScale,
63
+ animationMode: AnimationMode.Immediately
64
+ });
65
+ }
66
+ }
67
+ }
@@ -1,25 +1,29 @@
1
- import { AnimationMode, reaction } from "white-web-sdk";
1
+ import { reaction } from "white-web-sdk";
2
2
  import { callbacks } from "../callback";
3
3
  import { createView } from "./ViewManager";
4
- import { debounce, get, isEmpty, isEqual } from "lodash";
4
+ import { debounce, get, isEqual } from "lodash";
5
5
  import { emitter } from "../InternalEmitter";
6
+ import { Events } from "../constants";
6
7
  import { Fields } from "../AttributesDelegate";
7
8
  import { setViewFocusScenePath } from "../Utils/Common";
8
9
  import { SideEffectManager } from "side-effect-manager";
9
10
  import type { Camera, Size, View } from "white-web-sdk";
10
11
  import type { AppManager } from "../AppManager";
11
- import { Events } from "../constants";
12
+ import { CameraSynchronizer } from "./CameraSynchronizer";
12
13
 
13
14
  export class MainViewProxy {
14
- private scale?: number;
15
15
  private started = false;
16
16
  private mainViewIsAddListener = false;
17
17
  private mainView: View;
18
18
  private store = this.manager.store;
19
+ private synchronizer: CameraSynchronizer;
19
20
 
20
21
  private sideEffectManager = new SideEffectManager();
21
22
 
22
23
  constructor(private manager: AppManager) {
24
+ this.synchronizer = new CameraSynchronizer(
25
+ camera => this.store.setMainViewCamera({ ...camera, id: this.manager.uid })
26
+ );
23
27
  this.mainView = this.createMainView();
24
28
  this.moveCameraSizeByAttributes();
25
29
  emitter.once("mainViewMounted").then(() => {
@@ -28,18 +32,24 @@ export class MainViewProxy {
28
32
  this.ensureCameraAndSize();
29
33
  this.startListenWritableChange();
30
34
  });
31
- const playgroundSizeChangeListener = () => {
32
- this.sizeChangeHandler(this.mainViewSize);
33
- };
34
- this.sideEffectManager.add(() => {
35
- return emitter.on("playgroundSizeChange", playgroundSizeChangeListener);
36
- });
37
35
  this.sideEffectManager.add(() => {
38
36
  return emitter.on("containerSizeRatioUpdate", this.onUpdateContainerSizeRatio);
39
37
  });
40
38
  this.sideEffectManager.add(() => {
41
39
  return emitter.on("startReconnect", () => {
42
- this.mainView.release();
40
+ if (!(this.mainView as any).didRelease) {
41
+ this.mainView.release();
42
+ }
43
+ });
44
+ });
45
+ const rect = this.manager.boxManager?.teleBoxManager.stageRect;
46
+ if (rect) {
47
+ this.synchronizer.setRect(rect);
48
+ }
49
+ this.sideEffectManager.add(() => {
50
+ return emitter.on("playgroundSizeChange", rect => {
51
+ this.synchronizer.setRect(rect);
52
+ this.synchronizer.onLocalSizeUpdate(rect);
43
53
  });
44
54
  });
45
55
  }
@@ -52,7 +62,7 @@ export class MainViewProxy {
52
62
  }
53
63
  });
54
64
  });
55
- }
65
+ };
56
66
 
57
67
  public ensureCameraAndSize() {
58
68
  if (!this.mainViewCamera || !this.mainViewSize) {
@@ -74,8 +84,7 @@ export class MainViewProxy {
74
84
  }
75
85
 
76
86
  private moveCameraSizeByAttributes() {
77
- this.moveCameraToContian(this.mainViewSize);
78
- this.moveCamera(this.mainViewCamera);
87
+ this.synchronizer.onRemoteUpdate(this.mainViewCamera, this.mainViewSize);
79
88
  }
80
89
 
81
90
  public start() {
@@ -91,9 +100,12 @@ export class MainViewProxy {
91
100
  };
92
101
 
93
102
  public setCameraAndSize(): void {
94
- const camera = { ...this.mainView.camera, id: this.manager.uid };
95
- const size = { ...this.mainView.size, id: this.manager.uid };
96
- this.store.setMainViewCameraAndSize(camera, size);
103
+ const stageSize = this.getStageSize();
104
+ if (stageSize) {
105
+ const camera = { ...this.mainView.camera, id: this.manager.uid };
106
+ const size = { ...stageSize, id: this.manager.uid };
107
+ this.store.setMainViewCameraAndSize(camera, size);
108
+ }
97
109
  }
98
110
 
99
111
  private cameraReaction = () => {
@@ -101,8 +113,7 @@ export class MainViewProxy {
101
113
  () => this.mainViewCamera,
102
114
  camera => {
103
115
  if (camera && camera.id !== this.manager.uid) {
104
- this.moveCameraToContian(this.mainViewSize);
105
- this.moveCamera(camera);
116
+ this.synchronizer.onRemoteUpdate(camera, this.mainViewSize);
106
117
  }
107
118
  },
108
119
  { fireImmediately: true }
@@ -111,8 +122,7 @@ export class MainViewProxy {
111
122
 
112
123
  public sizeChangeHandler = debounce((size: Size) => {
113
124
  if (size) {
114
- this.moveCameraToContian(size);
115
- this.moveCamera(this.mainViewCamera);
125
+ this.synchronizer.onLocalSizeUpdate(size);
116
126
  }
117
127
  }, 30);
118
128
 
@@ -122,7 +132,7 @@ export class MainViewProxy {
122
132
  if (size.id === this.manager.uid) {
123
133
  this.setCameraAndSize();
124
134
  }
125
- }
135
+ };
126
136
 
127
137
  public get view(): View {
128
138
  return this.mainView;
@@ -138,6 +148,7 @@ export class MainViewProxy {
138
148
  if (mainViewScenePath) {
139
149
  setViewFocusScenePath(mainView, mainViewScenePath);
140
150
  }
151
+ this.synchronizer.setView(mainView);
141
152
  return mainView;
142
153
  }
143
154
 
@@ -172,12 +183,20 @@ export class MainViewProxy {
172
183
  }
173
184
 
174
185
  private onCameraUpdatedByDevice = (camera: Camera) => {
175
- this.store.setMainViewCamera({ ...camera, id: this.manager.uid });
176
- if (!isEqual(this.mainViewSize, { ...this.mainView.size, id: this.manager.uid })) {
177
- this.setMainViewSize(this.view.size);
186
+ this.synchronizer.onLocalCameraUpdate(camera);
187
+ const size = this.getStageSize();
188
+ if (size && !isEqual(size, this.mainViewSize)) {
189
+ this.setMainViewSize(size);
178
190
  }
179
191
  };
180
192
 
193
+ private getStageSize(): Size | undefined {
194
+ const stage = this.manager.boxManager?.teleBoxManager.stageRect;
195
+ if (stage) {
196
+ return { width: stage.width, height: stage.height };
197
+ }
198
+ }
199
+
181
200
  public addMainViewListener(): void {
182
201
  if (this.mainViewIsAddListener) return;
183
202
  if (this.view.divElement) {
@@ -205,7 +224,7 @@ export class MainViewProxy {
205
224
  this.manager.boxManager?.blurAllBox();
206
225
  }
207
226
 
208
- public setMainViewSize = debounce(size => {
227
+ public setMainViewSize = debounce((size: Size) => {
209
228
  this.store.setMainViewSize({ ...size, id: this.manager.uid });
210
229
  }, 50);
211
230
 
@@ -225,33 +244,6 @@ export class MainViewProxy {
225
244
  callbacks.emit("cameraStateChange", this.cameraState);
226
245
  };
227
246
 
228
- public moveCameraToContian(size: Size): void {
229
- if (!isEmpty(size)) {
230
- this.view.moveCameraToContain({
231
- width: size.width,
232
- height: size.height,
233
- originX: -size.width / 2,
234
- originY: -size.height / 2,
235
- animationMode: AnimationMode.Immediately,
236
- });
237
- this.scale = this.view.camera.scale;
238
- }
239
- }
240
-
241
- public moveCamera(camera: Camera): void {
242
- if (!isEmpty(camera)) {
243
- if (isEqual(camera, this.view.camera)) return;
244
- const { centerX, centerY, scale } = camera;
245
- const needScale = scale * (this.scale || 1);
246
- this.view.moveCamera({
247
- centerX: centerX,
248
- centerY: centerY,
249
- scale: needScale,
250
- animationMode: AnimationMode.Immediately,
251
- });
252
- }
253
- }
254
-
255
247
  public stop() {
256
248
  this.removeCameraListener();
257
249
  this.manager.refresher?.remove(Fields.MainViewCamera);
package/src/index.ts CHANGED
@@ -3,7 +3,6 @@ import { AppManager } from "./AppManager";
3
3
  import { appRegister } from "./Register";
4
4
  import { callbacks } from "./callback";
5
5
  import { checkVersion, setupWrapper } from "./Helper";
6
- import { ContainerResizeObserver } from "./ContainerResizeObserver";
7
6
  import { createBoxManager } from "./BoxManager";
8
7
  import { CursorManager } from "./Cursor";
9
8
  import { DEFAULT_CONTAINER_RATIO, Events, INIT_DIR, ROOT_DIR } from "./constants";
@@ -29,13 +28,7 @@ import {
29
28
  wait,
30
29
  } from "./Utils/Common";
31
30
  import type { TELE_BOX_STATE, BoxManager } from "./BoxManager";
32
- import {
33
- AppCreateError,
34
- AppManagerNotInitError,
35
- BindContainerRoomPhaseInvalidError,
36
- InvalidScenePath,
37
- ParamsInvalidError,
38
- } from "./Utils/error";
31
+ import * as Errors from "./Utils/error";
39
32
  import type { Apps, Position } from "./AttributesDelegate";
40
33
  import type {
41
34
  Displayer,
@@ -54,12 +47,13 @@ import type {
54
47
  SceneState,
55
48
  } from "white-web-sdk";
56
49
  import type { AppListeners } from "./AppListener";
57
- import type { NetlessApp, RegisterParams } from "./typings";
50
+ import type { ApplianceIcons, NetlessApp, RegisterParams } from "./typings";
58
51
  import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
59
52
  import type { AppProxy } from "./App";
60
53
  import type { PublicEvent } from "./callback";
61
54
  import type Emittery from "emittery";
62
55
  import type { PageController, AddPageParams, PageState } from "./Page";
56
+ import { boxEmitter } from "./BoxEmitter";
63
57
 
64
58
  export type WindowMangerAttributes = {
65
59
  modelValue?: string;
@@ -142,6 +136,7 @@ export type MountParams = {
142
136
  debug?: boolean;
143
137
  disableCameraTransform?: boolean;
144
138
  prefersColorScheme?: TeleBoxColorScheme;
139
+ applianceIcons?: ApplianceIcons;
145
140
  };
146
141
 
147
142
  export const reconnectRefresher = new ReconnectRefresher({ emitter });
@@ -149,7 +144,6 @@ export const reconnectRefresher = new ReconnectRefresher({ emitter });
149
144
  export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> implements PageController {
150
145
  public static kind = "WindowManager";
151
146
  public static displayer: Displayer;
152
- public static wrapper?: HTMLElement;
153
147
  public static playground?: HTMLElement;
154
148
  public static container?: HTMLElement;
155
149
  public static debug = false;
@@ -172,7 +166,6 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
172
166
  private boxManager?: BoxManager;
173
167
  private static params?: MountParams;
174
168
 
175
- private containerResizeObserver?: ContainerResizeObserver;
176
169
  public containerSizeRatio = WindowManager.containerSizeRatio;
177
170
 
178
171
  constructor(context: InvisiblePluginContext) {
@@ -237,11 +230,17 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
237
230
 
238
231
  manager.appManager = new AppManager(manager);
239
232
  manager._pageState = new PageStateImpl(manager.appManager);
240
- manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor));
233
+ manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor), params.applianceIcons);
241
234
  if (containerSizeRatio) {
242
235
  manager.containerSizeRatio = containerSizeRatio;
243
236
  }
244
-
237
+ manager.boxManager = createBoxManager(manager, callbacks, emitter, boxEmitter, {
238
+ collectorContainer: params.collectorContainer,
239
+ collectorStyles: params.collectorStyles,
240
+ prefersColorScheme: params.prefersColorScheme,
241
+ stageRatio: params.containerSizeRatio,
242
+ });
243
+ manager.appManager?.setBoxManager(manager.boxManager);
245
244
  if (params.container) {
246
245
  manager.bindContainer(params.container);
247
246
  }
@@ -287,31 +286,19 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
287
286
  }
288
287
 
289
288
  private static initContainer(
290
- manager: WindowManager,
291
289
  container: HTMLElement,
292
- chessboard: boolean | undefined,
293
290
  overwriteStyles: string | undefined
294
291
  ) {
295
292
  if (!WindowManager.container) {
296
293
  WindowManager.container = container;
297
294
  }
298
- const { playground, wrapper, sizer, mainViewElement } = setupWrapper(container);
295
+ const { playground, mainViewElement } = setupWrapper(container);
299
296
  WindowManager.playground = playground;
300
- if (chessboard) {
301
- sizer.classList.add("netless-window-manager-chess-sizer");
302
- }
303
297
  if (overwriteStyles) {
304
298
  const style = document.createElement("style");
305
299
  style.textContent = overwriteStyles;
306
300
  playground.appendChild(style);
307
301
  }
308
- manager.containerResizeObserver = ContainerResizeObserver.create(
309
- playground,
310
- sizer,
311
- wrapper,
312
- emitter
313
- );
314
- WindowManager.wrapper = wrapper;
315
302
  return mainViewElement;
316
303
  }
317
304
 
@@ -320,8 +307,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
320
307
  }
321
308
 
322
309
  public bindContainer(container: HTMLElement) {
323
- if (this.room.phase !== RoomPhase.Connected) {
324
- throw new BindContainerRoomPhaseInvalidError();
310
+ if (isRoom(this.displayer) && this.room.phase !== RoomPhase.Connected) {
311
+ throw new Errors.BindContainerRoomPhaseInvalidError();
325
312
  }
326
313
  if (WindowManager.isCreated && WindowManager.container) {
327
314
  if (WindowManager.container.firstChild) {
@@ -331,24 +318,15 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
331
318
  if (WindowManager.params) {
332
319
  const params = WindowManager.params;
333
320
  const mainViewElement = WindowManager.initContainer(
334
- this,
335
321
  container,
336
- params.chessboard,
337
322
  params.overwriteStyles
338
323
  );
339
- if (this.boxManager) {
340
- this.boxManager.destroy();
324
+ if (this.boxManager && WindowManager.playground) {
325
+ this.boxManager.setRoot(WindowManager.playground);
341
326
  }
342
- const boxManager = createBoxManager(this, callbacks, emitter, {
343
- collectorContainer: params.collectorContainer,
344
- collectorStyles: params.collectorStyles,
345
- prefersColorScheme: params.prefersColorScheme,
346
- });
347
- this.boxManager = boxManager;
348
- this.appManager?.setBoxManager(boxManager);
349
327
  this.bindMainView(mainViewElement, params.disableCameraTransform);
350
- if (WindowManager.wrapper) {
351
- this.cursorManager?.setupWrapper(WindowManager.wrapper);
328
+ if (WindowManager.playground) {
329
+ this.cursorManager?.setupWrapper(WindowManager.playground);
352
330
  }
353
331
  }
354
332
  }
@@ -362,7 +340,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
362
340
 
363
341
  public bindCollectorContainer(container: HTMLElement) {
364
342
  if (WindowManager.isCreated && this.boxManager) {
365
- this.boxManager.setCollectorContainer(container);
343
+ this.boxManager.teleBoxManager.collector.set$collector(container)
366
344
  } else {
367
345
  if (WindowManager.params) {
368
346
  WindowManager.params.collectorContainer = container;
@@ -407,19 +385,19 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
407
385
  return this._addApp(params);
408
386
  }
409
387
  } else {
410
- throw new AppManagerNotInitError();
388
+ throw new Errors.AppManagerNotInitError();
411
389
  }
412
390
  }
413
391
 
414
392
  private async _addApp<T = any>(params: AddAppParams<T>): Promise<string | undefined> {
415
393
  if (this.appManager) {
416
394
  if (!params.kind || typeof params.kind !== "string") {
417
- throw new ParamsInvalidError();
395
+ throw new Errors.ParamsInvalidError();
418
396
  }
419
397
  const appImpl = await appRegister.appClasses.get(params.kind)?.();
420
398
  if (appImpl && appImpl.config?.singleton) {
421
399
  if (this.appManager.appProxies.has(params.kind)) {
422
- throw new AppCreateError();
400
+ throw new Errors.AppCreateError();
423
401
  }
424
402
  }
425
403
  const isDynamicPPT = this.setupScenePath(params, this.appManager);
@@ -432,7 +410,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
432
410
  const appId = await this.appManager.addApp(params, Boolean(isDynamicPPT));
433
411
  return appId;
434
412
  } else {
435
- throw new AppManagerNotInitError();
413
+ throw new Errors.AppManagerNotInitError();
436
414
  }
437
415
  }
438
416
 
@@ -442,7 +420,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
442
420
  const { scenePath, scenes } = params.options;
443
421
  if (scenePath) {
444
422
  if (!isValidScenePath(scenePath)) {
445
- throw new InvalidScenePath();
423
+ throw new Errors.InvalidScenePath();
446
424
  }
447
425
  const apps = Object.keys(this.apps || {});
448
426
  for (const appId of apps) {
@@ -645,7 +623,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
645
623
  if (this.appManager) {
646
624
  return this.appManager.mainViewProxy.view;
647
625
  } else {
648
- throw new AppManagerNotInitError();
626
+ throw new Errors.AppManagerNotInitError();
649
627
  }
650
628
  }
651
629
 
@@ -653,7 +631,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
653
631
  if (this.appManager) {
654
632
  return this.appManager.mainViewProxy.view.camera;
655
633
  } else {
656
- throw new AppManagerNotInitError();
634
+ throw new Errors.AppManagerNotInitError();
657
635
  }
658
636
  }
659
637
 
@@ -661,7 +639,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
661
639
  if (this.appManager) {
662
640
  return this.appManager.mainViewProxy.cameraState;
663
641
  } else {
664
- throw new AppManagerNotInitError();
642
+ throw new Errors.AppManagerNotInitError();
665
643
  }
666
644
  }
667
645
 
@@ -673,7 +651,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
673
651
  if (this.appManager) {
674
652
  return this.appManager.boxManager?.boxState;
675
653
  } else {
676
- throw new AppManagerNotInitError();
654
+ throw new Errors.AppManagerNotInitError();
677
655
  }
678
656
  }
679
657
 
@@ -685,7 +663,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
685
663
  if (this.appManager) {
686
664
  return this.appManager.boxManager?.prefersColorScheme;
687
665
  } else {
688
- throw new AppManagerNotInitError();
666
+ throw new Errors.AppManagerNotInitError();
689
667
  }
690
668
  }
691
669
 
@@ -705,7 +683,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
705
683
  if (this.appManager) {
706
684
  return this.appManager?.getMainViewSceneDir();
707
685
  } else {
708
- throw new AppManagerNotInitError();
686
+ throw new Errors.AppManagerNotInitError();
709
687
  }
710
688
  }
711
689
 
@@ -730,7 +708,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
730
708
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
731
709
  return this.appManager.sceneState!;
732
710
  } else {
733
- throw new AppManagerNotInitError();
711
+ throw new Errors.AppManagerNotInitError();
734
712
  }
735
713
  }
736
714
 
@@ -738,7 +716,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
738
716
  if (this._pageState) {
739
717
  return this._pageState.toObject();
740
718
  } else {
741
- throw new AppManagerNotInitError();
719
+ throw new Errors.AppManagerNotInitError();
742
720
  }
743
721
  }
744
722
 
@@ -806,11 +784,9 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
806
784
  }
807
785
 
808
786
  private _destroy() {
809
- this.containerResizeObserver?.disconnect();
810
787
  this.appManager?.destroy();
811
788
  this.cursorManager?.destroy();
812
789
  WindowManager.container = undefined;
813
- WindowManager.wrapper = undefined;
814
790
  WindowManager.isCreated = false;
815
791
  if (WindowManager.playground) {
816
792
  WindowManager.playground.parentNode?.removeChild(WindowManager.playground);
package/src/typings.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type Emittery from "emittery";
2
2
  import type {
3
3
  AnimationMode,
4
+ ApplianceNames,
4
5
  Displayer,
5
6
  DisplayerState,
6
7
  Player,
@@ -75,6 +76,8 @@ export type RegisterParams<AppOptions = any, SetupResult = any, Attributes = any
75
76
 
76
77
  export type AppListenerKeys = keyof AppEmitterEvent;
77
78
 
79
+ export type ApplianceIcons = Partial<Record<ApplianceNames, string>>;
80
+
78
81
  export type { AppContext } from "./App/AppContext";
79
82
  export type { ReadonlyTeleBox, TeleBoxRect };
80
83
  export type { SceneState, SceneDefinition, View, AnimationMode, Displayer, Room, Player };
package/vite.config.js CHANGED
@@ -39,7 +39,6 @@ export default defineConfig(({ mode }) => {
39
39
  fileName: "index"
40
40
  },
41
41
  outDir: "dist",
42
- sourcemap: true,
43
42
  rollupOptions: {
44
43
  external: Object.keys({
45
44
  ...omit(dependencies, ["@netless/telebox-insider"]),
@@ -1,11 +0,0 @@
1
- import type { EmitterType } from "./InternalEmitter";
2
- export declare class ContainerResizeObserver {
3
- private emitter;
4
- private containerResizeObserver?;
5
- private disposer?;
6
- constructor(emitter: EmitterType);
7
- static create(container: HTMLElement, sizer: HTMLElement, wrapper: HTMLDivElement, emitter: EmitterType): ContainerResizeObserver;
8
- observePlaygroundSize(container: HTMLElement, sizer: HTMLElement, wrapper: HTMLDivElement): void;
9
- updateSizer({ width, height }: DOMRectReadOnly, sizer: HTMLElement, wrapper: HTMLDivElement): void;
10
- disconnect(): void;
11
- }
@@ -1,12 +0,0 @@
1
- import type { ScenesCallbacks, ScenesCallbacksNode } from "white-web-sdk";
2
- import type { AppManager } from "../AppManager";
3
- export declare class ScenesCallbackManager {
4
- private manager;
5
- private nodes;
6
- constructor(manager: AppManager);
7
- createNode(path: string, callbacks?: Partial<ScenesCallbacks>): ScenesCallbacksNode | null;
8
- getScenes(path: string): readonly string[] | undefined;
9
- getScenesOnce(path: string): readonly string[] | undefined;
10
- removeNode(path: string): void;
11
- destroy(): void;
12
- }