@esotericsoftware/spine-canvaskit 4.2.83 → 4.2.85

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.
@@ -4783,7 +4783,7 @@ var MeshAttachment = class _MeshAttachment extends VertexAttachment {
4783
4783
  this.copyTo(copy);
4784
4784
  copy.regionUVs = new Array(this.regionUVs.length);
4785
4785
  Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length);
4786
- copy.uvs = new Array(this.uvs.length);
4786
+ copy.uvs = this.uvs instanceof Float32Array ? Utils.newFloatArray(this.uvs.length) : new Array(this.uvs.length);
4787
4787
  Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, this.uvs.length);
4788
4788
  copy.triangles = new Array(this.triangles.length);
4789
4789
  Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length);
@@ -5524,16 +5524,15 @@ var AssetManagerBase = class {
5524
5524
  pathPrefix = "";
5525
5525
  textureLoader;
5526
5526
  downloader;
5527
- assets = {};
5528
- assetsRefCount = {};
5529
- assetsLoaded = {};
5527
+ cache;
5530
5528
  errors = {};
5531
5529
  toLoad = 0;
5532
5530
  loaded = 0;
5533
- constructor(textureLoader, pathPrefix = "", downloader = new Downloader()) {
5531
+ constructor(textureLoader, pathPrefix = "", downloader = new Downloader(), cache = new AssetCache()) {
5534
5532
  this.textureLoader = textureLoader;
5535
5533
  this.pathPrefix = pathPrefix;
5536
5534
  this.downloader = downloader;
5535
+ this.cache = cache;
5537
5536
  }
5538
5537
  start(path) {
5539
5538
  this.toLoad++;
@@ -5542,8 +5541,8 @@ var AssetManagerBase = class {
5542
5541
  success(callback, path, asset) {
5543
5542
  this.toLoad--;
5544
5543
  this.loaded++;
5545
- this.assets[path] = asset;
5546
- this.assetsRefCount[path] = (this.assetsRefCount[path] || 0) + 1;
5544
+ this.cache.assets[path] = asset;
5545
+ this.cache.assetsRefCount[path] = (this.cache.assetsRefCount[path] || 0) + 1;
5547
5546
  if (callback) callback(path, asset);
5548
5547
  }
5549
5548
  error(callback, path, message) {
@@ -5574,7 +5573,7 @@ var AssetManagerBase = class {
5574
5573
  }) {
5575
5574
  path = this.start(path);
5576
5575
  if (this.reuseAssets(path, success, error)) return;
5577
- this.assetsLoaded[path] = new Promise((resolve, reject) => {
5576
+ this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
5578
5577
  this.downloader.downloadBinary(path, (data) => {
5579
5578
  this.success(success, path, data);
5580
5579
  resolve(data);
@@ -5600,7 +5599,7 @@ var AssetManagerBase = class {
5600
5599
  }) {
5601
5600
  path = this.start(path);
5602
5601
  if (this.reuseAssets(path, success, error)) return;
5603
- this.assetsLoaded[path] = new Promise((resolve, reject) => {
5602
+ this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
5604
5603
  this.downloader.downloadJson(path, (data) => {
5605
5604
  this.success(success, path, data);
5606
5605
  resolve(data);
@@ -5614,10 +5613,14 @@ var AssetManagerBase = class {
5614
5613
  reuseAssets(path, success = () => {
5615
5614
  }, error = () => {
5616
5615
  }) {
5617
- const loadedStatus = this.assetsLoaded[path];
5616
+ const loadedStatus = this.cache.assetsLoaded[path];
5618
5617
  const alreadyExistsOrLoading = loadedStatus !== void 0;
5619
5618
  if (alreadyExistsOrLoading) {
5620
- loadedStatus.then((data) => this.success(success, path, data)).catch((errorMsg) => this.error(error, path, errorMsg));
5619
+ this.cache.assetsLoaded[path] = loadedStatus.then((data) => {
5620
+ data = data instanceof Image || data instanceof ImageBitmap ? this.textureLoader(data) : data;
5621
+ this.success(success, path, data);
5622
+ return data;
5623
+ }).catch((errorMsg) => this.error(error, path, errorMsg));
5621
5624
  }
5622
5625
  return alreadyExistsOrLoading;
5623
5626
  }
@@ -5626,7 +5629,7 @@ var AssetManagerBase = class {
5626
5629
  }) {
5627
5630
  path = this.start(path);
5628
5631
  if (this.reuseAssets(path, success, error)) return;
5629
- this.assetsLoaded[path] = new Promise((resolve, reject) => {
5632
+ this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
5630
5633
  let isBrowser = !!(typeof window !== "undefined" && typeof navigator !== "undefined" && window.document);
5631
5634
  let isWebWorker = !isBrowser;
5632
5635
  if (isWebWorker) {
@@ -5670,7 +5673,7 @@ var AssetManagerBase = class {
5670
5673
  let parent = index >= 0 ? path.substring(0, index + 1) : "";
5671
5674
  path = this.start(path);
5672
5675
  if (this.reuseAssets(path, success, error)) return;
5673
- this.assetsLoaded[path] = new Promise((resolve, reject) => {
5676
+ this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
5674
5677
  this.downloader.downloadText(path, (atlasText) => {
5675
5678
  try {
5676
5679
  let atlas = new TextureAtlas(atlasText);
@@ -5689,7 +5692,7 @@ var AssetManagerBase = class {
5689
5692
  },
5690
5693
  (imagePath, message) => {
5691
5694
  if (!abort) {
5692
- const errorMsg = `Couldn't load texture atlas ${path} page image: ${imagePath}`;
5695
+ const errorMsg = `Couldn't load texture ${path} page image: ${imagePath}`;
5693
5696
  this.error(error, path, errorMsg);
5694
5697
  reject(errorMsg);
5695
5698
  }
@@ -5714,7 +5717,7 @@ var AssetManagerBase = class {
5714
5717
  }, fileAlias) {
5715
5718
  path = this.start(path);
5716
5719
  if (this.reuseAssets(path, success, error)) return;
5717
- this.assetsLoaded[path] = new Promise((resolve, reject) => {
5720
+ this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
5718
5721
  this.downloader.downloadText(path, (atlasText) => {
5719
5722
  try {
5720
5723
  const atlas = new TextureAtlas(atlasText);
@@ -5778,33 +5781,36 @@ var AssetManagerBase = class {
5778
5781
  );
5779
5782
  });
5780
5783
  }
5784
+ setCache(cache) {
5785
+ this.cache = cache;
5786
+ }
5781
5787
  get(path) {
5782
- return this.assets[this.pathPrefix + path];
5788
+ return this.cache.assets[this.pathPrefix + path];
5783
5789
  }
5784
5790
  require(path) {
5785
5791
  path = this.pathPrefix + path;
5786
- let asset = this.assets[path];
5792
+ let asset = this.cache.assets[path];
5787
5793
  if (asset) return asset;
5788
5794
  let error = this.errors[path];
5789
5795
  throw Error("Asset not found: " + path + (error ? "\n" + error : ""));
5790
5796
  }
5791
5797
  remove(path) {
5792
5798
  path = this.pathPrefix + path;
5793
- let asset = this.assets[path];
5799
+ let asset = this.cache.assets[path];
5794
5800
  if (asset.dispose) asset.dispose();
5795
- delete this.assets[path];
5796
- delete this.assetsRefCount[path];
5797
- delete this.assetsLoaded[path];
5801
+ delete this.cache.assets[path];
5802
+ delete this.cache.assetsRefCount[path];
5803
+ delete this.cache.assetsLoaded[path];
5798
5804
  return asset;
5799
5805
  }
5800
5806
  removeAll() {
5801
- for (let path in this.assets) {
5802
- let asset = this.assets[path];
5807
+ for (let path in this.cache.assets) {
5808
+ let asset = this.cache.assets[path];
5803
5809
  if (asset.dispose) asset.dispose();
5804
5810
  }
5805
- this.assets = {};
5806
- this.assetsLoaded = {};
5807
- this.assetsRefCount = {};
5811
+ this.cache.assets = {};
5812
+ this.cache.assetsLoaded = {};
5813
+ this.cache.assetsRefCount = {};
5808
5814
  }
5809
5815
  isLoadingComplete() {
5810
5816
  return this.toLoad == 0;
@@ -5820,7 +5826,7 @@ var AssetManagerBase = class {
5820
5826
  }
5821
5827
  // dispose asset only if it's not used by others
5822
5828
  disposeAsset(path) {
5823
- if (--this.assetsRefCount[path] === 0) {
5829
+ if (--this.cache.assetsRefCount[path] === 0) {
5824
5830
  this.remove(path);
5825
5831
  }
5826
5832
  }
@@ -5831,6 +5837,23 @@ var AssetManagerBase = class {
5831
5837
  return this.errors;
5832
5838
  }
5833
5839
  };
5840
+ var AssetCache = class _AssetCache {
5841
+ assets = {};
5842
+ assetsRefCount = {};
5843
+ assetsLoaded = {};
5844
+ static AVAILABLE_CACHES = /* @__PURE__ */ new Map();
5845
+ static getCache(id) {
5846
+ const cache = _AssetCache.AVAILABLE_CACHES.get(id);
5847
+ if (cache) return cache;
5848
+ const newCache = new _AssetCache();
5849
+ _AssetCache.AVAILABLE_CACHES.set(id, newCache);
5850
+ return newCache;
5851
+ }
5852
+ async addAsset(path, asset) {
5853
+ this.assetsLoaded[path] = Promise.resolve(asset);
5854
+ this.assets[path] = await asset;
5855
+ }
5856
+ };
5834
5857
  var Downloader = class {
5835
5858
  callbacks = {};
5836
5859
  rawDataUris = {};
@@ -11512,6 +11535,7 @@ export {
11512
11535
  AnimationState,
11513
11536
  AnimationStateAdapter,
11514
11537
  AnimationStateData,
11538
+ AssetCache,
11515
11539
  AssetManagerBase,
11516
11540
  AtlasAttachmentLoader,
11517
11541
  Attachment,