@netless/window-manager 1.0.13-test.9 → 1.0.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.
package/dist/index.mjs CHANGED
@@ -352,7 +352,6 @@ const setScenePath = (room, scenePath) => {
352
352
  if (room && room.isWritable) {
353
353
  if (room.state.sceneState.scenePath !== scenePath) {
354
354
  const nextScenePath = scenePath === "/" ? "" : scenePath;
355
- console.log("[window-manager] real setScenePath for current room ", nextScenePath);
356
355
  room.setScenePath(nextScenePath);
357
356
  }
358
357
  }
@@ -464,7 +463,6 @@ class AppListeners {
464
463
  break;
465
464
  }
466
465
  case Events.SetMainViewScenePath: {
467
- console.log("[window-manager] mainMagixEventListener " + JSON.stringify(data.payload));
468
466
  this.setMainViewScenePathHandler(data.payload);
469
467
  break;
470
468
  }
@@ -5626,7 +5624,6 @@ class BoxManager {
5626
5624
  const rect = (_a = this.mainView.divElement) == null ? void 0 : _a.getBoundingClientRect();
5627
5625
  if (rect && rect.width > 0 && rect.height > 0) {
5628
5626
  const containerRect = { x: 0, y: 0, width: rect.width, height: rect.height };
5629
- console.log("[window-manager] updateManagerRect" + JSON.stringify(containerRect) + "mainView" + this.mainView.size);
5630
5627
  this.teleBoxManager.setContainerRect(containerRect);
5631
5628
  this.context.notifyContainerRectUpdate(this.teleBoxManager.containerRect);
5632
5629
  }
@@ -5693,6 +5690,88 @@ class BoxManager {
5693
5690
  }
5694
5691
  }
5695
5692
  BoxManager.kind = "BoxManager";
5693
+ function formatAttributesLogObjectKey(key) {
5694
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : JSON.stringify(key);
5695
+ }
5696
+ function stringifyForAttributesLog(value, seen) {
5697
+ if (value === void 0) {
5698
+ return "undefined";
5699
+ }
5700
+ if (value === null) {
5701
+ return "null";
5702
+ }
5703
+ const t2 = typeof value;
5704
+ if (t2 === "bigint") {
5705
+ return `${value}n`;
5706
+ }
5707
+ if (t2 === "symbol") {
5708
+ return String(value);
5709
+ }
5710
+ if (t2 === "function") {
5711
+ const fn = value;
5712
+ return `[Function ${fn.name || "anonymous"}]`;
5713
+ }
5714
+ if (t2 !== "object") {
5715
+ return t2 === "string" ? JSON.stringify(value) : String(value);
5716
+ }
5717
+ const obj = value;
5718
+ if (seen == null ? void 0 : seen.has(obj)) {
5719
+ return "[Circular]";
5720
+ }
5721
+ const nextSeen = seen != null ? seen : /* @__PURE__ */ new WeakSet();
5722
+ nextSeen.add(obj);
5723
+ try {
5724
+ if (Array.isArray(value)) {
5725
+ return `[${Array.from(
5726
+ value,
5727
+ (item) => stringifyForAttributesLog(item, nextSeen)
5728
+ ).join(",")}]`;
5729
+ }
5730
+ if (value instanceof Date) {
5731
+ return JSON.stringify(value.toISOString());
5732
+ }
5733
+ if (value instanceof RegExp) {
5734
+ return String(value);
5735
+ }
5736
+ const keys = Object.keys(value);
5737
+ const pairs = keys.map((k2) => {
5738
+ let v2;
5739
+ try {
5740
+ v2 = value[k2];
5741
+ } catch {
5742
+ return `${formatAttributesLogObjectKey(k2)}:[Threw]`;
5743
+ }
5744
+ return `${formatAttributesLogObjectKey(k2)}:${stringifyForAttributesLog(v2, nextSeen)}`;
5745
+ });
5746
+ return `{${pairs.join(",")}}`;
5747
+ } catch {
5748
+ return "[Unserializable]";
5749
+ } finally {
5750
+ nextSeen.delete(obj);
5751
+ }
5752
+ }
5753
+ function isShallowMergeAttributesRecord(value) {
5754
+ return value !== null && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !(value instanceof RegExp);
5755
+ }
5756
+ const ARGUS_LOG_INFO_MAX_LENGTH = 1500;
5757
+ function truncateArgusLogInfoMessage(message) {
5758
+ if (message.length <= ARGUS_LOG_INFO_MAX_LENGTH) {
5759
+ return message;
5760
+ }
5761
+ const ellipsis = "\u2026";
5762
+ return message.slice(0, ARGUS_LOG_INFO_MAX_LENGTH - ellipsis.length) + ellipsis;
5763
+ }
5764
+ function keysPathEqual(a2, b2) {
5765
+ if (a2.length !== b2.length) {
5766
+ return false;
5767
+ }
5768
+ for (let i2 = 0; i2 < a2.length; i2++) {
5769
+ if (a2[i2] !== b2[i2]) {
5770
+ return false;
5771
+ }
5772
+ }
5773
+ return true;
5774
+ }
5696
5775
  const log = (...args) => {
5697
5776
  if (WindowManager.debug) {
5698
5777
  console.log(`[WindowManager]:`, ...args);
@@ -5726,6 +5805,158 @@ class LocalConsole {
5726
5805
  }
5727
5806
  console.log(`[window-manager][${this.name}]: ${args.join(", ")}`);
5728
5807
  }
5808
+ destroy() {
5809
+ if (this.flushTimer != null) {
5810
+ clearTimeout(this.flushTimer);
5811
+ this.flushTimer = null;
5812
+ }
5813
+ this.pendingArgs = null;
5814
+ }
5815
+ }
5816
+ class ArgusLog {
5817
+ constructor(logger, name, debounceTime) {
5818
+ this.logger = logger;
5819
+ this.name = name;
5820
+ this.debounceTime = debounceTime;
5821
+ this.pendingArgs = null;
5822
+ this.flushTimer = null;
5823
+ this.pendingShallowMerge = null;
5824
+ this.shallowMergeTimer = null;
5825
+ this.pendingUpdateSegments = null;
5826
+ this.updateMergeTimer = null;
5827
+ }
5828
+ emitInfo(message) {
5829
+ this.logger.info(truncateArgusLogInfoMessage(message));
5830
+ }
5831
+ flush() {
5832
+ this.flushTimer = null;
5833
+ const args = this.pendingArgs;
5834
+ this.pendingArgs = null;
5835
+ if (args === null) {
5836
+ return;
5837
+ }
5838
+ this.emitInfo(`[WindowManager][${this.name}]: ${args.join(", ")}`);
5839
+ }
5840
+ flushShallowMerge() {
5841
+ this.shallowMergeTimer = null;
5842
+ const p2 = this.pendingShallowMerge;
5843
+ this.pendingShallowMerge = null;
5844
+ if (p2 === null) {
5845
+ return;
5846
+ }
5847
+ const body = p2.kind === "record" ? stringifyForAttributesLog(p2.data) : stringifyForAttributesLog(p2.value);
5848
+ this.emitInfo(`[WindowManager][${this.name}]: ${p2.label} ${body}`);
5849
+ if (p2.kind === "record") {
5850
+ for (const k2 of Object.keys(p2.data)) {
5851
+ delete p2.data[k2];
5852
+ }
5853
+ }
5854
+ }
5855
+ log(...args) {
5856
+ const ms = this.debounceTime;
5857
+ if (ms != null && ms > 0) {
5858
+ this.pendingArgs = args;
5859
+ if (this.flushTimer != null) {
5860
+ clearTimeout(this.flushTimer);
5861
+ }
5862
+ this.flushTimer = setTimeout(() => this.flush(), ms);
5863
+ return;
5864
+ }
5865
+ this.emitInfo(`[WindowManager][${this.name}]: ${args.join(", ")}`);
5866
+ }
5867
+ logDebouncedShallowMerge(label, payload) {
5868
+ var _a;
5869
+ const ms = this.debounceTime;
5870
+ const debounced = ms != null && ms > 0;
5871
+ const emit = (text2) => {
5872
+ this.emitInfo(`[WindowManager][${this.name}]: ${label} ${text2}`);
5873
+ };
5874
+ if (!debounced) {
5875
+ emit(stringifyForAttributesLog(payload));
5876
+ return;
5877
+ }
5878
+ if (this.shallowMergeTimer != null) {
5879
+ clearTimeout(this.shallowMergeTimer);
5880
+ this.shallowMergeTimer = null;
5881
+ }
5882
+ if (isShallowMergeAttributesRecord(payload)) {
5883
+ if (((_a = this.pendingShallowMerge) == null ? void 0 : _a.kind) === "record") {
5884
+ this.pendingShallowMerge = {
5885
+ kind: "record",
5886
+ label,
5887
+ data: { ...this.pendingShallowMerge.data, ...payload }
5888
+ };
5889
+ } else {
5890
+ this.pendingShallowMerge = { kind: "record", label, data: { ...payload } };
5891
+ }
5892
+ } else {
5893
+ this.pendingShallowMerge = { kind: "atom", label, value: payload };
5894
+ }
5895
+ this.shallowMergeTimer = setTimeout(() => this.flushShallowMerge(), ms);
5896
+ }
5897
+ flushUpdateAttributesMerge() {
5898
+ this.updateMergeTimer = null;
5899
+ const segments = this.pendingUpdateSegments;
5900
+ this.pendingUpdateSegments = null;
5901
+ if (segments === null || segments.length === 0) {
5902
+ return;
5903
+ }
5904
+ const parts = segments.map(
5905
+ (s2) => `${s2.keys.join(", ")} ${stringifyForAttributesLog(s2.value)}`
5906
+ );
5907
+ this.emitInfo(`[WindowManager][${this.name}]: safeUpdateAttributes ${parts.join(" | ")}`);
5908
+ for (const s2 of segments) {
5909
+ s2.keys.length = 0;
5910
+ s2.value = void 0;
5911
+ }
5912
+ segments.length = 0;
5913
+ }
5914
+ logDebouncedUpdateAttributes(keys, value) {
5915
+ const ms = this.debounceTime;
5916
+ const debounced = ms != null && ms > 0;
5917
+ const keysCopy = [...keys];
5918
+ if (!debounced) {
5919
+ this.emitInfo(
5920
+ `[WindowManager][${this.name}]: safeUpdateAttributes ${keysCopy.join(", ")} ${stringifyForAttributesLog(value)}`
5921
+ );
5922
+ return;
5923
+ }
5924
+ if (this.updateMergeTimer != null) {
5925
+ clearTimeout(this.updateMergeTimer);
5926
+ this.updateMergeTimer = null;
5927
+ }
5928
+ if (this.pendingUpdateSegments === null || this.pendingUpdateSegments.length === 0) {
5929
+ this.pendingUpdateSegments = [{ keys: keysCopy, value }];
5930
+ } else {
5931
+ const last = this.pendingUpdateSegments[this.pendingUpdateSegments.length - 1];
5932
+ if (keysPathEqual(last.keys, keysCopy)) {
5933
+ last.value = value;
5934
+ } else {
5935
+ this.pendingUpdateSegments.push({ keys: keysCopy, value });
5936
+ }
5937
+ }
5938
+ this.updateMergeTimer = setTimeout(() => this.flushUpdateAttributesMerge(), ms);
5939
+ }
5940
+ destroy() {
5941
+ if (this.flushTimer != null) {
5942
+ clearTimeout(this.flushTimer);
5943
+ this.flushTimer = null;
5944
+ }
5945
+ if (this.shallowMergeTimer != null) {
5946
+ clearTimeout(this.shallowMergeTimer);
5947
+ this.shallowMergeTimer = null;
5948
+ }
5949
+ if (this.updateMergeTimer != null) {
5950
+ clearTimeout(this.updateMergeTimer);
5951
+ this.updateMergeTimer = null;
5952
+ }
5953
+ this.pendingArgs = null;
5954
+ this.pendingShallowMerge = null;
5955
+ this.pendingUpdateSegments = null;
5956
+ }
5957
+ dispose() {
5958
+ this.destroy();
5959
+ }
5729
5960
  }
5730
5961
  const setupWrapper = (root) => {
5731
5962
  const playground = document.createElement("div");
@@ -7034,7 +7265,6 @@ var Fields = /* @__PURE__ */ ((Fields2) => {
7034
7265
  class AttributesDelegate {
7035
7266
  constructor(context) {
7036
7267
  this.context = context;
7037
- this.setMainViewCameraConsole = new LocalConsole("setMainViewCamera", 50);
7038
7268
  this.setAppFocus = (appId, focus) => {
7039
7269
  if (focus) {
7040
7270
  this.context.safeSetAttributes({ ["focus"]: appId });
@@ -7160,11 +7390,9 @@ class AttributesDelegate {
7160
7390
  return this.attributes["boxState"];
7161
7391
  }
7162
7392
  setMainViewScenePath(scenePath) {
7163
- console.log("[window-manager] setMainViewScenePath ", scenePath);
7164
7393
  this.context.safeSetAttributes({ _mainScenePath: scenePath });
7165
7394
  }
7166
7395
  setMainViewSceneIndex(index2) {
7167
- console.log("[window-manager] setMainViewSceneIndex ", index2);
7168
7396
  this.context.safeSetAttributes({ _mainSceneIndex: index2 });
7169
7397
  }
7170
7398
  getMainViewCamera() {
@@ -7174,19 +7402,16 @@ class AttributesDelegate {
7174
7402
  return get(this.attributes, ["mainViewSize"]);
7175
7403
  }
7176
7404
  setMainViewCamera(camera) {
7177
- this.setMainViewCameraConsole.log(JSON.stringify(camera));
7178
7405
  this.context.safeSetAttributes({ ["mainViewCamera"]: { ...camera } });
7179
7406
  }
7180
7407
  setMainViewSize(size2) {
7181
7408
  if (size2.width === 0 || size2.height === 0)
7182
7409
  return;
7183
- console.log("[window-manager] setMainViewSize ", JSON.stringify(size2));
7184
7410
  this.context.safeSetAttributes({ ["mainViewSize"]: { ...size2 } });
7185
7411
  }
7186
7412
  setMainViewCameraAndSize(camera, size2) {
7187
7413
  if (size2.width === 0 || size2.height === 0)
7188
7414
  return;
7189
- console.log("[window-manager] setMainViewCameraAndSize ", JSON.stringify(camera), JSON.stringify(size2));
7190
7415
  this.context.safeSetAttributes({
7191
7416
  ["mainViewCamera"]: { ...camera },
7192
7417
  ["mainViewSize"]: { ...size2 }
@@ -7430,13 +7655,13 @@ const _AppProxy = class {
7430
7655
  this.manager.safeUpdateAttributes(["apps", this.id, Fields.FullPath], path);
7431
7656
  }
7432
7657
  async baseInsertApp(skipUpdate = false, boxStatus = TELE_BOX_STATE.Normal) {
7433
- var _a, _b, _c;
7658
+ var _a;
7434
7659
  const params = this.params;
7435
7660
  if (!params.kind) {
7436
- (_a = this.Logger) == null ? void 0 : _a.error(`[WindowManager]: kind require`);
7661
+ this.Logger && this.Logger.error(`[WindowManager]: kind require`);
7437
7662
  throw new Error("[WindowManager]: kind require");
7438
7663
  }
7439
- const appImpl = await ((_b = appRegister.appClasses.get(params.kind)) == null ? void 0 : _b());
7664
+ const appImpl = await ((_a = appRegister.appClasses.get(params.kind)) == null ? void 0 : _a());
7440
7665
  const appParams = appRegister.registered.get(params.kind);
7441
7666
  if (appImpl) {
7442
7667
  await this.setupApp(
@@ -7451,7 +7676,7 @@ const _AppProxy = class {
7451
7676
  params.isDragContent
7452
7677
  );
7453
7678
  } else {
7454
- (_c = this.Logger) == null ? void 0 : _c.error(`[WindowManager]: app load failed ${params.kind} ${params.src}`);
7679
+ this.Logger && this.Logger.error(`[WindowManager]: app load failed ${params.kind} ${params.src}`);
7455
7680
  throw new Error(`[WindowManager]: app load failed ${params.kind} ${params.src}`);
7456
7681
  }
7457
7682
  internalEmitter.emit("updateManagerRect");
@@ -7465,7 +7690,7 @@ const _AppProxy = class {
7465
7690
  return (_a = this.boxManager) == null ? void 0 : _a.getBox(this.id);
7466
7691
  }
7467
7692
  async setupApp(appId, skipUpdate, app, options, appOptions, boxStatus, forceTop, forceNormal, isDragContent) {
7468
- var _a, _b;
7693
+ var _a;
7469
7694
  log("setupApp", appId, app, options, boxStatus, forceTop, forceNormal, isDragContent);
7470
7695
  if (!this.boxManager) {
7471
7696
  throw new BoxManagerNotFoundError();
@@ -7489,8 +7714,7 @@ const _AppProxy = class {
7489
7714
  currentMainViewScenePath = this.manager.mainView.scenePath;
7490
7715
  }
7491
7716
  setTimeout(async () => {
7492
- var _a3;
7493
- (_a3 = this.Logger) == null ? void 0 : _a3.info(`[WindowManager]: setup app ${this.kind}, appId: ${appId}`);
7717
+ this.Logger && this.Logger.info(`[WindowManager]: setup app ${this.kind}, appId: ${appId}`);
7494
7718
  const result = await app.setup(context);
7495
7719
  this.appResult = result;
7496
7720
  appRegister.notifyApp(this.kind, "created", { appId, result });
@@ -7525,7 +7749,7 @@ const _AppProxy = class {
7525
7749
  this.boxManager.focusBox({ appId }, false);
7526
7750
  }
7527
7751
  } catch (error) {
7528
- (_b = this.Logger) == null ? void 0 : _b.error(`[WindowManager]: app setup error: ${error.message}`);
7752
+ this.Logger && this.Logger.error(`[WindowManager]: app setup error: ${error.message}`);
7529
7753
  throw new Error(`[WindowManager]: app setup error: ${error.message}`);
7530
7754
  }
7531
7755
  }
@@ -7696,7 +7920,7 @@ const _AppProxy = class {
7696
7920
  }
7697
7921
  }
7698
7922
  async destroy(needCloseBox, cleanAttrs, skipUpdate, error) {
7699
- var _a, _b, _c;
7923
+ var _a;
7700
7924
  if (this.status === "destroyed")
7701
7925
  return;
7702
7926
  this.status = "destroyed";
@@ -7704,13 +7928,13 @@ const _AppProxy = class {
7704
7928
  await appRegister.notifyApp(this.kind, "destroy", { appId: this.id });
7705
7929
  await this.appEmitter.emit("destroy", { error });
7706
7930
  } catch (error2) {
7707
- (_a = this.Logger) == null ? void 0 : _a.error(`[WindowManager]: notifyApp error: ${error2.message}`);
7931
+ this.Logger && this.Logger.error(`[WindowManager]: notifyApp error: ${error2.message}`);
7708
7932
  console.error("[WindowManager]: notifyApp error", error2.message, error2.stack);
7709
7933
  }
7710
7934
  this.appEmitter.clearListeners();
7711
7935
  internalEmitter.emit(`destroy-${this.id}`, { error });
7712
7936
  if (needCloseBox) {
7713
- (_b = this.boxManager) == null ? void 0 : _b.closeBox(this.id, skipUpdate);
7937
+ (_a = this.boxManager) == null ? void 0 : _a.closeBox(this.id, skipUpdate);
7714
7938
  }
7715
7939
  if (cleanAttrs) {
7716
7940
  this.store.cleanAppAttributes(this.id);
@@ -7726,7 +7950,7 @@ const _AppProxy = class {
7726
7950
  this.manager.refresher.remove(this.stateKey);
7727
7951
  this.manager.refresher.remove(`${this.id}-fullPath`);
7728
7952
  this._prevFullPath = void 0;
7729
- (_c = this.Logger) == null ? void 0 : _c.info(`[WindowManager]: destroy app ${this.kind} appId: ${this.id}`);
7953
+ this.Logger && this.Logger.info(`[WindowManager]: destroy app ${this.kind} appId: ${this.id}`);
7730
7954
  }
7731
7955
  close() {
7732
7956
  return this.destroy(true, true, false);
@@ -7784,17 +8008,21 @@ const setDefaultCameraBound = (view) => {
7784
8008
  minContentMode: () => 0.1
7785
8009
  });
7786
8010
  };
7787
- window.___local_log = window.___local_log || /* @__PURE__ */ new Set();
7788
8011
  class MainViewProxy {
7789
8012
  constructor(manager) {
7790
8013
  this.manager = manager;
7791
8014
  this.polling = false;
7792
8015
  this.started = false;
7793
8016
  this.mainViewIsAddListener = false;
8017
+ this.isForcingMainViewDivElement = false;
8018
+ this.wrapperRectWorkaroundFrame = 0;
7794
8019
  this.store = this.manager.store;
7795
8020
  this.viewMode = this.manager.windowManger.viewMode;
7796
8021
  this.sideEffectManager = new o$2();
7797
- this.playgroundSizeChangeListenerLocalConsole = new LocalConsole("playgroundSizeChangeListener", 30);
8022
+ this.playgroundSizeChangeListenerLocalConsole = new LocalConsole("playgroundSizeChangeListener", 100);
8023
+ this.sizeUpdatedLocalConsole = new LocalConsole("sizeUpdated", 100);
8024
+ this.cameraUpdatedLocalConsole = new LocalConsole("cameraUpdated", 100);
8025
+ this.cameraReactionLocalConsole = new LocalConsole("cameraReaction", 100);
7798
8026
  this.syncCamera = () => {
7799
8027
  if (!this.polling || this.viewMode !== ViewMode.Broadcaster)
7800
8028
  return;
@@ -7814,6 +8042,32 @@ class MainViewProxy {
7814
8042
  });
7815
8043
  });
7816
8044
  };
8045
+ this.onWrapperRectChange = (payload) => {
8046
+ this.pendingWrapperRectChange = payload;
8047
+ if (this.wrapperRectWorkaroundFrame) {
8048
+ cancelAnimationFrame(this.wrapperRectWorkaroundFrame);
8049
+ }
8050
+ this.wrapperRectWorkaroundFrame = requestAnimationFrame(this.runWrapperRectWorkaround);
8051
+ };
8052
+ this.runWrapperRectWorkaround = () => {
8053
+ this.wrapperRectWorkaroundFrame = 0;
8054
+ const payload = this.pendingWrapperRectChange;
8055
+ const element2 = this.mainView.divElement;
8056
+ this.pendingWrapperRectChange = void 0;
8057
+ if (!payload || !element2)
8058
+ return;
8059
+ const rect = element2.getBoundingClientRect();
8060
+ const observedSize = { width: rect.width, height: rect.height };
8061
+ const wrapperMatchesDom = Math.abs(payload.width - observedSize.width) <= 0.5 && Math.abs(payload.height - observedSize.height) <= 0.5;
8062
+ const viewIsStale = Math.abs(this.mainView.size.width - observedSize.width) > 0.5 || Math.abs(this.mainView.size.height - observedSize.height) > 0.5;
8063
+ if (wrapperMatchesDom && viewIsStale) {
8064
+ this.forceSyncMainViewDivElement(
8065
+ `wrapperRectChange:${payload.origin || "unknown"}`,
8066
+ observedSize,
8067
+ element2
8068
+ );
8069
+ }
8070
+ };
7817
8071
  this.addCameraReaction = () => {
7818
8072
  this.manager.refresher.add(Fields.MainViewCamera, this.cameraReaction);
7819
8073
  };
@@ -7822,9 +8076,9 @@ class MainViewProxy {
7822
8076
  () => this.mainViewCamera,
7823
8077
  (camera) => {
7824
8078
  if (camera && camera.id !== this.manager.uid) {
7825
- console.log("[window-manager] cameraReaction " + JSON.stringify(camera) + JSON.stringify(this.mainViewSize));
7826
8079
  this.moveCameraToContian(this.mainViewSize);
7827
8080
  this.moveCamera(camera);
8081
+ this.cameraReactionLocalConsole.log(`camera: ${JSON.stringify(camera)}, current size: ${JSON.stringify(this.mainViewSize)}`);
7828
8082
  }
7829
8083
  },
7830
8084
  { fireImmediately: true }
@@ -7834,7 +8088,7 @@ class MainViewProxy {
7834
8088
  if (size2) {
7835
8089
  this.moveCameraToContian(size2);
7836
8090
  this.moveCamera(this.mainViewCamera);
7837
- 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));
8091
+ 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));
7838
8092
  }
7839
8093
  this.ensureMainViewSize();
7840
8094
  }, 30);
@@ -7858,7 +8112,7 @@ class MainViewProxy {
7858
8112
  this.store.setMainViewSize({ ...size2, id: this.manager.uid });
7859
8113
  }, 50);
7860
8114
  this._syncMainViewTimer = 0;
7861
- this.onCameraOrSizeUpdated = () => {
8115
+ this.handleCameraOrSizeUpdated = () => {
7862
8116
  callbacks$1.emit("cameraStateChange", this.cameraState);
7863
8117
  if (this.manager.room && this.manager.room.syncMainView) {
7864
8118
  clearTimeout(this._syncMainViewTimer);
@@ -7866,9 +8120,16 @@ class MainViewProxy {
7866
8120
  }
7867
8121
  this.ensureMainViewSize();
7868
8122
  };
8123
+ this.onCameraUpdated = (camera) => {
8124
+ this.cameraUpdatedLocalConsole.log(JSON.stringify(camera));
8125
+ this.handleCameraOrSizeUpdated();
8126
+ };
8127
+ this.onSizeUpdated = (size2) => {
8128
+ this.sizeUpdatedLocalConsole.log(JSON.stringify(size2));
8129
+ this.handleCameraOrSizeUpdated();
8130
+ };
7869
8131
  this.syncMainView = (room) => {
7870
8132
  if (room.isWritable) {
7871
- console.log("[window-manager] syncMainView ");
7872
8133
  room.syncMainView(this.mainView);
7873
8134
  }
7874
8135
  };
@@ -7905,6 +8166,9 @@ class MainViewProxy {
7905
8166
  this.sideEffectManager.add(() => {
7906
8167
  return internalEmitter.on("containerSizeRatioUpdate", this.onUpdateContainerSizeRatio);
7907
8168
  });
8169
+ this.sideEffectManager.add(() => {
8170
+ return internalEmitter.on("wrapperRectChange", this.onWrapperRectChange);
8171
+ });
7908
8172
  this.sideEffectManager.add(() => {
7909
8173
  return internalEmitter.on("startReconnect", () => {
7910
8174
  if (!this.didRelease) {
@@ -7935,8 +8199,52 @@ class MainViewProxy {
7935
8199
  this.moveCameraToContian(this.mainViewSize);
7936
8200
  this.moveCamera(this.mainViewCamera);
7937
8201
  }
8202
+ forceSyncMainViewDivElement(reason, observedSize, element2) {
8203
+ var _a, _b;
8204
+ const { width: viewWidth, height: viewHeight } = this.mainView.size;
8205
+ let targetElement = element2;
8206
+ if (Math.abs(viewWidth - observedSize.width) <= 0.5 && Math.abs(viewHeight - observedSize.height) <= 0.5) {
8207
+ return;
8208
+ }
8209
+ if (this.isForcingMainViewDivElement) {
8210
+ console.log("[window-manager] skipForceSyncMainViewDivElement " + JSON.stringify({
8211
+ reason,
8212
+ observedSize,
8213
+ viewSize: this.mainView.size
8214
+ }));
8215
+ return;
8216
+ }
8217
+ this.isForcingMainViewDivElement = true;
8218
+ try {
8219
+ const mainView = this.mainView;
8220
+ const screen = mainView.screen;
8221
+ const resizeObserver = screen == null ? void 0 : screen.resizeObserver;
8222
+ if (typeof (screen == null ? void 0 : screen.refreshSize) === "function") {
8223
+ console.log(
8224
+ "[window-manager] forceSyncMainViewDivElement observerReset " + JSON.stringify({
8225
+ reason,
8226
+ viewSize: this.mainView.size,
8227
+ observedSize
8228
+ })
8229
+ );
8230
+ (_a = resizeObserver == null ? void 0 : resizeObserver.disconnect) == null ? void 0 : _a.call(resizeObserver);
8231
+ screen.refreshSize(observedSize.width, observedSize.height);
8232
+ (_b = resizeObserver == null ? void 0 : resizeObserver.observe) == null ? void 0 : _b.call(resizeObserver, element2);
8233
+ }
8234
+ } finally {
8235
+ queueMicrotask(() => {
8236
+ const rect = targetElement.getBoundingClientRect();
8237
+ console.log("[window-manager] forceSyncMainViewDivElementResult " + JSON.stringify({
8238
+ reason,
8239
+ viewSize: this.mainView.size,
8240
+ rect: { width: rect.width, height: rect.height }
8241
+ }));
8242
+ this.isForcingMainViewDivElement = false;
8243
+ });
8244
+ }
8245
+ }
7938
8246
  start() {
7939
- console.log("[window-manager] start " + JSON.stringify(this.mainViewSize));
8247
+ console.log("[window-manager] start attributes size:" + JSON.stringify(this.mainViewSize));
7940
8248
  this.sizeChangeHandler(this.mainViewSize);
7941
8249
  if (this.started)
7942
8250
  return;
@@ -7945,6 +8253,10 @@ class MainViewProxy {
7945
8253
  if (this.manager.room)
7946
8254
  this.syncMainView(this.manager.room);
7947
8255
  this.started = true;
8256
+ if (this.mainView.focusScenePath) {
8257
+ this.manager.windowManger.onMainViewScenePathChangeHandler(this.mainView.focusScenePath);
8258
+ }
8259
+ console.log("[window-manager] start end mainView size:" + JSON.stringify(this.mainView.size));
7948
8260
  }
7949
8261
  setCameraAndSize() {
7950
8262
  const camera = { ...this.mainView.camera, id: this.manager.uid };
@@ -8018,13 +8330,13 @@ class MainViewProxy {
8018
8330
  }
8019
8331
  addCameraListener() {
8020
8332
  this.view.callbacks.on("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
8021
- this.view.callbacks.on("onCameraUpdated", this.onCameraOrSizeUpdated);
8022
- this.view.callbacks.on("onSizeUpdated", this.onCameraOrSizeUpdated);
8333
+ this.view.callbacks.on("onCameraUpdated", this.onCameraUpdated);
8334
+ this.view.callbacks.on("onSizeUpdated", this.onSizeUpdated);
8023
8335
  }
8024
8336
  removeCameraListener() {
8025
8337
  this.view.callbacks.off("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
8026
- this.view.callbacks.off("onCameraUpdated", this.onCameraOrSizeUpdated);
8027
- this.view.callbacks.off("onSizeUpdated", this.onCameraOrSizeUpdated);
8338
+ this.view.callbacks.off("onCameraUpdated", this.onCameraUpdated);
8339
+ this.view.callbacks.off("onSizeUpdated", this.onSizeUpdated);
8028
8340
  }
8029
8341
  ensureMainViewSize() {
8030
8342
  if ((!this.mainViewSize || this.mainViewSize.width === 0 || this.mainViewSize.height === 0) && this.mainView.size.width > 0 && this.mainView.size.height > 0) {
@@ -8064,6 +8376,15 @@ class MainViewProxy {
8064
8376
  this.started = false;
8065
8377
  }
8066
8378
  destroy() {
8379
+ console.log("[window-manager] destroy ");
8380
+ if (this.wrapperRectWorkaroundFrame) {
8381
+ cancelAnimationFrame(this.wrapperRectWorkaroundFrame);
8382
+ this.wrapperRectWorkaroundFrame = 0;
8383
+ }
8384
+ this.playgroundSizeChangeListenerLocalConsole.destroy();
8385
+ this.sizeUpdatedLocalConsole.destroy();
8386
+ this.cameraUpdatedLocalConsole.destroy();
8387
+ this.cameraReactionLocalConsole.destroy();
8067
8388
  this.removeMainViewListener();
8068
8389
  this.stop();
8069
8390
  this.sideEffectManager.flushAll();
@@ -8153,7 +8474,7 @@ class AppManager {
8153
8474
  var _a, _b;
8154
8475
  const { scenePath } = params;
8155
8476
  if (scenePath === ROOT_DIR) {
8156
- console.log("[window-manager] onRemoveScenes ROOT_DIR");
8477
+ console.log("[window-manager] onRemoveScenes ROOT_DIR");
8157
8478
  await this.onRootDirRemoved();
8158
8479
  this.dispatchInternalEvent(Events.RootDirRemoved);
8159
8480
  return;
@@ -8166,7 +8487,7 @@ class AppManager {
8166
8487
  sceneName = (_b = this.callbacksNode) == null ? void 0 : _b.scenes[nextIndex];
8167
8488
  }
8168
8489
  if (sceneName) {
8169
- console.log(`[window-manager] onRemoveScenes setMainViewScenePath${ROOT_DIR}${sceneName}`);
8490
+ console.log(`[window-manager] onRemoveScenes setMainViewScenePath ${ROOT_DIR}${sceneName}`);
8170
8491
  this.setMainViewScenePath(`${ROOT_DIR}${sceneName}`);
8171
8492
  }
8172
8493
  await this.setMainViewSceneIndex(nextIndex);
@@ -8464,7 +8785,6 @@ class AppManager {
8464
8785
  const pageName = scenePath.replace(sceneDir, "").replace("/", "");
8465
8786
  const index2 = scenes.findIndex((scene) => scene.name === pageName);
8466
8787
  if (isInteger(index2) && index2 >= 0) {
8467
- console.log("[window-manager] updateSceneIndex ", index2);
8468
8788
  this.safeSetAttributes({ _mainSceneIndex: index2 });
8469
8789
  }
8470
8790
  }
@@ -8505,8 +8825,6 @@ class AppManager {
8505
8825
  internalEmitter.on("setReadonly", this.onReadonlyChanged);
8506
8826
  this.createRootDirScenesCallback();
8507
8827
  appRegister.setSyncRegisterApp((payload) => {
8508
- var _a;
8509
- (_a = this.Logger) == null ? void 0 : _a.info(`[WindowManager] syncRegisterApp ${JSON.stringify(payload)}`);
8510
8828
  this.safeUpdateAttributes([Fields.Registered, payload.kind], payload);
8511
8829
  });
8512
8830
  }
@@ -8658,7 +8976,6 @@ class AppManager {
8658
8976
  }
8659
8977
  }
8660
8978
  async _attributesUpdateCallback(apps) {
8661
- var _a;
8662
8979
  if (apps && WindowManager.container) {
8663
8980
  const appIds = Object.keys(apps);
8664
8981
  if (appIds.length === 0) {
@@ -8682,7 +8999,7 @@ class AppManager {
8682
8999
  try {
8683
9000
  const appAttributes = this.attributes[id2];
8684
9001
  if (!appAttributes) {
8685
- (_a = this.Logger) == null ? void 0 : _a.error(
9002
+ this.Logger && this.Logger.error(
8686
9003
  `[WindowManager]: appAttributes is undefined, appId: ${id2}`
8687
9004
  );
8688
9005
  throw new Error("appAttributes is undefined");
@@ -8732,7 +9049,6 @@ class AppManager {
8732
9049
  (_a = this.boxManager) == null ? void 0 : _a.setMinimized(Boolean(this.store.getMinimized()));
8733
9050
  }
8734
9051
  bindMainView(divElement, disableCameraTransform) {
8735
- var _a, _b, _c, _d, _e, _f, _g, _h;
8736
9052
  const mainView = this.mainViewProxy.view;
8737
9053
  mainView.disableCameraTransform = disableCameraTransform;
8738
9054
  mainView.divElement = divElement;
@@ -8743,13 +9059,12 @@ class AppManager {
8743
9059
  callbacks$1.emit("onMainViewMounted", mainView);
8744
9060
  const hasRoot = this.hasRoot(mainView.divElement);
8745
9061
  const rect = this.getRectByDivElement(mainView.divElement);
8746
- console.log(
8747
- "[window-manager] bindMainView hasRoot" + hasRoot + JSON.stringify(rect) + window.outerHeight + window.outerWidth,
8748
- (_b = (_a = window.visualViewport) == null ? void 0 : _a.width) != null ? _b : "null",
8749
- (_d = (_c = window.visualViewport) == null ? void 0 : _c.height) != null ? _d : "null",
8750
- (_f = (_e = window.visualViewport) == null ? void 0 : _e.offsetLeft) != null ? _f : "null",
8751
- (_h = (_g = window.visualViewport) == null ? void 0 : _g.offsetTop) != null ? _h : "null"
8752
- );
9062
+ let log2 = `[window-manager] bindMainView hasRoot:${hasRoot}, rect:${JSON.stringify(rect)}, outerHeight:${window.outerHeight}, outerWidth:${window.outerWidth}`;
9063
+ const visualViewport = window.visualViewport;
9064
+ if (visualViewport) {
9065
+ log2 += `, visualViewportWidth:${visualViewport.width}, visualViewportHeight:${visualViewport.height}, visualViewportOffsetLeft:${visualViewport.offsetLeft}, visualViewportOffsetTop:${visualViewport.offsetTop}`;
9066
+ }
9067
+ console.log(log2);
8753
9068
  }
8754
9069
  hasRoot(divElement) {
8755
9070
  let current = divElement;
@@ -8825,7 +9140,7 @@ class AppManager {
8825
9140
  }
8826
9141
  }
8827
9142
  async baseInsertApp(params, appId, isAddApp, focus) {
8828
- var _a, _b;
9143
+ var _a;
8829
9144
  if (this.appProxies.has(appId)) {
8830
9145
  (_a = this.windowManger.Logger) == null ? void 0 : _a.warn(
8831
9146
  `[WindowManager]: app duplicate exists and cannot be created again, appId: ${appId}`
@@ -8840,7 +9155,7 @@ class AppManager {
8840
9155
  return appProxy;
8841
9156
  } else {
8842
9157
  this.appStatus.delete(appId);
8843
- (_b = this.Logger) == null ? void 0 : _b.error(`[WindowManager]: initialize AppProxy failed, appId: ${appId}`);
9158
+ this.Logger && this.Logger.error(`[WindowManager]: initialize AppProxy failed, appId: ${appId}`);
8844
9159
  throw new Error("[WindowManger]: initialize AppProxy failed");
8845
9160
  }
8846
9161
  }
@@ -8851,16 +9166,15 @@ class AppManager {
8851
9166
  this.windowManger.safeUpdateAttributes(keys, value);
8852
9167
  }
8853
9168
  async setMainViewScenePath(scenePath) {
8854
- var _a, _b;
8855
9169
  if (this.room) {
8856
9170
  const scenePathType = this.displayer.scenePathType(scenePath);
8857
9171
  const sceneDir = parseSceneDir(scenePath);
8858
9172
  if (sceneDir !== ROOT_DIR) {
8859
- (_a = this.Logger) == null ? void 0 : _a.error(`[WindowManager]: main view scenePath must in root dir "/"`);
9173
+ this.Logger && this.Logger.error(`[WindowManager]: main view scenePath must in root dir "/"`);
8860
9174
  throw new Error(`[WindowManager]: main view scenePath must in root dir "/"`);
8861
9175
  }
8862
9176
  if (scenePathType === ScenePathType.None) {
8863
- (_b = this.Logger) == null ? void 0 : _b.error(`[WindowManager]: ${scenePath} not valid scene`);
9177
+ this.Logger && this.Logger.error(`[WindowManager]: ${scenePath} not valid scene`);
8864
9178
  throw new Error(`[WindowManager]: ${scenePath} not valid scene`);
8865
9179
  } else if (scenePathType === ScenePathType.Page) {
8866
9180
  await this._setMainViewScenePath(scenePath);
@@ -8875,7 +9189,6 @@ class AppManager {
8875
9189
  async _setMainViewScenePath(scenePath) {
8876
9190
  const success = this.setMainViewFocusPath(scenePath);
8877
9191
  if (success) {
8878
- console.log("[window-manager] _setMainViewScenePath ", scenePath);
8879
9192
  this.safeSetAttributes({ _mainScenePath: scenePath });
8880
9193
  this.store.setMainViewFocusPath(this.mainView);
8881
9194
  this.updateSceneIndex();
@@ -8883,7 +9196,7 @@ class AppManager {
8883
9196
  }
8884
9197
  }
8885
9198
  async setMainViewSceneIndex(index2) {
8886
- var _a, _b;
9199
+ var _a;
8887
9200
  if (this.room) {
8888
9201
  if (this.store.getMainViewSceneIndex() === index2)
8889
9202
  return;
@@ -8897,13 +9210,12 @@ class AppManager {
8897
9210
  this.dispatchSetMainViewScenePath(scenePath);
8898
9211
  }
8899
9212
  } else {
8900
- (_b = this.Logger) == null ? void 0 : _b.error(`[WindowManager]: ${index2} not valid index`);
9213
+ this.Logger && this.Logger.error(`[WindowManager]: ${index2} not valid index`);
8901
9214
  throw new Error(`[WindowManager]: ${index2} not valid index`);
8902
9215
  }
8903
9216
  }
8904
9217
  }
8905
9218
  dispatchSetMainViewScenePath(scenePath) {
8906
- console.log("[window-manager] dispatchSetMainViewScenePath ", JSON.stringify(scenePath));
8907
9219
  this.dispatchInternalEvent(Events.SetMainViewScenePath, { nextScenePath: scenePath });
8908
9220
  callbacks$1.emit("mainViewScenePathChange", scenePath);
8909
9221
  setScenePath(this.room, scenePath);
@@ -8979,6 +9291,7 @@ const ResizeObserver$2 = window.ResizeObserver || ResizeObserver$3;
8979
9291
  class ContainerResizeObserver {
8980
9292
  constructor(emitter) {
8981
9293
  this.emitter = emitter;
9294
+ this.updateSizerLocalConsole = new LocalConsole("updateSizer", 100);
8982
9295
  }
8983
9296
  static create(container, sizer, wrapper, emitter) {
8984
9297
  const containerResizeObserver = new ContainerResizeObserver(emitter);
@@ -8986,26 +9299,23 @@ class ContainerResizeObserver {
8986
9299
  return containerResizeObserver;
8987
9300
  }
8988
9301
  observePlaygroundSize(container, sizer, wrapper) {
8989
- console.log(`[window-manager] observePlaygroundSize ${JSON.stringify(container.getBoundingClientRect())}, ${JSON.stringify(sizer.getBoundingClientRect())}, ${JSON.stringify(wrapper.getBoundingClientRect())}`);
8990
- this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
9302
+ this.updateSizer(container.getBoundingClientRect(), sizer, wrapper, "observePlaygroundSize");
8991
9303
  this.containerResizeObserver = new ResizeObserver$2((entries) => {
8992
9304
  var _a;
8993
9305
  const containerRect = (_a = entries[0]) == null ? void 0 : _a.contentRect;
8994
9306
  if (containerRect) {
8995
- this.updateSizer(containerRect, sizer, wrapper);
8996
- console.log(`[window-manager] containerResizeObserver ${JSON.stringify(containerRect)}`);
9307
+ this.updateSizer(containerRect, sizer, wrapper, "containerResizeObserver");
8997
9308
  this.emitter.emit("playgroundSizeChange", containerRect);
8998
9309
  }
8999
9310
  });
9000
9311
  this.disposer = this.emitter.on("containerSizeRatioUpdate", () => {
9001
9312
  const containerRect = container.getBoundingClientRect();
9002
- console.log(`[window-manager] containerSizeRatioUpdate ${JSON.stringify(containerRect)}`);
9003
- this.updateSizer(containerRect, sizer, wrapper);
9313
+ this.updateSizer(containerRect, sizer, wrapper, "containerSizeRatioUpdate");
9004
9314
  this.emitter.emit("playgroundSizeChange", containerRect);
9005
9315
  });
9006
9316
  this.containerResizeObserver.observe(container);
9007
9317
  }
9008
- updateSizer({ width, height }, sizer, wrapper) {
9318
+ updateSizer({ width, height }, sizer, wrapper, origin) {
9009
9319
  if (width && height) {
9010
9320
  if (height / width > WindowManager.containerSizeRatio) {
9011
9321
  height = width * WindowManager.containerSizeRatio;
@@ -9016,17 +9326,21 @@ class ContainerResizeObserver {
9016
9326
  }
9017
9327
  wrapper.style.width = `${width}px`;
9018
9328
  wrapper.style.height = `${height}px`;
9019
- wrapper.style.backgroundColor = "green";
9020
- console.log(`[window-manager] updateSizer ${JSON.stringify({ width, height })} ${wrapper.style.width} ${wrapper.style.height} ${JSON.stringify(wrapper.getBoundingClientRect())}`);
9329
+ const wrapperRect = wrapper.getBoundingClientRect();
9330
+ this.updateSizerLocalConsole.log(`from ${origin}, traget size: ${JSON.stringify({ width, height })}, wrapperRect: ${wrapperRect.width} ${wrapperRect.height}`);
9331
+ this.emitter.emit("wrapperRectChange", {
9332
+ width: wrapperRect.width,
9333
+ height: wrapperRect.height,
9334
+ origin
9335
+ });
9021
9336
  }
9022
9337
  }
9023
9338
  disconnect() {
9024
- var _a;
9339
+ var _a, _b;
9340
+ this.updateSizerLocalConsole.destroy();
9025
9341
  (_a = this.containerResizeObserver) == null ? void 0 : _a.disconnect();
9026
- if (isFunction(this.disposer)) {
9027
- this.disposer();
9028
- this.disposer = void 0;
9029
- }
9342
+ (_b = this.disposer) == null ? void 0 : _b.call(this);
9343
+ this.disposer = void 0;
9030
9344
  }
9031
9345
  }
9032
9346
  class PageStateImpl {
@@ -9179,10 +9493,24 @@ const replaceRoomFunction = (room, manager) => {
9179
9493
  var _a;
9180
9494
  _scalePptToFit.call(room, ...args);
9181
9495
  if ((_a = manager.appManager) == null ? void 0 : _a.mainViewProxy) {
9182
- console.log("[window-manager] scalePptToFit " + JSON.stringify(args));
9183
9496
  manager.appManager.mainViewProxy.setCameraAndSize();
9184
9497
  }
9185
9498
  };
9499
+ const _putScenes = room.putScenes;
9500
+ room.putScenes = (...args) => {
9501
+ const [path, scenes] = args;
9502
+ const currentScenePath = manager.mainView.focusScenePath;
9503
+ if (currentScenePath && path && scenes) {
9504
+ console.log("[window-manager] putScenes " + JSON.stringify(args));
9505
+ for (const scene of scenes) {
9506
+ if (`${path}${scene.name}` === currentScenePath) {
9507
+ console.error(`[window-manager] putScenes: scene name can not be the same as the current scene path: ${currentScenePath}`);
9508
+ return;
9509
+ }
9510
+ }
9511
+ }
9512
+ return _putScenes.call(room, ...args);
9513
+ };
9186
9514
  room.moveCamera = (camera) => manager.moveCamera(camera);
9187
9515
  room.moveCameraToContain = (...args) => manager.moveCameraToContain(...args);
9188
9516
  room.convertToPointInWorld = (...args) => manager.mainView.convertToPointInWorld(...args);
@@ -11429,7 +11757,7 @@ class StaticDocsViewer {
11429
11757
  img.src = pdfPageSrc;
11430
11758
  await new Promise((resolve) => img.onload = resolve);
11431
11759
  whiteCtx.drawImage(img, 0, 0);
11432
- const pdfPageBase64 = whiteSnapshotCanvas.toDataURL("image/jpeg", 0.6);
11760
+ const pdfPageBase64 = whiteSnapshotCanvas.toDataURL("image/png");
11433
11761
  whiteCtx.clearRect(0, 0, width, height);
11434
11762
  const camera = {
11435
11763
  centerX: width / 2,
@@ -11449,7 +11777,7 @@ class StaticDocsViewer {
11449
11777
  this.whiteboardView.screenshotToCanvas(whiteCtx, scenePath, width, height, camera);
11450
11778
  }
11451
11779
  const snapshot = whiteSnapshotCanvas.toDataURL("image/png");
11452
- pdf.addImage(pdfPageBase64, "JPEG", 0, 0, width, height, "", "FAST");
11780
+ pdf.addImage(pdfPageBase64, "PNG", 0, 0, width, height, "", "FAST");
11453
11781
  pdf.addImage(snapshot, "PNG", 0, 0, width, height, "", "FAST");
11454
11782
  whiteCtx.clearRect(0, 0, width, height);
11455
11783
  const progress = Math.ceil((index2 + 1) / this.pages.length * 100);
@@ -19773,16 +20101,13 @@ const reconnectRefresher = new ReconnectRefresher({ emitter: internalEmitter });
19773
20101
  const _WindowManager = class extends InvisiblePlugin {
19774
20102
  constructor(context) {
19775
20103
  super(context);
19776
- this.version = "1.0.13-test.9";
19777
- 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" } };
20104
+ this.version = "1.0.13";
20105
+ 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.54" }, "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.54" } };
19778
20106
  this.emitter = callbacks$1;
19779
20107
  this.viewMode = ViewMode.Broadcaster;
19780
20108
  this.isReplay = isPlayer(this.displayer);
19781
20109
  this._cursorUIDs = [];
19782
20110
  this.containerSizeRatio = _WindowManager.containerSizeRatio;
19783
- this.visibleStateListener = () => {
19784
- console.log("[window-manager] visibleStateListener isVisible:" + !document.hidden);
19785
- };
19786
20111
  this.onMainViewScenePathChangeHandler = (scenePath) => {
19787
20112
  const mainViewElement = this.mainView.divElement;
19788
20113
  if (mainViewElement) {
@@ -19791,17 +20116,17 @@ const _WindowManager = class extends InvisiblePlugin {
19791
20116
  const backgroundImageRect = backgroundImage == null ? void 0 : backgroundImage.getBoundingClientRect();
19792
20117
  const backgroundImageCSS = window.getComputedStyle(backgroundImage);
19793
20118
  const backgroundImageVisible = (backgroundImageRect == null ? void 0 : backgroundImageRect.width) > 0 && (backgroundImageRect == null ? void 0 : backgroundImageRect.height) > 0 && backgroundImageCSS.display !== "none";
19794
- console.log("[window-manager] backgroundImageVisible" + backgroundImageVisible);
20119
+ const camera = this.mainView.camera;
20120
+ console.log("[window-manager] backgroundImageVisible:" + backgroundImageVisible + " camera:" + JSON.stringify(camera));
19795
20121
  return;
19796
20122
  }
19797
- console.log("[window-manager] onMainViewScenePathChange" + scenePath + "backgroundImageVisible is not found");
20123
+ console.log("[window-manager] onMainViewScenePathChange scenePath:" + scenePath + " backgroundImageVisible is not found");
20124
+ return;
19798
20125
  }
19799
- console.log("[window-manager] onMainViewScenePathChange" + scenePath + "mainViewElement is not found");
20126
+ console.log("[window-manager] onMainViewScenePathChange scenePath:" + scenePath + " mainViewElement is not found");
19800
20127
  };
19801
20128
  _WindowManager.displayer = context.displayer;
19802
- 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" } };
19803
- this.visibleStateListener();
19804
- document.addEventListener("visibilitychange", this.visibleStateListener);
20129
+ 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.54" }, "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.54" } };
19805
20130
  this.emitter.on("mainViewScenePathChange", this.onMainViewScenePathChangeHandler);
19806
20131
  }
19807
20132
  get Logger() {
@@ -19833,6 +20158,7 @@ const _WindowManager = class extends InvisiblePlugin {
19833
20158
  manager = await this.initManager(room);
19834
20159
  if (manager) {
19835
20160
  manager._roomLogger = room.logger;
20161
+ manager.attributesDeboundceLog = new ArgusLog(manager._roomLogger, "attributes", 300);
19836
20162
  if (_WindowManager.registered.size > 0) {
19837
20163
  manager._roomLogger.info(
19838
20164
  `[WindowManager] registered apps: ${JSON.stringify(
@@ -20447,7 +20773,6 @@ const _WindowManager = class extends InvisiblePlugin {
20447
20773
  }, 500);
20448
20774
  }
20449
20775
  moveCameraToContain(rectangle) {
20450
- console.log("[window-manager] moveCameraToContain" + JSON.stringify(rectangle));
20451
20776
  this.mainView.moveCameraToContain(rectangle);
20452
20777
  setTimeout(() => {
20453
20778
  var _a;
@@ -20467,22 +20792,23 @@ const _WindowManager = class extends InvisiblePlugin {
20467
20792
  this._destroy();
20468
20793
  }
20469
20794
  _destroy() {
20470
- var _a, _b, _c, _d, _e, _f;
20471
- (_a = this.containerResizeObserver) == null ? void 0 : _a.disconnect();
20472
- (_b = this.appManager) == null ? void 0 : _b.destroy();
20473
- (_c = this.cursorManager) == null ? void 0 : _c.destroy();
20474
- (_d = this.extendPluginManager) == null ? void 0 : _d.destroy();
20795
+ var _a, _b, _c, _d, _e, _f, _g;
20796
+ (_a = this.attributesDeboundceLog) == null ? void 0 : _a.destroy();
20797
+ this.attributesDeboundceLog = void 0;
20798
+ (_b = this.containerResizeObserver) == null ? void 0 : _b.disconnect();
20799
+ (_c = this.appManager) == null ? void 0 : _c.destroy();
20800
+ (_d = this.cursorManager) == null ? void 0 : _d.destroy();
20801
+ (_e = this.extendPluginManager) == null ? void 0 : _e.destroy();
20475
20802
  _WindowManager.container = void 0;
20476
20803
  _WindowManager.wrapper = void 0;
20477
20804
  _WindowManager.sizer = void 0;
20478
20805
  _WindowManager.isCreated = false;
20479
20806
  if (_WindowManager.playground) {
20480
- (_e = _WindowManager.playground.parentNode) == null ? void 0 : _e.removeChild(_WindowManager.playground);
20807
+ (_f = _WindowManager.playground.parentNode) == null ? void 0 : _f.removeChild(_WindowManager.playground);
20481
20808
  }
20482
20809
  _WindowManager.params = void 0;
20483
- document.removeEventListener("visibilitychange", this.visibleStateListener);
20484
20810
  this.emitter.off("mainViewScenePathChange", this.onMainViewScenePathChangeHandler);
20485
- (_f = this._iframeBridge) == null ? void 0 : _f.destroy();
20811
+ (_g = this._iframeBridge) == null ? void 0 : _g.destroy();
20486
20812
  this._iframeBridge = void 0;
20487
20813
  log("Destroyed");
20488
20814
  }
@@ -20506,11 +20832,17 @@ const _WindowManager = class extends InvisiblePlugin {
20506
20832
  safeSetAttributes(attributes) {
20507
20833
  if (this.canOperate) {
20508
20834
  this.setAttributes(attributes);
20835
+ if (this.attributesDeboundceLog) {
20836
+ this.attributesDeboundceLog.logDebouncedShallowMerge("safeSetAttributes", attributes);
20837
+ }
20509
20838
  }
20510
20839
  }
20511
20840
  safeUpdateAttributes(keys, value) {
20512
20841
  if (this.canOperate) {
20513
20842
  this.updateAttributes(keys, value);
20843
+ if (this.attributesDeboundceLog) {
20844
+ this.attributesDeboundceLog.logDebouncedUpdateAttributes(keys, value);
20845
+ }
20514
20846
  }
20515
20847
  }
20516
20848
  setPrefersColorScheme(scheme) {
@@ -20518,9 +20850,10 @@ const _WindowManager = class extends InvisiblePlugin {
20518
20850
  (_b = (_a = this.appManager) == null ? void 0 : _a.boxManager) == null ? void 0 : _b.setPrefersColorScheme(scheme);
20519
20851
  }
20520
20852
  cleanCurrentScene() {
20521
- var _a;
20853
+ var _a, _b;
20522
20854
  log("clean current scene");
20523
20855
  (_a = this.focusedView) == null ? void 0 : _a.cleanCurrentScene();
20856
+ this.Logger && this.Logger.info(`[WindowManager]: cleanCurrentScene ${(_b = this.focusedView) == null ? void 0 : _b.focusScenePath}`);
20524
20857
  }
20525
20858
  redo() {
20526
20859
  var _a;
@@ -20531,8 +20864,9 @@ const _WindowManager = class extends InvisiblePlugin {
20531
20864
  return ((_a = this.focusedView) == null ? void 0 : _a.undo()) || 0;
20532
20865
  }
20533
20866
  delete() {
20534
- var _a;
20867
+ var _a, _b;
20535
20868
  (_a = this.focusedView) == null ? void 0 : _a.delete();
20869
+ this.Logger && this.Logger.info(`[WindowManager]: delete ${(_b = this.focusedView) == null ? void 0 : _b.focusScenePath}`);
20536
20870
  }
20537
20871
  copy() {
20538
20872
  var _a;