@netless/window-manager 1.0.12 → 1.0.13-bate.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.
package/dist/index.mjs CHANGED
@@ -5695,6 +5695,35 @@ const log = (...args) => {
5695
5695
  console.log(`[WindowManager]:`, ...args);
5696
5696
  }
5697
5697
  };
5698
+ class LocalConsole {
5699
+ constructor(name, debounceTime) {
5700
+ this.name = name;
5701
+ this.debounceTime = debounceTime;
5702
+ this.pendingArgs = null;
5703
+ this.flushTimer = null;
5704
+ }
5705
+ flush() {
5706
+ this.flushTimer = null;
5707
+ const args = this.pendingArgs;
5708
+ this.pendingArgs = null;
5709
+ if (args === null) {
5710
+ return;
5711
+ }
5712
+ console.log(`[window-manager][${this.name}]: ${args.join(", ")}`);
5713
+ }
5714
+ log(...args) {
5715
+ const ms = this.debounceTime;
5716
+ if (ms != null && ms > 0) {
5717
+ this.pendingArgs = args;
5718
+ if (this.flushTimer != null) {
5719
+ clearTimeout(this.flushTimer);
5720
+ }
5721
+ this.flushTimer = setTimeout(() => this.flush(), ms);
5722
+ return;
5723
+ }
5724
+ console.log(`[window-manager][${this.name}]: ${args.join(", ")}`);
5725
+ }
5726
+ }
5698
5727
  const setupWrapper = (root) => {
5699
5728
  const playground = document.createElement("div");
5700
5729
  playground.className = "netless-window-manager-playground";
@@ -7002,6 +7031,7 @@ var Fields = /* @__PURE__ */ ((Fields2) => {
7002
7031
  class AttributesDelegate {
7003
7032
  constructor(context) {
7004
7033
  this.context = context;
7034
+ this.setMainViewCameraConsole = new LocalConsole("setMainViewCamera", 30);
7005
7035
  this.setAppFocus = (appId, focus) => {
7006
7036
  if (focus) {
7007
7037
  this.context.safeSetAttributes({ ["focus"]: appId });
@@ -7139,6 +7169,7 @@ class AttributesDelegate {
7139
7169
  return get(this.attributes, ["mainViewSize"]);
7140
7170
  }
7141
7171
  setMainViewCamera(camera) {
7172
+ this.setMainViewCameraConsole.log(JSON.stringify(camera));
7142
7173
  this.context.safeSetAttributes({ ["mainViewCamera"]: { ...camera } });
7143
7174
  }
7144
7175
  setMainViewSize(size2) {
@@ -7372,6 +7403,9 @@ const _AppProxy = class {
7372
7403
  get appAttributes() {
7373
7404
  return this.store.getAppAttributes(this.id);
7374
7405
  }
7406
+ get Logger() {
7407
+ return this.manager.windowManger.Logger;
7408
+ }
7375
7409
  getFullScenePath() {
7376
7410
  if (this.scenePath) {
7377
7411
  return get(this.appAttributes, [Fields.FullPath]) || this.getFullScenePathFromScenes();
@@ -7392,6 +7426,7 @@ const _AppProxy = class {
7392
7426
  var _a;
7393
7427
  const params = this.params;
7394
7428
  if (!params.kind) {
7429
+ this.Logger && this.Logger.error(`[WindowManager]: kind require`);
7395
7430
  throw new Error("[WindowManager]: kind require");
7396
7431
  }
7397
7432
  const appImpl = await ((_a = appRegister.appClasses.get(params.kind)) == null ? void 0 : _a());
@@ -7409,6 +7444,7 @@ const _AppProxy = class {
7409
7444
  params.isDragContent
7410
7445
  );
7411
7446
  } else {
7447
+ this.Logger && this.Logger.error(`[WindowManager]: app load failed ${params.kind} ${params.src}`);
7412
7448
  throw new Error(`[WindowManager]: app load failed ${params.kind} ${params.src}`);
7413
7449
  }
7414
7450
  internalEmitter.emit("updateManagerRect");
@@ -7446,7 +7482,7 @@ const _AppProxy = class {
7446
7482
  currentMainViewScenePath = this.manager.mainView.scenePath;
7447
7483
  }
7448
7484
  setTimeout(async () => {
7449
- console.log("setup app", app);
7485
+ this.Logger && this.Logger.info(`[WindowManager]: setup app ${this.kind}, appId: ${appId}`);
7450
7486
  const result = await app.setup(context);
7451
7487
  this.appResult = result;
7452
7488
  appRegister.notifyApp(this.kind, "created", { appId, result });
@@ -7481,7 +7517,7 @@ const _AppProxy = class {
7481
7517
  this.boxManager.focusBox({ appId }, false);
7482
7518
  }
7483
7519
  } catch (error) {
7484
- console.error(error);
7520
+ this.Logger && this.Logger.error(`[WindowManager]: app setup error: ${error.message}`);
7485
7521
  throw new Error(`[WindowManager]: app setup error: ${error.message}`);
7486
7522
  }
7487
7523
  }
@@ -7660,6 +7696,7 @@ const _AppProxy = class {
7660
7696
  await appRegister.notifyApp(this.kind, "destroy", { appId: this.id });
7661
7697
  await this.appEmitter.emit("destroy", { error });
7662
7698
  } catch (error2) {
7699
+ this.Logger && this.Logger.error(`[WindowManager]: notifyApp error: ${error2.message}`);
7663
7700
  console.error("[WindowManager]: notifyApp error", error2.message, error2.stack);
7664
7701
  }
7665
7702
  this.appEmitter.clearListeners();
@@ -7681,6 +7718,7 @@ const _AppProxy = class {
7681
7718
  this.manager.refresher.remove(this.stateKey);
7682
7719
  this.manager.refresher.remove(`${this.id}-fullPath`);
7683
7720
  this._prevFullPath = void 0;
7721
+ this.Logger && this.Logger.info(`[WindowManager]: destroy app ${this.kind} appId: ${this.id}`);
7684
7722
  }
7685
7723
  close() {
7686
7724
  return this.destroy(true, true, false);
@@ -7744,9 +7782,14 @@ class MainViewProxy {
7744
7782
  this.polling = false;
7745
7783
  this.started = false;
7746
7784
  this.mainViewIsAddListener = false;
7785
+ this.isForcingMainViewDivElement = false;
7786
+ this.wrapperRectWorkaroundFrame = 0;
7747
7787
  this.store = this.manager.store;
7748
7788
  this.viewMode = this.manager.windowManger.viewMode;
7749
7789
  this.sideEffectManager = new o$2();
7790
+ this.playgroundSizeChangeListenerLocalConsole = new LocalConsole("playgroundSizeChangeListener", 30);
7791
+ this.sizeUpdatedLocalConsole = new LocalConsole("sizeUpdated", 30);
7792
+ this.cameraUpdatedLocalConsole = new LocalConsole("cameraUpdated", 30);
7750
7793
  this.syncCamera = () => {
7751
7794
  if (!this.polling || this.viewMode !== ViewMode.Broadcaster)
7752
7795
  return;
@@ -7766,6 +7809,32 @@ class MainViewProxy {
7766
7809
  });
7767
7810
  });
7768
7811
  };
7812
+ this.onWrapperRectChange = (payload) => {
7813
+ this.pendingWrapperRectChange = payload;
7814
+ if (this.wrapperRectWorkaroundFrame) {
7815
+ cancelAnimationFrame(this.wrapperRectWorkaroundFrame);
7816
+ }
7817
+ this.wrapperRectWorkaroundFrame = requestAnimationFrame(this.runWrapperRectWorkaround);
7818
+ };
7819
+ this.runWrapperRectWorkaround = () => {
7820
+ this.wrapperRectWorkaroundFrame = 0;
7821
+ const payload = this.pendingWrapperRectChange;
7822
+ const element2 = this.mainView.divElement;
7823
+ this.pendingWrapperRectChange = void 0;
7824
+ if (!payload || !element2)
7825
+ return;
7826
+ const rect = element2.getBoundingClientRect();
7827
+ const observedSize = { width: rect.width, height: rect.height };
7828
+ const wrapperMatchesDom = Math.abs(payload.width - observedSize.width) <= 0.5 && Math.abs(payload.height - observedSize.height) <= 0.5;
7829
+ const viewIsStale = Math.abs(this.mainView.size.width - observedSize.width) > 0.5 || Math.abs(this.mainView.size.height - observedSize.height) > 0.5;
7830
+ if (wrapperMatchesDom && viewIsStale) {
7831
+ this.forceSyncMainViewDivElement(
7832
+ `wrapperRectChange:${payload.origin || "unknown"}`,
7833
+ observedSize,
7834
+ element2
7835
+ );
7836
+ }
7837
+ };
7769
7838
  this.addCameraReaction = () => {
7770
7839
  this.manager.refresher.add(Fields.MainViewCamera, this.cameraReaction);
7771
7840
  };
@@ -7774,6 +7843,7 @@ class MainViewProxy {
7774
7843
  () => this.mainViewCamera,
7775
7844
  (camera) => {
7776
7845
  if (camera && camera.id !== this.manager.uid) {
7846
+ console.log("[window-manager] cameraReaction " + JSON.stringify(camera) + JSON.stringify(this.mainViewSize));
7777
7847
  this.moveCameraToContian(this.mainViewSize);
7778
7848
  this.moveCamera(camera);
7779
7849
  }
@@ -7785,11 +7855,13 @@ class MainViewProxy {
7785
7855
  if (size2) {
7786
7856
  this.moveCameraToContian(size2);
7787
7857
  this.moveCamera(this.mainViewCamera);
7858
+ console.log("[window-manager] sizeChangeHandler current size and camera" + JSON.stringify(size2) + JSON.stringify(this.mainViewCamera) + JSON.stringify(this.mainView.camera) + JSON.stringify(this.mainView.size));
7788
7859
  }
7789
7860
  this.ensureMainViewSize();
7790
7861
  }, 30);
7791
7862
  this.onUpdateContainerSizeRatio = () => {
7792
7863
  const size2 = this.store.getMainViewSize();
7864
+ console.log("[window-manager] onUpdateContainerSizeRatio " + JSON.stringify(size2));
7793
7865
  this.sizeChangeHandler(size2);
7794
7866
  };
7795
7867
  this.onCameraUpdatedByDevice = (camera) => {
@@ -7807,7 +7879,7 @@ class MainViewProxy {
7807
7879
  this.store.setMainViewSize({ ...size2, id: this.manager.uid });
7808
7880
  }, 50);
7809
7881
  this._syncMainViewTimer = 0;
7810
- this.onCameraOrSizeUpdated = () => {
7882
+ this.handleCameraOrSizeUpdated = () => {
7811
7883
  callbacks$1.emit("cameraStateChange", this.cameraState);
7812
7884
  if (this.manager.room && this.manager.room.syncMainView) {
7813
7885
  clearTimeout(this._syncMainViewTimer);
@@ -7815,6 +7887,14 @@ class MainViewProxy {
7815
7887
  }
7816
7888
  this.ensureMainViewSize();
7817
7889
  };
7890
+ this.onCameraUpdated = (camera) => {
7891
+ this.cameraUpdatedLocalConsole.log(JSON.stringify(camera));
7892
+ this.handleCameraOrSizeUpdated();
7893
+ };
7894
+ this.onSizeUpdated = (size2) => {
7895
+ this.sizeUpdatedLocalConsole.log(JSON.stringify(size2));
7896
+ this.handleCameraOrSizeUpdated();
7897
+ };
7818
7898
  this.syncMainView = (room) => {
7819
7899
  if (room.isWritable) {
7820
7900
  room.syncMainView(this.mainView);
@@ -7832,6 +7912,19 @@ class MainViewProxy {
7832
7912
  this.startListenWritableChange();
7833
7913
  });
7834
7914
  const playgroundSizeChangeListener = () => {
7915
+ var _a, _b, _c, _d, _e, _f, _g, _h;
7916
+ this.playgroundSizeChangeListenerLocalConsole.log(
7917
+ JSON.stringify(this.mainView.camera),
7918
+ JSON.stringify(this.mainView.size),
7919
+ JSON.stringify(this.mainViewSize),
7920
+ JSON.stringify(this.mainViewCamera),
7921
+ window.outerHeight,
7922
+ window.outerWidth,
7923
+ (_b = (_a = window.visualViewport) == null ? void 0 : _a.width) != null ? _b : "null",
7924
+ (_d = (_c = window.visualViewport) == null ? void 0 : _c.height) != null ? _d : "null",
7925
+ (_f = (_e = window.visualViewport) == null ? void 0 : _e.offsetLeft) != null ? _f : "null",
7926
+ (_h = (_g = window.visualViewport) == null ? void 0 : _g.offsetTop) != null ? _h : "null"
7927
+ );
7835
7928
  this.sizeChangeHandler(this.mainViewSize);
7836
7929
  };
7837
7930
  this.sideEffectManager.add(() => {
@@ -7840,6 +7933,9 @@ class MainViewProxy {
7840
7933
  this.sideEffectManager.add(() => {
7841
7934
  return internalEmitter.on("containerSizeRatioUpdate", this.onUpdateContainerSizeRatio);
7842
7935
  });
7936
+ this.sideEffectManager.add(() => {
7937
+ return internalEmitter.on("wrapperRectChange", this.onWrapperRectChange);
7938
+ });
7843
7939
  this.sideEffectManager.add(() => {
7844
7940
  return internalEmitter.on("startReconnect", () => {
7845
7941
  if (!this.didRelease) {
@@ -7870,7 +7966,34 @@ class MainViewProxy {
7870
7966
  this.moveCameraToContian(this.mainViewSize);
7871
7967
  this.moveCamera(this.mainViewCamera);
7872
7968
  }
7969
+ forceSyncMainViewDivElement(reason, observedSize, element2) {
7970
+ const { width: viewWidth, height: viewHeight } = this.mainView.size;
7971
+ if (Math.abs(viewWidth - observedSize.width) <= 0.5 && Math.abs(viewHeight - observedSize.height) <= 0.5) {
7972
+ return;
7973
+ }
7974
+ if (this.isForcingMainViewDivElement) {
7975
+ console.log("[window-manager] skipForceSyncMainViewDivElement " + JSON.stringify({
7976
+ reason,
7977
+ observedSize,
7978
+ viewSize: this.mainView.size
7979
+ }));
7980
+ return;
7981
+ }
7982
+ this.isForcingMainViewDivElement = true;
7983
+ this.mainView.divElement = null;
7984
+ this.mainView.divElement = element2;
7985
+ queueMicrotask(() => {
7986
+ const rect = element2.getBoundingClientRect();
7987
+ console.log("[window-manager] forceSyncMainViewDivElementResult " + JSON.stringify({
7988
+ reason,
7989
+ viewSize: this.mainView.size,
7990
+ rect: { width: rect.width, height: rect.height }
7991
+ }));
7992
+ this.isForcingMainViewDivElement = false;
7993
+ });
7994
+ }
7873
7995
  start() {
7996
+ console.log("[window-manager] start attributes size:" + JSON.stringify(this.mainViewSize));
7874
7997
  this.sizeChangeHandler(this.mainViewSize);
7875
7998
  if (this.started)
7876
7999
  return;
@@ -7879,6 +8002,10 @@ class MainViewProxy {
7879
8002
  if (this.manager.room)
7880
8003
  this.syncMainView(this.manager.room);
7881
8004
  this.started = true;
8005
+ if (this.mainView.focusScenePath) {
8006
+ this.manager.windowManger.onMainViewScenePathChangeHandler(this.mainView.focusScenePath);
8007
+ }
8008
+ console.log("[window-manager] start end mainView size:" + JSON.stringify(this.mainView.size));
7882
8009
  }
7883
8010
  setCameraAndSize() {
7884
8011
  const camera = { ...this.mainView.camera, id: this.manager.uid };
@@ -7952,13 +8079,13 @@ class MainViewProxy {
7952
8079
  }
7953
8080
  addCameraListener() {
7954
8081
  this.view.callbacks.on("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
7955
- this.view.callbacks.on("onCameraUpdated", this.onCameraOrSizeUpdated);
7956
- this.view.callbacks.on("onSizeUpdated", this.onCameraOrSizeUpdated);
8082
+ this.view.callbacks.on("onCameraUpdated", this.onCameraUpdated);
8083
+ this.view.callbacks.on("onSizeUpdated", this.onSizeUpdated);
7957
8084
  }
7958
8085
  removeCameraListener() {
7959
8086
  this.view.callbacks.off("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
7960
- this.view.callbacks.off("onCameraUpdated", this.onCameraOrSizeUpdated);
7961
- this.view.callbacks.off("onSizeUpdated", this.onCameraOrSizeUpdated);
8087
+ this.view.callbacks.off("onCameraUpdated", this.onCameraUpdated);
8088
+ this.view.callbacks.off("onSizeUpdated", this.onSizeUpdated);
7962
8089
  }
7963
8090
  ensureMainViewSize() {
7964
8091
  if ((!this.mainViewSize || this.mainViewSize.width === 0 || this.mainViewSize.height === 0) && this.mainView.size.width > 0 && this.mainView.size.height > 0) {
@@ -7998,6 +8125,11 @@ class MainViewProxy {
7998
8125
  this.started = false;
7999
8126
  }
8000
8127
  destroy() {
8128
+ console.log("[window-manager] destroy ");
8129
+ if (this.wrapperRectWorkaroundFrame) {
8130
+ cancelAnimationFrame(this.wrapperRectWorkaroundFrame);
8131
+ this.wrapperRectWorkaroundFrame = 0;
8132
+ }
8001
8133
  this.removeMainViewListener();
8002
8134
  this.stop();
8003
8135
  this.sideEffectManager.flushAll();
@@ -8087,6 +8219,7 @@ class AppManager {
8087
8219
  var _a, _b;
8088
8220
  const { scenePath } = params;
8089
8221
  if (scenePath === ROOT_DIR) {
8222
+ console.log("[window-manager] onRemoveScenes ROOT_DIR");
8090
8223
  await this.onRootDirRemoved();
8091
8224
  this.dispatchInternalEvent(Events.RootDirRemoved);
8092
8225
  return;
@@ -8099,6 +8232,7 @@ class AppManager {
8099
8232
  sceneName = (_b = this.callbacksNode) == null ? void 0 : _b.scenes[nextIndex];
8100
8233
  }
8101
8234
  if (sceneName) {
8235
+ console.log(`[window-manager] onRemoveScenes setMainViewScenePath ${ROOT_DIR}${sceneName}`);
8102
8236
  this.setMainViewScenePath(`${ROOT_DIR}${sceneName}`);
8103
8237
  }
8104
8238
  await this.setMainViewSceneIndex(nextIndex);
@@ -8491,6 +8625,9 @@ class AppManager {
8491
8625
  var _a;
8492
8626
  return ((_a = this.room) == null ? void 0 : _a.uid) || "";
8493
8627
  }
8628
+ get Logger() {
8629
+ return this.windowManger.Logger;
8630
+ }
8494
8631
  getMainViewSceneDir() {
8495
8632
  const scenePath = this.store.getMainViewScenePath();
8496
8633
  if (scenePath) {
@@ -8607,6 +8744,9 @@ class AppManager {
8607
8744
  try {
8608
8745
  const appAttributes = this.attributes[id2];
8609
8746
  if (!appAttributes) {
8747
+ this.Logger && this.Logger.error(
8748
+ `[WindowManager]: appAttributes is undefined, appId: ${id2}`
8749
+ );
8610
8750
  throw new Error("appAttributes is undefined");
8611
8751
  }
8612
8752
  this.appCreateQueue.push(async () => {
@@ -8662,6 +8802,28 @@ class AppManager {
8662
8802
  }
8663
8803
  internalEmitter.emit("mainViewMounted");
8664
8804
  callbacks$1.emit("onMainViewMounted", mainView);
8805
+ const hasRoot = this.hasRoot(mainView.divElement);
8806
+ const rect = this.getRectByDivElement(mainView.divElement);
8807
+ let log2 = `[window-manager] bindMainView hasRoot:${hasRoot}, rect:${JSON.stringify(rect)}, outerHeight:${window.outerHeight}, outerWidth:${window.outerWidth}`;
8808
+ const visualViewport = window.visualViewport;
8809
+ if (visualViewport) {
8810
+ log2 += `, visualViewportWidth:${visualViewport.width}, visualViewportHeight:${visualViewport.height}, visualViewportOffsetLeft:${visualViewport.offsetLeft}, visualViewportOffsetTop:${visualViewport.offsetTop}`;
8811
+ }
8812
+ console.log(log2);
8813
+ }
8814
+ hasRoot(divElement) {
8815
+ let current = divElement;
8816
+ while (current) {
8817
+ if (current.parentElement === document.body) {
8818
+ return true;
8819
+ }
8820
+ current = current.parentElement;
8821
+ }
8822
+ return false;
8823
+ }
8824
+ getRectByDivElement(divElement) {
8825
+ const rect = divElement.getBoundingClientRect();
8826
+ return rect;
8665
8827
  }
8666
8828
  setMainViewFocusPath(scenePath) {
8667
8829
  var _a;
@@ -8678,7 +8840,11 @@ class AppManager {
8678
8840
  }
8679
8841
  }
8680
8842
  async addApp(params, isDynamicPPT) {
8843
+ var _a;
8681
8844
  log("addApp", params);
8845
+ (_a = this.windowManger.Logger) == null ? void 0 : _a.info(
8846
+ `[WindowManager]: addApp ${params.kind}, isDynamicPPT: ${isDynamicPPT}`
8847
+ );
8682
8848
  const { appId, needFocus } = await this.beforeAddApp(params, isDynamicPPT);
8683
8849
  const appProxy = await this.baseInsertApp(params, appId, true, needFocus);
8684
8850
  this.afterAddApp(appProxy);
@@ -8719,8 +8885,11 @@ class AppManager {
8719
8885
  }
8720
8886
  }
8721
8887
  async baseInsertApp(params, appId, isAddApp, focus) {
8888
+ var _a;
8722
8889
  if (this.appProxies.has(appId)) {
8723
- console.warn("[WindowManager]: app duplicate exists and cannot be created again");
8890
+ (_a = this.windowManger.Logger) == null ? void 0 : _a.warn(
8891
+ `[WindowManager]: app duplicate exists and cannot be created again, appId: ${appId}`
8892
+ );
8724
8893
  return;
8725
8894
  }
8726
8895
  const AppProxyClass = getExtendClass$1(AppProxy, WindowManager.extendClass);
@@ -8731,6 +8900,7 @@ class AppManager {
8731
8900
  return appProxy;
8732
8901
  } else {
8733
8902
  this.appStatus.delete(appId);
8903
+ this.Logger && this.Logger.error(`[WindowManager]: initialize AppProxy failed, appId: ${appId}`);
8734
8904
  throw new Error("[WindowManger]: initialize AppProxy failed");
8735
8905
  }
8736
8906
  }
@@ -8745,9 +8915,11 @@ class AppManager {
8745
8915
  const scenePathType = this.displayer.scenePathType(scenePath);
8746
8916
  const sceneDir = parseSceneDir(scenePath);
8747
8917
  if (sceneDir !== ROOT_DIR) {
8918
+ this.Logger && this.Logger.error(`[WindowManager]: main view scenePath must in root dir "/"`);
8748
8919
  throw new Error(`[WindowManager]: main view scenePath must in root dir "/"`);
8749
8920
  }
8750
8921
  if (scenePathType === ScenePathType.None) {
8922
+ this.Logger && this.Logger.error(`[WindowManager]: ${scenePath} not valid scene`);
8751
8923
  throw new Error(`[WindowManager]: ${scenePath} not valid scene`);
8752
8924
  } else if (scenePathType === ScenePathType.Page) {
8753
8925
  await this._setMainViewScenePath(scenePath);
@@ -8783,6 +8955,7 @@ class AppManager {
8783
8955
  this.dispatchSetMainViewScenePath(scenePath);
8784
8956
  }
8785
8957
  } else {
8958
+ this.Logger && this.Logger.error(`[WindowManager]: ${index2} not valid index`);
8786
8959
  throw new Error(`[WindowManager]: ${index2} not valid index`);
8787
8960
  }
8788
8961
  }
@@ -8863,6 +9036,7 @@ const ResizeObserver$2 = window.ResizeObserver || ResizeObserver$3;
8863
9036
  class ContainerResizeObserver {
8864
9037
  constructor(emitter) {
8865
9038
  this.emitter = emitter;
9039
+ this.updateSizerLocalConsole = new LocalConsole("updateSizer", 30);
8866
9040
  }
8867
9041
  static create(container, sizer, wrapper, emitter) {
8868
9042
  const containerResizeObserver = new ContainerResizeObserver(emitter);
@@ -8870,23 +9044,23 @@ class ContainerResizeObserver {
8870
9044
  return containerResizeObserver;
8871
9045
  }
8872
9046
  observePlaygroundSize(container, sizer, wrapper) {
8873
- this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
9047
+ this.updateSizer(container.getBoundingClientRect(), sizer, wrapper, "observePlaygroundSize");
8874
9048
  this.containerResizeObserver = new ResizeObserver$2((entries) => {
8875
9049
  var _a;
8876
9050
  const containerRect = (_a = entries[0]) == null ? void 0 : _a.contentRect;
8877
9051
  if (containerRect) {
8878
- this.updateSizer(containerRect, sizer, wrapper);
9052
+ this.updateSizer(containerRect, sizer, wrapper, "containerResizeObserver");
8879
9053
  this.emitter.emit("playgroundSizeChange", containerRect);
8880
9054
  }
8881
9055
  });
8882
9056
  this.disposer = this.emitter.on("containerSizeRatioUpdate", () => {
8883
9057
  const containerRect = container.getBoundingClientRect();
8884
- this.updateSizer(containerRect, sizer, wrapper);
9058
+ this.updateSizer(containerRect, sizer, wrapper, "containerSizeRatioUpdate");
8885
9059
  this.emitter.emit("playgroundSizeChange", containerRect);
8886
9060
  });
8887
9061
  this.containerResizeObserver.observe(container);
8888
9062
  }
8889
- updateSizer({ width, height }, sizer, wrapper) {
9063
+ updateSizer({ width, height }, sizer, wrapper, origin) {
8890
9064
  if (width && height) {
8891
9065
  if (height / width > WindowManager.containerSizeRatio) {
8892
9066
  height = width * WindowManager.containerSizeRatio;
@@ -8897,6 +9071,13 @@ class ContainerResizeObserver {
8897
9071
  }
8898
9072
  wrapper.style.width = `${width}px`;
8899
9073
  wrapper.style.height = `${height}px`;
9074
+ const wrapperRect = wrapper.getBoundingClientRect();
9075
+ this.updateSizerLocalConsole.log(`from ${origin}, traget size: ${JSON.stringify({ width, height })}, wrapperRect: ${wrapperRect.width} ${wrapperRect.height}`);
9076
+ this.emitter.emit("wrapperRectChange", {
9077
+ width: wrapperRect.width,
9078
+ height: wrapperRect.height,
9079
+ origin
9080
+ });
8900
9081
  }
8901
9082
  }
8902
9083
  disconnect() {
@@ -9053,6 +9234,29 @@ const replaceRoomFunction = (room, manager) => {
9053
9234
  return manager.canRedoSteps;
9054
9235
  }
9055
9236
  });
9237
+ const _scalePptToFit = room.scalePptToFit;
9238
+ room.scalePptToFit = (...args) => {
9239
+ var _a;
9240
+ _scalePptToFit.call(room, ...args);
9241
+ if ((_a = manager.appManager) == null ? void 0 : _a.mainViewProxy) {
9242
+ manager.appManager.mainViewProxy.setCameraAndSize();
9243
+ }
9244
+ };
9245
+ const _putScenes = room.putScenes;
9246
+ room.putScenes = (...args) => {
9247
+ const [path, scenes] = args;
9248
+ const currentScenePath = manager.mainView.focusScenePath;
9249
+ if (currentScenePath && path && scenes) {
9250
+ console.log("[window-manager] putScenes " + JSON.stringify(args));
9251
+ for (const scene of scenes) {
9252
+ if (`${path}${scene.name}` === currentScenePath) {
9253
+ console.error(`[window-manager] putScenes: scene name can not be the same as the current scene path: ${currentScenePath}`);
9254
+ return;
9255
+ }
9256
+ }
9257
+ }
9258
+ return _putScenes.call(room, ...args);
9259
+ };
9056
9260
  room.moveCamera = (camera) => manager.moveCamera(camera);
9057
9261
  room.moveCameraToContain = (...args) => manager.moveCameraToContain(...args);
9058
9262
  room.convertToPointInWorld = (...args) => manager.mainView.convertToPointInWorld(...args);
@@ -19643,20 +19847,42 @@ const reconnectRefresher = new ReconnectRefresher({ emitter: internalEmitter });
19643
19847
  const _WindowManager = class extends InvisiblePlugin {
19644
19848
  constructor(context) {
19645
19849
  super(context);
19646
- this.version = "1.0.12";
19647
- this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.3.0", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "jspdf": "2.5.1", "white-web-sdk": "^2.16.52" }, "devDependencies": { "@hyrious/dts": "^0.2.2", "@netless/app-docs-viewer": "^0.2.19", "@netless/app-media-player": "0.1.4", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "1.0.0-next.30", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "jspdf": "^2.5.1", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "side-effect-manager": "0.1.5", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.9.9", "vitest": "^0.14.1", "white-web-sdk": "^2.16.52" } };
19850
+ this.version = "1.0.13-bate.0";
19851
+ this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.3.0", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "jspdf": "2.5.1", "white-web-sdk": "^2.16.53" }, "devDependencies": { "@hyrious/dts": "^0.2.2", "@netless/app-docs-viewer": "^0.2.19", "@netless/app-media-player": "0.1.4", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "1.0.0-next.30", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "jspdf": "^2.5.1", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "side-effect-manager": "0.1.5", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.9.9", "vitest": "^0.14.1", "white-web-sdk": "^2.16.53" } };
19648
19852
  this.emitter = callbacks$1;
19649
19853
  this.viewMode = ViewMode.Broadcaster;
19650
19854
  this.isReplay = isPlayer(this.displayer);
19651
19855
  this._cursorUIDs = [];
19652
19856
  this.containerSizeRatio = _WindowManager.containerSizeRatio;
19857
+ this.onMainViewScenePathChangeHandler = (scenePath) => {
19858
+ const mainViewElement = this.mainView.divElement;
19859
+ if (mainViewElement) {
19860
+ const backgroundImage = mainViewElement.querySelector(".background img");
19861
+ if (backgroundImage) {
19862
+ const backgroundImageRect = backgroundImage == null ? void 0 : backgroundImage.getBoundingClientRect();
19863
+ const backgroundImageCSS = window.getComputedStyle(backgroundImage);
19864
+ const backgroundImageVisible = (backgroundImageRect == null ? void 0 : backgroundImageRect.width) > 0 && (backgroundImageRect == null ? void 0 : backgroundImageRect.height) > 0 && backgroundImageCSS.display !== "none";
19865
+ const camera = this.mainView.camera;
19866
+ console.log("[window-manager] backgroundImageVisible:" + backgroundImageVisible + " camera:" + JSON.stringify(camera));
19867
+ return;
19868
+ }
19869
+ console.log("[window-manager] onMainViewScenePathChange scenePath:" + scenePath + " backgroundImageVisible is not found");
19870
+ return;
19871
+ }
19872
+ console.log("[window-manager] onMainViewScenePathChange scenePath:" + scenePath + " mainViewElement is not found");
19873
+ };
19653
19874
  _WindowManager.displayer = context.displayer;
19654
- window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.3.0", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "jspdf": "2.5.1", "white-web-sdk": "^2.16.52" }, "devDependencies": { "@hyrious/dts": "^0.2.2", "@netless/app-docs-viewer": "^0.2.19", "@netless/app-media-player": "0.1.4", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "1.0.0-next.30", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "jspdf": "^2.5.1", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "side-effect-manager": "0.1.5", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.9.9", "vitest": "^0.14.1", "white-web-sdk": "^2.16.52" } };
19875
+ window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.3.0", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "jspdf": "2.5.1", "white-web-sdk": "^2.16.53" }, "devDependencies": { "@hyrious/dts": "^0.2.2", "@netless/app-docs-viewer": "^0.2.19", "@netless/app-media-player": "0.1.4", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "1.0.0-next.30", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "jspdf": "^2.5.1", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "side-effect-manager": "0.1.5", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.9.9", "vitest": "^0.14.1", "white-web-sdk": "^2.16.53" } };
19876
+ this.emitter.on("mainViewScenePathChange", this.onMainViewScenePathChangeHandler);
19877
+ }
19878
+ get Logger() {
19879
+ return this._roomLogger;
19655
19880
  }
19656
19881
  static onCreate(manager) {
19657
19882
  _WindowManager._resolve(manager);
19658
19883
  }
19659
19884
  static async mount(params, extendClass) {
19885
+ var _a;
19660
19886
  const room = params.room;
19661
19887
  _WindowManager.container = params.container;
19662
19888
  _WindowManager.supportAppliancePlugin = params.supportAppliancePlugin;
@@ -19676,6 +19902,16 @@ const _WindowManager = class extends InvisiblePlugin {
19676
19902
  room.disableSerialization = false;
19677
19903
  }
19678
19904
  manager = await this.initManager(room);
19905
+ if (manager) {
19906
+ manager._roomLogger = room.logger;
19907
+ if (_WindowManager.registered.size > 0) {
19908
+ manager._roomLogger.info(
19909
+ `[WindowManager] registered apps: ${JSON.stringify(
19910
+ Array.from(_WindowManager.registered.keys())
19911
+ )}`
19912
+ );
19913
+ }
19914
+ }
19679
19915
  }
19680
19916
  if (_WindowManager.isCreated) {
19681
19917
  throw new Error("[WindowManager]: Already created cannot be created again");
@@ -19684,7 +19920,13 @@ const _WindowManager = class extends InvisiblePlugin {
19684
19920
  if (this.debug) {
19685
19921
  v({ verbose: true });
19686
19922
  }
19687
- log("Already insert room", manager);
19923
+ if (manager == null ? void 0 : manager._roomLogger) {
19924
+ manager._roomLogger.info(
19925
+ `[WindowManager] Already insert room version: ${manager.version}`
19926
+ );
19927
+ } else {
19928
+ log("Already insert room", manager);
19929
+ }
19688
19930
  if (isRoom(this.displayer)) {
19689
19931
  if (!manager) {
19690
19932
  throw new Error("[WindowManager]: init InvisiblePlugin failed");
@@ -19733,12 +19975,21 @@ const _WindowManager = class extends InvisiblePlugin {
19733
19975
  replaceRoomFunction(room, manager);
19734
19976
  internalEmitter.emit("onCreated");
19735
19977
  _WindowManager.isCreated = true;
19978
+ if (manager._roomLogger && manager.attributes.registered && Object.keys(manager.attributes.registered).length > 0) {
19979
+ manager._roomLogger.info(
19980
+ `[WindowManager] attributes registered apps: ${JSON.stringify(
19981
+ Array.from(Object.keys(manager.attributes.registered))
19982
+ )}`
19983
+ );
19984
+ }
19736
19985
  try {
19737
19986
  await initDb();
19738
19987
  } catch (error) {
19988
+ (_a = manager._roomLogger) == null ? void 0 : _a.warn(`[WindowManager] indexedDB open failed: ${error.message}`);
19739
19989
  console.warn("[WindowManager]: indexedDB open failed");
19740
19990
  console.log(error);
19741
19991
  }
19992
+ manager.emitter.on("mainViewScenePathChange", manager.onMainViewScenePathChangeHandler);
19742
19993
  return manager;
19743
19994
  }
19744
19995
  static initManager(room) {
@@ -20299,6 +20550,7 @@ const _WindowManager = class extends InvisiblePlugin {
20299
20550
  (_e = _WindowManager.playground.parentNode) == null ? void 0 : _e.removeChild(_WindowManager.playground);
20300
20551
  }
20301
20552
  _WindowManager.params = void 0;
20553
+ this.emitter.off("mainViewScenePathChange", this.onMainViewScenePathChangeHandler);
20302
20554
  (_f = this._iframeBridge) == null ? void 0 : _f.destroy();
20303
20555
  this._iframeBridge = void 0;
20304
20556
  log("Destroyed");
@@ -20322,11 +20574,13 @@ const _WindowManager = class extends InvisiblePlugin {
20322
20574
  }
20323
20575
  safeSetAttributes(attributes) {
20324
20576
  if (this.canOperate) {
20577
+ this.Logger && this.Logger.info(`[WindowManager]: safeSetAttributes ${JSON.stringify(attributes)}`);
20325
20578
  this.setAttributes(attributes);
20326
20579
  }
20327
20580
  }
20328
20581
  safeUpdateAttributes(keys, value) {
20329
20582
  if (this.canOperate) {
20583
+ this.Logger && this.Logger.info(`[WindowManager]: safeUpdateAttributes ${keys.join(", ")} ${value}`);
20330
20584
  this.updateAttributes(keys, value);
20331
20585
  }
20332
20586
  }
@@ -20335,9 +20589,10 @@ const _WindowManager = class extends InvisiblePlugin {
20335
20589
  (_b = (_a = this.appManager) == null ? void 0 : _a.boxManager) == null ? void 0 : _b.setPrefersColorScheme(scheme);
20336
20590
  }
20337
20591
  cleanCurrentScene() {
20338
- var _a;
20592
+ var _a, _b;
20339
20593
  log("clean current scene");
20340
- (_a = this.focusedView) == null ? void 0 : _a.cleanCurrentScene();
20594
+ this.Logger && this.Logger.info(`[WindowManager]: cleanCurrentScene ${(_a = this.focusedView) == null ? void 0 : _a.focusScenePath}`);
20595
+ (_b = this.focusedView) == null ? void 0 : _b.cleanCurrentScene();
20341
20596
  }
20342
20597
  redo() {
20343
20598
  var _a;
@@ -20348,8 +20603,9 @@ const _WindowManager = class extends InvisiblePlugin {
20348
20603
  return ((_a = this.focusedView) == null ? void 0 : _a.undo()) || 0;
20349
20604
  }
20350
20605
  delete() {
20351
- var _a;
20352
- (_a = this.focusedView) == null ? void 0 : _a.delete();
20606
+ var _a, _b;
20607
+ this.Logger && this.Logger.info(`[WindowManager]: delete ${(_a = this.focusedView) == null ? void 0 : _a.focusScenePath}`);
20608
+ (_b = this.focusedView) == null ? void 0 : _b.delete();
20353
20609
  }
20354
20610
  copy() {
20355
20611
  var _a;