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

@pixi/spritesheet

Package Overview
Dependencies
Maintainers
2
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixi/spritesheet - npm Package Compare versions

Comparing version 7.3.3 to 7.4.0

54

lib/Spritesheet.d.ts

@@ -74,2 +74,20 @@ import { BaseTexture, Texture, utils } from '@pixi/core';

/**
* Options for loading a spritesheet from an atlas.
* @memberof PIXI
*/
interface SpritesheetOptions<S extends ISpritesheetData = ISpritesheetData> {
/** Reference to Texture */
texture: BaseTexture | Texture;
/** JSON data for the atlas. */
data: S;
/** The filename to consider when determining the resolution of the spritesheet. */
resolutionFilename?: string;
/**
* Prefix to add to texture names when adding to global TextureCache,
* using this option can be helpful if you have multiple texture atlases
* that share texture names and you need to disambiguate them.
*/
cachePrefix?: string;
}
/**
* Utility class for maintaining reference to a collection

@@ -143,2 +161,29 @@ * of Textures on a single Spritesheet.

* supported by TexturePacker.
*
* Alternative ways for loading spritesheet image if you need more control:
*
* ```js
* import { Assets } from 'pixi.js';
*
* const sheetTexture = await Assets.load('images/spritesheet.png');
* Assets.add({
* alias: 'atlas',
* src: 'images/spritesheet.json'
* data: {texture: sheetTexture} // using of preloaded texture
* });
* const sheet = await Assets.load('atlas')
* ```
*
* or:
*
* ```js
* import { Assets } from 'pixi.js';
*
* Assets.add({
* alias: 'atlas',
* src: 'images/spritesheet.json'
* data: {imageFilename: 'my-spritesheet.2x.avif'} // using of custom filename located in "images/my-spritesheet.2x.avif"
* });
* const sheet = await Assets.load('atlas')
* ```
* @memberof PIXI

@@ -197,3 +242,11 @@ */

private _callback;
/** Prefix string to add to global cache */
readonly cachePrefix: string;
/**
* @class
* @param options - Options to use when constructing a new Spritesheet.
*/
constructor(options: SpritesheetOptions<S>);
/**
* @class
* @param texture - Reference to the source BaseTexture object.

@@ -237,1 +290,2 @@ * @param {object} data - Spritesheet image data.

}
export {};

16

lib/Spritesheet.js
"use strict";
var core = require("@pixi/core");
const _Spritesheet = class _Spritesheet2 {
/**
* @param texture - Reference to the source BaseTexture object.
* @param {object} data - Spritesheet image data.
* @param resolutionFilename - The filename to consider when determining
* the resolution of the spritesheet. If not provided, the imageUrl will
* be used on the BaseTexture.
*/
constructor(texture, data, resolutionFilename = null) {
this.linkedSheets = [], this._texture = texture instanceof core.Texture ? texture : null, this.baseTexture = texture instanceof core.BaseTexture ? texture : this._texture.baseTexture, this.textures = {}, this.animations = {}, this.data = data;
/** @ignore */
constructor(optionsOrTexture, arg1, arg2) {
this.linkedSheets = [], (optionsOrTexture instanceof core.BaseTexture || optionsOrTexture instanceof core.Texture) && (optionsOrTexture = { texture: optionsOrTexture, data: arg1, resolutionFilename: arg2 });
const { texture, data, resolutionFilename = null, cachePrefix = "" } = optionsOrTexture;
this.cachePrefix = cachePrefix, this._texture = texture instanceof core.Texture ? texture : null, this.baseTexture = texture instanceof core.BaseTexture ? texture : this._texture.baseTexture, this.textures = {}, this.animations = {}, this.data = data;
const resource = this.baseTexture.resource;

@@ -78,3 +74,3 @@ this.resolution = this._updateResolution(resolutionFilename || (resource ? resource.url : null)), this._frames = this.data.frames, this._frameKeys = Object.keys(this._frames), this._batchIndex = 0, this._callback = null;

data.borders
), core.Texture.addToCache(this.textures[i], i.toString());
), core.Texture.addToCache(this.textures[i], this.cachePrefix + i.toString());
}

@@ -81,0 +77,0 @@ frameIndex++;

@@ -9,8 +9,11 @@ "use strict";

}), Object.keys(asset.textures).forEach((key) => {
out[key] = asset.textures[key];
out[`${asset.cachePrefix}${key}`] = asset.textures[key];
}), !ignoreMultiPack) {
const basePath = core.utils.path.dirname(keys[0]);
asset.linkedSheets.forEach((item, i) => {
const out2 = getCacheableAssets([`${basePath}/${asset.data.meta.related_multi_packs[i]}`], item, !0);
Object.assign(out, out2);
Object.assign(out, getCacheableAssets(
[`${basePath}/${asset.data.meta.related_multi_packs[i]}`],
item,
!0
));
});

@@ -59,11 +62,25 @@ }

async parse(asset, options, loader) {
const {
texture: imageTexture,
// if user need to use preloaded texture
imageFilename,
// if user need to use custom filename (not from jsonFile.meta.image)
cachePrefix
// if user need to use custom cache prefix
} = options?.data ?? {};
let basePath = core.utils.path.dirname(options.src);
basePath && basePath.lastIndexOf("/") !== basePath.length - 1 && (basePath += "/");
let imagePath = basePath + asset.meta.image;
imagePath = assets.copySearchParams(imagePath, options.src);
const texture = (await loader.load([imagePath]))[imagePath], spritesheet = new Spritesheet.Spritesheet(
texture.baseTexture,
asset,
options.src
);
let texture;
if (imageTexture && imageTexture.baseTexture)
texture = imageTexture;
else {
const imagePath = assets.copySearchParams(basePath + (imageFilename ?? asset.meta.image), options.src);
texture = (await loader.load([imagePath]))[imagePath];
}
const spritesheet = new Spritesheet.Spritesheet({
texture: texture.baseTexture,
data: asset,
resolutionFilename: options.src,
cachePrefix
});
await spritesheet.parse();

@@ -70,0 +87,0 @@ const multiPacks = asset?.meta?.related_multi_packs;

{
"name": "@pixi/spritesheet",
"version": "7.3.3",
"version": "7.4.0",
"main": "lib/index.js",

@@ -39,5 +39,5 @@ "module": "lib/index.mjs",

"peerDependencies": {
"@pixi/assets": "7.3.3",
"@pixi/core": "7.3.3"
"@pixi/assets": "7.4.0",
"@pixi/core": "7.4.0"
}
}

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