Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pixi/assets

Package Overview
Dependencies
Maintainers
3
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixi/assets - npm Package Compare versions

Comparing version 7.0.0-beta.3 to 7.0.0-beta.4

104

dist/cjs/assets.js
/*!
* @pixi/assets - v7.0.0-beta.3
* Compiled Thu, 13 Oct 2022 15:35:43 UTC
* @pixi/assets - v7.0.0-beta.4
* Compiled Thu, 20 Oct 2022 19:45:44 UTC
*

@@ -782,16 +782,50 @@ * @pixi/assets is licensed under the MIT License.

let MAX_WORKERS;
const WHITE_PNG = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+ip1sAAAAASUVORK5CYII=";
const checkImageBitmapCode = {
id: "checkImageBitmap",
code: `
async function checkImageBitmap()
{
try
{
if (typeof createImageBitmap !== 'function') return false;
const response = await fetch('${WHITE_PNG}');
const imageBlob = await response.blob();
const imageBitmap = await createImageBitmap(imageBlob);
return imageBitmap.width === 1 && imageBitmap.height === 1;
}
catch (e)
{
return false;
}
}
checkImageBitmap().then((result) => { self.postMessage(result); });
`
};
const workerCode = {
id: "loadImageBitmap",
code: `
self.onmessage = function(event) {
async function loadImageBitmap(url)
{
const response = await fetch(url);
async function loadImageBitmap(url)
if (!response.ok)
{
const response = await fetch(url);
const imageBlob = await response.blob();
const imageBitmap = await createImageBitmap(imageBlob);
return imageBitmap;
throw new Error(\`[WorkerManager.loadImageBitmap] Failed to fetch \${url}: \`
+ \`\${response.status} \${response.statusText}\`);
}
loadImageBitmap(event.data.data[0]).then(imageBitmap => {
const imageBlob = await response.blob();
const imageBitmap = await createImageBitmap(imageBlob);
return imageBitmap;
}
self.onmessage = async (event) =>
{
try
{
const imageBitmap = await loadImageBitmap(event.data.data[0]);
self.postMessage({

@@ -802,10 +836,12 @@ data: imageBitmap,

}, [imageBitmap]);
}).catch(error => {
}
catch(e)
{
self.postMessage({
data: null,
error: e,
uuid: event.data.uuid,
id: event.data.id,
});
});
}`
}
};`
};

@@ -821,2 +857,16 @@ let workerURL;

}
isImageBitmapSupported() {
if (this._isImageBitmapSupported !== void 0)
return this._isImageBitmapSupported;
this._isImageBitmapSupported = new Promise((resolve) => {
const workerURL2 = URL.createObjectURL(new Blob([checkImageBitmapCode.code], { type: "application/javascript" }));
const worker = new Worker(workerURL2);
worker.addEventListener("message", (event) => {
worker.terminate();
URL.revokeObjectURL(workerURL2);
resolve(event.data);
});
});
return this._isImageBitmapSupported;
}
loadImageBitmap(src) {

@@ -853,10 +903,13 @@ return this._run("loadImageBitmap", [src]);

complete(data) {
const result = data.data;
this.resolveHash[data.uuid](result);
if (data.error !== void 0) {
this.resolveHash[data.uuid].reject(data.error);
} else {
this.resolveHash[data.uuid].resolve(data.data);
}
this.resolveHash[data.uuid] = null;
}
_run(id, args) {
this._initWorkers();
const promise = new Promise((resolve) => {
this.queue.push({ id, arguments: args, resolve });
async _run(id, args) {
await this._initWorkers();
const promise = new Promise((resolve, reject) => {
this.queue.push({ id, arguments: args, resolve, reject });
});

@@ -875,3 +928,3 @@ this.next();

const id = toDo.id;
this.resolveHash[UUID] = toDo.resolve;
this.resolveHash[UUID] = { resolve: toDo.resolve, reject: toDo.reject };
worker.postMessage({

@@ -906,2 +959,5 @@ data: toDo.arguments,

const response = await core.settings.ADAPTER.fetch(url);
if (!response.ok) {
throw new Error(`[loadImageBitmap] Failed to fetch ${url}: ${response.status} ${response.statusText}`);
}
const imageBlob = await response.blob();

@@ -922,3 +978,3 @@ const imageBitmap = await createImageBitmap(imageBlob);

for (let i = 0; i < validImages.length; i++) {
if (url.indexOf(`data:image/${validImages[i].slice(1)}`) === 0) {
if (url.startsWith(`data:image/${validImages[i].slice(1)}`)) {
isValidBase64Suffix = true;

@@ -933,3 +989,7 @@ break;

if (globalThis.createImageBitmap) {
src = this.config.preferWorkers ? await WorkerManager.loadImageBitmap(url) : await loadImageBitmap(url);
if (this.config.preferWorkers && await WorkerManager.isImageBitmapSupported()) {
src = await WorkerManager.loadImageBitmap(url);
} else {
src = await loadImageBitmap(url);
}
} else {

@@ -936,0 +996,0 @@ src = await new Promise((resolve) => {

"use strict";/*!
* @pixi/assets - v7.0.0-beta.3
* Compiled Thu, 13 Oct 2022 15:35:43 UTC
* @pixi/assets - v7.0.0-beta.4
* Compiled Thu, 20 Oct 2022 19:45:44 UTC
*
* @pixi/assets is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/Object.defineProperty(exports,"__esModule",{value:!0});var o=require("@pixi/core");class U{constructor(e,t=!1){this._loader=e,this._assetList=[],this._isLoading=!1,this._maxConcurrent=1,this.verbose=t}add(e){e.forEach(t=>{this._assetList.push(t)}),this.verbose&&console.log("[BackgroundLoader] assets: ",this._assetList),this._isActive&&!this._isLoading&&this._next()}async _next(){if(this._assetList.length&&this._isActive){this._isLoading=!0;const e=[],t=Math.min(this._assetList.length,this._maxConcurrent);for(let s=0;s<t;s++)e.push(this._assetList.pop());await this._loader.load(e),this._isLoading=!1,this._next()}}get active(){return this._isActive}set active(e){this._isActive!==e&&(this._isActive=e,e&&!this._isLoading&&this._next())}}const A=(a,e)=>(Array.isArray(a)||(a=[a]),e?a.map(t=>typeof t=="string"?e(t):t):a);function P(a,e,t,s,r){const i=e[t];for(let c=0;c<i.length;c++){const n=i[c];t<e.length-1?P(a.replace(s[t],n),e,t+1,s,r):r.push(a.replace(s[t],n))}}function E(a){const e=/\{(.*?)\}/g,t=a.match(e),s=[];if(t){const r=[];t.forEach(i=>{const c=i.substring(1,i.length-1).split(",");r.push(c)}),P(a,r,0,t,s)}else s.push(a);return s}const g=a=>!Array.isArray(a);class S{constructor(){this._parsers=[],this._cache=new Map,this._cacheMap=new Map}reset(){this._cacheMap.clear(),this._cache.clear()}has(e){return this._cache.has(e)}get(e){return this._cache.get(e)}set(e,t){const s=A(e);let r;for(let n=0;n<this.parsers.length;n++){const l=this.parsers[n];if(l.test(t)){r=l.getCacheableAssets(s,t);break}}r||(r={},s.forEach(n=>{r[n]=t}));const i=Object.keys(r),c={cacheKeys:i,keys:s};if(s.forEach(n=>{this._cacheMap.set(n,c)}),i.forEach(n=>{this._cache.has(n)&&this._cache.get(n),this._cache.set(n,r[n])}),t instanceof o.Texture){const n=t;s.forEach(l=>{n.baseTexture!==o.Texture.EMPTY.baseTexture&&o.BaseTexture.addToCache(n.baseTexture,l),o.Texture.addToCache(n,l)})}}remove(e){if(this._cacheMap.get(e),!this._cacheMap.has(e))return;const t=this._cacheMap.get(e);t.cacheKeys.forEach(s=>{this._cache.delete(s)}),t.keys.forEach(s=>{this._cacheMap.delete(s)})}get parsers(){return this._parsers}}const f=new S;class Q{constructor(){this._parsers=[],this.promiseCache={}}reset(){this.promiseCache={}}_getLoadPromiseAndParser(e,t){const s={promise:null,parser:null};return s.promise=(async()=>{let r=null;for(let i=0;i<this.parsers.length;i++){const c=this.parsers[i];if(c.load&&c.test?.(e,t,this)){r=await c.load(e,t,this),s.parser=c;break}}if(!s.parser)return null;for(let i=0;i<this.parsers.length;i++){const c=this.parsers[i];c.parse&&c.parse&&await c.testParse?.(r,t,this)&&(r=await c.parse(r,t,this)||r,s.parser=c)}return r})(),s}async load(e,t){let s=0;const r={},i=g(e),c=A(e,h=>({src:h})),n=c.length,l=c.map(async h=>{const d=o.utils.path.toAbsolute(h.src);if(!r[h.src])try{this.promiseCache[d]||(this.promiseCache[d]=this._getLoadPromiseAndParser(d,h)),r[h.src]=await this.promiseCache[d].promise,t&&t(++s/n)}catch(u){throw delete this.promiseCache[d],delete r[h.src],new Error(`[Loader.load] Failed to load ${d}.
${u}`)}});return await Promise.all(l),i?r[c[0].src]:r}async unload(e){const t=A(e,s=>({src:s})).map(async s=>{const r=o.utils.path.toAbsolute(s.src),i=this.promiseCache[r];if(i){const c=await i.promise;i.parser?.unload?.(c,s,this),delete this.promiseCache[r]}});await Promise.all(t)}get parsers(){return this._parsers}}class V{constructor(){this._assetMap={},this._preferredOrder=[],this._parsers=[],this._resolverHash={},this._bundles={}}prefer(...e){e.forEach(t=>{this._preferredOrder.push(t),t.priority||(t.priority=Object.keys(t.params))}),this._resolverHash={}}set basePath(e){this._basePath=e}get basePath(){return this._basePath}set rootPath(e){this._rootPath=e}get rootPath(){return this._rootPath}get parsers(){return this._parsers}reset(){this._preferredOrder=[],this._resolverHash={},this._assetMap={},this._rootPath=null,this._basePath=null,this._manifest=null}addManifest(e){this._manifest,this._manifest=e,e.bundles.forEach(t=>{this.addBundle(t.name,t.assets)})}addBundle(e,t){const s=[];Array.isArray(t)?t.forEach(r=>{typeof r.name=="string"?s.push(r.name):s.push(...r.name),this.add(r.name,r.srcs)}):Object.keys(t).forEach(r=>{s.push(r),this.add(r,t[r])}),this._bundles[e]=s}add(e,t,s){const r=A(e);r.forEach(c=>{this._assetMap[c]}),Array.isArray(t)||(typeof t=="string"?t=E(t):t=[t]);const i=t.map(c=>{let n=c;if(typeof c=="string"){let l=!1;for(let h=0;h<this._parsers.length;h++){const d=this._parsers[h];if(d.test(c)){n=d.parse(c),l=!0;break}}l||(n={src:c})}return n.format||(n.format=n.src.split(".").pop()),n.alias||(n.alias=r),(this._basePath||this._rootPath)&&(n.src=o.utils.path.toAbsolute(n.src,this._basePath,this._rootPath)),n.data=n.data??s,n});r.forEach(c=>{this._assetMap[c]=i})}resolveBundle(e){const t=g(e);e=A(e);const s={};return e.forEach(r=>{const i=this._bundles[r];i&&(s[r]=this.resolve(i))}),t?s[e[0]]:s}resolveUrl(e){const t=this.resolve(e);if(typeof e!="string"){const s={};for(const r in t)s[r]=t[r].src;return s}return t.src}resolve(e){const t=g(e);e=A(e);const s={};return e.forEach(r=>{if(!this._resolverHash[r])if(this._assetMap[r]){let i=this._assetMap[r];const c=this._getPreferredOrder(i),n=i[0];c?.priority.forEach(l=>{c.params[l].forEach(h=>{const d=i.filter(u=>u[l]?u[l]===h:!1);d.length&&(i=d)})}),this._resolverHash[r]=i[0]??n}else{let i=r;(this._basePath||this._rootPath)&&(i=o.utils.path.toAbsolute(i,this._basePath,this._rootPath)),this._resolverHash[r]={src:i}}s[r]=this._resolverHash[r]}),t?s[e[0]]:s}_getPreferredOrder(e){for(let t=0;t<e.length;t++){const s=e[0],r=this._preferredOrder.find(i=>i.params.format.includes(s.format));if(r)return r}return this._preferredOrder[0]}}class B{constructor(){this._detections=[],this._initialized=!1,this.resolver=new V,this.loader=new Q,this.cache=f,this._backgroundLoader=new U(this.loader),this._backgroundLoader.active=!0,this.reset()}async init(e={}){if(this._initialized)return;if(this._initialized=!0,e.basePath&&(this.resolver.basePath=e.basePath),e.manifest){let i=e.manifest;typeof i=="string"&&(i=await this.load(i)),this.resolver.addManifest(i)}const t=e.texturePreference?.resolution??1,s=typeof t=="number"?[t]:t;let r=[];if(e.texturePreference?.format){const i=e.texturePreference?.format;r=typeof i=="string"?[i]:i;for(const c of this._detections)await c.test()||(r=await c.remove(r))}else for(const i of this._detections)await i.test()&&(r=await i.add(r));this.resolver.prefer({params:{format:r,resolution:s}})}add(e,t,s){this.resolver.add(e,t,s)}async load(e,t){this._initialized||await this.init();const s=g(e),r=A(e).map(n=>typeof n!="string"?(this.resolver.add(n.src,n),n.src):n),i=this.resolver.resolve(r),c=await this._mapLoadToResolve(i,t);return s?c[r[0]]:c}addBundle(e,t){this.resolver.addBundle(e,t)}async loadBundle(e,t){this._initialized||await this.init();let s=!1;typeof e=="string"&&(s=!0,e=[e]);const r=this.resolver.resolveBundle(e),i={},c=Object.keys(r);let n=0,l=0;const h=()=>{t?.(++n/l)},d=c.map(u=>{const w=r[u];return l+=Object.keys(w).length,this._mapLoadToResolve(w,h).then(z=>{i[u]=z})});return await Promise.all(d),s?i[e[0]]:i}async backgroundLoad(e){this._initialized||await this.init(),typeof e=="string"&&(e=[e]);const t=this.resolver.resolve(e);this._backgroundLoader.add(Object.values(t))}async backgroundLoadBundle(e){this._initialized||await this.init(),typeof e=="string"&&(e=[e]);const t=this.resolver.resolveBundle(e);Object.values(t).forEach(s=>{this._backgroundLoader.add(Object.values(s))})}reset(){this.resolver.reset(),this.loader.reset(),this.cache.reset(),this._initialized=!1}get(e){if(typeof e=="string")return f.get(e);const t={};for(let s=0;s<e.length;s++)t[s]=f.get(e[s]);return t}async _mapLoadToResolve(e,t){const s=Object.values(e),r=Object.keys(e);this._backgroundLoader.active=!1;const i=await this.loader.load(s,t);this._backgroundLoader.active=!0;const c={};return s.forEach((n,l)=>{const h=i[n.src],d=[n.src];n.alias&&d.push(...n.alias),c[r[l]]=h,f.set(d,h)}),c}async unload(e){this._initialized||await this.init();const t=A(e).map(r=>typeof r!="string"?r.src:r),s=this.resolver.resolve(t);await this._unloadFromResolved(s)}async unloadBundle(e){this._initialized||await this.init(),e=A(e);const t=this.resolver.resolveBundle(e),s=Object.keys(t).map(r=>this._unloadFromResolved(t[r]));await Promise.all(s)}async _unloadFromResolved(e){const t=Object.values(e);t.forEach(s=>{f.remove(s.src)}),await this.loader.unload(t)}get detections(){return this._detections}}const m=new B;o.extensions.handleByList(o.ExtensionType.LoadParser,m.loader.parsers).handleByList(o.ExtensionType.ResolveParser,m.resolver.parsers).handleByList(o.ExtensionType.CacheParser,m.cache.parsers).handleByList(o.ExtensionType.DetectionParser,m.detections);const T={loader:o.ExtensionType.LoadParser,resolver:o.ExtensionType.ResolveParser,cache:o.ExtensionType.CacheParser,detection:o.ExtensionType.DetectionParser};o.extensions.handle(o.ExtensionType.Asset,a=>{const e=a.ref;Object.entries(T).filter(([t])=>!!e[t]).forEach(([t,s])=>o.extensions.add(Object.assign(e[t],{extension:e[t].extension??s})))},a=>{const e=a.ref;Object.keys(T).filter(t=>!!e[t]).forEach(t=>o.extensions.remove(e[t]))});const L={extension:o.ExtensionType.CacheParser,test:a=>Array.isArray(a)&&a.every(e=>e instanceof o.Texture),getCacheableAssets:(a,e)=>{const t={};return a.forEach(s=>{e.forEach((r,i)=>{t[s+(i===0?"":i+1)]=r})}),t}};o.extensions.add(L);var p=(a=>(a[a.Low=0]="Low",a[a.Normal=1]="Normal",a[a.High=2]="High",a))(p||{});const k={extension:{type:o.ExtensionType.LoadParser,priority:p.Low},test(a){return o.utils.path.extname(a).includes(".json")},async load(a){return await(await o.settings.ADAPTER.fetch(a)).json()}};o.extensions.add(k);const C={extension:{type:o.ExtensionType.LoadParser,priority:p.Low},test(a){return o.utils.path.extname(a).includes(".txt")},async load(a){return await(await o.settings.ADAPTER.fetch(a)).text()}};o.extensions.add(C);const N=["normal","bold","100","200","300","400","500","600","700","800","900"],Y=["woff","woff2","ttf","otf"];function O(a){const e=o.utils.path.extname(a);return o.utils.path.basename(a,e).replace(/(-|_)/g," ").toLowerCase().split(" ").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}const j={extension:{type:o.ExtensionType.LoadParser,priority:p.Low},test(a){const e=a.split("?")[0].split(".").pop();return Y.includes(e)},async load(a,e){if(!globalThis.navigator.onLine)throw new Error("[loadWebFont] Cannot load font - navigator is offline");const t=o.settings.ADAPTER.getFontFaceSet();if(t){const s=[],r=e.data?.family??O(a),i=e.data?.weights?.filter(n=>N.includes(n))??["normal"],c=e.data??{};for(let n=0;n<i.length;n++){const l=i[n],h=new FontFace(r,`url(${a})`,{...c,weight:l});await h.load(),t.add(h),s.push(h)}return s.length===1?s[0]:s}return null},unload(a){(Array.isArray(a)?a:[a]).forEach(e=>o.settings.ADAPTER.getFontFaceSet().delete(e))}};o.extensions.add(j);let R=0,_;const X={id:"loadImageBitmap",code:`
self.onmessage = function(event) {
*/Object.defineProperty(exports,"__esModule",{value:!0});var o=require("@pixi/core");class ${constructor(e,t=!1){this._loader=e,this._assetList=[],this._isLoading=!1,this._maxConcurrent=1,this.verbose=t}add(e){e.forEach(t=>{this._assetList.push(t)}),this.verbose&&console.log("[BackgroundLoader] assets: ",this._assetList),this._isActive&&!this._isLoading&&this._next()}async _next(){if(this._assetList.length&&this._isActive){this._isLoading=!0;const e=[],t=Math.min(this._assetList.length,this._maxConcurrent);for(let s=0;s<t;s++)e.push(this._assetList.pop());await this._loader.load(e),this._isLoading=!1,this._next()}}get active(){return this._isActive}set active(e){this._isActive!==e&&(this._isActive=e,e&&!this._isLoading&&this._next())}}const p=(a,e)=>(Array.isArray(a)||(a=[a]),e?a.map(t=>typeof t=="string"?e(t):t):a);function B(a,e,t,s,r){const i=e[t];for(let c=0;c<i.length;c++){const n=i[c];t<e.length-1?B(a.replace(s[t],n),e,t+1,s,r):r.push(a.replace(s[t],n))}}function E(a){const e=/\{(.*?)\}/g,t=a.match(e),s=[];if(t){const r=[];t.forEach(i=>{const c=i.substring(1,i.length-1).split(",");r.push(c)}),B(a,r,0,t,s)}else s.push(a);return s}const m=a=>!Array.isArray(a);class z{constructor(){this._parsers=[],this._cache=new Map,this._cacheMap=new Map}reset(){this._cacheMap.clear(),this._cache.clear()}has(e){return this._cache.has(e)}get(e){return this._cache.get(e)}set(e,t){const s=p(e);let r;for(let n=0;n<this.parsers.length;n++){const l=this.parsers[n];if(l.test(t)){r=l.getCacheableAssets(s,t);break}}r||(r={},s.forEach(n=>{r[n]=t}));const i=Object.keys(r),c={cacheKeys:i,keys:s};if(s.forEach(n=>{this._cacheMap.set(n,c)}),i.forEach(n=>{this._cache.has(n)&&this._cache.get(n),this._cache.set(n,r[n])}),t instanceof o.Texture){const n=t;s.forEach(l=>{n.baseTexture!==o.Texture.EMPTY.baseTexture&&o.BaseTexture.addToCache(n.baseTexture,l),o.Texture.addToCache(n,l)})}}remove(e){if(this._cacheMap.get(e),!this._cacheMap.has(e))return;const t=this._cacheMap.get(e);t.cacheKeys.forEach(s=>{this._cache.delete(s)}),t.keys.forEach(s=>{this._cacheMap.delete(s)})}get parsers(){return this._parsers}}const g=new z;class V{constructor(){this._parsers=[],this.promiseCache={}}reset(){this.promiseCache={}}_getLoadPromiseAndParser(e,t){const s={promise:null,parser:null};return s.promise=(async()=>{let r=null;for(let i=0;i<this.parsers.length;i++){const c=this.parsers[i];if(c.load&&c.test?.(e,t,this)){r=await c.load(e,t,this),s.parser=c;break}}if(!s.parser)return null;for(let i=0;i<this.parsers.length;i++){const c=this.parsers[i];c.parse&&c.parse&&await c.testParse?.(r,t,this)&&(r=await c.parse(r,t,this)||r,s.parser=c)}return r})(),s}async load(e,t){let s=0;const r={},i=m(e),c=p(e,h=>({src:h})),n=c.length,l=c.map(async h=>{const d=o.utils.path.toAbsolute(h.src);if(!r[h.src])try{this.promiseCache[d]||(this.promiseCache[d]=this._getLoadPromiseAndParser(d,h)),r[h.src]=await this.promiseCache[d].promise,t&&t(++s/n)}catch(A){throw delete this.promiseCache[d],delete r[h.src],new Error(`[Loader.load] Failed to load ${d}.
${A}`)}});return await Promise.all(l),i?r[c[0].src]:r}async unload(e){const t=p(e,s=>({src:s})).map(async s=>{const r=o.utils.path.toAbsolute(s.src),i=this.promiseCache[r];if(i){const c=await i.promise;i.parser?.unload?.(c,s,this),delete this.promiseCache[r]}});await Promise.all(t)}get parsers(){return this._parsers}}class Q{constructor(){this._assetMap={},this._preferredOrder=[],this._parsers=[],this._resolverHash={},this._bundles={}}prefer(...e){e.forEach(t=>{this._preferredOrder.push(t),t.priority||(t.priority=Object.keys(t.params))}),this._resolverHash={}}set basePath(e){this._basePath=e}get basePath(){return this._basePath}set rootPath(e){this._rootPath=e}get rootPath(){return this._rootPath}get parsers(){return this._parsers}reset(){this._preferredOrder=[],this._resolverHash={},this._assetMap={},this._rootPath=null,this._basePath=null,this._manifest=null}addManifest(e){this._manifest,this._manifest=e,e.bundles.forEach(t=>{this.addBundle(t.name,t.assets)})}addBundle(e,t){const s=[];Array.isArray(t)?t.forEach(r=>{typeof r.name=="string"?s.push(r.name):s.push(...r.name),this.add(r.name,r.srcs)}):Object.keys(t).forEach(r=>{s.push(r),this.add(r,t[r])}),this._bundles[e]=s}add(e,t,s){const r=p(e);r.forEach(c=>{this._assetMap[c]}),Array.isArray(t)||(typeof t=="string"?t=E(t):t=[t]);const i=t.map(c=>{let n=c;if(typeof c=="string"){let l=!1;for(let h=0;h<this._parsers.length;h++){const d=this._parsers[h];if(d.test(c)){n=d.parse(c),l=!0;break}}l||(n={src:c})}return n.format||(n.format=n.src.split(".").pop()),n.alias||(n.alias=r),(this._basePath||this._rootPath)&&(n.src=o.utils.path.toAbsolute(n.src,this._basePath,this._rootPath)),n.data=n.data??s,n});r.forEach(c=>{this._assetMap[c]=i})}resolveBundle(e){const t=m(e);e=p(e);const s={};return e.forEach(r=>{const i=this._bundles[r];i&&(s[r]=this.resolve(i))}),t?s[e[0]]:s}resolveUrl(e){const t=this.resolve(e);if(typeof e!="string"){const s={};for(const r in t)s[r]=t[r].src;return s}return t.src}resolve(e){const t=m(e);e=p(e);const s={};return e.forEach(r=>{if(!this._resolverHash[r])if(this._assetMap[r]){let i=this._assetMap[r];const c=this._getPreferredOrder(i),n=i[0];c?.priority.forEach(l=>{c.params[l].forEach(h=>{const d=i.filter(A=>A[l]?A[l]===h:!1);d.length&&(i=d)})}),this._resolverHash[r]=i[0]??n}else{let i=r;(this._basePath||this._rootPath)&&(i=o.utils.path.toAbsolute(i,this._basePath,this._rootPath)),this._resolverHash[r]={src:i}}s[r]=this._resolverHash[r]}),t?s[e[0]]:s}_getPreferredOrder(e){for(let t=0;t<e.length;t++){const s=e[0],r=this._preferredOrder.find(i=>i.params.format.includes(s.format));if(r)return r}return this._preferredOrder[0]}}class P{constructor(){this._detections=[],this._initialized=!1,this.resolver=new Q,this.loader=new V,this.cache=g,this._backgroundLoader=new $(this.loader),this._backgroundLoader.active=!0,this.reset()}async init(e={}){if(this._initialized)return;if(this._initialized=!0,e.basePath&&(this.resolver.basePath=e.basePath),e.manifest){let i=e.manifest;typeof i=="string"&&(i=await this.load(i)),this.resolver.addManifest(i)}const t=e.texturePreference?.resolution??1,s=typeof t=="number"?[t]:t;let r=[];if(e.texturePreference?.format){const i=e.texturePreference?.format;r=typeof i=="string"?[i]:i;for(const c of this._detections)await c.test()||(r=await c.remove(r))}else for(const i of this._detections)await i.test()&&(r=await i.add(r));this.resolver.prefer({params:{format:r,resolution:s}})}add(e,t,s){this.resolver.add(e,t,s)}async load(e,t){this._initialized||await this.init();const s=m(e),r=p(e).map(n=>typeof n!="string"?(this.resolver.add(n.src,n),n.src):n),i=this.resolver.resolve(r),c=await this._mapLoadToResolve(i,t);return s?c[r[0]]:c}addBundle(e,t){this.resolver.addBundle(e,t)}async loadBundle(e,t){this._initialized||await this.init();let s=!1;typeof e=="string"&&(s=!0,e=[e]);const r=this.resolver.resolveBundle(e),i={},c=Object.keys(r);let n=0,l=0;const h=()=>{t?.(++n/l)},d=c.map(A=>{const x=r[A];return l+=Object.keys(x).length,this._mapLoadToResolve(x,h).then(G=>{i[A]=G})});return await Promise.all(d),s?i[e[0]]:i}async backgroundLoad(e){this._initialized||await this.init(),typeof e=="string"&&(e=[e]);const t=this.resolver.resolve(e);this._backgroundLoader.add(Object.values(t))}async backgroundLoadBundle(e){this._initialized||await this.init(),typeof e=="string"&&(e=[e]);const t=this.resolver.resolveBundle(e);Object.values(t).forEach(s=>{this._backgroundLoader.add(Object.values(s))})}reset(){this.resolver.reset(),this.loader.reset(),this.cache.reset(),this._initialized=!1}get(e){if(typeof e=="string")return g.get(e);const t={};for(let s=0;s<e.length;s++)t[s]=g.get(e[s]);return t}async _mapLoadToResolve(e,t){const s=Object.values(e),r=Object.keys(e);this._backgroundLoader.active=!1;const i=await this.loader.load(s,t);this._backgroundLoader.active=!0;const c={};return s.forEach((n,l)=>{const h=i[n.src],d=[n.src];n.alias&&d.push(...n.alias),c[r[l]]=h,g.set(d,h)}),c}async unload(e){this._initialized||await this.init();const t=p(e).map(r=>typeof r!="string"?r.src:r),s=this.resolver.resolve(t);await this._unloadFromResolved(s)}async unloadBundle(e){this._initialized||await this.init(),e=p(e);const t=this.resolver.resolveBundle(e),s=Object.keys(t).map(r=>this._unloadFromResolved(t[r]));await Promise.all(s)}async _unloadFromResolved(e){const t=Object.values(e);t.forEach(s=>{g.remove(s.src)}),await this.loader.unload(t)}get detections(){return this._detections}}const f=new P;o.extensions.handleByList(o.ExtensionType.LoadParser,f.loader.parsers).handleByList(o.ExtensionType.ResolveParser,f.resolver.parsers).handleByList(o.ExtensionType.CacheParser,f.cache.parsers).handleByList(o.ExtensionType.DetectionParser,f.detections);const T={loader:o.ExtensionType.LoadParser,resolver:o.ExtensionType.ResolveParser,cache:o.ExtensionType.CacheParser,detection:o.ExtensionType.DetectionParser};o.extensions.handle(o.ExtensionType.Asset,a=>{const e=a.ref;Object.entries(T).filter(([t])=>!!e[t]).forEach(([t,s])=>o.extensions.add(Object.assign(e[t],{extension:e[t].extension??s})))},a=>{const e=a.ref;Object.keys(T).filter(t=>!!e[t]).forEach(t=>o.extensions.remove(e[t]))});const L={extension:o.ExtensionType.CacheParser,test:a=>Array.isArray(a)&&a.every(e=>e instanceof o.Texture),getCacheableAssets:(a,e)=>{const t={};return a.forEach(s=>{e.forEach((r,i)=>{t[s+(i===0?"":i+1)]=r})}),t}};o.extensions.add(L);var u=(a=>(a[a.Low=0]="Low",a[a.Normal=1]="Normal",a[a.High=2]="High",a))(u||{});const k={extension:{type:o.ExtensionType.LoadParser,priority:u.Low},test(a){return o.utils.path.extname(a).includes(".json")},async load(a){return await(await o.settings.ADAPTER.fetch(a)).json()}};o.extensions.add(k);const I={extension:{type:o.ExtensionType.LoadParser,priority:u.Low},test(a){return o.utils.path.extname(a).includes(".txt")},async load(a){return await(await o.settings.ADAPTER.fetch(a)).text()}};o.extensions.add(I);const N=["normal","bold","100","200","300","400","500","600","700","800","900"],Y=["woff","woff2","ttf","otf"];function C(a){const e=o.utils.path.extname(a);return o.utils.path.basename(a,e).replace(/(-|_)/g," ").toLowerCase().split(" ").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}const j={extension:{type:o.ExtensionType.LoadParser,priority:u.Low},test(a){const e=a.split("?")[0].split(".").pop();return Y.includes(e)},async load(a,e){if(!globalThis.navigator.onLine)throw new Error("[loadWebFont] Cannot load font - navigator is offline");const t=o.settings.ADAPTER.getFontFaceSet();if(t){const s=[],r=e.data?.family??C(a),i=e.data?.weights?.filter(n=>N.includes(n))??["normal"],c=e.data??{};for(let n=0;n<i.length;n++){const l=i[n],h=new FontFace(r,`url(${a})`,{...c,weight:l});await h.load(),t.add(h),s.push(h)}return s.length===1?s[0]:s}return null},unload(a){(Array.isArray(a)?a:[a]).forEach(e=>o.settings.ADAPTER.getFontFaceSet().delete(e))}};o.extensions.add(j);let R=0,_;const K="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+ip1sAAAAASUVORK5CYII=",X={id:"checkImageBitmap",code:`
async function checkImageBitmap()
{
try
{
if (typeof createImageBitmap !== 'function') return false;
async function loadImageBitmap(url)
{
const response = await fetch(url);
const response = await fetch('${K}');
const imageBlob = await response.blob();
const imageBitmap = await createImageBitmap(imageBlob);
return imageBitmap;
return imageBitmap.width === 1 && imageBitmap.height === 1;
}
catch (e)
{
return false;
}
}
checkImageBitmap().then((result) => { self.postMessage(result); });
`},Z={id:"loadImageBitmap",code:`
async function loadImageBitmap(url)
{
const response = await fetch(url);
loadImageBitmap(event.data.data[0]).then(imageBitmap => {
if (!response.ok)
{
throw new Error(\`[WorkerManager.loadImageBitmap] Failed to fetch \${url}: \`
+ \`\${response.status} \${response.statusText}\`);
}
const imageBlob = await response.blob();
const imageBitmap = await createImageBitmap(imageBlob);
return imageBitmap;
}
self.onmessage = async (event) =>
{
try
{
const imageBitmap = await loadImageBitmap(event.data.data[0]);
self.postMessage({

@@ -25,10 +54,12 @@ data: imageBitmap,

}, [imageBitmap]);
}).catch(error => {
}
catch(e)
{
self.postMessage({
data: null,
error: e,
uuid: event.data.uuid,
id: event.data.id,
});
});
}`};let v;class Z{constructor(){this._initialized=!1,this._createdWorkers=0,this.workerPool=[],this.queue=[],this.resolveHash={}}loadImageBitmap(e){return this._run("loadImageBitmap",[e])}async _initWorkers(){this._initialized||(this._initialized=!0)}getWorker(){_===void 0&&(_=navigator.hardwareConcurrency||4);let e=this.workerPool.pop();return!e&&this._createdWorkers<_&&(v||(v=URL.createObjectURL(new Blob([X.code],{type:"application/javascript"}))),this._createdWorkers++,e=new Worker(v),e.addEventListener("message",t=>{this.complete(t.data),this.returnWorker(t.target),this.next()})),e}returnWorker(e){this.workerPool.push(e)}complete(e){const t=e.data;this.resolveHash[e.uuid](t),this.resolveHash[e.uuid]=null}_run(e,t){this._initWorkers();const s=new Promise(r=>{this.queue.push({id:e,arguments:t,resolve:r})});return this.next(),s}next(){if(!this.queue.length)return;const e=this.getWorker();if(!e)return;const t=this.queue.pop(),s=t.id;this.resolveHash[R]=t.resolve,e.postMessage({data:t.arguments,uuid:R++,id:s})}}const $=new Z;function I(a,e){const t=a.split("?")[0],s=o.utils.path.extname(t).toLowerCase();return Array.isArray(e)?e.includes(s.toLowerCase()):s.toLowerCase()===e}function x(a,e,t){const s=new o.Texture(a);return s.baseTexture.on("dispose",()=>{delete e.promiseCache[t]}),s}const b=[".jpg",".png",".jpeg",".avif",".webp"];async function M(a){const e=await(await o.settings.ADAPTER.fetch(a)).blob();return await createImageBitmap(e)}const y={extension:{type:o.ExtensionType.LoadParser,priority:p.High},config:{preferWorkers:!0},test(a){let e=!1;for(let t=0;t<b.length;t++)if(a.indexOf(`data:image/${b[t].slice(1)}`)===0){e=!0;break}return e||I(a,b)},async load(a,e,t){let s=null;globalThis.createImageBitmap?s=this.config.preferWorkers?await $.loadImageBitmap(a):await M(a):s=await new Promise(i=>{s=new Image,s.crossOrigin="anonymous",s.src=a,s.complete?i(s):s.onload=()=>{i(s)}});const r=new o.BaseTexture(s,{resolution:o.utils.getResolutionOfUrl(a),...e.data});return r.resource.src=a,x(r,t,a)},unload(a){a.destroy(!0)}};o.extensions.add(y);const q={extension:{type:o.ExtensionType.LoadParser,priority:p.High},test(a){return o.utils.path.extname(a).includes(".svg")},async testParse(a){return o.SVGResource.test(a)},async parse(a,e,t){const s=new o.SVGResource(a,e?.data?.resourceOptions),r=new o.BaseTexture(s,{resolution:o.utils.getResolutionOfUrl(a),...e?.data});r.resource.src=a;const i=x(r,t,a);return e?.data?.resourceOptions?.autoLoad||await s.load(),i},async load(a,e){return(await o.settings.ADAPTER.fetch(a)).text()},unload:y.unload},W={extension:o.ExtensionType.ResolveParser,test:y.test,parse:a=>({resolution:parseFloat(o.settings.RETINA_PREFIX.exec(a)?.[1]??"1"),format:a.split(".").pop(),src:a})};o.extensions.add(W);const F={extension:{type:o.ExtensionType.DetectionParser,priority:1},test:async()=>{if(!globalThis.createImageBitmap)return!1;const a="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=",e=await o.settings.ADAPTER.fetch(a).then(t=>t.blob());return createImageBitmap(e).then(()=>!0,()=>!1)},add:async a=>[...a,"avif"],remove:async a=>a.filter(e=>e!=="avif")};o.extensions.add(F);const D={extension:{type:o.ExtensionType.DetectionParser,priority:0},test:async()=>{if(!globalThis.createImageBitmap)return!1;const a="data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=",e=await o.settings.ADAPTER.fetch(a).then(t=>t.blob());return createImageBitmap(e).then(()=>!0,()=>!1)},add:async a=>[...a,"webp"],remove:async a=>a.filter(e=>e!=="webp")};o.extensions.add(D);const H=["png","jpg","jpeg"],G={extension:{type:o.ExtensionType.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async a=>[...a,...H],remove:async a=>a.filter(e=>!H.includes(e))};o.extensions.add(G),exports.Assets=m,exports.AssetsClass=B,exports.Cache=f,exports.LoaderParserPriority=p,exports.cacheTextureArray=L,exports.checkExtension=I,exports.convertToList=A,exports.createStringVariations=E,exports.createTexture=x,exports.detectAvif=F,exports.detectDefaults=G,exports.detectWebp=D,exports.getFontFamilyName=O,exports.isSingleItem=g,exports.loadImageBitmap=M,exports.loadJson=k,exports.loadSVG=q,exports.loadTextures=y,exports.loadTxt=C,exports.loadWebFont=j,exports.resolveTextureUrl=W;
}
};`};let v;class q{constructor(){this._initialized=!1,this._createdWorkers=0,this.workerPool=[],this.queue=[],this.resolveHash={}}isImageBitmapSupported(){return this._isImageBitmapSupported!==void 0?this._isImageBitmapSupported:(this._isImageBitmapSupported=new Promise(e=>{const t=URL.createObjectURL(new Blob([X.code],{type:"application/javascript"})),s=new Worker(t);s.addEventListener("message",r=>{s.terminate(),URL.revokeObjectURL(t),e(r.data)})}),this._isImageBitmapSupported)}loadImageBitmap(e){return this._run("loadImageBitmap",[e])}async _initWorkers(){this._initialized||(this._initialized=!0)}getWorker(){_===void 0&&(_=navigator.hardwareConcurrency||4);let e=this.workerPool.pop();return!e&&this._createdWorkers<_&&(v||(v=URL.createObjectURL(new Blob([Z.code],{type:"application/javascript"}))),this._createdWorkers++,e=new Worker(v),e.addEventListener("message",t=>{this.complete(t.data),this.returnWorker(t.target),this.next()})),e}returnWorker(e){this.workerPool.push(e)}complete(e){e.error!==void 0?this.resolveHash[e.uuid].reject(e.error):this.resolveHash[e.uuid].resolve(e.data),this.resolveHash[e.uuid]=null}async _run(e,t){await this._initWorkers();const s=new Promise((r,i)=>{this.queue.push({id:e,arguments:t,resolve:r,reject:i})});return this.next(),s}next(){if(!this.queue.length)return;const e=this.getWorker();if(!e)return;const t=this.queue.pop(),s=t.id;this.resolveHash[R]={resolve:t.resolve,reject:t.reject},e.postMessage({data:t.arguments,uuid:R++,id:s})}}const O=new q;function M(a,e){const t=a.split("?")[0],s=o.utils.path.extname(t).toLowerCase();return Array.isArray(e)?e.includes(s.toLowerCase()):s.toLowerCase()===e}function w(a,e,t){const s=new o.Texture(a);return s.baseTexture.on("dispose",()=>{delete e.promiseCache[t]}),s}const b=[".jpg",".png",".jpeg",".avif",".webp"];async function W(a){const e=await o.settings.ADAPTER.fetch(a);if(!e.ok)throw new Error(`[loadImageBitmap] Failed to fetch ${a}: ${e.status} ${e.statusText}`);const t=await e.blob();return await createImageBitmap(t)}const y={extension:{type:o.ExtensionType.LoadParser,priority:u.High},config:{preferWorkers:!0},test(a){let e=!1;for(let t=0;t<b.length;t++)if(a.startsWith(`data:image/${b[t].slice(1)}`)){e=!0;break}return e||M(a,b)},async load(a,e,t){let s=null;globalThis.createImageBitmap?this.config.preferWorkers&&await O.isImageBitmapSupported()?s=await O.loadImageBitmap(a):s=await W(a):s=await new Promise(i=>{s=new Image,s.crossOrigin="anonymous",s.src=a,s.complete?i(s):s.onload=()=>{i(s)}});const r=new o.BaseTexture(s,{resolution:o.utils.getResolutionOfUrl(a),...e.data});return r.resource.src=a,w(r,t,a)},unload(a){a.destroy(!0)}};o.extensions.add(y);const J={extension:{type:o.ExtensionType.LoadParser,priority:u.High},test(a){return o.utils.path.extname(a).includes(".svg")},async testParse(a){return o.SVGResource.test(a)},async parse(a,e,t){const s=new o.SVGResource(a,e?.data?.resourceOptions),r=new o.BaseTexture(s,{resolution:o.utils.getResolutionOfUrl(a),...e?.data});r.resource.src=a;const i=w(r,t,a);return e?.data?.resourceOptions?.autoLoad||await s.load(),i},async load(a,e){return(await o.settings.ADAPTER.fetch(a)).text()},unload:y.unload},F={extension:o.ExtensionType.ResolveParser,test:y.test,parse:a=>({resolution:parseFloat(o.settings.RETINA_PREFIX.exec(a)?.[1]??"1"),format:a.split(".").pop(),src:a})};o.extensions.add(F);const D={extension:{type:o.ExtensionType.DetectionParser,priority:1},test:async()=>{if(!globalThis.createImageBitmap)return!1;const a="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=",e=await o.settings.ADAPTER.fetch(a).then(t=>t.blob());return createImageBitmap(e).then(()=>!0,()=>!1)},add:async a=>[...a,"avif"],remove:async a=>a.filter(e=>e!=="avif")};o.extensions.add(D);const H={extension:{type:o.ExtensionType.DetectionParser,priority:0},test:async()=>{if(!globalThis.createImageBitmap)return!1;const a="data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=",e=await o.settings.ADAPTER.fetch(a).then(t=>t.blob());return createImageBitmap(e).then(()=>!0,()=>!1)},add:async a=>[...a,"webp"],remove:async a=>a.filter(e=>e!=="webp")};o.extensions.add(H);const S=["png","jpg","jpeg"],U={extension:{type:o.ExtensionType.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async a=>[...a,...S],remove:async a=>a.filter(e=>!S.includes(e))};o.extensions.add(U),exports.Assets=f,exports.AssetsClass=P,exports.Cache=g,exports.LoaderParserPriority=u,exports.cacheTextureArray=L,exports.checkExtension=M,exports.convertToList=p,exports.createStringVariations=E,exports.createTexture=w,exports.detectAvif=D,exports.detectDefaults=U,exports.detectWebp=H,exports.getFontFamilyName=C,exports.isSingleItem=m,exports.loadImageBitmap=W,exports.loadJson=k,exports.loadSVG=J,exports.loadTextures=y,exports.loadTxt=I,exports.loadWebFont=j,exports.resolveTextureUrl=F;
//# sourceMappingURL=assets.min.js.map

@@ -82,15 +82,16 @@ /// <reference types="css-font-loading-module" />

* 3. Caches the assets and provides a way to access them.
* 4: Allow developers to unload assets and clear the cache.
* 4. Allow developers to unload assets and clear the cache.
*
* It also has a few advanced features:
* 1. Allows developers to provide a manifest upfront of all assets and help manage them via 'bundles'
* 1. Allows developers to provide a manifest upfront of all assets and help manage them via 'bundles'.
* 2. Allows users to background load assets. Shortening (or eliminating) load times and improving UX. With this feature,
* in-game loading bars can be a thing of the past!
*
* ### Assets Loading
*
* Do not be afraid to load things multiple times - under the hood, it will NEVER load anything more than once.
*
* for example:
* For example:
*
* ```
* ```js
* import { Assets } from 'pixi.js';

@@ -101,13 +102,14 @@ *

*
* //promise1 === promise2
* // promise1 === promise2
* ```
* here both promises will be the same. Once resolved.. forever resolved! It makes for really easy resource management!
*
* Here both promises will be the same. Once resolved... Forever resolved! It makes for really easy resource management!
*
* Out of the box it supports the following files:
* * textures (avif, webp, png, jpg, gif)
* * sprite sheets (json)
* * bitmap fonts (xml, fnt, txt)
* * web fonts (ttf, woff, woff2)
* * json files (json)
* * text files (txt)
* - textures (avif, webp, png, jpg, gif)
* - sprite sheets (json)
* - bitmap fonts (xml, fnt, txt)
* - web fonts (ttf, woff, woff2)
* - json files (json)
* - text files (txt)
*

@@ -124,4 +126,5 @@ * More types can be added fairly easily by creating additional loader parsers.

* but only 1x is available for that texture, the Asset manager will pick that up as a fallback automatically)
*
* #### Sprite sheets
* - it's hard to know what resolution a sprite sheet is without loading it first, to address this
* - It's hard to know what resolution a sprite sheet is without loading it first, to address this
* there is a naming convention we have added that will let Pixi understand the image format and resolution

@@ -132,3 +135,3 @@ * of the spritesheet via its file name:

*
* for example:
* For example:
*

@@ -138,23 +141,24 @@ * `my-spritesheet@2x.webp.json` // 2x resolution, WebP sprite sheet

*
* This is optional! you can just load a sprite sheet as normal,
* This is only useful if you have a bunch of different res / formatted spritesheets
* This is optional! You can just load a sprite sheet as normal.
* This is only useful if you have a bunch of different res / formatted spritesheets.
*
* ### Fonts
* * Web fonts will be loaded with all weights.
* it is possible to load only specific weights by doing the following:
* Web fonts will be loaded with all weights.
* It is possible to load only specific weights by doing the following:
*
* ```
* ```js
* import { Assets } from 'pixi.js';
*
* // load specific weights..
* // Load specific weights..
* await Assets.load({
* data: {
* weights: ['normal'], // only loads the weight
* },
* src: `outfit.woff2`,
* data: {
* weights: ['normal'], // Only loads the weight
* },
* src: `outfit.woff2`,
* });
*
* // load everything...
* // Load everything...
* await Assets.load(`outfit.woff2`);
* ```
*
* ### Background Loading

@@ -174,42 +178,42 @@ * Background loading will load stuff for you passively behind the scenes. To minimize jank,

*
* ```
* ```js
* import { Assets } from 'pixi.js';
*
* // manifest example
* // Manifest Example
* const manifest = {
* bundles:[{
* name:'load-screen',
* assets:[
* {
* name: 'background',
* srcs: 'sunset.png',
* },
* {
* name: 'bar',
* srcs: 'load-bar.{png,webp}',
* }
* ]
* },
* {
* name:'game-screen',
* assets:[
* {
* name: 'character',
* srcs: 'robot.png',
* },
* {
* name: 'enemy',
* srcs: 'bad-guy.png',
* }
* ]
* }]
* }}
* bundles: [
* {
* name: 'load-screen',
* assets: [
* {
* name: 'background',
* srcs: 'sunset.png',
* },
* {
* name: 'bar',
* srcs: 'load-bar.{png,webp}',
* },
* ],
* },
* {
* name: 'game-screen',
* assets: [
* {
* name: 'character',
* srcs: 'robot.png',
* },
* {
* name: 'enemy',
* srcs: 'bad-guy.png',
* },
* ],
* },
* ]
* };
*
* await Asset.init({
* manifest
* });
* await Asset.init({ manifest });
*
* // load a bundle..
* // Load a bundle...
* loadScreenAssets = await Assets.loadBundle('load-screen');
* // load another..
* // Load another bundle...
* gameScreenAssets = await Assets.loadBundle('game-screen');

@@ -254,7 +258,7 @@ * ```

*
* // simple
* // Simple
* Assets.add('bunnyBooBoo', 'bunny.png');
* const bunny = await Assets.load('bunnyBooBoo');
*
* // multiple keys:
* // Multiple keys:
* Assets.add(['burger', 'chicken'], 'bunny.png');

@@ -269,8 +273,8 @@ *

* 'bunny{png,webp}',
* {scaleMode:SCALE_MODES.NEAREST} // base texture options
* { scaleMode: SCALE_MODES.NEAREST }, // Base texture options
* );
*
* // multiple assets,
* // Multiple assets
*
* // the following all do the same thing:
* // The following all do the same thing:
*

@@ -280,18 +284,18 @@ * Assets.add('bunnyBooBoo', 'bunny{png,webp}');

* Assets.add('bunnyBooBoo', [
* 'bunny.png',
* 'bunny.webp'
* 'bunny.png',
* 'bunny.webp',
* ]);
*
* Assets.add('bunnyBooBoo', [
* {
* format:'png',
* src:'bunny.png',
* },
* {
* format:'webp',
* src:'bunny.webp',
* }
* {
* format: 'png',
* src: 'bunny.png',
* },
* {
* format: 'webp',
* src: 'bunny.webp',
* },
* ]);
*
* const bunny = await Assets.load('bunnyBooBoo'); // will try to load WebP if available
* const bunny = await Assets.load('bunnyBooBoo'); // Will try to load WebP if available
* @param keysIn - the key or keys that you will reference when loading this asset

@@ -313,3 +317,3 @@ * @param assetsIn - the asset or assets that will be chosen from when loading via the specified key

*
* // load a URL:
* // Load a URL:
* const myImageTexture = await Assets.load('http://some.url.com/image.png'); // => returns a texture

@@ -320,3 +324,3 @@ *

*
* // load multiple assets:
* // Load multiple assets:
* const textures = await Assets.load(['thumper', 'chicko']); // => {thumper: Texture, chicko: Texture}

@@ -334,9 +338,11 @@ * @param urls - the urls to load

* @example
* PIXI.Assets.addBundle('animals', {
* bunny: 'bunny.png',
* chicken: 'chicken.png',
* thumper: 'thumper.png',
* });
* import { Assets } from 'pixi.js';
*
* const assets = await PIXI.Assets.loadBundle('animals');
* Assets.addBundle('animals', {
* bunny: 'bunny.png',
* chicken: 'chicken.png',
* thumper: 'thumper.png',
* });
*
* const assets = await Assets.loadBundle('animals');
* @param bundleId - the id of the bundle to add

@@ -351,40 +357,42 @@ * @param assets - a record of the asset or assets that will be chosen from when loading via the specified key

* @example
* // manifest example
* import { Assets } from 'pixi.js';
*
* // Manifest Example
* const manifest = {
* bundles:[{
* name:'load-screen',
* assets:[
* {
* name: 'background',
* srcs: 'sunset.png',
* },
* {
* name: 'bar',
* srcs: 'load-bar.{png,webp}',
* }
* ]
* },
* {
* name:'game-screen',
* assets:[
* {
* name: 'character',
* srcs: 'robot.png',
* },
* {
* name: 'enemy',
* srcs: 'bad-guy.png',
* }
* ]
* }]
* }}
* bundles: [
* {
* name: 'load-screen',
* assets: [
* {
* name: 'background',
* srcs: 'sunset.png',
* },
* {
* name: 'bar',
* srcs: 'load-bar.{png,webp}',
* },
* ],
* },
* {
* name: 'game-screen',
* assets: [
* {
* name: 'character',
* srcs: 'robot.png',
* },
* {
* name: 'enemy',
* srcs: 'bad-guy.png',
* },
* ],
* },
* ]
* };
*
* await Asset.init({
* manifest
* });
* await Asset.init({ manifest });
*
* // load a bundle..
* loadScreenAssets = await PIXI.Assets.loadBundle('load-screen');
* // load another..
* gameScreenAssets = await PIXI.Assets.loadBundle('game-screen');
* // Load a bundle...
* loadScreenAssets = await Assets.loadBundle('load-screen');
* // Load another bundle...
* gameScreenAssets = await Assets.loadBundle('game-screen');
* @param bundleIds - the bundle id or ids to load

@@ -398,3 +406,3 @@ * @param onProgress - optional function that is called when progress on asset loading is made.

/**
* Initiate a background load of some assets. it will passively begin to load these assets in the background.
* Initiate a background load of some assets. It will passively begin to load these assets in the background.
* So when you actually come to loading them you will get a promise that resolves to the loaded assets immediately

@@ -406,6 +414,8 @@ *

* @example
* PIXI.Assets.backgroundLoad('bunny.png');
* import { Assets } from 'pixi.js';
*
* Assets.backgroundLoad('bunny.png');
*
* // later on in your app...
* await PIXI.Assets.loadBundle('bunny.png'); // will resolve quicker as loading may have completed!
* await Assets.loadBundle('bunny.png'); // Will resolve quicker as loading may have completed!
* @param urls - the url / urls you want to background load

@@ -418,17 +428,20 @@ */

* @example
* await PIXI.Assets.init({
* manifest: {
* bundles: [
* {
* name:'load-screen',
* assets:[...]
* }
* ...]
* }
* import { Assets } from 'pixi.js';
*
* await Assets.init({
* manifest: {
* bundles: [
* {
* name: 'load-screen',
* assets: [...],
* },
* ...
* ],
* },
* });
*
* PIXI.Assets.backgroundLoadBundle('load-screen');
* Assets.backgroundLoadBundle('load-screen');
*
* // later on in your app...
* await PIXI.Assets.loadBundle('load-screen'); // will resolve quicker as loading may have completed!
* // Later on in your app...
* await Assets.loadBundle('load-screen'); // Will resolve quicker as loading may have completed!
* @param bundleIds - the bundleId / bundleIds you want to background load

@@ -445,4 +458,4 @@ */

* Instantly gets an asset already loaded from the cache. If the asset has not yet been loaded,
* it will return undefined. So it's on you! When in doubt just use `PIXI.Assets.load` instead.
* (remember, the loader will never load things more than once!)
* it will return undefined. So it's on you! When in doubt just use `Assets.load` instead.
* (Remember, the loader will never load things more than once!)
* @param keys - The key or keys for the assets that you want to access

@@ -465,3 +478,3 @@ * @returns - The assets or hash of assets requested

*
* * it's up to you as the developer to make sure that textures are not actively being used when you unload them,
* - it's up to you as the developer to make sure that textures are not actively being used when you unload them,
* Pixi won't break but you will end up with missing assets. Not a good look for the user!

@@ -471,3 +484,3 @@ * @example

*
* // load a URL:
* // Load a URL:
* const myImageTexture = await Assets.load('http://some.url.com/image.png'); // => returns a texture

@@ -477,5 +490,5 @@ *

*
* myImageTexture <-- will now be destroyed.
* // myImageTexture will be destroyed now.
*
* // unload multiple assets:
* // Unload multiple assets:
* const textures = await Assets.unload(['thumper', 'chicko']);

@@ -491,13 +504,15 @@ * @param urls - the urls to unload

* @example
* PIXI.Assets.addBundle({
* 'thumper': 'http://some.url.com/thumper.png',
* import { Assets } from 'pixi.js';
*
* Assets.addBundle({
* 'thumper': 'http://some.url.com/thumper.png',
* })
*
* const assets = await PIXI.Assets.loadBundle('thumper');
* const assets = await Assets.loadBundle('thumper');
*
* // now to unload..
* // Now to unload...
*
* await await PIXI.Assets.unloadBundle('thumper');
* await Assets.unloadBundle('thumper');
*
* // all assets in the assets object will now have been destroyed and purged from the cache
* // All assets in the assets object will now have been destroyed and purged from the cache
* @param bundleIds - the bundle id or ids to unload

@@ -685,10 +700,10 @@ */

/**
* Loads an asset(s) using the parsers added to the Loader.
* Loads one or more assets using the parsers added to the Loader.
* @example
* // single asset:
* // Single asset:
* const asset = await Loader.load('cool.png');
* console.log(asset);
* @example
* // multiple assets:
* const assets = await Loader.load(['cool.png', 'cooler.png']);
*
* // Multiple assets:
* const assets = await Loader.load(['cool.png', 'cooler.png']);
* console.log(assets);

@@ -702,6 +717,6 @@ * @param assetsToLoadIn - urls that you want to load, or a single one!

/**
* Unloads an asset(s). Any unloaded assets will be destroyed, freeing up memory for your app.
* Unloads one or more assets. Any unloaded assets will be destroyed, freeing up memory for your app.
* The parser that created the asset, will be the one that unloads it.
* @example
* // single asset:
* // Single asset:
* const asset = await Loader.load('cool.png');

@@ -865,3 +880,3 @@ *

*
* ```
* ```js
* resolver.add('foo', 'bar');

@@ -873,13 +888,13 @@ * resolver.resolveUrl('foo') // => 'bar'

*
* ```
* resolver.prefer({
* params:{
* format:'webp',
* resolution: 2,
* }
* })
* ```js
* resolver.prefer({
* params: {
* format: 'webp',
* resolution: 2,
* }
* });
*
* resolver.add('foo', ['bar@2x.webp', 'bar@2x.png', 'bar.webp', 'bar.png']);
* resolver.add('foo', ['bar@2x.webp', 'bar@2x.png', 'bar.webp', 'bar.png']);
*
* resolver.resolveUrl('foo') // => 'bar@2x.webp'
* resolver.resolveUrl('foo') // => 'bar@2x.webp'
* ```

@@ -953,15 +968,15 @@ * Other features include:

* resolver.add('foo', [
* {
* resolution:2,
* format:'png'
* src: 'image@2x.png'
* },
* {
* resolution:1,
* format:'png'
* src: 'image.png'
* }
* {
* resolution: 2,
* format: 'png',
* src: 'image@2x.png',
* },
* {
* resolution:1,
* format:'png',
* src: 'image.png',
* },
* ]);
*
* // with a url parser the information such as resolution and file format could extracted from the url itself:
* // With a url parser the information such as resolution and file format could extracted from the url itself:
* extensions.add({

@@ -978,8 +993,7 @@ * extension: ExtensionType.ResolveParser,

*
* // now resolution and format can be extracted from the url
* // Now resolution and format can be extracted from the url
* resolver.add('foo', [
* 'image@2x.png'
* 'image.png'
* 'image@2x.png',
* 'image.png',
* ]);
* @
*/

@@ -999,7 +1013,7 @@ get parsers(): ResolveURLParser[];

* @example
* resolver.addBundle('animals', {
* bunny: 'bunny.png',
* chicken: 'chicken.png',
* thumper: 'thumper.png',
* });
* resolver.addBundle('animals', {
* bunny: 'bunny.png',
* chicken: 'chicken.png',
* thumper: 'thumper.png',
* });
*

@@ -1015,7 +1029,7 @@ * const resolvedAssets = await resolver.resolveBundle('animals');

* @example
* // single key, single asset:
* // Single key, single asset:
* resolver.add('foo', 'bar.png');
* resolver.resolveUrl('foo') // => 'bar.png'
*
* // multiple keys, single asset:
* // Multiple keys, single asset:
* resolver.add(['foo', 'boo'], 'bar.png');

@@ -1025,14 +1039,14 @@ * resolver.resolveUrl('foo') // => 'bar.png'

*
* // multiple keys, multiple assets:
* // Multiple keys, multiple assets:
* resolver.add(['foo', 'boo'], ['bar.png', 'bar.webp']);
* resolver.resolveUrl('foo') // => 'bar.png'
*
* // add custom data attached to the resolver
* // Add custom data attached to the resolver
* Resolver.add(
* 'bunnyBooBooSmooth',
* 'bunny{png,webp}',
* {scaleMode:SCALE_MODES.NEAREST} // base texture options
* { scaleMode:SCALE_MODES.NEAREST }, // Base texture options
* );
*
* resolver.resolve('bunnyBooBooSmooth') // => {src: 'bunny.png', data: {scaleMode: SCALE_MODES.NEAREST}}
* resolver.resolve('bunnyBooBooSmooth') // => { src: 'bunny.png', data: { scaleMode: SCALE_MODES.NEAREST } }
* @param keysIn - The keys to map, can be an array or a single key

@@ -1047,31 +1061,34 @@ * @param assetsIn - The assets to associate with the key(s)

* @example
* // manifest example
* // Manifest Example
* const manifest = {
* bundles:[{
* name:'load-screen',
* assets:[
* {
* name: 'background',
* srcs: 'sunset.png',
* },
* {
* name: 'bar',
* srcs: 'load-bar.{png,webp}',
* }
* ]
* },
* {
* name:'game-screen',
* assets:[
* {
* name: 'character',
* srcs: 'robot.png',
* },
* {
* name: 'enemy',
* srcs: 'bad-guy.png',
* }
* ]
* }]
* }}
* bundles: [
* {
* name: 'load-screen',
* assets: [
* {
* name: 'background',
* srcs: 'sunset.png',
* },
* {
* name: 'bar',
* srcs: 'load-bar.{png,webp}',
* },
* ],
* },
* {
* name: 'game-screen',
* assets: [
* {
* name: 'character',
* srcs: 'robot.png',
* },
* {
* name: 'enemy',
* srcs: 'bad-guy.png',
* },
* ],
* },
* ]
* };
*
* resolver.setManifest(manifest);

@@ -1097,6 +1114,6 @@ * const resolved = resolver.resolveBundle('load-screen');

*
* resolver.resolve('boo') // => {src:'bunny.png'}
* resolver.resolve('boo') // => { src: 'bunny.png' }
*
* // will return the same string as no key was added for this value..
* resolver.resolve('another-thing.png') // => {src:'another-thing.png'}
* // Will return the same string as no key was added for this value..
* resolver.resolve('another-thing.png') // => { src: 'another-thing.png' }
* @param keys - key or keys to resolve

@@ -1103,0 +1120,0 @@ * @returns - the resolve asset or a hash of resolve assets for each key specified

{
"name": "@pixi/assets",
"version": "7.0.0-beta.3",
"version": "7.0.0-beta.4",
"description": "Asset manager for PixiJS, loading resolving and Cacheing",

@@ -52,3 +52,3 @@ "keywords": [

],
"gitHead": "8055ae1c16d4c0f8dabda86cafd8e68c356450e8"
"gitHead": "a4581e4a49d23afc98fcf726765c9d54e51c3c39"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc