@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.
- package/dist/esm/spine-canvaskit.min.mjs +2 -2
- package/dist/esm/spine-canvaskit.mjs +51 -27
- package/dist/esm/spine-canvaskit.mjs.map +2 -2
- package/dist/iife/spine-canvaskit.js +51 -27
- package/dist/iife/spine-canvaskit.js.map +2 -2
- package/dist/iife/spine-canvaskit.min.js +2 -2
- package/package.json +2 -2
|
@@ -26,6 +26,7 @@ var spine = (() => {
|
|
|
26
26
|
AnimationState: () => AnimationState,
|
|
27
27
|
AnimationStateAdapter: () => AnimationStateAdapter,
|
|
28
28
|
AnimationStateData: () => AnimationStateData,
|
|
29
|
+
AssetCache: () => AssetCache,
|
|
29
30
|
AssetManagerBase: () => AssetManagerBase,
|
|
30
31
|
AtlasAttachmentLoader: () => AtlasAttachmentLoader,
|
|
31
32
|
Attachment: () => Attachment,
|
|
@@ -4928,7 +4929,7 @@ var spine = (() => {
|
|
|
4928
4929
|
this.copyTo(copy);
|
|
4929
4930
|
copy.regionUVs = new Array(this.regionUVs.length);
|
|
4930
4931
|
Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length);
|
|
4931
|
-
copy.uvs = new Array(this.uvs.length);
|
|
4932
|
+
copy.uvs = this.uvs instanceof Float32Array ? Utils.newFloatArray(this.uvs.length) : new Array(this.uvs.length);
|
|
4932
4933
|
Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, this.uvs.length);
|
|
4933
4934
|
copy.triangles = new Array(this.triangles.length);
|
|
4934
4935
|
Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length);
|
|
@@ -5669,16 +5670,15 @@ var spine = (() => {
|
|
|
5669
5670
|
pathPrefix = "";
|
|
5670
5671
|
textureLoader;
|
|
5671
5672
|
downloader;
|
|
5672
|
-
|
|
5673
|
-
assetsRefCount = {};
|
|
5674
|
-
assetsLoaded = {};
|
|
5673
|
+
cache;
|
|
5675
5674
|
errors = {};
|
|
5676
5675
|
toLoad = 0;
|
|
5677
5676
|
loaded = 0;
|
|
5678
|
-
constructor(textureLoader, pathPrefix = "", downloader = new Downloader()) {
|
|
5677
|
+
constructor(textureLoader, pathPrefix = "", downloader = new Downloader(), cache = new AssetCache()) {
|
|
5679
5678
|
this.textureLoader = textureLoader;
|
|
5680
5679
|
this.pathPrefix = pathPrefix;
|
|
5681
5680
|
this.downloader = downloader;
|
|
5681
|
+
this.cache = cache;
|
|
5682
5682
|
}
|
|
5683
5683
|
start(path) {
|
|
5684
5684
|
this.toLoad++;
|
|
@@ -5687,8 +5687,8 @@ var spine = (() => {
|
|
|
5687
5687
|
success(callback, path, asset) {
|
|
5688
5688
|
this.toLoad--;
|
|
5689
5689
|
this.loaded++;
|
|
5690
|
-
this.assets[path] = asset;
|
|
5691
|
-
this.assetsRefCount[path] = (this.assetsRefCount[path] || 0) + 1;
|
|
5690
|
+
this.cache.assets[path] = asset;
|
|
5691
|
+
this.cache.assetsRefCount[path] = (this.cache.assetsRefCount[path] || 0) + 1;
|
|
5692
5692
|
if (callback) callback(path, asset);
|
|
5693
5693
|
}
|
|
5694
5694
|
error(callback, path, message) {
|
|
@@ -5719,7 +5719,7 @@ var spine = (() => {
|
|
|
5719
5719
|
}) {
|
|
5720
5720
|
path = this.start(path);
|
|
5721
5721
|
if (this.reuseAssets(path, success, error)) return;
|
|
5722
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5722
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5723
5723
|
this.downloader.downloadBinary(path, (data) => {
|
|
5724
5724
|
this.success(success, path, data);
|
|
5725
5725
|
resolve(data);
|
|
@@ -5745,7 +5745,7 @@ var spine = (() => {
|
|
|
5745
5745
|
}) {
|
|
5746
5746
|
path = this.start(path);
|
|
5747
5747
|
if (this.reuseAssets(path, success, error)) return;
|
|
5748
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5748
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5749
5749
|
this.downloader.downloadJson(path, (data) => {
|
|
5750
5750
|
this.success(success, path, data);
|
|
5751
5751
|
resolve(data);
|
|
@@ -5759,10 +5759,14 @@ var spine = (() => {
|
|
|
5759
5759
|
reuseAssets(path, success = () => {
|
|
5760
5760
|
}, error = () => {
|
|
5761
5761
|
}) {
|
|
5762
|
-
const loadedStatus = this.assetsLoaded[path];
|
|
5762
|
+
const loadedStatus = this.cache.assetsLoaded[path];
|
|
5763
5763
|
const alreadyExistsOrLoading = loadedStatus !== void 0;
|
|
5764
5764
|
if (alreadyExistsOrLoading) {
|
|
5765
|
-
|
|
5765
|
+
this.cache.assetsLoaded[path] = loadedStatus.then((data) => {
|
|
5766
|
+
data = data instanceof Image || data instanceof ImageBitmap ? this.textureLoader(data) : data;
|
|
5767
|
+
this.success(success, path, data);
|
|
5768
|
+
return data;
|
|
5769
|
+
}).catch((errorMsg) => this.error(error, path, errorMsg));
|
|
5766
5770
|
}
|
|
5767
5771
|
return alreadyExistsOrLoading;
|
|
5768
5772
|
}
|
|
@@ -5771,7 +5775,7 @@ var spine = (() => {
|
|
|
5771
5775
|
}) {
|
|
5772
5776
|
path = this.start(path);
|
|
5773
5777
|
if (this.reuseAssets(path, success, error)) return;
|
|
5774
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5778
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5775
5779
|
let isBrowser = !!(typeof window !== "undefined" && typeof navigator !== "undefined" && window.document);
|
|
5776
5780
|
let isWebWorker = !isBrowser;
|
|
5777
5781
|
if (isWebWorker) {
|
|
@@ -5815,7 +5819,7 @@ var spine = (() => {
|
|
|
5815
5819
|
let parent = index >= 0 ? path.substring(0, index + 1) : "";
|
|
5816
5820
|
path = this.start(path);
|
|
5817
5821
|
if (this.reuseAssets(path, success, error)) return;
|
|
5818
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5822
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5819
5823
|
this.downloader.downloadText(path, (atlasText) => {
|
|
5820
5824
|
try {
|
|
5821
5825
|
let atlas = new TextureAtlas(atlasText);
|
|
@@ -5834,7 +5838,7 @@ var spine = (() => {
|
|
|
5834
5838
|
},
|
|
5835
5839
|
(imagePath, message) => {
|
|
5836
5840
|
if (!abort) {
|
|
5837
|
-
const errorMsg = `Couldn't load texture
|
|
5841
|
+
const errorMsg = `Couldn't load texture ${path} page image: ${imagePath}`;
|
|
5838
5842
|
this.error(error, path, errorMsg);
|
|
5839
5843
|
reject(errorMsg);
|
|
5840
5844
|
}
|
|
@@ -5859,7 +5863,7 @@ var spine = (() => {
|
|
|
5859
5863
|
}, fileAlias) {
|
|
5860
5864
|
path = this.start(path);
|
|
5861
5865
|
if (this.reuseAssets(path, success, error)) return;
|
|
5862
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5866
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5863
5867
|
this.downloader.downloadText(path, (atlasText) => {
|
|
5864
5868
|
try {
|
|
5865
5869
|
const atlas = new TextureAtlas(atlasText);
|
|
@@ -5923,33 +5927,36 @@ var spine = (() => {
|
|
|
5923
5927
|
);
|
|
5924
5928
|
});
|
|
5925
5929
|
}
|
|
5930
|
+
setCache(cache) {
|
|
5931
|
+
this.cache = cache;
|
|
5932
|
+
}
|
|
5926
5933
|
get(path) {
|
|
5927
|
-
return this.assets[this.pathPrefix + path];
|
|
5934
|
+
return this.cache.assets[this.pathPrefix + path];
|
|
5928
5935
|
}
|
|
5929
5936
|
require(path) {
|
|
5930
5937
|
path = this.pathPrefix + path;
|
|
5931
|
-
let asset = this.assets[path];
|
|
5938
|
+
let asset = this.cache.assets[path];
|
|
5932
5939
|
if (asset) return asset;
|
|
5933
5940
|
let error = this.errors[path];
|
|
5934
5941
|
throw Error("Asset not found: " + path + (error ? "\n" + error : ""));
|
|
5935
5942
|
}
|
|
5936
5943
|
remove(path) {
|
|
5937
5944
|
path = this.pathPrefix + path;
|
|
5938
|
-
let asset = this.assets[path];
|
|
5945
|
+
let asset = this.cache.assets[path];
|
|
5939
5946
|
if (asset.dispose) asset.dispose();
|
|
5940
|
-
delete this.assets[path];
|
|
5941
|
-
delete this.assetsRefCount[path];
|
|
5942
|
-
delete this.assetsLoaded[path];
|
|
5947
|
+
delete this.cache.assets[path];
|
|
5948
|
+
delete this.cache.assetsRefCount[path];
|
|
5949
|
+
delete this.cache.assetsLoaded[path];
|
|
5943
5950
|
return asset;
|
|
5944
5951
|
}
|
|
5945
5952
|
removeAll() {
|
|
5946
|
-
for (let path in this.assets) {
|
|
5947
|
-
let asset = this.assets[path];
|
|
5953
|
+
for (let path in this.cache.assets) {
|
|
5954
|
+
let asset = this.cache.assets[path];
|
|
5948
5955
|
if (asset.dispose) asset.dispose();
|
|
5949
5956
|
}
|
|
5950
|
-
this.assets = {};
|
|
5951
|
-
this.assetsLoaded = {};
|
|
5952
|
-
this.assetsRefCount = {};
|
|
5957
|
+
this.cache.assets = {};
|
|
5958
|
+
this.cache.assetsLoaded = {};
|
|
5959
|
+
this.cache.assetsRefCount = {};
|
|
5953
5960
|
}
|
|
5954
5961
|
isLoadingComplete() {
|
|
5955
5962
|
return this.toLoad == 0;
|
|
@@ -5965,7 +5972,7 @@ var spine = (() => {
|
|
|
5965
5972
|
}
|
|
5966
5973
|
// dispose asset only if it's not used by others
|
|
5967
5974
|
disposeAsset(path) {
|
|
5968
|
-
if (--this.assetsRefCount[path] === 0) {
|
|
5975
|
+
if (--this.cache.assetsRefCount[path] === 0) {
|
|
5969
5976
|
this.remove(path);
|
|
5970
5977
|
}
|
|
5971
5978
|
}
|
|
@@ -5976,6 +5983,23 @@ var spine = (() => {
|
|
|
5976
5983
|
return this.errors;
|
|
5977
5984
|
}
|
|
5978
5985
|
};
|
|
5986
|
+
var AssetCache = class _AssetCache {
|
|
5987
|
+
assets = {};
|
|
5988
|
+
assetsRefCount = {};
|
|
5989
|
+
assetsLoaded = {};
|
|
5990
|
+
static AVAILABLE_CACHES = /* @__PURE__ */ new Map();
|
|
5991
|
+
static getCache(id) {
|
|
5992
|
+
const cache = _AssetCache.AVAILABLE_CACHES.get(id);
|
|
5993
|
+
if (cache) return cache;
|
|
5994
|
+
const newCache = new _AssetCache();
|
|
5995
|
+
_AssetCache.AVAILABLE_CACHES.set(id, newCache);
|
|
5996
|
+
return newCache;
|
|
5997
|
+
}
|
|
5998
|
+
async addAsset(path, asset) {
|
|
5999
|
+
this.assetsLoaded[path] = Promise.resolve(asset);
|
|
6000
|
+
this.assets[path] = await asset;
|
|
6001
|
+
}
|
|
6002
|
+
};
|
|
5979
6003
|
var Downloader = class {
|
|
5980
6004
|
callbacks = {};
|
|
5981
6005
|
rawDataUris = {};
|