@netless/forge-whiteboard 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28051,6 +28051,8 @@ var ImageModel = class extends ElementModel {
28051
28051
  super(root, scope, liveCursor, isPerformanceMode);
28052
28052
  _defineProperty16(this, "item", null);
28053
28053
  _defineProperty16(this, "imageSets", void 0);
28054
+ _defineProperty16(this, "imageElement", null);
28055
+ _defineProperty16(this, "imageLoadVersion", 0);
28054
28056
  _defineProperty16(this, "clearLocalPointsWhenYPointsChange", true);
28055
28057
  _defineProperty16(this, "shouldUseLocalPoints", true);
28056
28058
  _defineProperty16(this, "localPointsPick", 4);
@@ -28061,22 +28063,44 @@ var ImageModel = class extends ElementModel {
28061
28063
  this.root.set(ElementModel.KEYS.shadow, "");
28062
28064
  }
28063
28065
  subDispose() {
28066
+ this.imageLoadVersion++;
28067
+ if (this.imageElement) {
28068
+ this.imageElement.onload = null;
28069
+ this.imageElement.onerror = null;
28070
+ this.imageElement.remove();
28071
+ this.imageElement = null;
28072
+ return;
28073
+ }
28064
28074
  const img = this.imageSets.querySelector(`[id='${this.uuid}']`);
28065
28075
  if (img) {
28076
+ img.onload = null;
28077
+ img.onerror = null;
28066
28078
  img.remove();
28067
28079
  }
28068
28080
  }
28081
+ bindImageLoad(img) {
28082
+ const loadVersion = ++this.imageLoadVersion;
28083
+ img.onload = () => {
28084
+ if (this.imageLoadVersion !== loadVersion || !this.item) {
28085
+ return;
28086
+ }
28087
+ };
28088
+ img.onerror = null;
28089
+ }
28069
28090
  createPaperItem() {
28070
28091
  if (this.item) {
28071
28092
  return;
28072
28093
  }
28073
- if (!this.imageSets.querySelector(`[id='${this.uuid}']`)) {
28074
- const img = document.createElement("img");
28094
+ let img = this.imageSets.querySelector(`[id='${this.uuid}']`);
28095
+ if (!img) {
28096
+ img = document.createElement("img");
28075
28097
  img.crossOrigin = "anonymous";
28076
- img.src = this.src;
28077
28098
  img.id = this.uuid;
28078
28099
  this.imageSets.appendChild(img);
28079
28100
  }
28101
+ this.imageElement = img;
28102
+ this.bindImageLoad(img);
28103
+ img.src = this.src;
28080
28104
  this.item = new this.scope.Raster(this.uuid);
28081
28105
  const matrix = new this.scope.Matrix(this.pointsMatrix);
28082
28106
  this.item.matrix = matrix;
@@ -28099,8 +28123,10 @@ var ImageModel = class extends ElementModel {
28099
28123
  }
28100
28124
  onStyleKeyUpdate(key) {
28101
28125
  if (key === "src") {
28102
- const imgElement = this.imageSets.querySelector(`[id='${this.uuid}']`);
28126
+ const imgElement = this.imageElement ?? this.imageSets.querySelector(`[id='${this.uuid}']`);
28103
28127
  if (imgElement) {
28128
+ this.imageElement = imgElement;
28129
+ this.bindImageLoad(imgElement);
28104
28130
  imgElement.src = this.src;
28105
28131
  }
28106
28132
  }