babylonjs-gui 5.42.2 → 5.43.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/babylon.gui.d.ts CHANGED
@@ -2065,9 +2065,14 @@ declare module BABYLON.GUI {
2065
2065
  private _populateNinePatchSlicesFromImage;
2066
2066
  private _detectPointerOnOpaqueOnly;
2067
2067
  private _imageDataCache;
2068
+ /**
2069
+ * Cache of images to avoid loading the same image multiple times
2070
+ */
2068
2071
  static SourceImgCache: Map<string, {
2069
2072
  img: BABYLON.IImage;
2070
2073
  timesUsed: number;
2074
+ loaded: boolean;
2075
+ waitingForLoadCallback: Array<() => void>;
2071
2076
  }>;
2072
2077
  /**
2073
2078
  * BABYLON.Observable notified when the content is loaded
package/babylon.gui.js CHANGED
@@ -8449,14 +8449,31 @@ var Image = /** @class */ (function (_super) {
8449
8449
  var cachedData = Image.SourceImgCache.get(value);
8450
8450
  this._domImage = cachedData.img;
8451
8451
  cachedData.timesUsed += 1;
8452
- this._onImageLoaded();
8452
+ if (cachedData.loaded) {
8453
+ this._onImageLoaded();
8454
+ }
8455
+ else {
8456
+ cachedData.waitingForLoadCallback.push(this._onImageLoaded.bind(this));
8457
+ }
8453
8458
  return;
8454
8459
  }
8455
8460
  this._domImage = engine.createCanvasImage();
8456
8461
  if (value) {
8457
- Image.SourceImgCache.set(value, { img: this._domImage, timesUsed: 1 });
8462
+ Image.SourceImgCache.set(value, { img: this._domImage, timesUsed: 1, loaded: false, waitingForLoadCallback: [this._onImageLoaded.bind(this)] });
8458
8463
  }
8459
8464
  this._domImage.onload = function () {
8465
+ if (value) {
8466
+ var cachedData = Image.SourceImgCache.get(value);
8467
+ if (cachedData) {
8468
+ cachedData.loaded = true;
8469
+ for (var _i = 0, _a = cachedData.waitingForLoadCallback; _i < _a.length; _i++) {
8470
+ var waitingCallback = _a[_i];
8471
+ waitingCallback();
8472
+ }
8473
+ cachedData.waitingForLoadCallback.length = 0;
8474
+ return;
8475
+ }
8476
+ }
8460
8477
  _this._onImageLoaded();
8461
8478
  };
8462
8479
  if (value) {
@@ -8820,6 +8837,9 @@ var Image = /** @class */ (function (_super) {
8820
8837
  this.onSVGAttributesComputedObservable.clear();
8821
8838
  this._removeCacheUsage(this._source);
8822
8839
  };
8840
+ /**
8841
+ * Cache of images to avoid loading the same image multiple times
8842
+ */
8823
8843
  Image.SourceImgCache = new Map();
8824
8844
  // Static
8825
8845
  /** STRETCH_NONE */