@netless/forge-slide 1.3.0-beta.1 → 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.
package/dist/slide.js CHANGED
@@ -63306,6 +63306,8 @@ var ImageModel = class extends ElementModel {
63306
63306
  super(root, scope, liveCursor, isPerformanceMode);
63307
63307
  _defineProperty16(this, "item", null);
63308
63308
  _defineProperty16(this, "imageSets", void 0);
63309
+ _defineProperty16(this, "imageElement", null);
63310
+ _defineProperty16(this, "imageLoadVersion", 0);
63309
63311
  _defineProperty16(this, "clearLocalPointsWhenYPointsChange", true);
63310
63312
  _defineProperty16(this, "shouldUseLocalPoints", true);
63311
63313
  _defineProperty16(this, "localPointsPick", 4);
@@ -63316,22 +63318,44 @@ var ImageModel = class extends ElementModel {
63316
63318
  this.root.set(ElementModel.KEYS.shadow, "");
63317
63319
  }
63318
63320
  subDispose() {
63321
+ this.imageLoadVersion++;
63322
+ if (this.imageElement) {
63323
+ this.imageElement.onload = null;
63324
+ this.imageElement.onerror = null;
63325
+ this.imageElement.remove();
63326
+ this.imageElement = null;
63327
+ return;
63328
+ }
63319
63329
  const img = this.imageSets.querySelector(`[id='${this.uuid}']`);
63320
63330
  if (img) {
63331
+ img.onload = null;
63332
+ img.onerror = null;
63321
63333
  img.remove();
63322
63334
  }
63323
63335
  }
63336
+ bindImageLoad(img) {
63337
+ const loadVersion = ++this.imageLoadVersion;
63338
+ img.onload = () => {
63339
+ if (this.imageLoadVersion !== loadVersion || !this.item) {
63340
+ return;
63341
+ }
63342
+ };
63343
+ img.onerror = null;
63344
+ }
63324
63345
  createPaperItem() {
63325
63346
  if (this.item) {
63326
63347
  return;
63327
63348
  }
63328
- if (!this.imageSets.querySelector(`[id='${this.uuid}']`)) {
63329
- const img = document.createElement("img");
63349
+ let img = this.imageSets.querySelector(`[id='${this.uuid}']`);
63350
+ if (!img) {
63351
+ img = document.createElement("img");
63330
63352
  img.crossOrigin = "anonymous";
63331
- img.src = this.src;
63332
63353
  img.id = this.uuid;
63333
63354
  this.imageSets.appendChild(img);
63334
63355
  }
63356
+ this.imageElement = img;
63357
+ this.bindImageLoad(img);
63358
+ img.src = this.src;
63335
63359
  this.item = new this.scope.Raster(this.uuid);
63336
63360
  const matrix = new this.scope.Matrix(this.pointsMatrix);
63337
63361
  this.item.matrix = matrix;
@@ -63354,8 +63378,10 @@ var ImageModel = class extends ElementModel {
63354
63378
  }
63355
63379
  onStyleKeyUpdate(key) {
63356
63380
  if (key === "src") {
63357
- const imgElement = this.imageSets.querySelector(`[id='${this.uuid}']`);
63381
+ const imgElement = this.imageElement ?? this.imageSets.querySelector(`[id='${this.uuid}']`);
63358
63382
  if (imgElement) {
63383
+ this.imageElement = imgElement;
63384
+ this.bindImageLoad(imgElement);
63359
63385
  imgElement.src = this.src;
63360
63386
  }
63361
63387
  }