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

@pixi/prepare

Package Overview
Dependencies
Maintainers
3
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 6.5.3 to 7.0.0-alpha

global.d.ts

723

dist/cjs/prepare.js
/*!
* @pixi/prepare - v6.5.3
* Compiled Fri, 09 Sep 2022 13:55:20 UTC
* @pixi/prepare - v7.0.0-alpha
* Compiled Fri, 09 Sep 2022 16:09:18 UTC
*

@@ -12,534 +12,271 @@ * @pixi/prepare is licensed under the MIT License.

var settings = require('@pixi/settings');
var core = require('@pixi/core');
var graphics = require('@pixi/graphics');
var ticker = require('@pixi/ticker');
var display = require('@pixi/display');
var text = require('@pixi/text');
var utils = require('@pixi/utils');
/**
* Default number of uploads per frame using prepare plugin.
* @static
* @memberof PIXI.settings
* @name UPLOADS_PER_FRAME
* @type {number}
* @default 4
*/
settings.settings.UPLOADS_PER_FRAME = 4;
core.settings.UPLOADS_PER_FRAME = 4;
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
class CountLimiter {
constructor(maxItemsPerFrame) {
this.maxItemsPerFrame = maxItemsPerFrame;
this.itemsLeft = 0;
}
beginFrame() {
this.itemsLeft = this.maxItemsPerFrame;
}
allowedToUpload() {
return this.itemsLeft-- > 0;
}
}
/**
* CountLimiter limits the number of items handled by a {@link PIXI.BasePrepare} to a specified
* number of items per frame.
* @memberof PIXI
*/
var CountLimiter = /** @class */ (function () {
/**
* @param maxItemsPerFrame - The maximum number of items that can be prepared each frame.
*/
function CountLimiter(maxItemsPerFrame) {
this.maxItemsPerFrame = maxItemsPerFrame;
this.itemsLeft = 0;
}
/** Resets any counting properties to start fresh on a new frame. */
CountLimiter.prototype.beginFrame = function () {
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.
*/
CountLimiter.prototype.allowedToUpload = function () {
return this.itemsLeft-- > 0;
};
return CountLimiter;
}());
/**
* Built-in hook to find multiple textures from objects like AnimatedSprites.
* @private
* @param item - Display object to check
* @param queue - Collection of items to upload
* @returns If a PIXI.Texture object was found.
*/
function findMultipleBaseTextures(item, queue) {
var result = false;
// Objects with multiple textures
if (item && item._textures && item._textures.length) {
for (var i = 0; i < item._textures.length; i++) {
if (item._textures[i] instanceof core.Texture) {
var baseTexture = item._textures[i].baseTexture;
if (queue.indexOf(baseTexture) === -1) {
queue.push(baseTexture);
result = true;
}
}
let result = false;
if (item?._textures?.length) {
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;
}
}
}
return result;
}
return result;
}
/**
* Built-in hook to find BaseTextures from Texture.
* @private
* @param item - Display object to check
* @param queue - Collection of items to upload
* @returns If a PIXI.Texture object was found.
*/
function findBaseTexture(item, queue) {
if (item.baseTexture instanceof core.BaseTexture) {
var texture = item.baseTexture;
if (queue.indexOf(texture) === -1) {
queue.push(texture);
}
return true;
if (item.baseTexture instanceof core.BaseTexture) {
const texture = item.baseTexture;
if (!queue.includes(texture)) {
queue.push(texture);
}
return false;
return true;
}
return false;
}
/**
* Built-in hook to find textures from objects.
* @private
* @param item - Display object to check
* @param queue - Collection of items to upload
* @returns If a PIXI.Texture object was found.
*/
function findTexture(item, queue) {
if (item._texture && item._texture instanceof core.Texture) {
var texture = item._texture.baseTexture;
if (queue.indexOf(texture) === -1) {
queue.push(texture);
}
return true;
if (item._texture && item._texture instanceof core.Texture) {
const texture = item._texture.baseTexture;
if (!queue.includes(texture)) {
queue.push(texture);
}
return false;
return true;
}
return false;
}
/**
* Built-in hook to draw PIXI.Text to its texture.
* @private
* @param _helper - Not used by this upload handler
* @param item - Item to check
* @returns If item was uploaded.
*/
function drawText(_helper, item) {
if (item instanceof text.Text) {
// updating text will return early if it is not dirty
item.updateText(true);
return true;
}
return false;
if (item instanceof text.Text) {
item.updateText(true);
return true;
}
return false;
}
/**
* Built-in hook to calculate a text style for a PIXI.Text object.
* @private
* @param _helper - Not used by this upload handler
* @param item - Item to check
* @returns If item was uploaded.
*/
function calculateTextStyle(_helper, item) {
if (item instanceof text.TextStyle) {
var font = item.toFontString();
text.TextMetrics.measureFont(font);
return true;
}
return false;
if (item instanceof text.TextStyle) {
const font = item.toFontString();
text.TextMetrics.measureFont(font);
return true;
}
return false;
}
/**
* Built-in hook to find Text objects.
* @private
* @param item - Display object to check
* @param queue - Collection of items to upload
* @returns if a PIXI.Text object was found.
*/
function findText(item, queue) {
if (item instanceof text.Text) {
// push the text style to prepare it - this can be really expensive
if (queue.indexOf(item.style) === -1) {
queue.push(item.style);
}
// also push the text object so that we can render it (to canvas/texture) if needed
if (queue.indexOf(item) === -1) {
queue.push(item);
}
// also push the Text's texture for upload to GPU
var texture = item._texture.baseTexture;
if (queue.indexOf(texture) === -1) {
queue.push(texture);
}
return true;
if (item instanceof text.Text) {
if (!queue.includes(item.style)) {
queue.push(item.style);
}
return false;
if (!queue.includes(item)) {
queue.push(item);
}
const texture = item._texture.baseTexture;
if (!queue.includes(texture)) {
queue.push(texture);
}
return true;
}
return false;
}
/**
* Built-in hook to find TextStyle objects.
* @private
* @param item - Display object to check
* @param queue - Collection of items to upload
* @returns If a PIXI.TextStyle object was found.
*/
function findTextStyle(item, queue) {
if (item instanceof text.TextStyle) {
if (queue.indexOf(item) === -1) {
queue.push(item);
}
return true;
if (item instanceof text.TextStyle) {
if (!queue.includes(item)) {
queue.push(item);
}
return false;
return true;
}
return false;
}
/**
* The prepare manager provides functionality to upload content to the GPU.
*
* BasePrepare handles basic queuing functionality and is extended by
* {@link PIXI.Prepare} and {@link PIXI.CanvasPrepare}
* to provide preparation capabilities specific to their respective renderers.
* @example
* // Create a sprite
* const sprite = PIXI.Sprite.from('something.png');
*
* // Load object into GPU
* app.renderer.plugins.prepare.upload(sprite, () => {
*
* //Texture(s) has been uploaded to GPU
* app.stage.addChild(sprite);
*
* })
* @abstract
* @memberof PIXI
*/
var BasePrepare = /** @class */ (function () {
/**
* @param {PIXI.AbstractRenderer} renderer - A reference to the current renderer
*/
function BasePrepare(renderer) {
var _this = this;
this.limiter = new CountLimiter(settings.settings.UPLOADS_PER_FRAME);
this.renderer = renderer;
this.uploadHookHelper = null;
this.queue = [];
this.addHooks = [];
this.uploadHooks = [];
this.completes = [];
this.ticking = false;
this.delayedTick = function () {
// unlikely, but in case we were destroyed between tick() and delayedTick()
if (!_this.queue) {
return;
}
_this.prepareItems();
};
// hooks to find the correct texture
this.registerFindHook(findText);
this.registerFindHook(findTextStyle);
this.registerFindHook(findMultipleBaseTextures);
this.registerFindHook(findBaseTexture);
this.registerFindHook(findTexture);
// upload hooks
this.registerUploadHook(drawText);
this.registerUploadHook(calculateTextStyle);
}
/** @ignore */
BasePrepare.prototype.upload = function (item, done) {
var _this = this;
if (typeof item === 'function') {
done = item;
item = null;
}
if (done) {
utils.deprecation('6.5.0', 'BasePrepare.upload callback is deprecated, use the return Promise instead.');
}
return new Promise(function (resolve) {
// If a display object, search for items
// that we could upload
if (item) {
_this.add(item);
}
// TODO: remove done callback and just use resolve
var complete = function () {
done === null || done === void 0 ? void 0 : done();
resolve();
};
// Get the items for upload from the display
if (_this.queue.length) {
_this.completes.push(complete);
if (!_this.ticking) {
_this.ticking = true;
ticker.Ticker.system.addOnce(_this.tick, _this, ticker.UPDATE_PRIORITY.UTILITY);
}
}
else {
complete();
}
});
class BasePrepare {
constructor(renderer) {
this.limiter = new CountLimiter(core.settings.UPLOADS_PER_FRAME);
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();
};
/**
* Handle tick update
* @private
*/
BasePrepare.prototype.tick = function () {
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
*/
BasePrepare.prototype.prepareItems = function () {
this.limiter.beginFrame();
// Upload the graphics
while (this.queue.length && this.limiter.allowedToUpload()) {
var item = this.queue[0];
var uploaded = false;
if (item && !item._destroyed) {
for (var i = 0, len = this.uploadHooks.length; i < len; i++) {
if (this.uploadHooks[i](this.uploadHookHelper, item)) {
this.queue.shift();
uploaded = true;
break;
}
}
}
if (!uploaded) {
this.queue.shift();
}
this.registerFindHook(findText);
this.registerFindHook(findTextStyle);
this.registerFindHook(findMultipleBaseTextures);
this.registerFindHook(findBaseTexture);
this.registerFindHook(findTexture);
this.registerUploadHook(drawText);
this.registerUploadHook(calculateTextStyle);
}
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);
}
// We're finished
if (!this.queue.length) {
this.ticking = false;
var completes = this.completes.slice(0);
this.completes.length = 0;
for (var i = 0, len = completes.length; i < len; i++) {
completes[i]();
}
} else {
resolve();
}
});
}
tick() {
setTimeout(this.delayedTick, 0);
}
prepareItems() {
this.limiter.beginFrame();
while (this.queue.length && this.limiter.allowedToUpload()) {
const item = this.queue[0];
let uploaded = false;
if (item && !item._destroyed) {
for (let i = 0, len = this.uploadHooks.length; i < len; i++) {
if (this.uploadHooks[i](this.uploadHookHelper, item)) {
this.queue.shift();
uploaded = true;
break;
}
}
else {
// if we are not finished, on the next rAF do this again
ticker.Ticker.system.addOnce(this.tick, this, ticker.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.
*/
BasePrepare.prototype.registerFindHook = function (addHook) {
if (addHook) {
this.addHooks.push(addHook);
}
return 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.
*/
BasePrepare.prototype.registerUploadHook = function (uploadHook) {
if (uploadHook) {
this.uploadHooks.push(uploadHook);
}
return 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.
*/
BasePrepare.prototype.add = function (item) {
// Add additional hooks for finding elements on special
// types of objects that
for (var i = 0, len = this.addHooks.length; i < len; i++) {
if (this.addHooks[i](item, this.queue)) {
break;
}
}
// Get children recursively
if (item instanceof display.Container) {
for (var i = item.children.length - 1; i >= 0; i--) {
this.add(item.children[i]);
}
}
return this;
};
/** Destroys the plugin, don't use after this. */
BasePrepare.prototype.destroy = function () {
if (this.ticking) {
ticker.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;
};
return BasePrepare;
}());
}
if (!uploaded) {
this.queue.shift();
}
}
if (!this.queue.length) {
this.ticking = false;
const completes = this.completes.slice(0);
this.completes.length = 0;
for (let i = 0, len = completes.length; i < len; i++) {
completes[i]();
}
} else {
core.Ticker.system.addOnce(this.tick, this, core.UPDATE_PRIORITY.UTILITY);
}
}
registerFindHook(addHook) {
if (addHook) {
this.addHooks.push(addHook);
}
return this;
}
registerUploadHook(uploadHook) {
if (uploadHook) {
this.uploadHooks.push(uploadHook);
}
return this;
}
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--) {
this.add(item.children[i]);
}
}
return 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;
}
}
/**
* Built-in hook to upload PIXI.Texture objects to the GPU.
* @private
* @param renderer - instance of the webgl renderer
* @param item - Item to check
* @returns If item was uploaded.
*/
function uploadBaseTextures(renderer, item) {
if (item instanceof core.BaseTexture) {
// if the texture already has a GL texture, then the texture has been prepared or rendered
// before now. If the texture changed, then the changer should be calling texture.update() which
// reuploads the texture without need for preparing it again
if (!item._glTextures[renderer.CONTEXT_UID]) {
renderer.texture.bind(item);
}
return true;
if (item instanceof core.BaseTexture) {
if (!item._glTextures[renderer.CONTEXT_UID]) {
renderer.texture.bind(item);
}
return false;
return true;
}
return false;
}
/**
* Built-in hook to upload PIXI.Graphics to the GPU.
* @private
* @param renderer - instance of the webgl renderer
* @param item - Item to check
* @returns If item was uploaded.
*/
function uploadGraphics(renderer, item) {
if (!(item instanceof graphics.Graphics)) {
return false;
if (!(item instanceof graphics.Graphics)) {
return false;
}
const { geometry } = item;
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);
}
var geometry = item.geometry;
// update dirty graphics to get batches
item.finishPoly();
geometry.updateBatches();
var batches = geometry.batches;
// upload all textures found in styles
for (var i = 0; i < batches.length; i++) {
var texture = batches[i].style.texture;
if (texture) {
uploadBaseTextures(renderer, texture.baseTexture);
}
}
// if its not batchable - update vao for particular shader
if (!geometry.batchable) {
renderer.geometry.bind(geometry, item._resolveDirectShader(renderer));
}
return true;
}
if (!geometry.batchable) {
renderer.geometry.bind(geometry, item._resolveDirectShader(renderer));
}
return true;
}
/**
* Built-in hook to find graphics.
* @private
* @param item - Display object to check
* @param queue - Collection of items to upload
* @returns if a PIXI.Graphics object was found.
*/
function findGraphics(item, queue) {
if (item instanceof graphics.Graphics) {
queue.push(item);
return true;
}
return false;
if (item instanceof graphics.Graphics) {
queue.push(item);
return true;
}
return false;
}
/**
* The prepare plugin provides renderer-specific plugins for pre-rendering DisplayObjects. These plugins are useful for
* asynchronously preparing and uploading to the GPU assets, textures, graphics waiting to be displayed.
*
* Do not instantiate this plugin directly. It is available from the `renderer.plugins` property.
* See {@link PIXI.CanvasRenderer#plugins} or {@link PIXI.Renderer#plugins}.
* @example
* // Create a new application
* const app = new PIXI.Application();
* document.body.appendChild(app.view);
*
* // Don't start rendering right away
* app.stop();
*
* // create a display object
* const rect = new PIXI.Graphics()
* .beginFill(0x00ff00)
* .drawRect(40, 40, 200, 200);
*
* // Add to the stage
* app.stage.addChild(rect);
*
* // Don't start rendering until the graphic is uploaded to the GPU
* app.renderer.plugins.prepare.upload(app.stage, () => {
* app.start();
* });
* @memberof PIXI
*/
var Prepare = /** @class */ (function (_super) {
__extends(Prepare, _super);
/**
* @param {PIXI.Renderer} renderer - A reference to the current renderer
*/
function Prepare(renderer) {
var _this = _super.call(this, renderer) || this;
_this.uploadHookHelper = _this.renderer;
// Add textures and graphics to upload
_this.registerFindHook(findGraphics);
_this.registerUploadHook(uploadBaseTextures);
_this.registerUploadHook(uploadGraphics);
return _this;
}
/** @ignore */
Prepare.extension = {
name: 'prepare',
type: core.ExtensionType.RendererPlugin,
};
return Prepare;
}(BasePrepare));
class Prepare extends BasePrepare {
constructor(renderer) {
super(renderer);
this.uploadHookHelper = this.renderer;
this.registerFindHook(findGraphics);
this.registerUploadHook(uploadBaseTextures);
this.registerUploadHook(uploadGraphics);
}
}
Prepare.extension = {
name: "prepare",
type: core.ExtensionType.RendererSystem
};
core.extensions.add(Prepare);
/**
* TimeLimiter limits the number of items handled by a {@link PIXI.BasePrepare} to a specified
* number of milliseconds per frame.
* @memberof PIXI
*/
var TimeLimiter = /** @class */ (function () {
/** @param maxMilliseconds - The maximum milliseconds that can be spent preparing items each frame. */
function TimeLimiter(maxMilliseconds) {
this.maxMilliseconds = maxMilliseconds;
this.frameStart = 0;
}
/** Resets any counting properties to start fresh on a new frame. */
TimeLimiter.prototype.beginFrame = function () {
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.
*/
TimeLimiter.prototype.allowedToUpload = function () {
return Date.now() - this.frameStart < this.maxMilliseconds;
};
return TimeLimiter;
}());
class TimeLimiter {
constructor(maxMilliseconds) {
this.maxMilliseconds = maxMilliseconds;
this.frameStart = 0;
}
beginFrame() {
this.frameStart = Date.now();
}
allowedToUpload() {
return Date.now() - this.frameStart < this.maxMilliseconds;
}
}

@@ -546,0 +283,0 @@ exports.BasePrepare = BasePrepare;

@@ -1,9 +0,8 @@

/*!
* @pixi/prepare - v6.5.3
* Compiled Fri, 09 Sep 2022 13:55:20 UTC
"use strict";/*!
* @pixi/prepare - v7.0.0-alpha
* Compiled Fri, 09 Sep 2022 16:09:18 UTC
*
* @pixi/prepare is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@pixi/settings"),t=require("@pixi/core"),i=require("@pixi/graphics"),r=require("@pixi/ticker"),n=require("@pixi/display"),o=require("@pixi/text");e.settings.UPLOADS_PER_FRAME=4;var s=function(e,t){return s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])},s(e,t)};var u=function(){function e(e){this.maxItemsPerFrame=e,this.itemsLeft=0}return e.prototype.beginFrame=function(){this.itemsLeft=this.maxItemsPerFrame},e.prototype.allowedToUpload=function(){return this.itemsLeft-- >0},e}();function a(e,i){var r=!1;if(e&&e._textures&&e._textures.length)for(var n=0;n<e._textures.length;n++)if(e._textures[n]instanceof t.Texture){var o=e._textures[n].baseTexture;-1===i.indexOf(o)&&(i.push(o),r=!0)}return r}function h(e,i){if(e.baseTexture instanceof t.BaseTexture){var r=e.baseTexture;return-1===i.indexOf(r)&&i.push(r),!0}return!1}function p(e,i){if(e._texture&&e._texture instanceof t.Texture){var r=e._texture.baseTexture;return-1===i.indexOf(r)&&i.push(r),!0}return!1}function c(e,t){return t instanceof o.Text&&(t.updateText(!0),!0)}function l(e,t){if(t instanceof o.TextStyle){var i=t.toFontString();return o.TextMetrics.measureFont(i),!0}return!1}function f(e,t){if(e instanceof o.Text){-1===t.indexOf(e.style)&&t.push(e.style),-1===t.indexOf(e)&&t.push(e);var i=e._texture.baseTexture;return-1===t.indexOf(i)&&t.push(i),!0}return!1}function d(e,t){return e instanceof o.TextStyle&&(-1===t.indexOf(e)&&t.push(e),!0)}var x=function(){function t(t){var i=this;this.limiter=new u(e.settings.UPLOADS_PER_FRAME),this.renderer=t,this.uploadHookHelper=null,this.queue=[],this.addHooks=[],this.uploadHooks=[],this.completes=[],this.ticking=!1,this.delayedTick=function(){i.queue&&i.prepareItems()},this.registerFindHook(f),this.registerFindHook(d),this.registerFindHook(a),this.registerFindHook(h),this.registerFindHook(p),this.registerUploadHook(c),this.registerUploadHook(l)}return t.prototype.upload=function(e,t){var i=this;return"function"==typeof e&&(t=e,e=null),new Promise((function(n){e&&i.add(e);var o=function(){null==t||t(),n()};i.queue.length?(i.completes.push(o),i.ticking||(i.ticking=!0,r.Ticker.system.addOnce(i.tick,i,r.UPDATE_PRIORITY.UTILITY))):o()}))},t.prototype.tick=function(){setTimeout(this.delayedTick,0)},t.prototype.prepareItems=function(){for(this.limiter.beginFrame();this.queue.length&&this.limiter.allowedToUpload();){var e=this.queue[0],t=!1;if(e&&!e._destroyed)for(var i=0,n=this.uploadHooks.length;i<n;i++)if(this.uploadHooks[i](this.uploadHookHelper,e)){this.queue.shift(),t=!0;break}t||this.queue.shift()}if(this.queue.length)r.Ticker.system.addOnce(this.tick,this,r.UPDATE_PRIORITY.UTILITY);else{this.ticking=!1;var o=this.completes.slice(0);this.completes.length=0;for(i=0,n=o.length;i<n;i++)o[i]()}},t.prototype.registerFindHook=function(e){return e&&this.addHooks.push(e),this},t.prototype.registerUploadHook=function(e){return e&&this.uploadHooks.push(e),this},t.prototype.add=function(e){for(var t=0,i=this.addHooks.length;t<i&&!this.addHooks[t](e,this.queue);t++);if(e instanceof n.Container)for(t=e.children.length-1;t>=0;t--)this.add(e.children[t]);return this},t.prototype.destroy=function(){this.ticking&&r.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},t}();function k(e,i){return i instanceof t.BaseTexture&&(i._glTextures[e.CONTEXT_UID]||e.texture.bind(i),!0)}function g(e,t){if(!(t instanceof i.Graphics))return!1;var r=t.geometry;t.finishPoly(),r.updateBatches();for(var n=r.batches,o=0;o<n.length;o++){var s=n[o].style.texture;s&&k(e,s.baseTexture)}return r.batchable||e.geometry.bind(r,t._resolveDirectShader(e)),!0}function m(e,t){return e instanceof i.Graphics&&(t.push(e),!0)}var T=function(e){function i(t){var i=e.call(this,t)||this;return i.uploadHookHelper=i.renderer,i.registerFindHook(m),i.registerUploadHook(k),i.registerUploadHook(g),i}return function(e,t){function i(){this.constructor=e}s(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}(i,e),i.extension={name:"prepare",type:t.ExtensionType.RendererPlugin},i}(x),y=function(){function e(e){this.maxMilliseconds=e,this.frameStart=0}return e.prototype.beginFrame=function(){this.frameStart=Date.now()},e.prototype.allowedToUpload=function(){return Date.now()-this.frameStart<this.maxMilliseconds},e}();exports.BasePrepare=x,exports.CountLimiter=u,exports.Prepare=T,exports.TimeLimiter=y;
*/Object.defineProperty(exports,"__esModule",{value:!0});var r=require("@pixi/core"),l=require("@pixi/graphics"),p=require("@pixi/display"),o=require("@pixi/text");r.settings.UPLOADS_PER_FRAME=4;class a{constructor(e){this.maxItemsPerFrame=e,this.itemsLeft=0}beginFrame(){this.itemsLeft=this.maxItemsPerFrame}allowedToUpload(){return this.itemsLeft-- >0}}function f(t,e){let s=!1;if(t?._textures?.length){for(let i=0;i<t._textures.length;i++)if(t._textures[i]instanceof r.Texture){const n=t._textures[i].baseTexture;e.includes(n)||(e.push(n),s=!0)}}return s}function m(t,e){if(t.baseTexture instanceof r.BaseTexture){const s=t.baseTexture;return e.includes(s)||e.push(s),!0}return!1}function k(t,e){if(t._texture&&t._texture instanceof r.Texture){const s=t._texture.baseTexture;return e.includes(s)||e.push(s),!0}return!1}function x(t,e){return e instanceof o.Text?(e.updateText(!0),!0):!1}function g(t,e){if(e instanceof o.TextStyle){const s=e.toFontString();return o.TextMetrics.measureFont(s),!0}return!1}function T(t,e){if(t instanceof o.Text){e.includes(t.style)||e.push(t.style),e.includes(t)||e.push(t);const s=t._texture.baseTexture;return e.includes(s)||e.push(s),!0}return!1}function H(t,e){return t instanceof o.TextStyle?(e.includes(t)||e.push(t),!0):!1}class c{constructor(e){this.limiter=new a(r.settings.UPLOADS_PER_FRAME),this.renderer=e,this.uploadHookHelper=null,this.queue=[],this.addHooks=[],this.uploadHooks=[],this.completes=[],this.ticking=!1,this.delayedTick=()=>{!this.queue||this.prepareItems()},this.registerFindHook(T),this.registerFindHook(H),this.registerFindHook(f),this.registerFindHook(m),this.registerFindHook(k),this.registerUploadHook(x),this.registerUploadHook(g)}upload(e){return new Promise(s=>{e&&this.add(e),this.queue.length?(this.completes.push(s),this.ticking||(this.ticking=!0,r.Ticker.system.addOnce(this.tick,this,r.UPDATE_PRIORITY.UTILITY))):s()})}tick(){setTimeout(this.delayedTick,0)}prepareItems(){for(this.limiter.beginFrame();this.queue.length&&this.limiter.allowedToUpload();){const e=this.queue[0];let s=!1;if(e&&!e._destroyed){for(let i=0,n=this.uploadHooks.length;i<n;i++)if(this.uploadHooks[i](this.uploadHookHelper,e)){this.queue.shift(),s=!0;break}}s||this.queue.shift()}if(this.queue.length)r.Ticker.system.addOnce(this.tick,this,r.UPDATE_PRIORITY.UTILITY);else{this.ticking=!1;const e=this.completes.slice(0);this.completes.length=0;for(let s=0,i=e.length;s<i;s++)e[s]()}}registerFindHook(e){return e&&this.addHooks.push(e),this}registerUploadHook(e){return e&&this.uploadHooks.push(e),this}add(e){for(let s=0,i=this.addHooks.length;s<i&&!this.addHooks[s](e,this.queue);s++);if(e instanceof p.Container)for(let s=e.children.length-1;s>=0;s--)this.add(e.children[s]);return this}destroy(){this.ticking&&r.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}}function d(t,e){return e instanceof r.BaseTexture?(e._glTextures[t.CONTEXT_UID]||t.texture.bind(e),!0):!1}function y(t,e){if(!(e instanceof l.Graphics))return!1;const{geometry:s}=e;e.finishPoly(),s.updateBatches();const{batches:i}=s;for(let n=0;n<i.length;n++){const{texture:h}=i[n].style;h&&d(t,h.baseTexture)}return s.batchable||t.geometry.bind(s,e._resolveDirectShader(t)),!0}function _(t,e){return t instanceof l.Graphics?(e.push(t),!0):!1}class u extends c{constructor(e){super(e),this.uploadHookHelper=this.renderer,this.registerFindHook(_),this.registerUploadHook(d),this.registerUploadHook(y)}}u.extension={name:"prepare",type:r.ExtensionType.RendererSystem},r.extensions.add(u);class b{constructor(e){this.maxMilliseconds=e,this.frameStart=0}beginFrame(){this.frameStart=Date.now()}allowedToUpload(){return Date.now()-this.frameStart<this.maxMilliseconds}}exports.BasePrepare=c,exports.CountLimiter=a,exports.Prepare=u,exports.TimeLimiter=b;
//# sourceMappingURL=prepare.min.js.map

@@ -1,2 +0,3 @@

import type { AbstractRenderer } from '@pixi/core';
/// <reference path="./global.d.ts" />
import { BaseTexture } from '@pixi/core';

@@ -6,2 +7,4 @@ import { Container } from '@pixi/display';

import type { ExtensionMetadata } from '@pixi/core';
import type { IRenderer } from '@pixi/core';
import type { ISystem } from '@pixi/core';
import type { Renderer } from '@pixi/core';

@@ -38,3 +41,3 @@ import { TextStyle } from '@pixi/text';

/** Reference to the renderer. */
protected renderer: AbstractRenderer;
protected renderer: IRenderer;
/**

@@ -73,5 +76,5 @@ * The only real difference between CanvasPrepare and Prepare is what they pass

/**
* @param {PIXI.AbstractRenderer} renderer - A reference to the current renderer
* @param {PIXI.IRenderer} renderer - A reference to the current renderer
*/
constructor(renderer: AbstractRenderer);
constructor(renderer: IRenderer);
/**

@@ -86,18 +89,2 @@ * Upload all the textures and graphics to the GPU.

/**
* Use the Promise-based API instead.
* @method PIXI.BasePrepare#upload
* @deprecated since version 6.5.0
* @param {PIXI.DisplayObject|PIXI.Container|PIXI.BaseTexture|PIXI.Texture|PIXI.Graphics|PIXI.Text} item -
* Item to upload.
* @param {Function} [done] - Callback when completed.
*/
upload(item?: IDisplayObjectExtended | Container | BaseTexture | Texture, done?: () => void): void;
/**
* Use the Promise-based API instead.
* @method PIXI.BasePrepare#upload
* @deprecated since version 6.5.0
* @param {Function} [done] - Callback when completed.
*/
upload(done?: () => void): void;
/**
* Handle tick update

@@ -172,3 +159,3 @@ * @private

declare interface IUploadHook {
(helper: AbstractRenderer | BasePrepare, item: IDisplayObjectExtended): boolean;
(helper: IRenderer | BasePrepare, item: IDisplayObjectExtended): boolean;
}

@@ -204,3 +191,3 @@

*/
export declare class Prepare extends BasePrepare {
export declare class Prepare extends BasePrepare implements ISystem {
/** @ignore */

@@ -207,0 +194,0 @@ static extension: ExtensionMetadata;

{
"name": "@pixi/prepare",
"version": "6.5.3",
"version": "7.0.0-alpha",
"main": "dist/cjs/prepare.js",
"module": "dist/esm/prepare.mjs",
"bundle": "dist/browser/prepare.js",
"types": "index.d.ts",

@@ -36,16 +35,12 @@ "exports": {

"files": [
"lib",
"dist",
"*.d.ts"
],
"peerDependencies": {
"@pixi/core": "6.5.3",
"@pixi/display": "6.5.3",
"@pixi/graphics": "6.5.3",
"@pixi/settings": "6.5.3",
"@pixi/text": "6.5.3",
"@pixi/ticker": "6.5.3",
"@pixi/utils": "6.5.3"
},
"gitHead": "28e6b2841a65837a5e2873a3d5a9c27cabbe795a"
"pixiRequirements": [
"@pixi/core",
"@pixi/display",
"@pixi/graphics",
"@pixi/text"
],
"gitHead": "da993226df64b804a9c00ed9ee4d011191467b8a"
}

@@ -12,6 +12,3 @@ # @pixi/prepare

```js
import { Prepare } from '@pixi/canvas-prepare';
import { extensions } from '@pixi/core';
extensions.add(Prepare);
import '@pixi/canvas-prepare';
```

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