@netless/forge-whiteboard 0.1.5 → 0.1.7

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.
@@ -27761,7 +27761,7 @@ var ToolbarModel = class extends import_eventemitter33.default {
27761
27761
  this.root = root;
27762
27762
  this.root.observe(this.handleRootUpdate);
27763
27763
  Object.keys(defaultStyle).forEach((key) => {
27764
- if (!this.root.has(key)) {
27764
+ if (!this.root.has(key) || this.root.get(key) === void 0) {
27765
27765
  this.root.set(key, defaultStyle[key]);
27766
27766
  }
27767
27767
  });
@@ -29993,6 +29993,8 @@ var WhiteboardApplication = class extends import_forge_room3.AbstractApplication
29993
29993
  paperScope = new import_paper.default.PaperScope();
29994
29994
  canvasElement = document.createElement("canvas");
29995
29995
  shadowScope = new import_paper.default.PaperScope();
29996
+ snapshotCanvasElement = document.createElement("canvas");
29997
+ snapshotScope = new import_paper.default.PaperScope();
29996
29998
  shadowCanvasElement = document.createElement("canvas");
29997
29999
  shadowEmitter;
29998
30000
  tools;
@@ -30147,6 +30149,12 @@ var WhiteboardApplication = class extends import_forge_room3.AbstractApplication
30147
30149
  this.inputType = type;
30148
30150
  this.emitter.emit("inputTypeChange", this.inputType);
30149
30151
  };
30152
+ this.emitter.on("error", (errorCode, errorMessage) => {
30153
+ (0, import_forge_room3.log)("WhiteboardApplicationError", {
30154
+ errorCode,
30155
+ errorMessage
30156
+ });
30157
+ });
30150
30158
  const that = this;
30151
30159
  Object.defineProperty(this.emitter, "tool", {
30152
30160
  get() {
@@ -30292,10 +30300,19 @@ var WhiteboardApplication = class extends import_forge_room3.AbstractApplication
30292
30300
  grab: new GrabTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope, this.camera)
30293
30301
  };
30294
30302
  this.toolbarModel.on("update", (style) => {
30295
- this.paperScope.tool = this.tools[style.tool].tool;
30303
+ if (this.tools[style.tool]) {
30304
+ this.paperScope.tool = this.tools[style.tool].tool;
30305
+ } else {
30306
+ this.emitter.emit("error", 300001, `${style.tool} not supported`);
30307
+ }
30296
30308
  this.emitter.emit("toolbarStyleChange", style);
30297
30309
  });
30298
- this.paperScope.tool = this.tools[this.toolbarModel.currentTool].tool;
30310
+ if (this.tools[this.toolbarModel.currentTool]) {
30311
+ this.paperScope.tool = this.tools[this.toolbarModel.currentTool].tool;
30312
+ } else {
30313
+ this.paperScope.tool = this.tools["curve"].tool;
30314
+ (0, import_forge_room3.log)(`${this.toolbarModel.currentTool} not supported, backup to curve`);
30315
+ }
30299
30316
  this.selectElementsModel.on("elementsChange", this.handleElementsSelect);
30300
30317
  this.trashedElementsModel.on("elementsChange", this.handleElementsTrash);
30301
30318
  this.trashedElementsModel.on("removeElementForSelf", this.handleRemoveTrashedElementForSelf);
@@ -30314,6 +30331,7 @@ var WhiteboardApplication = class extends import_forge_room3.AbstractApplication
30314
30331
  this.rootElement.appendChild(this.shadowCanvasElement);
30315
30332
  this.shadowScope.setup(this.shadowCanvasElement);
30316
30333
  this.shadowScope.settings.insertItems = false;
30334
+ this.snapshotScope.setup(this.snapshotCanvasElement);
30317
30335
  this.resizeObserver = new ResizeObserver(() => {
30318
30336
  const rootBounds = this.rootElement.getBoundingClientRect();
30319
30337
  const minWidth = Math.max(rootBounds.width, 10);
@@ -30513,7 +30531,7 @@ var WhiteboardApplication = class extends import_forge_room3.AbstractApplication
30513
30531
  getCurrentRenderableModel = () => {
30514
30532
  let layerId = this.userMap(this.userId).get(WhiteboardKeys.currentPage);
30515
30533
  if (!this.layers.has(layerId)) {
30516
- this.emitter.emit("error", 20001, `target page: ${layerId} not found`);
30534
+ this.emitter.emit("error", 300002, `target page: ${layerId} not found`);
30517
30535
  }
30518
30536
  return this.layers.get(layerId);
30519
30537
  };
@@ -30650,11 +30668,9 @@ var WhiteboardApplication = class extends import_forge_room3.AbstractApplication
30650
30668
  if (!renderableModel) {
30651
30669
  return Promise.resolve(null);
30652
30670
  }
30653
- const scope = new import_paper.default.PaperScope();
30654
- const canvas = document.createElement("canvas");
30655
- scope.setup(canvas);
30656
- scope.view.matrix = this.paperScope.project.view.matrix.clone();
30657
- scope.view.viewSize = this.paperScope.project.view.viewSize.clone();
30671
+ this.snapshotScope.project.activeLayer.removeChildren();
30672
+ this.snapshotScope.view.matrix = this.paperScope.project.view.matrix.clone();
30673
+ this.snapshotScope.view.viewSize = this.paperScope.project.view.viewSize.clone();
30658
30674
  for (const key of Array.from(renderableModel.elements.keys())) {
30659
30675
  let elementModel = null;
30660
30676
  if (renderableModel.elementModels.has(key)) {
@@ -30671,14 +30687,13 @@ var WhiteboardApplication = class extends import_forge_room3.AbstractApplication
30671
30687
  }
30672
30688
  if (elementModel.item) {
30673
30689
  const paperItem = elementModel.item.clone({ insert: false });
30674
- scope.project.activeLayer.addChild(paperItem);
30690
+ this.snapshotScope.project.activeLayer.addChild(paperItem);
30675
30691
  }
30676
30692
  }
30677
30693
  }
30678
- document.body.appendChild(scope.view.element);
30679
30694
  return new Promise((resolve) => {
30680
30695
  setTimeout(() => {
30681
- resolve(scope.view.element.toDataURL("image/png"));
30696
+ resolve(this.snapshotScope.view.element.toDataURL("image/png"));
30682
30697
  }, 32);
30683
30698
  });
30684
30699
  }
@@ -30694,6 +30709,7 @@ var WhiteboardApplication = class extends import_forge_room3.AbstractApplication
30694
30709
  this.rootElement.removeChild(this.shadowCanvasElement);
30695
30710
  this.paperScope.project.clear();
30696
30711
  this.shadowScope.project.clear();
30712
+ this.snapshotScope.project.clear();
30697
30713
  this.resizeObserver.disconnect();
30698
30714
  }
30699
30715
  };