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

@pixi/prepare

Package Overview
Dependencies
Maintainers
2
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixi/prepare - npm Package Compare versions

Comparing version 7.2.4 to 7.3.0-rc

209

lib/BasePrepare.js

@@ -1,22 +0,11 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var core = require('@pixi/core');
var display = require('@pixi/display');
var text = require('@pixi/text');
var CountLimiter = require('./CountLimiter.js');
"use strict";
var core = require("@pixi/core"), display = require("@pixi/display"), text = require("@pixi/text"), CountLimiter = require("./CountLimiter.js");
function findMultipleBaseTextures(item, queue) {
let result = false;
let result = !1;
if (item?._textures?.length) {
for (let i = 0; i < item._textures.length; i++) {
for (let i = 0; i < item._textures.length; i++)
if (item._textures[i] instanceof core.Texture) {
const baseTexture = item._textures[i].baseTexture;
if (!queue.includes(baseTexture)) {
queue.push(baseTexture);
result = true;
}
queue.includes(baseTexture) || (queue.push(baseTexture), result = !0);
}
}
}

@@ -28,8 +17,5 @@ return result;

const texture = item.baseTexture;
if (!queue.includes(texture)) {
queue.push(texture);
}
return true;
return queue.includes(texture) || queue.push(texture), !0;
}
return false;
return !1;
}

@@ -39,15 +25,8 @@ function findTexture(item, queue) {

const texture = item._texture.baseTexture;
if (!queue.includes(texture)) {
queue.push(texture);
}
return true;
return queue.includes(texture) || queue.push(texture), !0;
}
return false;
return !1;
}
function drawText(_helper, item) {
if (item instanceof text.Text) {
item.updateText(true);
return true;
}
return false;
return item instanceof text.Text ? (item.updateText(!0), !0) : !1;
}

@@ -57,147 +36,113 @@ function calculateTextStyle(_helper, item) {

const font = item.toFontString();
text.TextMetrics.measureFont(font);
return true;
return text.TextMetrics.measureFont(font), !0;
}
return false;
return !1;
}
function findText(item, queue) {
if (item instanceof text.Text) {
if (!queue.includes(item.style)) {
queue.push(item.style);
}
if (!queue.includes(item)) {
queue.push(item);
}
queue.includes(item.style) || queue.push(item.style), queue.includes(item) || queue.push(item);
const texture = item._texture.baseTexture;
if (!queue.includes(texture)) {
queue.push(texture);
}
return true;
return queue.includes(texture) || queue.push(texture), !0;
}
return false;
return !1;
}
function findTextStyle(item, queue) {
if (item instanceof text.TextStyle) {
if (!queue.includes(item)) {
queue.push(item);
}
return true;
}
return false;
return item instanceof text.TextStyle ? (queue.includes(item) || queue.push(item), !0) : !1;
}
const _BasePrepare = class {
const _BasePrepare = class _BasePrepare2 {
/**
* @param {PIXI.IRenderer} renderer - A reference to the current renderer
*/
constructor(renderer) {
this.limiter = new CountLimiter.CountLimiter(_BasePrepare.uploadsPerFrame);
this.renderer = renderer;
this.uploadHookHelper = null;
this.queue = [];
this.addHooks = [];
this.uploadHooks = [];
this.completes = [];
this.ticking = false;
this.delayedTick = () => {
if (!this.queue) {
return;
}
this.prepareItems();
};
this.registerFindHook(findText);
this.registerFindHook(findTextStyle);
this.registerFindHook(findMultipleBaseTextures);
this.registerFindHook(findBaseTexture);
this.registerFindHook(findTexture);
this.registerUploadHook(drawText);
this.registerUploadHook(calculateTextStyle);
this.limiter = new CountLimiter.CountLimiter(_BasePrepare2.uploadsPerFrame), this.renderer = renderer, this.uploadHookHelper = null, this.queue = [], this.addHooks = [], this.uploadHooks = [], this.completes = [], this.ticking = !1, this.delayedTick = () => {
this.queue && this.prepareItems();
}, this.registerFindHook(findText), this.registerFindHook(findTextStyle), this.registerFindHook(findMultipleBaseTextures), this.registerFindHook(findBaseTexture), this.registerFindHook(findTexture), this.registerUploadHook(drawText), this.registerUploadHook(calculateTextStyle);
}
/**
* Upload all the textures and graphics to the GPU.
* @method PIXI.BasePrepare#upload
* @param {PIXI.DisplayObject|PIXI.Container|PIXI.BaseTexture|PIXI.Texture|PIXI.Graphics|PIXI.Text} [item] -
* Container or display object to search for items to upload or the items to upload themselves,
* or optionally ommitted, if items have been added using {@link PIXI.BasePrepare#add `prepare.add`}.
*/
upload(item) {
return new Promise((resolve) => {
if (item) {
this.add(item);
}
if (this.queue.length) {
this.completes.push(resolve);
if (!this.ticking) {
this.ticking = true;
core.Ticker.system.addOnce(this.tick, this, core.UPDATE_PRIORITY.UTILITY);
}
} else {
resolve();
}
item && this.add(item), this.queue.length ? (this.completes.push(resolve), this.ticking || (this.ticking = !0, core.Ticker.system.addOnce(this.tick, this, core.UPDATE_PRIORITY.UTILITY))) : resolve();
});
}
/**
* Handle tick update
* @private
*/
tick() {
setTimeout(this.delayedTick, 0);
}
/**
* Actually prepare items. This is handled outside of the tick because it will take a while
* and we do NOT want to block the current animation frame from rendering.
* @private
*/
prepareItems() {
this.limiter.beginFrame();
while (this.queue.length && this.limiter.allowedToUpload()) {
for (this.limiter.beginFrame(); this.queue.length && this.limiter.allowedToUpload(); ) {
const item = this.queue[0];
let uploaded = false;
let uploaded = !1;
if (item && !item._destroyed) {
for (let i = 0, len = this.uploadHooks.length; i < len; i++) {
for (let i = 0, len = this.uploadHooks.length; i < len; i++)
if (this.uploadHooks[i](this.uploadHookHelper, item)) {
this.queue.shift();
uploaded = true;
this.queue.shift(), uploaded = !0;
break;
}
}
}
if (!uploaded) {
this.queue.shift();
}
uploaded || this.queue.shift();
}
if (!this.queue.length) {
this.ticking = false;
if (this.queue.length)
core.Ticker.system.addOnce(this.tick, this, core.UPDATE_PRIORITY.UTILITY);
else {
this.ticking = !1;
const completes = this.completes.slice(0);
this.completes.length = 0;
for (let i = 0, len = completes.length; i < len; i++) {
for (let i = 0, len = completes.length; i < len; i++)
completes[i]();
}
} else {
core.Ticker.system.addOnce(this.tick, this, core.UPDATE_PRIORITY.UTILITY);
}
}
/**
* Adds hooks for finding items.
* @param {Function} addHook - Function call that takes two parameters: `item:*, queue:Array`
* function must return `true` if it was able to add item to the queue.
* @returns Instance of plugin for chaining.
*/
registerFindHook(addHook) {
if (addHook) {
this.addHooks.push(addHook);
}
return this;
return addHook && this.addHooks.push(addHook), this;
}
/**
* Adds hooks for uploading items.
* @param {Function} uploadHook - Function call that takes two parameters: `prepare:CanvasPrepare, item:*` and
* function must return `true` if it was able to handle upload of item.
* @returns Instance of plugin for chaining.
*/
registerUploadHook(uploadHook) {
if (uploadHook) {
this.uploadHooks.push(uploadHook);
}
return this;
return uploadHook && this.uploadHooks.push(uploadHook), this;
}
/**
* Manually add an item to the uploading queue.
* @param {PIXI.DisplayObject|PIXI.Container|PIXI.BaseTexture|PIXI.Texture|PIXI.Graphics|PIXI.Text|*} item - Object to
* add to the queue
* @returns Instance of plugin for chaining.
*/
add(item) {
for (let i = 0, len = this.addHooks.length; i < len; i++) {
if (this.addHooks[i](item, this.queue)) {
break;
}
}
if (item instanceof display.Container) {
for (let i = item.children.length - 1; i >= 0; i--) {
for (let i = 0, len = this.addHooks.length; i < len && !this.addHooks[i](item, this.queue); i++)
;
if (item instanceof display.Container)
for (let i = item.children.length - 1; i >= 0; i--)
this.add(item.children[i]);
}
}
return this;
}
/** Destroys the plugin, don't use after this. */
destroy() {
if (this.ticking) {
core.Ticker.system.remove(this.tick, this);
}
this.ticking = false;
this.addHooks = null;
this.uploadHooks = null;
this.renderer = null;
this.completes = null;
this.queue = null;
this.limiter = null;
this.uploadHookHelper = null;
this.ticking && core.Ticker.system.remove(this.tick, this), this.ticking = !1, this.addHooks = null, this.uploadHooks = null, this.renderer = null, this.completes = null, this.queue = null, this.limiter = null, this.uploadHookHelper = null;
}
};
_BasePrepare.uploadsPerFrame = 4;
let BasePrepare = _BasePrepare;
BasePrepare.uploadsPerFrame = 4;
exports.BasePrepare = BasePrepare;
//# sourceMappingURL=BasePrepare.js.map

@@ -1,13 +0,17 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
"use strict";
class CountLimiter {
/**
* @param maxItemsPerFrame - The maximum number of items that can be prepared each frame.
*/
constructor(maxItemsPerFrame) {
this.maxItemsPerFrame = maxItemsPerFrame;
this.itemsLeft = 0;
this.maxItemsPerFrame = maxItemsPerFrame, this.itemsLeft = 0;
}
/** Resets any counting properties to start fresh on a new frame. */
beginFrame() {
this.itemsLeft = this.maxItemsPerFrame;
}
/**
* Checks to see if another item can be uploaded. This should only be called once per item.
* @returns If the item is allowed to be uploaded.
*/
allowedToUpload() {

@@ -17,4 +21,3 @@ return this.itemsLeft-- > 0;

}
exports.CountLimiter = CountLimiter;
//# sourceMappingURL=CountLimiter.js.map

@@ -1,13 +0,4 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
require('./settings.js');
var BasePrepare = require('./BasePrepare.js');
var CountLimiter = require('./CountLimiter.js');
var Prepare = require('./Prepare.js');
var TimeLimiter = require('./TimeLimiter.js');
"use strict";
require("./settings.js");
var BasePrepare = require("./BasePrepare.js"), CountLimiter = require("./CountLimiter.js"), Prepare = require("./Prepare.js"), TimeLimiter = require("./TimeLimiter.js");
exports.BasePrepare = BasePrepare.BasePrepare;

@@ -14,0 +5,0 @@ exports.CountLimiter = CountLimiter.CountLimiter;

@@ -1,51 +0,27 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var core = require('@pixi/core');
var graphics = require('@pixi/graphics');
var BasePrepare = require('./BasePrepare.js');
"use strict";
var core = require("@pixi/core"), graphics = require("@pixi/graphics"), BasePrepare = require("./BasePrepare.js");
function uploadBaseTextures(renderer, item) {
if (item instanceof core.BaseTexture) {
if (!item._glTextures[renderer.CONTEXT_UID]) {
renderer.texture.bind(item);
}
return true;
}
return false;
return item instanceof core.BaseTexture ? (item._glTextures[renderer.CONTEXT_UID] || renderer.texture.bind(item), !0) : !1;
}
function uploadGraphics(renderer, item) {
if (!(item instanceof graphics.Graphics)) {
return false;
}
if (!(item instanceof graphics.Graphics))
return !1;
const { geometry } = item;
item.finishPoly();
geometry.updateBatches();
item.finishPoly(), geometry.updateBatches();
const { batches } = geometry;
for (let i = 0; i < batches.length; i++) {
const { texture } = batches[i].style;
if (texture) {
uploadBaseTextures(renderer, texture.baseTexture);
}
texture && uploadBaseTextures(renderer, texture.baseTexture);
}
if (!geometry.batchable) {
renderer.geometry.bind(geometry, item._resolveDirectShader(renderer));
}
return true;
return geometry.batchable || renderer.geometry.bind(geometry, item._resolveDirectShader(renderer)), !0;
}
function findGraphics(item, queue) {
if (item instanceof graphics.Graphics) {
queue.push(item);
return true;
}
return false;
return item instanceof graphics.Graphics ? (queue.push(item), !0) : !1;
}
class Prepare extends BasePrepare.BasePrepare {
/**
* @param {PIXI.Renderer} renderer - A reference to the current renderer
*/
constructor(renderer) {
super(renderer);
this.uploadHookHelper = this.renderer;
this.registerFindHook(findGraphics);
this.registerUploadHook(uploadBaseTextures);
this.registerUploadHook(uploadGraphics);
super(renderer), this.uploadHookHelper = this.renderer, this.registerFindHook(findGraphics), this.registerUploadHook(uploadBaseTextures), this.registerUploadHook(uploadGraphics);
}

@@ -58,4 +34,3 @@ }

core.extensions.add(Prepare);
exports.Prepare = Prepare;
//# sourceMappingURL=Prepare.js.map

@@ -1,9 +0,13 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var core = require('@pixi/core');
var BasePrepare = require('./BasePrepare.js');
"use strict";
var core = require("@pixi/core"), BasePrepare = require("./BasePrepare.js");
Object.defineProperties(core.settings, {
/**
* Default number of uploads per frame using prepare plugin.
* @static
* @memberof PIXI.settings
* @name UPLOADS_PER_FRAME
* @deprecated since 7.1.0
* @see PIXI.BasePrepare.uploadsPerFrame
* @type {number}
*/
UPLOADS_PER_FRAME: {

@@ -14,12 +18,12 @@ get() {

set(value) {
core.utils.deprecation("7.1.0", "settings.UPLOADS_PER_FRAME is deprecated, use prepare.BasePrepare.uploadsPerFrame");
BasePrepare.BasePrepare.uploadsPerFrame = value;
core.utils.deprecation("7.1.0", "settings.UPLOADS_PER_FRAME is deprecated, use prepare.BasePrepare.uploadsPerFrame"), BasePrepare.BasePrepare.uploadsPerFrame = value;
}
}
});
Object.defineProperty(exports, 'settings', {
enumerable: true,
get: function () { return core.settings; }
Object.defineProperty(exports, "settings", {
enumerable: !0,
get: function() {
return core.settings;
}
});
//# sourceMappingURL=settings.js.map

@@ -1,13 +0,15 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
"use strict";
class TimeLimiter {
/** @param maxMilliseconds - The maximum milliseconds that can be spent preparing items each frame. */
constructor(maxMilliseconds) {
this.maxMilliseconds = maxMilliseconds;
this.frameStart = 0;
this.maxMilliseconds = maxMilliseconds, this.frameStart = 0;
}
/** Resets any counting properties to start fresh on a new frame. */
beginFrame() {
this.frameStart = Date.now();
}
/**
* Checks to see if another item can be uploaded. This should only be called once per item.
* @returns - If the item is allowed to be uploaded.
*/
allowedToUpload() {

@@ -17,4 +19,3 @@ return Date.now() - this.frameStart < this.maxMilliseconds;

}
exports.TimeLimiter = TimeLimiter;
//# sourceMappingURL=TimeLimiter.js.map
{
"name": "@pixi/prepare",
"version": "7.2.4",
"version": "7.3.0-rc",
"main": "lib/index.js",

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

"peerDependencies": {
"@pixi/core": "7.2.4",
"@pixi/display": "7.2.4",
"@pixi/graphics": "7.2.4",
"@pixi/text": "7.2.4"
"@pixi/core": "7.3.0-rc",
"@pixi/display": "7.3.0-rc",
"@pixi/graphics": "7.3.0-rc",
"@pixi/text": "7.3.0-rc"
}
}

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

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

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