@netless/forge-whiteboard 0.1.17 → 0.1.19

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.
@@ -29987,6 +29987,7 @@ var Whiteboard = class extends import_eventemitter38.default {
29987
29987
  _defineProperty31(this, "scaleCamera", void 0);
29988
29988
  _defineProperty31(this, "resetCamera", void 0);
29989
29989
  _defineProperty31(this, "showLiveCursor", void 0);
29990
+ _defineProperty31(this, "updateViewport", void 0);
29990
29991
  _defineProperty31(this, "setFreeModelUserPage", void 0);
29991
29992
  _defineProperty31(this, "indexedNavigation", void 0);
29992
29993
  _defineProperty31(this, "setViewModeToFree", void 0);
@@ -31151,6 +31152,20 @@ var WhiteboardApplication = class extends import_forge_room12.AbstractApplicatio
31151
31152
  }
31152
31153
  return null;
31153
31154
  }
31155
+ get viewportWidth() {
31156
+ const vw = this.getMap("attrs").get("viewportWidth");
31157
+ if (vw) {
31158
+ return vw;
31159
+ }
31160
+ return this.option.width;
31161
+ }
31162
+ get viewportHeight() {
31163
+ const vh = this.getMap("attrs").get("viewportHeight");
31164
+ if (vh) {
31165
+ return vh;
31166
+ }
31167
+ return this.option.height;
31168
+ }
31154
31169
  constructor() {
31155
31170
  var _this;
31156
31171
  super();
@@ -31190,6 +31205,12 @@ var WhiteboardApplication = class extends import_forge_room12.AbstractApplicatio
31190
31205
  _defineProperty43(this, "enableToolEvent", () => {
31191
31206
  return !(this.inputType === "pen" && !this.isPenEvent);
31192
31207
  });
31208
+ _defineProperty43(this, "handleViewportUpdate", (evt) => {
31209
+ if (evt.keysChanged.has("viewportWidth") || evt.keysChanged.has("viewportHeight")) {
31210
+ const rect = this.rootElement.getBoundingClientRect();
31211
+ this.adjustByOutFrame(rect.width, rect.height);
31212
+ }
31213
+ });
31193
31214
  _defineProperty43(this, "handleElementTranslateOut", (ids, container) => {
31194
31215
  const shadowLayer = this.shadowScope.project.activeLayer;
31195
31216
  let parent = null;
@@ -31422,21 +31443,24 @@ var WhiteboardApplication = class extends import_forge_room12.AbstractApplicatio
31422
31443
  }
31423
31444
  });
31424
31445
  _defineProperty43(this, "adjustByOutFrame", (frameWidth, frameHeight) => {
31425
- if (this.option.width > 0 && this.option.height > 0) {
31446
+ const viewportWidth = this.viewportWidth;
31447
+ const viewportHeight = this.viewportHeight;
31448
+ if (viewportWidth > 0 && viewportHeight > 0) {
31426
31449
  const minWidth = Math.max(frameWidth, 10);
31427
31450
  const minHeight = Math.max(frameHeight, 10);
31428
31451
  let width = minWidth;
31429
- let height = width * this.option.height / this.option.width;
31452
+ let height = width * viewportHeight / viewportWidth;
31430
31453
  if (height > minHeight) {
31431
31454
  height = minHeight;
31432
- width = height * this.option.width / this.option.height;
31455
+ width = height * viewportWidth / viewportHeight;
31433
31456
  }
31434
- this.camera.updateInherentScale(width / this.option.width);
31457
+ this.camera.updateInherentScale(width / viewportHeight);
31435
31458
  this.paperScope.project.view.viewSize = new this.paperScope.Size(width, height);
31436
31459
  this.shadowScope.project.view.viewSize = new this.paperScope.Size(width, height);
31437
31460
  this.camera.triggerZoom();
31438
31461
  }
31439
31462
  });
31463
+ window._wb = this;
31440
31464
  requestAnimationFrameHook(this.paperScope);
31441
31465
  requestAnimationFrameHook(this.shadowScope);
31442
31466
  const that = this;
@@ -31635,6 +31659,12 @@ var WhiteboardApplication = class extends import_forge_room12.AbstractApplicatio
31635
31659
  this.emitter.showLiveCursor = (value) => {
31636
31660
  this.liveCursor.showLiveCursor = value;
31637
31661
  };
31662
+ this.emitter.updateViewport = (width, height) => {
31663
+ this.updateOptionSize(width, height);
31664
+ };
31665
+ this.emitter.__setMainCanvasVisible = (visible) => {
31666
+ this.canvasElement.style.opacity = visible ? "1" : "0";
31667
+ };
31638
31668
  this.emitter.on("error", (errorCode, errorMessage) => {
31639
31669
  (0, import_forge_room12.log)("WhiteboardApplicationError", {
31640
31670
  errorCode,
@@ -31750,8 +31780,15 @@ var WhiteboardApplication = class extends import_forge_room12.AbstractApplicatio
31750
31780
  this.emitter["selfUserId"] = this.userId;
31751
31781
  this.option = option;
31752
31782
  if (this.option.stretchToFill) {
31753
- this.option.width = -1;
31754
- this.option.height = -1;
31783
+ this.getMap("attrs").set("viewportWidth", -1);
31784
+ this.getMap("attrs").set("viewportHeight", -1);
31785
+ } else {
31786
+ if (!this.getMap("attrs").has("viewportWidth")) {
31787
+ this.getMap("attrs").set("viewportWidth", option.width);
31788
+ }
31789
+ if (!this.getMap("attrs").has("viewportHeight")) {
31790
+ this.getMap("attrs").set("viewportHeight", option.height);
31791
+ }
31755
31792
  }
31756
31793
  this.userMap(this.userId).set(WhiteboardKeys.themeColor, "#009688");
31757
31794
  this.shadowEmitter = new ShadowEmitter(this.userMap(this.userId));
@@ -31920,12 +31957,13 @@ var WhiteboardApplication = class extends import_forge_room12.AbstractApplicatio
31920
31957
  this.clearElements();
31921
31958
  if (this.option.stretchToFill) {
31922
31959
  window.addEventListener("resize", () => {
31923
- const bounds = document.body.getBoundingClientRect();
31960
+ const bounds = this.rootElement.getBoundingClientRect();
31924
31961
  this.updateOptionSize(bounds.width, bounds.height);
31925
31962
  this.adjustByOutFrame(bounds.width, bounds.height);
31926
31963
  });
31927
31964
  }
31928
31965
  this.rootElement.appendChild(this.liveCursor.container);
31966
+ this.getMap("attrs").observe(this.handleViewportUpdate);
31929
31967
  }
31930
31968
  clearElements() {
31931
31969
  const userIds = this.userManager.userIdList();
@@ -32021,10 +32059,10 @@ var WhiteboardApplication = class extends import_forge_room12.AbstractApplicatio
32021
32059
  this.snapshotScope.view.viewSize = bounds.size.multiply(scale2);
32022
32060
  this.snapshotScope.view.matrix = matrix;
32023
32061
  } else if (area === "maxScale" && this.option.maxScaleRatio && this.option.maxScaleRatio !== -1) {
32024
- const width = this.option.width * this.option.maxScaleRatio;
32025
- const height = this.option.height * this.option.maxScaleRatio;
32026
- const offsetX = this.option.width * (this.option.maxScaleRatio - 1) / 2;
32027
- const offsetY = this.option.height * (this.option.maxScaleRatio - 1) / 2;
32062
+ const width = this.viewportWidth * this.option.maxScaleRatio;
32063
+ const height = this.viewportHeight * this.option.maxScaleRatio;
32064
+ const offsetX = this.viewportWidth * (this.option.maxScaleRatio - 1) / 2;
32065
+ const offsetY = this.viewportHeight * (this.option.maxScaleRatio - 1) / 2;
32028
32066
  const matrix = new this.paperScope.Matrix();
32029
32067
  matrix.scale(scale);
32030
32068
  matrix.translate({
@@ -32086,8 +32124,8 @@ var WhiteboardApplication = class extends import_forge_room12.AbstractApplicatio
32086
32124
  this.internalResizeObserver = value;
32087
32125
  }
32088
32126
  updateOptionSize(width, height) {
32089
- this.option.width = width;
32090
- this.option.height = height;
32127
+ this.getMap("attrs").set("viewportWidth", width);
32128
+ this.getMap("attrs").set("viewportHeight", height);
32091
32129
  this.camera.updateInitSize(new import_paper.default.Size(width, height));
32092
32130
  }
32093
32131
  async dispose() {