@esotericsoftware/spine-pixi-v8 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.
@@ -33,6 +33,7 @@ var spine = (() => {
33
33
  AnimationState: () => AnimationState,
34
34
  AnimationStateAdapter: () => AnimationStateAdapter,
35
35
  AnimationStateData: () => AnimationStateData,
36
+ AssetCache: () => AssetCache,
36
37
  AssetManagerBase: () => AssetManagerBase,
37
38
  AtlasAttachmentLoader: () => AtlasAttachmentLoader,
38
39
  Attachment: () => Attachment,
@@ -4952,7 +4953,7 @@ var spine = (() => {
4952
4953
  this.copyTo(copy);
4953
4954
  copy.regionUVs = new Array(this.regionUVs.length);
4954
4955
  Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length);
4955
- copy.uvs = new Array(this.uvs.length);
4956
+ copy.uvs = this.uvs instanceof Float32Array ? Utils.newFloatArray(this.uvs.length) : new Array(this.uvs.length);
4956
4957
  Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, this.uvs.length);
4957
4958
  copy.triangles = new Array(this.triangles.length);
4958
4959
  Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length);
@@ -5693,16 +5694,15 @@ var spine = (() => {
5693
5694
  pathPrefix = "";
5694
5695
  textureLoader;
5695
5696
  downloader;
5696
- assets = {};
5697
- assetsRefCount = {};
5698
- assetsLoaded = {};
5697
+ cache;
5699
5698
  errors = {};
5700
5699
  toLoad = 0;
5701
5700
  loaded = 0;
5702
- constructor(textureLoader, pathPrefix = "", downloader = new Downloader()) {
5701
+ constructor(textureLoader, pathPrefix = "", downloader = new Downloader(), cache = new AssetCache()) {
5703
5702
  this.textureLoader = textureLoader;
5704
5703
  this.pathPrefix = pathPrefix;
5705
5704
  this.downloader = downloader;
5705
+ this.cache = cache;
5706
5706
  }
5707
5707
  start(path2) {
5708
5708
  this.toLoad++;
@@ -5711,8 +5711,8 @@ var spine = (() => {
5711
5711
  success(callback, path2, asset) {
5712
5712
  this.toLoad--;
5713
5713
  this.loaded++;
5714
- this.assets[path2] = asset;
5715
- this.assetsRefCount[path2] = (this.assetsRefCount[path2] || 0) + 1;
5714
+ this.cache.assets[path2] = asset;
5715
+ this.cache.assetsRefCount[path2] = (this.cache.assetsRefCount[path2] || 0) + 1;
5716
5716
  if (callback) callback(path2, asset);
5717
5717
  }
5718
5718
  error(callback, path2, message) {
@@ -5743,7 +5743,7 @@ var spine = (() => {
5743
5743
  }) {
5744
5744
  path2 = this.start(path2);
5745
5745
  if (this.reuseAssets(path2, success, error)) return;
5746
- this.assetsLoaded[path2] = new Promise((resolve, reject) => {
5746
+ this.cache.assetsLoaded[path2] = new Promise((resolve, reject) => {
5747
5747
  this.downloader.downloadBinary(path2, (data) => {
5748
5748
  this.success(success, path2, data);
5749
5749
  resolve(data);
@@ -5769,7 +5769,7 @@ var spine = (() => {
5769
5769
  }) {
5770
5770
  path2 = this.start(path2);
5771
5771
  if (this.reuseAssets(path2, success, error)) return;
5772
- this.assetsLoaded[path2] = new Promise((resolve, reject) => {
5772
+ this.cache.assetsLoaded[path2] = new Promise((resolve, reject) => {
5773
5773
  this.downloader.downloadJson(path2, (data) => {
5774
5774
  this.success(success, path2, data);
5775
5775
  resolve(data);
@@ -5783,10 +5783,14 @@ var spine = (() => {
5783
5783
  reuseAssets(path2, success = () => {
5784
5784
  }, error = () => {
5785
5785
  }) {
5786
- const loadedStatus = this.assetsLoaded[path2];
5786
+ const loadedStatus = this.cache.assetsLoaded[path2];
5787
5787
  const alreadyExistsOrLoading = loadedStatus !== void 0;
5788
5788
  if (alreadyExistsOrLoading) {
5789
- loadedStatus.then((data) => this.success(success, path2, data)).catch((errorMsg) => this.error(error, path2, errorMsg));
5789
+ this.cache.assetsLoaded[path2] = loadedStatus.then((data) => {
5790
+ data = data instanceof Image || data instanceof ImageBitmap ? this.textureLoader(data) : data;
5791
+ this.success(success, path2, data);
5792
+ return data;
5793
+ }).catch((errorMsg) => this.error(error, path2, errorMsg));
5790
5794
  }
5791
5795
  return alreadyExistsOrLoading;
5792
5796
  }
@@ -5795,7 +5799,7 @@ var spine = (() => {
5795
5799
  }) {
5796
5800
  path2 = this.start(path2);
5797
5801
  if (this.reuseAssets(path2, success, error)) return;
5798
- this.assetsLoaded[path2] = new Promise((resolve, reject) => {
5802
+ this.cache.assetsLoaded[path2] = new Promise((resolve, reject) => {
5799
5803
  let isBrowser = !!(typeof window !== "undefined" && typeof navigator !== "undefined" && window.document);
5800
5804
  let isWebWorker = !isBrowser;
5801
5805
  if (isWebWorker) {
@@ -5839,7 +5843,7 @@ var spine = (() => {
5839
5843
  let parent = index >= 0 ? path2.substring(0, index + 1) : "";
5840
5844
  path2 = this.start(path2);
5841
5845
  if (this.reuseAssets(path2, success, error)) return;
5842
- this.assetsLoaded[path2] = new Promise((resolve, reject) => {
5846
+ this.cache.assetsLoaded[path2] = new Promise((resolve, reject) => {
5843
5847
  this.downloader.downloadText(path2, (atlasText) => {
5844
5848
  try {
5845
5849
  let atlas = new TextureAtlas(atlasText);
@@ -5858,7 +5862,7 @@ var spine = (() => {
5858
5862
  },
5859
5863
  (imagePath, message) => {
5860
5864
  if (!abort) {
5861
- const errorMsg = `Couldn't load texture atlas ${path2} page image: ${imagePath}`;
5865
+ const errorMsg = `Couldn't load texture ${path2} page image: ${imagePath}`;
5862
5866
  this.error(error, path2, errorMsg);
5863
5867
  reject(errorMsg);
5864
5868
  }
@@ -5883,7 +5887,7 @@ var spine = (() => {
5883
5887
  }, fileAlias) {
5884
5888
  path2 = this.start(path2);
5885
5889
  if (this.reuseAssets(path2, success, error)) return;
5886
- this.assetsLoaded[path2] = new Promise((resolve, reject) => {
5890
+ this.cache.assetsLoaded[path2] = new Promise((resolve, reject) => {
5887
5891
  this.downloader.downloadText(path2, (atlasText) => {
5888
5892
  try {
5889
5893
  const atlas = new TextureAtlas(atlasText);
@@ -5947,33 +5951,36 @@ var spine = (() => {
5947
5951
  );
5948
5952
  });
5949
5953
  }
5954
+ setCache(cache) {
5955
+ this.cache = cache;
5956
+ }
5950
5957
  get(path2) {
5951
- return this.assets[this.pathPrefix + path2];
5958
+ return this.cache.assets[this.pathPrefix + path2];
5952
5959
  }
5953
5960
  require(path2) {
5954
5961
  path2 = this.pathPrefix + path2;
5955
- let asset = this.assets[path2];
5962
+ let asset = this.cache.assets[path2];
5956
5963
  if (asset) return asset;
5957
5964
  let error = this.errors[path2];
5958
5965
  throw Error("Asset not found: " + path2 + (error ? "\n" + error : ""));
5959
5966
  }
5960
5967
  remove(path2) {
5961
5968
  path2 = this.pathPrefix + path2;
5962
- let asset = this.assets[path2];
5969
+ let asset = this.cache.assets[path2];
5963
5970
  if (asset.dispose) asset.dispose();
5964
- delete this.assets[path2];
5965
- delete this.assetsRefCount[path2];
5966
- delete this.assetsLoaded[path2];
5971
+ delete this.cache.assets[path2];
5972
+ delete this.cache.assetsRefCount[path2];
5973
+ delete this.cache.assetsLoaded[path2];
5967
5974
  return asset;
5968
5975
  }
5969
5976
  removeAll() {
5970
- for (let path2 in this.assets) {
5971
- let asset = this.assets[path2];
5977
+ for (let path2 in this.cache.assets) {
5978
+ let asset = this.cache.assets[path2];
5972
5979
  if (asset.dispose) asset.dispose();
5973
5980
  }
5974
- this.assets = {};
5975
- this.assetsLoaded = {};
5976
- this.assetsRefCount = {};
5981
+ this.cache.assets = {};
5982
+ this.cache.assetsLoaded = {};
5983
+ this.cache.assetsRefCount = {};
5977
5984
  }
5978
5985
  isLoadingComplete() {
5979
5986
  return this.toLoad == 0;
@@ -5989,7 +5996,7 @@ var spine = (() => {
5989
5996
  }
5990
5997
  // dispose asset only if it's not used by others
5991
5998
  disposeAsset(path2) {
5992
- if (--this.assetsRefCount[path2] === 0) {
5999
+ if (--this.cache.assetsRefCount[path2] === 0) {
5993
6000
  this.remove(path2);
5994
6001
  }
5995
6002
  }
@@ -6000,6 +6007,23 @@ var spine = (() => {
6000
6007
  return this.errors;
6001
6008
  }
6002
6009
  };
6010
+ var AssetCache = class _AssetCache {
6011
+ assets = {};
6012
+ assetsRefCount = {};
6013
+ assetsLoaded = {};
6014
+ static AVAILABLE_CACHES = /* @__PURE__ */ new Map();
6015
+ static getCache(id) {
6016
+ const cache = _AssetCache.AVAILABLE_CACHES.get(id);
6017
+ if (cache) return cache;
6018
+ const newCache = new _AssetCache();
6019
+ _AssetCache.AVAILABLE_CACHES.set(id, newCache);
6020
+ return newCache;
6021
+ }
6022
+ async addAsset(path2, asset) {
6023
+ this.assetsLoaded[path2] = Promise.resolve(asset);
6024
+ this.assets[path2] = await asset;
6025
+ }
6026
+ };
6003
6027
  var Downloader = class {
6004
6028
  callbacks = {};
6005
6029
  rawDataUris = {};
@@ -11514,6 +11538,7 @@ var spine = (() => {
11514
11538
  };
11515
11539
 
11516
11540
  // spine-pixi-v8/src/assets/atlasLoader.ts
11541
+ var loaderName = "spineTextureAtlasLoader";
11517
11542
  var spineTextureAtlasLoader = {
11518
11543
  extension: import_pixi2.ExtensionType.Asset,
11519
11544
  resolver: {
@@ -11528,10 +11553,11 @@ var spine = (() => {
11528
11553
  }
11529
11554
  },
11530
11555
  loader: {
11556
+ name: loaderName,
11531
11557
  extension: {
11532
11558
  type: import_pixi2.ExtensionType.LoadParser,
11533
11559
  priority: import_pixi2.LoaderParserPriority.Normal,
11534
- name: "spineTextureAtlasLoader"
11560
+ name: loaderName
11535
11561
  },
11536
11562
  test(url) {
11537
11563
  return (0, import_pixi2.checkExtension)(url, ".atlas");
@@ -11544,7 +11570,8 @@ var spine = (() => {
11544
11570
  testParse(asset, options) {
11545
11571
  const isExtensionRight = (0, import_pixi2.checkExtension)(options.src, ".atlas");
11546
11572
  const isString = typeof asset === "string";
11547
- return Promise.resolve(isExtensionRight && isString);
11573
+ const isExplicitLoadParserSet = options.loadParser === loaderName;
11574
+ return Promise.resolve((isExtensionRight || isExplicitLoadParserSet) && isString);
11548
11575
  },
11549
11576
  unload(atlas) {
11550
11577
  atlas.dispose();
@@ -11573,7 +11600,9 @@ var spine = (() => {
11573
11600
  src: (0, import_pixi2.copySearchParams)(url, options.src),
11574
11601
  data: {
11575
11602
  ...metadata.imageMetadata,
11576
- alphaMode: page.pma ? "premultiplied-alpha" : "premultiply-alpha-on-upload"
11603
+ // alphaMode: 'premultiplied-alpha'
11604
+ alphaMode: "premultiply-alpha-on-upload"
11605
+ // alphaMode: 'no-premultiply-alpha'
11577
11606
  }
11578
11607
  };
11579
11608
  const pixiPromise = loader.load(assetsToLoadIn).then((texture) => {
@@ -11591,6 +11620,7 @@ var spine = (() => {
11591
11620
 
11592
11621
  // spine-pixi-v8/src/assets/skeletonLoader.ts
11593
11622
  var import_pixi3 = __require("pixi.js");
11623
+ var loaderName2 = "spineSkeletonLoader";
11594
11624
  function isJson(resource) {
11595
11625
  return Object.prototype.hasOwnProperty.call(resource, "bones");
11596
11626
  }
@@ -11600,10 +11630,11 @@ var spine = (() => {
11600
11630
  var spineLoaderExtension = {
11601
11631
  extension: import_pixi3.ExtensionType.Asset,
11602
11632
  loader: {
11633
+ name: loaderName2,
11603
11634
  extension: {
11604
11635
  type: import_pixi3.ExtensionType.LoadParser,
11605
11636
  priority: import_pixi3.LoaderParserPriority.Normal,
11606
- name: "spineSkeletonLoader"
11637
+ name: loaderName2
11607
11638
  },
11608
11639
  test(url) {
11609
11640
  return (0, import_pixi3.checkExtension)(url, ".skel");
@@ -11616,7 +11647,8 @@ var spine = (() => {
11616
11647
  testParse(asset, options) {
11617
11648
  const isJsonSpineModel = (0, import_pixi3.checkExtension)(options.src, ".json") && isJson(asset);
11618
11649
  const isBinarySpineModel = (0, import_pixi3.checkExtension)(options.src, ".skel") && isBuffer(asset);
11619
- return Promise.resolve(isJsonSpineModel || isBinarySpineModel);
11650
+ const isExplicitLoadParserSet = options.loadParser === loaderName2;
11651
+ return Promise.resolve(isJsonSpineModel || isBinarySpineModel || isExplicitLoadParserSet);
11620
11652
  }
11621
11653
  }
11622
11654
  };