@netless/window-manager 0.4.31 → 1.0.0-canary.1

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/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,7 +47,7 @@ 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";
@@ -143,6 +136,7 @@ export type MountParams = {
143
136
  debug?: boolean;
144
137
  disableCameraTransform?: boolean;
145
138
  prefersColorScheme?: TeleBoxColorScheme;
139
+ applianceIcons?: ApplianceIcons;
146
140
  };
147
141
 
148
142
  export const reconnectRefresher = new ReconnectRefresher({ emitter });
@@ -150,7 +144,6 @@ export const reconnectRefresher = new ReconnectRefresher({ emitter });
150
144
  export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> implements PageController {
151
145
  public static kind = "WindowManager";
152
146
  public static displayer: Displayer;
153
- public static wrapper?: HTMLElement;
154
147
  public static playground?: HTMLElement;
155
148
  public static container?: HTMLElement;
156
149
  public static debug = false;
@@ -173,7 +166,6 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
173
166
  private boxManager?: BoxManager;
174
167
  private static params?: MountParams;
175
168
 
176
- private containerResizeObserver?: ContainerResizeObserver;
177
169
  public containerSizeRatio = WindowManager.containerSizeRatio;
178
170
 
179
171
  constructor(context: InvisiblePluginContext) {
@@ -238,11 +230,17 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
238
230
 
239
231
  manager.appManager = new AppManager(manager);
240
232
  manager._pageState = new PageStateImpl(manager.appManager);
241
- manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor));
233
+ manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor), params.applianceIcons);
242
234
  if (containerSizeRatio) {
243
235
  manager.containerSizeRatio = containerSizeRatio;
244
236
  }
245
-
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);
246
244
  if (params.container) {
247
245
  manager.bindContainer(params.container);
248
246
  }
@@ -288,31 +286,19 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
288
286
  }
289
287
 
290
288
  private static initContainer(
291
- manager: WindowManager,
292
289
  container: HTMLElement,
293
- chessboard: boolean | undefined,
294
290
  overwriteStyles: string | undefined
295
291
  ) {
296
292
  if (!WindowManager.container) {
297
293
  WindowManager.container = container;
298
294
  }
299
- const { playground, wrapper, sizer, mainViewElement } = setupWrapper(container);
295
+ const { playground, mainViewElement } = setupWrapper(container);
300
296
  WindowManager.playground = playground;
301
- if (chessboard) {
302
- sizer.classList.add("netless-window-manager-chess-sizer");
303
- }
304
297
  if (overwriteStyles) {
305
298
  const style = document.createElement("style");
306
299
  style.textContent = overwriteStyles;
307
300
  playground.appendChild(style);
308
301
  }
309
- manager.containerResizeObserver = ContainerResizeObserver.create(
310
- playground,
311
- sizer,
312
- wrapper,
313
- emitter
314
- );
315
- WindowManager.wrapper = wrapper;
316
302
  return mainViewElement;
317
303
  }
318
304
 
@@ -322,7 +308,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
322
308
 
323
309
  public bindContainer(container: HTMLElement) {
324
310
  if (isRoom(this.displayer) && this.room.phase !== RoomPhase.Connected) {
325
- throw new BindContainerRoomPhaseInvalidError();
311
+ throw new Errors.BindContainerRoomPhaseInvalidError();
326
312
  }
327
313
  if (WindowManager.isCreated && WindowManager.container) {
328
314
  if (WindowManager.container.firstChild) {
@@ -332,24 +318,15 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
332
318
  if (WindowManager.params) {
333
319
  const params = WindowManager.params;
334
320
  const mainViewElement = WindowManager.initContainer(
335
- this,
336
321
  container,
337
- params.chessboard,
338
322
  params.overwriteStyles
339
323
  );
340
- if (this.boxManager) {
341
- this.boxManager.destroy();
324
+ if (this.boxManager && WindowManager.playground) {
325
+ this.boxManager.setRoot(WindowManager.playground);
342
326
  }
343
- const boxManager = createBoxManager(this, callbacks, emitter, boxEmitter, {
344
- collectorContainer: params.collectorContainer,
345
- collectorStyles: params.collectorStyles,
346
- prefersColorScheme: params.prefersColorScheme,
347
- });
348
- this.boxManager = boxManager;
349
- this.appManager?.setBoxManager(boxManager);
350
327
  this.bindMainView(mainViewElement, params.disableCameraTransform);
351
- if (WindowManager.wrapper) {
352
- this.cursorManager?.setupWrapper(WindowManager.wrapper);
328
+ if (WindowManager.playground) {
329
+ this.cursorManager?.setupWrapper(WindowManager.playground);
353
330
  }
354
331
  }
355
332
  }
@@ -363,7 +340,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
363
340
 
364
341
  public bindCollectorContainer(container: HTMLElement) {
365
342
  if (WindowManager.isCreated && this.boxManager) {
366
- this.boxManager.setCollectorContainer(container);
343
+ this.boxManager.setCollector(container);
367
344
  } else {
368
345
  if (WindowManager.params) {
369
346
  WindowManager.params.collectorContainer = container;
@@ -408,19 +385,19 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
408
385
  return this._addApp(params);
409
386
  }
410
387
  } else {
411
- throw new AppManagerNotInitError();
388
+ throw new Errors.AppManagerNotInitError();
412
389
  }
413
390
  }
414
391
 
415
392
  private async _addApp<T = any>(params: AddAppParams<T>): Promise<string | undefined> {
416
393
  if (this.appManager) {
417
394
  if (!params.kind || typeof params.kind !== "string") {
418
- throw new ParamsInvalidError();
395
+ throw new Errors.ParamsInvalidError();
419
396
  }
420
397
  const appImpl = await appRegister.appClasses.get(params.kind)?.();
421
398
  if (appImpl && appImpl.config?.singleton) {
422
399
  if (this.appManager.appProxies.has(params.kind)) {
423
- throw new AppCreateError();
400
+ throw new Errors.AppCreateError();
424
401
  }
425
402
  }
426
403
  const isDynamicPPT = this.setupScenePath(params, this.appManager);
@@ -433,7 +410,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
433
410
  const appId = await this.appManager.addApp(params, Boolean(isDynamicPPT));
434
411
  return appId;
435
412
  } else {
436
- throw new AppManagerNotInitError();
413
+ throw new Errors.AppManagerNotInitError();
437
414
  }
438
415
  }
439
416
 
@@ -443,7 +420,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
443
420
  const { scenePath, scenes } = params.options;
444
421
  if (scenePath) {
445
422
  if (!isValidScenePath(scenePath)) {
446
- throw new InvalidScenePath();
423
+ throw new Errors.InvalidScenePath();
447
424
  }
448
425
  const apps = Object.keys(this.apps || {});
449
426
  for (const appId of apps) {
@@ -646,7 +623,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
646
623
  if (this.appManager) {
647
624
  return this.appManager.mainViewProxy.view;
648
625
  } else {
649
- throw new AppManagerNotInitError();
626
+ throw new Errors.AppManagerNotInitError();
650
627
  }
651
628
  }
652
629
 
@@ -654,7 +631,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
654
631
  if (this.appManager) {
655
632
  return this.appManager.mainViewProxy.view.camera;
656
633
  } else {
657
- throw new AppManagerNotInitError();
634
+ throw new Errors.AppManagerNotInitError();
658
635
  }
659
636
  }
660
637
 
@@ -662,7 +639,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
662
639
  if (this.appManager) {
663
640
  return this.appManager.mainViewProxy.cameraState;
664
641
  } else {
665
- throw new AppManagerNotInitError();
642
+ throw new Errors.AppManagerNotInitError();
666
643
  }
667
644
  }
668
645
 
@@ -674,7 +651,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
674
651
  if (this.appManager) {
675
652
  return this.appManager.boxManager?.boxState;
676
653
  } else {
677
- throw new AppManagerNotInitError();
654
+ throw new Errors.AppManagerNotInitError();
678
655
  }
679
656
  }
680
657
 
@@ -686,7 +663,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
686
663
  if (this.appManager) {
687
664
  return this.appManager.boxManager?.prefersColorScheme;
688
665
  } else {
689
- throw new AppManagerNotInitError();
666
+ throw new Errors.AppManagerNotInitError();
690
667
  }
691
668
  }
692
669
 
@@ -706,7 +683,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
706
683
  if (this.appManager) {
707
684
  return this.appManager?.getMainViewSceneDir();
708
685
  } else {
709
- throw new AppManagerNotInitError();
686
+ throw new Errors.AppManagerNotInitError();
710
687
  }
711
688
  }
712
689
 
@@ -731,7 +708,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
731
708
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
732
709
  return this.appManager.sceneState!;
733
710
  } else {
734
- throw new AppManagerNotInitError();
711
+ throw new Errors.AppManagerNotInitError();
735
712
  }
736
713
  }
737
714
 
@@ -739,7 +716,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
739
716
  if (this._pageState) {
740
717
  return this._pageState.toObject();
741
718
  } else {
742
- throw new AppManagerNotInitError();
719
+ throw new Errors.AppManagerNotInitError();
743
720
  }
744
721
  }
745
722
 
@@ -807,11 +784,9 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
807
784
  }
808
785
 
809
786
  private _destroy() {
810
- this.containerResizeObserver?.disconnect();
811
787
  this.appManager?.destroy();
812
788
  this.cursorManager?.destroy();
813
789
  WindowManager.container = undefined;
814
- WindowManager.wrapper = undefined;
815
790
  WindowManager.isCreated = false;
816
791
  if (WindowManager.playground) {
817
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
- }